Now that MADDRESS_SPACE became nearly an empty structure pointing only at the root, it can completely go away. Now VadRoot really is a MM_AVL_TABLE structure.

The BalancedRoot.u1.Parent now points to what used to be MemoryAreaRoot. This isn't really the most proper fix out there -- the problem is that React starts with an no root, while Windows
starts with an empty balanced root. So for now we keep doing it the React way, which means we have about 10 ugly typecast hacks. On the other hand, we got rid of more than 100 of them.


svn path=/trunk/; revision=34881
This commit is contained in:
ReactOS Portable Systems Group 2008-07-28 01:49:23 +00:00
parent 7c1492c712
commit a5a0461289
12 changed files with 133 additions and 173 deletions

View file

@ -250,11 +250,6 @@ typedef struct _MEMORY_AREA
} Data;
} MEMORY_AREA, *PMEMORY_AREA;
typedef struct _MADDRESS_SPACE
{
PMEMORY_AREA MemoryAreaRoot;
} MADDRESS_SPACE, *PMADDRESS_SPACE;
typedef struct
{
ULONG NrTotalPages;
@ -367,7 +362,7 @@ extern MM_MEMORY_CONSUMER MiMemoryConsumers[MC_MAXIMUM];
typedef VOID
(*PMM_ALTER_REGION_FUNC)(
PMADDRESS_SPACE AddressSpace,
PMM_AVL_TABLE AddressSpace,
PVOID BaseAddress,
ULONG Length,
ULONG OldType,
@ -386,22 +381,6 @@ typedef VOID
BOOLEAN Dirty
);
/* aspace.c ******************************************************************/
VOID
NTAPI
MmInitializeKernelAddressSpace(VOID);
NTSTATUS
NTAPI
MmInitializeAddressSpace(
struct _EPROCESS* Process,
PMADDRESS_SPACE AddressSpace);
NTSTATUS
NTAPI
MmDestroyAddressSpace(PMADDRESS_SPACE AddressSpace);
/* marea.c *******************************************************************/
NTSTATUS
@ -411,7 +390,7 @@ MmInitMemoryAreas(VOID);
NTSTATUS
NTAPI
MmCreateMemoryArea(
PMADDRESS_SPACE AddressSpace,
PMM_AVL_TABLE AddressSpace,
ULONG Type,
PVOID *BaseAddress,
ULONG_PTR Length,
@ -425,21 +404,21 @@ MmCreateMemoryArea(
PMEMORY_AREA
NTAPI
MmLocateMemoryAreaByAddress(
PMADDRESS_SPACE AddressSpace,
PMM_AVL_TABLE AddressSpace,
PVOID Address
);
ULONG_PTR
NTAPI
MmFindGapAtAddress(
PMADDRESS_SPACE AddressSpace,
PMM_AVL_TABLE AddressSpace,
PVOID Address
);
NTSTATUS
NTAPI
MmFreeMemoryArea(
PMADDRESS_SPACE AddressSpace,
PMM_AVL_TABLE AddressSpace,
PMEMORY_AREA MemoryArea,
PMM_FREE_PAGE_FUNC FreePage,
PVOID FreePageContext
@ -448,7 +427,7 @@ MmFreeMemoryArea(
NTSTATUS
NTAPI
MmFreeMemoryAreaByPtr(
PMADDRESS_SPACE AddressSpace,
PMM_AVL_TABLE AddressSpace,
PVOID BaseAddress,
PMM_FREE_PAGE_FUNC FreePage,
PVOID FreePageContext
@ -456,12 +435,12 @@ MmFreeMemoryAreaByPtr(
VOID
NTAPI
MmDumpMemoryAreas(PMADDRESS_SPACE AddressSpace);
MmDumpMemoryAreas(PMM_AVL_TABLE AddressSpace);
PMEMORY_AREA
NTAPI
MmLocateMemoryAreaByRegion(
PMADDRESS_SPACE AddressSpace,
PMM_AVL_TABLE AddressSpace,
PVOID Address,
ULONG_PTR Length
);
@ -469,7 +448,7 @@ MmLocateMemoryAreaByRegion(
PVOID
NTAPI
MmFindGap(
PMADDRESS_SPACE AddressSpace,
PMM_AVL_TABLE AddressSpace,
ULONG_PTR Length,
ULONG_PTR Granularity,
BOOLEAN TopDown
@ -479,7 +458,7 @@ VOID
NTAPI
MmReleaseMemoryAreaIfDecommitted(
struct _EPROCESS *Process,
PMADDRESS_SPACE AddressSpace,
PMM_AVL_TABLE AddressSpace,
PVOID BaseAddress
);
@ -745,7 +724,7 @@ MmAccessFault(
NTSTATUS
NTAPI
MmNotPresentFaultVirtualMemory(
PMADDRESS_SPACE AddressSpace,
PMM_AVL_TABLE AddressSpace,
MEMORY_AREA* MemoryArea,
PVOID Address,
BOOLEAN Locked
@ -754,7 +733,7 @@ MmNotPresentFaultVirtualMemory(
NTSTATUS
NTAPI
MmPageOutVirtualMemory(
PMADDRESS_SPACE AddressSpace,
PMM_AVL_TABLE AddressSpace,
PMEMORY_AREA MemoryArea,
PVOID Address,
struct _MM_PAGEOP* PageOp
@ -779,7 +758,7 @@ MmFreeVirtualMemory(
NTSTATUS
NTAPI
MmProtectAnonMem(
PMADDRESS_SPACE AddressSpace,
PMM_AVL_TABLE AddressSpace,
PMEMORY_AREA MemoryArea,
PVOID BaseAddress,
ULONG Length,
@ -790,7 +769,7 @@ MmProtectAnonMem(
NTSTATUS
NTAPI
MmWritePageVirtualMemory(
PMADDRESS_SPACE AddressSpace,
PMM_AVL_TABLE AddressSpace,
PMEMORY_AREA MArea,
PVOID Address,
PMM_PAGEOP PageOp
@ -1360,7 +1339,7 @@ MmTrimUserMemory(
NTSTATUS
NTAPI
MmAlterRegion(
PMADDRESS_SPACE AddressSpace,
PMM_AVL_TABLE AddressSpace,
PVOID BaseAddress,
PLIST_ENTRY RegionListHead,
PVOID StartAddress,
@ -1428,7 +1407,7 @@ MmQuerySectionView(
NTSTATUS
NTAPI
MmProtectSectionView(
PMADDRESS_SPACE AddressSpace,
PMM_AVL_TABLE AddressSpace,
PMEMORY_AREA MemoryArea,
PVOID BaseAddress,
ULONG Length,
@ -1439,7 +1418,7 @@ MmProtectSectionView(
NTSTATUS
NTAPI
MmWritePageSectionView(
PMADDRESS_SPACE AddressSpace,
PMM_AVL_TABLE AddressSpace,
PMEMORY_AREA MArea,
PVOID Address,
PMM_PAGEOP PageOp
@ -1452,7 +1431,7 @@ MmInitSectionImplementation(VOID);
NTSTATUS
NTAPI
MmNotPresentFaultSectionView(
PMADDRESS_SPACE AddressSpace,
PMM_AVL_TABLE AddressSpace,
MEMORY_AREA* MemoryArea,
PVOID Address,
BOOLEAN Locked
@ -1461,7 +1440,7 @@ MmNotPresentFaultSectionView(
NTSTATUS
NTAPI
MmPageOutSectionView(
PMADDRESS_SPACE AddressSpace,
PMM_AVL_TABLE AddressSpace,
PMEMORY_AREA MemoryArea,
PVOID Address,
struct _MM_PAGEOP *PageOp
@ -1474,7 +1453,7 @@ MmCreatePhysicalMemorySection(VOID);
NTSTATUS
NTAPI
MmAccessFaultSectionView(
PMADDRESS_SPACE AddressSpace,
PMM_AVL_TABLE AddressSpace,
MEMORY_AREA* MemoryArea,
PVOID Address,
BOOLEAN Locked
@ -1568,39 +1547,39 @@ MiSyncThreadProcessViews(IN PVOID Process,
}
extern PMADDRESS_SPACE MmKernelAddressSpace;
extern PMM_AVL_TABLE MmKernelAddressSpace;
FORCEINLINE
VOID
MmLockAddressSpace(PMADDRESS_SPACE AddressSpace)
MmLockAddressSpace(PMM_AVL_TABLE AddressSpace)
{
KeAcquireGuardedMutex(&CONTAINING_RECORD(AddressSpace, EPROCESS, VadRoot)->AddressCreationLock);
}
FORCEINLINE
VOID
MmUnlockAddressSpace(PMADDRESS_SPACE AddressSpace)
MmUnlockAddressSpace(PMM_AVL_TABLE AddressSpace)
{
KeReleaseGuardedMutex(&CONTAINING_RECORD(AddressSpace, EPROCESS, VadRoot)->AddressCreationLock);
}
FORCEINLINE
PEPROCESS
MmGetAddressSpaceOwner(IN PMADDRESS_SPACE AddressSpace)
MmGetAddressSpaceOwner(IN PMM_AVL_TABLE AddressSpace)
{
if (AddressSpace == MmKernelAddressSpace) return NULL;
return CONTAINING_RECORD(AddressSpace, EPROCESS, VadRoot);
}
FORCEINLINE
PMADDRESS_SPACE
PMM_AVL_TABLE
MmGetCurrentAddressSpace(VOID)
{
return (PMADDRESS_SPACE)&((PEPROCESS)KeGetCurrentThread()->ApcState.Process)->VadRoot;
return &((PEPROCESS)KeGetCurrentThread()->ApcState.Process)->VadRoot;
}
FORCEINLINE
PMADDRESS_SPACE
PMM_AVL_TABLE
MmGetKernelAddressSpace(VOID)
{
return MmKernelAddressSpace;

View file

@ -47,7 +47,7 @@
NTSTATUS
NTAPI
MmWritePageVirtualMemory(PMADDRESS_SPACE AddressSpace,
MmWritePageVirtualMemory(PMM_AVL_TABLE AddressSpace,
PMEMORY_AREA MemoryArea,
PVOID Address,
PMM_PAGEOP PageOp)
@ -130,7 +130,7 @@ MmWritePageVirtualMemory(PMADDRESS_SPACE AddressSpace,
NTSTATUS
NTAPI
MmPageOutVirtualMemory(PMADDRESS_SPACE AddressSpace,
MmPageOutVirtualMemory(PMM_AVL_TABLE AddressSpace,
PMEMORY_AREA MemoryArea,
PVOID Address,
PMM_PAGEOP PageOp)
@ -239,7 +239,7 @@ MmPageOutVirtualMemory(PMADDRESS_SPACE AddressSpace,
NTSTATUS
NTAPI
MmNotPresentFaultVirtualMemory(PMADDRESS_SPACE AddressSpace,
MmNotPresentFaultVirtualMemory(PMM_AVL_TABLE AddressSpace,
MEMORY_AREA* MemoryArea,
PVOID Address,
BOOLEAN Locked)
@ -437,7 +437,7 @@ MmNotPresentFaultVirtualMemory(PMADDRESS_SPACE AddressSpace,
}
VOID static
MmModifyAttributes(PMADDRESS_SPACE AddressSpace,
MmModifyAttributes(PMM_AVL_TABLE AddressSpace,
PVOID BaseAddress,
ULONG RegionSize,
ULONG OldType,
@ -553,7 +553,7 @@ NtAllocateVirtualMemory(IN HANDLE ProcessHandle,
ULONG_PTR MemoryAreaLength;
ULONG Type;
NTSTATUS Status;
PMADDRESS_SPACE AddressSpace;
PMM_AVL_TABLE AddressSpace;
PVOID BaseAddress;
ULONG RegionSize;
PVOID PBaseAddress;
@ -704,7 +704,7 @@ NtAllocateVirtualMemory(IN HANDLE ProcessHandle,
Type = (AllocationType & MEM_COMMIT) ? MEM_COMMIT : MEM_RESERVE;
DPRINT("Type %x\n", Type);
AddressSpace = (PMADDRESS_SPACE)&Process->VadRoot;
AddressSpace = &Process->VadRoot;
MmLockAddressSpace(AddressSpace);
if (PBaseAddress != 0)
@ -861,7 +861,7 @@ MmFreeVirtualMemory(PEPROCESS Process,
if (PageOp != NULL)
{
NTSTATUS Status;
MmUnlockAddressSpace((PMADDRESS_SPACE)&Process->VadRoot);
MmUnlockAddressSpace(&Process->VadRoot);
Status = KeWaitForSingleObject(&PageOp->CompletionEvent,
0,
KernelMode,
@ -872,7 +872,7 @@ MmFreeVirtualMemory(PEPROCESS Process,
DPRINT1("Failed to wait for page op\n");
KEBUGCHECK(0);
}
MmLockAddressSpace((PMADDRESS_SPACE)&Process->VadRoot);
MmLockAddressSpace(&Process->VadRoot);
MmReleasePageOp(PageOp);
}
}
@ -888,7 +888,7 @@ MmFreeVirtualMemory(PEPROCESS Process,
}
/* Actually free the memory area. */
MmFreeMemoryArea((PMADDRESS_SPACE)&Process->VadRoot,
MmFreeMemoryArea(&Process->VadRoot,
MemoryArea,
MmFreeVirtualMemoryPage,
(PVOID)Process);
@ -918,7 +918,7 @@ NtFreeVirtualMemory(IN HANDLE ProcessHandle,
MEMORY_AREA* MemoryArea;
NTSTATUS Status;
PEPROCESS Process;
PMADDRESS_SPACE AddressSpace;
PMM_AVL_TABLE AddressSpace;
PVOID BaseAddress;
ULONG RegionSize;
@ -941,7 +941,7 @@ NtFreeVirtualMemory(IN HANDLE ProcessHandle,
return(Status);
}
AddressSpace = (PMADDRESS_SPACE)&Process->VadRoot;
AddressSpace = &Process->VadRoot;
MmLockAddressSpace(AddressSpace);
MemoryArea = MmLocateMemoryAreaByAddress(AddressSpace, BaseAddress);
@ -991,7 +991,7 @@ unlock_deref_and_return:
NTSTATUS
NTAPI
MmProtectAnonMem(PMADDRESS_SPACE AddressSpace,
MmProtectAnonMem(PMM_AVL_TABLE AddressSpace,
PMEMORY_AREA MemoryArea,
PVOID BaseAddress,
ULONG Length,

View file

@ -19,27 +19,9 @@
/* GLOBALS ******************************************************************/
PMADDRESS_SPACE MmKernelAddressSpace;
ULONGLONG Cycles;
ULONG TimeDelta;
PMM_AVL_TABLE MmKernelAddressSpace;
/* FUNCTIONS *****************************************************************/
NTSTATUS
NTAPI
MmInitializeAddressSpace(PEPROCESS Process,
PMADDRESS_SPACE AddressSpace)
{
AddressSpace->MemoryAreaRoot = NULL;
return STATUS_SUCCESS;
}
NTSTATUS
NTAPI
MmDestroyAddressSpace(PMADDRESS_SPACE AddressSpace)
{
return STATUS_SUCCESS;
}
/* EOF */

View file

@ -197,7 +197,7 @@ MmInitializeHandBuiltProcess(IN PEPROCESS Process,
/* Initialize the Addresss Space */
KeInitializeGuardedMutex(&Process->AddressCreationLock);
MmInitializeAddressSpace(Process, (PMADDRESS_SPACE)&Process->VadRoot);
Process->VadRoot.BalancedRoot.u1.Parent = NULL;
/* The process now has an address space */
Process->HasAddressSpace = TRUE;

View file

@ -160,18 +160,18 @@ static PMEMORY_AREA MmIteratePrevNode(PMEMORY_AREA Node)
}
#ifdef VALIDATE_MEMORY_AREAS
static VOID MmVerifyMemoryAreas(PMADDRESS_SPACE AddressSpace)
static VOID MmVerifyMemoryAreas(PMM_AVL_TABLE AddressSpace)
{
PMEMORY_AREA Node;
ASSERT(AddressSpace != NULL);
/* Special case for empty tree. */
if (AddressSpace->MemoryAreaRoot == NULL)
if (AddressSpace->BalancedRoot.u1.Parent == NULL)
return;
/* Traverse the tree from left to right. */
for (Node = MmIterateFirstNode(AddressSpace->MemoryAreaRoot);
for (Node = MmIterateFirstNode(AddressSpace->BalancedRoot.u1.Parent);
Node != NULL;
Node = MmIterateNextNode(Node))
{
@ -186,18 +186,18 @@ static VOID MmVerifyMemoryAreas(PMADDRESS_SPACE AddressSpace)
#endif
VOID STDCALL
MmDumpMemoryAreas(PMADDRESS_SPACE AddressSpace)
MmDumpMemoryAreas(PMM_AVL_TABLE AddressSpace)
{
PMEMORY_AREA Node;
DbgPrint("MmDumpMemoryAreas()\n");
/* Special case for empty tree. */
if (AddressSpace->MemoryAreaRoot == NULL)
if (AddressSpace->BalancedRoot.u1.Parent == NULL)
return;
/* Traverse the tree from left to right. */
for (Node = MmIterateFirstNode(AddressSpace->MemoryAreaRoot);
for (Node = MmIterateFirstNode((PMEMORY_AREA)AddressSpace->BalancedRoot.u1.Parent);
Node != NULL;
Node = MmIterateNextNode(Node))
{
@ -211,10 +211,10 @@ MmDumpMemoryAreas(PMADDRESS_SPACE AddressSpace)
PMEMORY_AREA STDCALL
MmLocateMemoryAreaByAddress(
PMADDRESS_SPACE AddressSpace,
PMM_AVL_TABLE AddressSpace,
PVOID Address)
{
PMEMORY_AREA Node = AddressSpace->MemoryAreaRoot;
PMEMORY_AREA Node = (PMEMORY_AREA)AddressSpace->BalancedRoot.u1.Parent;
DPRINT("MmLocateMemoryAreaByAddress(AddressSpace %p, Address %p)\n",
AddressSpace, Address);
@ -241,7 +241,7 @@ MmLocateMemoryAreaByAddress(
PMEMORY_AREA STDCALL
MmLocateMemoryAreaByRegion(
PMADDRESS_SPACE AddressSpace,
PMM_AVL_TABLE AddressSpace,
PVOID Address,
ULONG_PTR Length)
{
@ -251,11 +251,11 @@ MmLocateMemoryAreaByRegion(
MmVerifyMemoryAreas(AddressSpace);
/* Special case for empty tree. */
if (AddressSpace->MemoryAreaRoot == NULL)
if (AddressSpace->BalancedRoot.u1.Parent == NULL)
return NULL;
/* Traverse the tree from left to right. */
for (Node = MmIterateFirstNode(AddressSpace->MemoryAreaRoot);
for (Node = MmIterateFirstNode((PMEMORY_AREA)AddressSpace->BalancedRoot.u1.Parent);
Node != NULL;
Node = MmIterateNextNode(Node))
{
@ -302,11 +302,11 @@ MmLocateMemoryAreaByRegion(
static VOID
MmCompressHelper(
PMADDRESS_SPACE AddressSpace,
PMM_AVL_TABLE AddressSpace,
ULONG Count)
{
PMEMORY_AREA Root = NULL;
PMEMORY_AREA Red = AddressSpace->MemoryAreaRoot;
PMEMORY_AREA Red = (PMEMORY_AREA)AddressSpace->BalancedRoot.u1.Parent;
PMEMORY_AREA Black = Red->LeftChild;
while (Count--)
@ -314,7 +314,7 @@ MmCompressHelper(
if (Root)
Root->LeftChild = Black;
else
AddressSpace->MemoryAreaRoot = Black;
AddressSpace->BalancedRoot.u1.Parent = (PVOID)Black;
Black->Parent = Root;
Red->LeftChild = Black->RightChild;
if (Black->RightChild)
@ -341,7 +341,7 @@ MmCompressHelper(
static VOID
MmRebalanceTree(
PMADDRESS_SPACE AddressSpace)
PMM_AVL_TABLE AddressSpace)
{
PMEMORY_AREA PreviousNode;
PMEMORY_AREA CurrentNode;
@ -354,7 +354,7 @@ MmRebalanceTree(
/* Transform the tree into Vine. */
PreviousNode = NULL;
CurrentNode = AddressSpace->MemoryAreaRoot;
CurrentNode = (PMEMORY_AREA)AddressSpace->BalancedRoot.u1.Parent;
while (CurrentNode != NULL)
{
if (CurrentNode->RightChild == NULL)
@ -379,7 +379,7 @@ MmRebalanceTree(
if (PreviousNode != NULL)
PreviousNode->LeftChild = TempNode;
else
AddressSpace->MemoryAreaRoot = TempNode;
AddressSpace->BalancedRoot.u1.Parent = (PVOID)TempNode;
TempNode->Parent = PreviousNode;
}
}
@ -410,7 +410,7 @@ MmRebalanceTree(
static VOID
MmInsertMemoryArea(
PMADDRESS_SPACE AddressSpace,
PMM_AVL_TABLE AddressSpace,
PMEMORY_AREA marea)
{
PMEMORY_AREA Node;
@ -419,14 +419,14 @@ MmInsertMemoryArea(
MmVerifyMemoryAreas(AddressSpace);
if (AddressSpace->MemoryAreaRoot == NULL)
if (AddressSpace->BalancedRoot.u1.Parent == NULL)
{
AddressSpace->MemoryAreaRoot = marea;
AddressSpace->BalancedRoot.u1.Parent = (PVOID)marea;
marea->LeftChild = marea->RightChild = marea->Parent = NULL;
return;
}
Node = AddressSpace->MemoryAreaRoot;
Node = (PMEMORY_AREA)AddressSpace->BalancedRoot.u1.Parent;
do
{
DPRINT("marea->EndingAddress: %p Node->StartingAddress: %p\n",
@ -466,7 +466,7 @@ MmInsertMemoryArea(
static PVOID
MmFindGapBottomUp(
PMADDRESS_SPACE AddressSpace,
PMM_AVL_TABLE AddressSpace,
ULONG_PTR Length,
ULONG_PTR Granularity)
{
@ -486,7 +486,7 @@ MmFindGapBottomUp(
AlignedAddress = MM_ROUND_UP(LowestAddress, Granularity);
/* Special case for empty tree. */
if (AddressSpace->MemoryAreaRoot == NULL)
if (AddressSpace->BalancedRoot.u1.Parent == NULL)
{
if ((ULONG_PTR)HighestAddress - (ULONG_PTR)AlignedAddress >= Length)
{
@ -498,7 +498,7 @@ MmFindGapBottomUp(
}
/* Go to the node with lowest address in the tree. */
FirstNode = Node = MmIterateFirstNode(AddressSpace->MemoryAreaRoot);
FirstNode = Node = MmIterateFirstNode((PMEMORY_AREA)AddressSpace->BalancedRoot.u1.Parent);
/* Traverse the tree from left to right. */
PreviousNode = Node;
@ -544,7 +544,7 @@ MmFindGapBottomUp(
static PVOID
MmFindGapTopDown(
PMADDRESS_SPACE AddressSpace,
PMM_AVL_TABLE AddressSpace,
ULONG_PTR Length,
ULONG_PTR Granularity)
{
@ -567,7 +567,7 @@ MmFindGapTopDown(
return NULL;
/* Special case for empty tree. */
if (AddressSpace->MemoryAreaRoot == NULL)
if (AddressSpace->BalancedRoot.u1.Parent == NULL)
{
if (AlignedAddress >= LowestAddress)
{
@ -579,7 +579,7 @@ MmFindGapTopDown(
}
/* Go to the node with highest address in the tree. */
Node = MmIterateLastNode(AddressSpace->MemoryAreaRoot);
Node = MmIterateLastNode((PMEMORY_AREA)AddressSpace->BalancedRoot.u1.Parent);
/* Check if there is enough space after the last memory area. */
if (Node->EndingAddress <= AlignedAddress)
@ -630,7 +630,7 @@ MmFindGapTopDown(
PVOID STDCALL
MmFindGap(
PMADDRESS_SPACE AddressSpace,
PMM_AVL_TABLE AddressSpace,
ULONG_PTR Length,
ULONG_PTR Granularity,
BOOLEAN TopDown)
@ -643,10 +643,10 @@ MmFindGap(
ULONG_PTR STDCALL
MmFindGapAtAddress(
PMADDRESS_SPACE AddressSpace,
PMM_AVL_TABLE AddressSpace,
PVOID Address)
{
PMEMORY_AREA Node = AddressSpace->MemoryAreaRoot;
PMEMORY_AREA Node = (PMEMORY_AREA)AddressSpace->BalancedRoot.u1.Parent;
PMEMORY_AREA RightNeighbour = NULL;
PVOID LowestAddress = MmGetAddressSpaceOwner(AddressSpace) ? MM_LOWEST_USER_ADDRESS : MmSystemRangeStart;
PVOID HighestAddress = MmGetAddressSpaceOwner(AddressSpace) ?
@ -740,7 +740,7 @@ MmInitMemoryAreas(VOID)
NTSTATUS STDCALL
MmFreeMemoryArea(
PMADDRESS_SPACE AddressSpace,
PMM_AVL_TABLE AddressSpace,
PMEMORY_AREA MemoryArea,
PMM_FREE_PAGE_FUNC FreePage,
PVOID FreePageContext)
@ -804,7 +804,7 @@ MmFreeMemoryArea(
ParentReplace = &MemoryArea->Parent->RightChild;
}
else
ParentReplace = &AddressSpace->MemoryAreaRoot;
ParentReplace = (PMEMORY_AREA*)&AddressSpace->BalancedRoot.u1.Parent;
if (MemoryArea->RightChild == NULL)
{
@ -882,7 +882,7 @@ MmFreeMemoryArea(
NTSTATUS STDCALL
MmFreeMemoryAreaByPtr(
PMADDRESS_SPACE AddressSpace,
PMM_AVL_TABLE AddressSpace,
PVOID BaseAddress,
PMM_FREE_PAGE_FUNC FreePage,
PVOID FreePageContext)
@ -933,7 +933,7 @@ MmFreeMemoryAreaByPtr(
*/
NTSTATUS STDCALL
MmCreateMemoryArea(PMADDRESS_SPACE AddressSpace,
MmCreateMemoryArea(PMM_AVL_TABLE AddressSpace,
ULONG Type,
PVOID *BaseAddress,
ULONG_PTR Length,
@ -1059,7 +1059,7 @@ MmMapMemoryArea(PVOID BaseAddress,
VOID STDCALL
MmReleaseMemoryAreaIfDecommitted(PEPROCESS Process,
PMADDRESS_SPACE AddressSpace,
PMM_AVL_TABLE AddressSpace,
PVOID BaseAddress)
{
PMEMORY_AREA MemoryArea;

View file

@ -366,12 +366,12 @@ MmUnmapLockedPages(IN PVOID BaseAddress,
ASSERT(Mdl->Process == PsGetCurrentProcess());
/* Find the memory area */
MemoryArea = MmLocateMemoryAreaByAddress((PMADDRESS_SPACE)&(Mdl->Process)->VadRoot,
MemoryArea = MmLocateMemoryAreaByAddress(&Mdl->Process->VadRoot,
BaseAddress);
ASSERT(MemoryArea);
/* Free it */
MmFreeMemoryArea((PMADDRESS_SPACE)&(Mdl->Process)->VadRoot,
MmFreeMemoryArea(&Mdl->Process->VadRoot,
MemoryArea,
NULL,
NULL);
@ -395,7 +395,7 @@ MmProbeAndLockPages(IN PMDL Mdl,
PFN_TYPE Page;
PEPROCESS CurrentProcess;
PETHREAD Thread;
PMADDRESS_SPACE AddressSpace;
PMM_AVL_TABLE AddressSpace;
DPRINT("Probing MDL: %p\n", Mdl);
/* Sanity checks */
@ -479,7 +479,7 @@ MmProbeAndLockPages(IN PMDL Mdl,
Mdl->Process = CurrentProcess;
/* Use the process lock */
AddressSpace = (PMADDRESS_SPACE)&(CurrentProcess)->VadRoot;
AddressSpace = &CurrentProcess->VadRoot;
}
@ -732,8 +732,8 @@ MmMapLockedPagesSpecifyCache(IN PMDL Mdl,
CurrentProcess = PsGetCurrentProcess();
MmLockAddressSpace((PMADDRESS_SPACE)&CurrentProcess->VadRoot);
Status = MmCreateMemoryArea((PMADDRESS_SPACE)&CurrentProcess->VadRoot,
MmLockAddressSpace(&CurrentProcess->VadRoot);
Status = MmCreateMemoryArea(&CurrentProcess->VadRoot,
MEMORY_AREA_MDL_MAPPING,
&Base,
PageCount * PAGE_SIZE,
@ -742,7 +742,7 @@ MmMapLockedPagesSpecifyCache(IN PMDL Mdl,
(Base != NULL),
0,
BoundaryAddressMultiple);
MmUnlockAddressSpace((PMADDRESS_SPACE)&CurrentProcess->VadRoot);
MmUnlockAddressSpace(&CurrentProcess->VadRoot);
if (!NT_SUCCESS(Status))
{
if (Mdl->MdlFlags & MDL_MAPPING_CAN_FAIL)

View file

@ -48,7 +48,7 @@ BOOLEAN NTAPI MmIsAddressValid(PVOID VirtualAddress)
*/
{
MEMORY_AREA* MemoryArea;
PMADDRESS_SPACE AddressSpace;
PMM_AVL_TABLE AddressSpace;
if (VirtualAddress >= MmSystemRangeStart)
{
@ -56,7 +56,7 @@ BOOLEAN NTAPI MmIsAddressValid(PVOID VirtualAddress)
}
else
{
AddressSpace = (PMADDRESS_SPACE)&(PsGetCurrentProcess())->VadRoot;
AddressSpace = &PsGetCurrentProcess()->VadRoot;
}
MmLockAddressSpace(AddressSpace);
@ -78,7 +78,7 @@ MmpAccessFault(KPROCESSOR_MODE Mode,
ULONG_PTR Address,
BOOLEAN FromMdl)
{
PMADDRESS_SPACE AddressSpace;
PMM_AVL_TABLE AddressSpace;
MEMORY_AREA* MemoryArea;
NTSTATUS Status;
BOOLEAN Locked = FromMdl;
@ -114,7 +114,7 @@ MmpAccessFault(KPROCESSOR_MODE Mode,
}
else
{
AddressSpace = (PMADDRESS_SPACE)&(PsGetCurrentProcess())->VadRoot;
AddressSpace = &PsGetCurrentProcess()->VadRoot;
}
if (!FromMdl)
@ -179,7 +179,7 @@ MmNotPresentFault(KPROCESSOR_MODE Mode,
ULONG_PTR Address,
BOOLEAN FromMdl)
{
PMADDRESS_SPACE AddressSpace;
PMM_AVL_TABLE AddressSpace;
MEMORY_AREA* MemoryArea;
NTSTATUS Status;
BOOLEAN Locked = FromMdl;
@ -210,7 +210,7 @@ MmNotPresentFault(KPROCESSOR_MODE Mode,
}
else
{
AddressSpace = (PMADDRESS_SPACE)&(PsGetCurrentProcess())->VadRoot;
AddressSpace = &PsGetCurrentProcess()->VadRoot;
}
if (!FromMdl)

View file

@ -80,7 +80,7 @@ MiCreatePebOrTeb(PEPROCESS Process,
PVOID BaseAddress)
{
NTSTATUS Status;
PMADDRESS_SPACE ProcessAddressSpace = (PMADDRESS_SPACE)&Process->VadRoot;
PMM_AVL_TABLE ProcessAddressSpace = &Process->VadRoot;
PMEMORY_AREA MemoryArea;
PHYSICAL_ADDRESS BoundaryAddressMultiple;
PVOID AllocatedBase = BaseAddress;
@ -161,7 +161,7 @@ STDCALL
MmDeleteTeb(PEPROCESS Process,
PTEB Teb)
{
PMADDRESS_SPACE ProcessAddressSpace = (PMADDRESS_SPACE)&Process->VadRoot;
PMM_AVL_TABLE ProcessAddressSpace = &Process->VadRoot;
PMEMORY_AREA MemoryArea;
/* Lock the Address Space */
@ -484,7 +484,7 @@ MmInitializeHandBuiltProcess2(IN PEPROCESS Process)
PMEMORY_AREA MemoryArea;
PHYSICAL_ADDRESS BoundaryAddressMultiple;
NTSTATUS Status;
PMADDRESS_SPACE ProcessAddressSpace = (PMADDRESS_SPACE)&Process->VadRoot;
PMM_AVL_TABLE ProcessAddressSpace = &Process->VadRoot;
BoundaryAddressMultiple.QuadPart = 0;
/* Create the shared data page */
@ -510,7 +510,7 @@ MmInitializeProcessAddressSpace(IN PEPROCESS Process,
IN POBJECT_NAME_INFORMATION *AuditName OPTIONAL)
{
NTSTATUS Status;
PMADDRESS_SPACE ProcessAddressSpace = (PMADDRESS_SPACE)&Process->VadRoot;
PMM_AVL_TABLE ProcessAddressSpace = &Process->VadRoot;
PVOID BaseAddress;
PMEMORY_AREA MemoryArea;
PHYSICAL_ADDRESS BoundaryAddressMultiple;
@ -519,9 +519,9 @@ MmInitializeProcessAddressSpace(IN PEPROCESS Process,
PROS_SECTION_OBJECT SectionObject = Section;
BoundaryAddressMultiple.QuadPart = 0;
/* Initialize the Addresss Space */
/* Initialize the Addresss Space lock */
KeInitializeGuardedMutex(&Process->AddressCreationLock);
MmInitializeAddressSpace(Process, ProcessAddressSpace);
Process->VadRoot.BalancedRoot.u1.Parent = NULL;
/* Acquire the Lock */
MmLockAddressSpace(ProcessAddressSpace);
@ -682,17 +682,17 @@ MmDeleteProcessAddressSpace(PEPROCESS Process)
DPRINT("MmDeleteProcessAddressSpace(Process %x (%s))\n", Process,
Process->ImageFileName);
MmLockAddressSpace((PMADDRESS_SPACE)&Process->VadRoot);
MmLockAddressSpace(&Process->VadRoot);
while ((MemoryArea = ((PMADDRESS_SPACE)&Process->VadRoot)->MemoryAreaRoot) != NULL)
while ((MemoryArea = (PMEMORY_AREA)Process->VadRoot.BalancedRoot.u1.Parent) != NULL)
{
switch (MemoryArea->Type)
{
case MEMORY_AREA_SECTION_VIEW:
Address = (PVOID)MemoryArea->StartingAddress;
MmUnlockAddressSpace((PMADDRESS_SPACE)&Process->VadRoot);
MmUnlockAddressSpace(&Process->VadRoot);
MmUnmapViewOfSection(Process, Address);
MmLockAddressSpace((PMADDRESS_SPACE)&Process->VadRoot);
MmLockAddressSpace(&Process->VadRoot);
break;
case MEMORY_AREA_VIRTUAL_MEMORY:
@ -702,7 +702,7 @@ MmDeleteProcessAddressSpace(PEPROCESS Process)
case MEMORY_AREA_SHARED_DATA:
case MEMORY_AREA_NO_ACCESS:
MmFreeMemoryArea((PMADDRESS_SPACE)&Process->VadRoot,
MmFreeMemoryArea(&Process->VadRoot,
MemoryArea,
NULL,
NULL);
@ -719,8 +719,7 @@ MmDeleteProcessAddressSpace(PEPROCESS Process)
Mmi386ReleaseMmInfo(Process);
MmUnlockAddressSpace((PMADDRESS_SPACE)&Process->VadRoot);
MmDestroyAddressSpace((PMADDRESS_SPACE)&Process->VadRoot);
MmUnlockAddressSpace(&Process->VadRoot);
DPRINT("Finished MmReleaseMmInfo()\n");
return(STATUS_SUCCESS);

View file

@ -33,7 +33,7 @@ InsertAfterEntry(PLIST_ENTRY Previous,
PMM_REGION static
MmSplitRegion(PMM_REGION InitialRegion, PVOID InitialBaseAddress,
PVOID StartAddress, ULONG Length, ULONG NewType,
ULONG NewProtect, PMADDRESS_SPACE AddressSpace,
ULONG NewProtect, PMM_AVL_TABLE AddressSpace,
PMM_ALTER_REGION_FUNC AlterFunc)
{
PMM_REGION NewRegion1;
@ -105,7 +105,7 @@ MmSplitRegion(PMM_REGION InitialRegion, PVOID InitialBaseAddress,
NTSTATUS
NTAPI
MmAlterRegion(PMADDRESS_SPACE AddressSpace, PVOID BaseAddress,
MmAlterRegion(PMM_AVL_TABLE AddressSpace, PVOID BaseAddress,
PLIST_ENTRY RegionListHead, PVOID StartAddress, ULONG Length,
ULONG NewType, ULONG NewProtect, PMM_ALTER_REGION_FUNC AlterFunc)
{

View file

@ -58,7 +58,7 @@ MmWritePagePhysicalAddress(PFN_TYPE Page)
{
PMM_RMAP_ENTRY entry;
PMEMORY_AREA MemoryArea;
PMADDRESS_SPACE AddressSpace;
PMM_AVL_TABLE AddressSpace;
ULONG Type;
PVOID Address;
PEPROCESS Process;
@ -91,7 +91,7 @@ MmWritePagePhysicalAddress(PFN_TYPE Page)
{
return Status;
}
AddressSpace = (PMADDRESS_SPACE)&Process->VadRoot;
AddressSpace = &Process->VadRoot;
}
else
{
@ -192,7 +192,7 @@ MmPageOutPhysicalAddress(PFN_TYPE Page)
{
PMM_RMAP_ENTRY entry;
PMEMORY_AREA MemoryArea;
PMADDRESS_SPACE AddressSpace;
PMM_AVL_TABLE AddressSpace;
ULONG Type;
PVOID Address;
PEPROCESS Process;
@ -222,7 +222,7 @@ MmPageOutPhysicalAddress(PFN_TYPE Page)
{
return Status;
}
AddressSpace = (PMADDRESS_SPACE)&Process->VadRoot;
AddressSpace = &Process->VadRoot;
}
else
{

View file

@ -152,7 +152,7 @@ MmGetFileNameForAddress(IN PVOID Address,
{
/*
* FIXME: TODO.
* Filip says to get the MADDRESS_SPACE from EPROCESS,
* Filip says to get the MM_AVL_TABLE from EPROCESS,
* then use the MmMarea routines to locate the Marea that
* corresponds to the address. Then make sure it's a section
* view type (MEMORY_AREA_SECTION_VIEW) and use the marea's
@ -707,7 +707,7 @@ MiReadPage(PMEMORY_AREA MemoryArea,
NTSTATUS
NTAPI
MmNotPresentFaultSectionView(PMADDRESS_SPACE AddressSpace,
MmNotPresentFaultSectionView(PMM_AVL_TABLE AddressSpace,
MEMORY_AREA* MemoryArea,
PVOID Address,
BOOLEAN Locked)
@ -1227,7 +1227,7 @@ MmNotPresentFaultSectionView(PMADDRESS_SPACE AddressSpace,
NTSTATUS
NTAPI
MmAccessFaultSectionView(PMADDRESS_SPACE AddressSpace,
MmAccessFaultSectionView(PMM_AVL_TABLE AddressSpace,
MEMORY_AREA* MemoryArea,
PVOID Address,
BOOLEAN Locked)
@ -1412,7 +1412,7 @@ MmPageOutDeleteMapping(PVOID Context, PEPROCESS Process, PVOID Address)
PageOutContext = (MM_SECTION_PAGEOUT_CONTEXT*)Context;
if (Process)
{
MmLockAddressSpace((PMADDRESS_SPACE)&Process->VadRoot);
MmLockAddressSpace(&Process->VadRoot);
}
MmDeleteVirtualMapping(Process,
@ -1436,7 +1436,7 @@ MmPageOutDeleteMapping(PVOID Context, PEPROCESS Process, PVOID Address)
}
if (Process)
{
MmUnlockAddressSpace((PMADDRESS_SPACE)&Process->VadRoot);
MmUnlockAddressSpace(&Process->VadRoot);
}
if (PageOutContext->Private)
@ -1449,7 +1449,7 @@ MmPageOutDeleteMapping(PVOID Context, PEPROCESS Process, PVOID Address)
NTSTATUS
NTAPI
MmPageOutSectionView(PMADDRESS_SPACE AddressSpace,
MmPageOutSectionView(PMM_AVL_TABLE AddressSpace,
MEMORY_AREA* MemoryArea,
PVOID Address,
PMM_PAGEOP PageOp)
@ -1803,7 +1803,7 @@ MmPageOutSectionView(PMADDRESS_SPACE AddressSpace,
NTSTATUS
NTAPI
MmWritePageSectionView(PMADDRESS_SPACE AddressSpace,
MmWritePageSectionView(PMM_AVL_TABLE AddressSpace,
PMEMORY_AREA MemoryArea,
PVOID Address,
PMM_PAGEOP PageOp)
@ -1950,7 +1950,7 @@ MmWritePageSectionView(PMADDRESS_SPACE AddressSpace,
}
VOID static
MmAlterViewAttributes(PMADDRESS_SPACE AddressSpace,
MmAlterViewAttributes(PMM_AVL_TABLE AddressSpace,
PVOID BaseAddress,
ULONG RegionSize,
ULONG OldType,
@ -2015,7 +2015,7 @@ MmAlterViewAttributes(PMADDRESS_SPACE AddressSpace,
NTSTATUS
NTAPI
MmProtectSectionView(PMADDRESS_SPACE AddressSpace,
MmProtectSectionView(PMM_AVL_TABLE AddressSpace,
PMEMORY_AREA MemoryArea,
PVOID BaseAddress,
ULONG Length,
@ -3566,7 +3566,7 @@ NtOpenSection(PHANDLE SectionHandle,
}
NTSTATUS static
MmMapViewOfSegment(PMADDRESS_SPACE AddressSpace,
MmMapViewOfSegment(PMM_AVL_TABLE AddressSpace,
PROS_SECTION_OBJECT Section,
PMM_SECTION_SEGMENT Segment,
PVOID* BaseAddress,
@ -3677,7 +3677,7 @@ NtMapViewOfSection(IN HANDLE SectionHandle,
PROS_SECTION_OBJECT Section;
PEPROCESS Process;
KPROCESSOR_MODE PreviousMode;
PMADDRESS_SPACE AddressSpace;
PMM_AVL_TABLE AddressSpace;
NTSTATUS Status = STATUS_SUCCESS;
ULONG tmpProtect;
@ -3758,7 +3758,7 @@ NtMapViewOfSection(IN HANDLE SectionHandle,
return(Status);
}
AddressSpace = (PMADDRESS_SPACE)&Process->VadRoot;
AddressSpace = &Process->VadRoot;
Status = ObReferenceObjectByHandle(SectionHandle,
SECTION_MAP_READ,
@ -3840,10 +3840,10 @@ MmFreeSectionPage(PVOID Context, MEMORY_AREA* MemoryArea, PVOID Address,
NTSTATUS Status;
PROS_SECTION_OBJECT Section;
PMM_SECTION_SEGMENT Segment;
PMADDRESS_SPACE AddressSpace;
PMM_AVL_TABLE AddressSpace;
PEPROCESS Process;
AddressSpace = (PMADDRESS_SPACE)Context;
AddressSpace = (PMM_AVL_TABLE)Context;
Process = MmGetAddressSpaceOwner(AddressSpace);
Address = (PVOID)PAGE_ROUND_DOWN(Address);
@ -3937,7 +3937,7 @@ MmFreeSectionPage(PVOID Context, MEMORY_AREA* MemoryArea, PVOID Address,
}
static NTSTATUS
MmUnmapViewOfSegment(PMADDRESS_SPACE AddressSpace,
MmUnmapViewOfSegment(PMM_AVL_TABLE AddressSpace,
PVOID BaseAddress)
{
NTSTATUS Status;
@ -3997,7 +3997,7 @@ MmUnmapViewOfSection(PEPROCESS Process,
{
NTSTATUS Status;
PMEMORY_AREA MemoryArea;
PMADDRESS_SPACE AddressSpace;
PMM_AVL_TABLE AddressSpace;
PROS_SECTION_OBJECT Section;
PMM_PAGEOP PageOp;
ULONG_PTR Offset;
@ -4008,7 +4008,7 @@ MmUnmapViewOfSection(PEPROCESS Process,
ASSERT(Process);
AddressSpace = (PMADDRESS_SPACE)&(Process)->VadRoot;
AddressSpace = &Process->VadRoot;
MmLockAddressSpace(AddressSpace);
MemoryArea = MmLocateMemoryAreaByAddress(AddressSpace,
@ -4398,7 +4398,7 @@ MmAllocateSection (IN ULONG Length, PVOID BaseAddress)
PVOID Result;
MEMORY_AREA* marea;
NTSTATUS Status;
PMADDRESS_SPACE AddressSpace;
PMM_AVL_TABLE AddressSpace;
PHYSICAL_ADDRESS BoundaryAddressMultiple;
DPRINT("MmAllocateSection(Length %x)\n",Length);
@ -4494,7 +4494,7 @@ MmMapViewOfSection(IN PVOID SectionObject,
IN ULONG Protect)
{
PROS_SECTION_OBJECT Section;
PMADDRESS_SPACE AddressSpace;
PMM_AVL_TABLE AddressSpace;
ULONG ViewOffset;
NTSTATUS Status = STATUS_SUCCESS;
@ -4514,7 +4514,7 @@ MmMapViewOfSection(IN PVOID SectionObject,
Section = (PROS_SECTION_OBJECT)SectionObject;
AddressSpace = (PMADDRESS_SPACE)&(Process)->VadRoot;
AddressSpace = &Process->VadRoot;
AllocationType |= (Section->AllocationAttributes & SEC_NO_CHANGE);
@ -4743,7 +4743,7 @@ MmMapViewInSystemSpace (IN PVOID SectionObject,
IN OUT PULONG ViewSize)
{
PROS_SECTION_OBJECT Section;
PMADDRESS_SPACE AddressSpace;
PMM_AVL_TABLE AddressSpace;
NTSTATUS Status;
DPRINT("MmMapViewInSystemSpace() called\n");
@ -4803,7 +4803,7 @@ MmMapViewInSessionSpace (
NTSTATUS STDCALL
MmUnmapViewInSystemSpace (IN PVOID MappedBase)
{
PMADDRESS_SPACE AddressSpace;
PMM_AVL_TABLE AddressSpace;
NTSTATUS Status;
DPRINT("MmUnmapViewInSystemSpace() called\n");

View file

@ -425,7 +425,7 @@ MiQueryVirtualMemory(IN HANDLE ProcessHandle,
NTSTATUS Status;
PEPROCESS Process;
MEMORY_AREA* MemoryArea;
PMADDRESS_SPACE AddressSpace;
PMM_AVL_TABLE AddressSpace;
if (Address < MmSystemRangeStart)
{
@ -441,7 +441,7 @@ MiQueryVirtualMemory(IN HANDLE ProcessHandle,
DPRINT("NtQueryVirtualMemory() = %x\n",Status);
return(Status);
}
AddressSpace = (PMADDRESS_SPACE)&Process->VadRoot;
AddressSpace = &Process->VadRoot;
}
else
{
@ -589,7 +589,7 @@ MiProtectVirtualMemory(IN PEPROCESS Process,
OUT PULONG OldAccessProtection OPTIONAL)
{
PMEMORY_AREA MemoryArea;
PMADDRESS_SPACE AddressSpace;
PMM_AVL_TABLE AddressSpace;
ULONG OldAccessProtection_;
NTSTATUS Status;
@ -598,7 +598,7 @@ MiProtectVirtualMemory(IN PEPROCESS Process,
PAGE_ROUND_DOWN(*BaseAddress);
*BaseAddress = (PVOID)PAGE_ROUND_DOWN(*BaseAddress);
AddressSpace = (PMADDRESS_SPACE)&(Process)->VadRoot;
AddressSpace = &Process->VadRoot;
MmLockAddressSpace(AddressSpace);
MemoryArea = MmLocateMemoryAreaByAddress(AddressSpace, *BaseAddress);