NtDllNtMapViewOfSection(IntPtr, SafeProcessHandle, IntPtr, IntPtr, IntPtr, Int64, UIntPtr, SectionInherit, MemoryAllocationType, MemoryProtectionOptions) Method

Maps a view of a section into the virtual address space of a subject process.

Definition

Namespace: DevCase.Win32.NativeMethods
Assembly: DevCase.net48 (in DevCase.net48.dll) Version: 6.0.0.0 (6.0)
XMLNS for XAML: Not mapped to an xmlns.
[DllImportAttribute("NtDll.dll", CallingConvention = CallingConvention.StdCall)]
public static NTStatus NtMapViewOfSection(
	IntPtr hSection,
	SafeProcessHandle hProcess,
	ref IntPtr refBaseAddress,
	IntPtr zeroBits,
	IntPtr commitSize,
	[OptionalAttribute] ref long refSectionOffset,
	ref UIntPtr refViewSize,
	SectionInherit sectionInherit,
	MemoryAllocationType allocationType,
	MemoryProtectionOptions protection
)

Parameters

hSection  IntPtr
Handle to a section object.

This handle is created by a successful call to NtCreateSection(IntPtr, GenericAccessRights, ObjectAttributes, UInt64, MemoryProtectionOptions, SectionAttributes, SafeFileHandle) or NtOpenSection(IntPtr, GenericAccessRights, IntPtr).

hProcess  SafeProcessHandle
Handle to the object that represents the process that the view should be mapped into.

The handle must have been opened with VirtualMemoryOperation access.

refBaseAddress  IntPtr
Pointer to a variable that receives the base address of the view.

If the value of this parameter is not Zero, the view is allocated starting at the specified virtual address rounded down to the next 64-kilobyte address boundary.

zeroBits  IntPtr
Specifies the number of high-order address bits that must be zero in the base address of the section view.

The value of this parameter must be less than 21 and is used only if refBaseAddress is NULL—in other words, when the caller allows the system to determine where to allocate the view.

commitSize  IntPtr
Specifies the size, in bytes, of the initially committed region of the view.

commitSize is meaningful only for page-file backed sections and is rounded up to the nearest multiple of PAGE_SIZE.

(for sections that map files, both the data and the image are committed at section-creation time).

refSectionOffset  Int64  (Optional)
A pointer to a variable that receives the offset, in bytes, from the beginning of the section to the view.

If this pointer is not Zero, the offset is rounded down to the next allocation-granularity size boundary.

refViewSize  UIntPtr
A pointer to a SIZE_T variable.

If the initial value of this variable is zero, NtMapViewOfSection(IntPtr, SafeProcessHandle, IntPtr, IntPtr, IntPtr, Int64, UIntPtr, SectionInherit, MemoryAllocationType, MemoryProtectionOptions) maps a view of the section that starts at refSectionOffset and continues to the end of the section. Otherwise, the initial value specifies the view's size, in bytes.

NtMapViewOfSection(IntPtr, SafeProcessHandle, IntPtr, IntPtr, IntPtr, Int64, UIntPtr, SectionInherit, MemoryAllocationType, MemoryProtectionOptions) always rounds this value up to the nearest multiple of PAGE_SIZE before mapping the view.

On return, the value receives the actual size, in bytes, of the view.

sectionInherit  SectionInherit
Specifies how the view is to be shared with child processes.
allocationType  MemoryAllocationType
Specifies a set of flags that describes the type of allocation to be performed for the specified region of pages.

The valid flags are LargePages, Reserve, and TopDown.

Although Commit is not allowed, it is implied unless Reserve is specified.

protection  MemoryProtectionOptions
Specifies the type of protection for the region of initially committed pages.

Device and intermediate drivers should set this value to ReadWrite.

Return Value

NTStatus
Returns SUCCESS on success, or the appropriate NTStatus error code on failure.

Remarks

See Also