ReactOS  0.4.15-dev-2087-g6bfb76b
newmm.h File Reference
#include <internal/arch/mm.h>
Include dependency graph for newmm.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _CACHE_SECTION_PAGE_TABLE
 
struct  _MM_REQUIRED_RESOURCES
 

Macros

#define MM_SEGMENT_FINALIZE   (0x40000000)
 
#define MIN(x, y)   (((x)<(y))?(x):(y))
 
#define MAX(x, y)   (((x)>(y))?(x):(y))
 
#define BALANCER_CAN_EVICT(Consumer)
 
#define SEC_CACHE   (0x20000000)
 
#define MiWaitForPageEvent(Process, Address)
 
#define MiSetPageEvent(Process, Address)
 
#define ENTRIES_PER_ELEMENT   256
 
#define MiSimpleWrite(F, O, B, L, R)   _MiSimpleWrite(F,O,B,L,R,__FILE__,__LINE__)
 
#define MiWriteBackPage(F, O, L, P)   _MiWriteBackPage(F,O,L,P,__FILE__,__LINE__)
 
#define MiFlushMappedSection(A, O, S, D)   _MiFlushMappedSection(A,O,S,D,__FILE__,__LINE__)
 
#define MiMapViewOfSegment(AddressSpace, Segment, BaseAddress, ViewSize, Protect, ViewOffset, AllocationType)   _MiMapViewOfSegment(AddressSpace,Segment,BaseAddress,ViewSize,Protect,ViewOffset,AllocationType,__FILE__,__LINE__)
 
#define MmTryToLockAddressSpace(x)   _MmTryToLockAddressSpace(x,__FILE__,__LINE__)
 
#define MiFlushMappedSection(A, O, S, D)   _MiFlushMappedSection(A,O,S,D,__FILE__,__LINE__)
 

Typedefs

typedef struct _CACHE_SECTION_PAGE_TABLE CACHE_SECTION_PAGE_TABLE
 
typedef struct _CACHE_SECTION_PAGE_TABLEPCACHE_SECTION_PAGE_TABLE
 
typedef struct _MEMORY_AREAMemoryArea
 
typedef struct _MEMORY_AREA struct _MM_REQUIRED_RESOURCESRequired
 
typedef NTSTATUS(NTAPINotPresentFaultHandler) (PMMSUPPORT AddressSpace, struct _MEMORY_AREA *MemoryArea, PVOID Address, BOOLEAN Locked, struct _MM_REQUIRED_RESOURCES *Required)
 
typedef NTSTATUS(NTAPIFaultHandler) (PMMSUPPORT AddressSpace, struct _MEMORY_AREA *MemoryArea, PVOID Address, struct _MM_REQUIRED_RESOURCES *Required)
 
typedef struct _MM_REQUIRED_RESOURCES MM_REQUIRED_RESOURCES
 
typedef struct _MM_REQUIRED_RESOURCESPMM_REQUIRED_RESOURCES
 
typedef VOID(NTAPIFREE_SECTION_PAGE_FUN) (PMM_SECTION_SEGMENT Segment, PLARGE_INTEGER Offset)
 

Functions

typedef NTSTATUS (NTAPI *AcquireResource)(PMMSUPPORT AddressSpace
 
NTSTATUS NTAPI MmCreateCacheSection (PSECTION *SectionObject, ACCESS_MASK DesiredAccess, POBJECT_ATTRIBUTES ObjectAttributes, PLARGE_INTEGER UMaximumSize, ULONG SectionPageProtection, ULONG AllocationAttributes, PFILE_OBJECT FileObject)
 
PFN_NUMBER NTAPI MmWithdrawSectionPage (PMM_SECTION_SEGMENT Segment, PLARGE_INTEGER FileOffset, BOOLEAN *Dirty)
 
NTSTATUS NTAPI MmFinalizeSectionPageOut (PMM_SECTION_SEGMENT Segment, PLARGE_INTEGER FileOffset, PFN_NUMBER Page, BOOLEAN Dirty)
 
VOID NTAPI MiInitializeSectionPageTable (PMM_SECTION_SEGMENT Segment)
 
VOID NTAPI MmFreePageTablesSectionSegment (PMM_SECTION_SEGMENT Segment, FREE_SECTION_PAGE_FUN FreePage)
 
NTSTATUS NTAPI MmSetSectionAssociation (PFN_NUMBER Page, PMM_SECTION_SEGMENT Segment, PLARGE_INTEGER Offset)
 
VOID NTAPI MmDeleteSectionAssociation (PFN_NUMBER Page)
 
NTSTATUS NTAPI MmpPageOutPhysicalAddress (PFN_NUMBER Page)
 
NTSTATUS MmspWaitForFileLock (PFILE_OBJECT File)
 
NTSTATUS NTAPI MiSimpleRead (PFILE_OBJECT FileObject, PLARGE_INTEGER FileOffset, PVOID Buffer, ULONG Length, BOOLEAN Paging, PIO_STATUS_BLOCK ReadStatus)
 
NTSTATUS NTAPI _MiSimpleWrite (PFILE_OBJECT FileObject, PLARGE_INTEGER FileOffset, PVOID Buffer, ULONG Length, PIO_STATUS_BLOCK ReadStatus, const char *file, int line)
 
NTSTATUS NTAPI _MiWriteBackPage (PFILE_OBJECT FileObject, PLARGE_INTEGER Offset, ULONG Length, PFN_NUMBER Page, const char *File, int Line)
 
NTSTATUS NTAPI MmAccessFaultCacheSection (KPROCESSOR_MODE Mode, ULONG_PTR Address, BOOLEAN FromMdl)
 
NTSTATUS NTAPI MiReadFilePage (PMMSUPPORT AddressSpace, PMEMORY_AREA MemoryArea, PMM_REQUIRED_RESOURCES RequiredResources)
 
NTSTATUS NTAPI MiGetOnePage (PMMSUPPORT AddressSpace, PMEMORY_AREA MemoryArea, PMM_REQUIRED_RESOURCES RequiredResources)
 
NTSTATUS NTAPI MiSwapInPage (PMMSUPPORT AddressSpace, PMEMORY_AREA MemoryArea, PMM_REQUIRED_RESOURCES RequiredResources)
 
NTSTATUS NTAPI MiWriteSwapPage (PMMSUPPORT AddressSpace, PMEMORY_AREA MemoryArea, PMM_REQUIRED_RESOURCES Resources)
 
NTSTATUS NTAPI MiWriteFilePage (PMMSUPPORT AddressSpace, PMEMORY_AREA MemoryArea, PMM_REQUIRED_RESOURCES Resources)
 
VOID NTAPI MiFreeSegmentPage (PMM_SECTION_SEGMENT Segment, PLARGE_INTEGER FileOffset)
 
 _Success_ (1) _When_(return ==STATUS_MORE_PROCESSING_REQUIRED
 
 _At_ (Required->DoAcquisition, _Post_notnull_)) NTSTATUS NTAPI MiCowCacheSectionPage(_In_ PMMSUPPORT AddressSpace
 
VOID MmPageOutDeleteMapping (PVOID Context, PEPROCESS Process, PVOID Address)
 
VOID MmFreeCacheSectionPage (PVOID Context, MEMORY_AREA *MemoryArea, PVOID Address, PFN_NUMBER Page, SWAPENTRY SwapEntry, BOOLEAN Dirty)
 
NTSTATUS NTAPI _MiFlushMappedSection (PVOID BaseAddress, PLARGE_INTEGER BaseOffset, PLARGE_INTEGER FileSize, BOOLEAN Dirty, const char *File, int Line)
 
VOID NTAPI MmFinalizeSegment (PMM_SECTION_SEGMENT Segment)
 
VOID NTAPI MmFreeSectionSegments (PFILE_OBJECT FileObject)
 
NTSTATUS NTAPI MmMapCacheViewInSystemSpaceAtOffset (IN PMM_SECTION_SEGMENT Segment, OUT PVOID *MappedBase, IN PLARGE_INTEGER ViewOffset, IN OUT PULONG ViewSize)
 
NTSTATUS NTAPI _MiMapViewOfSegment (PMMSUPPORT AddressSpace, PMM_SECTION_SEGMENT Segment, PVOID *BaseAddress, SIZE_T ViewSize, ULONG Protect, PLARGE_INTEGER ViewOffset, ULONG AllocationType, const char *file, int line)
 
NTSTATUS NTAPI MmUnmapViewOfCacheSegment (PMMSUPPORT AddressSpace, PVOID BaseAddress)
 
NTSTATUS NTAPI MmUnmapCacheViewInSystemSpace (PVOID Address)
 
NTSTATUS NTAPI MmPageOutPageFileView (PMMSUPPORT AddressSpace, PMEMORY_AREA MemoryArea, PVOID Address, PMM_REQUIRED_RESOURCES Required)
 
FORCEINLINE BOOLEAN _MmTryToLockAddressSpace (IN PMMSUPPORT AddressSpace, const char *file, int line)
 
NTSTATUS NTAPI MiWidenSegment (PMMSUPPORT AddressSpace, PMEMORY_AREA MemoryArea, PMM_REQUIRED_RESOURCES RequiredResources)
 
NTSTATUS NTAPI MiSwapInSectionPage (PMMSUPPORT AddressSpace, PMEMORY_AREA MemoryArea, PMM_REQUIRED_RESOURCES RequiredResources)
 
NTSTATUS NTAPI MmExtendCacheSection (PSECTION Section, PLARGE_INTEGER NewSize, BOOLEAN ExtendFile)
 
PVOID NTAPI MmGetSegmentRmap (PFN_NUMBER Page, PULONG RawOffset)
 
NTSTATUS NTAPI MmNotPresentFaultCacheSection (KPROCESSOR_MODE Mode, ULONG_PTR Address, BOOLEAN FromMdl)
 
ULONG NTAPI MiCacheEvictPages (PMM_SECTION_SEGMENT Segment, ULONG Target)
 
NTSTATUS MiRosTrimCache (ULONG Target, ULONG Priority, PULONG NrFreed)
 

Variables

KEVENT MmWaitPageEvent
 
_In_ PMEMORY_AREA _In_ PVOID Address
 
_In_ PMEMORY_AREA _In_ PVOID _In_ BOOLEAN Locked
 

Macro Definition Documentation

◆ BALANCER_CAN_EVICT

#define BALANCER_CAN_EVICT (   Consumer)
Value:
(((Consumer) == MC_USER) || \
((Consumer) == MC_CACHE))
#define MC_USER
Definition: mm.h:92

Definition at line 14 of file newmm.h.

◆ ENTRIES_PER_ELEMENT

#define ENTRIES_PER_ELEMENT   256

Definition at line 31 of file newmm.h.

◆ MAX

#define MAX (   x,
  y 
)    (((x)>(y))?(x):(y))

Definition at line 10 of file newmm.h.

◆ MiFlushMappedSection [1/2]

#define MiFlushMappedSection (   A,
  O,
  S,
  D 
)    _MiFlushMappedSection(A,O,S,D,__FILE__,__LINE__)

