ReactOS  0.4.15-dev-1638-gc0caa5c
page.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
#include <mm/ARM3/miarm.h>
Include dependency graph for page.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define InterlockedExchangePte(pte1, pte2)   InterlockedExchange64((LONG64*)&pte1->u.Long, pte2.u.Long)
 
#define PAGE_EXECUTE_ANY   (PAGE_EXECUTE|PAGE_EXECUTE_READ|PAGE_EXECUTE_READWRITE|PAGE_EXECUTE_WRITECOPY)
 
#define PAGE_WRITE_ANY   (PAGE_EXECUTE_READWRITE|PAGE_READWRITE|PAGE_EXECUTE_WRITECOPY|PAGE_WRITECOPY)
 
#define PAGE_WRITECOPY_ANY   (PAGE_EXECUTE_WRITECOPY|PAGE_WRITECOPY)
 

Functions

BOOLEAN FORCEINLINE MiIsHyperspaceAddress (PVOID Address)
 
VOID MiFlushTlb (PMMPTE Pte, PVOID Address, KIRQL OldIrql)
 
static PMMPTE MiGetPteForProcess (PEPROCESS Process, PVOID Address, BOOLEAN Create, PKIRQL OldIrql)
 
static ULONG64 MiGetPteValueForProcess (PEPROCESS Process, PVOID Address)
 
ULONG NTAPI MiGetPteProtection (MMPTE Pte)
 
static VOID MiSetPteProtection (PMMPTE Pte, ULONG Protection)
 
PFN_NUMBER NTAPI MmGetPfnForProcess (PEPROCESS Process, PVOID Address)
 
BOOLEAN NTAPI MmIsPagePresent (PEPROCESS Process, PVOID Address)
 
BOOLEAN NTAPI MmIsDisabledPage (PEPROCESS Process, PVOID Address)
 
BOOLEAN NTAPI MmIsPageSwapEntry (PEPROCESS Process, PVOID Address)
 
VOID NTAPI MmGetPageFileMapping (PEPROCESS Process, PVOID Address, SWAPENTRY *SwapEntry)
 
BOOLEAN NTAPI MmIsDirtyPage (PEPROCESS Process, PVOID Address)
 
ULONG NTAPI MmGetPageProtect (PEPROCESS Process, PVOID Address)
 
VOID NTAPI MmSetPageProtect (PEPROCESS Process, PVOID Address, ULONG flProtect)
 
VOID NTAPI MmSetCleanPage (PEPROCESS Process, PVOID Address)
 
VOID NTAPI MmSetDirtyPage (PEPROCESS Process, PVOID Address)
 
VOID NTAPI MmDeleteVirtualMapping (PEPROCESS Process, PVOID Address, BOOLEAN *WasDirty, PPFN_NUMBER Page)
 
VOID NTAPI MmDeletePageFileMapping (PEPROCESS Process, PVOID Address, SWAPENTRY *SwapEntry)
 
NTSTATUS NTAPI MmCreatePageFileMapping (PEPROCESS Process, PVOID Address, SWAPENTRY SwapEntry)
 
NTSTATUS NTAPI MmCreateVirtualMappingUnsafe (PEPROCESS Process, PVOID Address, ULONG PageProtection, PPFN_NUMBER Pages, ULONG PageCount)
 
NTSTATUS NTAPI MmCreateVirtualMapping (PEPROCESS Process, PVOID Address, ULONG Protect, PPFN_NUMBER Pages, ULONG PageCount)
 
BOOLEAN NTAPI MmCreateProcessAddressSpace (IN ULONG MinWs, IN PEPROCESS Process, OUT PULONG_PTR DirectoryTableBase)
 

Variables

MMPTE HyperTemplatePte
 
const ULONG64 MmProtectToPteMask [32]
 
const ULONG MmProtectToValue [32]
 

Macro Definition Documentation

◆ InterlockedExchangePte

#define InterlockedExchangePte (   pte1,
  pte2 
)    InterlockedExchange64((LONG64*)&pte1->u.Long, pte2.u.Long)

Definition at line 19 of file page.c.

◆ NDEBUG

#define NDEBUG

Definition at line 14 of file page.c.

◆ PAGE_EXECUTE_ANY

Definition at line 22 of file page.c.

◆ PAGE_WRITE_ANY

Definition at line 23 of file page.c.

◆ PAGE_WRITECOPY_ANY

#define PAGE_WRITECOPY_ANY   (PAGE_EXECUTE_WRITECOPY|PAGE_WRITECOPY)

Definition at line 24 of file page.c.

Function Documentation

◆ MiFlushTlb()

VOID MiFlushTlb ( PMMPTE  Pte,
PVOID  Address,
KIRQL  OldIrql 
)

Definition at line 128 of file page.c.

129 {
130  if (MiIsHyperspaceAddress(Pte))
131  {
133  }
134  else
135  {
136  __invlpg(Address);
137  }
138 }
#define PAGE_ROUND_DOWN(x)
Definition: mmtypes.h:36
#define PsGetCurrentProcess
Definition: psfuncs.h:17
static WCHAR Address[46]
Definition: ping.c:68
VOID NTAPI MiUnmapPageInHyperSpace(IN PEPROCESS Process, IN PVOID Address, IN KIRQL OldIrql)
Definition: hypermap.c:91
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
BOOLEAN FORCEINLINE MiIsHyperspaceAddress(PVOID Address)
Definition: page.c:121
__INTRIN_INLINE void __invlpg(void *Address)
Definition: intrin_x86.h:1897

Referenced by MmDeleteVirtualMapping(), MmSetCleanPage(), MmSetDirtyPage(), and MmSetPageProtect().

◆ MiGetPteForProcess()

static PMMPTE MiGetPteForProcess ( PEPROCESS  Process,
PVOID  Address,
BOOLEAN  Create,
PKIRQL  OldIrql 
)
static

Definition at line 142 of file page.c.

148 {
149  PMMPTE Pte;
150  PMMPDE Pde;
151  PMMPPE Ppe;
152  PMMPXE Pxe;
153 
154  *OldIrql = 0;
155  /* Make sure the process is correct */
157  {
158  /* FIXME: Implement this case */
160  }
161  else
162  {
164  }
165 
166  Pxe = MiAddressToPxe(Address);
167  Ppe = MiAddressToPpe(Address);
168  Pde = MiAddressToPde(Address);
169  Pte = MiAddressToPte(Address);
170 
171  if (Create)
172  {
173  /* Check the PXE */
174  if (Pxe->u.Long == 0)
175  {
176  /* Make it demand zero */
178  }
179 
180  /* Check the PPE */
181  if (Ppe->u.Long == 0)
182  {
183  /* Make it demand zero */
185  }
186 
187  /* Check the PDE */
188  if (Pde->u.Long == 0)
189  {
190  /* Make it demand zero */
192  }
193  }
194  else
195  {
196  /* Check the PXE */
197  if (!Pxe->u.Hard.Valid)
198  return NULL;
199 
200  /* Check the PPE */
201  if (!Ppe->u.Hard.Valid)
202  return NULL;
203 
204  /* Check the PDE */
205  if (!Pde->u.Hard.Valid)
206  return NULL;
207  }
208 
209  return Pte;
210 }
#define MiAddressToPde(x)
Definition: mmx86.c:20
_In_ BOOLEAN Create
Definition: pstypes.h:519
FORCEINLINE PMMPTE MiAddressToPpe(PVOID Address)
Definition: mm.h:154
#define MiAddressToPte(x)
Definition: mmx86.c:19
FORCEINLINE VOID MI_WRITE_INVALID_PDE(IN PMMPDE PointerPde, IN MMPDE InvalidPde)
Definition: miarm.h:1018
#define PsGetCurrentProcess
Definition: psfuncs.h:17
static WCHAR Address[46]
Definition: ping.c:68
FORCEINLINE PMMPTE MiAddressToPxe(PVOID Address)
Definition: mm.h:164
#define ASSERT(a)
Definition: mode.c:45
ULONG64 Valid
Definition: mmtypes.h:150
MMPDE DemandZeroPde
Definition: page.c:114
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
union _MMPTE::@2319 u
ULONG_PTR Long
Definition: mmtypes.h:215
MMPTE_HARDWARE Hard
Definition: mmtypes.h:217
#define NULL
Definition: types.h:112
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
#define MmSystemRangeStart
Definition: mm.h:32

Referenced by MiGetPteValueForProcess(), MmCreatePageFileMapping(), MmCreateVirtualMappingUnsafe(), MmDeletePageFileMapping(), MmDeleteVirtualMapping(), MmSetCleanPage(), MmSetDirtyPage(), and MmSetPageProtect().

◆ MiGetPteProtection()

ULONG NTAPI MiGetPteProtection ( MMPTE  Pte)

Definition at line 233 of file page.c.

234 {
235  ULONG Protect;
236 
237  if (!Pte.u.Flush.Valid)
238  {
240  }
241  else if (Pte.u.Flush.NoExecute)
242  {
243  if (Pte.u.Flush.CopyOnWrite)
245  else if (Pte.u.Flush.Write)
247  else
249  }
250  else
251  {
252  if (Pte.u.Flush.CopyOnWrite)
254  else if (Pte.u.Flush.Write)
256  else
258  }
259 
260  if (Pte.u.Flush.CacheDisable)
262 
263  if (Pte.u.Flush.WriteThrough)
265 
266  // PAGE_GUARD ?
267  return Protect;
268 }
#define PAGE_WRITETHROUGH
Definition: mm.h:85
ULONG64 Valid
Definition: mmtypes.h:66
#define PAGE_NOCACHE
Definition: nt_native.h:1311
_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
Definition: zwfuncs.h:214
ULONG64 CacheDisable
Definition: mmtypes.h:70
HARDWARE_PTE Flush
Definition: mmtypes.h:216
ULONG64 CopyOnWrite
Definition: mmtypes.h:75
#define PAGE_EXECUTE_WRITECOPY
Definition: nt_native.h:1309
#define PAGE_NOACCESS
Definition: nt_native.h:1302
ULONG64 WriteThrough
Definition: mmtypes.h:69
union _MMPTE::@2319 u
#define PAGE_READONLY
Definition: compat.h:138
#define PAGE_WRITECOPY
Definition: nt_native.h:1305
ULONG64 Write
Definition: mmtypes.h:67
unsigned int ULONG
Definition: retypes.h:1
#define PAGE_EXECUTE_READ
Definition: nt_native.h:1307
#define PAGE_EXECUTE_READWRITE
Definition: nt_native.h:1308
ULONG64 NoExecute
Definition: mmtypes.h:81
#define PAGE_READWRITE
Definition: nt_native.h:1304

Referenced by MmGetPageProtect().

◆ MiGetPteValueForProcess()

static ULONG64 MiGetPteValueForProcess ( PEPROCESS  Process,
PVOID  Address 
)
static

Definition at line 214 of file page.c.

217 {
218  PMMPTE Pte;
219  ULONG64 PteValue;
220  KIRQL OldIrql;
221 
223  PteValue = Pte ? Pte->u.Long : 0;
224 
225  if (MiIsHyperspaceAddress(Pte))
227 
228  return PteValue;
229 }
#define PAGE_ROUND_DOWN(x)
Definition: mmtypes.h:36
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define FALSE
Definition: types.h:117
#define PsGetCurrentProcess
Definition: psfuncs.h:17
static WCHAR Address[46]
Definition: ping.c:68
static PMMPTE MiGetPteForProcess(PEPROCESS Process, PVOID Address, BOOLEAN Create, PKIRQL OldIrql)
Definition: page.c:142
unsigned __int64 ULONG64
Definition: imports.h:198
VOID NTAPI MiUnmapPageInHyperSpace(IN PEPROCESS Process, IN PVOID Address, IN KIRQL OldIrql)
Definition: hypermap.c:91
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
union _MMPTE::@2319 u
BOOLEAN FORCEINLINE MiIsHyperspaceAddress(PVOID Address)
Definition: page.c:121
ULONG_PTR Long
Definition: mmtypes.h:215
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219

