Author: tkreuzer
Date: Sat May 16 23:36:42 2015
New Revision: 67792
URL:
http://svn.reactos.org/svn/reactos?rev=67792&view=rev
Log:
[NTOSKRNL]
Insert kernel memory areas into a "kernel VAD table".
Modified:
trunk/reactos/ntoskrnl/mm/ARM3/miarm.h
trunk/reactos/ntoskrnl/mm/ARM3/vadnode.c
trunk/reactos/ntoskrnl/mm/marea.c
Modified: trunk/reactos/ntoskrnl/mm/ARM3/miarm.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/ARM3/miarm.h?r…
==============================================================================
--- trunk/reactos/ntoskrnl/mm/ARM3/miarm.h [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/ARM3/miarm.h [iso-8859-1] Sat May 16 23:36:42 2015
@@ -2039,13 +2039,6 @@
IN ULONG ProtectionMask
);
-VOID
-NTAPI
-MiInsertVad(
- IN PMMVAD Vad,
- IN PEPROCESS Process
-);
-
NTSTATUS
NTAPI
MiInsertVadEx(
Modified: trunk/reactos/ntoskrnl/mm/ARM3/vadnode.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/ARM3/vadnode.c…
==============================================================================
--- trunk/reactos/ntoskrnl/mm/ARM3/vadnode.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/ARM3/vadnode.c [iso-8859-1] Sat May 16 23:36:42 2015
@@ -181,24 +181,22 @@
VOID
NTAPI
MiInsertVad(IN PMMVAD Vad,
- IN PEPROCESS Process)
+ IN PMM_AVL_TABLE VadRoot)
{
TABLE_SEARCH_RESULT Result;
PMMADDRESS_NODE Parent = NULL;
/* Validate the VAD and set it as the current hint */
ASSERT(Vad->EndingVpn >= Vad->StartingVpn);
- Process->VadRoot.NodeHint = Vad;
+ VadRoot->NodeHint = Vad;
/* Find the parent VAD and where this child should be inserted */
- Result = RtlpFindAvlTableNodeOrParent(&Process->VadRoot,
(PVOID)Vad->StartingVpn, &Parent);
+ Result = RtlpFindAvlTableNodeOrParent(VadRoot, (PVOID)Vad->StartingVpn,
&Parent);
ASSERT(Result != TableFoundNode);
ASSERT((Parent != NULL) || (Result == TableEmptyTree));
/* Do the actual insert operation */
- MiLockProcessWorkingSetUnsafe(PsGetCurrentProcess(), PsGetCurrentThread());
- MiInsertNode(&Process->VadRoot, (PVOID)Vad, Parent, Result);
- MiUnlockProcessWorkingSetUnsafe(PsGetCurrentProcess(), PsGetCurrentThread());
+ MiInsertNode(VadRoot, (PVOID)Vad, Parent, Result);
}
NTSTATUS
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 23:36:42 2015
@@ -359,7 +359,7 @@
VOID
NTAPI
MiInsertVad(IN PMMVAD Vad,
- IN PEPROCESS Process);
+ IN PMM_AVL_TABLE VadRoot);
ULONG
NTAPI
@@ -367,6 +367,9 @@
IN ULONG Protect
);
+MM_AVL_TABLE MiRosKernelVadRoot;
+BOOLEAN MiRosKernelVadRootInitialized;
+
static VOID
MmInsertMemoryArea(
PMMSUPPORT AddressSpace,
@@ -377,23 +380,37 @@
ULONG Depth = 0;
PEPROCESS Process = MmGetAddressSpaceOwner(AddressSpace);
+ marea->VadNode.StartingVpn = marea->StartingVpn;
+ marea->VadNode.EndingVpn = marea->EndingVpn;
+ marea->VadNode.u.VadFlags.Spare = 1;
+ marea->VadNode.u.VadFlags.Protection = MiMakeProtectionMask(marea->Protect);
+
/* Build a lame VAD if this is a user-space allocation */
- if ((MA_GetEndingAddress(marea) < (ULONG_PTR)MmSystemRangeStart) &&
- (marea->Type != MEMORY_AREA_OWNED_BY_ARM3))
- {
- ASSERT(marea->Type == MEMORY_AREA_SECTION_VIEW || marea->Type ==
MEMORY_AREA_CACHE);
-
- marea->VadNode.StartingVpn = marea->StartingVpn;
- marea->VadNode.EndingVpn = marea->EndingVpn;
- marea->VadNode.u.VadFlags.Spare = 1;
- marea->VadNode.u.VadFlags.Protection =
MiMakeProtectionMask(marea->Protect);
+ if (MA_GetEndingAddress(marea) < (ULONG_PTR)MmSystemRangeStart)
+ {
+ if (marea->Type != MEMORY_AREA_OWNED_BY_ARM3)
+ {
+ ASSERT(marea->Type == MEMORY_AREA_SECTION_VIEW || marea->Type ==
MEMORY_AREA_CACHE);
+
+ /* Insert the VAD */
+ MiLockProcessWorkingSetUnsafe(PsGetCurrentProcess(), PsGetCurrentThread());
+ MiInsertVad(&marea->VadNode, &Process->VadRoot);
+ MiUnlockProcessWorkingSetUnsafe(PsGetCurrentProcess(),
PsGetCurrentThread());
+ marea->Vad = &marea->VadNode;
+ }
+ }
+ else
+ {
+ if (!MiRosKernelVadRootInitialized)
+ {
+ MiRosKernelVadRoot.BalancedRoot.u1.Parent =
&MiRosKernelVadRoot.BalancedRoot;
+ MiRosKernelVadRootInitialized = TRUE;
+ }
/* Insert the VAD */
- MiInsertVad(&marea->VadNode, Process);
- marea->Vad = &marea->VadNode;
- }
- else
- {
+ MiLockWorkingSet(PsGetCurrentThread(), &MmSystemCacheWs);
+ MiInsertVad(&marea->VadNode, &MiRosKernelVadRoot);
+ MiUnlockWorkingSet(PsGetCurrentThread(), &MmSystemCacheWs);
marea->Vad = NULL;
}
@@ -797,19 +814,24 @@
KeDetachProcess();
}
+ //if (MemoryArea->VadNode.StartingVpn < (ULONG_PTR)MmSystemRangeStart
>> PAGE_SHIFT
if (MemoryArea->Vad)
{
ASSERT(MA_GetEndingAddress(MemoryArea) < (ULONG_PTR)MmSystemRangeStart);
ASSERT(MemoryArea->Type == MEMORY_AREA_SECTION_VIEW || MemoryArea->Type
== MEMORY_AREA_CACHE);
/* MmCleanProcessAddressSpace might have removed it (and this would be
MmDeleteProcessAdressSpace) */
- ASSERT(((PMMVAD)MemoryArea->Vad)->u.VadFlags.Spare != 0);
+ ASSERT(MemoryArea->VadNode.u.VadFlags.Spare != 0);
if (((PMMVAD)MemoryArea->Vad)->u.VadFlags.Spare == 1)
{
- MiRemoveNode(MemoryArea->Vad, &Process->VadRoot);
+ MiRemoveNode((PMMADDRESS_NODE)&MemoryArea->VadNode,
&Process->VadRoot);
}
MemoryArea->Vad = NULL;
+ }
+ else
+ {
+ MiRemoveNode((PMMADDRESS_NODE)&MemoryArea->VadNode,
&MiRosKernelVadRoot);
}
}