From e9499cff7b7c3fdf9c035fb726a09eaac16aafb3 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sat, 22 May 2021 07:18:55 +0100 Subject: [PATCH] openbsd update map sigcontext for amd64 --- build.rs | 5 + libc-test/build.rs | 5 + src/lib.rs | 11 ++ src/unix/bsd/netbsdlike/openbsd/x86_64.rs | 140 ++++++++++++++++++++++ 4 files changed, 161 insertions(+) diff --git a/build.rs b/build.rs index c4982111e701b..f390e5e02e15a 100644 --- a/build.rs +++ b/build.rs @@ -72,6 +72,11 @@ fn main() { println!("cargo:rustc-cfg=libc_cfg_target_vendor"); } + // Rust >= 1.51 supports std::ptr::addr_of. + if rustc_minor_ver >= 51 || rustc_dep_of_std { + println!("cargo:rustc-cfg=libc_addr_of"); + } + // #[thread_local] is currently unstable if rustc_dep_of_std { println!("cargo:rustc-cfg=libc_thread_local"); diff --git a/libc-test/build.rs b/libc-test/build.rs index a4f65ba0e9247..3c9c3032eb1d6 100755 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -387,6 +387,8 @@ fn test_openbsd(target: &str) { let mut cfg = ctest_cfg(); cfg.flag("-Wno-deprecated-declarations"); + let x86_64 = target.contains("x86_64"); + headers! { cfg: "elf.h", "errno.h", @@ -405,6 +407,7 @@ fn test_openbsd(target: &str) { "ctype.h", "dirent.h", "sys/socket.h", + [x86_64]:"machine/fpu.h", "net/if.h", "net/route.h", "net/if_arp.h", @@ -463,6 +466,8 @@ fn test_openbsd(target: &str) { match ty { // FIXME: actually a union "sigval" => true, + // fxsave64 is a packed struct + "fxsave64" => true, _ => false, } diff --git a/src/lib.rs b/src/lib.rs index 30c94b0969bb4..9610ef09aee44 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -42,6 +42,8 @@ cfg_if! { use core::ops; #[allow(unused_imports)] use core::option; + #[allow(unused_imports)] + use core::ptr; } } @@ -92,6 +94,15 @@ cfg_if! { } } +cfg_if! { + if #[cfg(libc_addr_of, std)] { + #[doc(hidden)] + extern crate std; + #[allow(unused_imports)] + use std::ptr; + } +} + cfg_if! { if #[cfg(windows)] { mod fixed_width_ints; diff --git a/src/unix/bsd/netbsdlike/openbsd/x86_64.rs b/src/unix/bsd/netbsdlike/openbsd/x86_64.rs index 263b6e13a2d72..6bb1a229ba71f 100644 --- a/src/unix/bsd/netbsdlike/openbsd/x86_64.rs +++ b/src/unix/bsd/netbsdlike/openbsd/x86_64.rs @@ -3,6 +3,146 @@ use PT_FIRSTMACH; pub type c_long = i64; pub type c_ulong = u64; pub type c_char = i8; +pub type ucontext_t = sigcontext; + +s_no_extra_traits! { + #[repr(C, packed)] + pub struct fxsave64 { + pub fx_fcw: u16, + pub fx_fsw: u16, + pub fx_ftw: u8, + __unused: u8, + pub fx_fop: u16, + pub fx_rip: u64, + pub fx_rdp: u64, + pub fx_mxcsr: u32, + pub fx_mxcsr_mask: u32, + pub fx_st: [[u64; 2]; 8], + pub fx_xmm: [[u64; 2]; 16], + __reserved: [u8; 96], + } +} + +cfg_if! { + if #[cfg(all(feature = "extra_traits", libc_addr_of, std))] { + impl PartialEq for fxsave64 { + fn eq(&self, other: &fxsave64) -> bool { + unsafe { + let fx_xmm = self.fx_xmm.as_ptr(); + let ofx_xmm = other.fx_xmm.as_ptr(); + self.fx_fcw == other.fx_fcw && + self.fx_fsw == other.fx_fsw && + self.fx_ftw == other.fx_ftw && + self.fx_fop == other.fx_fop && + self.fx_rip == other.fx_rip && + self.fx_rdp == other.fx_rdp && + self.fx_mxcsr == other.fx_mxcsr && + self.fx_mxcsr_mask == other.fx_mxcsr_mask && + self.fx_st == other.fx_st && + std::ptr::addr_of!(fx_xmm) == std::ptr::addr_of!(ofx_xmm) + } + } + } + impl Eq for fxsave64 {} + impl ::fmt::Debug for fxsave64 { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + unsafe { + let fx_xmm = self.fx_xmm.as_ptr(); + f.debug_struct("fxsave64") + .field("fx_fcw", &self.fx_fcw) + .field("fx_fsw", &self.fx_fsw) + .field("fx_ftw", &self.fx_ftw) + .field("fx_fop", &self.fx_fop) + .field("fx_rip", &self.fx_rip) + .field("fx_rdp", &self.fx_rdp) + .field("fx_mxcsr", &self.fx_mxcsr) + .field("fx_mxcsr_mask", &self.fx_mxcsr_mask) + .field("fx_st", &self.fx_st) + .field("fx_xmm", &*std::ptr::addr_of!(fx_xmm)) + .finish() + } + } + } + } + +} + +cfg_if! { + if #[cfg(all(feature = "extra_traits", not(std)))] { + impl PartialEq for fxsave64 { + fn eq(&self, other: &fxsave64) -> bool { + unsafe { + let fx_xmm = self.fx_xmm.as_ptr(); + let ofx_xmm = other.fx_xmm.as_ptr(); + self.fx_fcw == other.fx_fcw && + self.fx_fsw == other.fx_fsw && + self.fx_ftw == other.fx_ftw && + self.fx_fop == other.fx_fop && + self.fx_rip == other.fx_rip && + self.fx_rdp == other.fx_rdp && + self.fx_mxcsr == other.fx_mxcsr && + self.fx_mxcsr_mask == other.fx_mxcsr_mask && + self.fx_st == other.fx_st && + fx_xmm == ofx_xmm + } + } + } + impl Eq for fxsave64 {} + impl ::fmt::Debug for fxsave64 { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + unsafe { + f.debug_struct("fxsave64") + .field("fx_fcw", &self.fx_fcw) + .field("fx_fsw", &self.fx_fsw) + .field("fx_ftw", &self.fx_ftw) + .field("fx_fop", &self.fx_fop) + .field("fx_rip", &self.fx_rip) + .field("fx_rdp", &self.fx_rdp) + .field("fx_mxcsr", &self.fx_mxcsr) + .field("fx_mxcsr_mask", &self.fx_mxcsr_mask) + .field("fx_st", &self.fx_st) + .field("fx_xmm", &self.fx_xmm) + .finish() + } + } + } + } +} + +s! { + pub struct sigcontext { + pub sc_rdi: ::c_long, + pub sc_rsi: ::c_long, + pub sc_rdx: ::c_long, + pub sc_rcx: ::c_long, + pub sc_r8: ::c_long, + pub sc_r9: ::c_long, + pub sc_r10: ::c_long, + pub sc_r11: ::c_long, + pub sc_r12: ::c_long, + pub sc_r13: ::c_long, + pub sc_r14: ::c_long, + pub sc_r15: ::c_long, + pub sc_rbp: ::c_long, + pub sc_rbx: ::c_long, + pub sc_rax: ::c_long, + pub sc_gs: ::c_long, + pub sc_fs: ::c_long, + pub sc_es: ::c_long, + pub sc_ds: ::c_long, + pub sc_trapno: ::c_long, + pub sc_err: ::c_long, + pub sc_rip: ::c_long, + pub sc_cs: ::c_long, + pub sc_rflags: ::c_long, + pub sc_rsp: ::c_long, + pub sc_ss: ::c_long, + sc_fpstate: *mut fxsave64, + __unused: ::c_int, + pub sc_mask: ::c_int, + pub sc_cookie: ::c_long, + } +} // should be pub(crate), but that requires Rust 1.18.0 cfg_if! {