ReactOS  0.4.13-dev-242-g611e6d7
coninput.c File Reference
#include "consrv.h"
#include <debug.h>
Include dependency graph for coninput.c:

Go to the source code of this file.

Classes

struct  _GET_INPUT_INFO
 

Macros

#define NDEBUG
 
#define ConSrvGetInputBuffer(ProcessData, Handle, Ptr, Access, LockConsole)
 
#define ConSrvGetInputBufferAndHandleEntry(ProcessData, Handle, Ptr, Entry, Access, LockConsole)
 
#define ConSrvReleaseInputBuffer(Buff, IsConsoleLocked)   ConSrvReleaseObject(&(Buff)->Header, (IsConsoleLocked))
 
#define ConsoleInputUnicodeToAnsiChar(Console, dChar, sWChar)
 
#define ConsoleInputAnsiToUnicodeChar(Console, dWChar, sChar)
 

Typedefs

typedef struct _GET_INPUT_INFO GET_INPUT_INFO
 
typedef struct _GET_INPUT_INFOPGET_INPUT_INFO
 

Functions

static VOID ConioInputEventToAnsi (PCONSOLE Console, PINPUT_RECORD InputEvent)
 
static VOID ConioInputEventToUnicode (PCONSOLE Console, PINPUT_RECORD InputEvent)
 
static ULONG PreprocessInput (PCONSRV_CONSOLE Console, PINPUT_RECORD InputEvent, ULONG NumEventsToWrite)
 
static VOID PostprocessInput (PCONSRV_CONSOLE Console)
 
NTSTATUS NTAPI ConDrvWriteConsoleInput (IN PCONSOLE Console, IN PCONSOLE_INPUT_BUFFER InputBuffer, IN BOOLEAN AppendToEnd, IN PINPUT_RECORD InputRecord, IN ULONG NumEventsToWrite, OUT PULONG NumEventsWritten OPTIONAL)
 
static NTSTATUS ConioAddInputEvents (PCONSRV_CONSOLE Console, PINPUT_RECORD InputRecords, ULONG NumEventsToWrite, PULONG NumEventsWritten, BOOLEAN AppendToEnd)
 
NTSTATUS ConioProcessInputEvent (PCONSRV_CONSOLE Console, PINPUT_RECORD InputEvent)
 
static NTSTATUS WaitBeforeReading (IN PGET_INPUT_INFO InputInfo, IN PCSR_API_MESSAGE ApiMessage, IN CSR_WAIT_FUNCTION WaitFunction OPTIONAL, IN BOOLEAN CreateWaitBlock OPTIONAL)
 
static NTSTATUS ReadChars (IN PGET_INPUT_INFO InputInfo, IN PCSR_API_MESSAGE ApiMessage, IN BOOLEAN CreateWaitBlock OPTIONAL)
 
static BOOLEAN NTAPI ReadCharsThread (IN PLIST_ENTRY WaitList, IN PCSR_THREAD WaitThread, IN PCSR_API_MESSAGE WaitApiMessage, IN PVOID WaitContext, IN PVOID WaitArgument1, IN PVOID WaitArgument2, IN ULONG WaitFlags)
 
NTSTATUS NTAPI ConDrvReadConsole (IN PCONSOLE Console, IN PCONSOLE_INPUT_BUFFER InputBuffer, IN BOOLEAN Unicode, OUT PVOID Buffer, IN OUT PCONSOLE_READCONSOLE_CONTROL ReadControl, IN PVOID Parameter OPTIONAL, IN ULONG NumCharsToRead, OUT PULONG NumCharsRead OPTIONAL)
 
static NTSTATUS ReadInputBuffer (IN PGET_INPUT_INFO InputInfo, IN PCSR_API_MESSAGE ApiMessage, IN BOOLEAN CreateWaitBlock OPTIONAL)
 
static BOOLEAN NTAPI ReadInputBufferThread (IN PLIST_ENTRY WaitList, IN PCSR_THREAD WaitThread, IN PCSR_API_MESSAGE WaitApiMessage, IN PVOID WaitContext, IN PVOID WaitArgument1, IN PVOID WaitArgument2, IN ULONG WaitFlags)
 
NTSTATUS NTAPI ConDrvGetConsoleInput (IN PCONSOLE Console, IN PCONSOLE_INPUT_BUFFER InputBuffer, IN BOOLEAN KeepEvents, IN BOOLEAN WaitForMoreEvents, OUT PINPUT_RECORD InputRecord, IN ULONG NumEventsToRead, OUT PULONG NumEventsRead OPTIONAL)
 
 CSR_API (SrvReadConsole)
 
 CSR_API (SrvGetConsoleInput)
 
 CSR_API (SrvWriteConsoleInput)
 
NTSTATUS NTAPI ConDrvFlushConsoleInputBuffer (IN PCONSOLE Console, IN PCONSOLE_INPUT_BUFFER InputBuffer)
 
 CSR_API (SrvFlushConsoleInputBuffer)
 
NTSTATUS NTAPI ConDrvGetConsoleNumberOfInputEvents (IN PCONSOLE Console, IN PCONSOLE_INPUT_BUFFER InputBuffer, OUT PULONG NumberOfEvents)
 
 CSR_API (SrvGetConsoleNumberOfInputEvents)
 

Macro Definition Documentation

◆ ConsoleInputAnsiToUnicodeChar

#define ConsoleInputAnsiToUnicodeChar (   Console,
  dWChar,
  sChar 
)
Value:
ASSERT((ULONG_PTR)dWChar != (ULONG_PTR)sChar); \
MultiByteToWideChar((Console)->InputCodePage, 0, (sChar), 1, (dWChar), 1)
uint32_t ULONG_PTR
Definition: typedefs.h:63
UINT InputCodePage
Definition: console.c:25
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
CConsole Console

Definition at line 39 of file coninput.c.

◆ ConsoleInputUnicodeToAnsiChar

#define ConsoleInputUnicodeToAnsiChar (   Console,
  dChar,
  sWChar 
)
Value:
ASSERT((ULONG_PTR)dChar != (ULONG_PTR)sWChar); \
WideCharToMultiByte((Console)->InputCodePage, 0, (sWChar), 1, (dChar), 1, NULL, NULL)
uint32_t ULONG_PTR
Definition: typedefs.h:63
smooth NULL
Definition: ftsmooth.c:416
UINT InputCodePage
Definition: console.c:25
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
CConsole Console

Definition at line 35 of file coninput.c.

◆ ConSrvGetInputBuffer

#define ConSrvGetInputBuffer (   ProcessData,
  Handle,
  Ptr,
  Access,
  LockConsole 
)
Value:
(Access), (LockConsole), INPUT_BUFFER)
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
smooth NULL
Definition: ftsmooth.c:416
_In_ HANDLE Handle
Definition: extypes.h:390
NTSTATUS ConSrvGetObject(IN PCONSOLE_PROCESS_DATA ProcessData, IN HANDLE Handle, OUT PCONSOLE_IO_OBJECT *Object, OUT PVOID *Entry OPTIONAL, IN ULONG Access, IN BOOLEAN LockConsole, IN CONSOLE_IO_OBJECT_TYPE Type)
Definition: handle.c:401

Definition at line 19 of file coninput.c.

◆ ConSrvGetInputBufferAndHandleEntry

#define ConSrvGetInputBufferAndHandleEntry (   ProcessData,
  Handle,
  Ptr,
  Entry,
  Access,
  LockConsole 
)
Value:
ConSrvGetObject((ProcessData), (Handle), (PCONSOLE_IO_OBJECT*)(Ptr), (Entry), \
(Access), (LockConsole), INPUT_BUFFER)
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
_In_ HANDLE Handle
Definition: extypes.h:390
NTSTATUS ConSrvGetObject(IN PCONSOLE_PROCESS_DATA ProcessData, IN HANDLE Handle, OUT PCONSOLE_IO_OBJECT *Object, OUT PVOID *Entry OPTIONAL, IN ULONG Access, IN BOOLEAN LockConsole, IN CONSOLE_IO_OBJECT_TYPE Type)
Definition: handle.c:401
base of all file and directory entries
Definition: entries.h:82

