ReactOS  0.4.14-dev-50-g13bb5e2
console.c File Reference
#include "consrv.h"
#include "include/conio.h"
#include "include/conio2.h"
#include "handle.h"
#include "procinit.h"
#include "alias.h"
#include "coninput.h"
#include "conoutput.h"
#include "lineinput.h"
#include "include/settings.h"
#include "include/console.h"
#include "console.h"
#include "resource.h"
#include <debug.h>
Include dependency graph for console.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define ConDrvLockConsoleListExclusive()   RtlAcquireResourceExclusive(&ListLock, TRUE)
 
#define ConDrvLockConsoleListShared()   RtlAcquireResourceShared(&ListLock, TRUE)
 
#define ConDrvUnlockConsoleList()   RtlReleaseResource(&ListLock)
 
#define CONSOLE_HANDLES_INCREMENT   2 * 3
 
#define CONSOLE_VALID_CONTROL_MODES   ( ENABLE_EXTENDED_FLAGS | ENABLE_INSERT_MODE | ENABLE_QUICK_EDIT_MODE )
 
#define CONSOLE_VALID_INPUT_MODES
 
#define CONSOLE_VALID_OUTPUT_MODES   ( ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT )
 

Functions

NTSTATUS NTAPI RtlGetLastNtStatus (VOID)
 
static BOOLEAN ConsoleCreateUnicodeString (IN OUT PUNICODE_STRING UniDest, IN PCWSTR Source)
 
static VOID ConsoleFreeUnicodeString (IN PUNICODE_STRING UnicodeString)
 
static NTSTATUS InsertConsole (OUT PHANDLE Handle, IN PCONSOLE Console)
 
static NTSTATUS RemoveConsoleByPointer (IN PCONSOLE Console)
 
VOID ResetFrontEnd (IN PCONSOLE Console)
 
static NTSTATUS ConDrvConsoleCtrlEventTimeout (IN ULONG Event, IN PCONSOLE_PROCESS_DATA ProcessData, IN ULONG Timeout)
 
static NTSTATUS ConDrvConsoleCtrlEvent (IN ULONG Event, IN PCONSOLE_PROCESS_DATA ProcessData)
 
VOID FASTCALL ConioPause (PCONSOLE Console, UINT Flags)
 
VOID FASTCALL ConioUnpause (PCONSOLE Console, UINT Flags)
 
BOOLEAN NTAPI ConDrvValidateConsoleState (IN PCONSOLE Console, IN CONSOLE_STATE ExpectedState)
 
BOOLEAN NTAPI ConDrvValidateConsoleUnsafe (IN PCONSOLE Console, IN CONSOLE_STATE ExpectedState, IN BOOLEAN LockConsole)
 
BOOLEAN NTAPI ConDrvValidateConsole (OUT PCONSOLE *Console, IN HANDLE ConsoleHandle, IN CONSOLE_STATE ExpectedState, IN BOOLEAN LockConsole)
 
NTSTATUS NTAPI ConDrvGetConsole (OUT PCONSOLE *Console, IN HANDLE ConsoleHandle, IN BOOLEAN LockConsole)
 
VOID NTAPI ConDrvReleaseConsole (IN PCONSOLE Console, IN BOOLEAN WasConsoleLocked)
 
VOID NTAPI ConDrvInitConsoleSupport (VOID)
 
NTSTATUS NTAPI ConDrvInitConsole (OUT PHANDLE NewConsoleHandle, OUT PCONSOLE *NewConsole, IN PCONSOLE_INFO ConsoleInfo, IN ULONG ConsoleLeaderProcessId)
 
NTSTATUS NTAPI ConDrvRegisterFrontEnd (IN PCONSOLE Console, IN PFRONTEND FrontEnd)
 
NTSTATUS NTAPI ConDrvDeregisterFrontEnd (IN PCONSOLE Console)
 
VOID NTAPI ConDrvDeleteConsole (IN PCONSOLE Console)
 
NTSTATUS NTAPI ConDrvGetConsoleMode (IN PCONSOLE Console, IN PCONSOLE_IO_OBJECT Object, OUT PULONG ConsoleMode)
 
NTSTATUS NTAPI ConDrvSetConsoleMode (IN PCONSOLE Console, IN PCONSOLE_IO_OBJECT Object, IN ULONG ConsoleMode)
 
NTSTATUS NTAPI ConDrvGetConsoleTitle (IN PCONSOLE Console, IN OUT PWCHAR Title, IN OUT PULONG BufLength)
 
NTSTATUS NTAPI ConDrvSetConsoleTitle (IN PCONSOLE Console, IN PWCHAR Title, IN ULONG BufLength)
 
NTSTATUS NTAPI ConDrvGetConsoleCP (IN PCONSOLE Console, OUT PUINT CodePage, IN BOOLEAN InputCP)
 
NTSTATUS NTAPI ConDrvSetConsoleCP (IN PCONSOLE Console, IN UINT CodePage, IN BOOLEAN InputCP)
 
NTSTATUS NTAPI ConDrvGetConsoleProcessList (IN PCONSOLE Console, IN OUT PULONG ProcessIdsList, IN ULONG MaxIdListItems, OUT PULONG ProcessIdsTotal)
 
NTSTATUS NTAPI ConDrvConsoleProcessCtrlEvent (IN PCONSOLE Console, IN ULONG ProcessGroupId, IN ULONG Event)
 

Variables

static ULONG ConsoleListSize
 
static PCONSOLEConsoleList
 
static RTL_RESOURCE ListLock
 

Macro Definition Documentation

◆ ConDrvLockConsoleListExclusive

#define ConDrvLockConsoleListExclusive ( )    RtlAcquireResourceExclusive(&ListLock, TRUE)

Definition at line 41 of file console.c.

◆ ConDrvLockConsoleListShared

#define ConDrvLockConsoleListShared ( )    RtlAcquireResourceShared(&ListLock, TRUE)

Definition at line 44 of file console.c.

◆ ConDrvUnlockConsoleList

#define ConDrvUnlockConsoleList ( )    RtlReleaseResource(&ListLock)

Definition at line 47 of file console.c.

◆ CONSOLE_HANDLES_INCREMENT

#define CONSOLE_HANDLES_INCREMENT   2 * 3

◆ CONSOLE_VALID_CONTROL_MODES

#define CONSOLE_VALID_CONTROL_MODES   ( ENABLE_EXTENDED_FLAGS | ENABLE_INSERT_MODE | ENABLE_QUICK_EDIT_MODE )

◆ CONSOLE_VALID_INPUT_MODES

#define CONSOLE_VALID_INPUT_MODES
Value:
ENABLE_ECHO_INPUT | ENABLE_WINDOW_INPUT | \
ENABLE_MOUSE_INPUT )
#define ENABLE_LINE_INPUT
Definition: wincon.h:76
#define ENABLE_WINDOW_INPUT
Definition: wincon.h:78
#define ENABLE_PROCESSED_INPUT
Definition: wincon.h:75

◆ CONSOLE_VALID_OUTPUT_MODES

#define CONSOLE_VALID_OUTPUT_MODES   ( ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT )

◆ NDEBUG

#define NDEBUG

Definition at line 28 of file console.c.

Function Documentation

◆ ConDrvConsoleCtrlEvent()

static NTSTATUS ConDrvConsoleCtrlEvent ( IN ULONG  Event,
IN PCONSOLE_PROCESS_DATA  ProcessData 
)
static

Definition at line 254 of file console.c.

