guest_memory.h
The libsel4vm memory interface provides useful abstractions to manage your guest VM‘s address space. This interface can be leveraged for uses such as mapping device memory into your VM instance or for creating emulated device regions binded with custom handlers/callbacks. The main mechanisms this interface provides involves reserving memory regions and using those reservations to either map memory into your guest VM’s address space or emulate subsequent accesses. Reservations are created through either using vm_reserve_memory_at
or vm_reserve_anon_memory
. The user can then further back the reservation with seL4 frames by performing vm_map_reservation
.
Functions:
vm_reserve_memory_at(vm, addr, size, fault_callback, cookie)
vm_reserve_anon_memory(vm, size, fault_callback, cookie, addr)
Structs:
The interface guest_memory.h
defines the following functions.
vm_reserve_memory_at(vm, addr, size, fault_callback, cookie)
Reserve a region of the VM's memory at a given base address
Parameters:
vm {vm_t *}
: A handle to the VMaddr {uintptr}
: Base address of the memory region being reservedsize {size_t}
: Size of the memory region being reservedfault_callback {memory_fault_callback_fn}
: Callback function that will be invoked if memory region is faulted oncookie {void *}
: User cookie to pass onto to callbackReturns:
Back to interface description.
vm_reserve_anon_memory(vm, size, fault_callback, cookie, addr)
Reserve an anonymous region of the VM's memory. This uses memory previously made anonymous through the vm_memory_make_anon
function.
Parameters:
vm {vm_t *}
: A handle to the VMsize {size_t}
: Size of the anoymous emory region being reservedfault_callback {memory_fault_callback_fn}
: Callback function that will be invoked if memory region is faulted oncookie {void *}
: User cookie to pass onto to callbackaddr {uintptr_t *}
: Pointer that will be set with the base address of the reserved anonymous regionReturns:
Back to interface description.
vm_free_reserved_memory(vm, reservation)
Free memory reservation from the VM
Parameters:
vm {vm_t *}
: A handle to the VMreservation {vm_memory_reservation_t *}
: Pointer to the reservation being free'dReturns:
Back to interface description.
vm_map_reservation(vm, reservation, map_iterator, cookie)
Map a reservation into the VM's virtual address space
Parameters:
vm {vm_t *}
: A handle to the VMreservation {vm_memory_reservation_t *}
: Pointer to reservation object being mappedmap_iterator {memory_map_iterator_fn}
: Iterator function that returns a cap to the memory region being mappedcookie {void *}
: Cookie to pass onto map_iterator functionReturns:
Back to interface description.
vm_get_reservation_memory_region(reservation, addr, size)
Get the memory region information (address & size) from a given reservation
Parameters:
reservation {vm_memory_reservation_t *}
: Pointer to reservation objectaddr {uintptr_t *}
: Pointer that will be set with the address of reservationsize {size_t *}
: Pointer that will be set with the size of reservationReturns:
No return
Back to interface description.
vm_memory_init(vm)
Initialise a VM's memory management interface
Parameters:
vm {vm_t *}
: A handle to the VMReturns:
Back to interface description.
The interface guest_memory.h
defines the following structs.
vm_frame_t
Structure representing a mappable memory frame
Elements:
cptr {seL4_CPtr}
: Capability to framerights {seL4_CapRights_t}
: Mapping rights of framevaddr {uintptr_t}
: Virtual address of which to map the frame intosize_bits {size_t}
: Size of frame in bitsBack to interface description.
Back to top.