ReactOS  0.4.15-dev-1623-g66cf1d2
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

NTSTATUS NTAPI MiMapViewInSystemSpace (IN PVOID Section, IN PVOID Session, OUT PVOID *MappedBase, IN OUT PSIZE_T ViewSize)
 
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 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 MmFreeSectionSegments (PFILE_OBJECT FileObject)
 
VOID NTAPI MmSharePageEntrySectionSegment (PMM_SECTION_SEGMENT Segment, PLARGE_INTEGER Offset)
 
BOOLEAN NTAPI MmUnsharePageEntrySectionSegment (PROS_SECTION_OBJECT Section, PMM_SECTION_SEGMENT Segment, PLARGE_INTEGER Offset, BOOLEAN Dirty, BOOLEAN PageOut, ULONG_PTR *InEntry)
 
BOOLEAN MiIsPageFromCache (PMEMORY_AREA MemoryArea, LONGLONG SegOffset)
 
NTSTATUS NTAPI MiCopyFromUserPage (PFN_NUMBER DestPage, const VOID *SrcAddress)
 
NTSTATUS NTAPI MiReadPage (PMEMORY_AREA MemoryArea, LONGLONG SegOffset, PPFN_NUMBER Page)
 
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)
 
VOID MmPageOutDeleteMapping (PVOID Context, PEPROCESS Process, PVOID Address)
 
NTSTATUS NTAPI MmPageOutSectionView (PMMSUPPORT AddressSpace, MEMORY_AREA *MemoryArea, PVOID Address, ULONG_PTR Entry)
 
NTSTATUS NTAPI MmWritePageSectionView (PMMSUPPORT AddressSpace, PMEMORY_AREA MemoryArea, PVOID Address, ULONG PageEntry)
 
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 MmpFreePageFileSegment (PMM_SECTION_SEGMENT Segment)
 
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)
 
NTSTATUS NTAPI MmCreatePageFileSection (PROS_SECTION_OBJECT *SectionObject, ACCESS_MASK DesiredAccess, POBJECT_ATTRIBUTES ObjectAttributes, PLARGE_INTEGER UMaximumSize, ULONG SectionPageProtection, ULONG AllocationAttributes)
 
NTSTATUS NTAPI MmCreateDataFileSection (PROS_SECTION_OBJECT *SectionObject, ACCESS_MASK DesiredAccess, POBJECT_ATTRIBUTES ObjectAttributes, PLARGE_INTEGER UMaximumSize, ULONG SectionPageProtection, ULONG AllocationAttributes, PFILE_OBJECT FileObject)
 
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 (PROS_SECTION_OBJECT *SectionObject, ACCESS_MASK DesiredAccess, POBJECT_ATTRIBUTES ObjectAttributes, PLARGE_INTEGER UMaximumSize, ULONG SectionPageProtection, ULONG AllocationAttributes, PFILE_OBJECT FileObject)
 
static NTSTATUS MmMapViewOfSegment (PMMSUPPORT AddressSpace, PROS_SECTION_OBJECT Section, PMM_SECTION_SEGMENT Segment, PVOID *BaseAddress, SIZE_T ViewSize, ULONG Protect, ULONG 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 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)
 

Variables

MMSESSION MmSession
 
POBJECT_TYPE MmSectionObjectType = NULL
 
ULONG_PTR MmSubsectionBase
 
static ULONG SectionCharacteristicsToProtect [16]
 
ULONG MmMakeFileAccess []
 
static GENERIC_MAPPING MmpSectionMapping
 
static PEXEFMT_LOADER ExeFmtpLoaders []
 

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

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

◆ 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 3136 of file section.c.

3137 {
3138  SIZE_T SizeOfSegments;
3139  PMM_SECTION_SEGMENT Segments;
3140 
3141  /* TODO: check for integer overflow */
3142  SizeOfSegments = sizeof(MM_SECTION_SEGMENT) * NrSegments;
3143 
3145  SizeOfSegments,
3147 
3148  if(Segments)
3149  RtlZeroMemory(Segments, SizeOfSegments);
3150 
3151  return Segments;
3152 }
#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 3581 of file section.c.

