[KERNEL32/CONSRV]
authorHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sun, 18 Nov 2012 13:10:03 +0000 (13:10 +0000)
committerHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sun, 18 Nov 2012 13:10:03 +0000 (13:10 +0000)
- 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.

svn path=/branches/ros-csrss/; revision=57727

dll/win32/kernel32/client/console/console.c
include/reactos/subsys/win/conmsg.h
win32ss/user/consrv/conoutput.c
win32ss/user/consrv/console.c

index f6aaea0..d5f7187 100644 (file)
@@ -1448,8 +1448,8 @@ WINAPI
 GenerateConsoleCtrlEvent(DWORD dwCtrlEvent,
                          DWORD dwProcessGroupId)
 {
-    CSR_API_MESSAGE Request;
     NTSTATUS Status;
+    CONSOLE_API_MESSAGE ApiMessage;
 
     if (dwCtrlEvent != CTRL_C_EVENT && dwCtrlEvent != CTRL_BREAK_EVENT)
     {
@@ -1457,14 +1457,14 @@ GenerateConsoleCtrlEvent(DWORD dwCtrlEvent,
         return FALSE;
     }
 
-    Request.Data.GenerateCtrlEvent.Event = dwCtrlEvent;
-    Request.Data.GenerateCtrlEvent.ProcessGroup = dwProcessGroupId;
+    ApiMessage.Data.GenerateCtrlEvent.Event = dwCtrlEvent;
+    ApiMessage.Data.GenerateCtrlEvent.ProcessGroup = dwProcessGroupId;
 
-    Status = CsrClientCallServer(&Request,
+    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
                                  NULL,
-                                 CSR_CREATE_API_NUMBER(CSR_CONSOLE, GENERATE_CTRL_EVENT),
-                                 sizeof(CSR_API_MESSAGE));
-    if(!NT_SUCCESS(Status) || !(NT_SUCCESS(Status = Request.Status)))
+                                 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 @@ GenerateConsoleCtrlEvent(DWORD dwCtrlEvent,
 static DWORD
 IntGetConsoleTitle(LPVOID lpConsoleTitle, DWORD nSize, BOOL bUnicode)
 {
-    CSR_API_MESSAGE Request;
-    PCSR_CAPTURE_BUFFER CaptureBuffer;
     NTSTATUS Status;
+    CONSOLE_API_MESSAGE ApiMessage;
+    PCSRSS_CONSOLE_TITLE TitleRequest = &ApiMessage.Data.TitleRequest;
+    PCSR_CAPTURE_BUFFER CaptureBuffer;
 
     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 @@ IntGetConsoleTitle(LPVOID lpConsoleTitle, DWORD nSize, BOOL bUnicode)
     }
 
     CsrAllocateMessagePointer(CaptureBuffer,
-                              Request.Data.GetTitleRequest.Length,
-                              (PVOID*)&Request.Data.GetTitleRequest.Title);
+                              TitleRequest->Length,
+                              (PVOID*)&TitleRequest->Title);
 
-    Status = CsrClientCallServer(&Request,
+    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 @@ IntGetConsoleTitle(LPVOID lpConsoleTitle, DWORD nSize, BOOL bUnicode)
     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,14 +1528,15 @@ IntGetConsoleTitle(LPVOID lpConsoleTitle, DWORD nSize, BOOL bUnicode)
         {
             /* 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 @@ GetConsoleTitleW(LPWSTR lpConsoleTitle,
     return IntGetConsoleTitle(lpConsoleTitle, nSize, TRUE);
 }
 
+
 /*--------------------------------------------------------------
  *     GetConsoleTitleA
  *
@@ -1571,13 +1574,14 @@ BOOL
 WINAPI
 SetConsoleTitleW(LPCWSTR lpConsoleTitle)
 {
-    CSR_API_MESSAGE Request;
-    PCSR_CAPTURE_BUFFER CaptureBuffer;
     NTSTATUS Status;
+    CONSOLE_API_MESSAGE ApiMessage;
+    PCSRSS_CONSOLE_TITLE TitleRequest = &ApiMessage.Data.TitleRequest;
+    PCSR_CAPTURE_BUFFER CaptureBuffer;
 
-    Request.Data.SetTitleRequest.Length = wcslen(lpConsoleTitle) * sizeof(WCHAR);
+    TitleRequest->Length = wcslen(lpConsoleTitle) * sizeof(WCHAR);
 
-    CaptureBuffer = CsrAllocateCaptureBuffer(1, Request.Data.SetTitleRequest.Length);
+    CaptureBuffer = CsrAllocateCaptureBuffer(1, TitleRequest->Length);
     if (CaptureBuffer == NULL)
     {
         DPRINT1("CsrAllocateCaptureBuffer failed!\n");
@@ -1587,17 +1591,17 @@ SetConsoleTitleW(LPCWSTR lpConsoleTitle)
 
     CsrCaptureMessageBuffer(CaptureBuffer,
                             (PVOID)lpConsoleTitle,
-                            Request.Data.SetTitleRequest.Length,
-                            (PVOID*)&Request.Data.SetTitleRequest.Title);
+                            TitleRequest->Length,
+                            (PVOID*)&TitleRequest->Title);
 
-    Status = CsrClientCallServer(&Request,
+    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,20 +1687,23 @@ UINT
 WINAPI
 GetConsoleCP(VOID)
 {
-    CSR_API_MESSAGE Request;
     NTSTATUS Status;
+    CONSOLE_API_MESSAGE ApiMessage;
 
-    Status = CsrClientCallServer(&Request,
+    /* Get the Input Code Page */
+    ApiMessage.Data.ConsoleCPRequest.InputCP = TRUE;
+
+    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
                                  NULL,
-                                 CSR_CREATE_API_NUMBER(CSR_CONSOLE, GET_CONSOLE_CP),
-                                 sizeof(CSR_API_MESSAGE));
-    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
+                                 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetCP),
+                                 sizeof(CSRSS_CONSOLE_CP));
+    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = ApiMessage.Status))
     {
-        BaseSetLastNTError (Status);
+        BaseSetLastNTError(Status);
         return 0;
     }
 
