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
44 /// HACK: ReactOS-specific
45 RosSetLogonNotifyWindow
48 BOOLEAN UserServerApiServerValidTable
[UserpMaxApiNumber
] =
50 FALSE
, // SrvExitWindowsEx
51 // FALSE, // SrvEndTask
53 FALSE
, // SrvRegisterServicesProcess
54 // FALSE, // SrvActivateDebugger
55 // TRUE, // SrvGetThreadConsoleDesktop
56 // FALSE, // SrvDeviceEvent
57 FALSE
, // SrvRegisterLogonProcess
58 // FALSE, // SrvCreateSystemThreads
59 // FALSE, // SrvRecordShutdownReason
60 // FALSE, // SrvCancelShutdown
61 // FALSE, // SrvConsoleHandleOperation
62 // FALSE, // SrvGetSetShutdownBlockReason
64 /// HACK: ReactOS-specific
65 FALSE
, // RosSetLogonNotifyWindow
70 PCHAR UserServerApiNameTable
[UserpMaxApiNumber
] =
75 "SrvRegisterServicesProcess",
76 // "SrvActivateDebugger",
77 // "SrvGetThreadConsoleDesktop",
79 "SrvRegisterLogonProcess",
80 // "SrvCreateSystemThreads",
81 // "SrvRecordShutdownReason",
82 // "SrvCancelShutdown",
83 // "SrvConsoleHandleOperation",
84 // "SrvGetSetShutdownBlockReason",
86 /// HACK: ReactOS-specific
87 "RosSetLogonNotifyWindow",
93 /* FUNCTIONS ******************************************************************/
96 VOID WINAPI UserStaticServerThread(PVOID x)
98 // NTSTATUS Status = STATUS_SUCCESS;
99 PPORT_MESSAGE Request = (PPORT_MESSAGE)x;
100 PPORT_MESSAGE Reply = NULL;
101 ULONG MessageType = 0;
103 DPRINT("WINSRV: %s(%08lx) called\n", __FUNCTION__, x);
105 MessageType = Request->u2.s2.Type;
106 DPRINT("WINSRV: %s(%08lx) received a message (Type=%d)\n",
107 __FUNCTION__, x, MessageType);
112 /\* Status = *\/ NtReplyPort(WinSrvApiPort, Reply);
119 InitializeVideoAddressSpace(VOID
)
121 OBJECT_ATTRIBUTES ObjectAttributes
;
122 UNICODE_STRING PhysMemName
= RTL_CONSTANT_STRING(L
"\\Device\\PhysicalMemory");
124 HANDLE PhysMemHandle
;
126 LARGE_INTEGER Offset
;
128 CHAR IVTAndBda
[1024+256];
130 /* Free the 1MB pre-reserved region. In reality, ReactOS should simply support us mapping the view into the reserved area, but it doesn't. */
132 ViewSize
= 1024 * 1024;
133 Status
= ZwFreeVirtualMemory(NtCurrentProcess(),
137 if (!NT_SUCCESS(Status
))
139 DPRINT1("Couldn't unmap reserved memory (%x)\n", Status
);
143 /* Open the physical memory section */
144 InitializeObjectAttributes(&ObjectAttributes
,
149 Status
= ZwOpenSection(&PhysMemHandle
,
152 if (!NT_SUCCESS(Status
))
154 DPRINT1("Couldn't open \\Device\\PhysicalMemory\n");
158 /* Map the BIOS and device registers into the address space */
159 Offset
.QuadPart
= 0xa0000;
160 ViewSize
= 0x100000 - 0xa0000;
161 BaseAddress
= (PVOID
)0xa0000;
162 Status
= ZwMapViewOfSection(PhysMemHandle
,
171 PAGE_EXECUTE_READWRITE
);
172 if (!NT_SUCCESS(Status
))
174 DPRINT1("Couldn't map physical memory (%x)\n", Status
);
175 ZwClose(PhysMemHandle
);
179 /* Close physical memory section handle */
180 ZwClose(PhysMemHandle
);
182 if (BaseAddress
!= (PVOID
)0xa0000)
184 DPRINT1("Couldn't map physical memory at the right address (was %x)\n",
189 /* Allocate some low memory to use for the non-BIOS
190 * parts of the v86 mode address space
192 BaseAddress
= (PVOID
)0x1;
193 ViewSize
= 0xa0000 - 0x1000;
194 Status
= ZwAllocateVirtualMemory(NtCurrentProcess(),
198 MEM_RESERVE
| MEM_COMMIT
,
199 PAGE_EXECUTE_READWRITE
);
200 if (!NT_SUCCESS(Status
))
202 DPRINT1("Failed to allocate virtual memory (Status %x)\n", Status
);
205 if (BaseAddress
!= (PVOID
)0x0)
207 DPRINT1("Failed to allocate virtual memory at right address (was %x)\n",
212 /* Get the real mode IVT and BDA from the kernel */
213 Status
= NtVdmControl(VdmInitialize
, IVTAndBda
);
214 if (!NT_SUCCESS(Status
))
216 DPRINT1("NtVdmControl failed (status %x)\n", Status
);
224 /**********************************************************************
227 * TODO: we need a virtual device for sessions other than
228 * TODO: the console one
233 OBJECT_ATTRIBUTES ObjectAttributes
;
234 UNICODE_STRING DeviceName
= RTL_CONSTANT_STRING(L
"\\??\\DISPLAY1");
235 IO_STATUS_BLOCK Iosb
;
236 HANDLE VideoHandle
= (HANDLE
) 0;
237 NTSTATUS Status
= STATUS_SUCCESS
;
239 DPRINT("CSR: %s called\n", __FUNCTION__
);
241 InitializeVideoAddressSpace();
243 InitializeObjectAttributes(&ObjectAttributes
,
248 Status
= NtOpenFile(&VideoHandle
,
254 if (NT_SUCCESS(Status
))
256 NtClose(VideoHandle
);
264 PrivateCsrssManualGuiCheck(LONG Check
)
266 NtUserCallOneParam(Check
, ONEPARAM_ROUTINE_CSRSS_GUICHECK
);
269 /*** HACK from win32csr... ***/
270 static HHOOK hhk
= NULL
;
274 KeyboardHookProc(int nCode
,
278 return CallNextHookEx(hhk
, nCode
, wParam
, lParam
);
280 /*** END - HACK from win32csr... ***/
284 CreateSystemThreads(PVOID pParam
)
286 NtUserCallOneParam((DWORD
)pParam
, ONEPARAM_ROUTINE_CREATESYSTEMTHREADS
);
287 DPRINT1("This thread should not terminate!\n");
291 CSR_SERVER_DLL_INIT(UserServerDllInitialization
)
294 NTSTATUS Status = STATUS_SUCCESS;
296 DPRINT("WINSRV: %s called\n", __FUNCTION__);
298 // Get the listening port from csrsrv.dll
299 WinSrvApiPort = CsrQueryApiPort ();
300 if (NULL == WinSrvApiPort)
302 return STATUS_UNSUCCESSFUL;
304 // Register our message dispatcher
305 Status = CsrAddStaticServerThread (UserStaticServerThread);
306 if (NT_SUCCESS(Status))
308 //TODO: perform the real user server internal initialization here
313 /*** From win32csr... ***/
318 /*** END - From win32csr... ***/
320 /* Initialize memory */
321 UserSrvHeap
= RtlGetProcessHeap(); // Initialize our own heap.
322 // BaseSrvSharedHeap = LoadedServerDll->SharedSection; // Get the CSR shared heap.
323 // LoadedServerDll->SharedSection = BaseStaticServerData;
326 NtUserInitialize(0, NULL
, NULL
);
327 PrivateCsrssManualGuiCheck(0);
329 /* Setup the DLL Object */
330 LoadedServerDll
->ApiBase
= USERSRV_FIRST_API_NUMBER
;
331 LoadedServerDll
->HighestApiSupported
= UserpMaxApiNumber
;
332 LoadedServerDll
->DispatchTable
= UserServerApiDispatchTable
;
333 LoadedServerDll
->ValidTable
= UserServerApiServerValidTable
;
334 LoadedServerDll
->NameTable
= UserServerApiNameTable
;
335 LoadedServerDll
->SizeOfProcessData
= 0;
336 LoadedServerDll
->ConnectCallback
= NULL
;
337 // LoadedServerDll->DisconnectCallback = Win32CsrReleaseConsole;
338 // LoadedServerDll->NewProcessCallback = Win32CsrDuplicateHandleTable;
339 LoadedServerDll
->HardErrorCallback
= Win32CsrHardError
;
341 /*** From win32csr... See r54125 ***/
342 /* Start the Raw Input Thread and the Desktop Thread */
343 for (i
= 0; i
< 2; ++i
)
345 Status
= RtlCreateUserThread(NtCurrentProcess(), NULL
, TRUE
, 0, 0, 0, (PTHREAD_START_ROUTINE
)CreateSystemThreads
, (PVOID
)i
, &ServerThread
, &ClientId
);
346 if (NT_SUCCESS(Status
))
348 NtResumeThread(ServerThread
, NULL
);
349 NtClose(ServerThread
);
352 DPRINT1("Cannot start Raw Input Thread!\n");
354 /*** END - From win32csr... ***/
357 return STATUS_SUCCESS
;
360 // PUSER_SOUND_SENTRY. Used in basesrv.dll
361 BOOL WINAPI
_UserSoundSentry(VOID
)
369 DllMain(IN HINSTANCE hInstanceDll
,
371 IN LPVOID lpReserved
)
373 UNREFERENCED_PARAMETER(dwReason
);
374 UNREFERENCED_PARAMETER(lpReserved
);
376 if (DLL_PROCESS_ATTACH
== dwReason
)
378 UserSrvDllInstance
= hInstanceDll
;
380 /*** HACK from win32csr... ***/
383 // HACK HACK HACK ReactOS to BOOT! Initialization BUG ALERT! See bug 5655.
385 hhk
= SetWindowsHookEx(WH_KEYBOARD_LL
, KeyboardHookProc
, NULL
, 0);
386 // BUG ALERT! BUG ALERT! BUG ALERT! BUG ALERT! BUG ALERT! BUG ALERT! BUG ALERT!
387 // BUG ALERT! BUG ALERT! BUG ALERT! BUG ALERT! BUG ALERT! BUG ALERT! BUG ALERT!
388 // BUG ALERT! BUG ALERT! BUG ALERT! BUG ALERT! BUG ALERT! BUG ALERT! BUG ALERT!
390 /*** END - HACK from win32csr... ***/