From 444dae2d0d43dd000cb6abd0baefed80bcc7e6b2 Mon Sep 17 00:00:00 2001 From: Nathaniel Date: Sat, 17 Aug 2024 16:51:44 -0400 Subject: [PATCH] FreeBSD: Add ucontext_t, mcontext_t for all archs --- libc-test/semver/freebsd-x86_64.txt | 2 - libc-test/semver/freebsd.txt | 4 +- src/unix/bsd/freebsdlike/freebsd/arm.rs | 43 +++++++++++++ src/unix/bsd/freebsdlike/freebsd/mod.rs | 21 +++++++ src/unix/bsd/freebsdlike/freebsd/powerpc.rs | 62 +++++++++++++++++++ src/unix/bsd/freebsdlike/freebsd/powerpc64.rs | 62 +++++++++++++++++++ src/unix/bsd/freebsdlike/freebsd/x86.rs | 9 --- .../bsd/freebsdlike/freebsd/x86_64/align.rs | 11 ---- 8 files changed, 191 insertions(+), 23 deletions(-) diff --git a/libc-test/semver/freebsd-x86_64.txt b/libc-test/semver/freebsd-x86_64.txt index be73d1f7290fe..14ddc25a1b254 100644 --- a/libc-test/semver/freebsd-x86_64.txt +++ b/libc-test/semver/freebsd-x86_64.txt @@ -13,8 +13,6 @@ _MC_HASSEGS fpreg fpreg32 max_align_t -mcontext_t reg reg32 -ucontext_t xmmreg diff --git a/libc-test/semver/freebsd.txt b/libc-test/semver/freebsd.txt index 4e1f998f39982..d4f506322c6c5 100644 --- a/libc-test/semver/freebsd.txt +++ b/libc-test/semver/freebsd.txt @@ -2003,6 +2003,7 @@ mallctl mallctlbymib mallctlnametomib mallocx +mcontext_t memmem memrchr memset_s @@ -2333,13 +2334,14 @@ timer_t timex truncate ttyname_r -uuidgen +ucontext_t unmount useconds_t uselocale utimensat utmpx utrace +uuidgen vm_size_t vmtotal wait4 diff --git a/src/unix/bsd/freebsdlike/freebsd/arm.rs b/src/unix/bsd/freebsdlike/freebsd/arm.rs index af3c8a7cf6f6c..eb90f3f9030e7 100644 --- a/src/unix/bsd/freebsdlike/freebsd/arm.rs +++ b/src/unix/bsd/freebsdlike/freebsd/arm.rs @@ -5,6 +5,8 @@ pub type wchar_t = u32; pub type time_t = i64; pub type suseconds_t = i32; pub type register_t = i32; +pub type __greg_t = ::c_uint; +pub type __gregset_t = [::__greg_t; 17]; s! { pub struct stat { @@ -36,6 +38,47 @@ s! { } } +s_no_extra_traits! { + pub struct mcontext_t { + pub __gregs: ::__gregset_t, + pub mc_vfp_size: ::__size_t, + pub mc_vfp_ptr: *mut ::c_void, + pub mc_spare: [::c_uint; 33], + } +} + +cfg_if! { + if #[cfg(feature = "extra_traits")] { + impl PartialEq for mcontext_t { + fn eq(&self, other: &mcontext_t) -> bool { + self.__gregs == other.__gregs && + self.mc_vfp_size == other.mc_vfp_size && + self.mc_vfp_ptr == other.mc_vfp_ptr && + self.mc_spare.iter().zip(other.mc_spare.iter()).all(|(a, b)| a == b) + } + } + impl Eq for mcontext_t {} + impl ::fmt::Debug for mcontext_t { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("mcontext_t") + .field("__gregs", &self.__gregs) + .field("mc_vfp_size", &self.mc_vfp_size) + .field("mc_vfp_ptr", &self.mc_vfp_ptr) + .field("mc_spare", &self.mc_spare) + .finish() + } + } + impl ::hash::Hash for mcontext_t { + fn hash(&self, state: &mut H) { + self.__gregs.hash(state); + self.mc_vfp_size.hash(state); + self.mc_vfp_ptr.hash(state); + self.mc_spare.hash(state); + } + } + } +} + pub(crate) const _ALIGNBYTES: usize = ::mem::size_of::<::c_int>() - 1; pub const MAP_32BIT: ::c_int = 0x00080000; pub const MINSIGSTKSZ: ::size_t = 4096; // 1024 * 4 diff --git a/src/unix/bsd/freebsdlike/freebsd/mod.rs b/src/unix/bsd/freebsdlike/freebsd/mod.rs index 307ca87127f31..832b7537f8d91 100644 --- a/src/unix/bsd/freebsdlike/freebsd/mod.rs +++ b/src/unix/bsd/freebsdlike/freebsd/mod.rs @@ -1638,6 +1638,15 @@ s_no_extra_traits! { _kf_cap_spare: u64, pub kf_path: [::c_char; ::PATH_MAX as usize], } + + pub struct ucontext_t { + pub uc_sigmask: ::sigset_t, + pub uc_mcontext: ::mcontext_t, + pub uc_link: *mut ::ucontext_t, + pub uc_stack: ::stack_t, + pub uc_flags: ::c_int, + __spare__: [::c_int; 4], + } } cfg_if! { @@ -2592,6 +2601,18 @@ cfg_if! { self.kf_path.hash(state); } } + + impl ::fmt::Debug for ucontext_t { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("ucontext_t") + .field("uc_sigmask", &self.uc_sigmask) + .field("uc_mcontext", &self.uc_mcontext) + .field("uc_link", &self.uc_link) + .field("uc_stack", &self.uc_stack) + .field("uc_flags", &self.uc_flags) + .finish() + } + } } } diff --git a/src/unix/bsd/freebsdlike/freebsd/powerpc.rs b/src/unix/bsd/freebsdlike/freebsd/powerpc.rs index 0900005166a2e..5de61946de3b9 100644 --- a/src/unix/bsd/freebsdlike/freebsd/powerpc.rs +++ b/src/unix/bsd/freebsdlike/freebsd/powerpc.rs @@ -32,6 +32,68 @@ s! { } } +s_no_extra_traits! { + #[repr(align(16))] + pub struct mcontext_t { + pub mc_vers: ::c_int, + pub mc_flags: ::c_int, + pub mc_onstack: ::c_int, + pub mc_len: ::c_int, + pub mc_avec: [u64; 64], + pub mc_av: [u32; 2], + pub mc_frame: [::register_t; 42], + pub mc_fpreg: [u64; 33], + pub mc_vsxfpreg: [u64; 32], + } +} + +cfg_if! { + if #[cfg(feature = "extra_traits")] { + impl PartialEq for mcontext_t { + fn eq(&self, other: &mcontext_t) -> bool { + self.mc_vers == other.mc_vers && + self.mc_flags == other.mc_flags && + self.mc_onstack == other.mc_onstack && + self.mc_len == other.mc_len && + self.mc_avec == other.mc_avec && + self.mc_av == other.mc_av && + self.mc_frame == other.mc_frame && + self.mc_fpreg == other.mc_fpreg && + self.mc_vsxfpreg == other.mc_vsxfpreg + } + } + impl Eq for mcontext_t {} + impl ::fmt::Debug for mcontext_t { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("mcontext_t") + .field("mc_vers", &self.mc_vers) + .field("mc_flags", &self.mc_flags) + .field("mc_onstack", &self.mc_onstack) + .field("mc_len", &self.mc_len) + .field("mc_avec", &self.mc_avec) + .field("mc_av", &self.mc_av) + .field("mc_frame", &self.mc_frame) + .field("mc_fpreg", &self.mc_fpreg) + .field("mc_vsxfpreg", &self.mc_vsxfpreg) + .finish() + } + } + impl ::hash::Hash for mcontext_t { + fn hash(&self, state: &mut H) { + self.mc_vers.hash(state); + self.mc_flags.hash(state); + self.mc_onstack.hash(state); + self.mc_len.hash(state); + self.mc_avec.hash(state); + self.mc_av.hash(state); + self.mc_frame.hash(state); + self.mc_fpreg.hash(state); + self.mc_vsxfpreg.hash(state); + } + } + } +} + pub(crate) const _ALIGNBYTES: usize = ::mem::size_of::<::c_int>() - 1; pub const MAP_32BIT: ::c_int = 0x00080000; pub const MINSIGSTKSZ: ::size_t = 2048; // 512 * 4 diff --git a/src/unix/bsd/freebsdlike/freebsd/powerpc64.rs b/src/unix/bsd/freebsdlike/freebsd/powerpc64.rs index 07f2f11cdc9a4..ca9cf5c8524f2 100644 --- a/src/unix/bsd/freebsdlike/freebsd/powerpc64.rs +++ b/src/unix/bsd/freebsdlike/freebsd/powerpc64.rs @@ -32,6 +32,68 @@ s! { } } +s_no_extra_traits! { + #[repr(align(16))] + pub struct mcontext_t { + pub mc_vers: ::c_int, + pub mc_flags: ::c_int, + pub mc_onstack: ::c_int, + pub mc_len: ::c_int, + pub mc_avec: [u64; 64], + pub mc_av: [u32; 2], + pub mc_frame: [::register_t; 42], + pub mc_fpreg: [u64; 33], + pub mc_vsxfpreg: [u64; 32], + } +} + +cfg_if! { + if #[cfg(feature = "extra_traits")] { + impl PartialEq for mcontext_t { + fn eq(&self, other: &mcontext_t) -> bool { + self.mc_vers == other.mc_vers && + self.mc_flags == other.mc_flags && + self.mc_onstack == other.mc_onstack && + self.mc_len == other.mc_len && + self.mc_avec == other.mc_avec && + self.mc_av == other.mc_av && + self.mc_frame == other.mc_frame && + self.mc_fpreg == other.mc_fpreg && + self.mc_vsxfpreg == other.mc_vsxfpreg + } + } + impl Eq for mcontext_t {} + impl ::fmt::Debug for mcontext_t { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("mcontext_t") + .field("mc_vers", &self.mc_vers) + .field("mc_flags", &self.mc_flags) + .field("mc_onstack", &self.mc_onstack) + .field("mc_len", &self.mc_len) + .field("mc_avec", &self.mc_avec) + .field("mc_av", &self.mc_av) + .field("mc_frame", &self.mc_frame) + .field("mc_fpreg", &self.mc_fpreg) + .field("mc_vsxfpreg", &self.mc_vsxfpreg) + .finish() + } + } + impl ::hash::Hash for mcontext_t { + fn hash(&self, state: &mut H) { + self.mc_vers.hash(state); + self.mc_flags.hash(state); + self.mc_onstack.hash(state); + self.mc_len.hash(state); + self.mc_avec.hash(state); + self.mc_av.hash(state); + self.mc_frame.hash(state); + self.mc_fpreg.hash(state); + self.mc_vsxfpreg.hash(state); + } + } + } +} + pub(crate) const _ALIGNBYTES: usize = ::mem::size_of::<::c_long>() - 1; pub const MAP_32BIT: ::c_int = 0x00080000; diff --git a/src/unix/bsd/freebsdlike/freebsd/x86.rs b/src/unix/bsd/freebsdlike/freebsd/x86.rs index 3e3e5cc9f34fb..75a900a043d09 100644 --- a/src/unix/bsd/freebsdlike/freebsd/x86.rs +++ b/src/unix/bsd/freebsdlike/freebsd/x86.rs @@ -66,15 +66,6 @@ s! { pub st_birthtime_nsec: ::c_long, __unused: [u8; 8], } - - pub struct ucontext_t { - pub uc_sigmask: ::sigset_t, - pub uc_mcontext: ::mcontext_t, - pub uc_link: *mut ::ucontext_t, - pub uc_stack: ::stack_t, - pub uc_flags: ::c_int, - __spare__: [::c_int; 4], - } } pub(crate) const _ALIGNBYTES: usize = ::mem::size_of::<::c_long>() - 1; diff --git a/src/unix/bsd/freebsdlike/freebsd/x86_64/align.rs b/src/unix/bsd/freebsdlike/freebsd/x86_64/align.rs index 3a016a0519852..208e7f2c90c0a 100644 --- a/src/unix/bsd/freebsdlike/freebsd/x86_64/align.rs +++ b/src/unix/bsd/freebsdlike/freebsd/x86_64/align.rs @@ -184,14 +184,3 @@ cfg_if! { } } } - -s! { - pub struct ucontext_t { - pub uc_sigmask: ::sigset_t, - pub uc_mcontext: ::mcontext_t, - pub uc_link: *mut ::ucontext_t, - pub uc_stack: ::stack_t, - pub uc_flags: ::c_int, - __spare__: [::c_int; 4], - } -}