ReactOS  0.4.15-dev-2355-gaf9df93
section.c File Reference
#include <ntoskrnl.h>
#include <cache/newcc.h>
#include <cache/section/newmm.h>
#include <debug.h>
#include <reactos/exeformat.h>
#include "ARM3/miarm.h"
Include dependency graph for section.c:

Go to the source code of this file.

Classes

struct  MM_SECTION_PAGEOUT_CONTEXT
 

Macros

#define NDEBUG
 
#define MmSetPageEntrySectionSegment(S, O, E)
 
#define DIE(ARGS_)   { DPRINT ARGS_; goto l_Return; }
 

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)
 
static PMM_SECTION_SEGMENT MiGrabDataSection (PSECTION_OBJECT_POINTERS SectionObjectPointer)
 
PMM_IMAGE_SECTION_OBJECT ImageSectionObjectFromSegment (PMM_SECTION_SEGMENT Segment)
 
NTSTATUS MiMapViewInSystemSpace (IN PVOID Section, IN PVOID Session, OUT PVOID *MappedBase, IN OUT PSIZE_T ViewSize, IN PLARGE_INTEGER SectionOffset)
 
NTSTATUS NTAPI MmCreateArm3Section (OUT PVOID *SectionObject, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN PLARGE_INTEGER InputMaximumSize, IN ULONG SectionPageProtection, IN ULONG AllocationAttributes, IN HANDLE FileHandle OPTIONAL, IN PFILE_OBJECT FileObject OPTIONAL)
 
NTSTATUS NTAPI MmMapViewOfArm3Section (IN PVOID SectionObject, IN PEPROCESS Process, IN OUT PVOID *BaseAddress, IN ULONG_PTR ZeroBits, IN SIZE_T CommitSize, IN OUT PLARGE_INTEGER SectionOffset OPTIONAL, IN OUT PSIZE_T ViewSize, IN SECTION_INHERIT InheritDisposition, IN ULONG AllocationType, IN ULONG Protect)
 
 C_ASSERT (EXEFMT_LOAD_HEADER_SIZE >=sizeof(IMAGE_DOS_HEADER))
 
 C_ASSERT (sizeof(IMAGE_NT_HEADERS32)<=sizeof(IMAGE_NT_HEADERS64))
 
 C_ASSERT (TYPE_ALIGNMENT(IMAGE_NT_HEADERS32)==TYPE_ALIGNMENT(IMAGE_NT_HEADERS64))
 
 C_ASSERT (RTL_SIZEOF_THROUGH_FIELD(IMAGE_NT_HEADERS32, FileHeader)==RTL_SIZEOF_THROUGH_FIELD(IMAGE_NT_HEADERS64, FileHeader))
 
 C_ASSERT (FIELD_OFFSET(IMAGE_NT_HEADERS32, OptionalHeader)==FIELD_OFFSET(IMAGE_NT_HEADERS64, OptionalHeader))
 
 C_ASSERT (PEFMT_FIELDS_EQUAL(IMAGE_OPTIONAL_HEADER32, IMAGE_OPTIONAL_HEADER64, Magic))
 
 C_ASSERT (PEFMT_FIELDS_EQUAL(IMAGE_OPTIONAL_HEADER32, IMAGE_OPTIONAL_HEADER64, SectionAlignment))
 
 C_ASSERT (PEFMT_FIELDS_EQUAL(IMAGE_OPTIONAL_HEADER32, IMAGE_OPTIONAL_HEADER64, FileAlignment))
 
 C_ASSERT (PEFMT_FIELDS_EQUAL(IMAGE_OPTIONAL_HEADER32, IMAGE_OPTIONAL_HEADER64, Subsystem))
 
 C_ASSERT (PEFMT_FIELDS_EQUAL(IMAGE_OPTIONAL_HEADER32, IMAGE_OPTIONAL_HEADER64, MinorSubsystemVersion))
 
 C_ASSERT (PEFMT_FIELDS_EQUAL(IMAGE_OPTIONAL_HEADER32, IMAGE_OPTIONAL_HEADER64, MajorSubsystemVersion))
 
 C_ASSERT (PEFMT_FIELDS_EQUAL(IMAGE_OPTIONAL_HEADER32, IMAGE_OPTIONAL_HEADER64, AddressOfEntryPoint))
 
 C_ASSERT (PEFMT_FIELDS_EQUAL(IMAGE_OPTIONAL_HEADER32, IMAGE_OPTIONAL_HEADER64, SizeOfCode))
 
 C_ASSERT (PEFMT_FIELDS_EQUAL(IMAGE_OPTIONAL_HEADER32, IMAGE_OPTIONAL_HEADER64, SizeOfHeaders))
 
ACCESS_MASK NTAPI MiArm3GetCorrectFileAccessMask (IN ACCESS_MASK SectionPageProtection)
 
NTSTATUS NTAPI MiWritePage (PMM_SECTION_SEGMENT Segment, LONGLONG SegOffset, PFN_NUMBER Page)
 
NTSTATUS NTAPI PeFmtCreateSection (IN CONST VOID *FileHeader, IN SIZE_T FileHeaderSize, IN PVOID File, OUT PMM_IMAGE_SECTION_OBJECT ImageSectionObject, OUT PULONG Flags, IN PEXEFMT_CB_READ_FILE ReadFileCb, IN PEXEFMT_CB_ALLOCATE_SEGMENTS AllocateSegmentsCb)
 
NTSTATUS MmspWaitForFileLock (PFILE_OBJECT File)
 
VOID NTAPI MmpFreePageFileSegment (PMM_SECTION_SEGMENT Segment)
 
static VOID NTAPI FreeSegmentPage (PMM_SECTION_SEGMENT Segment, PLARGE_INTEGER Offset)
 
VOID NTAPI MmDereferenceSegment (PMM_SECTION_SEGMENT Segment)
 
VOID NTAPI MmSharePageEntrySectionSegment (PMM_SECTION_SEGMENT Segment, PLARGE_INTEGER Offset)
 
BOOLEAN NTAPI MmUnsharePageEntrySectionSegment (PMEMORY_AREA MemoryArea, PMM_SECTION_SEGMENT Segment, PLARGE_INTEGER Offset, BOOLEAN Dirty, BOOLEAN PageOut, ULONG_PTR *InEntry)
 
static NTSTATUS MiCopyFromUserPage (PFN_NUMBER DestPage, const VOID *SrcAddress)
 
static NTSTATUS NTAPI MmMakeSegmentResident (_In_ PMM_SECTION_SEGMENT Segment, _In_ LONGLONG Offset, _In_ ULONG Length, _In_opt_ PLARGE_INTEGER ValidDataLength)
 
static VOID MmAlterViewAttributes (PMMSUPPORT AddressSpace, PVOID BaseAddress, SIZE_T RegionSize, ULONG OldType, ULONG OldProtect, ULONG NewType, ULONG NewProtect)
 
NTSTATUS NTAPI MmNotPresentFaultSectionView (PMMSUPPORT AddressSpace, MEMORY_AREA *MemoryArea, PVOID Address, BOOLEAN Locked)
 
NTSTATUS NTAPI MmAccessFaultSectionView (PMMSUPPORT AddressSpace, MEMORY_AREA *MemoryArea, PVOID Address, BOOLEAN Locked)
 
NTSTATUS NTAPI MmProtectSectionView (PMMSUPPORT AddressSpace, PMEMORY_AREA MemoryArea, PVOID BaseAddress, SIZE_T Length, ULONG Protect, PULONG OldProtect)
 
NTSTATUS NTAPI MmQuerySectionView (PMEMORY_AREA MemoryArea, PVOID Address, PMEMORY_BASIC_INFORMATION Info, PSIZE_T ResultLength)
 
VOID NTAPI MmpDeleteSection (PVOID ObjectBody)
 
VOID NTAPI MmpCloseSection (IN PEPROCESS Process OPTIONAL, IN PVOID Object, IN ACCESS_MASK GrantedAccess, IN ULONG ProcessHandleCount, IN ULONG SystemHandleCount)
 
NTSTATUS NTAPI MmCreatePhysicalMemorySection (VOID)
 
NTSTATUS NTAPI MmInitSectionImplementation (VOID)
 
static NTSTATUS NTAPI MmCreateDataFileSection (PSECTION *SectionObject, ACCESS_MASK DesiredAccess, POBJECT_ATTRIBUTES ObjectAttributes, PLARGE_INTEGER UMaximumSize, ULONG SectionPageProtection, ULONG AllocationAttributes, PFILE_OBJECT FileObject, BOOLEAN GotFileHandle)
 
NTSTATUS NTAPI ElfFmtCreateSection (IN CONST VOID *FileHeader, IN SIZE_T FileHeaderSize, IN PVOID File, OUT PMM_IMAGE_SECTION_OBJECT ImageSectionObject, OUT PULONG Flags, IN PEXEFMT_CB_READ_FILE ReadFileCb, IN PEXEFMT_CB_ALLOCATE_SEGMENTS AllocateSegmentsCb)
 
static PMM_SECTION_SEGMENT NTAPI ExeFmtpAllocateSegments (IN ULONG NrSegments)
 
static NTSTATUS NTAPI ExeFmtpReadFile (IN PVOID File, IN PLARGE_INTEGER Offset, IN ULONG Length, OUT PVOID *Data, OUT PVOID *AllocBase, OUT PULONG ReadSize)
 
static VOID NTAPI MmspAssertSegmentsSorted (IN PMM_IMAGE_SECTION_OBJECT ImageSectionObject)
 
static VOID NTAPI MmspAssertSegmentsNoOverlap (IN PMM_IMAGE_SECTION_OBJECT ImageSectionObject)
 
static VOID NTAPI MmspAssertSegmentsPageAligned (IN PMM_IMAGE_SECTION_OBJECT ImageSectionObject)
 
static int __cdecl MmspCompareSegments (const void *x, const void *y)
 
static VOID NTAPI MmspSortSegments (IN OUT PMM_IMAGE_SECTION_OBJECT ImageSectionObject, IN ULONG Flags)
 
static BOOLEAN NTAPI MmspCheckSegmentBounds (IN OUT PMM_IMAGE_SECTION_OBJECT ImageSectionObject, IN ULONG Flags)
 
static BOOLEAN NTAPI MmspPageAlignSegments (IN OUT PMM_IMAGE_SECTION_OBJECT ImageSectionObject, IN ULONG Flags)
 
NTSTATUS ExeFmtpCreateImageSection (PFILE_OBJECT FileObject, PMM_IMAGE_SECTION_OBJECT ImageSectionObject)
 
NTSTATUS MmCreateImageSection (PSECTION *SectionObject, ACCESS_MASK DesiredAccess, POBJECT_ATTRIBUTES ObjectAttributes, PLARGE_INTEGER UMaximumSize, ULONG SectionPageProtection, ULONG AllocationAttributes, PFILE_OBJECT FileObject)
 
static NTSTATUS MmMapViewOfSegment (PMMSUPPORT AddressSpace, BOOLEAN AsImage, PMM_SECTION_SEGMENT Segment, PVOID *BaseAddress, SIZE_T ViewSize, ULONG Protect, LONGLONG ViewOffset, ULONG AllocationType)
 
static VOID MmFreeSectionPage (PVOID Context, MEMORY_AREA *MemoryArea, PVOID Address, PFN_NUMBER Page, SWAPENTRY SwapEntry, BOOLEAN Dirty)
 
static NTSTATUS MmUnmapViewOfSegment (PMMSUPPORT AddressSpace, PVOID BaseAddress)
 
NTSTATUS NTAPI MiRosUnmapViewOfSection (IN PEPROCESS Process, IN PVOID BaseAddress, IN BOOLEAN SkipDebuggerNotify)
 
NTSTATUS NTAPI NtQuerySection (_In_ HANDLE SectionHandle, _In_ SECTION_INFORMATION_CLASS SectionInformationClass, _Out_ PVOID SectionInformation, _In_ SIZE_T SectionInformationLength, _Out_opt_ PSIZE_T ResultLength)
 
NTSTATUS NTAPI MmMapViewOfSection (IN PVOID SectionObject, IN PEPROCESS Process, IN OUT PVOID *BaseAddress, IN ULONG_PTR ZeroBits, IN SIZE_T CommitSize, IN OUT PLARGE_INTEGER SectionOffset OPTIONAL, IN OUT PSIZE_T ViewSize, IN SECTION_INHERIT InheritDisposition, IN ULONG AllocationType, IN ULONG Protect)
 
BOOLEAN NTAPI MmCanFileBeTruncated (IN PSECTION_OBJECT_POINTERS SectionObjectPointer, IN PLARGE_INTEGER NewFileSize)
 
BOOLEAN NTAPI MmFlushImageSection (IN PSECTION_OBJECT_POINTERS SectionObjectPointer, IN MMFLUSH_TYPE FlushType)
 
NTSTATUS NTAPI MmMapViewInSystemSpace (IN PVOID SectionObject, OUT PVOID *MappedBase, IN OUT PSIZE_T ViewSize)
 
NTSTATUS NTAPI MmMapViewInSystemSpaceEx (_In_ PVOID SectionObject, _Outptr_result_bytebuffer_(*ViewSize) PVOID *MappedBase, _Inout_ PSIZE_T ViewSize, _Inout_ PLARGE_INTEGER SectionOffset, _In_ ULONG_PTR Flags)
 
NTSTATUS NTAPI MiRosUnmapViewInSystemSpace (IN PVOID MappedBase)
 
NTSTATUS NTAPI MmCreateSection (OUT PVOID *Section, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN PLARGE_INTEGER MaximumSize, IN ULONG SectionPageProtection, IN ULONG AllocationAttributes, IN HANDLE FileHandle OPTIONAL, IN PFILE_OBJECT FileObject OPTIONAL)
 
BOOLEAN NTAPI MmArePagesResident (_In_ PEPROCESS Process, _In_ PVOID Address, _In_ ULONG Length)
 
BOOLEAN NTAPI MmPurgeSegment (_In_ PSECTION_OBJECT_POINTERS SectionObjectPointer, _In_opt_ PLARGE_INTEGER Offset, _In_ ULONG Length)
 
NTSTATUS NTAPI MmMakeDataSectionResident (_In_ PSECTION_OBJECT_POINTERS SectionObjectPointer, _In_ LONGLONG Offset, _In_ ULONG Length, _In_ PLARGE_INTEGER ValidDataLength)
 
NTSTATUS NTAPI MmFlushSegment (_In_ PSECTION_OBJECT_POINTERS SectionObjectPointer, _In_opt_ PLARGE_INTEGER Offset, _In_ ULONG Length, _In_opt_ PIO_STATUS_BLOCK Iosb)
 
 _Requires_exclusive_lock_held_ (Segment->Lock) BOOLEAN NTAPI MmCheckDirtySegment(PMM_SECTION_SEGMENT Segment
 
 ASSERT (Segment->Locked)
 
 ASSERT ((Offset->QuadPart % PAGE_SIZE)==0)
 
 DPRINT ("Checking segment for file %wZ at offset 0x%I64X.\n", &Segment->FileObject->FileName, Offset->QuadPart)
 
 if (Entry==0)
 
 if (!IS_DIRTY_SSE(Entry) &&(SHARE_COUNT_FROM_SSE(Entry)==0) &&PageOut)
 
NTSTATUS NTAPI MmMakePagesDirty (_In_ PEPROCESS Process, _In_ PVOID Address, _In_ ULONG Length)
 
NTSTATUS NTAPI MmExtendSection (_In_ PVOID _Section, _Inout_ PLARGE_INTEGER NewSize)
 

Variables

MMSESSION MmSession
 
static LARGE_INTEGER TinyTime = {{-1L, -1L}}
 
KEVENT MmWaitPageEvent
 
POBJECT_TYPE MmSectionObjectType = NULL
 
ULONG_PTR MmSubsectionBase
 
static ULONG SectionCharacteristicsToProtect [16]
 
ULONG MmMakeFileAccess []
 
static GENERIC_MAPPING MmpSectionMapping
 
static PEXEFMT_LOADER ExeFmtpLoaders []
 
PLARGE_INTEGER Offset
 
PLARGE_INTEGER BOOLEAN ForceDirty
 
PLARGE_INTEGER BOOLEAN BOOLEAN PageOut
 
NTSTATUS Status
 
PFN_NUMBER Page
 
 Entry = MmGetPageEntrySectionSegment(Segment, Offset)
 
return FALSE
 

Macro Definition Documentation

◆ DIE

#define DIE (   ARGS_)    { DPRINT ARGS_; goto l_Return; }

◆ MmSetPageEntrySectionSegment

#define MmSetPageEntrySectionSegment (   S,
  O,
  E 
)
Value:
do { \
DPRINT("SetPageEntrySectionSegment(old,%p,%x,%x)\n",(S),(O)->LowPart,E); \
_MmSetPageEntrySectionSegment((S),(O),(E),__FILE__,__LINE__); \
} while (0)
static const WCHAR O[]
Definition: oid.c:1251
Definition: movable.cpp:7
static const WCHAR E[]
Definition: oid.c:1253

Definition at line 56 of file section.c.

◆ NDEBUG

#define NDEBUG

Definition at line 50 of file section.c.

Function Documentation

◆ _MmLockSectionSegment()

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

Definition at line 70 of file section.c.

71 {
72  //DPRINT("MmLockSectionSegment(%p,%s:%d)\n", Segment, file, line);
74  Segment->Locked = TRUE;
75 }
#define TRUE
Definition: types.h:120
_Inout_ PVOID Segment
Definition: exfuncs.h:1101
VOID FASTCALL ExAcquireFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:23

◆ _MmUnlockSectionSegment()

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

Definition at line 79 of file section.c.

80 {
81  ASSERT(Segment->Locked);
82  Segment->Locked = FALSE;
84  //DPRINT("MmUnlockSectionSegment(%p,%s:%d)\n", Segment, file, line);
85 }
VOID FASTCALL ExReleaseFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:31
ASSERT(Segment->Locked)
return FALSE
Definition: section.c:4880
_Inout_ PVOID Segment
Definition: exfuncs.h:1101

◆ _Requires_exclusive_lock_held_()

_Requires_exclusive_lock_held_ ( Segment->  Lock)

◆ ASSERT() [1/2]

ASSERT ( Segment->  Locked)

