ReactOS  0.4.14-dev-608-gd495a4f
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 PFN_FROM_SSE(E)   ((PFN_NUMBER)((E) >> PAGE_SHIFT))
 
#define IS_SWAP_FROM_SSE(E)   ((E) & 0x00000001)
 
#define MM_IS_WAIT_PTE(E)   (IS_SWAP_FROM_SSE(E) && SWAPENTRY_FROM_SSE(E) == MM_WAIT_ENTRY)
 
#define MAKE_PFN_SSE(P)   ((ULONG_PTR)((P) << PAGE_SHIFT))
 
#define SWAPENTRY_FROM_SSE(E)   ((E) >> 1)
 
#define MAKE_SWAP_SSE(S)   (((ULONG_PTR)(S) << 1) | 0x1)
 
#define DIRTY_SSE(E)   ((E) | 2)
 
#define CLEAN_SSE(E)   ((E) & ~2)
 
#define IS_DIRTY_SSE(E)   ((E) & 2)
 
#define PAGE_FROM_SSE(E)   ((E) & 0xFFFFF000)
 
#define SHARE_COUNT_FROM_SSE(E)   (((E) & 0x00000FFC) >> 2)
 
#define MAX_SHARE_COUNT   0x3FF
 
#define MAKE_SSE(P, C)   ((ULONG_PTR)((P) | ((C) << 2)))
 
#define MM_SEGMENT_FINALIZE   (0x40000000)
 
#define RMAP_SEGMENT_MASK   ~((ULONG_PTR)0xff)
 
#define RMAP_IS_SEGMENT(x)   (((ULONG_PTR)(x) & RMAP_SEGMENT_MASK) == RMAP_SEGMENT_MASK)
 
#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 MmSetPageEntrySectionSegment(S, O, E)   _MmSetPageEntrySectionSegment(S,O,E,__FILE__,__LINE__)
 
#define MmGetPageEntrySectionSegment(S, O)   _MmGetPageEntrySectionSegment(S,O,__FILE__,__LINE__)
 
#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 MmLockSectionSegment(x)   _MmLockSectionSegment(x,__FILE__,__LINE__)
 
#define MmUnlockSectionSegment(x)   _MmUnlockSectionSegment(x,__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 (PROS_SECTION_OBJECT *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)
 
NTSTATUS NTAPI _MmSetPageEntrySectionSegment (PMM_SECTION_SEGMENT Segment, PLARGE_INTEGER Offset, ULONG_PTR Entry, const char *file, int line)
 
ULONG_PTR NTAPI _MmGetPageEntrySectionSegment (PMM_SECTION_SEGMENT Segment, PLARGE_INTEGER Offset, const char *file, int line)
 
VOID NTAPI MmFreePageTablesSectionSegment (PMM_SECTION_SEGMENT Segment, FREE_SECTION_PAGE_FUN FreePage)
 
PMM_SECTION_SEGMENT NTAPI MmGetSectionAssociation (PFN_NUMBER Page, PLARGE_INTEGER Offset)
 
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 NTAPI _MmLockSectionSegment (PMM_SECTION_SEGMENT Segment, const char *file, int line)
 
VOID NTAPI _MmUnlockSectionSegment (PMM_SECTION_SEGMENT Segment, const char *file, int line)
 
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 (PROS_SECTION_OBJECT 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:94
#define MC_CACHE
Definition: mm.h:93

Definition at line 32 of file newmm.h.

◆ CLEAN_SSE

#define CLEAN_SSE (   E)    ((E) & ~2)

Definition at line 15 of file newmm.h.

◆ DIRTY_SSE

#define DIRTY_SSE (   E)    ((E) | 2)

Definition at line 14 of file newmm.h.

◆ ENTRIES_PER_ELEMENT

#define ENTRIES_PER_ELEMENT   256

Definition at line 49 of file newmm.h.

◆ IS_DIRTY_SSE

#define IS_DIRTY_SSE (   E)    ((E) & 2)

Definition at line 16 of file newmm.h.

◆ IS_SWAP_FROM_SSE

#define IS_SWAP_FROM_SSE (   E)    ((E) & 0x00000001)

Definition at line 8 of file newmm.h.

◆ MAKE_PFN_SSE

#define MAKE_PFN_SSE (   P)    ((ULONG_PTR)((P) << PAGE_SHIFT))

Definition at line 11 of file newmm.h.

◆ MAKE_SSE

#define MAKE_SSE (   P,
  C 
)    ((ULONG_PTR)((P) | ((C) << 2)))

Definition at line 20 of file newmm.h.

◆ MAKE_SWAP_SSE

#define MAKE_SWAP_SSE (   S)    (((ULONG_PTR)(S) << 1) | 0x1)

Definition at line 13 of file newmm.h.

◆ MAX

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

Definition at line 28 of file newmm.h.

◆ MAX_SHARE_COUNT

#define MAX_SHARE_COUNT   0x3FF

Definition at line 19 of file newmm.h.

◆ MiFlushMappedSection [1/2]

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

Definition at line 402 of file newmm.h.

◆ MiFlushMappedSection [2/2]

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

Definition at line 402 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 332 of file newmm.h.

◆ MIN

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

Definition at line 27 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:260
_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:566
KEVENT MmWaitPageEvent

Definition at line 43 of file newmm.h.

◆ MiSimpleWrite

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

Definition at line 198 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:260
smooth NULL
Definition: ftsmooth.c:416
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
KEVENT MmWaitPageEvent

Definition at line 38 of file newmm.h.

◆ MiWriteBackPage

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

Definition at line 209 of file newmm.h.

◆ MM_IS_WAIT_PTE

#define MM_IS_WAIT_PTE (   E)    (IS_SWAP_FROM_SSE(E) && SWAPENTRY_FROM_SSE(E) == MM_WAIT_ENTRY)

Definition at line 9 of file newmm.h.

◆ MM_SEGMENT_FINALIZE

#define MM_SEGMENT_FINALIZE   (0x40000000)

Definition at line 22 of file newmm.h.

◆ MmGetPageEntrySectionSegment

#define MmGetPageEntrySectionSegment (   S,
  O 
)    _MmGetPageEntrySectionSegment(S,O,__FILE__,__LINE__)

Definition at line 143 of file newmm.h.

◆ MmLockSectionSegment

#define MmLockSectionSegment (   x)    _MmLockSectionSegment(x,__FILE__,__LINE__)

Definition at line 276 of file newmm.h.

◆ MmSetPageEntrySectionSegment

#define MmSetPageEntrySectionSegment (   S,
  O,
  E 
)    _MmSetPageEntrySectionSegment(S,O,E,__FILE__,__LINE__)

Definition at line 141 of file newmm.h.

◆ MmTryToLockAddressSpace

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

Definition at line 373 of file newmm.h.

◆ MmUnlockSectionSegment

#define MmUnlockSectionSegment (   x)    _MmUnlockSectionSegment(x,__FILE__,__LINE__)

Definition at line 284 of file newmm.h.

◆ PAGE_FROM_SSE

#define PAGE_FROM_SSE (   E)    ((E) & 0xFFFFF000)

Definition at line 17 of file newmm.h.

◆ PFN_FROM_SSE

#define PFN_FROM_SSE (   E)    ((PFN_NUMBER)((E) >> PAGE_SHIFT))

Definition at line 7 of file newmm.h.

◆ RMAP_IS_SEGMENT

#define RMAP_IS_SEGMENT (   x)    (((ULONG_PTR)(x) & RMAP_SEGMENT_MASK) == RMAP_SEGMENT_MASK)

Definition at line 25 of file newmm.h.

◆ RMAP_SEGMENT_MASK

#define RMAP_SEGMENT_MASK   ~((ULONG_PTR)0xff)

Definition at line 24 of file newmm.h.

◆ SEC_CACHE

#define SEC_CACHE   (0x20000000)

Definition at line 36 of file newmm.h.

◆ SHARE_COUNT_FROM_SSE

#define SHARE_COUNT_FROM_SSE (   E)    (((E) & 0x00000FFC) >> 2)

Definition at line 18 of file newmm.h.

◆ SWAPENTRY_FROM_SSE

#define SWAPENTRY_FROM_SSE (   E)    ((E) >> 1)

Definition at line 12 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 145 of file newmm.h.

◆ MemoryArea

Definition at line 65 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 
)

Definition at line 128 of file data.c.