256 {
257  return ConDrvConsoleCtrlEventTimeout(Event, ProcessData, 0);
258 }
static NTSTATUS ConDrvConsoleCtrlEventTimeout(IN ULONG Event, IN PCONSOLE_PROCESS_DATA ProcessData, IN ULONG Timeout)
Definition: console.c:206

Referenced by ConDrvConsoleProcessCtrlEvent().

◆ ConDrvConsoleCtrlEventTimeout()

static NTSTATUS ConDrvConsoleCtrlEventTimeout ( IN ULONG  Event,
IN PCONSOLE_PROCESS_DATA  ProcessData,
IN ULONG  Timeout 
)
static

Definition at line 206 of file console.c.

209 {
211 
212  DPRINT("ConDrvConsoleCtrlEventTimeout Parent ProcessId = %x\n", ProcessData->Process->ClientId.UniqueProcess);
213 
214  if (ProcessData->CtrlDispatcher)
215  {
216  _SEH2_TRY
217  {
218  HANDLE Thread = NULL;
219 
220  _SEH2_TRY
221  {
222  Thread = CreateRemoteThread(ProcessData->Process->ProcessHandle, NULL, 0,
223  ProcessData->CtrlDispatcher,
224  UlongToPtr(Event), 0, NULL);
225  if (NULL == Thread)
226  {
228  DPRINT1("Failed thread creation, Status = 0x%08lx\n", Status);
229  }
230  else
231  {
232  DPRINT("ProcessData->CtrlDispatcher remote thread creation succeeded, ProcessId = %x, Process = 0x%p\n", ProcessData->Process->ClientId.UniqueProcess, ProcessData->Process);
234  }
235  }
237  {
239  }
240  _SEH2_END;
241  }
243  {
245  DPRINT1("ConDrvConsoleCtrlEventTimeout - Caught an exception, Status = 0x%08lx\n", Status);
246  }
247  _SEH2_END;
248  }
249 
250  return Status;
251 }
#define CloseHandle
Definition: compat.h:398
LONG NTSTATUS
Definition: precomp.h:26
_SEH2_TRY
Definition: create.c:4250
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define UlongToPtr(u)
Definition: config.h:106
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
Status
Definition: gdiplustypes.h:24
_SEH2_END
Definition: create.c:4424
static ULONG Timeout
Definition: ping.c:61
NTSTATUS NTAPI RtlGetLastNtStatus(VOID)
Definition: error.c:114
_SEH2_FINALLY
Definition: create.c:4395
#define DPRINT1
Definition: precomp.h:8
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
return STATUS_SUCCESS
Definition: btrfs.c:2966
HANDLE WINAPI CreateRemoteThread(IN HANDLE hProcess, IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:158

Referenced by ConDrvConsoleCtrlEvent().

◆ ConDrvConsoleProcessCtrlEvent()

NTSTATUS NTAPI ConDrvConsoleProcessCtrlEvent ( IN PCONSOLE  Console,
IN ULONG  ProcessGroupId,
IN ULONG  Event 
)

Definition at line 1069 of file console.c.

1072 {
1074  PLIST_ENTRY current_entry;
1076 
1077  /* If the console is already being destroyed, just return */
1079  return STATUS_UNSUCCESSFUL;
1080 
1081  /*
1082  * Loop through the process list, from the most recent process
1083  * (the active one) to the oldest one (the first created, i.e.
1084  * the console leader process), and for each, send an event
1085  * (new processes are inserted at the head of the console process list).
1086  */
1087  current_entry = Console->ProcessList.Flink;
1088  while (current_entry != &Console->ProcessList)
1089  {
1090  current = CONTAINING_RECORD(current_entry, CONSOLE_PROCESS_DATA, ConsoleLink);
1091  current_entry = current_entry->Flink;
1092 
1093  /*
1094  * Only processes belonging to the same process group are signaled.
1095  * If the process group ID is zero, then all the processes are signaled.
1096  */
1097  if (ProcessGroupId == 0 || current->Process->ProcessGroupId == ProcessGroupId)
1098  {
1100  }
1101  }
1102 
1103  return Status;
1104 }
BOOLEAN NTAPI ConDrvValidateConsoleState(IN PCONSOLE Console, IN CONSOLE_STATE ExpectedState)
Definition: console.c:108
LONG NTSTATUS
Definition: precomp.h:26
static NTSTATUS ConDrvConsoleCtrlEvent(IN ULONG Event, IN PCONSOLE_PROCESS_DATA ProcessData)
Definition: console.c:254
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
Definition: typedefs.h:117
Status
Definition: gdiplustypes.h:24
CConsole Console
return STATUS_SUCCESS
Definition: btrfs.c:2966
struct task_struct * current
Definition: linux.c:32

Referenced by ConDrvProcessKey(), CSR_API(), and GuiConsoleHandleClose().

◆ ConDrvDeleteConsole()

VOID NTAPI ConDrvDeleteConsole ( IN PCONSOLE  Console)

Definition at line 728 of file console.c.

729 {
730  DPRINT("ConDrvDeleteConsole(0x%p)\n", Console);
731 
732  /*
733  * Forbid validation of any console by other threads
734  * during the deletion of this console.
735  */
737 
738  /*
739  * If the console is already being destroyed, i.e. not running
740  * or finishing to be initialized, just return.
741  */
744  {
745  /* Unlock the console list and return */
747  return;
748  }
749 
750  /*
751  * We are about to be destroyed. Signal it to other people
752  * so that they can terminate what they are doing, and that
753  * they cannot longer validate the console.
754  */
755  Console->State = CONSOLE_TERMINATING;
756 
757  /*
758  * Allow other threads to finish their job: basically, unlock
759  * all other calls to EnterCriticalSection(&Console->Lock); by
760  * ConDrvValidateConsole(Unsafe) functions so that they just see
761  * that we are not in CONSOLE_RUNNING state anymore, or unlock
762  * other concurrent calls to ConDrvDeleteConsole so that they
763  * can see that we are in fact already deleting the console.
764  */
767 
768  /* FIXME: Send a terminate message to all the processes owning this console */
769 
770  /* Cleanup the UI-oriented part */
771  DPRINT("Deregister console\n");
773  DPRINT("Console deregistered\n");
774 
775  /***
776  * Check that the console is in terminating state before continuing
777  * (the cleanup code must not change the state of the console...
778  * ...unless to cancel console deletion ?).
779  ***/
780 
782 
784  {
786  return;
787  }
788 
789  /* We are now in destruction */
791 
792  /* We really delete the console. Reset the count to be sure. */
793  Console->ReferenceCount = 0;
794 
795  /* Remove the console from the list */
797 
798  /* Discard all entries in the input event queue */
800 
801  if (Console->LineBuffer) ConsoleFreeHeap(Console->LineBuffer);
802 
805 
806  ConioDeleteScreenBuffer(Console->ActiveBuffer);
807  Console->ActiveBuffer = NULL;
808  if (!IsListEmpty(&Console->BufferList))
809  {
810  DPRINT1("BUG: screen buffer list not empty\n");
811  ASSERT(FALSE);
812  }
813 
814  CloseHandle(Console->InputBuffer.ActiveEvent);
815  if (Console->UnpauseEvent) CloseHandle(Console->UnpauseEvent);
816 
817  ConsoleFreeUnicodeString(&Console->OriginalTitle);
819 
820  DPRINT("ConDrvDeleteConsole - Unlocking\n");
822  DPRINT("ConDrvDeleteConsole - Destroying lock\n");
824  DPRINT("ConDrvDeleteConsole - Lock destroyed ; freeing console\n");
825 
827  DPRINT("ConDrvDeleteConsole - Console destroyed\n");
828 
829  /* Unlock the console list and return */
831 }
VOID IntDeleteAllAliases(PCONSRV_CONSOLE Console)
Definition: alias.c:428
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
NTSTATUS NTAPI ConDrvDeregisterFrontEnd(IN PCONSOLE Console)
Definition: console.c:708
VOID HistoryDeleteBuffers(PCONSRV_CONSOLE Console)
Definition: history.c:313
#define ConDrvUnlockConsoleList()
Definition: console.c:47
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)
static NTSTATUS RemoveConsoleByPointer(IN PCONSOLE Console)
Definition: console.c:172
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
VOID WINAPI ConioDeleteScreenBuffer(PCONSOLE_SCREEN_BUFFER Buffer)
Definition: conoutput.c:113
static VOID PurgeInputBuffer(PCONSOLE Console)
Definition: coninput.c:173
BOOLEAN NTAPI ConDrvValidateConsoleUnsafe(IN PCONSOLE Console, IN CONSOLE_STATE ExpectedState, IN BOOLEAN LockConsole)
Definition: console.c:120
CConsole Console
#define DPRINT1
Definition: precomp.h:8
#define ConsoleFreeHeap(HeapBase)
Definition: heap.h:15
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
#define ConDrvLockConsoleListExclusive()
Definition: console.c:41
static VOID ConsoleFreeUnicodeString(IN PUNICODE_STRING UnicodeString)
Definition: console.c:70

