[BASESRV]
authorAleksandar Andrejevic <aandrejevic@reactos.org>
Sun, 2 Mar 2014 02:50:40 +0000 (02:50 +0000)
committerAleksandar Andrejevic <aandrejevic@reactos.org>
Sun, 2 Mar 2014 02:50:40 +0000 (02:50 +0000)
Move the GET_NEXT_VDM_COMMAND_DATA structure to a global header, and
rename it to VDM_COMMAND_INFO.
Implement BaseSrvCopyCommand, which moves the BASE_CHECK_VDM structure data
into a new VDM_COMMAND_INFO structure.
Implement BaseSrvFreeVDMInfo which frees a VDM_COMMAND_INFO structure and
everything in it.

svn path=/branches/ntvdm/; revision=62374

dll/win32/kernel32/client/vdm.c
dll/win32/kernel32/include/vdm.h
include/reactos/subsys/win/vdm.h
subsystems/win/basesrv/vdm.c
subsystems/win/basesrv/vdm.h

index 9ccc1dd..9601f10 100644 (file)
@@ -1130,7 +1130,7 @@ ExitVDM(BOOL IsWow, ULONG iWowTask)
  */
 DWORD
 WINAPI
-GetNextVDMCommand(PGET_NEXT_VDM_COMMAND_DATA CommandData)
+GetNextVDMCommand(PVDM_COMMAND_INFO CommandData)
 {
     STUB;
     return 0;
index 5917a22..82834fb 100644 (file)
@@ -25,39 +25,6 @@ typedef enum _VDM_ENTRY_CODE
 #define VDM_UNDO_REUSE      0x04
 #define VDM_UNDO_COMPLETED  0x08
 
-/* STRUCTURES *****************************************************************/
-
-typedef struct _GET_NEXT_VDM_COMMAND_DATA
-{
-    ULONG iTask;
-    ULONG dwUnused;
-    ULONG dwExitCode;
-    ULONG dwCodePage;
-    HANDLE hStdIn;
-    HANDLE hStdOut;
-    HANDLE hStdErr;
-    LPSTR lpCmdLine;
-    LPSTR lpAppName;
-    LPSTR lpPifFile;
-    LPSTR lpCurDirectory;
-    LPSTR lpEnv;
-    ULONG dwEnvLen;
-    STARTUPINFOA StartupInfo;
-    LPSTR lpDesktop;
-    ULONG dwDesktopLen;
-    LPSTR lpTitle;
-    ULONG dwTitleLen;
-    LPVOID lpReserved;
-    ULONG dwReservedLen;
-    USHORT wCmdLen;
-    USHORT wAppLen;
-    USHORT wPifLen;
-    USHORT wCurDirectoryLen;
-    USHORT wVDMState;
-    USHORT wCurrentDrive;
-    BOOLEAN fComingFromBat;
-} GET_NEXT_VDM_COMMAND_DATA, *PGET_NEXT_VDM_COMMAND_DATA;
-
 /* FUNCTION PROTOTYPES ********************************************************/
 
 BOOL
index 7df83a0..03b72e7 100644 (file)
 #define VDM_NOT_READY       0x02
 #define VDM_READY           0x04
 
+typedef struct
+{
+    ULONG TaskId;
+    ULONG Unused;
+    ULONG ExitCode;
+    ULONG CodePage;
+    HANDLE StdIn;
+    HANDLE StdOut;
+    HANDLE StdErr;
+    LPSTR CmdLine;
+    LPSTR AppName;
+    LPSTR PifFile;
+    LPSTR CurDirectory;
+    LPSTR Env;
+    ULONG EnvLen;
+    STARTUPINFOA StartupInfo;
+    LPSTR Desktop;
+    ULONG DesktopLen;
+    LPSTR Title;
+    ULONG TitleLen;
+    LPVOID Reserved;
+    ULONG ReservedLen;
+    USHORT CmdLen;
+    USHORT AppLen;
+    USHORT PifLen;
+    USHORT CurDirectoryLen;
+    USHORT VDMState;
+    USHORT CurrentDrive;
+    BOOLEAN ComingFromBat;
+} VDM_COMMAND_INFO, *PVDM_COMMAND_INFO;
+
 #endif // _VDM_H
 
 /* EOF */
index 63f4425..c47f885 100644 (file)
@@ -187,6 +187,166 @@ NTSTATUS NTAPI BaseSrvCreatePairWaitHandles(PHANDLE ServerEvent, PHANDLE ClientE
     return Status;
 }
 
+VOID BaseSrvFreeVDMInfo(PVDM_COMMAND_INFO CommandInfo)
+{
+    /* Free the allocated structure members */
+    if (CommandInfo->CmdLine != NULL) RtlFreeHeap(BaseSrvHeap, 0, CommandInfo->CmdLine);
+    if (CommandInfo->AppName != NULL) RtlFreeHeap(BaseSrvHeap, 0, CommandInfo->AppName);
+    if (CommandInfo->PifFile != NULL) RtlFreeHeap(BaseSrvHeap, 0, CommandInfo->PifFile);
+    if (CommandInfo->CurDirectory != NULL) RtlFreeHeap(BaseSrvHeap, 0, CommandInfo->CurDirectory);
+    if (CommandInfo->Env != NULL) RtlFreeHeap(BaseSrvHeap, 0, CommandInfo->Env);
+    if (CommandInfo->Desktop != NULL) RtlFreeHeap(BaseSrvHeap, 0, CommandInfo->Desktop);
+    if (CommandInfo->Title != NULL) RtlFreeHeap(BaseSrvHeap, 0, CommandInfo->Title);
+    if (CommandInfo->Reserved != NULL) RtlFreeHeap(BaseSrvHeap, 0, CommandInfo->Reserved);
+
+    /* Free the structure itself */
+    RtlFreeHeap(BaseSrvHeap, 0, CommandInfo);
+}
+
+BOOLEAN NTAPI BaseSrvCopyCommand(PBASE_CHECK_VDM CheckVdmRequest, PVDM_DOS_RECORD DosRecord)
+{
+    BOOLEAN Success = FALSE;
+    PVDM_COMMAND_INFO CommandInfo = NULL;
+
+    /* Allocate the command information structure */
+    CommandInfo = (PVDM_COMMAND_INFO)RtlAllocateHeap(BaseSrvHeap,
+                                                     HEAP_ZERO_MEMORY,
+                                                     sizeof(VDM_COMMAND_INFO));
+    if (CommandInfo == NULL) return FALSE;
+
+    /* Fill the structure */
+    CommandInfo->TaskId = CheckVdmRequest->iTask;
+    CommandInfo->ExitCode = DosRecord->ExitCode;
+    CommandInfo->CodePage = CheckVdmRequest->CodePage;
+    CommandInfo->StdIn = CheckVdmRequest->StdIn;
+    CommandInfo->StdOut = CheckVdmRequest->StdOut;
+    CommandInfo->StdErr = CheckVdmRequest->StdErr;
+
+    /* Allocate memory for the command line */
+    CommandInfo->CmdLine = RtlAllocateHeap(BaseSrvHeap,
+                                           HEAP_ZERO_MEMORY,
+                                           CheckVdmRequest->CmdLen);
+    if (CommandInfo->CmdLine == NULL) goto Cleanup;
+
+    /* Copy the command line */
+    RtlMoveMemory(CommandInfo->CmdLine, CheckVdmRequest->CmdLine, CheckVdmRequest->CmdLen);
+
+    /* Allocate memory for the application name */
+    CommandInfo->AppName = RtlAllocateHeap(BaseSrvHeap,
+                                           HEAP_ZERO_MEMORY,
+                                           CheckVdmRequest->AppLen);
+    if (CommandInfo->AppName == NULL) goto Cleanup;
+
+    /* Copy the application name */
+    RtlMoveMemory(CommandInfo->AppName, CheckVdmRequest->AppName, CheckVdmRequest->AppLen);
+
+    /* Allocate memory for the PIF file name */
+    if (CheckVdmRequest->PifLen != 0)
+    {
+        CommandInfo->PifFile = RtlAllocateHeap(BaseSrvHeap,
+                                               HEAP_ZERO_MEMORY,
+                                               CheckVdmRequest->PifLen);
+        if (CommandInfo->PifFile == NULL) goto Cleanup;
+
+        /* Copy the PIF file name */
+        RtlMoveMemory(CommandInfo->PifFile, CheckVdmRequest->PifFile, CheckVdmRequest->PifLen);
+    }
+    else CommandInfo->PifFile = NULL;
+
+    /* Allocate memory for the current directory */
+    if (CheckVdmRequest->CurDirectoryLen != 0)
+    {
+        CommandInfo->CurDirectory = RtlAllocateHeap(BaseSrvHeap,
+                                                    HEAP_ZERO_MEMORY,
+                                                    CheckVdmRequest->CurDirectoryLen);
+        if (CommandInfo->CurDirectory == NULL) goto Cleanup;
+
+        /* Copy the current directory */
+        RtlMoveMemory(CommandInfo->CurDirectory,
+                      CheckVdmRequest->CurDirectory,
+                      CheckVdmRequest->CurDirectoryLen);
+    }
+    else CommandInfo->CurDirectory = NULL;
+
+    /* Allocate memory for the environment block */
+    CommandInfo->Env = RtlAllocateHeap(BaseSrvHeap,
+                                       HEAP_ZERO_MEMORY,
+                                       CheckVdmRequest->EnvLen);
+    if (CommandInfo->Env == NULL) goto Cleanup;
+
+    /* Copy the environment block */
+    RtlMoveMemory(CommandInfo->Env, CheckVdmRequest->Env, CheckVdmRequest->EnvLen);
+
+    CommandInfo->EnvLen = CheckVdmRequest->EnvLen;
+    RtlMoveMemory(&CommandInfo->StartupInfo,
+                  CheckVdmRequest->StartupInfo,
+                  sizeof(STARTUPINFOA));
+    /* Allocate memory for the desktop */
+    if (CheckVdmRequest->DesktopLen != 0)
+    {
+        CommandInfo->Desktop = RtlAllocateHeap(BaseSrvHeap,
+                                               HEAP_ZERO_MEMORY,
+                                               CheckVdmRequest->DesktopLen);
+        if (CommandInfo->Desktop == NULL) goto Cleanup;
+
+        /* Copy the desktop name */
+        RtlMoveMemory(CommandInfo->Desktop, CheckVdmRequest->Desktop, CheckVdmRequest->DesktopLen);
+    }
+    else CommandInfo->Desktop = NULL;
+
+    CommandInfo->DesktopLen = CheckVdmRequest->DesktopLen;
+
+    /* Allocate memory for the title */
+    if (CheckVdmRequest->TitleLen != 0)
+    {
+        CommandInfo->Title = RtlAllocateHeap(BaseSrvHeap,
+                                             HEAP_ZERO_MEMORY,
+                                             CheckVdmRequest->TitleLen);
+        if (CommandInfo->Title == NULL) goto Cleanup;
+
+        /* Copy the title */
+        RtlMoveMemory(CommandInfo->Title, CheckVdmRequest->Title, CheckVdmRequest->TitleLen);
+    }
+    else CommandInfo->Title = NULL;
+
+    CommandInfo->TitleLen = CheckVdmRequest->TitleLen;
+
+    /* Allocate memory for the reserved field */
+    if (CheckVdmRequest->ReservedLen != 0)
+    {
+        CommandInfo->Reserved = RtlAllocateHeap(BaseSrvHeap,
+                                                HEAP_ZERO_MEMORY,
+                                                CheckVdmRequest->ReservedLen);
+        if (CommandInfo->Reserved == NULL) goto Cleanup;
+
+        /* Copy the reserved field */
+        RtlMoveMemory(CommandInfo->Reserved,
+                      CheckVdmRequest->Reserved,
+                      CheckVdmRequest->ReservedLen);
+    }
+    else CommandInfo->Reserved = NULL;
+
+    CommandInfo->ReservedLen = CheckVdmRequest->ReservedLen;
+
+    CommandInfo->CmdLen = CheckVdmRequest->CmdLen;
+    CommandInfo->AppLen = CheckVdmRequest->AppLen;
+    CommandInfo->PifLen = CheckVdmRequest->PifLen;
+    CommandInfo->CurDirectoryLen = CheckVdmRequest->CurDirectoryLen;
+    CommandInfo->VDMState = DosRecord->State;
+    // TODO: Set CommandInfo->CurrentDrive
+    // TODO: Set CommandInfo->ComingFromBat
+
+    /* Set the DOS record's command structure */
+    DosRecord->CommandInfo = CommandInfo;
+
+Cleanup:
+    /* If it wasn't successful, free the memory */
+    if (!Success) BaseSrvFreeVDMInfo(CommandInfo);
+
+    return Success;
+}
+
 VOID NTAPI BaseInitializeVDM(VOID)
 {
     /* Initialize the list head */
@@ -300,6 +460,14 @@ CSR_API(BaseSrvCheckVDM)
         Status = BaseSrvCreatePairWaitHandles(&DosRecord->ServerEvent, &DosRecord->ClientEvent);
         if (!NT_SUCCESS(Status)) goto Cleanup;
 
+        /* Translate the input structure into a VDM command structure and set it in the DOS record */
+        if (!BaseSrvCopyCommand(CheckVdmRequest, DosRecord))
+        {
+            /* The only possibility is that an allocation failure occurred */
+            Status = STATUS_NO_MEMORY;
+            goto Cleanup;
+        }
+
         /* Add the DOS record */
         InsertHeadList(&ConsoleRecord->DosListHead, &DosRecord->Entry);
 
index 37f34ba..a6df205 100644 (file)
@@ -34,6 +34,7 @@ typedef struct _VDM_DOS_RECORD
     ULONG ExitCode;
     HANDLE ServerEvent;
     HANDLE ClientEvent;
+    PVDM_COMMAND_INFO CommandInfo;
     // TODO: Structure incomplete!!!
 } VDM_DOS_RECORD, *PVDM_DOS_RECORD;