diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:57:31 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:57:31 +0000 |
commit | dc0db358abe19481e475e10c32149b53370f1a1c (patch) | |
tree | ab8ce99c4b255ce46f99ef402c27916055b899ee /vendor/rustix/src/process | |
parent | Releasing progress-linux version 1.71.1+dfsg1-2~progress7.99u1. (diff) | |
download | rustc-dc0db358abe19481e475e10c32149b53370f1a1c.tar.xz rustc-dc0db358abe19481e475e10c32149b53370f1a1c.zip |
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/rustix/src/process')
-rw-r--r-- | vendor/rustix/src/process/chdir.rs | 52 | ||||
-rw-r--r-- | vendor/rustix/src/process/chroot.rs | 4 | ||||
-rw-r--r-- | vendor/rustix/src/process/id.rs | 178 | ||||
-rw-r--r-- | vendor/rustix/src/process/ioctl.rs | 21 | ||||
-rw-r--r-- | vendor/rustix/src/process/kill.rs | 2 | ||||
-rw-r--r-- | vendor/rustix/src/process/membarrier.rs | 20 | ||||
-rw-r--r-- | vendor/rustix/src/process/mod.rs | 40 | ||||
-rw-r--r-- | vendor/rustix/src/process/pidfd.rs | 2 | ||||
-rw-r--r-- | vendor/rustix/src/process/pidfd_getfd.rs | 51 | ||||
-rw-r--r-- | vendor/rustix/src/process/prctl.rs | 185 | ||||
-rw-r--r-- | vendor/rustix/src/process/priority.rs | 6 | ||||
-rw-r--r-- | vendor/rustix/src/process/procctl.rs | 59 | ||||
-rw-r--r-- | vendor/rustix/src/process/rlimit.rs | 4 | ||||
-rw-r--r-- | vendor/rustix/src/process/sched.rs | 2 | ||||
-rw-r--r-- | vendor/rustix/src/process/system.rs | 137 | ||||
-rw-r--r-- | vendor/rustix/src/process/umask.rs | 4 | ||||
-rw-r--r-- | vendor/rustix/src/process/wait.rs | 26 |
17 files changed, 298 insertions, 495 deletions
diff --git a/vendor/rustix/src/process/chdir.rs b/vendor/rustix/src/process/chdir.rs index 4951e5670..0da0b5c2e 100644 --- a/vendor/rustix/src/process/chdir.rs +++ b/vendor/rustix/src/process/chdir.rs @@ -1,9 +1,13 @@ -use crate::ffi::CString; -use crate::path::SMALL_PATH_BUFFER_SIZE; -use crate::{backend, io, path}; -use alloc::vec::Vec; #[cfg(not(target_os = "fuchsia"))] -use backend::fd::AsFd; +use crate::backend::fd::AsFd; +#[cfg(any(feature = "fs", not(target_os = "fuchsia")))] +use crate::{backend, io}; +#[cfg(feature = "fs")] +use { + crate::ffi::{CStr, CString}, + crate::path::{self, SMALL_PATH_BUFFER_SIZE}, + alloc::vec::Vec, +}; /// `chdir(path)`—Change the current working directory. /// @@ -14,6 +18,8 @@ use backend::fd::AsFd; /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/chdir.html /// [Linux]: https://man7.org/linux/man-pages/man2/chdir.2.html #[inline] +#[cfg(feature = "fs")] +#[cfg_attr(doc_cfg, doc(cfg(feature = "fs")))] pub fn chdir<P: path::Arg>(path: P) -> io::Result<()> { path.into_with_c_str(backend::process::syscalls::chdir) } @@ -32,9 +38,9 @@ pub fn fchdir<Fd: AsFd>(fd: Fd) -> io::Result<()> { backend::process::syscalls::fchdir(fd.as_fd()) } -/// `getcwd()`—Return the current working directory. +/// `getCWD`—Return the current working directory. /// -/// If `reuse` is non-empty, reuse its buffer to store the result if possible. +/// If `reuse` already has available capacity, reuse it if possible. /// /// # References /// - [POSIX] @@ -42,29 +48,43 @@ pub fn fchdir<Fd: AsFd>(fd: Fd) -> io::Result<()> { /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getcwd.html /// [Linux]: https://man7.org/linux/man-pages/man3/getcwd.3.html +#[cfg(feature = "fs")] #[cfg(not(target_os = "wasi"))] +#[cfg_attr(doc_cfg, doc(cfg(feature = "fs")))] #[inline] pub fn getcwd<B: Into<Vec<u8>>>(reuse: B) -> io::Result<CString> { _getcwd(reuse.into()) } +#[cfg(feature = "fs")] +#[allow(unsafe_code)] fn _getcwd(mut buffer: Vec<u8>) -> io::Result<CString> { - // This code would benefit from having a better way to read into - // uninitialized memory, but that requires `unsafe`. buffer.clear(); buffer.reserve(SMALL_PATH_BUFFER_SIZE); - buffer.resize(buffer.capacity(), 0_u8); loop { - match backend::process::syscalls::getcwd(&mut buffer) { + match backend::process::syscalls::getcwd(buffer.spare_capacity_mut()) { Err(io::Errno::RANGE) => { - buffer.reserve(1); // use `Vec` reallocation strategy to grow capacity exponentially - buffer.resize(buffer.capacity(), 0_u8); + buffer.reserve(buffer.capacity() + 1); // use `Vec` reallocation strategy to grow capacity exponentially } Ok(_) => { - let len = buffer.iter().position(|x| *x == b'\0').unwrap(); - buffer.resize(len, 0_u8); - return Ok(CString::new(buffer).unwrap()); + // SAFETY: + // - "These functions return a null-terminated string" + // - [POSIX definition 3.375: String]: "A contiguous sequence of bytes + // terminated by and including the first null byte." + // + // Thus, there will be a single NUL byte at the end of the string. + // + // [POSIX definition 3.375: String]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_375 + unsafe { + buffer.set_len( + CStr::from_ptr(buffer.as_ptr().cast()) + .to_bytes_with_nul() + .len(), + ); + + return Ok(CString::from_vec_with_nul_unchecked(buffer)); + } } Err(errno) => return Err(errno), } diff --git a/vendor/rustix/src/process/chroot.rs b/vendor/rustix/src/process/chroot.rs index d68a8b081..a4fd8d852 100644 --- a/vendor/rustix/src/process/chroot.rs +++ b/vendor/rustix/src/process/chroot.rs @@ -1,3 +1,5 @@ +#[cfg(feature = "fs")] +#[cfg_attr(doc_cfg, doc(cfg(feature = "fs")))] use crate::{backend, io, path}; /// `chroot(path)`—Change the process root directory. @@ -6,6 +8,8 @@ use crate::{backend, io, path}; /// - [Linux] /// /// [Linux]: https://man7.org/linux/man-pages/man2/chroot.2.html +#[cfg(feature = "fs")] +#[cfg_attr(doc_cfg, doc(cfg(feature = "fs")))] #[inline] pub fn chroot<P: path::Arg>(path: P) -> io::Result<()> { path.into_with_c_str(backend::process::syscalls::chroot) diff --git a/vendor/rustix/src/process/id.rs b/vendor/rustix/src/process/id.rs index 687596a31..4cacf1ab0 100644 --- a/vendor/rustix/src/process/id.rs +++ b/vendor/rustix/src/process/id.rs @@ -9,163 +9,28 @@ use crate::{backend, io}; use alloc::vec::Vec; -#[cfg(any(target_os = "android", target_os = "linux"))] +#[cfg(linux_kernel)] use backend::process::types::RawCpuid; /// The raw integer value of a Unix user ID. -pub use backend::process::types::RawUid; +pub use crate::ugid::RawUid; /// The raw integer value of a Unix group ID. -pub use backend::process::types::RawGid; +pub use crate::ugid::RawGid; /// The raw integer value of a Unix process ID. -pub use backend::process::types::RawPid; +pub use crate::pid::RawPid; -/// The raw integer value of a Unix process ID. -pub use backend::process::types::RawNonZeroPid; - -/// `uid_t`—A Unix user ID. -#[repr(transparent)] -#[derive(Copy, Clone, Eq, PartialEq, Debug, Hash)] -pub struct Uid(RawUid); - -/// `gid_t`—A Unix group ID. -#[repr(transparent)] -#[derive(Copy, Clone, Eq, PartialEq, Debug, Hash)] -pub struct Gid(RawGid); - -/// `pid_t`—A non-zero Unix process ID. -/// -/// This is a pid, and not a pidfd. It is not a file descriptor, and the -/// process it refers to could disappear at any time and be replaced by -/// another, unrelated, process. -#[repr(transparent)] -#[derive(Copy, Clone, Eq, PartialEq, Debug, Hash)] -pub struct Pid(RawNonZeroPid); +pub use crate::pid::Pid; +pub use crate::ugid::{Gid, Uid}; /// A Linux CPU ID. -#[cfg(any(target_os = "android", target_os = "linux"))] +#[cfg(linux_kernel)] #[repr(transparent)] #[derive(Copy, Clone, Eq, PartialEq, Debug, Hash)] pub struct Cpuid(RawCpuid); -impl Uid { - /// A `Uid` corresponding to the root user (uid 0). - pub const ROOT: Self = Self(0); - - /// Converts a `RawUid` into a `Uid`. - /// - /// # Safety - /// - /// `raw` must be the value of a valid Unix user ID. - #[inline] - pub const unsafe fn from_raw(raw: RawUid) -> Self { - Self(raw) - } - - /// Converts a `Uid` into a `RawUid`. - #[inline] - pub const fn as_raw(self) -> RawUid { - self.0 - } - - /// Test whether this uid represents the root user (uid 0). - #[inline] - pub const fn is_root(self) -> bool { - self.0 == Self::ROOT.0 - } -} - -impl Gid { - /// A `Gid` corresponding to the root group (gid 0). - pub const ROOT: Self = Self(0); - - /// Converts a `RawGid` into a `Gid`. - /// - /// # Safety - /// - /// `raw` must be the value of a valid Unix group ID. - #[inline] - pub const unsafe fn from_raw(raw: RawGid) -> Self { - Self(raw) - } - - /// Converts a `Gid` into a `RawGid`. - #[inline] - pub const fn as_raw(self) -> RawGid { - self.0 - } - - /// Test whether this gid represents the root group (gid 0). - #[inline] - pub const fn is_root(self) -> bool { - self.0 == Self::ROOT.0 - } -} - -impl Pid { - /// A `Pid` corresponding to the init process (pid 1). - pub const INIT: Self = Self( - // SAFETY: The init process' pid is always valid. - unsafe { RawNonZeroPid::new_unchecked(1) }, - ); - - /// Converts a `RawPid` into a `Pid`. - /// - /// # Safety - /// - /// `raw` must be the value of a valid Unix process ID, or zero. - #[inline] - pub const unsafe fn from_raw(raw: RawPid) -> Option<Self> { - match RawNonZeroPid::new(raw) { - Some(pid) => Some(Self(pid)), - None => None, - } - } - - /// Converts a known non-zero `RawPid` into a `Pid`. - /// - /// # Safety - /// - /// `raw` must be the value of a valid Unix process ID. It must not be - /// zero. - #[inline] - pub const unsafe fn from_raw_nonzero(raw: RawNonZeroPid) -> Self { - Self(raw) - } - - /// Creates a `Pid` holding the ID of the given child process. - #[cfg(feature = "std")] - #[inline] - pub fn from_child(child: &std::process::Child) -> Self { - let id = child.id(); - debug_assert_ne!(id, 0); - - // SAFETY: We know the returned ID is valid because it came directly - // from an OS API. - unsafe { Self::from_raw_nonzero(RawNonZeroPid::new_unchecked(id as _)) } - } - - /// Converts a `Pid` into a `RawNonZeroPid`. - #[inline] - pub const fn as_raw_nonzero(self) -> RawNonZeroPid { - self.0 - } - - /// Converts an `Option<Pid>` into a `RawPid`. - #[inline] - pub fn as_raw(pid: Option<Self>) -> RawPid { - pid.map_or(0, |pid| pid.0.get()) - } - - /// Test whether this pid represents the init process (pid 0). - #[inline] - pub const fn is_init(self) -> bool { - self.0.get() == Self::INIT.0.get() - } -} - -#[cfg(any(target_os = "android", target_os = "linux"))] +#[cfg(linux_kernel)] impl Cpuid { /// Converts a `RawCpuid` into a `Cpuid`. /// @@ -195,7 +60,7 @@ impl Cpuid { #[inline] #[must_use] pub fn getuid() -> Uid { - backend::process::syscalls::getuid() + backend::ugid::syscalls::getuid() } /// `geteuid()`—Returns the process' effective user ID. @@ -209,7 +74,7 @@ pub fn getuid() -> Uid { #[inline] #[must_use] pub fn geteuid() -> Uid { - backend::process::syscalls::geteuid() + backend::ugid::syscalls::geteuid() } /// `getgid()`—Returns the process' real group ID. @@ -223,7 +88,7 @@ pub fn geteuid() -> Uid { #[inline] #[must_use] pub fn getgid() -> Gid { - backend::process::syscalls::getgid() + backend::ugid::syscalls::getgid() } /// `getegid()`—Returns the process' effective group ID. @@ -237,7 +102,7 @@ pub fn getgid() -> Gid { #[inline] #[must_use] pub fn getegid() -> Gid { - backend::process::syscalls::getegid() + backend::ugid::syscalls::getegid() } /// `getpid()`—Returns the process' ID. @@ -251,7 +116,7 @@ pub fn getegid() -> Gid { #[inline] #[must_use] pub fn getpid() -> Pid { - backend::process::syscalls::getpid() + backend::pid::syscalls::getpid() } /// `getppid()`—Returns the parent process' ID. @@ -364,20 +229,3 @@ pub fn getgroups() -> io::Result<Vec<Gid>> { buffer.resize(buffer.capacity(), Gid::ROOT); } } - -// Return the raw value of the IDs. In case of `None` it returns `u32::MAX` -// since it has the same bit pattern as `-1` indicating no change to the -// owner/group ID. -pub(crate) fn translate_fchown_args(owner: Option<Uid>, group: Option<Gid>) -> (u32, u32) { - let ow = match owner { - Some(o) => o.as_raw(), - None => u32::MAX, - }; - - let gr = match group { - Some(g) => g.as_raw(), - None => u32::MAX, - }; - - (ow, gr) -} diff --git a/vendor/rustix/src/process/ioctl.rs b/vendor/rustix/src/process/ioctl.rs new file mode 100644 index 000000000..46dbbc59b --- /dev/null +++ b/vendor/rustix/src/process/ioctl.rs @@ -0,0 +1,21 @@ +use crate::{backend, io}; +use backend::fd::AsFd; + +/// `ioctl(fd, TIOCSCTTY, 0)`—Sets the controlling terminal for the processs. +/// +/// # References +/// - [Linux] +/// - [FreeBSD] +/// - [NetBSD] +/// - [OpenBSD] +/// +/// [Linux]: https://man7.org/linux/man-pages/man4/tty_ioctl.4.html +/// [FreeBSD]: https://man.freebsd.org/cgi/man.cgi?query=tty&sektion=4 +/// [NetBSD]: https://man.netbsd.org/tty.4 +/// [OpenBSD]: https://man.openbsd.org/tty.4 +#[cfg(not(any(windows, target_os = "haiku", target_os = "redox", target_os = "wasi")))] +#[inline] +#[doc(alias = "TIOCSCTTY")] +pub fn ioctl_tiocsctty<Fd: AsFd>(fd: Fd) -> io::Result<()> { + backend::process::syscalls::ioctl_tiocsctty(fd.as_fd()) +} diff --git a/vendor/rustix/src/process/kill.rs b/vendor/rustix/src/process/kill.rs index 807cc1028..5f6f06c48 100644 --- a/vendor/rustix/src/process/kill.rs +++ b/vendor/rustix/src/process/kill.rs @@ -1,7 +1,7 @@ use crate::process::Pid; use crate::{backend, io}; -pub use backend::process::types::Signal; +pub use crate::signal::Signal; /// `kill(pid, sig)`—Sends a signal to a process. /// diff --git a/vendor/rustix/src/process/membarrier.rs b/vendor/rustix/src/process/membarrier.rs index 8709337bc..df9f1a44c 100644 --- a/vendor/rustix/src/process/membarrier.rs +++ b/vendor/rustix/src/process/membarrier.rs @@ -1,24 +1,20 @@ //! The Linux `membarrier` syscall. -//! -//! # Safety -//! -//! This file defines an enum and a bitflags type that represent the same -//! set of values and are kept in sync. -#![allow(unsafe_code)] use crate::process::Cpuid; use crate::{backend, io}; pub use backend::process::types::MembarrierCommand; -#[cfg(any(target_os = "android", target_os = "linux"))] +#[cfg(linux_kernel)] bitflags::bitflags! { /// A result from [`membarrier_query`]. /// /// These flags correspond to values of [`MembarrierCommand`] which are /// supported in the OS. + #[repr(transparent)] + #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct MembarrierQuery: u32 { - /// `MEMBARRIER_CMD_GLOBAL` + /// `MEMBARRIER_CMD_GLOBAL` (also known as `MEMBARRIER_CMD_SHARED`) #[doc(alias = "SHARED")] #[doc(alias = "MEMBARRIER_CMD_SHARED")] const GLOBAL = MembarrierCommand::Global as _; @@ -41,14 +37,14 @@ bitflags::bitflags! { } } -#[cfg(any(target_os = "android", target_os = "linux"))] +#[cfg(linux_kernel)] impl MembarrierQuery { /// Test whether this query result contains the given command. #[inline] pub fn contains_command(self, cmd: MembarrierCommand) -> bool { - // SAFETY: `MembarrierCommand` is an enum that only contains values - // also valid in `MembarrierQuery`. - self.contains(unsafe { Self::from_bits_unchecked(cmd as _) }) + // `MembarrierCommand` is an enum that only contains values also valid + // in `MembarrierQuery`. + self.contains(Self::from_bits_retain(cmd as _)) } } diff --git a/vendor/rustix/src/process/mod.rs b/vendor/rustix/src/process/mod.rs index 0002c0f46..7a189b013 100644 --- a/vendor/rustix/src/process/mod.rs +++ b/vendor/rustix/src/process/mod.rs @@ -7,30 +7,26 @@ mod chroot; mod exit; #[cfg(not(target_os = "wasi"))] // WASI doesn't have get[gpu]id. mod id; +mod ioctl; #[cfg(not(target_os = "wasi"))] mod kill; -#[cfg(any(target_os = "android", target_os = "linux"))] +#[cfg(linux_kernel)] mod membarrier; #[cfg(target_os = "linux")] mod pidfd; -#[cfg(any(target_os = "android", target_os = "linux"))] +#[cfg(target_os = "linux")] +mod pidfd_getfd; +#[cfg(linux_kernel)] mod prctl; #[cfg(not(any(target_os = "fuchsia", target_os = "wasi")))] // WASI doesn't have [gs]etpriority. mod priority; -#[cfg(target_os = "freebsd")] +#[cfg(freebsdlike)] mod procctl; #[cfg(not(any(target_os = "fuchsia", target_os = "redox", target_os = "wasi")))] mod rlimit; -#[cfg(any( - target_os = "android", - target_os = "dragonfly", - target_os = "fuchsia", - target_os = "linux", -))] +#[cfg(any(linux_kernel, target_os = "dragonfly", target_os = "fuchsia"))] mod sched; mod sched_yield; -#[cfg(not(target_os = "wasi"))] // WASI doesn't have uname. -mod system; #[cfg(not(target_os = "wasi"))] // WASI doesn't have umask. mod umask; #[cfg(not(target_os = "wasi"))] @@ -43,35 +39,27 @@ pub use chroot::*; pub use exit::*; #[cfg(not(target_os = "wasi"))] pub use id::*; +pub use ioctl::*; #[cfg(not(target_os = "wasi"))] pub use kill::*; -#[cfg(any(target_os = "android", target_os = "linux"))] +#[cfg(linux_kernel)] pub use membarrier::*; #[cfg(target_os = "linux")] pub use pidfd::*; -#[cfg(any(target_os = "android", target_os = "linux"))] +#[cfg(target_os = "linux")] +pub use pidfd_getfd::*; +#[cfg(linux_kernel)] pub use prctl::*; #[cfg(not(any(target_os = "fuchsia", target_os = "wasi")))] pub use priority::*; -#[cfg(target_os = "freebsd")] +#[cfg(freebsdlike)] pub use procctl::*; #[cfg(not(any(target_os = "fuchsia", target_os = "redox", target_os = "wasi")))] pub use rlimit::*; -#[cfg(any( - target_os = "android", - target_os = "dragonfly", - target_os = "fuchsia", - target_os = "linux", -))] +#[cfg(any(linux_kernel, target_os = "dragonfly", target_os = "fuchsia"))] pub use sched::*; pub use sched_yield::sched_yield; #[cfg(not(target_os = "wasi"))] -pub use system::*; -#[cfg(not(target_os = "wasi"))] pub use umask::*; #[cfg(not(target_os = "wasi"))] pub use wait::*; - -#[cfg(not(target_os = "wasi"))] -#[cfg(feature = "fs")] -pub(crate) use id::translate_fchown_args; diff --git a/vendor/rustix/src/process/pidfd.rs b/vendor/rustix/src/process/pidfd.rs index c9ddb591f..fb8298117 100644 --- a/vendor/rustix/src/process/pidfd.rs +++ b/vendor/rustix/src/process/pidfd.rs @@ -6,6 +6,8 @@ bitflags::bitflags! { /// `PIDFD_*` flags for use with [`pidfd_open`]. /// /// [`pidfd_open`]: crate::process::pidfd_open + #[repr(transparent)] + #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct PidfdFlags: backend::c::c_uint { /// `PIDFD_NONBLOCK`. const NONBLOCK = backend::c::PIDFD_NONBLOCK; diff --git a/vendor/rustix/src/process/pidfd_getfd.rs b/vendor/rustix/src/process/pidfd_getfd.rs new file mode 100644 index 000000000..7234810c2 --- /dev/null +++ b/vendor/rustix/src/process/pidfd_getfd.rs @@ -0,0 +1,51 @@ +#![allow(unsafe_code)] +use crate::fd::OwnedFd; +use crate::{backend, io}; +use backend::fd::{AsFd, RawFd}; + +/// Raw file descriptor in another process. +/// +/// A distinct type alias is used here to inform the user that normal file +/// descriptors from the calling process should not be used. The provided file +/// descriptor is used by the kernel as the index into the file descriptor +/// table of an entirely different process. +pub type ForeignRawFd = RawFd; + +bitflags::bitflags! { + /// All flags are reserved for future use. + #[repr(transparent)] + #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] + pub struct PidfdGetfdFlags: backend::c::c_uint {} +} + +/// `syscall(SYS_pidfd_getfd, pidfd, flags)`—Obtain a duplicate of another +/// process's file descriptor. +/// +/// # References +/// - [Linux] +/// +/// # Warning +/// +/// This function is generally safe for the calling process, but it can impact +/// the target process in unexpected ways. If you want to ensure that Rust I/O +/// safety assumptions continue to hold in the target process, then the target +/// process must have communicated the file description number to the calling +/// process from a value of a type that implements `AsRawFd`, and the target +/// process must not drop that value until after the calling process has +/// returned from `pidfd_getfd`. +/// +/// When `pidfd_getfd` is used to debug the target, or the target is not a Rust +/// aplication, or `pidfd_getfd` is used in any other way, then extra care +/// should be taken to avoid unexpected behaviour or crashes. +/// +/// For further details, see the references above. +/// +/// [Linux]: https://man7.org/linux/man-pages/man2/pidfd_getfd.2.html +#[inline] +pub fn pidfd_getfd<Fd: AsFd>( + pidfd: Fd, + targetfd: ForeignRawFd, + flags: PidfdGetfdFlags, +) -> io::Result<OwnedFd> { + backend::process::syscalls::pidfd_getfd(pidfd.as_fd(), targetfd, flags) +} diff --git a/vendor/rustix/src/process/prctl.rs b/vendor/rustix/src/process/prctl.rs index a4e1e546c..d79657e98 100644 --- a/vendor/rustix/src/process/prctl.rs +++ b/vendor/rustix/src/process/prctl.rs @@ -5,63 +5,20 @@ #![allow(unsafe_code)] -use core::convert::{TryFrom, TryInto}; -use core::mem::MaybeUninit; -use core::ptr::NonNull; -use core::{mem, ptr}; +use core::mem::size_of; +use core::ptr::{null, null_mut, NonNull}; use bitflags::bitflags; use crate::backend::c::{c_int, c_uint, c_void}; -use crate::backend::process::syscalls; -use crate::backend::process::types::Signal; +use crate::backend::prctl::syscalls; use crate::fd::{AsRawFd, BorrowedFd}; use crate::ffi::CStr; use crate::io; +use crate::prctl::*; use crate::process::{Pid, RawPid}; - -// -// Helper functions. -// - -#[inline] -pub(crate) unsafe fn prctl_1arg(option: c_int) -> io::Result<c_int> { - const NULL: *mut c_void = ptr::null_mut(); - syscalls::prctl(option, NULL, NULL, NULL, NULL) -} - -#[inline] -pub(crate) unsafe fn prctl_2args(option: c_int, arg2: *mut c_void) -> io::Result<c_int> { - const NULL: *mut c_void = ptr::null_mut(); - syscalls::prctl(option, arg2, NULL, NULL, NULL) -} - -#[inline] -pub(crate) unsafe fn prctl_3args( - option: c_int, - arg2: *mut c_void, - arg3: *mut c_void, -) -> io::Result<c_int> { - syscalls::prctl(option, arg2, arg3, ptr::null_mut(), ptr::null_mut()) -} - -#[inline] -pub(crate) unsafe fn prctl_get_at_arg2_optional<P>(option: i32) -> io::Result<P> { - let mut value: MaybeUninit<P> = MaybeUninit::uninit(); - prctl_2args(option, value.as_mut_ptr().cast())?; - Ok(value.assume_init()) -} - -#[inline] -pub(crate) unsafe fn prctl_get_at_arg2<P, T>(option: i32) -> io::Result<T> -where - P: Default, - T: TryFrom<P, Error = io::Errno>, -{ - let mut value: P = Default::default(); - prctl_2args(option, ((&mut value) as *mut P).cast())?; - TryFrom::try_from(value) -} +use crate::signal::Signal; +use crate::utils::{as_mut_ptr, as_ptr}; // // PR_GET_PDEATHSIG/PR_SET_PDEATHSIG @@ -78,6 +35,7 @@ const PR_GET_PDEATHSIG: c_int = 2; /// [Linux: `prctl(PR_GET_PDEATHSIG,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html /// [FreeBSD: `procctl(PROC_PDEATHSIG_STATUS,...)`]: https://man.freebsd.org/cgi/man.cgi?query=procctl&sektion=2 #[inline] +#[doc(alias = "PR_GET_PDEATHSIG")] pub fn parent_process_death_signal() -> io::Result<Option<Signal>> { unsafe { prctl_get_at_arg2_optional::<c_int>(PR_GET_PDEATHSIG) }.map(Signal::from_raw) } @@ -93,6 +51,7 @@ const PR_SET_PDEATHSIG: c_int = 1; /// [Linux: `prctl(PR_SET_PDEATHSIG,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html /// [FreeBSD: `procctl(PROC_PDEATHSIG_CTL,...)`]: https://man.freebsd.org/cgi/man.cgi?query=procctl&sektion=2 #[inline] +#[doc(alias = "PR_SET_PDEATHSIG")] pub fn set_parent_process_death_signal(signal: Option<Signal>) -> io::Result<()> { let signal = signal.map_or(0_usize, |signal| signal as usize); unsafe { prctl_2args(PR_SET_PDEATHSIG, signal as *mut _) }.map(|_r| ()) @@ -108,15 +67,19 @@ const SUID_DUMP_DISABLE: i32 = 0; const SUID_DUMP_USER: i32 = 1; const SUID_DUMP_ROOT: i32 = 2; -/// `SUID_DUMP_*`. +/// `SUID_DUMP_*` values for use with [`dumpable_behavior`] and +/// [`set_dumpable_behavior`]. #[derive(Copy, Clone, Debug, Eq, PartialEq)] #[repr(i32)] pub enum DumpableBehavior { /// Not dumpable. + #[doc(alias = "SUID_DUMP_DISABLE")] NotDumpable = SUID_DUMP_DISABLE, /// Dumpable. + #[doc(alias = "SUID_DUMP_USER")] Dumpable = SUID_DUMP_USER, /// Dumpable but only readable by root. + #[doc(alias = "SUID_DUMP_ROOT")] DumpableReadableOnlyByRoot = SUID_DUMP_ROOT, } @@ -140,6 +103,7 @@ impl TryFrom<i32> for DumpableBehavior { /// /// [`prctl(PR_GET_DUMPABLE,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] +#[doc(alias = "PR_GET_DUMPABLE")] pub fn dumpable_behavior() -> io::Result<DumpableBehavior> { unsafe { prctl_1arg(PR_GET_DUMPABLE) }.and_then(TryInto::try_into) } @@ -160,6 +124,7 @@ const PR_SET_DUMPABLE: c_int = 4; /// /// [`prctl(PR_SET_DUMPABLE,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] +#[doc(alias = "PR_SET_DUMPABLE")] pub fn set_dumpable_behavior(config: DumpableBehavior) -> io::Result<()> { unsafe { prctl_2args(PR_SET_DUMPABLE, config as usize as *mut _) }.map(|_r| ()) } @@ -171,11 +136,17 @@ pub fn set_dumpable_behavior(config: DumpableBehavior) -> io::Result<()> { const PR_GET_UNALIGN: c_int = 5; bitflags! { - /// `PR_UNALIGN_*`. + /// `PR_UNALIGN_*` flags for use with [`unaligned_access_control`] and + /// [`set_unaligned_access_control`]. + #[repr(transparent)] + #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct UnalignedAccessControl: u32 { /// Silently fix up unaligned user accesses. + #[doc(alias = "NOPRINT")] + #[doc(alias = "PR_UNALIGN_NOPRINT")] const NO_PRINT = 1; /// Generate a [`Signal::Bus`] signal on unaligned user access. + #[doc(alias = "PR_UNALIGN_SIGBUS")] const SIGBUS = 2; } } @@ -187,6 +158,7 @@ bitflags! { /// /// [`prctl(PR_GET_UNALIGN,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] +#[doc(alias = "PR_GET_UNALIGN")] pub fn unaligned_access_control() -> io::Result<UnalignedAccessControl> { let r = unsafe { prctl_get_at_arg2_optional::<c_uint>(PR_GET_UNALIGN)? }; UnalignedAccessControl::from_bits(r).ok_or(io::Errno::RANGE) @@ -201,6 +173,7 @@ const PR_SET_UNALIGN: c_int = 6; /// /// [`prctl(PR_SET_UNALIGN,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] +#[doc(alias = "PR_SET_UNALIGN")] pub fn set_unaligned_access_control(config: UnalignedAccessControl) -> io::Result<()> { unsafe { prctl_2args(PR_SET_UNALIGN, config.bits() as usize as *mut _) }.map(|_r| ()) } @@ -212,12 +185,17 @@ pub fn set_unaligned_access_control(config: UnalignedAccessControl) -> io::Resul const PR_GET_FPEMU: c_int = 9; bitflags! { - /// `PR_FPEMU_*`. + /// `PR_FPEMU_*` flags for use with [`floating_point_emulation_control`] + /// and [`set_floating_point_emulation_control`]. + #[repr(transparent)] + #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct FloatingPointEmulationControl: u32 { /// Silently emulate floating point operations accesses. + #[doc(alias = "PR_UNALIGN_NOPRINT")] const NO_PRINT = 1; /// Don't emulate floating point operations, send a [`Signal::Fpe`] /// signal instead. + #[doc(alias = "PR_UNALIGN_SIGFPE")] const SIGFPE = 2; } } @@ -229,6 +207,7 @@ bitflags! { /// /// [`prctl(PR_GET_FPEMU,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] +#[doc(alias = "PR_GET_FPEMU")] pub fn floating_point_emulation_control() -> io::Result<FloatingPointEmulationControl> { let r = unsafe { prctl_get_at_arg2_optional::<c_uint>(PR_GET_FPEMU)? }; FloatingPointEmulationControl::from_bits(r).ok_or(io::Errno::RANGE) @@ -243,6 +222,7 @@ const PR_SET_FPEMU: c_int = 10; /// /// [`prctl(PR_SET_FPEMU,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] +#[doc(alias = "PR_SET_FPEMU")] pub fn set_floating_point_emulation_control( config: FloatingPointEmulationControl, ) -> io::Result<()> { @@ -257,6 +237,8 @@ const PR_GET_FPEXC: c_int = 11; bitflags! { /// Zero means floating point exceptions are disabled. + #[repr(transparent)] + #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct FloatingPointExceptionMode: u32 { /// Async non-recoverable exception mode. const NONRECOV = 1; @@ -287,6 +269,7 @@ bitflags! { /// /// [`prctl(PR_GET_FPEXC,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] +#[doc(alias = "PR_GET_FPEXEC")] pub fn floating_point_exception_mode() -> io::Result<Option<FloatingPointExceptionMode>> { unsafe { prctl_get_at_arg2_optional::<c_uint>(PR_GET_FPEXC) } .map(FloatingPointExceptionMode::from_bits) @@ -301,6 +284,7 @@ const PR_SET_FPEXC: c_int = 12; /// /// [`prctl(PR_SET_FPEXC,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] +#[doc(alias = "PR_SET_FPEXEC")] pub fn set_floating_point_exception_mode( config: Option<FloatingPointExceptionMode>, ) -> io::Result<()> { @@ -317,7 +301,8 @@ const PR_GET_TIMING: c_int = 13; const PR_TIMING_STATISTICAL: i32 = 0; const PR_TIMING_TIMESTAMP: i32 = 1; -/// `PR_TIMING_*`. +/// `PR_TIMING_*` values for use with [`timing_method`] and +/// [`set_timing_method`]. #[derive(Copy, Clone, Debug, Eq, PartialEq)] #[repr(i32)] pub enum TimingMethod { @@ -346,6 +331,7 @@ impl TryFrom<i32> for TimingMethod { /// /// [`prctl(PR_GET_TIMING,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] +#[doc(alias = "PR_GET_TIMING")] pub fn timing_method() -> io::Result<TimingMethod> { unsafe { prctl_1arg(PR_GET_TIMING) }.and_then(TryInto::try_into) } @@ -360,6 +346,7 @@ const PR_SET_TIMING: c_int = 14; /// /// [`prctl(PR_SET_TIMING,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] +#[doc(alias = "PR_SET_TIMING")] pub fn set_timing_method(method: TimingMethod) -> io::Result<()> { unsafe { prctl_2args(PR_SET_TIMING, method as usize as *mut _) }.map(|_r| ()) } @@ -374,7 +361,7 @@ const PR_ENDIAN_BIG: u32 = 0; const PR_ENDIAN_LITTLE: u32 = 1; const PR_ENDIAN_PPC_LITTLE: u32 = 2; -/// `PR_ENDIAN_*`. +/// `PR_ENDIAN_*` values for use with [`endian_mode`]. #[derive(Copy, Clone, Debug, Eq, PartialEq)] #[repr(u32)] pub enum EndianMode { @@ -406,6 +393,7 @@ impl TryFrom<u32> for EndianMode { /// /// [`prctl(PR_GET_ENDIAN,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] +#[doc(alias = "PR_GET_ENDIAN")] pub fn endian_mode() -> io::Result<EndianMode> { unsafe { prctl_get_at_arg2::<c_uint, _>(PR_GET_ENDIAN) } } @@ -424,6 +412,7 @@ const PR_SET_ENDIAN: c_int = 20; /// /// [`prctl(PR_SET_ENDIAN,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] +#[doc(alias = "PR_SET_ENDIAN")] pub unsafe fn set_endian_mode(mode: EndianMode) -> io::Result<()> { prctl_2args(PR_SET_ENDIAN, mode as usize as *mut _).map(|_r| ()) } @@ -437,7 +426,8 @@ const PR_GET_TSC: c_int = 25; const PR_TSC_ENABLE: u32 = 1; const PR_TSC_SIGSEGV: u32 = 2; -/// `PR_TSC_*`. +/// `PR_TSC_*` values for use with [`time_stamp_counter_readability`] and +/// [`set_time_stamp_counter_readability`]. #[derive(Copy, Clone, Debug, Eq, PartialEq)] #[repr(u32)] pub enum TimeStampCounterReadability { @@ -466,6 +456,7 @@ impl TryFrom<u32> for TimeStampCounterReadability { /// /// [`prctl(PR_GET_TSC,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] +#[doc(alias = "PR_GET_TSC")] pub fn time_stamp_counter_readability() -> io::Result<TimeStampCounterReadability> { unsafe { prctl_get_at_arg2::<c_uint, _>(PR_GET_TSC) } } @@ -480,6 +471,7 @@ const PR_SET_TSC: c_int = 26; /// /// [`prctl(PR_SET_TSC,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] +#[doc(alias = "PR_SET_TSC")] pub fn set_time_stamp_counter_readability( readability: TimeStampCounterReadability, ) -> io::Result<()> { @@ -502,6 +494,8 @@ const PR_TASK_PERF_EVENTS_ENABLE: c_int = 32; /// [`prctl(PR_TASK_PERF_EVENTS_ENABLE,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html /// [`prctl(PR_TASK_PERF_EVENTS_DISABLE,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] +#[doc(alias = "PR_TASK_PERF_EVENTS_ENABLE")] +#[doc(alias = "PR_TASK_PERF_EVENTS_DISABLE")] pub fn configure_performance_counters(enable: bool) -> io::Result<()> { let option = if enable { PR_TASK_PERF_EVENTS_ENABLE @@ -522,15 +516,20 @@ const PR_MCE_KILL_LATE: u32 = 0; const PR_MCE_KILL_EARLY: u32 = 1; const PR_MCE_KILL_DEFAULT: u32 = 2; -/// `PR_MCE_KILL_*`. +/// `PR_MCE_KILL_*` values for use with +/// [`machine_check_memory_corruption_kill_policy`] and +/// [`set_machine_check_memory_corruption_kill_policy`]. #[derive(Copy, Clone, Debug, Eq, PartialEq)] #[repr(u32)] pub enum MachineCheckMemoryCorruptionKillPolicy { /// Late kill policy. + #[doc(alias = "PR_MCE_KILL_LATE")] Late = PR_MCE_KILL_LATE, /// Early kill policy. + #[doc(alias = "PR_MCE_KILL_EARLY")] Early = PR_MCE_KILL_EARLY, /// System-wide default policy. + #[doc(alias = "PR_MCE_KILL_DEFAULT")] Default = PR_MCE_KILL_DEFAULT, } @@ -554,6 +553,7 @@ impl TryFrom<u32> for MachineCheckMemoryCorruptionKillPolicy { /// /// [`prctl(PR_MCE_KILL_GET,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] +#[doc(alias = "PR_MCE_KILL_GET")] pub fn machine_check_memory_corruption_kill_policy( ) -> io::Result<MachineCheckMemoryCorruptionKillPolicy> { let r = unsafe { prctl_1arg(PR_MCE_KILL_GET)? } as c_uint; @@ -572,13 +572,14 @@ const PR_MCE_KILL_SET: usize = 1; /// /// [`prctl(PR_MCE_KILL,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] +#[doc(alias = "PR_MCE_KILL")] pub fn set_machine_check_memory_corruption_kill_policy( policy: Option<MachineCheckMemoryCorruptionKillPolicy>, ) -> io::Result<()> { let (sub_operation, policy) = if let Some(policy) = policy { (PR_MCE_KILL_SET, policy as usize as *mut _) } else { - (PR_MCE_KILL_CLEAR, ptr::null_mut()) + (PR_MCE_KILL_CLEAR, null_mut()) }; unsafe { prctl_3args(PR_MCE_KILL, sub_operation as *mut _, policy) }.map(|_r| ()) @@ -606,7 +607,7 @@ const PR_SET_MM_EXE_FILE: usize = 13; const PR_SET_MM_MAP: usize = 14; const PR_SET_MM_MAP_SIZE: usize = 15; -/// `PR_SET_MM_*`. +/// `PR_SET_MM_*` values for use with [`set_virtual_memory_map_address`]. #[derive(Copy, Clone, Debug, Eq, PartialEq)] #[repr(u32)] pub enum VirtualMemoryMapAddress { @@ -650,11 +651,12 @@ pub enum VirtualMemoryMapAddress { /// /// [`prctl(PR_SET_MM,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] +#[doc(alias = "PR_SET_MM")] pub unsafe fn set_virtual_memory_map_address( option: VirtualMemoryMapAddress, address: Option<NonNull<c_void>>, ) -> io::Result<()> { - let address = address.map_or_else(ptr::null_mut, NonNull::as_ptr); + let address = address.map_or_else(null_mut, NonNull::as_ptr); prctl_3args(PR_SET_MM, option as usize as *mut _, address).map(|_r| ()) } @@ -666,6 +668,8 @@ pub unsafe fn set_virtual_memory_map_address( /// /// [`prctl(PR_SET_MM,PR_SET_MM_EXE_FILE,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] +#[doc(alias = "PR_SET_MM")] +#[doc(alias = "PR_SET_MM_EXE_FILE")] pub fn set_executable_file(fd: BorrowedFd) -> io::Result<()> { let fd = usize::try_from(fd.as_raw_fd()).map_err(|_r| io::Errno::RANGE)?; unsafe { prctl_3args(PR_SET_MM, PR_SET_MM_EXE_FILE as *mut _, fd as *mut _) }.map(|_r| ()) @@ -683,13 +687,15 @@ pub fn set_executable_file(fd: BorrowedFd) -> io::Result<()> { /// /// [`prctl(PR_SET_MM,PR_SET_MM_AUXV,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] +#[doc(alias = "PR_SET_MM")] +#[doc(alias = "PR_SET_MM_AUXV")] pub unsafe fn set_auxiliary_vector(auxv: &[*const c_void]) -> io::Result<()> { syscalls::prctl( PR_SET_MM, PR_SET_MM_AUXV as *mut _, auxv.as_ptr() as *mut _, auxv.len() as *mut _, - ptr::null_mut(), + null_mut(), ) .map(|_r| ()) } @@ -701,9 +707,11 @@ pub unsafe fn set_auxiliary_vector(auxv: &[*const c_void]) -> io::Result<()> { /// /// [`prctl(PR_SET_MM,PR_SET_MM_MAP_SIZE,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] +#[doc(alias = "PR_SET_MM")] +#[doc(alias = "PR_SET_MM_MAP_SIZE")] pub fn virtual_memory_map_config_struct_size() -> io::Result<usize> { let mut value: c_uint = 0; - let value_ptr = (&mut value) as *mut c_uint; + let value_ptr = as_mut_ptr(&mut value); unsafe { prctl_3args(PR_SET_MM, PR_SET_MM_MAP_SIZE as *mut _, value_ptr.cast())? }; Ok(value as usize) } @@ -758,13 +766,15 @@ pub struct PrctlMmMap { /// /// [`prctl(PR_SET_MM,PR_SET_MM_MAP,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] +#[doc(alias = "PR_SET_MM")] +#[doc(alias = "PR_SET_MM_MAP")] pub unsafe fn configure_virtual_memory_map(config: &PrctlMmMap) -> io::Result<()> { syscalls::prctl( PR_SET_MM, PR_SET_MM_MAP as *mut _, - config as *const PrctlMmMap as *mut _, - mem::size_of::<PrctlMmMap>() as *mut _, - ptr::null_mut(), + as_ptr(config) as *mut _, + size_of::<PrctlMmMap>() as *mut _, + null_mut(), ) .map(|_r| ()) } @@ -796,9 +806,10 @@ pub enum PTracer { /// /// [`prctl(PR_SET_PTRACER,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] +#[doc(alias = "PR_SET_PTRACER")] pub fn set_ptracer(tracer: PTracer) -> io::Result<()> { let pid = match tracer { - PTracer::None => ptr::null_mut(), + PTracer::None => null_mut(), PTracer::Any => PR_SET_PTRACER_ANY as *mut _, PTracer::ProcessID(pid) => pid.as_raw_nonzero().get() as usize as *mut _, }; @@ -819,6 +830,7 @@ const PR_GET_CHILD_SUBREAPER: c_int = 37; /// /// [`prctl(PR_GET_CHILD_SUBREAPER,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] +#[doc(alias = "PR_GET_CHILD_SUBREAPER")] pub fn child_subreaper() -> io::Result<Option<Pid>> { unsafe { let r = prctl_get_at_arg2_optional::<c_uint>(PR_GET_CHILD_SUBREAPER)?; @@ -835,6 +847,7 @@ const PR_SET_CHILD_SUBREAPER: c_int = 36; /// /// [`prctl(PR_SET_CHILD_SUBREAPER,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] +#[doc(alias = "PR_SET_CHILD_SUBREAPER")] pub fn set_child_subreaper(pid: Option<Pid>) -> io::Result<()> { let pid = pid.map_or(0_usize, |pid| pid.as_raw_nonzero().get() as usize); unsafe { prctl_2args(PR_SET_CHILD_SUBREAPER, pid as *mut _) }.map(|_r| ()) @@ -849,7 +862,8 @@ const PR_GET_FP_MODE: c_int = 46; const PR_FP_MODE_FR: u32 = 1_u32 << 0; const PR_FP_MODE_FRE: u32 = 1_u32 << 1; -/// `PR_FP_MODE_*`. +/// `PR_FP_MODE_*` values for use with [`floating_point_mode`] and +/// [`set_floating_point_mode`]. #[derive(Copy, Clone, Debug, Eq, PartialEq)] #[repr(u32)] pub enum FloatingPointMode { @@ -878,6 +892,7 @@ impl TryFrom<u32> for FloatingPointMode { /// /// [`prctl(PR_GET_FP_MODE,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] +#[doc(alias = "PR_GET_FP_MODE")] pub fn floating_point_mode() -> io::Result<FloatingPointMode> { let r = unsafe { prctl_1arg(PR_GET_FP_MODE)? } as c_uint; FloatingPointMode::try_from(r) @@ -892,6 +907,7 @@ const PR_SET_FP_MODE: c_int = 45; /// /// [`prctl(PR_SET_FP_MODE,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] +#[doc(alias = "PR_SET_FP_MODE")] pub fn set_floating_point_mode(mode: FloatingPointMode) -> io::Result<()> { unsafe { prctl_2args(PR_SET_FP_MODE, mode as usize as *mut _) }.map(|_r| ()) } @@ -906,7 +922,8 @@ const PR_SPEC_STORE_BYPASS: u32 = 0; const PR_SPEC_INDIRECT_BRANCH: u32 = 1; const PR_SPEC_L1D_FLUSH: u32 = 2; -/// `PR_SPEC_*`. +/// `PR_SPEC_*` values for use with [`speculative_feature_state`] and +/// [`control_speculative_feature`]. #[derive(Copy, Clone, Debug, Eq, PartialEq)] #[repr(u32)] pub enum SpeculationFeature { @@ -932,7 +949,9 @@ impl TryFrom<u32> for SpeculationFeature { } bitflags! { - /// `PR_SPEC_*`. + /// `PR_SPEC_*` flags for use with [`control_speculative_feature`]. + #[repr(transparent)] + #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct SpeculationFeatureControl: u32 { /// The speculation feature is enabled, mitigation is disabled. const ENABLE = 1_u32 << 1; @@ -947,6 +966,8 @@ bitflags! { bitflags! { /// Zero means the processors are not vulnerable. + #[repr(transparent)] + #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct SpeculationFeatureState: u32 { /// Mitigation can be controlled per thread by `PR_SET_SPECULATION_CTRL`. const PRCTL = 1_u32 << 0; @@ -968,6 +989,7 @@ bitflags! { /// /// [`prctl(PR_GET_SPECULATION_CTRL,...)`]: https://www.kernel.org/doc/html/v5.18/userspace-api/spec_ctrl.html #[inline] +#[doc(alias = "PR_GET_SPECULATION_CTRL")] pub fn speculative_feature_state( feature: SpeculationFeature, ) -> io::Result<Option<SpeculationFeatureState>> { @@ -984,6 +1006,7 @@ const PR_SET_SPECULATION_CTRL: c_int = 53; /// /// [`prctl(PR_SET_SPECULATION_CTRL,...)`]: https://www.kernel.org/doc/html/v5.18/userspace-api/spec_ctrl.html #[inline] +#[doc(alias = "PR_SET_SPECULATION_CTRL")] pub fn control_speculative_feature( feature: SpeculationFeature, config: SpeculationFeatureControl, @@ -1006,6 +1029,7 @@ const PR_GET_IO_FLUSHER: c_int = 58; /// /// [`prctl(PR_GET_IO_FLUSHER,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] +#[doc(alias = "PR_GET_IO_FLUSHER")] pub fn is_io_flusher() -> io::Result<bool> { unsafe { prctl_1arg(PR_GET_IO_FLUSHER) }.map(|r| r != 0) } @@ -1020,8 +1044,9 @@ const PR_SET_IO_FLUSHER: c_int = 57; /// /// [`prctl(PR_SET_IO_FLUSHER,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] +#[doc(alias = "PR_SET_IO_FLUSHER")] pub fn configure_io_flusher_behavior(enable: bool) -> io::Result<()> { - unsafe { prctl_2args(PR_SET_IO_FLUSHER, enable as usize as *mut _) }.map(|_r| ()) + unsafe { prctl_2args(PR_SET_IO_FLUSHER, usize::from(enable) as *mut _) }.map(|_r| ()) } // @@ -1030,22 +1055,6 @@ pub fn configure_io_flusher_behavior(enable: bool) -> io::Result<()> { const PR_PAC_GET_ENABLED_KEYS: c_int = 61; -bitflags! { - /// `PR_PAC_AP*`. - pub struct PointerAuthenticationKeys: u32 { - /// Instruction authentication key `A`. - const INSTRUCTION_AUTHENTICATION_KEY_A = 1_u32 << 0; - /// Instruction authentication key `B`. - const INSTRUCTION_AUTHENTICATION_KEY_B = 1_u32 << 1; - /// Data authentication key `A`. - const DATA_AUTHENTICATION_KEY_A = 1_u32 << 2; - /// Data authentication key `B`. - const DATA_AUTHENTICATION_KEY_B = 1_u32 << 3; - /// Generic authentication `A` key. - const GENERIC_AUTHENTICATION_KEY_A = 1_u32 << 4; - } -} - /// Get enabled pointer authentication keys. /// /// # References @@ -1053,6 +1062,7 @@ bitflags! { /// /// [`prctl(PR_PAC_GET_ENABLED_KEYS,...)`]: https://www.kernel.org/doc/html/v5.18/arm64/pointer-authentication.html #[inline] +#[doc(alias = "PR_PAC_GET_ENABLED_KEYS")] pub fn enabled_pointer_authentication_keys() -> io::Result<PointerAuthenticationKeys> { let r = unsafe { prctl_1arg(PR_PAC_GET_ENABLED_KEYS)? } as c_uint; PointerAuthenticationKeys::from_bits(r).ok_or(io::Errno::RANGE) @@ -1072,6 +1082,7 @@ const PR_PAC_SET_ENABLED_KEYS: c_int = 60; /// /// [`prctl(PR_PAC_SET_ENABLED_KEYS,...)`]: https://www.kernel.org/doc/html/v5.18/arm64/pointer-authentication.html #[inline] +#[doc(alias = "PR_PAC_SET_ENABLED_KEYS")] pub unsafe fn configure_pointer_authentication_keys( config: impl Iterator<Item = (PointerAuthenticationKeys, bool)>, ) -> io::Result<()> { @@ -1116,6 +1127,8 @@ const PR_SET_VMA_ANON_NAME: usize = 0; /// /// [`prctl(PR_SET_VMA,PR_SET_VMA_ANON_NAME,...)`]: https://lwn.net/Articles/867818/ #[inline] +#[doc(alias = "PR_SET_VMA")] +#[doc(alias = "PR_SET_VMA_ANON_NAME")] pub fn set_virtual_memory_region_name(region: &[u8], name: Option<&CStr>) -> io::Result<()> { unsafe { syscalls::prctl( @@ -1123,7 +1136,7 @@ pub fn set_virtual_memory_region_name(region: &[u8], name: Option<&CStr>) -> io: PR_SET_VMA_ANON_NAME as *mut _, region.as_ptr() as *mut _, region.len() as *mut _, - name.map_or_else(ptr::null, CStr::as_ptr) as *mut _, + name.map_or_else(null, CStr::as_ptr) as *mut _, ) .map(|_r| ()) } diff --git a/vendor/rustix/src/process/priority.rs b/vendor/rustix/src/process/priority.rs index f8d061c6b..604614ef0 100644 --- a/vendor/rustix/src/process/priority.rs +++ b/vendor/rustix/src/process/priority.rs @@ -25,7 +25,6 @@ pub fn nice(inc: i32) -> io::Result<i32> { /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getpriority.html /// [Linux]: https://man7.org/linux/man-pages/man2/getpriority.2.html /// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/setpriority.2.html -#[cfg(not(target_os = "redox"))] #[inline] #[doc(alias = "getpriority")] pub fn getpriority_user(uid: Uid) -> io::Result<i32> { @@ -45,7 +44,6 @@ pub fn getpriority_user(uid: Uid) -> io::Result<i32> { /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getpriority.html /// [Linux]: https://man7.org/linux/man-pages/man2/getpriority.2.html /// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/setpriority.2.html -#[cfg(not(target_os = "redox"))] #[inline] #[doc(alias = "getpriority")] pub fn getpriority_pgrp(pgid: Option<Pid>) -> io::Result<i32> { @@ -65,7 +63,6 @@ pub fn getpriority_pgrp(pgid: Option<Pid>) -> io::Result<i32> { /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getpriority.html /// [Linux]: https://man7.org/linux/man-pages/man2/getpriority.2.html /// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/setpriority.2.html -#[cfg(not(target_os = "redox"))] #[inline] #[doc(alias = "getpriority")] pub fn getpriority_process(pid: Option<Pid>) -> io::Result<i32> { @@ -83,7 +80,6 @@ pub fn getpriority_process(pid: Option<Pid>) -> io::Result<i32> { /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/setpriority.html /// [Linux]: https://man7.org/linux/man-pages/man2/setpriority.2.html /// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/setpriority.2.html -#[cfg(not(target_os = "redox"))] #[inline] #[doc(alias = "setpriority")] pub fn setpriority_user(uid: Uid, priority: i32) -> io::Result<()> { @@ -103,7 +99,6 @@ pub fn setpriority_user(uid: Uid, priority: i32) -> io::Result<()> { /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/setpriority.html /// [Linux]: https://man7.org/linux/man-pages/man2/setpriority.2.html /// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/setpriority.2.html -#[cfg(not(target_os = "redox"))] #[inline] #[doc(alias = "setpriority")] pub fn setpriority_pgrp(pgid: Option<Pid>, priority: i32) -> io::Result<()> { @@ -123,7 +118,6 @@ pub fn setpriority_pgrp(pgid: Option<Pid>, priority: i32) -> io::Result<()> { /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/setpriority.html /// [Linux]: https://man7.org/linux/man-pages/man2/setpriority.2.html /// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/setpriority.2.html -#[cfg(not(target_os = "redox"))] #[inline] #[doc(alias = "setpriority")] pub fn setpriority_process(pid: Option<Pid>, priority: i32) -> io::Result<()> { diff --git a/vendor/rustix/src/process/procctl.rs b/vendor/rustix/src/process/procctl.rs index 443aa90a4..8da53d383 100644 --- a/vendor/rustix/src/process/procctl.rs +++ b/vendor/rustix/src/process/procctl.rs @@ -5,6 +5,8 @@ #![allow(unsafe_code)] +use alloc::vec; +use alloc::vec::Vec; use core::mem::MaybeUninit; use core::ptr; @@ -12,9 +14,11 @@ use bitflags::bitflags; use crate::backend::c::{c_int, c_uint, c_void}; use crate::backend::process::syscalls; -use crate::backend::process::types::{RawId, Signal}; +use crate::backend::process::types::RawId; use crate::io; use crate::process::{Pid, RawPid}; +use crate::signal::Signal; +use crate::utils::{as_mut_ptr, as_ptr}; // // Helper functions. @@ -59,7 +63,7 @@ pub(crate) unsafe fn procctl_set<P>( process: ProcSelector, data: &P, ) -> io::Result<()> { - procctl(option, process, (data as *const P as *mut P).cast()) + procctl(option, process, (as_ptr(data) as *mut P).cast()) } #[inline] @@ -180,7 +184,7 @@ pub fn trace_status(process: ProcSelector) -> io::Result<TracingStatus> { -1 => Ok(TracingStatus::NotTraceble), 0 => Ok(TracingStatus::Tracable), pid => { - let pid = unsafe { Pid::from_raw(pid as RawPid) }.ok_or(io::Errno::RANGE)?; + let pid = Pid::from_raw(pid as RawPid).ok_or(io::Errno::RANGE)?; Ok(TracingStatus::BeingTraced(pid)) } } @@ -218,6 +222,8 @@ const PROC_REAP_STATUS: c_int = 4; bitflags! { /// `REAPER_STATUS_*`. + #[repr(transparent)] + #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct ReaperStatusFlags: c_uint { /// The process has acquired reaper status. const OWNED = 1; @@ -249,7 +255,7 @@ pub struct ReaperStatus { /// The pid of the reaper for the specified process id. pub reaper: Pid, /// The pid of one reaper child if there are any descendants. - pub pid: Pid, + pub pid: Option<Pid>, } /// Get information about the reaper of the specified process (or the process @@ -263,11 +269,15 @@ pub struct ReaperStatus { pub fn get_reaper_status(process: ProcSelector) -> io::Result<ReaperStatus> { let raw = unsafe { procctl_get_optional::<procctl_reaper_status>(PROC_REAP_STATUS, process) }?; Ok(ReaperStatus { - flags: ReaperStatusFlags::from_bits_truncate(raw.rs_flags), + flags: ReaperStatusFlags::from_bits_retain(raw.rs_flags), children: raw.rs_children as _, descendants: raw.rs_descendants as _, - reaper: unsafe { Pid::from_raw(raw.rs_reaper) }.ok_or(io::Errno::RANGE)?, - pid: unsafe { Pid::from_raw(raw.rs_pid) }.ok_or(io::Errno::RANGE)?, + reaper: Pid::from_raw(raw.rs_reaper).ok_or(io::Errno::RANGE)?, + pid: if raw.rs_pid == -1 { + None + } else { + Some(Pid::from_raw(raw.rs_pid).ok_or(io::Errno::RANGE)?) + }, }) } @@ -275,12 +285,15 @@ const PROC_REAP_GETPIDS: c_int = 5; bitflags! { /// `REAPER_PIDINFO_*`. + #[repr(transparent)] + #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct PidInfoFlags: c_uint { /// This structure was filled by the kernel. const VALID = 1; /// The pid field identifies a direct child of the reaper. const CHILD = 2; - /// The reported process is itself a reaper. Descendants of a subordinate reaper are not reported. + /// The reported process is itself a reaper. Descendants of a + /// subordinate reaper are not reported. const REAPER = 4; /// The reported process is in the zombie state. const ZOMBIE = 8; @@ -335,23 +348,17 @@ pub fn get_reaper_pids(process: ProcSelector) -> io::Result<Vec<PidInfo>> { rp_pad0: [0; 15], rp_pids: pids.as_mut_slice().as_mut_ptr(), }; - unsafe { - procctl( - PROC_REAP_GETPIDS, - process, - (&mut pinfo as *mut procctl_reaper_pids).cast(), - )? - }; + unsafe { procctl(PROC_REAP_GETPIDS, process, as_mut_ptr(&mut pinfo).cast())? }; let mut result = Vec::new(); for raw in pids.into_iter() { - let flags = PidInfoFlags::from_bits_truncate(raw.pi_flags); + let flags = PidInfoFlags::from_bits_retain(raw.pi_flags); if !flags.contains(PidInfoFlags::VALID) { break; } result.push(PidInfo { flags, - subtree: unsafe { Pid::from_raw(raw.pi_subtree) }.ok_or(io::Errno::RANGE)?, - pid: unsafe { Pid::from_raw(raw.pi_pid) }.ok_or(io::Errno::RANGE)?, + subtree: Pid::from_raw(raw.pi_subtree).ok_or(io::Errno::RANGE)?, + pid: Pid::from_raw(raw.pi_pid).ok_or(io::Errno::RANGE)?, }); } Ok(result) @@ -361,6 +368,8 @@ const PROC_REAP_KILL: c_int = 6; bitflags! { /// `REAPER_KILL_*`. + #[repr(transparent)] + #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] struct KillFlags: c_uint { const CHILDREN = 1; const SUBTREE = 2; @@ -409,20 +418,10 @@ pub fn reaper_kill( rk_fpid: 0, rk_pad0: [0; 15], }; - unsafe { - procctl( - PROC_REAP_KILL, - process, - (&mut req as *mut procctl_reaper_kill).cast(), - )? - }; + unsafe { procctl(PROC_REAP_KILL, process, as_mut_ptr(&mut req).cast())? }; Ok(KillResult { killed: req.rk_killed as _, - first_failed: if req.rk_fpid == -1 { - None - } else { - unsafe { Pid::from_raw(req.rk_fpid) } - }, + first_failed: Pid::from_raw(req.rk_fpid), }) } diff --git a/vendor/rustix/src/process/rlimit.rs b/vendor/rustix/src/process/rlimit.rs index 089f6b4bb..ea760c22f 100644 --- a/vendor/rustix/src/process/rlimit.rs +++ b/vendor/rustix/src/process/rlimit.rs @@ -1,4 +1,4 @@ -#[cfg(any(target_os = "android", target_os = "linux"))] +#[cfg(linux_kernel)] use crate::process::Pid; use crate::{backend, io}; @@ -46,7 +46,7 @@ pub fn setrlimit(resource: Resource, new: Rlimit) -> io::Result<()> { /// - [Linux] /// /// [Linux]: https://man7.org/linux/man-pages/man2/prlimit.2.html -#[cfg(any(target_os = "android", target_os = "linux"))] +#[cfg(linux_kernel)] #[inline] pub fn prlimit(pid: Option<Pid>, resource: Resource, new: Rlimit) -> io::Result<Rlimit> { backend::process::syscalls::prlimit(pid, resource, new) diff --git a/vendor/rustix/src/process/sched.rs b/vendor/rustix/src/process/sched.rs index 88e661670..239b7df82 100644 --- a/vendor/rustix/src/process/sched.rs +++ b/vendor/rustix/src/process/sched.rs @@ -55,7 +55,7 @@ impl CpuSet { } /// Count the number of CPUs set in the `CpuSet`. - #[cfg(any(target_os = "android", target_os = "linux"))] + #[cfg(linux_kernel)] #[inline] pub fn count(&self) -> u32 { backend::process::cpu_set::CPU_COUNT(&self.cpu_set) diff --git a/vendor/rustix/src/process/system.rs b/vendor/rustix/src/process/system.rs deleted file mode 100644 index cf9a312fc..000000000 --- a/vendor/rustix/src/process/system.rs +++ /dev/null @@ -1,137 +0,0 @@ -//! Uname and other system-level functions. -//! -//! # Safety -//! -//! This function converts from `struct utsname` fields provided from the -//! kernel into `&str` references, which assumes that they're NUL-terminated. -#![allow(unsafe_code)] - -use crate::backend; -use crate::ffi::CStr; -#[cfg(not(target_os = "emscripten"))] -use crate::io; -use core::fmt; - -#[cfg(any(target_os = "android", target_os = "linux"))] -pub use backend::process::types::Sysinfo; - -/// `uname()`—Returns high-level information about the runtime OS and -/// hardware. -/// -/// # References -/// - [POSIX] -/// - [Linux] -/// -/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/uname.html -/// [Linux]: https://man7.org/linux/man-pages/man2/uname.2.html -#[inline] -pub fn uname() -> Uname { - Uname(backend::process::syscalls::uname()) -} - -/// `struct utsname`—Return type for [`uname`]. -#[doc(alias = "utsname")] -pub struct Uname(backend::process::types::RawUname); - -impl Uname { - /// `sysname`—Operating system release name - #[inline] - pub fn sysname(&self) -> &CStr { - Self::to_cstr(self.0.sysname.as_ptr().cast()) - } - - /// `nodename`—Name with vague meaning - /// - /// This is intended to be a network name, however it's unable to convey - /// information about hosts that have multiple names, or any information - /// about where the names are visible. - #[inline] - pub fn nodename(&self) -> &CStr { - Self::to_cstr(self.0.nodename.as_ptr().cast()) - } - - /// `release`—Operating system release version string - #[inline] - pub fn release(&self) -> &CStr { - Self::to_cstr(self.0.release.as_ptr().cast()) - } - - /// `version`—Operating system build identifiers - #[inline] - pub fn version(&self) -> &CStr { - Self::to_cstr(self.0.version.as_ptr().cast()) - } - - /// `machine`—Hardware architecture identifier - #[inline] - pub fn machine(&self) -> &CStr { - Self::to_cstr(self.0.machine.as_ptr().cast()) - } - - /// `domainname`—NIS or YP domain identifier - #[cfg(any(target_os = "android", target_os = "linux"))] - #[inline] - pub fn domainname(&self) -> &CStr { - Self::to_cstr(self.0.domainname.as_ptr().cast()) - } - - #[inline] - fn to_cstr<'a>(ptr: *const u8) -> &'a CStr { - // SAFETY: Strings returned from the kernel are always NUL-terminated. - unsafe { CStr::from_ptr(ptr.cast()) } - } -} - -impl fmt::Debug for Uname { - fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { - #[cfg(not(any(target_os = "android", target_os = "linux")))] - { - write!( - fmt, - "{} {} {} {} {}", - self.sysname().to_string_lossy(), - self.nodename().to_string_lossy(), - self.release().to_string_lossy(), - self.version().to_string_lossy(), - self.machine().to_string_lossy(), - ) - } - #[cfg(any(target_os = "android", target_os = "linux"))] - { - write!( - fmt, - "{} {} {} {} {} {}", - self.sysname().to_string_lossy(), - self.nodename().to_string_lossy(), - self.release().to_string_lossy(), - self.version().to_string_lossy(), - self.machine().to_string_lossy(), - self.domainname().to_string_lossy(), - ) - } - } -} - -/// `sysinfo()`—Returns status information about the runtime OS. -/// -/// # References -/// - [Linux] -/// -/// [Linux]: https://man7.org/linux/man-pages/man2/uname.2.html -#[cfg(any(target_os = "android", target_os = "linux"))] -#[inline] -pub fn sysinfo() -> Sysinfo { - backend::process::syscalls::sysinfo() -} - -/// `sethostname(name)—Sets the system host name. -/// -/// # References -/// - [Linux] -/// -/// [Linux]: https://man7.org/linux/man-pages/man2/sethostname.2.html -#[cfg(not(any(target_os = "emscripten", target_os = "redox", target_os = "wasi")))] -#[inline] -pub fn sethostname(name: &[u8]) -> io::Result<()> { - backend::process::syscalls::sethostname(name) -} diff --git a/vendor/rustix/src/process/umask.rs b/vendor/rustix/src/process/umask.rs index 7d83d6686..01779d7ed 100644 --- a/vendor/rustix/src/process/umask.rs +++ b/vendor/rustix/src/process/umask.rs @@ -13,9 +13,9 @@ use crate::fs::Mode; /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/umask.html /// [Linux]: https://man7.org/linux/man-pages/man2/umask.2.html -#[inline] -#[cfg_attr(doc_cfg, doc(cfg(feature = "fs")))] #[cfg(feature = "fs")] +#[cfg_attr(doc_cfg, doc(cfg(feature = "fs")))] +#[inline] pub fn umask(mask: Mode) -> Mode { backend::process::syscalls::umask(mask) } diff --git a/vendor/rustix/src/process/wait.rs b/vendor/rustix/src/process/wait.rs index ea2691ae1..d46c96005 100644 --- a/vendor/rustix/src/process/wait.rs +++ b/vendor/rustix/src/process/wait.rs @@ -10,34 +10,38 @@ use crate::backend::process::wait::SiginfoExt; bitflags! { /// Options for modifying the behavior of wait/waitpid + #[repr(transparent)] + #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct WaitOptions: u32 { /// Return immediately if no child has exited. - const NOHANG = backend::process::wait::WNOHANG as _; + const NOHANG = bitcast!(backend::process::wait::WNOHANG); /// Return if a child has stopped (but not traced via [`ptrace`]) /// /// [`ptrace`]: https://man7.org/linux/man-pages/man2/ptrace.2.html - const UNTRACED = backend::process::wait::WUNTRACED as _; + const UNTRACED = bitcast!(backend::process::wait::WUNTRACED); /// Return if a stopped child has been resumed by delivery of /// [`Signal::Cont`]. - const CONTINUED = backend::process::wait::WCONTINUED as _; + const CONTINUED = bitcast!(backend::process::wait::WCONTINUED); } } #[cfg(not(any(target_os = "wasi", target_os = "redox", target_os = "openbsd")))] bitflags! { /// Options for modifying the behavior of waitid + #[repr(transparent)] + #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct WaitidOptions: u32 { /// Return immediately if no child has exited. - const NOHANG = backend::process::wait::WNOHANG as _; + const NOHANG = bitcast!(backend::process::wait::WNOHANG); /// Return if a stopped child has been resumed by delivery of /// [`Signal::Cont`] - const CONTINUED = backend::process::wait::WCONTINUED as _; + const CONTINUED = bitcast!(backend::process::wait::WCONTINUED); /// Wait for processed that have exited. - const EXITED = backend::process::wait::WEXITED as _; + const EXITED = bitcast!(backend::process::wait::WEXITED); /// Keep processed in a waitable state. - const NOWAIT = backend::process::wait::WNOWAIT as _; + const NOWAIT = bitcast!(backend::process::wait::WNOWAIT); /// Wait for processes that have been stopped. - const STOPPED = backend::process::wait::WSTOPPED as _; + const STOPPED = bitcast!(backend::process::wait::WSTOPPED); } } @@ -230,8 +234,8 @@ impl WaitidStatus { #[cfg(not(any(target_os = "netbsd", target_os = "fuchsia", target_os = "emscripten")))] #[allow(unsafe_code)] fn si_status(&self) -> backend::c::c_int { - // SAFETY: POSIX [specifies] that the `siginfo_t` returned by a `waitid` - // call always has a valid `si_status` value. + // SAFETY: POSIX [specifies] that the `siginfo_t` returned by a + // `waitid` call always has a valid `si_status` value. // // [specifies]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html unsafe { self.0.si_status() } @@ -256,7 +260,7 @@ pub enum WaitId<'a> { /// Eat the lifetime for non-Linux platforms. #[doc(hidden)] #[cfg(not(target_os = "linux"))] - __EatLifetime(std::marker::PhantomData<&'a ()>), + __EatLifetime(core::marker::PhantomData<&'a ()>), // TODO(notgull): Once this crate has the concept of PGIDs, add a WaitId::Pgid } |