https://git.reactos.org/?p=reactos.git;a=commitdiff;h=8980850d565c226ec064e…
commit 8980850d565c226ec064e6ee0613ebeace8c6b51
Author: Timo Kreuzer <timo.kreuzer(a)reactos.org>
AuthorDate: Sun Feb 4 13:33:14 2018 +0100
Commit: Timo Kreuzer <timo.kreuzer(a)reactos.org>
CommitDate: Sun Nov 1 09:32:27 2020 +0100
[NTOS:MM:X64] Simplify and fix x64 mapping code
- Use demand-zero-ptes in MiGetPteForProcess
- Handle NoExecute in MiSetPteProtection
- Fix MmIsPageSwapEntry
- Fix MmGetPageFileMapping
- remove obsolete functions.
---
ntoskrnl/mm/amd64/page.c | 121 +++++++++++++++++------------------------------
1 file changed, 44 insertions(+), 77 deletions(-)
diff --git a/ntoskrnl/mm/amd64/page.c b/ntoskrnl/mm/amd64/page.c
index afae9827191..0559de76b88 100644
--- a/ntoskrnl/mm/amd64/page.c
+++ b/ntoskrnl/mm/amd64/page.c
@@ -144,75 +144,65 @@ MiGetPteForProcess(
PVOID Address,
BOOLEAN Create)
{
- MMPTE TmplPte, *Pte;
+ PMMPTE Pte;
+ PMMPDE Pde;
+ PMMPPE Ppe;
+ PMMPXE Pxe;
- /* Check if we need hypersapce mapping */
- if (Address < MmSystemRangeStart &&
- Process && Process != PsGetCurrentProcess())
+ /* Make sure the process is correct */
+ if (Address < MmSystemRangeStart)
{
- UNIMPLEMENTED;
- __debugbreak();
- return NULL;
+ ASSERT(Process == PsGetCurrentProcess());
}
- else if (Create)
+ else
{
- KIRQL OldIrql;
- TmplPte.u.Long = 0;
- TmplPte.u.Flush.Valid = 1;
- TmplPte.u.Flush.Write = 1;
-
- /* All page table levels of user pages are user owned */
- TmplPte.u.Flush.Owner = (Address < MmHighestUserAddress) ? 1 : 0;
+ ASSERT((Process == NULL) || (Process == PsGetCurrentProcess()));
+ }
- /* Lock the PFN database */
- OldIrql = MiAcquirePfnLock();
+ Pxe = MiAddressToPxe(Address);
+ Ppe = MiAddressToPpe(Address);
+ Pde = MiAddressToPde(Address);
+ Pte = MiAddressToPte(Address);
- /* Get the PXE */
- Pte = MiAddressToPxe(Address);
- if (!Pte->u.Hard.Valid)
+ if (Create)
+ {
+ /* Check the PXE */
+ if (Pxe->u.Long == 0)
{
- TmplPte.u.Hard.PageFrameNumber = MiRemoveZeroPage(0);
- MI_WRITE_VALID_PTE(Pte, TmplPte);
+ /* Make it demand zero */
+ MI_WRITE_INVALID_PDE(Pxe, DemandZeroPde);
}
- /* Get the PPE */
- Pte = MiAddressToPpe(Address);
- if (!Pte->u.Hard.Valid)
+ /* Check the PPE */
+ if (Ppe->u.Long == 0)
{
- TmplPte.u.Hard.PageFrameNumber = MiRemoveZeroPage(1);
- MI_WRITE_VALID_PTE(Pte, TmplPte);
+ /* Make it demand zero */
+ MI_WRITE_INVALID_PDE(Ppe, DemandZeroPde);
}
- /* Get the PDE */
- Pte = MiAddressToPde(Address);
- if (!Pte->u.Hard.Valid)
+ /* Check the PDE */
+ if (Pde->u.Long == 0)
{
- TmplPte.u.Hard.PageFrameNumber = MiRemoveZeroPage(2);
- MI_WRITE_VALID_PTE(Pte, TmplPte);
+ /* Make it demand zero */
+ MI_WRITE_INVALID_PDE(Pde, DemandZeroPde);
}
-
- /* Unlock PFN database */
- MiReleasePfnLock(OldIrql);
}
else
{
- /* Get the PXE */
- Pte = MiAddressToPxe(Address);
- if (!Pte->u.Hard.Valid)
+ /* Check the PXE */
+ if (!Pxe->u.Hard.Valid)
return NULL;
- /* Get the PPE */
- Pte = MiAddressToPpe(Address);
- if (!Pte->u.Hard.Valid)
+ /* Check the PPE */
+ if (!Ppe->u.Hard.Valid)
return NULL;
- /* Get the PDE */
- Pte = MiAddressToPde(Address);
- if (!Pte->u.Hard.Valid)
+ /* Check the PDE */
+ if (!Pde->u.Hard.Valid)
return NULL;
}
- return MiAddressToPte(Address);
+ return Pte;
}
static
@@ -272,8 +262,8 @@ MiGetPteProtection(MMPTE Pte)
return Protect;
}
+static
VOID
-NTAPI
MiSetPteProtection(PMMPTE Pte, ULONG Protection)
{
Pte->u.Flush.CopyOnWrite = (Protection & PAGE_WRITECOPY_ANY) ? 1 : 0;
@@ -282,7 +272,7 @@ MiSetPteProtection(PMMPTE Pte, ULONG Protection)
Pte->u.Flush.WriteThrough = (Protection & PAGE_WRITETHROUGH) ? 1 : 0;
// FIXME: This doesn't work. Why?
-// Pte->u.Flush.NoExecute = (Protection & PAGE_EXECUTE_ANY) ? 0 : 1;
+ Pte->u.Flush.NoExecute = (Protection & PAGE_EXECUTE_ANY) ? 0 : 1;
}
/* FUNCTIONS ***************************************************************/
@@ -324,34 +314,7 @@ MmIsPageSwapEntry(PEPROCESS Process, PVOID Address)
{
MMPTE Pte;
Pte.u.Long = MiGetPteValueForProcess(Process, Address);
- return Pte.u.Hard.Valid && Pte.u.Soft.Transition;
-}
-
-static PMMPTE
-MmGetPageTableForProcess(PEPROCESS Process, PVOID Address, BOOLEAN Create)
-{
- __debugbreak();
- return 0;
-}
-
-BOOLEAN MmUnmapPageTable(PMMPTE Pt)
-{
- ASSERT(FALSE);
- return 0;
-}
-
-static ULONG64 MmGetPageEntryForProcess(PEPROCESS Process, PVOID Address)
-{
- MMPTE Pte, *PointerPte;
-
- PointerPte = MmGetPageTableForProcess(Process, Address, FALSE);
- if (PointerPte)
- {
- Pte = *PointerPte;
- MmUnmapPageTable(PointerPte);
- return Pte.u.Long;
- }
- return 0;
+ return !Pte.u.Hard.Valid && Pte.u.Soft.Transition;
}
VOID
@@ -361,8 +324,12 @@ MmGetPageFileMapping(
PVOID Address,
SWAPENTRY* SwapEntry)
{
- ULONG64 Entry = MmGetPageEntryForProcess(Process, Address);
- *SwapEntry = Entry >> 1;
+ PMMPTE PointerPte;
+
+ ASSERT(Process == PsGetCurrentProcess());
+
+ PointerPte = MiAddressToPte(Address);
+ *SwapEntry = PointerPte->u.Long >> 1;
}
BOOLEAN