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
,
42 PW32_OBJECT_CALLBACK W32ObjectCallback
,
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
= (PW32PROCESS
)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 */
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
;
180 Win32Thread
->IsExiting
= FALSE
;
181 IntDestroyCaret(Win32Thread
);
182 Win32Thread
->MessageQueue
= MsqCreateMessageQueue(Thread
);
183 Win32Thread
->KeyboardLayout
= W32kGetDefaultKeyLayout();
184 Win32Thread
->MessagePumpHookValue
= 0;
185 InitializeListHead(&Win32Thread
->WindowListHead
);
186 ExInitializeFastMutex(&Win32Thread
->WindowListLock
);
187 InitializeListHead(&Win32Thread
->W32CallbackListHead
);
191 DPRINT("Destroying W32 thread TID:%d at IRQ level: %lu\n", Thread
->Cid
.UniqueThread
, KeGetCurrentIrql());
193 Win32Thread
->IsExiting
= TRUE
;
194 HOOK_DestroyThreadHooks(Thread
);
195 UnregisterThreadHotKeys(Thread
);
196 DestroyThreadWindows(Thread
);
197 IntBlockInput(Win32Thread
, FALSE
);
198 MsqDestroyMessageQueue(Win32Thread
->MessageQueue
);
199 IntCleanupThreadCallbacks(Win32Thread
);
200 if(Win32Thread
->Desktop
!= NULL
)
202 ObDereferenceObject(Win32Thread
->Desktop
);
206 return STATUS_SUCCESS
;
209 /* Only used in ntuser/input.c KeyboardThreadMain(). If it's
210 not called there anymore, please delete */
212 Win32kInitWin32Thread(PETHREAD Thread
)
216 Process
= Thread
->ThreadsProcess
;
218 if (Process
->Win32Process
== NULL
)
220 /* FIXME - lock the process */
221 Process
->Win32Process
= ExAllocatePool(NonPagedPool
, sizeof(W32PROCESS
));
223 if (Process
->Win32Process
== NULL
)
224 return STATUS_NO_MEMORY
;
226 RtlZeroMemory(Process
->Win32Process
, sizeof(W32PROCESS
));
227 /* FIXME - unlock the process */
229 Win32kProcessCallback(Process
, TRUE
);
232 if (Thread
->Tcb
.Win32Thread
== NULL
)
234 Thread
->Tcb
.Win32Thread
= ExAllocatePool (NonPagedPool
, sizeof(W32THREAD
));
235 if (Thread
->Tcb
.Win32Thread
== NULL
)
236 return STATUS_NO_MEMORY
;
238 RtlZeroMemory(Thread
->Tcb
.Win32Thread
, sizeof(W32THREAD
));
240 Win32kThreadCallback(Thread
, TRUE
);
243 return(STATUS_SUCCESS
);
249 IN PDRIVER_OBJECT DriverObject
,
250 IN PUNICODE_STRING RegistryPath
)
254 W32_OBJECT_CALLBACK Win32kObjectCallbacks
;
257 * Register user mode call interface
258 * (system service table index = 1)
260 Result
= KeAddSystemServiceTable (Win32kSSDT
,
262 Win32kNumberOfSysCalls
,
267 DPRINT1("Adding system services failed!\n");
268 return STATUS_UNSUCCESSFUL
;
272 * Register Object Manager Callbacks
274 Win32kObjectCallbacks
.WinStaCreate
= IntWinStaObjectOpen
;
275 Win32kObjectCallbacks
.WinStaParse
= IntWinStaObjectParse
;
276 Win32kObjectCallbacks
.WinStaDelete
= IntWinStaObjectDelete
;
277 Win32kObjectCallbacks
.WinStaFind
= IntWinStaObjectFind
;
278 Win32kObjectCallbacks
.DesktopCreate
= IntDesktopObjectCreate
;
279 Win32kObjectCallbacks
.DesktopDelete
= IntDesktopObjectDelete
;
281 * Register our per-process and per-thread structures.
283 PsEstablishWin32Callouts (Win32kProcessCallback
,
284 Win32kThreadCallback
,
285 &Win32kObjectCallbacks
,
290 Status
= IntUserCreateSharedSectionPool(48 * 1024 * 1024, /* 48 MB by default */
291 &SessionSharedSectionPool
);
292 if (!NT_SUCCESS(Status
))
294 DPRINT1("Failed to initialize the shared section pool: Status 0x%x\n", Status
);
297 Status
= InitWindowStationImpl();
298 if (!NT_SUCCESS(Status
))
300 DPRINT1("Failed to initialize window station implementation!\n");
301 return STATUS_UNSUCCESSFUL
;
304 Status
= InitClassImpl();
305 if (!NT_SUCCESS(Status
))
307 DPRINT1("Failed to initialize window class implementation!\n");
308 return STATUS_UNSUCCESSFUL
;
311 Status
= InitDesktopImpl();
312 if (!NT_SUCCESS(Status
))
314 DPRINT1("Failed to initialize desktop implementation!\n");
315 return STATUS_UNSUCCESSFUL
;
318 Status
= InitWindowImpl();
319 if (!NT_SUCCESS(Status
))
321 DPRINT1("Failed to initialize window implementation!\n");
322 return STATUS_UNSUCCESSFUL
;
325 Status
= InitMenuImpl();
326 if (!NT_SUCCESS(Status
))
328 DPRINT1("Failed to initialize menu implementation!\n");
329 return STATUS_UNSUCCESSFUL
;
332 Status
= InitInputImpl();
333 if (!NT_SUCCESS(Status
))
335 DPRINT1("Failed to initialize input implementation.\n");
339 Status
= InitKeyboardImpl();
340 if (!NT_SUCCESS(Status
))
342 DPRINT1("Failed to initialize keyboard implementation.\n");
346 Status
= InitMonitorImpl();
347 if (!NT_SUCCESS(Status
))
349 DbgPrint("Failed to initialize monitor implementation!\n");
350 return STATUS_UNSUCCESSFUL
;
353 Status
= MsqInitializeImpl();
354 if (!NT_SUCCESS(Status
))
356 DPRINT1("Failed to initialize message queue implementation.\n");
360 Status
= InitTimerImpl();
361 if (!NT_SUCCESS(Status
))
363 DPRINT1("Failed to initialize timer implementation.\n");
367 Status
= InitAcceleratorImpl();
368 if (!NT_SUCCESS(Status
))
370 DPRINT1("Failed to initialize accelerator implementation.\n");
374 Status
= InitGuiCheckImpl();
375 if (!NT_SUCCESS(Status
))
377 DPRINT1("Failed to initialize GUI check implementation.\n");
381 InitGdiObjectHandleTable ();
383 /* Initialize FreeType library */
384 if (! InitFontSupport())
386 DPRINT1("Unable to initialize font support\n");
387 return STATUS_UNSUCCESSFUL
;
390 /* Create stock objects, ie. precreated objects commonly
391 used by win32 applications */
392 CreateStockObjects();
393 CreateSysColorObjects();
395 return STATUS_SUCCESS
;
400 Win32kInitialize (VOID
)