◆ ConDrvDeregisterFrontEnd()

NTSTATUS NTAPI ConDrvDeregisterFrontEnd ( IN PCONSOLE  Console)

Definition at line 708 of file console.c.

709 {
710  if (Console == NULL) return STATUS_INVALID_PARAMETER;
711 
712  /* FIXME: Lock the console before ?? */
713 
714  /* Deinitialize the frontend BEFORE detaching it from the console */
715  Console->TermIFace.Vtbl->DeinitFrontEnd(&Console->TermIFace/*, Console*/);
716 
717  /*
718  * Detach the frontend from the console:
719  * reinitialize the frontend interface.
720  */
722 
723  DPRINT("Terminal FrontEnd unregistered\n");
724  return STATUS_SUCCESS;
725 }
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
VOID ResetFrontEnd(IN PCONSOLE Console)
CConsole Console
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by ConDrvDeleteConsole().

◆ ConDrvGetConsole()

NTSTATUS NTAPI ConDrvGetConsole ( OUT PCONSOLE Console,
IN HANDLE  ConsoleHandle,
IN BOOLEAN  LockConsole 
)

Definition at line 378 of file console.c.

381 {
383  PCONSOLE GrabConsole;
384 
385  if (Console == NULL) return STATUS_INVALID_PARAMETER;
386  *Console = NULL;
387 
388  if (ConDrvValidateConsole(&GrabConsole,
389  ConsoleHandle,
391  LockConsole))
392  {
393  InterlockedIncrement(&GrabConsole->ReferenceCount);
394  *Console = GrabConsole;
396  }
397 
398  return Status;
399 }
LONG ReferenceCount
Definition: conio.h:325
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_INVALID_HANDLE
Definition: ntstatus.h:231
smooth NULL
Definition: ftsmooth.c:416
BOOLEAN NTAPI ConDrvValidateConsole(OUT PCONSOLE *Console, IN HANDLE ConsoleHandle, IN CONSOLE_STATE ExpectedState, IN BOOLEAN LockConsole)
Definition: console.c:336
Status
Definition: gdiplustypes.h:24
#define InterlockedIncrement
Definition: armddk.h:53
CConsole Console
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by ConSrvGetConsole().

◆ ConDrvGetConsoleCP()

NTSTATUS NTAPI ConDrvGetConsoleCP ( IN PCONSOLE  Console,
OUT PUINT  CodePage,
IN BOOLEAN  InputCP 
)

Definition at line 1011 of file console.c.

1014 {
1015  if (Console == NULL || CodePage == NULL)
1016  return STATUS_INVALID_PARAMETER;
1017 
1018  *CodePage = (InputCP ? Console->CodePage : Console->OutputCodePage);
1019 
1020  return STATUS_SUCCESS;
1021 }
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
smooth NULL
Definition: ftsmooth.c:416
CConsole Console
return STATUS_SUCCESS
Definition: btrfs.c:2966

◆ ConDrvGetConsoleMode()

NTSTATUS NTAPI ConDrvGetConsoleMode ( IN PCONSOLE  Console,
IN PCONSOLE_IO_OBJECT  Object,
OUT PULONG  ConsoleMode 
)

Definition at line 837 of file console.c.

840 {
842 
843  if (Console == NULL || Object == NULL || ConsoleMode == NULL)
845 
846  /* Validity check */
847  ASSERT(Console == Object->Console);
848 
849  /*** FIXME: */ *ConsoleMode = 0; /***/
850 
851  if (INPUT_BUFFER == Object->Type)
852  {
854 
855  *ConsoleMode = InputBuffer->Mode;
856 
857  if (Console->QuickEdit || Console->InsertMode)
858  {
859  // Windows does this, even if it's not documented on MSDN
860  *ConsoleMode |= ENABLE_EXTENDED_FLAGS;
861 
862  if (Console->QuickEdit ) *ConsoleMode |= ENABLE_QUICK_EDIT_MODE;
863  if (Console->InsertMode) *ConsoleMode |= ENABLE_INSERT_MODE;
864  }
865  }
866  else if (TEXTMODE_BUFFER == Object->Type || GRAPHICS_BUFFER == Object->Type)
867  {
869  *ConsoleMode = Buffer->Mode;
870  }
871  else
872  {
874  }
875 
876  return Status;
877 }
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
#define TEXTMODE_BUFFER
Definition: pccons.c:21
#define STATUS_INVALID_HANDLE
Definition: ntstatus.h:231
CHAR InputBuffer[80]
Definition: conmgr.c:33
struct _CONSOLE_INPUT_BUFFER * PCONSOLE_INPUT_BUFFER
struct _CONSOLE_SCREEN_BUFFER * PCONSOLE_SCREEN_BUFFER
Definition: conio.h:70
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
static IUnknown Object
Definition: main.c:512
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24
#define ENABLE_INSERT_MODE
Definition: wincon.h:80
#define ENABLE_EXTENDED_FLAGS
Definition: wincon.h:82
CConsole Console
#define ENABLE_QUICK_EDIT_MODE
Definition: wincon.h:81
return STATUS_SUCCESS
Definition: btrfs.c:2966

◆ ConDrvGetConsoleProcessList()

NTSTATUS NTAPI ConDrvGetConsoleProcessList ( IN PCONSOLE  Console,
IN OUT PULONG  ProcessIdsList,
IN ULONG  MaxIdListItems,
OUT PULONG  ProcessIdsTotal 
)

Definition at line 1040 of file console.c.

