From 570301bb35e2d6d3b1fa679b663571f511813e39 Mon Sep 17 00:00:00 2001 From: Aiken Harris Date: Thu, 18 Dec 2025 22:38:59 +0100 Subject: [PATCH] Clarify page table entry offset semantics --- xtoskrnl/includes/mm/amd64/pagemap.hh | 10 +++---- xtoskrnl/includes/mm/i686/pagemap.hh | 6 ++--- xtoskrnl/mm/amd64/pagemap.cc | 39 ++++++++++++++------------- xtoskrnl/mm/i686/pagemap.cc | 20 +++++++------- 4 files changed, 38 insertions(+), 37 deletions(-) diff --git a/xtoskrnl/includes/mm/amd64/pagemap.hh b/xtoskrnl/includes/mm/amd64/pagemap.hh index 9aee6cf..19c62ae 100644 --- a/xtoskrnl/includes/mm/amd64/pagemap.hh +++ b/xtoskrnl/includes/mm/amd64/pagemap.hh @@ -29,23 +29,23 @@ namespace MM XTAPI PMMPTE GetNextPte(IN PMMPTE Pte); XTAPI BOOLEAN GetOneEntry(IN PMMPTE Pte); XTAPI PMMP5E GetP5eAddress(IN PVOID Address); - XTAPI ULONG GetP5eIndex(IN PVOID Address); + XTAPI ULONG GetP5eOffset(IN PVOID Address); XTAPI PVOID GetP5eVirtualAddress(IN PMMP5E P5ePointer); XTAPI PFN_NUMBER GetPageFrameNumber(IN PMMPTE Pte); XTAPI PMMPDE GetPdeAddress(IN PVOID Address); - XTAPI ULONG GetPdeIndex(IN PVOID Address); + XTAPI ULONG GetPdeOffset(IN PVOID Address); VIRTUAL XTAPI PVOID GetPdeVirtualAddress(IN PMMPDE PdePointer) = 0; XTAPI PMMPPE GetPpeAddress(IN PVOID Address); - XTAPI ULONG GetPpeIndex(IN PVOID Address); + XTAPI ULONG GetPpeOffset(IN PVOID Address); VIRTUAL XTAPI PVOID GetPpeVirtualAddress(IN PMMPPE PpePointer) = 0; XTAPI PMMPTE GetPteAddress(IN PVOID Address); XTAPI LONG GetPteDistance(PMMPTE EndPte, PMMPTE StartPte); - XTAPI ULONG GetPteIndex(IN PVOID Address); + XTAPI ULONG GetPteOffset(IN PVOID Address); XTAPI ULONG GetPteSize(VOID); VIRTUAL XTAPI PVOID GetPteVirtualAddress(IN PMMPTE PtePointer) = 0; XTAPI PMMPXE GetPxeAddress(IN PVOID Address); - XTAPI ULONG GetPxeIndex(IN PVOID Address); + XTAPI ULONG GetPxeOffset(IN PVOID Address); VIRTUAL XTAPI PVOID GetPxeVirtualAddress(IN PMMPXE PxePointer) = 0; XTAPI BOOLEAN GetXpaStatus(); VIRTUAL XTAPI VOID InitializePageMapInfo(VOID) = 0; diff --git a/xtoskrnl/includes/mm/i686/pagemap.hh b/xtoskrnl/includes/mm/i686/pagemap.hh index 5ae935a..e439fab 100644 --- a/xtoskrnl/includes/mm/i686/pagemap.hh +++ b/xtoskrnl/includes/mm/i686/pagemap.hh @@ -30,13 +30,13 @@ namespace MM VIRTUAL XTAPI BOOLEAN GetOneEntry(IN PMMPTE Pte) = 0; VIRTUAL XTAPI PFN_NUMBER GetPageFrameNumber(IN PMMPTE Pte) = 0; XTAPI PMMPDE GetPdeAddress(IN PVOID Address); - XTAPI ULONG GetPdeIndex(IN PVOID Address); + XTAPI ULONG GetPdeOffset(IN PVOID Address); VIRTUAL XTAPI PVOID GetPdeVirtualAddress(IN PMMPDE PdePointer) = 0; XTAPI PMMPPE GetPpeAddress(IN PVOID Address); - XTAPI ULONG GetPpeIndex(IN PVOID Address); + XTAPI ULONG GetPpeOffset(IN PVOID Address); XTAPI PVOID GetPpeVirtualAddress(IN PMMPPE PpePointer); XTAPI PMMPTE GetPteAddress(IN PVOID Address); - XTAPI ULONG GetPteIndex(IN PVOID Address); + XTAPI ULONG GetPteOffset(IN PVOID Address); VIRTUAL XTAPI LONG GetPteDistance(PMMPTE EndPte, PMMPTE StartPte) = 0; VIRTUAL XTAPI ULONG GetPteSize(VOID) = 0; diff --git a/xtoskrnl/mm/amd64/pagemap.cc b/xtoskrnl/mm/amd64/pagemap.cc index 290f880..fff7c91 100644 --- a/xtoskrnl/mm/amd64/pagemap.cc +++ b/xtoskrnl/mm/amd64/pagemap.cc @@ -140,19 +140,20 @@ MM::PageMap::GetP5eAddress(IN PVOID Address) } /** - * Gets the index of the P5E (Page Map Level 5 Entry), that maps given address. + * Gets the Offset of the P5E (Page Map Level 5 Entry), that maps given address. * * @param Address * Specifies the virtual address for which to retrieve the corresponding P5E. * - * @return This routine returns the index of the P5E, or NULLPTR if LA57 is not enabled. + * @return This routine returns the Offset of the P5E, or NULLPTR if LA57 is not enabled. * * @since XT 1.0 */ XTAPI ULONG -MM::PageMap::GetP5eIndex(IN PVOID Address) +MM::PageMap::GetP5eOffset(IN PVOID Address) { + /* Return P5E Offset */ return (((((ULONGLONG)Address) >> MM_P5I_SHIFT) & 0x1FF) * PageMapInfo.Xpa); } @@ -212,20 +213,20 @@ MM::PageMap::GetPdeAddress(IN PVOID Address) } /** - * Gets the index of the PDE (Page Directory Entry), that maps given address. + * Gets the Offset of the PDE (Page Directory Entry), that maps given address. * * @param Address * Specifies the virtual address for which to retrieve the corresponding PDE. * - * @return This routine returns the index of the PDE. + * @return This routine returns the Offset of the PDE. * * @since XT 1.0 */ XTAPI ULONG -MM::PageMap::GetPdeIndex(IN PVOID Address) +MM::PageMap::GetPdeOffset(IN PVOID Address) { - /* Return PDE index */ + /* Return PDE Offset */ return ((((ULONGLONG)Address) >> MM_PDI_SHIFT) & 0x1FF); } @@ -251,20 +252,20 @@ MM::PageMap::GetPpeAddress(IN PVOID Address) } /** - * Gets the index of the PPE (Page Directory Pointer Table Entry), that maps given address. + * Gets the Offset of the PPE (Page Directory Pointer Table Entry), that maps given address. * * @param Address * Specifies the virtual address for which to retrieve the corresponding PPE. * - * @return This routine returns the index of the PPE. + * @return This routine returns the Offset of the PPE. * * @since XT 1.0 */ XTAPI ULONG -MM::PageMap::GetPpeIndex(IN PVOID Address) +MM::PageMap::GetPpeOffset(IN PVOID Address) { - /* Return PPE index */ + /* Return PPE Offset */ return ((((ULONGLONG)Address) >> MM_PPI_SHIFT) & 0x1FF); } @@ -312,20 +313,20 @@ MM::PageMap::GetPteDistance(PMMPTE EndPte, } /** - * Gets the index of the PTE (Page Table Entry), that maps given address. + * Gets the Offset of the PTE (Page Table Entry), that maps given address. * * @param Address * Specifies the virtual address for which to retrieve the corresponding PTE. * - * @return This routine returns the index of the PTE. + * @return This routine returns the Offset of the PTE. * * @since XT 1.0 */ XTAPI ULONG -MM::PageMap::GetPteIndex(IN PVOID Address) +MM::PageMap::GetPteOffset(IN PVOID Address) { - /* Return PTE index */ + /* Return PTE Offset */ return ((((ULONGLONG)Address) >> MM_PTI_SHIFT) & 0x1FF); } @@ -366,20 +367,20 @@ MM::PageMap::GetPxeAddress(IN PVOID Address) } /** - * Gets the index of the PXE (Extended Page Entry), that maps given address. + * Gets the Offset of the PXE (Extended Page Entry), that maps given address. * * @param Address * Specifies the virtual address for which to retrieve the corresponding PXE. * - * @return This routine returns the index of the PXE. + * @return This routine returns the Offset of the PXE. * * @since XT 1.0 */ XTAPI ULONG -MM::PageMap::GetPxeIndex(IN PVOID Address) +MM::PageMap::GetPxeOffset(IN PVOID Address) { - /* Return PXE index */ + /* Return PXE Offset */ return ((((ULONGLONG)Address) >> MM_PXI_SHIFT) & 0x1FF); } diff --git a/xtoskrnl/mm/i686/pagemap.cc b/xtoskrnl/mm/i686/pagemap.cc index c972336..553d3ed 100644 --- a/xtoskrnl/mm/i686/pagemap.cc +++ b/xtoskrnl/mm/i686/pagemap.cc @@ -64,20 +64,20 @@ MM::PageMap::GetPdeAddress(IN PVOID Address) } /** - * Gets the index of the PDE (Page Directory Entry), that maps given address. + * Gets the Offset of the PDE (Page Directory Entry), that maps given address. * * @param Address * Specifies the virtual address for which to retrieve the corresponding PDE. * - * @return This routine returns the index of the PDE. + * @return This routine returns the Offset of the PDE. * * @since XT 1.0 */ XTAPI ULONG -MM::PageMap::GetPdeIndex(IN PVOID Address) +MM::PageMap::GetPdeOffset(IN PVOID Address) { - /* Return PDE index */ + /* Return PDE Offset */ return ((((ULONG_PTR)(Address)) >> PageMapInfo.PdiShift) & (PageMapInfo.Xpa ? 0x1FF : 0x3FF)); } @@ -101,7 +101,7 @@ MM::PageMap::GetPpeAddress(IN PVOID Address) } /** - * Gets the index of the PPE (Page Directory Pointer Table Entry), that maps given address. + * Gets the offset of the PPE (Page Directory Pointer Table Entry), that maps given address. * * @param Address * Specifies the virtual address for which to retrieve the corresponding PPE. @@ -112,7 +112,7 @@ MM::PageMap::GetPpeAddress(IN PVOID Address) */ XTAPI ULONG -MM::PageMap::GetPpeIndex(IN PVOID Address) +MM::PageMap::GetPpeOffset(IN PVOID Address) { /* Return zero */ return 0; @@ -158,20 +158,20 @@ MM::PageMap::GetPteAddress(IN PVOID Address) } /** - * Gets the index of the PTE (Page Table Entry), that maps given address. + * Gets the Offset of the PTE (Page Table Entry), that maps given address. * * @param Address * Specifies the virtual address for which to retrieve the corresponding PTE. * - * @return This routine returns the index of the PTE. + * @return This routine returns the Offset of the PTE. * * @since XT 1.0 */ XTAPI ULONG -MM::PageMap::GetPteIndex(IN PVOID Address) +MM::PageMap::GetPteOffset(IN PVOID Address) { - /* Return PTE index */ + /* Return PTE Offset */ return ((((ULONG_PTR)(Address)) >> MM_PTI_SHIFT) & (PageMapInfo.Xpa ? 0x1FF : 0x3FF)); }