From 7b6e284d394a2ba9f3e315abe116315aea9fa44e Mon Sep 17 00:00:00 2001 From: Aiken Harris Date: Tue, 3 Feb 2026 22:28:17 +0100 Subject: [PATCH] Refactor PFN database initialization loop on i686 --- xtoskrnl/mm/i686/pfn.cc | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/xtoskrnl/mm/i686/pfn.cc b/xtoskrnl/mm/i686/pfn.cc index a939809..e34db8a 100644 --- a/xtoskrnl/mm/i686/pfn.cc +++ b/xtoskrnl/mm/i686/pfn.cc @@ -69,27 +69,36 @@ MM::Pfn::InitializePfnDatabase(VOID) continue; } - /* Split PFN DB allocation out of free descriptor */ + /* Check if this is the modified free descriptor */ if(Descriptor == FreeDescriptor) { - /* Initialize PFNs for the remaining free memory after the PFN database */ - ProcessMemoryDescriptor(OriginalFreeDescriptor.BasePage + MemoryLayout->PfnDatabaseSize, - OriginalFreeDescriptor.PageCount - MemoryLayout->PfnDatabaseSize, - LoaderFree); + /* Switch to the original descriptor */ + Descriptor = &OriginalFreeDescriptor; + } - /* Initialize PFNs for the physical pages backing the PFN database itself */ - ProcessMemoryDescriptor(OriginalFreeDescriptor.BasePage, MemoryLayout->PfnDatabaseSize, LoaderMemoryData); - } - else + /* Check if the free memory block that was split is being processed */ + if(Descriptor == &OriginalFreeDescriptor) { - /* Initialize PFNs for the physical pages described by this descriptor */ - ProcessMemoryDescriptor(Descriptor->BasePage, Descriptor->PageCount, Descriptor->MemoryType); + /* Skip loop processing, free memory is initialized separately */ + ListEntry = ListEntry->Flink; + continue; } + /* Initialize PFNs for this memory range */ + ProcessMemoryDescriptor(Descriptor->BasePage, Descriptor->PageCount, Descriptor->MemoryType); + /* Move to the next descriptor */ ListEntry = ListEntry->Flink; } + /* Initialize PFNs for the free memory */ + ProcessMemoryDescriptor(FreeDescriptor->BasePage, FreeDescriptor->PageCount, LoaderFree); + + /* Initialize PFNs for the physical pages backing the PFN database */ + ProcessMemoryDescriptor(OriginalFreeDescriptor.BasePage, + FreeDescriptor->BasePage - OriginalFreeDescriptor.BasePage, + LoaderMemoryData); + /* Restore original free descriptor */ *FreeDescriptor = OriginalFreeDescriptor;