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>
29 BOOL INTERNAL_CALL
GDI_CleanupForProcess (struct _EPROCESS
*Process
);
31 extern SSDT Win32kSSDT
[];
32 extern SSPT Win32kSSPT
[];
33 extern ULONG Win32kNumberOfSysCalls
;
35 PSHARED_SECTION_POOL SessionSharedSectionPool
= NULL
;
38 Win32kProcessCallback (struct _EPROCESS
*Process
,
41 PW32PROCESS Win32Process
;
43 Win32Process
= (PW32PROCESS
)Process
->Win32Process
;
46 DPRINT("Creating W32 process PID:%d at IRQ level: %lu\n", Process
->UniqueProcessId
, KeGetCurrentIrql());
48 InitializeListHead(&Win32Process
->ClassListHead
);
49 ExInitializeFastMutex(&Win32Process
->ClassListLock
);
51 InitializeListHead(&Win32Process
->MenuListHead
);
52 ExInitializeFastMutex(&Win32Process
->MenuListLock
);
54 InitializeListHead(&Win32Process
->PrivateFontListHead
);
55 ExInitializeFastMutex(&Win32Process
->PrivateFontListLock
);
57 InitializeListHead(&Win32Process
->DriverObjListHead
);
58 ExInitializeFastMutex(&Win32Process
->DriverObjListLock
);
60 Win32Process
->KeyboardLayout
= W32kGetDefaultKeyLayout();
62 if(Process
->Peb
!= NULL
)
64 /* map the gdi handle table to user land */
65 Process
->Peb
->GdiSharedHandleTable
= GDI_MapHandleTable(Process
);
68 /* setup process flags */
69 Win32Process
->Flags
= 0;
73 DPRINT("Destroying W32 process PID:%d at IRQ level: %lu\n", Process
->UniqueProcessId
, KeGetCurrentIrql());
74 IntRemoveProcessWndProcHandles((HANDLE
)Process
->UniqueProcessId
);
75 IntCleanupMenus(Process
, Win32Process
);
76 IntCleanupCurIcons(Process
, Win32Process
);
77 IntEngCleanupDriverObjs(Process
, Win32Process
);
81 GDI_CleanupForProcess(Process
);
83 IntGraphicsCheck(FALSE
);
86 * Deregister logon application automatically
88 if(LogonProcess
== Win32Process
)
94 return STATUS_SUCCESS
;
99 Win32kThreadCallback (struct _ETHREAD
*Thread
,
102 struct _EPROCESS
*Process
;
103 PW32THREAD Win32Thread
;
105 Process
= Thread
->ThreadsProcess
;
106 Win32Thread
= Thread
->Tcb
.Win32Thread
;
109 HWINSTA hWinSta
= NULL
;
112 PUNICODE_STRING DesktopPath
;
113 PRTL_USER_PROCESS_PARAMETERS ProcessParams
= (Process
->Peb
? Process
->Peb
->ProcessParameters
: NULL
);
115 DPRINT("Creating W32 thread TID:%d at IRQ level: %lu\n", Thread
->Cid
.UniqueThread
, KeGetCurrentIrql());
118 * inherit the thread desktop and process window station (if not yet inherited) from the process startup
119 * info structure. See documentation of CreateProcess()
121 DesktopPath
= (ProcessParams
? ((ProcessParams
->DesktopInfo
.Length
> 0) ? &ProcessParams
->DesktopInfo
: NULL
) : NULL
);
122 Status
= IntParseDesktopPath(Process
,
126 if(NT_SUCCESS(Status
))
130 if(Process
!= CsrProcess
)
132 HWINSTA hProcessWinSta
= (HWINSTA
)InterlockedCompareExchangePointer((PVOID
)&Process
->Win32WindowStation
, (PVOID
)hWinSta
, NULL
);
133 if(hProcessWinSta
!= NULL
)
135 /* our process is already assigned to a different window station, we don't need the handle anymore */
147 Status
= ObReferenceObjectByHandle(hDesk
,
151 (PVOID
*)&Win32Thread
->Desktop
,
154 if(!NT_SUCCESS(Status
))
156 DPRINT1("Unable to reference thread desktop handle 0x%x\n", hDesk
);
157 Win32Thread
->Desktop
= NULL
;
161 Win32Thread
->IsExiting
= FALSE
;
162 IntDestroyCaret(Win32Thread
);
163 Win32Thread
->MessageQueue
= MsqCreateMessageQueue(Thread
);
164 Win32Thread
->KeyboardLayout
= W32kGetDefaultKeyLayout();
165 Win32Thread
->MessagePumpHookValue
= 0;
166 InitializeListHead(&Win32Thread
->WindowListHead
);
167 ExInitializeFastMutex(&Win32Thread
->WindowListLock
);
168 InitializeListHead(&Win32Thread
->W32CallbackListHead
);
172 DPRINT("Destroying W32 thread TID:%d at IRQ level: %lu\n", Thread
->Cid
.UniqueThread
, KeGetCurrentIrql());
174 Win32Thread
->IsExiting
= TRUE
;
175 HOOK_DestroyThreadHooks(Thread
);
176 UnregisterThreadHotKeys(Thread
);
177 DestroyThreadWindows(Thread
);
178 IntBlockInput(Win32Thread
, FALSE
);
179 MsqDestroyMessageQueue(Win32Thread
->MessageQueue
);
180 IntCleanupThreadCallbacks(Win32Thread
);
181 if(Win32Thread
->Desktop
!= NULL
)
183 ObDereferenceObject(Win32Thread
->Desktop
);
187 return STATUS_SUCCESS
;
190 /* Only used in ntuser/input.c KeyboardThreadMain(). If it's
191 not called there anymore, please delete */
193 Win32kInitWin32Thread(PETHREAD Thread
)
197 Process
= Thread
->ThreadsProcess
;
199 if (Process
->Win32Process
== NULL
)
201 /* FIXME - lock the process */
202 Process
->Win32Process
= ExAllocatePool(NonPagedPool
, sizeof(W32PROCESS
));
204 if (Process
->Win32Process
== NULL
)
205 return STATUS_NO_MEMORY
;
207 RtlZeroMemory(Process
->Win32Process
, sizeof(W32PROCESS
));
208 /* FIXME - unlock the process */
210 Win32kProcessCallback(Process
, TRUE
);
213 if (Thread
->Tcb
.Win32Thread
== NULL
)
215 Thread
->Tcb
.Win32Thread
= ExAllocatePool (NonPagedPool
, sizeof(W32THREAD
));
216 if (Thread
->Tcb
.Win32Thread
== NULL
)
217 return STATUS_NO_MEMORY
;
219 RtlZeroMemory(Thread
->Tcb
.Win32Thread
, sizeof(W32THREAD
));
221 Win32kThreadCallback(Thread
, TRUE
);
224 return(STATUS_SUCCESS
);
229 * This definition doesn't work
233 IN PDRIVER_OBJECT DriverObject
,
234 IN PUNICODE_STRING RegistryPath
)
238 W32_OBJECT_CALLBACK Win32kObjectCallbacks
;
241 * Register user mode call interface
242 * (system service table index = 1)
244 Result
= KeAddSystemServiceTable (Win32kSSDT
,
246 Win32kNumberOfSysCalls
,
251 DPRINT1("Adding system services failed!\n");
252 return STATUS_UNSUCCESSFUL
;
256 * Register Object Manager Callbacks
258 Win32kObjectCallbacks
.WinStaCreate
= IntWinStaObjectOpen
;
259 Win32kObjectCallbacks
.WinStaParse
= IntWinStaObjectParse
;
260 Win32kObjectCallbacks
.WinStaDelete
= IntWinStaObjectDelete
;
261 Win32kObjectCallbacks
.WinStaFind
= IntWinStaObjectFind
;
262 Win32kObjectCallbacks
.DesktopCreate
= IntDesktopObjectCreate
;
263 Win32kObjectCallbacks
.DesktopDelete
= IntDesktopObjectDelete
;
265 * Register our per-process and per-thread structures.
267 PsEstablishWin32Callouts (Win32kProcessCallback
,
268 Win32kThreadCallback
,
269 &Win32kObjectCallbacks
,
274 Status
= IntUserCreateSharedSectionPool(48 * 1024 * 1024, /* 48 MB by default */
275 &SessionSharedSectionPool
);
276 if (!NT_SUCCESS(Status
))
278 DPRINT1("Failed to initialize the shared section pool: Status 0x%x\n", Status
);
281 Status
= InitWindowStationImpl();
282 if (!NT_SUCCESS(Status
))
284 DPRINT1("Failed to initialize window station implementation!\n");
285 return STATUS_UNSUCCESSFUL
;
288 Status
= InitClassImpl();
289 if (!NT_SUCCESS(Status
))
291 DPRINT1("Failed to initialize window class implementation!\n");
292 return STATUS_UNSUCCESSFUL
;
295 Status
= InitDesktopImpl();
296 if (!NT_SUCCESS(Status
))
298 DPRINT1("Failed to initialize desktop implementation!\n");
299 return STATUS_UNSUCCESSFUL
;
302 Status
= InitWindowImpl();
303 if (!NT_SUCCESS(Status
))
305 DPRINT1("Failed to initialize window implementation!\n");
306 return STATUS_UNSUCCESSFUL
;
309 Status
= InitMenuImpl();
310 if (!NT_SUCCESS(Status
))
312 DPRINT1("Failed to initialize menu implementation!\n");
313 return STATUS_UNSUCCESSFUL
;
316 Status
= InitInputImpl();
317 if (!NT_SUCCESS(Status
))
319 DPRINT1("Failed to initialize input implementation.\n");
323 Status
= InitKeyboardImpl();
324 if (!NT_SUCCESS(Status
))
326 DPRINT1("Failed to initialize keyboard implementation.\n");
330 Status
= InitMonitorImpl();
331 if (!NT_SUCCESS(Status
))
333 DbgPrint("Failed to initialize monitor implementation!\n");
334 return STATUS_UNSUCCESSFUL
;
337 Status
= MsqInitializeImpl();
338 if (!NT_SUCCESS(Status
))
340 DPRINT1("Failed to initialize message queue implementation.\n");
344 Status
= InitTimerImpl();
345 if (!NT_SUCCESS(Status
))
347 DPRINT1("Failed to initialize timer implementation.\n");
351 Status
= InitAcceleratorImpl();
352 if (!NT_SUCCESS(Status
))
354 DPRINT1("Failed to initialize accelerator implementation.\n");
358 Status
= InitGuiCheckImpl();
359 if (!NT_SUCCESS(Status
))
361 DPRINT1("Failed to initialize GUI check implementation.\n");
365 InitGdiObjectHandleTable ();
367 /* Initialize FreeType library */
368 if (! InitFontSupport())
370 DPRINT1("Unable to initialize font support\n");
371 return STATUS_UNSUCCESSFUL
;
374 /* Create stock objects, ie. precreated objects commonly
375 used by win32 applications */
376 CreateStockObjects();
377 CreateSysColorObjects();
379 return STATUS_SUCCESS
;
384 Win32kInitialize (VOID
)