2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Console Server DLL
4 * FILE: win32ss/user/consrv/console.c
5 * PURPOSE: Console I/O functions
9 /* INCLUDES ******************************************************************/
12 #include "guiconsole.h"
13 #include "tuiconsole.h"
18 /* FUNCTIONS *****************************************************************/
20 /*** Taken from win32ss/user/win32csr/desktopbg.c ***/
22 DtbgIsDesktopVisible(VOID
)
24 HWND VisibleDesktopWindow
= GetDesktopWindow(); // DESKTOPWNDPROC
26 if (VisibleDesktopWindow
!= NULL
&&
27 !IsWindowVisible(VisibleDesktopWindow
))
29 VisibleDesktopWindow
= NULL
;
32 return VisibleDesktopWindow
!= NULL
;
34 /****************************************************/
37 ConioConsoleFromProcessData(PCSR_PROCESS ProcessData
, PCSRSS_CONSOLE
*Console
)
39 PCSRSS_CONSOLE ProcessConsole
;
41 RtlEnterCriticalSection(&ProcessData
->HandleTableLock
);
42 ProcessConsole
= ProcessData
->Console
;
47 RtlLeaveCriticalSection(&ProcessData
->HandleTableLock
);
48 return STATUS_INVALID_HANDLE
;
51 InterlockedIncrement(&ProcessConsole
->ReferenceCount
);
52 RtlLeaveCriticalSection(&ProcessData
->HandleTableLock
);
53 EnterCriticalSection(&(ProcessConsole
->Lock
));
54 *Console
= ProcessConsole
;
56 return STATUS_SUCCESS
;
60 ConioConsoleCtrlEventTimeout(DWORD Event
, PCSR_PROCESS ProcessData
, DWORD Timeout
)
64 DPRINT("ConioConsoleCtrlEvent Parent ProcessId = %x\n", ProcessData
->ClientId
.UniqueProcess
);
66 if (ProcessData
->CtrlDispatcher
)
69 Thread
= CreateRemoteThread(ProcessData
->ProcessHandle
, NULL
, 0,
70 (LPTHREAD_START_ROUTINE
) ProcessData
->CtrlDispatcher
,
71 UlongToPtr(Event
), 0, NULL
);
74 DPRINT1("Failed thread creation (Error: 0x%x)\n", GetLastError());
77 WaitForSingleObject(Thread
, Timeout
);
83 ConioConsoleCtrlEvent(DWORD Event
, PCSR_PROCESS ProcessData
)
85 ConioConsoleCtrlEventTimeout(Event
, ProcessData
, 0);
88 static NTSTATUS WINAPI
89 CsrInitConsole(PCSRSS_CONSOLE Console
, int ShowCmd
)
92 SECURITY_ATTRIBUTES SecurityAttributes
;
93 PCSRSS_SCREEN_BUFFER NewBuffer
;
98 Console
->Title
.MaximumLength
= Console
->Title
.Length
= 0;
99 Console
->Title
.Buffer
= NULL
;
101 hInst
= GetModuleHandleW(L
"win32csr");
102 if (LoadStringW(hInst
,IDS_COMMAND_PROMPT
,Title
,sizeof(Title
)/sizeof(Title
[0])))
104 RtlCreateUnicodeString(&Console
->Title
, Title
);
108 RtlCreateUnicodeString(&Console
->Title
, L
"Command Prompt");
111 Console
->ReferenceCount
= 0;
112 Console
->LineBuffer
= NULL
;
113 Console
->Header
.Type
= CONIO_CONSOLE_MAGIC
;
114 Console
->Header
.Console
= Console
;
115 Console
->Mode
= ENABLE_LINE_INPUT
| ENABLE_ECHO_INPUT
| ENABLE_PROCESSED_INPUT
| ENABLE_MOUSE_INPUT
;
116 InitializeListHead(&Console
->BufferList
);
117 Console
->ActiveBuffer
= NULL
;
118 InitializeListHead(&Console
->InputEvents
);
119 InitializeListHead(&Console
->HistoryBuffers
);
120 Console
->CodePage
= GetOEMCP();
121 Console
->OutputCodePage
= GetOEMCP();
123 SecurityAttributes
.nLength
= sizeof(SECURITY_ATTRIBUTES
);
124 SecurityAttributes
.lpSecurityDescriptor
= NULL
;
125 SecurityAttributes
.bInheritHandle
= TRUE
;
127 Console
->ActiveEvent
= CreateEventW(&SecurityAttributes
, TRUE
, FALSE
, NULL
);
128 if (NULL
== Console
->ActiveEvent
)
130 RtlFreeUnicodeString(&Console
->Title
);
131 return STATUS_UNSUCCESSFUL
;
133 Console
->PrivateData
= NULL
;
134 InitializeCriticalSection(&Console
->Lock
);
136 GuiMode
= DtbgIsDesktopVisible();
138 /* allocate console screen buffer */
139 NewBuffer
= HeapAlloc(ConSrvHeap
, HEAP_ZERO_MEMORY
, sizeof(CSRSS_SCREEN_BUFFER
));
140 if (NULL
== NewBuffer
)
142 RtlFreeUnicodeString(&Console
->Title
);
143 DeleteCriticalSection(&Console
->Lock
);
144 CloseHandle(Console
->ActiveEvent
);
145 return STATUS_INSUFFICIENT_RESOURCES
;
147 /* init screen buffer with defaults */
148 NewBuffer
->CursorInfo
.bVisible
= TRUE
;
149 NewBuffer
->CursorInfo
.dwSize
= CSR_DEFAULT_CURSOR_SIZE
;
150 /* make console active, and insert into console list */
151 Console
->ActiveBuffer
= (PCSRSS_SCREEN_BUFFER
) NewBuffer
;
155 Status
= TuiInitConsole(Console
);
156 if (! NT_SUCCESS(Status
))
158 DPRINT1("Failed to open text-mode console, switching to gui-mode\n");
164 Status
= GuiInitConsole(Console
, ShowCmd
);
165 if (! NT_SUCCESS(Status
))
167 HeapFree(ConSrvHeap
,0, NewBuffer
);
168 RtlFreeUnicodeString(&Console
->Title
);
169 DeleteCriticalSection(&Console
->Lock
);
170 CloseHandle(Console
->ActiveEvent
);
171 DPRINT1("GuiInitConsole: failed\n");
176 Status
= CsrInitConsoleScreenBuffer(Console
, NewBuffer
);
177 if (! NT_SUCCESS(Status
))
179 ConioCleanupConsole(Console
);
180 RtlFreeUnicodeString(&Console
->Title
);
181 DeleteCriticalSection(&Console
->Lock
);
182 CloseHandle(Console
->ActiveEvent
);
183 HeapFree(ConSrvHeap
, 0, NewBuffer
);
184 DPRINT1("CsrInitConsoleScreenBuffer: failed\n");
188 /* copy buffer contents to screen */
189 ConioDrawConsole(Console
);
191 return STATUS_SUCCESS
;
194 CSR_API(SrvAllocConsole
)
196 PCSRSS_ALLOC_CONSOLE AllocConsoleRequest
= &((PCONSOLE_API_MESSAGE
)ApiMessage
)->Data
.AllocConsoleRequest
;
197 PCSR_PROCESS ProcessData
= CsrGetClientThread()->Process
;
198 PCSRSS_CONSOLE Console
;
199 NTSTATUS Status
= STATUS_SUCCESS
;
200 BOOLEAN NewConsole
= FALSE
;
202 DPRINT("SrvAllocConsole\n");
204 RtlEnterCriticalSection(&ProcessData
->HandleTableLock
);
205 if (ProcessData
->Console
)
207 DPRINT1("Process already has a console\n");
208 RtlLeaveCriticalSection(&ProcessData
->HandleTableLock
);
209 return STATUS_INVALID_PARAMETER
;
212 /* If we don't need a console, then get out of here */
213 if (!AllocConsoleRequest
->ConsoleNeeded
)
215 DPRINT("No console needed\n");
216 RtlLeaveCriticalSection(&ProcessData
->HandleTableLock
);
217 return STATUS_SUCCESS
;
220 /* If we already have one, then don't create a new one... */
221 if (!AllocConsoleRequest
->Console
||
222 AllocConsoleRequest
->Console
!= ProcessData
->ParentConsole
)
224 /* Allocate a console structure */
226 Console
= HeapAlloc(ConSrvHeap
, HEAP_ZERO_MEMORY
, sizeof(CSRSS_CONSOLE
));
229 DPRINT1("Not enough memory for console\n");
230 RtlLeaveCriticalSection(&ProcessData
->HandleTableLock
);
231 return STATUS_NO_MEMORY
;
233 /* initialize list head */
234 InitializeListHead(&Console
->ProcessList
);
235 /* insert process data required for GUI initialization */
236 InsertHeadList(&Console
->ProcessList
, &ProcessData
->ConsoleLink
);
237 /* Initialize the Console */
238 Status
= CsrInitConsole(Console
, AllocConsoleRequest
->ShowCmd
);
239 if (!NT_SUCCESS(Status
))
241 DPRINT1("Console init failed\n");
242 HeapFree(ConSrvHeap
, 0, Console
);
243 RtlLeaveCriticalSection(&ProcessData
->HandleTableLock
);
249 /* Reuse our current console */
250 Console
= AllocConsoleRequest
->Console
;
253 /* Set the Process Console */
254 ProcessData
->Console
= Console
;
256 /* Return it to the caller */
257 AllocConsoleRequest
->Console
= Console
;
259 /* Add a reference count because the process is tied to the console */
260 _InterlockedIncrement(&Console
->ReferenceCount
);
262 if (NewConsole
|| !ProcessData
->bInheritHandles
)
264 /* Insert the Objects */
265 Status
= Win32CsrInsertObject(ProcessData
,
266 &AllocConsoleRequest
->InputHandle
,
268 GENERIC_READ
| GENERIC_WRITE
,
270 FILE_SHARE_READ
| FILE_SHARE_WRITE
);
271 if (! NT_SUCCESS(Status
))
273 DPRINT1("Failed to insert object\n");
274 ConioDeleteConsole((Object_t
*) Console
);
275 ProcessData
->Console
= 0;
276 RtlLeaveCriticalSection(&ProcessData
->HandleTableLock
);
280 Status
= Win32CsrInsertObject(ProcessData
,
281 &AllocConsoleRequest
->OutputHandle
,
282 &Console
->ActiveBuffer
->Header
,
283 GENERIC_READ
| GENERIC_WRITE
,
285 FILE_SHARE_READ
| FILE_SHARE_WRITE
);
286 if (!NT_SUCCESS(Status
))
288 DPRINT1("Failed to insert object\n");
289 ConioDeleteConsole((Object_t
*) Console
);
290 Win32CsrReleaseObject(ProcessData
,
291 AllocConsoleRequest
->InputHandle
);
292 ProcessData
->Console
= 0;
293 RtlLeaveCriticalSection(&ProcessData
->HandleTableLock
);
298 /* Duplicate the Event */
299 if (!DuplicateHandle(GetCurrentProcess(),
300 ProcessData
->Console
->ActiveEvent
,
301 ProcessData
->ProcessHandle
,
302 &ProcessData
->ConsoleEvent
,
307 DPRINT1("DuplicateHandle() failed: %lu\n", GetLastError());
308 ConioDeleteConsole((Object_t
*) Console
);
309 if (NewConsole
|| !ProcessData
->bInheritHandles
)
311 Win32CsrReleaseObject(ProcessData
,
312 AllocConsoleRequest
->OutputHandle
);
313 Win32CsrReleaseObject(ProcessData
,
314 AllocConsoleRequest
->InputHandle
);
316 ProcessData
->Console
= 0;
317 RtlLeaveCriticalSection(&ProcessData
->HandleTableLock
);
321 /* Set the Ctrl Dispatcher */
322 ProcessData
->CtrlDispatcher
= AllocConsoleRequest
->CtrlDispatcher
;
323 DPRINT("CSRSS:CtrlDispatcher address: %x\n", ProcessData
->CtrlDispatcher
);
327 /* Insert into the list if it has not been added */
328 InsertHeadList(&ProcessData
->Console
->ProcessList
, &ProcessData
->ConsoleLink
);
331 RtlLeaveCriticalSection(&ProcessData
->HandleTableLock
);
332 return STATUS_SUCCESS
;
335 CSR_API(SrvFreeConsole
)
337 Win32CsrReleaseConsole(CsrGetClientThread()->Process
);
338 return STATUS_SUCCESS
;
342 ConioDeleteConsole(Object_t
*Object
)
344 PCSRSS_CONSOLE Console
= (PCSRSS_CONSOLE
) Object
;
347 DPRINT("ConioDeleteConsole\n");
349 /* Drain input event queue */
350 while (Console
->InputEvents
.Flink
!= &Console
->InputEvents
)
352 Event
= (ConsoleInput
*) Console
->InputEvents
.Flink
;
353 Console
->InputEvents
.Flink
= Console
->InputEvents
.Flink
->Flink
;
354 Console
->InputEvents
.Flink
->Flink
->Blink
= &Console
->InputEvents
;
355 HeapFree(ConSrvHeap
, 0, Event
);
358 ConioCleanupConsole(Console
);
359 if (Console
->LineBuffer
)
360 RtlFreeHeap(ConSrvHeap
, 0, Console
->LineBuffer
);
361 while (!IsListEmpty(&Console
->HistoryBuffers
))
362 HistoryDeleteBuffer((struct tagHISTORY_BUFFER
*)Console
->HistoryBuffers
.Flink
);
364 ConioDeleteScreenBuffer(Console
->ActiveBuffer
);
365 if (!IsListEmpty(&Console
->BufferList
))
367 DPRINT1("BUG: screen buffer list not empty\n");
370 CloseHandle(Console
->ActiveEvent
);
371 if (Console
->UnpauseEvent
) CloseHandle(Console
->UnpauseEvent
);
372 DeleteCriticalSection(&Console
->Lock
);
373 RtlFreeUnicodeString(&Console
->Title
);
374 IntDeleteAllAliases(Console
->Aliases
);
375 HeapFree(ConSrvHeap
, 0, Console
);
379 CsrInitConsoleSupport(VOID
)
381 DPRINT("CSR: CsrInitConsoleSupport()\n");
383 /* Should call LoadKeyboardLayout */
387 ConioPause(PCSRSS_CONSOLE Console
, UINT Flags
)
389 Console
->PauseFlags
|= Flags
;
390 if (!Console
->UnpauseEvent
)
391 Console
->UnpauseEvent
= CreateEvent(NULL
, TRUE
, FALSE
, NULL
);
395 ConioUnpause(PCSRSS_CONSOLE Console
, UINT Flags
)
397 Console
->PauseFlags
&= ~Flags
;
398 if (Console
->PauseFlags
== 0 && Console
->UnpauseEvent
)
400 SetEvent(Console
->UnpauseEvent
);
401 CloseHandle(Console
->UnpauseEvent
);
402 Console
->UnpauseEvent
= NULL
;
406 CSR_API(SrvSetConsoleMode
)
409 PCSRSS_SET_CONSOLE_MODE SetConsoleModeRequest
= &((PCONSOLE_API_MESSAGE
)ApiMessage
)->Data
.SetConsoleModeRequest
;
410 PCSRSS_CONSOLE Console
;
411 PCSRSS_SCREEN_BUFFER Buff
;
413 DPRINT("SrvSetConsoleMode\n");
415 Status
= Win32CsrLockObject(CsrGetClientThread()->Process
,
416 SetConsoleModeRequest
->ConsoleHandle
,
417 (Object_t
**) &Console
, GENERIC_WRITE
, 0);
418 if (! NT_SUCCESS(Status
))
423 Buff
= (PCSRSS_SCREEN_BUFFER
)Console
;
424 if (CONIO_CONSOLE_MAGIC
== Console
->Header
.Type
)
426 Console
->Mode
= SetConsoleModeRequest
->Mode
& CONSOLE_INPUT_MODE_VALID
;
428 else if (CONIO_SCREEN_BUFFER_MAGIC
== Console
->Header
.Type
)
430 Buff
->Mode
= SetConsoleModeRequest
->Mode
& CONSOLE_OUTPUT_MODE_VALID
;
434 Status
= STATUS_INVALID_HANDLE
;
437 Win32CsrUnlockObject((Object_t
*)Console
);
442 CSR_API(SrvGetConsoleMode
)
445 PCSRSS_GET_CONSOLE_MODE GetConsoleModeRequest
= &((PCONSOLE_API_MESSAGE
)ApiMessage
)->Data
.GetConsoleModeRequest
;
446 PCSRSS_CONSOLE Console
;
447 PCSRSS_SCREEN_BUFFER Buff
;
449 DPRINT("SrvGetConsoleMode\n");
451 Status
= Win32CsrLockObject(CsrGetClientThread()->Process
, GetConsoleModeRequest
->ConsoleHandle
,
452 (Object_t
**) &Console
, GENERIC_READ
, 0);
453 if (! NT_SUCCESS(Status
))
457 Status
= STATUS_SUCCESS
;
458 Buff
= (PCSRSS_SCREEN_BUFFER
) Console
;
459 if (CONIO_CONSOLE_MAGIC
== Console
->Header
.Type
)
461 GetConsoleModeRequest
->ConsoleMode
= Console
->Mode
;
463 else if (CONIO_SCREEN_BUFFER_MAGIC
== Buff
->Header
.Type
)
465 GetConsoleModeRequest
->ConsoleMode
= Buff
->Mode
;
469 Status
= STATUS_INVALID_HANDLE
;
472 Win32CsrUnlockObject((Object_t
*)Console
);
476 CSR_API(SrvSetConsoleTitle
)
479 PCSRSS_SET_TITLE SetTitleRequest
= &((PCONSOLE_API_MESSAGE
)ApiMessage
)->Data
.SetTitleRequest
;
480 PCSR_PROCESS ProcessData
= CsrGetClientThread()->Process
;
481 PCSRSS_CONSOLE Console
;
484 DPRINT("SrvSetConsoleTitle\n");
486 if (!Win32CsrValidateBuffer(ProcessData
, SetTitleRequest
->Title
,
487 SetTitleRequest
->Length
, 1))
489 return STATUS_ACCESS_VIOLATION
;
492 Status
= ConioConsoleFromProcessData(ProcessData
, &Console
);
493 if(NT_SUCCESS(Status
))
495 Buffer
= RtlAllocateHeap(RtlGetProcessHeap(), 0, SetTitleRequest
->Length
);
498 /* copy title to console */
499 RtlFreeUnicodeString(&Console
->Title
);
500 Console
->Title
.Buffer
= Buffer
;
501 Console
->Title
.Length
= Console
->Title
.MaximumLength
= SetTitleRequest
->Length
;
502 memcpy(Console
->Title
.Buffer
, SetTitleRequest
->Title
, Console
->Title
.Length
);
503 if (! ConioChangeTitle(Console
))
505 Status
= STATUS_UNSUCCESSFUL
;
509 Status
= STATUS_SUCCESS
;
514 Status
= STATUS_NO_MEMORY
;
516 ConioUnlockConsole(Console
);
522 CSR_API(SrvGetConsoleTitle
)
525 PCSRSS_GET_TITLE GetTitleRequest
= &((PCONSOLE_API_MESSAGE
)ApiMessage
)->Data
.GetTitleRequest
;
526 PCSR_PROCESS ProcessData
= CsrGetClientThread()->Process
;
527 PCSRSS_CONSOLE Console
;
530 DPRINT("SrvGetConsoleTitle\n");
532 if (!Win32CsrValidateBuffer(ProcessData
, GetTitleRequest
->Title
,
533 GetTitleRequest
->Length
, 1))
535 return STATUS_ACCESS_VIOLATION
;
538 Status
= ConioConsoleFromProcessData(ProcessData
, &Console
);
539 if (! NT_SUCCESS(Status
))
541 DPRINT1("Can't get console\n");
545 /* Copy title of the console to the user title buffer */
546 if (GetTitleRequest
->Length
>= sizeof(WCHAR
))
548 Length
= min(GetTitleRequest
->Length
- sizeof(WCHAR
), Console
->Title
.Length
);
549 memcpy(GetTitleRequest
->Title
, Console
->Title
.Buffer
, Length
);
550 GetTitleRequest
->Title
[Length
/ sizeof(WCHAR
)] = L
'\0';
553 GetTitleRequest
->Length
= Console
->Title
.Length
;
555 ConioUnlockConsole(Console
);
556 return STATUS_SUCCESS
;
559 /**********************************************************************
560 * HardwareStateProperty
563 * Set/Get the value of the HardwareState and switch
564 * between direct video buffer ouput and GDI windowed
567 * Client hands us a CSRSS_CONSOLE_HARDWARE_STATE
568 * object. We use the same object to Request.
570 * ConsoleHwState has the correct size to be compatible
571 * with NT's, but values are not.
573 static NTSTATUS FASTCALL
574 SetConsoleHardwareState(PCSRSS_CONSOLE Console
, DWORD ConsoleHwState
)
576 DPRINT1("Console Hardware State: %d\n", ConsoleHwState
);
578 if ((CONSOLE_HARDWARE_STATE_GDI_MANAGED
== ConsoleHwState
)
579 ||(CONSOLE_HARDWARE_STATE_DIRECT
== ConsoleHwState
))
581 if (Console
->HardwareState
!= ConsoleHwState
)
583 /* TODO: implement switching from full screen to windowed mode */
584 /* TODO: or back; now simply store the hardware state */
585 Console
->HardwareState
= ConsoleHwState
;
588 return STATUS_SUCCESS
;
591 return STATUS_INVALID_PARAMETER_3
; /* Client: (handle, set_get, [mode]) */
594 CSR_API(SrvGetConsoleHardwareState
)
596 PCSRSS_SETGET_CONSOLE_HW_STATE ConsoleHardwareStateRequest
= &((PCONSOLE_API_MESSAGE
)ApiMessage
)->Data
.ConsoleHardwareStateRequest
;
597 PCSRSS_CONSOLE Console
;
600 DPRINT("SrvGetConsoleHardwareState\n");
602 Status
= ConioLockConsole(CsrGetClientThread()->Process
,
603 ConsoleHardwareStateRequest
->ConsoleHandle
,
606 if (! NT_SUCCESS(Status
))
608 DPRINT1("Failed to get console handle in SetConsoleHardwareState\n");
612 switch (ConsoleHardwareStateRequest
->SetGet
)
614 case CONSOLE_HARDWARE_STATE_GET
:
615 ConsoleHardwareStateRequest
->State
= Console
->HardwareState
;
618 case CONSOLE_HARDWARE_STATE_SET
:
619 DPRINT("Setting console hardware state.\n");
620 Status
= SetConsoleHardwareState(Console
, ConsoleHardwareStateRequest
->State
);
624 Status
= STATUS_INVALID_PARAMETER_2
; /* Client: (handle, [set_get], mode) */
628 ConioUnlockConsole(Console
);
633 CSR_API(SrvSetConsoleHardwareState
)
635 PCSRSS_SETGET_CONSOLE_HW_STATE ConsoleHardwareStateRequest
= &((PCONSOLE_API_MESSAGE
)ApiMessage
)->Data
.ConsoleHardwareStateRequest
;
636 PCSRSS_CONSOLE Console
;
639 DPRINT("SrvSetConsoleHardwareState\n");
641 Status
= ConioLockConsole(CsrGetClientThread()->Process
,
642 ConsoleHardwareStateRequest
->ConsoleHandle
,
645 if (! NT_SUCCESS(Status
))
647 DPRINT1("Failed to get console handle in SetConsoleHardwareState\n");
651 switch (ConsoleHardwareStateRequest
->SetGet
)
653 case CONSOLE_HARDWARE_STATE_GET
:
654 ConsoleHardwareStateRequest
->State
= Console
->HardwareState
;
657 case CONSOLE_HARDWARE_STATE_SET
:
658 DPRINT("Setting console hardware state.\n");
659 Status
= SetConsoleHardwareState(Console
, ConsoleHardwareStateRequest
->State
);
663 Status
= STATUS_INVALID_PARAMETER_2
; /* Client: (handle, [set_get], mode) */
667 ConioUnlockConsole(Console
);
672 CSR_API(SrvGetConsoleWindow
)
674 PCSRSS_GET_CONSOLE_WINDOW GetConsoleWindowRequest
= &((PCONSOLE_API_MESSAGE
)ApiMessage
)->Data
.GetConsoleWindowRequest
;
675 PCSRSS_CONSOLE Console
;
678 DPRINT("SrvGetConsoleWindow\n");
680 Status
= ConioConsoleFromProcessData(CsrGetClientThread()->Process
, &Console
);
681 if (! NT_SUCCESS(Status
))
686 GetConsoleWindowRequest
->WindowHandle
= Console
->hWindow
;
687 ConioUnlockConsole(Console
);
689 return STATUS_SUCCESS
;
692 CSR_API(SrvSetConsoleIcon
)
694 PCSRSS_SET_CONSOLE_ICON SetConsoleIconRequest
= &((PCONSOLE_API_MESSAGE
)ApiMessage
)->Data
.SetConsoleIconRequest
;
695 PCSRSS_CONSOLE Console
;
698 DPRINT("SrvSetConsoleIcon\n");
700 Status
= ConioConsoleFromProcessData(CsrGetClientThread()->Process
, &Console
);
701 if (! NT_SUCCESS(Status
))
706 Status
= (ConioChangeIcon(Console
, SetConsoleIconRequest
->WindowIcon
)
707 ? STATUS_SUCCESS
: STATUS_UNSUCCESSFUL
);
708 ConioUnlockConsole(Console
);
713 CSR_API(SrvGetConsoleCP
)
715 PCSRSS_GET_CONSOLE_CP GetConsoleCodePage
= &((PCONSOLE_API_MESSAGE
)ApiMessage
)->Data
.GetConsoleCodePage
;
716 PCSRSS_CONSOLE Console
;
719 DPRINT("SrvGetConsoleCP\n");
721 Status
= ConioConsoleFromProcessData(CsrGetClientThread()->Process
, &Console
);
722 if (! NT_SUCCESS(Status
))
727 GetConsoleCodePage
->CodePage
= Console
->CodePage
;
728 ConioUnlockConsole(Console
);
729 return STATUS_SUCCESS
;
732 CSR_API(CsrGetConsoleOutputCodePage
) // TODO: Merge this function with the other one.
734 PCSRSS_GET_CONSOLE_OUTPUT_CP GetConsoleOutputCodePage
= &((PCONSOLE_API_MESSAGE
)ApiMessage
)->Data
.GetConsoleOutputCodePage
;
735 PCSRSS_CONSOLE Console
;
738 DPRINT("CsrGetConsoleOutputCodePage\n");
740 Status
= ConioConsoleFromProcessData(CsrGetClientThread()->Process
, &Console
);
741 if (! NT_SUCCESS(Status
))
746 GetConsoleOutputCodePage
->CodePage
= Console
->OutputCodePage
;
747 ConioUnlockConsole(Console
);
748 return STATUS_SUCCESS
;
751 CSR_API(SrvSetConsoleCP
)
753 PCSRSS_SET_CONSOLE_CP SetConsoleCodePage
= &((PCONSOLE_API_MESSAGE
)ApiMessage
)->Data
.SetConsoleCodePage
;
754 PCSRSS_CONSOLE Console
;
757 DPRINT("SrvSetConsoleCP\n");
759 Status
= ConioConsoleFromProcessData(CsrGetClientThread()->Process
, &Console
);
760 if (! NT_SUCCESS(Status
))
765 if (IsValidCodePage(SetConsoleCodePage
->CodePage
))
767 Console
->CodePage
= SetConsoleCodePage
->CodePage
;
768 ConioUnlockConsole(Console
);
769 return STATUS_SUCCESS
;
772 ConioUnlockConsole(Console
);
773 return STATUS_INVALID_PARAMETER
;
776 CSR_API(CsrSetConsoleOutputCodePage
) // TODO: Merge this function with the other one.
778 PCSRSS_SET_CONSOLE_OUTPUT_CP SetConsoleOutputCodePage
= &((PCONSOLE_API_MESSAGE
)ApiMessage
)->Data
.SetConsoleOutputCodePage
;
779 PCSRSS_CONSOLE Console
;
782 DPRINT("CsrSetConsoleOutputCodePage\n");
784 Status
= ConioConsoleFromProcessData(CsrGetClientThread()->Process
, &Console
);
785 if (! NT_SUCCESS(Status
))
790 if (IsValidCodePage(SetConsoleOutputCodePage
->CodePage
))
792 Console
->OutputCodePage
= SetConsoleOutputCodePage
->CodePage
;
793 ConioUnlockConsole(Console
);
794 return STATUS_SUCCESS
;
797 ConioUnlockConsole(Console
);
798 return STATUS_INVALID_PARAMETER
;
801 CSR_API(SrvGetConsoleProcessList
)
803 PCSRSS_GET_PROCESS_LIST GetProcessListRequest
= &((PCONSOLE_API_MESSAGE
)ApiMessage
)->Data
.GetProcessListRequest
;
805 PCSR_PROCESS ProcessData
= CsrGetClientThread()->Process
;
806 PCSRSS_CONSOLE Console
;
807 PCSR_PROCESS current
;
808 PLIST_ENTRY current_entry
;
812 DPRINT("SrvGetConsoleProcessList\n");
814 Buffer
= GetProcessListRequest
->ProcessId
;
815 if (!Win32CsrValidateBuffer(ProcessData
, Buffer
, GetProcessListRequest
->nMaxIds
, sizeof(DWORD
)))
816 return STATUS_ACCESS_VIOLATION
;
818 Status
= ConioConsoleFromProcessData(ProcessData
, &Console
);
819 if (! NT_SUCCESS(Status
))
824 for (current_entry
= Console
->ProcessList
.Flink
;
825 current_entry
!= &Console
->ProcessList
;
826 current_entry
= current_entry
->Flink
)
828 current
= CONTAINING_RECORD(current_entry
, CSR_PROCESS
, ConsoleLink
);
829 if (++nItems
<= GetProcessListRequest
->nMaxIds
)
831 *Buffer
++ = HandleToUlong(current
->ClientId
.UniqueProcess
);
835 ConioUnlockConsole(Console
);
837 GetProcessListRequest
->nProcessIdsTotal
= nItems
;
838 return STATUS_SUCCESS
;
841 CSR_API(SrvGenerateConsoleCtrlEvent
)
843 PCSRSS_GENERATE_CTRL_EVENT GenerateCtrlEvent
= &((PCONSOLE_API_MESSAGE
)ApiMessage
)->Data
.GenerateCtrlEvent
;
844 PCSRSS_CONSOLE Console
;
845 PCSR_PROCESS current
;
846 PLIST_ENTRY current_entry
;
850 Status
= ConioConsoleFromProcessData(CsrGetClientThread()->Process
, &Console
);
851 if (! NT_SUCCESS(Status
))
856 Group
= GenerateCtrlEvent
->ProcessGroup
;
857 Status
= STATUS_INVALID_PARAMETER
;
858 for (current_entry
= Console
->ProcessList
.Flink
;
859 current_entry
!= &Console
->ProcessList
;
860 current_entry
= current_entry
->Flink
)
862 current
= CONTAINING_RECORD(current_entry
, CSR_PROCESS
, ConsoleLink
);
863 if (Group
== 0 || current
->ProcessGroupId
== Group
)
865 ConioConsoleCtrlEvent(GenerateCtrlEvent
->Event
, current
);
866 Status
= STATUS_SUCCESS
;
870 ConioUnlockConsole(Console
);
875 CSR_API(SrvGetConsoleSelectionInfo
)
878 PCSRSS_GET_CONSOLE_SELECTION_INFO GetConsoleSelectionInfo
= &((PCONSOLE_API_MESSAGE
)ApiMessage
)->Data
.GetConsoleSelectionInfo
;
879 PCSRSS_CONSOLE Console
;
881 Status
= ConioConsoleFromProcessData(CsrGetClientThread()->Process
, &Console
);
882 if (NT_SUCCESS(Status
))
884 memset(&GetConsoleSelectionInfo
->Info
, 0, sizeof(CONSOLE_SELECTION_INFO
));
885 if (Console
->Selection
.dwFlags
!= 0)
886 GetConsoleSelectionInfo
->Info
= Console
->Selection
;
887 ConioUnlockConsole(Console
);