Skip to content

MemMap

Maps a memory object into the caller's address space.

Number Selector Blocking Since
0x0B SVC_MANAGEMEMORY MNGMEM_MAP (0) no 2.0
void * MemMap(Handle mem_handle, VirtAddr hint_va, MemProt prot);

Registers: (mem, hint | prot) -> r0 address or error

A handle can back one mapping at a time; duplicate it to map the object twice.

Parameters

Name Direction Description
mem_handle in Memory object handle with PERM_MAP, plus PERM_WRITE to map writable and PERM_EXEC to map executable.
hint_va in Page-aligned address to map at, or 0 to let the kernel choose.
prot in PROT_READ / PROT_WRITE / PROT_EXEC, but never writable and executable.

Returns

The mapped address, or an error encoded as a pointer; check with PtrIsErr().

Errors

Error Condition
ERR_BADHANDLE mem_handle is not a live handle.
ERR_BADTYPE mem_handle is not a memory object.
ERR_NOPERM mem_handle lacks PERM_MAP, or the PERM_WRITE / PERM_EXEC prot asks for, or PROT_EXEC on uncached memory.
ERR_BUSY This handle is already mapped.
ERR_BADARG hint_va is unusable, or prot is both writable and executable.
ERR_NOMEM No address space or page tables left.