Skip to content

Commit

Permalink
[NTOS:MM] Get rid of MiQueryPageTableReferences
Browse files Browse the repository at this point in the history
  • Loading branch information
zefklop committed Jun 9, 2021
1 parent 6a2eeaa commit c7e0906
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 50 deletions.
29 changes: 0 additions & 29 deletions ntoskrnl/mm/ARM3/miarm.h
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
34 changes: 14 additions & 20 deletions ntoskrnl/mm/ARM3/virtual.c
Expand Up @@ -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))
{
Expand Down Expand Up @@ -709,37 +710,30 @@ 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);

if (Va > EndingAddress) return;

/* Otherwise, we exited because we hit a new PDE boundary, so start over */
PointerPde = MiAddressToPde(Va);
AddressGap = FALSE;
}
}
Expand Down
2 changes: 1 addition & 1 deletion ntoskrnl/mm/i386/page.c
Expand Up @@ -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;
Expand Down

1 comment on commit c7e0906

@JoachimHenze
Copy link
Contributor

@JoachimHenze JoachimHenze commented on c7e0906 Oct 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.