Author: ros-arm-bringup Date: Tue Mar 10 23:52:39 2009 New Revision: 39938
URL: http://svn.reactos.org/svn/reactos?rev=39938&view=rev Log: - Rework Hyperspace Mapping Interface for Page zeroing. It is now more efficient and adapted to ReactOS. - This also fixes some race conditions. - There was a lot of difficulty getting this patch through because of everyone else adding their 2 cents to the code. Next time, wait.
Modified: trunk/reactos/ntoskrnl/include/internal/mm.h trunk/reactos/ntoskrnl/mm/hypermap.c trunk/reactos/ntoskrnl/mm/i386/page.c trunk/reactos/ntoskrnl/mm/kmap.c trunk/reactos/ntoskrnl/mm/section.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 Mar 10 23:52:39 2009 @@ -65,6 +65,8 @@ #define MI_MAPPING_RANGE_START (ULONG)HYPER_SPACE #define MI_MAPPING_RANGE_END (MI_MAPPING_RANGE_START + \ MI_HYPERSPACE_PTES * PAGE_SIZE) +#define MI_ZERO_PTE (PMMPTE)(MI_MAPPING_RANGE_END + \ + PAGE_SIZE)
/* Signature of free pool blocks */ #define MM_FREE_POOL_TAG TAG('F', 'r', 'p', 'l') @@ -1086,11 +1088,7 @@
PVOID NTAPI -MiMapPagesToZeroInHyperSpace(IN PFN_NUMBER Page); - -VOID -NTAPI -MiUnmapPagesInZeroSpace(IN PVOID Address); +MiMapPageToZeroInHyperSpace(IN PFN_NUMBER Page);
// // ReactOS Compatibility Layer
Modified: trunk/reactos/ntoskrnl/mm/hypermap.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/hypermap.c?rev=... ============================================================================== --- trunk/reactos/ntoskrnl/mm/hypermap.c [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/mm/hypermap.c [iso-8859-1] Tue Mar 10 23:52:39 2009 @@ -130,11 +130,10 @@
PVOID NTAPI -MiMapPagesToZeroInHyperSpace(IN PFN_NUMBER Page) +MiMapPageToZeroInHyperSpace(IN PFN_NUMBER Page) { MMPTE TempPte; PMMPTE PointerPte; - PFN_NUMBER Offset; PVOID Address;
// @@ -149,49 +148,24 @@ TempPte.u.Hard.PageFrameNumber = Page;
// - // Pick the first hyperspace PTE + // Get the Zero PTE and its address // - PointerPte = MmFirstReservedMappingPte; - - // - // Now get the first free PTE - // - Offset = PFN_FROM_PTE(PointerPte); - if (!Offset) - { - // - // Reset the PTEs - // - Offset = MI_HYPERSPACE_PTES; - KeFlushProcessTb(); - } + PointerPte = MiAddressToPte(MI_ZERO_PTE); + Address = (PVOID)((ULONG_PTR)PointerPte << 10);
// - // Prepare the next PTE + // Invalidate the old address // - PointerPte->u.Hard.PageFrameNumber = Offset - 1; + __invlpg(Address);
// // Write the current PTE // - PointerPte += Offset; - ASSERT(PointerPte->u.Hard.Valid == 0); - ASSERT(TempPte.u.Hard.Valid == 1); + TempPte.u.Hard.PageFrameNumber = Page; *PointerPte = TempPte;
// // Return the address // - Address = (PVOID)((ULONG_PTR)PointerPte << 10); return Address; } - -VOID -NTAPI -MiUnmapPagesInZeroSpace(IN PVOID Address) -{ - // - // Blow away the mapping - // - MiAddressToPte(Address)->u.Long = 0; -}
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 Mar 10 23:52:39 2009 @@ -783,6 +783,7 @@ DPRINT1("Setting kernel address with process context\n"); KeBugCheck(MEMORY_MANAGEMENT); } + if (SwapEntry & (1 << 31)) { KeBugCheck(MEMORY_MANAGEMENT); @@ -1086,7 +1087,7 @@
if (Process != NULL && Process != PsGetCurrentProcess()) { - Pde = MiMapPagesToZeroInHyperSpace(PTE_TO_PFN(Process->Pcb.DirectoryTableBase[0])); + Pde = MiMapPageToZeroInHyperSpace(PTE_TO_PFN(Process->Pcb.DirectoryTableBase[0])); } else { @@ -1098,10 +1099,6 @@ { InterlockedCompareExchangePte(&Pde[Offset], MmGlobalKernelPageDirectory[Offset], 0); } - } - if (Pde != (PULONG)PAGEDIRECTORY_MAP) - { - MiUnmapPagesInZeroSpace(Pde); } }
Modified: trunk/reactos/ntoskrnl/mm/kmap.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/kmap.c?rev=3993... ============================================================================== --- trunk/reactos/ntoskrnl/mm/kmap.c [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/mm/kmap.c [iso-8859-1] Tue Mar 10 23:52:39 2009 @@ -22,13 +22,12 @@ { PVOID TempAddress;
- TempAddress = MiMapPagesToZeroInHyperSpace(Page); + TempAddress = MiMapPageToZeroInHyperSpace(Page); if (TempAddress == NULL) { return(STATUS_NO_MEMORY); } memset(TempAddress, 0, PAGE_SIZE); - MiUnmapPagesInZeroSpace(TempAddress); return(STATUS_SUCCESS); }
Modified: trunk/reactos/ntoskrnl/mm/section.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/section.c?rev=3... ============================================================================== --- trunk/reactos/ntoskrnl/mm/section.c [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/mm/section.c [iso-8859-1] Tue Mar 10 23:52:39 2009 @@ -691,7 +691,7 @@ return Status; } } - PageAddr = MiMapPagesToZeroInHyperSpace(*Page); + PageAddr = MiMapPageToZeroInHyperSpace(*Page); CacheSegOffset = BaseOffset + CacheSeg->Bcb->CacheSegmentSize - FileOffset; Length = RawLength - SegOffset; if (Length <= CacheSegOffset && Length <= PAGE_SIZE) @@ -714,7 +714,6 @@ &CacheSeg); if (!NT_SUCCESS(Status)) { - MiUnmapPagesInZeroSpace(PageAddr); return(Status); } if (!UptoDate) @@ -727,7 +726,6 @@ if (!NT_SUCCESS(Status)) { CcRosReleaseCacheSegment(Bcb, CacheSeg, FALSE, FALSE, FALSE); - MiUnmapPagesInZeroSpace(PageAddr); return Status; } } @@ -741,7 +739,6 @@ } } CcRosReleaseCacheSegment(Bcb, CacheSeg, TRUE, FALSE, FALSE); - MiUnmapPagesInZeroSpace(PageAddr); } return(STATUS_SUCCESS); }