[NTOSKRNL]
[reactos.git] / ntoskrnl / mm / ARM3 / miarm.h
1 /*
2 * PROJECT: ReactOS Kernel
3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * FILE: ntoskrnl/mm/ARM3/miarm.h
5 * PURPOSE: ARM Memory Manager Header
6 * PROGRAMMERS: ReactOS Portable Systems Group
7 */
8
9 #define MI_MIN_PAGES_FOR_NONPAGED_POOL_TUNING ((255*1024*1024) >> PAGE_SHIFT)
10 #define MI_MIN_PAGES_FOR_SYSPTE_TUNING ((19*1024*1024) >> PAGE_SHIFT)
11 #define MI_MIN_PAGES_FOR_SYSPTE_BOOST ((32*1024*1024) >> PAGE_SHIFT)
12 #define MI_MAX_INIT_NONPAGED_POOL_SIZE (128 * 1024 * 1024)
13 #define MI_MAX_NONPAGED_POOL_SIZE (128 * 1024 * 1024)
14 #define MI_MAX_FREE_PAGE_LISTS 4
15
16 #define MI_MIN_INIT_PAGED_POOLSIZE (32 * 1024 * 1024)
17
18 #define MI_SESSION_VIEW_SIZE (20 * 1024 * 1024)
19 #define MI_SESSION_POOL_SIZE (16 * 1024 * 1024)
20 #define MI_SESSION_IMAGE_SIZE (8 * 1024 * 1024)
21 #define MI_SESSION_WORKING_SET_SIZE (4 * 1024 * 1024)
22 #define MI_SESSION_SIZE (MI_SESSION_VIEW_SIZE + \
23 MI_SESSION_POOL_SIZE + \
24 MI_SESSION_IMAGE_SIZE + \
25 MI_SESSION_WORKING_SET_SIZE)
26
27 #define MI_SYSTEM_VIEW_SIZE (16 * 1024 * 1024)
28
29 #define MI_SYSTEM_CACHE_WS_START (PVOID)0xC0C00000
30 #define MI_PAGED_POOL_START (PVOID)0xE1000000
31 #define MI_NONPAGED_POOL_END (PVOID)0xFFBE0000
32 #define MI_DEBUG_MAPPING (PVOID)0xFFBFF000
33
34 #define MI_MIN_SECONDARY_COLORS 8
35 #define MI_SECONDARY_COLORS 64
36 #define MI_MAX_SECONDARY_COLORS 1024
37
38 #define MM_HIGHEST_VAD_ADDRESS \
39 (PVOID)((ULONG_PTR)MM_HIGHEST_USER_ADDRESS - (16 * PAGE_SIZE))
40
41 /* Make the code cleaner with some definitions for size multiples */
42 #define _1KB (1024)
43 #define _1MB (1024 * _1KB)
44
45 /* Area mapped by a PDE */
46 #define PDE_MAPPED_VA (PTE_COUNT * PAGE_SIZE)
47
48 /* Size of a page table */
49 #define PT_SIZE (PTE_COUNT * sizeof(MMPTE))
50
51 /* Architecture specific count of PDEs in a directory, and count of PTEs in a PT */
52 #ifdef _M_IX86
53 #define PD_COUNT 1
54 #define PDE_COUNT 1024
55 #define PTE_COUNT 1024
56 #elif _M_ARM
57 #define PD_COUNT 1
58 #define PDE_COUNT 4096
59 #define PTE_COUNT 256
60 #else
61 #error Define these please!
62 #endif
63
64 #ifdef _M_IX86
65 #define IMAGE_FILE_MACHINE_NATIVE IMAGE_FILE_MACHINE_I386
66 #elif _M_ARM
67 #define IMAGE_FILE_MACHINE_NATIVE IMAGE_FILE_MACHINE_ARM
68 #elif _M_AMD64
69 #define IMAGE_FILE_MACHINE_NATIVE IMAGE_FILE_MACHINE_AMD64
70 #else
71 #error Define these please!
72 #endif
73
74 //
75 // Protection Bits part of the internal memory manager Protection Mask
76 // Taken from http://www.reactos.org/wiki/Techwiki:Memory_management_in_the_Windows_XP_kernel
77 // and public assertions.
78 //
79 #define MM_ZERO_ACCESS 0
80 #define MM_READONLY 1
81 #define MM_EXECUTE 2
82 #define MM_EXECUTE_READ 3
83 #define MM_READWRITE 4
84 #define MM_WRITECOPY 5
85 #define MM_EXECUTE_READWRITE 6
86 #define MM_EXECUTE_WRITECOPY 7
87 #define MM_NOCACHE 8
88 #define MM_DECOMMIT 0x10
89 #define MM_NOACCESS (MM_DECOMMIT | MM_NOCACHE)
90
91 //
92 // Assertions for session images, addresses, and PTEs
93 //
94 #define MI_IS_SESSION_IMAGE_ADDRESS(Address) \
95 (((Address) >= MiSessionImageStart) && ((Address) < MiSessionImageEnd))
96
97 #define MI_IS_SESSION_ADDRESS(Address) \
98 (((Address) >= MmSessionBase) && ((Address) < MiSessionSpaceEnd))
99
100 #define MI_IS_SESSION_PTE(Pte) \
101 ((((PMMPTE)Pte) >= MiSessionBasePte) && (((PMMPTE)Pte) < MiSessionLastPte))
102
103 //
104 // Corresponds to MMPTE_SOFTWARE.Protection
105 //
106 #ifdef _M_IX86
107 #define MM_PTE_SOFTWARE_PROTECTION_BITS 5
108 #elif _M_ARM
109 #define MM_PTE_SOFTWARE_PROTECTION_BITS 5
110 #elif _M_AMD64
111 #define MM_PTE_SOFTWARE_PROTECTION_BITS 5
112 #else
113 #error Define these please!
114 #endif
115
116 //
117 // Creates a software PTE with the given protection
118 //
119 #define MI_MAKE_SOFTWARE_PTE(p, x) ((p)->u.Long = (x << MM_PTE_SOFTWARE_PROTECTION_BITS))
120
121 //
122 // Special values for LoadedImports
123 //
124 #define MM_SYSLDR_NO_IMPORTS (PVOID)0xFFFFFFFE
125 #define MM_SYSLDR_BOOT_LOADED (PVOID)0xFFFFFFFF
126 #define MM_SYSLDR_SINGLE_ENTRY 0x1
127
128 //
129 // PFN List Sentinel
130 //
131 #define LIST_HEAD 0xFFFFFFFF
132
133 //
134 // Special IRQL value (found in assertions)
135 //
136 #define MM_NOIRQL (KIRQL)0xFFFFFFFF
137
138 //
139 // FIXFIX: These should go in ex.h after the pool merge
140 //
141 #define POOL_LISTS_PER_PAGE (PAGE_SIZE / sizeof(LIST_ENTRY))
142 #define BASE_POOL_TYPE_MASK 1
143 #define POOL_MAX_ALLOC (PAGE_SIZE - (sizeof(POOL_HEADER) + sizeof(LIST_ENTRY)))
144
145 typedef struct _POOL_DESCRIPTOR
146 {
147 POOL_TYPE PoolType;
148 ULONG PoolIndex;
149 ULONG RunningAllocs;
150 ULONG RunningDeAllocs;
151 ULONG TotalPages;
152 ULONG TotalBigPages;
153 ULONG Threshold;
154 PVOID LockAddress;
155 PVOID PendingFrees;
156 LONG PendingFreeDepth;
157 SIZE_T TotalBytes;
158 SIZE_T Spare0;
159 LIST_ENTRY ListHeads[POOL_LISTS_PER_PAGE];
160 } POOL_DESCRIPTOR, *PPOOL_DESCRIPTOR;
161
162 typedef struct _POOL_HEADER
163 {
164 union
165 {
166 struct
167 {
168 USHORT PreviousSize:9;
169 USHORT PoolIndex:7;
170 USHORT BlockSize:9;
171 USHORT PoolType:7;
172 };
173 ULONG Ulong1;
174 };
175 union
176 {
177 ULONG PoolTag;
178 struct
179 {
180 USHORT AllocatorBackTraceIndex;
181 USHORT PoolTagHash;
182 };
183 };
184 } POOL_HEADER, *PPOOL_HEADER;
185
186 //
187 // Everything depends on this
188 //
189 C_ASSERT(sizeof(POOL_HEADER) == 8);
190 C_ASSERT(sizeof(POOL_HEADER) == sizeof(LIST_ENTRY));
191
192 extern ULONG ExpNumberOfPagedPools;
193 extern POOL_DESCRIPTOR NonPagedPoolDescriptor;
194 extern PPOOL_DESCRIPTOR ExpPagedPoolDescriptor[16 + 1];
195 extern PVOID PoolTrackTable;
196
197 //
198 // END FIXFIX
199 //
200
201 typedef struct _MI_LARGE_PAGE_DRIVER_ENTRY
202 {
203 LIST_ENTRY Links;
204 UNICODE_STRING BaseName;
205 } MI_LARGE_PAGE_DRIVER_ENTRY, *PMI_LARGE_PAGE_DRIVER_ENTRY;
206
207 typedef enum _MMSYSTEM_PTE_POOL_TYPE
208 {
209 SystemPteSpace,
210 NonPagedPoolExpansion,
211 MaximumPtePoolTypes
212 } MMSYSTEM_PTE_POOL_TYPE;
213
214 typedef enum _MI_PFN_CACHE_ATTRIBUTE
215 {
216 MiNonCached,
217 MiCached,
218 MiWriteCombined,
219 MiNotMapped
220 } MI_PFN_CACHE_ATTRIBUTE, *PMI_PFN_CACHE_ATTRIBUTE;
221
222 typedef struct _PHYSICAL_MEMORY_RUN
223 {
224 ULONG BasePage;
225 ULONG PageCount;
226 } PHYSICAL_MEMORY_RUN, *PPHYSICAL_MEMORY_RUN;
227
228 typedef struct _PHYSICAL_MEMORY_DESCRIPTOR
229 {
230 ULONG NumberOfRuns;
231 ULONG NumberOfPages;
232 PHYSICAL_MEMORY_RUN Run[1];
233 } PHYSICAL_MEMORY_DESCRIPTOR, *PPHYSICAL_MEMORY_DESCRIPTOR;
234
235 typedef struct _MMCOLOR_TABLES
236 {
237 PFN_NUMBER Flink;
238 PVOID Blink;
239 PFN_NUMBER Count;
240 } MMCOLOR_TABLES, *PMMCOLOR_TABLES;
241
242 typedef struct _MI_LARGE_PAGE_RANGES
243 {
244 PFN_NUMBER StartFrame;
245 PFN_NUMBER LastFrame;
246 } MI_LARGE_PAGE_RANGES, *PMI_LARGE_PAGE_RANGES;
247
248 extern MMPTE HyperTemplatePte;
249 extern MMPDE ValidKernelPde;
250 extern MMPTE ValidKernelPte;
251 extern BOOLEAN MmLargeSystemCache;
252 extern BOOLEAN MmZeroPageFile;
253 extern BOOLEAN MmProtectFreedNonPagedPool;
254 extern BOOLEAN MmTrackLockedPages;
255 extern BOOLEAN MmTrackPtes;
256 extern BOOLEAN MmDynamicPfn;
257 extern BOOLEAN MmMirroring;
258 extern BOOLEAN MmMakeLowMemory;
259 extern BOOLEAN MmEnforceWriteProtection;
260 extern ULONG MmAllocationFragment;
261 extern ULONG MmConsumedPoolPercentage;
262 extern ULONG MmVerifyDriverBufferType;
263 extern ULONG MmVerifyDriverLevel;
264 extern WCHAR MmVerifyDriverBuffer[512];
265 extern WCHAR MmLargePageDriverBuffer[512];
266 extern LIST_ENTRY MiLargePageDriverList;
267 extern BOOLEAN MiLargePageAllDrivers;
268 extern ULONG MmVerifyDriverBufferLength;
269 extern ULONG MmLargePageDriverBufferLength;
270 extern ULONG MmSizeOfNonPagedPoolInBytes;
271 extern ULONG MmMaximumNonPagedPoolInBytes;
272 extern PFN_NUMBER MmMaximumNonPagedPoolInPages;
273 extern PFN_NUMBER MmSizeOfPagedPoolInPages;
274 extern PVOID MmNonPagedSystemStart;
275 extern PVOID MmNonPagedPoolStart;
276 extern PVOID MmNonPagedPoolExpansionStart;
277 extern PVOID MmNonPagedPoolEnd;
278 extern ULONG MmSizeOfPagedPoolInBytes;
279 extern PVOID MmPagedPoolStart;
280 extern PVOID MmPagedPoolEnd;
281 extern PVOID MmSessionBase;
282 extern ULONG MmSessionSize;
283 extern PMMPTE MmFirstReservedMappingPte, MmLastReservedMappingPte;
284 extern PMMPTE MiFirstReservedZeroingPte;
285 extern MI_PFN_CACHE_ATTRIBUTE MiPlatformCacheAttributes[2][MmMaximumCacheType];
286 extern PPHYSICAL_MEMORY_DESCRIPTOR MmPhysicalMemoryBlock;
287 extern ULONG MmBootImageSize;
288 extern PMMPTE MmSystemPtesStart[MaximumPtePoolTypes];
289 extern PMMPTE MmSystemPtesEnd[MaximumPtePoolTypes];
290 extern PMEMORY_ALLOCATION_DESCRIPTOR MxFreeDescriptor;
291 extern MEMORY_ALLOCATION_DESCRIPTOR MxOldFreeDescriptor;
292 extern ULONG MxPfnAllocation;
293 extern MM_PAGED_POOL_INFO MmPagedPoolInfo;
294 extern RTL_BITMAP MiPfnBitMap;
295 extern KGUARDED_MUTEX MmPagedPoolMutex;
296 extern PVOID MmPagedPoolStart;
297 extern PVOID MmPagedPoolEnd;
298 extern PVOID MmNonPagedSystemStart;
299 extern PVOID MiSystemViewStart;
300 extern ULONG MmSystemViewSize;
301 extern PVOID MmSessionBase;
302 extern PVOID MiSessionSpaceEnd;
303 extern PMMPTE MiSessionImagePteStart;
304 extern PMMPTE MiSessionImagePteEnd;
305 extern PMMPTE MiSessionBasePte;
306 extern PMMPTE MiSessionLastPte;
307 extern ULONG MmSizeOfPagedPoolInBytes;
308 extern PMMPTE MmSystemPagePtes;
309 extern PVOID MmSystemCacheStart;
310 extern PVOID MmSystemCacheEnd;
311 extern MMSUPPORT MmSystemCacheWs;
312 extern SIZE_T MmAllocatedNonPagedPool;
313 extern ULONG_PTR MmSubsectionBase;
314 extern ULONG MmSpecialPoolTag;
315 extern PVOID MmHyperSpaceEnd;
316 extern PMMWSL MmSystemCacheWorkingSetList;
317 extern ULONG MmMinimumNonPagedPoolSize;
318 extern ULONG MmMinAdditionNonPagedPoolPerMb;
319 extern ULONG MmDefaultMaximumNonPagedPool;
320 extern ULONG MmMaxAdditionNonPagedPoolPerMb;
321 extern ULONG MmSecondaryColors;
322 extern ULONG MmSecondaryColorMask;
323 extern ULONG MmNumberOfSystemPtes;
324 extern ULONG MmMaximumNonPagedPoolPercent;
325 extern ULONG MmLargeStackSize;
326 extern PMMCOLOR_TABLES MmFreePagesByColor[FreePageList + 1];
327 extern ULONG MmProductType;
328 extern MM_SYSTEMSIZE MmSystemSize;
329 extern PKEVENT MiLowMemoryEvent;
330 extern PKEVENT MiHighMemoryEvent;
331 extern PKEVENT MiLowPagedPoolEvent;
332 extern PKEVENT MiHighPagedPoolEvent;
333 extern PKEVENT MiLowNonPagedPoolEvent;
334 extern PKEVENT MiHighNonPagedPoolEvent;
335 extern PFN_NUMBER MmLowMemoryThreshold;
336 extern PFN_NUMBER MmHighMemoryThreshold;
337 extern PFN_NUMBER MiLowPagedPoolThreshold;
338 extern PFN_NUMBER MiHighPagedPoolThreshold;
339 extern PFN_NUMBER MiLowNonPagedPoolThreshold;
340 extern PFN_NUMBER MiHighNonPagedPoolThreshold;
341 extern PFN_NUMBER MmMinimumFreePages;
342 extern PFN_NUMBER MmPlentyFreePages;
343 extern PFN_NUMBER MiExpansionPoolPagesInitialCharge;
344 extern PFN_NUMBER MmResidentAvailablePages;
345 extern PFN_NUMBER MmResidentAvailableAtInit;
346 extern ULONG MmTotalFreeSystemPtes[MaximumPtePoolTypes];
347 extern PFN_NUMBER MmTotalSystemDriverPages;
348 extern PVOID MiSessionImageStart;
349 extern PVOID MiSessionImageEnd;
350 extern PMMPTE MiHighestUserPte;
351 extern PMMPDE MiHighestUserPde;
352 extern PFN_NUMBER MmSystemPageDirectory[PD_COUNT];
353
354 #define MI_PFN_TO_PFNENTRY(x) (&MmPfnDatabase[1][x])
355 #define MI_PFNENTRY_TO_PFN(x) (x - MmPfnDatabase[1])
356
357 //
358 // Returns if the page is physically resident (ie: a large page)
359 // FIXFIX: CISC/x86 only?
360 //
361 FORCEINLINE
362 BOOLEAN
363 MI_IS_PHYSICAL_ADDRESS(IN PVOID Address)
364 {
365 PMMPDE PointerPde;
366
367 /* Large pages are never paged out, always physically resident */
368 PointerPde = MiAddressToPde(Address);
369 return ((PointerPde->u.Hard.LargePage) && (PointerPde->u.Hard.Valid));
370 }
371
372 NTSTATUS
373 NTAPI
374 MmArmInitSystem(
375 IN ULONG Phase,
376 IN PLOADER_PARAMETER_BLOCK LoaderBlock
377 );
378
379 NTSTATUS
380 NTAPI
381 MiInitMachineDependent(
382 IN PLOADER_PARAMETER_BLOCK LoaderBlock
383 );
384
385 VOID
386 NTAPI
387 MiComputeColorInformation(
388 VOID
389 );
390
391 VOID
392 NTAPI
393 MiMapPfnDatabase(
394 IN PLOADER_PARAMETER_BLOCK LoaderBlock
395 );
396
397 VOID
398 NTAPI
399 MiInitializeColorTables(
400 VOID
401 );
402
403 VOID
404 NTAPI
405 MiInitializePfnDatabase(
406 IN PLOADER_PARAMETER_BLOCK LoaderBlock
407 );
408
409 BOOLEAN
410 NTAPI
411 MiInitializeMemoryEvents(
412 VOID
413 );
414
415 PFN_NUMBER
416 NTAPI
417 MxGetNextPage(
418 IN PFN_NUMBER PageCount
419 );
420
421 PPHYSICAL_MEMORY_DESCRIPTOR
422 NTAPI
423 MmInitializeMemoryLimits(
424 IN PLOADER_PARAMETER_BLOCK LoaderBlock,
425 IN PBOOLEAN IncludeType
426 );
427
428 PFN_NUMBER
429 NTAPI
430 MiPagesInLoaderBlock(
431 IN PLOADER_PARAMETER_BLOCK LoaderBlock,
432 IN PBOOLEAN IncludeType
433 );
434
435 VOID
436 FASTCALL
437 MiSyncARM3WithROS(
438 IN PVOID AddressStart,
439 IN PVOID AddressEnd
440 );
441
442 NTSTATUS
443 NTAPI
444 MmArmAccessFault(
445 IN BOOLEAN StoreInstruction,
446 IN PVOID Address,
447 IN KPROCESSOR_MODE Mode,
448 IN PVOID TrapInformation
449 );
450
451 NTSTATUS
452 FASTCALL
453 MiCheckPdeForPagedPool(
454 IN PVOID Address
455 );
456
457 VOID
458 NTAPI
459 MiInitializeNonPagedPool(
460 VOID
461 );
462
463 VOID
464 NTAPI
465 MiInitializeNonPagedPoolThresholds(
466 VOID
467 );
468
469 VOID
470 NTAPI
471 MiInitializePoolEvents(
472 VOID
473 );
474
475 VOID //
476 NTAPI //
477 InitializePool( //
478 IN POOL_TYPE PoolType,// FIXFIX: This should go in ex.h after the pool merge
479 IN ULONG Threshold //
480 ); //
481
482 VOID
483 NTAPI
484 MiInitializeSystemPtes(
485 IN PMMPTE StartingPte,
486 IN ULONG NumberOfPtes,
487 IN MMSYSTEM_PTE_POOL_TYPE PoolType
488 );
489
490 PMMPTE
491 NTAPI
492 MiReserveSystemPtes(
493 IN ULONG NumberOfPtes,
494 IN MMSYSTEM_PTE_POOL_TYPE SystemPtePoolType
495 );
496
497 VOID
498 NTAPI
499 MiReleaseSystemPtes(
500 IN PMMPTE StartingPte,
501 IN ULONG NumberOfPtes,
502 IN MMSYSTEM_PTE_POOL_TYPE SystemPtePoolType
503 );
504
505
506 PFN_NUMBER
507 NTAPI
508 MiFindContiguousPages(
509 IN PFN_NUMBER LowestPfn,
510 IN PFN_NUMBER HighestPfn,
511 IN PFN_NUMBER BoundaryPfn,
512 IN PFN_NUMBER SizeInPages,
513 IN MEMORY_CACHING_TYPE CacheType
514 );
515
516 PVOID
517 NTAPI
518 MiCheckForContiguousMemory(
519 IN PVOID BaseAddress,
520 IN PFN_NUMBER BaseAddressPages,
521 IN PFN_NUMBER SizeInPages,
522 IN PFN_NUMBER LowestPfn,
523 IN PFN_NUMBER HighestPfn,
524 IN PFN_NUMBER BoundaryPfn,
525 IN MI_PFN_CACHE_ATTRIBUTE CacheAttribute
526 );
527
528 PMDL
529 NTAPI
530 MiAllocatePagesForMdl(
531 IN PHYSICAL_ADDRESS LowAddress,
532 IN PHYSICAL_ADDRESS HighAddress,
533 IN PHYSICAL_ADDRESS SkipBytes,
534 IN SIZE_T TotalBytes,
535 IN MI_PFN_CACHE_ATTRIBUTE CacheAttribute,
536 IN ULONG Flags
537 );
538
539 PVOID
540 NTAPI
541 MiMapLockedPagesInUserSpace(
542 IN PMDL Mdl,
543 IN PVOID BaseVa,
544 IN MEMORY_CACHING_TYPE CacheType,
545 IN PVOID BaseAddress
546 );
547
548 VOID
549 NTAPI
550 MiUnmapLockedPagesInUserSpace(
551 IN PVOID BaseAddress,
552 IN PMDL Mdl
553 );
554
555 VOID
556 NTAPI
557 MiInsertInListTail(
558 IN PMMPFNLIST ListHead,
559 IN PMMPFN Entry
560 );
561
562 VOID
563 NTAPI
564 MiInsertZeroListAtBack(
565 IN PFN_NUMBER PageIndex
566 );
567
568 VOID
569 NTAPI
570 MiUnlinkFreeOrZeroedPage(
571 IN PMMPFN Entry
572 );
573
574 PMMPFN
575 NTAPI
576 MiRemoveHeadList(
577 IN PMMPFNLIST ListHead
578 );
579
580 PFN_NUMBER
581 NTAPI
582 MiAllocatePfn(
583 IN PMMPTE PointerPte,
584 IN ULONG Protection
585 );
586
587 PFN_NUMBER
588 NTAPI
589 MiRemoveAnyPage(
590 IN ULONG Color
591 );
592
593 VOID
594 NTAPI
595 MiInsertPageInFreeList(
596 IN PFN_NUMBER PageFrameIndex
597 );
598
599 PLDR_DATA_TABLE_ENTRY
600 NTAPI
601 MiLookupDataTableEntry(
602 IN PVOID Address
603 );
604
605 VOID
606 NTAPI
607 MiInitializeDriverLargePageList(
608 VOID
609 );
610
611 VOID
612 NTAPI
613 MiInitializeLargePageSupport(
614 VOID
615 );
616
617 VOID
618 NTAPI
619 MiSyncCachedRanges(
620 VOID
621 );
622
623 BOOLEAN
624 NTAPI
625 MiIsPfnInUse(
626 IN PMMPFN Pfn1
627 );
628
629 /* EOF */