ReactOS  0.4.15-dev-318-g99b52df
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

VOID NTAPI MiInitializeUserPfnBitmap (VOID)
 
NTSTATUS MiRosTrimCache (ULONG Target, ULONG Priority, PULONG NrFreed)
 
INIT_FUNCTION VOID NTAPI MiCreateArm3StaticMemoryArea (PVOID BaseAddress, SIZE_T Size, BOOLEAN Executable)
 
INIT_FUNCTION VOID NTAPI MiInitSystemMemoryAreas (VOID)
 
INIT_FUNCTION VOID NTAPI MiDbgDumpAddressSpace (VOID)
 
INIT_FUNCTION NTSTATUS NTAPI MmInitBsmThread (VOID)
 
INIT_FUNCTION 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()

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

Definition at line 45 of file mminit.c.

46 {
47  const ULONG Protection = Executable ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE;
48  PVOID pBaseAddress = BaseAddress;
49  PMEMORY_AREA MArea;
51 
54  &pBaseAddress,
55  Size,
56  Protection,
57  &MArea,
58  0,
59  PAGE_SIZE);
61  // TODO: Perhaps it would be prudent to bugcheck here, not only assert?
62 }
LONG NTSTATUS
Definition: precomp.h:26
#define MEMORY_AREA_STATIC
Definition: mm.h:74
#define MEMORY_AREA_OWNED_BY_ARM3
Definition: mm.h:73
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
NTSTATUS NTAPI MmCreateMemoryArea(PMMSUPPORT AddressSpace, ULONG Type, PVOID *BaseAddress, SIZE_T Length, ULONG Protection, PMEMORY_AREA *Result, ULONG AllocationFlags, ULONG AllocationGranularity)
Definition: marea.c:410
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define PAGE_SIZE
Definition: env_spec_w32.h:49
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
Status
Definition: gdiplustypes.h:24
FORCEINLINE PMMSUPPORT MmGetKernelAddressSpace(VOID)
Definition: mm.h:1453
unsigned int ULONG
Definition: retypes.h:1
#define PAGE_EXECUTE_READWRITE
Definition: nt_native.h:1308
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define PAGE_READWRITE
Definition: nt_native.h:1304

Referenced by MiInitSystemMemoryAreas().

◆ MiDbgDumpAddressSpace()

INIT_FUNCTION VOID NTAPI MiDbgDumpAddressSpace ( VOID  )

Definition at line 123 of file mminit.c.

124 {
125  //
126  // Print the memory layout
127  //
128  DPRINT1(" 0x%p - 0x%p\t%s\n",
129  KSEG0_BASE,
131  "Boot Loaded Image");
132  DPRINT1(" 0x%p - 0x%p\t%s\n",
135  "PFN Database");
136  DPRINT1(" 0x%p - 0x%p\t%s\n",
139  "ARM3 Non Paged Pool");
140  DPRINT1(" 0x%p - 0x%p\t%s\n",
143  "System View Space");
144  DPRINT1(" 0x%p - 0x%p\t%s\n",
147  "Session Space");
148  DPRINT1(" 0x%p - 0x%p\t%s\n",
149  PTE_BASE, PTE_TOP,
150  "Page Tables");
151  DPRINT1(" 0x%p - 0x%p\t%s\n",
152  PDE_BASE, PDE_TOP,
153  "Page Directories");
154  DPRINT1(" 0x%p - 0x%p\t%s\n",
156  "Hyperspace");
157  DPRINT1(" 0x%p - 0x%p\t%s\n",
159  "System Cache");
160  DPRINT1(" 0x%p - 0x%p\t%s\n",
163  "ARM3 Paged Pool");
164  DPRINT1(" 0x%p - 0x%p\t%s\n",
166  "System PTE Space");
167  DPRINT1(" 0x%p - 0x%p\t%s\n",
169  "Non Paged Pool Expansion PTE Space");
170 }
#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:64
PFN_NUMBER MxPfnAllocation
Definition: mminit.c:187
PVOID MiSessionSpaceEnd
Definition: mminit.c:127
#define KSEG0_BASE
Definition: ketypes.h:273
#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().

◆ MiInitializeUserPfnBitmap()

VOID NTAPI MiInitializeUserPfnBitmap ( VOID  )

Definition at line 44 of file freelist.c.

45 {
46  PVOID Bitmap;
47 
48  /* Allocate enough buffer for the PFN bitmap and align it on 32-bits */
50  (((MmHighestPhysicalPage + 1) + 31) / 32) * 4,
51  TAG_MM);
52  ASSERT(Bitmap);
53 
54  /* Initialize it and clear all the bits to begin with */
56  Bitmap,
59 }
NTSYSAPI void WINAPI RtlInitializeBitMap(PRTL_BITMAP, PULONG, ULONG)
#define TAG_MM
Definition: tag.h:136
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
NTSYSAPI void WINAPI RtlClearAllBits(PRTL_BITMAP)
unsigned int ULONG
Definition: retypes.h:1
static RTL_BITMAP MiUserPfnBitMap
Definition: freelist.c:38
PFN_NUMBER MmHighestPhysicalPage
Definition: meminit.c:31

