Skip to content

Commit 2a58378

Browse files
committed
Auto merge of #1421 - DoumanAsh:expose_posix_timer_value, r=gnzlbg
Expose signal value of siginfo_t Currently exposes it for following platforms: - Linux has it as enum _timer and it is exposed alongside sigval - On FreeBSD like systems si_value follows after si_addr (according to headers) - Darwin is similar to FreeBSD - NetBSD and FreeBSD uses struct that contains pid, uid, and si_value. Exposed via it P.s. I'd like to take a look at other platforms too, but these are what I know so far. FreeBSD needs some testing though cc @gnzlbg
2 parents 789c381 + 2cd9b40 commit 2a58378

File tree

9 files changed

+132
-2
lines changed

9 files changed

+132
-2
lines changed

src/unix/bsd/apple/mod.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ impl ::Clone for timezone {
4444
fn clone(&self) -> timezone { *self }
4545
}
4646

47+
impl siginfo_t {
48+
pub unsafe fn si_addr(&self) -> *mut ::c_void {
49+
self.si_addr
50+
}
51+
52+
pub unsafe fn si_value(&self) -> ::sigval {
53+
self.si_value
54+
}
55+
}
56+
4757
s! {
4858
pub struct ip_mreq {
4959
pub imr_multiaddr: in_addr,
@@ -144,7 +154,9 @@ s! {
144154
pub si_uid: ::uid_t,
145155
pub si_status: ::c_int,
146156
pub si_addr: *mut ::c_void,
147-
_pad: [usize; 9],
157+
pub si_value: ::sigval,
158+
pub si_band: ::c_long,
159+
_pad: [usize; 7],
148160
}
149161

150162
pub struct sigaction {

src/unix/bsd/freebsdlike/mod.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ impl ::Clone for timezone {
2121
fn clone(&self) -> timezone { *self }
2222
}
2323

24+
impl siginfo_t {
25+
pub unsafe fn si_addr(&self) -> *mut ::c_void {
26+
self.si_addr
27+
}
28+
29+
pub unsafe fn si_value(&self) -> ::sigval {
30+
self.si_value
31+
}
32+
}
33+
2434
s! {
2535
pub struct in_addr {
2636
pub s_addr: ::in_addr_t,
@@ -68,7 +78,8 @@ s! {
6878
pub si_uid: ::uid_t,
6979
pub si_status: ::c_int,
7080
pub si_addr: *mut ::c_void,
71-
_pad: [::c_int; 12],
81+
pub si_value: ::sigval,
82+
_pad: [::c_int; 8],
7283
}
7384

7485
pub struct sigaction {

src/unix/bsd/netbsdlike/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ impl ::Clone for sem {
2525
}
2626

2727
s! {
28+
pub struct _timer {
29+
_pid: ::pid_t,
30+
_uid: ::uid_t,
31+
_value: ::sigval,
32+
}
33+
2834
pub struct sigaction {
2935
pub sa_sigaction: ::sighandler_t,
3036
pub sa_mask: ::sigset_t,

src/unix/bsd/netbsdlike/netbsd/mod.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,24 @@ pub type mqd_t = ::c_int;
99
type __pthread_spin_t = __cpu_simple_lock_nv_t;
1010
pub type vm_size_t = ::uintptr_t;
1111

12+
impl siginfo_t {
13+
pub unsafe fn si_value(&self) -> ::sigval {
14+
self.timer()._value
15+
}
16+
17+
pub unsafe fn timer(&self) -> ::_timer {
18+
#[repr(C)]
19+
struct siginfo_timer {
20+
_si_signo: ::c_int,
21+
_si_errno: ::c_int,
22+
_si_code: ::c_int,
23+
__pad1: ::c_int,
24+
timer: ::_timer,
25+
}
26+
(*(self as *const siginfo_t as *const siginfo_timer)).timer
27+
}
28+
}
29+
1230
s! {
1331
pub struct aiocb {
1432
pub aio_offset: ::off_t,

src/unix/bsd/netbsdlike/openbsd/mod.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,23 @@ s! {
308308
}
309309
}
310310

311+
impl siginfo_t {
312+
pub unsafe fn si_value(&self) -> ::sigval {
313+
self.timer()._value
314+
}
315+
316+
pub unsafe fn timer(&self) -> ::_timer {
317+
#[repr(C)]
318+
struct siginfo_timer {
319+
_si_signo: ::c_int,
320+
_si_errno: ::c_int,
321+
_si_code: ::c_int,
322+
timer: ::_timer,
323+
}
324+
(*(self as *const siginfo_t as *const siginfo_timer)).timer
325+
}
326+
}
327+
311328
s_no_extra_traits! {
312329
pub struct dirent {
313330
pub d_fileno: ::ino_t,

src/unix/linux_like/android/mod.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2192,3 +2192,20 @@ cfg_if! {
21922192
// Unknown target_pointer_width
21932193
}
21942194
}
2195+
2196+
impl siginfo_t {
2197+
pub unsafe fn si_value(&self) -> ::sigval {
2198+
self.timer().si_sigval
2199+
}
2200+
2201+
pub unsafe fn timer(&self) -> ::_timer {
2202+
#[repr(C)]
2203+
struct siginfo_timer {
2204+
_si_signo: ::c_int,
2205+
_si_errno: ::c_int,
2206+
_si_code: ::c_int,
2207+
timer: ::_timer,
2208+
}
2209+
(*(self as *const siginfo_t as *const siginfo_timer)).timer
2210+
}
2211+
}

src/unix/linux_like/linux/gnu/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,21 @@ impl siginfo_t {
193193
}
194194
(*(self as *const siginfo_t as *const siginfo_sigfault)).si_addr
195195
}
196+
197+
pub unsafe fn si_value(&self) -> ::sigval {
198+
self.timer().si_sigval
199+
}
200+
201+
pub unsafe fn timer(&self) -> ::_timer {
202+
#[repr(C)]
203+
struct siginfo_timer {
204+
_si_signo: ::c_int,
205+
_si_errno: ::c_int,
206+
_si_code: ::c_int,
207+
timer: ::_timer,
208+
}
209+
(*(self as *const siginfo_t as *const siginfo_timer)).timer
210+
}
196211
}
197212

198213
s_no_extra_traits! {

src/unix/linux_like/linux/musl/mod.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,34 @@ pub type fsblkcnt_t = ::c_ulonglong;
1313
pub type fsfilcnt_t = ::c_ulonglong;
1414
pub type rlim_t = ::c_ulonglong;
1515

16+
impl siginfo_t {
17+
pub unsafe fn si_addr(&self) -> *mut ::c_void {
18+
#[repr(C)]
19+
struct siginfo_sigfault {
20+
_si_signo: ::c_int,
21+
_si_errno: ::c_int,
22+
_si_code: ::c_int,
23+
si_addr: *mut ::c_void
24+
}
25+
26+
(*(self as *const siginfo_t as *const siginfo_sigfault)).si_addr
27+
}
28+
29+
pub unsafe fn si_value(&self) -> ::sigval {
30+
#[repr(C)]
31+
struct siginfo_si_value {
32+
_si_signo: ::c_int,
33+
_si_errno: ::c_int,
34+
_si_code: ::c_int,
35+
_si_timerid: ::c_int,
36+
_si_overrun: ::c_int,
37+
si_value: ::sigval,
38+
}
39+
40+
(*(self as *const siginfo_t as *const siginfo_si_value)).si_value
41+
}
42+
}
43+
1644
s! {
1745
pub struct aiocb {
1846
pub aio_fildes: ::c_int,

src/unix/linux_like/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ impl ::Clone for timezone {
1313
}
1414

1515
s! {
16+
pub struct _timer {
17+
pub si_tid: ::c_int,
18+
pub si_overrun: ::c_int,
19+
pub si_sigval: ::sigval,
20+
}
21+
1622
pub struct in_addr {
1723
pub s_addr: ::in_addr_t,
1824
}

0 commit comments

Comments
 (0)