diff --git a/build.rs b/build.rs index 2a37d436b632..915b3a929b0b 100644 --- a/build.rs +++ b/build.rs @@ -17,6 +17,8 @@ const ALLOWED_CFGS: &'static [&'static str] = &[ "libc_const_extern_fn", "libc_deny_warnings", "libc_ctest", + // Corresponds to `__USE_TIME_BITS64` in UAPI + "linux_time_bits64", ]; // Extra values to allow for check-cfg. @@ -42,6 +44,7 @@ fn main() { let rustc_dep_of_std = env::var("CARGO_FEATURE_RUSTC_DEP_OF_STD").is_ok(); let libc_ci = env::var("LIBC_CI").is_ok(); let libc_check_cfg = env::var("LIBC_CHECK_CFG").is_ok() || rustc_minor_ver >= 80; + let linux_time_bits64 = env::var("RUST_LIBC_UNSTABLE_LINUX_TIME_BITS64").is_ok(); // The ABI of libc used by std is backward compatible with FreeBSD 12. // The ABI of libc from crates.io is backward compatible with FreeBSD 12. @@ -78,6 +81,10 @@ fn main() { Some(_) | None => (), } + if linux_time_bits64 { + set_cfg("linux_time_bits64"); + } + // On CI: deny all warnings if libc_ci { set_cfg("libc_deny_warnings"); diff --git a/ci/verify-build.sh b/ci/verify-build.sh index cc407d7569b7..f062813dc53c 100755 --- a/ci/verify-build.sh +++ b/ci/verify-build.sh @@ -71,6 +71,11 @@ test_target() { $cmd $cmd --features extra_traits + if [ "$os" = "linux" ]; then + # Test with the equivalent of __USE_TIME_BITS64 + RUST_LIBC_UNSTABLE_LINUX_TIME_BITS64=1 $cmd + fi + # Test again without default features, i.e. without "std" $cmd --no-default-features $cmd --no-default-features --features extra_traits diff --git a/libc-test/semver/TODO-linux.txt b/libc-test/semver/TODO-linux.txt index 8427cf1ea12c..98568ab0e974 100644 --- a/libc-test/semver/TODO-linux.txt +++ b/libc-test/semver/TODO-linux.txt @@ -54,7 +54,6 @@ SO_SELECT_ERR_QUEUE SO_SNDTIMEO_NEW SO_STYLE SO_TIMESTAMPING_NEW -SO_TIMESTAMPNS SO_TIMESTAMPNS_NEW SO_TIMESTAMP_NEW SO_TXTIME diff --git a/libc-test/semver/linux-loongarch64.txt b/libc-test/semver/linux-loongarch64.txt index ebcd4bf93356..1302cb68b2c8 100644 --- a/libc-test/semver/linux-loongarch64.txt +++ b/libc-test/semver/linux-loongarch64.txt @@ -87,7 +87,6 @@ SO_SECURITY_AUTHENTICATION SO_SECURITY_ENCRYPTION_NETWORK SO_SECURITY_ENCRYPTION_TRANSPORT SO_SELECT_ERR_QUEUE -SO_TIMESTAMPNS SO_WIFI_STATUS SYS_accept SYS_msgctl diff --git a/libc-test/semver/linux-powerpc64.txt b/libc-test/semver/linux-powerpc64.txt index 77718d9ce47f..604add92838d 100644 --- a/libc-test/semver/linux-powerpc64.txt +++ b/libc-test/semver/linux-powerpc64.txt @@ -48,7 +48,6 @@ SO_SECURITY_AUTHENTICATION SO_SECURITY_ENCRYPTION_NETWORK SO_SECURITY_ENCRYPTION_TRANSPORT SO_SELECT_ERR_QUEUE -SO_TIMESTAMPNS SO_WIFI_STATUS SYS__llseek SYS__newselect diff --git a/libc-test/semver/linux-powerpc64le.txt b/libc-test/semver/linux-powerpc64le.txt index 99be508e6bd5..b4e5c4159a3d 100644 --- a/libc-test/semver/linux-powerpc64le.txt +++ b/libc-test/semver/linux-powerpc64le.txt @@ -46,7 +46,6 @@ SO_SECURITY_AUTHENTICATION SO_SECURITY_ENCRYPTION_NETWORK SO_SECURITY_ENCRYPTION_TRANSPORT SO_SELECT_ERR_QUEUE -SO_TIMESTAMPNS SO_WIFI_STATUS SYS__llseek SYS__newselect diff --git a/libc-test/semver/linux-riscv64gc.txt b/libc-test/semver/linux-riscv64gc.txt index 13f5b8519679..09519e9dfbe7 100644 --- a/libc-test/semver/linux-riscv64gc.txt +++ b/libc-test/semver/linux-riscv64gc.txt @@ -51,7 +51,6 @@ SO_SECURITY_AUTHENTICATION SO_SECURITY_ENCRYPTION_NETWORK SO_SECURITY_ENCRYPTION_TRANSPORT SO_SELECT_ERR_QUEUE -SO_TIMESTAMPNS SO_WIFI_STATUS SYS_accept SYS_fadvise64 diff --git a/libc-test/semver/linux.txt b/libc-test/semver/linux.txt index 33e47670a375..6775a8bfbcb9 100644 --- a/libc-test/semver/linux.txt +++ b/libc-test/semver/linux.txt @@ -2955,6 +2955,7 @@ SO_RXQ_OVFL SO_SNDBUFFORCE SO_TIMESTAMP SO_TIMESTAMPING +SO_TIMESTAMPNS SPLICE_F_GIFT SPLICE_F_MORE SPLICE_F_MOVE diff --git a/src/unix/linux_like/linux/arch/generic/mod.rs b/src/unix/linux_like/linux/arch/generic/mod.rs index 10953fe789df..ea38a20d67e4 100644 --- a/src/unix/linux_like/linux/arch/generic/mod.rs +++ b/src/unix/linux_like/linux/arch/generic/mod.rs @@ -40,10 +40,8 @@ pub const SO_PASSCRED: c_int = 16; pub const SO_PEERCRED: c_int = 17; pub const SO_RCVLOWAT: c_int = 18; pub const SO_SNDLOWAT: c_int = 19; -pub const SO_RCVTIMEO: c_int = 20; -pub const SO_SNDTIMEO: c_int = 21; -// pub const SO_RCVTIMEO_OLD: c_int = 20; -// pub const SO_SNDTIMEO_OLD: c_int = 21; +const SO_RCVTIMEO_OLD: c_int = 20; +const SO_SNDTIMEO_OLD: c_int = 21; pub const SO_SECURITY_AUTHENTICATION: c_int = 22; pub const SO_SECURITY_ENCRYPTION_TRANSPORT: c_int = 23; pub const SO_SECURITY_ENCRYPTION_NETWORK: c_int = 24; @@ -52,18 +50,35 @@ pub const SO_ATTACH_FILTER: c_int = 26; pub const SO_DETACH_FILTER: c_int = 27; pub const SO_GET_FILTER: c_int = SO_ATTACH_FILTER; pub const SO_PEERNAME: c_int = 28; -pub const SO_TIMESTAMP: c_int = 29; -// pub const SO_TIMESTAMP_OLD: c_int = 29; +const SO_TIMESTAMP_OLD: c_int = 29; +const SO_TIMESTAMPNS_OLD: c_int = 35; +const SO_TIMESTAMPING_OLD: c_int = 37; + +cfg_if! { + if #[cfg(all( + linux_time_bits64, + any(target_arch = "arm", target_arch = "x86") + ))] { + pub const SO_TIMESTAMP: c_int = SO_TIMESTAMP_NEW; + pub const SO_TIMESTAMPNS: c_int = SO_TIMESTAMPNS_NEW; + pub const SO_TIMESTAMPING: c_int = SO_TIMESTAMPING_NEW; + pub const SO_RCVTIMEO: c_int = SO_RCVTIMEO_NEW; + pub const SO_SNDTIMEO: c_int = SO_SNDTIMEO_NEW; + } else { + pub const SO_TIMESTAMP: c_int = SO_TIMESTAMP_OLD; + pub const SO_TIMESTAMPNS: c_int = SO_TIMESTAMPNS_OLD; + pub const SO_TIMESTAMPING: c_int = SO_TIMESTAMPING_OLD; + pub const SO_RCVTIMEO: c_int = SO_RCVTIMEO_OLD; + pub const SO_SNDTIMEO: c_int = SO_SNDTIMEO_OLD; + } +} + pub const SO_ACCEPTCONN: c_int = 30; pub const SO_PEERSEC: c_int = 31; pub const SO_SNDBUFFORCE: c_int = 32; pub const SO_RCVBUFFORCE: c_int = 33; pub const SO_PASSSEC: c_int = 34; -pub const SO_TIMESTAMPNS: c_int = 35; -// pub const SO_TIMESTAMPNS_OLD: c_int = 35; pub const SO_MARK: c_int = 36; -pub const SO_TIMESTAMPING: c_int = 37; -// pub const SO_TIMESTAMPING_OLD: c_int = 37; pub const SO_PROTOCOL: c_int = 38; pub const SO_DOMAIN: c_int = 39; pub const SO_RXQ_OVFL: c_int = 40; diff --git a/src/unix/linux_like/linux/arch/mips/mod.rs b/src/unix/linux_like/linux/arch/mips/mod.rs index 950ad5f118df..70364b3108cd 100644 --- a/src/unix/linux_like/linux/arch/mips/mod.rs +++ b/src/unix/linux_like/linux/arch/mips/mod.rs @@ -36,10 +36,17 @@ pub const SO_RCVLOWAT: c_int = 0x1004; // NOTE: These definitions are now being renamed with _OLD postfix, // but CI haven't support them yet. // Some related consts could be found in b32.rs and b64.rs -pub const SO_SNDTIMEO: c_int = 0x1005; -pub const SO_RCVTIMEO: c_int = 0x1006; -// pub const SO_SNDTIMEO_OLD: c_int = 0x1005; -// pub const SO_RCVTIMEO_OLD: c_int = 0x1006; +const SO_SNDTIMEO_OLD: c_int = 0x1005; +const SO_RCVTIMEO_OLD: c_int = 0x1006; +cfg_if! { + if #[cfg(linux_time_bits64)] { + pub const SO_SNDTIMEO: c_int = SO_SNDTIMEO_NEW; + pub const SO_RCVTIMEO: c_int = SO_RCVTIMEO_NEW; + } else { + pub const SO_SNDTIMEO: c_int = SO_SNDTIMEO_OLD; + pub const SO_RCVTIMEO: c_int = SO_RCVTIMEO_OLD; + } +} pub const SO_ACCEPTCONN: c_int = 0x1009; pub const SO_PROTOCOL: c_int = 0x1028; pub const SO_DOMAIN: c_int = 0x1029; @@ -91,17 +98,20 @@ pub const SO_BINDTOIFINDEX: c_int = 62; // NOTE: These definitions are now being renamed with _OLD postfix, // but CI haven't support them yet. // Some related consts could be found in b32.rs and b64.rs -pub const SO_TIMESTAMP: c_int = 29; -pub const SO_TIMESTAMPNS: c_int = 35; -pub const SO_TIMESTAMPING: c_int = 37; -// pub const SO_TIMESTAMP_OLD: c_int = 29; -// pub const SO_TIMESTAMPNS_OLD: c_int = 35; -// pub const SO_TIMESTAMPING_OLD: c_int = 37; -// pub const SO_TIMESTAMP_NEW: c_int = 63; -// pub const SO_TIMESTAMPNS_NEW: c_int = 64; -// pub const SO_TIMESTAMPING_NEW: c_int = 65; -// pub const SO_RCVTIMEO_NEW: c_int = 66; -// pub const SO_SNDTIMEO_NEW: c_int = 67; +const SO_TIMESTAMP_OLD: c_int = 29; +const SO_TIMESTAMPNS_OLD: c_int = 35; +const SO_TIMESTAMPING_OLD: c_int = 37; +cfg_if! { + if #[cfg(linux_time_bits64)] { + pub const SO_TIMESTAMP: c_int = SO_TIMESTAMP_NEW; + pub const SO_TIMESTAMPNS: c_int = SO_TIMESTAMPNS_NEW; + pub const SO_TIMESTAMPING: c_int = SO_TIMESTAMPING_NEW; + } else { + pub const SO_TIMESTAMP: c_int = SO_TIMESTAMP_OLD; + pub const SO_TIMESTAMPNS: c_int = SO_TIMESTAMPNS_OLD; + pub const SO_TIMESTAMPING: c_int = SO_TIMESTAMPING_OLD; + } +} // pub const SO_DETACH_REUSEPORT_BPF: c_int = 68; // pub const SO_PREFER_BUSY_POLL: c_int = 69; // pub const SO_BUSY_POLL_BUDGET: c_int = 70; @@ -349,10 +359,17 @@ cfg_if! { } cfg_if! { - if #[cfg( + if #[cfg(all( any(target_arch = "mips", target_arch = "mips32r6"), - any(target_env = "gnu", target_env = "uclibc") - )] { + any(target_env = "uclibc", target_env = "gnu"), + linux_time_bits64 + ))] { + pub const RLIM_INFINITY: crate::rlim_t = !0; + } else if #[cfg(all( + any(target_arch = "mips", target_arch = "mips32r6"), + any(target_env = "uclibc", target_env = "gnu"), + not(linux_time_bits64) + ))] { pub const RLIM_INFINITY: crate::rlim_t = 0x7fffffff; } } diff --git a/src/unix/linux_like/linux/arch/powerpc/mod.rs b/src/unix/linux_like/linux/arch/powerpc/mod.rs index de39df0d8323..2e8d3e367539 100644 --- a/src/unix/linux_like/linux/arch/powerpc/mod.rs +++ b/src/unix/linux_like/linux/arch/powerpc/mod.rs @@ -24,8 +24,15 @@ pub const SO_REUSEPORT: c_int = 15; // powerpc only differs in these pub const SO_RCVLOWAT: c_int = 16; pub const SO_SNDLOWAT: c_int = 17; -pub const SO_RCVTIMEO: c_int = 18; -pub const SO_SNDTIMEO: c_int = 19; +cfg_if! { + if #[cfg(linux_time_bits64)] { + pub const SO_SNDTIMEO: c_int = 67; + pub const SO_RCVTIMEO: c_int = 66; + } else { + pub const SO_SNDTIMEO: c_int = 19; + pub const SO_RCVTIMEO: c_int = 18; + } +} // pub const SO_RCVTIMEO_OLD: c_int = 18; // pub const SO_SNDTIMEO_OLD: c_int = 19; pub const SO_PASSCRED: c_int = 20; @@ -39,18 +46,26 @@ pub const SO_ATTACH_FILTER: c_int = 26; pub const SO_DETACH_FILTER: c_int = 27; pub const SO_GET_FILTER: c_int = SO_ATTACH_FILTER; pub const SO_PEERNAME: c_int = 28; -pub const SO_TIMESTAMP: c_int = 29; -// pub const SO_TIMESTAMP_OLD: c_int = 29; +cfg_if! { + if #[cfg(linux_time_bits64)] { + pub const SO_TIMESTAMP: c_int = SO_TIMESTAMP_NEW; + pub const SO_TIMESTAMPNS: c_int = SO_TIMESTAMPNS_NEW; + pub const SO_TIMESTAMPING: c_int = SO_TIMESTAMPING_NEW; + } else { + pub const SO_TIMESTAMP: c_int = SO_TIMESTAMP_OLD; + pub const SO_TIMESTAMPNS: c_int = SO_TIMESTAMPNS_OLD; + pub const SO_TIMESTAMPING: c_int = SO_TIMESTAMPING_OLD; + } +} +const SO_TIMESTAMP_OLD: c_int = 29; +const SO_TIMESTAMPNS_OLD: c_int = 35; +const SO_TIMESTAMPING_OLD: c_int = 37; pub const SO_ACCEPTCONN: c_int = 30; pub const SO_PEERSEC: c_int = 31; pub const SO_SNDBUFFORCE: c_int = 32; pub const SO_RCVBUFFORCE: c_int = 33; pub const SO_PASSSEC: c_int = 34; -pub const SO_TIMESTAMPNS: c_int = 35; -// pub const SO_TIMESTAMPNS_OLD: c_int = 35; pub const SO_MARK: c_int = 36; -pub const SO_TIMESTAMPING: c_int = 37; -// pub const SO_TIMESTAMPING_OLD: c_int = 37; pub const SO_PROTOCOL: c_int = 38; pub const SO_DOMAIN: c_int = 39; pub const SO_RXQ_OVFL: c_int = 40; diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs index 23d5bec28697..996d09f01b7f 100644 --- a/src/unix/linux_like/linux/mod.rs +++ b/src/unix/linux_like/linux/mod.rs @@ -326,7 +326,21 @@ s! { } pub struct input_event { + // FIXME(1.0): Change to the commented variant, see https://github.com/rust-lang/libc/pull/4148#discussion_r1857511742 + #[cfg(any(target_pointer_width = "64", not(linux_time_bits64)))] pub time: crate::timeval, + // #[cfg(any(target_pointer_width = "64", not(linux_time_bits64)))] + // pub input_event_sec: time_t, + // #[cfg(any(target_pointer_width = "64", not(linux_time_bits64)))] + // pub input_event_usec: suseconds_t, + // #[cfg(target_arch = "sparc64")] + // _pad1: c_int, + #[cfg(all(target_pointer_width = "32", linux_time_bits64))] + pub input_event_sec: c_ulong, + + #[cfg(all(target_pointer_width = "32", linux_time_bits64))] + pub input_event_usec: c_ulong, + pub type_: __u16, pub code: __u16, pub value: __s32, diff --git a/src/unix/mod.rs b/src/unix/mod.rs index 9154a0c43cfb..bb0bf8f3a3b2 100644 --- a/src/unix/mod.rs +++ b/src/unix/mod.rs @@ -66,6 +66,7 @@ s! { pub modtime: time_t, } + // FIXME(time): Needs updates at least for glibc _TIME_BITS=64 pub struct timeval { pub tv_sec: time_t, pub tv_usec: suseconds_t,