:: commit 07e6c2d5492bc8948ed34b0b75cdf654817eeb78

mintsuki <mintsuki@protonmail.com> — 2022-09-02 01:41

parents: 50fb77eec2

limine: Do not set NX bit in page tables if NX not available

diff --git a/common/protos/limine.c b/common/protos/limine.c
index 1890884d..7ece73f2 100644
--- a/common/protos/limine.c
+++ b/common/protos/limine.c
@@ -617,22 +617,22 @@ FEAT_END
 
     void *stack = ext_mem_alloc(stack_size) + stack_size;
 
+    bool nx_available = true;
+#if defined (__x86_64__) || defined (__i386__)
+    // Check if we have NX
+    if (!cpuid(0x80000001, 0, &eax, &ebx, &ecx, &edx) || !(edx & (1 << 20))) {
+        nx_available = false;
+    }
+#endif
+
     pagemap_t pagemap = {0};
-    pagemap = stivale_build_pagemap(want_5lv, true, ranges, ranges_count, true,
+    pagemap = stivale_build_pagemap(want_5lv, nx_available, ranges, ranges_count, true,
                                     physical_base, virtual_base, direct_map_offset);
 
 #if defined (UEFI)
     efi_exit_boot_services();
 #endif
 
-#if defined (__x86_64__) || defined (__i386__)
-    // Check if we have NX
-    bool nx_available = false;
-    if (cpuid(0x80000001, 0, &eax, &ebx, &ecx, &edx) && (edx & (1 << 20))) {
-        nx_available = true;
-    }
-#endif
-
     // SMP
 FEAT_START
     struct limine_smp_request *smp_request = get_request(LIMINE_SMP_REQUEST);
tab: 248 wrap: offon