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