ReactOS  0.4.15-dev-1207-g698a8e6
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)
 
INIT_FUNCTION NTSTATUS NTAPI MmCreatePhysicalMemorySection (VOID)
 
INIT_FUNCTION 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 62 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 3142 of file section.c.

3143 {
3144  SIZE_T SizeOfSegments;
3145  PMM_SECTION_SEGMENT Segments;
3146 
3147  /* TODO: check for integer overflow */
3148  SizeOfSegments = sizeof(MM_SECTION_SEGMENT) * NrSegments;
3149 
3151  SizeOfSegments,
3153 
3154  if(Segments)
3155  RtlZeroMemory(Segments, SizeOfSegments);
3156 
3157  return Segments;
3158 }
#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 3587 of file section.c.

3589 {
3591  PVOID FileHeader;
3592  PVOID FileHeaderBuffer;
3593  ULONG FileHeaderSize;
3594  ULONG Flags;
3595  ULONG OldNrSegments;
3596  NTSTATUS Status;
3597  ULONG i;
3598 
3599  /*
3600  * Read the beginning of the file (2 pages). Should be enough to contain
3601  * all (or most) of the headers
3602  */
3603  Offset.QuadPart = 0;
3604 
3606  &Offset,
3607  PAGE_SIZE * 2,
3608  &FileHeader,
3609  &FileHeaderBuffer,
3610  &FileHeaderSize);
3611 
3612  if (!NT_SUCCESS(Status))
3613  return Status;
3614 
3615  if (FileHeaderSize == 0)
3616  {
3617  ExFreePool(FileHeaderBuffer);
3618  return STATUS_UNSUCCESSFUL;
3619  }
3620 
3621  /*
3622  * Look for a loader that can handle this executable
3623  */
3624  for (i = 0; i < RTL_NUMBER_OF(ExeFmtpLoaders); ++ i)
3625  {
3626  RtlZeroMemory(ImageSectionObject, sizeof(*ImageSectionObject));
3627  Flags = 0;
3628 
3629  Status = ExeFmtpLoaders[i](FileHeader,
3630  FileHeaderSize,
3631  FileObject,
3632  ImageSectionObject,
3633  &Flags,
3636 
3637  if (!NT_SUCCESS(Status))
3638  {
3639  if (ImageSectionObject->Segments)
3640  {
3641  ExFreePool(ImageSectionObject->Segments);
3642  ImageSectionObject->Segments = NULL;
3643  }
3644  }
3645 
3647  break;
3648  }
3649 
3650  ExFreePoolWithTag(FileHeaderBuffer, 'rXmM');
3651 
3652  /*
3653  * No loader handled the format
3654  */
3656  {
3659  }
3660 
3661  if (!NT_SUCCESS(Status))
3662  return Status;
3663 
3664  ASSERT(ImageSectionObject->Segments != NULL);
3665 
3666  /*
3667  * Some defaults
3668  */
3669  /* FIXME? are these values platform-dependent? */
3670  if (ImageSectionObject->ImageInformation.MaximumStackSize == 0)
3671  ImageSectionObject->ImageInformation.MaximumStackSize = 0x40000;
3672 
3673  if(ImageSectionObject->ImageInformation.CommittedStackSize == 0)
3674  ImageSectionObject->ImageInformation.CommittedStackSize = 0x1000;
3675 
3676  if(ImageSectionObject->BasedAddress == NULL)
3677  {
3678  if(ImageSectionObject->ImageInformation.ImageCharacteristics & IMAGE_FILE_DLL)
3679  ImageSectionObject->BasedAddress = (PVOID)0x10000000;
3680  else
3681  ImageSectionObject->BasedAddress = (PVOID)0x00400000;
3682  }
3683 
3684  /*
3685  * And now the fun part: fixing the segments
3686  */
3687 
3688  /* Sort them by virtual address */
3689  MmspSortSegments(ImageSectionObject, Flags);
3690 
3691  /* Ensure they don't overlap in memory */
3692  if (!MmspCheckSegmentBounds(ImageSectionObject, Flags))
3694 
3695  /* Ensure they are aligned */
3696  OldNrSegments = ImageSectionObject->NrSegments;
3697 
3698  if (!MmspPageAlignSegments(ImageSectionObject, Flags))
3700 
3701  /* Trim them if the alignment phase merged some of them */
3702  if (ImageSectionObject->NrSegments < OldNrSegments)
3703  {
3704  PMM_SECTION_SEGMENT Segments;
3705  SIZE_T SizeOfSegments;
3706 
3707  SizeOfSegments = sizeof(MM_SECTION_SEGMENT) * ImageSectionObject->NrSegments;
3708 
3709  Segments = ExAllocatePoolWithTag(PagedPool,
3710  SizeOfSegments,
3712 
3713  if (Segments == NULL)
3715 
3716  RtlCopyMemory(Segments, ImageSectionObject->Segments, SizeOfSegments);
3717  ExFreePool(ImageSectionObject->Segments);
3718  ImageSectionObject->Segments = Segments;
3719  }
3720 
3721  /* And finish their initialization */
3722  for ( i = 0; i < ImageSectionObject->NrSegments; ++ i )
3723  {
3724  ExInitializeFastMutex(&ImageSectionObject->Segments[i].Lock);
3725  ImageSectionObject->Segments[i].ReferenceCount = 1;
3726  MiInitializeSectionPageTable(&ImageSectionObject->Segments[i]);
3727  }
3728 
3730  return Status;
3731 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#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:3404
static VOID NTAPI MmspSortSegments(IN OUT PMM_IMAGE_SECTION_OBJECT ImageSectionObject, IN ULONG Flags)
Definition: section.c:3327
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
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
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
smooth NULL
Definition: ftsmooth.c:416
void * PVOID
Definition: retypes.h:9
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:588
static PMM_SECTION_SEGMENT NTAPI ExeFmtpAllocateSegments(IN ULONG NrSegments)
Definition: section.c:3142
#define STATUS_INVALID_IMAGE_NOT_MZ
Definition: ntstatus.h:539
#define STATUS_INVALID_IMAGE_FORMAT
Definition: ntstatus.h:359
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
Status
Definition: gdiplustypes.h:24
static PEXEFMT_LOADER ExeFmtpLoaders[]
Definition: section.c:3131
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:3163
#define PAGE_SIZE
Definition: env_spec_w32.h:49
VOID NTAPI MiInitializeSectionPageTable(PMM_SECTION_SEGMENT Segment)
Definition: sptab.c:165
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define TAG_MM_SECTION_SEGMENT
Definition: tag.h:139
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
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 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:3353

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

3169 {
3170  NTSTATUS Status;
3172  ULONG AdjustOffset;
3173  ULONG OffsetAdjustment;
3174  ULONG BufferSize;
3175  ULONG UsedSize;
3176  PVOID Buffer;
3179 
3181 
3182  if(Length == 0)
3183  {
3184  KeBugCheck(MEMORY_MANAGEMENT);
3185  }
3186 
3187  FileOffset = *Offset;
3188 
3189  /* Negative/special offset: it cannot be used in this context */
3190  if(FileOffset.u.HighPart < 0)
3191  {
3192  KeBugCheck(MEMORY_MANAGEMENT);
3193  }
3194 
3195  AdjustOffset = PAGE_ROUND_DOWN(FileOffset.u.LowPart);
3196  OffsetAdjustment = FileOffset.u.LowPart - AdjustOffset;
3197  FileOffset.u.LowPart = AdjustOffset;
3198 
3199  BufferSize = Length + OffsetAdjustment;
3201 
3202  /* Flush data since we're about to perform a non-cached read */
3203  CcFlushCache(FileObject->SectionObjectPointer,
3204  &FileOffset,
3205  BufferSize,
3206  &Iosb);
3207 
3208  /*
3209  * It's ok to use paged pool, because this is a temporary buffer only used in
3210  * the loading of executables. The assumption is that MmCreateSection is
3211  * always called at low IRQLs and that these buffers don't survive a brief
3212  * initialization phase
3213  */
3215  BufferSize,
3216  'rXmM');
3217  if (!Buffer)
3218  {
3220  }
3221 
3222  UsedSize = 0;
3223 
3225 
3226  UsedSize = (ULONG)Iosb.Information;
3227 
3228  if(NT_SUCCESS(Status) && UsedSize < OffsetAdjustment)
3229  {
3232  }
3233 
3234  if(NT_SUCCESS(Status))
3235  {
3236  *Data = (PVOID)((ULONG_PTR)Buffer + OffsetAdjustment);
3237  *AllocBase = Buffer;
3238  *ReadSize = UsedSize - OffsetAdjustment;
3239  }
3240  else
3241  {
3242  ExFreePoolWithTag(Buffer, 'rXmM');
3243  }
3244 
3245  return Status;
3246 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
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
#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
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
DECLSPEC_NORETURN VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1431
_In_opt_ PVOID _In_ PCSTR File
Definition: iofuncs.h:615
Definition: bufpool.h:45
void * PVOID
Definition: retypes.h:9
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:588
return Iosb
Definition: create.c:4402
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define BufferSize
Definition: mmc.h:75
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
* PFILE_OBJECT
Definition: iotypes.h:1978
#define ASSERT_IRQL_LESS(x)
Definition: debug.h:253
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
Status
Definition: gdiplustypes.h:24
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
_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
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
NTSTATUS NTAPI MiSimpleRead(PFILE_OBJECT FileObject, PLARGE_INTEGER FileOffset, PVOID Buffer, ULONG Length, BOOLEAN Paging, PIO_STATUS_BLOCK ReadStatus)
Definition: io.c:114

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

1051 {
1053  KIRQL Irql;
1054  PVOID DestAddress;
1055 
1057  DestAddress = MiMapPageInHyperSpace(Process, DestPage, &Irql);
1058  if (DestAddress == NULL)
1059  {
1060  return(STATUS_NO_MEMORY);
1061  }
1062  ASSERT((ULONG_PTR)DestAddress % PAGE_SIZE == 0);
1063  ASSERT((ULONG_PTR)SrcAddress % PAGE_SIZE == 0);
1064  RtlCopyMemory(DestAddress, SrcAddress, PAGE_SIZE);
1065  MiUnmapPageInHyperSpace(Process, DestAddress, Irql);
1066  return(STATUS_SUCCESS);
1067 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
_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
smooth NULL
Definition: ftsmooth.c:416
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
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
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
return STATUS_SUCCESS
Definition: btrfs.c:3014

Referenced by MmAccessFaultSectionView().

◆ MiIsPageFromCache()

BOOLEAN MiIsPageFromCache ( PMEMORY_AREA  MemoryArea,
LONGLONG  SegOffset 
)

Definition at line 1028 of file section.c.

1030 {
1031 #ifndef NEWCC
1032  if (!(MemoryArea->Data.SectionData.Segment->Image.Characteristics & IMAGE_SCN_MEM_SHARED))
1033  {
1034  PROS_SHARED_CACHE_MAP SharedCacheMap;
1035  PROS_VACB Vacb;
1036  SharedCacheMap = MemoryArea->Data.SectionData.Section->FileObject->SectionObjectPointer->SharedCacheMap;
1037  Vacb = CcRosLookupVacb(SharedCacheMap, SegOffset + MemoryArea->Data.SectionData.Segment->Image.FileOffset);
1038  if (Vacb)
1039  {
1040  CcRosReleaseVacb(SharedCacheMap, Vacb, Vacb->Valid, FALSE, TRUE);
1041  return TRUE;
1042  }
1043  }
1044 #endif
1045  return FALSE;
1046 }
Definition: cc.h:201
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
union _MEMORY_AREA::@1771 Data
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
struct _MEMORY_AREA::@1771::@1772 SectionData

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

1082 {
1083  LONGLONG BaseOffset;
1086  BOOLEAN UptoDate;
1087  PROS_VACB Vacb;
1089  NTSTATUS Status;
1090  LONGLONG RawLength;
1091  PROS_SHARED_CACHE_MAP SharedCacheMap;
1092  BOOLEAN IsImageSection;
1093  LONGLONG Length;
1094 
1095  FileObject = MemoryArea->Data.SectionData.Section->FileObject;
1096  SharedCacheMap = FileObject->SectionObjectPointer->SharedCacheMap;
1097  RawLength = MemoryArea->Data.SectionData.Segment->RawLength.QuadPart;
1098  FileOffset = SegOffset + MemoryArea->Data.SectionData.Segment->Image.FileOffset;
1099  IsImageSection = MemoryArea->Data.SectionData.Section->AllocationAttributes & SEC_IMAGE ? TRUE : FALSE;
1100 
1101  ASSERT(SharedCacheMap);
1102 
1103  DPRINT("%S %I64x\n", FileObject->FileName.Buffer, FileOffset);
1104 
1105  /*
1106  * If the file system is letting us go directly to the cache and the
1107  * memory area was mapped at an offset in the file which is page aligned
1108  * then get the related VACB.
1109  */
1110  if (((FileOffset % PAGE_SIZE) == 0) &&
1111  ((SegOffset + PAGE_SIZE <= RawLength) || !IsImageSection) &&
1112  !(MemoryArea->Data.SectionData.Segment->Image.Characteristics & IMAGE_SCN_MEM_SHARED))
1113  {
1114 
1115  /*
1116  * Get the related VACB; we use a lower level interface than
1117  * filesystems do because it is safe for us to use an offset with an
1118  * alignment less than the file system block size.
1119  */
1120  Status = CcRosGetVacb(SharedCacheMap,
1121  FileOffset,
1122  &BaseOffset,
1123  &BaseAddress,
1124  &UptoDate,
1125  &Vacb);
1126  if (!NT_SUCCESS(Status))
1127  {
1128  return(Status);
1129  }
1130  if (!UptoDate)
1131  {
1132  /*
1133  * If the VACB isn't up to date then call the file
1134  * system to read in the data.
1135  */
1136  Status = CcReadVirtualAddress(Vacb);
1137  if (!NT_SUCCESS(Status))
1138  {
1139  CcRosReleaseVacb(SharedCacheMap, Vacb, FALSE, FALSE, FALSE);
1140  return Status;
1141  }
1142  }
1143 
1144  /* Probe the page, since it's PDE might not be synced */
1145  (void)*((volatile char*)BaseAddress + FileOffset - BaseOffset);
1146 
1147  /*
1148  * Retrieve the page from the view that we actually want.
1149  */
1150  (*Page) = MmGetPhysicalAddress((char*)BaseAddress +
1151  FileOffset - BaseOffset).LowPart >> PAGE_SHIFT;
1152 
1153  CcRosReleaseVacb(SharedCacheMap, Vacb, TRUE, FALSE, TRUE);
1154  }
1155  else
1156  {
1158  KIRQL Irql;
1159  PVOID PageAddr;
1160  LONGLONG VacbOffset;
1161 
1162  /*
1163  * Allocate a page, this is rather complicated by the possibility
1164  * we might have to move other things out of memory
1165  */
1167  MI_SET_PROCESS2(PsGetCurrentProcess()->ImageFileName);
1169  if (!NT_SUCCESS(Status))
1170  {
1171  return(Status);
1172  }
1173  Status = CcRosGetVacb(SharedCacheMap,
1174  FileOffset,
1175  &BaseOffset,
1176  &BaseAddress,
1177  &UptoDate,
1178  &Vacb);
1179  if (!NT_SUCCESS(Status))
1180  {
1181  return(Status);
1182  }
1183  if (!UptoDate)
1184  {
1185  /*
1186  * If the VACB isn't up to date then call the file
1187  * system to read in the data.
1188  */
1189  Status = CcReadVirtualAddress(Vacb);
1190  if (!NT_SUCCESS(Status))
1191  {
1192  CcRosReleaseVacb(SharedCacheMap, Vacb, FALSE, FALSE, FALSE);
1193  return Status;
1194  }
1195  }
1196 
1198  PageAddr = MiMapPageInHyperSpace(Process, *Page, &Irql);
1199  VacbOffset = BaseOffset + VACB_MAPPING_GRANULARITY - FileOffset;
1200  Length = RawLength - SegOffset;
1201  if (Length <= VacbOffset && Length <= PAGE_SIZE)
1202  {
1203  memcpy(PageAddr, (char*)BaseAddress + FileOffset - BaseOffset, Length);
1204  }
1205  else if (VacbOffset >= PAGE_SIZE)
1206  {
1207  memcpy(PageAddr, (char*)BaseAddress + FileOffset - BaseOffset, PAGE_SIZE);
1208  }
1209  else
1210  {
1211  memcpy(PageAddr, (char*)BaseAddress + FileOffset - BaseOffset, VacbOffset);
1212  MiUnmapPageInHyperSpace(Process, PageAddr, Irql);
1213  CcRosReleaseVacb(SharedCacheMap, Vacb, TRUE, FALSE, FALSE);
1214  Status = CcRosGetVacb(SharedCacheMap,
1215  FileOffset + VacbOffset,
1216  &BaseOffset,
1217  &BaseAddress,
1218  &UptoDate,
1219  &Vacb);
1220  if (!NT_SUCCESS(Status))
1221  {
1222  return(Status);
1223  }
1224  if (!UptoDate)
1225  {
1226  /*
1227  * If the VACB isn't up to date then call the file
1228  * system to read in the data.
1229  */
1230  Status = CcReadVirtualAddress(Vacb);
1231  if (!NT_SUCCESS(Status))
1232  {
1233  CcRosReleaseVacb(SharedCacheMap, Vacb, FALSE, FALSE, FALSE);
1234  return Status;
1235  }
1236  }
1237  PageAddr = MiMapPageInHyperSpace(Process, *Page, &Irql);
1238  if (Length < PAGE_SIZE)
1239  {
1240  memcpy((char*)PageAddr + VacbOffset, BaseAddress, Length - VacbOffset);
1241  }
1242  else
1243  {
1244  memcpy((char*)PageAddr + VacbOffset, BaseAddress, PAGE_SIZE - VacbOffset);
1245  }
1246  }
1247  MiUnmapPageInHyperSpace(Process, PageAddr, Irql);
1248  CcRosReleaseVacb(SharedCacheMap, Vacb, TRUE, FALSE, FALSE);
1249  }
1250  return(STATUS_SUCCESS);
1251 }
#define PAGE_SHIFT
Definition: env_spec_w32.h:45
Definition: cc.h:201
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:229
_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
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define FALSE
Definition: types.h:117
#define MI_SET_PROCESS2(x)
Definition: mm.h:254
#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
union _MEMORY_AREA::@1771 Data
void DPRINT(...)
Definition: polytest.cpp:61
#define MI_SET_USAGE(x)
Definition: mm.h:253
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:588
int64_t LONGLONG
Definition: typedefs.h:68
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#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
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
* PFILE_OBJECT
Definition: iotypes.h:1978
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
VOID NTAPI MiUnmapPageInHyperSpace(IN PEPROCESS Process, IN PVOID Address, IN KIRQL OldIrql)
Definition: hypermap.c:93
Status
Definition: gdiplustypes.h:24
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:685
struct _MEMORY_AREA::@1771::@1772 SectionData
return STATUS_SUCCESS
Definition: btrfs.c:3014
NTSTATUS NTAPI CcReadVirtualAddress(PROS_VACB Vacb)
Definition: copy.c:81

Referenced by MmNotPresentFaultSectionView().

◆ MiRosUnmapViewInSystemSpace()

NTSTATUS NTAPI MiRosUnmapViewInSystemSpace ( IN PVOID  MappedBase)

Definition at line 4905 of file section.c.

4906 {
4908  NTSTATUS Status;
4909 
4910  DPRINT("MmUnmapViewInSystemSpace() called\n");
4911 
4913 
4915 
4917 
4919 
4920  return Status;
4921 }
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG AddressSpace
Definition: iofuncs.h:2268
FORCEINLINE VOID MmUnlockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1431
LONG NTSTATUS
Definition: precomp.h:26
static NTSTATUS MmUnmapViewOfSegment(PMMSUPPORT AddressSpace, PVOID BaseAddress)
Definition: section.c:4076
void DPRINT(...)
Definition: polytest.cpp:61
Status
Definition: gdiplustypes.h:24
FORCEINLINE PMMSUPPORT MmGetKernelAddressSpace(VOID)
Definition: mm.h:1453
_Must_inspect_result_ _Outptr_result_bytebuffer_ ViewSize PVOID * MappedBase
Definition: mmfuncs.h:492
FORCEINLINE VOID MmLockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1424

Referenced by MmUnmapViewInSystemSpace().

◆ MiRosUnmapViewOfSection()

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

Definition at line 4141 of file section.c.

4144 {
4145  NTSTATUS Status;
4148  PROS_SECTION_OBJECT Section;
4149  PVOID ImageBaseAddress = 0;
4150 
4151  DPRINT("Opening memory area Process %p BaseAddress %p\n",
4152  Process, BaseAddress);
4153 
4154  ASSERT(Process);
4155 
4157 
4160  BaseAddress);
4161  if (MemoryArea == NULL ||
4165  {
4168  return STATUS_NOT_MAPPED_VIEW;
4169  }
4170 
4171  Section = MemoryArea->Data.SectionData.Section;
4172 
4173  if ((Section != NULL) && (Section->AllocationAttributes & SEC_IMAGE))
4174  {
4175  ULONG i;
4176  ULONG NrSegments;
4177  PMM_IMAGE_SECTION_OBJECT ImageSectionObject;
4178  PMM_SECTION_SEGMENT SectionSegments;
4180 
4181  Segment = MemoryArea->Data.SectionData.Segment;
4182  ImageSectionObject = Section->ImageSection;
4183  SectionSegments = ImageSectionObject->Segments;
4184  NrSegments = ImageSectionObject->NrSegments;
4185 
4187 
4188  /* Search for the current segment within the section segments
4189  * and calculate the image base address */
4190  for (i = 0; i < NrSegments; i++)
4191  {
4192  if (Segment == &SectionSegments[i])
4193  {
4194  ImageBaseAddress = (char*)BaseAddress - (ULONG_PTR)SectionSegments[i].Image.VirtualAddress;
4195  break;
4196  }
4197  }
4198  if (i >= NrSegments)
4199  {
4200  KeBugCheck(MEMORY_MANAGEMENT);
4201  }
4202 
4203  for (i = 0; i < NrSegments; i++)
4204  {
4205  PVOID SBaseAddress = (PVOID)
4206  ((char*)ImageBaseAddress + (ULONG_PTR)SectionSegments[i].Image.VirtualAddress);
4207 
4208  Status = MmUnmapViewOfSegment(AddressSpace, SBaseAddress);
4209  if (!NT_SUCCESS(Status))
4210  {
4211  DPRINT1("MmUnmapViewOfSegment failed for %p (Process %p) with %lx\n",
4212  SBaseAddress, Process, Status);
4214  }
4215  }
4216  }
4217  else
4218  {
4220  if (!NT_SUCCESS(Status))
4221  {
4222  DPRINT1("MmUnmapViewOfSegment failed for %p (Process %p) with %lx\n",
4225  }
4226  }
4227 
4229 
4230  /* Notify debugger */
4231  if (ImageBaseAddress && !SkipDebuggerNotify) DbgkUnMapViewOfSection(ImageBaseAddress);
4232 
4233  return(STATUS_SUCCESS);
4234 }
ULONG Type
Definition: mm.h:214
#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:1431
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:4076
PMM_IMAGE_SECTION_OBJECT ImageSection
Definition: mm.h:202
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 MEMORY_AREA_OWNED_BY_ARM3
Definition: mm.h:73
DECLSPEC_NORETURN VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1431
smooth NULL
Definition: ftsmooth.c:416
union _MEMORY_AREA::@1771 Data
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
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
PMM_SECTION_SEGMENT Segments
Definition: mm.h:189
BOOLEAN DeleteInProgress
Definition: mm.h:217
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
struct _MM_SECTION_SEGMENT::@1768 Image
VOID NTAPI DbgkUnMapViewOfSection(IN PVOID BaseAddress)
Definition: dbgkutil.c:436
Status
Definition: gdiplustypes.h:24
FORCEINLINE PMMSUPPORT MmGetKernelAddressSpace(VOID)
Definition: mm.h:1453
#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:198
struct _MEMORY_AREA::@1771::@1772 SectionData
return STATUS_SUCCESS
Definition: btrfs.c:3014
struct _MEMORY_AREA * MemoryArea
Definition: newmm.h:65
FORCEINLINE VOID MmLockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1424

Referenced by MiRosCleanupMemoryArea(), and MiUnmapViewOfSection().

◆ MmAccessFaultSectionView()

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

Definition at line 1801 of file section.c.

1804 {
1806  PROS_SECTION_OBJECT Section;
1807  PFN_NUMBER OldPage;
1808  PFN_NUMBER NewPage;
1809  NTSTATUS Status;
1810  PVOID PAddress;
1813  ULONG_PTR Entry;
1815 
1816  DPRINT("MmAccessFaultSectionView(%p, %p, %p)\n", AddressSpace, MemoryArea, Address);
1817 
1818  /* Make sure we have a page mapping for this address. */
1820  if (!NT_SUCCESS(Status))
1821  {
1822  /* This is invalid access ! */
1823  return Status;
1824  }
1825 
1826  /*
1827  * Check if the page has already been set readwrite
1828  */
1830  {
1831  DPRINT("Address 0x%p\n", Address);
1832  return(STATUS_SUCCESS);
1833  }
1834 
1835  /*
1836  * Find the offset of the page
1837  */
1838  PAddress = MM_ROUND_DOWN(Address, PAGE_SIZE);
1839  Offset.QuadPart = (ULONG_PTR)PAddress - MA_GetStartingAddress(MemoryArea)
1840  + MemoryArea->Data.SectionData.ViewOffset.QuadPart;
1841 
1842  Segment = MemoryArea->Data.SectionData.Segment;
1843  Section = MemoryArea->Data.SectionData.Section;
1845  &MemoryArea->Data.SectionData.RegionListHead,
1846  Address, NULL);
1847  ASSERT(Region != NULL);
1848 
1849  /*
1850  * Check if we are doing COW
1851  */
1852  if (!((Segment->WriteCopy) &&
1853  (Region->Protect == PAGE_READWRITE ||
1854  Region->Protect == PAGE_EXECUTE_READWRITE)))
1855  {
1856  DPRINT("Address 0x%p\n", Address);
1857  return(STATUS_ACCESS_VIOLATION);
1858  }
1859 
1860  /* Get the page mapping this section offset. */
1863 
1864  /* Get the current page mapping for the process */
1865  ASSERT(MmIsPagePresent(Process, PAddress));
1866  OldPage = MmGetPfnForProcess(Process, PAddress);
1867  ASSERT(OldPage != 0);
1868 
1869  if (IS_SWAP_FROM_SSE(Entry) ||
1870  PFN_FROM_SSE(Entry) != OldPage)
1871  {
1873  /* This is a private page. We must only change the page protection. */
1874  MmSetPageProtect(Process, PAddress, Region->Protect);
1875  return(STATUS_SUCCESS);
1876  }
1877 
1878  /*
1879  * Allocate a page
1880  */
1882  if (Process) MI_SET_PROCESS2(Process->ImageFileName);
1883  if (!Process) MI_SET_PROCESS2("Kernel Section");
1885  if (!NT_SUCCESS(Status))
1886  {
1887  KeBugCheck(MEMORY_MANAGEMENT);
1888  }
1889 
1890  /*
1891  * Copy the old page
1892  */
1893  NT_VERIFY(NT_SUCCESS(MiCopyFromUserPage(NewPage, PAddress)));
1894 
1895  /*
1896  * Unshare the old page.
1897  */
1898  DPRINT("Swapping page (Old %x New %x)\n", OldPage, NewPage);
1899  MmDeleteVirtualMapping(Process, PAddress, NULL, NULL);
1900  MmDeleteRmap(OldPage, Process, PAddress);
1903 
1904  /*
1905  * Set the PTE to point to the new page
1906  */
1908  PAddress,
1909  Region->Protect,
1910  &NewPage,
1911  1);
1912  if (!NT_SUCCESS(Status))
1913  {
1914  DPRINT1("MmCreateVirtualMapping failed, unable to create virtual mapping, not out of memory\n");
1915  KeBugCheck(MEMORY_MANAGEMENT);
1916  return(Status);
1917  }
1918  MmInsertRmap(NewPage, Process, PAddress);
1919 
1921  DPRINT("Address 0x%p\n", Address);
1922  return(STATUS_SUCCESS);
1923 }
PMM_REGION NTAPI MmFindRegion(PVOID BaseAddress, PLIST_ENTRY RegionListHead, PVOID Address, PVOID *RegionBaseAddress)
Definition: region.c:257
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:390
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI MmRequestPageMemoryConsumer(ULONG Consumer, BOOLEAN MyWait, PPFN_NUMBER AllocatedPage)
Definition: balance.c:229
#define NT_VERIFY(exp)
Definition: rtlfuncs.h:3289
uint32_t ULONG_PTR
Definition: typedefs.h:65
BOOLEAN NTAPI MmIsPagePresent(struct _EPROCESS *Process, PVOID Address)
ULONG PFN_NUMBER
Definition: ke.h:8
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define FALSE
Definition: types.h:117
DECLSPEC_NORETURN VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1431
NTSTATUS NTAPI MmNotPresentFaultSectionView(PMMSUPPORT AddressSpace, MEMORY_AREA *MemoryArea, PVOID Address, BOOLEAN Locked)
Definition: section.c:1368
#define MI_SET_PROCESS2(x)
Definition: mm.h:254
BOOLEAN NTAPI MmUnsharePageEntrySectionSegment(PROS_SECTION_OBJECT Section, PMM_SECTION_SEGMENT Segment, PLARGE_INTEGER Offset, BOOLEAN Dirty, BOOLEAN PageOut, ULONG_PTR *InEntry)
Definition: section.c:883
smooth NULL
Definition: ftsmooth.c:416
static WCHAR Address[46]
Definition: ping.c:68
VOID NTAPI MmDeleteVirtualMapping(struct _EPROCESS *Process, PVOID Address, BOOLEAN *WasDirty, PPFN_NUMBER Page)
union _MEMORY_AREA::@1771 Data
void DPRINT(...)
Definition: polytest.cpp:61
#define MI_SET_USAGE(x)
Definition: mm.h:253
_Inout_ PVOID Segment
Definition: exfuncs.h:1101
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
VOID NTAPI MmSetPageProtect(struct _EPROCESS *Process, PVOID Address, ULONG flProtect)
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24
#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:207
#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:1438
#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
struct _MEMORY_AREA::@1771::@1772 SectionData
#define MmUnlockSectionSegment(x)
Definition: newmm.h:284
return STATUS_SUCCESS
Definition: btrfs.c:3014
NTSTATUS NTAPI MiCopyFromUserPage(PFN_NUMBER DestPage, const VOID *SrcAddress)
Definition: section.c:1050
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 1286 of file section.c.

1293 {
1296  BOOLEAN DoCOW = FALSE;
1297  ULONG i;
1299 
1301  ASSERT(MemoryArea != NULL);
1302  Segment = MemoryArea->Data.SectionData.Segment;
1304 
1305  if ((Segment->WriteCopy) &&
1307  {
1308  DoCOW = TRUE;
1309  }
1310 
1311  if (OldProtect != NewProtect)
1312  {
1313  for (i = 0; i < PAGE_ROUND_UP(RegionSize) / PAGE_SIZE; i++)
1314  {
1315  SWAPENTRY SwapEntry;
1316  PVOID Address = (char*)BaseAddress + (i * PAGE_SIZE);
1318 
1319  /* Wait for a wait entry to disappear */
1320  do
1321  {
1322  MmGetPageFileMapping(Process, Address, &SwapEntry);
1323  if (SwapEntry != MM_WAIT_ENTRY)
1324  break;
1326  }
1327  while (TRUE);
1328 
1329  /*
1330  * If we doing COW for this segment then check if the page is
1331  * already private.
1332  */
1333  if (DoCOW && MmIsPagePresent(Process, Address))
1334  {
1336  ULONG_PTR Entry;
1337  PFN_NUMBER Page;
1338 
1340  + MemoryArea->Data.SectionData.ViewOffset.QuadPart;
1342  /*
1343  * An MM_WAIT_ENTRY is ok in this case... It'll just count as
1344  * IS_SWAP_FROM_SSE and we'll do the right thing.
1345  */
1347 
1349  if (IS_SWAP_FROM_SSE(Entry) || PFN_FROM_SSE(Entry) != Page)
1350  {
1351  Protect = NewProtect;
1352  }
1353  }
1354 
1356  {
1358  Protect);
1359  }
1360  }
1361  }
1362 
1364 }
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 MM_WAIT_ENTRY
Definition: mm.h:152
#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
BOOLEAN NTAPI MmIsPagePresent(struct _EPROCESS *Process, PVOID Address)
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
ULONG PFN_NUMBER
Definition: ke.h:8
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define FALSE
Definition: types.h:117
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
static WCHAR Address[46]
Definition: ping.c:68
union _MEMORY_AREA::@1771 Data
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
BOOLEAN NTAPI MmIsDisabledPage(struct _EPROCESS *Process, PVOID Address)
VOID NTAPI MmSetPageProtect(struct _EPROCESS *Process, PVOID Address, ULONG flProtect)
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define IS_SWAP_FROM_SSE(E)
Definition: newmm.h:8
#define MA_GetStartingAddress(_MemoryArea)
Definition: mm.h:207
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:1438
_Must_inspect_result_ _In_ ULONG NewProtect
Definition: mmfuncs.h:682
#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
struct _MEMORY_AREA::@1771::@1772 SectionData
#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 4728 of file section.c.

4730 {
4731  /* Check whether an ImageSectionObject exists */
4732  if (SectionObjectPointer->ImageSectionObject != NULL)
4733  {
4734  DPRINT1("ERROR: File can't be truncated because it has an image section\n");
4735  return FALSE;
4736  }
4737 
4738  if (SectionObjectPointer->DataSectionObject != NULL)
4739  {
4741 
4743  DataSectionObject;
4744 
4745  if (Segment->ReferenceCount != 0)
4746  {
4747 #ifdef NEWCC
4749  CcpLock();
4750  if (SectionObjectPointer->SharedCacheMap && (Segment->ReferenceCount > CcpCountCacheSections((PNOCC_CACHE_MAP)SectionObjectPointer->SharedCacheMap)))
4751  {
4752  CcpUnlock();
4753  /* Check size of file */
4754  if (SectionObjectPointer->SharedCacheMap)
4755  {
4756  if (!CcGetFileSizes(Segment->FileObject, &FileSizes))
4757  {
4758  return FALSE;
4759  }
4760 
4762  {
4763  return FALSE;
4764  }
4765  }
4766  }
4767  else
4768  CcpUnlock();
4769 #else
4770  /* Check size of file */
4771  if (SectionObjectPointer->SharedCacheMap)
4772  {
4773  PROS_SHARED_CACHE_MAP SharedCacheMap = SectionObjectPointer->SharedCacheMap;
4774  if (NewFileSize->QuadPart <= SharedCacheMap->FileSize.QuadPart)
4775  {
4776  return FALSE;
4777  }
4778  }
4779 #endif
4780  }
4781  else
4782  {
4783  /* Something must gone wrong
4784  * how can we have a Section but no
4785  * reference? */
4786  DPRINT("ERROR: DataSectionObject without reference!\n");
4787  }
4788  }
4789 
4790  DPRINT("FIXME: didn't check for outstanding write probes\n");
4791 
4792  return TRUE;
4793 }
#define CcpLock()
Definition: newcc.h:143
#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
smooth NULL
Definition: ftsmooth.c:416
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 DPRINT1
Definition: precomp.h:8
LARGE_INTEGER FileSize
Definition: cc.h:175
#define CcpUnlock()
Definition: newcc.h:144
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 2412 of file section.c.

2420 {
2421  SECTION Section;
2422  PSECTION NewSection;
2423  PSUBSECTION Subsection;
2424  PSEGMENT NewSegment, Segment;
2425  NTSTATUS Status;
2426  PCONTROL_AREA ControlArea;
2427  ULONG ProtectionMask, ControlAreaSize, Size, NonPagedCharge, PagedCharge;
2429  BOOLEAN FileLock = FALSE, KernelCall = FALSE;
2430  KIRQL OldIrql;
2432  BOOLEAN UserRefIncremented = FALSE;
2433  PVOID PreviousSectionPointer;
2434 
2435  /* Make the same sanity checks that the Nt interface should've validated */
2438  SEC_NO_CHANGE)) == 0);
2442  SEC_NOCACHE | SEC_NO_CHANGE))));
2448 
2449  /* Convert section flag to page flag */
2451 
2452  /* Check to make sure the protection is correct. Nt* does this already */
2453  ProtectionMask = MiMakeProtectionMask(SectionPageProtection);
2454  if (ProtectionMask == MM_INVALID_PROTECTION) return STATUS_INVALID_PAGE_PROTECTION;
2455 
2456  /* Check if this is going to be a data or image backed file section */
2457  if ((FileHandle) || (FileObject))
2458  {
2459  /* These cannot be mapped with large pages */
2461 
2462  /* For now, only support the mechanism through a file handle */
2463  ASSERT(FileObject == NULL);
2464 
2465  /* Reference the file handle to get the object */
2467  MmMakeFileAccess[ProtectionMask],
2469  PreviousMode,
2470  (PVOID*)&File,
2471  NULL);
2472  if (!NT_SUCCESS(Status)) return Status;
2473 
2474  /* Make sure Cc has been doing its job */
2475  if (!File->SectionObjectPointer)
2476  {
2477  /* This is not a valid file system-based file, fail */
2480  }
2481 
2482  /* Image-file backed sections are not yet supported */
2484 
2485  /* Compute the size of the control area, and allocate it */
2486  ControlAreaSize = sizeof(CONTROL_AREA) + sizeof(MSUBSECTION);
2487  ControlArea = ExAllocatePoolWithTag(NonPagedPool, ControlAreaSize, 'aCmM');
2488  if (!ControlArea)
2489  {
2492  }
2493 
2494  /* Zero it out */
2495  RtlZeroMemory(ControlArea, ControlAreaSize);
2496 
2497  /* Did we get a handle, or an object? */
2498  if (FileHandle)
2499  {
2500  /* We got a file handle so we have to lock down the file */
2501 #if 0
2502  Status = FsRtlAcquireToCreateMappedSection(File, SectionPageProtection);
2503  if (!NT_SUCCESS(Status))
2504  {
2505  ExFreePool(ControlArea);
2507  return Status;
2508  }
2509 #else
2510  /* ReactOS doesn't support this API yet, so do nothing */
2512 #endif
2513  /* Update the top-level IRP so that drivers know what's happening */
2515  FileLock = TRUE;
2516  }
2517 
2518  /* Lock the PFN database while we play with the section pointers */
2520 
2521  /* Image-file backed sections are not yet supported */
2523 
2524  /* There should not already be a control area for this file */
2525  ASSERT(File->SectionObjectPointer->DataSectionObject == NULL);
2526  NewSegment = NULL;
2527 
2528  /* Write down that this CA is being created, and set it */
2529  ControlArea->u.Flags.BeingCreated = TRUE;
2531  PreviousSectionPointer = File->SectionObjectPointer;
2532  File->SectionObjectPointer->DataSectionObject = ControlArea;
2533 
2534  /* We can release the PFN lock now */
2536 
2537  /* We don't support previously-mapped file */
2538  ASSERT(NewSegment == NULL);
2539 
2540  /* Image-file backed sections are not yet supported */
2542 
2543  /* So we always create a data file map */
2545  &Segment,
2546  (PSIZE_T)InputMaximumSize,
2549  KernelCall);
2550  if (!NT_SUCCESS(Status))
2551  {
2552  /* Lock the PFN database while we play with the section pointers */
2554 
2555  /* Reset the waiting-for-deletion event */
2556  ASSERT(ControlArea->WaitingForDeletion == NULL);
2557  ControlArea->WaitingForDeletion = NULL;
2558 
2559  /* Set the file pointer NULL flag */
2560  ASSERT(ControlArea->u.Flags.FilePointerNull == 0);
2561  ControlArea->u.Flags.FilePointerNull = TRUE;
2562 
2563  /* Delete the data section object */
2565  File->SectionObjectPointer->DataSectionObject = NULL;
2566 
2567  /* No longer being created */
2568  ControlArea->u.Flags.BeingCreated = FALSE;
2569 
2570  /* We can release the PFN lock now */
2572 
2573  /* Check if we locked and set the IRP */
2574  if (FileLock)
2575  {
2576  /* Undo */
2578  //FsRtlReleaseFile(File);
2579  }
2580 
2581  /* Free the control area and de-ref the file object */
2582  ExFreePool(ControlArea);
2584 
2585  /* All done */
2586  return Status;
2587  }
2588 
2589  /* On success, we expect this */
2590  ASSERT(PreviousSectionPointer == File->SectionObjectPointer);
2591 
2592  /* Check if a maximum size was specified */
2593  if (!InputMaximumSize->QuadPart)
2594  {
2595  /* Nope, use the segment size */
2596  Section.SizeOfSection.QuadPart = (LONGLONG)Segment->SizeOfSegment;
2597  }
2598  else
2599  {
2600  /* Yep, use the entered size */
2601  Section.SizeOfSection.QuadPart = InputMaximumSize->QuadPart;
2602  }
2603  }
2604  else
2605  {
2606  /* A handle must be supplied with SEC_IMAGE, as this is the no-handle path */
2608 
2609  /* Not yet supported */
2611 
2612  /* So this must be a pagefile-backed section, create the mappings needed */
2613  Status = MiCreatePagingFileMap(&NewSegment,
2614  (PSIZE_T)InputMaximumSize,
2615  ProtectionMask,
2617  if (!NT_SUCCESS(Status)) return Status;
2618 
2619  /* Set the size here, and read the control area */
2620  Section.SizeOfSection.QuadPart = NewSegment->SizeOfSegment;
2621  ControlArea = NewSegment->ControlArea;
2622 
2623  /* MiCreatePagingFileMap increments user references */
2624  UserRefIncremented = TRUE;
2625  }
2626 
2627  /* Did we already have a segment? */
2628  if (!NewSegment)
2629  {
2630  /* This must be the file path and we created a segment */
2631  NewSegment = Segment;
2632  ASSERT(File != NULL);
2633 
2634  /* Acquire the PFN lock while we set control area flags */
2636 
2637  /* We don't support this race condition yet, so assume no waiters */
2638  ASSERT(ControlArea->WaitingForDeletion == NULL);
2639  ControlArea->WaitingForDeletion = NULL;
2640 
2641  /* Image-file backed sections are not yet supported, nor ROM images */
2643  ASSERT(Segment->ControlArea->u.Flags.Rom == 0);
2644 
2645  /* Take off the being created flag, and then release the lock */
2646  ControlArea->u.Flags.BeingCreated = FALSE;
2648  }
2649 
2650  /* Check if we locked the file earlier */
2651  if (FileLock)
2652  {
2653  /* Reset the top-level IRP and release the lock */
2655  //FsRtlReleaseFile(File);
2656  FileLock = FALSE;
2657  }
2658 
2659  /* Set the initial section object data */
2660  Section.InitialPageProtection = SectionPageProtection;
2661 
2662  /* The mapping created a control area and segment, save the flags */
2663  Section.Segment = NewSegment;
2664  Section.u.LongFlags = ControlArea->u.LongFlags;
2665 
2666  /* Check if this is a user-mode read-write non-image file mapping */
2667  if (!(FileObject) &&
2669  !(ControlArea->u.Flags.Image) &&
2670  (ControlArea->FilePointer))
2671  {
2672  /* Add a reference and set the flag */
2673  Section.u.Flags.UserWritable = TRUE;
2674  InterlockedIncrement((volatile LONG*)&ControlArea->WritableUserReferences);
2675  }
2676 
2677  /* Check for image mappings or page file mappings */
2678  if ((ControlArea->u.Flags.Image) || !(ControlArea->FilePointer))
2679  {
2680  /* Charge the segment size, and allocate a subsection */
2681  PagedCharge = sizeof(SECTION) + NewSegment->TotalNumberOfPtes * sizeof(MMPTE);
2682  Size = sizeof(SUBSECTION);
2683  }
2684  else
2685  {
2686  /* Charge nothing, and allocate a mapped subsection */
2687  PagedCharge = 0;
2688  Size = sizeof(MSUBSECTION);
2689  }
2690 
2691  /* Check if this is a normal CA */
2692  ASSERT(ControlArea->u.Flags.GlobalOnlyPerSession == 0);
2693  ASSERT(ControlArea->u.Flags.Rom == 0);
2694 
2695  /* Charge only a CA, and the subsection is right after */
2696  NonPagedCharge = sizeof(CONTROL_AREA);
2697  Subsection = (PSUBSECTION)(ControlArea + 1);
2698 
2699  /* We only support single-subsection mappings */
2700  NonPagedCharge += Size;
2701  ASSERT(Subsection->NextSubsection == NULL);
2702 
2703  /* Create the actual section object, with enough space for the prototype PTEs */
2707  PreviousMode,
2708  NULL,
2709  sizeof(SECTION),
2710  PagedCharge,
2711  NonPagedCharge,
2712  (PVOID*)&NewSection);
2713  if (!NT_SUCCESS(Status))
2714  {
2715  /* Check if this is a user-mode read-write non-image file mapping */
2716  if (!(FileObject) &&
2718  !(ControlArea->u.Flags.Image) &&
2719  (ControlArea->FilePointer))
2720  {
2721  /* Remove a reference and check the flag */
2722  ASSERT(Section.u.Flags.UserWritable == 1);
2723  InterlockedDecrement((volatile LONG*)&ControlArea->WritableUserReferences);
2724  }
2725 
2726  /* Check if a user reference was added */
2727  if (UserRefIncremented)
2728  {
2729  /* Acquire the PFN lock while we change counters */
2731 
2732  /* Decrement the accounting counters */
2733  ControlArea->NumberOfSectionReferences--;
2734  ASSERT((LONG)ControlArea->NumberOfUserReferences > 0);
2735  ControlArea->NumberOfUserReferences--;
2736 
2737  /* Check if we should destroy the CA and release the lock */
2738  MiCheckControlArea(ControlArea, OldIrql);
2739  }
2740 
2741  /* Return the failure code */
2742  return Status;
2743  }
2744 
2745  /* NOTE: Past this point, all failures will be handled by Ob upon ref->0 */
2746 
2747  /* Now copy the local section object from the stack into this new object */
2748  RtlCopyMemory(NewSection, &Section, sizeof(SECTION));
2749  NewSection->Address.StartingVpn = 0;
2750 
2751  /* For now, only user calls are supported */
2752  ASSERT(KernelCall == FALSE);
2753  NewSection->u.Flags.UserReference = TRUE;
2754 
2755  /* Is this a "based" allocation, in which all mappings are identical? */
2757  {
2758  /* Lock the VAD tree during the search */
2760 
2761  /* Is it a brand new ControArea ? */
2762  if (ControlArea->u.Flags.BeingCreated == 1)
2763  {
2764  ASSERT(ControlArea->u.Flags.Based == 1);
2765  /* Then we must find a global address, top-down */
2768  _64K,
2770  (ULONG_PTR*)&ControlArea->Segment->BasedAddress);
2771 
2772  if (!NT_SUCCESS(Status))
2773  {
2774  /* No way to find a valid range. */
2776  ControlArea->u.Flags.Based = 0;
2777  NewSection->u.Flags.Based = 0;
2778  ObDereferenceObject(NewSection);
2779  return Status;
2780  }
2781 
2782  /* Compute the ending address and insert it into the VAD tree */
2783  NewSection->Address.StartingVpn = (ULONG_PTR)ControlArea->Segment->BasedAddress;
2784  NewSection->Address.EndingVpn = NewSection->Address.StartingVpn + NewSection->SizeOfSection.LowPart - 1;
2785  MiInsertBasedSection(NewSection);
2786  }
2787  else
2788  {
2789  /* 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 !*/
2790  ASSERT(FALSE);
2791  }
2792 
2794  }
2795 
2796  /* The control area is not being created anymore */
2797  if (ControlArea->u.Flags.BeingCreated == 1)
2798  {
2799  /* Acquire the PFN lock while we set control area flags */
2801 
2802  /* Take off the being created flag, and then release the lock */
2803  ControlArea->u.Flags.BeingCreated = 0;
2804  NewSection->u.Flags.BeingCreated = 0;
2805 
2807  }
2808 
2809  /* Migrate the attribute into a flag */
2810  if (AllocationAttributes & SEC_NO_CHANGE) NewSection->u.Flags.NoChange = TRUE;
2811 
2812  /* If R/W access is not requested, this might eventually become a CoW mapping */
2814  {
2815  NewSection->u.Flags.CopyOnWrite = TRUE;
2816  }
2817 
2818  /* Write down if this was a kernel call */
2819  ControlArea->u.Flags.WasPurged |= KernelCall;
2820  ASSERT(ControlArea->u.Flags.WasPurged == FALSE);
2821 
2822  /* Make sure the segment and the section are the same size, or the section is smaller */
2823  ASSERT((ULONG64)NewSection->SizeOfSection.QuadPart <= NewSection->Segment->SizeOfSegment);
2824 
2825  /* Return the object and the creation status */
2826  *SectionObject = (PVOID)NewSection;
2827  return Status;
2828 }
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
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
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:1495
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:901
ACCESS_MASK MmMakeFileAccess[8]
Definition: section.c:32
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:3066
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
#define SEC_NOCACHE
Definition: mmtypes.h:100
NTSTATUS NTAPI MiFindEmptyAddressRangeDownBasedTree(IN SIZE_T Length, IN ULONG_PTR BoundaryAddress, IN ULONG_PTR Alignment, IN PMM_AVL_TABLE Table, OUT PULONG_PTR Base)
Definition: vadnode.c:713
ULONG TotalNumberOfPtes
Definition: mmtypes.h:407
struct _SUBSECTION SUBSECTION
union _CONTROL_AREA::@2555 u
NTSTATUS NTAPI MiCreatePagingFileMap(OUT PSEGMENT *Segment, IN PSIZE_T MaximumSize, IN ULONG ProtectionMask, IN ULONG AllocationAttributes)
Definition: section.c:1510
VOID NTAPI MiInsertBasedSection(IN PSECTION Section)
Definition: vadnode.c:345
FORCEINLINE VOID MiReleasePfnLock(_In_ KIRQL OldIrql)
Definition: mm.h:908
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
struct _MSUBSECTION MSUBSECTION
_In_opt_ PVOID _In_ PCSTR File
Definition: iofuncs.h:615
#define PAGE_NOACCESS
Definition: nt_native.h:1302
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
ULONG LongFlags
Definition: mmtypes.h:527
struct _SECTION SECTION
void * PVOID
Definition: retypes.h:9
ULONG_PTR StartingVpn
Definition: mmtypes.h:663
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:588
_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
int64_t LONGLONG
Definition: typedefs.h:68
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ULONG NTAPI MiMakeProtectionMask(IN ULONG Protect)
Definition: section.c:158
#define STATUS_INVALID_FILE_FOR_SECTION
Definition: ntstatus.h:269
POBJECT_TYPE MmSectionObjectType
Definition: section.c:136
#define FSRTL_FSP_TOP_LEVEL_IRP
Definition: fsrtltypes.h:59
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
* PFILE_OBJECT
Definition: iotypes.h:1978
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#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
Status
Definition: gdiplustypes.h:24
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
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
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
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
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define ULONG_PTR
Definition: config.h:101
#define SEC_IMAGE
Definition: mmtypes.h:96
#define PAGE_EXECUTE_READWRITE
Definition: nt_native.h:1308
Definition: File.h:15
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define SEC_NO_CHANGE
Definition: mmtypes.h:94
union _SECTION::@2571 u
#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 2917 of file section.c.

