[CONSRV/WIN32CSR]
[reactos.git] / win32ss / user / consrv / init.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Console Server DLL
4 * FILE: win32ss/user/consrv/init.c
5 * PURPOSE: Initialization
6 * PROGRAMMERS: Hermes Belusca-Maito (hermes.belusca@sfr.fr)
7 */
8
9 #include "consrv.h"
10
11 #define NDEBUG
12 #include <debug.h>
13
14 HANDLE DllHandle = NULL;
15 // HANDLE BaseApiPort = NULL;
16
17 /* Memory */
18 HANDLE ConSrvHeap = NULL; // Our own heap.
19 // HANDLE BaseSrvSharedHeap = NULL; // Shared heap with CSR. (CsrSrvSharedSectionHeap)
20 // PBASE_STATIC_SERVER_DATA BaseStaticServerData = NULL; // Data that we can share amongst processes. Initialized inside BaseSrvSharedHeap.
21
22 // Windows 2k3 tables, adapted from http://j00ru.vexillium.org/csrss_list/api_list.html#Windows_2k3
23 // plus a little bit of Windows 7. It is for testing purposes. After that I will add stubs.
24 // Some names are also deduced from the subsystems/win32/csrss/csrsrv/server.c ones.
25 PCSR_API_ROUTINE ConsoleServerApiDispatchTable[ConsolepMaxApiNumber] =
26 {
27 // SrvOpenConsole,
28 SrvGetConsoleInput,
29 SrvWriteConsoleInput,
30 SrvReadConsoleOutput,
31 SrvWriteConsoleOutput,
32 // SrvReadConsoleOutputString,
33 // SrvWriteConsoleOutputString,
34 // SrvFillConsoleOutput,
35 SrvGetConsoleMode,
36 // SrvGetConsoleNumberOfFonts,
37 SrvGetConsoleNumberOfInputEvents,
38 SrvGetConsoleScreenBufferInfo,
39 SrvGetConsoleCursorInfo,
40 // SrvGetConsoleMouseInfo,
41 // SrvGetConsoleFontInfo,
42 // SrvGetConsoleFontSize,
43 // SrvGetConsoleCurrentFont,
44 SrvSetConsoleMode,
45 SrvSetConsoleActiveScreenBuffer,
46 SrvFlushConsoleInputBuffer,
47 // SrvGetLargestConsoleWindowSize,
48 SrvSetConsoleScreenBufferSize,
49 // SrvSetConsoleCursorPosition,
50 SrvSetConsoleCursorInfo,
51 // SrvSetConsoleWindowInfo,
52 SrvScrollConsoleScreenBuffer,
53 // SrvSetConsoleTextAttribute,
54 // SrvSetConsoleFont,
55 SrvSetConsoleIcon,
56 SrvReadConsole,
57 SrvWriteConsole,
58 SrvDuplicateHandle,
59 // SrvGetHandleInformation,
60 // SrvSetHandleInformation,
61 SrvCloseHandle,
62 SrvVerifyConsoleIoHandle,
63 SrvAllocConsole,
64 SrvFreeConsole,
65 SrvGetConsoleTitle,
66 SrvSetConsoleTitle,
67 SrvCreateConsoleScreenBuffer,
68 // SrvInvalidateBitMapRect,
69 // SrvVDMConsoleOperation,
70 SrvSetConsoleCursor,
71 // SrvShowConsoleCursor,
72 // SrvConsoleMenuControl,
73 // SrvSetConsolePalette,
74 // SrvSetConsoleDisplayMode,
75 // SrvRegisterConsoleVDM,
76 SrvGetConsoleHardwareState,
77 SrvSetConsoleHardwareState,
78 // SrvGetConsoleDisplayMode,
79 SrvAddConsoleAlias,
80 SrvGetConsoleAlias,
81 SrvGetConsoleAliasesLength,
82 SrvGetConsoleAliasExesLength,
83 SrvGetConsoleAliases,
84 SrvGetConsoleAliasExes,
85 SrvExpungeConsoleCommandHistory,
86 SrvSetConsoleNumberOfCommands,
87 SrvGetConsoleCommandHistoryLength,
88 SrvGetConsoleCommandHistory,
89 // SrvSetConsoleCommandHistoryMode,
90 SrvGetConsoleCP,
91 SrvSetConsoleCP,
92 // SrvSetConsoleKeyShortcuts,
93 // SrvSetConsoleMenuClose,
94 // SrvConsoleNotifyLastClose,
95 SrvGenerateConsoleCtrlEvent,
96 // SrvGetConsoleKeyboardLayoutName,
97 SrvGetConsoleWindow,
98 // SrvGetConsoleCharType,
99 // SrvSetConsoleLocalEUDC,
100 // SrvSetConsoleCursorMode,
101 // SrvGetConsoleCursorMode,
102 // SrvRegisterConsoleOS2,
103 // SrvSetConsoleOS2OemFormat,
104 // SrvGetConsoleNlsMode,
105 // SrvSetConsoleNlsMode,
106 // SrvRegisterConsoleIME,
107 // SrvUnregisterConsoleIME,
108 // SrvGetConsoleLangId,
109 // SrvAttachConsole,
110 SrvGetConsoleSelectionInfo,
111 SrvGetConsoleProcessList,
112 SrvGetConsoleHistory,
113 SrvSetConsoleHistory
114 };
115
116 BOOLEAN ConsoleServerApiServerValidTable[ConsolepMaxApiNumber] =
117 {
118 // FALSE, // SrvOpenConsole,
119 FALSE, // SrvGetConsoleInput,
120 FALSE, // SrvWriteConsoleInput,
121 FALSE, // SrvReadConsoleOutput,
122 FALSE, // SrvWriteConsoleOutput,
123 // FALSE, // SrvReadConsoleOutputString,
124 // FALSE, // SrvWriteConsoleOutputString,
125 // FALSE, // SrvFillConsoleOutput,
126 FALSE, // SrvGetConsoleMode,
127 // FALSE, // SrvGetConsoleNumberOfFonts,
128 FALSE, // SrvGetConsoleNumberOfInputEvents,
129 FALSE, // SrvGetConsoleScreenBufferInfo,
130 FALSE, // SrvGetConsoleCursorInfo,
131 // FALSE, // SrvGetConsoleMouseInfo,
132 // FALSE, // SrvGetConsoleFontInfo,
133 // FALSE, // SrvGetConsoleFontSize,
134 // FALSE, // SrvGetConsoleCurrentFont,
135 FALSE, // SrvSetConsoleMode,
136 FALSE, // SrvSetConsoleActiveScreenBuffer,
137 FALSE, // SrvFlushConsoleInputBuffer,
138 // FALSE, // SrvGetLargestConsoleWindowSize,
139 FALSE, // SrvSetConsoleScreenBufferSize,
140 // FALSE, // SrvSetConsoleCursorPosition,
141 FALSE, // SrvSetConsoleCursorInfo,
142 // FALSE, // SrvSetConsoleWindowInfo,
143 FALSE, // SrvScrollConsoleScreenBuffer,
144 // FALSE, // SrvSetConsoleTextAttribute,
145 // FALSE, // SrvSetConsoleFont,
146 FALSE, // SrvSetConsoleIcon,
147 FALSE, // SrvReadConsole,
148 FALSE, // SrvWriteConsole,
149 FALSE, // SrvDuplicateHandle,
150 // FALSE, // SrvGetHandleInformation,
151 // FALSE, // SrvSetHandleInformation,
152 FALSE, // SrvCloseHandle,
153 FALSE, // SrvVerifyConsoleIoHandle,
154 FALSE, // SrvAllocConsole,
155 FALSE, // SrvFreeConsole,
156 FALSE, // SrvGetConsoleTitle,
157 FALSE, // SrvSetConsoleTitle,
158 FALSE, // SrvCreateConsoleScreenBuffer,
159 // FALSE, // SrvInvalidateBitMapRect,
160 // FALSE, // SrvVDMConsoleOperation,
161 FALSE, // SrvSetConsoleCursor,
162 // FALSE, // SrvShowConsoleCursor,
163 // FALSE, // SrvConsoleMenuControl,
164 // FALSE, // SrvSetConsolePalette,
165 // FALSE, // SrvSetConsoleDisplayMode,
166 // FALSE, // SrvRegisterConsoleVDM,
167 FALSE, // SrvGetConsoleHardwareState,
168 FALSE, // SrvSetConsoleHardwareState,
169 // TRUE, // SrvGetConsoleDisplayMode,
170 FALSE, // SrvAddConsoleAlias,
171 FALSE, // SrvGetConsoleAlias,
172 FALSE, // SrvGetConsoleAliasesLength,
173 FALSE, // SrvGetConsoleAliasExesLength,
174 FALSE, // SrvGetConsoleAliases,
175 FALSE, // SrvGetConsoleAliasExes,
176 FALSE, // SrvExpungeConsoleCommandHistory,
177 FALSE, // SrvSetConsoleNumberOfCommands,
178 FALSE, // SrvGetConsoleCommandHistoryLength,
179 FALSE, // SrvGetConsoleCommandHistory,
180 // FALSE, // SrvSetConsoleCommandHistoryMode,
181 FALSE, // SrvGetConsoleCP,
182 FALSE, // SrvSetConsoleCP,
183 // FALSE, // SrvSetConsoleKeyShortcuts,
184 // FALSE, // SrvSetConsoleMenuClose,
185 // FALSE, // SrvConsoleNotifyLastClose,
186 FALSE, // SrvGenerateConsoleCtrlEvent,
187 // FALSE, // SrvGetConsoleKeyboardLayoutName,
188 FALSE, // SrvGetConsoleWindow,
189 // FALSE, // SrvGetConsoleCharType,
190 // FALSE, // SrvSetConsoleLocalEUDC,
191 // FALSE, // SrvSetConsoleCursorMode,
192 // FALSE, // SrvGetConsoleCursorMode,
193 // FALSE, // SrvRegisterConsoleOS2,
194 // FALSE, // SrvSetConsoleOS2OemFormat,
195 // FALSE, // SrvGetConsoleNlsMode,
196 // FALSE, // SrvSetConsoleNlsMode,
197 // FALSE, // SrvRegisterConsoleIME,
198 // FALSE, // SrvUnregisterConsoleIME,
199 // FALSE, // SrvGetConsoleLangId,
200 // FALSE, // SrvAttachConsole,
201 FALSE, // SrvGetConsoleSelectionInfo,
202 FALSE, // SrvGetConsoleProcessList,
203 FALSE, // SrvGetConsoleHistory,
204 FALSE, // SrvSetConsoleHistory
205
206 // FALSE
207 };
208
209 PCHAR ConsoleServerApiNameTable[ConsolepMaxApiNumber] =
210 {
211 // "OpenConsole",
212 "GetConsoleInput",
213 "WriteConsoleInput",
214 "ReadConsoleOutput",
215 "WriteConsoleOutput",
216 // "ReadConsoleOutputString",
217 // "WriteConsoleOutputString",
218 // "FillConsoleOutput",
219 "GetConsoleMode",
220 // "GetConsoleNumberOfFonts",
221 "GetConsoleNumberOfInputEvents",
222 "GetConsoleScreenBufferInfo",
223 "GetConsoleCursorInfo",
224 // "GetConsoleMouseInfo",
225 // "GetConsoleFontInfo",
226 // "GetConsoleFontSize",
227 // "GetConsoleCurrentFont",
228 "SetConsoleMode",
229 "SetConsoleActiveScreenBuffer",
230 "FlushConsoleInputBuffer",
231 // "GetLargestConsoleWindowSize",
232 "SetConsoleScreenBufferSize",
233 // "SetConsoleCursorPosition",
234 "SetConsoleCursorInfo",
235 // "SetConsoleWindowInfo",
236 "ScrollConsoleScreenBuffer",
237 // "SetConsoleTextAttribute",
238 // "SetConsoleFont",
239 "SetConsoleIcon",
240 "ReadConsole",
241 "WriteConsole",
242 "DuplicateHandle",
243 // "GetHandleInformation",
244 // "SetHandleInformation",
245 "CloseHandle",
246 "VerifyConsoleIoHandle",
247 "AllocConsole",
248 "FreeConsole",
249 "GetConsoleTitle",
250 "SetConsoleTitle",
251 "CreateConsoleScreenBuffer",
252 // "InvalidateBitMapRect",
253 // "VDMConsoleOperation",
254 "SetConsoleCursor",
255 // "ShowConsoleCursor",
256 // "ConsoleMenuControl",
257 // "SetConsolePalette",
258 // "SetConsoleDisplayMode",
259 // "RegisterConsoleVDM",
260 "GetConsoleHardwareState",
261 "SetConsoleHardwareState",
262 // "GetConsoleDisplayMode",
263 "AddConsoleAlias",
264 "GetConsoleAlias",
265 "GetConsoleAliasesLength",
266 "GetConsoleAliasExesLength",
267 "GetConsoleAliases",
268 "GetConsoleAliasExes",
269 "ExpungeConsoleCommandHistory",
270 "SetConsoleNumberOfCommands",
271 "GetConsoleCommandHistoryLength",
272 "GetConsoleCommandHistory",
273 // "SetConsoleCommandHistoryMode",
274 "GetConsoleCP",
275 "SetConsoleCP",
276 // "SetConsoleKeyShortcuts",
277 // "SetConsoleMenuClose",
278 // "ConsoleNotifyLastClose",
279 "GenerateConsoleCtrlEvent",
280 // "GetConsoleKeyboardLayoutName",
281 "GetConsoleWindow",
282 // "GetConsoleCharType",
283 // "SetConsoleLocalEUDC",
284 // "SetConsoleCursorMode",
285 // "GetConsoleCursorMode",
286 // "RegisterConsoleOS2",
287 // "SetConsoleOS2OemFormat",
288 // "GetConsoleNlsMode",
289 // "SetConsoleNlsMode",
290 // "RegisterConsoleIME",
291 // "UnregisterConsoleIME",
292 // "GetConsoleLangId",
293 // "AttachConsole",
294 "GetConsoleSelectionInfo",
295 "GetConsoleProcessList",
296 "GetConsoleHistory",
297 "SetConsoleHistory"
298
299 // NULL
300 };
301
302
303 /* FUNCTIONS ******************************************************************/
304
305 /*
306 VOID WINAPI ConsoleStaticServerThread(PVOID x)
307 {
308 // NTSTATUS Status = STATUS_SUCCESS;
309 PPORT_MESSAGE Request = (PPORT_MESSAGE)x;
310 PPORT_MESSAGE Reply = NULL;
311 ULONG MessageType = 0;
312
313 DPRINT("BASESRV: %s called\n", __FUNCTION__);
314
315 MessageType = Request->u2.s2.Type;
316 DPRINT("BASESRV: %s received a message (Type=%d)\n",
317 __FUNCTION__, MessageType);
318 switch (MessageType)
319 {
320 default:
321 Reply = Request;
322 /\* Status = *\/ NtReplyPort(BaseApiPort, Reply);
323 break;
324 }
325 }
326 */
327
328 CSR_SERVER_DLL_INIT(ConServerDllInitialization)
329 {
330 // NTSTATUS Status = STATUS_SUCCESS;
331
332 /*
333 DPRINT("BASSRV: %s(%ld,...) called\n", __FUNCTION__, ArgumentCount);
334
335 BaseApiPort = CsrQueryApiPort ();
336 Status = CsrAddStaticServerThread(ConsoleStaticServerThread);
337 if (NT_SUCCESS(Status))
338 {
339 //TODO initialize the BASE server
340 }
341 return STATUS_SUCCESS;
342 */
343
344 /* Initialize memory */
345 ConSrvHeap = RtlGetProcessHeap(); // Initialize our own heap.
346 // BaseSrvSharedHeap = LoadedServerDll->SharedSection; // Get the CSR shared heap.
347 // LoadedServerDll->SharedSection = BaseStaticServerData;
348
349 CsrInitConsoleSupport();
350
351 /* Setup the DLL Object */
352 LoadedServerDll->ApiBase = CONSRV_FIRST_API_NUMBER;
353 LoadedServerDll->HighestApiSupported = ConsolepMaxApiNumber;
354 LoadedServerDll->DispatchTable = ConsoleServerApiDispatchTable;
355 LoadedServerDll->ValidTable = ConsoleServerApiServerValidTable;
356 LoadedServerDll->NameTable = ConsoleServerApiNameTable;
357 LoadedServerDll->SizeOfProcessData = 0;
358 LoadedServerDll->ConnectCallback = NULL;
359 LoadedServerDll->DisconnectCallback = Win32CsrReleaseConsole;
360 LoadedServerDll->NewProcessCallback = Win32CsrDuplicateHandleTable;
361 // LoadedServerDll->HardErrorCallback = Win32CsrHardError;
362
363 /* All done */
364 return STATUS_SUCCESS;
365 }
366
367 BOOL
368 NTAPI
369 DllMain(IN HANDLE hDll,
370 IN DWORD dwReason,
371 IN LPVOID lpReserved)
372 {
373 UNREFERENCED_PARAMETER(dwReason);
374 UNREFERENCED_PARAMETER(lpReserved);
375
376 if (DLL_PROCESS_ATTACH == dwReason)
377 {
378 DllHandle = hDll;
379 }
380
381 return TRUE;
382 }
383
384 /* EOF */