Amend nasty design decisions

This commit is contained in:
August 2026-11-09 19:56:42 +00:00
parent 0ae51c120f
commit c84d3ae273
Signed by: shibedrill
SSH Key Fingerprint: SHA256:M0m3JW1s38BgO2t0fG146Yxd9OJ2IOqkvCAsuRHQ6Pw
2 changed files with 23 additions and 52 deletions

View File

@ -2,6 +2,7 @@
"rust-analyzer.cargo.target": "x86_64-unknown-none",
"rust-analyzer.check.allTargets": false,
"nixEnvPicker.terminalActivateCommand": "nix-shell",
"nixEnvSelector.nixFile": "${workspaceFolder}/shell.nix",
"nixEnvSelector.useFlakes": false,
"nixEnvSelector.nixFile": "${workspaceFolder}/flake.nix",
"nixEnvSelector.useFlakes": true,
"nixEnvSelector.flakeShell": "default",
}

View File

@ -1,57 +1,27 @@
#![allow(dead_code)]
use core::pin;
#[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
resource: ResourceIdentifier<'a>, // Can point to a capability of any type
child: pin::Pin<&'a mut Capability<'a>>, // Derived capability, 1 byte
parent: pin::Pin<&'a mut Capability<'a>>, // Parent capability, 1 byte
}
#[repr(u32)]
pub enum ResourceIdentifier<'a> {
CapabilityBlock(pin::Pin<&'a mut CapabilityBlock<'a>>),
Page(PageCap),
Channel(u64),
Untyped(u64),
Null,
}
pub struct PageCap {
addr: u64,
}
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) => {}
}
}
caps: [Capability<'a>; 128],
}