Skip to content

Commit

Permalink
Auto merge of #2008 - bsteinb:macos-aarch64-mcontext, r=JohnTitor
Browse files Browse the repository at this point in the history
Make test suite pass on macOS on aarch64

While working on #2007 I tried to run `cargo test` in `libc-test`, which failed, because the definition of `__darwin_mcontext64` was incomplete (see #1990). This adds definitions for the exception state and the floating point state as well.

`libc-test` still does not pass, because I use the type `[u128; 32]` for the `__v` field of `__darwin_arm_neon_state64` (in C it is `__uint128_t __v[32]`. `ctest2` does not translate `u128` to `__uint128_t` and the generated C code does not compile. Any ideas for working around this?
  • Loading branch information
bors committed Jan 5, 2021
2 parents a98a649 + ee84dae commit 2ec333c
Show file tree
Hide file tree
Showing 10 changed files with 191 additions and 130 deletions.
3 changes: 3 additions & 0 deletions libc-test/build.rs
Expand Up @@ -199,6 +199,8 @@ fn test_apple(target: &str) {
"SF_SETTABLE" => true,
// FIXME: the value has been changed since Catalina (VM_FLAGS_RESILIENT_MEDIA is also contained now).
"VM_FLAGS_USER_REMAP" => true,
// FIXME: the values have been changed since Big Sur
"HW_TARGET" | "HW_PRODUCT" | "HW_MAXID" => true,
_ => false,
}
});
Expand All @@ -220,6 +222,7 @@ fn test_apple(target: &str) {
match (struct_, field) {
// FIXME: the array size has been changed since macOS 10.15 ([8] -> [7]).
("statfs", "f_reserved") => true,
("__darwin_arm_neon_state64", "__v") => true,
_ => false,
}
});
Expand Down
17 changes: 0 additions & 17 deletions src/unix/bsd/apple/b64/aarch64.rs

This file was deleted.

48 changes: 48 additions & 0 deletions src/unix/bsd/apple/b64/aarch64/align.rs
@@ -0,0 +1,48 @@
pub type mcontext_t = *mut __darwin_mcontext64;

s_no_extra_traits! {
#[allow(missing_debug_implementations)]
pub struct max_align_t {
priv_: f64
}
}

s! {
pub struct ucontext_t {
pub uc_onstack: ::c_int,
pub uc_sigmask: ::sigset_t,
pub uc_stack: ::stack_t,
pub uc_link: *mut ::ucontext_t,
pub uc_mcsize: usize,
pub uc_mcontext: mcontext_t,
}

pub struct __darwin_mcontext64 {
pub __es: __darwin_arm_exception_state64,
pub __ss: __darwin_arm_thread_state64,
pub __ns: __darwin_arm_neon_state64,
}

pub struct __darwin_arm_exception_state64 {
pub __far: u64,
pub __esr: u32,
pub __exception: u32,
}

pub struct __darwin_arm_thread_state64 {
pub __x: [u64; 29],
pub __fp: u64,
pub __lr: u64,
pub __sp: u64,
pub __pc: u64,
pub __cpsr: u32,
pub __pad: u32,
}

#[repr(align(16))]
pub struct __darwin_arm_neon_state64 {
pub __v: [[u64; 2]; 32],
pub __fpsr: u32,
pub __fpcr: u32,
}
}
8 changes: 8 additions & 0 deletions src/unix/bsd/apple/b64/aarch64/mod.rs
@@ -0,0 +1,8 @@
pub type boolean_t = ::c_int;

cfg_if! {
if #[cfg(libc_align)] {
mod align;
pub use self::align::*;
}
}
80 changes: 0 additions & 80 deletions src/unix/bsd/apple/b64/mod.rs
Expand Up @@ -2,8 +2,6 @@

pub type c_long = i64;
pub type c_ulong = u64;
pub type boolean_t = ::c_uint;
pub type mcontext_t = *mut __darwin_mcontext64;

