ReactOS  0.4.15-dev-3187-ge372f2b
mminit.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
#include "ARM3/miarm.h"
Include dependency graph for mminit.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define MODULE_INVOLVED_IN_ARM3
 

Functions

NTSTATUS MiRosTrimCache (ULONG Target, ULONG Priority, PULONG NrFreed)
 
VOID NTAPI MiCreateArm3StaticMemoryArea (PVOID BaseAddress, SIZE_T Size, BOOLEAN Executable)
 
VOID NTAPI MiInitSystemMemoryAreas (VOID)
 
VOID NTAPI MiDbgDumpAddressSpace (VOID)
 
NTSTATUS NTAPI MmInitBsmThread (VOID)
 
BOOLEAN NTAPI MmInitSystem (IN ULONG Phase, IN PLOADER_PARAMETER_BLOCK LoaderBlock)
 

Variables

BOOLEAN Mm64BitPhysicalAddress = FALSE
 
ULONG MmReadClusterSize
 
UCHAR MmDisablePagingExecutive = 1
 
PMMPTE MmSharedUserDataPte
 
PMMSUPPORT MmKernelAddressSpace
 
KEVENT MmWaitPageEvent
 
FAST_MUTEX MiGlobalPageOperation
 
LIST_ENTRY MiSegmentList
 

Macro Definition Documentation

◆ MODULE_INVOLVED_IN_ARM3

#define MODULE_INVOLVED_IN_ARM3

Definition at line 15 of file mminit.c.

◆ NDEBUG

#define NDEBUG

Definition at line 12 of file mminit.c.

Function Documentation

◆ MiCreateArm3StaticMemoryArea()

VOID NTAPI MiCreateArm3StaticMemoryArea ( PVOID  BaseAddress,
SIZE_T  Size,
BOOLEAN  Executable 
)

Definition at line 43 of file mminit.c.

44 {
45  const ULONG Protection = Executable ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE;
46  PVOID pBaseAddress = BaseAddress;
47  PMEMORY_AREA MArea;
49 
52  &pBaseAddress,
53  Size,
54  Protection,
55  &MArea,
56  0,
57  PAGE_SIZE);
59  // TODO: Perhaps it would be prudent to bugcheck here, not only assert?
60 }
LONG NTSTATUS
Definition: precomp.h:26
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
#define MEMORY_AREA_STATIC
Definition: mm.h:87
#define MEMORY_AREA_OWNED_BY_ARM3
Definition: mm.h:86
Status
Definition: gdiplustypes.h:24
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define ASSERT(a)
Definition: mode.c:44
NTSTATUS NTAPI MmCreateMemoryArea(PMMSUPPORT AddressSpace, ULONG Type, PVOID *BaseAddress, SIZE_T Length, ULONG Protection, PMEMORY_AREA *Result, ULONG AllocationFlags, ULONG AllocationGranularity)
Definition: marea.c:401
#define PAGE_SIZE
Definition: env_spec_w32.h:49
FORCEINLINE PMMSUPPORT MmGetKernelAddressSpace(VOID)
Definition: mm.h:1640
unsigned int ULONG
Definition: retypes.h:1
#define PAGE_EXECUTE_READWRITE
Definition: nt_native.h:1308
#define STATUS_SUCCESS
Definition: shellext.h:65
#define PAGE_READWRITE
Definition: nt_native.h:1304

Referenced by MiInitSystemMemoryAreas().

◆ MiDbgDumpAddressSpace()

VOID NTAPI MiDbgDumpAddressSpace ( VOID  )

Definition at line 126 of file mminit.c.