134 {
140  ULONG_PTR BeginningAddress, EndingAddress;
141  LARGE_INTEGER ViewOffset;
143  PFN_NUMBER Page;
144  PPFN_NUMBER Pages;
145  KIRQL OldIrql;
146 
147  DPRINT("MiFlushMappedSection(%p,%I64x,%I64x,%u,%s:%d)\n",
148  BaseAddress,
149  BaseOffset->QuadPart,
150  FileSize ? FileSize->QuadPart : 0,
151  WriteData,
152  File,
153  Line);
154 
158  {
160  DPRINT("STATUS_NOT_MAPPED_DATA\n");
161  return STATUS_NOT_MAPPED_DATA;
162  }
163  BeginningAddress = PAGE_ROUND_DOWN(MA_GetStartingAddress(MemoryArea));
164  EndingAddress = PAGE_ROUND_UP(MA_GetEndingAddress(MemoryArea));
165  Segment = MemoryArea->Data.SectionData.Segment;
166  ViewOffset.QuadPart = MemoryArea->Data.SectionData.ViewOffset.QuadPart;
167 
168  ASSERT(ViewOffset.QuadPart == BaseOffset->QuadPart);
169 
171 
173  sizeof(PFN_NUMBER) * ((EndingAddress - BeginningAddress) >> PAGE_SHIFT));
174 
175  if (!Pages)
176  {
177  ASSERT(FALSE);
178  }
179 
180  //DPRINT("Getting pages in range %08x-%08x\n", BeginningAddress, EndingAddress);
181 
182  for (PageAddress = BeginningAddress;
183  PageAddress < EndingAddress;
185  {
187  FileOffset.QuadPart = ViewOffset.QuadPart + PageAddress - BeginningAddress;
189  &FileOffset);
190  Page = PFN_FROM_SSE(Entry);
191  if (Entry != 0 && !IS_SWAP_FROM_SSE(Entry) &&
192  (MmIsDirtyPageRmap(Page) || IS_DIRTY_SSE(Entry)) &&
193  FileOffset.QuadPart < FileSize->QuadPart)
194  {
196  MmReferencePage(Page);
198  Pages[(PageAddress - BeginningAddress) >> PAGE_SHIFT] = Entry;
199  }
200  else
201  {
202  Pages[(PageAddress - BeginningAddress) >> PAGE_SHIFT] = 0;
203  }
204  }
205 
208 
209  for (PageAddress = BeginningAddress;
210  PageAddress < EndingAddress;
212  {
214  FileOffset.QuadPart = ViewOffset.QuadPart + PageAddress - BeginningAddress;
215  Entry = Pages[(PageAddress - BeginningAddress) >> PAGE_SHIFT];
216  Page = PFN_FROM_SSE(Entry);
217  if (Page)
218  {
219  if (WriteData) {
220  //DPRINT("MiWriteBackPage(%wZ,addr %x,%08x%08x)\n", &Segment->FileObject->FileName, PageAddress, FileOffset.u.HighPart, FileOffset.u.LowPart);
221  Status = MiWriteBackPage(Segment->FileObject, &FileOffset, PAGE_SIZE, Page);
222  } else
224 
225  if (NT_SUCCESS(Status)) {
227  MmSetCleanAllRmaps(Page);
228 
231  PAGE_READONLY);
232 
235 
236  if (Entry && !IS_SWAP_FROM_SSE(Entry) && PFN_FROM_SSE(Entry) == Page)
238 
241  } else {
242  DPRINT("Writeback from section flush %08x%08x (%x) %x@%x (%08x%08x:%wZ) failed %x\n",
243  FileOffset.u.HighPart,
244  FileOffset.u.LowPart,
245  (ULONG)(FileSize->QuadPart - FileOffset.QuadPart),
246  PageAddress,
247  Page,
248  FileSize->u.HighPart,
249  FileSize->u.LowPart,
250  &Segment->FileObject->FileName,
251  Status);
252  }
254  }
255  }
256 
257  ExFreePool(Pages);
258 
259  return Status;
260 }
#define MmSetPageEntrySectionSegment(S, O, E)
Definition: newmm.h:141
struct _LARGE_INTEGER::@2220 u
VOID NTAPI MmSetCleanAllRmaps(PFN_NUMBER Page)
Definition: rmap.c:195
#define PAGE_SHIFT
Definition: env_spec_w32.h:45
#define STATUS_NOT_MAPPED_DATA
Definition: udferr_usr.h:157
#define IS_DIRTY_SSE(E)
Definition: newmm.h:16
ULONG Type
Definition: mm.h:214
struct _Entry Entry
Definition: kefuncs.h:640
#define PFN_FROM_SSE(E)
Definition: newmm.h:7
#define CLEAN_SSE(E)
Definition: newmm.h:15
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG AddressSpace
Definition: iofuncs.h:2268
FORCEINLINE VOID MmUnlockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1431
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI MmReleasePageMemoryConsumer(ULONG Consumer, PFN_NUMBER Page)
Definition: balance.c:97
#define PAGE_ROUND_DOWN(x)
Definition: mmtypes.h:36
BOOLEAN NTAPI MmIsDirtyPageRmap(PFN_NUMBER Page)
Definition: rmap.c:239
FORCEINLINE KIRQL MiAcquirePfnLock(VOID)
Definition: mm.h:901
PMEMORY_AREA NTAPI MmLocateMemoryAreaByAddress(PMMSUPPORT AddressSpace, PVOID Address)
Definition: marea.c:60
#define PAGE_ROUND_UP(x)
Definition: scsiport_int.h:13
FORCEINLINE VOID MiReleasePfnLock(_In_ KIRQL OldIrql)
Definition: mm.h:908
#define MEMORY_AREA_CACHE
Definition: mm.h:72
_Must_inspect_result_ _In_ SIZE_T _In_ PVOID PageAddress
Definition: mmfuncs.h:472
uint32_t ULONG_PTR
Definition: typedefs.h:63
UCHAR KIRQL
Definition: env_spec_w32.h:591
ULONG * PPFN_NUMBER
Definition: ke.h:8
ULONG PFN_NUMBER
Definition: ke.h:8
union _MEMORY_AREA::@1743 Data
void DPRINT(...)
Definition: polytest.cpp:61
_Inout_ PVOID Segment
Definition: exfuncs.h:893
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
struct _MEMORY_AREA::@1743::@1744 SectionData
BOOLEAN DeleteInProgress
Definition: mm.h:217
#define MA_GetEndingAddress(_MemoryArea)
Definition: mm.h:208
VOID NTAPI MmSetPageProtect(struct _EPROCESS *Process, PVOID Address, ULONG flProtect)
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Definition: ncftp.h:79
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
_Must_inspect_result_ _Out_ PLARGE_INTEGER FileSize
Definition: fsrtlfuncs.h:108
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define IS_SWAP_FROM_SSE(E)
Definition: newmm.h:8
#define MA_GetStartingAddress(_MemoryArea)
Definition: mm.h:207
Status
Definition: gdiplustypes.h:24
FORCEINLINE PMMSUPPORT MmGetKernelAddressSpace(VOID)
Definition: mm.h:1453
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:151
FORCEINLINE PEPROCESS MmGetAddressSpaceOwner(IN PMMSUPPORT AddressSpace)
Definition: mm.h:1438
#define PAGE_READONLY
Definition: compat.h:127
#define MmLockSectionSegment(x)
Definition: newmm.h:276
#define MC_CACHE
Definition: mm.h:93
unsigned int ULONG
Definition: retypes.h:1
Definition: File.h:15
#define MmUnlockSectionSegment(x)
Definition: newmm.h:284
return STATUS_SUCCESS
Definition: btrfs.c:2938
VOID NTAPI MmReferencePage(PFN_NUMBER Page)
Definition: freelist.c:489
struct _MEMORY_AREA * MemoryArea
Definition: newmm.h:65
FORCEINLINE VOID MmLockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1424
static VOID WriteData(USHORT Data)
Definition: hardware.c:25
base of all file and directory entries
Definition: entries.h:82
#define MmGetPageEntrySectionSegment(S, O)
Definition: newmm.h:143
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
LONGLONG QuadPart
Definition: typedefs.h:112
#define MiWriteBackPage(F, O, L, P)
Definition: newmm.h:209

◆ _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 
)

Definition at line 539 of file data.c.

548 {
549  PMEMORY_AREA MArea;
551 
554  BaseAddress,
555  ViewSize,
556  Protect,
557  &MArea,
559  *BaseAddress ?
561 
562  if (!NT_SUCCESS(Status))
563  {
564  DPRINT("Mapping between 0x%p and 0x%p failed (%X).\n",
565  (*BaseAddress),
566  (char*)(*BaseAddress) + ViewSize,
567  Status);
568 
569  return Status;
570  }
571 
572  DPRINTC("MiMapViewOfSegment %p %p %p %I64x %Ix %wZ %s:%d\n",
574  *BaseAddress,
575  Segment,
576  ViewOffset ? ViewOffset->QuadPart : 0,
577  ViewSize,
578  Segment->FileObject ? &Segment->FileObject->FileName : NULL,
579  file,
580  line);
581 
582  MArea->Data.SectionData.Segment = Segment;
583  if (ViewOffset)
584  MArea->Data.SectionData.ViewOffset = *ViewOffset;
585  else
586  MArea->Data.SectionData.ViewOffset.QuadPart = 0;
587 
588 #if 0
589  MArea->NotPresent = MmNotPresentFaultPageFile;
590  MArea->AccessFault = MiCowSectionPage;
591  MArea->PageOut = MmPageOutPageFileView;
592 #endif
593 
594  MmInitializeRegion(&MArea->Data.SectionData.RegionListHead,
595  ViewSize,
596  0,
597  Protect);
598 
599  DPRINTC("MiMapViewOfSegment(P %p, A %p, T %x)\n",
601  *BaseAddress,
602  MArea->Type);
603 
604  return STATUS_SUCCESS;
605 }
#define DPRINTC
Definition: data.c:84
ULONG Type
Definition: mm.h:214
_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
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG AddressSpace
Definition: iofuncs.h:2268
LONG NTSTATUS
Definition: precomp.h:26
#define MEMORY_AREA_CACHE
Definition: mm.h:72
union _MEMORY_AREA::@1743 Data
smooth NULL
Definition: ftsmooth.c:416
Definition: parser.c:48
void DPRINT(...)
Definition: polytest.cpp:61
_Inout_ PVOID Segment
Definition: exfuncs.h:893
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
struct _MEMORY_AREA::@1743::@1744 SectionData
NTSTATUS NTAPI MmCreateMemoryArea(PMMSUPPORT AddressSpace, ULONG Type, PVOID *BaseAddress, SIZE_T Length, ULONG Protection, PMEMORY_AREA *Result, ULONG AllocationFlags, ULONG AllocationGranularity)
Definition: marea.c:410
#define PAGE_SIZE
Definition: env_spec_w32.h:49
_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 AllocationType
Definition: mmfuncs.h:404
Status
Definition: gdiplustypes.h:24
FORCEINLINE PEPROCESS MmGetAddressSpaceOwner(IN PMMSUPPORT AddressSpace)
Definition: mm.h:1438
VOID NTAPI MmInitializeRegion(PLIST_ENTRY RegionListHead, SIZE_T Length, ULONG Type, ULONG Protect)
Definition: region.c:239
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T _Inout_opt_ PLARGE_INTEGER _Inout_ PSIZE_T ViewSize
Definition: mmfuncs.h:404
return STATUS_SUCCESS
Definition: btrfs.c:2938
NTSTATUS NTAPI MmPageOutPageFileView(PMMSUPPORT AddressSpace, PMEMORY_AREA MemoryArea, PVOID Address, PMM_REQUIRED_RESOURCES Required)
#define MM_ALLOCATION_GRANULARITY
Definition: mmtypes.h:36
LONGLONG QuadPart
Definition: typedefs.h:112
Definition: fci.c:126

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 
)

Definition at line 205 of file io.c.

212 {
214  PIRP Irp = NULL;
215  KEVENT ReadWait;
218 
221  ASSERT(Buffer);
223 
226 
227  DPRINT("PAGING WRITE: FileObject %p <%wZ> Offset 0x%I64x Length %lu (%s:%d)\n",
228  FileObject,
229  &FileObject->FileName,
230  FileOffset->QuadPart,
231  Length,
232  File,
233  Line);
234 
236 
238  DeviceObject,
239  Buffer,
240  Length,
241  FileOffset,
242  ReadStatus);
243 
244  if (!Irp)
245  {
246  return STATUS_NO_MEMORY;
247  }
248 
250 
251  Irp->UserEvent = &ReadWait;
252  Irp->Tail.Overlay.OriginalFileObject = FileObject;
253  Irp->Tail.Overlay.Thread = PsGetCurrentThread();
257  IrpSp->CompletionRoutine = MiSimpleReadComplete;
258 
259  DPRINT("Call Driver\n");
261  DPRINT("Status %x\n", Status);
262 
263  if (Status == STATUS_PENDING)
264  {
265  DPRINT("KeWaitForSingleObject(&ReadWait)\n");
266  if (!NT_SUCCESS(KeWaitForSingleObject(&ReadWait,
267  Suspended,
268  KernelMode,
269  FALSE,
270  NULL)))
271  {
272  DPRINT1("Warning: Failed to wait for synchronous IRP\n");
273  ASSERT(FALSE);
274  return Status;
275  }
276  }
277 
278  DPRINT("Paging IO Done: %08x\n", ReadStatus->Status);
279  return ReadStatus->Status;
280 }
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
_In_ PIRP Irp
Definition: csq.h:116
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
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
Definition: bufpool.h:45
PDEVICE_OBJECT NTAPI MmGetDeviceObjectForFile(IN PFILE_OBJECT FileObject)
Definition: io.c:62
PIO_COMPLETION_ROUTINE CompletionRoutine
Definition: iotypes.h:2958
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
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
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define SL_INVOKE_ON_ERROR
Definition: iotypes.h:2973
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Definition: ncftp.h:79
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2647
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define SL_INVOKE_ON_SUCCESS
Definition: iotypes.h:2972
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:151
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
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_SYNCHRONOUS_API
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
static USHORT ReadStatus(PUCHAR ReadDataPort)
Definition: hardware.c:116
Definition: File.h:15
#define IRP_SYNCHRONOUS_PAGING_IO

