ReactOS  0.4.11-dev-201-g2a6aa77
data.c File Reference
#include <ntoskrnl.h>
#include "newmm.h"
#include <cache/newcc.h>
#include <debug.h>
#include <mm/ARM3/miarm.h>
Include dependency graph for data.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define DPRINTC   DPRINT
 

Functions

VOID NTAPI _MmLockSectionSegment (PMM_SECTION_SEGMENT Segment, const char *file, int line)
 
VOID NTAPI _MmUnlockSectionSegment (PMM_SECTION_SEGMENT Segment, const char *file, int line)
 
NTSTATUS NTAPI _MiFlushMappedSection (PVOID BaseAddress, PLARGE_INTEGER BaseOffset, PLARGE_INTEGER FileSize, BOOLEAN WriteData, const char *File, int Line)
 
VOID NTAPI MmFinalizeSegment (PMM_SECTION_SEGMENT Segment)
 
NTSTATUS NTAPI MmCreateCacheSection (PROS_SECTION_OBJECT *SectionObject, ACCESS_MASK DesiredAccess, POBJECT_ATTRIBUTES ObjectAttributes, PLARGE_INTEGER UMaximumSize, ULONG SectionPageProtection, ULONG AllocationAttributes, PFILE_OBJECT FileObject)
 
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)
 
VOID NTAPI MiFreeSegmentPage (PMM_SECTION_SEGMENT Segment, PLARGE_INTEGER FileOffset)
 
VOID MmFreeCacheSectionPage (PVOID Context, MEMORY_AREA *MemoryArea, PVOID Address, PFN_NUMBER Page, SWAPENTRY SwapEntry, BOOLEAN Dirty)
 
NTSTATUS NTAPI MmUnmapViewOfCacheSegment (PMMSUPPORT AddressSpace, PVOID BaseAddress)
 
NTSTATUS NTAPI MmExtendCacheSection (PROS_SECTION_OBJECT Section, PLARGE_INTEGER NewSize, BOOLEAN ExtendFile)
 
NTSTATUS NTAPI MmMapCacheViewInSystemSpaceAtOffset (IN PMM_SECTION_SEGMENT Segment, OUT PVOID *MappedBase, PLARGE_INTEGER FileOffset, IN OUT PULONG ViewSize)
 
NTSTATUS NTAPI MmUnmapCacheViewInSystemSpace (IN PVOID MappedBase)
 

Variables

LIST_ENTRY MiSegmentList
 
KEVENT MpwThreadEvent
 
KSPIN_LOCK MiSectionPageTableLock
 
PMMWSL MmWorkingSetList
 

Macro Definition Documentation

#define NDEBUG

Definition at line 80 of file data.c.

Function Documentation

NTSTATUS NTAPI _MiFlushMappedSection ( PVOID  BaseAddress,
PLARGE_INTEGER  BaseOffset,
PLARGE_INTEGER  FileSize,
BOOLEAN  WriteData,
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 
155  MmLockAddressSpace(AddressSpace);
156  MemoryArea = MmLocateMemoryAreaByAddress(AddressSpace, BaseAddress);
157  if (!MemoryArea || MemoryArea->Type != MEMORY_AREA_CACHE || MemoryArea->DeleteInProgress)
158  {
159  MmUnlockAddressSpace(AddressSpace);
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 
170  MmLockSectionSegment(Segment);
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;
184  PageAddress += PAGE_SIZE)
185  {
187  FileOffset.QuadPart = ViewOffset.QuadPart + PageAddress - BeginningAddress;
188  Entry = MmGetPageEntrySectionSegment(MemoryArea->Data.SectionData.Segment,
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  {
195  OldIrql = MiAcquirePfnLock();
196  MmReferencePage(Page);
197  MiReleasePfnLock(OldIrql);
198  Pages[(PageAddress - BeginningAddress) >> PAGE_SHIFT] = Entry;
199  }
200  else
201  {
202  Pages[(PageAddress - BeginningAddress) >> PAGE_SHIFT] = 0;
203  }
204  }
205 
206  MmUnlockSectionSegment(Segment);
207  MmUnlockAddressSpace(AddressSpace);
208 
209  for (PageAddress = BeginningAddress;
210  PageAddress < EndingAddress;
211  PageAddress += PAGE_SIZE)
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
223  Status = STATUS_SUCCESS;
224 
225  if (NT_SUCCESS(Status)) {
226  MmLockAddressSpace(AddressSpace);
227  MmSetCleanAllRmaps(Page);
228 
230  (PVOID)PageAddress,
231  PAGE_READONLY);
232 
233  MmLockSectionSegment(Segment);
234  Entry = MmGetPageEntrySectionSegment(Segment, &FileOffset);
235 
236  if (Entry && !IS_SWAP_FROM_SSE(Entry) && PFN_FROM_SSE(Entry) == Page)
237  MmSetPageEntrySectionSegment(Segment, &FileOffset, CLEAN_SSE(Entry));
238 
239  MmUnlockSectionSegment(Segment);
240  MmUnlockAddressSpace(AddressSpace);
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
DWORD *typedef PVOID
Definition: winlogon.h:61
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
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
#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:1410
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:894
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:901
#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
#define FALSE
Definition: types.h:117
void DPRINT(...)
Definition: polytest.cpp:61
PFILE_OBJECT FileObject
Definition: mm.h:163
_Inout_ PVOID Segment
Definition: exfuncs.h:893
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
BOOLEAN DeleteInProgress
Definition: mm.h:217
struct _MEMORY_AREA::@1716::@1717 SectionData
#define MA_GetEndingAddress(_MemoryArea)
Definition: mm.h:208
VOID NTAPI MmSetPageProtect(struct _EPROCESS *Process, PVOID Address, ULONG flProtect)
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
#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:1432
FORCEINLINE PEPROCESS MmGetAddressSpaceOwner(IN PMMSUPPORT AddressSpace)
Definition: mm.h:1417
#define PAGE_READONLY
Definition: compat.h:127
#define MmLockSectionSegment(x)
Definition: newmm.h:276
_In_ PLARGE_INTEGER FileOffset
Definition: cctypes.h:53
#define MC_CACHE
Definition: mm.h:93
struct _LARGE_INTEGER::@2192 u
unsigned int ULONG
Definition: retypes.h:1
Definition: File.h:15
union _MEMORY_AREA::@1716 Data
#define MmUnlockSectionSegment(x)
Definition: newmm.h:284
return STATUS_SUCCESS
Definition: btrfs.c:2710
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:1403
static VOID WriteData(USHORT Data)
Definition: hardware.c:25
#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
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.

Referenced by MmMapViewOfSegment().

548 {
549  PMEMORY_AREA MArea;
551 
552  Status = MmCreateMemoryArea(AddressSpace,
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",
573  MmGetAddressSpaceOwner(AddressSpace),
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",
600  MmGetAddressSpaceOwner(AddressSpace),
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
#define MEMORY_AREA_CACHE
Definition: mm.h:72
smooth NULL
Definition: ftsmooth.c:416
Definition: parser.c:48
void DPRINT(...)
Definition: polytest.cpp:61
PFILE_OBJECT FileObject
Definition: mm.h:163
_Inout_ PVOID Segment
Definition: exfuncs.h:893
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
struct _MEMORY_AREA::@1716::@1717 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:1417
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
union _MEMORY_AREA::@1716 Data
return STATUS_SUCCESS
Definition: btrfs.c:2710
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
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
BOOLEAN Locked
Definition: mm.h:171
VOID FASTCALL ExAcquireFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:23
FAST_MUTEX Lock
Definition: mm.h:162
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 }
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
VOID FASTCALL ExReleaseFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:31
#define FALSE
Definition: types.h:117
BOOLEAN Locked
Definition: mm.h:171
FAST_MUTEX Lock
Definition: mm.h:162
VOID NTAPI MiFreeSegmentPage ( PMM_SECTION_SEGMENT  Segment,
PLARGE_INTEGER  FileOffset 
)

Definition at line 616 of file data.c.

Referenced by MmFinalizeSegment().

618 {
621 
622  Entry = MmGetPageEntrySectionSegment(Segment, FileOffset);
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 
639  MiWriteBackPage(FileObject, FileOffset, PAGE_SIZE, OldPage);
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 
649  MmSetPageEntrySectionSegment(Segment, FileOffset, 0);
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
PFILE_OBJECT FileObject
Definition: mm.h:163
#define SWAPENTRY_FROM_SSE(E)
Definition: newmm.h:12
* PFILE_OBJECT
Definition: iotypes.h:1954
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
#define MC_CACHE
Definition: mm.h:93
#define MmGetPageEntrySectionSegment(S, O)
Definition: newmm.h:143
VOID NTAPI MmFreeSwapPage(SWAPENTRY Entry)
Definition: pagefile.c:278
LONGLONG QuadPart
Definition: typedefs.h:112
#define MiWriteBackPage(F, O, L, P)
Definition: newmm.h:209
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.

Referenced by MmCreateSection().

318 {
319  PROS_SECTION_OBJECT Section;
326  KIRQL OldIrql;
327 
328  DPRINT("MmCreateDataFileSection\n");
329 
330  /* Create the section */
333  ObjectAttributes,
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  */
363  if (!CcGetFileSizes(FileObject, &FileSizes))
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  }
389  ASSERT(Status != STATUS_PENDING);
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);
410  MaximumSize.QuadPart = 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);
434  RtlZeroMemory(Segment, sizeof(MM_SECTION_SEGMENT));
435  ExInitializeFastMutex(&Segment->Lock);
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;
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  }
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 
493  MmLockSectionSegment(Segment);
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 
503  MmUnlockSectionSegment(Segment);
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,
510  FileSizes.ValidDataLength.QuadPart);
511  if (MaximumSize.QuadPart > FileSizes.ValidDataLength.QuadPart)
512  {
513  DPRINT("Changing file size to %I64x, segment %p\n",
514  MaximumSize.QuadPart,
515  Segment);
516 
517  Status = IoSetInformation(FileObject,
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 }
DWORD *typedef PVOID
Definition: winlogon.h:61
#define DPRINTC
Definition: data.c:84
BOOLEAN WriteCopy
Definition: mm.h:170
#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
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
FORCEINLINE VOID InsertHeadList(_Inout_ PLIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PLIST_ENTRY Entry)
Definition: rtlfuncs.h:201
LIST_ENTRY ListOfSegments
Definition: mm.h:180
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:2927
NTSTATUS NTAPI IoSetInformation(IN PFILE_OBJECT FileObject, IN FILE_INFORMATION_CLASS FileInformationClass, IN ULONG Length, IN PVOID FileInformation)
Definition: iofunc.c:1201
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:1161
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 FALSE
Definition: types.h:117
ULONG Protection
Definition: mm.h:168
#define SEC_RESERVE
Definition: nt_native.h:1323
BOOLEAN Locked
Definition: mm.h:171
smooth NULL
Definition: ftsmooth.c:416
LARGE_INTEGER EndOfFile
Definition: nt_native.h:948
void DPRINT(...)
Definition: polytest.cpp:61
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
PFILE_OBJECT FileObject
Definition: mm.h:163
_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:938
LARGE_INTEGER Length
Definition: mm.h:165
#define DBG_UNREFERENCED_LOCAL_VARIABLE(L)
Definition: ntbasedef.h:326
LONG NTSTATUS
Definition: precomp.h:26
PFILE_OBJECT FileObject
Definition: mm.h:199
return Iosb
Definition: create.c:4426
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
#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
LARGE_INTEGER RawLength
Definition: mm.h:164
#define MM_DATAFILE_SEGMENT
Definition: mm.h:91
POBJECT_TYPE MmSectionObjectType
Definition: section.c:136
struct _MM_SECTION_SEGMENT * PMM_SECTION_SEGMENT
ULONG Flags
Definition: mm.h:169
#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
ULONG ReferenceCount
Definition: mm.h:166
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:1469
#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 MmLockSectionSegment(x)
Definition: newmm.h:276
struct _MM_SECTION_SEGMENT::@1713 Image
FAST_MUTEX Lock
Definition: mm.h:162
#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:2710
#define memset(x, y, z)
Definition: compat.h:39
Iosb Information
Definition: create.c:4377
LONGLONG QuadPart
Definition: typedefs.h:112
NTSTATUS NTAPI MmExtendCacheSection ( PROS_SECTION_OBJECT  Section,
PLARGE_INTEGER  NewSize,
BOOLEAN  ExtendFile 
)

Definition at line 758 of file data.c.

Referenced by CcSetFileSizes().

761 {
762  LARGE_INTEGER OldSize;
764  DPRINT("Extend Segment %p\n", Segment);
765 
766  MmLockSectionSegment(Segment);
767  OldSize.QuadPart = Segment->RawLength.QuadPart;
768  MmUnlockSectionSegment(Segment);
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 
786  MmLockSectionSegment(Segment);
787  Segment->RawLength.QuadPart = NewSize->QuadPart;
788  Segment->Length.QuadPart = MAX(Segment->Length.QuadPart,
790  MmUnlockSectionSegment(Segment);
791  return STATUS_SUCCESS;
792 }
NTSTATUS NTAPI IoSetInformation(IN PFILE_OBJECT FileObject, IN FILE_INFORMATION_CLASS FileInformationClass, IN ULONG Length, IN PVOID FileInformation)
Definition: iofunc.c:1201
#define PAGE_ROUND_UP(x)
Definition: scsiport_int.h:13
void DPRINT(...)
Definition: polytest.cpp:61
PFILE_OBJECT FileObject
Definition: mm.h:163
_Inout_ PVOID Segment
Definition: exfuncs.h:893
LARGE_INTEGER Length
Definition: mm.h:165
int64_t LONG64
Definition: typedefs.h:66
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
LARGE_INTEGER RawLength
Definition: mm.h:164
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:2710
LONGLONG QuadPart
Definition: typedefs.h:112
VOID NTAPI MmFinalizeSegment ( PMM_SECTION_SEGMENT  Segment)

Definition at line 271 of file data.c.

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

272 {
273  KIRQL OldIrql = 0;
274 
275  DPRINT("Finalize segment %p\n", Segment);
276 
277  MmLockSectionSegment(Segment);
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);
283  MmUnlockSectionSegment(Segment);
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);
292  MmUnlockSectionSegment(Segment);
293  DPRINT("Dereference file object %wZ\n", &Segment->FileObject->FileName);
295  DPRINT("Done with %wZ\n", &Segment->FileObject->FileName);
296  Segment->FileObject = NULL;
297  } else {
298  DPRINTC("Finalizing segment %p\n", Segment);
300  MmUnlockSectionSegment(Segment);
301  }
302  DPRINTC("Segment %p destroy\n", Segment);
304 }
#define DPRINTC
Definition: data.c:84
LIST_ENTRY ListOfSegments
Definition: mm.h:180
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
PFILE_OBJECT FileObject
Definition: mm.h:163
#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
ULONG Flags
Definition: mm.h:169
_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
VOID MmFreeCacheSectionPage ( PVOID  Context,
MEMORY_AREA MemoryArea,
PVOID  Address,
PFN_NUMBER  Page,
SWAPENTRY  SwapEntry,
BOOLEAN  Dirty 
)