Definition at line 22 of file coninput.c.

◆ ConSrvReleaseInputBuffer

#define ConSrvReleaseInputBuffer (   Buff,
  IsConsoleLocked 
)    ConSrvReleaseObject(&(Buff)->Header, (IsConsoleLocked))

Definition at line 25 of file coninput.c.

◆ NDEBUG

#define NDEBUG

Definition at line 14 of file coninput.c.

Typedef Documentation

◆ GET_INPUT_INFO

◆ PGET_INPUT_INFO

Function Documentation

◆ ConDrvFlushConsoleInputBuffer()

NTSTATUS NTAPI ConDrvFlushConsoleInputBuffer ( IN PCONSOLE  Console,
IN PCONSOLE_INPUT_BUFFER  InputBuffer 
)

Definition at line 352 of file coninput.c.

354 {
355  PLIST_ENTRY CurrentEntry;
357 
358  if (Console == NULL || InputBuffer == NULL)
360 
361  /* Validity check */
362  ASSERT(Console == InputBuffer->Header.Console);
363 
364  /* Discard all entries in the input event queue */
365  while (!IsListEmpty(&InputBuffer->InputEvents))
366  {
367  CurrentEntry = RemoveHeadList(&InputBuffer->InputEvents);
368  Event = CONTAINING_RECORD(CurrentEntry, ConsoleInput, ListEntry);
370  }
371  ResetEvent(InputBuffer->ActiveEvent);
372 
373  return STATUS_SUCCESS;
374 }
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
CHAR InputBuffer[80]
Definition: conmgr.c:33
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:434
smooth NULL
Definition: ftsmooth.c:416
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
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
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Definition: typedefs.h:117
BOOL WINAPI DECLSPEC_HOTPATCH ResetEvent(IN HANDLE hEvent)
Definition: synch.c:660
CConsole Console
#define ConsoleFreeHeap(HeapBase)
Definition: heap.h:15
return STATUS_SUCCESS
Definition: btrfs.c:2745

◆ ConDrvGetConsoleInput()

NTSTATUS NTAPI ConDrvGetConsoleInput ( IN PCONSOLE  Console,
IN PCONSOLE_INPUT_BUFFER  InputBuffer,
IN BOOLEAN  KeepEvents,
IN BOOLEAN  WaitForMoreEvents,
OUT PINPUT_RECORD  InputRecord,
IN ULONG  NumEventsToRead,
OUT PULONG NumEventsRead  OPTIONAL 
)

Definition at line 260 of file coninput.c.

267 {
268  PLIST_ENTRY CurrentInput;
270  ULONG i = 0;
271 
272  if (Console == NULL || InputBuffer == NULL /* || InputRecord == NULL */)
274 
275  /* Validity checks */
276  ASSERT(Console == InputBuffer->Header.Console);
277  ASSERT((InputRecord != NULL) || (InputRecord == NULL && NumEventsToRead == 0));
278 
279  if (NumEventsRead) *NumEventsRead = 0;
280 
281  if (IsListEmpty(&InputBuffer->InputEvents))
282  {
283  /*
284  * No input is available. Wait for more input if requested,
285  * otherwise, we don't wait, so we return success.
286  */
287  return (WaitForMoreEvents ? STATUS_PENDING : STATUS_SUCCESS);
288  }
289 
290  /* Only get input if there is any */
291  CurrentInput = InputBuffer->InputEvents.Flink;
292  i = 0;
293  while ((CurrentInput != &InputBuffer->InputEvents) && (i < NumEventsToRead))
294  {
295  Input = CONTAINING_RECORD(CurrentInput, ConsoleInput, ListEntry);
296 
297  *InputRecord = Input->InputEvent;
298 
299  ++InputRecord;
300  ++i;
301  CurrentInput = CurrentInput->Flink;
302 
303  /* Remove the events from the queue if needed */
304  if (!KeepEvents)
305  {
306  RemoveEntryList(&Input->ListEntry);
308  }
309  }
310 
311  if (NumEventsRead) *NumEventsRead = i;
312 
313  if (IsListEmpty(&InputBuffer->InputEvents))
314  {
315  ResetEvent(InputBuffer->ActiveEvent);
316  }
317 
318  // FIXME: If we add back UNICODE support, it's here that we need to do the translation.
319 
320  /* We read all the inputs available, we return success */
321  return STATUS_SUCCESS;
322 }
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
Definition: arc.h:84
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
CHAR InputBuffer[80]
Definition: conmgr.c:33
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
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
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_PENDING
Definition: ntstatus.h:82
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Definition: typedefs.h:117
BOOL WINAPI DECLSPEC_HOTPATCH ResetEvent(IN HANDLE hEvent)
Definition: synch.c:660
CConsole Console
#define ConsoleFreeHeap(HeapBase)
Definition: heap.h:15
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2745

◆ ConDrvGetConsoleNumberOfInputEvents()

NTSTATUS NTAPI ConDrvGetConsoleNumberOfInputEvents ( IN PCONSOLE  Console,
IN PCONSOLE_INPUT_BUFFER  InputBuffer,
OUT PULONG  NumberOfEvents 
)

Definition at line 377 of file coninput.c.

380 {
381  PLIST_ENTRY CurrentInput;
382 
383  if (Console == NULL || InputBuffer == NULL || NumberOfEvents == NULL)
385 
386  /* Validity check */
387  ASSERT(Console == InputBuffer->Header.Console);
388 
389  *NumberOfEvents = 0;
390 
391  /* If there are any events ... */
392  CurrentInput = InputBuffer->InputEvents.Flink;
393  while (CurrentInput != &InputBuffer->InputEvents)
394  {
395  CurrentInput = CurrentInput->Flink;
396  (*NumberOfEvents)++;
397  }
398 
399  return STATUS_SUCCESS;
400 }
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
CHAR InputBuffer[80]
Definition: conmgr.c:33
smooth NULL
Definition: ftsmooth.c:416
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Definition: typedefs.h:117
CConsole Console
return STATUS_SUCCESS
Definition: btrfs.c:2745

◆ ConDrvReadConsole()

NTSTATUS NTAPI ConDrvReadConsole ( IN PCONSOLE  Console,
IN PCONSOLE_INPUT_BUFFER  InputBuffer,
IN BOOLEAN  Unicode,
OUT PVOID  Buffer,
IN OUT PCONSOLE_READCONSOLE_CONTROL  ReadControl,
IN PVOID Parameter  OPTIONAL,
IN ULONG  NumCharsToRead,
OUT PULONG NumCharsRead  OPTIONAL 
)

Definition at line 227 of file coninput.c.

235 {
236  // STATUS_PENDING : Wait if more to read ; STATUS_SUCCESS : Don't wait.
237  // NTSTATUS Status; = STATUS_PENDING;
238 
239  if (Console == NULL || InputBuffer == NULL || /* Buffer == NULL || */
240  ReadControl == NULL || ReadControl->nLength != sizeof(CONSOLE_READCONSOLE_CONTROL))
241  {
243  }
244 
245  /* Validity checks */
246  ASSERT(Console == InputBuffer->Header.Console);
247  ASSERT((Buffer != NULL) || (Buffer == NULL && NumCharsToRead == 0));
248 
249  /* Call the line-discipline */
250  return TermReadStream(Console,
251  Unicode,
252  Buffer,
253  ReadControl,
254  Parameter,
255  NumCharsToRead,
256  NumCharsRead);
257 }
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_In_ PVOID Parameter
Definition: ldrtypes.h:240
CHAR InputBuffer[80]
Definition: conmgr.c:33
#define TermReadStream(Console, Unicode, Buffer, ReadControl, Parameter, NumCharsToRead, NumCharsRead)
Definition: term.h:13
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
CConsole Console

