ReactOS  0.4.13-dev-92-gf251225
reqtools.c File Reference
#include <ntoskrnl.h>
#include "newmm.h"
#include <debug.h>
Include dependency graph for reqtools.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define DPRINTC   DPRINT
 

Functions

VOID NTAPI MmBuildMdlFromPages (PMDL Mdl, PPFN_NUMBER Pages)
 
NTSTATUS NTAPI MiGetOnePage (PMMSUPPORT AddressSpace, PMEMORY_AREA MemoryArea, PMM_REQUIRED_RESOURCES Required)
 
NTSTATUS NTAPI MiReadFilePage (PMMSUPPORT AddressSpace, PMEMORY_AREA MemoryArea, PMM_REQUIRED_RESOURCES RequiredResources)
 
NTSTATUS NTAPI MiSwapInPage (PMMSUPPORT AddressSpace, PMEMORY_AREA MemoryArea, PMM_REQUIRED_RESOURCES Resources)
 
NTSTATUS NTAPI MiWriteFilePage (PMMSUPPORT AddressSpace, PMEMORY_AREA MemoryArea, PMM_REQUIRED_RESOURCES Required)
 

Macro Definition Documentation

◆ DPRINTC

#define DPRINTC   DPRINT

Definition at line 59 of file reqtools.c.

◆ NDEBUG

#define NDEBUG

Definition at line 56 of file reqtools.c.

Function Documentation

◆ MiGetOnePage()

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

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:2725

Referenced by MiCowCacheSectionPage().

◆ 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:434
#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:1954
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:2725

Referenced by MmNotPresentFaultCachePage().

◆ MiSwapInPage()

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

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

◆ MiWriteFilePage()

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

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

◆ MmBuildMdlFromPages()

VOID NTAPI MmBuildMdlFromPages ( PMDL  Mdl,
PPFN_NUMBER  Pages 
)

Definition at line 98 of file pagefile.c.

99 {
100  memcpy(Mdl + 1, Pages, sizeof(PFN_NUMBER) * (PAGE_ROUND_UP(Mdl->ByteOffset+Mdl->ByteCount)/PAGE_SIZE));
101 
102  /* FIXME: this flag should be set by the caller perhaps? */
103  Mdl->MdlFlags |= MDL_IO_PAGE_READ;
104 }
#define MDL_IO_PAGE_READ
Definition: mmtypes.h:24
#define PAGE_ROUND_UP(x)
Definition: scsiport_int.h:13
ULONG PFN_NUMBER
Definition: ke.h:8
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define PAGE_SIZE
Definition: env_spec_w32.h:49

Referenced by MiReadFilePage().