Referenced by _MmUnlockSectionSegment(), ExeFmtpCreateImageSection(), ExeFmtpReadFile(), FreeSegmentPage(), ImageSectionObjectFromSegment(), MiAddMappedPtes(), MiCheckControlArea(), MiCheckPurgeAndUpMapCount(), MiCopyFromUserPage(), MiCreateDataFileMap(), MiCreatePagingFileMap(), MiDeleteARM3Section(), MiFillSystemPageDirectory(), MiFlushTbAndCapture(), MiGetFileObjectForSectionAddress(), MiGetFileObjectForVad(), MiGrabDataSection(), MiInitializeSystemSpaceMap(), MiInsertInSystemSpace(), MiLocateSubsection(), MiMakeProtectionMask(), MiMapViewInSystemSpace(), MiMapViewOfDataSection(), MiRemoveMappedPtes(), MiRemoveMappedView(), MiRosUnmapViewOfSection(), MiSegmentDelete(), MiSessionCommitPageTables(), MiSetControlAreaSymbolsLoaded(), MiSetProtectionOnSection(), MiSubsectionConsistent(), MiUnmapViewOfSection(), MmAccessFaultSectionView(), MmAlterViewAttributes(), MmArePagesResident(), MmCommitSessionMappedView(), MmCreateArm3Section(), MmCreateDataFileSection(), MmCreateImageSection(), MmDereferenceSegment(), MmFlushSegment(), MmFreeSectionPage(), MmGetFileObjectForSection(), MmGetImageInformation(), MmInitSectionImplementation(), MmMakeDataSectionResident(), MmMakePagesDirty(), MmMakeSegmentResident(), MmMapViewInSessionSpace(), MmMapViewOfArm3Section(), MmMapViewOfSection(), MmMapViewOfSegment(), MmNotPresentFaultSectionView(), MmpDeleteSection(), MmProtectSectionView(), MmPurgeSegment(), MmspAssertSegmentsNoOverlap(), MmspAssertSegmentsPageAligned(), MmspAssertSegmentsSorted(), MmspCheckSegmentBounds(), MmspPageAlignSegments(), MmUnmapViewInSessionSpace(), MmUnsharePageEntrySectionSegment(), NtQuerySection(), and PeFmtCreateSection().

◆ ASSERT() [2/2]

