[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)

svn path=/trunk/; revision=54988
This commit is contained in:
Cameron Gutman
2012-01-17 07:03:46 +00:00
parent c114281942
commit 5bed4995b4
3 changed files with 62 additions and 2 deletions
+2 -2
View File
@@ -1503,9 +1503,9 @@ NTSTATUS
NTAPI
MmReleaseMmInfo(struct _EPROCESS *Process);
NTSTATUS
VOID
NTAPI
Mmi386ReleaseMmInfo(struct _EPROCESS *Process);
MmDeleteProcessPageDirectory(struct _EPROCESS *Process);
VOID
NTAPI
+58
View File
@@ -200,6 +200,64 @@ ProtectToPTE(ULONG flProtect)
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)
{
+2
View File
@@ -1057,6 +1057,8 @@ MmDeleteProcessAddressSpace(PEPROCESS Process)
}
}
MmDeleteProcessPageDirectory(Process);
MmUnlockAddressSpace(&Process->Vm);
DPRINT("Finished MmReleaseMmInfo()\n");