Skip to content

Commit 3b458ff

Browse files
authored
Merge pull request #4148 from snogge/linux_time_bits64
Add new cfg linux_time_bits64 corresponding to __USE_TIME_BITS64
2 parents fe783ce + c201302 commit 3b458ff

File tree

13 files changed

+111
-41
lines changed

13 files changed

+111
-41
lines changed

build.rs

+7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ const ALLOWED_CFGS: &'static [&'static str] = &[
1717
"libc_const_extern_fn",
1818
"libc_deny_warnings",
1919
"libc_ctest",
20+
// Corresponds to `__USE_TIME_BITS64` in UAPI
21+
"linux_time_bits64",
2022
];
2123

2224
// Extra values to allow for check-cfg.
@@ -42,6 +44,7 @@ fn main() {
4244
let rustc_dep_of_std = env::var("CARGO_FEATURE_RUSTC_DEP_OF_STD").is_ok();
4345
let libc_ci = env::var("LIBC_CI").is_ok();
4446
let libc_check_cfg = env::var("LIBC_CHECK_CFG").is_ok() || rustc_minor_ver >= 80;
47+
let linux_time_bits64 = env::var("RUST_LIBC_UNSTABLE_LINUX_TIME_BITS64").is_ok();
4548

4649
// The ABI of libc used by std is backward compatible with FreeBSD 12.
4750
// The ABI of libc from crates.io is backward compatible with FreeBSD 12.
@@ -78,6 +81,10 @@ fn main() {
7881
Some(_) | None => (),
7982
}
8083

84+
if linux_time_bits64 {
85+
set_cfg("linux_time_bits64");
86+
}
87+
8188
// On CI: deny all warnings
8289
if libc_ci {
8390
set_cfg("libc_deny_warnings");

ci/verify-build.sh

+5
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ test_target() {
7171
$cmd
7272
$cmd --features extra_traits
7373

74+
if [ "$os" = "linux" ]; then
75+
# Test with the equivalent of __USE_TIME_BITS64
76+
RUST_LIBC_UNSTABLE_LINUX_TIME_BITS64=1 $cmd
77+
fi
78+
7479
# Test again without default features, i.e. without "std"
7580
$cmd --no-default-features
7681
$cmd --no-default-features --features extra_traits

libc-test/semver/TODO-linux.txt

-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ SO_SELECT_ERR_QUEUE
5454
SO_SNDTIMEO_NEW
5555
SO_STYLE
5656
SO_TIMESTAMPING_NEW
57-
SO_TIMESTAMPNS
5857
SO_TIMESTAMPNS_NEW
5958
SO_TIMESTAMP_NEW
6059
SO_TXTIME

libc-test/semver/linux-loongarch64.txt

-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ SO_SECURITY_AUTHENTICATION
8787
SO_SECURITY_ENCRYPTION_NETWORK
8888
SO_SECURITY_ENCRYPTION_TRANSPORT
8989
SO_SELECT_ERR_QUEUE
90-
SO_TIMESTAMPNS
9190
SO_WIFI_STATUS
9291
SYS_accept
9392
SYS_msgctl

libc-test/semver/linux-powerpc64.txt

-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ SO_SECURITY_AUTHENTICATION
4848
SO_SECURITY_ENCRYPTION_NETWORK
4949
SO_SECURITY_ENCRYPTION_TRANSPORT
5050
SO_SELECT_ERR_QUEUE
51-
SO_TIMESTAMPNS
5251
SO_WIFI_STATUS
5352
SYS__llseek
5453
SYS__newselect

libc-test/semver/linux-powerpc64le.txt

-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ SO_SECURITY_AUTHENTICATION
4646
SO_SECURITY_ENCRYPTION_NETWORK
4747
SO_SECURITY_ENCRYPTION_TRANSPORT
4848
SO_SELECT_ERR_QUEUE
49-
SO_TIMESTAMPNS
5049
SO_WIFI_STATUS
5150
SYS__llseek
5251
SYS__newselect

libc-test/semver/linux-riscv64gc.txt

-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ SO_SECURITY_AUTHENTICATION
5151
SO_SECURITY_ENCRYPTION_NETWORK
5252
SO_SECURITY_ENCRYPTION_TRANSPORT
5353
SO_SELECT_ERR_QUEUE
54-
SO_TIMESTAMPNS
5554
SO_WIFI_STATUS
5655
SYS_accept
5756
SYS_fadvise64

libc-test/semver/linux.txt

+1
Original file line numberDiff line numberDiff line change
@@ -2955,6 +2955,7 @@ SO_RXQ_OVFL
29552955
SO_SNDBUFFORCE
29562956
SO_TIMESTAMP
29572957
SO_TIMESTAMPING
2958+
SO_TIMESTAMPNS
29582959
SPLICE_F_GIFT
29592960
SPLICE_F_MORE
29602961
SPLICE_F_MOVE

src/unix/linux_like/linux/arch/generic/mod.rs

+25-10
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,8 @@ pub const SO_PASSCRED: c_int = 16;
4040
pub const SO_PEERCRED: c_int = 17;
4141
pub const SO_RCVLOWAT: c_int = 18;
4242
pub const SO_SNDLOWAT: c_int = 19;
43-
pub const SO_RCVTIMEO: c_int = 20;
44-
pub const SO_SNDTIMEO: c_int = 21;
45-
// pub const SO_RCVTIMEO_OLD: c_int = 20;
46-
// pub const SO_SNDTIMEO_OLD: c_int = 21;
43+
const SO_RCVTIMEO_OLD: c_int = 20;
44+
const SO_SNDTIMEO_OLD: c_int = 21;
4745
pub const SO_SECURITY_AUTHENTICATION: c_int = 22;
4846
pub const SO_SECURITY_ENCRYPTION_TRANSPORT: c_int = 23;
4947
pub const SO_SECURITY_ENCRYPTION_NETWORK: c_int = 24;
@@ -52,18 +50,35 @@ pub const SO_ATTACH_FILTER: c_int = 26;
5250
pub const SO_DETACH_FILTER: c_int = 27;
5351
pub const SO_GET_FILTER: c_int = SO_ATTACH_FILTER;
5452
pub const SO_PEERNAME: c_int = 28;
55-
pub const SO_TIMESTAMP: c_int = 29;
56-
// pub const SO_TIMESTAMP_OLD: c_int = 29;
53+
const SO_TIMESTAMP_OLD: c_int = 29;
54+
const SO_TIMESTAMPNS_OLD: c_int = 35;
55+
const SO_TIMESTAMPING_OLD: c_int = 37;
56+
57+
cfg_if! {
58+
if #[cfg(all(
59+
linux_time_bits64,
60+
any(target_arch = "arm", target_arch = "x86")
61+
))] {
62+
pub const SO_TIMESTAMP: c_int = SO_TIMESTAMP_NEW;
63+
pub const SO_TIMESTAMPNS: c_int = SO_TIMESTAMPNS_NEW;
64+
pub const SO_TIMESTAMPING: c_int = SO_TIMESTAMPING_NEW;
65+
pub const SO_RCVTIMEO: c_int = SO_RCVTIMEO_NEW;
66+
pub const SO_SNDTIMEO: c_int = SO_SNDTIMEO_NEW;
67+
} else {
68+
pub const SO_TIMESTAMP: c_int = SO_TIMESTAMP_OLD;
69+
pub const SO_TIMESTAMPNS: c_int = SO_TIMESTAMPNS_OLD;
70+
pub const SO_TIMESTAMPING: c_int = SO_TIMESTAMPING_OLD;
71+
pub const SO_RCVTIMEO: c_int = SO_RCVTIMEO_OLD;
72+
pub const SO_SNDTIMEO: c_int = SO_SNDTIMEO_OLD;
73+
}
74+
}
75+
5776
pub const SO_ACCEPTCONN: c_int = 30;
5877
pub const SO_PEERSEC: c_int = 31;
5978
pub const SO_SNDBUFFORCE: c_int = 32;
6079
pub const SO_RCVBUFFORCE: c_int = 33;
6180
pub const SO_PASSSEC: c_int = 34;
62-
pub const SO_TIMESTAMPNS: c_int = 35;
63-
// pub const SO_TIMESTAMPNS_OLD: c_int = 35;
6481
pub const SO_MARK: c_int = 36;
65-
pub const SO_TIMESTAMPING: c_int = 37;
66-
// pub const SO_TIMESTAMPING_OLD: c_int = 37;
6782
pub const SO_PROTOCOL: c_int = 38;
6883
pub const SO_DOMAIN: c_int = 39;
6984
pub const SO_RXQ_OVFL: c_int = 40;