1044 {
1046  PLIST_ENTRY current_entry;
1047 
1048  if (Console == NULL || ProcessIdsList == NULL || ProcessIdsTotal == NULL)
1049  return STATUS_INVALID_PARAMETER;
1050 
1051  *ProcessIdsTotal = 0;
1052 
1053  for (current_entry = Console->ProcessList.Flink;
1054  current_entry != &Console->ProcessList;
1055  current_entry = current_entry->Flink)
1056  {
1057  current = CONTAINING_RECORD(current_entry, CONSOLE_PROCESS_DATA, ConsoleLink);
1058  if (++(*ProcessIdsTotal) <= MaxIdListItems)
1059  {
1060  *ProcessIdsList++ = HandleToUlong(current->Process->ClientId.UniqueProcess);
1061  }
1062  }
1063 
1064  return STATUS_SUCCESS;
1065 }
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define HandleToUlong(h)
Definition: basetsd.h:79
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
Definition: typedefs.h:117
CConsole Console
return STATUS_SUCCESS
Definition: btrfs.c:2966
struct task_struct * current
Definition: linux.c:32

Referenced by CSR_API().

◆ ConDrvGetConsoleTitle()

NTSTATUS NTAPI ConDrvGetConsoleTitle ( IN PCONSOLE  Console,
IN OUT PWCHAR  Title,
IN OUT PULONG  BufLength 
)

Definition at line 960 of file console.c.

