From 54bd4f5cc8f0ca2dc6b16ebb24ca9c1378b70501 Mon Sep 17 00:00:00 2001 From: Timo Kreuzer Date: Wed, 8 Feb 2012 22:23:10 +0000 Subject: [PATCH] [NTOSKRNL] - Implement amd64 version of MmDeleteProcessPageDirectory - Fix amd64 build svn path=/trunk/; revision=55505 --- reactos/ntoskrnl/kd64/kddata.c | 1 + reactos/ntoskrnl/mm/ARM3/mminit.c | 3 +- reactos/ntoskrnl/mm/amd64/page.c | 112 ++++++++++++++++++++---------- 3 files changed, 77 insertions(+), 39 deletions(-) diff --git a/reactos/ntoskrnl/kd64/kddata.c b/reactos/ntoskrnl/kd64/kddata.c index 092efce3a63..d6b0107fcb9 100644 --- a/reactos/ntoskrnl/kd64/kddata.c +++ b/reactos/ntoskrnl/kd64/kddata.c @@ -12,6 +12,7 @@ #define NDEBUG #include #include "../mm/ARM3/miarm.h" +#undef MmSystemRangeStart VOID NTAPI RtlpBreakWithStatusInstruction(VOID); diff --git a/reactos/ntoskrnl/mm/ARM3/mminit.c b/reactos/ntoskrnl/mm/ARM3/mminit.c index 3d19b04e2dd..5554b9ebed7 100644 --- a/reactos/ntoskrnl/mm/ARM3/mminit.c +++ b/reactos/ntoskrnl/mm/ARM3/mminit.c @@ -14,6 +14,7 @@ #define MODULE_INVOLVED_IN_ARM3 #include "miarm.h" +#undef MmSystemRangeStart /* GLOBALS ********************************************************************/ @@ -170,7 +171,7 @@ PMMPDE MmSystemPagePtes; // // This should be 0xC0C00000 -- the cache itself starts at 0xC1000000 // -PMMWSL MmSystemCacheWorkingSetList = MI_SYSTEM_CACHE_WS_START; +PMMWSL MmSystemCacheWorkingSetList = (PVOID)MI_SYSTEM_CACHE_WS_START; // // Windows NT seems to choose between 7000, 11000 and 50000 diff --git a/reactos/ntoskrnl/mm/amd64/page.c b/reactos/ntoskrnl/mm/amd64/page.c index ea245533f06..de5dd773d14 100644 --- a/reactos/ntoskrnl/mm/amd64/page.c +++ b/reactos/ntoskrnl/mm/amd64/page.c @@ -137,6 +137,80 @@ MiFlushTlb(PMMPTE Pte, PVOID Address) } } +static +VOID +MmDeletePageTablePfn(PFN_NUMBER PageFrameNumber, ULONG Level) +{ + PMMPTE PageTable; + KIRQL OldIrql; + PMMPFN PfnEntry; + ULONG i, NumberEntries; + + /* Check if this is a page table */ + if (Level > 0) + { + NumberEntries = (Level == 4) ? MiAddressToPxi(MmHighestUserAddress)+1 : 512; + + /* Map the page table in hyperspace */ + PageTable = (PMMPTE)MmCreateHyperspaceMapping(PageFrameNumber); + + /* Loop all page table entries */ + for (i = 0; i < NumberEntries; i++) + { + /* Check if the entry is valid */ + if (PageTable[i].u.Hard.Valid) + { + /* Recursively free the page that backs it */ + MmDeletePageTablePfn(PageTable[i].u.Hard.PageFrameNumber, Level - 1); + } + } + + /* Delete the hyperspace mapping */ + MmDeleteHyperspaceMapping(PageTable); + } + + /* Check if this is a legacy allocation */ + PfnEntry = MiGetPfnEntry(PageFrameNumber); + if (MI_IS_ROS_PFN(PfnEntry)) + { + /* Free it using the legacy API */ + MmReleasePageMemoryConsumer(MC_SYSTEM, PageFrameNumber); + } + else + { + OldIrql = KeAcquireQueuedSpinLock(LockQueuePfnLock); + + /* Free it using the ARM3 API */ + MI_SET_PFN_DELETED(PfnEntry); + MiDecrementShareCount(PfnEntry, PageFrameNumber); + + KeReleaseQueuedSpinLock(LockQueuePfnLock, OldIrql); + } +} + +VOID +NTAPI +MmDeleteProcessPageDirectory(PEPROCESS Process) +{ + PFN_NUMBER TableBasePfn; + PMMPTE PageDir; + + /* Get the page directory PFN */ + TableBasePfn = Process->Pcb.DirectoryTableBase[0] >> PAGE_SHIFT; + + /* Map the page directory in hyperspace */ + PageDir = (PMMPTE)MmCreateHyperspaceMapping(TableBasePfn); + + /* Free the hyperspace mapping page (ARM3) */ + //MmDeletePageTablePfn(PageDir[ADDR_TO_PDE_OFFSET(HYPERSPACE)].u.Hard.PageFrameNumber, 3); + + /* Delete the hyperspace mapping */ + MmDeleteHyperspaceMapping(PageDir); + + /* Recursively free the page directories */ + MmDeletePageTablePfn(TableBasePfn, 4); +} + static PMMPTE MiGetPteForProcess( @@ -628,44 +702,6 @@ MmCreateVirtualMapping(PEPROCESS Process, return MmCreateVirtualMappingUnsafe(Process, Address, Protect, Pages, PageCount); } -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; -} - -VOID -NTAPI -MmGetPageFileMapping( - PEPROCESS Process, - PVOID Address, - SWAPENTRY* SwapEntry) -{ - ULONG64 Entry = MmGetPageEntryForProcess(Process, Address); - *SwapEntry = Entry >> 1; -} - BOOLEAN NTAPI MmCreateProcessAddressSpace(IN ULONG MinWs,