src/unix/linux_like/linux/arch/mips/mod.rs

+35-18
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,17 @@ pub const SO_RCVLOWAT: c_int = 0x1004;
3636
// NOTE: These definitions are now being renamed with _OLD postfix,
3737
// but CI haven't support them yet.
3838
// Some related consts could be found in b32.rs and b64.rs
39-
pub const SO_SNDTIMEO: c_int = 0x1005;
40-
pub const SO_RCVTIMEO: c_int = 0x1006;
41-
// pub const SO_SNDTIMEO_OLD: c_int = 0x1005;
42-
// pub const SO_RCVTIMEO_OLD: c_int = 0x1006;
39+
const SO_SNDTIMEO_OLD: c_int = 0x1005;
40+
const SO_RCVTIMEO_OLD: c_int = 0x1006;
41+
cfg_if! {
42+
if #[cfg(linux_time_bits64)] {
43+
pub const SO_SNDTIMEO: c_int = SO_SNDTIMEO_NEW;
44+
pub const SO_RCVTIMEO: c_int = SO_RCVTIMEO_NEW;
45+
} else {
46+
pub const SO_SNDTIMEO: c_int = SO_SNDTIMEO_OLD;
47+
pub const SO_RCVTIMEO: c_int = SO_RCVTIMEO_OLD;
48+
}
49+
}
4350
pub const SO_ACCEPTCONN: c_int = 0x1009;
4451
pub const SO_PROTOCOL: c_int = 0x1028;
4552
pub const SO_DOMAIN: c_int = 0x1029;
@@ -91,17 +98,20 @@ pub const SO_BINDTOIFINDEX: c_int = 62;
9198
// NOTE: These definitions are now being renamed with _OLD postfix,
9299
// but CI haven't support them yet.
93100
// Some related consts could be found in b32.rs and b64.rs
94-
pub const SO_TIMESTAMP: c_int = 29;
95-
pub const SO_TIMESTAMPNS: c_int = 35;
96-
pub const SO_TIMESTAMPING: c_int = 37;
97-
// pub const SO_TIMESTAMP_OLD: c_int = 29;
98-
// pub const SO_TIMESTAMPNS_OLD: c_int = 35;
99-
// pub const SO_TIMESTAMPING_OLD: c_int = 37;
100-
// pub const SO_TIMESTAMP_NEW: c_int = 63;
101-
// pub const SO_TIMESTAMPNS_NEW: c_int = 64;
102-
// pub const SO_TIMESTAMPING_NEW: c_int = 65;
103-
// pub const SO_RCVTIMEO_NEW: c_int = 66;
104-
// pub const SO_SNDTIMEO_NEW: c_int = 67;
101+
const SO_TIMESTAMP_OLD: c_int = 29;
102+
const SO_TIMESTAMPNS_OLD: c_int = 35;
103+
const SO_TIMESTAMPING_OLD: c_int = 37;
104+
cfg_if! {
105+
if #[cfg(linux_time_bits64)] {
106+
pub const SO_TIMESTAMP: c_int = SO_TIMESTAMP_NEW;
107+
pub const SO_TIMESTAMPNS: c_int = SO_TIMESTAMPNS_NEW;
108+
pub const SO_TIMESTAMPING: c_int = SO_TIMESTAMPING_NEW;
109+
} else {
110+
pub const SO_TIMESTAMP: c_int = SO_TIMESTAMP_OLD;
111+
pub const SO_TIMESTAMPNS: c_int = SO_TIMESTAMPNS_OLD;
112+
pub const SO_TIMESTAMPING: c_int = SO_TIMESTAMPING_OLD;
113+
}
114+
}
105115
// pub const SO_DETACH_REUSEPORT_BPF: c_int = 68;
106116
// pub const SO_PREFER_BUSY_POLL: c_int = 69;
107117
// pub const SO_BUSY_POLL_BUDGET: c_int = 70;
@@ -349,10 +359,17 @@ cfg_if! {
349359
}
350360

