Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions src/new/apple/apple_libc/signal.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//! Header: `signal.h`
//!
//! https://github.com/apple-oss-distributions/Libc/blob/main/include/signal.h

pub use crate::sys::signal::*;
10 changes: 10 additions & 0 deletions src/new/apple/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//! Entrypoint for Apple headers, usually found as part of the Xcode SDK.

pub(crate) mod xnu;
pub(crate) use xnu::*;

pub(crate) mod apple_libc {
pub(crate) mod signal;
}

pub(crate) use apple_libc::*;
15 changes: 15 additions & 0 deletions src/new/apple/xnu/arm/_mcontext.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//! Header: `arm/_mcontext.h`
//!
//! https://github.com/apple-oss-distributions/xnu/blob/main/bsd/arm/_mcontext.h

pub use crate::mach::machine::_structs::*;

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

pub type mcontext_t = *mut __darwin_mcontext64;
15 changes: 15 additions & 0 deletions src/new/apple/xnu/i386/_mcontext.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//! Header: `i386/_mcontext.h`
//!
//! https://github.com/apple-oss-distributions/xnu/blob/main/bsd/i386/_mcontext.h

pub use crate::mach::machine::_structs::*;

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

pub type mcontext_t = *mut __darwin_mcontext64;
37 changes: 37 additions & 0 deletions src/new/apple/xnu/mach/arm/_structs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//! Header: `arm/_structs.h`
//!
//! https://github.com/apple-oss-distributions/xnu/blob/main/osfmk/mach/arm/_structs.h

#[cfg(target_arch = "arm")]
use crate::prelude::*;

s! {
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,
}

#[cfg(target_arch = "aarch64")]
pub struct __darwin_arm_neon_state64 {
pub __v: [crate::__uint128_t; 32],
pub __fpsr: u32,
pub __fpcr: u32,
}

#[cfg(target_arch = "arm")]
#[repr(align(16))]
pub struct __darwin_arm_neon_state64 {
opaque: [c_char; (32 * 16) + (2 * size_of::<u32>())],
}
}
92 changes: 92 additions & 0 deletions src/new/apple/xnu/mach/i386/_structs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
//! Header: `i386/_structs.h`
//!
//! https://github.com/apple-oss-distributions/xnu/blob/main/osfmk/mach/i386/_structs.h

use crate::prelude::*;

s! {
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],
}

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_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,
// FIXME(apple): 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,
}
}
13 changes: 13 additions & 0 deletions src/new/apple/xnu/mach/machine/_structs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//! Header: `mach/machine/_structs.h`
//!
//! https://github.com/apple-oss-distributions/xnu/blob/main/osfmk/mach/machine/_structs.h

cfg_if! {
if #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] {
pub use crate::mach::i386::_structs::*;
} else if #[cfg(any(target_arch = "arm", target_arch = "aarch64"))] {
pub use crate::mach::arm::_structs::*;
} else {
// Unsupported arch
}
}
20 changes: 20 additions & 0 deletions src/new/apple/xnu/mach/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//! Directory: `mach/`
//!
//! https://github.com/apple-oss-distributions/xnu/tree/main/osfmk/mach

/// Directory: `mach/arm`
#[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
pub(crate) mod arm {
pub(crate) mod _structs;
}

/// Directory: `mach/i386`
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
pub(crate) mod i386 {
pub(crate) mod _structs;
}

/// Directory: `mach/machine`
pub(crate) mod machine {
pub(crate) mod _structs;
}
11 changes: 11 additions & 0 deletions src/new/apple/xnu/machine/_mcontext.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//! Header: `machine/_mcontext.h`

cfg_if! {
if #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] {
pub use crate::i386::_mcontext::*;
} else if #[cfg(any(target_arch = "arm", target_arch = "aarch64"))] {
pub use crate::arm::_mcontext::*;
} else {
// Unsupported arch
}
}
30 changes: 30 additions & 0 deletions src/new/apple/xnu/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//! Source from XNU <https://github.com/apple-oss-distributions/xnu/tree/main>
//!
//! We omit nesting for the `bsd` module since most items of interest are in there.

/// Directory: `arm/`
///
/// https://github.com/apple-oss-distributions/xnu/tree/main/bsd/arm
#[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
pub(crate) mod arm {
pub(crate) mod _mcontext;
}

/// Directory: `i386/`
///
/// https://github.com/apple-oss-distributions/xnu/tree/main/bsd/i386
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
pub(crate) mod i386 {
pub(crate) mod _mcontext;
}

pub(crate) mod mach;

/// Directory: `machine/`
///
/// https://github.com/apple-oss-distributions/xnu/tree/main/bsd/machine
pub(crate) mod machine {
pub(crate) mod _mcontext;
}

pub(crate) mod sys;
17 changes: 17 additions & 0 deletions src/new/apple/xnu/sys/_types/_ucontext.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//! Header: `sys/_types/_ucontext.h`

pub use crate::machine::_mcontext::*;
use crate::prelude::*;

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

pub type ucontext_t = __darwin_ucontext;
12 changes: 12 additions & 0 deletions src/new/apple/xnu/sys/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//! Directory: `sys/`
//!
//! https://github.com/apple-oss-distributions/xnu/tree/main/bsd/sys

pub(crate) mod signal;

/// Directory: `sys/_types`
///
/// https://github.com/apple-oss-distributions/xnu/tree/main/bsd/sys/_types
pub(crate) mod _types {
pub(crate) mod _ucontext;
}
6 changes: 6 additions & 0 deletions src/new/apple/xnu/sys/signal.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//! Header: `sys/signal.h`
//!
//! https://github.com/apple-oss-distributions/xnu/blob/main/bsd/sys/signal.h

pub use crate::machine::_mcontext::*;
pub use crate::sys::_types::_ucontext::*;
14 changes: 14 additions & 0 deletions src/new/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
//!
//! Eventually everything should be moved over, and we will move this directory to the top
//! level in `src`.
//!
//! # Basic structure
//!
//! Each child module here represents a library or group of libraries that we are binding. Each of
//! these has several submodules, representing either a directory or a header file in that library.
//!
//! `#include`s turn into `pub use ...*;` statements. Then at the root level (here), we choose
//! which top-level headers we want to reexport the definitions for.
//!
//! All modules are only crate-public since we don't reexport this structure.

cfg_if! {
if #[cfg(target_os = "linux")] {
Expand All @@ -11,5 +21,9 @@ cfg_if! {
} else if #[cfg(target_os = "android")] {
mod bionic;
pub use bionic::*;
} else if #[cfg(target_vendor = "apple")] {
mod apple;
pub(crate) use apple::*;
pub use signal::*;
}
}
38 changes: 0 additions & 38 deletions src/unix/bsd/apple/b64/aarch64/mod.rs
Original file line number Diff line number Diff line change
@@ -1,49 +1,11 @@
use crate::prelude::*;

pub type boolean_t = c_int;
pub type mcontext_t = *mut __darwin_mcontext64;

s! {
pub struct malloc_zone_t {
__private: [crate::uintptr_t; 18], // FIXME(macos): needs arm64 auth pointers support
}

pub struct ucontext_t {
pub uc_onstack: c_int,
pub uc_sigmask: crate::sigset_t,
pub uc_stack: crate::stack_t,
pub uc_link: *mut crate::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,
}

pub struct __darwin_arm_neon_state64 {
pub __v: [crate::__uint128_t; 32],
pub __fpsr: u32,
pub __fpcr: u32,
}
}

s_no_extra_traits! {
Expand Down
Loading