◆ _MiWriteBackPage()

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

Definition at line 296 of file io.c.

302 {
304  PVOID Hyperspace;
306  KIRQL OldIrql;
308 
309  if (!PageBuffer) return STATUS_NO_MEMORY;
310 
311  Hyperspace = MiMapPageInHyperSpace(PsGetCurrentProcess(), Page, &OldIrql);
312  if (!Hyperspace)
313  {
314  ExFreePool(PageBuffer);
315  return STATUS_NO_MEMORY;
316  }
317  RtlCopyMemory(PageBuffer, Hyperspace, PAGE_SIZE);
319 
320  DPRINT("MiWriteBackPage(%wZ,%08x%08x,%s:%d)\n",
321  &FileObject->FileName,
322  FileOffset->u.HighPart,
323  FileOffset->u.LowPart,
324  File,
325  Line);
326 
328  FileOffset,
329  PageBuffer,
330  Length,
331  &Iosb);
332 
333  ExFreePool(PageBuffer);
334 
335  if (!NT_SUCCESS(Status))
336  {
337  DPRINT1("MiSimpleWrite failed (%x)\n", Status);
338  }
339 
340  return Status;
341 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
LONG NTSTATUS
Definition: precomp.h:26
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define PsGetCurrentProcess
Definition: psfuncs.h:17
PVOID NTAPI MiMapPageInHyperSpace(IN PEPROCESS Process, IN PFN_NUMBER Page, IN PKIRQL OldIrql)
Definition: hypermap.c:30
void DPRINT(...)
Definition: polytest.cpp:61
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
return Iosb
Definition: create.c:4426
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
Definition: ncftp.h:79
VOID NTAPI MiUnmapPageInHyperSpace(IN PEPROCESS Process, IN PVOID Address, IN KIRQL OldIrql)
Definition: hypermap.c:93
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
#define MiSimpleWrite(F, O, B, L, R)
Definition: newmm.h:198
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
#define PAGE_SIZE
Definition: env_spec_w32.h:49
Status
Definition: gdiplustypes.h:24
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:151
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
#define DPRINT1
Definition: precomp.h:8
Definition: File.h:15
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

◆ _MmGetPageEntrySectionSegment()

ULONG_PTR NTAPI _MmGetPageEntrySectionSegment ( PMM_SECTION_SEGMENT  Segment,
PLARGE_INTEGER  Offset,
const char file,
int  line 
)

Definition at line 237 of file sptab.c.

241 {
243  ULONG_PTR PageIndex, Result;
245 
246  ASSERT(Segment->Locked);
247  FileOffset.QuadPart = ROUND_DOWN(Offset->QuadPart,
250  if (!PageTable) return 0;
251  PageIndex = (ULONG_PTR)((Offset->QuadPart - PageTable->FileOffset.QuadPart) / PAGE_SIZE);
252  Result = PageTable->PageEntries[PageIndex];
253 #if 0
254  DPRINTC
255  ("MiGetPageEntrySectionSegment(%p,%08x%08x) => %x %s:%d\n",
256  Segment,
257  FileOffset.u.HighPart,
258  FileOffset.u.LowPart + PageIndex * PAGE_SIZE,
259  Result,
260  file, line);
261 #endif
262  return Result;
263 }
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
uint32_t ULONG_PTR
Definition: typedefs.h:63
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
_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
Definition: parser.c:48
_Inout_ PVOID Segment
Definition: exfuncs.h:893
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define ROUND_DOWN(n, align)
Definition: eventvwr.h:30
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:151
#define ULONG_PTR
Definition: config.h:101
#define DPRINTC
Definition: sptab.c:61
#define ENTRIES_PER_ELEMENT
Definition: newmm.h:49
Definition: fci.c:126

◆ _MmLockSectionSegment()

VOID NTAPI _MmLockSectionSegment ( PMM_SECTION_SEGMENT  Segment,
const char file,
int  line 
)

Definition at line 98 of file data.c.

99 {
100  //DPRINT("MmLockSectionSegment(%p,%s:%d)\n", Segment, file, line);
101  ExAcquireFastMutex(&Segment->Lock);
102  Segment->Locked = TRUE;
103 }
#define TRUE
Definition: types.h:120
_Inout_ PVOID Segment
Definition: exfuncs.h:893
VOID FASTCALL ExAcquireFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:23

◆ _MmSetPageEntrySectionSegment()

NTSTATUS NTAPI _MmSetPageEntrySectionSegment ( PMM_SECTION_SEGMENT  Segment,
PLARGE_INTEGER  Offset,
ULONG_PTR  Entry,
const char file,
int  line 
)

Definition at line 178 of file sptab.c.

183 {
184  ULONG_PTR PageIndex, OldEntry;
186 
187  ASSERT(Segment->Locked);
189 
190  if (Entry && !IS_SWAP_FROM_SSE(Entry))
192 
194 
195  if (!PageTable) return STATUS_NO_MEMORY;
196 
198 
199  PageTable->Segment = Segment;
200  PageIndex = (ULONG_PTR)((Offset->QuadPart - PageTable->FileOffset.QuadPart) / PAGE_SIZE);
201  OldEntry = PageTable->PageEntries[PageIndex];
202 
203  DPRINT("MiSetPageEntrySectionSegment(%p,%08x%08x,%x=>%x)\n",
204  Segment,
205  Offset->u.HighPart,
206  Offset->u.LowPart,
207  OldEntry,
208  Entry);
209 
210  if (PFN_FROM_SSE(Entry) == PFN_FROM_SSE(OldEntry)) {
211  /* Nothing */
212  } else if (Entry && !IS_SWAP_FROM_SSE(Entry)) {
213  ASSERT(!OldEntry || IS_SWAP_FROM_SSE(OldEntry));
215  } else if (OldEntry && !IS_SWAP_FROM_SSE(OldEntry)) {
218  } else if (IS_SWAP_FROM_SSE(Entry)) {
219  ASSERT(!IS_SWAP_FROM_SSE(OldEntry) ||
220  SWAPENTRY_FROM_SSE(OldEntry) == MM_WAIT_ENTRY);
221  if (OldEntry && SWAPENTRY_FROM_SSE(OldEntry) != MM_WAIT_ENTRY)
223  } else if (IS_SWAP_FROM_SSE(OldEntry)) {
225  if (Entry)
227  } else {
228  /* We should not be replacing a page like this */
229  ASSERT(FALSE);
230  }
231  PageTable->PageEntries[PageIndex] = Entry;
232  return STATUS_SUCCESS;
233 }
#define IS_DIRTY_SSE(E)
Definition: newmm.h:16
struct _Entry Entry
Definition: kefuncs.h:640
#define PFN_FROM_SSE(E)
Definition: newmm.h:7
static PMEM_HOOK PageTable[TOTAL_PAGES]
Definition: memory.c:40
struct _MM_RMAP_ENTRY *NTAPI MmGetRmapListHeadPage(PFN_NUMBER Page)
Definition: freelist.c:427
static PCACHE_SECTION_PAGE_TABLE NTAPI MiSectionPageTableGet(PRTL_GENERIC_TABLE Table, PLARGE_INTEGER FileOffset)
Definition: sptab.c:117
#define MM_WAIT_ENTRY
Definition: mm.h:152
static PCACHE_SECTION_PAGE_TABLE NTAPI MiSectionPageTableGetOrAllocate(PRTL_GENERIC_TABLE Table, PLARGE_INTEGER FileOffset)
Definition: sptab.c:136
uint32_t ULONG_PTR
Definition: typedefs.h:63
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
VOID NTAPI MmDeleteSectionAssociation(PFN_NUMBER Page)
Definition: rmap.c:484
void DPRINT(...)
Definition: polytest.cpp:61
_Inout_ PVOID Segment
Definition: exfuncs.h:893
#define SWAPENTRY_FROM_SSE(E)
Definition: newmm.h:12
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
NTSTATUS NTAPI MmSetSectionAssociation(PFN_NUMBER Page, PMM_SECTION_SEGMENT Segment, PLARGE_INTEGER Offset)
Definition: sptab.c:352
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define IS_SWAP_FROM_SSE(E)
Definition: newmm.h:8
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
#define ULONG_PTR
Definition: config.h:101
return STATUS_SUCCESS
Definition: btrfs.c:2938
base of all file and directory entries
Definition: entries.h:82

◆ _MmTryToLockAddressSpace()

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

Definition at line 364 of file newmm.h.

367 {
369  //DbgPrint("(%s:%d) Try Lock Address Space %x -> %s\n", file, line, AddressSpace, Result ? "true" : "false");
370  return Result;
371 }
_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

◆ _MmUnlockSectionSegment()

VOID NTAPI _MmUnlockSectionSegment ( PMM_SECTION_SEGMENT  Segment,
const char file,
int  line 
)

Definition at line 107 of file data.c.

108 {
109  ASSERT(Segment->Locked);
110  Segment->Locked = FALSE;
111  ExReleaseFastMutex(&Segment->Lock);
112  //DPRINT("MmUnlockSectionSegment(%p,%s:%d)\n", Segment, file, line);
113 }
VOID FASTCALL ExReleaseFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:31
_Inout_ PVOID Segment
Definition: exfuncs.h:893
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)

◆ _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;
596  PFN_NUMBER Page;
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)) {
612  Page = PFN_FROM_SSE(Entry);
615  if (NT_SUCCESS(Status))
616  Result++;
618  }
619  }
620  }
621 
623 
624  return Result;
625 }
struct _Entry Entry
Definition: kefuncs.h:640
#define PFN_FROM_SSE(E)
Definition: newmm.h:7
NTSYSAPI ULONG NTAPI RtlNumberGenericTableElements(_In_ PRTL_GENERIC_TABLE Table)
LONG NTSTATUS
Definition: precomp.h:26
uint32_t ULONG_PTR
Definition: typedefs.h:63
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
ULONG PFN_NUMBER
Definition: ke.h:8
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
_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
_Inout_ PVOID Segment
Definition: exfuncs.h:893
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
#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:55
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define IS_SWAP_FROM_SSE(E)
Definition: newmm.h:8
Status
Definition: gdiplustypes.h:24
#define MmLockSectionSegment(x)
Definition: newmm.h:276
unsigned int ULONG
Definition: retypes.h:1
#define MmUnlockSectionSegment(x)
Definition: newmm.h:284
base of all file and directory entries
Definition: entries.h:82
#define MmGetPageEntrySectionSegment(S, O)
Definition: newmm.h:143
NTSTATUS NTAPI MmpPageOutPhysicalAddress(PFN_NUMBER Page)
Definition: swapout.c:345
#define ENTRIES_PER_ELEMENT
Definition: newmm.h:49

Referenced by MiRosTrimCache().

◆ MiFreeSegmentPage()

VOID NTAPI MiFreeSegmentPage ( PMM_SECTION_SEGMENT  Segment,
PLARGE_INTEGER  FileOffset 
)

