2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS User API Server DLL
4 * FILE: win32ss/user/winsrv/init.c
5 * PURPOSE: Initialization
6 * PROGRAMMERS: Dmitry Philippov (shedon@mail.ru)
7 * Hermes Belusca-Maito (hermes.belusca@sfr.fr)
10 /* INCLUDES *******************************************************************/
14 /* Public Win32K Headers */
15 // For calling NtUser...()
21 /* GLOBALS ********************************************************************/
23 HINSTANCE UserServerDllInstance
= NULL
;
26 HANDLE UserServerHeap
= NULL
; // Our own heap.
28 // Windows Server 2003 table from http://j00ru.vexillium.org/csrss_list/api_list.html#Windows_2k3
29 PCSR_API_ROUTINE UserServerApiDispatchTable
[UserpMaxApiNumber
] =
34 SrvRegisterServicesProcess
, // Not present in Win7
35 // SrvActivateDebugger,
36 // SrvGetThreadConsoleDesktop, // Not present in Win7
38 SrvRegisterLogonProcess
, // Not present in Win7
39 // SrvCreateSystemThreads,
40 // SrvRecordShutdownReason,
41 // SrvCancelShutdown, // Added in Vista
42 // SrvConsoleHandleOperation, // Added in Win7
43 // SrvGetSetShutdownBlockReason, // Added in Vista
45 /// HACK: ReactOS-specific
46 RosSetLogonNotifyWindow
,
49 BOOLEAN UserServerApiServerValidTable
[UserpMaxApiNumber
] =
51 FALSE
, // SrvExitWindowsEx
52 // FALSE, // SrvEndTask
54 FALSE
, // SrvRegisterServicesProcess
55 // FALSE, // SrvActivateDebugger
56 // TRUE, // SrvGetThreadConsoleDesktop
57 // FALSE, // SrvDeviceEvent
58 FALSE
, // SrvRegisterLogonProcess
59 // FALSE, // SrvCreateSystemThreads
60 // FALSE, // SrvRecordShutdownReason
61 // FALSE, // SrvCancelShutdown
62 // FALSE, // SrvConsoleHandleOperation
63 // FALSE, // SrvGetSetShutdownBlockReason
65 /// HACK: ReactOS-specific
66 FALSE
, // RosSetLogonNotifyWindow
69 PCHAR UserServerApiNameTable
[UserpMaxApiNumber
] =
74 "SrvRegisterServicesProcess",
75 // "SrvActivateDebugger",
76 // "SrvGetThreadConsoleDesktop",
78 "SrvRegisterLogonProcess",
79 // "SrvCreateSystemThreads",
80 // "SrvRecordShutdownReason",
81 // "SrvCancelShutdown",
82 // "SrvConsoleHandleOperation",
83 // "SrvGetSetShutdownBlockReason",
85 /// HACK: ReactOS-specific
86 "RosSetLogonNotifyWindow",
90 /* FUNCTIONS ******************************************************************/
92 // PUSER_SOUND_SENTRY. Used in basesrv.dll
93 BOOL WINAPI
_UserSoundSentry(VOID
)
95 // TODO: Do something.
100 InitializeVideoAddressSpace(VOID
)
102 OBJECT_ATTRIBUTES ObjectAttributes
;
103 UNICODE_STRING PhysMemName
= RTL_CONSTANT_STRING(L
"\\Device\\PhysicalMemory");
105 HANDLE PhysMemHandle
;
107 LARGE_INTEGER Offset
;
109 CHAR IVTAndBda
[1024+256];
111 /* Free the 1MB pre-reserved region. In reality, ReactOS should simply support us mapping the view into the reserved area, but it doesn't. */
113 ViewSize
= 1024 * 1024;
114 Status
= ZwFreeVirtualMemory(NtCurrentProcess(),
118 if (!NT_SUCCESS(Status
))
120 DPRINT1("Couldn't unmap reserved memory (%x)\n", Status
);
124 /* Open the physical memory section */
125 InitializeObjectAttributes(&ObjectAttributes
,
130 Status
= ZwOpenSection(&PhysMemHandle
,
133 if (!NT_SUCCESS(Status
))
135 DPRINT1("Couldn't open \\Device\\PhysicalMemory\n");
139 /* Map the BIOS and device registers into the address space */
140 Offset
.QuadPart
= 0xa0000;
141 ViewSize
= 0x100000 - 0xa0000;
142 BaseAddress
= (PVOID
)0xa0000;
143 Status
= ZwMapViewOfSection(PhysMemHandle
,
152 PAGE_EXECUTE_READWRITE
);
153 if (!NT_SUCCESS(Status
))
155 DPRINT1("Couldn't map physical memory (%x)\n", Status
);
156 ZwClose(PhysMemHandle
);
160 /* Close physical memory section handle */
161 ZwClose(PhysMemHandle
);
163 if (BaseAddress
!= (PVOID
)0xa0000)
165 DPRINT1("Couldn't map physical memory at the right address (was %x)\n",
170 /* Allocate some low memory to use for the non-BIOS
171 * parts of the v86 mode address space
173 BaseAddress
= (PVOID
)0x1;
174 ViewSize
= 0xa0000 - 0x1000;
175 Status
= ZwAllocateVirtualMemory(NtCurrentProcess(),
179 MEM_RESERVE
| MEM_COMMIT
,
180 PAGE_EXECUTE_READWRITE
);
181 if (!NT_SUCCESS(Status
))
183 DPRINT1("Failed to allocate virtual memory (Status %x)\n", Status
);
186 if (BaseAddress
!= (PVOID
)0x0)
188 DPRINT1("Failed to allocate virtual memory at right address (was %x)\n",
193 /* Get the real mode IVT and BDA from the kernel */
194 Status
= NtVdmControl(VdmInitialize
, IVTAndBda
);
195 if (!NT_SUCCESS(Status
))
197 DPRINT1("NtVdmControl failed (status %x)\n", Status
);
205 /**********************************************************************
208 * TODO: we need a virtual device for sessions other than
209 * TODO: the console one
214 OBJECT_ATTRIBUTES ObjectAttributes
;
215 UNICODE_STRING DeviceName
= RTL_CONSTANT_STRING(L
"\\??\\DISPLAY1");
216 IO_STATUS_BLOCK Iosb
;
217 HANDLE VideoHandle
= (HANDLE
) 0;
218 NTSTATUS Status
= STATUS_SUCCESS
;
220 DPRINT("CSR: %s called\n", __FUNCTION__
);
222 InitializeVideoAddressSpace();
224 InitializeObjectAttributes(&ObjectAttributes
,
229 Status
= NtOpenFile(&VideoHandle
,
235 if (NT_SUCCESS(Status
))
237 NtClose(VideoHandle
);
245 PrivateCsrssManualGuiCheck(LONG Check
)
247 NtUserCallOneParam(Check
, ONEPARAM_ROUTINE_CSRSS_GUICHECK
);
250 /*** HACK from win32csr... ***/
251 static HHOOK hhk
= NULL
;
255 KeyboardHookProc(int nCode
,
259 return CallNextHookEx(hhk
, nCode
, wParam
, lParam
);
261 /*** END - HACK from win32csr... ***/
265 CreateSystemThreads(PVOID pParam
)
267 NtUserCallOneParam((DWORD
)pParam
, ONEPARAM_ROUTINE_CREATESYSTEMTHREADS
);
268 DPRINT1("This thread should not terminate!\n");
272 CSR_SERVER_DLL_INIT(UserServerDllInitialization
)
274 /*** From win32csr... ***/
279 /*** END - From win32csr... ***/
281 /* Initialize the memory */
282 UserServerHeap
= RtlGetProcessHeap();
284 /* Initialize the video */
286 NtUserInitialize(0, NULL
, NULL
);
287 PrivateCsrssManualGuiCheck(0);
289 /* Setup the DLL Object */
290 LoadedServerDll
->ApiBase
= USERSRV_FIRST_API_NUMBER
;
291 LoadedServerDll
->HighestApiSupported
= UserpMaxApiNumber
;
292 LoadedServerDll
->DispatchTable
= UserServerApiDispatchTable
;
293 LoadedServerDll
->ValidTable
= UserServerApiServerValidTable
;
294 LoadedServerDll
->NameTable
= UserServerApiNameTable
;
295 LoadedServerDll
->SizeOfProcessData
= 0;
296 LoadedServerDll
->ConnectCallback
= NULL
;
297 LoadedServerDll
->DisconnectCallback
= NULL
;
298 LoadedServerDll
->HardErrorCallback
= UserServerHardError
;
299 LoadedServerDll
->ShutdownProcessCallback
= NULL
;
301 UserServerDllInstance
= LoadedServerDll
->ServerHandle
;
303 /*** From win32csr... See r54125 ***/
304 /* Start the Raw Input Thread and the Desktop Thread */
305 for (i
= 0; i
< 2; ++i
)
307 Status
= RtlCreateUserThread(NtCurrentProcess(), NULL
, TRUE
, 0, 0, 0, (PTHREAD_START_ROUTINE
)CreateSystemThreads
, (PVOID
)i
, &ServerThread
, &ClientId
);
308 if (NT_SUCCESS(Status
))
310 NtResumeThread(ServerThread
, NULL
);
311 NtClose(ServerThread
);
314 DPRINT1("Cannot start Raw Input Thread!\n");
316 /*** END - From win32csr... ***/
319 return STATUS_SUCCESS
;
324 DllMain(IN HINSTANCE hInstanceDll
,
326 IN LPVOID lpReserved
)
328 UNREFERENCED_PARAMETER(hInstanceDll
);
329 UNREFERENCED_PARAMETER(dwReason
);
330 UNREFERENCED_PARAMETER(lpReserved
);
332 if (DLL_PROCESS_ATTACH
== dwReason
)
334 DPRINT1("WINSRV - HACK: Use keyboard hook hack\n");
335 /*** HACK from win32csr... ***/
337 // HACK HACK HACK ReactOS to BOOT! Initialization BUG ALERT! See bug 5655.
339 hhk
= SetWindowsHookEx(WH_KEYBOARD_LL
, KeyboardHookProc
, NULL
, 0);
340 // BUG ALERT! BUG ALERT! BUG ALERT! BUG ALERT! BUG ALERT! BUG ALERT! BUG ALERT!
341 // BUG ALERT! BUG ALERT! BUG ALERT! BUG ALERT! BUG ALERT! BUG ALERT! BUG ALERT!
342 // BUG ALERT! BUG ALERT! BUG ALERT! BUG ALERT! BUG ALERT! BUG ALERT! BUG ALERT!
344 /*** END - HACK from win32csr... ***/