diff --git a/xtoskrnl/hl/acpi.cc b/xtoskrnl/hl/acpi.cc index 661d9d3..6fc4689 100644 --- a/xtoskrnl/hl/acpi.cc +++ b/xtoskrnl/hl/acpi.cc @@ -496,7 +496,7 @@ HL::Acpi::InitializeAcpiSystemStructure(VOID) PageCount = SIZE_TO_PAGES(CpuCount * sizeof(PROCESSOR_IDENTITY)); /* Allocate memory for CPU information */ - Status = MM::HardwarePool::AllocateHardwareMemory(PageCount, TRUE, &PhysicalAddress); + Status = MM::HardwarePool::AllocateHardwareMemory(PageCount, TRUE, MM_MAXIMUM_PHYSICAL_ADDRESS, &PhysicalAddress); if(Status != STATUS_SUCCESS) { /* Failed to allocate memory, return error */ diff --git a/xtoskrnl/includes/mm/hlpool.hh b/xtoskrnl/includes/mm/hlpool.hh index 007605c..de53a94 100644 --- a/xtoskrnl/includes/mm/hlpool.hh +++ b/xtoskrnl/includes/mm/hlpool.hh @@ -25,6 +25,7 @@ namespace MM public: STATIC XTAPI XTSTATUS AllocateHardwareMemory(IN PFN_NUMBER PageCount, IN BOOLEAN Aligned, + IN ULONGLONG MaximumAddress, OUT PPHYSICAL_ADDRESS Buffer); STATIC XTAPI XTSTATUS MapHardwareMemory(IN PHYSICAL_ADDRESS PhysicalAddress, IN PFN_NUMBER PageCount, diff --git a/xtoskrnl/mm/hlpool.cc b/xtoskrnl/mm/hlpool.cc index 2504f8b..847d6ea 100644 --- a/xtoskrnl/mm/hlpool.cc +++ b/xtoskrnl/mm/hlpool.cc @@ -18,6 +18,9 @@ * @param Aligned * Specifies whether allocated memory should be aligned to 64k boundary or not. * + * @param MaximumAddress + * Supplies the maximum acceptable physical address for the allocation. + * * @param Buffer * Supplies a buffer that receives the physical address. * @@ -29,18 +32,19 @@ XTAPI XTSTATUS MM::HardwarePool::AllocateHardwareMemory(IN PFN_NUMBER PageCount, IN BOOLEAN Aligned, + IN ULONGLONG MaximumAddress, OUT PPHYSICAL_ADDRESS Buffer) { PLOADER_MEMORY_DESCRIPTOR Descriptor, ExtraDescriptor, HardwareDescriptor; + PLIST_ENTRY ListEntry, LoaderMemoryDescriptors; PFN_NUMBER Alignment, MaxPage; ULONGLONG PhysicalAddress; - PLIST_ENTRY ListEntry, LoaderMemoryDescriptors; /* Assume failure */ (*Buffer).QuadPart = 0; - /* Calculate maximum page address */ - MaxPage = MM_MAXIMUM_PHYSICAL_ADDRESS >> MM_PAGE_SHIFT; + /* Calculate maximum page address based on the requested limit */ + MaxPage = MaximumAddress >> MM_PAGE_SHIFT; /* Make sure there are at least 2 descriptors available */ if((UsedHardwareAllocationDescriptors + 2) > MM_HARDWARE_ALLOCATION_DESCRIPTORS) @@ -53,7 +57,7 @@ MM::HardwarePool::AllocateHardwareMemory(IN PFN_NUMBER PageCount, LoaderMemoryDescriptors = KE::BootInformation::GetMemoryDescriptors(); /* Scan memory descriptors provided by the boot loader */ - ListEntry = LoaderMemoryDescriptors->Flink; + ListEntry = LoaderMemoryDescriptors->Blink; while(ListEntry != LoaderMemoryDescriptors) { Descriptor = CONTAIN_RECORD(ListEntry, LOADER_MEMORY_DESCRIPTOR, ListEntry); @@ -75,8 +79,8 @@ MM::HardwarePool::AllocateHardwareMemory(IN PFN_NUMBER PageCount, } } - /* Move to next descriptor */ - ListEntry = ListEntry->Flink; + /* Move to previous descriptor */ + ListEntry = ListEntry->Blink; } /* Make sure we found a descriptor */ diff --git a/xtoskrnl/mm/mmgr.cc b/xtoskrnl/mm/mmgr.cc index 4f75947..ce5e4af 100644 --- a/xtoskrnl/mm/mmgr.cc +++ b/xtoskrnl/mm/mmgr.cc @@ -298,7 +298,7 @@ MM::Manager::MapKernelSharedData(VOID) XTSTATUS Status; /* Allocate one physical page from the hardware pool for the shared data */ - Status = MM::HardwarePool::AllocateHardwareMemory(1, FALSE, &PhysAddr); + Status = MM::HardwarePool::AllocateHardwareMemory(1, FALSE, MM_MAXIMUM_PHYSICAL_ADDRESS, &PhysAddr); if(Status != STATUS_SUCCESS) { /* Memory allocation failed, return error code */