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)
12 /* Public Win32K Headers */
13 // For calling NtUser...()
19 HINSTANCE UserSrvDllInstance
= NULL
;
20 // HANDLE WinSrvApiPort = NULL;
23 HANDLE UserSrvHeap
= NULL
; // Our own heap.
24 // HANDLE BaseSrvSharedHeap = NULL; // Shared heap with CSR. (CsrSrvSharedSectionHeap)
25 // PBASE_STATIC_SERVER_DATA BaseStaticServerData = NULL; // Data that we can share amongst processes. Initialized inside BaseSrvSharedHeap.
28 PCSR_API_ROUTINE UserServerApiDispatchTable
[UserpMaxApiNumber
] =
33 SrvRegisterServicesProcess
, // Not present in Win7
34 // SrvActivateDebugger,
35 // SrvGetThreadConsoleDesktop, // Not present in Win7
37 SrvRegisterLogonProcess
, // Not present in Win7
38 // SrvCreateSystemThreads,
39 // SrvRecordShutdownReason,
40 // SrvCancelShutdown, // Added in Vista
41 // SrvConsoleHandleOperation, // Added in Win7
42 // SrvGetSetShutdownBlockReason, // Added in Vista
45 BOOLEAN UserServerApiServerValidTable
[UserpMaxApiNumber
] =
47 FALSE
, // SrvExitWindowsEx
48 // FALSE, // SrvEndTask
50 FALSE
, // SrvRegisterServicesProcess
51 // FALSE, // SrvActivateDebugger
52 // TRUE, // SrvGetThreadConsoleDesktop
53 // FALSE, // SrvDeviceEvent
54 FALSE
, // SrvRegisterLogonProcess
55 // FALSE, // SrvCreateSystemThreads
56 // FALSE, // SrvRecordShutdownReason
57 // FALSE, // SrvCancelShutdown
58 // FALSE, // SrvConsoleHandleOperation
59 // FALSE, // SrvGetSetShutdownBlockReason
64 PCHAR UserServerApiNameTable
[UserpMaxApiNumber
] =
69 "SrvRegisterServicesProcess",
70 // "SrvActivateDebugger",
71 // "SrvGetThreadConsoleDesktop",
73 "SrvRegisterLogonProcess",
74 // "SrvCreateSystemThreads",
75 // "SrvRecordShutdownReason",
76 // "SrvCancelShutdown",
77 // "SrvConsoleHandleOperation",
78 // "SrvGetSetShutdownBlockReason",
84 /* FUNCTIONS ******************************************************************/
87 VOID WINAPI UserStaticServerThread(PVOID x)
89 // NTSTATUS Status = STATUS_SUCCESS;
90 PPORT_MESSAGE Request = (PPORT_MESSAGE)x;
91 PPORT_MESSAGE Reply = NULL;
92 ULONG MessageType = 0;
94 DPRINT("WINSRV: %s(%08lx) called\n", __FUNCTION__, x);
96 MessageType = Request->u2.s2.Type;
97 DPRINT("WINSRV: %s(%08lx) received a message (Type=%d)\n",
98 __FUNCTION__, x, MessageType);
103 /\* Status = *\/ NtReplyPort(WinSrvApiPort, Reply);
110 InitializeVideoAddressSpace(VOID
)
112 OBJECT_ATTRIBUTES ObjectAttributes
;
113 UNICODE_STRING PhysMemName
= RTL_CONSTANT_STRING(L
"\\Device\\PhysicalMemory");
115 HANDLE PhysMemHandle
;
117 LARGE_INTEGER Offset
;
119 CHAR IVTAndBda
[1024+256];
121 /* Free the 1MB pre-reserved region. In reality, ReactOS should simply support us mapping the view into the reserved area, but it doesn't. */
123 ViewSize
= 1024 * 1024;
124 Status
= ZwFreeVirtualMemory(NtCurrentProcess(),
128 if (!NT_SUCCESS(Status
))
130 DPRINT1("Couldn't unmap reserved memory (%x)\n", Status
);
134 /* Open the physical memory section */
135 InitializeObjectAttributes(&ObjectAttributes
,
140 Status
= ZwOpenSection(&PhysMemHandle
,
143 if (!NT_SUCCESS(Status
))
145 DPRINT1("Couldn't open \\Device\\PhysicalMemory\n");
149 /* Map the BIOS and device registers into the address space */
150 Offset
.QuadPart
= 0xa0000;
151 ViewSize
= 0x100000 - 0xa0000;
152 BaseAddress
= (PVOID
)0xa0000;
153 Status
= ZwMapViewOfSection(PhysMemHandle
,
162 PAGE_EXECUTE_READWRITE
);
163 if (!NT_SUCCESS(Status
))
165 DPRINT1("Couldn't map physical memory (%x)\n", Status
);
166 ZwClose(PhysMemHandle
);
170 /* Close physical memory section handle */
171 ZwClose(PhysMemHandle
);
173 if (BaseAddress
!= (PVOID
)0xa0000)
175 DPRINT1("Couldn't map physical memory at the right address (was %x)\n",
180 /* Allocate some low memory to use for the non-BIOS
181 * parts of the v86 mode address space
183 BaseAddress
= (PVOID
)0x1;
184 ViewSize
= 0xa0000 - 0x1000;
185 Status
= ZwAllocateVirtualMemory(NtCurrentProcess(),
189 MEM_RESERVE
| MEM_COMMIT
,
190 PAGE_EXECUTE_READWRITE
);
191 if (!NT_SUCCESS(Status
))
193 DPRINT1("Failed to allocate virtual memory (Status %x)\n", Status
);
196 if (BaseAddress
!= (PVOID
)0x0)
198 DPRINT1("Failed to allocate virtual memory at right address (was %x)\n",
203 /* Get the real mode IVT and BDA from the kernel */
204 Status
= NtVdmControl(VdmInitialize
, IVTAndBda
);
205 if (!NT_SUCCESS(Status
))
207 DPRINT1("NtVdmControl failed (status %x)\n", Status
);
215 /**********************************************************************
218 * TODO: we need a virtual device for sessions other than
219 * TODO: the console one
224 OBJECT_ATTRIBUTES ObjectAttributes
;
225 UNICODE_STRING DeviceName
= RTL_CONSTANT_STRING(L
"\\??\\DISPLAY1");
226 IO_STATUS_BLOCK Iosb
;
227 HANDLE VideoHandle
= (HANDLE
) 0;
228 NTSTATUS Status
= STATUS_SUCCESS
;
230 DPRINT("CSR: %s called\n", __FUNCTION__
);
232 InitializeVideoAddressSpace();
234 InitializeObjectAttributes(&ObjectAttributes
,
239 Status
= NtOpenFile(&VideoHandle
,
245 if (NT_SUCCESS(Status
))
247 NtClose(VideoHandle
);
255 PrivateCsrssManualGuiCheck(LONG Check
)
257 NtUserCallOneParam(Check
, ONEPARAM_ROUTINE_CSRSS_GUICHECK
);
260 /*** HACK from win32csr... ***/
261 static HHOOK hhk
= NULL
;
265 KeyboardHookProc(int nCode
,
269 return CallNextHookEx(hhk
, nCode
, wParam
, lParam
);
271 /*** END - HACK from win32csr... ***/
275 CreateSystemThreads(PVOID pParam
)
277 NtUserCallOneParam((DWORD
)pParam
, ONEPARAM_ROUTINE_CREATESYSTEMTHREADS
);
278 DPRINT1("This thread should not terminate!\n");
282 CSR_SERVER_DLL_INIT(UserServerDllInitialization
)
285 NTSTATUS Status = STATUS_SUCCESS;
287 DPRINT("WINSRV: %s called\n", __FUNCTION__);
289 // Get the listening port from csrsrv.dll
290 WinSrvApiPort = CsrQueryApiPort ();
291 if (NULL == WinSrvApiPort)
293 return STATUS_UNSUCCESSFUL;
295 // Register our message dispatcher
296 Status = CsrAddStaticServerThread (UserStaticServerThread);
297 if (NT_SUCCESS(Status))
299 //TODO: perform the real user server internal initialization here
304 /*** From win32csr... ***/
309 /*** END - From win32csr... ***/
311 /* Initialize memory */
312 UserSrvHeap
= RtlGetProcessHeap(); // Initialize our own heap.
313 // BaseSrvSharedHeap = LoadedServerDll->SharedSection; // Get the CSR shared heap.
314 // LoadedServerDll->SharedSection = BaseStaticServerData;
317 NtUserInitialize(0, NULL
, NULL
);
318 PrivateCsrssManualGuiCheck(0);
320 /* Setup the DLL Object */
321 LoadedServerDll
->ApiBase
= USERSRV_FIRST_API_NUMBER
;
322 LoadedServerDll
->HighestApiSupported
= UserpMaxApiNumber
;
323 LoadedServerDll
->DispatchTable
= UserServerApiDispatchTable
;
324 LoadedServerDll
->ValidTable
= UserServerApiServerValidTable
;
325 LoadedServerDll
->NameTable
= UserServerApiNameTable
;
326 LoadedServerDll
->SizeOfProcessData
= 0;
327 LoadedServerDll
->ConnectCallback
= NULL
;
328 // LoadedServerDll->DisconnectCallback = Win32CsrReleaseConsole;
329 // LoadedServerDll->NewProcessCallback = Win32CsrDuplicateHandleTable;
330 LoadedServerDll
->HardErrorCallback
= Win32CsrHardError
;
332 /*** From win32csr... See r54125 ***/
333 /* Start the Raw Input Thread and the Desktop Thread */
334 for (i
= 0; i
< 2; ++i
)
336 Status
= RtlCreateUserThread(NtCurrentProcess(), NULL
, TRUE
, 0, 0, 0, (PTHREAD_START_ROUTINE
)CreateSystemThreads
, (PVOID
)i
, &ServerThread
, &ClientId
);
337 if (NT_SUCCESS(Status
))
339 NtResumeThread(ServerThread
, NULL
);
340 NtClose(ServerThread
);
343 DPRINT1("Cannot start Raw Input Thread!\n");
345 /*** END - From win32csr... ***/
348 return STATUS_SUCCESS
;
351 // PUSER_SOUND_SENTRY. Used in basesrv.dll
352 BOOL WINAPI
_UserSoundSentry(VOID
)
360 DllMain(IN HINSTANCE hInstanceDll
,
362 IN LPVOID lpReserved
)
364 UNREFERENCED_PARAMETER(dwReason
);
365 UNREFERENCED_PARAMETER(lpReserved
);
367 if (DLL_PROCESS_ATTACH
== dwReason
)
369 UserSrvDllInstance
= hInstanceDll
;
371 /*** HACK from win32csr... ***/
374 // HACK HACK HACK ReactOS to BOOT! Initialization BUG ALERT! See bug 5655.
376 hhk
= SetWindowsHookEx(WH_KEYBOARD_LL
, KeyboardHookProc
, NULL
, 0);
377 // BUG ALERT! BUG ALERT! BUG ALERT! BUG ALERT! BUG ALERT! BUG ALERT! BUG ALERT!
378 // BUG ALERT! BUG ALERT! BUG ALERT! BUG ALERT! BUG ALERT! BUG ALERT! BUG ALERT!
379 // BUG ALERT! BUG ALERT! BUG ALERT! BUG ALERT! BUG ALERT! BUG ALERT! BUG ALERT!
381 /*** END - HACK from win32csr... ***/