xref: /reactos/win32ss/user/ntuser/win32.h (revision 83e13630)
1 #pragma once
2 
3 /* W32PROCESS flags */
4 #define W32PF_CONSOLEAPPLICATION      0x00000001
5 #define W32PF_FORCEOFFFEEDBACK        0x00000002
6 #define W32PF_STARTGLASS              0x00000004
7 #define W32PF_WOW                     0x00000008
8 #define W32PF_READSCREENACCESSGRANTED 0x00000010
9 #define W32PF_INITIALIZED             0x00000020
10 #define W32PF_APPSTARTING             0x00000040
11 #define W32PF_WOW64                   0x00000080
12 #define W32PF_ALLOWFOREGROUNDACTIVATE 0x00000100
13 #define W32PF_OWNDCCLEANUP            0x00000200
14 #define W32PF_SHOWSTARTGLASSCALLED    0x00000400
15 #define W32PF_FORCEBACKGROUNDPRIORITY 0x00000800
16 #define W32PF_TERMINATED              0x00001000
17 #define W32PF_CLASSESREGISTERED       0x00002000
18 #define W32PF_THREADCONNECTED         0x00004000
19 #define W32PF_PROCESSCONNECTED        0x00008000
20 #define W32PF_SETFOREGROUNDALLOWED    0x00008000
21 #define W32PF_WAKEWOWEXEC             0x00010000
22 #define W32PF_WAITFORINPUTIDLE        0x00020000
23 #define W32PF_IOWINSTA                0x00040000
24 #define W32PF_CONSOLEFOREGROUND       0x00080000
25 #define W32PF_OLELOADED               0x00100000
26 #define W32PF_SCREENSAVER             0x00200000
27 #define W32PF_IDLESCREENSAVER         0x00400000
28 #define W32PF_DISABLEIME              0x00800000
29 #define W32PF_ICONTITLEREGISTERED     0x10000000
30 #define W32PF_DPIAWARE                0x20000000
31 // ReactOS
32 #define W32PF_NOWINDOWGHOSTING       (0x01000000)
33 #define W32PF_MANUALGUICHECK         (0x02000000)
34 #define W32PF_CREATEDWINORDC         (0x04000000)
35 #define W32PF_APIHOOKLOADED          (0x08000000)
36 
37 #define QSIDCOUNTS 7
38 
39 typedef enum _QS_ROS_TYPES
40 {
41     QSRosKey = 0,
42     QSRosMouseMove,
43     QSRosMouseButton,
44     QSRosPostMessage,
45     QSRosSendMessage,
46     QSRosHotKey,
47     QSRosEvent,
48 } QS_ROS_TYPES, *PQS_ROS_TYPES;
49 
50 extern BOOL ClientPfnInit;
51 extern HINSTANCE hModClient;
52 extern HANDLE hModuleWin;    // This Win32k Instance.
53 extern struct _CLS *SystemClassList;
54 extern BOOL RegisteredSysClasses;
55 
56 struct _TL;
57 typedef struct _TL *PTL;
58 
59 typedef struct _W32THREAD
60 {
61     PETHREAD pEThread;
62     LONG RefCount;
63     PTL ptlW32;
64     PVOID pgdiDcattr;
65     PVOID pgdiBrushAttr;
66     PVOID pUMPDObjs;
67     PVOID pUMPDHeap;
68     DWORD dwEngAcquireCount;
69     PVOID pSemTable;
70     PVOID pUMPDObj;
71 } W32THREAD, *PW32THREAD;
72 
73 struct tagIMC;
74 
75 /*
76  * THREADINFO structure.
77  * See also: https://reactos.org/wiki/Techwiki:Win32k/THREADINFO
78  */
79 #ifdef __cplusplus
80 typedef struct _THREADINFO : _W32THREAD
81 {
82 #else
83 typedef struct _THREADINFO
84 {
85     W32THREAD;
86 #endif
87     PTL                 ptl;
88     PPROCESSINFO        ppi;
89     struct _USER_MESSAGE_QUEUE* MessageQueue;
90     struct tagKL*       KeyboardLayout;
91     struct _CLIENTTHREADINFO  * pcti;
92     struct _DESKTOP*    rpdesk;
93     struct _DESKTOPINFO  *  pDeskInfo;
94     struct _CLIENTINFO * pClientInfo;
95     FLONG               TIF_flags;
96     PUNICODE_STRING     pstrAppName;
97     struct _USER_SENT_MESSAGE *pusmSent;
98     struct _USER_SENT_MESSAGE *pusmCurrent;
99     /* Queue of messages sent to the queue. */
100     LIST_ENTRY          SentMessagesListHead;    // psmsReceiveList
101     /* Last message time and ID */
102     LONG                timeLast;
103     ULONG_PTR           idLast;
104     /* True if a WM_QUIT message is pending. */
105     BOOLEAN             QuitPosted;
106     /* The quit exit code. */
107     INT                 exitCode;
108     HDESK               hdesk;
109     UINT                cPaintsReady; /* Count of paints pending. */
110     UINT                cTimersReady; /* Count of timers pending. */
111     struct tagMENUSTATE* pMenuState;
112     DWORD               dwExpWinVer;
113     DWORD               dwCompatFlags;
114     DWORD               dwCompatFlags2;
115     struct _USER_MESSAGE_QUEUE* pqAttach;
116     PTHREADINFO         ptiSibling;
117     ULONG               fsHooks;
118     struct tagHOOK *    sphkCurrent;
119     LPARAM              lParamHkCurrent;
120     WPARAM              wParamHkCurrent;
121     struct tagSBTRACK*  pSBTrack;
122     /* Set if there are new messages specified by WakeMask in any of the queues. */
123     HANDLE              hEventQueueClient;
124     /* Handle for the above event (in the context of the process owning the queue). */
125     PKEVENT             pEventQueueServer;
126     LIST_ENTRY          PtiLink;
127     INT                 iCursorLevel;
128     /* Last message cursor position */
129     POINT               ptLast;
130     /* Input context-related */
131     struct _WND*        spwndDefaultIme;
132     struct tagIMC*      spDefaultImc;
133     HKL                 hklPrev;
134 
135     INT                 cEnterCount;
136     /* Queue of messages posted to the queue. */
137     LIST_ENTRY          PostedMessagesListHead; // mlPost
138     WORD                fsChangeBitsRemoved;
139     WCHAR               wchInjected;
140     UINT                cWindows;
141     UINT                cVisWindows;
142 #ifndef __cplusplus /// FIXME!
143     LIST_ENTRY          aphkStart[NB_HOOKS];
144     CLIENTTHREADINFO    cti;  // Used only when no Desktop or pcti NULL.
145 
146     /* ReactOS */
147 
148     /* Thread Queue state tracking */
149     // Send list QS_SENDMESSAGE
150     // Post list QS_POSTMESSAGE|QS_HOTKEY|QS_PAINT|QS_TIMER|QS_KEY
151     // Hard list QS_MOUSE|QS_KEY only
152     // Accounting of queue bit sets, the rest are flags. QS_TIMER QS_PAINT counts are handled in thread information.
153     DWORD nCntsQBits[QSIDCOUNTS]; // QS_KEY QS_MOUSEMOVE QS_MOUSEBUTTON QS_POSTMESSAGE QS_SENDMESSAGE QS_HOTKEY
154 
155     LIST_ENTRY WindowListHead;
156     LIST_ENTRY W32CallbackListHead;
157     SINGLE_LIST_ENTRY  ReferencesList;
158     ULONG cExclusiveLocks;
159 #if DBG
160     USHORT acExclusiveLockCount[GDIObjTypeTotal + 1];
161 #endif
162 #endif // __cplusplus
163 } THREADINFO;
164 
165 
166 #define IntReferenceThreadInfo(pti) \
167     InterlockedIncrement(&(pti)->RefCount)
168 
169 VOID UserDeleteW32Thread(PTHREADINFO);
170 
171 #define IntDereferenceThreadInfo(pti) \
172 do { \
173     if (InterlockedDecrement(&(pti)->RefCount) == 0) \
174     { \
175         ASSERT(((pti)->TIF_flags & (TIF_INCLEANUP|TIF_DONTATTACHQUEUE)) == (TIF_INCLEANUP|TIF_DONTATTACHQUEUE)); \
176         UserDeleteW32Thread(pti); \
177     } \
178 } while(0)
179 
180 
181 #define IntReferenceProcessInfo(ppi) \
182     InterlockedIncrement((volatile LONG*)(&(ppi)->RefCount))
183 
184 VOID UserDeleteW32Process(_Pre_notnull_ __drv_freesMem(Mem) PPROCESSINFO);
185 
186 #define IntDereferenceProcessInfo(ppi) \
187 do { \
188     if (InterlockedDecrement((volatile LONG*)(&(ppi)->RefCount)) == 0) \
189     { \
190         ASSERT(((ppi)->W32PF_flags & W32PF_TERMINATED) != 0); \
191         UserDeleteW32Process(ppi); \
192     } \
193 } while(0)
194 
195 
196 typedef struct _W32HEAP_USER_MAPPING
197 {
198     struct _W32HEAP_USER_MAPPING* Next;
199     PVOID KernelMapping;
200     PVOID UserMapping;
201     ULONG_PTR Limit;
202     ULONG Count;
203 } W32HEAP_USER_MAPPING, *PW32HEAP_USER_MAPPING;
204 
205 
206 /*
207  * Information from STARTUPINFOW, psdk/winbase.h.
208  * Set from PsGetCurrentProcess()->Peb->ProcessParameters.
209  * See also: https://reactos.org/wiki/Techwiki:Win32k/PROCESSINFO
210 */
211 typedef struct tagUSERSTARTUPINFO
212 {
213     ULONG cb;
214     DWORD dwX;        // STARTF_USEPOSITION StartupInfo->dwX/Y
215     DWORD dwY;
216     DWORD dwXSize;    // STARTF_USESIZE StartupInfo->dwX/YSize
217     DWORD dwYSize;
218     DWORD dwFlags;    // STARTF_ StartupInfo->dwFlags
219     WORD wShowWindow; // StartupInfo->wShowWindow
220     USHORT cbReserved2;
221 } USERSTARTUPINFO, *PUSERSTARTUPINFO;
222 
223 typedef struct _W32PROCESS
224 {
225     PEPROCESS     peProcess;
226     DWORD         RefCount;
227     ULONG         W32PF_flags;
228     PKEVENT       InputIdleEvent;
229     DWORD         StartCursorHideTime;
230     struct _W32PROCESS* NextStart;
231     PVOID         pDCAttrList;
232     PVOID         pBrushAttrList;
233     DWORD         W32Pid;
234     LONG          GDIHandleCount;
235     LONG          UserHandleCount;
236     PEX_PUSH_LOCK GDIPushLock;  /* Locking Process during access to structure. */
237     RTL_AVL_TABLE GDIEngUserMemAllocTable;  /* Process AVL Table. */
238     LIST_ENTRY    GDIDcAttrFreeList;
239     LIST_ENTRY    GDIBrushAttrFreeList;
240 } W32PROCESS, *PW32PROCESS;
241 
242 #define CLIBS 32
243 
244 /*
245  * PROCESSINFO structure.
246  * See also: https://reactos.org/wiki/Techwiki:Win32k/PROCESSINFO
247  */
248 #ifdef __cplusplus
249 typedef struct _PROCESSINFO : _W32PROCESS
250 {
251 #else
252 typedef struct _PROCESSINFO
253 {
254     W32PROCESS;
255 #endif
256     PTHREADINFO ptiList;
257     PTHREADINFO ptiMainThread;
258     struct _DESKTOP* rpdeskStartup;
259     struct _CLS *pclsPrivateList;
260     struct _CLS *pclsPublicList;
261     PPROCESSINFO ppiNext;
262     INT cThreads;
263     HDESK hdeskStartup;
264     DWORD dwhmodLibLoadedMask;
265     HANDLE ahmodLibLoaded[CLIBS];
266     struct _WINSTATION_OBJECT* prpwinsta;
267     HWINSTA hwinsta;
268     ACCESS_MASK amwinsta;
269     DWORD dwHotkey;
270     HMONITOR hMonitor;
271     UINT iClipSerialNumber;
272     struct _CURICON_OBJECT* pCursorCache;
273     PVOID pClientBase;
274     DWORD dwLpkEntryPoints;
275     PVOID pW32Job;
276     DWORD dwImeCompatFlags;
277     LUID luidSession;
278     USERSTARTUPINFO usi;
279     DWORD dwLayout;
280     DWORD dwRegisteredClasses;
281 
282     /* ReactOS */
283     FAST_MUTEX PrivateFontListLock;
284     LIST_ENTRY PrivateFontListHead;
285     LIST_ENTRY PrivateMemFontListHead;
286     UINT PrivateMemFontHandleCount;
287 
288     FAST_MUTEX DriverObjListLock;
289     LIST_ENTRY DriverObjListHead;
290     W32HEAP_USER_MAPPING HeapMappings;
291     struct _GDI_POOL* pPoolDcAttr;
292     struct _GDI_POOL* pPoolBrushAttr;
293     struct _GDI_POOL* pPoolRgnAttr;
294 
295 #if DBG
296     BYTE DbgChannelLevel[DbgChCount];
297 #ifndef __cplusplus
298     DWORD DbgHandleCount[TYPE_CTYPES];
299 #endif // __cplusplus
300 #endif // DBG
301 } PROCESSINFO;
302 
303 #if DBG
304 void NTAPI UserDbgPreServiceHook(ULONG ulSyscallId, PULONG_PTR pulArguments);
305 ULONG_PTR NTAPI UserDbgPostServiceHook(ULONG ulSyscallId, ULONG_PTR ulResult);
306 #endif
307 
308 /* Helper function used by some wine code */
309 
310 __forceinline
311 int
312 lstrlenW(
313     _In_ LPCWSTR lpString)
314 {
315     size_t size = wcslen(lpString);
316     if (size > ULONG_MAX) __fastfail(FAST_FAIL_RANGE_CHECK_FAILURE);
317     return (int)size;
318 }
319 
320 #define strlenW lstrlenW
321