2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS User API Server DLL
4 * FILE: win32ss/user/winsrv/usersrv/init.c
5 * PURPOSE: Initialization
6 * PROGRAMMERS: Dmitry Philippov (shedon@mail.ru)
7 * Hermes Belusca-Maito (hermes.belusca@sfr.fr)
10 /* INCLUDES *******************************************************************/
18 /* GLOBALS ********************************************************************/
20 HINSTANCE UserServerDllInstance
= NULL
;
23 HANDLE UserServerHeap
= NULL
; // Our own heap.
25 // Windows Server 2003 table from http://j00ru.vexillium.org/csrss_list/api_list.html#Windows_2k3
26 PCSR_API_ROUTINE UserServerApiDispatchTable
[UserpMaxApiNumber
- USERSRV_FIRST_API_NUMBER
] =
31 SrvRegisterServicesProcess
, // Not present in Win7
32 // SrvActivateDebugger,
33 // SrvGetThreadConsoleDesktop, // Not present in Win7
35 SrvRegisterLogonProcess
, // Not present in Win7
36 // SrvCreateSystemThreads,
37 // SrvRecordShutdownReason,
38 // SrvCancelShutdown, // Added in Vista
39 // SrvConsoleHandleOperation, // Added in Win7
40 // SrvGetSetShutdownBlockReason, // Added in Vista
43 BOOLEAN UserServerApiServerValidTable
[UserpMaxApiNumber
- USERSRV_FIRST_API_NUMBER
] =
45 FALSE
, // SrvExitWindowsEx
46 // FALSE, // SrvEndTask
48 FALSE
, // SrvRegisterServicesProcess
49 // FALSE, // SrvActivateDebugger
50 // TRUE, // SrvGetThreadConsoleDesktop
51 // FALSE, // SrvDeviceEvent
52 FALSE
, // SrvRegisterLogonProcess
53 // FALSE, // SrvCreateSystemThreads
54 // FALSE, // SrvRecordShutdownReason
55 // FALSE, // SrvCancelShutdown
56 // FALSE, // SrvConsoleHandleOperation
57 // FALSE, // SrvGetSetShutdownBlockReason
60 PCHAR UserServerApiNameTable
[UserpMaxApiNumber
- USERSRV_FIRST_API_NUMBER
] =
65 "SrvRegisterServicesProcess",
66 // "SrvActivateDebugger",
67 // "SrvGetThreadConsoleDesktop",
69 "SrvRegisterLogonProcess",
70 // "SrvCreateSystemThreads",
71 // "SrvRecordShutdownReason",
72 // "SrvCancelShutdown",
73 // "SrvConsoleHandleOperation",
74 // "SrvGetSetShutdownBlockReason",
78 /* FUNCTIONS ******************************************************************/
80 // PUSER_SOUND_SENTRY. Used in basesrv.dll
81 BOOL WINAPI
_UserSoundSentry(VOID
)
83 // TODO: Do something.
88 InitializeVideoAddressSpace(VOID
)
90 OBJECT_ATTRIBUTES ObjectAttributes
;
91 UNICODE_STRING PhysMemName
= RTL_CONSTANT_STRING(L
"\\Device\\PhysicalMemory");
97 CHAR IVTAndBda
[1024+256];
99 /* Free the 1MB pre-reserved region. In reality, ReactOS should simply support us mapping the view into the reserved area, but it doesn't. */
101 ViewSize
= 1024 * 1024;
102 Status
= ZwFreeVirtualMemory(NtCurrentProcess(),
106 if (!NT_SUCCESS(Status
))
108 DPRINT1("Couldn't unmap reserved memory (%x)\n", Status
);
112 /* Open the physical memory section */
113 InitializeObjectAttributes(&ObjectAttributes
,
118 Status
= ZwOpenSection(&PhysMemHandle
,
121 if (!NT_SUCCESS(Status
))
123 DPRINT1("Couldn't open \\Device\\PhysicalMemory\n");
127 /* Map the BIOS and device registers into the address space */
128 Offset
.QuadPart
= 0xa0000;
129 ViewSize
= 0x100000 - 0xa0000;
130 BaseAddress
= (PVOID
)0xa0000;
131 Status
= ZwMapViewOfSection(PhysMemHandle
,
140 PAGE_EXECUTE_READWRITE
);
141 if (!NT_SUCCESS(Status
))
143 DPRINT1("Couldn't map physical memory (%x)\n", Status
);
144 ZwClose(PhysMemHandle
);
148 /* Close physical memory section handle */
149 ZwClose(PhysMemHandle
);
151 if (BaseAddress
!= (PVOID
)0xa0000)
153 DPRINT1("Couldn't map physical memory at the right address (was %x)\n",
158 /* Allocate some low memory to use for the non-BIOS
159 * parts of the v86 mode address space
161 BaseAddress
= (PVOID
)0x1;
162 ViewSize
= 0xa0000 - 0x1000;
163 Status
= ZwAllocateVirtualMemory(NtCurrentProcess(),
167 MEM_RESERVE
| MEM_COMMIT
,
168 PAGE_EXECUTE_READWRITE
);
169 if (!NT_SUCCESS(Status
))
171 DPRINT1("Failed to allocate virtual memory (Status %x)\n", Status
);
174 if (BaseAddress
!= (PVOID
)0x0)
176 DPRINT1("Failed to allocate virtual memory at right address (was %x)\n",
181 /* Get the real mode IVT and BDA from the kernel */
182 Status
= NtVdmControl(VdmInitialize
, IVTAndBda
);
183 if (!NT_SUCCESS(Status
))
185 DPRINT1("NtVdmControl failed (status %x)\n", Status
);
193 /**********************************************************************
196 * TODO: we need a virtual device for sessions other than
197 * TODO: the console one
202 OBJECT_ATTRIBUTES ObjectAttributes
;
203 UNICODE_STRING DeviceName
= RTL_CONSTANT_STRING(L
"\\??\\DISPLAY1");
204 IO_STATUS_BLOCK Iosb
;
205 HANDLE VideoHandle
= (HANDLE
) 0;
206 NTSTATUS Status
= STATUS_SUCCESS
;
208 DPRINT("CSR: %s called\n", __FUNCTION__
);
210 InitializeVideoAddressSpace();
212 InitializeObjectAttributes(&ObjectAttributes
,
217 Status
= NtOpenFile(&VideoHandle
,
223 if (NT_SUCCESS(Status
))
225 NtClose(VideoHandle
);
231 // From win32ss/user/win32csr/dllmain.c
234 PrivateCsrssManualGuiCheck(LONG Check
)
236 NtUserCallOneParam(Check
, ONEPARAM_ROUTINE_CSRSS_GUICHECK
);
241 CreateSystemThreads(PVOID pParam
)
243 NtUserCallOneParam((DWORD
)pParam
, ONEPARAM_ROUTINE_CREATESYSTEMTHREADS
);
244 DPRINT1("This thread should not terminate!\n");
248 CSR_SERVER_DLL_INIT(UserServerDllInitialization
)
250 /*** From win32csr... ***/
255 /*** END - From win32csr... ***/
257 /* Initialize the memory */
258 UserServerHeap
= RtlGetProcessHeap();
260 /* Initialize the video */
262 NtUserInitialize(0, NULL
, NULL
);
263 PrivateCsrssManualGuiCheck(0);
265 /* Setup the DLL Object */
266 LoadedServerDll
->ApiBase
= USERSRV_FIRST_API_NUMBER
;
267 LoadedServerDll
->HighestApiSupported
= UserpMaxApiNumber
;
268 LoadedServerDll
->DispatchTable
= UserServerApiDispatchTable
;
269 LoadedServerDll
->ValidTable
= UserServerApiServerValidTable
;
270 LoadedServerDll
->NameTable
= UserServerApiNameTable
;
271 LoadedServerDll
->SizeOfProcessData
= 0;
272 LoadedServerDll
->ConnectCallback
= NULL
;
273 LoadedServerDll
->DisconnectCallback
= NULL
;
274 LoadedServerDll
->HardErrorCallback
= UserServerHardError
;
275 LoadedServerDll
->ShutdownProcessCallback
= NULL
;
277 UserServerDllInstance
= LoadedServerDll
->ServerHandle
;
279 /*** From win32csr... See r54125 ***/
280 /* Start the Raw Input Thread and the Desktop Thread */
281 for (i
= 0; i
< 2; ++i
)
283 Status
= RtlCreateUserThread(NtCurrentProcess(), NULL
, TRUE
, 0, 0, 0, (PTHREAD_START_ROUTINE
)CreateSystemThreads
, (PVOID
)i
, &ServerThread
, &ClientId
);
284 if (NT_SUCCESS(Status
))
286 NtResumeThread(ServerThread
, NULL
);
287 NtClose(ServerThread
);
290 DPRINT1("Cannot start Raw Input Thread!\n");
292 /*** END - From win32csr... ***/
295 return STATUS_SUCCESS
;