ASSERT ( (Offset->QuadPart % PAGE_SIZE = =0)

◆ C_ASSERT() [1/14]

C_ASSERT ( EXEFMT_LOAD_HEADER_SIZE >=  sizeofIMAGE_DOS_HEADER)

◆ C_ASSERT() [2/14]

◆ C_ASSERT() [3/14]

◆ C_ASSERT() [4/14]

◆ C_ASSERT() [5/14]

C_ASSERT ( FIELD_OFFSET(IMAGE_NT_HEADERS32, OptionalHeader)  = =FIELD_OFFSET(IMAGE_NT_HEADERS64, OptionalHeader))

◆ C_ASSERT() [6/14]

◆ C_ASSERT() [7/14]

◆ C_ASSERT() [8/14]

◆ C_ASSERT() [9/14]

◆ C_ASSERT() [10/14]

C_ASSERT ( PEFMT_FIELDS_EQUAL(IMAGE_OPTIONAL_HEADER32, IMAGE_OPTIONAL_HEADER64, MinorSubsystemVersion)  )

◆ C_ASSERT() [11/14]

C_ASSERT ( PEFMT_FIELDS_EQUAL(IMAGE_OPTIONAL_HEADER32, IMAGE_OPTIONAL_HEADER64, MajorSubsystemVersion)  )

◆ C_ASSERT() [12/14]

◆ C_ASSERT() [13/14]

◆ C_ASSERT() [14/14]

◆ DPRINT()

◆ ElfFmtCreateSection()

NTSTATUS NTAPI ElfFmtCreateSection ( IN CONST VOID FileHeader,
IN SIZE_T  FileHeaderSize,
IN PVOID  File,
OUT PMM_IMAGE_SECTION_OBJECT  ImageSectionObject,
OUT PULONG  Flags,
IN PEXEFMT_CB_READ_FILE  ReadFileCb,
IN PEXEFMT_CB_ALLOCATE_SEGMENTS  AllocateSegmentsCb 
)

◆ ExeFmtpAllocateSegments()

static PMM_SECTION_SEGMENT NTAPI ExeFmtpAllocateSegments ( IN ULONG  NrSegments)
static

Definition at line 2521 of file section.c.

2522 {
2523  SIZE_T SizeOfSegments;
2524  PMM_SECTION_SEGMENT Segments;
2525 
2526  /* TODO: check for integer overflow */
2527  SizeOfSegments = sizeof(MM_SECTION_SEGMENT) * NrSegments;
2528 
2530  SizeOfSegments,
2532 
2533  if(Segments)
2534  RtlZeroMemory(Segments, SizeOfSegments);
2535 
2536  return Segments;
2537 }
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define TAG_MM_SECTION_SEGMENT
Definition: tag.h:139
struct _MM_SECTION_SEGMENT MM_SECTION_SEGMENT
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262

Referenced by ExeFmtpCreateImageSection().

◆ ExeFmtpCreateImageSection()

NTSTATUS ExeFmtpCreateImageSection ( PFILE_OBJECT  FileObject,
PMM_IMAGE_SECTION_OBJECT  ImageSectionObject 
)

Definition at line 2955 of file section.c.

2957 {
2959  PVOID FileHeader;
2960  PVOID FileHeaderBuffer;
2961  ULONG FileHeaderSize;
2962  ULONG Flags;
2963  ULONG OldNrSegments;
2964  NTSTATUS Status;
2965  ULONG i;
2966 
2967  /*
2968  * Read the beginning of the file (2 pages). Should be enough to contain
2969  * all (or most) of the headers
2970  */
2971  Offset.QuadPart = 0;
2972 
2974  &Offset,
2975  PAGE_SIZE * 2,
2976  &FileHeader,
2977  &FileHeaderBuffer,
2978  &FileHeaderSize);
2979 
2980  if (!NT_SUCCESS(Status))
2981  return Status;
2982 
2983  if (FileHeaderSize == 0)
2984  {
2985  ExFreePool(FileHeaderBuffer);
2986  return STATUS_UNSUCCESSFUL;
2987  }
2988 
2989  /*
2990  * Look for a loader that can handle this executable
2991  */
2992  for (i = 0; i < RTL_NUMBER_OF(ExeFmtpLoaders); ++ i)
2993  {
2994  Flags = 0;
2995 
2996  Status = ExeFmtpLoaders[i](FileHeader,
2997  FileHeaderSize,
2998  FileObject,
2999  ImageSectionObject,
3000  &Flags,
3003 
3004  if (!NT_SUCCESS(Status))
3005  {
3006  if (ImageSectionObject->Segments)
3007  {
3008  ExFreePool(ImageSectionObject->Segments);
3009  ImageSectionObject->Segments = NULL;
3010  }
3011  }
3012 
3014  break;
3015  }
3016 
3017  ExFreePoolWithTag(FileHeaderBuffer, 'rXmM');
3018 
3019  /*
3020  * No loader handled the format
3021  */
3023  {
3026  }
3027 
3028  if (!NT_SUCCESS(Status))
3029  return Status;
3030 
3031  ASSERT(ImageSectionObject->Segments != NULL);
3032  ASSERT(ImageSectionObject->RefCount > 0);
3033 
3034  /*
3035  * Some defaults
3036  */
3037  /* FIXME? are these values platform-dependent? */
3038  if (ImageSectionObject->ImageInformation.MaximumStackSize == 0)
3039  ImageSectionObject->ImageInformation.MaximumStackSize = 0x40000;
3040 
3041  if(ImageSectionObject->ImageInformation.CommittedStackSize == 0)
3042  ImageSectionObject->ImageInformation.CommittedStackSize = 0x1000;
3043 
3044  if(ImageSectionObject->BasedAddress == NULL)
3045  {
3046  if(ImageSectionObject->ImageInformation.ImageCharacteristics & IMAGE_FILE_DLL)
3047  ImageSectionObject->BasedAddress = (PVOID)0x10000000;
3048  else
3049  ImageSectionObject->BasedAddress = (PVOID)0x00400000;
3050  }
3051 
3052  /*
3053  * And now the fun part: fixing the segments
3054  */
3055 
3056  /* Sort them by virtual address */
3057  MmspSortSegments(ImageSectionObject, Flags);
3058 
3059  /* Ensure they don't overlap in memory */
3060  if (!MmspCheckSegmentBounds(ImageSectionObject, Flags))
3062 
3063  /* Ensure they are aligned */
3064  OldNrSegments = ImageSectionObject->NrSegments;
3065 
3066  if (!MmspPageAlignSegments(ImageSectionObject, Flags))
3068 
3069  /* Trim them if the alignment phase merged some of them */
3070  if (ImageSectionObject->NrSegments < OldNrSegments)
3071  {
3072  PMM_SECTION_SEGMENT Segments;
3073  SIZE_T SizeOfSegments;
3074 
3075  SizeOfSegments = sizeof(MM_SECTION_SEGMENT) * ImageSectionObject->NrSegments;
3076 
3077  Segments = ExAllocatePoolWithTag(PagedPool,
3078  SizeOfSegments,
3080 
3081  if (Segments == NULL)
3083 
3084  RtlCopyMemory(Segments, ImageSectionObject->Segments, SizeOfSegments);
3085  ExFreePool(ImageSectionObject->Segments);
3086  ImageSectionObject->Segments = Segments;
3087  }
3088 
3089  /* And finish their initialization */
3090  for ( i = 0; i < ImageSectionObject->NrSegments; ++ i )
3091  {
3092  ExInitializeFastMutex(&ImageSectionObject->Segments[i].Lock);
3093  ImageSectionObject->Segments[i].ReferenceCount = &ImageSectionObject->RefCount;
3094  ImageSectionObject->Segments[i].Flags = &ImageSectionObject->SegFlags;
3095  MiInitializeSectionPageTable(&ImageSectionObject->Segments[i]);
3096  ImageSectionObject->Segments[i].FileObject = FileObject;
3097  }
3098 
3099  ASSERT(ImageSectionObject->RefCount > 0);
3100 
3101  ImageSectionObject->FileObject = FileObject;
3102 
3104  return Status;
3105 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
LONG NTSTATUS
Definition: precomp.h:26
#define IMAGE_FILE_DLL
Definition: pedump.c:169
static BOOLEAN NTAPI MmspPageAlignSegments(IN OUT PMM_IMAGE_SECTION_OBJECT ImageSectionObject, IN ULONG Flags)
Definition: section.c:2772
static VOID NTAPI MmspSortSegments(IN OUT PMM_IMAGE_SECTION_OBJECT ImageSectionObject, IN ULONG Flags)
Definition: section.c:2695
ASSERT(Segment->Locked)
NTSTATUS Status
Definition: section.c:4755
void * PVOID
Definition: retypes.h:9
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
Status
Definition: gdiplustypes.h:24
static PMM_SECTION_SEGMENT NTAPI ExeFmtpAllocateSegments(IN ULONG NrSegments)
Definition: section.c:2521
#define STATUS_INVALID_IMAGE_NOT_MZ
Definition: ntstatus.h:539
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define STATUS_INVALID_IMAGE_FORMAT
Definition: ntstatus.h:359
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
static PEXEFMT_LOADER ExeFmtpLoaders[]
Definition: section.c:2510
static NTSTATUS NTAPI ExeFmtpReadFile(IN PVOID File, IN PLARGE_INTEGER Offset, IN ULONG Length, OUT PVOID *Data, OUT PVOID *AllocBase, OUT PULONG ReadSize)
Definition: section.c:2541
#define PAGE_SIZE
Definition: env_spec_w32.h:49
VOID NTAPI MiInitializeSectionPageTable(PMM_SECTION_SEGMENT Segment)
Definition: sptab.c:165
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
ULONG_PTR SIZE_T
Definition: typedefs.h:80
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 TAG_MM_SECTION_SEGMENT
Definition: tag.h:139
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
PLARGE_INTEGER Offset
Definition: section.c:4750
#define NULL
Definition: types.h:112
struct _MM_SECTION_SEGMENT MM_SECTION_SEGMENT
#define STATUS_ROS_EXEFMT_UNKNOWN_FORMAT
Definition: exeformat.h:72
unsigned int ULONG
Definition: retypes.h:1
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
static BOOLEAN NTAPI MmspCheckSegmentBounds(IN OUT PMM_IMAGE_SECTION_OBJECT ImageSectionObject, IN ULONG Flags)
Definition: section.c:2721

Referenced by MmCreateImageSection().

◆ ExeFmtpReadFile()

static NTSTATUS NTAPI ExeFmtpReadFile ( IN PVOID  File,
IN PLARGE_INTEGER  Offset,
IN ULONG  Length,
OUT PVOID Data,
OUT PVOID AllocBase,
OUT PULONG  ReadSize 
)
static

Definition at line 2541 of file section.c.

2547 {
2548  NTSTATUS Status;
2550  ULONG AdjustOffset;
2551  ULONG OffsetAdjustment;
2552  ULONG BufferSize;
2553  ULONG UsedSize;
2554  PVOID Buffer;
2557 
2559 
2560  if(Length == 0)
2561  {
2562  KeBugCheck(MEMORY_MANAGEMENT);
2563  }
2564 
2565  FileOffset = *Offset;
2566 
2567  /* Negative/special offset: it cannot be used in this context */
2568  if(FileOffset.u.HighPart < 0)
2569  {
2570  KeBugCheck(MEMORY_MANAGEMENT);
2571  }
2572 
2573  AdjustOffset = PAGE_ROUND_DOWN(FileOffset.u.LowPart);
2574  OffsetAdjustment = FileOffset.u.LowPart - AdjustOffset;
2575  FileOffset.u.LowPart = AdjustOffset;
2576 
2577  BufferSize = Length + OffsetAdjustment;
2579 
2580  /*
2581  * It's ok to use paged pool, because this is a temporary buffer only used in
2582  * the loading of executables. The assumption is that MmCreateSection is
2583  * always called at low IRQLs and that these buffers don't survive a brief
2584  * initialization phase
2585  */
2587  if (!Buffer)
2588  {
2590  }
2591 
2593 
2594  UsedSize = (ULONG)Iosb.Information;
2595 
2596  if(NT_SUCCESS(Status) && UsedSize < OffsetAdjustment)
2597  {
2600  }
2601 
2602  if(NT_SUCCESS(Status))
2603  {
2604  *Data = (PVOID)((ULONG_PTR)Buffer + OffsetAdjustment);
2605  *AllocBase = Buffer;
2606  *ReadSize = UsedSize - OffsetAdjustment;
2607  }
2608  else
2609  {
2610  ExFreePoolWithTag(Buffer, 'rXmM');
2611  }
2612 
2613  return Status;
2614 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
#define PAGE_ROUND_DOWN(x)
Definition: mmtypes.h:36
uint32_t ULONG_PTR
Definition: typedefs.h:65
ASSERT(Segment->Locked)
DECLSPEC_NORETURN VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1427
NTSTATUS Status
Definition: section.c:4755
Definition: bufpool.h:45
void * PVOID
Definition: retypes.h:9
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
Status
Definition: gdiplustypes.h:24
return Iosb
Definition: create.c:4402
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
* PFILE_OBJECT
Definition: iotypes.h:1998
#define ASSERT_IRQL_LESS(x)
Definition: debug.h:253
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:159
PLARGE_INTEGER Offset
Definition: section.c:4750
#define PAGE_ROUND_UP(x)
Definition: mmtypes.h:38
unsigned int ULONG
Definition: retypes.h:1
#define STATUS_IN_PAGE_ERROR
Definition: ntstatus.h:243
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
_Must_inspect_result_ _In_ WDFDEVICE _In_ BOOLEAN _In_opt_ PVOID _In_ LONG _In_z_ PCHAR File
Definition: wdfdevice.h:4061
#define BufferSize
Definition: mmc.h:75
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:251
NTSTATUS NTAPI MiSimpleRead(PFILE_OBJECT FileObject, PLARGE_INTEGER FileOffset, PVOID Buffer, ULONG Length, BOOLEAN Paging, PIO_STATUS_BLOCK ReadStatus)
Definition: io.c:109

Referenced by ExeFmtpCreateImageSection().

◆ FreeSegmentPage()

static VOID NTAPI FreeSegmentPage ( PMM_SECTION_SEGMENT  Segment,
PLARGE_INTEGER  Offset 
)
static

Definition at line 961 of file section.c.

962 {
965 
967 
969 
971 
972  /* This must be either a valid entry or nothing */
974 
975  /* There should be no reference anymore */
977 
979  /* If there is a page, this must be because it's still dirty */
980  ASSERT(Page != 0);
981 
982  /* Write the page */
983  if (IS_DIRTY_SSE(Entry))
984  MiWritePage(Segment, Offset->QuadPart, Page);
985 
987 }
#define MmGetPageEntrySectionSegment(S, O)
Definition: mm.h:1463
#define MC_USER
Definition: mm.h:92
#define PFN_FROM_SSE(E)
Definition: mm.h:1259
NTSTATUS NTAPI MmReleasePageMemoryConsumer(ULONG Consumer, PFN_NUMBER Page)
Definition: balance.c:77
#define MmLockSectionSegment(x)
Definition: mm.h:1284
uint32_t ULONG_PTR
Definition: typedefs.h:65
ASSERT(Segment->Locked)
ULONG PFN_NUMBER
Definition: ke.h:9
#define IS_DIRTY_SSE(E)
Definition: mm.h:1268
Entry
Definition: section.c:4764
PFN_NUMBER Page
Definition: section.c:4756
#define MmUnlockSectionSegment(x)
Definition: mm.h:1292
_Inout_ PVOID Segment
Definition: exfuncs.h:1101
NTSTATUS NTAPI MiWritePage(PMM_SECTION_SEGMENT Segment, LONGLONG SegOffset, PFN_NUMBER Page)
Definition: section.c:239
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define IS_SWAP_FROM_SSE(E)
Definition: mm.h:1260
#define SHARE_COUNT_FROM_SSE(E)
Definition: mm.h:1272
base of all file and directory entries
Definition: entries.h:82

Referenced by MmDereferenceSegment().

◆ if() [1/2]

if ( Entry  = = 0)

Definition at line 4765 of file section.c.

4770  {
4771  BOOLEAN DirtyAgain;
4772 
4773  /*
4774  * We got a dirty entry. This path is for the shared data,
4775  * be-it regular file maps or shared sections of DLLs
4776  */
4777  ASSERT(!Segment->WriteCopy);
4778  ASSERT(FlagOn(*Segment->Flags, MM_DATAFILE_SEGMENT) || FlagOn(Segment->Image.Characteristics, IMAGE_SCN_MEM_SHARED));
4779 
4780  /* Insert the cleaned entry back. Mark it as write in progress, and clear the dirty bit. */
4782  Entry = WRITE_SSE(Entry);
4784 
4786 
4787  if (FlagOn(*Segment->Flags, MM_DATAFILE_SEGMENT))
4788  {
4789  /* We have to write it back to the file. Tell the FS driver who we are */
4790  if (PageOut)
4792 
4793  /* Go ahead and write the page */
4794  DPRINT("Writing page at offset %I64d for file %wZ, Pageout: %s\n",
4795  Offset->QuadPart, &Segment->FileObject->FileName, PageOut ? "TRUE" : "FALSE");
4796  Status = MiWritePage(Segment, Offset->QuadPart, Page);
4797 
4798  if (PageOut)
4800  }
4801  else
4802  {
4803  /* This must only be called by the page-out path */
4804  ASSERT(PageOut);
4805 
4806  /* And this must be for a shared section in a DLL */
4807  ASSERT(Segment->Image.Characteristics & IMAGE_SCN_MEM_SHARED);
4808 
4809  SWAPENTRY SwapEntry = MmGetSavedSwapEntryPage(Page);
4810  if (!SwapEntry)
4811  {
4812  SwapEntry = MmAllocSwapPage();
4813  }
4814 
4815  if (SwapEntry)
4816  {
4817  Status = MmWriteToSwapPage(SwapEntry, Page);
4818  if (NT_SUCCESS(Status))
4819  {
4820  MmSetSavedSwapEntryPage(Page, SwapEntry);
4821  }
4822  else
4823  {
4824  MmFreeSwapPage(SwapEntry);
4825  }
4826  }
4827  else
4828  {
4829  DPRINT1("Failed to allocate a swap page!\n");
4831  }
4832  }
4833 
4835 
4836  /* Get the entry again */
4839 
4840  if (!NT_SUCCESS(Status))
4841  {
4842  /* Damn, this failed. Consider this page as still dirty */
4843  DPRINT1("MiWritePage FAILED: Status 0x%08x!\n", Status);
4844  DirtyAgain = TRUE;
4845  }
4846  else
4847  {
4848  /* Check if someone dirtified this page while we were not looking */
4849  DirtyAgain = IS_DIRTY_SSE(Entry);
4850  }
4851 
4852  /* Drop the reference we got, deleting the write altogether. */
4854  if (DirtyAgain)
4855  {
4856  Entry = DIRTY_SSE(Entry);
4857  }
4859  }
#define PAGE_SHIFT
Definition: env_spec_w32.h:45
#define MmGetPageEntrySectionSegment(S, O)
Definition: mm.h:1463
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define WRITE_SSE(E)
Definition: mm.h:1269
#define FSRTL_MOD_WRITE_TOP_LEVEL_IRP
Definition: fsrtltypes.h:61
#define MmSetPageEntrySectionSegment(S, O, E)
Definition: section.c:56
#define TRUE
Definition: types.h:120
#define PFN_FROM_SSE(E)
Definition: mm.h:1259
#define MmLockSectionSegment(x)
Definition: mm.h:1284
#define DIRTY_SSE(E)
Definition: mm.h:1266
ASSERT(Segment->Locked)
#define IS_DIRTY_SSE(E)
Definition: mm.h:1268
#define MAKE_SSE(P, C)
Definition: mm.h:1274
unsigned char BOOLEAN
PFN_NUMBER Page
Definition: section.c:4756
#define MmUnlockSectionSegment(x)
Definition: mm.h:1292
_Inout_ PVOID Segment
Definition: exfuncs.h:1101
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
SWAPENTRY NTAPI MmAllocSwapPage(VOID)
Definition: pagefile.c:304
PLARGE_INTEGER BOOLEAN BOOLEAN PageOut
Definition: section.c:4753
#define MM_DATAFILE_SEGMENT
Definition: mm.h:207
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
#define PAGE_FROM_SSE(E)
Definition: mm.h:1271
#define IMAGE_SCN_MEM_SHARED
Definition: ntimage.h:238
#define FlagOn(_F, _SF)
Definition: ext2fs.h:179
NTSTATUS NTAPI MiWritePage(PMM_SECTION_SEGMENT Segment, LONGLONG SegOffset, PFN_NUMBER Page)
Definition: section.c:239
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
ULONG_PTR SWAPENTRY
Definition: mm.h:47
DPRINT("Checking segment for file %wZ at offset 0x%I64X.\n", &Segment->FileObject->FileName, Offset->QuadPart)
#define NULL
Definition: types.h:112
#define SHARE_COUNT_FROM_SSE(E)
Definition: mm.h:1272
#define DPRINT1
Definition: precomp.h:8
VOID NTAPI MmSetSavedSwapEntryPage(PFN_NUMBER Page, SWAPENTRY SavedSwapEntry)
Definition: freelist.c:483
NTSTATUS NTAPI MmWriteToSwapPage(SWAPENTRY SwapEntry, PFN_NUMBER Page)
Definition: pagefile.c:130
base of all file and directory entries
Definition: entries.h:82
VOID NTAPI MmFreeSwapPage(SWAPENTRY Entry)
Definition: pagefile.c:274
SWAPENTRY NTAPI MmGetSavedSwapEntryPage(PFN_NUMBER Page)
Definition: freelist.c:499

Referenced by MmExtendSection(), MmMapViewInSystemSpaceEx(), MmpDeleteSection(), NtQuerySection(), and PeFmtCreateSection().

◆ if() [2/2]

if ( !IS_DIRTY_SSE(Entry) &&(SHARE_COUNT_FROM_SSE(Entry)==0) &&  PageOut)

Definition at line 4862 of file section.c.

4863  {
4864  ULONG_PTR NewEntry = 0;
4865  /* Restore the swap entry here */
4866  if (!FlagOn(*Segment->Flags, MM_DATAFILE_SEGMENT))
4867  {
4868  SWAPENTRY SwapEntry = MmGetSavedSwapEntryPage(Page);
4869  if (SwapEntry)
4870  NewEntry = MAKE_SWAP_SSE(SwapEntry);
4871  }
4872 
4873  /* Yes. Release it */
4876  /* Tell the caller we released the page */
4877  return TRUE;
4878  }
#define MmSetPageEntrySectionSegment(S, O, E)
Definition: section.c:56
#define TRUE
Definition: types.h:120
#define MC_USER
Definition: mm.h:92
NTSTATUS NTAPI MmReleasePageMemoryConsumer(ULONG Consumer, PFN_NUMBER Page)
Definition: balance.c:77
uint32_t ULONG_PTR
Definition: typedefs.h:65
PFN_NUMBER Page
Definition: section.c:4756
_Inout_ PVOID Segment
Definition: exfuncs.h:1101
#define MM_DATAFILE_SEGMENT
Definition: mm.h:207
#define FlagOn(_F, _SF)
Definition: ext2fs.h:179
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
ULONG_PTR SWAPENTRY
Definition: mm.h:47
#define MAKE_SWAP_SSE(S)
Definition: mm.h:1265
SWAPENTRY NTAPI MmGetSavedSwapEntryPage(PFN_NUMBER Page)
Definition: freelist.c:499

◆ ImageSectionObjectFromSegment()

PMM_IMAGE_SECTION_OBJECT ImageSectionObjectFromSegment ( PMM_SECTION_SEGMENT  Segment)

Definition at line 120 of file section.c.

121 {
122  ASSERT((Segment->SegFlags & MM_DATAFILE_SEGMENT) == 0);
123 
124  return CONTAINING_RECORD(Segment->ReferenceCount, MM_IMAGE_SECTION_OBJECT, RefCount);
125 }
ASSERT(Segment->Locked)
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
_Inout_ PVOID Segment
Definition: exfuncs.h:1101
#define MM_DATAFILE_SEGMENT
Definition: mm.h:207

Referenced by MiRosUnmapViewOfSection().

◆ MiArm3GetCorrectFileAccessMask()

ACCESS_MASK NTAPI MiArm3GetCorrectFileAccessMask ( IN ACCESS_MASK  SectionPageProtection)

Definition at line 140 of file section.c.

141 {
142  ULONG ProtectionMask;
143 
144  /* Calculate the protection mask and make sure it's valid */
146  if (ProtectionMask == MM_INVALID_PROTECTION)
147  {
148  DPRINT1("Invalid protection mask\n");
150  }
151 
152  /* Now convert it to the required file access */
153  return MmMakeFileAccess[ProtectionMask & 0x7];
154 }
#define MM_INVALID_PROTECTION
Definition: miarm.h:63
ACCESS_MASK MmMakeFileAccess[8]
Definition: section.c:32
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_opt_ PLARGE_INTEGER _In_ ULONG SectionPageProtection
Definition: mmfuncs.h:360
ULONG NTAPI MiMakeProtectionMask(IN ULONG Protect)
Definition: section.c:158
#define STATUS_INVALID_PAGE_PROTECTION
Definition: ntstatus.h:305
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1

◆ MiCopyFromUserPage()

static NTSTATUS MiCopyFromUserPage ( PFN_NUMBER  DestPage,
const VOID SrcAddress 
)
static

Definition at line 1164 of file section.c.

1165 {
1167  KIRQL Irql;
1168  PVOID DestAddress;
1169 
1171  DestAddress = MiMapPageInHyperSpace(Process, DestPage, &Irql);
1172  if (DestAddress == NULL)
1173  {
1174  return STATUS_NO_MEMORY;
1175  }
1176  ASSERT((ULONG_PTR)DestAddress % PAGE_SIZE == 0);
1177  ASSERT((ULONG_PTR)SrcAddress % PAGE_SIZE == 0);
1178  RtlCopyMemory(DestAddress, SrcAddress, PAGE_SIZE);
1179  MiUnmapPageInHyperSpace(Process, DestAddress, Irql);
1180  return STATUS_SUCCESS;
1181 }
_Out_ PKIRQL Irql
Definition: csq.h:179
uint32_t ULONG_PTR
Definition: typedefs.h:65
UCHAR KIRQL
Definition: env_spec_w32.h:591
ASSERT(Segment->Locked)
#define PsGetCurrentProcess
Definition: psfuncs.h:17
PVOID NTAPI MiMapPageInHyperSpace(IN PEPROCESS Process, IN PFN_NUMBER Page, IN PKIRQL OldIrql)
Definition: hypermap.c:28
VOID NTAPI MiUnmapPageInHyperSpace(IN PEPROCESS Process, IN PVOID Address, IN KIRQL OldIrql)
Definition: hypermap.c:91
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
#define NULL
Definition: types.h:112
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by MmAccessFaultSectionView().

◆ MiGrabDataSection()

static PMM_SECTION_SEGMENT MiGrabDataSection ( PSECTION_OBJECT_POINTERS  SectionObjectPointer)
static

Definition at line 90 of file section.c.

91 {
94 
95  while (TRUE)
96  {
97  Segment = SectionObjectPointer->DataSectionObject;
98  if (!Segment)
99  break;
100 
101  if (Segment->SegFlags & (MM_SEGMENT_INCREATE | MM_SEGMENT_INDELETE))
102  {
106  continue;
107  }
108 
109  ASSERT(Segment->SegFlags & MM_DATAFILE_SEGMENT);
110  InterlockedIncrement64(&Segment->RefCount);
111  break;
112  }
113 
115 
116  return Segment;
117 }
static LARGE_INTEGER TinyTime
Definition: section.c:63
#define TRUE
Definition: types.h:120
FORCEINLINE KIRQL MiAcquirePfnLock(VOID)
Definition: mm.h:919
FORCEINLINE VOID MiReleasePfnLock(_In_ KIRQL OldIrql)
Definition: mm.h:926
_Must_inspect_result_ _In_ PDEVICE_OBJECT _In_ PSECTION_OBJECT_POINTERS SectionObjectPointer
Definition: fsrtlfuncs.h:1368
UCHAR KIRQL
Definition: env_spec_w32.h:591
ASSERT(Segment->Locked)
NTSTATUS NTAPI KeDelayExecutionThread(IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Interval OPTIONAL)
Definition: wait.c:283
#define MM_SEGMENT_INCREATE
Definition: mm.h:209
return FALSE
Definition: section.c:4880
_Inout_ PVOID Segment
Definition: exfuncs.h:1101
#define InterlockedIncrement64
Definition: interlocked.h:211
#define MM_DATAFILE_SEGMENT
Definition: mm.h:207
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
#define MM_SEGMENT_INDELETE
Definition: mm.h:208
#define NULL
Definition: types.h:112

Referenced by MmCanFileBeTruncated(), MmFlushSegment(), MmMakeDataSectionResident(), and MmPurgeSegment().

◆ MiMapViewInSystemSpace()

NTSTATUS MiMapViewInSystemSpace ( IN PVOID  Section,
IN PVOID  Session,
OUT PVOID MappedBase,
IN OUT PSIZE_T  ViewSize,
IN PLARGE_INTEGER  SectionOffset 
)

◆ MiRosUnmapViewInSystemSpace()

NTSTATUS NTAPI MiRosUnmapViewInSystemSpace ( IN PVOID  MappedBase)

Definition at line 4278 of file section.c.

4279 {
4280  DPRINT("MmUnmapViewInSystemSpace() called\n");
4281 
4283 }
static NTSTATUS MmUnmapViewOfSegment(PMMSUPPORT AddressSpace, PVOID BaseAddress)
Definition: section.c:3438
FORCEINLINE PMMSUPPORT MmGetKernelAddressSpace(VOID)
Definition: mm.h:1563
DPRINT("Checking segment for file %wZ at offset 0x%I64X.\n", &Segment->FileObject->FileName, Offset->QuadPart)
_Must_inspect_result_ _Outptr_result_bytebuffer_ ViewSize PVOID * MappedBase
Definition: mmfuncs.h:492

Referenced by MmUnmapViewInSystemSpace().

◆ MiRosUnmapViewOfSection()

NTSTATUS NTAPI MiRosUnmapViewOfSection ( IN PEPROCESS  Process,
IN PVOID  BaseAddress,
IN BOOLEAN  SkipDebuggerNotify 
)

Definition at line 3502 of file section.c.

3505 {
3506  NTSTATUS Status;
3509  PVOID ImageBaseAddress = 0;
3510 
3511  DPRINT("Opening memory area Process %p BaseAddress %p\n",
3512  Process, BaseAddress);
3513 
3514  ASSERT(Process);
3515 
3517 
3519  BaseAddress);
3520  if (MemoryArea == NULL ||
3521 #ifdef NEWCC
3522  ((MemoryArea->Type != MEMORY_AREA_SECTION_VIEW) && (MemoryArea->Type != MEMORY_AREA_CACHE)) ||
3523 #else
3525 #endif
3527 
3528  {
3530 
3531  DPRINT1("Unable to find memory area at address %p.\n", BaseAddress);
3532  return STATUS_NOT_MAPPED_VIEW;
3533  }
3534 
3536  {
3537  ULONG i;
3538  ULONG NrSegments;
3539  PMM_IMAGE_SECTION_OBJECT ImageSectionObject;
3540  PMM_SECTION_SEGMENT SectionSegments;
3542 
3543  Segment = MemoryArea->SectionData.Segment;
3544  ImageSectionObject = ImageSectionObjectFromSegment(Segment);
3545  SectionSegments = ImageSectionObject->Segments;
3546  NrSegments = ImageSectionObject->NrSegments;
3547 
3549 
3550  /* Search for the current segment within the section segments
3551  * and calculate the image base address */
3552  for (i = 0; i < NrSegments; i++)
3553  {
3554  if (Segment == &SectionSegments[i])
3555  {
3556  ImageBaseAddress = (char*)BaseAddress - (ULONG_PTR)SectionSegments[i].Image.VirtualAddress;
3557  break;
3558  }
3559  }
3560  if (i >= NrSegments)
3561  {
3562  KeBugCheck(MEMORY_MANAGEMENT);
3563  }
3564 
3565  for (i = 0; i < NrSegments; i++)
3566  {
3567  PVOID SBaseAddress = (PVOID)
3568  ((char*)ImageBaseAddress + (ULONG_PTR)SectionSegments[i].Image.VirtualAddress);
3569 
3570  Status = MmUnmapViewOfSegment(AddressSpace, SBaseAddress);
3571  if (!NT_SUCCESS(Status))
3572  {
3573  DPRINT1("MmUnmapViewOfSegment failed for %p (Process %p) with %lx\n",
3574  SBaseAddress, Process, Status);
3576  }
3577  }
3578  }
3579  else
3580  {
3582  if (!NT_SUCCESS(Status))
3583  {
3584  DPRINT1("MmUnmapViewOfSegment failed for %p (Process %p) with %lx\n",
3587  }
3588  }
3589 
3590  /* Notify debugger */
3591  if (ImageBaseAddress && !SkipDebuggerNotify) DbgkUnMapViewOfSection(ImageBaseAddress);
3592 
3593  return STATUS_SUCCESS;
3594 }
ULONG Type
Definition: mm.h:219
#define TRUE
Definition: types.h:120
struct _MM_SECTION_SEGMENT::@1774 Image
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG AddressSpace
Definition: iofuncs.h:2268
LONG NTSTATUS
Definition: precomp.h:26
PMEMORY_AREA NTAPI MmLocateMemoryAreaByAddress(PMMSUPPORT AddressSpace, PVOID Address)
Definition: marea.c:60
MMVAD_FLAGS VadFlags
Definition: mmtypes.h:731
uint32_t ULONG_PTR
Definition: typedefs.h:65
static NTSTATUS MmUnmapViewOfSegment(PMMSUPPORT AddressSpace, PVOID BaseAddress)
Definition: section.c:3438
else
Definition: tritemp.h:161
ASSERT(Segment->Locked)
#define MEMORY_AREA_OWNED_BY_ARM3
Definition: mm.h:75
DECLSPEC_NORETURN VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1427
NTSTATUS Status
Definition: section.c:4755
void * PVOID
Definition: retypes.h:9
#define MEMORY_AREA_SECTION_VIEW
Definition: mm.h:71
_Inout_ PVOID Segment
Definition: exfuncs.h:1101
Status
Definition: gdiplustypes.h:24
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
PMM_SECTION_SEGMENT Segments
Definition: mm.h:203
BOOLEAN DeleteInProgress
Definition: mm.h:221
MMVAD VadNode
Definition: mm.h:217
VOID NTAPI DbgkUnMapViewOfSection(IN PVOID BaseAddress)
Definition: dbgkutil.c:436
FORCEINLINE PMMSUPPORT MmGetKernelAddressSpace(VOID)
Definition: mm.h:1563
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
PMM_IMAGE_SECTION_OBJECT ImageSectionObjectFromSegment(PMM_SECTION_SEGMENT Segment)
Definition: section.c:120
union _MMVAD::@2564 u
DPRINT("Checking segment for file %wZ at offset 0x%I64X.\n", &Segment->FileObject->FileName, Offset->QuadPart)
#define NULL
Definition: types.h:112
struct _MEMORY_AREA::@1775 SectionData
#define DPRINT1
Definition: precomp.h:8
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
unsigned int ULONG
Definition: retypes.h:1
#define STATUS_NOT_MAPPED_VIEW
Definition: ntstatus.h:262
#define ULONG_PTR
Definition: config.h:101
#define STATUS_SUCCESS
Definition: shellext.h:65
struct _MEMORY_AREA * MemoryArea
Definition: newmm.h:37
ULONG_PTR VadType
Definition: mmtypes.h:691

Referenced by MiRosCleanupMemoryArea(), and MiUnmapViewOfSection().

◆ MiWritePage()

NTSTATUS NTAPI MiWritePage ( PMM_SECTION_SEGMENT  Segment,
LONGLONG  SegOffset,
PFN_NUMBER  Page 
)

Definition at line 239 of file section.c.

249 {
252  KEVENT Event;
253  UCHAR MdlBase[sizeof(MDL) + sizeof(PFN_NUMBER)];
254  PMDL Mdl = (PMDL)MdlBase;
255  PFILE_OBJECT FileObject = Segment->FileObject;
257 
258  FileOffset.QuadPart = Segment->Image.FileOffset + SegOffset;
259 
260  RtlZeroMemory(MdlBase, sizeof(MdlBase));
263  Mdl->MdlFlags |= MDL_PAGES_LOCKED;
264 
267  if (Status == STATUS_PENDING)
268  {
270  Status = IoStatus.Status;
271  }
272  if (Mdl->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA)
273  {
274  MmUnmapLockedPages (Mdl->MappedSystemVa, Mdl);
275  }
276 
277  return Status;
278 }
#define MmInitializeMdl(_MemoryDescriptorList, _BaseVa, _Length)
LONG NTSTATUS
Definition: precomp.h:26
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
ULONG PFN_NUMBER
Definition: ke.h:9
VOID NTAPI MmUnmapLockedPages(IN PVOID BaseAddress, IN PMDL Mdl)
Definition: mdlsup.c:841
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:467
NTSTATUS Status
Definition: section.c:4755
return FALSE
Definition: section.c:4880
PFN_NUMBER Page
Definition: section.c:4756
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
_Inout_ PVOID Segment
Definition: exfuncs.h:1101
Status
Definition: gdiplustypes.h:24
#define MDL_PAGES_LOCKED
Definition: mmtypes.h:19
#define STATUS_PENDING
Definition: ntstatus.h:82
VOID NTAPI MmBuildMdlFromPages(PMDL Mdl, PPFN_NUMBER Pages)
Definition: pagefile.c:94
* PFILE_OBJECT
Definition: iotypes.h:1998
unsigned char UCHAR
Definition: xmlstorage.h:181
MDL
Definition: mmtypes.h:117
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:159
NTSTATUS NTAPI IoSynchronousPageWrite(IN PFILE_OBJECT FileObject, IN PMDL Mdl, IN PLARGE_INTEGER Offset, IN PKEVENT Event, IN PIO_STATUS_BLOCK StatusBlock)
Definition: iofunc.c:1144
#define NULL
Definition: types.h:112
_In_ WDFDEVICE _In_ PVOID _In_opt_ PMDL Mdl
__in UCHAR __in POWER_STATE __in_opt PVOID __in PIO_STATUS_BLOCK IoStatus
Definition: mxum.h:155
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262

Referenced by FreeSegmentPage().

◆ MmAccessFaultSectionView()

NTSTATUS NTAPI MmAccessFaultSectionView ( PMMSUPPORT  AddressSpace,
MEMORY_AREA MemoryArea,
PVOID  Address,
BOOLEAN  Locked 
)

Definition at line 1877 of file section.c.

1881 {
1883  PFN_NUMBER OldPage;
1884  PFN_NUMBER NewPage;
1885  PVOID PAddress;
1888  ULONG_PTR Entry;
1890  BOOLEAN Cow = FALSE;
1891  ULONG NewProtect;
1892 
1893  DPRINT("MmAccessFaultSectionView(%p, %p, %p)\n", AddressSpace, MemoryArea, Address);
1894 
1895  /* Get the region for this address */
1897  &MemoryArea->SectionData.RegionListHead,
1898  Address, NULL);
1899  ASSERT(Region != NULL);
1900  if (!(Region->Protect & PAGE_IS_WRITABLE))
1901  return STATUS_ACCESS_VIOLATION;
1902 
1903  /* Make sure we have a page mapping for this address. */
1905  {
1907  if (!NT_SUCCESS(Status))
1908  {
1909  /* This is invalid access ! */
1910  return Status;
1911  }
1912  }
1913 
1914  /*
1915  * Check if the page has already been set readwrite
1916  */
1918  {
1919  DPRINT("Address 0x%p\n", Address);
1920  return STATUS_SUCCESS;
1921  }
1922 
1923  /* Check if we are doing Copy-On-Write */
1924  Segment = MemoryArea->SectionData.Segment;
1925  Cow = Segment->WriteCopy || (Region->Protect & PAGE_IS_WRITECOPY);
1926 
1927  if (!Cow)
1928  {
1929  /* Simply update page protection and we're done */
1930  MmSetPageProtect(Process, Address, Region->Protect);
1931  return STATUS_SUCCESS;
1932  }
1933 
1934  /* Calculate the new protection & check if we should update the region */
1935  NewProtect = Region->Protect;
1937  {
1939  if (Region->Protect & PAGE_IS_EXECUTABLE)
1941  else
1944  &MemoryArea->SectionData.RegionListHead,
1947  }
1948 
1949  /*
1950  * Find the offset of the page
1951  */
1952  PAddress = MM_ROUND_DOWN(Address, PAGE_SIZE);
1953  Offset.QuadPart = (ULONG_PTR)PAddress - MA_GetStartingAddress(MemoryArea)
1954  + MemoryArea->SectionData.ViewOffset;
1955 
1956  /* Get the page mapping this section offset. */
1959 
1960  /* Get the current page mapping for the process */
1961  ASSERT(MmIsPagePresent(Process, PAddress));
1962  OldPage = MmGetPfnForProcess(Process, PAddress);
1963  ASSERT(OldPage != 0);
1964 
1965  if (IS_SWAP_FROM_SSE(Entry) ||
1966  PFN_FROM_SSE(Entry) != OldPage)
1967  {
1969  /* This is a private page. We must only change the page protection. */
1970  MmSetPageProtect(Process, PAddress, NewProtect);
1971  return STATUS_SUCCESS;
1972  }
1973 
1974  /*
1975  * Allocate a page
1976  */
1978  {
1979  KeBugCheck(MEMORY_MANAGEMENT);
1980  }
1981 
1982  /*
1983  * Copy the old page
1984  */
1985  NT_VERIFY(NT_SUCCESS(MiCopyFromUserPage(NewPage, PAddress)));
1986 
1987  /*
1988  * Unshare the old page.
1989  */
1990  DPRINT("Swapping page (Old %x New %x)\n", OldPage, NewPage);
1991  MmDeleteVirtualMapping(Process, PAddress, NULL, NULL);
1992  if (Process)
1993  MmDeleteRmap(OldPage, Process, PAddress);
1996 
1997  /*
1998  * Set the PTE to point to the new page
1999  */
2000  if (!NT_SUCCESS(MmCreateVirtualMapping(Process, PAddress, NewProtect, NewPage)))
2001  {
2002  DPRINT1("MmCreateVirtualMapping failed, unable to create virtual mapping, not out of memory\n");
2003  KeBugCheck(MEMORY_MANAGEMENT);
2004  }
2005 
2006  if (Process)
2007  MmInsertRmap(NewPage, Process, PAddress);
2008 
2009  DPRINT("Address 0x%p\n", Address);
2010  return STATUS_SUCCESS;
2011 }
PMM_REGION NTAPI MmFindRegion(PVOID BaseAddress, PLIST_ENTRY RegionListHead, PVOID Address, PVOID *RegionBaseAddress)
Definition: region.c:257
#define MmGetPageEntrySectionSegment(S, O)
Definition: mm.h:1463
static VOID MmAlterViewAttributes(PMMSUPPORT AddressSpace, PVOID BaseAddress, SIZE_T RegionSize, ULONG OldType, ULONG OldProtect, ULONG NewType, ULONG NewProtect)
Definition: section.c:1425
VOID NTAPI MmInsertRmap(PFN_NUMBER Page, struct _EPROCESS *Process, PVOID Address)
#define PAGE_IS_EXECUTABLE
Definition: mm.h:137
ULONG NTAPI MmGetPageProtect(struct _EPROCESS *Process, PVOID Address)
#define TRUE
Definition: types.h:120
#define MC_USER
Definition: mm.h:92
#define PFN_FROM_SSE(E)
Definition: mm.h:1259
VOID NTAPI MmDeleteRmap(PFN_NUMBER Page, struct _EPROCESS *Process, PVOID Address)
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG AddressSpace
Definition: iofuncs.h:2268
Definition: mm.h:429
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI MmUnsharePageEntrySectionSegment(PMEMORY_AREA MemoryArea, PMM_SECTION_SEGMENT Segment, PLARGE_INTEGER Offset, BOOLEAN Dirty, BOOLEAN PageOut, ULONG_PTR *InEntry)
Definition: section.c:1084
NTSTATUS NTAPI MmRequestPageMemoryConsumer(ULONG Consumer, BOOLEAN MyWait, PPFN_NUMBER AllocatedPage)
Definition: balance.c:275
NTSTATUS NTAPI MmCreateVirtualMapping(struct _EPROCESS *Process, PVOID Address, ULONG flProtect, PFN_NUMBER Page)
#define PAGE_IS_WRITECOPY
Definition: mm.h:143
#define NT_VERIFY(exp)
Definition: rtlfuncs.h:3289
#define MmLockSectionSegment(x)
Definition: mm.h:1284
uint32_t ULONG_PTR
Definition: typedefs.h:65
BOOLEAN NTAPI MmIsPagePresent(struct _EPROCESS *Process, PVOID Address)
ASSERT(Segment->Locked)
ULONG PFN_NUMBER
Definition: ke.h:9
NTSTATUS NTAPI MmAlterRegion(PMMSUPPORT AddressSpace, PVOID BaseAddress, PLIST_ENTRY RegionListHead, PVOID StartAddress, SIZE_T Length, ULONG NewType, ULONG NewProtect, PMM_ALTER_REGION_FUNC AlterFunc)
Definition: region.c:108
#define PAGE_IS_WRITABLE
Definition: mm.h:131
DECLSPEC_NORETURN VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1427
_In_ PMEMORY_AREA _In_ PVOID _In_ BOOLEAN Locked
Definition: newmm.h:207
NTSTATUS NTAPI MmNotPresentFaultSectionView(PMMSUPPORT AddressSpace, MEMORY_AREA *MemoryArea, PVOID Address, BOOLEAN Locked)
Definition: section.c:1511
NTSTATUS Status
Definition: section.c:4755
unsigned char BOOLEAN
static WCHAR Address[46]
Definition: ping.c:68
Entry
Definition: section.c:4764
VOID NTAPI MmDeleteVirtualMapping(struct _EPROCESS *Process, PVOID Address, BOOLEAN *WasDirty, PPFN_NUMBER Page)
return FALSE
Definition: section.c:4880
#define MmUnlockSectionSegment(x)
Definition: mm.h:1292
_Inout_ PVOID Segment
Definition: exfuncs.h:1101
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
VOID NTAPI MmSetPageProtect(struct _EPROCESS *Process, PVOID Address, ULONG flProtect)
#define MM_ROUND_DOWN(x, s)
Definition: mm.h:109
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define MA_GetStartingAddress(_MemoryArea)
Definition: mm.h:212
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
PFN_NUMBER NTAPI MmGetPfnForProcess(struct _EPROCESS *Process, PVOID Address)
#define IS_SWAP_FROM_SSE(E)
Definition: mm.h:1260
FORCEINLINE PEPROCESS MmGetAddressSpaceOwner(IN PMMSUPPORT AddressSpace)
Definition: mm.h:1548
_Must_inspect_result_ _In_ ULONG NewProtect
Definition: mmfuncs.h:682
PLARGE_INTEGER Offset
Definition: section.c:4750
DPRINT("Checking segment for file %wZ at offset 0x%I64X.\n", &Segment->FileObject->FileName, Offset->QuadPart)
#define NULL
Definition: types.h:112
struct _MEMORY_AREA::@1775 SectionData
#define DPRINT1
Definition: precomp.h:8
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
static NTSTATUS MiCopyFromUserPage(PFN_NUMBER DestPage, const VOID *SrcAddress)
Definition: section.c:1164
#define PAGE_EXECUTE_READWRITE
Definition: nt_native.h:1308
#define STATUS_SUCCESS
Definition: shellext.h:65
base of all file and directory entries
Definition: entries.h:82
#define PAGE_READWRITE
Definition: nt_native.h:1304

Referenced by MmpAccessFault().

◆ MmAlterViewAttributes()

static VOID MmAlterViewAttributes ( PMMSUPPORT  AddressSpace,
PVOID  BaseAddress,
SIZE_T  RegionSize,
ULONG  OldType,
ULONG  OldProtect,
ULONG  NewType,
ULONG  NewProtect 
)
static

Definition at line 1425 of file section.c.

1432 {
1435  BOOLEAN DoCOW = FALSE;
1436  ULONG i;
1438 
1440  ASSERT(MemoryArea != NULL);
1441  Segment = MemoryArea->SectionData.Segment;
1443 
1444  if ((Segment->WriteCopy) &&
1446  {
1447  DoCOW = TRUE;
1448  }
1449 
1450  if (OldProtect != NewProtect)
1451  {
1452  for (i = 0; i < PAGE_ROUND_UP(RegionSize) / PAGE_SIZE; i++)
1453  {
1454  SWAPENTRY SwapEntry;
1455  PVOID Address = (char*)BaseAddress + (i * PAGE_SIZE);
1457 
1458  /* Wait for a wait entry to disappear */
1459  do
1460  {
1461  MmGetPageFileMapping(Process, Address, &SwapEntry);
1462  if (SwapEntry != MM_WAIT_ENTRY)
1463  break;
1466  YieldProcessor();
1469  }
1470  while (TRUE);
1471 
1472  /*
1473  * If we doing COW for this segment then check if the page is
1474  * already private.
1475  */
1476  if (DoCOW && MmIsPagePresent(Process, Address))
1477  {
1479  ULONG_PTR Entry;
1480  PFN_NUMBER Page;
1481 
1483  + MemoryArea->SectionData.ViewOffset;
1485  /*
1486  * An MM_WAIT_ENTRY is ok in this case... It'll just count as
1487  * IS_SWAP_FROM_SSE and we'll do the right thing.
1488  */
1490 
1493  {
1494  Protect = NewProtect;
1495  }
1496  }
1497 
1499  {
1501  Protect);
1502  }
1503  }
1504  }
1505 
1507 }
#define MmGetPageEntrySectionSegment(S, O)
Definition: mm.h:1463
_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 TRUE
Definition: types.h:120
#define PFN_FROM_SSE(E)
Definition: mm.h:1259
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG AddressSpace
Definition: iofuncs.h:2268
FORCEINLINE VOID MmUnlockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1541
PMEMORY_AREA NTAPI MmLocateMemoryAreaByAddress(PMMSUPPORT AddressSpace, PVOID Address)
Definition: marea.c:60
#define MmLockSectionSegment(x)
Definition: mm.h:1284
uint32_t ULONG_PTR
Definition: typedefs.h:65
FORCEINLINE VOID YieldProcessor(VOID)
Definition: ke.h:32
BOOLEAN NTAPI MmIsPagePresent(struct _EPROCESS *Process, PVOID Address)
ASSERT(Segment->Locked)
ULONG PFN_NUMBER
Definition: ke.h:9
unsigned char BOOLEAN
static WCHAR Address[46]
Definition: ping.c:68
Entry
Definition: section.c:4764
return FALSE
Definition: section.c:4880
PFN_NUMBER Page
Definition: section.c:4756
#define MmUnlockSectionSegment(x)
Definition: mm.h:1292
_Inout_ PVOID Segment
Definition: exfuncs.h:1101
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
BOOLEAN NTAPI MmIsDisabledPage(struct _EPROCESS *Process, PVOID Address)
VOID NTAPI MmSetPageProtect(struct _EPROCESS *Process, PVOID Address, ULONG flProtect)
#define PAGE_SIZE
Definition: env_spec_w32.h:49
VOID NTAPI MmGetPageFileMapping(PEPROCESS Process, PVOID Address, SWAPENTRY *SwapEntry)
Definition: page.c:300
#define MA_GetStartingAddress(_MemoryArea)
Definition: mm.h:212
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
PFN_NUMBER NTAPI MmGetPfnForProcess(struct _EPROCESS *Process, PVOID Address)
__kernel_entry _Inout_ _Inout_ PSIZE_T RegionSize
Definition: mmfuncs.h:172
#define IS_SWAP_FROM_SSE(E)
Definition: mm.h:1260
ULONG_PTR SWAPENTRY
Definition: mm.h:47
FORCEINLINE PEPROCESS MmGetAddressSpaceOwner(IN PMMSUPPORT AddressSpace)
Definition: mm.h:1548
_Must_inspect_result_ _In_ ULONG NewProtect
Definition: mmfuncs.h:682
PLARGE_INTEGER Offset
Definition: section.c:4750
#define NULL
Definition: types.h:112
#define PAGE_READONLY
Definition: compat.h:138
#define PAGE_ROUND_UP(x)
Definition: mmtypes.h:38
struct _MEMORY_AREA::@1775 SectionData
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
#define PAGE_EXECUTE_READWRITE
Definition: nt_native.h:1308
struct _MEMORY_AREA * MemoryArea
Definition: newmm.h:37
FORCEINLINE VOID MmLockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1534
base of all file and directory entries
Definition: entries.h:82
#define PAGE_READWRITE
Definition: nt_native.h:1304

Referenced by MmAccessFaultSectionView(), MmNotPresentFaultSectionView(), and MmProtectSectionView().

◆ MmArePagesResident()

BOOLEAN NTAPI MmArePagesResident ( _In_ PEPROCESS  Process,
_In_ PVOID  Address,
_In_ ULONG  Length 
)

Definition at line 4496 of file section.c.

4500 {
4502  BOOLEAN Ret = TRUE;
4504  LARGE_INTEGER SegmentOffset, RangeEnd;
4506 
4508 
4510  if (MemoryArea == NULL)
4511  {
4513  return FALSE;
4514  }
4515 
4516  /* Only supported in old Mm for now */
4518  /* For file mappings */
4520 
4521  Segment = MemoryArea->SectionData.Segment;
4523 
4525  + MemoryArea->SectionData.ViewOffset;
4527  + MemoryArea->SectionData.ViewOffset;
4528 
4529  while (SegmentOffset.QuadPart < RangeEnd.QuadPart)
4530  {
4532  if ((Entry == 0) || IS_SWAP_FROM_SSE(Entry))
4533  {
4534  Ret = FALSE;
4535  break;
4536  }
4537  SegmentOffset.QuadPart += PAGE_SIZE;
4538  }
4539 
4541 
4543  return Ret;
4544 }
#define MmGetPageEntrySectionSegment(S, O)
Definition: mm.h:1463
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
ULONG Type
Definition: mm.h:219
#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:1541
#define PAGE_ROUND_DOWN(x)
Definition: mmtypes.h:36
PMEMORY_AREA NTAPI MmLocateMemoryAreaByAddress(PMMSUPPORT AddressSpace, PVOID Address)
Definition: marea.c:60
#define MmLockSectionSegment(x)
Definition: mm.h:1284
MMVAD_FLAGS VadFlags
Definition: mmtypes.h:731
uint32_t ULONG_PTR
Definition: typedefs.h:65
ASSERT(Segment->Locked)
unsigned char BOOLEAN
static WCHAR Address[46]
Definition: ping.c:68
return FALSE
Definition: section.c:4880
#define MEMORY_AREA_SECTION_VIEW
Definition: mm.h:71
#define MmUnlockSectionSegment(x)
Definition: mm.h:1292
_Inout_ PVOID Segment
Definition: exfuncs.h:1101
MMVAD VadNode
Definition: mm.h:217
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define MA_GetStartingAddress(_MemoryArea)
Definition: mm.h:212
FORCEINLINE PMMSUPPORT MmGetKernelAddressSpace(VOID)
Definition: mm.h:1563
#define IS_SWAP_FROM_SSE(E)
Definition: mm.h:1260
union _MMVAD::@2564 u
#define NULL
Definition: types.h:112
#define PAGE_ROUND_UP(x)
Definition: mmtypes.h:38
struct _MEMORY_AREA::@1775 SectionData
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
struct _MEMORY_AREA * MemoryArea
Definition: newmm.h:37
FORCEINLINE VOID MmLockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1534
ULONG_PTR VadType
Definition: mmtypes.h:691
base of all file and directory entries
Definition: entries.h:82
LONGLONG QuadPart
Definition: typedefs.h:114

Referenced by CcRosEnsureVacbResident().

◆ MmCanFileBeTruncated()

BOOLEAN NTAPI MmCanFileBeTruncated ( IN PSECTION_OBJECT_POINTERS  SectionObjectPointer,
IN PLARGE_INTEGER  NewFileSize 
)

Definition at line 4091 of file section.c.

4093 {
4094  BOOLEAN Ret;
4096 
4097  /* Check whether an ImageSectionObject exists */
4098  if (SectionObjectPointer->ImageSectionObject != NULL)
4099  {
4100  DPRINT1("ERROR: File can't be truncated because it has an image section\n");
4101  return FALSE;
4102  }
4103 
4105  if (!Segment)
4106  {
4107  /* There is no data section. It's fine to do anything. */
4108  return TRUE;
4109  }
4110 
4112  if ((Segment->SectionCount == 0) ||
4113  ((Segment->SectionCount == 1) && (SectionObjectPointer->SharedCacheMap != NULL)))
4114  {
4115  /* If the cache is the only one holding a reference to the segment, then it's fine to resize */
4116  Ret = TRUE;
4117  }
4118  else
4119  {
4120  /* We can't shrink, but we can extend */
4121  Ret = NewFileSize->QuadPart >= Segment->RawLength.QuadPart;
4122 #if DBG
4123  if (!Ret)
4124  {
4125  DPRINT1("Cannot truncate data: New Size %I64d, Segment Size %I64d\n", NewFileSize->QuadPart, Segment->RawLength.QuadPart);
4126  }
4127 #endif
4128  }
4131 
4132  DPRINT("FIXME: didn't check for outstanding write probes\n");
4133 
4134  return Ret;
4135 }
#define TRUE
Definition: types.h:120
#define MmLockSectionSegment(x)
Definition: mm.h:1284
_Must_inspect_result_ _In_ PDEVICE_OBJECT _In_ PSECTION_OBJECT_POINTERS SectionObjectPointer
Definition: fsrtlfuncs.h:1368
unsigned char BOOLEAN
return FALSE
Definition: section.c:4880
#define MmUnlockSectionSegment(x)
Definition: mm.h:1292
_Inout_ PVOID Segment
Definition: exfuncs.h:1101
_In_opt_ PLARGE_INTEGER NewFileSize
Definition: mmfuncs.h:608
static PMM_SECTION_SEGMENT MiGrabDataSection(PSECTION_OBJECT_POINTERS SectionObjectPointer)
Definition: section.c:90
DPRINT("Checking segment for file %wZ at offset 0x%I64X.\n", &Segment->FileObject->FileName, Offset->QuadPart)
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
VOID NTAPI MmDereferenceSegment(PMM_SECTION_SEGMENT Segment)
Definition: section.c:991
LONGLONG QuadPart
Definition: typedefs.h:114

Referenced by Ext2SetFileInformation(), Ext2SupersedeOrOverWriteFile(), FFSSetInformation(), FFSSupersedeOrOverWriteFile(), NtfsSetEndOfFile(), open_file2(), RfsdSetInformation(), RfsdSupersedeOrOverWriteFile(), RxCommonSetInformation(), set_end_of_file_information(), SetAttributeDataLength(), UDFCommonCreate(), UDFSetAllocationInformation(), UDFSetEOF(), VfatSetAllocationSizeInformation(), and VfatSetInformation().

◆ MmCreateArm3Section()

NTSTATUS NTAPI MmCreateArm3Section ( OUT PVOID SectionObject,
IN ACCESS_MASK  DesiredAccess,
IN POBJECT_ATTRIBUTES ObjectAttributes  OPTIONAL,
IN PLARGE_INTEGER  InputMaximumSize,
IN ULONG  SectionPageProtection,
IN ULONG  AllocationAttributes,
IN HANDLE FileHandle  OPTIONAL,
IN PFILE_OBJECT FileObject  OPTIONAL 
)

Definition at line 2463 of file section.c.

2471 {
2472  SECTION Section;
2473  PSECTION NewSection;
2474  PSUBSECTION Subsection;
2475  PSEGMENT NewSegment, Segment;
2476  NTSTATUS Status;
2477  PCONTROL_AREA ControlArea;
2478  ULONG ProtectionMask, ControlAreaSize, Size, NonPagedCharge, PagedCharge;
2480  BOOLEAN FileLock = FALSE, KernelCall = FALSE;
2481  KIRQL OldIrql;
2483  BOOLEAN UserRefIncremented = FALSE;
2484  PVOID PreviousSectionPointer;
2485 
2486  /* Make the same sanity checks that the Nt interface should've validated */
2489  SEC_NO_CHANGE)) == 0);
2493  SEC_NOCACHE | SEC_NO_CHANGE))));
2499 
2500  /* Convert section flag to page flag */
2502 
2503  /* Check to make sure the protection is correct. Nt* does this already */
2504  ProtectionMask = MiMakeProtectionMask(SectionPageProtection);
2505  if (ProtectionMask == MM_INVALID_PROTECTION) return STATUS_INVALID_PAGE_PROTECTION;
2506 
2507  /* Check if this is going to be a data or image backed file section */
2508  if ((FileHandle) || (FileObject))
2509  {
2510  /* These cannot be mapped with large pages */
2512 
2513  /* For now, only support the mechanism through a file handle */
2514  ASSERT(FileObject == NULL);
2515 
2516  /* Reference the file handle to get the object */
2518  MmMakeFileAccess[ProtectionMask],
2520  PreviousMode,
2521  (PVOID*)&File,
2522  NULL);
2523  if (!NT_SUCCESS(Status)) return Status;
2524 
2525  /* Make sure Cc has been doing its job */
2526  if (!File->SectionObjectPointer)
2527  {
2528  /* This is not a valid file system-based file, fail */
2531  }
2532 
2533  /* Image-file backed sections are not yet supported */
2535 
2536  /* Compute the size of the control area, and allocate it */
2537  ControlAreaSize = sizeof(CONTROL_AREA) + sizeof(MSUBSECTION);
2538  ControlArea = ExAllocatePoolWithTag(NonPagedPool, ControlAreaSize, 'aCmM');
2539  if (!ControlArea)
2540  {
2543  }
2544 
2545  /* Zero it out */
2546  RtlZeroMemory(ControlArea, ControlAreaSize);
2547 
2548  /* Did we get a handle, or an object? */
2549  if (FileHandle)
2550  {
2551  /* We got a file handle so we have to lock down the file */
2552 #if 0
2554  if (!NT_SUCCESS(Status))
2555  {
2556  ExFreePool(ControlArea);
2558  return Status;
2559  }
2560 #else
2561  /* ReactOS doesn't support this API yet, so do nothing */
2563 #endif
2564  /* Update the top-level IRP so that drivers know what's happening */
2566  FileLock = TRUE;
2567  }
2568 
2569  /* Lock the PFN database while we play with the section pointers */
2571 
2572  /* Image-file backed sections are not yet supported */
2574 
2575  /* There should not already be a control area for this file */
2576  ASSERT(File->SectionObjectPointer->DataSectionObject == NULL);
2577  NewSegment = NULL;
2578 
2579  /* Write down that this CA is being created, and set it */
2580  ControlArea->u.Flags.BeingCreated = TRUE;
2582  PreviousSectionPointer = File->SectionObjectPointer;
2583  File->SectionObjectPointer->DataSectionObject = ControlArea;
2584 
2585  /* We can release the PFN lock now */
2587 
2588  /* We don't support previously-mapped file */
2589  ASSERT(NewSegment == NULL);
2590 
2591  /* Image-file backed sections are not yet supported */
2593 
2594  /* So we always create a data file map */
2596  &Segment,
2597  (PSIZE_T)InputMaximumSize,
2600  KernelCall);
2601  if (!NT_SUCCESS(Status))
2602  {
2603  /* Lock the PFN database while we play with the section pointers */
2605 
2606  /* Reset the waiting-for-deletion event */
2607  ASSERT(ControlArea->WaitingForDeletion == NULL);
2608  ControlArea->WaitingForDeletion = NULL;
2609 
2610  /* Set the file pointer NULL flag */
2611  ASSERT(ControlArea->u.Flags.FilePointerNull == 0);
2612  ControlArea->u.Flags.FilePointerNull = TRUE;
2613 
2614  /* Delete the data section object */
2616  File->SectionObjectPointer->DataSectionObject = NULL;
2617 
2618  /* No longer being created */
2619  ControlArea->u.Flags.BeingCreated = FALSE;
2620 
2621  /* We can release the PFN lock now */
2623 
2624  /* Check if we locked and set the IRP */
2625  if (FileLock)
2626  {
2627  /* Undo */
2629  //FsRtlReleaseFile(File);
2630  }
2631 
2632  /* Free the control area and de-ref the file object */
2633  ExFreePool(ControlArea);
2635 
2636  /* All done */
2637  return Status;
2638  }
2639 
2640  /* On success, we expect this */
2641  ASSERT(PreviousSectionPointer == File->SectionObjectPointer);
2642 
2643  /* Check if a maximum size was specified */
2644  if (!InputMaximumSize->QuadPart)
2645  {
2646  /* Nope, use the segment size */
2647  Section.SizeOfSection.QuadPart = (LONGLONG)Segment->SizeOfSegment;
2648  }
2649  else
2650  {
2651  /* Yep, use the entered size */
2652  Section.SizeOfSection.QuadPart = InputMaximumSize->QuadPart;
2653  }
2654  }
2655  else
2656  {
2657  /* A handle must be supplied with SEC_IMAGE, as this is the no-handle path */
2659 
2660  /* Not yet supported */
2662 
2663  /* So this must be a pagefile-backed section, create the mappings needed */
2664  Status = MiCreatePagingFileMap(&NewSegment,
2665  InputMaximumSize,
2666  ProtectionMask,
2668  if (!NT_SUCCESS(Status)) return Status;
2669 
2670  /* Set the size here, and read the control area */
2671  Section.SizeOfSection.QuadPart = NewSegment->SizeOfSegment;
2672  ControlArea = NewSegment->ControlArea;
2673 
2674  /* MiCreatePagingFileMap increments user references */
2675  UserRefIncremented = TRUE;
2676  }
2677 
2678  /* Did we already have a segment? */
2679  if (!NewSegment)
2680  {
2681  /* This must be the file path and we created a segment */
2682  NewSegment = Segment;
2683  ASSERT(File != NULL);
2684 
2685  /* Acquire the PFN lock while we set control area flags */
2687 
2688  /* We don't support this race condition yet, so assume no waiters */
2689  ASSERT(ControlArea->WaitingForDeletion == NULL);
2690  ControlArea->WaitingForDeletion = NULL;
2691 
2692  /* Image-file backed sections are not yet supported, nor ROM images */
2694  ASSERT(Segment->ControlArea->u.Flags.Rom == 0);
2695 
2696  /* Take off the being created flag, and then release the lock */
2697  ControlArea->u.Flags.BeingCreated = FALSE;
2699  }
2700 
2701  /* Check if we locked the file earlier */
2702  if (FileLock)
2703  {
2704  /* Reset the top-level IRP and release the lock */
2706  //FsRtlReleaseFile(File);
2707  FileLock = FALSE;
2708  }
2709 
2710  /* Set the initial section object data */
2711  Section.InitialPageProtection = SectionPageProtection;
2712 
2713  /* The mapping created a control area and segment, save the flags */
2714  Section.Segment = NewSegment;
2715  Section.u.LongFlags = ControlArea->u.LongFlags;
2716 
2717  /* Check if this is a user-mode read-write non-image file mapping */
2718  if (!(FileObject) &&
2720  !(ControlArea->u.Flags.Image) &&
2721  (ControlArea->FilePointer))
2722  {
2723  /* Add a reference and set the flag */
2724  Section.u.Flags.UserWritable = TRUE;
2725  InterlockedIncrement((volatile LONG*)&ControlArea->WritableUserReferences);
2726  }
2727 
2728  /* Check for image mappings or page file mappings */
2729  if ((ControlArea->u.Flags.Image) || !(ControlArea->FilePointer))
2730  {
2731  /* Charge the segment size, and allocate a subsection */
2732  PagedCharge = sizeof(SECTION) + NewSegment->TotalNumberOfPtes * sizeof(MMPTE);
2733  Size = sizeof(SUBSECTION);
2734  }
2735  else
2736  {
2737  /* Charge nothing, and allocate a mapped subsection */
2738  PagedCharge = 0;
2739  Size = sizeof(MSUBSECTION);
2740  }
2741 
2742  /* Check if this is a normal CA */
2743  ASSERT(ControlArea->u.Flags.GlobalOnlyPerSession == 0);
2744  ASSERT(ControlArea->u.Flags.Rom == 0);
2745 
2746  /* Charge only a CA, and the subsection is right after */
2747  NonPagedCharge = sizeof(CONTROL_AREA);
2748  Subsection = (PSUBSECTION)(ControlArea + 1);
2749 
2750  /* We only support single-subsection mappings */
2751  NonPagedCharge += Size;
2752  ASSERT(Subsection->NextSubsection == NULL);
2753 
2754  /* Create the actual section object, with enough space for the prototype PTEs */
2758  PreviousMode,
2759  NULL,
2760  sizeof(SECTION),
2761  PagedCharge,
2762  NonPagedCharge,
2763  (PVOID*)&NewSection);
2764  if (!NT_SUCCESS(Status))
2765  {
2766  /* Check if this is a user-mode read-write non-image file mapping */
2767  if (!(FileObject) &&
2769  !(ControlArea->u.Flags.Image) &&
2770  (ControlArea->FilePointer))
2771  {
2772  /* Remove a reference and check the flag */
2773  ASSERT(Section.u.Flags.UserWritable == 1);
2774  InterlockedDecrement((volatile LONG*)&ControlArea->WritableUserReferences);
2775  }
2776 
2777  /* Check if a user reference was added */
2778  if (UserRefIncremented)
2779  {
2780  /* Acquire the PFN lock while we change counters */
2782 
2783  /* Decrement the accounting counters */
2784  ControlArea->NumberOfSectionReferences--;
2785  ASSERT((LONG)ControlArea->NumberOfUserReferences > 0);
2786  ControlArea->NumberOfUserReferences--;
2787 
2788  /* Check if we should destroy the CA and release the lock */
2789  MiCheckControlArea(ControlArea, OldIrql);
2790  }
2791 
2792  /* Return the failure code */
2793  return Status;
2794  }
2795 
2796  /* NOTE: Past this point, all failures will be handled by Ob upon ref->0 */
2797 
2798  /* Now copy the local section object from the stack into this new object */
2799  RtlCopyMemory(NewSection, &Section, sizeof(SECTION));
2800  NewSection->Address.StartingVpn = 0;
2801 
2802  /* For now, only user calls are supported */
2803  ASSERT(KernelCall == FALSE);
2804  NewSection->u.Flags.UserReference = TRUE;
2805 
2806  /* Is this a "based" allocation, in which all mappings are identical? */
2808  {
2809  /* Lock the VAD tree during the search */
2811 
2812  /* Is it a brand new ControArea ? */
2813  if (ControlArea->u.Flags.BeingCreated == 1)
2814  {
2815  ASSERT(ControlArea->u.Flags.Based == 1);
2816  /* Then we must find a global address, top-down */
2819  _64K,
2821  (ULONG_PTR*)&ControlArea->Segment->BasedAddress);
2822 
2823  if (!NT_SUCCESS(Status))
2824  {
2825  /* No way to find a valid range. */
2827  ControlArea->u.Flags.Based = 0;
2828  NewSection->u.Flags.Based = 0;
2829  ObDereferenceObject(NewSection);
2830  return Status;
2831  }
2832 
2833  /* Compute the ending address and insert it into the VAD tree */
2834  NewSection->Address.StartingVpn = (ULONG_PTR)ControlArea->Segment->BasedAddress;
2835  NewSection->Address.EndingVpn = NewSection->Address.StartingVpn + NewSection->SizeOfSection.LowPart - 1;
2836  MiInsertBasedSection(NewSection);
2837  }
2838  else
2839  {
2840  /* FIXME : Should we deny section creation if SEC_BASED is not set ? Can we have two different section objects on the same based address ? Investigate !*/
2841  ASSERT(FALSE);
2842  }
2843 
2845  }
2846 
2847  /* The control area is not being created anymore */
2848  if (ControlArea->u.Flags.BeingCreated == 1)
2849  {
2850  /* Acquire the PFN lock while we set control area flags */
2852 
2853  /* Take off the being created flag, and then release the lock */
2854  ControlArea->u.Flags.BeingCreated = 0;
2855  NewSection->u.Flags.BeingCreated = 0;
2856 
2858  }
2859 
2860  /* Migrate the attribute into a flag */
2861  if (AllocationAttributes & SEC_NO_CHANGE) NewSection->u.Flags.NoChange = TRUE;
2862 
2863  /* If R/W access is not requested, this might eventually become a CoW mapping */
2865  {
2866  NewSection->u.Flags.CopyOnWrite = TRUE;
2867  }
2868 
2869  /* Write down if this was a kernel call */
2870  ControlArea->u.Flags.WasPurged |= KernelCall;
2871  ASSERT(ControlArea->u.Flags.WasPurged == FALSE);
2872 
2873  /* Make sure the segment and the section are the same size, or the section is smaller */
2874  ASSERT((ULONG64)NewSection->SizeOfSection.QuadPart <= NewSection->Segment->SizeOfSegment);
2875 
2876  /* Return the object and the creation status */
2877  *SectionObject = (PVOID)NewSection;
2878  return Status;
2879 }
ULONG NoChange
Definition: mmtypes.h:483
_Must_inspect_result_ _Outptr_ PVOID * SectionObject
Definition: fsrtlfuncs.h:860
#define PAGE_NOCACHE
Definition: nt_native.h:1311
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define MM_INVALID_PROTECTION
Definition: miarm.h:63
PEVENT_COUNTER WaitingForDeletion
Definition: mmtypes.h:531
PFILE_OBJECT FilePointer
Definition: mmtypes.h:530
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define SEC_LARGE_PAGES
Definition: mmtypes.h:102
ULONGLONG SizeOfSegment
Definition: mmtypes.h:410
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ ULONG AllocationAttributes
Definition: mmfuncs.h:360
ULONG UserReference
Definition: mmtypes.h:476
ULONG NumberOfSectionReferences
Definition: mmtypes.h:520
PSEGMENT Segment
Definition: mmtypes.h:809
NTSTATUS NTAPI MiCreateDataFileMap(IN PFILE_OBJECT File, OUT PSEGMENT *Segment, IN PSIZE_T MaximumSize, IN ULONG SectionPageProtection, IN ULONG AllocationAttributes, IN ULONG IgnoreFileSizing)
Definition: section.c:1533
VOID FASTCALL KeAcquireGuardedMutex(IN PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:42
#define TRUE
Definition: types.h:120
#define PAGE_GUARD
Definition: nt_native.h:1310
KGUARDED_MUTEX MmSectionBasedMutex
Definition: section.c:110
LONG NTSTATUS
Definition: precomp.h:26
MM_AVL_TABLE MmSectionBasedRoot
Definition: section.c:109
FORCEINLINE KIRQL MiAcquirePfnLock(VOID)
Definition: mm.h:919
ACCESS_MASK MmMakeFileAccess[8]
Definition: section.c:32
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:3066
#define SEC_NOCACHE
Definition: mmtypes.h:100
static NTSTATUS NTAPI MiCreatePagingFileMap(OUT PSEGMENT *Segment, IN PLARGE_INTEGER MaximumSize, IN ULONG ProtectionMask, IN ULONG AllocationAttributes)
Definition: section.c:1549
NTSTATUS NTAPI MiFindEmptyAddressRangeDownBasedTree(IN SIZE_T Length, IN ULONG_PTR BoundaryAddress, IN ULONG_PTR Alignment, IN PMM_AVL_TABLE Table, OUT PULONG_PTR Base)
Definition: vadnode.c:713
ULONG TotalNumberOfPtes
Definition: mmtypes.h:407
struct _SUBSECTION SUBSECTION
union _CONTROL_AREA::@2557 u
VOID NTAPI MiInsertBasedSection(IN PSECTION Section)
Definition: vadnode.c:345
FORCEINLINE VOID MiReleasePfnLock(_In_ KIRQL OldIrql)
Definition: mm.h:926
struct _CONTROL_AREA * ControlArea
Definition: mmtypes.h:406
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define SEC_BASED
_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
HANDLE FileHandle
Definition: stats.c:38
ASSERT(Segment->Locked)
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:496
#define SEC_COMMIT
Definition: mmtypes.h:99
ULONG_PTR * PSIZE_T
Definition: typedefs.h:80
struct _SUBSECTION * NextSubsection
Definition: mmtypes.h:581
long LONG
Definition: pedump.c:60
LARGE_INTEGER SizeOfSection
Definition: mmtypes.h:810
#define SEC_RESERVE
Definition: nt_native.h:1323
struct _MSUBSECTION MSUBSECTION
NTSTATUS NTAPI FsRtlAcquireToCreateMappedSection(_In_ PFILE_OBJECT FileObject, _In_ ULONG SectionPageProtection)
Definition: fastio.c:1647
NTSTATUS Status
Definition: section.c:4755
#define PAGE_NOACCESS
Definition: nt_native.h:1302
unsigned char BOOLEAN
return FALSE
Definition: section.c:4880
ULONG LongFlags
Definition: mmtypes.h:527
struct _SECTION SECTION
void * PVOID
Definition: retypes.h:9
ULONG_PTR StartingVpn
Definition: mmtypes.h:650
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
_Inout_ PVOID Segment
Definition: exfuncs.h:1101
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
ULONG_PTR EndingVpn
Definition: mmtypes.h:651
Status
Definition: gdiplustypes.h:24
int64_t LONGLONG
Definition: typedefs.h:68
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ULONG NTAPI MiMakeProtectionMask(IN ULONG Protect)
Definition: section.c:158
#define ObDereferenceObject
Definition: obfuncs.h:203
#define STATUS_INVALID_FILE_FOR_SECTION
Definition: ntstatus.h:269
POBJECT_TYPE MmSectionObjectType
Definition: section.c:194
#define FSRTL_FSP_TOP_LEVEL_IRP
Definition: fsrtltypes.h:59
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
* PFILE_OBJECT
Definition: iotypes.h:1998
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
struct _CONTROL_AREA CONTROL_AREA
struct _SUBSECTION * PSUBSECTION
unsigned __int64 ULONG64
Definition: imports.h:198
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
MMSECTION_FLAGS Flags
Definition: mmtypes.h:814
#define InterlockedDecrement
Definition: armddk.h:52
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
ULONG GlobalOnlyPerSession
Definition: mmtypes.h:488
ULONG LowPart
Definition: typedefs.h:106
#define STATUS_INVALID_PAGE_PROTECTION
Definition: ntstatus.h:305
ULONG CopyOnWrite
Definition: mmtypes.h:471
POBJECT_TYPE IoFileObjectType
Definition: iomgr.c:36
#define _64K
Definition: miarm.h:19
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define PAGE_WRITECOMBINE
Definition: mmtypes.h:78
#define InterlockedIncrement
Definition: armddk.h:53
ULONG FilePointerNull
Definition: mmtypes.h:479
ULONG WritableUserReferences
Definition: mmtypes.h:534
PSEGMENT Segment
Definition: mmtypes.h:518
MMADDRESS_NODE Address
Definition: mmtypes.h:808
#define STATUS_INVALID_PARAMETER_6
Definition: ntstatus.h:480
ULONG NumberOfUserReferences
Definition: mmtypes.h:524
#define NULL
Definition: types.h:112
VOID NTAPI MiCheckControlArea(IN PCONTROL_AREA ControlArea, IN KIRQL OldIrql)
Definition: section.c:732
VOID FASTCALL KeReleaseGuardedMutex(IN OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:53
PVOID BasedAddress
Definition: mmtypes.h:415
union _SECTION::@2573 u
PVOID MmHighSectionBase
Definition: section.c:111
ULONG WasPurged
Definition: mmtypes.h:475
MMSECTION_FLAGS Flags
Definition: mmtypes.h:528
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define ULONG_PTR
Definition: config.h:101
#define SEC_IMAGE
Definition: mmtypes.h:96
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define PAGE_EXECUTE_READWRITE
Definition: nt_native.h:1308
Definition: File.h:15
#define STATUS_SUCCESS
Definition: shellext.h:65
_Must_inspect_result_ _In_ WDFDEVICE _In_ BOOLEAN _In_opt_ PVOID _In_ LONG _In_z_ PCHAR File
Definition: wdfdevice.h:4061
#define SEC_NO_CHANGE
Definition: mmtypes.h:94
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
ULONG BeingCreated
Definition: mmtypes.h:461
LONGLONG QuadPart
Definition: typedefs.h:114
#define PAGE_READWRITE
Definition: nt_native.h:1304

Referenced by MmCreateSection().

◆ MmCreateDataFileSection()

static NTSTATUS NTAPI MmCreateDataFileSection ( PSECTION SectionObject,
ACCESS_MASK  DesiredAccess,
POBJECT_ATTRIBUTES  ObjectAttributes,
PLARGE_INTEGER  UMaximumSize,
ULONG  SectionPageProtection,
ULONG  AllocationAttributes,
PFILE_OBJECT  FileObject,
BOOLEAN  GotFileHandle 
)
static

Definition at line 2272 of file section.c.

2283 {
2284  PSECTION Section;
2285  NTSTATUS Status;
2288  KIRQL OldIrql;
2289 
2290  /*
2291  * Create the section
2292  */
2297  NULL,
2298  sizeof(*Section),
2299  0,
2300  0,
2301  (PVOID*)&Section);
2302  if (!NT_SUCCESS(Status))
2303  {
2304  return Status;
2305  }
2306  /*
2307  * Initialize it
2308  */
2309  RtlZeroMemory(Section, sizeof(*Section));
2310 
2311  /* Mark this as a "ROS" section */
2312  Section->u.Flags.filler = 1;
2314  Section->u.Flags.File = 1;
2315 
2317  Section->u.Flags.NoChange = 1;
2319  Section->u.Flags.Reserve = 1;
2320 
2321  if (!GotFileHandle)
2322  {
2323  ASSERT(UMaximumSize != NULL);
2324  // ASSERT(UMaximumSize->QuadPart != 0);
2325  MaximumSize = *UMaximumSize;
2326  }
2327  else
2328  {
2331  if (!NT_SUCCESS(Status))
2332  {
2333  ObDereferenceObject(Section);
2334  return Status;
2335  }
2336 
2337  /*
2338  * FIXME: Revise this once a locking order for file size changes is
2339  * decided
2340  */
2341  if ((UMaximumSize != NULL) && (UMaximumSize->QuadPart != 0))
2342  {
2343  MaximumSize = *UMaximumSize;
2344  }
2345  else
2346  {
2348  /* Mapping zero-sized files isn't allowed. */
2349  if (MaximumSize.QuadPart == 0)
2350  {
2351  ObDereferenceObject(Section);
2353  }
2354  }
2355 
2356  if (MaximumSize.QuadPart > FileSize.QuadPart)
2357  {
2360  sizeof(LARGE_INTEGER),
2361  &MaximumSize);
2362  if (!NT_SUCCESS(Status))
2363  {
2364  ObDereferenceObject(Section);
2366  }
2367  }
2368  }
2369 
2370  if (FileObject->SectionObjectPointer == NULL)
2371  {
2372  ObDereferenceObject(Section);
2374  }
2375 
2376  /*
2377  * Lock the file
2378  */
2380  if (Status != STATUS_SUCCESS)
2381  {
2382  ObDereferenceObject(Section);
2383  return Status;
2384  }
2385 
2386  /* Lock the PFN lock while messing with Section Object pointers */
2388  Segment = FileObject->SectionObjectPointer->DataSectionObject;
2389 
2390  while (Segment && (Segment->SegFlags & (MM_SEGMENT_INDELETE | MM_SEGMENT_INCREATE)))
2391  {
2395  Segment = FileObject->SectionObjectPointer->DataSectionObject;
2396  }
2397 
2398  /*
2399  * If this file hasn't been mapped as a data file before then allocate a
2400  * section segment to describe the data file mapping
2401  */
2402  if (Segment == NULL)
2403  {
2406  if (Segment == NULL)
2407  {
2408  //KeSetEvent((PVOID)&FileObject->Lock, IO_NO_INCREMENT, FALSE);
2410  ObDereferenceObject(Section);
2411  return STATUS_NO_MEMORY;
2412  }
2413 
2414  /* We are creating it */
2415  RtlZeroMemory(Segment, sizeof(*Segment));
2417  Segment->RefCount = 1;
2418 
2419  FileObject->SectionObjectPointer->DataSectionObject = Segment;
2420 
2421  /* We're safe to release the lock now */
2423 
2424  Section->Segment = (PSEGMENT)Segment;
2425 
2426  /* Self-referencing segment */
2427  Segment->Flags = &Segment->SegFlags;
2428  Segment->ReferenceCount = &Segment->RefCount;
2429 
2430  Segment->SectionCount = 1;
2431 
2433  Segment->FileObject = FileObject;
2435 
2436  Segment->Image.FileOffset = 0;
2437  Segment->Protection = SectionPageProtection;
2438 
2439  Segment->Image.Characteristics = 0;
2442  {
2443  Segment->Length.QuadPart = Segment->RawLength.QuadPart = 0;
2444  }
2445  else
2446  {
2447  Segment->RawLength.QuadPart = MaximumSize.QuadPart;
2448  Segment->Length.QuadPart = PAGE_ROUND_UP(Segment->RawLength.QuadPart);
2449  }
2450  Segment->Image.VirtualAddress = 0;
2452 
2453  /* We're good to use it now */
2455  Segment->SegFlags &= ~MM_SEGMENT_INCREATE;
2457  }
2458  else
2459  {
2460  Section->Segment = (PSEGMENT)Segment;
2461  Segment->RefCount++;
2462  InterlockedIncrementUL(&Segment->SectionCount);
2463 
2465 
2467 
2468  if (MaximumSize.QuadPart > Segment->RawLength.QuadPart &&
2470  {
2471  Segment->RawLength.QuadPart = MaximumSize.QuadPart;
2472  Segment->Length.QuadPart = PAGE_ROUND_UP(Segment->RawLength.QuadPart);
2473  }
2474 
2476  }
2477  Section->SizeOfSection = MaximumSize;
2478 
2479  //KeSetEvent((PVOID)&FileObject->Lock, IO_NO_INCREMENT, FALSE);
2480  *SectionObject = Section;
2481  return STATUS_SUCCESS;
2482 }
ULONG NoChange
Definition: mmtypes.h:483
_Must_inspect_result_ _Outptr_ PVOID * SectionObject
Definition: fsrtlfuncs.h:860
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
static LARGE_INTEGER TinyTime
Definition: section.c:63
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ ULONG AllocationAttributes
Definition: mmfuncs.h:360
PSEGMENT Segment
Definition: mmtypes.h:809
ULONG InitialPageProtection
Definition: mmtypes.h:816
LONG NTSTATUS
Definition: precomp.h:26
FORCEINLINE KIRQL MiAcquirePfnLock(VOID)
Definition: mm.h:919
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
NTSTATUS NTAPI FsRtlGetFileSize(IN PFILE_OBJECT FileObject, IN OUT PLARGE_INTEGER FileSize)
Definition: fastio.c:815
#define MmLockSectionSegment(x)
Definition: mm.h:1284
FORCEINLINE VOID MiReleasePfnLock(_In_ KIRQL OldIrql)
Definition: mm.h:926
_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
ASSERT(Segment->Locked)
#define PAGE_EXECUTE_WRITECOPY
Definition: nt_native.h:1309
LARGE_INTEGER SizeOfSection
Definition: mmtypes.h:810
#define SEC_RESERVE
Definition: nt_native.h:1323
NTSTATUS NTAPI KeDelayExecutionThread(IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Interval OPTIONAL)
Definition: wait.c:283
NTSTATUS Status
Definition: section.c:4755
#define MM_SEGMENT_INCREATE
Definition: mm.h:209
return FALSE
Definition: section.c:4880
#define MmUnlockSectionSegment(x)
Definition: mm.h:1292
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
_Inout_ PVOID Segment
Definition: exfuncs.h:1101
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
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274
#define ObDereferenceObject
Definition: obfuncs.h:203
#define STATUS_INVALID_FILE_FOR_SECTION
Definition: ntstatus.h:269
#define MM_DATAFILE_SEGMENT
Definition: mm.h:207
POBJECT_TYPE MmSectionObjectType
Definition: section.c:194
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
MMSECTION_FLAGS Flags
Definition: mmtypes.h:814
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
_Must_inspect_result_ _Out_ PLARGE_INTEGER FileSize
Definition: fsrtlfuncs.h:108
NTSTATUS MmspWaitForFileLock(PFILE_OBJECT File)
Definition: section.c:908
VOID NTAPI MiInitializeSectionPageTable(PMM_SECTION_SEGMENT Segment)
Definition: sptab.c:165
struct _SEGMENT * PSEGMENT
#define TAG_MM_SECTION_SEGMENT
Definition: tag.h:139
#define InterlockedIncrementUL(Addend)
Definition: ex.h:1499
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
#define MM_SEGMENT_INDELETE
Definition: mm.h:208
#define NULL
Definition: types.h:112
#define STATUS_SECTION_NOT_EXTENDED
Definition: ntstatus.h:371
#define PAGE_ROUND_UP(x)
Definition: mmtypes.h:38
#define PAGE_WRITECOPY
Definition: nt_native.h:1305
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_opt_ PLARGE_INTEGER MaximumSize
Definition: mmfuncs.h:360
#define ObReferenceObject
Definition: obfuncs.h:204
union _SECTION::@2573 u
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_MAPPED_FILE_SIZE_ZERO
Definition: ntstatus.h:522
#define SEC_NO_CHANGE
Definition: mmtypes.h:94
LONGLONG QuadPart
Definition: typedefs.h:114

Referenced by MmCreateSection().

◆ MmCreateImageSection()

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

Definition at line 3108 of file section.c.

3115 {
3116  PSECTION Section;
3117  NTSTATUS Status;
3118  PMM_IMAGE_SECTION_OBJECT ImageSectionObject;
3119  KIRQL OldIrql;
3120 
3121 
3122  if (FileObject == NULL)
3124 
3125  if (FileObject->SectionObjectPointer == NULL)
3126  {
3127  DPRINT1("Denying section creation due to missing cache initialization\n");
3129  }
3130 
3131  /*
3132  * Create the section
3133  */
3138  NULL,
3139  sizeof(*Section),
3140  0,
3141  0,
3142  (PVOID*)(PVOID)&Section);
3143  if (!NT_SUCCESS(Status))
3144  {
3145  return Status;
3146  }
3147 
3148  /*
3149  * Initialize it
3150  */
3151  RtlZeroMemory(Section, sizeof(*Section));
3152 
3153  /* Mark this as a "ROS" Section */
3154  Section->u.Flags.filler = 1;
3155 
3157  Section->u.Flags.File = 1;
3158  Section->u.Flags.Image = 1;
3160  Section->u.Flags.NoChange = 1;
3161 
3163 
3164  /* Wait for it to be properly created or deleted */
3165  ImageSectionObject = FileObject->SectionObjectPointer->ImageSectionObject;
3166  while(ImageSectionObject && (ImageSectionObject->SegFlags & (MM_SEGMENT_INDELETE | MM_SEGMENT_INCREATE)))
3167  {
3169 
3171 
3173  ImageSectionObject = FileObject->SectionObjectPointer->ImageSectionObject;
3174  }
3175 
3176  if (ImageSectionObject == NULL)
3177  {
3178  NTSTATUS StatusExeFmt;
3179 
3180  ImageSectionObject = ExAllocatePoolZero(NonPagedPool, sizeof(MM_IMAGE_SECTION_OBJECT), TAG_MM_SECTION_SEGMENT);
3181  if (ImageSectionObject == NULL)
3182  {
3184  ObDereferenceObject(Section);
3185  return STATUS_NO_MEMORY;
3186  }
3187 
3188  ImageSectionObject->SegFlags = MM_SEGMENT_INCREATE;
3189  ImageSectionObject->RefCount = 1;
3190  FileObject->SectionObjectPointer->ImageSectionObject = ImageSectionObject;
3191 
3193 
3194  /* Purge the cache */
3195  CcFlushCache(FileObject->SectionObjectPointer, NULL, 0, NULL);
3196 
3197  StatusExeFmt = ExeFmtpCreateImageSection(FileObject, ImageSectionObject);
3198 
3199  if (!NT_SUCCESS(StatusExeFmt))
3200  {
3201  /* Unset */
3203  FileObject->SectionObjectPointer->ImageSectionObject = NULL;
3205 
3206  if(ImageSectionObject->Segments != NULL)
3207  ExFreePool(ImageSectionObject->Segments);
3208 
3209  /*
3210  * If image file is empty, then return that the file is invalid for section
3211  */
3212  Status = StatusExeFmt;
3213  if (StatusExeFmt == STATUS_END_OF_FILE)
3214  {
3216  }
3217 
3218  ExFreePoolWithTag(ImageSectionObject, TAG_MM_SECTION_SEGMENT);
3219  ObDereferenceObject(Section);
3220  return Status;
3221  }
3222 
3223  Section->Segment = (PSEGMENT)ImageSectionObject;
3224  ASSERT(ImageSectionObject->Segments);
3225  ASSERT(ImageSectionObject->RefCount > 0);
3226 
3227  /*
3228  * Lock the file
3229  */
3231  if (!NT_SUCCESS(Status))
3232  {
3233  /* Unset */
3235  FileObject->SectionObjectPointer->ImageSectionObject = NULL;
3237 
3238  ExFreePool(ImageSectionObject->Segments);
3239  ExFreePool(ImageSectionObject);
3240  ObDereferenceObject(Section);
3241  return Status;
3242  }
3243 
3245  ImageSectionObject->SegFlags &= ~MM_SEGMENT_INCREATE;
3246 
3247  /* Take a ref on the file on behalf of the newly created structure */
3249 
3251 
3252  Status = StatusExeFmt;
3253  }
3254  else
3255  {
3256  /* Take one ref */
3257  ImageSectionObject->RefCount++;
3258 
3260 
3261  Section->Segment = (PSEGMENT)ImageSectionObject;
3262 
3264  }
3265  //KeSetEvent((PVOID)&FileObject->Lock, IO_NO_INCREMENT, FALSE);
3266  *SectionObject = Section;
3267  ASSERT(ImageSectionObject->RefCount > 0);
3268 
3269  return Status;
3270 }
ULONG NoChange
Definition: mmtypes.h:483
_Must_inspect_result_ _Outptr_ PVOID * SectionObject
Definition: fsrtlfuncs.h:860
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
static LARGE_INTEGER TinyTime
Definition: section.c:63
NTSTATUS ExeFmtpCreateImageSection(PFILE_OBJECT FileObject, PMM_IMAGE_SECTION_OBJECT ImageSectionObject)
Definition: section.c:2955
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ ULONG AllocationAttributes
Definition: mmfuncs.h:360
PSEGMENT Segment
Definition: mmtypes.h:809
VOID NTAPI CcFlushCache(IN PSECTION_OBJECT_POINTERS SectionObjectPointer, IN OPTIONAL PLARGE_INTEGER FileOffset, IN ULONG Length, OUT OPTIONAL PIO_STATUS_BLOCK IoStatus)
Definition: cachesub.c:222
ULONG InitialPageProtection
Definition: mmtypes.h:816
LONG NTSTATUS
Definition: precomp.h:26
FORCEINLINE KIRQL MiAcquirePfnLock(VOID)
Definition: mm.h:919
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:3066
FORCEINLINE VOID MiReleasePfnLock(_In_ KIRQL OldIrql)
Definition: mm.h:926
#define STATUS_END_OF_FILE
Definition: shellext.h:67
_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
ASSERT(Segment->Locked)
NTSTATUS NTAPI KeDelayExecutionThread(IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Interval OPTIONAL)
Definition: wait.c:283
NTSTATUS Status
Definition: section.c:4755
#define MM_SEGMENT_INCREATE
Definition: mm.h:209
return FALSE
Definition: section.c:4880
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
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
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
PMM_SECTION_SEGMENT Segments
Definition: mm.h:203
#define ObDereferenceObject
Definition: obfuncs.h:203
#define STATUS_INVALID_FILE_FOR_SECTION
Definition: ntstatus.h:269
POBJECT_TYPE MmSectionObjectType
Definition: section.c:194
MMSECTION_FLAGS Flags
Definition: mmtypes.h:814
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
NTSTATUS MmspWaitForFileLock(PFILE_OBJECT File)
Definition: section.c:908
struct _SEGMENT * PSEGMENT
#define TAG_MM_SECTION_SEGMENT
Definition: tag.h:139
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
#define MM_SEGMENT_INDELETE
Definition: mm.h:208
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
#define ObReferenceObject
Definition: obfuncs.h:204
union _SECTION::@2573 u
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define STATUS_SUCCESS
Definition: shellext.h:65
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define SEC_NO_CHANGE
Definition: mmtypes.h:94
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by MmCreateSection().

