xref: /reactos/win32ss/user/ntuser/win32.h (revision 93d8a1b7)
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 // FIXME: Move to ntuser.h
57 typedef struct _TL
58 {
59     struct _TL* next;
60     PVOID pobj;
61     PVOID pfnFree;
62 } TL, *PTL;
63 
64 typedef struct _W32THREAD
65 {
66     PETHREAD pEThread;
67     LONG RefCount;
68     PTL ptlW32;
69     PVOID pgdiDcattr;
70     PVOID pgdiBrushAttr;
71     PVOID pUMPDObjs;
72     PVOID pUMPDHeap;
73     DWORD dwEngAcquireCount;
74     PVOID pSemTable;
75     PVOID pUMPDObj;
76 } W32THREAD, *PW32THREAD;
77 
78 struct tagIMC;
79 
80 #ifdef __cplusplus
81 typedef struct _THREADINFO : _W32THREAD
82 {
83 #else
84 typedef struct _THREADINFO
85 {
86     W32THREAD;
87 #endif
88     PTL                 ptl;
89     PPROCESSINFO        ppi;
90     struct _USER_MESSAGE_QUEUE* MessageQueue;
91     struct tagKL*       KeyboardLayout;
92     struct _CLIENTTHREADINFO  * pcti;
93     struct _DESKTOP*    rpdesk;
94     struct _DESKTOPINFO  *  pDeskInfo;
95     struct _CLIENTINFO * pClientInfo;
96     FLONG               TIF_flags;
97     PUNICODE_STRING     pstrAppName;
98     struct _USER_SENT_MESSAGE *pusmSent;
99     struct _USER_SENT_MESSAGE *pusmCurrent;
100     /* Queue of messages sent to the queue. */
101     LIST_ENTRY          SentMessagesListHead;    // psmsReceiveList
102     /* Last message time and ID */
103     LONG                timeLast;
104     ULONG_PTR           idLast;
105     /* True if a WM_QUIT message is pending. */
106     BOOLEAN             QuitPosted;
107     /* The quit exit code. */
108     INT                 exitCode;
109     HDESK               hdesk;
110     UINT                cPaintsReady; /* Count of paints pending. */
111     UINT                cTimersReady; /* Count of timers pending. */
112     struct tagMENUSTATE* pMenuState;
113     DWORD               dwExpWinVer;
114     DWORD               dwCompatFlags;
115     DWORD               dwCompatFlags2;
116     struct _USER_MESSAGE_QUEUE* pqAttach;
117     PTHREADINFO         ptiSibling;
118     ULONG               fsHooks;
119     struct tagHOOK *    sphkCurrent;
120     LPARAM              lParamHkCurrent;
121     WPARAM              wParamHkCurrent;
122     struct tagSBTRACK*  pSBTrack;
123     /* Set if there are new messages specified by WakeMask in any of the queues. */
124     HANDLE              hEventQueueClient;
125     /* Handle for the above event (in the context of the process owning the queue). */
126     PKEVENT             pEventQueueServer;
127     LIST_ENTRY          PtiLink;
128     INT                 iCursorLevel;
129     /* Last message cursor position */
130     POINT               ptLast;
131     /* Input context-related */
132     struct _WND*        spwndDefaultIme;
133     struct tagIMC*      spDefaultImc;
134     HKL                 hklPrev;
135 
136     INT                 cEnterCount;
137     /* Queue of messages posted to the queue. */
138     LIST_ENTRY          PostedMessagesListHead; // mlPost
139     WORD                fsChangeBitsRemoved;
140     WCHAR               wchInjected;
141     UINT                cWindows;
142     UINT                cVisWindows;
143 #ifndef __cplusplus /// FIXME!
144     LIST_ENTRY          aphkStart[NB_HOOKS];
145     CLIENTTHREADINFO    cti;  // Used only when no Desktop or pcti NULL.
146 
147     /* ReactOS */
148 
149     /* Thread Queue state tracking */
150     // Send list QS_SENDMESSAGE
151     // Post list QS_POSTMESSAGE|QS_HOTKEY|QS_PAINT|QS_TIMER|QS_KEY
152     // Hard list QS_MOUSE|QS_KEY only
153     // Accounting of queue bit sets, the rest are flags. QS_TIMER QS_PAINT counts are handled in thread information.
154     DWORD nCntsQBits[QSIDCOUNTS]; // QS_KEY QS_MOUSEMOVE QS_MOUSEBUTTON QS_POSTMESSAGE QS_SENDMESSAGE QS_HOTKEY
155 
156     LIST_ENTRY WindowListHead;
157     LIST_ENTRY W32CallbackListHead;
158     SINGLE_LIST_ENTRY  ReferencesList;
159     ULONG cExclusiveLocks;
160 #if DBG
161     USHORT acExclusiveLockCount[GDIObjTypeTotal + 1];
162 #endif
163 #endif // __cplusplus
164 } THREADINFO;
165 
166 
167 #define IntReferenceThreadInfo(pti) \
168     InterlockedIncrement(&(pti)->RefCount)
169 
170 VOID UserDeleteW32Thread(PTHREADINFO);
171 
172 #define IntDereferenceThreadInfo(pti) \
173 do { \
174     if (InterlockedDecrement(&(pti)->RefCount) == 0) \
175     { \
176         ASSERT(((pti)->TIF_flags & (TIF_INCLEANUP|TIF_DONTATTACHQUEUE)) == (TIF_INCLEANUP|TIF_DONTATTACHQUEUE)); \
177         UserDeleteW32Thread(pti); \
178     } \
179 } while(0)
180 
181 
182 #define IntReferenceProcessInfo(ppi) \
183     InterlockedIncrement((volatile LONG*)(&(ppi)->RefCount))
184 
185 VOID UserDeleteW32Process(_Pre_notnull_ __drv_freesMem(Mem) PPROCESSINFO);
186 
187 #define IntDereferenceProcessInfo(ppi) \
188 do { \
189     if (InterlockedDecrement((volatile LONG*)(&(ppi)->RefCount)) == 0) \
190     { \
191         ASSERT(((ppi)->W32PF_flags & W32PF_TERMINATED) != 0); \
192         UserDeleteW32Process(ppi); \
193     } \
194 } while(0)
195 
196 
197 typedef struct _W32HEAP_USER_MAPPING
198 {
199     struct _W32HEAP_USER_MAPPING* Next;
200     PVOID KernelMapping;
201     PVOID UserMapping;
202     ULONG_PTR Limit;
203     ULONG Count;
204 } W32HEAP_USER_MAPPING, *PW32HEAP_USER_MAPPING;
205 
206 
207 /*
208  Information from STARTUPINFOW, psdk/winbase.h.
209  Set from PsGetCurrentProcess()->Peb->ProcessParameters.
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 #ifdef __cplusplus
245 typedef struct _PROCESSINFO : _W32PROCESS
246 {
247 #else
248 typedef struct _PROCESSINFO
249 {
250     W32PROCESS;
251 #endif
252     PTHREADINFO ptiList;
253     PTHREADINFO ptiMainThread;
254     struct _DESKTOP* rpdeskStartup;
255     struct _CLS *pclsPrivateList;
256     struct _CLS *pclsPublicList;
257     PPROCESSINFO ppiNext;
258     INT cThreads;
259     HDESK hdeskStartup;
260     DWORD dwhmodLibLoadedMask;
261     HANDLE ahmodLibLoaded[CLIBS];
262     struct _WINSTATION_OBJECT* prpwinsta;
263     HWINSTA hwinsta;
264     ACCESS_MASK amwinsta;
265     DWORD dwHotkey;
266     HMONITOR hMonitor;
267     UINT iClipSerialNumber;
268     struct _CURICON_OBJECT* pCursorCache;
269     PVOID pClientBase;
270     DWORD dwLpkEntryPoints;
271     PVOID pW32Job;
272     DWORD dwImeCompatFlags;
273     LUID luidSession;
274     USERSTARTUPINFO usi;
275     DWORD dwLayout;
276     DWORD dwRegisteredClasses;
277 
278     /* ReactOS */
279     FAST_MUTEX PrivateFontListLock;
280     LIST_ENTRY PrivateFontListHead;
281     LIST_ENTRY PrivateMemFontListHead;
282     UINT PrivateMemFontHandleCount;
283 
284     FAST_MUTEX DriverObjListLock;
285     LIST_ENTRY DriverObjListHead;
286     W32HEAP_USER_MAPPING HeapMappings;
287     struct _GDI_POOL* pPoolDcAttr;
288     struct _GDI_POOL* pPoolBrushAttr;
289     struct _GDI_POOL* pPoolRgnAttr;
290 
291 #if DBG
292     BYTE DbgChannelLevel[DbgChCount];
293 #ifndef __cplusplus
294     DWORD DbgHandleCount[TYPE_CTYPES];
295 #endif // __cplusplus
296 #endif // DBG
297 } PROCESSINFO;
298 
299 #if DBG
300 void NTAPI UserDbgPreServiceHook(ULONG ulSyscallId, PULONG_PTR pulArguments);
301 ULONG_PTR NTAPI UserDbgPostServiceHook(ULONG ulSyscallId, ULONG_PTR ulResult);
302 #endif
303 
304 /* Helper function used by some wine code */
305 
306 __forceinline
307 int
308 lstrlenW(
309     _In_ LPCWSTR lpString)
310 {
311     size_t size = wcslen(lpString);
312     if (size > ULONG_MAX) __fastfail(FAST_FAIL_RANGE_CHECK_FAILURE);
313     return (int)size;
314 }
315 
316 #define strlenW lstrlenW
317