Amend nasty design decisions
This commit is contained in:
parent
0ae51c120f
commit
c84d3ae273
5
.vscode/settings.json
vendored
5
.vscode/settings.json
vendored
@ -2,6 +2,7 @@
|
|||||||
"rust-analyzer.cargo.target": "x86_64-unknown-none",
|
"rust-analyzer.cargo.target": "x86_64-unknown-none",
|
||||||
"rust-analyzer.check.allTargets": false,
|
"rust-analyzer.check.allTargets": false,
|
||||||
"nixEnvPicker.terminalActivateCommand": "nix-shell",
|
"nixEnvPicker.terminalActivateCommand": "nix-shell",
|
||||||
"nixEnvSelector.nixFile": "${workspaceFolder}/shell.nix",
|
"nixEnvSelector.nixFile": "${workspaceFolder}/flake.nix",
|
||||||
"nixEnvSelector.useFlakes": false,
|
"nixEnvSelector.useFlakes": true,
|
||||||
|
"nixEnvSelector.flakeShell": "default",
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,57 +1,27 @@
|
|||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
|
|
||||||
|
use core::pin;
|
||||||
|
|
||||||
#[repr(C, packed)]
|
#[repr(C, packed)]
|
||||||
pub struct Capability<'a> {
|
pub struct Capability<'a> {
|
||||||
component: u16, // Issuing component ID, 0.25 bytes
|
resource: ResourceIdentifier<'a>, // Can point to a capability of any type
|
||||||
resource: u16, // Resource type, 0.25 bytes
|
child: pin::Pin<&'a mut Capability<'a>>, // Derived capability, 1 byte
|
||||||
instance: u64, // Instance ID, 1 byte
|
parent: pin::Pin<&'a mut Capability<'a>>, // Parent capability, 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
|
#[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> {
|
pub struct CapabilityBlock<'a> {
|
||||||
caps: [Capability<'a>; 1024],
|
caps: [Capability<'a>; 128],
|
||||||
}
|
}
|
||||||
|
|
||||||
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) => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user