Skip to content

Commit 45d9482

Browse files
committed
Add mcontext_t/ucontext_t for FreeBSD (amd64 and aarch64)
1 parent d1dd244 commit 45d9482

File tree

6 files changed

+195
-0
lines changed

6 files changed

+195
-0
lines changed

src/unix/bsd/freebsdlike/freebsd/aarch64.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ pub type c_long = i64;
33
pub type c_ulong = u64;
44
pub type time_t = i64;
55
pub type suseconds_t = i64;
6+
pub type register_t = i64;
67

78
s! {
89
pub struct stat {
@@ -30,6 +31,35 @@ s! {
3031
}
3132
}
3233

34+
pub const _MC_FP_VALID: ::c_int = 0x1;
35+
36+
s! {
37+
pub struct gpregs {
38+
pub gp_x: [register_t; 30],
39+
pub gp_lr: register_t,
40+
pub gp_sp: register_t,
41+
pub gp_elr: register_t,
42+
pub gp_spsr: u32,
43+
pub gp_pad: ::c_int,
44+
}
45+
46+
pub struct fpregs {
47+
pub fp_q: [u128; 32],
48+
pub fp_sr: u32,
49+
pub fp_cr: u32,
50+
pub fp_flags: ::c_int,
51+
pub fp_pad: ::c_int,
52+
}
53+
54+
pub struct mcontext_t {
55+
pub mc_gpregs: gpregs,
56+
pub mc_fpregs: fpregs,
57+
pub mc_flags: ::c_int,
58+
pub mc_pad: ::c_int,
59+
pub mc_spare: [u64; 8],
60+
}
61+
}
62+
3363
// should be pub(crate), but that requires Rust 1.18.0
3464
cfg_if! {
3565
if #[cfg(libc_const_size_of)] {

src/unix/bsd/freebsdlike/freebsd/arm.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ pub type c_long = i32;
33
pub type c_ulong = u32;
44
pub type time_t = i64;
55
pub type suseconds_t = i32;
6+
pub type register_t = i32;
67

78
s! {
89
pub struct stat {

src/unix/bsd/freebsdlike/freebsd/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,17 @@ s_no_extra_traits! {
151151
__unused1: ::c_int,
152152
__unused2: [::c_long; 7]
153153
}
154+
155+
#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
156+
#[cfg_attr(feature = "extra_traits", derive(Debug))]
157+
pub struct ucontext_t {
158+
pub uc_sigmask: ::sigset_t,
159+
pub uc_mcontext: ::mcontext_t,
160+
pub uc_link: *mut ::ucontext_t,
161+
pub uc_stack: ::stack_t,
162+
pub uc_flags: ::c_int,
163+
__spare__: [::c_int; 4],
164+
}
154165
}
155166

156167
cfg_if! {

src/unix/bsd/freebsdlike/freebsd/powerpc64.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ pub type c_long = i64;
33
pub type c_ulong = u64;
44
pub type time_t = i64;
55
pub type suseconds_t = i64;
6+
pub type register_t = i64;
67

78
s! {
89
pub struct stat {

src/unix/bsd/freebsdlike/freebsd/x86.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ pub type c_long = i32;
33
pub type c_ulong = u32;
44
pub type time_t = i32;
55
pub type suseconds_t = i32;
6+
pub type register_t = i32;
67

78
s! {
89
pub struct stat {

src/unix/bsd/freebsdlike/freebsd/x86_64/mod.rs

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ pub type c_long = i64;
33
pub type c_ulong = u64;
44
pub type time_t = i64;
55
pub type suseconds_t = i64;
6+
pub type register_t = i64;
67

78
// should be pub(crate), but that requires Rust 1.18.0
89
cfg_if! {
@@ -22,3 +23,153 @@ cfg_if! {
2223
pub use self::align::*;
2324
}
2425
}
26+
27+
pub const _MC_HASSEGS: u32 = 0x1;
28+
pub const _MC_HASBASES: u32 = 0x2;
29+
pub const _MC_HASFPXSTATE: u32 = 0x4;
30+
pub const _MC_FLAG_MASK: u32 = (_MC_HASSEGS | _MC_HASBASES | _MC_HASFPXSTATE);
31+
32+
s_no_extra_traits! {
33+
#[repr(align(16))]
34+
pub struct mcontext_t {
35+
pub mc_onstack: register_t,
36+
pub mc_rdi: register_t,
37+
pub mc_rsi: register_t,
38+
pub mc_rdx: register_t,
39+
pub mc_rcx: register_t,
40+
pub mc_r8: register_t,
41+
pub mc_r9: register_t,
42+
pub mc_rax: register_t,
43+
pub mc_rbx: register_t,
44+
pub mc_rbp: register_t,
45+
pub mc_r10: register_t,
46+
pub mc_r11: register_t,
47+
pub mc_r12: register_t,
48+
pub mc_r13: register_t,
49+
pub mc_r14: register_t,
50+
pub mc_r15: register_t,
51+
pub mc_trapno: u32,
52+
pub mc_fs: u16,
53+
pub mc_gs: u16,
54+
pub mc_addr: register_t,
55+
pub mc_flags: u32,
56+
pub mc_es: u16,
57+
pub mc_ds: u16,
58+
pub mc_err: register_t,
59+
pub mc_rip: register_t,
60+
pub mc_cs: register_t,
61+
pub mc_rflags: register_t,
62+
pub mc_rsp: register_t,
63+
pub mc_ss: register_t,
64+
pub mc_len: c_long,
65+
pub mc_fpformat: c_long,
66+
pub mc_ownedfp: c_long,
67+
pub mc_fpstate: [c_long; 64],
68+
pub mc_fsbase: register_t,
69+
pub mc_gsbase: register_t,
70+
pub mc_xfpustate: register_t,
71+
pub mc_xfpustate_len: register_t,
72+
pub mc_spare: [c_long; 4],
73+
}
74+
}
75+
76+
cfg_if! {
77+
if #[cfg(feature = "extra_traits")] {
78+
impl PartialEq for mcontext_t {
79+
fn eq(&self, other: &mcontext_t) -> bool {
80+
self.mc_onstack == other.mc_onstack &&
81+
self.mc_rdi == other.mc_rdi &&
82+
self.mc_rsi == other.mc_rsi &&
83+
self.mc_rdx == other.mc_rdx &&
84+
self.mc_rcx == other.mc_rcx &&
85+
self.mc_r8 == other.mc_r8 &&
86+
self.mc_r9 == other.mc_r9 &&
87+
self.mc_rax == other.mc_rax &&
88+
self.mc_rbx == other.mc_rbx &&
89+
self.mc_rbp == other.mc_rbp &&
90+
self.mc_r10 == other.mc_r10 &&
91+
self.mc_r11 == other.mc_r11 &&
92+
self.mc_r12 == other.mc_r12 &&
93+
self.mc_r13 == other.mc_r13 &&
94+
self.mc_r14 == other.mc_r14 &&
95+
self.mc_r15 == other.mc_r15 &&
96+
self.mc_trapno == other.mc_trapno &&
97+
self.mc_fs == other.mc_fs &&
98+
self.mc_gs == other.mc_gs &&
99+
self.mc_addr == other.mc_addr &&
100+
self.mc_flags == other.mc_flags &&
101+
self.mc_es == other.mc_es &&
102+
self.mc_ds == other.mc_ds &&
103+
self.mc_err == other.mc_err &&
104+
self.mc_rip == other.mc_rip &&
105+
self.mc_cs == other.mc_cs &&
106+
self.mc_rflags == other.mc_rflags &&
107+
self.mc_rsp == other.mc_rsp &&
108+
self.mc_ss == other.mc_ss &&
109+
self.mc_len == other.mc_len &&
110+
self.mc_fpformat == other.mc_fpformat &&
111+
self.mc_ownedfp == other.mc_ownedfp &&
112+
self.mc_fpstate.iter().zip(other.mc_fpstate.iter())
113+
.all(|(a, b)| a == b) &&
114+
self.mc_fsbase == other.mc_fsbase &&
115+
self.mc_gsbase == other.mc_gsbase &&
116+
self.mc_xfpustate == other.mc_xfpustate &&
117+
self.mc_xfpustate_len == other.mc_xfpustate_len &&
118+
self.mc_spare == other.mc_spare
119+
}
120+
}
121+
122+
impl Eq for mcontext_t {}
123+
124+
impl ::fmt::Debug for mcontext_t {
125+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
126+
f.debug_struct("mcontext_t")
127+
.field("mc_onstack", &self.mc_onstack)
128+
.field("mc_rdi", &self.mc_rdi)
129+
.field("mc_rsi", &self.mc_rsi)
130+
.field("mc_rdx", &self.mc_rdx)
131+
.field("mc_rcx", &self.mc_rcx)
132+
.field("mc_r8", &self.mc_r8)
133+
.field("mc_r9", &self.mc_r9)
134+
.field("mc_rax", &self.mc_rax)
135+
.field("mc_rbx", &self.mc_rbx)
136+
.field("mc_rbp", &self.mc_rbp)
137+
.field("mc_r10", &self.mc_r10)
138+
.field("mc_r11", &self.mc_r11)
139+
.field("mc_r12", &self.mc_r12)
140+
.field("mc_r13", &self.mc_r13)
141+
.field("mc_r14", &self.mc_r14)
142+
.field("mc_r15", &self.mc_r15)
143+
.field("mc_trapno", &self.mc_trapno)
144+
.field("mc_fs", &self.mc_fs)
145+
.field("mc_gs", &self.mc_gs)
146+
.field("mc_addr", &self.mc_addr)
147+
.field("mc_flags", &self.mc_flags)
148+
.field("mc_es", &self.mc_es)
149+
.field("mc_ds", &self.mc_ds)
150+
.field("mc_err", &self.mc_err)
151+
.field("mc_rip", &self.mc_rip)
152+
.field("mc_cs", &self.mc_cs)
153+
.field("mc_rflags", &self.mc_rflags)
154+
.field("mc_rsp", &self.mc_rsp)
155+
.field("mc_ss", &self.mc_ss)
156+
.field("mc_len", &self.mc_len)
157+
.field("mc_fpformat", &self.mc_fpformat)
158+
.field("mc_ownedfp", &self.mc_ownedfp)
159+
// FIXME: .field("mc_fpstate", &self.mc_fpstate)
160+
.field("mc_fsbase", &self.mc_fsbase)
161+
.field("mc_gsbase", &self.mc_gsbase)
162+
.field("mc_xfpustate", &self.mc_xfpustate)
163+
.field("mc_xfpustate_len", &self.mc_xfpustate_len)
164+
.field("mc_spare", &self.mc_spare)
165+
.finish()
166+
}
167+
}
168+
}
169+
}
170+
171+
pub const _MC_FPFMT_NODEV: c_long = 0x10000;
172+
pub const _MC_FPFMT_XMM: c_long = 0x10002;
173+
pub const _MC_FPOWNED_NONE: c_long = 0x20000;
174+
pub const _MC_FPOWNED_FPU: c_long = 0x20001;
175+
pub const _MC_FPOWNED_PCB: c_long = 0x20002;

0 commit comments

Comments
 (0)