[NTOSKRNL]
[reactos.git] / reactos / ntoskrnl / include / internal / mm.h
index 02fa7e9..4cace38 100644 (file)
@@ -6,12 +6,13 @@
 
 struct _EPROCESS;
 
-extern PFN_NUMBER MiFreeSwapPages;
-extern PFN_NUMBER MiUsedSwapPages;
+extern PMMSUPPORT MmKernelAddressSpace;
+extern PFN_COUNT MiFreeSwapPages;
+extern PFN_COUNT MiUsedSwapPages;
 extern SIZE_T MmTotalPagedPoolQuota;
 extern SIZE_T MmTotalNonPagedPoolQuota;
 extern PHYSICAL_ADDRESS MmSharedDataPagePhysicalAddress;
-extern PFN_NUMBER MmNumberOfPhysicalPages;
+extern PFN_COUNT MmNumberOfPhysicalPages;
 extern UCHAR MmDisablePagingExecutive;
 extern PFN_NUMBER MmLowestPhysicalPage;
 extern PFN_NUMBER MmHighestPhysicalPage;
@@ -48,8 +49,7 @@ extern PMMPTE MmDebugPte;
 struct _KTRAP_FRAME;
 struct _EPROCESS;
 struct _MM_RMAP_ENTRY;
-struct _MM_PAGEOP;
-typedef ULONG SWAPENTRY;
+typedef ULONG_PTR SWAPENTRY;
 
 //
 // MmDbgCopyMemory Flags
@@ -73,7 +73,7 @@ typedef ULONG SWAPENTRY;
 #endif
 
 #define MEMORY_AREA_SECTION_VIEW            (1)
-#define MEMORY_AREA_VIRTUAL_MEMORY          (8)
+#define MEMORY_AREA_CACHE                   (2)
 #define MEMORY_AREA_OWNED_BY_ARM3           (15)
 #define MEMORY_AREA_STATIC                  (0x80000000)
 
@@ -83,11 +83,6 @@ typedef ULONG SWAPENTRY;
 #define MM_CORE_DUMP_TYPE_MINIMAL           (0x1)
 #define MM_CORE_DUMP_TYPE_FULL              (0x2)
 
-#define MM_PAGEOP_PAGEIN                    (1)
-#define MM_PAGEOP_PAGEOUT                   (2)
-#define MM_PAGEOP_PAGESYNCH                 (3)
-#define MM_PAGEOP_ACCESSFAULT               (4)
-
 /* Number of list heads to use */
 #define MI_FREE_POOL_LISTS 4
 
@@ -184,6 +179,10 @@ typedef ULONG SWAPENTRY;
     (PAGE_WRITECOPY | \
     PAGE_EXECUTE_WRITECOPY)
 
+//
+// Wait entry for marking pages that are being serviced
+//
+#define MM_WAIT_ENTRY            0x7ffffc00
 
 #define InterlockedCompareExchangePte(PointerPte, Exchange, Comperand) \
     InterlockedCompareExchange((PLONG)(PointerPte), Exchange, Comperand)
@@ -191,45 +190,35 @@ typedef ULONG SWAPENTRY;
 #define InterlockedExchangePte(PointerPte, Value) \
     InterlockedExchange((PLONG)(PointerPte), Value)
 
-typedef struct
-{
-    ULONG Entry[NR_SECTION_PAGE_ENTRIES];
-} SECTION_PAGE_TABLE, *PSECTION_PAGE_TABLE;
-
-typedef struct
-{
-    PSECTION_PAGE_TABLE PageTables[NR_SECTION_PAGE_TABLES];
-} SECTION_PAGE_DIRECTORY, *PSECTION_PAGE_DIRECTORY;
-
 typedef struct _MM_SECTION_SEGMENT
 {
-    LONG FileOffset;           /* start offset into the file for image sections */
-    ULONG_PTR VirtualAddress;  /* dtart offset into the address range for image sections */
-    ULONG RawLength;           /* length of the segment which is part of the mapped file */
-    ULONG Length;                      /* absolute length of the segment */
-    ULONG Protection;
     FAST_MUTEX Lock;           /* lock which protects the page directory */
+       PFILE_OBJECT FileObject;
+    LARGE_INTEGER RawLength;           /* length of the segment which is part of the mapped file */
+    LARGE_INTEGER Length;                      /* absolute length of the segment */
     ULONG ReferenceCount;
-    SECTION_PAGE_DIRECTORY PageDirectory;
+       ULONG CacheCount;
+    ULONG Protection;
     ULONG Flags;
-    ULONG Characteristics;
     BOOLEAN WriteCopy;
+       BOOLEAN Locked;
+
+       struct
+       {
+               ULONGLONG FileOffset;           /* start offset into the file for image sections */
+               ULONG_PTR VirtualAddress;       /* start offset into the address range for image sections */
+               ULONG Characteristics;
+       } Image;
+
+       LIST_ENTRY ListOfSegments;
+       RTL_GENERIC_TABLE PageTable;
 } MM_SECTION_SEGMENT, *PMM_SECTION_SEGMENT;
 
 typedef struct _MM_IMAGE_SECTION_OBJECT
 {
-    ULONG_PTR ImageBase;
-    ULONG_PTR StackReserve;
-    ULONG_PTR StackCommit;
-    ULONG_PTR EntryPoint;
-    USHORT Subsystem;
-    USHORT ImageCharacteristics;
-    USHORT MinorSubsystemVersion;
-    USHORT MajorSubsystemVersion;
-    USHORT Machine;
-    BOOLEAN Executable;
+    SECTION_IMAGE_INFORMATION ImageInformation;
+    PVOID BasedAddress;
     ULONG NrSegments;
-    ULONG ImageSize;
     PMM_SECTION_SEGMENT Segments;
 } MM_IMAGE_SECTION_OBJECT, *PMM_IMAGE_SECTION_OBJECT;
 