3583 {
3585  PVOID FileHeader;
3586  PVOID FileHeaderBuffer;
3587  ULONG FileHeaderSize;
3588  ULONG Flags;
3589  ULONG OldNrSegments;
3590  NTSTATUS Status;
3591  ULONG i;
3592 
3593  /*
3594  * Read the beginning of the file (2 pages). Should be enough to contain
3595  * all (or most) of the headers
3596  */
3597  Offset.QuadPart = 0;
3598 
3600  &Offset,
3601  PAGE_SIZE * 2,
3602  &FileHeader,
3603  &FileHeaderBuffer,
3604  &FileHeaderSize);
3605 
3606  if (!NT_SUCCESS(Status))
3607  return Status;
3608 
3609  if (FileHeaderSize == 0)
3610  {
3611  ExFreePool(FileHeaderBuffer);
3612  return STATUS_UNSUCCESSFUL;
3613  }
3614 
3615  /*
3616  * Look for a loader that can handle this executable
3617  */
3618  for (i = 0; i < RTL_NUMBER_OF(ExeFmtpLoaders); ++ i)
3619  {
3620  RtlZeroMemory(ImageSectionObject, sizeof(*ImageSectionObject));
3621  Flags = 0;
3622 
3623  Status = ExeFmtpLoaders[i](FileHeader,
3624  FileHeaderSize,
3625  FileObject,
3626  ImageSectionObject,
3627  &Flags,
3630 
3631  if (!NT_SUCCESS(Status))
3632  {
3633  if (ImageSectionObject->Segments)
3634  {
3635  ExFreePool(ImageSectionObject->Segments);
3636  ImageSectionObject->Segments = NULL;
3637  }
3638  }
3639 
3641  break;
3642  }
3643 
3644  ExFreePoolWithTag(FileHeaderBuffer, 'rXmM');
3645 
3646  /*
3647  * No loader handled the format
3648  */
3650  {
3653  }
3654 
3655  if (!NT_SUCCESS(Status))
3656  return Status;
3657 
3658  ASSERT(ImageSectionObject->Segments != NULL);
3659 
3660  /*
3661  * Some defaults
3662  */
3663  /* FIXME? are these values platform-dependent? */
3664  if (ImageSectionObject->ImageInformation.MaximumStackSize == 0)
3665  ImageSectionObject->ImageInformation.MaximumStackSize = 0x40000;
3666 
3667  if(ImageSectionObject->ImageInformation.CommittedStackSize == 0)
3668  ImageSectionObject->ImageInformation.CommittedStackSize = 0x1000;
3669 
3670  if(ImageSectionObject->BasedAddress == NULL)
3671  {
3672  if(ImageSectionObject->ImageInformation.ImageCharacteristics & IMAGE_FILE_DLL)
3673  ImageSectionObject->BasedAddress = (PVOID)0x10000000;
3674  else
3675  ImageSectionObject->BasedAddress = (PVOID)0x00400000;
3676  }
3677 
3678  /*
3679  * And now the fun part: fixing the segments
3680  */
3681 
3682  /* Sort them by virtual address */
3683  MmspSortSegments(ImageSectionObject, Flags);
3684 
3685  /* Ensure they don't overlap in memory */
3686  if (!MmspCheckSegmentBounds(ImageSectionObject, Flags))
3688 
3689  /* Ensure they are aligned */
3690  OldNrSegments = ImageSectionObject->NrSegments;
3691 
3692  if (!MmspPageAlignSegments(ImageSectionObject, Flags))
3694 
3695  /* Trim them if the alignment phase merged some of them */
3696  if (ImageSectionObject->NrSegments < OldNrSegments)
3697  {
3698  PMM_SECTION_SEGMENT Segments;
3699  SIZE_T SizeOfSegments;
3700 
3701  SizeOfSegments = sizeof(MM_SECTION_SEGMENT) * ImageSectionObject->NrSegments;
3702 
3703  Segments = ExAllocatePoolWithTag(PagedPool,
3704  SizeOfSegments,
3706 
3707  if (Segments == NULL)
3709 
3710  RtlCopyMemory(Segments, ImageSectionObject->Segments, SizeOfSegments);
3711  ExFreePool(ImageSectionObject->Segments);
3712  ImageSectionObject->Segments = Segments;
3713  }
3714 
3715  /* And finish their initialization */
3716  for ( i = 0; i < ImageSectionObject->NrSegments; ++ i )
3717  {
3718  ExInitializeFastMutex(&ImageSectionObject->Segments[i].Lock);
3719  ImageSectionObject->Segments[i].ReferenceCount = 1;
3720  MiInitializeSectionPageTable(&ImageSectionObject->Segments[i]);
3721  }
3722 
3724  return Status;
3725 }
#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:3398
static VOID NTAPI MmspSortSegments(IN OUT PMM_IMAGE_SECTION_OBJECT ImageSectionObject, IN ULONG Flags)
Definition: section.c:3321
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:3136
#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 ASSERT(a)
Definition: mode.c:45
#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:3125
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:3157
#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
#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 RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#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:3347

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 3157 of file section.c.

3163 {
3164  NTSTATUS Status;
3166  ULONG AdjustOffset;
3167  ULONG OffsetAdjustment;
3168  ULONG BufferSize;
3169  ULONG UsedSize;
3170  PVOID Buffer;
3173 
3175 
3176  if(Length == 0)
3177  {
3178  KeBugCheck(MEMORY_MANAGEMENT);
3179  }
3180 
3181  FileOffset = *Offset;
3182 
3183  /* Negative/special offset: it cannot be used in this context */
3184  if(FileOffset.u.HighPart < 0)
3185  {
3186  KeBugCheck(MEMORY_MANAGEMENT);
3187  }
3188 
3189  AdjustOffset = PAGE_ROUND_DOWN(FileOffset.u.LowPart);
3190  OffsetAdjustment = FileOffset.u.LowPart - AdjustOffset;
3191  FileOffset.u.LowPart = AdjustOffset;
3192 
3193  BufferSize = Length + OffsetAdjustment;
3195 
3196  /* Flush data since we're about to perform a non-cached read */
3197  CcFlushCache(FileObject->SectionObjectPointer,
3198  &FileOffset,
3199  BufferSize,
3200  &Iosb);
3201 
3202  /*
3203  * It's ok to use paged pool, because this is a temporary buffer only used in
3204  * the loading of executables. The assumption is that MmCreateSection is
3205  * always called at low IRQLs and that these buffers don't survive a brief
3206  * initialization phase
3207  */
3209  BufferSize,
3210  'rXmM');
3211  if (!Buffer)
3212  {
3214  }
3215 
3216  UsedSize = 0;
3217 
3219 
3220  UsedSize = (ULONG)Iosb.Information;
3221 
3222  if(NT_SUCCESS(Status) && UsedSize < OffsetAdjustment)
3223  {
3226  }
3227 
3228  if(NT_SUCCESS(Status))
3229  {
3230  *Data = (PVOID)((ULONG_PTR)Buffer + OffsetAdjustment);
3231  *AllocBase = Buffer;
3232  *ReadSize = UsedSize - OffsetAdjustment;
3233  }
3234  else
3235  {
3236  ExFreePoolWithTag(Buffer, 'rXmM');
3237  }
3238 
3239  return Status;
3240 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
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
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
DECLSPEC_NORETURN VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1427
Definition: bufpool.h:45
void * PVOID
Definition: retypes.h:9
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
Status
Definition: gdiplustypes.h:24
#define ASSERT(a)
Definition: mode.c:45
return Iosb
Definition: create.c:4402
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
* PFILE_OBJECT
Definition: iotypes.h:1995
#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_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:159
#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().

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

NTSTATUS NTAPI MiCopyFromUserPage ( PFN_NUMBER  DestPage,
const VOID SrcAddress 
)

Definition at line 1044 of file section.c.

1045 {
1047  KIRQL Irql;
1048  PVOID DestAddress;
1049 
1051  DestAddress = MiMapPageInHyperSpace(Process, DestPage, &Irql);
1052  if (DestAddress == NULL)
1053  {
1054  return(STATUS_NO_MEMORY);
1055  }
1056  ASSERT((ULONG_PTR)DestAddress % PAGE_SIZE == 0);
1057  ASSERT((ULONG_PTR)SrcAddress % PAGE_SIZE == 0);
1058  RtlCopyMemory(DestAddress, SrcAddress, PAGE_SIZE);
1059  MiUnmapPageInHyperSpace(Process, DestAddress, Irql);
1060  return(STATUS_SUCCESS);
1061 }
_Out_ PKIRQL Irql
Definition: csq.h:179
uint32_t ULONG_PTR
Definition: typedefs.h:65
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define PsGetCurrentProcess
Definition: psfuncs.h:17
PVOID NTAPI MiMapPageInHyperSpace(IN PEPROCESS Process, IN PFN_NUMBER Page, IN PKIRQL OldIrql)
Definition: hypermap.c:30
#define ASSERT(a)
Definition: mode.c:45
VOID NTAPI MiUnmapPageInHyperSpace(IN PEPROCESS Process, IN PVOID Address, IN KIRQL OldIrql)
Definition: hypermap.c:93
#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().

◆ MiIsPageFromCache()

BOOLEAN MiIsPageFromCache ( PMEMORY_AREA  MemoryArea,
LONGLONG  SegOffset 
)

Definition at line 1022 of file section.c.

1024 {
1025 #ifndef NEWCC
1026  if (!(MemoryArea->Data.SectionData.Segment->Image.Characteristics & IMAGE_SCN_MEM_SHARED))
1027  {
1028  PROS_SHARED_CACHE_MAP SharedCacheMap;
1029  PROS_VACB Vacb;
1030  SharedCacheMap = MemoryArea->Data.SectionData.Section->FileObject->SectionObjectPointer->SharedCacheMap;
1031  Vacb = CcRosLookupVacb(SharedCacheMap, SegOffset + MemoryArea->Data.SectionData.Segment->Image.FileOffset);
1032  if (Vacb)
1033  {
1034  CcRosReleaseVacb(SharedCacheMap, Vacb, Vacb->Valid, FALSE, TRUE);
1035  return TRUE;
1036  }
1037  }
1038 #endif
1039  return FALSE;
1040 }
union _MEMORY_AREA::@1788 Data
Definition: cc.h:201
#define TRUE
Definition: types.h:120
struct _MEMORY_AREA::@1788::@1789 SectionData
#define FALSE
Definition: types.h:117
NTSTATUS NTAPI CcRosReleaseVacb(PROS_SHARED_CACHE_MAP SharedCacheMap, PROS_VACB Vacb, BOOLEAN Valid, BOOLEAN Dirty, BOOLEAN Mapped)
Definition: view.c:421
#define IMAGE_SCN_MEM_SHARED
Definition: ntimage.h:238
BOOLEAN Valid
Definition: cc.h:208
PROS_VACB NTAPI CcRosLookupVacb(PROS_SHARED_CACHE_MAP SharedCacheMap, LONGLONG FileOffset)
Definition: view.c:458

Referenced by MmPageOutSectionView().

◆ MiMapViewInSystemSpace()

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

◆ MiReadPage()

NTSTATUS NTAPI MiReadPage ( PMEMORY_AREA  MemoryArea,
LONGLONG  SegOffset,
PPFN_NUMBER  Page 
)

Definition at line 1066 of file section.c.

1076 {
1077  LONGLONG BaseOffset;
1080  BOOLEAN UptoDate;
1081  PROS_VACB Vacb;
1083  NTSTATUS Status;
1084  LONGLONG RawLength;
1085  PROS_SHARED_CACHE_MAP SharedCacheMap;
1086  BOOLEAN IsImageSection;
1087  LONGLONG Length;
1088 
1089  FileObject = MemoryArea->Data.SectionData.Section->FileObject;
1090  SharedCacheMap = FileObject->SectionObjectPointer->SharedCacheMap;
1091  RawLength = MemoryArea->Data.SectionData.Segment->RawLength.QuadPart;
1092  FileOffset = SegOffset + MemoryArea->Data.SectionData.Segment->Image.FileOffset;
1093  IsImageSection = MemoryArea->Data.SectionData.Section->AllocationAttributes & SEC_IMAGE ? TRUE : FALSE;
1094 
1095  ASSERT(SharedCacheMap);
1096 
1097  DPRINT("%S %I64x\n", FileObject->FileName.Buffer, FileOffset);
1098 
1099  /*
1100  * If the file system is letting us go directly to the cache and the
1101  * memory area was mapped at an offset in the file which is page aligned
1102  * then get the related VACB.
1103  */
1104  if (((FileOffset % PAGE_SIZE) == 0) &&
1105  ((SegOffset + PAGE_SIZE <= RawLength) || !IsImageSection) &&
1106  !(MemoryArea->Data.SectionData.Segment->Image.Characteristics & IMAGE_SCN_MEM_SHARED))
1107  {
1108 
1109  /*
1110  * Get the related VACB; we use a lower level interface than
1111  * filesystems do because it is safe for us to use an offset with an
1112  * alignment less than the file system block size.
1113  */
1114  Status = CcRosGetVacb(SharedCacheMap,
1115  FileOffset,
1116  &BaseOffset,
1117  &BaseAddress,
1118  &UptoDate,
1119  &Vacb);
1120  if (!NT_SUCCESS(Status))
1121  {
1122  return(Status);
1123  }
1124  if (!UptoDate)
1125  {
1126  /*
1127  * If the VACB isn't up to date then call the file
1128  * system to read in the data.
1129  */
1130  Status = CcReadVirtualAddress(Vacb);
1131  if (!NT_SUCCESS(Status))
1132  {
1133  CcRosReleaseVacb(SharedCacheMap, Vacb, FALSE, FALSE, FALSE);
1134  return Status;
1135  }
1136  }
1137 
1138  /* Probe the page, since it's PDE might not be synced */
1139  (void)*((volatile char*)BaseAddress + FileOffset - BaseOffset);
1140 
1141  /*
1142  * Retrieve the page from the view that we actually want.
1143  */
1144  (*Page) = MmGetPhysicalAddress((char*)BaseAddress +
1145  FileOffset - BaseOffset).LowPart >> PAGE_SHIFT;
1146 
1147  CcRosReleaseVacb(SharedCacheMap, Vacb, TRUE, FALSE, TRUE);
1148  }
1149  else
1150  {
1152  KIRQL Irql;
1153  PVOID PageAddr;
1154  LONGLONG VacbOffset;
1155 
1156  /*
1157  * Allocate a page, this is rather complicated by the possibility
1158  * we might have to move other things out of memory
1159  */
1161  MI_SET_PROCESS2(PsGetCurrentProcess()->ImageFileName);
1163  if (!NT_SUCCESS(Status))
1164  {
1165  return(Status);
1166  }
1167  Status = CcRosGetVacb(SharedCacheMap,
1168  FileOffset,
1169  &BaseOffset,
1170  &BaseAddress,
1171  &UptoDate,
1172  &Vacb);
1173  if (!NT_SUCCESS(Status))
1174  {
1175  return(Status);
1176  }
1177  if (!UptoDate)
1178  {
1179  /*
1180  * If the VACB isn't up to date then call the file
1181  * system to read in the data.
1182  */
1183  Status = CcReadVirtualAddress(Vacb);
1184  if (!NT_SUCCESS(Status))
1185  {
1186  CcRosReleaseVacb(SharedCacheMap, Vacb, FALSE, FALSE, FALSE);
1187  return Status;
1188  }
1189  }
1190 
1192  PageAddr = MiMapPageInHyperSpace(Process, *Page, &Irql);
1193  VacbOffset = BaseOffset + VACB_MAPPING_GRANULARITY - FileOffset;
1194  Length = RawLength - SegOffset;
1195  if (Length <= VacbOffset && Length <= PAGE_SIZE)
1196  {
1197  memcpy(PageAddr, (char*)BaseAddress + FileOffset - BaseOffset, Length);
1198  }
1199  else if (VacbOffset >= PAGE_SIZE)
1200  {
1201  memcpy(PageAddr, (char*)BaseAddress + FileOffset - BaseOffset, PAGE_SIZE);
1202  }
1203  else
1204  {
1205  memcpy(PageAddr, (char*)BaseAddress + FileOffset - BaseOffset, VacbOffset);
1206  MiUnmapPageInHyperSpace(Process, PageAddr, Irql);
1207  CcRosReleaseVacb(SharedCacheMap, Vacb, TRUE, FALSE, FALSE);
1208  Status = CcRosGetVacb(SharedCacheMap,
1209  FileOffset + VacbOffset,
1210  &BaseOffset,
1211  &BaseAddress,
1212  &UptoDate,
1213  &Vacb);
1214  if (!NT_SUCCESS(Status))
1215  {
1216  return(Status);
1217  }
1218  if (!UptoDate)
1219  {
1220  /*
1221  * If the VACB isn't up to date then call the file
1222  * system to read in the data.
1223  */
1224  Status = CcReadVirtualAddress(Vacb);
1225  if (!NT_SUCCESS(Status))
1226  {
1227  CcRosReleaseVacb(SharedCacheMap, Vacb, FALSE, FALSE, FALSE);
1228  return Status;
1229  }
1230  }
1231  PageAddr = MiMapPageInHyperSpace(Process, *Page, &Irql);
1232  if (Length < PAGE_SIZE)
1233  {
1234  memcpy((char*)PageAddr + VacbOffset, BaseAddress, Length - VacbOffset);
1235  }
1236  else
1237  {
1238  memcpy((char*)PageAddr + VacbOffset, BaseAddress, PAGE_SIZE - VacbOffset);
1239  }
1240  }
1241  MiUnmapPageInHyperSpace(Process, PageAddr, Irql);
1242  CcRosReleaseVacb(SharedCacheMap, Vacb, TRUE, FALSE, FALSE);
1243  }
1244  return(STATUS_SUCCESS);
1245 }
#define PAGE_SHIFT
Definition: env_spec_w32.h:45
union _MEMORY_AREA::@1788 Data
Definition: cc.h:201
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
#define TRUE
Definition: types.h:120
#define MC_USER
Definition: mm.h:94
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI MmRequestPageMemoryConsumer(ULONG Consumer, BOOLEAN MyWait, PPFN_NUMBER AllocatedPage)
Definition: balance.c:222
_Out_ PKIRQL Irql
Definition: csq.h:179
NTSTATUS NTAPI CcRosGetVacb(PROS_SHARED_CACHE_MAP SharedCacheMap, LONGLONG FileOffset, PLONGLONG BaseOffset, PVOID *BaseAddress, PBOOLEAN UptoDate, PROS_VACB *Vacb)
Definition: view.c:937
struct _MEMORY_AREA::@1788::@1789 SectionData
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define FALSE
Definition: types.h:117
#define MI_SET_PROCESS2(x)
Definition: mm.h:260
#define PsGetCurrentProcess
Definition: psfuncs.h:17
PVOID NTAPI MiMapPageInHyperSpace(IN PEPROCESS Process, IN PFN_NUMBER Page, IN PKIRQL OldIrql)
Definition: hypermap.c:30
unsigned char BOOLEAN
void DPRINT(...)
Definition: polytest.cpp:61
#define MI_SET_USAGE(x)
Definition: mm.h:259
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
Status
Definition: gdiplustypes.h:24
int64_t LONGLONG
Definition: typedefs.h:68
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define ASSERT(a)
Definition: mode.c:45
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI CcRosReleaseVacb(PROS_SHARED_CACHE_MAP SharedCacheMap, PROS_VACB Vacb, BOOLEAN Valid, BOOLEAN Dirty, BOOLEAN Mapped)
Definition: view.c:421
* PFILE_OBJECT
Definition: iotypes.h:1995
VOID NTAPI MiUnmapPageInHyperSpace(IN PEPROCESS Process, IN PVOID Address, IN KIRQL OldIrql)
Definition: hypermap.c:93
ULONG LowPart
Definition: typedefs.h:106
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define IMAGE_SCN_MEM_SHARED
Definition: ntimage.h:238
#define PAGE_SIZE
Definition: env_spec_w32.h:49
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:159
#define VACB_MAPPING_GRANULARITY
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
#define SEC_IMAGE
Definition: mmtypes.h:96
PHYSICAL_ADDRESS NTAPI MmGetPhysicalAddress(IN PVOID Address)
Definition: stubs.c:686
#define STATUS_SUCCESS
Definition: shellext.h:65
NTSTATUS NTAPI CcReadVirtualAddress(PROS_VACB Vacb)
Definition: copy.c:81

Referenced by MmNotPresentFaultSectionView().

◆ MiRosUnmapViewInSystemSpace()

NTSTATUS NTAPI MiRosUnmapViewInSystemSpace ( IN PVOID  MappedBase)

Definition at line 4899 of file section.c.

4900 {
4902  NTSTATUS Status;
4903 
4904  DPRINT("MmUnmapViewInSystemSpace() called\n");
4905 
4907 
4909 
4911 
4913 
4914  return Status;
4915 }
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG AddressSpace
Definition: iofuncs.h:2268
FORCEINLINE VOID MmUnlockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1427
LONG NTSTATUS
Definition: precomp.h:26
static NTSTATUS MmUnmapViewOfSegment(PMMSUPPORT AddressSpace, PVOID BaseAddress)
Definition: section.c:4070
void DPRINT(...)
Definition: polytest.cpp:61
Status
Definition: gdiplustypes.h:24
FORCEINLINE PMMSUPPORT MmGetKernelAddressSpace(VOID)
Definition: mm.h:1449
_Must_inspect_result_ _Outptr_result_bytebuffer_ ViewSize PVOID * MappedBase
Definition: mmfuncs.h:492
FORCEINLINE VOID MmLockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1420

Referenced by MmUnmapViewInSystemSpace().

◆ MiRosUnmapViewOfSection()

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

Definition at line 4135 of file section.c.

4138 {
4139  NTSTATUS Status;
4142  PROS_SECTION_OBJECT Section;
4143  PVOID ImageBaseAddress = 0;
4144 
4145  DPRINT("Opening memory area Process %p BaseAddress %p\n",
4146  Process, BaseAddress);
4147 
4148  ASSERT(Process);
4149 
4151 
4154  BaseAddress);
4155  if (MemoryArea == NULL ||
4159  {
4162  return STATUS_NOT_MAPPED_VIEW;
4163  }
4164 
4165  Section = MemoryArea->Data.SectionData.Section;
4166 
4167  if ((Section != NULL) && (Section->AllocationAttributes & SEC_IMAGE))
4168  {
4169  ULONG i;
4170  ULONG NrSegments;
4171  PMM_IMAGE_SECTION_OBJECT ImageSectionObject;
4172  PMM_SECTION_SEGMENT SectionSegments;
4174 
4175  Segment = MemoryArea->Data.SectionData.Segment;
4176  ImageSectionObject = Section->ImageSection;
4177  SectionSegments = ImageSectionObject->Segments;
4178  NrSegments = ImageSectionObject->NrSegments;
4179 
4181 
4182  /* Search for the current segment within the section segments
4183  * and calculate the image base address */
4184  for (i = 0; i < NrSegments; i++)
4185  {
4186  if (Segment == &SectionSegments[i])
4187  {
4188  ImageBaseAddress = (char*)BaseAddress - (ULONG_PTR)SectionSegments[i].Image.VirtualAddress;
4189  break;
4190  }
4191  }
4192  if (i >= NrSegments)
4193  {
4194  KeBugCheck(MEMORY_MANAGEMENT);
4195  }
4196 
4197  for (i = 0; i < NrSegments; i++)
4198  {
4199  PVOID SBaseAddress = (PVOID)
4200  ((char*)ImageBaseAddress + (ULONG_PTR)SectionSegments[i].Image.VirtualAddress);
4201 
4202  Status = MmUnmapViewOfSegment(AddressSpace, SBaseAddress);
4203  if (!NT_SUCCESS(Status))
4204  {
4205  DPRINT1("MmUnmapViewOfSegment failed for %p (Process %p) with %lx\n",
4206  SBaseAddress, Process, Status);
4208  }
4209  }
4210  }
4211  else
4212  {
4214  if (!NT_SUCCESS(Status))
4215  {
4216  DPRINT1("MmUnmapViewOfSegment failed for %p (Process %p) with %lx\n",
4219  }
4220  }
4221 
4223 
4224  /* Notify debugger */
4225  if (ImageBaseAddress && !SkipDebuggerNotify) DbgkUnMapViewOfSection(ImageBaseAddress);
4226 
4227  return(STATUS_SUCCESS);
4228 }
union _MEMORY_AREA::@1788 Data
struct _MM_SECTION_SEGMENT::@1785 Image
ULONG Type
Definition: mm.h:220
#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:1427
LONG NTSTATUS
Definition: precomp.h:26
PMEMORY_AREA NTAPI MmLocateMemoryAreaByAddress(PMMSUPPORT AddressSpace, PVOID Address)
Definition: marea.c:60
#define MEMORY_AREA_CACHE
Definition: mm.h:72
uint32_t ULONG_PTR
Definition: typedefs.h:65
static NTSTATUS MmUnmapViewOfSegment(PMMSUPPORT AddressSpace, PVOID BaseAddress)
Definition: section.c:4070
struct _MEMORY_AREA::@1788::@1789 SectionData
PMM_IMAGE_SECTION_OBJECT ImageSection
Definition: mm.h:208
#define MEMORY_AREA_OWNED_BY_ARM3
Definition: mm.h:73
DECLSPEC_NORETURN VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1427
void DPRINT(...)
Definition: polytest.cpp:61
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 ASSERT(a)
Definition: mode.c:45
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
PMM_SECTION_SEGMENT Segments
Definition: mm.h:195
BOOLEAN DeleteInProgress
Definition: mm.h:223
VOID NTAPI DbgkUnMapViewOfSection(IN PVOID BaseAddress)
Definition: dbgkutil.c:436
FORCEINLINE PMMSUPPORT MmGetKernelAddressSpace(VOID)
Definition: mm.h:1449
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 NULL
Definition: types.h:112
#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 SEC_IMAGE
Definition: mmtypes.h:96
ULONG AllocationAttributes
Definition: mm.h:204
#define STATUS_SUCCESS
Definition: shellext.h:65
struct _MEMORY_AREA * MemoryArea
Definition: newmm.h:65
FORCEINLINE VOID MmLockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1420

Referenced by MiRosCleanupMemoryArea(), and MiUnmapViewOfSection().

◆ MmAccessFaultSectionView()

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

Definition at line 1795 of file section.c.

1798 {
1800  PROS_SECTION_OBJECT Section;
1801  PFN_NUMBER OldPage;
1802  PFN_NUMBER NewPage;
1803  NTSTATUS Status;
1804  PVOID PAddress;
1807  ULONG_PTR Entry;
1809 
1810  DPRINT("MmAccessFaultSectionView(%p, %p, %p)\n", AddressSpace, MemoryArea, Address);
1811 
1812  /* Make sure we have a page mapping for this address. */
1814  if (!NT_SUCCESS(Status))
1815  {
1816  /* This is invalid access ! */
1817  return Status;
1818  }
1819 
1820  /*
1821  * Check if the page has already been set readwrite
1822  */
1824  {
1825  DPRINT("Address 0x%p\n", Address);
1826  return(STATUS_SUCCESS);
1827  }
1828 
1829  /*
1830  * Find the offset of the page
1831  */
1832  PAddress = MM_ROUND_DOWN(Address, PAGE_SIZE);
1833  Offset.QuadPart = (ULONG_PTR)PAddress - MA_GetStartingAddress(MemoryArea)
1834  + MemoryArea->Data.SectionData.ViewOffset.QuadPart;
1835 
1836  Segment = MemoryArea->Data.SectionData.Segment;
1837  Section = MemoryArea->Data.SectionData.Section;
1839  &MemoryArea->Data.SectionData.RegionListHead,
1840  Address, NULL);
1841  ASSERT(Region != NULL);
1842 
1843  /*
1844  * Check if we are doing COW
1845  */
1846  if (!((Segment->WriteCopy) &&
1847  (Region->Protect == PAGE_READWRITE ||
1848  Region->Protect == PAGE_EXECUTE_READWRITE)))
1849  {
1850  DPRINT("Address 0x%p\n", Address);
1851  return(STATUS_ACCESS_VIOLATION);
1852  }
1853 
1854  /* Get the page mapping this section offset. */
1857 
1858  /* Get the current page mapping for the process */
1859  ASSERT(MmIsPagePresent(Process, PAddress));
1860  OldPage = MmGetPfnForProcess(Process, PAddress);
1861  ASSERT(OldPage != 0);
1862 
1863  if (IS_SWAP_FROM_SSE(Entry) ||
1864  PFN_FROM_SSE(Entry) != OldPage)
1865  {
1867  /* This is a private page. We must only change the page protection. */
1868  MmSetPageProtect(Process, PAddress, Region->Protect);
1869  return(STATUS_SUCCESS);
1870  }
1871 
1872  /*
1873  * Allocate a page
1874  */
1876  if (Process) MI_SET_PROCESS2(Process->ImageFileName);
1877  if (!Process) MI_SET_PROCESS2("Kernel Section");
1879  if (!NT_SUCCESS(Status))
1880  {
1881  KeBugCheck(MEMORY_MANAGEMENT);
1882  }
1883 
1884  /*
1885  * Copy the old page
1886  */
1887  NT_VERIFY(NT_SUCCESS(MiCopyFromUserPage(NewPage, PAddress)));
1888 
1889  /*
1890  * Unshare the old page.
1891  */
1892  DPRINT("Swapping page (Old %x New %x)\n", OldPage, NewPage);
1893  MmDeleteVirtualMapping(Process, PAddress, NULL, NULL);
1894  MmDeleteRmap(OldPage, Process, PAddress);
1897 
1898  /*
1899  * Set the PTE to point to the new page
1900  */
1902  PAddress,
1903  Region->Protect,
1904  &NewPage,
1905  1);
1906  if (!NT_SUCCESS(Status))
1907  {
1908  DPRINT1("MmCreateVirtualMapping failed, unable to create virtual mapping, not out of memory\n");
1909  KeBugCheck(MEMORY_MANAGEMENT);
1910  return(Status);
1911  }
1912  MmInsertRmap(NewPage, Process, PAddress);
1913 
1915  DPRINT("Address 0x%p\n", Address);
1916  return(STATUS_SUCCESS);
1917 }
PMM_REGION NTAPI MmFindRegion(PVOID BaseAddress, PLIST_ENTRY RegionListHead, PVOID Address, PVOID *RegionBaseAddress)
Definition: region.c:257
union _MEMORY_AREA::@1788 Data
VOID NTAPI MmInsertRmap(PFN_NUMBER Page, struct _EPROCESS *Process, PVOID Address)
#define MiSetPageEvent(Process, Address)
Definition: newmm.h:43
struct _Entry Entry
Definition: kefuncs.h:627
#define PFN_FROM_SSE(E)
Definition: newmm.h:7
NTSTATUS NTAPI MmCreateVirtualMapping(struct _EPROCESS *Process, PVOID Address, ULONG flProtect, PPFN_NUMBER Pages, ULONG PageCount)
ULONG NTAPI MmGetPageProtect(struct _EPROCESS *Process, PVOID Address)
#define TRUE
Definition: types.h:120
#define MC_USER
Definition: mm.h:94
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:396
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI MmRequestPageMemoryConsumer(ULONG Consumer, BOOLEAN MyWait, PPFN_NUMBER AllocatedPage)
Definition: balance.c:222
#define NT_VERIFY(exp)
Definition: rtlfuncs.h:3289
uint32_t ULONG_PTR
Definition: typedefs.h:65
struct _MEMORY_AREA::@1788::@1789 SectionData
BOOLEAN NTAPI MmIsPagePresent(struct _EPROCESS *Process, PVOID Address)
ULONG PFN_NUMBER
Definition: ke.h:9
#define FALSE
Definition: types.h:117
DECLSPEC_NORETURN VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1427
NTSTATUS NTAPI MmNotPresentFaultSectionView(PMMSUPPORT AddressSpace, MEMORY_AREA *MemoryArea, PVOID Address, BOOLEAN Locked)
Definition: section.c:1362
#define MI_SET_PROCESS2(x)
Definition: mm.h:260
BOOLEAN NTAPI MmUnsharePageEntrySectionSegment(PROS_SECTION_OBJECT Section, PMM_SECTION_SEGMENT Segment, PLARGE_INTEGER Offset, BOOLEAN Dirty, BOOLEAN PageOut, ULONG_PTR *InEntry)
Definition: section.c:877
static WCHAR Address[46]
Definition: ping.c:68
VOID NTAPI MmDeleteVirtualMapping(struct _EPROCESS *Process, PVOID Address, BOOLEAN *WasDirty, PPFN_NUMBER Page)
void DPRINT(...)
Definition: polytest.cpp:61
#define MI_SET_USAGE(x)
Definition: mm.h:259
_Inout_ PVOID Segment
Definition: exfuncs.h:1101
Status
Definition: gdiplustypes.h:24
#define ASSERT(a)
Definition: mode.c:45
#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:111
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define IS_SWAP_FROM_SSE(E)
Definition: newmm.h:8
#define MA_GetStartingAddress(_MemoryArea)
Definition: mm.h:213
_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)
FORCEINLINE PEPROCESS MmGetAddressSpaceOwner(IN PMMSUPPORT AddressSpace)
Definition: mm.h:1434
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
#define MmLockSectionSegment(x)
Definition: newmm.h:276
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
#define ULONG_PTR
Definition: config.h:101
#define PAGE_EXECUTE_READWRITE
Definition: nt_native.h:1308
#define STATUS_SUCCESS
Definition: shellext.h:65
#define MmUnlockSectionSegment(x)
Definition: newmm.h:284
NTSTATUS NTAPI MiCopyFromUserPage(PFN_NUMBER DestPage, const VOID *SrcAddress)
Definition: section.c:1044
base of all file and directory entries
Definition: entries.h:82
#define MmGetPageEntrySectionSegment(S, O)
Definition: newmm.h:143
#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 1280 of file section.c.

