AllocateUserPhysicalPages2 function (memoryapi.h)

Allocates physical memory pages to be mapped and unmapped within any Address Windowing Extensions (AWE) region of a specified process, with extended parameters.

Syntax

BOOL AllocateUserPhysicalPages2(
  [in]     HANDLE                  ObjectHandle,
  [in,out] PULONG_PTR              NumberOfPages,
  [out]    PULONG_PTR              PageArray,
  [in,out] PMEM_EXTENDED_PARAMETER ExtendedParameters,
  [in]     ULONG                   ExtendedParameterCount
);

Parameters

[in] ObjectHandle

A handle to a process.

The function allocates memory that can later be mapped within the virtual address space of this process. The handle must have the PROCESS_VM_OPERATION access right. For more information, see Process Security and Access Rights.

[in,out] NumberOfPages

The size of the physical memory to allocate, in pages.

To determine the page size of the computer, use the GetSystemInfo function. On output, this parameter receives the number of pages that are actually allocated, which might be less than the number requested.

[out] PageArray

A pointer to an array to store the page frame numbers of the allocated memory.

The size of the array that is allocated should be at least the NumberOfPages times the size of the ULONG_PTR data type.

Do not attempt to modify this buffer. It contains operating system data, and corruption could be catastrophic. The information in the buffer is not useful to an application.

[in,out] ExtendedParameters

Pointer to an array of MEM_EXTENDED_PARAMETER structures.

[in] ExtendedParameterCount

The number of MEM_EXTENDED_PARAMETER in the ExtendedParameters array.

Return value

If the function succeeds, the return value is TRUE.

Fewer pages than requested can be allocated. The caller must check the value of the NumberOfPages parameter on return to see how many pages are allocated. All allocated page frame numbers are sequentially placed in the memory pointed to by the UserPfnArray parameter.

If the function fails, the return value is FALSE, and no frames are allocated. To get extended error information, call GetLastError.

Remarks

AllocateUserPhysicalPages2 is the same as AllocateUserPhysicalPages but it adds the ExtendedParameters and ExtendedParameterCount parameters.

The AllocateUserPhysicalPages2 function is used to allocate physical memory that can later be mapped within the virtual address space of the process. The SeLockMemoryPrivilege privilege must be enabled in the caller's token or the function will fail with ERROR_PRIVILEGE_NOT_HELD. For more information, see Privilege Constants.

Memory allocated by this function must be physically present in the system. After the memory is allocated, it is locked down and unavailable to the rest of the virtual memory management system.

Physical pages cannot be simultaneously mapped at more than one virtual address.

Physical pages can reside at any physical address. You should make no assumptions about the contiguity of the physical pages.

Requirements

Requirement Value
Minimum supported client Windows 11, Build 20348
Minimum supported server Windows Server, Build 20348
Header memoryapi.h
Library onecore.lib
DLL kernelbase.dll

See also

AllocateUserPhysicalPages

Address Windowing Extensions

AllocateUserPhysicalPagesNuma

FreeUserPhysicalPages

MapUserPhysicalPages

MapUserPhysicalPagesScatter

Memory Management Functions