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

Go to the source code of this file.

Classes

struct  MM_SECTION_PAGEOUT_CONTEXT
 

Macros

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

Functions

NTSTATUS NTAPI MiMapViewInSystemSpace (IN PVOID Section, IN PVOID Session, OUT PVOID *MappedBase, IN OUT PSIZE_T ViewSize)
 
NTSTATUS NTAPI MmCreateArm3Section (OUT PVOID *SectionObject, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN PLARGE_INTEGER InputMaximumSize, IN ULONG SectionPageProtection, IN ULONG AllocationAttributes, IN HANDLE FileHandle OPTIONAL, IN PFILE_OBJECT FileObject OPTIONAL)
 
NTSTATUS NTAPI MmMapViewOfArm3Section (IN PVOID SectionObject, IN PEPROCESS Process, IN OUT PVOID *BaseAddress, IN ULONG_PTR ZeroBits, IN SIZE_T CommitSize, IN OUT PLARGE_INTEGER SectionOffset OPTIONAL, IN OUT PSIZE_T ViewSize, IN SECTION_INHERIT InheritDisposition, IN ULONG AllocationType, IN ULONG Protect)
 
 C_ASSERT (EXEFMT_LOAD_HEADER_SIZE >=sizeof(IMAGE_DOS_HEADER))
 
 C_ASSERT (sizeof(IMAGE_NT_HEADERS32)<=sizeof(IMAGE_NT_HEADERS64))
 
 C_ASSERT (TYPE_ALIGNMENT(IMAGE_NT_HEADERS32)==TYPE_ALIGNMENT(IMAGE_NT_HEADERS64))
 
 C_ASSERT (RTL_SIZEOF_THROUGH_FIELD(IMAGE_NT_HEADERS32, FileHeader)==RTL_SIZEOF_THROUGH_FIELD(IMAGE_NT_HEADERS64, FileHeader))
 
 C_ASSERT (FIELD_OFFSET(IMAGE_NT_HEADERS32, OptionalHeader)==FIELD_OFFSET(IMAGE_NT_HEADERS64, OptionalHeader))
 
 C_ASSERT (PEFMT_FIELDS_EQUAL(IMAGE_OPTIONAL_HEADER32, IMAGE_OPTIONAL_HEADER64, Magic))
 
 C_ASSERT (PEFMT_FIELDS_EQUAL(IMAGE_OPTIONAL_HEADER32, IMAGE_OPTIONAL_HEADER64, SectionAlignment))
 
 C_ASSERT (PEFMT_FIELDS_EQUAL(IMAGE_OPTIONAL_HEADER32, IMAGE_OPTIONAL_HEADER64, FileAlignment))
 
 C_ASSERT (PEFMT_FIELDS_EQUAL(IMAGE_OPTIONAL_HEADER32, IMAGE_OPTIONAL_HEADER64, Subsystem))
 
 C_ASSERT (PEFMT_FIELDS_EQUAL(IMAGE_OPTIONAL_HEADER32, IMAGE_OPTIONAL_HEADER64, MinorSubsystemVersion))
 
 C_ASSERT (PEFMT_FIELDS_EQUAL(IMAGE_OPTIONAL_HEADER32, IMAGE_OPTIONAL_HEADER64, MajorSubsystemVersion))
 
 C_ASSERT (PEFMT_FIELDS_EQUAL(IMAGE_OPTIONAL_HEADER32, IMAGE_OPTIONAL_HEADER64, AddressOfEntryPoint))
 
 C_ASSERT (PEFMT_FIELDS_EQUAL(IMAGE_OPTIONAL_HEADER32, IMAGE_OPTIONAL_HEADER64, SizeOfCode))
 
 C_ASSERT (PEFMT_FIELDS_EQUAL(IMAGE_OPTIONAL_HEADER32, IMAGE_OPTIONAL_HEADER64, SizeOfHeaders))
 
ACCESS_MASK NTAPI MiArm3GetCorrectFileAccessMask (IN ACCESS_MASK SectionPageProtection)
 
NTSTATUS NTAPI PeFmtCreateSection (IN CONST VOID *FileHeader, IN SIZE_T FileHeaderSize, IN PVOID File, OUT PMM_IMAGE_SECTION_OBJECT ImageSectionObject, OUT PULONG Flags, IN PEXEFMT_CB_READ_FILE ReadFileCb, IN PEXEFMT_CB_ALLOCATE_SEGMENTS AllocateSegmentsCb)
 
NTSTATUS MmspWaitForFileLock (PFILE_OBJECT File)
 
VOID NTAPI MmFreeSectionSegments (PFILE_OBJECT FileObject)
 
VOID NTAPI MmSharePageEntrySectionSegment (PMM_SECTION_SEGMENT Segment, PLARGE_INTEGER Offset)
 
BOOLEAN NTAPI MmUnsharePageEntrySectionSegment (PROS_SECTION_OBJECT Section, PMM_SECTION_SEGMENT Segment, PLARGE_INTEGER Offset, BOOLEAN Dirty, BOOLEAN PageOut, ULONG_PTR *InEntry)
 
BOOLEAN MiIsPageFromCache (PMEMORY_AREA MemoryArea, LONGLONG SegOffset)
 
NTSTATUS NTAPI MiCopyFromUserPage (PFN_NUMBER DestPage, const VOID *SrcAddress)
 
NTSTATUS NTAPI MiReadPage (PMEMORY_AREA MemoryArea, LONGLONG SegOffset, PPFN_NUMBER Page)
 
static VOID MmAlterViewAttributes (PMMSUPPORT AddressSpace, PVOID BaseAddress, SIZE_T RegionSize, ULONG OldType, ULONG OldProtect, ULONG NewType, ULONG NewProtect)
 
NTSTATUS NTAPI MmNotPresentFaultSectionView (PMMSUPPORT AddressSpace, MEMORY_AREA *MemoryArea, PVOID Address, BOOLEAN Locked)
 
NTSTATUS NTAPI MmAccessFaultSectionView (PMMSUPPORT AddressSpace, MEMORY_AREA *MemoryArea, PVOID Address)
 
VOID MmPageOutDeleteMapping (PVOID Context, PEPROCESS Process, PVOID Address)
 
NTSTATUS NTAPI MmPageOutSectionView (PMMSUPPORT AddressSpace, MEMORY_AREA *MemoryArea, PVOID Address, ULONG_PTR Entry)
 
NTSTATUS NTAPI MmWritePageSectionView (PMMSUPPORT AddressSpace, PMEMORY_AREA MemoryArea, PVOID Address, ULONG PageEntry)
 
NTSTATUS NTAPI MmProtectSectionView (PMMSUPPORT AddressSpace, PMEMORY_AREA MemoryArea, PVOID BaseAddress, SIZE_T Length, ULONG Protect, PULONG OldProtect)
 
NTSTATUS NTAPI MmQuerySectionView (PMEMORY_AREA MemoryArea, PVOID Address, PMEMORY_BASIC_INFORMATION Info, PSIZE_T ResultLength)
 
VOID NTAPI MmpFreePageFileSegment (PMM_SECTION_SEGMENT Segment)
 
VOID NTAPI MmpDeleteSection (PVOID ObjectBody)
 
VOID NTAPI MmpCloseSection (IN PEPROCESS Process OPTIONAL, IN PVOID Object, IN ACCESS_MASK GrantedAccess, IN ULONG ProcessHandleCount, IN ULONG SystemHandleCount)
 
NTSTATUS INIT_FUNCTION NTAPI MmCreatePhysicalMemorySection (VOID)
 
NTSTATUS INIT_FUNCTION 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 3138 of file section.c.

3139 {
3140  SIZE_T SizeOfSegments;
3141  PMM_SECTION_SEGMENT Segments;
3142 
3143  /* TODO: check for integer overflow */
3144  SizeOfSegments = sizeof(MM_SECTION_SEGMENT) * NrSegments;
3145 
3147  SizeOfSegments,
3149 
3150  if(Segments)
3151  RtlZeroMemory(Segments, SizeOfSegments);
3152 
3153  return Segments;
3154 }
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
ULONG_PTR SIZE_T
Definition: typedefs.h:78
#define TAG_MM_SECTION_SEGMENT
Definition: tag.h:139
struct _MM_SECTION_SEGMENT MM_SECTION_SEGMENT
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261

