kernel_thread/utils/
obj.rsuse alloc::vec::Vec;
use common::{ObjectAllocator, config::DEFAULT_CUSTOM_SLOT};
use sel4::{
Cap,
cap::{Granule, Notification, PT},
cap_type,
};
use spin::Mutex;
pub(crate) static OBJ_ALLOCATOR: ObjectAllocator = ObjectAllocator::empty();
#[inline]
pub fn alloc_notification() -> Notification {
OBJ_ALLOCATOR.alloc_notification()
}
pub fn alloc_vdso_page() -> Granule {
OBJ_ALLOCATOR.alloc_page()
}
#[inline]
pub fn alloc_pt() -> PT {
OBJ_ALLOCATOR.alloc_pt()
}
pub fn init() {
OBJ_ALLOCATOR.init(Cap::from_bits(DEFAULT_CUSTOM_SLOT as _));
}
const ALLOC_SIZE_BITS: usize = 21; static RECYCLED_UNTYPED: Mutex<Vec<Cap<cap_type::Untyped>>> = Mutex::new(Vec::new());
pub fn alloc_untyped_unit() -> (Cap<cap_type::Untyped>, usize) {
let cap = match RECYCLED_UNTYPED.lock().pop() {
Some(cap) => cap,
None => OBJ_ALLOCATOR.alloc_untyped(ALLOC_SIZE_BITS),
};
(cap, 1 << ALLOC_SIZE_BITS)
}
pub fn recycle_untyped_unit(cap: Cap<cap_type::Untyped>) {
RECYCLED_UNTYPED.lock().push(cap);
}