Skip to content

Commit

Permalink
feat(vm) Simplify get_pc for aarch64-apple-darwin.
Browse files Browse the repository at this point in the history
Since libc 0.2.82, the issue
rust-lang/libc#1977 has been fixed with
rust-lang/libc#1990. Our current version of
libc is 0.2.87. Let's update our code to remove the
`__darwin_arm_thread_state64` type, and use the one from libc.
  • Loading branch information
Hywan committed Mar 5, 2021
1 parent cbfd873 commit c645352
Showing 1 changed file with 1 addition and 16 deletions.
17 changes: 1 addition & 16 deletions lib/vm/src/trap/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,23 +252,8 @@ cfg_if::cfg_if! {
let cx = &*(cx as *const libc::ucontext_t);
(*cx.uc_mcontext).__ss.__rip as *const u8
} else if #[cfg(all(target_os = "macos", target_arch = "aarch64"))] {
use std::mem;
// TODO: This should be integrated into rust/libc
// Related issue: https://github.com/rust-lang/libc/issues/1977
#[allow(non_camel_case_types)]
pub struct __darwin_arm_thread_state64 {
pub __x: [u64; 29], /* General purpose registers x0-x28 */
pub __fp: u64, /* Frame pointer x29 */
pub __lr: u64, /* Link register x30 */
pub __sp: u64, /* Stack pointer x31 */
pub __pc: u64, /* Program counter */
pub __cpsr: u32, /* Current program status register */
pub __pad: u32, /* Same size for 32-bit or 64-bit clients */
}

let cx = &*(cx as *const libc::ucontext_t);
let uc_mcontext = mem::transmute::<_, *const __darwin_arm_thread_state64>(&(*cx.uc_mcontext).__ss);
(*uc_mcontext).__pc as *const u8
(*cx.uc_mcontext).__ss.__pc as *const u8
} else if #[cfg(all(target_os = "freebsd", target_arch = "x86_64"))] {
let cx = &*(cx as *const libc::ucontext_t);
cx.uc_mcontext.mc_rip as *const u8
Expand Down

0 comments on commit c645352

Please sign in to comment.