- Initialize the used page count for the non paged pool in MmInitializeBalancer.
[reactos.git] / reactos / ntoskrnl / include / internal / mm.h
index e14b03a..9dd2742 100644 (file)
 /* TYPES *********************************************************************/
 
 struct _EPROCESS;
+
+struct _MM_RMAP_ENTRY;
+struct _MM_PAGEOP;
 typedef ULONG SWAPENTRY;
 
 #define MEMORY_AREA_INVALID              (0)
-#define MEMORY_AREA_SECTION_VIEW_COMMIT  (1)
+#define MEMORY_AREA_SECTION_VIEW         (1)
 #define MEMORY_AREA_CONTINUOUS_MEMORY    (2)
 #define MEMORY_AREA_NO_CACHE             (3)
 #define MEMORY_AREA_IO_MAPPING           (4)
 #define MEMORY_AREA_SYSTEM               (5)
 #define MEMORY_AREA_MDL_MAPPING          (7)
 #define MEMORY_AREA_VIRTUAL_MEMORY       (8)
-#define MEMORY_AREA_SECTION_VIEW_RESERVE (9)
-#define MEMORY_AREA_CACHE_SEGMENT        (10)
-#define MEMORY_AREA_SHARED_DATA          (11)
-#define MEMORY_AREA_WORKING_SET          (12)
+#define MEMORY_AREA_CACHE_SEGMENT        (9)
+#define MEMORY_AREA_SHARED_DATA          (10)
+#define MEMORY_AREA_KERNEL_STACK         (11)
+#define MEMORY_AREA_PAGED_POOL           (12)
+#define MEMORY_AREA_NO_ACCESS            (13)
 
 #define PAGE_TO_SECTION_PAGE_DIRECTORY_OFFSET(x) \
                           ((x) / (4*1024*1024))
@@ -34,10 +38,6 @@ typedef ULONG SWAPENTRY;
 #define NR_SECTION_PAGE_TABLES           (1024)
 #define NR_SECTION_PAGE_ENTRIES          (1024)
 
