Write more comments.

Make a pass over the crate adding and cleanup up comments and doc aliases.
This commit is contained in:
Dan Gohman
2022-01-13 12:34:34 -08:00
parent 79c366d7a6
commit f7e4c56df5
46 changed files with 479 additions and 55 deletions
+10 -10
View File
@@ -32,7 +32,7 @@ portable APIs built on this functionality, see the [`system-interface`],
The `linux_raw` backend is enabled by default on Linux on x86-64, x86, aarch64,
riscv64gc and arm (v5 onwards), and uses raw Linux system calls and vDSO calls.
It supports stable as well as nightly Rust.
It supports stable as well as nightly and 1.48 Rust.
- By being implemented entirely in Rust, avoiding `libc`, `errno`, and pthread
cancellation, and employing some specialized optimizations, most functions
compile down to very efficient code. On nightly Rust, they can often be
@@ -42,11 +42,10 @@ It supports stable as well as nightly Rust.
- `linux_raw` uses a 64-bit `time_t` type on all platforms, avoiding the
[y2038 bug].
The `libc` backend is enabled by default on all other platforms, and can be
set explicitly for any target by setting `RUSTFLAGS` to
`--cfg rustix_use_libc`. It uses the [`libc`] crate which provides bindings to
native `libc` libraries, as well as [`winapi`] for Winsock2, and is portable to
many OS's.
The `libc` backend is enabled by default on all other platforms, and can be set
explicitly for any target by setting `RUSTFLAGS` to `--cfg=rustix_use_libc`. It
uses the [`libc`] crate which provides bindings to native `libc` libraries, and
[`winapi`] for Winsock2, and is portable to many OS's.
## Similar crates
@@ -80,12 +79,12 @@ way, so users don't need to open `.` to get a current-directory handle.
`rustix`'s `openat2` function is similar to the [`openat2`] crate, but uses
I/O safety types rather than `RawFd`. `rustix` does not provide dynamic feature
detection, so users must handle `NOSYS` themselves.
detection, so users must handle the [`NOSYS`] error themselves.
# Minimum Supported Rust Version
# Minimum Supported Rust Version (MSRV)
This crate currently works on the version of [Rust on Debian stable], which
is currently Rust 1.48. This policy may change in the future, in minor version
This crate currently works on the version of [Rust on Debian stable], which is
currently Rust 1.48. This policy may change in the future, in minor version
releases, so users using a fixed version of Rust should pin to a specific
version of this crate.
@@ -114,3 +113,4 @@ version of this crate.
[y2038 bug]: https://en.wikipedia.org/wiki/Year_2038_problem
[`OwnedFd`]: https://docs.rs/io-lifetimes/latest/io_lifetimes/struct.OwnedFd.html
[`AsFd`]: https://docs.rs/io-lifetimes/latest/io_lifetimes/trait.AsFd.html
[`NOSYS`]: https://docs.rs/rustix/latest/rustix/io/struct.Error.html#associatedconstant.NOSYS
+2
View File
@@ -1,3 +1,5 @@
//! A command which prints out information about the process it runs in.
#[cfg(not(windows))]
use rustix::io;
#[cfg(not(windows))]
+3
View File
@@ -1,3 +1,6 @@
//! A command which prints out information about the standard input,
//! output, and error streams provided to it.
#[cfg(not(windows))]
use rustix::fd::AsFd;
#[cfg(any(all(linux_raw, feature = "procfs"), all(not(windows), libc)))]
+3
View File
@@ -1,3 +1,6 @@
//! A command which prints the current values of the realtime and monotonic
//! clocks it's given.
#[cfg(not(windows))]
fn main() {
println!(
+11
View File
@@ -1,3 +1,8 @@
//! 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.
use crate::imp;
use crate::io::{self, OwnedFd};
use imp::fd::{AsFd, RawFd};
@@ -12,6 +17,7 @@ use imp::fs::{FdFlags, OFlags};
/// [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> {
let fd = fd.as_fd();
imp::syscalls::fcntl_getfd(fd)
@@ -26,6 +32,7 @@ pub fn fcntl_getfd<Fd: AsFd>(fd: &Fd) -> io::Result<FdFlags> {
/// [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<()> {
let fd = fd.as_fd();
imp::syscalls::fcntl_setfd(fd, flags)
@@ -40,6 +47,7 @@ pub fn fcntl_setfd<Fd: AsFd>(fd: &Fd, flags: FdFlags) -> io::Result<()> {
/// [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_GETFL")]
pub fn fcntl_getfl<Fd: AsFd>(fd: &Fd) -> io::Result<OFlags> {
let fd = fd.as_fd();
imp::syscalls::fcntl_getfl(fd)
@@ -54,6 +62,7 @@ pub fn fcntl_getfl<Fd: AsFd>(fd: &Fd) -> io::Result<OFlags> {
/// [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_SETFL")]
pub fn fcntl_setfl<Fd: AsFd>(fd: &Fd, flags: OFlags) -> io::Result<()> {
let fd = fd.as_fd();
imp::syscalls::fcntl_setfl(fd, flags)
@@ -82,6 +91,7 @@ pub fn fcntl_setfl<Fd: AsFd>(fd: &Fd, flags: OFlags) -> io::Result<()> {
)
))]
#[inline]
#[doc(alias = "F_GET_SEALS")]
pub fn fcntl_get_seals<Fd: AsFd>(fd: &Fd) -> io::Result<u32> {
let fd = fd.as_fd();
imp::syscalls::fcntl_get_seals(fd)
@@ -104,6 +114,7 @@ pub fn fcntl_get_seals<Fd: AsFd>(fd: &Fd) -> io::Result<u32> {
/// [Linux]: https://man7.org/linux/man-pages/man2/fcntl.2.html
#[cfg(not(target_os = "wasi"))]
#[inline]
#[doc(alias = "F_DUPFD_CLOEXEC")]
pub fn fcntl_dupfd_cloexec<Fd: AsFd>(fd: &Fd, min: RawFd) -> io::Result<OwnedFd> {
let fd = fd.as_fd();
imp::syscalls::fcntl_dupfd_cloexec(fd, min)
+4
View File
@@ -198,12 +198,16 @@ pub(crate) fn _is_file_read_write(fd: BorrowedFd<'_>) -> io::Result<(bool, bool)
/// `fsync(fd)`—Ensures that file data and metadata is written to the
/// underlying storage device.
///
/// Note that on iOS and macOS this isn't sufficient to ensure that data has
/// reached persistent storage; use [`fcntl_fullfsync`] to ensure that.
///
/// # References
/// - [POSIX]
/// - [Linux]
///
/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/fsync.html
/// [Linux]: https://man7.org/linux/man-pages/man2/fsync.2.html
/// [`fcntl_fullfsync`]: https://docs.rs/rustix/*/x86_64-apple-darwin/rustix/fs/fn.fcntl_fullfsync.html
#[inline]
pub fn fsync<Fd: AsFd>(fd: &Fd) -> io::Result<()> {
let fd = fd.as_fd();
+4
View File
@@ -1,3 +1,7 @@
//! Libc call arguments and return values are often things like `c_int`,
//! `c_uint`, or libc-specific pointer types. This module provides functions
//! for converting between rustix's types and libc types.
#![allow(dead_code)]
use super::c;
+161 -3
View File
@@ -3,8 +3,6 @@
//! This type holds an OS error code, which conceptually corresponds to an
//! `errno` value.
#![allow(missing_docs)]
use super::super::c;
use errno::errno;
@@ -13,14 +11,19 @@ use errno::errno;
/// This is similar to `std::io::Error`, but only holds an OS error code,
/// and no extra error value.
#[repr(transparent)]
#[doc(alias = "errno")]
#[derive(Eq, PartialEq, Hash, Copy, Clone)]
pub struct Error(pub(crate) c::c_int);
impl Error {
/// `EACCES`
#[doc(alias = "ACCES")]
pub const ACCESS: Self = Self(c::EACCES);
/// `EADDRINUSE`
pub const ADDRINUSE: Self = Self(c::EADDRINUSE);
/// `EADDRNOTAVAIL`
pub const ADDRNOTAVAIL: Self = Self(c::EADDRNOTAVAIL);
/// `EADV`
#[cfg(not(any(
windows,
target_os = "dragonfly",
@@ -32,9 +35,13 @@ impl Error {
target_os = "wasi",
)))]
pub const ADV: Self = Self(c::EADV);
/// `EAFNOSUPPORT`
pub const AFNOSUPPORT: Self = Self(c::EAFNOSUPPORT);
/// `EAGAIN`
pub const AGAIN: Self = Self(c::EAGAIN);
/// `EALREADY`
pub const ALREADY: Self = Self(c::EALREADY);
/// `EAUTH`
#[cfg(any(
target_os = "dragonfly",
target_os = "freebsd",
@@ -44,6 +51,7 @@ impl Error {
target_os = "openbsd"
))]
pub const AUTH: Self = Self(c::EAUTH);
/// `EBADE`
#[cfg(not(any(
windows,
target_os = "dragonfly",
@@ -55,7 +63,9 @@ impl Error {
target_os = "wasi",
)))]
pub const BADE: Self = Self(c::EBADE);
/// `EBADF`
pub const BADF: Self = Self(c::EBADF);
/// `EBADFD`
#[cfg(not(any(
windows,
target_os = "dragonfly",
@@ -67,8 +77,10 @@ impl Error {
target_os = "wasi",
)))]
pub const BADFD: Self = Self(c::EBADFD);
/// `EBADMSG`
#[cfg(not(windows))]
pub const BADMSG: Self = Self(c::EBADMSG);
/// `EBADR`
#[cfg(not(any(
windows,
target_os = "dragonfly",
@@ -80,6 +92,7 @@ impl Error {
target_os = "wasi",
)))]
pub const BADR: Self = Self(c::EBADR);
/// `EBADRPC`
#[cfg(any(
target_os = "dragonfly",
target_os = "freebsd",
@@ -89,6 +102,7 @@ impl Error {
target_os = "openbsd"
))]
pub const BADRPC: Self = Self(c::EBADRPC);
/// `EBADRQC`
#[cfg(not(any(
windows,
target_os = "dragonfly",
@@ -100,6 +114,7 @@ impl Error {
target_os = "wasi",
)))]
pub const BADRQC: Self = Self(c::EBADRQC);
/// `EBADSLT`
#[cfg(not(any(
windows,
target_os = "dragonfly",
@@ -111,6 +126,7 @@ impl Error {
target_os = "wasi",
)))]
pub const BADSLT: Self = Self(c::EBADSLT);
/// `EBFONT`
#[cfg(not(any(
windows,
target_os = "dragonfly",
@@ -122,13 +138,18 @@ impl Error {
target_os = "wasi",
)))]
pub const BFONT: Self = Self(c::EBFONT);
/// `EBUSY`
#[cfg(not(windows))]
pub const BUSY: Self = Self(c::EBUSY);
/// `ECANCELED`
pub const CANCELED: Self = Self(c::ECANCELED);
/// `ECAPMODE`
#[cfg(any(target_os = "freebsd"))]
pub const CAPMODE: Self = Self(c::ECAPMODE);
/// `ECHILD`
#[cfg(not(windows))]
pub const CHILD: Self = Self(c::ECHILD);
/// `ECHRNG`
#[cfg(not(any(
windows,
target_os = "dragonfly",
@@ -140,6 +161,7 @@ impl Error {
target_os = "wasi",
)))]
pub const CHRNG: Self = Self(c::ECHRNG);
/// `ECOMM`
#[cfg(not(any(
windows,
target_os = "dragonfly",
@@ -151,11 +173,16 @@ impl Error {
target_os = "wasi",
)))]
pub const COMM: Self = Self(c::ECOMM);
/// `ECONNABORTED`
pub const CONNABORTED: Self = Self(c::ECONNABORTED);
/// `ECONNREFUSED`
pub const CONNREFUSED: Self = Self(c::ECONNREFUSED);
/// `ECONNRESET`
pub const CONNRESET: Self = Self(c::ECONNRESET);
/// `EDEADLK`
#[cfg(not(windows))]
pub const DEADLK: Self = Self(c::EDEADLK);
/// `EDEADLOCK`
#[cfg(not(any(
windows,
target_os = "dragonfly",
@@ -168,13 +195,18 @@ impl Error {
target_os = "wasi",
)))]
pub const DEADLOCK: Self = Self(c::EDEADLOCK);
/// `EDESTADDRREQ`
pub const DESTADDRREQ: Self = Self(c::EDESTADDRREQ);
/// `EDISCON`
#[cfg(windows)]
pub const DISCON: Self = Self(c::EDISCON);
/// `EDOM`
#[cfg(not(windows))]
pub const DOM: Self = Self(c::EDOM);
/// `EDOOFUS`
#[cfg(any(target_os = "dragonfly", target_os = "freebsd"))]
pub const DOOFUS: Self = Self(c::EDOOFUS);
/// `EDOTDOT`
#[cfg(not(any(
windows,
target_os = "dragonfly",
@@ -186,12 +218,17 @@ impl Error {
target_os = "wasi",
)))]
pub const DOTDOT: Self = Self(c::EDOTDOT);
/// `EDQUOT`
pub const DQUOT: Self = Self(c::EDQUOT);
/// `EEXIST`
#[cfg(not(windows))]
pub const EXIST: Self = Self(c::EEXIST);
/// `EFAULT`
pub const FAULT: Self = Self(c::EFAULT);
/// `EFBIG`
#[cfg(not(windows))]
pub const FBIG: Self = Self(c::EFBIG);
/// `EFTYPE`
#[cfg(any(
target_env = "newlib",
target_os = "dragonfly",
@@ -202,9 +239,12 @@ impl Error {
target_os = "openbsd"
))]
pub const FTYPE: Self = Self(c::EFTYPE);
/// `EHOSTDOWN`
#[cfg(not(target_os = "wasi"))]
pub const HOSTDOWN: Self = Self(c::EHOSTDOWN);
/// `EHOSTUNREACH`
pub const HOSTUNREACH: Self = Self(c::EHOSTUNREACH);
/// `EHWPOISON`
#[cfg(not(any(
windows,
target_os = "android",
@@ -218,22 +258,38 @@ impl Error {
target_os = "wasi",
)))]
pub const HWPOISON: Self = Self(c::EHWPOISON);
/// `EIDRM`
#[cfg(not(windows))]
pub const IDRM: Self = Self(c::EIDRM);
/// `EILSEQ`
#[cfg(not(windows))]
pub const ILSEQ: Self = Self(c::EILSEQ);
/// `EINPROGRESS`
pub const INPROGRESS: Self = Self(c::EINPROGRESS);
/// `EINTR`
///
/// For a convenient way to retry system calls that exit with `INTR`, use
/// [`with_retrying`].
///
/// [`with_retrying`]: crate::io::with_retrying
pub const INTR: Self = Self(c::EINTR);
/// `EINVAL`
pub const INVAL: Self = Self(c::EINVAL);
/// `EINVALIDPROCTABLE`
#[cfg(windows)]
pub const INVALIDPROCTABLE: Self = Self(c::EINVALIDPROCTABLE);
/// `EINVALIDPROVIDER`
#[cfg(windows)]
pub const INVALIDPROVIDER: Self = Self(c::EINVALIDPROVIDER);
/// `EIO`
#[cfg(not(windows))]
pub const IO: Self = Self(c::EIO);
/// `EISCONN`
pub const ISCONN: Self = Self(c::EISCONN);
/// `EISDIR`
#[cfg(not(windows))]
pub const ISDIR: Self = Self(c::EISDIR);
/// `EISNAM`
#[cfg(not(any(
windows,
target_os = "dragonfly",
@@ -245,6 +301,7 @@ impl Error {
target_os = "wasi",
)))]
pub const ISNAM: Self = Self(c::EISNAM);
/// `EKEYEXPIRED`
#[cfg(not(any(
windows,
target_os = "dragonfly",
@@ -256,6 +313,7 @@ impl Error {
target_os = "wasi",
)))]
pub const KEYEXPIRED: Self = Self(c::EKEYEXPIRED);
/// `EKEYREJECTED`
#[cfg(not(any(
windows,
target_os = "dragonfly",
@@ -267,6 +325,7 @@ impl Error {
target_os = "wasi",
)))]
pub const KEYREJECTED: Self = Self(c::EKEYREJECTED);
/// `EKEYREVOKED`
#[cfg(not(any(
windows,
target_os = "dragonfly",
@@ -278,6 +337,7 @@ impl Error {
target_os = "wasi",
)))]
pub const KEYREVOKED: Self = Self(c::EKEYREVOKED);
/// `EL2HLT`
#[cfg(not(any(
windows,
target_os = "dragonfly",
@@ -289,6 +349,7 @@ impl Error {
target_os = "wasi",
)))]
pub const L2HLT: Self = Self(c::EL2HLT);
/// `EL2NSYNC`
#[cfg(not(any(
windows,
target_os = "dragonfly",
@@ -300,6 +361,7 @@ impl Error {
target_os = "wasi",
)))]
pub const L2NSYNC: Self = Self(c::EL2NSYNC);
/// `EL3HLT`
#[cfg(not(any(
windows,
target_os = "dragonfly",
@@ -311,6 +373,7 @@ impl Error {
target_os = "wasi",
)))]
pub const L3HLT: Self = Self(c::EL3HLT);
/// `EL3RST`
#[cfg(not(any(
windows,
target_os = "dragonfly",
@@ -322,6 +385,7 @@ impl Error {
target_os = "wasi",
)))]
pub const L3RST: Self = Self(c::EL3RST);
/// `ELIBACC`
#[cfg(not(any(
windows,
target_os = "dragonfly",
@@ -333,6 +397,7 @@ impl Error {
target_os = "wasi",
)))]
pub const LIBACC: Self = Self(c::ELIBACC);
/// `ELIBBAD`
#[cfg(not(any(
windows,
target_os = "dragonfly",
@@ -344,6 +409,7 @@ impl Error {
target_os = "wasi",
)))]
pub const LIBBAD: Self = Self(c::ELIBBAD);
/// `ELIBEXEC`
#[cfg(not(any(
windows,
target_os = "dragonfly",
@@ -355,6 +421,7 @@ impl Error {
target_os = "wasi",
)))]
pub const LIBEXEC: Self = Self(c::ELIBEXEC);
/// `ELIBMAX`
#[cfg(not(any(
windows,
target_os = "dragonfly",
@@ -366,6 +433,7 @@ impl Error {
target_os = "wasi",
)))]
pub const LIBMAX: Self = Self(c::ELIBMAX);
/// `ELIBSCN`
#[cfg(not(any(
windows,
target_os = "dragonfly",
@@ -377,6 +445,7 @@ impl Error {
target_os = "wasi",
)))]
pub const LIBSCN: Self = Self(c::ELIBSCN);
/// `ELNRNG`
#[cfg(not(any(
windows,
target_os = "dragonfly",
@@ -388,7 +457,9 @@ impl Error {
target_os = "wasi",
)))]
pub const LNRNG: Self = Self(c::ELNRNG);
/// `ELOOP`
pub const LOOP: Self = Self(c::ELOOP);
/// `EMEDIUMTYPE`
#[cfg(not(any(
windows,
target_os = "dragonfly",
@@ -400,13 +471,19 @@ impl Error {
target_os = "wasi",
)))]
pub const MEDIUMTYPE: Self = Self(c::EMEDIUMTYPE);
/// `EMFILE`
pub const MFILE: Self = Self(c::EMFILE);
/// `EMLINK`
#[cfg(not(windows))]
pub const MLINK: Self = Self(c::EMLINK);
/// `EMSGSIZE`
pub const MSGSIZE: Self = Self(c::EMSGSIZE);
/// `EMULTIHOP`
#[cfg(not(any(windows, target_os = "openbsd")))]
pub const MULTIHOP: Self = Self(c::EMULTIHOP);
/// `ENAMETOOLONG`
pub const NAMETOOLONG: Self = Self(c::ENAMETOOLONG);
/// `ENAVAIL`
#[cfg(not(any(
windows,
target_os = "dragonfly",
@@ -418,6 +495,7 @@ impl Error {
target_os = "wasi",
)))]
pub const NAVAIL: Self = Self(c::ENAVAIL);
/// `ENEEDAUTH`
#[cfg(any(
target_os = "dragonfly",
target_os = "freebsd",
@@ -427,11 +505,16 @@ impl Error {
target_os = "openbsd"
))]
pub const NEEDAUTH: Self = Self(c::ENEEDAUTH);
/// `ENETDOWN`
pub const NETDOWN: Self = Self(c::ENETDOWN);
/// `ENETRESET`
pub const NETRESET: Self = Self(c::ENETRESET);
/// `ENETUNREACH`
pub const NETUNREACH: Self = Self(c::ENETUNREACH);
/// `ENFILE`
#[cfg(not(windows))]
pub const NFILE: Self = Self(c::ENFILE);
/// `ENOANO`
#[cfg(not(any(
windows,
target_os = "dragonfly",
@@ -443,6 +526,7 @@ impl Error {
target_os = "wasi",
)))]
pub const NOANO: Self = Self(c::ENOANO);
/// `ENOATTR`
#[cfg(any(
target_os = "dragonfly",
target_os = "freebsd",
@@ -452,7 +536,9 @@ impl Error {
target_os = "openbsd"
))]
pub const NOATTR: Self = Self(c::ENOATTR);
/// `ENOBUFS`
pub const NOBUFS: Self = Self(c::ENOBUFS);
/// `ENOCSI`
#[cfg(not(any(
windows,
target_os = "dragonfly",
@@ -464,6 +550,7 @@ impl Error {
target_os = "wasi",
)))]
pub const NOCSI: Self = Self(c::ENOCSI);
/// `ENODATA`
#[cfg(not(any(
windows,
target_os = "dragonfly",
@@ -472,12 +559,16 @@ impl Error {
target_os = "wasi",
)))]
pub const NODATA: Self = Self(c::ENODATA);
/// `ENODEV`
#[cfg(not(windows))]
pub const NODEV: Self = Self(c::ENODEV);
/// `ENOENT`
#[cfg(not(windows))]
pub const NOENT: Self = Self(c::ENOENT);
/// `ENOEXEC`
#[cfg(not(windows))]
pub const NOEXEC: Self = Self(c::ENOEXEC);
/// `ENOKEY`
#[cfg(not(any(
windows,
target_os = "dragonfly",
@@ -489,10 +580,13 @@ impl Error {
target_os = "wasi",
)))]
pub const NOKEY: Self = Self(c::ENOKEY);
/// `ENOLCK`
#[cfg(not(windows))]
pub const NOLCK: Self = Self(c::ENOLCK);
/// `ENOLINK`
#[cfg(not(any(windows, target_os = "openbsd")))]
pub const NOLINK: Self = Self(c::ENOLINK);
/// `ENOMEDIUM`
#[cfg(not(any(
windows,
target_os = "dragonfly",
@@ -504,12 +598,16 @@ impl Error {
target_os = "wasi",
)))]
pub const NOMEDIUM: Self = Self(c::ENOMEDIUM);
/// `ENOMEM`
#[cfg(not(windows))]
pub const NOMEM: Self = Self(c::ENOMEM);
/// `ENOMORE`
#[cfg(windows)]
pub const NOMORE: Self = Self(c::ENOMORE);
/// `ENOMSG`
#[cfg(not(windows))]
pub const NOMSG: Self = Self(c::ENOMSG);
/// `ENONET`
#[cfg(not(any(
windows,
target_os = "dragonfly",
@@ -521,6 +619,7 @@ impl Error {
target_os = "wasi",
)))]
pub const NONET: Self = Self(c::ENONET);
/// `ENOPKG`
#[cfg(not(any(
windows,
target_os = "dragonfly",
@@ -532,9 +631,12 @@ impl Error {
target_os = "wasi",
)))]
pub const NOPKG: Self = Self(c::ENOPKG);
/// `ENOPROTOOPT`
pub const NOPROTOOPT: Self = Self(c::ENOPROTOOPT);
/// `ENOSPC`
#[cfg(not(windows))]
pub const NOSPC: Self = Self(c::ENOSPC);
/// `ENOSR`
#[cfg(not(any(
windows,
target_os = "dragonfly",
@@ -543,6 +645,7 @@ impl Error {
target_os = "wasi",
)))]
pub const NOSR: Self = Self(c::ENOSR);
/// `ENOSTR`
#[cfg(not(any(
windows,
target_os = "dragonfly",
@@ -551,16 +654,23 @@ impl Error {
target_os = "wasi",
)))]
pub const NOSTR: Self = Self(c::ENOSTR);
/// `ENOSYS`
#[cfg(not(windows))]
pub const NOSYS: Self = Self(c::ENOSYS);
/// `ENOTBLK`
#[cfg(not(any(windows, target_os = "wasi")))]
pub const NOTBLK: Self = Self(c::ENOTBLK);
/// `ENOTCAPABLE`
#[cfg(any(target_os = "freebsd", target_os = "wasi"))]
pub const NOTCAPABLE: Self = Self(c::ENOTCAPABLE);
/// `ENOTCONN`
pub const NOTCONN: Self = Self(c::ENOTCONN);
/// `ENOTDIR`
#[cfg(not(windows))]
pub const NOTDIR: Self = Self(c::ENOTDIR);
/// `ENOTEMPTY`
pub const NOTEMPTY: Self = Self(c::ENOTEMPTY);
/// `ENOTNAM`
#[cfg(not(any(
windows,
target_os = "dragonfly",
@@ -572,13 +682,18 @@ impl Error {
target_os = "wasi",
)))]
pub const NOTNAM: Self = Self(c::ENOTNAM);
/// `ENOTRECOVERABLE`
#[cfg(not(any(windows, target_os = "dragonfly", target_os = "netbsd")))]
pub const NOTRECOVERABLE: Self = Self(c::ENOTRECOVERABLE);
/// `ENOTSOCK`
pub const NOTSOCK: Self = Self(c::ENOTSOCK);
/// `ENOTSUP`
#[cfg(not(any(windows, target_os = "redox")))]
pub const NOTSUP: Self = Self(c::ENOTSUP);
/// `ENOTTY`
#[cfg(not(windows))]
pub const NOTTY: Self = Self(c::ENOTTY);
/// `ENOTUNIQ`
#[cfg(not(any(
windows,
target_os = "dragonfly",
@@ -590,19 +705,27 @@ impl Error {
target_os = "wasi",
)))]
pub const NOTUNIQ: Self = Self(c::ENOTUNIQ);
/// `ENXIO`
#[cfg(not(windows))]
pub const NXIO: Self = Self(c::ENXIO);
/// `EOPNOTSUPP`
pub const OPNOTSUPP: Self = Self(c::EOPNOTSUPP);
/// `EOVERFLOW`
#[cfg(not(windows))]
pub const OVERFLOW: Self = Self(c::EOVERFLOW);
/// `EOWNERDEAD`
#[cfg(not(any(windows, target_os = "dragonfly", target_os = "netbsd")))]
pub const OWNERDEAD: Self = Self(c::EOWNERDEAD);
/// `EPERM`
#[cfg(not(windows))]
pub const PERM: Self = Self(c::EPERM);
/// `EPFNOSUPPORT`
#[cfg(not(target_os = "wasi"))]
pub const PFNOSUPPORT: Self = Self(c::EPFNOSUPPORT);
/// `EPIPE`
#[cfg(not(windows))]
pub const PIPE: Self = Self(c::EPIPE);
/// `EPROCLIM`
#[cfg(any(
target_os = "dragonfly",
target_os = "freebsd",
@@ -612,6 +735,7 @@ impl Error {
target_os = "openbsd"
))]
pub const PROCLIM: Self = Self(c::EPROCLIM);
/// `EPROCUNAVAIL`
#[cfg(any(
target_os = "dragonfly",
target_os = "freebsd",
@@ -621,6 +745,7 @@ impl Error {
target_os = "openbsd"
))]
pub const PROCUNAVAIL: Self = Self(c::EPROCUNAVAIL);
/// `EPROGMISMATCH`
#[cfg(any(
target_os = "dragonfly",
target_os = "freebsd",
@@ -630,6 +755,7 @@ impl Error {
target_os = "openbsd"
))]
pub const PROGMISMATCH: Self = Self(c::EPROGMISMATCH);
/// `EPROGUNAVAIL`
#[cfg(any(
target_os = "dragonfly",
target_os = "freebsd",
@@ -639,16 +765,23 @@ impl Error {
target_os = "openbsd"
))]
pub const PROGUNAVAIL: Self = Self(c::EPROGUNAVAIL);
/// `EPROTO`
#[cfg(not(windows))]
pub const PROTO: Self = Self(c::EPROTO);
/// `EPROTONOSUPPORT`
pub const PROTONOSUPPORT: Self = Self(c::EPROTONOSUPPORT);
/// `EPROTOTYPE`
pub const PROTOTYPE: Self = Self(c::EPROTOTYPE);
/// `EPROVIDERFAILEDINIT`
#[cfg(windows)]
pub const PROVIDERFAILEDINIT: Self = Self(c::EPROVIDERFAILEDINIT);
/// `ERANGE`
#[cfg(not(windows))]
pub const RANGE: Self = Self(c::ERANGE);
/// `EREFUSED`
#[cfg(windows)]
pub const REFUSED: Self = Self(c::EREFUSED);
/// `EREMCHG`
#[cfg(not(any(
windows,
target_os = "dragonfly",
@@ -660,8 +793,10 @@ impl Error {
target_os = "wasi",
)))]
pub const REMCHG: Self = Self(c::EREMCHG);
/// `EREMOTE`
#[cfg(not(target_os = "wasi"))]
pub const REMOTE: Self = Self(c::EREMOTE);
/// `EREMOTEIO`
#[cfg(not(any(
windows,
target_os = "dragonfly",
@@ -673,6 +808,7 @@ impl Error {
target_os = "wasi",
)))]
pub const REMOTEIO: Self = Self(c::EREMOTEIO);
/// `ERESTART`
#[cfg(not(any(
windows,
target_os = "dragonfly",
@@ -684,6 +820,7 @@ impl Error {
target_os = "wasi",
)))]
pub const RESTART: Self = Self(c::ERESTART);
/// `ERFKILL`
#[cfg(not(any(
windows,
target_os = "android",
@@ -697,8 +834,10 @@ impl Error {
target_os = "wasi",
)))]
pub const RFKILL: Self = Self(c::ERFKILL);
/// `EROFS`
#[cfg(not(windows))]
pub const ROFS: Self = Self(c::EROFS);
/// `ERPCMISMATCH`
#[cfg(any(
target_os = "dragonfly",
target_os = "freebsd",
@@ -708,14 +847,19 @@ impl Error {
target_os = "openbsd"
))]
pub const RPCMISMATCH: Self = Self(c::ERPCMISMATCH);
/// `ESHUTDOWN`
#[cfg(not(target_os = "wasi"))]
pub const SHUTDOWN: Self = Self(c::ESHUTDOWN);
/// `ESOCKTNOSUPPORT`
#[cfg(not(target_os = "wasi"))]
pub const SOCKTNOSUPPORT: Self = Self(c::ESOCKTNOSUPPORT);
/// `ESPIPE`
#[cfg(not(windows))]
pub const SPIPE: Self = Self(c::ESPIPE);
/// `ESRCH`
#[cfg(not(windows))]
pub const SRCH: Self = Self(c::ESRCH);
/// `ESRMNT`
#[cfg(not(any(
windows,
target_os = "dragonfly",
@@ -727,7 +871,9 @@ impl Error {
target_os = "wasi",
)))]
pub const SRMNT: Self = Self(c::ESRMNT);
/// `ESTALE`
pub const STALE: Self = Self(c::ESTALE);
/// `ESTRPIPE`
#[cfg(not(any(
windows,
target_os = "dragonfly",
@@ -739,6 +885,7 @@ impl Error {
target_os = "wasi",
)))]
pub const STRPIPE: Self = Self(c::ESTRPIPE);
/// `ETIME`
#[cfg(not(any(
windows,
target_os = "dragonfly",
@@ -747,13 +894,19 @@ impl Error {
target_os = "wasi",
)))]
pub const TIME: Self = Self(c::ETIME);
/// `ETIMEDOUT`
pub const TIMEDOUT: Self = Self(c::ETIMEDOUT);
/// `E2BIG`
#[cfg(not(windows))]
#[doc(alias = "2BIG")]
pub const TOOBIG: Self = Self(c::E2BIG);
/// `ETOOMANYREFS`
#[cfg(not(target_os = "wasi"))]
pub const TOOMANYREFS: Self = Self(c::ETOOMANYREFS);
/// `ETXTBSY`
#[cfg(not(windows))]
pub const TXTBSY: Self = Self(c::ETXTBSY);
/// `EUCLEAN`
#[cfg(not(any(
windows,
target_os = "dragonfly",
@@ -765,6 +918,7 @@ impl Error {
target_os = "wasi",
)))]
pub const UCLEAN: Self = Self(c::EUCLEAN);
/// `EUNATCH`
#[cfg(not(any(
windows,
target_os = "dragonfly",
@@ -776,11 +930,15 @@ impl Error {
target_os = "wasi",
)))]
pub const UNATCH: Self = Self(c::EUNATCH);
/// `EUSERS`
#[cfg(not(target_os = "wasi"))]
pub const USERS: Self = Self(c::EUSERS);
/// `EWOULDBLOCK`
pub const WOULDBLOCK: Self = Self(c::EWOULDBLOCK);
/// `EXDEV`
#[cfg(not(windows))]
pub const XDEV: Self = Self(c::EXDEV);
/// `EXFULL`
#[cfg(not(any(
windows,
target_os = "dragonfly",
@@ -795,7 +953,7 @@ impl Error {
}
impl Error {
/// Extract the raw OS error number from this error.
/// Extract an `Error` value from a `std::io::Error`.
///
/// This isn't a `From` conversion because it's expected to be relatively
/// uncommon.
+2
View File
@@ -1,3 +1,5 @@
//! aarch64 Linux system calls.
use crate::imp::reg::{ArgReg, FromAsm, RetReg, SyscallNumber, ToAsm, A0, A1, A2, A3, A4, A5, R0};
use core::arch::asm;
+2
View File
@@ -1,3 +1,5 @@
//! arm Linux system calls.
use crate::imp::reg::{ArgReg, FromAsm, RetReg, SyscallNumber, ToAsm, A0, A1, A2, A3, A4, A5, R0};
use core::arch::asm;
+2
View File
@@ -1,3 +1,5 @@
//! riscv64 Linux system calls.
use crate::imp::reg::{ArgReg, FromAsm, RetReg, SyscallNumber, ToAsm, A0, A1, A2, A3, A4, A5, R0};
use core::arch::asm;
+2
View File
@@ -1,3 +1,5 @@
//! x86-64 Linux system calls.
use crate::imp::reg::{ArgReg, FromAsm, RetReg, SyscallNumber, ToAsm, A0, A1, A2, A3, A4, A5, R0};
use core::arch::asm;
+2
View File
@@ -1,3 +1,5 @@
// Assembly code for making aarch64 syscalls.
//
// aarch64 syscall argument register ordering is the same as the aarch64
// userspace argument register ordering except that the syscall number
// (nr) is passed in w8.
+3 -1
View File
@@ -1,3 +1,5 @@
// Assembly code for making arm syscalls.
//
// arm syscall argument register ordering is the similar to the arm
// userspace argument register ordering except that the syscall number
// (nr) is passed in r7.
@@ -37,7 +39,7 @@ rustix_syscall1_nr_last:
pop {r7, pc}
.fnend
.size rustix_syscall1_nr_last, .-rustix_syscall1_nr_last
.section .text.rustix_syscall1_noreturn_nr_last,"ax",%progbits
.p2align 4
.weak rustix_syscall1_noreturn_nr_last
+2
View File
@@ -1,3 +1,5 @@
# Assembly code for making riscv64 syscalls.
#
# riscv64 syscall argument register ordering is the same as the riscv64
# userspace argument register ordering except that the syscall number
# (nr) is passed in a7.
+2
View File
@@ -1,3 +1,5 @@
// Assembly code for making x86 syscalls.
//
// On x86 we use the "fastcall" convention which passes the first two
// arguments in ecx and edx. Outline.rs reorders the arguments to put
// a1 and a2 in those registers so they we don't have to move them to
+2
View File
@@ -1,3 +1,5 @@
// Assembly code for making x86-64 syscalls.
//
// x86-64 syscall argument register ordering is the same as the x86-64
// userspace argument register ordering except that a3 is passed in r10
// instead of rcx, and the syscall number (nr) is passed in eax.
+143 -2
View File
@@ -8,7 +8,6 @@
//! Linux uses error codes in `-4095..0`; we use rustc attributes to describe
//! this restricted range of values.
#![allow(unsafe_code)]
#![allow(missing_docs)]
#![cfg_attr(not(rustc_attrs), allow(unused_unsafe))]
use super::super::c;
@@ -22,6 +21,7 @@ use linux_raw_sys::{errno, v5_4};
/// This is similar to `std::io::Error`, but only holds an OS error code,
/// and no extra error value.
#[repr(transparent)]
#[doc(alias = "errno")]
#[derive(Eq, PartialEq, Hash, Copy, Clone)]
// Linux returns negated error codes, and we leave them in negated form, so
// error codes are in `-4095..0`.
@@ -30,7 +30,7 @@ use linux_raw_sys::{errno, v5_4};
pub struct Error(u16);
impl Error {
/// Extract the raw OS error number from this error.
/// Extract an `Error` value from a `std::io::Error`.
///
/// This isn't a `From` conversion because it's expected to be relatively
/// uncommon.
@@ -231,140 +231,281 @@ pub(in crate::imp) fn decode_usize_infallible<Num: RetNumber>(raw: RetReg<Num>)
}
impl Error {
/// `EACCES`
#[doc(alias = "ACCES")]
pub const ACCESS: Self = Self::from_errno(errno::EACCES);
/// `EADDRINUSE`
pub const ADDRINUSE: Self = Self::from_errno(errno::EADDRINUSE);
/// `EADDRNOTAVAIL`
pub const ADDRNOTAVAIL: Self = Self::from_errno(errno::EADDRNOTAVAIL);
/// `EADV`
pub const ADV: Self = Self::from_errno(errno::EADV);
/// `EAFNOSUPPORT`
pub const AFNOSUPPORT: Self = Self::from_errno(errno::EAFNOSUPPORT);
/// `EAGAIN`
pub const AGAIN: Self = Self::from_errno(errno::EAGAIN);
/// `EALREADY`
pub const ALREADY: Self = Self::from_errno(errno::EALREADY);
/// `EBADE`
pub const BADE: Self = Self::from_errno(errno::EBADE);
/// `EBADF`
pub const BADF: Self = Self::from_errno(errno::EBADF);
/// `EBADFD`
pub const BADFD: Self = Self::from_errno(errno::EBADFD);
/// `EBADMSG`
pub const BADMSG: Self = Self::from_errno(errno::EBADMSG);
/// `EBADR`
pub const BADR: Self = Self::from_errno(errno::EBADR);
/// `EBADRQC`
pub const BADRQC: Self = Self::from_errno(errno::EBADRQC);
/// `EBADSLT`
pub const BADSLT: Self = Self::from_errno(errno::EBADSLT);
/// `EBFONT`
pub const BFONT: Self = Self::from_errno(errno::EBFONT);
/// `EBUSY`
pub const BUSY: Self = Self::from_errno(errno::EBUSY);
/// `ECANCELED`
pub const CANCELED: Self = Self::from_errno(errno::ECANCELED);
/// `ECHILD`
pub const CHILD: Self = Self::from_errno(errno::ECHILD);
/// `ECHRNG`
pub const CHRNG: Self = Self::from_errno(errno::ECHRNG);
/// `ECOMM`
pub const COMM: Self = Self::from_errno(errno::ECOMM);
/// `ECONNABORTED`
pub const CONNABORTED: Self = Self::from_errno(errno::ECONNABORTED);
/// `ECONNREFUSED`
pub const CONNREFUSED: Self = Self::from_errno(errno::ECONNREFUSED);
/// `ECONNRESET`
pub const CONNRESET: Self = Self::from_errno(errno::ECONNRESET);
/// `EDEADLK`
pub const DEADLK: Self = Self::from_errno(errno::EDEADLK);
/// `EDEADLOCK`
pub const DEADLOCK: Self = Self::from_errno(errno::EDEADLOCK);
/// `EDESTADDRREQ`
pub const DESTADDRREQ: Self = Self::from_errno(errno::EDESTADDRREQ);
/// `EDOM`
pub const DOM: Self = Self::from_errno(errno::EDOM);
/// `EDOTDOT`
pub const DOTDOT: Self = Self::from_errno(errno::EDOTDOT);
/// `EDQUOT`
pub const DQUOT: Self = Self::from_errno(errno::EDQUOT);
/// `EEXIST`
pub const EXIST: Self = Self::from_errno(errno::EEXIST);
/// `EFAULT`
pub const FAULT: Self = Self::from_errno(errno::EFAULT);
/// `EFBIG`
pub const FBIG: Self = Self::from_errno(errno::EFBIG);
/// `EHOSTDOWN`
pub const HOSTDOWN: Self = Self::from_errno(errno::EHOSTDOWN);
/// `EHOSTUNREACH`
pub const HOSTUNREACH: Self = Self::from_errno(errno::EHOSTUNREACH);
/// `EHWPOISON`
pub const HWPOISON: Self = Self::from_errno(v5_4::errno::EHWPOISON);
/// `EIDRM`
pub const IDRM: Self = Self::from_errno(errno::EIDRM);
/// `EILSEQ`
pub const ILSEQ: Self = Self::from_errno(errno::EILSEQ);
/// `EINPROGRESS`
pub const INPROGRESS: Self = Self::from_errno(errno::EINPROGRESS);
/// `EINTR`.
///
/// For a convenient way to retry system calls that exit with `INTR`, use
/// [`with_retrying`].
///
/// [`with_retrying`]: io::with_retrying
pub const INTR: Self = Self::from_errno(errno::EINTR);
/// `EINVAL`
pub const INVAL: Self = Self::from_errno(errno::EINVAL);
/// `EIO`
pub const IO: Self = Self::from_errno(errno::EIO);
/// `EISCONN`
pub const ISCONN: Self = Self::from_errno(errno::EISCONN);
/// `EISDIR`
pub const ISDIR: Self = Self::from_errno(errno::EISDIR);
/// `EISNAM`
pub const ISNAM: Self = Self::from_errno(errno::EISNAM);
/// `EKEYEXPIRED`
pub const KEYEXPIRED: Self = Self::from_errno(errno::EKEYEXPIRED);
/// `EKEYREJECTED`
pub const KEYREJECTED: Self = Self::from_errno(errno::EKEYREJECTED);
/// `EKEYREVOKED`
pub const KEYREVOKED: Self = Self::from_errno(errno::EKEYREVOKED);
/// `EL2HLT`
pub const L2HLT: Self = Self::from_errno(errno::EL2HLT);
/// `EL2NSYNC`
pub const L2NSYNC: Self = Self::from_errno(errno::EL2NSYNC);
/// `EL3HLT`
pub const L3HLT: Self = Self::from_errno(errno::EL3HLT);
/// `EL3RST`
pub const L3RST: Self = Self::from_errno(errno::EL3RST);
/// `ELIBACC`
pub const LIBACC: Self = Self::from_errno(errno::ELIBACC);
/// `ELIBBAD`
pub const LIBBAD: Self = Self::from_errno(errno::ELIBBAD);
/// `ELIBEXEC`
pub const LIBEXEC: Self = Self::from_errno(errno::ELIBEXEC);
/// `ELIBMAX`
pub const LIBMAX: Self = Self::from_errno(errno::ELIBMAX);
/// `ELIBSCN`
pub const LIBSCN: Self = Self::from_errno(errno::ELIBSCN);
/// `ELNRNG`
pub const LNRNG: Self = Self::from_errno(errno::ELNRNG);
/// `ELOOP`
pub const LOOP: Self = Self::from_errno(errno::ELOOP);
/// `EMEDIUMTYPE`
pub const MEDIUMTYPE: Self = Self::from_errno(errno::EMEDIUMTYPE);
/// `EMFILE`
pub const MFILE: Self = Self::from_errno(errno::EMFILE);
/// `EMLINK`
pub const MLINK: Self = Self::from_errno(errno::EMLINK);
/// `EMSGSIZE`
pub const MSGSIZE: Self = Self::from_errno(errno::EMSGSIZE);
/// `EMULTIHOP`
pub const MULTIHOP: Self = Self::from_errno(errno::EMULTIHOP);
/// `ENAMETOOLONG`
pub const NAMETOOLONG: Self = Self::from_errno(errno::ENAMETOOLONG);
/// `ENAVAIL`
pub const NAVAIL: Self = Self::from_errno(errno::ENAVAIL);
/// `ENETDOWN`
pub const NETDOWN: Self = Self::from_errno(errno::ENETDOWN);
/// `ENETRESET`
pub const NETRESET: Self = Self::from_errno(errno::ENETRESET);
/// `ENETUNREACH`
pub const NETUNREACH: Self = Self::from_errno(errno::ENETUNREACH);
/// `ENFILE`
pub const NFILE: Self = Self::from_errno(errno::ENFILE);
/// `ENOANO`
pub const NOANO: Self = Self::from_errno(errno::ENOANO);
/// `ENOBUFS`
pub const NOBUFS: Self = Self::from_errno(errno::ENOBUFS);
/// `ENOCSI`
pub const NOCSI: Self = Self::from_errno(errno::ENOCSI);
/// `ENODATA`
#[doc(alias = "NOATTR")]
pub const NODATA: Self = Self::from_errno(errno::ENODATA);
/// `ENODEV`
pub const NODEV: Self = Self::from_errno(errno::ENODEV);
/// `ENOENT`
pub const NOENT: Self = Self::from_errno(errno::ENOENT);
/// `ENOEXEC`
pub const NOEXEC: Self = Self::from_errno(errno::ENOEXEC);
/// `ENOKEY`
pub const NOKEY: Self = Self::from_errno(errno::ENOKEY);
/// `ENOLCK`
pub const NOLCK: Self = Self::from_errno(errno::ENOLCK);
/// `ENOLINK`
pub const NOLINK: Self = Self::from_errno(errno::ENOLINK);
/// `ENOMEDIUM`
pub const NOMEDIUM: Self = Self::from_errno(errno::ENOMEDIUM);
/// `ENOMEM`
pub const NOMEM: Self = Self::from_errno(errno::ENOMEM);
/// `ENOMSG`
pub const NOMSG: Self = Self::from_errno(errno::ENOMSG);
/// `ENONET`
pub const NONET: Self = Self::from_errno(errno::ENONET);
/// `ENOPKG`
pub const NOPKG: Self = Self::from_errno(errno::ENOPKG);
/// `ENOPROTOOPT`
pub const NOPROTOOPT: Self = Self::from_errno(errno::ENOPROTOOPT);
/// `ENOSPC`
pub const NOSPC: Self = Self::from_errno(errno::ENOSPC);
/// `ENOSR`
pub const NOSR: Self = Self::from_errno(errno::ENOSR);
/// `ENOSTR`
pub const NOSTR: Self = Self::from_errno(errno::ENOSTR);
/// `ENOSYS`
pub const NOSYS: Self = Self::from_errno(errno::ENOSYS);
/// `ENOTBLK`
pub const NOTBLK: Self = Self::from_errno(errno::ENOTBLK);
/// `ENOTCONN`
pub const NOTCONN: Self = Self::from_errno(errno::ENOTCONN);
/// `ENOTDIR`
pub const NOTDIR: Self = Self::from_errno(errno::ENOTDIR);
/// `ENOTEMPTY`
pub const NOTEMPTY: Self = Self::from_errno(errno::ENOTEMPTY);
/// `ENOTNAM`
pub const NOTNAM: Self = Self::from_errno(errno::ENOTNAM);
/// `ENOTRECOVERABLE`
pub const NOTRECOVERABLE: Self = Self::from_errno(errno::ENOTRECOVERABLE);
/// `ENOTSOCK`
pub const NOTSOCK: Self = Self::from_errno(errno::ENOTSOCK);
/// `ENOTSUP`
// On Linux, `ENOTSUP` has the same value as `EOPNOTSUPP`.
pub const NOTSUP: Self = Self::from_errno(errno::EOPNOTSUPP);
/// `ENOTTY`
pub const NOTTY: Self = Self::from_errno(errno::ENOTTY);
/// `ENOTUNIQ`
pub const NOTUNIQ: Self = Self::from_errno(errno::ENOTUNIQ);
/// `ENXIO`
pub const NXIO: Self = Self::from_errno(errno::ENXIO);
/// `EOPNOTSUPP`
pub const OPNOTSUPP: Self = Self::from_errno(errno::EOPNOTSUPP);
/// `EOVERFLOW`
pub const OVERFLOW: Self = Self::from_errno(errno::EOVERFLOW);
/// `EOWNERDEAD`
pub const OWNERDEAD: Self = Self::from_errno(errno::EOWNERDEAD);
/// `EPERM`
pub const PERM: Self = Self::from_errno(errno::EPERM);
/// `EPFNOSUPPORT`
pub const PFNOSUPPORT: Self = Self::from_errno(errno::EPFNOSUPPORT);
/// `EPIPE`
pub const PIPE: Self = Self::from_errno(errno::EPIPE);
/// `EPROTO`
pub const PROTO: Self = Self::from_errno(errno::EPROTO);
/// `EPROTONOSUPPORT`
pub const PROTONOSUPPORT: Self = Self::from_errno(errno::EPROTONOSUPPORT);
/// `EPROTOTYPE`
pub const PROTOTYPE: Self = Self::from_errno(errno::EPROTOTYPE);
/// `ERANGE`
pub const RANGE: Self = Self::from_errno(errno::ERANGE);
/// `EREMCHG`
pub const REMCHG: Self = Self::from_errno(errno::EREMCHG);
/// `EREMOTE`
pub const REMOTE: Self = Self::from_errno(errno::EREMOTE);
/// `EREMOTEIO`
pub const REMOTEIO: Self = Self::from_errno(errno::EREMOTEIO);
/// `ERESTART`
pub const RESTART: Self = Self::from_errno(errno::ERESTART);
/// `ERFKILL`
pub const RFKILL: Self = Self::from_errno(errno::ERFKILL);
/// `EROFS`
pub const ROFS: Self = Self::from_errno(errno::EROFS);
/// `ESHUTDOWN`
pub const SHUTDOWN: Self = Self::from_errno(errno::ESHUTDOWN);
/// `ESOCKTNOSUPPORT`
pub const SOCKTNOSUPPORT: Self = Self::from_errno(errno::ESOCKTNOSUPPORT);
/// `ESPIPE`
pub const SPIPE: Self = Self::from_errno(errno::ESPIPE);
/// `ESRCH`
pub const SRCH: Self = Self::from_errno(errno::ESRCH);
/// `ESRMNT`
pub const SRMNT: Self = Self::from_errno(errno::ESRMNT);
/// `ESTALE`
pub const STALE: Self = Self::from_errno(errno::ESTALE);
/// `ESTRPIPE`
pub const STRPIPE: Self = Self::from_errno(errno::ESTRPIPE);
/// `ETIME`
pub const TIME: Self = Self::from_errno(errno::ETIME);
/// `ETIMEDOUT`
pub const TIMEDOUT: Self = Self::from_errno(errno::ETIMEDOUT);
/// `E2BIG`
#[doc(alias = "2BIG")]
pub const TOOBIG: Self = Self::from_errno(errno::E2BIG);
/// `ETOOMANYREFS`
pub const TOOMANYREFS: Self = Self::from_errno(errno::ETOOMANYREFS);
/// `ETXTBSY`
pub const TXTBSY: Self = Self::from_errno(errno::ETXTBSY);
/// `EUCLEAN`
pub const UCLEAN: Self = Self::from_errno(errno::EUCLEAN);
/// `EUNATCH`
pub const UNATCH: Self = Self::from_errno(errno::EUNATCH);
/// `EUSERS`
pub const USERS: Self = Self::from_errno(errno::EUSERS);
/// `EWOULDBLOCK`
pub const WOULDBLOCK: Self = Self::from_errno(errno::EWOULDBLOCK);
/// `EXDEV`
pub const XDEV: Self = Self::from_errno(errno::EXDEV);
/// `EXFULL`
pub const XFULL: Self = Self::from_errno(errno::EXFULL);
}
+2 -2
View File
@@ -1,7 +1,7 @@
bitflags::bitflags! {
/// Flags for use with [`futex`].
///
/// [`futex`]: std::thread::futex
/// [`futex`]: crate::thread::futex
pub struct FutexFlags: u32 {
/// `FUTEX_PRIVATE_FLAG`
const PRIVATE = linux_raw_sys::general::FUTEX_PRIVATE_FLAG;
@@ -12,7 +12,7 @@ bitflags::bitflags! {
/// Operations for use with [`futex`].
///
/// [`futex`]: std::thread::futex
/// [`futex`]: crate::thread::futex
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
#[repr(u32)]
pub enum FutexOperation {
+5 -6
View File
@@ -281,7 +281,7 @@ impl Vdso {
/// to our expectations.
#[inline]
pub(super) fn new() -> Option<Self> {
init_from_proc_self_auxv()
init_from_auxv()
}
/// Check the version for a symbol.
@@ -372,9 +372,8 @@ impl Vdso {
}
}
// Find the `AT_SYSINFO_EHDR` in auxv records in memory. We don't currently
// have direct access to the auxv records in memory, so we use /proc/self/auxv
// instead.
// Find the `AT_SYSINFO_EHDR` in auxv records in memory. We have our own code
// for reading the auxv records in memory, so we don't currently use this.
//
// # Safety
//
@@ -394,8 +393,8 @@ unsafe fn init_from_auxv(elf_auxv: *const Elf_auxv_t) -> Option<Vdso> {
}
*/
// Find the `AT_SYSINFO_EHDR` in auxv records in /proc/self/auxv.
fn init_from_proc_self_auxv() -> Option<Vdso> {
// Find the vDSO image by following the `AT_SYSINFO_EHDR` auxv record pointer.
fn init_from_auxv() -> Option<Vdso> {
// Safety: `sysinfo_ehdr` does extensive checks to ensure that the value
// we get really is an `AT_SYSINFO_EHDR` value from the kernel.
unsafe { init_from_sysinfo_ehdr(super::process::sysinfo_ehdr()) }
-1
View File
@@ -1 +0,0 @@
+21
View File
@@ -1,4 +1,8 @@
//! The unsafe `close` for raw file descriptors.
//!
//! # Safety
//!
//! Operating on raw file descriptors is unsafe.
#![allow(unsafe_code)]
use crate::imp;
@@ -9,6 +13,23 @@ use imp::fd::RawFd;
/// Most users won't need to use this, as `OwnedFd` automatically closes its
/// file descriptor on `Drop`.
///
/// This function does not return a `Result`, as it is the [responsibility]
/// of filesystem designers to not return errors from `close`. Users who chose
/// to use NFS or similar filesystems should take care to monitor for problems
/// externally.
///
/// [responsibility]: https://lwn.net/Articles/576518/
///
/// # References
///
/// - [POSIX]
/// - [Linux]
/// - [Apple]
///
/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/close.html
/// [Linux]: https://man7.org/linux/man-pages/man2/close.2.html
/// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/close.2.html#//apple_ref/doc/man/2/close
///
/// # Safety
///
/// This function takes a `RawFd`, which must be valid before the call, and is
+1 -1
View File
@@ -71,7 +71,7 @@ impl From<Error> for std::io::Error {
}
}
/// Call `f` until it either succeeds or fails other than `io::Error::INTR`.
/// Call `f` until it either succeeds or fails other than [`Error::INTR`].
#[inline]
pub fn with_retrying<T, F: FnMut() -> Result<T>>(mut f: F) -> Result<T> {
loop {
+16 -1
View File
@@ -1,3 +1,8 @@
//! The Unix `ioctl` 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.
#[cfg(not(any(windows, target_os = "wasi")))]
use crate::io::{Termios, Winsize};
use crate::{imp, io};
@@ -20,6 +25,7 @@ use imp::fd::AsSocketAsFd;
#[cfg(not(any(windows, target_os = "wasi")))]
#[inline]
#[doc(alias = "tcgetattr")]
#[doc(alias = "TCGETS")]
pub fn ioctl_tcgets<Fd: AsFd>(fd: &Fd) -> io::Result<Termios> {
let fd = fd.as_fd();
imp::syscalls::ioctl_tcgets(fd)
@@ -30,6 +36,8 @@ pub fn ioctl_tcgets<Fd: AsFd>(fd: &Fd) -> io::Result<Termios> {
/// Also known as `fcntl(fd, F_SETFD, FD_CLOEXEC)`.
#[cfg(any(target_os = "ios", target_os = "macos"))]
#[inline]
#[doc(alias = "FIOCLEX")]
#[doc(alias = "FD_CLOEXEC")]
pub fn ioctl_fioclex<Fd: AsFd>(fd: &Fd) -> io::Result<()> {
let fd = fd.as_fd();
imp::syscalls::ioctl_fioclex(fd)
@@ -43,6 +51,7 @@ pub fn ioctl_fioclex<Fd: AsFd>(fd: &Fd) -> io::Result<()> {
/// [Linux]: https://man7.org/linux/man-pages/man4/tty_ioctl.4.html
#[cfg(not(any(windows, target_os = "wasi")))]
#[inline]
#[doc(alias = "TIOCGWINSZ")]
pub fn ioctl_tiocgwinsz<Fd: AsFd>(fd: &Fd) -> io::Result<Winsize> {
let fd = fd.as_fd();
imp::syscalls::ioctl_tiocgwinsz(fd)
@@ -50,6 +59,7 @@ pub fn ioctl_tiocgwinsz<Fd: AsFd>(fd: &Fd) -> io::Result<Winsize> {
/// `ioctl(fd, FIONBIO, &value)`—Enables or disables non-blocking mode.
#[inline]
#[doc(alias = "FIONBIO")]
pub fn ioctl_fionbio<Fd: AsFd>(fd: &Fd, value: bool) -> io::Result<()> {
let fd = fd.as_fd();
imp::syscalls::ioctl_fionbio(fd, value)
@@ -66,6 +76,7 @@ pub fn ioctl_fionbio<Fd: AsFd>(fd: &Fd, value: bool) -> io::Result<()> {
all(libc, not(any(windows, target_os = "redox", target_os = "wasi")))
))]
#[inline]
#[doc(alias = "TIOCEXCL")]
pub fn ioctl_tiocexcl<Fd: AsFd>(fd: &Fd) -> io::Result<()> {
let fd = fd.as_fd();
imp::syscalls::ioctl_tiocexcl(fd)
@@ -82,6 +93,7 @@ pub fn ioctl_tiocexcl<Fd: AsFd>(fd: &Fd) -> io::Result<()> {
all(libc, not(any(windows, target_os = "redox", target_os = "wasi")))
))]
#[inline]
#[doc(alias = "TIOCNXCL")]
pub fn ioctl_tiocnxcl<Fd: AsFd>(fd: &Fd) -> io::Result<()> {
let fd = fd.as_fd();
imp::syscalls::ioctl_tiocnxcl(fd)
@@ -98,14 +110,16 @@ pub fn ioctl_tiocnxcl<Fd: AsFd>(fd: &Fd) -> io::Result<()> {
/// [Linux]: https://man7.org/linux/man-pages/man2/ioctl_tty.2.html
#[cfg(not(any(windows, target_os = "redox")))]
#[inline]
#[doc(alias = "FIONREAD")]
pub fn ioctl_fionread<Fd: AsFd>(fd: &Fd) -> io::Result<u64> {
let fd = fd.as_fd();
imp::syscalls::ioctl_fionread(fd)
}
/// `ioctl(fd, BLKPBSZGET)`—Returns the logical block size of a block device.
/// `ioctl(fd, BLKSSZGET)`—Returns the logical block size of a block device.
#[cfg(target_os = "linux")]
#[inline]
#[doc(alias = "BLKSSZGET")]
pub fn ioctl_blksszget<Fd: AsFd>(fd: &Fd) -> io::Result<u32> {
let fd = fd.as_fd();
imp::syscalls::ioctl_blksszget(fd)
@@ -114,6 +128,7 @@ pub fn ioctl_blksszget<Fd: AsFd>(fd: &Fd) -> io::Result<u32> {
/// `ioctl(fd, BLKPBSZGET)`—Returns the physical block size of a block device.
#[cfg(target_os = "linux")]
#[inline]
#[doc(alias = "BLKPBSZGET")]
pub fn ioctl_blkpbszget<Fd: AsFd>(fd: &Fd) -> io::Result<u32> {
let fd = fd.as_fd();
imp::syscalls::ioctl_blkpbszget(fd)
+1 -1
View File
@@ -1,4 +1,4 @@
//! Functions which operate on file descriptors.
//! The [`is_read_write`] function.
use crate::{imp, io};
use imp::fd::AsFd;
+2 -2
View File
@@ -2,8 +2,8 @@
//!
//! # Safety
//!
//! `mmap` manipulates raw pointers and has special semantics and is
//! wildly unsafe.
//! `mmap` and related functions manipulate raw pointers and have special
//! semantics and are wildly unsafe.
#![allow(unsafe_code)]
use crate::{imp, io};
+5
View File
@@ -1,5 +1,10 @@
//! A wrapper around `io_lifetimes::OwnedFd`.
//!
//! rustix needs to wrap `OwnedFd` 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
+1 -1
View File
@@ -1,4 +1,4 @@
//! Functions which operate on file descriptors.
//! Functions which operate on file descriptors which might be terminals.
use crate::imp;
#[cfg(any(
+2
View File
@@ -20,8 +20,10 @@ pub use imp::io::UserfaultfdFlags;
///
/// # References
/// - [Linux]
/// - [Linux userfaultfd]
///
/// [Linux]: https://man7.org/linux/man-pages/man2/userfaultfd.2.html
/// [Linux userfaultfd]: https://www.kernel.org/doc/Documentation/vm/userfaultfd.txt
#[inline]
pub unsafe fn userfaultfd(flags: UserfaultfdFlags) -> io::Result<OwnedFd> {
imp::syscalls::userfaultfd(flags)
+7
View File
@@ -1,4 +1,11 @@
//! Network-related operations.
//!
//! On Windows, one must call [`wsa_startup`] in the process before calling any
//! of these APIs. [`wsa_cleanup`] may be used in the process if these APIs are
//! no longer needed.
//!
//! [`wsa_startup`]: https://docs.rs/rustix/latest/x86_64-pc-windows-msvc/rustix/net/fn.wsa_startup.html
//! [`wsa_cleanup`]: https://docs.rs/rustix/latest/x86_64-pc-windows-msvc/rustix/net/fn.wsa_cleanup.html
use crate::imp;
+3
View File
@@ -1,4 +1,7 @@
//! `getsockopt` and `setsockopt` functions.
//!
//! In the rustix API, there is a separate function for each option, so that
//! it can be given an option-specific type signature.
#![doc(alias = "getsockopt")]
#![doc(alias = "setsockopt")]
+8 -5
View File
@@ -1,3 +1,6 @@
//! This module defines the `Arg` trait and implements it for several common
//! string types.
use crate::ffi::{ZStr, ZString};
use crate::io;
#[cfg(feature = "itoa")]
@@ -953,11 +956,11 @@ fn with_z_str<T, F>(bytes: &[u8], f: F) -> io::Result<T>
where
F: FnOnce(&ZStr) -> io::Result<T>,
{
// Most paths are less than `SMALL_PATH_BUFFER_SIZE` long. The rest can go through
// the dynamic allocation path. If you're opening many files in a directory
// with a long path, consider opening the directory and using `openat` to open
// the files under it, which will avoid this, and is often faster in the OS
// as well.
// Most paths are less than `SMALL_PATH_BUFFER_SIZE` long. The rest can go
// through the dynamic allocation path. If you're opening many files in a
// directory with a long path, consider opening the directory and using
// `openat` to open the files under it, which will avoid this, and is often
// faster in the OS as well.
// Test with >= so that we have room for the trailing NUL.
if bytes.len() >= SMALL_PATH_BUFFER_SIZE {
+3 -4
View File
@@ -2,10 +2,9 @@
//!
//! # Safety
//!
//! The `Uid`, `Gid`, and `Uid` types can be constructed from raw integers,
//! which is marked safe for similar reasons as [`FromRawFd::from_raw_fd`].
//!
//! [`FromRawFd::from_raw_fd`]: https://doc.rust-lang.org/std/os/unix/io/trait.FromRawFd.html#tymethod.from_raw_fd
//! The `Uid`, `Gid`, and `Pid` types can be constructed from raw integers,
//! which is marked unsafe because actual OS's assign special meaning to some
//! integer values.
#![allow(unsafe_code)]
use crate::imp;
+2
View File
@@ -114,6 +114,8 @@ pub const EXIT_SIGNALED_SIGABRT: i32 = imp::process::EXIT_SIGNALED_SIGABRT;
/// `sched_yield()`—Hints to the OS that other processes should run.
///
/// This function always succeeds.
///
/// # References
/// - [POSIX]
/// - [Linux]
+18 -12
View File
@@ -1,14 +1,17 @@
use crate::process::Pid;
use crate::{imp, io};
/// CpuSet represent a bit-mask of CPUs.
/// CpuSets are used by `sched_setaffinity` and
/// `sched_getaffinity` for example.
/// `CpuSet` represents a bit-mask of CPUs.
///
/// `CpuSet`s are used by [`sched_setaffinity`] and [`sched_getaffinity`], for
/// example.
///
/// # References
/// - [Linux]
///
/// [Linux]: https://man7.org/linux/man-pages/man3/CPU_SET.3.html
/// [`sched_setaffinity`]: crate::process::sched_setaffinity
/// [`sched_getaffinity`]: crate::process::sched_getaffinity
#[repr(C)]
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub struct CpuSet {
@@ -16,7 +19,7 @@ pub struct CpuSet {
}
impl CpuSet {
/// The maximum number of CPU in CpuSet
/// The maximum number of CPU in `CpuSet`.
pub const MAX_CPU: usize = imp::process::CPU_SETSIZE;
/// Create a new and empty CpuSet.
@@ -27,35 +30,38 @@ impl CpuSet {
}
}
/// Test to see if a CPU is in the CpuSet.
/// `field` is the CPU id to test
/// Test to see if a CPU is in the `CpuSet`.
///
/// `field` is the CPU id to test.
#[inline]
pub fn is_set(&self, field: usize) -> bool {
imp::process::cpu_set::CPU_ISSET(field, &self.cpu_set)
}
/// Add a CPU to CpuSet.
/// `field` is the CPU id to add
/// Add a CPU to `CpuSet`.
///
/// `field` is the CPU id to add.
#[inline]
pub fn set(&mut self, field: usize) {
imp::process::cpu_set::CPU_SET(field, &mut self.cpu_set)
}
/// Remove a CPU from CpuSet.
/// `field` is the CPU id to remove
/// Remove a CPU from `CpuSet`.
///
/// `field` is the CPU id to remove.
#[inline]
pub fn unset(&mut self, field: usize) {
imp::process::cpu_set::CPU_CLR(field, &mut self.cpu_set)
}
/// Count the number of CPUs set in the CpuSet
/// Count the number of CPUs set in the `CpuSet`.
#[cfg(target_os = "linux")]
#[inline]
pub fn count(&self) -> u32 {
imp::process::cpu_set::CPU_COUNT(&self.cpu_set)
}
/// Zeroes the CpuSet.
/// Zeroes the `CpuSet`.
#[inline]
pub fn clear(&mut self) {
imp::process::cpu_set::CPU_ZERO(&mut self.cpu_set)
+4 -1
View File
@@ -1,4 +1,5 @@
//! Low-level implementation details for libc-like runtime libraries.
//! Low-level implementation details for libc-like runtime libraries such as
//! [origin].
//!
//! These functions are for implementing thread-local storage (TLS),
//! managing threads, loaded libraries, and other process-wide resources.
@@ -9,6 +10,8 @@
//! The API for these functions is not stable, and this module is
//! `doc(hidden)`.
//!
//! [origin]: https://github.com/sunfishcode/mustang/tree/main/origin
//!
//! # Safety
//!
//! This module is intended to be used for implementing a runtime library
+2
View File
@@ -1,3 +1,5 @@
//! Tests for [`rustix::fs`].
#![cfg(not(windows))]
#![cfg_attr(target_os = "wasi", feature(wasi_ext))]
#![cfg_attr(io_lifetimes_use_std, feature(io_safety))]
+1 -1
View File
@@ -27,7 +27,7 @@ fn dup2_to_replace_stdio() {
drop(reader);
drop(writer);
// Don't use std::io::stdout() because in tests it's captured.
// Don't use `std::io::stdout()` because in tests it's captured.
unsafe {
writeln!(
rustix::io::stdout().as_filelike_view::<std::fs::File>(),
+3 -1
View File
@@ -1,3 +1,5 @@
//! Tests for [`rustix::io`].
#![cfg_attr(target_os = "wasi", feature(wasi_ext))]
#![cfg_attr(io_lifetimes_use_std, feature(io_safety))]
@@ -21,4 +23,4 @@ mod prot;
#[cfg(not(windows))]
#[cfg(not(target_os = "redox"))] // redox doesn't have cwd/openat
#[cfg(not(target_os = "wasi"))] // wasi support for S_IRUSR etc. submitted to libc in #2264
mod readwrite;
mod read_write;
+2
View File
@@ -1,3 +1,5 @@
//! Tests for [`rustix::net`].
#![cfg_attr(target_os = "wasi", feature(wasi_ext))]
#![cfg(not(any(target_os = "redox", target_os = "wasi")))] // WASI doesn't support `net` yet.
#![cfg_attr(io_lifetimes_use_std, feature(io_safety))]
+2
View File
@@ -1,3 +1,5 @@
//! Tests for [`rustix::path`].
#![cfg(not(windows))]
#![cfg_attr(target_os = "wasi", feature(wasi_ext))]
#![cfg_attr(io_lifetimes_use_std, feature(io_safety))]
+2
View File
@@ -1,3 +1,5 @@
//! Tests for [`rustix::process`].
#![cfg(not(windows))]
#![cfg_attr(target_os = "wasi", feature(wasi_ext))]
#![cfg_attr(io_lifetimes_use_std, feature(io_safety))]
+2
View File
@@ -1,3 +1,5 @@
//! Tests for [`rustix::rand`].
#![cfg(not(windows))]
#![cfg_attr(target_os = "wasi", feature(wasi_ext))]
#![cfg_attr(io_lifetimes_use_std, feature(io_safety))]
+2
View File
@@ -1,3 +1,5 @@
//! Tests for [`rustix::thread`].
#![cfg(not(windows))]
#[cfg(not(any(target_os = "redox")))]
+2
View File
@@ -1,3 +1,5 @@
//! Tests for [`rustix::time`].
#![cfg(not(windows))]
#![cfg_attr(target_os = "wasi", feature(wasi_ext))]
#![cfg_attr(io_lifetimes_use_std, feature(io_safety))]