Definition at line 616 of file data.c.

618 {
620  PFILE_OBJECT FileObject = Segment->FileObject;
621 
623  DPRINTC("MiFreeSegmentPage(%p:%I64x -> Entry %Ix\n",
624  Segment,
625  FileOffset->QuadPart,
626  Entry);
627 
628  if (Entry && !IS_SWAP_FROM_SSE(Entry))
629  {
630  // The segment is carrying a dirty page.
631  PFN_NUMBER OldPage = PFN_FROM_SSE(Entry);
632  if (IS_DIRTY_SSE(Entry) && FileObject)
633  {
634  DPRINT("MiWriteBackPage(%p,%wZ,%I64x)\n",
635  Segment,
636  &FileObject->FileName,
637  FileOffset->QuadPart);
638 
640  }
641  DPRINTC("Free page %Ix (off %I64x from %p) (ref ct %lu, ent %Ix, dirty? %s)\n",
642  OldPage,
643  FileOffset->QuadPart,
644  Segment,
645  MmGetReferenceCountPage(OldPage),
646  Entry,
647  IS_DIRTY_SSE(Entry) ? "true" : "false");
648 
651  }
652  else if (IS_SWAP_FROM_SSE(Entry))
653  {
654  DPRINT("Free swap\n");
656  }
657 
658  DPRINT("Done\n");
659 }
#define MmSetPageEntrySectionSegment(S, O, E)
Definition: newmm.h:141
#define DPRINTC
Definition: data.c:84
#define IS_DIRTY_SSE(E)
Definition: newmm.h:16
struct _Entry Entry
Definition: kefuncs.h:640
#define PFN_FROM_SSE(E)
Definition: newmm.h:7
NTSTATUS NTAPI MmReleasePageMemoryConsumer(ULONG Consumer, PFN_NUMBER Page)
Definition: balance.c:97
uint32_t ULONG_PTR
Definition: typedefs.h:63
ULONG PFN_NUMBER
Definition: ke.h:8
void DPRINT(...)
Definition: polytest.cpp:61
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
_Inout_ PVOID Segment
Definition: exfuncs.h:893
#define SWAPENTRY_FROM_SSE(E)
Definition: newmm.h:12
* PFILE_OBJECT
Definition: iotypes.h:1955
ULONG NTAPI MmGetReferenceCountPage(PFN_NUMBER Page)
Definition: freelist.c:509
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define IS_SWAP_FROM_SSE(E)
Definition: newmm.h:8
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:151
#define MC_CACHE
Definition: mm.h:93
base of all file and directory entries
Definition: entries.h:82
#define MmGetPageEntrySectionSegment(S, O)
Definition: newmm.h:143
VOID NTAPI MmFreeSwapPage(SWAPENTRY Entry)
Definition: pagefile.c:278
#define MiWriteBackPage(F, O, L, P)
Definition: newmm.h:209

Referenced by MmFinalizeSegment().

◆ 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:97
NTSTATUS NTAPI MmRequestPageMemoryConsumer(ULONG Consumer, BOOLEAN MyWait, PPFN_NUMBER AllocatedPage)
Definition: balance.c:229
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 NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
#define DPRINTC
Definition: reqtools.c:59
unsigned int ULONG
Definition: retypes.h:1
struct _MEMORY_AREA struct _MM_REQUIRED_RESOURCES * Required
Definition: newmm.h:66
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by MiCowCacheSectionPage().

◆ 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
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
_Inout_ PVOID Segment
Definition: exfuncs.h:893

Referenced by ExeFmtpCreateImageSection(), MmCreateCacheSection(), MmCreateDataFileSection(), and MmCreatePageFileSection().

◆ 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 
164  MmBuildMdlFromPages(Mdl, Page);
165  Mdl->MdlFlags |= MDL_PAGES_LOCKED;
166 
168  Status = IoPageRead(FileObject, Mdl, FileOffset, &Event, &IOSB);
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 
179  PageBuf = MiMapPageInHyperSpace(PsGetCurrentProcess(), *Page, &OldIrql);
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 TRUE
Definition: types.h:120
#define MmInitializeMdl(_MemoryDescriptorList, _BaseVa, _Length)
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI MmReleasePageMemoryConsumer(ULONG Consumer, PFN_NUMBER Page)
Definition: balance.c:97
NTSTATUS NTAPI MmRequestPageMemoryConsumer(ULONG Consumer, BOOLEAN MyWait, PPFN_NUMBER AllocatedPage)
Definition: balance.c:229
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:8
PFN_NUMBER Page[2]
Definition: newmm.h:90
VOID NTAPI MmUnmapLockedPages(IN PVOID BaseAddress, IN PMDL Mdl)
Definition: mdlsup.c:841
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:435
#define PsGetCurrentProcess
Definition: psfuncs.h:17
PVOID NTAPI MiMapPageInHyperSpace(IN PEPROCESS Process, IN PFN_NUMBER Page, IN PKIRQL OldIrql)
Definition: hypermap.c:30
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#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:98
* PFILE_OBJECT
Definition: iotypes.h:1955
VOID NTAPI MiUnmapPageInHyperSpace(IN PEPROCESS Process, IN PVOID Address, IN KIRQL OldIrql)
Definition: hypermap.c:93
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:803
#define PAGE_SIZE
Definition: env_spec_w32.h:49
Status
Definition: gdiplustypes.h:24
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:151
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
#define DPRINT1
Definition: precomp.h:8
#define DPRINTC
Definition: reqtools.c:59
LARGE_INTEGER FileOffset
Definition: newmm.h:88
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by MmNotPresentFaultCachePage().

◆ 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:640
#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:893
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
_Must_inspect_result_ typedef _In_ ULONG _In_ BOOLEAN Target
Definition: iotypes.h:1068
LIST_ENTRY MiSegmentList
Definition: data.c:86
Definition: typedefs.h:117
ULONG NTAPI MiCacheEvictPages(PMM_SECTION_SEGMENT Segment, ULONG Target)
Definition: swapout.c:590
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2938
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 114 of file io.c.

120 {
122  PIRP Irp = NULL;
123  KEVENT ReadWait;
126 
129  ASSERT(Buffer);
131 
134  ReadStatus->Information = 0;
135 
137 
138  DPRINT("PAGING READ: FileObject %p <%wZ> Offset %08x%08x Length %ul\n",
139  FileObject,
140  &FileObject->FileName,
141  FileOffset->HighPart,
142  FileOffset->LowPart,
143  Length);
144 
146 
148  DeviceObject,
149  Buffer,
150  Length,
151  FileOffset,
152  ReadStatus);
153 
154  if (!Irp)
155  {
156  return STATUS_NO_MEMORY;
157  }
158 
160 
161  Irp->UserEvent = &ReadWait;
162  Irp->Tail.Overlay.OriginalFileObject = FileObject;
163  Irp->Tail.Overlay.Thread = PsGetCurrentThread();
167  IrpSp->CompletionRoutine = MiSimpleReadComplete;
168 
169  /* Non paging case, the FileObject will be dereferenced at completion */
170  if (!Paging)
172 
174  if (Status == STATUS_PENDING)
175  {
176  DPRINT("KeWaitForSingleObject(&ReadWait)\n");
177  if (!NT_SUCCESS(KeWaitForSingleObject(&ReadWait,
178  Suspended,
179  KernelMode,
180  FALSE,
181  NULL)))
182  {
183  DPRINT1("Warning: Failed to wait for synchronous IRP\n");
184  ASSERT(FALSE);
185  return Status;
186  }
187  }
188 
189  DPRINT("Paging IO Done: %08x\n", ReadStatus->Status);
190  /* When "ReadStatus->Information > 0" is false and "ReadStatus->Status == STATUS_END_OF_FILE" is true
191  * it means that read pointer is out of file, so we must fail */
192  Status = ReadStatus->Status == STATUS_END_OF_FILE && ReadStatus->Information > 0 ? STATUS_SUCCESS : ReadStatus->Status;
193  return Status;
194 }
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
_In_ PIRP Irp
Definition: csq.h:116
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:451
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
Definition: bufpool.h:45
PDEVICE_OBJECT NTAPI MmGetDeviceObjectForFile(IN PFILE_OBJECT FileObject)
Definition: io.c:62
PIO_COMPLETION_ROUTINE CompletionRoutine
Definition: iotypes.h:2958
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
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
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define SL_INVOKE_ON_ERROR
Definition: iotypes.h:2973
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2647
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define SL_INVOKE_ON_SUCCESS
Definition: iotypes.h:2972
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:151
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
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
static USHORT ReadStatus(PUCHAR ReadDataPort)
Definition: hardware.c:116
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define IRP_SYNCHRONOUS_PAGING_IO

Referenced by CcZeroData(), ExeFmtpReadFile(), and KdbpReadSymFile().

◆ 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:229
NTSTATUS NTAPI MmReadFromSwapPage(SWAPENTRY SwapEntry, PFN_NUMBER Page)
Definition: pagefile.c:194
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
#define DPRINT1
Definition: precomp.h:8
VOID NTAPI MmSetSavedSwapEntryPage(PFN_NUMBER Page, SWAPENTRY SavedSwapEntry)
Definition: freelist.c:454

◆ 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:66
#define MiWriteBackPage(F, O, L, P)
Definition: newmm.h:209

◆ 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 
)

Definition at line 688 of file fault.c.

691 {
695 
696  DPRINT("MmpAccessFault(Mode %d, Address %Ix)\n", Mode, Address);
697 
699 
701  {
702  DPRINT1("Page fault at high IRQL %u, address %Ix\n",
704  Address);
705  return STATUS_UNSUCCESSFUL;
706  }
707 
708  /* Find the memory area for the faulting address */
710  {
711  /* Check permissions */
712  if (Mode != KernelMode)
713  {
714  DPRINT1("Address: %p:%Ix\n", PsGetCurrentProcess(), Address);
716  }
718  }
719  else
720  {
722  }
723 
726  AddressSpace,
727  Address,
728  FromMdl,
729  Thread);
731 
732  return Status;
733 }
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
_In_ ULONG Mode
Definition: hubbusif.h:303
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG AddressSpace
Definition: iofuncs.h:2268
LONG NTSTATUS
Definition: precomp.h:26
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define PsGetCurrentProcess
Definition: psfuncs.h:17
static WCHAR Address[46]
Definition: ping.c:68
void DPRINT(...)
Definition: polytest.cpp:61
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
NTSTATUS NTAPI MmpSectionAccessFaultInner(KPROCESSOR_MODE Mode, PMMSUPPORT AddressSpace, ULONG_PTR Address, BOOLEAN FromMdl, PETHREAD Thread)
Definition: fault.c:528
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
Status
Definition: gdiplustypes.h:24
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
FORCEINLINE PMMSUPPORT MmGetKernelAddressSpace(VOID)
Definition: mm.h:1453
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:228
UCHAR ActiveFaultCount
Definition: pstypes.h:1174
#define DPRINT1
Definition: precomp.h:8
#define MmSystemRangeStart
Definition: mm.h:32

Referenced by MmpAccessFault().

◆ MmCreateCacheSection()

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

Definition at line 308 of file data.c.

