ReactOS  r76032
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, PFN_NUMBER SrcPage)
 
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:1071
Definition: movable.cpp:7
void DPRINT(...)
Definition: polytest.cpp:61
static const WCHAR E[]
Definition: oid.c:1073

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

Referenced by ExeFmtpCreateImageSection().

3121 {
3122  SIZE_T SizeOfSegments;
3123  PMM_SECTION_SEGMENT Segments;
3124 
3125  /* TODO: check for integer overflow */
3126  SizeOfSegments = sizeof(MM_SECTION_SEGMENT) * NrSegments;
3127 
3129  SizeOfSegments,
3131 
3132  if(Segments)
3133  RtlZeroMemory(Segments, SizeOfSegments);
3134 
3135  return Segments;
3136 }
#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 3562 of file section.c.

Referenced by MmCreateImageSection().

3564 {
3566  PVOID FileHeader;
3567  PVOID FileHeaderBuffer;
3569  ULONG Flags;
3570  ULONG OldNrSegments;
3571  NTSTATUS Status;
3572  ULONG i;
3573 
3574  /*
3575  * Read the beginning of the file (2 pages). Should be enough to contain
3576  * all (or most) of the headers
3577  */
3578  Offset.QuadPart = 0;
3579 
3580  Status = ExeFmtpReadFile (FileObject,
3581  &Offset,
3582  PAGE_SIZE * 2,
3583  &FileHeader,
3584  &FileHeaderBuffer,
3585  &FileHeaderSize);
3586 
3587  if (!NT_SUCCESS(Status))
3588  return Status;
3589 
3590  if (FileHeaderSize == 0)
3591  {
3592  ExFreePool(FileHeaderBuffer);
3593  return STATUS_UNSUCCESSFUL;
3594  }
3595 
3596  /*
3597  * Look for a loader that can handle this executable
3598  */
3599  for (i = 0; i < RTL_NUMBER_OF(ExeFmtpLoaders); ++ i)
3600  {
3601  RtlZeroMemory(ImageSectionObject, sizeof(*ImageSectionObject));
3602  Flags = 0;
3603 
3604  Status = ExeFmtpLoaders[i](FileHeader,
3606  FileObject,
3608  &Flags,
3611 
3612  if (!NT_SUCCESS(Status))
3613  {
3614  if (ImageSectionObject->Segments)
3615  {
3616  ExFreePool(ImageSectionObject->Segments);
3617  ImageSectionObject->Segments = NULL;
3618  }
3619  }
3620 
3621  if (Status != STATUS_ROS_EXEFMT_UNKNOWN_FORMAT)
3622  break;
3623  }
3624 
3625  ExFreePoolWithTag(FileHeaderBuffer, 'rXmM');
3626 
3627  /*
3628  * No loader handled the format
3629  */
3630  if (Status == STATUS_ROS_EXEFMT_UNKNOWN_FORMAT)
3631  {
3632  Status = STATUS_INVALID_IMAGE_NOT_MZ;
3633  ASSERT(!NT_SUCCESS(Status));
3634  }
3635 
3636  if (!NT_SUCCESS(Status))
3637  return Status;
3638 
3639  ASSERT(ImageSectionObject->Segments != NULL);
3640 
3641  /*
3642  * Some defaults
3643  */
3644  /* FIXME? are these values platform-dependent? */
3645  if (ImageSectionObject->ImageInformation.MaximumStackSize == 0)
3646  ImageSectionObject->ImageInformation.MaximumStackSize = 0x40000;
3647 
3648  if(ImageSectionObject->ImageInformation.CommittedStackSize == 0)
3649  ImageSectionObject->ImageInformation.CommittedStackSize = 0x1000;
3650 
3651  if(ImageSectionObject->BasedAddress == NULL)
3652  {
3653  if(ImageSectionObject->ImageInformation.ImageCharacteristics & IMAGE_FILE_DLL)
3654  ImageSectionObject->BasedAddress = (PVOID)0x10000000;
3655  else
3656  ImageSectionObject->BasedAddress = (PVOID)0x00400000;
3657  }
3658 
3659  /*
3660  * And now the fun part: fixing the segments
3661  */
3662 
3663  /* Sort them by virtual address */
3664  MmspSortSegments(ImageSectionObject, Flags);
3665 
3666  /* Ensure they don't overlap in memory */
3667  if (!MmspCheckSegmentBounds(ImageSectionObject, Flags))
3669 
3670  /* Ensure they are aligned */
3671  OldNrSegments = ImageSectionObject->NrSegments;
3672 
3673  if (!MmspPageAlignSegments(ImageSectionObject, Flags))
3675 
3676  /* Trim them if the alignment phase merged some of them */
3677  if (ImageSectionObject->NrSegments < OldNrSegments)
3678  {
3679  PMM_SECTION_SEGMENT Segments;
3680  SIZE_T SizeOfSegments;
3681 
3682  SizeOfSegments = sizeof(MM_SECTION_SEGMENT) * ImageSectionObject->NrSegments;
3683 
3684  Segments = ExAllocatePoolWithTag(PagedPool,
3685  SizeOfSegments,
3687 
3688  if (Segments == NULL)
3690 
3691  RtlCopyMemory(Segments, ImageSectionObject->Segments, SizeOfSegments);
3692  ExFreePool(ImageSectionObject->Segments);
3693  ImageSectionObject->Segments = Segments;
3694  }
3695 
3696  /* And finish their initialization */
3697  for ( i = 0; i < ImageSectionObject->NrSegments; ++ i )
3698  {
3699  ExInitializeFastMutex(&ImageSectionObject->Segments[i].Lock);
3700  ImageSectionObject->Segments[i].ReferenceCount = 1;
3701  MiInitializeSectionPageTable(&ImageSectionObject->Segments[i]);
3702  }
3703 
3704  ASSERT(NT_SUCCESS(Status));
3705  return Status;
3706 }
DWORD *typedef PVOID
Definition: winlogon.h:52
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:3379
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:3302
_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:557
_In_ PFILE_OBJECT FileObject
Definition: classpnp.h:1229
static PMM_SECTION_SEGMENT NTAPI ExeFmtpAllocateSegments(IN ULONG NrSegments)
Definition: section.c:3120
#define STATUS_INVALID_IMAGE_NOT_MZ
Definition: ntstatus.h:525
#define STATUS_INVALID_IMAGE_FORMAT
Definition: ntstatus.h:345
#define NT_SUCCESS(StatCode)
Definition: apphelp.c: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:3109
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:3141
#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
LONG NTSTATUS
Definition: DriverTester.h:11
#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:1097
#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:3328
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 3141 of file section.c.

Referenced by ExeFmtpCreateImageSection().

3147 {
3148  NTSTATUS Status;
3150  ULONG AdjustOffset;
3151  ULONG OffsetAdjustment;
3152  ULONG BufferSize;
3153  ULONG UsedSize;
3154  PVOID Buffer;
3157 
3159 
3160  if(Length == 0)
3161  {
3162  KeBugCheck(MEMORY_MANAGEMENT);
3163  }
3164 
3165  FileOffset = *Offset;
3166 
3167  /* Negative/special offset: it cannot be used in this context */
3168  if(FileOffset.u.HighPart < 0)
3169  {
3170  KeBugCheck(MEMORY_MANAGEMENT);
3171  }
3172 
3173  AdjustOffset = PAGE_ROUND_DOWN(FileOffset.u.LowPart);
3174  OffsetAdjustment = FileOffset.u.LowPart - AdjustOffset;
3175  FileOffset.u.LowPart = AdjustOffset;
3176 
3177  BufferSize = Length + OffsetAdjustment;
3178  BufferSize = PAGE_ROUND_UP(BufferSize);
3179 
3180  /* Flush data since we're about to perform a non-cached read */
3181  CcFlushCache(FileObject->SectionObjectPointer,
3182  &FileOffset,
3183  BufferSize,
3184  &Iosb);
3185 
3186  /*
3187  * It's ok to use paged pool, because this is a temporary buffer only used in
3188  * the loading of executables. The assumption is that MmCreateSection is
3189  * always called at low IRQLs and that these buffers don't survive a brief
3190  * initialization phase
3191  */
3193  BufferSize,
3194  'rXmM');
3195  if (!Buffer)
3196  {
3198  }
3199 
3200  UsedSize = 0;
3201 
3202  Status = MiSimpleRead(FileObject, &FileOffset, Buffer, BufferSize, TRUE, &Iosb);
3203 
3204  UsedSize = (ULONG)Iosb.Information;
3205 
3206  if(NT_SUCCESS(Status) && UsedSize < OffsetAdjustment)
3207  {
3208  Status = STATUS_IN_PAGE_ERROR;
3209  ASSERT(!NT_SUCCESS(Status));
3210  }
3211 
3212  if(NT_SUCCESS(Status))
3213  {
3214  *Data = (PVOID)((ULONG_PTR)Buffer + OffsetAdjustment);
3215  *AllocBase = Buffer;
3216  *ReadSize = UsedSize - OffsetAdjustment;
3217  }
3218  else
3219  {
3220  ExFreePoolWithTag(Buffer, 'rXmM');
3221  }
3222 
3223  return Status;
3224 }
DWORD *typedef PVOID
Definition: winlogon.h:52
#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
struct _LARGE_INTEGER::@2037 u
uint32_t ULONG_PTR
Definition: typedefs.h:63
_Must_inspect_result_ _Out_ PIO_STATUS_BLOCK Iosb
Definition: fltkernel.h:1761
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
_In_ PFILE_OBJECT FileObject
Definition: classpnp.h:1229
VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1469
IN PLARGE_INTEGER IN ULONG OUT PVOID OUT PVOID OUT PULONG ReadSize
Definition: exeformat.h:38
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
* PFILE_OBJECT
Definition: iotypes.h:1949
UINTN VOID * Buffer
Definition: acefiex.h:370
#define ASSERT_IRQL_LESS(x)
Definition: debug.h:252
#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
LONG NTSTATUS
Definition: DriverTester.h:11
_In_ PLARGE_INTEGER FileOffset
Definition: cctypes.h:53
unsigned int ULONG
Definition: retypes.h:1
#define STATUS_IN_PAGE_ERROR
Definition: ntstatus.h:229
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1097
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 140 of file section.c.

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

Definition at line 1043 of file section.c.

Referenced by MmAccessFaultSectionView().

1044 {
1046  KIRQL Irql, Irql2;
1047  PVOID DestAddress, SrcAddress;
1048 
1049  Process = PsGetCurrentProcess();
1050  DestAddress = MiMapPageInHyperSpace(Process, DestPage, &Irql);
1051  SrcAddress = MiMapPageInHyperSpace(Process, SrcPage, &Irql2);
1052  if (DestAddress == NULL || SrcAddress == NULL)
1053  {
1054  return(STATUS_NO_MEMORY);
1055  }
1056  ASSERT((ULONG_PTR)DestAddress % PAGE_SIZE == 0);
1057  ASSERT((ULONG_PTR)SrcAddress % PAGE_SIZE == 0);
1058  RtlCopyMemory(DestAddress, SrcAddress, PAGE_SIZE);
1059  MiUnmapPageInHyperSpace(Process, SrcAddress, Irql2);
1060  MiUnmapPageInHyperSpace(Process, DestAddress, Irql);
1061  return(STATUS_SUCCESS);
1062 }
DWORD *typedef PVOID
Definition: winlogon.h:52
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
return STATUS_SUCCESS
Definition: btrfs.c:2664
_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:557
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
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:162
union _MEMORY_AREA::@1561 Data
#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:380
#define IMAGE_SCN_MEM_SHARED
Definition: ntimage.h:238
struct _MEMORY_AREA::@1561::@1562 SectionData
BOOLEAN Valid
Definition: cc.h:169
PROS_VACB NTAPI CcRosLookupVacb(PROS_SHARED_CACHE_MAP SharedCacheMap, LONGLONG FileOffset)
Definition: view.c:433
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 1067 of file section.c.

Referenced by MmNotPresentFaultSectionView().

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

Definition at line 4890 of file section.c.

Referenced by MmUnmapViewInSystemSpace().

4891 {
4893  NTSTATUS Status;
4894 
4895  DPRINT("MmUnmapViewInSystemSpace() called\n");
4896 
4897  AddressSpace = MmGetKernelAddressSpace();
4898 
4899  MmLockAddressSpace(AddressSpace);
4900 
4901  Status = MmUnmapViewOfSegment(AddressSpace, MappedBase);
4902 
4903  MmUnlockAddressSpace(AddressSpace);
4904 
4905  return Status;
4906 }
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG AddressSpace
Definition: iofuncs.h:2268
FORCEINLINE VOID MmUnlockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1350
static NTSTATUS MmUnmapViewOfSegment(PMMSUPPORT AddressSpace, PVOID BaseAddress)
Definition: section.c:4061
void DPRINT(...)
Definition: polytest.cpp:61
Status
Definition: gdiplustypes.h:24
FORCEINLINE PMMSUPPORT MmGetKernelAddressSpace(VOID)
Definition: mm.h:1372
LONG NTSTATUS
Definition: DriverTester.h:11
_Must_inspect_result_ _Outptr_result_bytebuffer_ ViewSize PVOID * MappedBase
Definition: mmfuncs.h:493
FORCEINLINE VOID MmLockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1343
NTSTATUS NTAPI MiRosUnmapViewOfSection ( IN PEPROCESS  Process,
IN PVOID  BaseAddress,
IN BOOLEAN  SkipDebuggerNotify 
)

Definition at line 4126 of file section.c.

Referenced by MiRosCleanupMemoryArea(), and MiUnmapViewOfSection().

4129 {
4130  NTSTATUS Status;
4133  PROS_SECTION_OBJECT Section;
4134  PVOID ImageBaseAddress = 0;
4135 
4136  DPRINT("Opening memory area Process %p BaseAddress %p\n",
4137  Process, BaseAddress);
4138 
4139  ASSERT(Process);
4140 
4141  AddressSpace = Process ? &Process->Vm : MmGetKernelAddressSpace();
4142 
4143  MmLockAddressSpace(AddressSpace);
4144  MemoryArea = MmLocateMemoryAreaByAddress(AddressSpace,
4145  BaseAddress);
4146  if (MemoryArea == NULL ||
4147  ((MemoryArea->Type != MEMORY_AREA_SECTION_VIEW) &&
4148  (MemoryArea->Type != MEMORY_AREA_CACHE)) ||
4149  MemoryArea->DeleteInProgress)
4150  {
4151  if (MemoryArea) ASSERT(MemoryArea->Type != MEMORY_AREA_OWNED_BY_ARM3);
4152  MmUnlockAddressSpace(AddressSpace);
4153  return STATUS_NOT_MAPPED_VIEW;
4154  }
4155 
4156  Section = MemoryArea->Data.SectionData.Section;
4157 
4158  if ((Section != NULL) && (Section->AllocationAttributes & SEC_IMAGE))
4159  {
4160  ULONG i;
4161  ULONG NrSegments;
4163  PMM_SECTION_SEGMENT SectionSegments;
4165 
4166  Segment = MemoryArea->Data.SectionData.Segment;
4167  ImageSectionObject = Section->ImageSection;
4168  SectionSegments = ImageSectionObject->Segments;
4169  NrSegments = ImageSectionObject->NrSegments;
4170 
4171  MemoryArea->DeleteInProgress = TRUE;
4172 
4173  /* Search for the current segment within the section segments
4174  * and calculate the image base address */
4175  for (i = 0; i < NrSegments; i++)
4176  {
4177  if (Segment == &SectionSegments[i])
4178  {
4179  ImageBaseAddress = (char*)BaseAddress - (ULONG_PTR)SectionSegments[i].Image.VirtualAddress;
4180  break;
4181  }
4182  }
4183  if (i >= NrSegments)
4184  {
4185  KeBugCheck(MEMORY_MANAGEMENT);
4186  }
4187 
4188  for (i = 0; i < NrSegments; i++)
4189  {
4190  PVOID SBaseAddress = (PVOID)
4191  ((char*)ImageBaseAddress + (ULONG_PTR)SectionSegments[i].Image.VirtualAddress);
4192 
4193  Status = MmUnmapViewOfSegment(AddressSpace, SBaseAddress);
4194  if (!NT_SUCCESS(Status))
4195  {
4196  DPRINT1("MmUnmapViewOfSegment failed for %p (Process %p) with %lx\n",
4197  SBaseAddress, Process, Status);
4198  ASSERT(NT_SUCCESS(Status));
4199  }
4200  }
4201  }
4202  else
4203  {
4204  Status = MmUnmapViewOfSegment(AddressSpace, BaseAddress);
4205  if (!NT_SUCCESS(Status))
4206  {
4207  DPRINT1("MmUnmapViewOfSegment failed for %p (Process %p) with %lx\n",
4208  BaseAddress, Process, Status);
4209  ASSERT(NT_SUCCESS(Status));
4210  }
4211  }
4212 
4213  MmUnlockAddressSpace(AddressSpace);
4214 
4215  /* Notify debugger */
4216  if (ImageBaseAddress && !SkipDebuggerNotify) DbgkUnMapViewOfSection(ImageBaseAddress);
4217 
4218  return(STATUS_SUCCESS);
4219 }
DWORD *typedef PVOID
Definition: winlogon.h:52
#define TRUE
Definition: types.h:120
union _MEMORY_AREA::@1561 Data
ULONG Type
Definition: mm.h:210
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
return STATUS_SUCCESS
Definition: btrfs.c:2664
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG AddressSpace
Definition: iofuncs.h:2268
FORCEINLINE VOID MmUnlockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1350
struct _MM_SECTION_SEGMENT::@1558 Image
PMEMORY_AREA NTAPI MmLocateMemoryAreaByAddress(PMMSUPPORT AddressSpace, PVOID Address)
Definition: marea.c:60
#define MEMORY_AREA_CACHE
Definition: mm.h:70
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:4061
PMM_IMAGE_SECTION_OBJECT ImageSection
Definition: mm.h:198
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define MEMORY_AREA_OWNED_BY_ARM3
Definition: mm.h:71
smooth NULL
Definition: ftsmooth.c:557
void DPRINT(...)
Definition: polytest.cpp:61
VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1469
#define MEMORY_AREA_SECTION_VIEW
Definition: mm.h:69
_Inout_ PVOID Segment
Definition: exfuncs.h:893
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
PMM_SECTION_SEGMENT Segments
Definition: mm.h:185
BOOLEAN DeleteInProgress
Definition: mm.h:213
VOID NTAPI DbgkUnMapViewOfSection(IN PVOID BaseAddress)
Definition: dbgkutil.c:436
struct _MEMORY_AREA::@1561::@1562 SectionData
Status
Definition: gdiplustypes.h:24
FORCEINLINE PMMSUPPORT MmGetKernelAddressSpace(VOID)
Definition: mm.h:1372
LONG NTSTATUS
Definition: DriverTester.h:11
#define DPRINT1
Definition: precomp.h:8
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
unsigned int ULONG
Definition: retypes.h:1
#define STATUS_NOT_MAPPED_VIEW
Definition: ntstatus.h:248
#define ULONG_PTR
Definition: config.h:101
#define SEC_IMAGE
Definition: mmtypes.h:96
ULONG AllocationAttributes
Definition: mm.h:194
struct _MEMORY_AREA * MemoryArea
Definition: newmm.h:65
FORCEINLINE VOID MmLockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1343
NTSTATUS NTAPI MmAccessFaultSectionView ( PMMSUPPORT  AddressSpace,
MEMORY_AREA MemoryArea,
PVOID  Address 
)

Definition at line 1692 of file section.c.

Referenced by MmpAccessFault().

1695 {
1697  PROS_SECTION_OBJECT Section;
1698  PFN_NUMBER OldPage;
1699  PFN_NUMBER NewPage;
1700  NTSTATUS Status;
1701  PVOID PAddress;
1704  ULONG_PTR Entry;
1705  PEPROCESS Process = MmGetAddressSpaceOwner(AddressSpace);
1706 
1707  DPRINT("MmAccessFaultSectionView(%p, %p, %p)\n", AddressSpace, MemoryArea, Address);
1708 
1709  /* Make sure we have a page mapping for this address. */
1710  Status = MmNotPresentFaultSectionView(AddressSpace, MemoryArea, Address, TRUE);
1711  if (!NT_SUCCESS(Status))
1712  {
1713  /* This is invalid access ! */
1714  return Status;
1715  }
1716 
1717  /*
1718  * Check if the page has already been set readwrite
1719  */
1720  if (MmGetPageProtect(Process, Address) & PAGE_READWRITE)
1721  {
1722  DPRINT("Address 0x%p\n", Address);
1723  return(STATUS_SUCCESS);
1724  }
1725 
1726  /*
1727  * Find the offset of the page
1728  */
1729  PAddress = MM_ROUND_DOWN(Address, PAGE_SIZE);
1730  Offset.QuadPart = (ULONG_PTR)PAddress - MA_GetStartingAddress(MemoryArea)
1731  + MemoryArea->Data.SectionData.ViewOffset.QuadPart;
1732 
1733  Segment = MemoryArea->Data.SectionData.Segment;
1734  Section = MemoryArea->Data.SectionData.Section;
1735  Region = MmFindRegion((PVOID)MA_GetStartingAddress(MemoryArea),
1736  &MemoryArea->Data.SectionData.RegionListHead,
1737  Address, NULL);
1738  ASSERT(Region != NULL);
1739 
1740  /*
1741  * Check if we are doing COW
1742  */
1743  if (!((Segment->WriteCopy) &&
1744  (Region->Protect == PAGE_READWRITE ||
1745  Region->Protect == PAGE_EXECUTE_READWRITE)))
1746  {
1747  DPRINT("Address 0x%p\n", Address);
1748  return(STATUS_ACCESS_VIOLATION);
1749  }
1750 
1751  /* Get the page mapping this section offset. */
1752  MmLockSectionSegment(Segment);
1753  Entry = MmGetPageEntrySectionSegment(Segment, &Offset);
1754 
1755  /* Get the current page mapping for the process */
1756  ASSERT(MmIsPagePresent(Process, PAddress));
1757  OldPage = MmGetPfnForProcess(Process, PAddress);
1758  ASSERT(OldPage != 0);
1759 
1760  if (IS_SWAP_FROM_SSE(Entry) ||
1761  PFN_FROM_SSE(Entry) != OldPage)
1762  {
1763  MmUnlockSectionSegment(Segment);
1764  /* This is a private page. We must only change the page protection. */
1765  MmSetPageProtect(Process, PAddress, Region->Protect);
1766  return(STATUS_SUCCESS);
1767  }
1768 
1769  /*
1770  * Allocate a page
1771  */
1773  if (Process) MI_SET_PROCESS2(Process->ImageFileName);
1774  if (!Process) MI_SET_PROCESS2("Kernel Section");
1775  Status = MmRequestPageMemoryConsumer(MC_USER, TRUE, &NewPage);
1776  if (!NT_SUCCESS(Status))
1777  {
1778  KeBugCheck(MEMORY_MANAGEMENT);
1779  }
1780 
1781  /*
1782  * Copy the old page
1783  */
1784  MiCopyFromUserPage(NewPage, OldPage);
1785 
1786  /*
1787  * Unshare the old page.
1788  */
1789  DPRINT("Swapping page (Old %x New %x)\n", OldPage, NewPage);
1790  MmDeleteVirtualMapping(Process, PAddress, NULL, NULL);
1791  MmDeleteRmap(OldPage, Process, PAddress);
1792  MmUnsharePageEntrySectionSegment(Section, Segment, &Offset, FALSE, FALSE, NULL);
1793  MmUnlockSectionSegment(Segment);
1794 
1795  /*
1796  * Set the PTE to point to the new page
1797  */
1798  Status = MmCreateVirtualMapping(Process,
1799  PAddress,
1800  Region->Protect,
1801  &NewPage,
1802  1);
1803  if (!NT_SUCCESS(Status))
1804  {
1805  DPRINT1("MmCreateVirtualMapping failed, unable to create virtual mapping, not out of memory\n");
1806  KeBugCheck(MEMORY_MANAGEMENT);
1807  return(Status);
1808  }
1809  MmInsertRmap(NewPage, Process, PAddress);
1810 
1811  MiSetPageEvent(Process, Address);
1812  DPRINT("Address 0x%p\n", Address);
1813  return(STATUS_SUCCESS);
1814 }
DWORD *typedef PVOID
Definition: winlogon.h:52
PMM_REGION NTAPI MmFindRegion(PVOID BaseAddress, PLIST_ENTRY RegionListHead, PVOID Address, PVOID *RegionBaseAddress)
Definition: region.c:257
BOOLEAN WriteCopy
Definition: mm.h:166
#define TRUE
Definition: types.h:120
PVOID ULONG Address
Definition: oprghdlr.h:14
VOID NTAPI MmInsertRmap(PFN_NUMBER Page, struct _EPROCESS *Process, PVOID Address)
union _MEMORY_AREA::@1561 Data
#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:92
return STATUS_SUCCESS
Definition: btrfs.c:2664
VOID NTAPI MmDeleteRmap(PFN_NUMBER Page, struct _EPROCESS *Process, PVOID Address)
Definition: mm.h:386
NTSTATUS NTAPI MmRequestPageMemoryConsumer(ULONG Consumer, BOOLEAN MyWait, PPFN_NUMBER AllocatedPage)
Definition: balance.c:229
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:1282
#define MI_SET_PROCESS2(x)
Definition: mm.h:250
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:557
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:249
_Inout_ PVOID Segment
Definition: exfuncs.h:893
ULONG Protect
Definition: mm.h:389
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
VOID NTAPI MmSetPageProtect(struct _EPROCESS *Process, PVOID Address, ULONG flProtect)
#define MM_ROUND_DOWN(x, s)
Definition: mm.h:107
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define IS_SWAP_FROM_SSE(E)
Definition: newmm.h:8
struct _MEMORY_AREA::@1561::@1562 SectionData
#define MA_GetStartingAddress(_MemoryArea)
Definition: mm.h:203
Status
Definition: gdiplustypes.h:24
LONG NTSTATUS
Definition: DriverTester.h:11
#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:1357
NTSTATUS NTAPI MiCopyFromUserPage(PFN_NUMBER DestPage, PFN_NUMBER SrcPage)
Definition: section.c:1043
#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:1258
#define ULONG_PTR
Definition: config.h:101
#define PAGE_EXECUTE_READWRITE
Definition: nt_native.h:1308
#define MmUnlockSectionSegment(x)
Definition: newmm.h:284
#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 2423 of file section.c.

Referenced by MmProtectSectionView().

2430 {
2433  BOOLEAN DoCOW = FALSE;
2434  ULONG i;
2435  PEPROCESS Process = MmGetAddressSpaceOwner(AddressSpace);
2436 
2437  MemoryArea = MmLocateMemoryAreaByAddress(AddressSpace, BaseAddress);
2438  ASSERT(MemoryArea != NULL);
2439  Segment = MemoryArea->Data.SectionData.Segment;
2440  MmLockSectionSegment(Segment);
2441 
2442  if ((Segment->WriteCopy) &&
2444  {
2445  DoCOW = TRUE;
2446  }
2447 
2448  if (OldProtect != NewProtect)
2449  {
2450  for (i = 0; i < PAGE_ROUND_UP(RegionSize) / PAGE_SIZE; i++)
2451  {
2452  SWAPENTRY SwapEntry;
2453  PVOID Address = (char*)BaseAddress + (i * PAGE_SIZE);
2455 
2456  /* Wait for a wait entry to disappear */
2457  do
2458  {
2459  MmGetPageFileMapping(Process, Address, &SwapEntry);
2460  if (SwapEntry != MM_WAIT_ENTRY)
2461  break;
2462  MiWaitForPageEvent(Process, Address);
2463  }
2464  while (TRUE);
2465 
2466  /*
2467  * If we doing COW for this segment then check if the page is
2468  * already private.
2469  */
2470  if (DoCOW && MmIsPagePresent(Process, Address))
2471  {
2473  ULONG_PTR Entry;
2474  PFN_NUMBER Page;
2475 
2476  Offset.QuadPart = (ULONG_PTR)Address - MA_GetStartingAddress(MemoryArea)
2477  + MemoryArea->Data.SectionData.ViewOffset.QuadPart;
2478  Entry = MmGetPageEntrySectionSegment(Segment, &Offset);
2479  /*
2480  * An MM_WAIT_ENTRY is ok in this case... It'll just count as
2481  * IS_SWAP_FROM_SSE and we'll do the right thing.
2482  */
2483  Page = MmGetPfnForProcess(Process, Address);
2484 
2485  Protect = PAGE_READONLY;
2486  if (Segment->Image.Characteristics & IMAGE_SCN_CNT_UNINITIALIZED_DATA ||
2487  IS_SWAP_FROM_SSE(Entry) ||
2488  PFN_FROM_SSE(Entry) != Page)
2489  {
2490  Protect = NewProtect;
2491  }
2492  }
2493 
2494  if (MmIsPagePresent(Process, Address) || MmIsDisabledPage(Process, Address))
2495  {
2496  MmSetPageProtect(Process, Address,
2497  Protect);
2498  }
2499  }
2500  }
2501 
2502  MmUnlockSectionSegment(Segment);
2503 }
DWORD *typedef PVOID
Definition: winlogon.h:52
BOOLEAN WriteCopy
Definition: mm.h:166
#define TRUE
Definition: types.h:120
PVOID ULONG Address
Definition: oprghdlr.h:14
union _MEMORY_AREA::@1561 Data
struct _Entry Entry
Definition: kefuncs.h:640
#define PFN_FROM_SSE(E)
Definition: newmm.h:7
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
struct _MM_SECTION_SEGMENT::@1558 Image
#define MM_WAIT_ENTRY
Definition: mm.h:148
#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
_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
smooth NULL
Definition: ftsmooth.c:557
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)
VOID NTAPI MmSetPageProtect(struct _EPROCESS *Process, PVOID Address, ULONG flProtect)
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define IMAGE_SCN_CNT_UNINITIALIZED_DATA
Definition: ntimage.h:232
#define IS_SWAP_FROM_SSE(E)
Definition: newmm.h:8
struct _MEMORY_AREA::@1561::@1562 SectionData
#define MA_GetStartingAddress(_MemoryArea)
Definition: mm.h:203
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:45
FORCEINLINE PEPROCESS MmGetAddressSpaceOwner(IN PMMSUPPORT AddressSpace)
Definition: mm.h:1357
_Must_inspect_result_ _In_ ULONG NewProtect
Definition: mmfuncs.h:683
#define PAGE_READONLY
Definition: compat.h:127
#define MmLockSectionSegment(x)
Definition: newmm.h:276
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
#define PAGE_EXECUTE_READWRITE
Definition: nt_native.h:1308
#define MmUnlockSectionSegment(x)
Definition: newmm.h:284
struct _MEMORY_AREA * MemoryArea
Definition: newmm.h:65
#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 4713 of file section.c.

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

4715 {
4716  /* Check whether an ImageSectionObject exists */
4717  if (SectionObjectPointer->ImageSectionObject != NULL)
4718  {
4719  DPRINT1("ERROR: File can't be truncated because it has an image section\n");
4720  return FALSE;
4721  }
4722 
4723  if (SectionObjectPointer->DataSectionObject != NULL)
4724  {
4726 
4728  DataSectionObject;
4729 
4730  if (Segment->ReferenceCount != 0)
4731  {
4732 #ifdef NEWCC
4733  CC_FILE_SIZES FileSizes;
4734  CcpLock();
4735  if (SectionObjectPointer->SharedCacheMap && (Segment->ReferenceCount > CcpCountCacheSections((PNOCC_CACHE_MAP)SectionObjectPointer->SharedCacheMap)))
4736  {
4737  CcpUnlock();
4738  /* Check size of file */
4739  if (SectionObjectPointer->SharedCacheMap)
4740  {
4741  if (!CcGetFileSizes(Segment->FileObject, &FileSizes))
4742  {
4743  return FALSE;
4744  }
4745 
4746  if (NewFileSize->QuadPart <= FileSizes.FileSize.QuadPart)
4747  {
4748  return FALSE;
4749  }
4750  }
4751  }
4752  else
4753  CcpUnlock();
4754 #else
4755  /* Check size of file */
4756  if (SectionObjectPointer->SharedCacheMap)
4757  {
4758  PROS_SHARED_CACHE_MAP SharedCacheMap = SectionObjectPointer->SharedCacheMap;
4759  if (NewFileSize->QuadPart <= SharedCacheMap->FileSize.QuadPart)
4760  {
4761  return FALSE;
4762  }
4763  }
4764 #endif
4765  }
4766  else
4767  {
4768  /* Something must gone wrong
4769  * how can we have a Section but no
4770  * reference? */
4771  DPRINT("ERROR: DataSectionObject without reference!\n");
4772  }
4773  }
4774 
4775  DPRINT("FIXME: didn't check for outstanding write probes\n");
4776 
4777  return TRUE;
4778 }
#define TRUE
Definition: types.h:120
#define CcpLock()
Definition: newcc.h:140
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:557
_Inout_ PLARGE_INTEGER NewFileSize
Definition: mrx.h:204
void DPRINT(...)
Definition: polytest.cpp:61
PFILE_OBJECT FileObject
Definition: mm.h:159
_Inout_ PVOID Segment
Definition: exfuncs.h:893
if(!(yy_init))
Definition: macro.lex.yy.c:704
struct _MM_SECTION_SEGMENT * PMM_SECTION_SEGMENT
ULONG ReferenceCount
Definition: mm.h:162
ULONG NTAPI CcpCountCacheSections(IN PNOCC_CACHE_MAP Map)
Definition: fssup.c:270
#define DPRINT1
Definition: precomp.h:8
LARGE_INTEGER FileSize
Definition: cc.h:151
#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 2410 of file section.c.

Referenced by MmCreateSection().

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

Referenced by MmCreateSection().

2905 {
2906  PROS_SECTION_OBJECT Section;
2907  NTSTATUS Status;
2911  ULONG Length;
2912 
2913  /*
2914  * Create the section
2915  */
2916  Status = ObCreateObject(ExGetPreviousMode(),
2918  ObjectAttributes,
2920  NULL,
2921  sizeof(ROS_SECTION_OBJECT),
2922  0,
2923  0,
2924  (PVOID*)&Section);
2925  if (!NT_SUCCESS(Status))
2926  {
2928  return(Status);
2929  }
2930  /*
2931  * Initialize it
2932  */
2933  RtlZeroMemory(Section, sizeof(ROS_SECTION_OBJECT));
2934  Section->Type = 'SC';
2935  Section->Size = 'TN';
2938 
2939  /*
2940  * FIXME: This is propably not entirely correct. We can't look into
2941  * the standard FCB header because it might not be initialized yet
2942  * (as in case of the EXT2FS driver by Manoj Paul Joseph where the
2943  * standard file information is filled on first request).
2944  */
2947  sizeof(FILE_STANDARD_INFORMATION),
2948  &FileInfo,
2949  &Length);
2950  if (!NT_SUCCESS(Status))
2951  {
2952  ObDereferenceObject(Section);
2954  return Status;
2955  }
2956 
2957  /*
2958  * FIXME: Revise this once a locking order for file size changes is
2959  * decided
2960  */
2961  if ((UMaximumSize != NULL) && (UMaximumSize->QuadPart != 0))
2962  {
2963  MaximumSize = *UMaximumSize;
2964  }
2965  else
2966  {
2967  MaximumSize = FileInfo.EndOfFile;
2968  /* Mapping zero-sized files isn't allowed. */
2969  if (MaximumSize.QuadPart == 0)
2970  {
2971  ObDereferenceObject(Section);
2974  }
2975  }
2976 
2977  if (MaximumSize.QuadPart > FileInfo.EndOfFile.QuadPart)
2978  {
2979  Status = IoSetInformation(FileObject,
2981  sizeof(LARGE_INTEGER),
2982  &MaximumSize);
2983  if (!NT_SUCCESS(Status))
2984  {
2985  ObDereferenceObject(Section);
2988  }
2989  }
2990 
2991  if (FileObject->SectionObjectPointer == NULL ||
2992  FileObject->SectionObjectPointer->SharedCacheMap == NULL)
2993  {
2994  ObDereferenceObject(Section);
2997  }
2998 
2999  /*
3000  * Lock the file
3001  */
3002  Status = MmspWaitForFileLock(FileObject);
3003  if (Status != STATUS_SUCCESS)
3004  {
3005  ObDereferenceObject(Section);
3007  return(Status);
3008  }
3009 
3010  /*
3011  * If this file hasn't been mapped as a data file before then allocate a
3012  * section segment to describe the data file mapping
3013  */
3014  if (FileObject->SectionObjectPointer->DataSectionObject == NULL)
3015  {
3018  if (Segment == NULL)
3019  {
3020  //KeSetEvent((PVOID)&FileObject->Lock, IO_NO_INCREMENT, FALSE);
3021  ObDereferenceObject(Section);
3023  return(STATUS_NO_MEMORY);
3024  }
3025  Section->Segment = Segment;
3026  Segment->ReferenceCount = 1;
3027  ExInitializeFastMutex(&Segment->Lock);
3028  /*
3029  * Set the lock before assigning the segment to the file object
3030  */
3031  ExAcquireFastMutex(&Segment->Lock);
3032  FileObject->SectionObjectPointer->DataSectionObject = (PVOID)Segment;
3033 
3034  Segment->Image.FileOffset = 0;
3035  Segment->Protection = SectionPageProtection;
3036  Segment->Flags = MM_DATAFILE_SEGMENT;
3037  Segment->Image.Characteristics = 0;
3040  {
3041  Segment->Length.QuadPart = Segment->RawLength.QuadPart = 0;
3042  }
3043  else
3044  {
3045  Segment->RawLength.QuadPart = MaximumSize.QuadPart;
3046  Segment->Length.QuadPart = PAGE_ROUND_UP(Segment->RawLength.QuadPart);
3047  }
3048  Segment->Image.VirtualAddress = 0;
3049  Segment->Locked = TRUE;
3051  }
3052  else
3053  {
3054  /*
3055  * If the file is already mapped as a data file then we may need
3056  * to extend it
3057  */
3058  Segment =
3059  (PMM_SECTION_SEGMENT)FileObject->SectionObjectPointer->
3060  DataSectionObject;
3061  Section->Segment = Segment;
3062  (void)InterlockedIncrementUL(&Segment->ReferenceCount);
3063  MmLockSectionSegment(Segment);
3064 
3065  if (MaximumSize.QuadPart > Segment->RawLength.QuadPart &&
3067  {
3068  Segment->RawLength.QuadPart = MaximumSize.QuadPart;
3069  Segment->Length.QuadPart = PAGE_ROUND_UP(Segment->RawLength.QuadPart);
3070  }
3071  }
3072  MmUnlockSectionSegment(Segment);
3073  Section->FileObject = FileObject;
3074  Section->MaximumSize = MaximumSize;
3075 #ifndef NEWCC
3077 #endif
3078  //KeSetEvent((PVOID)&FileObject->Lock, IO_NO_INCREMENT, FALSE);
3079  *SectionObject = Section;
3080  return(STATUS_SUCCESS);
3081 }
DWORD *typedef PVOID
Definition: winlogon.h:52
BOOLEAN WriteCopy
Definition: mm.h:166
#define TRUE
Definition: types.h:120
LARGE_INTEGER MaximumSize
Definition: mm.h:192
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ ULONG AllocationAttributes
Definition: mmfuncs.h:360
return STATUS_SUCCESS
Definition: btrfs.c:2664
struct _MM_SECTION_SEGMENT::@1558 Image
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:2740
NTSTATUS NTAPI IoSetInformation(IN PFILE_OBJECT FileObject, IN FILE_INFORMATION_CLASS FileInformationClass, IN ULONG Length, IN PVOID FileInformation)
Definition: iofunc.c:1164
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:267
#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:1124
_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:164
#define SEC_RESERVE
Definition: nt_native.h:1323
BOOLEAN Locked
Definition: mm.h:167
smooth NULL
Definition: ftsmooth.c:557
_In_ PFILE_OBJECT FileObject
Definition: classpnp.h:1229
LARGE_INTEGER EndOfFile
Definition: nt_native.h:948
VOID NTAPI CcRosReferenceCache(PFILE_OBJECT FileObject)
Definition: view.c:1044
_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:161
PFILE_OBJECT FileObject
Definition: mm.h:195
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
CSHORT Type
Definition: mm.h:190
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274
LARGE_INTEGER RawLength
Definition: mm.h:160
#define STATUS_INVALID_FILE_FOR_SECTION
Definition: ntstatus.h:255
#define MM_DATAFILE_SEGMENT
Definition: mm.h:89
POBJECT_TYPE MmSectionObjectType
Definition: section.c:136
struct _MM_SECTION_SEGMENT * PMM_SECTION_SEGMENT
ULONG Flags
Definition: mm.h:165
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
VOID UINTN Length
Definition: acefiex.h:744
ULONG ReferenceCount
Definition: mm.h:162
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
LONG NTSTATUS
Definition: DriverTester.h:11
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:1455
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
ULONG SectionPageProtection
Definition: mm.h:193
#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
FAST_MUTEX Lock
Definition: mm.h:158
struct FileInfo FileInfo
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
CSHORT Size
Definition: mm.h:191
ULONG AllocationAttributes
Definition: mm.h:194
#define STATUS_MAPPED_FILE_SIZE_ZERO
Definition: ntstatus.h:508
#define MmUnlockSectionSegment(x)
Definition: newmm.h:284
PMM_SECTION_SEGMENT Segment
Definition: mm.h:199
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 3709 of file section.c.

Referenced by MmCreateSection().

3716 {
3717  PROS_SECTION_OBJECT Section;
3718  NTSTATUS Status;
3719  PMM_SECTION_SEGMENT SectionSegments;
3721  ULONG i;
3722 
3723  if (FileObject == NULL)
3725 
3726 #ifndef NEWCC
3727  if (FileObject->SectionObjectPointer->SharedCacheMap == NULL)
3728  {
3729  DPRINT1("Denying section creation due to missing cache initialization\n");
3731  }
3732 #endif
3733 
3734  /*
3735  * Create the section
3736  */
3737  Status = ObCreateObject (ExGetPreviousMode(),
3739  ObjectAttributes,
3741  NULL,
3742  sizeof(ROS_SECTION_OBJECT),
3743  0,
3744  0,
3745  (PVOID*)(PVOID)&Section);
3746  if (!NT_SUCCESS(Status))
3747  {
3749  return(Status);
3750  }
3751 
3752  /*
3753  * Initialize it
3754  */
3755  RtlZeroMemory(Section, sizeof(ROS_SECTION_OBJECT));
3756  Section->Type = 'SC';
3757  Section->Size = 'TN';
3760 
3761 #ifndef NEWCC
3762  /*
3763  * Initialized caching for this file object if previously caching
3764  * was initialized for the same on disk file
3765  */
3767 #else
3768  Status = STATUS_SUCCESS;
3769 #endif
3770 
3771  if (!NT_SUCCESS(Status) || FileObject->SectionObjectPointer->ImageSectionObject == NULL)
3772  {
3773  NTSTATUS StatusExeFmt;
3774 
3776  if (ImageSectionObject == NULL)
3777  {
3779  ObDereferenceObject(Section);
3780  return(STATUS_NO_MEMORY);
3781  }
3782 
3783  RtlZeroMemory(ImageSectionObject, sizeof(MM_IMAGE_SECTION_OBJECT));
3784 
3785  StatusExeFmt = ExeFmtpCreateImageSection(FileObject, ImageSectionObject);
3786 
3787  if (!NT_SUCCESS(StatusExeFmt))
3788  {
3789  if(ImageSectionObject->Segments != NULL)
3790  ExFreePool(ImageSectionObject->Segments);
3791 
3792  /*
3793  * If image file is empty, then return that the file is invalid for section
3794  */
3795  Status = StatusExeFmt;
3796  if (StatusExeFmt == STATUS_END_OF_FILE)
3797  {
3799  }
3800 
3801  ExFreePoolWithTag(ImageSectionObject, TAG_MM_SECTION_SEGMENT);
3802  ObDereferenceObject(Section);
3804  return(Status);
3805  }
3806 
3807  Section->ImageSection = ImageSectionObject;
3808  ASSERT(ImageSectionObject->Segments);
3809 
3810  /*
3811  * Lock the file
3812  */
3813  Status = MmspWaitForFileLock(FileObject);
3814  if (!NT_SUCCESS(Status))
3815  {
3816  ExFreePool(ImageSectionObject->Segments);
3817  ExFreePool(ImageSectionObject);
3818  ObDereferenceObject(Section);
3820  return(Status);
3821  }
3822 
3823  if (NULL != InterlockedCompareExchangePointer(&FileObject->SectionObjectPointer->ImageSectionObject,
3824  ImageSectionObject, NULL))
3825  {
3826  /*
3827  * An other thread has initialized the same image in the background
3828  */
3829  ExFreePool(ImageSectionObject->Segments);
3830  ExFreePool(ImageSectionObject);
3831  ImageSectionObject = FileObject->SectionObjectPointer->ImageSectionObject;
3832  Section->ImageSection = ImageSectionObject;
3833  SectionSegments = ImageSectionObject->Segments;
3834 
3835  for (i = 0; i < ImageSectionObject->NrSegments; i++)
3836  {
3837  (void)InterlockedIncrementUL(&SectionSegments[i].ReferenceCount);
3838  }
3839  }
3840 
3841  Status = StatusExeFmt;
3842  }
3843  else
3844  {
3845  /*
3846  * Lock the file
3847  */
3848  Status = MmspWaitForFileLock(FileObject);
3849  if (Status != STATUS_SUCCESS)
3850  {
3851  ObDereferenceObject(Section);
3853  return(Status);
3854  }
3855 
3856  ImageSectionObject = FileObject->SectionObjectPointer->ImageSectionObject;
3857  Section->ImageSection = ImageSectionObject;
3858  SectionSegments = ImageSectionObject->Segments;
3859 
3860  /*
3861  * Otherwise just reference all the section segments
3862  */
3863  for (i = 0; i < ImageSectionObject->NrSegments; i++)
3864  {
3865  (void)InterlockedIncrementUL(&SectionSegments[i].ReferenceCount);
3866  }
3867 
3868  Status = STATUS_SUCCESS;
3869  }
3870  Section->FileObject = FileObject;
3871 #ifndef NEWCC
3873 #endif
3874  //KeSetEvent((PVOID)&FileObject->Lock, IO_NO_INCREMENT, FALSE);
3875  *SectionObject = Section;
3876  return(Status);
3877 }
DWORD *typedef PVOID
Definition: winlogon.h:52
NTSTATUS ExeFmtpCreateImageSection(PFILE_OBJECT FileObject, PMM_IMAGE_SECTION_OBJECT ImageSectionObject)
Definition: section.c:3562
_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)
return STATUS_SUCCESS
Definition: btrfs.c:2664
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:2740
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:267
#define STATUS_END_OF_FILE
Definition: shellext.h:48
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:198
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:557
_In_ PFILE_OBJECT FileObject
Definition: classpnp.h:1229
VOID NTAPI CcRosReferenceCache(PFILE_OBJECT FileObject)
Definition: view.c:1044
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
NTSTATUS NTAPI CcTryToInitializeFileCache(PFILE_OBJECT FileObject)
Definition: view.c:1130
PFILE_OBJECT FileObject
Definition: mm.h:195
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
CSHORT Type
Definition: mm.h:190
PMM_SECTION_SEGMENT Segments
Definition: mm.h:185
#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
LONG NTSTATUS
Definition: DriverTester.h:11
#define TAG_MM_SECTION_SEGMENT
Definition: tag.h:139
#define InterlockedIncrementUL(Addend)
Definition: ex.h:1455
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
ULONG SectionPageProtection
Definition: mm.h:193
#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:191
ULONG AllocationAttributes
Definition: mm.h:194
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1097
#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 2820 of file section.c.

