Files
k-os/crates/adapter-riscv/src/boot/caps.rs
Gabriel Kaszewski d43421e33e feat(kernel): object lifetimes via slot generations
- SlotGenerations per table, never wraps, retires exhausted slots
- caps to dead/reused process, endpoint, region rejected
- endpoints owned, die w/ owner, waiters woken w/ error
- DropCap syscall + libkos wrapper
- irq table bounds-checked, routes dropped w/ thread
- self-kill terminates caller, exit_thread full cleanup
- sched run_now: switch to named thread, not queue head
- lifetime tests, fuzz kills/recreates, kani gen proofs
2026-10-26 19:54:23 +01:00

108 lines
3.1 KiB
Rust

use crate::hw::uart::Uart;
use types::id::ProcessId;
fn kern() -> &'static mut kernel::Kernel<crate::platform::RiscVPlatform> {
unsafe { &mut *crate::kernel_ptr() }
}
pub fn grant_all(
uart: &Uart,
init_pid: ProcessId,
storage_pid: ProcessId,
display_pid: ProcessId,
input_pid: ProcessId,
) {
let all_perms = types::permission::PermissionSet::empty()
.with(types::permission::Permission::Read)
.with(types::permission::Permission::Write)
.with(types::permission::Permission::Execute)
.with(types::permission::Permission::Delegate);
let ipc_perms = types::permission::PermissionSet::empty()
.with(types::permission::Permission::Read)
.with(types::permission::Permission::Execute);
let storage_ep = kern()
.create_endpoint(storage_pid)
.unwrap_or_else(|_| crate::halt(uart, "storage endpoint failed"));
kern()
.grant_capability(
init_pid,
domain::resource::Resource::Process(storage_pid),
all_perms,
)
.unwrap_or_else(|_| crate::halt(uart, "grant failed"));
kern()
.grant_capability(
init_pid,
domain::resource::Resource::Endpoint(storage_ep),
all_perms,
)
.unwrap_or_else(|_| crate::halt(uart, "grant failed"));
kern()
.grant_capability(
storage_pid,
domain::resource::Resource::Endpoint(storage_ep),
ipc_perms,
)
.unwrap_or_else(|_| crate::halt(uart, "grant failed"));
let display_ep = kern()
.create_endpoint(display_pid)
.unwrap_or_else(|_| crate::halt(uart, "display endpoint failed"));
kern()
.grant_capability(
display_pid,
domain::resource::Resource::Endpoint(display_ep),
ipc_perms,
)
.unwrap_or_else(|_| crate::halt(uart, "grant failed"));
kern()
.grant_capability(
init_pid,
domain::resource::Resource::Endpoint(display_ep),
all_perms,
)
.unwrap_or_else(|_| crate::halt(uart, "grant failed"));
kern()
.grant_capability(
init_pid,
domain::resource::Resource::Process(display_pid),
all_perms,
)
.unwrap_or_else(|_| crate::halt(uart, "grant failed"));
let input_ep = kern()
.create_endpoint(input_pid)
.unwrap_or_else(|_| crate::halt(uart, "input endpoint failed"));
kern()
.grant_capability(
input_pid,
domain::resource::Resource::Endpoint(input_ep),
ipc_perms,
)
.unwrap_or_else(|_| crate::halt(uart, "grant failed"));
kern()
.grant_capability(
init_pid,
domain::resource::Resource::Endpoint(input_ep),
all_perms,
)
.unwrap_or_else(|_| crate::halt(uart, "grant failed"));
kern()
.grant_capability(
init_pid,
domain::resource::Resource::Process(input_pid),
all_perms,
)
.unwrap_or_else(|_| crate::halt(uart, "grant failed"));
uart.write_str("k-os: capabilities granted\n");
}