Parameterize maximum allocation address in hardware pool and scan memory descriptors in reverse
All checks were successful
Builds / ExectOS (amd64, release) (push) Successful in -59m30s
Builds / ExectOS (amd64, debug) (push) Successful in -59m28s
Builds / ExectOS (i686, debug) (push) Successful in -59m27s
Builds / ExectOS (i686, release) (push) Successful in -59m29s

This commit is contained in:
2026-05-12 19:35:06 +02:00
parent 5a92173586
commit 06635ed014
4 changed files with 13 additions and 8 deletions

View File

@@ -496,7 +496,7 @@ HL::Acpi::InitializeAcpiSystemStructure(VOID)
PageCount = SIZE_TO_PAGES(CpuCount * sizeof(PROCESSOR_IDENTITY)); PageCount = SIZE_TO_PAGES(CpuCount * sizeof(PROCESSOR_IDENTITY));
/* Allocate memory for CPU information */ /* 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) if(Status != STATUS_SUCCESS)
{ {
/* Failed to allocate memory, return error */ /* Failed to allocate memory, return error */

View File

@@ -25,6 +25,7 @@ namespace MM
public: public:
STATIC XTAPI XTSTATUS AllocateHardwareMemory(IN PFN_NUMBER PageCount, STATIC XTAPI XTSTATUS AllocateHardwareMemory(IN PFN_NUMBER PageCount,
IN BOOLEAN Aligned, IN BOOLEAN Aligned,
IN ULONGLONG MaximumAddress,
OUT PPHYSICAL_ADDRESS Buffer); OUT PPHYSICAL_ADDRESS Buffer);
STATIC XTAPI XTSTATUS MapHardwareMemory(IN PHYSICAL_ADDRESS PhysicalAddress, STATIC XTAPI XTSTATUS MapHardwareMemory(IN PHYSICAL_ADDRESS PhysicalAddress,
IN PFN_NUMBER PageCount, IN PFN_NUMBER PageCount,

View File

@@ -18,6 +18,9 @@
* @param Aligned * @param Aligned
* Specifies whether allocated memory should be aligned to 64k boundary or not. * 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 * @param Buffer
* Supplies a buffer that receives the physical address. * Supplies a buffer that receives the physical address.
* *
@@ -29,18 +32,19 @@ XTAPI
XTSTATUS XTSTATUS
MM::HardwarePool::AllocateHardwareMemory(IN PFN_NUMBER PageCount, MM::HardwarePool::AllocateHardwareMemory(IN PFN_NUMBER PageCount,
IN BOOLEAN Aligned, IN BOOLEAN Aligned,
IN ULONGLONG MaximumAddress,
OUT PPHYSICAL_ADDRESS Buffer) OUT PPHYSICAL_ADDRESS Buffer)
{ {
PLOADER_MEMORY_DESCRIPTOR Descriptor, ExtraDescriptor, HardwareDescriptor; PLOADER_MEMORY_DESCRIPTOR Descriptor, ExtraDescriptor, HardwareDescriptor;
PLIST_ENTRY ListEntry, LoaderMemoryDescriptors;
PFN_NUMBER Alignment, MaxPage; PFN_NUMBER Alignment, MaxPage;
ULONGLONG PhysicalAddress; ULONGLONG PhysicalAddress;
PLIST_ENTRY ListEntry, LoaderMemoryDescriptors;
/* Assume failure */ /* Assume failure */
(*Buffer).QuadPart = 0; (*Buffer).QuadPart = 0;
/* Calculate maximum page address */ /* Calculate maximum page address based on the requested limit */
MaxPage = MM_MAXIMUM_PHYSICAL_ADDRESS >> MM_PAGE_SHIFT; MaxPage = MaximumAddress >> MM_PAGE_SHIFT;
/* Make sure there are at least 2 descriptors available */ /* Make sure there are at least 2 descriptors available */
if((UsedHardwareAllocationDescriptors + 2) > MM_HARDWARE_ALLOCATION_DESCRIPTORS) if((UsedHardwareAllocationDescriptors + 2) > MM_HARDWARE_ALLOCATION_DESCRIPTORS)
@@ -53,7 +57,7 @@ MM::HardwarePool::AllocateHardwareMemory(IN PFN_NUMBER PageCount,
LoaderMemoryDescriptors = KE::BootInformation::GetMemoryDescriptors(); LoaderMemoryDescriptors = KE::BootInformation::GetMemoryDescriptors();
/* Scan memory descriptors provided by the boot loader */ /* Scan memory descriptors provided by the boot loader */
ListEntry = LoaderMemoryDescriptors->Flink; ListEntry = LoaderMemoryDescriptors->Blink;
while(ListEntry != LoaderMemoryDescriptors) while(ListEntry != LoaderMemoryDescriptors)
{ {
Descriptor = CONTAIN_RECORD(ListEntry, LOADER_MEMORY_DESCRIPTOR, ListEntry); Descriptor = CONTAIN_RECORD(ListEntry, LOADER_MEMORY_DESCRIPTOR, ListEntry);
@@ -75,8 +79,8 @@ MM::HardwarePool::AllocateHardwareMemory(IN PFN_NUMBER PageCount,
} }
} }
/* Move to next descriptor */ /* Move to previous descriptor */
ListEntry = ListEntry->Flink; ListEntry = ListEntry->Blink;
} }
/* Make sure we found a descriptor */ /* Make sure we found a descriptor */

View File

@@ -298,7 +298,7 @@ MM::Manager::MapKernelSharedData(VOID)
XTSTATUS Status; XTSTATUS Status;
/* Allocate one physical page from the hardware pool for the shared data */ /* 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) if(Status != STATUS_SUCCESS)
{ {
/* Memory allocation failed, return error code */ /* Memory allocation failed, return error code */