From 80dd9f5a90487188213da24ff1e46335461e2281 Mon Sep 17 00:00:00 2001 From: Timo Kreuzer Date: Mon, 10 Apr 2023 22:14:23 +0300 Subject: [PATCH] [NTOS:Mm] Add PFN ShareCount handling to old Mm --- ntoskrnl/mm/i386/page.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/ntoskrnl/mm/i386/page.c b/ntoskrnl/mm/i386/page.c index 4c64dd2a941..38cd5066256 100644 --- a/ntoskrnl/mm/i386/page.c +++ b/ntoskrnl/mm/i386/page.c @@ -325,7 +325,18 @@ MmDeleteVirtualMappingEx( if (!IsPhysical && OldPte.u.Hard.Valid) { - // TODO: Handle PFN ShareCount + PMMPFN Pfn1; + KIRQL OldIrql; + + OldIrql = MiAcquirePfnLock(); + Pfn1 = &MmPfnDatabase[OldPte.u.Hard.PageFrameNumber]; + ASSERT(Pfn1->u3.e1.PageLocation == ActiveAndValid); + ASSERT(Pfn1->u2.ShareCount > 0); + if (--Pfn1->u2.ShareCount == 0) + { + Pfn1->u3.e1.PageLocation = TransitionPage; + } + MiReleasePfnLock(OldIrql); } MiUnlockProcessWorkingSetUnsafe(Process, PsGetCurrentThread()); @@ -685,7 +696,14 @@ MmCreateVirtualMappingUnsafeEx( if (!IsPhysical) { - // TODO: Handle PFN ShareCount + PMMPFN Pfn1; + KIRQL OldIrql; + + OldIrql = MiAcquirePfnLock(); + Pfn1 = &MmPfnDatabase[TempPte.u.Hard.PageFrameNumber]; + Pfn1->u2.ShareCount++; + Pfn1->u3.e1.PageLocation = ActiveAndValid; + MiReleasePfnLock(OldIrql); } /* We don't need to flush the TLB here because it only caches valid translations