From 4a1429bb28d29f8b7f620c5b18f695da0b451f2a Mon Sep 17 00:00:00 2001 From: Hartmut Birr Date: Thu, 20 May 2004 08:37:21 +0000 Subject: [PATCH] - Do not change the mapping count of a page if the physical address falls in the range of valid physical memory (in MmMapIoSpace and MmUnmapIoSpace). svn path=/trunk/; revision=9445 --- reactos/ntoskrnl/include/internal/mm.h | 4 -- reactos/ntoskrnl/mm/i386/page.c | 88 +++----------------------- reactos/ntoskrnl/mm/iospace.c | 3 +- reactos/ntoskrnl/mm/marea.c | 41 +++++++----- reactos/ntoskrnl/mm/pagefile.c | 9 +-- 5 files changed, 38 insertions(+), 107 deletions(-) diff --git a/reactos/ntoskrnl/include/internal/mm.h b/reactos/ntoskrnl/include/internal/mm.h index c61e4c48414..9fb32f2dbf1 100644 --- a/reactos/ntoskrnl/include/internal/mm.h +++ b/reactos/ntoskrnl/include/internal/mm.h @@ -669,9 +669,5 @@ VOID MmRawDeleteVirtualMapping(PVOID Address); VOID MiStopPagerThread(VOID); -NTSTATUS -MmCreateVirtualMappingDump(PVOID Address, - ULONG flProtect, - PHYSICAL_ADDRESS PhysicalAddress); #endif diff --git a/reactos/ntoskrnl/mm/i386/page.c b/reactos/ntoskrnl/mm/i386/page.c index b71e1a4b94c..cbd39188991 100644 --- a/reactos/ntoskrnl/mm/i386/page.c +++ b/reactos/ntoskrnl/mm/i386/page.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: page.c,v 1.65 2004/04/28 20:46:03 hbirr Exp $ +/* $Id: page.c,v 1.66 2004/05/20 08:37:21 hbirr Exp $ * * PROJECT: ReactOS kernel * FILE: ntoskrnl/mm/i386/page.c @@ -1003,9 +1003,9 @@ BOOLEAN MmIsPageSwapEntry(PEPROCESS Process, PVOID Address) } NTSTATUS -MmCreateVirtualMappingDump(PVOID Address, - ULONG flProtect, - PHYSICAL_ADDRESS PhysicalAddress) +MmCreateVirtualMappingForKernel(PVOID Address, + ULONG flProtect, + PHYSICAL_ADDRESS PhysicalAddress) { ULONG Attributes; PULONG Pte; @@ -1013,7 +1013,7 @@ MmCreateVirtualMappingDump(PVOID Address, if (Address < (PVOID)KERNEL_BASE) { - DPRINT1("No process\n"); + DPRINT1("MmCreateVirtualMappingForKernel is called for user space\n"); KEBUGCHECK(0); } @@ -1031,87 +1031,15 @@ MmCreateVirtualMappingDump(PVOID Address, { return(Status); } - if (PAGE_MASK((*Pte)) != 0 && !((*Pte) & PA_PRESENT)) - { - KEBUGCHECK(0); - } - *Pte = (ULONG)(PhysicalAddress.QuadPart | Attributes); - FLUSH_TLB; - return(STATUS_SUCCESS); -} - -NTSTATUS -MmCreateVirtualMappingForKernel(PVOID Address, - ULONG flProtect, - PHYSICAL_ADDRESS PhysicalAddress) -{ - PEPROCESS CurrentProcess; - ULONG Attributes; - PULONG Pte; - NTSTATUS Status; - PEPROCESS Process = NULL; - - if (Process != NULL) - { - CurrentProcess = PsGetCurrentProcess(); - } - else - { - CurrentProcess = NULL; - } - - if (Process == NULL && Address < (PVOID)KERNEL_BASE) - { - DPRINT1("No process\n"); - KEBUGCHECK(0); - } - if (Process != NULL && Address >= (PVOID)KERNEL_BASE) - { - DPRINT1("Setting kernel address with process context\n"); - KEBUGCHECK(0); - } - Attributes = ProtectToPTE(flProtect); - - if (Process != NULL && Process != CurrentProcess) - { - KeAttachProcess(Process); - } - - Status = MmGetPageEntry2(Address, &Pte, FALSE); - if (!NT_SUCCESS(Status)) - { - if (Process != NULL && Process != CurrentProcess) - { - KeDetachProcess(); - } - return(Status); - } - if (PAGE_MASK((*Pte)) != 0 && !((*Pte) & PA_PRESENT)) - { - KEBUGCHECK(0); - } if (PAGE_MASK((*Pte)) != 0) { - MmMarkPageUnmapped(PTE_TO_PAGE((*Pte))); + KEBUGCHECK(0); } + *Pte = (ULONG)(PhysicalAddress.QuadPart | Attributes); - if (Process != NULL && - Process->AddressSpace.PageTableRefCountTable != NULL && - Address < (PVOID)KERNEL_BASE && - Attributes & PA_PRESENT) - { - PUSHORT Ptrc; - - Ptrc = Process->AddressSpace.PageTableRefCountTable; - - Ptrc[ADDR_TO_PAGE_TABLE(Address)]++; - } FLUSH_TLB; - if (Process != NULL && Process != CurrentProcess) - { - KeDetachProcess(); - } + return(STATUS_SUCCESS); } diff --git a/reactos/ntoskrnl/mm/iospace.c b/reactos/ntoskrnl/mm/iospace.c index 548f77c2fa4..c58f8cefd3f 100644 --- a/reactos/ntoskrnl/mm/iospace.c +++ b/reactos/ntoskrnl/mm/iospace.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: iospace.c,v 1.27 2004/05/15 22:45:49 hbirr Exp $ +/* $Id: iospace.c,v 1.28 2004/05/20 08:37:20 hbirr Exp $ * * PROJECT: ReactOS kernel * FILE: ntoskrnl/mm/iospace.c @@ -126,7 +126,6 @@ MmMapIoSpace (IN PHYSICAL_ADDRESS PhysicalAddress, DbgPrint("Unable to create virtual mapping\n"); KEBUGCHECK(0); } - MmMarkPageMapped(PhysicalAddress); } return ((PVOID)((char*)Result + Offset)); } diff --git a/reactos/ntoskrnl/mm/marea.c b/reactos/ntoskrnl/mm/marea.c index fc0475d3ab3..092cb8eb263 100644 --- a/reactos/ntoskrnl/mm/marea.c +++ b/reactos/ntoskrnl/mm/marea.c @@ -395,28 +395,35 @@ MmFreeMemoryArea(PMADDRESS_SPACE AddressSpace, PHYSICAL_ADDRESS PhysAddr = { 0 }; #endif - BOOL Dirty = FALSE; - SWAPENTRY SwapEntry = 0; - - if (MmIsPageSwapEntry(AddressSpace->Process, - (char*)MemoryArea->BaseAddress + (i * PAGE_SIZE))) + if (MemoryArea->Type == MEMORY_AREA_IO_MAPPING) { - MmDeletePageFileMapping(AddressSpace->Process, - (char*)MemoryArea->BaseAddress + (i * PAGE_SIZE), - &SwapEntry); + MmRawDeleteVirtualMapping((char*)MemoryArea->BaseAddress + (i * PAGE_SIZE)); } else { - MmDeleteVirtualMapping(AddressSpace->Process, - (char*)MemoryArea->BaseAddress + (i*PAGE_SIZE), - FALSE, &Dirty, &PhysAddr); + BOOL Dirty = FALSE; + SWAPENTRY SwapEntry = 0; - } - if (FreePage != NULL) - { - FreePage(FreePageContext, MemoryArea, - (char*)MemoryArea->BaseAddress + (i * PAGE_SIZE), PhysAddr, - SwapEntry, (BOOLEAN)Dirty); + if (MmIsPageSwapEntry(AddressSpace->Process, + (char*)MemoryArea->BaseAddress + (i * PAGE_SIZE))) + { + MmDeletePageFileMapping(AddressSpace->Process, + (char*)MemoryArea->BaseAddress + (i * PAGE_SIZE), + &SwapEntry); + } + else + { + MmDeleteVirtualMapping(AddressSpace->Process, + (char*)MemoryArea->BaseAddress + (i*PAGE_SIZE), + FALSE, &Dirty, &PhysAddr); + + } + if (FreePage != NULL) + { + FreePage(FreePageContext, MemoryArea, + (char*)MemoryArea->BaseAddress + (i * PAGE_SIZE), PhysAddr, + SwapEntry, (BOOLEAN)Dirty); + } } } if (AddressSpace->Process != NULL && diff --git a/reactos/ntoskrnl/mm/pagefile.c b/reactos/ntoskrnl/mm/pagefile.c index 9ebf161488d..b984a62e70f 100644 --- a/reactos/ntoskrnl/mm/pagefile.c +++ b/reactos/ntoskrnl/mm/pagefile.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: pagefile.c,v 1.44 2004/04/22 01:57:49 jimtabor Exp $ +/* $Id: pagefile.c,v 1.45 2004/05/20 08:37:20 hbirr Exp $ * * PROJECT: ReactOS kernel * FILE: ntoskrnl/mm/pagefile.c @@ -587,9 +587,9 @@ MmDumpToPagingFile(ULONG BugCode, LARGE_INTEGER PhysicalAddress; PhysicalAddress.QuadPart = i * PAGE_SIZE; MdlMap[0] = i * PAGE_SIZE; - MmCreateVirtualMappingDump(MmCoreDumpPageFrame, - PAGE_READWRITE, - PhysicalAddress); + MmCreateVirtualMappingForKernel(MmCoreDumpPageFrame, + PAGE_READWRITE, + PhysicalAddress); #if defined(__GNUC__) DiskOffset = MmGetOffsetPageFile(RetrievalPointers, @@ -604,6 +604,7 @@ MmDumpToPagingFile(ULONG BugCode, #endif DiskOffset.QuadPart += MmCoreDumpLcnMapping.LcnDiskOffset.QuadPart; Status = MmCoreDumpFunctions->DumpWrite(DiskOffset, Mdl); + MmRawDeleteVirtualMapping(MmCoreDumpPageFrame); if (!NT_SUCCESS(Status)) { DPRINT1("MM: Failed to write page to core dump.\n");