From 9cc9f6687bf1c58aba80fdd7dfe363870488f2d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Gardou?= Date: Tue, 15 Nov 2011 18:36:26 +0000 Subject: [PATCH] [NTOSKRNL/MM] - call mm functions with a process, when we have one. - Fix potential rounding issues - Add some sanity ASSERTs - You never use enough brackets ;-) svn path=/trunk/; revision=54386 --- reactos/ntoskrnl/mm/anonmem.c | 6 +++--- reactos/ntoskrnl/mm/freelist.c | 2 ++ reactos/ntoskrnl/mm/marea.c | 5 ++++- reactos/ntoskrnl/mm/pagefile.c | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/reactos/ntoskrnl/mm/anonmem.c b/reactos/ntoskrnl/mm/anonmem.c index 0940db22ffc..659be426093 100644 --- a/reactos/ntoskrnl/mm/anonmem.c +++ b/reactos/ntoskrnl/mm/anonmem.c @@ -183,7 +183,7 @@ MmNotPresentFaultVirtualMemory(PMMSUPPORT AddressSpace, * address space when another thread could load the page so we check * that. */ - if (MmIsPagePresent(NULL, Address)) + if (MmIsPagePresent(Process, Address)) { return(STATUS_SUCCESS); } @@ -301,7 +301,7 @@ MmNotPresentFaultVirtualMemory(PMMSUPPORT AddressSpace, /* * Handle swapped out pages. */ - if (MmIsPageSwapEntry(NULL, Address)) + if (MmIsPageSwapEntry(Process, Address)) { SWAPENTRY SwapEntry; @@ -327,7 +327,7 @@ MmNotPresentFaultVirtualMemory(PMMSUPPORT AddressSpace, { MmUnlockAddressSpace(AddressSpace); Status = MmCreateVirtualMapping(Process, - Address, + (PVOID)PAGE_ROUND_DOWN(Address), Region->Protect, &Page, 1); diff --git a/reactos/ntoskrnl/mm/freelist.c b/reactos/ntoskrnl/mm/freelist.c index c4cf0e2987f..f8efc073964 100644 --- a/reactos/ntoskrnl/mm/freelist.c +++ b/reactos/ntoskrnl/mm/freelist.c @@ -92,6 +92,7 @@ MmInsertLRULastUserPage(PFN_NUMBER Pfn) /* Set the page as a user page */ ASSERT(Pfn != 0); ASSERT_IS_ROS_PFN(MiGetPfnEntry(Pfn)); + ASSERT(!RtlCheckBit(&MiUserPfnBitMap, (ULONG)Pfn)); OldIrql = KeAcquireQueuedSpinLock(LockQueuePfnLock); RtlSetBit(&MiUserPfnBitMap, (ULONG)Pfn); KeReleaseQueuedSpinLock(LockQueuePfnLock, OldIrql); @@ -123,6 +124,7 @@ MmRemoveLRUUserPage(PFN_NUMBER Page) /* Unset the page as a user page */ ASSERT(Page != 0); ASSERT_IS_ROS_PFN(MiGetPfnEntry(Page)); + ASSERT(RtlCheckBit(&MiUserPfnBitMap, (ULONG)Page)); RtlClearBit(&MiUserPfnBitMap, (ULONG)Page); } diff --git a/reactos/ntoskrnl/mm/marea.c b/reactos/ntoskrnl/mm/marea.c index fb3265e63a8..fe6717131be 100644 --- a/reactos/ntoskrnl/mm/marea.c +++ b/reactos/ntoskrnl/mm/marea.c @@ -893,7 +893,7 @@ MmCreateMemoryArea(PMMSUPPORT AddressSpace, Granularity = (MEMORY_AREA_VIRTUAL_MEMORY == Type ? MM_VIRTMEM_GRANULARITY : PAGE_SIZE); if ((*BaseAddress) == 0 && !FixedAddress) { - tmpLength = PAGE_ROUND_UP(Length); + tmpLength = (ULONG_PTR)MM_ROUND_UP(Length, Granularity); *BaseAddress = MmFindGap(AddressSpace, tmpLength, Granularity, @@ -908,6 +908,7 @@ MmCreateMemoryArea(PMMSUPPORT AddressSpace, { tmpLength = Length + ((ULONG_PTR) *BaseAddress - (ULONG_PTR) MM_ROUND_DOWN(*BaseAddress, Granularity)); + tmpLength = (ULONG_PTR)MM_ROUND_UP(tmpLength, Granularity); *BaseAddress = MM_ROUND_DOWN(*BaseAddress, Granularity); if (!MmGetAddressSpaceOwner(AddressSpace) && *BaseAddress < MmSystemRangeStart) @@ -986,6 +987,8 @@ MmMapMemoryArea(PVOID BaseAddress, { ULONG i; NTSTATUS Status; + + ASSERT(((ULONG_PTR)BaseAddress % PAGE_SIZE) == 0); for (i = 0; i < PAGE_ROUND_UP(Length) / PAGE_SIZE; i++) { diff --git a/reactos/ntoskrnl/mm/pagefile.c b/reactos/ntoskrnl/mm/pagefile.c index 0a6be61416e..987e798f67c 100644 --- a/reactos/ntoskrnl/mm/pagefile.c +++ b/reactos/ntoskrnl/mm/pagefile.c @@ -113,7 +113,7 @@ static PFN_COUNT MiReservedSwapPages; */ #define FILE_FROM_ENTRY(i) ((i) & 0x0f) #define OFFSET_FROM_ENTRY(i) ((i) >> 11) -#define ENTRY_FROM_FILE_OFFSET(i, j) ((i) | (j) << 11 | 0x400) +#define ENTRY_FROM_FILE_OFFSET(i, j) ((i) | ((j) << 11) | 0x400) static BOOLEAN MmSwapSpaceMessage = FALSE;