Skip to content

Commit 9cfe90b

Browse files
committed
Expose si_addr on siginfo_t. Refs #716
1 parent 11f30a8 commit 9cfe90b

File tree

1 file changed

+120
-30
lines changed
  • src/unix/notbsd/linux/other

1 file changed

+120
-30
lines changed

src/unix/notbsd/linux/other/mod.rs

+120-30
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,125 @@
11
pub type __priority_which_t = ::c_uint;
22

3+
cfg_if! {
4+
if #[cfg(libc_union)] {
5+
#[repr(C)]
6+
#[derive(Copy, Clone)]
7+
struct addr_bnd_t {
8+
lower: *mut ::c_void,
9+
upper: *mut ::c_void,
10+
}
11+
12+
#[repr(C)]
13+
#[derive(Copy, Clone)]
14+
union sigfault_t_anonymous_union {
15+
addr_bnd: addr_bnd_t,
16+
pkey: u32,
17+
}
18+
19+
#[repr(C)]
20+
#[derive(Copy, Clone)]
21+
struct sigfault_t {
22+
addr: *mut ::c_void,
23+
#[cfg(target_arch = "sparc")]
24+
trapno: ::c_int,
25+
addr_lsb: ::c_short,
26+
anonymous_union: sigfault_t_anonymous_union,
27+
}
28+
29+
cfg_if! {
30+
if #[cfg(target_pointer_width = "64")] {
31+
type SI_PADDING = [::c_int; 28];
32+
} else {
33+
type SI_PADDING = [::c_int; 29];
34+
}
35+
}
36+
37+
#[repr(C)]
38+
#[derive(Copy, Clone)]
39+
union sifields_t {
40+
_pad: SI_PADDING,
41+
sigfault: sigfault_t,
42+
}
43+
44+
impl ::fmt::Debug for sigfault_t_anonymous_union {
45+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
46+
// Excludes the fields because we can't know which is valid
47+
f.debug_struct("sigfault_t_anonymous_union")
48+
.finish()
49+
}
50+
}
51+
52+
impl ::fmt::Debug for sigfault_t {
53+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
54+
// TODO: include trapno on Sparc
55+
f.debug_struct("sigfault_t")
56+
.field("addr", &self.addr)
57+
.field("addr_lsb", &self.addr_lsb)
58+
.field("anonymous_union", &self.anonymous_union)
59+
.finish()
60+
}
61+
}
62+
63+
impl ::fmt::Debug for sifields_t {
64+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
65+
// No way to print anything more detailed without the
66+
// discriminant from siginfo_t
67+
f.debug_struct("sifields_t").finish()
68+
}
69+
}
70+
} else {
71+
type sifields_t = [::c_int; 29];
72+
}
73+
}
74+
75+
s_no_extra_traits! {
76+
pub struct siginfo_t {
77+
pub si_signo: ::c_int,
78+
pub si_errno: ::c_int,
79+
pub si_code: ::c_int,
80+
sifields: sifields_t,
81+
82+
#[cfg(target_arch = "x86_64")]
83+
_align: [u64; 0],
84+
#[cfg(not(target_arch = "x86_64"))]
85+
_align: [usize; 0],
86+
}
87+
}
88+
89+
cfg_if! {
90+
if #[cfg(libc_union)] {
91+
impl siginfo_t {
92+
pub unsafe fn si_addr(&self) -> *mut ::c_void {
93+
self.sifields.sigfault.addr
94+
}
95+
}
96+
} else {
97+
impl siginfo_t {
98+
pub unsafe fn si_addr(&self) -> *mut ::c_void {
99+
#[repr(C)]
100+
struct siginfo_sigfault {
101+
_si_signo: ::c_int,
102+
_si_errno: ::c_int,
103+
_si_code: ::c_int,
104+
si_addr: *mut ::c_void
105+
}
106+
(*(self as *const siginfo_t as *const siginfo_sigfault)).si_addr
107+
}
108+
}
109+
}
110+
}
111+
112+
impl ::fmt::Debug for siginfo_t {
113+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
114+
// TODO: include fields from sifields
115+
f.debug_struct("siginfo_t")
116+
.field("si_signo", &self.si_signo)
117+
.field("si_errno", &self.si_errno)
118+
.field("si_code", &self.si_code)
119+
.finish()
120+
}
121+
}
122+
3123
s! {
4124
pub struct aiocb {
5125
pub aio_fildes: ::c_int,
@@ -44,23 +164,6 @@ s! {
44164
pub ss_size: ::size_t
45165
}
46166

47-
pub struct siginfo_t {
48-
pub si_signo: ::c_int,
49-
pub si_errno: ::c_int,
50-
pub si_code: ::c_int,
51-
#[deprecated(
52-
since="0.2.54",
53-
note="Please leave a comment on \
54-
https://github.com/rust-lang/libc/pull/1316 if you're using \
55-
this field"
56-
)]
57-
pub _pad: [::c_int; 29],
58-
#[cfg(target_arch = "x86_64")]
59-
_align: [u64; 0],
60-
#[cfg(not(target_arch = "x86_64"))]
61-
_align: [usize; 0],
62-
}
63-
64167
pub struct glob64_t {
65168
pub gl_pathc: ::size_t,
66169
pub gl_pathv: *mut *mut ::c_char,
@@ -200,19 +303,6 @@ s! {
200303
}
201304
}
202305

203-
impl siginfo_t {
204-
pub unsafe fn si_addr(&self) -> *mut ::c_void {
205-
#[repr(C)]
206-
struct siginfo_sigfault {
207-
_si_signo: ::c_int,
208-
_si_errno: ::c_int,
209-
_si_code: ::c_int,
210-
si_addr: *mut ::c_void
211-
}
212-
(*(self as *const siginfo_t as *const siginfo_sigfault)).si_addr
213-
}
214-
}
215-
216306
s_no_extra_traits! {
217307
pub struct utmpx {
218308
pub ut_type: ::c_short,

0 commit comments

Comments
 (0)