Correctly setup PFN database for ROM and in-use pages
This commit is contained in:
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user