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.46 2003/10/16 22:07:37 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/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>
44 #include <win32k/debug1.h>
46 extern SSDT Win32kSSDT
[];
47 extern SSPT Win32kSSPT
[];
48 extern ULONG Win32kNumberOfSysCalls
;
50 PEPROCESS Win32kDeviceProcess
;
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 ValidateWindowStationHandle(Process
->Win32WindowStation
,
85 &Win32Process
->WindowStation
);
86 if (!NT_SUCCESS(Status
))
88 DbgPrint("Win32K: Failed to reference a window station for "
96 DbgPrint (" Destroy process\n");
97 DbgPrint (" IRQ level: %lu\n", KeGetCurrentIrql ());
100 IntCleanupMenus(Process
, Win32Process
);
102 CleanupForProcess(Process
, Process
->UniqueProcessId
);
105 return STATUS_SUCCESS
;
110 Win32kThreadCallback (struct _ETHREAD
*Thread
,
113 struct _EPROCESS
*Process
;
114 PW32THREAD Win32Thread
;
118 DbgPrint ("Win32kThreadCallback() called\n");
121 Process
= Thread
->ThreadsProcess
;
122 Win32Thread
= Thread
->Win32Thread
;
126 DbgPrint (" Create thread\n");
129 IntDestroyCaret(Win32Thread
);
130 Win32Thread
->MessageQueue
= MsqCreateMessageQueue();
131 Win32Thread
->KeyboardLayout
= W32kGetDefaultKeyLayout();
132 InitializeListHead(&Win32Thread
->WindowListHead
);
133 ExInitializeFastMutex(&Win32Thread
->WindowListLock
);
135 /* By default threads get assigned their process's desktop. */
136 Win32Thread
->Desktop
= NULL
;
137 if (Process
->Win32Desktop
!= NULL
)
139 Status
= ObReferenceObjectByHandle(Process
->Win32Desktop
,
143 (PVOID
*)&Win32Thread
->Desktop
,
145 if (!NT_SUCCESS(Status
))
147 DbgPrint("Win32K: Failed to reference a desktop for thread.\n");
154 DbgPrint (" Destroy thread\n");
157 RemoveTimersThread(Thread
->Cid
.UniqueThread
);
158 DestroyThreadWindows(Thread
);
161 return STATUS_SUCCESS
;
166 * This definition doesn't work
168 // WINBOOL STDCALL DllMain(VOID)
172 IN PDRIVER_OBJECT DriverObject
,
173 IN PUNICODE_STRING RegistryPath
)
178 IntInitializeWinLock();
181 * Register user mode call interface
182 * (system service table index = 1)
184 Result
= KeAddSystemServiceTable (Win32kSSDT
,
186 Win32kNumberOfSysCalls
,
191 DbgPrint("Adding system services failed!\n");
192 return STATUS_UNSUCCESSFUL
;
196 * Register our per-process and per-thread structures.
198 PsEstablishWin32Callouts (Win32kProcessCallback
,
199 Win32kThreadCallback
,
202 sizeof(W32THREAD
) + sizeof(THRDCARETINFO
),
205 WinPosSetupInternalPos();
207 Status
= InitWindowStationImpl();
208 if (!NT_SUCCESS(Status
))
210 DbgPrint("Failed to initialize window station implementation!\n");
211 return STATUS_UNSUCCESSFUL
;
214 Status
= InitClassImpl();
215 if (!NT_SUCCESS(Status
))
217 DbgPrint("Failed to initialize window class implementation!\n");
218 return STATUS_UNSUCCESSFUL
;
221 Status
= InitWindowImpl();
222 if (!NT_SUCCESS(Status
))
224 DbgPrint("Failed to initialize window implementation!\n");
225 return STATUS_UNSUCCESSFUL
;
228 Status
= InitMenuImpl();
229 if (!NT_SUCCESS(Status
))
231 DbgPrint("Failed to initialize menu implementation!\n");
232 return STATUS_UNSUCCESSFUL
;
235 Status
= InitInputImpl();
236 if (!NT_SUCCESS(Status
))
238 DbgPrint("Failed to initialize input implementation.\n");
242 Status
= MsqInitializeImpl();
243 if (!NT_SUCCESS(Status
))
245 DbgPrint("Failed to initialize message queue implementation.\n");
249 Status
= InitTimerImpl();
250 if (!NT_SUCCESS(Status
))
252 DbgPrint("Failed to initialize timer implementation.\n");
256 return STATUS_SUCCESS
;
262 Win32kInitialize (VOID
)
264 DPRINT("in Win32kInitialize\n");
266 Win32kDeviceProcess
= PsGetCurrentProcess();
268 InitGdiObjectHandleTable ();
270 // Initialize FreeType library
271 if(!InitFontSupport()) return FALSE
;
273 // Create stock objects, ie. precreated objects commonly used by win32 applications
274 CreateStockObjects();