summaryrefslogtreecommitdiffstats
path: root/vendor/rustix/src/io
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:18:25 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:18:25 +0000
commit5363f350887b1e5b5dd21a86f88c8af9d7fea6da (patch)
tree35ca005eb6e0e9a1ba3bb5dbc033209ad445dc17 /vendor/rustix/src/io
parentAdding debian version 1.66.0+dfsg1-1. (diff)
downloadrustc-5363f350887b1e5b5dd21a86f88c8af9d7fea6da.tar.xz
rustc-5363f350887b1e5b5dd21a86f88c8af9d7fea6da.zip
Merging upstream version 1.67.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/rustix/src/io')
-rw-r--r--vendor/rustix/src/io/close.rs6
-rw-r--r--vendor/rustix/src/io/dup.rs20
-rw-r--r--vendor/rustix/src/io/errno.rs4
-rw-r--r--vendor/rustix/src/io/eventfd.rs8
-rw-r--r--vendor/rustix/src/io/fcntl.rs86
-rw-r--r--vendor/rustix/src/io/fd/owned.rs4
-rw-r--r--vendor/rustix/src/io/fd/raw.rs2
-rw-r--r--vendor/rustix/src/io/ioctl.rs22
-rw-r--r--vendor/rustix/src/io/is_read_write.rs10
-rw-r--r--vendor/rustix/src/io/mod.rs45
-rw-r--r--vendor/rustix/src/io/owned_fd.rs272
-rw-r--r--vendor/rustix/src/io/pipe.rs91
-rw-r--r--vendor/rustix/src/io/poll.rs6
-rw-r--r--vendor/rustix/src/io/procfs.rs106
-rw-r--r--vendor/rustix/src/io/read_write.rs32
-rw-r--r--vendor/rustix/src/io/stdio.rs96
16 files changed, 385 insertions, 425 deletions
diff --git a/vendor/rustix/src/io/close.rs b/vendor/rustix/src/io/close.rs
index 2116f53bd..b286d2368 100644
--- a/vendor/rustix/src/io/close.rs
+++ b/vendor/rustix/src/io/close.rs
@@ -5,8 +5,8 @@
//! Operating on raw file descriptors is unsafe.
#![allow(unsafe_code)]
-use crate::imp;
-use imp::fd::RawFd;
+use crate::backend;
+use backend::fd::RawFd;
/// `close(raw_fd)`—Closes a `RawFd` directly.
///
@@ -37,5 +37,5 @@ use imp::fd::RawFd;
/// not valid after the call.
#[inline]
pub unsafe fn close(raw_fd: RawFd) {
- imp::io::syscalls::close(raw_fd)
+ backend::io::syscalls::close(raw_fd)
}
diff --git a/vendor/rustix/src/io/dup.rs b/vendor/rustix/src/io/dup.rs
index ffa0401f2..8da6aa091 100644
--- a/vendor/rustix/src/io/dup.rs
+++ b/vendor/rustix/src/io/dup.rs
@@ -1,11 +1,11 @@
//! Functions which duplicate file descriptors.
-use crate::imp;
-use crate::io::{self, OwnedFd};
-use imp::fd::AsFd;
+use crate::fd::OwnedFd;
+use crate::{backend, io};
+use backend::fd::AsFd;
#[cfg(not(target_os = "wasi"))]
-pub use imp::io::types::DupFlags;
+pub use backend::io::types::DupFlags;
/// `dup(fd)`—Creates a new `OwnedFd` instance that shares the same
/// underlying [file description] as `fd`.
@@ -23,14 +23,14 @@ pub use imp::io::types::DupFlags;
/// - [Apple]
///
/// [file description]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_258
-/// [`fcntl_dupfd_cloexec`]: crate::fs::fcntl_dupfd_cloexec
+/// [`fcntl_dupfd_cloexec`]: crate::io::fcntl_dupfd_cloexec
/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/dup.html
/// [Linux]: https://man7.org/linux/man-pages/man2/dup.2.html
/// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/dup.2.html
#[cfg(not(target_os = "wasi"))]
#[inline]
pub fn dup<Fd: AsFd>(fd: Fd) -> io::Result<OwnedFd> {
- imp::io::syscalls::dup(fd.as_fd())
+ backend::io::syscalls::dup(fd.as_fd())
}
/// `dup2(fd, new)`—Changes the [file description] of a file descriptor.
@@ -50,14 +50,14 @@ pub fn dup<Fd: AsFd>(fd: Fd) -> io::Result<OwnedFd> {
/// - [Apple]
///
/// [file description]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_258
-/// [`fcntl_dupfd_cloexec`]: crate::fs::fcntl_dupfd_cloexec
+/// [`fcntl_dupfd_cloexec`]: crate::io::fcntl_dupfd_cloexec
/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/dup2.html
/// [Linux]: https://man7.org/linux/man-pages/man2/dup2.2.html
/// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/dup2.2.html
#[cfg(not(target_os = "wasi"))]
#[inline]
pub fn dup2<Fd: AsFd>(fd: Fd, new: &mut OwnedFd) -> io::Result<()> {
- imp::io::syscalls::dup2(fd.as_fd(), new)
+ backend::io::syscalls::dup2(fd.as_fd(), new)
}
/// `dup3(fd, new, flags)`—Changes the [file description] of a file
@@ -73,8 +73,8 @@ pub fn dup2<Fd: AsFd>(fd: Fd, new: &mut OwnedFd) -> io::Result<()> {
///
/// [file description]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_258
/// [Linux]: https://man7.org/linux/man-pages/man2/dup3.2.html
-#[cfg(not(target_os = "wasi"))]
+#[cfg(not(any(target_os = "aix", target_os = "wasi")))]
#[inline]
pub fn dup3<Fd: AsFd>(fd: Fd, new: &mut OwnedFd, flags: DupFlags) -> io::Result<()> {
- imp::io::syscalls::dup3(fd.as_fd(), new, flags)
+ backend::io::syscalls::dup3(fd.as_fd(), new, flags)
}
diff --git a/vendor/rustix/src/io/errno.rs b/vendor/rustix/src/io/errno.rs
index 84ced6a37..f39573797 100644
--- a/vendor/rustix/src/io/errno.rs
+++ b/vendor/rustix/src/io/errno.rs
@@ -4,7 +4,7 @@
//! enum because we may not know about all of the host's error values
//! and we don't want unrecognized values to create UB.
-use crate::imp;
+use crate::backend;
use core::{fmt, result};
#[cfg(feature = "std")]
use std::error;
@@ -25,7 +25,7 @@ pub type Result<T> = result::Result<T, Errno>;
///
/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/errno.html
/// [Linux]: https://man7.org/linux/man-pages/man3/errno.3.html
-pub use imp::io::errno::Errno;
+pub use backend::io::errno::Errno;
impl Errno {
/// Shorthand for `std::io::Error::from(self).kind()`.
diff --git a/vendor/rustix/src/io/eventfd.rs b/vendor/rustix/src/io/eventfd.rs
index 53e9d11f0..22ffc627c 100644
--- a/vendor/rustix/src/io/eventfd.rs
+++ b/vendor/rustix/src/io/eventfd.rs
@@ -1,7 +1,7 @@
-use crate::imp;
-use crate::io::{self, OwnedFd};
+use crate::fd::OwnedFd;
+use crate::{backend, io};
-pub use imp::io::types::EventfdFlags;
+pub use backend::io::types::EventfdFlags;
/// `eventfd(initval, flags)`—Creates a file descriptor for event
/// notification.
@@ -12,5 +12,5 @@ pub use imp::io::types::EventfdFlags;
/// [Linux]: https://man7.org/linux/man-pages/man2/eventfd.2.html
#[inline]
pub fn eventfd(initval: u32, flags: EventfdFlags) -> io::Result<OwnedFd> {
- imp::io::syscalls::eventfd(initval, flags)
+ backend::io::syscalls::eventfd(initval, flags)
}
diff --git a/vendor/rustix/src/io/fcntl.rs b/vendor/rustix/src/io/fcntl.rs
new file mode 100644
index 000000000..109e4540b
--- /dev/null
+++ b/vendor/rustix/src/io/fcntl.rs
@@ -0,0 +1,86 @@
+//! The Unix `fcntl` function is effectively lots of different functions
+//! hidden behind a single dynamic dispatch interface. In order to provide
+//! a type-safe API, rustix makes them all separate functions so that they
+//! can have dedicated static type signatures.
+//!
+//! `fcntl` functions which are not specific to files or directories live
+//! in the [`io`] module instead.
+//!
+//! [`io`]: crate::io
+
+use crate::backend;
+use crate::io;
+use backend::fd::{AsFd, OwnedFd, RawFd};
+
+pub use backend::io::types::FdFlags;
+
+/// `fcntl(fd, F_GETFD)`—Returns a file descriptor's flags.
+///
+/// # References
+/// - [POSIX]
+/// - [Linux]
+///
+/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/fcntl.html
+/// [Linux]: https://man7.org/linux/man-pages/man2/fcntl.2.html
+#[inline]
+#[doc(alias = "F_GETFD")]
+pub fn fcntl_getfd<Fd: AsFd>(fd: Fd) -> io::Result<FdFlags> {
+ backend::io::syscalls::fcntl_getfd(fd.as_fd())
+}
+
+/// `fcntl(fd, F_SETFD, flags)`—Sets a file descriptor's flags.
+///
+/// # References
+/// - [POSIX]
+/// - [Linux]
+///
+/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/fcntl.html
+/// [Linux]: https://man7.org/linux/man-pages/man2/fcntl.2.html
+#[inline]
+#[doc(alias = "F_SETFD")]
+pub fn fcntl_setfd<Fd: AsFd>(fd: Fd, flags: FdFlags) -> io::Result<()> {
+ backend::io::syscalls::fcntl_setfd(fd.as_fd(), flags)
+}
+
+/// `fcntl(fd, F_DUPFD_CLOEXEC)`—Creates a new `OwnedFd` instance, with value
+/// at least `min`, that has `O_CLOEXEC` set and that shares the same
+/// underlying [file description] as `fd`.
+///
+/// POSIX guarantees that `F_DUPFD_CLOEXEC` will use the lowest unused file
+/// descriptor which is at least `min`, however it is not safe in general to
+/// rely on this, as file descriptors may be unexpectedly allocated on other
+/// threads or in libraries.
+///
+/// # References
+/// - [POSIX]
+/// - [Linux]
+///
+/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/fcntl.html
+/// [Linux]: https://man7.org/linux/man-pages/man2/fcntl.2.html
+#[cfg(not(any(target_os = "wasi", target_os = "espidf")))]
+#[inline]
+#[doc(alias = "F_DUPFD_CLOEXEC")]
+pub fn fcntl_dupfd_cloexec<Fd: AsFd>(fd: Fd, min: RawFd) -> io::Result<OwnedFd> {
+ backend::io::syscalls::fcntl_dupfd_cloexec(fd.as_fd(), min)
+}
+
+/// `fcntl(fd, F_DUPFD)`—Creates a new `OwnedFd` instance, with value at least
+/// `min`, that shares the same underlying [file description] as `fd`.
+///
+/// POSIX guarantees that `F_DUPFD` will use the lowest unused file descriptor
+/// which is at least `min`, however it is not safe in general to rely on this,
+/// as file descriptors may be unexpectedly allocated on other threads or in
+/// libraries.
+///
+/// # References
+/// - [POSIX]
+/// - [Linux]
+///
+/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/fcntl.html
+/// [Linux]: https://man7.org/linux/man-pages/man2/fcntl.2.html
+#[cfg(target_os = "espidf")]
+#[inline]
+#[doc(alias = "F_DUPFD")]
+pub fn fcntl_dupfd<Fd: AsFd>(fd: Fd, min: RawFd) -> io::Result<OwnedFd> {
+ backend::io::syscalls::fcntl_dupfd(fd.as_fd(), min)
+}
diff --git a/vendor/rustix/src/io/fd/owned.rs b/vendor/rustix/src/io/fd/owned.rs
index d99b6a0f9..c2972b073 100644
--- a/vendor/rustix/src/io/fd/owned.rs
+++ b/vendor/rustix/src/io/fd/owned.rs
@@ -92,14 +92,14 @@ impl OwnedFd {
// CLOEXEC flag, and currently that's done via F_DUPFD_CLOEXEC. This
// is a POSIX flag that was added to Linux in 2.6.24.
#[cfg(not(target_os = "espidf"))]
- let fd = crate::fs::fcntl_dupfd_cloexec(self, 0)?;
+ let fd = crate::io::fcntl_dupfd_cloexec(self, 0)?;
// For ESP-IDF, F_DUPFD is used instead, because the CLOEXEC semantics
// will never be supported, as this is a bare metal framework with
// no capabilities for multi-process execution. While F_DUPFD is also
// not supported yet, it might be (currently it returns ENOSYS).
#[cfg(target_os = "espidf")]
- let fd = crate::fs::fcntl_dupfd(self)?;
+ let fd = crate::io::fcntl_dupfd(self)?;
Ok(fd.into())
}
diff --git a/vendor/rustix/src/io/fd/raw.rs b/vendor/rustix/src/io/fd/raw.rs
index 44322d9fe..a522c9794 100644
--- a/vendor/rustix/src/io/fd/raw.rs
+++ b/vendor/rustix/src/io/fd/raw.rs
@@ -7,7 +7,7 @@
#![cfg_attr(staged_api, stable(feature = "rust1", since = "1.0.0"))]
#![allow(unsafe_code)]
-use crate::imp::c;
+use crate::backend::c;
/// Raw file descriptors.
#[cfg_attr(staged_api, stable(feature = "rust1", since = "1.0.0"))]
diff --git a/vendor/rustix/src/io/ioctl.rs b/vendor/rustix/src/io/ioctl.rs
index be47e7958..01ded2e12 100644
--- a/vendor/rustix/src/io/ioctl.rs
+++ b/vendor/rustix/src/io/ioctl.rs
@@ -3,8 +3,8 @@
//! a type-safe API, rustix makes them all separate functions so that they
//! can have dedicated static type signatures.
-use crate::{imp, io};
-use imp::fd::AsFd;
+use crate::{backend, io};
+use backend::fd::AsFd;
/// `ioctl(fd, TIOCEXCL)`—Enables exclusive mode on a terminal.
///
@@ -12,11 +12,11 @@ use imp::fd::AsFd;
/// - [Linux]
///
/// [Linux]: https://man7.org/linux/man-pages/man4/tty_ioctl.4.html
-#[cfg(not(any(windows, target_os = "redox", target_os = "wasi")))]
+#[cfg(not(any(windows, target_os = "haiku", target_os = "redox", target_os = "wasi")))]
#[inline]
#[doc(alias = "TIOCEXCL")]
pub fn ioctl_tiocexcl<Fd: AsFd>(fd: Fd) -> io::Result<()> {
- imp::io::syscalls::ioctl_tiocexcl(fd.as_fd())
+ backend::io::syscalls::ioctl_tiocexcl(fd.as_fd())
}
/// `ioctl(fd, TIOCNXCL)`—Disables exclusive mode on a terminal.
@@ -25,11 +25,11 @@ pub fn ioctl_tiocexcl<Fd: AsFd>(fd: Fd) -> io::Result<()> {
/// - [Linux]
///
/// [Linux]: https://man7.org/linux/man-pages/man4/tty_ioctl.4.html
-#[cfg(not(any(windows, target_os = "redox", target_os = "wasi")))]
+#[cfg(not(any(windows, target_os = "haiku", target_os = "redox", target_os = "wasi")))]
#[inline]
#[doc(alias = "TIOCNXCL")]
pub fn ioctl_tiocnxcl<Fd: AsFd>(fd: Fd) -> io::Result<()> {
- imp::io::syscalls::ioctl_tiocnxcl(fd.as_fd())
+ backend::io::syscalls::ioctl_tiocnxcl(fd.as_fd())
}
/// `ioctl(fd, FIOCLEX)`—Set the close-on-exec flag.
@@ -47,7 +47,7 @@ pub fn ioctl_tiocnxcl<Fd: AsFd>(fd: Fd) -> io::Result<()> {
#[doc(alias = "FIOCLEX")]
#[doc(alias = "FD_CLOEXEC")]
pub fn ioctl_fioclex<Fd: AsFd>(fd: Fd) -> io::Result<()> {
- imp::io::syscalls::ioctl_fioclex(fd.as_fd())
+ backend::io::syscalls::ioctl_fioclex(fd.as_fd())
}
/// `ioctl(fd, FIONBIO, &value)`—Enables or disables non-blocking mode.
@@ -61,7 +61,7 @@ pub fn ioctl_fioclex<Fd: AsFd>(fd: Fd) -> io::Result<()> {
#[inline]
#[doc(alias = "FIONBIO")]
pub fn ioctl_fionbio<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> {
- imp::io::syscalls::ioctl_fionbio(fd.as_fd(), value)
+ backend::io::syscalls::ioctl_fionbio(fd.as_fd(), value)
}
/// `ioctl(fd, FIONREAD)`—Returns the number of bytes ready to be read.
@@ -79,7 +79,7 @@ pub fn ioctl_fionbio<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> {
#[inline]
#[doc(alias = "FIONREAD")]
pub fn ioctl_fionread<Fd: AsFd>(fd: Fd) -> io::Result<u64> {
- imp::io::syscalls::ioctl_fionread(fd.as_fd())
+ backend::io::syscalls::ioctl_fionread(fd.as_fd())
}
/// `ioctl(fd, BLKSSZGET)`—Returns the logical block size of a block device.
@@ -87,7 +87,7 @@ pub fn ioctl_fionread<Fd: AsFd>(fd: Fd) -> io::Result<u64> {
#[inline]
#[doc(alias = "BLKSSZGET")]
pub fn ioctl_blksszget<Fd: AsFd>(fd: Fd) -> io::Result<u32> {
- imp::io::syscalls::ioctl_blksszget(fd.as_fd())
+ backend::io::syscalls::ioctl_blksszget(fd.as_fd())
}
/// `ioctl(fd, BLKPBSZGET)`—Returns the physical block size of a block device.
@@ -95,5 +95,5 @@ pub fn ioctl_blksszget<Fd: AsFd>(fd: Fd) -> io::Result<u32> {
#[inline]
#[doc(alias = "BLKPBSZGET")]
pub fn ioctl_blkpbszget<Fd: AsFd>(fd: Fd) -> io::Result<u32> {
- imp::io::syscalls::ioctl_blkpbszget(fd.as_fd())
+ backend::io::syscalls::ioctl_blkpbszget(fd.as_fd())
}
diff --git a/vendor/rustix/src/io/is_read_write.rs b/vendor/rustix/src/io/is_read_write.rs
index c6f189090..74007e7f9 100644
--- a/vendor/rustix/src/io/is_read_write.rs
+++ b/vendor/rustix/src/io/is_read_write.rs
@@ -1,7 +1,9 @@
//! The [`is_read_write`] function.
-use crate::{imp, io};
-use imp::fd::AsFd;
+#[cfg(all(feature = "fs", feature = "net"))]
+use crate::{backend, io};
+#[cfg(all(feature = "fs", feature = "net"))]
+use backend::fd::AsFd;
/// Returns a pair of booleans indicating whether the file descriptor is
/// readable and/or writable, respectively.
@@ -11,6 +13,8 @@ use imp::fd::AsFd;
///
/// [`is_file_read_write`]: crate::fs::is_file_read_write
#[inline]
+#[cfg(all(feature = "fs", feature = "net"))]
+#[cfg_attr(doc_cfg, doc(cfg(all(feature = "fs", feature = "net"))))]
pub fn is_read_write<Fd: AsFd>(fd: Fd) -> io::Result<(bool, bool)> {
- imp::io::syscalls::is_read_write(fd.as_fd())
+ backend::io::syscalls::is_read_write(fd.as_fd())
}
diff --git a/vendor/rustix/src/io/mod.rs b/vendor/rustix/src/io/mod.rs
index 5cd5e2ec9..03f06c4ac 100644
--- a/vendor/rustix/src/io/mod.rs
+++ b/vendor/rustix/src/io/mod.rs
@@ -6,13 +6,13 @@ mod dup;
mod errno;
#[cfg(any(target_os = "android", target_os = "linux"))]
mod eventfd;
+#[cfg(not(windows))]
+mod fcntl;
#[cfg(not(feature = "std"))]
pub(crate) mod fd;
mod ioctl;
#[cfg(not(any(windows, target_os = "redox")))]
-#[cfg(feature = "net")]
mod is_read_write;
-mod owned_fd;
#[cfg(not(any(windows, target_os = "wasi")))]
mod pipe;
mod poll;
@@ -26,13 +26,17 @@ mod seek_from;
mod stdio;
#[cfg(any(target_os = "android", target_os = "linux"))]
-pub use crate::imp::io::epoll;
+pub use crate::backend::io::epoll;
pub use close::close;
-#[cfg(not(any(windows, target_os = "wasi")))]
+#[cfg(not(any(windows, target_os = "aix", target_os = "wasi")))]
pub use dup::{dup, dup2, dup3, DupFlags};
pub use errno::{retry_on_intr, Errno, Result};
#[cfg(any(target_os = "android", target_os = "linux"))]
pub use eventfd::{eventfd, EventfdFlags};
+#[cfg(not(any(windows, target_os = "wasi")))]
+pub use fcntl::fcntl_dupfd_cloexec;
+#[cfg(not(windows))]
+pub use fcntl::{fcntl_getfd, fcntl_setfd, FdFlags};
#[cfg(any(target_os = "ios", target_os = "macos"))]
pub use ioctl::ioctl_fioclex;
pub use ioctl::ioctl_fionbio;
@@ -40,29 +44,46 @@ pub use ioctl::ioctl_fionbio;
pub use ioctl::ioctl_fionread;
#[cfg(any(target_os = "android", target_os = "linux"))]
pub use ioctl::{ioctl_blkpbszget, ioctl_blksszget};
-#[cfg(not(any(windows, target_os = "redox", target_os = "wasi")))]
+#[cfg(not(any(windows, target_os = "haiku", target_os = "redox", target_os = "wasi")))]
pub use ioctl::{ioctl_tiocexcl, ioctl_tiocnxcl};
#[cfg(not(any(windows, target_os = "redox")))]
-#[cfg(feature = "net")]
+#[cfg(all(feature = "fs", feature = "net"))]
pub use is_read_write::is_read_write;
-pub use owned_fd::OwnedFd;
#[cfg(not(any(windows, target_os = "wasi")))]
pub use pipe::pipe;
#[cfg(not(any(
windows,
+ target_os = "haiku",
target_os = "illumos",
target_os = "redox",
+ target_os = "solaris",
target_os = "wasi",
)))]
pub use pipe::PIPE_BUF;
-#[cfg(not(any(windows, target_os = "ios", target_os = "macos", target_os = "wasi")))]
+#[cfg(not(any(
+ windows,
+ target_os = "aix",
+ target_os = "haiku",
+ target_os = "ios",
+ target_os = "macos",
+ target_os = "wasi"
+)))]
pub use pipe::{pipe_with, PipeFlags};
+#[cfg(any(target_os = "android", target_os = "linux"))]
+pub use pipe::{splice, vmsplice, IoSliceRaw, SpliceFlags};
pub use poll::{poll, PollFd, PollFlags};
#[cfg(all(feature = "procfs", any(target_os = "android", target_os = "linux")))]
-pub use procfs::{proc_self_fd, proc_self_fdinfo_fd, proc_self_maps, proc_self_pagemap};
+pub use procfs::{
+ proc_self_fd, proc_self_fdinfo_fd, proc_self_maps, proc_self_pagemap, proc_self_status,
+};
#[cfg(not(windows))]
pub use read_write::{pread, pwrite, read, readv, write, writev, IoSlice, IoSliceMut};
-#[cfg(not(any(windows, target_os = "redox")))]
+#[cfg(not(any(
+ windows,
+ target_os = "haiku",
+ target_os = "redox",
+ target_os = "solaris"
+)))]
pub use read_write::{preadv, pwritev};
#[cfg(any(target_os = "android", target_os = "linux"))]
pub use read_write::{preadv2, pwritev2, ReadWriteFlags};
@@ -71,4 +92,6 @@ pub use seek_from::SeekFrom;
#[cfg(feature = "std")]
pub use std::io::SeekFrom;
#[cfg(not(windows))]
-pub use stdio::{stderr, stdin, stdout, take_stderr, take_stdin, take_stdout};
+pub use stdio::{
+ raw_stderr, raw_stdin, raw_stdout, stderr, stdin, stdout, take_stderr, take_stdin, take_stdout,
+};
diff --git a/vendor/rustix/src/io/owned_fd.rs b/vendor/rustix/src/io/owned_fd.rs
deleted file mode 100644
index 63c6145b0..000000000
--- a/vendor/rustix/src/io/owned_fd.rs
+++ /dev/null
@@ -1,272 +0,0 @@
-//! A wrapper around [`io_lifetimes::OwnedFd`].
-//!
-//! rustix needs to wrap io-lifetimes' `OwnedFd` type so that it can call its
-//! own [`close`] function when the `OwnedFd` is dropped.
-//!
-//! [`close`]: crate::io::close
-//!
-//! # Safety
-//!
-//! We wrap an `OwnedFd` in a `ManuallyDrop` so that we can extract the
-//! file descriptor and close it ourselves.
-#![allow(unsafe_code)]
-
-use crate::imp::fd::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, RawFd};
-#[cfg(all(not(io_lifetimes_use_std), feature = "std"))]
-use crate::imp::fd::{FromFd, IntoFd};
-use crate::io::close;
-use core::fmt;
-use core::mem::{forget, ManuallyDrop};
-
-/// A wrapper around [`io_lifetimes::OwnedFd`] which closes the file descriptor
-/// using rustix's own [`close`] rather than libc's `close`.
-///
-/// [`close`]: crate::io::close
-#[repr(transparent)]
-pub struct OwnedFd {
- inner: ManuallyDrop<crate::imp::fd::OwnedFd>,
-}
-
-impl OwnedFd {
- /// Creates a new `OwnedFd` instance that shares the same underlying file
- /// handle as the existing `OwnedFd` instance.
- #[cfg(all(unix, not(target_os = "wasi")))]
- pub fn try_clone(&self) -> crate::io::Result<Self> {
- // We want to atomically duplicate this file descriptor and set the
- // CLOEXEC flag, and currently that's done via F_DUPFD_CLOEXEC. This
- // is a POSIX flag that was added to Linux in 2.6.24.
- #[cfg(not(target_os = "espidf"))]
- let fd = crate::fs::fcntl_dupfd_cloexec(self, 0)?;
-
- // For ESP-IDF, F_DUPFD is used instead, because the CLOEXEC semantics
- // will never be supported, as this is a bare metal framework with
- // no capabilities for multi-process execution. While F_DUPFD is also
- // not supported yet, it might be (currently it returns ENOSYS).
- #[cfg(target_os = "espidf")]
- let fd = crate::fs::fcntl_dupfd(self)?;
-
- Ok(fd)
- }
-
- /// Creates a new `OwnedFd` instance that shares the same underlying file
- /// handle as the existing `OwnedFd` instance.
- #[cfg(target_os = "wasi")]
- pub fn try_clone(&self) -> std::io::Result<Self> {
- Err(std::io::Error::new(
- std::io::ErrorKind::Unsupported,
- "operation not supported on WASI yet",
- ))
- }
-
- /// Creates a new `OwnedFd` instance that shares the same underlying file
- /// handle as the existing `OwnedFd` instance.
- #[cfg(target_os = "windows")]
- pub fn try_clone(&self) -> std::io::Result<Self> {
- use windows_sys::Win32::Networking::WinSock::{
- WSADuplicateSocketW, WSAGetLastError, WSASocketW, INVALID_SOCKET, SOCKET_ERROR,
- WSAEINVAL, WSAEPROTOTYPE, WSAPROTOCOL_INFOW, WSA_FLAG_NO_HANDLE_INHERIT,
- WSA_FLAG_OVERLAPPED,
- };
- use windows_sys::Win32::System::Threading::GetCurrentProcessId;
-
- let mut info = unsafe { std::mem::zeroed::<WSAPROTOCOL_INFOW>() };
- let result =
- unsafe { WSADuplicateSocketW(self.as_raw_fd() as _, GetCurrentProcessId(), &mut info) };
- match result {
- SOCKET_ERROR => return Err(std::io::Error::last_os_error()),
- 0 => (),
- _ => panic!(),
- }
- let socket = unsafe {
- WSASocketW(
- info.iAddressFamily,
- info.iSocketType,
- info.iProtocol,
- &mut info,
- 0,
- WSA_FLAG_OVERLAPPED | WSA_FLAG_NO_HANDLE_INHERIT,
- )
- };
-
- if socket != INVALID_SOCKET {
- unsafe { Ok(Self::from_raw_fd(socket as _)) }
- } else {
- let error = unsafe { WSAGetLastError() };
-
- if error != WSAEPROTOTYPE && error != WSAEINVAL {
- return Err(std::io::Error::from_raw_os_error(error));
- }
-
- let socket = unsafe {
- WSASocketW(
- info.iAddressFamily,
- info.iSocketType,
- info.iProtocol,
- &mut info,
- 0,
- WSA_FLAG_OVERLAPPED,
- )
- };
-
- if socket == INVALID_SOCKET {
- return Err(std::io::Error::last_os_error());
- }
-
- unsafe {
- let socket = Self::from_raw_fd(socket as _);
- socket.set_no_inherit()?;
- Ok(socket)
- }
- }
- }
-
- #[cfg(windows)]
- #[cfg(not(target_vendor = "uwp"))]
- fn set_no_inherit(&self) -> std::io::Result<()> {
- use windows_sys::Win32::Foundation::{SetHandleInformation, HANDLE, HANDLE_FLAG_INHERIT};
- match unsafe { SetHandleInformation(self.as_raw_fd() as HANDLE, HANDLE_FLAG_INHERIT, 0) } {
- 0 => return Err(std::io::Error::last_os_error()),
- _ => Ok(()),
- }
- }
-
- #[cfg(windows)]
- #[cfg(target_vendor = "uwp")]
- fn set_no_inherit(&self) -> std::io::Result<()> {
- Err(std::io::Error::new(
- std::io::ErrorKind::Unsupported,
- "Unavailable on UWP",
- ))
- }
-}
-
-#[cfg(not(windows))]
-impl AsFd for OwnedFd {
- #[inline]
- fn as_fd(&self) -> BorrowedFd<'_> {
- self.inner.as_fd()
- }
-}
-
-#[cfg(windows)]
-impl io_lifetimes::AsSocket for OwnedFd {
- #[inline]
- fn as_socket(&self) -> BorrowedFd<'_> {
- self.inner.as_socket()
- }
-}
-
-#[cfg(any(io_lifetimes_use_std, not(feature = "std")))]
-impl From<OwnedFd> for crate::imp::fd::OwnedFd {
- #[inline]
- fn from(owned_fd: OwnedFd) -> Self {
- let raw_fd = owned_fd.inner.as_fd().as_raw_fd();
- forget(owned_fd);
-
- // Safety: We use `as_fd().as_raw_fd()` to extract the raw file
- // descriptor from `self.inner`, and then `forget` `self` so
- // that they remain valid until the new `OwnedFd` acquires them.
- unsafe { crate::imp::fd::OwnedFd::from_raw_fd(raw_fd) }
- }
-}
-
-#[cfg(not(any(io_lifetimes_use_std, not(feature = "std"))))]
-impl IntoFd for OwnedFd {
- #[inline]
- fn into_fd(self) -> crate::imp::fd::OwnedFd {
- let raw_fd = self.inner.as_fd().as_raw_fd();
- forget(self);
-
- // Safety: We use `as_fd().as_raw_fd()` to extract the raw file
- // descriptor from `self.inner`, and then `forget` `self` so
- // that they remain valid until the new `OwnedFd` acquires them.
- unsafe { crate::imp::fd::OwnedFd::from_raw_fd(raw_fd) }
- }
-}
-
-#[cfg(any(io_lifetimes_use_std, not(feature = "std")))]
-impl From<crate::imp::fd::OwnedFd> for OwnedFd {
- #[inline]
- fn from(owned_fd: crate::imp::fd::OwnedFd) -> Self {
- Self {
- inner: ManuallyDrop::new(owned_fd),
- }
- }
-}
-
-#[cfg(all(not(io_lifetimes_use_std), feature = "std"))]
-impl FromFd for OwnedFd {
- #[inline]
- fn from_fd(owned_fd: crate::imp::fd::OwnedFd) -> Self {
- Self {
- inner: ManuallyDrop::new(owned_fd),
- }
- }
-}
-
-#[cfg(not(any(io_lifetimes_use_std, not(feature = "std"))))]
-impl From<crate::imp::fd::OwnedFd> for OwnedFd {
- #[inline]
- fn from(fd: crate::imp::fd::OwnedFd) -> Self {
- Self {
- inner: ManuallyDrop::new(fd),
- }
- }
-}
-
-#[cfg(not(any(io_lifetimes_use_std, not(feature = "std"))))]
-impl From<OwnedFd> for crate::imp::fd::OwnedFd {
- #[inline]
- fn from(fd: OwnedFd) -> Self {
- let raw_fd = fd.inner.as_fd().as_raw_fd();
- forget(fd);
-
- // Safety: We use `as_fd().as_raw_fd()` to extract the raw file
- // descriptor from `self.inner`, and then `forget` `self` so
- // that they remain valid until the new `OwnedFd` acquires them.
- unsafe { Self::from_raw_fd(raw_fd) }
- }
-}
-
-impl AsRawFd for OwnedFd {
- #[inline]
- fn as_raw_fd(&self) -> RawFd {
- self.inner.as_raw_fd()
- }
-}
-
-impl IntoRawFd for OwnedFd {
- #[inline]
- fn into_raw_fd(self) -> RawFd {
- let raw_fd = self.inner.as_fd().as_raw_fd();
- forget(self);
- raw_fd
- }
-}
-
-impl FromRawFd for OwnedFd {
- #[inline]
- unsafe fn from_raw_fd(raw_fd: RawFd) -> Self {
- Self {
- inner: ManuallyDrop::new(crate::imp::fd::OwnedFd::from_raw_fd(raw_fd)),
- }
- }
-}
-
-impl Drop for OwnedFd {
- #[inline]
- fn drop(&mut self) {
- // Safety: We use `as_fd().as_raw_fd()` to extract the raw file
- // descriptor from `self.inner`. `self.inner` is wrapped with
- // `ManuallyDrop` so dropping it doesn't invalid them.
- unsafe {
- close(self.as_fd().as_raw_fd());
- }
- }
-}
-
-impl fmt::Debug for OwnedFd {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- self.inner.fmt(f)
- }
-}
diff --git a/vendor/rustix/src/io/pipe.rs b/vendor/rustix/src/io/pipe.rs
index 2878d10b1..2b8af6a84 100644
--- a/vendor/rustix/src/io/pipe.rs
+++ b/vendor/rustix/src/io/pipe.rs
@@ -1,8 +1,15 @@
-use crate::imp;
-use crate::io::{self, OwnedFd};
+#![allow(unsafe_code)]
+
+use crate::fd::OwnedFd;
+use crate::{backend, io};
+#[cfg(any(target_os = "android", target_os = "linux"))]
+use backend::fd::AsFd;
#[cfg(not(any(target_os = "ios", target_os = "macos")))]
-pub use imp::io::types::PipeFlags;
+pub use backend::io::types::PipeFlags;
+
+#[cfg(any(target_os = "android", target_os = "linux"))]
+pub use backend::io::types::{IoSliceRaw, SpliceFlags};
/// `PIPE_BUF`—The maximum length at which writes to a pipe are atomic.
///
@@ -14,11 +21,13 @@ pub use imp::io::types::PipeFlags;
/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/write.html
#[cfg(not(any(
windows,
+ target_os = "haiku",
target_os = "illumos",
target_os = "redox",
+ target_os = "solaris",
target_os = "wasi",
)))]
-pub const PIPE_BUF: usize = imp::io::types::PIPE_BUF;
+pub const PIPE_BUF: usize = backend::io::types::PIPE_BUF;
/// `pipe()`—Creates a pipe.
///
@@ -33,7 +42,7 @@ pub const PIPE_BUF: usize = imp::io::types::PIPE_BUF;
/// [Linux]: https://man7.org/linux/man-pages/man2/pipe.2.html
#[inline]
pub fn pipe() -> io::Result<(OwnedFd, OwnedFd)> {
- imp::io::syscalls::pipe()
+ backend::io::syscalls::pipe()
}
/// `pipe2(flags)`—Creates a pipe, with flags.
@@ -45,9 +54,77 @@ pub fn pipe() -> io::Result<(OwnedFd, OwnedFd)> {
/// - [Linux]
///
/// [Linux]: https://man7.org/linux/man-pages/man2/pipe2.2.html
-#[cfg(not(any(target_os = "ios", target_os = "macos")))]
+#[cfg(not(any(
+ target_os = "aix",
+ target_os = "haiku",
+ target_os = "ios",
+ target_os = "macos"
+)))]
#[inline]
#[doc(alias = "pipe2")]
pub fn pipe_with(flags: PipeFlags) -> io::Result<(OwnedFd, OwnedFd)> {
- imp::io::syscalls::pipe_with(flags)
+ backend::io::syscalls::pipe_with(flags)
+}
+
+/// `splice(fd_in, off_in, fd_out, off_out, len, flags)`—Transfer data between a file and a pipe.
+///
+/// This function transfers up to `len` bytes of data from the file descriptor `fd_in`
+/// to the file descriptor `fd_out`, where one of the file descriptors
+/// must refer to a pipe.
+///
+/// `off_*` must be `None` if the corresponding fd refers to a pipe.
+/// Otherwise its value points to the starting offset to the file,
+/// from which the data is read/written.
+/// on success the number of bytes read/written is added to the offset.
+///
+/// passing `None` causes the read/write to start from the file offset,
+/// and the file offset is adjusted appropriately.
+///
+/// # References
+/// - [Linux]
+///
+/// [Linux]: https://man7.org/linux/man-pages/man2/splice.2.html
+#[cfg(any(target_os = "android", target_os = "linux"))]
+#[inline]
+pub fn splice<FdIn: AsFd, FdOut: AsFd>(
+ fd_in: FdIn,
+ off_in: Option<&mut u64>,
+ fd_out: FdOut,
+ off_out: Option<&mut u64>,
+ len: usize,
+ flags: SpliceFlags,
+) -> io::Result<usize> {
+ backend::io::syscalls::splice(fd_in.as_fd(), off_in, fd_out.as_fd(), off_out, len, flags)
+}
+
+/// `vmsplice(fd, bufs, flags)`—Transfer data between memory and a pipe.
+///
+/// If `fd` is the write end of the pipe,
+/// the function maps the memory pointer at by `bufs` to the pipe.
+///
+/// If `fd` is the read end of the pipe,
+/// the function writes data from the pipe to said memory.
+///
+/// # Safety
+///
+/// If the memory must not be mutated (such as when `bufs` were originally immutable slices),
+/// it is up to the caller to ensure that the write end of the pipe is placed in `fd`.
+///
+/// Additionally if `SpliceFlags::GIFT` is set, the caller must also ensure
+/// that the contents of `bufs` in never modified following the call,
+/// and that all of the pointers in `bufs` are page aligned,
+/// and the lengths are multiples of a page size in bytes.
+///
+/// # References
+/// - [Linux]
+///
+/// [Linux]: https://man7.org/linux/man-pages/man2/vmsplice.2.html
+#[cfg(any(target_os = "android", target_os = "linux"))]
+#[inline]
+pub unsafe fn vmsplice<PipeFd: AsFd>(
+ fd: PipeFd,
+ bufs: &[io::IoSliceRaw],
+ flags: SpliceFlags,
+) -> io::Result<usize> {
+ backend::io::syscalls::vmsplice(fd.as_fd(), bufs, flags)
}
diff --git a/vendor/rustix/src/io/poll.rs b/vendor/rustix/src/io/poll.rs
index efa25045c..01f625af2 100644
--- a/vendor/rustix/src/io/poll.rs
+++ b/vendor/rustix/src/io/poll.rs
@@ -1,6 +1,6 @@
-use crate::{imp, io};
+use crate::{backend, io};
-pub use imp::io::poll_fd::{PollFd, PollFlags};
+pub use backend::io::poll_fd::{PollFd, PollFlags};
/// `poll(self.fds, timeout)`
///
@@ -16,5 +16,5 @@ pub use imp::io::poll_fd::{PollFd, PollFlags};
/// [Winsock2]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsapoll
#[inline]
pub fn poll(fds: &mut [PollFd<'_>], timeout: i32) -> io::Result<usize> {
- imp::io::syscalls::poll(fds, timeout)
+ backend::io::syscalls::poll(fds, timeout)
}
diff --git a/vendor/rustix/src/io/procfs.rs b/vendor/rustix/src/io/procfs.rs
index a947a4e06..c6eeb08e0 100644
--- a/vendor/rustix/src/io/procfs.rs
+++ b/vendor/rustix/src/io/procfs.rs
@@ -16,15 +16,15 @@
//! namespace. So with the checking here, they may fail, but they won't be able
//! to succeed with bogus results.
-use crate::fd::{AsFd, BorrowedFd};
+use crate::fd::{AsFd, BorrowedFd, OwnedFd};
use crate::ffi::CStr;
use crate::fs::{
cwd, fstat, fstatfs, major, openat, renameat, Dir, FileType, Mode, OFlags, Stat,
PROC_SUPER_MAGIC,
};
-use crate::io::{self, OwnedFd};
+use crate::io;
use crate::path::DecInt;
-use crate::process::{getgid, getpid, getuid, Gid, RawGid, RawUid, Uid};
+use crate::process::getpid;
#[cfg(feature = "rustc-dep-of-std")]
use core::lazy::OnceCell;
#[cfg(not(feature = "rustc-dep-of-std"))]
@@ -47,11 +47,9 @@ fn check_proc_entry(
kind: Kind,
entry: BorrowedFd<'_>,
proc_stat: Option<&Stat>,
- uid: RawUid,
- gid: RawGid,
) -> io::Result<Stat> {
let entry_stat = fstat(entry)?;
- check_proc_entry_with_stat(kind, entry, entry_stat, proc_stat, uid, gid)
+ check_proc_entry_with_stat(kind, entry, entry_stat, proc_stat)
}
/// Check a subdirectory of "/proc" for anomalies, using the provided `Stat`.
@@ -60,8 +58,6 @@ fn check_proc_entry_with_stat(
entry: BorrowedFd<'_>,
entry_stat: Stat,
proc_stat: Option<&Stat>,
- uid: RawUid,
- gid: RawGid,
) -> io::Result<Stat> {
// Check the filesystem magic.
check_procfs(entry)?;
@@ -72,13 +68,6 @@ fn check_proc_entry_with_stat(
Kind::File => check_proc_file(&entry_stat, proc_stat)?,
}
- // Check the ownership of the directory. We can't do that for the toplevel
- // "/proc" though, because in e.g. a user namespace scenario, root outside
- // the container may be mapped to another uid like `nobody`.
- if !matches!(kind, Kind::Proc) && (entry_stat.st_uid, entry_stat.st_gid) != (uid, gid) {
- return Err(io::Errno::NOTSUP);
- }
-
// "/proc" directories are typically mounted r-xr-xr-x.
// "/proc/self/fd" is r-x------. Allow them to have fewer permissions, but
// not more.
@@ -207,6 +196,7 @@ fn is_mountpoint(file: BorrowedFd<'_>) -> bool {
/// Open a directory in `/proc`, mapping all errors to `io::Errno::NOTSUP`.
fn proc_opendirat<P: crate::path::Arg, Fd: AsFd>(dirfd: Fd, path: P) -> io::Result<OwnedFd> {
// We could add `PATH`|`NOATIME` here but Linux 2.6.32 doesn't support it.
+ // Also for `NOATIME` see the comment in `open_and_check_file`.
let oflags = OFlags::NOFOLLOW | OFlags::DIRECTORY | OFlags::CLOEXEC | OFlags::NOCTTY;
openat(dirfd, path, oflags, Mode::empty()).map_err(|_err| io::Errno::NOTSUP)
}
@@ -229,14 +219,8 @@ fn proc() -> io::Result<(BorrowedFd<'static>, &'static Stat)> {
PROC.get_or_try_init(|| {
// Open "/proc".
let proc = proc_opendirat(cwd(), cstr!("/proc"))?;
- let proc_stat = check_proc_entry(
- Kind::Proc,
- proc.as_fd(),
- None,
- Uid::ROOT.as_raw(),
- Gid::ROOT.as_raw(),
- )
- .map_err(|_err| io::Errno::NOTSUP)?;
+ let proc_stat =
+ check_proc_entry(Kind::Proc, proc.as_fd(), None).map_err(|_err| io::Errno::NOTSUP)?;
Ok(new_static_fd(proc, proc_stat))
})
@@ -260,19 +244,13 @@ fn proc_self() -> io::Result<(BorrowedFd<'static>, &'static Stat)> {
.get_or_try_init(|| {
let (proc, proc_stat) = proc()?;
- let (uid, gid, pid) = (getuid(), getgid(), getpid());
+ let pid = getpid();
// Open "/proc/self". Use our pid to compute the name rather than literally
// using "self", as "self" is a symlink.
let proc_self = proc_opendirat(proc, DecInt::new(pid.as_raw_nonzero().get()))?;
- let proc_self_stat = check_proc_entry(
- Kind::Pid,
- proc_self.as_fd(),
- Some(proc_stat),
- uid.as_raw(),
- gid.as_raw(),
- )
- .map_err(|_err| io::Errno::NOTSUP)?;
+ let proc_self_stat = check_proc_entry(Kind::Pid, proc_self.as_fd(), Some(proc_stat))
+ .map_err(|_err| io::Errno::NOTSUP)?;
Ok(new_static_fd(proc_self, proc_self_stat))
})
@@ -297,18 +275,13 @@ pub fn proc_self_fd() -> io::Result<BorrowedFd<'static>> {
.get_or_try_init(|| {
let (_, proc_stat) = proc()?;
- let (proc_self, proc_self_stat) = proc_self()?;
+ let (proc_self, _proc_self_stat) = proc_self()?;
// Open "/proc/self/fd".
let proc_self_fd = proc_opendirat(proc_self, cstr!("fd"))?;
- let proc_self_fd_stat = check_proc_entry(
- Kind::Fd,
- proc_self_fd.as_fd(),
- Some(proc_stat),
- proc_self_stat.st_uid,
- proc_self_stat.st_gid,
- )
- .map_err(|_err| io::Errno::NOTSUP)?;
+ let proc_self_fd_stat =
+ check_proc_entry(Kind::Fd, proc_self_fd.as_fd(), Some(proc_stat))
+ .map_err(|_err| io::Errno::NOTSUP)?;
Ok(new_static_fd(proc_self_fd, proc_self_fd_stat))
})
@@ -333,24 +306,19 @@ fn new_static_fd(fd: OwnedFd, stat: Stat) -> (OwnedFd, Stat) {
///
/// [Linux]: https://man7.org/linux/man-pages/man5/proc.5.html
fn proc_self_fdinfo() -> io::Result<(BorrowedFd<'static>, &'static Stat)> {
- static PROC_SELF_FDINFO: OnceCell<(OwnedFd, Stat)> = OnceCell::new();
+ static PROC_SELF_FDINFO: StaticFd = StaticFd::new();
PROC_SELF_FDINFO
.get_or_try_init(|| {
let (_, proc_stat) = proc()?;
- let (proc_self, proc_self_stat) = proc_self()?;
+ let (proc_self, _proc_self_stat) = proc_self()?;
// Open "/proc/self/fdinfo".
let proc_self_fdinfo = proc_opendirat(proc_self, cstr!("fdinfo"))?;
- let proc_self_fdinfo_stat = check_proc_entry(
- Kind::Fd,
- proc_self_fdinfo.as_fd(),
- Some(proc_stat),
- proc_self_stat.st_uid,
- proc_self_stat.st_gid,
- )
- .map_err(|_err| io::Errno::NOTSUP)?;
+ let proc_self_fdinfo_stat =
+ check_proc_entry(Kind::Fd, proc_self_fdinfo.as_fd(), Some(proc_stat))
+ .map_err(|_err| io::Errno::NOTSUP)?;
Ok((proc_self_fdinfo, proc_self_fdinfo_stat))
})
@@ -410,6 +378,21 @@ pub fn proc_self_maps() -> io::Result<OwnedFd> {
proc_self_file(cstr!("maps"))
}
+/// Returns a handle to a Linux `/proc/self/status` file.
+///
+/// This ensures that `/proc/self/status` is `procfs`, that nothing is
+/// mounted on top of it, and that it looks normal.
+///
+/// # References
+/// - [Linux]
+///
+/// [Linux]: https://man7.org/linux/man-pages/man5/proc.5.html
+#[inline]
+#[cfg_attr(doc_cfg, doc(cfg(feature = "procfs")))]
+pub fn proc_self_status() -> io::Result<OwnedFd> {
+ proc_self_file(cstr!("status"))
+}
+
/// Open a file under `/proc/self`.
fn proc_self_file(name: &CStr) -> io::Result<OwnedFd> {
let (proc_self, proc_self_stat) = proc_self()?;
@@ -420,9 +403,14 @@ fn proc_self_file(name: &CStr) -> io::Result<OwnedFd> {
fn open_and_check_file(dir: BorrowedFd, dir_stat: &Stat, name: &CStr) -> io::Result<OwnedFd> {
let (_, proc_stat) = proc()?;
- let oflags =
- OFlags::RDONLY | OFlags::CLOEXEC | OFlags::NOFOLLOW | OFlags::NOCTTY | OFlags::NOATIME;
- let file = openat(&dir, name, oflags, Mode::empty()).map_err(|_err| io::Errno::NOTSUP)?;
+ // Don't use `NOATIME`, because it [requires us to own the file], and when
+ // a process sets itself non-dumpable Linux changes the user:group of its
+ // `/proc/<pid>` files [to root:root].
+ //
+ // [requires us to own the file]: https://man7.org/linux/man-pages/man2/openat.2.html
+ // [to root:root]: https://man7.org/linux/man-pages/man5/proc.5.html
+ let oflags = OFlags::RDONLY | OFlags::CLOEXEC | OFlags::NOFOLLOW | OFlags::NOCTTY;
+ let file = openat(dir, name, oflags, Mode::empty()).map_err(|_err| io::Errno::NOTSUP)?;
let file_stat = fstat(&file)?;
// `is_mountpoint` only works on directory mount points, not file mount
@@ -455,14 +443,8 @@ fn open_and_check_file(dir: BorrowedFd, dir_stat: &Stat, name: &CStr) -> io::Res
&& entry.file_name() == name
{
// We found the file. Proceed to check the file handle.
- let _ = check_proc_entry_with_stat(
- Kind::File,
- file.as_fd(),
- file_stat,
- Some(proc_stat),
- dir_stat.st_uid,
- dir_stat.st_gid,
- )?;
+ let _ =
+ check_proc_entry_with_stat(Kind::File, file.as_fd(), file_stat, Some(proc_stat))?;
found_file = true;
} else if entry.ino() == dir_stat.st_ino
diff --git a/vendor/rustix/src/io/read_write.rs b/vendor/rustix/src/io/read_write.rs
index abb96e9c1..1a4d37b65 100644
--- a/vendor/rustix/src/io/read_write.rs
+++ b/vendor/rustix/src/io/read_write.rs
@@ -1,19 +1,19 @@
//! `read` and `write`, optionally positioned, optionally vectored
-use crate::{imp, io};
-use imp::fd::AsFd;
+use crate::{backend, io};
+use backend::fd::AsFd;
// Declare `IoSlice` and `IoSliceMut`.
#[cfg(not(windows))]
#[cfg(not(feature = "std"))]
-pub use imp::io::io_slice::{IoSlice, IoSliceMut};
+pub use backend::io::io_slice::{IoSlice, IoSliceMut};
#[cfg(not(windows))]
#[cfg(feature = "std")]
pub use std::io::{IoSlice, IoSliceMut};
/// `RWF_*` constants for use with [`preadv2`] and [`pwritev2`].
#[cfg(any(target_os = "android", target_os = "linux"))]
-pub use imp::io::types::ReadWriteFlags;
+pub use backend::io::types::ReadWriteFlags;
/// `read(fd, buf)`—Reads from a stream.
///
@@ -27,7 +27,7 @@ pub use imp::io::types::ReadWriteFlags;
/// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/read.2.html
#[inline]
pub fn read<Fd: AsFd>(fd: Fd, buf: &mut [u8]) -> io::Result<usize> {
- imp::io::syscalls::read(fd.as_fd(), buf)
+ backend::io::syscalls::read(fd.as_fd(), buf)
}
/// `write(fd, buf)`—Writes to a stream.
@@ -42,7 +42,7 @@ pub fn read<Fd: AsFd>(fd: Fd, buf: &mut [u8]) -> io::Result<usize> {
/// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/write.2.html
#[inline]
pub fn write<Fd: AsFd>(fd: Fd, buf: &[u8]) -> io::Result<usize> {
- imp::io::syscalls::write(fd.as_fd(), buf)
+ backend::io::syscalls::write(fd.as_fd(), buf)
}
/// `pread(fd, buf, offset)`—Reads from a file at a given position.
@@ -57,7 +57,7 @@ pub fn write<Fd: AsFd>(fd: Fd, buf: &[u8]) -> io::Result<usize> {
/// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/pread.2.html
#[inline]
pub fn pread<Fd: AsFd>(fd: Fd, buf: &mut [u8], offset: u64) -> io::Result<usize> {
- imp::io::syscalls::pread(fd.as_fd(), buf, offset)
+ backend::io::syscalls::pread(fd.as_fd(), buf, offset)
}
/// `pwrite(fd, bufs)`—Writes to a file at a given position.
@@ -72,7 +72,7 @@ pub fn pread<Fd: AsFd>(fd: Fd, buf: &mut [u8], offset: u64) -> io::Result<usize>
/// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/pwrite.2.html
#[inline]
pub fn pwrite<Fd: AsFd>(fd: Fd, buf: &[u8], offset: u64) -> io::Result<usize> {
- imp::io::syscalls::pwrite(fd.as_fd(), buf, offset)
+ backend::io::syscalls::pwrite(fd.as_fd(), buf, offset)
}
/// `readv(fd, bufs)`—Reads from a stream into multiple buffers.
@@ -87,7 +87,7 @@ pub fn pwrite<Fd: AsFd>(fd: Fd, buf: &[u8], offset: u64) -> io::Result<usize> {
/// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/readv.2.html
#[inline]
pub fn readv<Fd: AsFd>(fd: Fd, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
- imp::io::syscalls::readv(fd.as_fd(), bufs)
+ backend::io::syscalls::readv(fd.as_fd(), bufs)
}
/// `writev(fd, bufs)`—Writes to a stream from multiple buffers.
@@ -102,7 +102,7 @@ pub fn readv<Fd: AsFd>(fd: Fd, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize>
/// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/writev.2.html
#[inline]
pub fn writev<Fd: AsFd>(fd: Fd, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
- imp::io::syscalls::writev(fd.as_fd(), bufs)
+ backend::io::syscalls::writev(fd.as_fd(), bufs)
}
/// `preadv(fd, bufs, offset)`—Reads from a file at a given position into
@@ -112,10 +112,10 @@ pub fn writev<Fd: AsFd>(fd: Fd, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
/// - [Linux]
///
/// [Linux]: https://man7.org/linux/man-pages/man2/preadv.2.html
-#[cfg(not(target_os = "redox"))]
+#[cfg(not(any(target_os = "haiku", target_os = "redox", target_os = "solaris")))]
#[inline]
pub fn preadv<Fd: AsFd>(fd: Fd, bufs: &mut [IoSliceMut<'_>], offset: u64) -> io::Result<usize> {
- imp::io::syscalls::preadv(fd.as_fd(), bufs, offset)
+ backend::io::syscalls::preadv(fd.as_fd(), bufs, offset)
}
/// `pwritev(fd, bufs, offset)`—Writes to a file at a given position from
@@ -125,10 +125,10 @@ pub fn preadv<Fd: AsFd>(fd: Fd, bufs: &mut [IoSliceMut<'_>], offset: u64) -> io:
/// - [Linux]
///
/// [Linux]: https://man7.org/linux/man-pages/man2/pwritev.2.html
-#[cfg(not(target_os = "redox"))]
+#[cfg(not(any(target_os = "haiku", target_os = "redox", target_os = "solaris")))]
#[inline]
pub fn pwritev<Fd: AsFd>(fd: Fd, bufs: &[IoSlice<'_>], offset: u64) -> io::Result<usize> {
- imp::io::syscalls::pwritev(fd.as_fd(), bufs, offset)
+ backend::io::syscalls::pwritev(fd.as_fd(), bufs, offset)
}
/// `preadv2(fd, bufs, offset, flags)`—Reads data, with several options.
@@ -147,7 +147,7 @@ pub fn preadv2<Fd: AsFd>(
offset: u64,
flags: ReadWriteFlags,
) -> io::Result<usize> {
- imp::io::syscalls::preadv2(fd.as_fd(), bufs, offset, flags)
+ backend::io::syscalls::preadv2(fd.as_fd(), bufs, offset, flags)
}
/// `pwritev2(fd, bufs, offset, flags)`—Writes data, with several options.
@@ -166,5 +166,5 @@ pub fn pwritev2<Fd: AsFd>(
offset: u64,
flags: ReadWriteFlags,
) -> io::Result<usize> {
- imp::io::syscalls::pwritev2(fd.as_fd(), bufs, offset, flags)
+ backend::io::syscalls::pwritev2(fd.as_fd(), bufs, offset, flags)
}
diff --git a/vendor/rustix/src/io/stdio.rs b/vendor/rustix/src/io/stdio.rs
index f9d03a701..caa8183c2 100644
--- a/vendor/rustix/src/io/stdio.rs
+++ b/vendor/rustix/src/io/stdio.rs
@@ -8,9 +8,9 @@
//! stdio streams.
#![allow(unsafe_code)]
-use crate::imp;
-use crate::io::OwnedFd;
-use imp::fd::{BorrowedFd, FromRawFd, RawFd};
+use crate::backend;
+use crate::fd::OwnedFd;
+use backend::fd::{BorrowedFd, FromRawFd, RawFd};
/// `STDIN_FILENO`—Standard input, borrowed.
///
@@ -36,9 +36,10 @@ use imp::fd::{BorrowedFd, FromRawFd, RawFd};
///
/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/stdin.html
/// [Linux]: https://man7.org/linux/man-pages/man3/stdin.3.html
+#[doc(alias = "STDIN_FILENO")]
#[inline]
-pub unsafe fn stdin() -> BorrowedFd<'static> {
- BorrowedFd::borrow_raw(imp::io::types::STDIN_FILENO as RawFd)
+pub const unsafe fn stdin() -> BorrowedFd<'static> {
+ BorrowedFd::borrow_raw(backend::io::types::STDIN_FILENO as RawFd)
}
/// `STDIN_FILENO`—Standard input, owned.
@@ -65,11 +66,10 @@ pub unsafe fn stdin() -> BorrowedFd<'static> {
///
/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/stdin.html
/// [Linux]: https://man7.org/linux/man-pages/man3/stdin.3.html
+#[doc(alias = "STDIN_FILENO")]
#[inline]
pub unsafe fn take_stdin() -> OwnedFd {
- OwnedFd::from(imp::fd::OwnedFd::from_raw_fd(
- imp::io::types::STDIN_FILENO as RawFd,
- ))
+ backend::fd::OwnedFd::from_raw_fd(backend::io::types::STDIN_FILENO as RawFd)
}
/// `STDOUT_FILENO`—Standard output, borrowed.
@@ -97,9 +97,10 @@ pub unsafe fn take_stdin() -> OwnedFd {
///
/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/stdout.html
/// [Linux]: https://man7.org/linux/man-pages/man3/stdout.3.html
+#[doc(alias = "STDOUT_FILENO")]
#[inline]
-pub unsafe fn stdout() -> BorrowedFd<'static> {
- BorrowedFd::borrow_raw(imp::io::types::STDOUT_FILENO as RawFd)
+pub const unsafe fn stdout() -> BorrowedFd<'static> {
+ BorrowedFd::borrow_raw(backend::io::types::STDOUT_FILENO as RawFd)
}
/// `STDOUT_FILENO`—Standard output, owned.
@@ -126,11 +127,10 @@ pub unsafe fn stdout() -> BorrowedFd<'static> {
///
/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/stdout.html
/// [Linux]: https://man7.org/linux/man-pages/man3/stdout.3.html
+#[doc(alias = "STDOUT_FILENO")]
#[inline]
pub unsafe fn take_stdout() -> OwnedFd {
- OwnedFd::from(imp::fd::OwnedFd::from_raw_fd(
- imp::io::types::STDOUT_FILENO as RawFd,
- ))
+ backend::fd::OwnedFd::from_raw_fd(backend::io::types::STDOUT_FILENO as RawFd)
}
/// `STDERR_FILENO`—Standard error, borrowed.
@@ -157,9 +157,10 @@ pub unsafe fn take_stdout() -> OwnedFd {
///
/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/stderr.html
/// [Linux]: https://man7.org/linux/man-pages/man3/stderr.3.html
+#[doc(alias = "STDERR_FILENO")]
#[inline]
-pub unsafe fn stderr() -> BorrowedFd<'static> {
- BorrowedFd::borrow_raw(imp::io::types::STDERR_FILENO as RawFd)
+pub const unsafe fn stderr() -> BorrowedFd<'static> {
+ BorrowedFd::borrow_raw(backend::io::types::STDERR_FILENO as RawFd)
}
/// `STDERR_FILENO`—Standard error, owned.
@@ -186,9 +187,68 @@ pub unsafe fn stderr() -> BorrowedFd<'static> {
///
/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/stderr.html
/// [Linux]: https://man7.org/linux/man-pages/man3/stderr.3.html
+#[doc(alias = "STDERR_FILENO")]
#[inline]
pub unsafe fn take_stderr() -> OwnedFd {
- OwnedFd::from(imp::fd::OwnedFd::from_raw_fd(
- imp::io::types::STDERR_FILENO as RawFd,
- ))
+ backend::fd::OwnedFd::from_raw_fd(backend::io::types::STDERR_FILENO as RawFd)
+}
+
+/// `STDIN_FILENO`—Standard input, raw.
+///
+/// This is similar to [`stdin`], however it returns a `RawFd`.
+///
+/// # Other hazards
+///
+/// This has the same hazards as [`stdin`].
+///
+/// # References
+/// - [POSIX]
+/// - [Linux]
+///
+/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/stdin.html
+/// [Linux]: https://man7.org/linux/man-pages/man3/stdin.3.html
+#[doc(alias = "STDIN_FILENO")]
+#[inline]
+pub const fn raw_stdin() -> RawFd {
+ backend::io::types::STDIN_FILENO as RawFd
+}
+
+/// `STDOUT_FILENO`—Standard output, raw.
+///
+/// This is similar to [`stdout`], however it returns a `RawFd`.
+///
+/// # Other hazards
+///
+/// This has the same hazards as [`stdout`].
+///
+/// # References
+/// - [POSIX]
+/// - [Linux]
+///
+/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/stdout.html
+/// [Linux]: https://man7.org/linux/man-pages/man3/stdout.3.html
+#[doc(alias = "STDOUT_FILENO")]
+#[inline]
+pub const fn raw_stdout() -> RawFd {
+ backend::io::types::STDOUT_FILENO as RawFd
+}
+
+/// `STDERR_FILENO`—Standard error, raw.
+///
+/// This is similar to [`stderr`], however it returns a `RawFd`.
+///
+/// # Other hazards
+///
+/// This has the same hazards as [`stderr`].
+///
+/// # References
+/// - [POSIX]
+/// - [Linux]
+///
+/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/stderr.html
+/// [Linux]: https://man7.org/linux/man-pages/man3/stderr.3.html
+#[doc(alias = "STDERR_FILENO")]
+#[inline]
+pub const fn raw_stderr() -> RawFd {
+ backend::io::types::STDERR_FILENO as RawFd
}