Referenced by MmCreateSection().

2829 {
2831  PROS_SECTION_OBJECT Section;
2833  NTSTATUS Status;
2834 
2835  if (UMaximumSize == NULL)
2836  {
2837  DPRINT1("MmCreatePageFileSection: (UMaximumSize == NULL)\n");
2838  return(STATUS_INVALID_PARAMETER);
2839  }
2840  MaximumSize = *UMaximumSize;
2841 
2842  /*
2843  * Create the section
2844  */
2845  Status = ObCreateObject(ExGetPreviousMode(),
2847  ObjectAttributes,
2849  NULL,
2850  sizeof(ROS_SECTION_OBJECT),
2851  0,
2852  0,
2853  (PVOID*)(PVOID)&Section);
2854  if (!NT_SUCCESS(Status))
2855  {
2856  DPRINT1("MmCreatePageFileSection: failed to create object (0x%lx)\n", Status);
2857  return(Status);
2858  }
2859 
2860  /*
2861  * Initialize it
2862  */
2863  RtlZeroMemory(Section, sizeof(ROS_SECTION_OBJECT));
2864  Section->Type = 'SC';
2865  Section->Size = 'TN';
2868  Section->MaximumSize = MaximumSize;
2871  if (Segment == NULL)
2872  {
2873  ObDereferenceObject(Section);
2874  return(STATUS_NO_MEMORY);
2875  }
2876  RtlZeroMemory(Segment, sizeof(MM_SECTION_SEGMENT));
2877  Section->Segment = Segment;
2878  Segment->ReferenceCount = 1;
2879  ExInitializeFastMutex(&Segment->Lock);
2880  Segment->Image.FileOffset = 0;
2881  Segment->Protection = SectionPageProtection;
2882  Segment->RawLength.QuadPart = MaximumSize.u.LowPart;
2883  Segment->Length.QuadPart = PAGE_ROUND_UP(MaximumSize.u.LowPart);
2884  Segment->Flags = MM_PAGEFILE_SEGMENT;
2885  Segment->WriteCopy = FALSE;
2886  Segment->Image.VirtualAddress = 0;
2887  Segment->Image.Characteristics = 0;
2888  *SectionObject = Section;
2890  return(STATUS_SUCCESS);
2891 }
DWORD *typedef PVOID
Definition: winlogon.h:52
BOOLEAN WriteCopy
Definition: mm.h:166
LARGE_INTEGER MaximumSize
Definition: mm.h:192
_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
return STATUS_SUCCESS
Definition: btrfs.c:2664
struct _MM_SECTION_SEGMENT::@1558 Image
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:2740
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:267
#define PAGE_ROUND_UP(x)
Definition: scsiport_int.h:13
struct _LARGE_INTEGER::@2037 u
_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:164
smooth NULL
Definition: ftsmooth.c:557
_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:161
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
CSHORT Type
Definition: mm.h:190
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274
LARGE_INTEGER RawLength
Definition: mm.h:160
POBJECT_TYPE MmSectionObjectType
Definition: section.c:136
ULONG Flags
Definition: mm.h:165
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define MM_PAGEFILE_SEGMENT
Definition: mm.h:88
ULONG ReferenceCount
Definition: mm.h:162
VOID NTAPI MiInitializeSectionPageTable(PMM_SECTION_SEGMENT Segment)
Definition: sptab.c:165
Status
Definition: gdiplustypes.h:24
LONG NTSTATUS
Definition: DriverTester.h:11
#define TAG_MM_SECTION_SEGMENT
Definition: tag.h:139
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
ULONG SectionPageProtection
Definition: mm.h:193
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_opt_ PLARGE_INTEGER MaximumSize
Definition: mmfuncs.h:360
#define DPRINT1
Definition: precomp.h:8
FAST_MUTEX Lock
Definition: mm.h:158
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
CSHORT Size
Definition: mm.h:191
ULONG AllocationAttributes
Definition: mm.h:194
PMM_SECTION_SEGMENT Segment
Definition: mm.h:199
LONGLONG QuadPart
Definition: typedefs.h:112
NTSTATUS INIT_FUNCTION NTAPI MmCreatePhysicalMemorySection ( VOID  )