Referenced by ReadChars().

◆ ConDrvWriteConsoleInput()

NTSTATUS NTAPI ConDrvWriteConsoleInput ( IN PCONSOLE  Console,
IN PCONSOLE_INPUT_BUFFER  InputBuffer,
IN BOOLEAN  AppendToEnd,
IN PINPUT_RECORD  InputRecord,
IN ULONG  NumEventsToWrite,
OUT PULONG NumEventsWritten  OPTIONAL 
)

Definition at line 325 of file coninput.c.

331 {
332  if (Console == NULL || InputBuffer == NULL /* || InputRecord == NULL */)
334 
335  /* Validity checks */
336  ASSERT(Console == InputBuffer->Header.Console);
337  ASSERT((InputRecord != NULL) || (InputRecord == NULL && NumEventsToWrite == 0));
338 
339  /* Now, add the events */
340  if (NumEventsWritten) *NumEventsWritten = 0;
341 
342  // FIXME: If we add back UNICODE support, it's here that we need to do the translation.
343 
344  return AddInputEvents(Console,
345  InputRecord,
346  NumEventsToWrite,
347  NumEventsWritten,
348  AppendToEnd);
349 }
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
CHAR InputBuffer[80]
Definition: conmgr.c:33
smooth NULL
Definition: ftsmooth.c:416
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
static NTSTATUS AddInputEvents(PCONSOLE Console, PINPUT_RECORD InputRecords, ULONG NumEventsToWrite, PULONG NumEventsWritten, BOOLEAN AppendToEnd)
Definition: coninput.c:21
CConsole Console

◆ ConioAddInputEvents()

static NTSTATUS ConioAddInputEvents ( PCONSRV_CONSOLE  Console,
PINPUT_RECORD  InputRecords,
ULONG  NumEventsToWrite,
PULONG  NumEventsWritten,
BOOLEAN  AppendToEnd 
)
static

Definition at line 161 of file coninput.c.

166 {
168 
169  if (NumEventsWritten) *NumEventsWritten = 0;
170 
171  NumEventsToWrite = PreprocessInput(Console, InputRecords, NumEventsToWrite);
172  if (NumEventsToWrite == 0) return STATUS_SUCCESS;
173 
174  // Status = ConDrvAddInputEvents(Console,
175  // InputRecords,
176  // NumEventsToWrite,
177  // NumEventsWritten,
178  // AppendToEnd);
179 
181  &Console->InputBuffer,
182  AppendToEnd,
183  InputRecords,
184  NumEventsToWrite,
185  NumEventsWritten);
186 
187  // if (NT_SUCCESS(Status))
189 
190  return Status;
191 }
LONG NTSTATUS
Definition: precomp.h:26
static ULONG PreprocessInput(PCONSRV_CONSOLE Console, PINPUT_RECORD InputEvent, ULONG NumEventsToWrite)
Definition: coninput.c:81
static VOID PostprocessInput(PCONSRV_CONSOLE Console)
Definition: coninput.c:140
Status
Definition: gdiplustypes.h:24
CConsole Console
return STATUS_SUCCESS
Definition: btrfs.c:2745
NTSTATUS NTAPI ConDrvWriteConsoleInput(IN PCONSOLE Console, IN PCONSOLE_INPUT_BUFFER InputBuffer, IN BOOLEAN AppendToEnd, IN PINPUT_RECORD InputRecord, IN ULONG NumEventsToWrite, OUT PULONG NumEventsWritten OPTIONAL)
Definition: coninput.c:325

Referenced by ConioProcessInputEvent(), and CSR_API().

◆ ConioInputEventToAnsi()

static VOID ConioInputEventToAnsi ( PCONSOLE  Console,
PINPUT_RECORD  InputEvent 
)
static

Definition at line 55 of file coninput.c.

56 {
57  if (InputEvent->EventType == KEY_EVENT)
58  {
59  WCHAR UnicodeChar = InputEvent->Event.KeyEvent.uChar.UnicodeChar;
60  InputEvent->Event.KeyEvent.uChar.UnicodeChar = 0;
62  &InputEvent->Event.KeyEvent.uChar.AsciiChar,
63  &UnicodeChar);
64  }
65 }
WCHAR UnicodeChar
Definition: wincon.h:230
union _KEY_EVENT_RECORD::@3144 uChar
#define KEY_EVENT
Definition: wincon.h:122
#define ConsoleInputUnicodeToAnsiChar(Console, dChar, sWChar)
Definition: coninput.c:35
union _INPUT_RECORD::@3145 Event
__wchar_t WCHAR
Definition: xmlstorage.h:180
KEY_EVENT_RECORD KeyEvent
Definition: wincon.h:263
CConsole Console
WORD EventType
Definition: wincon.h:261

Referenced by ReadInputBuffer().

◆ ConioInputEventToUnicode()

static VOID ConioInputEventToUnicode ( PCONSOLE  Console,
PINPUT_RECORD  InputEvent 
)
static

Definition at line 68 of file coninput.c.

69 {
70  if (InputEvent->EventType == KEY_EVENT)
71  {
72  CHAR AsciiChar = InputEvent->Event.KeyEvent.uChar.AsciiChar;
73  InputEvent->Event.KeyEvent.uChar.AsciiChar = 0;
75  &InputEvent->Event.KeyEvent.uChar.UnicodeChar,
76  &AsciiChar);
77  }
78 }
WCHAR UnicodeChar
Definition: wincon.h:230
union _KEY_EVENT_RECORD::@3144 uChar
char CHAR
Definition: xmlstorage.h:175
#define KEY_EVENT
Definition: wincon.h:122
union _INPUT_RECORD::@3145 Event
#define ConsoleInputAnsiToUnicodeChar(Console, dWChar, sChar)
Definition: coninput.c:39
KEY_EVENT_RECORD KeyEvent
Definition: wincon.h:263
CConsole Console
WORD EventType
Definition: wincon.h:261

Referenced by CSR_API().

◆ ConioProcessInputEvent()

NTSTATUS ConioProcessInputEvent ( PCONSRV_CONSOLE  Console,
PINPUT_RECORD  InputEvent 
)

Definition at line 195 of file coninput.c.

197 {
198  ULONG NumEventsWritten;
200  InputEvent,
201  1,
202  &NumEventsWritten,
203  TRUE);
204 }
#define TRUE
Definition: types.h:120
static NTSTATUS ConioAddInputEvents(PCONSRV_CONSOLE Console, PINPUT_RECORD InputRecords, ULONG NumEventsToWrite, PULONG NumEventsWritten, BOOLEAN AppendToEnd)
Definition: coninput.c:161
CConsole Console
unsigned int ULONG
Definition: retypes.h:1

Referenced by ConDrvProcessKey(), ConDrvWriteConsoleInput(), ConioProcessKey(), ConioResizeBuffer(), GuiConsoleHandleMouse(), GuiConsoleWndProc(), GuiPasteToTextModeBuffer(), GuiSendMenuEvent(), OnFocus(), OnMouse(), PasteText(), and SendMenuEvent().

◆ CSR_API() [1/5]

CSR_API ( SrvReadConsole  )

Definition at line 551 of file coninput.c.

