Skip to content

Commit 5f4b05a

Browse files
committed
openbsd: export struct sigcontext for x86_64
based on initial work from @devnexen
1 parent d056f09 commit 5f4b05a

File tree

2 files changed

+109
-0
lines changed

2 files changed

+109
-0
lines changed

libc-test/build.rs

+3
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,8 @@ fn test_openbsd(target: &str) {
387387
let mut cfg = ctest_cfg();
388388
cfg.flag("-Wno-deprecated-declarations");
389389

390+
let x86_64 = target.contains("x86_64");
391+
390392
headers! { cfg:
391393
"elf.h",
392394
"errno.h",
@@ -405,6 +407,7 @@ fn test_openbsd(target: &str) {
405407
"ctype.h",
406408
"dirent.h",
407409
"sys/socket.h",
410+
[x86_64]:"machine/fpu.h",
408411
"net/if.h",
409412
"net/route.h",
410413
"net/if_arp.h",

src/unix/bsd/netbsdlike/openbsd/x86_64.rs

+106
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,112 @@ use PT_FIRSTMACH;
33
pub type c_long = i64;
44
pub type c_ulong = u64;
55
pub type c_char = i8;
6+
pub type ucontext_t = sigcontext;
7+
8+
s! {
9+
pub struct sigcontext {
10+
pub sc_rdi: ::c_long,
11+
pub sc_rsi: ::c_long,
12+
pub sc_rdx: ::c_long,
13+
pub sc_rcx: ::c_long,
14+
pub sc_r8: ::c_long,
15+
pub sc_r9: ::c_long,
16+
pub sc_r10: ::c_long,
17+
pub sc_r11: ::c_long,
18+
pub sc_r12: ::c_long,
19+
pub sc_r13: ::c_long,
20+
pub sc_r14: ::c_long,
21+
pub sc_r15: ::c_long,
22+
pub sc_rbp: ::c_long,
23+
pub sc_rbx: ::c_long,
24+
pub sc_rax: ::c_long,
25+
pub sc_gs: ::c_long,
26+
pub sc_fs: ::c_long,
27+
pub sc_es: ::c_long,
28+
pub sc_ds: ::c_long,
29+
pub sc_trapno: ::c_long,
30+
pub sc_err: ::c_long,
31+
pub sc_rip: ::c_long,
32+
pub sc_cs: ::c_long,
33+
pub sc_rflags: ::c_long,
34+
pub sc_rsp: ::c_long,
35+
pub sc_ss: ::c_long,
36+
pub sc_fpstate: *mut fxsave64,
37+
__sc_unused: ::c_int,
38+
pub sc_mask: ::c_int,
39+
pub sc_cookie: ::c_long,
40+
}
41+
}
42+
43+
s_no_extra_traits! {
44+
#[repr(packed)]
45+
pub struct fxsave64 {
46+
pub fx_fcw: u16,
47+
pub fx_fsw: u16,
48+
pub fx_ftw: u8,
49+
__fx_unused1: u8,
50+
pub fx_fop: u16,
51+
pub fx_rip: u64,
52+
pub fx_rdp: u64,
53+
pub fx_mxcsr: u32,
54+
pub fx_mxcsr_mask: u32,
55+
pub fx_st: [[u64; 2]; 8],
56+
pub fx_xmm: [[u64; 2]; 16],
57+
__fx_unused3: [u8; 96],
58+
}
59+
}
60+
61+
cfg_if! {
62+
if #[cfg(feature = "extra_traits")] {
63+
// `fxsave64` is packed, so field access is unaligned.
64+
// use {x} to create temporary storage, copy field to it, and do aligned access.
65+
impl PartialEq for fxsave64 {
66+
fn eq(&self, other: &fxsave64) -> bool {
67+
return {self.fx_fcw} == {other.fx_fcw} &&
68+
{self.fx_fsw} == {other.fx_fsw} &&
69+
{self.fx_ftw} == {other.fx_ftw} &&
70+
{self.fx_fop} == {other.fx_fop} &&
71+
{self.fx_rip} == {other.fx_rip} &&
72+
{self.fx_rdp} == {other.fx_rdp} &&
73+
{self.fx_mxcsr} == {other.fx_mxcsr} &&
74+
{self.fx_mxcsr_mask} == {other.fx_mxcsr_mask} &&
75+
{self.fx_st}.iter().zip({other.fx_st}.iter()).all(|(a,b)| a == b) &&
76+
{self.fx_xmm}.iter().zip({other.fx_xmm}.iter()).all(|(a,b)| a == b)
77+
}
78+
}
79+
impl Eq for fxsave64 {}
80+
impl ::fmt::Debug for fxsave64 {
81+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
82+
f.debug_struct("fxsave64")
83+
.field("fx_fcw", &{self.fx_fcw})
84+
.field("fx_fsw", &{self.fx_fsw})
85+
.field("fx_ftw", &{self.fx_ftw})
86+
.field("fx_fop", &{self.fx_fop})
87+
.field("fx_rip", &{self.fx_rip})
88+
.field("fx_rdp", &{self.fx_rdp})
89+
.field("fx_mxcsr", &{self.fx_mxcsr})
90+
.field("fx_mxcsr_mask", &{self.fx_mxcsr_mask})
91+
// FIXME: .field("fx_st", &{self.fx_st})
92+
// FIXME: .field("fx_xmm", &{self.fx_xmm})
93+
.finish()
94+
}
95+
}
96+
impl ::hash::Hash for fxsave64 {
97+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
98+
{self.fx_fcw}.hash(state);
99+
{self.fx_fsw}.hash(state);
100+
{self.fx_ftw}.hash(state);
101+
{self.fx_fop}.hash(state);
102+
{self.fx_rip}.hash(state);
103+
{self.fx_rdp}.hash(state);
104+
{self.fx_mxcsr}.hash(state);
105+
{self.fx_mxcsr_mask}.hash(state);
106+
{self.fx_st}.hash(state);
107+
{self.fx_xmm}.hash(state);
108+
}
109+
}
110+
}
111+
}
6112

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

0 commit comments

Comments
 (0)