From e1ff5d61e95a4a64b60cbb158986045ebb916149 Mon Sep 17 00:00:00 2001 From: Andy Caldwell Date: Mon, 25 Nov 2024 01:40:50 -0500 Subject: [PATCH] musl: Unify definitions of `siginfo_t` Musl provides a single definition for `siginfo_t` [1] with the order of `si_code` and `si_errno` controlled by `__SI_SWAP_ERRNO_CODE`. This is only set on mips (both 32- and 64-bit). [1]: https://github.com/kraj/musl/blob/ffb23aef7b5339b8c3234f4c6a93c488dc873919/include/signal.h#L99-L147 [ extracted from "Remove all redundant definitions in musl backend", add context to the commit message - Trevor ] --- src/unix/linux_like/linux/musl/b32/arm/mod.rs | 8 -------- src/unix/linux_like/linux/musl/b32/hexagon.rs | 8 -------- .../linux_like/linux/musl/b32/mips/mod.rs | 8 -------- src/unix/linux_like/linux/musl/b32/powerpc.rs | 8 -------- .../linux_like/linux/musl/b32/riscv32/mod.rs | 15 -------------- src/unix/linux_like/linux/musl/b32/x86/mod.rs | 8 -------- src/unix/linux_like/linux/musl/b64/mod.rs | 8 -------- .../linux_like/linux/musl/b64/riscv64/mod.rs | 15 -------------- src/unix/linux_like/linux/musl/mod.rs | 20 +++++++++++++++++++ 9 files changed, 20 insertions(+), 78 deletions(-) diff --git a/src/unix/linux_like/linux/musl/b32/arm/mod.rs b/src/unix/linux_like/linux/musl/b32/arm/mod.rs index 4149b7ebb1534..0d291ac0eac09 100644 --- a/src/unix/linux_like/linux/musl/b32/arm/mod.rs +++ b/src/unix/linux_like/linux/musl/b32/arm/mod.rs @@ -112,14 +112,6 @@ s! { pub f_spare: [::c_ulong; 4], } - pub struct siginfo_t { - pub si_signo: ::c_int, - pub si_errno: ::c_int, - pub si_code: ::c_int, - pub _pad: [::c_int; 29], - _align: [usize; 0], - } - pub struct statfs64 { pub f_type: ::c_ulong, pub f_bsize: ::c_ulong, diff --git a/src/unix/linux_like/linux/musl/b32/hexagon.rs b/src/unix/linux_like/linux/musl/b32/hexagon.rs index 4fc29f4f0df05..1802356339d27 100644 --- a/src/unix/linux_like/linux/musl/b32/hexagon.rs +++ b/src/unix/linux_like/linux/musl/b32/hexagon.rs @@ -90,14 +90,6 @@ s! { pub f_spare: [::c_ulong; 4], } - pub struct siginfo_t { - pub si_signo: ::c_int, - pub si_errno: ::c_int, - pub si_code: ::c_int, - pub _pad: [::c_int; 29], - _align: [usize; 0], - } - pub struct statfs64 { pub f_type: ::c_ulong, pub f_bsize: ::c_ulong, diff --git a/src/unix/linux_like/linux/musl/b32/mips/mod.rs b/src/unix/linux_like/linux/musl/b32/mips/mod.rs index 219c96b0d9fd9..04e0126cc66c7 100644 --- a/src/unix/linux_like/linux/musl/b32/mips/mod.rs +++ b/src/unix/linux_like/linux/musl/b32/mips/mod.rs @@ -120,14 +120,6 @@ s! { pub f_spare: [::c_ulong; 5], } - pub struct siginfo_t { - pub si_signo: ::c_int, - pub si_code: ::c_int, - pub si_errno: ::c_int, - pub _pad: [::c_int; 29], - _align: [usize; 0], - } - pub struct statfs64 { pub f_type: ::c_ulong, pub f_bsize: ::c_ulong, diff --git a/src/unix/linux_like/linux/musl/b32/powerpc.rs b/src/unix/linux_like/linux/musl/b32/powerpc.rs index 80eb9f57c2622..cbb7a7b0e277f 100644 --- a/src/unix/linux_like/linux/musl/b32/powerpc.rs +++ b/src/unix/linux_like/linux/musl/b32/powerpc.rs @@ -112,14 +112,6 @@ s! { pub f_spare: [::c_ulong; 4], } - pub struct siginfo_t { - pub si_signo: ::c_int, - pub si_errno: ::c_int, - pub si_code: ::c_int, - pub _pad: [::c_int; 29], - _align: [usize; 0], - } - pub struct statfs64 { pub f_type: ::c_ulong, pub f_bsize: ::c_ulong, diff --git a/src/unix/linux_like/linux/musl/b32/riscv32/mod.rs b/src/unix/linux_like/linux/musl/b32/riscv32/mod.rs index 13a099c18e26c..fe5b02acd2796 100644 --- a/src/unix/linux_like/linux/musl/b32/riscv32/mod.rs +++ b/src/unix/linux_like/linux/musl/b32/riscv32/mod.rs @@ -113,21 +113,6 @@ s! { __f_spare: [::c_int; 6], } - pub struct siginfo_t { - pub si_signo: ::c_int, - pub si_errno: ::c_int, - pub si_code: ::c_int, - #[doc(hidden)] - #[deprecated( - since = "0.2.54", - note = "Please leave a comment on \ - https://github.com/rust-lang/libc/pull/1316 if you're using \ - this field" - )] - pub _pad: [::c_int; 29], - _align: [u64; 0], - } - pub struct stack_t { pub ss_sp: *mut ::c_void, pub ss_flags: ::c_int, diff --git a/src/unix/linux_like/linux/musl/b32/x86/mod.rs b/src/unix/linux_like/linux/musl/b32/x86/mod.rs index aeeb6d118599c..f448f536bbbee 100644 --- a/src/unix/linux_like/linux/musl/b32/x86/mod.rs +++ b/src/unix/linux_like/linux/musl/b32/x86/mod.rs @@ -116,14 +116,6 @@ s! { pub f_spare: [::c_ulong; 4], } - pub struct siginfo_t { - pub si_signo: ::c_int, - pub si_errno: ::c_int, - pub si_code: ::c_int, - pub _pad: [::c_int; 29], - _align: [usize; 0], - } - pub struct statfs64 { pub f_type: ::c_ulong, pub f_bsize: ::c_ulong, diff --git a/src/unix/linux_like/linux/musl/b64/mod.rs b/src/unix/linux_like/linux/musl/b64/mod.rs index a8a1fb32024fe..ff58b7003cbd5 100644 --- a/src/unix/linux_like/linux/musl/b64/mod.rs +++ b/src/unix/linux_like/linux/musl/b64/mod.rs @@ -120,14 +120,6 @@ s! { pub struct sem_t { __val: [::c_int; 8], } - - pub struct siginfo_t { - pub si_signo: ::c_int, - pub si_errno: ::c_int, - pub si_code: ::c_int, - pub _pad: [::c_int; 29], - _align: [usize; 0], - } } pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56; diff --git a/src/unix/linux_like/linux/musl/b64/riscv64/mod.rs b/src/unix/linux_like/linux/musl/b64/riscv64/mod.rs index a2b823c1adf95..1af905701eaf8 100644 --- a/src/unix/linux_like/linux/musl/b64/riscv64/mod.rs +++ b/src/unix/linux_like/linux/musl/b64/riscv64/mod.rs @@ -119,21 +119,6 @@ s! { pub __f_spare: [::c_int; 6], } - pub struct siginfo_t { - pub si_signo: ::c_int, - pub si_errno: ::c_int, - pub si_code: ::c_int, - #[doc(hidden)] - #[deprecated( - since = "0.2.54", - note = "Please leave a comment on \ - https://github.com/rust-lang/libc/pull/1316 if you're using \ - this field" - )] - pub _pad: [::c_int; 29], - _align: [u64; 0], - } - pub struct stack_t { pub ss_sp: *mut ::c_void, pub ss_flags: ::c_int, diff --git a/src/unix/linux_like/linux/musl/mod.rs b/src/unix/linux_like/linux/musl/mod.rs index ec295aa57deb3..c21fdaf04efc4 100644 --- a/src/unix/linux_like/linux/musl/mod.rs +++ b/src/unix/linux_like/linux/musl/mod.rs @@ -144,6 +144,26 @@ s! { pub sa_restorer: ::Option, } + // `mips*` targets swap the `s_errno` and `s_code` fields otherwise this struct is + // target-agnostic (see https://www.openwall.com/lists/musl/2016/01/27/1/2) + pub struct siginfo_t { + pub si_signo: ::c_int, + #[cfg(not(target_arch = "mips"))] + pub si_errno: ::c_int, + pub si_code: ::c_int, + #[cfg(target_arch = "mips")] + pub si_errno: ::c_int, + #[doc(hidden)] + #[deprecated( + since = "0.2.54", + note = "Please leave a comment on \ + https://github.com/rust-lang/libc/pull/1316 if you're using \ + this field" + )] + pub _pad: [::c_int; 29], + _align: [usize; 0], + } + pub struct statvfs { pub f_bsize: ::c_ulong, pub f_frsize: ::c_ulong,