Skip to content

Commit 85109af

Browse files
committed
Auto merge of #76561 - Thomasdezeeuw:iov-constant-limits, r=Amanieu
Use IOV_MAX and UIO_MAXIOV constants in limit vectored I/O Also updates the libc dependency to 0.2.77 (from 0.2.74) as the constants were only recently added. Related #68042, #75005 r? `@Amanieu` (also reviewed #75005)
2 parents 2d6cbd2 + c394624 commit 85109af

File tree

4 files changed

+50
-21
lines changed

4 files changed

+50
-21
lines changed

Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -1610,9 +1610,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
16101610

16111611
[[package]]
16121612
name = "libc"
1613-
version = "0.2.74"
1613+
version = "0.2.77"
16141614
source = "registry+https://github.com/rust-lang/crates.io-index"
1615-
checksum = "a2f02823cf78b754822df5f7f268fb59822e7296276d3e069d8e8cb26a14bd10"
1615+
checksum = "f2f96b10ec2560088a8e76961b00d47107b3a625fecb76dedb29ee7ccbf98235"
16161616
dependencies = [
16171617
"rustc-std-workspace-core",
16181618
]

library/std/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ cfg-if = { version = "0.1.8", features = ['rustc-dep-of-std'] }
1616
panic_unwind = { path = "../panic_unwind", optional = true }
1717
panic_abort = { path = "../panic_abort" }
1818
core = { path = "../core" }
19-
libc = { version = "0.2.74", default-features = false, features = ['rustc-dep-of-std'] }
19+
libc = { version = "0.2.77", default-features = false, features = ['rustc-dep-of-std'] }
2020
compiler_builtins = { version = "0.1.35" }
2121
profiler_builtins = { path = "../profiler_builtins", optional = true }
2222
unwind = { path = "../unwind" }

library/std/src/sys/unix/fd.rs

+26-17
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ mod tests;
66
use crate::cmp;
77
use crate::io::{self, Initializer, IoSlice, IoSliceMut, Read};
88
use crate::mem;
9-
#[cfg(not(any(target_os = "redox", target_env = "newlib")))]
10-
use crate::sync::atomic::{AtomicUsize, Ordering};
119
use crate::sys::cvt;
1210
use crate::sys_common::AsInner;
1311

@@ -31,24 +29,35 @@ const READ_LIMIT: usize = c_int::MAX as usize - 1;
3129
#[cfg(not(target_os = "macos"))]
3230
const READ_LIMIT: usize = libc::ssize_t::MAX as usize;
3331

34-
#[cfg(not(any(target_os = "redox", target_env = "newlib")))]
35-
fn max_iov() -> usize {
36-
static LIM: AtomicUsize = AtomicUsize::new(0);
37-
38-
let mut lim = LIM.load(Ordering::Relaxed);
39-
if lim == 0 {
40-
let ret = unsafe { libc::sysconf(libc::_SC_IOV_MAX) };
41-
42-
// 16 is the minimum value required by POSIX.
43-
lim = if ret > 0 { ret as usize } else { 16 };
44-
LIM.store(lim, Ordering::Relaxed);
45-
}
32+
#[cfg(any(
33+
target_os = "dragonfly",
34+
target_os = "freebsd",
35+
target_os = "ios",
36+
target_os = "macos",
37+
target_os = "netbsd",
38+
target_os = "openbsd",
39+
))]
40+
const fn max_iov() -> usize {
41+
libc::IOV_MAX as usize
42+
}
4643

47-
lim
44+
#[cfg(any(target_os = "android", target_os = "emscripten", target_os = "linux"))]
45+
const fn max_iov() -> usize {
46+
libc::UIO_MAXIOV as usize
4847
}
4948

50-
#[cfg(any(target_os = "redox", target_env = "newlib"))]
51-
fn max_iov() -> usize {
49+
#[cfg(not(any(
50+
target_os = "android",
51+
target_os = "dragonfly",
52+
target_os = "emscripten",
53+
target_os = "freebsd",
54+
target_os = "ios",
55+
target_os = "linux",
56+
target_os = "macos",
57+
target_os = "netbsd",
58+
target_os = "openbsd",
59+
)))]
60+
const fn max_iov() -> usize {
5261
16 // The minimum value required by POSIX.
5362
}
5463

library/std/src/sys/unix/process/process_unix.rs

+21-1
Original file line numberDiff line numberDiff line change
@@ -459,18 +459,38 @@ impl ExitStatus {
459459
}
460460

461461
fn exited(&self) -> bool {
462-
unsafe { libc::WIFEXITED(self.0) }
462+
// On Linux-like OSes this function is safe, on others it is not. See
463+
// libc issue: https://github.com/rust-lang/libc/issues/1888.
464+
#[cfg_attr(
465+
any(target_os = "linux", target_os = "android", target_os = "emscripten"),
466+
allow(unused_unsafe)
467+
)]
468+
unsafe {
469+
libc::WIFEXITED(self.0)
470+
}
463471
}
464472

465473
pub fn success(&self) -> bool {
466474
self.code() == Some(0)
467475
}
468476

469477
pub fn code(&self) -> Option<i32> {
478+
// On Linux-like OSes this function is safe, on others it is not. See
479+
// libc issue: https://github.com/rust-lang/libc/issues/1888.
480+
#[cfg_attr(
481+
any(target_os = "linux", target_os = "android", target_os = "emscripten"),
482+
allow(unused_unsafe)
483+
)]
470484
if self.exited() { Some(unsafe { libc::WEXITSTATUS(self.0) }) } else { None }
471485
}
472486

473487
pub fn signal(&self) -> Option<i32> {
488+
// On Linux-like OSes this function is safe, on others it is not. See
489+
// libc issue: https://github.com/rust-lang/libc/issues/1888.
490+
#[cfg_attr(
491+
any(target_os = "linux", target_os = "android", target_os = "emscripten"),
492+
allow(unused_unsafe)
493+
)]
474494
if !self.exited() { Some(unsafe { libc::WTERMSIG(self.0) }) } else { None }
475495
}
476496
}

0 commit comments

Comments
 (0)