Skip to content

Commit 3b8d029

Browse files
committed
rust: panic: Call into arch panic handler
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]>
1 parent 70586be commit 3b8d029

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

main.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,12 @@ int main(void)
1616
return 0;
1717
}
1818

19+
/* On most arches, panic is entirely macros resulting in some kind of inline assembly. Create this
20+
* wrapper so the Rust panic handler can call the same kind of panic.
21+
*/
22+
void rust_panic_wrap(void)
23+
{
24+
k_panic();
25+
}
26+
1927
#endif

zephyr/src/lib.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,13 @@ fn panic(info :&PanicInfo) -> ! {
3333
printkln!("panic: {}", info);
3434
}
3535
let _ = info;
36-
loop {
36+
37+
// Call into the wrapper for the system panic function.
38+
unsafe {
39+
extern "C" {
40+
fn rust_panic_wrap() -> !;
41+
}
42+
rust_panic_wrap();
3743
}
3844
}
3945

0 commit comments

Comments
 (0)