552 {
554  PCONSOLE_READCONSOLE ReadConsoleRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.ReadConsoleRequest;
556  PVOID HandleEntry;
558  GET_INPUT_INFO InputInfo;
559 
560  DPRINT("SrvReadConsole\n");
561 
562  /*
563  * For optimization purposes, Windows (and hence ReactOS, too, for
564  * compatibility reasons) uses a static buffer if no more than eighty
565  * bytes are read. Otherwise a new buffer is used.
566  * The client-side expects that we know this behaviour.
567  */
568  if (ReadConsoleRequest->CaptureBufferSize <= sizeof(ReadConsoleRequest->StaticBuffer))
569  {
570  /*
571  * Adjust the internal pointer, because its old value points to
572  * the static buffer in the original ApiMessage structure.
573  */
574  // ReadConsoleRequest->Buffer = ReadConsoleRequest->StaticBuffer;
575  }
576  else
577  {
578  if (!CsrValidateMessageBuffer(ApiMessage,
579  (PVOID*)&ReadConsoleRequest->Buffer,
580  ReadConsoleRequest->CaptureBufferSize,
581  sizeof(BYTE)))
582  {
584  }
585  }
586 
587  if (ReadConsoleRequest->InitialNumBytes > ReadConsoleRequest->NumBytes)
588  {
590  }
591 
592  Status = ConSrvGetInputBufferAndHandleEntry(ProcessData, ReadConsoleRequest->InputHandle, &InputBuffer, &HandleEntry, GENERIC_READ, TRUE);
593  if (!NT_SUCCESS(Status)) return Status;
594 
595  InputInfo.CallingThread = CsrGetClientThread();
596  InputInfo.HandleEntry = HandleEntry;
597  InputInfo.InputBuffer = InputBuffer;
598 
599  Status = ReadChars(&InputInfo, ApiMessage, TRUE);
600 
602 
603  if (Status == STATUS_PENDING) *ReplyCode = CsrReplyPending;
604 
605  return Status;
606 }
#define CsrGetClientThread()
Definition: csrsrv.h:77
#define TRUE
Definition: types.h:120
HANDLE InputHandle
Definition: conmsg.h:256
PVOID HandleEntry
Definition: coninput.c:47
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
struct _CONSOLE_API_MESSAGE * PCONSOLE_API_MESSAGE
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI CsrValidateMessageBuffer(IN PCSR_API_MESSAGE ApiMessage, IN PVOID *Buffer, IN ULONG ElementCount, IN ULONG ElementSize)
Definition: api.c:1315
PCSR_THREAD CallingThread
Definition: coninput.c:46
CHAR StaticBuffer[80]
Definition: conmsg.h:260
CHAR InputBuffer[80]
Definition: conmgr.c:33
ULONG CaptureBufferSize
Definition: conmsg.h:264
void DPRINT(...)
Definition: polytest.cpp:61
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
#define ConsoleGetPerProcessData(Process)
Definition: consrv.h:37
ULONG InitialNumBytes
Definition: conmsg.h:266
unsigned char BYTE
Definition: mem.h:68
#define GENERIC_READ
Definition: compat.h:124
Status
Definition: gdiplustypes.h:24
#define ConSrvGetInputBufferAndHandleEntry(ProcessData, Handle, Ptr, Entry, Access, LockConsole)
Definition: coninput.c:22
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
PCONSOLE_INPUT_BUFFER InputBuffer
Definition: coninput.c:48
#define ConSrvReleaseInputBuffer(Buff, IsConsoleLocked)
Definition: coninput.c:25
static NTSTATUS ReadChars(IN PGET_INPUT_INFO InputInfo, IN PCSR_API_MESSAGE ApiMessage, IN BOOLEAN CreateWaitBlock OPTIONAL)
Definition: coninput.c:312

◆ CSR_API() [2/5]

CSR_API ( SrvGetConsoleInput  )

Definition at line 608 of file coninput.c.

609 {
611  PCONSOLE_GETINPUT GetInputRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetInputRequest;
613  PVOID HandleEntry;
615  GET_INPUT_INFO InputInfo;
616 
617  DPRINT("SrvGetConsoleInput\n");
618 
619  if (GetInputRequest->Flags & ~(CONSOLE_READ_KEEPEVENT | CONSOLE_READ_CONTINUE))
621 
622  /*
623  * For optimization purposes, Windows (and hence ReactOS, too, for
624  * compatibility reasons) uses a static buffer if no more than five
625  * input records are read. Otherwise a new buffer is used.
626  * The client-side expects that we know this behaviour.
627  */
628  if (GetInputRequest->NumRecords <= sizeof(GetInputRequest->RecordStaticBuffer)/sizeof(INPUT_RECORD))
629  {
630  /*
631  * Adjust the internal pointer, because its old value points to
632  * the static buffer in the original ApiMessage structure.
633  */
634  // GetInputRequest->RecordBufPtr = GetInputRequest->RecordStaticBuffer;
635  }
636  else
637  {
638  if (!CsrValidateMessageBuffer(ApiMessage,
639  (PVOID*)&GetInputRequest->RecordBufPtr,
640  GetInputRequest->NumRecords,
641  sizeof(INPUT_RECORD)))
642  {
644  }
645  }
646 
647  Status = ConSrvGetInputBufferAndHandleEntry(ProcessData, GetInputRequest->InputHandle, &InputBuffer, &HandleEntry, GENERIC_READ, TRUE);
648  if (!NT_SUCCESS(Status)) return Status;
649 
650  InputInfo.CallingThread = CsrGetClientThread();
651  InputInfo.HandleEntry = HandleEntry;
652  InputInfo.InputBuffer = InputBuffer;
653 
654  Status = ReadInputBuffer(&InputInfo, ApiMessage, TRUE);
655 
657 
658  if (Status == STATUS_PENDING) *ReplyCode = CsrReplyPending;
659 
660  return Status;
661 }
#define CsrGetClientThread()
Definition: csrsrv.h:77
ULONG NumRecords
Definition: conmsg.h:568
#define TRUE
Definition: types.h:120
PVOID HandleEntry
Definition: coninput.c:47
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
struct _CONSOLE_API_MESSAGE * PCONSOLE_API_MESSAGE
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI CsrValidateMessageBuffer(IN PCSR_API_MESSAGE ApiMessage, IN PVOID *Buffer, IN ULONG ElementCount, IN ULONG ElementSize)
Definition: api.c:1315
PCSR_THREAD CallingThread
Definition: coninput.c:46
INPUT_RECORD RecordStaticBuffer[5]
Definition: conmsg.h:566
HANDLE InputHandle
Definition: conmsg.h:565
CHAR InputBuffer[80]
Definition: conmgr.c:33
void DPRINT(...)
Definition: polytest.cpp:61
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
#define ConsoleGetPerProcessData(Process)
Definition: consrv.h:37
PINPUT_RECORD RecordBufPtr
Definition: conmsg.h:567
#define GENERIC_READ
Definition: compat.h:124
#define CONSOLE_READ_KEEPEVENT
Definition: wincon.h:116
Status
Definition: gdiplustypes.h:24
#define CONSOLE_READ_CONTINUE
Definition: wincon.h:117
#define ConSrvGetInputBufferAndHandleEntry(ProcessData, Handle, Ptr, Entry, Access, LockConsole)
Definition: coninput.c:22
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
PCONSOLE_INPUT_BUFFER InputBuffer
Definition: coninput.c:48
static NTSTATUS ReadInputBuffer(IN PGET_INPUT_INFO InputInfo, IN PCSR_API_MESSAGE ApiMessage, IN BOOLEAN CreateWaitBlock OPTIONAL)
Definition: coninput.c:475
#define ConSrvReleaseInputBuffer(Buff, IsConsoleLocked)
Definition: coninput.c:25

◆ CSR_API() [3/5]

CSR_API ( SrvWriteConsoleInput  )

Definition at line 672 of file coninput.c.

