Skip to content

Commit e911c44

Browse files
committed
apple: Port mcontext and ucontext to the new layout
This includes `signal.h` stubs since that is a common header to import these types.
1 parent eab4196 commit e911c44

File tree

16 files changed

+283
-140
lines changed

16 files changed

+283
-140
lines changed

src/new/apple/apple_libc/signal.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//! Header: `signal.h`
2+
//!
3+
//! https://github.com/apple-oss-distributions/Libc/blob/main/include/signal.h
4+
5+
pub use crate::sys::signal::*;

src/new/apple/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//! Entrypoint for Apple headers, usually found as part of the xcode SDK.
2+
3+
pub(crate) mod xnu;
4+
pub(crate) use xnu::*;
5+
6+
pub(crate) mod apple_libc {
7+
pub(crate) mod signal;
8+
}
9+
10+
pub(crate) use apple_libc::*;

src/new/apple/xnu/arm/_mcontext.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//! Header: `arm/_mcontext.h`
2+
//!
3+
//! https://github.com/apple-oss-distributions/xnu/blob/main/bsd/arm/_mcontext.h
4+
5+
pub use crate::mach::machine::_structs::*;
6+
7+
s! {
8+
pub struct __darwin_mcontext64 {
9+
pub __es: __darwin_arm_exception_state64,
10+
pub __ss: __darwin_arm_thread_state64,
11+
pub __ns: __darwin_arm_neon_state64,
12+
}
13+
}
14+
15+
pub type mcontext_t = *mut __darwin_mcontext64;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//! Header: `i386/_mcontext.h`
2+
//!
3+
//! https://github.com/apple-oss-distributions/xnu/blob/main/bsd/i386/_mcontext.h
4+
5+
pub use crate::mach::machine::_structs::*;
6+
7+
s! {
8+
pub struct __darwin_mcontext64 {
9+
pub __es: __darwin_x86_exception_state64,
10+
pub __ss: __darwin_x86_thread_state64,
11+
pub __fs: __darwin_x86_float_state64,
12+
}
13+
}
14+
15+
pub type mcontext_t = *mut __darwin_mcontext64;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//! Header: `arm/_structs.h`
2+
//!
3+
//! https://github.com/apple-oss-distributions/xnu/blob/main/osfmk/mach/arm/_structs.h
4+
5+
#[cfg(target_arch = "arm")]
6+
use crate::prelude::*;
7+
8+
s! {
9+
pub struct __darwin_arm_exception_state64 {
10+
pub __far: u64,
11+
pub __esr: u32,
12+
pub __exception: u32,
13+
}
14+
15+
pub struct __darwin_arm_thread_state64 {
16+
pub __x: [u64; 29],
17+
pub __fp: u64,
18+
pub __lr: u64,
19+
pub __sp: u64,
20+
pub __pc: u64,
21+
pub __cpsr: u32,
22+
pub __pad: u32,
23+
}
24+
25+
#[cfg(target_arch = "aarch64")]
26+
pub struct __darwin_arm_neon_state64 {
27+
pub __v: [crate::__uint128_t; 32],
28+
pub __fpsr: u32,
29+
pub __fpcr: u32,
30+
}
31+
32+
#[cfg(target_arch = "arm")]
33+
#[repr(align(16))]
34+
pub struct __darwin_arm_neon_state64 {
35+
opaque: [c_char; (32 * 16) + (2 * size_of::<u32>())],
36+
}
37+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
use crate::prelude::*;
2+
3+
s! {
4+
pub struct __darwin_mmst_reg {
5+
pub __mmst_reg: [c_char; 10],
6+
pub __mmst_rsrv: [c_char; 6],
7+
}
8+
9+
pub struct __darwin_xmm_reg {
10+
pub __xmm_reg: [c_char; 16],
11+
}
12+
13+
pub struct __darwin_x86_thread_state64 {
14+
pub __rax: u64,
15+
pub __rbx: u64,
16+
pub __rcx: u64,
17+
pub __rdx: u64,
18+
pub __rdi: u64,
19+
pub __rsi: u64,
20+
pub __rbp: u64,
21+
pub __rsp: u64,
22+
pub __r8: u64,
23+
pub __r9: u64,
24+
pub __r10: u64,
25+
pub __r11: u64,
26+
pub __r12: u64,
27+
pub __r13: u64,
28+
pub __r14: u64,
29+
pub __r15: u64,
30+
pub __rip: u64,
31+
pub __rflags: u64,
32+
pub __cs: u64,
33+
pub __fs: u64,
34+
pub __gs: u64,
35+
}
36+
37+
pub struct __darwin_x86_exception_state64 {
38+
pub __trapno: u16,
39+
pub __cpu: u16,
40+
pub __err: u32,
41+
pub __faultvaddr: u64,
42+
}
43+
44+
pub struct __darwin_x86_float_state64 {
45+
pub __fpu_reserved: [c_int; 2],
46+
__fpu_fcw: c_short,
47+
__fpu_fsw: c_short,
48+
pub __fpu_ftw: u8,
49+
pub __fpu_rsrv1: u8,
50+
pub __fpu_fop: u16,
51+
pub __fpu_ip: u32,
52+
pub __fpu_cs: u16,
53+
pub __fpu_rsrv2: u16,
54+
pub __fpu_dp: u32,
55+
pub __fpu_ds: u16,
56+
pub __fpu_rsrv3: u16,
57+
pub __fpu_mxcsr: u32,
58+
pub __fpu_mxcsrmask: u32,
59+
pub __fpu_stmm0: __darwin_mmst_reg,
60+
pub __fpu_stmm1: __darwin_mmst_reg,
61+
pub __fpu_stmm2: __darwin_mmst_reg,
62+
pub __fpu_stmm3: __darwin_mmst_reg,
63+
pub __fpu_stmm4: __darwin_mmst_reg,
64+
pub __fpu_stmm5: __darwin_mmst_reg,
65+
pub __fpu_stmm6: __darwin_mmst_reg,
66+
pub __fpu_stmm7: __darwin_mmst_reg,
67+
pub __fpu_xmm0: __darwin_xmm_reg,
68+
pub __fpu_xmm1: __darwin_xmm_reg,
69+
pub __fpu_xmm2: __darwin_xmm_reg,
70+
pub __fpu_xmm3: __darwin_xmm_reg,
71+
pub __fpu_xmm4: __darwin_xmm_reg,
72+
pub __fpu_xmm5: __darwin_xmm_reg,
73+
pub __fpu_xmm6: __darwin_xmm_reg,
74+
pub __fpu_xmm7: __darwin_xmm_reg,
75+
pub __fpu_xmm8: __darwin_xmm_reg,
76+
pub __fpu_xmm9: __darwin_xmm_reg,
77+
pub __fpu_xmm10: __darwin_xmm_reg,
78+
pub __fpu_xmm11: __darwin_xmm_reg,
79+
pub __fpu_xmm12: __darwin_xmm_reg,
80+
pub __fpu_xmm13: __darwin_xmm_reg,
81+
pub __fpu_xmm14: __darwin_xmm_reg,
82+
pub __fpu_xmm15: __darwin_xmm_reg,
83+
// this field is actually [u8; 96], but defining it with a bigger type
84+
// allows us to auto-implement traits for it since the length of the
85+
// array is less than 32
86+
__fpu_rsrv4: [u32; 24],
87+
pub __fpu_reserved1: c_int,
88+
}
89+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//! Header: `mach/machine/_structs.h`
2+
3+
cfg_if! {
4+
if #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] {
5+
pub use crate::mach::i386::_structs::*;
6+
} else if #[cfg(any(target_arch = "arm", target_arch = "aarch64"))] {
7+
pub use crate::mach::arm::_structs::*;
8+
} else {
9+
// Unsupported arch
10+
}
11+
}

