Skip to content

Commit 6534c7d

Browse files
committedApr 12, 2019
Expose si_addr on siginfo_t. Refs #716
1 parent 363ba93 commit 6534c7d

File tree

2 files changed

+112
-11
lines changed

2 files changed

+112
-11
lines changed
 

‎src/macros.rs

+30
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ macro_rules! s_no_extra_traits {
8989
($($(#[$attr:meta])* pub $t:ident $i:ident { $($field:tt)* })*) => ($(
9090
s_no_extra_traits!(it: $(#[$attr])* pub $t $i { $($field)* });
9191
)*);
92+
($($(#[$attr:meta])* $t:ident $i:ident { $($field:tt)* })*) => ($(
93+
s_no_extra_traits!(it: $(#[$attr])* $t $i { $($field)* });
94+
)*);
9295
(it: $(#[$attr:meta])* pub union $i:ident { $($field:tt)* }) => (
9396
cfg_if! {
9497
if #[cfg(libc_union)] {
@@ -105,6 +108,22 @@ macro_rules! s_no_extra_traits {
105108
}
106109
}
107110
);
111+
(it: $(#[$attr:meta])* union $i:ident { $($field:tt)* }) => (
112+
cfg_if! {
113+
if #[cfg(libc_union)] {
114+
__item! {
115+
#[repr(C)]
116+
$(#[$attr])*
117+
union $i { $($field)* }
118+
}
119+
120+
impl ::Copy for $i {}
121+
impl ::Clone for $i {
122+
fn clone(&self) -> $i { *self }
123+
}
124+
}
125+
}
126+
);
108127
(it: $(#[$attr:meta])* pub struct $i:ident { $($field:tt)* }) => (
109128
__item! {
110129
#[repr(C)]
@@ -116,6 +135,17 @@ macro_rules! s_no_extra_traits {
116135
fn clone(&self) -> $i { *self }
117136
}
118137
);
138+
(it: $(#[$attr:meta])* struct $i:ident { $($field:tt)* }) => (
139+
__item! {
140+
#[repr(C)]
141+
$(#[$attr])*
142+
struct $i { $($field)* }
143+
}
144+
impl ::Copy for $i {}
145+
impl ::Clone for $i {
146+
fn clone(&self) -> $i { *self }
147+
}
148+
);
119149
}
120150

121151
#[allow(unused_macros)]

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

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

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

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-
58129
pub struct glob64_t {
59130
pub gl_pathc: ::size_t,
60131
pub gl_pathv: *mut *mut ::c_char,

0 commit comments

Comments
 (0)
Please sign in to comment.