summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Triplett <josh@joshtriplett.org>2020-08-09 15:10:20 -0700
committerJosh Triplett <josh@joshtriplett.org>2020-08-10 01:24:22 -0700
commit13d0cdb68f839a2c13b739f9fe3ed87ebc86c049 (patch)
treed5fded9407ebf3f188821c503d79900c614396a8
parentab3c229140cc6a609c52fd732ea76bf69f9a5855 (diff)
downloadrust-libc-13d0cdb68f839a2c13b739f9fe3ed87ebc86c049.tar.gz
Expose si_pid, si_uid, and si_status from siginfo_t as functions
On Linux, siginfo_t cannot expose these fields directly due to https://github.com/rust-lang/libc/issues/716 , so expose them as functions, just like si_addr and si_value. In order to get alignment correct on both 32-bit and 64-bit architectures, define an sifields union that includes a pointer field, to ensure that it has the same alignment as a pointer.
-rw-r--r--src/unix/bsd/apple/mod.rs8
-rw-r--r--src/unix/bsd/freebsdlike/mod.rs8
-rw-r--r--src/unix/haiku/mod.rs14
-rw-r--r--src/unix/linux_like/linux/gnu/mod.rs49
-rwxr-xr-xsrc/vxworks/mod.rs18
5 files changed, 97 insertions, 0 deletions
diff --git a/src/unix/bsd/apple/mod.rs b/src/unix/bsd/apple/mod.rs
index f130974728..f56ee02b06 100644
--- a/src/unix/bsd/apple/mod.rs
+++ b/src/unix/bsd/apple/mod.rs
@@ -680,6 +680,14 @@ impl siginfo_t {
(*(self as *const siginfo_t as *const siginfo_timer)).si_value
}
+
+ pub unsafe fn si_pid(&self) -> ::pid_t {
+ self.si_pid
+ }
+
+ pub unsafe fn si_uid(&self) -> ::uid_t {
+ self.si_uid
+ }
}
cfg_if! {
diff --git a/src/unix/bsd/freebsdlike/mod.rs b/src/unix/bsd/freebsdlike/mod.rs
index b75c1a8e8e..e9f70579ea 100644
--- a/src/unix/bsd/freebsdlike/mod.rs
+++ b/src/unix/bsd/freebsdlike/mod.rs
@@ -31,6 +31,14 @@ impl siginfo_t {
pub unsafe fn si_value(&self) -> ::sigval {
self.si_value
}
+
+ pub unsafe fn si_pid(&self) -> ::pid_t {
+ self.si_pid
+ }
+
+ pub unsafe fn si_uid(&self) -> ::uid_t {
+ self.si_uid
+ }
}
s! {
diff --git a/src/unix/haiku/mod.rs b/src/unix/haiku/mod.rs
index 27f88f155f..adcac2e5ae 100644
--- a/src/unix/haiku/mod.rs
+++ b/src/unix/haiku/mod.rs
@@ -38,6 +38,20 @@ impl ::Clone for timezone {
}
}
+impl siginfo_t {
+ pub unsafe fn si_addr(&self) -> *mut ::c_void {
+ self.si_addr
+ }
+
+ pub unsafe fn si_pid(&self) -> ::pid_t {
+ self.si_pid
+ }
+
+ pub unsafe fn si_uid(&self) -> ::uid_t {
+ self.si_uid
+ }
+}
+
s! {
pub struct in_addr {
pub s_addr: ::in_addr_t,
diff --git a/src/unix/linux_like/linux/gnu/mod.rs b/src/unix/linux_like/linux/gnu/mod.rs
index 44796c3e3d..982916a22e 100644
--- a/src/unix/linux_like/linux/gnu/mod.rs
+++ b/src/unix/linux_like/linux/gnu/mod.rs
@@ -313,6 +313,55 @@ impl siginfo_t {
}
}
+cfg_if! {
+ if #[cfg(libc_union)] {
+ // Internal, for casts to access union fields
+ #[repr(C)]
+ #[derive(Copy,Clone)]
+ struct sifields_sigchld {
+ si_pid: ::pid_t,
+ si_uid: ::uid_t,
+ si_status: ::c_int,
+ }
+
+ // Internal, for casts to access union fields
+ #[repr(C)]
+ union sifields {
+ _align_pointer: *mut ::c_void,
+ sigchld: sifields_sigchld,
+ }
+
+ // Internal, for casts to access union fields. Note that some variants
+ // of sifields start with a pointer, which makes the alignment of
+ // sifields vary on 32-bit and 64-bit architectures.
+ #[repr(C)]
+ struct siginfo_f {
+ _si_signo: ::c_int,
+ _si_errno: ::c_int,
+ _si_code: ::c_int,
+ sifields: sifields,
+ }
+
+ impl siginfo_t {
+ unsafe fn sifields(&self) -> &sifields {
+ &(*(self as *const siginfo_t as *const siginfo_f)).sifields
+ }
+
+ pub unsafe fn si_pid(&self) -> ::pid_t {
+ self.sifields().sigchld.si_pid
+ }
+
+ pub unsafe fn si_uid(&self) -> ::uid_t {
+ self.sifields().sigchld.si_uid
+ }
+
+ pub unsafe fn si_status(&self) -> ::c_int {
+ self.sifields().sigchld.si_status
+ }
+ }
+ }
+}
+
s_no_extra_traits! {
pub struct utmpx {
pub ut_type: ::c_short,
diff --git a/src/vxworks/mod.rs b/src/vxworks/mod.rs
index 2ca38d5e24..2a3ac7ff78 100755
--- a/src/vxworks/mod.rs
+++ b/src/vxworks/mod.rs
@@ -112,6 +112,24 @@ impl ::Clone for _Vx_semaphore {
}
}
+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
+ }
+
+ pub unsafe fn si_pid(&self) -> ::pid_t {
+ self.si_pid
+ }
+
+ pub unsafe fn si_uid(&self) -> ::uid_t {
+ self.si_uid
+ }
+}
+
s! {
// b_pthread_condattr_t.h
pub struct pthread_condattr_t {