From 858055798575d293693786193a4352c9877679b2 Mon Sep 17 00:00:00 2001 From: Rafal Kupiec Date: Mon, 22 Jan 2024 15:09:03 +0100 Subject: [PATCH] Check if new mapping is a subset of an already existing mapping --- xtldr/memory.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/xtldr/memory.c b/xtldr/memory.c index 717c871..8ae89d1 100644 --- a/xtldr/memory.c +++ b/xtldr/memory.c @@ -339,6 +339,17 @@ BlMapVirtualMemory(IN OUT PXTBL_PAGE_MAPPING PageMap, Mapping2 = CONTAIN_RECORD(ListEntry, LOADER_MEMORY_MAPPING, ListEntry); PhysicalAddress2End = (PUINT8)Mapping2->PhysicalAddress + (Mapping2->NumberOfPages * EFI_PAGE_SIZE) - 1 ; + /* Check if new mapping is a subset of an existing mapping */ + if(Mapping1->PhysicalAddress >= Mapping2->PhysicalAddress && PhysicalAddressEnd <= PhysicalAddress2End) + { + /* Make sure it's memory type is the same */ + if(Mapping1->MemoryType == Mapping2->MemoryType) + { + /* It is already mapped */ + return STATUS_EFI_SUCCESS; + } + } + /* Check if they overlap */ if(PhysicalAddressEnd > Mapping2->PhysicalAddress && PhysicalAddressEnd <= PhysicalAddress2End) {