Referenced by ExeFmtpCreateImageSection().

◆ ExeFmtpCreateImageSection()

NTSTATUS ExeFmtpCreateImageSection ( PFILE_OBJECT  FileObject,
PMM_IMAGE_SECTION_OBJECT  ImageSectionObject 
)

Definition at line 3583 of file section.c.

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

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

3165 {
3166  NTSTATUS Status;
3168  ULONG AdjustOffset;
3169  ULONG OffsetAdjustment;
3170  ULONG BufferSize;
3171  ULONG UsedSize;
3172  PVOID Buffer;
3175 
3177 
3178  if(Length == 0)
3179  {
3180  KeBugCheck(MEMORY_MANAGEMENT);
3181  }
3182 
3183  FileOffset = *Offset;
3184 
3185  /* Negative/special offset: it cannot be used in this context */
3186  if(FileOffset.u.HighPart < 0)
3187  {
3188  KeBugCheck(MEMORY_MANAGEMENT);
3189  }
3190 
3191  AdjustOffset = PAGE_ROUND_DOWN(FileOffset.u.LowPart);
3192  OffsetAdjustment = FileOffset.u.LowPart - AdjustOffset;
3193  FileOffset.u.LowPart = AdjustOffset;
3194 
3195  BufferSize = Length + OffsetAdjustment;
3197 
3198  /* Flush data since we're about to perform a non-cached read */
3199  CcFlushCache(FileObject->SectionObjectPointer,
3200  &FileOffset,
3201  BufferSize,
3202  &Iosb);
3203 
3204  /*
3205  * It's ok to use paged pool, because this is a temporary buffer only used in
3206  * the loading of executables. The assumption is that MmCreateSection is
3207  * always called at low IRQLs and that these buffers don't survive a brief
3208  * initialization phase
3209  */
3211  BufferSize,
3212  'rXmM');
3213  if (!Buffer)
3214  {
3216  }
3217 
3218  UsedSize = 0;
3219 
3221 
3222  UsedSize = (ULONG)Iosb.Information;
3223 
3224  if(NT_SUCCESS(Status) && UsedSize < OffsetAdjustment)
3225  {
3228  }
3229 
3230  if(NT_SUCCESS(Status))
3231  {
3232  *Data = (PVOID)((ULONG_PTR)Buffer + OffsetAdjustment);
3233  *AllocBase = Buffer;
3234  *ReadSize = UsedSize - OffsetAdjustment;
3235  }
3236  else
3237  {
3238  ExFreePoolWithTag(Buffer, 'rXmM');
3239  }
3240 
3241  return Status;
3242 }
#define TRUE
Definition: types.h:120
#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
LONG NTSTATUS
Definition: precomp.h:26
#define PAGE_ROUND_DOWN(x)
Definition: mmtypes.h:36
#define PAGE_ROUND_UP(x)
Definition: scsiport_int.h:13
uint32_t ULONG_PTR
Definition: typedefs.h:63
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
_In_opt_ PVOID _In_ PCSTR File
Definition: iofuncs.h:615
VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1507
Definition: bufpool.h:45
void * PVOID
Definition: retypes.h:9
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
return Iosb
Definition: create.c:4426
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define BufferSize
Definition: classpnp.h:419
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
* PFILE_OBJECT
Definition: iotypes.h:1955
#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:151
unsigned int ULONG
Definition: retypes.h:1
#define STATUS_IN_PAGE_ERROR
Definition: ntstatus.h:229
#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:71
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:291
#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 1046 of file section.c.

1047 {
1049  KIRQL Irql;
1050  PVOID DestAddress;
1051 
1053  DestAddress = MiMapPageInHyperSpace(Process, DestPage, &Irql);
1054  if (DestAddress == NULL)
1055  {
1056  return(STATUS_NO_MEMORY);
1057  }
1058  ASSERT((ULONG_PTR)DestAddress % PAGE_SIZE == 0);
1059  ASSERT((ULONG_PTR)SrcAddress % PAGE_SIZE == 0);
1060  RtlCopyMemory(DestAddress, SrcAddress, PAGE_SIZE);
1061  MiUnmapPageInHyperSpace(Process, DestAddress, Irql);
1062  return(STATUS_SUCCESS);
1063 }
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:63
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:246
_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:2938

Referenced by MmAccessFaultSectionView().

◆ MiIsPageFromCache()

BOOLEAN MiIsPageFromCache ( PMEMORY_AREA  MemoryArea,
LONGLONG  SegOffset 
)

Definition at line 1024 of file section.c.

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

Referenced by MmPageOutSectionView().

◆ MiMapViewInSystemSpace()

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

◆ MiReadPage()

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

Definition at line 1068 of file section.c.

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

Referenced by MmNotPresentFaultSectionView().

◆ MiRosUnmapViewInSystemSpace()

NTSTATUS NTAPI MiRosUnmapViewInSystemSpace ( IN PVOID  MappedBase)

Definition at line 4901 of file section.c.

4902 {
4904  NTSTATUS Status;
4905 
4906  DPRINT("MmUnmapViewInSystemSpace() called\n");
4907 
4909 
4911 
4913 
4915 
4916  return Status;
4917 }
_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:4072
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:493
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 4137 of file section.c.

4140 {
4141  NTSTATUS Status;
4144  PROS_SECTION_OBJECT Section;
4145  PVOID ImageBaseAddress = 0;
4146 
4147  DPRINT("Opening memory area Process %p BaseAddress %p\n",
4148  Process, BaseAddress);
4149 
4150  ASSERT(Process);
4151 
4153 
4156  BaseAddress);
4157  if (MemoryArea == NULL ||
4161  {
4164  return STATUS_NOT_MAPPED_VIEW;
4165  }
4166 
4167  Section = MemoryArea->Data.SectionData.Section;
4168 
4169  if ((Section != NULL) && (Section->AllocationAttributes & SEC_IMAGE))
4170  {
4171  ULONG i;
4172  ULONG NrSegments;
4173  PMM_IMAGE_SECTION_OBJECT ImageSectionObject;
4174  PMM_SECTION_SEGMENT SectionSegments;
4176 
4177  Segment = MemoryArea->Data.SectionData.Segment;
4178  ImageSectionObject = Section->ImageSection;
4179  SectionSegments = ImageSectionObject->Segments;
4180  NrSegments = ImageSectionObject->NrSegments;
4181 
4183 
4184  /* Search for the current segment within the section segments
4185  * and calculate the image base address */
4186  for (i = 0; i < NrSegments; i++)
4187  {
4188  if (Segment == &SectionSegments[i])
4189  {
4190  ImageBaseAddress = (char*)BaseAddress - (ULONG_PTR)SectionSegments[i].Image.VirtualAddress;
4191  break;
4192  }
4193  }
4194  if (i >= NrSegments)
4195  {
4196  KeBugCheck(MEMORY_MANAGEMENT);
4197  }
4198 
4199  for (i = 0; i < NrSegments; i++)
4200  {
4201  PVOID SBaseAddress = (PVOID)
4202  ((char*)ImageBaseAddress + (ULONG_PTR)SectionSegments[i].Image.VirtualAddress);
4203 
4204  Status = MmUnmapViewOfSegment(AddressSpace, SBaseAddress);
4205  if (!NT_SUCCESS(Status))
4206  {
4207  DPRINT1("MmUnmapViewOfSegment failed for %p (Process %p) with %lx\n",
4208  SBaseAddress, Process, Status);
4210  }
4211  }
4212  }
4213  else
4214  {
4216  if (!NT_SUCCESS(Status))
4217  {
4218  DPRINT1("MmUnmapViewOfSegment failed for %p (Process %p) with %lx\n",
4221  }
4222  }
4223 
4225 
4226  /* Notify debugger */
4227  if (ImageBaseAddress && !SkipDebuggerNotify) DbgkUnMapViewOfSection(ImageBaseAddress);
4228 
4229  return(STATUS_SUCCESS);
4230 }
#define TRUE
Definition: types.h:120
ULONG Type
Definition: mm.h:214
struct _MM_SECTION_SEGMENT::@1740 Image
_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:63
static NTSTATUS MmUnmapViewOfSegment(PMMSUPPORT AddressSpace, PVOID BaseAddress)
Definition: section.c:4072
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
union _MEMORY_AREA::@1743 Data
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1507
void * PVOID
Definition: retypes.h:9
#define MEMORY_AREA_SECTION_VIEW
Definition: mm.h:71
_Inout_ PVOID Segment
Definition: exfuncs.h:893
_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
struct _MEMORY_AREA::@1743::@1744 SectionData
BOOLEAN DeleteInProgress
Definition: mm.h:217
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
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:248
#define ULONG_PTR
Definition: config.h:101
#define SEC_IMAGE
Definition: mmtypes.h:96
ULONG AllocationAttributes
Definition: mm.h:198
return STATUS_SUCCESS
Definition: btrfs.c:2938
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 1797 of file section.c.

1800 {
1802  PROS_SECTION_OBJECT Section;
1803  PFN_NUMBER OldPage;
1804  PFN_NUMBER NewPage;
1805  NTSTATUS Status;
1806  PVOID PAddress;
1809  ULONG_PTR Entry;
1811 
1812  DPRINT("MmAccessFaultSectionView(%p, %p, %p)\n", AddressSpace, MemoryArea, Address);
1813 
1814  /* Make sure we have a page mapping for this address. */
1816  if (!NT_SUCCESS(Status))
1817  {
1818  /* This is invalid access ! */
1819  return Status;
1820  }
1821 
1822  /*
1823  * Check if the page has already been set readwrite
1824  */
1826  {
1827  DPRINT("Address 0x%p\n", Address);
1828  return(STATUS_SUCCESS);
1829  }
1830 
1831  /*
1832  * Find the offset of the page
1833  */
1834  PAddress = MM_ROUND_DOWN(Address, PAGE_SIZE);
1835  Offset.QuadPart = (ULONG_PTR)PAddress - MA_GetStartingAddress(MemoryArea)
1836  + MemoryArea->Data.SectionData.ViewOffset.QuadPart;
1837 
1838  Segment = MemoryArea->Data.SectionData.Segment;
1839  Section = MemoryArea->Data.SectionData.Section;
1841  &MemoryArea->Data.SectionData.RegionListHead,
1842  Address, NULL);
1843  ASSERT(Region != NULL);
1844 
1845  /*
1846  * Check if we are doing COW
1847  */
1848  if (!((Segment->WriteCopy) &&
1849  (Region->Protect == PAGE_READWRITE ||
1850  Region->Protect == PAGE_EXECUTE_READWRITE)))
1851  {
1852  DPRINT("Address 0x%p\n", Address);
1853  return(STATUS_ACCESS_VIOLATION);
1854  }
1855 
1856  /* Get the page mapping this section offset. */
1859 
1860  /* Get the current page mapping for the process */
1861  ASSERT(MmIsPagePresent(Process, PAddress));
1862  OldPage = MmGetPfnForProcess(Process, PAddress);
1863  ASSERT(OldPage != 0);
1864 
1865  if (IS_SWAP_FROM_SSE(Entry) ||
1866  PFN_FROM_SSE(Entry) != OldPage)
1867  {
1869  /* This is a private page. We must only change the page protection. */
1870  MmSetPageProtect(Process, PAddress, Region->Protect);
1871  return(STATUS_SUCCESS);
1872  }
1873 
1874  /*
1875  * Allocate a page
1876  */
1878  if (Process) MI_SET_PROCESS2(Process->ImageFileName);
1879  if (!Process) MI_SET_PROCESS2("Kernel Section");
1881  if (!NT_SUCCESS(Status))
1882  {
1883  KeBugCheck(MEMORY_MANAGEMENT);
1884  }
1885 
1886  /*
1887  * Copy the old page
1888  */
1889  NT_VERIFY(NT_SUCCESS(MiCopyFromUserPage(NewPage, PAddress)));
1890 
1891  /*
1892  * Unshare the old page.
1893  */
1894  DPRINT("Swapping page (Old %x New %x)\n", OldPage, NewPage);
1895  MmDeleteVirtualMapping(Process, PAddress, NULL, NULL);
1896  MmDeleteRmap(OldPage, Process, PAddress);
1899 
1900  /*
1901  * Set the PTE to point to the new page
1902  */
1904  PAddress,
1905  Region->Protect,
1906  &NewPage,
1907  1);
1908  if (!NT_SUCCESS(Status))
1909  {
1910  DPRINT1("MmCreateVirtualMapping failed, unable to create virtual mapping, not out of memory\n");
1911  KeBugCheck(MEMORY_MANAGEMENT);
1912  return(Status);
1913  }
1914  MmInsertRmap(NewPage, Process, PAddress);
1915 
1917  DPRINT("Address 0x%p\n", Address);
1918  return(STATUS_SUCCESS);
1919 }
PMM_REGION NTAPI MmFindRegion(PVOID BaseAddress, PLIST_ENTRY RegionListHead, PVOID Address, PVOID *RegionBaseAddress)
Definition: region.c:257
#define TRUE
Definition: types.h:120
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:640
#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 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:63
BOOLEAN NTAPI MmIsPagePresent(struct _EPROCESS *Process, PVOID Address)
ULONG PFN_NUMBER
Definition: ke.h:8
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
NTSTATUS NTAPI MmNotPresentFaultSectionView(PMMSUPPORT AddressSpace, MEMORY_AREA *MemoryArea, PVOID Address, BOOLEAN Locked)
Definition: section.c:1364
union _MEMORY_AREA::@1743 Data
#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:879
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)
void DPRINT(...)
Definition: polytest.cpp:61
VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1507
#define MI_SET_USAGE(x)
Definition: mm.h:253
_Inout_ PVOID Segment
Definition: exfuncs.h:893
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
struct _MEMORY_AREA::@1743::@1744 SectionData
VOID NTAPI MmSetPageProtect(struct _EPROCESS *Process, PVOID Address, ULONG flProtect)
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#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
Status
Definition: gdiplustypes.h:24
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:228
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
#define MmUnlockSectionSegment(x)
Definition: newmm.h:284
return STATUS_SUCCESS
Definition: btrfs.c:2938
NTSTATUS NTAPI MiCopyFromUserPage(PFN_NUMBER DestPage, const VOID *SrcAddress)
Definition: section.c:1046
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 1282 of file section.c.

1289 {
1292  BOOLEAN DoCOW = FALSE;
1293  ULONG i;
1295 
1297  ASSERT(MemoryArea != NULL);
1298  Segment = MemoryArea->Data.SectionData.Segment;
1300 
1301  if ((Segment->WriteCopy) &&
1303  {
1304  DoCOW = TRUE;
1305  }
1306 
1307  if (OldProtect != NewProtect)
1308  {
1309  for (i = 0; i < PAGE_ROUND_UP(RegionSize) / PAGE_SIZE; i++)
1310  {
1311  SWAPENTRY SwapEntry;
1312  PVOID Address = (char*)BaseAddress + (i * PAGE_SIZE);
1314 
1315  /* Wait for a wait entry to disappear */
1316  do
1317  {
1318  MmGetPageFileMapping(Process, Address, &SwapEntry);
1319  if (SwapEntry != MM_WAIT_ENTRY)
1320  break;
1322  }
1323  while (TRUE);
1324 
1325  /*
1326  * If we doing COW for this segment then check if the page is
1327  * already private.
1328  */
1329  if (DoCOW && MmIsPagePresent(Process, Address))
1330  {
1332  ULONG_PTR Entry;
1333  PFN_NUMBER Page;
1334 
1336  + MemoryArea->Data.SectionData.ViewOffset.QuadPart;
1338  /*
1339  * An MM_WAIT_ENTRY is ok in this case... It'll just count as
1340  * IS_SWAP_FROM_SSE and we'll do the right thing.
1341  */
1343 
1345  if (IS_SWAP_FROM_SSE(Entry) || PFN_FROM_SSE(Entry) != Page)
1346  {
1347  Protect = NewProtect;
1348  }
1349  }
1350 
1352  {
1354  Protect);
1355  }
1356  }
1357  }
1358 
1360 }
#define TRUE
Definition: types.h:120
struct _Entry Entry
Definition: kefuncs.h:640
#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
_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
#define PAGE_ROUND_UP(x)
Definition: scsiport_int.h:13
uint32_t ULONG_PTR
Definition: typedefs.h:63
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
union _MEMORY_AREA::@1743 Data
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
static WCHAR Address[46]
Definition: ping.c:68
VOID NTAPI MmGetPageFileMapping(struct _EPROCESS *Process, PVOID Address, SWAPENTRY *SwapEntry)
_Inout_ PVOID Segment
Definition: exfuncs.h:893
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
struct _MEMORY_AREA::@1743::@1744 SectionData
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:683
#define PAGE_READONLY
Definition: compat.h:127
#define MmLockSectionSegment(x)
Definition: newmm.h:276
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
#define PAGE_EXECUTE_READWRITE
Definition: nt_native.h:1308
#define MmUnlockSectionSegment(x)
Definition: newmm.h:284
struct _MEMORY_AREA * MemoryArea
Definition: newmm.h:65
base of all file and directory entries
Definition: entries.h:82
#define MmGetPageEntrySectionSegment(S, O)
Definition: newmm.h:143
#define PAGE_READWRITE
Definition: nt_native.h:1304

Referenced by MmNotPresentFaultSectionView(), and MmProtectSectionView().

◆ MmCanFileBeTruncated()

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

Definition at line 4724 of file section.c.

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

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:477
_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:71
PEVENT_COUNTER WaitingForDeletion
Definition: mmtypes.h:525
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
PFILE_OBJECT FilePointer
Definition: mmtypes.h:524
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define SEC_LARGE_PAGES
Definition: mmtypes.h:102
ULONGLONG SizeOfSegment
Definition: mmtypes.h:404
_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:470
ULONG NumberOfSectionReferences
Definition: mmtypes.h:514
PSEGMENT Segment
Definition: mmtypes.h:812
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 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:401
struct _SUBSECTION SUBSECTION
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:400
uint32_t ULONG_PTR
Definition: typedefs.h:63
#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:78
struct _SUBSECTION * NextSubsection
Definition: mmtypes.h:573
long LONG
Definition: pedump.c:60
LARGE_INTEGER SizeOfSection
Definition: mmtypes.h:813
#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:521
struct _SECTION SECTION
union _SECTION::@2524 u
void * PVOID
Definition: retypes.h:9
ULONG_PTR StartingVpn
Definition: mmtypes.h:653
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
_Inout_ PVOID Segment
Definition: exfuncs.h:893
NTSTATUS NTAPI ObCreateObject(IN KPROCESSOR_MODE ProbeMode OPTIONAL, IN POBJECT_TYPE Type, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN KPROCESSOR_MODE AccessMode, IN OUT PVOID ParseContext OPTIONAL, IN ULONG ObjectSize, IN ULONG PagedPoolCharge OPTIONAL, IN ULONG NonPagedPoolCharge OPTIONAL, OUT PVOID *Object)
Definition: oblife.c:952
ULONG_PTR EndingVpn
Definition: mmtypes.h:654
int64_t LONGLONG
Definition: typedefs.h:66
_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:255
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:1955
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
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
MMSECTION_FLAGS Flags
Definition: mmtypes.h:817
#define InterlockedDecrement
Definition: armddk.h:52
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
ULONG GlobalOnlyPerSession
Definition: mmtypes.h:482
ULONG LowPart
Definition: typedefs.h:104
#define STATUS_INVALID_PAGE_PROTECTION
Definition: ntstatus.h:291
ULONG CopyOnWrite
Definition: mmtypes.h:465
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
POBJECT_TYPE IoFileObjectType
Definition: iomgr.c:36
#define _64K
Definition: miarm.h:19
Status
Definition: gdiplustypes.h:24
ULONG_PTR SIZE_T
Definition: typedefs.h:78
#define PAGE_WRITECOMBINE
Definition: mmtypes.h:78
#define InterlockedIncrement
Definition: armddk.h:53
ULONG FilePointerNull
Definition: mmtypes.h:473
ULONG WritableUserReferences
Definition: mmtypes.h:528
PSEGMENT Segment
Definition: mmtypes.h:512
MMADDRESS_NODE Address
Definition: mmtypes.h:811
#define STATUS_INVALID_PARAMETER_6
Definition: ntstatus.h:466
ULONG NumberOfUserReferences
Definition: mmtypes.h:518
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:409
PVOID MmHighSectionBase
Definition: section.c:111
ULONG WasPurged
Definition: mmtypes.h:469
MMSECTION_FLAGS Flags
Definition: mmtypes.h:522
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define ULONG_PTR
Definition: config.h:101
union _CONTROL_AREA::@2508 u
#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:2938
#define SEC_NO_CHANGE
Definition: mmtypes.h:94
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
ULONG BeingCreated
Definition: mmtypes.h:455
LONGLONG QuadPart
Definition: typedefs.h:112
#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 2913 of file section.c.

2923 {
2924  PROS_SECTION_OBJECT Section;
2925  NTSTATUS Status;
2929  ULONG Length;
2930 
2931  /*
2932  * Create the section
2933  */
2938  NULL,
2939  sizeof(ROS_SECTION_OBJECT),
2940  0,
2941  0,
2942  (PVOID*)&Section);
2943  if (!NT_SUCCESS(Status))
2944  {
2946  return(Status);
2947  }
2948  /*
2949  * Initialize it
2950  */
2951  RtlZeroMemory(Section, sizeof(ROS_SECTION_OBJECT));
2952  Section->Type = 'SC';
2953  Section->Size = 'TN';
2956 
2957  /*
2958  * FIXME: This is propably not entirely correct. We can't look into
2959  * the standard FCB header because it might not be initialized yet
2960  * (as in case of the EXT2FS driver by Manoj Paul Joseph where the
2961  * standard file information is filled on first request).
2962  */
2965  sizeof(FILE_STANDARD_INFORMATION),
2966  &FileInfo,
2967  &Length);
2968  if (!NT_SUCCESS(Status))
2969  {
2970  ObDereferenceObject(Section);
2972  return Status;
2973  }
2974 
2975  /*
2976  * FIXME: Revise this once a locking order for file size changes is
2977  * decided
2978  */
2979  if ((UMaximumSize != NULL) && (UMaximumSize->QuadPart != 0))
2980  {
2981  MaximumSize = *UMaximumSize;
2982  }
2983  else
2984  {
2985  MaximumSize = FileInfo.EndOfFile;
2986  /* Mapping zero-sized files isn't allowed. */
2987  if (MaximumSize.QuadPart == 0)
2988  {
2989  ObDereferenceObject(Section);
2992  }
2993  }
2994 
2995  if (MaximumSize.QuadPart > FileInfo.EndOfFile.QuadPart)
2996  {
2999  sizeof(LARGE_INTEGER),
3000  &MaximumSize);
3001  if (!NT_SUCCESS(Status))
3002  {
3003  ObDereferenceObject(Section);
3006  }
3007  }
3008 
3009  if (FileObject->SectionObjectPointer == NULL ||
3010  FileObject->SectionObjectPointer->SharedCacheMap == NULL)
3011  {
3012  ObDereferenceObject(Section);
3015  }
3016 
3017  /*
3018  * Lock the file
3019  */
3021  if (Status != STATUS_SUCCESS)
3022  {
3023  ObDereferenceObject(Section);
3025  return(Status);
3026  }
3027 
3028  /*
3029  * If this file hasn't been mapped as a data file before then allocate a
3030  * section segment to describe the data file mapping
3031  */
3032  if (FileObject->SectionObjectPointer->DataSectionObject == NULL)
3033  {
3036  if (Segment == NULL)
3037  {
3038  //KeSetEvent((PVOID)&FileObject->Lock, IO_NO_INCREMENT, FALSE);
3039  ObDereferenceObject(Section);
3041  return(STATUS_NO_MEMORY);
3042  }
3043  Section->Segment = Segment;
3044  Segment->ReferenceCount = 1;
3046  /*
3047  * Set the lock before assigning the segment to the file object
3048  */
3049  ExAcquireFastMutex(&Segment->Lock);
3050  FileObject->SectionObjectPointer->DataSectionObject = (PVOID)Segment;
3051 
3052  Segment->Image.FileOffset = 0;
3053  Segment->Protection = SectionPageProtection;
3054  Segment->Flags = MM_DATAFILE_SEGMENT;
3055  Segment->Image.Characteristics = 0;
3058  {
3059  Segment->Length.QuadPart = Segment->RawLength.QuadPart = 0;
3060  }
3061  else
3062  {
3063  Segment->RawLength.QuadPart = MaximumSize.QuadPart;
3064  Segment->Length.QuadPart = PAGE_ROUND_UP(Segment->RawLength.QuadPart);
3065  }
3066  Segment->Image.VirtualAddress = 0;
3067  Segment->Locked = TRUE;
3069  }
3070  else
3071  {
3072  /*
3073  * If the file is already mapped as a data file then we may need
3074  * to extend it
3075  */
3076  Segment =
3077  (PMM_SECTION_SEGMENT)FileObject->SectionObjectPointer->
3078  DataSectionObject;
3079  Section->Segment = Segment;
3080  (void)InterlockedIncrementUL(&Segment->ReferenceCount);
3082 
3083  if (MaximumSize.QuadPart > Segment->RawLength.QuadPart &&
3085  {
3086  Segment->RawLength.QuadPart = MaximumSize.QuadPart;
3087  Segment->Length.QuadPart = PAGE_ROUND_UP(Segment->RawLength.QuadPart);
3088  }
3089  }
3091  Section->FileObject = FileObject;
3092  Section->MaximumSize = MaximumSize;
3093 #ifndef NEWCC
3095 #endif
3096  //KeSetEvent((PVOID)&FileObject->Lock, IO_NO_INCREMENT, FALSE);
3097  *SectionObject = Section;
3098  return(STATUS_SUCCESS);
3099 }
_Must_inspect_result_ _Outptr_ PVOID * SectionObject
Definition: fsrtlfuncs.h:860
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define TRUE
Definition: types.h:120
LARGE_INTEGER MaximumSize
Definition: mm.h:196
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ ULONG AllocationAttributes
Definition: mmfuncs.h:360
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
#define PAGE_ROUND_UP(x)
Definition: scsiport_int.h:13
NTSTATUS NTAPI IoQueryFileInformation(IN PFILE_OBJECT FileObject, IN FILE_INFORMATION_CLASS FileInformationClass, IN ULONG Length, OUT PVOID FileInformation, OUT PULONG ReturnedLength)
Definition: iofunc.c: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:593
_Inout_ PVOID Segment
Definition: exfuncs.h:893
NTSTATUS NTAPI ObCreateObject(IN KPROCESSOR_MODE ProbeMode OPTIONAL, IN POBJECT_TYPE Type, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN KPROCESSOR_MODE AccessMode, IN OUT PVOID ParseContext OPTIONAL, IN ULONG ObjectSize, IN ULONG PagedPoolCharge OPTIONAL, IN ULONG NonPagedPoolCharge OPTIONAL, OUT PVOID *Object)
Definition: oblife.c: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:255
_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
NTSTATUS MmspWaitForFileLock(PFILE_OBJECT File)
Definition: section.c:799
VOID NTAPI MiInitializeSectionPageTable(PMM_SECTION_SEGMENT Segment)
Definition: sptab.c:165
Status
Definition: gdiplustypes.h:24
VOID FASTCALL ExAcquireFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:23
#define TAG_MM_SECTION_SEGMENT
Definition: tag.h:139
#define InterlockedIncrementUL(Addend)
Definition: ex.h:1513
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
ULONG SectionPageProtection
Definition: mm.h:197
#define STATUS_SECTION_NOT_EXTENDED
Definition: ntstatus.h:357
#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:261
CSHORT Size
Definition: mm.h:195
ULONG AllocationAttributes
Definition: mm.h:198
#define STATUS_MAPPED_FILE_SIZE_ZERO
Definition: ntstatus.h:508
#define MmUnlockSectionSegment(x)
Definition: newmm.h:284
PMM_SECTION_SEGMENT Segment
Definition: mm.h:203
return STATUS_SUCCESS
Definition: btrfs.c:2938
LONGLONG QuadPart
Definition: typedefs.h:112

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

3737 {
3738  PROS_SECTION_OBJECT Section;
3739  NTSTATUS Status;
3740  PMM_SECTION_SEGMENT SectionSegments;
3741  PMM_IMAGE_SECTION_OBJECT ImageSectionObject;
3742  ULONG i;
3743 
3744  if (FileObject == NULL)
3746 
3747 #ifndef NEWCC
3748  if (!CcIsFileCached(FileObject))
3749  {
3750  DPRINT1("Denying section creation due to missing cache initialization\n");
3752  }
3753 #endif
3754 
3755  /*
3756  * Create the section
3757  */
3762  NULL,
3763  sizeof(ROS_SECTION_OBJECT),
3764  0,
3765  0,
3766  (PVOID*)(PVOID)&Section);
3767  if (!NT_SUCCESS(Status))
3768  {
3770  return(Status);
3771  }
3772 
3773  /*
3774  * Initialize it
3775  */
3776  RtlZeroMemory(Section, sizeof(ROS_SECTION_OBJECT));
3777  Section->Type = 'SC';
3778  Section->Size = 'TN';
3781 
3782  if (FileObject->SectionObjectPointer->ImageSectionObject == NULL)
3783  {
3784  NTSTATUS StatusExeFmt;
3785 
3787  if (ImageSectionObject == NULL)
3788  {
3790  ObDereferenceObject(Section);
3791  return(STATUS_NO_MEMORY);
3792  }
3793 
3794  RtlZeroMemory(ImageSectionObject, sizeof(MM_IMAGE_SECTION_OBJECT));
3795 
3796  StatusExeFmt = ExeFmtpCreateImageSection(FileObject, ImageSectionObject);
3797 
3798  if (!NT_SUCCESS(StatusExeFmt))
3799  {
3800  if(ImageSectionObject->Segments != NULL)
3801  ExFreePool(ImageSectionObject->Segments);
3802 
3803  /*
3804  * If image file is empty, then return that the file is invalid for section
3805  */
3806  Status = StatusExeFmt;
3807  if (StatusExeFmt == STATUS_END_OF_FILE)
3808  {
3810  }
3811 
3812  ExFreePoolWithTag(ImageSectionObject, TAG_MM_SECTION_SEGMENT);
3813  ObDereferenceObject(Section);
3815  return(Status);
3816  }
3817 
3818  Section->ImageSection = ImageSectionObject;
3819  ASSERT(ImageSectionObject->Segments);
3820 
3821  /*
3822  * Lock the file
3823  */
3825  if (!NT_SUCCESS(Status))
3826  {
3827  ExFreePool(ImageSectionObject->Segments);
3828  ExFreePool(ImageSectionObject);
3829  ObDereferenceObject(Section);
3831  return(Status);
3832  }
3833 
3834  if (NULL != InterlockedCompareExchangePointer(&FileObject->SectionObjectPointer->ImageSectionObject,
3835  ImageSectionObject, NULL))
3836  {
3837  /*
3838  * An other thread has initialized the same image in the background
3839  */
3840  ExFreePool(ImageSectionObject->Segments);
3841  ExFreePool(ImageSectionObject);
3842  ImageSectionObject = FileObject->SectionObjectPointer->ImageSectionObject;
3843  Section->ImageSection = ImageSectionObject;
3844  SectionSegments = ImageSectionObject->Segments;
3845 
3846  for (i = 0; i < ImageSectionObject->NrSegments; i++)
3847  {
3848  (void)InterlockedIncrementUL(&SectionSegments[i].ReferenceCount);
3849  }
3850  }
3851 
3852  Status = StatusExeFmt;
3853  }
3854  else
3855  {
3856  /*
3857  * Lock the file
3858  */
3860  if (Status != STATUS_SUCCESS)
3861  {
3862  ObDereferenceObject(Section);
3864  return(Status);
3865  }
3866 
3867  ImageSectionObject = FileObject->SectionObjectPointer->ImageSectionObject;
3868  Section->ImageSection = ImageSectionObject;
3869  SectionSegments = ImageSectionObject->Segments;
3870 
3871  /*
3872  * Otherwise just reference all the section segments
3873  */
3874  for (i = 0; i < ImageSectionObject->NrSegments; i++)
3875  {
3876  (void)InterlockedIncrementUL(&SectionSegments[i].ReferenceCount);
3877  }
3878 
3880  }
3881  Section->FileObject = FileObject;
3882 #ifndef NEWCC
3884 #endif
3885  //KeSetEvent((PVOID)&FileObject->Lock, IO_NO_INCREMENT, FALSE);
3886  *SectionObject = Section;
3887  return(Status);
3888 }
_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:3583
_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:593
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:255
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
NTSTATUS MmspWaitForFileLock(PFILE_OBJECT File)
Definition: section.c:799
Status
Definition: gdiplustypes.h:24
#define TAG_MM_SECTION_SEGMENT
Definition: tag.h:139
#define InterlockedIncrementUL(Addend)
Definition: ex.h:1513
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
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:261
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:2938
#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 2838 of file section.c.

2847 {
2849  PROS_SECTION_OBJECT Section;
2851  NTSTATUS Status;
2852 
2853  if (UMaximumSize == NULL)
2854  {
2855  DPRINT1("MmCreatePageFileSection: (UMaximumSize == NULL)\n");
2856  return(STATUS_INVALID_PARAMETER);
2857  }
2858  MaximumSize = *UMaximumSize;
2859 
2860  /*
2861  * Create the section
2862  */
2867  NULL,
2868  sizeof(ROS_SECTION_OBJECT),
2869  0,
2870  0,
2871  (PVOID*)(PVOID)&Section);
2872  if (!NT_SUCCESS(Status))
2873  {
2874  DPRINT1("MmCreatePageFileSection: failed to create object (0x%lx)\n", Status);
2875  return(Status);
2876  }
2877 
2878  /*
2879  * Initialize it
2880  */
2881  RtlZeroMemory(Section, sizeof(ROS_SECTION_OBJECT));
2882  Section->Type = 'SC';
2883  Section->Size = 'TN';
2886  Section->MaximumSize = MaximumSize;
2889  if (Segment == NULL)
2890  {
2891  ObDereferenceObject(Section);
2892  return(STATUS_NO_MEMORY);
2893  }
2895  Section->Segment = Segment;
2896  Segment->ReferenceCount = 1;
2898  Segment->Image.FileOffset = 0;
2899  Segment->Protection = SectionPageProtection;
2900  Segment->RawLength.QuadPart = MaximumSize.u.LowPart;
2901  Segment->Length.QuadPart = PAGE_ROUND_UP(MaximumSize.u.LowPart);
2902  Segment->Flags = MM_PAGEFILE_SEGMENT;
2903  Segment->WriteCopy = FALSE;
2904  Segment->Image.VirtualAddress = 0;
2905  Segment->Image.Characteristics = 0;
2906  *SectionObject = Section;
2908  return(STATUS_SUCCESS);
2909 }
_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
#define PAGE_ROUND_UP(x)
Definition: scsiport_int.h:13
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_opt_ PLARGE_INTEGER _In_ ULONG SectionPageProtection
Definition: mmfuncs.h:360
smooth NULL
Definition: ftsmooth.c:416
_Inout_ PVOID Segment
Definition: exfuncs.h:893
NTSTATUS NTAPI ObCreateObject(IN KPROCESSOR_MODE ProbeMode OPTIONAL, IN POBJECT_TYPE Type, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN KPROCESSOR_MODE AccessMode, IN OUT PVOID ParseContext OPTIONAL, IN ULONG ObjectSize, IN ULONG PagedPoolCharge OPTIONAL, IN ULONG NonPagedPoolCharge OPTIONAL, OUT PVOID *Object)
Definition: oblife.c: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
VOID NTAPI MiInitializeSectionPageTable(PMM_SECTION_SEGMENT Segment)
Definition: sptab.c:165
Status
Definition: gdiplustypes.h:24
#define TAG_MM_SECTION_SEGMENT
Definition: tag.h:139
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
ULONG SectionPageProtection
Definition: mm.h:197
_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:261
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:2938

Referenced by MmCreateSection().

◆ MmCreatePhysicalMemorySection()

NTSTATUS INIT_FUNCTION NTAPI MmCreatePhysicalMemorySection ( VOID  )

Definition at line 2755 of file section.c.

2756 {
2757  PROS_SECTION_OBJECT PhysSection;
2758  NTSTATUS Status;
2760  UNICODE_STRING Name = RTL_CONSTANT_STRING(L"\\Device\\PhysicalMemory");
2761  LARGE_INTEGER SectionSize;
2762  HANDLE Handle;
2763 
2764  /*
2765  * Create the section mapping physical memory
2766  */
2767  SectionSize.QuadPart = 0xFFFFFFFF;
2769  &Name,
2771  NULL,
2772  NULL);
2773  Status = MmCreateSection((PVOID)&PhysSection,
2775  &Obj,
2776  &SectionSize,
2779  NULL,
2780  NULL);
2781  if (!NT_SUCCESS(Status))
2782  {
2783  DPRINT1("Failed to create PhysicalMemory section\n");
2784  KeBugCheck(MEMORY_MANAGEMENT);
2785  }
2786  Status = ObInsertObject(PhysSection,
2787  NULL,
2789  0,
2790  NULL,
2791  &Handle);
2792  if (!NT_SUCCESS(Status))
2793  {
2794  ObDereferenceObject(PhysSection);
2795  }
2797  PhysSection->AllocationAttributes |= SEC_PHYSICALMEMORY;
2798  PhysSection->Segment->Flags &= ~MM_PAGEFILE_SEGMENT;
2799 
2800  return(STATUS_SUCCESS);
2801 }
LONG NTSTATUS
Definition: precomp.h:26
#define OBJ_PERMANENT
Definition: winternl.h:226
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
#define SECTION_ALL_ACCESS
Definition: nt_native.h:1293
smooth NULL
Definition: ftsmooth.c:416
VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1507
_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:4975
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
static const WCHAR L[]
Definition: oid.c:1250
#define SEC_PHYSICALMEMORY
Definition: mm.h:88
Status
Definition: gdiplustypes.h:24
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:2938
LONGLONG QuadPart
Definition: typedefs.h:112
#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 4975 of file section.c.

4983 {
4984  NTSTATUS Status;
4985  ULONG Protection;
4987 
4988  /* Check if an ARM3 section is being created instead */
4990  {
4991  if (!(FileObject) && !(FileHandle))
4992  {
4993  return MmCreateArm3Section(Section,
4994  DesiredAccess,
4996  MaximumSize,
4998  AllocationAttributes &~ 1,
4999  FileHandle,
5000  FileObject);
5001  }
5002  }
5003 
5004  /* Convert section flag to page flag */
5006 
5007  /* Check to make sure the protection is correct. Nt* does this already */
5009  if (Protection == MM_INVALID_PROTECTION)
5010  {
5011  DPRINT1("Page protection is invalid\n");
5013  }
5014 
5015  /* Check if this is going to be a data or image backed file section */
5016  if ((FileHandle) || (FileObject))
5017  {
5018  /* These cannot be mapped with large pages */
5020  {
5021  DPRINT1("Large pages cannot be used with an image mapping\n");
5023  }
5024 
5025  /* Did the caller pass an object? */
5026  if (FileObject)
5027  {
5028  /* Reference the object directly */
5030  }
5031  else
5032  {
5033  /* Reference the file handle to get the object */
5035  MmMakeFileAccess[Protection],
5038  (PVOID*)&FileObject,
5039  NULL);
5040  if (!NT_SUCCESS(Status))
5041  {
5042  DPRINT1("Failed to get a handle to the FO: %lx\n", Status);
5043  return Status;
5044  }
5045  }
5046  }
5047  else
5048  {
5049  /* A handle must be supplied with SEC_IMAGE, as this is the no-handle path */
5051  }
5052 
5053 #ifndef NEWCC // A hack for initializing caching.
5054  // This is needed only in the old case.
5055  if (FileHandle)
5056  {
5058  NTSTATUS Status;
5059  CHAR Buffer;
5061  ByteOffset.QuadPart = 0;
5062  Status = ZwReadFile(FileHandle,
5063  NULL,
5064  NULL,
5065  NULL,
5066  &Iosb,
5067  &Buffer,
5068  sizeof(Buffer),
5069  &ByteOffset,
5070  NULL);
5072  {
5073  DPRINT1("CC failure: %lx\n", Status);
5074  if (FileObject)
5076  return Status;
5077  }
5078  // Caching is initialized...
5079 
5080  // Hack of the hack: actually, it might not be initialized if FSD init on effective right and if file is null-size
5081  // In such case, force cache by initiating a write IRP
5083  (FileObject->SectionObjectPointer == NULL || FileObject->SectionObjectPointer->SharedCacheMap == NULL))
5084  {
5085  Buffer = 0xdb;
5086  Status = ZwWriteFile(FileHandle,
5087  NULL,
5088  NULL,
5089  NULL,
5090  &Iosb,
5091  &Buffer,
5092  sizeof(Buffer),
5093  &ByteOffset,
5094  NULL);
5095  if (NT_SUCCESS(Status))
5096  {
5098  Zero.QuadPart = 0LL;
5099 
5102  sizeof(LARGE_INTEGER),
5103  &Zero);
5105  }
5106  }
5107  }
5108 #endif
5109 
5111  {
5113  DesiredAccess,
5115  MaximumSize,
5118  FileObject);
5119  }
5120 #ifndef NEWCC
5121  else if (FileHandle != NULL)
5122  {
5124  DesiredAccess,
5126  MaximumSize,
5129  FileObject);
5130  }
5131 #else
5132  else if (FileHandle != NULL || FileObject != NULL)
5133  {
5135  DesiredAccess,
5137  MaximumSize,
5140  FileObject);
5141  }
5142 #endif
5143  else
5144  {
5146  {
5147  DPRINT1("Invalid path: %lx %p %p\n", AllocationAttributes, FileObject, FileHandle);
5148  }
5149 // ASSERT(AllocationAttributes & SEC_PHYSICALMEMORY);
5151  DesiredAccess,
5153  MaximumSize,
5156  if (FileObject)
5158  }
5159 
5160  return Status;
5161 }
_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:71
#define LL
Definition: tui.h:85
#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:593
return Iosb
Definition: create.c:4426
#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:2838
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:3730
#define STATUS_INVALID_FILE_FOR_SECTION
Definition: ntstatus.h:255
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define SEC_PHYSICALMEMORY
Definition: mm.h:88
#define STATUS_INVALID_PAGE_PROTECTION
Definition: ntstatus.h:291
POBJECT_TYPE IoFileObjectType
Definition: iomgr.c:36
Status
Definition: gdiplustypes.h:24
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:2913
_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:4157
#define STATUS_INVALID_PARAMETER_6
Definition: ntstatus.h:466
_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:402
#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:716

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

4800 {
4801  BOOLEAN Result = TRUE;
4802 #ifdef NEWCC
4804 #endif
4805 
4806  switch(FlushType)
4807  {
4808  case MmFlushForDelete:
4809  if (SectionObjectPointer->ImageSectionObject ||
4810  SectionObjectPointer->DataSectionObject)
4811  {
4812  return FALSE;
4813  }
4814 #ifndef NEWCC
4816 #endif
4817  return TRUE;
4818  case MmFlushForWrite:
4819  {
4820  DPRINT("MmFlushImageSection(%d)\n", FlushType);
4821 #ifdef NEWCC
4822  Segment = (PMM_SECTION_SEGMENT)SectionObjectPointer->DataSectionObject;
4823 #endif
4824 
4825  if (SectionObjectPointer->ImageSectionObject)
4826  {
4827  DPRINT1("SectionObject has ImageSection\n");
4828  return FALSE;
4829  }
4830 
4831 #ifdef NEWCC
4832  CcpLock();
4833  Result = !SectionObjectPointer->SharedCacheMap || (Segment->ReferenceCount == CcpCountCacheSections((PNOCC_CACHE_MAP)SectionObjectPointer->SharedCacheMap));
4834  CcpUnlock();
4835  DPRINT("Result %d\n", Result);
4836 #endif
4837  return Result;
4838  }
4839  }
4840  return FALSE;
4841 }
#define TRUE
Definition: types.h:120
#define CcpLock()
Definition: newcc.h:143
_Must_inspect_result_ _In_ PDEVICE_OBJECT _In_ PSECTION_OBJECT_POINTERS SectionObjectPointer
Definition: fsrtlfuncs.h:1368
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:1071
_Inout_ PVOID Segment
Definition: exfuncs.h:893
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:270
#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 3970 of file section.c.

3972 {
3973  ULONG_PTR Entry;
3974 #ifndef NEWCC
3976  PROS_SHARED_CACHE_MAP SharedCacheMap;
3977 #endif
3979  SWAPENTRY SavedSwapEntry;
3980  PROS_SECTION_OBJECT Section;
3984 
3987 
3989 
3991  MemoryArea->Data.SectionData.ViewOffset.QuadPart;
3992 
3993  Section = MemoryArea->Data.SectionData.Section;
3994  Segment = MemoryArea->Data.SectionData.Segment;
3995 
3997  while (Entry && MM_IS_WAIT_PTE(Entry))
3998  {
4001 
4003 
4007  }
4008 
4009  /*
4010  * For a dirty, datafile, non-private page mark it as dirty in the
4011  * cache manager.
4012  */
4013  if (Segment->Flags & MM_DATAFILE_SEGMENT)
4014  {
4015  if (Page == PFN_FROM_SSE(Entry) && Dirty)
4016  {
4017 #ifndef NEWCC
4018  FileObject = MemoryArea->Data.SectionData.Section->FileObject;
4019  SharedCacheMap = FileObject->SectionObjectPointer->SharedCacheMap;
4020  CcRosMarkDirtyFile(SharedCacheMap, Offset.QuadPart + Segment->Image.FileOffset);
4021 #endif
4022  ASSERT(SwapEntry == 0);
4023  }
4024  }
4025 
4026  if (SwapEntry != 0)
4027  {
4028  /*
4029  * Sanity check
4030  */
4031  if (Segment->Flags & MM_PAGEFILE_SEGMENT)
4032  {
4033  DPRINT1("Found a swap entry for a page in a pagefile section.\n");
4034  KeBugCheck(MEMORY_MANAGEMENT);
4035  }
4036  MmFreeSwapPage(SwapEntry);
4037  }
4038  else if (Page != 0)
4039  {
4040  if (IS_SWAP_FROM_SSE(Entry) ||
4041  Page != PFN_FROM_SSE(Entry))
4042  {
4043  /*
4044  * Sanity check
4045  */
4046  if (Segment->Flags & MM_PAGEFILE_SEGMENT)
4047  {
4048  DPRINT1("Found a private page in a pagefile section.\n");
4049  KeBugCheck(MEMORY_MANAGEMENT);
4050  }
4051  /*
4052  * Just dereference private pages
4053  */
4054  SavedSwapEntry = MmGetSavedSwapEntryPage(Page);
4055  if (SavedSwapEntry != 0)
4056  {
4057  MmFreeSwapPage(SavedSwapEntry);
4058  MmSetSavedSwapEntryPage(Page, 0);
4059  }
4060  MmDeleteRmap(Page, Process, Address);
4062  }
4063  else
4064  {
4065  MmDeleteRmap(Page, Process, Address);
4067  }
4068  }
4069 }
struct _Entry Entry
Definition: kefuncs.h:640
#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:63
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
union _MEMORY_AREA::@1743 Data
BOOLEAN NTAPI MmUnsharePageEntrySectionSegment(PROS_SECTION_OBJECT Section, PMM_SECTION_SEGMENT Segment, PLARGE_INTEGER Offset, BOOLEAN Dirty, BOOLEAN PageOut, ULONG_PTR *InEntry)
Definition: section.c:879
smooth NULL
Definition: ftsmooth.c:416
static WCHAR Address[46]
Definition: ping.c:68
VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1507
void * PVOID
Definition: retypes.h:9
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
_Inout_ PVOID Segment
Definition: exfuncs.h:893
struct _MMSUPPORT * PMMSUPPORT
struct _MEMORY_AREA::@1743::@1744 SectionData
#define MM_DATAFILE_SEGMENT
Definition: mm.h:91
* PFILE_OBJECT
Definition: iotypes.h:1955
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
#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 807 of file section.c.

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

NTSTATUS INIT_FUNCTION NTAPI MmInitSectionImplementation ( VOID  )

Definition at line 2806 of file section.c.

2807 {
2808  OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;
2810 
2811  DPRINT("Creating Section Object Type\n");
2812 
2813  /* Initialize the section based root */
2816 
2817  /* Initialize the Section object type */
2818  RtlZeroMemory(&ObjectTypeInitializer, sizeof(ObjectTypeInitializer));
2819  RtlInitUnicodeString(&Name, L"Section");
2820  ObjectTypeInitializer.Length = sizeof(ObjectTypeInitializer);
2821  ObjectTypeInitializer.DefaultPagedPoolCharge = sizeof(ROS_SECTION_OBJECT);
2822  ObjectTypeInitializer.PoolType = PagedPool;
2823  ObjectTypeInitializer.UseDefaultObject = TRUE;
2824  ObjectTypeInitializer.GenericMapping = MmpSectionMapping;
2825  ObjectTypeInitializer.DeleteProcedure = MmpDeleteSection;
2826  ObjectTypeInitializer.CloseProcedure = MmpCloseSection;
2827  ObjectTypeInitializer.ValidAccessMask = SECTION_ALL_ACCESS;
2828  ObjectTypeInitializer.InvalidAttributes = OBJ_OPENLINK;
2829  ObCreateObjectType(&Name, &ObjectTypeInitializer, NULL, &MmSectionObjectType);
2830 
2832 
2833  return(STATUS_SUCCESS);
2834 }
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:2743
ULONG_PTR NumberGenericTableElements
Definition: mmtypes.h:668
MM_AVL_TABLE MmSectionBasedRoot
Definition: section.c:109
#define OBJ_OPENLINK
Definition: winternl.h:230
MMADDRESS_NODE BalancedRoot
Definition: mmtypes.h:662
union _MMADDRESS_NODE::@2513 u1
#define SECTION_ALL_ACCESS
Definition: nt_native.h:1293
static GENERIC_MAPPING MmpSectionMapping
Definition: section.c:166
struct NameRec_ * Name
Definition: cdprocs.h:464
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)
NTSTATUS INIT_FUNCTION NTAPI MmCreatePhysicalMemorySection(VOID)
Definition: section.c:2755
static const WCHAR L[]
Definition: oid.c:1250
VOID NTAPI MmpDeleteSection(PVOID ObjectBody)
Definition: section.c:2644
GENERIC_MAPPING GenericMapping
Definition: obtypes.h:358
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
return STATUS_SUCCESS
Definition: btrfs.c:2938
OB_DELETE_METHOD DeleteProcedure
Definition: obtypes.h:369
struct _MMADDRESS_NODE * Parent
Definition: mmtypes.h:649

Referenced by MmInitSystem().

◆ MmMapViewInSystemSpace()

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

Definition at line 4847 of file section.c.

4850 {
4851  PROS_SECTION_OBJECT Section;
4853  NTSTATUS Status;
4854  PAGED_CODE();
4855 
4857  {
4859  &MmSession,
4860  MappedBase,
4861  ViewSize);
4862  }
4863 
4864  DPRINT("MmMapViewInSystemSpace() called\n");
4865 
4868 
4870 
4871 
4872  if ((*ViewSize) == 0)
4873  {
4874  (*ViewSize) = Section->MaximumSize.u.LowPart;
4875  }
4876  else if ((*ViewSize) > Section->MaximumSize.u.LowPart)
4877  {
4878  (*ViewSize) = Section->MaximumSize.u.LowPart;
4879  }
4880 
4881  MmLockSectionSegment(Section->Segment);
4882 
4883 
4885  Section,
4886  Section->Segment,
4887  MappedBase,
4888  *ViewSize,
4890  0,
4891  0);
4892 
4893  MmUnlockSectionSegment(Section->Segment);
4895 
4896  return Status;
4897 }
struct _LARGE_INTEGER::@2220 u
_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:3893
#define PAGED_CODE()
Definition: video.h:57
void DPRINT(...)
Definition: polytest.cpp:61
struct _ROS_SECTION_OBJECT * PROS_SECTION_OBJECT
NTSTATUS NTAPI MiMapViewInSystemSpace(IN PVOID Section, IN PMMSESSION Session, OUT PVOID *MappedBase, IN OUT PSIZE_T ViewSize)
Definition: section.c:1052
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:493
#define MmLockSectionSegment(x)
Definition: newmm.h:276
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T _Inout_opt_ PLARGE_INTEGER _Inout_ PSIZE_T ViewSize
Definition: mmfuncs.h:404
#define MmUnlockSectionSegment(x)
Definition: newmm.h:284
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
FORCEINLINE BOOLEAN MiIsRosSectionObject(IN PVOID Section)
Definition: miarm.h:1071
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:71
#define TRUE
Definition: types.h:120
KAPC_STATE
Definition: ketypes.h:1273
BOOLEAN NTAPI MiIsProtectionCompatible(IN ULONG SectionPageProtection, IN ULONG NewSectionPageProtection)
Definition: section.c:117
PSEGMENT Segment
Definition: mmtypes.h:812
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
_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:464
ULONG InitialPageProtection
Definition: mmtypes.h:819
LONG NTSTATUS
Definition: precomp.h:26
#define PAGED_CODE()
Definition: video.h:57
struct _CONTROL_AREA * ControlArea
Definition: mmtypes.h:400
uint32_t ULONG_PTR
Definition: typedefs.h:63
static BOOL Attached
Definition: vidbios.c:3905
VOID NTAPI KeStackAttachProcess(IN PKPROCESS Process, OUT PRKAPC_STATE ApcState)
Definition: procobj.c:701
LARGE_INTEGER SizeOfSection
Definition: mmtypes.h:813
#define MEM_RESERVE
Definition: nt_native.h:1314
#define PsGetCurrentProcess
Definition: psfuncs.h:17
unsigned char BOOLEAN
struct _SECTION * PSECTION
union _SECTION::@2524 u
_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:465
_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:300
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
unsigned __int64 ULONG64
Definition: imports.h:198
MMSECTION_FLAGS Flags
Definition: mmtypes.h:817
#define STATUS_INVALID_PAGE_PROTECTION
Definition: ntstatus.h:291
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T _Inout_opt_ PLARGE_INTEGER _Inout_ PSIZE_T _In_ SECTION_INHERIT _In_ ULONG AllocationType
Definition: mmfuncs.h:404
Status
Definition: gdiplustypes.h:24
#define PAGE_WRITECOMBINE
Definition: mmtypes.h:78
#define STATUS_INVALID_VIEW_SIZE
Definition: ntstatus.h:254
VOID NTAPI KeUnstackDetachProcess(IN PRKAPC_STATE ApcState)
Definition: procobj.c:753
#define STATUS_INVALID_PARAMETER_10
Definition: ntstatus.h:470
_Out_ PKAPC_STATE ApcState
Definition: mm.h:1492
#define DPRINT1
Definition: precomp.h:8
#define MM_HIGHEST_VAD_ADDRESS
Definition: mm.h:43
_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:522
unsigned int ULONG
Definition: retypes.h:1
union _CONTROL_AREA::@2508 u
NTSTATUS NTAPI MiMapViewOfDataSection(IN PCONTROL_AREA ControlArea, IN PEPROCESS Process, IN PVOID *BaseAddress, IN PLARGE_INTEGER SectionOffset, IN PSIZE_T ViewSize, IN PSECTION Section, IN SECTION_INHERIT InheritDisposition, IN ULONG ProtectionMask, IN SIZE_T CommitSize, IN ULONG_PTR ZeroBits, IN ULONG AllocationType)
Definition: section.c:1252
ULONG WriteCombined
Definition: mmtypes.h:484
LONGLONG QuadPart
Definition: typedefs.h:112

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

4512 {
4513  PROS_SECTION_OBJECT Section;
4515  ULONG ViewOffset;
4517  BOOLEAN NotAtBase = FALSE;
4518 
4520  {
4521  DPRINT("Mapping ARM3 section into %s\n", Process->ImageFileName);
4523  Process,
4524  BaseAddress,
4525  ZeroBits,
4526  CommitSize,
4527  SectionOffset,
4528  ViewSize,
4531  Protect);
4532  }
4533 
4534  ASSERT(Process);
4535