diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:20:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:20:29 +0000 |
commit | 631cd5845e8de329d0e227aaa707d7ea228b8f8f (patch) | |
tree | a1b87c8f8cad01cf18f7c5f57a08f102771ed303 /vendor/rustix/src/process | |
parent | Adding debian version 1.69.0+dfsg1-1. (diff) | |
download | rustc-631cd5845e8de329d0e227aaa707d7ea228b8f8f.tar.xz rustc-631cd5845e8de329d0e227aaa707d7ea228b8f8f.zip |
Merging upstream version 1.70.0+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/id.rs | 4 | ||||
-rw-r--r-- | vendor/rustix/src/process/membarrier.rs | 2 | ||||
-rw-r--r-- | vendor/rustix/src/process/mod.rs | 46 | ||||
-rw-r--r-- | vendor/rustix/src/process/pidfd.rs | 25 | ||||
-rw-r--r-- | vendor/rustix/src/process/prctl.rs | 135 | ||||
-rw-r--r-- | vendor/rustix/src/process/priority.rs | 2 | ||||
-rw-r--r-- | vendor/rustix/src/process/procctl.rs | 380 | ||||
-rw-r--r-- | vendor/rustix/src/process/rlimit.rs | 4 | ||||
-rw-r--r-- | vendor/rustix/src/process/umask.rs | 21 | ||||
-rw-r--r-- | vendor/rustix/src/process/uname.rs | 2 | ||||
-rw-r--r-- | vendor/rustix/src/process/wait.rs | 58 |
11 files changed, 560 insertions, 119 deletions
diff --git a/vendor/rustix/src/process/id.rs b/vendor/rustix/src/process/id.rs index e7fff7e53..04f1b879c 100644 --- a/vendor/rustix/src/process/id.rs +++ b/vendor/rustix/src/process/id.rs @@ -105,7 +105,7 @@ impl Gid { impl Pid { /// A `Pid` corresponding to the init process (pid 1). pub const INIT: Self = Self( - // Safety: The init process' pid is always valid. + // SAFETY: The init process' pid is always valid. unsafe { RawNonZeroPid::new_unchecked(1) }, ); @@ -140,7 +140,7 @@ impl Pid { let id = child.id(); debug_assert_ne!(id, 0); - // Safety: We know the returned ID is valid because it came directly + // 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 _)) } } diff --git a/vendor/rustix/src/process/membarrier.rs b/vendor/rustix/src/process/membarrier.rs index b64deb82e..8709337bc 100644 --- a/vendor/rustix/src/process/membarrier.rs +++ b/vendor/rustix/src/process/membarrier.rs @@ -46,7 +46,7 @@ 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 + // SAFETY: `MembarrierCommand` is an enum that only contains values // also valid in `MembarrierQuery`. self.contains(unsafe { Self::from_bits_unchecked(cmd as _) }) } diff --git a/vendor/rustix/src/process/mod.rs b/vendor/rustix/src/process/mod.rs index e6baa1935..3ae976439 100644 --- a/vendor/rustix/src/process/mod.rs +++ b/vendor/rustix/src/process/mod.rs @@ -9,6 +9,8 @@ mod id; mod kill; #[cfg(any(target_os = "android", target_os = "linux"))] mod membarrier; +#[cfg(target_os = "linux")] +mod pidfd; #[cfg(any(target_os = "android", target_os = "linux"))] mod prctl; #[cfg(not(any(target_os = "fuchsia", target_os = "wasi")))] // WASI doesn't have [gs]etpriority. @@ -25,60 +27,46 @@ mod rlimit; ))] mod sched; mod sched_yield; +#[cfg(not(target_os = "wasi"))] // WASI doesn't have umask. +mod umask; #[cfg(not(target_os = "wasi"))] // WASI doesn't have uname. mod uname; #[cfg(not(target_os = "wasi"))] mod wait; #[cfg(not(target_os = "wasi"))] -pub use chdir::chdir; -#[cfg(not(any(target_os = "wasi", target_os = "fuchsia")))] -pub use chdir::fchdir; +pub use chdir::*; +pub use exit::*; #[cfg(not(target_os = "wasi"))] -pub use chdir::getcwd; +pub use id::*; #[cfg(not(target_os = "wasi"))] -pub use exit::EXIT_SIGNALED_SIGABRT; -pub use exit::{EXIT_FAILURE, EXIT_SUCCESS}; +pub use kill::*; #[cfg(any(target_os = "android", target_os = "linux"))] -pub use id::Cpuid; -#[cfg(not(target_os = "wasi"))] -pub use id::{ - getegid, geteuid, getgid, getpgid, getpgrp, getpid, getppid, getuid, setsid, Gid, Pid, RawGid, - RawNonZeroPid, RawPid, RawUid, Uid, -}; -#[cfg(not(target_os = "wasi"))] -pub use kill::{kill_current_process_group, kill_process, kill_process_group, Signal}; -#[cfg(any(target_os = "android", target_os = "linux"))] -pub use membarrier::{ - membarrier, membarrier_cpu, membarrier_query, MembarrierCommand, MembarrierQuery, -}; +pub use membarrier::*; +#[cfg(target_os = "linux")] +pub use pidfd::*; #[cfg(any(target_os = "android", target_os = "linux"))] pub use prctl::*; #[cfg(not(any(target_os = "fuchsia", target_os = "wasi")))] -pub use priority::nice; -#[cfg(not(any(target_os = "fuchsia", target_os = "redox", target_os = "wasi")))] -pub use priority::{ - getpriority_pgrp, getpriority_process, getpriority_user, setpriority_pgrp, setpriority_process, - setpriority_user, -}; +pub use priority::*; #[cfg(target_os = "freebsd")] pub use procctl::*; -#[cfg(any(target_os = "android", target_os = "linux"))] -pub use rlimit::prlimit; #[cfg(not(any(target_os = "fuchsia", target_os = "redox", target_os = "wasi")))] -pub use rlimit::{getrlimit, setrlimit, Resource, Rlimit}; +pub use rlimit::*; #[cfg(any( target_os = "android", target_os = "dragonfly", target_os = "fuchsia", target_os = "linux", ))] -pub use sched::{sched_getaffinity, sched_setaffinity, CpuSet}; +pub use sched::*; pub use sched_yield::sched_yield; #[cfg(not(target_os = "wasi"))] +pub use umask::*; +#[cfg(not(target_os = "wasi"))] pub use uname::{uname, Uname}; #[cfg(not(target_os = "wasi"))] -pub use wait::{wait, waitpid, WaitOptions, WaitStatus}; +pub use wait::*; #[cfg(not(target_os = "wasi"))] #[cfg(feature = "fs")] diff --git a/vendor/rustix/src/process/pidfd.rs b/vendor/rustix/src/process/pidfd.rs new file mode 100644 index 000000000..c9ddb591f --- /dev/null +++ b/vendor/rustix/src/process/pidfd.rs @@ -0,0 +1,25 @@ +use crate::fd::OwnedFd; +use crate::process::Pid; +use crate::{backend, io}; + +bitflags::bitflags! { + /// `PIDFD_*` flags for use with [`pidfd_open`]. + /// + /// [`pidfd_open`]: crate::process::pidfd_open + pub struct PidfdFlags: backend::c::c_uint { + /// `PIDFD_NONBLOCK`. + const NONBLOCK = backend::c::PIDFD_NONBLOCK; + } +} + +/// `syscall(SYS_pidfd_open, pid, flags)`—Creates a file descriptor for +/// a process. +/// +/// # References +/// - [Linux] +/// +/// [Linux]: https://man7.org/linux/man-pages/man2/pidfd_open.2.html +#[inline] +pub fn pidfd_open(pid: Pid, flags: PidfdFlags) -> io::Result<OwnedFd> { + backend::process::syscalls::pidfd_open(pid, flags) +} diff --git a/vendor/rustix/src/process/prctl.rs b/vendor/rustix/src/process/prctl.rs index 49927be25..34eef7aa4 100644 --- a/vendor/rustix/src/process/prctl.rs +++ b/vendor/rustix/src/process/prctl.rs @@ -1,7 +1,7 @@ //! Bindings for the Linux `prctl` system call. //! -//! There are similarities (but also differences) with FreeBSD's `procctl` system call, whose -//! interface is located in the `procctl.rs` file. +//! There are similarities (but also differences) with FreeBSD's `procctl` +//! system call, whose interface is located in the `procctl.rs` file. #![allow(unsafe_code)] @@ -72,8 +72,8 @@ const PR_GET_PDEATHSIG: c_int = 2; /// Get the current value of the parent process death signal. /// /// # References -/// - [Linux: `prctl(PR_GET_PDEATHSIG,...)`] -/// - [FreeBSD: `procctl(PROC_PDEATHSIG_STATUS,...)`] +/// - [Linux: `prctl(PR_GET_PDEATHSIG,...)`] +/// - [FreeBSD: `procctl(PROC_PDEATHSIG_STATUS,...)`] /// /// [Linux: `prctl(PR_GET_PDEATHSIG,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html /// [FreeBSD: `procctl(PROC_PDEATHSIG_STATUS,...)`]: https://www.freebsd.org/cgi/man.cgi?query=procctl&sektion=2 @@ -87,8 +87,8 @@ const PR_SET_PDEATHSIG: c_int = 1; /// Set the parent-death signal of the calling process. /// /// # References -/// - [Linux: `prctl(PR_SET_PDEATHSIG,...)`] -/// - [FreeBSD: `procctl(PROC_PDEATHSIG_CTL,...)`] +/// - [Linux: `prctl(PR_SET_PDEATHSIG,...)`] +/// - [FreeBSD: `procctl(PROC_PDEATHSIG_CTL,...)`] /// /// [Linux: `prctl(PR_SET_PDEATHSIG,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html /// [FreeBSD: `procctl(PROC_PDEATHSIG_CTL,...)`]: https://www.freebsd.org/cgi/man.cgi?query=procctl&sektion=2 @@ -136,7 +136,7 @@ impl TryFrom<i32> for DumpableBehavior { /// Get the current state of the calling process's `dumpable` attribute. /// /// # References -/// - [`prctl(PR_GET_DUMPABLE,...)`] +/// - [`prctl(PR_GET_DUMPABLE,...)`] /// /// [`prctl(PR_GET_DUMPABLE,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] @@ -146,16 +146,17 @@ pub fn dumpable_behavior() -> io::Result<DumpableBehavior> { const PR_SET_DUMPABLE: c_int = 4; -/// Set the state of the `dumpable` attribute, which determines whether the process can be traced -/// and whether core dumps are produced for the calling process upon delivery of a signal whose -/// default behavior is to produce a core dump. +/// Set the state of the `dumpable` attribute, which determines whether the +/// process can be traced and whether core dumps are produced for the calling +/// process upon delivery of a signal whose default behavior is to produce a +/// core dump. /// -/// A similar function with the same name is available on FreeBSD (as part of the `procctl` -/// interface), but it has an extra argument which allows to select a process other then the -/// current process. +/// A similar function with the same name is available on FreeBSD (as part of +/// the `procctl` interface), but it has an extra argument which allows to +/// select a process other then the current process. /// /// # References -/// - [`prctl(PR_SET_DUMPABLE,...)`] +/// - [`prctl(PR_SET_DUMPABLE,...)`] /// /// [`prctl(PR_SET_DUMPABLE,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] @@ -182,7 +183,7 @@ bitflags! { /// Get unaligned access control bits. /// /// # References -/// - [`prctl(PR_GET_UNALIGN,...)`] +/// - [`prctl(PR_GET_UNALIGN,...)`] /// /// [`prctl(PR_GET_UNALIGN,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] @@ -196,7 +197,7 @@ const PR_SET_UNALIGN: c_int = 6; /// Set unaligned access control bits. /// /// # References -/// - [`prctl(PR_SET_UNALIGN,...)`] +/// - [`prctl(PR_SET_UNALIGN,...)`] /// /// [`prctl(PR_SET_UNALIGN,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] @@ -223,7 +224,7 @@ bitflags! { /// Get floating point emulation control bits. /// /// # References -/// - [`prctl(PR_GET_FPEMU,...)`] +/// - [`prctl(PR_GET_FPEMU,...)`] /// /// [`prctl(PR_GET_FPEMU,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] @@ -237,7 +238,7 @@ const PR_SET_FPEMU: c_int = 10; /// Set floating point emulation control bits. /// /// # References -/// - [`prctl(PR_SET_FPEMU,...)`] +/// - [`prctl(PR_SET_FPEMU,...)`] /// /// [`prctl(PR_SET_FPEMU,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] @@ -281,7 +282,7 @@ bitflags! { /// Get floating point exception mode. /// /// # References -/// - [`prctl(PR_GET_FPEXC,...)`] +/// - [`prctl(PR_GET_FPEXC,...)`] /// /// [`prctl(PR_GET_FPEXC,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] @@ -295,7 +296,7 @@ const PR_SET_FPEXC: c_int = 12; /// Set floating point exception mode. /// /// # References -/// - [`prctl(PR_SET_FPEXC,...)`] +/// - [`prctl(PR_SET_FPEXC,...)`] /// /// [`prctl(PR_SET_FPEXC,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] @@ -340,7 +341,7 @@ impl TryFrom<i32> for TimingMethod { /// Get which process timing method is currently in use. /// /// # References -/// - [`prctl(PR_GET_TIMING,...)`] +/// - [`prctl(PR_GET_TIMING,...)`] /// /// [`prctl(PR_GET_TIMING,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] @@ -350,11 +351,11 @@ pub fn timing_method() -> io::Result<TimingMethod> { const PR_SET_TIMING: c_int = 14; -/// Set whether to use (normal, traditional) statistical process timing or accurate -/// timestamp-based process timing. +/// Set whether to use (normal, traditional) statistical process timing or +/// accurate timestamp-based process timing. /// /// # References -/// - [`prctl(PR_SET_TIMING,...)`] +/// - [`prctl(PR_SET_TIMING,...)`] /// /// [`prctl(PR_SET_TIMING,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] @@ -400,7 +401,7 @@ impl TryFrom<u32> for EndianMode { /// Get the endianness of the calling process. /// /// # References -/// - [`prctl(PR_GET_ENDIAN,...)`] +/// - [`prctl(PR_GET_ENDIAN,...)`] /// /// [`prctl(PR_GET_ENDIAN,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] @@ -413,7 +414,7 @@ const PR_SET_ENDIAN: c_int = 20; /// Set the endianness of the calling process. /// /// # References -/// - [`prctl(PR_SET_ENDIAN,...)`] +/// - [`prctl(PR_SET_ENDIAN,...)`] /// /// # Safety /// @@ -460,7 +461,7 @@ impl TryFrom<u32> for TimeStampCounterReadability { /// Get the state of the flag determining if the timestamp counter can be read. /// /// # References -/// - [`prctl(PR_GET_TSC,...)`] +/// - [`prctl(PR_GET_TSC,...)`] /// /// [`prctl(PR_GET_TSC,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] @@ -470,10 +471,11 @@ pub fn time_stamp_counter_readability() -> io::Result<TimeStampCounterReadabilit const PR_SET_TSC: c_int = 26; -/// Set the state of the flag determining if the timestamp counter can be read by the process. +/// Set the state of the flag determining if the timestamp counter can be read +/// by the process. /// /// # References -/// - [`prctl(PR_SET_TSC,...)`] +/// - [`prctl(PR_SET_TSC,...)`] /// /// [`prctl(PR_SET_TSC,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] @@ -493,8 +495,8 @@ const PR_TASK_PERF_EVENTS_ENABLE: c_int = 32; /// Enable or disable all performance counters attached to the calling process. /// /// # References -/// - [`prctl(PR_TASK_PERF_EVENTS_ENABLE,...)`] -/// - [`prctl(PR_TASK_PERF_EVENTS_DISABLE,...)`] +/// - [`prctl(PR_TASK_PERF_EVENTS_ENABLE,...)`] +/// - [`prctl(PR_TASK_PERF_EVENTS_DISABLE,...)`] /// /// [`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 @@ -547,7 +549,7 @@ impl TryFrom<u32> for MachineCheckMemoryCorruptionKillPolicy { /// Get the current per-process machine check kill policy. /// /// # References -/// - [`prctl(PR_MCE_KILL_GET,...)`] +/// - [`prctl(PR_MCE_KILL_GET,...)`] /// /// [`prctl(PR_MCE_KILL_GET,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] @@ -565,7 +567,7 @@ const PR_MCE_KILL_SET: usize = 1; /// Set the machine check memory corruption kill policy for the calling thread. /// /// # References -/// - [`prctl(PR_MCE_KILL,...)`] +/// - [`prctl(PR_MCE_KILL,...)`] /// /// [`prctl(PR_MCE_KILL,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] @@ -611,13 +613,16 @@ pub enum VirtualMemoryMapAddress { CodeStart = PR_SET_MM_START_CODE, /// Set the address below which the program text can run. CodeEnd = PR_SET_MM_END_CODE, - /// Set the address above which initialized and uninitialized (bss) data are placed. + /// Set the address above which initialized and uninitialized (bss) data + /// are placed. DataStart = PR_SET_MM_START_DATA, - /// Set the address below which initialized and uninitialized (bss) data are placed. + /// Set the address below which initialized and uninitialized (bss) data + /// are placed. DataEnd = PR_SET_MM_END_DATA, /// Set the start address of the stack. StackStart = PR_SET_MM_START_STACK, - /// Set the address above which the program heap can be expanded with `brk` call. + /// Set the address above which the program heap can be expanded with `brk` + /// call. BrkStart = PR_SET_MM_START_BRK, /// Set the current `brk` value. BrkCurrent = PR_SET_MM_BRK, @@ -631,10 +636,11 @@ pub enum VirtualMemoryMapAddress { EnvironmentEnd = PR_SET_MM_ENV_END, } -/// Modify certain kernel memory map descriptor addresses of the calling process. +/// Modify certain kernel memory map descriptor addresses of the calling +/// process. /// /// # References -/// - [`prctl(PR_SET_MM,...)`] +/// - [`prctl(PR_SET_MM,...)`] /// /// # Safety /// @@ -651,10 +657,11 @@ pub unsafe fn set_virtual_memory_map_address( prctl_3args(PR_SET_MM, option as usize as *mut _, address).map(|_r| ()) } -/// Supersede the `/proc/pid/exe` symbolic link with a new one pointing to a new executable file. +/// Supersede the `/proc/pid/exe` symbolic link with a new one pointing to a +/// new executable file. /// /// # References -/// - [`prctl(PR_SET_MM,PR_SET_MM_EXE_FILE,...)`] +/// - [`prctl(PR_SET_MM,PR_SET_MM_EXE_FILE,...)`] /// /// [`prctl(PR_SET_MM,PR_SET_MM_EXE_FILE,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] @@ -666,7 +673,7 @@ pub fn set_executable_file(fd: BorrowedFd) -> io::Result<()> { /// Set a new auxiliary vector. /// /// # References -/// - [`prctl(PR_SET_MM,PR_SET_MM_AUXV,...)`] +/// - [`prctl(PR_SET_MM,PR_SET_MM_AUXV,...)`] /// /// # Safety /// @@ -689,7 +696,7 @@ pub unsafe fn set_auxiliary_vector(auxv: &[*const c_void]) -> io::Result<()> { /// Get the size of the [`PrctlMmMap`] the kernel expects. /// /// # References -/// - [`prctl(PR_SET_MM,PR_SET_MM_MAP_SIZE,...)`] +/// - [`prctl(PR_SET_MM,PR_SET_MM_MAP_SIZE,...)`] /// /// [`prctl(PR_SET_MM,PR_SET_MM_MAP_SIZE,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] @@ -700,8 +707,8 @@ pub fn virtual_memory_map_config_struct_size() -> io::Result<usize> { Ok(value as usize) } -/// This structure provides new memory descriptor map which mostly modifies `/proc/pid/stat[m]` -/// output for a task. +/// This structure provides new memory descriptor map which mostly modifies +/// `/proc/pid/stat[m]` output for a task. /// This mostly done in a sake of checkpoint/restore functionality. #[repr(C)] #[derive(Debug, Clone)] @@ -732,14 +739,16 @@ pub struct PrctlMmMap { pub auxv: *mut u64, /// Auxiliary vector size. pub auxv_size: u32, - /// File descriptor of executable file that was used to create this process. + /// File descriptor of executable file that was used to create this + /// process. pub exe_fd: u32, } -/// Provides one-shot access to all the addresses by passing in a [`PrctlMmMap`]. +/// Provides one-shot access to all the addresses by passing in a +/// [`PrctlMmMap`]. /// /// # References -/// - [`prctl(PR_SET_MM,PR_SET_MM_MAP,...)`] +/// - [`prctl(PR_SET_MM,PR_SET_MM_MAP,...)`] /// /// # Safety /// @@ -778,11 +787,11 @@ pub enum PTracer { ProcessID(Pid), } -/// Declare that the ptracer process can `ptrace` the calling process as if it were a direct -/// process ancestor. +/// Declare that the ptracer process can `ptrace` the calling process as if it +/// were a direct process ancestor. /// /// # References -/// - [`prctl(PR_SET_PTRACER,...)`] +/// - [`prctl(PR_SET_PTRACER,...)`] /// /// [`prctl(PR_SET_PTRACER,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] @@ -805,7 +814,7 @@ const PR_GET_CHILD_SUBREAPER: c_int = 37; /// Get the `child subreaper` setting of the calling process. /// /// # References -/// - [`prctl(PR_GET_CHILD_SUBREAPER,...)`] +/// - [`prctl(PR_GET_CHILD_SUBREAPER,...)`] /// /// [`prctl(PR_GET_CHILD_SUBREAPER,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] @@ -821,7 +830,7 @@ const PR_SET_CHILD_SUBREAPER: c_int = 36; /// Set the `child subreaper` attribute of the calling process. /// /// # References -/// - [`prctl(PR_SET_CHILD_SUBREAPER,...)`] +/// - [`prctl(PR_SET_CHILD_SUBREAPER,...)`] /// /// [`prctl(PR_SET_CHILD_SUBREAPER,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] @@ -864,7 +873,7 @@ impl TryFrom<u32> for FloatingPointMode { /// Get the current floating point mode. /// /// # References -/// - [`prctl(PR_GET_FP_MODE,...)`] +/// - [`prctl(PR_GET_FP_MODE,...)`] /// /// [`prctl(PR_GET_FP_MODE,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] @@ -878,7 +887,7 @@ const PR_SET_FP_MODE: c_int = 45; /// Allow control of the floating point mode from user space. /// /// # References -/// - [`prctl(PR_SET_FP_MODE,...)`] +/// - [`prctl(PR_SET_FP_MODE,...)`] /// /// [`prctl(PR_SET_FP_MODE,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] @@ -954,7 +963,7 @@ bitflags! { /// Get the state of the speculation misfeature. /// /// # References -/// - [`prctl(PR_GET_SPECULATION_CTRL,...)`] +/// - [`prctl(PR_GET_SPECULATION_CTRL,...)`] /// /// [`prctl(PR_GET_SPECULATION_CTRL,...)`]: https://www.kernel.org/doc/html/v5.18/userspace-api/spec_ctrl.html #[inline] @@ -970,7 +979,7 @@ const PR_SET_SPECULATION_CTRL: c_int = 53; /// Sets the state of the speculation misfeature. /// /// # References -/// - [`prctl(PR_SET_SPECULATION_CTRL,...)`] +/// - [`prctl(PR_SET_SPECULATION_CTRL,...)`] /// /// [`prctl(PR_SET_SPECULATION_CTRL,...)`]: https://www.kernel.org/doc/html/v5.18/userspace-api/spec_ctrl.html #[inline] @@ -992,7 +1001,7 @@ const PR_GET_IO_FLUSHER: c_int = 58; /// Get the `IO_FLUSHER` state of the caller. /// /// # References -/// - [`prctl(PR_GET_IO_FLUSHER,...)`] +/// - [`prctl(PR_GET_IO_FLUSHER,...)`] /// /// [`prctl(PR_GET_IO_FLUSHER,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] @@ -1002,11 +1011,11 @@ pub fn is_io_flusher() -> io::Result<bool> { const PR_SET_IO_FLUSHER: c_int = 57; -/// Put the process in the `IO_FLUSHER` state, allowing it to make progress when -/// allocating memory. +/// Put the process in the `IO_FLUSHER` state, allowing it to make progress +/// when allocating memory. /// /// # References -/// - [`prctl(PR_SET_IO_FLUSHER,...)`] +/// - [`prctl(PR_SET_IO_FLUSHER,...)`] /// /// [`prctl(PR_SET_IO_FLUSHER,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] @@ -1039,7 +1048,7 @@ bitflags! { /// Get enabled pointer authentication keys. /// /// # References -/// - [`prctl(PR_PAC_GET_ENABLED_KEYS,...)`] +/// - [`prctl(PR_PAC_GET_ENABLED_KEYS,...)`] /// /// [`prctl(PR_PAC_GET_ENABLED_KEYS,...)`]: https://www.kernel.org/doc/html/v5.18/arm64/pointer-authentication.html #[inline] @@ -1053,7 +1062,7 @@ const PR_PAC_SET_ENABLED_KEYS: c_int = 60; /// Set enabled pointer authentication keys. /// /// # References -/// - [`prctl(PR_PAC_SET_ENABLED_KEYS,...)`] +/// - [`prctl(PR_PAC_SET_ENABLED_KEYS,...)`] /// /// # Safety /// @@ -1102,7 +1111,7 @@ const PR_SET_VMA_ANON_NAME: usize = 0; /// Set the name for a virtual memory region. /// /// # References -/// - [`prctl(PR_SET_VMA,PR_SET_VMA_ANON_NAME,...)`] +/// - [`prctl(PR_SET_VMA,PR_SET_VMA_ANON_NAME,...)`] /// /// [`prctl(PR_SET_VMA,PR_SET_VMA_ANON_NAME,...)`]: https://lwn.net/Articles/867818/ #[inline] diff --git a/vendor/rustix/src/process/priority.rs b/vendor/rustix/src/process/priority.rs index 4835ceaa2..f8d061c6b 100644 --- a/vendor/rustix/src/process/priority.rs +++ b/vendor/rustix/src/process/priority.rs @@ -1,7 +1,7 @@ use crate::process::{Pid, Uid}; use crate::{backend, io}; -/// `nice()`—Adjust the scheduling priority of the current process. +/// `nice(inc)`—Adjust the scheduling priority of the current process. /// /// # References /// - [POSIX] diff --git a/vendor/rustix/src/process/procctl.rs b/vendor/rustix/src/process/procctl.rs index ff842513f..9e2b3c6e6 100644 --- a/vendor/rustix/src/process/procctl.rs +++ b/vendor/rustix/src/process/procctl.rs @@ -1,11 +1,14 @@ //! Bindings for the FreeBSD `procctl` system call. //! -//! There are similarities (but also differences) with Linux's `prctl` system call, whose interface -//! is located in the `prctl.rs` file. +//! There are similarities (but also differences) with Linux's `prctl` system +//! call, whose interface is located in the `prctl.rs` file. #![allow(unsafe_code)] use core::mem::MaybeUninit; +use core::ptr; + +use bitflags::bitflags; use crate::backend::c::{c_int, c_uint, c_void}; use crate::backend::process::syscalls; @@ -28,9 +31,10 @@ pub enum IdType { /// A process selector for use with the `procctl` interface. /// -/// `None` represents the current process. `Some((IdType::Pid, pid))` represents the process -/// with pid `pid`. `Some((IdType::Pgid, pgid))` represents the control processes belonging to -/// the process group with id `pgid`. +/// `None` represents the current process. `Some((IdType::Pid, pid))` +/// represents the process with pid `pid`. `Some((IdType::Pgid, pgid))` +/// represents the control processes belonging to the process group with id +/// `pgid`. pub type ProcSelector = Option<(IdType, Pid)>; fn proc_selector_to_raw(selector: ProcSelector) -> (IdType, RawPid) { match selector { @@ -77,8 +81,8 @@ const PROC_PDEATHSIG_STATUS: c_int = 12; /// Get the current value of the parent process death signal. /// /// # References -/// - [Linux: `prctl(PR_GET_PDEATHSIG,...)`] -/// - [FreeBSD: `procctl(PROC_PDEATHSIG_STATUS,...)`] +/// - [Linux: `prctl(PR_GET_PDEATHSIG,...)`] +/// - [FreeBSD: `procctl(PROC_PDEATHSIG_STATUS,...)`] /// /// [Linux: `prctl(PR_GET_PDEATHSIG,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html /// [FreeBSD: `procctl(PROC_PDEATHSIG_STATUS,...)`]: https://www.freebsd.org/cgi/man.cgi?query=procctl&sektion=2 @@ -92,8 +96,8 @@ const PROC_PDEATHSIG_CTL: c_int = 11; /// Set the parent-death signal of the calling process. /// /// # References -/// - [Linux: `prctl(PR_SET_PDEATHSIG,...)`] -/// - [FreeBSD: `procctl(PROC_PDEATHSIG_CTL,...)`] +/// - [Linux: `prctl(PR_SET_PDEATHSIG,...)`] +/// - [FreeBSD: `procctl(PROC_PDEATHSIG_CTL,...)`] /// /// [Linux: `prctl(PR_SET_PDEATHSIG,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html /// [FreeBSD: `procctl(PROC_PDEATHSIG_CTL,...)`]: https://www.freebsd.org/cgi/man.cgi?query=procctl&sektion=2 @@ -125,16 +129,18 @@ pub enum DumpableBehavior { NotDumpableExecPreserved = PROC_TRACE_CTL_DISABLE_EXEC, } -/// Set the state of the `dumpable` attribute for the process indicated by `idtype` and `id`. -/// This determines whether the process can be traced and whether core dumps are produced for -/// the process upon delivery of a signal whose default behavior is to produce a core dump. +/// Set the state of the `dumpable` attribute for the process indicated by +/// `idtype` and `id`. This determines whether the process can be traced and +/// whether core dumps are produced for the process upon delivery of a signal +/// whose default behavior is to produce a core dump. /// -/// This is similar to `set_dumpable_behavior` on Linux, with the exception that on FreeBSD -/// there is an extra argument `process`. When `process` is set to `None`, the operation is -/// performed for the current process, like on Linux. +/// This is similar to `set_dumpable_behavior` on Linux, with the exception +/// that on FreeBSD there is an extra argument `process`. When `process` is set +/// to `None`, the operation is performed for the current process, like on +/// Linux. /// /// # References -/// - [`procctl(PROC_TRACE_CTL,...)`] +/// - [`procctl(PROC_TRACE_CTL,...)`] /// /// [`procctl(PROC_TRACE_CTL,...)`]: https://www.freebsd.org/cgi/man.cgi?query=procctl&sektion=2 #[inline] @@ -153,17 +159,18 @@ const PROC_TRACE_STATUS: c_int = 8; pub enum TracingStatus { /// Tracing is disabled for the process. NotTraceble, - /// Tracing is not disabled for the process, but not debugger/tracer is attached. + /// Tracing is not disabled for the process, but not debugger/tracer is + /// attached. Tracable, - /// The process is being traced by the process whose pid is stored in the first - /// component of this variant. + /// The process is being traced by the process whose pid is stored in the + /// first component of this variant. BeingTraced(Pid), } /// Get the tracing status of the process indicated by `idtype` and `id`. /// /// # References -/// - [`procctl(PROC_TRACE_STATUS,...)`] +/// - [`procctl(PROC_TRACE_STATUS,...)`] /// /// [`procctl(PROC_TRACE_STATUS,...)`]: https://www.freebsd.org/cgi/man.cgi?query=procctl&sektion=2 #[inline] @@ -178,3 +185,336 @@ pub fn trace_status(process: ProcSelector) -> io::Result<TracingStatus> { } } } + +// +// PROC_REAP_* +// + +const PROC_REAP_ACQUIRE: c_int = 2; +const PROC_REAP_RELEASE: c_int = 3; + +/// Acquire or release the reaper status of the calling process. +/// +/// # References +/// - [FreeBSD: `procctl(PROC_REAP_ACQUIRE/RELEASE,...)`] +/// +/// [FreeBSD: `procctl(PROC_REAP_ACQUIRE/RELEASE,...)`]: https://www.freebsd.org/cgi/man.cgi?query=procctl&sektion=2 +#[inline] +pub fn set_reaper_status(reaper: bool) -> io::Result<()> { + unsafe { + procctl( + if reaper { + PROC_REAP_ACQUIRE + } else { + PROC_REAP_RELEASE + }, + None, + ptr::null_mut(), + ) + } +} + +const PROC_REAP_STATUS: c_int = 4; + +bitflags! { + /// `REAPER_STATUS_*`. + pub struct ReaperStatusFlags: c_uint { + /// The process has acquired reaper status. + const OWNED = 1; + /// The process is the root of the reaper tree (pid 1). + const REALINIT = 2; + } +} + +#[repr(C)] +struct procctl_reaper_status { + rs_flags: c_uint, + rs_children: c_uint, + rs_descendants: c_uint, + rs_reaper: RawPid, + rs_pid: RawPid, + rs_pad0: [c_uint; 15], +} + +/// Reaper status as returned by [`get_reaper_status`]. +#[derive(Copy, Clone, Debug, Eq, PartialEq)] +pub struct ReaperStatus { + /// The flags. + pub flags: ReaperStatusFlags, + /// The number of children of the reaper among the descendants. + pub children: usize, + /// The total number of descendants of the reaper(s), not counting + /// descendants of the reaper in the subtree. + pub descendants: usize, + /// 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, +} + +/// Get information about the reaper of the specified process (or the process +/// itself if it is a reaper). +/// +/// # References +/// - [FreeBSD: `procctl(PROC_REAP_STATUS,...)`] +/// +/// [FreeBSD: `procctl(PROC_REAP_STATUS,...)`]: https://www.freebsd.org/cgi/man.cgi?query=procctl&sektion=2 +#[inline] +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), + 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)?, + }) +} + +const PROC_REAP_GETPIDS: c_int = 5; + +bitflags! { + /// `REAPER_PIDINFO_*`. + 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. + const REAPER = 4; + } +} + +#[repr(C)] +#[derive(Default, Clone)] +struct procctl_reaper_pidinfo { + pi_pid: RawPid, + pi_subtree: RawPid, + pi_flags: c_uint, + pi_pad0: [c_uint; 15], +} + +#[repr(C)] +struct procctl_reaper_pids { + rp_count: c_uint, + rp_pad0: [c_uint; 15], + rp_pids: *mut procctl_reaper_pidinfo, +} + +/// A child process of a reaper. +#[derive(Copy, Clone, Debug, Eq, PartialEq)] +pub struct PidInfo { + /// The flags of the process. + pub flags: PidInfoFlags, + /// The pid of the process. + pub pid: Pid, + /// The pid of the child of the reaper which is the (grand-..)parent of the + /// process. + pub subtree: Pid, +} + +/// Get the list of descendants of the specified reaper process. +/// +/// # References +/// - [FreeBSD: `procctl(PROC_REAP_GETPIDS,...)`] +/// +/// [FreeBSD: `procctl(PROC_REAP_GETPIDS,...)`]: https://www.freebsd.org/cgi/man.cgi?query=procctl&sektion=2 +pub fn get_reaper_pids(process: ProcSelector) -> io::Result<Vec<PidInfo>> { + // Sadly no better way to guarantee that we get all the results than to + // allocate ~8MB of memory.. + const PID_MAX: usize = 99999; + let mut pids: Vec<procctl_reaper_pidinfo> = vec![Default::default(); PID_MAX]; + let mut pinfo = procctl_reaper_pids { + rp_count: PID_MAX as _, + 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(), + )? + }; + let mut result = Vec::new(); + for raw in pids.into_iter() { + let flags = PidInfoFlags::from_bits_truncate(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)?, + }); + } + Ok(result) +} + +const PROC_REAP_KILL: c_int = 6; + +bitflags! { + /// `REAPER_KILL_*`. + struct KillFlags: c_uint { + const CHILDREN = 1; + const SUBTREE = 2; + } +} + +#[repr(C)] +struct procctl_reaper_kill { + rk_sig: c_int, + rk_flags: c_uint, + rk_subtree: RawPid, + rk_killed: c_uint, + rk_fpid: RawPid, + rk_pad0: [c_uint; 15], +} + +/// Reaper status as returned by [`get_reaper_status`]. +#[derive(Copy, Clone, Debug, Eq, PartialEq)] +pub struct KillResult { + /// The number of processes that were signalled. + pub killed: usize, + /// The pid of the first process that wasn't successfully signalled. + pub first_failed: Option<Pid>, +} + +/// Deliver a signal to some subset of +/// +/// # References +/// - [FreeBSD: `procctl(PROC_REAP_KILL,...)`] +/// +/// [FreeBSD: `procctl(PROC_REAP_KILL,...)`]: https://www.freebsd.org/cgi/man.cgi?query=procctl&sektion=2 +pub fn reaper_kill( + process: ProcSelector, + signal: Signal, + direct_children: bool, + subtree: Option<Pid>, +) -> io::Result<KillResult> { + let mut flags = KillFlags::empty(); + flags.set(KillFlags::CHILDREN, direct_children); + flags.set(KillFlags::SUBTREE, subtree.is_some()); + let mut req = procctl_reaper_kill { + rk_sig: signal as c_int, + rk_flags: flags.bits(), + rk_subtree: subtree.map(|p| p.as_raw_nonzero().into()).unwrap_or(0), + rk_killed: 0, + rk_fpid: 0, + rk_pad0: [0; 15], + }; + unsafe { + procctl( + PROC_REAP_KILL, + process, + (&mut req as *mut procctl_reaper_kill).cast(), + )? + }; + Ok(KillResult { + killed: req.rk_killed as _, + first_failed: if req.rk_fpid == -1 { + None + } else { + unsafe { Pid::from_raw(req.rk_fpid) } + }, + }) +} + +// +// PROC_TRAPCAP_STATUS/PROC_TRAPCAP_CTL +// + +const PROC_TRAPCAP_CTL: c_int = 9; + +const PROC_TRAPCAP_CTL_ENABLE: i32 = 1; +const PROC_TRAPCAP_CTL_DISABLE: i32 = 2; + +/// `PROC_TRAPCAP_CTL_*`. +#[derive(Copy, Clone, Debug, Eq, PartialEq)] +#[repr(i32)] +pub enum TrapCapBehavior { + /// Disable the SIGTRAP signal delivery on capability mode access + /// violations. + Disable = PROC_TRAPCAP_CTL_DISABLE, + /// Enable the SIGTRAP signal delivery on capability mode access + /// violations. + Enable = PROC_TRAPCAP_CTL_ENABLE, +} + +/// Set the current value of the capability mode violation trapping behavior. +/// If this behavior is enabled, the kernel would deliver a SIGTRAP signal on +/// any return from a system call that would result in a `ENOTCAPABLE` or +/// `ECAPMODE` error. +/// +/// This behavior is inherited by the children of the process and is kept +/// across `execve` calls. +/// +/// # References +/// - [FreeBSD: `procctl(PROC_TRAPCAP_CTL,...)`] +/// +/// [FreeBSD: `procctl(PROC_TRAPCAP_CTL,...)`]: https://www.freebsd.org/cgi/man.cgi?query=procctl&sektion=2 +#[inline] +pub fn set_trap_cap_behavior(process: ProcSelector, config: TrapCapBehavior) -> io::Result<()> { + let config = config as c_int; + unsafe { procctl_set::<c_int>(PROC_TRAPCAP_CTL, process, &config) } +} + +const PROC_TRAPCAP_STATUS: c_int = 10; + +/// Get the current value of the capability mode violation trapping behavior. +/// +/// # References +/// - [FreeBSD: `procctl(PROC_TRAPCAP_STATUS,...)`] +/// +/// [FreeBSD: `procctl(PROC_TRAPCAP_STATUS,...)`]: https://www.freebsd.org/cgi/man.cgi?query=procctl&sektion=2 +#[inline] +pub fn trap_cap_behavior(process: ProcSelector) -> io::Result<TrapCapBehavior> { + let val = unsafe { procctl_get_optional::<c_int>(PROC_TRAPCAP_STATUS, process) }?; + match val { + PROC_TRAPCAP_CTL_DISABLE => Ok(TrapCapBehavior::Disable), + PROC_TRAPCAP_CTL_ENABLE => Ok(TrapCapBehavior::Enable), + _ => Err(io::Errno::RANGE), + } +} + +// +// PROC_NO_NEW_PRIVS_STATUS/PROC_NO_NEW_PRIVS_CTL +// + +const PROC_NO_NEW_PRIVS_CTL: c_int = 19; + +const PROC_NO_NEW_PRIVS_ENABLE: c_int = 1; + +/// Enable the `no_new_privs` mode that ignores SUID and SGID bits +/// on `execve` in the specified process and its future descendants. +/// +/// This is similar to `set_no_new_privs` on Linux, with the exception +/// that on FreeBSD there is no argument `no_new_privs` argument as it's +/// only possible to enable this mode and there's no going back. +/// +/// # References +/// - [Linux: `prctl(PR_SET_NO_NEW_PRIVS,...)`] +/// - [FreeBSD: `procctl(PROC_NO_NEW_PRIVS_CTL,...)`] +/// +/// [Linux: `prctl(PR_SET_NO_NEW_PRIVS,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +/// [FreeBSD: `procctl(PROC_NO_NEW_PRIVS_CTL,...)`]: https://www.freebsd.org/cgi/man.cgi?query=procctl&sektion=2 +#[inline] +pub fn set_no_new_privs(process: ProcSelector) -> io::Result<()> { + unsafe { procctl_set::<c_int>(PROC_NO_NEW_PRIVS_CTL, process, &PROC_NO_NEW_PRIVS_ENABLE) } +} + +const PROC_NO_NEW_PRIVS_STATUS: c_int = 20; + +/// Check the `no_new_privs` mode of the specified process. +/// +/// # References +/// - [Linux: `prctl(PR_GET_NO_NEW_PRIVS,...)`] +/// - [FreeBSD: `procctl(PROC_NO_NEW_PRIVS_STATUS,...)`] +/// +/// [Linux: `prctl(PR_GET_NO_NEW_PRIVS,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +/// [FreeBSD: `procctl(PROC_NO_NEW_PRIVS_STATUS,...)`]: https://www.freebsd.org/cgi/man.cgi?query=procctl&sektion=2 +#[inline] +pub fn no_new_privs(process: ProcSelector) -> io::Result<bool> { + unsafe { procctl_get_optional::<c_int>(PROC_NO_NEW_PRIVS_STATUS, process) } + .map(|x| x == PROC_NO_NEW_PRIVS_ENABLE) +} diff --git a/vendor/rustix/src/process/rlimit.rs b/vendor/rustix/src/process/rlimit.rs index e8216af79..089f6b4bb 100644 --- a/vendor/rustix/src/process/rlimit.rs +++ b/vendor/rustix/src/process/rlimit.rs @@ -8,9 +8,9 @@ pub use backend::process::types::Resource; /// [`setrlimit`], and [`prlimit`]. #[derive(Debug, Clone, PartialEq, Eq)] pub struct Rlimit { - /// Current effective, "soft", limit. + /// Current effective, “soft”, limit. pub current: Option<u64>, - /// Maximum, "hard", value that `current` may be dynamically increased to. + /// Maximum, “hard”, value that `current` may be dynamically increased to. pub maximum: Option<u64>, } diff --git a/vendor/rustix/src/process/umask.rs b/vendor/rustix/src/process/umask.rs new file mode 100644 index 000000000..7d83d6686 --- /dev/null +++ b/vendor/rustix/src/process/umask.rs @@ -0,0 +1,21 @@ +//! Umask support. + +#[cfg(feature = "fs")] +use crate::backend; +#[cfg(feature = "fs")] +use crate::fs::Mode; + +/// `umask(mask)`—Set the process file creation mask. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [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")] +pub fn umask(mask: Mode) -> Mode { + backend::process::syscalls::umask(mask) +} diff --git a/vendor/rustix/src/process/uname.rs b/vendor/rustix/src/process/uname.rs index 95dec2699..904532a99 100644 --- a/vendor/rustix/src/process/uname.rs +++ b/vendor/rustix/src/process/uname.rs @@ -65,7 +65,7 @@ impl Uname { #[inline] fn to_cstr<'a>(ptr: *const u8) -> &'a CStr { - // Safety: Strings returned from the kernel are always NUL-terminated. + // SAFETY: Strings returned from the kernel are always NUL-terminated. unsafe { CStr::from_ptr(ptr.cast()) } } } diff --git a/vendor/rustix/src/process/wait.rs b/vendor/rustix/src/process/wait.rs index a4bd1b528..784e6627c 100644 --- a/vendor/rustix/src/process/wait.rs +++ b/vendor/rustix/src/process/wait.rs @@ -2,6 +2,9 @@ use crate::process::Pid; use crate::{backend, io}; use bitflags::bitflags; +#[cfg(target_os = "linux")] +use crate::fd::BorrowedFd; + bitflags! { /// Options for modifying the behavior of wait/waitpid pub struct WaitOptions: u32 { @@ -14,6 +17,23 @@ bitflags! { } } +#[cfg(not(any(target_os = "wasi", target_os = "redox", target_os = "openbsd")))] +bitflags! { + /// Options for modifying the behavior of waitid + pub struct WaitidOptions: u32 { + /// Return immediately if no child has exited. + const NOHANG = backend::process::wait::WNOHANG as _; + /// Return if a stopped child has been resumed by delivery of `SIGCONT` + const CONTINUED = backend::process::wait::WCONTINUED as _; + /// Wait for processed that have exited. + const EXITED = backend::process::wait::WEXITED as _; + /// Keep processed in a waitable state. + const NOWAIT = backend::process::wait::WNOWAIT as _; + /// Wait for processes that have been stopped. + const STOPPED = backend::process::wait::WSTOPPED as _; + } +} + /// the status of the child processes the caller waited on #[derive(Debug, Clone, Copy)] pub struct WaitStatus(u32); @@ -77,6 +97,33 @@ impl WaitStatus { } } +/// The status of a process after calling [`waitid`]. +#[derive(Clone, Copy)] +#[cfg(not(any(target_os = "wasi", target_os = "redox", target_os = "openbsd")))] +pub struct WaitidStatus(pub(crate) backend::c::siginfo_t); + +/// The identifier to wait on in a call to [`waitid`]. +#[cfg(not(any(target_os = "wasi", target_os = "redox", target_os = "openbsd")))] +#[derive(Debug, Clone)] +#[non_exhaustive] +pub enum WaitId<'a> { + /// Wait on all processes. + All, + + /// Wait for a specific process ID. + Pid(Pid), + + /// Wait for a specific process file descriptor. + #[cfg(target_os = "linux")] + PidFd(BorrowedFd<'a>), + + /// Eat the lifetime for non-Linux platforms. + #[doc(hidden)] + #[cfg(not(target_os = "linux"))] + __EatLifetime(std::marker::PhantomData<&'a ()>), + // TODO(notgull): Once this crate has the concept of PGIDs, add a WaitId::Pgid +} + /// `waitpid(pid, waitopts)`—Wait for a specific process to change state. /// /// If the pid is `None`, the call will wait for any child process whose @@ -127,3 +174,14 @@ pub fn waitpid(pid: Option<Pid>, waitopts: WaitOptions) -> io::Result<Option<Wai pub fn wait(waitopts: WaitOptions) -> io::Result<Option<(Pid, WaitStatus)>> { backend::process::syscalls::wait(waitopts) } + +/// `waitid(_, _, _, opts)`—Wait for the specified child process to change +/// state. +#[cfg(not(any(target_os = "wasi", target_os = "redox", target_os = "openbsd")))] +#[inline] +pub fn waitid<'a>( + id: impl Into<WaitId<'a>>, + options: WaitidOptions, +) -> io::Result<Option<WaitidStatus>> { + backend::process::syscalls::waitid(id.into(), options) +} |