b102d943f8f12f5bf70fc8bf676c38c4d9b8c777
[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 /* Make sure the PFN number is valid */
990 ASSERT(Pfn <= MmPageArraySize);
991
992 /* Get the entry */
993 Page = &MmPageArray[Pfn];
994
995 /* Make sure it's valid */
996 ASSERT_PFN(Page);
997
998 /* Return it */
999 return Page;
1000 };
1001
1002 PFN_TYPE
1003 NTAPI
1004 MmGetLRUNextUserPage(PFN_TYPE PreviousPage);
1005
1006 PFN_TYPE
1007 NTAPI
1008 MmGetLRUFirstUserPage(VOID);
1009
1010 VOID
1011 NTAPI
1012 MmInsertLRULastUserPage(PFN_TYPE Page);
1013
1014 VOID
1015 NTAPI
1016 MmRemoveLRUUserPage(PFN_TYPE Page);
1017
1018 VOID
1019 NTAPI
1020 MmLockPage(PFN_TYPE Page);
1021
1022 VOID
1023 NTAPI
1024 MmLockPageUnsafe(PFN_TYPE Page);
1025
1026 VOID
1027 NTAPI
1028 MmUnlockPage(PFN_TYPE Page);
1029
1030 ULONG
1031 NTAPI
1032 MmGetLockCountPage(PFN_TYPE Page);
1033
1034 VOID
1035 NTAPI
1036 MmInitializePageList(
1037 VOID
1038 );
1039
1040 PFN_TYPE
1041 NTAPI
1042 MmGetContinuousPages(
1043 ULONG NumberOfBytes,
1044 PHYSICAL_ADDRESS LowestAcceptableAddress,
1045 PHYSICAL_ADDRESS HighestAcceptableAddress,
1046 PHYSICAL_ADDRESS BoundaryAddressMultiple
1047 );
1048
1049 NTSTATUS
1050 NTAPI
1051 MmZeroPageThreadMain(
1052 PVOID Context
1053 );
1054
1055 /* i386/page.c *********************************************************/
1056
1057 PVOID
1058 NTAPI
1059 MmCreateHyperspaceMapping(PFN_TYPE Page);
1060
1061 PFN_TYPE
1062 NTAPI
1063 MmChangeHyperspaceMapping(
1064 PVOID Address,
1065 PFN_TYPE Page
1066 );
1067
1068 PFN_TYPE
1069 NTAPI
1070 MmDeleteHyperspaceMapping(PVOID Address);
1071
1072 NTSTATUS
1073 NTAPI
1074 MmCreateVirtualMappingForKernel(
1075 PVOID Address,
1076 ULONG flProtect,
1077 PPFN_TYPE Pages,
1078 ULONG PageCount
1079 );
1080
1081 NTSTATUS
1082 NTAPI
1083 MmCommitPagedPoolAddress(
1084 PVOID Address,
1085 BOOLEAN Locked
1086 );
1087
1088 NTSTATUS
1089 NTAPI
1090 MmCreateVirtualMapping(
1091 struct _EPROCESS* Process,
1092 PVOID Address,
1093 ULONG flProtect,
1094 PPFN_TYPE Pages,
1095 ULONG PageCount
1096 );
1097
1098 NTSTATUS
1099 NTAPI
1100 MmCreateVirtualMappingUnsafe(
1101 struct _EPROCESS* Process,
1102 PVOID Address,
1103 ULONG flProtect,
1104 PPFN_TYPE Pages,
1105 ULONG PageCount
1106 );
1107
1108 ULONG
1109 NTAPI
1110 MmGetPageProtect(
1111 struct _EPROCESS* Process,
1112 PVOID Address);
1113
1114 VOID
1115 NTAPI
1116 MmSetPageProtect(
1117 struct _EPROCESS* Process,
1118 PVOID Address,
1119 ULONG flProtect
1120 );
1121
1122 BOOLEAN
1123 NTAPI
1124 MmIsPagePresent(
1125 struct _EPROCESS* Process,
1126 PVOID Address
1127 );
1128
1129 VOID
1130 NTAPI
1131 MmInitGlobalKernelPageDirectory(VOID);
1132
1133 VOID
1134 NTAPI
1135 MmDisableVirtualMapping(
1136 struct _EPROCESS *Process,
1137 PVOID Address,
1138 BOOLEAN* WasDirty,
1139 PPFN_TYPE Page
1140 );
1141
1142 VOID
1143 NTAPI
1144 MmEnableVirtualMapping(
1145 struct _EPROCESS *Process,
1146 PVOID Address
1147 );
1148
1149 VOID
1150 NTAPI
1151 MmRawDeleteVirtualMapping(PVOID Address);
1152
1153 VOID
1154 NTAPI
1155 MmDeletePageFileMapping(
1156 struct _EPROCESS *Process,
1157 PVOID Address,
1158 SWAPENTRY* SwapEntry
1159 );
1160
1161 NTSTATUS
1162 NTAPI
1163 MmCreatePageFileMapping(
1164 struct _EPROCESS *Process,
1165 PVOID Address,
1166 SWAPENTRY SwapEntry
1167 );
1168
1169 BOOLEAN
1170 NTAPI
1171 MmIsPageSwapEntry(
1172 struct _EPROCESS *Process,
1173 PVOID Address
1174 );
1175
1176 VOID
1177 NTAPI
1178 MmTransferOwnershipPage(
1179 PFN_TYPE Page,
1180 ULONG NewConsumer
1181 );
1182
1183 VOID
1184 NTAPI
1185 MmSetDirtyPage(
1186 struct _EPROCESS *Process,
1187 PVOID Address
1188 );
1189
1190 PFN_TYPE
1191 NTAPI
1192 MmAllocPage(
1193 ULONG Consumer,
1194 SWAPENTRY SavedSwapEntry
1195 );
1196
1197 LONG
1198 NTAPI
1199 MmAllocPagesSpecifyRange(
1200 ULONG Consumer,
1201 PHYSICAL_ADDRESS LowestAddress,
1202 PHYSICAL_ADDRESS HighestAddress,
1203 ULONG NumberOfPages,
1204 PPFN_TYPE Pages
1205 );
1206
1207 VOID
1208 NTAPI
1209 MmDereferencePage(PFN_TYPE Page);
1210
1211 VOID
1212 NTAPI
1213 MmReferencePage(PFN_TYPE Page);
1214
1215 VOID
1216 NTAPI
1217 MmReferencePageUnsafe(PFN_TYPE Page);
1218
1219 BOOLEAN
1220 NTAPI
1221 MmIsAccessedAndResetAccessPage(
1222 struct _EPROCESS *Process,
1223 PVOID Address
1224 );
1225
1226 ULONG
1227 NTAPI
1228 MmGetReferenceCountPage(PFN_TYPE Page);
1229
1230 BOOLEAN
1231 NTAPI
1232 MmIsPageInUse(PFN_TYPE Page);
1233
1234 VOID
1235 NTAPI
1236 MmSetFlagsPage(
1237 PFN_TYPE Page,
1238 ULONG Flags);
1239
1240 ULONG
1241 NTAPI
1242 MmGetFlagsPage(PFN_TYPE Page);
1243
1244 VOID
1245 NTAPI
1246 MmSetSavedSwapEntryPage(
1247 PFN_TYPE Page,
1248 SWAPENTRY SavedSwapEntry);
1249
1250 SWAPENTRY
1251 NTAPI
1252 MmGetSavedSwapEntryPage(PFN_TYPE Page);
1253
1254 VOID
1255 NTAPI
1256 MmSetCleanPage(
1257 struct _EPROCESS *Process,
1258 PVOID Address
1259 );
1260
1261 NTSTATUS
1262 NTAPI
1263 MmCreatePageTable(PVOID PAddress);
1264
1265 VOID
1266 NTAPI
1267 MmDeletePageTable(
1268 struct _EPROCESS *Process,
1269 PVOID Address
1270 );
1271
1272 PFN_TYPE
1273 NTAPI
1274 MmGetPfnForProcess(
1275 struct _EPROCESS *Process,
1276 PVOID Address
1277 );
1278
1279 BOOLEAN
1280 NTAPI
1281 MmCreateProcessAddressSpace(
1282 IN ULONG MinWs,
1283 IN PEPROCESS Dest,
1284 IN PLARGE_INTEGER DirectoryTableBase
1285 );
1286
1287 NTSTATUS
1288 NTAPI
1289 MmInitializeHandBuiltProcess(
1290 IN PEPROCESS Process,
1291 IN PLARGE_INTEGER DirectoryTableBase
1292 );
1293
1294
1295 NTSTATUS
1296 NTAPI
1297 MmInitializeHandBuiltProcess2(
1298 IN PEPROCESS Process
1299 );
1300
1301 NTSTATUS
1302 NTAPI
1303 MmReleaseMmInfo(struct _EPROCESS *Process);
1304
1305 NTSTATUS
1306 NTAPI
1307 Mmi386ReleaseMmInfo(struct _EPROCESS *Process);
1308
1309 VOID
1310 NTAPI
1311 MmDeleteVirtualMapping(
1312 struct _EPROCESS *Process,
1313 PVOID Address,
1314 BOOLEAN FreePage,
1315 BOOLEAN* WasDirty,
1316 PPFN_TYPE Page
1317 );
1318
1319 BOOLEAN
1320 NTAPI
1321 MmIsDirtyPage(
1322 struct _EPROCESS *Process,
1323 PVOID Address
1324 );
1325
1326 VOID
1327 NTAPI
1328 MmMarkPageMapped(PFN_TYPE Page);
1329
1330 VOID
1331 NTAPI
1332 MmMarkPageUnmapped(PFN_TYPE Page);
1333
1334 VOID
1335 NTAPI
1336 MmUpdatePageDir(
1337 struct _EPROCESS *Process,
1338 PVOID Address,
1339 ULONG Size
1340 );
1341
1342 VOID
1343 NTAPI
1344 MiInitPageDirectoryMap(VOID);
1345
1346 ULONG
1347 NTAPI
1348 MiGetUserPageDirectoryCount(VOID);
1349
1350 /* wset.c ********************************************************************/
1351
1352 NTSTATUS
1353 MmTrimUserMemory(
1354 ULONG Target,
1355 ULONG Priority,
1356 PULONG NrFreedPages
1357 );
1358
1359 /* region.c ************************************************************/
1360
1361 NTSTATUS
1362 NTAPI
1363 MmAlterRegion(
1364 PMADDRESS_SPACE AddressSpace,
1365 PVOID BaseAddress,
1366 PLIST_ENTRY RegionListHead,
1367 PVOID StartAddress,
1368 ULONG Length,
1369 ULONG NewType,
1370 ULONG NewProtect,
1371 PMM_ALTER_REGION_FUNC AlterFunc
1372 );
1373
1374 VOID
1375 NTAPI
1376 MmInitializeRegion(
1377 PLIST_ENTRY RegionListHead,
1378 SIZE_T Length,
1379 ULONG Type,
1380 ULONG Protect
1381 );
1382
1383 PMM_REGION
1384 NTAPI
1385 MmFindRegion(
1386 PVOID BaseAddress,
1387 PLIST_ENTRY RegionListHead,
1388 PVOID Address,
1389 PVOID* RegionBaseAddress
1390 );
1391
1392 /* section.c *****************************************************************/
1393
1394 PFILE_OBJECT
1395 NTAPI
1396 MmGetFileObjectForSection(
1397 IN PROS_SECTION_OBJECT Section
1398 );
1399 NTSTATUS
1400 NTAPI
1401 MmGetFileNameForAddress(
1402 IN PVOID Address,
1403 OUT PUNICODE_STRING ModuleName
1404 );
1405
1406 NTSTATUS
1407 NTAPI
1408 MmGetFileNameForSection(
1409 IN PROS_SECTION_OBJECT Section,
1410 OUT POBJECT_NAME_INFORMATION *ModuleName
1411 );
1412
1413 PVOID
1414 NTAPI
1415 MmAllocateSection(
1416 IN ULONG Length,
1417 PVOID BaseAddress
1418 );
1419
1420 NTSTATUS
1421 NTAPI
1422 MmQuerySectionView(
1423 PMEMORY_AREA MemoryArea,
1424 PVOID Address,
1425 PMEMORY_BASIC_INFORMATION Info,
1426 PULONG ResultLength
1427 );
1428
1429 NTSTATUS
1430 NTAPI
1431 MmProtectSectionView(
1432 PMADDRESS_SPACE AddressSpace,
1433 PMEMORY_AREA MemoryArea,
1434 PVOID BaseAddress,
1435 ULONG Length,
1436 ULONG Protect,
1437 PULONG OldProtect
1438 );
1439
1440 NTSTATUS
1441 NTAPI
1442 MmWritePageSectionView(
1443 PMADDRESS_SPACE AddressSpace,
1444 PMEMORY_AREA MArea,
1445 PVOID Address,
1446 PMM_PAGEOP PageOp
1447 );
1448
1449 NTSTATUS
1450 NTAPI
1451 MmInitSectionImplementation(VOID);
1452
1453 NTSTATUS
1454 NTAPI
1455 MmNotPresentFaultSectionView(
1456 PMADDRESS_SPACE AddressSpace,
1457 MEMORY_AREA* MemoryArea,
1458 PVOID Address,
1459 BOOLEAN Locked
1460 );
1461
1462 NTSTATUS
1463 NTAPI
1464 MmPageOutSectionView(
1465 PMADDRESS_SPACE AddressSpace,
1466 PMEMORY_AREA MemoryArea,
1467 PVOID Address,
1468 struct _MM_PAGEOP *PageOp
1469 );
1470
1471 NTSTATUS
1472 NTAPI
1473 MmCreatePhysicalMemorySection(VOID);
1474
1475 NTSTATUS
1476 NTAPI
1477 MmAccessFaultSectionView(
1478 PMADDRESS_SPACE AddressSpace,
1479 MEMORY_AREA* MemoryArea,
1480 PVOID Address,
1481 BOOLEAN Locked
1482 );
1483
1484 VOID
1485 NTAPI
1486 MmFreeSectionSegments(PFILE_OBJECT FileObject);
1487
1488 /* mpw.c *********************************************************************/
1489
1490 NTSTATUS
1491 NTAPI
1492 MmInitMpwThread(VOID);
1493
1494 NTSTATUS
1495 NTAPI
1496 MmInitBsmThread(VOID);
1497
1498 /* pager.c *******************************************************************/
1499
1500 BOOLEAN
1501 NTAPI
1502 MiIsPagerThread(VOID);
1503
1504 VOID
1505 NTAPI
1506 MiStartPagerThread(VOID);
1507
1508 VOID
1509 NTAPI
1510 MiStopPagerThread(VOID);
1511
1512 NTSTATUS
1513 FASTCALL
1514 MiQueryVirtualMemory(
1515 IN HANDLE ProcessHandle,
1516 IN PVOID Address,
1517 IN MEMORY_INFORMATION_CLASS VirtualMemoryInformationClass,
1518 OUT PVOID VirtualMemoryInformation,
1519 IN ULONG Length,
1520 OUT PULONG ResultLength
1521 );
1522
1523 /* sysldr.c ******************************************************************/
1524
1525 VOID
1526 NTAPI
1527 MiReloadBootLoadedDrivers(
1528 IN PLOADER_PARAMETER_BLOCK LoaderBlock
1529 );
1530
1531 BOOLEAN
1532 NTAPI
1533 MiInitializeLoadedModuleList(
1534 IN PLOADER_PARAMETER_BLOCK LoaderBlock
1535 );
1536
1537 NTSTATUS
1538 NTAPI
1539 MmLoadSystemImage(
1540 IN PUNICODE_STRING FileName,
1541 IN PUNICODE_STRING NamePrefix OPTIONAL,
1542 IN PUNICODE_STRING LoadedName OPTIONAL,
1543 IN ULONG Flags,
1544 OUT PVOID *ModuleObject,
1545 OUT PVOID *ImageBaseAddress
1546 );
1547
1548 NTSTATUS
1549 NTAPI
1550 MmUnloadSystemImage(
1551 IN PVOID ImageHandle
1552 );
1553
1554 NTSTATUS
1555 NTAPI
1556 MmCheckSystemImage(
1557 IN HANDLE ImageHandle,
1558 IN BOOLEAN PurgeSection
1559 );
1560
1561 FORCEINLINE
1562 VOID
1563 NTAPI
1564 MiSyncThreadProcessViews(IN PVOID Process,
1565 IN PVOID Address,
1566 IN ULONG Size)
1567 {
1568 MmUpdatePageDir((PEPROCESS)Process, Address, Size);
1569 }
1570
1571
1572 extern MADDRESS_SPACE MmKernelAddressSpace;
1573
1574 FORCEINLINE
1575 VOID
1576 MmLockAddressSpace(PMADDRESS_SPACE AddressSpace)
1577 {
1578 KeEnterCriticalRegion();
1579 ExAcquirePushLockExclusive(AddressSpace->Lock);
1580 }
1581
1582 FORCEINLINE
1583 VOID
1584 MmUnlockAddressSpace(PMADDRESS_SPACE AddressSpace)
1585 {
1586 ExReleasePushLock(AddressSpace->Lock);
1587 KeLeaveCriticalRegion();
1588 }
1589
1590 FORCEINLINE
1591 PMADDRESS_SPACE
1592 MmGetCurrentAddressSpace(VOID)
1593 {
1594 return (PMADDRESS_SPACE)&((PEPROCESS)KeGetCurrentThread()->ApcState.Process)->VadRoot;
1595 }
1596
1597 FORCEINLINE
1598 PMADDRESS_SPACE
1599 MmGetKernelAddressSpace(VOID)
1600 {
1601 return &MmKernelAddressSpace;
1602 }
1603
1604 #endif