2 * ReactOS W32 Subsystem
3 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * Entry Point for win32k.sys
26 #include <win32k/debug1.h>
30 typedef NTSTATUS (STDCALL
*PW32_PROCESS_CALLBACK
)(
31 struct _EPROCESS
*Process
,
34 typedef NTSTATUS (STDCALL
*PW32_THREAD_CALLBACK
)(
35 struct _ETHREAD
*Thread
,
39 PsEstablishWin32Callouts(
40 PW32_PROCESS_CALLBACK W32ProcessCallback
,
41 PW32_THREAD_CALLBACK W32ThreadCallback
,
45 ULONG W32ProcessSize
);
48 BOOL INTERNAL_CALL
GDI_CleanupForProcess (struct _EPROCESS
*Process
);
50 extern SSDT Win32kSSDT
[];
51 extern SSPT Win32kSSPT
[];
52 extern ULONG Win32kNumberOfSysCalls
;
55 Win32kProcessCallback (struct _EPROCESS
*Process
,
58 PW32PROCESS Win32Process
;
60 Win32Process
= Process
->Win32Process
;
63 DPRINT("Creating W32 process PID:%d at IRQ level: %lu\n", Process
->UniqueProcessId
, KeGetCurrentIrql());
65 InitializeListHead(&Win32Process
->ClassListHead
);
66 ExInitializeFastMutex(&Win32Process
->ClassListLock
);
68 InitializeListHead(&Win32Process
->MenuListHead
);
69 ExInitializeFastMutex(&Win32Process
->MenuListLock
);
71 InitializeListHead(&Win32Process
->PrivateFontListHead
);
72 ExInitializeFastMutex(&Win32Process
->PrivateFontListLock
);
74 InitializeListHead(&Win32Process
->CursorIconListHead
);
75 ExInitializeFastMutex(&Win32Process
->CursorIconListLock
);
77 Win32Process
->KeyboardLayout
= W32kGetDefaultKeyLayout();
79 /* setup process flags */
80 Win32Process
->Flags
= 0;
84 DPRINT("Destroying W32 process PID:%d at IRQ level: %lu\n", Process
->UniqueProcessId
, KeGetCurrentIrql());
85 IntRemoveProcessWndProcHandles((HANDLE
)Process
->UniqueProcessId
);
86 IntCleanupMenus(Process
, Win32Process
);
87 IntCleanupCurIcons(Process
, Win32Process
);
90 GDI_CleanupForProcess(Process
);
92 IntGraphicsCheck(FALSE
);
95 * Deregister logon application automatically
97 if(LogonProcess
== Win32Process
)
103 return STATUS_SUCCESS
;
108 Win32kThreadCallback (struct _ETHREAD
*Thread
,
111 struct _EPROCESS
*Process
;
112 PW32THREAD Win32Thread
;
114 Process
= Thread
->ThreadsProcess
;
115 Win32Thread
= Thread
->Tcb
.Win32Thread
;
118 HWINSTA hWinSta
= NULL
;
121 PUNICODE_STRING DesktopPath
;
122 PRTL_USER_PROCESS_PARAMETERS ProcessParams
= (Process
->Peb
? Process
->Peb
->ProcessParameters
: NULL
);
124 DPRINT("Creating W32 thread TID:%d at IRQ level: %lu\n", Thread
->Cid
.UniqueThread
, KeGetCurrentIrql());
127 * inherit the thread desktop and process window station (if not yet inherited) from the process startup
128 * info structure. See documentation of CreateProcess()
130 DesktopPath
= (ProcessParams
? ((ProcessParams
->DesktopInfo
.Length
> 0) ? &ProcessParams
->DesktopInfo
: NULL
) : NULL
);
131 Status
= IntParseDesktopPath(Process
,
135 if(NT_SUCCESS(Status
))
139 if(Process
!= CsrProcess
)
141 HWINSTA hProcessWinSta
= (HWINSTA
)InterlockedCompareExchangePointer((PVOID
)&Process
->Win32WindowStation
, (PVOID
)hWinSta
, NULL
);
142 if(hProcessWinSta
!= NULL
)
144 /* our process is already assigned to a different window station, we don't need the handle anymore */
154 Win32Thread
->hDesktop
= hDesk
;
156 Status
= ObReferenceObjectByHandle(hDesk
,
160 (PVOID
*)&Win32Thread
->Desktop
,
163 if(!NT_SUCCESS(Status
))
165 DPRINT1("Unable to reference thread desktop handle 0x%x\n", hDesk
);
166 Win32Thread
->Desktop
= NULL
;
171 Win32Thread
->IsExiting
= FALSE
;
172 IntDestroyCaret(Win32Thread
);
173 Win32Thread
->MessageQueue
= MsqCreateMessageQueue(Thread
);
174 Win32Thread
->KeyboardLayout
= W32kGetDefaultKeyLayout();
175 Win32Thread
->MessagePumpHookValue
= 0;
176 InitializeListHead(&Win32Thread
->WindowListHead
);
177 ExInitializeFastMutex(&Win32Thread
->WindowListLock
);
178 InitializeListHead(&Win32Thread
->W32CallbackListHead
);
179 ExInitializeFastMutex(&Win32Thread
->W32CallbackListLock
);
183 DPRINT("Destroying W32 thread TID:%d at IRQ level: %lu\n", Thread
->Cid
.UniqueThread
, KeGetCurrentIrql());
185 Win32Thread
->IsExiting
= TRUE
;
186 HOOK_DestroyThreadHooks(Thread
);
187 UnregisterThreadHotKeys(Thread
);
188 DestroyThreadWindows(Thread
);
189 IntBlockInput(Win32Thread
, FALSE
);
190 MsqDestroyMessageQueue(Win32Thread
->MessageQueue
);
191 IntCleanupThreadCallbacks(Win32Thread
);
192 if(Win32Thread
->Desktop
!= NULL
)
194 ObDereferenceObject(Win32Thread
->Desktop
);
198 return STATUS_SUCCESS
;
204 IN PDRIVER_OBJECT DriverObject
,
205 IN PUNICODE_STRING RegistryPath
)
211 * Register user mode call interface
212 * (system service table index = 1)
214 Result
= KeAddSystemServiceTable (Win32kSSDT
,
216 Win32kNumberOfSysCalls
,
221 DPRINT1("Adding system services failed!\n");
222 return STATUS_UNSUCCESSFUL
;
226 * Register our per-process and per-thread structures.
228 PsEstablishWin32Callouts (Win32kProcessCallback
,
229 Win32kThreadCallback
,
235 Status
= InitWindowStationImpl();
236 if (!NT_SUCCESS(Status
))
238 DPRINT1("Failed to initialize window station implementation!\n");
239 return STATUS_UNSUCCESSFUL
;
242 Status
= InitClassImpl();
243 if (!NT_SUCCESS(Status
))
245 DPRINT1("Failed to initialize window class implementation!\n");
246 return STATUS_UNSUCCESSFUL
;
249 Status
= InitDesktopImpl();
250 if (!NT_SUCCESS(Status
))
252 DPRINT1("Failed to initialize desktop implementation!\n");
253 return STATUS_UNSUCCESSFUL
;
256 Status
= InitWindowImpl();
257 if (!NT_SUCCESS(Status
))
259 DPRINT1("Failed to initialize window implementation!\n");
260 return STATUS_UNSUCCESSFUL
;
263 Status
= InitMenuImpl();
264 if (!NT_SUCCESS(Status
))
266 DPRINT1("Failed to initialize menu implementation!\n");
267 return STATUS_UNSUCCESSFUL
;
270 Status
= InitInputImpl();
271 if (!NT_SUCCESS(Status
))
273 DPRINT1("Failed to initialize input implementation.\n");
277 Status
= InitKeyboardImpl();
278 if (!NT_SUCCESS(Status
))
280 DPRINT1("Failed to initialize keyboard implementation.\n");
284 Status
= InitMonitorImpl();
285 if (!NT_SUCCESS(Status
))
287 DbgPrint("Failed to initialize monitor implementation!\n");
288 return STATUS_UNSUCCESSFUL
;
291 Status
= MsqInitializeImpl();
292 if (!NT_SUCCESS(Status
))
294 DPRINT1("Failed to initialize message queue implementation.\n");
298 Status
= InitTimerImpl();
299 if (!NT_SUCCESS(Status
))
301 DPRINT1("Failed to initialize timer implementation.\n");
305 Status
= InitAcceleratorImpl();
306 if (!NT_SUCCESS(Status
))
308 DPRINT1("Failed to initialize accelerator implementation.\n");
312 Status
= InitGuiCheckImpl();
313 if (!NT_SUCCESS(Status
))
315 DPRINT1("Failed to initialize GUI check implementation.\n");
319 InitGdiObjectHandleTable ();
321 /* Initialize FreeType library */
322 if (! InitFontSupport())
324 DPRINT1("Unable to initialize font support\n");
325 return STATUS_UNSUCCESSFUL
;
328 /* Create stock objects, ie. precreated objects commonly
329 used by win32 applications */
330 CreateStockObjects();
331 CreateSysColorObjects();
333 return STATUS_SUCCESS
;
338 Win32kInitialize (VOID
)