From 7f0341bb8333f100d987037bdee0a71a8ac1a3ca Mon Sep 17 00:00:00 2001 From: Aiken Harris Date: Sun, 1 Feb 2026 11:11:59 +0100 Subject: [PATCH] Fix physical address limit checks --- boot/xtldr/memory.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/boot/xtldr/memory.cc b/boot/xtldr/memory.cc index 792330b..7a765b0 100644 --- a/boot/xtldr/memory.cc +++ b/boot/xtldr/memory.cc @@ -376,14 +376,14 @@ Memory::MapEfiMemory(IN OUT PXTBL_PAGE_MAPPING PageMap, else if(PageMap->PageMapLevel == 3) { /* Limit physical address to 64GB in PAE mode */ - MaxAddress = 0xFFFFFFFFF; + MaxAddress = 0xFFFFFFFFFULL; } /* Check page map level */ if(PageMap->PageMapLevel == 2 || PageMap->PageMapLevel == 3) { /* Check if physical address starts beyond limit */ - if(Descriptor->PhysicalStart > MaxAddress) + if(Descriptor->PhysicalStart >= MaxAddress) { /* Go to the next descriptor */ Descriptor = (PEFI_MEMORY_DESCRIPTOR)((PUCHAR)Descriptor + MemoryMap->DescriptorSize); @@ -394,7 +394,7 @@ Memory::MapEfiMemory(IN OUT PXTBL_PAGE_MAPPING PageMap, if(Descriptor->PhysicalStart + (Descriptor->NumberOfPages << EFI_PAGE_SHIFT) > MaxAddress) { /* Truncate memory descriptor to the lowest supported physical page */ - Descriptor->NumberOfPages = (((ULONGLONG)MaxAddress) - Descriptor->PhysicalStart) >> EFI_PAGE_SHIFT; + Descriptor->NumberOfPages = (MaxAddress - Descriptor->PhysicalStart) >> EFI_PAGE_SHIFT; } }