963 {
964  ULONG Length;
965 
966  if (Console == NULL || Title == NULL || BufLength == NULL)
968 
969  /* Copy title of the console to the user title buffer */
970  if (*BufLength >= sizeof(WCHAR))
971  {
972  Length = min(*BufLength - sizeof(WCHAR), Console->Title.Length);
973  RtlCopyMemory(Title, Console->Title.Buffer, Length);
974  Title[Length / sizeof(WCHAR)] = L'\0';
975  }
976 
977  *BufLength = Console->Title.Length;
978 
979  return STATUS_SUCCESS;
980 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
smooth NULL
Definition: ftsmooth.c:416
static const WCHAR Title[]
Definition: oid.c:1259
__wchar_t WCHAR
Definition: xmlstorage.h:180
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
static const WCHAR L[]
Definition: oid.c:1250
#define min(a, b)
Definition: monoChain.cc:55
CConsole Console
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by CSR_API().

◆ ConDrvInitConsole()

NTSTATUS NTAPI ConDrvInitConsole ( OUT PHANDLE  NewConsoleHandle,
OUT PCONSOLE NewConsole,
IN PCONSOLE_INFO  ConsoleInfo,
IN ULONG  ConsoleLeaderProcessId 
)

Definition at line 446 of file console.c.

450 {
452  SECURITY_ATTRIBUTES SecurityAttributes;
453  // CONSOLE_INFO CapturedConsoleInfo;
455  HANDLE ConsoleHandle;
457  PCONSOLE_SCREEN_BUFFER NewBuffer;
458  // WCHAR DefaultTitle[128];
459 
460  if (NewConsoleHandle == NULL || NewConsole == NULL || ConsoleInfo == NULL)
462 
463  *NewConsoleHandle = NULL;
464  *NewConsole = NULL;
465 
466  /*
467  * Allocate a console structure
468  */
470  if (NULL == Console)
471  {
472  DPRINT1("Not enough memory for console creation.\n");
473  return STATUS_NO_MEMORY;
474  }
475 
476  /*
477  * Load the console settings
478  */
479 
480  /* 1. Load the default settings */
481  // ConSrvGetDefaultSettings(ConsoleInfo, ProcessId);
482 
483  // /* 2. Get the title of the console (initialize ConsoleInfo.ConsoleTitle) */
484  // Length = min(wcslen(ConsoleStartInfo->ConsoleTitle),
485  // sizeof(ConsoleInfo.ConsoleTitle) / sizeof(ConsoleInfo.ConsoleTitle[0]) - 1);
486  // wcsncpy(ConsoleInfo.ConsoleTitle, ConsoleStartInfo->ConsoleTitle, Length);
487  // ConsoleInfo.ConsoleTitle[Length] = L'\0';
488 
489  /*
490  * 4. Load the remaining console settings via the registry.
491  */
492 #if 0
493  if ((ConsoleStartInfo->dwStartupFlags & STARTF_TITLEISLINKNAME) == 0)
494  {
495  /*
496  * Either we weren't created by an app launched via a shell-link,
497  * or we failed to load shell-link console properties.
498  * Therefore, load the console infos for the application from the registry.
499  */
501 
502  /*
503  * Now, update them with the properties the user might gave to us
504  * via the STARTUPINFO structure before calling CreateProcess
505  * (and which was transmitted via the ConsoleStartInfo structure).
506  * We therefore overwrite the values read in the registry.
507  */
508  if (ConsoleStartInfo->dwStartupFlags & STARTF_USEFILLATTRIBUTE)
509  {
510  ConsoleInfo->ScreenAttrib = (USHORT)ConsoleStartInfo->FillAttribute;
511  }
512  if (ConsoleStartInfo->dwStartupFlags & STARTF_USECOUNTCHARS)
513  {
514  ConsoleInfo->ScreenBufferSize = ConsoleStartInfo->ScreenBufferSize;
515  }
516  if (ConsoleStartInfo->dwStartupFlags & STARTF_USESIZE)
517  {
518  // ConsoleInfo->ConsoleSize = ConsoleStartInfo->ConsoleWindowSize;
519  ConsoleInfo->ConsoleSize.X = (SHORT)ConsoleStartInfo->ConsoleWindowSize.cx;
520  ConsoleInfo->ConsoleSize.Y = (SHORT)ConsoleStartInfo->ConsoleWindowSize.cy;
521  }
522  }
523 #endif
524 
525  /*
526  * Fix the screen buffer size if needed. The rule is:
527  * ScreenBufferSize >= ConsoleSize
528  */
529  if (ConsoleInfo->ScreenBufferSize.X < ConsoleInfo->ConsoleSize.X)
530  ConsoleInfo->ScreenBufferSize.X = ConsoleInfo->ConsoleSize.X;
531  if (ConsoleInfo->ScreenBufferSize.Y < ConsoleInfo->ConsoleSize.Y)
532  ConsoleInfo->ScreenBufferSize.Y = ConsoleInfo->ConsoleSize.Y;
533 
534  /*
535  * Initialize the console
536  */
537  Console->State = CONSOLE_INITIALIZING;
538  Console->ReferenceCount = 0;
540  InitializeListHead(&Console->ProcessList);
541 
542  /* Initialize the frontend interface */
544 
545  memcpy(Console->Colors, ConsoleInfo->Colors, sizeof(ConsoleInfo->Colors));
546  Console->ConsoleSize = ConsoleInfo->ConsoleSize;
547  Console->FixedSize = FALSE; // Value by default; is reseted by the front-ends if needed.
548 
549  /*
550  * Initialize the input buffer
551  */
552  ConSrvInitObject(&Console->InputBuffer.Header, INPUT_BUFFER, Console);
553 
554  SecurityAttributes.nLength = sizeof(SECURITY_ATTRIBUTES);
555  SecurityAttributes.lpSecurityDescriptor = NULL;
556  SecurityAttributes.bInheritHandle = TRUE;
557  Console->InputBuffer.ActiveEvent = CreateEventW(&SecurityAttributes, TRUE, FALSE, NULL);
558  if (NULL == Console->InputBuffer.ActiveEvent)
559  {
562  return STATUS_UNSUCCESSFUL;
563  }
564 
565  Console->InputBuffer.InputBufferSize = 0; // FIXME!
566  InitializeListHead(&Console->InputBuffer.InputEvents);
567  InitializeListHead(&Console->InputBuffer.ReadWaitQueue);
568  Console->InputBuffer.Mode = ENABLE_PROCESSED_INPUT | ENABLE_LINE_INPUT |
570 
571  Console->QuickEdit = ConsoleInfo->QuickEdit;
572  Console->InsertMode = ConsoleInfo->InsertMode;
573  Console->LineBuffer = NULL;
574  Console->LineMaxSize = Console->LineSize = Console->LinePos = 0;
575  Console->LineComplete = Console->LineUpPressed = Console->LineInsertToggle = FALSE;
576  // LineWakeupMask
577 
578  // FIXME: This is terminal-specific !! VV
579  RtlZeroMemory(&Console->Selection, sizeof(CONSOLE_SELECTION_INFO));
580  Console->Selection.dwFlags = CONSOLE_NO_SELECTION;
581  // dwSelectionCursor
582 
583  /* Set-up the code page */
584  Console->CodePage = Console->OutputCodePage = ConsoleInfo->CodePage;
585 
586  /* Initialize a new text-mode screen buffer with default settings */
587  ScreenBufferInfo.ScreenBufferSize = ConsoleInfo->ScreenBufferSize;
588  ScreenBufferInfo.ScreenAttrib = ConsoleInfo->ScreenAttrib;
589  ScreenBufferInfo.PopupAttrib = ConsoleInfo->PopupAttrib;
590  ScreenBufferInfo.IsCursorVisible = TRUE;
591  ScreenBufferInfo.CursorSize = ConsoleInfo->CursorSize;
592 
593  InitializeListHead(&Console->BufferList);
594  Status = ConDrvCreateScreenBuffer(&NewBuffer,
595  Console,
598  if (!NT_SUCCESS(Status))
599  {
600  DPRINT1("ConDrvCreateScreenBuffer: failed, Status = 0x%08lx\n", Status);
601  CloseHandle(Console->InputBuffer.ActiveEvent);
604  return Status;
605  }
606  /* Make the new screen buffer active */
607  Console->ActiveBuffer = NewBuffer;
608  InitializeListHead(&Console->WriteWaitQueue);
609  Console->PauseFlags = 0;
610  Console->UnpauseEvent = NULL;
611 
612  /*
613  * Initialize the alias and history buffers
614  */
615  Console->Aliases = NULL;
616  InitializeListHead(&Console->HistoryBuffers);
617  Console->HistoryBufferSize = ConsoleInfo->HistoryBufferSize;
618  Console->NumberOfHistoryBuffers = ConsoleInfo->NumberOfHistoryBuffers;
619  Console->HistoryNoDup = ConsoleInfo->HistoryNoDup;
620 
621  /* Initialize the console title */
622  ConsoleCreateUnicodeString(&Console->OriginalTitle, ConsoleInfo->ConsoleTitle);
623  // if (ConsoleInfo.ConsoleTitle[0] == L'\0')
624  // {
625  // if (LoadStringW(ConSrvDllInstance, IDS_CONSOLE_TITLE, DefaultTitle, sizeof(DefaultTitle) / sizeof(DefaultTitle[0])))
626  // {
627  // ConsoleCreateUnicodeString(&Console->Title, DefaultTitle);
628  // }
629  // else
630  // {
631  // ConsoleCreateUnicodeString(&Console->Title, L"ReactOS Console");
632  // }
633  // }
634  // else
635  // {
636  ConsoleCreateUnicodeString(&Console->Title, ConsoleInfo->ConsoleTitle);
637  // }
638 
639  /* Lock the console until its initialization is finished */
640  // EnterCriticalSection(&Console->Lock);
641 
642  DPRINT("Console initialized\n");
643 
644  /* All went right, so add the console to the list */
645  Status = InsertConsole(&ConsoleHandle, Console);
646  if (!NT_SUCCESS(Status))
647  {
648  /* Fail */
650  return Status;
651  }
652 
653  /* The initialization is finished */
654  DPRINT("Change state\n");
655  Console->State = CONSOLE_RUNNING;
656 
657  /* Unlock the console */
658  // LeaveCriticalSection(&Console->Lock);
659 
660  /* Return the newly created console to the caller and a success code too */
661  *NewConsoleHandle = ConsoleHandle;
662  *NewConsole = Console;
663  return STATUS_SUCCESS;
664 }
IN PLARGE_INTEGER IN PLARGE_INTEGER PEPROCESS ProcessId
Definition: fatprocs.h:2697
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
CONSOLE_SCREEN_BUFFER_INFO ScreenBufferInfo
Definition: notevil.c:38
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
#define ConsoleAllocHeap(Flags, Size)
Definition: heap.h:14
#define STARTF_USEFILLATTRIBUTE
Definition: winbase.h:476
#define CONSOLE_NO_SELECTION
Definition: wincon.h:96
NTSTATUS ConDrvCreateScreenBuffer(OUT PCONSOLE_SCREEN_BUFFER *Buffer, IN PCONSOLE Console, IN HANDLE ProcessHandle OPTIONAL, IN ULONG BufferType, IN PVOID ScreenBufferInfo)
Definition: conoutput.c:79
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventW(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL, IN BOOL bManualReset, IN BOOL bInitialState, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:651
#define ENABLE_ECHO_INPUT
Definition: wincon.h:77
VOID NTAPI ConDrvDeleteConsole(IN PCONSOLE Console)
Definition: console.c:327
BOOL ConSrvReadUserSettings(IN OUT PCONSOLE_INFO ConsoleInfo, IN DWORD ProcessId)
Definition: settings.c:194
short SHORT
Definition: pedump.c:59
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:751
smooth NULL
Definition: ftsmooth.c:416
static BOOLEAN ConsoleCreateUnicodeString(IN OUT PUNICODE_STRING UniDest, IN PCWSTR Source)
Definition: console.c:52
void DPRINT(...)
Definition: polytest.cpp:61
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ENABLE_LINE_INPUT
Definition: wincon.h:76
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define ENABLE_MOUSE_INPUT
Definition: wincon.h:79
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
VOID ConSrvInitObject(IN OUT PCONSOLE_IO_OBJECT Object, IN CONSOLE_IO_OBJECT_TYPE Type, IN PCONSOLE Console)
Definition: handle.c:294
Status
Definition: gdiplustypes.h:24
#define ENABLE_PROCESSED_INPUT
Definition: wincon.h:75
#define STARTF_USECOUNTCHARS
Definition: winbase.h:475
LPVOID lpSecurityDescriptor
Definition: compat.h:181
#define CONSOLE_TEXTMODE_BUFFER
Definition: wincon.h:59
unsigned short USHORT
Definition: pedump.c:61
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
static CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo
Definition: video.c:47
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
VOID ResetFrontEnd(IN PCONSOLE Console)
#define STARTF_USESIZE
Definition: winbase.h:473
static NTSTATUS InsertConsole(OUT PHANDLE Handle, IN PCONSOLE Console)
Definition: console.c:81
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
CConsole Console
#define DPRINT1
Definition: precomp.h:8
#define ConsoleFreeHeap(HeapBase)
Definition: heap.h:15
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
return STATUS_SUCCESS
Definition: btrfs.c:2966
struct _SECURITY_ATTRIBUTES SECURITY_ATTRIBUTES

◆ ConDrvInitConsoleSupport()

VOID NTAPI ConDrvInitConsoleSupport ( VOID  )

Definition at line 433 of file console.c.

434 {
435  DPRINT("CONSRV: ConDrvInitConsoleSupport()\n");
436 
437  /* Initialize the console list and its lock */
438  ConsoleListSize = 0;
439  ConsoleList = NULL;
441 
442  /* Should call LoadKeyboardLayout */
443 }
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
NTSYSAPI VOID NTAPI RtlInitializeResource(_In_ PRTL_RESOURCE Resource)
static PCONSOLE * ConsoleList
Definition: console.c:38
static ULONG ConsoleListSize
Definition: console.c:37
static RTL_RESOURCE ListLock
Definition: console.c:39

◆ ConDrvRegisterFrontEnd()

NTSTATUS NTAPI ConDrvRegisterFrontEnd ( IN PCONSOLE  Console,
IN PFRONTEND  FrontEnd 
)

Definition at line 667 of file console.c.

669 {
671 
672  if (Console == NULL || FrontEnd == NULL)
674 
675  /* FIXME: Lock the console before ?? */
676 
677  /*
678  * Attach the frontend to the console. Use now the TermIFace of the console,
679  * and not the user-defined temporary FrontEnd pointer.
680  */
681  Console->TermIFace = *FrontEnd;
682  Console->TermIFace.Console = Console;
683 
684  /* Initialize the frontend AFTER having attached it to the console */
685  DPRINT("Finish initialization of frontend\n");
686  Status = Console->TermIFace.Vtbl->InitFrontEnd(&Console->TermIFace, Console);
687  if (!NT_SUCCESS(Status))
688  {
689  DPRINT1("FrontEnd initialization failed, Status = 0x%08lx\n", Status);
690 
691  /* We failed, detach the frontend from the console */
692  FrontEnd->Console = NULL; // For the caller
694 
695  return Status;
696  }
697 
698  /* Copy buffer contents to screen */
699  // FrontEnd.Draw();
700  // ConioDrawConsole(Console);
701  DPRINT("Console drawn\n");
702 
703  DPRINT("Terminal FrontEnd initialization done\n");
704  return STATUS_SUCCESS;
705 }
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
VOID ResetFrontEnd(IN PCONSOLE Console)
CConsole Console
#define DPRINT1
Definition: precomp.h:8
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by ConSrvInitConsole().

◆ ConDrvReleaseConsole()

VOID NTAPI ConDrvReleaseConsole ( IN PCONSOLE  Console,
IN BOOLEAN  WasConsoleLocked 
)

Definition at line 402 of file console.c.

404 {
405  LONG RefCount = 0;
406 
407  if (!Console) return;
408  // if (Console->ReferenceCount == 0) return; // This shouldn't happen
409  ASSERT(Console->ReferenceCount > 0);
410 
411  /* The console must be locked */
412  // ASSERT(Console_locked);
413 
414  /*
415  * Decrement the reference count. Save the new value too,
416  * because Console->ReferenceCount might be modified after
417  * the console gets unlocked but before we check whether we
418  * can destroy it.
419  */
420  RefCount = _InterlockedDecrement(&Console->ReferenceCount);
421 
422  /* Unlock the console if needed */
423  if (WasConsoleLocked) LeaveCriticalSection(&Console->Lock);
424 
425  /* Delete the console if needed */
426  if (RefCount <= 0) ConDrvDeleteConsole(Console);
427 }
VOID NTAPI ConDrvDeleteConsole(IN PCONSOLE Console)
Definition: console.c:327
long LONG
Definition: pedump.c:60
long __cdecl _InterlockedDecrement(_Interlocked_operand_ long volatile *_Addend)
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
CConsole Console
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)

Referenced by ConSrvReleaseConsole(), and ConSrvRemoveConsole().

◆ ConDrvSetConsoleCP()

NTSTATUS NTAPI ConDrvSetConsoleCP ( IN PCONSOLE  Console,
IN UINT  CodePage,
IN BOOLEAN  InputCP 
)

Definition at line 1024 of file console.c.

1027 {
1028  if (Console == NULL || !IsValidCodePage(CodePage))
1029  return STATUS_INVALID_PARAMETER;
1030 
1031  if (InputCP)
1032  Console->CodePage = CodePage;
1033  else
1034  Console->OutputCodePage = CodePage;
1035 
1036  return STATUS_SUCCESS;
1037 }
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI IsValidCodePage(UINT CodePage)
Definition: nls.c:1468
CConsole Console
return STATUS_SUCCESS
Definition: btrfs.c:2966

◆ ConDrvSetConsoleMode()

NTSTATUS NTAPI ConDrvSetConsoleMode ( IN PCONSOLE  Console,
IN PCONSOLE_IO_OBJECT  Object,
IN ULONG  ConsoleMode 
)

Definition at line 880 of file console.c.

883 {
884 #define CONSOLE_VALID_CONTROL_MODES ( ENABLE_EXTENDED_FLAGS | ENABLE_INSERT_MODE | ENABLE_QUICK_EDIT_MODE )
885 #define CONSOLE_VALID_INPUT_MODES ( ENABLE_PROCESSED_INPUT | ENABLE_LINE_INPUT | \
886  ENABLE_ECHO_INPUT | ENABLE_WINDOW_INPUT | \
887  ENABLE_MOUSE_INPUT )
888 #define CONSOLE_VALID_OUTPUT_MODES ( ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT )
889 
891 
892  if (Console == NULL || Object == NULL)
894 
895  /* Validity check */
896  ASSERT(Console == Object->Console);
897 
898  if (INPUT_BUFFER == Object->Type)
899  {
901 
902  DPRINT("SetConsoleMode(Input, %d)\n", ConsoleMode);
903 
904  /*
905  * 1. Only the presence of valid mode flags is allowed.
906  */
908  {
910  goto Quit;
911  }
912 
913  /*
914  * 2. If we use control mode flags without ENABLE_EXTENDED_FLAGS,
915  * then consider the flags invalid.
916  *
917  if ( (ConsoleMode & CONSOLE_VALID_CONTROL_MODES) &&
918  (ConsoleMode & ENABLE_EXTENDED_FLAGS) == 0 )
919  {
920  Status = STATUS_INVALID_PARAMETER;
921  goto Quit;
922  }
923  */
924 
925  /*
926  * 3. Now we can continue.
927  */
928  if (ConsoleMode & CONSOLE_VALID_CONTROL_MODES)
929  {
930  Console->QuickEdit = !!(ConsoleMode & ENABLE_QUICK_EDIT_MODE);
931  Console->InsertMode = !!(ConsoleMode & ENABLE_INSERT_MODE);
932  }
933  InputBuffer->Mode = (ConsoleMode & CONSOLE_VALID_INPUT_MODES);
934  }
935  else if (TEXTMODE_BUFFER == Object->Type || GRAPHICS_BUFFER == Object->Type)
936  {
938 
939  DPRINT("SetConsoleMode(Output, %d)\n", ConsoleMode);
940 
941  if (ConsoleMode & ~CONSOLE_VALID_OUTPUT_MODES)
942  {
944  }
945  else
946  {
947  Buffer->Mode = (ConsoleMode & CONSOLE_VALID_OUTPUT_MODES);
948  }
949  }
950  else
951  {
953  }
954 
955 Quit:
956  return Status;
957 }
#define CONSOLE_VALID_CONTROL_MODES
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define CONSOLE_VALID_OUTPUT_MODES
LONG NTSTATUS
Definition: precomp.h:26
#define TEXTMODE_BUFFER
Definition: pccons.c:21
#define STATUS_INVALID_HANDLE
Definition: ntstatus.h:231
CHAR InputBuffer[80]
Definition: conmgr.c:33
struct _CONSOLE_INPUT_BUFFER * PCONSOLE_INPUT_BUFFER
struct _CONSOLE_SCREEN_BUFFER * PCONSOLE_SCREEN_BUFFER
Definition: conio.h:70
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
Definition: bufpool.h:45
static IUnknown Object
Definition: main.c:512
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24
#define ENABLE_INSERT_MODE
Definition: wincon.h:80
CConsole Console
#define ENABLE_QUICK_EDIT_MODE
Definition: wincon.h:81
#define CONSOLE_VALID_INPUT_MODES
return STATUS_SUCCESS
Definition: btrfs.c:2966

◆ ConDrvSetConsoleTitle()

NTSTATUS NTAPI ConDrvSetConsoleTitle ( IN PCONSOLE  Console,
IN PWCHAR  Title,
IN ULONG  BufLength 
)

Definition at line 983 of file console.c.

986 {
987  PWCHAR Buffer;
988 
989  if (Console == NULL || Title == NULL)
991 
992  /* Allocate a new buffer to hold the new title (NULL-terminated) */
993  Buffer = ConsoleAllocHeap(0, BufLength + sizeof(WCHAR));
994  if (!Buffer) return STATUS_NO_MEMORY;
995 
996  /* Free the old title */
998 
999  /* Copy title to console */
1000  Console->Title.Buffer = Buffer;
1001  Console->Title.Length = BufLength;
1002  Console->Title.MaximumLength = Console->Title.Length + sizeof(WCHAR);
1003  RtlCopyMemory(Console->Title.Buffer, Title, Console->Title.Length);
1004  Console->Title.Buffer[Console->Title.Length / sizeof(WCHAR)] = L'\0';
1005 
1006  // ConioChangeTitle(Console);
1007  return STATUS_SUCCESS;
1008 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define ConsoleAllocHeap(Flags, Size)
Definition: heap.h:14
uint16_t * PWCHAR
Definition: typedefs.h:54
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
static const WCHAR Title[]
Definition: oid.c:1259
__wchar_t WCHAR
Definition: xmlstorage.h:180
static const WCHAR L[]
Definition: oid.c:1250
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
CConsole Console
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
return STATUS_SUCCESS
Definition: btrfs.c:2966
static VOID ConsoleFreeUnicodeString(IN PUNICODE_STRING UnicodeString)
Definition: console.c:70

Referenced by CSR_API().

◆ ConDrvValidateConsole()

BOOLEAN NTAPI ConDrvValidateConsole ( OUT PCONSOLE Console,
IN HANDLE  ConsoleHandle,
IN CONSOLE_STATE  ExpectedState,
IN BOOLEAN  LockConsole 
)

Definition at line 336 of file console.c.

340 {
341  BOOLEAN RetVal = FALSE;
342 
343  ULONG Index = HandleToULong(ConsoleHandle) >> 2;
344  PCONSOLE ValidatedConsole;
345 
346  if (!Console) return FALSE;
347  *Console = NULL;
348 
349  /*
350  * Forbid creation or deletion of consoles when
351  * checking for the existence of a console.
352  */
354 
355  if (Index >= ConsoleListSize ||
356  (ValidatedConsole = ConsoleList[Index]) == NULL)
357  {
358  /* Unlock the console list */
360 
361  return FALSE;
362  }
363 
364  ValidatedConsole = ConsoleList[Index];
365 
366  /* Unlock the console list and return */
368 
369  RetVal = ConDrvValidateConsoleUnsafe(ValidatedConsole,
370  ExpectedState,
371  LockConsole);
372  if (RetVal) *Console = ValidatedConsole;
373 
374  return RetVal;
375 }
#define ConDrvUnlockConsoleList()
Definition: console.c:47
#define HandleToULong(h)
Definition: basetsd.h:95
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
static const UCHAR Index[8]
Definition: usbohci.c:18
static PCONSOLE * ConsoleList
Definition: console.c:38
static ULONG ConsoleListSize
Definition: console.c:37
BOOLEAN NTAPI ConDrvValidateConsoleUnsafe(IN PCONSOLE Console, IN CONSOLE_STATE ExpectedState, IN BOOLEAN LockConsole)
Definition: console.c:120
CConsole Console
unsigned int ULONG
Definition: retypes.h:1
#define ConDrvLockConsoleListShared()
Definition: console.c:44

Referenced by ConDrvGetConsole(), ConSrvInheritConsole(), ConSrvNewProcess(), and ConSrvRemoveConsole().

◆ ConDrvValidateConsoleState()

BOOLEAN NTAPI ConDrvValidateConsoleState ( IN PCONSOLE  Console,
IN CONSOLE_STATE  ExpectedState 
)

Definition at line 297 of file console.c.

299 {
300  // if (!Console) return FALSE;
301 
302  /* The console must be locked */
303  // ASSERT(Console_locked);
304 
305  return (Console->State == ExpectedState);
306 }
CConsole Console

◆ ConDrvValidateConsoleUnsafe()

BOOLEAN NTAPI ConDrvValidateConsoleUnsafe ( IN PCONSOLE  Console,
IN CONSOLE_STATE  ExpectedState,
IN BOOLEAN  LockConsole 
)

Definition at line 309 of file console.c.

312 {
313  if (!Console) return FALSE;
314 
315  /*
316  * Lock the console to forbid possible console's state changes
317  * (which must be done when the console is already locked).
318  * If we don't want to lock it, it's because the lock is already
319  * held. So there must be no problems.
320  */
321  if (LockConsole) EnterCriticalSection(&Console->Lock);
322 
323  // ASSERT(Console_locked);
324 
325  /* Check whether the console's state is what we expect */
326  if (!ConDrvValidateConsoleState(Console, ExpectedState))
327  {
328  if (LockConsole) LeaveCriticalSection(&Console->Lock);
329  return FALSE;
330  }
331 
332  return TRUE;
333 }
BOOLEAN NTAPI ConDrvValidateConsoleState(IN PCONSOLE Console, IN CONSOLE_STATE ExpectedState)
Definition: console.c:108
#define TRUE
Definition: types.h:120
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
CConsole Console
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)

◆ ConioPause()

VOID FASTCALL ConioPause ( PCONSOLE  Console,
UINT  Flags 
)

Definition at line 261 of file console.c.

262 {
263  Console->PauseFlags |= Flags;
264  if (!Console->UnpauseEvent)
265  Console->UnpauseEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
266 }
#define CreateEvent
Definition: winbase.h:3565
#define TRUE
Definition: types.h:120
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
smooth NULL
Definition: ftsmooth.c:416
CConsole Console

◆ ConioUnpause()

VOID FASTCALL ConioUnpause ( PCONSOLE  Console,
UINT  Flags 
)

Definition at line 269 of file console.c.

270 {
271  Console->PauseFlags &= ~Flags;
272 
273  // if ((Console->PauseFlags & (PAUSED_FROM_KEYBOARD | PAUSED_FROM_SCROLLBAR | PAUSED_FROM_SELECTION)) == 0)
274  if (Console->PauseFlags == 0 && Console->UnpauseEvent)
275  {
276  SetEvent(Console->UnpauseEvent);
277  CloseHandle(Console->UnpauseEvent);
278  Console->UnpauseEvent = NULL;
279 
280  CsrNotifyWait(&Console->WriteWaitQueue,
281  WaitAll,
282  NULL,
283  NULL);
284  if (!IsListEmpty(&Console->WriteWaitQueue))
285  {
286  CsrDereferenceWait(&Console->WriteWaitQueue);
287  }
288  }
289 }
#define CloseHandle
Definition: compat.h:398
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:733
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
BOOLEAN NTAPI CsrNotifyWait(IN PLIST_ENTRY WaitList, IN BOOLEAN NotifyAll, IN PVOID WaitArgument1, IN PVOID WaitArgument2)
Definition: wait.c:388
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
smooth NULL
Definition: ftsmooth.c:416
VOID NTAPI CsrDereferenceWait(IN PLIST_ENTRY WaitList)
Definition: wait.c:266
CConsole Console

◆ ConsoleCreateUnicodeString()

static BOOLEAN ConsoleCreateUnicodeString ( IN OUT PUNICODE_STRING  UniDest,
IN PCWSTR  Source 
)
static

Definition at line 52 of file console.c.

54 {
55  SIZE_T Size = (wcslen(Source) + 1) * sizeof(WCHAR);
56  if (Size > MAXUSHORT) return FALSE;
57 
58  UniDest->Buffer = ConsoleAllocHeap(HEAP_ZERO_MEMORY, Size);
59  if (UniDest->Buffer == NULL) return FALSE;
60 
61  RtlCopyMemory(UniDest->Buffer, Source, Size);
62  UniDest->MaximumLength = (USHORT)Size;
63  UniDest->Length = (USHORT)Size - sizeof(WCHAR);
64 
65  return TRUE;
66 }
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define ConsoleAllocHeap(Flags, Size)
Definition: heap.h:14
smooth NULL
Definition: ftsmooth.c:416
__wchar_t WCHAR
Definition: xmlstorage.h:180
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
ULONG_PTR SIZE_T
Definition: typedefs.h:78
unsigned short USHORT
Definition: pedump.c:61
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
#define MAXUSHORT
Definition: typedefs.h:81
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3167
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)

