2003-12-07 Casper S. Hornstrup <chorns@users.sourceforge.net>
[reactos.git] / reactos / subsys / win32k / main / dllmain.c
1 /*
2 * ReactOS W32 Subsystem
3 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
4 *
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.
9 *
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.
14 *
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.
18 */
19 /* $Id: dllmain.c,v 1.57 2003/12/07 12:59:34 chorns Exp $
20 *
21 * Entry Point for win32k.sys
22 */
23
24 #undef WIN32_LEAN_AND_MEAN
25 #define WIN32_NO_STATUS
26 #include <windows.h>
27 #define NTOS_MODE_KERNEL
28 #include <ntos.h>
29 #include <ddk/winddi.h>
30
31 #include <win32k/win32k.h>
32
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>
45
46 #define NDEBUG
47 #include <win32k/debug1.h>
48
49 extern SSDT Win32kSSDT[];
50 extern SSPT Win32kSSPT[];
51 extern ULONG Win32kNumberOfSysCalls;
52
53 NTSTATUS STDCALL
54 Win32kProcessCallback (struct _EPROCESS *Process,
55 BOOLEAN Create)
56 {
57 PW32PROCESS Win32Process;
58 NTSTATUS Status;
59
60 #if 0
61 DbgPrint ("Win32kProcessCallback() called\n");
62 #endif
63
64 Win32Process = Process->Win32Process;
65 if (Create)
66 {
67 #if 0
68 DbgPrint (" Create process\n");
69 #endif
70
71 InitializeListHead(&Win32Process->ClassListHead);
72 ExInitializeFastMutex(&Win32Process->ClassListLock);
73
74 InitializeListHead(&Win32Process->MenuListHead);
75 ExInitializeFastMutex(&Win32Process->MenuListLock);
76
77 Win32Process->KeyboardLayout = W32kGetDefaultKeyLayout();
78 Win32Process->WindowStation = NULL;
79 if (Process->Win32WindowStation != NULL)
80 {
81 Status =
82 IntValidateWindowStationHandle(Process->Win32WindowStation,
83 UserMode,
84 GENERIC_ALL,
85 &Win32Process->WindowStation);
86 if (!NT_SUCCESS(Status))
87 {
88 DbgPrint("Win32K: Failed to reference a window station for "
89 "process.\n");
90 }
91 }
92
93 Win32Process->CreatedWindowOrDC = FALSE;
94 }
95 else
96 {
97 #if 0
98 DbgPrint (" Destroy process\n");
99 DbgPrint (" IRQ level: %lu\n", KeGetCurrentIrql ());
100 #endif
101 IntRemoveProcessWndProcHandles((HANDLE)Process->UniqueProcessId);
102 IntCleanupMenus(Process, Win32Process);
103
104 CleanupForProcess(Process, Process->UniqueProcessId);
105
106 IntGraphicsCheck(FALSE);
107 }
108
109 return STATUS_SUCCESS;
110 }
111
112
113 NTSTATUS STDCALL
114 Win32kThreadCallback (struct _ETHREAD *Thread,
115 BOOLEAN Create)
116 {
117 struct _EPROCESS *Process;
118 PW32THREAD Win32Thread;
119 NTSTATUS Status;
120
121 #if 0
122 DbgPrint ("Win32kThreadCallback() called\n");
123 #endif
124
125 Process = Thread->ThreadsProcess;
126 Win32Thread = Thread->Win32Thread;
127 if (Create)
128 {
129 #if 0
130 DbgPrint (" Create thread\n");
131 #endif
132
133 IntDestroyCaret(Win32Thread);
134 Win32Thread->MessageQueue = MsqCreateMessageQueue(Thread);
135 Win32Thread->KeyboardLayout = W32kGetDefaultKeyLayout();
136 Win32Thread->MessagePumpHookValue = 0;
137 InitializeListHead(&Win32Thread->WindowListHead);
138 ExInitializeFastMutex(&Win32Thread->WindowListLock);
139
140 /* By default threads get assigned their process's desktop. */
141 Win32Thread->Desktop = NULL;
142 if (Process->Win32Desktop != NULL)
143 {
144 Status = ObReferenceObjectByHandle(Process->Win32Desktop,
145 GENERIC_ALL,
146 ExDesktopObjectType,
147 UserMode,
148 (PVOID*)&Win32Thread->Desktop,
149 NULL);
150 if (!NT_SUCCESS(Status))
151 {
152 DbgPrint("Win32K: Failed to reference a desktop for thread.\n");
153 }
154 }
155 }
156 else
157 {
158 #if 0
159 DbgPrint (" Destroy thread\n");
160 #endif
161
162 RemoveTimersThread(Thread->Cid.UniqueThread);
163 UnregisterThreadHotKeys(Thread);
164 DestroyThreadWindows(Thread);
165 }
166
167 return STATUS_SUCCESS;
168 }
169
170
171 /*
172 * This definition doesn't work
173 */
174 // WINBOOL STDCALL DllMain(VOID)
175 NTSTATUS STDCALL
176 DllMain (
177 IN PDRIVER_OBJECT DriverObject,
178 IN PUNICODE_STRING RegistryPath)
179 {
180 NTSTATUS Status;
181 BOOLEAN Result;
182
183 IntInitializeWinLock();
184
185 /*
186 * Register user mode call interface
187 * (system service table index = 1)
188 */
189 Result = KeAddSystemServiceTable (Win32kSSDT,
190 NULL,
191 Win32kNumberOfSysCalls,
192 Win32kSSPT,
193 1);
194 if (Result == FALSE)
195 {
196 DbgPrint("Adding system services failed!\n");
197 return STATUS_UNSUCCESSFUL;
198 }
199
200 /*
201 * Register our per-process and per-thread structures.
202 */
203 PsEstablishWin32Callouts (Win32kProcessCallback,
204 Win32kThreadCallback,
205 0,
206 0,
207 sizeof(W32THREAD) + sizeof(THRDCARETINFO),
208 sizeof(W32PROCESS));
209
210 WinPosSetupInternalPos();
211
212 Status = InitWindowStationImpl();
213 if (!NT_SUCCESS(Status))
214 {
215 DbgPrint("Failed to initialize window station implementation!\n");
216 return STATUS_UNSUCCESSFUL;
217 }
218
219 Status = InitClassImpl();
220 if (!NT_SUCCESS(Status))
221 {
222 DbgPrint("Failed to initialize window class implementation!\n");
223 return STATUS_UNSUCCESSFUL;
224 }
225
226 Status = InitDesktopImpl();
227 if (!NT_SUCCESS(Status))
228 {
229 DbgPrint("Failed to initialize window station implementation!\n");
230 return STATUS_UNSUCCESSFUL;
231 }
232
233 Status = InitWindowImpl();
234 if (!NT_SUCCESS(Status))
235 {
236 DbgPrint("Failed to initialize window implementation!\n");
237 return STATUS_UNSUCCESSFUL;
238 }
239
240 Status = InitMenuImpl();
241 if (!NT_SUCCESS(Status))
242 {
243 DbgPrint("Failed to initialize menu implementation!\n");
244 return STATUS_UNSUCCESSFUL;
245 }
246
247 Status = InitInputImpl();
248 if (!NT_SUCCESS(Status))
249 {
250 DbgPrint("Failed to initialize input implementation.\n");
251 return(Status);
252 }
253
254 Status = InitKeyboardImpl();
255 if (!NT_SUCCESS(Status))
256 {
257 DbgPrint("Failed to initialize keyboard implementation.\n");
258 return(Status);
259 }
260
261 Status = MsqInitializeImpl();
262 if (!NT_SUCCESS(Status))
263 {
264 DbgPrint("Failed to initialize message queue implementation.\n");
265 return(Status);
266 }
267
268 Status = InitTimerImpl();
269 if (!NT_SUCCESS(Status))
270 {
271 DbgPrint("Failed to initialize timer implementation.\n");
272 return(Status);
273 }
274
275 Status = InitAcceleratorImpl();
276 if (!NT_SUCCESS(Status))
277 {
278 DbgPrint("Failed to initialize accelerator implementation.\n");
279 return(Status);
280 }
281
282 InitGdiObjectHandleTable ();
283
284 /* Initialize FreeType library */
285 if (! InitFontSupport())
286 {
287 DPRINT1("Unable to initialize font support\n");
288 return STATUS_UNSUCCESSFUL;
289 }
290
291 /* Create stock objects, ie. precreated objects commonly
292 used by win32 applications */
293 CreateStockObjects();
294
295 return STATUS_SUCCESS;
296 }
297
298
299 BOOLEAN STDCALL
300 Win32kInitialize (VOID)
301 {
302 return TRUE;
303 }
304
305 /* EOF */