Definition at line 343 of file newmm.h.

◆ MiFlushMappedSection [2/2]

#define MiFlushMappedSection (   A,
  O,
  S,
  D 
)    _MiFlushMappedSection(A,O,S,D,__FILE__,__LINE__)

Definition at line 343 of file newmm.h.

◆ MiMapViewOfSegment

#define MiMapViewOfSegment (   AddressSpace,
  Segment,
  BaseAddress,
  ViewSize,
  Protect,
  ViewOffset,
  AllocationType 
)    _MiMapViewOfSegment(AddressSpace,Segment,BaseAddress,ViewSize,Protect,ViewOffset,AllocationType,__FILE__,__LINE__)

Definition at line 273 of file newmm.h.

◆ MIN

#define MIN (   x,
  y 
)    (((x)<(y))?(x):(y))

Definition at line 9 of file newmm.h.

◆ MiSetPageEvent

#define MiSetPageEvent (   Process,
  Address 
)
Value:
do { \
DPRINT("MiSetPageEvent %p:%p #\n",Process, (PVOID)(Address)); \
} while(0)
_In_ PMEMORY_AREA _In_ PVOID Address
Definition: newmm.h:217
#define FALSE
Definition: types.h:117
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
#define IO_NO_INCREMENT
Definition: iotypes.h:598
KEVENT MmWaitPageEvent
Definition: section.c:66

Definition at line 25 of file newmm.h.

◆ MiSimpleWrite

#define MiSimpleWrite (   F,
  O,
  B,
  L,
  R 
)    _MiSimpleWrite(F,O,B,L,R,__FILE__,__LINE__)

Definition at line 155 of file newmm.h.

◆ MiWaitForPageEvent

#define MiWaitForPageEvent (   Process,
  Address 
)
Value:
do { \
DPRINT("MiWaitForPageEvent %p:%p #\n", Process, Address); \
KeWaitForSingleObject(&MmWaitPageEvent, 0, KernelMode, FALSE, NULL); \
} while(0)
_In_ PMEMORY_AREA _In_ PVOID Address
Definition: newmm.h:217
#define FALSE
Definition: types.h:117
#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
KEVENT MmWaitPageEvent
Definition: section.c:66

Definition at line 20 of file newmm.h.

◆ MiWriteBackPage

#define MiWriteBackPage (   F,
  O,
  L,
  P 
)    _MiWriteBackPage(F,O,L,P,__FILE__,__LINE__)

Definition at line 166 of file newmm.h.

◆ MM_SEGMENT_FINALIZE

#define MM_SEGMENT_FINALIZE   (0x40000000)

Definition at line 6 of file newmm.h.

◆ MmTryToLockAddressSpace

#define MmTryToLockAddressSpace (   x)    _MmTryToLockAddressSpace(x,__FILE__,__LINE__)

Definition at line 314 of file newmm.h.

◆ SEC_CACHE

#define SEC_CACHE   (0x20000000)

Definition at line 18 of file newmm.h.

Typedef Documentation

◆ CACHE_SECTION_PAGE_TABLE

◆ FaultHandler

◆ FREE_SECTION_PAGE_FUN

typedef VOID(NTAPI * FREE_SECTION_PAGE_FUN) (PMM_SECTION_SEGMENT Segment, PLARGE_INTEGER Offset)

Definition at line 108 of file newmm.h.

◆ MemoryArea

Definition at line 47 of file newmm.h.

◆ MM_REQUIRED_RESOURCES

◆ NotPresentFaultHandler

◆ PCACHE_SECTION_PAGE_TABLE

◆ PMM_REQUIRED_RESOURCES

◆ Required

Function Documentation

◆ _At_()

_At_ ( Required->  DoAcquisition,
_Post_notnull_   
)

◆ _MiFlushMappedSection()

NTSTATUS NTAPI _MiFlushMappedSection ( PVOID  BaseAddress,
PLARGE_INTEGER  BaseOffset,
PLARGE_INTEGER  FileSize,
BOOLEAN  Dirty,
const char File,
int  Line 
)

◆ _MiMapViewOfSegment()

NTSTATUS NTAPI _MiMapViewOfSegment ( PMMSUPPORT  AddressSpace,
PMM_SECTION_SEGMENT  Segment,
PVOID BaseAddress,
SIZE_T  ViewSize,
ULONG  Protect,
PLARGE_INTEGER  ViewOffset,
ULONG  AllocationType,
const char file,
int  line 
)

Referenced by MmMapViewOfSegment().

◆ _MiSimpleWrite()

NTSTATUS NTAPI _MiSimpleWrite ( PFILE_OBJECT  FileObject,
PLARGE_INTEGER  FileOffset,
PVOID  Buffer,
ULONG  Length,
PIO_STATUS_BLOCK  ReadStatus,
const char file,
int  line 
)

◆ _MiWriteBackPage()

NTSTATUS NTAPI _MiWriteBackPage ( PFILE_OBJECT  FileObject,
PLARGE_INTEGER  Offset,
ULONG  Length,
PFN_NUMBER  Page,
const char File,
int  Line 
)

◆ _MmTryToLockAddressSpace()

FORCEINLINE BOOLEAN _MmTryToLockAddressSpace ( IN PMMSUPPORT  AddressSpace,
const char file,
int  line 
)

Definition at line 305 of file newmm.h.

308 {
310  //DbgPrint("(%s:%d) Try Lock Address Space %x -> %s\n", file, line, AddressSpace, Result ? "true" : "false");
311  return Result;
312 }
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG AddressSpace
Definition: iofuncs.h:2268
unsigned char BOOLEAN
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
BOOLEAN FASTCALL KeTryToAcquireGuardedMutex(IN OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:86

◆ _Success_()

_Success_ ( ) ==STATUS_MORE_PROCESSING_REQUIRED

◆ MiCacheEvictPages()

ULONG NTAPI MiCacheEvictPages ( PMM_SECTION_SEGMENT  Segment,
ULONG  Target 
)

Definition at line 590 of file swapout.c.

592 {
594  ULONG Result = 0, i, j;
598 
600 
601  for (i = 0; i < RtlNumberGenericTableElements(&Segment->PageTable); i++) {
602 
604  i);
605 
606  ASSERT(Element);
607 
608  Offset = Element->FileOffset;
609  for (j = 0; j < ENTRIES_PER_ELEMENT; j++, Offset.QuadPart += PAGE_SIZE) {
611  if (Entry && !IS_SWAP_FROM_SSE(Entry)) {
615  if (NT_SUCCESS(Status))
616  Result++;
618  }
619  }
620  }
621 
623 
624  return Result;
625 }
#define MmGetPageEntrySectionSegment(S, O)
Definition: mm.h:1448
struct _Entry Entry
Definition: kefuncs.h:627
NTSYSAPI ULONG NTAPI RtlNumberGenericTableElements(_In_ PRTL_GENERIC_TABLE Table)
#define PFN_FROM_SSE(E)
Definition: mm.h:1237
LONG NTSTATUS
Definition: precomp.h:26
#define MmLockSectionSegment(x)
Definition: mm.h:1262
uint32_t ULONG_PTR
Definition: typedefs.h:65
ULONG PFN_NUMBER
Definition: ke.h:9
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
PFN_NUMBER Page
Definition: section.c:4831
#define MmUnlockSectionSegment(x)
Definition: mm.h:1270
_Inout_ PVOID Segment
Definition: exfuncs.h:1101
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
Definition: glfuncs.h:250
Status
Definition: gdiplustypes.h:24
#define ASSERT(a)
Definition: mode.c:45
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_Must_inspect_result_ NTSYSAPI PVOID NTAPI RtlGetElementGenericTable(_In_ PRTL_GENERIC_TABLE Table, _In_ ULONG I)
LARGE_INTEGER FileOffset
Definition: newmm.h:37
#define PAGE_SIZE
Definition: env_spec_w32.h:49
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
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 IS_SWAP_FROM_SSE(E)
Definition: mm.h:1238
unsigned int ULONG
Definition: retypes.h:1
base of all file and directory entries
Definition: entries.h:82
NTSTATUS NTAPI MmpPageOutPhysicalAddress(PFN_NUMBER Page)
Definition: swapout.c:345
#define ENTRIES_PER_ELEMENT
Definition: newmm.h:31