Definition at line 2737 of file section.c.

Referenced by MmInitSectionImplementation().

2738 {
2739  PROS_SECTION_OBJECT PhysSection;
2740  NTSTATUS Status;
2742  UNICODE_STRING Name = RTL_CONSTANT_STRING(L"\\Device\\PhysicalMemory");
2743  LARGE_INTEGER SectionSize;
2744  HANDLE Handle;
2745 
2746  /*
2747  * Create the section mapping physical memory
2748  */
2749  SectionSize.QuadPart = 0xFFFFFFFF;
2751  &Name,
2753  NULL,
2754  NULL);
2755  Status = MmCreateSection((PVOID)&PhysSection,
2757  &Obj,
2758  &SectionSize,
2761  NULL,
2762  NULL);
2763  if (!NT_SUCCESS(Status))
2764  {
2765  DPRINT1("Failed to create PhysicalMemory section\n");
2766  KeBugCheck(MEMORY_MANAGEMENT);
2767  }
2768  Status = ObInsertObject(PhysSection,
2769  NULL,
2771  0,
2772  NULL,
2773  &Handle);
2774  if (!NT_SUCCESS(Status))
2775  {
2776  ObDereferenceObject(PhysSection);
2777  }
2778  ObCloseHandle(Handle, KernelMode);
2779  PhysSection->AllocationAttributes |= SEC_PHYSICALMEMORY;
2780  PhysSection->Segment->Flags &= ~MM_PAGEFILE_SEGMENT;
2781 
2782  return(STATUS_SUCCESS);
2783 }
DWORD *typedef PVOID
Definition: winlogon.h:52
Definition: bidi.c:75
return STATUS_SUCCESS
Definition: btrfs.c:2664
#define OBJ_PERMANENT
Definition: winternl.h:226
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:267
#define SECTION_ALL_ACCESS
Definition: nt_native.h:1293
smooth NULL
Definition: ftsmooth.c:557
VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1469
_In_ HANDLE Handle
Definition: extypes.h:390
#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:4964
ULONG Flags
Definition: mm.h:165
_In_ PUNICODE_STRING Name
Definition: mrx.h:218
#define MM_PAGEFILE_SEGMENT
Definition: mm.h:88
NTSTATUS NTAPI ObCloseHandle(IN HANDLE Handle, IN KPROCESSOR_MODE AccessMode)
Definition: obhandle.c:3369
#define SEC_PHYSICALMEMORY
Definition: mm.h:86
Status
Definition: gdiplustypes.h:24
DWORD *typedef HANDLE
Definition: winlogon.h:52
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:2925
LONG NTSTATUS
Definition: DriverTester.h:11
#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:194
#define PAGE_EXECUTE_READWRITE
Definition: nt_native.h:1308
PMM_SECTION_SEGMENT Segment
Definition: mm.h:199
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 4964 of file section.c.

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

