extern PMEMORY_ALLOCATION_DESCRIPTOR MiFreeDescriptor;
extern MEMORY_ALLOCATION_DESCRIPTOR MiFreeDescriptorOrg;
extern ULONG MmHighestPhysicalPage;
-extern PVOID MmPfnDatabase;
struct _KTRAP_FRAME;
struct _EPROCESS;
typedef ULONG SWAPENTRY;
typedef ULONG PFN_TYPE, *PPFN_TYPE;
+#define MI_STATIC_MEMORY_AREAS (8)
+
#define MEMORY_AREA_INVALID (0)
#define MEMORY_AREA_SECTION_VIEW (1)
#define MEMORY_AREA_CONTINUOUS_MEMORY (2)
#define MEMORY_AREA_PAGED_POOL (12)
#define MEMORY_AREA_NO_ACCESS (13)
#define MEMORY_AREA_PEB_OR_TEB (14)
+#define MEMORY_AREA_STATIC (0x80000000)
#define MM_PHYSICAL_PAGE_MPW_PENDING (0x8)
/* Number of list heads to use */
#define MI_FREE_POOL_LISTS 4
-#define HYPER_SPACE (0xC0400000)
-
#define MI_HYPERSPACE_PTES (256 - 1)
+#define MI_ZERO_PTES (32)
#define MI_MAPPING_RANGE_START (ULONG)HYPER_SPACE
#define MI_MAPPING_RANGE_END (MI_MAPPING_RANGE_START + \
MI_HYPERSPACE_PTES * PAGE_SIZE)
#define MC_USER (1)
#define MC_PPOOL (2)
#define MC_NPPOOL (3)
-#define MC_MAXIMUM (4)
+#define MC_SYSTEM (4)
+#define MC_MAXIMUM (5)
#define PAGED_POOL_MASK 1
#define MUST_SUCCEED_POOL_MASK 2
ULONG PagingRequestsInLastFifteenMinutes;
} MM_STATS;
-typedef struct _PHYSICAL_PAGE
+//
+// These two mappings are actually used by Windows itself, based on the ASSERTS
+//
+#define StartOfAllocation ReadInProgress
+#define EndOfAllocation WriteInProgress
+
+typedef struct _MMPFNENTRY
+{
+ USHORT Modified:1;
+ USHORT ReadInProgress:1; // StartOfAllocation
+ USHORT WriteInProgress:1; // EndOfAllocation
+ USHORT PrototypePte:1; // Zero
+ USHORT PageColor:4; // LockCount
+ USHORT PageLocation:3; // Consumer
+ USHORT RemovalRequested:1;
+ USHORT CacheAttribute:2; // Type
+ USHORT Rom:1;
+ USHORT ParityError:1;
+} MMPFNENTRY;
+
+typedef struct _MMPFN
{
union
{
+ PFN_NUMBER Flink; // ListEntry.Flink
+ ULONG WsIndex;
+ PKEVENT Event;
+ NTSTATUS ReadStatus;
+ SINGLE_LIST_ENTRY NextStackPfn;
+ } u1;
+ PMMPTE PteAddress; // ListEntry.Blink
+ union
+ {
+ PFN_NUMBER Blink;
+ ULONG_PTR ShareCount; // MapCount
+ } u2;
+ union
+ {
+ struct
+ {
+ USHORT ReferenceCount; // ReferenceCount
+ MMPFNENTRY e1;
+ };
struct
{
- ULONG Type: 2;
- ULONG Consumer: 3;
- ULONG Zero: 1;
- ULONG StartOfAllocation: 1;
- ULONG EndOfAllocation: 1;
- }
- Flags;
- ULONG AllFlags;
+ USHORT ReferenceCount;
+ USHORT ShortFlags;
+ } e2;
+ } u3;
+ union
+ {
+ MMPTE OriginalPte;
+ LONG AweReferenceCount; // RmapListHead
};
-
- LIST_ENTRY ListEntry;
- ULONG ReferenceCount;
- SWAPENTRY SavedSwapEntry;
- ULONG LockCount;
- ULONG MapCount;
- struct _MM_RMAP_ENTRY* RmapListHead;
-}
-PHYSICAL_PAGE, *PPHYSICAL_PAGE;
-
+ union
+ {
+ ULONG_PTR EntireFrame; // SavedSwapEntry
+ struct
+ {
+ ULONG_PTR PteFrame:25;
+ ULONG_PTR InPageError:1;
+ ULONG_PTR VerifierAllocation:1;
+ ULONG_PTR AweAllocation:1;
+ ULONG_PTR Priority:3;
+ ULONG_PTR MustBeCached:1;
+ };
+ } u4;
+} MMPFN, *PMMPFN;
+
+extern PMMPFN MmPfnDatabase;
extern MM_STATS MmStats;
typedef struct _MM_PAGEOP
NTAPI
ExFreePagedPool(IN PVOID Block);
+BOOLEAN
+NTAPI
+ExpIsPoolTagDebuggable(ULONG Tag);
+
+PVOID
+NTAPI
+ExpAllocateDebugPool(
+ POOL_TYPE Type,
+ ULONG Size,
+ ULONG Tag,
+ PVOID Caller,
+ BOOLEAN EndOfPage
+);
+
+VOID
+NTAPI
+ExpFreeDebugPool(PVOID Block, BOOLEAN PagedPool);
+
VOID
NTAPI
MmInitializePagedPool(VOID);
PMEMORY_AREA MemoryArea,
PVOID Address,
PMEMORY_BASIC_INFORMATION Info,
- PULONG ResultLength
+ PSIZE_T ResultLength
);
VOID
/* freelist.c **********************************************************/
-#define ASSERT_PFN(x) ASSERT((x)->Flags.Type != 0)
+#define ASSERT_PFN(x) ASSERT((x)->u3.e1.CacheAttribute != 0)
FORCEINLINE
-PPHYSICAL_PAGE
+PMMPFN
MiGetPfnEntry(IN PFN_TYPE Pfn)
{
- PPHYSICAL_PAGE Page;
- extern PPHYSICAL_PAGE MmPageArray;
- extern ULONG MmPageArraySize;
-
- /* Mark MmPageArraySize as unreferenced, otherwise it will appear as an unused variable on a Release build */
- UNREFERENCED_PARAMETER(MmPageArraySize);
+ PMMPFN Page;
+ extern RTL_BITMAP MiPfnBitMap;
/* Make sure the PFN number is valid */
- ASSERT(Pfn <= MmPageArraySize);
+ if (Pfn > MmHighestPhysicalPage) return NULL;
+
+ /* Make sure this page actually has a PFN entry */
+ if ((MiPfnBitMap.Buffer) && !(RtlTestBit(&MiPfnBitMap, Pfn))) return NULL;
/* Get the entry */
- Page = &MmPageArray[Pfn];
+ Page = &MmPfnDatabase[Pfn];
/* Make sure it's valid */
ASSERT_PFN(Page);
return Page;
};
+FORCEINLINE
+PFN_NUMBER
+MiGetPfnEntryIndex(IN PMMPFN Pfn1)
+{
+ //
+ // This will return the Page Frame Number (PFN) from the MMPFN
+ //
+ return Pfn1 - MmPfnDatabase;
+}
+
PFN_TYPE
NTAPI
MmGetLRUNextUserPage(PFN_TYPE PreviousPage);
VOID
);
+VOID
+NTAPI
+MmDumpPfnDatabase(
+ VOID
+);
+
PFN_TYPE
NTAPI
MmGetContinuousPages(
ULONG NumberOfBytes,
PHYSICAL_ADDRESS LowestAcceptableAddress,
PHYSICAL_ADDRESS HighestAcceptableAddress,
- PHYSICAL_ADDRESS BoundaryAddressMultiple
+ PHYSICAL_ADDRESS BoundaryAddressMultiple,
+ BOOLEAN ZeroPages
);
NTSTATUS
PVOID
NTAPI
-MiMapPageToZeroInHyperSpace(IN PFN_NUMBER Page);
+MiMapPagesToZeroInHyperSpace(IN PMMPFN *Pages,
+ IN PFN_NUMBER NumberOfPages);
+
+VOID
+NTAPI
+MiUnmapPagesInZeroSpace(IN PVOID VirtualAddress,
+ IN PFN_NUMBER NumberOfPages);
//
// ReactOS Compatibility Layer
//
-PVOID
FORCEINLINE
+PVOID
MmCreateHyperspaceMapping(IN PFN_NUMBER Page)
{
HyperProcess = (PEPROCESS)KeGetCurrentThread()->ApcState.Process;
return MiMapPageInHyperSpace(HyperProcess, Page, &HyperIrql);
}
+FORCEINLINE
+PVOID
+MiMapPageToZeroInHyperSpace(IN PFN_NUMBER Page)
+{
+ PMMPFN Pfn1 = MiGetPfnEntry(Page);
+ return MiMapPagesToZeroInHyperSpace(&Pfn1, 1);
+}
+
#define MmDeleteHyperspaceMapping(x) MiUnmapPageInHyperSpace(HyperProcess, x, HyperIrql);
/* i386/page.c *********************************************************/
NTAPI
MmIsPageInUse(PFN_TYPE Page);
-VOID
-NTAPI
-MmSetFlagsPage(
- PFN_TYPE Page,
- ULONG Flags);
-
-ULONG
-NTAPI
-MmGetFlagsPage(PFN_TYPE Page);
-
VOID
NTAPI
MmSetSavedSwapEntryPage(
MmCreateProcessAddressSpace(
IN ULONG MinWs,
IN PEPROCESS Dest,
- IN PULONG DirectoryTableBase
+ IN PULONG_PTR DirectoryTableBase
);
NTSTATUS
NTAPI
MmInitializeHandBuiltProcess(
IN PEPROCESS Process,
- IN PULONG DirectoryTableBase
+ IN PULONG_PTR DirectoryTableBase
);
PMEMORY_AREA MemoryArea,
PVOID Address,
PMEMORY_BASIC_INFORMATION Info,
- PULONG ResultLength
+ PSIZE_T ResultLength
);
NTSTATUS
IN PVOID Address,
IN MEMORY_INFORMATION_CLASS VirtualMemoryInformationClass,
OUT PVOID VirtualMemoryInformation,
- IN ULONG Length,
- OUT PULONG ResultLength
+ IN SIZE_T Length,
+ OUT PSIZE_T ResultLength
);
/* sysldr.c ******************************************************************/