ReactOS 0.4.15-dev-8227-g32d615f
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
#define PAGE_SIZE
Definition: env_spec_w32.h:49
Status
Definition: gdiplustypes.h:25
#define ASSERT(a)
Definition: mode.c:44
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define PAGE_READWRITE
Definition: nt_native.h:1304
#define PAGE_EXECUTE_READWRITE
Definition: nt_native.h:1308
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
#define MEMORY_AREA_STATIC
Definition: mm.h:98
#define MEMORY_AREA_OWNED_BY_ARM3
Definition: mm.h:97
FORCEINLINE PMMSUPPORT MmGetKernelAddressSpace(VOID)
Definition: mm.h:1726
#define STATUS_SUCCESS
Definition: shellext.h:65
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533

Referenced by MiInitSystemMemoryAreas().

◆ MiDbgDumpAddressSpace()

VOID NTAPI MiDbgDumpAddressSpace ( VOID  )

Definition at line 130 of file mminit.c.

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

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
72
73#ifdef _M_AMD64
74 // Reserved range FFFF800000000000 - FFFFF68000000000
76#endif /* _M_AMD64 */
77
78 // The loader mappings. The only Executable area.
80
81 // The PTE base
83
84 // Hyperspace
86
87 // Protect the PFN database
89
90 // ReactOS requires a memory area to keep the initial NP area off-bounds
92
93 // System PTE space
95
96 // Nonpaged pool expansion space
98
99 // System view space
101
102 // Session space
104
105 // Paged pool
107
108 // Debugger mapping
110
111#if defined(_X86_)
112 // Reserved HAL area (includes KUSER_SHARED_DATA and KPCR)
114#else /* _X86_ */
115#ifndef _M_AMD64
116 // KPCR, one page per CPU. Only for 32-bit kernel.
118#endif /* _M_AMD64 */
119
120 // KUSER_SHARED_DATA
122#endif /* _X86_ */
123
125}
PFN_COUNT MmNumberOfSystemPtes
Definition: mminit.c:181
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
CCHAR KeNumberProcessors
Definition: krnlinit.c:35
VOID NTAPI MiCreateArm3StaticMemoryArea(PVOID BaseAddress, SIZE_T Size, BOOLEAN Executable)
Definition: mminit.c:43
#define MM_HAL_VA_END
Definition: ketypes.h:338
#define MM_HAL_VA_START
Definition: ketypes.h:337
#define MI_REAL_SYSTEM_RANGE_START
Definition: mm.h:12
#define MI_DEBUG_MAPPING
Definition: mm.h:20
#define PCR
Definition: ke.h:8
FORCEINLINE VOID MmLockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1691
FORCEINLINE VOID MmUnlockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1704
#define KI_USER_SHARED_DATA

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);
644 *NrFreed < Target && Entry != &MiSegmentList;
645 Entry = Entry->Flink) {
647 /* Defer to MM to try recovering pages from it */
649 *NrFreed += Freed;
650 }
651 DPRINT1("Evicted %lu cache pages\n", Target);
652
653 if (!IsListEmpty(&MiSegmentList)) {
657 }
658
659 return STATUS_SUCCESS;
660}
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
#define InsertTailList(ListHead, Entry)
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
base of all file and directory entries
Definition: entries.h:83
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
ULONG NTAPI MiCacheEvictPages(PMM_SECTION_SEGMENT Segment, ULONG Target)
Definition: swapout.c:590
LIST_ENTRY MiSegmentList
Definition: data.c:86
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
_In_ WDFIOTARGET Target
Definition: wdfrequest.h:306
_Inout_ PVOID Segment
Definition: exfuncs.h:1101

Referenced by MmInitSystem().

◆ MmInitBsmThread()

NTSTATUS NTAPI MmInitBsmThread ( VOID  )

Definition at line 182 of file mminit.c.

183{
186 HANDLE ThreadHandle;
187
188 /* Create the thread */
190 Status = PsCreateSystemThread(&ThreadHandle,
193 NULL,
194 NULL,
196 NULL);
197
198 /* Close the handle and return status */
199 ZwClose(ThreadHandle);
200 return Status;
201}
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define NULL
Definition: types.h:112
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
#define THREAD_ALL_ACCESS
Definition: nt_native.h:1339
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

Referenced by MmInitSystem().

◆ MmInitSystem()

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

Definition at line 206 of file mminit.c.

