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<()> {
1414 use std::os::unix::ffi::OsStrExt;
1515 let path = std::ffi::CString::new(path.as_os_str().as_bytes())?;
1616 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.
1819 #[cfg(any(target_os = "macos", target_os = "ios"))]
1920 for signal in [
2021 libc::SIGSEGV,
......@@ -22,6 +23,7 @@ pub(super) fn prepare(path: &Path) -> std::io::Result<()> {
2223 libc::SIGILL,
2324 libc::SIGFPE,
2425 libc::SIGABRT,
26 libc::SIGTRAP,
2527 ] {
2628 let mut action: libc::sigaction = unsafe { std::mem::zeroed() };
2729 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) {
119121extern "C" fn fatal(signal: i32, info: *mut libc::siginfo_t, _: *mut libc::c_void) {
120122 unsafe {
121123 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);
122126 libc::raise(signal);
123127 }
124128}
crates/crash-report/tests/native.rs+20-6
......@@ -26,6 +26,10 @@ fn crash_child() {
2626 crash_report::conceal("AI.one");
2727 let _ = std::panic::catch_unwind(|| panic!("Cannot read section AI"));
2828 }
29 #[cfg(target_vendor = "apple")]
30 if std::env::var_os("SNOWBOUND_TEST_TRAP").is_some() {
31 unsafe { libc::raise(libc::SIGTRAP) };
32 }
2933 std::process::abort();
3034}
3135
......@@ -36,10 +40,13 @@ fn fatal_signals_leave_a_report_and_preserve_the_first_panic() {
3640 process::{Command, Stdio},
3741 };
3842 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 });
4350 let mut child = Command::new(std::env::current_exe().unwrap());
4451 child
4552 .args(["--exact", "crash_child", "--nocapture"])
......@@ -49,7 +56,11 @@ fn fatal_signals_leave_a_report_and_preserve_the_first_panic() {
4956 if panic {
5057 child.env("SNOWBOUND_TEST_PANIC", "1");
5158 }
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));
5364 let saved = std::fs::read_to_string(report).unwrap();
5465 assert!(
5566 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() {
6273 );
6374 assert!(!saved.contains("Native signal"), "{saved}");
6475 } else {
65 assert!(saved.contains("Native signal:"), "{saved}");
76 assert!(
77 saved.contains(&format!("Native signal: 0x{signal:016x}\n")),
78 "{saved}"
79 );
6680 assert!(!saved.contains("Fault address:"), "{saved}");
6781 }
6882 }