Referenced by MmInitSystem().

◆ MiInitSystemMemoryAreas()

INIT_FUNCTION VOID NTAPI MiInitSystemMemoryAreas ( VOID  )

Definition at line 67 of file mminit.c.

68 {
69  //
70  // Create all the static memory areas.
71  //
72 
73  // The loader mappings. The only Executable area.
75 
76  // The PTE base
78 
79  // Hyperspace
81 
82  // Protect the PFN database
84 
85  // ReactOS requires a memory area to keep the initial NP area off-bounds
87 
88  // System PTE space
90 
91  // Nonpaged pool expansion space
93 
94  // System view space
96 
97  // Session space
99 
100  // Paged pool
102 
103  // Debugger mapping
105 
106 #if defined(_X86_)
107  // Reserved HAL area (includes KUSER_SHARED_DATA and KPCR)
109 #else /* _X86_ */
110 #ifndef _M_AMD64
111  // KPCR, one page per CPU. Only for 32-bit kernel.
113 #endif /* _M_AMD64 */
114 
115  // KUSER_SHARED_DATA
117 #endif /* _X86_ */
118 }
#define PAGE_SHIFT
Definition: env_spec_w32.h:45
#define MM_HAL_VA_START
Definition: ketypes.h:256
#define TRUE
Definition: types.h:120
INIT_FUNCTION VOID NTAPI MiCreateArm3StaticMemoryArea(PVOID BaseAddress, SIZE_T Size, BOOLEAN Executable)
Definition: mminit.c:45
#define MM_HAL_VA_END
Definition: ketypes.h:257
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:64
PFN_NUMBER MxPfnAllocation
Definition: mminit.c:187
PVOID MiSessionSpaceEnd
Definition: mminit.c:127
#define PCR
Definition: ke.h:8
#define KSEG0_BASE
Definition: ketypes.h:273
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
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
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:893
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120
_Must_inspect_result_ typedef _In_ ULONG _In_ BOOLEAN Target
Definition: iotypes.h:1068
LIST_ENTRY MiSegmentList
Definition: data.c:86
Definition: typedefs.h:118
ULONG NTAPI MiCacheEvictPages(PMM_SECTION_SEGMENT Segment, ULONG Target)
Definition: swapout.c:590
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:3014
base of all file and directory entries
Definition: entries.h:82

Referenced by MmInitSystem().

◆ MmInitBsmThread()

INIT_FUNCTION NTSTATUS NTAPI MmInitBsmThread ( VOID  )

Definition at line 175 of file mminit.c.

176 {
179  HANDLE ThreadHandle;
180 
181  /* Create the thread */
183  Status = PsCreateSystemThread(&ThreadHandle,
186  NULL,
187  NULL,
189  NULL);
190 
191  /* Close the handle and return status */
192  ZwClose(ThreadHandle);
193  return Status;
194 }
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
smooth NULL
Definition: ftsmooth.c:416
VOID NTAPI KeBalanceSetManager(IN PVOID Context)
Definition: balmgr.c:137
Status
Definition: gdiplustypes.h:24
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 InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106

Referenced by MmInitSystem().

◆ MmInitSystem()

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

Definition at line 199 of file mminit.c.