Referenced by MiRosTrimCache().

◆ MiFreeSegmentPage()

VOID NTAPI MiFreeSegmentPage ( PMM_SECTION_SEGMENT  Segment,
PLARGE_INTEGER  FileOffset 
)

Definition at line 617 of file data.c.

619 {
621  PFILE_OBJECT FileObject = Segment->FileObject;
622 
624  DPRINTC("MiFreeSegmentPage(%p:%I64x -> Entry %Ix\n",
625  Segment,
626  FileOffset->QuadPart,
627  Entry);
628 
629  if (Entry && !IS_SWAP_FROM_SSE(Entry))
630  {
631  // The segment is carrying a dirty page.
632  PFN_NUMBER OldPage = PFN_FROM_SSE(Entry);
633  if (IS_DIRTY_SSE(Entry) && FileObject)
634  {
635  DPRINT("MiWriteBackPage(%p,%wZ,%I64x)\n",
636  Segment,
637  &FileObject->FileName,
638  FileOffset->QuadPart);
639 
641  }
642  DPRINTC("Free page %Ix (off %I64x from %p) (ref ct %lu, ent %Ix, dirty? %s)\n",
643  OldPage,
644  FileOffset->QuadPart,
645  Segment,
646  MmGetReferenceCountPage(OldPage),
647  Entry,
648  IS_DIRTY_SSE(Entry) ? "true" : "false");
649 
651  MmReleasePageMemoryConsumer(MC_CACHE, OldPage);
652  }
653  else if (IS_SWAP_FROM_SSE(Entry))
654  {
655  DPRINT("Free swap\n");
657  }
658 
659  DPRINT("Done\n");
660 }
#define DPRINTC
Definition: data.c:84
#define MmGetPageEntrySectionSegment(S, O)
Definition: mm.h:1448
struct _Entry Entry
Definition: kefuncs.h:627
#define PFN_FROM_SSE(E)
Definition: mm.h:1237
NTSTATUS NTAPI MmReleasePageMemoryConsumer(ULONG Consumer, PFN_NUMBER Page)
Definition: balance.c:77
#define MmSetPageEntrySectionSegment(S, O, E)
Definition: mm.h:1446
uint32_t ULONG_PTR
Definition: typedefs.h:65
ULONG PFN_NUMBER
Definition: ke.h:9
#define IS_DIRTY_SSE(E)
Definition: mm.h:1246
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
_Inout_ PVOID Segment
Definition: exfuncs.h:1101
* PFILE_OBJECT
Definition: iotypes.h:1995
ULONG NTAPI MmGetReferenceCountPage(PFN_NUMBER Page)
Definition: freelist.c:538
#define PAGE_SIZE
Definition: env_spec_w32.h:49
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:159
#define IS_SWAP_FROM_SSE(E)
Definition: mm.h:1238
#define DPRINT
Definition: sndvol32.h:71
#define SWAPENTRY_FROM_SSE(E)
Definition: mm.h:1242
base of all file and directory entries
Definition: entries.h:82
VOID NTAPI MmFreeSwapPage(SWAPENTRY Entry)
Definition: pagefile.c:274
#define MiWriteBackPage(F, O, L, P)
Definition: newmm.h:166

◆ MiGetOnePage()

NTSTATUS NTAPI MiGetOnePage ( PMMSUPPORT  AddressSpace,
PMEMORY_AREA  MemoryArea,
PMM_REQUIRED_RESOURCES  RequiredResources 
)

Definition at line 83 of file reqtools.c.

86 {
87  ULONG i;
89 
90  for (i = 0; i < Required->Amount; i++)
91  {
92  DPRINTC("MiGetOnePage(%s:%d)\n", Required->File, Required->Line);
94  TRUE,
95  &Required->Page[i]);
96  if (!NT_SUCCESS(Status))
97  {
98  while (i > 0)
99  {
101  Required->Page[i-1]);
102  i--;
103  }
104  return Status;
105  }
106  }
107 
108  return Status;
109 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI MmReleasePageMemoryConsumer(ULONG Consumer, PFN_NUMBER Page)
Definition: balance.c:77
NTSTATUS NTAPI MmRequestPageMemoryConsumer(ULONG Consumer, BOOLEAN MyWait, PPFN_NUMBER AllocatedPage)
Definition: balance.c:275
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
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 DPRINTC
Definition: reqtools.c:59
unsigned int ULONG
Definition: retypes.h:1
#define STATUS_SUCCESS
Definition: shellext.h:65
struct _MEMORY_AREA struct _MM_REQUIRED_RESOURCES * Required
Definition: newmm.h:48

◆ MiInitializeSectionPageTable()

VOID NTAPI MiInitializeSectionPageTable ( PMM_SECTION_SEGMENT  Segment)

Definition at line 165 of file sptab.c.

166 {
168  MiSectionPageTableCompare,
169  MiSectionPageTableAllocate,
170  MiSectionPageTableFree,
171  NULL);
172 
173  DPRINT("MiInitializeSectionPageTable(%p)\n", &Segment->PageTable);
174 }
VOID NTAPI RtlInitializeGenericTable(IN PRTL_GENERIC_TABLE Table, IN PRTL_GENERIC_COMPARE_ROUTINE CompareRoutine, IN PRTL_GENERIC_ALLOCATE_ROUTINE AllocateRoutine, IN PRTL_GENERIC_FREE_ROUTINE FreeRoutine, IN PVOID TableContext)
Definition: generictable.c:100
_Inout_ PVOID Segment
Definition: exfuncs.h:1101
#define NULL
Definition: types.h:112
#define DPRINT
Definition: sndvol32.h:71

Referenced by ExeFmtpCreateImageSection(), MmCreateDataFileSection(), and MmCreatePhysicalMemorySection().

◆ MiReadFilePage()

NTSTATUS NTAPI MiReadFilePage ( PMMSUPPORT  AddressSpace,
PMEMORY_AREA  MemoryArea,
PMM_REQUIRED_RESOURCES  RequiredResources 
)

Definition at line 133 of file reqtools.c.