127 {
128  //
129  // Print the memory layout
130  //
131  DPRINT1(" 0x%p - 0x%p\t%s\n",
132  KSEG0_BASE,
134  "Boot Loaded Image");
135  DPRINT1(" 0x%p - 0x%p\t%s\n",
138  "PFN Database");
139  DPRINT1(" 0x%p - 0x%p\t%s\n",
142  "ARM3 Non Paged Pool");
143  DPRINT1(" 0x%p - 0x%p\t%s\n",
146  "System View Space");
147  DPRINT1(" 0x%p - 0x%p\t%s\n",
150  "Session Space");
151  DPRINT1(" 0x%p - 0x%p\t%s\n",
152  PTE_BASE, PTE_TOP,
153  "Page Tables");
154  DPRINT1(" 0x%p - 0x%p\t%s\n",
155  PDE_BASE, PDE_TOP,
156  "Page Directories");
157  DPRINT1(" 0x%p - 0x%p\t%s\n",
159  "Hyperspace");
160  DPRINT1(" 0x%p - 0x%p\t%s\n",
162  "System Cache");
163  DPRINT1(" 0x%p - 0x%p\t%s\n",
166  "ARM3 Paged Pool");
167  DPRINT1(" 0x%p - 0x%p\t%s\n",
169  "System PTE Space");
170  DPRINT1(" 0x%p - 0x%p\t%s\n",
172  "Non Paged Pool Expansion PTE Space");
173 }
#define PAGE_SHIFT
Definition: env_spec_w32.h:45
PVOID MmSessionBase
Definition: mminit.c:134
SIZE_T MmSizeOfNonPagedPoolInBytes
Definition: mminit.c:26
PMMPFN MmPfnDatabase
Definition: freelist.c:24
uint32_t ULONG_PTR
Definition: typedefs.h:65
PFN_NUMBER MxPfnAllocation
Definition: mminit.c:187
PVOID MiSessionSpaceEnd
Definition: mminit.c:127
#define KSEG0_BASE
Definition: ketypes.h:277
#define PDE_BASE
Definition: winldr.c:21
PVOID MiSystemViewStart
Definition: mminit.c:154
SIZE_T MmBootImageSize
Definition: mminit.c:222
PVOID MmSystemCacheEnd
Definition: mminit.c:244
PVOID MmPagedPoolStart
Definition: mminit.c:104
#define HYPER_SPACE_END
Definition: mm.h:15
#define PDE_TOP
Definition: mm.h:161
PVOID MmNonPagedSystemStart
Definition: mminit.c:96
#define PTE_BASE
Definition: mmx86.c:14
PVOID MmSystemCacheStart
Definition: mminit.c:243
#define DPRINT1
Definition: precomp.h:8
PVOID MmNonPagedPoolEnd
Definition: mminit.c:99
#define PTE_TOP
Definition: mm.h:154
#define HYPER_SPACE
Definition: mm.h:14
SIZE_T MmSizeOfPagedPoolInBytes
Definition: mminit.c:110
PVOID MmNonPagedPoolExpansionStart
Definition: mminit.c:98
PVOID MmNonPagedPoolStart
Definition: mminit.c:97
SIZE_T MmSystemViewSize
Definition: mminit.c:155

Referenced by MmInitSystem().

◆ MiInitSystemMemoryAreas()

VOID NTAPI MiInitSystemMemoryAreas ( VOID  )

Definition at line 65 of file mminit.c.