318 {
319  PROS_SECTION_OBJECT Section;
326  KIRQL OldIrql;
327 
328  DPRINT("MmCreateDataFileSection\n");
329 
330  /* Create the section */
335  NULL,
336  sizeof(ROS_SECTION_OBJECT),
337  0,
338  0,
339  (PVOID*)(PVOID)&Section);
340  if (!NT_SUCCESS(Status))
341  {
342  DPRINT("Failed: %x\n", Status);
344  return Status;
345  }
346 
347  /* Initialize it */
348  RtlZeroMemory(Section, sizeof(ROS_SECTION_OBJECT));
349  Section->Type = 'SC';
350  Section->Size = 'TN';
353  Section->Segment = NULL;
354 
355  Section->FileObject = FileObject;
356 
357  DPRINT("Getting original file size\n");
358  /* A hack: If we're cached, we can overcome deadlocking with the upper
359  * layer filesystem call by retriving the object sizes from the cache
360  * which is made to keep track. If I had to guess, they were figuring
361  * out a similar problem.
362  */
364  {
366  /*
367  * FIXME: This is propably not entirely correct. We can't look into
368  * the standard FCB header because it might not be initialized yet
369  * (as in case of the EXT2FS driver by Manoj Paul Joseph where the
370  * standard file information is filled on first request).
371  */
372  DPRINT("Querying info\n");
376  &FileInfo,
377  &Information);
378  Iosb.Information = Information;
379  DPRINT("Query => %x\n", Status);
381 
382  if (!NT_SUCCESS(Status))
383  {
384  DPRINT("Status %x\n", Status);
385  ObDereferenceObject(Section);
387  return Status;
388  }
390 
391  FileSizes.ValidDataLength = FileInfo.EndOfFile;
392  FileSizes.FileSize = FileInfo.EndOfFile;
393  }
394  DPRINT("Got %I64x\n", FileSizes.ValidDataLength.QuadPart);
395 
396  /*
397  * FIXME: Revise this once a locking order for file size changes is
398  * decided
399  *
400  * We're handed down a maximum size in every case. Should we still check at all?
401  */
402  if (UMaximumSize != NULL && UMaximumSize->QuadPart)
403  {
404  DPRINT("Taking maximum %I64x\n", UMaximumSize->QuadPart);
405  MaximumSize.QuadPart = UMaximumSize->QuadPart;
406  }
407  else
408  {
409  DPRINT("Got file size %I64x\n", FileSizes.FileSize.QuadPart);
411  }
412 
413  /* Mapping zero-sized files isn't allowed. */
414  if (MaximumSize.QuadPart == 0)
415  {
416  DPRINT("Zero size file\n");
417  ObDereferenceObject(Section);
419  return STATUS_FILE_INVALID;
420  }
421 
423  sizeof(MM_SECTION_SEGMENT),
425  if (Segment == NULL)
426  {
427  DPRINT("Failed: STATUS_NO_MEMORY\n");
428  ObDereferenceObject(Section);
430  return STATUS_NO_MEMORY;
431  }
432 
433  DPRINT("Zeroing %p\n", Segment);
436 
437  Segment->ReferenceCount = 1;
438  Segment->Locked = TRUE;
439  RtlZeroMemory(&Segment->Image, sizeof(Segment->Image));
440  Section->Segment = Segment;
441 
442  KeAcquireSpinLock(&FileObject->IrpListLock, &OldIrql);
443  /*
444  * If this file hasn't been mapped as a data file before then allocate a
445  * section segment to describe the data file mapping
446  */
447  if (FileObject->SectionObjectPointer->DataSectionObject == NULL)
448  {
449  FileObject->SectionObjectPointer->DataSectionObject = (PVOID)Segment;
450  KeReleaseSpinLock(&FileObject->IrpListLock, OldIrql);
451 
452  /*
453  * Set the lock before assigning the segment to the file object
454  */
455  ExAcquireFastMutex(&Segment->Lock);
456 
457  DPRINT("Filling out Segment info (No previous data section)\n");
459  Segment->FileObject = FileObject;
460  Segment->Protection = SectionPageProtection;
461  Segment->Flags = MM_DATAFILE_SEGMENT;
462  memset(&Segment->Image, 0, sizeof(Segment->Image));
463  Segment->WriteCopy = FALSE;
464 
466  {
467  Segment->Length.QuadPart = Segment->RawLength.QuadPart = 0;
468  }
469  else
470  {
471  Segment->RawLength.QuadPart = MaximumSize.QuadPart;
472  Segment->Length.QuadPart = PAGE_ROUND_UP(Segment->RawLength.QuadPart);
473  }
475  InsertHeadList(&MiSegmentList, &Segment->ListOfSegments);
476  }
477  else
478  {
479  KeReleaseSpinLock(&FileObject->IrpListLock, OldIrql);
480  DPRINTC("Free Segment %p\n", Segment);
482 
483  DPRINT("Filling out Segment info (previous data section)\n");
484 
485  /*
486  * If the file is already mapped as a data file then we may need
487  * to extend it
488  */
489  Segment = (PMM_SECTION_SEGMENT)FileObject->SectionObjectPointer->DataSectionObject;
490  Section->Segment = Segment;
491  (void)InterlockedIncrementUL(&Segment->ReferenceCount);
492 
494 
495  if (MaximumSize.QuadPart > Segment->RawLength.QuadPart &&
497  {
498  Segment->RawLength.QuadPart = MaximumSize.QuadPart;
499  Segment->Length.QuadPart = PAGE_ROUND_UP(Segment->RawLength.QuadPart);
500  }
501  }
502 
504 
505  Section->MaximumSize.QuadPart = MaximumSize.QuadPart;
506 
507  /* Extend file if section is longer */
508  DPRINT("MaximumSize %I64x ValidDataLength %I64x\n",
509  MaximumSize.QuadPart,
512  {
513  DPRINT("Changing file size to %I64x, segment %p\n",
514  MaximumSize.QuadPart,
515  Segment);
516 
519  sizeof(LARGE_INTEGER),
520  &MaximumSize);
521 
522  DPRINT("Change: Status %x\n", Status);
523  if (!NT_SUCCESS(Status))
524  {
525  DPRINT("Could not expand section\n");
526  ObDereferenceObject(Section);
527  return Status;
528  }
529  }
530 
531  DPRINTC("Segment %p created (%x)\n", Segment, Segment->Flags);
532 
533  *SectionObject = Section;
534  return STATUS_SUCCESS;
535 }
_Must_inspect_result_ _Outptr_ PVOID * SectionObject
Definition: fsrtlfuncs.h:860
#define DPRINTC
Definition: data.c:84
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define TRUE
Definition: types.h:120
LARGE_INTEGER MaximumSize
Definition: mm.h:196
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ ULONG AllocationAttributes
Definition: mmfuncs.h:360
FORCEINLINE VOID InsertHeadList(_Inout_ PLIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PLIST_ENTRY Entry)
Definition: rtlfuncs.h:201
LONG NTSTATUS
Definition: precomp.h:26
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:3066
NTSTATUS NTAPI IoSetInformation(IN PFILE_OBJECT FileObject, IN FILE_INFORMATION_CLASS FileInformationClass, IN ULONG Length, IN PVOID FileInformation)
Definition: iofunc.c:1312
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
static CC_FILE_SIZES FileSizes
#define STATUS_FILE_INVALID
Definition: ntstatus.h:374
#define PAGE_ROUND_UP(x)
Definition: scsiport_int.h:13
NTSTATUS NTAPI IoQueryFileInformation(IN PFILE_OBJECT FileObject, IN FILE_INFORMATION_CLASS FileInformationClass, IN ULONG Length, OUT PVOID FileInformation, OUT PULONG ReturnedLength)
Definition: iofunc.c:1272
BOOLEAN NTAPI CcGetFileSizes(IN PFILE_OBJECT FileObject, IN PCC_FILE_SIZES FileSizes)
Definition: fssup.c:373
LARGE_INTEGER FileSize
Definition: cctypes.h:16
LIST_ENTRY MiSegmentList
Definition: data.c:86
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_opt_ PLARGE_INTEGER _In_ ULONG SectionPageProtection
Definition: mmfuncs.h:360
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define SEC_RESERVE
Definition: nt_native.h:1323
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
void * PVOID
Definition: retypes.h:9
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
_Inout_ PVOID Segment
Definition: exfuncs.h:893
NTSTATUS NTAPI ObCreateObject(IN KPROCESSOR_MODE ProbeMode OPTIONAL, IN POBJECT_TYPE Type, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN KPROCESSOR_MODE AccessMode, IN OUT PVOID ParseContext OPTIONAL, IN ULONG ObjectSize, IN ULONG PagedPoolCharge OPTIONAL, IN ULONG NonPagedPoolCharge OPTIONAL, OUT PVOID *Object)
Definition: oblife.c:952
#define DBG_UNREFERENCED_LOCAL_VARIABLE(L)
Definition: ntbasedef.h:326
PFILE_OBJECT FileObject
Definition: mm.h:199
return Iosb
Definition: create.c:4426
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
CSHORT Type
Definition: mm.h:194
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
#define MM_DATAFILE_SEGMENT
Definition: mm.h:91
POBJECT_TYPE MmSectionObjectType
Definition: section.c:136
struct _MM_SECTION_SEGMENT * PMM_SECTION_SEGMENT
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
LARGE_INTEGER ValidDataLength
Definition: cctypes.h:17
VOID NTAPI MiInitializeSectionPageTable(PMM_SECTION_SEGMENT Segment)
Definition: sptab.c:165
Status
Definition: gdiplustypes.h:24
VOID FASTCALL ExAcquireFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:23
#define TAG_MM_SECTION_SEGMENT
Definition: tag.h:139
#define InterlockedIncrementUL(Addend)
Definition: ex.h:1513
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
ULONG SectionPageProtection
Definition: mm.h:197
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_opt_ PLARGE_INTEGER MaximumSize
Definition: mmfuncs.h:360
#define FileStandardInformation
Definition: propsheet.cpp:61
#define MmLockSectionSegment(x)
Definition: newmm.h:276
#define ObReferenceObject
Definition: obfuncs.h:204
struct FileInfo FileInfo
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
CSHORT Size
Definition: mm.h:195
ULONG AllocationAttributes
Definition: mm.h:198
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define MmUnlockSectionSegment(x)
Definition: newmm.h:284
PMM_SECTION_SEGMENT Segment
Definition: mm.h:203
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define memset(x, y, z)
Definition: compat.h:39
Iosb Information
Definition: create.c:4377
LONGLONG QuadPart
Definition: typedefs.h:112

Referenced by MmCreateSection().

◆ MmDeleteSectionAssociation()

VOID NTAPI MmDeleteSectionAssociation ( PFN_NUMBER  Page)

Definition at line 484 of file rmap.c.

485 {
486  PMM_RMAP_ENTRY current_entry, previous_entry;
487 
489  previous_entry = NULL;
490  current_entry = MmGetRmapListHeadPage(Page);
491  while (current_entry != NULL)
492  {
493  if (RMAP_IS_SEGMENT(current_entry->Address))
494  {
495  if (previous_entry == NULL)
496  {
497  MmSetRmapListHeadPage(Page, current_entry->Next);
498  }
499  else
500  {
501  previous_entry->Next = current_entry->Next;
502  }
504  ExFreeToNPagedLookasideList(&RmapLookasideList, current_entry);
505  return;
506  }
507  previous_entry = current_entry;
508  current_entry = current_entry->Next;
509  }
511 }
struct _MM_RMAP_ENTRY *NTAPI MmGetRmapListHeadPage(PFN_NUMBER Page)
Definition: freelist.c:427
VOID FASTCALL ExReleaseFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:31
smooth NULL
Definition: ftsmooth.c:416
VOID NTAPI MmSetRmapListHeadPage(PFN_NUMBER Page, struct _MM_RMAP_ENTRY *ListHead)
FAST_MUTEX RmapListLock
Definition: rmap.c:26
VOID FASTCALL ExAcquireFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:23
struct _MM_RMAP_ENTRY * Next
Definition: mm.h:238
Definition: mm.h:236
static NPAGED_LOOKASIDE_LIST RmapLookasideList
Definition: rmap.c:25
PVOID Address
Definition: mm.h:240
#define RMAP_IS_SEGMENT(x)
Definition: newmm.h:25

Referenced by _MmSetPageEntrySectionSegment().

◆ MmExtendCacheSection()

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

Definition at line 758 of file data.c.

761 {
762  LARGE_INTEGER OldSize;
764  DPRINT("Extend Segment %p\n", Segment);
765 
767  OldSize.QuadPart = Segment->RawLength.QuadPart;
769 
770  DPRINT("OldSize 0x%I64x NewSize 0x%I64x\n",
771  OldSize.QuadPart,
772  NewSize->QuadPart);
773 
774  if (ExtendFile && OldSize.QuadPart < NewSize->QuadPart)
775  {
777 
778  Status = IoSetInformation(Segment->FileObject,
780  sizeof(LARGE_INTEGER),
781  NewSize);
782 
783  if (!NT_SUCCESS(Status)) return Status;
784  }
785 
787  Segment->RawLength.QuadPart = NewSize->QuadPart;
788  Segment->Length.QuadPart = MAX(Segment->Length.QuadPart,
789  (LONG64)PAGE_ROUND_UP(Segment->RawLength.QuadPart));
791  return STATUS_SUCCESS;
792 }
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI IoSetInformation(IN PFILE_OBJECT FileObject, IN FILE_INFORMATION_CLASS FileInformationClass, IN ULONG Length, IN PVOID FileInformation)
Definition: iofunc.c:1312
#define PAGE_ROUND_UP(x)
Definition: scsiport_int.h:13
void DPRINT(...)
Definition: polytest.cpp:61
_Inout_ PVOID Segment
Definition: exfuncs.h:893
int64_t LONG64
Definition: typedefs.h:66
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_Must_inspect_result_ _In_ USHORT NewSize
Definition: fltkernel.h:975
Status
Definition: gdiplustypes.h:24
T MAX(T a, T b)
Definition: polytest.cpp:85
#define MmLockSectionSegment(x)
Definition: newmm.h:276
#define MmUnlockSectionSegment(x)
Definition: newmm.h:284
PMM_SECTION_SEGMENT Segment
Definition: mm.h:203
return STATUS_SUCCESS
Definition: btrfs.c:2938
LONGLONG QuadPart
Definition: typedefs.h:112

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);
245  MmSetSavedSwapEntryPage(Page, 0);
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 }
#define MmSetPageEntrySectionSegment(S, O, E)
Definition: newmm.h:141
#define TRUE
Definition: types.h:120
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:43
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI MmReleasePageMemoryConsumer(ULONG Consumer, PFN_NUMBER Page)
Definition: balance.c:97
#define MAKE_PFN_SSE(P)
Definition: newmm.h:11
uint32_t ULONG_PTR
Definition: typedefs.h:63
VOID NTAPI MmFinalizeSegment(PMM_SECTION_SEGMENT Segment)
Definition: data.c:271
unsigned char BOOLEAN
void DPRINT(...)
Definition: polytest.cpp:61
_Inout_ PVOID Segment
Definition: exfuncs.h:893
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ULONG NTAPI MmGetReferenceCountPage(PFN_NUMBER Page)
Definition: freelist.c:509
#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:1510
#define PAGE_SIZE
Definition: env_spec_w32.h:49
Status
Definition: gdiplustypes.h:24
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:151
#define InterlockedIncrementUL(Addend)
Definition: ex.h:1513
ULONG_PTR SWAPENTRY
Definition: mm.h:47
#define DPRINT1
Definition: precomp.h:8
#define MmLockSectionSegment(x)
Definition: newmm.h:276
VOID NTAPI MmSetSavedSwapEntryPage(PFN_NUMBER Page, SWAPENTRY SavedSwapEntry)
Definition: freelist.c:454
#define MC_CACHE
Definition: mm.h:93
#define DIRTY_SSE(E)
Definition: newmm.h:14
#define MmUnlockSectionSegment(x)
Definition: newmm.h:284
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define MAKE_SWAP_SSE(S)
Definition: newmm.h:13
SWAPENTRY NTAPI MmGetSavedSwapEntryPage(PFN_NUMBER Page)
Definition: freelist.c:470
#define MiWriteBackPage(F, O, L, P)
Definition: newmm.h:209

Referenced by MmpPageOutPhysicalAddress().

◆ MmFinalizeSegment()

VOID NTAPI MmFinalizeSegment ( PMM_SECTION_SEGMENT  Segment)

Definition at line 271 of file data.c.

272 {
273  KIRQL OldIrql = 0;
274 
275  DPRINT("Finalize segment %p\n", Segment);
276 
278  RemoveEntryList(&Segment->ListOfSegments);
279  if (Segment->Flags & MM_DATAFILE_SEGMENT) {
280  KeAcquireSpinLock(&Segment->FileObject->IrpListLock, &OldIrql);
281  if (Segment->Flags & MM_SEGMENT_FINALIZE) {
282  KeReleaseSpinLock(&Segment->FileObject->IrpListLock, OldIrql);
284  return;
285  }
286  Segment->Flags |= MM_SEGMENT_FINALIZE;
287  DPRINTC("Finalizing data file segment %p\n", Segment);
288 
289  Segment->FileObject->SectionObjectPointer->DataSectionObject = NULL;
290  KeReleaseSpinLock(&Segment->FileObject->IrpListLock, OldIrql);
293  DPRINT("Dereference file object %wZ\n", &Segment->FileObject->FileName);
294  ObDereferenceObject(Segment->FileObject);
295  DPRINT("Done with %wZ\n", &Segment->FileObject->FileName);
296  Segment->FileObject = NULL;
297  } else {
298  DPRINTC("Finalizing segment %p\n", Segment);
301  }
302  DPRINTC("Segment %p destroy\n", Segment);
304 }
#define DPRINTC
Definition: data.c:84
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
UCHAR KIRQL
Definition: env_spec_w32.h:591
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
_Inout_ PVOID Segment
Definition: exfuncs.h:893
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
VOID NTAPI MmFreePageTablesSectionSegment(PMM_SECTION_SEGMENT Segment, FREE_SECTION_PAGE_FUN FreePage)
Definition: sptab.c:278
#define MM_DATAFILE_SEGMENT
Definition: mm.h:91
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
#define MM_SEGMENT_FINALIZE
Definition: newmm.h:22
#define TAG_MM_SECTION_SEGMENT
Definition: tag.h:139
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define MmLockSectionSegment(x)
Definition: newmm.h:276
VOID NTAPI MiFreeSegmentPage(PMM_SECTION_SEGMENT Segment, PLARGE_INTEGER FileOffset)
Definition: data.c:616
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define MmUnlockSectionSegment(x)
Definition: newmm.h:284

Referenced by MmFinalizeSectionPageOut(), MmpDeleteSection(), and MmpPageOutPhysicalAddress().

◆ MmFreeCacheSectionPage()

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

Definition at line 662 of file data.c.

668 {
670  PVOID *ContextData = Context;
675 
676  DPRINT("MmFreeSectionPage(%p,%p,%Ix,%Ix,%u)\n",
677  MmGetAddressSpaceOwner(ContextData[0]),
678  Address,
679  Page,
680  SwapEntry,
681  Dirty);
682 
683  AddressSpace = ContextData[0];
686  Segment = ContextData[1];
688  MemoryArea->Data.SectionData.ViewOffset.QuadPart;
689 
691 
692  if (Page != 0 && PFN_FROM_SSE(Entry) == Page && Dirty)
693  {
694  DPRINT("Freeing section page %p:%I64x -> %Ix\n", Segment, Offset.QuadPart, Entry);
696  }
697  if (Page)
698  {
699  DPRINT("Removing page %p:%I64x -> %x\n", Segment, Offset.QuadPart, Entry);
700  MmSetSavedSwapEntryPage(Page, 0);
701  MmDeleteRmap(Page, Process, Address);
704  }
705  if (SwapEntry != 0)
706  {
707  MmFreeSwapPage(SwapEntry);
708  }
709 }
#define MmSetPageEntrySectionSegment(S, O, E)
Definition: newmm.h:141
struct _Entry Entry
Definition: kefuncs.h:640
#define PFN_FROM_SSE(E)
Definition: newmm.h:7
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:97
#define PAGE_ROUND_DOWN(x)
Definition: mmtypes.h:36
uint32_t ULONG_PTR
Definition: typedefs.h:63
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
union _MEMORY_AREA::@1743 Data
smooth NULL
Definition: ftsmooth.c:416
static WCHAR Address[46]
Definition: ping.c:68
VOID NTAPI MmDeleteVirtualMapping(struct _EPROCESS *Process, PVOID Address, BOOLEAN *WasDirty, PPFN_NUMBER Page)
void DPRINT(...)
Definition: polytest.cpp:61
void * PVOID
Definition: retypes.h:9
_Inout_ PVOID Segment
Definition: exfuncs.h:893
struct _MEMORY_AREA::@1743::@1744 SectionData
#define MA_GetStartingAddress(_MemoryArea)
Definition: mm.h:207
FORCEINLINE PEPROCESS MmGetAddressSpaceOwner(IN PMMSUPPORT AddressSpace)
Definition: mm.h:1438
VOID NTAPI MmSetSavedSwapEntryPage(PFN_NUMBER Page, SWAPENTRY SavedSwapEntry)
Definition: freelist.c:454
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
#define MC_CACHE
Definition: mm.h:93
#define DIRTY_SSE(E)
Definition: newmm.h:14
struct tagContext Context
Definition: acpixf.h:1030
#define ULONG_PTR
Definition: config.h:101
base of all file and directory entries
Definition: entries.h:82
#define MmGetPageEntrySectionSegment(S, O)
Definition: newmm.h:143
VOID NTAPI MmFreeSwapPage(SWAPENTRY Entry)
Definition: pagefile.c:278

Referenced by MmUnmapViewOfCacheSegment().

◆ MmFreePageTablesSectionSegment()

VOID NTAPI MmFreePageTablesSectionSegment ( PMM_SECTION_SEGMENT  Segment,
FREE_SECTION_PAGE_FUN  FreePage 
)

Definition at line 278 of file sptab.c.

