|
5 | 5 | // ignore-sgx no libc
|
6 | 6 | // ignore-emscripten no processes
|
7 | 7 | // ignore-sgx no processes
|
8 |
| -// ignore-android: FIXME(#85261) |
9 | 8 | // ignore-fuchsia no fork
|
10 | 9 |
|
11 | 10 | #![feature(rustc_private)]
|
@@ -79,7 +78,49 @@ unsafe impl<A:GlobalAlloc> GlobalAlloc for PidChecking<A> {
|
79 | 78 | fn expect_aborted(status: ExitStatus) {
|
80 | 79 | dbg!(status);
|
81 | 80 | let signal = status.signal().expect("expected child process to die of signal");
|
| 81 | + |
| 82 | + #[cfg(not(target_os = "android"))] |
82 | 83 | assert!(signal == libc::SIGABRT || signal == libc::SIGILL || signal == libc::SIGTRAP);
|
| 84 | + |
| 85 | + #[cfg(target_os = "android")] |
| 86 | + { |
| 87 | + // Android signals an abort() call with SIGSEGV at address 0xdeadbaad |
| 88 | + // See e.g. https://groups.google.com/g/android-ndk/c/laW1CJc7Icc |
| 89 | + assert!(signal == libc::SIGSEGV); |
| 90 | + |
| 91 | + // Additional checks performed: |
| 92 | + // 1. Find last tombstone (similar to coredump but in text format) from the |
| 93 | + // same executable (path) as we are (must be because of usage of fork): |
| 94 | + // This ensures that we look into the correct tombstone. |
| 95 | + // 2. Cause of crash is a SIGSEGV with address 0xdeadbaad. |
| 96 | + // 3. libc::abort call is in one of top two functions on callstack. |
| 97 | + // The last two steps distinguish between a normal SIGSEGV and one caused |
| 98 | + // by libc::abort. |
| 99 | + |
| 100 | + let this_exe = std::env::current_exe().unwrap().into_os_string().into_string().unwrap(); |
| 101 | + let exe_string = format!(">>> {this_exe} <<<"); |
| 102 | + let tombstone = (0..100) |
| 103 | + .map(|n| format!("/data/tombstones/tombstone_{n:02}")) |
| 104 | + .filter(|f| std::path::Path::new(&f).exists()) |
| 105 | + .map(|f| std::fs::read_to_string(&f).expect("Cannot read tombstone file")) |
| 106 | + .filter(|f| f.contains(&exe_string)) |
| 107 | + .last() |
| 108 | + .expect("no tombstone found"); |
| 109 | + |
| 110 | + println!("Content of tombstone:\n{tombstone}"); |
| 111 | + |
| 112 | + assert!( |
| 113 | + tombstone.contains("signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr deadbaad") |
| 114 | + ); |
| 115 | + let abort_on_top = tombstone |
| 116 | + .lines() |
| 117 | + .skip_while(|l| !l.contains("backtrace:")) |
| 118 | + .skip(1) |
| 119 | + .take_while(|l| l.starts_with(" #")) |
| 120 | + .take(2) |
| 121 | + .any(|f| f.contains("/system/lib/libc.so (abort")); |
| 122 | + assert!(abort_on_top); |
| 123 | + } |
83 | 124 | }
|
84 | 125 |
|
85 | 126 | fn main() {
|
|
0 commit comments