Truly independent web browser
AK: Capture the backtrace of a Rust panic that will abort
Jelle Raaijmakerseceab62981d9
diff --git a/AK/Assertions.cpp b/AK/Assertions.cppindex d6bd0f8c480..f9631d54666 100644--- a/AK/Assertions.cpp+++ b/AK/Assertions.cpp@@ -90,6 +90,13 @@ char const* AK::current_rust_panic_message()void ladybird_rust_panic_will_abort(){+ // The panic hooks of the process's Rust crates chain into each other, and each of them that knows the panic is+ // fatal asks for the backtrace.+ static thread_local bool s_backtrace_captured;+ if (s_backtrace_captured)+ return;+ s_backtrace_captured = true;+if (__atomic_load_n(&s_rust_is_panicking, __ATOMIC_ACQUIRE)) {if (auto callback = __atomic_load_n(&s_assertion_failure_callback, __ATOMIC_ACQUIRE))callback(AK::AssertionFailureKind::RustPanic, s_rust_panic_message.data());diff --git a/Libraries/RustPanic.rs b/Libraries/RustPanic.rsindex 4fe9e347c38..9b3f76e9fb5 100644--- a/Libraries/RustPanic.rs+++ b/Libraries/RustPanic.rs@@ -52,6 +52,12 @@ pub(crate) extern "C" fn initialize() {is_panicking,);}+ // Nothing can catch this panic, so no later code gets to capture the backtrace.+ #[cfg(panic = "abort")]+ // SAFETY: The bridge only reads the message stored above.+ unsafe {+ ladybird_rust_panic_will_abort();+ }previous(info);}));});