- Moved all members with variable length in CSRSS_XXX structures to the end.

- Defined all members with variable length as arrays with a size of zero.  
- Used the stack for allocating CSR_API_MESSAGE structures.

svn path=/trunk/; revision=17563
This commit is contained in:
Hartmut Birr 2005-08-26 20:35:33 +00:00
parent 1a8c456007
commit 342d03f235
3 changed files with 187 additions and 330 deletions

View file

@ -46,7 +46,7 @@ typedef struct
ULONG nMaxIds; ULONG nMaxIds;
ULONG nProcessIdsCopied; ULONG nProcessIdsCopied;
ULONG nProcessIdsTotal; ULONG nProcessIdsTotal;
HANDLE ProcessId[1]; HANDLE ProcessId[0];
} CSRSS_GET_PROCESS_LIST, *PCSRSS_GET_PROCESS_LIST; } CSRSS_GET_PROCESS_LIST, *PCSRSS_GET_PROCESS_LIST;
typedef struct typedef struct
@ -54,8 +54,8 @@ typedef struct
HANDLE ConsoleHandle; HANDLE ConsoleHandle;
BOOL Unicode; BOOL Unicode;
ULONG NrCharactersToWrite; ULONG NrCharactersToWrite;
BYTE Buffer[1];
ULONG NrCharactersWritten; ULONG NrCharactersWritten;
BYTE Buffer[0];
} CSRSS_WRITE_CONSOLE, *PCSRSS_WRITE_CONSOLE; } CSRSS_WRITE_CONSOLE, *PCSRSS_WRITE_CONSOLE;
typedef struct typedef struct
@ -66,7 +66,7 @@ typedef struct
WORD nCharsCanBeDeleted; /* number of chars already in buffer that can be backspaced */ WORD nCharsCanBeDeleted; /* number of chars already in buffer that can be backspaced */
HANDLE EventHandle; HANDLE EventHandle;
ULONG NrCharactersRead; ULONG NrCharactersRead;
BYTE Buffer[1]; BYTE Buffer[0];
} CSRSS_READ_CONSOLE, *PCSRSS_READ_CONSOLE; } CSRSS_READ_CONSOLE, *PCSRSS_READ_CONSOLE;
typedef struct typedef struct
@ -132,9 +132,9 @@ typedef struct
BOOL Unicode; BOOL Unicode;
WORD Length; WORD Length;
COORD Coord; COORD Coord;
CHAR String[1];
COORD EndCoord; COORD EndCoord;
ULONG NrCharactersWritten; ULONG NrCharactersWritten;
CHAR String[0];
} CSRSS_WRITE_CONSOLE_OUTPUT_CHAR, *PCSRSS_WRITE_CONSOLE_OUTPUT_CHAR; } CSRSS_WRITE_CONSOLE_OUTPUT_CHAR, *PCSRSS_WRITE_CONSOLE_OUTPUT_CHAR;
typedef struct typedef struct
@ -142,8 +142,8 @@ typedef struct
HANDLE ConsoleHandle; HANDLE ConsoleHandle;
WORD Length; WORD Length;
COORD Coord; COORD Coord;
CHAR String[1];
COORD EndCoord; COORD EndCoord;
WORD Attribute[0];
} CSRSS_WRITE_CONSOLE_OUTPUT_ATTRIB, *PCSRSS_WRITE_CONSOLE_OUTPUT_ATTRIB; } CSRSS_WRITE_CONSOLE_OUTPUT_ATTRIB, *PCSRSS_WRITE_CONSOLE_OUTPUT_ATTRIB;
typedef struct typedef struct
@ -197,14 +197,14 @@ typedef struct
{ {
HANDLE Console; HANDLE Console;
DWORD Length; DWORD Length;
WCHAR Title[1]; WCHAR Title[0];
} CSRSS_SET_TITLE, *PCSRSS_SET_TITLE; } CSRSS_SET_TITLE, *PCSRSS_SET_TITLE;
typedef struct typedef struct
{ {
HANDLE ConsoleHandle; HANDLE ConsoleHandle;
DWORD Length; DWORD Length;
WCHAR Title[1]; WCHAR Title[0];
} CSRSS_GET_TITLE, *PCSRSS_GET_TITLE; } CSRSS_GET_TITLE, *PCSRSS_GET_TITLE;
typedef struct typedef struct
@ -241,7 +241,7 @@ typedef struct
COORD ReadCoord; COORD ReadCoord;
COORD EndCoord; COORD EndCoord;
DWORD CharsRead; DWORD CharsRead;
CHAR String[1]; CHAR String[0];
}CSRSS_READ_CONSOLE_OUTPUT_CHAR, *PCSRSS_READ_CONSOLE_OUTPUT_CHAR; }CSRSS_READ_CONSOLE_OUTPUT_CHAR, *PCSRSS_READ_CONSOLE_OUTPUT_CHAR;
typedef struct typedef struct
@ -250,13 +250,13 @@ typedef struct
DWORD NumAttrsToRead; DWORD NumAttrsToRead;
COORD ReadCoord; COORD ReadCoord;
COORD EndCoord; COORD EndCoord;
CHAR String[1]; WORD Attribute[0];
}CSRSS_READ_CONSOLE_OUTPUT_ATTRIB, *PCSRSS_READ_CONSOLE_OUTPUT_ATTRIB; }CSRSS_READ_CONSOLE_OUTPUT_ATTRIB, *PCSRSS_READ_CONSOLE_OUTPUT_ATTRIB;
typedef struct typedef struct
{ {
HANDLE ConsoleHandle; HANDLE ConsoleHandle;
DWORD NumInputEvents; DWORD NumInputEvents;
}CSRSS_GET_NUM_INPUT_EVENTS, *PCSRSS_GET_NUM_INPUT_EVENTS; }CSRSS_GET_NUM_INPUT_EVENTS, *PCSRSS_GET_NUM_INPUT_EVENTS;
typedef struct typedef struct
@ -410,20 +410,14 @@ typedef struct
HANDLE InputWaitHandle; HANDLE InputWaitHandle;
} CSRSS_GET_INPUT_WAIT_HANDLE, *PCSRSS_GET_INPUT_WAIT_HANDLE; } CSRSS_GET_INPUT_WAIT_HANDLE, *PCSRSS_GET_INPUT_WAIT_HANDLE;
#define CSRSS_MAX_WRITE_CONSOLE \ #define CSR_API_MESSAGE_HEADER_SIZE(Type) (FIELD_OFFSET(CSR_API_MESSAGE, Data) + sizeof(Type))
(LPC_MAX_DATA_LENGTH - sizeof(ULONG) - sizeof(CSRSS_WRITE_CONSOLE)) #define CSRSS_MAX_WRITE_CONSOLE (LPC_MAX_DATA_LENGTH - CSR_API_MESSAGE_HEADER_SIZE(CSRSS_WRITE_CONSOLE))
#define CSRSS_MAX_SET_TITLE (LPC_MAX_DATA_LENGTH - CSR_API_MESSAGE_HEADER_SIZE(CSRSS_SET_TITLE))
#define CSRSS_MAX_SET_TITLE (LPC_MAX_DATA_LENGTH - sizeof( HANDLE ) - sizeof( DWORD ) - sizeof( ULONG ) - sizeof(PORT_MESSAGE)) #define CSRSS_MAX_WRITE_CONSOLE_OUTPUT_CHAR (LPC_MAX_DATA_LENGTH - CSR_API_MESSAGE_HEADER_SIZE(CSRSS_WRITE_CONSOLE_OUTPUT_CHAR))
#define CSRSS_MAX_WRITE_CONSOLE_OUTPUT_ATTRIB (LPC_MAX_DATA_LENGTH - CSR_API_MESSAGE_HEADER_SIZE(CSRSS_WRITE_CONSOLE_OUTPUT_ATTRIB))
#define CSRSS_MAX_WRITE_CONSOLE_OUTPUT_CHAR (LPC_MAX_DATA_LENGTH - sizeof( ULONG ) - sizeof( CSRSS_WRITE_CONSOLE_OUTPUT_CHAR )) #define CSRSS_MAX_READ_CONSOLE (LPC_MAX_DATA_LENGTH - CSR_API_MESSAGE_HEADER_SIZE(CSRSS_READ_CONSOLE))
#define CSRSS_MAX_READ_CONSOLE_OUTPUT_CHAR (LPC_MAX_DATA_LENGTH - CSR_API_MESSAGE_HEADER_SIZE(CSRSS_READ_CONSOLE_OUTPUT_CHAR))
#define CSRSS_MAX_WRITE_CONSOLE_OUTPUT_ATTRIB ((LPC_MAX_DATA_LENGTH - sizeof( ULONG ) - sizeof( CSRSS_WRITE_CONSOLE_OUTPUT_ATTRIB )) / 2) #define CSRSS_MAX_READ_CONSOLE_OUTPUT_ATTRIB (LPC_MAX_DATA_LENGTH - CSR_API_MESSAGE_HEADER_SIZE(CSRSS_READ_CONSOLE_OUTPUT_ATTRIB))
#define CSRSS_MAX_READ_CONSOLE (LPC_MAX_DATA_LENGTH - sizeof( ULONG ) - sizeof( CSRSS_READ_CONSOLE ))
#define CSRSS_MAX_READ_CONSOLE_OUTPUT_CHAR (LPC_MAX_DATA_LENGTH - sizeof(ULONG) - sizeof(HANDLE) - sizeof(DWORD) - sizeof(CSRSS_READ_CONSOLE_OUTPUT_CHAR))
#define CSRSS_MAX_READ_CONSOLE_OUTPUT_ATTRIB (LPC_MAX_DATA_LENGTH - sizeof(ULONG) - sizeof(HANDLE) - sizeof(DWORD) - sizeof(CSRSS_READ_CONSOLE_OUTPUT_ATTRIB))
/* WCHARs, not bytes! */ /* WCHARs, not bytes! */
#define CSRSS_MAX_TITLE_LENGTH 80 #define CSRSS_MAX_TITLE_LENGTH 80

