Skip to content

Commit 28a8d26

Browse files
nathaniel-bennetttgross35
authored andcommitted
FreeBSD: Add ucontext_t, mcontext_t for all archs (rust-lang#3848)
(backport <rust-lang#3848>) (cherry picked from commit 2053d5b)
1 parent ae7b38d commit 28a8d26

File tree

8 files changed

+192
-25
lines changed

8 files changed

+192
-25
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
@@ -2020,6 +2020,7 @@ mallctl
20202020
mallctlbymib
20212021
mallctlnametomib
20222022
mallocx
2023+
mcontext_t
20232024
memmem
20242025
memrchr
20252026
memset_s
@@ -2350,13 +2351,14 @@ timer_t
23502351
timex
23512352
truncate
23522353
ttyname_r
2353-
uuidgen
2354+
ucontext_t
23542355
unmount
23552356
useconds_t
23562357
uselocale
23572358
utimensat
23582359
utmpx
23592360
utrace
2361+
uuidgen
23602362
vm_size_t
23612363
vmtotal
23622364
wait4

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

+44
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
// should be pub(crate), but that requires Rust 1.18.0
1012
cfg_if! {
@@ -16,5 +18,47 @@ cfg_if! {
1618
pub const _ALIGNBYTES: usize = 4 - 1;
1719
}
1820
}
21+
22+
s_no_extra_traits! {
23+
pub struct mcontext_t {
24+
pub __gregs: ::__gregset_t,
25+
pub mc_vfp_size: ::__size_t,
26+
pub mc_vfp_ptr: *mut ::c_void,
27+
pub mc_spare: [::c_uint; 33],
28+
}
29+
}
30+
31+
cfg_if! {
32+
if #[cfg(feature = "extra_traits")] {
33+
impl PartialEq for mcontext_t {
34+
fn eq(&self, other: &mcontext_t) -> bool {
35+
self.__gregs == other.__gregs &&
36+
self.mc_vfp_size == other.mc_vfp_size &&
37+
self.mc_vfp_ptr == other.mc_vfp_ptr &&
38+
self.mc_spare.iter().zip(other.mc_spare.iter()).all(|(a, b)| a == b)
39+
}
40+
}
41+
impl Eq for mcontext_t {}
42+
impl ::fmt::Debug for mcontext_t {
43+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
44+
f.debug_struct("mcontext_t")
45+
.field("__gregs", &self.__gregs)
46+
.field("mc_vfp_size", &self.mc_vfp_size)
47+
.field("mc_vfp_ptr", &self.mc_vfp_ptr)
48+
.field("mc_spare", &self.mc_spare)
49+
.finish()
50+
}
51+
}
52+
impl ::hash::Hash for mcontext_t {
53+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
54+
self.__gregs.hash(state);
55+
self.mc_vfp_size.hash(state);
56+
self.mc_vfp_ptr.hash(state);
57+
self.mc_spare.hash(state);
58+
}
59+
}
60+
}
61+
}
62+
1963
pub const MAP_32BIT: ::c_int = 0x00080000;
2064
pub const MINSIGSTKSZ: ::size_t = 4096; // 1024 * 4

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

+21
Original file line numberDiff line numberDiff line change
@@ -1654,6 +1654,15 @@ s_no_extra_traits! {
16541654
_kf_cap_spare: u64,
16551655
pub kf_path: [::c_char; ::PATH_MAX as usize],
16561656
}
1657+
1658+
pub struct ucontext_t {
1659+
pub uc_sigmask: ::sigset_t,
1660+
pub uc_mcontext: ::mcontext_t,
1661+
pub uc_link: *mut ::ucontext_t,
1662+
pub uc_stack: ::stack_t,
1663+
pub uc_flags: ::c_int,
1664+
__spare__: [::c_int; 4],
1665+
}
16571666
}
16581667

16591668
cfg_if! {
@@ -2656,6 +2665,18 @@ cfg_if! {
26562665
self.kf_path.hash(state);
26572666
}
26582667
}
2668+
2669+
impl ::fmt::Debug for ucontext_t {
2670+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
2671+
f.debug_struct("ucontext_t")
2672+
.field("uc_sigmask", &self.uc_sigmask)
2673+
.field("uc_mcontext", &self.uc_mcontext)
2674+
.field("uc_link", &self.uc_link)
2675+
.field("uc_stack", &self.uc_stack)
2676+
.field("uc_flags", &self.uc_flags)
2677+
.finish()
2678+
}
2679+
}
26592680
}
26602681
}
26612682

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

+62
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,67 @@ cfg_if! {
1717
}
1818
}
1919

