MemoryProtectionOptions Enumeration

Specifies memory-protection options.

You must specify one of the following values when allocating or protecting a page in memory.

Protection attributes cannot be assigned to a portion of a page; they can only be assigned to a whole page

Definition

Namespace: DevCase.Win32.Enums
Assembly: DevCase.net48 (in DevCase.net48.dll) Version: 6.0.0.0 (6.0)
XMLNS for XAML: Not mapped to an xmlns.
[FlagsAttribute]
public enum MemoryProtectionOptions

Remarks

Members

None 0 None.
NoAccess 1 Disables all access to the committed region of pages.

An attempt to read from, write to, or execute the committed region results in an access violation.

This flag is not supported by the CreateFileMapping function.

ReadOnly 2 Enables read-only access to the committed region of pages.

An attempt to write to the committed region results in an access violation.

If Data Execution Prevention feature is enabled in the current Windows operating system, an attempt to execute code in the committed region results in an access violation.

ReadWrite 4 Enables read-only or read/write access to the committed region of pages.

If Data Execution Prevention feature is enabled in the current Windows operating system, attempting to execute code in the committed region results in an access violation.

WriteCopy 8 Enables read-only or copy-on-write access to a mapped view of a file mapping object.

An attempt to write to a committed copy-on-write page results in a private copy of the page being made for the process.

The private page is marked as ReadWrite, and the change is written to the new page.

If Data Execution Prevention feature is enabled in the current Windows operating system, attempting to execute code in the committed region results in an access violation.

This flag is not supported by the VirtualAlloc(IntPtr, IntPtr, MemoryAllocationType, MemoryProtectionOptions) or VirtualAllocEx(IntPtr, IntPtr, IntPtr, MemoryAllocationType, MemoryProtectionOptions) functions.

Execute 16 Enables execute access to the committed region of pages.

An attempt to write to the committed region results in an access violation.

This flag is not supported by the CreateFileMapping function.

ExecuteRead 32 Enables execute or read-only access to the committed region of pages.

An attempt to write to the committed region results in an access violation.

ExecuteReadWrite 64 Enables execute, read-only, or read/write access to the committed region of pages.
ExecuteWriteCopy 128 Enables execute, read-only, or copy-on-write access to a mapped view of a file mapping object.

An attempt to write to a committed copy-on-write page results in a private copy of the page being made for the process.

The private page is marked as ExecuteReadWrite, and the change is written to the new page.

This flag is not supported by the VirtualAlloc(IntPtr, IntPtr, MemoryAllocationType, MemoryProtectionOptions) or VirtualAllocEx(IntPtr, IntPtr, IntPtr, MemoryAllocationType, MemoryProtectionOptions) functions.

Guard 256 Pages in the region become guard pages.

Any attempt to access a guard page causes the system to raise a STATUS_GUARD_PAGE_VIOLATION exception and turn off the guard page status.

Guard pages thus act as a one-time access alarm.

When an access attempt leads the system to turn off guard page status, the underlying page protection takes over.

If a guard page exception occurs during a system service, the service typically returns a failure status indicator.

This value cannot be used with NoAccess.

This flag is not supported by the CreateFileMapping function.

NoCache 512 Sets all pages to be non-cachable.

Applications should not use this attribute except when explicitly required for a device.

Using the interlocked functions with memory that is mapped with SEC_NOCACHE can result in an EXCEPTION_ILLEGAL_INSTRUCTION exception.

The NoCache flag cannot be used with the Guard, NoAccess, or WriteCombine flags.

The NoCache flag can be used only when allocating private memory with the VirtualAlloc(IntPtr, IntPtr, MemoryAllocationType, MemoryProtectionOptions), VirtualAllocEx(IntPtr, IntPtr, IntPtr, MemoryAllocationType, MemoryProtectionOptions), or VirtualAllocExNuma functions.

To enable non-cached memory access for shared memory, specify the SEC_NOCACHE flag when calling the CreateFileMapping function.

WriteCombine 1,024 Sets all pages to be write-combined.

Applications should not use this attribute except when explicitly required for a device.

Using the interlocked functions with memory that is mapped as write-combined can result in an EXCEPTION_ILLEGAL_INSTRUCTION exception.

The PAGE_WRITECOMBINE flag cannot be specified with the PAGE_NOACCESS, PAGE_GUARD, and PAGE_NOCACHE flags.

The WriteCombine flag can be used only when allocating private memory with the VirtualAlloc(IntPtr, IntPtr, MemoryAllocationType, MemoryProtectionOptions), VirtualAllocEx(IntPtr, IntPtr, IntPtr, MemoryAllocationType, MemoryProtectionOptions), or VirtualAllocExNuma functions.

To enable write-combined memory access for shared memory, specify the SEC_WRITECOMBINE flag when calling the CreateFileMapping function.

See Also