136 {
137  PFILE_OBJECT FileObject = RequiredResources->Context;
138  PPFN_NUMBER Page = &RequiredResources->Page[RequiredResources->Offset];
139  PLARGE_INTEGER FileOffset = &RequiredResources->FileOffset;
141  PVOID PageBuf = NULL;
142  KEVENT Event;
143  IO_STATUS_BLOCK IOSB;
144  UCHAR MdlBase[sizeof(MDL) + sizeof(ULONG)];
145  PMDL Mdl = (PMDL)MdlBase;
146  KIRQL OldIrql;
147 
148  DPRINTC("Pulling page %I64x from %wZ to %Ix\n",
149  FileOffset->QuadPart,
150  &FileObject->FileName,
151  *Page);
152 
153  Status = MmRequestPageMemoryConsumer(RequiredResources->Consumer,
154  TRUE,
155  Page);
156 
157  if (!NT_SUCCESS(Status))
158  {
159  DPRINT1("Status: %x\n", Status);
160  return Status;
161  }
162 
165  Mdl->MdlFlags |= MDL_PAGES_LOCKED;
166 
169  if (Status == STATUS_PENDING)
170  {
172  Status = IOSB.Status;
173  }
174  if (Mdl->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA)
175  {
176  MmUnmapLockedPages (Mdl->MappedSystemVa, Mdl);
177  }
178 
180  if (!PageBuf)
181  {
182  MmReleasePageMemoryConsumer(RequiredResources->Consumer, *Page);
183  return STATUS_NO_MEMORY;
184  }
185 
186  RtlZeroMemory((PCHAR)PageBuf+RequiredResources->Amount,
187  PAGE_SIZE-RequiredResources->Amount);
188 
190 
191  DPRINT("Read Status %x (Page %x)\n", Status, *Page);
192 
193  if (!NT_SUCCESS(Status))
194  {
195  MmReleasePageMemoryConsumer(RequiredResources->Consumer, *Page);
196  DPRINT("Status: %x\n", Status);
197  return Status;
198  }
199 
200  return STATUS_SUCCESS;
201 }
signed char * PCHAR
Definition: retypes.h:7
#define MmInitializeMdl(_MemoryDescriptorList, _BaseVa, _Length)
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI MmReleasePageMemoryConsumer(ULONG Consumer, PFN_NUMBER Page)
Definition: balance.c:77
NTSTATUS NTAPI MmRequestPageMemoryConsumer(ULONG Consumer, BOOLEAN MyWait, PPFN_NUMBER AllocatedPage)
Definition: balance.c:275
NTSTATUS NTAPI IoPageRead(IN PFILE_OBJECT FileObject, IN PMDL Mdl, IN PLARGE_INTEGER Offset, IN PKEVENT Event, IN PIO_STATUS_BLOCK StatusBlock)
Definition: iofunc.c:1199
PVOID PMDL
Definition: usb.h:39
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define MDL_MAPPED_TO_SYSTEM_VA
Definition: mmtypes.h:18
UCHAR KIRQL
Definition: env_spec_w32.h:591
ULONG * PPFN_NUMBER
Definition: ke.h:9
#define FALSE
Definition: types.h:117
PFN_NUMBER Page[2]
Definition: newmm.h:72
VOID NTAPI MmUnmapLockedPages(IN PVOID BaseAddress, IN PMDL Mdl)
Definition: mdlsup.c:841
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:467
#define PsGetCurrentProcess
Definition: psfuncs.h:17
PVOID NTAPI MiMapPageInHyperSpace(IN PEPROCESS Process, IN PFN_NUMBER Page, IN PKIRQL OldIrql)
Definition: hypermap.c:28
PFN_NUMBER Page
Definition: section.c:4831
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
Status
Definition: gdiplustypes.h:24
#define MDL_PAGES_LOCKED
Definition: mmtypes.h:19
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
VOID NTAPI MmBuildMdlFromPages(PMDL Mdl, PPFN_NUMBER Pages)
Definition: pagefile.c:94
* PFILE_OBJECT
Definition: iotypes.h:1995
VOID NTAPI MiUnmapPageInHyperSpace(IN PEPROCESS Process, IN PVOID Address, IN KIRQL OldIrql)
Definition: hypermap.c:91
unsigned char UCHAR
Definition: xmlstorage.h:181
MDL
Definition: mmtypes.h:117
_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
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:159
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
#define NULL
Definition: types.h:112
_In_ WDFDEVICE _In_ PVOID _In_opt_ PMDL Mdl
#define DPRINT1
Definition: precomp.h:8
#define DPRINTC
Definition: reqtools.c:59
LARGE_INTEGER FileOffset
Definition: newmm.h:70
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71

◆ MiRosTrimCache()

NTSTATUS MiRosTrimCache ( ULONG  Target,
ULONG  Priority,
PULONG  NrFreed 
)

Definition at line 633 of file swapout.c.

636 {
637  ULONG Freed;
640  *NrFreed = 0;
641 
642  DPRINT1("Need to trim %lu cache pages\n", Target);
643  for (Entry = MiSegmentList.Flink;
644  *NrFreed < Target && Entry != &MiSegmentList;
645  Entry = Entry->Flink) {
647  /* Defer to MM to try recovering pages from it */
648  Freed = MiCacheEvictPages(Segment, Target);
649  *NrFreed += Freed;
650  }
651  DPRINT1("Evicted %lu cache pages\n", Target);
652 
653  if (!IsListEmpty(&MiSegmentList)) {
657  }
658 
659  return STATUS_SUCCESS;
660 }
struct _Entry Entry
Definition: kefuncs.h:627
#define InsertTailList(ListHead, Entry)
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
_Inout_ PVOID Segment
Definition: exfuncs.h:1101
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
LIST_ENTRY MiSegmentList
Definition: data.c:86
Definition: typedefs.h:119
ULONG NTAPI MiCacheEvictPages(PMM_SECTION_SEGMENT Segment, ULONG Target)
Definition: swapout.c:590
_In_ WDFIOTARGET Target
Definition: wdfrequest.h:306
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
#define STATUS_SUCCESS
Definition: shellext.h:65
base of all file and directory entries
Definition: entries.h:82

Referenced by CcShutdownSystem().

◆ MiSimpleRead()

NTSTATUS NTAPI MiSimpleRead ( PFILE_OBJECT  FileObject,
PLARGE_INTEGER  FileOffset,
PVOID  Buffer,
ULONG  Length,
BOOLEAN  Paging,
PIO_STATUS_BLOCK  ReadStatus 
)

Definition at line 109 of file io.c.

115 {
117  PIRP Irp = NULL;
118  KEVENT ReadWait;
121 
124  ASSERT(Buffer);
126 
129  ReadStatus->Information = 0;
130 
132 
133  DPRINT("PAGING READ: FileObject %p <%wZ> Offset %08x%08x Length %ul\n",
134  FileObject,
135  &FileObject->FileName,
136  FileOffset->HighPart,
137  FileOffset->LowPart,
138  Length);
139 
141 
143  DeviceObject,
144  Buffer,
145  Length,
146  FileOffset,
147  ReadStatus);
148 
149  if (!Irp)
150  {
151  return STATUS_NO_MEMORY;
152  }
153 
155 
156  Irp->UserEvent = &ReadWait;
157  Irp->Tail.Overlay.OriginalFileObject = FileObject;
158  Irp->Tail.Overlay.Thread = PsGetCurrentThread();
162  IrpSp->CompletionRoutine = MiSimpleReadComplete;
163 
164  /* Non paging case, the FileObject will be dereferenced at completion */
165  if (!Paging)
167 
169  if (Status == STATUS_PENDING)
170  {
171  DPRINT("KeWaitForSingleObject(&ReadWait)\n");
172  if (!NT_SUCCESS(KeWaitForSingleObject(&ReadWait,
173  Suspended,
174  KernelMode,
175  FALSE,
176  NULL)))
177  {
178  DPRINT1("Warning: Failed to wait for synchronous IRP\n");
179  ASSERT(FALSE);
180  return Status;
181  }
182  }
183 
184  DPRINT("Paging IO Done: %08x\n", ReadStatus->Status);
185  /* When "ReadStatus->Information > 0" is false and "ReadStatus->Status == STATUS_END_OF_FILE" is true
186  * it means that read pointer is out of file, so we must fail */
187  Status = ReadStatus->Status == STATUS_END_OF_FILE && ReadStatus->Information > 0 ? STATUS_SUCCESS : ReadStatus->Status;
188  return Status;
189 }
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
LONG NTSTATUS
Definition: precomp.h:26
#define IRP_NOCACHE
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define STATUS_END_OF_FILE
Definition: shellext.h:67
#define STATUS_INTERNAL_ERROR
Definition: ntstatus.h:465
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
Definition: bufpool.h:45
PDEVICE_OBJECT NTAPI MmGetDeviceObjectForFile(IN PFILE_OBJECT FileObject)
Definition: io.c:57
PIO_COMPLETION_ROUTINE CompletionRoutine
Definition: iotypes.h:3310
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
Status
Definition: gdiplustypes.h:24
#define ASSERT(a)
Definition: mode.c:45
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
static USHORT ReadStatus(IN PUCHAR ReadDataPort)
Definition: hardware.c:128
PIRP NTAPI IoBuildAsynchronousFsdRequest(IN ULONG MajorFunction, IN PDEVICE_OBJECT DeviceObject, IN PVOID Buffer, IN ULONG Length, IN PLARGE_INTEGER StartingOffset, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:750
#define SL_INVOKE_ON_ERROR
Definition: iotypes.h:3325
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2691
PFILE_OBJECT FileObject
Definition: iotypes.h:3165
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define SL_INVOKE_ON_SUCCESS
Definition: iotypes.h:3324
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:159
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
#define NULL
Definition: types.h:112
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define IRP_PAGING_IO
#define DPRINT1
Definition: precomp.h:8
#define IRP_MJ_READ
Definition: rdpdr.c:46
#define ObReferenceObject
Definition: obfuncs.h:204
#define IRP_SYNCHRONOUS_API
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71
#define IRP_SYNCHRONOUS_PAGING_IO

Referenced by CcZeroData(), and ExeFmtpReadFile().

◆ MiSwapInPage()

NTSTATUS NTAPI MiSwapInPage ( PMMSUPPORT  AddressSpace,
PMEMORY_AREA  MemoryArea,
PMM_REQUIRED_RESOURCES  RequiredResources 
)

Definition at line 220 of file reqtools.c.

223 {
225 
227  TRUE,
228  &Resources->Page[Resources->Offset]);
229  if (!NT_SUCCESS(Status))
230  {
231  DPRINT1("MmRequestPageMemoryConsumer failed, status = %x\n", Status);
232  return Status;
233  }
234 
235  Status = MmReadFromSwapPage(Resources->SwapEntry,
236  Resources->Page[Resources->Offset]);
237  if (!NT_SUCCESS(Status))
238  {
239  DPRINT1("MmReadFromSwapPage failed, status = %x\n", Status);
240  return Status;
241  }
242 
244  Resources->SwapEntry);
245 
246  DPRINT1("MiSwapInPage(%x,%x)\n",
247  Resources->Page[Resources->Offset],
248  Resources->SwapEntry);
249 
250  return Status;
251 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI MmRequestPageMemoryConsumer(ULONG Consumer, BOOLEAN MyWait, PPFN_NUMBER AllocatedPage)
Definition: balance.c:275
NTSTATUS NTAPI MmReadFromSwapPage(SWAPENTRY SwapEntry, PFN_NUMBER Page)
Definition: pagefile.c:187
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define DPRINT1
Definition: precomp.h:8
VOID NTAPI MmSetSavedSwapEntryPage(PFN_NUMBER Page, SWAPENTRY SavedSwapEntry)
Definition: freelist.c:483