20+
s_no_extra_traits! {
21+
#[repr(align(16))]
22+
pub struct mcontext_t {
23+
pub mc_vers: ::c_int,
24+
pub mc_flags: ::c_int,
25+
pub mc_onstack: ::c_int,
26+
pub mc_len: ::c_int,
27+
pub mc_avec: [u64; 64],
28+
pub mc_av: [u32; 2],
29+
pub mc_frame: [::register_t; 42],
30+
pub mc_fpreg: [u64; 33],
31+
pub mc_vsxfpreg: [u64; 32],
32+
}
33+
}
34+
35+
cfg_if! {
36+
if #[cfg(feature = "extra_traits")] {
37+
impl PartialEq for mcontext_t {
38+
fn eq(&self, other: &mcontext_t) -> bool {
39+
self.mc_vers == other.mc_vers &&
40+
self.mc_flags == other.mc_flags &&
41+
self.mc_onstack == other.mc_onstack &&
42+
self.mc_len == other.mc_len &&
43+
self.mc_avec == other.mc_avec &&
44+
self.mc_av == other.mc_av &&
45+
self.mc_frame == other.mc_frame &&
46+
self.mc_fpreg == other.mc_fpreg &&
47+
self.mc_vsxfpreg == other.mc_vsxfpreg
48+
}
49+
}
50+
impl Eq for mcontext_t {}
51+
impl ::fmt::Debug for mcontext_t {
52+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
53+
f.debug_struct("mcontext_t")
54+
.field("mc_vers", &self.mc_vers)
55+
.field("mc_flags", &self.mc_flags)
56+
.field("mc_onstack", &self.mc_onstack)
57+
.field("mc_len", &self.mc_len)
58+
.field("mc_avec", &self.mc_avec)
59+
.field("mc_av", &self.mc_av)
60+
.field("mc_frame", &self.mc_frame)
61+
.field("mc_fpreg", &self.mc_fpreg)
62+
.field("mc_vsxfpreg", &self.mc_vsxfpreg)
63+
.finish()
64+
}
65+
}
66+
impl ::hash::Hash for mcontext_t {
67+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
68+
self.mc_vers.hash(state);
69+
self.mc_flags.hash(state);
70+
self.mc_onstack.hash(state);
71+
self.mc_len.hash(state);
72+
self.mc_avec.hash(state);
73+
self.mc_av.hash(state);
74+
self.mc_frame.hash(state);
75+
self.mc_fpreg.hash(state);
76+
self.mc_vsxfpreg.hash(state);
77+
}
78+
}
79+
}
80+
}
81+
2082
pub const MAP_32BIT: ::c_int = 0x00080000;
2183
pub const MINSIGSTKSZ: ::size_t = 2048; // 512 * 4

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

+62
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,67 @@ cfg_if! {
1717
}
1818
}
1919

20+
s_no_extra_traits! {
21+
#[repr(align(16))]
22+
pub struct mcontext_t {
23+
pub mc_vers: ::c_int,
24+
pub mc_flags: ::c_int,
25+
pub mc_onstack: ::c_int,
26+
pub mc_len: ::c_int,
27+
pub mc_avec: [u64; 64],
28+
pub mc_av: [u32; 2],
29+
pub mc_frame: [::register_t; 42],
30+
pub mc_fpreg: [u64; 33],
31+
pub mc_vsxfpreg: [u64; 32],
32+
}
33+
}
34+
35+
cfg_if! {
36+
if #[cfg(feature = "extra_traits")] {
37+
impl PartialEq for mcontext_t {
38+
fn eq(&self, other: &mcontext_t) -> bool {
39+
self.mc_vers == other.mc_vers &&
40+
self.mc_flags == other.mc_flags &&
41+
self.mc_onstack == other.mc_onstack &&
42+
self.mc_len == other.mc_len &&
43+
self.mc_avec == other.mc_avec &&
44+
self.mc_av == other.mc_av &&
45+
self.mc_frame == other.mc_frame &&
46+
self.mc_fpreg == other.mc_fpreg &&
47+
self.mc_vsxfpreg == other.mc_vsxfpreg
48+
}
49+
}
50+
impl Eq for mcontext_t {}
51+
impl ::fmt::Debug for mcontext_t {
52+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
53+
f.debug_struct("mcontext_t")
54+
.field("mc_vers", &self.mc_vers)
55+
.field("mc_flags", &self.mc_flags)
56+
.field("mc_onstack", &self.mc_onstack)
57+
.field("mc_len", &self.mc_len)
58+
.field("mc_avec", &self.mc_avec)
59+
.field("mc_av", &self.mc_av)
60+
.field("mc_frame", &self.mc_frame)
61+
.field("mc_fpreg", &self.mc_fpreg)
62+
.field("mc_vsxfpreg", &self.mc_vsxfpreg)
63+
.finish()
64+
}
65+
}
66+
impl ::hash::Hash for mcontext_t {
67+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
68+
self.mc_vers.hash(state);
69+
self.mc_flags.hash(state);
70+
self.mc_onstack.hash(state);
71+
self.mc_len.hash(state);
72+
self.mc_avec.hash(state);
73+
self.mc_av.hash(state);
74+
self.mc_frame.hash(state);
75+
self.mc_fpreg.hash(state);
76+
self.mc_vsxfpreg.hash(state);
77+
}
78+
}
79+
}
80+
}
81+
2082
pub const MAP_32BIT: ::c_int = 0x00080000;
2183
pub const MINSIGSTKSZ: ::size_t = 2048; // 512 * 4

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

-11
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,6 @@ s_no_extra_traits! {
4141
}
4242
}
4343

44-
s! {
45-
pub struct ucontext_t {
46-
pub uc_sigmask: ::sigset_t,
47-
pub uc_mcontext: ::mcontext_t,
48-
pub uc_link: *mut ::ucontext_t,
49-
pub uc_stack: ::stack_t,
50-
pub uc_flags: ::c_int,
51-
__spare__: [::c_int; 4],
52-
}
53-
}
54-
5544
// should be pub(crate), but that requires Rust 1.18.0
5645
cfg_if! {
5746
if #[cfg(libc_const_size_of)] {

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)