diff --git a/xtoskrnl/includes/mm/pfn.hh b/xtoskrnl/includes/mm/pfn.hh index 6546b2f..9f98251 100644 --- a/xtoskrnl/includes/mm/pfn.hh +++ b/xtoskrnl/includes/mm/pfn.hh @@ -31,6 +31,7 @@ namespace MM STATIC XTAPI VOID ComputePfnDatabaseSize(VOID); STATIC XTAPI ULONGLONG GetNumberOfPhysicalPages(VOID); STATIC XTAPI PFN_NUMBER GetPfnDatabaseSize(VOID); + STATIC XTAPI PMMPFN GetPfnEntry(IN PFN_NUMBER Pfn); STATIC XTAPI VOID ScanMemoryDescriptors(VOID); private: diff --git a/xtoskrnl/mm/pfn.cc b/xtoskrnl/mm/pfn.cc index 5a8d20e..966572e 100644 --- a/xtoskrnl/mm/pfn.cc +++ b/xtoskrnl/mm/pfn.cc @@ -105,6 +105,36 @@ MM::Pfn::GetPfnDatabaseSize(VOID) return PfnDatabaseSize; } +/** + * Retrieves a pointer to the PFN database entry for a given physical page. + * + * @param Pfn + * The Page Frame Number (PFN) to look up. + * + * @return This routine returns a pointer to the MMPFN structure for the given PFN, or NULLPTR if the PFN is invalid. + * + * @since XT 1.0 + */ +XTAPI +PMMPFN +MM::Pfn::GetPfnEntry(IN PFN_NUMBER Pfn) +{ + PMMMEMORY_LAYOUT MemoryLayout; + + /* Validate that the PFN is within the range of managed physical memory */ + if(Pfn > HighestPhysicalPage) + { + /* The requested page number is outside the bounds, return NULLPTR */ + return NULLPTR; + } + + /* Get the memory layout */ + MemoryLayout = MM::Manager::GetMemoryLayout(); + + /* Calculate the address of the PFN entry by indexing into the PFN database array and return it */ + return &((PMMPFN)MemoryLayout->PfnDatabaseAddress)[Pfn]; +} + /** * Increments the global count of available pages. *