4972 {
4973  NTSTATUS Status;
4974  ULONG Protection;
4976 
4977  /* Check if an ARM3 section is being created instead */
4979  {
4980  if (!(FileObject) && !(FileHandle))
4981  {
4982  return MmCreateArm3Section(Section,
4983  DesiredAccess,
4985  MaximumSize,
4987  AllocationAttributes &~ 1,
4988  FileHandle,
4989  FileObject);
4990  }
4991  }
4992 
4993  /* Convert section flag to page flag */
4995 
4996  /* Check to make sure the protection is correct. Nt* does this already */
4998  if (Protection == MM_INVALID_PROTECTION)
4999  {
5000  DPRINT1("Page protection is invalid\n");
5002  }
5003 
5004  /* Check if this is going to be a data or image backed file section */
5005  if ((FileHandle) || (FileObject))
5006  {
5007  /* These cannot be mapped with large pages */
5009  {
5010  DPRINT1("Large pages cannot be used with an image mapping\n");
5012  }
5013 
5014  /* Did the caller pass an object? */
5015  if (FileObject)
5016  {
5017  /* Reference the object directly */
5019  }
5020  else
5021  {
5022  /* Reference the file handle to get the object */
5024  MmMakeFileAccess[Protection],
5027  (PVOID*)&FileObject,
5028  NULL);
5029  if (!NT_SUCCESS(Status))
5030  {
5031  DPRINT1("Failed to get a handle to the FO: %lx\n", Status);
5032  return Status;
5033  }
5034  }
5035  }
5036  else
5037  {
5038  /* A handle must be supplied with SEC_IMAGE, as this is the no-handle path */
5040  }
5041 
5042 #ifndef NEWCC // A hack for initializing caching.
5043  // This is needed only in the old case.
5044  if (FileHandle)
5045  {
5047  NTSTATUS Status;
5048  CHAR Buffer;
5050  ByteOffset.QuadPart = 0;
5051  Status = ZwReadFile(FileHandle,
5052  NULL,
5053  NULL,
5054  NULL,
5055  &Iosb,
5056  &Buffer,
5057  sizeof(Buffer),
5058  &ByteOffset,
5059  NULL);
5060  if (!NT_SUCCESS(Status) && Status != STATUS_END_OF_FILE)
5061  {
5062  DPRINT1("CC failure: %lx\n", Status);
5063  if (FileObject)
5065  return Status;
5066  }
5067  // Caching is initialized...
5068 
5069  // Hack of the hack: actually, it might not be initialized if FSD init on effective right and if file is null-size
5070  // In such case, force cache by initiating a write IRP
5071  if (Status == STATUS_END_OF_FILE && !(AllocationAttributes & SEC_IMAGE) && FileObject != NULL &&
5072  (FileObject->SectionObjectPointer == NULL || FileObject->SectionObjectPointer->SharedCacheMap == NULL))
5073  {
5074  Buffer = 0xdb;
5075  Status = ZwWriteFile(FileHandle,
5076  NULL,
5077  NULL,
5078  NULL,
5079  &Iosb,
5080  &Buffer,
5081  sizeof(Buffer),
5082  &ByteOffset,
5083  NULL);
5084  if (NT_SUCCESS(Status))
5085  {
5086  LARGE_INTEGER Zero;
5087  Zero.QuadPart = 0LL;
5088 
5089  Status = IoSetInformation(FileObject,
5091  sizeof(LARGE_INTEGER),
5092  &Zero);
5093  ASSERT(NT_SUCCESS(Status));
5094  }
5095  }
5096  }
5097 #endif
5098 
5099  if (AllocationAttributes & SEC_IMAGE)
5100  {
5101  Status = MmCreateImageSection(SectionObject,
5102  DesiredAccess,
5104  MaximumSize,
5107  FileObject);
5108  }
5109 #ifndef NEWCC
5110  else if (FileHandle != NULL)
5111  {
5112  Status = MmCreateDataFileSection(SectionObject,
5113  DesiredAccess,
5115  MaximumSize,
5118  FileObject);
5119  }
5120 #else
5121  else if (FileHandle != NULL || FileObject != NULL)
5122  {
5123  Status = MmCreateCacheSection(SectionObject,
5124  DesiredAccess,
5126  MaximumSize,
5129  FileObject);
5130  }
5131 #endif
5132  else
5133  {
5135  {
5136  DPRINT1("Invalid path: %lx %p %p\n", AllocationAttributes, FileObject, FileHandle);
5137  }
5138 // ASSERT(AllocationAttributes & SEC_PHYSICALMEMORY);
5139  Status = MmCreatePageFileSection(SectionObject,
5140  DesiredAccess,
5142  MaximumSize,
5145  if (FileObject)
5147  }
5148 
5149  return Status;
5150 }
_Must_inspect_result_ _Outptr_ PVOID * SectionObject
Definition: fsrtlfuncs.h:860
DWORD *typedef PVOID
Definition: winlogon.h:52
#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:69
#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:32
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:2740
NTSTATUS NTAPI IoSetInformation(IN PFILE_OBJECT FileObject, IN FILE_INFORMATION_CLASS FileInformationClass, IN ULONG Length, IN PVOID FileInformation)
Definition: iofunc.c:1164
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:267
#define SEC_NOCACHE
Definition: mmtypes.h:100
IN POBJECT_ATTRIBUTES PortAttributes IN ACCESS_MASK DesiredAccess
Definition: creport.c:28
#define STATUS_END_OF_FILE
Definition: shellext.h:48
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:2410
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_opt_ PLARGE_INTEGER _In_ ULONG SectionPageProtection
Definition: mmfuncs.h:360
_Must_inspect_result_ _Out_ PIO_STATUS_BLOCK Iosb
Definition: fltkernel.h:1761
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:388
smooth NULL
Definition: ftsmooth.c:557
_In_ PFILE_OBJECT FileObject
Definition: classpnp.h:1229
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
#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:2820
ULONG NTAPI MiMakeProtectionMask(IN ULONG Protect)
Definition: section.c:158
NTSTATUS MmCreateImageSection(PROS_SECTION_OBJECT *SectionObject, ACCESS_MASK DesiredAccess, POBJECT_ATTRIBUTES ObjectAttributes, PLARGE_INTEGER UMaximumSize, ULONG SectionPageProtection, ULONG AllocationAttributes, PFILE_OBJECT FileObject)
Definition: section.c:3709
#define STATUS_INVALID_FILE_FOR_SECTION
Definition: ntstatus.h:255
UINTN VOID * Buffer
Definition: acefiex.h:370
#define SEC_PHYSICALMEMORY
Definition: mm.h:86
#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:47
LONG NTSTATUS
Definition: DriverTester.h:11
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:2895
#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
#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 4787 of file section.c.

