[NTOS]: Delete deprecated handling of MEMORY_AREA_IO_MAPPING. Delete all MEMORY_AREA definitions except the ones for SEGMENT_VIEW and VIRTUAL_MEMORY. All other memory is now owned by ARM3!

[NTOS]: Delete WriteCopyView flag from MEMORY_AREA (unused, and was taking up 4 bytes due to alignment), and add a Vad pointer (takes up 4 bytes -- no actual size change).
[NTOS]: For VM and Section MEMORY_AREAs mapped in user-mode, build a "fake" VAD and insert it into the VAD Root of the Process. This means there is now a consistent view between ARM3 and RosMm in terms of user-mode address space layout, which will come in handy later.
[NTOS]: Destroy the MEMORY_AREA's VAD when the MEMORY_AREA itself is deleted. Watch out for the scenario explained in a previous check-in, where the VAD was caught by the MmCleanProcessAddressSpace vad-cleanup-loop.
[NTOS]: Implement MiInsertVad to restore the old functionality of MiInsertNode when the current parent and insertion result is not yet known. It obtains the information and calls MiInsertNode.

svn path=/trunk/; revision=48992
This commit is contained in:
Sir Richard 2010-10-05 05:07:13 +00:00
parent 4499f604f5
commit 121276a884
3 changed files with 78 additions and 33 deletions

View file

@ -76,20 +76,8 @@ typedef ULONG SWAPENTRY;
#define MI_STATIC_MEMORY_AREAS (13)
#endif
#define MEMORY_AREA_INVALID (0)
#define MEMORY_AREA_SECTION_VIEW (1)
#define MEMORY_AREA_CONTINUOUS_MEMORY (2)
#define MEMORY_AREA_NO_CACHE (3)
#define MEMORY_AREA_IO_MAPPING (4)
#define MEMORY_AREA_SYSTEM (5)
#define MEMORY_AREA_MDL_MAPPING (7)
#define MEMORY_AREA_VIRTUAL_MEMORY (8)
#define MEMORY_AREA_CACHE_SEGMENT (9)
#define MEMORY_AREA_SHARED_DATA (10)
#define MEMORY_AREA_KERNEL_STACK (11)
#define MEMORY_AREA_PAGED_POOL (12)
#define MEMORY_AREA_NO_ACCESS (13)
#define MEMORY_AREA_PEB_OR_TEB (14)
#define MEMORY_AREA_OWNED_BY_ARM3 (15)
#define MEMORY_AREA_STATIC (0x80000000)
@ -278,6 +266,7 @@ typedef struct _MEMORY_AREA
ULONG Flags;
BOOLEAN DeleteInProgress;
ULONG PageOpCount;
PVOID Vad;
union
{
struct
@ -285,7 +274,6 @@ typedef struct _MEMORY_AREA
ROS_SECTION_OBJECT* Section;
ULONG ViewOffset;
PMM_SECTION_SEGMENT Segment;
BOOLEAN WriteCopyView;
LIST_ENTRY RegionListHead;
} SectionData;
struct

View file

