Skip to content

Commit 444dae2

Browse files
FreeBSD: Add ucontext_t, mcontext_t for all archs
1 parent e19650d commit 444dae2

File tree

8 files changed

+191
-23
lines changed

8 files changed

+191
-23
lines changed

libc-test/semver/freebsd-x86_64.txt

-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ _MC_HASSEGS
1313
fpreg
1414
fpreg32
1515
max_align_t
16-
mcontext_t
1716
reg
1817
reg32
19-
ucontext_t
2018
xmmreg

libc-test/semver/freebsd.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -2003,6 +2003,7 @@ mallctl
20032003
mallctlbymib
20042004
mallctlnametomib
20052005
mallocx
2006+
mcontext_t
20062007
memmem
20072008
memrchr
20082009
memset_s
@@ -2333,13 +2334,14 @@ timer_t
23332334
timex
23342335
truncate
23352336
ttyname_r
2336-
uuidgen
2337+
ucontext_t
23372338
unmount
23382339
useconds_t
23392340
uselocale
23402341
utimensat
23412342
utmpx
23422343
utrace
2344+
uuidgen
23432345
vm_size_t
23442346
vmtotal
23452347
wait4

src/unix/bsd/freebsdlike/freebsd/arm.rs

+43
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ pub type wchar_t = u32;
55
pub type time_t = i64;
66
pub type suseconds_t = i32;
77
pub type register_t = i32;
8+
pub type __greg_t = ::c_uint;
9+
pub type __gregset_t = [::__greg_t; 17];
810

911
s! {
1012
pub struct stat {
@@ -36,6 +38,47 @@ s! {
3638
}
3739
}
3840

41+
s_no_extra_traits! {
42+
pub struct mcontext_t {
43+
pub __gregs: ::__gregset_t,
44+
pub mc_vfp_size: ::__size_t,
45+
pub mc_vfp_ptr: *mut ::c_void,
46+
pub mc_spare: [::c_uint; 33],
47+
}
48+
}
49+
50+
cfg_if! {
51+
if #[cfg(feature = "extra_traits")] {
52+
impl PartialEq for mcontext_t {
53+
fn eq(&self, other: &mcontext_t) -> bool {
54+
self.__gregs == other.__gregs &&
55+
self.mc_vfp_size == other.mc_vfp_size &&
56+
self.mc_vfp_ptr == other.mc_vfp_ptr &&
57+
self.mc_spare.iter().zip(other.mc_spare.iter()).all(|(a, b)| a == b)
58+
}
59+
}
60+
impl Eq for mcontext_t {}
61+
impl ::fmt::Debug for mcontext_t {
62+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
63+
f.debug_struct("mcontext_t")
64+
.field("__gregs", &self.__gregs)
65+
.field("mc_vfp_size", &self.mc_vfp_size)
66+
.field("mc_vfp_ptr", &self.mc_vfp_ptr)
67+
.field("mc_spare", &self.mc_spare)
68+
.finish()
69+
}
70+
}
71+
impl ::hash::Hash for mcontext_t {
72+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
73+
self.__gregs.hash(state);
74+
self.mc_vfp_size.hash(state);
75+
self.mc_vfp_ptr.hash(state);
76+
self.mc_spare.hash(state);
77+
}
78+
}
79+
}
80+
}
81+
3982
pub(crate) const _ALIGNBYTES: usize = ::mem::size_of::<::c_int>() - 1;
4083
pub const MAP_32BIT: ::c_int = 0x00080000;
4184
pub const MINSIGSTKSZ: ::size_t = 4096; // 1024 * 4

src/unix/bsd/freebsdlike/freebsd/mod.rs

+21
Original file line numberDiff line numberDiff line change
@@ -1638,6 +1638,15 @@ s_no_extra_traits! {
16381638
_kf_cap_spare: u64,
16391639
pub kf_path: [::c_char; ::PATH_MAX as usize],
16401640
}
1641+
1642+
pub struct ucontext_t {
1643+
pub uc_sigmask: ::sigset_t,
1644+
pub uc_mcontext: ::mcontext_t,
1645+
pub uc_link: *mut ::ucontext_t,
1646+
pub uc_stack: ::stack_t,
1647+
pub uc_flags: ::c_int,
1648+
__spare__: [::c_int; 4],
1649+
}
16411650
}
16421651

