From 8fd082e6e6337cb6e480d7235c25d89f50bebc0e Mon Sep 17 00:00:00 2001 From: chrysn Date: Fri, 8 Mar 2024 17:28:28 +0100 Subject: [PATCH 1/2] thread/name: Avoid calling C function known to return 0 --- src/thread/riot_c.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/thread/riot_c.rs b/src/thread/riot_c.rs index 4a93e5cb..0d116476 100644 --- a/src/thread/riot_c.rs +++ b/src/thread/riot_c.rs @@ -106,6 +106,11 @@ impl KernelPID { } pub fn get_name(&self) -> Option<&str> { + // Shortcut through an otherwise unoptimizable function + if !cfg!(riot_develhelp) { + return None; + } + let ptr = unsafe { raw::thread_getname(self.0) }; // If the thread stops, the name might be not valid any more, but then again the getname From f22819223ca28e5f470f23638e3ffe4341de01f9 Mon Sep 17 00:00:00 2001 From: chrysn Date: Fri, 8 Mar 2024 17:37:42 +0100 Subject: [PATCH 2/2] panic: Crash sooner with panic_handler_crash 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. --- src/panic.rs | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/src/panic.rs b/src/panic.rs index 41e33547..688d5da3 100644 --- a/src/panic.rs +++ b/src/panic.rs @@ -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 @@ -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 {