[NTOS:MM] Get rid of MiQueryPageTableReferences

This commit is contained in:
Jérôme Gardou 2021-06-07 14:12:21 +02:00 committed by Jérôme Gardou
parent 6a2eeaa5ae
commit c7e09061ca
3 changed files with 15 additions and 50 deletions

View file

@ -2477,17 +2477,6 @@ MiDecrementPageTableReferences(IN PVOID Address)
ASSERT(*RefCount < PTE_PER_PAGE);
return *RefCount;
}
FORCEINLINE
USHORT
MiQueryPageTableReferences(IN PVOID Address)
{
PUSHORT RefCount;
RefCount = &MmWorkingSetList->UsedPageTableEntries[MiGetPdeOffset(Address)];
return *RefCount;
}
#else
FORCEINLINE
USHORT
@ -2543,24 +2532,6 @@ MiDecrementPageTableReferences(IN PVOID Address)
return Pfn->OriginalPte.u.Soft.UsedPageTableEntries;
}
FORCEINLINE
USHORT
MiQueryPageTableReferences(IN PVOID Address)
{
PMMPDE PointerPde;
PMMPFN Pfn;
/* Make sure we're locked */
ASSERT((PsGetCurrentThread()->OwnsProcessWorkingSetExclusive) || (PsGetCurrentThread()->OwnsProcessWorkingSetShared));
PointerPde = MiAddressToPde(Address);
ASSERT(PointerPde->u.Hard.Valid);
/* This lies on the PFN */
Pfn = MiGetPfnEntry(PFN_FROM_PDE(PointerPde));
return Pfn->OriginalPte.u.Soft.UsedPageTableEntries;
}
#endif
#ifdef __cplusplus

View file

@ -659,12 +659,13 @@ 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))
{
@ -709,29 +710,23 @@ 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++;
/* 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)
{
ASSERT(PointerPde->u.Long != 0);
/* Delete the PDE proper */
MiDeletePde(PointerPde, CurrentProcess);
}
} while ((Va & (PDE_MAPPED_VA - 1)) && (Va <= EndingAddress));
/* Release the lock */
MiReleasePfnLock(OldIrql);
@ -739,7 +734,6 @@ MiDeleteVirtualAddresses(IN ULONG_PTR Va,
if (Va > EndingAddress) return;
/* Otherwise, we exited because we hit a new PDE boundary, so start over */
PointerPde = MiAddressToPde(Va);
AddressGap = FALSE;
}
}

View file

@ -119,7 +119,7 @@ BOOLEAN
MiIsPageTablePresent(PVOID Address)
{
#if _MI_PAGING_LEVELS == 2
return MiQueryPageTableReferences(Address) != 0;
return MmWorkingSetList->UsedPageTableEntries[MiGetPdeOffset(Address)] != 0;
#else
PMMPDE PointerPde;
PMMPPE PointerPpe;