Skip to content

Commit

Permalink
FreeBSD: Add ucontext_t, mcontext_t for all archs (rust-lang#3848)
Browse files Browse the repository at this point in the history
(backport <rust-lang#3848>)
(cherry picked from commit 2053d5b)
  • Loading branch information
nathaniel-bennett authored and tgross35 committed Nov 6, 2024
1 parent ae7b38d commit 1ae3bdd
Show file tree
Hide file tree
Showing 8 changed files with 192 additions and 25 deletions.
2 changes: 0 additions & 2 deletions libc-test/semver/freebsd-x86_64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ _MC_HASSEGS
fpreg
fpreg32
max_align_t
mcontext_t
reg
reg32
ucontext_t
xmmreg
4 changes: 3 additions & 1 deletion libc-test/semver/freebsd.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2020,6 +2020,7 @@ mallctl
mallctlbymib
mallctlnametomib
mallocx
mcontext_t
memmem
memrchr
memset_s
Expand Down Expand Up @@ -2350,13 +2351,14 @@ timer_t
timex
truncate
ttyname_r
uuidgen
ucontext_t
unmount
useconds_t
uselocale
utimensat
utmpx
utrace
uuidgen
vm_size_t
vmtotal
wait4
Expand Down
44 changes: 44 additions & 0 deletions src/unix/bsd/freebsdlike/freebsd/arm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,49 @@ 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_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<H: ::hash::Hasher>(&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);
}
}
}
}

// should be pub(crate), but that requires Rust 1.18.0
cfg_if! {
Expand All @@ -16,5 +59,6 @@ cfg_if! {
pub const _ALIGNBYTES: usize = 4 - 1;
}
}

pub const MAP_32BIT: ::c_int = 0x00080000;
pub const MINSIGSTKSZ: ::size_t = 4096; // 1024 * 4
21 changes: 21 additions & 0 deletions src/unix/bsd/freebsdlike/freebsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1654,6 +1654,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! {
Expand Down Expand Up @@ -2656,6 +2665,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()
}
}
}
}

Expand Down
62 changes: 62 additions & 0 deletions src/unix/bsd/freebsdlike/freebsd/powerpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,68 @@ pub type time_t = i64;
pub type suseconds_t = i32;
pub type register_t = i32;

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<H: ::hash::Hasher>(&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);
}
}
}
}

// should be pub(crate), but that requires Rust 1.18.0
cfg_if! {
if #[cfg(libc_const_size_of)] {
Expand Down
62 changes: 62 additions & 0 deletions src/unix/bsd/freebsdlike/freebsd/powerpc64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,68 @@ pub type time_t = i64;
pub type suseconds_t = i64;
pub type register_t = i64;

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<H: ::hash::Hasher>(&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);
}
}
}
}

// should be pub(crate), but that requires Rust 1.18.0
cfg_if! {
if #[cfg(libc_const_size_of)] {
Expand Down
11 changes: 0 additions & 11 deletions src/unix/bsd/freebsdlike/freebsd/x86.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,6 @@ s_no_extra_traits! {
}
}

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],
}
}

// should be pub(crate), but that requires Rust 1.18.0
cfg_if! {
if #[cfg(libc_const_size_of)] {
Expand Down
11 changes: 0 additions & 11 deletions src/unix/bsd/freebsdlike/freebsd/x86_64/align.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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],
}
}

0 comments on commit 1ae3bdd

Please sign in to comment.