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.
19 /* $Id: dllmain.c,v 1.75 2004/05/22 16:48:50 weiden Exp $
21 * Entry Point for win32k.sys
27 typedef NTSTATUS (STDCALL
*PW32_PROCESS_CALLBACK
)(
28 struct _EPROCESS
*Process
,
31 typedef NTSTATUS (STDCALL
*PW32_THREAD_CALLBACK
)(
32 struct _ETHREAD
*Thread
,
36 PsEstablishWin32Callouts(
37 PW32_PROCESS_CALLBACK W32ProcessCallback
,
38 PW32_THREAD_CALLBACK W32ThreadCallback
,
42 ULONG W32ProcessSize
);
45 extern SSDT Win32kSSDT
[];
46 extern SSPT Win32kSSPT
[];
47 extern ULONG Win32kNumberOfSysCalls
;
50 Win32kProcessCallback (struct _EPROCESS
*Process
,
53 PW32PROCESS Win32Process
;
57 DbgPrint ("Win32kProcessCallback() called\n");
60 Win32Process
= Process
->Win32Process
;
64 DbgPrint (" Create process\n");
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
->CursorIconListHead
);
77 ExInitializeFastMutex(&Win32Process
->CursorIconListLock
);
79 Win32Process
->KeyboardLayout
= W32kGetDefaultKeyLayout();
80 Win32Process
->WindowStation
= NULL
;
81 if (Process
->Win32WindowStation
!= NULL
)
84 IntValidateWindowStationHandle(Process
->Win32WindowStation
,
87 &Win32Process
->WindowStation
);
88 if (!NT_SUCCESS(Status
))
90 DbgPrint("Win32K: Failed to reference a window station for "
95 /* setup process flags */
96 Win32Process
->Flags
= 0;
101 DbgPrint (" Destroy process\n");
102 DbgPrint (" IRQ level: %lu\n", KeGetCurrentIrql ());
104 IntRemoveProcessWndProcHandles((HANDLE
)Process
->UniqueProcessId
);
105 IntCleanupMenus(Process
, Win32Process
);
106 IntCleanupCurIcons(Process
, Win32Process
);
108 CleanupForProcess(Process
, Process
->UniqueProcessId
);
110 IntGraphicsCheck(FALSE
);
113 * Deregister logon application automatically
115 if(LogonProcess
== Win32Process
)
121 return STATUS_SUCCESS
;
126 Win32kThreadCallback (struct _ETHREAD
*Thread
,
129 struct _EPROCESS
*Process
;
130 PW32THREAD Win32Thread
;
134 DbgPrint ("Win32kThreadCallback() called\n");
137 Process
= Thread
->ThreadsProcess
;
138 Win32Thread
= Thread
->Win32Thread
;
142 DbgPrint (" Create thread\n");
145 Win32Thread
->IsExiting
= FALSE
;
146 IntDestroyCaret(Win32Thread
);
147 Win32Thread
->MessageQueue
= MsqCreateMessageQueue(Thread
);
148 Win32Thread
->KeyboardLayout
= W32kGetDefaultKeyLayout();
149 Win32Thread
->MessagePumpHookValue
= 0;
150 InitializeListHead(&Win32Thread
->WindowListHead
);
151 ExInitializeFastMutex(&Win32Thread
->WindowListLock
);
153 /* By default threads get assigned their process's desktop. */
154 Win32Thread
->Desktop
= NULL
;
155 Win32Thread
->hDesktop
= NULL
;
156 if (Process
->Win32Desktop
!= NULL
)
158 Status
= ObReferenceObjectByHandle(Process
->Win32Desktop
,
162 (PVOID
*)&Win32Thread
->Desktop
,
164 if (!NT_SUCCESS(Status
))
166 DbgPrint("Win32K: Failed to reference a desktop for thread.\n");
169 Win32Thread
->hDesktop
= Process
->Win32Desktop
;
175 DbgPrint (" Destroy thread\n");
178 Win32Thread
->IsExiting
= TRUE
;
179 HOOK_DestroyThreadHooks(Thread
);
180 RemoveTimersThread(Thread
->Cid
.UniqueThread
);
181 UnregisterThreadHotKeys(Thread
);
182 DestroyThreadWindows(Thread
);
183 IntBlockInput(Win32Thread
, FALSE
);
184 MsqDestroyMessageQueue(Win32Thread
->MessageQueue
);
187 return STATUS_SUCCESS
;
192 * This definition doesn't work
194 // BOOL STDCALL DllMain(VOID)
197 IN PDRIVER_OBJECT DriverObject
,
198 IN PUNICODE_STRING RegistryPath
)
204 * Register user mode call interface
205 * (system service table index = 1)
207 Result
= KeAddSystemServiceTable (Win32kSSDT
,
209 Win32kNumberOfSysCalls
,
214 DbgPrint("Adding system services failed!\n");
215 return STATUS_UNSUCCESSFUL
;
219 * Register our per-process and per-thread structures.
221 PsEstablishWin32Callouts (Win32kProcessCallback
,
222 Win32kThreadCallback
,
228 Status
= InitWindowStationImpl();
229 if (!NT_SUCCESS(Status
))
231 DbgPrint("Failed to initialize window station implementation!\n");
232 return STATUS_UNSUCCESSFUL
;
235 Status
= InitClassImpl();
236 if (!NT_SUCCESS(Status
))
238 DbgPrint("Failed to initialize window class implementation!\n");
239 return STATUS_UNSUCCESSFUL
;
242 Status
= InitDesktopImpl();
243 if (!NT_SUCCESS(Status
))
245 DbgPrint("Failed to initialize window station implementation!\n");
246 return STATUS_UNSUCCESSFUL
;
249 Status
= InitWindowImpl();
250 if (!NT_SUCCESS(Status
))
252 DbgPrint("Failed to initialize window implementation!\n");
253 return STATUS_UNSUCCESSFUL
;
256 Status
= InitMenuImpl();
257 if (!NT_SUCCESS(Status
))
259 DbgPrint("Failed to initialize menu implementation!\n");
260 return STATUS_UNSUCCESSFUL
;
263 Status
= InitInputImpl();
264 if (!NT_SUCCESS(Status
))
266 DbgPrint("Failed to initialize input implementation.\n");
270 Status
= InitKeyboardImpl();
271 if (!NT_SUCCESS(Status
))
273 DbgPrint("Failed to initialize keyboard implementation.\n");
277 Status
= MsqInitializeImpl();
278 if (!NT_SUCCESS(Status
))
280 DbgPrint("Failed to initialize message queue implementation.\n");
284 Status
= InitTimerImpl();
285 if (!NT_SUCCESS(Status
))
287 DbgPrint("Failed to initialize timer implementation.\n");
291 Status
= InitAcceleratorImpl();
292 if (!NT_SUCCESS(Status
))
294 DbgPrint("Failed to initialize accelerator implementation.\n");
298 InitGdiObjectHandleTable ();
300 /* Initialize FreeType library */
301 if (! InitFontSupport())
303 DPRINT1("Unable to initialize font support\n");
304 return STATUS_UNSUCCESSFUL
;
307 /* Create stock objects, ie. precreated objects commonly
308 used by win32 applications */
309 CreateStockObjects();
313 return STATUS_SUCCESS
;
318 Win32kInitialize (VOID
)