Skip to content

Commit b1d4d35

Browse files
authored
Merge pull request rust-lang#4280 from tgross35/backport-time-b64
[0.2] `RUST_LIBC_UNSTABLE_LINUX_TIME_BITS64` backports
2 parents 54e923a + 8b0ab16 commit b1d4d35

File tree

13 files changed

+134
-46
lines changed

13 files changed

+134
-46
lines changed

build.rs

+8
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ const ALLOWED_CFGS: &'static [&'static str] = &[
1818
"libc_deny_warnings",
1919
"libc_thread_local",
2020
"libc_ctest",
21+
// Corresponds to `__USE_TIME_BITS64` in UAPI
22+
"linux_time_bits64",
2123
];
2224

2325
// Extra values to allow for check-cfg.
@@ -79,6 +81,12 @@ fn main() {
7981
_ => (),
8082
}
8183

84+
let linux_time_bits64 = env::var("RUST_LIBC_UNSTABLE_LINUX_TIME_BITS64").is_ok();
85+
println!("cargo:rerun-if-env-changed=RUST_LIBC_UNSTABLE_LINUX_TIME_BITS64");
86+
if linux_time_bits64 {
87+
set_cfg("linux_time_bits64");
88+
}
89+
8290
// On CI: deny all warnings
8391
if libc_ci {
8492
set_cfg("libc_deny_warnings");

ci/verify-build.sh

+5
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ test_target() {
7272
$cmd --features const-extern-fn
7373
$cmd --features extra_traits
7474

75+
if [ "$os" = "linux" ]; then
76+
# Test with the equivalent of __USE_TIME_BITS64
77+
RUST_LIBC_UNSTABLE_LINUX_TIME_BITS64=1 $cmd
78+
fi
79+
7580
# Test again without default features, i.e. without "std"
7681
$cmd --no-default-features
7782
$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
@@ -2964,6 +2964,7 @@ SO_RXQ_OVFL
29642964
SO_SNDBUFFORCE
29652965
SO_TIMESTAMP
29662966
SO_TIMESTAMPING
2967+
SO_TIMESTAMPNS
29672968
SPLICE_F_GIFT
29682969
SPLICE_F_MORE
29692970
SPLICE_F_MOVE

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

+37-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,46 @@ 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+
not(any(target_env = "musl", target_env = "ohos"))
62+
))] {
63+
pub const SO_TIMESTAMP: c_int = SO_TIMESTAMP_NEW;
64+
pub const SO_TIMESTAMPNS: c_int = SO_TIMESTAMPNS_NEW;
65+
pub const SO_TIMESTAMPING: c_int = SO_TIMESTAMPING_NEW;
66+
pub const SO_RCVTIMEO: c_int = SO_RCVTIMEO_NEW;
67+
pub const SO_SNDTIMEO: c_int = SO_SNDTIMEO_NEW;
68+
} else if #[cfg(all(
69+
linux_time_bits64,
70+
any(target_arch = "arm", target_arch = "x86"),
71+
any(target_env = "musl", target_env = "ohos")
72+
))] {
73+
pub const SO_TIMESTAMP: c_int = 63;
74+
pub const SO_TIMESTAMPNS: c_int = 64;
75+
pub const SO_TIMESTAMPING: c_int = 65;
76+
pub const SO_RCVTIMEO: c_int = 66;
77+
pub const SO_SNDTIMEO: c_int = 67;
78+
} else {
79+
pub const SO_TIMESTAMP: c_int = SO_TIMESTAMP_OLD;
80+
pub const SO_TIMESTAMPNS: c_int = SO_TIMESTAMPNS_OLD;
81+
pub const SO_TIMESTAMPING: c_int = SO_TIMESTAMPING_OLD;
82+
pub const SO_RCVTIMEO: c_int = SO_RCVTIMEO_OLD;
83+
pub const SO_SNDTIMEO: c_int = SO_SNDTIMEO_OLD;
84+
}
85+
}
86+
5787
pub const SO_ACCEPTCONN: c_int = 30;
5888
pub const SO_PEERSEC: c_int = 31;
5989
pub const SO_SNDBUFFORCE: c_int = 32;
6090
pub const SO_RCVBUFFORCE: c_int = 33;
6191
pub const SO_PASSSEC: c_int = 34;
62-
pub const SO_TIMESTAMPNS: c_int = 35;
63-
// pub const SO_TIMESTAMPNS_OLD: c_int = 35;
6492
pub const SO_MARK: c_int = 36;
65-
pub const SO_TIMESTAMPING: c_int = 37;
66-
// pub const SO_TIMESTAMPING_OLD: c_int = 37;
6793
pub const SO_PROTOCOL: c_int = 38;
6894
pub const SO_DOMAIN: c_int = 39;
6995
pub const SO_RXQ_OVFL: c_int = 40;
@@ -99,6 +125,7 @@ cfg_if! {
99125
any(
100126
target_arch = "x86",
101127
target_arch = "x86_64",
128+
target_arch = "arm",
102129
target_arch = "aarch64",
103130
target_arch = "csky",
104131
target_arch = "loongarch64"

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

+40-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,25 @@ 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_RCVTIMEO_NEW: c_int = 66;
103+
const SO_SNDTIMEO_NEW: c_int = 67;
104+
const SO_TIMESTAMPNS_OLD: c_int = 35;
105+
const SO_TIMESTAMPING_OLD: c_int = 37;
106+
const SO_TIMESTAMP_NEW: c_int = 63;
107+
const SO_TIMESTAMPNS_NEW: c_int = 64;
108+
const SO_TIMESTAMPING_NEW: c_int = 65;
109+
cfg_if! {
110+
if #[cfg(linux_time_bits64)] {
111+
pub const SO_TIMESTAMP: c_int = SO_TIMESTAMP_NEW;
112+
pub const SO_TIMESTAMPNS: c_int = SO_TIMESTAMPNS_NEW;
113+
pub const SO_TIMESTAMPING: c_int = SO_TIMESTAMPING_NEW;
114+
} else {
115+
pub const SO_TIMESTAMP: c_int = SO_TIMESTAMP_OLD;
116+
pub const SO_TIMESTAMPNS: c_int = SO_TIMESTAMPNS_OLD;
117+
pub const SO_TIMESTAMPING: c_int = SO_TIMESTAMPING_OLD;
118+
}
119+
}
105120
// pub const SO_DETACH_REUSEPORT_BPF: c_int = 68;
106121
// pub const SO_PREFER_BUSY_POLL: c_int = 69;
107122
// pub const SO_BUSY_POLL_BUDGET: c_int = 70;
@@ -349,10 +364,17 @@ cfg_if! {
349364
}
350365

351366
cfg_if! {
352-
if #[cfg(
367+
if #[cfg(all(
353368
any(target_arch = "mips", target_arch = "mips32r6"),
354-
any(target_env = "gnu", target_env = "uclibc")
355-
)] {
369+
any(target_env = "uclibc", target_env = "gnu"),
370+
linux_time_bits64
371+
))] {
372+
pub const RLIM_INFINITY: crate::rlim_t = !0;
373+
} else if #[cfg(all(
374+
any(target_arch = "mips", target_arch = "mips32r6"),
375+
any(target_env = "uclibc", target_env = "gnu"),
376+
not(linux_time_bits64)
377+
))] {
356378
pub const RLIM_INFINITY: crate::rlim_t = 0x7fffffff;
357379
}
358380
}

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

