Skip to content

Commit b2e9b5f

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

File tree

1 file changed

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

1 file changed

+101
-11
lines changed

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

+101-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,106 @@
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)]
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+
// TODO: no idea how to tell which of the members is used
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 discriminant from
58+
// siginfo_t
59+
f.debug_struct("sifields_t").finish()
60+
}
61+
}
62+
}
63+
}
64+
65+
s_no_extra_traits! {
66+
pub struct siginfo_t {
67+
pub si_signo: ::c_int,
68+
pub si_errno: ::c_int,
69+
pub si_code: ::c_int,
70+
71+
#[cfg(libc_union)]
72+
sifields: sifields_t,
73+
#[cfg(not(libc_union))]
74+
_pad: [::c_int; 29],
75+
76+
#[cfg(target_arch = "x86_64")]
77+
_align: [u64; 0],
78+
#[cfg(not(target_arch = "x86_64"))]
79+
_align: [usize; 0],
80+
}
81+
}
82+
83+
cfg_if! {
84+
if #[cfg(libc_union)] {
85+
impl siginfo_t {
86+
pub unsafe fn si_addr(&self) -> *mut ::c_void {
87+
self.sifields.sigfault.addr
88+
}
89+
}
90+
}
91+
}
92+
93+
impl ::fmt::Debug for siginfo_t {
94+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
95+
// TODO: include fields from sifields
96+
f.debug_struct("siginfo_t")
97+
.field("si_signo", &self.si_signo)
98+
.field("si_errno", &self.si_errno)
99+
.field("si_code", &self.si_code)
100+
.finish()
101+
}
102+
}
103+
3104
s! {
4105
pub struct aiocb {
5106
pub aio_fildes: ::c_int,
@@ -44,17 +145,6 @@ s! {
44145
pub ss_size: ::size_t
45146
}
46147

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-
58148
pub struct glob64_t {
59149
pub gl_pathc: ::size_t,
60150
pub gl_pathv: *mut *mut ::c_char,

0 commit comments

Comments
 (0)