673 {
675  PCONSOLE_WRITEINPUT WriteInputRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.WriteInputRequest;
677  ULONG NumEventsWritten;
678 
679  PINPUT_RECORD InputRecord;
680 
681  DPRINT("SrvWriteConsoleInput\n");
682 
683  /*
684  * For optimization purposes, Windows (and hence ReactOS, too, for
685  * compatibility reasons) uses a static buffer if no more than five
686  * input records are written. Otherwise a new buffer is used.
687  * The client-side expects that we know this behaviour.
688  */
689  if (WriteInputRequest->NumRecords <= sizeof(WriteInputRequest->RecordStaticBuffer)/sizeof(INPUT_RECORD))
690  {
691  /*
692  * Adjust the internal pointer, because its old value points to
693  * the static buffer in the original ApiMessage structure.
694  */
695  // WriteInputRequest->RecordBufPtr = WriteInputRequest->RecordStaticBuffer;
696  InputRecord = WriteInputRequest->RecordStaticBuffer;
697  }
698  else
699  {
700  if (!CsrValidateMessageBuffer(ApiMessage,
701  (PVOID*)&WriteInputRequest->RecordBufPtr,
702  WriteInputRequest->NumRecords,
703  sizeof(INPUT_RECORD)))
704  {
706  }
707 
708  InputRecord = WriteInputRequest->RecordBufPtr;
709  }
710 
712  WriteInputRequest->InputHandle,
714  if (!NT_SUCCESS(Status))
715  {
716  WriteInputRequest->NumRecords = 0;
717  return Status;
718  }
719 
720  /* First translate everything to UNICODE */
721  if (!WriteInputRequest->Unicode)
722  {
723  ULONG i;
724  for (i = 0; i < WriteInputRequest->NumRecords; ++i)
725  {
726  ConioInputEventToUnicode(InputBuffer->Header.Console, &InputRecord[i]);
727  }
728  }
729 
730  /* Now, add the events */
731  NumEventsWritten = 0;
733  // InputBuffer,
734  InputRecord,
735  WriteInputRequest->NumRecords,
736  &NumEventsWritten,
737  WriteInputRequest->AppendToEnd);
738 
739  // Status = ConDrvWriteConsoleInput(InputBuffer->Header.Console,
740  // InputBuffer,
741  // WriteInputRequest->AppendToEnd,
742  // InputRecord,
743  // WriteInputRequest->NumRecords,
744  // &NumEventsWritten);
745 
746  WriteInputRequest->NumRecords = NumEventsWritten;
747 
749  return Status;
750 }
#define CsrGetClientThread()
Definition: csrsrv.h:77
#define TRUE
Definition: types.h:120
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
struct _CONSOLE_API_MESSAGE * PCONSOLE_API_MESSAGE
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI CsrValidateMessageBuffer(IN PCSR_API_MESSAGE ApiMessage, IN PVOID *Buffer, IN ULONG ElementCount, IN ULONG ElementSize)
Definition: api.c:1315
HANDLE InputHandle
Definition: conmsg.h:576
static VOID ConioInputEventToUnicode(PCONSOLE Console, PINPUT_RECORD InputEvent)
Definition: coninput.c:68
#define PCONSRV_CONSOLE
Definition: conio.h:27
CHAR InputBuffer[80]
Definition: conmgr.c:33
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
#define GENERIC_WRITE
Definition: nt_native.h:90
void DPRINT(...)
Definition: polytest.cpp:61
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ConsoleGetPerProcessData(Process)
Definition: consrv.h:37
PINPUT_RECORD RecordBufPtr
Definition: conmsg.h:578
INPUT_RECORD RecordStaticBuffer[5]
Definition: conmsg.h:577
BOOLEAN AppendToEnd
Definition: conmsg.h:581
static NTSTATUS ConioAddInputEvents(PCONSRV_CONSOLE Console, PINPUT_RECORD InputRecords, ULONG NumEventsToWrite, PULONG NumEventsWritten, BOOLEAN AppendToEnd)
Definition: coninput.c:161
Status
Definition: gdiplustypes.h:24
BOOLEAN Unicode
Definition: conmsg.h:580
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
#define ConSrvGetInputBuffer(ProcessData, Handle, Ptr, Access, LockConsole)
Definition: coninput.c:19
unsigned int ULONG
Definition: retypes.h:1
#define ConSrvReleaseInputBuffer(Buff, IsConsoleLocked)
Definition: coninput.c:25

◆ CSR_API() [4/5]

CSR_API ( SrvFlushConsoleInputBuffer  )

Definition at line 755 of file coninput.c.

756 {
758  PCONSOLE_FLUSHINPUTBUFFER FlushInputBufferRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.FlushInputBufferRequest;
760 
761  DPRINT("SrvFlushConsoleInputBuffer\n");
762 
764  FlushInputBufferRequest->InputHandle,
766  if (!NT_SUCCESS(Status)) return Status;
767 
769  InputBuffer);
770 
772  return Status;
773 }
#define CsrGetClientThread()
Definition: csrsrv.h:77
#define TRUE
Definition: types.h:120
struct _CONSOLE_API_MESSAGE * PCONSOLE_API_MESSAGE
LONG NTSTATUS
Definition: precomp.h:26
CHAR InputBuffer[80]
Definition: conmgr.c:33
NTSTATUS NTAPI ConDrvFlushConsoleInputBuffer(IN PCONSOLE Console, IN PCONSOLE_INPUT_BUFFER InputBuffer)
Definition: coninput.c:352
#define GENERIC_WRITE
Definition: nt_native.h:90
void DPRINT(...)
Definition: polytest.cpp:61
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ConsoleGetPerProcessData(Process)
Definition: consrv.h:37
Status
Definition: gdiplustypes.h:24
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
#define ConSrvGetInputBuffer(ProcessData, Handle, Ptr, Access, LockConsole)
Definition: coninput.c:19
#define ConSrvReleaseInputBuffer(Buff, IsConsoleLocked)
Definition: coninput.c:25

◆ CSR_API() [5/5]

CSR_API ( SrvGetConsoleNumberOfInputEvents  )

Definition at line 779 of file coninput.c.

780 {
782  PCONSOLE_GETNUMINPUTEVENTS GetNumInputEventsRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetNumInputEventsRequest;
784 
785  DPRINT("SrvGetConsoleNumberOfInputEvents\n");
786 
788  GetNumInputEventsRequest->InputHandle,
790  if (!NT_SUCCESS(Status)) return Status;
791 
793  InputBuffer,
794  &GetNumInputEventsRequest->NumberOfEvents);
795 
797  return Status;
798 }
#define CsrGetClientThread()
Definition: csrsrv.h:77
#define TRUE
Definition: types.h:120
struct _CONSOLE_API_MESSAGE * PCONSOLE_API_MESSAGE
LONG NTSTATUS
Definition: precomp.h:26
CHAR InputBuffer[80]
Definition: conmgr.c:33
void DPRINT(...)
Definition: polytest.cpp:61
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ConsoleGetPerProcessData(Process)
Definition: consrv.h:37
#define GENERIC_READ
Definition: compat.h:124
Status
Definition: gdiplustypes.h:24
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
#define ConSrvGetInputBuffer(ProcessData, Handle, Ptr, Access, LockConsole)
Definition: coninput.c:19
NTSTATUS NTAPI ConDrvGetConsoleNumberOfInputEvents(IN PCONSOLE Console, IN PCONSOLE_INPUT_BUFFER InputBuffer, OUT PULONG NumberOfEvents)
Definition: coninput.c:377
#define ConSrvReleaseInputBuffer(Buff, IsConsoleLocked)
Definition: coninput.c:25

◆ PostprocessInput()

static VOID PostprocessInput ( PCONSRV_CONSOLE  Console)
static

Definition at line 140 of file coninput.c.

