Skip to content

Commit 6307a0b

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 1375b11 + 0c2e783 commit 6307a0b

File tree

7 files changed

+124
-1
lines changed

7 files changed

+124
-1
lines changed

src/unix/bsd/apple/mod.rs

+24
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ s! {
144144
pub si_uid: ::uid_t,
145145
pub si_status: ::c_int,
146146
pub si_addr: *mut ::c_void,
147+
//Requires it to be union for tests
148+
//pub si_value: ::sigval,
147149
_pad: [usize; 9],
148150
}
149151

@@ -614,6 +616,28 @@ s_no_extra_traits!{
614616
}
615617
}
616618

619+
impl siginfo_t {
620+
pub unsafe fn si_addr(&self) -> *mut ::c_void {
621+
self.si_addr
622+
}
623+
624+
pub unsafe fn si_value(&self) -> ::sigval {
625+
#[repr(C)]
626+
struct siginfo_timer {
627+
_si_signo: ::c_int,
628+
_si_errno: ::c_int,
629+
_si_code: ::c_int,
630+
_si_pid: ::pid_t,
631+
_si_uid: ::uid_t,
632+
_si_status: ::c_int,
633+
_si_addr: *mut ::c_void,
634+
si_value: ::sigval,
635+
}
636+
637+
(*(self as *const siginfo_t as *const siginfo_timer)).si_value
638+
}
639+
}
640+
617641
cfg_if! {
618642
if #[cfg(libc_union)] {
619643
s_no_extra_traits! {

src/unix/bsd/freebsdlike/mod.rs

+13-1
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,9 @@ 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+
_pad1: ::c_long,
83+
_pad2: [::c_int; 7],
7284
}
7385

7486
pub struct sigaction {

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

+16
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,22 @@ 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+
#[repr(C)]
15+
struct siginfo_timer {
16+
_si_signo: ::c_int,
17+
_si_errno: ::c_int,
18+
_si_code: ::c_int,
19+
__pad1: ::c_int,
20+
_pid: ::pid_t,
21+
_uid: ::uid_t,
22+
value: ::sigval,
23+
}
24+
(*(self as *const siginfo_t as *const siginfo_timer)).value
25+
}
26+
}
27+
1228
s! {
1329
pub struct aiocb {
1430
pub aio_offset: ::off_t,

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

+15
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,21 @@ s! {
308308
}
309309
}
310310

311+
impl siginfo_t {
312+
pub unsafe fn si_value(&self) -> ::sigval {
313+
#[repr(C)]
314+
struct siginfo_timer {
315+
_si_signo: ::c_int,
316+
_si_errno: ::c_int,
317+
_si_code: ::c_int,
318+
_pid: ::pid_t,
319+
_uid: ::uid_t,
320+
value: ::sigval,
321+
}
322+
(*(self as *const siginfo_t as *const siginfo_timer)).value
323+
}
324+
}
325+
311326
s_no_extra_traits! {
312327
pub struct dirent {
313328
pub d_fileno: ::ino_t,

src/unix/linux_like/android/mod.rs

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

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

+13
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,19 @@ 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+
#[repr(C)]
199+
struct siginfo_timer {
200+
_si_signo: ::c_int,
201+
_si_errno: ::c_int,
202+
_si_code: ::c_int,
203+
_si_tid: ::c_int,
204+
_si_overrun: ::c_int,
205+
si_sigval: ::sigval,
206+
}
207+
(*(self as *const siginfo_t as *const siginfo_timer)).si_sigval
208+
}
196209
}
197210

198211
s_no_extra_traits! {

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

+28
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,

0 commit comments

Comments
 (0)