@@ -248,8 +237,6 @@ typedef struct _ROS_SECTION_OBJECT
     };
 } ROS_SECTION_OBJECT, *PROS_SECTION_OBJECT;
 
-struct _MM_CACHE_SECTION_SEGMENT;
-
 typedef struct _MEMORY_AREA
 {
     PVOID StartingAddress;
@@ -261,22 +248,17 @@ typedef struct _MEMORY_AREA
     ULONG Protect;
     ULONG Flags;
     BOOLEAN DeleteInProgress;
-    ULONG PageOpCount;
+    ULONG Magic;
     PVOID Vad;
     union
     {
         struct
         {
             ROS_SECTION_OBJECT* Section;
-            ULONG ViewOffset;
+            LARGE_INTEGER ViewOffset;
             PMM_SECTION_SEGMENT Segment;
             LIST_ENTRY RegionListHead;
         } SectionData;
-               struct
-               {
-            LARGE_INTEGER ViewOffset;
-            struct _MM_CACHE_SECTION_SEGMENT *Segment;
-               } CacheData;
         struct
         {
             LIST_ENTRY RegionListHead;
@@ -357,10 +339,13 @@ typedef struct _MMPFN
     union
     {
         PFN_NUMBER Flink;
-        ULONG WsIndex;                       // SavedSwapEntry
+        ULONG WsIndex;
         PKEVENT Event;
         NTSTATUS ReadStatus;
         SINGLE_LIST_ENTRY NextStackPfn;
+
+        // HACK for ROSPFN
+        SWAPENTRY SwapEntry;
     } u1;
     PMMPTE PteAddress;
     union
@@ -372,7 +357,7 @@ typedef struct _MMPFN
     {
         struct
         {
-            USHORT ReferenceCount;           // ReferenceCount
+            USHORT ReferenceCount;
             MMPFNENTRY e1;
         };
         struct
@@ -384,7 +369,10 @@ typedef struct _MMPFN
     union
     {
         MMPTE OriginalPte;
-        LONG AweReferenceCount;              // RmapListHead
+        LONG AweReferenceCount;
+
+        // HACK for ROSPFN
+        PMM_RMAP_ENTRY RmapListHead;
     };
     union
     {
@@ -421,37 +409,6 @@ extern MMPFNLIST MmStandbyPageListHead;
 extern MMPFNLIST MmModifiedPageListHead;
 extern MMPFNLIST MmModifiedNoWritePageListHead;
 
-typedef struct _MM_PAGEOP
-{
-  /* Type of operation. */
-  ULONG OpType;
-  /* Number of threads interested in this operation. */
-  ULONG ReferenceCount;
-  /* Event that will be set when the operation is completed. */
-  KEVENT CompletionEvent;
-  /* Status of the operation once it is completed. */
-  NTSTATUS Status;
-  /* TRUE if the operation was abandoned. */
-  BOOLEAN Abandoned;
-  /* The memory area to be affected by the operation. */
-  PMEMORY_AREA MArea;
-  ULONG Hash;
-  struct _MM_PAGEOP* Next;
-  struct _ETHREAD* Thread;
-  /*
-   * These fields are used to identify the operation if it is against a
-   * virtual memory area.
-   */
-  HANDLE Pid;
-  PVOID Address;
-  /*
-   * These fields are used to identify the operation if it is against a
-   * section mapping.
-   */
-  PMM_SECTION_SEGMENT Segment;
-  ULONG Offset;
-} MM_PAGEOP, *PMM_PAGEOP;
-
 typedef struct _MM_MEMORY_CONSUMER
 {
     ULONG PagesUsed;
@@ -463,7 +420,7 @@ typedef struct _MM_REGION
 {
     ULONG Type;
     ULONG Protect;
-    ULONG Length;
+    SIZE_T Length;
     LIST_ENTRY RegionListEntry;
 } MM_REGION, *PMM_REGION;
 
@@ -471,7 +428,7 @@ typedef struct _MM_REGION
 typedef struct _MMFREE_POOL_ENTRY
 {
     LIST_ENTRY List;
-    PFN_NUMBER Size;
+    PFN_COUNT Size;
     ULONG Signature;
     struct _MMFREE_POOL_ENTRY *Owner;
 } MMFREE_POOL_ENTRY, *PMMFREE_POOL_ENTRY;
@@ -498,7 +455,7 @@ typedef VOID
 (*PMM_ALTER_REGION_FUNC)(
     PMMSUPPORT AddressSpace,
     PVOID BaseAddress,
-    ULONG Length,
+    SIZE_T Length,
     ULONG OldType,
     ULONG OldProtect,
     ULONG NewType,
@@ -536,6 +493,18 @@ MmIsSessionAddress(
     IN PVOID Address
 );
 
+ULONG
+NTAPI
+MmGetSessionId(
+    IN PEPROCESS Process
+);
+
+ULONG
+NTAPI
+MmGetSessionIdEx(
+    IN PEPROCESS Process
+);
+
 /* marea.c *******************************************************************/
 
 NTSTATUS
@@ -544,12 +513,12 @@ MmCreateMemoryArea(
     PMMSUPPORT AddressSpace,
     ULONG Type,
     PVOID *BaseAddress,
-    ULONG_PTR Length,
+    SIZE_T Length,
     ULONG Protection,
     PMEMORY_AREA *Result,
     BOOLEAN FixedAddress,
     ULONG AllocationFlags,
-    PHYSICAL_ADDRESS BoundaryAddressMultiple OPTIONAL
+    ULONG AllocationGranularity
 );
 
 PMEMORY_AREA
@@ -593,14 +562,14 @@ NTAPI
 MmLocateMemoryAreaByRegion(
     PMMSUPPORT AddressSpace,
     PVOID Address,
-    ULONG_PTR Length
+    SIZE_T Length
 );
 
 PVOID
 NTAPI
 MmFindGap(
     PMMSUPPORT AddressSpace,
-    ULONG_PTR Length,
+    SIZE_T Length,
     ULONG_PTR Granularity,
     BOOLEAN TopDown
 );
@@ -616,10 +585,19 @@ MmReleaseMemoryAreaIfDecommitted(
 VOID
 NTAPI
 MmMapMemoryArea(PVOID BaseAddress,
-                ULONG Length,
+                SIZE_T Length,
                 ULONG Consumer,
                 ULONG Protection);
 
+VOID
+NTAPI
+MiRosCheckMemoryAreas(
+   PMMSUPPORT AddressSpace);
+
+VOID
+NTAPI
+MiCheckAllProcessMemoryAreas(VOID);
+
 /* npool.c *******************************************************************/
 
 VOID
@@ -886,6 +864,36 @@ MmPageFault(
     ULONG ErrorCode
 );
 
+/* special.c *****************************************************************/
+
+VOID
+NTAPI
+MiInitializeSpecialPool();
+
+BOOLEAN
+NTAPI
+MmUseSpecialPool(
+    IN SIZE_T NumberOfBytes,
+    IN ULONG Tag);
+
+BOOLEAN
+NTAPI
+MmIsSpecialPoolAddress(
+    IN PVOID P);
+
+PVOID
+NTAPI
+MmAllocateSpecialPool(
+    IN SIZE_T NumberOfBytes,
+    IN ULONG Tag,
+    IN POOL_TYPE PoolType,
+    IN ULONG SpecialType);
+
+VOID
+NTAPI
+MmFreeSpecialPool(
+    IN PVOID P);
+
 /* mm.c **********************************************************************/
 
 NTSTATUS
@@ -904,8 +912,7 @@ NTAPI
 MmNotPresentFaultVirtualMemory(
     PMMSUPPORT AddressSpace,
     MEMORY_AREA* MemoryArea,
-    PVOID Address,
-    BOOLEAN Locked
+    PVOID Address
 );
 
 NTSTATUS
@@ -914,7 +921,7 @@ MmPageOutVirtualMemory(
     PMMSUPPORT AddressSpace,
     PMEMORY_AREA MemoryArea,
     PVOID Address,
-    struct _MM_PAGEOP* PageOp
+    PFN_NUMBER Page
 );
 
 NTSTATUS
@@ -939,7 +946,7 @@ MmProtectAnonMem(
     PMMSUPPORT AddressSpace,
     PMEMORY_AREA MemoryArea,
     PVOID BaseAddress,
-    ULONG Length,
+    SIZE_T Length,
     ULONG Protect,
     PULONG OldProtect
 );
@@ -950,7 +957,7 @@ MmWritePageVirtualMemory(
     PMMSUPPORT AddressSpace,
     PMEMORY_AREA MArea,
     PVOID Address,
-    PMM_PAGEOP PageOp
+    PFN_NUMBER Page
 );
 
 /* kmap.c ********************************************************************/
@@ -970,8 +977,8 @@ ExAllocatePageWithPhysPage(PFN_NUMBER Page);
 NTSTATUS
 NTAPI
 MiCopyFromUserPage(
-    PFN_NUMBER Page,
-    PVOID SourceAddress
+    PFN_NUMBER NewPage,
+    PFN_NUMBER OldPage
 );
 
 NTSTATUS
@@ -984,38 +991,6 @@ PVOID
 FASTCALL
 MmSafeReadPtr(PVOID Source);
 
-/* pageop.c ******************************************************************/
-
-VOID
-NTAPI
-MmReleasePageOp(PMM_PAGEOP PageOp);
-
-PMM_PAGEOP
-NTAPI
-MmGetPageOp(
-    PMEMORY_AREA MArea,
-    HANDLE Pid,
-    PVOID Address,
-    PMM_SECTION_SEGMENT Segment,
-    ULONG Offset,
-    ULONG OpType,
-    BOOLEAN First
-);
-
-PMM_PAGEOP
-NTAPI
-MmCheckForPageOp(
-    PMEMORY_AREA MArea,
-    HANDLE Pid,
-    PVOID Address,
-    PMM_SECTION_SEGMENT Segment,
-    ULONG Offset
-);
-
-VOID
-NTAPI
-MmInitializePageOp(VOID);
-
 /* process.c *****************************************************************/
 
 PVOID
@@ -1119,10 +1094,6 @@ BOOLEAN
 NTAPI
 MmIsDirtyPageRmap(PFN_NUMBER Page);
 
-NTSTATUS
-NTAPI
-MmWritePagePhysicalAddress(PFN_NUMBER Page);
-
 NTSTATUS
 NTAPI
 MmPageOutPhysicalAddress(PFN_NUMBER Page);
@@ -1138,9 +1109,9 @@ MiGetPfnEntry(IN PFN_NUMBER Pfn)
 
     /* Make sure the PFN number is valid */
     if (Pfn > MmHighestPhysicalPage) return NULL;
-    
+
     /* Make sure this page actually has a PFN entry */
-    if ((MiPfnBitMap.Buffer) && !(RtlTestBit(&MiPfnBitMap, Pfn))) return NULL;
+    if ((MiPfnBitMap.Buffer) && !(RtlTestBit(&MiPfnBitMap, (ULONG)Pfn))) return NULL;
 
     /* Get the entry */
     Page = &MmPfnDatabase[Pfn];
@@ -1234,8 +1205,8 @@ MiUnmapPageInHyperSpace(IN PEPROCESS Process,
 
 PVOID
 NTAPI
-MiMapPagesToZeroInHyperSpace(IN PMMPFN Pfn1,
-                             IN PFN_NUMBER NumberOfPages);
+MiMapPagesInZeroSpace(IN PMMPFN Pfn1,
+                      IN PFN_NUMBER NumberOfPages);
 
 VOID
 NTAPI
@@ -1314,18 +1285,16 @@ MmIsPagePresent(
     PVOID Address
 );
 
-VOID
+BOOLEAN
 NTAPI
-MmInitGlobalKernelPageDirectory(VOID);
+MmIsDisabledPage(
+    struct _EPROCESS* Process,
+    PVOID Address
+);
 
 VOID
 NTAPI
-MmDisableVirtualMapping(
-    struct _EPROCESS *Process,
-    PVOID Address,
-    BOOLEAN* WasDirty,
-    PPFN_NUMBER Page
-);
+MmInitGlobalKernelPageDirectory(VOID);
 
 VOID
 NTAPI
@@ -1334,15 +1303,10 @@ MmEnableVirtualMapping(
     PVOID Address
 );
 
-VOID
-NTAPI
-MmRawDeleteVirtualMapping(PVOID Address);
-
-
 VOID
 NTAPI
 MmGetPageFileMapping(
-       struct _EPROCESS *Process, 
+       struct _EPROCESS *Process,
        PVOID Address,
        SWAPENTRY* SwapEntry);
 
@@ -1478,7 +1442,15 @@ MmReleaseMmInfo(struct _EPROCESS *Process);
 
 NTSTATUS
 NTAPI
-Mmi386ReleaseMmInfo(struct _EPROCESS *Process);
+MmSetExecuteOptions(IN ULONG ExecuteOptions);
+
+NTSTATUS
+NTAPI
+MmGetExecuteOptions(IN PULONG ExecuteOptions);
+
+VOID
+NTAPI
+MmDeleteProcessPageDirectory(struct _EPROCESS *Process);
 
 VOID
 NTAPI
@@ -1539,7 +1511,7 @@ MmAlterRegion(
     PVOID BaseAddress,
     PLIST_ENTRY RegionListHead,
     PVOID StartAddress,
-    ULONG Length,
+    SIZE_T Length,
     ULONG NewType,
     ULONG NewProtect,
     PMM_ALTER_REGION_FUNC AlterFunc
@@ -1565,6 +1537,12 @@ MmFindRegion(
 
 /* section.c *****************************************************************/
 
+VOID
+NTAPI
+MmGetImageInformation(
+    OUT PSECTION_IMAGE_INFORMATION ImageInformation
+);
+
 PFILE_OBJECT
 NTAPI
 MmGetFileObjectForSection(
@@ -1587,7 +1565,7 @@ MmGetFileNameForSection(
 PVOID
 NTAPI
 MmAllocateSection(
-    IN ULONG Length,
+    IN SIZE_T Length,
     PVOID BaseAddress
 );
 
@@ -1606,20 +1584,11 @@ MmProtectSectionView(
     PMMSUPPORT AddressSpace,
     PMEMORY_AREA MemoryArea,
     PVOID BaseAddress,
-    ULONG Length,
+    SIZE_T Length,
     ULONG Protect,
     PULONG OldProtect
 );
 
-NTSTATUS
-NTAPI
-MmWritePageSectionView(
-    PMMSUPPORT AddressSpace,
-    PMEMORY_AREA MArea,
-    PVOID Address,
-    PMM_PAGEOP PageOp
-);
-
 NTSTATUS
 NTAPI
 MmInitSectionImplementation(VOID);
@@ -1639,7 +1608,7 @@ MmPageOutSectionView(
     PMMSUPPORT AddressSpace,
     PMEMORY_AREA MemoryArea,
     PVOID Address,
-    struct _MM_PAGEOP *PageOp
+    ULONG_PTR Entry
 );
 
 NTSTATUS
@@ -1651,8 +1620,7 @@ NTAPI
 MmAccessFaultSectionView(
     PMMSUPPORT AddressSpace,
     MEMORY_AREA* MemoryArea,
-    PVOID Address,
-    BOOLEAN Locked
+    PVOID Address
 );
 
 VOID
@@ -1739,7 +1707,15 @@ MmCallDllInitialize(
     IN PLIST_ENTRY ListHead
 );
 
-extern PMMSUPPORT MmKernelAddressSpace;
+
+/* procsup.c *****************************************************************/
+
+NTSTATUS
+NTAPI
+MmGrowKernelStack(
+    IN PVOID StackPointer
+);
+
 
 FORCEINLINE
 VOID
@@ -1776,3 +1752,46 @@ MmGetKernelAddressSpace(VOID)
 {
     return MmKernelAddressSpace;
 }
+
+
+/* expool.c ******************************************************************/
+
+VOID
+NTAPI
+ExpCheckPoolAllocation(
+    PVOID P,
+    POOL_TYPE PoolType,
+    ULONG Tag);
+
+
+/* session.c *****************************************************************/
+
+_IRQL_requires_max_(APC_LEVEL)
+NTSTATUS
+NTAPI
+MmAttachSession(
+    _Inout_ PVOID SessionEntry,
+    _Out_ PKAPC_STATE ApcState);
+
+_IRQL_requires_max_(APC_LEVEL)
+VOID
+NTAPI
+MmDetachSession(
+    _Inout_ PVOID SessionEntry,
+    _Out_ PKAPC_STATE ApcState);
+
+VOID
+NTAPI
+MmQuitNextSession(
+    _Inout_ PVOID SessionEntry);
+
+PVOID
+NTAPI
+MmGetSessionById(
+    _In_ ULONG SessionId);
+
+_IRQL_requires_max_(APC_LEVEL)
+VOID
+NTAPI
+MmSetSessionLocaleId(
+    _In_ LCID LocaleId);