Skip to content

Commit 8535dc4

Browse files
nathaniel-bennettAkhilTThomas
authored andcommitted
FreeBSD: Add ucontext_t, mcontext_t for all archs (rust-lang#3848)
[ gate ppc under `cfg(libc_align)` and adjust `Debug` implementations to meet msrv - Trevor ] (backport <rust-lang#3848>) (cherry picked from commit 2053d5b)
1 parent 1bc00dd commit 8535dc4

File tree

3 files changed

+209
-1
lines changed

3 files changed

+209
-1
lines changed

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,6 +1661,15 @@ s_no_extra_traits! {
16611661
pub uc_flags: c_int,
16621662
__spare__: [c_int; 4],
16631663
}
1664+
1665+
pub struct ucontext_t {
1666+
pub uc_sigmask: ::sigset_t,
1667+
pub uc_mcontext: ::mcontext_t,
1668+
pub uc_link: *mut ::ucontext_t,
1669+
pub uc_stack: ::stack_t,
1670+
pub uc_flags: ::c_int,
1671+
__spare__: [::c_int; 4],
1672+
}
16641673
}
16651674

16661675
cfg_if! {
@@ -2587,6 +2596,18 @@ cfg_if! {
25872596
self.kf_path.hash(state);
25882597
}
25892598
}
2599+
2600+
impl ::fmt::Debug for ucontext_t {
2601+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
2602+
f.debug_struct("ucontext_t")
2603+
.field("uc_sigmask", &self.uc_sigmask)
2604+
.field("uc_mcontext", &self.uc_mcontext)
2605+
.field("uc_link", &self.uc_link)
2606+
.field("uc_stack", &self.uc_stack)
2607+
.field("uc_flags", &self.uc_flags)
2608+
.finish()
2609+
}
2610+
}
25902611
}
25912612
}
25922613

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ cfg_if! {
118118
.field("mc_fpformat", &self.mc_fpformat)
119119
.field("mc_ownedfp", &self.mc_ownedfp)
120120
.field("mc_flags", &self.mc_flags)
121-
.field("mc_fpstate", &self.mc_fpstate)
121+
// FIXME(msrv) debug not supported for arrays in old MSRV
122+
// .field("mc_fpstate", &self.mc_fpstate)
122123
.field("mc_fsbase", &self.mc_fsbase)
123124
.field("mc_gsbase", &self.mc_gsbase)
124125
.field("mc_xfpustate", &self.mc_xfpustate)
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
use {c_long, register_t};
2+
3+
s_no_extra_traits! {
4+
#[allow(missing_debug_implementations)]
5+
#[repr(align(16))]
6+
pub struct max_align_t {
7+
priv_: [f64; 4]
8+
}
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+
}

0 commit comments

Comments
 (0)