Author: cgutman Date: Tue Jan 17 07:03:46 2012 New Revision: 54988
URL: http://svn.reactos.org/svn/reactos?rev=54988&view=rev Log: [NTOSKRNL] - Deallocate the process page directory when destroying its address space (removed in r48233 and now resurrected in a version compatible with ARM3) - Fixes leaking system pages on each process exit (868 MC_SYSTEM pages were allocated just sitting at the desktop on livecd without the patch, only 187 with the patch)
Modified: trunk/reactos/ntoskrnl/include/internal/mm.h trunk/reactos/ntoskrnl/mm/i386/page.c trunk/reactos/ntoskrnl/mm/marea.c
Modified: trunk/reactos/ntoskrnl/include/internal/mm.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/m... ============================================================================== --- trunk/reactos/ntoskrnl/include/internal/mm.h [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/include/internal/mm.h [iso-8859-1] Tue Jan 17 07:03:46 2012 @@ -1503,9 +1503,9 @@ NTAPI MmReleaseMmInfo(struct _EPROCESS *Process);
-NTSTATUS -NTAPI -Mmi386ReleaseMmInfo(struct _EPROCESS *Process); +VOID +NTAPI +MmDeleteProcessPageDirectory(struct _EPROCESS *Process);
VOID NTAPI
Modified: trunk/reactos/ntoskrnl/mm/i386/page.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/i386/page.c?rev... ============================================================================== --- trunk/reactos/ntoskrnl/mm/i386/page.c [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/mm/i386/page.c [iso-8859-1] Tue Jan 17 07:03:46 2012 @@ -200,6 +200,64 @@ return(Attributes); }
+static +VOID +MmDeletePageDirectoryEntry(ULONG PdeEntry) +{ + KIRQL OldIrql; + PMMPFN Page; + + Page = MiGetPfnEntry(PTE_TO_PFN(PdeEntry)); + + /* Check if this is a legacy allocation */ + if (MI_IS_ROS_PFN(Page)) + { + /* Free it using the legacy API */ + MmReleasePageMemoryConsumer(MC_SYSTEM, PTE_TO_PFN(PdeEntry)); + } + else + { + OldIrql = KeAcquireQueuedSpinLock(LockQueuePfnLock); + + /* Free it using the ARM3 API */ + MI_SET_PFN_DELETED(Page); + MiDecrementShareCount(Page, PTE_TO_PFN(PdeEntry)); + + KeReleaseQueuedSpinLock(LockQueuePfnLock, OldIrql); + } +} + +VOID +NTAPI +MmDeleteProcessPageDirectory(PEPROCESS Process) +{ + PULONG PageDir; + ULONG PdeOffset; + + /* Map the page directory in hyperspace */ + PageDir = MmCreateHyperspaceMapping(PTE_TO_PFN(Process->Pcb.DirectoryTableBase[0])); + + /* Loop the user land page directory */ + for (PdeOffset = 0; PdeOffset < ADDR_TO_PDE_OFFSET(MmSystemRangeStart); PdeOffset++) + { + /* Check if a valid PDE exists here */ + if (PageDir[PdeOffset] != 0) + { + /* Free the page that backs it */ + MmDeletePageDirectoryEntry(PageDir[PdeOffset]); + } + } + + /* Free the hyperspace mapping page (ARM3) */ + MmDeletePageDirectoryEntry(PageDir[ADDR_TO_PDE_OFFSET(HYPERSPACE)]); + + /* Delete the hyperspace mapping */ + MmDeleteHyperspaceMapping(PageDir); + + /* Free the PDE page itself (ARM3) */ + MmDeletePageDirectoryEntry(Process->Pcb.DirectoryTableBase[0]); +} + static PULONG MmGetPageTableForProcess(PEPROCESS Process, PVOID Address, BOOLEAN Create) {
Modified: trunk/reactos/ntoskrnl/mm/marea.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/marea.c?rev=549... ============================================================================== --- trunk/reactos/ntoskrnl/mm/marea.c [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/mm/marea.c [iso-8859-1] Tue Jan 17 07:03:46 2012 @@ -1057,6 +1057,8 @@ } }
+ MmDeleteProcessPageDirectory(Process); + MmUnlockAddressSpace(&Process->Vm);
DPRINT("Finished MmReleaseMmInfo()\n");