66 {
67  //
68  // Create all the static memory areas.
69  //
70 
71 #ifdef _M_AMD64
72  // Reserved range FFFF800000000000 - FFFFF68000000000
74 #endif /* _M_AMD64 */
75 
76  // The loader mappings. The only Executable area.
78 
79  // The PTE base
81 
82  // Hyperspace
84 
85  // Protect the PFN database
87 
88  // ReactOS requires a memory area to keep the initial NP area off-bounds
90 
91  // System PTE space
93 
94  // Nonpaged pool expansion space
96 
97  // System view space
99 
100  // Session space
102 
103  // Paged pool
105 
106  // Debugger mapping
108 
109 #if defined(_X86_)
110  // Reserved HAL area (includes KUSER_SHARED_DATA and KPCR)
112 #else /* _X86_ */
113 #ifndef _M_AMD64
114  // KPCR, one page per CPU. Only for 32-bit kernel.
116 #endif /* _M_AMD64 */
117 
118  // KUSER_SHARED_DATA
120 #endif /* _X86_ */
121 }
#define PAGE_SHIFT
Definition: env_spec_w32.h:45
#define MM_HAL_VA_START
Definition: ketypes.h:260
#define MM_HAL_VA_END
Definition: ketypes.h:261
PVOID MmSessionBase
Definition: mminit.c:134
#define TRUE
Definition: types.h:120
SIZE_T MmSizeOfNonPagedPoolInBytes
Definition: mminit.c:26
PMMPFN MmPfnDatabase
Definition: freelist.c:24
uint32_t ULONG_PTR
Definition: typedefs.h:65
PFN_NUMBER MxPfnAllocation
Definition: mminit.c:187
#define FALSE
Definition: types.h:117
PVOID MiSessionSpaceEnd
Definition: mminit.c:127
#define PCR
Definition: ke.h:8
#define KSEG0_BASE
Definition: ketypes.h:277
PVOID MiSystemViewStart
Definition: mminit.c:154
SIZE_T MmBootImageSize
Definition: mminit.c:222
#define MI_DEBUG_MAPPING
Definition: mm.h:20
PFN_COUNT MmNumberOfSystemPtes
Definition: mminit.c:181
#define MI_REAL_SYSTEM_RANGE_START
Definition: mm.h:12
PVOID MmPagedPoolStart
Definition: mminit.c:104
#define HYPER_SPACE_END
Definition: mm.h:15
PVOID MmNonPagedSystemStart
Definition: mminit.c:96
#define KI_USER_SHARED_DATA
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define PTE_BASE
Definition: mmx86.c:14
CCHAR KeNumberProcessors
Definition: krnlinit.c:35
PVOID MmNonPagedPoolEnd
Definition: mminit.c:99
#define PTE_TOP
Definition: mm.h:154
#define HYPER_SPACE
Definition: mm.h:14
SIZE_T MmSizeOfPagedPoolInBytes
Definition: mminit.c:110
VOID NTAPI MiCreateArm3StaticMemoryArea(PVOID BaseAddress, SIZE_T Size, BOOLEAN Executable)
Definition: mminit.c:43
PVOID MmNonPagedPoolExpansionStart
Definition: mminit.c:98
PVOID MmNonPagedPoolStart
Definition: mminit.c:97
SIZE_T MmSystemViewSize
Definition: mminit.c:155

Referenced by MmInitSystem().

◆ MiRosTrimCache()

NTSTATUS MiRosTrimCache ( ULONG  Target,
ULONG  Priority,
PULONG  NrFreed 
)

Definition at line 633 of file swapout.c.

636 {
637  ULONG Freed;
640  *NrFreed = 0;
641 
642  DPRINT1("Need to trim %lu cache pages\n", Target);
643  for (Entry = MiSegmentList.Flink;
644  *NrFreed < Target && Entry != &MiSegmentList;
645  Entry = Entry->Flink) {
647  /* Defer to MM to try recovering pages from it */
648  Freed = MiCacheEvictPages(Segment, Target);
649  *NrFreed += Freed;
650  }
651  DPRINT1("Evicted %lu cache pages\n", Target);
652 
653  if (!IsListEmpty(&MiSegmentList)) {
657  }
658 
659  return STATUS_SUCCESS;
660 }
struct _Entry Entry
Definition: kefuncs.h:627
#define InsertTailList(ListHead, Entry)
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
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
_Inout_ PVOID Segment
Definition: exfuncs.h:1101
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
LIST_ENTRY MiSegmentList
Definition: data.c:86
Definition: typedefs.h:119
ULONG NTAPI MiCacheEvictPages(PMM_SECTION_SEGMENT Segment, ULONG Target)
Definition: swapout.c:590
_In_ WDFIOTARGET Target
Definition: wdfrequest.h:306
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
#define STATUS_SUCCESS
Definition: shellext.h:65
base of all file and directory entries
Definition: entries.h:82

Referenced by MmInitSystem().

◆ MmInitBsmThread()

NTSTATUS NTAPI MmInitBsmThread ( VOID  )

Definition at line 178 of file mminit.c.

