Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix posix-signals-on-macos on aarch64-apple-darwin #6793

Merged
merged 1 commit into from
Aug 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions crates/runtime/src/traphandlers/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,21 @@ unsafe extern "C" fn trap_handler(
}
}

// FIXME(rust-lang/libc#3312) the currenty definition of `ucontext_t` in the
// `libc` crate is incorrect on aarch64-apple-drawin so it's defined here with a
// more accurate definition. When that PR and/or issue is resolved then this
// should no longer be necessary.
#[repr(C)]
#[cfg(all(target_arch = "aarch64", target_os = "macos"))]
struct ucontext_t {
uc_onstack: libc::c_int,
uc_sigmask: libc::sigset_t,
uc_stack: libc::stack_t,
uc_link: *mut libc::ucontext_t,
uc_mcsize: usize,
uc_mcontext: libc::mcontext_t,
}

unsafe fn get_pc_and_fp(cx: *mut libc::c_void, _signum: libc::c_int) -> (*const u8, usize) {
cfg_if::cfg_if! {
if #[cfg(all(target_os = "linux", target_arch = "x86_64"))] {
Expand Down Expand Up @@ -214,7 +229,7 @@ unsafe fn get_pc_and_fp(cx: *mut libc::c_void, _signum: libc::c_int) -> (*const
(*cx.uc_mcontext).__ss.__rbp as usize,
)
} else if #[cfg(all(target_os = "macos", target_arch = "aarch64"))] {
let cx = &*(cx as *const libc::ucontext_t);
let cx = &*(cx as *const ucontext_t);
(
(*cx.uc_mcontext).__ss.__pc as *const u8,
(*cx.uc_mcontext).__ss.__fp as usize,
Expand Down Expand Up @@ -270,7 +285,7 @@ unsafe fn set_pc(cx: *mut libc::c_void, pc: usize, arg1: usize) {
(*cx.uc_mcontext).__ss.__rsp -= 8;
}
} else if #[cfg(target_arch = "aarch64")] {
let cx = &mut *(cx as *mut libc::ucontext_t);
let cx = &mut *(cx as *mut ucontext_t);
(*cx.uc_mcontext).__ss.__pc = pc as u64;
(*cx.uc_mcontext).__ss.__x[0] = arg1 as u64;
} else {
Expand Down