◆ MmCreatePhysicalMemorySection()

NTSTATUS NTAPI MmCreatePhysicalMemorySection ( VOID  )

Definition at line 2148 of file section.c.

2149 {
2150  PSECTION PhysSection;
2151  NTSTATUS Status;
2153  UNICODE_STRING Name = RTL_CONSTANT_STRING(L"\\Device\\PhysicalMemory");
2154  LARGE_INTEGER SectionSize;
2155  HANDLE Handle;
2157 
2158  /*
2159  * Create the section mapping physical memory
2160  */
2161  SectionSize.QuadPart = MmHighestPhysicalPage * PAGE_SIZE;
2163  &Name,
2165  NULL,
2166  NULL);
2167  /*
2168  * Create the Object
2169  */
2172  &Obj,
2174  NULL,
2175  sizeof(*PhysSection),
2176  0,
2177  0,
2178  (PVOID*)&PhysSection);
2179  if (!NT_SUCCESS(Status))
2180  {
2181  DPRINT1("MmCreatePhysicalMemorySection: failed to create object (0x%lx)\n", Status);
2182  return Status;
2183  }
2184 
2185  /*
2186  * Initialize it
2187  */
2188  RtlZeroMemory(PhysSection, sizeof(*PhysSection));
2189 
2190  /* Mark this as a "ROS Section" */
2191  PhysSection->u.Flags.filler = 1;
2193  PhysSection->u.Flags.PhysicalMemory = 1;
2194  PhysSection->SizeOfSection = SectionSize;
2197  if (Segment == NULL)
2198  {
2199  ObDereferenceObject(PhysSection);
2200  return STATUS_NO_MEMORY;
2201  }
2203  PhysSection->Segment = (PSEGMENT)Segment;
2204  Segment->RefCount = 1;
2205 
2206  Segment->ReferenceCount = &Segment->RefCount;
2207  Segment->Flags = &Segment->SegFlags;
2208 
2210  Segment->Image.FileOffset = 0;
2211  Segment->Protection = PAGE_EXECUTE_READWRITE;
2212  Segment->RawLength = SectionSize;
2213  Segment->Length = SectionSize;
2214  Segment->SegFlags = MM_PHYSICALMEMORY_SEGMENT;
2215  Segment->WriteCopy = FALSE;
2216  Segment->Image.VirtualAddress = 0;
2217  Segment->Image.Characteristics = 0;
2219 
2220  Status = ObInsertObject(PhysSection,
2221  NULL,
2223  0,
2224  NULL,
2225  &Handle);
2226  if (!NT_SUCCESS(Status))
2227  {
2228  ObDereferenceObject(PhysSection);
2229  return Status;
2230  }
2232 
2233  return STATUS_SUCCESS;
2234 }
PSEGMENT Segment
Definition: mmtypes.h:809
ULONG PhysicalMemory
Definition: mmtypes.h:470
ULONG InitialPageProtection
Definition: mmtypes.h:816
LONG NTSTATUS
Definition: precomp.h:26
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:3066
#define SECTION_ALL_ACCESS
Definition: nt_native.h:1293
LARGE_INTEGER SizeOfSection
Definition: mmtypes.h:810
NTSTATUS Status
Definition: section.c:4755
return FALSE
Definition: section.c:4880
_Inout_ PVOID Segment
Definition: exfuncs.h:1101
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
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274
#define ObDereferenceObject
Definition: obfuncs.h:203
POBJECT_TYPE MmSectionObjectType
Definition: section.c:194
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
NTSTATUS NTAPI ObCloseHandle(IN HANDLE Handle, IN KPROCESSOR_MODE AccessMode)
Definition: obhandle.c:3376
MMSECTION_FLAGS Flags
Definition: mmtypes.h:814
static const WCHAR L[]
Definition: oid.c:1250
#define OBJ_PERMANENT
Definition: winternl.h:226
#define PAGE_SIZE
Definition: env_spec_w32.h:49
VOID NTAPI MiInitializeSectionPageTable(PMM_SECTION_SEGMENT Segment)
Definition: sptab.c:165
struct _SEGMENT * PSEGMENT
#define MM_PHYSICALMEMORY_SEGMENT
Definition: mm.h:206
NTSTATUS NTAPI ObInsertObject(IN PVOID Object, IN PACCESS_STATE AccessState OPTIONAL, IN ACCESS_MASK DesiredAccess, IN ULONG ObjectPointerBias, OUT PVOID *NewObject OPTIONAL, OUT PHANDLE Handle)
Definition: obhandle.c:2932
#define TAG_MM_SECTION_SEGMENT
Definition: tag.h:139
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
#define NULL
Definition: types.h:112
#define OBJ_KERNEL_EXCLUSIVE
Definition: obtypes.h:91
#define DPRINT1
Definition: precomp.h:8
_In_ HANDLE Handle
Definition: extypes.h:390
union _SECTION::@2573 u
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define PAGE_EXECUTE_READWRITE
Definition: nt_native.h:1308
PFN_NUMBER MmHighestPhysicalPage
Definition: meminit.c:31
#define STATUS_SUCCESS
Definition: shellext.h:65
LONGLONG QuadPart
Definition: typedefs.h:114
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14

