Skip to content

Commit 9340bb3

Browse files
committed
FreeBSD: add mcontext_t/ucontext_t (only amd64 for now)
1 parent 1366bda commit 9340bb3

File tree

6 files changed

+206
-0
lines changed

6 files changed

+206
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ pub type c_ulong = u64;
44
pub type wchar_t = u32;
55
pub type time_t = i64;
66
pub type suseconds_t = i64;
7+
pub type register_t = i64;
78

89
// should be pub(crate), but that requires Rust 1.18.0
910
cfg_if! {

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

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

89
s! {
910
pub struct stat {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ pub type c_ulong = u64;
44
pub type wchar_t = i32;
55
pub type time_t = i64;
66
pub type suseconds_t = i64;
7+
pub type register_t = i64;
78

89
s! {
910
pub struct stat {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ pub type c_ulong = u32;
44
pub type wchar_t = i32;
55
pub type time_t = i32;
66
pub type suseconds_t = i32;
7+
pub type register_t = i32;
78

89
s! {
910
pub struct stat {
Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,197 @@
1+
use {c_long, register_t};
2+
13
s_no_extra_traits! {
24
#[allow(missing_debug_implementations)]
35
#[repr(align(16))]
46
pub struct max_align_t {
57
priv_: [f64; 4]
68
}
9+
10+
#[repr(align(16))]
11+
pub struct mcontext_t {
12+
pub mc_onstack: register_t,
13+
pub mc_rdi: register_t,
14+
pub mc_rsi: register_t,
15+
pub mc_rdx: register_t,
16+
pub mc_rcx: register_t,
17+
pub mc_r8: register_t,
18+
pub mc_r9: register_t,
19+
pub mc_rax: register_t,
20+
pub mc_rbx: register_t,
21+
pub mc_rbp: register_t,
22+
pub mc_r10: register_t,
23+
pub mc_r11: register_t,
24+
pub mc_r12: register_t,
25+
pub mc_r13: register_t,
26+
pub mc_r14: register_t,
27+
pub mc_r15: register_t,
28+
pub mc_trapno: u32,
29+
pub mc_fs: u16,
30+
pub mc_gs: u16,
31+
pub mc_addr: register_t,
32+
pub mc_flags: u32,
33+
pub mc_es: u16,
34+
pub mc_ds: u16,
35+
pub mc_err: register_t,
36+
pub mc_rip: register_t,
37+
pub mc_cs: register_t,
38+
pub mc_rflags: register_t,
39+
pub mc_rsp: register_t,
40+
pub mc_ss: register_t,
41+
pub mc_len: c_long,
42+
pub mc_fpformat: c_long,
43+
pub mc_ownedfp: c_long,
44+
pub mc_fpstate: [c_long; 64],
45+
pub mc_fsbase: register_t,
46+
pub mc_gsbase: register_t,
47+
pub mc_xfpustate: register_t,
48+
pub mc_xfpustate_len: register_t,
49+
pub mc_spare: [c_long; 4],
50+
}
51+
}
52+
53+
cfg_if! {
54+
if #[cfg(feature = "extra_traits")] {
55+
impl PartialEq for mcontext_t {
56+
fn eq(&self, other: &mcontext_t) -> bool {
57+
self.mc_onstack == other.mc_onstack &&
58+
self.mc_rdi == other.mc_rdi &&
59+
self.mc_rsi == other.mc_rsi &&
60+
self.mc_rdx == other.mc_rdx &&
61+
self.mc_rcx == other.mc_rcx &&
62+
self.mc_r8 == other.mc_r8 &&
63+
self.mc_r9 == other.mc_r9 &&
64+
self.mc_rax == other.mc_rax &&
65+
self.mc_rbx == other.mc_rbx &&
66+
self.mc_rbp == other.mc_rbp &&
67+
self.mc_r10 == other.mc_r10 &&
68+
self.mc_r11 == other.mc_r11 &&
69+
self.mc_r12 == other.mc_r12 &&
70+
self.mc_r13 == other.mc_r13 &&
71+
self.mc_r14 == other.mc_r14 &&
72+
self.mc_r15 == other.mc_r15 &&
73+
self.mc_trapno == other.mc_trapno &&
74+
self.mc_fs == other.mc_fs &&
75+
self.mc_gs == other.mc_gs &&
76+
self.mc_addr == other.mc_addr &&
77+
self.mc_flags == other.mc_flags &&
78+
self.mc_es == other.mc_es &&
79+
self.mc_ds == other.mc_ds &&
80+
self.mc_err == other.mc_err &&
81+
self.mc_rip == other.mc_rip &&
82+
self.mc_cs == other.mc_cs &&
83+
self.mc_rflags == other.mc_rflags &&
84+
self.mc_rsp == other.mc_rsp &&
85+
self.mc_ss == other.mc_ss &&
86+
self.mc_len == other.mc_len &&
87+
self.mc_fpformat == other.mc_fpformat &&
88+
self.mc_ownedfp == other.mc_ownedfp &&
89+
self.mc_fpstate.iter().zip(other.mc_fpstate.iter())
90+
.all(|(a, b)| a == b) &&
91+
self.mc_fsbase == other.mc_fsbase &&
92+
self.mc_gsbase == other.mc_gsbase &&
93+
self.mc_xfpustate == other.mc_xfpustate &&
94+
self.mc_xfpustate_len == other.mc_xfpustate_len &&
95+
self.mc_spare == other.mc_spare
96+
}
97+
}
98+
impl Eq for mcontext_t {}
99+
impl ::fmt::Debug for mcontext_t {
100+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
101+
f.debug_struct("mcontext_t")
102+
.field("mc_onstack", &self.mc_onstack)
103+
.field("mc_rdi", &self.mc_rdi)
104+
.field("mc_rsi", &self.mc_rsi)
105+
.field("mc_rdx", &self.mc_rdx)
106+
.field("mc_rcx", &self.mc_rcx)
107+
.field("mc_r8", &self.mc_r8)
108+
.field("mc_r9", &self.mc_r9)
109+
.field("mc_rax", &self.mc_rax)
110+
.field("mc_rbx", &self.mc_rbx)
111+
.field("mc_rbp", &self.mc_rbp)
112+
.field("mc_r10", &self.mc_r10)
113+
.field("mc_r11", &self.mc_r11)
114+
.field("mc_r12", &self.mc_r12)
115+
.field("mc_r13", &self.mc_r13)
116+
.field("mc_r14", &self.mc_r14)
117+
.field("mc_r15", &self.mc_r15)
118+
.field("mc_trapno", &self.mc_trapno)
119+
.field("mc_fs", &self.mc_fs)
120+
.field("mc_gs", &self.mc_gs)
121+
.field("mc_addr", &self.mc_addr)
122+
.field("mc_flags", &self.mc_flags)
123+
.field("mc_es", &self.mc_es)
124+
.field("mc_ds", &self.mc_ds)
125+
.field("mc_err", &self.mc_err)
126+
.field("mc_rip", &self.mc_rip)
127+
.field("mc_cs", &self.mc_cs)
128+
.field("mc_rflags", &self.mc_rflags)
129+
.field("mc_rsp", &self.mc_rsp)
130+
.field("mc_ss", &self.mc_ss)
131+
.field("mc_len", &self.mc_len)
132+
.field("mc_fpformat", &self.mc_fpformat)
133+
.field("mc_ownedfp", &self.mc_ownedfp)
134+
// FIXME: .field("mc_fpstate", &self.mc_fpstate)
135+
.field("mc_fsbase", &self.mc_fsbase)
136+
.field("mc_gsbase", &self.mc_gsbase)
137+
.field("mc_xfpustate", &self.mc_xfpustate)
138+
.field("mc_xfpustate_len", &self.mc_xfpustate_len)
139+
.field("mc_spare", &self.mc_spare)
140+
.finish()
141+
}
142+
}
143+
impl ::hash::Hash for mcontext_t {
144+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
145+
self.mc_onstack.hash(state);
146+
self.mc_rdi.hash(state);
147+
self.mc_rsi.hash(state);
148+
self.mc_rdx.hash(state);
149+
self.mc_rcx.hash(state);
150+
self.mc_r8.hash(state);
151+
self.mc_r9.hash(state);
152+
self.mc_rax.hash(state);
153+
self.mc_rbx.hash(state);
154+
self.mc_rbp.hash(state);
155+
self.mc_r10.hash(state);
156+
self.mc_r11.hash(state);
157+
self.mc_r12.hash(state);
158+
self.mc_r13.hash(state);
159+
self.mc_r14.hash(state);
160+
self.mc_r15.hash(state);
161+
self.mc_trapno.hash(state);
162+
self.mc_fs.hash(state);
163+
self.mc_gs.hash(state);
164+
self.mc_addr.hash(state);
165+
self.mc_flags.hash(state);
166+
self.mc_es.hash(state);
167+
self.mc_ds.hash(state);
168+
self.mc_err.hash(state);
169+
self.mc_rip.hash(state);
170+
self.mc_cs.hash(state);
171+
self.mc_rflags.hash(state);
172+
self.mc_rsp.hash(state);
173+
self.mc_ss.hash(state);
174+
self.mc_len.hash(state);
175+
self.mc_fpformat.hash(state);
176+
self.mc_ownedfp.hash(state);
177+
self.mc_fpstate.hash(state);
178+
self.mc_fsbase.hash(state);
179+
self.mc_gsbase.hash(state);
180+
self.mc_xfpustate.hash(state);
181+
self.mc_xfpustate_len.hash(state);
182+
self.mc_spare.hash(state);
183+
}
184+
}
185+
}
186+
}
187+
188+
s! {
189+
pub struct ucontext_t {
190+
pub uc_sigmask: ::sigset_t,
191+
pub uc_mcontext: ::mcontext_t,
192+
pub uc_link: *mut ::ucontext_t,
193+
pub uc_stack: ::stack_t,
194+
pub uc_flags: ::c_int,
195+
__spare__: [::c_int; 4],
196+
}
7197
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ pub type c_ulong = u64;
44
pub type wchar_t = i32;
55
pub type time_t = i64;
66
pub type suseconds_t = i64;
7+
pub type register_t = i64;
78

89
s! {
910
pub struct reg32 {
@@ -188,6 +189,17 @@ cfg_if! {
188189
pub const MAP_32BIT: ::c_int = 0x00080000;
189190
pub const MINSIGSTKSZ: ::size_t = 2048; // 512 * 4
190191

192+
pub const _MC_HASSEGS: u32 = 0x1;
193+
pub const _MC_HASBASES: u32 = 0x2;
194+
pub const _MC_HASFPXSTATE: u32 = 0x4;
195+
pub const _MC_FLAG_MASK: u32 = _MC_HASSEGS | _MC_HASBASES | _MC_HASFPXSTATE;
196+
197+
pub const _MC_FPFMT_NODEV: c_long = 0x10000;
198+
pub const _MC_FPFMT_XMM: c_long = 0x10002;
199+
pub const _MC_FPOWNED_NONE: c_long = 0x20000;
200+
pub const _MC_FPOWNED_FPU: c_long = 0x20001;
201+
pub const _MC_FPOWNED_PCB: c_long = 0x20002;
202+
191203
cfg_if! {
192204
if #[cfg(libc_align)] {
193205
mod align;

0 commit comments

Comments
 (0)