ReactOS  0.4.15-dev-499-g1f31905
marea.c File Reference
#include <ntoskrnl.h>
#include <cache/section/newmm.h>
#include <debug.h>
#include "ARM3/miarm.h"
Include dependency graph for marea.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

PMEMORY_AREA NTAPI MmLocateMemoryAreaByAddress (PMMSUPPORT AddressSpace, PVOID Address_)
 
PMEMORY_AREA NTAPI MmLocateMemoryAreaByRegion (PMMSUPPORT AddressSpace, PVOID Address_, ULONG_PTR Length)
 
VOID NTAPI MiInsertVad (IN PMMVAD Vad, IN PMM_AVL_TABLE VadRoot)
 
ULONG NTAPI MiMakeProtectionMask (IN ULONG Protect)
 
static VOID MmInsertMemoryArea (PMMSUPPORT AddressSpace, PMEMORY_AREA marea)
 
PVOID NTAPI MmFindGap (PMMSUPPORT AddressSpace, ULONG_PTR Length, ULONG_PTR Granularity, BOOLEAN TopDown)
 
VOID NTAPI MiRemoveNode (IN PMMADDRESS_NODE Node, IN PMM_AVL_TABLE Table)
 
MmFreeMemoryArea

Free an existing memory area.

Parameters
AddressSpaceAddress space to free the area from.
MemoryAreaMemory area we're about to free.
FreePageCallback function for each freed page.
FreePageContextContext passed to the callback function.
Returns
Status
Remarks
Lock the address space before calling this function.
NTSTATUS NTAPI MmFreeMemoryArea (PMMSUPPORT AddressSpace, PMEMORY_AREA MemoryArea, PMM_FREE_PAGE_FUNC FreePage, PVOID FreePageContext)
 
MmCreateMemoryArea

Create a memory area.

Parameters
AddressSpaceAddress space to create the area in.
TypeType of the memory area.
BaseAddressBase address for the memory area we're about the create. On input it contains either 0 (auto-assign address) or preferred address. On output it contains the starting address of the newly created area.
LengthLength of the area to allocate.
AttributesProtection attributes for the memory area.
ResultReceives a pointer to the memory area on successful exit.
Returns
Status
Remarks
Lock the address space before calling this function.
NTSTATUS NTAPI MmCreateMemoryArea (PMMSUPPORT AddressSpace, ULONG Type, PVOID *BaseAddress, ULONG_PTR Length, ULONG Protect, PMEMORY_AREA *Result, ULONG AllocationFlags, ULONG Granularity)
 
VOID NTAPI MiRosCleanupMemoryArea (PEPROCESS Process, PMMVAD Vad)
 
VOID NTAPI MmDeleteProcessAddressSpace2 (IN PEPROCESS Process)
 
NTSTATUS NTAPI MmDeleteProcessAddressSpace (PEPROCESS Process)
 

Variables

MEMORY_AREA MiStaticMemoryAreas [MI_STATIC_MEMORY_AREAS]
 
ULONG MiStaticMemoryAreaCount
 
MM_AVL_TABLE MiRosKernelVadRoot
 
BOOLEAN MiRosKernelVadRootInitialized
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 45 of file marea.c.

Function Documentation

◆ MiInsertVad()

VOID NTAPI MiInsertVad ( IN PMMVAD  Vad,
IN PMM_AVL_TABLE  VadRoot 
)

Definition at line 183 of file vadnode.c.

185 {
188 
189  /* Validate the VAD and set it as the current hint */
190  ASSERT(Vad->EndingVpn >= Vad->StartingVpn);
191  VadRoot->NodeHint = Vad;
192 
193  /* Find the parent VAD and where this child should be inserted */
194  Result = RtlpFindAvlTableNodeOrParent(VadRoot, (PVOID)Vad->StartingVpn, &Parent);
196  ASSERT((Parent != NULL) || (Result == TableEmptyTree));
197 
198  /* Do the actual insert operation */
199  MiInsertNode(VadRoot, (PVOID)Vad, Parent, Result);
200 }
enum _TABLE_SEARCH_RESULT TABLE_SEARCH_RESULT
ACPI_PHYSICAL_ADDRESS ACPI_SIZE BOOLEAN Warn BOOLEAN Physical UINT32 ACPI_TABLE_HEADER *OutTableHeader ACPI_TABLE_HEADER **OutTable ACPI_HANDLE UINT32 ACPI_WALK_CALLBACK ACPI_WALK_CALLBACK void void **ReturnValue UINT32 ACPI_BUFFER *RetPathPtr ACPI_OBJECT_HANDLER void *Data ACPI_OBJECT_HANDLER void **Data ACPI_STRING ACPI_OBJECT_LIST ACPI_BUFFER *ReturnObjectBuffer ACPI_DEVICE_INFO **ReturnBuffer ACPI_HANDLE Parent
Definition: acpixf.h:728
smooth NULL
Definition: ftsmooth.c:416
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
FORCEINLINE TABLE_SEARCH_RESULT RtlpFindAvlTableNodeOrParent(IN PRTL_AVL_TABLE Table, IN PVOID Buffer, OUT PRTL_BALANCED_LINKS *NodeOrParent)
Definition: avlsupp.c:32
VOID NTAPI MiInsertNode(IN PMM_AVL_TABLE Table, IN PMMADDRESS_NODE NewNode, IN PMMADDRESS_NODE Parent, IN TABLE_SEARCH_RESULT Result)
Definition: vadnode.c:128

Referenced by MmInsertMemoryArea().

◆ MiMakeProtectionMask()

ULONG NTAPI MiMakeProtectionMask ( IN ULONG  Protect)

Definition at line 158 of file section.c.

159 {
160  ULONG Mask1, Mask2, ProtectMask;
161 
162  /* PAGE_EXECUTE_WRITECOMBINE is theoretically the maximum */
163  if (Protect >= (PAGE_WRITECOMBINE * 2)) return MM_INVALID_PROTECTION;
164 
165  /*
166  * Windows API protection mask can be understood as two bitfields, differing
167  * by whether or not execute rights are being requested
168  */
169  Mask1 = Protect & 0xF;
170  Mask2 = (Protect >> 4) & 0xF;
171 
172  /* Check which field is there */
173  if (!Mask1)
174  {
175  /* Mask2 must be there, use it to determine the PTE protection */
176  if (!Mask2) return MM_INVALID_PROTECTION;
177  ProtectMask = MmUserProtectionToMask2[Mask2];
178  }
179  else
180  {
181  /* Mask2 should not be there, use Mask1 to determine the PTE mask */
182  if (Mask2) return MM_INVALID_PROTECTION;
183  ProtectMask = MmUserProtectionToMask1[Mask1];
184  }
185 
186  /* Make sure the final mask is a valid one */
187  if (ProtectMask == MM_INVALID_PROTECTION) return MM_INVALID_PROTECTION;
188 
189  /* Check for PAGE_GUARD option */
190  if (Protect & PAGE_GUARD)
191  {
192  /* It's not valid on no-access, nocache, or writecombine pages */
193  if ((ProtectMask == MM_NOACCESS) ||
195  {
196  /* Fail such requests */
197  return MM_INVALID_PROTECTION;
198  }
199 
200  /* This actually turns on guard page in this scenario! */
201  ProtectMask |= MM_GUARDPAGE;
202  }
203 
204  /* Check for nocache option */
205  if (Protect & PAGE_NOCACHE)
206  {
207  /* The earlier check should've eliminated this possibility */
208  ASSERT((Protect & PAGE_GUARD) == 0);
209 
210  /* Check for no-access page or write combine page */
211  if ((ProtectMask == MM_NOACCESS) || (Protect & PAGE_WRITECOMBINE))
212  {
213  /* Such a request is invalid */
214  return MM_INVALID_PROTECTION;
215  }
216 
217  /* Add the PTE flag */
218  ProtectMask |= MM_NOCACHE;
219  }
220 
221  /* Check for write combine option */
223  {
224  /* The two earlier scenarios should've caught this */
225  ASSERT((Protect & (PAGE_GUARD | PAGE_NOACCESS)) == 0);
226 
227  /* Don't allow on no-access pages */
228  if (ProtectMask == MM_NOACCESS) return MM_INVALID_PROTECTION;
229 
230  /* This actually turns on write-combine in this scenario! */
231  ProtectMask |= MM_NOACCESS;
232  }
233 
234  /* Return the final MM PTE protection mask */
235  return ProtectMask;
236 }
#define PAGE_NOCACHE
Definition: nt_native.h:1311
#define MM_INVALID_PROTECTION
Definition: miarm.h:63
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T _Inout_opt_ PLARGE_INTEGER _Inout_ PSIZE_T _In_ SECTION_INHERIT _In_ ULONG _In_ ULONG Protect
Definition: zwfuncs.h:214
CHAR MmUserProtectionToMask1[16]
Definition: section.c:44
#define PAGE_GUARD
Definition: nt_native.h:1310
#define MM_NOACCESS
Definition: miarm.h:61
#define MM_NOCACHE
Definition: miarm.h:52
#define PAGE_NOACCESS
Definition: nt_native.h:1302
CHAR MmUserProtectionToMask2[16]
Definition: section.c:64
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define MM_GUARDPAGE
Definition: miarm.h:53
#define PAGE_WRITECOMBINE
Definition: mmtypes.h:78
unsigned int ULONG
Definition: retypes.h:1

Referenced by MiArm3GetCorrectFileAccessMask(), MiIsProtectionCompatible(), MiSetProtectionOnSection(), MmCreateArm3Section(), MmCreateSection(), MmInsertMemoryArea(), MmMapViewOfArm3Section(), and NtMapViewOfSection().

◆ MiRemoveNode()

VOID NTAPI MiRemoveNode ( IN PMMADDRESS_NODE  Node,
IN PMM_AVL_TABLE  Table 
)

Definition at line 360 of file vadnode.c.

362 {
363  PMMVAD_LONG Vad;
364 
365  /* Call the AVL code */
367 
368  /* Decrease element count */
369  Table->NumberGenericTableElements--;
370 
371  /* Check if this node was the hint */
372  if (Table->NodeHint == Node)
373  {
374  /* Get a new hint, unless we're empty now, in which case nothing */
375  if (!Table->NumberGenericTableElements) Table->NodeHint = NULL;
376  else Table->NodeHint = Table->BalancedRoot.RightChild;
377  }
378 
379  /* Free the node from ReactOS view as well */
380  Vad = (PMMVAD_LONG)Node;
381  if ((Table != &MmSectionBasedRoot) && (Vad->u.VadFlags.Spare == 0))
382  {
385 
386  /* Check if this is VM VAD */
387  if (Vad->ControlArea == NULL)
388  {
389  /* We store the ReactOS MEMORY_AREA here */
391  }
392  else
393  {
394  /* This is a section VAD. We store the ReactOS MEMORY_AREA here */
396  }
397 
398  /* Make sure one actually still exists */
399  if (MemoryArea)
400  {
401  /* Make sure we have not already freed it */
402  ASSERT(MemoryArea != (PVOID)(ULONG_PTR)0xDEADBAB1DEADBAB1ULL);
403 
404  /* Get the process */
406 
407  /* We only create fake memory-areas for ARM3 VADs */
409  ASSERT(MemoryArea->Vad == NULL);
410 
411  /* Free it */
413 
414  /* Check if this is VM VAD */
415  if (Vad->ControlArea == NULL)
416  {
417  /* Delete the pointer to it */
418  Vad->FirstPrototypePte = (PVOID)(ULONG_PTR)0xDEADBAB1DEADBAB1ULL;
419  }
420  else
421  {
422  /* Delete the pointer to it */
423  Vad->u4.Banked = (PVOID)(ULONG_PTR)0xDEADBAB1DEADBAB1ULL;
424  }
425  }
426  }
427 }
FORCEINLINE VOID RtlpDeleteAvlTreeNode(IN PRTL_AVL_TABLE Table, IN PRTL_BALANCED_LINKS Node)
Definition: avlsupp.c:295
ASMGENDATA Table[]
Definition: genincdata.c:61
MM_AVL_TABLE MmSectionBasedRoot
Definition: section.c:109
ULONG Type
Definition: mm.h:214
struct _MEMORY_AREA * PMEMORY_AREA
MMVAD_FLAGS VadFlags
Definition: mmtypes.h:767
PCONTROL_AREA ControlArea
Definition: mmtypes.h:769
uint32_t ULONG_PTR
Definition: typedefs.h:64
#define MEMORY_AREA_OWNED_BY_ARM3
Definition: mm.h:73
union _MMVAD_LONG::@2542 u4
smooth NULL
Definition: ftsmooth.c:416
PVOID Banked
Definition: mmtypes.h:784
void * PVOID
Definition: retypes.h:9
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
#define ULL(a, b)
Definition: format_msg.c:27
union _MMVAD_LONG::@2539 u
struct _MMVAD_LONG * PMMVAD_LONG
NTSTATUS NTAPI MmFreeMemoryArea(PMMSUPPORT AddressSpace, PMEMORY_AREA MemoryArea, PMM_FREE_PAGE_FUNC FreePage, PVOID FreePageContext)
Definition: marea.c:278
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
ULONG_PTR Spare
Definition: mmtypes.h:701
PMMPTE FirstPrototypePte
Definition: mmtypes.h:770
struct _MEMORY_AREA * MemoryArea
Definition: newmm.h:65
PVOID Vad
Definition: mm.h:219
Definition: dlist.c:348

Referenced by MmFreeMemoryArea().

◆ MiRosCleanupMemoryArea()

VOID NTAPI MiRosCleanupMemoryArea ( PEPROCESS  Process,
PMMVAD  Vad 
)

Definition at line 522 of file marea.c.

525 {
529 
530  /* We must be called from MmCleanupAddressSpace and nowhere else!
531  Make sure things are as expected... */
533  ASSERT(Process->VmDeleted == TRUE);
534  ASSERT(((PsGetCurrentThread()->ThreadsProcess == Process) &&
535  (Process->ActiveThreads == 1)) ||
536  (Process->ActiveThreads == 0));
537 
538  /* We are in cleanup, we don't need to synchronize */
540 
541  MemoryArea = (PMEMORY_AREA)Vad;
543 
545  {
547  }
548  else if (MemoryArea->Type == MEMORY_AREA_CACHE)
549  {
551  }
552  else
553  {
554  /* There shouldn't be anything else! */
555  ASSERT(FALSE);
556  }
557 
558  /* Make sure this worked! */
560 
561  /* Lock the address space again */
563 }
#define TRUE
Definition: types.h:120
ULONG Type
Definition: mm.h:214
struct _MEMORY_AREA * PMEMORY_AREA
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
FORCEINLINE VOID MmUnlockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1431
LONG NTSTATUS
Definition: precomp.h:26
#define MEMORY_AREA_CACHE
Definition: mm.h:72
#define PsGetCurrentProcess
Definition: psfuncs.h:17
void * PVOID
Definition: retypes.h:9
#define MEMORY_AREA_SECTION_VIEW
Definition: mm.h:71
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define MA_GetStartingAddress(_MemoryArea)
Definition: mm.h:207
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI MmUnmapViewOfCacheSegment(PMMSUPPORT AddressSpace, PVOID BaseAddress)
Definition: data.c:713
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
NTSTATUS NTAPI MiRosUnmapViewOfSection(IN PEPROCESS Process, IN PVOID BaseAddress, IN BOOLEAN SkipDebuggerNotify)
Definition: section.c:4137
struct _MEMORY_AREA * MemoryArea
Definition: newmm.h:65
FORCEINLINE VOID MmLockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1424

Referenced by MmCleanProcessAddressSpace().

◆ MmCreateMemoryArea()

NTSTATUS NTAPI MmCreateMemoryArea ( PMMSUPPORT  AddressSpace,
ULONG  Type,
PVOID BaseAddress,
ULONG_PTR  Length,
ULONG  Protect,
PMEMORY_AREA Result,
ULONG  AllocationFlags,
ULONG  Granularity 
)

Definition at line 410 of file marea.c.

418 {
419  ULONG_PTR tmpLength;
421  ULONG_PTR EndingAddress;
422 
423  DPRINT("MmCreateMemoryArea(Type 0x%lx, BaseAddress %p, "
424  "*BaseAddress %p, Length %p, AllocationFlags %x, "
425  "Result %p)\n",
426  Type, BaseAddress, *BaseAddress, Length, AllocationFlags,
427  Result);
428 
429  /* Is this a static memory area? */
430  if (Type & MEMORY_AREA_STATIC)
431  {
432  /* Use the static array instead of the pool */
435  }
436  else
437  {
438  /* Allocate the memory area from nonpaged pool */
440  sizeof(MEMORY_AREA),
441  TAG_MAREA);
442  }
443 
444  if (!MemoryArea)
445  {
446  DPRINT1("Not enough memory.\n");
447  return STATUS_NO_MEMORY;
448  }
449 
453  MemoryArea->Flags = AllocationFlags;
454  MemoryArea->Magic = 'erAM';
456 
457  if (*BaseAddress == 0)
458  {
459  tmpLength = (ULONG_PTR)MM_ROUND_UP(Length, PAGE_SIZE);
461  tmpLength,
462  Granularity,
463  (AllocationFlags & MEM_TOP_DOWN) == MEM_TOP_DOWN);
464  if ((*BaseAddress) == 0)
465  {
466  DPRINT("No suitable gap\n");
468  return STATUS_NO_MEMORY;
469  }
470 
472  MemoryArea->VadNode.EndingVpn = ((ULONG_PTR)*BaseAddress + tmpLength - 1) >> PAGE_SHIFT;
474  }
475  else
476  {
477  EndingAddress = ((ULONG_PTR)*BaseAddress + Length - 1) | (PAGE_SIZE - 1);
479  tmpLength = EndingAddress + 1 - (ULONG_PTR)*BaseAddress;
480 
482  {
483  ASSERT(FALSE);
486  }
487 
490  {
491  DPRINT("Memory area for user mode address space exceeds MmSystemRangeStart\n");
494  }
495 
496  /* No need to check ARM3 owned memory areas, the range MUST be free */
498  {
500  *BaseAddress,
501  tmpLength) != NULL)
502  {
503  DPRINT("Memory area already occupied\n");
506  }
507  }
508 
510  MemoryArea->VadNode.EndingVpn = ((ULONG_PTR)*BaseAddress + tmpLength - 1) >> PAGE_SHIFT;
512  }
513 
514  *Result = MemoryArea;
515 
516  DPRINT("MmCreateMemoryArea() succeeded (%p)\n", *BaseAddress);
517  return STATUS_SUCCESS;
518 }
#define PAGE_SHIFT
Definition: env_spec_w32.h:45
ULONG Type
Definition: mm.h:214
Type
Definition: Type.h:6
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T _Inout_opt_ PLARGE_INTEGER _Inout_ PSIZE_T _In_ SECTION_INHERIT _In_ ULONG _In_ ULONG Protect
Definition: zwfuncs.h:214
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG AddressSpace
Definition: iofuncs.h:2268
#define MEMORY_AREA_STATIC
Definition: mm.h:74
uint32_t ULONG_PTR
Definition: typedefs.h:64
ULONG_PTR EndingVpn
Definition: mmtypes.h:734
ULONG Magic
Definition: mm.h:218
#define MEMORY_AREA_OWNED_BY_ARM3
Definition: mm.h:73
#define TAG_MAREA
Definition: tag.h:120
smooth NULL
Definition: ftsmooth.c:416
ULONG Protect
Definition: mm.h:215
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
void DPRINT(...)
Definition: polytest.cpp:61
ULONG_PTR StartingVpn
Definition: mmtypes.h:733
#define MM_ROUND_UP(x, s)
Definition: mm.h:108
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
BOOLEAN DeleteInProgress
Definition: mm.h:217
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
MMVAD VadNode
Definition: mm.h:212
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
MEMORY_AREA MiStaticMemoryAreas[MI_STATIC_MEMORY_AREAS]
Definition: marea.c:51
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:228
ULONG MiStaticMemoryAreaCount
Definition: marea.c:52
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
FORCEINLINE PEPROCESS MmGetAddressSpaceOwner(IN PMMSUPPORT AddressSpace)
Definition: mm.h:1438
#define DPRINT1
Definition: precomp.h:8
#define MI_STATIC_MEMORY_AREAS
Definition: mm.h:68
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define ULONG_PTR
Definition: config.h:101
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
PVOID NTAPI MmFindGap(PMMSUPPORT AddressSpace, ULONG_PTR Length, ULONG_PTR Granularity, BOOLEAN TopDown)
Definition: marea.c:210
PMEMORY_AREA NTAPI MmLocateMemoryAreaByRegion(PMMSUPPORT AddressSpace, PVOID Address_, ULONG_PTR Length)
Definition: marea.c:106
#define MEM_TOP_DOWN
Definition: nt_native.h:1321
#define STATUS_CONFLICTING_ADDRESSES
Definition: ntstatus.h:247
return STATUS_SUCCESS
Definition: btrfs.c:3014
static VOID MmInsertMemoryArea(PMMSUPPORT AddressSpace, PMEMORY_AREA marea)
Definition: marea.c:166
#define ALIGN_DOWN_POINTER_BY(ptr, align)
Definition: umtypes.h:82
struct _MEMORY_AREA * MemoryArea
Definition: newmm.h:65
#define MmSystemRangeStart
Definition: mm.h:32
ULONG Flags
Definition: mm.h:216

