Skip to content

Commit 8581b59

Browse files
Disable mmap in libbacktrace on Apple platforms
Fixes #45731 libbacktrace uses mmap if available to map ranges of the files containing debug information. On macOS `mmap` will succeed even if the mapped range does not exist, and a SIGBUS (with an unusual EXC_BAD_ACCESS code 10) will occur when the program attempts to page in the memory. To combat this we force `libbacktrace` to be built with the simple `read` based fallback on Apple platforms.
1 parent e177df3 commit 8581b59

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

src/libbacktrace/configure

+6
Original file line numberDiff line numberDiff line change
@@ -12323,6 +12323,12 @@ fi
1232312323
1232412324
fi
1232512325
fi
12326+
12327+
case "${host_os}" in
12328+
darwin*)
12329+
have_mmap=no ;;
12330+
esac
12331+
1232612332
if test "$have_mmap" = "no"; then
1232712333
VIEW_FILE=read.lo
1232812334
ALLOC_FILE=alloc.lo

src/libbacktrace/configure.ac

+6
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,12 @@ else
283283
AC_CHECK_FUNC(mmap, [have_mmap=yes], [have_mmap=no])
284284
fi
285285
fi
286+
287+
case "${host_os}" in
288+
darwin*)
289+
have_mmap=no ;;
290+
esac
291+
286292
if test "$have_mmap" = "no"; then
287293
VIEW_FILE=read.lo
288294
ALLOC_FILE=alloc.lo

src/test/run-pass/issue-45731.rs

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// compile-flags:--test -g
12+
13+
use std::{env, panic, fs};
14+
15+
#[cfg(target_os = "macos")]
16+
#[test]
17+
fn simple_test() {
18+
// Find our dSYM and replace the DWARF binary with an empty file
19+
let mut dsym_path = env::current_exe().unwrap();
20+
let executable_name = dsym_path.file_name().unwrap().to_str().unwrap().to_string();
21+
assert!(dsym_path.pop()); // Pop executable
22+
dsym_path.push(format!("{}.dSYM/Contents/Resources/DWARF/{0}", executable_name));
23+
{
24+
let file = fs::OpenOptions::new().read(false).write(true).truncate(true).create(false)
25+
.open(&dsym_path).unwrap();
26+
}
27+
28+
env::set_var("RUST_BACKTRACE", "1");
29+
30+
// We don't need to die of panic, just trigger a backtrace
31+
let _ = panic::catch_unwind(|| {
32+
assert!(false);
33+
});
34+
}

0 commit comments

Comments
 (0)