Skip to content

Commit

Permalink
Merge pull request #4280 from tgross35/backport-time-b64
Browse files Browse the repository at this point in the history
[0.2] `RUST_LIBC_UNSTABLE_LINUX_TIME_BITS64` backports
  • Loading branch information
tgross35 authored Feb 22, 2025
2 parents 54e923a + 8b0ab16 commit b1d4d35
Show file tree
Hide file tree
Showing 13 changed files with 134 additions and 46 deletions.
8 changes: 8 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const ALLOWED_CFGS: &'static [&'static str] = &[
"libc_deny_warnings",
"libc_thread_local",
"libc_ctest",
// Corresponds to `__USE_TIME_BITS64` in UAPI
"linux_time_bits64",
];

// Extra values to allow for check-cfg.
Expand Down Expand Up @@ -79,6 +81,12 @@ fn main() {
_ => (),
}

let linux_time_bits64 = env::var("RUST_LIBC_UNSTABLE_LINUX_TIME_BITS64").is_ok();
println!("cargo:rerun-if-env-changed=RUST_LIBC_UNSTABLE_LINUX_TIME_BITS64");
if linux_time_bits64 {
set_cfg("linux_time_bits64");
}

// On CI: deny all warnings
if libc_ci {
set_cfg("libc_deny_warnings");
Expand Down
5 changes: 5 additions & 0 deletions ci/verify-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ test_target() {
$cmd --features const-extern-fn
$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
Expand Down
1 change: 0 additions & 1 deletion libc-test/semver/TODO-linux.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion libc-test/semver/linux-loongarch64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion libc-test/semver/linux-powerpc64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion libc-test/semver/linux-powerpc64le.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion libc-test/semver/linux-riscv64gc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions libc-test/semver/linux.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2964,6 +2964,7 @@ SO_RXQ_OVFL
SO_SNDBUFFORCE
SO_TIMESTAMP
SO_TIMESTAMPING
SO_TIMESTAMPNS
SPLICE_F_GIFT
SPLICE_F_MORE
SPLICE_F_MOVE
Expand Down
47 changes: 37 additions & 10 deletions src/unix/linux_like/linux/arch/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -52,18 +50,46 @@ 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"),
not(any(target_env = "musl", target_env = "ohos"))
))] {
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 if #[cfg(all(
linux_time_bits64,
any(target_arch = "arm", target_arch = "x86"),
any(target_env = "musl", target_env = "ohos")
))] {
pub const SO_TIMESTAMP: c_int = 63;
pub const SO_TIMESTAMPNS: c_int = 64;
pub const SO_TIMESTAMPING: c_int = 65;
pub const SO_RCVTIMEO: c_int = 66;
pub const SO_SNDTIMEO: c_int = 67;
} 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;
Expand Down Expand Up @@ -99,6 +125,7 @@ cfg_if! {
any(
target_arch = "x86",
target_arch = "x86_64",
target_arch = "arm",
target_arch = "aarch64",
target_arch = "csky",
target_arch = "loongarch64"
Expand Down
58 changes: 40 additions & 18 deletions src/unix/linux_like/linux/arch/mips/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -91,17 +98,25 @@ 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_RCVTIMEO_NEW: c_int = 66;
const SO_SNDTIMEO_NEW: c_int = 67;
const SO_TIMESTAMPNS_OLD: c_int = 35;
const SO_TIMESTAMPING_OLD: c_int = 37;
const SO_TIMESTAMP_NEW: c_int = 63;
const SO_TIMESTAMPNS_NEW: c_int = 64;
const SO_TIMESTAMPING_NEW: c_int = 65;
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;
Expand Down Expand Up @@ -349,10 +364,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;
}
}
41 changes: 28 additions & 13 deletions src/unix/linux_like/linux/arch/powerpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -79,11 +94,11 @@ pub const SO_ZEROCOPY: c_int = 60;
pub const SO_TXTIME: c_int = 61;
pub const SCM_TXTIME: c_int = SO_TXTIME;
pub const SO_BINDTOIFINDEX: c_int = 62;
// 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_NEW: c_int = 63;
const SO_TIMESTAMPNS_NEW: c_int = 64;
const SO_TIMESTAMPING_NEW: c_int = 65;
const SO_RCVTIMEO_NEW: c_int = 66;
const SO_SNDTIMEO_NEW: c_int = 67;
// 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;
Expand Down
14 changes: 14 additions & 0 deletions src/unix/linux_like/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,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,
Expand Down
1 change: 1 addition & 0 deletions src/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,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,
Expand Down

0 comments on commit b1d4d35

Please sign in to comment.