From 24a8e7e9959aaccac328219048201f59e71fc9fe Mon Sep 17 00:00:00 2001 From: Taylor Cramer Date: Tue, 26 Nov 2024 10:58:04 -0800 Subject: [PATCH 1/3] Revert "Fix a few other array size hacks" This reverts commit d63be8b69b0736753213f5d933767866a5801ee7. --- src/unix/bsd/freebsdlike/freebsd/mod.rs | 9 ++------- src/unix/bsd/netbsdlike/netbsd/mod.rs | 2 +- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/unix/bsd/freebsdlike/freebsd/mod.rs b/src/unix/bsd/freebsdlike/freebsd/mod.rs index 43c2d0dfbe7f1..b6b750e0e8a52 100644 --- a/src/unix/bsd/freebsdlike/freebsd/mod.rs +++ b/src/unix/bsd/freebsdlike/freebsd/mod.rs @@ -1144,7 +1144,7 @@ s! { pub sinfo_assoc_id: ::sctp_assoc_t, pub sinfo_keynumber: u16, pub sinfo_keynumber_valid: u16, - pub __reserve_pad: [u8; SCTP_ALIGN_RESV_PAD], + pub __reserve_pad: [[u8; 23]; 4], } pub struct sctp_extrcvinfo { @@ -1164,7 +1164,7 @@ s! { pub serinfo_next_ppid: u32, pub sinfo_keynumber: u16, pub sinfo_keynumber_valid: u16, - pub __reserve_pad: [u8; SCTP_ALIGN_RESV_PAD_SHORT], + pub __reserve_pad: [[u8; 19]; 4], } pub struct sctp_sndinfo { @@ -4865,11 +4865,6 @@ pub const SCTP_ASSOC_RESET_FAILED: ::c_int = 0x0008; pub const SCTP_STREAM_CHANGE_DENIED: ::c_int = 0x0004; pub const SCTP_STREAM_CHANGE_FAILED: ::c_int = 0x0008; -// sctp_uio.h - -pub const SCTP_ALIGN_RESV_PAD: usize = 92; -pub const SCTP_ALIGN_RESV_PAD_SHORT: usize = 76; - pub const KENV_DUMP_LOADER: ::c_int = 4; pub const KENV_DUMP_STATIC: ::c_int = 5; diff --git a/src/unix/bsd/netbsdlike/netbsd/mod.rs b/src/unix/bsd/netbsdlike/netbsd/mod.rs index 84358eb06dc81..8f3e7bbedcb50 100644 --- a/src/unix/bsd/netbsdlike/netbsd/mod.rs +++ b/src/unix/bsd/netbsdlike/netbsd/mod.rs @@ -520,7 +520,7 @@ s! { pub struct accept_filter_arg { pub af_name: [::c_char; 16], - pub af_arg: [::c_char; 256 - 16], + af_arg: [[::c_char; 10]; 24], } pub struct ki_sigset_t { From 4dc6a1c20e9f024339080d602332209b620c560b Mon Sep 17 00:00:00 2001 From: Taylor Cramer Date: Tue, 26 Nov 2024 11:00:08 -0800 Subject: [PATCH 2/3] Revert "Remove array size hacks for Rust < 1.47" This reverts commit 27ee6fe02ca0848b2af3cd747536264e4c7b697d. These array structure changes were breaking changes to the public API and should not have landed without a major version bump. --- libc-test/build.rs | 9 ++++++++- src/unix/bsd/apple/mod.rs | 4 +++- src/unix/bsd/freebsdlike/dragonfly/mod.rs | 2 +- src/unix/bsd/freebsdlike/freebsd/freebsd11/mod.rs | 2 +- src/unix/bsd/freebsdlike/freebsd/freebsd12/mod.rs | 2 +- src/unix/bsd/freebsdlike/freebsd/freebsd13/mod.rs | 2 +- src/unix/bsd/freebsdlike/freebsd/freebsd14/mod.rs | 2 +- src/unix/bsd/freebsdlike/freebsd/freebsd15/mod.rs | 2 +- src/unix/bsd/freebsdlike/freebsd/mod.rs | 2 +- src/unix/bsd/freebsdlike/mod.rs | 2 +- src/unix/bsd/netbsdlike/netbsd/mod.rs | 2 +- src/unix/linux_like/android/b64/aarch64/mod.rs | 4 +++- src/unix/linux_like/android/mod.rs | 2 +- src/unix/linux_like/linux/gnu/b64/aarch64/mod.rs | 4 +++- src/unix/linux_like/linux/musl/b64/aarch64/mod.rs | 2 +- 15 files changed, 28 insertions(+), 15 deletions(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index 8a353e5d4a5fb..31a5e390e1831 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -400,7 +400,8 @@ fn test_apple(target: &str) { // FIXME: the array size has been changed since macOS 10.15 ([8] -> [7]). ("statfs", "f_reserved") => true, ("__darwin_arm_neon_state64", "__v") => true, - + // MAXPATHLEN is too big for auto-derive traits on arrays. + ("vnode_info_path", "vip_path") => true, ("ifreq", "ifr_ifru") => true, ("in6_ifreq", "ifr_ifru") => true, ("ifkpi", "ifk_data") => true, @@ -2763,6 +2764,8 @@ fn test_freebsd(target: &str) { ("umutex", "m_owner") => true, // c_has_waiters field is a volatile int32_t ("ucond", "c_has_waiters") => true, + // is PATH_MAX long but tests can't accept multi array as equivalent. + ("kinfo_vmentry", "kve_path") => true, // a_un field is a union ("Elf32_Auxinfo", "a_un") => true, @@ -2791,6 +2794,10 @@ fn test_freebsd(target: &str) { // Anonymous type. ("filestat", "next") => true, + // We ignore this field because we needed to use a hack in order to make rust 1.19 + // happy... + ("kinfo_proc", "ki_sparestrings") => true, + // `__sem_base` is a private struct field ("semid_ds", "__sem_base") => true, diff --git a/src/unix/bsd/apple/mod.rs b/src/unix/bsd/apple/mod.rs index 057bdfe7432e3..34bd285666610 100644 --- a/src/unix/bsd/apple/mod.rs +++ b/src/unix/bsd/apple/mod.rs @@ -939,7 +939,9 @@ s! { pub struct vnode_info_path { pub vip_vi: vnode_info, - pub vip_path: [::c_char; ::MAXPATHLEN as usize], + // Normally it's `vip_path: [::c_char; MAXPATHLEN]` but because libc supports an old rustc + // version, we go around this limitation like this. + pub vip_path: [[::c_char; 32]; 32], } pub struct proc_vnodepathinfo { diff --git a/src/unix/bsd/freebsdlike/dragonfly/mod.rs b/src/unix/bsd/freebsdlike/dragonfly/mod.rs index 88292afdb1208..9bf25b335cc7e 100644 --- a/src/unix/bsd/freebsdlike/dragonfly/mod.rs +++ b/src/unix/bsd/freebsdlike/dragonfly/mod.rs @@ -517,7 +517,7 @@ s_no_extra_traits! { pub mc_ownedfp: ::c_uint, __reserved: ::c_uint, __unused: [::c_uint; 8], - pub mc_fpregs: [::c_uint; 256], + pub mc_fpregs: [[::c_uint; 8]; 32], } pub struct ucontext_t { diff --git a/src/unix/bsd/freebsdlike/freebsd/freebsd11/mod.rs b/src/unix/bsd/freebsdlike/freebsd/freebsd11/mod.rs index cb62ee608a8b4..f62b77ba8e3c2 100644 --- a/src/unix/bsd/freebsdlike/freebsd/freebsd11/mod.rs +++ b/src/unix/bsd/freebsdlike/freebsd/freebsd11/mod.rs @@ -166,7 +166,7 @@ s! { /// More thread name. pub ki_moretdname: [::c_char; ::MAXCOMLEN - ::TDNAMLEN + 1], /// Spare string space. - pub ki_sparestrings: [::c_char; 46], + pub ki_sparestrings: [[::c_char; 23]; 2], // little hack to allow PartialEq /// Spare room for growth. pub ki_spareints: [::c_int; ::KI_NSPARE_INT], /// Which cpu we are on. diff --git a/src/unix/bsd/freebsdlike/freebsd/freebsd12/mod.rs b/src/unix/bsd/freebsdlike/freebsd/freebsd12/mod.rs index c2a168a501e58..c5b85f99c1d49 100644 --- a/src/unix/bsd/freebsdlike/freebsd/freebsd12/mod.rs +++ b/src/unix/bsd/freebsdlike/freebsd/freebsd12/mod.rs @@ -173,7 +173,7 @@ s! { /// More thread name. pub ki_moretdname: [::c_char; ::MAXCOMLEN - ::TDNAMLEN + 1], /// Spare string space. - pub ki_sparestrings: [::c_char; 46], + pub ki_sparestrings: [[::c_char; 23]; 2], // little hack to allow PartialEq /// Spare room for growth. pub ki_spareints: [::c_int; ::KI_NSPARE_INT], /// Controlling tty dev. diff --git a/src/unix/bsd/freebsdlike/freebsd/freebsd13/mod.rs b/src/unix/bsd/freebsdlike/freebsd/freebsd13/mod.rs index a663a3b5db1a7..b0a2786022011 100644 --- a/src/unix/bsd/freebsdlike/freebsd/freebsd13/mod.rs +++ b/src/unix/bsd/freebsdlike/freebsd/freebsd13/mod.rs @@ -183,7 +183,7 @@ s! { /// More thread name. pub ki_moretdname: [::c_char; ::MAXCOMLEN - ::TDNAMLEN + 1], /// Spare string space. - pub ki_sparestrings: [::c_char; 46], + pub ki_sparestrings: [[::c_char; 23]; 2], // little hack to allow PartialEq /// Spare room for growth. pub ki_spareints: [::c_int; ::KI_NSPARE_INT], /// Controlling tty dev. diff --git a/src/unix/bsd/freebsdlike/freebsd/freebsd14/mod.rs b/src/unix/bsd/freebsdlike/freebsd/freebsd14/mod.rs index afca6890711ae..265cc2ba595d9 100644 --- a/src/unix/bsd/freebsdlike/freebsd/freebsd14/mod.rs +++ b/src/unix/bsd/freebsdlike/freebsd/freebsd14/mod.rs @@ -183,7 +183,7 @@ s! { /// More thread name. pub ki_moretdname: [::c_char; ::MAXCOMLEN - ::TDNAMLEN + 1], /// Spare string space. - pub ki_sparestrings: [::c_char; 46], + pub ki_sparestrings: [[::c_char; 23]; 2], // little hack to allow PartialEq /// Spare room for growth. pub ki_spareints: [::c_int; ::KI_NSPARE_INT], /// Controlling tty dev. diff --git a/src/unix/bsd/freebsdlike/freebsd/freebsd15/mod.rs b/src/unix/bsd/freebsdlike/freebsd/freebsd15/mod.rs index 031f41364804d..47012e38b7db7 100644 --- a/src/unix/bsd/freebsdlike/freebsd/freebsd15/mod.rs +++ b/src/unix/bsd/freebsdlike/freebsd/freebsd15/mod.rs @@ -183,7 +183,7 @@ s! { /// More thread name. pub ki_moretdname: [::c_char; ::MAXCOMLEN - ::TDNAMLEN + 1], /// Spare string space. - pub ki_sparestrings: [::c_char; 46], + pub ki_sparestrings: [[::c_char; 23]; 2], // little hack to allow PartialEq /// Spare room for growth. pub ki_spareints: [::c_int; ::KI_NSPARE_INT], /// Controlling tty dev. diff --git a/src/unix/bsd/freebsdlike/freebsd/mod.rs b/src/unix/bsd/freebsdlike/freebsd/mod.rs index b6b750e0e8a52..e9bc592ddd61d 100644 --- a/src/unix/bsd/freebsdlike/freebsd/mod.rs +++ b/src/unix/bsd/freebsdlike/freebsd/mod.rs @@ -457,7 +457,7 @@ s! { _kve_is_spare: [::c_int; 8], #[cfg(freebsd11)] _kve_is_spare: [::c_int; 12], - pub kve_path: [::c_char; ::PATH_MAX as usize], + pub kve_path: [[::c_char; 32]; 32], } pub struct __c_anonymous_filestat { diff --git a/src/unix/bsd/freebsdlike/mod.rs b/src/unix/bsd/freebsdlike/mod.rs index 0ef069c8a4fd4..17723dda97a98 100644 --- a/src/unix/bsd/freebsdlike/mod.rs +++ b/src/unix/bsd/freebsdlike/mod.rs @@ -284,7 +284,7 @@ s! { pub struct accept_filter_arg { pub af_name: [::c_char; 16], - af_arg: [::c_char; 240], + af_arg: [[::c_char; 10]; 24], } pub struct ptrace_io_desc { diff --git a/src/unix/bsd/netbsdlike/netbsd/mod.rs b/src/unix/bsd/netbsdlike/netbsd/mod.rs index 8f3e7bbedcb50..a0d3283979e19 100644 --- a/src/unix/bsd/netbsdlike/netbsd/mod.rs +++ b/src/unix/bsd/netbsdlike/netbsd/mod.rs @@ -671,7 +671,7 @@ s! { pub kve_vn_rdev: u64, pub kve_vn_type: u32, pub kve_vn_mode: u32, - pub kve_path: [::c_char; ::PATH_MAX as usize], + pub kve_path: [[::c_char; 32]; 32], } pub struct __c_anonymous_posix_spawn_fae_open { diff --git a/src/unix/linux_like/android/b64/aarch64/mod.rs b/src/unix/linux_like/android/b64/aarch64/mod.rs index 2ea2d2cfcc0ac..1bd4491070716 100644 --- a/src/unix/linux_like/android/b64/aarch64/mod.rs +++ b/src/unix/linux_like/android/b64/aarch64/mod.rs @@ -72,7 +72,9 @@ s! { pub sp: ::c_ulonglong, pub pc: ::c_ulonglong, pub pstate: ::c_ulonglong, - __reserved: [u64; 512], + // nested arrays to get the right size/length while being able to + // auto-derive traits like Debug + __reserved: [[u64; 32]; 16], } pub struct user_fpsimd_struct { diff --git a/src/unix/linux_like/android/mod.rs b/src/unix/linux_like/android/mod.rs index db83b494a4a48..df24f67afd180 100644 --- a/src/unix/linux_like/android/mod.rs +++ b/src/unix/linux_like/android/mod.rs @@ -608,7 +608,7 @@ s_no_extra_traits! { pub struct prop_info { __name: [::c_char; 32], __serial: ::c_uint, - __value: [::c_char; 92], + __value: [[::c_char; 4]; 23], } pub union __c_anonymous_ifr_ifru { diff --git a/src/unix/linux_like/linux/gnu/b64/aarch64/mod.rs b/src/unix/linux_like/linux/gnu/b64/aarch64/mod.rs index 82273217aacf1..263a942068926 100644 --- a/src/unix/linux_like/linux/gnu/b64/aarch64/mod.rs +++ b/src/unix/linux_like/linux/gnu/b64/aarch64/mod.rs @@ -212,7 +212,9 @@ s! { pub sp: ::c_ulonglong, pub pc: ::c_ulonglong, pub pstate: ::c_ulonglong, - __reserved: [u64; 512], + // nested arrays to get the right size/length while being able to + // auto-derive traits like Debug + __reserved: [[u64; 32]; 16], } pub struct user_fpsimd_struct { diff --git a/src/unix/linux_like/linux/musl/b64/aarch64/mod.rs b/src/unix/linux_like/linux/musl/b64/aarch64/mod.rs index 6528fa2d84e3e..2fd68d95187bf 100644 --- a/src/unix/linux_like/linux/musl/b64/aarch64/mod.rs +++ b/src/unix/linux_like/linux/musl/b64/aarch64/mod.rs @@ -84,7 +84,7 @@ s! { pub sp: ::c_ulong, pub pc: ::c_ulong, pub pstate: ::c_ulong, - __reserved: [u64; 512], + __reserved: [[u64; 32]; 16], } #[repr(align(8))] From a1c30e3fa5bf358dd8f8194ffcd6d8ffeb87e261 Mon Sep 17 00:00:00 2001 From: Taylor Cramer Date: Tue, 26 Nov 2024 11:57:19 -0800 Subject: [PATCH 3/3] Remove array-size hacks for private fields --- src/unix/bsd/freebsdlike/mod.rs | 2 +- src/unix/bsd/netbsdlike/netbsd/mod.rs | 2 +- src/unix/linux_like/android/b64/aarch64/mod.rs | 4 +--- src/unix/linux_like/android/mod.rs | 2 +- src/unix/linux_like/linux/gnu/b64/aarch64/mod.rs | 4 +--- src/unix/linux_like/linux/musl/b64/aarch64/mod.rs | 2 +- 6 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/unix/bsd/freebsdlike/mod.rs b/src/unix/bsd/freebsdlike/mod.rs index 17723dda97a98..7628eee7f5c11 100644 --- a/src/unix/bsd/freebsdlike/mod.rs +++ b/src/unix/bsd/freebsdlike/mod.rs @@ -284,7 +284,7 @@ s! { pub struct accept_filter_arg { pub af_name: [::c_char; 16], - af_arg: [[::c_char; 10]; 24], + af_arg: [::c_char; 256 - 16], } pub struct ptrace_io_desc { diff --git a/src/unix/bsd/netbsdlike/netbsd/mod.rs b/src/unix/bsd/netbsdlike/netbsd/mod.rs index a0d3283979e19..a0b1c232d69d9 100644 --- a/src/unix/bsd/netbsdlike/netbsd/mod.rs +++ b/src/unix/bsd/netbsdlike/netbsd/mod.rs @@ -520,7 +520,7 @@ s! { pub struct accept_filter_arg { pub af_name: [::c_char; 16], - af_arg: [[::c_char; 10]; 24], + af_arg: [::c_char; 256 - 16], } pub struct ki_sigset_t { diff --git a/src/unix/linux_like/android/b64/aarch64/mod.rs b/src/unix/linux_like/android/b64/aarch64/mod.rs index 1bd4491070716..2ea2d2cfcc0ac 100644 --- a/src/unix/linux_like/android/b64/aarch64/mod.rs +++ b/src/unix/linux_like/android/b64/aarch64/mod.rs @@ -72,9 +72,7 @@ s! { pub sp: ::c_ulonglong, pub pc: ::c_ulonglong, pub pstate: ::c_ulonglong, - // nested arrays to get the right size/length while being able to - // auto-derive traits like Debug - __reserved: [[u64; 32]; 16], + __reserved: [u64; 512], } pub struct user_fpsimd_struct { diff --git a/src/unix/linux_like/android/mod.rs b/src/unix/linux_like/android/mod.rs index df24f67afd180..db83b494a4a48 100644 --- a/src/unix/linux_like/android/mod.rs +++ b/src/unix/linux_like/android/mod.rs @@ -608,7 +608,7 @@ s_no_extra_traits! { pub struct prop_info { __name: [::c_char; 32], __serial: ::c_uint, - __value: [[::c_char; 4]; 23], + __value: [::c_char; 92], } pub union __c_anonymous_ifr_ifru { diff --git a/src/unix/linux_like/linux/gnu/b64/aarch64/mod.rs b/src/unix/linux_like/linux/gnu/b64/aarch64/mod.rs index 263a942068926..82273217aacf1 100644 --- a/src/unix/linux_like/linux/gnu/b64/aarch64/mod.rs +++ b/src/unix/linux_like/linux/gnu/b64/aarch64/mod.rs @@ -212,9 +212,7 @@ s! { pub sp: ::c_ulonglong, pub pc: ::c_ulonglong, pub pstate: ::c_ulonglong, - // nested arrays to get the right size/length while being able to - // auto-derive traits like Debug - __reserved: [[u64; 32]; 16], + __reserved: [u64; 512], } pub struct user_fpsimd_struct { diff --git a/src/unix/linux_like/linux/musl/b64/aarch64/mod.rs b/src/unix/linux_like/linux/musl/b64/aarch64/mod.rs index 2fd68d95187bf..6528fa2d84e3e 100644 --- a/src/unix/linux_like/linux/musl/b64/aarch64/mod.rs +++ b/src/unix/linux_like/linux/musl/b64/aarch64/mod.rs @@ -84,7 +84,7 @@ s! { pub sp: ::c_ulong, pub pc: ::c_ulong, pub pstate: ::c_ulong, - __reserved: [[u64; 32]; 16], + __reserved: [u64; 512], } #[repr(align(8))]