Skip to content

Commit

Permalink
panic: Crash sooner with panic_handler_crash
Browse files Browse the repository at this point in the history
With the feature panic_handler_crash, a panic would previously have
tried to print details (depending on other features) before calling the
RIOT panic. This feature's purpose is to shut down everything ASAP, so
instead it now also bypasses these prints, allowing the compiler to also
remove the check for whether an interrupt is active.
  • Loading branch information
chrysn committed Mar 8, 2024
1 parent cae6482 commit e1359d4
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions src/panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
fn panic(info: &::core::panic::PanicInfo) -> ! {
use crate::thread;

let os_can_continue = crate::thread::InThread::new()
// Panics with IRQs off are fatal because we can't safely re-enable them
.map(|i| i.irq_is_enabled())
// Panics in ISRs are always fatal because continuing in threads would signal to the
// remaining system that the ISR terminated
.unwrap_or(false);
let os_can_continue = !cfg!(feature = "panic_handler_crash")
&& crate::thread::InThread::new()
// Panics with IRQs off are fatal because we can't safely re-enable them
.map(|i| i.irq_is_enabled())
// Panics in ISRs are always fatal because continuing in threads would signal to the
// remaining system that the ISR terminated
.unwrap_or(false);

if !os_can_continue {
// We can't abort on stable -- but even if we could: Set a breakpoint and wait for the
Expand Down Expand Up @@ -49,15 +50,6 @@ fn panic(info: &::core::panic::PanicInfo) -> ! {
let _ = stdio.write_str("!\n");
}

if cfg!(feature = "panic_handler_crash") {
unsafe {
riot_sys::core_panic(
riot_sys::core_panic_t_PANIC_GENERAL_ERROR,
cstr::cstr!("RUST PANIC").as_ptr() as _,
)
}
}

// Not trying any unwinding -- this thread is just dead, won't be re-claimed, any mutexes it
// holds are just held indefinitely rather than throwing poison errors.
loop {
Expand Down

0 comments on commit e1359d4

Please sign in to comment.