◆ MiSwapInSectionPage()

NTSTATUS NTAPI MiSwapInSectionPage ( PMMSUPPORT  AddressSpace,
PMEMORY_AREA  MemoryArea,
PMM_REQUIRED_RESOURCES  RequiredResources 
)

◆ MiWidenSegment()

NTSTATUS NTAPI MiWidenSegment ( PMMSUPPORT  AddressSpace,
PMEMORY_AREA  MemoryArea,
PMM_REQUIRED_RESOURCES  RequiredResources 
)

◆ MiWriteFilePage()

NTSTATUS NTAPI MiWriteFilePage ( PMMSUPPORT  AddressSpace,
PMEMORY_AREA  MemoryArea,
PMM_REQUIRED_RESOURCES  Resources 
)

Definition at line 271 of file reqtools.c.

274 {
275  DPRINT1("MiWriteFilePage(%x,%x)\n",
276  Required->Page[Required->Offset],
277  Required->FileOffset.LowPart);
278 
279  return MiWriteBackPage(Required->Context,
280  &Required->FileOffset,
281  PAGE_SIZE,
282  Required->Page[Required->Offset]);
283 }
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define DPRINT1
Definition: precomp.h:8
struct _MEMORY_AREA struct _MM_REQUIRED_RESOURCES * Required
Definition: newmm.h:48
#define MiWriteBackPage(F, O, L, P)
Definition: newmm.h:166

◆ MiWriteSwapPage()

NTSTATUS NTAPI MiWriteSwapPage ( PMMSUPPORT  AddressSpace,
PMEMORY_AREA  MemoryArea,
PMM_REQUIRED_RESOURCES  Resources 
)

◆ MmAccessFaultCacheSection()

NTSTATUS NTAPI MmAccessFaultCacheSection ( KPROCESSOR_MODE  Mode,
ULONG_PTR  Address,
BOOLEAN  FromMdl 
)

Referenced by MmpAccessFault().

◆ MmCreateCacheSection()

NTSTATUS NTAPI MmCreateCacheSection ( PSECTION SectionObject,
ACCESS_MASK  DesiredAccess,
POBJECT_ATTRIBUTES  ObjectAttributes,
PLARGE_INTEGER  UMaximumSize,
ULONG  SectionPageProtection,
ULONG  AllocationAttributes,
PFILE_OBJECT  FileObject 
)

Referenced by MmCreateSection().

◆ MmDeleteSectionAssociation()

VOID NTAPI MmDeleteSectionAssociation ( PFN_NUMBER  Page)

Definition at line 532 of file rmap.c.

533 {
534  PMM_RMAP_ENTRY current_entry, previous_entry;
536 
537  previous_entry = NULL;
538  current_entry = MmGetRmapListHeadPage(Page);
539  while (current_entry != NULL)
540  {
541  if (RMAP_IS_SEGMENT(current_entry->Address))
542  {
543  if (previous_entry == NULL)
544  {
545  MmSetRmapListHeadPage(Page, current_entry->Next);
546  }
547  else
548  {
549  previous_entry->Next = current_entry->Next;
550  }
552  ExFreeToNPagedLookasideList(&RmapLookasideList, current_entry);
553  return;
554  }
555  previous_entry = current_entry;
556  current_entry = current_entry->Next;
557  }
559 }
struct _MM_RMAP_ENTRY *NTAPI MmGetRmapListHeadPage(PFN_NUMBER Page)
Definition: freelist.c:458
FORCEINLINE KIRQL MiAcquirePfnLock(VOID)
Definition: mm.h:886
FORCEINLINE VOID MiReleasePfnLock(_In_ KIRQL OldIrql)
Definition: mm.h:893
UCHAR KIRQL
Definition: env_spec_w32.h:591
PFN_NUMBER Page
Definition: section.c:4831
VOID NTAPI MmSetRmapListHeadPage(PFN_NUMBER Page, struct _MM_RMAP_ENTRY *ListHead)
#define RMAP_IS_SEGMENT(x)
Definition: mm.h:825
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
#define NULL
Definition: types.h:112
struct _MM_RMAP_ENTRY * Next
Definition: mm.h:235
Definition: mm.h:233
static NPAGED_LOOKASIDE_LIST RmapLookasideList
Definition: rmap.c:21
PVOID Address
Definition: mm.h:237

Referenced by _MmSetPageEntrySectionSegment().

◆ MmExtendCacheSection()

NTSTATUS NTAPI MmExtendCacheSection ( PSECTION  Section,
PLARGE_INTEGER  NewSize,
BOOLEAN  ExtendFile 
)

Referenced by CcSetFileSizes().

◆ MmFinalizeSectionPageOut()

NTSTATUS NTAPI MmFinalizeSectionPageOut ( PMM_SECTION_SEGMENT  Segment,
PLARGE_INTEGER  FileOffset,
PFN_NUMBER  Page,
BOOLEAN  Dirty 
)

Definition at line 165 of file swapout.c.

169 {
171  BOOLEAN WriteZero = FALSE, WritePage = FALSE;
173 
174  /* Bail early if the reference count isn't where we need it */
175  if (MmGetReferenceCountPage(Page) != 1)
176  {
177  DPRINT1("Cannot page out locked page %x with ref count %lu\n",
178  Page,
180  return STATUS_UNSUCCESSFUL;
181  }
182 
184  (void)InterlockedIncrementUL(&Segment->ReferenceCount);
185 
186  if (Dirty)
187  {
188  DPRINT("Finalize (dirty) Segment %p Page %x\n", Segment, Page);
189  DPRINT("Segment->FileObject %p\n", Segment->FileObject);
190  DPRINT("Segment->Flags %x\n", Segment->Flags);
191 
192  WriteZero = TRUE;
193  WritePage = TRUE;
194  }
195  else
196  {
197  WriteZero = TRUE;
198  }
199 
200  DPRINT("Status %x\n", Status);
201 
203 
204  if (WritePage)
205  {
206  DPRINT("MiWriteBackPage(Segment %p FileObject %p Offset %x)\n",
207  Segment,
208  Segment->FileObject,
209  FileOffset->LowPart);
210 
211  Status = MiWriteBackPage(Segment->FileObject,
212  FileOffset,
213  PAGE_SIZE,
214  Page);
215  }
216 
218 
219  if (WriteZero && NT_SUCCESS(Status))
220  {
221  DPRINT("Setting page entry in segment %p:%x to swap %x\n",
222  Segment,
223  FileOffset->LowPart,
224  Swap);
225 
227  FileOffset,
228  Swap ? MAKE_SWAP_SSE(Swap) : 0);
229  }
230  else
231  {
232  DPRINT("Setting page entry in segment %p:%x to page %x\n",
233  Segment,
234  FileOffset->LowPart,
235  Page);
236 
238  FileOffset,
239  Page ? (Dirty ? DIRTY_SSE(MAKE_PFN_SSE(Page)) : MAKE_PFN_SSE(Page)) : 0);
240  }
241 
242  if (NT_SUCCESS(Status))
243  {
244  DPRINT("Removing page %x for real\n", Page);
247  }
248 
250 
251  if (InterlockedDecrementUL(&Segment->ReferenceCount) == 0)
252  {
254  }
255 
256  /* Note: Writing may evict the segment... Nothing is guaranteed from here down */
258 
259  DPRINT("Status %x\n", Status);
260  return Status;
261 }
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
#define MiSetPageEvent(Process, Address)
Definition: newmm.h:25
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI MmReleasePageMemoryConsumer(ULONG Consumer, PFN_NUMBER Page)
Definition: balance.c:77
#define MmSetPageEntrySectionSegment(S, O, E)
Definition: mm.h:1446
#define MmLockSectionSegment(x)
Definition: mm.h:1262
#define DIRTY_SSE(E)
Definition: mm.h:1244
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define FALSE
Definition: types.h:117
VOID NTAPI MmFinalizeSegment(PMM_SECTION_SEGMENT Segment)
unsigned char BOOLEAN
PFN_NUMBER Page
Definition: section.c:4831
#define MmUnlockSectionSegment(x)
Definition: mm.h:1270
_Inout_ PVOID Segment
Definition: exfuncs.h:1101
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ULONG NTAPI MmGetReferenceCountPage(PFN_NUMBER Page)
Definition: freelist.c:538
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
static VOID WritePage(PMEM_HOOK Hook, ULONG Address, PVOID Buffer, ULONG Size)
Definition: memory.c:126
#define Swap(a, b)
Definition: geom.c:201
#define InterlockedDecrementUL(Addend)
Definition: ex.h:1496
#define PAGE_SIZE
Definition: env_spec_w32.h:49
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:159
#define InterlockedIncrementUL(Addend)
Definition: ex.h:1499
ULONG_PTR SWAPENTRY
Definition: mm.h:47
#define DPRINT1
Definition: precomp.h:8
VOID NTAPI MmSetSavedSwapEntryPage(PFN_NUMBER Page, SWAPENTRY SavedSwapEntry)
Definition: freelist.c:483
#define MAKE_SWAP_SSE(S)
Definition: mm.h:1243
#define MAKE_PFN_SSE(P)
Definition: mm.h:1241
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71
SWAPENTRY NTAPI MmGetSavedSwapEntryPage(PFN_NUMBER Page)
Definition: freelist.c:499
#define MiWriteBackPage(F, O, L, P)
Definition: newmm.h:166