16431652
cfg_if! {
@@ -2592,6 +2601,18 @@ cfg_if! {
25922601
self.kf_path.hash(state);
25932602
}
25942603
}
2604+
2605+
impl ::fmt::Debug for ucontext_t {
2606+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
2607+
f.debug_struct("ucontext_t")
2608+
.field("uc_sigmask", &self.uc_sigmask)
2609+
.field("uc_mcontext", &self.uc_mcontext)
2610+
.field("uc_link", &self.uc_link)
2611+
.field("uc_stack", &self.uc_stack)
2612+
.field("uc_flags", &self.uc_flags)
2613+
.finish()
2614+
}
2615+
}
25952616
}
25962617
}
25972618

src/unix/bsd/freebsdlike/freebsd/powerpc.rs

+62
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,68 @@ s! {
3232
}
3333
}
3434

35+
s_no_extra_traits! {
36+
#[repr(align(16))]
37+
pub struct mcontext_t {
38+
pub mc_vers: ::c_int,
39+
pub mc_flags: ::c_int,
40+
pub mc_onstack: ::c_int,
41+
pub mc_len: ::c_int,
42+
pub mc_avec: [u64; 64],
43+
pub mc_av: [u32; 2],
44+
pub mc_frame: [::register_t; 42],
45+
pub mc_fpreg: [u64; 33],
46+
pub mc_vsxfpreg: [u64; 32],
47+
}
48+
}
49+
50+
cfg_if! {
51+
if #[cfg(feature = "extra_traits")] {
52+
impl PartialEq for mcontext_t {
53+
fn eq(&self, other: &mcontext_t) -> bool {
54+
self.mc_vers == other.mc_vers &&
55+
self.mc_flags == other.mc_flags &&
56+
self.mc_onstack == other.mc_onstack &&
57+
self.mc_len == other.mc_len &&
58+
self.mc_avec == other.mc_avec &&
59+
self.mc_av == other.mc_av &&
60+
self.mc_frame == other.mc_frame &&
61+
self.mc_fpreg == other.mc_fpreg &&
62+
self.mc_vsxfpreg == other.mc_vsxfpreg
63+
}
64+
}
65+
impl Eq for mcontext_t {}
66+
impl ::fmt::Debug for mcontext_t {
67+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
68+
f.debug_struct("mcontext_t")
69+
.field("mc_vers", &self.mc_vers)
70+
.field("mc_flags", &self.mc_flags)
71+
.field("mc_onstack", &self.mc_onstack)
72+
.field("mc_len", &self.mc_len)
73+
.field("mc_avec", &self.mc_avec)
74+
.field("mc_av", &self.mc_av)
75+
.field("mc_frame", &self.mc_frame)
76+
.field("mc_fpreg", &self.mc_fpreg)
77+
.field("mc_vsxfpreg", &self.mc_vsxfpreg)
78+
.finish()
79+
}
80+
}
81+
impl ::hash::Hash for mcontext_t {
82+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
83+
self.mc_vers.hash(state);
84+
self.mc_flags.hash(state);
85+
self.mc_onstack.hash(state);
86+
self.mc_len.hash(state);
87+
self.mc_avec.hash(state);
88+
self.mc_av.hash(state);
89+
self.mc_frame.hash(state);
90+
self.mc_fpreg.hash(state);
91+
self.mc_vsxfpreg.hash(state);
92+
}
93+
}
94+
}
95+
}
96+
3597
pub(crate) const _ALIGNBYTES: usize = ::mem::size_of::<::c_int>() - 1;
3698
pub const MAP_32BIT: ::c_int = 0x00080000;
3799
pub const MINSIGSTKSZ: ::size_t = 2048; // 512 * 4

src/unix/bsd/freebsdlike/freebsd/powerpc64.rs

