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 *******************************************************************/
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 ******************************************************************/
93 // PUSER_SOUND_SENTRY. Used in basesrv.dll
94 BOOL NTAPI
_UserSoundSentry(VOID
)
96 // TODO: Do something.
102 CreateSystemThreads(PVOID pParam
)
104 NtUserCallOneParam((DWORD
)pParam
, ONEPARAM_ROUTINE_CREATESYSTEMTHREADS
);
105 RtlExitUserThread(0);
109 CSR_API(SrvCreateSystemThreads
)
111 DPRINT1("%s not yet implemented\n", __FUNCTION__
);
112 return STATUS_NOT_IMPLEMENTED
;
115 CSR_API(SrvActivateDebugger
)
117 DPRINT1("%s not yet implemented\n", __FUNCTION__
);
118 return STATUS_NOT_IMPLEMENTED
;
121 CSR_API(SrvGetThreadConsoleDesktop
)
123 PUSER_GET_THREAD_CONSOLE_DESKTOP GetThreadConsoleDesktopRequest
= &((PUSER_API_MESSAGE
)ApiMessage
)->Data
.GetThreadConsoleDesktopRequest
;
125 DPRINT1("%s not yet implemented\n", __FUNCTION__
);
127 /* Return nothing for the moment... */
128 GetThreadConsoleDesktopRequest
->ConsoleDesktop
= NULL
;
130 /* Always succeeds */
131 return STATUS_SUCCESS
;
134 CSR_API(SrvDeviceEvent
)
136 DPRINT1("%s not yet implemented\n", __FUNCTION__
);
137 return STATUS_NOT_IMPLEMENTED
;
142 PUSER_LOGON LogonRequest
= &((PUSER_API_MESSAGE
)ApiMessage
)->Data
.LogonRequest
;
144 DPRINT1("We are logged %s\n", LogonRequest
->IsLogon
? "on" : "off");
146 /* Impersonate the caller in order to retrieve settings in its context */
147 if (!CsrImpersonateClient(NULL
))
148 return STATUS_UNSUCCESSFUL
;
150 GetTimeouts(&ShutdownSettings
);
154 return STATUS_SUCCESS
;
159 UserClientConnect(IN PCSR_PROCESS CsrProcess
,
160 IN OUT PVOID ConnectionInfo
,
161 IN OUT PULONG ConnectionInfoLength
)
165 PUSERSRV_API_CONNECTINFO ConnectInfo
= (PUSERSRV_API_CONNECTINFO
)ConnectionInfo
;
167 DPRINT("UserClientConnect\n");
169 /* Check if we don't have an API port yet */
170 if (CsrApiPort
== NULL
)
172 /* Query the API port and save it globally */
173 CsrApiPort
= CsrQueryApiPort();
175 /* Inform win32k about the API port */
176 Status
= NtUserSetInformationThread(NtCurrentThread(),
177 UserThreadCsrApiPort
,
180 if (!NT_SUCCESS(Status
))
186 /* Check connection info validity */
187 if ( ConnectionInfo
== NULL
||
188 ConnectionInfoLength
== NULL
||
189 *ConnectionInfoLength
!= sizeof(*ConnectInfo
) )
191 DPRINT1("USERSRV: Connection failed - ConnectionInfo = 0x%p ; ConnectionInfoLength = 0x%p (%lu), expected %lu\n",
193 ConnectionInfoLength
,
194 ConnectionInfoLength
? *ConnectionInfoLength
: (ULONG
)-1,
195 sizeof(*ConnectInfo
));
197 return STATUS_INVALID_PARAMETER
;
200 /* Pass the request to win32k */
201 ConnectInfo
->dwDispatchCount
= 0; // gDispatchTableValues;
202 Status
= NtUserProcessConnect(CsrProcess
->ProcessHandle
,
204 *ConnectionInfoLength
);
209 CSR_SERVER_DLL_INIT(UserServerDllInitialization
)
213 /* Initialize the memory */
214 UserServerHeap
= RtlGetProcessHeap();
216 /* Setup the DLL Object */
217 LoadedServerDll
->ApiBase
= USERSRV_FIRST_API_NUMBER
;
218 LoadedServerDll
->HighestApiSupported
= UserpMaxApiNumber
;
219 LoadedServerDll
->DispatchTable
= UserServerApiDispatchTable
;
220 LoadedServerDll
->ValidTable
= UserServerApiServerValidTable
;
222 LoadedServerDll
->NameTable
= UserServerApiNameTable
;
224 LoadedServerDll
->SizeOfProcessData
= 0;
225 LoadedServerDll
->ConnectCallback
= UserClientConnect
;
226 LoadedServerDll
->DisconnectCallback
= NULL
;
227 LoadedServerDll
->HardErrorCallback
= UserServerHardError
;
228 LoadedServerDll
->ShutdownProcessCallback
= UserClientShutdown
;
230 UserServerDllInstance
= LoadedServerDll
->ServerHandle
;
232 /* Create the power request event */
233 Status
= NtCreateEvent(&ghPowerRequestEvent
,
236 SynchronizationEvent
,
238 if (!NT_SUCCESS(Status
))
240 DPRINT1("Power request event creation failed with Status 0x%08x\n", Status
);
244 /* Create the media request event */
245 Status
= NtCreateEvent(&ghMediaRequestEvent
,
248 SynchronizationEvent
,
250 if (!NT_SUCCESS(Status
))
252 DPRINT1("Media request event creation failed with Status 0x%08x\n", Status
);
256 /* Set the process creation notify routine for BASE */
257 BaseSetProcessCreateNotify(NtUserNotifyProcessCreate
);
259 /* Initialize the kernel mode subsystem */
260 Status
= NtUserInitialize(USER_VERSION
,
262 ghMediaRequestEvent
);
263 if (!NT_SUCCESS(Status
))
265 DPRINT1("NtUserInitialize failed with Status 0x%08x\n", Status
);
269 /*** From win32csr... See r54125 ***/
275 /* Start the Raw Input Thread and the Desktop Thread */
276 for (i
= 0; i
< 2; ++i
)
278 Status
= RtlCreateUserThread(NtCurrentProcess(),
281 (PVOID
)i
, &ServerThread
, &ClientId
);
282 if (NT_SUCCESS(Status
))
284 NtResumeThread(ServerThread
, NULL
);
285 NtClose(ServerThread
);
289 DPRINT1("Cannot start Raw Input Thread!\n");
293 /*** END - From win32csr... ***/
296 return STATUS_SUCCESS
;