141 {
142  CsrNotifyWait(&Console->ReadWaitQueue,
143  FALSE,
144  NULL,
145  NULL);
146  if (!IsListEmpty(&Console->ReadWaitQueue))
147  {
148  CsrDereferenceWait(&Console->ReadWaitQueue);
149  }
150 }
_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
smooth NULL
Definition: ftsmooth.c:416
VOID NTAPI CsrDereferenceWait(IN PLIST_ENTRY WaitList)
Definition: wait.c:266
CConsole Console

Referenced by ConioAddInputEvents().

◆ PreprocessInput()

static ULONG PreprocessInput ( PCONSRV_CONSOLE  Console,
PINPUT_RECORD  InputEvent,
ULONG  NumEventsToWrite 
)
static

Definition at line 81 of file coninput.c.

84 {
85  ULONG NumEvents;
86 
87  /*
88  * Loop each event, and for each, check for pause or unpause
89  * and perform adequate behaviour.
90  */
91  for (NumEvents = NumEventsToWrite; NumEvents > 0; --NumEvents)
92  {
93  /* Check for pause or unpause */
94  if (InputEvent->EventType == KEY_EVENT && InputEvent->Event.KeyEvent.bKeyDown)
95  {
96  WORD vk = InputEvent->Event.KeyEvent.wVirtualKeyCode;
97  if (!(Console->PauseFlags & PAUSED_FROM_KEYBOARD))
98  {
99  DWORD cks = InputEvent->Event.KeyEvent.dwControlKeyState;
100  if (Console->InputBuffer.Mode & ENABLE_LINE_INPUT &&
101  (vk == VK_PAUSE ||
102  (vk == 'S' && (cks & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED)) &&
103  !(cks & (LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED)))))
104  {
106 
107  /* Skip the event */
108  RtlMoveMemory(InputEvent,
109  InputEvent + 1,
110  (NumEvents - 1) * sizeof(INPUT_RECORD));
111  --NumEventsToWrite;
112  continue;
113  }
114  }
115  else
116  {
117  if ((vk < VK_SHIFT || vk > VK_CAPITAL) && vk != VK_LWIN &&
118  vk != VK_RWIN && vk != VK_NUMLOCK && vk != VK_SCROLL)
119  {
121 
122  /* Skip the event */
123  RtlMoveMemory(InputEvent,
124  InputEvent + 1,
125  (NumEvents - 1) * sizeof(INPUT_RECORD));
126  --NumEventsToWrite;
127  continue;
128  }
129  }
130  }
131 
132  /* Go to the next event */
133  ++InputEvent;
134  }
135 
136  return NumEventsToWrite;
137 }
VOID ConioUnpause(PCONSRV_CONSOLE Console, UINT Flags)
Definition: console.c:250
#define PAUSED_FROM_KEYBOARD
Definition: conio_winsrv.h:126
DWORD dwControlKeyState
Definition: wincon.h:233
#define VK_LWIN
Definition: winuser.h:2189
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:263
WORD wVirtualKeyCode
Definition: wincon.h:227
#define KEY_EVENT
Definition: wincon.h:122
union _INPUT_RECORD::@3145 Event
#define LEFT_ALT_PRESSED
Definition: wincon.h:132
KEY_EVENT_RECORD KeyEvent
Definition: wincon.h:263
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned long DWORD
Definition: ntddk_ex.h:95
#define ENABLE_LINE_INPUT
Definition: wincon.h:76
#define LEFT_CTRL_PRESSED
Definition: wincon.h:134
#define VK_RWIN
Definition: winuser.h:2190
#define VK_SCROLL
Definition: winuser.h:2234
#define VK_NUMLOCK
Definition: winuser.h:2233
#define VK_CAPITAL
Definition: winuser.h:2160
CConsole Console
WORD EventType
Definition: wincon.h:261
VOID ConioPause(PCONSRV_CONSOLE Console, UINT Flags)
Definition: console.c:243
#define VK_PAUSE
Definition: winuser.h:2159
unsigned int ULONG
Definition: retypes.h:1
#define RIGHT_CTRL_PRESSED
Definition: wincon.h:133
#define RIGHT_ALT_PRESSED
Definition: wincon.h:131

Referenced by ConioAddInputEvents().

◆ ReadChars()

static NTSTATUS ReadChars ( IN PGET_INPUT_INFO  InputInfo,
IN PCSR_API_MESSAGE  ApiMessage,
IN BOOLEAN CreateWaitBlock  OPTIONAL 
)
static

Definition at line 312 of file coninput.c.

315 {
317  PCONSOLE_READCONSOLE ReadConsoleRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.ReadConsoleRequest;
318  PCONSOLE_INPUT_BUFFER InputBuffer = InputInfo->InputBuffer;
319  CONSOLE_READCONSOLE_CONTROL ReadControl;
320 
321  UNICODE_STRING ExeName;
322 
323  PVOID Buffer;
324  ULONG NrCharactersRead = 0;
325  ULONG CharSize = (ReadConsoleRequest->Unicode ? sizeof(WCHAR) : sizeof(CHAR));
326 
327  /* Retrieve the executable name, if needed */
328  if (ReadConsoleRequest->InitialNumBytes == 0 &&
329  ReadConsoleRequest->ExeLength <= sizeof(ReadConsoleRequest->StaticBuffer))
330  {
331  ExeName.Length = ExeName.MaximumLength = ReadConsoleRequest->ExeLength;
332  ExeName.Buffer = (PWCHAR)ReadConsoleRequest->StaticBuffer;
333  }
334  else
335  {
336  ExeName.Length = ExeName.MaximumLength = 0;
337  ExeName.Buffer = NULL;
338  }
339 
340  /* Build the ReadControl structure */
341  ReadControl.nLength = sizeof(CONSOLE_READCONSOLE_CONTROL);
342  ReadControl.nInitialChars = ReadConsoleRequest->InitialNumBytes / CharSize;
343  ReadControl.dwCtrlWakeupMask = ReadConsoleRequest->CtrlWakeupMask;
344  ReadControl.dwControlKeyState = ReadConsoleRequest->ControlKeyState;
345 
346  /*
347  * For optimization purposes, Windows (and hence ReactOS, too, for
348  * compatibility reasons) uses a static buffer if no more than eighty
349  * bytes are read. Otherwise a new buffer is used.
350  * The client-side expects that we know this behaviour.
351  */
352  if (ReadConsoleRequest->CaptureBufferSize <= sizeof(ReadConsoleRequest->StaticBuffer))
353  {
354  /*
355  * Adjust the internal pointer, because its old value points to
356  * the static buffer in the original ApiMessage structure.
357  */
358  // ReadConsoleRequest->Buffer = ReadConsoleRequest->StaticBuffer;
359  Buffer = ReadConsoleRequest->StaticBuffer;
360  }
361  else
362  {
363  Buffer = ReadConsoleRequest->Buffer;
364  }
365 
366  DPRINT("Calling ConDrvReadConsole(%wZ)\n", &ExeName);
367  Status = ConDrvReadConsole(InputBuffer->Header.Console,
368  InputBuffer,
369  ReadConsoleRequest->Unicode,
370  Buffer,
371  &ReadControl,
372  &ExeName,
373  ReadConsoleRequest->NumBytes / CharSize, // NrCharactersToRead
374  &NrCharactersRead);
375  DPRINT("ConDrvReadConsole returned (%d ; Status = 0x%08x)\n",
376  NrCharactersRead, Status);
377 
378  // ReadConsoleRequest->ControlKeyState = ReadControl.dwControlKeyState;
379 
380  if (Status == STATUS_PENDING)
381  {
382  /* We haven't completed a read, so start a wait */
383  return WaitBeforeReading(InputInfo,
384  ApiMessage,
386  CreateWaitBlock);
387  }
388  else
389  {
390  /*
391  * We read all what we wanted. Set the number of bytes read and
392  * return the error code we were given.
393  */
394  ReadConsoleRequest->NumBytes = NrCharactersRead * CharSize;
395  ReadConsoleRequest->ControlKeyState = ReadControl.dwControlKeyState;
396 
397  return Status;
398  // return STATUS_SUCCESS;
399  }
400 }
USHORT MaximumLength
Definition: env_spec_w32.h:370
static BOOLEAN NTAPI ReadCharsThread(IN PLIST_ENTRY WaitList, IN PCSR_THREAD WaitThread, IN PCSR_API_MESSAGE WaitApiMessage, IN PVOID WaitContext, IN PVOID WaitArgument1, IN PVOID WaitArgument2, IN ULONG WaitFlags)
Definition: coninput.c:246
char CHAR
Definition: xmlstorage.h:175
struct _CONSOLE_API_MESSAGE * PCONSOLE_API_MESSAGE
ULONG ControlKeyState
Definition: conmsg.h:268
LONG NTSTATUS
Definition: precomp.h:26
uint16_t * PWCHAR
Definition: typedefs.h:54
CHAR StaticBuffer[80]
Definition: conmsg.h:260
CHAR InputBuffer[80]
Definition: conmgr.c:33
ULONG CtrlWakeupMask
Definition: conmsg.h:267
static NTSTATUS WaitBeforeReading(IN PGET_INPUT_INFO InputInfo, IN PCSR_API_MESSAGE ApiMessage, IN CSR_WAIT_FUNCTION WaitFunction OPTIONAL, IN BOOLEAN CreateWaitBlock OPTIONAL)
Definition: coninput.c:208
smooth NULL
Definition: ftsmooth.c:416
ULONG CaptureBufferSize
Definition: conmsg.h:264
void DPRINT(...)
Definition: polytest.cpp:61
Definition: bufpool.h:45
NTSTATUS NTAPI ConDrvReadConsole(IN PCONSOLE Console, IN PCONSOLE_INPUT_BUFFER InputBuffer, IN BOOLEAN Unicode, OUT PVOID Buffer, IN OUT PCONSOLE_READCONSOLE_CONTROL ReadControl, IN PVOID Parameter OPTIONAL, IN ULONG NumCharsToRead, OUT PULONG NumCharsRead OPTIONAL)
Definition: coninput.c:227
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define STATUS_PENDING
Definition: ntstatus.h:82
ULONG InitialNumBytes
Definition: conmsg.h:266
struct _CONSOLE_READCONSOLE_CONTROL CONSOLE_READCONSOLE_CONTROL
Status
Definition: gdiplustypes.h:24
unsigned int ULONG
Definition: retypes.h:1
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34