351361
cfg_if! {
352-
if #[cfg(
362+
if #[cfg(all(
353363
any(target_arch = "mips", target_arch = "mips32r6"),
354-
any(target_env = "gnu", target_env = "uclibc")
355-
)] {
364+
any(target_env = "uclibc", target_env = "gnu"),
365+
linux_time_bits64
366+
))] {
367+
pub const RLIM_INFINITY: crate::rlim_t = !0;
368+
} else if #[cfg(all(
369+
any(target_arch = "mips", target_arch = "mips32r6"),
370+
any(target_env = "uclibc", target_env = "gnu"),
371+
not(linux_time_bits64)
372+
))] {
356373
pub const RLIM_INFINITY: crate::rlim_t = 0x7fffffff;
357374
}
358375
}

src/unix/linux_like/linux/arch/powerpc/mod.rs

+23-8
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,15 @@ pub const SO_REUSEPORT: c_int = 15;
2424
// powerpc only differs in these
2525
pub const SO_RCVLOWAT: c_int = 16;
2626
pub const SO_SNDLOWAT: c_int = 17;
27-
pub const SO_RCVTIMEO: c_int = 18;
28-
pub const SO_SNDTIMEO: c_int = 19;
27+
cfg_if! {
28+
if #[cfg(linux_time_bits64)] {
29+
pub const SO_SNDTIMEO: c_int = 67;
30+
pub const SO_RCVTIMEO: c_int = 66;
31+
} else {
32+
pub const SO_SNDTIMEO: c_int = 19;
33+
pub const SO_RCVTIMEO: c_int = 18;
34+
}
35+
}
2936
// pub const SO_RCVTIMEO_OLD: c_int = 18;
3037
// pub const SO_SNDTIMEO_OLD: c_int = 19;
3138
pub const SO_PASSCRED: c_int = 20;
@@ -39,18 +46,26 @@ pub const SO_ATTACH_FILTER: c_int = 26;
3946
pub const SO_DETACH_FILTER: c_int = 27;
4047
pub const SO_GET_FILTER: c_int = SO_ATTACH_FILTER;
4148
pub const SO_PEERNAME: c_int = 28;
42-
pub const SO_TIMESTAMP: c_int = 29;
43-
// pub const SO_TIMESTAMP_OLD: c_int = 29;
49+
cfg_if! {
50+
if #[cfg(linux_time_bits64)] {
51+
pub const SO_TIMESTAMP: c_int = SO_TIMESTAMP_NEW;
52+
pub const SO_TIMESTAMPNS: c_int = SO_TIMESTAMPNS_NEW;
53+
pub const SO_TIMESTAMPING: c_int = SO_TIMESTAMPING_NEW;
54+
} else {
55+
pub const SO_TIMESTAMP: c_int = SO_TIMESTAMP_OLD;
56+
pub const SO_TIMESTAMPNS: c_int = SO_TIMESTAMPNS_OLD;
57+
pub const SO_TIMESTAMPING: c_int = SO_TIMESTAMPING_OLD;
58+
}
59+
}
60+
const SO_TIMESTAMP_OLD: c_int = 29;
61+
const SO_TIMESTAMPNS_OLD: c_int = 35;
62+
const SO_TIMESTAMPING_OLD: c_int = 37;
4463
pub const SO_ACCEPTCONN: c_int = 30;
4564
pub const SO_PEERSEC: c_int = 31;
4665
pub const SO_SNDBUFFORCE: c_int = 32;
4766
pub const SO_RCVBUFFORCE: c_int = 33;
4867
pub const SO_PASSSEC: c_int = 34;
49-
pub const SO_TIMESTAMPNS: c_int = 35;
50-
// pub const SO_TIMESTAMPNS_OLD: c_int = 35;
5168
pub const SO_MARK: c_int = 36;
52-
pub const SO_TIMESTAMPING: c_int = 37;
53-
// pub const SO_TIMESTAMPING_OLD: c_int = 37;
5469
pub const SO_PROTOCOL: c_int = 38;
5570
pub const SO_DOMAIN: c_int = 39;
5671
pub const SO_RXQ_OVFL: c_int = 40;

