Skip to content

Commit 996a213

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

File tree

1 file changed

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

1 file changed

+84
-11
lines changed

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

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

3+
s! {
4+
pub struct addr_bnd_t {
5+
lower: *mut ::c_void,
6+
upper: *mut ::c_void,
7+
}
8+
9+
}
10+
11+
s_no_extra_traits! {
12+
pub union sigfault_t_anonymous_union {
13+
addr_bnd: addr_bnd_t,
14+
pkey: u32,
15+
}
16+
17+
pub struct sigfault_t {
18+
addr: *mut ::c_void,
19+
#[cfg(target_arch = "sparc")]
20+
trapno: ::c_int,
21+
addr_lsb: ::c_short,
22+
anonymous_union: sigfault_t_anonymous_union,
23+
}
24+
25+
#[repr(C, packed)]
26+
pub union sifields_t {
27+
_pad: [::c_int; 29],
28+
sigfault: sigfault_t,
29+
}
30+
31+
pub struct siginfo_t {
32+
pub si_signo: ::c_int,
33+
pub si_errno: ::c_int,
34+
pub si_code: ::c_int,
35+
sifields: sifields_t,
36+
#[cfg(target_arch = "x86_64")]
37+
_align: [u64; 0],
38+
#[cfg(not(target_arch = "x86_64"))]
39+
_align: [usize; 0],
40+
}
41+
}
42+
43+
impl ::fmt::Debug for sigfault_t_anonymous_union {
44+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
45+
// TODO: no idea how to tell which of the members is used
46+
f.debug_struct("sigfault_t_anonymous_union")
47+
.finish()
48+
}
49+
}
50+
51+
impl ::fmt::Debug for sigfault_t {
52+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
53+
// TODO: include trapno on Sparc
54+
f.debug_struct("sigfault_t")
55+
.field("addr", &self.addr)
56+
.field("addr_lsb", &self.addr_lsb)
57+
.field("anonymous_union", &self.anonymous_union)
58+
.finish()
59+
}
60+
}
61+
62+
impl ::fmt::Debug for sifields_t {
63+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
64+
// No way to print anything more detailed without the discriminant from siginfo_t
65+
f.debug_struct("sifields_t").finish()
66+
}
67+
}
68+
69+
impl siginfo_t {
70+
pub unsafe fn si_addr(&self) -> *mut ::c_void {
71+
self.sifields.sigfault.addr
72+
}
73+
}
74+
75+
impl ::fmt::Debug for siginfo_t {
76+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
77+
// TODO: include fields from sifields
78+
f.debug_struct("siginfo_t")
79+
.field("si_signo", &self.si_signo)
80+
.field("si_errno", &self.si_errno)
81+
.field("si_code", &self.si_code)
82+
.finish()
83+
}
84+
}
85+
86+
387
s! {
488
pub struct aiocb {
589
pub aio_fildes: ::c_int,
@@ -44,17 +128,6 @@ s! {
44128
pub ss_size: ::size_t
45129
}
46130

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-
58131
pub struct glob64_t {
59132
pub gl_pathc: ::size_t,
60133
pub gl_pathv: *mut *mut ::c_char,

0 commit comments

Comments
 (0)