Skip to content

Commit d3378bc

Browse files
committed
Expose si_addr on siginfo_t. Refs #716
1 parent 0d01633 commit d3378bc

File tree

1 file changed

+99
-11
lines changed
  • src/unix/notbsd/linux/other

1 file changed

+99
-11
lines changed

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

+99-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,104 @@
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+
#[repr(C, packed)]
30+
#[derive(Copy, Clone)]
31+
union sifields_t {
32+
_pad: [::c_int; 29],
33+
sigfault: sigfault_t,
34+
}
35+
36+
impl ::fmt::Debug for sigfault_t_anonymous_union {
37+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
38+
// Excludes the fields because we can't know which is valid
39+
f.debug_struct("sigfault_t_anonymous_union")
40+
.finish()
41+
}
42+
}
43+
44+
impl ::fmt::Debug for sigfault_t {
45+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
46+
// TODO: include trapno on Sparc
47+
f.debug_struct("sigfault_t")
48+
.field("addr", &self.addr)
49+
.field("addr_lsb", &self.addr_lsb)
50+
.field("anonymous_union", &self.anonymous_union)
51+
.finish()
52+
}
53+
}
54+
55+
impl ::fmt::Debug for sifields_t {
56+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
57+
// No way to print anything more detailed without the
58+
// discriminant from siginfo_t
59+
f.debug_struct("sifields_t").finish()
60+
}
61+
}
62+
} else {
63+
type sifields_t = [::c_int; 29];
64+
}
65+
}
66+
67+
s_no_extra_traits! {
68+
pub struct siginfo_t {
69+
pub si_signo: ::c_int,
70+
pub si_errno: ::c_int,
71+
pub si_code: ::c_int,
72+
sifields: sifields_t,
73+
74+
#[cfg(target_arch = "x86_64")]
75+
_align: [u64; 0],
76+
#[cfg(not(target_arch = "x86_64"))]
77+
_align: [usize; 0],
78+
}
79+
}
80+
81+
cfg_if! {
82+
if #[cfg(libc_union)] {
83+
impl siginfo_t {
84+
pub unsafe fn si_addr(&self) -> *mut ::c_void {
85+
self.sifields.sigfault.addr
86+
}
87+
}
88+
}
89+
}
90+
91+
impl ::fmt::Debug for siginfo_t {
92+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
93+
// TODO: include fields from sifields
94+
f.debug_struct("siginfo_t")
95+
.field("si_signo", &self.si_signo)
96+
.field("si_errno", &self.si_errno)
97+
.field("si_code", &self.si_code)
98+
.finish()
99+
}
100+
}
101+
3102
s! {
4103
pub struct aiocb {
5104
pub aio_fildes: ::c_int,
@@ -44,17 +143,6 @@ s! {
44143
pub ss_size: ::size_t
45144
}
46145

47-
pub struct siginfo_t {
48-
pub si_signo: ::c_int,
49-
pub si_errno: ::c_int,
50-
pub si_code: ::c_int,
51-
pub _pad: [::c_int; 29],
52-
#[cfg(target_arch = "x86_64")]
53-
_align: [u64; 0],
54-
#[cfg(not(target_arch = "x86_64"))]
55-
_align: [usize; 0],
56-
}
57-
58146
pub struct glob64_t {
59147
pub gl_pathc: ::size_t,
60148
pub gl_pathv: *mut *mut ::c_char,

0 commit comments

Comments
 (0)