ReactOS  0.4.15-dev-2100-g9e32854
newmm.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <internal/arch/mm.h>
4 
5 /* TYPES *********************************************************************/
6 #define MM_SEGMENT_FINALIZE (0x40000000)
7 
8 
9 #define MIN(x,y) (((x)<(y))?(x):(y))
10 #define MAX(x,y) (((x)>(y))?(x):(y))
11 
12 /* Determine what's needed to make paged pool fit in this category.
13  * it seems that something more is required to satisfy arm3. */
14 #define BALANCER_CAN_EVICT(Consumer) \
15  (((Consumer) == MC_USER) || \
16  ((Consumer) == MC_CACHE))
17 
18 #define SEC_CACHE (0x20000000)
19 
20 #define MiWaitForPageEvent(Process,Address) do { \
21  DPRINT("MiWaitForPageEvent %p:%p #\n", Process, Address); \
22  KeWaitForSingleObject(&MmWaitPageEvent, 0, KernelMode, FALSE, NULL); \
23 } while(0)
24 
25 #define MiSetPageEvent(Process,Address) do { \
26  DPRINT("MiSetPageEvent %p:%p #\n",Process, (PVOID)(Address)); \
27  KeSetEvent(&MmWaitPageEvent, IO_NO_INCREMENT, FALSE); \
28 } while(0)
29 
30 /* We store 8 bits of location with a page association */
31 #define ENTRIES_PER_ELEMENT 256
32 
33 extern KEVENT MmWaitPageEvent;
34 
36 {
42 
44 
45 typedef NTSTATUS (NTAPI * AcquireResource)(
49 
52  struct _MEMORY_AREA *MemoryArea,
53  PVOID Address,
56 
59  struct _MEMORY_AREA *MemoryArea,
60  PVOID Address,
62 
63 typedef struct _MM_REQUIRED_RESOURCES
64 {
71  AcquireResource DoAcquisition;
75  const char *File;
76  int Line;
78 
80 NTAPI
84  PLARGE_INTEGER UMaximumSize,
88 
90 NTAPI
93  BOOLEAN *Dirty);
94 
96 NTAPI
100  BOOLEAN Dirty);
101 
102 /* sptab.c *******************************************************************/
103 
104 VOID
105 NTAPI
107 
111 
112 VOID
113 NTAPI
116 
117 NTSTATUS
118 NTAPI
122 
123 VOID
124 NTAPI
126 
127 NTSTATUS
128 NTAPI
130 
131 /* io.c **********************************************************************/
132 
133 NTSTATUS
135 
136 NTSTATUS
137 NTAPI
140  PVOID Buffer,
141  ULONG Length,
142  BOOLEAN Paging,
144 
145 NTSTATUS
146 NTAPI
149  PVOID Buffer,
150  ULONG Length,
152  const char *file,
153  int line);
154 
155 #define MiSimpleWrite(F,O,B,L,R) _MiSimpleWrite(F,O,B,L,R,__FILE__,__LINE__)
156 
157 NTSTATUS
158 NTAPI
161  ULONG Length,
163  const char *File,
164  int Line);
165 
166 #define MiWriteBackPage(F,O,L,P) _MiWriteBackPage(F,O,L,P,__FILE__,__LINE__)
167 
168 /* section.c *****************************************************************/
169 
170 NTSTATUS
171 NTAPI
174  BOOLEAN FromMdl);
175 
176 NTSTATUS
177 NTAPI
180  PMM_REQUIRED_RESOURCES RequiredResources);
181 
182 NTSTATUS
183 NTAPI
186  PMM_REQUIRED_RESOURCES RequiredResources);
187 
188 NTSTATUS
189 NTAPI
192  PMM_REQUIRED_RESOURCES RequiredResources);
193 
194 NTSTATUS
195 NTAPI
199 
200 NTSTATUS
201 NTAPI
205 
206 VOID
207 NTAPI
210 
211 _Success_(1)
213 NTSTATUS
214 NTAPI
215 MiCowCacheSectionPage (
221 
222 VOID
225  PVOID Address);
226 
227 VOID
230  PVOID Address,
232  SWAPENTRY SwapEntry,
233  BOOLEAN Dirty);
234 
235 NTSTATUS
236 NTAPI
238  PLARGE_INTEGER BaseOffset,
240  BOOLEAN Dirty,
241  const char *File,
242  int Line);
243 
244 #define MiFlushMappedSection(A,O,S,D) _MiFlushMappedSection(A,O,S,D,__FILE__,__LINE__)
245 
246 VOID
247 NTAPI
249 
250 VOID
251 NTAPI
253 
254 NTSTATUS
255 NTAPI
258  IN PLARGE_INTEGER ViewOffset,
260 
261 NTSTATUS
262 NTAPI
267  ULONG Protect,
268  PLARGE_INTEGER ViewOffset,
270  const char *file,
271  int line);
272 
273 #define MiMapViewOfSegment(AddressSpace,Segment,BaseAddress,ViewSize,Protect,ViewOffset,AllocationType) \
274  _MiMapViewOfSegment(AddressSpace,Segment,BaseAddress,ViewSize,Protect,ViewOffset,AllocationType,__FILE__,__LINE__)
275 
276 NTSTATUS
277 NTAPI
280 
281 NTSTATUS
282 NTAPI
284 
285 _Success_(1)
287 NTSTATUS
288 NTAPI
289 MmNotPresentFaultCachePage (
295 
296 NTSTATUS
297 NTAPI
300  PVOID Address,
302 
304 BOOLEAN
306  const char *file,
307  int line)
308 {
310  //DbgPrint("(%s:%d) Try Lock Address Space %x -> %s\n", file, line, AddressSpace, Result ? "true" : "false");
311  return Result;
312 }
313 
314 #define MmTryToLockAddressSpace(x) _MmTryToLockAddressSpace(x,__FILE__,__LINE__)
315 
316 NTSTATUS
317 NTAPI
320  PMM_REQUIRED_RESOURCES RequiredResources);
321 
322 NTSTATUS
323 NTAPI
326  PMM_REQUIRED_RESOURCES RequiredResources);
327 
328 NTSTATUS
329 NTAPI
332  BOOLEAN ExtendFile);
333 
334 NTSTATUS
335 NTAPI
337  PLARGE_INTEGER BaseOffset,
339  BOOLEAN Dirty,
340  const char *File,
341  int Line);
342 
343 #define MiFlushMappedSection(A,O,S,D) _MiFlushMappedSection(A,O,S,D,__FILE__,__LINE__)
344 
345 PVOID
346 NTAPI
348  PULONG RawOffset);
349 
350 NTSTATUS
351 NTAPI
354  BOOLEAN FromMdl);
355 
356 ULONG
357 NTAPI
359  ULONG Target);
360 
361 NTSTATUS
363  ULONG Priority,
364  PULONG NrFreed);
_Must_inspect_result_ _Outptr_ PVOID * SectionObject
Definition: fsrtlfuncs.h:860
VOID(NTAPI * FREE_SECTION_PAGE_FUN)(PMM_SECTION_SEGMENT Segment, PLARGE_INTEGER Offset)
Definition: newmm.h:108
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define IN
Definition: typedefs.h:39
NTSTATUS NTAPI MmAccessFaultCacheSection(KPROCESSOR_MODE Mode, ULONG_PTR Address, BOOLEAN FromMdl)
return
Definition: dirsup.c:529
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK DesiredAccess
Definition: wdfdevice.h:2654
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)
PVOID NTAPI MmGetSegmentRmap(PFN_NUMBER Page, PULONG RawOffset)
Definition: rmap.c:493
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
NTSTATUS NTAPI MiSimpleRead(PFILE_OBJECT FileObject, PLARGE_INTEGER FileOffset, PVOID Buffer, ULONG Length, BOOLEAN Paging, PIO_STATUS_BLOCK ReadStatus)
Definition: io.c:109
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ ULONG AllocationAttributes
Definition: mmfuncs.h:360
_In_ ULONG Mode
Definition: hubbusif.h:303
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:68
_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
_At_(Required->DoAcquisition, _Post_notnull_)) NTSTATUS NTAPI MiCowCacheSectionPage(_In_ PMMSUPPORT AddressSpace
_In_ PMEMORY_AREA _In_ PVOID Address
Definition: newmm.h:217
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI MmFinalizeSectionPageOut(PMM_SECTION_SEGMENT Segment, PLARGE_INTEGER FileOffset, PFN_NUMBER Page, BOOLEAN Dirty)
Definition: swapout.c:165
AcquireResource DoAcquisition
Definition: newmm.h:71
struct _CACHE_SECTION_PAGE_TABLE * PCACHE_SECTION_PAGE_TABLE
NTSTATUS NTAPI MiReadFilePage(PMMSUPPORT AddressSpace, PMEMORY_AREA MemoryArea, PMM_REQUIRED_RESOURCES RequiredResources)
Definition: reqtools.c:133
NTSTATUS MiRosTrimCache(ULONG Target, ULONG Priority, PULONG NrFreed)
Definition: swapout.c:633
NTSTATUS(NTAPI * NotPresentFaultHandler)(PMMSUPPORT AddressSpace, struct _MEMORY_AREA *MemoryArea, PVOID Address, BOOLEAN Locked, struct _MM_REQUIRED_RESOURCES *Required)
Definition: newmm.h:50
NTSTATUS NTAPI MiSwapInPage(PMMSUPPORT AddressSpace, PMEMORY_AREA MemoryArea, PMM_REQUIRED_RESOURCES RequiredResources)
Definition: reqtools.c:220
NTSTATUS NTAPI _MiSimpleWrite(PFILE_OBJECT FileObject, PLARGE_INTEGER FileOffset, PVOID Buffer, ULONG Length, PIO_STATUS_BLOCK ReadStatus, const char *file, int line)
VOID NTAPI MiFreeSegmentPage(PMM_SECTION_SEGMENT Segment, PLARGE_INTEGER FileOffset)
Definition: data.c:617
uint32_t ULONG_PTR
Definition: typedefs.h:65
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_opt_ PLARGE_INTEGER _In_ ULONG SectionPageProtection
Definition: mmfuncs.h:360
ULONG PFN_NUMBER
Definition: ke.h:9
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
ULONG_PTR PageEntries[ENTRIES_PER_ELEMENT]
Definition: newmm.h:40
NTSTATUS NTAPI MiGetOnePage(PMMSUPPORT AddressSpace, PMEMORY_AREA MemoryArea, PMM_REQUIRED_RESOURCES RequiredResources)
Definition: reqtools.c:83
VOID MmFreeCacheSectionPage(PVOID Context, MEMORY_AREA *MemoryArea, PVOID Address, PFN_NUMBER Page, SWAPENTRY SwapEntry, BOOLEAN Dirty)
Definition: data.c:663
PFN_NUMBER Page[2]
Definition: newmm.h:72
_In_ PMEMORY_AREA _In_ PVOID _In_ BOOLEAN Locked
Definition: newmm.h:217
VOID NTAPI MmFinalizeSegment(PMM_SECTION_SEGMENT Segment)
NTSTATUS NTAPI MmpPageOutPhysicalAddress(PFN_NUMBER Page)
Definition: swapout.c:345
VOID NTAPI MmDeleteSectionAssociation(PFN_NUMBER Page)
Definition: rmap.c:532
NTSTATUS NTAPI MmUnmapCacheViewInSystemSpace(PVOID Address)
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
Definition: parser.c:48
Definition: bufpool.h:45
NTSTATUS NTAPI MmExtendCacheSection(PSECTION Section, PLARGE_INTEGER NewSize, BOOLEAN ExtendFile)
PFN_NUMBER Page
Definition: section.c:4843
VOID MmPageOutDeleteMapping(PVOID Context, PEPROCESS Process, PVOID Address)
NTSTATUS NTAPI MmSetSectionAssociation(PFN_NUMBER Page, PMM_SECTION_SEGMENT Segment, PLARGE_INTEGER Offset)
Definition: sptab.c:373
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
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
_Inout_ PVOID Segment
Definition: exfuncs.h:1101
PMM_SECTION_SEGMENT Segment
Definition: newmm.h:38
NTSTATUS NTAPI _MiWriteBackPage(PFILE_OBJECT FileObject, PLARGE_INTEGER Offset, ULONG Length, PFN_NUMBER Page, const char *File, int Line)
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
VOID NTAPI MmFreeSectionSegments(PFILE_OBJECT FileObject)
static USHORT ReadStatus(IN PUCHAR ReadDataPort)
Definition: hardware.c:128
LARGE_INTEGER FileOffset
Definition: newmm.h:37
VOID NTAPI MmFreePageTablesSectionSegment(PMM_SECTION_SEGMENT Segment, FREE_SECTION_PAGE_FUN FreePage)
Definition: sptab.c:299
#define _Inout_
Definition: no_sal2.h:162
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
* PFILE_OBJECT
Definition: iotypes.h:1995
FORCEINLINE BOOLEAN _MmTryToLockAddressSpace(IN PMMSUPPORT AddressSpace, const char *file, int line)
Definition: newmm.h:305
Definition: ncftp.h:79
#define _Post_notnull_
Definition: sal.h:701
_In_ WDFINTERRUPT _In_ WDF_INTERRUPT_POLICY _In_ WDF_INTERRUPT_PRIORITY Priority
Definition: wdfinterrupt.h:651
struct _MM_REQUIRED_RESOURCES * PMM_REQUIRED_RESOURCES
struct _MM_REQUIRED_RESOURCES MM_REQUIRED_RESOURCES
NTSTATUS NTAPI MiSwapInSectionPage(PMMSUPPORT AddressSpace, PMEMORY_AREA MemoryArea, PMM_REQUIRED_RESOURCES RequiredResources)
#define VOID
Definition: acefi.h:82
_Must_inspect_result_ _Out_ PLARGE_INTEGER FileSize
Definition: fsrtlfuncs.h:108
_Must_inspect_result_ _In_ USHORT NewSize
Definition: fltkernel.h:975
_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
VOID NTAPI MiInitializeSectionPageTable(PMM_SECTION_SEGMENT Segment)
Definition: sptab.c:165
NTSTATUS NTAPI MmUnmapViewOfCacheSegment(PMMSUPPORT AddressSpace, PVOID BaseAddress)
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define _In_
Definition: no_sal2.h:158
typedef NTSTATUS(NTAPI *AcquireResource)(PMMSUPPORT AddressSpace
ULONG_PTR SIZE_T
Definition: typedefs.h:80
_Success_(1) _When_(return
ULONG NTAPI MiCacheEvictPages(PMM_SECTION_SEGMENT Segment, ULONG Target)
Definition: swapout.c:590
NTSTATUS MmspWaitForFileLock(PFILE_OBJECT File)
Definition: section.c:908
BOOLEAN FASTCALL KeTryToAcquireGuardedMutex(IN OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:86
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:159
ULONG_PTR SWAPENTRY
Definition: mm.h:47
#define FORCEINLINE
Definition: wdftypes.h:67
unsigned int * PULONG
Definition: retypes.h:1
NTSTATUS(NTAPI * FaultHandler)(PMMSUPPORT AddressSpace, struct _MEMORY_AREA *MemoryArea, PVOID Address, struct _MM_REQUIRED_RESOURCES *Required)
Definition: newmm.h:57
_In_ WDFIOTARGET Target
Definition: wdfrequest.h:306
_Must_inspect_result_ _Outptr_result_bytebuffer_ ViewSize PVOID * MappedBase
Definition: mmfuncs.h:492
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
NTSTATUS NTAPI MiWriteSwapPage(PMMSUPPORT AddressSpace, PMEMORY_AREA MemoryArea, PMM_REQUIRED_RESOURCES Resources)
#define _When_(c, a)
Definition: no_sal2.h:38
SWAPENTRY SwapEntry
Definition: newmm.h:74
#define OUT
Definition: typedefs.h:40
_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
LARGE_INTEGER FileOffset
Definition: newmm.h:70
const char * File
Definition: newmm.h:75
unsigned int ULONG
Definition: retypes.h:1
#define const
Definition: zconf.h:230
KEVENT MmWaitPageEvent
Definition: section.c:66
struct _CACHE_SECTION_PAGE_TABLE CACHE_SECTION_PAGE_TABLE
NTSTATUS NTAPI _MiFlushMappedSection(PVOID BaseAddress, PLARGE_INTEGER BaseOffset, PLARGE_INTEGER FileSize, BOOLEAN Dirty, const char *File, int Line)
NTSTATUS NTAPI MmNotPresentFaultCacheSection(KPROCESSOR_MODE Mode, ULONG_PTR Address, BOOLEAN FromMdl)
Definition: File.h:15
NTSTATUS NTAPI MmCreateCacheSection(PSECTION *SectionObject, ACCESS_MASK DesiredAccess, POBJECT_ATTRIBUTES ObjectAttributes, PLARGE_INTEGER UMaximumSize, ULONG SectionPageProtection, ULONG AllocationAttributes, PFILE_OBJECT FileObject)
struct _MEMORY_AREA struct _MM_REQUIRED_RESOURCES * Required
Definition: newmm.h:48
NTSTATUS NTAPI MmMapCacheViewInSystemSpaceAtOffset(IN PMM_SECTION_SEGMENT Segment, OUT PVOID *MappedBase, IN PLARGE_INTEGER ViewOffset, IN OUT PULONG ViewSize)
NTSTATUS NTAPI MiWriteFilePage(PMMSUPPORT AddressSpace, PMEMORY_AREA MemoryArea, PMM_REQUIRED_RESOURCES Resources)
Definition: reqtools.c:271
NTSTATUS NTAPI MmPageOutPageFileView(PMMSUPPORT AddressSpace, PMEMORY_AREA MemoryArea, PVOID Address, PMM_REQUIRED_RESOURCES Required)
struct _MEMORY_AREA * MemoryArea
Definition: newmm.h:47
ULONG ACCESS_MASK
Definition: nt_native.h:40
NTSTATUS NTAPI MiWidenSegment(PMMSUPPORT AddressSpace, PMEMORY_AREA MemoryArea, PMM_REQUIRED_RESOURCES RequiredResources)
PFN_NUMBER NTAPI MmWithdrawSectionPage(PMM_SECTION_SEGMENT Segment, PLARGE_INTEGER FileOffset, BOOLEAN *Dirty)
Definition: swapout.c:87
#define ENTRIES_PER_ELEMENT
Definition: newmm.h:31
Definition: fci.c:126