+28-13
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;
@@ -79,11 +94,11 @@ pub const SO_ZEROCOPY: c_int = 60;
7994
pub const SO_TXTIME: c_int = 61;
8095
pub const SCM_TXTIME: c_int = SO_TXTIME;
8196
pub const SO_BINDTOIFINDEX: c_int = 62;
82-
// pub const SO_TIMESTAMP_NEW: c_int = 63;
83-
// pub const SO_TIMESTAMPNS_NEW: c_int = 64;
84-
// pub const SO_TIMESTAMPING_NEW: c_int = 65;
85-
// pub const SO_RCVTIMEO_NEW: c_int = 66;
86-
// pub const SO_SNDTIMEO_NEW: c_int = 67;
97+
const SO_TIMESTAMP_NEW: c_int = 63;
98+
const SO_TIMESTAMPNS_NEW: c_int = 64;
99+
const SO_TIMESTAMPING_NEW: c_int = 65;
100+
const SO_RCVTIMEO_NEW: c_int = 66;
101+
const SO_SNDTIMEO_NEW: c_int = 67;
87102
// pub const SO_DETACH_REUSEPORT_BPF: c_int = 68;
88103
// pub const SO_PREFER_BUSY_POLL: c_int = 69;
89104
// pub const SO_BUSY_POLL_BUDGET: c_int = 70;

src/unix/linux_like/linux/mod.rs

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

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

src/unix/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ s! {
5656
pub modtime: time_t,
5757
}
5858

59+
// FIXME(time): Needs updates at least for glibc _TIME_BITS=64
5960
pub struct timeval {
6061
pub tv_sec: time_t,
6162
pub tv_usec: suseconds_t,

0 commit comments

Comments
 (0)