Referenced by CdPurgeVolume(), Ext2CreateFile(), Ext2IsFileRemovable(), Ext2PurgeFile(), Ext2PurgeVolume(), 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().

4789 {
4790  BOOLEAN Result = TRUE;
4791 #ifdef NEWCC
4793 #endif
4794 
4795  switch(FlushType)
4796  {
4797  case MmFlushForDelete:
4798  if (SectionObjectPointer->ImageSectionObject ||
4799  SectionObjectPointer->DataSectionObject)
4800  {
4801  return FALSE;
4802  }
4803 #ifndef NEWCC
4805 #endif
4806  return TRUE;
4807  case MmFlushForWrite:
4808  {
4809  DPRINT("MmFlushImageSection(%d)\n", FlushType);
4810 #ifdef NEWCC
4811  Segment = (PMM_SECTION_SEGMENT)SectionObjectPointer->DataSectionObject;
4812 #endif
4813 
4814  if (SectionObjectPointer->ImageSectionObject)
4815  {
4816  DPRINT1("SectionObject has ImageSection\n");
4817  return FALSE;
4818  }
4819 
4820 #ifdef NEWCC
4821  CcpLock();
4822  Result = !SectionObjectPointer->SharedCacheMap || (Segment->ReferenceCount == CcpCountCacheSections((PNOCC_CACHE_MAP)SectionObjectPointer->SharedCacheMap));
4823  CcpUnlock();
4824  DPRINT("Result %d\n", Result);
4825 #endif
4826  return Result;
4827  }
4828  }
4829  return FALSE;
4830 }
#define TRUE
Definition: types.h:120
#define CcpLock()
Definition: newcc.h:140
_In_ MMFLUSH_TYPE FlushType
Definition: mmfuncs.h:601
_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
_Inout_ PVOID Segment
Definition: exfuncs.h:893
unsigned char BOOLEAN
if(!(yy_init))
Definition: macro.lex.yy.c:704
struct _MM_SECTION_SEGMENT * PMM_SECTION_SEGMENT
VOID NTAPI CcRosRemoveIfClosed(PSECTION_OBJECT_POINTERS SectionObjectPointer)
Definition: view.c:1058
ULONG ReferenceCount
Definition: mm.h:162
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 3959 of file section.c.