s! {
pub struct timeval32 {
Expand Down Expand Up @@ -49,77 +47,6 @@ s! {
pub bh_datalen: u32,
pub bh_hdrlen: ::c_ushort,
}

pub struct ucontext_t {
pub uc_onstack: ::c_int,
pub uc_sigmask: ::sigset_t,
pub uc_stack: ::stack_t,
pub uc_link: *mut ::ucontext_t,
pub uc_mcsize: usize,
pub uc_mcontext: mcontext_t,
}

pub struct __darwin_x86_exception_state64 {
pub __trapno: u16,
pub __cpu: u16,
pub __err: u32,
pub __faultvaddr: u64,
}

pub struct __darwin_x86_float_state64 {
pub __fpu_reserved: [::c_int; 2],
__fpu_fcw: ::c_short,
__fpu_fsw: ::c_short,
pub __fpu_ftw: u8,
pub __fpu_rsrv1: u8,
pub __fpu_fop: u16,
pub __fpu_ip: u32,
pub __fpu_cs: u16,
pub __fpu_rsrv2: u16,
pub __fpu_dp: u32,
pub __fpu_ds: u16,
pub __fpu_rsrv3: u16,
pub __fpu_mxcsr: u32,
pub __fpu_mxcsrmask: u32,
pub __fpu_stmm0: __darwin_mmst_reg,
pub __fpu_stmm1: __darwin_mmst_reg,
pub __fpu_stmm2: __darwin_mmst_reg,
pub __fpu_stmm3: __darwin_mmst_reg,
pub __fpu_stmm4: __darwin_mmst_reg,
pub __fpu_stmm5: __darwin_mmst_reg,
pub __fpu_stmm6: __darwin_mmst_reg,
pub __fpu_stmm7: __darwin_mmst_reg,
pub __fpu_xmm0: __darwin_xmm_reg,
pub __fpu_xmm1: __darwin_xmm_reg,
pub __fpu_xmm2: __darwin_xmm_reg,
pub __fpu_xmm3: __darwin_xmm_reg,
pub __fpu_xmm4: __darwin_xmm_reg,
pub __fpu_xmm5: __darwin_xmm_reg,
pub __fpu_xmm6: __darwin_xmm_reg,
pub __fpu_xmm7: __darwin_xmm_reg,
pub __fpu_xmm8: __darwin_xmm_reg,
pub __fpu_xmm9: __darwin_xmm_reg,
pub __fpu_xmm10: __darwin_xmm_reg,
pub __fpu_xmm11: __darwin_xmm_reg,
pub __fpu_xmm12: __darwin_xmm_reg,
pub __fpu_xmm13: __darwin_xmm_reg,
pub __fpu_xmm14: __darwin_xmm_reg,
pub __fpu_xmm15: __darwin_xmm_reg,
// this field is actually [u8; 96], but defining it with a bigger type
// allows us to auto-implement traits for it since the length of the
// array is less than 32
__fpu_rsrv4: [u32; 24],
pub __fpu_reserved1: ::c_int,
}

pub struct __darwin_mmst_reg {
pub __mmst_reg: [::c_char; 10],
pub __mmst_rsrv: [::c_char; 6],
}

pub struct __darwin_xmm_reg {
pub __xmm_reg: [::c_char; 16],
}
}

s_no_extra_traits! {
Expand Down Expand Up @@ -184,13 +111,6 @@ extern "C" {
) -> ::c_int;
}

cfg_if! {
if #[cfg(libc_align)] {
mod align;
pub use self::align::*;
}
}