View file

@ -1097,55 +1097,44 @@ IntWriteConsole(HANDLE hConsoleOutput,
LPVOID lpReserved, LPVOID lpReserved,
BOOL bUnicode) BOOL bUnicode)
{ {
PCSR_API_MESSAGE Request; ULONG CsrRequest; CSR_API_MESSAGE Request;
ULONG CsrRequest;
NTSTATUS Status; NTSTATUS Status;
USHORT nChars; USHORT nChars;
ULONG MessageSize, BufferSize, SizeBytes, CharSize; ULONG SizeBytes, CharSize;
DWORD Written = 0; DWORD Written = 0;
CharSize = (bUnicode ? sizeof(WCHAR) : sizeof(CHAR)); CharSize = (bUnicode ? sizeof(WCHAR) : sizeof(CHAR));
BufferSize = sizeof(CSR_API_MESSAGE) + min(nNumberOfCharsToWrite * CharSize, CSRSS_MAX_WRITE_CONSOLE);
Request = RtlAllocateHeap(GetProcessHeap(), 0, BufferSize);
if(Request == NULL)
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return FALSE;
}
CsrRequest = MAKE_CSR_API(WRITE_CONSOLE, CSR_CONSOLE); CsrRequest = MAKE_CSR_API(WRITE_CONSOLE, CSR_CONSOLE);
Request->Data.WriteConsoleRequest.ConsoleHandle = hConsoleOutput; Request.Data.WriteConsoleRequest.ConsoleHandle = hConsoleOutput;
Request->Data.WriteConsoleRequest.Unicode = bUnicode; Request.Data.WriteConsoleRequest.Unicode = bUnicode;
while(nNumberOfCharsToWrite > 0) while(nNumberOfCharsToWrite > 0)
{ {
nChars = min(nNumberOfCharsToWrite, CSRSS_MAX_WRITE_CONSOLE) / CharSize; nChars = min(nNumberOfCharsToWrite, CSRSS_MAX_WRITE_CONSOLE) / CharSize;
Request->Data.WriteConsoleRequest.NrCharactersToWrite = nChars; Request.Data.WriteConsoleRequest.NrCharactersToWrite = nChars;
SizeBytes = nChars * CharSize; SizeBytes = nChars * CharSize;
memcpy(Request->Data.WriteConsoleRequest.Buffer, lpBuffer, SizeBytes); memcpy(Request.Data.WriteConsoleRequest.Buffer, lpBuffer, SizeBytes);
MessageSize = CSRSS_HEADER_SIZE + sizeof(CSRSS_WRITE_CONSOLE) + SizeBytes; Status = CsrClientCallServer(&Request,
Status = CsrClientCallServer(Request,
NULL, NULL,
CsrRequest, CsrRequest,
MessageSize); sizeof(CSR_API_MESSAGE));
if(!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request->Status)) if(!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
{ {
RtlFreeHeap(GetProcessHeap(), 0, Request);
SetLastErrorByStatus(Status); SetLastErrorByStatus(Status);
return FALSE; return FALSE;
} }
nNumberOfCharsToWrite -= nChars; nNumberOfCharsToWrite -= nChars;
lpBuffer = (PVOID)((ULONG_PTR)lpBuffer + (ULONG_PTR)SizeBytes); lpBuffer = (PVOID)((ULONG_PTR)lpBuffer + (ULONG_PTR)SizeBytes);
Written += Request->Data.WriteConsoleRequest.NrCharactersWritten; Written += Request.Data.WriteConsoleRequest.NrCharactersWritten;
} }
RtlFreeHeap(GetProcessHeap(), 0, Request);
if(lpNumberOfCharsWritten != NULL) if(lpNumberOfCharsWritten != NULL)
{ {
*lpNumberOfCharsWritten = Written; *lpNumberOfCharsWritten = Written;
@ -1207,27 +1196,20 @@ IntReadConsole(HANDLE hConsoleInput,
LPVOID lpReserved, LPVOID lpReserved,
BOOL bUnicode) BOOL bUnicode)
{ {
PCSR_API_MESSAGE Request; ULONG CsrRequest; CSR_API_MESSAGE Request;
ULONG CsrRequest;
NTSTATUS Status; NTSTATUS Status;
ULONG BufferSize, CharSize, CharsRead = 0; ULONG CharSize, CharsRead = 0;
CharSize = (bUnicode ? sizeof(WCHAR) : sizeof(CHAR)); CharSize = (bUnicode ? sizeof(WCHAR) : sizeof(CHAR));
BufferSize = sizeof(CSR_API_MESSAGE) + min(nNumberOfCharsToRead * CharSize, CSRSS_MAX_READ_CONSOLE); Request.Status = STATUS_SUCCESS;
Request = RtlAllocateHeap(GetProcessHeap(), 0, BufferSize);
if(Request == NULL)
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return FALSE;
}
Request->Status = STATUS_SUCCESS;
do do
{ {
if(Request->Status == STATUS_PENDING) if(Request.Status == STATUS_PENDING)
{ {
Status = NtWaitForSingleObject(Request->Data.ReadConsoleRequest.EventHandle, FALSE, 0); Status = NtWaitForSingleObject(Request.Data.ReadConsoleRequest.EventHandle, FALSE, 0);
if(!NT_SUCCESS(Status)) if(!NT_SUCCESS(Status))
{ {
DPRINT1("Wait for console input failed!\n"); DPRINT1("Wait for console input failed!\n");
@ -1236,39 +1218,38 @@ IntReadConsole(HANDLE hConsoleInput,
} }
CsrRequest = MAKE_CSR_API(READ_CONSOLE, CSR_CONSOLE); CsrRequest = MAKE_CSR_API(READ_CONSOLE, CSR_CONSOLE);
Request->Data.ReadConsoleRequest.ConsoleHandle = hConsoleInput; Request.Data.ReadConsoleRequest.ConsoleHandle = hConsoleInput;
Request->Data.ReadConsoleRequest.Unicode = bUnicode; Request.Data.ReadConsoleRequest.Unicode = bUnicode;
Request->Data.ReadConsoleRequest.NrCharactersToRead = min(nNumberOfCharsToRead, CSRSS_MAX_READ_CONSOLE) / CharSize; Request.Data.ReadConsoleRequest.NrCharactersToRead = min(nNumberOfCharsToRead, CSRSS_MAX_READ_CONSOLE) / CharSize;
Request->Data.ReadConsoleRequest.nCharsCanBeDeleted = CharsRead; Request.Data.ReadConsoleRequest.nCharsCanBeDeleted = CharsRead;
Status = CsrClientCallServer(Request, Status = CsrClientCallServer(&Request,
NULL, NULL,
CsrRequest, CsrRequest,
sizeof(CSR_API_MESSAGE) + (Request->Data.ReadConsoleRequest.NrCharactersToRead * CharSize)); sizeof(CSR_API_MESSAGE));
if(!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request->Status)) if(!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
{ {
DPRINT1("CSR returned error in ReadConsole\n"); DPRINT1("CSR returned error in ReadConsole\n");
SetLastErrorByStatus(Status); SetLastErrorByStatus(Status);
RtlFreeHeap(GetProcessHeap(), 0, Request);
return FALSE; return FALSE;
} }
nNumberOfCharsToRead -= Request->Data.ReadConsoleRequest.NrCharactersRead; nNumberOfCharsToRead -= Request.Data.ReadConsoleRequest.NrCharactersRead;
memcpy((PVOID)((ULONG_PTR)lpBuffer + (ULONG_PTR)(CharsRead * CharSize)), memcpy((PVOID)((ULONG_PTR)lpBuffer + (ULONG_PTR)(CharsRead * CharSize)),
Request->Data.ReadConsoleRequest.Buffer, Request.Data.ReadConsoleRequest.Buffer,
Request->Data.ReadConsoleRequest.NrCharactersRead * CharSize); Request.Data.ReadConsoleRequest.NrCharactersRead * CharSize);
CharsRead += Request->Data.ReadConsoleRequest.NrCharactersRead; CharsRead += Request.Data.ReadConsoleRequest.NrCharactersRead;
if(Request->Status == STATUS_NOTIFY_CLEANUP) if(Request.Status == STATUS_NOTIFY_CLEANUP)
{ {
if(CharsRead > 0) if(CharsRead > 0)
{ {
CharsRead--; CharsRead--;
nNumberOfCharsToRead++; nNumberOfCharsToRead++;
} }
Request->Status = STATUS_PENDING; Request.Status = STATUS_PENDING;
} }
} while(Request->Status == STATUS_PENDING && nNumberOfCharsToRead > 0); } while(Request.Status == STATUS_PENDING && nNumberOfCharsToRead > 0);
if(lpNumberOfCharsRead != NULL) if(lpNumberOfCharsRead != NULL)
{ {
@ -1539,7 +1520,7 @@ IntPeekConsoleInput(HANDLE hConsoleInput,
LPDWORD lpNumberOfEventsRead, LPDWORD lpNumberOfEventsRead,
BOOL bUnicode) BOOL bUnicode)
{ {
PCSR_API_MESSAGE Request; ULONG CsrRequest; CSR_API_MESSAGE Request; ULONG CsrRequest;
NTSTATUS Status; NTSTATUS Status;
PVOID BufferBase; PVOID BufferBase;
PVOID BufferTargetBase; PVOID BufferTargetBase;
@ -1560,39 +1541,30 @@ IntPeekConsoleInput(HANDLE hConsoleInput,
return FALSE; return FALSE;
} }
Request = RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CSR_API_MESSAGE));
if(Request == NULL)
{
CsrReleaseParameterBuffer(BufferBase);
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return FALSE;
}
CsrRequest = MAKE_CSR_API(PEEK_CONSOLE_INPUT, CSR_CONSOLE); CsrRequest = MAKE_CSR_API(PEEK_CONSOLE_INPUT, CSR_CONSOLE);
Request->Data.PeekConsoleInputRequest.ConsoleHandle = hConsoleInput; Request.Data.PeekConsoleInputRequest.ConsoleHandle = hConsoleInput;
Request->Data.PeekConsoleInputRequest.Unicode = bUnicode; Request.Data.PeekConsoleInputRequest.Unicode = bUnicode;
Request->Data.PeekConsoleInputRequest.Length = nLength; Request.Data.PeekConsoleInputRequest.Length = nLength;
Request->Data.PeekConsoleInputRequest.InputRecord = (INPUT_RECORD*)BufferTargetBase; Request.Data.PeekConsoleInputRequest.InputRecord = (INPUT_RECORD*)BufferTargetBase;
Status = CsrClientCallServer(Request, NULL, Status = CsrClientCallServer(&Request,
NULL,
CsrRequest, CsrRequest,
sizeof(CSR_API_MESSAGE)); sizeof(CSR_API_MESSAGE));
if(!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request->Status)) if(!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
{ {
RtlFreeHeap(GetProcessHeap(), 0, Request);
CsrReleaseParameterBuffer(BufferBase); CsrReleaseParameterBuffer(BufferBase);
return FALSE; return FALSE;
} }
memcpy(lpBuffer, BufferBase, sizeof(INPUT_RECORD) * Request->Data.PeekConsoleInputRequest.Length); memcpy(lpBuffer, BufferBase, sizeof(INPUT_RECORD) * Request.Data.PeekConsoleInputRequest.Length);
RtlFreeHeap(GetProcessHeap(), 0, Request);
CsrReleaseParameterBuffer(BufferBase); CsrReleaseParameterBuffer(BufferBase);
if(lpNumberOfEventsRead != NULL) if(lpNumberOfEventsRead != NULL)
{ {
*lpNumberOfEventsRead = Request->Data.PeekConsoleInputRequest.Length; *lpNumberOfEventsRead = Request.Data.PeekConsoleInputRequest.Length;
} }
return TRUE; return TRUE;
@ -1853,7 +1825,7 @@ IntReadConsoleOutput(HANDLE hConsoleOutput,
PSMALL_RECT lpReadRegion, PSMALL_RECT lpReadRegion,
BOOL bUnicode) BOOL bUnicode)
{ {
PCSR_API_MESSAGE Request; ULONG CsrRequest; CSR_API_MESSAGE Request; ULONG CsrRequest;
PVOID BufferBase; PVOID BufferBase;
PVOID BufferTargetBase; PVOID BufferTargetBase;
@ -1875,43 +1847,34 @@ IntReadConsoleOutput(HANDLE hConsoleOutput,
return FALSE; return FALSE;
} }
Request = RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CSR_API_MESSAGE));
if(Request == NULL)
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
CsrReleaseParameterBuffer(BufferBase);
return FALSE;
}
CsrRequest = MAKE_CSR_API(READ_CONSOLE_OUTPUT, CSR_CONSOLE); CsrRequest = MAKE_CSR_API(READ_CONSOLE_OUTPUT, CSR_CONSOLE);
Request->Data.ReadConsoleOutputRequest.ConsoleHandle = hConsoleOutput; Request.Data.ReadConsoleOutputRequest.ConsoleHandle = hConsoleOutput;
Request->Data.ReadConsoleOutputRequest.Unicode = bUnicode; Request.Data.ReadConsoleOutputRequest.Unicode = bUnicode;
Request->Data.ReadConsoleOutputRequest.BufferSize = dwBufferSize; Request.Data.ReadConsoleOutputRequest.BufferSize = dwBufferSize;
Request->Data.ReadConsoleOutputRequest.BufferCoord = dwBufferCoord; Request.Data.ReadConsoleOutputRequest.BufferCoord = dwBufferCoord;
Request->Data.ReadConsoleOutputRequest.ReadRegion = *lpReadRegion; Request.Data.ReadConsoleOutputRequest.ReadRegion = *lpReadRegion;
Request->Data.ReadConsoleOutputRequest.CharInfo = (PCHAR_INFO)BufferTargetBase; Request.Data.ReadConsoleOutputRequest.CharInfo = (PCHAR_INFO)BufferTargetBase;
Status = CsrClientCallServer(Request, NULL, Status = CsrClientCallServer(&Request,
NULL,
CsrRequest, CsrRequest,
sizeof(CSR_API_MESSAGE)); sizeof(CSR_API_MESSAGE));
if(!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request->Status)) if(!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
{ {
SetLastErrorByStatus(Status); SetLastErrorByStatus(Status);
RtlFreeHeap(GetProcessHeap(), 0, Request);
CsrReleaseParameterBuffer(BufferBase); CsrReleaseParameterBuffer(BufferBase);
return FALSE; return FALSE;
} }
SizeX = Request->Data.ReadConsoleOutputRequest.ReadRegion.Right - Request->Data.ReadConsoleOutputRequest.ReadRegion.Left + 1; SizeX = Request.Data.ReadConsoleOutputRequest.ReadRegion.Right - Request.Data.ReadConsoleOutputRequest.ReadRegion.Left + 1;
SizeY = Request->Data.ReadConsoleOutputRequest.ReadRegion.Bottom - Request->Data.ReadConsoleOutputRequest.ReadRegion.Top + 1; SizeY = Request.Data.ReadConsoleOutputRequest.ReadRegion.Bottom - Request.Data.ReadConsoleOutputRequest.ReadRegion.Top + 1;
memcpy(lpBuffer, BufferBase, sizeof(CHAR_INFO) * SizeX * SizeY); memcpy(lpBuffer, BufferBase, sizeof(CHAR_INFO) * SizeX * SizeY);
RtlFreeHeap(GetProcessHeap(), 0, Request);
CsrReleaseParameterBuffer(BufferBase); CsrReleaseParameterBuffer(BufferBase);
*lpReadRegion = Request->Data.ReadConsoleOutputRequest.ReadRegion; *lpReadRegion = Request.Data.ReadConsoleOutputRequest.ReadRegion;
return TRUE; return TRUE;
} }
@ -1964,7 +1927,7 @@ IntWriteConsoleOutput(HANDLE hConsoleOutput,
PSMALL_RECT lpWriteRegion, PSMALL_RECT lpWriteRegion,
BOOL bUnicode) BOOL bUnicode)
{ {
PCSR_API_MESSAGE Request; ULONG CsrRequest; CSR_API_MESSAGE Request; ULONG CsrRequest;
NTSTATUS Status; NTSTATUS Status;
ULONG Size; ULONG Size;
PVOID BufferBase; PVOID BufferBase;
@ -1982,40 +1945,30 @@ IntWriteConsoleOutput(HANDLE hConsoleOutput,
return(FALSE); return(FALSE);
} }
Request = RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY,
sizeof(CSR_API_MESSAGE));
if (Request == NULL)
{
CsrReleaseParameterBuffer(BufferBase);
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return FALSE;
}
CsrRequest = MAKE_CSR_API(WRITE_CONSOLE_OUTPUT, CSR_CONSOLE); CsrRequest = MAKE_CSR_API(WRITE_CONSOLE_OUTPUT, CSR_CONSOLE);
Request->Data.WriteConsoleOutputRequest.ConsoleHandle = hConsoleOutput; Request.Data.WriteConsoleOutputRequest.ConsoleHandle = hConsoleOutput;
Request->Data.WriteConsoleOutputRequest.Unicode = bUnicode; Request.Data.WriteConsoleOutputRequest.Unicode = bUnicode;
Request->Data.WriteConsoleOutputRequest.BufferSize = dwBufferSize; Request.Data.WriteConsoleOutputRequest.BufferSize = dwBufferSize;
Request->Data.WriteConsoleOutputRequest.BufferCoord = dwBufferCoord; Request.Data.WriteConsoleOutputRequest.BufferCoord = dwBufferCoord;
Request->Data.WriteConsoleOutputRequest.WriteRegion = *lpWriteRegion; Request.Data.WriteConsoleOutputRequest.WriteRegion = *lpWriteRegion;
Request->Data.WriteConsoleOutputRequest.CharInfo = Request.Data.WriteConsoleOutputRequest.CharInfo =
(CHAR_INFO*)BufferTargetBase; (CHAR_INFO*)BufferTargetBase;
Status = CsrClientCallServer(Request, Status = CsrClientCallServer(&Request,
NULL, NULL,
CsrRequest, CsrRequest,
sizeof(CSR_API_MESSAGE)); sizeof(CSR_API_MESSAGE));
if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request->Status)) if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
{ {
CsrReleaseParameterBuffer(BufferBase); CsrReleaseParameterBuffer(BufferBase);
RtlFreeHeap(GetProcessHeap(), 0, Request);
SetLastErrorByStatus(Status); SetLastErrorByStatus(Status);
return FALSE; return FALSE;
} }
RtlFreeHeap(GetProcessHeap(), 0, Request);
CsrReleaseParameterBuffer(BufferBase); CsrReleaseParameterBuffer(BufferBase);
*lpWriteRegion = Request->Data.WriteConsoleOutputRequest.WriteRegion; *lpWriteRegion = Request.Data.WriteConsoleOutputRequest.WriteRegion;
return(TRUE); return(TRUE);
} }
@ -2065,7 +2018,7 @@ IntReadConsoleOutputCharacter(HANDLE hConsoleOutput,
LPDWORD lpNumberOfCharsRead, LPDWORD lpNumberOfCharsRead,
BOOL bUnicode) BOOL bUnicode)
{ {
PCSR_API_MESSAGE Request; ULONG CsrRequest; CSR_API_MESSAGE Request; ULONG CsrRequest;
NTSTATUS Status; NTSTATUS Status;
ULONG nChars, SizeBytes, CharSize; ULONG nChars, SizeBytes, CharSize;
DWORD CharsRead = 0; DWORD CharsRead = 0;
@ -2075,47 +2028,37 @@ IntReadConsoleOutputCharacter(HANDLE hConsoleOutput,
nChars = min(nLength, CSRSS_MAX_READ_CONSOLE_OUTPUT_CHAR) / CharSize; nChars = min(nLength, CSRSS_MAX_READ_CONSOLE_OUTPUT_CHAR) / CharSize;
SizeBytes = nChars * CharSize; SizeBytes = nChars * CharSize;
Request = RtlAllocateHeap(GetProcessHeap(), 0,
sizeof(CSR_API_MESSAGE) + SizeBytes);
if(Request == NULL)
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return FALSE;
}
CsrRequest = MAKE_CSR_API(READ_CONSOLE_OUTPUT_CHAR, CSR_CONSOLE); CsrRequest = MAKE_CSR_API(READ_CONSOLE_OUTPUT_CHAR, CSR_CONSOLE);
Request->Data.ReadConsoleOutputCharRequest.ConsoleHandle = hConsoleOutput; Request.Data.ReadConsoleOutputCharRequest.ConsoleHandle = hConsoleOutput;
Request->Data.ReadConsoleOutputCharRequest.Unicode = bUnicode; Request.Data.ReadConsoleOutputCharRequest.Unicode = bUnicode;
Request->Data.ReadConsoleOutputCharRequest.ReadCoord = dwReadCoord; Request.Data.ReadConsoleOutputCharRequest.ReadCoord = dwReadCoord;
while(nLength > 0) while(nLength > 0)
{ {
DWORD BytesRead; DWORD BytesRead;
Request->Data.ReadConsoleOutputCharRequest.NumCharsToRead = min(nLength, nChars); Request.Data.ReadConsoleOutputCharRequest.NumCharsToRead = min(nLength, nChars);
SizeBytes = Request.Data.ReadConsoleOutputCharRequest.NumCharsToRead * CharSize;
Status = CsrClientCallServer(Request, Status = CsrClientCallServer(&Request,
NULL, NULL,
CsrRequest, CsrRequest,
sizeof(CSR_API_MESSAGE) + SizeBytes); sizeof(CSR_API_MESSAGE));
if(!NT_SUCCESS(Status) || !NT_SUCCESS(Request->Status)) if(!NT_SUCCESS(Status) || !NT_SUCCESS(Request.Status))
{ {
SetLastErrorByStatus(Status); SetLastErrorByStatus(Status);
break; break;
} }
BytesRead = Request->Data.ReadConsoleOutputCharRequest.CharsRead * CharSize; BytesRead = Request.Data.ReadConsoleOutputCharRequest.CharsRead * CharSize;
memcpy(lpCharacter, &Request->Data.ReadConsoleOutputCharRequest.String[0], BytesRead); memcpy(lpCharacter, Request.Data.ReadConsoleOutputCharRequest.String, BytesRead);
lpCharacter = (PVOID)((ULONG_PTR)lpCharacter + (ULONG_PTR)BytesRead); lpCharacter = (PVOID)((ULONG_PTR)lpCharacter + (ULONG_PTR)BytesRead);
CharsRead += Request->Data.ReadConsoleOutputCharRequest.CharsRead; CharsRead += Request.Data.ReadConsoleOutputCharRequest.CharsRead;
nLength -= Request->Data.ReadConsoleOutputCharRequest.CharsRead; nLength -= Request.Data.ReadConsoleOutputCharRequest.CharsRead;
Request->Data.ReadConsoleOutputCharRequest.ReadCoord = Request->Data.ReadConsoleOutputCharRequest.EndCoord; Request.Data.ReadConsoleOutputCharRequest.ReadCoord = Request.Data.ReadConsoleOutputCharRequest.EndCoord;
} }
RtlFreeHeap(GetProcessHeap(), 0, Request);
if(lpNumberOfCharsRead != NULL) if(lpNumberOfCharsRead != NULL)
{ {
*lpNumberOfCharsRead = CharsRead; *lpNumberOfCharsRead = CharsRead;
@ -2188,55 +2131,42 @@ ReadConsoleOutputAttribute(
LPDWORD lpNumberOfAttrsRead LPDWORD lpNumberOfAttrsRead
) )
{ {
PCSR_API_MESSAGE Request; ULONG CsrRequest; CSR_API_MESSAGE Request; ULONG CsrRequest;
NTSTATUS Status; NTSTATUS Status;
DWORD Size, i; DWORD Size;
Request = RtlAllocateHeap(GetProcessHeap(), 0,
sizeof(CSR_API_MESSAGE) + min(nLength, CSRSS_MAX_READ_CONSOLE_OUTPUT_ATTRIB));
if (Request == NULL)
{
SetLastError(ERROR_OUTOFMEMORY);
return(FALSE);
}
if (lpNumberOfAttrsRead != NULL) if (lpNumberOfAttrsRead != NULL)
*lpNumberOfAttrsRead = nLength; *lpNumberOfAttrsRead = nLength;
CsrRequest = MAKE_CSR_API(READ_CONSOLE_OUTPUT_ATTRIB, CSR_CONSOLE); CsrRequest = MAKE_CSR_API(READ_CONSOLE_OUTPUT_ATTRIB, CSR_CONSOLE);
Request->Data.ReadConsoleOutputAttribRequest.ConsoleHandle = hConsoleOutput; Request.Data.ReadConsoleOutputAttribRequest.ConsoleHandle = hConsoleOutput;
Request->Data.ReadConsoleOutputAttribRequest.ReadCoord = dwReadCoord; Request.Data.ReadConsoleOutputAttribRequest.ReadCoord = dwReadCoord;
while (nLength != 0) while (nLength != 0)
{ {
if (nLength > CSRSS_MAX_READ_CONSOLE_OUTPUT_ATTRIB) if (nLength > CSRSS_MAX_READ_CONSOLE_OUTPUT_ATTRIB / sizeof(WORD))
Size = CSRSS_MAX_READ_CONSOLE_OUTPUT_ATTRIB; Size = CSRSS_MAX_READ_CONSOLE_OUTPUT_ATTRIB / sizeof(WCHAR);
else else
Size = nLength; Size = nLength;
Request->Data.ReadConsoleOutputAttribRequest.NumAttrsToRead = Size; Request.Data.ReadConsoleOutputAttribRequest.NumAttrsToRead = Size;
Status = CsrClientCallServer(Request, Status = CsrClientCallServer(&Request,
NULL, NULL,
CsrRequest, CsrRequest,
sizeof(CSR_API_MESSAGE) + Size); sizeof(CSR_API_MESSAGE));
if (!NT_SUCCESS(Status) || !NT_SUCCESS(Request->Status)) if (!NT_SUCCESS(Status) || !NT_SUCCESS(Request.Status))
{ {
RtlFreeHeap(GetProcessHeap(), 0, Request);
SetLastErrorByStatus(Status); SetLastErrorByStatus(Status);
return(FALSE); return(FALSE);
} }
// Convert CHARs to WORDs memcpy(lpAttribute, Request.Data.ReadConsoleOutputAttribRequest.Attribute, Size * sizeof(WORD));
for(i = 0; i < Size; ++i) lpAttribute += Size;
*lpAttribute++ = Request->Data.ReadConsoleOutputAttribRequest.String[i];
nLength -= Size; nLength -= Size;
Request->Data.ReadConsoleOutputAttribRequest.ReadCoord = Request->Data.ReadConsoleOutputAttribRequest.EndCoord; Request.Data.ReadConsoleOutputAttribRequest.ReadCoord = Request.Data.ReadConsoleOutputAttribRequest.EndCoord;
} }
RtlFreeHeap(GetProcessHeap(), 0, Request);
return(TRUE); return(TRUE);
} }
@ -2249,59 +2179,48 @@ IntWriteConsoleOutputCharacter(HANDLE hConsoleOutput,
LPDWORD lpNumberOfCharsWritten, LPDWORD lpNumberOfCharsWritten,
BOOL bUnicode) BOOL bUnicode)
{ {
PCSR_API_MESSAGE Request; ULONG CsrRequest; CSR_API_MESSAGE Request; ULONG CsrRequest;
NTSTATUS Status; NTSTATUS Status;
ULONG SizeBytes, CharSize, nChars; ULONG SizeBytes, CharSize, nChars;
DWORD Written = 0; DWORD Written = 0;
CharSize = (bUnicode ? sizeof(WCHAR) : sizeof(CHAR)); CharSize = (bUnicode ? sizeof(WCHAR) : sizeof(CHAR));
nChars = min(nLength, CSRSS_MAX_WRITE_CONSOLE) / CharSize; nChars = min(nLength, CSRSS_MAX_WRITE_CONSOLE_OUTPUT_CHAR / CharSize);
SizeBytes = nChars * CharSize; SizeBytes = nChars * CharSize;
Request = RtlAllocateHeap(GetProcessHeap(), 0,
sizeof(CSR_API_MESSAGE) + (nChars * CharSize));
if(Request == NULL)
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return FALSE;
}
CsrRequest = MAKE_CSR_API(WRITE_CONSOLE_OUTPUT_CHAR, CSR_CONSOLE); CsrRequest = MAKE_CSR_API(WRITE_CONSOLE_OUTPUT_CHAR, CSR_CONSOLE);
Request->Data.WriteConsoleOutputCharRequest.ConsoleHandle = hConsoleOutput; Request.Data.WriteConsoleOutputCharRequest.ConsoleHandle = hConsoleOutput;
Request->Data.WriteConsoleOutputCharRequest.Unicode = bUnicode; Request.Data.WriteConsoleOutputCharRequest.Unicode = bUnicode;
Request->Data.WriteConsoleOutputCharRequest.Coord = dwWriteCoord; Request.Data.WriteConsoleOutputCharRequest.Coord = dwWriteCoord;
while(nLength > 0) while(nLength > 0)
{ {
DWORD BytesWrite; DWORD BytesWrite;
Request->Data.WriteConsoleOutputCharRequest.Length = min(nLength, nChars); Request.Data.WriteConsoleOutputCharRequest.Length = min(nLength, nChars);
BytesWrite = Request->Data.WriteConsoleOutputCharRequest.Length * CharSize; BytesWrite = Request.Data.WriteConsoleOutputCharRequest.Length * CharSize;
memcpy(&Request->Data.WriteConsoleOutputCharRequest.String[0], lpCharacter, BytesWrite); memcpy(Request.Data.WriteConsoleOutputCharRequest.String, lpCharacter, BytesWrite);
Status = CsrClientCallServer(Request, Status = CsrClientCallServer(&Request,
NULL, NULL,
CsrRequest, CsrRequest,
sizeof(CSR_API_MESSAGE) + BytesWrite); sizeof(CSR_API_MESSAGE));
if(!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request->Status)) if(!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
{ {
RtlFreeHeap(GetProcessHeap(), 0, Request);
SetLastErrorByStatus(Status); SetLastErrorByStatus(Status);
return FALSE; return FALSE;
} }
nLength -= Request->Data.WriteConsoleOutputCharRequest.NrCharactersWritten; nLength -= Request.Data.WriteConsoleOutputCharRequest.NrCharactersWritten;
lpCharacter = (PVOID)((ULONG_PTR)lpCharacter + (ULONG_PTR)(Request->Data.WriteConsoleOutputCharRequest.NrCharactersWritten * CharSize)); lpCharacter = (PVOID)((ULONG_PTR)lpCharacter + (ULONG_PTR)(Request.Data.WriteConsoleOutputCharRequest.NrCharactersWritten * CharSize));
Written += Request->Data.WriteConsoleOutputCharRequest.NrCharactersWritten; Written += Request.Data.WriteConsoleOutputCharRequest.NrCharactersWritten;
Request->Data.WriteConsoleOutputCharRequest.Coord = Request->Data.WriteConsoleOutputCharRequest.EndCoord; Request.Data.WriteConsoleOutputCharRequest.Coord = Request.Data.WriteConsoleOutputCharRequest.EndCoord;
} }
RtlFreeHeap(GetProcessHeap(), 0, Request);
if(lpNumberOfCharsWritten != NULL) if(lpNumberOfCharsWritten != NULL)
{ {
*lpNumberOfCharsWritten = Written; *lpNumberOfCharsWritten = Written;
@ -2368,43 +2287,32 @@ WriteConsoleOutputAttribute(
LPDWORD lpNumberOfAttrsWritten LPDWORD lpNumberOfAttrsWritten
) )
{ {
PCSR_API_MESSAGE Request; ULONG CsrRequest; CSR_API_MESSAGE Request; ULONG CsrRequest;
NTSTATUS Status; NTSTATUS Status;
WORD Size; WORD Size;
int c;
Request = RtlAllocateHeap(GetProcessHeap(), 0,
sizeof(CSR_API_MESSAGE) +
min(nLength, CSRSS_MAX_WRITE_CONSOLE_OUTPUT_ATTRIB));
if( !Request )
{
SetLastError( ERROR_OUTOFMEMORY );
return FALSE;
}
CsrRequest = MAKE_CSR_API(WRITE_CONSOLE_OUTPUT_ATTRIB, CSR_CONSOLE); CsrRequest = MAKE_CSR_API(WRITE_CONSOLE_OUTPUT_ATTRIB, CSR_CONSOLE);
Request->Data.WriteConsoleOutputAttribRequest.ConsoleHandle = hConsoleOutput; Request.Data.WriteConsoleOutputAttribRequest.ConsoleHandle = hConsoleOutput;
Request->Data.WriteConsoleOutputAttribRequest.Coord = dwWriteCoord; Request.Data.WriteConsoleOutputAttribRequest.Coord = dwWriteCoord;
if( lpNumberOfAttrsWritten ) if( lpNumberOfAttrsWritten )
*lpNumberOfAttrsWritten = nLength; *lpNumberOfAttrsWritten = nLength;
while( nLength ) while( nLength )
{ {
Size = nLength > CSRSS_MAX_WRITE_CONSOLE_OUTPUT_ATTRIB ? CSRSS_MAX_WRITE_CONSOLE_OUTPUT_ATTRIB : nLength; Size = min(nLength, CSRSS_MAX_WRITE_CONSOLE_OUTPUT_ATTRIB / sizeof(WORD));
Request->Data.WriteConsoleOutputAttribRequest.Length = Size; Request.Data.WriteConsoleOutputAttribRequest.Length = Size;
for( c = 0; c < Size; c++ ) memcpy(Request.Data.WriteConsoleOutputAttribRequest.Attribute, lpAttribute, Size * sizeof(WORD));
Request->Data.WriteConsoleOutputAttribRequest.String[c] = (char)lpAttribute[c];
Status = CsrClientCallServer( Request, NULL, CsrRequest, sizeof( CSR_API_MESSAGE ) + (Size * 2)); Status = CsrClientCallServer( &Request, NULL, CsrRequest, sizeof(CSR_API_MESSAGE));
if( !NT_SUCCESS( Status ) || !NT_SUCCESS( Status = Request->Status ) ) if( !NT_SUCCESS( Status ) || !NT_SUCCESS( Status = Request.Status ) )
{ {
RtlFreeHeap( GetProcessHeap(), 0, Request );
SetLastErrorByStatus ( Status ); SetLastErrorByStatus ( Status );
return FALSE; return FALSE;
} }
nLength -= Size; nLength -= Size;
lpAttribute += Size; lpAttribute += Size;
Request->Data.WriteConsoleOutputAttribRequest.Coord = Request->Data.WriteConsoleOutputAttribRequest.EndCoord; Request.Data.WriteConsoleOutputAttribRequest.Coord = Request.Data.WriteConsoleOutputAttribRequest.EndCoord;
} }
RtlFreeHeap( GetProcessHeap(), 0, Request );
return TRUE; return TRUE;
} }
@ -2971,7 +2879,7 @@ GetConsoleTitleW(
DWORD nSize DWORD nSize
) )
{ {
PCSR_API_MESSAGE Request; ULONG CsrRequest; CSR_API_MESSAGE Request; ULONG CsrRequest;
NTSTATUS Status; NTSTATUS Status;
HANDLE hConsole; HANDLE hConsole;
@ -2981,42 +2889,32 @@ GetConsoleTitleW(
return 0; return 0;
} }
Request = RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CSR_API_MESSAGE) + CSRSS_MAX_TITLE_LENGTH * sizeof(WCHAR));
if(Request == NULL)
{
CloseHandle(hConsole);
SetLastError(ERROR_OUTOFMEMORY);
return 0;
}
CsrRequest = MAKE_CSR_API(GET_TITLE, CSR_CONSOLE); CsrRequest = MAKE_CSR_API(GET_TITLE, CSR_CONSOLE);
Request->Data.GetTitleRequest.ConsoleHandle = hConsole; Request.Data.GetTitleRequest.ConsoleHandle = hConsole;
Status = CsrClientCallServer(Request, Status = CsrClientCallServer(&Request,
NULL, NULL,
CsrRequest, CsrRequest,
sizeof(CSR_API_MESSAGE) + CSRSS_MAX_TITLE_LENGTH * sizeof(WCHAR)); sizeof(CSR_API_MESSAGE));
CloseHandle(hConsole); CloseHandle(hConsole);
if(!NT_SUCCESS(Status) || !(NT_SUCCESS(Status = Request->Status))) if(!NT_SUCCESS(Status) || !(NT_SUCCESS(Status = Request.Status)))
{ {
SetLastErrorByStatus(Status); SetLastErrorByStatus(Status);
RtlFreeHeap(GetProcessHeap(), 0, Request);
return 0; return 0;
} }
if(nSize * sizeof(WCHAR) < Request->Data.GetTitleRequest.Length) if(nSize * sizeof(WCHAR) < Request.Data.GetTitleRequest.Length)
{ {
wcsncpy(lpConsoleTitle, Request->Data.GetTitleRequest.Title, nSize - 1); wcsncpy(lpConsoleTitle, Request.Data.GetTitleRequest.Title, nSize - 1);
lpConsoleTitle[nSize--] = L'\0'; lpConsoleTitle[nSize--] = L'\0';
} }
else else
{ {
nSize = Request->Data.GetTitleRequest.Length / sizeof (WCHAR); nSize = Request.Data.GetTitleRequest.Length / sizeof (WCHAR);
wcscpy(lpConsoleTitle, Request->Data.GetTitleRequest.Title); wcscpy(lpConsoleTitle, Request.Data.GetTitleRequest.Title);
lpConsoleTitle[nSize] = L'\0'; lpConsoleTitle[nSize] = L'\0';
} }
RtlFreeHeap(GetProcessHeap(), 0, Request);
return nSize; return nSize;
} }
@ -3073,7 +2971,7 @@ SetConsoleTitleW(
LPCWSTR lpConsoleTitle LPCWSTR lpConsoleTitle
) )
{ {
PCSR_API_MESSAGE Request; ULONG CsrRequest; CSR_API_MESSAGE Request; ULONG CsrRequest;
NTSTATUS Status; NTSTATUS Status;
unsigned int c; unsigned int c;
HANDLE hConsole; HANDLE hConsole;
@ -3084,37 +2982,24 @@ SetConsoleTitleW(
return FALSE; return FALSE;
} }
Request = RtlAllocateHeap(GetProcessHeap(),
HEAP_ZERO_MEMORY,
sizeof(CSR_API_MESSAGE) + CSRSS_MAX_SET_TITLE);
if (Request == NULL)
{
CloseHandle(hConsole);
SetLastError(ERROR_OUTOFMEMORY);
return(FALSE);
}
CsrRequest = MAKE_CSR_API(SET_TITLE, CSR_CONSOLE); CsrRequest = MAKE_CSR_API(SET_TITLE, CSR_CONSOLE);
Request->Data.SetTitleRequest.Console = hConsole; Request.Data.SetTitleRequest.Console = hConsole;
for( c = 0; lpConsoleTitle[c] && c < CSRSS_MAX_TITLE_LENGTH; c++ ) for( c = 0; lpConsoleTitle[c] && c < CSRSS_MAX_TITLE_LENGTH; c++ )
Request->Data.SetTitleRequest.Title[c] = lpConsoleTitle[c]; Request.Data.SetTitleRequest.Title[c] = lpConsoleTitle[c];
// add null // add null
Request->Data.SetTitleRequest.Title[c] = 0; Request.Data.SetTitleRequest.Title[c] = 0;
Request->Data.SetTitleRequest.Length = c; Request.Data.SetTitleRequest.Length = c;
Status = CsrClientCallServer(Request, Status = CsrClientCallServer(&Request,
NULL, NULL,
CsrRequest, CsrRequest,
sizeof(CSR_API_MESSAGE) + sizeof(CSR_API_MESSAGE));
c * sizeof(WCHAR));
CloseHandle(hConsole); CloseHandle(hConsole);
if (!NT_SUCCESS(Status) || !NT_SUCCESS( Status = Request->Status ) ) if (!NT_SUCCESS(Status) || !NT_SUCCESS( Status = Request.Status ) )
{ {
RtlFreeHeap( GetProcessHeap(), 0, Request );
SetLastErrorByStatus (Status); SetLastErrorByStatus (Status);
return(FALSE); return(FALSE);
} }
RtlFreeHeap( GetProcessHeap(), 0, Request );
return TRUE; return TRUE;
} }
@ -3132,7 +3017,7 @@ SetConsoleTitleA(
LPCSTR lpConsoleTitle LPCSTR lpConsoleTitle
) )
{ {
PCSR_API_MESSAGE Request; ULONG CsrRequest; CSR_API_MESSAGE Request; ULONG CsrRequest;
NTSTATUS Status; NTSTATUS Status;
unsigned int c; unsigned int c;
HANDLE hConsole; HANDLE hConsole;
@ -3143,37 +3028,24 @@ SetConsoleTitleA(
return FALSE; return FALSE;
} }
Request = RtlAllocateHeap(GetProcessHeap(),
HEAP_ZERO_MEMORY,
sizeof(CSR_API_MESSAGE) + CSRSS_MAX_SET_TITLE);
if (Request == NULL)
{
CloseHandle(hConsole);
SetLastError(ERROR_OUTOFMEMORY);
return(FALSE);
}
CsrRequest = MAKE_CSR_API(SET_TITLE, CSR_CONSOLE); CsrRequest = MAKE_CSR_API(SET_TITLE, CSR_CONSOLE);
Request->Data.SetTitleRequest.Console = hConsole; Request.Data.SetTitleRequest.Console = hConsole;
for( c = 0; lpConsoleTitle[c] && c < CSRSS_MAX_TITLE_LENGTH; c++ ) for( c = 0; lpConsoleTitle[c] && c < CSRSS_MAX_TITLE_LENGTH; c++ )
Request->Data.SetTitleRequest.Title[c] = lpConsoleTitle[c]; Request.Data.SetTitleRequest.Title[c] = lpConsoleTitle[c];
// add null // add null
Request->Data.SetTitleRequest.Title[c] = 0; Request.Data.SetTitleRequest.Title[c] = 0;
Request->Data.SetTitleRequest.Length = c; Request.Data.SetTitleRequest.Length = c;
Status = CsrClientCallServer(Request, Status = CsrClientCallServer(&Request,
NULL, NULL,
CsrRequest, CsrRequest,
sizeof(CSR_API_MESSAGE) + sizeof(CSR_API_MESSAGE));
c * sizeof(WCHAR));
CloseHandle(hConsole); CloseHandle(hConsole);
if (!NT_SUCCESS(Status) || !NT_SUCCESS( Status = Request->Status ) ) if (!NT_SUCCESS(Status) || !NT_SUCCESS( Status = Request.Status ) )
{ {
RtlFreeHeap( GetProcessHeap(), 0, Request );
SetLastErrorByStatus (Status); SetLastErrorByStatus (Status);
return(FALSE); return(FALSE);
} }
RtlFreeHeap( GetProcessHeap(), 0, Request );
return TRUE; return TRUE;
} }
@ -3322,8 +3194,8 @@ DWORD STDCALL
GetConsoleProcessList(LPDWORD lpdwProcessList, GetConsoleProcessList(LPDWORD lpdwProcessList,
DWORD dwProcessCount) DWORD dwProcessCount)
{ {
PCSR_API_MESSAGE Request; ULONG CsrRequest; CSR_API_MESSAGE Request; ULONG CsrRequest;
ULONG BufferSize, nProcesses; ULONG nProcesses;
NTSTATUS Status; NTSTATUS Status;
if(lpdwProcessList == NULL || dwProcessCount == 0) if(lpdwProcessList == NULL || dwProcessCount == 0)
@ -3332,47 +3204,34 @@ GetConsoleProcessList(LPDWORD lpdwProcessList,
return 0; return 0;
} }
BufferSize = sizeof(CSR_API_MESSAGE) +
(dwProcessCount * sizeof(Request->Data.GetProcessListRequest.ProcessId[0]));
Request = RtlAllocateHeap(GetProcessHeap(), 0, BufferSize);
if(Request == NULL)
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return 0;
}
Request->Status = STATUS_SUCCESS;
CsrRequest = MAKE_CSR_API(GET_PROCESS_LIST, CSR_CONSOLE); CsrRequest = MAKE_CSR_API(GET_PROCESS_LIST, CSR_CONSOLE);
Request->Data.GetProcessListRequest.nMaxIds = dwProcessCount; Request.Data.GetProcessListRequest.nMaxIds = dwProcessCount;
Status = CsrClientCallServer(Request, Status = CsrClientCallServer(&Request,
NULL, NULL,
CsrRequest, CsrRequest,
BufferSize); sizeof(CSR_API_MESSAGE));
if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request->Status)) if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
{ {
SetLastErrorByStatus (Status); SetLastErrorByStatus (Status);
nProcesses = 0; nProcesses = 0;
} }
else else
{ {
if(dwProcessCount >= Request->Data.GetProcessListRequest.nProcessIdsTotal) if(dwProcessCount >= Request.Data.GetProcessListRequest.nProcessIdsTotal)
{ {
nProcesses = Request->Data.GetProcessListRequest.nProcessIdsCopied; nProcesses = Request.Data.GetProcessListRequest.nProcessIdsCopied;
for(nProcesses = 0; nProcesses < Request->Data.GetProcessListRequest.nProcessIdsCopied; nProcesses++) for(nProcesses = 0; nProcesses < Request.Data.GetProcessListRequest.nProcessIdsCopied; nProcesses++)
{ {
*(lpdwProcessList++) = (DWORD)Request->Data.GetProcessListRequest.ProcessId[nProcesses]; *(lpdwProcessList++) = (DWORD)Request.Data.GetProcessListRequest.ProcessId[nProcesses];
} }
} }
else else
{ {
nProcesses = Request->Data.GetProcessListRequest.nProcessIdsTotal; nProcesses = Request.Data.GetProcessListRequest.nProcessIdsTotal;
} }
} }
RtlFreeHeap(GetProcessHeap(), 0, Request);
return nProcesses; return nProcesses;
} }