Referenced by _MiMapViewOfSegment(), CcRosMapVacbInKernelSpace(), MiCreateArm3StaticMemoryArea(), MiInsertNode(), and MmMapViewOfSegment().

◆ MmDeleteProcessAddressSpace()

NTSTATUS NTAPI MmDeleteProcessAddressSpace ( PEPROCESS  Process)

Definition at line 571 of file marea.c.

572 {
573 #ifndef _M_AMD64
574  KIRQL OldIrql;
575 #endif
576 
577  DPRINT("MmDeleteProcessAddressSpace(Process %p (%s))\n", Process,
578  Process->ImageFileName);
579 
580 #ifndef _M_AMD64
582  RemoveEntryList(&Process->MmProcessLinks);
584 #endif
586 
587  /* There should not be any memory areas left! */
588  ASSERT(Process->Vm.WorkingSetExpansionLinks.Flink == NULL);
589 
590 #if (_MI_PAGING_LEVELS == 2)
591  {
592  KIRQL OldIrql;
593  PVOID Address;
594  PMMPDE pointerPde;
595 
596  /* Attach to Process */
597  KeAttachProcess(&Process->Pcb);
598 
599  /* Acquire PFN lock */
601 
605  {
606  /* At this point all references should be dead */
608  {
609  DPRINT1("Process %p, Address %p, UsedPageTableEntries %lu\n",
610  Process,
611  Address,
614  }
615 
616  pointerPde = MiAddressToPde(Address);
617  /* Unlike in ARM3, we don't necesarrily free the PDE page as soon as reference reaches 0,
618  * so we must clean up a bit when process closes */
619  if (pointerPde->u.Hard.Valid)
620  MiDeletePte(pointerPde, MiPdeToPte(pointerPde), Process, NULL);
621  ASSERT(pointerPde->u.Hard.Valid == 0);
622  }
623 
624  /* Release lock */
626 
627  /* Detach */
628  KeDetachProcess();
629  }
630 #endif
631 
633 
634  DPRINT("Finished MmDeleteProcessAddressSpace()\n");
636  return(STATUS_SUCCESS);
637 }
#define MiAddressToPde(x)
Definition: mmx86.c:20
FORCEINLINE KIRQL MiAcquireExpansionLock(VOID)
Definition: miarm.h:1376
#define MI_LOWEST_VAD_ADDRESS
Definition: miarm.h:11
FORCEINLINE VOID MmUnlockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1431
FORCEINLINE KIRQL MiAcquirePfnLock(VOID)
Definition: mm.h:901
FORCEINLINE USHORT MiQueryPageTableReferences(IN PVOID Address)
Definition: miarm.h:1687
FORCEINLINE VOID MiReleasePfnLock(_In_ KIRQL OldIrql)
Definition: mm.h:908
VOID NTAPI MiDeletePte(IN PMMPTE PointerPte, IN PVOID VirtualAddress, IN PEPROCESS CurrentProcess, IN PMMPTE PrototypePte)
Definition: virtual.c:391
uint32_t ULONG_PTR
Definition: typedefs.h:64
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
UCHAR KIRQL
Definition: env_spec_w32.h:591
smooth NULL
Definition: ftsmooth.c:416
static WCHAR Address[46]
Definition: ping.c:68
VOID NTAPI MmDeleteProcessAddressSpace2(IN PEPROCESS Process)
Definition: procsup.c:1326
void DPRINT(...)
Definition: polytest.cpp:61
union _MMPTE::@2276 u
void * PVOID
Definition: retypes.h:9
ULONG64 Valid
Definition: mmtypes.h:150
#define PTE_PER_PAGE
Definition: mm.h:20
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
VOID NTAPI KeDetachProcess(VOID)
Definition: procobj.c:618
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
#define PAGE_SIZE
Definition: env_spec_w32.h:49
MMPTE_HARDWARE Hard
Definition: mmtypes.h:217
#define MiPdeToPte(_Pde)
Definition: mm.h:235
VOID NTAPI KeAttachProcess(IN PKPROCESS Process)
Definition: procobj.c:579
FORCEINLINE VOID MiReleaseExpansionLock(KIRQL OldIrql)
Definition: miarm.h:1389
#define DPRINT1
Definition: precomp.h:8
#define MM_HIGHEST_VAD_ADDRESS
Definition: mm.h:46
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
return STATUS_SUCCESS
Definition: btrfs.c:3014
FORCEINLINE VOID MmLockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1424

◆ MmDeleteProcessAddressSpace2()

VOID NTAPI MmDeleteProcessAddressSpace2 ( IN PEPROCESS  Process)

Definition at line 1326 of file procsup.c.

1327 {
1328  PMMPFN Pfn1, Pfn2;
1329  KIRQL OldIrql;
1330  PFN_NUMBER PageFrameIndex;
1331 
1332  //ASSERT(Process->CommitCharge == 0);
1333 
1334  /* Acquire the PFN lock */
1336 
1337  /* Check for fully initialized process */
1338  if (Process->AddressSpaceInitialized == 2)
1339  {
1340  /* Map the working set page and its page table */
1341  Pfn1 = MiGetPfnEntry(Process->WorkingSetPage);
1342  Pfn2 = MiGetPfnEntry(Pfn1->u4.PteFrame);
1343 
1344  /* Nuke it */
1345  MI_SET_PFN_DELETED(Pfn1);
1346  MiDecrementShareCount(Pfn2, Pfn1->u4.PteFrame);
1347  MiDecrementShareCount(Pfn1, Process->WorkingSetPage);
1348  ASSERT((Pfn1->u3.e2.ReferenceCount == 0) || (Pfn1->u3.e1.WriteInProgress));
1349  MiReleaseSystemPtes(MiAddressToPte(Process->Vm.VmWorkingSetList), 1, SystemPteSpace);
1350 
1351  /* Now map hyperspace and its page table */
1352  PageFrameIndex = Process->Pcb.DirectoryTableBase[1] >> PAGE_SHIFT;
1353  Pfn1 = MiGetPfnEntry(PageFrameIndex);
1354  Pfn2 = MiGetPfnEntry(Pfn1->u4.PteFrame);
1355 
1356  /* Nuke it */
1357  MI_SET_PFN_DELETED(Pfn1);
1358  MiDecrementShareCount(Pfn2, Pfn1->u4.PteFrame);
1359  MiDecrementShareCount(Pfn1, PageFrameIndex);
1360  ASSERT((Pfn1->u3.e2.ReferenceCount == 0) || (Pfn1->u3.e1.WriteInProgress));
1361 
1362  /* Finally, nuke the PDE itself */
1363  PageFrameIndex = Process->Pcb.DirectoryTableBase[0] >> PAGE_SHIFT;
1364  Pfn1 = MiGetPfnEntry(PageFrameIndex);
1365  MI_SET_PFN_DELETED(Pfn1);
1366  MiDecrementShareCount(Pfn1, PageFrameIndex);
1367  MiDecrementShareCount(Pfn1, PageFrameIndex);
1368 
1369  /* Page table is now dead. Bye bye... */
1370  ASSERT((Pfn1->u3.e2.ReferenceCount == 0) || (Pfn1->u3.e1.WriteInProgress));
1371  }
1372  else
1373  {
1374  /* A partly-initialized process should never exit through here */
1375  ASSERT(FALSE);
1376  }
1377 
1378  /* Release the PFN lock */
1380 
1381  /* Drop a reference on the session */
1383 
1384  /* Clear out the PDE pages */
1385  Process->Pcb.DirectoryTableBase[0] = 0;
1386  Process->Pcb.DirectoryTableBase[1] = 0;
1387 }
#define PAGE_SHIFT
Definition: env_spec_w32.h:45
VOID NTAPI MiReleaseProcessReferenceToSessionDataPage(IN PMM_SESSION_SPACE SessionGlobal)
Definition: session.c:210
union _MMPFN::@1772 u4
FORCEINLINE KIRQL MiAcquirePfnLock(VOID)
Definition: mm.h:901
FORCEINLINE VOID MiReleasePfnLock(_In_ KIRQL OldIrql)
Definition: mm.h:908
UCHAR KIRQL
Definition: env_spec_w32.h:591
MMPFNENTRY e1
Definition: mm.h:329
#define MiAddressToPte(x)
Definition: mmx86.c:19
ULONG PFN_NUMBER
Definition: ke.h:8
VOID NTAPI MiDecrementShareCount(IN PMMPFN Pfn1, IN PFN_NUMBER PageFrameIndex)
Definition: pfnlist.c:1133
VOID NTAPI MiReleaseSystemPtes(IN PMMPTE StartingPte, IN ULONG NumberOfPtes, IN MMSYSTEM_PTE_POOL_TYPE SystemPtePoolType)
Definition: syspte.c:275
USHORT WriteInProgress
Definition: mm.h:294
union _MMPFN::@1769 u3
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
Definition: mm.h:305
FORCEINLINE PMMPFN MiGetPfnEntry(IN PFN_NUMBER Pfn)
Definition: mm.h:940
#define MI_SET_PFN_DELETED(x)
Definition: miarm.h:190
ULONG_PTR PteFrame
Definition: mm.h:350
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
struct _MMPFN::@1769::@1775 e2

Referenced by MmDeleteProcessAddressSpace().

◆ MmFindGap()

PVOID NTAPI MmFindGap ( PMMSUPPORT  AddressSpace,
ULONG_PTR  Length,
ULONG_PTR  Granularity,
BOOLEAN  TopDown 
)

Definition at line 210 of file marea.c.

215 {
217  PMM_AVL_TABLE VadRoot;
220  ULONG_PTR StartingAddress, HighestAddress;
221 
223  VadRoot = Process ? &Process->VadRoot : &MiRosKernelVadRoot;
224  if (TopDown)
225  {
226  /* Find an address top-down */
227  HighestAddress = Process ? (ULONG_PTR)MM_HIGHEST_VAD_ADDRESS : (LONG_PTR)-1;
229  HighestAddress,
230  Granularity,
231  VadRoot,
232  &StartingAddress,
233  &Parent);
234  }
235  else
236  {
238  Granularity,
239  VadRoot,
240  &Parent,
241  &StartingAddress);
242  }
243 
244  if (Result == TableFoundNode)
245  {
246  return NULL;
247  }
248 
249  return (PVOID)StartingAddress;
250 }
MM_AVL_TABLE MiRosKernelVadRoot
Definition: marea.c:54
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)
Definition: vadnode.c:597
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG AddressSpace
Definition: iofuncs.h:2268
enum _TABLE_SEARCH_RESULT TABLE_SEARCH_RESULT
ACPI_PHYSICAL_ADDRESS ACPI_SIZE BOOLEAN Warn BOOLEAN Physical UINT32 ACPI_TABLE_HEADER *OutTableHeader ACPI_TABLE_HEADER **OutTable ACPI_HANDLE UINT32 ACPI_WALK_CALLBACK ACPI_WALK_CALLBACK void void **ReturnValue UINT32 ACPI_BUFFER *RetPathPtr ACPI_OBJECT_HANDLER void *Data ACPI_OBJECT_HANDLER void **Data ACPI_STRING ACPI_OBJECT_LIST ACPI_BUFFER *ReturnObjectBuffer ACPI_DEVICE_INFO **ReturnBuffer ACPI_HANDLE Parent
Definition: acpixf.h:728
uint32_t ULONG_PTR
Definition: typedefs.h:64
TABLE_SEARCH_RESULT NTAPI MiFindEmptyAddressRangeInTree(IN SIZE_T Length, IN ULONG_PTR Alignment, IN PMM_AVL_TABLE Table, OUT PMMADDRESS_NODE *PreviousVad, OUT PULONG_PTR Base)
Definition: vadnode.c:502
smooth NULL
Definition: ftsmooth.c:416
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
FORCEINLINE PEPROCESS MmGetAddressSpaceOwner(IN PMMSUPPORT AddressSpace)
Definition: mm.h:1438
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
#define MM_HIGHEST_VAD_ADDRESS
Definition: mm.h:46
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
#define ULONG_PTR
Definition: config.h:101