Referenced by MmInitSectionImplementation().

◆ MmCreateSection()

NTSTATUS NTAPI MmCreateSection ( OUT PVOID Section,
IN ACCESS_MASK  DesiredAccess,
IN POBJECT_ATTRIBUTES ObjectAttributes  OPTIONAL,
IN PLARGE_INTEGER  MaximumSize,
IN ULONG  SectionPageProtection,
IN ULONG  AllocationAttributes,
IN HANDLE FileHandle  OPTIONAL,
IN PFILE_OBJECT FileObject  OPTIONAL 
)

Definition at line 4341 of file section.c.

4349 {
4350  NTSTATUS Status;
4351  ULONG Protection;
4352  PSECTION *SectionObject = (PSECTION *)Section;
4353  BOOLEAN FileLock = FALSE;
4354 
4355  /* Check if an ARM3 section is being created instead */
4357  {
4358  if (!(FileObject) && !(FileHandle))
4359  {
4360  return MmCreateArm3Section(Section,
4361  DesiredAccess,
4363  MaximumSize,
4365  AllocationAttributes &~ 1,
4366  FileHandle,
4367  FileObject);
4368  }
4369  }
4370 
4371  /* Convert section flag to page flag */
4373 
4374  /* Check to make sure the protection is correct. Nt* does this already */
4376  if (Protection == MM_INVALID_PROTECTION)
4377  {
4378  DPRINT1("Page protection is invalid\n");
4380  }
4381 
4382  /* Check if this is going to be a data or image backed file section */
4383  if ((FileHandle) || (FileObject))
4384  {
4385  /* These cannot be mapped with large pages */
4387  {
4388  DPRINT1("Large pages cannot be used with an image mapping\n");
4390  }
4391 
4392  /* Did the caller pass a file object ? */
4393  if (FileObject)
4394  {
4395  /* Reference the object directly */
4397 
4398  /* We don't create image mappings with file objects */
4400  }
4401  else
4402  {
4403  /* Reference the file handle to get the object */
4405  MmMakeFileAccess[Protection],
4408  (PVOID*)&FileObject,
4409  NULL);
4410  if (!NT_SUCCESS(Status))
4411  {
4412  DPRINT1("Failed to get a handle to the FO: %lx\n", Status);
4413  return Status;
4414  }
4415 
4416  /* Lock the file */
4418  if (!NT_SUCCESS(Status))
4419  {
4421  return Status;
4422  }
4423 
4424  FileLock = TRUE;
4425 
4426  /* Deny access if there are writes on the file */
4427 #if 0
4429  {
4430  DPRINT1("Cannot create image maps with writers open on the file!\n");
4432  goto Quit;
4433  }
4434 #else
4436  DPRINT1("Creating image map with writers open on the file!\n");
4437 #endif
4438  }
4439  }
4440  else
4441  {
4442  /* A handle must be supplied with SEC_IMAGE, as this is the no-handle path */
4444  }
4445 
4447  {
4449  DesiredAccess,
4451  MaximumSize,
4454  FileObject);
4455  }
4456 #ifndef NEWCC
4457  else if (FileObject != NULL)
4458  {
4460  DesiredAccess,
4462  MaximumSize,
4465  FileObject,
4466  FileHandle != NULL);
4467  }
4468 #else
4469  else if (FileHandle != NULL || FileObject != NULL)
4470  {
4472  DesiredAccess,
4474  MaximumSize,
4477  FileObject);
4478  }
4479 #endif
4480  else
4481  {
4482  /* All cases should be handled above */
4484  }
4485 
4486  if (FileLock)
4488  if (FileObject)
4490 
4491  return Status;
4492 }
_Must_inspect_result_ _Outptr_ PVOID * SectionObject
Definition: fsrtlfuncs.h:860
#define PAGE_NOCACHE
Definition: nt_native.h:1311
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define MM_INVALID_PROTECTION
Definition: miarm.h:63
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK DesiredAccess
Definition: wdfdevice.h:2654
#define SEC_LARGE_PAGES
Definition: mmtypes.h:102
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ ULONG AllocationAttributes
Definition: mmfuncs.h:360
#define TRUE
Definition: types.h:120
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
ACCESS_MASK MmMakeFileAccess[8]
Definition: section.c:32
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:3066
#define SEC_NOCACHE
Definition: mmtypes.h:100
VOID NTAPI FsRtlReleaseFile(IN PFILE_OBJECT FileObject)
Definition: fastio.c:1659
NTSTATUS NTAPI MmCreateArm3Section(OUT PVOID *SectionObject, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN PLARGE_INTEGER InputMaximumSize, IN ULONG SectionPageProtection, IN ULONG AllocationAttributes, IN HANDLE FileHandle OPTIONAL, IN PFILE_OBJECT FileObject OPTIONAL)
Definition: section.c:2463
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_opt_ PLARGE_INTEGER _In_ ULONG SectionPageProtection
Definition: mmfuncs.h:360
HANDLE FileHandle
Definition: stats.c:38
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:496
NTSTATUS NTAPI FsRtlAcquireToCreateMappedSection(_In_ PFILE_OBJECT FileObject, _In_ ULONG SectionPageProtection)
Definition: fastio.c:1647
NTSTATUS Status
Definition: section.c:4755
unsigned char BOOLEAN
return FALSE
Definition: section.c:4880
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ULONG NTAPI MiMakeProtectionMask(IN ULONG Protect)
Definition: section.c:158
#define ObDereferenceObject
Definition: obfuncs.h:203
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
#define STATUS_INVALID_FILE_FOR_SECTION
Definition: ntstatus.h:269
NTSTATUS MmCreateImageSection(PSECTION *SectionObject, ACCESS_MASK DesiredAccess, POBJECT_ATTRIBUTES ObjectAttributes, PLARGE_INTEGER UMaximumSize, ULONG SectionPageProtection, ULONG AllocationAttributes, PFILE_OBJECT FileObject)
Definition: section.c:3108
#define SEC_PHYSICALMEMORY
Definition: mm.h:90
#define STATUS_INVALID_PAGE_PROTECTION
Definition: ntstatus.h:305
POBJECT_TYPE IoFileObjectType
Definition: iomgr.c:36
static NTSTATUS NTAPI MmCreateDataFileSection(PSECTION *SectionObject, ACCESS_MASK DesiredAccess, POBJECT_ATTRIBUTES ObjectAttributes, PLARGE_INTEGER UMaximumSize, ULONG SectionPageProtection, ULONG AllocationAttributes, PFILE_OBJECT FileObject, BOOLEAN GotFileHandle)
Definition: section.c:2272
#define STATUS_INVALID_PARAMETER_6
Definition: ntstatus.h:480
#define NULL
Definition: types.h:112
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_opt_ PLARGE_INTEGER MaximumSize
Definition: mmfuncs.h:360
#define DPRINT1
Definition: precomp.h:8
#define ObReferenceObject
Definition: obfuncs.h:204
#define STATUS_FILE_LOCKED_WITH_WRITERS
Definition: ntstatus.h:112
unsigned int ULONG
Definition: retypes.h:1
#define SEC_IMAGE
Definition: mmtypes.h:96
NTSTATUS NTAPI MmCreateCacheSection(PSECTION *SectionObject, ACCESS_MASK DesiredAccess, POBJECT_ATTRIBUTES ObjectAttributes, PLARGE_INTEGER UMaximumSize, ULONG SectionPageProtection, ULONG AllocationAttributes, PFILE_OBJECT FileObject)

