Skip to content

Commit

Permalink
chore: stop using static mut (#11088)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes authored Sep 21, 2024
1 parent f141a74 commit c36b2f7
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions crates/cli/util/src/sigsegv_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,14 @@ macro_rules! raw_errln {
/// Signal handler installed for SIGSEGV
extern "C" fn print_stack_trace(_: libc::c_int) {
const MAX_FRAMES: usize = 256;
// Reserve data segment so we don't have to malloc in a signal handler, which might fail
// in incredibly undesirable and unexpected ways due to e.g. the allocator deadlocking
static mut STACK_TRACE: [*mut libc::c_void; MAX_FRAMES] = [ptr::null_mut(); MAX_FRAMES];
#[allow(static_mut_refs)]
// TODO: remove static mut; this will become a hard error in edition 2024
let mut stack_trace: [*mut libc::c_void; MAX_FRAMES] = [ptr::null_mut(); MAX_FRAMES];
let stack = unsafe {
// Collect return addresses
let depth = libc::backtrace(STACK_TRACE.as_mut_ptr(), MAX_FRAMES as i32);
let depth = libc::backtrace(stack_trace.as_mut_ptr(), MAX_FRAMES as i32);
if depth == 0 {
return
}
&STACK_TRACE.as_slice()[0..(depth as _)]
&stack_trace[0..depth as usize]
};

// Just a stack trace is cryptic. Explain what we're doing.
Expand Down

0 comments on commit c36b2f7

Please sign in to comment.