2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Console Server DLL
4 * FILE: consrv/console.c
5 * PURPOSE: Console Management Functions
6 * PROGRAMMERS: Gé van Geldorp
8 * Hermes Belusca-Maito (hermes.belusca@sfr.fr)
11 /* INCLUDES *******************************************************************/
15 /* This is for COM usage */
27 // FIXME: Add this prototype to winternl.h / rtlfuncs.h / ...
28 NTSTATUS NTAPI
RtlGetLastNtStatus(VOID
);
30 /* GLOBALS ********************************************************************/
32 /* The list of the ConSrv consoles */
33 static ULONG ConsoleListSize
;
34 static PCONSRV_CONSOLE
* ConsoleList
;
35 static RTL_RESOURCE ListLock
;
37 #define ConSrvLockConsoleListExclusive() \
38 RtlAcquireResourceExclusive(&ListLock, TRUE)
40 #define ConSrvLockConsoleListShared() \
41 RtlAcquireResourceShared(&ListLock, TRUE)
43 #define ConSrvUnlockConsoleList() \
44 RtlReleaseResource(&ListLock)
48 InsertConsole(OUT PHANDLE Handle
,
49 IN PCONSRV_CONSOLE Console
)
51 #define CONSOLE_HANDLES_INCREMENT 2 * 3
53 NTSTATUS Status
= STATUS_SUCCESS
;
55 PCONSRV_CONSOLE
* Block
;
57 ASSERT( (ConsoleList
== NULL
&& ConsoleListSize
== 0) ||
58 (ConsoleList
!= NULL
&& ConsoleListSize
!= 0) );
60 /* All went right, so add the console to the list */
61 ConSrvLockConsoleListExclusive();
62 DPRINT("Insert in the list\n");
66 for (i
= 0; i
< ConsoleListSize
; i
++)
68 if (ConsoleList
[i
] == NULL
) break;
72 if (i
>= ConsoleListSize
)
74 DPRINT("Creation of a new handles table\n");
75 /* Allocate a new handles table */
76 Block
= ConsoleAllocHeap(HEAP_ZERO_MEMORY
,
78 CONSOLE_HANDLES_INCREMENT
) * sizeof(PCONSRV_CONSOLE
));
81 Status
= STATUS_UNSUCCESSFUL
;
85 /* If we previously had a handles table, free it and use the new one */
88 /* Copy the handles from the old table to the new one */
91 ConsoleListSize
* sizeof(PCONSRV_CONSOLE
));
92 ConsoleFreeHeap(ConsoleList
);
95 ConsoleListSize
+= CONSOLE_HANDLES_INCREMENT
;
98 ConsoleList
[i
] = Console
;
99 *Handle
= ULongToHandle((i
<< 2) | 0x3);
102 /* Unlock the console list and return status */
103 ConSrvUnlockConsoleList();
110 RemoveConsoleByHandle(IN HANDLE Handle
)
112 NTSTATUS Status
= STATUS_SUCCESS
;
113 PCONSRV_CONSOLE Console
;
115 BOOLEAN ValidHandle
= ((HandleToULong(Handle
) & 0x3) == 0x3);
116 ULONG Index
= HandleToULong(Handle
) >> 2;
118 if (!ValidHandle
) return STATUS_INVALID_HANDLE
;
120 ASSERT( (ConsoleList
== NULL
&& ConsoleListSize
== 0) ||
121 (ConsoleList
!= NULL
&& ConsoleListSize
!= 0) );
123 /* Remove the console from the list */
124 ConSrvLockConsoleListExclusive();
126 if (Index
>= ConsoleListSize
||
127 (Console
= ConsoleList
[Index
]) == NULL
)
129 Status
= STATUS_INVALID_HANDLE
;
133 ConsoleList
[Index
] = NULL
;
136 /* Unlock the console list and return status */
137 ConSrvUnlockConsoleList();
143 RemoveConsoleByPointer(IN PCONSRV_CONSOLE Console
)
147 if (!Console
) return STATUS_INVALID_PARAMETER
;
149 ASSERT( (ConsoleList
== NULL
&& ConsoleListSize
== 0) ||
150 (ConsoleList
!= NULL
&& ConsoleListSize
!= 0) );
152 /* Remove the console from the list */
153 ConSrvLockConsoleListExclusive();
157 for (i
= 0; i
< ConsoleListSize
; i
++)
159 if (ConsoleList
[i
] == Console
) ConsoleList
[i
] = NULL
;
163 /* Unlock the console list and return */
164 ConSrvUnlockConsoleList();
165 return STATUS_SUCCESS
;
169 ConSrvValidateConsole(OUT PCONSRV_CONSOLE
* Console
,
170 IN HANDLE ConsoleHandle
,
171 IN CONSOLE_STATE ExpectedState
,
172 IN BOOLEAN LockConsole
)
174 BOOLEAN RetVal
= FALSE
;
175 PCONSRV_CONSOLE ValidatedConsole
;
177 BOOLEAN ValidHandle
= ((HandleToULong(ConsoleHandle
) & 0x3) == 0x3);
178 ULONG Index
= HandleToULong(ConsoleHandle
) >> 2;
180 if (!ValidHandle
) return FALSE
;
182 if (!Console
) return FALSE
;
186 * Forbid creation or deletion of consoles when
187 * checking for the existence of a console.
189 ConSrvLockConsoleListShared();
191 if (Index
>= ConsoleListSize
||
192 (ValidatedConsole
= ConsoleList
[Index
]) == NULL
)
194 /* Unlock the console list and return */
195 ConSrvUnlockConsoleList();
199 ValidatedConsole
= ConsoleList
[Index
];
201 /* Unlock the console list and return */
202 ConSrvUnlockConsoleList();
204 RetVal
= ConDrvValidateConsoleUnsafe((PCONSOLE
)ValidatedConsole
,
207 if (RetVal
) *Console
= ValidatedConsole
;
213 /* PRIVATE FUNCTIONS **********************************************************/
215 // Adapted from reactos/lib/rtl/unicode.c, RtlCreateUnicodeString line 2180
217 ConsoleCreateUnicodeString(IN OUT PUNICODE_STRING UniDest
,
220 SIZE_T Size
= (wcslen(Source
) + 1) * sizeof(WCHAR
);
221 if (Size
> MAXUSHORT
) return FALSE
;
223 UniDest
->Buffer
= ConsoleAllocHeap(HEAP_ZERO_MEMORY
, Size
);
224 if (UniDest
->Buffer
== NULL
) return FALSE
;
226 RtlCopyMemory(UniDest
->Buffer
, Source
, Size
);
227 UniDest
->MaximumLength
= (USHORT
)Size
;
228 UniDest
->Length
= (USHORT
)Size
- sizeof(WCHAR
);
233 // Adapted from reactos/lib/rtl/unicode.c, RtlFreeUnicodeString line 431
235 ConsoleFreeUnicodeString(IN PUNICODE_STRING UnicodeString
)
237 if (UnicodeString
->Buffer
)
239 ConsoleFreeHeap(UnicodeString
->Buffer
);
240 RtlZeroMemory(UnicodeString
, sizeof(UNICODE_STRING
));
245 ConioPause(PCONSRV_CONSOLE Console
, UINT Flags
)
247 Console
->PauseFlags
|= Flags
;
248 ConDrvPause((PCONSOLE
)Console
);
252 ConioUnpause(PCONSRV_CONSOLE Console
, UINT Flags
)
254 Console
->PauseFlags
&= ~Flags
;
256 // if ((Console->PauseFlags & (PAUSED_FROM_KEYBOARD | PAUSED_FROM_SCROLLBAR | PAUSED_FROM_SELECTION)) == 0)
257 if (Console
->PauseFlags
== 0)
259 ConDrvUnpause((PCONSOLE
)Console
);
261 CsrNotifyWait(&Console
->WriteWaitQueue
,
265 if (!IsListEmpty(&Console
->WriteWaitQueue
))
267 CsrDereferenceWait(&Console
->WriteWaitQueue
);
273 ConSrvGetConsole(IN PCONSOLE_PROCESS_DATA ProcessData
,
274 OUT PCONSRV_CONSOLE
* Console
,
275 IN BOOLEAN LockConsole
)
277 NTSTATUS Status
= STATUS_INVALID_HANDLE
;
278 PCONSRV_CONSOLE GrabConsole
;
280 // if (Console == NULL) return STATUS_INVALID_PARAMETER;
284 if (ConSrvValidateConsole(&GrabConsole
,
285 ProcessData
->ConsoleHandle
,
289 InterlockedIncrement(&GrabConsole
->ReferenceCount
);
290 *Console
= GrabConsole
;
291 Status
= STATUS_SUCCESS
;
298 ConSrvReleaseConsole(IN PCONSRV_CONSOLE Console
,
299 IN BOOLEAN WasConsoleLocked
)
303 if (!Console
) return;
304 // if (Console->ReferenceCount == 0) return; // This shouldn't happen
305 ASSERT(Console
->ReferenceCount
> 0);
307 /* The console must be locked */
308 // ASSERT(Console_locked);
311 * Decrement the reference count. Save the new value too,
312 * because Console->ReferenceCount might be modified after
313 * the console gets unlocked but before we check whether we
316 RefCount
= _InterlockedDecrement(&Console
->ReferenceCount
);
318 /* Unlock the console if needed */
319 if (WasConsoleLocked
) LeaveCriticalSection(&Console
->Lock
);
321 /* Delete the console if needed */
322 if (RefCount
<= 0) ConSrvDeleteConsole(Console
);
326 /* CONSOLE INITIALIZATION FUNCTIONS *******************************************/
329 ConSrvInitConsoleSupport(VOID
)
331 DPRINT("CONSRV: ConSrvInitConsoleSupport()\n");
333 /* Initialize the console list and its lock */
336 RtlInitializeResource(&ListLock
);
338 /* Should call LoadKeyboardLayout */
342 ConSrvInitTerminal(IN OUT PTERMINAL Terminal
,
343 IN OUT PCONSOLE_INFO ConsoleInfo
,
344 IN OUT PVOID ExtraConsoleInfo
,
347 ConSrvDeinitTerminal(IN OUT PTERMINAL Terminal
);
351 LoadShellLinkConsoleInfo(IN OUT PCONSOLE_INFO ConsoleInfo
,
352 IN OUT PCONSOLE_INIT_INFO ConsoleInitInfo
)
354 #define PATH_SEPARATOR L'\\'
359 LPWSTR LinkName
= NULL
;
360 LPWSTR IconPath
= NULL
;
361 WCHAR Buffer
[MAX_PATH
+ 1];
363 ConsoleInitInfo
->ConsoleStartInfo
->IconIndex
= 0;
365 if ((ConsoleInitInfo
->ConsoleStartInfo
->dwStartupFlags
& STARTF_TITLEISLINKNAME
) == 0)
367 // return FALSE; // FIXME!! (for icon loading)
372 /* 1- Find the last path separator if any */
373 LinkName
= wcsrchr(ConsoleInfo
->ConsoleTitle
, PATH_SEPARATOR
);
374 if (LinkName
== NULL
)
375 LinkName
= ConsoleInfo
->ConsoleTitle
;
377 ++LinkName
; // Skip the path separator
379 /* 2- Check for the link extension. The name ".lnk" is considered invalid. */
380 Length
= wcslen(LinkName
);
381 if ( (Length
<= 4) || (wcsicmp(LinkName
+ (Length
- 4), L
".lnk") != 0) )
384 /* 3- It may be a link. Try to retrieve some properties */
385 hRes
= CoInitialize(NULL
);
388 /* Get a pointer to the IShellLink interface */
389 IShellLinkW
* pshl
= NULL
;
390 hRes
= CoCreateInstance(&CLSID_ShellLink
,
392 CLSCTX_INPROC_SERVER
,
397 /* Get a pointer to the IPersistFile interface */
398 IPersistFile
* ppf
= NULL
;
399 hRes
= IPersistFile_QueryInterface(pshl
, &IID_IPersistFile
, (LPVOID
*)&ppf
);
402 /* Load the shortcut */
403 hRes
= IPersistFile_Load(ppf
, ConsoleInfo
->ConsoleTitle
, STGM_READ
);
407 * Finally we can get the properties !
408 * Update the old ones if needed.
413 /* Reset the name of the console with the name of the shortcut */
414 Length
= min(/*Length*/ Length
- 4, // 4 == len(".lnk")
415 sizeof(ConsoleInfo
->ConsoleTitle
) / sizeof(ConsoleInfo
->ConsoleTitle
[0]) - 1);
416 wcsncpy(ConsoleInfo
->ConsoleTitle
, LinkName
, Length
);
417 ConsoleInfo
->ConsoleTitle
[Length
] = L
'\0';
419 /* Get the window showing command */
420 hRes
= IShellLinkW_GetShowCmd(pshl
, &ShowCmd
);
421 if (SUCCEEDED(hRes
)) ConsoleInitInfo
->ConsoleStartInfo
->wShowWindow
= (WORD
)ShowCmd
;
424 // hRes = pshl->GetHotkey(&ShowCmd);
425 // if (SUCCEEDED(hRes)) ConsoleInitInfo->ConsoleStartInfo->HotKey = HotKey;
427 /* Get the icon location, if any */
428 hRes
= IShellLinkW_GetIconLocation(pshl
,
430 sizeof(Buffer
)/sizeof(Buffer
[0]) - 1, // == MAX_PATH
431 &ConsoleInitInfo
->ConsoleStartInfo
->IconIndex
);
432 if (!SUCCEEDED(hRes
))
434 ConsoleInitInfo
->ConsoleStartInfo
->IconIndex
= 0;
441 // FIXME: Since we still don't load console properties from the shortcut,
442 // return false. When this will be done, we will return true instead.
443 RetVal
= TRUE
; // FALSE;
445 IPersistFile_Release(ppf
);
447 IShellLinkW_Release(pshl
);
456 /* Get the associated icon, if any */
457 if (IconPath
== NULL
)
459 // Question: How to retrieve the full path name
460 // of the app we are going to run??
461 Length
= RtlDosSearchPath_U(ConsoleInitInfo
->CurDir
,
462 ConsoleInitInfo
->AppName
,
467 if (Length
> 0 && Length
< sizeof(Buffer
))
470 IconPath
= ConsoleInitInfo
->AppName
;
472 // ConsoleInitInfo->ConsoleStartInfo->IconIndex = 0;
474 DPRINT("IconPath = '%S' ; IconIndex = %lu\n",
475 IconPath
, ConsoleInitInfo
->ConsoleStartInfo
->IconIndex
);
476 if (IconPath
&& *IconPath
)
478 HICON hIcon
= NULL
, hIconSm
= NULL
;
479 PrivateExtractIconExW(IconPath
,
480 ConsoleInitInfo
->ConsoleStartInfo
->IconIndex
,
484 DPRINT("hIcon = 0x%p ; hIconSm = 0x%p\n", hIcon
, hIconSm
);
485 if (hIcon
!= NULL
) ConsoleInitInfo
->ConsoleStartInfo
->hIcon
= hIcon
;
486 if (hIconSm
!= NULL
) ConsoleInitInfo
->ConsoleStartInfo
->hIconSm
= hIconSm
;
490 // FIXME: See the previous FIXME above.
497 ConSrvInitConsole(OUT PHANDLE NewConsoleHandle
,
498 OUT PCONSRV_CONSOLE
* NewConsole
,
499 IN OUT PCONSOLE_INIT_INFO ConsoleInitInfo
,
500 IN ULONG ConsoleLeaderProcessId
)
503 HANDLE ConsoleHandle
;
504 PCONSRV_CONSOLE Console
;
505 CONSOLE_INFO ConsoleInfo
;
508 TERMINAL Terminal
; /* The ConSrv terminal for this console */
510 if (NewConsole
== NULL
|| ConsoleInitInfo
== NULL
)
511 return STATUS_INVALID_PARAMETER
;
516 * Load the console settings
519 /* 1. Load the default settings */
520 ConSrvGetDefaultSettings(&ConsoleInfo
, ConsoleLeaderProcessId
);
522 /* 2. Get the title of the console (initialize ConsoleInfo.ConsoleTitle) */
523 Length
= min(ConsoleInitInfo
->TitleLength
,
524 sizeof(ConsoleInfo
.ConsoleTitle
) / sizeof(ConsoleInfo
.ConsoleTitle
[0]) - 1);
525 wcsncpy(ConsoleInfo
.ConsoleTitle
, ConsoleInitInfo
->ConsoleTitle
, Length
);
526 ConsoleInfo
.ConsoleTitle
[Length
] = L
'\0'; // NULL-terminate it.
528 /* 3. Initialize the ConSrv terminal */
529 Status
= ConSrvInitTerminal(&Terminal
,
532 ConsoleLeaderProcessId
);
533 if (!NT_SUCCESS(Status
))
535 DPRINT1("CONSRV: Failed to initialize a terminal, Status = 0x%08lx\n", Status
);
538 DPRINT("CONSRV: Terminal initialized\n");
541 * Load per-application terminal settings.
543 * Check whether the process creating the console was launched via
544 * a shell-link. ConsoleInfo->ConsoleTitle may be updated with the
545 * name of the shortcut, and ConsoleStartInfo->Icon[Path|Index] too.
547 // if (ConsoleInitInfo->ConsoleStartInfo->dwStartupFlags & STARTF_TITLEISLINKNAME) // FIXME!! (for icon loading)
549 if (!LoadShellLinkConsoleInfo(&ConsoleInfo
, ConsoleInitInfo
))
551 ConsoleInitInfo
->ConsoleStartInfo
->dwStartupFlags
&= ~STARTF_TITLEISLINKNAME
;
556 * 4. Load the remaining console settings via the registry.
558 if ((ConsoleInitInfo
->ConsoleStartInfo
->dwStartupFlags
& STARTF_TITLEISLINKNAME
) == 0)
561 * Either we weren't created by an app launched via a shell-link,
562 * or we failed to load shell-link console properties.
563 * Therefore, load the console infos for the application from the registry.
565 ConSrvReadUserSettings(&ConsoleInfo
, ConsoleLeaderProcessId
);
568 * Now, update them with the properties the user might gave to us
569 * via the STARTUPINFO structure before calling CreateProcess
570 * (and which was transmitted via the ConsoleStartInfo structure).
571 * We therefore overwrite the values read in the registry.
573 if (ConsoleInitInfo
->ConsoleStartInfo
->dwStartupFlags
& STARTF_USEFILLATTRIBUTE
)
575 ConsoleInfo
.ScreenAttrib
= (USHORT
)ConsoleInitInfo
->ConsoleStartInfo
->wFillAttribute
;
577 if (ConsoleInitInfo
->ConsoleStartInfo
->dwStartupFlags
& STARTF_USECOUNTCHARS
)
579 ConsoleInfo
.ScreenBufferSize
= ConsoleInitInfo
->ConsoleStartInfo
->dwScreenBufferSize
;
581 if (ConsoleInitInfo
->ConsoleStartInfo
->dwStartupFlags
& STARTF_USESIZE
)
583 ConsoleInfo
.ConsoleSize
= ConsoleInitInfo
->ConsoleStartInfo
->dwWindowSize
;
587 /* Set-up the code page */
588 ConsoleInfo
.CodePage
= GetOEMCP();
590 /* Initialize a new console via the driver */
591 Status
= ConDrvInitConsole(&Console
, &ConsoleInfo
);
592 if (!NT_SUCCESS(Status
))
594 DPRINT1("Creating a new console failed, Status = 0x%08lx\n", Status
);
595 ConSrvDeinitTerminal(&Terminal
);
600 DPRINT("Console initialized\n");
602 /*** Register ConSrv features ***/
604 /* Initialize the console title */
606 WCHAR DefaultTitle
[128];
608 ConsoleCreateUnicodeString(&Console
->OriginalTitle
, ConsoleInfo
.ConsoleTitle
);
610 if (ConsoleInfo
.ConsoleTitle
[0] == L
'\0')
612 if (LoadStringW(ConSrvDllInstance
, IDS_CONSOLE_TITLE
, DefaultTitle
, sizeof(DefaultTitle
) / sizeof(DefaultTitle
[0])))
614 ConsoleCreateUnicodeString(&Console
->Title
, DefaultTitle
);
618 ConsoleCreateUnicodeString(&Console
->Title
, L
"ReactOS Console");
624 ConsoleCreateUnicodeString(&Console
->Title
, ConsoleInfo
.ConsoleTitle
);
629 /* Initialize process support */
630 InitializeListHead(&Console
->ProcessList
);
631 Console
->NotifiedLastCloseProcess
= NULL
;
632 Console
->NotifyLastClose
= FALSE
;
634 /* Initialize pausing support */
635 Console
->PauseFlags
= 0;
636 InitializeListHead(&Console
->ReadWaitQueue
);
637 InitializeListHead(&Console
->WriteWaitQueue
);
639 /* Initialize the alias and history buffers */
640 Console
->Aliases
= NULL
;
641 InitializeListHead(&Console
->HistoryBuffers
);
642 Console
->HistoryBufferSize
= ConsoleInfo
.HistoryBufferSize
;
643 Console
->NumberOfHistoryBuffers
= ConsoleInfo
.NumberOfHistoryBuffers
;
644 Console
->HistoryNoDup
= ConsoleInfo
.HistoryNoDup
;
646 /* Initialize the Input Line Discipline */
647 Console
->LineBuffer
= NULL
;
648 Console
->LinePos
= Console
->LineMaxSize
= Console
->LineSize
= 0;
649 Console
->LineComplete
= Console
->LineUpPressed
= FALSE
;
651 Console
->LineInsertToggle
=
652 Console
->InsertMode
= ConsoleInfo
.InsertMode
;
653 Console
->QuickEdit
= ConsoleInfo
.QuickEdit
;
656 InitializeListHead(&Console
->PopupWindows
);
659 memcpy(Console
->Colors
, ConsoleInfo
.Colors
, sizeof(ConsoleInfo
.Colors
));
661 /* Create the Initialization Events */
662 Status
= NtCreateEvent(&Console
->InitEvents
[INIT_SUCCESS
], EVENT_ALL_ACCESS
,
663 NULL
, NotificationEvent
, FALSE
);
664 if (!NT_SUCCESS(Status
))
666 DPRINT1("NtCreateEvent(InitEvents[INIT_SUCCESS]) failed: %lu\n", Status
);
667 ConDrvDeleteConsole(Console
);
668 ConSrvDeinitTerminal(&Terminal
);
671 Status
= NtCreateEvent(&Console
->InitEvents
[INIT_FAILURE
], EVENT_ALL_ACCESS
,
672 NULL
, NotificationEvent
, FALSE
);
673 if (!NT_SUCCESS(Status
))
675 DPRINT1("NtCreateEvent(InitEvents[INIT_FAILURE]) failed: %lu\n", Status
);
676 NtClose(Console
->InitEvents
[INIT_SUCCESS
]);
677 ConDrvDeleteConsole(Console
);
678 ConSrvDeinitTerminal(&Terminal
);
683 * Attach the ConSrv terminal to the console.
684 * This call makes a copy of our local Terminal variable.
686 Status
= ConDrvRegisterTerminal(Console
, &Terminal
);
687 if (!NT_SUCCESS(Status
))
689 DPRINT1("Failed to register terminal to the given console, Status = 0x%08lx\n", Status
);
690 NtClose(Console
->InitEvents
[INIT_FAILURE
]);
691 NtClose(Console
->InitEvents
[INIT_SUCCESS
]);
692 ConDrvDeleteConsole(Console
);
693 ConSrvDeinitTerminal(&Terminal
);
696 DPRINT("Terminal registered\n");
698 /* All went right, so add the console to the list */
699 Status
= InsertConsole(&ConsoleHandle
, Console
);
701 // FIXME! We do not support at all asynchronous console creation!
702 NtSetEvent(Console
->InitEvents
[INIT_SUCCESS
], NULL
);
703 // NtSetEvent(Console->InitEvents[INIT_FAILURE], NULL);
705 /* Return the newly created console to the caller and a success code too */
706 *NewConsoleHandle
= ConsoleHandle
;
707 *NewConsole
= Console
;
708 return STATUS_SUCCESS
;
712 ConSrvDeleteConsole(PCONSRV_CONSOLE Console
)
714 DPRINT("ConSrvDeleteConsole\n");
716 // FIXME: Send a terminate message to all the processes owning this console
718 /* Remove the console from the list */
719 RemoveConsoleByPointer(Console
);
721 /* Destroy the Initialization Events */
722 NtClose(Console
->InitEvents
[INIT_FAILURE
]);
723 NtClose(Console
->InitEvents
[INIT_SUCCESS
]);
725 /* Clean the Input Line Discipline */
726 if (Console
->LineBuffer
) ConsoleFreeHeap(Console
->LineBuffer
);
728 /* Clean aliases and history */
729 IntDeleteAllAliases(Console
);
730 HistoryDeleteBuffers(Console
);
732 /* Free the console title */
733 ConsoleFreeUnicodeString(&Console
->OriginalTitle
);
734 ConsoleFreeUnicodeString(&Console
->Title
);
736 /* Now, call the driver. ConDrvDeregisterTerminal is called on-demand. */
737 ConDrvDeleteConsole((PCONSOLE
)Console
);
739 /* Deinit the ConSrv terminal */
741 // ConSrvDeinitTerminal(&Terminal);
750 ConSrvConsoleCtrlEventTimeout(IN ULONG CtrlEvent
,
751 IN PCONSOLE_PROCESS_DATA ProcessData
,
754 NTSTATUS Status
= STATUS_SUCCESS
;
756 DPRINT("ConSrvConsoleCtrlEventTimeout Parent ProcessId = %x\n", ProcessData
->Process
->ClientId
.UniqueProcess
);
758 if (ProcessData
->CtrlRoutine
)
762 HANDLE Thread
= NULL
;
766 Thread
= CreateRemoteThread(ProcessData
->Process
->ProcessHandle
, NULL
, 0,
767 ProcessData
->CtrlRoutine
,
768 UlongToPtr(CtrlEvent
), 0, NULL
);
771 Status
= RtlGetLastNtStatus();
772 DPRINT1("Failed thread creation, Status = 0x%08lx\n", Status
);
776 DPRINT("ProcessData->CtrlRoutine remote thread creation succeeded, ProcessId = %x, Process = 0x%p\n",
777 ProcessData
->Process
->ClientId
.UniqueProcess
, ProcessData
->Process
);
778 WaitForSingleObject(Thread
, Timeout
);
787 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
789 Status
= _SEH2_GetExceptionCode();
790 DPRINT1("ConSrvConsoleCtrlEventTimeout - Caught an exception, Status = 0x%08lx\n", Status
);
799 ConSrvConsoleCtrlEvent(IN ULONG CtrlEvent
,
800 IN PCONSOLE_PROCESS_DATA ProcessData
)
802 return ConSrvConsoleCtrlEventTimeout(CtrlEvent
, ProcessData
, 0);
805 PCONSOLE_PROCESS_DATA NTAPI
806 ConSrvGetConsoleLeaderProcess(IN PCONSRV_CONSOLE Console
)
808 if (Console
== NULL
) return NULL
;
810 return CONTAINING_RECORD(Console
->ProcessList
.Blink
,
811 CONSOLE_PROCESS_DATA
,
816 ConSrvGetConsoleProcessList(IN PCONSRV_CONSOLE Console
,
817 IN OUT PULONG ProcessIdsList
,
818 IN ULONG MaxIdListItems
,
819 OUT PULONG ProcessIdsTotal
)
821 PCONSOLE_PROCESS_DATA current
;
822 PLIST_ENTRY current_entry
;
824 if (Console
== NULL
|| ProcessIdsList
== NULL
|| ProcessIdsTotal
== NULL
)
825 return STATUS_INVALID_PARAMETER
;
827 *ProcessIdsTotal
= 0;
829 for (current_entry
= Console
->ProcessList
.Flink
;
830 current_entry
!= &Console
->ProcessList
;
831 current_entry
= current_entry
->Flink
)
833 current
= CONTAINING_RECORD(current_entry
, CONSOLE_PROCESS_DATA
, ConsoleLink
);
834 if (++(*ProcessIdsTotal
) <= MaxIdListItems
)
836 *ProcessIdsList
++ = HandleToUlong(current
->Process
->ClientId
.UniqueProcess
);
840 return STATUS_SUCCESS
;
843 // ConSrvGenerateConsoleCtrlEvent
845 ConSrvConsoleProcessCtrlEvent(IN PCONSRV_CONSOLE Console
,
846 IN ULONG ProcessGroupId
,
849 NTSTATUS Status
= STATUS_SUCCESS
;
850 PLIST_ENTRY current_entry
;
851 PCONSOLE_PROCESS_DATA current
;
853 /* If the console is already being destroyed, just return */
854 if (!ConDrvValidateConsoleState((PCONSOLE
)Console
, CONSOLE_RUNNING
))
855 return STATUS_UNSUCCESSFUL
;
858 * Loop through the process list, from the most recent process
859 * (the active one) to the oldest one (the first created, i.e.
860 * the console leader process), and for each, send an event
861 * (new processes are inserted at the head of the console process list).
863 current_entry
= Console
->ProcessList
.Flink
;
864 while (current_entry
!= &Console
->ProcessList
)
866 current
= CONTAINING_RECORD(current_entry
, CONSOLE_PROCESS_DATA
, ConsoleLink
);
867 current_entry
= current_entry
->Flink
;
870 * Only processes belonging to the same process group are signaled.
871 * If the process group ID is zero, then all the processes are signaled.
873 if (ProcessGroupId
== 0 || current
->Process
->ProcessGroupId
== ProcessGroupId
)
875 Status
= ConSrvConsoleCtrlEvent(CtrlEvent
, current
);
883 /* PUBLIC SERVER APIS *********************************************************/
885 CSR_API(SrvAllocConsole
)
887 NTSTATUS Status
= STATUS_SUCCESS
;
888 PCONSOLE_ALLOCCONSOLE AllocConsoleRequest
= &((PCONSOLE_API_MESSAGE
)ApiMessage
)->Data
.AllocConsoleRequest
;
889 PCSR_PROCESS CsrProcess
= CsrGetClientThread()->Process
;
890 PCONSOLE_PROCESS_DATA ProcessData
= ConsoleGetPerProcessData(CsrProcess
);
891 CONSOLE_INIT_INFO ConsoleInitInfo
;
893 if (ProcessData
->ConsoleHandle
!= NULL
)
895 DPRINT1("Process already has a console\n");
896 return STATUS_ACCESS_DENIED
;
899 if ( !CsrValidateMessageBuffer(ApiMessage
,
900 (PVOID
*)&AllocConsoleRequest
->ConsoleStartInfo
,
902 sizeof(CONSOLE_START_INFO
)) ||
903 !CsrValidateMessageBuffer(ApiMessage
,
904 (PVOID
*)&AllocConsoleRequest
->ConsoleTitle
,
905 AllocConsoleRequest
->TitleLength
,
907 !CsrValidateMessageBuffer(ApiMessage
,
908 (PVOID
*)&AllocConsoleRequest
->Desktop
,
909 AllocConsoleRequest
->DesktopLength
,
911 !CsrValidateMessageBuffer(ApiMessage
,
912 (PVOID
*)&AllocConsoleRequest
->CurDir
,
913 AllocConsoleRequest
->CurDirLength
,
915 !CsrValidateMessageBuffer(ApiMessage
,
916 (PVOID
*)&AllocConsoleRequest
->AppName
,
917 AllocConsoleRequest
->AppNameLength
,
920 return STATUS_INVALID_PARAMETER
;
923 /* Initialize the console initialization info structure */
924 ConsoleInitInfo
.ConsoleStartInfo
= AllocConsoleRequest
->ConsoleStartInfo
;
925 ConsoleInitInfo
.IsWindowVisible
= TRUE
; // The console window is always visible.
926 ConsoleInitInfo
.TitleLength
= AllocConsoleRequest
->TitleLength
;
927 ConsoleInitInfo
.ConsoleTitle
= AllocConsoleRequest
->ConsoleTitle
;
928 ConsoleInitInfo
.DesktopLength
= AllocConsoleRequest
->DesktopLength
;
929 ConsoleInitInfo
.Desktop
= AllocConsoleRequest
->Desktop
;
930 ConsoleInitInfo
.AppNameLength
= AllocConsoleRequest
->AppNameLength
;
931 ConsoleInitInfo
.AppName
= AllocConsoleRequest
->AppName
;
932 ConsoleInitInfo
.CurDirLength
= AllocConsoleRequest
->CurDirLength
;
933 ConsoleInitInfo
.CurDir
= AllocConsoleRequest
->CurDir
;
935 /* Initialize a new Console owned by the Console Leader Process */
936 Status
= ConSrvAllocateConsole(ProcessData
,
937 &AllocConsoleRequest
->ConsoleStartInfo
->InputHandle
,
938 &AllocConsoleRequest
->ConsoleStartInfo
->OutputHandle
,
939 &AllocConsoleRequest
->ConsoleStartInfo
->ErrorHandle
,
941 if (!NT_SUCCESS(Status
))
943 DPRINT1("Console allocation failed\n");
947 /* Set the Property-Dialog and Control-Dispatcher handlers */
948 ProcessData
->PropRoutine
= AllocConsoleRequest
->PropRoutine
;
949 ProcessData
->CtrlRoutine
= AllocConsoleRequest
->CtrlRoutine
;
951 return STATUS_SUCCESS
;
954 CSR_API(SrvAttachConsole
)
956 NTSTATUS Status
= STATUS_SUCCESS
;
957 PCONSOLE_ATTACHCONSOLE AttachConsoleRequest
= &((PCONSOLE_API_MESSAGE
)ApiMessage
)->Data
.AttachConsoleRequest
;
958 PCSR_PROCESS SourceProcess
= NULL
; // The parent process.
959 PCSR_PROCESS TargetProcess
= CsrGetClientThread()->Process
; // Ourselves.
960 HANDLE ProcessId
= ULongToHandle(AttachConsoleRequest
->ProcessId
);
961 PCONSOLE_PROCESS_DATA SourceProcessData
, TargetProcessData
;
963 TargetProcessData
= ConsoleGetPerProcessData(TargetProcess
);
965 if (TargetProcessData
->ConsoleHandle
!= NULL
)
967 DPRINT1("Process already has a console\n");
968 return STATUS_ACCESS_DENIED
;
971 if (!CsrValidateMessageBuffer(ApiMessage
,
972 (PVOID
*)&AttachConsoleRequest
->ConsoleStartInfo
,
974 sizeof(CONSOLE_START_INFO
)))
976 return STATUS_INVALID_PARAMETER
;
979 /* Check whether we try to attach to the parent's console */
980 if (ProcessId
== ULongToHandle(ATTACH_PARENT_PROCESS
))
982 PROCESS_BASIC_INFORMATION ProcessInfo
;
983 ULONG Length
= sizeof(ProcessInfo
);
985 /* Get the real parent's ID */
987 Status
= NtQueryInformationProcess(TargetProcess
->ProcessHandle
,
988 ProcessBasicInformation
,
991 if (!NT_SUCCESS(Status
))
993 DPRINT1("SrvAttachConsole - Cannot retrieve basic process info, Status = 0x%08lx\n", Status
);
997 ProcessId
= ULongToHandle(ProcessInfo
.InheritedFromUniqueProcessId
);
1000 /* Lock the source process via its PID */
1001 Status
= CsrLockProcessByClientId(ProcessId
, &SourceProcess
);
1002 if (!NT_SUCCESS(Status
)) return Status
;
1004 SourceProcessData
= ConsoleGetPerProcessData(SourceProcess
);
1006 if (SourceProcessData
->ConsoleHandle
== NULL
)
1008 Status
= STATUS_INVALID_HANDLE
;
1013 * Inherit the console from the parent,
1014 * if any, otherwise return an error.
1016 Status
= ConSrvInheritConsole(TargetProcessData
,
1017 SourceProcessData
->ConsoleHandle
,
1019 &AttachConsoleRequest
->ConsoleStartInfo
->InputHandle
,
1020 &AttachConsoleRequest
->ConsoleStartInfo
->OutputHandle
,
1021 &AttachConsoleRequest
->ConsoleStartInfo
->ErrorHandle
,
1022 AttachConsoleRequest
->ConsoleStartInfo
);
1023 if (!NT_SUCCESS(Status
))
1025 DPRINT1("Console inheritance failed\n");
1029 /* Set the Property-Dialog and Control-Dispatcher handlers */
1030 TargetProcessData
->PropRoutine
= AttachConsoleRequest
->PropRoutine
;
1031 TargetProcessData
->CtrlRoutine
= AttachConsoleRequest
->CtrlRoutine
;
1033 Status
= STATUS_SUCCESS
;
1036 /* Unlock the "source" process and exit */
1037 CsrUnlockProcess(SourceProcess
);
1041 CSR_API(SrvFreeConsole
)
1043 return ConSrvRemoveConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process
));
1047 ConDrvGetConsoleMode(IN PCONSOLE Console
,
1048 IN PCONSOLE_IO_OBJECT Object
,
1049 OUT PULONG ConsoleMode
);
1050 CSR_API(SrvGetConsoleMode
)
1053 PCONSOLE_GETSETCONSOLEMODE ConsoleModeRequest
= &((PCONSOLE_API_MESSAGE
)ApiMessage
)->Data
.ConsoleModeRequest
;
1054 PCONSOLE_IO_OBJECT Object
;
1056 PULONG ConsoleMode
= &ConsoleModeRequest
->Mode
;
1058 Status
= ConSrvGetObject(ConsoleGetPerProcessData(CsrGetClientThread()->Process
),
1059 ConsoleModeRequest
->Handle
,
1060 &Object
, NULL
, GENERIC_READ
, TRUE
, 0);
1061 if (!NT_SUCCESS(Status
)) return Status
;
1063 /* Get the standard console modes */
1064 Status
= ConDrvGetConsoleMode(Object
->Console
, Object
,
1066 if (NT_SUCCESS(Status
))
1069 * If getting the console modes succeeds, then retrieve
1070 * the extended CONSRV-specific input modes.
1072 if (INPUT_BUFFER
== Object
->Type
)
1074 if (Object
->Console
->InsertMode
|| Object
->Console
->QuickEdit
)
1076 /* Windows also adds ENABLE_EXTENDED_FLAGS, even if it's not documented on MSDN */
1077 *ConsoleMode
|= ENABLE_EXTENDED_FLAGS
;
1079 if (Object
->Console
->InsertMode
) *ConsoleMode
|= ENABLE_INSERT_MODE
;
1080 if (Object
->Console
->QuickEdit
) *ConsoleMode
|= ENABLE_QUICK_EDIT_MODE
;
1085 ConSrvReleaseObject(Object
, TRUE
);
1090 ConDrvSetConsoleMode(IN PCONSOLE Console
,
1091 IN PCONSOLE_IO_OBJECT Object
,
1092 IN ULONG ConsoleMode
);
1093 CSR_API(SrvSetConsoleMode
)
1095 #define CONSOLE_VALID_CONTROL_MODES ( ENABLE_EXTENDED_FLAGS | \
1096 ENABLE_INSERT_MODE | ENABLE_QUICK_EDIT_MODE )
1099 PCONSOLE_GETSETCONSOLEMODE ConsoleModeRequest
= &((PCONSOLE_API_MESSAGE
)ApiMessage
)->Data
.ConsoleModeRequest
;
1100 PCONSOLE_IO_OBJECT Object
;
1102 ULONG ConsoleMode
= ConsoleModeRequest
->Mode
;
1104 Status
= ConSrvGetObject(ConsoleGetPerProcessData(CsrGetClientThread()->Process
),
1105 ConsoleModeRequest
->Handle
,
1106 &Object
, NULL
, GENERIC_WRITE
, TRUE
, 0);
1107 if (!NT_SUCCESS(Status
)) return Status
;
1109 /* Set the standard console modes (without the CONSRV-specific input modes) */
1110 ConsoleMode
&= ~CONSOLE_VALID_CONTROL_MODES
; // Remove CONSRV-specific input modes.
1111 Status
= ConDrvSetConsoleMode(Object
->Console
, Object
,
1113 if (NT_SUCCESS(Status
))
1116 * If setting the console modes succeeds, then set
1117 * the extended CONSRV-specific input modes.
1119 if (INPUT_BUFFER
== Object
->Type
)
1121 ConsoleMode
= ConsoleModeRequest
->Mode
;
1123 if (ConsoleMode
& CONSOLE_VALID_CONTROL_MODES
)
1126 * If we use control mode flags without ENABLE_EXTENDED_FLAGS,
1127 * then consider the flags invalid.
1129 if ((ConsoleMode
& ENABLE_EXTENDED_FLAGS
) == 0)
1131 Status
= STATUS_INVALID_PARAMETER
;
1135 Object
->Console
->InsertMode
= !!(ConsoleMode
& ENABLE_INSERT_MODE
);
1136 Object
->Console
->QuickEdit
= !!(ConsoleMode
& ENABLE_QUICK_EDIT_MODE
);
1142 ConSrvReleaseObject(Object
, TRUE
);
1146 CSR_API(SrvGetConsoleTitle
)
1149 PCONSOLE_GETSETCONSOLETITLE TitleRequest
= &((PCONSOLE_API_MESSAGE
)ApiMessage
)->Data
.TitleRequest
;
1150 PCONSRV_CONSOLE Console
;
1153 if (!CsrValidateMessageBuffer(ApiMessage
,
1154 (PVOID
)&TitleRequest
->Title
,
1155 TitleRequest
->Length
,
1158 return STATUS_INVALID_PARAMETER
;
1161 Status
= ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process
), &Console
, TRUE
);
1162 if (!NT_SUCCESS(Status
))
1164 DPRINT1("Can't get console\n");
1168 /* Copy title of the console to the user title buffer */
1169 if (TitleRequest
->Unicode
)
1171 if (TitleRequest
->Length
>= sizeof(WCHAR
))
1173 Length
= min(TitleRequest
->Length
- sizeof(WCHAR
), Console
->Title
.Length
);
1174 RtlCopyMemory(TitleRequest
->Title
, Console
->Title
.Buffer
, Length
);
1175 ((PWCHAR
)TitleRequest
->Title
)[Length
/ sizeof(WCHAR
)] = L
'\0';
1176 TitleRequest
->Length
= Length
;
1180 TitleRequest
->Length
= Console
->Title
.Length
;
1185 if (TitleRequest
->Length
>= sizeof(CHAR
))
1187 Length
= min(TitleRequest
->Length
- sizeof(CHAR
), Console
->Title
.Length
/ sizeof(WCHAR
));
1188 Length
= WideCharToMultiByte(Console
->InputCodePage
, 0,
1189 Console
->Title
.Buffer
, Length
,
1190 TitleRequest
->Title
, Length
,
1192 ((PCHAR
)TitleRequest
->Title
)[Length
] = '\0';
1193 TitleRequest
->Length
= Length
;
1197 TitleRequest
->Length
= Console
->Title
.Length
/ sizeof(WCHAR
);
1201 ConSrvReleaseConsole(Console
, TRUE
);
1205 CSR_API(SrvSetConsoleTitle
)
1208 PCONSOLE_GETSETCONSOLETITLE TitleRequest
= &((PCONSOLE_API_MESSAGE
)ApiMessage
)->Data
.TitleRequest
;
1209 PCONSRV_CONSOLE Console
;
1214 if (!CsrValidateMessageBuffer(ApiMessage
,
1215 (PVOID
)&TitleRequest
->Title
,
1216 TitleRequest
->Length
,
1219 return STATUS_INVALID_PARAMETER
;
1222 Status
= ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process
), &Console
, TRUE
);
1223 if (!NT_SUCCESS(Status
))
1225 DPRINT1("Can't get console\n");
1229 if (TitleRequest
->Unicode
)
1231 /* Length is in bytes */
1232 Length
= TitleRequest
->Length
;
1236 /* Use the console input CP for the conversion */
1237 Length
= MultiByteToWideChar(Console
->InputCodePage
, 0,
1238 TitleRequest
->Title
, TitleRequest
->Length
,
1240 /* The returned Length was in number of wchars, convert it in bytes */
1241 Length
*= sizeof(WCHAR
);
1244 /* Allocate a new buffer to hold the new title (NULL-terminated) */
1245 Buffer
= ConsoleAllocHeap(HEAP_ZERO_MEMORY
, Length
+ sizeof(WCHAR
));
1248 Status
= STATUS_NO_MEMORY
;
1252 /* Free the old title */
1253 ConsoleFreeUnicodeString(&Console
->Title
);
1255 /* Copy title to console */
1256 Console
->Title
.Buffer
= Buffer
;
1257 Console
->Title
.Length
= Length
;
1258 Console
->Title
.MaximumLength
= Console
->Title
.Length
+ sizeof(WCHAR
);
1260 if (TitleRequest
->Unicode
)
1262 RtlCopyMemory(Console
->Title
.Buffer
, TitleRequest
->Title
, Console
->Title
.Length
);
1266 MultiByteToWideChar(Console
->InputCodePage
, 0,
1267 TitleRequest
->Title
, TitleRequest
->Length
,
1268 Console
->Title
.Buffer
,
1269 Console
->Title
.Length
/ sizeof(WCHAR
));
1272 /* NULL-terminate */
1273 Console
->Title
.Buffer
[Console
->Title
.Length
/ sizeof(WCHAR
)] = L
'\0';
1275 TermChangeTitle(Console
);
1276 Status
= STATUS_SUCCESS
;
1279 ConSrvReleaseConsole(Console
, TRUE
);
1284 ConDrvGetConsoleCP(IN PCONSOLE Console
,
1286 IN BOOLEAN OutputCP
);
1287 CSR_API(SrvGetConsoleCP
)
1290 PCONSOLE_GETINPUTOUTPUTCP GetConsoleCPRequest
= &((PCONSOLE_API_MESSAGE
)ApiMessage
)->Data
.GetConsoleCPRequest
;
1291 PCONSRV_CONSOLE Console
;
1293 DPRINT("SrvGetConsoleCP, getting %s Code Page\n",
1294 GetConsoleCPRequest
->OutputCP
? "Output" : "Input");
1296 Status
= ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process
), &Console
, TRUE
);
1297 if (!NT_SUCCESS(Status
)) return Status
;
1299 Status
= ConDrvGetConsoleCP(Console
,
1300 &GetConsoleCPRequest
->CodePage
,
1301 GetConsoleCPRequest
->OutputCP
);
1303 ConSrvReleaseConsole(Console
, TRUE
);
1308 ConDrvSetConsoleCP(IN PCONSOLE Console
,
1310 IN BOOLEAN OutputCP
);
1311 CSR_API(SrvSetConsoleCP
)
1313 NTSTATUS Status
= STATUS_INVALID_PARAMETER
;
1314 PCONSOLE_SETINPUTOUTPUTCP SetConsoleCPRequest
= &((PCONSOLE_API_MESSAGE
)ApiMessage
)->Data
.SetConsoleCPRequest
;
1315 PCONSRV_CONSOLE Console
;
1317 DPRINT("SrvSetConsoleCP, setting %s Code Page\n",
1318 SetConsoleCPRequest
->OutputCP
? "Output" : "Input");
1320 Status
= ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process
), &Console
, TRUE
);
1321 if (!NT_SUCCESS(Status
)) return Status
;
1323 Status
= ConDrvSetConsoleCP(Console
,
1324 SetConsoleCPRequest
->CodePage
,
1325 SetConsoleCPRequest
->OutputCP
);
1327 ConSrvReleaseConsole(Console
, TRUE
);
1331 CSR_API(SrvGetConsoleProcessList
)
1334 PCONSOLE_GETPROCESSLIST GetProcessListRequest
= &((PCONSOLE_API_MESSAGE
)ApiMessage
)->Data
.GetProcessListRequest
;
1335 PCONSRV_CONSOLE Console
;
1337 if (!CsrValidateMessageBuffer(ApiMessage
,
1338 (PVOID
)&GetProcessListRequest
->ProcessIdsList
,
1339 GetProcessListRequest
->ProcessCount
,
1342 return STATUS_INVALID_PARAMETER
;
1345 Status
= ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process
), &Console
, TRUE
);
1346 if (!NT_SUCCESS(Status
)) return Status
;
1348 Status
= ConSrvGetConsoleProcessList(Console
,
1349 GetProcessListRequest
->ProcessIdsList
,
1350 GetProcessListRequest
->ProcessCount
,
1351 &GetProcessListRequest
->ProcessCount
);
1353 ConSrvReleaseConsole(Console
, TRUE
);
1357 CSR_API(SrvGenerateConsoleCtrlEvent
)
1360 PCONSOLE_GENERATECTRLEVENT GenerateCtrlEventRequest
= &((PCONSOLE_API_MESSAGE
)ApiMessage
)->Data
.GenerateCtrlEventRequest
;
1361 PCONSRV_CONSOLE Console
;
1363 Status
= ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process
), &Console
, TRUE
);
1364 if (!NT_SUCCESS(Status
)) return Status
;
1366 Status
= ConSrvConsoleProcessCtrlEvent(Console
,
1367 GenerateCtrlEventRequest
->ProcessGroupId
,
1368 GenerateCtrlEventRequest
->CtrlEvent
);
1370 ConSrvReleaseConsole(Console
, TRUE
);
1374 CSR_API(SrvConsoleNotifyLastClose
)
1377 PCONSOLE_PROCESS_DATA ProcessData
= ConsoleGetPerProcessData(CsrGetClientThread()->Process
);
1378 PCONSRV_CONSOLE Console
;
1380 Status
= ConSrvGetConsole(ProcessData
, &Console
, TRUE
);
1381 if (!NT_SUCCESS(Status
)) return Status
;
1383 /* Only one process is allowed to be registered for last close notification */
1384 if (!Console
->NotifyLastClose
)
1386 Console
->NotifyLastClose
= TRUE
;
1387 Console
->NotifiedLastCloseProcess
= ProcessData
;
1388 Status
= STATUS_SUCCESS
;
1392 Status
= STATUS_ACCESS_DENIED
;
1395 ConSrvReleaseConsole(Console
, TRUE
);
1401 CSR_API(SrvGetConsoleMouseInfo
)
1404 PCONSOLE_GETMOUSEINFO GetMouseInfoRequest
= &((PCONSOLE_API_MESSAGE
)ApiMessage
)->Data
.GetMouseInfoRequest
;
1405 PCONSRV_CONSOLE Console
;
1407 Status
= ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process
), &Console
, TRUE
);
1408 if (!NT_SUCCESS(Status
)) return Status
;
1410 /* Just retrieve the number of buttons of the mouse attached to this console */
1411 GetMouseInfoRequest
->NumButtons
= GetSystemMetrics(SM_CMOUSEBUTTONS
);
1413 ConSrvReleaseConsole(Console
, TRUE
);
1414 return STATUS_SUCCESS
;
1417 CSR_API(SrvSetConsoleKeyShortcuts
)
1419 DPRINT1("%s not yet implemented\n", __FUNCTION__
);
1420 return STATUS_NOT_IMPLEMENTED
;
1423 CSR_API(SrvGetConsoleKeyboardLayoutName
)
1426 PCONSOLE_GETKBDLAYOUTNAME GetKbdLayoutNameRequest
= &((PCONSOLE_API_MESSAGE
)ApiMessage
)->Data
.GetKbdLayoutNameRequest
;
1427 PCONSRV_CONSOLE Console
;
1429 Status
= ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process
), &Console
, TRUE
);
1430 if (!NT_SUCCESS(Status
)) return Status
;
1432 /* Retrieve the keyboard layout name of the system */
1433 if (GetKbdLayoutNameRequest
->Ansi
)
1434 GetKeyboardLayoutNameA((PCHAR
)GetKbdLayoutNameRequest
->LayoutBuffer
);
1436 GetKeyboardLayoutNameW((PWCHAR
)GetKbdLayoutNameRequest
->LayoutBuffer
);
1438 ConSrvReleaseConsole(Console
, TRUE
);
1439 return STATUS_SUCCESS
;
1442 CSR_API(SrvGetConsoleCharType
)
1444 DPRINT1("%s not yet implemented\n", __FUNCTION__
);
1445 return STATUS_NOT_IMPLEMENTED
;
1448 CSR_API(SrvSetConsoleLocalEUDC
)
1450 DPRINT1("%s not yet implemented\n", __FUNCTION__
);
1451 return STATUS_NOT_IMPLEMENTED
;
1454 CSR_API(SrvSetConsoleCursorMode
)
1456 DPRINT1("%s not yet implemented\n", __FUNCTION__
);
1457 return STATUS_NOT_IMPLEMENTED
;
1460 CSR_API(SrvGetConsoleCursorMode
)
1462 DPRINT1("%s not yet implemented\n", __FUNCTION__
);
1463 return STATUS_NOT_IMPLEMENTED
;
1466 CSR_API(SrvGetConsoleNlsMode
)
1468 DPRINT1("%s not yet implemented\n", __FUNCTION__
);
1469 return STATUS_NOT_IMPLEMENTED
;
1472 CSR_API(SrvSetConsoleNlsMode
)
1474 DPRINT1("%s not yet implemented\n", __FUNCTION__
);
1475 return STATUS_NOT_IMPLEMENTED
;
1478 CSR_API(SrvGetConsoleLangId
)
1480 DPRINT1("%s not yet implemented\n", __FUNCTION__
);
1481 return STATUS_NOT_IMPLEMENTED
;