Referenced by MmpPageOutPhysicalAddress().

◆ MmFinalizeSegment()

VOID NTAPI MmFinalizeSegment ( PMM_SECTION_SEGMENT  Segment)

◆ MmFreeCacheSectionPage()

VOID MmFreeCacheSectionPage ( PVOID  Context,
MEMORY_AREA MemoryArea,
PVOID  Address,
PFN_NUMBER  Page,
SWAPENTRY  SwapEntry,
BOOLEAN  Dirty 
)

Definition at line 663 of file data.c.

669 {
671  PVOID *ContextData = Context;
676 
677  DPRINT("MmFreeSectionPage(%p,%p,%Ix,%Ix,%u)\n",
678  MmGetAddressSpaceOwner(ContextData[0]),
679  Address,
680  Page,
681  SwapEntry,
682  Dirty);
683 
684  AddressSpace = ContextData[0];
687  Segment = ContextData[1];
689  MemoryArea->Data.SectionData.ViewOffset.QuadPart;
690 
692 
693  if (Page != 0 && PFN_FROM_SSE(Entry) == Page && Dirty)
694  {
695  DPRINT("Freeing section page %p:%I64x -> %Ix\n", Segment, Offset.QuadPart, Entry);
697  }
698  if (Page)
699  {
700  DPRINT("Removing page %p:%I64x -> %x\n", Segment, Offset.QuadPart, Entry);
705  }
706  if (SwapEntry != 0)
707  {
708  MmFreeSwapPage(SwapEntry);
709  }
710 }
#define MmGetPageEntrySectionSegment(S, O)
Definition: mm.h:1448
struct _Entry Entry
Definition: kefuncs.h:627
#define PFN_FROM_SSE(E)
Definition: mm.h:1237
VOID NTAPI MmDeleteRmap(PFN_NUMBER Page, struct _EPROCESS *Process, PVOID Address)
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG AddressSpace
Definition: iofuncs.h:2268
NTSTATUS NTAPI MmReleasePageMemoryConsumer(ULONG Consumer, PFN_NUMBER Page)
Definition: balance.c:77
#define PAGE_ROUND_DOWN(x)
Definition: mmtypes.h:36
#define MmSetPageEntrySectionSegment(S, O, E)
Definition: mm.h:1446
#define DIRTY_SSE(E)
Definition: mm.h:1244
uint32_t ULONG_PTR
Definition: typedefs.h:65
static WCHAR Address[46]
Definition: ping.c:68
VOID NTAPI MmDeleteVirtualMapping(struct _EPROCESS *Process, PVOID Address, BOOLEAN *WasDirty, PPFN_NUMBER Page)
PFN_NUMBER Page
Definition: section.c:4831
void * PVOID
Definition: retypes.h:9
_Inout_ PVOID Segment
Definition: exfuncs.h:1101
#define MA_GetStartingAddress(_MemoryArea)
Definition: mm.h:212
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
FORCEINLINE PEPROCESS MmGetAddressSpaceOwner(IN PMMSUPPORT AddressSpace)
Definition: mm.h:1533
#define NULL
Definition: types.h:112
struct _MEMORY_AREA::@1775 SectionData
VOID NTAPI MmSetSavedSwapEntryPage(PFN_NUMBER Page, SWAPENTRY SavedSwapEntry)
Definition: freelist.c:483
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
struct tagContext Context
Definition: acpixf.h:1034
#define ULONG_PTR
Definition: config.h:101
#define DPRINT
Definition: sndvol32.h:71
base of all file and directory entries
Definition: entries.h:82
VOID NTAPI MmFreeSwapPage(SWAPENTRY Entry)
Definition: pagefile.c:274

◆ MmFreePageTablesSectionSegment()

VOID NTAPI MmFreePageTablesSectionSegment ( PMM_SECTION_SEGMENT  Segment,
FREE_SECTION_PAGE_FUN  FreePage 
)

Definition at line 299 of file sptab.c.

301 {
303  DPRINT("MiFreePageTablesSectionSegment(%p)\n", &Segment->PageTable);
304  while ((Element = RtlGetElementGenericTable(&Segment->PageTable, 0))) {
305  DPRINT("Delete table for <%wZ> %p -> %I64x\n",
306  Segment->FileObject ? &Segment->FileObject->FileName : NULL,
307  Segment,
308  Element->FileOffset.QuadPart);
309  if (FreePage)
310  {
311  ULONG i;
312  for (i = 0; i < ENTRIES_PER_ELEMENT; i++)
313  {
316  Offset.QuadPart = Element->FileOffset.QuadPart + i * PAGE_SIZE;
317  Entry = Element->PageEntries[i];
318  if (Entry && !IS_SWAP_FROM_SSE(Entry))
319  {
320  DPRINT("Freeing page %p:%Ix @ %I64x\n",
321  Segment,
322  Entry,
323  Offset.QuadPart);
324 
326  }
327  }
328  }
329  DPRINT("Remove memory\n");
330  RtlDeleteElementGenericTable(&Segment->PageTable, Element);
331  }
332  DPRINT("Done\n");
333 }
struct _Entry Entry
Definition: kefuncs.h:627
uint32_t ULONG_PTR
Definition: typedefs.h:65
ULONG_PTR PageEntries[ENTRIES_PER_ELEMENT]
Definition: newmm.h:40
_Inout_ PVOID Segment
Definition: exfuncs.h:1101
_Must_inspect_result_ NTSYSAPI PVOID NTAPI RtlGetElementGenericTable(_In_ PRTL_GENERIC_TABLE Table, _In_ ULONG I)
LARGE_INTEGER FileOffset
Definition: newmm.h:37
#define PAGE_SIZE
Definition: env_spec_w32.h:49
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
NTSYSAPI BOOLEAN NTAPI RtlDeleteElementGenericTable(_In_ PRTL_GENERIC_TABLE Table, _In_ PVOID Buffer)
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 IS_SWAP_FROM_SSE(E)
Definition: mm.h:1238
#define NULL
Definition: types.h:112
unsigned int ULONG
Definition: retypes.h:1
#define DPRINT
Definition: sndvol32.h:71
base of all file and directory entries
Definition: entries.h:82
LONGLONG QuadPart
Definition: typedefs.h:114
#define ENTRIES_PER_ELEMENT
Definition: newmm.h:31

Referenced by MmDereferenceSegment().

◆ MmFreeSectionSegments()

VOID NTAPI MmFreeSectionSegments ( PFILE_OBJECT  FileObject)

◆ MmGetSegmentRmap()

PVOID NTAPI MmGetSegmentRmap ( PFN_NUMBER  Page,
PULONG  RawOffset 
)

Definition at line 493 of file rmap.c.