2927 {
2928  PROS_SECTION_OBJECT Section;
2929  NTSTATUS Status;
2933  ULONG Length;
2934 
2935  /*
2936  * Create the section
2937  */
2942  NULL,
2943  sizeof(ROS_SECTION_OBJECT),
2944  0,
2945  0,
2946  (PVOID*)&Section);
2947  if (!NT_SUCCESS(Status))
2948  {
2950  return(Status);
2951  }
2952  /*
2953  * Initialize it
2954  */
2955  RtlZeroMemory(Section, sizeof(ROS_SECTION_OBJECT));
2956  Section->Type = 'SC';
2957  Section->Size = 'TN';
2960 
2961  /*
2962  * FIXME: This is propably not entirely correct. We can't look into
2963  * the standard FCB header because it might not be initialized yet
2964  * (as in case of the EXT2FS driver by Manoj Paul Joseph where the
2965  * standard file information is filled on first request).
2966  */
2969  sizeof(FILE_STANDARD_INFORMATION),
2970  &FileInfo,
2971  &Length);
2972  if (!NT_SUCCESS(Status))
2973  {
2974  ObDereferenceObject(Section);
2976  return Status;
2977  }
2978 
2979  /*
2980  * FIXME: Revise this once a locking order for file size changes is
2981  * decided
2982  */
2983  if ((UMaximumSize != NULL) && (UMaximumSize->QuadPart != 0))
2984  {
2985  MaximumSize = *UMaximumSize;
2986  }
2987  else
2988  {
2989  MaximumSize = FileInfo.EndOfFile;
2990  /* Mapping zero-sized files isn't allowed. */
2991  if (MaximumSize.QuadPart == 0)
2992  {
2993  ObDereferenceObject(Section);
2996  }
2997  }
2998 
2999  if (MaximumSize.QuadPart > FileInfo.EndOfFile.QuadPart)
3000  {
3003  sizeof(LARGE_INTEGER),
3004  &MaximumSize);
3005  if (!NT_SUCCESS(Status))
3006  {
3007  ObDereferenceObject(Section);
3010  }
3011  }
3012 
3013  if (FileObject->SectionObjectPointer == NULL ||
3014  FileObject->SectionObjectPointer->SharedCacheMap == NULL)
3015  {
3016  ObDereferenceObject(Section);
3019  }
3020 
3021  /*
3022  * Lock the file
3023  */
3025  if (Status != STATUS_SUCCESS)
3026  {
3027  ObDereferenceObject(Section);
3029  return(Status);
3030  }
3031 
3032  /*
3033  * If this file hasn't been mapped as a data file before then allocate a
3034  * section segment to describe the data file mapping
3035  */
3036  if (FileObject->SectionObjectPointer->DataSectionObject == NULL)
3037  {
3040  if (Segment == NULL)
3041  {
3042  //KeSetEvent((PVOID)&FileObject->Lock, IO_NO_INCREMENT, FALSE);
3043  ObDereferenceObject(Section);
3045  return(STATUS_NO_MEMORY);
3046  }
3047  Section->Segment = Segment;
3048  Segment->ReferenceCount = 1;
3050  /*
3051  * Set the lock before assigning the segment to the file object
3052  */
3053  ExAcquireFastMutex(&Segment->Lock);
3054  FileObject->SectionObjectPointer->DataSectionObject = (PVOID)Segment;
3055 
3056  Segment->Image.FileOffset = 0;
3057  Segment->Protection = SectionPageProtection;
3058  Segment->Flags = MM_DATAFILE_SEGMENT;
3059  Segment->Image.Characteristics = 0;
3062  {
3063  Segment->Length.QuadPart = Segment->RawLength.QuadPart = 0;
3064  }
3065  else
3066  {
3067  Segment->RawLength.QuadPart = MaximumSize.QuadPart;
3068  Segment->Length.QuadPart = PAGE_ROUND_UP(Segment->RawLength.QuadPart);
3069  }
3070  Segment->Image.VirtualAddress = 0;
3071  Segment->Locked = TRUE;
3073  }
3074  else
3075  {
3076  /*
3077  * If the file is already mapped as a data file then we may need
3078  * to extend it
3079  */
3080  Segment =
3081  (PMM_SECTION_SEGMENT)FileObject->SectionObjectPointer->
3082  DataSectionObject;
3083  Section->Segment = Segment;
3084  (void)InterlockedIncrementUL(&Segment->ReferenceCount);
3086 
3087  if (MaximumSize.QuadPart > Segment->RawLength.QuadPart &&
3089  {
3090  Segment->RawLength.QuadPart = MaximumSize.QuadPart;
3091  Segment->Length.QuadPart = PAGE_ROUND_UP(Segment->RawLength.QuadPart);
3092  }
3093  }
3095  Section->FileObject = FileObject;
3096  Section->MaximumSize = MaximumSize;
3097 #ifndef NEWCC
3099 #endif
3100  //KeSetEvent((PVOID)&FileObject->Lock, IO_NO_INCREMENT, FALSE);
3101  *SectionObject = Section;
3102  return(STATUS_SUCCESS);
3103 }
_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:196
_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:3066
NTSTATUS NTAPI IoSetInformation(IN PFILE_OBJECT FileObject, IN FILE_INFORMATION_CLASS FileInformationClass, IN ULONG Length, IN PVOID FileInformation)
Definition: iofunc.c:1312
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
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
smooth NULL
Definition: ftsmooth.c:416
VOID NTAPI CcRosReferenceCache(PFILE_OBJECT FileObject)
Definition: view.c:1270
void * PVOID
Definition: retypes.h:9
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:588
_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
PFILE_OBJECT FileObject
Definition: mm.h:199
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
CSHORT Type
Definition: mm.h:194
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274
#define STATUS_INVALID_FILE_FOR_SECTION
Definition: ntstatus.h:269
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define MM_DATAFILE_SEGMENT
Definition: mm.h:91
POBJECT_TYPE MmSectionObjectType
Definition: section.c:136
struct _MM_SECTION_SEGMENT * PMM_SECTION_SEGMENT
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
Status
Definition: gdiplustypes.h:24
NTSTATUS MmspWaitForFileLock(PFILE_OBJECT File)
Definition: section.c:803
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:1520
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
ULONG SectionPageProtection
Definition: mm.h:197
#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:195
ULONG AllocationAttributes
Definition: mm.h:198
#define STATUS_MAPPED_FILE_SIZE_ZERO
Definition: ntstatus.h:522
#define MmUnlockSectionSegment(x)
Definition: newmm.h:284
PMM_SECTION_SEGMENT Segment
Definition: mm.h:203
return STATUS_SUCCESS
Definition: btrfs.c:3014
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 3734 of file section.c.

3741 {
3742  PROS_SECTION_OBJECT Section;
3743  NTSTATUS Status;
3744  PMM_SECTION_SEGMENT SectionSegments;
3745  PMM_IMAGE_SECTION_OBJECT ImageSectionObject;
3746  ULONG i;
3747 
3748  if (FileObject == NULL)
3750 
3751 #ifndef NEWCC
3752  if (!CcIsFileCached(FileObject))
3753  {
3754  DPRINT1("Denying section creation due to missing cache initialization\n");
3756  }
3757 #endif
3758 
3759  /*
3760  * Create the section
3761  */
3766  NULL,
3767  sizeof(ROS_SECTION_OBJECT),
3768  0,
3769  0,
3770  (PVOID*)(PVOID)&Section);
3771  if (!NT_SUCCESS(Status))
3772  {
3774  return(Status);
3775  }
3776 
3777  /*
3778  * Initialize it
3779  */
3780  RtlZeroMemory(Section, sizeof(ROS_SECTION_OBJECT));
3781  Section->Type = 'SC';
3782  Section->Size = 'TN';
3785 
3786  if (FileObject->SectionObjectPointer->ImageSectionObject == NULL)
3787  {
3788  NTSTATUS StatusExeFmt;
3789 
3791  if (ImageSectionObject == NULL)
3792  {
3794  ObDereferenceObject(Section);
3795  return(STATUS_NO_MEMORY);
3796  }
3797 
3798  RtlZeroMemory(ImageSectionObject, sizeof(MM_IMAGE_SECTION_OBJECT));
3799 
3800  StatusExeFmt = ExeFmtpCreateImageSection(FileObject, ImageSectionObject);
3801 
3802  if (!NT_SUCCESS(StatusExeFmt))
3803  {
3804  if(ImageSectionObject->Segments != NULL)
3805  ExFreePool(ImageSectionObject->Segments);
3806 
3807  /*
3808  * If image file is empty, then return that the file is invalid for section
3809  */
3810  Status = StatusExeFmt;
3811  if (StatusExeFmt == STATUS_END_OF_FILE)
3812  {
3814  }
3815 
3816  ExFreePoolWithTag(ImageSectionObject, TAG_MM_SECTION_SEGMENT);
3817  ObDereferenceObject(Section);
3819  return(Status);
3820  }
3821 
3822  Section->ImageSection = ImageSectionObject;
3823  ASSERT(ImageSectionObject->Segments);
3824 
3825  /*
3826  * Lock the file
3827  */
3829  if (!NT_SUCCESS(Status))
3830  {
3831  ExFreePool(ImageSectionObject->Segments);
3832  ExFreePool(ImageSectionObject);
3833  ObDereferenceObject(Section);
3835  return(Status);
3836  }
3837 
3838  if (NULL != InterlockedCompareExchangePointer(&FileObject->SectionObjectPointer->ImageSectionObject,
3839  ImageSectionObject, NULL))
3840  {
3841  /*
3842  * An other thread has initialized the same image in the background
3843  */
3844  ExFreePool(ImageSectionObject->Segments);
3845  ExFreePool(ImageSectionObject);
3846  ImageSectionObject = FileObject->SectionObjectPointer->ImageSectionObject;
3847  Section->ImageSection = ImageSectionObject;
3848  SectionSegments = ImageSectionObject->Segments;
3849 
3850  for (i = 0; i < ImageSectionObject->NrSegments; i++)
3851  {
3852  (void)InterlockedIncrementUL(&SectionSegments[i].ReferenceCount);
3853  }
3854  }
3855 
3856  Status = StatusExeFmt;
3857  }
3858  else
3859  {
3860  /*
3861  * Lock the file
3862  */
3864  if (Status != STATUS_SUCCESS)
3865  {
3866  ObDereferenceObject(Section);
3868  return(Status);
3869  }
3870 
3871  ImageSectionObject = FileObject->SectionObjectPointer->ImageSectionObject;
3872  Section->ImageSection = ImageSectionObject;
3873  SectionSegments = ImageSectionObject->Segments;
3874 
3875  /*
3876  * Otherwise just reference all the section segments
3877  */
3878  for (i = 0; i < ImageSectionObject->NrSegments; i++)
3879  {
3880  (void)InterlockedIncrementUL(&SectionSegments[i].ReferenceCount);
3881  }
3882 
3884  }
3885  Section->FileObject = FileObject;
3886 #ifndef NEWCC
3888 #endif
3889  //KeSetEvent((PVOID)&FileObject->Lock, IO_NO_INCREMENT, FALSE);
3890  *SectionObject = Section;
3891  return(Status);
3892 }
_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:3587
_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:3066
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
#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:202
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 CcIsFileCached(FO)
#define InterlockedCompareExchangePointer
Definition: interlocked.h:129
smooth NULL
Definition: ftsmooth.c:416
VOID NTAPI CcRosReferenceCache(PFILE_OBJECT FileObject)
Definition: view.c:1270
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:588
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
PFILE_OBJECT FileObject
Definition: mm.h:199
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
CSHORT Type
Definition: mm.h:194
PMM_SECTION_SEGMENT Segments
Definition: mm.h:189
#define STATUS_INVALID_FILE_FOR_SECTION
Definition: ntstatus.h:269
POBJECT_TYPE MmSectionObjectType
Definition: section.c:136
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
Status
Definition: gdiplustypes.h:24
NTSTATUS MmspWaitForFileLock(PFILE_OBJECT File)
Definition: section.c:803
#define TAG_MM_SECTION_SEGMENT
Definition: tag.h:139
#define InterlockedIncrementUL(Addend)
Definition: ex.h:1520
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
ULONG SectionPageProtection
Definition: mm.h:197
#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:195
ULONG AllocationAttributes
Definition: mm.h:198
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
return STATUS_SUCCESS
Definition: btrfs.c:3014
#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 2842 of file section.c.

2851 {
2853  PROS_SECTION_OBJECT Section;
2855  NTSTATUS Status;
2856 
2857  if (UMaximumSize == NULL)
2858  {
2859  DPRINT1("MmCreatePageFileSection: (UMaximumSize == NULL)\n");
2860  return(STATUS_INVALID_PARAMETER);
2861  }
2862  MaximumSize = *UMaximumSize;
2863 
2864  /*
2865  * Create the section
2866  */
2871  NULL,
2872  sizeof(ROS_SECTION_OBJECT),
2873  0,
2874  0,
2875  (PVOID*)(PVOID)&Section);
2876  if (!NT_SUCCESS(Status))
2877  {
2878  DPRINT1("MmCreatePageFileSection: failed to create object (0x%lx)\n", Status);
2879  return(Status);
2880  }
2881 
2882  /*
2883  * Initialize it
2884  */
2885  RtlZeroMemory(Section, sizeof(ROS_SECTION_OBJECT));
2886  Section->Type = 'SC';
2887  Section->Size = 'TN';
2890  Section->MaximumSize = MaximumSize;
2893  if (Segment == NULL)
2894  {
2895  ObDereferenceObject(Section);
2896  return(STATUS_NO_MEMORY);
2897  }
2899  Section->Segment = Segment;
2900  Segment->ReferenceCount = 1;
2902  Segment->Image.FileOffset = 0;
2903  Segment->Protection = SectionPageProtection;
2904  Segment->RawLength.QuadPart = MaximumSize.u.LowPart;
2905  Segment->Length.QuadPart = PAGE_ROUND_UP(MaximumSize.u.LowPart);
2906  Segment->Flags = MM_PAGEFILE_SEGMENT;
2907  Segment->WriteCopy = FALSE;
2908  Segment->Image.VirtualAddress = 0;
2909  Segment->Image.Characteristics = 0;
2910  *SectionObject = Section;
2912  return(STATUS_SUCCESS);
2913 }
_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:196
_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:3066
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_opt_ PLARGE_INTEGER _In_ ULONG SectionPageProtection
Definition: mmfuncs.h:360
#define FALSE
Definition: types.h:117
smooth NULL
Definition: ftsmooth.c:416
_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
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
CSHORT Type
Definition: mm.h:194
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274
POBJECT_TYPE MmSectionObjectType
Definition: section.c:136
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define MM_PAGEFILE_SEGMENT
Definition: mm.h:90
Status
Definition: gdiplustypes.h:24
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:197
#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:195
ULONG AllocationAttributes
Definition: mm.h:198
PMM_SECTION_SEGMENT Segment
Definition: mm.h:203
return STATUS_SUCCESS
Definition: btrfs.c:3014

Referenced by MmCreateSection().

◆ MmCreatePhysicalMemorySection()

INIT_FUNCTION NTSTATUS NTAPI MmCreatePhysicalMemorySection ( VOID  )

Definition at line 2759 of file section.c.

2760 {
2761  PROS_SECTION_OBJECT PhysSection;
2762  NTSTATUS Status;
2764  UNICODE_STRING Name = RTL_CONSTANT_STRING(L"\\Device\\PhysicalMemory");
2765  LARGE_INTEGER SectionSize;
2766  HANDLE Handle;
2767 
2768  /*
2769  * Create the section mapping physical memory
2770  */
2771  SectionSize.QuadPart = 0xFFFFFFFF;
2773  &Name,
2775  NULL,
2776  NULL);
2777  Status = MmCreateSection((PVOID)&PhysSection,
2779  &Obj,
2780  &SectionSize,
2783  NULL,
2784  NULL);
2785  if (!NT_SUCCESS(Status))
2786  {
2787  DPRINT1("Failed to create PhysicalMemory section\n");
2788  KeBugCheck(MEMORY_MANAGEMENT);
2789  }
2790  Status = ObInsertObject(PhysSection,
2791  NULL,
2793  0,
2794  NULL,
2795  &Handle);
2796  if (!NT_SUCCESS(Status))
2797  {
2798  ObDereferenceObject(PhysSection);
2799  }
2801  PhysSection->AllocationAttributes |= SEC_PHYSICALMEMORY;
2802  PhysSection->Segment->Flags &= ~MM_PAGEFILE_SEGMENT;
2803 
2804  return(STATUS_SUCCESS);
2805 }
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
#define SECTION_ALL_ACCESS
Definition: nt_native.h:1293
DECLSPEC_NORETURN VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1431
smooth NULL
Definition: ftsmooth.c:416
_In_ HANDLE Handle
Definition: extypes.h:390
#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:4979
ULONG Flags
Definition: mm.h:169
#define MM_PAGEFILE_SEGMENT
Definition: mm.h:90
NTSTATUS NTAPI ObCloseHandle(IN HANDLE Handle, IN KPROCESSOR_MODE AccessMode)
Definition: obhandle.c:3376
Status
Definition: gdiplustypes.h:24
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 OBJ_KERNEL_EXCLUSIVE
Definition: obtypes.h:91
#define DPRINT1
Definition: precomp.h:8
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
ULONG AllocationAttributes
Definition: mm.h:198
#define PAGE_EXECUTE_READWRITE
Definition: nt_native.h:1308
PMM_SECTION_SEGMENT Segment
Definition: mm.h:203
return STATUS_SUCCESS
Definition: btrfs.c:3014
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 4979 of file section.c.

4987 {
4988  NTSTATUS Status;
4989  ULONG Protection;
4991 
4992  /* Check if an ARM3 section is being created instead */
4994  {
4995  if (!(FileObject) && !(FileHandle))
4996  {
4997  return MmCreateArm3Section(Section,
4998  DesiredAccess,
5000  MaximumSize,
5002  AllocationAttributes &~ 1,
5003  FileHandle,
5004  FileObject);
5005  }
5006  }
5007 
5008  /* Convert section flag to page flag */
5010 
5011  /* Check to make sure the protection is correct. Nt* does this already */
5013  if (Protection == MM_INVALID_PROTECTION)
5014  {
5015  DPRINT1("Page protection is invalid\n");
5017  }
5018 
5019  /* Check if this is going to be a data or image backed file section */
5020  if ((FileHandle) || (FileObject))
5021  {
5022  /* These cannot be mapped with large pages */
5024  {
5025  DPRINT1("Large pages cannot be used with an image mapping\n");
5027  }
5028 
5029  /* Did the caller pass an object? */
5030  if (FileObject)
5031  {
5032  /* Reference the object directly */
5034  }
5035  else
5036  {
5037  /* Reference the file handle to get the object */
5039  MmMakeFileAccess[Protection],
5042  (PVOID*)&FileObject,
5043  NULL);
5044  if (!NT_SUCCESS(Status))
5045  {
5046  DPRINT1("Failed to get a handle to the FO: %lx\n", Status);
5047  return Status;
5048  }
5049  }
5050  }
5051  else
5052  {
5053  /* A handle must be supplied with SEC_IMAGE, as this is the no-handle path */
5055  }
5056 
5057 #ifndef NEWCC // A hack for initializing caching.
5058  // This is needed only in the old case.
5059  if (FileHandle)
5060  {
5062  NTSTATUS Status;
5063  CHAR Buffer;
5065  ByteOffset.QuadPart = 0;
5066  Status = ZwReadFile(FileHandle,
5067  NULL,
5068  NULL,
5069  NULL,
5070  &Iosb,
5071  &Buffer,
5072  sizeof(Buffer),
5073  &ByteOffset,
5074  NULL);
5076  {
5077  DPRINT1("CC failure: %lx\n", Status);
5078  if (FileObject)
5080  return Status;
5081  }
5082  // Caching is initialized...
5083 
5084  // Hack of the hack: actually, it might not be initialized if FSD init on effective right and if file is null-size
5085  // In such case, force cache by initiating a write IRP
5087  (FileObject->SectionObjectPointer == NULL || FileObject->SectionObjectPointer->SharedCacheMap == NULL))
5088  {
5089  Buffer = 0xdb;
5090  Status = ZwWriteFile(FileHandle,
5091  NULL,
5092  NULL,
5093  NULL,
5094  &Iosb,
5095  &Buffer,
5096  sizeof(Buffer),
5097  &ByteOffset,
5098  NULL);
5099  if (NT_SUCCESS(Status))
5100  {
5102  Zero.QuadPart = 0LL;
5103 
5106  sizeof(LARGE_INTEGER),
5107  &Zero);
5109  }
5110  }
5111  }
5112 #endif
5113 
5115  {
5117  DesiredAccess,
5119  MaximumSize,
5122  FileObject);
5123  }
5124 #ifndef NEWCC
5125  else if (FileHandle != NULL)
5126  {
5128  DesiredAccess,
5130  MaximumSize,
5133  FileObject);
5134  }
5135 #else
5136  else if (FileHandle != NULL || FileObject != NULL)
5137  {
5139  DesiredAccess,
5141  MaximumSize,
5144  FileObject);
5145  }
5146 #endif
5147  else
5148  {
5150  {
5151  DPRINT1("Invalid path: %lx %p %p\n", AllocationAttributes, FileObject, FileHandle);
5152  }
5153 // ASSERT(AllocationAttributes & SEC_PHYSICALMEMORY);
5155  DesiredAccess,
5157  MaximumSize,
5160  if (FileObject)
5162  }
5163 
5164  return Status;
5165 }
_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
#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
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:3066
NTSTATUS NTAPI IoSetInformation(IN PFILE_OBJECT FileObject, IN FILE_INFORMATION_CLASS FileInformationClass, IN ULONG Length, IN PVOID FileInformation)
Definition: iofunc.c:1312
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
#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:2412
_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
smooth NULL
Definition: ftsmooth.c:416
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
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:588
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:2842
ULONG NTAPI MiMakeProtectionMask(IN ULONG Protect)
Definition: section.c:158
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:3734
#define STATUS_INVALID_FILE_FOR_SECTION
Definition: ntstatus.h:269
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24
#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:2917
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB _In_ PDIRENT _In_ ULONG _In_ ULONG _In_ PUNICODE_STRING _In_ PACCESS_MASK DesiredAccess
Definition: create.c:4137
#define STATUS_INVALID_PARAMETER_6
Definition: ntstatus.h:480
_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 BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
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 4802 of file section.c.

4804 {
4805  BOOLEAN Result = TRUE;
4806 #ifdef NEWCC
4808 #endif
4809 
4810  switch(FlushType)
4811  {
4812  case MmFlushForDelete:
4813  if (SectionObjectPointer->ImageSectionObject ||
4814  SectionObjectPointer->DataSectionObject)
4815  {
4816  return FALSE;
4817  }
4818 #ifndef NEWCC
4820 #endif
4821  return TRUE;
4822  case MmFlushForWrite:
4823  {
4824  DPRINT("MmFlushImageSection(%d)\n", FlushType);
4825 #ifdef NEWCC
4826  Segment = (PMM_SECTION_SEGMENT)SectionObjectPointer->DataSectionObject;
4827 #endif
4828 
4829  if (SectionObjectPointer->ImageSectionObject)
4830  {
4831  DPRINT1("SectionObject has ImageSection\n");
4832  return FALSE;
4833  }
4834 
4835 #ifdef NEWCC
4836  CcpLock();
4837  Result = !SectionObjectPointer->SharedCacheMap || (Segment->ReferenceCount == CcpCountCacheSections((PNOCC_CACHE_MAP)SectionObjectPointer->SharedCacheMap));
4838  CcpUnlock();
4839  DPRINT("Result %d\n", Result);
4840 #endif
4841  return Result;
4842  }
4843  }
4844  return FALSE;
4845 }
#define CcpLock()
Definition: newcc.h:143
#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:144

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

3976 {
3977  ULONG_PTR Entry;
3978 #ifndef NEWCC
3980  PROS_SHARED_CACHE_MAP SharedCacheMap;
3981 #endif
3983  SWAPENTRY SavedSwapEntry;
3984  PROS_SECTION_OBJECT Section;
3988 
3991 
3993 
3995  MemoryArea->Data.SectionData.ViewOffset.QuadPart;
3996 
3997  Section = MemoryArea->Data.SectionData.Section;
3998  Segment = MemoryArea->Data.SectionData.Segment;
3999 
4001  while (Entry && MM_IS_WAIT_PTE(Entry))
4002  {
4005 
4007 
4011  }
4012 
4013  /*
4014  * For a dirty, datafile, non-private page mark it as dirty in the
4015  * cache manager.
4016  */
4017  if (Segment->Flags & MM_DATAFILE_SEGMENT)
4018  {
4019  if (Page == PFN_FROM_SSE(Entry) && Dirty)
4020  {
4021 #ifndef NEWCC
4022  FileObject = MemoryArea->Data.SectionData.Section->FileObject;
4023  SharedCacheMap = FileObject->SectionObjectPointer->SharedCacheMap;
4024  CcRosMarkDirtyFile(SharedCacheMap, Offset.QuadPart + Segment->Image.FileOffset);
4025 #endif
4026  ASSERT(SwapEntry == 0);
4027  }
4028  }
4029 
4030  if (SwapEntry != 0)
4031  {
4032  /*
4033  * Sanity check
4034  */
4035  if (Segment->Flags & MM_PAGEFILE_SEGMENT)
4036  {
4037  DPRINT1("Found a swap entry for a page in a pagefile section.\n");
4038  KeBugCheck(MEMORY_MANAGEMENT);
4039  }
4040  MmFreeSwapPage(SwapEntry);
4041  }
4042  else if (Page != 0)
4043  {
4044  if (IS_SWAP_FROM_SSE(Entry) ||
4045  Page != PFN_FROM_SSE(Entry))
4046  {
4047  /*
4048  * Sanity check
4049  */
4050  if (Segment->Flags & MM_PAGEFILE_SEGMENT)
4051  {
4052  DPRINT1("Found a private page in a pagefile section.\n");
4053  KeBugCheck(MEMORY_MANAGEMENT);
4054  }
4055  /*
4056  * Just dereference private pages
4057  */
4058  SavedSwapEntry = MmGetSavedSwapEntryPage(Page);
4059  if (SavedSwapEntry != 0)
4060  {
4061  MmFreeSwapPage(SavedSwapEntry);
4062  MmSetSavedSwapEntryPage(Page, 0);
4063  }
4064  MmDeleteRmap(Page, Process, Address);
4066  }
4067  else
4068  {
4069  MmDeleteRmap(Page, Process, Address);
4071  }
4072  }
4073 }
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:1431
NTSTATUS NTAPI MmReleasePageMemoryConsumer(ULONG Consumer, PFN_NUMBER Page)
Definition: balance.c:97
#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
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define FALSE
Definition: types.h:117
DECLSPEC_NORETURN VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1431
BOOLEAN NTAPI MmUnsharePageEntrySectionSegment(PROS_SECTION_OBJECT Section, PMM_SECTION_SEGMENT Segment, PLARGE_INTEGER Offset, BOOLEAN Dirty, BOOLEAN PageOut, ULONG_PTR *InEntry)
Definition: section.c:883
smooth NULL
Definition: ftsmooth.c:416
static WCHAR Address[46]
Definition: ping.c:68
union _MEMORY_AREA::@1771 Data
void * PVOID
Definition: retypes.h:9
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:588
_Inout_ PVOID Segment
Definition: exfuncs.h:1101
struct _MMSUPPORT * PMMSUPPORT
#define MM_DATAFILE_SEGMENT
Definition: mm.h:91
* PFILE_OBJECT
Definition: iotypes.h:1978
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#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:207
ULONG_PTR SWAPENTRY
Definition: mm.h:47
FORCEINLINE PEPROCESS MmGetAddressSpaceOwner(IN PMMSUPPORT AddressSpace)
Definition: mm.h:1438
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
struct _MEMORY_AREA::@1771::@1772 SectionData
#define MmUnlockSectionSegment(x)
Definition: newmm.h:284
FORCEINLINE VOID MmLockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1424
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:278
SWAPENTRY NTAPI MmGetSavedSwapEntryPage(PFN_NUMBER Page)
Definition: freelist.c:470

Referenced by MmUnmapViewOfSegment().

◆ MmFreeSectionSegments()

VOID NTAPI MmFreeSectionSegments ( PFILE_OBJECT  FileObject)

Definition at line 811 of file section.c.

812 {
813  if (FileObject->SectionObjectPointer->ImageSectionObject != NULL)
814  {
815  PMM_IMAGE_SECTION_OBJECT ImageSectionObject;
816  PMM_SECTION_SEGMENT SectionSegments;
817  ULONG NrSegments;
818  ULONG i;
819 
820  ImageSectionObject = (PMM_IMAGE_SECTION_OBJECT)FileObject->SectionObjectPointer->ImageSectionObject;
821  NrSegments = ImageSectionObject->NrSegments;
822  SectionSegments = ImageSectionObject->Segments;
823  for (i = 0; i < NrSegments; i++)
824  {
825  if (SectionSegments[i].ReferenceCount != 0)
826  {
827  DPRINT1("Image segment %lu still referenced (was %lu)\n", i,
828  SectionSegments[i].ReferenceCount);
829  KeBugCheck(MEMORY_MANAGEMENT);
830  }
831  MmFreePageTablesSectionSegment(&SectionSegments[i], NULL);
832  }
833  ExFreePool(ImageSectionObject->Segments);
834  ExFreePool(ImageSectionObject);
835  FileObject->SectionObjectPointer->ImageSectionObject = NULL;
836  }
837  if (FileObject->SectionObjectPointer->DataSectionObject != NULL)
838  {
840 
841  Segment = (PMM_SECTION_SEGMENT)FileObject->SectionObjectPointer->
842  DataSectionObject;
843 
844  if (Segment->ReferenceCount != 0)
845  {
846  DPRINT1("Data segment still referenced\n");
847  KeBugCheck(MEMORY_MANAGEMENT);
848  }
851  FileObject->SectionObjectPointer->DataSectionObject = NULL;
852  }
853 }
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
DECLSPEC_NORETURN VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1431
smooth NULL
Definition: ftsmooth.c:416
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:588
_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:189
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
#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()

INIT_FUNCTION NTSTATUS NTAPI MmInitSectionImplementation ( VOID  )

Definition at line 2810 of file section.c.

2811 {
2812  OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;
2814 
2815  DPRINT("Creating Section Object Type\n");
2816 
2817  /* Initialize the section based root */
2820 
2821  /* Initialize the Section object type */
2822  RtlZeroMemory(&ObjectTypeInitializer, sizeof(ObjectTypeInitializer));
2823  RtlInitUnicodeString(&Name, L"Section");
2824  ObjectTypeInitializer.Length = sizeof(ObjectTypeInitializer);
2825  ObjectTypeInitializer.DefaultPagedPoolCharge = sizeof(ROS_SECTION_OBJECT);
2826  ObjectTypeInitializer.PoolType = PagedPool;
2827  ObjectTypeInitializer.UseDefaultObject = TRUE;
2828  ObjectTypeInitializer.GenericMapping = MmpSectionMapping;
2829  ObjectTypeInitializer.DeleteProcedure = MmpDeleteSection;
2830  ObjectTypeInitializer.CloseProcedure = MmpCloseSection;
2831  ObjectTypeInitializer.ValidAccessMask = SECTION_ALL_ACCESS;
2832  ObjectTypeInitializer.InvalidAttributes = OBJ_OPENLINK;
2833  ObCreateObjectType(&Name, &ObjectTypeInitializer, NULL, &MmSectionObjectType);
2834 
2836 
2837  return(STATUS_SUCCESS);
2838 }
#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:2747
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:166
struct NameRec_ * Name
Definition: cdprocs.h:459
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
OB_CLOSE_METHOD CloseProcedure
Definition: obtypes.h:368
struct _ROS_SECTION_OBJECT ROS_SECTION_OBJECT
POBJECT_TYPE MmSectionObjectType
Definition: section.c:136
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
static const WCHAR L[]
Definition: oid.c:1250
VOID NTAPI MmpDeleteSection(PVOID ObjectBody)
Definition: section.c:2648
GENERIC_MAPPING GenericMapping
Definition: obtypes.h:358
INIT_FUNCTION NTSTATUS NTAPI MmCreatePhysicalMemorySection(VOID)
Definition: section.c:2759
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
union _MMADDRESS_NODE::@2560 u1
return STATUS_SUCCESS
Definition: btrfs.c:3014
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 4851 of file section.c.

4854 {
4855  PROS_SECTION_OBJECT Section;
4857  NTSTATUS Status;
4858  PAGED_CODE();
4859 
4861  {
4863  &MmSession,
4864  MappedBase,
4865  ViewSize);
4866  }
4867 
4868  DPRINT("MmMapViewInSystemSpace() called\n");
4869 
4872 
4874 
4875 
4876  if ((*ViewSize) == 0)
4877  {
4878  (*ViewSize) = Section->MaximumSize.u.LowPart;
4879  }
4880  else if ((*ViewSize) > Section->MaximumSize.u.LowPart)
4881  {
4882  (*ViewSize) = Section->MaximumSize.u.LowPart;
4883  }
4884 
4885  MmLockSectionSegment(Section->Segment);
4886 
4887 
4889  Section,
4890  Section->Segment,
4891  MappedBase,
4892  *ViewSize,
4894  0,
4895  0);
4896 
4897  MmUnlockSectionSegment(Section->Segment);
4899 
4900  return Status;
4901 }
_Must_inspect_result_ _Outptr_ PVOID * SectionObject
Definition: fsrtlfuncs.h:860
LARGE_INTEGER MaximumSize
Definition: mm.h:196
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG AddressSpace
Definition: iofuncs.h:2268
FORCEINLINE VOID MmUnlockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1431
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:3897
#define FALSE
Definition: types.h:117
void DPRINT(...)
Definition: polytest.cpp:61
struct _ROS_SECTION_OBJECT * PROS_SECTION_OBJECT
Status
Definition: gdiplustypes.h:24
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:1453
_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
struct _LARGE_INTEGER::@2267 u
#define MmUnlockSectionSegment(x)
Definition: newmm.h:284
PMM_SECTION_SEGMENT Segment
Definition: mm.h:203
FORCEINLINE VOID MmLockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1424
#define PAGE_READWRITE
Definition: nt_native.h:1304
#define PAGED_CODE()
FORCEINLINE BOOLEAN MiIsRosSectionObject(IN PVOID Section)
Definition: miarm.h:1062
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 2835 of file section.c.

2845 {
2848  PSECTION Section;
2849  PCONTROL_AREA ControlArea;
2850  ULONG ProtectionMask;
2851  NTSTATUS Status;
2852  ULONG64 CalculatedViewSize;
2853  PAGED_CODE();
2854 
2855  /* Get the segment and control area */
2856  Section = (PSECTION)SectionObject;
2857  ControlArea = Section->Segment->ControlArea;
2858 
2859  /* These flags/states are not yet supported by ARM3 */
2860  ASSERT(Section->u.Flags.Image == 0);
2861  ASSERT(Section->u.Flags.NoCache == 0);
2862  ASSERT(Section->u.Flags.WriteCombined == 0);
2863  ASSERT(ControlArea->u.Flags.PhysicalMemory == 0);
2864 
2865  /* FIXME */
2866  if ((AllocationType & MEM_RESERVE) != 0)
2867  {
2868  DPRINT1("MmMapViewOfArm3Section called with MEM_RESERVE, this is not implemented yet!!!\n");
2869  return STATUS_NOT_IMPLEMENTED;
2870  }
2871 
2872  /* Check if the mapping protection is compatible with the create */
2874  {
2875  DPRINT1("Mapping protection is incompatible\n");
2877  }
2878 
2879  /* Check if the offset and size would cause an overflow */
2880  if (((ULONG64)SectionOffset->QuadPart + *ViewSize) <
2881  (ULONG64)SectionOffset->QuadPart)
2882  {
2883  DPRINT1("Section offset overflows\n");
2884  return STATUS_INVALID_VIEW_SIZE;
2885  }
2886 
2887  /* Check if the offset and size are bigger than the section itself */
2888  if (((ULONG64)SectionOffset->QuadPart + *ViewSize) >
2889  (ULONG64)Section->SizeOfSection.QuadPart)
2890  {
2891  DPRINT1("Section offset is larger than section\n");
2892  return STATUS_INVALID_VIEW_SIZE;
2893  }
2894 
2895  /* Check if the caller did not specify a view size */
2896  if (!(*ViewSize))
2897  {
2898  /* Compute it for the caller */
2899  CalculatedViewSize = Section->SizeOfSection.QuadPart -
2900  SectionOffset->QuadPart;
2901 
2902  /* Check if it's larger than 4GB or overflows into kernel-mode */
2903  if (!NT_SUCCESS(RtlULongLongToSIZET(CalculatedViewSize, ViewSize)) ||
2904  (((ULONG_PTR)MM_HIGHEST_VAD_ADDRESS - (ULONG_PTR)*BaseAddress) < CalculatedViewSize))
2905  {
2906  DPRINT1("Section view won't fit\n");
2907  return STATUS_INVALID_VIEW_SIZE;
2908  }
2909  }
2910 
2911  /* Check if the commit size is larger than the view size */
2912  if (CommitSize > *ViewSize)
2913  {
2914  DPRINT1("Attempting to commit more than the view itself\n");
2916  }
2917 
2918  /* Check if the view size is larger than the section */
2919  if (*ViewSize > (ULONG64)Section->SizeOfSection.QuadPart)
2920  {
2921  DPRINT1("The view is larger than the section\n");
2922  return STATUS_INVALID_VIEW_SIZE;
2923  }
2924 
2925  /* Compute and validate the protection mask */
2926  ProtectionMask = MiMakeProtectionMask(Protect);
2927  if (ProtectionMask == MM_INVALID_PROTECTION)
2928  {
2929  DPRINT1("The protection is invalid\n");
2931  }
2932 
2933  /* We only handle pagefile-backed sections, which cannot be writecombined */
2934  if (Protect & PAGE_WRITECOMBINE)
2935  {
2936  DPRINT1("Cannot write combine a pagefile-backed section\n");
2938  }
2939 
2940  /* Start by attaching to the current process if needed */
2941  if (PsGetCurrentProcess() != Process)
2942  {
2944  Attached = TRUE;
2945  }
2946 
2947  /* Do the actual mapping */
2948  Status = MiMapViewOfDataSection(ControlArea,
2949  Process,
2950  BaseAddress,
2951  SectionOffset,
2952  ViewSize,
2953  Section,
2955  ProtectionMask,
2956  CommitSize,
2957  ZeroBits,
2958  AllocationType);
2959 
2960  /* Detach if needed, then return status */
2962  return Status;
2963 }
_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:1279
BOOLEAN NTAPI MiIsProtectionCompatible(IN ULONG SectionPageProtection, IN ULONG NewSectionPageProtection)
Definition: section.c:117
PSEGMENT Segment
Definition: mmtypes.h:822
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:239
_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
union _CONTROL_AREA::@2555 u
struct _CONTROL_AREA * ControlArea
Definition: mmtypes.h:406
uint32_t ULONG_PTR
Definition: typedefs.h:65
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
#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
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#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
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
unsigned __int64 ULONG64
Definition: imports.h:198
Status
Definition: gdiplustypes.h:24
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:1492
#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
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
union _SECTION::@2571 u
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 4506 of file section.c.

4516 {
4517  PROS_SECTION_OBJECT Section;
4519  ULONG ViewOffset;
4521  BOOLEAN NotAtBase = FALSE;
4522 
4524  {
4525  DPRINT("Mapping ARM3 section into %s\n", Process->ImageFileName);
4527  Process,
4528  BaseAddress,
4529  ZeroBits,
4530  CommitSize,
4531  SectionOffset,