gila/src/kernel/capability.rs
August a384ebec4f
All checks were successful
Continuous Integration / Check (push) Successful in 1m2s
Continuous Integration / Clippy (push) Successful in 1m5s
Capability structure start
2026-10-11 21:55:45 -04:00

58 lines
1.6 KiB
Rust

#![allow(dead_code)]
#[repr(C, packed)]
pub struct Capability<'a> {
component: u16, // Issuing component ID, 0.25 bytes
resource: u16, // Resource type, 0.25 bytes
instance: u64, // Instance ID, 1 byte
rights: u32, // Access rights, 0.5 bytes
child: *mut Capability<'a>, // Derived capability, 1 byte
parent: *mut Capability<'a>, // Parent capability, 1 byte
}
pub struct CapabilityBlock<'a> {
caps: [Capability<'a>; 1024],
}
impl<'a> Capability<'a> {
fn null() -> Capability<'a> {
Capability {
component: 0,
resource: 0,
instance: 0,
rights: 0,
child: core::ptr::null_mut(),
parent: core::ptr::null_mut(),
}
}
fn child(&self) -> Option<&'a Capability<'a>> {
unsafe { self.child.as_ref() }
}
fn child_mut(&mut self) -> Option<&'a mut Capability<'a>> {
unsafe { self.child.as_mut() }
}
fn delete_child(&mut self) {
if let Some(child) = self.child_mut() {
match child.child_mut() {
// Current child has no children. Null it and gorget it
None => {
let _ = core::mem::replace(child, Capability::null());
self.child = core::ptr::null_mut();
}
// Current child has children. Delegate their deletion to the child
Some(other_child) => other_child.delete_child(),
}
}
}
pub fn revoke(&mut self) {
match self.child() {
None => {}
Some(_c) => {}
}
}
}