vmar_map - add a memory mapping
#include <magenta/syscalls.h> mx_status_t mx_vmar_map(mx_handle_t vmar, size_t vmar_offset, mx_handle_t vmo, uint64_t vmo_offset, size_t len, uint32_t map_flags, uintptr_t* mapped_addr)
Maps the given VMO into the given virtual memory address region. The mapping retains a reference to the underlying virtual memory object, which means closing the VMO handle does not remove the mapping added by this function.
map_flags is a bit vector of the following flags:
vmar_offset must be 0 if map_flags does not have MX_VM_FLAG_SPECIFIC or MX_VM_FLAG_SPECIFIC_OVERWRITE set. If neither of those flags are set, then the mapping will be assigned an offset at random by the kernel (with an allocator determined by policy set on the target VMAR).
vmar_map() returns MX_OK and the absolute base address of the mapping (via mapped_addr) on success. In the event of failure, a negative error value is returned.
MX_ERR_BAD_HANDLE vmar or vmo is not a valid handle.
MX_ERR_WRONG_TYPE vmar or vmo is not a VMAR or VMO handle, respectively.
MX_ERR_BAD_STATE vmar refers to a destroyed VMAR.
MX_ERR_INVALID_ARGS mapped_addr or map_flags are not valid, vmar_offset is non-zero when neither MX_VM_FLAG_SPECIFIC nor MX_VM_FLAG_SPECIFIC_OVERWRITE are given, vmar_offset and len describe an unsatisfiable allocation due to exceeding the region bounds, vmar_offset or vmo_offset are not page-aligned, vmo_offset + ROUNDUP(len, PAGE_SIZE) overflows, or len is 0.
MX_ERR_ACCESS_DENIED Insufficient privileges to make the requested mapping.
MX_ERR_NO_MEMORY (Temporary) Failure due to lack of memory.
A virtual memory object can be larger than the address space, which means you should check for overflow before converting the uint64_t size of the VMO to vmar_map's size_t len parameter.