:: commit 3553c13581edf8fa545c3e1fe8aa792fb9a475d6

mintsuki <mintsuki@protonmail.com> — 2021-10-31 04:17

parents: 9861b22641

elf: Fix bug related to overshoot check

diff --git a/stage23/lib/elf.c b/stage23/lib/elf.c
index 76755969..6398c6ac 100644
--- a/stage23/lib/elf.c
+++ b/stage23/lib/elf.c
@@ -542,11 +542,6 @@ final:
 
         uint64_t this_top = load_addr + phdr.p_memsz;
 
-        // Make sure we don't overshoot
-        if (higher_half == true && this_top > 0x80000000) {
-            goto again;
-        }
-
         if (top) {
             if (this_top > *top) {
                 *top = this_top;
@@ -564,7 +559,8 @@ final:
         }
 
         if (!fully_virtual &&
-            !memmap_alloc_range((size_t)mem_base, (size_t)mem_size, alloc_type, true, false, simulation, false)) {
+            ((higher_half == true && this_top > 0x80000000)
+          || !memmap_alloc_range((size_t)mem_base, (size_t)mem_size, alloc_type, true, false, simulation, false))) {
             if (++try_count == max_simulated_tries || simulation == false) {
                 panic("elf: Failed to allocate necessary memory ranges");
             }
tab: 248 wrap: offon