179 {
182  HANDLE ThreadHandle;
183 
184  /* Create the thread */
186  Status = PsCreateSystemThread(&ThreadHandle,
189  NULL,
190  NULL,
192  NULL);
193 
194  /* Close the handle and return status */
195  ZwClose(ThreadHandle);
196  return Status;
197 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define THREAD_ALL_ACCESS
Definition: nt_native.h:1339
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: gdiplustypes.h:24
VOID NTAPI KeBalanceSetManager(IN PVOID Context)
Definition: balmgr.c:137
NTSTATUS NTAPI PsCreateSystemThread(OUT PHANDLE ThreadHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, IN HANDLE ProcessHandle, IN PCLIENT_ID ClientId, IN PKSTART_ROUTINE StartRoutine, IN PVOID StartContext)
Definition: thread.c:602
#define NULL
Definition: types.h:112
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106

Referenced by MmInitSystem().

◆ MmInitSystem()

BOOLEAN NTAPI MmInitSystem ( IN ULONG  Phase,
IN PLOADER_PARAMETER_BLOCK  LoaderBlock 
)

Definition at line 202 of file mminit.c.

204 {
205  extern MMPTE ValidKernelPte;
206  PMMPTE PointerPte;
208  PFN_NUMBER PageFrameNumber;
209  PLIST_ENTRY ListEntry;
210  PLDR_DATA_TABLE_ENTRY DataTableEntry;
211 
212  /* Initialize the kernel address space */
213  ASSERT(Phase == 1);
214 
215 #ifdef NEWCC
219  // Until we're fully demand paged, we can do things the old way through
220  // the balance manager
221  // CcInitView will override this...
223 #else
225 #endif
226 
228 
229  /* Intialize system memory areas */
231 
232  /* Dump the address space */
234 
240 
241  //
242  // Create a PTE to double-map the shared data section. We allocate it
243  // from paged pool so that we can't fault when trying to touch the PTE
244  // itself (to map it), since paged pool addresses will already be mapped
245  // by the fault handler.
246  //
248  sizeof(MMPTE),
249  TAG_MM);
250  if (!MmSharedUserDataPte) return FALSE;
251 
252  //
253  // Now get the PTE for shared data, and read the PFN that holds it
254  //
256  ASSERT(PointerPte->u.Hard.Valid == 1);
257  PageFrameNumber = PFN_FROM_PTE(PointerPte);
258 
259  /* Build the PTE and write it */
261  PointerPte,
262  MM_READONLY,
263  PageFrameNumber);
265 
266  /* Initialize session working set support */
268 
269  /* Setup session IDs */
271 
272  /* Setup the memory threshold events */
273  if (!MiInitializeMemoryEvents()) return FALSE;
274 
275  /*
276  * Unmap low memory
277  */
279 
280  /* Initialize the balance set manager */
281  MmInitBsmThread();
282 
283  /* Loop the boot loaded images (under lock) */
285  for (ListEntry = PsLoadedModuleList.Flink;
286  ListEntry != &PsLoadedModuleList;
287  ListEntry = ListEntry->Flink)
288  {
289  /* Get the data table entry */
290  DataTableEntry = CONTAINING_RECORD(ListEntry, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks);
291 
292  /* Set up the image protection */
293  MiWriteProtectSystemImage(DataTableEntry->DllBase);
294  }
296 
297  return TRUE;
298 }
KEVENT MmWaitPageEvent
Definition: section.c:67
LIST_ENTRY MiSegmentList
Definition: data.c:86
FAST_MUTEX MiGlobalPageOperation
Definition: swapout.c:74
PMMPTE MmSharedUserDataPte
Definition: mminit.c:26
#define TRUE
Definition: types.h:120
#define MC_USER
Definition: mm.h:103
union _MMPTE::@2274 u
VOID NTAPI MiWriteProtectSystemImage(_In_ PVOID ImageBase)
Definition: sysldr.c:2443
BOOLEAN NTAPI MiInitializeMemoryEvents(VOID)
Definition: mminit.c:1339
NTSTATUS NTAPI MmInitBsmThread(VOID)
Definition: mminit.c:178
ERESOURCE PsLoadedModuleResource
Definition: sysldr.c:37
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
VOID NTAPI MiInitializeSessionWsSupport(VOID)
Definition: session.c:40
PVOID DllBase
Definition: btrfs_drv.h:1926
PEPROCESS PsIdleProcess
Definition: psmgr.c:51
VOID NTAPI MmInitializeMemoryConsumer(ULONG Consumer, NTSTATUS(*Trim)(ULONG Target, ULONG Priority, PULONG NrFreed))
Definition: balance.c:58
VOID NTAPI MmInitPagingFile(VOID)
Definition: pagefile.c:255
#define MiAddressToPte(x)
Definition: mmx86.c:19
ULONG PFN_NUMBER
Definition: ke.h:9
#define TAG_MM
Definition: tag.h:136
NTSTATUS NTAPI MmInitSectionImplementation(VOID)
Definition: section.c:2260
#define FALSE
Definition: types.h:117
VOID NTAPI MiInitializeSessionIds(VOID)
Definition: session.c:116
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_READONLY
Definition: inbv.c:11
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define ASSERT(a)
Definition: mode.c:44
LIST_ENTRY PsLoadedModuleList
Definition: sysldr.c:34
ULONG64 Valid
Definition: mmtypes.h:150
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274
HARDWARE_PTE_ARMV6 TempPte
Definition: winldr.c:76
MMPTE ValidKernelPte
Definition: init.c:29
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define KI_USER_SHARED_DATA
Definition: btrfs_drv.h:1922
NTSTATUS MiRosTrimCache(ULONG Target, ULONG Priority, PULONG NrFreed)
Definition: swapout.c:633
VOID NTAPI MiInitBalancerThread(VOID)
Definition: balance.c:361
Definition: typedefs.h:119
MMSUPPORT Vm
Definition: pstypes.h:1356
MMPTE_HARDWARE Hard
Definition: mmtypes.h:217
VOID NTAPI MiInitSystemMemoryAreas(VOID)
Definition: mminit.c:65
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
NTSTATUS MmTrimUserMemory(ULONG Target, ULONG Priority, PULONG NrFreedPages)
Definition: balance.c:138
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
VOID NTAPI MiDbgDumpAddressSpace(VOID)
Definition: mminit.c:126
FORCEINLINE VOID MI_MAKE_HARDWARE_PTE_KERNEL(IN PMMPTE NewPte, IN PMMPTE MappingPte, IN ULONG_PTR ProtectionMask, IN PFN_NUMBER PageFrameNumber)
Definition: miarm.h:778
VOID NTAPI MmInitGlobalKernelPageDirectory(VOID)
Definition: page.c:277
VOID NTAPI MmInitializeRmapList(VOID)
Definition: rmap.c:38
#define PFN_FROM_PTE(v)
Definition: mm.h:92
PMMSUPPORT MmKernelAddressSpace
Definition: mminit.c:27

