[KERNEL32][CONSRV]
authorHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sun, 20 Apr 2014 22:40:39 +0000 (22:40 +0000)
committerHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sun, 20 Apr 2014 22:40:39 +0000 (22:40 +0000)
Make kernel32 / winsrv console CSR structures Win2k3-compliant for CreateConsoleScreenBuffer.
The aim is to be able to put our kernel32.dll or winsrv.dll on win2k3, and vice-versa.

Because of that, we need to introduce and use the redundant hMutex and lpBitMap in the CONSOLE_CREATESCREENBUFFER structure, instead of the ones that are already present in its CONSOLE_GRAPHICS_BUFFER_INFO member ...
Isn't MS dumb sometimes?

I also homogeneize some variable names wrt. equivalent ones that I use elsewhere, and I fix a broken return value in the case the API fails.

Part 3/X

CORE-7931

svn path=/trunk/; revision=62846

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

index 1a250a1..f65838c 100644 (file)
@@ -1935,11 +1935,10 @@ CreateConsoleScreenBuffer(DWORD dwDesiredAccess,
                           DWORD dwFlags,
                           LPVOID lpScreenBufferData)
 {
-    NTSTATUS Status;
     CONSOLE_API_MESSAGE ApiMessage;
     PCONSOLE_CREATESCREENBUFFER CreateScreenBufferRequest = &ApiMessage.Data.CreateScreenBufferRequest;
     PCSR_CAPTURE_BUFFER CaptureBuffer = NULL;
-    PCONSOLE_GRAPHICS_BUFFER_INFO GraphicsBufferInfo = /*(PCONSOLE_GRAPHICS_BUFFER_INFO)*/lpScreenBufferData;
+    PCONSOLE_GRAPHICS_BUFFER_INFO GraphicsBufferInfo = lpScreenBufferData;
 
     if ( (dwDesiredAccess & ~(GENERIC_READ | GENERIC_WRITE))    ||
          (dwShareMode & ~(FILE_SHARE_READ | FILE_SHARE_WRITE))  ||
@@ -1949,15 +1948,16 @@ CreateConsoleScreenBuffer(DWORD dwDesiredAccess,
         return INVALID_HANDLE_VALUE;
     }
 
-    CreateScreenBufferRequest->ScreenBufferType = dwFlags;
-    CreateScreenBufferRequest->Access      = dwDesiredAccess;
-    CreateScreenBufferRequest->ShareMode   = dwShareMode;
-    CreateScreenBufferRequest->Inheritable =
+    CreateScreenBufferRequest->ConsoleHandle    = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
+    CreateScreenBufferRequest->DesiredAccess    = dwDesiredAccess;
+    CreateScreenBufferRequest->InheritHandle    =
         (lpSecurityAttributes ? lpSecurityAttributes->bInheritHandle : FALSE);
+    CreateScreenBufferRequest->ShareMode        = dwShareMode;
+    CreateScreenBufferRequest->ScreenBufferType = dwFlags;
 
     if (dwFlags == CONSOLE_GRAPHICS_BUFFER)
     {
-        if (CreateScreenBufferRequest->Inheritable || GraphicsBufferInfo == NULL)
+        if (CreateScreenBufferRequest->InheritHandle || GraphicsBufferInfo == NULL)
         {
             SetLastError(ERROR_INVALID_PARAMETER);
             return INVALID_HANDLE_VALUE;
@@ -1969,7 +1969,7 @@ CreateConsoleScreenBuffer(DWORD dwDesiredAccess,
         if (CaptureBuffer == NULL)
         {
             SetLastError(ERROR_NOT_ENOUGH_MEMORY);
-            return FALSE;
+            return INVALID_HANDLE_VALUE;
         }
 
         CsrCaptureMessageBuffer(CaptureBuffer,
@@ -1978,24 +1978,23 @@ CreateConsoleScreenBuffer(DWORD dwDesiredAccess,
                                 (PVOID*)&CreateScreenBufferRequest->GraphicsBufferInfo.lpBitMapInfo);
     }
 
-    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
-                                 CaptureBuffer,
-                                 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepCreateScreenBuffer),
-                                 sizeof(CONSOLE_CREATESCREENBUFFER));
+    CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+                        CaptureBuffer,
+                        CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepCreateScreenBuffer),
+                        sizeof(*CreateScreenBufferRequest));
 
-     if (CaptureBuffer)
-        CsrFreeCaptureBuffer(CaptureBuffer);
+    if (CaptureBuffer) CsrFreeCaptureBuffer(CaptureBuffer);
 
-    if (!NT_SUCCESS(Status))
+    if (!NT_SUCCESS(ApiMessage.Status))
     {
-        BaseSetLastNTError(Status);
+        BaseSetLastNTError(ApiMessage.Status);
         return INVALID_HANDLE_VALUE;
     }
 
     if (dwFlags == CONSOLE_GRAPHICS_BUFFER && GraphicsBufferInfo)
     {
-        GraphicsBufferInfo->hMutex   = CreateScreenBufferRequest->GraphicsBufferInfo.hMutex  ;
-        GraphicsBufferInfo->lpBitMap = CreateScreenBufferRequest->GraphicsBufferInfo.lpBitMap;
+        GraphicsBufferInfo->hMutex   = CreateScreenBufferRequest->hMutex  ; // CreateScreenBufferRequest->GraphicsBufferInfo.hMutex  ;
+        GraphicsBufferInfo->lpBitMap = CreateScreenBufferRequest->lpBitMap; // CreateScreenBufferRequest->GraphicsBufferInfo.lpBitMap;
     }
 
     return CreateScreenBufferRequest->OutputHandle;
index a208d3e..70bf665 100644 (file)
@@ -351,17 +351,19 @@ typedef struct
 
 typedef struct
 {
-    HANDLE OutputHandle;     /* Handle to newly created screen buffer */
+    HANDLE ConsoleHandle;
+    DWORD  DesiredAccess;
+    BOOL   InheritHandle;
+    DWORD  ShareMode;
     DWORD  ScreenBufferType; /* Type of the screen buffer: CONSOLE_TEXTMODE_BUFFER or CONSOLE_GRAPHICS_BUFFER */
     /*
-     * If we are creating a graphics screen buffer,
-     * this structure holds the initialization information.
+     * This structure holds the initialization information
+     * for graphics screen buffers.
      */
     CONSOLE_GRAPHICS_BUFFER_INFO GraphicsBufferInfo;
-
-    DWORD Access;
-    DWORD ShareMode;
-    BOOL  Inheritable;
+    HANDLE hMutex;
+    PVOID  lpBitMap;
+    HANDLE OutputHandle;     /* Handle to newly created screen buffer */
 } CONSOLE_CREATESCREENBUFFER, *PCONSOLE_CREATESCREENBUFFER;
 
 typedef struct
index 9c01dd4..f5dac64 100644 (file)
@@ -232,8 +232,8 @@ CSR_API(SrvCreateConsoleScreenBuffer)
         /* Get infos from the graphics buffer information structure */
         if (!CsrValidateMessageBuffer(ApiMessage,
                                       (PVOID*)&CreateScreenBufferRequest->GraphicsBufferInfo.lpBitMapInfo,
-                                      1,
-                                      CreateScreenBufferRequest->GraphicsBufferInfo.dwBitMapInfoLength))
+                                      CreateScreenBufferRequest->GraphicsBufferInfo.dwBitMapInfoLength,
+                                      sizeof(BYTE)))
         {
             Status = STATUS_INVALID_PARAMETER;
             goto Quit;
@@ -242,11 +242,13 @@ CSR_API(SrvCreateConsoleScreenBuffer)
         ScreenBufferInfo = &GraphicsInfo;
 
         /* Initialize shared variables */
-        CreateScreenBufferRequest->GraphicsBufferInfo.hMutex   = GraphicsInfo.Info.hMutex   = INVALID_HANDLE_VALUE;
-        CreateScreenBufferRequest->GraphicsBufferInfo.lpBitMap = GraphicsInfo.Info.lpBitMap = NULL;
+        // CreateScreenBufferRequest->GraphicsBufferInfo.hMutex
+        CreateScreenBufferRequest->hMutex   = GraphicsInfo.Info.hMutex   = INVALID_HANDLE_VALUE;
+        // CreateScreenBufferRequest->GraphicsBufferInfo.lpBitMap
+        CreateScreenBufferRequest->lpBitMap = GraphicsInfo.Info.lpBitMap = NULL;
 
         /* A graphics screen buffer is never inheritable */
-        CreateScreenBufferRequest->Inheritable = FALSE;
+        CreateScreenBufferRequest->InheritHandle = FALSE;
     }
 
     Status = ConDrvCreateScreenBuffer(&Buff,
@@ -261,8 +263,8 @@ CSR_API(SrvCreateConsoleScreenBuffer)
     Status = ConSrvInsertObject(ProcessData,
                                 &CreateScreenBufferRequest->OutputHandle,
                                 &Buff->Header,
-                                CreateScreenBufferRequest->Access,
-                                CreateScreenBufferRequest->Inheritable,
+                                CreateScreenBufferRequest->DesiredAccess,
+                                CreateScreenBufferRequest->InheritHandle,
                                 CreateScreenBufferRequest->ShareMode);
 
     RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
@@ -276,8 +278,10 @@ CSR_API(SrvCreateConsoleScreenBuffer)
          * Initialize the graphics buffer information structure
          * and give it back to the client.
          */
-        CreateScreenBufferRequest->GraphicsBufferInfo.hMutex   = Buffer->ClientMutex;
-        CreateScreenBufferRequest->GraphicsBufferInfo.lpBitMap = Buffer->ClientBitMap;
+        // CreateScreenBufferRequest->GraphicsBufferInfo.hMutex
+        CreateScreenBufferRequest->hMutex   = Buffer->ClientMutex;
+        // CreateScreenBufferRequest->GraphicsBufferInfo.lpBitMap
+        CreateScreenBufferRequest->lpBitMap = Buffer->ClientBitMap;
     }
 
 Quit: