ReactOS  0.4.11-dev-195-gef016bf
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)
 
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)
 
static VOID MmAlterViewAttributes (PMMSUPPORT AddressSpace, PVOID BaseAddress, SIZE_T RegionSize, ULONG OldType, ULONG OldProtect, ULONG NewType, ULONG NewProtect)
 
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

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

Referenced by PeFmtCreateSection().

#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)
NTSTATUS NTAPI _MmSetPageEntrySectionSegment(PMM_SECTION_SEGMENT Segment, PLARGE_INTEGER Offset, ULONG_PTR Entry, const char *file, int line)
Definition: sptab.c:178
static const WCHAR O[]
Definition: oid.c:1088
Definition: movable.cpp:7
void DPRINT(...)
Definition: polytest.cpp:61
static const WCHAR E[]
Definition: oid.c:1090

Definition at line 62 of file section.c.

Referenced by MmNotPresentFaultSectionView(), MmPageOutSectionView(), MmpFreePageFileSegment(), MmSharePageEntrySectionSegment(), MmUnsharePageEntrySectionSegment(), and MmWritePageSectionView().

#define NDEBUG

Definition at line 50 of file section.c.

Function Documentation

C_ASSERT ( EXEFMT_LOAD_HEADER_SIZE >=  sizeofIMAGE_DOS_HEADER)
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, MinorSubsystemVersion)  )
C_ASSERT ( PEFMT_FIELDS_EQUAL(IMAGE_OPTIONAL_HEADER32, IMAGE_OPTIONAL_HEADER64, MajorSubsystemVersion)  )
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

Definition at line 3112 of file section.c.

Referenced by ExeFmtpCreateImageSection().

3113 {
3114  SIZE_T SizeOfSegments;
3115  PMM_SECTION_SEGMENT Segments;
3116 
3117  /* TODO: check for integer overflow */
3118  SizeOfSegments = sizeof(MM_SECTION_SEGMENT) * NrSegments;
3119 
3121  SizeOfSegments,
3123 
3124  if(Segments)
3125  RtlZeroMemory(Segments, SizeOfSegments);
3126 
3127  return Segments;
3128 }
#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
NTSTATUS ExeFmtpCreateImageSection ( PFILE_OBJECT  FileObject,
PMM_IMAGE_SECTION_OBJECT  ImageSectionObject 
)

Definition at line 3554 of file section.c.

Referenced by MmCreateImageSection().