Referenced by Phase1InitializationDiscard().

Variable Documentation

◆ MiGlobalPageOperation

FAST_MUTEX MiGlobalPageOperation

Definition at line 74 of file swapout.c.

Referenced by MmInitSystem(), and MmpPageOutPhysicalAddress().

◆ MiSegmentList

LIST_ENTRY MiSegmentList

Definition at line 86 of file data.c.

Referenced by MmInitSystem().

◆ Mm64BitPhysicalAddress

BOOLEAN Mm64BitPhysicalAddress = FALSE

Definition at line 20 of file mminit.c.

◆ MmDisablePagingExecutive

UCHAR MmDisablePagingExecutive = 1

Definition at line 25 of file mminit.c.

Referenced by MiEnablePagingOfDriver(), and MmPageEntireDriver().

◆ MmKernelAddressSpace

PMMSUPPORT MmKernelAddressSpace

Definition at line 27 of file mminit.c.

Referenced by MmGetAddressSpaceOwner(), MmGetKernelAddressSpace(), and MmInitSystem().

◆ MmReadClusterSize

ULONG MmReadClusterSize

Definition at line 21 of file mminit.c.

Referenced by PspCreateThread().

◆ MmSharedUserDataPte

PMMPTE MmSharedUserDataPte

Definition at line 26 of file mminit.c.

Referenced by MiCheckVirtualAddress(), and MmInitSystem().

◆ MmWaitPageEvent

KEVENT MmWaitPageEvent

Definition at line 67 of file section.c.

Referenced by MmInitSystem().