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

commit 4dd734e92c1db15083e03b9d88e0cb8243386b7d
Author:     Hermès Bélusca-Maïto <[email protected]>
AuthorDate: Tue Nov 16 00:34:39 2021 +0100
Commit:     Hermès Bélusca-Maïto <[email protected]>
CommitDate: Fri Jan 14 23:59:32 2022 +0100

    [NTDLL:LDR] Don't hardcode process-execute flag values. (#4111)
---
 dll/ntdll/ldr/ldrinit.c | 27 ++++++++++++++++-----------
 1 file changed, 16 insertions(+), 11 deletions(-)

diff --git a/dll/ntdll/ldr/ldrinit.c b/dll/ntdll/ldr/ldrinit.c
index 0a0be84b0c4..b41166c06ad 100644
--- a/dll/ntdll/ldr/ldrinit.c
+++ b/dll/ntdll/ldr/ldrinit.c
@@ -2427,21 +2427,26 @@ LdrpInitializeProcess(IN PCONTEXT Context,
     /* Validate the Image for MP Usage */
     if (LdrpNumberOfProcessors > 1) LdrpValidateImageForMp(LdrpImageEntry);
 
-    /* Check NX Options */
-    if (SharedUserData->NXSupportPolicy == 1)
+    /* Check NX options and set them */
+    if (SharedUserData->NXSupportPolicy == NX_SUPPORT_POLICY_ALWAYSON)
     {
-        ExecuteOptions = 0xD;
+        ExecuteOptions = MEM_EXECUTE_OPTION_DISABLE |
+                         MEM_EXECUTE_OPTION_DISABLE_THUNK_EMULATION |
+                         MEM_EXECUTE_OPTION_PERMANENT;
     }
-    else if (!SharedUserData->NXSupportPolicy)
+    else if (SharedUserData->NXSupportPolicy == NX_SUPPORT_POLICY_ALWAYSOFF)
     {
-        ExecuteOptions = 0xA;
+        ExecuteOptions = MEM_EXECUTE_OPTION_ENABLE | 
MEM_EXECUTE_OPTION_PERMANENT;
+    }
+    Status = NtSetInformationProcess(NtCurrentProcess(),
+                                     ProcessExecuteFlags,
+                                     &ExecuteOptions,
+                                     sizeof(ExecuteOptions));
+    if (!NT_SUCCESS(Status))
+    {
+        DPRINT1("LDR: Could not set process execute flags 0x%x; status %x\n",
+                ExecuteOptions, Status);
     }
-
-    /* Let Mm know */
-    ZwSetInformationProcess(NtCurrentProcess(),
-                            ProcessExecuteFlags,
-                            &ExecuteOptions,
-                            sizeof(ULONG));
 
     // FIXME: Should be done by Application Compatibility features,
     // by reading the registry, etc...

Reply via email to