3556 {
3558  PVOID FileHeader;
3559  PVOID FileHeaderBuffer;
3561  ULONG Flags;
3562  ULONG OldNrSegments;
3563  NTSTATUS Status;
3564  ULONG i;
3565 
3566  /*
3567  * Read the beginning of the file (2 pages). Should be enough to contain
3568  * all (or most) of the headers
3569  */
3570  Offset.QuadPart = 0;
3571 
3572  Status = ExeFmtpReadFile (FileObject,
3573  &Offset,
3574  PAGE_SIZE * 2,
3575  &FileHeader,
3576  &FileHeaderBuffer,
3577  &FileHeaderSize);
3578 
3579  if (!NT_SUCCESS(Status))
3580  return Status;
3581 
3582  if (FileHeaderSize == 0)
3583  {
3584  ExFreePool(FileHeaderBuffer);
3585  return STATUS_UNSUCCESSFUL;
3586  }
3587 
3588  /*
3589  * Look for a loader that can handle this executable
3590  */
3591  for (i = 0; i < RTL_NUMBER_OF(ExeFmtpLoaders); ++ i)
3592  {
3593  RtlZeroMemory(ImageSectionObject, sizeof(*ImageSectionObject));
3594  Flags = 0;
3595 
3596  Status = ExeFmtpLoaders[i](FileHeader,
3598  FileObject,
3600  &Flags,
3603 
3604  if (!NT_SUCCESS(Status))
3605  {
3606  if (ImageSectionObject->Segments)
3607  {
3608  ExFreePool(ImageSectionObject->Segments);
3609  ImageSectionObject->Segments = NULL;
3610  }
3611  }
3612 
3613  if (Status != STATUS_ROS_EXEFMT_UNKNOWN_FORMAT)
3614  break;
3615  }
3616 
3617  ExFreePoolWithTag(FileHeaderBuffer, 'rXmM');
3618 
3619  /*
3620  * No loader handled the format
3621  */
3622  if (Status == STATUS_ROS_EXEFMT_UNKNOWN_FORMAT)
3623  {
3624  Status = STATUS_INVALID_IMAGE_NOT_MZ;
3625  ASSERT(!NT_SUCCESS(Status));
3626  }
3627 
3628  if (!NT_SUCCESS(Status))
3629  return Status;
3630 
3631  ASSERT(ImageSectionObject->Segments != NULL);
3632 
3633  /*
3634  * Some defaults
3635  */
3636  /* FIXME? are these values platform-dependent? */
3637  if (ImageSectionObject->ImageInformation.MaximumStackSize == 0)
3638  ImageSectionObject->ImageInformation.MaximumStackSize = 0x40000;
3639 
3640  if(ImageSectionObject->ImageInformation.CommittedStackSize == 0)
3641  ImageSectionObject->ImageInformation.CommittedStackSize = 0x1000;
3642 
3643  if(ImageSectionObject->BasedAddress == NULL)
3644  {
3645  if(ImageSectionObject->ImageInformation.ImageCharacteristics & IMAGE_FILE_DLL)
3646  ImageSectionObject->BasedAddress = (PVOID)0x10000000;
3647  else
3648  ImageSectionObject->BasedAddress = (PVOID)0x00400000;
3649  }
3650 
3651  /*
3652  * And now the fun part: fixing the segments
3653  */
3654 
3655  /* Sort them by virtual address */
3656  MmspSortSegments(ImageSectionObject, Flags);
3657 
3658  /* Ensure they don't overlap in memory */
3659  if (!MmspCheckSegmentBounds(ImageSectionObject, Flags))
3661 
3662  /* Ensure they are aligned */
3663  OldNrSegments = ImageSectionObject->NrSegments;
3664 
3665  if (!MmspPageAlignSegments(ImageSectionObject, Flags))
3667 
3668  /* Trim them if the alignment phase merged some of them */
3669  if (ImageSectionObject->NrSegments < OldNrSegments)
3670  {
3671  PMM_SECTION_SEGMENT Segments;
3672  SIZE_T SizeOfSegments;
3673 
3674  SizeOfSegments = sizeof(MM_SECTION_SEGMENT) * ImageSectionObject->NrSegments;
3675 
3676  Segments = ExAllocatePoolWithTag(PagedPool,
3677  SizeOfSegments,
3679 
3680  if (Segments == NULL)
3682 
3683  RtlCopyMemory(Segments, ImageSectionObject->Segments, SizeOfSegments);
3684  ExFreePool(ImageSectionObject->Segments);
3685  ImageSectionObject->Segments = Segments;
3686  }
3687 
3688  /* And finish their initialization */
3689  for ( i = 0; i < ImageSectionObject->NrSegments; ++ i )
3690  {
3691  ExInitializeFastMutex(&ImageSectionObject->Segments[i].Lock);
3692  ImageSectionObject->Segments[i].ReferenceCount = 1;
3693  MiInitializeSectionPageTable(&ImageSectionObject->Segments[i]);
3694  }
3695 
3696  ASSERT(NT_SUCCESS(Status));
3697  return Status;
3698 }
DWORD *typedef PVOID
Definition: winlogon.h:61
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
#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:3371
IN SIZE_T FileHeaderSize
Definition: exeformat.h:53
IN SIZE_T IN PVOID OUT PMM_IMAGE_SECTION_OBJECT ImageSectionObject
Definition: exeformat.h:53
static VOID NTAPI MmspSortSegments(IN OUT PMM_IMAGE_SECTION_OBJECT ImageSectionObject, IN ULONG Flags)
Definition: section.c:3294
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
GLenum GLclampf GLint i
Definition: glfuncs.h:14
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
smooth NULL
Definition: ftsmooth.c:416
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
static PMM_SECTION_SEGMENT NTAPI ExeFmtpAllocateSegments(IN ULONG NrSegments)
Definition: section.c:3112
#define STATUS_INVALID_IMAGE_NOT_MZ
Definition: ntstatus.h:525
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_INVALID_IMAGE_FORMAT
Definition: ntstatus.h:345
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
static PEXEFMT_LOADER ExeFmtpLoaders[]
Definition: section.c:3101
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:3133
#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:3320
LONGLONG QuadPart
Definition: typedefs.h:112
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 3133 of file section.c.

Referenced by ExeFmtpCreateImageSection().

3139 {
3140  NTSTATUS Status;
3142  ULONG AdjustOffset;
3143  ULONG OffsetAdjustment;
3144  ULONG BufferSize;
3145  ULONG UsedSize;
3146  PVOID Buffer;
3149 
3151 
3152  if(Length == 0)
3153  {
3154  KeBugCheck(MEMORY_MANAGEMENT);
3155  }
3156 
3157  FileOffset = *Offset;
3158 
3159  /* Negative/special offset: it cannot be used in this context */
3160  if(FileOffset.u.HighPart < 0)
3161  {
3162  KeBugCheck(MEMORY_MANAGEMENT);
3163  }
3164 
3165  AdjustOffset = PAGE_ROUND_DOWN(FileOffset.u.LowPart);
3166  OffsetAdjustment = FileOffset.u.LowPart - AdjustOffset;
3167  FileOffset.u.LowPart = AdjustOffset;
3168 
3169  BufferSize = Length + OffsetAdjustment;
3170  BufferSize = PAGE_ROUND_UP(BufferSize);
3171 
3172  /* Flush data since we're about to perform a non-cached read */
3173  CcFlushCache(FileObject->SectionObjectPointer,
3174  &FileOffset,
3175  BufferSize,
3176  &Iosb);
3177 
3178  /*
3179  * It's ok to use paged pool, because this is a temporary buffer only used in
3180  * the loading of executables. The assumption is that MmCreateSection is
3181  * always called at low IRQLs and that these buffers don't survive a brief
3182  * initialization phase
3183  */
3185  BufferSize,
3186  'rXmM');
3187  if (!Buffer)
3188  {
3190  }
3191 
3192  UsedSize = 0;
3193 
3194  Status = MiSimpleRead(FileObject, &FileOffset, Buffer, BufferSize, TRUE, &Iosb);
3195 
3196  UsedSize = (ULONG)Iosb.Information;
3197 
3198  if(NT_SUCCESS(Status) && UsedSize < OffsetAdjustment)
3199  {
3200  Status = STATUS_IN_PAGE_ERROR;
3201  ASSERT(!NT_SUCCESS(Status));
3202  }
3203 
3204  if(NT_SUCCESS(Status))
3205  {
3206  *Data = (PVOID)((ULONG_PTR)Buffer + OffsetAdjustment);
3207  *AllocBase = Buffer;
3208  *ReadSize = UsedSize - OffsetAdjustment;
3209  }
3210  else
3211  {
3212  ExFreePoolWithTag(Buffer, 'rXmM');
3213  }
3214 
3215  return Status;
3216 }
DWORD *typedef PVOID
Definition: winlogon.h:61
#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
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
#define PAGE_ROUND_DOWN(x)
Definition: mmtypes.h:36
IN SIZE_T IN PVOID File
Definition: exeformat.h:53
#define BufferSize
Definition: acefiex.h:377
#define PAGE_ROUND_UP(x)
Definition: scsiport_int.h:13
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
uint32_t ULONG_PTR
Definition: typedefs.h:63
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1469
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
IN PLARGE_INTEGER IN ULONG OUT PVOID OUT PVOID OUT PULONG ReadSize
Definition: exeformat.h:38
LONG NTSTATUS
Definition: precomp.h:26
return Iosb
Definition: create.c:4426
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
* PFILE_OBJECT
Definition: iotypes.h:1954
#define ASSERT_IRQL_LESS(x)
Definition: debug.h:253
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
VOID UINTN Length
Definition: acefiex.h:744
Status
Definition: gdiplustypes.h:24
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
_In_ PLARGE_INTEGER FileOffset
Definition: cctypes.h:53
struct _LARGE_INTEGER::@2192 u
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 PLARGE_INTEGER IN ULONG OUT PVOID OUT PVOID * AllocBase
Definition: exeformat.h:38
NTSTATUS NTAPI MiSimpleRead(PFILE_OBJECT FileObject, PLARGE_INTEGER FileOffset, PVOID Buffer, ULONG Length, BOOLEAN Paging, PIO_STATUS_BLOCK ReadStatus)
Definition: io.c:114
ACCESS_MASK NTAPI MiArm3GetCorrectFileAccessMask ( IN ACCESS_MASK  SectionPageProtection)

Definition at line 141 of file section.c.

142 {
143  ULONG ProtectionMask;
144 
145  /* Calculate the protection mask and make sure it's valid */
147  if (ProtectionMask == MM_INVALID_PROTECTION)
148  {
149  DPRINT1("Invalid protection mask\n");
151  }
152 
153  /* Now convert it to the required file access */
154  return MmMakeFileAccess[ProtectionMask & 0x7];
155 }
#define MM_INVALID_PROTECTION
Definition: miarm.h:71
ACCESS_MASK MmMakeFileAccess[8]
Definition: section.c:33
_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:159
#define STATUS_INVALID_PAGE_PROTECTION
Definition: ntstatus.h:291
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
NTSTATUS NTAPI MiCopyFromUserPage ( PFN_NUMBER  DestPage,
const VOID SrcAddress 
)

Definition at line 1043 of file section.c.

Referenced by MmAccessFaultSectionView().

1044 {
1046  KIRQL Irql;
1047  PVOID DestAddress;
1048 
1049  Process = PsGetCurrentProcess();
1050  DestAddress = MiMapPageInHyperSpace(Process, DestPage, &Irql);
1051  if (DestAddress == NULL)
1052  {
1053  return(STATUS_NO_MEMORY);
1054  }
1055  ASSERT((ULONG_PTR)DestAddress % PAGE_SIZE == 0);
1056  ASSERT((ULONG_PTR)SrcAddress % PAGE_SIZE == 0);
1057  RtlCopyMemory(DestAddress, SrcAddress, PAGE_SIZE);
1058  MiUnmapPageInHyperSpace(Process, DestAddress, Irql);
1059  return(STATUS_SUCCESS);
1060 }
DWORD *typedef PVOID
Definition: winlogon.h:61
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
_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
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:2710
BOOLEAN MiIsPageFromCache ( PMEMORY_AREA  MemoryArea,
LONGLONG  SegOffset 
)

Definition at line 1021 of file section.c.

Referenced by MmPageOutSectionView().

1023 {
1024 #ifndef NEWCC
1025  if (!(MemoryArea->Data.SectionData.Segment->Image.Characteristics & IMAGE_SCN_MEM_SHARED))
1026  {
1027  PROS_SHARED_CACHE_MAP SharedCacheMap;
1028  PROS_VACB Vacb;
1029  SharedCacheMap = MemoryArea->Data.SectionData.Section->FileObject->SectionObjectPointer->SharedCacheMap;
1030  Vacb = CcRosLookupVacb(SharedCacheMap, SegOffset + MemoryArea->Data.SectionData.Segment->Image.FileOffset);
1031  if (Vacb)
1032  {
1033  CcRosReleaseVacb(SharedCacheMap, Vacb, Vacb->Valid, FALSE, TRUE);
1034  return TRUE;
1035  }
1036  }
1037 #endif
1038  return FALSE;
1039 }
#define TRUE
Definition: types.h:120
Definition: cc.h:201
#define FALSE
Definition: types.h:117
NTSTATUS NTAPI CcRosReleaseVacb(PROS_SHARED_CACHE_MAP SharedCacheMap, PROS_VACB Vacb, BOOLEAN Valid, BOOLEAN Dirty, BOOLEAN Mapped)
Definition: view.c:412
struct _MEMORY_AREA::@1716::@1717 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:449
union _MEMORY_AREA::@1716 Data
NTSTATUS NTAPI MiMapViewInSystemSpace ( IN PVOID  Section,
IN PVOID  Session,
OUT PVOID MappedBase,
IN OUT PSIZE_T  ViewSize 
)
NTSTATUS NTAPI MiReadPage ( PMEMORY_AREA  MemoryArea,
LONGLONG  SegOffset,
PPFN_NUMBER  Page 
)

Definition at line 1065 of file section.c.

Referenced by MmNotPresentFaultSectionView().

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

Definition at line 4872 of file section.c.

Referenced by MmUnmapViewInSystemSpace().

4873 {
4875  NTSTATUS Status;
4876 
4877  DPRINT("MmUnmapViewInSystemSpace() called\n");
4878 
4879  AddressSpace = MmGetKernelAddressSpace();
4880 
4881  MmLockAddressSpace(AddressSpace);
4882 
4883  Status = MmUnmapViewOfSegment(AddressSpace, MappedBase);
4884 
4885  MmUnlockAddressSpace(AddressSpace);
4886 
4887  return Status;
4888 }
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG AddressSpace
Definition: iofuncs.h:2268
FORCEINLINE VOID MmUnlockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1410
static NTSTATUS MmUnmapViewOfSegment(PMMSUPPORT AddressSpace, PVOID BaseAddress)
Definition: section.c:4043
void DPRINT(...)
Definition: polytest.cpp:61
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: gdiplustypes.h:24
FORCEINLINE PMMSUPPORT MmGetKernelAddressSpace(VOID)
Definition: mm.h:1432
_Must_inspect_result_ _Outptr_result_bytebuffer_ ViewSize PVOID * MappedBase
Definition: mmfuncs.h:493
FORCEINLINE VOID MmLockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1403
NTSTATUS NTAPI MiRosUnmapViewOfSection ( IN PEPROCESS  Process,
IN PVOID  BaseAddress,
IN BOOLEAN  SkipDebuggerNotify 
)

Definition at line 4108 of file section.c.

Referenced by MiRosCleanupMemoryArea(), and MiUnmapViewOfSection().

4111 {
4112  NTSTATUS Status;
4115  PROS_SECTION_OBJECT Section;
4116  PVOID ImageBaseAddress = 0;
4117 
4118  DPRINT("Opening memory area Process %p BaseAddress %p\n",
4119  Process, BaseAddress);
4120 
4121  ASSERT(Process);
4122 
4123  AddressSpace = Process ? &Process->Vm : MmGetKernelAddressSpace();
4124 
4125  MmLockAddressSpace(AddressSpace);
4126  MemoryArea = MmLocateMemoryAreaByAddress(AddressSpace,
4127  BaseAddress);
4128  if (MemoryArea == NULL ||
4129  ((MemoryArea->Type != MEMORY_AREA_SECTION_VIEW) &&
4130  (MemoryArea->Type != MEMORY_AREA_CACHE)) ||
4131  MemoryArea->DeleteInProgress)
4132  {
4133  if (MemoryArea) ASSERT(MemoryArea->Type != MEMORY_AREA_OWNED_BY_ARM3);
4134  MmUnlockAddressSpace(AddressSpace);
4135  return STATUS_NOT_MAPPED_VIEW;
4136  }
4137 
4138  Section = MemoryArea->Data.SectionData.Section;
4139 
4140  if ((Section != NULL) && (Section->AllocationAttributes & SEC_IMAGE))
4141  {
4142  ULONG i;
4143  ULONG NrSegments;
4145  PMM_SECTION_SEGMENT SectionSegments;
4147 
4148  Segment = MemoryArea->Data.SectionData.Segment;
4149  ImageSectionObject = Section->ImageSection;
4150  SectionSegments = ImageSectionObject->Segments;
4151  NrSegments = ImageSectionObject->NrSegments;
4152 
4153  MemoryArea->DeleteInProgress = TRUE;
4154 
4155  /* Search for the current segment within the section segments
4156  * and calculate the image base address */
4157  for (i = 0; i < NrSegments; i++)
4158  {
4159  if (Segment == &SectionSegments[i])
4160  {
4161  ImageBaseAddress = (char*)BaseAddress - (ULONG_PTR)SectionSegments[i].Image.VirtualAddress;
4162  break;
4163  }
4164  }
4165  if (i >= NrSegments)
4166  {
4167  KeBugCheck(MEMORY_MANAGEMENT);
4168  }
4169 
4170  for (i = 0; i < NrSegments; i++)
4171  {
4172  PVOID SBaseAddress = (PVOID)
4173  ((char*)ImageBaseAddress + (ULONG_PTR)SectionSegments[i].Image.VirtualAddress);
4174 
4175  Status = MmUnmapViewOfSegment(AddressSpace, SBaseAddress);
4176  if (!NT_SUCCESS(Status))
4177  {
4178  DPRINT1("MmUnmapViewOfSegment failed for %p (Process %p) with %lx\n",
4179  SBaseAddress, Process, Status);
4180  ASSERT(NT_SUCCESS(Status));
4181  }
4182  }
4183  }
4184  else
4185  {
4186  Status = MmUnmapViewOfSegment(AddressSpace, BaseAddress);
4187  if (!NT_SUCCESS(Status))
4188  {
4189  DPRINT1("MmUnmapViewOfSegment failed for %p (Process %p) with %lx\n",
4190  BaseAddress, Process, Status);
4191  ASSERT(NT_SUCCESS(Status));
4192  }
4193  }
4194 
4195  MmUnlockAddressSpace(AddressSpace);
4196 
4197  /* Notify debugger */
4198  if (ImageBaseAddress && !SkipDebuggerNotify) DbgkUnMapViewOfSection(ImageBaseAddress);
4199 
4200  return(STATUS_SUCCESS);
4201 }
DWORD *typedef PVOID
Definition: winlogon.h:61
#define TRUE
Definition: types.h:120
ULONG Type
Definition: mm.h:214
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG AddressSpace
Definition: iofuncs.h:2268
FORCEINLINE VOID MmUnlockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1410
PMEMORY_AREA NTAPI MmLocateMemoryAreaByAddress(PMMSUPPORT AddressSpace, PVOID Address)
Definition: marea.c:60
#define MEMORY_AREA_CACHE
Definition: mm.h:72
uint32_t ULONG_PTR
Definition: typedefs.h:63
IN SIZE_T IN PVOID OUT PMM_IMAGE_SECTION_OBJECT ImageSectionObject
Definition: exeformat.h:53
static NTSTATUS MmUnmapViewOfSegment(PMMSUPPORT AddressSpace, PVOID BaseAddress)
Definition: section.c:4043
PMM_IMAGE_SECTION_OBJECT ImageSection
Definition: mm.h:202
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define MEMORY_AREA_OWNED_BY_ARM3
Definition: mm.h:73
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1469
#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
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
PMM_SECTION_SEGMENT Segments
Definition: mm.h:189
BOOLEAN DeleteInProgress
Definition: mm.h:217
struct _MEMORY_AREA::@1716::@1717 SectionData
VOID NTAPI DbgkUnMapViewOfSection(IN PVOID BaseAddress)
Definition: dbgkutil.c:436
Status
Definition: gdiplustypes.h:24
FORCEINLINE PMMSUPPORT MmGetKernelAddressSpace(VOID)
Definition: mm.h:1432
#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
struct _MM_SECTION_SEGMENT::@1713 Image
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
union _MEMORY_AREA::@1716 Data
return STATUS_SUCCESS
Definition: btrfs.c:2710
struct _MEMORY_AREA * MemoryArea
Definition: newmm.h:65
FORCEINLINE VOID MmLockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1403
NTSTATUS NTAPI MmAccessFaultSectionView ( PMMSUPPORT  AddressSpace,
MEMORY_AREA MemoryArea,
PVOID  Address 
)

Definition at line 1690 of file section.c.

Referenced by MmpAccessFault().

1693 {
1695  PROS_SECTION_OBJECT Section;
1696  PFN_NUMBER OldPage;
1697  PFN_NUMBER NewPage;
1698  NTSTATUS Status;
1699  PVOID PAddress;
1702  ULONG_PTR Entry;
1703  PEPROCESS Process = MmGetAddressSpaceOwner(AddressSpace);
1704 
1705  DPRINT("MmAccessFaultSectionView(%p, %p, %p)\n", AddressSpace, MemoryArea, Address);
1706 
1707  /* Make sure we have a page mapping for this address. */
1708  Status = MmNotPresentFaultSectionView(AddressSpace, MemoryArea, Address, TRUE);
1709  if (!NT_SUCCESS(Status))
1710  {
1711  /* This is invalid access ! */
1712  return Status;
1713  }
1714 
1715  /*
1716  * Check if the page has already been set readwrite
1717  */
1718  if (MmGetPageProtect(Process, Address) & PAGE_READWRITE)
1719  {
1720  DPRINT("Address 0x%p\n", Address);
1721  return(STATUS_SUCCESS);
1722  }
1723 
1724  /*
1725  * Find the offset of the page
1726  */
1727  PAddress = MM_ROUND_DOWN(Address, PAGE_SIZE);
1728  Offset.QuadPart = (ULONG_PTR)PAddress - MA_GetStartingAddress(MemoryArea)
1729  + MemoryArea->Data.SectionData.ViewOffset.QuadPart;
1730 
1731  Segment = MemoryArea->Data.SectionData.Segment;
1732  Section = MemoryArea->Data.SectionData.Section;
1733  Region = MmFindRegion((PVOID)MA_GetStartingAddress(MemoryArea),
1734  &MemoryArea->Data.SectionData.RegionListHead,
1735  Address, NULL);
1736  ASSERT(Region != NULL);
1737 
1738  /*
1739  * Check if we are doing COW
1740  */
1741  if (!((Segment->WriteCopy) &&
1742  (Region->Protect == PAGE_READWRITE ||
1743  Region->Protect == PAGE_EXECUTE_READWRITE)))
1744  {
1745  DPRINT("Address 0x%p\n", Address);
1746  return(STATUS_ACCESS_VIOLATION);
1747  }
1748 
1749  /* Get the page mapping this section offset. */
1750  MmLockSectionSegment(Segment);
1751  Entry = MmGetPageEntrySectionSegment(Segment, &Offset);
1752 
1753  /* Get the current page mapping for the process */
1754  ASSERT(MmIsPagePresent(Process, PAddress));
1755  OldPage = MmGetPfnForProcess(Process, PAddress);
1756  ASSERT(OldPage != 0);
1757 
1758  if (IS_SWAP_FROM_SSE(Entry) ||
1759  PFN_FROM_SSE(Entry) != OldPage)
1760  {
1761  MmUnlockSectionSegment(Segment);
1762  /* This is a private page. We must only change the page protection. */
1763  MmSetPageProtect(Process, PAddress, Region->Protect);
1764  return(STATUS_SUCCESS);
1765  }
1766 
1767  /*
1768  * Allocate a page
1769  */
1771  if (Process) MI_SET_PROCESS2(Process->ImageFileName);
1772  if (!Process) MI_SET_PROCESS2("Kernel Section");
1773  Status = MmRequestPageMemoryConsumer(MC_USER, TRUE, &NewPage);
1774  if (!NT_SUCCESS(Status))
1775  {
1776  KeBugCheck(MEMORY_MANAGEMENT);
1777  }
1778 
1779  /*
1780  * Copy the old page
1781  */
1782  NT_VERIFY(NT_SUCCESS(MiCopyFromUserPage(NewPage, PAddress)));
1783 
1784  /*
1785  * Unshare the old page.
1786  */
1787  DPRINT("Swapping page (Old %x New %x)\n", OldPage, NewPage);
1788  MmDeleteVirtualMapping(Process, PAddress, NULL, NULL);
1789  MmDeleteRmap(OldPage, Process, PAddress);
1790  MmUnsharePageEntrySectionSegment(Section, Segment, &Offset, FALSE, FALSE, NULL);
1791  MmUnlockSectionSegment(Segment);
1792 
1793  /*
1794  * Set the PTE to point to the new page
1795  */
1796  Status = MmCreateVirtualMapping(Process,
1797  PAddress,
1798  Region->Protect,
1799  &NewPage,
1800  1);
1801  if (!NT_SUCCESS(Status))
1802  {
1803  DPRINT1("MmCreateVirtualMapping failed, unable to create virtual mapping, not out of memory\n");
1804  KeBugCheck(MEMORY_MANAGEMENT);
1805  return(Status);
1806  }
1807  MmInsertRmap(NewPage, Process, PAddress);
1808 
1809  MiSetPageEvent(Process, Address);
1810  DPRINT("Address 0x%p\n", Address);
1811  return(STATUS_SUCCESS);
1812 }
DWORD *typedef PVOID
Definition: winlogon.h:61
PMM_REGION NTAPI MmFindRegion(PVOID BaseAddress, PLIST_ENTRY RegionListHead, PVOID Address, PVOID *RegionBaseAddress)
Definition: region.c:257
BOOLEAN WriteCopy
Definition: mm.h:170
#define TRUE
Definition: types.h:120
PVOID ULONG Address
Definition: oprghdlr.h:14
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)
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
#define MC_USER
Definition: mm.h:94
VOID NTAPI MmDeleteRmap(PFN_NUMBER Page, struct _EPROCESS *Process, PVOID Address)
Definition: mm.h:390
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
#define FALSE
Definition: types.h:117
NTSTATUS NTAPI MmNotPresentFaultSectionView(PMMSUPPORT AddressSpace, MEMORY_AREA *MemoryArea, PVOID Address, BOOLEAN Locked)
Definition: section.c:1280
#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:876
smooth NULL
Definition: ftsmooth.c:416
VOID NTAPI MmDeleteVirtualMapping(struct _EPROCESS *Process, PVOID Address, BOOLEAN *WasDirty, PPFN_NUMBER Page)
void DPRINT(...)
Definition: polytest.cpp:61
VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1469
#define MI_SET_USAGE(x)
Definition: mm.h:253
_Inout_ PVOID Segment
Definition: exfuncs.h:893
ULONG Protect
Definition: mm.h:393
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
struct _MEMORY_AREA::@1716::@1717 SectionData
VOID NTAPI MmSetPageProtect(struct _EPROCESS *Process, PVOID Address, ULONG flProtect)
#define MM_ROUND_DOWN(x, s)
Definition: mm.h:111
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define IS_SWAP_FROM_SSE(E)
Definition: newmm.h:8
#define MA_GetStartingAddress(_MemoryArea)
Definition: mm.h: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:1417
#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
CHAR ImageFileName[16]
Definition: pstypes.h:1257
#define ULONG_PTR
Definition: config.h:101
#define PAGE_EXECUTE_READWRITE
Definition: nt_native.h:1308
union _MEMORY_AREA::@1716 Data
#define MmUnlockSectionSegment(x)
Definition: newmm.h:284
return STATUS_SUCCESS
Definition: btrfs.c:2710
NTSTATUS NTAPI MiCopyFromUserPage(PFN_NUMBER DestPage, const VOID *SrcAddress)
Definition: section.c:1043
#define MmGetPageEntrySectionSegment(S, O)
Definition: newmm.h:143
LONGLONG QuadPart
Definition: typedefs.h:112
#define PAGE_READWRITE
Definition: nt_native.h:1304
static VOID MmAlterViewAttributes ( PMMSUPPORT  AddressSpace,
PVOID  BaseAddress,
SIZE_T  RegionSize,
ULONG  OldType,
ULONG  OldProtect,
ULONG  NewType,
ULONG  NewProtect 
)
static

Definition at line 2417 of file section.c.

Referenced by MmProtectSectionView().

2424 {
2427  BOOLEAN DoCOW = FALSE;
2428  ULONG i;
2429  PEPROCESS Process = MmGetAddressSpaceOwner(AddressSpace);
2430 
2431  MemoryArea = MmLocateMemoryAreaByAddress(AddressSpace, BaseAddress);
2432  ASSERT(MemoryArea != NULL);
2433  Segment = MemoryArea->Data.SectionData.Segment;
2434  MmLockSectionSegment(Segment);
2435 
2436  if ((Segment->WriteCopy) &&
2438  {
2439  DoCOW = TRUE;
2440  }
2441 
2442  if (OldProtect != NewProtect)
2443  {
2444  for (i = 0; i < PAGE_ROUND_UP(RegionSize) / PAGE_SIZE; i++)
2445  {
2446  SWAPENTRY SwapEntry;
2447  PVOID Address = (char*)BaseAddress + (i * PAGE_SIZE);
2449 
2450  /* Wait for a wait entry to disappear */
2451  do
2452  {
2453  MmGetPageFileMapping(Process, Address, &SwapEntry);
2454  if (SwapEntry != MM_WAIT_ENTRY)
2455  break;
2456  MiWaitForPageEvent(Process, Address);
2457  }
2458  while (TRUE);
2459 
2460  /*
2461  * If we doing COW for this segment then check if the page is
2462  * already private.
2463  */
2464  if (DoCOW && MmIsPagePresent(Process, Address))
2465  {
2467  ULONG_PTR Entry;
2468  PFN_NUMBER Page;
2469 
2470  Offset.QuadPart = (ULONG_PTR)Address - MA_GetStartingAddress(MemoryArea)
2471  + MemoryArea->Data.SectionData.ViewOffset.QuadPart;
2472  Entry = MmGetPageEntrySectionSegment(Segment, &Offset);
2473  /*
2474  * An MM_WAIT_ENTRY is ok in this case... It'll just count as
2475  * IS_SWAP_FROM_SSE and we'll do the right thing.
2476  */
2477  Page = MmGetPfnForProcess(Process, Address);
2478 
2479  Protect = PAGE_READONLY;
2480  if (IS_SWAP_FROM_SSE(Entry) || PFN_FROM_SSE(Entry) != Page)
2481  {
2482  Protect = NewProtect;
2483  }
2484  }
2485 
2486  if (MmIsPagePresent(Process, Address) || MmIsDisabledPage(Process, Address))
2487  {
2488  MmSetPageProtect(Process, Address,
2489  Protect);
2490  }
2491  }
2492  }
2493 
2494  MmUnlockSectionSegment(Segment);
2495 }
DWORD *typedef PVOID
Definition: winlogon.h:61
BOOLEAN WriteCopy
Definition: mm.h:170
#define TRUE
Definition: types.h:120
PVOID ULONG Address
Definition: oprghdlr.h:14
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
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
#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)
GLenum GLclampf GLint i
Definition: glfuncs.h:14
ULONG PFN_NUMBER
Definition: ke.h:8
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define FALSE
Definition: types.h:117
smooth NULL
Definition: ftsmooth.c:416
VOID NTAPI MmGetPageFileMapping(struct _EPROCESS *Process, PVOID Address, SWAPENTRY *SwapEntry)
_Inout_ PVOID Segment
Definition: exfuncs.h:893
unsigned char BOOLEAN
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
BOOLEAN NTAPI MmIsDisabledPage(struct _EPROCESS *Process, PVOID Address)
struct _MEMORY_AREA::@1716::@1717 SectionData
VOID NTAPI MmSetPageProtect(struct _EPROCESS *Process, PVOID Address, ULONG flProtect)
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define IS_SWAP_FROM_SSE(E)
Definition: newmm.h:8
#define MA_GetStartingAddress(_MemoryArea)
Definition: mm.h: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:1417
_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
union _MEMORY_AREA::@1716 Data
#define MmUnlockSectionSegment(x)
Definition: newmm.h:284
struct _MEMORY_AREA * MemoryArea
Definition: newmm.h:65
#define MmGetPageEntrySectionSegment(S, O)
Definition: newmm.h:143
LONGLONG QuadPart
Definition: typedefs.h:112
#define PAGE_READWRITE
Definition: nt_native.h:1304
BOOLEAN NTAPI MmCanFileBeTruncated ( IN PSECTION_OBJECT_POINTERS  SectionObjectPointer,
IN PLARGE_INTEGER  NewFileSize 
)

Definition at line 4695 of file section.c.

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

4697 {
4698  /* Check whether an ImageSectionObject exists */
4699  if (SectionObjectPointer->ImageSectionObject != NULL)
4700  {
4701  DPRINT1("ERROR: File can't be truncated because it has an image section\n");
4702  return FALSE;
4703  }
4704 
4705  if (SectionObjectPointer->DataSectionObject != NULL)
4706  {
4708 
4710  DataSectionObject;
4711 
4712  if (Segment->ReferenceCount != 0)
4713  {
4714 #ifdef NEWCC
4716  CcpLock();
4717  if (SectionObjectPointer->SharedCacheMap && (Segment->ReferenceCount > CcpCountCacheSections((PNOCC_CACHE_MAP)SectionObjectPointer->SharedCacheMap)))
4718  {
4719  CcpUnlock();
4720  /* Check size of file */
4721  if (SectionObjectPointer->SharedCacheMap)
4722  {
4723  if (!CcGetFileSizes(Segment->FileObject, &FileSizes))
4724  {
4725  return FALSE;
4726  }
4727 
4728  if (NewFileSize->QuadPart <= FileSizes.FileSize.QuadPart)
4729  {
4730  return FALSE;
4731  }
4732  }
4733  }
4734  else
4735  CcpUnlock();
4736 #else
4737  /* Check size of file */
4738  if (SectionObjectPointer->SharedCacheMap)
4739  {
4740  PROS_SHARED_CACHE_MAP SharedCacheMap = SectionObjectPointer->SharedCacheMap;
4741  if (NewFileSize->QuadPart <= SharedCacheMap->FileSize.QuadPart)
4742  {
4743  return FALSE;
4744  }
4745  }
4746 #endif
4747  }
4748  else
4749  {
4750  /* Something must gone wrong
4751  * how can we have a Section but no
4752  * reference? */
4753  DPRINT("ERROR: DataSectionObject without reference!\n");
4754  }
4755  }
4756 
4757  DPRINT("FIXME: didn't check for outstanding write probes\n");
4758 
4759  return TRUE;
4760 }
#define TRUE
Definition: types.h:120
#define CcpLock()
Definition: newcc.h:140
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
#define FALSE
Definition: types.h:117
smooth NULL
Definition: ftsmooth.c:416
_Inout_ PLARGE_INTEGER NewFileSize
Definition: mrx.h:204
void DPRINT(...)
Definition: polytest.cpp:61
PFILE_OBJECT FileObject
Definition: mm.h:163
_Inout_ PVOID Segment
Definition: exfuncs.h:893
if(!(yy_init))
Definition: macro.lex.yy.c:717
struct _MM_SECTION_SEGMENT * PMM_SECTION_SEGMENT
ULONG ReferenceCount
Definition: mm.h:166
ULONG NTAPI CcpCountCacheSections(IN PNOCC_CACHE_MAP Map)
Definition: fssup.c:270
#define DPRINT1
Definition: precomp.h:8
LARGE_INTEGER FileSize
Definition: cc.h:174
#define CcpUnlock()
Definition: newcc.h:141
LONGLONG QuadPart
Definition: typedefs.h:112
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 2411 of file section.c.

Referenced by MmCreateSection().

2419 {
2420  SECTION Section;
2421  PSECTION NewSection;
2422  PSUBSECTION Subsection;
2423  PSEGMENT NewSegment, Segment;
2424  NTSTATUS Status;
2425  PCONTROL_AREA ControlArea;
2426  ULONG ProtectionMask, ControlAreaSize, Size, NonPagedCharge, PagedCharge;
2428  BOOLEAN FileLock = FALSE, KernelCall = FALSE;
2429  KIRQL OldIrql;
2431  BOOLEAN UserRefIncremented = FALSE;
2432  PVOID PreviousSectionPointer;
2433 
2434  /* Make the same sanity checks that the Nt interface should've validated */
2437  SEC_NO_CHANGE)) == 0);
2441  SEC_NOCACHE | SEC_NO_CHANGE))));
2447 
2448  /* Convert section flag to page flag */
2450 
2451  /* Check to make sure the protection is correct. Nt* does this already */
2452  ProtectionMask = MiMakeProtectionMask(SectionPageProtection);
2453  if (ProtectionMask == MM_INVALID_PROTECTION) return STATUS_INVALID_PAGE_PROTECTION;
2454 
2455  /* Check if this is going to be a data or image backed file section */
2456  if ((FileHandle) || (FileObject))
2457  {
2458  /* These cannot be mapped with large pages */
2460 
2461  /* For now, only support the mechanism through a file handle */
2462  ASSERT(FileObject == NULL);
2463 
2464  /* Reference the file handle to get the object */
2466  MmMakeFileAccess[ProtectionMask],
2468  PreviousMode,
2469  (PVOID*)&File,
2470  NULL);
2471  if (!NT_SUCCESS(Status)) return Status;
2472 
2473  /* Make sure Cc has been doing its job */
2474  if (!File->SectionObjectPointer)
2475  {
2476  /* This is not a valid file system-based file, fail */
2477  ObDereferenceObject(File);
2479  }
2480 
2481  /* Image-file backed sections are not yet supported */
2482  ASSERT((AllocationAttributes & SEC_IMAGE) == 0);
2483 
2484  /* Compute the size of the control area, and allocate it */
2485  ControlAreaSize = sizeof(CONTROL_AREA) + sizeof(MSUBSECTION);
2486  ControlArea = ExAllocatePoolWithTag(NonPagedPool, ControlAreaSize, 'aCmM');
2487  if (!ControlArea)
2488  {
2489  ObDereferenceObject(File);
2491  }
2492 
2493  /* Zero it out */
2494  RtlZeroMemory(ControlArea, ControlAreaSize);
2495 
2496  /* Did we get a handle, or an object? */
2497  if (FileHandle)
2498  {
2499  /* We got a file handle so we have to lock down the file */
2500 #if 0
2501  Status = FsRtlAcquireToCreateMappedSection(File, SectionPageProtection);
2502  if (!NT_SUCCESS(Status))
2503  {
2504  ExFreePool(ControlArea);
2505  ObDereferenceObject(File);
2506  return Status;
2507  }
2508 #else
2509  /* ReactOS doesn't support this API yet, so do nothing */
2510  Status = STATUS_SUCCESS;
2511 #endif
2512  /* Update the top-level IRP so that drivers know what's happening */
2514  FileLock = TRUE;
2515  }
2516 
2517  /* Lock the PFN database while we play with the section pointers */
2518  OldIrql = MiAcquirePfnLock();
2519 
2520  /* Image-file backed sections are not yet supported */
2521  ASSERT((AllocationAttributes & SEC_IMAGE) == 0);
2522 
2523  /* There should not already be a control area for this file */
2524  ASSERT(File->SectionObjectPointer->DataSectionObject == NULL);
2525  NewSegment = NULL;
2526 
2527  /* Write down that this CA is being created, and set it */
2528  ControlArea->u.Flags.BeingCreated = TRUE;
2529  ASSERT((AllocationAttributes & SEC_IMAGE) == 0);
2530  PreviousSectionPointer = File->SectionObjectPointer;
2531  File->SectionObjectPointer->DataSectionObject = ControlArea;
2532 
2533  /* We can release the PFN lock now */
2534  MiReleasePfnLock(OldIrql);
2535 
2536  /* We don't support previously-mapped file */
2537  ASSERT(NewSegment == NULL);
2538 
2539  /* Image-file backed sections are not yet supported */
2540  ASSERT((AllocationAttributes & SEC_IMAGE) == 0);
2541 
2542  /* So we always create a data file map */
2543  Status = MiCreateDataFileMap(File,
2544  &Segment,
2545  (PSIZE_T)InputMaximumSize,
2548  KernelCall);
2549  if (!NT_SUCCESS(Status))
2550  {
2551  /* Lock the PFN database while we play with the section pointers */
2552  OldIrql = MiAcquirePfnLock();
2553 
2554  /* Reset the waiting-for-deletion event */
2555  ASSERT(ControlArea->WaitingForDeletion == NULL);
2556  ControlArea->WaitingForDeletion = NULL;
2557 
2558  /* Set the file pointer NULL flag */
2559  ASSERT(ControlArea->u.Flags.FilePointerNull == 0);
2560  ControlArea->u.Flags.FilePointerNull = TRUE;
2561 
2562  /* Delete the data section object */
2563  ASSERT((AllocationAttributes & SEC_IMAGE) == 0);
2564  File->SectionObjectPointer->DataSectionObject = NULL;
2565 
2566  /* No longer being created */
2567  ControlArea->u.Flags.BeingCreated = FALSE;
2568 
2569  /* We can release the PFN lock now */
2570  MiReleasePfnLock(OldIrql);
2571 
2572  /* Check if we locked and set the IRP */
2573  if (FileLock)
2574  {
2575  /* Undo */
2577  //FsRtlReleaseFile(File);
2578  }
2579 
2580  /* Free the control area and de-ref the file object */
2581  ExFreePool(ControlArea);
2582  ObDereferenceObject(File);
2583 
2584  /* All done */
2585  return Status;
2586  }
2587 
2588  /* On success, we expect this */
2589  ASSERT(PreviousSectionPointer == File->SectionObjectPointer);
2590 
2591  /* Check if a maximum size was specified */
2592  if (!InputMaximumSize->QuadPart)
2593  {
2594  /* Nope, use the segment size */
2595  Section.SizeOfSection.QuadPart = (LONGLONG)Segment->SizeOfSegment;
2596  }
2597  else
2598  {
2599  /* Yep, use the entered size */
2600  Section.SizeOfSection.QuadPart = InputMaximumSize->QuadPart;
2601  }
2602  }
2603  else
2604  {
2605  /* A handle must be supplied with SEC_IMAGE, as this is the no-handle path */
2606  if (AllocationAttributes & SEC_IMAGE) return STATUS_INVALID_FILE_FOR_SECTION;
2607 
2608  /* Not yet supported */
2609  ASSERT((AllocationAttributes & SEC_LARGE_PAGES) == 0);
2610 
2611  /* So this must be a pagefile-backed section, create the mappings needed */
2612  Status = MiCreatePagingFileMap(&NewSegment,
2613  (PSIZE_T)InputMaximumSize,
2614  ProtectionMask,
2616  if (!NT_SUCCESS(Status)) return Status;
2617 
2618  /* Set the size here, and read the control area */
2619  Section.SizeOfSection.QuadPart = NewSegment->SizeOfSegment;
2620  ControlArea = NewSegment->ControlArea;
2621 
2622  /* MiCreatePagingFileMap increments user references */
2623  UserRefIncremented = TRUE;
2624  }
2625 
2626  /* Did we already have a segment? */
2627  if (!NewSegment)
2628  {
2629  /* This must be the file path and we created a segment */
2630  NewSegment = Segment;
2631  ASSERT(File != NULL);
2632 
2633  /* Acquire the PFN lock while we set control area flags */
2634  OldIrql = MiAcquirePfnLock();
2635 
2636  /* We don't support this race condition yet, so assume no waiters */
2637  ASSERT(ControlArea->WaitingForDeletion == NULL);
2638  ControlArea->WaitingForDeletion = NULL;
2639 
2640  /* Image-file backed sections are not yet supported, nor ROM images */
2641  ASSERT((AllocationAttributes & SEC_IMAGE) == 0);
2642  ASSERT(Segment->ControlArea->u.Flags.Rom == 0);
2643 
2644  /* Take off the being created flag, and then release the lock */
2645  ControlArea->u.Flags.BeingCreated = FALSE;
2646  MiReleasePfnLock(OldIrql);
2647  }
2648 
2649  /* Check if we locked the file earlier */
2650  if (FileLock)
2651  {
2652  /* Reset the top-level IRP and release the lock */
2654  //FsRtlReleaseFile(File);
2655  FileLock = FALSE;
2656  }
2657 
2658  /* Set the initial section object data */
2659  Section.InitialPageProtection = SectionPageProtection;
2660 
2661  /* The mapping created a control area and segment, save the flags */
2662  Section.Segment = NewSegment;
2663  Section.u.LongFlags = ControlArea->u.LongFlags;
2664 
2665  /* Check if this is a user-mode read-write non-image file mapping */
2666  if (!(FileObject) &&
2668  !(ControlArea->u.Flags.Image) &&
2669  (ControlArea->FilePointer))
2670  {
2671  /* Add a reference and set the flag */
2672  Section.u.Flags.UserWritable = TRUE;
2673  InterlockedIncrement((volatile LONG*)&ControlArea->WritableUserReferences);
2674  }
2675 
2676  /* Check for image mappings or page file mappings */
2677  if ((ControlArea->u.Flags.Image) || !(ControlArea->FilePointer))
2678  {
2679  /* Charge the segment size, and allocate a subsection */
2680  PagedCharge = sizeof(SECTION) + NewSegment->TotalNumberOfPtes * sizeof(MMPTE);
2681  Size = sizeof(SUBSECTION);
2682  }
2683  else
2684  {
2685  /* Charge nothing, and allocate a mapped subsection */
2686  PagedCharge = 0;
2687  Size = sizeof(MSUBSECTION);
2688  }
2689 
2690  /* Check if this is a normal CA */
2691  ASSERT(ControlArea->u.Flags.GlobalOnlyPerSession == 0);
2692  ASSERT(ControlArea->u.Flags.Rom == 0);
2693 
2694  /* Charge only a CA, and the subsection is right after */
2695  NonPagedCharge = sizeof(CONTROL_AREA);
2696  Subsection = (PSUBSECTION)(ControlArea + 1);
2697 
2698  /* We only support single-subsection mappings */
2699  NonPagedCharge += Size;
2700  ASSERT(Subsection->NextSubsection == NULL);
2701 
2702  /* Create the actual section object, with enough space for the prototype PTEs */
2703  Status = ObCreateObject(PreviousMode,
2706  PreviousMode,
2707  NULL,
2708  sizeof(SECTION),
2709  PagedCharge,
2710  NonPagedCharge,
2711  (PVOID*)&NewSection);
2712  if (!NT_SUCCESS(Status))
2713  {
2714  /* Check if this is a user-mode read-write non-image file mapping */
2715  if (!(FileObject) &&
2717  !(ControlArea->u.Flags.Image) &&
2718  (ControlArea->FilePointer))
2719  {
2720  /* Remove a reference and check the flag */
2721  ASSERT(Section.u.Flags.UserWritable == 1);
2722  InterlockedDecrement((volatile LONG*)&ControlArea->WritableUserReferences);
2723  }
2724 
2725  /* Check if a user reference was added */
2726  if (UserRefIncremented)
2727  {
2728  /* Acquire the PFN lock while we change counters */
2729  OldIrql = MiAcquirePfnLock();
2730 
2731  /* Decrement the accounting counters */
2732  ControlArea->NumberOfSectionReferences--;
2733  ASSERT((LONG)ControlArea->NumberOfUserReferences > 0);
2734  ControlArea->NumberOfUserReferences--;
2735 
2736  /* Check if we should destroy the CA and release the lock */
2737  MiCheckControlArea(ControlArea, OldIrql);
2738  }
2739 
2740  /* Return the failure code */
2741  return Status;
2742  }
2743 
2744  /* NOTE: Past this point, all failures will be handled by Ob upon ref->0 */
2745 
2746  /* Now copy the local section object from the stack into this new object */
2747  RtlCopyMemory(NewSection, &Section, sizeof(SECTION));
2748  NewSection->Address.StartingVpn = 0;
2749 
2750  /* For now, only user calls are supported */
2751  ASSERT(KernelCall == FALSE);
2752  NewSection->u.Flags.UserReference = TRUE;
2753 
2754  /* Is this a "based" allocation, in which all mappings are identical? */
2756  {
2757  /* Lock the VAD tree during the search */
2759 
2760  /* Is it a brand new ControArea ? */
2761  if (ControlArea->u.Flags.BeingCreated == 1)
2762  {
2763  ASSERT(ControlArea->u.Flags.Based == 1);
2764  /* Then we must find a global address, top-down */
2767  _64K,
2769  (ULONG_PTR*)&ControlArea->Segment->BasedAddress);
2770 
2771  if (!NT_SUCCESS(Status))
2772  {
2773  /* No way to find a valid range. */
2775  ControlArea->u.Flags.Based = 0;
2776  NewSection->u.Flags.Based = 0;
2777  ObDereferenceObject(NewSection);
2778  return Status;
2779  }
2780 
2781  /* Compute the ending address and insert it into the VAD tree */
2782  NewSection->Address.StartingVpn = (ULONG_PTR)ControlArea->Segment->BasedAddress;
2783  NewSection->Address.EndingVpn = NewSection->Address.StartingVpn + NewSection->SizeOfSection.LowPart - 1;
2784  MiInsertBasedSection(NewSection);
2785  }
2786  else
2787  {
2788  /* 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 !*/
2789  ASSERT(FALSE);
2790  }
2791 
2793  }
2794 
2795  /* The control area is not being created anymore */
2796  if (ControlArea->u.Flags.BeingCreated == 1)
2797  {
2798  /* Acquire the PFN lock while we set control area flags */
2799  OldIrql = MiAcquirePfnLock();
2800 
2801  /* Take off the being created flag, and then release the lock */
2802  ControlArea->u.Flags.BeingCreated = 0;
2803  NewSection->u.Flags.BeingCreated = 0;
2804 
2805  MiReleasePfnLock(OldIrql);
2806  }
2807 
2808  /* Migrate the attribute into a flag */
2809  if (AllocationAttributes & SEC_NO_CHANGE) NewSection->u.Flags.NoChange = TRUE;
2810 
2811  /* If R/W access is not requested, this might eventually become a CoW mapping */
2813  {
2814  NewSection->u.Flags.CopyOnWrite = TRUE;
2815  }
2816 
2817  /* Write down if this was a kernel call */
2818  ControlArea->u.Flags.WasPurged |= KernelCall;
2819  ASSERT(ControlArea->u.Flags.WasPurged == FALSE);
2820 
2821  /* Make sure the segment and the section are the same size, or the section is smaller */
2822  ASSERT((ULONG64)NewSection->SizeOfSection.QuadPart <= NewSection->Segment->SizeOfSegment);
2823 
2824  /* Return the object and the creation status */
2825  *SectionObject = (PVOID)NewSection;
2826  return Status;
2827 }
ULONG NoChange
Definition: mmtypes.h:478
_Must_inspect_result_ _Outptr_ PVOID * SectionObject
Definition: fsrtlfuncs.h:860
DWORD *typedef PVOID
Definition: winlogon.h:61
#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:526
#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:525
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define SEC_LARGE_PAGES
Definition: mmtypes.h:102
ULONGLONG SizeOfSegment
Definition: mmtypes.h:405
_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:471
ULONG NumberOfSectionReferences
Definition: mmtypes.h:515
PSEGMENT Segment
Definition: mmtypes.h:813
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:1496
VOID FASTCALL KeAcquireGuardedMutex(IN PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:42
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
#define PAGE_GUARD
Definition: nt_native.h:1310
KGUARDED_MUTEX MmSectionBasedMutex
Definition: section.c:111
MM_AVL_TABLE MmSectionBasedRoot
Definition: section.c:110
FORCEINLINE KIRQL MiAcquirePfnLock(VOID)
Definition: mm.h:894
ACCESS_MASK MmMakeFileAccess[8]
Definition: section.c:33
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:2927
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
IN SIZE_T IN PVOID File
Definition: exeformat.h:53
#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:402
struct _SUBSECTION SUBSECTION
NTSTATUS NTAPI MiCreatePagingFileMap(OUT PSEGMENT *Segment, IN PSIZE_T MaximumSize, IN ULONG ProtectionMask, IN ULONG AllocationAttributes)
Definition: section.c:1511
VOID NTAPI MiInsertBasedSection(IN PSECTION Section)
Definition: vadnode.c:345
FORCEINLINE VOID MiReleasePfnLock(_In_ KIRQL OldIrql)
Definition: mm.h:901
struct _CONTROL_AREA * ControlArea
Definition: mmtypes.h:401
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
union _SECTION::@2496 u
UCHAR KIRQL
Definition: env_spec_w32.h:591
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
#define FALSE
Definition: types.h:117
struct _SUBSECTION * NextSubsection
Definition: mmtypes.h:574
long LONG
Definition: pedump.c:60
LARGE_INTEGER SizeOfSection
Definition: mmtypes.h:814
#define SEC_RESERVE
Definition: nt_native.h:1323
struct _MSUBSECTION MSUBSECTION
#define PAGE_NOACCESS
Definition: nt_native.h:1302
smooth NULL
Definition: ftsmooth.c:416
ULONG LongFlags
Definition: mmtypes.h:522
struct _SECTION SECTION
ULONG_PTR StartingVpn
Definition: mmtypes.h:654
_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:938
UINTN Size
Definition: acefiex.h:555
ULONG_PTR EndingVpn
Definition: mmtypes.h:655
int64_t LONGLONG
Definition: typedefs.h:66
unsigned char BOOLEAN
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
ULONG NTAPI MiMakeProtectionMask(IN ULONG Protect)
Definition: section.c:159
#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:1954
#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:818
#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:483
ULONG LowPart
Definition: typedefs.h:104
#define STATUS_INVALID_PAGE_PROTECTION
Definition: ntstatus.h:291
ULONG CopyOnWrite
Definition: mmtypes.h:466
POBJECT_TYPE IoFileObjectType
Definition: iomgr.c:36
#define _64K
Definition: miarm.h:19
Status
Definition: gdiplustypes.h:24
static HANDLE FileHandle
Definition: cabinet.c:48
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:474
ULONG WritableUserReferences
Definition: mmtypes.h:529
PSEGMENT Segment
Definition: mmtypes.h:513
MMADDRESS_NODE Address
Definition: mmtypes.h:812
#define STATUS_INVALID_PARAMETER_6
Definition: ntstatus.h:466
ULONG NumberOfUserReferences
Definition: mmtypes.h:519
VOID NTAPI MiCheckControlArea(IN PCONTROL_AREA ControlArea, IN KIRQL OldIrql)
Definition: section.c:729
VOID FASTCALL KeReleaseGuardedMutex(IN OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:53
PVOID BasedAddress
Definition: mmtypes.h:410
union _CONTROL_AREA::@2480 u
PVOID MmHighSectionBase
Definition: section.c:112
ULONG WasPurged
Definition: mmtypes.h:470
PVOID PIRP
Definition: usb.h:38
MMSECTION_FLAGS Flags
Definition: mmtypes.h:523
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define ULONG_PTR
Definition: config.h:101
#define SEC_IMAGE
Definition: mmtypes.h:96
#define PAGE_EXECUTE_READWRITE
Definition: nt_native.h:1308
return STATUS_SUCCESS
Definition: btrfs.c:2710
#define SEC_NO_CHANGE
Definition: mmtypes.h:94
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
ULONG BeingCreated
Definition: mmtypes.h:456
LONGLONG QuadPart
Definition: typedefs.h:112
#define PAGE_READWRITE
Definition: nt_native.h:1304
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 2887 of file section.c.

Referenced by MmCreateSection().

2897 {
2898  PROS_SECTION_OBJECT Section;
2899  NTSTATUS Status;
2903  ULONG Length;
2904 
2905  /*
2906  * Create the section
2907  */
2908  Status = ObCreateObject(ExGetPreviousMode(),
2910  ObjectAttributes,
2912  NULL,
2913  sizeof(ROS_SECTION_OBJECT),
2914  0,
2915  0,
2916  (PVOID*)&Section);
2917  if (!NT_SUCCESS(Status))
2918  {
2920  return(Status);
2921  }
2922  /*
2923  * Initialize it
2924  */
2925  RtlZeroMemory(Section, sizeof(ROS_SECTION_OBJECT));
2926  Section->Type = 'SC';
2927  Section->Size = 'TN';
2930 
2931  /*
2932  * FIXME: This is propably not entirely correct. We can't look into
2933  * the standard FCB header because it might not be initialized yet
2934  * (as in case of the EXT2FS driver by Manoj Paul Joseph where the
2935  * standard file information is filled on first request).
2936  */
2939  sizeof(FILE_STANDARD_INFORMATION),
2940  &FileInfo,
2941  &Length);
2942  if (!NT_SUCCESS(Status))
2943  {
2944  ObDereferenceObject(Section);
2946  return Status;
2947  }
2948 
2949  /*
2950  * FIXME: Revise this once a locking order for file size changes is
2951  * decided
2952  */
2953  if ((UMaximumSize != NULL) && (UMaximumSize->QuadPart != 0))
2954  {
2955  MaximumSize = *UMaximumSize;
2956  }
2957  else
2958  {
2959  MaximumSize = FileInfo.EndOfFile;
2960  /* Mapping zero-sized files isn't allowed. */
2961  if (MaximumSize.QuadPart == 0)
2962  {
2963  ObDereferenceObject(Section);
2966  }
2967  }
2968 
2969  if (MaximumSize.QuadPart > FileInfo.EndOfFile.QuadPart)
2970  {
2971  Status = IoSetInformation(FileObject,
2973  sizeof(LARGE_INTEGER),
2974  &MaximumSize);
2975  if (!NT_SUCCESS(Status))
2976  {
2977  ObDereferenceObject(Section);
2980  }
2981  }
2982 
2983  if (FileObject->SectionObjectPointer == NULL ||
2984  FileObject->SectionObjectPointer->SharedCacheMap == NULL)
2985  {
2986  ObDereferenceObject(Section);
2989  }
2990 
2991  /*
2992  * Lock the file
2993  */
2994  Status = MmspWaitForFileLock(FileObject);
2995  if (Status != STATUS_SUCCESS)
2996  {
2997  ObDereferenceObject(Section);
2999  return(Status);
3000  }
3001 
3002  /*
3003  * If this file hasn't been mapped as a data file before then allocate a
3004  * section segment to describe the data file mapping
3005  */
3006  if (FileObject->SectionObjectPointer->DataSectionObject == NULL)
3007  {
3010  if (Segment == NULL)
3011  {
3012  //KeSetEvent((PVOID)&FileObject->Lock, IO_NO_INCREMENT, FALSE);
3013  ObDereferenceObject(Section);
3015  return(STATUS_NO_MEMORY);
3016  }
3017  Section->Segment = Segment;
3018  Segment->ReferenceCount = 1;
3019  ExInitializeFastMutex(&Segment->Lock);
3020  /*
3021  * Set the lock before assigning the segment to the file object
3022  */
3023  ExAcquireFastMutex(&Segment->Lock);
3024  FileObject->SectionObjectPointer->DataSectionObject = (PVOID)Segment;
3025 
3026  Segment->Image.FileOffset = 0;
3027  Segment->Protection = SectionPageProtection;
3028  Segment->Flags = MM_DATAFILE_SEGMENT;
3029  Segment->Image.Characteristics = 0;
3032  {
3033  Segment->Length.QuadPart = Segment->RawLength.QuadPart = 0;
3034  }
3035  else
3036  {
3037  Segment->RawLength.QuadPart = MaximumSize.QuadPart;
3038  Segment->Length.QuadPart = PAGE_ROUND_UP(Segment->RawLength.QuadPart);
3039  }
3040  Segment->Image.VirtualAddress = 0;
3041  Segment->Locked = TRUE;
3043  }
3044  else
3045  {
3046  /*
3047  * If the file is already mapped as a data file then we may need
3048  * to extend it
3049  */
3050  Segment =
3051  (PMM_SECTION_SEGMENT)FileObject->SectionObjectPointer->
3052  DataSectionObject;
3053  Section->Segment = Segment;
3054  (void)InterlockedIncrementUL(&Segment->ReferenceCount);
3055  MmLockSectionSegment(Segment);
3056 
3057  if (MaximumSize.QuadPart > Segment->RawLength.QuadPart &&
3059  {
3060  Segment->RawLength.QuadPart = MaximumSize.QuadPart;
3061  Segment->Length.QuadPart = PAGE_ROUND_UP(Segment->RawLength.QuadPart);
3062  }
3063  }
3064  MmUnlockSectionSegment(Segment);
3065  Section->FileObject = FileObject;
3066  Section->MaximumSize = MaximumSize;
3067 #ifndef NEWCC
3069 #endif
3070  //KeSetEvent((PVOID)&FileObject->Lock, IO_NO_INCREMENT, FALSE);
3071  *SectionObject = Section;
3072  return(STATUS_SUCCESS);
3073 }
DWORD *typedef PVOID
Definition: winlogon.h:61
BOOLEAN WriteCopy
Definition: mm.h:170
#define TRUE
Definition: types.h:120
LARGE_INTEGER MaximumSize
Definition: mm.h:196
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ ULONG AllocationAttributes
Definition: mmfuncs.h:360
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:2927
NTSTATUS NTAPI IoSetInformation(IN PFILE_OBJECT FileObject, IN FILE_INFORMATION_CLASS FileInformationClass, IN ULONG Length, IN PVOID FileInformation)
Definition: iofunc.c:1201
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
#define PAGE_ROUND_UP(x)
Definition: scsiport_int.h:13
NTSTATUS NTAPI IoQueryFileInformation(IN PFILE_OBJECT FileObject, IN FILE_INFORMATION_CLASS FileInformationClass, IN ULONG Length, OUT PVOID FileInformation, OUT PULONG ReturnedLength)
Definition: iofunc.c:1161
_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
ULONG Protection
Definition: mm.h:168
#define SEC_RESERVE
Definition: nt_native.h:1323
BOOLEAN Locked
Definition: mm.h:171
smooth NULL
Definition: ftsmooth.c:416
LARGE_INTEGER EndOfFile
Definition: nt_native.h:948
VOID NTAPI CcRosReferenceCache(PFILE_OBJECT FileObject)
Definition: view.c:1267
_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:938
LARGE_INTEGER Length
Definition: mm.h:165
LONG NTSTATUS
Definition: precomp.h:26
PFILE_OBJECT FileObject
Definition: mm.h:199
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
CSHORT Type
Definition: mm.h:194
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274
LARGE_INTEGER RawLength
Definition: mm.h:164
#define STATUS_INVALID_FILE_FOR_SECTION
Definition: ntstatus.h:255
#define MM_DATAFILE_SEGMENT
Definition: mm.h:91
POBJECT_TYPE MmSectionObjectType
Definition: section.c:136
struct _MM_SECTION_SEGMENT * PMM_SECTION_SEGMENT
ULONG Flags
Definition: mm.h:169
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
VOID UINTN Length
Definition: acefiex.h:744
ULONG ReferenceCount
Definition: mm.h:166
NTSTATUS MmspWaitForFileLock(PFILE_OBJECT File)
Definition: section.c:796
VOID NTAPI MiInitializeSectionPageTable(PMM_SECTION_SEGMENT Segment)
Definition: sptab.c:165
Status
Definition: gdiplustypes.h:24
VOID FASTCALL ExAcquireFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:23
#define TAG_MM_SECTION_SEGMENT
Definition: tag.h:139
#define InterlockedIncrementUL(Addend)
Definition: ex.h:1469
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
ULONG SectionPageProtection
Definition: mm.h:197
#define 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 MmLockSectionSegment(x)
Definition: newmm.h:276
struct _MM_SECTION_SEGMENT::@1713 Image
FAST_MUTEX Lock
Definition: mm.h:162
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:2710
LONGLONG QuadPart
Definition: typedefs.h:112
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 3701 of file section.c.

Referenced by MmCreateSection().

3708 {
3709  PROS_SECTION_OBJECT Section;
3710  NTSTATUS Status;
3711  PMM_SECTION_SEGMENT SectionSegments;
3713  ULONG i;
3714 
3715  if (FileObject == NULL)
3717 
3718 #ifndef NEWCC
3719  if (FileObject->SectionObjectPointer->SharedCacheMap == NULL)
3720  {
3721  DPRINT1("Denying section creation due to missing cache initialization\n");
3723  }
3724 #endif
3725 
3726  /*
3727  * Create the section
3728  */
3729  Status = ObCreateObject (ExGetPreviousMode(),
3731  ObjectAttributes,
3733  NULL,
3734  sizeof(ROS_SECTION_OBJECT),
3735  0,
3736  0,
3737  (PVOID*)(PVOID)&Section);
3738  if (!NT_SUCCESS(Status))
3739  {
3741  return(Status);
3742  }
3743 
3744  /*
3745  * Initialize it
3746  */
3747  RtlZeroMemory(Section, sizeof(ROS_SECTION_OBJECT));
3748  Section->Type = 'SC';
3749  Section->Size = 'TN';
3752 
3753  if (FileObject->SectionObjectPointer->ImageSectionObject == NULL)
3754  {
3755  NTSTATUS StatusExeFmt;
3756 
3758  if (ImageSectionObject == NULL)
3759  {
3761  ObDereferenceObject(Section);
3762  return(STATUS_NO_MEMORY);
3763  }
3764 
3765  RtlZeroMemory(ImageSectionObject, sizeof(MM_IMAGE_SECTION_OBJECT));
3766 
3767  StatusExeFmt = ExeFmtpCreateImageSection(FileObject, ImageSectionObject);
3768 
3769  if (!NT_SUCCESS(StatusExeFmt))
3770  {
3771  if(ImageSectionObject->Segments != NULL)
3772  ExFreePool(ImageSectionObject->Segments);
3773 
3774  /*
3775  * If image file is empty, then return that the file is invalid for section
3776  */
3777  Status = StatusExeFmt;
3778  if (StatusExeFmt == STATUS_END_OF_FILE)
3779  {
3781  }
3782 
3783  ExFreePoolWithTag(ImageSectionObject, TAG_MM_SECTION_SEGMENT);
3784  ObDereferenceObject(Section);
3786  return(Status);
3787  }
3788 
3789  Section->ImageSection = ImageSectionObject;
3790  ASSERT(ImageSectionObject->Segments);
3791 
3792  /*
3793  * Lock the file
3794  */
3795  Status = MmspWaitForFileLock(FileObject);
3796  if (!NT_SUCCESS(Status))
3797  {
3798  ExFreePool(ImageSectionObject->Segments);
3799  ExFreePool(ImageSectionObject);
3800  ObDereferenceObject(Section);
3802  return(Status);
3803  }
3804 
3805  if (NULL != InterlockedCompareExchangePointer(&FileObject->SectionObjectPointer->ImageSectionObject,
3806  ImageSectionObject, NULL))
3807  {
3808  /*
3809  * An other thread has initialized the same image in the background
3810  */
3811  ExFreePool(ImageSectionObject->Segments);
3812  ExFreePool(ImageSectionObject);
3813  ImageSectionObject = FileObject->SectionObjectPointer->ImageSectionObject;
3814  Section->ImageSection = ImageSectionObject;
3815  SectionSegments = ImageSectionObject->Segments;
3816 
3817  for (i = 0; i < ImageSectionObject->NrSegments; i++)
3818  {
3819  (void)InterlockedIncrementUL(&SectionSegments[i].ReferenceCount);
3820  }
3821  }
3822 
3823  Status = StatusExeFmt;
3824  }
3825  else
3826  {
3827  /*
3828  * Lock the file
3829  */
3830  Status = MmspWaitForFileLock(FileObject);
3831  if (Status != STATUS_SUCCESS)
3832  {
3833  ObDereferenceObject(Section);
3835  return(Status);
3836  }
3837 
3838  ImageSectionObject = FileObject->SectionObjectPointer->ImageSectionObject;
3839  Section->ImageSection = ImageSectionObject;
3840  SectionSegments = ImageSectionObject->Segments;
3841 
3842  /*
3843  * Otherwise just reference all the section segments
3844  */
3845  for (i = 0; i < ImageSectionObject->NrSegments; i++)
3846  {
3847  (void)InterlockedIncrementUL(&SectionSegments[i].ReferenceCount);
3848  }
3849 
3850  Status = STATUS_SUCCESS;
3851  }
3852  Section->FileObject = FileObject;
3853 #ifndef NEWCC
3855 #endif
3856  //KeSetEvent((PVOID)&FileObject->Lock, IO_NO_INCREMENT, FALSE);
3857  *SectionObject = Section;
3858  return(Status);
3859 }
DWORD *typedef PVOID
Definition: winlogon.h:61
NTSTATUS ExeFmtpCreateImageSection(PFILE_OBJECT FileObject, PMM_IMAGE_SECTION_OBJECT ImageSectionObject)
Definition: section.c:3554
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ ULONG AllocationAttributes
Definition: mmfuncs.h:360
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:2927
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
#define STATUS_END_OF_FILE
Definition: shellext.h:50
IN SIZE_T IN PVOID OUT PMM_IMAGE_SECTION_OBJECT ImageSectionObject
Definition: exeformat.h:53
_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
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define InterlockedCompareExchangePointer
Definition: interlocked.h:129
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:47
smooth NULL
Definition: ftsmooth.c:416
VOID NTAPI CcRosReferenceCache(PFILE_OBJECT FileObject)
Definition: view.c:1267
_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:938
LONG NTSTATUS
Definition: precomp.h:26
PFILE_OBJECT FileObject
Definition: mm.h:199
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
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
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
NTSTATUS MmspWaitForFileLock(PFILE_OBJECT File)
Definition: section.c:796
Status
Definition: gdiplustypes.h:24
#define TAG_MM_SECTION_SEGMENT
Definition: tag.h:139
#define InterlockedIncrementUL(Addend)
Definition: ex.h:1469
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
ULONG SectionPageProtection
Definition: mm.h:197
#define 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:2710
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
NTSTATUS NTAPI MmCreatePageFileSection ( PROS_SECTION_OBJECT SectionObject,
ACCESS_MASK  DesiredAccess,
POBJECT_ATTRIBUTES  ObjectAttributes,
PLARGE_INTEGER  UMaximumSize,
ULONG  SectionPageProtection,
ULONG  AllocationAttributes 
)

Definition at line 2812 of file section.c.

Referenced by MmCreateSection().

2821 {
2823  PROS_SECTION_OBJECT Section;
2825  NTSTATUS Status;
2826 
2827  if (UMaximumSize == NULL)
2828  {
2829  DPRINT1("MmCreatePageFileSection: (UMaximumSize == NULL)\n");
2830  return(STATUS_INVALID_PARAMETER);
2831  }
2832  MaximumSize = *UMaximumSize;
2833 
2834  /*
2835  * Create the section
2836  */
2837  Status = ObCreateObject(ExGetPreviousMode(),
2839  ObjectAttributes,
2841  NULL,
2842  sizeof(ROS_SECTION_OBJECT),
2843  0,
2844  0,
2845  (PVOID*)(PVOID)&Section);
2846  if (!NT_SUCCESS(Status))
2847  {
2848  DPRINT1("MmCreatePageFileSection: failed to create object (0x%lx)\n", Status);
2849  return(Status);
2850  }
2851 
2852  /*
2853  * Initialize it
2854  */
2855  RtlZeroMemory(Section, sizeof(ROS_SECTION_OBJECT));
2856  Section->Type = 'SC';
2857  Section->Size = 'TN';
2860  Section->MaximumSize = MaximumSize;
2863  if (Segment == NULL)
2864  {
2865  ObDereferenceObject(Section);
2866  return(STATUS_NO_MEMORY);
2867  }
2868  RtlZeroMemory(Segment, sizeof(MM_SECTION_SEGMENT));
2869  Section->Segment = Segment;
2870  Segment->ReferenceCount = 1;
2871  ExInitializeFastMutex(&Segment->Lock);
2872  Segment->Image.FileOffset = 0;
2873  Segment->Protection = SectionPageProtection;
2874  Segment->RawLength.QuadPart = MaximumSize.u.LowPart;
2875  Segment->Length.QuadPart = PAGE_ROUND_UP(MaximumSize.u.LowPart);
2876  Segment->Flags = MM_PAGEFILE_SEGMENT;
2877  Segment->WriteCopy = FALSE;
2878  Segment->Image.VirtualAddress = 0;
2879  Segment->Image.Characteristics = 0;
2880  *SectionObject = Section;
2882  return(STATUS_SUCCESS);
2883 }
DWORD *typedef PVOID
Definition: winlogon.h:61
BOOLEAN WriteCopy
Definition: mm.h:170
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
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:2927
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
#define FALSE
Definition: types.h:117
ULONG Protection
Definition: mm.h:168
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:938
LARGE_INTEGER Length
Definition: mm.h:165
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
CSHORT Type
Definition: mm.h:194
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274
LARGE_INTEGER RawLength
Definition: mm.h:164
POBJECT_TYPE MmSectionObjectType
Definition: section.c:136
ULONG Flags
Definition: mm.h:169
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define MM_PAGEFILE_SEGMENT
Definition: mm.h:90
ULONG ReferenceCount
Definition: mm.h:166
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
struct _MM_SECTION_SEGMENT::@1713 Image
FAST_MUTEX Lock
Definition: mm.h:162
struct _LARGE_INTEGER::@2192 u
#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:2710
LONGLONG QuadPart
Definition: typedefs.h:112
NTSTATUS INIT_FUNCTION NTAPI MmCreatePhysicalMemorySection ( VOID  )

Definition at line 2729 of file section.c.

Referenced by MmInitSectionImplementation().

2730 {
2731  PROS_SECTION_OBJECT PhysSection;
2732  NTSTATUS Status;
2734  UNICODE_STRING Name = RTL_CONSTANT_STRING(L"\\Device\\PhysicalMemory");
2735  LARGE_INTEGER SectionSize;
2736  HANDLE Handle;
2737 
2738  /*
2739  * Create the section mapping physical memory
2740  */
2741  SectionSize.QuadPart = 0xFFFFFFFF;
2743  &Name,
2745  NULL,
2746  NULL);
2747  Status = MmCreateSection((PVOID)&PhysSection,
2749  &Obj,
2750  &SectionSize,
2753  NULL,
2754  NULL);
2755  if (!NT_SUCCESS(Status))
2756  {
2757  DPRINT1("Failed to create PhysicalMemory section\n");
2758  KeBugCheck(MEMORY_MANAGEMENT);
2759  }
2760  Status = ObInsertObject(PhysSection,
2761  NULL,
2763  0,
2764  NULL,
2765  &Handle);
2766  if (!NT_SUCCESS(Status))
2767  {
2768  ObDereferenceObject(PhysSection);
2769  }
2770  ObCloseHandle(Handle, KernelMode);
2771  PhysSection->AllocationAttributes |= SEC_PHYSICALMEMORY;
2772  PhysSection->Segment->Flags &= ~MM_PAGEFILE_SEGMENT;
2773 
2774  return(STATUS_SUCCESS);
2775 }
DWORD *typedef PVOID
Definition: winlogon.h:61
#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:1469
_In_ HANDLE Handle
Definition: extypes.h:390
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
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:4946
ULONG Flags
Definition: mm.h:169
_In_ PUNICODE_STRING Name
Definition: mrx.h:218
#define MM_PAGEFILE_SEGMENT
Definition: mm.h:90
NTSTATUS NTAPI ObCloseHandle(IN HANDLE Handle, IN KPROCESSOR_MODE AccessMode)
Definition: obhandle.c:3370
static const WCHAR L[]
Definition: oid.c:1087
#define SEC_PHYSICALMEMORY
Definition: mm.h:88
Status
Definition: gdiplustypes.h:24
DWORD *typedef HANDLE
Definition: winlogon.h:61
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:2926
#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:2710
LONGLONG QuadPart
Definition: typedefs.h:112
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
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 4946 of file section.c.

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

4954 {
4955  NTSTATUS Status;
4956  ULONG Protection;
4958 
4959  /* Check if an ARM3 section is being created instead */
4961  {
4962  if (!(FileObject) && !(FileHandle))
4963  {
4964  return MmCreateArm3Section(Section,
4965  DesiredAccess,
4967  MaximumSize,
4969  AllocationAttributes &~ 1,
4970  FileHandle,
4971  FileObject);
4972  }
4973  }
4974 
4975  /* Convert section flag to page flag */
4977 
4978  /* Check to make sure the protection is correct. Nt* does this already */
4980  if (Protection == MM_INVALID_PROTECTION)
4981  {
4982  DPRINT1("Page protection is invalid\n");
4984  }
4985 
4986  /* Check if this is going to be a data or image backed file section */
4987  if ((FileHandle) || (FileObject))
4988  {
4989  /* These cannot be mapped with large pages */
4991  {
4992  DPRINT1("Large pages cannot be used with an image mapping\n");
4994  }
4995 
4996  /* Did the caller pass an object? */
4997  if (FileObject)
4998  {
4999  /* Reference the object directly */
5001  }
5002  else
5003  {
5004  /* Reference the file handle to get the object */
5006  MmMakeFileAccess[Protection],
5009  (PVOID*)&FileObject,
5010  NULL);
5011  if (!NT_SUCCESS(Status))
5012  {
5013  DPRINT1("Failed to get a handle to the FO: %lx\n", Status);
5014  return Status;
5015  }
5016  }
5017  }
5018  else
5019  {
5020  /* A handle must be supplied with SEC_IMAGE, as this is the no-handle path */
5022  }
5023 
5024 #ifndef NEWCC // A hack for initializing caching.
5025  // This is needed only in the old case.
5026  if (FileHandle)
5027  {
5029  NTSTATUS Status;
5030  CHAR Buffer;
5032  ByteOffset.QuadPart = 0;
5033  Status = ZwReadFile(FileHandle,
5034  NULL,
5035  NULL,
5036  NULL,
5037  &Iosb,
5038  &Buffer,
5039  sizeof(Buffer),
5040  &ByteOffset,
5041  NULL);
5042  if (!NT_SUCCESS(Status) && Status != STATUS_END_OF_FILE)
5043  {
5044  DPRINT1("CC failure: %lx\n", Status);
5045  if (FileObject)
5047  return Status;
5048  }
5049  // Caching is initialized...
5050 
5051  // Hack of the hack: actually, it might not be initialized if FSD init on effective right and if file is null-size
5052  // In such case, force cache by initiating a write IRP
5053  if (Status == STATUS_END_OF_FILE && !(AllocationAttributes & SEC_IMAGE) && FileObject != NULL &&
5054  (FileObject->SectionObjectPointer == NULL || FileObject->SectionObjectPointer->SharedCacheMap == NULL))
5055  {
5056  Buffer = 0xdb;
5057  Status = ZwWriteFile(FileHandle,
5058  NULL,
5059  NULL,
5060  NULL,
5061  &Iosb,
5062  &Buffer,
5063  sizeof(Buffer),
5064  &ByteOffset,
5065  NULL);
5066  if (NT_SUCCESS(Status))
5067  {
5069  Zero.QuadPart = 0LL;
5070 
5071  Status = IoSetInformation(FileObject,
5073  sizeof(LARGE_INTEGER),
5074  &Zero);
5075  ASSERT(NT_SUCCESS(Status));
5076  }
5077  }
5078  }
5079 #endif
5080 
5081  if (AllocationAttributes & SEC_IMAGE)
5082  {
5083  Status = MmCreateImageSection(SectionObject,
5084  DesiredAccess,
5086  MaximumSize,
5089  FileObject);
5090  }
5091 #ifndef NEWCC
5092  else if (FileHandle != NULL)
5093  {
5094  Status = MmCreateDataFileSection(SectionObject,
5095  DesiredAccess,
5097  MaximumSize,
5100  FileObject);
5101  }
5102 #else
5103  else if (FileHandle != NULL || FileObject != NULL)
5104  {
5105  Status = MmCreateCacheSection(SectionObject,
5106  DesiredAccess,
5108  MaximumSize,
5111  FileObject);
5112  }
5113 #endif
5114  else
5115  {
5117  {
5118  DPRINT1("Invalid path: %lx %p %p\n", AllocationAttributes, FileObject, FileHandle);
5119  }
5120 // ASSERT(AllocationAttributes & SEC_PHYSICALMEMORY);
5121  Status = MmCreatePageFileSection(SectionObject,
5122  DesiredAccess,
5124  MaximumSize,
5127  if (FileObject)
5129  }
5130 
5131  return Status;
5132 }
_Must_inspect_result_ _Outptr_ PVOID * SectionObject
Definition: fsrtlfuncs.h:860
DWORD *typedef PVOID
Definition: winlogon.h:61
#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:72
#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
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
char CHAR
Definition: xmlstorage.h:175
ACCESS_MASK MmMakeFileAccess[8]
Definition: section.c:33
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:2927
NTSTATUS NTAPI IoSetInformation(IN PFILE_OBJECT FileObject, IN FILE_INFORMATION_CLASS FileInformationClass, IN ULONG Length, IN PVOID FileInformation)
Definition: iofunc.c:1201
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
#define SEC_NOCACHE
Definition: mmtypes.h:100
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
#define STATUS_END_OF_FILE
Definition: shellext.h:50
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:2411
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_opt_ PLARGE_INTEGER _In_ ULONG SectionPageProtection
Definition: mmfuncs.h:360
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
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
LONG NTSTATUS
Definition: precomp.h:26
return Iosb
Definition: create.c:4426
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
NTSTATUS NTAPI MmCreatePageFileSection(PROS_SECTION_OBJECT *SectionObject, ACCESS_MASK DesiredAccess, POBJECT_ATTRIBUTES ObjectAttributes, PLARGE_INTEGER UMaximumSize, ULONG SectionPageProtection, ULONG AllocationAttributes)
Definition: section.c:2812
ULONG NTAPI MiMakeProtectionMask(IN ULONG Protect)
Definition: section.c:159
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:3701
#define STATUS_INVALID_FILE_FOR_SECTION
Definition: ntstatus.h:255
#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
_In_ PLARGE_INTEGER ByteOffset
Definition: mrx.h:173
static HANDLE FileHandle
Definition: cabinet.c:48
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:2887
_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
LONGLONG QuadPart
Definition: typedefs.h:112
BOOLEAN NTAPI MmFlushImageSection ( IN PSECTION_OBJECT_POINTERS  SectionObjectPointer,
IN MMFLUSH_TYPE  FlushType 
)

Definition at line 4769 of file section.c.

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

4771 {
4772  BOOLEAN Result = TRUE;
4773 #ifdef NEWCC
4775 #endif
4776 
4777  switch(FlushType)
4778  {
4779  case MmFlushForDelete:
4780  if (SectionObjectPointer->ImageSectionObject ||
4781  SectionObjectPointer->DataSectionObject)
4782  {
4783  return FALSE;
4784  }
4785 #ifndef NEWCC
4787 #endif
4788  return TRUE;
4789  case MmFlushForWrite:
4790  {
4791  DPRINT("MmFlushImageSection(%d)\n", FlushType);
4792 #ifdef NEWCC
4793  Segment = (PMM_SECTION_SEGMENT)SectionObjectPointer->DataSectionObject;
4794 #endif
4795 
4796  if (SectionObjectPointer->ImageSectionObject)
4797  {
4798  DPRINT1("SectionObject has ImageSection\n");
4799  return FALSE;
4800  }
4801 
4802 #ifdef NEWCC
4803  CcpLock();
4804  Result = !SectionObjectPointer->SharedCacheMap || (Segment->ReferenceCount == CcpCountCacheSections((PNOCC_CACHE_MAP)SectionObjectPointer->SharedCacheMap));
4805  CcpUnlock();
4806  DPRINT("Result %d\n", Result);
4807 #endif
4808  return Result;
4809  }
4810  }
4811  return FALSE;
4812 }
#define TRUE
Definition: types.h:120
#define CcpLock()
Definition: newcc.h:140
_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
_Must_inspect_result_ _In_ PDEVICE_OBJECT _In_ PSECTION_OBJECT_POINTERS SectionObjectPointer
Definition: fsrtlfuncs.h:1368
#define FALSE
Definition: types.h:117
void DPRINT(...)
Definition: polytest.cpp:61
IN PFCB IN FAT_FLUSH_TYPE FlushType
Definition: fatprocs.h:1071
_Inout_ PVOID Segment
Definition: exfuncs.h:893
unsigned char BOOLEAN
if(!(yy_init))
Definition: macro.lex.yy.c:717
struct _MM_SECTION_SEGMENT * PMM_SECTION_SEGMENT
VOID NTAPI CcRosRemoveIfClosed(PSECTION_OBJECT_POINTERS SectionObjectPointer)
Definition: view.c:1281
ULONG ReferenceCount
Definition: mm.h:166
ULONG NTAPI CcpCountCacheSections(IN PNOCC_CACHE_MAP Map)
Definition: fssup.c:270
#define DPRINT1
Definition: precomp.h:8
#define CcpUnlock()
Definition: newcc.h:141
static VOID MmFreeSectionPage ( PVOID  Context,
MEMORY_AREA MemoryArea,
PVOID  Address,
PFN_NUMBER  Page,
SWAPENTRY  SwapEntry,
BOOLEAN  Dirty 
)
static

Definition at line 3941 of file section.c.

Referenced by MmUnmapViewOfSegment().

3943 {
3944  ULONG_PTR Entry;
3945 #ifndef NEWCC
3947  PROS_SHARED_CACHE_MAP SharedCacheMap;
3948 #endif
3950  SWAPENTRY SavedSwapEntry;
3951  PROS_SECTION_OBJECT Section;
3955 
3956  AddressSpace = (PMMSUPPORT)Context;
3957  Process = MmGetAddressSpaceOwner(AddressSpace);
3958 
3960 
3961  Offset.QuadPart = ((ULONG_PTR)Address - MA_GetStartingAddress(MemoryArea)) +
3962  MemoryArea->Data.SectionData.ViewOffset.QuadPart;
3963 
3964  Section = MemoryArea->Data.SectionData.Section;
3965  Segment = MemoryArea->Data.SectionData.Segment;
3966 
3967  Entry = MmGetPageEntrySectionSegment(Segment, &Offset);
3968  while (Entry && MM_IS_WAIT_PTE(Entry))
3969  {
3970  MmUnlockSectionSegment(Segment);
3971  MmUnlockAddressSpace(AddressSpace);
3972 
3974 
3975  MmLockAddressSpace(AddressSpace);
3976  MmLockSectionSegment(Segment);
3977  Entry = MmGetPageEntrySectionSegment(Segment, &Offset);
3978  }
3979 
3980  /*
3981  * For a dirty, datafile, non-private page mark it as dirty in the
3982  * cache manager.
3983  */
3984  if (Segment->Flags & MM_DATAFILE_SEGMENT)
3985  {
3986  if (Page == PFN_FROM_SSE(Entry) && Dirty)
3987  {
3988 #ifndef NEWCC
3989  FileObject = MemoryArea->Data.SectionData.Section->FileObject;
3990  SharedCacheMap = FileObject->SectionObjectPointer->SharedCacheMap;
3991  CcRosMarkDirtyFile(SharedCacheMap, Offset.QuadPart + Segment->Image.FileOffset);
3992 #endif
3993  ASSERT(SwapEntry == 0);
3994  }
3995  }
3996 
3997  if (SwapEntry != 0)
3998  {
3999  /*
4000  * Sanity check
4001  */
4002  if (Segment->Flags & MM_PAGEFILE_SEGMENT)
4003  {
4004  DPRINT1("Found a swap entry for a page in a pagefile section.\n");
4005  KeBugCheck(MEMORY_MANAGEMENT);
4006  }
4007  MmFreeSwapPage(SwapEntry);
4008  }
4009  else if (Page != 0)
4010  {
4011  if (IS_SWAP_FROM_SSE(Entry) ||
4012  Page != PFN_FROM_SSE(Entry))
4013  {
4014  /*
4015  * Sanity check
4016  */
4017  if (Segment->Flags & MM_PAGEFILE_SEGMENT)
4018  {
4019  DPRINT1("Found a private page in a pagefile section.\n");
4020  KeBugCheck(MEMORY_MANAGEMENT);
4021  }
4022  /*
4023  * Just dereference private pages
4024  */
4025  SavedSwapEntry = MmGetSavedSwapEntryPage(Page);
4026  if (SavedSwapEntry != 0)
4027  {
4028  MmFreeSwapPage(SavedSwapEntry);
4029  MmSetSavedSwapEntryPage(Page, 0);
4030  }
4031  MmDeleteRmap(Page, Process, Address);
4033  }
4034  else
4035  {
4036  MmDeleteRmap(Page, Process, Address);
4037  MmUnsharePageEntrySectionSegment(Section, Segment, &Offset, Dirty, FALSE, NULL);
4038  }
4039  }
4040 }
DWORD *typedef PVOID
Definition: winlogon.h:61
PVOID ULONG Address
Definition: oprghdlr.h:14
struct _Entry Entry
Definition: kefuncs.h:640
#define PFN_FROM_SSE(E)
Definition: newmm.h:7
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
#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:1410
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
#define FALSE
Definition: types.h:117
BOOLEAN NTAPI MmUnsharePageEntrySectionSegment(PROS_SECTION_OBJECT Section, PMM_SECTION_SEGMENT Segment, PLARGE_INTEGER Offset, BOOLEAN Dirty, BOOLEAN PageOut, ULONG_PTR *InEntry)
Definition: section.c:876
smooth NULL
Definition: ftsmooth.c:416
VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1469
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
_Inout_ PVOID Segment
Definition: exfuncs.h:893
struct _MMSUPPORT * PMMSUPPORT
struct _MEMORY_AREA::@1716::@1717 SectionData
#define MM_DATAFILE_SEGMENT
Definition: mm.h:91
* PFILE_OBJECT
Definition: iotypes.h:1954
ULONG Flags
Definition: mm.h:169
#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:1417
NTSTATUS NTAPI CcRosMarkDirtyFile(PROS_SHARED_CACHE_MAP SharedCacheMap, LONGLONG FileOffset)
Definition: view.c:565
#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
struct _MM_SECTION_SEGMENT::@1713 Image
#define ULONG_PTR
Definition: config.h:101
union _MEMORY_AREA::@1716 Data
#define MmUnlockSectionSegment(x)
Definition: newmm.h:284
FORCEINLINE VOID MmLockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1403
#define MmGetPageEntrySectionSegment(S, O)
Definition: newmm.h:143
VOID NTAPI MmFreeSwapPage(SWAPENTRY Entry)
Definition: pagefile.c:278
LONGLONG QuadPart
Definition: typedefs.h:112
SWAPENTRY NTAPI MmGetSavedSwapEntryPage(PFN_NUMBER Page)
Definition: freelist.c:470
VOID NTAPI MmFreeSectionSegments ( PFILE_OBJECT  FileObject)

Definition at line 804 of file section.c.

Referenced by CcRosDereferenceCache(), and CcRosReleaseFileCache().

805 {
806  if (FileObject->SectionObjectPointer->ImageSectionObject != NULL)
807  {
809  PMM_SECTION_SEGMENT SectionSegments;
810  ULONG NrSegments;
811  ULONG i;
812 
813  ImageSectionObject = (PMM_IMAGE_SECTION_OBJECT)FileObject->SectionObjectPointer->ImageSectionObject;
814  NrSegments = ImageSectionObject->NrSegments;
815  SectionSegments = ImageSectionObject->Segments;
816  for (i = 0; i < NrSegments; i++)
817  {
818  if (SectionSegments[i].ReferenceCount != 0)
819  {
820  DPRINT1("Image segment %lu still referenced (was %lu)\n", i,
821  SectionSegments[i].ReferenceCount);
822  KeBugCheck(MEMORY_MANAGEMENT);
823  }
824  MmFreePageTablesSectionSegment(&SectionSegments[i], NULL);
825  }
826  ExFreePool(ImageSectionObject->Segments);
827  ExFreePool(ImageSectionObject);
828  FileObject->SectionObjectPointer->ImageSectionObject = NULL;
829  }
830  if (FileObject->SectionObjectPointer->DataSectionObject != NULL)
831  {
833 
834  Segment = (PMM_SECTION_SEGMENT)FileObject->SectionObjectPointer->
835  DataSectionObject;
836 
837  if (Segment->ReferenceCount != 0)
838  {
839  DPRINT1("Data segment still referenced\n");
840  KeBugCheck(MEMORY_MANAGEMENT);
841  }
843  ExFreePool(Segment);
844  FileObject->SectionObjectPointer->DataSectionObject = NULL;
845  }
846 }
IN SIZE_T IN PVOID OUT PMM_IMAGE_SECTION_OBJECT ImageSectionObject
Definition: exeformat.h:53
GLenum GLclampf GLint i
Definition: glfuncs.h:14
smooth NULL
Definition: ftsmooth.c:416
VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1469
_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:717
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
ULONG ReferenceCount
Definition: mm.h:166
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
NTSTATUS INIT_FUNCTION NTAPI MmInitSectionImplementation ( VOID  )

Definition at line 2780 of file section.c.

Referenced by MmInitSystem().

2781 {
2782  OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;
2784 
2785  DPRINT("Creating Section Object Type\n");
2786 
2787  /* Initialize the section based root */
2790 
2791  /* Initialize the Section object type */
2792  RtlZeroMemory(&ObjectTypeInitializer, sizeof(ObjectTypeInitializer));
2793  RtlInitUnicodeString(&Name, L"Section");
2794  ObjectTypeInitializer.Length = sizeof(ObjectTypeInitializer);
2795  ObjectTypeInitializer.DefaultPagedPoolCharge = sizeof(ROS_SECTION_OBJECT);
2796  ObjectTypeInitializer.PoolType = PagedPool;
2797  ObjectTypeInitializer.UseDefaultObject = TRUE;
2798  ObjectTypeInitializer.GenericMapping = MmpSectionMapping;
2799  ObjectTypeInitializer.DeleteProcedure = MmpDeleteSection;
2800  ObjectTypeInitializer.CloseProcedure = MmpCloseSection;
2801  ObjectTypeInitializer.ValidAccessMask = SECTION_ALL_ACCESS;
2802  ObjectTypeInitializer.InvalidAttributes = OBJ_OPENLINK;
2803  ObCreateObjectType(&Name, &ObjectTypeInitializer, NULL, &MmSectionObjectType);
2804 
2806 
2807  return(STATUS_SUCCESS);
2808 }
NTSTATUS NTAPI ObCreateObjectType(IN PUNICODE_STRING TypeName, IN POBJECT_TYPE_INITIALIZER ObjectTypeInitializer, IN PVOID Reserved, OUT POBJECT_TYPE *ObjectType)
Definition: oblife.c:1034
#define TRUE
Definition: types.h:120
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
VOID NTAPI MmpCloseSection(IN PEPROCESS Process OPTIONAL, IN PVOID Object, IN ACCESS_MASK GrantedAccess, IN ULONG ProcessHandleCount, IN ULONG SystemHandleCount)
Definition: section.c:2717
ULONG_PTR NumberGenericTableElements
Definition: mmtypes.h:669
MM_AVL_TABLE MmSectionBasedRoot
Definition: section.c:110
#define OBJ_OPENLINK
Definition: winternl.h:230
MMADDRESS_NODE BalancedRoot
Definition: mmtypes.h:663
#define SECTION_ALL_ACCESS
Definition: nt_native.h:1293
static GENERIC_MAPPING MmpSectionMapping
Definition: section.c:166
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
OB_CLOSE_METHOD CloseProcedure
Definition: obtypes.h:368
union _MMADDRESS_NODE::@2485 u1
struct _ROS_SECTION_OBJECT ROS_SECTION_OBJECT
POBJECT_TYPE MmSectionObjectType
Definition: section.c:136
NTSTATUS INIT_FUNCTION NTAPI MmCreatePhysicalMemorySection(VOID)
Definition: section.c:2729
_In_ PUNICODE_STRING Name
Definition: mrx.h:218
static const WCHAR L[]
Definition: oid.c:1087
VOID NTAPI MmpDeleteSection(PVOID ObjectBody)
Definition: section.c:2618
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:2710
OB_DELETE_METHOD DeleteProcedure
Definition: obtypes.h:369
struct _MMADDRESS_NODE * Parent
Definition: mmtypes.h:650
NTSTATUS NTAPI MmMapViewInSystemSpace ( IN PVOID  SectionObject,
OUT PVOID MappedBase,
IN OUT PSIZE_T  ViewSize 
)

Definition at line 4818 of file section.c.

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

4821 {
4822  PROS_SECTION_OBJECT Section;
4824  NTSTATUS Status;
4825  PAGED_CODE();
4826 
4828  {
4830  &MmSession,
4831  MappedBase,
4832  ViewSize);
4833  }
4834 
4835  DPRINT("MmMapViewInSystemSpace() called\n");
4836 
4838  AddressSpace = MmGetKernelAddressSpace();
4839 
4840  MmLockAddressSpace(AddressSpace);
4841 
4842 
4843  if ((*ViewSize) == 0)
4844  {
4845  (*ViewSize) = Section->MaximumSize.u.LowPart;
4846  }
4847  else if ((*ViewSize) > Section->MaximumSize.u.LowPart)
4848  {
4849  (*ViewSize) = Section->MaximumSize.u.LowPart;
4850  }
4851 
4852  MmLockSectionSegment(Section->Segment);
4853 
4854 
4855  Status = MmMapViewOfSegment(AddressSpace,
4856  Section,
4857  Section->Segment,
4858  MappedBase,
4859  *ViewSize,
4861  0,
4862  0);
4863 
4864  MmUnlockSectionSegment(Section->Segment);
4865  MmUnlockAddressSpace(AddressSpace);
4866 
4867  return Status;
4868 }
_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:1410
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:3864
#define PAGED_CODE()
Definition: video.h:57
#define FALSE
Definition: types.h:117
void DPRINT(...)
Definition: polytest.cpp:61
LONG NTSTATUS
Definition: precomp.h:26
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:1053
Status
Definition: gdiplustypes.h:24
FORCEINLINE PMMSUPPORT MmGetKernelAddressSpace(VOID)
Definition: mm.h:1432
_Must_inspect_result_ _Outptr_result_bytebuffer_ ViewSize PVOID * MappedBase
Definition: mmfuncs.h:493
#define MmLockSectionSegment(x)
Definition: newmm.h:276
struct _LARGE_INTEGER::@2192 u
_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:1403
#define PAGE_READWRITE
Definition: nt_native.h:1304
FORCEINLINE BOOLEAN MiIsRosSectionObject(IN PVOID Section)
Definition: miarm.h:1036
MMSESSION MmSession
Definition: section.c:108
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 2834 of file section.c.

Referenced by MmMapViewOfSection().

2844 {
2847  PSECTION Section;
2848  PCONTROL_AREA ControlArea;
2849  ULONG ProtectionMask;
2850  NTSTATUS Status;
2851  ULONG64 CalculatedViewSize;
2852  PAGED_CODE();
2853 
2854  /* Get the segment and control area */
2855  Section = (PSECTION)SectionObject;
2856  ControlArea = Section->Segment->ControlArea;
2857 
2858  /* These flags/states are not yet supported by ARM3 */
2859  ASSERT(Section->u.Flags.Image == 0);
2860  ASSERT(Section->u.Flags.NoCache == 0);
2861  ASSERT(Section->u.Flags.WriteCombined == 0);
2862  ASSERT(ControlArea->u.Flags.PhysicalMemory == 0);
2863 
2864  /* FIXME */
2865  if ((AllocationType & MEM_RESERVE) != 0)
2866  {
2867  DPRINT1("MmMapViewOfArm3Section called with MEM_RESERVE, this is not implemented yet!!!\n");
2868  return STATUS_NOT_IMPLEMENTED;
2869  }
2870 
2871  /* Check if the mapping protection is compatible with the create */
2873  {
2874  DPRINT1("Mapping protection is incompatible\n");
2876  }
2877 
2878  /* Check if the offset and size would cause an overflow */
2879  if (((ULONG64)SectionOffset->QuadPart + *ViewSize) <
2881  {
2882  DPRINT1("Section offset overflows\n");
2883  return STATUS_INVALID_VIEW_SIZE;
2884  }
2885 
2886  /* Check if the offset and size are bigger than the section itself */
2887  if (((ULONG64)SectionOffset->QuadPart + *ViewSize) >
2888  (ULONG64)Section->SizeOfSection.QuadPart)
2889  {
2890  DPRINT1("Section offset is larger than section\n");
2891  return STATUS_INVALID_VIEW_SIZE;
2892  }
2893 
2894  /* Check if the caller did not specify a view size */
2895  if (!(*ViewSize))
2896  {
2897  /* Compute it for the caller */
2898  CalculatedViewSize = Section->SizeOfSection.QuadPart -
2900 
2901  /* Check if it's larger than 4GB or overflows into kernel-mode */
2902  if (!NT_SUCCESS(RtlULongLongToSIZET(CalculatedViewSize, ViewSize)) ||
2903  (((ULONG_PTR)MM_HIGHEST_VAD_ADDRESS - (ULONG_PTR)*BaseAddress) < CalculatedViewSize))
2904  {
2905  DPRINT1("Section view won't fit\n");
2906  return STATUS_INVALID_VIEW_SIZE;
2907  }
2908  }
2909 
2910  /* Check if the commit size is larger than the view size */
2911  if (CommitSize > *ViewSize)
2912  {
2913  DPRINT1("Attempting to commit more than the view itself\n");
2915  }
2916 
2917  /* Check if the view size is larger than the section */
2918  if (*ViewSize > (ULONG64)Section->SizeOfSection.QuadPart)
2919  {
2920  DPRINT1("The view is larger than the section\n");
2921  return STATUS_INVALID_VIEW_SIZE;
2922  }
2923 
2924  /* Compute and validate the protection mask */
2925  ProtectionMask = MiMakeProtectionMask(Protect);
2926  if (ProtectionMask == MM_INVALID_PROTECTION)
2927  {
2928  DPRINT1("The protection is invalid\n");
2930  }
2931 
2932  /* We only handle pagefile-backed sections, which cannot be writecombined */
2933  if (Protect & PAGE_WRITECOMBINE)
2934  {
2935  DPRINT1("Cannot write combine a pagefile-backed section\n");
2937  }
2938 
2939  /* Start by attaching to the current process if needed */
2940  if (PsGetCurrentProcess() != Process)
2941  {
2942  KeStackAttachProcess(&Process->Pcb, &ApcState);
2943  Attached = TRUE;
2944  }
2945 
2946  /* Do the actual mapping */
2947  Status = MiMapViewOfDataSection(ControlArea,
2948  Process,
2949  BaseAddress,
2950  SectionOffset,
2951  ViewSize,
2952  Section,
2954  ProtectionMask,
2955  CommitSize,
2956  ZeroBits,
2957  AllocationType);
2958 
2959  /* Detach if needed, then return status */
2960  if (Attached) KeUnstackDetachProcess(&ApcState);
2961  return Status;
2962 }
_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:118
PSEGMENT Segment
Definition: mmtypes.h:813
#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:465
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
ULONG InitialPageProtection
Definition: mmtypes.h:820
#define PAGED_CODE()
Definition: video.h:57
struct _CONTROL_AREA * ControlArea
Definition: mmtypes.h:401
uint32_t ULONG_PTR
Definition: typedefs.h:63
union _SECTION::@2496 u
static BOOL Attached
Definition: vidbios.c:3905
#define FALSE
Definition: types.h:117
VOID NTAPI KeStackAttachProcess(IN PKPROCESS Process, OUT PRKAPC_STATE ApcState)
Definition: procobj.c:701
LARGE_INTEGER SizeOfSection
Definition: mmtypes.h:814
#define MEM_RESERVE
Definition: nt_native.h:1314
#define PsGetCurrentProcess
Definition: psfuncs.h:17
struct _SECTION * PSECTION
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T _Inout_opt_ PLARGE_INTEGER SectionOffset
Definition: mmfuncs.h:404
#define STATUS_INVALID_PARAMETER_5
Definition: ntstatus.h:465
unsigned char BOOLEAN
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
ULONG NTAPI MiMakeProtectionMask(IN ULONG Protect)
Definition: section.c:159
_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
unsigned __int64 ULONG64
Definition: imports.h:198
MMSECTION_FLAGS Flags
Definition: mmtypes.h:818
#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:1471
#define DPRINT1
Definition: precomp.h:8
#define MM_HIGHEST_VAD_ADDRESS
Definition: mm.h:42
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
union _CONTROL_AREA::@2480 u
_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:523
unsigned int ULONG
Definition: retypes.h:1
NTSTATUS NTAPI MiMapViewOfDataSection(IN PCONTROL_AREA ControlArea, IN PEPROCESS Process, IN PVOID *BaseAddress, IN PLARGE_INTEGER SectionOffset, IN PSIZE_T ViewSize, IN PSECTION Section, IN SECTION_INHERIT InheritDisposition, IN ULONG ProtectionMask, IN SIZE_T CommitSize, IN ULONG_PTR ZeroBits, IN ULONG AllocationType)
Definition: section.c:1253
ULONG WriteCombined
Definition: mmtypes.h:485
LONGLONG QuadPart
Definition: typedefs.h:112
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 4473 of file section.c.

Referenced by _Function_class_(), _Success_(), ExpInitNls(), GDI_MapHandleTable(), IntMapDesktopView(), IntUserHeapCreate(), MapGlobalUserHeap(), MiLoadImageSection(), MmCreatePeb(), MmInitializeProcessAddressSpace(), NtMapViewOfSection(), NtSecureConnectPort(), and PspMapSystemDll().

4483 {
4484  PROS_SECTION_OBJECT Section;
4486  ULONG ViewOffset;
4488  BOOLEAN NotAtBase = FALSE;
4489 
4491  {
4492  DPRINT("Mapping ARM3 section into %s\n", Process->ImageFileName);
4494  Process,
4495  BaseAddress,
4496  ZeroBits,
4497  CommitSize,
4498  SectionOffset,
4499  ViewSize,
4502  Protect);
4503  }
4504 
4505  ASSERT(Process);
4506 
4508  {
4510  }
4511 
4512  /* FIXME: We should keep this, but it would break code checking equality */
4513  Protect &= ~PAGE_NOCACHE;
4514 
4516  AddressSpace = &Process->Vm;
4517 
4519 
4520  MmLockAddressSpace(AddressSpace);
4521 
4522  if (Section->AllocationAttributes & SEC_IMAGE)
4523  {
4524  ULONG i;
4525  ULONG NrSegments;
4526  ULONG_PTR ImageBase;
4527  SIZE_T ImageSize;
4529  PMM_SECTION_SEGMENT SectionSegments;
4530 
4531  ImageSectionObject = Section->ImageSection;
4532  SectionSegments = ImageSectionObject->Segments;
4533  NrSegments = ImageSectionObject->NrSegments;
4534 
4535  ImageBase = (ULONG_PTR)*BaseAddress;
4536  if (ImageBase == 0)
4537  {
4538  ImageBase = (ULONG_PTR)ImageSectionObject->BasedAddress;
4539  }
4540 
4541  ImageSize = 0;
4542  for (i = 0; i < NrSegments; i++)
4543  {
4544  ULONG_PTR MaxExtent;
4545  MaxExtent = (ULONG_PTR)(SectionSegments[i].Image.VirtualAddress +
4546  SectionSegments[i].Length.QuadPart);
4547  ImageSize = max(ImageSize, MaxExtent);
4548  }
4549 
4550  ImageSectionObject->ImageInformation.ImageFileSize = (ULONG)ImageSize;
4551 
4552  /* Check for an illegal base address */
4553  if (((ImageBase + ImageSize) > (ULONG_PTR)MmHighestUserAddress) ||
4554  ((ImageBase + ImageSize) < ImageSize))
4555  {
4556  ASSERT(*BaseAddress == NULL);
4557  ImageBase = ALIGN_DOWN_BY((ULONG_PTR)MmHighestUserAddress - ImageSize,
4559  NotAtBase = TRUE;
4560  }
4561  else if (ImageBase != ALIGN_DOWN_BY(ImageBase, MM_VIRTMEM_GRANULARITY))
4562  {
4563  ASSERT(*BaseAddress == NULL);
4564  ImageBase = ALIGN_DOWN_BY(ImageBase, MM_VIRTMEM_GRANULARITY);
4565  NotAtBase = TRUE;
4566  }
4567 
4568  /* Check there is enough space to map the section at that point. */
4569  if (MmLocateMemoryAreaByRegion(AddressSpace, (PVOID)ImageBase,
4570  PAGE_ROUND_UP(ImageSize)) != NULL)
4571  {
4572  /* Fail if the user requested a fixed base address. */
4573  if ((*BaseAddress) != NULL)
4574  {
4575  MmUnlockAddressSpace(AddressSpace);
4577  }
4578  /* Otherwise find a gap to map the image. */
4579  ImageBase = (ULONG_PTR)MmFindGap(AddressSpace, PAGE_ROUND_UP(ImageSize), MM_VIRTMEM_GRANULARITY, FALSE);
4580  if (ImageBase == 0)
4581  {
4582  MmUnlockAddressSpace(AddressSpace);
4584  }
4585  /* Remember that we loaded image at a different base address */
4586  NotAtBase = TRUE;
4587  }
4588 
4589  for (i = 0; i < NrSegments; i++)
4590  {
4591  PVOID SBaseAddress = (PVOID)
4592  ((char*)ImageBase + (ULONG_PTR)SectionSegments[i].Image.VirtualAddress);
4593  MmLockSectionSegment(&SectionSegments[i]);
4594  Status = MmMapViewOfSegment(AddressSpace,
4595  Section,
4596  &SectionSegments[i],
4597  &SBaseAddress,
4598  SectionSegments[i].Length.LowPart,
4599  SectionSegments[i].Protection,
4600  0,
4601  0);
4602  MmUnlockSectionSegment(&SectionSegments[i]);
4603  if (!NT_SUCCESS(Status))
4604  {
4605  MmUnlockAddressSpace(AddressSpace);
4606  return(Status);
4607  }
4608  }
4609 
4610  *BaseAddress = (PVOID)ImageBase;
4611  *ViewSize = ImageSize;
4612  }
4613  else
4614  {
4615  /* check for write access */
4618  {
4619  MmUnlockAddressSpace(AddressSpace);
4621  }
4622  /* check for read access */
4625  {
4626  MmUnlockAddressSpace(AddressSpace);
4628  }
4629  /* check for execute access */
4632  {
4633  MmUnlockAddressSpace(AddressSpace);
4635  }
4636 
4637  if (SectionOffset == NULL)
4638  {
4639  ViewOffset = 0;
4640  }
4641  else
4642  {
4643  ViewOffset = SectionOffset->u.LowPart;
4644  }
4645 
4646  if ((ViewOffset % PAGE_SIZE) != 0)
4647  {
4648  MmUnlockAddressSpace(AddressSpace);
4649  return(STATUS_MAPPED_ALIGNMENT);
4650  }
4651 
4652  if ((*ViewSize) == 0)
4653  {
4654  (*ViewSize) = Section->MaximumSize.u.LowPart - ViewOffset;
4655  }
4656  else if (((*ViewSize)+ViewOffset) > Section->MaximumSize.u.LowPart)
4657  {
4658  (*ViewSize) = Section->MaximumSize.u.LowPart - ViewOffset;
4659  }
4660 
4662 
4663