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.67 2004/02/24 01:30:57 weiden Exp $
21 * Entry Point for win32k.sys
24 #undef WIN32_LEAN_AND_MEAN
25 #define WIN32_NO_STATUS
27 #define NTOS_MODE_KERNEL
29 #include <ddk/winddi.h>
31 #include <win32k/win32k.h>
33 #include <include/winsta.h>
34 #include <include/desktop.h>
35 #include <include/class.h>
36 #include <include/window.h>
37 #include <include/menu.h>
38 #include <include/object.h>
39 #include <include/input.h>
40 #include <include/timer.h>
41 #include <include/text.h>
42 #include <include/caret.h>
43 #include <include/hotkey.h>
44 #include <include/accelerator.h>
45 #include <include/cursoricon.h>
46 #include <include/guicheck.h>
47 #include <include/hook.h>
50 #include <win32k/debug1.h>
52 extern SSDT Win32kSSDT
[];
53 extern SSPT Win32kSSPT
[];
54 extern ULONG Win32kNumberOfSysCalls
;
57 Win32kProcessCallback (struct _EPROCESS
*Process
,
60 PW32PROCESS Win32Process
;
64 DbgPrint ("Win32kProcessCallback() called\n");
67 Win32Process
= Process
->Win32Process
;
71 DbgPrint (" Create process\n");
74 InitializeListHead(&Win32Process
->ClassListHead
);
75 ExInitializeFastMutex(&Win32Process
->ClassListLock
);
77 InitializeListHead(&Win32Process
->MenuListHead
);
78 ExInitializeFastMutex(&Win32Process
->MenuListLock
);
80 InitializeListHead(&Win32Process
->PrivateFontListHead
);
81 ExInitializeFastMutex(&Win32Process
->PrivateFontListLock
);
83 InitializeListHead(&Win32Process
->CursorIconListHead
);
84 ExInitializeFastMutex(&Win32Process
->CursorIconListLock
);
86 Win32Process
->KeyboardLayout
= W32kGetDefaultKeyLayout();
87 Win32Process
->WindowStation
= NULL
;
88 if (Process
->Win32WindowStation
!= NULL
)
91 IntValidateWindowStationHandle(Process
->Win32WindowStation
,
94 &Win32Process
->WindowStation
);
95 if (!NT_SUCCESS(Status
))
97 DbgPrint("Win32K: Failed to reference a window station for "
102 Win32Process
->CreatedWindowOrDC
= FALSE
;
103 Win32Process
->ManualGuiCheck
= FALSE
;
108 DbgPrint (" Destroy process\n");
109 DbgPrint (" IRQ level: %lu\n", KeGetCurrentIrql ());
111 IntRemoveProcessWndProcHandles((HANDLE
)Process
->UniqueProcessId
);
112 IntCleanupMenus(Process
, Win32Process
);
113 IntCleanupCurIcons(Process
, Win32Process
);
115 CleanupForProcess(Process
, Process
->UniqueProcessId
);
117 IntGraphicsCheck(FALSE
);
120 return STATUS_SUCCESS
;
125 Win32kThreadCallback (struct _ETHREAD
*Thread
,
128 struct _EPROCESS
*Process
;
129 PW32THREAD Win32Thread
;
133 DbgPrint ("Win32kThreadCallback() called\n");
136 Process
= Thread
->ThreadsProcess
;
137 Win32Thread
= Thread
->Win32Thread
;
141 DbgPrint (" Create thread\n");
144 Win32Thread
->IsExiting
= FALSE
;
145 IntDestroyCaret(Win32Thread
);
146 Win32Thread
->MessageQueue
= MsqCreateMessageQueue(Thread
);
147 Win32Thread
->KeyboardLayout
= W32kGetDefaultKeyLayout();
148 Win32Thread
->MessagePumpHookValue
= 0;
149 InitializeListHead(&Win32Thread
->WindowListHead
);
150 ExInitializeFastMutex(&Win32Thread
->WindowListLock
);
152 /* By default threads get assigned their process's desktop. */
153 Win32Thread
->Desktop
= NULL
;
154 if (Process
->Win32Desktop
!= NULL
)
156 Status
= ObReferenceObjectByHandle(Process
->Win32Desktop
,
160 (PVOID
*)&Win32Thread
->Desktop
,
162 if (!NT_SUCCESS(Status
))
164 DbgPrint("Win32K: Failed to reference a desktop for thread.\n");
171 DbgPrint (" Destroy thread\n");
174 Win32Thread
->IsExiting
= TRUE
;
175 HOOK_DestroyThreadHooks(Thread
);
176 RemoveTimersThread(Thread
->Cid
.UniqueThread
);
177 UnregisterThreadHotKeys(Thread
);
178 DestroyThreadWindows(Thread
);
181 return STATUS_SUCCESS
;
186 * This definition doesn't work
188 // BOOL STDCALL DllMain(VOID)
191 IN PDRIVER_OBJECT DriverObject
,
192 IN PUNICODE_STRING RegistryPath
)
198 * Register user mode call interface
199 * (system service table index = 1)
201 Result
= KeAddSystemServiceTable (Win32kSSDT
,
203 Win32kNumberOfSysCalls
,
208 DbgPrint("Adding system services failed!\n");
209 return STATUS_UNSUCCESSFUL
;
213 * Register our per-process and per-thread structures.
215 PsEstablishWin32Callouts (Win32kProcessCallback
,
216 Win32kThreadCallback
,
222 Status
= InitWindowStationImpl();
223 if (!NT_SUCCESS(Status
))
225 DbgPrint("Failed to initialize window station implementation!\n");
226 return STATUS_UNSUCCESSFUL
;
229 Status
= InitClassImpl();
230 if (!NT_SUCCESS(Status
))
232 DbgPrint("Failed to initialize window class implementation!\n");
233 return STATUS_UNSUCCESSFUL
;
236 Status
= InitDesktopImpl();
237 if (!NT_SUCCESS(Status
))
239 DbgPrint("Failed to initialize window station implementation!\n");
240 return STATUS_UNSUCCESSFUL
;
243 Status
= InitWindowImpl();
244 if (!NT_SUCCESS(Status
))
246 DbgPrint("Failed to initialize window implementation!\n");
247 return STATUS_UNSUCCESSFUL
;
250 Status
= InitMenuImpl();
251 if (!NT_SUCCESS(Status
))
253 DbgPrint("Failed to initialize menu implementation!\n");
254 return STATUS_UNSUCCESSFUL
;
257 Status
= InitInputImpl();
258 if (!NT_SUCCESS(Status
))
260 DbgPrint("Failed to initialize input implementation.\n");
264 Status
= InitKeyboardImpl();
265 if (!NT_SUCCESS(Status
))
267 DbgPrint("Failed to initialize keyboard implementation.\n");
271 Status
= MsqInitializeImpl();
272 if (!NT_SUCCESS(Status
))
274 DbgPrint("Failed to initialize message queue implementation.\n");
278 Status
= InitTimerImpl();
279 if (!NT_SUCCESS(Status
))
281 DbgPrint("Failed to initialize timer implementation.\n");
285 Status
= InitAcceleratorImpl();
286 if (!NT_SUCCESS(Status
))
288 DbgPrint("Failed to initialize accelerator implementation.\n");
292 InitGdiObjectHandleTable ();
294 /* Initialize FreeType library */
295 if (! InitFontSupport())
297 DPRINT1("Unable to initialize font support\n");
298 return STATUS_UNSUCCESSFUL
;
301 /* Create stock objects, ie. precreated objects commonly
302 used by win32 applications */
303 CreateStockObjects();
305 return STATUS_SUCCESS
;
310 Win32kInitialize (VOID
)