201 {
202  extern MMPTE ValidKernelPte;
203  PMMPTE PointerPte;
205  PFN_NUMBER PageFrameNumber;
206  PLIST_ENTRY ListEntry;
207  PLDR_DATA_TABLE_ENTRY DataTableEntry;
208 
209  /* Initialize the kernel address space */
210  ASSERT(Phase == 1);
211 
215  // Until we're fully demand paged, we can do things the old way through
216  // the balance manager
218 
220 
221  /* Intialize system memory areas */
223 
224  /* Dump the address space */
226 
233 
234  //
235  // Create a PTE to double-map the shared data section. We allocate it
236  // from paged pool so that we can't fault when trying to touch the PTE
237  // itself (to map it), since paged pool addresses will already be mapped
238  // by the fault handler.
239  //
241  sizeof(MMPTE),
242  TAG_MM);
243  if (!MmSharedUserDataPte) return FALSE;
244 
245  //
246  // Now get the PTE for shared data, and read the PFN that holds it
247  //
249  ASSERT(PointerPte->u.Hard.Valid == 1);
250  PageFrameNumber = PFN_FROM_PTE(PointerPte);
251 
252  /* Build the PTE and write it */
254  PointerPte,
255  MM_READONLY,
256  PageFrameNumber);
258 
259  /* Initialize session working set support */
261 
262  /* Setup session IDs */
264 
265  /* Setup the memory threshold events */
266  if (!MiInitializeMemoryEvents()) return FALSE;
267 
268  /*
269  * Unmap low memory
270  */
272 
273  /* Initialize the balance set manager */
274  MmInitBsmThread();
275 
276  /* Loop the boot loaded images */
277  for (ListEntry = PsLoadedModuleList.Flink;
278  ListEntry != &PsLoadedModuleList;
279  ListEntry = ListEntry->Flink)
280  {
281  /* Get the data table entry */
282  DataTableEntry = CONTAINING_RECORD(ListEntry, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks);
283 
284  /* Set up the image protection */
285  MiWriteProtectSystemImage(DataTableEntry->DllBase);
286  }
287 
288  return TRUE;
289 }
KEVENT MmWaitPageEvent
LIST_ENTRY MiSegmentList
Definition: data.c:86
#define TRUE
Definition: types.h:120
INIT_FUNCTION NTSTATUS NTAPI MmInitSectionImplementation(VOID)
Definition: section.c:2806
VOID NTAPI MiInitializeUserPfnBitmap(VOID)
Definition: freelist.c:44
FAST_MUTEX MiGlobalPageOperation
Definition: swapout.c:74
PMMPTE MmSharedUserDataPte
Definition: mminit.c:28
#define MC_USER
Definition: mm.h:94
INIT_FUNCTION FORCEINLINE VOID MmInitGlobalKernelPageDirectory(VOID)
Definition: mm.h:299
VOID NTAPI MiWriteProtectSystemImage(_In_ PVOID ImageBase)
Definition: sysldr.c:2431
INIT_FUNCTION VOID NTAPI MiInitBalancerThread(VOID)
Definition: balance.c:449
INIT_FUNCTION VOID NTAPI MiInitSystemMemoryAreas(VOID)
Definition: mminit.c:67
VOID NTAPI MiInitializeSessionWsSupport(VOID)
Definition: session.c:40
PVOID DllBase
Definition: btrfs_drv.h:1926
PEPROCESS PsIdleProcess
Definition: psmgr.c:51
#define MiAddressToPte(x)
Definition: mmx86.c:19
ULONG PFN_NUMBER
Definition: ke.h:8
#define TAG_MM
Definition: tag.h:136
VOID NTAPI MiInitializeSessionIds(VOID)
Definition: session.c:117
INIT_FUNCTION NTSTATUS NTAPI MmInitBsmThread(VOID)
Definition: mminit.c:175
INIT_FUNCTION BOOLEAN NTAPI MiInitializeMemoryEvents(VOID)
Definition: mminit.c:1339
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:120
INIT_FUNCTION VOID NTAPI MmInitializeRmapList(VOID)
Definition: rmap.c:43
INIT_FUNCTION VOID NTAPI MmInitializeMemoryConsumer(ULONG Consumer, NTSTATUS(*Trim)(ULONG Target, ULONG Priority, PULONG NrFreed))
Definition: balance.c:82
INIT_FUNCTION VOID NTAPI MmInitPagingFile(VOID)
Definition: pagefile.c:259
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
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
union _MMPTE::@2280 u
#define KI_USER_SHARED_DATA
Definition: btrfs_drv.h:1922
NTSTATUS MiRosTrimCache(ULONG Target, ULONG Priority, PULONG NrFreed)
Definition: swapout.c:633
Definition: typedefs.h:118
MMSUPPORT Vm
Definition: pstypes.h:1295
MMPTE_HARDWARE Hard
Definition: mmtypes.h:217
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
NTSTATUS MmTrimUserMemory(ULONG Target, ULONG Priority, PULONG NrFreedPages)
Definition: balance.c:178
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
INIT_FUNCTION VOID NTAPI MiDbgDumpAddressSpace(VOID)
Definition: mminit.c:123
#define MC_CACHE
Definition: mm.h:93
FORCEINLINE VOID MI_MAKE_HARDWARE_PTE_KERNEL(IN PMMPTE NewPte, IN PMMPTE MappingPte, IN ULONG_PTR ProtectionMask, IN PFN_NUMBER PageFrameNumber)
Definition: miarm.h:774
#define PFN_FROM_PTE(v)
Definition: mm.h:92
PMMSUPPORT MmKernelAddressSpace
Definition: mminit.c:29

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 MmCreateCacheSection(), and MmInitSystem().

◆ Mm64BitPhysicalAddress

BOOLEAN Mm64BitPhysicalAddress = FALSE

Definition at line 22 of file mminit.c.

◆ MmDisablePagingExecutive

UCHAR MmDisablePagingExecutive = 1

Definition at line 27 of file mminit.c.

Referenced by MiEnablePagingOfDriver(), and MmPageEntireDriver().

◆ MmKernelAddressSpace

PMMSUPPORT MmKernelAddressSpace

Definition at line 29 of file mminit.c.

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

◆ MmReadClusterSize

ULONG MmReadClusterSize

Definition at line 23 of file mminit.c.

Referenced by PspCreateThread().

◆ MmSharedUserDataPte

PMMPTE MmSharedUserDataPte

Definition at line 28 of file mminit.c.

Referenced by MiCheckVirtualAddress(), and MmInitSystem().

◆ MmWaitPageEvent

KEVENT MmWaitPageEvent

Referenced by MmInitSystem().