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