Author: aandrejevic
Date: Fri May  2 18:24:40 2014
New Revision: 63116

URL: http://svn.reactos.org/svn/reactos?rev=63116&view=rev
Log:
[NTVDM]
Use VdmRunning to keep the state of the whole VDM, not a VDM task.
Add an event whose signaled state determines the state of the VDM task.
Use FILE_SHARE_READ when opening executables.


Modified:
    branches/ntvdm/subsystems/ntvdm/dos/dos32krnl/dos.c
    branches/ntvdm/subsystems/ntvdm/emulator.c
    branches/ntvdm/subsystems/ntvdm/ntvdm.c
    branches/ntvdm/subsystems/ntvdm/ntvdm.h

Modified: branches/ntvdm/subsystems/ntvdm/dos/dos32krnl/dos.c
URL: 
http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/dos/dos32krnl/dos.c?rev=63116&r1=63115&r2=63116&view=diff
==============================================================================
--- branches/ntvdm/subsystems/ntvdm/dos/dos32krnl/dos.c [iso-8859-1] (original)
+++ branches/ntvdm/subsystems/ntvdm/dos/dos32krnl/dos.c [iso-8859-1] Fri May  2 
18:24:40 2014
@@ -1075,7 +1075,7 @@
     /* Open a handle to the executable */
     FileHandle = CreateFileA(ExecutablePath,
                              GENERIC_READ,
-                             0,
+                             FILE_SHARE_READ,
                              NULL,
                              OPEN_EXISTING,
                              FILE_ATTRIBUTE_NORMAL,
@@ -1443,12 +1443,16 @@
     if (Psp == CurrentPsp)
     {
         CurrentPsp = PspBlock->ParentPsp;
-        if (CurrentPsp == SYSTEM_PSP) VdmRunning = FALSE;
+        if (CurrentPsp == SYSTEM_PSP)
+        {
+            ResetEvent(VdmTaskEvent);
+            EmulatorUnsimulate();
+        }
     }
 
     // FIXME: This is probably not the best way to do it
     /* Check if this was a nested DOS task */
-    if (VdmRunning)
+    if (CurrentPsp != SYSTEM_PSP)
     {
         /* Decrement the re-entry count */
         CommandInfo.VDMState = VDM_DEC_REENTER_COUNT;
@@ -2646,8 +2650,9 @@
 {
     UNREFERENCED_PARAMETER(Stack);
 
-    /* Stop the VDM */
-    VdmRunning = FALSE;
+    /* Stop the VDM task */
+    ResetEvent(VdmTaskEvent);
+    EmulatorUnsimulate();
 }
 
 VOID WINAPI DosFastConOut(LPWORD Stack)

Modified: branches/ntvdm/subsystems/ntvdm/emulator.c
URL: 
http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/emulator.c?rev=63116&r1=63115&r2=63116&view=diff
==============================================================================
--- branches/ntvdm/subsystems/ntvdm/emulator.c  [iso-8859-1] (original)
+++ branches/ntvdm/subsystems/ntvdm/emulator.c  [iso-8859-1] Fri May  2 
18:24:40 2014
@@ -203,7 +203,7 @@
     }
     CpuCallLevel++;
 
-    VdmRunning = CpuSimulate = TRUE;
+    CpuSimulate = TRUE;
     while (VdmRunning && CpuSimulate) ClockUpdate();
 
     CpuCallLevel--;

Modified: branches/ntvdm/subsystems/ntvdm/ntvdm.c
URL: 
http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/ntvdm.c?rev=63116&r1=63115&r2=63116&view=diff
==============================================================================
--- branches/ntvdm/subsystems/ntvdm/ntvdm.c     [iso-8859-1] (original)
+++ branches/ntvdm/subsystems/ntvdm/ntvdm.c     [iso-8859-1] Fri May  2 
18:24:40 2014
@@ -40,6 +40,8 @@
 static HMENU hConsoleMenu  = NULL;
 static INT   VdmMenuPos    = -1;
 static BOOLEAN ShowPointer = FALSE;
+
+HANDLE VdmTaskEvent = NULL;
 
 /*
  * Those menu helpers were taken from the GUI frontend in winsrv.dll
@@ -200,10 +202,11 @@
         }
         case CTRL_LAST_CLOSE_EVENT:
         {
-            if (!VdmRunning)
+            if (WaitForSingleObject(VdmTaskEvent, 0) == WAIT_TIMEOUT)
             {
                 /* Exit immediately */
                 if (CommandThread) TerminateThread(CommandThread, 0);
+                EmulatorTerminate();
             }
             else
             {
@@ -243,6 +246,9 @@
 
     while (VdmRunning)
     {
+        /* Make sure the task event is signaled */
+        WaitForSingleObject(VdmTaskEvent, INFINITE);
+
         /* Wait for an input record */
         if (!ReadConsoleInput(ConsoleInput, &InputRecord, 1, &Count))
         {
@@ -442,6 +448,7 @@
         }
 
         /* Start simulation */
+        SetEvent(VdmTaskEvent);
         EmulatorSimulate();
 
         /* Perform another screen refresh */
@@ -476,6 +483,10 @@
 #endif
 
     DPRINT1("\n\n\nNTVDM - Starting...\n\n\n");
+
+    /* Create the task event */
+    VdmTaskEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
+    ASSERT(VdmTaskEvent != NULL);
 
     /* Initialize the console */
     if (!ConsoleInit())
@@ -539,6 +550,7 @@
     }
 
     /* Start simulation */
+    SetEvent(VdmTaskEvent);
     EmulatorSimulate();
 
     /* Perform another screen refresh */

Modified: branches/ntvdm/subsystems/ntvdm/ntvdm.h
URL: 
http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/ntvdm.h?rev=63116&r1=63115&r2=63116&view=diff
==============================================================================
--- branches/ntvdm/subsystems/ntvdm/ntvdm.h     [iso-8859-1] (original)
+++ branches/ntvdm/subsystems/ntvdm/ntvdm.h     [iso-8859-1] Fri May  2 
18:24:40 2014
@@ -33,6 +33,8 @@
 
 /* FUNCTIONS 
******************************************************************/
 
+extern HANDLE VdmTaskEvent;
+
 VOID DisplayMessage(LPCWSTR Format, ...);
 
 #endif // _NTVDM_H_


Reply via email to