Skip to content

Commit

Permalink
Auto merge of #1421 - DoumanAsh:expose_posix_timer_value, r=gnzlbg
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Jul 9, 2019
2 parents 1375b11 + 0c2e783 commit 6307a0b
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 1 deletion.
24 changes: 24 additions & 0 deletions src/unix/bsd/apple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ s! {
pub si_uid: ::uid_t,
pub si_status: ::c_int,
pub si_addr: *mut ::c_void,
//Requires it to be union for tests
//pub si_value: ::sigval,
_pad: [usize; 9],
}

Expand Down Expand Up @@ -614,6 +616,28 @@ s_no_extra_traits!{
}
}

impl siginfo_t {
pub unsafe fn si_addr(&self) -> *mut ::c_void {
self.si_addr
}

pub unsafe fn si_value(&self) -> ::sigval {
#[repr(C)]
struct siginfo_timer {
_si_signo: ::c_int,
_si_errno: ::c_int,
_si_code: ::c_int,
_si_pid: ::pid_t,
_si_uid: ::uid_t,
_si_status: ::c_int,
_si_addr: *mut ::c_void,
si_value: ::sigval,
}

(*(self as *const siginfo_t as *const siginfo_timer)).si_value
}
}

cfg_if! {
if #[cfg(libc_union)] {
s_no_extra_traits! {
Expand Down
14 changes: 13 additions & 1 deletion src/unix/bsd/freebsdlike/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ impl ::Clone for timezone {
fn clone(&self) -> timezone { *self }
}

impl siginfo_t {
pub unsafe fn si_addr(&self) -> *mut ::c_void {
self.si_addr
}

pub unsafe fn si_value(&self) -> ::sigval {
self.si_value
}
}

s! {
pub struct in_addr {
pub s_addr: ::in_addr_t,
Expand Down Expand Up @@ -68,7 +78,9 @@ s! {
pub si_uid: ::uid_t,
pub si_status: ::c_int,
pub si_addr: *mut ::c_void,
_pad: [::c_int; 12],
pub si_value: ::sigval,
_pad1: ::c_long,
_pad2: [::c_int; 7],
}

pub struct sigaction {
Expand Down
16 changes: 16 additions & 0 deletions src/unix/bsd/netbsdlike/netbsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@ pub type mqd_t = ::c_int;
type __pthread_spin_t = __cpu_simple_lock_nv_t;
pub type vm_size_t = ::uintptr_t;

impl siginfo_t {
pub unsafe fn si_value(&self) -> ::sigval {
#[repr(C)]
struct siginfo_timer {
_si_signo: ::c_int,
_si_errno: ::c_int,
_si_code: ::c_int,
__pad1: ::c_int,
_pid: ::pid_t,
_uid: ::uid_t,
value: ::sigval,
}
(*(self as *const siginfo_t as *const siginfo_timer)).value
}
}

s! {
pub struct aiocb {
pub aio_offset: ::off_t,
Expand Down
15 changes: 15 additions & 0 deletions src/unix/bsd/netbsdlike/openbsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,21 @@ s! {
}
}

impl siginfo_t {
pub unsafe fn si_value(&self) -> ::sigval {
#[repr(C)]
struct siginfo_timer {
_si_signo: ::c_int,
_si_errno: ::c_int,
_si_code: ::c_int,
_pid: ::pid_t,
_uid: ::uid_t,
value: ::sigval,
}
(*(self as *const siginfo_t as *const siginfo_timer)).value
}
}

s_no_extra_traits! {
pub struct dirent {
pub d_fileno: ::ino_t,
Expand Down
15 changes: 15 additions & 0 deletions src/unix/linux_like/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2192,3 +2192,18 @@ cfg_if! {
// Unknown target_pointer_width
}
}

impl siginfo_t {
pub unsafe fn si_value(&self) -> ::sigval {
#[repr(C)]
struct siginfo_timer {
_si_signo: ::c_int,
_si_errno: ::c_int,
_si_code: ::c_int,
_si_tid: ::c_int,
_si_overrun: ::c_int,
si_sigval: ::sigval,
}
(*(self as *const siginfo_t as *const siginfo_timer)).si_sigval
}
}
13 changes: 13 additions & 0 deletions src/unix/linux_like/linux/gnu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,19 @@ impl siginfo_t {
}
(*(self as *const siginfo_t as *const siginfo_sigfault)).si_addr
}

pub unsafe fn si_value(&self) -> ::sigval {
#[repr(C)]
struct siginfo_timer {
_si_signo: ::c_int,
_si_errno: ::c_int,
_si_code: ::c_int,
_si_tid: ::c_int,
_si_overrun: ::c_int,
si_sigval: ::sigval,
}
(*(self as *const siginfo_t as *const siginfo_timer)).si_sigval
}
}

s_no_extra_traits! {
Expand Down
28 changes: 28 additions & 0 deletions src/unix/linux_like/linux/musl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,34 @@ pub type fsblkcnt_t = ::c_ulonglong;
pub type fsfilcnt_t = ::c_ulonglong;
pub type rlim_t = ::c_ulonglong;

impl siginfo_t {
pub unsafe fn si_addr(&self) -> *mut ::c_void {
#[repr(C)]
struct siginfo_sigfault {
_si_signo: ::c_int,
_si_errno: ::c_int,
_si_code: ::c_int,
si_addr: *mut ::c_void
}

(*(self as *const siginfo_t as *const siginfo_sigfault)).si_addr
}

pub unsafe fn si_value(&self) -> ::sigval {
#[repr(C)]
struct siginfo_si_value {
_si_signo: ::c_int,
_si_errno: ::c_int,
_si_code: ::c_int,
_si_timerid: ::c_int,
_si_overrun: ::c_int,
si_value: ::sigval,
}

(*(self as *const siginfo_t as *const siginfo_si_value)).si_value
}
}

s! {
pub struct aiocb {
pub aio_fildes: ::c_int,
Expand Down

0 comments on commit 6307a0b

Please sign in to comment.