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.57 2003/12/07 12:59:34 chorns 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/class.h>
35 #include <include/window.h>
36 #include <include/menu.h>
37 #include <include/object.h>
38 #include <include/input.h>
39 #include <include/timer.h>
40 #include <include/text.h>
41 #include <include/caret.h>
42 #include <include/hotkey.h>
43 #include <include/accelerator.h>
44 #include <include/guicheck.h>
47 #include <win32k/debug1.h>
49 extern SSDT Win32kSSDT
[];
50 extern SSPT Win32kSSPT
[];
51 extern ULONG Win32kNumberOfSysCalls
;
54 Win32kProcessCallback (struct _EPROCESS
*Process
,
57 PW32PROCESS Win32Process
;
61 DbgPrint ("Win32kProcessCallback() called\n");
64 Win32Process
= Process
->Win32Process
;
68 DbgPrint (" Create process\n");
71 InitializeListHead(&Win32Process
->ClassListHead
);
72 ExInitializeFastMutex(&Win32Process
->ClassListLock
);
74 InitializeListHead(&Win32Process
->MenuListHead
);
75 ExInitializeFastMutex(&Win32Process
->MenuListLock
);
77 Win32Process
->KeyboardLayout
= W32kGetDefaultKeyLayout();
78 Win32Process
->WindowStation
= NULL
;
79 if (Process
->Win32WindowStation
!= NULL
)
82 IntValidateWindowStationHandle(Process
->Win32WindowStation
,
85 &Win32Process
->WindowStation
);
86 if (!NT_SUCCESS(Status
))
88 DbgPrint("Win32K: Failed to reference a window station for "
93 Win32Process
->CreatedWindowOrDC
= FALSE
;
98 DbgPrint (" Destroy process\n");
99 DbgPrint (" IRQ level: %lu\n", KeGetCurrentIrql ());
101 IntRemoveProcessWndProcHandles((HANDLE
)Process
->UniqueProcessId
);
102 IntCleanupMenus(Process
, Win32Process
);
104 CleanupForProcess(Process
, Process
->UniqueProcessId
);
106 IntGraphicsCheck(FALSE
);
109 return STATUS_SUCCESS
;
114 Win32kThreadCallback (struct _ETHREAD
*Thread
,
117 struct _EPROCESS
*Process
;
118 PW32THREAD Win32Thread
;
122 DbgPrint ("Win32kThreadCallback() called\n");
125 Process
= Thread
->ThreadsProcess
;
126 Win32Thread
= Thread
->Win32Thread
;
130 DbgPrint (" Create thread\n");
133 IntDestroyCaret(Win32Thread
);
134 Win32Thread
->MessageQueue
= MsqCreateMessageQueue(Thread
);
135 Win32Thread
->KeyboardLayout
= W32kGetDefaultKeyLayout();
136 Win32Thread
->MessagePumpHookValue
= 0;
137 InitializeListHead(&Win32Thread
->WindowListHead
);
138 ExInitializeFastMutex(&Win32Thread
->WindowListLock
);
140 /* By default threads get assigned their process's desktop. */
141 Win32Thread
->Desktop
= NULL
;
142 if (Process
->Win32Desktop
!= NULL
)
144 Status
= ObReferenceObjectByHandle(Process
->Win32Desktop
,
148 (PVOID
*)&Win32Thread
->Desktop
,
150 if (!NT_SUCCESS(Status
))
152 DbgPrint("Win32K: Failed to reference a desktop for thread.\n");
159 DbgPrint (" Destroy thread\n");
162 RemoveTimersThread(Thread
->Cid
.UniqueThread
);
163 UnregisterThreadHotKeys(Thread
);
164 DestroyThreadWindows(Thread
);
167 return STATUS_SUCCESS
;
172 * This definition doesn't work
174 // WINBOOL STDCALL DllMain(VOID)
177 IN PDRIVER_OBJECT DriverObject
,
178 IN PUNICODE_STRING RegistryPath
)
183 IntInitializeWinLock();
186 * Register user mode call interface
187 * (system service table index = 1)
189 Result
= KeAddSystemServiceTable (Win32kSSDT
,
191 Win32kNumberOfSysCalls
,
196 DbgPrint("Adding system services failed!\n");
197 return STATUS_UNSUCCESSFUL
;
201 * Register our per-process and per-thread structures.
203 PsEstablishWin32Callouts (Win32kProcessCallback
,
204 Win32kThreadCallback
,
207 sizeof(W32THREAD
) + sizeof(THRDCARETINFO
),
210 WinPosSetupInternalPos();
212 Status
= InitWindowStationImpl();
213 if (!NT_SUCCESS(Status
))
215 DbgPrint("Failed to initialize window station implementation!\n");
216 return STATUS_UNSUCCESSFUL
;
219 Status
= InitClassImpl();
220 if (!NT_SUCCESS(Status
))
222 DbgPrint("Failed to initialize window class implementation!\n");
223 return STATUS_UNSUCCESSFUL
;
226 Status
= InitDesktopImpl();
227 if (!NT_SUCCESS(Status
))
229 DbgPrint("Failed to initialize window station implementation!\n");
230 return STATUS_UNSUCCESSFUL
;
233 Status
= InitWindowImpl();
234 if (!NT_SUCCESS(Status
))
236 DbgPrint("Failed to initialize window implementation!\n");
237 return STATUS_UNSUCCESSFUL
;
240 Status
= InitMenuImpl();
241 if (!NT_SUCCESS(Status
))
243 DbgPrint("Failed to initialize menu implementation!\n");
244 return STATUS_UNSUCCESSFUL
;
247 Status
= InitInputImpl();
248 if (!NT_SUCCESS(Status
))
250 DbgPrint("Failed to initialize input implementation.\n");
254 Status
= InitKeyboardImpl();
255 if (!NT_SUCCESS(Status
))
257 DbgPrint("Failed to initialize keyboard implementation.\n");
261 Status
= MsqInitializeImpl();
262 if (!NT_SUCCESS(Status
))
264 DbgPrint("Failed to initialize message queue implementation.\n");
268 Status
= InitTimerImpl();
269 if (!NT_SUCCESS(Status
))
271 DbgPrint("Failed to initialize timer implementation.\n");
275 Status
= InitAcceleratorImpl();
276 if (!NT_SUCCESS(Status
))
278 DbgPrint("Failed to initialize accelerator implementation.\n");
282 InitGdiObjectHandleTable ();
284 /* Initialize FreeType library */
285 if (! InitFontSupport())
287 DPRINT1("Unable to initialize font support\n");
288 return STATUS_UNSUCCESSFUL
;
291 /* Create stock objects, ie. precreated objects commonly
292 used by win32 applications */
293 CreateStockObjects();
295 return STATUS_SUCCESS
;
300 Win32kInitialize (VOID
)