Skip to content

Commit

Permalink
kata-os-camkes: wrap request ipc buffer capability handling
Browse files Browse the repository at this point in the history
Add Camkes::set_request_cap to attach an seL4 capability to an outbound
ipc message. The return value is an RAII wrapper that cleans up state
and must be held until after the CAmkES rpc call completes

Change-Id: I0672c59e0b5e43e39c9ea3fb16809270a33f51ef
GitOrigin-RevId: 56be13a2c05fcc1b4a1aa5c8e0eab47bcd0f2345
  • Loading branch information
sleffler committed Aug 10, 2022
1 parent a67242a commit 45f374c
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions apps/system/components/kata-os-common/src/camkes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use sel4_sys;
use sel4_sys::seL4_CNode_Delete;
use sel4_sys::seL4_CPtr;
use sel4_sys::seL4_GetCapReceivePath;
use sel4_sys::seL4_SetCap;
use sel4_sys::seL4_SetCapReceivePath;
use sel4_sys::seL4_Word;
use sel4_sys::seL4_WordBits;
Expand All @@ -28,6 +29,14 @@ extern "C" {
static SELF_CNODE_LAST_SLOT: seL4_CPtr;
}

// RAII wrapper for handling request cap cleanup.
pub struct RequestCapCleanup {}
impl Drop for RequestCapCleanup {
fn drop(&mut self) {
unsafe { seL4_SetCap(0, 0); }
}
}

pub struct Camkes {
name: &'static str, // Component name
recv_path: seL4_CPath, // IPCBuffer receive path
Expand Down Expand Up @@ -115,6 +124,14 @@ impl Camkes {
self.get_current_recv_path(), self.recv_path);
}

// Attaches a capability to a CAmkES RPC request msg. seL4 will copy
// the capabiltiy.
#[must_use]
pub fn set_request_cap(cptr: seL4_CPtr) -> RequestCapCleanup {
unsafe { seL4_SetCap(0, cptr); }
RequestCapCleanup{}
}

// Wrappers for sel4_sys::debug_assert macros.
pub fn debug_assert_slot_empty(tag: &str, path: &seL4_CPath) {
sel4_sys::debug_assert_slot_empty!(path.1,
Expand Down

0 comments on commit 45f374c

Please sign in to comment.