Correctly setup PFN database for ROM and in-use pages
All checks were successful
Builds / ExectOS (amd64, debug) (push) Successful in 23s
Builds / ExectOS (i686, debug) (push) Successful in 25s
Builds / ExectOS (amd64, release) (push) Successful in 38s
Builds / ExectOS (i686, release) (push) Successful in 37s

This commit is contained in:
2026-01-06 14:49:30 +01:00
parent 36e53bfc8c
commit bee91d0c71

View File

@@ -177,7 +177,8 @@ MM::Pfn::ProcessMemoryDescriptor(IN PFN_NUMBER BasePage,
IN PFN_NUMBER PageCount, IN PFN_NUMBER PageCount,
IN LOADER_MEMORY_TYPE MemoryType) IN LOADER_MEMORY_TYPE MemoryType)
{ {
PFN_NUMBER CurrentPage, PageNumber; PFN_NUMBER PageNumber;
PMMPDE PointerPde;
PMMPFN Pfn; PMMPFN Pfn;
/* Check if the memory descriptor describes a free memory region */ /* Check if the memory descriptor describes a free memory region */
@@ -186,13 +187,8 @@ MM::Pfn::ProcessMemoryDescriptor(IN PFN_NUMBER BasePage,
/* Iterate over each page in this free memory run */ /* Iterate over each page in this free memory run */
for(PageNumber = 0; PageNumber < PageCount; PageNumber++) for(PageNumber = 0; PageNumber < PageCount; PageNumber++)
{ {
/* Get the PFN entry for the current page and set its initial cache attribute */
CurrentPage = BasePage + PageNumber;
Pfn = GetPfnEntry(CurrentPage);
Pfn->u3.e1.CacheAttribute = PfnNonCached;
/* Add the page to the free list to make it available for allocation */ /* Add the page to the free list to make it available for allocation */
LinkFreePage(CurrentPage); LinkFreePage(BasePage + PageNumber);
} }
} }
else else
@@ -215,8 +211,14 @@ MM::Pfn::ProcessMemoryDescriptor(IN PFN_NUMBER BasePage,
/* Get the PFN entry for the current ROM page */ /* Get the PFN entry for the current ROM page */
Pfn = GetPfnEntry(BasePage + PageNumber); Pfn = GetPfnEntry(BasePage + PageNumber);
/* Ensure that the page is not already in-use */
if(Pfn->u3.e2.ReferenceCount == 0)
{
/* Get the page directory entry for the current page */
PointerPde = MM::Paging::GetPdeAddress((PVOID)(KSEG0_BASE + (BasePage << MM_PAGE_SHIFT)));
/* Initialize the PFN entry to represent a ROM page */ /* Initialize the PFN entry to represent a ROM page */
Pfn->PteAddress = 0; Pfn->PteAddress = MM::Paging::GetPteAddress((PVOID)(KSEG0_BASE + (BasePage << MM_PAGE_SHIFT)));
Pfn->u1.Flink = 0; Pfn->u1.Flink = 0;
Pfn->u2.ShareCount = 0; Pfn->u2.ShareCount = 0;
Pfn->u3.e1.CacheAttribute = PfnNonCached; Pfn->u3.e1.CacheAttribute = PfnNonCached;
@@ -225,7 +227,8 @@ MM::Pfn::ProcessMemoryDescriptor(IN PFN_NUMBER BasePage,
Pfn->u3.e1.Rom = 1; Pfn->u3.e1.Rom = 1;
Pfn->u3.e2.ReferenceCount = 0; Pfn->u3.e2.ReferenceCount = 0;
Pfn->u4.InPageError = 0; Pfn->u4.InPageError = 0;
Pfn->u4.PteFrame = 0; Pfn->u4.PteFrame = MM::Paging::GetPageFrameNumber(PointerPde);
}
} }
break; break;
default: default:
@@ -235,8 +238,20 @@ MM::Pfn::ProcessMemoryDescriptor(IN PFN_NUMBER BasePage,
/* Get the PFN entry for the current in-use page */ /* Get the PFN entry for the current in-use page */
Pfn = GetPfnEntry(BasePage + PageNumber); Pfn = GetPfnEntry(BasePage + PageNumber);
/* Mark the PFN as active and valid to prevent it from being allocated */ /* Ensure that the page is not already in-use */
if(Pfn->u3.e2.ReferenceCount == 0)
{
/* Get the page directory entry for the current page */
PointerPde = MM::Paging::GetPdeAddress((PVOID)(KSEG0_BASE + (BasePage << MM_PAGE_SHIFT)));
/* Initialize the PFN entry to represent an in-use page and prevent it from being allocated */
Pfn->PteAddress = MM::Paging::GetPteAddress((PVOID)(KSEG0_BASE + (BasePage << MM_PAGE_SHIFT)));
Pfn->u2.ShareCount++;
Pfn->u3.e1.CacheAttribute = PfnNonCached;
Pfn->u3.e1.PageLocation = ActiveAndValid; Pfn->u3.e1.PageLocation = ActiveAndValid;
Pfn->u3.e2.ReferenceCount = 1;
Pfn->u4.PteFrame = MM::Paging::GetPageFrameNumber(PointerPde);
}
} }
break; break;
} }