PCONSOLE_READCONSOLE_CONTROL pInputControl,
BOOL bUnicode)
{
- NTSTATUS Status;
CONSOLE_API_MESSAGE ApiMessage;
PCONSOLE_READCONSOLE ReadConsoleRequest = &ApiMessage.Data.ReadConsoleRequest;
PCSR_CAPTURE_BUFFER CaptureBuffer;
* For ANSI mode, set this parameter to NULL."
*/
ReadConsoleRequest->NrCharactersRead = pInputControl->nInitialChars;
- memcpy(ReadConsoleRequest->Buffer,
- lpBuffer,
- pInputControl->nInitialChars * sizeof(WCHAR));
+ RtlCopyMemory(ReadConsoleRequest->Buffer,
+ lpBuffer,
+ pInputControl->nInitialChars * sizeof(WCHAR));
ReadConsoleRequest->CtrlWakeupMask = pInputControl->dwCtrlWakeupMask;
}
/* Call the server */
- Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
- CaptureBuffer,
- CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepReadConsole),
- sizeof(CONSOLE_READCONSOLE));
+ CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+ CaptureBuffer,
+ CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepReadConsole),
+ sizeof(*ReadConsoleRequest));
/* Check for success */
- if (NT_SUCCESS(Status))
+ if (NT_SUCCESS(ApiMessage.Status))
{
- memcpy(lpBuffer,
- ReadConsoleRequest->Buffer,
- ReadConsoleRequest->NrCharactersRead * CharSize);
+ RtlCopyMemory(lpBuffer,
+ ReadConsoleRequest->Buffer,
+ ReadConsoleRequest->NrCharactersRead * CharSize);
if (lpNumberOfCharsRead != NULL)
*lpNumberOfCharsRead = ReadConsoleRequest->NrCharactersRead;
*lpNumberOfCharsRead = 0;
/* Error out */
- BaseSetLastNTError(Status);
+ BaseSetLastNTError(ApiMessage.Status);
}
CsrFreeCaptureBuffer(CaptureBuffer);
/* Return TRUE or FALSE */
// return TRUE;
return (ReadConsoleRequest->NrCharactersRead > 0);
- // return NT_SUCCESS(Status);
+ // return NT_SUCCESS(ApiMessage.Status);
}
static
BOOL
-IntGetConsoleInput(HANDLE hConsoleInput,
- PINPUT_RECORD lpBuffer,
- DWORD nLength,
- LPDWORD lpNumberOfEventsRead,
- WORD wFlags,
- BOOLEAN bUnicode)
+IntGetConsoleInput(IN HANDLE hConsoleInput,
+ OUT PINPUT_RECORD lpBuffer,
+ IN DWORD nLength,
+ OUT LPDWORD lpNumberOfEventsRead,
+ IN WORD wFlags,
+ IN BOOLEAN bUnicode)
{
- NTSTATUS Status;
+ BOOL Success;
CONSOLE_API_MESSAGE ApiMessage;
PCONSOLE_GETINPUT GetInputRequest = &ApiMessage.Data.GetInputRequest;
- PCSR_CAPTURE_BUFFER CaptureBuffer;
- ULONG Size;
+ PCSR_CAPTURE_BUFFER CaptureBuffer = NULL;
- if (lpBuffer == NULL)
+ if (!IsConsoleHandle(hConsoleInput))
{
- SetLastError(ERROR_INVALID_PARAMETER);
+ _SEH2_TRY
+ {
+ *lpNumberOfEventsRead = 0;
+ SetLastError(ERROR_INVALID_HANDLE);
+ }
+ _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
+ {
+ SetLastError(ERROR_INVALID_ACCESS);
+ }
+ _SEH2_END;
+
return FALSE;
}
- Size = nLength * sizeof(INPUT_RECORD);
+ DPRINT("IntGetConsoleInput: %lx %p\n", nLength, lpNumberOfEventsRead);
- DPRINT("IntGetConsoleInput: %lx %p\n", Size, lpNumberOfEventsRead);
+ /* Set up the data to send to the Console Server */
+ GetInputRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
+ GetInputRequest->InputHandle = hConsoleInput;
+ GetInputRequest->NumRecords = nLength;
+ GetInputRequest->Flags = wFlags;
+ GetInputRequest->Unicode = bUnicode;
- /* Allocate a Capture Buffer */
- CaptureBuffer = CsrAllocateCaptureBuffer(1, Size);
- if (CaptureBuffer == NULL)
+ /*
+ * For optimization purposes, Windows (and hence ReactOS, too, for
+ * compatibility reasons) uses a static buffer if no more than five
+ * input records are read. Otherwise a new buffer is allocated.
+ * This behaviour is also expected in the server-side.
+ */
+ if (nLength <= sizeof(GetInputRequest->RecordStaticBuffer)/sizeof(INPUT_RECORD))
{
- DPRINT1("CsrAllocateCaptureBuffer failed!\n");
- SetLastError(ERROR_NOT_ENOUGH_MEMORY);
- return FALSE;
+ GetInputRequest->RecordBufPtr = GetInputRequest->RecordStaticBuffer;
+ // CaptureBuffer = NULL;
}
+ else
+ {
+ ULONG Size = nLength * sizeof(INPUT_RECORD);
+
+ /* Allocate a Capture Buffer */
+ CaptureBuffer = CsrAllocateCaptureBuffer(1, Size);
+ if (CaptureBuffer == NULL)
+ {
+ DPRINT1("CsrAllocateCaptureBuffer failed!\n");
+ SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+ return FALSE;
+ }
- /* Allocate space in the Buffer */
- CsrAllocateMessagePointer(CaptureBuffer,
- Size,
- (PVOID*)&GetInputRequest->InputRecord);
-
- /* Set up the data to send to the Console Server */
- GetInputRequest->InputHandle = hConsoleInput;
- GetInputRequest->InputsRead = 0;
- GetInputRequest->Length = nLength;
- GetInputRequest->wFlags = wFlags;
- GetInputRequest->Unicode = bUnicode;
+ /* Allocate space in the Buffer */
+ CsrAllocateMessagePointer(CaptureBuffer,
+ Size,
+ (PVOID*)&GetInputRequest->RecordBufPtr);
+ }
/* Call the server */
- Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
- CaptureBuffer,
- CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetConsoleInput),
- sizeof(CONSOLE_GETINPUT));
- DPRINT("Server returned: %x\n", Status);
+ CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+ CaptureBuffer,
+ CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetConsoleInput),
+ sizeof(*GetInputRequest));
/* Check for success */
- if (NT_SUCCESS(Status))
- {
- /* Return the number of events read */
- DPRINT("Events read: %lx\n", GetInputRequest->InputsRead);
-
- if (lpNumberOfEventsRead != NULL)
- *lpNumberOfEventsRead = GetInputRequest->InputsRead;
+ Success = NT_SUCCESS(ApiMessage.Status);
- /* Copy into the buffer */
- DPRINT("Copying to buffer\n");
- RtlCopyMemory(lpBuffer,
- GetInputRequest->InputRecord,
- sizeof(INPUT_RECORD) * GetInputRequest->InputsRead);
+ /* Retrieve the results */
+ _SEH2_TRY
+ {
+ DPRINT("Events read: %lx\n", GetInputRequest->NumRecords);
+ *lpNumberOfEventsRead = GetInputRequest->NumRecords;
+
+ if (Success)
+ {
+ RtlCopyMemory(lpBuffer,
+ GetInputRequest->RecordBufPtr,
+ GetInputRequest->NumRecords * sizeof(INPUT_RECORD));
+ }
+ else
+ {
+ BaseSetLastNTError(ApiMessage.Status);
+ }
}
- else
+ _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
- if (lpNumberOfEventsRead != NULL)
- *lpNumberOfEventsRead = 0;
-
- /* Error out */
- BaseSetLastNTError(Status);
+ SetLastError(ERROR_INVALID_ACCESS);
+ Success = FALSE;
}
+ _SEH2_END;
- /* Release the capture buffer */
- CsrFreeCaptureBuffer(CaptureBuffer);
+ /* Release the capture buffer if needed */
+ if (CaptureBuffer) CsrFreeCaptureBuffer(CaptureBuffer);
- /* Return TRUE or FALSE */
- return (GetInputRequest->InputsRead > 0);
- // return NT_SUCCESS(Status);
+ /* Return success status */
+ return Success;
}
if (lpBuffer == NULL)
{
- SetLastError(ERROR_INVALID_PARAMETER);
+ SetLastError(ERROR_INVALID_ACCESS);
return FALSE;
}
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
CaptureBuffer,
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepReadConsoleOutput),
- sizeof(CONSOLE_READOUTPUT));
- DPRINT("Server returned: %x\n", ApiMessage.Status);
+ sizeof(*ReadOutputRequest));
/* Check for success */
if (NT_SUCCESS(ApiMessage.Status))
static
BOOL
-IntReadConsoleOutputCode(HANDLE hConsoleOutput,
- CODE_TYPE CodeType,
- PVOID pCode,
- DWORD nLength,
- COORD dwReadCoord,
- LPDWORD lpNumberOfCodesRead)
+IntReadConsoleOutputCode(IN HANDLE hConsoleOutput,
+ IN CODE_TYPE CodeType,
+ OUT PVOID pCode,
+ IN DWORD nLength,
+ IN COORD dwReadCoord,
+ OUT LPDWORD lpNumberOfCodesRead)
{
- NTSTATUS Status;
- BOOL bRet = TRUE;
+ BOOL Success;
CONSOLE_API_MESSAGE ApiMessage;
PCONSOLE_READOUTPUTCODE ReadOutputCodeRequest = &ApiMessage.Data.ReadOutputCodeRequest;
- PCSR_CAPTURE_BUFFER CaptureBuffer;
+ PCSR_CAPTURE_BUFFER CaptureBuffer = NULL;
ULONG SizeBytes, CodeSize;
- DWORD CodesRead;
+
+ DPRINT("IntReadConsoleOutputCode\n");
+
+ if ( (CodeType != CODE_ASCII ) &&
+ (CodeType != CODE_UNICODE ) &&
+ (CodeType != CODE_ATTRIBUTE) )
+ {
+ SetLastError(ERROR_INVALID_PARAMETER);
+ return FALSE;
+ }
+
+ /* Set up the data to send to the Console Server */
+ ReadOutputCodeRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
+ ReadOutputCodeRequest->OutputHandle = hConsoleOutput;
+ ReadOutputCodeRequest->Coord = dwReadCoord;
+ ReadOutputCodeRequest->NumCodes = nLength;
/* Determine the needed size */
+ ReadOutputCodeRequest->CodeType = CodeType;
switch (CodeType)
{
case CODE_ASCII:
- CodeSize = sizeof(CHAR);
+ CodeSize = RTL_FIELD_SIZE(CODE_ELEMENT, AsciiChar);
break;
case CODE_UNICODE:
- CodeSize = sizeof(WCHAR);
+ CodeSize = RTL_FIELD_SIZE(CODE_ELEMENT, UnicodeChar);
break;
case CODE_ATTRIBUTE:
- CodeSize = sizeof(WORD);
+ CodeSize = RTL_FIELD_SIZE(CODE_ELEMENT, Attribute);
break;
-
- default:
- SetLastError(ERROR_INVALID_PARAMETER);
- return FALSE;
}
SizeBytes = nLength * CodeSize;
- /* Allocate a Capture Buffer */
- CaptureBuffer = CsrAllocateCaptureBuffer(1, SizeBytes);
- if (CaptureBuffer == NULL)
+ /*
+ * For optimization purposes, Windows (and hence ReactOS, too, for
+ * compatibility reasons) uses a static buffer if no more than eighty
+ * bytes are read. Otherwise a new buffer is allocated.
+ * This behaviour is also expected in the server-side.
+ */
+ if (SizeBytes <= sizeof(ReadOutputCodeRequest->CodeStaticBuffer))
{
- DPRINT1("CsrAllocateCaptureBuffer failed!\n");
- SetLastError(ERROR_NOT_ENOUGH_MEMORY);
- return FALSE;
+ ReadOutputCodeRequest->pCode = ReadOutputCodeRequest->CodeStaticBuffer;
+ // CaptureBuffer = NULL;
}
+ else
+ {
+ /* Allocate a Capture Buffer */
+ CaptureBuffer = CsrAllocateCaptureBuffer(1, SizeBytes);
+ if (CaptureBuffer == NULL)
+ {
+ DPRINT1("CsrAllocateCaptureBuffer failed!\n");
+ SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+ return FALSE;
+ }
- /* Allocate space in the Buffer */
- CsrAllocateMessagePointer(CaptureBuffer,
- SizeBytes,
- (PVOID*)&ReadOutputCodeRequest->pCode.pCode);
-
- /* Start reading */
- ReadOutputCodeRequest->OutputHandle = hConsoleOutput;
- ReadOutputCodeRequest->CodeType = CodeType;
- ReadOutputCodeRequest->ReadCoord = dwReadCoord;
-
- ReadOutputCodeRequest->NumCodesToRead = nLength;
+ /* Allocate space in the Buffer */
+ CsrAllocateMessagePointer(CaptureBuffer,
+ SizeBytes,
+ (PVOID*)&ReadOutputCodeRequest->pCode);
+ }
/* Call the server */
- Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
- CaptureBuffer,
- CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepReadConsoleOutputString),
- sizeof(CONSOLE_READOUTPUTCODE));
+ CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+ CaptureBuffer,
+ CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepReadConsoleOutputString),
+ sizeof(*ReadOutputCodeRequest));
/* Check for success */
- if (NT_SUCCESS(Status))
- {
- CodesRead = ReadOutputCodeRequest->CodesRead;
- memcpy(pCode, ReadOutputCodeRequest->pCode.pCode, CodesRead * CodeSize);
+ Success = NT_SUCCESS(ApiMessage.Status);
- // ReadOutputCodeRequest->ReadCoord = ReadOutputCodeRequest->EndCoord;
-
- if (lpNumberOfCodesRead != NULL)
- *lpNumberOfCodesRead = CodesRead;
-
- bRet = TRUE;
+ /* Retrieve the results */
+ _SEH2_TRY
+ {
+ *lpNumberOfCodesRead = ReadOutputCodeRequest->NumCodes;
+
+ if (Success)
+ {
+ RtlCopyMemory(pCode,
+ ReadOutputCodeRequest->pCode,
+ ReadOutputCodeRequest->NumCodes * CodeSize);
+ }
+ else
+ {
+ BaseSetLastNTError(ApiMessage.Status);
+ }
}
- else
+ _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
- if (lpNumberOfCodesRead != NULL)
- *lpNumberOfCodesRead = 0;
-
- /* Error out */
- BaseSetLastNTError(Status);
- bRet = FALSE;
+ SetLastError(ERROR_INVALID_ACCESS);
+ Success = FALSE;
}
+ _SEH2_END;
- CsrFreeCaptureBuffer(CaptureBuffer);
+ /* Release the capture buffer if needed */
+ if (CaptureBuffer) CsrFreeCaptureBuffer(CaptureBuffer);
- return bRet;
+ /* Return success status */
+ return Success;
}
LPVOID lpReserved,
BOOL bUnicode)
{
- NTSTATUS Status;
BOOL bRet = TRUE;
CONSOLE_API_MESSAGE ApiMessage;
PCONSOLE_WRITECONSOLE WriteConsoleRequest = &ApiMessage.Data.WriteConsoleRequest;
WriteConsoleRequest->Unicode = bUnicode;
/* Call the server */
- Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
- CaptureBuffer,
- CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepWriteConsole),
- sizeof(CONSOLE_WRITECONSOLE));
+ CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+ CaptureBuffer,
+ CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepWriteConsole),
+ sizeof(*WriteConsoleRequest));
/* Check for success */
- if (NT_SUCCESS(Status))
+ if (NT_SUCCESS(ApiMessage.Status))
{
if (lpNumberOfCharsWritten != NULL)
*lpNumberOfCharsWritten = WriteConsoleRequest->NrCharactersWritten;
*lpNumberOfCharsWritten = 0;
/* Error out */
- BaseSetLastNTError(Status);
+ BaseSetLastNTError(ApiMessage.Status);
bRet = FALSE;
}
static
BOOL
-IntWriteConsoleInput(HANDLE hConsoleInput,
- PINPUT_RECORD lpBuffer,
- DWORD nLength,
- LPDWORD lpNumberOfEventsWritten,
- BOOL bUnicode,
- BOOL bAppendToEnd)
+IntWriteConsoleInput(IN HANDLE hConsoleInput,
+ IN PINPUT_RECORD lpBuffer,
+ IN DWORD nLength,
+ OUT LPDWORD lpNumberOfEventsWritten,
+ IN BOOLEAN bUnicode,
+ IN BOOLEAN bAppendToEnd)
{
+ BOOL Success;
CONSOLE_API_MESSAGE ApiMessage;
PCONSOLE_WRITEINPUT WriteInputRequest = &ApiMessage.Data.WriteInputRequest;
- PCSR_CAPTURE_BUFFER CaptureBuffer;
- DWORD Size;
+ PCSR_CAPTURE_BUFFER CaptureBuffer = NULL;
- Size = nLength * sizeof(INPUT_RECORD);
+ DPRINT("IntWriteConsoleInput: %lx %p\n", nLength, lpNumberOfEventsWritten);
- DPRINT("IntWriteConsoleInput: %lx %p\n", Size, lpNumberOfEventsWritten);
+ /* Set up the data to send to the Console Server */
+ WriteInputRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
+ WriteInputRequest->InputHandle = hConsoleInput;
+ WriteInputRequest->NumRecords = nLength;
+ WriteInputRequest->Unicode = bUnicode;
+ WriteInputRequest->AppendToEnd = bAppendToEnd;
- /* Allocate a Capture Buffer */
- CaptureBuffer = CsrAllocateCaptureBuffer(1, Size);
- if (CaptureBuffer == NULL)
+ /*
+ * For optimization purposes, Windows (and hence ReactOS, too, for
+ * compatibility reasons) uses a static buffer if no more than five
+ * input records are written. Otherwise a new buffer is allocated.
+ * This behaviour is also expected in the server-side.
+ */
+ if (nLength <= sizeof(WriteInputRequest->RecordStaticBuffer)/sizeof(INPUT_RECORD))
{
- DPRINT1("CsrAllocateCaptureBuffer failed!\n");
- SetLastError(ERROR_NOT_ENOUGH_MEMORY);
- return FALSE;
- }
+ WriteInputRequest->RecordBufPtr = WriteInputRequest->RecordStaticBuffer;
+ // CaptureBuffer = NULL;
- /* Capture the user buffer */
- CsrCaptureMessageBuffer(CaptureBuffer,
- lpBuffer,
- Size,
- (PVOID*)&WriteInputRequest->InputRecord);
+ _SEH2_TRY
+ {
+ RtlCopyMemory(WriteInputRequest->RecordBufPtr,
+ lpBuffer,
+ nLength * sizeof(INPUT_RECORD));
+ }
+ _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
+ {
+ SetLastError(ERROR_INVALID_ACCESS);
+ return FALSE;
+ }
+ _SEH2_END;
+ }
+ else
+ {
+ ULONG Size = nLength * sizeof(INPUT_RECORD);
+
+ /* Allocate a Capture Buffer */
+ CaptureBuffer = CsrAllocateCaptureBuffer(1, Size);
+ if (CaptureBuffer == NULL)
+ {
+ DPRINT1("CsrAllocateCaptureBuffer failed!\n");
+ SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+ return FALSE;
+ }
- /* Set up the data to send to the Console Server */
- WriteInputRequest->InputHandle = hConsoleInput;
- WriteInputRequest->Length = nLength;
- WriteInputRequest->Unicode = bUnicode;
- WriteInputRequest->AppendToEnd = bAppendToEnd;
+ /* Capture the user buffer */
+ CsrCaptureMessageBuffer(CaptureBuffer,
+ lpBuffer,
+ Size,
+ (PVOID*)&WriteInputRequest->RecordBufPtr);
+ }
/* Call the server */
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
CaptureBuffer,
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepWriteConsoleInput),
- sizeof(CONSOLE_WRITEINPUT));
- DPRINT("Server returned: %x\n", ApiMessage.Status);
+ sizeof(*WriteInputRequest));
/* Check for success */
- if (NT_SUCCESS(ApiMessage.Status))
+ Success = NT_SUCCESS(ApiMessage.Status);
+
+ /* Release the capture buffer if needed */
+ if (CaptureBuffer) CsrFreeCaptureBuffer(CaptureBuffer);
+
+ /* Retrieve the results */
+ _SEH2_TRY
{
- /* Return the number of events read */
- DPRINT("Events read: %lx\n", WriteInputRequest->Length);
+ DPRINT("Events written: %lx\n", WriteInputRequest->NumRecords);
+ *lpNumberOfEventsWritten = WriteInputRequest->NumRecords;
- if (lpNumberOfEventsWritten != NULL)
- *lpNumberOfEventsWritten = WriteInputRequest->Length;
+ if (!Success)
+ BaseSetLastNTError(ApiMessage.Status);
}
- else
+ _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
- if (lpNumberOfEventsWritten != NULL)
- *lpNumberOfEventsWritten = 0;
-
- /* Error out */
- BaseSetLastNTError(ApiMessage.Status);
+ SetLastError(ERROR_INVALID_ACCESS);
+ Success = FALSE;
}
+ _SEH2_END;
- /* Release the capture buffer */
- CsrFreeCaptureBuffer(CaptureBuffer);
-
- /* Return TRUE or FALSE */
- return NT_SUCCESS(ApiMessage.Status);
+ /* Return success status */
+ return Success;
}
if ((lpBuffer == NULL) || (lpWriteRegion == NULL))
{
- SetLastError(ERROR_INVALID_PARAMETER);
+ SetLastError(ERROR_INVALID_ACCESS);
return FALSE;
}
/*
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
CaptureBuffer,
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepWriteConsoleOutput),
- sizeof(CONSOLE_WRITEOUTPUT));
- DPRINT("Server returned: %x\n", ApiMessage.Status);
+ sizeof(*WriteOutputRequest));
/* Check for success */
if (!NT_SUCCESS(ApiMessage.Status))
static
BOOL
-IntWriteConsoleOutputCode(HANDLE hConsoleOutput,
- CODE_TYPE CodeType,
- CONST VOID *pCode,
- DWORD nLength,
- COORD dwWriteCoord,
- LPDWORD lpNumberOfCodesWritten)
+IntWriteConsoleOutputCode(IN HANDLE hConsoleOutput,
+ IN CODE_TYPE CodeType,
+ IN CONST VOID *pCode,
+ IN DWORD nLength,
+ IN COORD dwWriteCoord,
+ OUT LPDWORD lpNumberOfCodesWritten)
{
- NTSTATUS Status;
- BOOL bRet = TRUE;
+ BOOL Success;
CONSOLE_API_MESSAGE ApiMessage;
PCONSOLE_WRITEOUTPUTCODE WriteOutputCodeRequest = &ApiMessage.Data.WriteOutputCodeRequest;
- PCSR_CAPTURE_BUFFER CaptureBuffer;
- ULONG CodeSize;
+ PCSR_CAPTURE_BUFFER CaptureBuffer = NULL;
+ ULONG SizeBytes, CodeSize;
+
+ if ( (CodeType != CODE_ASCII ) &&
+ (CodeType != CODE_UNICODE ) &&
+ (CodeType != CODE_ATTRIBUTE) )
+ {
+ SetLastError(ERROR_INVALID_PARAMETER);
+ return FALSE;
+ }
+
+ DPRINT("IntWriteConsoleOutputCode\n");
+
+ /* Set up the data to send to the Console Server */
+ WriteOutputCodeRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
+ WriteOutputCodeRequest->OutputHandle = hConsoleOutput;
+ WriteOutputCodeRequest->Coord = dwWriteCoord;
+ WriteOutputCodeRequest->NumCodes = nLength;
/* Determine the needed size */
+ WriteOutputCodeRequest->CodeType = CodeType;
switch (CodeType)
{
case CODE_ASCII:
- CodeSize = sizeof(CHAR);
+ CodeSize = RTL_FIELD_SIZE(CODE_ELEMENT, AsciiChar);
break;
case CODE_UNICODE:
- CodeSize = sizeof(WCHAR);
+ CodeSize = RTL_FIELD_SIZE(CODE_ELEMENT, UnicodeChar);
break;
case CODE_ATTRIBUTE:
- CodeSize = sizeof(WORD);
+ CodeSize = RTL_FIELD_SIZE(CODE_ELEMENT, Attribute);
break;
-
- default:
- SetLastError(ERROR_INVALID_PARAMETER);
- return FALSE;
}
- WriteOutputCodeRequest->BufferSize = nLength * CodeSize;
+ SizeBytes = nLength * CodeSize;
- /* Allocate a Capture Buffer */
- CaptureBuffer = CsrAllocateCaptureBuffer(1, WriteOutputCodeRequest->BufferSize);
- if (CaptureBuffer == NULL)
+ /*
+ * For optimization purposes, Windows (and hence ReactOS, too, for
+ * compatibility reasons) uses a static buffer if no more than eighty
+ * bytes are written. Otherwise a new buffer is allocated.
+ * This behaviour is also expected in the server-side.
+ */
+ if (SizeBytes <= sizeof(WriteOutputCodeRequest->CodeStaticBuffer))
{
- DPRINT1("CsrAllocateCaptureBuffer failed!\n");
- SetLastError(ERROR_NOT_ENOUGH_MEMORY);
- return FALSE;
+ WriteOutputCodeRequest->pCode = WriteOutputCodeRequest->CodeStaticBuffer;
+ // CaptureBuffer = NULL;
+
+ _SEH2_TRY
+ {
+ RtlCopyMemory(WriteOutputCodeRequest->pCode,
+ pCode,
+ SizeBytes);
+ }
+ _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
+ {
+ SetLastError(ERROR_INVALID_ACCESS);
+ return FALSE;
+ }
+ _SEH2_END;
}
+ else
+ {
+ /* Allocate a Capture Buffer */
+ CaptureBuffer = CsrAllocateCaptureBuffer(1, SizeBytes);
+ if (CaptureBuffer == NULL)
+ {
+ DPRINT1("CsrAllocateCaptureBuffer failed!\n");
+ SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+ return FALSE;
+ }
- /* Capture the buffer to write */
- CsrCaptureMessageBuffer(CaptureBuffer,
- (PVOID)pCode,
- WriteOutputCodeRequest->BufferSize,
- (PVOID*)&WriteOutputCodeRequest->pCode.pCode);
-
- /* Start writing */
- WriteOutputCodeRequest->OutputHandle = hConsoleOutput;
- WriteOutputCodeRequest->CodeType = CodeType;
- WriteOutputCodeRequest->Coord = dwWriteCoord;
-
- WriteOutputCodeRequest->Length = (USHORT)nLength;
+ /* Capture the buffer to write */
+ CsrCaptureMessageBuffer(CaptureBuffer,
+ (PVOID)pCode,
+ SizeBytes,
+ (PVOID*)&WriteOutputCodeRequest->pCode);
+ }
/* Call the server */
- Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
- CaptureBuffer,
- CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepWriteConsoleOutputString),
- sizeof(CONSOLE_WRITEOUTPUTCODE));
+ CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+ CaptureBuffer,
+ CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepWriteConsoleOutputString),
+ sizeof(*WriteOutputCodeRequest));
/* Check for success */
- if (NT_SUCCESS(Status))
- {
- // WriteOutputCodeRequest->Coord = WriteOutputCodeRequest->EndCoord;
+ Success = NT_SUCCESS(ApiMessage.Status);
- if (lpNumberOfCodesWritten != NULL)
- // *lpNumberOfCodesWritten = WriteOutputCodeRequest->NrCharactersWritten;
- *lpNumberOfCodesWritten = WriteOutputCodeRequest->Length;
+ /* Release the capture buffer if needed */
+ if (CaptureBuffer) CsrFreeCaptureBuffer(CaptureBuffer);
- bRet = TRUE;
- }
- else
+ /* Retrieve the results */
+ _SEH2_TRY
{
- if (lpNumberOfCodesWritten != NULL)
- *lpNumberOfCodesWritten = 0;
+ *lpNumberOfCodesWritten = WriteOutputCodeRequest->NumCodes;
- /* Error out */
- BaseSetLastNTError(Status);
- bRet = FALSE;
+ if (!Success)
+ BaseSetLastNTError(ApiMessage.Status);
}
+ _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
+ {
+ SetLastError(ERROR_INVALID_ACCESS);
+ Success = FALSE;
+ }
+ _SEH2_END;
- CsrFreeCaptureBuffer(CaptureBuffer);
-
- return bRet;
+ /* Return success status */
+ return Success;
}
static
BOOL
-IntFillConsoleOutputCode(HANDLE hConsoleOutput,
- CODE_TYPE CodeType,
- PVOID pCode,
- DWORD nLength,
- COORD dwWriteCoord,
- LPDWORD lpNumberOfCodesWritten)
+IntFillConsoleOutputCode(IN HANDLE hConsoleOutput,
+ IN CODE_TYPE CodeType,
+ IN CODE_ELEMENT Code,
+ IN DWORD nLength,
+ IN COORD dwWriteCoord,
+ OUT LPDWORD lpNumberOfCodesWritten)
{
- NTSTATUS Status;
+ BOOL Success;
CONSOLE_API_MESSAGE ApiMessage;
PCONSOLE_FILLOUTPUTCODE FillOutputRequest = &ApiMessage.Data.FillOutputRequest;
- FillOutputRequest->OutputHandle = hConsoleOutput;
- FillOutputRequest->CodeType = CodeType;
+ DPRINT("IntFillConsoleOutputCode\n");
- switch (CodeType)
+ if ( (CodeType != CODE_ASCII ) &&
+ (CodeType != CODE_UNICODE ) &&
+ (CodeType != CODE_ATTRIBUTE) )
{
- case CODE_ASCII:
- FillOutputRequest->Code.AsciiChar = *(PCHAR)pCode;
- break;
-
- case CODE_UNICODE:
- FillOutputRequest->Code.UnicodeChar = *(PWCHAR)pCode;
- break;
-
- case CODE_ATTRIBUTE:
- FillOutputRequest->Code.Attribute = *(PWORD)pCode;
- break;
-
- default:
- SetLastError(ERROR_INVALID_PARAMETER);
- return FALSE;
+ SetLastError(ERROR_INVALID_PARAMETER);
+ return FALSE;
}
/* Set up the data to send to the Console Server */
- FillOutputRequest->Coord = dwWriteCoord;
- FillOutputRequest->Length = nLength;
+ FillOutputRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
+ FillOutputRequest->OutputHandle = hConsoleOutput;
+ FillOutputRequest->WriteCoord = dwWriteCoord;
+ FillOutputRequest->CodeType = CodeType;
+ FillOutputRequest->Code = Code;
+ FillOutputRequest->NumCodes = nLength;
/* Call the server */
- Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
- NULL,
- CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepFillConsoleOutput),
- sizeof(CONSOLE_FILLOUTPUTCODE));
+ CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+ NULL,
+ CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepFillConsoleOutput),
+ sizeof(*FillOutputRequest));
/* Check for success */
- if (NT_SUCCESS(Status))
+ Success = NT_SUCCESS(ApiMessage.Status);
+
+ /* Retrieve the results */
+ _SEH2_TRY
{
- if (lpNumberOfCodesWritten != NULL)
- *lpNumberOfCodesWritten = FillOutputRequest->Length;
- // *lpNumberOfCodesWritten = Request.Data.FillOutputRequest.NrCharactersWritten;
+ *lpNumberOfCodesWritten = FillOutputRequest->NumCodes;
- return TRUE;
+ if (!Success)
+ BaseSetLastNTError(ApiMessage.Status);
}
- else
+ _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
- if (lpNumberOfCodesWritten != NULL)
- *lpNumberOfCodesWritten = 0;
-
- BaseSetLastNTError(Status);
- return FALSE;
+ SetLastError(ERROR_INVALID_ACCESS);
+ Success = FALSE;
}
+ _SEH2_END;
+
+ /* Return success status */
+ return Success;
}
*/
BOOL
WINAPI
-PeekConsoleInputW(HANDLE hConsoleInput,
- PINPUT_RECORD lpBuffer,
- DWORD nLength,
- LPDWORD lpNumberOfEventsRead)
+PeekConsoleInputW(IN HANDLE hConsoleInput,
+ OUT PINPUT_RECORD lpBuffer,
+ IN DWORD nLength,
+ OUT LPDWORD lpNumberOfEventsRead)
{
return IntGetConsoleInput(hConsoleInput,
lpBuffer,
*/
BOOL
WINAPI
-PeekConsoleInputA(HANDLE hConsoleInput,
- PINPUT_RECORD lpBuffer,
- DWORD nLength,
- LPDWORD lpNumberOfEventsRead)
+PeekConsoleInputA(IN HANDLE hConsoleInput,
+ OUT PINPUT_RECORD lpBuffer,
+ IN DWORD nLength,
+ OUT LPDWORD lpNumberOfEventsRead)
{
return IntGetConsoleInput(hConsoleInput,
lpBuffer,
*/
BOOL
WINAPI
-ReadConsoleInputW(HANDLE hConsoleInput,
- PINPUT_RECORD lpBuffer,
- DWORD nLength,
- LPDWORD lpNumberOfEventsRead)
+ReadConsoleInputW(IN HANDLE hConsoleInput,
+ OUT PINPUT_RECORD lpBuffer,
+ IN DWORD nLength,
+ OUT LPDWORD lpNumberOfEventsRead)
{
return IntGetConsoleInput(hConsoleInput,
lpBuffer,
*/
BOOL
WINAPI
-ReadConsoleInputA(HANDLE hConsoleInput,
- PINPUT_RECORD lpBuffer,
- DWORD nLength,
- LPDWORD lpNumberOfEventsRead)
+ReadConsoleInputA(IN HANDLE hConsoleInput,
+ OUT PINPUT_RECORD lpBuffer,
+ IN DWORD nLength,
+ OUT LPDWORD lpNumberOfEventsRead)
{
return IntGetConsoleInput(hConsoleInput,
lpBuffer,
*/
BOOL
WINAPI
-ReadConsoleInputExW(HANDLE hConsoleInput,
- PINPUT_RECORD lpBuffer,
- DWORD nLength,
- LPDWORD lpNumberOfEventsRead,
- WORD wFlags)
+ReadConsoleInputExW(IN HANDLE hConsoleInput,
+ OUT PINPUT_RECORD lpBuffer,
+ IN DWORD nLength,
+ OUT LPDWORD lpNumberOfEventsRead,
+ IN WORD wFlags)
{
return IntGetConsoleInput(hConsoleInput,
lpBuffer,
*/
BOOL
WINAPI
-ReadConsoleInputExA(HANDLE hConsoleInput,
- PINPUT_RECORD lpBuffer,
- DWORD nLength,
- LPDWORD lpNumberOfEventsRead,
- WORD wFlags)
+ReadConsoleInputExA(IN HANDLE hConsoleInput,
+ OUT PINPUT_RECORD lpBuffer,
+ IN DWORD nLength,
+ OUT LPDWORD lpNumberOfEventsRead,
+ IN WORD wFlags)
{
return IntGetConsoleInput(hConsoleInput,
lpBuffer,
*/
BOOL
WINAPI
-ReadConsoleOutputCharacterW(HANDLE hConsoleOutput,
- LPWSTR lpCharacter,
- DWORD nLength,
- COORD dwReadCoord,
- LPDWORD lpNumberOfCharsRead)
+ReadConsoleOutputCharacterW(IN HANDLE hConsoleOutput,
+ OUT LPWSTR lpCharacter,
+ IN DWORD nLength,
+ IN COORD dwReadCoord,
+ OUT LPDWORD lpNumberOfCharsRead)
{
return IntReadConsoleOutputCode(hConsoleOutput,
CODE_UNICODE,
*/
BOOL
WINAPI
-ReadConsoleOutputCharacterA(HANDLE hConsoleOutput,
- LPSTR lpCharacter,
- DWORD nLength,
- COORD dwReadCoord,
- LPDWORD lpNumberOfCharsRead)
+ReadConsoleOutputCharacterA(IN HANDLE hConsoleOutput,
+ OUT LPSTR lpCharacter,
+ IN DWORD nLength,
+ IN COORD dwReadCoord,
+ OUT LPDWORD lpNumberOfCharsRead)
{
return IntReadConsoleOutputCode(hConsoleOutput,
CODE_ASCII,
*/
BOOL
WINAPI
-ReadConsoleOutputAttribute(HANDLE hConsoleOutput,
- LPWORD lpAttribute,
- DWORD nLength,
- COORD dwReadCoord,
- LPDWORD lpNumberOfAttrsRead)
+ReadConsoleOutputAttribute(IN HANDLE hConsoleOutput,
+ OUT LPWORD lpAttribute,
+ IN DWORD nLength,
+ IN COORD dwReadCoord,
+ OUT LPDWORD lpNumberOfAttrsRead)
{
return IntReadConsoleOutputCode(hConsoleOutput,
CODE_ATTRIBUTE,
*/
BOOL
WINAPI
-WriteConsoleInputW(HANDLE hConsoleInput,
- CONST INPUT_RECORD *lpBuffer,
- DWORD nLength,
- LPDWORD lpNumberOfEventsWritten)
+WriteConsoleInputW(IN HANDLE hConsoleInput,
+ IN CONST INPUT_RECORD *lpBuffer,
+ IN DWORD nLength,
+ OUT LPDWORD lpNumberOfEventsWritten)
{
return IntWriteConsoleInput(hConsoleInput,
(PINPUT_RECORD)lpBuffer,
*/
BOOL
WINAPI
-WriteConsoleInputA(HANDLE hConsoleInput,
- CONST INPUT_RECORD *lpBuffer,
- DWORD nLength,
- LPDWORD lpNumberOfEventsWritten)
+WriteConsoleInputA(IN HANDLE hConsoleInput,
+ IN CONST INPUT_RECORD *lpBuffer,
+ IN DWORD nLength,
+ OUT LPDWORD lpNumberOfEventsWritten)
{
return IntWriteConsoleInput(hConsoleInput,
(PINPUT_RECORD)lpBuffer,
*/
BOOL
WINAPI
-WriteConsoleInputVDMW(HANDLE hConsoleInput,
- CONST INPUT_RECORD *lpBuffer,
- DWORD nLength,
- LPDWORD lpNumberOfEventsWritten)
+WriteConsoleInputVDMW(IN HANDLE hConsoleInput,
+ IN CONST INPUT_RECORD *lpBuffer,
+ IN DWORD nLength,
+ OUT LPDWORD lpNumberOfEventsWritten)
{
return IntWriteConsoleInput(hConsoleInput,
(PINPUT_RECORD)lpBuffer,
*/
BOOL
WINAPI
-WriteConsoleInputVDMA(HANDLE hConsoleInput,
- CONST INPUT_RECORD *lpBuffer,
- DWORD nLength,
- LPDWORD lpNumberOfEventsWritten)
+WriteConsoleInputVDMA(IN HANDLE hConsoleInput,
+ IN CONST INPUT_RECORD *lpBuffer,
+ IN DWORD nLength,
+ OUT LPDWORD lpNumberOfEventsWritten)
{
return IntWriteConsoleInput(hConsoleInput,
(PINPUT_RECORD)lpBuffer,
*/
BOOL
WINAPI
-WriteConsoleOutputCharacterW(HANDLE hConsoleOutput,
- LPCWSTR lpCharacter,
- DWORD nLength,
- COORD dwWriteCoord,
- LPDWORD lpNumberOfCharsWritten)
+WriteConsoleOutputCharacterW(IN HANDLE hConsoleOutput,
+ IN LPCWSTR lpCharacter,
+ IN DWORD nLength,
+ IN COORD dwWriteCoord,
+ OUT LPDWORD lpNumberOfCharsWritten)
{
return IntWriteConsoleOutputCode(hConsoleOutput,
CODE_UNICODE,
*/
BOOL
WINAPI
-WriteConsoleOutputCharacterA(HANDLE hConsoleOutput,
- LPCSTR lpCharacter,
- DWORD nLength,
- COORD dwWriteCoord,
- LPDWORD lpNumberOfCharsWritten)
+WriteConsoleOutputCharacterA(IN HANDLE hConsoleOutput,
+ IN LPCSTR lpCharacter,
+ IN DWORD nLength,
+ IN COORD dwWriteCoord,
+ OUT LPDWORD lpNumberOfCharsWritten)
{
return IntWriteConsoleOutputCode(hConsoleOutput,
CODE_ASCII,
*/
BOOL
WINAPI
-WriteConsoleOutputAttribute(HANDLE hConsoleOutput,
- CONST WORD *lpAttribute,
- DWORD nLength,
- COORD dwWriteCoord,
- LPDWORD lpNumberOfAttrsWritten)
+WriteConsoleOutputAttribute(IN HANDLE hConsoleOutput,
+ IN CONST WORD *lpAttribute,
+ IN DWORD nLength,
+ IN COORD dwWriteCoord,
+ OUT LPDWORD lpNumberOfAttrsWritten)
{
return IntWriteConsoleOutputCode(hConsoleOutput,
CODE_ATTRIBUTE,
*/
BOOL
WINAPI
-FillConsoleOutputCharacterW(HANDLE hConsoleOutput,
- WCHAR cCharacter,
- DWORD nLength,
- COORD dwWriteCoord,
- LPDWORD lpNumberOfCharsWritten)
+FillConsoleOutputCharacterW(IN HANDLE hConsoleOutput,
+ IN WCHAR cCharacter,
+ IN DWORD nLength,
+ IN COORD dwWriteCoord,
+ OUT LPDWORD lpNumberOfCharsWritten)
{
+ CODE_ELEMENT Code;
+ Code.UnicodeChar = cCharacter;
return IntFillConsoleOutputCode(hConsoleOutput,
CODE_UNICODE,
- &cCharacter,
+ Code,
nLength,
dwWriteCoord,
lpNumberOfCharsWritten);
*/
BOOL
WINAPI
-FillConsoleOutputCharacterA(HANDLE hConsoleOutput,
- CHAR cCharacter,
- DWORD nLength,
- COORD dwWriteCoord,
+FillConsoleOutputCharacterA(IN HANDLE hConsoleOutput,
+ IN CHAR cCharacter,
+ IN DWORD nLength,
+ IN COORD dwWriteCoord,
LPDWORD lpNumberOfCharsWritten)
{
+ CODE_ELEMENT Code;
+ Code.AsciiChar = cCharacter;
return IntFillConsoleOutputCode(hConsoleOutput,
CODE_ASCII,
- &cCharacter,
+ Code,
nLength,
dwWriteCoord,
lpNumberOfCharsWritten);
*/
BOOL
WINAPI
-FillConsoleOutputAttribute(HANDLE hConsoleOutput,
- WORD wAttribute,
- DWORD nLength,
- COORD dwWriteCoord,
- LPDWORD lpNumberOfAttrsWritten)
+FillConsoleOutputAttribute(IN HANDLE hConsoleOutput,
+ IN WORD wAttribute,
+ IN DWORD nLength,
+ IN COORD dwWriteCoord,
+ OUT LPDWORD lpNumberOfAttrsWritten)
{
+ CODE_ELEMENT Code;
+ Code.Attribute = wAttribute;
return IntFillConsoleOutputCode(hConsoleOutput,
CODE_ATTRIBUTE,
- &wAttribute,
+ Code,
nLength,
dwWriteCoord,
lpNumberOfAttrsWritten);