494 {
496  PMM_RMAP_ENTRY current_entry;//, previous_entry;
498 
499  //previous_entry = NULL;
500  current_entry = MmGetRmapListHeadPage(Page);
501  while (current_entry != NULL)
502  {
503  if (RMAP_IS_SEGMENT(current_entry->Address))
504  {
505  Result = (PCACHE_SECTION_PAGE_TABLE)current_entry->Process;
506  *RawOffset = (ULONG_PTR)current_entry->Address & ~RMAP_SEGMENT_MASK;
507  if (*Result->Segment->Flags & MM_SEGMENT_INDELETE)
508  {
510  return NULL;
511  }
512 
513  InterlockedIncrement64(Result->Segment->ReferenceCount);
515  return Result;
516  }
517  //previous_entry = current_entry;
518  current_entry = current_entry->Next;
519  }
521  return NULL;
522 }
PEPROCESS Process
Definition: mm.h:236
struct _MM_RMAP_ENTRY *NTAPI MmGetRmapListHeadPage(PFN_NUMBER Page)
Definition: freelist.c:458
FORCEINLINE KIRQL MiAcquirePfnLock(VOID)
Definition: mm.h:886
struct _CACHE_SECTION_PAGE_TABLE * PCACHE_SECTION_PAGE_TABLE
FORCEINLINE VOID MiReleasePfnLock(_In_ KIRQL OldIrql)
Definition: mm.h:893
uint32_t ULONG_PTR
Definition: typedefs.h:65
UCHAR KIRQL
Definition: env_spec_w32.h:591
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
PFN_NUMBER Page
Definition: section.c:4831
#define InterlockedIncrement64
Definition: interlocked.h:211
#define RMAP_SEGMENT_MASK
Definition: mm.h:824
#define RMAP_IS_SEGMENT(x)
Definition: mm.h:825
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
#define MM_SEGMENT_INDELETE
Definition: mm.h:208
#define NULL
Definition: types.h:112
struct _MM_RMAP_ENTRY * Next
Definition: mm.h:235
Definition: mm.h:233
PVOID Address
Definition: mm.h:237

Referenced by MmGetSectionAssociation().

◆ MmMapCacheViewInSystemSpaceAtOffset()

NTSTATUS NTAPI MmMapCacheViewInSystemSpaceAtOffset ( IN PMM_SECTION_SEGMENT  Segment,
OUT PVOID MappedBase,
IN PLARGE_INTEGER  ViewOffset,
IN OUT PULONG  ViewSize 
)

Referenced by CcpMapData().

◆ MmNotPresentFaultCacheSection()

NTSTATUS NTAPI MmNotPresentFaultCacheSection ( KPROCESSOR_MODE  Mode,
ULONG_PTR  Address,
BOOLEAN  FromMdl 
)

Referenced by MmNotPresentFault().

◆ MmPageOutDeleteMapping()

VOID MmPageOutDeleteMapping ( PVOID  Context,
PEPROCESS  Process,
PVOID  Address 
)

◆ MmPageOutPageFileView()

NTSTATUS NTAPI MmPageOutPageFileView ( PMMSUPPORT  AddressSpace,
PMEMORY_AREA  MemoryArea,
PVOID  Address,
PMM_REQUIRED_RESOURCES  Required 
)

◆ MmpPageOutPhysicalAddress()

NTSTATUS NTAPI MmpPageOutPhysicalAddress ( PFN_NUMBER  Page)

Definition at line 345 of file swapout.c.

346 {
347  BOOLEAN ProcRef = FALSE, PageDirty;
348  PFN_NUMBER SectionPage = 0;
354  BOOLEAN Dirty = FALSE;
355  PVOID Address = NULL;
359 
360  DPRINTC("Page out %x (ref ct %x)\n", Page, MmGetReferenceCountPage(Page));
361 
364  {
365  DPRINTC("Withdrawing page (%x) %p:%x\n",
366  Page,
367  Segment,
368  FileOffset.LowPart);
369 
370  SectionPage = MmWithdrawSectionPage(Segment, &FileOffset, &Dirty);
371  DPRINTC("SectionPage %x\n", SectionPage);
372 
373  if (SectionPage == MM_WAIT_ENTRY || SectionPage == 0)
374  {
375  DPRINT1("In progress page out %x\n", SectionPage);
377  return STATUS_UNSUCCESSFUL;
378  }
379  else
380  {
381  ASSERT(SectionPage == Page);
382  }
383  Resources.State = Dirty ? 1 : 0;
384  }
385  else
386  {
387  DPRINT("No segment association for %x\n", Page);
388  }
389 
390  Dirty = MmIsDirtyPageRmap(Page);
391 
392  DPRINTC("Trying to unmap all instances of %x\n", Page);
395 
396  // Entry and Segment might be null here in the case that the page
397  // is new and is in the process of being swapped in
398  if (!entry && !Segment)
399  {
401  DPRINT1("Page %x is in transit\n", Page);
403  goto bail;
404  }
405 
406  while (entry != NULL && NT_SUCCESS(Status))
407  {
408  Process = entry->Process;
409  Address = entry->Address;
410 
411  DPRINTC("Process %p Address %p Page %x\n", Process, Address, Page);
412 
414  {
415  entry = entry->Next;
416  continue;
417  }
418 
420  {
421  /* Make sure we don't try to page out part of an exiting process */
423  {
424  DPRINT("bail\n");
426  goto bail;
427  }
429  ProcRef = TRUE;
430  AddressSpace = &Process->Vm;
431  }
432  else
433  {
435  }
437 
438  RtlZeroMemory(&Resources, sizeof(Resources));
439 
440  if ((((ULONG_PTR)Address) & 0xFFF) != 0)
441  {
442  KeBugCheck(MEMORY_MANAGEMENT);
443  }
444 
445  do
446  {
448 
451  {
454  DPRINTC("bail\n");
455  goto bail;
456  }
457 
458  DPRINTC("Type %x (%p -> %p)\n",
459  MemoryArea->Type,
462 
463  Resources.DoAcquisition = NULL;
464  Resources.Page[0] = Page;
465 
467 
468  DPRINT("%p:%p, page %x %x\n",
469  Process,
470  Address,
471  Page,
472  Resources.Page[0]);
473 
474  PageDirty = FALSE;
475 
477  MemoryArea,
478  Address,
479  &PageDirty,
480  &Resources);
481 
482  Dirty |= PageDirty;
483  DPRINT("%x\n", Status);
484 
486 
488 
489  if (Status == STATUS_SUCCESS + 1)
490  {
491  // Wait page ... the other guy has it, so we'll just fail for now
492  DPRINT1("Wait entry ... can't continue\n");
494  goto bail;
495  }
497  {
498  DPRINTC("DoAcquisition %p\n", Resources.DoAcquisition);
499 
500  Status = Resources.DoAcquisition(AddressSpace,
501  MemoryArea,
502  &Resources);
503 
504  DPRINTC("Status %x\n", Status);
505  if (!NT_SUCCESS(Status))
506  {
507  DPRINT1("bail\n");
508  goto bail;
509  }
510  else
511  {
513  }
514  }
515  }
517 
518  if (ProcRef)
519  {
521  ProcRef = FALSE;
522  }
523 
527 
528  DPRINTC("Entry %p\n", entry);
529  }
530 
532 
533 bail:
534  DPRINTC("BAIL %x\n", Status);
535 
536  if (Segment)
537  {
538  ULONG RefCount;
539 
540  DPRINTC("About to finalize section page %x (%p:%x) Status %x %s\n",
541  Page,
542  Segment,
543  FileOffset.LowPart,
544  Status,
545  Dirty ? "dirty" : "clean");
546 
547  if (!NT_SUCCESS(Status) ||
549  &FileOffset,
550  Page,
551  Dirty)))
552  {
553  DPRINTC("Failed to page out %x, replacing %x at %x in segment %x\n",
554  SectionPage,
555  FileOffset.LowPart,
556  Segment);
557 
559 
561  &FileOffset,
563 
565  }
566 
567  /* Alas, we had the last reference */
568  if ((RefCount = InterlockedDecrementUL(&Segment->ReferenceCount)) == 0)
570  }
571 
572  if (ProcRef)
573  {
574  DPRINTC("Dereferencing process...\n");
576  }
577 
579 
580  DPRINTC("%s %x %x\n",
581  NT_SUCCESS(Status) ? "Evicted" : "Spared",
582  Page,
583  Status);
584 
586 }
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
#define PageDirty(page)
Definition: module.h:607
#define DPRINTC
Definition: swapout.c:68
ULONG Type
Definition: mm.h:219
NTSTATUS NTAPI MmFinalizeSectionPageOut(PMM_SECTION_SEGMENT Segment, PLARGE_INTEGER FileOffset, PFN_NUMBER Page, BOOLEAN Dirty)
Definition: swapout.c:165
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:68
#define TRUE
Definition: types.h:120
#define STATUS_MM_RESTART_OPERATION
Definition: mm.h:82
struct _MM_RMAP_ENTRY *NTAPI MmGetRmapListHeadPage(PFN_NUMBER Page)
Definition: freelist.c:458
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG AddressSpace
Definition: iofuncs.h:2268
FORCEINLINE VOID MmUnlockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1526
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI MmIsDirtyPageRmap(PFN_NUMBER Page)
Definition: rmap.c:320
#define MmSetPageEntrySectionSegment(S, O, E)
Definition: mm.h:1446
PMEMORY_AREA NTAPI MmLocateMemoryAreaByAddress(PMMSUPPORT AddressSpace, PVOID Address)
Definition: marea.c:60
#define MmLockSectionSegment(x)
Definition: mm.h:1262
FAST_MUTEX RmapListLock
VOID FASTCALL ExReleaseFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:31
#define DIRTY_SSE(E)
Definition: mm.h:1244
uint32_t ULONG_PTR
Definition: typedefs.h:65
ULONG PFN_NUMBER
Definition: ke.h:9
NTSTATUS NTAPI MmPageOutCacheSection(PMMSUPPORT AddressSpace, MEMORY_AREA *MemoryArea, PVOID Address, PBOOLEAN Dirty, PMM_REQUIRED_RESOURCES Required)
Definition: swapout.c:279
#define FALSE
Definition: types.h:117
DECLSPEC_NORETURN VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1427
VOID NTAPI MmFinalizeSegment(PMM_SECTION_SEGMENT Segment)
unsigned char BOOLEAN
static WCHAR Address[46]
Definition: ping.c:68
PFN_NUMBER Page
Definition: section.c:4831
#define MM_IS_WAIT_PTE(E)
Definition: mm.h:1239
#define MmUnlockSectionSegment(x)
Definition: mm.h:1270
_Inout_ PVOID Segment
Definition: exfuncs.h:1101
Status
Definition: gdiplustypes.h:24
#define ASSERT(a)
Definition: mode.c:45
PMM_SECTION_SEGMENT NTAPI MmGetSectionAssociation(PFN_NUMBER Page, PLARGE_INTEGER Offset)
Definition: sptab.c:352
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ObDereferenceObject
Definition: obfuncs.h:203
BOOLEAN DeleteInProgress
Definition: mm.h:221
#define RMAP_IS_SEGMENT(x)
Definition: mm.h:825
#define MA_GetEndingAddress(_MemoryArea)
Definition: mm.h:213
BOOLEAN NTAPI PspIsProcessExiting(IN PEPROCESS Process)
Definition: kill.c:1067
ULONG NTAPI MmGetReferenceCountPage(PFN_NUMBER Page)
Definition: freelist.c:538
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
uint32_t entry
Definition: isohybrid.c:63
#define InterlockedDecrementUL(Addend)
Definition: ex.h:1496
#define MA_GetStartingAddress(_MemoryArea)
Definition: mm.h:212
FORCEINLINE PMMSUPPORT MmGetKernelAddressSpace(VOID)
Definition: mm.h:1548
VOID FASTCALL ExAcquireFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:23
PFN_NUMBER NTAPI MmGetPfnForProcess(struct _EPROCESS *Process, PVOID Address)
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:159
#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 ObReferenceObject
Definition: obfuncs.h:204
#define MAKE_PFN_SSE(P)
Definition: mm.h:1241
unsigned int ULONG
Definition: retypes.h:1
Definition: mm.h:233
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71
FAST_MUTEX MiGlobalPageOperation
Definition: swapout.c:74
struct _MEMORY_AREA * MemoryArea
Definition: newmm.h:47
#define APC_LEVEL
Definition: env_spec_w32.h:695
FORCEINLINE VOID MmLockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1519
#define MmSystemRangeStart
Definition: mm.h:32
PFN_NUMBER NTAPI MmWithdrawSectionPage(PMM_SECTION_SEGMENT Segment, PLARGE_INTEGER FileOffset, BOOLEAN *Dirty)
Definition: swapout.c:87

