Skip to content

Commit

Permalink
Use common si_addr() accessor
Browse files Browse the repository at this point in the history
Now that all of the UNIX-ish platforms in libc implement this function
to extract the si_addr from a siginfo_t, it can be used to simplify such
data collection during stack overflow handling.
  • Loading branch information
pfmooney committed Apr 4, 2022
1 parent e69e652 commit f9e8d05
Showing 1 changed file with 1 addition and 17 deletions.
18 changes: 1 addition & 17 deletions library/std/src/sys/unix/stack_overflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,6 @@ mod imp {
use crate::sys::unix::os::page_size;
use crate::sys_common::thread_info;

#[cfg(any(target_os = "linux", target_os = "android"))]
unsafe fn siginfo_si_addr(info: *mut libc::siginfo_t) -> usize {
#[repr(C)]
struct siginfo_t {
a: [libc::c_int; 3], // si_signo, si_errno, si_code
si_addr: *mut libc::c_void,
}

(*(info as *const siginfo_t)).si_addr as usize
}

#[cfg(not(any(target_os = "linux", target_os = "android")))]
unsafe fn siginfo_si_addr(info: *mut libc::siginfo_t) -> usize {
(*info).si_addr as usize
}

// Signal handler for the SIGSEGV and SIGBUS handlers. We've got guard pages
// (unmapped pages) at the end of every thread's stack, so if a thread ends
// up running into the guard page it'll trigger this handler. We want to
Expand Down Expand Up @@ -97,7 +81,7 @@ mod imp {
_data: *mut libc::c_void,
) {
let guard = thread_info::stack_guard().unwrap_or(0..0);
let addr = siginfo_si_addr(info);
let addr = (*info).si_addr() as usize;

// If the faulting address is within the guard page, then we print a
// message saying so and abort.
Expand Down

0 comments on commit f9e8d05

Please sign in to comment.