authoravatarclover caruso<git@paperclover.net>2026-10-16 13:44:10-07:00
committeravatarclover caruso<git@paperclover.net>2026-10-19 11:25:14-07:00
logd87e4bf1bd81de7fc0966d3dff01bc3784a51d10
tree18e5f827706f01ae33f11602b83662f50f59cdec
parent20174448f624d39ffedda6ad2291f07b96542644
signature Signed by SSH key SHA256:52mNGHRsVFBDED9IAX5pe+LRWUefqTbxEReunq21QvU

fix(crash-report): keep reports of Swift traps on Apple platforms

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.5

2 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,7 +14,8 @@ pub(super) fn prepare(path: &Path) -> std::io::Result<()> {
14 use std::os::unix::ffi::OsStrExt;14 use std::os::unix::ffi::OsStrExt;
15 let path = std::ffi::CString::new(path.as_os_str().as_bytes())?;15 let path = std::ffi::CString::new(path.as_os_str().as_bytes())?;
16 let _ = PATH.set(path);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 #[cfg(any(target_os = "macos", target_os = "ios"))]19 #[cfg(any(target_os = "macos", target_os = "ios"))]
19 for signal in [20 for signal in [
20 libc::SIGSEGV,21 libc::SIGSEGV,
...@@ -22,6 +23,7 @@ pub(super) fn prepare(path: &Path) -> std::io::Result<()> {...@@ -22,6 +23,7 @@ pub(super) fn prepare(path: &Path) -> std::io::Result<()> {
22 libc::SIGILL,23 libc::SIGILL,
23 libc::SIGFPE,24 libc::SIGFPE,
24 libc::SIGABRT,25 libc::SIGABRT,
26 libc::SIGTRAP,
25 ] {27 ] {
26 let mut action: libc::sigaction = unsafe { std::mem::zeroed() };28 let mut action: libc::sigaction = unsafe { std::mem::zeroed() };
27 action.sa_sigaction = fatal as *const () as libc::sighandler_t;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,6 +121,8 @@ pub unsafe fn record_signal(signal: i32, info: *const libc::siginfo_t) {
119extern "C" fn fatal(signal: i32, info: *mut libc::siginfo_t, _: *mut libc::c_void) {121extern "C" fn fatal(signal: i32, info: *mut libc::siginfo_t, _: *mut libc::c_void) {
120 unsafe {122 unsafe {
121 record_signal(signal, info);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 libc::raise(signal);126 libc::raise(signal);
123 }127 }
124}128}
crates/crash-report/tests/native.rs+20-6
...@@ -26,6 +26,10 @@ fn crash_child() {...@@ -26,6 +26,10 @@ fn crash_child() {
26 crash_report::conceal("AI.one");26 crash_report::conceal("AI.one");
27 let _ = std::panic::catch_unwind(|| panic!("Cannot read section AI"));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 std::process::abort();33 std::process::abort();
30}34}
3135
...@@ -36,10 +40,13 @@ fn fatal_signals_leave_a_report_and_preserve_the_first_panic() {...@@ -36,10 +40,13 @@ fn fatal_signals_leave_a_report_and_preserve_the_first_panic() {
36 process::{Command, Stdio},40 process::{Command, Stdio},
37 };41 };
38 let folder = tempfile::tempdir().unwrap();42 let folder = tempfile::tempdir().unwrap();
39 for panic in [false, true] {43 let trap = cfg!(target_vendor = "apple");
40 let report = folder44 for (panic, trap) in [(false, false), (true, false), (false, trap)] {
41 .path()45 let report = folder.path().join(match (panic, trap) {
42 .join(if panic { "panic.txt" } else { "native.txt" });46 (true, _) => "panic.txt",
47 (_, true) => "trap.txt",
48 _ => "native.txt",
49 });
43 let mut child = Command::new(std::env::current_exe().unwrap());50 let mut child = Command::new(std::env::current_exe().unwrap());
44 child51 child
45 .args(["--exact", "crash_child", "--nocapture"])52 .args(["--exact", "crash_child", "--nocapture"])
...@@ -49,7 +56,11 @@ fn fatal_signals_leave_a_report_and_preserve_the_first_panic() {...@@ -49,7 +56,11 @@ fn fatal_signals_leave_a_report_and_preserve_the_first_panic() {
49 if panic {56 if panic {
50 child.env("SNOWBOUND_TEST_PANIC", "1");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 let saved = std::fs::read_to_string(report).unwrap();64 let saved = std::fs::read_to_string(report).unwrap();
54 assert!(65 assert!(
55 saved.starts_with("Snowbound test, native-test\nSystem: test system\n"),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,7 +73,10 @@ fn fatal_signals_leave_a_report_and_preserve_the_first_panic() {
62 );73 );
63 assert!(!saved.contains("Native signal"), "{saved}");74 assert!(!saved.contains("Native signal"), "{saved}");
64 } else {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 assert!(!saved.contains("Fault address:"), "{saved}");80 assert!(!saved.contains("Fault address:"), "{saved}");
67 }81 }
68 }82 }