message: Move this code into whole functions so that we don't get errors on symbols that aren't defined in the crate on the wrong platform.
diff: @@ -76,6 +76,25 @@ cfg_if::cfg_if! {
  }
  }
  + #[cfg(target_os = "macos")]
  + unsafe fn thread_stack() -> (usize, usize) {
  + let this_thread = libc::pthread_self();
  + let stackaddr = libc::pthread_get_stackaddr_np(this_thread);
  + let stacksize = libc::pthread_get_stacksize_np(this_thread);
  + (stackaddr as usize, stacksize)
  + }
  +
  + #[cfg(not(target_os = "macos"))]
  + unsafe fn thread_stack() -> (usize, usize) {
  + let this_thread = libc::pthread_self();
  + let mut thread_attrs: libc::pthread_attr_t = mem::zeroed();
  + libc::pthread_getattr_np(this_thread, &mut thread_attrs);
  + let mut stackaddr: *mut libc::c_void = ptr::null_mut();
  + let mut stacksize: libc::size_t = 0;
  + libc::pthread_attr_getstack(&thread_attrs, &mut stackaddr, &mut stacksize);
  + (stackaddr as usize, stacksize)
  + }
  +
  unsafe extern "C" fn trap_handler(
  signum: libc::c_int,
  siginfo: *mut libc::siginfo_t,
  @@ -91,22 +110,8 @@ cfg_if::cfg_if! {
  // We try to get the Code trap associated to this signal
  let maybe_signal_trap = match signum {
  libc::SIGSEGV | libc::SIGBUS => {
  - let addr = (*siginfo).si_addr();
  - let this_thread = libc::pthread_self();
  - let (stackaddr, stacksize) = if cfg!(target_os = "macos") {
  - let stackaddr = libc::pthread_get_stackaddr_np(this_thread);
  - let stacksize = libc::pthread_get_stacksize_np(this_thread);
  - (stackaddr as usize, stacksize)
  - } else {
  - let mut thread_attrs: libc::pthread_attr_t = mem::zeroed();
  - libc::pthread_getattr_np(this_thread, &mut thread_attrs);
  - let mut stackaddr: *mut libc::c_void = ptr::null_mut();
  - let mut stacksize: libc::size_t = 0;
  - libc::pthread_attr_getstack(&thread_attrs, &mut stackaddr, &mut stacksize);
  - (stackaddr as usize, stacksize)
  - }
  - let addr = addr as usize;
  - let stackaddr = stackaddr as usize;
  + let addr = (*siginfo).si_addr() as usize;
  + let (stackaddr, stacksize) = thread_stack();
  // Assuming page size of 4KiB.
  if stackaddr - 4096 < addr && addr < stackaddr + stacksize {
  Some(TrapCode::StackOverflow)
  