cfg_if! {
if #[cfg(target_arch = "x86_64")] {
mod x86_64;
Expand Down
31 changes: 0 additions & 31 deletions src/unix/bsd/apple/b64/x86_64.rs

This file was deleted.

7 changes: 7 additions & 0 deletions src/unix/bsd/apple/b64/x86_64/align.rs
@@ -0,0 +1,7 @@
s_no_extra_traits! {
#[allow(missing_debug_implementations)]
#[repr(align(16))]
pub struct max_align_t {
priv_: [f64; 2]
}
}
112 changes: 112 additions & 0 deletions src/unix/bsd/apple/b64/x86_64/mod.rs
@@ -0,0 +1,112 @@
pub type boolean_t = ::c_uint;
pub type mcontext_t = *mut __darwin_mcontext64;

s! {
pub struct ucontext_t {
pub uc_onstack: ::c_int,
pub uc_sigmask: ::sigset_t,
pub uc_stack: ::stack_t,
pub uc_link: *mut ::ucontext_t,
pub uc_mcsize: usize,
pub uc_mcontext: mcontext_t,
}

pub struct __darwin_mcontext64 {
pub __es: __darwin_x86_exception_state64,
pub __ss: __darwin_x86_thread_state64,
pub __fs: __darwin_x86_float_state64,
}

pub struct __darwin_x86_exception_state64 {
pub __trapno: u16,
pub __cpu: u16,
pub __err: u32,
pub __faultvaddr: u64,
}

pub struct __darwin_x86_thread_state64 {
pub __rax: u64,
pub __rbx: u64,
pub __rcx: u64,
pub __rdx: u64,
pub __rdi: u64,
pub __rsi: u64,
pub __rbp: u64,
pub __rsp: u64,
pub __r8: u64,
pub __r9: u64,
pub __r10: u64,
pub __r11: u64,
pub __r12: u64,
pub __r13: u64,
pub __r14: u64,
pub __r15: u64,
pub __rip: u64,
pub __rflags: u64,
pub __cs: u64,
pub __fs: u64,
pub __gs: u64,
}

pub struct __darwin_x86_float_state64 {
pub __fpu_reserved: [::c_int; 2],
__fpu_fcw: ::c_short,
__fpu_fsw: ::c_short,
pub __fpu_ftw: u8,
pub __fpu_rsrv1: u8,
pub __fpu_fop: u16,
pub __fpu_ip: u32,
pub __fpu_cs: u16,
pub __fpu_rsrv2: u16,
pub __fpu_dp: u32,
pub __fpu_ds: u16,
pub __fpu_rsrv3: u16,
pub __fpu_mxcsr: u32,
pub __fpu_mxcsrmask: u32,
pub __fpu_stmm0: __darwin_mmst_reg,
pub __fpu_stmm1: __darwin_mmst_reg,
pub __fpu_stmm2: __darwin_mmst_reg,
pub __fpu_stmm3: __darwin_mmst_reg,
pub __fpu_stmm4: __darwin_mmst_reg,
pub __fpu_stmm5: __darwin_mmst_reg,
pub __fpu_stmm6: __darwin_mmst_reg,
pub __fpu_stmm7: __darwin_mmst_reg,
pub __fpu_xmm0: __darwin_xmm_reg,
pub __fpu_xmm1: __darwin_xmm_reg,
pub __fpu_xmm2: __darwin_xmm_reg,
pub __fpu_xmm3: __darwin_xmm_reg,
pub __fpu_xmm4: __darwin_xmm_reg,
pub __fpu_xmm5: __darwin_xmm_reg,
pub __fpu_xmm6: __darwin_xmm_reg,
pub __fpu_xmm7: __darwin_xmm_reg,
pub __fpu_xmm8: __darwin_xmm_reg,
pub __fpu_xmm9: __darwin_xmm_reg,
pub __fpu_xmm10: __darwin_xmm_reg,
pub __fpu_xmm11: __darwin_xmm_reg,
pub __fpu_xmm12: __darwin_xmm_reg,
pub __fpu_xmm13: __darwin_xmm_reg,
pub __fpu_xmm14: __darwin_xmm_reg,
pub __fpu_xmm15: __darwin_xmm_reg,
// this field is actually [u8; 96], but defining it with a bigger type
// allows us to auto-implement traits for it since the length of the
// array is less than 32
__fpu_rsrv4: [u32; 24],
pub __fpu_reserved1: ::c_int,
}

pub struct __darwin_mmst_reg {
pub __mmst_reg: [::c_char; 10],
pub __mmst_rsrv: [::c_char; 6],
}

pub struct __darwin_xmm_reg {
pub __xmm_reg: [::c_char; 16],
}
}

cfg_if! {
if #[cfg(libc_align)] {
mod align;
pub use self::align::*;
}
}
10 changes: 9 additions & 1 deletion src/unix/bsd/apple/mod.rs
Expand Up @@ -1907,6 +1907,9 @@ pub const PTHREAD_PROCESS_PRIVATE: ::c_int = 2;
pub const PTHREAD_PROCESS_SHARED: ::c_int = 1;
pub const PTHREAD_CREATE_JOINABLE: ::c_int = 1;
pub const PTHREAD_CREATE_DETACHED: ::c_int = 2;
#[cfg(target_arch = "aarch64")]
pub const PTHREAD_STACK_MIN: ::size_t = 16384;
#[cfg(not(target_arch = "aarch64"))]
pub const PTHREAD_STACK_MIN: ::size_t = 8192;

pub const RLIMIT_CPU: ::c_int = 0;
Expand Down Expand Up @@ -2843,7 +2846,9 @@ pub const HW_L3CACHESIZE: ::c_int = 22;
pub const HW_TB_FREQ: ::c_int = 23;
pub const HW_MEMSIZE: ::c_int = 24;
pub const HW_AVAILCPU: ::c_int = 25;
pub const HW_MAXID: ::c_int = 26;
pub const HW_TARGET: ::c_int = 26;
pub const HW_PRODUCT: ::c_int = 27;
pub const HW_MAXID: ::c_int = 28;
pub const USER_CS_PATH: ::c_int = 1;
pub const USER_BC_BASE_MAX: ::c_int = 2;
pub const USER_BC_DIM_MAX: ::c_int = 3;
Expand Down Expand Up @@ -3129,6 +3134,9 @@ pub const SETALL: ::c_int = 9;
// sys/shm.h
pub const SHM_RDONLY: ::c_int = 0x1000;
pub const SHM_RND: ::c_int = 0x2000;
#[cfg(target_arch = "aarch64")]
pub const SHMLBA: ::c_int = 16 * 1024;
#[cfg(not(target_arch = "aarch64"))]
pub const SHMLBA: ::c_int = 4096;
pub const SHM_R: ::c_int = IPC_R;
pub const SHM_W: ::c_int = IPC_W;
Expand Down
5 changes: 4 additions & 1 deletion src/unix/bsd/mod.rs
Expand Up @@ -632,7 +632,10 @@ extern "C" {
egid: *mut ::gid_t,
) -> ::c_int;

#[cfg_attr(target_os = "macos", link_name = "glob$INODE64")]
#[cfg_attr(
all(target_os = "macos", not(target_arch = "aarch64")),
link_name = "glob$INODE64")
]
#[cfg_attr(target_os = "netbsd", link_name = "__glob30")]
#[cfg_attr(
all(target_os = "freebsd", any(freebsd11, freebsd10)),
Expand Down

0 comments on commit 2ec333c

Please sign in to comment.