:: commit dcfef93ff6c6c234861fac79d0dff01f6d62a0c3

mintsuki <mintsuki@protonmail.com> — 2022-07-24 20:36

parents: 4859ee9790

efi: Handle cases where untouched memmap entries are lower than current base

diff --git a/common/lib/blib.c b/common/lib/blib.c
index a14e8c79..d8e8b9d4 100644
--- a/common/lib/blib.c
+++ b/common/lib/blib.c
@@ -234,7 +234,25 @@ retry:
             if (untouched_memmap[j].type != MEMMAP_USABLE)
                 continue;
 
-            if (untouched_memmap[j].base >= base && untouched_memmap[j].base < top) {
+            if (top > untouched_memmap[j].base && top <= untouched_memmap[j].base + untouched_memmap[j].length) {
+                if (untouched_memmap[j].base < base) {
+                    new_entry->NumberOfPages = (base - untouched_memmap[j].base) / 4096;
+
+                    efi_copy_i++;
+                    if (efi_copy_i == EFI_COPY_MAX_ENTRIES) {
+                        panic(false, "efi: New memory map exhausted");
+                    }
+                    new_entry = (void *)efi_copy + efi_copy_i * efi_desc_size;
+                    memcpy(new_entry, orig_entry, efi_desc_size);
+
+                    new_entry->NumberOfPages -= (base - untouched_memmap[j].base) / 4096;
+                    new_entry->PhysicalStart = base;
+                    new_entry->VirtualStart = new_entry->PhysicalStart;
+
+                    length = new_entry->NumberOfPages * 4096;
+                    top = base + length;
+                }
+
                 if (untouched_memmap[j].base > base) {
                     new_entry->NumberOfPages = (untouched_memmap[j].base - base) / 4096;
 
tab: 248 wrap: offon