Record and expose how every process ends (M17.2)
The kernel records an ExitReason at all three death sites — clean exit, fault (classified by vector), and process_kill — into a bounded ring before the exit notification posts, so a supervisor's query never races the notice. process_exit_reason is gated by the same supervisor check as kill; runtime.process.exitReason is the stable interface. This is the input restart policy reads (docs/process-lifecycle.md iron rule 2).
This commit is contained in:
@@ -412,13 +412,26 @@ fn recoverableFault(vector: u64) bool {
|
||||
/// plus a POST code and a persistent breadcrumb. (A ring-3 fault on a *borrowed*
|
||||
/// kernel thread — process.run, the user-pf isolation probe — also lands here: there
|
||||
/// is no scheduled process to kill.)
|
||||
/// Classify a CPU exception vector as the ExitReason a supervisor reads — the
|
||||
/// fault classes of docs/process-lifecycle.md. Faults are exit reasons, never
|
||||
/// signals delivered to the faulting process: recovery is restart, not a handler.
|
||||
fn exitReasonForVector(vector: u64) abi.ExitReason {
|
||||
return switch (vector) {
|
||||
14 => .segmentation_fault, // page fault
|
||||
6 => .illegal_instruction, // invalid opcode
|
||||
0, 16, 19 => .arithmetic_fault, // divide error, x87, SIMD
|
||||
13 => .protection_fault, // general protection
|
||||
else => .fault,
|
||||
};
|
||||
}
|
||||
|
||||
fn onException(state: *const architecture.CpuState) noreturn {
|
||||
if (architecture.fromUser(state) and scheduler.currentIsUserProcess() and recoverableFault(state.vector)) {
|
||||
statusPrint("\ndanos: process {d} ({s}) killed by {s} (vector {d}) on core {d}\n", .{ scheduler.currentId(), scheduler.current().name(), architecture.exceptionName(state.vector), state.vector, scheduler.currentCpuIndex() });
|
||||
statusPrint(" error code : 0x{x}\n", .{state.error_code});
|
||||
statusPrint(" IP : 0x{x:0>16}\n", .{architecture.instructionPointer(state)});
|
||||
if (architecture.faultAddress(state)) |address| statusPrint(" fault addr : 0x{x:0>16}\n", .{address});
|
||||
process.killCurrentProcess(); // reclaims everything, reschedules; never returns
|
||||
process.killCurrentProcess(exitReasonForVector(state.vector)); // reclaims everything, reschedules; never returns
|
||||
}
|
||||
|
||||
log.checkpoint(cp_exception);
|
||||
|
||||
Reference in New Issue
Block a user