Add a memory mapping.
#include <zircon/syscalls.h> zx_status_t zx_vmar_map(zx_handle_t handle, zx_vm_option_t options, size_t vmar_offset, zx_handle_t vmo, uint64_t vmo_offset, size_t len, zx_vaddr_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.
options is a bit vector of the following:
zx_pager_create_vmo()
.vmar_offset must be 0 if options does not have ZX_VM_SPECIFIC or ZX_VM_SPECIFIC_OVERWRITE set. If neither of those 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).
len must be page-aligned.
In addition one of the following power-of-two alignment flags can added:
Using ZX_VM_ALIGN flags with ZX_VM_SPECIFIC will fail if the vmar base address + vmo_offset are not aligned to the requested value.
handle must be of type ZX_OBJ_TYPE_VMAR.
vmo must be of type ZX_OBJ_TYPE_VMO.
zx_vmar_map()
returns ZX_OK and the absolute base address of the mapping (via mapped_addr) on success. The base address will be page-aligned and non-zero. In the event of failure, a negative error value is returned.
ZX_ERR_BAD_HANDLE handle or vmo is not a valid handle.
ZX_ERR_WRONG_TYPE handle or vmo is not a VMAR or VMO handle, respectively.
ZX_ERR_BAD_STATE handle refers to a destroyed VMAR.
ZX_ERR_INVALID_ARGS mapped_addr or options are not valid, vmar_offset is non-zero when neither ZX_VM_SPECIFIC nor ZX_VM_SPECIFIC_OVERWRITE are given, ZX_VM_SPECIFIC_OVERWRITE and ZX_VM_MAP_RANGE are both given, vmar_offset and len describe an unsatisfiable allocation due to exceeding the region bounds, vmar_offset or vmo_offset or len are not page-aligned, vmo_offset + ROUNDUP(len, PAGE_SIZE)
overflows.
ZX_ERR_ACCESS_DENIED Insufficient privileges to make the requested mapping.
ZX_ERR_NOT_SUPPORTED If the vmo is resizable, or backed by a pager but ZX_VM_ALLOW_FAULTS is not set.
ZX_ERR_BUFFER_TOO_SMALL The VMO is not resizable and the mapping extends past the end of the VMO but ZX_VM_ALLOW_FAULTS is not set.
ZX_ERR_NO_MEMORY Failure due to lack of memory. There is no good way for userspace to handle this (unlikely) error. In a future build this error will no longer occur.
ZX_ERR_NO_MEMORY ZX_VM_SPECIFIC has been specified, ZX_VM_SPECIFIC_OVERWRITE has not been specified, and the requested range overlaps with another mapping.
The VMO that backs a memory mapping can be resized to a smaller size. This can cause the thread is reading or writing to the VMAR region to fault. To avoid this hazard, services that receive VMOs from clients should use ZX_VM_REQUIRE_NON_RESIZABLE when mapping the VMO.