View file

@ -346,7 +346,9 @@ CSR_API(CsrAllocConsole)
DPRINT("CSRSS:CtrlDispatcher address: %x\n", ProcessData->CtrlDispatcher); DPRINT("CSRSS:CtrlDispatcher address: %x\n", ProcessData->CtrlDispatcher);
/* Insert into the list */ /* Insert into the list */
////////////////////////////
InsertHeadList(&ProcessData->Console->ProcessList, &ProcessData->ProcessEntry); InsertHeadList(&ProcessData->Console->ProcessList, &ProcessData->ProcessEntry);
///////////////////////////
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
@ -922,7 +924,7 @@ CSR_API(CsrWriteConsole)
DPRINT("CsrWriteConsole\n"); DPRINT("CsrWriteConsole\n");
if (Request->Header.u1.s1.DataLength if (Request->Header.u1.s1.DataLength
< sizeof(CSRSS_WRITE_CONSOLE) - 1 < sizeof(CSRSS_WRITE_CONSOLE)
+ (Request->Data.WriteConsoleRequest.NrCharactersToWrite * CharSize)) + (Request->Data.WriteConsoleRequest.NrCharactersToWrite * CharSize))
{ {
DPRINT1("Invalid request size\n"); DPRINT1("Invalid request size\n");
@ -1557,7 +1559,7 @@ CSR_API(CsrWriteConsoleOutputChar)
CharSize = (Request->Data.WriteConsoleOutputCharRequest.Unicode ? sizeof(WCHAR) : sizeof(CHAR)); CharSize = (Request->Data.WriteConsoleOutputCharRequest.Unicode ? sizeof(WCHAR) : sizeof(CHAR));
if (Request->Header.u1.s1.DataLength if (Request->Header.u1.s1.DataLength
< sizeof(CSRSS_WRITE_CONSOLE_OUTPUT_CHAR) - 1 < sizeof(CSRSS_WRITE_CONSOLE_OUTPUT_CHAR)
+ (Request->Data.WriteConsoleOutputCharRequest.Length * CharSize)) + (Request->Data.WriteConsoleOutputCharRequest.Length * CharSize))
{ {
DPRINT1("Invalid request size\n"); DPRINT1("Invalid request size\n");
@ -1714,7 +1716,8 @@ CSR_API(CsrFillOutputChar)
{ {
ConioUnlockConsole(Console); ConioUnlockConsole(Console);
} }
Length = Request->Data.FillOutputRequest.Length;
Request->Data.FillOutputRequest.NrCharactersWritten = Length;
return Request->Status; return Request->Status;
} }
@ -1801,7 +1804,8 @@ CSR_API(CsrWriteConsoleOutputAttrib)
{ {
PCSRSS_CONSOLE Console; PCSRSS_CONSOLE Console;
PCSRSS_SCREEN_BUFFER Buff; PCSRSS_SCREEN_BUFFER Buff;
PUCHAR Buffer, Attribute; PUCHAR Buffer;
PWORD Attribute;
int X, Y, Length; int X, Y, Length;
NTSTATUS Status; NTSTATUS Status;
RECT UpdateRect; RECT UpdateRect;
@ -1809,7 +1813,7 @@ CSR_API(CsrWriteConsoleOutputAttrib)
DPRINT("CsrWriteConsoleOutputAttrib\n"); DPRINT("CsrWriteConsoleOutputAttrib\n");
if (Request->Header.u1.s1.DataLength if (Request->Header.u1.s1.DataLength
< sizeof(CSRSS_WRITE_CONSOLE_OUTPUT_ATTRIB) - 1 < sizeof(CSRSS_WRITE_CONSOLE_OUTPUT_ATTRIB)
+ Request->Data.WriteConsoleOutputAttribRequest.Length) + Request->Data.WriteConsoleOutputAttribRequest.Length)
{ {
DPRINT1("Invalid request size\n"); DPRINT1("Invalid request size\n");
@ -1842,10 +1846,10 @@ CSR_API(CsrWriteConsoleOutputAttrib)
Y = (Request->Data.WriteConsoleOutputAttribRequest.Coord.Y + Buff->ShowY) % Buff->MaxY; Y = (Request->Data.WriteConsoleOutputAttribRequest.Coord.Y + Buff->ShowY) % Buff->MaxY;
Length = Request->Data.WriteConsoleOutputAttribRequest.Length; Length = Request->Data.WriteConsoleOutputAttribRequest.Length;
Buffer = &Buff->Buffer[2 * (Y * Buff->MaxX + X) + 1]; Buffer = &Buff->Buffer[2 * (Y * Buff->MaxX + X) + 1];
Attribute = (PUCHAR)Request->Data.WriteConsoleOutputAttribRequest.String; Attribute = Request->Data.WriteConsoleOutputAttribRequest.Attribute;
while (Length--) while (Length--)
{ {
*Buffer = *Attribute++; *Buffer = (UCHAR)(*Attribute++);
Buffer += 2; Buffer += 2;
if (++X == Buff->MaxX) if (++X == Buff->MaxX)
{ {
@ -2256,7 +2260,7 @@ CSR_API(CsrSetTitle)
DPRINT("CsrSetTitle\n"); DPRINT("CsrSetTitle\n");
if (Request->Header.u1.s1.DataLength if (Request->Header.u1.s1.DataLength
< sizeof(CSRSS_SET_TITLE) - 1 < sizeof(CSRSS_SET_TITLE)
+ Request->Data.SetTitleRequest.Length) + Request->Data.SetTitleRequest.Length)
{ {
DPRINT1("Invalid request size\n"); DPRINT1("Invalid request size\n");
@ -2662,14 +2666,14 @@ CSR_API(CsrReadConsoleOutputAttrib)
NTSTATUS Status; NTSTATUS Status;
PCSRSS_SCREEN_BUFFER Buff; PCSRSS_SCREEN_BUFFER Buff;
DWORD Xpos, Ypos; DWORD Xpos, Ypos;
CHAR* ReadBuffer; PWORD ReadBuffer;
DWORD i; DWORD i;
DPRINT("CsrReadConsoleOutputAttrib\n"); DPRINT("CsrReadConsoleOutputAttrib\n");
Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE);
Request->Header.u1.s1.DataLength = Request->Header.u1.s1.TotalLength - sizeof(PORT_MESSAGE); Request->Header.u1.s1.DataLength = Request->Header.u1.s1.TotalLength - sizeof(PORT_MESSAGE);
ReadBuffer = Request->Data.ReadConsoleOutputAttribRequest.String; ReadBuffer = Request->Data.ReadConsoleOutputAttribRequest.Attribute;
Status = ConioLockScreenBuffer(ProcessData, Request->Data.ReadConsoleOutputAttribRequest.ConsoleHandle, &Buff); Status = ConioLockScreenBuffer(ProcessData, Request->Data.ReadConsoleOutputAttribRequest.ConsoleHandle, &Buff);
if (! NT_SUCCESS(Status)) if (! NT_SUCCESS(Status))