Referenced by CcpAllocateSection(), CcRosInitializeFileCache(), EngCreateSection(), EngCreateSectionHack(), EngLoadModuleEx(), InitGdiHandleTable(), IntGdiAddFontResourceEx(), NtCreateSection(), TestCreateSection(), TestPhysicalMemorySection(), and UserCreateHeap().

◆ MmDereferenceSegment()

VOID NTAPI MmDereferenceSegment ( PMM_SECTION_SEGMENT  Segment)

Definition at line 991 of file section.c.

992 {
993  KIRQL OldIrql;
994 
995  /* Lock the PFN lock because we mess around with SectionObjectPointers */
997 
998  if (InterlockedDecrement64(Segment->ReferenceCount) > 0)
999  {
1000  /* Nothing to do yet */
1002  return;
1003  }
1004 
1005  *Segment->Flags |= MM_SEGMENT_INDELETE;
1006 
1008 
1009  /* Flush the segment */
1010  if (*Segment->Flags & MM_DATAFILE_SEGMENT)
1011  {
1012  /* Free the page table. This will flush any remaining dirty data */
1014 
1016  /* Delete the pointer on the file */
1017  ASSERT(Segment->FileObject->SectionObjectPointer->DataSectionObject == Segment);
1018  Segment->FileObject->SectionObjectPointer->DataSectionObject = NULL;
1020  ObDereferenceObject(Segment->FileObject);
1021 
1023  }
1024  else
1025  {
1026  /* Most grotesque thing ever */
1027  PMM_IMAGE_SECTION_OBJECT ImageSectionObject = CONTAINING_RECORD(Segment->ReferenceCount, MM_IMAGE_SECTION_OBJECT, RefCount);
1028  PMM_SECTION_SEGMENT SectionSegments;
1029  ULONG NrSegments;
1030  ULONG i;
1031 
1033  /* Delete the pointer on the file */
1034  ASSERT(ImageSectionObject->FileObject->SectionObjectPointer->ImageSectionObject == ImageSectionObject);
1035  ImageSectionObject->FileObject->SectionObjectPointer->ImageSectionObject = NULL;
1037 
1038  ObDereferenceObject(ImageSectionObject->FileObject);
1039 
1040  NrSegments = ImageSectionObject->NrSegments;
1041  SectionSegments = ImageSectionObject->Segments;
1042  for (i = 0; i < NrSegments; i++)
1043  {
1044  if (SectionSegments[i].Image.Characteristics & IMAGE_SCN_MEM_SHARED)
1045  {
1046  MmpFreePageFileSegment(&SectionSegments[i]);
1047  }
1048 
1049  MmFreePageTablesSectionSegment(&SectionSegments[i], NULL);
1050  }
1051 
1052  ExFreePoolWithTag(ImageSectionObject->Segments, TAG_MM_SECTION_SEGMENT);
1053  ExFreePoolWithTag(ImageSectionObject, TAG_MM_SECTION_SEGMENT);
1054  }
1055 }
static VOID NTAPI FreeSegmentPage(PMM_SECTION_SEGMENT Segment, PLARGE_INTEGER Offset)
Definition: section.c:961
FORCEINLINE KIRQL MiAcquirePfnLock(VOID)
Definition: mm.h:919
FORCEINLINE VOID MiReleasePfnLock(_In_ KIRQL OldIrql)
Definition: mm.h:926
UCHAR KIRQL
Definition: env_spec_w32.h:591
ASSERT(Segment->Locked)
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
_Inout_ PVOID Segment
Definition: exfuncs.h:1101
VOID NTAPI MmpFreePageFileSegment(PMM_SECTION_SEGMENT Segment)
Definition: section.c:918
PMM_SECTION_SEGMENT Segments
Definition: mm.h:203
#define ObDereferenceObject
Definition: obfuncs.h:203
VOID NTAPI MmFreePageTablesSectionSegment(PMM_SECTION_SEGMENT Segment, FREE_SECTION_PAGE_FUN FreePage)
Definition: sptab.c:299
#define MM_DATAFILE_SEGMENT
Definition: mm.h:207
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
#define IMAGE_SCN_MEM_SHARED
Definition: ntimage.h:238
#define InterlockedDecrement64
Definition: interlocked.h:144
PFILE_OBJECT FileObject
Definition: mm.h:195
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 TAG_MM_SECTION_SEGMENT
Definition: tag.h:139
#define MM_SEGMENT_INDELETE
Definition: mm.h:208
#define NULL
Definition: types.h:112
unsigned int ULONG
Definition: retypes.h:1
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099