1287 {
1290  BOOLEAN DoCOW = FALSE;
1291  ULONG i;
1293 
1295  ASSERT(MemoryArea != NULL);
1296  Segment = MemoryArea->Data.SectionData.Segment;
1298 
1299  if ((Segment->WriteCopy) &&
1301  {
1302  DoCOW = TRUE;
1303  }
1304 
1305  if (OldProtect != NewProtect)
1306  {
1307  for (i = 0; i < PAGE_ROUND_UP(RegionSize) / PAGE_SIZE; i++)
1308  {
1309  SWAPENTRY SwapEntry;
1310  PVOID Address = (char*)BaseAddress + (i * PAGE_SIZE);
1312 
1313  /* Wait for a wait entry to disappear */
1314  do
1315  {
1316  MmGetPageFileMapping(Process, Address, &SwapEntry);
1317  if (SwapEntry != MM_WAIT_ENTRY)
1318  break;
1320  }
1321  while (TRUE);
1322 
1323  /*
1324  * If we doing COW for this segment then check if the page is
1325  * already private.
1326  */
1327  if (DoCOW && MmIsPagePresent(Process, Address))
1328  {
1330  ULONG_PTR Entry;
1331  PFN_NUMBER Page;
1332 
1334  + MemoryArea->Data.SectionData.ViewOffset.QuadPart;
1336  /*
1337  * An MM_WAIT_ENTRY is ok in this case... It'll just count as
1338  * IS_SWAP_FROM_SSE and we'll do the right thing.
1339  */
1341 
1343  if (IS_SWAP_FROM_SSE(Entry) || PFN_FROM_SSE(Entry) != Page)
1344  {
1345  Protect = NewProtect;
1346  }
1347  }
1348 
1350  {
1352  Protect);
1353  }
1354  }
1355  }
1356 
1358 }
union _MEMORY_AREA::@1788 Data
struct _Entry Entry
Definition: kefuncs.h:627
#define PFN_FROM_SSE(E)
Definition: newmm.h:7
_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
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG AddressSpace
Definition: iofuncs.h:2268
#define MiWaitForPageEvent(Process, Address)
Definition: newmm.h:38
PMEMORY_AREA NTAPI MmLocateMemoryAreaByAddress(PMMSUPPORT AddressSpace, PVOID Address)
Definition: marea.c:60
uint32_t ULONG_PTR
Definition: typedefs.h:65
struct _MEMORY_AREA::@1788::@1789 SectionData
BOOLEAN NTAPI MmIsPagePresent(struct _EPROCESS *Process, PVOID Address)
ULONG PFN_NUMBER
Definition: ke.h:9
#define FALSE
Definition: types.h:117
unsigned char BOOLEAN
static WCHAR Address[46]
Definition: ping.c:68
VOID NTAPI MmGetPageFileMapping(struct _EPROCESS *Process, PVOID Address, SWAPENTRY *SwapEntry)
_Inout_ PVOID Segment
Definition: exfuncs.h:1101
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define ASSERT(a)
Definition: mode.c:45
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
#define IS_SWAP_FROM_SSE(E)
Definition: newmm.h:8
#define MA_GetStartingAddress(_MemoryArea)
Definition: mm.h:213
_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
ULONG_PTR SWAPENTRY
Definition: mm.h:47
FORCEINLINE PEPROCESS MmGetAddressSpaceOwner(IN PMMSUPPORT AddressSpace)
Definition: mm.h:1434
_Must_inspect_result_ _In_ ULONG NewProtect
Definition: mmfuncs.h:682
#define NULL
Definition: types.h:112
#define PAGE_READONLY
Definition: compat.h:138
#define PAGE_ROUND_UP(x)
Definition: mmtypes.h:38
#define MmLockSectionSegment(x)
Definition: newmm.h:276
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
#define PAGE_EXECUTE_READWRITE
Definition: nt_native.h:1308
#define MmUnlockSectionSegment(x)
Definition: newmm.h:284
struct _MEMORY_AREA * MemoryArea
Definition: newmm.h:65
base of all file and directory entries
Definition: entries.h:82
#define MmGetPageEntrySectionSegment(S, O)
Definition: newmm.h:143
#define PAGE_READWRITE
Definition: nt_native.h:1304

Referenced by MmNotPresentFaultSectionView(), and MmProtectSectionView().

◆ MmCanFileBeTruncated()

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

Definition at line 4722 of file section.c.

4724 {
4725  /* Check whether an ImageSectionObject exists */
4726  if (SectionObjectPointer->ImageSectionObject != NULL)
4727  {
4728  DPRINT1("ERROR: File can't be truncated because it has an image section\n");
4729  return FALSE;
4730  }
4731 
4732  if (SectionObjectPointer->DataSectionObject != NULL)
4733  {
4735 
4737  DataSectionObject;
4738 
4739  if (Segment->ReferenceCount != 0)
4740  {
4741 #ifdef NEWCC
4743  CcpLock();
4744  if (SectionObjectPointer->SharedCacheMap && (Segment->ReferenceCount > CcpCountCacheSections((PNOCC_CACHE_MAP)SectionObjectPointer->SharedCacheMap)))
4745  {
4746  CcpUnlock();
4747  /* Check size of file */
4748  if (SectionObjectPointer->SharedCacheMap)
4749  {
4750  if (!CcGetFileSizes(Segment->FileObject, &FileSizes))
4751  {
4752  return FALSE;
4753  }
4754 
4756  {
4757  return FALSE;
4758  }
4759  }
4760  }
4761  else
4762  CcpUnlock();
4763 #else
4764  /* Check size of file */
4765  if (SectionObjectPointer->SharedCacheMap)
4766  {
4767  PROS_SHARED_CACHE_MAP SharedCacheMap = SectionObjectPointer->SharedCacheMap;
4768  if (NewFileSize->QuadPart <= SharedCacheMap->FileSize.QuadPart)
4769  {
4770  return FALSE;
4771  }
4772  }
4773 #endif
4774  }
4775  else
4776  {
4777  /* Something must gone wrong
4778  * how can we have a Section but no
4779  * reference? */
4780  DPRINT("ERROR: DataSectionObject without reference!\n");
4781  }
4782  }
4783 
4784  DPRINT("FIXME: didn't check for outstanding write probes\n");
4785 
4786  return TRUE;
4787 }
#define CcpLock()
Definition: newcc.h:140
#define TRUE
Definition: types.h:120
static CC_FILE_SIZES FileSizes
BOOLEAN NTAPI CcGetFileSizes(IN PFILE_OBJECT FileObject, IN PCC_FILE_SIZES FileSizes)
Definition: fssup.c:375
_Must_inspect_result_ _In_ PDEVICE_OBJECT _In_ PSECTION_OBJECT_POINTERS SectionObjectPointer
Definition: fsrtlfuncs.h:1368
LARGE_INTEGER FileSize
Definition: cctypes.h:16
#define FALSE
Definition: types.h:117
void DPRINT(...)
Definition: polytest.cpp:61
_Inout_ PVOID Segment
Definition: exfuncs.h:1101
if(!(yy_init))
Definition: macro.lex.yy.c:714
struct _MM_SECTION_SEGMENT * PMM_SECTION_SEGMENT
_In_opt_ PLARGE_INTEGER NewFileSize
Definition: mmfuncs.h:608
ULONG NTAPI CcpCountCacheSections(IN PNOCC_CACHE_MAP Map)
Definition: fssup.c:272
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
LARGE_INTEGER FileSize
Definition: cc.h:175
#define CcpUnlock()
Definition: newcc.h:141
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 2432 of file section.c.

2440 {
2441  SECTION Section;
2442  PSECTION NewSection;
2443  PSUBSECTION Subsection;
2444  PSEGMENT NewSegment, Segment;
2445  NTSTATUS Status;
2446  PCONTROL_AREA ControlArea;
2447  ULONG ProtectionMask, ControlAreaSize, Size, NonPagedCharge, PagedCharge;
2449  BOOLEAN FileLock = FALSE, KernelCall = FALSE;
2450  KIRQL OldIrql;
2452  BOOLEAN UserRefIncremented = FALSE;
2453  PVOID PreviousSectionPointer;
2454 
2455  /* Make the same sanity checks that the Nt interface should've validated */
2458  SEC_NO_CHANGE)) == 0);
2462  SEC_NOCACHE | SEC_NO_CHANGE))));
2468 
2469  /* Convert section flag to page flag */
2471 
2472  /* Check to make sure the protection is correct. Nt* does this already */
2473  ProtectionMask = MiMakeProtectionMask(SectionPageProtection);
2474  if (ProtectionMask == MM_INVALID_PROTECTION) return STATUS_INVALID_PAGE_PROTECTION;
2475 
2476  /* Check if this is going to be a data or image backed file section */
2477  if ((FileHandle) || (FileObject))
2478  {
2479  /* These cannot be mapped with large pages */
2481 
2482  /* For now, only support the mechanism through a file handle */
2483  ASSERT(FileObject == NULL);
2484 
2485  /* Reference the file handle to get the object */
2487  MmMakeFileAccess[ProtectionMask],
2489  PreviousMode,
2490  (PVOID*)&File,
2491  NULL);
2492  if (!NT_SUCCESS(Status)) return Status;
2493 
2494  /* Make sure Cc has been doing its job */
2495  if (!File->SectionObjectPointer)
2496  {
2497  /* This is not a valid file system-based file, fail */
2500  }
2501 
2502  /* Image-file backed sections are not yet supported */
2504 
2505  /* Compute the size of the control area, and allocate it */
2506  ControlAreaSize = sizeof(CONTROL_AREA) + sizeof(MSUBSECTION);
2507  ControlArea = ExAllocatePoolWithTag(NonPagedPool, ControlAreaSize, 'aCmM');
2508  if (!ControlArea)
2509  {
2512  }
2513 
2514  /* Zero it out */
2515  RtlZeroMemory(ControlArea, ControlAreaSize);
2516 
2517  /* Did we get a handle, or an object? */
2518  if (FileHandle)
2519  {
2520  /* We got a file handle so we have to lock down the file */
2521 #if 0
2523  if (!NT_SUCCESS(Status))
2524  {
2525  ExFreePool(ControlArea);
2527  return Status;
2528  }
2529 #else
2530  /* ReactOS doesn't support this API yet, so do nothing */
2532 #endif
2533  /* Update the top-level IRP so that drivers know what's happening */
2535  FileLock = TRUE;
2536  }
2537 
2538  /* Lock the PFN database while we play with the section pointers */
2540 
2541  /* Image-file backed sections are not yet supported */
2543 
2544  /* There should not already be a control area for this file */
2545  ASSERT(File->SectionObjectPointer->DataSectionObject == NULL);
2546  NewSegment = NULL;
2547 
2548  /* Write down that this CA is being created, and set it */
2549  ControlArea->u.Flags.BeingCreated = TRUE;
2551  PreviousSectionPointer = File->SectionObjectPointer;
2552  File->SectionObjectPointer->DataSectionObject = ControlArea;
2553 
2554  /* We can release the PFN lock now */
2556 
2557  /* We don't support previously-mapped file */
2558  ASSERT(NewSegment == NULL);
2559 
2560  /* Image-file backed sections are not yet supported */
2562 
2563  /* So we always create a data file map */
2565  &Segment,
2566  (PSIZE_T)InputMaximumSize,
2569  KernelCall);
2570  if (!NT_SUCCESS(Status))
2571  {
2572  /* Lock the PFN database while we play with the section pointers */
2574 
2575  /* Reset the waiting-for-deletion event */
2576  ASSERT(ControlArea->WaitingForDeletion == NULL);
2577  ControlArea->WaitingForDeletion = NULL;
2578 
2579  /* Set the file pointer NULL flag */
2580  ASSERT(ControlArea->u.Flags.FilePointerNull == 0);
2581  ControlArea->u.Flags.FilePointerNull = TRUE;
2582 
2583  /* Delete the data section object */
2585  File->SectionObjectPointer->DataSectionObject = NULL;
2586 
2587  /* No longer being created */
2588  ControlArea->u.Flags.BeingCreated = FALSE;
2589 
2590  /* We can release the PFN lock now */
2592 
2593  /* Check if we locked and set the IRP */
2594  if (FileLock)
2595  {
2596  /* Undo */
2598  //FsRtlReleaseFile(File);
2599  }
2600 
2601  /* Free the control area and de-ref the file object */
2602  ExFreePool(ControlArea);
2604 
2605  /* All done */
2606  return Status;
2607  }
2608 
2609  /* On success, we expect this */
2610  ASSERT(PreviousSectionPointer == File->SectionObjectPointer);
2611 
2612  /* Check if a maximum size was specified */
2613  if (!InputMaximumSize->QuadPart)
2614  {
2615  /* Nope, use the segment size */
2616  Section.SizeOfSection.QuadPart = (LONGLONG)Segment->SizeOfSegment;
2617  }
2618  else
2619  {
2620  /* Yep, use the entered size */
2621  Section.SizeOfSection.QuadPart = InputMaximumSize->QuadPart;
2622  }
2623  }
2624  else
2625  {
2626  /* A handle must be supplied with SEC_IMAGE, as this is the no-handle path */
2628 
2629  /* Not yet supported */
2631 
2632  /* So this must be a pagefile-backed section, create the mappings needed */
2633  Status = MiCreatePagingFileMap(&NewSegment,
2634  InputMaximumSize,
2635  ProtectionMask,
2637  if (!NT_SUCCESS(Status)) return Status;
2638 
2639  /* Set the size here, and read the control area */
2640  Section.SizeOfSection.QuadPart = NewSegment->SizeOfSegment;
2641  ControlArea = NewSegment->ControlArea;
2642 
2643  /* MiCreatePagingFileMap increments user references */
2644  UserRefIncremented = TRUE;
2645  }
2646 
2647  /* Did we already have a segment? */
2648  if (!NewSegment)
2649  {
2650  /* This must be the file path and we created a segment */
2651  NewSegment = Segment;
2652  ASSERT(File != NULL);
2653 
2654  /* Acquire the PFN lock while we set control area flags */
2656 
2657  /* We don't support this race condition yet, so assume no waiters */
2658  ASSERT(ControlArea->WaitingForDeletion == NULL);
2659  ControlArea->WaitingForDeletion = NULL;
2660 
2661  /* Image-file backed sections are not yet supported, nor ROM images */
2663  ASSERT(Segment->ControlArea->u.Flags.Rom == 0);
2664 
2665  /* Take off the being created flag, and then release the lock */
2666  ControlArea->u.Flags.BeingCreated = FALSE;
2668  }
2669 
2670  /* Check if we locked the file earlier */
2671  if (FileLock)
2672  {
2673  /* Reset the top-level IRP and release the lock */
2675  //FsRtlReleaseFile(File);
2676  FileLock = FALSE;
2677  }
2678 
2679  /* Set the initial section object data */
2680  Section.InitialPageProtection = SectionPageProtection;
2681 
2682  /* The mapping created a control area and segment, save the flags */
2683  Section.Segment = NewSegment;
2684  Section.u.LongFlags = ControlArea->u.LongFlags;
2685 
2686  /* Check if this is a user-mode read-write non-image file mapping */
2687  if (!(FileObject) &&
2689  !(ControlArea->u.Flags.Image) &&
2690  (ControlArea->FilePointer))
2691  {
2692  /* Add a reference and set the flag */
2693  Section.u.Flags.UserWritable = TRUE;
2694  InterlockedIncrement((volatile LONG*)&ControlArea->WritableUserReferences);
2695  }
2696 
2697  /* Check for image mappings or page file mappings */
2698  if ((ControlArea->u.Flags.Image) || !(ControlArea->FilePointer))
2699  {
2700  /* Charge the segment size, and allocate a subsection */
2701  PagedCharge = sizeof(SECTION) + NewSegment->TotalNumberOfPtes * sizeof(MMPTE);
2702  Size = sizeof(SUBSECTION);
2703  }
2704  else
2705  {
2706  /* Charge nothing, and allocate a mapped subsection */
2707  PagedCharge = 0;
2708  Size = sizeof(MSUBSECTION);
2709  }
2710 
2711  /* Check if this is a normal CA */
2712  ASSERT(ControlArea->u.Flags.GlobalOnlyPerSession == 0);
2713  ASSERT(ControlArea->u.Flags.Rom == 0);
2714 
2715  /* Charge only a CA, and the subsection is right after */
2716  NonPagedCharge = sizeof(CONTROL_AREA);
2717  Subsection = (PSUBSECTION)(ControlArea + 1);
2718 
2719  /* We only support single-subsection mappings */
2720  NonPagedCharge += Size;
2721  ASSERT(Subsection->NextSubsection == NULL);
2722 
2723  /* Create the actual section object, with enough space for the prototype PTEs */
2727  PreviousMode,
2728  NULL,
2729  sizeof(SECTION),
2730  PagedCharge,
2731  NonPagedCharge,
2732  (PVOID*)&NewSection);
2733  if (!NT_SUCCESS(Status))
2734  {
2735  /* Check if this is a user-mode read-write non-image file mapping */
2736  if (!(FileObject) &&
2738  !(ControlArea->u.Flags.Image) &&
2739  (ControlArea->FilePointer))
2740  {
2741  /* Remove a reference and check the flag */
2742  ASSERT(Section.u.Flags.UserWritable == 1);
2743  InterlockedDecrement((volatile LONG*)&ControlArea->WritableUserReferences);
2744  }
2745 
2746  /* Check if a user reference was added */
2747  if (UserRefIncremented)
2748  {
2749  /* Acquire the PFN lock while we change counters */
2751 
2752  /* Decrement the accounting counters */
2753  ControlArea->NumberOfSectionReferences--;
2754  ASSERT((LONG)ControlArea->NumberOfUserReferences > 0);
2755  ControlArea->NumberOfUserReferences--;
2756 
2757  /* Check if we should destroy the CA and release the lock */
2758  MiCheckControlArea(ControlArea, OldIrql);
2759  }
2760 
2761  /* Return the failure code */
2762  return Status;
2763  }
2764 
2765  /* NOTE: Past this point, all failures will be handled by Ob upon ref->0 */
2766 
2767  /* Now copy the local section object from the stack into this new object */
2768  RtlCopyMemory(NewSection, &Section, sizeof(SECTION));
2769  NewSection->Address.StartingVpn = 0;
2770 
2771  /* For now, only user calls are supported */
2772  ASSERT(KernelCall == FALSE);
2773  NewSection->u.Flags.UserReference = TRUE;
2774 
2775  /* Is this a "based" allocation, in which all mappings are identical? */
2777  {
2778  /* Lock the VAD tree during the search */
2780 
2781  /* Is it a brand new ControArea ? */
2782  if (ControlArea->u.Flags.BeingCreated == 1)
2783  {
2784  ASSERT(ControlArea->u.Flags.Based == 1);
2785  /* Then we must find a global address, top-down */
2788  _64K,
2790  (ULONG_PTR*)&ControlArea->Segment->BasedAddress);
2791 
2792  if (!NT_SUCCESS(Status))
2793  {
2794  /* No way to find a valid range. */
2796  ControlArea->u.Flags.Based = 0;
2797  NewSection->u.Flags.Based = 0;
2798  ObDereferenceObject(NewSection);
2799  return Status;
2800  }
2801 
2802  /* Compute the ending address and insert it into the VAD tree */
2803  NewSection->Address.StartingVpn = (ULONG_PTR)ControlArea->Segment->BasedAddress;
2804  NewSection->Address.EndingVpn = NewSection->Address.StartingVpn + NewSection->SizeOfSection.LowPart - 1;
2805  MiInsertBasedSection(NewSection);
2806  }
2807  else
2808  {
2809  /* 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 !*/
2810  ASSERT(FALSE);
2811  }
2812 
2814  }
2815 
2816  /* The control area is not being created anymore */
2817  if (ControlArea->u.Flags.BeingCreated == 1)
2818  {
2819  /* Acquire the PFN lock while we set control area flags */
2821 
2822  /* Take off the being created flag, and then release the lock */
2823  ControlArea->u.Flags.BeingCreated = 0;
2824  NewSection->u.Flags.BeingCreated = 0;
2825 
2827  }
2828 
2829  /* Migrate the attribute into a flag */
2830  if (AllocationAttributes & SEC_NO_CHANGE) NewSection->u.Flags.NoChange = TRUE;
2831 
2832  /* If R/W access is not requested, this might eventually become a CoW mapping */
2834  {
2835  NewSection->u.Flags.CopyOnWrite = TRUE;
2836  }
2837 
2838  /* Write down if this was a kernel call */
2839  ControlArea->u.Flags.WasPurged |= KernelCall;
2840  ASSERT(ControlArea->u.Flags.WasPurged == FALSE);
2841 
2842  /* Make sure the segment and the section are the same size, or the section is smaller */
2843  ASSERT((ULONG64)NewSection->SizeOfSection.QuadPart <= NewSection->Segment->SizeOfSegment);
2844 
2845  /* Return the object and the creation status */
2846  *SectionObject = (PVOID)NewSection;
2847  return Status;
2848 }
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:822
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:1503
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:900
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:3070
#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:1519
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
VOID NTAPI MiInsertBasedSection(IN PSECTION Section)
Definition: vadnode.c:345
FORCEINLINE VOID MiReleasePfnLock(_In_ KIRQL OldIrql)
Definition: mm.h:907
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
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
#define FALSE
Definition: types.h:117
struct _SUBSECTION * NextSubsection
Definition: mmtypes.h:581
long LONG
Definition: pedump.c:60
LARGE_INTEGER SizeOfSection
Definition: mmtypes.h:823
#define SEC_RESERVE
Definition: nt_native.h:1323
union _CONTROL_AREA::@2572 u
struct _MSUBSECTION MSUBSECTION
NTSTATUS NTAPI FsRtlAcquireToCreateMappedSection(_In_ PFILE_OBJECT FileObject, _In_ ULONG SectionPageProtection)
Definition: fastio.c:1647
#define PAGE_NOACCESS
Definition: nt_native.h:1302
unsigned char BOOLEAN
ULONG LongFlags
Definition: mmtypes.h:527
struct _SECTION SECTION
void * PVOID
Definition: retypes.h:9
ULONG_PTR StartingVpn
Definition: mmtypes.h:663
_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:664
Status
Definition: gdiplustypes.h:24
int64_t LONGLONG
Definition: typedefs.h:68
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
#define ASSERT(a)
Definition: mode.c:45
#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:130
#define FSRTL_FSP_TOP_LEVEL_IRP
Definition: fsrtltypes.h:59
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
* PFILE_OBJECT
Definition: iotypes.h:1995
#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:827
#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:821
#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:728
VOID FASTCALL KeReleaseGuardedMutex(IN OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:53
PVOID BasedAddress
Definition: mmtypes.h:415
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
union _SECTION::@2588 u
#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()

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

Definition at line 2911 of file section.c.

2921 {
2922  PROS_SECTION_OBJECT Section;
2923  NTSTATUS Status;
2927  ULONG Length;
2928 
2929  /*
2930  * Create the section
2931  */
2936  NULL,
2937  sizeof(ROS_SECTION_OBJECT),
2938  0,
2939  0,
2940  (PVOID*)&Section);
2941  if (!NT_SUCCESS(Status))
2942  {
2944  return(Status);
2945  }
2946  /*
2947  * Initialize it
2948  */
2949  RtlZeroMemory(Section, sizeof(ROS_SECTION_OBJECT));
2950  Section->Type = 'SC';
2951  Section->Size = 'TN';
2954 
2955  /*
2956  * FIXME: This is propably not entirely correct. We can't look into
2957  * the standard FCB header because it might not be initialized yet
2958  * (as in case of the EXT2FS driver by Manoj Paul Joseph where the
2959  * standard file information is filled on first request).
2960  */
2963  sizeof(FILE_STANDARD_INFORMATION),
2964  &FileInfo,
2965  &Length);
2966  if (!NT_SUCCESS(Status))
2967  {
2968  ObDereferenceObject(Section);
2970  return Status;
2971  }
2972 
2973  /*
2974  * FIXME: Revise this once a locking order for file size changes is
2975  * decided
2976  */
2977  if ((UMaximumSize != NULL) && (UMaximumSize->QuadPart != 0))
2978  {
2979  MaximumSize = *UMaximumSize;
2980  }
2981  else
2982  {
2983  MaximumSize = FileInfo.EndOfFile;
2984  /* Mapping zero-sized files isn't allowed. */
2985  if (MaximumSize.QuadPart == 0)
2986  {
2987  ObDereferenceObject(Section);
2990  }
2991  }
2992 
2993  if (MaximumSize.QuadPart > FileInfo.EndOfFile.QuadPart)
2994  {
2997  sizeof(LARGE_INTEGER),
2998  &MaximumSize);
2999  if (!NT_SUCCESS(Status))
3000  {
3001  ObDereferenceObject(Section);
3004  }
3005  }
3006 
3007  if (FileObject->SectionObjectPointer == NULL ||
3008  FileObject->SectionObjectPointer->SharedCacheMap == NULL)
3009  {
3010  ObDereferenceObject(Section);
3013  }
3014 
3015  /*
3016  * Lock the file
3017  */
3019  if (Status != STATUS_SUCCESS)
3020  {
3021  ObDereferenceObject(Section);
3023  return(Status);
3024  }
3025 
3026  /*
3027  * If this file hasn't been mapped as a data file before then allocate a
3028  * section segment to describe the data file mapping
3029  */
3030  if (FileObject->SectionObjectPointer->DataSectionObject == NULL)
3031  {
3034  if (Segment == NULL)
3035  {
3036  //KeSetEvent((PVOID)&FileObject->Lock, IO_NO_INCREMENT, FALSE);
3037  ObDereferenceObject(Section);
3039  return(STATUS_NO_MEMORY);
3040  }
3041  Section->Segment = Segment;
3042  Segment->ReferenceCount = 1;
3044  /*
3045  * Set the lock before assigning the segment to the file object
3046  */
3047  ExAcquireFastMutex(&Segment->Lock);
3048  FileObject->SectionObjectPointer->DataSectionObject = (PVOID)Segment;
3049 
3050  Segment->Image.FileOffset = 0;
3051  Segment->Protection = SectionPageProtection;
3052  Segment->Flags = MM_DATAFILE_SEGMENT;
3053  Segment->Image.Characteristics = 0;
3056  {
3057  Segment->Length.QuadPart = Segment->RawLength.QuadPart = 0;
3058  }
3059  else
3060  {
3061  Segment->RawLength.QuadPart = MaximumSize.QuadPart;
3062  Segment->Length.QuadPart = PAGE_ROUND_UP(Segment->RawLength.QuadPart);
3063  }
3064  Segment->Image.VirtualAddress = 0;
3065  Segment->Locked = TRUE;
3067  }
3068  else
3069  {
3070  /*
3071  * If the file is already mapped as a data file then we may need
3072  * to extend it
3073  */
3074  Segment =
3075  (PMM_SECTION_SEGMENT)FileObject->SectionObjectPointer->
3076  DataSectionObject;
3077  Section->Segment = Segment;
3078  (void)InterlockedIncrementUL(&Segment->ReferenceCount);
3080 
3081  if (MaximumSize.QuadPart > Segment->RawLength.QuadPart &&
3083  {
3084  Segment->RawLength.QuadPart = MaximumSize.QuadPart;
3085  Segment->Length.QuadPart = PAGE_ROUND_UP(Segment->RawLength.QuadPart);
3086  }
3087  }
3089  Section->FileObject = FileObject;
3090  Section->MaximumSize = MaximumSize;
3091 #ifndef NEWCC
3093 #endif
3094  //KeSetEvent((PVOID)&FileObject->Lock, IO_NO_INCREMENT, FALSE);
3095  *SectionObject = Section;
3096  return(STATUS_SUCCESS);
3097 }
_Must_inspect_result_ _Outptr_ PVOID * SectionObject
Definition: fsrtlfuncs.h:860
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
LARGE_INTEGER MaximumSize
Definition: mm.h:202
_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
LONG NTSTATUS
Definition: precomp.h:26
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:3070
NTSTATUS NTAPI IoSetInformation(IN PFILE_OBJECT FileObject, IN FILE_INFORMATION_CLASS FileInformationClass, IN ULONG Length, IN PVOID FileInformation)
Definition: iofunc.c:1312
NTSTATUS NTAPI IoQueryFileInformation(IN PFILE_OBJECT FileObject, IN FILE_INFORMATION_CLASS FileInformationClass, IN ULONG Length, OUT PVOID FileInformation, OUT PULONG ReturnedLength)
Definition: iofunc.c:1272
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_opt_ PLARGE_INTEGER _In_ ULONG SectionPageProtection
Definition: mmfuncs.h:360
#define PAGE_EXECUTE_WRITECOPY
Definition: nt_native.h:1309
#define SEC_RESERVE
Definition: nt_native.h:1323
VOID NTAPI CcRosReferenceCache(PFILE_OBJECT FileObject)
Definition: view.c:1270
void * PVOID
Definition: retypes.h:9
_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
PFILE_OBJECT FileObject
Definition: mm.h:205
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
CSHORT Type
Definition: mm.h:200
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:91
POBJECT_TYPE MmSectionObjectType
Definition: section.c:130
struct _MM_SECTION_SEGMENT * PMM_SECTION_SEGMENT
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
NTSTATUS MmspWaitForFileLock(PFILE_OBJECT File)
Definition: section.c:797
VOID NTAPI MiInitializeSectionPageTable(PMM_SECTION_SEGMENT Segment)
Definition: sptab.c:165
VOID FASTCALL ExAcquireFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:23
#define TAG_MM_SECTION_SEGMENT
Definition: tag.h:139
#define InterlockedIncrementUL(Addend)
Definition: ex.h:1499
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
ULONG SectionPageProtection
Definition: mm.h:203
#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 FileStandardInformation
Definition: propsheet.cpp:61
#define MmLockSectionSegment(x)
Definition: newmm.h:276
struct FileInfo FileInfo
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
CSHORT Size
Definition: mm.h:201
ULONG AllocationAttributes
Definition: mm.h:204
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_MAPPED_FILE_SIZE_ZERO
Definition: ntstatus.h:522
#define MmUnlockSectionSegment(x)
Definition: newmm.h:284
PMM_SECTION_SEGMENT Segment
Definition: mm.h:209
LONGLONG QuadPart
Definition: typedefs.h:114

Referenced by MmCreateSection().

◆ MmCreateImageSection()

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

Definition at line 3728 of file section.c.

3735 {
3736  PROS_SECTION_OBJECT Section;
3737  NTSTATUS Status;
3738  PMM_SECTION_SEGMENT SectionSegments;
3739  PMM_IMAGE_SECTION_OBJECT ImageSectionObject;
3740  ULONG i;
3741 
3742  if (FileObject == NULL)
3744 
3745 #ifndef NEWCC
3746  if (!CcIsFileCached(FileObject))
3747  {
3748  DPRINT1("Denying section creation due to missing cache initialization\n");
3750  }
3751 #endif
3752 
3753  /*
3754  * Create the section
3755  */
3760  NULL,
3761  sizeof(ROS_SECTION_OBJECT),
3762  0,
3763  0,
3764  (PVOID*)(PVOID)&Section);
3765  if (!NT_SUCCESS(Status))
3766  {
3768  return(Status);
3769  }
3770 
3771  /*
3772  * Initialize it
3773  */
3774  RtlZeroMemory(Section, sizeof(ROS_SECTION_OBJECT));
3775  Section->Type = 'SC';
3776  Section->Size = 'TN';
3779 
3780  if (FileObject->SectionObjectPointer->ImageSectionObject == NULL)
3781  {
3782  NTSTATUS StatusExeFmt;
3783 
3785  if (ImageSectionObject == NULL)
3786  {
3788  ObDereferenceObject(Section);
3789  return(STATUS_NO_MEMORY);
3790  }
3791 
3792  RtlZeroMemory(ImageSectionObject, sizeof(MM_IMAGE_SECTION_OBJECT));
3793 
3794  StatusExeFmt = ExeFmtpCreateImageSection(FileObject, ImageSectionObject);
3795 
3796  if (!NT_SUCCESS(StatusExeFmt))
3797  {
3798  if(ImageSectionObject->Segments != NULL)
3799  ExFreePool(ImageSectionObject->Segments);
3800 
3801  /*
3802  * If image file is empty, then return that the file is invalid for section
3803  */
3804  Status = StatusExeFmt;
3805  if (StatusExeFmt == STATUS_END_OF_FILE)
3806  {
3808  }
3809 
3810  ExFreePoolWithTag(ImageSectionObject, TAG_MM_SECTION_SEGMENT);
3811  ObDereferenceObject(Section);
3813  return(Status);
3814  }
3815 
3816  Section->ImageSection = ImageSectionObject;
3817  ASSERT(ImageSectionObject->Segments);
3818 
3819  /*
3820  * Lock the file
3821  */
3823  if (!NT_SUCCESS(Status))
3824  {
3825  ExFreePool(ImageSectionObject->Segments);
3826  ExFreePool(ImageSectionObject);
3827  ObDereferenceObject(Section);
3829  return(Status);
3830  }
3831 
3832  if (NULL != InterlockedCompareExchangePointer(&FileObject->SectionObjectPointer->ImageSectionObject,
3833  ImageSectionObject, NULL))
3834  {
3835  /*
3836  * An other thread has initialized the same image in the background
3837  */
3838  ExFreePool(ImageSectionObject->Segments);
3839  ExFreePool(ImageSectionObject);
3840  ImageSectionObject = FileObject->SectionObjectPointer->ImageSectionObject;
3841  Section->ImageSection = ImageSectionObject;
3842  SectionSegments = ImageSectionObject->Segments;
3843 
3844  for (i = 0; i < ImageSectionObject->NrSegments; i++)
3845  {
3846  (void)InterlockedIncrementUL(&SectionSegments[i].ReferenceCount);
3847  }
3848  }
3849 
3850  Status = StatusExeFmt;
3851  }
3852  else
3853  {
3854  /*
3855  * Lock the file
3856  */
3858  if (Status != STATUS_SUCCESS)
3859  {
3860  ObDereferenceObject(Section);
3862  return(Status);
3863  }
3864 
3865  ImageSectionObject = FileObject->SectionObjectPointer->ImageSectionObject;
3866  Section->ImageSection = ImageSectionObject;
3867  SectionSegments = ImageSectionObject->Segments;
3868 
3869  /*
3870  * Otherwise just reference all the section segments
3871  */
3872  for (i = 0; i < ImageSectionObject->NrSegments; i++)
3873  {
3874  (void)InterlockedIncrementUL(&SectionSegments[i].ReferenceCount);
3875  }
3876 
3878  }
3879  Section->FileObject = FileObject;
3880 #ifndef NEWCC
3882 #endif
3883  //KeSetEvent((PVOID)&FileObject->Lock, IO_NO_INCREMENT, FALSE);
3884  *SectionObject = Section;
3885  return(Status);
3886 }
_Must_inspect_result_ _Outptr_ PVOID * SectionObject
Definition: fsrtlfuncs.h:860
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
NTSTATUS ExeFmtpCreateImageSection(PFILE_OBJECT FileObject, PMM_IMAGE_SECTION_OBJECT ImageSectionObject)
Definition: section.c:3581
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ ULONG AllocationAttributes
Definition: mmfuncs.h:360
LONG NTSTATUS
Definition: precomp.h:26
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:3070
#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
PMM_IMAGE_SECTION_OBJECT ImageSection
Definition: mm.h:208
#define CcIsFileCached(FO)
#define InterlockedCompareExchangePointer
Definition: interlocked.h:129
VOID NTAPI CcRosReferenceCache(PFILE_OBJECT FileObject)
Definition: view.c:1270
_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
PFILE_OBJECT FileObject
Definition: mm.h:205
#define ASSERT(a)
Definition: mode.c:45
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
CSHORT Type
Definition: mm.h:200
PMM_SECTION_SEGMENT Segments
Definition: mm.h:195
#define ObDereferenceObject
Definition: obfuncs.h:203
#define STATUS_INVALID_FILE_FOR_SECTION
Definition: ntstatus.h:269
POBJECT_TYPE MmSectionObjectType
Definition: section.c:130
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
NTSTATUS MmspWaitForFileLock(PFILE_OBJECT File)
Definition: section.c:797
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 InterlockedIncrementUL(Addend)
Definition: ex.h:1499
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
ULONG SectionPageProtection
Definition: mm.h:203
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
CSHORT Size
Definition: mm.h:201
ULONG AllocationAttributes
Definition: mm.h:204
#define STATUS_SUCCESS
Definition: shellext.h:65
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by MmCreateSection().

◆ MmCreatePageFileSection()

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

Definition at line 2836 of file section.c.

2845 {
2847  PROS_SECTION_OBJECT Section;
2849  NTSTATUS Status;
2850 
2851  if (UMaximumSize == NULL)
2852  {
2853  DPRINT1("MmCreatePageFileSection: (UMaximumSize == NULL)\n");
2854  return(STATUS_INVALID_PARAMETER);
2855  }
2856  MaximumSize = *UMaximumSize;
2857 
2858  /*
2859  * Create the section
2860  */
2865  NULL,
2866  sizeof(ROS_SECTION_OBJECT),
2867  0,
2868  0,
2869  (PVOID*)(PVOID)&Section);
2870  if (!NT_SUCCESS(Status))
2871  {
2872  DPRINT1("MmCreatePageFileSection: failed to create object (0x%lx)\n", Status);
2873  return(Status);
2874  }
2875 
2876  /*
2877  * Initialize it
2878  */
2879  RtlZeroMemory(Section, sizeof(ROS_SECTION_OBJECT));
2880  Section->Type = 'SC';
2881  Section->Size = 'TN';
2884  Section->MaximumSize = MaximumSize;
2887  if (Segment == NULL)
2888  {
2889  ObDereferenceObject(Section);
2890  return(STATUS_NO_MEMORY);
2891  }
2893  Section->Segment = Segment;
2894  Segment->ReferenceCount = 1;
2896  Segment->Image.FileOffset = 0;
2897  Segment->Protection = SectionPageProtection;
2898  Segment->RawLength.QuadPart = MaximumSize.u.LowPart;
2899  Segment->Length.QuadPart = PAGE_ROUND_UP(MaximumSize.u.LowPart);
2900  Segment->Flags = MM_PAGEFILE_SEGMENT;
2901  Segment->WriteCopy = FALSE;
2902  Segment->Image.VirtualAddress = 0;
2903  Segment->Image.Characteristics = 0;
2904  *SectionObject = Section;
2906  return(STATUS_SUCCESS);
2907 }
_Must_inspect_result_ _Outptr_ PVOID * SectionObject
Definition: fsrtlfuncs.h:860
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
LARGE_INTEGER MaximumSize
Definition: mm.h:202
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ ULONG AllocationAttributes
Definition: mmfuncs.h:360
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:3070
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_opt_ PLARGE_INTEGER _In_ ULONG SectionPageProtection
Definition: mmfuncs.h:360
#define FALSE
Definition: types.h:117
_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
CSHORT Type
Definition: mm.h:200
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274
#define ObDereferenceObject
Definition: obfuncs.h:203
POBJECT_TYPE MmSectionObjectType
Definition: section.c:130
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define MM_PAGEFILE_SEGMENT
Definition: mm.h:90
VOID NTAPI MiInitializeSectionPageTable(PMM_SECTION_SEGMENT Segment)
Definition: sptab.c:165
#define TAG_MM_SECTION_SEGMENT
Definition: tag.h:139
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
ULONG SectionPageProtection
Definition: mm.h:203
#define NULL
Definition: types.h:112
#define PAGE_ROUND_UP(x)
Definition: mmtypes.h:38
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_opt_ PLARGE_INTEGER MaximumSize
Definition: mmfuncs.h:360
#define DPRINT1
Definition: precomp.h:8
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
CSHORT Size
Definition: mm.h:201
ULONG AllocationAttributes
Definition: mm.h:204
#define STATUS_SUCCESS
Definition: shellext.h:65
PMM_SECTION_SEGMENT Segment
Definition: mm.h:209

Referenced by MmCreateSection().

◆ MmCreatePhysicalMemorySection()

NTSTATUS NTAPI MmCreatePhysicalMemorySection ( VOID  )

Definition at line 2753 of file section.c.

2754 {
2755  PROS_SECTION_OBJECT PhysSection;
2756  NTSTATUS Status;
2758  UNICODE_STRING Name = RTL_CONSTANT_STRING(L"\\Device\\PhysicalMemory");
2759  LARGE_INTEGER SectionSize;
2760  HANDLE Handle;
2761 
2762  /*
2763  * Create the section mapping physical memory
2764  */
2765  SectionSize.QuadPart = 0xFFFFFFFF;
2767  &Name,
2769  NULL,
2770  NULL);
2771  Status = MmCreateSection((PVOID)&PhysSection,
2773  &Obj,
2774  &SectionSize,
2777  NULL,
2778  NULL);
2779  if (!NT_SUCCESS(Status))
2780  {
2781  DPRINT1("Failed to create PhysicalMemory section\n");
2782  KeBugCheck(MEMORY_MANAGEMENT);
2783  }
2784  Status = ObInsertObject(PhysSection,
2785  NULL,
2787  0,
2788  NULL,
2789  &Handle);
2790  if (!NT_SUCCESS(Status))
2791  {
2792  ObDereferenceObject(PhysSection);
2793  }
2795  PhysSection->AllocationAttributes |= SEC_PHYSICALMEMORY;
2796  PhysSection->Segment->Flags &= ~MM_PAGEFILE_SEGMENT;
2797 
2798  return(STATUS_SUCCESS);
2799 }
LONG NTSTATUS
Definition: precomp.h:26
#define SECTION_ALL_ACCESS
Definition: nt_native.h:1293
DECLSPEC_NORETURN VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1427
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
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: section.c:4973
#define ObDereferenceObject
Definition: obfuncs.h:203
ULONG Flags
Definition: mm.h:175
#define MM_PAGEFILE_SEGMENT
Definition: mm.h:90
NTSTATUS NTAPI ObCloseHandle(IN HANDLE Handle, IN KPROCESSOR_MODE AccessMode)
Definition: obhandle.c:3376
static const WCHAR L[]
Definition: oid.c:1250
#define SEC_PHYSICALMEMORY
Definition: mm.h:88
#define OBJ_PERMANENT
Definition: winternl.h:226
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 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
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
ULONG AllocationAttributes
Definition: mm.h:204
#define PAGE_EXECUTE_READWRITE
Definition: nt_native.h:1308
#define STATUS_SUCCESS
Definition: shellext.h:65
PMM_SECTION_SEGMENT Segment
Definition: mm.h:209
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 4973 of file section.c.

4981 {
4982  NTSTATUS Status;
4983  ULONG Protection;
4985 
4986  /* Check if an ARM3 section is being created instead */
4988  {
4989  if (!(FileObject) && !(FileHandle))
4990  {
4991  return MmCreateArm3Section(Section,
4992  DesiredAccess,
4994  MaximumSize,
4996  AllocationAttributes &~ 1,
4997  FileHandle,
4998  FileObject);
4999  }
5000  }
5001 
5002  /* Convert section flag to page flag */
5004 
5005  /* Check to make sure the protection is correct. Nt* does this already */
5007  if (Protection == MM_INVALID_PROTECTION)
5008  {
5009  DPRINT1("Page protection is invalid\n");
5011  }
5012 
5013  /* Check if this is going to be a data or image backed file section */
5014  if ((FileHandle) || (FileObject))
5015  {
5016  /* These cannot be mapped with large pages */
5018  {
5019  DPRINT1("Large pages cannot be used with an image mapping\n");
5021  }
5022 
5023  /* Did the caller pass an object? */
5024  if (FileObject)
5025  {
5026  /* Reference the object directly */
5028  }
5029  else
5030  {
5031  /* Reference the file handle to get the object */
5033  MmMakeFileAccess[Protection],
5036  (PVOID*)&FileObject,
5037  NULL);
5038  if (!NT_SUCCESS(Status))
5039  {
5040  DPRINT1("Failed to get a handle to the FO: %lx\n", Status);
5041  return Status;
5042  }
5043  }
5044  }
5045  else
5046  {
5047  /* A handle must be supplied with SEC_IMAGE, as this is the no-handle path */
5049  }
5050 
5051 #ifndef NEWCC // A hack for initializing caching.
5052  // This is needed only in the old case.
5053  if (FileHandle)
5054  {
5056  NTSTATUS Status;
5057  CHAR Buffer;
5059  ByteOffset.QuadPart = 0;
5060  Status = ZwReadFile(FileHandle,
5061  NULL,
5062  NULL,
5063  NULL,
5064  &Iosb,
5065  &Buffer,
5066  sizeof(Buffer),
5067  &ByteOffset,
5068  NULL);
5070  {
5071  DPRINT1("CC failure: %lx\n", Status);
5072  if (FileObject)
5074  return Status;
5075  }
5076  // Caching is initialized...
5077 
5078  // Hack of the hack: actually, it might not be initialized if FSD init on effective right and if file is null-size
5079  // In such case, force cache by initiating a write IRP
5081  (FileObject->SectionObjectPointer == NULL || FileObject->SectionObjectPointer->SharedCacheMap == NULL))
5082  {
5083  Buffer = 0xdb;
5084  Status = ZwWriteFile(FileHandle,
5085  NULL,
5086  NULL,
5087  NULL,
5088  &Iosb,
5089  &Buffer,
5090  sizeof(Buffer),
5091  &ByteOffset,
5092  NULL);
5093  if (NT_SUCCESS(Status))
5094  {
5096  Zero.QuadPart = 0LL;
5097 
5100  sizeof(LARGE_INTEGER),
5101  &Zero);
5103  }
5104  }
5105  }
5106 #endif
5107 
5109  {
5111  DesiredAccess,
5113  MaximumSize,
5116  FileObject);
5117  }
5118 #ifndef NEWCC
5119  else if (FileHandle != NULL)
5120  {
5122  DesiredAccess,
5124  MaximumSize,
5127  FileObject);
5128  }
5129 #else
5130  else if (FileHandle != NULL || FileObject != NULL)
5131  {
5133  DesiredAccess,
5135  MaximumSize,
5138  FileObject);
5139  }
5140 #endif
5141  else
5142  {
5144  {
5145  DPRINT1("Invalid path: %lx %p %p\n", AllocationAttributes, FileObject, FileHandle);
5146  }
5147 // ASSERT(AllocationAttributes & SEC_PHYSICALMEMORY);
5149  DesiredAccess,
5151  MaximumSize,
5154  if (FileObject)
5156  }
5157 
5158  return Status;
5159 }
_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 LL
Definition: tui.h:84
#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
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
char CHAR
Definition: xmlstorage.h:175
LONG NTSTATUS
Definition: precomp.h:26
ACCESS_MASK MmMakeFileAccess[8]
Definition: section.c:32
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:3070
NTSTATUS NTAPI IoSetInformation(IN PFILE_OBJECT FileObject, IN FILE_INFORMATION_CLASS FileInformationClass, IN ULONG Length, IN PVOID FileInformation)
Definition: iofunc.c:1312
#define SEC_NOCACHE
Definition: mmtypes.h:100
#define STATUS_END_OF_FILE
Definition: shellext.h:67
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:2432
_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 MmCreateCacheSection(PROS_SECTION_OBJECT *SectionObject, ACCESS_MASK DesiredAccess, POBJECT_ATTRIBUTES ObjectAttributes, PLARGE_INTEGER UMaximumSize, ULONG SectionPageProtection, ULONG AllocationAttributes, PFILE_OBJECT FileObject)
Definition: data.c:308
Definition: bufpool.h:45
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
Status
Definition: gdiplustypes.h:24
#define ASSERT(a)
Definition: mode.c:45
return Iosb
Definition: create.c:4402
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI MmCreatePageFileSection(PROS_SECTION_OBJECT *SectionObject, ACCESS_MASK DesiredAccess, POBJECT_ATTRIBUTES ObjectAttributes, PLARGE_INTEGER UMaximumSize, ULONG SectionPageProtection, ULONG AllocationAttributes)
Definition: section.c:2836
ULONG NTAPI MiMakeProtectionMask(IN ULONG Protect)
Definition: section.c:158
#define ObDereferenceObject
Definition: obfuncs.h:203
NTSTATUS MmCreateImageSection(PROS_SECTION_OBJECT *SectionObject, ACCESS_MASK DesiredAccess, POBJECT_ATTRIBUTES ObjectAttributes, PLARGE_INTEGER UMaximumSize, ULONG SectionPageProtection, ULONG AllocationAttributes, PFILE_OBJECT FileObject)
Definition: section.c:3728
#define STATUS_INVALID_FILE_FOR_SECTION
Definition: ntstatus.h:269
#define SEC_PHYSICALMEMORY
Definition: mm.h:88
#define STATUS_INVALID_PAGE_PROTECTION
Definition: ntstatus.h:305
POBJECT_TYPE IoFileObjectType
Definition: iomgr.c:36
NTSTATUS NTAPI MmCreateDataFileSection(PROS_SECTION_OBJECT *SectionObject, ACCESS_MASK DesiredAccess, POBJECT_ATTRIBUTES ObjectAttributes, PLARGE_INTEGER UMaximumSize, ULONG SectionPageProtection, ULONG AllocationAttributes, PFILE_OBJECT FileObject)
Definition: section.c:2911
#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
IN PVCB IN VBO IN ULONG OUT PBCB OUT PVOID IN BOOLEAN IN BOOLEAN Zero
Definition: fatprocs.h:411
#define DPRINT1
Definition: precomp.h:8
#define ObReferenceObject
Definition: obfuncs.h:204
unsigned int ULONG
Definition: retypes.h:1
#define SEC_IMAGE
Definition: mmtypes.h:96
IN PDCB IN PCCB IN VBO IN OUT PULONG OUT PDIRENT OUT PBCB OUT PVBO ByteOffset
Definition: fatprocs.h:725

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

◆ MmFlushImageSection()

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

Definition at line 4796 of file section.c.

4798 {
4799  BOOLEAN Result = TRUE;
4800 #ifdef NEWCC
4802 #endif
4803 
4804  switch(FlushType)
4805  {
4806  case MmFlushForDelete:
4807  if (SectionObjectPointer->ImageSectionObject ||
4808  SectionObjectPointer->DataSectionObject)
4809  {
4810  return FALSE;
4811  }
4812 #ifndef NEWCC
4814 #endif
4815  return TRUE;
4816  case MmFlushForWrite:
4817  {
4818  DPRINT("MmFlushImageSection(%d)\n", FlushType);
4819 #ifdef NEWCC
4820  Segment = (PMM_SECTION_SEGMENT)SectionObjectPointer->DataSectionObject;
4821 #endif
4822 
4823  if (SectionObjectPointer->ImageSectionObject)
4824  {
4825  DPRINT1("SectionObject has ImageSection\n");
4826  return FALSE;
4827  }
4828 
4829 #ifdef NEWCC
4830  CcpLock();
4831  Result = !SectionObjectPointer->SharedCacheMap || (Segment->ReferenceCount == CcpCountCacheSections((PNOCC_CACHE_MAP)SectionObjectPointer->SharedCacheMap));
4832  CcpUnlock();
4833  DPRINT("Result %d\n", Result);
4834 #endif
4835  return Result;
4836  }
4837  }
4838  return FALSE;
4839 }
#define CcpLock()
Definition: newcc.h:140
#define TRUE
Definition: types.h:120
_Must_inspect_result_ _In_ PDEVICE_OBJECT _In_ PSECTION_OBJECT_POINTERS SectionObjectPointer
Definition: fsrtlfuncs.h:1368
#define FALSE
Definition: types.h:117
unsigned char BOOLEAN
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
void DPRINT(...)
Definition: polytest.cpp:61
IN PFCB IN FAT_FLUSH_TYPE FlushType
Definition: fatprocs.h:1080
_Inout_ PVOID Segment
Definition: exfuncs.h:1101
if(!(yy_init))
Definition: macro.lex.yy.c:714
struct _MM_SECTION_SEGMENT * PMM_SECTION_SEGMENT
VOID NTAPI CcRosRemoveIfClosed(PSECTION_OBJECT_POINTERS SectionObjectPointer)
Definition: view.c:1286
ULONG NTAPI CcpCountCacheSections(IN PNOCC_CACHE_MAP Map)
Definition: fssup.c:272
#define DPRINT1
Definition: precomp.h:8
#define CcpUnlock()
Definition: newcc.h:141

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().

◆ MmFreeSectionPage()

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

Definition at line 3968 of file section.c.

3970 {
3971  ULONG_PTR Entry;
3972 #ifndef NEWCC
3974  PROS_SHARED_CACHE_MAP SharedCacheMap;
3975 #endif
3977  SWAPENTRY SavedSwapEntry;
3978  PROS_SECTION_OBJECT Section;
3982 
3985 
3987 
3989  MemoryArea->Data.SectionData.ViewOffset.QuadPart;
3990 
3991  Section = MemoryArea->Data.SectionData.Section;
3992  Segment = MemoryArea->Data.SectionData.Segment;
3993 
3995  while (Entry && MM_IS_WAIT_PTE(Entry))
3996  {
3999 
4001 
4005  }
4006 
4007  /*
4008  * For a dirty, datafile, non-private page mark it as dirty in the
4009  * cache manager.
4010  */
4011  if (Segment->Flags & MM_DATAFILE_SEGMENT)
4012  {
4013  if (Page == PFN_FROM_SSE(Entry) && Dirty)
4014  {
4015 #ifndef NEWCC
4016  FileObject = MemoryArea->Data.SectionData.Section->FileObject;
4017  SharedCacheMap = FileObject->SectionObjectPointer->SharedCacheMap;
4018  CcRosMarkDirtyFile(SharedCacheMap, Offset.QuadPart + Segment->Image.FileOffset);
4019 #endif
4020  ASSERT(SwapEntry == 0);
4021  }
4022  }
4023 
4024  if (SwapEntry != 0)
4025  {
4026  /*
4027  * Sanity check
4028  */
4029  if (Segment->Flags & MM_PAGEFILE_SEGMENT)
4030  {
4031  DPRINT1("Found a swap entry for a page in a pagefile section.\n");
4032  KeBugCheck(MEMORY_MANAGEMENT);
4033  }
4034  MmFreeSwapPage(SwapEntry);
4035  }
4036  else if (Page != 0)
4037  {
4038  if (IS_SWAP_FROM_SSE(Entry) ||
4039  Page != PFN_FROM_SSE(Entry))
4040  {
4041  /*
4042  * Sanity check
4043  */
4044  if (Segment->Flags & MM_PAGEFILE_SEGMENT)
4045  {
4046  DPRINT1("Found a private page in a pagefile section.\n");
4047  KeBugCheck(MEMORY_MANAGEMENT);
4048  }
4049  /*
4050  * Just dereference private pages
4051  */
4052  SavedSwapEntry = MmGetSavedSwapEntryPage(Page);
4053  if (SavedSwapEntry != 0)
4054  {
4055  MmFreeSwapPage(SavedSwapEntry);
4056  MmSetSavedSwapEntryPage(Page, 0);
4057  }
4058  MmDeleteRmap(Page, Process, Address);
4060  }
4061  else
4062  {
4063  MmDeleteRmap(Page, Process, Address);
4065  }
4066  }
4067 }
union _MEMORY_AREA::@1788 Data
struct _Entry Entry
Definition: kefuncs.h:627
#define PFN_FROM_SSE(E)
Definition: newmm.h:7
#define MC_USER
Definition: mm.h:94
VOID NTAPI MmDeleteRmap(PFN_NUMBER Page, struct _EPROCESS *Process, PVOID Address)
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG AddressSpace
Definition: iofuncs.h:2268
FORCEINLINE VOID MmUnlockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1427
NTSTATUS NTAPI MmReleasePageMemoryConsumer(ULONG Consumer, PFN_NUMBER Page)
Definition: balance.c:90
#define PAGE_ROUND_DOWN(x)
Definition: mmtypes.h:36
#define MiWaitForPageEvent(Process, Address)
Definition: newmm.h:38
uint32_t ULONG_PTR
Definition: typedefs.h:65
struct _MEMORY_AREA::@1788::@1789 SectionData
#define FALSE
Definition: types.h:117
DECLSPEC_NORETURN VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1427
BOOLEAN NTAPI MmUnsharePageEntrySectionSegment(PROS_SECTION_OBJECT Section, PMM_SECTION_SEGMENT Segment, PLARGE_INTEGER Offset, BOOLEAN Dirty, BOOLEAN PageOut, ULONG_PTR *InEntry)
Definition: section.c:877
static WCHAR Address[46]
Definition: ping.c:68
void * PVOID
Definition: retypes.h:9
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
_Inout_ PVOID Segment
Definition: exfuncs.h:1101
struct _MMSUPPORT * PMMSUPPORT
#define ASSERT(a)
Definition: mode.c:45
#define MM_DATAFILE_SEGMENT
Definition: mm.h:91
* PFILE_OBJECT
Definition: iotypes.h:1995
#define MM_PAGEFILE_SEGMENT
Definition: mm.h:90
#define IS_SWAP_FROM_SSE(E)
Definition: newmm.h:8
#define MA_GetStartingAddress(_MemoryArea)
Definition: mm.h:213
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
ULONG_PTR SWAPENTRY
Definition: mm.h:47
FORCEINLINE PEPROCESS MmGetAddressSpaceOwner(IN PMMSUPPORT AddressSpace)
Definition: mm.h:1434
#define NULL
Definition: types.h:112
NTSTATUS NTAPI CcRosMarkDirtyFile(PROS_SHARED_CACHE_MAP SharedCacheMap, LONGLONG FileOffset)
Definition: view.c:572
#define DPRINT1
Definition: precomp.h:8
#define MmLockSectionSegment(x)
Definition: newmm.h:276
#define MM_IS_WAIT_PTE(E)
Definition: newmm.h:9
VOID NTAPI MmSetSavedSwapEntryPage(PFN_NUMBER Page, SWAPENTRY SavedSwapEntry)
Definition: freelist.c:454
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
#define ULONG_PTR
Definition: config.h:101
#define MmUnlockSectionSegment(x)
Definition: newmm.h:284
FORCEINLINE VOID MmLockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1420
base of all file and directory entries
Definition: entries.h:82
#define MmGetPageEntrySectionSegment(S, O)
Definition: newmm.h:143
VOID NTAPI MmFreeSwapPage(SWAPENTRY Entry)
Definition: pagefile.c:274
SWAPENTRY NTAPI MmGetSavedSwapEntryPage(PFN_NUMBER Page)
Definition: freelist.c:470

Referenced by MmUnmapViewOfSegment().

◆ MmFreeSectionSegments()

VOID NTAPI MmFreeSectionSegments ( PFILE_OBJECT  FileObject)

Definition at line 805 of file section.c.

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

Referenced by CcRosDereferenceCache(), and CcRosReleaseFileCache().

◆ MmInitSectionImplementation()

NTSTATUS NTAPI MmInitSectionImplementation ( VOID  )

Definition at line 2804 of file section.c.

