[WINSRV]
[reactos.git] / reactos / win32ss / user / winsrv / usersrv / init.c
1 /*
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)
8 */
9
10 /* INCLUDES *******************************************************************/
11
12 #include "usersrv.h"
13
14 #include "api.h"
15
16 #define NDEBUG
17 #include <debug.h>
18
19 /* GLOBALS ********************************************************************/
20
21 HINSTANCE UserServerDllInstance = NULL;
22
23 /* Memory */
24 HANDLE UserServerHeap = NULL; // Our own heap.
25
26 // Windows Server 2003 table from http://j00ru.vexillium.org/csrss_list/api_list.html#Windows_2k3
27 PCSR_API_ROUTINE UserServerApiDispatchTable[UserpMaxApiNumber - USERSRV_FIRST_API_NUMBER] =
28 {
29 SrvExitWindowsEx,
30 SrvEndTask,
31 SrvLogon,
32 SrvRegisterServicesProcess, // Not present in Win7
33 SrvActivateDebugger,
34 SrvGetThreadConsoleDesktop, // Not present in Win7
35 SrvDeviceEvent,
36 SrvRegisterLogonProcess, // Not present in Win7
37 SrvCreateSystemThreads,
38 SrvRecordShutdownReason,
39 // SrvCancelShutdown, // Added in Vista
40 // SrvConsoleHandleOperation, // Added in Win7
41 // SrvGetSetShutdownBlockReason, // Added in Vista
42 };
43
44 BOOLEAN UserServerApiServerValidTable[UserpMaxApiNumber - USERSRV_FIRST_API_NUMBER] =
45 {
46 FALSE, // SrvExitWindowsEx
47 FALSE, // SrvEndTask
48 FALSE, // SrvLogon
49 FALSE, // SrvRegisterServicesProcess
50 FALSE, // SrvActivateDebugger
51 TRUE, // SrvGetThreadConsoleDesktop
52 FALSE, // SrvDeviceEvent
53 FALSE, // SrvRegisterLogonProcess
54 FALSE, // SrvCreateSystemThreads
55 FALSE, // SrvRecordShutdownReason
56 // FALSE, // SrvCancelShutdown
57 // FALSE, // SrvConsoleHandleOperation
58 // FALSE, // SrvGetSetShutdownBlockReason
59 };
60
61 /*
62 * On Windows Server 2003, CSR Servers contain
63 * the API Names Table only in Debug Builds.
64 */
65 #ifdef CSR_DBG
66 PCHAR UserServerApiNameTable[UserpMaxApiNumber - USERSRV_FIRST_API_NUMBER] =
67 {
68 "SrvExitWindowsEx",
69 "SrvEndTask",
70 "SrvLogon",
71 "SrvRegisterServicesProcess",
72 "SrvActivateDebugger",
73 "SrvGetThreadConsoleDesktop",
74 "SrvDeviceEvent",
75 "SrvRegisterLogonProcess",
76 "SrvCreateSystemThreads",
77 "SrvRecordShutdownReason",
78 // "SrvCancelShutdown",
79 // "SrvConsoleHandleOperation",
80 // "SrvGetSetShutdownBlockReason",
81 };
82 #endif
83
84 /* FUNCTIONS ******************************************************************/
85
86 // PUSER_SOUND_SENTRY. Used in basesrv.dll
87 BOOL WINAPI _UserSoundSentry(VOID)
88 {
89 // TODO: Do something.
90 return TRUE;
91 }
92
93 ULONG
94 NTAPI
95 CreateSystemThreads(PVOID pParam)
96 {
97 NtUserCallOneParam((DWORD)pParam, ONEPARAM_ROUTINE_CREATESYSTEMTHREADS);
98 DPRINT1("This thread should not terminate!\n");
99 return 0;
100 }
101
102 CSR_API(SrvCreateSystemThreads)
103 {
104 DPRINT1("%s not yet implemented\n", __FUNCTION__);
105 return STATUS_NOT_IMPLEMENTED;
106 }
107
108 CSR_API(SrvActivateDebugger)
109 {
110 DPRINT1("%s not yet implemented\n", __FUNCTION__);
111 return STATUS_NOT_IMPLEMENTED;
112 }
113
114 CSR_API(SrvGetThreadConsoleDesktop)
115 {
116 PUSER_GET_THREAD_CONSOLE_DESKTOP GetThreadConsoleDesktopRequest = &((PUSER_API_MESSAGE)ApiMessage)->Data.GetThreadConsoleDesktopRequest;
117
118 DPRINT1("%s not yet implemented\n", __FUNCTION__);
119
120 /* Return nothing for the moment... */
121 GetThreadConsoleDesktopRequest->ConsoleDesktop = NULL;
122
123 /* Always succeeds */
124 return STATUS_SUCCESS;
125 }
126
127 CSR_API(SrvDeviceEvent)
128 {
129 DPRINT1("%s not yet implemented\n", __FUNCTION__);
130 return STATUS_NOT_IMPLEMENTED;
131 }
132
133 CSR_SERVER_DLL_INIT(UserServerDllInitialization)
134 {
135 /*** From win32csr... ***/
136 HANDLE ServerThread;
137 CLIENT_ID ClientId;
138 NTSTATUS Status;
139 UINT i;
140 /*** END - From win32csr... ***/
141
142 /* Initialize the memory */
143 UserServerHeap = RtlGetProcessHeap();
144
145 /* Initialize the video */
146 NtUserInitialize(0, NULL, NULL);
147
148 /* Setup the DLL Object */
149 LoadedServerDll->ApiBase = USERSRV_FIRST_API_NUMBER;
150 LoadedServerDll->HighestApiSupported = UserpMaxApiNumber;
151 LoadedServerDll->DispatchTable = UserServerApiDispatchTable;
152 LoadedServerDll->ValidTable = UserServerApiServerValidTable;
153 #ifdef CSR_DBG
154 LoadedServerDll->NameTable = UserServerApiNameTable;
155 #endif
156 LoadedServerDll->SizeOfProcessData = 0;
157 LoadedServerDll->ConnectCallback = NULL;
158 LoadedServerDll->DisconnectCallback = NULL;
159 LoadedServerDll->HardErrorCallback = UserServerHardError;
160 LoadedServerDll->ShutdownProcessCallback = UserClientShutdown;
161
162 UserServerDllInstance = LoadedServerDll->ServerHandle;
163
164 /*** From win32csr... See r54125 ***/
165 /* Start the Raw Input Thread and the Desktop Thread */
166 for (i = 0; i < 2; ++i)
167 {
168 Status = RtlCreateUserThread(NtCurrentProcess(),
169 NULL, TRUE, 0, 0, 0,
170 CreateSystemThreads,
171 (PVOID)i, &ServerThread, &ClientId);
172 if (NT_SUCCESS(Status))
173 {
174 NtResumeThread(ServerThread, NULL);
175 NtClose(ServerThread);
176 }
177 else
178 DPRINT1("Cannot start Raw Input Thread!\n");
179 }
180 /*** END - From win32csr... ***/
181
182 /* All done */
183 return STATUS_SUCCESS;
184 }
185
186 /* EOF */