Merge "sel4-sys: add some debug helpers"

GitOrigin-RevId: 6d3453d2d46b3af864ea84e8c8d8413acdceb681
This commit is contained in:
Sam Leffler
2022-05-10 22:42:31 +00:00
parent d13355401a
commit 3bf4242a91
2 changed files with 60 additions and 0 deletions

View File

@@ -0,0 +1,57 @@
#![allow(dead_code)]
// Support for debugging capability handling. These only do something
// in a DEBUG build where cap_identify should work. Beware of the
// hardwired cap type codes; the 3 macros defined should be portable
// but seL4 generates defs that are architecture & feature-dependent.
// Note one can implement an is_slot_empty check without
// seL4_DebugCapIdentify by checking the error code from doing a cap
// move slot -> slot. We do not use it mainly because it will spam
// the console if CONFIG_PRINTING is enabled.
use crate::seL4_CPtr;
#[inline]
#[cfg(feature = "CONFIG_DEBUG_BUILD")]
pub fn cap_identify(cap: seL4_CPtr) -> Option<u32> {
Some(unsafe { crate::seL4_DebugCapIdentify(cap) })
}
#[inline]
#[cfg(not(feature = "CONFIG_DEBUG_BUILD"))]
pub fn cap_identify(_cap: seL4_CPtr) -> Option<u32> {
None // cap_null_cap
}
#[macro_export]
macro_rules! debug_assert_slot_empty {
// 0 is cap_null_cap
($cap:expr) => {
debug_assert!($crate::cap_identify($cap) == Some(0))
};
($cap:expr, $($arg:tt)+) => {
debug_assert!($crate::cap_identify($cap) == Some(0), $($arg)+)
};
}
#[macro_export]
macro_rules! debug_assert_slot_frame {
// 1 is cap_frame_cap
($cap:expr) => {
debug_assert!($crate::cap_identify($cap) == Some(1))
};
($cap:expr, $($arg:tt)+) => {
debug_assert!($crate::cap_identify($cap) == Some(1), $($arg)+)
};
}
#[macro_export]
macro_rules! debug_assert_slot_cnode {
// 10 is cap_frame_cap
($cap:expr) => {
debug_assert!($crate::cap_identify($cap) == Some(10))
};
($cap:expr, $($arg:tt)+) => {
debug_assert!($crate::cap_identify($cap) == Some(10), $($arg)+)
};
}

View File

@@ -25,6 +25,9 @@ assert_cfg!(any(
all(target_arch = "x86_64"),
));
mod debug;
pub use debug::*;
pub use seL4_BreakpointAccess::*;
pub use seL4_BreakpointType::*;
pub use seL4_Error::*;