src/new/apple/xnu/mach/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
2+
pub(crate) mod arm {
3+
pub(crate) mod _structs;
4+
}
5+
6+
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
7+
pub(crate) mod i386 {
8+
pub(crate) mod _structs;
9+
}
10+
11+
pub(crate) mod machine {
12+
pub(crate) mod _structs;
13+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//! Header: `machine/_mcontext.h`
2+
3+
cfg_if! {
4+
if #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] {
5+
pub use crate::i386::_mcontext::*;
6+
} else if #[cfg(any(target_arch = "arm", target_arch = "aarch64"))] {
7+
pub use crate::arm::_mcontext::*;
8+
} else {
9+
// Unsupported arch
10+
}
11+
}

src/new/apple/xnu/mod.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//! Source from XNU <https://github.com/apple-oss-distributions/xnu/tree/main>
2+
//!
3+
//! We omit nesting for the `bsd` module since most items of interest are in there.
4+
5+
/// Directory: `arm/`
6+
///
7+
/// https://github.com/apple-oss-distributions/xnu/tree/main/bsd/arm
8+
#[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
9+
pub(crate) mod arm {
10+
pub(crate) mod _mcontext;
11+
}
12+
13+
/// Directory: `i386/`
14+
///
15+
/// https://github.com/apple-oss-distributions/xnu/tree/main/bsd/i386
16+
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
17+
pub(crate) mod i386 {
18+
pub(crate) mod _mcontext;
19+
}
20+
21+
pub(crate) mod mach;
22+
23+
/// Directory: `machine/`
24+
///
25+
/// https://github.com/apple-oss-distributions/xnu/tree/main/bsd/machine
26+
pub(crate) mod machine {
27+
pub(crate) mod _mcontext;
28+
}
29+
30+
pub(crate) mod sys;

0 commit comments

Comments
 (0)