| author | |
| committer | |
| log | d87e4bf1bd81de7fc0966d3dff01bc3784a51d10 |
| tree | 18e5f827706f01ae33f11602b83662f50f59cdec |
| parent | 20174448f624d39ffedda6ad2291f07b96542644 |
| signature | Signed by SSH key SHA256:52mNGHRsVFBDED9IAX5pe+LRWUefqTbxEReunq21QvU |
A Swift runtime failure (a force unwrap of nil, an index out of range) traps
as SIGTRAP, which the macOS and iOS handler did not catch, so the iPhone app
saved no report for any crash in its UIKit code. The handler now takes
SIGTRAP too. It also resets the signal to its default before raising it
again: SA_RESETHAND leaves SIGILL and SIGTRAP caught, so the raise came
straight back to the handler and the process spun instead of ending, which
the extended native test showed.
- A crash in the iPhone app's interface now leaves a report to send on the next launch.
Assisted-by: claude-opus-5.52 files changed, 25 insertions(+), 7 deletions(-)
crates/crash-report/src/native.rs+5-1| ... | ... | @@ -14,7 +14,8 @@ pub(super) fn prepare(path: &Path) -> std::io::Result<()> { |
| 14 | 14 | use std::os::unix::ffi::OsStrExt; |
| 15 | 15 | let path = std::ffi::CString::new(path.as_os_str().as_bytes())?; |
| 16 | 16 | let _ = PATH.set(path); |
| 17 | // Linux forwards its existing signal handler, preserving its symbolized log. | |
| 17 | // Linux forwards its existing signal handler, preserving its symbolized log. A Swift | |
| 18 | // runtime failure (a force unwrap of nil, an index out of range) traps as SIGTRAP. | |
| 18 | 19 | #[cfg(any(target_os = "macos", target_os = "ios"))] |
| 19 | 20 | for signal in [ |
| 20 | 21 | libc::SIGSEGV, |
| ... | ... | @@ -22,6 +23,7 @@ pub(super) fn prepare(path: &Path) -> std::io::Result<()> { |
| 22 | 23 | libc::SIGILL, |
| 23 | 24 | libc::SIGFPE, |
| 24 | 25 | libc::SIGABRT, |
| 26 | libc::SIGTRAP, | |
| 25 | 27 | ] { |
| 26 | 28 | let mut action: libc::sigaction = unsafe { std::mem::zeroed() }; |
| 27 | 29 | action.sa_sigaction = fatal as *const () as libc::sighandler_t; |
| ... | ... | @@ -119,6 +121,8 @@ pub unsafe fn record_signal(signal: i32, info: *const libc::siginfo_t) { |
| 119 | 121 | extern "C" fn fatal(signal: i32, info: *mut libc::siginfo_t, _: *mut libc::c_void) { |
| 120 | 122 | unsafe { |
| 121 | 123 | record_signal(signal, info); |
| 124 | // SA_RESETHAND leaves SIGILL and SIGTRAP caught, which would come straight back here. | |
| 125 | libc::signal(signal, libc::SIG_DFL); | |
| 122 | 126 | libc::raise(signal); |
| 123 | 127 | } |
| 124 | 128 | } |
crates/crash-report/tests/native.rs+20-6| ... | ... | @@ -26,6 +26,10 @@ fn crash_child() { |
| 26 | 26 | crash_report::conceal("AI.one"); |
| 27 | 27 | let _ = std::panic::catch_unwind(|| panic!("Cannot read section AI")); |
| 28 | 28 | } |
| 29 | #[cfg(target_vendor = "apple")] | |
| 30 | if std::env::var_os("SNOWBOUND_TEST_TRAP").is_some() { | |
| 31 | unsafe { libc::raise(libc::SIGTRAP) }; | |
| 32 | } | |
| 29 | 33 | std::process::abort(); |
| 30 | 34 | } |
| 31 | 35 | |
| ... | ... | @@ -36,10 +40,13 @@ fn fatal_signals_leave_a_report_and_preserve_the_first_panic() { |
| 36 | 40 | process::{Command, Stdio}, |
| 37 | 41 | }; |
| 38 | 42 | let folder = tempfile::tempdir().unwrap(); |
| 39 | for panic in [false, true] { | |
| 40 | let report = folder | |
| 41 | .path() | |
| 42 | .join(if panic { "panic.txt" } else { "native.txt" }); | |
| 43 | let trap = cfg!(target_vendor = "apple"); | |
| 44 | for (panic, trap) in [(false, false), (true, false), (false, trap)] { | |
| 45 | let report = folder.path().join(match (panic, trap) { | |
| 46 | (true, _) => "panic.txt", | |
| 47 | (_, true) => "trap.txt", | |
| 48 | _ => "native.txt", | |
| 49 | }); | |
| 43 | 50 | let mut child = Command::new(std::env::current_exe().unwrap()); |
| 44 | 51 | child |
| 45 | 52 | .args(["--exact", "crash_child", "--nocapture"]) |
| ... | ... | @@ -49,7 +56,11 @@ fn fatal_signals_leave_a_report_and_preserve_the_first_panic() { |
| 49 | 56 | if panic { |
| 50 | 57 | child.env("SNOWBOUND_TEST_PANIC", "1"); |
| 51 | 58 | } |
| 52 | assert_eq!(child.status().unwrap().signal(), Some(libc::SIGABRT)); | |
| 59 | if trap { | |
| 60 | child.env("SNOWBOUND_TEST_TRAP", "1"); | |
| 61 | } | |
| 62 | let signal = if trap { libc::SIGTRAP } else { libc::SIGABRT }; | |
| 63 | assert_eq!(child.status().unwrap().signal(), Some(signal)); | |
| 53 | 64 | let saved = std::fs::read_to_string(report).unwrap(); |
| 54 | 65 | assert!( |
| 55 | 66 | saved.starts_with("Snowbound test, native-test\nSystem: test system\n"), |
| ... | ... | @@ -62,7 +73,10 @@ fn fatal_signals_leave_a_report_and_preserve_the_first_panic() { |
| 62 | 73 | ); |
| 63 | 74 | assert!(!saved.contains("Native signal"), "{saved}"); |
| 64 | 75 | } else { |
| 65 | assert!(saved.contains("Native signal:"), "{saved}"); | |
| 76 | assert!( | |
| 77 | saved.contains(&format!("Native signal: 0x{signal:016x}\n")), | |
| 78 | "{saved}" | |
| 79 | ); | |
| 66 | 80 | assert!(!saved.contains("Fault address:"), "{saved}"); |
| 67 | 81 | } |
| 68 | 82 | } |