feat: add Halt syscall, fault notification to fault handler, supervisor with back-off, shutdown with timeout

- Halt syscall: only pid 0 (init) can halt, adapter uses SBI SRST
- Fault notification: kernel delivers fault info to process fault handler endpoint before killing
- Supervisor: tracks restart counts, back-off up to 5 restarts
- Shutdown: notifies servers, waits with timeout, calls halt
- Trap handler: faults now call kernel.handle_fault instead of halting
This commit is contained in:
2026-10-18 03:29:05 +02:00
parent a83b53d962
commit b7bc223a79
13 changed files with 232 additions and 6 deletions

View File

@@ -126,4 +126,17 @@ impl Platform for RiscVPlatform {
),
});
}
fn halt(&self) -> ! {
unsafe {
core::arch::asm!(
"ecall",
in("a0") 0usize,
in("a1") 0usize,
in("a7") 0x53525354usize,
in("a6") 0usize,
);
}
loop { unsafe { core::arch::asm!("wfi") }; }
}
}

View File

@@ -161,6 +161,7 @@ fn decode_syscall(frame: &TrapFrame) -> Option<domain::syscall::Syscall> {
match nr {
SYS_EXIT => Some(Syscall::Exit),
SYS_HALT => Some(Syscall::Halt),
SYS_EXIT_THREAD => Some(Syscall::ExitThread),
SYS_YIELD => Some(Syscall::Yield),
SYS_GET_TIME => Some(Syscall::GetTime),
@@ -408,7 +409,21 @@ fn handle_exception(frame: &mut TrapFrame, scause: usize) {
uart.write_str(" sepc=");
uart.write_hex(frame.sepc);
uart.put_char(b'\n');
loop { unsafe { core::arch::asm!("wfi") }; }
let kern = crate::kernel_ref();
if let Some(current_tid) = kern.current_thread() {
let fault = match scause {
2 => domain::fault::Fault::IllegalInstruction,
5 | 7 | 13 | 15 => domain::fault::Fault::MemoryFault {
address: types::address::VirtualAddress::from_raw(stval),
},
_ => domain::fault::Fault::InvalidSyscall,
};
kern.handle_fault(current_tid, fault, frame.sepc);
switch_to_next(frame, current_tid);
} else {
loop { unsafe { core::arch::asm!("wfi") }; }
}
}
}
}