Referenced by ConDrvInitConsole().

◆ ConsoleFreeUnicodeString()

static VOID ConsoleFreeUnicodeString ( IN PUNICODE_STRING  UnicodeString)
static

Definition at line 70 of file console.c.

71 {
72  if (UnicodeString->Buffer)
73  {
76  }
77 }
#define ConsoleFreeHeap(HeapBase)
Definition: heap.h:15
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261

Referenced by ConDrvDeleteConsole(), and ConDrvSetConsoleTitle().

◆ InsertConsole()

static NTSTATUS InsertConsole ( OUT PHANDLE  Handle,
IN PCONSOLE  Console 
)
static

Definition at line 81 of file console.c.

83 {
84 #define CONSOLE_HANDLES_INCREMENT 2 * 3
85 
87  ULONG i = 0;
88  PCONSOLE* Block;
89 
90  ASSERT( (ConsoleList == NULL && ConsoleListSize == 0) ||
91  (ConsoleList != NULL && ConsoleListSize != 0) );
92 
93  /* All went right, so add the console to the list */
95  DPRINT1("Insert in the list\n");
96 
97  if (ConsoleList)
98  {
99  for (i = 0; i < ConsoleListSize; i++)
100  {
101  if (ConsoleList[i] == NULL) break;
102  }
103  }
104 
105  if (i >= ConsoleListSize)
106  {
107  DPRINT1("Creation of a new handles table\n");
108  /* Allocate a new handles table */
110  (ConsoleListSize +
112  if (Block == NULL)
113  {
115  goto Quit;
116  }
117 
118  /* If we previously had a handles table, free it and use the new one */
119  if (ConsoleList)
120  {
121  /* Copy the handles from the old table to the new one */
122  RtlCopyMemory(Block,
123  ConsoleList,
124  ConsoleListSize * sizeof(PCONSOLE));
126  }
127  ConsoleList = Block;
129  }
130 
131  ConsoleList[i] = Console;
132  *Handle = ULongToHandle((i << 2) | 0x3);
133 
134 Quit:
135  /* Unlock the console list and return status */
137  return Status;
138 }
#define ULongToHandle(h)
Definition: basetsd.h:81
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
LONG NTSTATUS
Definition: precomp.h:26
#define ConDrvUnlockConsoleList()
Definition: console.c:47
#define ConsoleAllocHeap(Flags, Size)
Definition: heap.h:14
#define CONSOLE_HANDLES_INCREMENT
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
smooth NULL
Definition: ftsmooth.c:416
_In_ HANDLE Handle
Definition: extypes.h:390
static PCONSOLE * ConsoleList
Definition: console.c:38
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
Status
Definition: gdiplustypes.h:24
static ULONG ConsoleListSize
Definition: console.c:37
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
CConsole Console
#define DPRINT1
Definition: precomp.h:8
#define ConsoleFreeHeap(HeapBase)
Definition: heap.h:15
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2966
#define ConDrvLockConsoleListExclusive()
Definition: console.c:41

Referenced by ConDrvInitConsole().

◆ RemoveConsoleByPointer()

static NTSTATUS RemoveConsoleByPointer ( IN PCONSOLE  Console)
static

Definition at line 172 of file console.c.

173 {
174  ULONG i = 0;
175 
176  if (!Console) return STATUS_INVALID_PARAMETER;
177 
178  ASSERT( (ConsoleList == NULL && ConsoleListSize == 0) ||
179  (ConsoleList != NULL && ConsoleListSize != 0) );
180 
181  /* Remove the console from the list */
183 
184  if (ConsoleList)
185  {
186  for (i = 0; i < ConsoleListSize; i++)
187  {
188  if (ConsoleList[i] == Console) ConsoleList[i] = NULL;
189  }
190  }
191 
192  /* Unlock the console list */
194 
195  return STATUS_SUCCESS;
196 }
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define ConDrvUnlockConsoleList()
Definition: console.c:47
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
smooth NULL
Definition: ftsmooth.c:416
static PCONSOLE * ConsoleList
Definition: console.c:38
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
static ULONG ConsoleListSize
Definition: console.c:37
CConsole Console
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2966
#define ConDrvLockConsoleListExclusive()
Definition: console.c:41

Referenced by ConDrvDeleteConsole().

◆ ResetFrontEnd()

VOID ResetFrontEnd ( IN PCONSOLE  Console)

Definition at line 176 of file dummyfrontend.c.

177 {
178  if (!Console) return;
179 
180  /* Reinitialize the frontend interface */
181  RtlZeroMemory(&Console->TermIFace, sizeof(Console->TermIFace));
182  Console->TermIFace.Vtbl = &DummyVtbl;
183 }
static FRONTEND_VTBL DummyVtbl
CConsole Console
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261

Referenced by ConDrvDeregisterFrontEnd(), ConDrvInitConsole(), and ConDrvRegisterFrontEnd().

◆ RtlGetLastNtStatus()

NTSTATUS NTAPI RtlGetLastNtStatus ( VOID  )

Definition at line 114 of file error.c.

115 {
116  return NtCurrentTeb()->LastStatusValue;
117 }
FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
Definition: psfuncs.h:420

Referenced by ConDrvConsoleCtrlEventTimeout(), and ConSrvConsoleCtrlEventTimeout().

Variable Documentation

◆ ConsoleList

PCONSOLE* ConsoleList
static

◆ ConsoleListSize

ULONG ConsoleListSize
static

◆ ListLock

RTL_RESOURCE ListLock
static

Definition at line 39 of file console.c.

Referenced by ConDrvInitConsoleSupport().