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

This commit is contained in:
mintsuki 2022-07-24 22:36:46 +02:00
parent 4859ee9790
commit dcfef93ff6

View File

@ -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;