From 62e7f00211004cb96430862d4bbd249132ac3726 Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Mon, 23 Sep 2024 10:44:13 -0600 Subject: [PATCH] Fix the definition of "struct stat" on 32-bit FreeBSD 12+ The original definitions were never correct. But nobody noticed because we don't do CI on 32-bit FreeBSD. The problem is apparent now due to #3723 , which caused the nightly toolchain to switch to a FreeBSD 12 ABI. Fixes https://github.com/rust-lang/rust/issues/130677 --- src/unix/bsd/freebsdlike/freebsd/arm.rs | 30 ------------- .../{freebsd12/b64.rs => freebsd11/b32.rs} | 13 +++--- .../bsd/freebsdlike/freebsd/freebsd11/mod.rs | 7 +-- .../bsd/freebsdlike/freebsd/freebsd12/mod.rs | 43 +++++++++++++++---- .../bsd/freebsdlike/freebsd/freebsd13/b64.rs | 34 --------------- .../bsd/freebsdlike/freebsd/freebsd13/mod.rs | 43 +++++++++++++++---- .../bsd/freebsdlike/freebsd/freebsd14/b64.rs | 34 --------------- .../bsd/freebsdlike/freebsd/freebsd14/mod.rs | 43 +++++++++++++++---- .../bsd/freebsdlike/freebsd/freebsd15/b64.rs | 34 --------------- .../bsd/freebsdlike/freebsd/freebsd15/mod.rs | 43 +++++++++++++++---- src/unix/bsd/freebsdlike/freebsd/powerpc.rs | 26 ----------- src/unix/bsd/freebsdlike/freebsd/powerpc64.rs | 27 ------------ src/unix/bsd/freebsdlike/freebsd/x86.rs | 25 ----------- 13 files changed, 146 insertions(+), 256 deletions(-) rename src/unix/bsd/freebsdlike/freebsd/{freebsd12/b64.rs => freebsd11/b32.rs} (89%) delete mode 100644 src/unix/bsd/freebsdlike/freebsd/freebsd13/b64.rs delete mode 100644 src/unix/bsd/freebsdlike/freebsd/freebsd14/b64.rs delete mode 100644 src/unix/bsd/freebsdlike/freebsd/freebsd15/b64.rs diff --git a/src/unix/bsd/freebsdlike/freebsd/arm.rs b/src/unix/bsd/freebsdlike/freebsd/arm.rs index af3c8a7cf6f6c..ea12f1b08d02c 100644 --- a/src/unix/bsd/freebsdlike/freebsd/arm.rs +++ b/src/unix/bsd/freebsdlike/freebsd/arm.rs @@ -6,36 +6,6 @@ pub type time_t = i64; pub type suseconds_t = i32; pub type register_t = i32; -s! { - pub struct stat { - pub st_dev: ::dev_t, - pub st_ino: ::ino_t, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_atime_pad: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_mtime_pad: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - pub st_ctime_pad: ::c_long, - pub st_size: ::off_t, - pub st_blocks: ::blkcnt_t, - pub st_blksize: ::blksize_t, - pub st_flags: ::fflags_t, - pub st_gen: u32, - pub st_lspare: i32, - pub st_birthtime: ::time_t, - pub st_birthtime_nsec: ::c_long, - pub st_birthtime_pad: ::c_long, - } -} - pub(crate) const _ALIGNBYTES: usize = ::mem::size_of::<::c_int>() - 1; pub const MAP_32BIT: ::c_int = 0x00080000; pub const MINSIGSTKSZ: ::size_t = 4096; // 1024 * 4 diff --git a/src/unix/bsd/freebsdlike/freebsd/freebsd12/b64.rs b/src/unix/bsd/freebsdlike/freebsd/freebsd11/b32.rs similarity index 89% rename from src/unix/bsd/freebsdlike/freebsd/freebsd12/b64.rs rename to src/unix/bsd/freebsdlike/freebsd/freebsd11/b32.rs index 80c6fa1684530..5c1156581fd61 100644 --- a/src/unix/bsd/freebsdlike/freebsd/freebsd12/b64.rs +++ b/src/unix/bsd/freebsdlike/freebsd/freebsd11/b32.rs @@ -3,12 +3,10 @@ pub struct stat { pub st_dev: ::dev_t, pub st_ino: ::ino_t, - pub st_nlink: ::nlink_t, pub st_mode: ::mode_t, - st_padding0: i16, + pub st_nlink: ::nlink_t, pub st_uid: ::uid_t, pub st_gid: ::gid_t, - st_padding1: i32, pub st_rdev: ::dev_t, pub st_atime: ::time_t, pub st_atime_nsec: ::c_long, @@ -16,14 +14,15 @@ pub struct stat { pub st_mtime_nsec: ::c_long, pub st_ctime: ::time_t, pub st_ctime_nsec: ::c_long, - pub st_birthtime: ::time_t, - pub st_birthtime_nsec: ::c_long, pub st_size: ::off_t, pub st_blocks: ::blkcnt_t, pub st_blksize: ::blksize_t, pub st_flags: ::fflags_t, - pub st_gen: u64, - pub st_spare: [u64; 10], + pub st_gen: u32, + pub st_lspare: i32, + pub st_birthtime: ::time_t, + pub st_birthtime_nsec: ::c_long, + __unused: [u8; 8], } impl ::Copy for ::stat {} diff --git a/src/unix/bsd/freebsdlike/freebsd/freebsd11/mod.rs b/src/unix/bsd/freebsdlike/freebsd/freebsd11/mod.rs index 68a8364194607..e416ebf745841 100644 --- a/src/unix/bsd/freebsdlike/freebsd/freebsd11/mod.rs +++ b/src/unix/bsd/freebsdlike/freebsd/freebsd11/mod.rs @@ -479,10 +479,11 @@ extern "C" { } cfg_if! { - if #[cfg(any(target_arch = "x86_64", - target_arch = "aarch64", - target_arch = "riscv64"))] { + if #[cfg(target_pointer_width = "64")] { mod b64; pub use self::b64::*; + } else { + mod b32; + pub use self::b32::*; } } diff --git a/src/unix/bsd/freebsdlike/freebsd/freebsd12/mod.rs b/src/unix/bsd/freebsdlike/freebsd/freebsd12/mod.rs index 197400ffb4e28..c4431a6458e8f 100644 --- a/src/unix/bsd/freebsdlike/freebsd/freebsd12/mod.rs +++ b/src/unix/bsd/freebsdlike/freebsd/freebsd12/mod.rs @@ -218,6 +218,40 @@ s! { /// kthread flag. pub ki_tdflags: ::c_long, } + + pub struct stat { + pub st_dev: ::dev_t, + pub st_ino: ::ino_t, + pub st_nlink: ::nlink_t, + pub st_mode: ::mode_t, + st_padding0: i16, + pub st_uid: ::uid_t, + pub st_gid: ::gid_t, + st_padding1: i32, + pub st_rdev: ::dev_t, + #[cfg(target_arch = "x86")] + st_atim_ext: i32, + pub st_atime: ::time_t, + pub st_atime_nsec: ::c_long, + #[cfg(target_arch = "x86")] + st_mtim_ext: i32, + pub st_mtime: ::time_t, + pub st_mtime_nsec: ::c_long, + #[cfg(target_arch = "x86")] + st_ctim_ext: i32, + pub st_ctime: ::time_t, + pub st_ctime_nsec: ::c_long, + #[cfg(target_arch = "x86")] + st_btim_ext: i32, + pub st_birthtime: ::time_t, + pub st_birthtime_nsec: ::c_long, + pub st_size: ::off_t, + pub st_blocks: ::blkcnt_t, + pub st_blksize: ::blksize_t, + pub st_flags: ::fflags_t, + pub st_gen: u64, + pub st_spare: [u64; 10], + } } s_no_extra_traits! { @@ -488,15 +522,6 @@ extern "C" { pub fn basename(path: *mut ::c_char) -> *mut ::c_char; } -cfg_if! { - if #[cfg(any(target_arch = "x86_64", - target_arch = "aarch64", - target_arch = "riscv64"))] { - mod b64; - pub use self::b64::*; - } -} - cfg_if! { if #[cfg(target_arch = "x86_64")] { mod x86_64; diff --git a/src/unix/bsd/freebsdlike/freebsd/freebsd13/b64.rs b/src/unix/bsd/freebsdlike/freebsd/freebsd13/b64.rs deleted file mode 100644 index 80c6fa1684530..0000000000000 --- a/src/unix/bsd/freebsdlike/freebsd/freebsd13/b64.rs +++ /dev/null @@ -1,34 +0,0 @@ -#[repr(C)] -#[cfg_attr(feature = "extra_traits", derive(Debug, Eq, Hash, PartialEq))] -pub struct stat { - pub st_dev: ::dev_t, - pub st_ino: ::ino_t, - pub st_nlink: ::nlink_t, - pub st_mode: ::mode_t, - st_padding0: i16, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - st_padding1: i32, - pub st_rdev: ::dev_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - pub st_birthtime: ::time_t, - pub st_birthtime_nsec: ::c_long, - pub st_size: ::off_t, - pub st_blocks: ::blkcnt_t, - pub st_blksize: ::blksize_t, - pub st_flags: ::fflags_t, - pub st_gen: u64, - pub st_spare: [u64; 10], -} - -impl ::Copy for ::stat {} -impl ::Clone for ::stat { - fn clone(&self) -> ::stat { - *self - } -} diff --git a/src/unix/bsd/freebsdlike/freebsd/freebsd13/mod.rs b/src/unix/bsd/freebsdlike/freebsd/freebsd13/mod.rs index d3a77d03c48d0..118404e8b089b 100644 --- a/src/unix/bsd/freebsdlike/freebsd/freebsd13/mod.rs +++ b/src/unix/bsd/freebsdlike/freebsd/freebsd13/mod.rs @@ -228,6 +228,40 @@ s! { /// kthread flag. pub ki_tdflags: ::c_long, } + + pub struct stat { + pub st_dev: ::dev_t, + pub st_ino: ::ino_t, + pub st_nlink: ::nlink_t, + pub st_mode: ::mode_t, + st_padding0: i16, + pub st_uid: ::uid_t, + pub st_gid: ::gid_t, + st_padding1: i32, + pub st_rdev: ::dev_t, + #[cfg(target_arch = "x86")] + st_atim_ext: i32, + pub st_atime: ::time_t, + pub st_atime_nsec: ::c_long, + #[cfg(target_arch = "x86")] + st_mtim_ext: i32, + pub st_mtime: ::time_t, + pub st_mtime_nsec: ::c_long, + #[cfg(target_arch = "x86")] + st_ctim_ext: i32, + pub st_ctime: ::time_t, + pub st_ctime_nsec: ::c_long, + #[cfg(target_arch = "x86")] + st_btim_ext: i32, + pub st_birthtime: ::time_t, + pub st_birthtime_nsec: ::c_long, + pub st_size: ::off_t, + pub st_blocks: ::blkcnt_t, + pub st_blksize: ::blksize_t, + pub st_flags: ::fflags_t, + pub st_gen: u64, + pub st_spare: [u64; 10], + } } s_no_extra_traits! { @@ -529,15 +563,6 @@ extern "C" { pub fn kvm_kerndisp(kd: *mut ::kvm_t) -> ::kssize_t; } -cfg_if! { - if #[cfg(any(target_arch = "x86_64", - target_arch = "aarch64", - target_arch = "riscv64"))] { - mod b64; - pub use self::b64::*; - } -} - cfg_if! { if #[cfg(target_arch = "x86_64")] { mod x86_64; diff --git a/src/unix/bsd/freebsdlike/freebsd/freebsd14/b64.rs b/src/unix/bsd/freebsdlike/freebsd/freebsd14/b64.rs deleted file mode 100644 index 80c6fa1684530..0000000000000 --- a/src/unix/bsd/freebsdlike/freebsd/freebsd14/b64.rs +++ /dev/null @@ -1,34 +0,0 @@ -#[repr(C)] -#[cfg_attr(feature = "extra_traits", derive(Debug, Eq, Hash, PartialEq))] -pub struct stat { - pub st_dev: ::dev_t, - pub st_ino: ::ino_t, - pub st_nlink: ::nlink_t, - pub st_mode: ::mode_t, - st_padding0: i16, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - st_padding1: i32, - pub st_rdev: ::dev_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - pub st_birthtime: ::time_t, - pub st_birthtime_nsec: ::c_long, - pub st_size: ::off_t, - pub st_blocks: ::blkcnt_t, - pub st_blksize: ::blksize_t, - pub st_flags: ::fflags_t, - pub st_gen: u64, - pub st_spare: [u64; 10], -} - -impl ::Copy for ::stat {} -impl ::Clone for ::stat { - fn clone(&self) -> ::stat { - *self - } -} diff --git a/src/unix/bsd/freebsdlike/freebsd/freebsd14/mod.rs b/src/unix/bsd/freebsdlike/freebsd/freebsd14/mod.rs index 9d65317d29cb4..e624dd7201b0a 100644 --- a/src/unix/bsd/freebsdlike/freebsd/freebsd14/mod.rs +++ b/src/unix/bsd/freebsdlike/freebsd/freebsd14/mod.rs @@ -228,6 +228,40 @@ s! { /// kthread flag. pub ki_tdflags: ::c_long, } + + pub struct stat { + pub st_dev: ::dev_t, + pub st_ino: ::ino_t, + pub st_nlink: ::nlink_t, + pub st_mode: ::mode_t, + st_padding0: i16, + pub st_uid: ::uid_t, + pub st_gid: ::gid_t, + st_padding1: i32, + pub st_rdev: ::dev_t, + #[cfg(target_arch = "x86")] + st_atim_ext: i32, + pub st_atime: ::time_t, + pub st_atime_nsec: ::c_long, + #[cfg(target_arch = "x86")] + st_mtim_ext: i32, + pub st_mtime: ::time_t, + pub st_mtime_nsec: ::c_long, + #[cfg(target_arch = "x86")] + st_ctim_ext: i32, + pub st_ctime: ::time_t, + pub st_ctime_nsec: ::c_long, + #[cfg(target_arch = "x86")] + st_btim_ext: i32, + pub st_birthtime: ::time_t, + pub st_birthtime_nsec: ::c_long, + pub st_size: ::off_t, + pub st_blocks: ::blkcnt_t, + pub st_blksize: ::blksize_t, + pub st_flags: ::fflags_t, + pub st_gen: u64, + pub st_spare: [u64; 10], + } } s_no_extra_traits! { @@ -529,15 +563,6 @@ extern "C" { pub fn kvm_kerndisp(kd: *mut ::kvm_t) -> ::kssize_t; } -cfg_if! { - if #[cfg(any(target_arch = "x86_64", - target_arch = "aarch64", - target_arch = "riscv64"))] { - mod b64; - pub use self::b64::*; - } -} - cfg_if! { if #[cfg(target_arch = "x86_64")] { mod x86_64; diff --git a/src/unix/bsd/freebsdlike/freebsd/freebsd15/b64.rs b/src/unix/bsd/freebsdlike/freebsd/freebsd15/b64.rs deleted file mode 100644 index 80c6fa1684530..0000000000000 --- a/src/unix/bsd/freebsdlike/freebsd/freebsd15/b64.rs +++ /dev/null @@ -1,34 +0,0 @@ -#[repr(C)] -#[cfg_attr(feature = "extra_traits", derive(Debug, Eq, Hash, PartialEq))] -pub struct stat { - pub st_dev: ::dev_t, - pub st_ino: ::ino_t, - pub st_nlink: ::nlink_t, - pub st_mode: ::mode_t, - st_padding0: i16, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - st_padding1: i32, - pub st_rdev: ::dev_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - pub st_birthtime: ::time_t, - pub st_birthtime_nsec: ::c_long, - pub st_size: ::off_t, - pub st_blocks: ::blkcnt_t, - pub st_blksize: ::blksize_t, - pub st_flags: ::fflags_t, - pub st_gen: u64, - pub st_spare: [u64; 10], -} - -impl ::Copy for ::stat {} -impl ::Clone for ::stat { - fn clone(&self) -> ::stat { - *self - } -} diff --git a/src/unix/bsd/freebsdlike/freebsd/freebsd15/mod.rs b/src/unix/bsd/freebsdlike/freebsd/freebsd15/mod.rs index f76208400f324..a299af7d5d53e 100644 --- a/src/unix/bsd/freebsdlike/freebsd/freebsd15/mod.rs +++ b/src/unix/bsd/freebsdlike/freebsd/freebsd15/mod.rs @@ -228,6 +228,40 @@ s! { /// kthread flag. pub ki_tdflags: ::c_long, } + + pub struct stat { + pub st_dev: ::dev_t, + pub st_ino: ::ino_t, + pub st_nlink: ::nlink_t, + pub st_mode: ::mode_t, + st_padding0: i16, + pub st_uid: ::uid_t, + pub st_gid: ::gid_t, + st_padding1: i32, + pub st_rdev: ::dev_t, + #[cfg(target_arch = "x86")] + st_atim_ext: i32, + pub st_atime: ::time_t, + pub st_atime_nsec: ::c_long, + #[cfg(target_arch = "x86")] + st_mtim_ext: i32, + pub st_mtime: ::time_t, + pub st_mtime_nsec: ::c_long, + #[cfg(target_arch = "x86")] + st_ctim_ext: i32, + pub st_ctime: ::time_t, + pub st_ctime_nsec: ::c_long, + #[cfg(target_arch = "x86")] + st_btim_ext: i32, + pub st_birthtime: ::time_t, + pub st_birthtime_nsec: ::c_long, + pub st_size: ::off_t, + pub st_blocks: ::blkcnt_t, + pub st_blksize: ::blksize_t, + pub st_flags: ::fflags_t, + pub st_gen: u64, + pub st_spare: [u64; 10], + } } s_no_extra_traits! { @@ -529,15 +563,6 @@ extern "C" { pub fn kvm_kerndisp(kd: *mut ::kvm_t) -> ::kssize_t; } -cfg_if! { - if #[cfg(any(target_arch = "x86_64", - target_arch = "aarch64", - target_arch = "riscv64"))] { - mod b64; - pub use self::b64::*; - } -} - cfg_if! { if #[cfg(target_arch = "x86_64")] { mod x86_64; diff --git a/src/unix/bsd/freebsdlike/freebsd/powerpc.rs b/src/unix/bsd/freebsdlike/freebsd/powerpc.rs index 0900005166a2e..f065e34dd0083 100644 --- a/src/unix/bsd/freebsdlike/freebsd/powerpc.rs +++ b/src/unix/bsd/freebsdlike/freebsd/powerpc.rs @@ -6,32 +6,6 @@ pub type time_t = i64; pub type suseconds_t = i32; pub type register_t = i32; -s! { - pub struct stat { - pub st_dev: ::dev_t, - pub st_ino: ::ino_t, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - pub st_size: ::off_t, - pub st_blocks: ::blkcnt_t, - pub st_blksize: ::blksize_t, - pub st_flags: ::fflags_t, - pub st_gen: u32, - pub st_lspare: i32, - pub st_birthtime: ::time_t, - pub st_birthtime_nsec: ::c_long, - } -} - pub(crate) const _ALIGNBYTES: usize = ::mem::size_of::<::c_int>() - 1; pub const MAP_32BIT: ::c_int = 0x00080000; pub const MINSIGSTKSZ: ::size_t = 2048; // 512 * 4 diff --git a/src/unix/bsd/freebsdlike/freebsd/powerpc64.rs b/src/unix/bsd/freebsdlike/freebsd/powerpc64.rs index 07f2f11cdc9a4..199f6a50b8a76 100644 --- a/src/unix/bsd/freebsdlike/freebsd/powerpc64.rs +++ b/src/unix/bsd/freebsdlike/freebsd/powerpc64.rs @@ -6,33 +6,6 @@ pub type time_t = i64; pub type suseconds_t = i64; pub type register_t = i64; -s! { - pub struct stat { - pub st_dev: ::dev_t, - pub st_ino: ::ino_t, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - pub st_size: ::off_t, - pub st_blocks: ::blkcnt_t, - pub st_blksize: ::blksize_t, - pub st_flags: ::fflags_t, - pub st_gen: u32, - pub st_lspare: i32, - pub st_birthtime: ::time_t, - pub st_birthtime_nsec: ::c_long, - } -} - pub(crate) const _ALIGNBYTES: usize = ::mem::size_of::<::c_long>() - 1; - pub const MAP_32BIT: ::c_int = 0x00080000; pub const MINSIGSTKSZ: ::size_t = 2048; // 512 * 4 diff --git a/src/unix/bsd/freebsdlike/freebsd/x86.rs b/src/unix/bsd/freebsdlike/freebsd/x86.rs index 3e3e5cc9f34fb..e6928006be2ff 100644 --- a/src/unix/bsd/freebsdlike/freebsd/x86.rs +++ b/src/unix/bsd/freebsdlike/freebsd/x86.rs @@ -42,31 +42,6 @@ s_no_extra_traits! { } s! { - pub struct stat { - pub st_dev: ::dev_t, - pub st_ino: ::ino_t, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - pub st_size: ::off_t, - pub st_blocks: ::blkcnt_t, - pub st_blksize: ::blksize_t, - pub st_flags: ::fflags_t, - pub st_gen: u32, - pub st_lspare: i32, - pub st_birthtime: ::time_t, - pub st_birthtime_nsec: ::c_long, - __unused: [u8; 8], - } - pub struct ucontext_t { pub uc_sigmask: ::sigset_t, pub uc_mcontext: ::mcontext_t,