18#define PA_BIT_PRESENT (0)
19#define PA_BIT_READWRITE (1)
20#define PA_BIT_USER (2)
23#define PA_BIT_ACCESSED (5)
24#define PA_BIT_DIRTY (6)
25#define PA_BIT_GLOBAL (8)
27#define PA_PRESENT (1 << PA_BIT_PRESENT)
28#define PA_READWRITE (1 << PA_BIT_READWRITE)
29#define PA_USER (1 << PA_BIT_USER)
30#define PA_DIRTY (1 << PA_BIT_DIRTY)
31#define PA_WT (1 << PA_BIT_WT)
32#define PA_CD (1 << PA_BIT_CD)
33#define PA_ACCESSED (1 << PA_BIT_ACCESSED)
34#define PA_GLOBAL (1 << PA_BIT_GLOBAL)
36#define PAGEDIRECTORY_MAP (0xc0000000 + (PTE_BASE / (1024)))
37#define PAE_PAGEDIRECTORY_MAP (0xc0000000 + (PTE_BASE / (512)))
39#define HYPERSPACE (Ke386Pae ? 0xc0800000 : 0xc0400000)
40#define IS_HYPERSPACE(v) (((ULONG)(v) >= HYPERSPACE && (ULONG)(v) < HYPERSPACE + 0x400000))
45#define PTE_TO_PFN(X) ((X) >> PAGE_SHIFT)
46#define PFN_TO_PTE(X) ((X) << PAGE_SHIFT)
48#define PAE_PTE_TO_PFN(X) (PAE_PAGE_MASK(X) >> PAGE_SHIFT)
49#define PAE_PFN_TO_PTE(X) ((X) << PAGE_SHIFT)
51#define PAGE_MASK(x) ((x)&(~0xfff))
52#define PAE_PAGE_MASK(x) ((x)&(~0xfffLL))
123 DPRINT1(
"Unknown main protection type.\n");
150#define ADDR_TO_PAGE_TABLE(v) (((ULONG)(v)) / (1024 * PAGE_SIZE))
152#define ADDR_TO_PDE(v) (PULONG)(PAGEDIRECTORY_MAP + \
153 ((((ULONG)(v)) / (1024 * 1024))&(~0x3)))
154#define ADDR_TO_PTE(v) (PULONG)(PTE_BASE + ((((ULONG)(v) / 1024))&(~0x3)))
156#define ADDR_TO_PDE_OFFSET(v) ((((ULONG)(v)) / (1024 * PAGE_SIZE)))
158#define ADDR_TO_PTE_OFFSET(v) ((((ULONG)(v)) % (1024 * PAGE_SIZE)) / PAGE_SIZE)
161#define PAE_ADDR_TO_PAGE_TABLE(v) (((ULONG)(v)) / (512 * PAGE_SIZE))
163#define PAE_ADDR_TO_PDE(v) (PULONGLONG) (PAE_PAGEDIRECTORY_MAP + \
164 ((((ULONG_PTR)(v)) / (512 * 512))&(~0x7)))
165#define PAE_ADDR_TO_PTE(v) (PULONGLONG) (PTE_BASE + ((((ULONG_PTR)(v) / 512))&(~0x7)))
168#define PAE_ADDR_TO_PDTE_OFFSET(v) (((ULONG_PTR)(v)) / (512 * 512 * PAGE_SIZE))
170#define PAE_ADDR_TO_PDE_PAGE_OFFSET(v) ((((ULONG_PTR)(v)) % (512 * 512 * PAGE_SIZE)) / (512 * PAGE_SIZE))
172#define PAE_ADDR_TO_PDE_OFFSET(v) (((ULONG_PTR)(v))/ (512 * PAGE_SIZE))
174#define PAE_ADDR_TO_PTE_OFFSET(v) ((((ULONG_PTR)(v)) % (512 * PAGE_SIZE)) / PAGE_SIZE)
196 for (
j = 0;
j <
i;
j++)
210 PageDirTable = MmCreateHyperspaceMapping(Pfn[0]);
211 for (
i = 0;
i < 4;
i++)
215 MmDeleteHyperspaceMapping(PageDirTable);
218 PageDir = (
PULONGLONG)MmCreateHyperspaceMapping(Pfn[
i+1]);
222 for (
j = 0;
j < 4;
j++)
232 MmDeleteHyperspaceMapping(PageDir);
238 PageDirectory = MmCreateHyperspaceMapping(Pfn[0]);
248 MmDeleteHyperspaceMapping(PageDirectory);
251 DirectoryTableBase->QuadPart =
PFN_TO_PTE(Pfn[0]);
252 DPRINT(
"Finished MmCopyMmInfo(): %I64x\n", DirectoryTableBase->QuadPart);
274 for (
i = 0;
i < 512;
i++)
278 DbgPrint(
"Page table entry not clear at %x/%x (is %I64x)\n",
291 for (
i = 0;
i < 1024;
i++)
295 DbgPrint(
"Page table entry not clear at %x/%x (is %x)\n",
331 DPRINT(
"MmGetPageTableForProcessForPAE(%x %x %d)\n",
340 if (PageDirTable ==
NULL)
345 MmDeleteHyperspaceMapping(PageDirTable);
356 MmDeleteHyperspaceMapping(PageDir);
376 MmDeleteHyperspaceMapping(PageDir);
377 Pt = MmCreateHyperspaceMapping(Pfn);
401 if (Ke386GlobalPagesEnabled)
454 MmDeleteHyperspaceMapping(PageDir);
473 MmDeleteHyperspaceMapping(PageDir);
474 Pt = MmCreateHyperspaceMapping(Pfn);
498 if (Ke386GlobalPagesEnabled)
622 DPRINT(
"MmDeleteVirtualMapping(%x, %x, %d, %x, %x)\n",
647 Pte = ExfpInterlockedExchange64UL(Pt, &Pte);
655 MmMarkPageUnmapped(Pfn);
705 MmMarkPageUnmapped(Pfn);
728 ((PMADDRESS_SPACE)&
Process->VadRoot)->PageTableRefCountTable !=
NULL &&
734 Ptrc = ((PMADDRESS_SPACE)&
Process->VadRoot)->PageTableRefCountTable;
769 Pte = ExfpInterlockedExchange64UL(Pt, &Pte);
777 ((PMADDRESS_SPACE)&
Process->VadRoot)->PageTableRefCountTable !=
NULL &&
782 Ptrc = ((PMADDRESS_SPACE)&
Process->VadRoot)->PageTableRefCountTable;
795 *SwapEntry = Pte >> 1;
821 ((PMADDRESS_SPACE)&
Process->VadRoot)->PageTableRefCountTable !=
NULL &&
826 Ptrc = ((PMADDRESS_SPACE)&
Process->VadRoot)->PageTableRefCountTable;
839 *SwapEntry = Pte >> 1;
856 FLASH_TLB_ONE(PAddress);
873 FLASH_TLB_ONE(PAddress);
904 DPRINT1(
"MmSetCleanPage is called for user space without a process.\n");
923 tmpPte = Pte & ~PA_DIRTY;
969 DPRINT1(
"MmSetDirtyPage is called for user space without a process.\n");
1069 DPRINT1(
"Setting kernel address with process context\n");
1072 if (SwapEntry & (1 << 31))
1088 tmpPte = SwapEntry << 1;
1089 Pte = ExfpInterlockedExchange64UL(Pt, &tmpPte);
1130 ((PMADDRESS_SPACE)&
Process->VadRoot)->PageTableRefCountTable !=
NULL &&
1136 Ptrc = ((PMADDRESS_SPACE)&
Process->VadRoot)->PageTableRefCountTable;
1155 ULONG oldPdeOffset, PdeOffset;
1158 DPRINT(
"MmCreateVirtualMappingUnsafe(%x, %x, %x, %x (%x), %d)\n",
1168 if (PageCount > 0x10000 ||
1171 DPRINT1(
"Page count to large\n");
1179 DPRINT1(
"Setting kernel address with process context\n");
1186 DPRINT1(
"Page Count to large\n");
1200 if (Ke386GlobalPagesEnabled)
1222 DPRINT1(
"Setting physical address but not allowing access at address "
1223 "0x%.8X with attributes %x/%x.\n",
1228 if (oldPdeOffset != PdeOffset)
1241 oldPdeOffset = PdeOffset;
1243 MmMarkPageMapped(Pages[
i]);
1247 tmpPte |= 0x8000000000000000LL;
1249 Pte = ExfpInterlockedExchange64UL(Pt, &tmpPte);
1259 ((PMADDRESS_SPACE)&
Process->VadRoot)->PageTableRefCountTable !=
NULL &&
1264 Ptrc = ((PMADDRESS_SPACE)&
Process->VadRoot)->PageTableRefCountTable;
1291 DPRINT1(
"Setting physical address but not allowing access at address "
1292 "0x%.8X with attributes %x/%x.\n",
1297 if (oldPdeOffset != PdeOffset)
1310 oldPdeOffset = PdeOffset;
1313 MmMarkPageMapped(Pages[
i]);
1324 ((PMADDRESS_SPACE)&
Process->VadRoot)->PageTableRefCountTable !=
NULL &&
1329 Ptrc = ((PMADDRESS_SPACE)&
Process->VadRoot)->PageTableRefCountTable;
1360 for (
i = 0;
i < PageCount;
i++)
1429 DPRINT(
"MmSetPageProtect(Process %x Address %x flProtect %x)\n",
1441 if (Ke386GlobalPagesEnabled)
1467 tmpPte |= 0x8000000000000000LL;
1471 tmpPte &= ~0x8000000000000000LL;
1498 DPRINT(
"MmInitGlobalKernelPageDirectory()\n");
1510 if (Ke386GlobalPagesEnabled)
1528 if (Ke386GlobalPagesEnabled)
#define InterlockedExchange
#define NT_SUCCESS(StatCode)
#define InterlockedCompareExchangeUL(Destination, Exchange, Comperand)
#define ExfInterlockedCompareExchange64UL(Destination, Exchange, Comperand)
#define InterlockedExchangeUL(Target, Value)
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
__INTRIN_INLINE void __invlpg(void *Address)
#define memcpy(s1, s2, n)
#define PAGE_ROUND_DOWN(x)
#define PAGE_EXECUTE_READ
__GNU_EXTENSION typedef unsigned __int64 * PULONGLONG
#define MmSystemRangeStart
VOID NTAPI KeFlushCurrentTb(VOID)
#define MmSetDirtyPage(__P, __A)
_In_ PVOID _Out_opt_ BOOLEAN * WasDirty
#define MmSetCleanPage(__P, __A)
#define PAGE_WRITETHROUGH
_In_ PVOID _Out_opt_ BOOLEAN _Out_opt_ PPFN_NUMBER Page
BOOLEAN NTAPI MmIsPageInUse(PFN_NUMBER Page)
#define PAGE_IS_EXECUTABLE
NTSTATUS NTAPI MmRequestPageMemoryConsumer(ULONG Consumer, BOOLEAN MyWait, PPFN_NUMBER AllocatedPage)
NTSTATUS NTAPI MmReleasePageMemoryConsumer(ULONG Consumer, PFN_NUMBER Page)
ULONG_PTR NTAPI KeIpiGenericCall(_In_ PKIPI_BROADCAST_WORKER Function, _In_ ULONG_PTR Argument)
#define ADDR_TO_PAGE_TABLE(v)
static ULONG MmGetPageEntryForProcess(PEPROCESS Process, PVOID Address)
static PULONG MmGetPageTableForProcess(PEPROCESS Process, PVOID Address, BOOLEAN Create)
BOOLEAN MmUnmapPageTable(PULONG Pt)
#define PAE_PFN_TO_PTE(X)
VOID NTAPI MmSetPageProtect(PEPROCESS Process, PVOID Address, ULONG flProtect)
static ULONGLONG MmGlobalKernelPageDirectoryForPAE[2048]
#define ADDR_TO_PDE_OFFSET(v)
VOID NTAPI MmDeleteVirtualMapping(PEPROCESS Process, PVOID Address, BOOLEAN *WasDirty, PPFN_NUMBER Page)
static ULONG ProtectToPTE(ULONG flProtect)
VOID NTAPI MmFreePageTable(PEPROCESS Process, PVOID Address)
#define PAE_ADDR_TO_PDE_PAGE_OFFSET(v)
#define PAE_ADDR_TO_PDE(v)
static PULONGLONG MmGetPageTableForProcessForPAE(PEPROCESS Process, PVOID Address, BOOLEAN Create)
ULONG_PTR NTAPI MiFlushTlbIpiRoutine(ULONG_PTR Address)
#define PAE_ADDR_TO_PTE_OFFSET(v)
VOID NTAPI MmDeletePageFileMapping(PEPROCESS Process, PVOID Address, SWAPENTRY *SwapEntry)
ULONG NTAPI MmGetPageProtect(PEPROCESS Process, PVOID Address)
static ULONGLONG MmGetPageEntryForProcessForPAE(PEPROCESS Process, PVOID Address)
static ULONG MmGlobalKernelPageDirectory[1024]
VOID MiFlushTlb(PULONG Pt, PVOID Address)
#define ADDR_TO_PTE_OFFSET(v)
#define PAE_ADDR_TO_PDE_OFFSET(v)
#define PAGEDIRECTORY_MAP
NTSTATUS NTAPI MmCreateVirtualMapping(PEPROCESS Process, PVOID Address, ULONG flProtect, PPFN_NUMBER Pages, ULONG PageCount)
BOOLEAN NTAPI MmIsDirtyPage(PEPROCESS Process, PVOID Address)
NTSTATUS NTAPI MmCreatePageFileMapping(PEPROCESS Process, PVOID Address, SWAPENTRY SwapEntry)
BOOLEAN NTAPI MmCreateProcessAddressSpace(IN ULONG MinWs, IN PEPROCESS Process, IN PLARGE_INTEGER DirectoryTableBase)
BOOLEAN NTAPI MmIsPagePresent(PEPROCESS Process, PVOID Address)
BOOLEAN Mmi386MakeKernelPageTableGlobal(PVOID PAddress)
BOOLEAN NTAPI MmIsPageSwapEntry(PEPROCESS Process, PVOID Address)
#define PAE_ADDR_TO_PDTE_OFFSET(v)
#define PAE_ADDR_TO_PAGE_TABLE(v)
PFN_NUMBER NTAPI MmGetPfnForProcess(PEPROCESS Process, PVOID Address)
VOID NTAPI MmInitGlobalKernelPageDirectory(VOID)
#define PAE_PAGEDIRECTORY_MAP
#define PAE_ADDR_TO_PTE(v)
#define PAE_PTE_TO_PFN(X)
NTSTATUS NTAPI MmCreateVirtualMappingUnsafe(PEPROCESS Process, PVOID Address, ULONG flProtect, PPFN_NUMBER Pages, ULONG PageCount)
VOID NTAPI KeDetachProcess(VOID)
VOID NTAPI KeAttachProcess(IN PKPROCESS Process)
base of all file and directory entries
static PMEM_HOOK PageTable[TOTAL_PAGES]
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes
#define PsGetCurrentProcess
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T _Inout_opt_ PLARGE_INTEGER _Inout_ PSIZE_T _In_ SECTION_INHERIT _In_ ULONG _In_ ULONG Protect