208{
209 extern MMPTE ValidKernelPte;
210 PMMPTE PointerPte;
212 PFN_NUMBER PageFrameNumber;
213 PLIST_ENTRY ListEntry;
214 PLDR_DATA_TABLE_ENTRY DataTableEntry;
215
216 /* Initialize the kernel address space */
217 ASSERT(Phase == 1);
218
219#ifdef NEWCC
223 // Until we're fully demand paged, we can do things the old way through
224 // the balance manager
225 // CcInitView will override this...
227#else
229#endif
230
232
233 /* Intialize system memory areas */
235
236 /* Dump the address space */
238
244
245 //
246 // Create a PTE to double-map the shared data section. We allocate it
247 // from paged pool so that we can't fault when trying to touch the PTE
248 // itself (to map it), since paged pool addresses will already be mapped
249 // by the fault handler.
250 //
252 sizeof(MMPTE),
253 TAG_MM);
254 if (!MmSharedUserDataPte) return FALSE;
255
256 //
257 // Now get the PTE for shared data, and read the PFN that holds it
258 //
260 ASSERT(PointerPte->u.Hard.Valid == 1);
261 PageFrameNumber = PFN_FROM_PTE(PointerPte);
262
263 /* Build the PTE and write it */
265 PointerPte,
267 PageFrameNumber);
269
270 /* Initialize session working set support */
272
273 /* Setup session IDs */
275
276 /* Setup the memory threshold events */
277 if (!MiInitializeMemoryEvents()) return FALSE;
278
279 /*
280 * Unmap low memory
281 */
283
284 /* Initialize the balance set manager */
286
287 /* Loop the boot loaded images (under lock) */
289 for (ListEntry = PsLoadedModuleList.Flink;
290 ListEntry != &PsLoadedModuleList;
291 ListEntry = ListEntry->Flink)
292 {
293 /* Get the data table entry */
294 DataTableEntry = CONTAINING_RECORD(ListEntry, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks);
295
296 /* Set up the image protection */
297 MiWriteProtectSystemImage(DataTableEntry->DllBase);
298 }
300
301 return TRUE;
302}
HARDWARE_PTE_ARMV6 TempPte
Definition: winldr.c:76
#define MM_READONLY
Definition: bootanim.c:18
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define ExAcquireResourceExclusiveLite(res, wait)
Definition: env_spec_w32.h:615
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define PagedPool
Definition: env_spec_w32.h:308
BOOLEAN NTAPI MiInitializeMemoryEvents(VOID)
Definition: mminit.c:1339
VOID NTAPI MiInitializeSessionIds(VOID)
Definition: session.c:116
VOID NTAPI MiWriteProtectSystemImage(_In_ PVOID ImageBase)
Definition: sysldr.c:2481
FORCEINLINE VOID MI_MAKE_HARDWARE_PTE_KERNEL(IN PMMPTE NewPte, IN PMMPTE MappingPte, IN ULONG_PTR ProtectionMask, IN PFN_NUMBER PageFrameNumber)
Definition: miarm.h:773
VOID NTAPI MiInitializeSessionWsSupport(VOID)
Definition: session.c:40
PMMSUPPORT MmKernelAddressSpace
Definition: mminit.c:27
FAST_MUTEX MiGlobalPageOperation
Definition: swapout.c:74
NTSTATUS MiRosTrimCache(ULONG Target, ULONG Priority, PULONG NrFreed)
Definition: swapout.c:633
PMMPTE MmSharedUserDataPte
Definition: mminit.c:26
VOID NTAPI MiInitSystemMemoryAreas(VOID)
Definition: mminit.c:65
NTSTATUS NTAPI MmInitBsmThread(VOID)
Definition: mminit.c:182
VOID NTAPI MiDbgDumpAddressSpace(VOID)
Definition: mminit.c:130
LIST_ENTRY MiSegmentList
Definition: data.c:86
KEVENT MmWaitPageEvent
Definition: fault.c:461
#define MiAddressToPte(x)
Definition: mmx86.c:19
@ SynchronizationEvent
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1822
#define PFN_FROM_PTE(v)
Definition: mm.h:92
#define MC_USER
Definition: mm.h:114
NTSTATUS MmTrimUserMemory(ULONG Target, ULONG Priority, PULONG NrFreedPages)
Definition: balance.c:138
VOID NTAPI MiInitBalancerThread(VOID)
Definition: balance.c:420
VOID NTAPI MmInitializeMemoryConsumer(ULONG Consumer, NTSTATUS(*Trim)(ULONG Target, ULONG Priority, PULONG NrFreed))
Definition: balance.c:57
NTSTATUS NTAPI MmInitSectionImplementation(VOID)
Definition: section.c:2294
VOID NTAPI MmInitializeRmapList(VOID)
Definition: rmap.c:38
VOID NTAPI MmInitGlobalKernelPageDirectory(VOID)
Definition: page.c:277
VOID NTAPI MmInitPagingFile(VOID)
Definition: pagefile.c:272
MMPTE ValidKernelPte
Definition: init.c:29
LIST_ENTRY PsLoadedModuleList
Definition: sysldr.c:21
ERESOURCE PsLoadedModuleResource
Definition: sysldr.c:24
PEPROCESS PsIdleProcess
Definition: psmgr.c:51
ULONG PFN_NUMBER
Definition: ke.h:9
MMSUPPORT Vm
Definition: pstypes.h:1356
Definition: btrfs_drv.h:1876
PVOID DllBase
Definition: btrfs_drv.h:1880
ULONG64 Valid
Definition: mmtypes.h:150
union _MMPTE::@2341 u
MMPTE_HARDWARE Hard
Definition: mmtypes.h:217
#define TAG_MM
Definition: tag.h:113
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274

Referenced by Phase1InitializationDiscard().

Variable Documentation

◆ MiGlobalPageOperation

FAST_MUTEX MiGlobalPageOperation
extern

Definition at line 74 of file swapout.c.

Referenced by MmInitSystem(), and MmpPageOutPhysicalAddress().

◆ MiSegmentList

LIST_ENTRY MiSegmentList
extern

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
extern

Definition at line 461 of file fault.c.

Referenced by MmInitSystem().