Skip to content

Commit

Permalink
rust: panic: Call into arch panic handler
Browse files Browse the repository at this point in the history
When the panic happens, call into the Zephyr `k_panic()` handler instead
of just spinning.  This should halt the whole system, not just the
current thread.

Signed-off-by: David Brown <[email protected]>
  • Loading branch information
d3zd3z committed Sep 10, 2024
1 parent 8587d26 commit f8d9823
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
8 changes: 8 additions & 0 deletions lib/rust/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,12 @@ int main(void)
return 0;
}

/* On most arches, panic is entirely macros resulting in some kind of inline assembly. Create this
* wrapper so the Rust panic handler can call the same kind of panic.
*/
void rust_panic_wrap(void)
{
k_panic();
}

#endif
8 changes: 7 additions & 1 deletion lib/rust/zephyr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ fn panic(info :&PanicInfo) -> ! {
printkln!("panic: {}", info);
}
let _ = info;
loop {

// Call into the wrapper for the system panic function.
unsafe {
extern "C" {
fn rust_panic_wrap() -> !;
}
rust_panic_wrap();
}
}

Expand Down

0 comments on commit f8d9823

Please sign in to comment.