twizzler_abi/runtime/object/
slot.rspub fn global_allocate() -> Option<usize> {
SLOT_TRACKER.lock().alloc()
}
#[allow(dead_code)]
pub fn global_release(slot: usize) {
SLOT_TRACKER.lock().dealloc(slot)
}
use bitset_core::BitSet;
use crate::{
arch::SLOTS,
aux::KernelInitInfo,
object::{MAX_SIZE, NULLPAGE_SIZE},
runtime::simple_mutex::Mutex,
};
struct SlotTracker {
bitmap: [u32; SLOTS / 32],
}
static SLOT_TRACKER: Mutex<SlotTracker> = Mutex::new(SlotTracker {
bitmap: [0; SLOTS / 32],
});
use crate::slot::ALLOC_START;
impl SlotTracker {
fn alloc(&mut self) -> Option<usize> {
for slot in ALLOC_START..self.bitmap.bit_len() {
if !self.bitmap.bit_test(slot) {
self.bitmap.bit_set(slot);
return Some(slot);
}
}
None
}
fn dealloc(&mut self, slot: usize) {
self.bitmap.bit_reset(slot);
}
}
pub(crate) fn slot_to_start_and_meta(slot: usize) -> (usize, usize) {
let start = slot * MAX_SIZE;
let end = (slot + 1) * MAX_SIZE - NULLPAGE_SIZE;
(start, end)
}
pub fn get_kernel_init_info() -> &'static KernelInitInfo {
let (start, _) = slot_to_start_and_meta(crate::slot::RESERVED_KERNEL_INIT);
unsafe {
((start + NULLPAGE_SIZE) as *const KernelInitInfo)
.as_ref()
.unwrap()
}
}