2805 {
2806  OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;
2808 
2809  DPRINT("Creating Section Object Type\n");
2810 
2811  /* Initialize the section based root */
2814 
2815  /* Initialize the Section object type */
2816  RtlZeroMemory(&ObjectTypeInitializer, sizeof(ObjectTypeInitializer));
2817  RtlInitUnicodeString(&Name, L"Section");
2818  ObjectTypeInitializer.Length = sizeof(ObjectTypeInitializer);
2819  ObjectTypeInitializer.DefaultPagedPoolCharge = sizeof(ROS_SECTION_OBJECT);
2820  ObjectTypeInitializer.PoolType = PagedPool;
2821  ObjectTypeInitializer.UseDefaultObject = TRUE;
2822  ObjectTypeInitializer.GenericMapping = MmpSectionMapping;
2823  ObjectTypeInitializer.DeleteProcedure = MmpDeleteSection;
2824  ObjectTypeInitializer.CloseProcedure = MmpCloseSection;
2825  ObjectTypeInitializer.ValidAccessMask = SECTION_ALL_ACCESS;
2826  ObjectTypeInitializer.InvalidAttributes = OBJ_OPENLINK;
2827  ObCreateObjectType(&Name, &ObjectTypeInitializer, NULL, &MmSectionObjectType);
2828 
2830 
2831  return(STATUS_SUCCESS);
2832 }
#define OBJ_OPENLINK
Definition: winternl.h:230
NTSTATUS NTAPI ObCreateObjectType(IN PUNICODE_STRING TypeName, IN POBJECT_TYPE_INITIALIZER ObjectTypeInitializer, IN PVOID Reserved, OUT POBJECT_TYPE *ObjectType)
Definition: oblife.c:1048
#define TRUE
Definition: types.h:120
VOID NTAPI MmpCloseSection(IN PEPROCESS Process OPTIONAL, IN PVOID Object, IN ACCESS_MASK GrantedAccess, IN ULONG ProcessHandleCount, IN ULONG SystemHandleCount)
Definition: section.c:2741
ULONG_PTR NumberGenericTableElements
Definition: mmtypes.h:678
MM_AVL_TABLE MmSectionBasedRoot
Definition: section.c:109
MMADDRESS_NODE BalancedRoot
Definition: mmtypes.h:672
#define SECTION_ALL_ACCESS
Definition: nt_native.h:1293
static GENERIC_MAPPING MmpSectionMapping
Definition: section.c:160
NTSTATUS NTAPI MmCreatePhysicalMemorySection(VOID)
Definition: section.c:2753
struct NameRec_ * Name
Definition: cdprocs.h:459
void DPRINT(...)
Definition: polytest.cpp:61
OB_CLOSE_METHOD CloseProcedure
Definition: obtypes.h:368
struct _ROS_SECTION_OBJECT ROS_SECTION_OBJECT
#define ASSERT(a)
Definition: mode.c:45
union _MMADDRESS_NODE::@2577 u1
POBJECT_TYPE MmSectionObjectType
Definition: section.c:130
static const WCHAR L[]
Definition: oid.c:1250
VOID NTAPI MmpDeleteSection(PVOID ObjectBody)
Definition: section.c:2642
GENERIC_MAPPING GenericMapping
Definition: obtypes.h:358
#define NULL
Definition: types.h:112
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define STATUS_SUCCESS
Definition: shellext.h:65
OB_DELETE_METHOD DeleteProcedure
Definition: obtypes.h:369
struct _MMADDRESS_NODE * Parent
Definition: mmtypes.h:659

Referenced by MmInitSystem().

◆ MmMapViewInSystemSpace()

NTSTATUS NTAPI MmMapViewInSystemSpace ( IN PVOID  SectionObject,
OUT PVOID MappedBase,
IN OUT PSIZE_T  ViewSize 
)

Definition at line 4845 of file section.c.

4848 {
4849  PROS_SECTION_OBJECT Section;
4851  NTSTATUS Status;
4852  PAGED_CODE();
4853 
4855  {
4857  &MmSession,
4858  MappedBase,
4859  ViewSize);
4860  }
4861 
4862  DPRINT("MmMapViewInSystemSpace() called\n");
4863 
4866 
4868 
4869 
4870  if ((*ViewSize) == 0)
4871  {
4872  (*ViewSize) = Section->MaximumSize.u.LowPart;
4873  }
4874  else if ((*ViewSize) > Section->MaximumSize.u.LowPart)
4875  {
4876  (*ViewSize) = Section->MaximumSize.u.LowPart;
4877  }
4878 
4879  MmLockSectionSegment(Section->Segment);
4880 
4881 
4883  Section,
4884  Section->Segment,
4885  MappedBase,
4886  *ViewSize,
4888  0,
4889  0);
4890 
4891  MmUnlockSectionSegment(Section->Segment);
4893 
4894  return Status;
4895 }
_Must_inspect_result_ _Outptr_ PVOID * SectionObject
Definition: fsrtlfuncs.h:860
LARGE_INTEGER MaximumSize
Definition: mm.h:202
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG AddressSpace
Definition: iofuncs.h:2268
FORCEINLINE VOID MmUnlockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1427
LONG NTSTATUS
Definition: precomp.h:26
static NTSTATUS MmMapViewOfSegment(PMMSUPPORT AddressSpace, PROS_SECTION_OBJECT Section, PMM_SECTION_SEGMENT Segment, PVOID *BaseAddress, SIZE_T ViewSize, ULONG Protect, ULONG ViewOffset, ULONG AllocationType)
Definition: section.c:3891
#define FALSE
Definition: types.h:117
void DPRINT(...)
Definition: polytest.cpp:61
struct _LARGE_INTEGER::@2284 u
Status
Definition: gdiplustypes.h:24
struct _ROS_SECTION_OBJECT * PROS_SECTION_OBJECT
NTSTATUS NTAPI MiMapViewInSystemSpace(IN PVOID Section, IN PMMSESSION Session, OUT PVOID *MappedBase, IN OUT PSIZE_T ViewSize)
Definition: section.c:1052
FORCEINLINE PMMSUPPORT MmGetKernelAddressSpace(VOID)
Definition: mm.h:1449
_Must_inspect_result_ _Outptr_result_bytebuffer_ ViewSize PVOID * MappedBase
Definition: mmfuncs.h:492
#define MmLockSectionSegment(x)
Definition: newmm.h:276
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T _Inout_opt_ PLARGE_INTEGER _Inout_ PSIZE_T ViewSize
Definition: mmfuncs.h:404
#define MmUnlockSectionSegment(x)
Definition: newmm.h:284
PMM_SECTION_SEGMENT Segment
Definition: mm.h:209
FORCEINLINE VOID MmLockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1420
#define PAGE_READWRITE
Definition: nt_native.h:1304
#define PAGED_CODE()
FORCEINLINE BOOLEAN MiIsRosSectionObject(IN PVOID Section)
Definition: miarm.h:1072
MMSESSION MmSession
Definition: section.c:107

Referenced by ExpInitNls(), IntGdiAddFontResourceEx(), and MmMapViewInSessionSpace().

◆ MmMapViewOfArm3Section()

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 
)

Definition at line 2855 of file section.c.

2865 {
2868  PSECTION Section;
2869  PCONTROL_AREA ControlArea;
2870  ULONG ProtectionMask;
2871  NTSTATUS Status;
2872  ULONG64 CalculatedViewSize;
2873  PAGED_CODE();
2874 
2875  /* Get the segment and control area */
2876  Section = (PSECTION)SectionObject;
2877  ControlArea = Section->Segment->ControlArea;
2878 
2879  /* These flags/states are not yet supported by ARM3 */
2880  ASSERT(Section->u.Flags.Image == 0);
2881  ASSERT(Section->u.Flags.NoCache == 0);
2882  ASSERT(Section->u.Flags.WriteCombined == 0);
2883  ASSERT(ControlArea->u.Flags.PhysicalMemory == 0);
2884 
2885  /* FIXME */
2886  if ((AllocationType & MEM_RESERVE) != 0)
2887  {
2888  DPRINT1("MmMapViewOfArm3Section called with MEM_RESERVE, this is not implemented yet!!!\n");
2889  return STATUS_NOT_IMPLEMENTED;
2890  }
2891 
2892  /* Check if the mapping protection is compatible with the create */
2894  {
2895  DPRINT1("Mapping protection is incompatible\n");
2897  }
2898 
2899  /* Check if the offset and size would cause an overflow */
2900  if (((ULONG64)SectionOffset->QuadPart + *ViewSize) <
2901  (ULONG64)SectionOffset->QuadPart)
2902  {
2903  DPRINT1("Section offset overflows\n");
2904  return STATUS_INVALID_VIEW_SIZE;
2905  }
2906 
2907  /* Check if the offset and size are bigger than the section itself */
2908  if (((ULONG64)SectionOffset->QuadPart + *ViewSize) >
2909  (ULONG64)Section->SizeOfSection.QuadPart)
2910  {
2911  DPRINT1("Section offset is larger than section\n");
2912  return STATUS_INVALID_VIEW_SIZE;
2913  }
2914 
2915  /* Check if the caller did not specify a view size */
2916  if (!(*ViewSize))
2917  {
2918  /* Compute it for the caller */
2919  CalculatedViewSize = Section->SizeOfSection.QuadPart -
2920  SectionOffset->QuadPart;
2921 
2922  /* Check if it's larger than 4GB or overflows into kernel-mode */
2923  if (!NT_SUCCESS(RtlULongLongToSIZET(CalculatedViewSize, ViewSize)) ||
2924  (((ULONG_PTR)MM_HIGHEST_VAD_ADDRESS - (ULONG_PTR)*BaseAddress) < CalculatedViewSize))
2925  {
2926  DPRINT1("Section view won't fit\n");
2927  return STATUS_INVALID_VIEW_SIZE;
2928  }
2929  }
2930 
2931  /* Check if the commit size is larger than the view size */
2932  if (CommitSize > *ViewSize)
2933  {
2934  DPRINT1("Attempting to commit more than the view itself\n");
2936  }
2937 
2938  /* Check if the view size is larger than the section */
2939  if (*ViewSize > (ULONG64)Section->SizeOfSection.QuadPart)
2940  {
2941  DPRINT1("The view is larger than the section\n");
2942  return STATUS_INVALID_VIEW_SIZE;
2943  }
2944 
2945  /* Compute and validate the protection mask */
2946  ProtectionMask = MiMakeProtectionMask(Protect);
2947  if (ProtectionMask == MM_INVALID_PROTECTION)
2948  {
2949  DPRINT1("The protection is invalid\n");
2951  }
2952 
2953  /* We only handle pagefile-backed sections, which cannot be writecombined */
2954  if (Protect & PAGE_WRITECOMBINE)
2955  {
2956  DPRINT1("Cannot write combine a pagefile-backed section\n");
2958  }
2959 
2960  /* Start by attaching to the current process if needed */
2961  if (PsGetCurrentProcess() != Process)
2962  {
2964  Attached = TRUE;
2965  }
2966 
2967  /* Do the actual mapping */
2968  Status = MiMapViewOfDataSection(ControlArea,
2969  Process,
2970  BaseAddress,
2971  SectionOffset,
2972  ViewSize,
2973  Section,
2975  ProtectionMask,
2976  CommitSize,
2977  ZeroBits,
2978  AllocationType);
2979 
2980  /* Detach if needed, then return status */
2982  return Status;
2983 }
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T _Inout_opt_ PLARGE_INTEGER _Inout_ PSIZE_T _In_ SECTION_INHERIT InheritDisposition
Definition: mmfuncs.h:404
_Must_inspect_result_ _Outptr_ PVOID * SectionObject
Definition: fsrtlfuncs.h:860
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR ZeroBits
Definition: mmfuncs.h:404
#define MM_INVALID_PROTECTION
Definition: miarm.h:63
KAPC_STATE
Definition: ketypes.h:1280
BOOLEAN NTAPI MiIsProtectionCompatible(IN ULONG SectionPageProtection, IN ULONG NewSectionPageProtection)
Definition: section.c:117
PSEGMENT Segment
Definition: mmtypes.h:822
_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
ULONG PhysicalMemory
Definition: mmtypes.h:470
#define TRUE
Definition: types.h:120
ULONG InitialPageProtection
Definition: mmtypes.h:829
LONG NTSTATUS
Definition: precomp.h:26
struct _CONTROL_AREA * ControlArea
Definition: mmtypes.h:406
uint32_t ULONG_PTR
Definition: typedefs.h:65
return STATUS_NOT_IMPLEMENTED
static BOOL Attached
Definition: vidbios.c:3905
#define FALSE
Definition: types.h:117
VOID NTAPI KeStackAttachProcess(IN PKPROCESS Process, OUT PRKAPC_STATE ApcState)
Definition: procobj.c:701
LARGE_INTEGER SizeOfSection
Definition: mmtypes.h:823
union _CONTROL_AREA::@2572 u
#define MEM_RESERVE
Definition: nt_native.h:1314
#define PsGetCurrentProcess
Definition: psfuncs.h:17
unsigned char BOOLEAN
struct _SECTION * PSECTION
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T _Inout_opt_ PLARGE_INTEGER SectionOffset
Definition: mmfuncs.h:404
#define STATUS_INVALID_PARAMETER_5
Definition: ntstatus.h:479
Status
Definition: gdiplustypes.h:24
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define ASSERT(a)
Definition: mode.c:45
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ULONG NTAPI MiMakeProtectionMask(IN ULONG Protect)
Definition: section.c:158
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T CommitSize
Definition: mmfuncs.h:404
#define STATUS_SECTION_PROTECTION
Definition: ntstatus.h:314
unsigned __int64 ULONG64
Definition: imports.h:198
MMSECTION_FLAGS Flags
Definition: mmtypes.h:827
#define STATUS_INVALID_PAGE_PROTECTION
Definition: ntstatus.h:305
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T _Inout_opt_ PLARGE_INTEGER _Inout_ PSIZE_T _In_ SECTION_INHERIT _In_ ULONG AllocationType
Definition: mmfuncs.h:404
#define PAGE_WRITECOMBINE
Definition: mmtypes.h:78
#define STATUS_INVALID_VIEW_SIZE
Definition: ntstatus.h:268
VOID NTAPI KeUnstackDetachProcess(IN PRKAPC_STATE ApcState)
Definition: procobj.c:753
#define STATUS_INVALID_PARAMETER_10
Definition: ntstatus.h:484
_Out_ PKAPC_STATE ApcState
Definition: mm.h:1488
#define DPRINT1
Definition: precomp.h:8
#define MM_HIGHEST_VAD_ADDRESS
Definition: mm.h:46
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T _Inout_opt_ PLARGE_INTEGER _Inout_ PSIZE_T ViewSize
Definition: mmfuncs.h:404
MMSECTION_FLAGS Flags
Definition: mmtypes.h:528
unsigned int ULONG
Definition: retypes.h:1
union _SECTION::@2588 u
NTSTATUS NTAPI MiMapViewOfDataSection(IN PCONTROL_AREA ControlArea, IN PEPROCESS Process, IN PVOID *BaseAddress, IN PLARGE_INTEGER SectionOffset, IN PSIZE_T ViewSize, IN PSECTION Section, IN SECTION_INHERIT InheritDisposition, IN ULONG ProtectionMask, IN SIZE_T CommitSize, IN ULONG_PTR ZeroBits, IN ULONG AllocationType)
Definition: section.c:1252
ULONG WriteCombined
Definition: mmtypes.h:490
LONGLONG QuadPart
Definition: typedefs.h:114
#define PAGED_CODE()

Referenced by MmMapViewOfSection().

◆ MmMapViewOfSection()

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 
)

Definition at line 4500 of file section.c.

4510 {
4511  PROS_SECTION_OBJECT Section;
4513