xref: /reactos/win32ss/user/ntuser/ntuser.c (revision 0493e8e4)
1 /*
2  *  COPYRIGHT:        See COPYING in the top level directory
3  *  PROJECT:          ReactOS kernel
4  *  PURPOSE:          ntuser init. and main funcs.
5  *  FILE:             win32ss/user/ntuser/ntuser.c
6  */
7 
8 #include <win32k.h>
9 DBG_DEFAULT_CHANNEL(UserMisc);
10 
11 BOOL FASTCALL RegisterControlAtoms(VOID);
12 
13 /* GLOBALS ********************************************************************/
14 
15 PTHREADINFO gptiCurrent = NULL;
16 PPROCESSINFO gppiInputProvider = NULL;
17 BOOL g_AlwaysDisplayVersion = FALSE;
18 ERESOURCE UserLock;
19 ATOM AtomMessage;       // Window Message atom.
20 ATOM AtomWndObj;        // Window Object atom.
21 ATOM AtomLayer;         // Window Layer atom.
22 ATOM AtomFlashWndState; // Window Flash State atom.
23 ATOM AtomDDETrack;      // Window DDE Tracking atom.
24 ATOM AtomQOS;           // Window DDE Quality of Service atom.
25 HINSTANCE hModClient = NULL;
26 BOOL ClientPfnInit = FALSE;
27 ATOM gaGuiConsoleWndClass;
28 
29 /* PRIVATE FUNCTIONS **********************************************************/
30 
31 static
32 NTSTATUS FASTCALL
33 InitUserAtoms(VOID)
34 {
35     RegisterControlAtoms();
36 
37     gpsi->atomSysClass[ICLS_MENU]      = 32768;
38     gpsi->atomSysClass[ICLS_DESKTOP]   = 32769;
39     gpsi->atomSysClass[ICLS_DIALOG]    = 32770;
40     gpsi->atomSysClass[ICLS_SWITCH]    = 32771;
41     gpsi->atomSysClass[ICLS_ICONTITLE] = 32772;
42     gpsi->atomSysClass[ICLS_TOOLTIPS]  = 32774;
43 
44     /* System Message Atom */
45     AtomMessage = IntAddGlobalAtom(L"Message", TRUE);
46     gpsi->atomSysClass[ICLS_HWNDMESSAGE] = AtomMessage;
47 
48     /* System Context Help Id Atom */
49     gpsi->atomContextHelpIdProp = IntAddGlobalAtom(L"SysCH", TRUE);
50 
51     gpsi->atomIconSmProp = IntAddGlobalAtom(L"SysICS", TRUE);
52     gpsi->atomIconProp   = IntAddGlobalAtom(L"SysIC", TRUE);
53 
54     gpsi->atomFrostedWindowProp = IntAddGlobalAtom(L"SysFrostedWindow", TRUE);
55 
56     AtomDDETrack = IntAddGlobalAtom(L"SysDT", TRUE);
57     AtomQOS      = IntAddGlobalAtom(L"SysQOS", TRUE);
58 
59     /*
60      * FIXME: AddPropW uses the global kernel atom table, thus leading to conflicts if we use
61      * the win32k atom table for this one. What is the right thing to do ?
62      */
63     // AtomWndObj = IntAddGlobalAtom(L"SysWNDO", TRUE);
64     NtAddAtom(L"SysWNDO", 14, &AtomWndObj);
65 
66     AtomLayer = IntAddGlobalAtom(L"SysLayer", TRUE);
67     AtomFlashWndState = IntAddGlobalAtom(L"FlashWState", TRUE);
68 
69     return STATUS_SUCCESS;
70 }
71 
72 /* FUNCTIONS ******************************************************************/
73 
74 INIT_FUNCTION
75 NTSTATUS
76 NTAPI
77 InitUserImpl(VOID)
78 {
79     NTSTATUS Status;
80     HKEY hKey;
81 
82     ExInitializeResourceLite(&UserLock);
83 
84     if (!UserCreateHandleTable())
85     {
86         ERR("Failed creating handle table\n");
87         return STATUS_INSUFFICIENT_RESOURCES;
88     }
89 
90     Status = InitSessionImpl();
91     if (!NT_SUCCESS(Status))
92     {
93         ERR("Error init session impl.\n");
94         return Status;
95     }
96 
97     InitUserAtoms();
98 
99     Status = RegOpenKey(L"\\Registry\\Machine\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows",
100                         &hKey);
101     if (NT_SUCCESS(Status))
102     {
103         DWORD dwValue = 0;
104         RegReadDWORD(hKey, L"DisplayVersion", &dwValue);
105         g_AlwaysDisplayVersion = !!dwValue;
106         ZwClose(hKey);
107     }
108 
109     InitSysParams();
110 
111     return STATUS_SUCCESS;
112 }
113 
114 NTSTATUS
115 NTAPI
116 InitVideo(VOID);
117 
118 NTSTATUS
119 NTAPI
120 UserInitialize(VOID)
121 {
122     static const DWORD wPattern55AA[] = /* 32 bit aligned */
123     { 0x55555555, 0xaaaaaaaa, 0x55555555, 0xaaaaaaaa,
124       0x55555555, 0xaaaaaaaa, 0x55555555, 0xaaaaaaaa };
125     HBITMAP hPattern55AABitmap = NULL;
126     NTSTATUS Status;
127 
128     NT_ASSERT(PsGetCurrentThreadWin32Thread() != NULL);
129 
130 // Create Event for Disconnect Desktop.
131 
132     Status = UserCreateWinstaDirectory();
133     if (!NT_SUCCESS(Status)) return Status;
134 
135     /* Initialize the Video */
136     Status = InitVideo();
137     if (!NT_SUCCESS(Status))
138     {
139         /* We failed, bugcheck */
140         KeBugCheckEx(VIDEO_DRIVER_INIT_FAILURE, Status, 0, 0, USER_VERSION);
141     }
142 
143 // {
144 //     DrvInitConsole.
145 //     DrvChangeDisplaySettings.
146 //     Update Shared Device Caps.
147 //     Initialize User Screen.
148 // }
149 
150 // Set Global SERVERINFO Error flags.
151 // Load Resources.
152 
153     NtUserUpdatePerUserSystemParameters(0, TRUE);
154 
155     if (gpsi->hbrGray == NULL)
156     {
157         hPattern55AABitmap = GreCreateBitmap(8, 8, 1, 1, (LPBYTE)wPattern55AA);
158         if (hPattern55AABitmap == NULL)
159             return STATUS_INSUFFICIENT_RESOURCES;
160 
161         gpsi->hbrGray = IntGdiCreatePatternBrush(hPattern55AABitmap);
162 
163         if (gpsi->hbrGray == NULL)
164             return STATUS_INSUFFICIENT_RESOURCES;
165     }
166 
167     return STATUS_SUCCESS;
168 }
169 
170 /*
171  * Called from usersrv.
172  */
173 NTSTATUS
174 APIENTRY
175 NtUserInitialize(
176     DWORD  dwWinVersion,
177     HANDLE hPowerRequestEvent,
178     HANDLE hMediaRequestEvent)
179 {
180     NTSTATUS Status;
181 
182     TRACE("Enter NtUserInitialize(%lx, %p, %p)\n",
183           dwWinVersion, hPowerRequestEvent, hMediaRequestEvent);
184 
185     /* Check if we are already initialized */
186     if (gpepCSRSS)
187         return STATUS_UNSUCCESSFUL;
188 
189     /* Check Windows USER subsystem version */
190     if (dwWinVersion != USER_VERSION)
191     {
192         /* No match, bugcheck */
193         KeBugCheckEx(WIN32K_INIT_OR_RIT_FAILURE, 0, 0, dwWinVersion, USER_VERSION);
194     }
195 
196     /* Acquire exclusive lock */
197     UserEnterExclusive();
198 
199     /* Save the EPROCESS of CSRSS */
200     InitCsrProcess(/*PsGetCurrentProcess()*/);
201 
202 // Initialize Power Request List (use hPowerRequestEvent).
203 // Initialize Media Change (use hMediaRequestEvent).
204 
205 // InitializeGreCSRSS();
206 // {
207 //    Startup DxGraphics.
208 //    calls ** UserGetLanguageID() and sets it **.
209 //    Enables Fonts drivers, Initialize Font table & Stock Fonts.
210 // }
211 
212     /* Initialize USER */
213     Status = UserInitialize();
214 
215     /* Return */
216     UserLeave();
217     return Status;
218 }
219 
220 
221 /*
222 RETURN
223    True if current thread owns the lock (possibly shared)
224 */
225 BOOL FASTCALL UserIsEntered(VOID)
226 {
227     return ExIsResourceAcquiredExclusiveLite(&UserLock) ||
228            ExIsResourceAcquiredSharedLite(&UserLock);
229 }
230 
231 BOOL FASTCALL UserIsEnteredExclusive(VOID)
232 {
233     return ExIsResourceAcquiredExclusiveLite(&UserLock);
234 }
235 
236 VOID FASTCALL CleanupUserImpl(VOID)
237 {
238     ExDeleteResourceLite(&UserLock);
239 }
240 
241 VOID FASTCALL UserEnterShared(VOID)
242 {
243     KeEnterCriticalRegion();
244     ExAcquireResourceSharedLite(&UserLock, TRUE);
245 }
246 
247 VOID FASTCALL UserEnterExclusive(VOID)
248 {
249     ASSERT_NOGDILOCKS();
250     KeEnterCriticalRegion();
251     ExAcquireResourceExclusiveLite(&UserLock, TRUE);
252     gptiCurrent = PsGetCurrentThreadWin32Thread();
253 }
254 
255 VOID FASTCALL UserLeave(VOID)
256 {
257     ASSERT_NOGDILOCKS();
258     ASSERT(UserIsEntered());
259     ExReleaseResourceLite(&UserLock);
260     KeLeaveCriticalRegion();
261 }
262 
263 /* EOF */
264