Referenced by CSR_API(), and ReadCharsThread().

◆ ReadCharsThread()

static BOOLEAN NTAPI ReadCharsThread ( IN PLIST_ENTRY  WaitList,
IN PCSR_THREAD  WaitThread,
IN PCSR_API_MESSAGE  WaitApiMessage,
IN PVOID  WaitContext,
IN PVOID  WaitArgument1,
IN PVOID  WaitArgument2,
IN ULONG  WaitFlags 
)
static

Definition at line 246 of file coninput.c.

253 {
255  PGET_INPUT_INFO InputInfo = (PGET_INPUT_INFO)WaitContext;
256 
257  PVOID InputHandle = WaitArgument2;
258 
259  DPRINT("ReadCharsThread - WaitContext = 0x%p, WaitArgument1 = 0x%p, WaitArgument2 = 0x%p, WaitFlags = %lu\n", WaitContext, WaitArgument1, WaitArgument2, WaitFlags);
260 
261  /*
262  * If we are notified of the process termination via a call
263  * to CsrNotifyWaitBlock triggered by CsrDestroyProcess or
264  * CsrDestroyThread, just return.
265  */
266  if (WaitFlags & CsrProcessTerminating)
267  {
269  goto Quit;
270  }
271 
272  /*
273  * Somebody is closing a handle to this input buffer,
274  * by calling ConSrvCloseHandleEntry.
275  * See whether we are linked to that handle (ie. we
276  * are a waiter for this handle), and if so, return.
277  * Otherwise, ignore the call and continue waiting.
278  */
279  if (InputHandle != NULL)
280  {
281  Status = (InputHandle == InputInfo->HandleEntry ? STATUS_ALERTED
282  : STATUS_PENDING);
283  goto Quit;
284  }
285 
286  /*
287  * If we go there, that means we are notified for some new input.
288  * The console is therefore already locked.
289  */
290  Status = ReadChars(InputInfo, WaitApiMessage, FALSE);
291 
292 Quit:
293  if (Status != STATUS_PENDING)
294  {
295  WaitApiMessage->Status = Status;
296  ConsoleFreeHeap(InputInfo);
297  }
298 
299  return (Status == STATUS_PENDING ? FALSE : TRUE);
300 }
#define TRUE
Definition: types.h:120
PVOID HandleEntry
Definition: coninput.c:47
#define STATUS_THREAD_IS_TERMINATING
Definition: ntstatus.h:297
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_ALERTED
Definition: ntstatus.h:80
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define STATUS_PENDING
Definition: ntstatus.h:82
Status
Definition: gdiplustypes.h:24
HANDLE InputHandle
Definition: apc.c:9
#define ConsoleFreeHeap(HeapBase)
Definition: heap.h:15
struct _GET_INPUT_INFO * PGET_INPUT_INFO
static NTSTATUS ReadChars(IN PGET_INPUT_INFO InputInfo, IN PCSR_API_MESSAGE ApiMessage, IN BOOLEAN CreateWaitBlock OPTIONAL)
Definition: coninput.c:312

Referenced by ReadChars().

◆ ReadInputBuffer()

static NTSTATUS ReadInputBuffer ( IN PGET_INPUT_INFO  InputInfo,
IN PCSR_API_MESSAGE  ApiMessage,
IN BOOLEAN CreateWaitBlock  OPTIONAL 
)
static

Definition at line 475 of file coninput.c.

