Skip to content

Commit af0a837

Browse files
authored
On Linux, require Linux >= 3.2. (#927)
Add a Minimum Linux Version policy, which is currently Linux 3.2, and enable `ClockId::Boottime` and other values without extra feature gates. Fixes #905. Fixes #907.
1 parent 5ee3917 commit af0a837

File tree

8 files changed

+40
-35
lines changed

8 files changed

+40
-35
lines changed

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,23 @@ safety types rather than `RawFd`, and the flags parameters to functions such as
147147
## Minimum Supported Rust Version (MSRV)
148148

149149
This crate currently works on the version of [Rust on Debian stable], which is
150-
currently Rust 1.63. This policy may change in the future, in minor version
150+
currently [Rust 1.63]. This policy may change in the future, in minor version
151151
releases, so users using a fixed version of Rust should pin to a specific
152152
version of this crate.
153153

154+
## Minimum Linux Version
155+
156+
On Linux platforms, rustix requires at least Linux 3.2. This is at most the
157+
oldest Linux version supported by:
158+
- [any current Rust target], or
159+
- [kernel.org] at the time of rustix's [MSRV] release.
160+
The specifics of this policy may change in the future, but we intend it to
161+
always reflect “very old” Linux versions.
162+
163+
[MSRV]: #minimum-supported-rust-version-msrv
164+
[Rust 1.63]: https://blog.rust-lang.org/2022/08/11/Rust-1.63.0.html
165+
[any current Rust target]: https://doc.rust-lang.org/nightly/rustc/platform-support.html
166+
[kernel.org]: https://www.kernel.org/releases.html
154167
[Rust on Debian stable]: https://packages.debian.org/stable/rust/rustc
155168
[`nix`]: https://crates.io/crates/nix
156169
[`unix`]: https://crates.io/crates/unix

src/backend/libc/mm/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,10 +383,10 @@ pub enum Advice {
383383
/// `MADV_UNMERGEABLE`
384384
#[cfg(linux_kernel)]
385385
LinuxUnmergeable = bitcast!(c::MADV_UNMERGEABLE),
386-
/// `MADV_HUGEPAGE` (since Linux 2.6.38)
386+
/// `MADV_HUGEPAGE`
387387
#[cfg(linux_kernel)]
388388
LinuxHugepage = bitcast!(c::MADV_HUGEPAGE),
389-
/// `MADV_NOHUGEPAGE` (since Linux 2.6.38)
389+
/// `MADV_NOHUGEPAGE`
390390
#[cfg(linux_kernel)]
391391
LinuxNoHugepage = bitcast!(c::MADV_NOHUGEPAGE),
392392
/// `MADV_DONTDUMP` (since Linux 3.4)

src/backend/linux_raw/c.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,13 +269,13 @@ pub(crate) const CLOCK_THREAD_CPUTIME_ID: c_int =
269269
linux_raw_sys::general::CLOCK_THREAD_CPUTIME_ID as _;
270270
pub(crate) const CLOCK_PROCESS_CPUTIME_ID: c_int =
271271
linux_raw_sys::general::CLOCK_PROCESS_CPUTIME_ID as _;
272-
#[cfg(all(feature = "time", feature = "linux_4_11"))]
272+
#[cfg(any(feature = "thread", feature = "time", target_arch = "x86"))]
273273
pub(crate) const CLOCK_BOOTTIME: c_int = linux_raw_sys::general::CLOCK_BOOTTIME as _;
274-
#[cfg(all(feature = "time", feature = "linux_4_11"))]
274+
#[cfg(any(feature = "thread", feature = "time", target_arch = "x86"))]
275275
pub(crate) const CLOCK_BOOTTIME_ALARM: c_int = linux_raw_sys::general::CLOCK_BOOTTIME_ALARM as _;
276-
#[cfg(all(feature = "time", feature = "linux_4_11"))]
276+
#[cfg(any(feature = "thread", feature = "time", target_arch = "x86"))]
277277
pub(crate) const CLOCK_TAI: c_int = linux_raw_sys::general::CLOCK_TAI as _;
278-
#[cfg(all(feature = "time", feature = "linux_4_11"))]
278+
#[cfg(any(feature = "thread", feature = "time", target_arch = "x86"))]
279279
pub(crate) const CLOCK_REALTIME_ALARM: c_int = linux_raw_sys::general::CLOCK_REALTIME_ALARM as _;
280280

281281
#[cfg(feature = "system")]

src/backend/linux_raw/fs/types.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,13 @@ bitflags! {
197197
/// `O_DIRECTORY`
198198
const DIRECTORY = linux_raw_sys::general::O_DIRECTORY;
199199

200-
/// `O_DSYNC`. Linux 2.6.32 only supports `O_SYNC`.
200+
/// `O_DSYNC`.
201201
const DSYNC = linux_raw_sys::general::O_SYNC;
202202

203203
/// `O_EXCL`
204204
const EXCL = linux_raw_sys::general::O_EXCL;
205205

206-
/// `O_FSYNC`. Linux 2.6.32 only supports `O_SYNC`.
206+
/// `O_FSYNC`.
207207
const FSYNC = linux_raw_sys::general::O_SYNC;
208208

209209
/// `O_NOFOLLOW`
@@ -226,7 +226,7 @@ bitflags! {
226226
/// `O_NOCTTY`
227227
const NOCTTY = linux_raw_sys::general::O_NOCTTY;
228228

229-
/// `O_RSYNC`. Linux 2.6.32 only supports `O_SYNC`.
229+
/// `O_RSYNC`.
230230
const RSYNC = linux_raw_sys::general::O_SYNC;
231231

232232
/// `O_SYNC`

src/backend/linux_raw/mm/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,9 @@ pub enum Advice {
212212
LinuxMergeable = linux_raw_sys::general::MADV_MERGEABLE,
213213
/// `MADV_UNMERGEABLE`
214214
LinuxUnmergeable = linux_raw_sys::general::MADV_UNMERGEABLE,
215-
/// `MADV_HUGEPAGE` (since Linux 2.6.38)
215+
/// `MADV_HUGEPAGE`
216216
LinuxHugepage = linux_raw_sys::general::MADV_HUGEPAGE,
217-
/// `MADV_NOHUGEPAGE` (since Linux 2.6.38)
217+
/// `MADV_NOHUGEPAGE`
218218
LinuxNoHugepage = linux_raw_sys::general::MADV_NOHUGEPAGE,
219219
/// `MADV_DONTDUMP` (since Linux 3.4)
220220
LinuxDontDump = linux_raw_sys::general::MADV_DONTDUMP,

src/backend/linux_raw/vdso_wrappers.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,10 @@ pub(crate) fn clock_gettime_dynamic(which_clock: DynamicClockId<'_>) -> io::Resu
8686
((!fd.as_raw_fd() << 3) | CLOCKFD) as __kernel_clockid_t
8787
}
8888

89-
DynamicClockId::RealtimeAlarm => {
90-
linux_raw_sys::general::CLOCK_REALTIME_ALARM as __kernel_clockid_t
91-
}
92-
DynamicClockId::Tai => linux_raw_sys::general::CLOCK_TAI as __kernel_clockid_t,
93-
DynamicClockId::Boottime => linux_raw_sys::general::CLOCK_BOOTTIME as __kernel_clockid_t,
94-
DynamicClockId::BoottimeAlarm => {
95-
linux_raw_sys::general::CLOCK_BOOTTIME_ALARM as __kernel_clockid_t
96-
}
89+
DynamicClockId::RealtimeAlarm => c::CLOCK_REALTIME_ALARM as __kernel_clockid_t,
90+
DynamicClockId::Tai => c::CLOCK_TAI as __kernel_clockid_t,
91+
DynamicClockId::Boottime => c::CLOCK_BOOTTIME as __kernel_clockid_t,
92+
DynamicClockId::BoottimeAlarm => c::CLOCK_BOOTTIME_ALARM as __kernel_clockid_t,
9793
};
9894

9995
// SAFETY: `CLOCK_GETTIME` contains either null or the address of a

src/clockid.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ pub enum ClockId {
6464
#[doc(alias = "CLOCK_MONOTONIC_RAW")]
6565
MonotonicRaw = c::CLOCK_MONOTONIC_RAW,
6666

67-
/// `CLOCK_REALTIME_ALARM`, available on Linux >= 3.0
68-
#[cfg(all(linux_kernel, feature = "linux_4_11"))]
67+
/// `CLOCK_REALTIME_ALARM`
68+
#[cfg(linux_kernel)]
6969
#[doc(alias = "CLOCK_REALTIME_ALARM")]
7070
RealtimeAlarm = bitcast!(c::CLOCK_REALTIME_ALARM),
7171

@@ -74,20 +74,16 @@ pub enum ClockId {
7474
#[doc(alias = "CLOCK_TAI")]
7575
Tai = bitcast!(c::CLOCK_TAI),
7676

77-
/// `CLOCK_BOOTTIME`, available on Linux >= 2.6.39
77+
/// `CLOCK_BOOTTIME`
7878
///
7979
/// On FreeBSD, use [`Self::Uptime`], as `CLOCK_BOOTTIME` is an alias for
8080
/// `CLOCK_UPTIME`.
81-
#[cfg(any(
82-
all(linux_kernel, feature = "linux_4_11"),
83-
target_os = "fuchsia",
84-
target_os = "openbsd"
85-
))]
81+
#[cfg(any(linux_kernel, target_os = "fuchsia", target_os = "openbsd"))]
8682
#[doc(alias = "CLOCK_BOOTTIME")]
8783
Boottime = bitcast!(c::CLOCK_BOOTTIME),
8884

89-
/// `CLOCK_BOOTTIME_ALARM`, available on Linux >= 2.6.39
90-
#[cfg(any(all(linux_kernel, feature = "linux_4_11"), target_os = "fuchsia"))]
85+
/// `CLOCK_BOOTTIME_ALARM`
86+
#[cfg(any(linux_kernel, target_os = "fuchsia"))]
9187
#[doc(alias = "CLOCK_BOOTTIME_ALARM")]
9288
BoottimeAlarm = bitcast!(c::CLOCK_BOOTTIME_ALARM),
9389
}
@@ -139,7 +135,7 @@ pub enum DynamicClockId<'a> {
139135
/// Linux dynamic clocks.
140136
Dynamic(BorrowedFd<'a>),
141137

142-
/// `CLOCK_REALTIME_ALARM`, available on Linux >= 3.0
138+
/// `CLOCK_REALTIME_ALARM`
143139
#[cfg(linux_kernel)]
144140
#[doc(alias = "CLOCK_REALTIME_ALARM")]
145141
RealtimeAlarm,
@@ -149,7 +145,7 @@ pub enum DynamicClockId<'a> {
149145
#[doc(alias = "CLOCK_TAI")]
150146
Tai,
151147

152-
/// `CLOCK_BOOTTIME`, available on Linux >= 2.6.39
148+
/// `CLOCK_BOOTTIME`
153149
#[cfg(any(
154150
freebsdlike,
155151
linux_kernel,
@@ -159,7 +155,7 @@ pub enum DynamicClockId<'a> {
159155
#[doc(alias = "CLOCK_BOOTTIME")]
160156
Boottime,
161157

162-
/// `CLOCK_BOOTTIME_ALARM`, available on Linux >= 2.6.39
158+
/// `CLOCK_BOOTTIME_ALARM`
163159
#[cfg(any(linux_kernel, target_os = "fuchsia"))]
164160
#[doc(alias = "CLOCK_BOOTTIME_ALARM")]
165161
BoottimeAlarm,

src/procfs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,8 @@ fn is_mountpoint(file: BorrowedFd<'_>) -> bool {
226226

227227
/// Open a directory in `/proc`, mapping all errors to `io::Errno::NOTSUP`.
228228
fn proc_opendirat<P: crate::path::Arg, Fd: AsFd>(dirfd: Fd, path: P) -> io::Result<OwnedFd> {
229-
// We could add `PATH`|`NOATIME` here but Linux 2.6.32 doesn't support it.
230-
// Also for `NOATIME` see the comment in `open_and_check_file`.
229+
// We don't add `PATH` here because that disables `DIRECTORY`. And we don't
230+
// add `NOATIME` for the same reason as the comment in `open_and_check_file`.
231231
let oflags = OFlags::NOFOLLOW | OFlags::DIRECTORY | OFlags::CLOEXEC | OFlags::NOCTTY;
232232
openat(dirfd, path, oflags, Mode::empty()).map_err(|_err| io::Errno::NOTSUP)
233233
}

0 commit comments

Comments
 (0)