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 *******************************************************************/
17 /* GLOBALS ********************************************************************/
19 HINSTANCE UserServerDllInstance
= NULL
;
22 HANDLE UserServerHeap
= NULL
; // Our own heap.
24 // Windows Server 2003 table from http://j00ru.vexillium.org/csrss_list/api_list.html#Windows_2k3
25 PCSR_API_ROUTINE UserServerApiDispatchTable
[UserpMaxApiNumber
- USERSRV_FIRST_API_NUMBER
] =
30 SrvRegisterServicesProcess
, // Not present in Win7
31 // SrvActivateDebugger,
32 // SrvGetThreadConsoleDesktop, // Not present in Win7
34 SrvRegisterLogonProcess
, // Not present in Win7
35 // SrvCreateSystemThreads,
36 // SrvRecordShutdownReason,
37 // SrvCancelShutdown, // Added in Vista
38 // SrvConsoleHandleOperation, // Added in Win7
39 // SrvGetSetShutdownBlockReason, // Added in Vista
42 BOOLEAN UserServerApiServerValidTable
[UserpMaxApiNumber
- USERSRV_FIRST_API_NUMBER
] =
44 FALSE
, // SrvExitWindowsEx
45 // FALSE, // SrvEndTask
47 FALSE
, // SrvRegisterServicesProcess
48 // FALSE, // SrvActivateDebugger
49 // TRUE, // SrvGetThreadConsoleDesktop
50 // FALSE, // SrvDeviceEvent
51 FALSE
, // SrvRegisterLogonProcess
52 // FALSE, // SrvCreateSystemThreads
53 // FALSE, // SrvRecordShutdownReason
54 // FALSE, // SrvCancelShutdown
55 // FALSE, // SrvConsoleHandleOperation
56 // FALSE, // SrvGetSetShutdownBlockReason
59 PCHAR UserServerApiNameTable
[UserpMaxApiNumber
- USERSRV_FIRST_API_NUMBER
] =
64 "SrvRegisterServicesProcess",
65 // "SrvActivateDebugger",
66 // "SrvGetThreadConsoleDesktop",
68 "SrvRegisterLogonProcess",
69 // "SrvCreateSystemThreads",
70 // "SrvRecordShutdownReason",
71 // "SrvCancelShutdown",
72 // "SrvConsoleHandleOperation",
73 // "SrvGetSetShutdownBlockReason",
77 /* FUNCTIONS ******************************************************************/
79 // PUSER_SOUND_SENTRY. Used in basesrv.dll
80 BOOL WINAPI
_UserSoundSentry(VOID
)
82 // TODO: Do something.
87 InitializeVideoAddressSpace(VOID
)
89 OBJECT_ATTRIBUTES ObjectAttributes
;
90 UNICODE_STRING PhysMemName
= RTL_CONSTANT_STRING(L
"\\Device\\PhysicalMemory");
96 CHAR IVTAndBda
[1024+256];
98 /* Free the 1MB pre-reserved region. In reality, ReactOS should simply support us mapping the view into the reserved area, but it doesn't. */
100 ViewSize
= 1024 * 1024;
101 Status
= ZwFreeVirtualMemory(NtCurrentProcess(),
105 if (!NT_SUCCESS(Status
))
107 DPRINT1("Couldn't unmap reserved memory (%x)\n", Status
);
111 /* Open the physical memory section */
112 InitializeObjectAttributes(&ObjectAttributes
,
117 Status
= ZwOpenSection(&PhysMemHandle
,
120 if (!NT_SUCCESS(Status
))
122 DPRINT1("Couldn't open \\Device\\PhysicalMemory\n");
126 /* Map the BIOS and device registers into the address space */
127 Offset
.QuadPart
= 0xa0000;
128 ViewSize
= 0x100000 - 0xa0000;
129 BaseAddress
= (PVOID
)0xa0000;
130 Status
= ZwMapViewOfSection(PhysMemHandle
,
139 PAGE_EXECUTE_READWRITE
);
140 if (!NT_SUCCESS(Status
))
142 DPRINT1("Couldn't map physical memory (%x)\n", Status
);
143 ZwClose(PhysMemHandle
);
147 /* Close physical memory section handle */
148 ZwClose(PhysMemHandle
);
150 if (BaseAddress
!= (PVOID
)0xa0000)
152 DPRINT1("Couldn't map physical memory at the right address (was %x)\n",
157 /* Allocate some low memory to use for the non-BIOS
158 * parts of the v86 mode address space
160 BaseAddress
= (PVOID
)0x1;
161 ViewSize
= 0xa0000 - 0x1000;
162 Status
= ZwAllocateVirtualMemory(NtCurrentProcess(),
166 MEM_RESERVE
| MEM_COMMIT
,
167 PAGE_EXECUTE_READWRITE
);
168 if (!NT_SUCCESS(Status
))
170 DPRINT1("Failed to allocate virtual memory (Status %x)\n", Status
);
173 if (BaseAddress
!= (PVOID
)0x0)
175 DPRINT1("Failed to allocate virtual memory at right address (was %x)\n",
180 /* Get the real mode IVT and BDA from the kernel */
181 Status
= NtVdmControl(VdmInitialize
, IVTAndBda
);
182 if (!NT_SUCCESS(Status
))
184 DPRINT1("NtVdmControl failed (status %x)\n", Status
);
192 /**********************************************************************
195 * TODO: we need a virtual device for sessions other than
196 * TODO: the console one
201 OBJECT_ATTRIBUTES ObjectAttributes
;
202 UNICODE_STRING DeviceName
= RTL_CONSTANT_STRING(L
"\\??\\DISPLAY1");
203 IO_STATUS_BLOCK Iosb
;
204 HANDLE VideoHandle
= (HANDLE
) 0;
205 NTSTATUS Status
= STATUS_SUCCESS
;
207 DPRINT("CSR: %s called\n", __FUNCTION__
);
209 InitializeVideoAddressSpace();
211 InitializeObjectAttributes(&ObjectAttributes
,
216 Status
= NtOpenFile(&VideoHandle
,
222 if (NT_SUCCESS(Status
))
224 NtClose(VideoHandle
);
232 PrivateCsrssManualGuiCheck(LONG Check
)
234 NtUserCallOneParam(Check
, ONEPARAM_ROUTINE_CSRSS_GUICHECK
);
237 /*** HACK from win32csr... ***/
238 static HHOOK hhk
= NULL
;
242 KeyboardHookProc(int nCode
,
246 return CallNextHookEx(hhk
, nCode
, wParam
, lParam
);
248 /*** END - HACK from win32csr... ***/
252 CreateSystemThreads(PVOID pParam
)
254 NtUserCallOneParam((DWORD
)pParam
, ONEPARAM_ROUTINE_CREATESYSTEMTHREADS
);
255 DPRINT1("This thread should not terminate!\n");
259 CSR_SERVER_DLL_INIT(UserServerDllInitialization
)
261 /*** From win32csr... ***/
266 /*** END - From win32csr... ***/
268 /* Initialize the memory */
269 UserServerHeap
= RtlGetProcessHeap();
271 /* Initialize the video */
273 NtUserInitialize(0, NULL
, NULL
);
274 PrivateCsrssManualGuiCheck(0);
276 /* Setup the DLL Object */
277 LoadedServerDll
->ApiBase
= USERSRV_FIRST_API_NUMBER
;
278 LoadedServerDll
->HighestApiSupported
= UserpMaxApiNumber
;
279 LoadedServerDll
->DispatchTable
= UserServerApiDispatchTable
;
280 LoadedServerDll
->ValidTable
= UserServerApiServerValidTable
;
281 LoadedServerDll
->NameTable
= UserServerApiNameTable
;
282 LoadedServerDll
->SizeOfProcessData
= 0;
283 LoadedServerDll
->ConnectCallback
= NULL
;
284 LoadedServerDll
->DisconnectCallback
= NULL
;
285 LoadedServerDll
->HardErrorCallback
= UserServerHardError
;
286 LoadedServerDll
->ShutdownProcessCallback
= NULL
;
288 UserServerDllInstance
= LoadedServerDll
->ServerHandle
;
290 /*** From win32csr... See r54125 ***/
291 /* Start the Raw Input Thread and the Desktop Thread */
292 for (i
= 0; i
< 2; ++i
)
294 Status
= RtlCreateUserThread(NtCurrentProcess(), NULL
, TRUE
, 0, 0, 0, (PTHREAD_START_ROUTINE
)CreateSystemThreads
, (PVOID
)i
, &ServerThread
, &ClientId
);
295 if (NT_SUCCESS(Status
))
297 NtResumeThread(ServerThread
, NULL
);
298 NtClose(ServerThread
);
301 DPRINT1("Cannot start Raw Input Thread!\n");
303 /*** END - From win32csr... ***/
306 return STATUS_SUCCESS
;
311 DllMain(IN HINSTANCE hInstanceDll
,
313 IN LPVOID lpReserved
)
315 UNREFERENCED_PARAMETER(hInstanceDll
);
316 UNREFERENCED_PARAMETER(dwReason
);
317 UNREFERENCED_PARAMETER(lpReserved
);
319 if (DLL_PROCESS_ATTACH
== dwReason
)
321 DPRINT1("WINSRV - HACK: Use keyboard hook hack\n");
322 /*** HACK from win32csr... ***/
324 // HACK HACK HACK ReactOS to BOOT! Initialization BUG ALERT! See bug 5655.
326 hhk
= SetWindowsHookEx(WH_KEYBOARD_LL
, KeyboardHookProc
, NULL
, 0);
327 // BUG ALERT! BUG ALERT! BUG ALERT! BUG ALERT! BUG ALERT! BUG ALERT! BUG ALERT!
328 // BUG ALERT! BUG ALERT! BUG ALERT! BUG ALERT! BUG ALERT! BUG ALERT! BUG ALERT!
329 // BUG ALERT! BUG ALERT! BUG ALERT! BUG ALERT! BUG ALERT! BUG ALERT! BUG ALERT!
331 /*** END - HACK from win32csr... ***/