Author: hbelusca
Date: Sun Nov 18 13:10:03 2012
New Revision: 57727
URL:
http://svn.reactos.org/svn/reactos?rev=57727&view=rev
Log:
[KERNEL32/CONSRV]
- Use new structures and api indices namings (as usual).
[CONSRV]
- Merge CSRSS_SET_TITLE and CSRSS_GET_TITLE into CSRSS_CONSOLE_TITLE.
- Merge CSRSS_GET_CONSOLE_(OUTPUT_)CP and CSRSS_SET_CONSOLE_(OUTPUT_)CP into
CSRSS_CONSOLE_CP.
- NtDuplicateObject(GetCurrentProcess(), ... ---> NtDuplicateObject(NtCurrentProcess(),
...
- Use CsrValidateMessageBuffer instead of Win32CsrValidateBuffer.
- Use CONSOLE_PROCESS_DATA structure.
TODO: Remove a DPRINT1 checkpoint in SrvAllocConsole after future tests are OK.
Modified:
branches/ros-csrss/dll/win32/kernel32/client/console/console.c
branches/ros-csrss/include/reactos/subsys/win/conmsg.h
branches/ros-csrss/win32ss/user/consrv/conoutput.c
branches/ros-csrss/win32ss/user/consrv/console.c
Modified: branches/ros-csrss/dll/win32/kernel32/client/console/console.c
URL:
http://svn.reactos.org/svn/reactos/branches/ros-csrss/dll/win32/kernel32/cl…
==============================================================================
--- branches/ros-csrss/dll/win32/kernel32/client/console/console.c [iso-8859-1]
(original)
+++ branches/ros-csrss/dll/win32/kernel32/client/console/console.c [iso-8859-1] Sun Nov 18
13:10:03 2012
@@ -1448,8 +1448,8 @@
GenerateConsoleCtrlEvent(DWORD dwCtrlEvent,
DWORD dwProcessGroupId)
{
- CSR_API_MESSAGE Request;
- NTSTATUS Status;
+ NTSTATUS Status;
+ CONSOLE_API_MESSAGE ApiMessage;
if (dwCtrlEvent != CTRL_C_EVENT && dwCtrlEvent != CTRL_BREAK_EVENT)
{
@@ -1457,14 +1457,14 @@
return FALSE;
}
- Request.Data.GenerateCtrlEvent.Event = dwCtrlEvent;
- Request.Data.GenerateCtrlEvent.ProcessGroup = dwProcessGroupId;
-
- Status = CsrClientCallServer(&Request,
- NULL,
- CSR_CREATE_API_NUMBER(CSR_CONSOLE,
GENERATE_CTRL_EVENT),
- sizeof(CSR_API_MESSAGE));
- if(!NT_SUCCESS(Status) || !(NT_SUCCESS(Status = Request.Status)))
+ ApiMessage.Data.GenerateCtrlEvent.Event = dwCtrlEvent;
+ ApiMessage.Data.GenerateCtrlEvent.ProcessGroup = dwProcessGroupId;
+
+ Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+ NULL,
+ CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX,
ConsolepGenerateCtrlEvent),
+ sizeof(CSRSS_GENERATE_CTRL_EVENT));
+ if(!NT_SUCCESS(Status) || !(NT_SUCCESS(Status = ApiMessage.Status)))
{
BaseSetLastNTError(Status);
return FALSE;
@@ -1477,15 +1477,16 @@
static DWORD
IntGetConsoleTitle(LPVOID lpConsoleTitle, DWORD nSize, BOOL bUnicode)
{
- CSR_API_MESSAGE Request;
+ NTSTATUS Status;
+ CONSOLE_API_MESSAGE ApiMessage;
+ PCSRSS_CONSOLE_TITLE TitleRequest = &ApiMessage.Data.TitleRequest;
PCSR_CAPTURE_BUFFER CaptureBuffer;
- NTSTATUS Status;
if (nSize == 0)
return 0;
- Request.Data.GetTitleRequest.Length = nSize * (bUnicode ? 1 : sizeof(WCHAR));
- CaptureBuffer = CsrAllocateCaptureBuffer(1, Request.Data.GetTitleRequest.Length);
+ TitleRequest->Length = nSize * (bUnicode ? 1 : sizeof(WCHAR));
+ CaptureBuffer = CsrAllocateCaptureBuffer(1, TitleRequest->Length);
if (CaptureBuffer == NULL)
{
DPRINT1("CsrAllocateCaptureBuffer failed!\n");
@@ -1494,14 +1495,14 @@
}
CsrAllocateMessagePointer(CaptureBuffer,
- Request.Data.GetTitleRequest.Length,
- (PVOID*)&Request.Data.GetTitleRequest.Title);
-
- Status = CsrClientCallServer(&Request,
+ TitleRequest->Length,
+ (PVOID*)&TitleRequest->Title);
+
+ Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
CaptureBuffer,
- CSR_CREATE_API_NUMBER(CSR_CONSOLE, GET_TITLE),
- sizeof(CSR_API_MESSAGE));
- if (!NT_SUCCESS(Status) || !(NT_SUCCESS(Status = Request.Status)))
+ CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX,
ConsolepGetTitle),
+ sizeof(CSRSS_CONSOLE_TITLE));
+ if (!NT_SUCCESS(Status) || !(NT_SUCCESS(Status = ApiMessage.Status)))
{
CsrFreeCaptureBuffer(CaptureBuffer);
BaseSetLastNTError(Status);
@@ -1511,14 +1512,14 @@
if (bUnicode)
{
if (nSize >= sizeof(WCHAR))
- wcscpy((LPWSTR)lpConsoleTitle, Request.Data.GetTitleRequest.Title);
+ wcscpy((LPWSTR)lpConsoleTitle, TitleRequest->Title);
}
else
{
- if (nSize < Request.Data.GetTitleRequest.Length / sizeof(WCHAR) ||
+ if (nSize < TitleRequest->Length / sizeof(WCHAR) ||
!WideCharToMultiByte(CP_ACP, // ANSI code page
0, // performance and mapping flags
- Request.Data.GetTitleRequest.Title, // address of
wide-character string
+ TitleRequest->Title, // address of wide-character
string
-1, // number of characters in string
(LPSTR)lpConsoleTitle, // address of buffer for new
string
nSize, // size of buffer
@@ -1527,13 +1528,14 @@
{
/* Yes, if the buffer isn't big enough, it returns 0... Bad API */
*(LPSTR)lpConsoleTitle = '\0';
- Request.Data.GetTitleRequest.Length = 0;
+ TitleRequest->Length = 0;
}
}
CsrFreeCaptureBuffer(CaptureBuffer);
- return Request.Data.GetTitleRequest.Length / sizeof(WCHAR);
-}
+ return TitleRequest->Length / sizeof(WCHAR);
+}
+
/*--------------------------------------------------------------
* GetConsoleTitleW
@@ -1548,6 +1550,7 @@
return IntGetConsoleTitle(lpConsoleTitle, nSize, TRUE);
}
+
/*--------------------------------------------------------------
* GetConsoleTitleA
*
@@ -1571,13 +1574,14 @@
WINAPI
SetConsoleTitleW(LPCWSTR lpConsoleTitle)
{
- CSR_API_MESSAGE Request;
+ NTSTATUS Status;
+ CONSOLE_API_MESSAGE ApiMessage;
+ PCSRSS_CONSOLE_TITLE TitleRequest = &ApiMessage.Data.TitleRequest;
PCSR_CAPTURE_BUFFER CaptureBuffer;
- NTSTATUS Status;
-
- Request.Data.SetTitleRequest.Length = wcslen(lpConsoleTitle) * sizeof(WCHAR);
-
- CaptureBuffer = CsrAllocateCaptureBuffer(1, Request.Data.SetTitleRequest.Length);
+
+ TitleRequest->Length = wcslen(lpConsoleTitle) * sizeof(WCHAR);
+
+ CaptureBuffer = CsrAllocateCaptureBuffer(1, TitleRequest->Length);
if (CaptureBuffer == NULL)
{
DPRINT1("CsrAllocateCaptureBuffer failed!\n");
@@ -1587,17 +1591,17 @@
CsrCaptureMessageBuffer(CaptureBuffer,
(PVOID)lpConsoleTitle,
- Request.Data.SetTitleRequest.Length,
- (PVOID*)&Request.Data.SetTitleRequest.Title);
-
- Status = CsrClientCallServer(&Request,
+ TitleRequest->Length,
+ (PVOID*)&TitleRequest->Title);
+
+ Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
CaptureBuffer,
- CSR_CREATE_API_NUMBER(CSR_CONSOLE, SET_TITLE),
- sizeof(CSR_API_MESSAGE));
+ CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX,
ConsolepSetTitle),
+ sizeof(CSRSS_CONSOLE_TITLE));
CsrFreeCaptureBuffer(CaptureBuffer);
- if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
+ if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = ApiMessage.Status))
{
BaseSetLastNTError(Status);
return FALSE;
@@ -1683,73 +1687,81 @@
WINAPI
GetConsoleCP(VOID)
{
- CSR_API_MESSAGE Request;
- NTSTATUS Status;
-
- Status = CsrClientCallServer(&Request,
- NULL,
- CSR_CREATE_API_NUMBER(CSR_CONSOLE, GET_CONSOLE_CP),
- sizeof(CSR_API_MESSAGE));
- if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
+ NTSTATUS Status;
+ CONSOLE_API_MESSAGE ApiMessage;
+
+ /* Get the Input Code Page */
+ ApiMessage.Data.ConsoleCPRequest.InputCP = TRUE;
+
+ Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+ NULL,
+ CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX,
ConsolepGetCP),
+ sizeof(CSRSS_CONSOLE_CP));
+ if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = ApiMessage.Status))
+ {
+ BaseSetLastNTError(Status);
+ return 0;
+ }
+
+ return ApiMessage.Data.ConsoleCPRequest.CodePage;
+}
+
+
+/*--------------------------------------------------------------
+ * SetConsoleCP
+ *
+ * @implemented
+ */
+BOOL
+WINAPI
+SetConsoleCP(UINT wCodePageID)
+{
+ NTSTATUS Status;
+ CONSOLE_API_MESSAGE ApiMessage;
+
+ /* Set the Input Code Page */
+ ApiMessage.Data.ConsoleCPRequest.InputCP = TRUE;
+ ApiMessage.Data.ConsoleCPRequest.CodePage = wCodePageID;
+
+ Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+ NULL,
+ CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX,
ConsolepSetCP),
+ sizeof(CSRSS_CONSOLE_CP));
+ if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = ApiMessage.Status))
+ {
+ BaseSetLastNTError(Status);
+ }
+
+ return NT_SUCCESS(Status);
+}
+
+
+/*--------------------------------------------------------------
+ * GetConsoleOutputCP
+ *
+ * @implemented
+ */
+UINT
+WINAPI
+GetConsoleOutputCP(VOID)
+{
+ NTSTATUS Status;
+ CONSOLE_API_MESSAGE ApiMessage;
+
+ /* Get the Output Code Page */
+ ApiMessage.Data.ConsoleCPRequest.InputCP = FALSE;
+
+ Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+ NULL,
+ CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX,
ConsolepGetCP),
+ sizeof(CSRSS_CONSOLE_CP));
+ if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = ApiMessage.Status))
{
BaseSetLastNTError (Status);
return 0;
}
- return Request.Data.GetConsoleCodePage.CodePage;
-}
-
-
-/*--------------------------------------------------------------
- * SetConsoleCP
- *
- * @implemented
- */
-BOOL
-WINAPI
-SetConsoleCP(UINT wCodePageID)
-{
- CSR_API_MESSAGE Request;
- NTSTATUS Status;
-
- Request.Data.SetConsoleCodePage.CodePage = wCodePageID;
-
- Status = CsrClientCallServer(&Request,
- NULL,
- CSR_CREATE_API_NUMBER(CSR_CONSOLE, SET_CONSOLE_CP),
- sizeof(CSR_API_MESSAGE));
- if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
- {
- BaseSetLastNTError(Status);
- }
-
- return NT_SUCCESS(Status);
-}
-
-
-/*--------------------------------------------------------------
- * GetConsoleOutputCP
- *
- * @implemented
- */
-UINT
-WINAPI
-GetConsoleOutputCP(VOID)
-{
- CSR_API_MESSAGE Request;
- NTSTATUS Status;
-
- Status = CsrClientCallServer(&Request,
- NULL,
- CSR_CREATE_API_NUMBER(CSR_CONSOLE,
GET_CONSOLE_OUTPUT_CP),
- sizeof(CSR_API_MESSAGE));
- if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
- {
- BaseSetLastNTError (Status);
- return 0;
- }
-
- return Request.Data.GetConsoleOutputCodePage.CodePage;
+ return ApiMessage.Data.ConsoleCPRequest.CodePage;
}
@@ -1762,16 +1774,18 @@
WINAPI
SetConsoleOutputCP(UINT wCodePageID)
{
- CSR_API_MESSAGE Request;
- NTSTATUS Status;
-
- Request.Data.SetConsoleOutputCodePage.CodePage = wCodePageID;
-
- Status = CsrClientCallServer(&Request,
- NULL,
- CSR_CREATE_API_NUMBER(CSR_CONSOLE,
SET_CONSOLE_OUTPUT_CP),
- sizeof(CSR_API_MESSAGE));
- if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
+ NTSTATUS Status;
+ CONSOLE_API_MESSAGE ApiMessage;
+
+ /* Set the Output Code Page */
+ ApiMessage.Data.ConsoleCPRequest.InputCP = FALSE;
+ ApiMessage.Data.ConsoleCPRequest.CodePage = wCodePageID;
+
+ Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+ NULL,
+ CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX,
ConsolepSetCP),
+ sizeof(CSRSS_CONSOLE_CP));
+ if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = ApiMessage.Status))
{
BaseSetLastNTError(Status);
}
@@ -1790,10 +1804,11 @@
GetConsoleProcessList(LPDWORD lpdwProcessList,
DWORD dwProcessCount)
{
+ NTSTATUS Status;
+ CONSOLE_API_MESSAGE ApiMessage;
+ PCSRSS_GET_PROCESS_LIST GetProcessListRequest =
&ApiMessage.Data.GetProcessListRequest;
PCSR_CAPTURE_BUFFER CaptureBuffer;
- CSR_API_MESSAGE Request;
ULONG nProcesses;
- NTSTATUS Status;
if (lpdwProcessList == NULL || dwProcessCount == 0)
{
@@ -1809,26 +1824,27 @@
return FALSE;
}
- Request.Data.GetProcessListRequest.nMaxIds = dwProcessCount;
+ GetProcessListRequest->nMaxIds = dwProcessCount;
+
CsrAllocateMessagePointer(CaptureBuffer,
dwProcessCount * sizeof(DWORD),
-
(PVOID*)&Request.Data.GetProcessListRequest.ProcessId);
-
- Status = CsrClientCallServer(&Request,
+ (PVOID*)&GetProcessListRequest->pProcessIds);
+
+ Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
CaptureBuffer,
- CSR_CREATE_API_NUMBER(CSR_CONSOLE, GET_PROCESS_LIST),
- sizeof(CSR_API_MESSAGE));
- if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
+ CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX,
ConsolepGetProcessList),
+ sizeof(CSRSS_GET_PROCESS_LIST));
+ if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = ApiMessage.Status))
{
BaseSetLastNTError (Status);
nProcesses = 0;
}
else
{
- nProcesses = Request.Data.GetProcessListRequest.nProcessIdsTotal;
+ nProcesses = GetProcessListRequest->nProcessIdsTotal;
if (dwProcessCount >= nProcesses)
{
- memcpy(lpdwProcessList, Request.Data.GetProcessListRequest.ProcessId,
nProcesses * sizeof(DWORD));
+ memcpy(lpdwProcessList, GetProcessListRequest->pProcessIds, nProcesses *
sizeof(DWORD));
}
}
@@ -2136,7 +2152,7 @@
BOOL
WINAPI
-RegisterConsoleIME(HWND hWnd, LPDWORD ThreadId)
+SetConsoleCursorMode(HANDLE hConsole, BOOL Unknown1, BOOL Unknown2)
{
STUB;
return FALSE;
@@ -2144,7 +2160,7 @@
BOOL
WINAPI
-RegisterConsoleOS2(BOOL bUnknown)
+SetConsoleLocalEUDC(DWORD Unknown1, DWORD Unknown2, DWORD Unknown3, DWORD Unknown4)
{
STUB;
return FALSE;
@@ -2152,7 +2168,7 @@
BOOL
WINAPI
-SetConsoleCursorMode(HANDLE hConsole, BOOL Unknown1, BOOL Unknown2)
+SetConsoleNlsMode(HANDLE hConsole, DWORD dwMode)
{
STUB;
return FALSE;
@@ -2160,7 +2176,7 @@
BOOL
WINAPI
-SetConsoleLocalEUDC(DWORD Unknown1, DWORD Unknown2, DWORD Unknown3, DWORD Unknown4)
+RegisterConsoleIME(HWND hWnd, LPDWORD ThreadId)
{
STUB;
return FALSE;
@@ -2168,7 +2184,7 @@
BOOL
WINAPI
-SetConsoleNlsMode(HANDLE hConsole, DWORD dwMode)
+RegisterConsoleOS2(BOOL bUnknown)
{
STUB;
return FALSE;
Modified: branches/ros-csrss/include/reactos/subsys/win/conmsg.h
URL:
http://svn.reactos.org/svn/reactos/branches/ros-csrss/include/reactos/subsy…
==============================================================================
--- branches/ros-csrss/include/reactos/subsys/win/conmsg.h [iso-8859-1] (original)
+++ branches/ros-csrss/include/reactos/subsys/win/conmsg.h [iso-8859-1] Sun Nov 18
13:10:03 2012
@@ -126,7 +126,7 @@
typedef struct
{
USHORT nMaxIds;
- PDWORD ProcessId;
+ PDWORD pProcessIds;
ULONG nProcessIdsTotal;
} CSRSS_GET_PROCESS_LIST, *PCSRSS_GET_PROCESS_LIST;
@@ -260,13 +260,7 @@
{
DWORD Length;
PWCHAR Title;
-} CSRSS_SET_TITLE, *PCSRSS_SET_TITLE;
-
-typedef struct
-{
- DWORD Length;
- PWCHAR Title;
-} CSRSS_GET_TITLE, *PCSRSS_GET_TITLE;
+} CSRSS_CONSOLE_TITLE, *PCSRSS_CONSOLE_TITLE;
typedef struct
{
@@ -540,23 +534,9 @@
typedef struct
{
+ BOOL InputCP; // TRUE : Input Code Page ; FALSE : Output Code Page
UINT CodePage;
-} CSRSS_GET_CONSOLE_CP, *PCSRSS_GET_CONSOLE_CP;
-
-typedef struct
-{
- UINT CodePage;
-} CSRSS_SET_CONSOLE_CP, *PCSRSS_SET_CONSOLE_CP;
-
-typedef struct
-{
- UINT CodePage;
-} CSRSS_GET_CONSOLE_OUTPUT_CP, *PCSRSS_GET_CONSOLE_OUTPUT_CP;
-
-typedef struct
-{
- UINT CodePage;
-} CSRSS_SET_CONSOLE_OUTPUT_CP, *PCSRSS_SET_CONSOLE_OUTPUT_CP;
+} CSRSS_CONSOLE_CP, *PCSRSS_CONSOLE_CP;
typedef struct _CONSOLE_API_MESSAGE
{
@@ -597,8 +577,7 @@
CSRSS_CONSOLE_HW_STATE ConsoleHardwareStateRequest;
/* Console window */
- CSRSS_SET_TITLE SetTitleRequest;
- CSRSS_GET_TITLE GetTitleRequest;
+ CSRSS_CONSOLE_TITLE TitleRequest;
CSRSS_GET_CONSOLE_WINDOW GetConsoleWindowRequest;
CSRSS_SET_CONSOLE_ICON SetConsoleIconRequest;
@@ -636,11 +615,8 @@
CSRSS_GENERATE_CTRL_EVENT GenerateCtrlEvent;
CSRSS_GET_NUM_INPUT_EVENTS GetNumInputEventsRequest;
- /* CodePage */
- CSRSS_GET_CONSOLE_CP GetConsoleCodePage;
- CSRSS_SET_CONSOLE_CP SetConsoleCodePage;
- CSRSS_GET_CONSOLE_OUTPUT_CP GetConsoleOutputCodePage;
- CSRSS_SET_CONSOLE_OUTPUT_CP SetConsoleOutputCodePage;
+ /* Input and Output Code Pages */
+ CSRSS_CONSOLE_CP ConsoleCPRequest;
CSRSS_GET_PROCESS_LIST GetProcessListRequest;
} Data;
Modified: branches/ros-csrss/win32ss/user/consrv/conoutput.c
URL:
http://svn.reactos.org/svn/reactos/branches/ros-csrss/win32ss/user/consrv/c…
==============================================================================
--- branches/ros-csrss/win32ss/user/consrv/conoutput.c [iso-8859-1] (original)
+++ branches/ros-csrss/win32ss/user/consrv/conoutput.c [iso-8859-1] Sun Nov 18 13:10:03
2012
@@ -556,7 +556,7 @@
if (Console->UnpauseEvent)
{
- Status = NtDuplicateObject(GetCurrentProcess(), Console->UnpauseEvent,
+ Status = NtDuplicateObject(NtCurrentProcess(), Console->UnpauseEvent,
ProcessData->ProcessHandle,
&WriteConsoleRequest->UnpauseEvent,
SYNCHRONIZE, 0, 0);
ConioUnlockScreenBuffer(Buff);
Modified: branches/ros-csrss/win32ss/user/consrv/console.c
URL:
http://svn.reactos.org/svn/reactos/branches/ros-csrss/win32ss/user/consrv/c…
==============================================================================
--- branches/ros-csrss/win32ss/user/consrv/console.c [iso-8859-1] (original)
+++ branches/ros-csrss/win32ss/user/consrv/console.c [iso-8859-1] Sun Nov 18 13:10:03
2012
@@ -62,7 +62,7 @@
{
HANDLE Thread;
- DPRINT("ConioConsoleCtrlEvent Parent ProcessId = %x\n",
ProcessData->Process->ClientId.UniqueProcess);
+ DPRINT("ConioConsoleCtrlEvent Parent pProcessIds = %x\n",
ProcessData->Process->ClientId.UniqueProcess);
if (ProcessData->CtrlDispatcher)
{
@@ -250,15 +250,16 @@
CSR_API(SrvAllocConsole)
{
+ NTSTATUS Status = STATUS_SUCCESS;
PCSRSS_ALLOC_CONSOLE AllocConsoleRequest =
&((PCONSOLE_API_MESSAGE)ApiMessage)->Data.AllocConsoleRequest;
- PCSR_PROCESS ProcessData = CsrGetClientThread()->Process;
- PCSRSS_CONSOLE Console;
- NTSTATUS Status = STATUS_SUCCESS;
+ PCONSOLE_PROCESS_DATA ProcessData =
ConsoleGetPerProcessData(CsrGetClientThread()->Process);
+ PCSRSS_CONSOLE Console;
BOOLEAN NewConsole = FALSE;
DPRINT("SrvAllocConsole\n");
RtlEnterCriticalSection(&ProcessData->HandleTableLock);
+
if (ProcessData->Console)
{
DPRINT1("Process already has a console\n");
@@ -266,6 +267,8 @@
return STATUS_INVALID_PARAMETER;
}
+ DPRINT1("SrvAllocConsole - Checkpoint 1\n");
+
/* If we don't need a console, then get out of here */
if (!AllocConsoleRequest->ConsoleNeeded)
{
@@ -276,7 +279,7 @@
/* If we already have one, then don't create a new one... */
if (!AllocConsoleRequest->Console ||
- AllocConsoleRequest->Console != ProcessData->ParentConsole)
+ AllocConsoleRequest->Console != ProcessData->ParentConsole)
{
/* Allocate a console structure */
NewConsole = TRUE;
@@ -287,10 +290,13 @@
RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
return STATUS_NO_MEMORY;
}
- /* initialize list head */
+
+ /* Initialize list head */
InitializeListHead(&Console->ProcessList);
- /* insert process data required for GUI initialization */
+
+ /* Insert process data required for GUI initialization */
InsertHeadList(&Console->ProcessList, &ProcessData->ConsoleLink);
+
/* Initialize the Console */
Status = CsrInitConsole(Console, AllocConsoleRequest->ShowCmd);
if (!NT_SUCCESS(Status))
@@ -329,7 +335,7 @@
{
DPRINT1("Failed to insert object\n");
ConioDeleteConsole((Object_t *) Console);
- ProcessData->Console = 0;
+ ProcessData->Console = NULL;
RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
return Status;
}
@@ -346,22 +352,21 @@
ConioDeleteConsole((Object_t *) Console);
Win32CsrReleaseObject(ProcessData,
AllocConsoleRequest->InputHandle);
- ProcessData->Console = 0;
+ ProcessData->Console = NULL;
RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
return Status;
}
}
/* Duplicate the Event */
- if (!DuplicateHandle(GetCurrentProcess(),
- ProcessData->Console->ActiveEvent,
- ProcessData->ProcessHandle,
- &ProcessData->ConsoleEvent,
- EVENT_ALL_ACCESS,
- FALSE,
- 0))
- {
- DPRINT1("DuplicateHandle() failed: %lu\n", GetLastError());
+ Status = NtDuplicateObject(NtCurrentProcess(),
+ ProcessData->Console->ActiveEvent,
+ ProcessData->Process->ProcessHandle,
+ &ProcessData->ConsoleEvent,
+ EVENT_ALL_ACCESS, 0, 0);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT1("NtDuplicateObject() failed: %lu\n", Status);
ConioDeleteConsole((Object_t *) Console);
if (NewConsole || !ProcessData->bInheritHandles)
{
@@ -370,7 +375,7 @@
Win32CsrReleaseObject(ProcessData,
AllocConsoleRequest->InputHandle);
}
- ProcessData->Console = 0;
+ ProcessData->Console = NULL;
RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
return Status;
}
@@ -531,31 +536,41 @@
CSR_API(SrvSetConsoleTitle)
{
NTSTATUS Status;
- PCSRSS_SET_TITLE SetTitleRequest =
&((PCONSOLE_API_MESSAGE)ApiMessage)->Data.SetTitleRequest;
- PCSR_PROCESS ProcessData = CsrGetClientThread()->Process;
+ PCSRSS_CONSOLE_TITLE TitleRequest =
&((PCONSOLE_API_MESSAGE)ApiMessage)->Data.TitleRequest;
+ // PCSR_PROCESS Process = CsrGetClientThread()->Process;
PCSRSS_CONSOLE Console;
PWCHAR Buffer;
DPRINT("SrvSetConsoleTitle\n");
- if (!Win32CsrValidateBuffer(ProcessData, SetTitleRequest->Title,
- SetTitleRequest->Length, 1))
+ if (!CsrValidateMessageBuffer(ApiMessage,
+ (PVOID)&TitleRequest->Title,
+ TitleRequest->Length,
+ sizeof(BYTE)))
+ {
+ return STATUS_INVALID_PARAMETER;
+ }
+/*
+ if (!Win32CsrValidateBuffer(Process, TitleRequest->Title,
+ TitleRequest->Length, 1))
{
return STATUS_ACCESS_VIOLATION;
}
-
- Status = ConioConsoleFromProcessData(ProcessData, &Console);
+*/
+
+ Status =
ConioConsoleFromProcessData(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
&Console);
if(NT_SUCCESS(Status))
{
- Buffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, SetTitleRequest->Length);
+ Buffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, TitleRequest->Length);
if (Buffer)
{
- /* copy title to console */
+ /* Copy title to console */
RtlFreeUnicodeString(&Console->Title);
Console->Title.Buffer = Buffer;
- Console->Title.Length = Console->Title.MaximumLength =
SetTitleRequest->Length;
- memcpy(Console->Title.Buffer, SetTitleRequest->Title,
Console->Title.Length);
- if (! ConioChangeTitle(Console))
+ Console->Title.Length = Console->Title.MaximumLength =
TitleRequest->Length;
+ memcpy(Console->Title.Buffer, TitleRequest->Title,
Console->Title.Length);
+
+ if (!ConioChangeTitle(Console))
{
Status = STATUS_UNSUCCESSFUL;
}
@@ -568,6 +583,7 @@
{
Status = STATUS_NO_MEMORY;
}
+
ConioUnlockConsole(Console);
}
@@ -577,35 +593,44 @@
CSR_API(SrvGetConsoleTitle)
{
NTSTATUS Status;
- PCSRSS_GET_TITLE GetTitleRequest =
&((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetTitleRequest;
- PCSR_PROCESS ProcessData = CsrGetClientThread()->Process;
+ PCSRSS_CONSOLE_TITLE TitleRequest =
&((PCONSOLE_API_MESSAGE)ApiMessage)->Data.TitleRequest;
+ // PCSR_PROCESS Process = CsrGetClientThread()->Process;
PCSRSS_CONSOLE Console;
DWORD Length;
DPRINT("SrvGetConsoleTitle\n");
- if (!Win32CsrValidateBuffer(ProcessData, GetTitleRequest->Title,
- GetTitleRequest->Length, 1))
+ if (!CsrValidateMessageBuffer(ApiMessage,
+ (PVOID)&TitleRequest->Title,
+ TitleRequest->Length,
+ sizeof(BYTE)))
+ {
+ return STATUS_INVALID_PARAMETER;
+ }
+/*
+ if (!Win32CsrValidateBuffer(Process, TitleRequest->Title,
+ TitleRequest->Length, 1))
{
return STATUS_ACCESS_VIOLATION;
}
-
- Status = ConioConsoleFromProcessData(ProcessData, &Console);
- if (! NT_SUCCESS(Status))
+*/
+
+ Status =
ConioConsoleFromProcessData(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
&Console);
+ if (!NT_SUCCESS(Status))
{
DPRINT1("Can't get console\n");
return Status;
}
/* Copy title of the console to the user title buffer */
- if (GetTitleRequest->Length >= sizeof(WCHAR))
- {
- Length = min(GetTitleRequest->Length - sizeof(WCHAR),
Console->Title.Length);
- memcpy(GetTitleRequest->Title, Console->Title.Buffer, Length);
- GetTitleRequest->Title[Length / sizeof(WCHAR)] = L'\0';
- }
-
- GetTitleRequest->Length = Console->Title.Length;
+ if (TitleRequest->Length >= sizeof(WCHAR))
+ {
+ Length = min(TitleRequest->Length - sizeof(WCHAR), Console->Title.Length);
+ memcpy(TitleRequest->Title, Console->Title.Buffer, Length);
+ TitleRequest->Title[Length / sizeof(WCHAR)] = L'\0';
+ }
+
+ TitleRequest->Length = Console->Title.Length;
ConioUnlockConsole(Console);
return STATUS_SUCCESS;
@@ -699,17 +724,14 @@
CSR_API(SrvGetConsoleWindow)
{
+ NTSTATUS Status;
PCSRSS_GET_CONSOLE_WINDOW GetConsoleWindowRequest =
&((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetConsoleWindowRequest;
PCSRSS_CONSOLE Console;
- NTSTATUS Status;
DPRINT("SrvGetConsoleWindow\n");
- Status = ConioConsoleFromProcessData(CsrGetClientThread()->Process,
&Console);
- if (! NT_SUCCESS(Status))
- {
- return Status;
- }
+ Status =
ConioConsoleFromProcessData(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
&Console);
+ if (!NT_SUCCESS(Status)) return Status;
GetConsoleWindowRequest->WindowHandle = Console->hWindow;
ConioUnlockConsole(Console);
@@ -719,20 +741,19 @@
CSR_API(SrvSetConsoleIcon)
{
+ NTSTATUS Status;
PCSRSS_SET_CONSOLE_ICON SetConsoleIconRequest =
&((PCONSOLE_API_MESSAGE)ApiMessage)->Data.SetConsoleIconRequest;
PCSRSS_CONSOLE Console;
- NTSTATUS Status;
DPRINT("SrvSetConsoleIcon\n");
- Status = ConioConsoleFromProcessData(CsrGetClientThread()->Process,
&Console);
- if (! NT_SUCCESS(Status))
- {
- return Status;
- }
+ Status =
ConioConsoleFromProcessData(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
&Console);
+ if (!NT_SUCCESS(Status)) return Status;
Status = (ConioChangeIcon(Console, SetConsoleIconRequest->WindowIcon)
- ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL);
+ ? STATUS_SUCCESS
+ : STATUS_UNSUCCESSFUL);
+
ConioUnlockConsole(Console);
return Status;
@@ -740,59 +761,41 @@
CSR_API(SrvGetConsoleCP)
{
- PCSRSS_GET_CONSOLE_CP GetConsoleCodePage =
&((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetConsoleCodePage;
- PCSRSS_CONSOLE Console;
- NTSTATUS Status;
-
- DPRINT("SrvGetConsoleCP\n");
-
- Status = ConioConsoleFromProcessData(CsrGetClientThread()->Process,
&Console);
- if (! NT_SUCCESS(Status))
- {
- return Status;
- }
-
- GetConsoleCodePage->CodePage = Console->CodePage;
+ NTSTATUS Status;
+ PCSRSS_CONSOLE_CP ConsoleCPRequest =
&((PCONSOLE_API_MESSAGE)ApiMessage)->Data.ConsoleCPRequest;
+ PCSRSS_CONSOLE Console;
+
+ DPRINT("SrvGetConsoleCP, getting %s Code Page\n",
+ ConsoleCPRequest->InputCP ? "Input" : "Output");
+
+ Status =
ConioConsoleFromProcessData(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
&Console);
+ if (!NT_SUCCESS(Status)) return Status;
+
+ ConsoleCPRequest->CodePage = (ConsoleCPRequest->InputCP ? Console->CodePage
+ :
Console->OutputCodePage);
ConioUnlockConsole(Console);
return STATUS_SUCCESS;
}
-CSR_API(CsrGetConsoleOutputCodePage) // TODO: Merge this function with the other one.
-{
- PCSRSS_GET_CONSOLE_OUTPUT_CP GetConsoleOutputCodePage =
&((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetConsoleOutputCodePage;
- PCSRSS_CONSOLE Console;
- NTSTATUS Status;
-
- DPRINT("CsrGetConsoleOutputCodePage\n");
-
- Status = ConioConsoleFromProcessData(CsrGetClientThread()->Process,
&Console);
- if (! NT_SUCCESS(Status))
- {
- return Status;
- }
-
- GetConsoleOutputCodePage->CodePage = Console->OutputCodePage;
- ConioUnlockConsole(Console);
- return STATUS_SUCCESS;
-}
-
CSR_API(SrvSetConsoleCP)
{
- PCSRSS_SET_CONSOLE_CP SetConsoleCodePage =
&((PCONSOLE_API_MESSAGE)ApiMessage)->Data.SetConsoleCodePage;
- PCSRSS_CONSOLE Console;
- NTSTATUS Status;
-
- DPRINT("SrvSetConsoleCP\n");
-
- Status = ConioConsoleFromProcessData(CsrGetClientThread()->Process,
&Console);
- if (! NT_SUCCESS(Status))
- {
- return Status;
- }
-
- if (IsValidCodePage(SetConsoleCodePage->CodePage))
- {
- Console->CodePage = SetConsoleCodePage->CodePage;
+ NTSTATUS Status;
+ PCSRSS_CONSOLE_CP ConsoleCPRequest =
&((PCONSOLE_API_MESSAGE)ApiMessage)->Data.ConsoleCPRequest;
+ PCSRSS_CONSOLE Console;
+
+ DPRINT("SrvSetConsoleCP, setting %s Code Page\n",
+ ConsoleCPRequest->InputCP ? "Input" : "Output");
+
+ Status =
ConioConsoleFromProcessData(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
&Console);
+ if (!NT_SUCCESS(Status)) return Status;
+
+ if (IsValidCodePage(ConsoleCPRequest->CodePage))
+ {
+ if (ConsoleCPRequest->InputCP)
+ Console->CodePage = ConsoleCPRequest->CodePage;
+ else
+ Console->OutputCodePage = ConsoleCPRequest->CodePage;
+
ConioUnlockConsole(Console);
return STATUS_SUCCESS;
}
@@ -801,62 +804,45 @@
return STATUS_INVALID_PARAMETER;
}
-CSR_API(CsrSetConsoleOutputCodePage) // TODO: Merge this function with the other one.
-{
- PCSRSS_SET_CONSOLE_OUTPUT_CP SetConsoleOutputCodePage =
&((PCONSOLE_API_MESSAGE)ApiMessage)->Data.SetConsoleOutputCodePage;
- PCSRSS_CONSOLE Console;
- NTSTATUS Status;
-
- DPRINT("CsrSetConsoleOutputCodePage\n");
-
- Status = ConioConsoleFromProcessData(CsrGetClientThread()->Process,
&Console);
- if (! NT_SUCCESS(Status))
- {
- return Status;
- }
-
- if (IsValidCodePage(SetConsoleOutputCodePage->CodePage))
- {
- Console->OutputCodePage = SetConsoleOutputCodePage->CodePage;
- ConioUnlockConsole(Console);
- return STATUS_SUCCESS;
- }
-
- ConioUnlockConsole(Console);
- return STATUS_INVALID_PARAMETER;
-}
-
CSR_API(SrvGetConsoleProcessList)
{
+ NTSTATUS Status;
PCSRSS_GET_PROCESS_LIST GetProcessListRequest =
&((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetProcessListRequest;
PDWORD Buffer;
- PCSR_PROCESS ProcessData = CsrGetClientThread()->Process;
- PCSRSS_CONSOLE Console;
- PCSR_PROCESS current;
+ // PCSR_PROCESS Process = CsrGetClientThread()->Process;
+ PCSRSS_CONSOLE Console;
+ PCONSOLE_PROCESS_DATA current;
PLIST_ENTRY current_entry;
ULONG nItems = 0;
- NTSTATUS Status;
DPRINT("SrvGetConsoleProcessList\n");
- Buffer = GetProcessListRequest->ProcessId;
+ if (!CsrValidateMessageBuffer(ApiMessage,
+ (PVOID)&GetProcessListRequest->pProcessIds,
+ GetProcessListRequest->nMaxIds,
+ sizeof(DWORD)))
+ {
+ return STATUS_INVALID_PARAMETER;
+ }
+
+ Buffer = GetProcessListRequest->pProcessIds;
+
+/*
if (!Win32CsrValidateBuffer(ProcessData, Buffer, GetProcessListRequest->nMaxIds,
sizeof(DWORD)))
return STATUS_ACCESS_VIOLATION;
-
- Status = ConioConsoleFromProcessData(ProcessData, &Console);
- if (! NT_SUCCESS(Status))
- {
- return Status;
- }
+*/
+
+ Status =
ConioConsoleFromProcessData(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
&Console);
+ if (!NT_SUCCESS(Status)) return Status;
for (current_entry = Console->ProcessList.Flink;
current_entry != &Console->ProcessList;
current_entry = current_entry->Flink)
{
- current = CONTAINING_RECORD(current_entry, CSR_PROCESS, ConsoleLink);
+ current = CONTAINING_RECORD(current_entry, CONSOLE_PROCESS_DATA, ConsoleLink);
if (++nItems <= GetProcessListRequest->nMaxIds)
{
- *Buffer++ = HandleToUlong(current->ClientId.UniqueProcess);
+ *Buffer++ = HandleToUlong(current->Process->ClientId.UniqueProcess);
}
}
@@ -868,27 +854,24 @@
CSR_API(SrvGenerateConsoleCtrlEvent)
{
+ NTSTATUS Status;
PCSRSS_GENERATE_CTRL_EVENT GenerateCtrlEvent =
&((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GenerateCtrlEvent;
PCSRSS_CONSOLE Console;
- PCSR_PROCESS current;
+ PCONSOLE_PROCESS_DATA current;
PLIST_ENTRY current_entry;
DWORD Group;
- NTSTATUS Status;
-
- Status = ConioConsoleFromProcessData(CsrGetClientThread()->Process,
&Console);
- if (! NT_SUCCESS(Status))
- {
- return Status;
- }
+
+ Status =
ConioConsoleFromProcessData(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
&Console);
+ if (!NT_SUCCESS(Status)) return Status;
Group = GenerateCtrlEvent->ProcessGroup;
Status = STATUS_INVALID_PARAMETER;
- for (current_entry = Console->ProcessList.Flink;
- current_entry != &Console->ProcessList;
- current_entry = current_entry->Flink)
- {
- current = CONTAINING_RECORD(current_entry, CSR_PROCESS, ConsoleLink);
- if (Group == 0 || current->ProcessGroupId == Group)
+ for (current_entry = Console->ProcessList.Flink;
+ current_entry != &Console->ProcessList;
+ current_entry = current_entry->Flink)
+ {
+ current = CONTAINING_RECORD(current_entry, CONSOLE_PROCESS_DATA, ConsoleLink);
+ if (Group == 0 || current->Process->ProcessGroupId == Group)
{
ConioConsoleCtrlEvent(GenerateCtrlEvent->Event, current);
Status = STATUS_SUCCESS;
@@ -906,7 +889,7 @@
PCSRSS_GET_CONSOLE_SELECTION_INFO GetConsoleSelectionInfo =
&((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetConsoleSelectionInfo;
PCSRSS_CONSOLE Console;
- Status = ConioConsoleFromProcessData(CsrGetClientThread()->Process,
&Console);
+ Status =
ConioConsoleFromProcessData(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
&Console);
if (NT_SUCCESS(Status))
{
memset(&GetConsoleSelectionInfo->Info, 0,
sizeof(CONSOLE_SELECTION_INFO));
@@ -914,6 +897,7 @@
GetConsoleSelectionInfo->Info = Console->Selection;
ConioUnlockConsole(Console);
}
+
return Status;
}