diff --git a/ntoskrnl/mm/ARM3/mdlsup.c b/ntoskrnl/mm/ARM3/mdlsup.c index 9332ec3153..10a2aa02f6 100644 --- a/ntoskrnl/mm/ARM3/mdlsup.c +++ b/ntoskrnl/mm/ARM3/mdlsup.c @@ -248,7 +248,6 @@ MiMapLockedPagesInUserSpace( /* Acquire a share count */ Pfn1 = MI_PFN_ELEMENT(PointerPde->u.Hard.PageFrameNumber); - DPRINT("Incrementing %p from %p\n", Pfn1, _ReturnAddress()); OldIrql = MiAcquirePfnLock(); Pfn1->u2.ShareCount++; MiReleasePfnLock(OldIrql); @@ -331,6 +330,9 @@ MiUnmapLockedPagesInUserSpace( ASSERT(MiAddressToPte(PointerPte)->u.Hard.Valid == 1); ASSERT(PointerPte->u.Hard.Valid == 1); + /* Dereference the page */ + MiDecrementPageTableReferences(BaseAddress); + /* Invalidate it */ MI_ERASE_PTE(PointerPte); @@ -339,17 +341,28 @@ MiUnmapLockedPagesInUserSpace( PageTablePage = PointerPde->u.Hard.PageFrameNumber; MiDecrementShareCount(MiGetPfnEntry(PageTablePage), PageTablePage); - if (MiDecrementPageTableReferences(BaseAddress) == 0) - { - ASSERT(MiIsPteOnPdeBoundary(PointerPte + 1) || (NumberOfPages == 1)); - MiDeletePde(PointerPde, Process); - } - /* Next page */ PointerPte++; NumberOfPages--; BaseAddress = (PVOID)((ULONG_PTR)BaseAddress + PAGE_SIZE); MdlPages++; + + /* Moving to a new PDE? */ + if (PointerPde != MiAddressToPde(BaseAddress)) + { + /* See if we should delete it */ + KeFlushProcessTb(); + PointerPde = MiPteToPde(PointerPte - 1); + ASSERT(PointerPde->u.Hard.Valid == 1); + if (MiQueryPageTableReferences(BaseAddress) == 0) + { + ASSERT(PointerPde->u.Long != 0); + MiDeletePte(PointerPde, + MiPteToAddress(PointerPde), + Process, + NULL); + } + } } KeFlushProcessTb(); diff --git a/ntoskrnl/mm/ARM3/miarm.h b/ntoskrnl/mm/ARM3/miarm.h index 6d2f2753bb..da42ba468a 100644 --- a/ntoskrnl/mm/ARM3/miarm.h +++ b/ntoskrnl/mm/ARM3/miarm.h @@ -230,6 +230,11 @@ extern const ULONG MmProtectToValue[32]; #error Define these please! #endif +// +// Special IRQL value (found in assertions) +// +// #define MM_NOIRQL (KIRQL)0xFFFFFFFF + // // Returns the color of a page // @@ -1818,7 +1823,40 @@ MiReferenceUnusedPageAndBumpLockCount(IN PMMPFN Pfn1) } } +FORCEINLINE +VOID +MiIncrementPageTableReferences(IN PVOID Address) +{ + PUSHORT RefCount; + + RefCount = &MmWorkingSetList->UsedPageTableEntries[MiGetPdeOffset(Address)]; + + *RefCount += 1; + ASSERT(*RefCount <= PTE_PER_PAGE); +} + +FORCEINLINE +VOID +MiDecrementPageTableReferences(IN PVOID Address) +{ + PUSHORT RefCount; + + RefCount = &MmWorkingSetList->UsedPageTableEntries[MiGetPdeOffset(Address)]; + + *RefCount -= 1; + ASSERT(*RefCount < PTE_PER_PAGE); +} + +FORCEINLINE +USHORT +MiQueryPageTableReferences(IN PVOID Address) +{ + PUSHORT RefCount; + RefCount = &MmWorkingSetList->UsedPageTableEntries[MiGetPdeOffset(Address)]; + + return *RefCount; +} CODE_SEG("INIT") BOOLEAN @@ -2446,117 +2484,8 @@ MiSynchronizeSystemPde(PMMPDE PointerPde) } #endif -#if _MI_PAGING_LEVELS == 2 -FORCEINLINE -USHORT -MiIncrementPageTableReferences(IN PVOID Address) -{ - PUSHORT RefCount; - - RefCount = &MmWorkingSetList->UsedPageTableEntries[MiGetPdeOffset(Address)]; - - *RefCount += 1; - ASSERT(*RefCount <= PTE_PER_PAGE); - return *RefCount; -} - -FORCEINLINE -USHORT -MiDecrementPageTableReferences(IN PVOID Address) -{ - PUSHORT RefCount; - - RefCount = &MmWorkingSetList->UsedPageTableEntries[MiGetPdeOffset(Address)]; - - *RefCount -= 1; - ASSERT(*RefCount < PTE_PER_PAGE); - return *RefCount; -} -#else -FORCEINLINE -USHORT -MiIncrementPageTableReferences(IN PVOID Address) -{ - PMMPDE PointerPde = MiAddressToPde(Address); - PMMPFN Pfn; - - /* We should not tinker with this one. */ - ASSERT(PointerPde != (PMMPDE)PXE_SELFMAP); - DPRINT("Incrementing %p from %p\n", Address, _ReturnAddress()); - - /* Make sure we're locked */ - ASSERT(PsGetCurrentThread()->OwnsProcessWorkingSetExclusive); - - /* If we're bumping refcount, then it must be valid! */ - ASSERT(PointerPde->u.Hard.Valid == 1); - - /* This lies on the PFN */ - Pfn = MiGetPfnEntry(PFN_FROM_PDE(PointerPde)); - Pfn->OriginalPte.u.Soft.UsedPageTableEntries++; - - ASSERT(Pfn->OriginalPte.u.Soft.UsedPageTableEntries <= PTE_PER_PAGE); - - return Pfn->OriginalPte.u.Soft.UsedPageTableEntries; -} - -FORCEINLINE -USHORT -MiDecrementPageTableReferences(IN PVOID Address) -{ - PMMPDE PointerPde = MiAddressToPde(Address); - PMMPFN Pfn; - - /* We should not tinker with this one. */ - ASSERT(PointerPde != (PMMPDE)PXE_SELFMAP); - - DPRINT("Decrementing %p from %p\n", PointerPde, _ReturnAddress()); - - /* Make sure we're locked */ - ASSERT(PsGetCurrentThread()->OwnsProcessWorkingSetExclusive); - - /* If we're decreasing refcount, then it must be valid! */ - ASSERT(PointerPde->u.Hard.Valid == 1); - - /* This lies on the PFN */ - Pfn = MiGetPfnEntry(PFN_FROM_PDE(PointerPde)); - - ASSERT(Pfn->OriginalPte.u.Soft.UsedPageTableEntries != 0); - Pfn->OriginalPte.u.Soft.UsedPageTableEntries--; - - ASSERT(Pfn->OriginalPte.u.Soft.UsedPageTableEntries < PTE_PER_PAGE); - - return Pfn->OriginalPte.u.Soft.UsedPageTableEntries; -} -#endif - #ifdef __cplusplus } // extern "C" #endif -FORCEINLINE -VOID -MiDeletePde( - _In_ PMMPDE PointerPde, - _In_ PEPROCESS CurrentProcess) -{ - /* Only for user-mode ones */ - ASSERT(MiIsUserPde(PointerPde)); - - /* Kill this one as a PTE */ - MiDeletePte((PMMPTE)PointerPde, MiPdeToPte(PointerPde), CurrentProcess, NULL); -#if _MI_PAGING_LEVELS >= 3 - /* Cascade down */ - if (MiDecrementPageTableReferences(MiPdeToPte(PointerPde)) == 0) - { - MiDeletePte(MiPdeToPpe(PointerPde), PointerPde, CurrentProcess, NULL); -#if _MI_PAGING_LEVELS == 4 - if (MiDecrementPageTableReferences(PointerPde) == 0) - { - MiDeletePte(MiPdeToPxe(PointerPde), MiPdeToPpe(PointerPde), CurrentProcess, NULL); - } -#endif - } -#endif -} - /* EOF */ diff --git a/ntoskrnl/mm/ARM3/pagfault.c b/ntoskrnl/mm/ARM3/pagfault.c index 8d1ce33c39..87c789c174 100644 --- a/ntoskrnl/mm/ARM3/pagfault.c +++ b/ntoskrnl/mm/ARM3/pagfault.c @@ -1286,14 +1286,6 @@ MiResolveProtoPteFault(IN BOOLEAN StoreInstruction, (ULONG)TempPte.u.Soft.Protection, Process, OldIrql); -#if MI_TRACE_PFNS - /* Update debug info */ - if (TrapInformation) - MiGetPfnEntry(PointerProtoPte->u.Hard.PageFrameNumber)->CallSite = (PVOID)((PKTRAP_FRAME)TrapInformation)->Eip; - else - MiGetPfnEntry(PointerProtoPte->u.Hard.PageFrameNumber)->CallSite = _ReturnAddress(); -#endif - ASSERT(NT_SUCCESS(Status)); } @@ -1645,14 +1637,6 @@ MiDispatchFault(IN ULONG FaultCode, ASSERT(KeAreAllApcsDisabled() == TRUE); if (NT_SUCCESS(Status)) { -#if MI_TRACE_PFNS - /* Update debug info */ - if (TrapInformation) - MiGetPfnEntry(PointerPte->u.Hard.PageFrameNumber)->CallSite = (PVOID)((PKTRAP_FRAME)TrapInformation)->Eip; - else - MiGetPfnEntry(PointerPte->u.Hard.PageFrameNumber)->CallSite = _ReturnAddress(); -#endif - // // Make sure we're returning in a sane state and pass the status down // @@ -2161,7 +2145,6 @@ UserFault: /* We should come back with a valid PPE */ ASSERT(PointerPpe->u.Hard.Valid == 1); - MiIncrementPageTableReferences(PointerPde); } #endif @@ -2201,17 +2184,8 @@ UserFault: MM_EXECUTE_READWRITE, CurrentProcess, MM_NOIRQL); -#if _MI_PAGING_LEVELS >= 3 - MiIncrementPageTableReferences(PointerPte); -#endif - #if MI_TRACE_PFNS UserPdeFault = FALSE; - /* Update debug info */ - if (TrapInformation) - MiGetPfnEntry(PointerPde->u.Hard.PageFrameNumber)->CallSite = (PVOID)((PKTRAP_FRAME)TrapInformation)->Eip; - else - MiGetPfnEntry(PointerPde->u.Hard.PageFrameNumber)->CallSite = _ReturnAddress(); #endif /* We should come back with APCs enabled, and with a valid PDE */ ASSERT(KeAreAllApcsDisabled() == TRUE); @@ -2307,14 +2281,6 @@ UserFault: CurrentProcess, MM_NOIRQL); -#if MI_TRACE_PFNS - /* Update debug info */ - if (TrapInformation) - MiGetPfnEntry(PointerPte->u.Hard.PageFrameNumber)->CallSite = (PVOID)((PKTRAP_FRAME)TrapInformation)->Eip; - else - MiGetPfnEntry(PointerPte->u.Hard.PageFrameNumber)->CallSite = _ReturnAddress(); -#endif - /* Return the status */ MiUnlockProcessWorkingSet(CurrentProcess, CurrentThread); return STATUS_PAGE_FAULT_DEMAND_ZERO; @@ -2343,14 +2309,7 @@ UserFault: * Check if this is a real user-mode address or actually a kernel-mode * page table for a user mode address */ - if (Address <= MM_HIGHEST_USER_ADDRESS -#if _MI_PAGING_LEVELS >= 3 - || MiIsUserPte(Address) -#if _MI_PAGING_LEVELS == 4 - || MiIsUserPde(Address) -#endif -#endif - ) + if (Address <= MM_HIGHEST_USER_ADDRESS) { /* Add an additional page table reference */ MiIncrementPageTableReferences(Address); diff --git a/ntoskrnl/mm/ARM3/pfnlist.c b/ntoskrnl/mm/ARM3/pfnlist.c index bbf4275a9d..b9838f2960 100644 --- a/ntoskrnl/mm/ARM3/pfnlist.c +++ b/ntoskrnl/mm/ARM3/pfnlist.c @@ -254,7 +254,6 @@ MiUnlinkFreeOrZeroedPage(IN PMMPFN Entry) ASSERT(MI_PFN_CURRENT_USAGE != MI_USAGE_NOT_SET); Entry->PfnUsage = MI_PFN_CURRENT_USAGE; memcpy(Entry->ProcessName, MI_PFN_CURRENT_PROCESS_NAME, 16); - Entry->CallSite = _ReturnAddress(); MI_PFN_CURRENT_USAGE = MI_USAGE_NOT_SET; MI_SET_PROCESS2("Not Set"); #endif @@ -463,7 +462,6 @@ MiRemovePageByColor(IN PFN_NUMBER PageIndex, ASSERT(MI_PFN_CURRENT_USAGE != MI_USAGE_NOT_SET); Pfn1->PfnUsage = MI_PFN_CURRENT_USAGE; memcpy(Pfn1->ProcessName, MI_PFN_CURRENT_PROCESS_NAME, 16); - Pfn1->CallSite = _ReturnAddress(); MI_PFN_CURRENT_USAGE = MI_USAGE_NOT_SET; MI_SET_PROCESS2("Not Set"); #endif @@ -712,7 +710,6 @@ MiInsertPageInFreeList(IN PFN_NUMBER PageFrameIndex) #if MI_TRACE_PFNS Pfn1->PfnUsage = MI_USAGE_FREE_PAGE; RtlZeroMemory(Pfn1->ProcessName, 16); - Pfn1->CallSite = NULL; #endif } @@ -943,7 +940,6 @@ MiInsertPageInList(IN PMMPFNLIST ListHead, ASSERT(MI_PFN_CURRENT_USAGE == MI_USAGE_NOT_SET); Pfn1->PfnUsage = MI_USAGE_FREE_PAGE; RtlZeroMemory(Pfn1->ProcessName, 16); - Pfn1->CallSite = NULL; #endif } else if (ListName == ModifiedPageList) @@ -1031,8 +1027,6 @@ MiInitializePfn(IN PFN_NUMBER PageFrameIndex, ASSERT(PageFrameIndex != 0); Pfn1->u4.PteFrame = PageFrameIndex; - DPRINT("Incrementing share count of %lp from %p\n", PageFrameIndex, _ReturnAddress()); - /* Increase its share count so we don't get rid of it */ Pfn1 = MI_PFN_ELEMENT(PageFrameIndex); Pfn1->u2.ShareCount++; diff --git a/ntoskrnl/mm/ARM3/session.c b/ntoskrnl/mm/ARM3/session.c index 70ae1ec988..cb4de5f9b5 100644 --- a/ntoskrnl/mm/ARM3/session.c +++ b/ntoskrnl/mm/ARM3/session.c @@ -477,7 +477,7 @@ MiSessionInitializeWorkingSetList(VOID) /* Fill out the two pointers */ MmSessionSpace->Vm.VmWorkingSetList = WorkingSetList; - MmSessionSpace->Wsle = (PMMWSLE)((&WorkingSetList->VadBitMapHint) + 1); + MmSessionSpace->Wsle = (PMMWSLE)WorkingSetList->UsedPageTableEntries; /* Get the PDE for the working set, and check if it's already allocated */ PointerPde = MiAddressToPde(WorkingSetList); diff --git a/ntoskrnl/mm/ARM3/virtual.c b/ntoskrnl/mm/ARM3/virtual.c index 9cb0cacf23..311ab07857 100644 --- a/ntoskrnl/mm/ARM3/virtual.c +++ b/ntoskrnl/mm/ARM3/virtual.c @@ -659,13 +659,12 @@ MiDeleteVirtualAddresses(IN ULONG_PTR Va, PointerPte = MiAddressToPte(Va); do { - /* Making sure the PDE is still valid */ - ASSERT(PointerPde->u.Hard.Valid == 1); - /* Capture the PDE and make sure it exists */ TempPte = *PointerPte; if (TempPte.u.Long) { + MiDecrementPageTableReferences((PVOID)Va); + /* Check if the PTE is actually mapped in */ if (MI_IS_MAPPED_PTE(&TempPte)) { @@ -710,30 +709,40 @@ MiDeleteVirtualAddresses(IN ULONG_PTR Va, /* The PTE was never mapped, just nuke it here */ MI_ERASE_PTE(PointerPte); } - - if (MiDecrementPageTableReferences((PVOID)Va) == 0) - { - ASSERT(PointerPde->u.Long != 0); - /* Delete the PDE proper */ - MiDeletePde(PointerPde, CurrentProcess); - /* Jump */ - Va = (ULONG_PTR)MiPdeToAddress(PointerPde + 1); - break; - } } /* Update the address and PTE for it */ Va += PAGE_SIZE; PointerPte++; PrototypePte++; - } while ((Va & (PDE_MAPPED_VA - 1)) && (Va <= EndingAddress)); - /* Release the lock */ - MiReleasePfnLock(OldIrql); + /* Making sure the PDE is still valid */ + ASSERT(PointerPde->u.Hard.Valid == 1); + } + while ((Va & (PDE_MAPPED_VA - 1)) && (Va <= EndingAddress)); + + /* The PDE should still be valid at this point */ + ASSERT(PointerPde->u.Hard.Valid == 1); + + /* Check remaining PTE count (go back 1 page due to above loop) */ + if (MiQueryPageTableReferences((PVOID)(Va - PAGE_SIZE)) == 0) + { + if (PointerPde->u.Long != 0) + { + /* Delete the PTE proper */ + MiDeletePte(PointerPde, + MiPteToAddress(PointerPde), + CurrentProcess, + NULL); + } + } + /* Release the lock and get out if we're done */ + MiReleasePfnLock(OldIrql); if (Va > EndingAddress) return; /* Otherwise, we exited because we hit a new PDE boundary, so start over */ + PointerPde = MiAddressToPde(Va); AddressGap = FALSE; } } @@ -2412,7 +2421,7 @@ MiProtectVirtualMemory(IN PEPROCESS Process, MI_WRITE_INVALID_PTE(PointerPte, PteContents); #ifdef CONFIG_SMP // FIXME: Should invalidate entry in every CPU TLB - ASSERT(KeNumberProcessors == 1); + ASSERT(FALSE); #endif KeInvalidateTlbEntry(MiPteToAddress(PointerPte)); @@ -2471,13 +2480,7 @@ MiMakePdeExistAndMakeValid(IN PMMPDE PointerPde, IN PEPROCESS TargetProcess, IN KIRQL OldIrql) { - PMMPTE PointerPte; -#if _MI_PAGING_LEVELS >= 3 - PMMPPE PointerPpe = MiPdeToPpe(PointerPde); -#if _MI_PAGING_LEVELS == 4 - PMMPXE PointerPxe = MiPdeToPxe(PointerPde); -#endif -#endif + PMMPTE PointerPte, PointerPpe, PointerPxe; // // Sanity checks. The latter is because we only use this function with the @@ -2486,16 +2489,16 @@ MiMakePdeExistAndMakeValid(IN PMMPDE PointerPde, ASSERT(KeAreAllApcsDisabled() == TRUE); ASSERT(OldIrql == MM_NOIRQL); + // + // Also get the PPE and PXE. This is okay not to #ifdef because they will + // return the same address as the PDE on 2-level page table systems. // // If everything is already valid, there is nothing to do. // - if ( -#if _MI_PAGING_LEVELS == 4 - (PointerPxe->u.Hard.Valid) && -#endif -#if _MI_PAGING_LEVELS >= 3 + PointerPpe = MiAddressToPte(PointerPde); + PointerPxe = MiAddressToPde(PointerPde); + if ((PointerPxe->u.Hard.Valid) && (PointerPpe->u.Hard.Valid) && -#endif (PointerPde->u.Hard.Valid)) { return; @@ -2515,7 +2518,6 @@ MiMakePdeExistAndMakeValid(IN PMMPDE PointerPde, // ASSERT(KeAreAllApcsDisabled() == TRUE); -#if _MI_PAGING_LEVELS == 4 // // First, make the PXE valid if needed // @@ -2524,9 +2526,7 @@ MiMakePdeExistAndMakeValid(IN PMMPDE PointerPde, MiMakeSystemAddressValid(PointerPpe, TargetProcess); ASSERT(PointerPxe->u.Hard.Valid == 1); } -#endif -#if _MI_PAGING_LEVELS >= 3 // // Next, the PPE // @@ -2535,28 +2535,22 @@ MiMakePdeExistAndMakeValid(IN PMMPDE PointerPde, MiMakeSystemAddressValid(PointerPde, TargetProcess); ASSERT(PointerPpe->u.Hard.Valid == 1); } -#endif // // And finally, make the PDE itself valid. // MiMakeSystemAddressValid(PointerPte, TargetProcess); - /* Do not increment Page table refcount here for the PDE, this must be managed by caller */ - // // This should've worked the first time so the loop is really just for // show -- ASSERT that we're actually NOT going to be looping. // + ASSERT(PointerPxe->u.Hard.Valid == 1); + ASSERT(PointerPpe->u.Hard.Valid == 1); ASSERT(PointerPde->u.Hard.Valid == 1); - } while ( -#if _MI_PAGING_LEVELS == 4 - !PointerPxe->u.Hard.Valid || -#endif -#if _MI_PAGING_LEVELS >= 3 - !PointerPpe->u.Hard.Valid || -#endif - !PointerPde->u.Hard.Valid); + } while (!(PointerPxe->u.Hard.Valid) || + !(PointerPpe->u.Hard.Valid) || + !(PointerPde->u.Hard.Valid)); } VOID @@ -5675,3 +5669,4 @@ MmGetPhysicalAddress(PVOID Address) /* EOF */ + \ No newline at end of file diff --git a/ntoskrnl/mm/i386/page.c b/ntoskrnl/mm/i386/page.c index cf2e012389..d15a9f7496 100644 --- a/ntoskrnl/mm/i386/page.c +++ b/ntoskrnl/mm/i386/page.c @@ -114,75 +114,6 @@ NTAPI MiFillSystemPageDirectory(IN PVOID Base, IN SIZE_T NumberOfBytes); -static -BOOLEAN -MiIsPageTablePresent(PVOID Address) -{ -#if _MI_PAGING_LEVELS == 2 - return MmWorkingSetList->UsedPageTableEntries[MiGetPdeOffset(Address)] != 0; -#else - PMMPDE PointerPde; - PMMPPE PointerPpe; -#if _MI_PAGING_LEVELS == 4 - PMMPXE PointerPxe; -#endif - PMMPFN Pfn; - - /* Make sure we're locked */ - ASSERT((PsGetCurrentThread()->OwnsProcessWorkingSetExclusive) || (PsGetCurrentThread()->OwnsProcessWorkingSetShared)); - - /* Must not hold the PFN lock! */ - ASSERT(KeGetCurrentIrql() < DISPATCH_LEVEL); - - /* Check if PXE or PPE have references first. */ -#if _MI_PAGING_LEVELS == 4 - PointerPxe = MiAddressToPxe(Address); - if ((PointerPxe->u.Hard.Valid == 1) || (PointerPxe->u.Soft.Transition == 1)) - { - Pfn = MiGetPfnEntry(PFN_FROM_PXE(PointerPxe)); - if (Pfn->OriginalPte.u.Soft.UsedPageTableEntries == 0) - return FALSE; - } - else if (PointerPxe->u.Soft.UsedPageTableEntries == 0) - { - return FALSE; - } - - if (PointerPxe->u.Hard.Valid == 0) - { - MiMakeSystemAddressValid(MiPteToAddress(PointerPxe), PsGetCurrentProcess()); - } -#endif - - PointerPpe = MiAddressToPpe(Address); - if ((PointerPpe->u.Hard.Valid == 1) || (PointerPpe->u.Soft.Transition == 1)) - { - Pfn = MiGetPfnEntry(PFN_FROM_PPE(PointerPpe)); - if (Pfn->OriginalPte.u.Soft.UsedPageTableEntries == 0) - return FALSE; - } - else if (PointerPpe->u.Soft.UsedPageTableEntries == 0) - { - return FALSE; - } - - if (PointerPpe->u.Hard.Valid == 0) - { - MiMakeSystemAddressValid(MiPteToAddress(PointerPpe), PsGetCurrentProcess()); - } - - PointerPde = MiAddressToPde(Address); - if ((PointerPde->u.Hard.Valid == 0) && (PointerPde->u.Soft.Transition == 0)) - { - return PointerPde->u.Soft.UsedPageTableEntries != 0; - } - - /* This lies on the PFN */ - Pfn = MiGetPfnEntry(PFN_FROM_PDE(PointerPde)); - return Pfn->OriginalPte.u.Soft.UsedPageTableEntries != 0; -#endif -} - PFN_NUMBER NTAPI MmGetPfnForProcess(PEPROCESS Process, @@ -201,7 +132,7 @@ MmGetPfnForProcess(PEPROCESS Process, /* Lock for reading */ MiLockProcessWorkingSetShared(Process, PsGetCurrentThread()); - if (!MiIsPageTablePresent(Address)) + if (MiQueryPageTableReferences(Address) == 0) { MiUnlockProcessWorkingSetShared(Process, PsGetCurrentThread()); return 0; @@ -270,7 +201,7 @@ MmDeleteVirtualMapping(PEPROCESS Process, PVOID Address, MiLockProcessWorkingSetUnsafe(Process, PsGetCurrentThread()); /* No PDE --> No page */ - if (!MiIsPageTablePresent(Address)) + if (MiQueryPageTableReferences(Address) == 0) { MiUnlockProcessWorkingSetUnsafe(Process, PsGetCurrentThread()); if (WasDirty) @@ -307,10 +238,11 @@ MmDeleteVirtualMapping(PEPROCESS Process, PVOID Address, if (Address < MmSystemRangeStart) { /* Remove PDE reference */ - if (MiDecrementPageTableReferences(Address) == 0) + MiDecrementPageTableReferences(Address); + if (MiQueryPageTableReferences(Address) == 0) { KIRQL OldIrql = MiAcquirePfnLock(); - MiDeletePde(MiAddressToPde(Address), Process); + MiDeletePte(MiAddressToPte(PointerPte), PointerPte, Process, NULL); MiReleasePfnLock(OldIrql); } @@ -361,11 +293,12 @@ MmDeletePageFileMapping( } /* This used to be a non-zero PTE, now we can let the PDE go. */ - if (MiDecrementPageTableReferences(Address) == 0) + MiDecrementPageTableReferences(Address); + if (MiQueryPageTableReferences(Address) == 0) { /* We can let it go */ KIRQL OldIrql = MiAcquirePfnLock(); - MiDeletePde(MiPteToPde(PointerPte), Process); + MiDeletePte(MiAddressToPte(PointerPte), PointerPte, Process, NULL); MiReleasePfnLock(OldIrql); } @@ -401,7 +334,7 @@ MmIsPagePresent(PEPROCESS Process, PVOID Address) MiLockProcessWorkingSetShared(Process, PsGetCurrentThread()); - if (!MiIsPageTablePresent(Address)) + if (MiQueryPageTableReferences(Address) == 0) { /* It can't be present if there is no PDE */ MiUnlockProcessWorkingSetShared(Process, PsGetCurrentThread()); @@ -444,7 +377,7 @@ MmIsDisabledPage(PEPROCESS Process, PVOID Address) MiLockProcessWorkingSetShared(Process, PsGetCurrentThread()); - if (!MiIsPageTablePresent(Address)) + if (MiQueryPageTableReferences(Address) == 0) { /* It can't be disabled if there is no PDE */ MiUnlockProcessWorkingSetShared(Process, PsGetCurrentThread()); @@ -484,7 +417,7 @@ MmIsPageSwapEntry(PEPROCESS Process, PVOID Address) MiLockProcessWorkingSetShared(Process, PsGetCurrentThread()); - if (!MiIsPageTablePresent(Address)) + if (MiQueryPageTableReferences(Address) == 0) { /* There can't be a swap entry if there is no PDE */ MiUnlockProcessWorkingSetShared(Process, PsGetCurrentThread()); @@ -520,7 +453,7 @@ MmGetPageFileMapping(PEPROCESS Process, PVOID Address, SWAPENTRY* SwapEntry) MiLockProcessWorkingSetShared(Process, PsGetCurrentThread()); - if (!MiIsPageTablePresent(Address)) + if (MiQueryPageTableReferences(Address) == 0) { /* There can't be a swap entry if there is no PDE */ MiUnlockProcessWorkingSetShared(Process, PsGetCurrentThread()); @@ -707,7 +640,7 @@ MmGetPageProtect(PEPROCESS Process, PVOID Address) MiLockProcessWorkingSetShared(Process, PsGetCurrentThread()); - if (!MiIsPageTablePresent(Address)) + if (MiQueryPageTableReferences(Address) == 0) { /* It can't be present if there is no PDE */ MiUnlockProcessWorkingSetShared(Process, PsGetCurrentThread());