Refactor PFN initialization to ensure proper page table setup
This commit is contained in:
@@ -24,7 +24,6 @@ MM::Pfn::InitializePfnDatabase(VOID)
|
|||||||
PKERNEL_INITIALIZATION_BLOCK InitializationBlock;
|
PKERNEL_INITIALIZATION_BLOCK InitializationBlock;
|
||||||
PLIST_ENTRY ListEntry;
|
PLIST_ENTRY ListEntry;
|
||||||
PLOADER_MEMORY_DESCRIPTOR Descriptor;
|
PLOADER_MEMORY_DESCRIPTOR Descriptor;
|
||||||
PFN_NUMBER BasePage, PageCount;
|
|
||||||
PUCHAR PfnDatabaseEnd;
|
PUCHAR PfnDatabaseEnd;
|
||||||
PMMMEMORY_LAYOUT MemoryLayout;
|
PMMMEMORY_LAYOUT MemoryLayout;
|
||||||
PMMPTE ValidPte;
|
PMMPTE ValidPte;
|
||||||
@@ -67,43 +66,41 @@ MM::Pfn::InitializePfnDatabase(VOID)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Determine the physical page range to process */
|
/* Check if this is the modified free descriptor */
|
||||||
if(Descriptor == FreeDescriptor)
|
if(Descriptor == FreeDescriptor)
|
||||||
{
|
{
|
||||||
BasePage = OriginalFreeDescriptor.BasePage;
|
/* Switch to the original descriptor */
|
||||||
PageCount = OriginalFreeDescriptor.PageCount;
|
Descriptor = &OriginalFreeDescriptor;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
/* Map PFN database entries for this range */
|
||||||
|
MM::Pte::MapPTE(&((PMMPFN)MemoryLayout->PfnDatabase)[Descriptor->BasePage],
|
||||||
|
(PUCHAR)&((PMMPFN)MemoryLayout->PfnDatabase)[Descriptor->BasePage + Descriptor->PageCount] - 1,
|
||||||
|
ValidPte);
|
||||||
|
|
||||||
|
/* Check if the free memory block that was split is being processed */
|
||||||
|
if(Descriptor == &OriginalFreeDescriptor)
|
||||||
{
|
{
|
||||||
BasePage = Descriptor->BasePage;
|
/* Skip loop processing, free memory is initialized separately */
|
||||||
PageCount = Descriptor->PageCount;
|
ListEntry = ListEntry->Flink;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Map PFN database entries for this physical range */
|
/* Map PFN database entries for this physical range */
|
||||||
MM::Pte::MapPTE(&((PMMPFN)MemoryLayout->PfnDatabase)[BasePage],
|
ProcessMemoryDescriptor(Descriptor->BasePage, Descriptor->PageCount, Descriptor->MemoryType);
|
||||||
(PUCHAR)&((PMMPFN)MemoryLayout->PfnDatabase)[BasePage + PageCount] - 1,
|
|
||||||
ValidPte);
|
|
||||||
|
|
||||||
/* Split PFN database allocation out of the free descriptor */
|
|
||||||
if(Descriptor == FreeDescriptor)
|
|
||||||
{
|
|
||||||
/* Initialize PFNs for the remaining free memory */
|
|
||||||
ProcessMemoryDescriptor(BasePage + MemoryLayout->PfnDatabaseSize,
|
|
||||||
PageCount - MemoryLayout->PfnDatabaseSize, LoaderFree);
|
|
||||||
|
|
||||||
/* Initialize PFNs for the physical pages backing the PFN database */
|
|
||||||
ProcessMemoryDescriptor(BasePage, MemoryLayout->PfnDatabaseSize, LoaderMemoryData);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Initialize PFNs for this memory range */
|
|
||||||
ProcessMemoryDescriptor(BasePage, PageCount, Descriptor->MemoryType);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Move to the next descriptor */
|
/* Move to the next descriptor */
|
||||||
ListEntry = ListEntry->Flink;
|
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 */
|
/* Restore original free descriptor */
|
||||||
*FreeDescriptor = OriginalFreeDescriptor;
|
*FreeDescriptor = OriginalFreeDescriptor;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user