2 * ReactOS W32 Subsystem
3 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 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
;
54 PSHARED_SECTION_POOL SessionSharedSectionPool
= NULL
;
57 Win32kProcessCallback (struct _EPROCESS
*Process
,
60 PW32PROCESS Win32Process
;
62 Win32Process
= Process
->Win32Process
;
65 DPRINT("Creating W32 process PID:%d at IRQ level: %lu\n", Process
->UniqueProcessId
, KeGetCurrentIrql());
67 InitializeListHead(&Win32Process
->ClassListHead
);
68 ExInitializeFastMutex(&Win32Process
->ClassListLock
);
70 InitializeListHead(&Win32Process
->MenuListHead
);
71 ExInitializeFastMutex(&Win32Process
->MenuListLock
);
73 InitializeListHead(&Win32Process
->PrivateFontListHead
);
74 ExInitializeFastMutex(&Win32Process
->PrivateFontListLock
);
76 InitializeListHead(&Win32Process
->DriverObjListHead
);
77 ExInitializeFastMutex(&Win32Process
->DriverObjListLock
);
79 Win32Process
->KeyboardLayout
= W32kGetDefaultKeyLayout();
81 if(Process
->Peb
!= NULL
)
83 /* map the gdi handle table to user land */
84 Process
->Peb
->GdiSharedHandleTable
= GDI_MapHandleTable(Process
);
87 /* setup process flags */
88 Win32Process
->Flags
= 0;
92 DPRINT("Destroying W32 process PID:%d at IRQ level: %lu\n", Process
->UniqueProcessId
, KeGetCurrentIrql());
93 IntRemoveProcessWndProcHandles((HANDLE
)Process
->UniqueProcessId
);
94 IntCleanupMenus(Process
, Win32Process
);
95 IntCleanupCurIcons(Process
, Win32Process
);
96 IntEngCleanupDriverObjs(Process
, Win32Process
);
100 GDI_CleanupForProcess(Process
);
102 IntGraphicsCheck(FALSE
);
105 * Deregister logon application automatically
107 if(LogonProcess
== Win32Process
)
113 return STATUS_SUCCESS
;
118 Win32kThreadCallback (struct _ETHREAD
*Thread
,
121 struct _EPROCESS
*Process
;
122 PW32THREAD Win32Thread
;
124 Process
= Thread
->ThreadsProcess
;
125 Win32Thread
= Thread
->Tcb
.Win32Thread
;
128 HWINSTA hWinSta
= NULL
;
131 PUNICODE_STRING DesktopPath
;
132 PRTL_USER_PROCESS_PARAMETERS ProcessParams
= (Process
->Peb
? Process
->Peb
->ProcessParameters
: NULL
);
134 DPRINT("Creating W32 thread TID:%d at IRQ level: %lu\n", Thread
->Cid
.UniqueThread
, KeGetCurrentIrql());
137 * inherit the thread desktop and process window station (if not yet inherited) from the process startup
138 * info structure. See documentation of CreateProcess()
140 DesktopPath
= (ProcessParams
? ((ProcessParams
->DesktopInfo
.Length
> 0) ? &ProcessParams
->DesktopInfo
: NULL
) : NULL
);
141 Status
= IntParseDesktopPath(Process
,
145 if(NT_SUCCESS(Status
))
149 if(Process
!= CsrProcess
)
151 HWINSTA hProcessWinSta
= (HWINSTA
)InterlockedCompareExchangePointer((PVOID
)&Process
->Win32WindowStation
, (PVOID
)hWinSta
, NULL
);
152 if(hProcessWinSta
!= NULL
)
154 /* our process is already assigned to a different window station, we don't need the handle anymore */
164 Win32Thread
->hDesktop
= hDesk
;
166 Status
= ObReferenceObjectByHandle(hDesk
,
170 (PVOID
*)&Win32Thread
->Desktop
,
173 if(!NT_SUCCESS(Status
))
175 DPRINT1("Unable to reference thread desktop handle 0x%x\n", hDesk
);
176 Win32Thread
->Desktop
= NULL
;
181 Win32Thread
->IsExiting
= FALSE
;
182 IntDestroyCaret(Win32Thread
);
183 Win32Thread
->MessageQueue
= MsqCreateMessageQueue(Thread
);
184 Win32Thread
->KeyboardLayout
= W32kGetDefaultKeyLayout();
185 Win32Thread
->MessagePumpHookValue
= 0;
186 InitializeListHead(&Win32Thread
->WindowListHead
);
187 ExInitializeFastMutex(&Win32Thread
->WindowListLock
);
188 InitializeListHead(&Win32Thread
->W32CallbackListHead
);
192 DPRINT("Destroying W32 thread TID:%d at IRQ level: %lu\n", Thread
->Cid
.UniqueThread
, KeGetCurrentIrql());
194 Win32Thread
->IsExiting
= TRUE
;
195 HOOK_DestroyThreadHooks(Thread
);
196 UnregisterThreadHotKeys(Thread
);
197 DestroyThreadWindows(Thread
);
198 IntBlockInput(Win32Thread
, FALSE
);
199 MsqDestroyMessageQueue(Win32Thread
->MessageQueue
);
200 IntCleanupThreadCallbacks(Win32Thread
);
201 if(Win32Thread
->Desktop
!= NULL
)
203 ObDereferenceObject(Win32Thread
->Desktop
);
207 return STATUS_SUCCESS
;
213 IN PDRIVER_OBJECT DriverObject
,
214 IN PUNICODE_STRING RegistryPath
)
220 * Register user mode call interface
221 * (system service table index = 1)
223 Result
= KeAddSystemServiceTable (Win32kSSDT
,
225 Win32kNumberOfSysCalls
,
230 DPRINT1("Adding system services failed!\n");
231 return STATUS_UNSUCCESSFUL
;
235 * Register our per-process and per-thread structures.
237 PsEstablishWin32Callouts (Win32kProcessCallback
,
238 Win32kThreadCallback
,
244 Status
= IntUserCreateSharedSectionPool(48 * 1024 * 1024, /* 48 MB by default */
245 &SessionSharedSectionPool
);
246 if (!NT_SUCCESS(Status
))
248 DPRINT1("Failed to initialize the shared section pool: Status 0x%x\n", Status
);
251 Status
= InitWindowStationImpl();
252 if (!NT_SUCCESS(Status
))
254 DPRINT1("Failed to initialize window station implementation!\n");
255 return STATUS_UNSUCCESSFUL
;
258 Status
= InitClassImpl();
259 if (!NT_SUCCESS(Status
))
261 DPRINT1("Failed to initialize window class implementation!\n");
262 return STATUS_UNSUCCESSFUL
;
265 Status
= InitDesktopImpl();
266 if (!NT_SUCCESS(Status
))
268 DPRINT1("Failed to initialize desktop implementation!\n");
269 return STATUS_UNSUCCESSFUL
;
272 Status
= InitWindowImpl();
273 if (!NT_SUCCESS(Status
))
275 DPRINT1("Failed to initialize window implementation!\n");
276 return STATUS_UNSUCCESSFUL
;
279 Status
= InitMenuImpl();
280 if (!NT_SUCCESS(Status
))
282 DPRINT1("Failed to initialize menu implementation!\n");
283 return STATUS_UNSUCCESSFUL
;
286 Status
= InitInputImpl();
287 if (!NT_SUCCESS(Status
))
289 DPRINT1("Failed to initialize input implementation.\n");
293 Status
= InitKeyboardImpl();
294 if (!NT_SUCCESS(Status
))
296 DPRINT1("Failed to initialize keyboard implementation.\n");
300 Status
= InitMonitorImpl();
301 if (!NT_SUCCESS(Status
))
303 DbgPrint("Failed to initialize monitor implementation!\n");
304 return STATUS_UNSUCCESSFUL
;
307 Status
= MsqInitializeImpl();
308 if (!NT_SUCCESS(Status
))
310 DPRINT1("Failed to initialize message queue implementation.\n");
314 Status
= InitTimerImpl();
315 if (!NT_SUCCESS(Status
))
317 DPRINT1("Failed to initialize timer implementation.\n");
321 Status
= InitAcceleratorImpl();
322 if (!NT_SUCCESS(Status
))
324 DPRINT1("Failed to initialize accelerator implementation.\n");
328 Status
= InitGuiCheckImpl();
329 if (!NT_SUCCESS(Status
))
331 DPRINT1("Failed to initialize GUI check implementation.\n");
335 InitGdiObjectHandleTable ();
337 /* Initialize FreeType library */
338 if (! InitFontSupport())
340 DPRINT1("Unable to initialize font support\n");
341 return STATUS_UNSUCCESSFUL
;
344 /* Create stock objects, ie. precreated objects commonly
345 used by win32 applications */
346 CreateStockObjects();
347 CreateSysColorObjects();
349 return STATUS_SUCCESS
;
354 Win32kInitialize (VOID
)