[NTVDM][KERNEL32]
authorAleksandar Andrejevic <aandrejevic@reactos.org>
Thu, 23 Apr 2015 02:30:53 +0000 (02:30 +0000)
committerAleksandar Andrejevic <aandrejevic@reactos.org>
Thu, 23 Apr 2015 02:30:53 +0000 (02:30 +0000)
In DosCreateProcess, allocate space for the environment block dynamically and expand
it if needed, just like we do in CommandThreadProc.
In GetNextVDMCommand, remove the check that checks whether VDMState is one of
VDM_NOT_LOADED, VDM_NOT_READY or VDM_READY - that check makes no sense whatsoever,
since those aren't input values for that structure field. Their bit masks do correspond
to valid input fields, but even then the check makes no sense.

svn path=/trunk/; revision=67363

reactos/dll/win32/kernel32/client/vdm.c
reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/dos.c

index 3456dab..49ca70b 100644 (file)
@@ -1278,7 +1278,22 @@ GetNextVDMCommand(PVDM_COMMAND_INFO CommandData)
 
     if (CommandData != NULL)
     {
-        if (CommandData->VDMState & (VDM_NOT_LOADED | VDM_NOT_READY | VDM_READY))
+        if ((CommandData->VDMState == VDM_INC_REENTER_COUNT)
+            || (CommandData->VDMState == VDM_DEC_REENTER_COUNT))
+        {
+            /* Setup the input parameters */
+            SetReenterCount->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
+            SetReenterCount->fIncDec = CommandData->VDMState;
+
+            /* Call CSRSS */
+            Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+                                         NULL,
+                                         CSR_CREATE_API_NUMBER(BASESRV_SERVERDLL_INDEX, BasepSetReenterCount),
+                                         sizeof(BASE_SET_REENTER_COUNT));
+            BaseSetLastNTError(Status);
+            Result = NT_SUCCESS(Status);
+        }
+        else
         {
             /* Clear the structure */
             ZeroMemory(GetNextVdmCommand, sizeof(*GetNextVdmCommand));
@@ -1546,26 +1561,6 @@ GetNextVDMCommand(PVDM_COMMAND_INFO CommandData)
             /* It was successful */
             Result = TRUE;
         }
-        else if ((CommandData->VDMState == VDM_INC_REENTER_COUNT)
-                 || (CommandData->VDMState == VDM_DEC_REENTER_COUNT))
-        {
-            /* Setup the input parameters */
-            SetReenterCount->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
-            SetReenterCount->fIncDec = CommandData->VDMState;
-
-            /* Call CSRSS */
-            Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
-                                         NULL,
-                                         CSR_CREATE_API_NUMBER(BASESRV_SERVERDLL_INDEX, BasepSetReenterCount),
-                                         sizeof(BASE_SET_REENTER_COUNT));
-            BaseSetLastNTError(Status);
-            Result = NT_SUCCESS(Status);
-        }
-        else
-        {
-            BaseSetLastNTError(STATUS_INVALID_PARAMETER);
-            Result = FALSE;
-        }
     }
     else
     {
index a71e25b..26996d3 100644 (file)
@@ -1039,7 +1039,8 @@ WORD DosCreateProcess(DOS_EXEC_TYPE LoadType,
     CHAR PifFile[MAX_PATH];
     CHAR Desktop[MAX_PATH];
     CHAR Title[MAX_PATH];
-    CHAR Env[MAX_PATH];
+    ULONG EnvSize = 256;
+    PVOID Env = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, EnvSize);
     STARTUPINFOA StartupInfo;
     PROCESS_INFORMATION ProcessInfo;
 
@@ -1098,17 +1099,25 @@ WORD DosCreateProcess(DOS_EXEC_TYPE LoadType,
             CommandInfo.Env = Env;
             CommandInfo.EnvLen = sizeof(Env);
 
+Command:
             /* Get the VDM command information */
             if (!GetNextVDMCommand(&CommandInfo))
             {
+                if (CommandInfo.EnvLen > EnvSize)
+                {
+                    /* Expand the environment size */
+                    EnvSize = CommandInfo.EnvLen;
+                    CommandInfo.Env = Env = RtlReAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, Env, EnvSize);
+
+                    /* Repeat the request */
+                    CommandInfo.VDMState |= VDM_FLAG_RETRY;
+                    goto Command;
+                }
+
                 /* Shouldn't happen */
                 ASSERT(FALSE);
             }
 
-            /* Increment the re-entry count */
-            CommandInfo.VDMState = VDM_INC_REENTER_COUNT;
-            GetNextVDMCommand(&CommandInfo);
-
             /* Load the executable */
             Result = DosLoadExecutable(LoadType,
                                        AppName,
@@ -1116,11 +1125,15 @@ WORD DosCreateProcess(DOS_EXEC_TYPE LoadType,
                                        Env,
                                        &Parameters->StackLocation,
                                        &Parameters->EntryPoint);
-            if (Result != ERROR_SUCCESS)
+            if (Result == ERROR_SUCCESS)
+            {
+                /* Increment the re-entry count */
+                CommandInfo.VDMState = VDM_INC_REENTER_COUNT;
+                GetNextVDMCommand(&CommandInfo);
+            }
+            else
             {
                 DisplayMessage(L"Could not load '%S'. Error: %u", AppName, Result);
-                // FIXME: Decrement the reenter count. Or, instead, just increment
-                // the VDM reenter count *only* if this call succeeds...
             }
 
             break;
@@ -1134,6 +1147,8 @@ WORD DosCreateProcess(DOS_EXEC_TYPE LoadType,
         }
     }
 
+    RtlFreeHeap(RtlGetProcessHeap(), 0, Env);
+
     /* Close the handles */
     CloseHandle(ProcessInfo.hProcess);
     CloseHandle(ProcessInfo.hThread);