-/*
- * Flags for section objects
- */
-#define SO_PHYSICAL_MEMORY                      (0x1)
 
 /*
  * Additional flags for protection attributes
@@ -57,7 +57,7 @@ typedef ULONG SWAPENTRY;
 
 typedef struct
 {
-   ULONG Pages[NR_SECTION_PAGE_ENTRIES];
+  ULONG Entry[NR_SECTION_PAGE_ENTRIES];
 } SECTION_PAGE_TABLE, *PSECTION_PAGE_TABLE;
 
 typedef struct
@@ -65,8 +65,10 @@ typedef struct
    PSECTION_PAGE_TABLE PageTables[NR_SECTION_PAGE_TABLES];
 } SECTION_PAGE_DIRECTORY, *PSECTION_PAGE_DIRECTORY;
 
-#define MM_PAGEFILE_SECTION    (0x1)
-#define MM_IMAGE_SECTION       (0x2)
+#define SEC_PHYSICALMEMORY     (0x80000000)
+
+#define MM_PAGEFILE_SEGMENT    (0x1)
+#define MM_DATAFILE_SEGMENT    (0x2)
 
 #define MM_SECTION_SEGMENT_BSS (0x1)
 
@@ -77,28 +79,17 @@ typedef struct _MM_SECTION_SEGMENT
   ULONG Attributes;
   ULONG Length;
   ULONG RawLength;
-  KMUTEX Lock;
+  FAST_MUTEX Lock;
   ULONG ReferenceCount;
   SECTION_PAGE_DIRECTORY PageDirectory;
   ULONG Flags;
   PVOID VirtualAddress;
   ULONG Characteristics;
+  BOOLEAN WriteCopy;
 } MM_SECTION_SEGMENT, *PMM_SECTION_SEGMENT;
 
-typedef struct
+typedef struct _MM_IMAGE_SECTION_OBJECT
 {
-  CSHORT Type;
-  CSHORT Size;
-  LARGE_INTEGER MaximumSize;
-  ULONG SectionPageProtection;
-  ULONG AllocateAttributes;
-  PFILE_OBJECT FileObject;
-  LIST_ENTRY ViewListHead;
-  KSPIN_LOCK ViewListLock;
-  KMUTEX Lock;
-  ULONG Flags;
-  ULONG NrSegments;
-  PMM_SECTION_SEGMENT Segments;
   PVOID ImageBase;
   PVOID EntryPoint;
   ULONG StackReserve;
@@ -109,54 +100,81 @@ typedef struct
   ULONG ImageCharacteristics;
   USHORT Machine;
   BOOLEAN Executable;
-} SECTION_OBJECT, *PSECTION_OBJECT;
+  ULONG NrSegments;
+  MM_SECTION_SEGMENT Segments[0];
+} MM_IMAGE_SECTION_OBJECT, *PMM_IMAGE_SECTION_OBJECT;
 
-typedef struct
+typedef struct _SECTION_OBJECT
 {
-   ULONG Type;
-   PVOID BaseAddress;
-   ULONG Length;
-   ULONG Attributes;
-   LIST_ENTRY Entry;
-   ULONG LockCount;
-   struct _EPROCESS* Process;
-   union
-     {
-       struct
-         {          
-            SECTION_OBJECT* Section;
-            ULONG ViewOffset;
-            LIST_ENTRY ViewListEntry;
-            PMM_SECTION_SEGMENT Segment;
-         } SectionData;
-       struct
-         {
-            LIST_ENTRY SegmentListHead;
-         } VirtualMemoryData;
-     } Data;
-} MEMORY_AREA, *PMEMORY_AREA;
+  CSHORT Type;
+  CSHORT Size;
+  LARGE_INTEGER MaximumSize;
+  ULONG SectionPageProtection;
+  ULONG AllocationAttributes;
+  PFILE_OBJECT FileObject;
+  LIST_ENTRY ViewListHead;
+  KSPIN_LOCK ViewListLock;
+  union
+  {
+    PMM_IMAGE_SECTION_OBJECT ImageSection;
+    PMM_SECTION_SEGMENT Segment;
+  };
+} SECTION_OBJECT;
+
+#ifndef __USE_W32API
+
+typedef struct _SECTION_OBJECT *PSECTION_OBJECT;
 
-typedef struct _KCIRCULAR_QUEUE
+#endif /* __USE_W32API */
+
+typedef struct
 {
-  ULONG First;
-  ULONG Last;
-  ULONG CurrentSize;
-  ULONG MaximumSize;  
-  PVOID* Mem;
-} KCIRCULAR_QUEUE, *PKCIRCULAR_QUEUE;
+  ULONG Type;
+  PVOID BaseAddress;
+  ULONG Length;
+  ULONG Attributes;
+  LIST_ENTRY Entry;
+  ULONG LockCount;
+  struct _EPROCESS* Process;
+  BOOLEAN DeleteInProgress;
+  ULONG PageOpCount;
+  union
+  {
+    struct
+    {
+      SECTION_OBJECT* Section;
+      ULONG ViewOffset;
+      LIST_ENTRY ViewListEntry;
+      PMM_SECTION_SEGMENT Segment;
+      BOOLEAN WriteCopyView;
+      LIST_ENTRY RegionListHead;
+    } SectionData;
+    struct
+    {
+      LIST_ENTRY RegionListHead;
+    } VirtualMemoryData;
+  } Data;
+} MEMORY_AREA, *PMEMORY_AREA;
 
 typedef struct _MADDRESS_SPACE
 {
   LIST_ENTRY MAreaListHead;
-  KMUTEX Lock;
+  FAST_MUTEX Lock;
   ULONG LowestAddress;
   struct _EPROCESS* Process;
-  PMEMORY_AREA WorkingSetArea;
-  KCIRCULAR_QUEUE WSQueue;
   PUSHORT PageTableRefCountTable;
   ULONG PageTableRefCountTableSize;
 } MADDRESS_SPACE, *PMADDRESS_SPACE;
 
+
+#ifndef __USE_W32API
+/* VARIABLES */
+
+extern PVOID MmSystemRangeStart;
+
+#endif /* __USE_W32API */
+
+
 /* FUNCTIONS */
 
 VOID MmLockAddressSpace(PMADDRESS_SPACE AddressSpace);
@@ -175,23 +193,27 @@ NTSTATUS MmCreateMemoryArea(struct _EPROCESS* Process,
                            ULONG Length,
                            ULONG Attributes,
                            MEMORY_AREA** Result,
-                           BOOL FixedAddress);
+                           BOOL FixedAddress,
+                           BOOL TopDown);
 MEMORY_AREA* MmOpenMemoryAreaByAddress(PMADDRESS_SPACE AddressSpace, 
                                       PVOID Address);
 NTSTATUS MmInitMemoryAreas(VOID);
-VOID ExInitNonPagedPool(ULONG BaseAddress);
+VOID MiInitializeNonPagedPool(VOID);
 NTSTATUS MmFreeMemoryArea(PMADDRESS_SPACE AddressSpace,
                          PVOID BaseAddress,
                          ULONG Length,
-                         VOID (*FreePage)(PVOID Context, PVOID Address,
-                                          ULONG PhysAddr),
+                         VOID (*FreePage)(PVOID Context, MEMORY_AREA* MemoryArea, 
+                                          PVOID Address, PHYSICAL_ADDRESS PhysAddr, SWAPENTRY SwapEntry,
+                                          BOOLEAN Dirty),
                          PVOID FreePageContext);
 VOID MmDumpMemoryAreas(PLIST_ENTRY ListHead);
 NTSTATUS MmLockMemoryArea(MEMORY_AREA* MemoryArea);
 NTSTATUS MmUnlockMemoryArea(MEMORY_AREA* MemoryArea);
 NTSTATUS MmInitSectionImplementation(VOID);
 
+#ifndef __USE_W32API
 #define MM_LOWEST_USER_ADDRESS (4096)
+#endif
 
 PMEMORY_AREA MmSplitMemoryArea(struct _EPROCESS* Process,
                               PMADDRESS_SPACE AddressSpace,
@@ -200,14 +222,17 @@ PMEMORY_AREA MmSplitMemoryArea(struct _EPROCESS* Process,
                               ULONG Length,
                               ULONG NewType,
                               ULONG NewAttributes);
-PVOID MmInitializePageList(PVOID FirstPhysKernelAddress,
-                          PVOID LastPhysKernelAddress,
-                          ULONG MemorySizeInPages,
-                          ULONG LastKernelBase);
-
-PVOID MmAllocPage(SWAPENTRY SavedSwapEntry);
-VOID MmDereferencePage(PVOID PhysicalAddress);
-VOID MmReferencePage(PVOID PhysicalAddress);
+PVOID 
+MmInitializePageList(PVOID FirstPhysKernelAddress,
+                    PVOID LastPhysKernelAddress,
+                    ULONG MemorySizeInPages,
+                    ULONG LastKernelBase,
+                    PADDRESS_RANGE BIOSMemoryMap,
+                    ULONG AddressRangeCount);
+PHYSICAL_ADDRESS
+MmAllocPage(ULONG Consumer, SWAPENTRY SavedSwapEntry);
+VOID MmDereferencePage(PHYSICAL_ADDRESS PhysicalAddress);
+VOID MmReferencePage(PHYSICAL_ADDRESS PhysicalAddress);
 VOID MmDeletePageTable(struct _EPROCESS* Process, 
                       PVOID Address);
 NTSTATUS MmCopyMmInfo(struct _EPROCESS* Src, 
@@ -219,7 +244,8 @@ MmDeleteVirtualMapping(struct _EPROCESS* Process,
                       PVOID Address, 
                       BOOL FreePage,
                       BOOL* WasDirty,
-                      ULONG* PhysicalPage);
+                      PHYSICAL_ADDRESS* PhysicalPage);
+VOID MmUpdateStackPageDir(PULONG LocalPageDir, struct _KTHREAD* KThread);
 
 #define MM_PAGE_CLEAN     (0)
 #define MM_PAGE_DIRTY     (1)
@@ -227,8 +253,9 @@ MmDeleteVirtualMapping(struct _EPROCESS* Process,
 VOID MmBuildMdlFromPages(PMDL Mdl, PULONG Pages);
 PVOID MmGetMdlPageAddress(PMDL Mdl, PVOID Offset);
 VOID MiShutdownMemoryManager(VOID);
-ULONG MmGetPhysicalAddressForProcess(struct _EPROCESS* Process,
-                                    PVOID Address);
+PHYSICAL_ADDRESS
+MmGetPhysicalAddressForProcess(struct _EPROCESS* Process,
+                              PVOID Address);
 NTSTATUS STDCALL
 MmUnmapViewOfSection(struct _EPROCESS* Process, PVOID BaseAddress);
 VOID MmInitPagingFile(VOID);
@@ -274,35 +301,25 @@ MmNotPresentFaultSectionView(PMADDRESS_SPACE AddressSpace,
 NTSTATUS MmWaitForPage(PVOID Page);
 VOID MmClearWaitPage(PVOID Page);
 VOID MmSetWaitPage(PVOID Page);
-BOOLEAN MmIsPageDirty(struct _EPROCESS* Process, PVOID Address);
+BOOLEAN MmIsDirtyPage(struct _EPROCESS* Process, PVOID Address);
 BOOLEAN MmIsPageTablePresent(PVOID PAddress);
-ULONG MmPageOutSectionView(PMADDRESS_SPACE AddressSpace,
-                          MEMORY_AREA* MemoryArea, 
-                          PVOID Address,
-                          PBOOLEAN Ul);
-ULONG MmPageOutVirtualMemory(PMADDRESS_SPACE AddressSpace,
-                            PMEMORY_AREA MemoryArea,
-                            PVOID Address,
-                            PBOOLEAN Ul);
+NTSTATUS 
+MmPageOutVirtualMemory(PMADDRESS_SPACE AddressSpace,
+                      PMEMORY_AREA MemoryArea,
+                      PVOID Address,
+                      struct _MM_PAGEOP* PageOp);
+NTSTATUS 
+MmPageOutSectionView(PMADDRESS_SPACE AddressSpace,
+                      PMEMORY_AREA MemoryArea,
+                      PVOID Address,
+                      struct _MM_PAGEOP* PageOp);
 MEMORY_AREA* MmOpenMemoryAreaByRegion(PMADDRESS_SPACE AddressSpace, 
                                      PVOID Address,
                                      ULONG Length);
-
+PVOID MmFindGap(PMADDRESS_SPACE AddressSpace, ULONG Length, BOOL TopDown);
 VOID ExUnmapPage(PVOID Addr);
 PVOID ExAllocatePage(VOID);
 
-VOID MmLockWorkingSet(struct _EPROCESS* Process);
-VOID MmUnlockWorkingSet(struct _EPROCESS* Process);
-VOID MmInitializeWorkingSet(struct _EPROCESS* Process,
-                           PMADDRESS_SPACE AddressSpace);
-ULONG MmTrimWorkingSet(struct _EPROCESS* Process,
-                      ULONG ReduceHint);
-VOID MmRemovePageFromWorkingSet(struct _EPROCESS* Process,
-                               PVOID Address);
-VOID MmAddPageToWorkingSet(struct _EPROCESS* Process,
-                             PVOID Address);
-
-VOID MmInitPagingFile(VOID);
 BOOLEAN MmReserveSwapPages(ULONG Nr);
 VOID MmDereserveSwapPages(ULONG Nr);
 SWAPENTRY MmAllocSwapPage(VOID);
@@ -310,16 +327,17 @@ VOID MmFreeSwapPage(SWAPENTRY Entry);
 
 VOID MmInit1(ULONG FirstKernelPhysAddress, 
             ULONG LastKernelPhysAddress,
-            ULONG LastKernelAddress);
+            ULONG LastKernelAddress,
+       PADDRESS_RANGE BIOSMemoryMap,
+       ULONG AddressRangeCount,
+       ULONG MaxMemInMeg);
 VOID MmInit2(VOID);
 VOID MmInit3(VOID);
+VOID MiFreeInitMemory(VOID);
 NTSTATUS MmInitPagerThread(VOID);
+NTSTATUS MmInitZeroPageThread(VOID);
 
-VOID MmInitKernelMap(PVOID BaseAddress);
-
-VOID MmWaitForFreePages(VOID);
-PVOID MmMustAllocPage(SWAPENTRY SavedSwapEntry);
-PVOID MmAllocPageMaybeSwap(SWAPENTRY SavedSwapEntry);
+VOID MiInitKernelMap(VOID);
 NTSTATUS MmCreatePageTable(PVOID PAddress);
 
 typedef struct
@@ -338,14 +356,6 @@ typedef struct
 
 extern MM_STATS MmStats;
 
-NTSTATUS 
-MmWritePageSectionView(PMADDRESS_SPACE AddressSpace,
-                      PMEMORY_AREA MArea,
-                      PVOID Address);
-NTSTATUS 
-MmWritePageVirtualMemory(PMADDRESS_SPACE AddressSpace,
-                        PMEMORY_AREA MArea,
-                        PVOID Address);
 PVOID 
 MmGetDirtyPagesFromWorkingSet(struct _EPROCESS* Process);
 NTSTATUS 
@@ -353,21 +363,22 @@ MmWriteToSwapPage(SWAPENTRY SwapEntry, PMDL Mdl);
 NTSTATUS 
 MmReadFromSwapPage(SWAPENTRY SwapEntry, PMDL Mdl);
 VOID 
-MmSetFlagsPage(PVOID PhysicalAddress, ULONG Flags);
+MmSetFlagsPage(PHYSICAL_ADDRESS PhysicalAddress, ULONG Flags);
 ULONG 
-MmGetFlagsPage(PVOID PhysicalAddress);
-VOID MmSetSavedSwapEntryPage(PVOID PhysicalAddress,
+MmGetFlagsPage(PHYSICAL_ADDRESS PhysicalAddress);
+VOID MmSetSavedSwapEntryPage(PHYSICAL_ADDRESS PhysicalAddress,
                             SWAPENTRY SavedSwapEntry);
-SWAPENTRY MmGetSavedSwapEntryPage(PVOID PhysicalAddress);
+SWAPENTRY MmGetSavedSwapEntryPage(PHYSICAL_ADDRESS PhysicalAddress);
 VOID MmSetCleanPage(struct _EPROCESS* Process, PVOID Address);
-VOID MmLockPage(PVOID PhysicalPage);
-VOID MmUnlockPage(PVOID PhysicalPage);
+VOID MmLockPage(PHYSICAL_ADDRESS PhysicalPage);
+VOID MmUnlockPage(PHYSICAL_ADDRESS PhysicalPage);
+ULONG MmGetLockCountPage(PHYSICAL_ADDRESS PhysicalPage);
 
-NTSTATUS MmSafeCopyFromUser(PVOID Dest, PVOID Src, ULONG Count);
-NTSTATUS MmSafeCopyToUser(PVOID Dest, PVOID Src, ULONG Count);
+NTSTATUS MmSafeCopyFromUser(PVOID Dest, const VOID *Src, ULONG Count);
+NTSTATUS MmSafeCopyToUser(PVOID Dest, const VOID *Src, ULONG Count);
 NTSTATUS 
 MmCreatePhysicalMemorySection(VOID);
-PVOID
+PHYSICAL_ADDRESS
 MmGetContinuousPages(ULONG NumberOfBytes,
                     PHYSICAL_ADDRESS HighestAcceptableAddress,
                     ULONG Alignment);
@@ -382,11 +393,16 @@ MmAccessFaultSectionView(PMADDRESS_SPACE AddressSpace,
 ULONG
 MmGetPageProtect(struct _EPROCESS* Process, PVOID Address);
 PVOID 
-ExAllocatePageWithPhysPage(ULONG PhysPage);
+ExAllocatePageWithPhysPage(PHYSICAL_ADDRESS PhysPage);
 ULONG
-MmGetReferenceCountPage(PVOID PhysicalAddress);
+MmGetReferenceCountPage(PHYSICAL_ADDRESS PhysicalAddress);
 BOOLEAN
-MmIsUsablePage(PVOID PhysicalAddress);
+MmIsUsablePage(PHYSICAL_ADDRESS PhysicalAddress);
+
+#define MM_PAGEOP_PAGEIN        (1)
+#define MM_PAGEOP_PAGEOUT       (2)
+#define MM_PAGEOP_PAGESYNCH     (3)
+#define MM_PAGEOP_ACCESSFAULT   (4)
 
 typedef struct _MM_PAGEOP
 {
@@ -424,34 +440,217 @@ MmReleasePageOp(PMM_PAGEOP PageOp);
 
 PMM_PAGEOP
 MmGetPageOp(PMEMORY_AREA MArea, ULONG Pid, PVOID Address,
-           PMM_SECTION_SEGMENT Segment, ULONG Offset);
-
+           PMM_SECTION_SEGMENT Segment, ULONG Offset, ULONG OpType);
+PMM_PAGEOP
+MmCheckForPageOp(PMEMORY_AREA MArea, ULONG Pid, PVOID Address,
+                PMM_SECTION_SEGMENT Segment, ULONG Offset);
+VOID
+MmInitializePageOp(VOID);
 VOID
 MiDebugDumpNonPagedPool(BOOLEAN NewOnly);
 VOID
 MiDebugDumpNonPagedPoolStats(BOOLEAN NewOnly);
 VOID 
-MmMarkPageMapped(PVOID PhysicalAddress);
+MmMarkPageMapped(PHYSICAL_ADDRESS PhysicalAddress);
 VOID 
-MmMarkPageUnmapped(PVOID PhysicalAddress);
+MmMarkPageUnmapped(PHYSICAL_ADDRESS PhysicalAddress);
 VOID
 MmFreeSectionSegments(PFILE_OBJECT FileObject);
 
-typedef struct _MM_IMAGE_SECTION_OBJECT
-{
-  ULONG NrSegments;
-  MM_SECTION_SEGMENT Segments[0];
-} MM_IMAGE_SECTION_OBJECT, *PMM_IMAGE_SECTION_OBJECT;
+
 
 VOID 
 MmFreeVirtualMemory(struct _EPROCESS* Process, PMEMORY_AREA MemoryArea);
 NTSTATUS
-MiCopyFromUserPage(ULONG DestPhysPage, PVOID SourceAddress);
+MiCopyFromUserPage(PHYSICAL_ADDRESS DestPhysPage, PVOID SourceAddress);
 NTSTATUS
-MiZeroPage(ULONG PhysPage);
+MiZeroPage(PHYSICAL_ADDRESS PhysPage);
 BOOLEAN 
 MmIsAccessedAndResetAccessPage(struct _EPROCESS* Process, PVOID Address);
-SWAPENTRY 
-MmGetSavedSwapEntryPage(PVOID PhysicalAddress);
+
+#define STATUS_MM_RESTART_OPERATION       ((NTSTATUS)0xD0000001)
+
+NTSTATUS 
+MmCreateVirtualMappingForKernel(PVOID Address, 
+                               ULONG flProtect,
+                               PHYSICAL_ADDRESS PhysicalAddress);
+NTSTATUS MmCommitPagedPoolAddress(PVOID Address);
+NTSTATUS MmCreateVirtualMapping(struct _EPROCESS* Process,
+                               PVOID Address, 
+                               ULONG flProtect,
+                               PHYSICAL_ADDRESS PhysicalAddress,
+                               BOOLEAN MayWait);
+NTSTATUS 
+MmCreateVirtualMappingUnsafe(struct _EPROCESS* Process,
+                            PVOID Address, 
+                            ULONG flProtect,
+                            PHYSICAL_ADDRESS PhysicalAddress,
+                            BOOLEAN MayWait);
+
+VOID MmSetPageProtect(struct _EPROCESS* Process,
+                     PVOID Address,
+                     ULONG flProtect);
+BOOLEAN MmIsPagePresent(struct _EPROCESS* Process, 
+                       PVOID Address);
+
+VOID MmInitGlobalKernelPageDirectory(VOID);
+
+/* Memory balancing. */
+VOID
+MmInitializeMemoryConsumer(ULONG Consumer, 
+                          NTSTATUS (*Trim)(ULONG Target, ULONG Priority, 
+                                           PULONG NrFreed));
+VOID
+MmInitializeBalancer(ULONG NrAvailablePages, ULONG NrSystemPages);
+NTSTATUS
+MmReleasePageMemoryConsumer(ULONG Consumer, PHYSICAL_ADDRESS Page);
+NTSTATUS
+MmRequestPageMemoryConsumer(ULONG Consumer, BOOLEAN CanWait, 
+                           PHYSICAL_ADDRESS* AllocatedPage);
+
+#define MC_CACHE          (0)
+#define MC_USER           (1)
+#define MC_PPOOL          (2)
+#define MC_NPPOOL         (3)
+#define MC_MAXIMUM        (4)
+
+VOID 
+MmSetRmapListHeadPage(PHYSICAL_ADDRESS PhysicalAddress, 
+                     struct _MM_RMAP_ENTRY* ListHead);
+struct _MM_RMAP_ENTRY*
+MmGetRmapListHeadPage(PHYSICAL_ADDRESS PhysicalAddress);
+VOID
+MmInsertRmap(PHYSICAL_ADDRESS PhysicalAddress, PEPROCESS Process, 
+            PVOID Address);
+VOID
+MmDeleteAllRmaps(PHYSICAL_ADDRESS PhysicalAddress, PVOID Context, 
+                VOID (*DeleteMapping)(PVOID Context, PEPROCESS Process, PVOID Address));
+VOID
+MmDeleteRmap(PHYSICAL_ADDRESS PhysicalAddress, PEPROCESS Process, 
+            PVOID Address);
+VOID
+MmInitializeRmapList(VOID);
+PHYSICAL_ADDRESS
+MmGetLRUNextUserPage(PHYSICAL_ADDRESS PreviousPhysicalAddress);
+PHYSICAL_ADDRESS
+MmGetLRUFirstUserPage(VOID);
+NTSTATUS
+MmPageOutPhysicalAddress(PHYSICAL_ADDRESS PhysicalAddress);
+NTSTATUS
+MmTrimUserMemory(ULONG Target, ULONG Priority, PULONG NrFreedPages);
+
+VOID
+MmDisableVirtualMapping(PEPROCESS Process, PVOID Address, BOOL* WasDirty, PHYSICAL_ADDRESS* PhysicalAddr);
+VOID MmEnableVirtualMapping(PEPROCESS Process, PVOID Address);
+VOID
+MmDeletePageFileMapping(PEPROCESS Process, PVOID Address, 
+                       SWAPENTRY* SwapEntry);
+NTSTATUS 
+MmCreatePageFileMapping(PEPROCESS Process,
+                       PVOID Address,
+                       SWAPENTRY SwapEntry);
+BOOLEAN MmIsPageSwapEntry(PEPROCESS Process, PVOID Address);
+VOID
+MmTransferOwnershipPage(PHYSICAL_ADDRESS PhysicalAddress, ULONG NewConsumer);
+VOID MmSetDirtyPage(PEPROCESS Process, PVOID Address);
+VOID
+MmInitializeMdlImplementation(VOID);
+extern PHYSICAL_ADDRESS MmSharedDataPagePhysicalAddress;
+struct _KTRAP_FRAME;
+NTSTATUS STDCALL 
+MmDumpToPagingFile(ULONG BugCode,
+                  ULONG BugCodeParameter1,
+                  ULONG BugCodeParameter2,
+                  ULONG BugCodeParameter3,
+                  ULONG BugCodeParameter4,
+                  struct _KTRAP_FRAME* TrapFrame);
+
+typedef VOID (*PMM_ALTER_REGION_FUNC)(PMADDRESS_SPACE AddressSpace,
+                                     PVOID BaseAddress, ULONG Length,
+                                     ULONG OldType, ULONG OldProtect,
+                                     ULONG NewType, ULONG NewProtect);
+
+typedef struct _MM_REGION
+{
+   ULONG Type;
+   ULONG Protect;
+   ULONG Length;
+   LIST_ENTRY RegionListEntry;
+} MM_REGION, *PMM_REGION;
+
+NTSTATUS
+MmAlterRegion(PMADDRESS_SPACE AddressSpace, PVOID BaseAddress, 
+             PLIST_ENTRY RegionListHead, PVOID StartAddress, ULONG Length, 
+             ULONG NewType, ULONG NewProtect, 
+             PMM_ALTER_REGION_FUNC AlterFunc);
+VOID
+MmInitialiseRegion(PLIST_ENTRY RegionListHead, ULONG Length, ULONG Type,
+                  ULONG Protect);
+PMM_REGION
+MmFindRegion(PVOID BaseAddress, PLIST_ENTRY RegionListHead, PVOID Address,
+            PVOID* RegionBaseAddress);
+NTSTATUS STDCALL
+MmQueryAnonMem(PMEMORY_AREA MemoryArea,
+              PVOID Address,
+              PMEMORY_BASIC_INFORMATION Info,
+              PULONG ResultLength);
+NTSTATUS STDCALL
+MmQuerySectionView(PMEMORY_AREA MemoryArea,
+                  PVOID Address,
+                  PMEMORY_BASIC_INFORMATION Info,
+                  PULONG ResultLength);
+NTSTATUS
+MmProtectAnonMem(PMADDRESS_SPACE AddressSpace,
+                PMEMORY_AREA MemoryArea,
+                PVOID BaseAddress,
+                ULONG Length,
+                ULONG Protect,
+                PULONG OldProtect);
+NTSTATUS
+MmProtectSectionView(PMADDRESS_SPACE AddressSpace,
+                    PMEMORY_AREA MemoryArea,
+                    PVOID BaseAddress,
+                    ULONG Length,
+                    ULONG Protect,
+                    PULONG OldProtect);
+NTSTATUS 
+MmWritePageSectionView(PMADDRESS_SPACE AddressSpace,
+                      PMEMORY_AREA MArea,
+                      PVOID Address,
+                      PMM_PAGEOP PageOp);
+NTSTATUS 
+MmWritePageVirtualMemory(PMADDRESS_SPACE AddressSpace,
+                        PMEMORY_AREA MArea,
+                        PVOID Address,
+                        PMM_PAGEOP PageOp);
+VOID
+MmSetCleanAllRmaps(PHYSICAL_ADDRESS PhysicalAddress);
+VOID
+MmSetDirtyAllRmaps(PHYSICAL_ADDRESS PhysicalAddress);
+NTSTATUS
+MmWritePagePhysicalAddress(PHYSICAL_ADDRESS PhysicalAddress);
+BOOL
+MmIsDirtyPageRmap(PHYSICAL_ADDRESS PhysicalAddress);
+NTSTATUS MmInitMpwThread(VOID);
+BOOLEAN
+MmIsAvailableSwapPage(VOID);
+VOID
+MmShowOutOfSpaceMessagePagingFile(VOID);
+VOID
+MmRebalanceMemoryConsumers(VOID);
+BOOLEAN
+MiIsPagerThread(VOID);
+VOID
+MiStartPagerThread(VOID);
+VOID
+MmSetLRULastPage(PHYSICAL_ADDRESS PhysicalAddress);
+VOID
+MmRawDeleteVirtualMapping(PVOID Address);
+VOID
+MiStopPagerThread(VOID);
+NTSTATUS 
+MmCreateVirtualMappingDump(PVOID Address, 
+                          ULONG flProtect,
+                          PHYSICAL_ADDRESS PhysicalAddress);
 
 #endif