478 {
480  PCONSOLE_GETINPUT GetInputRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetInputRequest;
481  PCONSOLE_INPUT_BUFFER InputBuffer = InputInfo->InputBuffer;
482  ULONG NumEventsRead;
483 
484  PINPUT_RECORD InputRecord;
485 
486  /*
487  * For optimization purposes, Windows (and hence ReactOS, too, for
488  * compatibility reasons) uses a static buffer if no more than five
489  * input records are read. Otherwise a new buffer is used.
490  * The client-side expects that we know this behaviour.
491  */
492  if (GetInputRequest->NumRecords <= sizeof(GetInputRequest->RecordStaticBuffer)/sizeof(INPUT_RECORD))
493  {
494  /*
495  * Adjust the internal pointer, because its old value points to
496  * the static buffer in the original ApiMessage structure.
497  */
498  // GetInputRequest->RecordBufPtr = GetInputRequest->RecordStaticBuffer;
499  InputRecord = GetInputRequest->RecordStaticBuffer;
500  }
501  else
502  {
503  InputRecord = GetInputRequest->RecordBufPtr;
504  }
505 
506  NumEventsRead = 0;
507  Status = ConDrvGetConsoleInput(InputBuffer->Header.Console,
508  InputBuffer,
509  (GetInputRequest->Flags & CONSOLE_READ_KEEPEVENT) != 0,
510  (GetInputRequest->Flags & CONSOLE_READ_CONTINUE ) == 0,
511  InputRecord,
512  GetInputRequest->NumRecords,
513  &NumEventsRead);
514 
515  if (Status == STATUS_PENDING)
516  {
517  /* We haven't completed a read, so start a wait */
518  return WaitBeforeReading(InputInfo,
519  ApiMessage,
521  CreateWaitBlock);
522  }
523  else
524  {
525  /*
526  * We read all what we wanted. Set the number of events read and
527  * return the error code we were given.
528  */
529  GetInputRequest->NumRecords = NumEventsRead;
530 
531  if (NT_SUCCESS(Status))
532  {
533  /* Now translate everything to ANSI */
534  if (!GetInputRequest->Unicode)
535  {
536  for (; NumEventsRead > 0; --NumEventsRead)
537  {
538  ConioInputEventToAnsi(InputBuffer->Header.Console, --InputRecord);
539  }
540  }
541  }
542 
543  return Status;
544  // return STATUS_SUCCESS;
545  }
546 }
ULONG NumRecords
Definition: conmsg.h:568
struct _CONSOLE_API_MESSAGE * PCONSOLE_API_MESSAGE
LONG NTSTATUS
Definition: precomp.h:26
INPUT_RECORD RecordStaticBuffer[5]
Definition: conmsg.h:566
CHAR InputBuffer[80]
Definition: conmgr.c:33
static VOID ConioInputEventToAnsi(PCONSOLE Console, PINPUT_RECORD InputEvent)
Definition: coninput.c:55
static NTSTATUS WaitBeforeReading(IN PGET_INPUT_INFO InputInfo, IN PCSR_API_MESSAGE ApiMessage, IN CSR_WAIT_FUNCTION WaitFunction OPTIONAL, IN BOOLEAN CreateWaitBlock OPTIONAL)
Definition: coninput.c:208
static BOOLEAN NTAPI ReadInputBufferThread(IN PLIST_ENTRY WaitList, IN PCSR_THREAD WaitThread, IN PCSR_API_MESSAGE WaitApiMessage, IN PVOID WaitContext, IN PVOID WaitArgument1, IN PVOID WaitArgument2, IN ULONG WaitFlags)
Definition: coninput.c:410
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
PINPUT_RECORD RecordBufPtr
Definition: conmsg.h:567
#define CONSOLE_READ_KEEPEVENT
Definition: wincon.h:116
Status
Definition: gdiplustypes.h:24
BOOLEAN Unicode
Definition: conmsg.h:570
#define CONSOLE_READ_CONTINUE
Definition: wincon.h:117
unsigned int ULONG
Definition: retypes.h:1
NTSTATUS NTAPI ConDrvGetConsoleInput(IN PCONSOLE Console, IN PCONSOLE_INPUT_BUFFER InputBuffer, IN BOOLEAN KeepEvents, IN BOOLEAN WaitForMoreEvents, OUT PINPUT_RECORD InputRecord, IN ULONG NumEventsToRead, OUT PULONG NumEventsRead OPTIONAL)
Definition: coninput.c:260
struct _INPUT_RECORD INPUT_RECORD

Referenced by CSR_API(), and ReadInputBufferThread().

◆ ReadInputBufferThread()

static BOOLEAN NTAPI ReadInputBufferThread ( IN PLIST_ENTRY  WaitList,
IN PCSR_THREAD  WaitThread,
IN PCSR_API_MESSAGE  WaitApiMessage,
IN PVOID  WaitContext,
IN PVOID  WaitArgument1,
IN PVOID  WaitArgument2,
IN ULONG  WaitFlags 
)
static

Definition at line 410 of file coninput.c.

417 {
419  PGET_INPUT_INFO InputInfo = (PGET_INPUT_INFO)WaitContext;
420 
421  PVOID InputHandle = WaitArgument2;
422 
423  DPRINT("ReadInputBufferThread - WaitContext = 0x%p, WaitArgument1 = 0x%p, WaitArgument2 = 0x%p, WaitFlags = %lu\n", WaitContext, WaitArgument1, WaitArgument2, WaitFlags);
424 
425  /*
426  * If we are notified of the process termination via a call
427  * to CsrNotifyWaitBlock triggered by CsrDestroyProcess or
428  * CsrDestroyThread, just return.
429  */
430  if (WaitFlags & CsrProcessTerminating)
431  {
433  goto Quit;
434  }
435 
436  /*
437  * Somebody is closing a handle to this input buffer,
438  * by calling ConSrvCloseHandleEntry.
439  * See whether we are linked to that handle (ie. we
440  * are a waiter for this handle), and if so, return.
441  * Otherwise, ignore the call and continue waiting.
442  */
443  if (InputHandle != NULL)
444  {
445  Status = (InputHandle == InputInfo->HandleEntry ? STATUS_ALERTED
446  : STATUS_PENDING);
447  goto Quit;
448  }
449 
450  /*
451  * If we go there, that means we are notified for some new input.
452  * The console is therefore already locked.
453  */
454  Status = ReadInputBuffer(InputInfo, WaitApiMessage, FALSE);
455 
456 Quit:
457  if (Status != STATUS_PENDING)
458  {
459  WaitApiMessage->Status = Status;
460  ConsoleFreeHeap(InputInfo);
461  }
462 
463  return (Status == STATUS_PENDING ? FALSE : TRUE);
464 }
#define TRUE
Definition: types.h:120
PVOID HandleEntry
Definition: coninput.c:47
#define STATUS_THREAD_IS_TERMINATING
Definition: ntstatus.h:297
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_ALERTED
Definition: ntstatus.h:80
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define STATUS_PENDING
Definition: ntstatus.h:82
Status
Definition: gdiplustypes.h:24
HANDLE InputHandle
Definition: apc.c:9
#define ConsoleFreeHeap(HeapBase)
Definition: heap.h:15
static NTSTATUS ReadInputBuffer(IN PGET_INPUT_INFO InputInfo, IN PCSR_API_MESSAGE ApiMessage, IN BOOLEAN CreateWaitBlock OPTIONAL)
Definition: coninput.c:475
struct _GET_INPUT_INFO * PGET_INPUT_INFO

Referenced by ReadInputBuffer().

◆ WaitBeforeReading()

static NTSTATUS WaitBeforeReading ( IN PGET_INPUT_INFO  InputInfo,
IN PCSR_API_MESSAGE  ApiMessage,
IN CSR_WAIT_FUNCTION WaitFunction  OPTIONAL,
IN BOOLEAN CreateWaitBlock  OPTIONAL 
)
static

Definition at line 208 of file coninput.c.

212 {
213  if (CreateWaitBlock)
214  {
215  PGET_INPUT_INFO CapturedInputInfo;
216  PCONSRV_CONSOLE Console = (PCONSRV_CONSOLE)InputInfo->InputBuffer->Header.Console;
217 
218  CapturedInputInfo = ConsoleAllocHeap(0, sizeof(GET_INPUT_INFO));
219  if (!CapturedInputInfo) return STATUS_NO_MEMORY;
220 
221  RtlMoveMemory(CapturedInputInfo, InputInfo, sizeof(GET_INPUT_INFO));
222 
223  if (!CsrCreateWait(&Console->ReadWaitQueue,
224  WaitFunction,
225  InputInfo->CallingThread,
226  ApiMessage,
227  CapturedInputInfo))
228  {
229  ConsoleFreeHeap(CapturedInputInfo);
230  return STATUS_NO_MEMORY;
231  }
232  }
233 
234  /* Wait for input */
235  return STATUS_PENDING;
236 }
#define ConsoleAllocHeap(Flags, Size)
Definition: heap.h:14
#define PCONSRV_CONSOLE
Definition: conio.h:27
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define STATUS_PENDING
Definition: ntstatus.h:82
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
CConsole Console
#define ConsoleFreeHeap(HeapBase)
Definition: heap.h:15
BOOLEAN NTAPI CsrCreateWait(IN PLIST_ENTRY WaitList, IN CSR_WAIT_FUNCTION WaitFunction, IN PCSR_THREAD CsrWaitThread, IN OUT PCSR_API_MESSAGE WaitApiMessage, IN PVOID WaitContext)
Definition: wait.c:209

Referenced by ReadChars(), and ReadInputBuffer().