VirtualProtectVlm

[This is preliminary documentation and subject to change.]

The VirtualProtectVlm function changes the access type for a region of memory allocated using the VirtualAllocVlm function.

BOOL VirtualProtectVlm(
  HANDLE hProcess,     // process within which to protect memory
  PVOID64 lpAddress,   // address of region of committed pages
  DWORDLONG ullSize,   // size of the region
  DWORD flNewProtect,  // desired access protection
  PDWORD lpflOldProtect 
                       // address of variable to get old protection
);
 

Parameters

hProcess
Handle to the process whose access attributes are to be changed. The calling process must have had the PROCESS_VM_OPERATION flag set on a preceding call to the OpenProcess function, indicating virtual memory access to the target process, or VirtualProtectVlm fails.
lpAddress
Pointer to the base address of the region of pages whose access attributes are to be changed.

Only full 64-bit addresses are supported here — 32-bit sign-extended addresses are not supported. In other words, the 4 GB range surrounding address zero cannot be modified using VirtualProtectVlm.

All pages in the specified region must have been allocated in a single call to the VirtualAllocVlm function. The pages cannot span adjacent regions that were allocated by separate calls to VirtualAllocVlm.

ullSize
Size, in bytes, of the region whose access attributes are to be changed. The region of affected pages includes all pages containing one or more bytes in the range from the value of lpAddress to the value of lpAddress plus the value of the ullSize parameter. This functionality means that changing the attributes of a 2-byte range straddling a page boundary causes the access attributes of both pages to be changed.
flNewProtect
Flag that specifies the new access type. You can specify one of the following flags.
Value Meaning
PAGE_NOACCESS Disables all access to the committed region of pages. An attempt to read from, or write to, or execute code in the committed region results in an access violation exception.
PAGE_READONLY Enables read access to the committed region of pages. An attempt to write to the committed region results in an access violation. If the operating system differentiates between read-only access and execute access, an attempt to execute code in the committed region results in an access violation.
PAGE_READWRITE Enables both read and write access to the committed region of pages.

lpflOldProtect
Pointer to a variable that VirtualProtectVlm sets to the previous access value of the first page in the specified region of pages. If the lpflOldProtect parameter is NULL or does not point to a valid variable, VirtualProtectVlm fails.

Return Values

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

You can set an access value for pages that have been committed only. If any page in the specified region is not committed, VirtualProtectVlm fails and returns without modifying the access state of any pages in the specified region.

QuickInfo

  Windows NT: Requires version 5.0 or later.
  Windows: Unsupported.
  Windows CE: Unsupported.
  Header: Declared in winbase.h.
  Import Library: Use kernel32.lib.

See Also

Memory Management Overview, Memory Management Functions, Very Large Memory (VLM), OpenProcess, VirtualAllocVlm, VirtualProtect, VirtualProtectEx