[NTOS:MM] Add macros to determine whether a VAD is a MEMORY_AREA

This commit is contained in:
Timo Kreuzer 2024-04-05 23:20:09 +03:00
parent d27f5971c5
commit 42c7e4f66a
6 changed files with 14 additions and 9 deletions

View file

@ -269,6 +269,9 @@ typedef struct _MEMORY_AREA
} SectionData;
} MEMORY_AREA, *PMEMORY_AREA;
#define MI_SET_MEMORY_AREA_VAD(Vad) do { (Vad)->u.VadFlags.Spare |= 1; } while (0)
#define MI_IS_MEMORY_AREA_VAD(Vad) (((Vad)->u.VadFlags.Spare & 1) != 0)
typedef struct _MM_RMAP_ENTRY
{
struct _MM_RMAP_ENTRY* Next;

View file

@ -1293,7 +1293,7 @@ MmCleanProcessAddressSpace(IN PEPROCESS Process)
Vad = (PMMVAD)VadTree->BalancedRoot.RightChild;
/* Check for old-style memory areas */
if (Vad->u.VadFlags.Spare == 1)
if (MI_IS_MEMORY_AREA_VAD(Vad))
{
/* Let RosMm handle this */
MiRosCleanupMemoryArea(Process, Vad);

View file

@ -778,6 +778,7 @@ MiRemoveMappedView(IN PEPROCESS CurrentProcess,
ASSERT(Vad->u2.VadFlags2.ExtendableFile == FALSE);
ASSERT(ControlArea);
ASSERT(ControlArea->FilePointer == NULL);
ASSERT(!MI_IS_MEMORY_AREA_VAD(Vad));
/* Delete the actual virtual memory pages */
MiDeleteVirtualAddresses(Vad->StartingVpn << PAGE_SHIFT,
@ -1564,7 +1565,7 @@ MiGetFileObjectForVad(
PFILE_OBJECT FileObject;
/* Check if this is a RosMm memory area */
if (Vad->u.VadFlags.Spare != 0)
if (MI_IS_MEMORY_AREA_VAD(Vad))
{
PMEMORY_AREA MemoryArea = (PMEMORY_AREA)Vad;

View file

@ -213,7 +213,7 @@ MiInsertNode(IN PMM_AVL_TABLE Table,
/* Now insert an ARM3 MEMORY_AREA for this node, unless the insert was already from the MEMORY_AREA code */
Vad = (PMMVAD_LONG)NewNode;
if (Vad->u.VadFlags.Spare == 0)
if (!MI_IS_MEMORY_AREA_VAD(Vad))
{
NTSTATUS Status;
PMEMORY_AREA MemoryArea;
@ -460,7 +460,7 @@ MiRemoveNode(IN PMMADDRESS_NODE Node,
/* Free the node from ReactOS view as well */
Vad = (PMMVAD_LONG)Node;
if ((Table != &MmSectionBasedRoot) && (Vad->u.VadFlags.Spare == 0))
if ((Table != &MmSectionBasedRoot) && !MI_IS_MEMORY_AREA_VAD(Vad))
{
PMEMORY_AREA MemoryArea;
PEPROCESS Process;

View file

@ -546,7 +546,7 @@ MiDeleteVirtualAddresses(IN ULONG_PTR Va,
PSUBSECTION Subsection;
/* Get out if this is a fake VAD, RosMm will free the marea pages */
if ((Vad) && (Vad->u.VadFlags.Spare == 1)) return;
if ((Vad) && MI_IS_MEMORY_AREA_VAD(Vad)) return;
/* Get the current process */
CurrentProcess = PsGetCurrentProcess();

View file

@ -92,7 +92,7 @@ MmLocateMemoryAreaByRegion(
}
Vad = (PMMVAD_LONG)Node;
if (Vad->u.VadFlags.Spare == 0)
if (!MI_IS_MEMORY_AREA_VAD(Vad))
{
/* Check if this is VM VAD */
if (Vad->ControlArea == NULL)
@ -157,7 +157,6 @@ MmInsertMemoryArea(
{
PEPROCESS Process = MmGetAddressSpaceOwner(AddressSpace);
marea->VadNode.u.VadFlags.Spare = 1;
marea->VadNode.u.VadFlags.Protection = MiMakeProtectionMask(Protect);
/* Build a lame VAD if this is a user-space allocation */
@ -334,9 +333,10 @@ MmFreeMemoryArea(
#endif
/* MmCleanProcessAddressSpace might have removed it (and this would be MmDeleteProcessAddressSpace) */
ASSERT(MemoryArea->VadNode.u.VadFlags.Spare != 0);
if (((PMMVAD)MemoryArea->Vad)->u.VadFlags.Spare == 1)
ASSERT(MI_IS_MEMORY_AREA_VAD(&MemoryArea->VadNode));
if (MI_IS_MEMORY_AREA_VAD((PMMVAD)MemoryArea->Vad))
{
ASSERT((PMMVAD)MemoryArea->Vad == &MemoryArea->VadNode);
MiLockProcessWorkingSet(PsGetCurrentProcess(), PsGetCurrentThread());
MiRemoveNode((PMMADDRESS_NODE)&MemoryArea->VadNode, &Process->VadRoot);
MiUnlockProcessWorkingSet(PsGetCurrentProcess(), PsGetCurrentThread());
@ -439,6 +439,7 @@ MmCreateMemoryArea(PMMSUPPORT AddressSpace,
MemoryArea->Flags = AllocationFlags;
MemoryArea->Magic = 'erAM';
MemoryArea->DeleteInProgress = FALSE;
MI_SET_MEMORY_AREA_VAD(&MemoryArea->VadNode);
if (*BaseAddress == 0)
{