Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new cfg linux_time_bits64 corresponding to __USE_TIME_BITS64 #4148

Merged
merged 5 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
tgross35 marked this conversation as resolved.
Show resolved Hide resolved
];

// Extra values to allow for check-cfg.
Expand All @@ -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.
Expand Down Expand Up @@ -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");
Expand Down
5 changes: 5 additions & 0 deletions ci/verify-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 @@ -2955,6 +2955,7 @@ SO_RXQ_OVFL
SO_SNDBUFFORCE
SO_TIMESTAMP
SO_TIMESTAMPING
SO_TIMESTAMPNS
SPLICE_F_GIFT
SPLICE_F_MORE
SPLICE_F_MOVE
Expand Down
35 changes: 25 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,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;
Expand Down
53 changes: 35 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,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;
Expand Down Expand Up @@ -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;
}
}
31 changes: 23 additions & 8 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
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 @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading