Skip to content

Commit

Permalink
Expose si_addr on siginfo_t. Refs rust-lang#716
Browse files Browse the repository at this point in the history
  • Loading branch information
alex committed Apr 12, 2019
1 parent 363ba93 commit 6534c7d
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 11 deletions.
30 changes: 30 additions & 0 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ macro_rules! s_no_extra_traits {
($($(#[$attr:meta])* pub $t:ident $i:ident { $($field:tt)* })*) => ($(
s_no_extra_traits!(it: $(#[$attr])* pub $t $i { $($field)* });
)*);
($($(#[$attr:meta])* $t:ident $i:ident { $($field:tt)* })*) => ($(
s_no_extra_traits!(it: $(#[$attr])* $t $i { $($field)* });
)*);
(it: $(#[$attr:meta])* pub union $i:ident { $($field:tt)* }) => (
cfg_if! {
if #[cfg(libc_union)] {
Expand All @@ -105,6 +108,22 @@ macro_rules! s_no_extra_traits {
}
}
);
(it: $(#[$attr:meta])* union $i:ident { $($field:tt)* }) => (
cfg_if! {
if #[cfg(libc_union)] {
__item! {
#[repr(C)]
$(#[$attr])*
union $i { $($field)* }
}

impl ::Copy for $i {}
impl ::Clone for $i {
fn clone(&self) -> $i { *self }
}
}
}
);
(it: $(#[$attr:meta])* pub struct $i:ident { $($field:tt)* }) => (
__item! {
#[repr(C)]
Expand All @@ -116,6 +135,17 @@ macro_rules! s_no_extra_traits {
fn clone(&self) -> $i { *self }
}
);
(it: $(#[$attr:meta])* struct $i:ident { $($field:tt)* }) => (
__item! {
#[repr(C)]
$(#[$attr])*
struct $i { $($field)* }
}
impl ::Copy for $i {}
impl ::Clone for $i {
fn clone(&self) -> $i { *self }
}
);
}

#[allow(unused_macros)]
Expand Down
93 changes: 82 additions & 11 deletions src/unix/notbsd/linux/other/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,87 @@
pub type __priority_which_t = ::c_uint;

s_no_extra_traits! {
struct addr_bnd_t {
lower: *mut ::c_void,
upper: *mut ::c_void,
}

union sigfault_t_anonymous_union {
addr_bnd: addr_bnd_t,
pkey: u32,
}

struct sigfault_t {
addr: *mut ::c_void,
#[cfg(target_arch = "sparc")]
trapno: ::c_int,
addr_lsb: ::c_short,
anonymous_union: sigfault_t_anonymous_union,
}

union sifields_t {
_pad: [::c_int; 29],
sigfault: sigfault_t,
}
}

s_no_extra_traits! {
pub struct siginfo_t {
pub si_signo: ::c_int,
pub si_errno: ::c_int,
pub si_code: ::c_int,
sifields: sifields_t,
#[cfg(target_arch = "x86_64")]
_align: [u64; 0],
#[cfg(not(target_arch = "x86_64"))]
_align: [usize; 0],
}
}

impl ::fmt::Debug for sigfault_t_anonymous_union {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
// TODO: no idea how to tell which of the members is used
f.debug_struct("sigfault_t_anonymous_union")
.finish()
}
}

impl ::fmt::Debug for sigfault_t {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
// TODO: include trapno on Sparc
f.debug_struct("sigfault_t")
.field("addr", &self.addr)
.field("addr_lsb", &self.addr_lsb)
.field("anonymous_union", &self.anonymous_union)
.finish()
}
}

impl ::fmt::Debug for sifields_t {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
// No way to print anything more detailed without the discriminant from
// siginfo_t
f.debug_struct("sifields_t").finish()
}
}

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

impl ::fmt::Debug for siginfo_t {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
// TODO: include fields from sifields
f.debug_struct("siginfo_t")
.field("si_signo", &self.si_signo)
.field("si_errno", &self.si_errno)
.field("si_code", &self.si_code)
.finish()
}
}

s! {
pub struct aiocb {
pub aio_fildes: ::c_int,
Expand Down Expand Up @@ -44,17 +126,6 @@ s! {
pub ss_size: ::size_t
}

pub struct siginfo_t {
pub si_signo: ::c_int,
pub si_errno: ::c_int,
pub si_code: ::c_int,
pub _pad: [::c_int; 29],
#[cfg(target_arch = "x86_64")]
_align: [u64; 0],
#[cfg(not(target_arch = "x86_64"))]
_align: [usize; 0],
}

pub struct glob64_t {
pub gl_pathc: ::size_t,
pub gl_pathv: *mut *mut ::c_char,
Expand Down

0 comments on commit 6534c7d

Please sign in to comment.