diff --git a/xtoskrnl/includes/mm/amd64/pagemap.hh b/xtoskrnl/includes/mm/amd64/pagemap.hh index d896eadd..c92a8ee0 100644 --- a/xtoskrnl/includes/mm/amd64/pagemap.hh +++ b/xtoskrnl/includes/mm/amd64/pagemap.hh @@ -44,6 +44,7 @@ namespace MM PMMPTE StartPte); XTAPI ULONG GetPteOffset(IN PVOID Address); XTAPI ULONG GetPteSize(VOID); + XTAPI ULONG GetPteSoftwareProtection(IN PMMPTE PtePointer); XTAPI ULONG GetPteSoftwarePrototype(IN PMMPTE PtePointer); XTAPI ULONG GetPteSoftwareTransition(IN PMMPTE PtePointer); VIRTUAL XTAPI PVOID GetPteVirtualAddress(IN PMMPTE PtePointer) = 0; @@ -65,6 +66,8 @@ namespace MM XTAPI VOID SetPteCaching(IN PMMPTE PtePointer, IN BOOLEAN CacheDisable, IN BOOLEAN WriteThrough); + XTAPI VOID TransitionPte(IN PMMPTE PointerPte, + IN ULONG_PTR Protection); XTAPI VOID WritePte(IN PMMPTE Pte, IN MMPTE Value); } PAGEMAP, *PPAGEMAP; diff --git a/xtoskrnl/includes/mm/amd64/paging.hh b/xtoskrnl/includes/mm/amd64/paging.hh index c8dc83aa..a15d64bf 100644 --- a/xtoskrnl/includes/mm/amd64/paging.hh +++ b/xtoskrnl/includes/mm/amd64/paging.hh @@ -41,6 +41,7 @@ namespace MM STATIC XTAPI LONG GetPteDistance(PMMPTE EndPte, PMMPTE StartPte); STATIC XTAPI ULONG GetPteSize(VOID); + STATIC XTAPI ULONG GetPteSoftwareProtection(IN PMMPTE PtePointer); STATIC XTAPI ULONG GetPteSoftwarePrototype(IN PMMPTE PtePointer); STATIC XTAPI ULONG GetPteSoftwareTransition(IN PMMPTE PtePointer); STATIC XTAPI PVOID GetPteVirtualAddress(IN PMMPTE PtePointer); @@ -63,6 +64,8 @@ namespace MM IN BOOLEAN WriteThrough); STATIC XTAPI VOID WritePte(IN PMMPTE Pte, IN MMPTE Value); + STATIC XTAPI VOID TransitionPte(IN PMMPTE PointerPte, + IN ULONG_PTR Protection); STATIC XTFASTCALL VOID ZeroPages(IN PVOID Address, IN ULONG Size); diff --git a/xtoskrnl/includes/mm/i686/pagemap.hh b/xtoskrnl/includes/mm/i686/pagemap.hh index 1da4aebc..6db0cb7c 100644 --- a/xtoskrnl/includes/mm/i686/pagemap.hh +++ b/xtoskrnl/includes/mm/i686/pagemap.hh @@ -41,6 +41,7 @@ namespace MM VIRTUAL XTAPI LONG GetPteDistance(PMMPTE EndPte, PMMPTE StartPte) = 0; VIRTUAL XTAPI ULONG GetPteSize(VOID) = 0; + VIRTUAL XTAPI ULONG GetPteSoftwareProtection(IN PMMPTE PtePointer) = 0; VIRTUAL XTAPI ULONG GetPteSoftwarePrototype(IN PMMPTE PtePointer) = 0; VIRTUAL XTAPI ULONG GetPteSoftwareTransition(IN PMMPTE PtePointer) = 0; VIRTUAL XTAPI PVOID GetPteVirtualAddress(IN PMMPTE PtePointer) = 0; @@ -59,6 +60,8 @@ namespace MM VIRTUAL XTAPI VOID SetPteCaching(IN PMMPTE PtePointer, IN BOOLEAN CacheDisable, IN BOOLEAN WriteThrough) = 0; + VIRTUAL XTAPI VOID TransitionPte(IN PMMPTE PointerPte, + IN ULONG_PTR Protection) = 0; VIRTUAL XTAPI VOID WritePte(IN PMMPTE Pte, IN MMPTE Value) = 0; @@ -79,6 +82,7 @@ namespace MM XTAPI LONG GetPteDistance(PMMPTE EndPte, PMMPTE StartPte); XTAPI ULONG GetPteSize(VOID); + XTAPI ULONG GetPteSoftwareProtection(IN PMMPTE PtePointer); XTAPI ULONG GetPteSoftwarePrototype(IN PMMPTE PtePointer); XTAPI ULONG GetPteSoftwareTransition(IN PMMPTE PtePointer); XTAPI PVOID GetPteVirtualAddress(IN PMMPTE PtePointer); @@ -96,6 +100,8 @@ namespace MM XTAPI VOID SetPteCaching(IN PMMPTE PtePointer, IN BOOLEAN CacheDisable, IN BOOLEAN WriteThrough); + XTAPI VOID TransitionPte(IN PMMPTE PointerPte, + IN ULONG_PTR Protection); XTAPI VOID WritePte(IN PMMPTE Pte, IN MMPTE Value); }; @@ -115,6 +121,7 @@ namespace MM XTAPI LONG GetPteDistance(PMMPTE EndPte, PMMPTE StartPte); XTAPI ULONG GetPteSize(VOID); + XTAPI ULONG GetPteSoftwareProtection(IN PMMPTE PtePointer); XTAPI ULONG GetPteSoftwarePrototype(IN PMMPTE PtePointer); XTAPI ULONG GetPteSoftwareTransition(IN PMMPTE PtePointer); XTAPI PVOID GetPteVirtualAddress(IN PMMPTE PtePointer); @@ -132,6 +139,8 @@ namespace MM XTAPI VOID SetPteCaching(IN PMMPTE PtePointer, IN BOOLEAN CacheDisable, IN BOOLEAN WriteThrough); + XTAPI VOID TransitionPte(IN PMMPTE PointerPte, + IN ULONG_PTR Protection); XTAPI VOID WritePte(IN PMMPTE Pte, IN MMPTE Value); }; diff --git a/xtoskrnl/includes/mm/i686/paging.hh b/xtoskrnl/includes/mm/i686/paging.hh index 69e8cedf..18c09647 100644 --- a/xtoskrnl/includes/mm/i686/paging.hh +++ b/xtoskrnl/includes/mm/i686/paging.hh @@ -39,6 +39,7 @@ namespace MM STATIC XTAPI LONG GetPteDistance(PMMPTE EndPte, PMMPTE StartPte); STATIC XTAPI ULONG GetPteSize(VOID); + STATIC XTAPI ULONG GetPteSoftwareProtection(IN PMMPTE PtePointer); STATIC XTAPI ULONG GetPteSoftwarePrototype(IN PMMPTE PtePointer); STATIC XTAPI ULONG GetPteSoftwareTransition(IN PMMPTE PtePointer); STATIC XTAPI PVOID GetPteVirtualAddress(IN PMMPTE PtePointer); @@ -59,6 +60,8 @@ namespace MM IN BOOLEAN WriteThrough); STATIC XTAPI VOID WritePte(IN PMMPTE Pte, IN MMPTE Value); + STATIC XTAPI VOID TransitionPte(IN PMMPTE PointerPte, + IN ULONG_PTR Protection); STATIC XTFASTCALL VOID ZeroPages(IN PVOID Address, IN ULONG Size); diff --git a/xtoskrnl/mm/amd64/pagemap.cc b/xtoskrnl/mm/amd64/pagemap.cc index 5342d7e7..313e176c 100644 --- a/xtoskrnl/mm/amd64/pagemap.cc +++ b/xtoskrnl/mm/amd64/pagemap.cc @@ -363,6 +363,24 @@ MM::PageMap::GetPteSize(VOID) return sizeof(MMPTE); } +/** + * Gets the software protection value of the corresponding Page Table Entry. + * + * @param PtePointer + * Specifies the address of the PTE. + * + * @return This routine returns the PTE software protection value. + * + * @since XT 1.0 + */ +XTAPI +ULONG +MM::PageMap::GetPteSoftwareProtection(IN PMMPTE PtePointer) +{ + /* Return PTE software protection value */ + return (ULONG)PtePointer->Software.Protection; +} + /** * Gets the software prototype value of the corresponding Page Table Entry. * @@ -377,6 +395,7 @@ XTAPI ULONG MM::PageMap::GetPteSoftwarePrototype(IN PMMPTE PtePointer) { + /* Return PTE software prototype value */ return (ULONG)PtePointer->Software.Prototype; } @@ -394,6 +413,7 @@ XTAPI ULONG MM::PageMap::GetPteSoftwareTransition(IN PMMPTE PtePointer) { + /* Return PTE software transition value */ return (ULONG)PtePointer->Software.Transition; } @@ -588,6 +608,37 @@ MM::PageMap::SetPteCaching(IN PMMPTE PtePointer, PtePointer->Hardware.WriteThrough = WriteThrough; } +/** + * Transitions a Page Table Entry (PTE) to invalid state + * + * @param PointerPte + * Pointer to the page table entry (PTE) to transition. + * + * @param Protection + * Specifies the protection attribute to apply to the PTE. + * + * @return This routine does not return any value. + * + * @since XT 1.0 + */ +XTAPI +VOID +MM::PageMap::TransitionPte(IN PMMPTE PointerPte, + IN ULONG_PTR Protection) +{ + MMPTE TempPte; + + /* Set transition PTE */ + TempPte = *PointerPte; + TempPte.Software.Protection = Protection; + TempPte.Software.Prototype = 0; + TempPte.Software.Transition = 1; + TempPte.Software.Valid = 0; + + /* Write PTE value */ + *PointerPte = TempPte; +} + /** * Writes a Page Table Entry (PTE) with the specified value. * diff --git a/xtoskrnl/mm/i686/pagemap.cc b/xtoskrnl/mm/i686/pagemap.cc index 2744f5c4..2473319a 100644 --- a/xtoskrnl/mm/i686/pagemap.cc +++ b/xtoskrnl/mm/i686/pagemap.cc @@ -355,6 +355,24 @@ MM::PageMapBasic::GetPteSize(VOID) return sizeof(MMPML2_PTE); } +/** + * Gets the software protection value of the corresponding Page Table Entry. + * + * @param PtePointer + * Specifies the address of the PTE. + * + * @return This routine returns the PTE software protection value. + * + * @since XT 1.0 + */ +XTAPI +ULONG +MM::PageMapBasic::GetPteSoftwareProtection(IN PMMPTE PtePointer) +{ + /* Return PTE software protection value */ + return (ULONG)PtePointer->Pml2.Software.Protection; +} + /** * Gets the software prototype value of the corresponding Page Table Entry. * @@ -369,6 +387,7 @@ XTAPI ULONG MM::PageMapBasic::GetPteSoftwarePrototype(IN PMMPTE PtePointer) { + /* Return PTE software prototype value */ return (ULONG)PtePointer->Pml2.Software.Prototype; } @@ -386,6 +405,7 @@ XTAPI ULONG MM::PageMapBasic::GetPteSoftwareTransition(IN PMMPTE PtePointer) { + /* Return PTE software transition value */ return (ULONG)PtePointer->Pml2.Software.Transition; } @@ -571,6 +591,37 @@ MM::PageMapBasic::SetPteCaching(IN PMMPTE PtePointer, PtePointer->Pml2.Hardware.WriteThrough = WriteThrough; } +/** + * Transitions a Page Table Entry (PTE) to invalid state + * + * @param PointerPte + * Pointer to the page table entry (PTE) to transition. + * + * @param Protection + * Specifies the protection attribute to apply to the PTE. + * + * @return This routine does not return any value. + * + * @since XT 1.0 + */ +XTAPI +VOID +MM::PageMapBasic::TransitionPte(IN PMMPTE PointerPte, + IN ULONG_PTR Protection) +{ + MMPTE TempPte; + + /* Set transition PTE */ + TempPte = *PointerPte; + TempPte.Pml2.Software.Protection = Protection; + TempPte.Pml2.Software.Prototype = 0; + TempPte.Pml2.Software.Transition = 1; + TempPte.Pml2.Software.Valid = 0; + + /* Write PTE value */ + *PointerPte = TempPte; +} + /** * Writes a PML2 page table entry (PTE) with the specified value. * @@ -777,6 +828,24 @@ MM::PageMapXpa::GetPteSize(VOID) return sizeof(MMPML3_PTE); } +/** + * Gets the software protection value of the corresponding Page Table Entry. + * + * @param PtePointer + * Specifies the address of the PTE. + * + * @return This routine returns the PTE software protection value. + * + * @since XT 1.0 + */ +XTAPI +ULONG +MM::PageMapXpa::GetPteSoftwareProtection(IN PMMPTE PtePointer) +{ + /* Return PTE software protection value */ + return (ULONG)PtePointer->Pml3.Software.Protection; +} + /** * Gets the software prototype value of the corresponding Page Table Entry. * @@ -791,6 +860,7 @@ XTAPI ULONG MM::PageMapXpa::GetPteSoftwarePrototype(IN PMMPTE PtePointer) { + /* Return PTE software prototype value */ return (ULONG)PtePointer->Pml3.Software.Prototype; } @@ -808,6 +878,7 @@ XTAPI ULONG MM::PageMapXpa::GetPteSoftwareTransition(IN PMMPTE PtePointer) { + /* Return PTE software transition value */ return (ULONG)PtePointer->Pml3.Software.Transition; } @@ -992,6 +1063,37 @@ MM::PageMapXpa::SetPteCaching(IN PMMPTE PtePointer, PtePointer->Pml3.Hardware.WriteThrough = WriteThrough; } +/** + * Transitions a Page Table Entry (PTE) to invalid state + * + * @param PointerPte + * Pointer to the page table entry (PTE) to transition. + * + * @param Protection + * Specifies the protection attribute to apply to the PTE. + * + * @return This routine does not return any value. + * + * @since XT 1.0 + */ +XTAPI +VOID +MM::PageMapXpa::TransitionPte(IN PMMPTE PointerPte, + IN ULONG_PTR Protection) +{ + MMPTE TempPte; + + /* Set transition PTE */ + TempPte = *PointerPte; + TempPte.Pml3.Software.Protection = Protection; + TempPte.Pml3.Software.Prototype = 0; + TempPte.Pml3.Software.Transition = 1; + TempPte.Pml3.Software.Valid = 0; + + /* Write PTE value */ + *PointerPte = TempPte; +} + /** * Writes a PML3 page table entry (PTE) with the specified value. * diff --git a/xtoskrnl/mm/paging.cc b/xtoskrnl/mm/paging.cc index 71969519..34cde8e2 100644 --- a/xtoskrnl/mm/paging.cc +++ b/xtoskrnl/mm/paging.cc @@ -366,6 +366,24 @@ MM::Paging::GetPteSize(VOID) return PmlRoutines->GetPteSize(); } +/** + * Gets the software protection value of the corresponding Page Table Entry. + * + * @param PtePointer + * Specifies the address of the PTE. + * + * @return This routine returns the PTE software protection value. + * + * @since XT 1.0 + */ +XTAPI +ULONG +MM::Paging::GetPteSoftwareProtection(IN PMMPTE PtePointer) +{ + /* Return PTE software protection value */ + return PmlRoutines->GetPteSoftwareProtection(PtePointer); +} + /** * Gets the software prototype value of the corresponding Page Table Entry. * @@ -380,6 +398,7 @@ XTAPI ULONG MM::Paging::GetPteSoftwarePrototype(IN PMMPTE PtePointer) { + /* Return PTE software prototype value */ return PmlRoutines->GetPteSoftwarePrototype(PtePointer); } @@ -397,6 +416,7 @@ XTAPI ULONG MM::Paging::GetPteSoftwareTransition(IN PMMPTE PtePointer) { + /* Return PTE software transition value */ return PmlRoutines->GetPteSoftwareTransition(PtePointer); } @@ -594,6 +614,28 @@ MM::Paging::SetPteCaching(IN PMMPTE PtePointer, PmlRoutines->SetPteCaching(PtePointer, CacheDisable, WriteThrough); } +/** + * Transitions a Page Table Entry (PTE) to invalid state + * + * @param PointerPte + * Pointer to the page table entry (PTE) to transition. + * + * @param Protection + * Specifies the protection attribute to apply to the PTE. + * + * @return This routine does not return any value. + * + * @since XT 1.0 + */ +XTAPI +VOID +MM::Paging::TransitionPte(IN PMMPTE PointerPte, + IN ULONG_PTR Protection) +{ + /* Transition PTE */ + PmlRoutines->TransitionPte(PointerPte, Protection); +} + /** * Writes a Page Table Entry (PTE) with the specified value. *