:: commit 8a024b24e351db072a210e65f0fa25d362c5bfc0

Qwinci <qwinci222@gmail.com> — 2025-09-15 15:54

parents: 0827a27560

lib: Don't discard discardable sections for PE images

Code put to a discardable section like INIT might be intended to only be
discarded after early kernel init, not before the kernel is even loaded.
Leave reclaiming the discardable memory up to the kernel so it can choose
to do it after it is done using the memory.
diff --git a/common/lib/pe.c b/common/lib/pe.c
index ade34e4b..e2c734e1 100644
--- a/common/lib/pe.c
+++ b/common/lib/pe.c
@@ -117,7 +117,6 @@ typedef struct {
     IMAGE_OPTIONAL_HEADER64 OptionalHeader;
 } IMAGE_NT_HEADERS64;
 
-#define IMAGE_SCN_MEM_DISCARDABLE 0x2000000
 #define IMAGE_SCN_MEM_EXECUTE 0x20000000
 #define IMAGE_SCN_MEM_READ 0x40000000
 #define IMAGE_SCN_MEM_WRITE 0x80000000
@@ -348,10 +347,6 @@ again:
         for (size_t i = 0; i < nt_hdrs->FileHeader.NumberOfSections; i++) {
             IMAGE_SECTION_HEADER *section = &sections[i];
 
-            if (section->Characteristics & IMAGE_SCN_MEM_DISCARDABLE) {
-                continue;
-            }
-
             if (section->VirtualAddress == 0) {
                 headers_within_section = true;
             }
@@ -380,10 +375,6 @@ again:
         for (size_t i = 0; i < nt_hdrs->FileHeader.NumberOfSections; i++) {
             IMAGE_SECTION_HEADER *section = &sections[i];
 
-            if (section->Characteristics & IMAGE_SCN_MEM_DISCARDABLE) {
-                continue;
-            }
-
             uintptr_t misalign = section->VirtualAddress % alignment;
 
             struct mem_range *range = &ranges[range_index++];
tab: 248 wrap: offon