-    return Request.Data.GetConsoleCodePage.CodePage;
+    return ApiMessage.Data.ConsoleCPRequest.CodePage;
 }
 
 
@@ -1709,16 +1716,18 @@ BOOL
 WINAPI
 SetConsoleCP(UINT wCodePageID)
 {
-    CSR_API_MESSAGE Request;
     NTSTATUS Status;
+    CONSOLE_API_MESSAGE ApiMessage;
 
-    Request.Data.SetConsoleCodePage.CodePage = wCodePageID;
+    /* Set the Input Code Page */
+    ApiMessage.Data.ConsoleCPRequest.InputCP = TRUE;
+    ApiMessage.Data.ConsoleCPRequest.CodePage = wCodePageID;
 
-    Status = CsrClientCallServer(&Request,
+    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
                                  NULL,
-                                 CSR_CREATE_API_NUMBER(CSR_CONSOLE, SET_CONSOLE_CP),
-                                 sizeof(CSR_API_MESSAGE));
-    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
+                                 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetCP),
+                                 sizeof(CSRSS_CONSOLE_CP));
+    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = ApiMessage.Status))
     {
         BaseSetLastNTError(Status);
     }
@@ -1736,20 +1745,23 @@ UINT
 WINAPI
 GetConsoleOutputCP(VOID)
 {
-    CSR_API_MESSAGE Request;
     NTSTATUS Status;
+    CONSOLE_API_MESSAGE ApiMessage;
 
-    Status = CsrClientCallServer(&Request,
+    /* Get the Output Code Page */
+    ApiMessage.Data.ConsoleCPRequest.InputCP = FALSE;
+
+    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
                                  NULL,
-                                 CSR_CREATE_API_NUMBER(CSR_CONSOLE, GET_CONSOLE_OUTPUT_CP),
-                                 sizeof(CSR_API_MESSAGE));
-    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
+                                 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.GetConsoleOutputCodePage.CodePage;
+    return ApiMessage.Data.ConsoleCPRequest.CodePage;
 }
 
 
@@ -1762,16 +1774,18 @@ BOOL
 WINAPI
 SetConsoleOutputCP(UINT wCodePageID)
 {
-    CSR_API_MESSAGE Request;
     NTSTATUS Status;
+    CONSOLE_API_MESSAGE ApiMessage;
 
-    Request.Data.SetConsoleOutputCodePage.CodePage = wCodePageID;
+    /* Set the Output Code Page */
+    ApiMessage.Data.ConsoleCPRequest.InputCP = FALSE;
+    ApiMessage.Data.ConsoleCPRequest.CodePage = wCodePageID;
 
-    Status = CsrClientCallServer(&Request,
+    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
                                  NULL,
-                                 CSR_CREATE_API_NUMBER(CSR_CONSOLE, SET_CONSOLE_OUTPUT_CP),
-                                 sizeof(CSR_API_MESSAGE));
-    if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
+                                 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 @@ WINAPI
 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 @@ GetConsoleProcessList(LPDWORD lpdwProcessList,
         return FALSE;
     }
 
-    Request.Data.GetProcessListRequest.nMaxIds = dwProcessCount;
+    GetProcessListRequest->nMaxIds = dwProcessCount;
+
     CsrAllocateMessagePointer(CaptureBuffer,
                               dwProcessCount * sizeof(DWORD),
-                              (PVOID*)&Request.Data.GetProcessListRequest.ProcessId);
+                              (PVOID*)&GetProcessListRequest->pProcessIds);
 
