From e1bd8312dba87f90a2198102b41add2a393be13a Mon Sep 17 00:00:00 2001 From: Wedson Almeida Filho Date: Thu, 19 Aug 2021 17:29:56 +0100 Subject: [PATCH] rust: report information about a panic. At the moment we get a mangled call stack. This prints the panic message and source location. Moving the panic handler do the `kernel` crate allows us to use `pr_emerg` to print the panic info. Signed-off-by: Wedson Almeida Filho --- rust/compiler_builtins.rs | 11 ----------- rust/kernel/lib.rs | 11 +++++++++++ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/rust/compiler_builtins.rs b/rust/compiler_builtins.rs index cb4bbf7be4e313..6a2fbdb3061824 100644 --- a/rust/compiler_builtins.rs +++ b/rust/compiler_builtins.rs @@ -133,14 +133,3 @@ define_panicking_intrinsics!("`u64` division/modulo should not be used", { __aeabi_uldivmod, __mulodi4, }); - -extern "C" { - fn rust_helper_BUG() -> !; -} - -#[panic_handler] -fn panic(_info: &core::panic::PanicInfo<'_>) -> ! { - unsafe { - rust_helper_BUG(); - } -} diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs index 226af02dc825a8..b538d6209fed94 100644 --- a/rust/kernel/lib.rs +++ b/rust/kernel/lib.rs @@ -226,3 +226,14 @@ macro_rules! container_of { ptr.wrapping_offset(-offset) as *const $type }} } + +#[cfg(not(any(testlib, test)))] +#[panic_handler] +fn panic(info: &core::panic::PanicInfo<'_>) -> ! { + extern "C" { + fn rust_helper_BUG() -> !; + } + pr_emerg!("{}\n", info); + // SAFETY: FFI call. + unsafe { rust_helper_BUG() }; +}