Author: tkreuzer
Date: Wed Oct 8 00:30:30 2014
New Revision: 64584
URL:
http://svn.reactos.org/svn/reactos?rev=64584&view=rev
Log:
[NTOSKRNL]
Refactor CcRosMapVacb a bit
Modified:
trunk/reactos/ntoskrnl/cc/view.c
Modified: trunk/reactos/ntoskrnl/cc/view.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/cc/view.c?rev=645…
==============================================================================
--- trunk/reactos/ntoskrnl/cc/view.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/cc/view.c [iso-8859-1] Wed Oct 8 00:30:30 2014
@@ -579,38 +579,60 @@
}
static
-VOID
-CcRosMapVacb(PVOID BaseAddress,
- SIZE_T Length,
- ULONG Consumer,
- ULONG Protection)
+NTSTATUS
+CcRosMapVacb(
+ PROS_VACB Vacb)
{
ULONG i;
NTSTATUS Status;
-
- ASSERT(((ULONG_PTR)BaseAddress % PAGE_SIZE) == 0);
-
- for (i = 0; i < PAGE_ROUND_UP(Length) / PAGE_SIZE; i++)
- {
- PFN_NUMBER Page;
-
- Status = MmRequestPageMemoryConsumer(Consumer, TRUE, &Page);
- if (!NT_SUCCESS(Status))
+ ULONG_PTR NumberOfPages;
+
+ /* Create a memory area. */
+ MmLockAddressSpace(MmGetKernelAddressSpace());
+ Status = MmCreateMemoryArea(MmGetKernelAddressSpace(),
+ 0, // nothing checks for VACB mareas, so set to 0
+ &Vacb->BaseAddress,
+ VACB_MAPPING_GRANULARITY,
+ PAGE_READWRITE,
+ (PMEMORY_AREA*)&Vacb->MemoryArea,
+ FALSE,
+ 0,
+ PAGE_SIZE);
+ MmUnlockAddressSpace(MmGetKernelAddressSpace());
+ if (!NT_SUCCESS(Status))
+ {
+ KeBugCheck(CACHE_MANAGER);
+ }
+
+ ASSERT(((ULONG_PTR)Vacb->BaseAddress % PAGE_SIZE) == 0);
+ ASSERT((ULONG_PTR)Vacb->BaseAddress > (ULONG_PTR)MmSystemRangeStart);
+
+ /* Create a virtual mapping for this memory area */
+ NumberOfPages = BYTES_TO_PAGES(VACB_MAPPING_GRANULARITY);
+ for (i = 0; i < NumberOfPages; i++)
+ {
+ PFN_NUMBER PageFrameNumber;
+
+ Status = MmRequestPageMemoryConsumer(MC_CACHE, TRUE, &PageFrameNumber);
+ if (PageFrameNumber == 0)
{
DPRINT1("Unable to allocate page\n");
KeBugCheck(MEMORY_MANAGEMENT);
}
- Status = MmCreateVirtualMapping (NULL,
- (PVOID)((ULONG_PTR)BaseAddress + (i *
PAGE_SIZE)),
- Protection,
- &Page,
- 1);
+
+ Status = MmCreateVirtualMapping(NULL,
+ (PVOID)((ULONG_PTR)Vacb->BaseAddress + (i *
PAGE_SIZE)),
+ PAGE_READWRITE,
+ &PageFrameNumber,
+ 1);
if (!NT_SUCCESS(Status))
{
DPRINT1("Unable to create virtual mapping\n");
KeBugCheck(MEMORY_MANAGEMENT);
}
}
+
+ return STATUS_SUCCESS;
}
static
@@ -637,6 +659,7 @@
}
current = ExAllocateFromNPagedLookasideList(&VacbLookasideList);
+ current->BaseAddress = NULL;
current->Valid = FALSE;
current->Dirty = FALSE;
current->PageOut = FALSE;
@@ -724,24 +747,6 @@
InsertTailList(&VacbLruListHead, ¤t->VacbLruListEntry);
KeReleaseGuardedMutex(&ViewLock);
- MmLockAddressSpace(MmGetKernelAddressSpace());
- current->BaseAddress = NULL;
- Status = MmCreateMemoryArea(MmGetKernelAddressSpace(),
- 0, // nothing checks for VACB mareas, so set to 0
- ¤t->BaseAddress,
- VACB_MAPPING_GRANULARITY,
- PAGE_READWRITE,
- (PMEMORY_AREA*)¤t->MemoryArea,
- FALSE,
- 0,
- PAGE_SIZE);
- MmUnlockAddressSpace(MmGetKernelAddressSpace());
- if (!NT_SUCCESS(Status))
- {
- KeBugCheck(CACHE_MANAGER);
- }
-
- /* Create a virtual mapping for this memory area */
MI_SET_USAGE(MI_USAGE_CACHE);
#if MI_TRACE_PFNS
if ((SharedCacheMap->FileObject) &&
(SharedCacheMap->FileObject->FileName.Buffer))
@@ -754,10 +759,9 @@
}
#endif
- CcRosMapVacb(current->BaseAddress, VACB_MAPPING_GRANULARITY,
- MC_CACHE, PAGE_READWRITE);
-
- return STATUS_SUCCESS;
+ Status = CcRosMapVacb(current);
+
+ return Status;
}
NTSTATUS