280 {
282  DPRINT("MiFreePageTablesSectionSegment(%p)\n", &Segment->PageTable);
283  while ((Element = RtlGetElementGenericTable(&Segment->PageTable, 0))) {
284  DPRINT("Delete table for <%wZ> %p -> %I64x\n",
285  Segment->FileObject ? &Segment->FileObject->FileName : NULL,
286  Segment,
287  Element->FileOffset.QuadPart);
288  if (FreePage)
289  {
290  ULONG i;
291  for (i = 0; i < ENTRIES_PER_ELEMENT; i++)
292  {
295  Offset.QuadPart = Element->FileOffset.QuadPart + i * PAGE_SIZE;
296  Entry = Element->PageEntries[i];
297  if (Entry && !IS_SWAP_FROM_SSE(Entry))
298  {
299  DPRINT("Freeing page %p:%Ix @ %I64x\n",
300  Segment,
301  Entry,
302  Offset.QuadPart);
303 
305  }
306  }
307  }
308  DPRINT("Remove memory\n");
309  RtlDeleteElementGenericTable(&Segment->PageTable, Element);
310  }
311  DPRINT("Done\n");
312 }
struct _Entry Entry
Definition: kefuncs.h:640
uint32_t ULONG_PTR
Definition: typedefs.h:63
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
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
ULONG_PTR PageEntries[ENTRIES_PER_ELEMENT]
Definition: newmm.h:58
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
_Inout_ PVOID Segment
Definition: exfuncs.h:893
_Must_inspect_result_ NTSYSAPI PVOID NTAPI RtlGetElementGenericTable(_In_ PRTL_GENERIC_TABLE Table, _In_ ULONG I)
LARGE_INTEGER FileOffset
Definition: newmm.h:55
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define IS_SWAP_FROM_SSE(E)
Definition: newmm.h:8
NTSYSAPI BOOLEAN NTAPI RtlDeleteElementGenericTable(_In_ PRTL_GENERIC_TABLE Table, _In_ PVOID Buffer)
unsigned int ULONG
Definition: retypes.h:1
base of all file and directory entries
Definition: entries.h:82
LONGLONG QuadPart
Definition: typedefs.h:112
#define ENTRIES_PER_ELEMENT
Definition: newmm.h:49

Referenced by MmFinalizeSegment(), MmFreeSectionSegments(), and MmpDeleteSection().

◆ MmFreeSectionSegments()

VOID NTAPI MmFreeSectionSegments ( PFILE_OBJECT  FileObject)

Definition at line 807 of file section.c.

808 {
809  if (FileObject->SectionObjectPointer->ImageSectionObject != NULL)
810  {
811  PMM_IMAGE_SECTION_OBJECT ImageSectionObject;
812  PMM_SECTION_SEGMENT SectionSegments;
813  ULONG NrSegments;
814  ULONG i;
815 
816  ImageSectionObject = (PMM_IMAGE_SECTION_OBJECT)FileObject->SectionObjectPointer->ImageSectionObject;
817  NrSegments = ImageSectionObject->NrSegments;
818  SectionSegments = ImageSectionObject->Segments;
819  for (i = 0; i < NrSegments; i++)
820  {
821  if (SectionSegments[i].ReferenceCount != 0)
822  {
823  DPRINT1("Image segment %lu still referenced (was %lu)\n", i,
824  SectionSegments[i].ReferenceCount);
825  KeBugCheck(MEMORY_MANAGEMENT);
826  }
827  MmFreePageTablesSectionSegment(&SectionSegments[i], NULL);
828  }
829  ExFreePool(ImageSectionObject->Segments);
830  ExFreePool(ImageSectionObject);
831  FileObject->SectionObjectPointer->ImageSectionObject = NULL;
832  }
833  if (FileObject->SectionObjectPointer->DataSectionObject != NULL)
834  {
836 
837  Segment = (PMM_SECTION_SEGMENT)FileObject->SectionObjectPointer->
838  DataSectionObject;
839 
840  if (Segment->ReferenceCount != 0)
841  {
842  DPRINT1("Data segment still referenced\n");
843  KeBugCheck(MEMORY_MANAGEMENT);
844  }
847  FileObject->SectionObjectPointer->DataSectionObject = NULL;
848  }
849 }
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
smooth NULL
Definition: ftsmooth.c:416
VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1507
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
_Inout_ PVOID Segment
Definition: exfuncs.h:893
struct _MM_IMAGE_SECTION_OBJECT * PMM_IMAGE_SECTION_OBJECT
if(!(yy_init))
Definition: macro.lex.yy.c:714
PMM_SECTION_SEGMENT Segments
Definition: mm.h:189
VOID NTAPI MmFreePageTablesSectionSegment(PMM_SECTION_SEGMENT Segment, FREE_SECTION_PAGE_FUN FreePage)
Definition: sptab.c:278
#define for
Definition: utility.h:88
struct _MM_SECTION_SEGMENT * PMM_SECTION_SEGMENT
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by CcRosDereferenceCache(), and CcRosReleaseFileCache().

◆ MmGetSectionAssociation()

PMM_SECTION_SEGMENT NTAPI MmGetSectionAssociation ( PFN_NUMBER  Page,
PLARGE_INTEGER  Offset 
)

Definition at line 331 of file sptab.c.

333 {
334  ULONG RawOffset;
337 
339  &RawOffset);
340  if (PageTable)
341  {
342  Segment = PageTable->Segment;
343  Offset->QuadPart = PageTable->FileOffset.QuadPart +
344  ((ULONG64)RawOffset << PAGE_SHIFT);
345  }
346 
347  return Segment;
348 }
#define PAGE_SHIFT
Definition: env_spec_w32.h:45
PVOID NTAPI MmGetSegmentRmap(PFN_NUMBER Page, PULONG RawOffset)
Definition: rmap.c:451
static PMEM_HOOK PageTable[TOTAL_PAGES]
Definition: memory.c:40
struct _CACHE_SECTION_PAGE_TABLE * PCACHE_SECTION_PAGE_TABLE
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
smooth NULL
Definition: ftsmooth.c:416
_Inout_ PVOID Segment
Definition: exfuncs.h:893
unsigned __int64 ULONG64
Definition: imports.h:198
unsigned int ULONG
Definition: retypes.h:1

Referenced by MmpPageOutPhysicalAddress().

◆ MmGetSegmentRmap()

PVOID NTAPI MmGetSegmentRmap ( PFN_NUMBER  Page,
PULONG  RawOffset 
)

Definition at line 451 of file rmap.c.

452 {
454  PMM_RMAP_ENTRY current_entry;//, previous_entry;
455 
457  //previous_entry = NULL;
458  current_entry = MmGetRmapListHeadPage(Page);
459  while (current_entry != NULL)
460  {
461  if (RMAP_IS_SEGMENT(current_entry->Address))
462  {
463  Result = (PCACHE_SECTION_PAGE_TABLE)current_entry->Process;
464  *RawOffset = (ULONG_PTR)current_entry->Address & ~RMAP_SEGMENT_MASK;
465  InterlockedIncrementUL(&Result->Segment->ReferenceCount);
467  return Result;
468  }
469  //previous_entry = current_entry;
470  current_entry = current_entry->Next;
471  }
473  return NULL;
474 }
PEPROCESS Process
Definition: mm.h:239
struct _MM_RMAP_ENTRY *NTAPI MmGetRmapListHeadPage(PFN_NUMBER Page)
Definition: freelist.c:427
#define RMAP_SEGMENT_MASK
Definition: newmm.h:24
struct _CACHE_SECTION_PAGE_TABLE * PCACHE_SECTION_PAGE_TABLE
VOID FASTCALL ExReleaseFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:31
uint32_t ULONG_PTR
Definition: typedefs.h:63
smooth NULL
Definition: ftsmooth.c:416
_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
FAST_MUTEX RmapListLock
Definition: rmap.c:26
VOID FASTCALL ExAcquireFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:23
#define InterlockedIncrementUL(Addend)
Definition: ex.h:1513
struct _MM_RMAP_ENTRY * Next
Definition: mm.h:238
Definition: mm.h:236
PVOID Address
Definition: mm.h:240
#define RMAP_IS_SEGMENT(x)
Definition: newmm.h:25

Referenced by MmGetSectionAssociation().

◆ MmMapCacheViewInSystemSpaceAtOffset()

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

◆ MmNotPresentFaultCacheSection()

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

Definition at line 907 of file fault.c.

910 {
914 
915  Address &= ~(PAGE_SIZE - 1);
916  DPRINT("MmNotPresentFault(Mode %d, Address %Ix)\n", Mode, Address);
917 
919 
921  {
922  DPRINT1("Page fault at high IRQL %u, address %Ix\n",
924  Address);
925 
926  ASSERT(FALSE);
927  return STATUS_UNSUCCESSFUL;
928  }
929 
930  /* Find the memory area for the faulting address */
932  {
933  /* Check permissions */
934  if (Mode != KernelMode)
935  {
936  DPRINTC("Address: %x\n", Address);
938  }
940  }
941  else
942  {
944  }
945 
948  AddressSpace,
949  Address,
950  FromMdl,
951  Thread);
953 
956  DPRINT("MmAccessFault %p:%Ix -> %x\n",
958  Address,
959  Status);
960 
961  return Status;
962 }
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
_In_ ULONG Mode
Definition: hubbusif.h:303
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG AddressSpace
Definition: iofuncs.h:2268
LONG NTSTATUS
Definition: precomp.h:26
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define PsGetCurrentProcess
Definition: psfuncs.h:17
static WCHAR Address[46]
Definition: ping.c:68
NTSTATUS NTAPI MmNotPresentFaultCacheSectionInner(KPROCESSOR_MODE Mode, PMMSUPPORT AddressSpace, ULONG_PTR Address, BOOLEAN FromMdl, PETHREAD Thread)
Definition: fault.c:747
void DPRINT(...)
Definition: polytest.cpp:61
#define DPRINTC
Definition: fault.c:82
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define PAGE_SIZE
Definition: env_spec_w32.h:49
Status
Definition: gdiplustypes.h:24
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
FORCEINLINE PMMSUPPORT MmGetKernelAddressSpace(VOID)
Definition: mm.h:1453
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:228
FORCEINLINE PEPROCESS MmGetAddressSpaceOwner(IN PMMSUPPORT AddressSpace)
Definition: mm.h:1438
UCHAR ActiveFaultCount
Definition: pstypes.h:1174
#define DPRINT1
Definition: precomp.h:8
#define MmSystemRangeStart
Definition: mm.h:32

Referenced by MmNotPresentFault().

◆ MmPageOutDeleteMapping()

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

Definition at line 1922 of file section.c.

