Fix the Release build by marking MmPageArraySize as unreferenced.
[reactos.git] / reactos / ntoskrnl / include / internal / mm.h
1 #ifndef __INCLUDE_INTERNAL_MM_H
2 #define __INCLUDE_INTERNAL_MM_H
3
4 #include <internal/arch/mm.h>
5
6 /* TYPES *********************************************************************/
7
8 struct _EPROCESS;
9
10 extern ULONG MiFreeSwapPages;
11 extern ULONG MiUsedSwapPages;
12 extern ULONG MmPagedPoolSize;
13 extern ULONG MmTotalPagedPoolQuota;
14 extern ULONG MmTotalNonPagedPoolQuota;
15 extern PHYSICAL_ADDRESS MmSharedDataPagePhysicalAddress;
16 extern ULONG MmNumberOfPhysicalPages;
17
18 extern PVOID MmPagedPoolBase;
19 extern ULONG MmPagedPoolSize;
20
21 extern PMEMORY_ALLOCATION_DESCRIPTOR MiFreeDescriptor;
22 extern MEMORY_ALLOCATION_DESCRIPTOR MiFreeDescriptorOrg;
23 extern ULONG MmHighestPhysicalPage;
24 extern PVOID MmPfnDatabase;
25
26 struct _KTRAP_FRAME;
27 struct _EPROCESS;
28 struct _MM_RMAP_ENTRY;
29 struct _MM_PAGEOP;
30 typedef ULONG SWAPENTRY;
31 typedef ULONG PFN_TYPE, *PPFN_TYPE;
32
33 #define MEMORY_AREA_INVALID (0)
34 #define MEMORY_AREA_SECTION_VIEW (1)
35 #define MEMORY_AREA_CONTINUOUS_MEMORY (2)
36 #define MEMORY_AREA_NO_CACHE (3)
37 #define MEMORY_AREA_IO_MAPPING (4)
38 #define MEMORY_AREA_SYSTEM (5)
39 #define MEMORY_AREA_MDL_MAPPING (7)
40 #define MEMORY_AREA_VIRTUAL_MEMORY (8)
41 #define MEMORY_AREA_CACHE_SEGMENT (9)
42 #define MEMORY_AREA_SHARED_DATA (10)
43 #define MEMORY_AREA_KERNEL_STACK (11)
44 #define MEMORY_AREA_PAGED_POOL (12)
45 #define MEMORY_AREA_NO_ACCESS (13)
46 #define MEMORY_AREA_PEB_OR_TEB (14)
47
48 #define MM_PHYSICAL_PAGE_MPW_PENDING (0x8)
49
50 #define MM_CORE_DUMP_TYPE_NONE (0x0)
51 #define MM_CORE_DUMP_TYPE_MINIMAL (0x1)
52 #define MM_CORE_DUMP_TYPE_FULL (0x2)
53
54 #define MM_PAGEOP_PAGEIN (1)
55 #define MM_PAGEOP_PAGEOUT (2)
56 #define MM_PAGEOP_PAGESYNCH (3)
57 #define MM_PAGEOP_ACCESSFAULT (4)
58
59 /* Number of list heads to use */
60 #define MI_FREE_POOL_LISTS 4
61
62 /* Signature of free pool blocks */
63 #define MM_FREE_POOL_TAG TAG('F', 'r', 'p', 'l')
64
65 #define PAGE_TO_SECTION_PAGE_DIRECTORY_OFFSET(x) \
66 ((x) / (4*1024*1024))
67
68 #define PAGE_TO_SECTION_PAGE_TABLE_OFFSET(x) \
69 ((((x)) % (4*1024*1024)) / (4*1024))
70
71 #define NR_SECTION_PAGE_TABLES 1024
72 #define NR_SECTION_PAGE_ENTRIES 1024
73
74 #define TEB_BASE 0x7FFDE000
75
76 /* Although Microsoft says this isn't hardcoded anymore,
77 they won't be able to change it. Stuff depends on it */
78 #define MM_VIRTMEM_GRANULARITY (64 * 1024)
79
80 #define STATUS_MM_RESTART_OPERATION ((NTSTATUS)0xD0000001)
81
82 /*
83 * Additional flags for protection attributes
84 */
85 #define PAGE_WRITETHROUGH (1024)
86 #define PAGE_SYSTEM (2048)
87
88 #define SEC_PHYSICALMEMORY (0x80000000)
89
90 #define MM_PAGEFILE_SEGMENT (0x1)
91 #define MM_DATAFILE_SEGMENT (0x2)
92
93 #define MC_CACHE (0)
94 #define MC_USER (1)
95 #define MC_PPOOL (2)
96 #define MC_NPPOOL (3)
97 #define MC_MAXIMUM (4)
98
99 #define PAGED_POOL_MASK 1
100 #define MUST_SUCCEED_POOL_MASK 2
101 #define CACHE_ALIGNED_POOL_MASK 4
102 #define QUOTA_POOL_MASK 8
103 #define SESSION_POOL_MASK 32
104 #define VERIFIER_POOL_MASK 64
105
106 #define MM_PAGED_POOL_SIZE (100*1024*1024)
107 #define MM_NONPAGED_POOL_SIZE (100*1024*1024)
108
109 /*
110 * Paged and non-paged pools are 8-byte aligned
111 */
112 #define MM_POOL_ALIGNMENT 8
113
114 /*
115 * Maximum size of the kmalloc area (this is totally arbitary)
116 */
117 #define MM_KERNEL_MAP_SIZE (16*1024*1024)
118 #define MM_KERNEL_MAP_BASE (0xf0c00000)
119
120 /*
121 * FIXME - different architectures have different cache line sizes...
122 */
123 #define MM_CACHE_LINE_SIZE 32
124
125 #define MM_ROUND_UP(x,s) \
126 ((PVOID)(((ULONG_PTR)(x)+(s)-1) & ~((ULONG_PTR)(s)-1)))
127
128 #define MM_ROUND_DOWN(x,s) \
129 ((PVOID)(((ULONG_PTR)(x)) & ~((ULONG_PTR)(s)-1)))
130
131 #define PAGE_FLAGS_VALID_FROM_USER_MODE \
132 (PAGE_READONLY | \
133 PAGE_READWRITE | \
134 PAGE_WRITECOPY | \
135 PAGE_EXECUTE | \
136 PAGE_EXECUTE_READ | \
137 PAGE_EXECUTE_READWRITE | \
138 PAGE_EXECUTE_WRITECOPY | \
139 PAGE_GUARD | \
140 PAGE_NOACCESS | \
141 PAGE_NOCACHE)
142
143 #define PAGE_IS_READABLE \
144 (PAGE_READONLY | \
145 PAGE_READWRITE | \
146 PAGE_WRITECOPY | \
147 PAGE_EXECUTE_READ | \
148 PAGE_EXECUTE_READWRITE | \
149 PAGE_EXECUTE_WRITECOPY)
150
151 #define PAGE_IS_WRITABLE \
152 (PAGE_READWRITE | \
153 PAGE_WRITECOPY | \
154 PAGE_EXECUTE_READWRITE | \
155 PAGE_EXECUTE_WRITECOPY)
156
157 #define PAGE_IS_EXECUTABLE \
158 (PAGE_EXECUTE | \
159 PAGE_EXECUTE_READ | \
160 PAGE_EXECUTE_READWRITE | \
161 PAGE_EXECUTE_WRITECOPY)
162
163 #define PAGE_IS_WRITECOPY \
164 (PAGE_WRITECOPY | \
165 PAGE_EXECUTE_WRITECOPY)
166
167 typedef struct
168 {
169 ULONG Entry[NR_SECTION_PAGE_ENTRIES];
170 } SECTION_PAGE_TABLE, *PSECTION_PAGE_TABLE;
171
172 typedef struct
173 {
174 PSECTION_PAGE_TABLE PageTables[NR_SECTION_PAGE_TABLES];
175 } SECTION_PAGE_DIRECTORY, *PSECTION_PAGE_DIRECTORY;
176
177 typedef struct _MM_SECTION_SEGMENT
178 {
179 LONG FileOffset; /* start offset into the file for image sections */
180 ULONG_PTR VirtualAddress; /* dtart offset into the address range for image sections */
181 ULONG RawLength; /* length of the segment which is part of the mapped file */
182 ULONG Length; /* absolute length of the segment */
183 ULONG Protection;
184 FAST_MUTEX Lock; /* lock which protects the page directory */
185 ULONG ReferenceCount;
186 SECTION_PAGE_DIRECTORY PageDirectory;
187 ULONG Flags;
188 ULONG Characteristics;
189 BOOLEAN WriteCopy;
190 } MM_SECTION_SEGMENT, *PMM_SECTION_SEGMENT;
191
192 typedef struct _MM_IMAGE_SECTION_OBJECT
193 {
194 ULONG_PTR ImageBase;
195 ULONG_PTR StackReserve;
196 ULONG_PTR StackCommit;
197 ULONG_PTR EntryPoint;
198 USHORT Subsystem;
199 USHORT ImageCharacteristics;
200 USHORT MinorSubsystemVersion;
201 USHORT MajorSubsystemVersion;
202 USHORT Machine;
203 BOOLEAN Executable;
204 ULONG NrSegments;
205 ULONG ImageSize;
206 PMM_SECTION_SEGMENT Segments;
207 } MM_IMAGE_SECTION_OBJECT, *PMM_IMAGE_SECTION_OBJECT;
208
209 typedef struct _ROS_SECTION_OBJECT
210 {
211 CSHORT Type;
212 CSHORT Size;
213 LARGE_INTEGER MaximumSize;
214 ULONG SectionPageProtection;
215 ULONG AllocationAttributes;
216 PFILE_OBJECT FileObject;
217 union
218 {
219 PMM_IMAGE_SECTION_OBJECT ImageSection;
220 PMM_SECTION_SEGMENT Segment;
221 };
222 } ROS_SECTION_OBJECT, *PROS_SECTION_OBJECT;
223
224 typedef struct _MEMORY_AREA
225 {
226 PVOID StartingAddress;
227 PVOID EndingAddress;
228 struct _MEMORY_AREA *Parent;
229 struct _MEMORY_AREA *LeftChild;
230 struct _MEMORY_AREA *RightChild;
231 ULONG Type;
232 ULONG Protect;
233 ULONG Flags;
234 BOOLEAN DeleteInProgress;
235 ULONG PageOpCount;
236 union
237 {
238 struct
239 {
240 ROS_SECTION_OBJECT* Section;
241 ULONG ViewOffset;
242 PMM_SECTION_SEGMENT Segment;
243 BOOLEAN WriteCopyView;
244 LIST_ENTRY RegionListHead;
245 } SectionData;
246 struct
247 {
248 LIST_ENTRY RegionListHead;
249 } VirtualMemoryData;
250 } Data;
251 } MEMORY_AREA, *PMEMORY_AREA;
252
253 typedef struct _MADDRESS_SPACE
254 {
255 PMEMORY_AREA MemoryAreaRoot;
256 PVOID LowestAddress;
257 PEPROCESS Process;
258 PUSHORT PageTableRefCountTable;
259 PEX_PUSH_LOCK Lock;
260 } MADDRESS_SPACE, *PMADDRESS_SPACE;
261
262 typedef struct
263 {
264 ULONG NrTotalPages;
265 ULONG NrSystemPages;
266 ULONG NrUserPages;
267 ULONG NrFreePages;
268 ULONG NrDirtyPages;
269 ULONG NrLockedPages;
270 ULONG PagingRequestsInLastMinute;
271 ULONG PagingRequestsInLastFiveMinutes;
272 ULONG PagingRequestsInLastFifteenMinutes;
273 } MM_STATS;
274
275 typedef struct _PHYSICAL_PAGE
276 {
277 union
278 {
279 struct
280 {
281 ULONG Type: 2;
282 ULONG Consumer: 3;
283 ULONG Zero: 1;
284 ULONG StartOfAllocation: 1;
285 ULONG EndOfAllocation: 1;
286 }
287 Flags;
288 ULONG AllFlags;
289 };
290
291 LIST_ENTRY ListEntry;
292 ULONG ReferenceCount;
293 SWAPENTRY SavedSwapEntry;
294 ULONG LockCount;
295 ULONG MapCount;
296 struct _MM_RMAP_ENTRY* RmapListHead;
297 }
298 PHYSICAL_PAGE, *PPHYSICAL_PAGE;
299
300 extern MM_STATS MmStats;
301
302 typedef struct _MM_PAGEOP
303 {
304 /* Type of operation. */
305 ULONG OpType;
306 /* Number of threads interested in this operation. */
307 ULONG ReferenceCount;
308 /* Event that will be set when the operation is completed. */
309 KEVENT CompletionEvent;
310 /* Status of the operation once it is completed. */
311 NTSTATUS Status;
312 /* TRUE if the operation was abandoned. */
313 BOOLEAN Abandoned;
314 /* The memory area to be affected by the operation. */
315 PMEMORY_AREA MArea;
316 ULONG Hash;
317 struct _MM_PAGEOP* Next;
318 struct _ETHREAD* Thread;
319 /*
320 * These fields are used to identify the operation if it is against a
321 * virtual memory area.
322 */
323 HANDLE Pid;
324 PVOID Address;
325 /*
326 * These fields are used to identify the operation if it is against a
327 * section mapping.
328 */
329 PMM_SECTION_SEGMENT Segment;
330 ULONG Offset;
331 } MM_PAGEOP, *PMM_PAGEOP;
332
333 typedef struct _MM_MEMORY_CONSUMER
334 {
335 ULONG PagesUsed;
336 ULONG PagesTarget;
337 NTSTATUS (*Trim)(ULONG Target, ULONG Priority, PULONG NrFreed);
338 } MM_MEMORY_CONSUMER, *PMM_MEMORY_CONSUMER;
339
340 typedef struct _MM_REGION
341 {
342 ULONG Type;
343 ULONG Protect;
344 ULONG Length;
345 LIST_ENTRY RegionListEntry;
346 } MM_REGION, *PMM_REGION;
347
348 /* Entry describing free pool memory */
349 typedef struct _MMFREE_POOL_ENTRY
350 {
351 LIST_ENTRY List;
352 PFN_NUMBER Size;
353 ULONG Signature;
354 struct _MMFREE_POOL_ENTRY *Owner;
355 } MMFREE_POOL_ENTRY, *PMMFREE_POOL_ENTRY;
356
357 /* Paged pool information */
358 typedef struct _MM_PAGED_POOL_INFO
359 {
360 PRTL_BITMAP PagedPoolAllocationMap;
361 PRTL_BITMAP EndOfPagedPoolBitmap;
362 PMMPTE FirstPteForPagedPool;
363 PMMPTE LastPteForPagedPool;
364 PMMPTE NextPdeForPagedPoolExpansion;
365 ULONG PagedPoolHint;
366 SIZE_T PagedPoolCommit;
367 SIZE_T AllocatedPagedPool;
368 } MM_PAGED_POOL_INFO, *PMM_PAGED_POOL_INFO;
369
370 extern MM_MEMORY_CONSUMER MiMemoryConsumers[MC_MAXIMUM];
371
372 typedef VOID
373 (*PMM_ALTER_REGION_FUNC)(
374 PMADDRESS_SPACE AddressSpace,
375 PVOID BaseAddress,
376 ULONG Length,
377 ULONG OldType,
378 ULONG OldProtect,
379 ULONG NewType,
380 ULONG NewProtect
381 );
382
383 typedef VOID
384 (*PMM_FREE_PAGE_FUNC)(
385 PVOID Context,
386 PMEMORY_AREA MemoryArea,
387 PVOID Address,
388 PFN_TYPE Page,
389 SWAPENTRY SwapEntry,
390 BOOLEAN Dirty
391 );
392
393 /* aspace.c ******************************************************************/
394
395 VOID
396 NTAPI
397 MmInitializeKernelAddressSpace(VOID);
398
399 NTSTATUS
400 NTAPI
401 MmInitializeAddressSpace(
402 struct _EPROCESS* Process,
403 PMADDRESS_SPACE AddressSpace);
404
405 NTSTATUS
406 NTAPI
407 MmDestroyAddressSpace(PMADDRESS_SPACE AddressSpace);
408
409 /* marea.c *******************************************************************/
410
411 NTSTATUS
412 NTAPI
413 MmInitMemoryAreas(VOID);
414
415 NTSTATUS
416 NTAPI
417 MmCreateMemoryArea(
418 PMADDRESS_SPACE AddressSpace,
419 ULONG Type,
420 PVOID *BaseAddress,
421 ULONG_PTR Length,
422 ULONG Protection,
423 PMEMORY_AREA *Result,
424 BOOLEAN FixedAddress,
425 ULONG AllocationFlags,
426 PHYSICAL_ADDRESS BoundaryAddressMultiple OPTIONAL
427 );
428
429 PMEMORY_AREA
430 NTAPI
431 MmLocateMemoryAreaByAddress(
432 PMADDRESS_SPACE AddressSpace,
433 PVOID Address
434 );
435
436 ULONG_PTR
437 NTAPI
438 MmFindGapAtAddress(
439 PMADDRESS_SPACE AddressSpace,
440 PVOID Address
441 );
442
443 NTSTATUS
444 NTAPI
445 MmFreeMemoryArea(
446 PMADDRESS_SPACE AddressSpace,
447 PMEMORY_AREA MemoryArea,
448 PMM_FREE_PAGE_FUNC FreePage,
449 PVOID FreePageContext
450 );
451
452 NTSTATUS
453 NTAPI
454 MmFreeMemoryAreaByPtr(
455 PMADDRESS_SPACE AddressSpace,
456 PVOID BaseAddress,
457 PMM_FREE_PAGE_FUNC FreePage,
458 PVOID FreePageContext
459 );
460
461 VOID
462 NTAPI
463 MmDumpMemoryAreas(PMADDRESS_SPACE AddressSpace);
464
465 PMEMORY_AREA
466 NTAPI
467 MmLocateMemoryAreaByRegion(
468 PMADDRESS_SPACE AddressSpace,
469 PVOID Address,
470 ULONG_PTR Length
471 );
472
473 PVOID
474 NTAPI
475 MmFindGap(
476 PMADDRESS_SPACE AddressSpace,
477 ULONG_PTR Length,
478 ULONG_PTR Granularity,
479 BOOLEAN TopDown
480 );
481
482 VOID
483 NTAPI
484 MmReleaseMemoryAreaIfDecommitted(
485 struct _EPROCESS *Process,
486 PMADDRESS_SPACE AddressSpace,
487 PVOID BaseAddress
488 );
489
490 VOID
491 NTAPI
492 MmMapMemoryArea(PVOID BaseAddress,
493 ULONG Length,
494 ULONG Consumer,
495 ULONG Protection);
496
497 /* npool.c *******************************************************************/
498
499 VOID
500 NTAPI
501 MiDebugDumpNonPagedPool(BOOLEAN NewOnly);
502
503 VOID
504 NTAPI
505 MiDebugDumpNonPagedPoolStats(BOOLEAN NewOnly);
506
507 VOID
508 NTAPI
509 MiInitializeNonPagedPool(VOID);
510
511 PVOID
512 NTAPI
513 MiAllocatePoolPages(
514 IN POOL_TYPE PoolType,
515 IN SIZE_T SizeInBytes
516 );
517
518 POOL_TYPE
519 NTAPI
520 MmDeterminePoolType(
521 IN PVOID VirtualAddress
522 );
523
524 ULONG
525 NTAPI
526 MiFreePoolPages(
527 IN PVOID StartingAddress
528 );
529
530 PVOID
531 NTAPI
532 MmGetMdlPageAddress(
533 PMDL Mdl,
534 PVOID Offset
535 );
536
537 /* pool.c *******************************************************************/
538
539 PVOID
540 NTAPI
541 ExAllocateNonPagedPoolWithTag(
542 POOL_TYPE type,
543 ULONG size,
544 ULONG Tag,
545 PVOID Caller
546 );
547
548 PVOID
549 NTAPI
550 ExAllocatePagedPoolWithTag(
551 POOL_TYPE Type,
552 ULONG size,
553 ULONG Tag
554 );
555
556 VOID
557 NTAPI
558 ExFreeNonPagedPool(PVOID block);
559
560 VOID
561 NTAPI
562 ExFreePagedPool(IN PVOID Block);
563
564 VOID
565 NTAPI
566 MmInitializePagedPool(VOID);
567
568 PVOID
569 NTAPI
570 MiAllocateSpecialPool(
571 IN POOL_TYPE PoolType,
572 IN SIZE_T NumberOfBytes,
573 IN ULONG Tag,
574 IN ULONG Underrun
575 );
576
577 BOOLEAN
578 NTAPI
579 MiRaisePoolQuota(
580 IN POOL_TYPE PoolType,
581 IN ULONG CurrentMaxQuota,
582 OUT PULONG NewMaxQuota
583 );
584
585 /* mdl.c *********************************************************************/
586
587 VOID
588 NTAPI
589 MmBuildMdlFromPages(
590 PMDL Mdl,
591 PULONG Pages
592 );
593
594 /* mminit.c ******************************************************************/
595
596 VOID
597 NTAPI
598 MiShutdownMemoryManager(VOID);
599
600 VOID
601 NTAPI
602 MmInit1(
603 VOID
604 );
605
606 BOOLEAN
607 NTAPI
608 MmInitSystem(IN ULONG Phase,
609 IN PLOADER_PARAMETER_BLOCK LoaderBlock);
610
611 VOID
612 NTAPI
613 MiFreeInitMemory(VOID);
614
615 VOID
616 NTAPI
617 MmInitializeMdlImplementation(VOID);
618
619 /* pagefile.c ****************************************************************/
620
621 SWAPENTRY
622 NTAPI
623 MmAllocSwapPage(VOID);
624
625 VOID
626 NTAPI
627 MmDereserveSwapPages(ULONG Nr);
628
629 VOID
630 NTAPI
631 MmFreeSwapPage(SWAPENTRY Entry);
632
633 VOID
634 NTAPI
635 MmInitPagingFile(VOID);
636
637 NTSTATUS
638 NTAPI
639 MmReadFromSwapPage(
640 SWAPENTRY SwapEntry,
641 PFN_TYPE Page
642 );
643
644 BOOLEAN
645 NTAPI
646 MmReserveSwapPages(ULONG Nr);
647
648 NTSTATUS
649 NTAPI
650 MmWriteToSwapPage(
651 SWAPENTRY SwapEntry,
652 PFN_TYPE Page
653 );
654
655 NTSTATUS
656 NTAPI
657 MmDumpToPagingFile(
658 ULONG BugCode,
659 ULONG BugCodeParameter1,
660 ULONG BugCodeParameter2,
661 ULONG BugCodeParameter3,
662 ULONG BugCodeParameter4,
663 struct _KTRAP_FRAME* TrapFrame
664 );
665
666 BOOLEAN
667 NTAPI
668 MmIsAvailableSwapPage(VOID);
669
670 VOID
671 NTAPI
672 MmShowOutOfSpaceMessagePagingFile(VOID);
673
674 /* process.c ****************************************************************/
675
676 NTSTATUS
677 NTAPI
678 MmInitializeProcessAddressSpace(
679 IN PEPROCESS Process,
680 IN PEPROCESS Clone OPTIONAL,
681 IN PVOID Section OPTIONAL,
682 IN OUT PULONG Flags,
683 IN POBJECT_NAME_INFORMATION *AuditName OPTIONAL
684 );
685
686 NTSTATUS
687 NTAPI
688 MmCreatePeb(struct _EPROCESS *Process);
689
690 PTEB
691 NTAPI
692 MmCreateTeb(
693 struct _EPROCESS *Process,
694 PCLIENT_ID ClientId,
695 PINITIAL_TEB InitialTeb
696 );
697
698 VOID
699 NTAPI
700 MmDeleteTeb(
701 struct _EPROCESS *Process,
702 PTEB Teb
703 );
704
705 VOID
706 NTAPI
707 MmCleanProcessAddressSpace(IN PEPROCESS Process);
708
709 NTSTATUS
710 NTAPI
711 MmDeleteProcessAddressSpace(IN PEPROCESS Process);
712
713 ULONG
714 NTAPI
715 MmGetSessionLocaleId(VOID);
716
717 NTSTATUS
718 NTAPI
719 MmSetMemoryPriorityProcess(
720 IN PEPROCESS Process,
721 IN UCHAR MemoryPriority
722 );
723
724 /* i386/pfault.c *************************************************************/
725
726 NTSTATUS
727 NTAPI
728 MmPageFault(
729 ULONG Cs,
730 PULONG Eip,
731 PULONG Eax,
732 ULONG Cr2,
733 ULONG ErrorCode
734 );
735
736 /* mm.c **********************************************************************/
737
738 NTSTATUS
739 NTAPI
740 MmAccessFault(
741 IN BOOLEAN StoreInstruction,
742 IN PVOID Address,
743 IN KPROCESSOR_MODE Mode,
744 IN PVOID TrapInformation
745 );
746
747 /* anonmem.c *****************************************************************/
748
749 NTSTATUS
750 NTAPI
751 MmNotPresentFaultVirtualMemory(
752 PMADDRESS_SPACE AddressSpace,
753 MEMORY_AREA* MemoryArea,
754 PVOID Address,
755 BOOLEAN Locked
756 );
757
758 NTSTATUS
759 NTAPI
760 MmPageOutVirtualMemory(
761 PMADDRESS_SPACE AddressSpace,
762 PMEMORY_AREA MemoryArea,
763 PVOID Address,
764 struct _MM_PAGEOP* PageOp
765 );
766
767 NTSTATUS
768 NTAPI
769 MmQueryAnonMem(
770 PMEMORY_AREA MemoryArea,
771 PVOID Address,
772 PMEMORY_BASIC_INFORMATION Info,
773 PULONG ResultLength
774 );
775
776 VOID
777 NTAPI
778 MmFreeVirtualMemory(
779 struct _EPROCESS* Process,
780 PMEMORY_AREA MemoryArea
781 );
782
783 NTSTATUS
784 NTAPI
785 MmProtectAnonMem(
786 PMADDRESS_SPACE AddressSpace,
787 PMEMORY_AREA MemoryArea,
788 PVOID BaseAddress,
789 ULONG Length,
790 ULONG Protect,
791 PULONG OldProtect
792 );
793
794 NTSTATUS
795 NTAPI
796 MmWritePageVirtualMemory(
797 PMADDRESS_SPACE AddressSpace,
798 PMEMORY_AREA MArea,
799 PVOID Address,
800 PMM_PAGEOP PageOp
801 );
802
803 /* kmap.c ********************************************************************/
804
805 PVOID
806 NTAPI
807 ExAllocatePage(VOID);
808
809 VOID
810 NTAPI
811 ExUnmapPage(PVOID Addr);
812
813 PVOID
814 NTAPI
815 ExAllocatePageWithPhysPage(PFN_TYPE Page);
816
817 NTSTATUS
818 NTAPI
819 MiCopyFromUserPage(
820 PFN_TYPE Page,
821 PVOID SourceAddress
822 );
823
824 NTSTATUS
825 NTAPI
826 MiZeroPage(PFN_TYPE Page);
827
828 /* memsafe.s *****************************************************************/
829
830 PVOID
831 FASTCALL
832 MmSafeReadPtr(PVOID Source);
833
834 /* pageop.c ******************************************************************/
835
836 VOID
837 NTAPI
838 MmReleasePageOp(PMM_PAGEOP PageOp);
839
840 PMM_PAGEOP
841 NTAPI
842 MmGetPageOp(
843 PMEMORY_AREA MArea,
844 HANDLE Pid,
845 PVOID Address,
846 PMM_SECTION_SEGMENT Segment,
847 ULONG Offset,
848 ULONG OpType,
849 BOOLEAN First
850 );
851
852 PMM_PAGEOP
853 NTAPI
854 MmCheckForPageOp(
855 PMEMORY_AREA MArea,
856 HANDLE Pid,
857 PVOID Address,
858 PMM_SECTION_SEGMENT Segment,
859 ULONG Offset
860 );
861
862 VOID
863 NTAPI
864 MmInitializePageOp(VOID);
865
866 /* process.c *****************************************************************/
867
868 PVOID
869 NTAPI
870 MmCreateKernelStack(BOOLEAN GuiStack, UCHAR Node);
871
872 VOID
873 NTAPI
874 MmDeleteKernelStack(PVOID Stack,
875 BOOLEAN GuiStack);
876
877 /* balace.c ******************************************************************/
878
879 VOID
880 NTAPI
881 MmInitializeMemoryConsumer(
882 ULONG Consumer,
883 NTSTATUS (*Trim)(ULONG Target, ULONG Priority, PULONG NrFreed)
884 );
885
886 VOID
887 NTAPI
888 MmInitializeBalancer(
889 ULONG NrAvailablePages,
890 ULONG NrSystemPages
891 );
892
893 NTSTATUS
894 NTAPI
895 MmReleasePageMemoryConsumer(
896 ULONG Consumer,
897 PFN_TYPE Page
898 );
899
900 NTSTATUS
901 NTAPI
902 MmRequestPageMemoryConsumer(
903 ULONG Consumer,
904 BOOLEAN MyWait,
905 PPFN_TYPE AllocatedPage
906 );
907
908 VOID
909 NTAPI
910 MiInitBalancerThread(VOID);
911
912 VOID
913 NTAPI
914 MmRebalanceMemoryConsumers(VOID);
915
916 /* rmap.c **************************************************************/
917
918 VOID
919 NTAPI
920 MmSetRmapListHeadPage(
921 PFN_TYPE Page,
922 struct _MM_RMAP_ENTRY* ListHead
923 );
924
925 struct _MM_RMAP_ENTRY*
926 NTAPI
927 MmGetRmapListHeadPage(PFN_TYPE Page);
928
929 VOID
930 NTAPI
931 MmInsertRmap(
932 PFN_TYPE Page,
933 struct _EPROCESS *Process,
934 PVOID Address
935 );
936
937 VOID
938 NTAPI
939 MmDeleteAllRmaps(
940 PFN_TYPE Page,
941 PVOID Context,
942 VOID (*DeleteMapping)(PVOID Context, struct _EPROCESS *Process, PVOID Address)
943 );
944
945 VOID
946 NTAPI
947 MmDeleteRmap(
948 PFN_TYPE Page,
949 struct _EPROCESS *Process,
950 PVOID Address
951 );
952
953 VOID
954 NTAPI
955 MmInitializeRmapList(VOID);
956
957 VOID
958 NTAPI
959 MmSetCleanAllRmaps(PFN_TYPE Page);
960
961 VOID
962 NTAPI
963 MmSetDirtyAllRmaps(PFN_TYPE Page);
964
965 BOOLEAN
966 NTAPI
967 MmIsDirtyPageRmap(PFN_TYPE Page);
968
969 NTSTATUS
970 NTAPI
971 MmWritePagePhysicalAddress(PFN_TYPE Page);
972
973 NTSTATUS
974 NTAPI
975 MmPageOutPhysicalAddress(PFN_TYPE Page);
976
977 /* freelist.c **********************************************************/
978
979 #define ASSERT_PFN(x) ASSERT((x)->Flags.Type != 0)
980
981 FORCEINLINE
982 PPHYSICAL_PAGE
983 MiGetPfnEntry(IN PFN_TYPE Pfn)
984 {
985 PPHYSICAL_PAGE Page;
986 extern PPHYSICAL_PAGE MmPageArray;
987 extern ULONG MmPageArraySize;
988
989 /* Mark MmPageArraySize as unreferenced, otherwise it will appear as an unused variable on a Release build */
990 UNREFERENCED_PARAMETER(MmPageArraySize);
991
992 /* Make sure the PFN number is valid */
993 ASSERT(Pfn <= MmPageArraySize);
994
995 /* Get the entry */
996 Page = &MmPageArray[Pfn];
997
998 /* Make sure it's valid */
999 ASSERT_PFN(Page);
1000
1001 /* Return it */
1002 return Page;
1003 };
1004
1005 PFN_TYPE
1006 NTAPI
1007 MmGetLRUNextUserPage(PFN_TYPE PreviousPage);
1008
1009 PFN_TYPE
1010 NTAPI
1011 MmGetLRUFirstUserPage(VOID);
1012
1013 VOID
1014 NTAPI
1015 MmInsertLRULastUserPage(PFN_TYPE Page);
1016
1017 VOID
1018 NTAPI
1019 MmRemoveLRUUserPage(PFN_TYPE Page);
1020
1021 VOID
1022 NTAPI
1023 MmLockPage(PFN_TYPE Page);
1024
1025 VOID
1026 NTAPI
1027 MmLockPageUnsafe(PFN_TYPE Page);
1028
1029 VOID
1030 NTAPI
1031 MmUnlockPage(PFN_TYPE Page);
1032
1033 ULONG
1034 NTAPI
1035 MmGetLockCountPage(PFN_TYPE Page);
1036
1037 VOID
1038 NTAPI
1039 MmInitializePageList(
1040 VOID
1041 );
1042
1043 PFN_TYPE
1044 NTAPI
1045 MmGetContinuousPages(
1046 ULONG NumberOfBytes,
1047 PHYSICAL_ADDRESS LowestAcceptableAddress,
1048 PHYSICAL_ADDRESS HighestAcceptableAddress,
1049 PHYSICAL_ADDRESS BoundaryAddressMultiple
1050 );
1051
1052 NTSTATUS
1053 NTAPI
1054 MmZeroPageThreadMain(
1055 PVOID Context
1056 );
1057
1058 /* i386/page.c *********************************************************/
1059
1060 PVOID
1061 NTAPI
1062 MmCreateHyperspaceMapping(PFN_TYPE Page);
1063
1064 PFN_TYPE
1065 NTAPI
1066 MmChangeHyperspaceMapping(
1067 PVOID Address,
1068 PFN_TYPE Page
1069 );
1070
1071 PFN_TYPE
1072 NTAPI
1073 MmDeleteHyperspaceMapping(PVOID Address);
1074
1075 NTSTATUS
1076 NTAPI
1077 MmCreateVirtualMappingForKernel(
1078 PVOID Address,
1079 ULONG flProtect,
1080 PPFN_TYPE Pages,
1081 ULONG PageCount
1082 );
1083
1084 NTSTATUS
1085 NTAPI
1086 MmCommitPagedPoolAddress(
1087 PVOID Address,
1088 BOOLEAN Locked
1089 );
1090
1091 NTSTATUS
1092 NTAPI
1093 MmCreateVirtualMapping(
1094 struct _EPROCESS* Process,
1095 PVOID Address,
1096 ULONG flProtect,
1097 PPFN_TYPE Pages,
1098 ULONG PageCount
1099 );
1100
1101 NTSTATUS
1102 NTAPI
1103 MmCreateVirtualMappingUnsafe(
1104 struct _EPROCESS* Process,
1105 PVOID Address,
1106 ULONG flProtect,
1107 PPFN_TYPE Pages,
1108 ULONG PageCount
1109 );
1110
1111 ULONG
1112 NTAPI
1113 MmGetPageProtect(
1114 struct _EPROCESS* Process,
1115 PVOID Address);
1116
1117 VOID
1118 NTAPI
1119 MmSetPageProtect(
1120 struct _EPROCESS* Process,
1121 PVOID Address,
1122 ULONG flProtect
1123 );
1124
1125 BOOLEAN
1126 NTAPI
1127 MmIsPagePresent(
1128 struct _EPROCESS* Process,
1129 PVOID Address
1130 );
1131
1132 VOID
1133 NTAPI
1134 MmInitGlobalKernelPageDirectory(VOID);
1135
1136 VOID
1137 NTAPI
1138 MmDisableVirtualMapping(
1139 struct _EPROCESS *Process,
1140 PVOID Address,
1141 BOOLEAN* WasDirty,
1142 PPFN_TYPE Page
1143 );
1144
1145 VOID
1146 NTAPI
1147 MmEnableVirtualMapping(
1148 struct _EPROCESS *Process,
1149 PVOID Address
1150 );
1151
1152 VOID
1153 NTAPI
1154 MmRawDeleteVirtualMapping(PVOID Address);
1155
1156 VOID
1157 NTAPI
1158 MmDeletePageFileMapping(
1159 struct _EPROCESS *Process,
1160 PVOID Address,
1161 SWAPENTRY* SwapEntry
1162 );
1163
1164 NTSTATUS
1165 NTAPI
1166 MmCreatePageFileMapping(
1167 struct _EPROCESS *Process,
1168 PVOID Address,
1169 SWAPENTRY SwapEntry
1170 );
1171
1172 BOOLEAN
1173 NTAPI
1174 MmIsPageSwapEntry(
1175 struct _EPROCESS *Process,
1176 PVOID Address
1177 );
1178
1179 VOID
1180 NTAPI
1181 MmTransferOwnershipPage(
1182 PFN_TYPE Page,
1183 ULONG NewConsumer
1184 );
1185
1186 VOID
1187 NTAPI
1188 MmSetDirtyPage(
1189 struct _EPROCESS *Process,
1190 PVOID Address
1191 );
1192
1193 PFN_TYPE
1194 NTAPI
1195 MmAllocPage(
1196 ULONG Consumer,
1197 SWAPENTRY SavedSwapEntry
1198 );
1199
1200 LONG
1201 NTAPI
1202 MmAllocPagesSpecifyRange(
1203 ULONG Consumer,
1204 PHYSICAL_ADDRESS LowestAddress,
1205 PHYSICAL_ADDRESS HighestAddress,
1206 ULONG NumberOfPages,
1207 PPFN_TYPE Pages
1208 );
1209
1210 VOID
1211 NTAPI
1212 MmDereferencePage(PFN_TYPE Page);
1213
1214 VOID
1215 NTAPI
1216 MmReferencePage(PFN_TYPE Page);
1217
1218 VOID
1219 NTAPI
1220 MmReferencePageUnsafe(PFN_TYPE Page);
1221
1222 BOOLEAN
1223 NTAPI
1224 MmIsAccessedAndResetAccessPage(
1225 struct _EPROCESS *Process,
1226 PVOID Address
1227 );
1228
1229 ULONG
1230 NTAPI
1231 MmGetReferenceCountPage(PFN_TYPE Page);
1232
1233 BOOLEAN
1234 NTAPI
1235 MmIsPageInUse(PFN_TYPE Page);
1236
1237 VOID
1238 NTAPI
1239 MmSetFlagsPage(
1240 PFN_TYPE Page,
1241 ULONG Flags);
1242
1243 ULONG
1244 NTAPI
1245 MmGetFlagsPage(PFN_TYPE Page);
1246
1247 VOID
1248 NTAPI
1249 MmSetSavedSwapEntryPage(
1250 PFN_TYPE Page,
1251 SWAPENTRY SavedSwapEntry);
1252
1253 SWAPENTRY
1254 NTAPI
1255 MmGetSavedSwapEntryPage(PFN_TYPE Page);
1256
1257 VOID
1258 NTAPI
1259 MmSetCleanPage(
1260 struct _EPROCESS *Process,
1261 PVOID Address
1262 );
1263
1264 NTSTATUS
1265 NTAPI
1266 MmCreatePageTable(PVOID PAddress);
1267
1268 VOID
1269 NTAPI
1270 MmDeletePageTable(
1271 struct _EPROCESS *Process,
1272 PVOID Address
1273 );
1274
1275 PFN_TYPE
1276 NTAPI
1277 MmGetPfnForProcess(
1278 struct _EPROCESS *Process,
1279 PVOID Address
1280 );
1281
1282 BOOLEAN
1283 NTAPI
1284 MmCreateProcessAddressSpace(
1285 IN ULONG MinWs,
1286 IN PEPROCESS Dest,
1287 IN PLARGE_INTEGER DirectoryTableBase
1288 );
1289
1290 NTSTATUS
1291 NTAPI
1292 MmInitializeHandBuiltProcess(
1293 IN PEPROCESS Process,
1294 IN PLARGE_INTEGER DirectoryTableBase
1295 );
1296
1297
1298 NTSTATUS
1299 NTAPI
1300 MmInitializeHandBuiltProcess2(
1301 IN PEPROCESS Process
1302 );
1303
1304 NTSTATUS
1305 NTAPI
1306 MmReleaseMmInfo(struct _EPROCESS *Process);
1307
1308 NTSTATUS
1309 NTAPI
1310 Mmi386ReleaseMmInfo(struct _EPROCESS *Process);
1311
1312 VOID
1313 NTAPI
1314 MmDeleteVirtualMapping(
1315 struct _EPROCESS *Process,
1316 PVOID Address,
1317 BOOLEAN FreePage,
1318 BOOLEAN* WasDirty,
1319 PPFN_TYPE Page
1320 );
1321
1322 BOOLEAN
1323 NTAPI
1324 MmIsDirtyPage(
1325 struct _EPROCESS *Process,
1326 PVOID Address
1327 );
1328
1329 VOID
1330 NTAPI
1331 MmMarkPageMapped(PFN_TYPE Page);
1332
1333 VOID
1334 NTAPI
1335 MmMarkPageUnmapped(PFN_TYPE Page);
1336
1337 VOID
1338 NTAPI
1339 MmUpdatePageDir(
1340 struct _EPROCESS *Process,
1341 PVOID Address,
1342 ULONG Size
1343 );
1344
1345 VOID
1346 NTAPI
1347 MiInitPageDirectoryMap(VOID);
1348
1349 ULONG
1350 NTAPI
1351 MiGetUserPageDirectoryCount(VOID);
1352
1353 /* wset.c ********************************************************************/
1354
1355 NTSTATUS
1356 MmTrimUserMemory(
1357 ULONG Target,
1358 ULONG Priority,
1359 PULONG NrFreedPages
1360 );
1361
1362 /* region.c ************************************************************/
1363
1364 NTSTATUS
1365 NTAPI
1366 MmAlterRegion(
1367 PMADDRESS_SPACE AddressSpace,
1368 PVOID BaseAddress,
1369 PLIST_ENTRY RegionListHead,
1370 PVOID StartAddress,
1371 ULONG Length,
1372 ULONG NewType,
1373 ULONG NewProtect,
1374 PMM_ALTER_REGION_FUNC AlterFunc
1375 );
1376
1377 VOID
1378 NTAPI
1379 MmInitializeRegion(
1380 PLIST_ENTRY RegionListHead,
1381 SIZE_T Length,
1382 ULONG Type,
1383 ULONG Protect
1384 );
1385
1386 PMM_REGION
1387 NTAPI
1388 MmFindRegion(
1389 PVOID BaseAddress,
1390 PLIST_ENTRY RegionListHead,
1391 PVOID Address,
1392 PVOID* RegionBaseAddress
1393 );
1394
1395 /* section.c *****************************************************************/
1396
1397 PFILE_OBJECT
1398 NTAPI
1399 MmGetFileObjectForSection(
1400 IN PROS_SECTION_OBJECT Section
1401 );
1402 NTSTATUS
1403 NTAPI
1404 MmGetFileNameForAddress(
1405 IN PVOID Address,
1406 OUT PUNICODE_STRING ModuleName
1407 );
1408
1409 NTSTATUS
1410 NTAPI
1411 MmGetFileNameForSection(
1412 IN PROS_SECTION_OBJECT Section,
1413 OUT POBJECT_NAME_INFORMATION *ModuleName
1414 );
1415
1416 PVOID
1417 NTAPI
1418 MmAllocateSection(
1419 IN ULONG Length,
1420 PVOID BaseAddress
1421 );
1422
1423 NTSTATUS
1424 NTAPI
1425 MmQuerySectionView(
1426 PMEMORY_AREA MemoryArea,
1427 PVOID Address,
1428 PMEMORY_BASIC_INFORMATION Info,
1429 PULONG ResultLength
1430 );
1431
1432 NTSTATUS
1433 NTAPI
1434 MmProtectSectionView(
1435 PMADDRESS_SPACE AddressSpace,
1436 PMEMORY_AREA MemoryArea,
1437 PVOID BaseAddress,
1438 ULONG Length,
1439 ULONG Protect,
1440 PULONG OldProtect
1441 );
1442
1443 NTSTATUS
1444 NTAPI
1445 MmWritePageSectionView(
1446 PMADDRESS_SPACE AddressSpace,
1447 PMEMORY_AREA MArea,
1448 PVOID Address,
1449 PMM_PAGEOP PageOp
1450 );
1451
1452 NTSTATUS
1453 NTAPI
1454 MmInitSectionImplementation(VOID);
1455
1456 NTSTATUS
1457 NTAPI
1458 MmNotPresentFaultSectionView(
1459 PMADDRESS_SPACE AddressSpace,
1460 MEMORY_AREA* MemoryArea,
1461 PVOID Address,
1462 BOOLEAN Locked
1463 );
1464
1465 NTSTATUS
1466 NTAPI
1467 MmPageOutSectionView(
1468 PMADDRESS_SPACE AddressSpace,
1469 PMEMORY_AREA MemoryArea,
1470 PVOID Address,
1471 struct _MM_PAGEOP *PageOp
1472 );
1473
1474 NTSTATUS
1475 NTAPI
1476 MmCreatePhysicalMemorySection(VOID);
1477
1478 NTSTATUS
1479 NTAPI
1480 MmAccessFaultSectionView(
1481 PMADDRESS_SPACE AddressSpace,
1482 MEMORY_AREA* MemoryArea,
1483 PVOID Address,
1484 BOOLEAN Locked
1485 );
1486
1487 VOID
1488 NTAPI
1489 MmFreeSectionSegments(PFILE_OBJECT FileObject);
1490
1491 /* mpw.c *********************************************************************/
1492
1493 NTSTATUS
1494 NTAPI
1495 MmInitMpwThread(VOID);
1496
1497 NTSTATUS
1498 NTAPI
1499 MmInitBsmThread(VOID);
1500
1501 /* pager.c *******************************************************************/
1502
1503 BOOLEAN
1504 NTAPI
1505 MiIsPagerThread(VOID);
1506
1507 VOID
1508 NTAPI
1509 MiStartPagerThread(VOID);
1510
1511 VOID
1512 NTAPI
1513 MiStopPagerThread(VOID);
1514
1515 NTSTATUS
1516 FASTCALL
1517 MiQueryVirtualMemory(
1518 IN HANDLE ProcessHandle,
1519 IN PVOID Address,
1520 IN MEMORY_INFORMATION_CLASS VirtualMemoryInformationClass,
1521 OUT PVOID VirtualMemoryInformation,
1522 IN ULONG Length,
1523 OUT PULONG ResultLength
1524 );
1525
1526 /* sysldr.c ******************************************************************/
1527
1528 VOID
1529 NTAPI
1530 MiReloadBootLoadedDrivers(
1531 IN PLOADER_PARAMETER_BLOCK LoaderBlock
1532 );
1533
1534 BOOLEAN
1535 NTAPI
1536 MiInitializeLoadedModuleList(
1537 IN PLOADER_PARAMETER_BLOCK LoaderBlock
1538 );
1539
1540 NTSTATUS
1541 NTAPI
1542 MmLoadSystemImage(
1543 IN PUNICODE_STRING FileName,
1544 IN PUNICODE_STRING NamePrefix OPTIONAL,
1545 IN PUNICODE_STRING LoadedName OPTIONAL,
1546 IN ULONG Flags,
1547 OUT PVOID *ModuleObject,
1548 OUT PVOID *ImageBaseAddress
1549 );
1550
1551 NTSTATUS
1552 NTAPI
1553 MmUnloadSystemImage(
1554 IN PVOID ImageHandle
1555 );
1556
1557 NTSTATUS
1558 NTAPI
1559 MmCheckSystemImage(
1560 IN HANDLE ImageHandle,
1561 IN BOOLEAN PurgeSection
1562 );
1563
1564 FORCEINLINE
1565 VOID
1566 NTAPI
1567 MiSyncThreadProcessViews(IN PVOID Process,
1568 IN PVOID Address,
1569 IN ULONG Size)
1570 {
1571 MmUpdatePageDir((PEPROCESS)Process, Address, Size);
1572 }
1573
1574
1575 extern MADDRESS_SPACE MmKernelAddressSpace;
1576
1577 FORCEINLINE
1578 VOID
1579 MmLockAddressSpace(PMADDRESS_SPACE AddressSpace)
1580 {
1581 KeEnterCriticalRegion();
1582 ExAcquirePushLockExclusive(AddressSpace->Lock);
1583 }
1584
1585 FORCEINLINE
1586 VOID
1587 MmUnlockAddressSpace(PMADDRESS_SPACE AddressSpace)
1588 {
1589 ExReleasePushLock(AddressSpace->Lock);
1590 KeLeaveCriticalRegion();
1591 }
1592
1593 FORCEINLINE
1594 PMADDRESS_SPACE
1595 MmGetCurrentAddressSpace(VOID)
1596 {
1597 return (PMADDRESS_SPACE)&((PEPROCESS)KeGetCurrentThread()->ApcState.Process)->VadRoot;
1598 }
1599
1600 FORCEINLINE
1601 PMADDRESS_SPACE
1602 MmGetKernelAddressSpace(VOID)
1603 {
1604 return &MmKernelAddressSpace;
1605 }
1606
1607 #endif