Referenced by _MmSetPageEntrySectionSegment(), MiShutdownSystem(), MmCanFileBeTruncated(), MmFlushSegment(), MmMakeDataSectionResident(), MmPageOutPhysicalAddress(), MmpDeleteSection(), MmPurgeSegment(), and MmUnmapViewOfSegment().

◆ MmExtendSection()

NTSTATUS NTAPI MmExtendSection ( _In_ PVOID  _Section,
_Inout_ PLARGE_INTEGER  NewSize 
)

Definition at line 4956 of file section.c.

4959 {
4960  PSECTION Section = _Section;
4961 
4962  /* It makes no sense to extend an image mapping */
4963  if (Section->u.Flags.Image)
4965 
4966  /* Nor is it possible to extend a page file mapping */
4967  if (!Section->u.Flags.File)
4969 
4970  if (!MiIsRosSectionObject(Section))
4971  return STATUS_NOT_IMPLEMENTED;
4972 
4973  /* We just extend the sizes. Shrinking is a no-op ? */
4974  if (NewSize->QuadPart > Section->SizeOfSection.QuadPart)
4975  {
4977  Section->SizeOfSection = *NewSize;
4978 
4979  if (!Section->u.Flags.Reserve)
4980  {
4982  if (Segment->RawLength.QuadPart < NewSize->QuadPart)
4983  {
4984  Segment->RawLength = *NewSize;
4985  Segment->Length.QuadPart = (NewSize->QuadPart + PAGE_SIZE - 1) & ~((LONGLONG)PAGE_SIZE);
4986  }
4988  }
4989  }
4990 
4991  return STATUS_SUCCESS;
4992 }
if(Entry==0)
Definition: section.c:4765
PSEGMENT Segment
Definition: mmtypes.h:809
#define MmLockSectionSegment(x)
Definition: mm.h:1284
return STATUS_NOT_IMPLEMENTED
LARGE_INTEGER SizeOfSection
Definition: mmtypes.h:810
#define MmUnlockSectionSegment(x)
Definition: mm.h:1292
_Inout_ PVOID Segment
Definition: exfuncs.h:1101
int64_t LONGLONG
Definition: typedefs.h:68
struct _MM_SECTION_SEGMENT * PMM_SECTION_SEGMENT
MMSECTION_FLAGS Flags
Definition: mmtypes.h:814
_Must_inspect_result_ _In_ USHORT NewSize
Definition: fltkernel.h:975
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define STATUS_SECTION_NOT_EXTENDED
Definition: ntstatus.h:371
union _SECTION::@2573 u
#define STATUS_SUCCESS
Definition: shellext.h:65
LONGLONG QuadPart
Definition: typedefs.h:114
FORCEINLINE BOOLEAN MiIsRosSectionObject(IN PVOID Section)
Definition: miarm.h:1072

