Skip to content

Commit

Permalink
FreeBSD: Add ucontext_t, mcontext_t for all archs
Browse files Browse the repository at this point in the history
  • Loading branch information
nathaniel-bennett committed Aug 17, 2024
1 parent e19650d commit c5581de
Show file tree
Hide file tree
Showing 8 changed files with 191 additions and 23 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 @@ -2003,6 +2003,7 @@ mallctl
mallctlbymib
mallctlnametomib
mallocx
mcontext_t
memmem
memrchr
memset_s
Expand Down Expand Up @@ -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
Expand Down
43 changes: 43 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,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 {
Expand Down Expand Up @@ -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<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);
}
}
}
}

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
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 @@ -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! {
Expand Down Expand Up @@ -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()
}
}
}
}

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 @@ -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<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);
}
}
}
}

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
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 @@ -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<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);
}
}
}
}

pub(crate) const _ALIGNBYTES: usize = ::mem::size_of::<::c_long>() - 1;

pub const MAP_32BIT: ::c_int = 0x00080000;
Expand Down
9 changes: 0 additions & 9 deletions src/unix/bsd/freebsdlike/freebsd/x86.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
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 c5581de

Please sign in to comment.