Files
k-os/crates/init/src/shutdown.rs

26 lines
947 B
Rust

use types::bounded::CapSlot;
const SHUTDOWN_TIMEOUT_TICKS: usize = 50_000_000;
const SHUTDOWN_SIGNAL: usize = 0xFFFF_FFFF;
/// Best-effort shutdown: notify all servers, wait briefly for them to flush, then halt.
///
/// Servers that receive the shutdown signal should flush state to storage and exit.
/// We can't block on individual acks because a crashed server would deadlock us.
/// Instead, we yield repeatedly until the timeout expires, giving servers time to finish.
pub fn shutdown(server_endpoints: &[CapSlot], endpoint_count: usize) -> ! {
for i in 0..endpoint_count {
let ep = server_endpoints[i].value() as usize;
userspace::syscall::send(ep, SHUTDOWN_SIGNAL, 0, 0, 0);
}
let start = userspace::syscall::get_time();
let deadline = start + SHUTDOWN_TIMEOUT_TICKS;
while userspace::syscall::get_time() < deadline {
userspace::syscall::yield_now();
}
userspace::syscall::halt();
}