https://git.reactos.org/?p=reactos.git;a=commitdiff;h=b849a696ef8f5a45edc94f7a42f2292b093c6455

commit b849a696ef8f5a45edc94f7a42f2292b093c6455
Author:     Hermès Bélusca-Maïto <[email protected]>
AuthorDate: Sat Nov 27 01:06:21 2021 +0100
Commit:     Hermès Bélusca-Maïto <[email protected]>
CommitDate: Sun Nov 28 00:26:43 2021 +0100

    [NTVDM] In non-STANDALONE builds, check whether we are started as a VDM and 
bail out if not.
---
 subsystems/mvdm/ntvdm/ntvdm.c | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)

diff --git a/subsystems/mvdm/ntvdm/ntvdm.c b/subsystems/mvdm/ntvdm/ntvdm.c
index d7e88cb20ad..bedc20ea7ea 100644
--- a/subsystems/mvdm/ntvdm/ntvdm.c
+++ b/subsystems/mvdm/ntvdm/ntvdm.c
@@ -20,6 +20,9 @@
 
 #include "dos/dem.h"
 
+/* Extra PSDK/NDK Headers */
+#include <ndk/psfuncs.h>
+
 /* VARIABLES 
******************************************************************/
 
 NTVDM_SETTINGS GlobalSettings;
@@ -473,9 +476,6 @@ PrintMessageAnsi(IN CHAR_PRINT CharPrint,
 INT
 wmain(INT argc, WCHAR *argv[])
 {
-    NtVdmArgc = argc;
-    NtVdmArgv = argv;
-
 #ifdef STANDALONE
 
     if (argc < 2)
@@ -485,8 +485,27 @@ wmain(INT argc, WCHAR *argv[])
         return 0;
     }
 
+#else
+
+    /* For non-STANDALONE builds, we must be started as a VDM */
+    NTSTATUS Status;
+    ULONG VdmPower = 0;
+    Status = NtQueryInformationProcess(NtCurrentProcess(),
+                                       ProcessWx86Information,
+                                       &VdmPower,
+                                       sizeof(VdmPower),
+                                       NULL);
+    if (!NT_SUCCESS(Status) || (VdmPower == 0))
+    {
+        /* Not a VDM, bail out */
+        return 0;
+    }
+
 #endif
 
+    NtVdmArgc = argc;
+    NtVdmArgv = argv;
+
 #ifdef ADVANCED_DEBUGGING
     {
     INT i = 20;

Reply via email to