+62
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,68 @@ s! {
3232
}
3333
}
3434

35+
s_no_extra_traits! {
36+
#[repr(align(16))]
37+
pub struct mcontext_t {
38+
pub mc_vers: ::c_int,
39+
pub mc_flags: ::c_int,
40+
pub mc_onstack: ::c_int,
41+
pub mc_len: ::c_int,
42+
pub mc_avec: [u64; 64],
43+
pub mc_av: [u32; 2],
44+
pub mc_frame: [::register_t; 42],
45+
pub mc_fpreg: [u64; 33],
46+
pub mc_vsxfpreg: [u64; 32],
47+
}
48+
}
49+
50+
cfg_if! {
51+
if #[cfg(feature = "extra_traits")] {
52+
impl PartialEq for mcontext_t {
53+
fn eq(&self, other: &mcontext_t) -> bool {
54+
self.mc_vers == other.mc_vers &&
55+
self.mc_flags == other.mc_flags &&
56+
self.mc_onstack == other.mc_onstack &&
57+
self.mc_len == other.mc_len &&
58+
self.mc_avec == other.mc_avec &&
59+
self.mc_av == other.mc_av &&
60+
self.mc_frame == other.mc_frame &&
61+
self.mc_fpreg == other.mc_fpreg &&
62+
self.mc_vsxfpreg == other.mc_vsxfpreg
63+
}
64+
}
65+
impl Eq for mcontext_t {}
66+
impl ::fmt::Debug for mcontext_t {
67+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
68+
f.debug_struct("mcontext_t")
69+
.field("mc_vers", &self.mc_vers)
70+
.field("mc_flags", &self.mc_flags)
71+
.field("mc_onstack", &self.mc_onstack)
72+
.field("mc_len", &self.mc_len)
73+
.field("mc_avec", &self.mc_avec)
74+
.field("mc_av", &self.mc_av)
75+
.field("mc_frame", &self.mc_frame)
76+
.field("mc_fpreg", &self.mc_fpreg)
77+
.field("mc_vsxfpreg", &self.mc_vsxfpreg)
78+
.finish()
79+
}
80+
}
81+
impl ::hash::Hash for mcontext_t {
82+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
83+
self.mc_vers.hash(state);
84+
self.mc_flags.hash(state);
85+
self.mc_onstack.hash(state);
86+
self.mc_len.hash(state);
87+
self.mc_avec.hash(state);
88+
self.mc_av.hash(state);
89+
self.mc_frame.hash(state);
90+
self.mc_fpreg.hash(state);
91+
self.mc_vsxfpreg.hash(state);
92+
}
93+
}
94+
}
95+
}
96+
3597
pub(crate) const _ALIGNBYTES: usize = ::mem::size_of::<::c_long>() - 1;
3698

3799
pub const MAP_32BIT: ::c_int = 0x00080000;

src/unix/bsd/freebsdlike/freebsd/x86.rs

-9
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,6 @@ s! {
6666
pub st_birthtime_nsec: ::c_long,
6767
__unused: [u8; 8],
6868
}
69-
70-
pub struct ucontext_t {
71-
pub uc_sigmask: ::sigset_t,
72-
pub uc_mcontext: ::mcontext_t,
73-
pub uc_link: *mut ::ucontext_t,
74-
pub uc_stack: ::stack_t,
75-
pub uc_flags: ::c_int,
76-
__spare__: [::c_int; 4],
77-
}
7869
}
7970

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

src/unix/bsd/freebsdlike/freebsd/x86_64/align.rs

-11
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,3 @@ cfg_if! {
184184
}
185185
}
186186
}
187-
188-
s! {
189-
pub struct ucontext_t {
190-
pub uc_sigmask: ::sigset_t,
191-
pub uc_mcontext: ::mcontext_t,
192-
pub uc_link: *mut ::ucontext_t,
193-
pub uc_stack: ::stack_t,
194-
pub uc_flags: ::c_int,
195-
__spare__: [::c_int; 4],
196-
}
197-
}

0 commit comments

Comments
 (0)