Definition at line 662 of file data.c.

Referenced by MmUnmapViewOfCacheSegment().

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];
684  Process = MmGetAddressSpaceOwner(AddressSpace);
686  Segment = ContextData[1];
687  Offset.QuadPart = (ULONG_PTR)Address - MA_GetStartingAddress(MemoryArea) +
688  MemoryArea->Data.SectionData.ViewOffset.QuadPart;
689 
690  Entry = MmGetPageEntrySectionSegment(Segment, &Offset);
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);
695  MmSetPageEntrySectionSegment(Segment, &Offset, DIRTY_SSE(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
DWORD *typedef PVOID
Definition: winlogon.h:61
PVOID ULONG Address
Definition: oprghdlr.h:14
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
smooth NULL
Definition: ftsmooth.c:416
VOID NTAPI MmDeleteVirtualMapping(struct _EPROCESS *Process, PVOID Address, BOOLEAN *WasDirty, PPFN_NUMBER Page)
void DPRINT(...)
Definition: polytest.cpp:61
_Inout_ PVOID Segment
Definition: exfuncs.h:893
struct _MEMORY_AREA::@1716::@1717 SectionData
#define MA_GetStartingAddress(_MemoryArea)
Definition: mm.h:207
FORCEINLINE PEPROCESS MmGetAddressSpaceOwner(IN PMMSUPPORT AddressSpace)
Definition: mm.h:1417
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:1014
#define ULONG_PTR
Definition: config.h:101
union _MEMORY_AREA::@1716 Data
#define MmGetPageEntrySectionSegment(S, O)
Definition: newmm.h:143
VOID NTAPI MmFreeSwapPage(SWAPENTRY Entry)
Definition: pagefile.c:278
LONGLONG QuadPart
Definition: typedefs.h:112
NTSTATUS NTAPI MmMapCacheViewInSystemSpaceAtOffset ( IN PMM_SECTION_SEGMENT  Segment,
OUT PVOID MappedBase,
PLARGE_INTEGER  FileOffset,
IN OUT PULONG  ViewSize 
)

Definition at line 796 of file data.c.

Referenced by CcpMapData().

800 {
803 
804  DPRINT("MmMapViewInSystemSpaceAtOffset() called offset 0x%I64x\n",
805  FileOffset->QuadPart);
806 
807  AddressSpace = MmGetKernelAddressSpace();
808 
809  MmLockAddressSpace(AddressSpace);
811 
812  Status = MiMapViewOfSegment(AddressSpace,
813  Segment,
814  MappedBase,
815  *ViewSize,
817  FileOffset,
818  0);
819 
821  MmUnlockAddressSpace(AddressSpace);
822 
823  return Status;
824 }
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG AddressSpace
Definition: iofuncs.h:2268
FORCEINLINE VOID MmUnlockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1410
void DPRINT(...)
Definition: polytest.cpp:61
_Inout_ PVOID Segment
Definition: exfuncs.h:893
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: gdiplustypes.h:24
FORCEINLINE PMMSUPPORT MmGetKernelAddressSpace(VOID)
Definition: mm.h:1432
_Must_inspect_result_ _Outptr_result_bytebuffer_ ViewSize PVOID * MappedBase
Definition: mmfuncs.h:493
#define MmLockSectionSegment(x)
Definition: newmm.h:276
_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
#define MmUnlockSectionSegment(x)
Definition: newmm.h:284
FORCEINLINE VOID MmLockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1403
LONGLONG QuadPart
Definition: typedefs.h:112
#define PAGE_READWRITE
Definition: nt_native.h:1304
#define MiMapViewOfSegment(AddressSpace, Segment, BaseAddress, ViewSize, Protect, ViewOffset, AllocationType)
Definition: newmm.h:332
NTSTATUS NTAPI MmUnmapCacheViewInSystemSpace ( IN PVOID  MappedBase)

Definition at line 830 of file data.c.

Referenced by CcpDereferenceCache(), and CcpUnmapCache().

831 {
834 
835  DPRINT("MmUnmapViewInSystemSpace() called\n");
836 
837  AddressSpace = MmGetKernelAddressSpace();
838 
839  Status = MmUnmapViewOfCacheSegment(AddressSpace, MappedBase);
840 
841  return Status;
842 }
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG AddressSpace
Definition: iofuncs.h:2268
void DPRINT(...)
Definition: polytest.cpp:61
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI MmUnmapViewOfCacheSegment(PMMSUPPORT AddressSpace, PVOID BaseAddress)
Definition: data.c:713
FORCEINLINE PMMSUPPORT MmGetKernelAddressSpace(VOID)
Definition: mm.h:1432
_Must_inspect_result_ _Outptr_result_bytebuffer_ ViewSize PVOID * MappedBase
Definition: mmfuncs.h:493
NTSTATUS NTAPI MmUnmapViewOfCacheSegment ( PMMSUPPORT  AddressSpace,
PVOID  BaseAddress 
)

Definition at line 713 of file data.c.

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

715 {
716  PVOID Context[2];
719 
720  MemoryArea = MmLocateMemoryAreaByAddress(AddressSpace, BaseAddress);
721  if (MemoryArea == NULL || MemoryArea->DeleteInProgress)
722  {
723  ASSERT(MemoryArea);
724  return STATUS_UNSUCCESSFUL;
725  }
726 
727  MemoryArea->DeleteInProgress = TRUE;
728  Segment = MemoryArea->Data.SectionData.Segment;
729  MemoryArea->Data.SectionData.Segment = NULL;
730 
731  MmLockSectionSegment(Segment);
732 
733  Context[0] = AddressSpace;
734  Context[1] = Segment;
735 
736  DPRINT("MmFreeMemoryArea(%p,%p)\n",
737  MmGetAddressSpaceOwner(AddressSpace),
738  MA_GetStartingAddress(MemoryArea));
739 
740  MmLockAddressSpace(AddressSpace);
741 
742  MmFreeMemoryArea(AddressSpace, MemoryArea, MmFreeCacheSectionPage, Context);
743 
744  MmUnlockAddressSpace(AddressSpace);
745 
746  MmUnlockSectionSegment(Segment);
747 
748  DPRINTC("MiUnmapViewOfSegment %p %p %p\n",
749  MmGetAddressSpaceOwner(AddressSpace),
750  BaseAddress,
751  Segment);
752 
753  return STATUS_SUCCESS;
754 }
DWORD *typedef PVOID
Definition: winlogon.h:61
#define DPRINTC
Definition: data.c:84
#define TRUE
Definition: types.h:120
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG AddressSpace
Definition: iofuncs.h:2268
FORCEINLINE VOID MmUnlockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1410
PMEMORY_AREA NTAPI MmLocateMemoryAreaByAddress(PMMSUPPORT AddressSpace, PVOID Address)
Definition: marea.c:60
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
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
struct _MEMORY_AREA::@1716::@1717 SectionData
#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:1417
#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
union _MEMORY_AREA::@1716 Data
#define MmUnlockSectionSegment(x)
Definition: newmm.h:284
return STATUS_SUCCESS
Definition: btrfs.c:2710
struct _MEMORY_AREA * MemoryArea
Definition: newmm.h:65
FORCEINLINE VOID MmLockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1403

Variable Documentation

KSPIN_LOCK MiSectionPageTableLock
LIST_ENTRY MiSegmentList

Definition at line 86 of file data.c.

PMMWSL MmWorkingSetList

Definition at line 21 of file procsup.c.

Referenced by MiInitMachineDependent(), and MmCreateProcessAddressSpace().

KEVENT MpwThreadEvent