Referenced by MiCacheEvictPages(), and MmPageOutPhysicalAddress().

◆ MmSetSectionAssociation()

NTSTATUS NTAPI MmSetSectionAssociation ( PFN_NUMBER  Page,
PMM_SECTION_SEGMENT  Segment,
PLARGE_INTEGER  Offset 
)

Definition at line 373 of file sptab.c.

376 {
378  ULONG ActualOffset;
379 
381  ASSERT(PageTable);
382 
383  ActualOffset = (ULONG)(Offset->QuadPart - PageTable->FileOffset.QuadPart);
386  (PVOID)(RMAP_SEGMENT_MASK | (ActualOffset >> PAGE_SHIFT)));
387 
388  return STATUS_SUCCESS;
389 }
#define PAGE_SHIFT
Definition: env_spec_w32.h:45
VOID NTAPI MmInsertRmap(PFN_NUMBER Page, struct _EPROCESS *Process, PVOID Address)
static PMEM_HOOK PageTable[TOTAL_PAGES]
Definition: memory.c:40
static PCACHE_SECTION_PAGE_TABLE NTAPI MiSectionPageTableGet(PRTL_GENERIC_TABLE Table, PLARGE_INTEGER FileOffset)
Definition: sptab.c:117
PFN_NUMBER Page
Definition: section.c:4831
_Inout_ PVOID Segment
Definition: exfuncs.h:1101
#define ASSERT(a)
Definition: mode.c:45
#define RMAP_SEGMENT_MASK
Definition: mm.h:824
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
unsigned int ULONG
Definition: retypes.h:1
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by _MmSetPageEntrySectionSegment().

◆ MmspWaitForFileLock()

NTSTATUS MmspWaitForFileLock ( PFILE_OBJECT  File)

Definition at line 908 of file section.c.

909 {
910  return STATUS_SUCCESS;
911  //return KeWaitForSingleObject(&File->Lock, 0, KernelMode, FALSE, NULL);
912 }
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by MmCreateDataFileSection(), and MmCreateImageSection().

◆ MmUnmapCacheViewInSystemSpace()

NTSTATUS NTAPI MmUnmapCacheViewInSystemSpace ( PVOID  Address)

◆ MmUnmapViewOfCacheSegment()

NTSTATUS NTAPI MmUnmapViewOfCacheSegment ( PMMSUPPORT  AddressSpace,
PVOID  BaseAddress 
)

◆ MmWithdrawSectionPage()

PFN_NUMBER NTAPI MmWithdrawSectionPage ( PMM_SECTION_SEGMENT  Segment,
PLARGE_INTEGER  FileOffset,
BOOLEAN Dirty 
)

Definition at line 87 of file swapout.c.

90 {
92 
93  DPRINT("MmWithdrawSectionPage(%p,%08x%08x,%p)\n",
94  Segment,
95  FileOffset->HighPart,
96  FileOffset->LowPart,
97  Dirty);
98 
101 
102  *Dirty = !!IS_DIRTY_SSE(Entry);
103 
104  DPRINT("Withdraw %x (%x) of %wZ\n",
105  FileOffset->LowPart,
106  Entry,
107  Segment->FileObject ? &Segment->FileObject->FileName : NULL);
108 
109  if (!Entry)
110  {
111  DPRINT("Stoeled!\n");
113  return 0;
114  }
115  else if (MM_IS_WAIT_PTE(Entry))
116  {
117  DPRINT("WAIT\n");
119  return MM_WAIT_ENTRY;
120  }
121  else if (Entry && !IS_SWAP_FROM_SSE(Entry))
122  {
123  DPRINT("Page %x\n", PFN_FROM_SSE(Entry));
124 
125  *Dirty |= (Entry & 2);
126 
128  FileOffset,
129  MAKE_SWAP_SSE(MM_WAIT_ENTRY));
130 
132  return PFN_FROM_SSE(Entry);
133  }
134  else
135  {
136  DPRINT1("SWAP ENTRY?! (%p:%08x%08x)\n",
137  Segment,
138  FileOffset->HighPart,
139  FileOffset->LowPart);
140 
141  ASSERT(FALSE);
143  return 0;
144  }
145 }
#define MmGetPageEntrySectionSegment(S, O)
Definition: mm.h:1448
struct _Entry Entry
Definition: kefuncs.h:627
#define PFN_FROM_SSE(E)
Definition: mm.h:1237
#define MmSetPageEntrySectionSegment(S, O, E)
Definition: mm.h:1446
#define MmLockSectionSegment(x)
Definition: mm.h:1262
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define IS_DIRTY_SSE(E)
Definition: mm.h:1246
#define FALSE
Definition: types.h:117
#define MM_IS_WAIT_PTE(E)
Definition: mm.h:1239
#define MmUnlockSectionSegment(x)
Definition: mm.h:1270
_Inout_ PVOID Segment
Definition: exfuncs.h:1101
#define ASSERT(a)
Definition: mode.c:45
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:159
#define IS_SWAP_FROM_SSE(E)
Definition: mm.h:1238
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
#define MAKE_SWAP_SSE(S)
Definition: mm.h:1243
#define DPRINT
Definition: sndvol32.h:71
base of all file and directory entries
Definition: entries.h:82

Referenced by MmpPageOutPhysicalAddress().

◆ NTSTATUS()

typedef NTSTATUS ( NTAPI AcquireResource)

Variable Documentation

◆ Address

Definition at line 217 of file newmm.h.

◆ Locked

◆ MmWaitPageEvent

KEVENT MmWaitPageEvent

Definition at line 66 of file section.c.