1923 {
1924  MM_SECTION_PAGEOUT_CONTEXT* PageOutContext;
1925  BOOLEAN WasDirty;
1926  PFN_NUMBER Page = 0;
1927 
1928  PageOutContext = (MM_SECTION_PAGEOUT_CONTEXT*)Context;
1929  if (Process)
1930  {
1932  }
1933 
1935  Address,
1936  &WasDirty,
1937  &Page);
1938  if (WasDirty)
1939  {
1940  PageOutContext->WasDirty = TRUE;
1941  }
1942  if (!PageOutContext->Private)
1943  {
1944  MmLockSectionSegment(PageOutContext->Segment);
1946  PageOutContext->Segment,
1947  &PageOutContext->Offset,
1948  PageOutContext->WasDirty,
1949  TRUE,
1950  &PageOutContext->SectionEntry);
1951  MmUnlockSectionSegment(PageOutContext->Segment);
1952  }
1953  if (Process)
1954  {
1956  }
1957 
1958  if (PageOutContext->Private)
1959  {
1961  }
1962 }
#define TRUE
Definition: types.h:120
#define MC_USER
Definition: mm.h:94
FORCEINLINE VOID MmUnlockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1431
LARGE_INTEGER Offset
Definition: section.c:126
NTSTATUS NTAPI MmReleasePageMemoryConsumer(ULONG Consumer, PFN_NUMBER Page)
Definition: balance.c:97
ULONG PFN_NUMBER
Definition: ke.h:8
BOOLEAN NTAPI MmUnsharePageEntrySectionSegment(PROS_SECTION_OBJECT Section, PMM_SECTION_SEGMENT Segment, PLARGE_INTEGER Offset, BOOLEAN Dirty, BOOLEAN PageOut, ULONG_PTR *InEntry)
Definition: section.c:879
unsigned char BOOLEAN
static WCHAR Address[46]
Definition: ping.c:68
VOID NTAPI MmDeleteVirtualMapping(struct _EPROCESS *Process, PVOID Address, BOOLEAN *WasDirty, PPFN_NUMBER Page)
PROS_SECTION_OBJECT Section
Definition: section.c:124
#define MmLockSectionSegment(x)
Definition: newmm.h:276
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
PMM_SECTION_SEGMENT Segment
Definition: section.c:125
#define MmUnlockSectionSegment(x)
Definition: newmm.h:284
FORCEINLINE VOID MmLockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1424

Referenced by MmPageOutSectionView().

◆ MmPageOutPageFileView()

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

Referenced by _MiMapViewOfSegment().

◆ 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,
562  Dirty ? MAKE_PFN_SSE(Page) : DIRTY_SSE(MAKE_PFN_SSE(Page)));
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 MmSetPageEntrySectionSegment(S, O, E)
Definition: newmm.h:141
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
#define PageDirty(page)
Definition: module.h:607
#define TRUE
Definition: types.h:120
#define DPRINTC
Definition: swapout.c:68
ULONG Type
Definition: mm.h:214
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 STATUS_MM_RESTART_OPERATION
Definition: mm.h:80
struct _MM_RMAP_ENTRY *NTAPI MmGetRmapListHeadPage(PFN_NUMBER Page)
Definition: freelist.c:427
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG AddressSpace
Definition: iofuncs.h:2268
FORCEINLINE VOID MmUnlockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1431
LONG NTSTATUS
Definition: precomp.h:26
#define MAKE_PFN_SSE(P)
Definition: newmm.h:11
BOOLEAN NTAPI MmIsDirtyPageRmap(PFN_NUMBER Page)
Definition: rmap.c:239
#define MM_WAIT_ENTRY
Definition: mm.h:152
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
PMEMORY_AREA NTAPI MmLocateMemoryAreaByAddress(PMMSUPPORT AddressSpace, PVOID Address)
Definition: marea.c:60
FAST_MUTEX RmapListLock
Definition: rmap.c:26
VOID FASTCALL ExReleaseFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:31
uint32_t ULONG_PTR
Definition: typedefs.h:63
VOID NTAPI MmFinalizeSegment(PMM_SECTION_SEGMENT Segment)
Definition: data.c:271
ULONG PFN_NUMBER
Definition: ke.h:8
NTSTATUS NTAPI MmPageOutCacheSection(PMMSUPPORT AddressSpace, MEMORY_AREA *MemoryArea, PVOID Address, PBOOLEAN Dirty, PMM_REQUIRED_RESOURCES Required)
Definition: swapout.c:279
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
static WCHAR Address[46]
Definition: ping.c:68
void DPRINT(...)
Definition: polytest.cpp:61
VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1507
PMM_SECTION_SEGMENT NTAPI MmGetSectionAssociation(PFN_NUMBER Page, PLARGE_INTEGER Offset)
Definition: sptab.c:331
_Inout_ PVOID Segment
Definition: exfuncs.h:893
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
BOOLEAN DeleteInProgress
Definition: mm.h:217
#define MA_GetEndingAddress(_MemoryArea)
Definition: mm.h:208
BOOLEAN NTAPI PspIsProcessExiting(IN PEPROCESS Process)
Definition: kill.c:1067
ULONG NTAPI MmGetReferenceCountPage(PFN_NUMBER Page)
Definition: freelist.c:509
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
uint32_t entry
Definition: isohybrid.c:63
#define InterlockedDecrementUL(Addend)
Definition: ex.h:1510
#define MA_GetStartingAddress(_MemoryArea)
Definition: mm.h:207
Status
Definition: gdiplustypes.h:24
FORCEINLINE PMMSUPPORT MmGetKernelAddressSpace(VOID)
Definition: mm.h:1453
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:151
#define DPRINT1
Definition: precomp.h:8
#define MmLockSectionSegment(x)
Definition: newmm.h:276
#define MM_IS_WAIT_PTE(E)
Definition: newmm.h:9
_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 DIRTY_SSE(E)
Definition: newmm.h:14
unsigned int ULONG
Definition: retypes.h:1
Definition: mm.h:236
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define MmUnlockSectionSegment(x)
Definition: newmm.h:284
#define RMAP_IS_SEGMENT(x)
Definition: newmm.h:25
FAST_MUTEX MiGlobalPageOperation
Definition: swapout.c:74
return STATUS_SUCCESS
Definition: btrfs.c:2938
struct _MEMORY_AREA * MemoryArea
Definition: newmm.h:65
#define APC_LEVEL
Definition: env_spec_w32.h:695
FORCEINLINE VOID MmLockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1424
#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 352 of file sptab.c.

355 {
357  ULONG ActualOffset;
358 
360  ASSERT(PageTable);
361 
362  ActualOffset = (ULONG)(Offset->QuadPart - PageTable->FileOffset.QuadPart);
363  MmInsertRmap(Page,
365  (PVOID)(RMAP_SEGMENT_MASK | (ActualOffset >> PAGE_SHIFT)));
366 
367  return STATUS_SUCCESS;
368 }
#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
#define RMAP_SEGMENT_MASK
Definition: newmm.h:24
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
_Inout_ PVOID Segment
Definition: exfuncs.h:893
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by _MmSetPageEntrySectionSegment().

◆ MmspWaitForFileLock()

NTSTATUS MmspWaitForFileLock ( PFILE_OBJECT  File)

Definition at line 799 of file section.c.

800 {
801  return STATUS_SUCCESS;
802  //return KeWaitForSingleObject(&File->Lock, 0, KernelMode, FALSE, NULL);
803 }
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by MmCreateDataFileSection(), and MmCreateImageSection().

◆ MmUnmapCacheViewInSystemSpace()

NTSTATUS NTAPI MmUnmapCacheViewInSystemSpace ( PVOID  Address)

◆ MmUnmapViewOfCacheSegment()

NTSTATUS NTAPI MmUnmapViewOfCacheSegment ( PMMSUPPORT  AddressSpace,
PVOID  BaseAddress 
)

Definition at line 713 of file data.c.

715 {
716  PVOID Context[2];
719 
722  {
724  return STATUS_UNSUCCESSFUL;
725  }
726 
728  Segment = MemoryArea->Data.SectionData.Segment;
729  MemoryArea->Data.SectionData.Segment = NULL;
730 
732 
733  Context[0] = AddressSpace;
734  Context[1] = Segment;
735 
736  DPRINT("MmFreeMemoryArea(%p,%p)\n",
739 
741 
743 
745 
747 
748  DPRINTC("MiUnmapViewOfSegment %p %p %p\n",
750  BaseAddress,
751  Segment);
752 
753  return STATUS_SUCCESS;
754 }
#define DPRINTC
Definition: data.c:84
#define TRUE
Definition: types.h:120
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG AddressSpace
Definition: iofuncs.h:2268
FORCEINLINE VOID MmUnlockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1431
PMEMORY_AREA NTAPI MmLocateMemoryAreaByAddress(PMMSUPPORT AddressSpace, PVOID Address)
Definition: marea.c:60
union _MEMORY_AREA::@1743 Data
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
_Inout_ PVOID Segment
Definition: exfuncs.h:893
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
struct _MEMORY_AREA::@1743::@1744 SectionData
BOOLEAN DeleteInProgress
Definition: mm.h:217
NTSTATUS NTAPI MmFreeMemoryArea(PMMSUPPORT AddressSpace, PMEMORY_AREA MemoryArea, PMM_FREE_PAGE_FUNC FreePage, PVOID FreePageContext)
Definition: marea.c:278
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define MA_GetStartingAddress(_MemoryArea)
Definition: mm.h:207
FORCEINLINE PEPROCESS MmGetAddressSpaceOwner(IN PMMSUPPORT AddressSpace)
Definition: mm.h:1438
#define MmLockSectionSegment(x)
Definition: newmm.h:276
VOID MmFreeCacheSectionPage(PVOID Context, MEMORY_AREA *MemoryArea, PVOID Address, PFN_NUMBER Page, SWAPENTRY SwapEntry, BOOLEAN Dirty)
Definition: data.c:662
#define MmUnlockSectionSegment(x)
Definition: newmm.h:284
return STATUS_SUCCESS
Definition: btrfs.c:2938
struct _MEMORY_AREA * MemoryArea
Definition: newmm.h:65
FORCEINLINE VOID MmLockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1424

Referenced by MiRosCleanupMemoryArea(), MmUnmapCacheViewInSystemSpace(), and MmUnmapViewOfSegment().

◆ 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,
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 MmSetPageEntrySectionSegment(S, O, E)
Definition: newmm.h:141
#define IS_DIRTY_SSE(E)
Definition: newmm.h:16
struct _Entry Entry
Definition: kefuncs.h:640
#define PFN_FROM_SSE(E)
Definition: newmm.h:7
#define MM_WAIT_ENTRY
Definition: mm.h:152
uint32_t ULONG_PTR
Definition: typedefs.h:63
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
_Inout_ PVOID Segment
Definition: exfuncs.h:893
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define IS_SWAP_FROM_SSE(E)
Definition: newmm.h:8
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:151
#define DPRINT1
Definition: precomp.h:8
#define MmLockSectionSegment(x)
Definition: newmm.h:276
#define MM_IS_WAIT_PTE(E)
Definition: newmm.h:9
#define MmUnlockSectionSegment(x)
Definition: newmm.h:284
#define MAKE_SWAP_SSE(S)
Definition: newmm.h:13
base of all file and directory entries
Definition: entries.h:82
#define MmGetPageEntrySectionSegment(S, O)
Definition: newmm.h:143

Referenced by MmpPageOutPhysicalAddress().

◆ NTSTATUS()

typedef NTSTATUS ( NTAPI AcquireResource)

Variable Documentation

◆ Address

Definition at line 260 of file newmm.h.

◆ Locked

◆ MmWaitPageEvent

KEVENT MmWaitPageEvent