Author: sir_richard Date: Tue Oct 5 05:07:13 2010 New Revision: 48992
URL: http://svn.reactos.org/svn/reactos?rev=48992&view=rev Log: [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.
Modified: trunk/reactos/ntoskrnl/include/internal/mm.h trunk/reactos/ntoskrnl/mm/ARM3/vadnode.c trunk/reactos/ntoskrnl/mm/marea.c
Modified: trunk/reactos/ntoskrnl/include/internal/mm.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/m... ============================================================================== --- trunk/reactos/ntoskrnl/include/internal/mm.h [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/include/internal/mm.h [iso-8859-1] Tue Oct 5 05:07:13 2010 @@ -76,20 +76,8 @@ #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 @@ ULONG Flags; BOOLEAN DeleteInProgress; ULONG PageOpCount; + PVOID Vad; union { struct @@ -285,7 +274,6 @@ ROS_SECTION_OBJECT* Section; ULONG ViewOffset; PMM_SECTION_SEGMENT Segment; - BOOLEAN WriteCopyView; LIST_ENTRY RegionListHead; } SectionData; struct
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] Tue Oct 5 05:07:13 2010 @@ -93,14 +93,34 @@
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 @@ -163,13 +183,12 @@
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 @@ 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;
Modified: trunk/reactos/ntoskrnl/mm/marea.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/marea.c?rev=489... ============================================================================== --- trunk/reactos/ntoskrnl/mm/marea.c [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/mm/marea.c [iso-8859-1] Tue Oct 5 05:07:13 2010 @@ -407,6 +407,11 @@ } }
+VOID +NTAPI +MiInsertVad(IN PMMVAD Vad, +IN PEPROCESS Process); + static VOID MmInsertMemoryArea( PMMSUPPORT AddressSpace, @@ -417,6 +422,26 @@ 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 @@ } }
+VOID +NTAPI +MiRemoveNode(IN PMMADDRESS_NODE Node, +IN PMM_AVL_TABLE Table);
/** * @name MmFreeMemoryArea @@ -749,12 +778,6 @@ 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,13 +795,28 @@ FreePage(FreePageContext, MemoryArea, (PVOID)Address, Page, SwapEntry, (BOOLEAN)Dirty); } - } }
if (Process != NULL && Process != CurrentProcess) { 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; } }