Skip to content

Commit 9727b9e

Browse files
committed
Expose si_addr on siginfo_t. Refs rust-lang#716
1 parent 363ba93 commit 9727b9e

File tree

1 file changed

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

1 file changed

+96
-11
lines changed

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

Lines changed: 96 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,101 @@
11
pub type __priority_which_t = ::c_uint;
22

3+
#[repr(C)]
4+
#[derive(Copy, Clone)]
5+
struct addr_bnd_t {
6+
lower: *mut ::c_void,
7+
upper: *mut ::c_void,
8+
}
9+
10+
cfg_if! {
11+
if #[cfg(libc_union)] {
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+
}
20+
21+
#[repr(C)]
22+
#[derive(Copy, Clone)]
23+
struct sigfault_t {
24+
addr: *mut ::c_void,
25+
#[cfg(target_arch = "sparc")]
26+
trapno: ::c_int,
27+
addr_lsb: ::c_short,
28+
anonymous_union: sigfault_t_anonymous_union,
29+
}
30+
31+
cfg_if! {
32+
if #[cfg(libc_union)] {
33+
#[repr(C)]
34+
#[derive(Copy, Clone)]
35+
union sifields_t {
36+
_pad: [::c_int; 29],
37+
sigfault: sigfault_t,
38+
}
39+
}
40+
}
41+
42+
s_no_extra_traits! {
43+
pub struct siginfo_t {
44+
pub si_signo: ::c_int,
45+
pub si_errno: ::c_int,
46+
pub si_code: ::c_int,
47+
sifields: sifields_t,
48+
#[cfg(target_arch = "x86_64")]
49+
_align: [u64; 0],
50+
#[cfg(not(target_arch = "x86_64"))]
51+
_align: [usize; 0],
52+
}
53+
}
54+
55+
impl ::fmt::Debug for sigfault_t_anonymous_union {
56+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
57+
// TODO: no idea how to tell which of the members is used
58+
f.debug_struct("sigfault_t_anonymous_union")
59+
.finish()
60+
}
61+
}
62+
63+
impl ::fmt::Debug for sigfault_t {
64+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
65+
// TODO: include trapno on Sparc
66+
f.debug_struct("sigfault_t")
67+
.field("addr", &self.addr)
68+
.field("addr_lsb", &self.addr_lsb)
69+
.field("anonymous_union", &self.anonymous_union)
70+
.finish()
71+
}
72+
}
73+
74+
impl ::fmt::Debug for sifields_t {
75+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
76+
// No way to print anything more detailed without the discriminant from
77+
// siginfo_t
78+
f.debug_struct("sifields_t").finish()
79+
}
80+
}
81+
82+
impl siginfo_t {
83+
pub unsafe fn si_addr(&self) -> *mut ::c_void {
84+
self.sifields.sigfault.addr
85+
}
86+
}
87+
88+
impl ::fmt::Debug for siginfo_t {
89+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
90+
// TODO: include fields from sifields
91+
f.debug_struct("siginfo_t")
92+
.field("si_signo", &self.si_signo)
93+
.field("si_errno", &self.si_errno)
94+
.field("si_code", &self.si_code)
95+
.finish()
96+
}
97+
}
98+
399
s! {
4100
pub struct aiocb {
5101
pub aio_fildes: ::c_int,
@@ -44,17 +140,6 @@ s! {
44140
pub ss_size: ::size_t
45141
}
46142

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-
58143
pub struct glob64_t {
59144
pub gl_pathc: ::size_t,
60145
pub gl_pathv: *mut *mut ::c_char,

0 commit comments

Comments
 (0)