Skip to content

Commit 7b0b5f8

Browse files
committed
Auto merge of #1955 - gremlin:update-musl-siginfo, r=JohnTitor
Bring the MUSL version of siginfo_t up-to-date. **Background** As far as I can tell, the [current MUSL version of `siginfo_t`](https://git.musl-libc.org/cgit/musl/tree/include/signal.h#n97) includes fields like [`si_pid`](https://git.musl-libc.org/cgit/musl/tree/include/signal.h#n108) and [`si_uid`](https://git.musl-libc.org/cgit/musl/tree/include/signal.h#n109). **Change** This update unifies `siginfo_t` support between GNU and MUSL.
2 parents 80b3a51 + e90e708 commit 7b0b5f8

File tree

1 file changed

+62
-2
lines changed
  • src/unix/linux_like/linux/musl

1 file changed

+62
-2
lines changed

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

+62-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ impl siginfo_t {
2424
_si_code: ::c_int,
2525
si_addr: *mut ::c_void,
2626
}
27-
2827
(*(self as *const siginfo_t as *const siginfo_sigfault)).si_addr
2928
}
3029

@@ -38,11 +37,72 @@ impl siginfo_t {
3837
_si_overrun: ::c_int,
3938
si_value: ::sigval,
4039
}
41-
4240
(*(self as *const siginfo_t as *const siginfo_si_value)).si_value
4341
}
4442
}
4543

44+
cfg_if! {
45+
if #[cfg(libc_union)] {
46+
// Internal, for casts to access union fields
47+
#[repr(C)]
48+
struct sifields_sigchld {
49+
si_pid: ::pid_t,
50+
si_uid: ::uid_t,
51+
si_status: ::c_int,
52+
si_utime: ::c_long,
53+
si_stime: ::c_long,
54+
}
55+
impl ::Copy for sifields_sigchld {}
56+
impl ::Clone for sifields_sigchld {
57+
fn clone(&self) -> sifields_sigchld {
58+
*self
59+
}
60+
}
61+
62+
// Internal, for casts to access union fields
63+
#[repr(C)]
64+
union sifields {
65+
_align_pointer: *mut ::c_void,
66+
sigchld: sifields_sigchld,
67+
}
68+
69+
// Internal, for casts to access union fields. Note that some variants
70+
// of sifields start with a pointer, which makes the alignment of
71+
// sifields vary on 32-bit and 64-bit architectures.
72+
#[repr(C)]
73+
struct siginfo_f {
74+
_siginfo_base: [::c_int; 3],
75+
sifields: sifields,
76+
}
77+
78+
impl siginfo_t {
79+
unsafe fn sifields(&self) -> &sifields {
80+
&(*(self as *const siginfo_t as *const siginfo_f)).sifields
81+
}
82+
83+
pub unsafe fn si_pid(&self) -> ::pid_t {
84+
self.sifields().sigchld.si_pid
85+
}
86+
87+
pub unsafe fn si_uid(&self) -> ::uid_t {
88+
self.sifields().sigchld.si_uid
89+
}
90+
91+
pub unsafe fn si_status(&self) -> ::c_int {
92+
self.sifields().sigchld.si_status
93+
}
94+
95+
pub unsafe fn si_utime(&self) -> ::c_long {
96+
self.sifields().sigchld.si_utime
97+
}
98+
99+
pub unsafe fn si_stime(&self) -> ::c_long {
100+
self.sifields().sigchld.si_stime
101+
}
102+
}
103+
}
104+
}
105+
46106
s! {
47107
pub struct aiocb {
48108
pub aio_fildes: ::c_int,

0 commit comments

Comments
 (0)