Referenced by CcSetFileSizes(), and NtExtendSection().

◆ MmFlushImageSection()

BOOLEAN NTAPI MmFlushImageSection ( IN PSECTION_OBJECT_POINTERS  SectionObjectPointer,
IN MMFLUSH_TYPE  FlushType 
)

Definition at line 4141 of file section.c.

4143 {
4144  switch(FlushType)
4145  {
4146  case MmFlushForDelete:
4147  case MmFlushForWrite:
4148  {
4149  BOOLEAN Ret = TRUE;
4151 
4152  if (SectionObjectPointer->ImageSectionObject)
4153  {
4154  PMM_IMAGE_SECTION_OBJECT ImageSectionObject = SectionObjectPointer->ImageSectionObject;
4155  if (!(ImageSectionObject->SegFlags & MM_SEGMENT_INDELETE))
4156  Ret = FALSE;
4157  }
4158 
4160  return Ret;
4161  }
4162  }
4163  return FALSE;
4164 }
#define TRUE
Definition: types.h:120
FORCEINLINE KIRQL MiAcquirePfnLock(VOID)
Definition: mm.h:919
FORCEINLINE VOID MiReleasePfnLock(_In_ KIRQL OldIrql)
Definition: mm.h:926
_Must_inspect_result_ _In_ PDEVICE_OBJECT _In_ PSECTION_OBJECT_POINTERS SectionObjectPointer
Definition: fsrtlfuncs.h:1368
UCHAR KIRQL
Definition: env_spec_w32.h:591
unsigned char BOOLEAN
return FALSE
Definition: section.c:4880
IN PFCB IN FAT_FLUSH_TYPE FlushType
Definition: fatprocs.h:1080
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
#define MM_SEGMENT_INDELETE
Definition: mm.h:208

Referenced by _Requires_lock_held_(), Ext2CreateFile(), Ext2IsFileRemovable(), Ext2PurgeFile(), Ext2PurgeVolume(), FatSetRenameInfo(), FFSCreateFile(), FFSPurgeFile(), FFSPurgeVolume(), FFSSetDispositionInfo(), open_file2(), RfsdCreateFile(), RfsdPurgeFile(), RfsdPurgeVolume(), RfsdSetDispositionInfo(), RxCommonSetInformation(), RxPurgeFcbInSystemCache(), RxPurgeFobx(), RxPurgeNetFcb(), set_disposition_information(), UDFCloseAllXXXDelayedInDir(), UDFCommonCreate(), UDFMarkStreamsForDeletion(), UDFSetDispositionInformation(), VfatCreateFile(), vfatPrepareTargetForRename(), and VfatSetDispositionInformation().

◆ MmFlushSegment()

NTSTATUS NTAPI MmFlushSegment ( _In_ PSECTION_OBJECT_POINTERS  SectionObjectPointer,
_In_opt_ PLARGE_INTEGER  Offset,
_In_ ULONG  Length,
_In_opt_ PIO_STATUS_BLOCK  Iosb 
)

Definition at line 4661 of file section.c.

4666 {
4667  LARGE_INTEGER FlushStart, FlushEnd;
4668  NTSTATUS Status;
4669 
4670  if (Offset)
4671  {
4672  FlushStart = *Offset;
4673  Status = RtlLongLongAdd(FlushStart.QuadPart, Length, &FlushEnd.QuadPart);
4674  if (!NT_SUCCESS(Status))
4675  return Status;
4676  }
4677 
4678  if (Iosb)
4679  Iosb->Information = 0;
4680 
4682  if (!Segment)
4683  {
4684  /* Nothing to flush */
4685  if (Iosb)
4686  Iosb->Status = STATUS_SUCCESS;
4687  return STATUS_SUCCESS;
4688  }
4689 
4690  ASSERT(*Segment->Flags & MM_DATAFILE_SEGMENT);
4691 
4693 
4694  if (!Offset)
4695  {
4696  FlushStart.QuadPart = 0;
4697 
4698  /* FIXME: All of this is suboptimal */
4699  ULONG ElemCount = RtlNumberGenericTableElements(&Segment->PageTable);
4700  /* No page. Nothing to flush */
4701  if (!ElemCount)
4702  {
4705  if (Iosb)
4706  {
4707  Iosb->Status = STATUS_SUCCESS;
4708  Iosb->Information = 0;
4709  }
4710  return STATUS_SUCCESS;
4711  }
4712 
4714  FlushEnd.QuadPart = PageTable->FileOffset.QuadPart + _countof(PageTable->PageEntries) * PAGE_SIZE;
4715  }
4716 
4717  FlushStart.QuadPart >>= PAGE_SHIFT;
4718  FlushStart.QuadPart <<= PAGE_SHIFT;
4719 
4720  while (FlushStart.QuadPart < FlushEnd.QuadPart)
4721  {
4723 
4724  if (IS_DIRTY_SSE(Entry))
4725  {
4726  MmCheckDirtySegment(Segment, &FlushStart, FALSE, FALSE);
4727 
4728  if (Iosb)
4729  Iosb->Information += PAGE_SIZE;
4730  }
4731 
4732  FlushStart.QuadPart += PAGE_SIZE;
4733  }
4734 
4736 
4738 
4739  if (Iosb)
4740  Iosb->Status = STATUS_SUCCESS;
4741 
4742  return STATUS_SUCCESS;
4743 }
#define PAGE_SHIFT
Definition: env_spec_w32.h:45
#define MmGetPageEntrySectionSegment(S, O)
Definition: mm.h:1463
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
static PMEM_HOOK PageTable[TOTAL_PAGES]
Definition: memory.c:40
NTSYSAPI ULONG NTAPI RtlNumberGenericTableElements(_In_ PRTL_GENERIC_TABLE Table)
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI MmCheckDirtySegment(PMM_SECTION_SEGMENT Segment, PLARGE_INTEGER Offset, BOOLEAN ForceDirty, BOOLEAN PageOut)
#define MmLockSectionSegment(x)
Definition: mm.h:1284
_Must_inspect_result_ _In_ PDEVICE_OBJECT _In_ PSECTION_OBJECT_POINTERS SectionObjectPointer
Definition: fsrtlfuncs.h:1368
uint32_t ULONG_PTR
Definition: typedefs.h:65
ASSERT(Segment->Locked)
#define IS_DIRTY_SSE(E)
Definition: mm.h:1268
NTSTATUS Status
Definition: section.c:4755
return FALSE
Definition: section.c:4880
#define MmUnlockSectionSegment(x)
Definition: mm.h:1292
_Inout_ PVOID Segment
Definition: exfuncs.h:1101
Status
Definition: gdiplustypes.h:24
return Iosb
Definition: create.c:4402
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define _countof(array)
Definition: sndvol32.h:68
_Must_inspect_result_ NTSYSAPI PVOID NTAPI RtlGetElementGenericTable(_In_ PRTL_GENERIC_TABLE Table, _In_ ULONG I)
#define MM_DATAFILE_SEGMENT
Definition: mm.h:207
#define PAGE_SIZE
Definition: env_spec_w32.h:49
static PMM_SECTION_SEGMENT MiGrabDataSection(PSECTION_OBJECT_POINTERS SectionObjectPointer)
Definition: section.c:90
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
PLARGE_INTEGER Offset
Definition: section.c:4750
unsigned int ULONG
Definition: retypes.h:1
#define STATUS_SUCCESS
Definition: shellext.h:65
VOID NTAPI MmDereferenceSegment(PMM_SECTION_SEGMENT Segment)
Definition: section.c:991
base of all file and directory entries
Definition: entries.h:82
LONGLONG QuadPart
Definition: typedefs.h:114

Referenced by CcFlushCache(), CcRosDeleteFileCache(), and CcRosFlushVacb().

◆ MmFreeSectionPage()

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

Definition at line 3354 of file section.c.

3356 {
3357  ULONG_PTR Entry;
3359  SWAPENTRY SavedSwapEntry;
3363 
3366 
3368 
3370  MemoryArea->SectionData.ViewOffset;
3371 
3372  Segment = MemoryArea->SectionData.Segment;
3373 
3375  while (Entry && MM_IS_WAIT_PTE(Entry))
3376  {
3379 
3380  YieldProcessor();
3381