Referenced by MmUnmapViewOfSegment().

3961 {
3962  ULONG_PTR Entry;
3963 #ifndef NEWCC
3965  PROS_SHARED_CACHE_MAP SharedCacheMap;
3966 #endif
3968  SWAPENTRY SavedSwapEntry;
3969  PROS_SECTION_OBJECT Section;
3973 
3974  AddressSpace = (PMMSUPPORT)Context;
3975  Process = MmGetAddressSpaceOwner(AddressSpace);
3976 
3978 
3979  Offset.QuadPart = ((ULONG_PTR)Address - MA_GetStartingAddress(MemoryArea)) +
3980  MemoryArea->Data.SectionData.ViewOffset.QuadPart;
3981 
3982  Section = MemoryArea->Data.SectionData.Section;
3983  Segment = MemoryArea->Data.SectionData.Segment;
3984 
3985  Entry = MmGetPageEntrySectionSegment(Segment, &Offset);
3986  while (Entry && MM_IS_WAIT_PTE(Entry))
3987  {
3988  MmUnlockSectionSegment(Segment);
3989  MmUnlockAddressSpace(AddressSpace);
3990 
3992 
3993  MmLockAddressSpace(AddressSpace);
3994  MmLockSectionSegment(Segment);
3995  Entry = MmGetPageEntrySectionSegment(Segment, &Offset);
3996  }
3997 
3998  /*
3999  * For a dirty, datafile, non-private page mark it as dirty in the
4000  * cache manager.
4001  */
4002  if (Segment->Flags & MM_DATAFILE_SEGMENT)
4003  {
4004  if (Page == PFN_FROM_SSE(Entry) && Dirty)
4005  {
4006 #ifndef NEWCC
4007  FileObject = MemoryArea->Data.SectionData.Section->FileObject;
4008  SharedCacheMap = FileObject->SectionObjectPointer->SharedCacheMap;
4009  CcRosMarkDirtyVacb(SharedCacheMap, Offset.QuadPart + Segment->Image.FileOffset);
4010 #endif
4011  ASSERT(SwapEntry == 0);
4012  }
4013  }
4014 
4015  if (SwapEntry != 0)
4016  {
4017  /*
4018  * Sanity check
4019  */
4020  if (Segment->Flags & MM_PAGEFILE_SEGMENT)
4021  {
4022  DPRINT1("Found a swap entry for a page in a pagefile section.\n");
4023  KeBugCheck(MEMORY_MANAGEMENT);
4024  }
4025  MmFreeSwapPage(SwapEntry);
4026  }
4027  else if (Page != 0)
4028  {
4029  if (IS_SWAP_FROM_SSE(Entry) ||
4030  Page != PFN_FROM_SSE(Entry))
4031  {
4032  /*
4033  * Sanity check
4034  */
4035  if (Segment->Flags & MM_PAGEFILE_SEGMENT)
4036  {
4037  DPRINT1("Found a private page in a pagefile section.\n");
4038  KeBugCheck(MEMORY_MANAGEMENT);
4039  }
4040  /*
4041  * Just dereference private pages
4042  */
4043  SavedSwapEntry = MmGetSavedSwapEntryPage(Page);
4044  if (SavedSwapEntry != 0)
4045  {
4046  MmFreeSwapPage(SavedSwapEntry);
4047  MmSetSavedSwapEntryPage(Page, 0);
4048  }
4049  MmDeleteRmap(Page, Process, Address);
4051  }
4052  else
4053  {
4054  MmDeleteRmap(Page, Process, Address);
4055  MmUnsharePageEntrySectionSegment(Section, Segment, &Offset, Dirty, FALSE, NULL);
4056  }
4057  }
4058 }
DWORD *typedef PVOID
Definition: winlogon.h:52
PVOID ULONG Address
Definition: oprghdlr.h:14
union _MEMORY_AREA::@1561 Data
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:92
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:1350
struct _MM_SECTION_SEGMENT::@1558 Image
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
NTSTATUS NTAPI CcRosMarkDirtyVacb(PROS_SHARED_CACHE_MAP SharedCacheMap, LONGLONG FileOffset)
Definition: view.c:478
_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:557
_In_ PFILE_OBJECT FileObject
Definition: classpnp.h:1229
VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1469
_Inout_ PVOID Segment
Definition: exfuncs.h:893
struct _MMSUPPORT * PMMSUPPORT
#define MM_DATAFILE_SEGMENT
Definition: mm.h:89
* PFILE_OBJECT
Definition: iotypes.h:1949
ULONG Flags
Definition: mm.h:165
#define MM_PAGEFILE_SEGMENT
Definition: mm.h:88
#define IS_SWAP_FROM_SSE(E)
Definition: newmm.h:8
struct _MEMORY_AREA::@1561::@1562 SectionData
#define MA_GetStartingAddress(_MemoryArea)
Definition: mm.h:203
ULONG_PTR SWAPENTRY
Definition: mm.h:45
FORCEINLINE PEPROCESS MmGetAddressSpaceOwner(IN PMMSUPPORT AddressSpace)
Definition: mm.h:1357
#define DPRINT1
Definition: precomp.h:8
#define MmLockSectionSegment(x)
Definition: newmm.h:276
#define MM_IS_WAIT_PTE(E)
Definition: newmm.h:9
VOID NTAPI MmSetSavedSwapEntryPage(PFN_NUMBER Page, SWAPENTRY SavedSwapEntry)
Definition: freelist.c:454
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
#define ULONG_PTR
Definition: config.h:101
#define MmUnlockSectionSegment(x)
Definition: newmm.h:284
FORCEINLINE VOID MmLockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1343
#define MmGetPageEntrySectionSegment(S, O)
Definition: newmm.h:143
VOID NTAPI MmFreeSwapPage(SWAPENTRY Entry)
Definition: pagefile.c:392
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:557
_In_ PFILE_OBJECT FileObject
Definition: classpnp.h:1229
VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1469
_Inout_ PVOID Segment
Definition: exfuncs.h:893
struct _MM_IMAGE_SECTION_OBJECT * PMM_IMAGE_SECTION_OBJECT
if(!(yy_init))
Definition: macro.lex.yy.c:704
PMM_SECTION_SEGMENT Segments
Definition: mm.h:185
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:162
#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 2788 of file section.c.