Referenced by MmCreateMemoryArea(), and MmMapViewOfSection().

◆ MmFreeMemoryArea()

NTSTATUS NTAPI MmFreeMemoryArea ( PMMSUPPORT  AddressSpace,
PMEMORY_AREA  MemoryArea,
PMM_FREE_PAGE_FUNC  FreePage,
PVOID  FreePageContext 
)

Definition at line 278 of file marea.c.

283 {
285  PVOID EndAddress;
286 
287  /* Make sure we own the address space lock! */
288  ASSERT(CONTAINING_RECORD(AddressSpace, EPROCESS, Vm)->AddressCreationLock.Owner == KeGetCurrentThread());
289 
290  /* Check magic */
291  ASSERT(MemoryArea->Magic == 'erAM');
292 
294  {
297 
298  if (Process != NULL &&
300  {
301  KeAttachProcess(&Process->Pcb);
302  }
303 
306  Address < (ULONG_PTR)EndAddress;
307  Address += PAGE_SIZE)
308  {
309  BOOLEAN Dirty = FALSE;
310  SWAPENTRY SwapEntry = 0;
311  PFN_NUMBER Page = 0;
312 
314  {
316  }
317  else
318  {
319  MmDeleteVirtualMapping(Process, (PVOID)Address, &Dirty, &Page);
320  }
321  if (FreePage != NULL)
322  {
323  FreePage(FreePageContext, MemoryArea, (PVOID)Address,
324  Page, SwapEntry, (BOOLEAN)Dirty);
325  }
326 #if (_MI_PAGING_LEVELS == 2)
327  /* Remove page table reference */
329  if ((SwapEntry || Page) && ((PVOID)Address < MmSystemRangeStart))
330  {
333  {
334  /* No PTE relies on this PDE. Release it */
336  PMMPDE PointerPde = MiAddressToPde(Address);
337  ASSERT(PointerPde->u.Hard.Valid == 1);
338  MiDeletePte(PointerPde, MiPdeToPte(PointerPde), Process, NULL);
339  ASSERT(PointerPde->u.Hard.Valid == 0);
341  }
342  }
343 #endif
344  }
345 
346  if (Process != NULL &&
348  {
349  KeDetachProcess();
350  }
351 
352  //if (MemoryArea->VadNode.StartingVpn < (ULONG_PTR)MmSystemRangeStart >> PAGE_SHIFT
353  if (MemoryArea->Vad)
354  {
357 
358  /* MmCleanProcessAddressSpace might have removed it (and this would be MmDeleteProcessAdressSpace) */
360  if (((PMMVAD)MemoryArea->Vad)->u.VadFlags.Spare == 1)
361  {
363  }
364 
365  MemoryArea->Vad = NULL;
366  }
367  else
368  {
370  }
371  }
372 
373 #if DBG
374  MemoryArea->Magic = 'daeD';
375 #endif
377 
378  DPRINT("MmFreeMemoryArea() succeeded\n");
379 
380  return STATUS_SUCCESS;
381 }
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
MM_AVL_TABLE MiRosKernelVadRoot
Definition: marea.c:54
#define PAGE_SHIFT
Definition: env_spec_w32.h:45
VOID NTAPI MiRemoveNode(IN PMMADDRESS_NODE Node, IN PMM_AVL_TABLE Table)
Definition: vadnode.c:360
ULONG Type
Definition: mm.h:214
#define MiAddressToPde(x)
Definition: mmx86.c:20
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG AddressSpace
Definition: iofuncs.h:2268
FORCEINLINE KIRQL MiAcquirePfnLock(VOID)
Definition: mm.h:901
FORCEINLINE USHORT MiQueryPageTableReferences(IN PVOID Address)
Definition: miarm.h:1687
VOID NTAPI MmDeletePageFileMapping(struct _EPROCESS *Process, PVOID Address, SWAPENTRY *SwapEntry)
MMVAD_FLAGS VadFlags
Definition: mmtypes.h:738
FORCEINLINE VOID MiReleasePfnLock(_In_ KIRQL OldIrql)
Definition: mm.h:908
#define MEMORY_AREA_CACHE
Definition: mm.h:72
VOID NTAPI MiDeletePte(IN PMMPTE PointerPte, IN PVOID VirtualAddress, IN PEPROCESS CurrentProcess, IN PMMPTE PrototypePte)
Definition: virtual.c:391
uint32_t ULONG_PTR
Definition: typedefs.h:64
UCHAR KIRQL
Definition: env_spec_w32.h:591
ULONG_PTR EndingVpn
Definition: mmtypes.h:734
ULONG Magic
Definition: mm.h:218
ULONG PFN_NUMBER
Definition: ke.h:8
#define MEMORY_AREA_OWNED_BY_ARM3
Definition: mm.h:73
#define TAG_MAREA
Definition: tag.h:120
#define PsGetCurrentProcess
Definition: psfuncs.h:17
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
static WCHAR Address[46]
Definition: ping.c:68
union _MMVAD::@2536 u
VOID NTAPI MmDeleteVirtualMapping(struct _EPROCESS *Process, PVOID Address, BOOLEAN *WasDirty, PPFN_NUMBER Page)
void DPRINT(...)
Definition: polytest.cpp:61
union _MMPTE::@2276 u
#define MEMORY_AREA_SECTION_VIEW
Definition: mm.h:71
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
#define MM_ROUND_UP(x, s)
Definition: mm.h:108
ULONG CurrentProcess
Definition: shell.c:125
ULONG64 Valid
Definition: mmtypes.h:150
#define MA_GetEndingAddress(_MemoryArea)
Definition: mm.h:208
BOOLEAN NTAPI MmIsPageSwapEntry(struct _EPROCESS *Process, PVOID Address)
MMVAD VadNode
Definition: mm.h:212
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
VOID NTAPI KeDetachProcess(VOID)
Definition: procobj.c:618
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define MA_GetStartingAddress(_MemoryArea)
Definition: mm.h:207
MMPTE_HARDWARE Hard
Definition: mmtypes.h:217
FORCEINLINE PMMSUPPORT MmGetKernelAddressSpace(VOID)
Definition: mm.h:1453
#define MiPdeToPte(_Pde)
Definition: mm.h:235
VOID NTAPI KeAttachProcess(IN PKPROCESS Process)
Definition: procobj.c:579
ULONG_PTR SWAPENTRY
Definition: mm.h:47
FORCEINLINE PEPROCESS MmGetAddressSpaceOwner(IN PMMSUPPORT AddressSpace)
Definition: mm.h:1438
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
ULONG_PTR Spare
Definition: mmtypes.h:701
#define ULONG_PTR
Definition: config.h:101
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define KeGetCurrentThread
Definition: hal.h:44
return STATUS_SUCCESS
Definition: btrfs.c:3014
PVOID Vad
Definition: mm.h:219
#define APC_LEVEL
Definition: env_spec_w32.h:695
#define MmSystemRangeStart
Definition: mm.h:32

Referenced by CcRosInternalFreeVacb(), MiRemoveNode(), MmUnmapViewOfCacheSegment(), and MmUnmapViewOfSegment().

◆ MmInsertMemoryArea()

static VOID MmInsertMemoryArea ( PMMSUPPORT  AddressSpace,
PMEMORY_AREA  marea 
)
static

Definition at line 166 of file marea.c.

169 {
171 
172  marea->VadNode.u.VadFlags.Spare = 1;
174 
175  /* Build a lame VAD if this is a user-space allocation */
177  {
178  ASSERT(Process != NULL);
179  if (marea->Type != MEMORY_AREA_OWNED_BY_ARM3)
180  {
182 
183  /* Insert the VAD */
185  MiInsertVad(&marea->VadNode, &Process->VadRoot);
187  marea->Vad = &marea->VadNode;
188  }
189  }
190  else
191  {
192  ASSERT(Process == NULL);
193 
195  {
199  }
200 
201  /* Insert the VAD */
205  marea->Vad = NULL;
206  }
207 }
MM_AVL_TABLE MiRosKernelVadRoot
Definition: marea.c:54
ULONG NTAPI MiMakeProtectionMask(IN ULONG Protect)
Definition: section.c:158
#define PAGE_SHIFT
Definition: env_spec_w32.h:45
#define TRUE
Definition: types.h:120
ULONG Type
Definition: mm.h:214
FORCEINLINE VOID MiUnlockProcessWorkingSetUnsafe(IN PEPROCESS Process, IN PETHREAD Thread)
Definition: miarm.h:1205
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG AddressSpace
Definition: iofuncs.h:2268
ULONG_PTR Unused
Definition: mmtypes.h:668
ULONG_PTR Protection
Definition: mmtypes.h:700
MMVAD_FLAGS VadFlags
Definition: mmtypes.h:738
#define MEMORY_AREA_CACHE
Definition: mm.h:72
MMADDRESS_NODE BalancedRoot
Definition: mmtypes.h:666
uint32_t ULONG_PTR
Definition: typedefs.h:64
ULONG_PTR EndingVpn
Definition: mmtypes.h:734
#define MEMORY_AREA_OWNED_BY_ARM3
Definition: mm.h:73
union _MMADDRESS_NODE::@2534 u1
#define PsGetCurrentProcess
Definition: psfuncs.h:17
MMSUPPORT MmSystemCacheWs
Definition: init.c:55
smooth NULL
Definition: ftsmooth.c:416
ULONG Protect
Definition: mm.h:215
union _MMVAD::@2536 u
FORCEINLINE VOID MiUnlockWorkingSet(IN PETHREAD Thread, IN PMMSUPPORT WorkingSet)
Definition: miarm.h:1275
#define MEMORY_AREA_SECTION_VIEW
Definition: mm.h:71
FORCEINLINE VOID MiLockProcessWorkingSetUnsafe(IN PEPROCESS Process, IN PETHREAD Thread)
Definition: miarm.h:1135
MMVAD VadNode
Definition: mm.h:212
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
BOOLEAN MiRosKernelVadRootInitialized
Definition: marea.c:55
FORCEINLINE PEPROCESS MmGetAddressSpaceOwner(IN PMMSUPPORT AddressSpace)
Definition: mm.h:1438
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
ULONG_PTR Spare
Definition: mmtypes.h:701
VOID NTAPI MiInsertVad(IN PMMVAD Vad, IN PMM_AVL_TABLE VadRoot)
Definition: vadnode.c:183
FORCEINLINE VOID MiLockWorkingSet(IN PETHREAD Thread, IN PMMSUPPORT WorkingSet)
Definition: miarm.h:1231
PVOID Vad
Definition: mm.h:219
#define MmSystemRangeStart
Definition: mm.h:32
struct _MMADDRESS_NODE * Parent
Definition: mmtypes.h:653

Referenced by MmCreateMemoryArea().

◆ MmLocateMemoryAreaByAddress()

PMEMORY_AREA NTAPI MmLocateMemoryAreaByAddress ( PMMSUPPORT  AddressSpace,
PVOID  Address_ 
)

Definition at line 60 of file marea.c.

63 {
64  ULONG_PTR StartVpn = (ULONG_PTR)Address_ / PAGE_SIZE;
70  PMMVAD_LONG Vad;
71 
73  Table = (Process != NULL) ? &Process->VadRoot : &MiRosKernelVadRoot;
74 
75  Result = MiCheckForConflictingNode(StartVpn, StartVpn, Table, &Node);
76  if (Result != TableFoundNode)
77  {
78  return NULL;
79  }
80 
81  Vad = (PMMVAD_LONG)Node;
82  if (Vad->u.VadFlags.Spare == 0)
83  {
84  /* Check if this is VM VAD */
85  if (Vad->ControlArea == NULL)
86  {
87  /* We store the reactos MEMORY_AREA here */
89  }
90  else
91  {
92  /* This is a section VAD. Store the MAREA here for now */
94  }
95  }
96  else
97  {
99  }
100 
101  return MemoryArea;
102 }
MM_AVL_TABLE MiRosKernelVadRoot
Definition: marea.c:54
ASMGENDATA Table[]
Definition: genincdata.c:61
struct _MEMORY_AREA * PMEMORY_AREA
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG AddressSpace
Definition: iofuncs.h:2268
MMVAD_FLAGS VadFlags
Definition: mmtypes.h:767
enum _TABLE_SEARCH_RESULT TABLE_SEARCH_RESULT
PCONTROL_AREA ControlArea
Definition: mmtypes.h:769
uint32_t ULONG_PTR
Definition: typedefs.h:64
union _MMVAD_LONG::@2542 u4
union node Node
Definition: types.h:1255
smooth NULL
Definition: ftsmooth.c:416
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
PVOID Banked
Definition: mmtypes.h:784
TABLE_SEARCH_RESULT NTAPI MiCheckForConflictingNode(IN ULONG_PTR StartVpn, IN ULONG_PTR EndVpn, IN PMM_AVL_TABLE Table, OUT PMMADDRESS_NODE *NodeOrParent)
Definition: vadnode.c:78
union _MMVAD_LONG::@2539 u
struct _MMVAD_LONG * PMMVAD_LONG
#define PAGE_SIZE
Definition: env_spec_w32.h:49
FORCEINLINE PEPROCESS MmGetAddressSpaceOwner(IN PMMSUPPORT AddressSpace)
Definition: mm.h:1438
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
ULONG_PTR Spare
Definition: mmtypes.h:701
PMMPTE FirstPrototypePte
Definition: mmtypes.h:770
#define ULONG_PTR
Definition: config.h:101
struct _MEMORY_AREA * MemoryArea
Definition: newmm.h:65
Definition: dlist.c:348

Referenced by _MiFlushMappedSection(), KdbSymPrintAddress(), MiProtectVirtualMemory(), MiQueryMemoryBasicInformation(), MiRosProtectVirtualMemory(), MiRosUnmapViewOfSection(), MiUnmapViewOfSection(), MmAccessFault(), MmAlterViewAttributes(), MmNotPresentFault(), MmNotPresentFaultCacheSectionInner(), MmpAccessFault(), MmPageOutPhysicalAddress(), MmpPageOutPhysicalAddress(), MmpSectionAccessFaultInner(), MmUnmapViewInSystemSpace(), MmUnmapViewOfCacheSegment(), MmUnmapViewOfSegment(), NtAllocateVirtualMemory(), and NtFreeVirtualMemory().

◆ MmLocateMemoryAreaByRegion()

PMEMORY_AREA NTAPI MmLocateMemoryAreaByRegion ( PMMSUPPORT  AddressSpace,
PVOID  Address_,
ULONG_PTR  Length 
)

Definition at line 106 of file marea.c.

110 {
111  ULONG_PTR StartVpn = (ULONG_PTR)Address_ / PAGE_SIZE;
112  ULONG_PTR EndVpn = ((ULONG_PTR)Address_ + Length - 1) / PAGE_SIZE;
118  PMMVAD_LONG Vad;
119 
121  Table = (Process != NULL) ? &Process->VadRoot : &MiRosKernelVadRoot;
122 
123  Result = MiCheckForConflictingNode(StartVpn, EndVpn, Table, &Node);
124  if (Result != TableFoundNode)
125  {
126  return NULL;
127  }
128 
129  Vad = (PMMVAD_LONG)Node;
130  if (Vad->u.VadFlags.Spare == 0)
131  {
132  /* Check if this is VM VAD */
133  if (Vad->ControlArea == NULL)
134  {
135  /* We store the reactos MEMORY_AREA here */
137  }
138  else
139  {
140  /* This is a section VAD. Store the MAREA here for now */
142  }
143  }
144  else
145  {
147  }
148 
149  ASSERT(MemoryArea != NULL);
150  return MemoryArea;
151 }
MM_AVL_TABLE MiRosKernelVadRoot
Definition: marea.c:54
ASMGENDATA Table[]
Definition: genincdata.c:61
struct _MEMORY_AREA * PMEMORY_AREA
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG AddressSpace
Definition: iofuncs.h:2268
MMVAD_FLAGS VadFlags
Definition: mmtypes.h:767
enum _TABLE_SEARCH_RESULT TABLE_SEARCH_RESULT
PCONTROL_AREA ControlArea
Definition: mmtypes.h:769
uint32_t ULONG_PTR
Definition: typedefs.h:64
union _MMVAD_LONG::@2542 u4
union node Node
Definition: types.h:1255
smooth NULL
Definition: ftsmooth.c:416
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
PVOID Banked
Definition: mmtypes.h:784
TABLE_SEARCH_RESULT NTAPI MiCheckForConflictingNode(IN ULONG_PTR StartVpn, IN ULONG_PTR EndVpn, IN PMM_AVL_TABLE Table, OUT PMMADDRESS_NODE *NodeOrParent)
Definition: vadnode.c:78
union _MMVAD_LONG::@2539 u
struct _MMVAD_LONG * PMMVAD_LONG
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define PAGE_SIZE
Definition: env_spec_w32.h:49
FORCEINLINE PEPROCESS MmGetAddressSpaceOwner(IN PMMSUPPORT AddressSpace)
Definition: mm.h:1438
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
ULONG_PTR Spare
Definition: mmtypes.h:701
PMMPTE FirstPrototypePte
Definition: mmtypes.h:770
#define ULONG_PTR
Definition: config.h:101
struct _MEMORY_AREA * MemoryArea
Definition: newmm.h:65
Definition: dlist.c:348

Referenced by MmCreateMemoryArea(), and MmMapViewOfSection().

Variable Documentation

◆ MiRosKernelVadRoot

◆ MiRosKernelVadRootInitialized

BOOLEAN MiRosKernelVadRootInitialized

Definition at line 55 of file marea.c.

Referenced by MmInsertMemoryArea().

◆ MiStaticMemoryAreaCount

ULONG MiStaticMemoryAreaCount

Definition at line 52 of file marea.c.

Referenced by MmCreateMemoryArea().

◆ MiStaticMemoryAreas

MEMORY_AREA MiStaticMemoryAreas[MI_STATIC_MEMORY_AREAS]

Definition at line 51 of file marea.c.

Referenced by MmCreateMemoryArea().