Implement domain and endpoint modules with capability management, message passing, and scheduling features

This commit is contained in:
2026-10-17 23:09:21 +02:00
parent 667bc7f7f7
commit 06b51b6712
25 changed files with 1064 additions and 24 deletions

View File

@@ -0,0 +1,82 @@
use types::{bounded::CapSlot, generation::Generation, permission::PermissionSet};
pub mod authority;
use crate::{error::KernelError, resource::Resource};
#[cfg(test)]
#[path = "tests.rs"]
mod tests;
const MAX_CAPS_PER_PROCESS: usize = 16;
pub struct Capability {
resource: Resource,
permissions: PermissionSet,
generation: Generation,
}
impl Capability {
pub(crate) fn new(
resource: Resource,
permissions: PermissionSet,
generation: Generation,
) -> Self {
Self {
resource,
permissions,
generation,
}
}
pub fn resource(&self) -> &Resource {
&self.resource
}
pub fn permissions(&self) -> &PermissionSet {
&self.permissions
}
pub fn generation(&self) -> &Generation {
&self.generation
}
}
pub struct CapabilityTable {
slots: [Option<Capability>; MAX_CAPS_PER_PROCESS],
}
impl CapabilityTable {
pub fn new() -> Self {
Self {
slots: [const { None }; MAX_CAPS_PER_PROCESS],
}
}
pub fn get(&self, slot: CapSlot) -> Result<&Capability, KernelError> {
let idx = slot.value() as usize;
self.slots[idx]
.as_ref()
.ok_or(KernelError::InvalidSlot(slot))
}
pub fn insert(&mut self, cap: Capability) -> Result<CapSlot, KernelError> {
let idx = self
.slots
.iter()
.position(|s| s.is_none())
.ok_or(KernelError::NoFreeSlot)?;
self.slots[idx] = Some(cap);
CapSlot::new(idx as u8).ok_or(KernelError::NoFreeSlot)
}
pub fn remove(&mut self, slot: CapSlot) -> Result<(), KernelError> {
let idx = slot.value() as usize;
if self.slots[idx].is_none() {
return Err(KernelError::InvalidSlot(slot));
}
self.slots[idx] = None;
Ok(())
}
}