Referenced by MmInitSystem().

2789 {
2790  OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;
2792 
2793  DPRINT("Creating Section Object Type\n");
2794 
2795  /* Initialize the section based root */
2798 
2799  /* Initialize the Section object type */
2800  RtlZeroMemory(&ObjectTypeInitializer, sizeof(ObjectTypeInitializer));
2801  RtlInitUnicodeString(&Name, L"Section");
2802  ObjectTypeInitializer.Length = sizeof(ObjectTypeInitializer);
2803  ObjectTypeInitializer.DefaultPagedPoolCharge = sizeof(ROS_SECTION_OBJECT);
2804  ObjectTypeInitializer.PoolType = PagedPool;
2805  ObjectTypeInitializer.UseDefaultObject = TRUE;
2806  ObjectTypeInitializer.GenericMapping = MmpSectionMapping;
2807  ObjectTypeInitializer.DeleteProcedure = MmpDeleteSection;
2808  ObjectTypeInitializer.CloseProcedure = MmpCloseSection;
2809  ObjectTypeInitializer.ValidAccessMask = SECTION_ALL_ACCESS;
2810  ObjectTypeInitializer.InvalidAttributes = OBJ_OPENLINK;
2811  ObCreateObjectType(&Name, &ObjectTypeInitializer, NULL, &MmSectionObjectType);
2812 
2814 
2815  return(STATUS_SUCCESS);
2816 }
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
Definition: bidi.c:75
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
return STATUS_SUCCESS
Definition: btrfs.c:2664
VOID NTAPI MmpCloseSection(IN PEPROCESS Process OPTIONAL, IN PVOID Object, IN ACCESS_MASK GrantedAccess, IN ULONG ProcessHandleCount, IN ULONG SystemHandleCount)
Definition: section.c:2725
ULONG_PTR NumberGenericTableElements
Definition: mmtypes.h:669
MM_AVL_TABLE MmSectionBasedRoot
Definition: section.c:109
#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:557
void DPRINT(...)
Definition: polytest.cpp:61
OB_CLOSE_METHOD CloseProcedure
Definition: obtypes.h:368
struct _ROS_SECTION_OBJECT ROS_SECTION_OBJECT
union _MMADDRESS_NODE::@2309 u1
POBJECT_TYPE MmSectionObjectType
Definition: section.c:136
NTSTATUS INIT_FUNCTION NTAPI MmCreatePhysicalMemorySection(VOID)
Definition: section.c:2737
_In_ PUNICODE_STRING Name
Definition: mrx.h:218
VOID NTAPI MmpDeleteSection(PVOID ObjectBody)
Definition: section.c:2626
GENERIC_MAPPING GenericMapping
Definition: obtypes.h:358
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
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 4836 of file section.c.

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

4839 {
4840  PROS_SECTION_OBJECT Section;
4842  NTSTATUS Status;
4843  PAGED_CODE();
4844 
4846  {
4848  &MmSession,
4849  MappedBase,
4850  ViewSize);
4851  }
4852 
4853  DPRINT("MmMapViewInSystemSpace() called\n");
4854 
4856  AddressSpace = MmGetKernelAddressSpace();
4857 
4858  MmLockAddressSpace(AddressSpace);
4859 
4860 
4861  if ((*ViewSize) == 0)
4862  {
4863  (*ViewSize) = Section->MaximumSize.u.LowPart;
4864  }
4865  else if ((*ViewSize) > Section->MaximumSize.u.LowPart)
4866  {
4867  (*ViewSize) = Section->MaximumSize.u.LowPart;
4868  }
4869 
4870  MmLockSectionSegment(Section->Segment);
4871 
4872 
4873  Status = MmMapViewOfSegment(AddressSpace,
4874  Section,
4875  Section->Segment,
4876  MappedBase,
4877  *ViewSize,
4879  0,
4880  0);
4881 
4882  MmUnlockSectionSegment(Section->Segment);
4883  MmUnlockAddressSpace(AddressSpace);
4884 
4885  return Status;
4886 }
_Must_inspect_result_ _Outptr_ PVOID * SectionObject
Definition: fsrtlfuncs.h:860
LARGE_INTEGER MaximumSize
Definition: mm.h:192
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG AddressSpace
Definition: iofuncs.h:2268
FORCEINLINE VOID MmUnlockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1350
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:3882
struct _LARGE_INTEGER::@2037 u
#define FALSE
Definition: types.h:117
void DPRINT(...)
Definition: polytest.cpp:61
struct _ROS_SECTION_OBJECT * PROS_SECTION_OBJECT
#define PAGED_CODE()
Definition: video.h:57
NTSTATUS NTAPI MiMapViewInSystemSpace(IN PVOID Section, IN PMMSESSION Session, OUT PVOID *MappedBase, IN OUT PSIZE_T ViewSize)
Definition: section.c:1052
Status
Definition: gdiplustypes.h:24
FORCEINLINE PMMSUPPORT MmGetKernelAddressSpace(VOID)
Definition: mm.h:1372
LONG NTSTATUS
Definition: DriverTester.h:11
_Must_inspect_result_ _Outptr_result_bytebuffer_ ViewSize PVOID * MappedBase
Definition: mmfuncs.h:493
#define MmLockSectionSegment(x)
Definition: newmm.h:276
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T _Inout_opt_ PLARGE_INTEGER _Inout_ PSIZE_T ViewSize
Definition: mmfuncs.h:404
#define MmUnlockSectionSegment(x)
Definition: newmm.h:284
PMM_SECTION_SEGMENT Segment
Definition: mm.h:199
FORCEINLINE VOID MmLockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1343
#define PAGE_READWRITE
Definition: nt_native.h:1304
FORCEINLINE BOOLEAN MiIsRosSectionObject(IN PVOID Section)
Definition: miarm.h:1034
MMSESSION MmSession
Definition: section.c:107
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 2833 of file section.c.

Referenced by MmMapViewOfSection().