src/unix/linux_like/linux/mod.rs

+14
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,21 @@ s! {
326326
}
327327

328328
pub struct input_event {
329+
// FIXME(1.0): Change to the commented variant, see https://github.com/rust-lang/libc/pull/4148#discussion_r1857511742
330+
#[cfg(any(target_pointer_width = "64", not(linux_time_bits64)))]
329331
pub time: crate::timeval,
332+
// #[cfg(any(target_pointer_width = "64", not(linux_time_bits64)))]
333+
// pub input_event_sec: time_t,
334+
// #[cfg(any(target_pointer_width = "64", not(linux_time_bits64)))]
335+
// pub input_event_usec: suseconds_t,
336+
// #[cfg(target_arch = "sparc64")]
337+
// _pad1: c_int,
338+
#[cfg(all(target_pointer_width = "32", linux_time_bits64))]
339+
pub input_event_sec: c_ulong,
340+
341+
#[cfg(all(target_pointer_width = "32", linux_time_bits64))]
342+
pub input_event_usec: c_ulong,
343+
330344
pub type_: __u16,
331345
pub code: __u16,
332346
pub value: __s32,

src/unix/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ s! {
6666
pub modtime: time_t,
6767
}
6868

69+
// FIXME(time): Needs updates at least for glibc _TIME_BITS=64
6970
pub struct timeval {
7071
pub tv_sec: time_t,
7172
pub tv_usec: suseconds_t,

0 commit comments

Comments
 (0)