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 *******************************************************************/
13 #include "api.h" // USERSRV Public server APIs definitions
14 #include "../consrv/api.h" // CONSRV Public server APIs definitions
19 /* GLOBALS ********************************************************************/
21 HINSTANCE UserServerDllInstance
= NULL
;
23 /* Handles for Power and Media events. Used by both usersrv and win32k. */
24 HANDLE ghPowerRequestEvent
;
25 HANDLE ghMediaRequestEvent
;
27 /* Copy of CSR Port handle for win32k */
28 HANDLE CsrApiPort
= NULL
;
31 HANDLE UserServerHeap
= NULL
; // Our own heap.
33 // Windows Server 2003 table from http://j00ru.vexillium.org/csrss_list/api_list.html#Windows_2k3
34 PCSR_API_ROUTINE UserServerApiDispatchTable
[UserpMaxApiNumber
- USERSRV_FIRST_API_NUMBER
] =
39 SrvRegisterServicesProcess
, // Not present in Win7
41 SrvGetThreadConsoleDesktop
, // Not present in Win7
43 SrvRegisterLogonProcess
, // Not present in Win7
44 SrvCreateSystemThreads
,
45 SrvRecordShutdownReason
,
46 // SrvCancelShutdown, // Added in Vista
47 // SrvConsoleHandleOperation, // Added in Win7
48 // SrvGetSetShutdownBlockReason, // Added in Vista
51 BOOLEAN UserServerApiServerValidTable
[UserpMaxApiNumber
- USERSRV_FIRST_API_NUMBER
] =
53 FALSE
, // SrvExitWindowsEx
56 FALSE
, // SrvRegisterServicesProcess
57 FALSE
, // SrvActivateDebugger
58 TRUE
, // SrvGetThreadConsoleDesktop
59 FALSE
, // SrvDeviceEvent
60 FALSE
, // SrvRegisterLogonProcess
61 FALSE
, // SrvCreateSystemThreads
62 FALSE
, // SrvRecordShutdownReason
63 // FALSE, // SrvCancelShutdown
64 // FALSE, // SrvConsoleHandleOperation
65 // FALSE, // SrvGetSetShutdownBlockReason
69 * On Windows Server 2003, CSR Servers contain
70 * the API Names Table only in Debug Builds.
73 PCHAR UserServerApiNameTable
[UserpMaxApiNumber
- USERSRV_FIRST_API_NUMBER
] =
78 "SrvRegisterServicesProcess",
79 "SrvActivateDebugger",
80 "SrvGetThreadConsoleDesktop",
82 "SrvRegisterLogonProcess",
83 "SrvCreateSystemThreads",
84 "SrvRecordShutdownReason",
85 // "SrvCancelShutdown",
86 // "SrvConsoleHandleOperation",
87 // "SrvGetSetShutdownBlockReason",
91 /* FUNCTIONS ******************************************************************/
98 if (GetWindow(hWnd
, GW_OWNER
) == NULL
)
100 *(HWND
*)lParam
= hWnd
;
106 // PUSER_SOUND_SENTRY. Used in basesrv.dll
107 BOOL NTAPI
_UserSoundSentry(VOID
)
109 // TODO: Do something.
115 CreateSystemThreads(PVOID pParam
)
117 NtUserCallOneParam((DWORD_PTR
)pParam
, ONEPARAM_ROUTINE_CREATESYSTEMTHREADS
);
118 RtlExitUserThread(0);
122 /* API_NUMBER: UserpCreateSystemThreads */
123 CSR_API(SrvCreateSystemThreads
)
125 NTSTATUS Status
= CsrExecServerThread(CreateSystemThreads
, 0);
126 if (!NT_SUCCESS(Status
))
128 DPRINT1("Cannot start system thread!\n");
134 /* API_NUMBER: UserpActivateDebugger */
135 CSR_API(SrvActivateDebugger
)
137 DPRINT1("%s not yet implemented\n", __FUNCTION__
);
138 return STATUS_NOT_IMPLEMENTED
;
141 /* API_NUMBER: UserpGetThreadConsoleDesktop */
142 CSR_API(SrvGetThreadConsoleDesktop
)
145 PUSER_GET_THREAD_CONSOLE_DESKTOP GetThreadConsoleDesktopRequest
= &((PUSER_API_MESSAGE
)ApiMessage
)->Data
.GetThreadConsoleDesktopRequest
;
147 Status
= GetThreadConsoleDesktop(GetThreadConsoleDesktopRequest
->ThreadId
,
148 &GetThreadConsoleDesktopRequest
->ConsoleDesktop
);
149 if (!NT_SUCCESS(Status
))
151 DPRINT1("GetThreadConsoleDesktop(%lu) failed with Status 0x%08x\n",
152 GetThreadConsoleDesktopRequest
->ThreadId
, Status
);
155 /* Windows-compatibility: Always return success since User32 relies on this! */
156 return STATUS_SUCCESS
;
159 /* API_NUMBER: UserpDeviceEvent */
160 CSR_API(SrvDeviceEvent
)
162 DPRINT1("%s not yet implemented\n", __FUNCTION__
);
163 return STATUS_NOT_IMPLEMENTED
;
166 /* API_NUMBER: UserpLogon */
169 PUSER_LOGON LogonRequest
= &((PUSER_API_MESSAGE
)ApiMessage
)->Data
.LogonRequest
;
171 DPRINT1("We are logged %s\n", LogonRequest
->IsLogon
? "on" : "off");
173 /* Impersonate the caller in order to retrieve settings in its context */
174 if (!CsrImpersonateClient(NULL
))
175 return STATUS_UNSUCCESSFUL
;
177 GetTimeouts(&ShutdownSettings
);
181 return STATUS_SUCCESS
;
186 UserClientConnect(IN PCSR_PROCESS CsrProcess
,
187 IN OUT PVOID ConnectionInfo
,
188 IN OUT PULONG ConnectionInfoLength
)
192 PUSERSRV_API_CONNECTINFO ConnectInfo
= (PUSERSRV_API_CONNECTINFO
)ConnectionInfo
;
194 DPRINT("UserClientConnect\n");
196 /* Check if we don't have an API port yet */
197 if (CsrApiPort
== NULL
)
199 /* Query the API port and save it globally */
200 CsrApiPort
= CsrQueryApiPort();
202 /* Inform win32k about the API port */
203 Status
= NtUserSetInformationThread(NtCurrentThread(),
204 UserThreadCsrApiPort
,
207 if (!NT_SUCCESS(Status
))
213 /* Check connection info validity */
214 if ( ConnectionInfo
== NULL
||
215 ConnectionInfoLength
== NULL
||
216 *ConnectionInfoLength
!= sizeof(*ConnectInfo
) )
218 DPRINT1("USERSRV: Connection failed - ConnectionInfo = 0x%p ; ConnectionInfoLength = 0x%p (%lu), expected %lu\n",
220 ConnectionInfoLength
,
221 ConnectionInfoLength
? *ConnectionInfoLength
: (ULONG
)-1,
222 sizeof(*ConnectInfo
));
224 return STATUS_INVALID_PARAMETER
;
227 /* Pass the request to win32k */
228 ConnectInfo
->dwDispatchCount
= 0; // gDispatchTableValues;
229 Status
= NtUserProcessConnect(CsrProcess
->ProcessHandle
,
231 *ConnectionInfoLength
);
236 CSR_SERVER_DLL_INIT(UserServerDllInitialization
)
240 /* Initialize the memory */
241 UserServerHeap
= RtlGetProcessHeap();
243 /* Setup the DLL Object */
244 LoadedServerDll
->ApiBase
= USERSRV_FIRST_API_NUMBER
;
245 LoadedServerDll
->HighestApiSupported
= UserpMaxApiNumber
;
246 LoadedServerDll
->DispatchTable
= UserServerApiDispatchTable
;
247 LoadedServerDll
->ValidTable
= UserServerApiServerValidTable
;
249 LoadedServerDll
->NameTable
= UserServerApiNameTable
;
251 LoadedServerDll
->SizeOfProcessData
= 0;
252 LoadedServerDll
->ConnectCallback
= UserClientConnect
;
253 LoadedServerDll
->DisconnectCallback
= NULL
;
254 LoadedServerDll
->HardErrorCallback
= UserServerHardError
;
255 LoadedServerDll
->ShutdownProcessCallback
= UserClientShutdown
;
257 UserServerDllInstance
= LoadedServerDll
->ServerHandle
;
259 /* Create the power request event */
260 Status
= NtCreateEvent(&ghPowerRequestEvent
,
263 SynchronizationEvent
,
265 if (!NT_SUCCESS(Status
))
267 DPRINT1("Power request event creation failed with Status 0x%08x\n", Status
);
271 /* Create the media request event */
272 Status
= NtCreateEvent(&ghMediaRequestEvent
,
275 SynchronizationEvent
,
277 if (!NT_SUCCESS(Status
))
279 DPRINT1("Media request event creation failed with Status 0x%08x\n", Status
);
283 /* Set the process creation notify routine for BASE */
284 BaseSetProcessCreateNotify(NtUserNotifyProcessCreate
);
286 /* Initialize the hard errors cache */
287 UserInitHardErrorsCache();
289 /* Initialize the kernel mode subsystem */
290 Status
= NtUserInitialize(USER_VERSION
,
292 ghMediaRequestEvent
);
293 if (!NT_SUCCESS(Status
))
295 DPRINT1("NtUserInitialize failed with Status 0x%08x\n", Status
);
300 return STATUS_SUCCESS
;