Referenced by MmGetPageProtect(), MmGetPfnForProcess(), MmIsDirtyPage(), MmIsDisabledPage(), MmIsPagePresent(), and MmIsPageSwapEntry().

◆ MiIsHyperspaceAddress()

BOOLEAN FORCEINLINE MiIsHyperspaceAddress ( PVOID  Address)

Definition at line 121 of file page.c.

122 {
123  return ((ULONG64)Address >= HYPER_SPACE &&
125 }
static WCHAR Address[46]
Definition: ping.c:68
#define HYPER_SPACE_END
Definition: mm.h:15
unsigned __int64 ULONG64
Definition: imports.h:198
#define HYPER_SPACE
Definition: mm.h:14

Referenced by MiFlushTlb(), MiGetPteValueForProcess(), MmCreatePageFileMapping(), MmCreateVirtualMappingUnsafe(), MmDeletePageFileMapping(), MmSetCleanPage(), and MmSetDirtyPage().

◆ MiSetPteProtection()

static VOID MiSetPteProtection ( PMMPTE  Pte,
ULONG  Protection 
)
static

Definition at line 272 of file page.c.

273 {
274  Pte->u.Flush.CopyOnWrite = (Protection & PAGE_WRITECOPY_ANY) ? 1 : 0;
275  Pte->u.Flush.Write = (Protection & PAGE_WRITE_ANY) ? 1 : 0;
276  Pte->u.Flush.CacheDisable = (Protection & PAGE_NOCACHE) ? 1 : 0;
277  Pte->u.Flush.WriteThrough = (Protection & PAGE_WRITETHROUGH) ? 1 : 0;
278 
279  // FIXME: This doesn't work. Why?
280  Pte->u.Flush.NoExecute = (Protection & PAGE_EXECUTE_ANY) ? 0 : 1;
281 }
#define PAGE_WRITETHROUGH
Definition: mm.h:85
#define PAGE_NOCACHE
Definition: nt_native.h:1311
#define PAGE_WRITECOPY_ANY
Definition: page.c:24
ULONG64 CacheDisable
Definition: mmtypes.h:70
HARDWARE_PTE Flush
Definition: mmtypes.h:216
ULONG64 CopyOnWrite
Definition: mmtypes.h:75
#define PAGE_EXECUTE_ANY
Definition: page.c:22
ULONG64 WriteThrough
Definition: mmtypes.h:69
union _MMPTE::@2319 u
#define PAGE_WRITE_ANY
Definition: page.c:23
ULONG64 Write
Definition: mmtypes.h:67
ULONG64 NoExecute
Definition: mmtypes.h:81

Referenced by MmCreateVirtualMappingUnsafe(), and MmSetPageProtect().

◆ MmCreatePageFileMapping()

NTSTATUS NTAPI MmCreatePageFileMapping ( PEPROCESS  Process,
PVOID  Address,
SWAPENTRY  SwapEntry 
)

Definition at line 499 of file page.c.

502 {
503  PMMPTE Pte;
504  MMPTE PteValue;
505  KIRQL OldIrql;
506 
508  {
509  DPRINT1("No process\n");
510  KeBugCheck(MEMORY_MANAGEMENT);
511  }
512  if (Process != NULL && Address >= MmSystemRangeStart)
513  {
514  DPRINT1("Setting kernel address with process context\n");
515  KeBugCheck(MEMORY_MANAGEMENT);
516  }
517 
518  if (SwapEntry & (1ull << 63))
519  {
520  KeBugCheck(MEMORY_MANAGEMENT);
521  }
522 
523  /* Allocate a PTE */
525  if (Pte == NULL)
526  {
527  return STATUS_UNSUCCESSFUL;
528  }
529 
530  NT_ASSERT(Pte->u.Long == 0);
531  PteValue.u.Long = SwapEntry << 1;
532  MI_WRITE_INVALID_PTE(Pte, PteValue);
533 
534  if (MiIsHyperspaceAddress(Pte))
536 
537  return STATUS_UNSUCCESSFUL;
538 }
#define TRUE
Definition: types.h:120
#define PAGE_ROUND_DOWN(x)
Definition: mmtypes.h:36
UCHAR KIRQL
Definition: env_spec_w32.h:591
DECLSPEC_NORETURN VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1427
#define PsGetCurrentProcess
Definition: psfuncs.h:17
static WCHAR Address[46]
Definition: ping.c:68
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
static PMMPTE MiGetPteForProcess(PEPROCESS Process, PVOID Address, BOOLEAN Create, PKIRQL OldIrql)
Definition: page.c:142
VOID NTAPI MiUnmapPageInHyperSpace(IN PEPROCESS Process, IN PVOID Address, IN KIRQL OldIrql)
Definition: hypermap.c:91
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
union _MMPTE::@2319 u
BOOLEAN FORCEINLINE MiIsHyperspaceAddress(PVOID Address)
Definition: page.c:121
ULONG_PTR Long
Definition: mmtypes.h:215
FORCEINLINE VOID MI_WRITE_INVALID_PTE(IN PMMPTE PointerPte, IN MMPTE InvalidPte)
Definition: miarm.h:975
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
#define MmSystemRangeStart
Definition: mm.h:32
#define NT_ASSERT
Definition: rtlfuncs.h:3312

◆ MmCreateProcessAddressSpace()

BOOLEAN NTAPI MmCreateProcessAddressSpace ( IN ULONG  MinWs,
IN PEPROCESS  Process,
OUT PULONG_PTR  DirectoryTableBase 
)

architecture specific

end architecture specific

Definition at line 623 of file page.c.

626 {
627  KIRQL OldIrql;
628  PFN_NUMBER TableBasePfn, HyperPfn, HyperPdPfn, HyperPtPfn, WorkingSetPfn;
629  PMMPTE SystemPte;
630  MMPTE TempPte, PdePte;
631  ULONG TableIndex;
632  PMMPTE PageTablePointer;
633 
634  /* Make sure we don't already have a page directory setup */
635  ASSERT(Process->Pcb.DirectoryTableBase[0] == 0);
636  ASSERT(Process->Pcb.DirectoryTableBase[1] == 0);
637  ASSERT(Process->WorkingSetPage == 0);
638 
639  /* Choose a process color */
640  Process->NextPageColor = (USHORT)RtlRandom(&MmProcessColorSeed);
641 
642  /* Setup the hyperspace lock */
643  KeInitializeSpinLock(&Process->HyperSpaceLock);
644 
645  /* Lock PFN database */
647 
648  /* Get a page for the table base and one for hyper space. The PFNs for
649  these pages will be initialized in MmInitializeProcessAddressSpace,
650  when we are already attached to the process. */
656 
657  /* Release PFN lock */
659 
660  /* Zero pages */
661  MiZeroPhysicalPage(TableBasePfn);
662  MiZeroPhysicalPage(HyperPfn);
663  MiZeroPhysicalPage(HyperPdPfn);
664  MiZeroPhysicalPage(HyperPtPfn);
665  MiZeroPhysicalPage(WorkingSetPfn);
666 
667  /* Set the base directory pointers */
668  Process->WorkingSetPage = WorkingSetPfn;
669  DirectoryTableBase[0] = TableBasePfn << PAGE_SHIFT;
670  DirectoryTableBase[1] = HyperPfn << PAGE_SHIFT;
671 
672  /* Get a PTE to map the page directory */
673  SystemPte = MiReserveSystemPtes(1, SystemPteSpace);
674  ASSERT(SystemPte != NULL);
675 
676  /* Get its address */
677  PageTablePointer = MiPteToAddress(SystemPte);
678 
679  /* Build the PTE for the page directory and map it */
680  PdePte = ValidKernelPte;
681  PdePte.u.Hard.PageFrameNumber = TableBasePfn;
682  *SystemPte = PdePte;
683 
685  //MiInitializePageDirectoryForProcess(
686 
687  /* Copy the kernel mappings and zero out the rest */
688  TableIndex = PXE_PER_PAGE / 2;
689  RtlZeroMemory(PageTablePointer, TableIndex * sizeof(MMPTE));
690  RtlCopyMemory(PageTablePointer + TableIndex,
691  MiAddressToPxe(0) + TableIndex,
692  PAGE_SIZE - TableIndex * sizeof(MMPTE));
693 
694  /* Sanity check */
695  ASSERT(MiAddressToPxi(MmHyperSpaceEnd) >= TableIndex);
696 
697  /* Setup a PTE for the page directory mappings */
699 
700  /* Update the self mapping of the PML4 */
701  TableIndex = MiAddressToPxi((PVOID)PXE_SELFMAP);
702  TempPte.u.Hard.PageFrameNumber = TableBasePfn;
703  PageTablePointer[TableIndex] = TempPte;
704 
705  /* Write the PML4 entry for hyperspace */
706  TableIndex = MiAddressToPxi((PVOID)HYPER_SPACE);
707  TempPte.u.Hard.PageFrameNumber = HyperPfn;
708  PageTablePointer[TableIndex] = TempPte;
709 
710  /* Map the hyperspace PDPT to the system PTE */
711  PdePte.u.Hard.PageFrameNumber = HyperPfn;
712  *SystemPte = PdePte;
713  __invlpg(PageTablePointer);
714 
715  /* Write the hyperspace entry for the first PD */
716  TempPte.u.Hard.PageFrameNumber = HyperPdPfn;
717  PageTablePointer[0] = TempPte;
718 
719  /* Map the hyperspace PD to the system PTE */
720  PdePte.u.Hard.PageFrameNumber = HyperPdPfn;
721  *SystemPte = PdePte;
722  __invlpg(PageTablePointer);
723 
724  /* Write the hyperspace entry for the first PT */
725  TempPte.u.Hard.PageFrameNumber = HyperPtPfn;
726  PageTablePointer[0] = TempPte;
727 
728  /* Map the hyperspace PT to the system PTE */
729  PdePte.u.Hard.PageFrameNumber = HyperPtPfn;
730  *SystemPte = PdePte;
731  __invlpg(PageTablePointer);
732 
733  /* Write the hyperspace PTE for the working set list index */
734  TempPte.u.Hard.PageFrameNumber = WorkingSetPfn;
735  TableIndex = MiAddressToPti(MmWorkingSetList);
736  PageTablePointer[TableIndex] = TempPte;
737 
739 
740  /* Release the system PTE */
741  MiReleaseSystemPtes(SystemPte, 1, SystemPteSpace);
742 
743  /* Switch to phase 1 initialization */
744  ASSERT(Process->AddressSpaceInitialized == 0);
745  Process->AddressSpaceInitialized = 1;
746 
747  /* Add the process to the session */
749  return TRUE;
750 }
NTSYSAPI ULONG NTAPI RtlRandom(_Inout_ PULONG Seed)
ULONG MmProcessColorSeed
Definition: procsup.c:20
#define PAGE_SHIFT
Definition: env_spec_w32.h:45
#define PXE_PER_PAGE
#define TRUE
Definition: types.h:120
PMMPTE NTAPI MiReserveSystemPtes(IN ULONG NumberOfPtes, IN MMSYSTEM_PTE_POOL_TYPE SystemPtePoolType)
Definition: syspte.c:246
FORCEINLINE KIRQL MiAcquirePfnLock(VOID)
Definition: mm.h:900
VOID NTAPI MiZeroPhysicalPage(IN PFN_NUMBER PageFrameIndex)
Definition: pfnlist.c:122
FORCEINLINE VOID MiReleasePfnLock(_In_ KIRQL OldIrql)
Definition: mm.h:907
UCHAR KIRQL
Definition: env_spec_w32.h:591
ULONG PFN_NUMBER
Definition: ke.h:9
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:238
VOID NTAPI MiReleaseSystemPtes(IN PMMPTE StartingPte, IN ULONG NumberOfPtes, IN MMSYSTEM_PTE_POOL_TYPE SystemPtePoolType)
Definition: syspte.c:275
#define PXE_SELFMAP
FORCEINLINE PMMPTE MiAddressToPxe(PVOID Address)
Definition: mm.h:164
#define ASSERT(a)
Definition: mode.c:45
#define MI_GET_NEXT_PROCESS_COLOR(x)
Definition: miarm.h:239
HARDWARE_PTE_ARMV6 TempPte
Definition: winldr.c:76
MMPTE ValidKernelPte
Definition: page.c:111
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
FORCEINLINE ULONG MiAddressToPxi(PVOID Address)
Definition: mm.h:193
#define PAGE_SIZE
Definition: env_spec_w32.h:49
PMMWSL MmWorkingSetList
Definition: procsup.c:21
union _MMPTE::@2319 u
PFN_NUMBER NTAPI MiRemoveAnyPage(IN ULONG Color)
Definition: pfnlist.c:475
MMPTE_HARDWARE Hard
Definition: mmtypes.h:217
unsigned short USHORT
Definition: pedump.c:61
#define NULL
Definition: types.h:112
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
__INTRIN_INLINE void __invlpg(void *Address)
Definition: intrin_x86.h:1897
VOID NTAPI MiSessionAddProcess(IN PEPROCESS NewProcess)
Definition: session.c:427
#define HYPER_SPACE
Definition: mm.h:14
PVOID MmHyperSpaceEnd
Definition: init.c:56
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
ULONG64 PageFrameNumber
Definition: mmtypes.h:171
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
FORCEINLINE PVOID MiPteToAddress(PMMPTE PointerPte)
Definition: mm.h:201
FORCEINLINE ULONG MiAddressToPti(PVOID Address)
Definition: mm.h:174
ULONG PageFrameNumber
Definition: mmtypes.h:109

◆ MmCreateVirtualMapping()

NTSTATUS NTAPI MmCreateVirtualMapping ( PEPROCESS  Process,
PVOID  Address,
ULONG  Protect,
PPFN_NUMBER  Pages,
ULONG  PageCount 
)

Definition at line 599 of file page.c.

604 {
605  ULONG i;
606 
608 
609  for (i = 0; i < PageCount; i++)
610  {
611  if (!MmIsPageInUse(Pages[i]))
612  {
613  DPRINT1("Page %x not in use\n", Pages[i]);
614  KeBugCheck(MEMORY_MANAGEMENT);
615  }
616  }
617 
618  return MmCreateVirtualMappingUnsafe(Process, Address, Protect, Pages, PageCount);
619 }
_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
Definition: zwfuncs.h:214
BOOLEAN NTAPI MmIsPageInUse(PFN_NUMBER Page)
Definition: freelist.c:530
uint32_t ULONG_PTR
Definition: typedefs.h:65
DECLSPEC_NORETURN VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1427
static WCHAR Address[46]
Definition: ping.c:68
NTSTATUS NTAPI MmCreateVirtualMappingUnsafe(PEPROCESS Process, PVOID Address, ULONG PageProtection, PPFN_NUMBER Pages, ULONG PageCount)
Definition: page.c:543
#define ASSERT(a)
Definition: mode.c:45
#define PAGE_SIZE
Definition: env_spec_w32.h:49
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
Definition: glfuncs.h:248
#define DPRINT1
Definition: precomp.h:8
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
unsigned int ULONG
Definition: retypes.h:1

◆ MmCreateVirtualMappingUnsafe()

NTSTATUS NTAPI MmCreateVirtualMappingUnsafe ( PEPROCESS  Process,
PVOID  Address,
ULONG  PageProtection,
PPFN_NUMBER  Pages,
ULONG  PageCount 
)

Definition at line 543 of file page.c.

549 {
550  ULONG i;
551  MMPTE TmplPte, *Pte;
552 
554 
555  /* Check if the range is valid */
556  if ((Process == NULL && Address < MmSystemRangeStart) ||
558  {
559  DPRINT1("Address 0x%p is invalid for process %p\n", Address, Process);
560  ASSERT(FALSE);
561  }
562 
563  TmplPte.u.Long = 0;
564  TmplPte.u.Hard.Valid = 1;
565  MiSetPteProtection(&TmplPte, PageProtection);
566 
567  TmplPte.u.Flush.Owner = (Address < MmHighestUserAddress) ? 1 : 0;
568 
569 //__debugbreak();
570 
571  for (i = 0; i < PageCount; i++)
572  {
573  KIRQL OldIrql;
574 
575  TmplPte.u.Hard.PageFrameNumber = Pages[i];
576 
578 
579 DPRINT("MmCreateVirtualMappingUnsafe, Address=%p, TmplPte=%p, Pte=%p\n",
580  Address, TmplPte.u.Long, Pte);
581 
582  if (InterlockedExchangePte(Pte, TmplPte))
583  {
585  }
586 
587  if (MiIsHyperspaceAddress(Pte))
589 
591  }
592 
593 
594  return STATUS_SUCCESS;
595 }
#define TRUE
Definition: types.h:120
ULONG64 Owner
Definition: mmtypes.h:68
static VOID MiSetPteProtection(PMMPTE Pte, ULONG Protection)
Definition: page.c:272
#define PAGE_ROUND_DOWN(x)
Definition: mmtypes.h:36
#define InterlockedExchangePte(pte1, pte2)
Definition: page.c:19
HARDWARE_PTE Flush
Definition: mmtypes.h:216
uint32_t ULONG_PTR
Definition: typedefs.h:65
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define FALSE
Definition: types.h:117
#define PsGetCurrentProcess
Definition: psfuncs.h:17
static WCHAR Address[46]
Definition: ping.c:68
void DPRINT(...)
Definition: polytest.cpp:61
void * PVOID
Definition: retypes.h:9
FORCEINLINE VOID KeInvalidateTlbEntry(IN PVOID Address)
Definition: ke.h:201
#define ASSERT(a)
Definition: mode.c:45
ULONG64 Valid
Definition: mmtypes.h:150
static PMMPTE MiGetPteForProcess(PEPROCESS Process, PVOID Address, BOOLEAN Create, PKIRQL OldIrql)
Definition: page.c:142
unsigned __int64 ULONG64
Definition: imports.h:198
VOID NTAPI MiUnmapPageInHyperSpace(IN PEPROCESS Process, IN PVOID Address, IN KIRQL OldIrql)
Definition: hypermap.c:91
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
#define PAGE_SIZE
Definition: env_spec_w32.h:49
union _MMPTE::@2319 u
BOOLEAN FORCEINLINE MiIsHyperspaceAddress(PVOID Address)
Definition: page.c:121
ULONG_PTR Long
Definition: mmtypes.h:215
MMPTE_HARDWARE Hard
Definition: mmtypes.h:217
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
Definition: glfuncs.h:248
#define NULL
Definition: types.h:112
PVOID MmHighestUserAddress
Definition: rtlcompat.c:29
#define DPRINT1
Definition: precomp.h:8
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
unsigned int ULONG
Definition: retypes.h:1
ULONG64 PageFrameNumber
Definition: mmtypes.h:171
#define STATUS_SUCCESS
Definition: shellext.h:65
#define MmSystemRangeStart
Definition: mm.h:32

Referenced by MmCreateVirtualMapping().

◆ MmDeletePageFileMapping()

VOID NTAPI MmDeletePageFileMapping ( PEPROCESS  Process,
PVOID  Address,
SWAPENTRY SwapEntry 
)

Definition at line 471 of file page.c.

473 {
474  PMMPTE Pte;
475  KIRQL OldIrql;
476 
478  if (Pte == NULL)
479  {
480  *SwapEntry = 0;
481  return;
482  }
483 
484  if (Pte->u.Trans.Valid || !Pte->u.Trans.Transition)
485  {
486  DPRINT1("Pte %x (want not 1 and 0x800)\n", Pte);
487  KeBugCheck(MEMORY_MANAGEMENT);
488  }
489 
490  *SwapEntry = Pte->u.Long >> 1;
491  MI_ERASE_PTE(Pte);
492 
493  if (MiIsHyperspaceAddress(Pte))
495 }
FORCEINLINE VOID MI_ERASE_PTE(IN PMMPTE PointerPte)
Definition: miarm.h:989
#define PAGE_ROUND_DOWN(x)
Definition: mmtypes.h:36
ULONG64 Transition
Definition: mmtypes.h:105
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define FALSE
Definition: types.h:117
DECLSPEC_NORETURN VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1427
#define PsGetCurrentProcess
Definition: psfuncs.h:17
static WCHAR Address[46]
Definition: ping.c:68
MMPTE_TRANSITION Trans
Definition: mmtypes.h:220
static PMMPTE MiGetPteForProcess(PEPROCESS Process, PVOID Address, BOOLEAN Create, PKIRQL OldIrql)
Definition: page.c:142
VOID NTAPI MiUnmapPageInHyperSpace(IN PEPROCESS Process, IN PVOID Address, IN KIRQL OldIrql)
Definition: hypermap.c:91
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
union _MMPTE::@2319 u
BOOLEAN FORCEINLINE MiIsHyperspaceAddress(PVOID Address)
Definition: page.c:121
ULONG_PTR Long
Definition: mmtypes.h:215
ULONG64 Valid
Definition: mmtypes.h:98
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219

◆ MmDeleteVirtualMapping()

VOID NTAPI MmDeleteVirtualMapping ( PEPROCESS  Process,
PVOID  Address,
BOOLEAN WasDirty,
PPFN_NUMBER  Page 
)

Definition at line 428 of file page.c.

433 {
434  PFN_NUMBER Pfn;
435  PMMPTE Pte;
436  MMPTE OldPte;
437  KIRQL OldIrql;
438 
440 
441  if (Pte)
442  {
443  /* Atomically set the entry to zero and get the old value. */
444  OldPte.u.Long = InterlockedExchange64((LONG64*)&Pte->u.Long, 0);
445 
446  if (OldPte.u.Hard.Valid)
447  {
448  Pfn = OldPte.u.Hard.PageFrameNumber;
449  }
450  else
451  Pfn = 0;
452  }
453  else
454  {
455  OldPte.u.Long = 0;
456  Pfn = 0;
457  }
458 
459  /* Return information to the caller */
460  if (WasDirty)
461  *WasDirty = (BOOLEAN)OldPte.u.Hard.Dirty;
462 
463  if (Page)
464  *Page = Pfn;
465 
466  MiFlushTlb(Pte, Address, OldIrql);
467 }
#define InterlockedExchange64
Definition: interlocked.h:171
ULONG64 Dirty
Definition: mmtypes.h:164
UCHAR KIRQL
Definition: env_spec_w32.h:591
ULONG PFN_NUMBER
Definition: ke.h:9
#define FALSE
Definition: types.h:117
static WCHAR Address[46]
Definition: ping.c:68
int64_t LONG64
Definition: typedefs.h:68
if(!(yy_init))
Definition: macro.lex.yy.c:714
ULONG64 Valid
Definition: mmtypes.h:150
static PMMPTE MiGetPteForProcess(PEPROCESS Process, PVOID Address, BOOLEAN Create, PKIRQL OldIrql)
Definition: page.c:142
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
VOID MiFlushTlb(PMMPTE Pte, PVOID Address, KIRQL OldIrql)
Definition: page.c:128
union _MMPTE::@2319 u
ULONG_PTR Long
Definition: mmtypes.h:215
MMPTE_HARDWARE Hard
Definition: mmtypes.h:217
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
#define BOOLEAN
Definition: pedump.c:73
ULONG64 PageFrameNumber
Definition: mmtypes.h:171

◆ MmGetPageFileMapping()

VOID NTAPI MmGetPageFileMapping ( PEPROCESS  Process,
PVOID  Address,
SWAPENTRY SwapEntry 
)

Definition at line 327 of file page.c.

331 {
332  PMMPTE PointerPte;
333 
335 
336  PointerPte = MiAddressToPte(Address);
337  *SwapEntry = PointerPte->u.Long >> 1;
338 }
#define MiAddressToPte(x)
Definition: mmx86.c:19
#define PsGetCurrentProcess
Definition: psfuncs.h:17
static WCHAR Address[46]
Definition: ping.c:68
#define ASSERT(a)
Definition: mode.c:45
union _MMPTE::@2319 u
ULONG_PTR Long
Definition: mmtypes.h:215
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219

◆ MmGetPageProtect()

ULONG NTAPI MmGetPageProtect ( PEPROCESS  Process,
PVOID  Address 
)

Definition at line 351 of file page.c.

352 {
353  MMPTE Pte;
354 
356 
357  return MiGetPteProtection(Pte);
358 }
static WCHAR Address[46]
Definition: ping.c:68
ULONG NTAPI MiGetPteProtection(MMPTE Pte)
Definition: page.c:233
union _MMPTE::@2319 u
ULONG_PTR Long
Definition: mmtypes.h:215
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
static ULONG64 MiGetPteValueForProcess(PEPROCESS Process, PVOID Address)
Definition: page.c:214

◆ MmGetPfnForProcess()

PFN_NUMBER NTAPI MmGetPfnForProcess ( PEPROCESS  Process,
PVOID  Address 
)

Definition at line 287 of file page.c.

289 {
290  MMPTE Pte;
292  return Pte.u.Hard.Valid ? Pte.u.Hard.PageFrameNumber : 0;
293 }
static WCHAR Address[46]
Definition: ping.c:68
ULONG64 Valid
Definition: mmtypes.h:150
union _MMPTE::@2319 u
ULONG_PTR Long
Definition: mmtypes.h:215
MMPTE_HARDWARE Hard
Definition: mmtypes.h:217
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
ULONG64 PageFrameNumber
Definition: mmtypes.h:171
static ULONG64 MiGetPteValueForProcess(PEPROCESS Process, PVOID Address)
Definition: page.c:214

◆ MmIsDirtyPage()

BOOLEAN NTAPI MmIsDirtyPage ( PEPROCESS  Process,
PVOID  Address 
)

Definition at line 342 of file page.c.

343 {
344  MMPTE Pte;
346  return Pte.u.Hard.Valid && Pte.u.Hard.Dirty;
347 }
ULONG64 Dirty
Definition: mmtypes.h:164
static WCHAR Address[46]
Definition: ping.c:68
ULONG64 Valid
Definition: mmtypes.h:150
union _MMPTE::@2319 u
ULONG_PTR Long
Definition: mmtypes.h:215
MMPTE_HARDWARE Hard
Definition: mmtypes.h:217
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
static ULONG64 MiGetPteValueForProcess(PEPROCESS Process, PVOID Address)
Definition: page.c:214

◆ MmIsDisabledPage()

BOOLEAN NTAPI MmIsDisabledPage ( PEPROCESS  Process,
PVOID  Address 
)

Definition at line 306 of file page.c.

307 {
308  MMPTE Pte;
310 
311  return (Pte.u.Hard.Valid == 0) &&
312  (Pte.u.Trans.Transition == 0) &&
313  (Pte.u.Hard.PageFrameNumber != 0);
314 }
ULONG64 Transition
Definition: mmtypes.h:105
static WCHAR Address[46]
Definition: ping.c:68
MMPTE_TRANSITION Trans
Definition: mmtypes.h:220
ULONG64 Valid
Definition: mmtypes.h:150
union _MMPTE::@2319 u
ULONG_PTR Long
Definition: mmtypes.h:215
MMPTE_HARDWARE Hard
Definition: mmtypes.h:217
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
ULONG64 PageFrameNumber
Definition: mmtypes.h:171
static ULONG64 MiGetPteValueForProcess(PEPROCESS Process, PVOID Address)
Definition: page.c:214

◆ MmIsPagePresent()

BOOLEAN NTAPI MmIsPagePresent ( PEPROCESS  Process,
PVOID  Address 
)

Definition at line 297 of file page.c.

298 {
299  MMPTE Pte;
301  return (BOOLEAN)Pte.u.Hard.Valid;
302 }
unsigned char BOOLEAN
static WCHAR Address[46]
Definition: ping.c:68
ULONG64 Valid
Definition: mmtypes.h:150
union _MMPTE::@2319 u
ULONG_PTR Long
Definition: mmtypes.h:215
MMPTE_HARDWARE Hard
Definition: mmtypes.h:217
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
static ULONG64 MiGetPteValueForProcess(PEPROCESS Process, PVOID Address)
Definition: page.c:214

◆ MmIsPageSwapEntry()

BOOLEAN NTAPI MmIsPageSwapEntry ( PEPROCESS  Process,
PVOID  Address 
)

Definition at line 318 of file page.c.

319 {
320  MMPTE Pte;
322  return !Pte.u.Hard.Valid && Pte.u.Soft.Transition;
323 }
static WCHAR Address[46]
Definition: ping.c:68
ULONG64 Valid
Definition: mmtypes.h:150
union _MMPTE::@2319 u
ULONG_PTR Long
Definition: mmtypes.h:215
MMPTE_HARDWARE Hard
Definition: mmtypes.h:217
ULONG64 Transition
Definition: mmtypes.h:90
MMPTE_SOFTWARE Soft
Definition: mmtypes.h:219
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
static ULONG64 MiGetPteValueForProcess(PEPROCESS Process, PVOID Address)
Definition: page.c:214

◆ MmSetCleanPage()

VOID NTAPI MmSetCleanPage ( PEPROCESS  Process,
PVOID  Address 
)

Definition at line 382 of file page.c.

383 {
384  PMMPTE Pte;
385  KIRQL OldIrql;
386 
388  if (!Pte)
389  {
390  KeBugCheckEx(MEMORY_MANAGEMENT, 0x1234, (ULONG64)Address, 0, 0);
391  }
392 
393  /* Ckear the dirty bit */
394  if (InterlockedBitTestAndReset64((PVOID)Pte, 6))
395  {
396  if (!MiIsHyperspaceAddress(Pte))
397  __invlpg(Address);
398  }
399 
400  MiFlushTlb(Pte, Address, OldIrql);
401 }
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define FALSE
Definition: types.h:117
static WCHAR Address[46]
Definition: ping.c:68
static PMMPTE MiGetPteForProcess(PEPROCESS Process, PVOID Address, BOOLEAN Create, PKIRQL OldIrql)
Definition: page.c:142
unsigned __int64 ULONG64
Definition: imports.h:198
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
VOID MiFlushTlb(PMMPTE Pte, PVOID Address, KIRQL OldIrql)
Definition: page.c:128
BOOLEAN FORCEINLINE MiIsHyperspaceAddress(PVOID Address)
Definition: page.c:121
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
__INTRIN_INLINE void __invlpg(void *Address)
Definition: intrin_x86.h:1897
VOID NTAPI KeBugCheckEx(_In_ ULONG BugCheckCode, _In_ ULONG_PTR BugCheckParameter1, _In_ ULONG_PTR BugCheckParameter2, _In_ ULONG_PTR BugCheckParameter3, _In_ ULONG_PTR BugCheckParameter4)
Definition: rtlcompat.c:108

◆ MmSetDirtyPage()

VOID NTAPI MmSetDirtyPage ( PEPROCESS  Process,
PVOID  Address 
)

Definition at line 405 of file page.c.

406 {
407  PMMPTE Pte;
408  KIRQL OldIrql;
409 
411  if (!Pte)
412  {
413  KeBugCheckEx(MEMORY_MANAGEMENT, 0x1234, (ULONG64)Address, 0, 0);
414  }
415 
416  /* Ckear the dirty bit */
417  if (InterlockedBitTestAndSet64((PVOID)Pte, 6))
418  {
419  if (!MiIsHyperspaceAddress(Pte))
420  __invlpg(Address);
421  }
422 
423  MiFlushTlb(Pte, Address, OldIrql);
424 }
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define FALSE
Definition: types.h:117
static WCHAR Address[46]
Definition: ping.c:68
static PMMPTE MiGetPteForProcess(PEPROCESS Process, PVOID Address, BOOLEAN Create, PKIRQL OldIrql)
Definition: page.c:142
unsigned __int64 ULONG64
Definition: imports.h:198
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
VOID MiFlushTlb(PMMPTE Pte, PVOID Address, KIRQL OldIrql)
Definition: page.c:128
BOOLEAN FORCEINLINE MiIsHyperspaceAddress(PVOID Address)
Definition: page.c:121
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
__INTRIN_INLINE void __invlpg(void *Address)
Definition: intrin_x86.h:1897
VOID NTAPI KeBugCheckEx(_In_ ULONG BugCheckCode, _In_ ULONG_PTR BugCheckParameter1, _In_ ULONG_PTR BugCheckParameter2, _In_ ULONG_PTR BugCheckParameter3, _In_ ULONG_PTR BugCheckParameter4)
Definition: rtlcompat.c:108

◆ MmSetPageProtect()

VOID NTAPI MmSetPageProtect ( PEPROCESS  Process,
PVOID  Address,
ULONG  flProtect 
)

Definition at line 362 of file page.c.

363 {
364  PMMPTE Pte;
365  MMPTE NewPte;
366  KIRQL OldIrql;
367 
369  ASSERT(Pte != NULL);
370 
371  NewPte = *Pte;
372 
373  MiSetPteProtection(&NewPte, flProtect);
374 
375  InterlockedExchangePte(Pte, NewPte);
376 
377  MiFlushTlb(Pte, Address, OldIrql);
378 }
static VOID MiSetPteProtection(PMMPTE Pte, ULONG Protection)
Definition: page.c:272
#define InterlockedExchangePte(pte1, pte2)
Definition: page.c:19
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define FALSE
Definition: types.h:117
static WCHAR Address[46]
Definition: ping.c:68
#define ASSERT(a)
Definition: mode.c:45
static PMMPTE MiGetPteForProcess(PEPROCESS Process, PVOID Address, BOOLEAN Create, PKIRQL OldIrql)
Definition: page.c:142
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
VOID MiFlushTlb(PMMPTE Pte, PVOID Address, KIRQL OldIrql)
Definition: page.c:128
#define NULL
Definition: types.h:112
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219

Variable Documentation

◆ HyperTemplatePte

MMPTE HyperTemplatePte

Definition at line 22 of file hypermap.c.

Referenced by MiInitializePageTable().

◆ MmProtectToPteMask

const ULONG64 MmProtectToPteMask[32]

Definition at line 32 of file page.c.

Referenced by MiDispatchFault(), and MiResolveTransitionFault().

◆ MmProtectToValue