-    Status = CsrClientCallServer(&Request,
+    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 @@ GetConsoleNlsMode(HANDLE hConsole, LPDWORD lpMode)
 
 BOOL
 WINAPI
-RegisterConsoleIME(HWND hWnd, LPDWORD ThreadId)
+SetConsoleCursorMode(HANDLE hConsole, BOOL Unknown1, BOOL Unknown2)
 {
     STUB;
     return FALSE;
@@ -2144,7 +2160,7 @@ RegisterConsoleIME(HWND hWnd, LPDWORD ThreadId)
 
 BOOL
 WINAPI
-RegisterConsoleOS2(BOOL bUnknown)
+SetConsoleLocalEUDC(DWORD Unknown1, DWORD Unknown2, DWORD Unknown3, DWORD Unknown4)
 {
     STUB;
     return FALSE;
@@ -2152,7 +2168,7 @@ RegisterConsoleOS2(BOOL bUnknown)
 
 BOOL
 WINAPI
-SetConsoleCursorMode(HANDLE hConsole, BOOL Unknown1, BOOL Unknown2)
+SetConsoleNlsMode(HANDLE hConsole, DWORD dwMode)
 {
     STUB;
     return FALSE;
@@ -2160,7 +2176,7 @@ SetConsoleCursorMode(HANDLE hConsole, BOOL Unknown1, BOOL Unknown2)
 
 BOOL
 WINAPI
-SetConsoleLocalEUDC(DWORD Unknown1, DWORD Unknown2, DWORD Unknown3, DWORD Unknown4)
+RegisterConsoleIME(HWND hWnd, LPDWORD ThreadId)
 {
     STUB;
     return FALSE;
@@ -2168,7 +2184,7 @@ SetConsoleLocalEUDC(DWORD Unknown1, DWORD Unknown2, DWORD Unknown3, DWORD Unknow
 
 BOOL
 WINAPI
-SetConsoleNlsMode(HANDLE hConsole, DWORD dwMode)
+RegisterConsoleOS2(BOOL bUnknown)
 {
     STUB;
     return FALSE;
index 5e1fd41..e7ee61c 100644 (file)
@@ -126,7 +126,7 @@ typedef enum _CONSRV_API_NUMBER
 typedef struct
 {
     USHORT nMaxIds;
-    PDWORD ProcessId;
+    PDWORD pProcessIds;
     ULONG nProcessIdsTotal;
 } CSRSS_GET_PROCESS_LIST, *PCSRSS_GET_PROCESS_LIST;
 
@@ -260,13 +260,7 @@ typedef struct
 {
     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
 
 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 @@ typedef struct _CONSOLE_API_MESSAGE
         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 @@ typedef struct _CONSOLE_API_MESSAGE
         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;
index bd69083..a36de7d 100644 (file)
@@ -556,7 +556,7 @@ CSR_API(SrvWriteConsole)
 
     if (Console->UnpauseEvent)
     {
-        Status = NtDuplicateObject(GetCurrentProcess(), Console->UnpauseEvent,
+        Status = NtDuplicateObject(NtCurrentProcess(), Console->UnpauseEvent,
                                    ProcessData->ProcessHandle, &WriteConsoleRequest->UnpauseEvent,
                                    SYNCHRONIZE, 0, 0);
         ConioUnlockScreenBuffer(Buff);
index ee0fe44..23ae47c 100644 (file)
@@ -62,7 +62,7 @@ ConioConsoleCtrlEventTimeout(DWORD Event,
 {
     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(SrvOpenConsole)
 
 CSR_API(SrvAllocConsole)
 {
+    NTSTATUS Status = STATUS_SUCCESS;
     PCSRSS_ALLOC_CONSOLE AllocConsoleRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.AllocConsoleRequest;
-    PCSR_PROCESS ProcessData = CsrGetClientThread()->Process;
+    PCONSOLE_PROCESS_DATA ProcessData = ConsoleGetPerProcessData(CsrGetClientThread()->Process);
     PCSRSS_CONSOLE Console;
-    NTSTATUS Status = STATUS_SUCCESS;
     BOOLEAN NewConsole = FALSE;
 
     DPRINT("SrvAllocConsole\n");
 
     RtlEnterCriticalSection(&ProcessData->HandleTableLock);
+
     if (ProcessData->Console)
     {
         DPRINT1("Process already has a console\n");
@@ -266,6 +267,8 @@ CSR_API(SrvAllocConsole)
         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 @@ CSR_API(SrvAllocConsole)
 
     /* 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 @@ CSR_API(SrvAllocConsole)
             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 @@ CSR_API(SrvAllocConsole)
         {
             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 @@ CSR_API(SrvAllocConsole)
             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 @@ CSR_API(SrvAllocConsole)
             Win32CsrReleaseObject(ProcessData,
                                   AllocConsoleRequest->InputHandle);
         }
-        ProcessData->Console = 0;
+        ProcessData->Console = NULL;
         RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
         return Status;
     }
@@ -531,31 +536,41 @@ CSR_API(SrvGetConsoleMode)
 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 @@ CSR_API(SrvSetConsoleTitle)
         {
             Status = STATUS_NO_MEMORY;
         }
+
         ConioUnlockConsole(Console);
     }
 
@@ -577,35 +593,44 @@ CSR_API(SrvSetConsoleTitle)
 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))
+    if (TitleRequest->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';
+        Length = min(TitleRequest->Length - sizeof(WCHAR), Console->Title.Length);
+        memcpy(TitleRequest->Title, Console->Title.Buffer, Length);
+        TitleRequest->Title[Length / sizeof(WCHAR)] = L'\0';
     }
 
-    GetTitleRequest->Length = Console->Title.Length;
+    TitleRequest->Length = Console->Title.Length;
 
     ConioUnlockConsole(Console);
     return STATUS_SUCCESS;
@@ -699,17 +724,14 @@ CSR_API(SrvSetConsoleHardwareState)
 
 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(SrvGetConsoleWindow)
 
 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,84 +761,41 @@ CSR_API(SrvSetConsoleIcon)
 
 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;
-    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_CP ConsoleCPRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.ConsoleCPRequest;
     PCSRSS_CONSOLE Console;
-    NTSTATUS Status;
 
-    DPRINT("CsrGetConsoleOutputCodePage\n");
+    DPRINT("SrvGetConsoleCP, getting %s Code Page\n",
+            ConsoleCPRequest->InputCP ? "Input" : "Output");
 
-    Status = ConioConsoleFromProcessData(CsrGetClientThread()->Process, &Console);
-    if (! NT_SUCCESS(Status))
-    {
-        return Status;
-    }
+    Status = ConioConsoleFromProcessData(ConsoleGetPerProcessData(CsrGetClientThread()->Process), &Console);
+    if (!NT_SUCCESS(Status)) return Status;
 
-    GetConsoleOutputCodePage->CodePage = Console->OutputCodePage;
+    ConsoleCPRequest->CodePage = (ConsoleCPRequest->InputCP ? Console->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;
-        ConioUnlockConsole(Console);
-        return STATUS_SUCCESS;
-    }
-
-    ConioUnlockConsole(Console);
-    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_CP ConsoleCPRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.ConsoleCPRequest;
     PCSRSS_CONSOLE Console;
-    NTSTATUS Status;
 
-    DPRINT("CsrSetConsoleOutputCodePage\n");
+    DPRINT("SrvSetConsoleCP, setting %s Code Page\n",
+            ConsoleCPRequest->InputCP ? "Input" : "Output");
 
-    Status = ConioConsoleFromProcessData(CsrGetClientThread()->Process, &Console);
-    if (! NT_SUCCESS(Status))
-    {
-        return Status;
-    }
+    Status = ConioConsoleFromProcessData(ConsoleGetPerProcessData(CsrGetClientThread()->Process), &Console);
+    if (!NT_SUCCESS(Status)) return Status;
 
-    if (IsValidCodePage(SetConsoleOutputCodePage->CodePage))
+    if (IsValidCodePage(ConsoleCPRequest->CodePage))
     {
-        Console->OutputCodePage = SetConsoleOutputCodePage->CodePage;
+        if (ConsoleCPRequest->InputCP)
+            Console->CodePage = ConsoleCPRequest->CodePage;
+        else
+            Console->OutputCodePage = ConsoleCPRequest->CodePage;
+
         ConioUnlockConsole(Console);
         return STATUS_SUCCESS;
     }
@@ -828,35 +806,43 @@ CSR_API(CsrSetConsoleOutputCodePage) // TODO: Merge this function with the other
 
 CSR_API(SrvGetConsoleProcessList)
 {
+    NTSTATUS Status;
     PCSRSS_GET_PROCESS_LIST GetProcessListRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetProcessListRequest;
     PDWORD Buffer;
-    PCSR_PROCESS ProcessData = CsrGetClientThread()->Process;
+    // PCSR_PROCESS Process = CsrGetClientThread()->Process;
     PCSRSS_CONSOLE Console;
-    PCSR_PROCESS current;
+    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(SrvGetConsoleProcessList)
 
 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)
+    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)
+        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 @@ CSR_API(SrvGetConsoleSelectionInfo)
     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 @@ CSR_API(SrvGetConsoleSelectionInfo)
             GetConsoleSelectionInfo->Info = Console->Selection;
         ConioUnlockConsole(Console);
     }
+
     return Status;
 }