@ -93,16 +93,36 @@ MiCheckForConflictingNode(IN ULONG_PTR StartVpn,
VOID
NTAPI
MiInsertNode(
IN PMM_AVL_TABLE Table,
IN PMMADDRESS_NODE NewNode,
PMMADDRESS_NODE Parent,
TABLE_SEARCH_RESULT Result)
MiInsertNode(IN PMM_AVL_TABLE Table,
IN PMMADDRESS_NODE NewNode,
IN PMMADDRESS_NODE Parent,
IN TABLE_SEARCH_RESULT Result)
{
/* Insert it into the tree */
RtlpInsertAvlTreeNode(Table, NewNode, Parent, Result);
}
VOID
NTAPI
MiInsertVad(IN PMMVAD Vad,
IN PEPROCESS Process)
{
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;
/* Find the parent VAD and where this child should be inserted */
Result = RtlpFindAvlTableNodeOrParent(&Process->VadRoot, (PVOID)Vad->StartingVpn, &Parent);
ASSERT(Result != TableFoundNode);
ASSERT((Parent != NULL) || (Result == TableEmptyTree));
/* Do the actual insert operation */
MiInsertNode(&Process->VadRoot, (PVOID)Vad, Parent, Result);
}
VOID
NTAPI
MiRemoveNode(IN PMMADDRESS_NODE Node,
@ -163,13 +183,12 @@ MiGetPreviousNode(IN PMMADDRESS_NODE Node)
TABLE_SEARCH_RESULT
NTAPI
MiFindEmptyAddressRangeDownTree(
IN SIZE_T Length,
IN ULONG_PTR BoundaryAddress,
IN ULONG_PTR Alignment,
IN PMM_AVL_TABLE Table,
OUT PULONG_PTR Base,
OUT PMMADDRESS_NODE *Parent)
MiFindEmptyAddressRangeDownTree(IN SIZE_T Length,
IN ULONG_PTR BoundaryAddress,
IN ULONG_PTR Alignment,
IN PMM_AVL_TABLE Table,
OUT PULONG_PTR Base,
OUT PMMADDRESS_NODE *Parent)
{
PMMADDRESS_NODE Node, LowestNode, Child;
ULONG LowVpn, HighVpn;
@ -180,7 +199,7 @@ MiFindEmptyAddressRangeDownTree(
ASSERT(BoundaryAddress <= ((ULONG_PTR)MM_HIGHEST_VAD_ADDRESS + 1));
/* Compute page length, make sure the boundary address is valid */
Length = PAGE_ROUND_UP(Length);
Length = ROUND_TO_PAGES(Length);
PageCount = Length >> PAGE_SHIFT;
if ((BoundaryAddress + 1) < Length) return STATUS_NO_MEMORY;

View file

@ -407,6 +407,11 @@ MmRebalanceTree(
}
}
VOID
NTAPI
MiInsertVad(IN PMMVAD Vad,
IN PEPROCESS Process);
static VOID
MmInsertMemoryArea(
PMMSUPPORT AddressSpace,
@ -417,6 +422,26 @@ MmInsertMemoryArea(
ULONG Depth = 0;
MmVerifyMemoryAreas(AddressSpace);
/* Build a lame VAD if this is a user-space allocation */
if ((marea->EndingAddress < MmSystemRangeStart) && (marea->Type != MEMORY_AREA_OWNED_BY_ARM3))
{
ASSERT(marea->Type == MEMORY_AREA_VIRTUAL_MEMORY || marea->Type == MEMORY_AREA_SECTION_VIEW);
PMMVAD Vad;
Vad = ExAllocatePoolWithTag(NonPagedPool, sizeof(MMVAD), 'Fake');
ASSERT(Vad);
RtlZeroMemory(Vad, sizeof(MMVAD));
Vad->StartingVpn = PAGE_ROUND_DOWN(marea->StartingAddress) >> PAGE_SHIFT;
Vad->EndingVpn = PAGE_ROUND_DOWN((ULONG_PTR)marea->EndingAddress - 1) >> PAGE_SHIFT;
Vad->u.VadFlags.Spare = 1;
Vad->u.VadFlags.PrivateMemory = 1;
MiInsertVad(Vad, MmGetAddressSpaceOwner(AddressSpace));
marea->Vad = Vad;
}
else
{
marea->Vad = NULL;
}
if (AddressSpace->WorkingSetExpansionLinks.Flink == NULL)
{
@ -702,6 +727,10 @@ MmFindGapAtAddress(
}
}
VOID
NTAPI
MiRemoveNode(IN PMMADDRESS_NODE Node,
IN PMM_AVL_TABLE Table);
/**
* @name MmFreeMemoryArea
@ -749,12 +778,6 @@ MmFreeMemoryArea(
Address < (ULONG_PTR)EndAddress;
Address += PAGE_SIZE)
{
if (MemoryArea->Type == MEMORY_AREA_IO_MAPPING)
{
MmRawDeleteVirtualMapping((PVOID)Address);
}
else
{
BOOLEAN Dirty = FALSE;
SWAPENTRY SwapEntry = 0;
PFN_NUMBER Page = 0;
@ -772,7 +795,6 @@ MmFreeMemoryArea(
FreePage(FreePageContext, MemoryArea, (PVOID)Address,
Page, SwapEntry, (BOOLEAN)Dirty);
}
}
}
if (Process != NULL &&
@ -780,6 +802,22 @@ MmFreeMemoryArea(
{
KeDetachProcess();
}
if (MemoryArea->Vad)
{
ASSERT(MemoryArea->EndingAddress < MmSystemRangeStart);
ASSERT(MemoryArea->Type == MEMORY_AREA_VIRTUAL_MEMORY || MemoryArea->Type == MEMORY_AREA_SECTION_VIEW);
/* MmCleanProcessAddressSpace might have removed it (and this would be MmDeleteProcessAdressSpace) */
ASSERT(((PMMVAD)MemoryArea->Vad)->u.VadFlags.Spare != 0);
if (((PMMVAD)MemoryArea->Vad)->u.VadFlags.Spare == 1)
{
MiRemoveNode(MemoryArea->Vad, &Process->VadRoot);
}
ExFreePool(MemoryArea->Vad);
MemoryArea->Vad = NULL;
}
}
/* Remove the tree item. */