Skip to content

Commit 62ce4df

Browse files
authored
Disable use-libc-auxv by default, and document cargo features (#1389)
* Disable use-libc-auxv by default, and document cargo features Disable use-libc-auxv by default, as we can now use `PR_GET_AUXV` on most systems today, and fall back to "/proc/self/auxv". And add documentation for the main user-facing Cargo features to README.md. Fixes #1387. * Bump linux-raw-sys to 0.9.1 to pick up `EM_CURRENT` for powerpc. * Bump linux-raw-sys to 0.9.2 to pick up `EM_CURRENT` for s390x.
1 parent d7819fd commit 62ce4df

File tree

5 files changed

+33
-21
lines changed

5 files changed

+33
-21
lines changed

Cargo.toml

+6-10
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ compiler_builtins = { version = '0.1.49', optional = true }
3030
# libc backend can be selected via adding `--cfg=rustix_use_libc` to
3131
# `RUSTFLAGS` or enabling the `use-libc` cargo feature.
3232
[target.'cfg(all(not(rustix_use_libc), not(miri), target_os = "linux", any(target_endian = "little", any(target_arch = "s390x", target_arch = "powerpc")), any(target_arch = "arm", all(target_arch = "aarch64", target_pointer_width = "64"), target_arch = "riscv64", all(rustix_use_experimental_asm, target_arch = "powerpc"), all(rustix_use_experimental_asm, target_arch = "powerpc64"), all(rustix_use_experimental_asm, target_arch = "s390x"), all(rustix_use_experimental_asm, target_arch = "mips"), all(rustix_use_experimental_asm, target_arch = "mips32r6"), all(rustix_use_experimental_asm, target_arch = "mips64"), all(rustix_use_experimental_asm, target_arch = "mips64r6"), target_arch = "x86", all(target_arch = "x86_64", target_pointer_width = "64"))))'.dependencies]
33-
linux-raw-sys = { version = "0.9.0", default-features = false, features = ["general", "errno", "ioctl", "no_std", "elf"] }
33+
linux-raw-sys = { version = "0.9.2", default-features = false, features = ["general", "errno", "ioctl", "no_std", "elf"] }
3434
libc_errno = { package = "errno", version = "0.3.10", default-features = false, optional = true }
3535
libc = { version = "0.2.168", default-features = false, optional = true }
3636

@@ -47,7 +47,7 @@ libc = { version = "0.2.168", default-features = false }
4747
# Some syscalls do not have libc wrappers, such as in `io_uring`. For these,
4848
# the libc backend uses the linux-raw-sys ABI and `libc::syscall`.
4949
[target.'cfg(all(any(target_os = "android", target_os = "linux"), any(rustix_use_libc, miri, not(all(target_os = "linux", any(target_endian = "little", any(target_arch = "s390x", target_arch = "powerpc")), any(target_arch = "arm", all(target_arch = "aarch64", target_pointer_width = "64"), target_arch = "riscv64", all(rustix_use_experimental_asm, target_arch = "powerpc"), all(rustix_use_experimental_asm, target_arch = "powerpc64"), all(rustix_use_experimental_asm, target_arch = "s390x"), all(rustix_use_experimental_asm, target_arch = "mips"), all(rustix_use_experimental_asm, target_arch = "mips32r6"), all(rustix_use_experimental_asm, target_arch = "mips64"), all(rustix_use_experimental_asm, target_arch = "mips64r6"), target_arch = "x86", all(target_arch = "x86_64", target_pointer_width = "64")))))))'.dependencies]
50-
linux-raw-sys = { version = "0.9.0", default-features = false, features = ["general", "ioctl", "no_std"] }
50+
linux-raw-sys = { version = "0.9.2", default-features = false, features = ["general", "ioctl", "no_std"] }
5151

5252
# For the libc backend on Windows, use the Winsock API in windows-sys.
5353
[target.'cfg(windows)'.dependencies.windows-sys]
@@ -106,12 +106,8 @@ targets = [
106106

107107
[features]
108108

109-
# By default, use `std` and use libc for aux values.
110-
#
111-
# It turns out to be bizarrely awkward to obtain the aux values reliably and
112-
# efficiently on Linux from anywhere other than libc. We can do it, but most
113-
# users are better served by just using libc for this.
114-
default = ["std", "use-libc-auxv"]
109+
# By default, use `std`.
110+
default = ["std"]
115111

116112
# This enables use of std. Disabling this enables `#![no_std]`, and requires
117113
# Rust 1.77 or newer.
@@ -200,8 +196,8 @@ all-apis = [
200196
"time",
201197
]
202198

203-
# When using the linux_raw backend, should we use libc for reading the aux
204-
# vectors, instead of reading them ourselves from /proc/self/auxv?
199+
# When using the linux_raw backend, should we use `getauxval` for reading aux
200+
# vectors, instead of `PR_GET_AUXV` or "/proc/self/auxv"?
205201
use-libc-auxv = []
206202

207203
# Enable "use-explicitly-provided-auxv" mode, with a public

README.md

+13-2
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ building.
5353
## Cargo features
5454

5555
The modules [`rustix::io`], [`rustix::fd`], [`rustix::ffi`], and
56-
[`rustix::ioctl`] are enabled by default. The rest of the API is conditional
57-
with cargo feature flags:
56+
[`rustix::ioctl`] are enabled by default. The rest of the API modules are
57+
conditional with cargo feature flags.
5858

5959
| Name | Description |
6060
| ---------- | -------------------------------------------------------------- |
@@ -77,6 +77,16 @@ with cargo feature flags:
7777
| `time` | [`rustix::time`]—Time-related operations. |
7878
| | |
7979
| `use-libc` | Enable the libc backend. |
80+
| | |
81+
| `linux_4_11` | Enable optimizations that assume Linux ≥ 4.11 |
82+
| `linux_5_1` | Enable optimizations that assume Linux ≥ 5.1 |
83+
| `linux_5_11` | Enable optimizations that assume Linux ≥ 5.11 |
84+
| `linux_latest` | Enable optimizations that assume the latest Linux release |
85+
| | |
86+
| `use-libc-auxv` | Use `getauxval` instead of `PR_GET_AUXV` or "/proc/self/auxv". |
87+
| | |
88+
| `std` | On by default; disable to activate `#![no_std]`. |
89+
| `alloc` | On by default; enables features that depend on [`alloc`]. |
8090

8191
[`rustix::event`]: https://docs.rs/rustix/*/rustix/event/index.html
8292
[`rustix::fs`]: https://docs.rs/rustix/*/rustix/fs/index.html
@@ -194,3 +204,4 @@ always reflect “very old” Linux versions.
194204
[`OwnedFd`]: https://doc.rust-lang.org/stable/std/os/fd/struct.OwnedFd.html
195205
[`AsFd`]: https://doc.rust-lang.org/stable/std/os/fd/trait.AsFd.html
196206
[`NOSYS`]: https://docs.rs/rustix/*/rustix/io/struct.Errno.html#associatedconstant.NOSYS
207+
[`alloc`]: https://doc.rust-lang.org/alloc/alloc/index.html

src/backend/libc/event/syscalls.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ pub(crate) fn port_get(port: BorrowedFd<'_>, timeout: Option<&Timespec>) -> io::
379379

380380
let mut event = MaybeUninit::<c::port_event>::uninit();
381381

382-
// In Rust >= 1.65, the `as _` can be `.cast_mut()`.
382+
// In Rust 1.65, the `as _` can be `.cast_mut()`.
383383
unsafe {
384384
ret(c::port_get(
385385
borrowed_fd(port),
@@ -426,7 +426,7 @@ pub(crate) unsafe fn port_getn(
426426
return Ok(0);
427427
}
428428

429-
// In Rust >= 1.65, the `as _` can be `.cast_mut()`.
429+
// In Rust 1.65, the `as _` can be `.cast_mut()`.
430430
ret(c::port_getn(
431431
borrowed_fd(port),
432432
events.0.cast(),
@@ -538,7 +538,7 @@ pub(crate) unsafe fn epoll_wait(
538538
events: (*mut crate::event::epoll::Event, usize),
539539
timeout: Option<&Timespec>,
540540
) -> io::Result<usize> {
541-
// If we're on Linux >= 5.11 and a libc that has an `epoll_pwait2`
541+
// If we're on Linux 5.11 and a libc that has an `epoll_pwait2`
542542
// function, and it's y2038-safe, use it.
543543
#[cfg(all(
544544
linux_kernel,
@@ -569,7 +569,7 @@ pub(crate) unsafe fn epoll_wait(
569569
}
570570
}
571571

572-
// If we're on Linux >= 5.11, use `epoll_pwait2` via `libc::syscall`.
572+
// If we're on Linux 5.11, use `epoll_pwait2` via `libc::syscall`.
573573
#[cfg(all(linux_kernel, feature = "linux_5_11"))]
574574
{
575575
syscall! {

src/backend/linux_raw/param/auxv.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,13 @@ static RANDOM: AtomicPtr<[u8; 16]> = AtomicPtr::new(null_mut());
204204

205205
const PR_GET_AUXV: c::c_int = 0x4155_5856;
206206

207-
/// Use Linux ≥ 6.4's `PR_GET_AUXV` to read the aux records, into a provided
207+
/// Use Linux ≥ 6.4's [`PR_GET_AUXV`] to read the aux records, into a provided
208208
/// statically-sized buffer. Return:
209209
/// - `Ok(…)` if the buffer is big enough.
210210
/// - `Err(Ok(len))` if we need a buffer of length `len`.
211211
/// - `Err(Err(err))` if we failed with `err`.
212+
///
213+
/// [`PR_GET_AUXV`]: https://www.man7.org/linux/man-pages/man2/PR_GET_AUXV.2const.html
212214
#[cold]
213215
fn pr_get_auxv_static(buffer: &mut [u8; 512]) -> Result<&mut [u8], crate::io::Result<usize>> {
214216
let len = unsafe {
@@ -228,11 +230,13 @@ fn pr_get_auxv_static(buffer: &mut [u8; 512]) -> Result<&mut [u8], crate::io::Re
228230
Err(Ok(len))
229231
}
230232

231-
/// Use Linux ≥ 6.4's `PR_GET_AUXV` to read the aux records, using a provided
232-
/// statically-sized buffer if possible, or a dynamically allocated buffer
233-
/// otherwise. Return:
233+
/// Use Linux ≥ 6.4's [`PR_GET_AUXV`] to read the aux records, using a
234+
/// provided statically-sized buffer if possible, or a dynamically allocated
235+
/// buffer otherwise. Return:
234236
/// - Ok(…) on success.
235237
/// - Err(err) on failure.
238+
///
239+
/// [`PR_GET_AUXV`]: https://www.man7.org/linux/man-pages/man2/PR_GET_AUXV.2const.html
236240
#[cfg(feature = "alloc")]
237241
#[cold]
238242
fn pr_get_auxv_dynamic(buffer: &mut [u8; 512]) -> crate::io::Result<Cow<'_, [u8]>> {
@@ -278,6 +282,7 @@ fn maybe_init_auxv() {
278282
/// /proc/self/auxv for kernels that don't support `PR_GET_AUXV`.
279283
#[cold]
280284
fn init_auxv_impl() -> Result<(), ()> {
285+
// 512 AUX elements ought to be enough for anybody…
281286
let mut buffer = [0_u8; 512];
282287

283288
// If we don't have "alloc", just try to read into our statically-sized

src/thread/futex.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ impl Default for Wait {
556556
/// `futex_waitv(waiters.as_ptr(), waiters.len(), flags, timeout, clockd)`—
557557
/// Wait on an array of futexes, wake on any.
558558
///
559-
/// This requires Linux >= 5.16.
559+
/// This requires Linux 5.16.
560560
///
561561
/// # References
562562
/// - [Linux]

0 commit comments

Comments
 (0)