2843 {
2846  PSECTION Section;
2847  PCONTROL_AREA ControlArea;
2848  ULONG ProtectionMask;
2849  NTSTATUS Status;
2850  PAGED_CODE();
2851 
2852  /* Get the segment and control area */
2853  Section = (PSECTION)SectionObject;
2854  ControlArea = Section->Segment->ControlArea;
2855 
2856  /* These flags/states are not yet supported by ARM3 */
2857  ASSERT(Section->u.Flags.Image == 0);
2858  ASSERT(Section->u.Flags.NoCache == 0);
2859  ASSERT(Section->u.Flags.WriteCombined == 0);
2860  ASSERT(ControlArea->u.Flags.PhysicalMemory == 0);
2861 
2862  /* FIXME */
2863  if ((AllocationType & MEM_RESERVE) != 0)
2864  {
2865  DPRINT1("MmMapViewOfArm3Section called with MEM_RESERVE, this is not implemented yet!!!\n");
2866  return STATUS_NOT_IMPLEMENTED;
2867  }
2868 
2869  /* Check if the mapping protection is compatible with the create */
2871  {
2872  DPRINT1("Mapping protection is incompatible\n");
2874  }
2875 
2876  /* Check if the offset and size would cause an overflow */
2877  if (((ULONG64)SectionOffset->QuadPart + *ViewSize) <
2879  {
2880  DPRINT1("Section offset overflows\n");
2881  return STATUS_INVALID_VIEW_SIZE;
2882  }
2883 
2884  /* Check if the offset and size are bigger than the section itself */
2885  if (((ULONG64)SectionOffset->QuadPart + *ViewSize) >
2886  (ULONG64)Section->SizeOfSection.QuadPart)
2887  {
2888  DPRINT1("Section offset is larger than section\n");
2889  return STATUS_INVALID_VIEW_SIZE;
2890  }
2891 
2892  /* Check if the caller did not specify a view size */
2893  if (!(*ViewSize))
2894  {
2895  /* Compute it for the caller */
2897 
2898  /* Check if it's larger than 4GB or overflows into kernel-mode */
2899  if ((*ViewSize > 0xFFFFFFFF) ||
2901  {
2902  DPRINT1("Section view won't fit\n");
2903  return STATUS_INVALID_VIEW_SIZE;
2904  }
2905  }
2906 
2907  /* Check if the commit size is larger than the view size */
2908  if (CommitSize > *ViewSize)
2909  {
2910  DPRINT1("Attempting to commit more than the view itself\n");
2912  }
2913 
2914  /* Check if the view size is larger than the section */
2915  if (*ViewSize > (ULONG64)Section->SizeOfSection.QuadPart)
2916  {
2917  DPRINT1("The view is larger than the section\n");
2918  return STATUS_INVALID_VIEW_SIZE;
2919  }
2920 
2921  /* Compute and validate the protection mask */
2922  ProtectionMask = MiMakeProtectionMask(Protect);
2923  if (ProtectionMask == MM_INVALID_PROTECTION)
2924  {
2925  DPRINT1("The protection is invalid\n");
2927  }
2928 
2929  /* We only handle pagefile-backed sections, which cannot be writecombined */
2930  if (Protect & PAGE_WRITECOMBINE)
2931  {
2932  DPRINT1("Cannot write combine a pagefile-backed section\n");
2934  }
2935 
2936  /* Start by attaching to the current process if needed */
2937  if (PsGetCurrentProcess() != Process)
2938  {
2939  KeStackAttachProcess(&Process->Pcb, &ApcState);
2940  Attached = TRUE;
2941  }
2942 
2943  /* Do the actual mapping */
2944  Status = MiMapViewOfDataSection(ControlArea,
2945  Process,
2946  BaseAddress,
2947  SectionOffset,
2948  ViewSize,
2949  Section,
2951  ProtectionMask,
2952  CommitSize,
2953  ZeroBits,
2954  AllocationType);
2955 
2956  /* Detach if needed, then return status */
2957  if (Attached) KeUnstackDetachProcess(&ApcState);
2958  return Status;
2959 }
_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:69
#define TRUE
Definition: types.h:120
KAPC_STATE
Definition: ketypes.h:1258
BOOLEAN NTAPI MiIsProtectionCompatible(IN ULONG SectionPageProtection, IN ULONG NewSectionPageProtection)
Definition: section.c:117
PSEGMENT Segment
Definition: mmtypes.h:813
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
ULONG PhysicalMemory
Definition: mmtypes.h:465
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
ULONG InitialPageProtection
Definition: mmtypes.h:820
union _CONTROL_AREA::@2304 u
union _SECTION::@2320 u
struct _CONTROL_AREA * ControlArea
Definition: mmtypes.h:401
uint32_t ULONG_PTR
Definition: typedefs.h:63
static BOOL Attached
Definition: vidbios.c:3904
#define FALSE
Definition: types.h:117
VOID NTAPI KeStackAttachProcess(IN PKPROCESS Process, OUT PRKAPC_STATE ApcState)
Definition: procobj.c:649
_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
LARGE_INTEGER SizeOfSection
Definition: mmtypes.h:814
uint64_t ULONG64
Definition: typedefs.h:65
#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
ULONG NTAPI MiMakeProtectionMask(IN ULONG Protect)
Definition: section.c:158
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T CommitSize
Definition: mmfuncs.h:404
#define STATUS_SECTION_PROTECTION
Definition: ntstatus.h:300
#define PAGED_CODE()
Definition: video.h:57
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
ULONG_PTR SIZE_T
Definition: typedefs.h:78
#define PAGE_WRITECOMBINE
Definition: mmtypes.h:78
#define STATUS_INVALID_VIEW_SIZE
Definition: ntstatus.h:254
LONG NTSTATUS
Definition: DriverTester.h:11
VOID NTAPI KeUnstackDetachProcess(IN PRKAPC_STATE ApcState)
Definition: procobj.c:701
#define STATUS_INVALID_PARAMETER_10
Definition: ntstatus.h:470
_Out_ PKAPC_STATE ApcState
Definition: mm.h:1411
#define DPRINT1
Definition: precomp.h:8
#define MM_HIGHEST_VAD_ADDRESS
Definition: mm.h:36
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T _Inout_opt_ PLARGE_INTEGER _Inout_ PSIZE_T ViewSize
Definition: mmfuncs.h:404
MMSECTION_FLAGS Flags
Definition: mmtypes.h:523
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
NTSTATUS NTAPI MiMapViewOfDataSection(IN PCONTROL_AREA ControlArea, IN PEPROCESS Process, IN PVOID *BaseAddress, IN PLARGE_INTEGER SectionOffset, IN PSIZE_T ViewSize, IN PSECTION Section, IN SECTION_INHERIT InheritDisposition, IN ULONG ProtectionMask, IN SIZE_T CommitSize, IN ULONG_PTR ZeroBits, IN ULONG AllocationType)
Definition: section.c:1252
ULONG WriteCombined
Definition: mmtypes.h: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 4491 of file section.c.

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

4501 {
4502  PROS_SECTION_OBJECT Section;
4504  ULONG ViewOffset;
4506  BOOLEAN NotAtBase = FALSE;
4507 
4509  {
4510  DPRINT("Mapping ARM3 section into %s\n", Process->ImageFileName);
4512  Process,
4513  BaseAddress,
4514  ZeroBits,
4515  CommitSize,
4516  SectionOffset,
4517  ViewSize,
4520  Protect);
4521  }
4522 
4523  ASSERT(Process);
4524 
4526  {
4528  }
4529 
4530  /* FIXME: We should keep this, but it would break code checking equality */
4531  Protect &= ~PAGE_NOCACHE;
4532 
4534  AddressSpace = &Process->Vm;
4535 
4537 
4538  MmLockAddressSpace(AddressSpace);
4539 
4540  if (Section->AllocationAttributes & SEC_IMAGE)
4541  {
4542  ULONG i;
4543  ULONG NrSegments;
4544  ULONG_PTR ImageBase;
4545  SIZE_T ImageSize;
4547  PMM_SECTION_SEGMENT SectionSegments;
4548 
4549  ImageSectionObject = Section->ImageSection;
4550  SectionSegments = ImageSectionObject->Segments;
4551  NrSegments = ImageSectionObject->NrSegments;
4552 
4553  ImageBase = (ULONG_PTR)*BaseAddress;
4554  if (ImageBase == 0)
4555  {
4556  ImageBase = (ULONG_PTR)ImageSectionObject->BasedAddress;
4557  }
4558 
4559  ImageSize = 0;
4560  for (i = 0; i < NrSegments; i++)
4561  {
4562  ULONG_PTR MaxExtent;
4563  MaxExtent = (ULONG_PTR)(SectionSegments[i].Image.VirtualAddress +
4564  SectionSegments[i].Length.QuadPart);
4565  ImageSize = max(ImageSize, MaxExtent);
4566  }
4567 
4568  ImageSectionObject->ImageInformation.ImageFileSize = (ULONG)ImageSize;
4569 
4570  /* Check for an illegal base address */
4571  if (((ImageBase + ImageSize) > (ULONG_PTR)MmHighestUserAddress) ||
4572  ((ImageBase + ImageSize) < ImageSize))
4573  {
4574  ASSERT(*BaseAddress == NULL);
4575  ImageBase = ALIGN_DOWN_BY((ULONG_PTR)MmHighestUserAddress - ImageSize,
4577  NotAtBase = TRUE;
4578  }
4579  else if (ImageBase != ALIGN_DOWN_BY(ImageBase, MM_VIRTMEM_GRANULARITY))
4580  {
4581  ASSERT(*BaseAddress == NULL);
4582  ImageBase = ALIGN_DOWN_BY(ImageBase, MM_VIRTMEM_GRANULARITY);
4583  NotAtBase = TRUE;
4584  }
4585 
4586  /* Check there is enough space to map the section at that point. */
4587  if (MmLocateMemoryAreaByRegion(AddressSpace, (PVOID)ImageBase,
4588  PAGE_ROUND_UP(ImageSize)) != NULL)
4589  {
4590  /* Fail if the user requested a fixed base address. */
4591  if ((*BaseAddress) != NULL)
4592  {
4593  MmUnlockAddressSpace(AddressSpace);
4595  }
4596  /* Otherwise find a gap to map the image. */
4597  ImageBase = (ULONG_PTR)MmFindGap(AddressSpace, PAGE_ROUND_UP(ImageSize), MM_VIRTMEM_GRANULARITY, FALSE);
4598  if (ImageBase == 0)
4599  {
4600  MmUnlockAddressSpace(AddressSpace);
4602  }
4603  /* Remember that we loaded image at a different base address */
4604  NotAtBase = TRUE;
4605  }
4606 
4607  for (i = 0; i < NrSegments; i++)
4608  {
4609  PVOID SBaseAddress = (PVOID)
4610  ((char*)ImageBase + (ULONG_PTR)SectionSegments[i].Image.VirtualAddress);
4611  MmLockSectionSegment(&SectionSegments[i]);
4612  Status = MmMapViewOfSegment(AddressSpace,
4613  Section,
4614  &SectionSegments[i],
4615  &SBaseAddress,
4616  SectionSegments[i].Length.LowPart,
4617  SectionSegments[i].Protection,
4618  0,
4619  0);
4620  MmUnlockSectionSegment(&SectionSegments[i]);
4621  if (!NT_SUCCESS(Status))
4622  {
4623  MmUnlockAddressSpace(AddressSpace);
4624  return(Status);
4625  }
4626  }
4627 
4628  *BaseAddress = (PVOID)ImageBase;
4629  *ViewSize = ImageSize;
4630  }
4631  else
4632  {
4633  /* check for write access */
4636  {
4637  MmUnlockAddressSpace(AddressSpace);
4639  }
4640  /* check for read access */
4643  {
4644  MmUnlockAddressSpace(AddressSpace);
4646  }
4647  /* check for execute access */
4650  {
4651  MmUnlockAddressSpace(AddressSpace);
4653  }
4654 
4655  if (SectionOffset == NULL)
4656  {
4657  ViewOffset = 0;
4658  }
4659  else
4660  {
4661  ViewOffset = SectionOffset->u.LowPart;
4662  }
4663 
4664  if ((ViewOffset % PAGE_SIZE) != 0)
4665  {
4666  MmUnlockAddressSpace(AddressSpace);
4667  return(STATUS_MAPPED_ALIGNMENT);
4668  }
4669 
4670  if ((*ViewSize) == 0)
4671  {
4672  (*ViewSize) = Section->MaximumSize.u.LowPart - ViewOffset;
4673  }
4674  else if (((*ViewSize)+ViewOffset) > Section->MaximumSize.u.LowPart)
4675  {
4676  (*ViewSize) = Section->MaximumSize.u.LowPart - ViewOffset;
4677  }
4678 
4680 
4681  MmLockSectionSegment(Section->Segment);
4682  Status = MmMapViewOfSegment(AddressSpace,
4683  Section,
4684  Section->Segment,