Author: tkreuzer
Date: Sat May 16 21:30:52 2015
New Revision: 67791
URL:
http://svn.reactos.org/svn/reactos?rev=67791&view=rev
Log:
[NTOSKRNL]
- Allocate Memory area before trying to insert it in different pathes of
MmCreateMemoryArea. This change is a preparation for upcoming changes.
- Cleanup MmInsertMemoryArea from useless stuff
Modified:
trunk/reactos/ntoskrnl/mm/marea.c
Modified: trunk/reactos/ntoskrnl/mm/marea.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/marea.c?rev=67…
==============================================================================
--- trunk/reactos/ntoskrnl/mm/marea.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/marea.c [iso-8859-1] Sat May 16 21:30:52 2015
@@ -381,32 +381,16 @@
if ((MA_GetEndingAddress(marea) < (ULONG_PTR)MmSystemRangeStart) &&
(marea->Type != MEMORY_AREA_OWNED_BY_ARM3))
{
- PMMVAD Vad;
-
ASSERT(marea->Type == MEMORY_AREA_SECTION_VIEW || marea->Type ==
MEMORY_AREA_CACHE);
- Vad = &marea->VadNode;
-
- RtlZeroMemory(Vad, sizeof(MMVAD));
- Vad->StartingVpn = PAGE_ROUND_DOWN(MA_GetStartingAddress(marea)) >>
PAGE_SHIFT;
- /*
- * For some strange reason, it is perfectly valid to create a MAREA from 0x1000
to... 0x1000.
- * In a normal OS/Memory Manager, this would be retarded, but ReactOS allows this
(how it works
- * I don't even want to know).
- */
- if (MA_GetEndingAddress(marea) != MA_GetStartingAddress(marea))
- {
- Vad->EndingVpn = PAGE_ROUND_DOWN((ULONG_PTR)MA_GetEndingAddress(marea) -
1) >> PAGE_SHIFT;
- }
- else
- {
- Vad->EndingVpn = Vad->StartingVpn;
- }
- Vad->u.VadFlags.Spare = 1;
- Vad->u.VadFlags.Protection = MiMakeProtectionMask(marea->Protect);
+
+ marea->VadNode.StartingVpn = marea->StartingVpn;
+ marea->VadNode.EndingVpn = marea->EndingVpn;
+ marea->VadNode.u.VadFlags.Spare = 1;
+ marea->VadNode.u.VadFlags.Protection =
MiMakeProtectionMask(marea->Protect);
/* Insert the VAD */
- MiInsertVad(Vad, Process);
- marea->Vad = Vad;
+ MiInsertVad(&marea->VadNode, Process);
+ marea->Vad = &marea->VadNode;
}
else
{
@@ -936,6 +920,41 @@
Type, BaseAddress, *BaseAddress, Length, AllocationFlags,
Result);
+ //
+ // Is this a static memory area?
+ //
+ if (Type & MEMORY_AREA_STATIC)
+ {
+ //
+ // Use the static array instead of the pool
+ //
+ ASSERT(MiStaticMemoryAreaCount < MI_STATIC_MEMORY_AREAS);
+ MemoryArea = &MiStaticMemoryAreas[MiStaticMemoryAreaCount++];
+ }
+ else
+ {
+ //
+ // Allocate the memory area from nonpaged pool
+ //
+ MemoryArea = ExAllocatePoolWithTag(NonPagedPool,
+ sizeof(MEMORY_AREA),
+ TAG_MAREA);
+ }
+
+ if (!MemoryArea)
+ {
+ DPRINT1("Not enough memory.\n");
+ return STATUS_NO_MEMORY;
+ }
+
+ RtlZeroMemory(MemoryArea, sizeof(MEMORY_AREA));
+ MemoryArea->Type = Type & ~MEMORY_AREA_STATIC;
+ MemoryArea->Protect = Protect;
+ MemoryArea->Flags = AllocationFlags;
+ //MemoryArea->LockCount = 0;
+ MemoryArea->Magic = 'erAM';
+ MemoryArea->DeleteInProgress = FALSE;
+
if (*BaseAddress == 0)
{
tmpLength = (ULONG_PTR)MM_ROUND_UP(Length, PAGE_SIZE);
@@ -946,8 +965,13 @@
if ((*BaseAddress) == 0)
{
DPRINT("No suitable gap\n");
+ if (!(Type & MEMORY_AREA_STATIC)) ExFreePoolWithTag(MemoryArea,
TAG_MAREA);
return STATUS_NO_MEMORY;
}
+
+ MemoryArea->StartingVpn = (ULONG_PTR)*BaseAddress >> PAGE_SHIFT;
+ MemoryArea->EndingVpn = ((ULONG_PTR)*BaseAddress + tmpLength - 1) >>
PAGE_SHIFT;
+ MmInsertMemoryArea(AddressSpace, MemoryArea);
}
else
{
@@ -957,6 +981,8 @@
if (!MmGetAddressSpaceOwner(AddressSpace) && *BaseAddress <
MmSystemRangeStart)
{
+ ASSERT(FALSE);
+ if (!(Type & MEMORY_AREA_STATIC)) ExFreePoolWithTag(MemoryArea,
TAG_MAREA);
return STATUS_ACCESS_VIOLATION;
}
@@ -964,6 +990,7 @@
(ULONG_PTR)(*BaseAddress) + tmpLength >
(ULONG_PTR)MmSystemRangeStart)
{
DPRINT("Memory area for user mode address space exceeds
MmSystemRangeStart\n");
+ if (!(Type & MEMORY_AREA_STATIC)) ExFreePoolWithTag(MemoryArea,
TAG_MAREA);
return STATUS_ACCESS_VIOLATION;
}
@@ -972,49 +999,14 @@
tmpLength) != NULL)
{
DPRINT("Memory area already occupied\n");
+ if (!(Type & MEMORY_AREA_STATIC)) ExFreePoolWithTag(MemoryArea,
TAG_MAREA);
return STATUS_CONFLICTING_ADDRESSES;
}
- }
-
- //
- // Is this a static memory area?
- //
- if (Type & MEMORY_AREA_STATIC)
- {
- //
- // Use the static array instead of the pool
- //
- ASSERT(MiStaticMemoryAreaCount < MI_STATIC_MEMORY_AREAS);
- MemoryArea = &MiStaticMemoryAreas[MiStaticMemoryAreaCount++];
- Type &= ~MEMORY_AREA_STATIC;
- }
- else
- {
- //
- // Allocate the memory area from nonpaged pool
- //
- MemoryArea = ExAllocatePoolWithTag(NonPagedPool,
- sizeof(MEMORY_AREA),
- TAG_MAREA);
- }
-
- if (!MemoryArea)
- {
- DPRINT1("Not enough memory.\n");
- return STATUS_NO_MEMORY;
- }
-
- RtlZeroMemory(MemoryArea, sizeof(MEMORY_AREA));
- MemoryArea->Type = Type;
- MemoryArea->StartingVpn = (ULONG_PTR)*BaseAddress >> PAGE_SHIFT;
- MemoryArea->EndingVpn = ((ULONG_PTR)*BaseAddress + tmpLength - 1) >>
PAGE_SHIFT;
- MemoryArea->Protect = Protect;
- MemoryArea->Flags = AllocationFlags;
- //MemoryArea->LockCount = 0;
- MemoryArea->Magic = 'erAM';
- MemoryArea->DeleteInProgress = FALSE;
-
- MmInsertMemoryArea(AddressSpace, MemoryArea);
+
+ MemoryArea->StartingVpn = (ULONG_PTR)*BaseAddress >> PAGE_SHIFT;
+ MemoryArea->EndingVpn = ((ULONG_PTR)*BaseAddress + tmpLength - 1) >>
PAGE_SHIFT;
+ MmInsertMemoryArea(AddressSpace, MemoryArea);
+ }
*Result = MemoryArea;