diff options
Diffstat (limited to 'vendor/rustix/src')
64 files changed, 1040 insertions, 196 deletions
diff --git a/vendor/rustix/src/backend/libc/c.rs b/vendor/rustix/src/backend/libc/c.rs index f788cb120..d3a1e5f4a 100644 --- a/vendor/rustix/src/backend/libc/c.rs +++ b/vendor/rustix/src/backend/libc/c.rs @@ -130,8 +130,8 @@ pub(super) use libc::{ blksize64_t as blksize_t, fstat64 as fstat, fstatfs64 as fstatfs, fstatvfs64 as fstatvfs, ftruncate64 as ftruncate, getrlimit64 as getrlimit, ino_t, lseek64 as lseek, mmap, off64_t as off_t, openat, posix_fadvise64 as posix_fadvise, preadv, pwritev, - rlimit64 as rlimit, setrlimit64 as setrlimit, statfs64 as statfs, statvfs64 as statvfs, - RLIM_INFINITY, + rlimit64 as rlimit, setrlimit64 as setrlimit, stat64at as fstatat, statfs64 as statfs, + statvfs64 as statvfs, RLIM_INFINITY, }; #[cfg(any(linux_like, target_os = "hurd"))] pub(super) use libc::{ diff --git a/vendor/rustix/src/backend/libc/event/epoll.rs b/vendor/rustix/src/backend/libc/event/epoll.rs index b41b05711..ced3be103 100644 --- a/vendor/rustix/src/backend/libc/event/epoll.rs +++ b/vendor/rustix/src/backend/libc/event/epoll.rs @@ -278,8 +278,8 @@ pub fn wait(epoll: impl AsFd, event_list: &mut EventVec, timeout: c::c_int) -> i /// An iterator over the `Event`s in an `EventVec`. pub struct Iter<'a> { /// Use `Copied` to copy the struct, since `Event` is `packed` on some - /// platforms, and it's common for users to directly destructure it, - /// which would lead to errors about forming references to packed fields. + /// platforms, and it's common for users to directly destructure it, which + /// would lead to errors about forming references to packed fields. iter: core::iter::Copied<slice::Iter<'a, Event>>, } diff --git a/vendor/rustix/src/backend/libc/event/poll_fd.rs b/vendor/rustix/src/backend/libc/event/poll_fd.rs index 42f94f3c7..32fd83dd0 100644 --- a/vendor/rustix/src/backend/libc/event/poll_fd.rs +++ b/vendor/rustix/src/backend/libc/event/poll_fd.rs @@ -12,7 +12,7 @@ use { bitflags! { /// `POLL*` flags for use with [`poll`]. /// - /// [`poll`]: crate::io::poll + /// [`poll`]: crate::event::poll #[repr(transparent)] #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct PollFlags: c::c_short { diff --git a/vendor/rustix/src/backend/libc/event/syscalls.rs b/vendor/rustix/src/backend/libc/event/syscalls.rs index f2dcdf5ad..725ec8250 100644 --- a/vendor/rustix/src/backend/libc/event/syscalls.rs +++ b/vendor/rustix/src/backend/libc/event/syscalls.rs @@ -181,3 +181,11 @@ pub(crate) fn port_send( ) -> io::Result<()> { unsafe { ret(c::port_send(borrowed_fd(port), events, userdata)) } } + +#[cfg(not(any(windows, target_os = "redox", target_os = "wasi")))] +pub(crate) fn pause() { + let r = unsafe { libc::pause() }; + let errno = libc_errno::errno().0; + debug_assert_eq!(r, -1); + debug_assert_eq!(errno, libc::EINTR); +} diff --git a/vendor/rustix/src/backend/libc/event/types.rs b/vendor/rustix/src/backend/libc/event/types.rs index ea4776667..a04d7e6cf 100644 --- a/vendor/rustix/src/backend/libc/event/types.rs +++ b/vendor/rustix/src/backend/libc/event/types.rs @@ -17,7 +17,7 @@ use bitflags::bitflags; bitflags! { /// `EFD_*` flags for use with [`eventfd`]. /// - /// [`eventfd`]: crate::io::eventfd + /// [`eventfd`]: crate::event::eventfd #[repr(transparent)] #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct EventfdFlags: u32 { diff --git a/vendor/rustix/src/backend/libc/fs/dir.rs b/vendor/rustix/src/backend/libc/fs/dir.rs index 0df1ea1b5..82a0a908f 100644 --- a/vendor/rustix/src/backend/libc/fs/dir.rs +++ b/vendor/rustix/src/backend/libc/fs/dir.rs @@ -2,7 +2,7 @@ use super::types::FileType; use crate::backend::c; use crate::backend::conv::owned_fd; -use crate::fd::{AsFd, BorrowedFd}; +use crate::fd::{AsFd, BorrowedFd, OwnedFd}; use crate::ffi::{CStr, CString}; use crate::fs::{fcntl_getfl, openat, Mode, OFlags}; #[cfg(not(target_os = "vita"))] @@ -48,8 +48,34 @@ pub struct Dir { } impl Dir { - /// Construct a `Dir` that reads entries from the given directory - /// file descriptor. + /// Take ownership of `fd` and construct a `Dir` that reads entries from + /// the given directory file descriptor. + #[inline] + pub fn new<Fd: Into<OwnedFd>>(fd: Fd) -> io::Result<Self> { + Self::_new(fd.into()) + } + + #[inline] + fn _new(fd: OwnedFd) -> io::Result<Self> { + let raw = owned_fd(fd); + unsafe { + let libc_dir = c::fdopendir(raw); + + if let Some(libc_dir) = NonNull::new(libc_dir) { + Ok(Self { + libc_dir, + any_errors: false, + }) + } else { + let err = io::Errno::last_os_error(); + let _ = c::close(raw); + Err(err) + } + } + } + + /// Borrow `fd` and construct a `Dir` that reads entries from the given + /// directory file descriptor. #[inline] pub fn read_from<Fd: AsFd>(fd: Fd) -> io::Result<Self> { Self::_read_from(fd.as_fd()) @@ -393,5 +419,5 @@ fn dir_iterator_handles_io_errors() { } assert!(matches!(dir.next(), Some(Err(_)))); - assert!(matches!(dir.next(), None)); + assert!(dir.next().is_none()); } diff --git a/vendor/rustix/src/backend/libc/fs/syscalls.rs b/vendor/rustix/src/backend/libc/fs/syscalls.rs index 5e0b62f8e..fcf069a83 100644 --- a/vendor/rustix/src/backend/libc/fs/syscalls.rs +++ b/vendor/rustix/src/backend/libc/fs/syscalls.rs @@ -2,8 +2,7 @@ use crate::backend::c; #[cfg(any( - apple, - linux_kernel, + not(target_os = "redox"), feature = "alloc", all(linux_kernel, feature = "procfs") ))] @@ -275,10 +274,7 @@ pub(crate) fn readlink(path: &CStr, buf: &mut [u8]) -> io::Result<usize> { } } -#[cfg(all( - any(feature = "alloc", all(linux_kernel, feature = "procfs")), - not(target_os = "redox") -))] +#[cfg(not(target_os = "redox"))] #[inline] pub(crate) fn readlinkat( dirfd: BorrowedFd<'_>, @@ -660,7 +656,7 @@ pub(crate) fn lstat(path: &CStr) -> io::Result<Stat> { } } -#[cfg(not(any(target_os = "aix", target_os = "espidf", target_os = "redox")))] +#[cfg(not(any(target_os = "espidf", target_os = "redox")))] pub(crate) fn statat(dirfd: BorrowedFd<'_>, path: &CStr, flags: AtFlags) -> io::Result<Stat> { // See the comments in `fstat` about using `crate::fs::statx` here. #[cfg(all( @@ -1703,7 +1699,7 @@ pub(crate) fn ftruncate(fd: BorrowedFd<'_>, length: u64) -> io::Result<()> { } #[cfg(any(linux_kernel, target_os = "freebsd"))] -pub(crate) fn memfd_create(path: &CStr, flags: MemfdFlags) -> io::Result<OwnedFd> { +pub(crate) fn memfd_create(name: &CStr, flags: MemfdFlags) -> io::Result<OwnedFd> { #[cfg(target_os = "freebsd")] weakcall! { fn memfd_create( @@ -1720,7 +1716,7 @@ pub(crate) fn memfd_create(path: &CStr, flags: MemfdFlags) -> io::Result<OwnedFd ) via SYS_memfd_create -> c::c_int } - unsafe { ret_owned_fd(memfd_create(c_str(path), bitflags_bits!(flags))) } + unsafe { ret_owned_fd(memfd_create(c_str(name), bitflags_bits!(flags))) } } #[cfg(linux_kernel)] diff --git a/vendor/rustix/src/backend/libc/mm/types.rs b/vendor/rustix/src/backend/libc/mm/types.rs index ef335d27a..a4aa3e232 100644 --- a/vendor/rustix/src/backend/libc/mm/types.rs +++ b/vendor/rustix/src/backend/libc/mm/types.rs @@ -6,7 +6,7 @@ bitflags! { /// /// For `PROT_NONE`, use `ProtFlags::empty()`. /// - /// [`mmap`]: crate::io::mmap + /// [`mmap`]: crate::mm::mmap #[repr(transparent)] #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct ProtFlags: u32 { @@ -27,7 +27,7 @@ bitflags! { /// /// For `PROT_NONE`, use `MprotectFlags::empty()`. /// - /// [`mprotect`]: crate::io::mprotect + /// [`mprotect`]: crate::mm::mprotect #[repr(transparent)] #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct MprotectFlags: u32 { @@ -69,8 +69,8 @@ bitflags! { /// /// For `MAP_ANONYMOUS` (aka `MAP_ANON`), see [`mmap_anonymous`]. /// - /// [`mmap`]: crate::io::mmap - /// [`mmap_anonymous`]: crates::io::mmap_anonymous + /// [`mmap`]: crate::mm::mmap + /// [`mmap_anonymous`]: crates::mm::mmap_anonymous #[repr(transparent)] #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct MapFlags: u32 { @@ -242,8 +242,8 @@ bitflags! { /// /// For `MREMAP_FIXED`, see [`mremap_fixed`]. /// - /// [`mremap`]: crate::io::mremap - /// [`mremap_fixed`]: crate::io::mremap_fixed + /// [`mremap`]: crate::mm::mremap + /// [`mremap_fixed`]: crate::mm::mremap_fixed #[repr(transparent)] #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct MremapFlags: u32 { @@ -258,7 +258,7 @@ bitflags! { bitflags! { /// `MS_*` flags for use with [`msync`]. /// - /// [`msync`]: crate::io::msync + /// [`msync`]: crate::mm::msync #[repr(transparent)] #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct MsyncFlags: u32 { @@ -281,7 +281,7 @@ bitflags! { bitflags! { /// `MLOCK_*` flags for use with [`mlock_with`]. /// - /// [`mlock_with`]: crate::io::mlock_with + /// [`mlock_with`]: crate::mm::mlock_with #[repr(transparent)] #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct MlockFlags: u32 { @@ -383,10 +383,10 @@ pub enum Advice { /// `MADV_UNMERGEABLE` #[cfg(linux_kernel)] LinuxUnmergeable = bitcast!(c::MADV_UNMERGEABLE), - /// `MADV_HUGEPAGE` (since Linux 2.6.38) + /// `MADV_HUGEPAGE` #[cfg(linux_kernel)] LinuxHugepage = bitcast!(c::MADV_HUGEPAGE), - /// `MADV_NOHUGEPAGE` (since Linux 2.6.38) + /// `MADV_NOHUGEPAGE` #[cfg(linux_kernel)] LinuxNoHugepage = bitcast!(c::MADV_NOHUGEPAGE), /// `MADV_DONTDUMP` (since Linux 3.4) @@ -429,7 +429,7 @@ impl Advice { bitflags! { /// `O_*` flags for use with [`userfaultfd`]. /// - /// [`userfaultfd`]: crate::io::userfaultfd + /// [`userfaultfd`]: crate::mm::userfaultfd #[repr(transparent)] #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct UserfaultfdFlags: u32 { @@ -451,8 +451,17 @@ bitflags! { #[repr(transparent)] #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct MlockAllFlags: u32 { - // libc doesn't define `MCL_ONFAULT` yet. - // const ONFAULT = libc::MCL_ONFAULT; + /// Used together with `MCL_CURRENT`, `MCL_FUTURE`, or both. Mark all + /// current (with `MCL_CURRENT`) or future (with `MCL_FUTURE`) mappings + /// to lock pages when they are faulted in. When used with + /// `MCL_CURRENT`, all present pages are locked, but `mlockall` will + /// not fault in non-present pages. When used with `MCL_FUTURE`, all + /// future mappings will be marked to lock pages when they are faulted + /// in, but they will not be populated by the lock when the mapping is + /// created. `MCL_ONFAULT` must be used with either `MCL_CURRENT` or + /// `MCL_FUTURE` or both. + #[cfg(linux_kernel)] + const ONFAULT = bitcast!(libc::MCL_ONFAULT); /// Lock all pages which will become mapped into the address space of /// the process in the future. These could be, for instance, new pages /// required by a growing heap and stack as well as new memory-mapped diff --git a/vendor/rustix/src/backend/libc/mount/types.rs b/vendor/rustix/src/backend/libc/mount/types.rs index d4f9c2da7..238f2128e 100644 --- a/vendor/rustix/src/backend/libc/mount/types.rs +++ b/vendor/rustix/src/backend/libc/mount/types.rs @@ -299,9 +299,9 @@ bitflags! { #[cfg(linux_kernel)] bitflags! { - /// `MS_*` constants for use with [`change_mount`]. + /// `MS_*` constants for use with [`mount_change`]. /// - /// [`change_mount`]: crate::mount::change_mount + /// [`mount_change`]: crate::mount::mount_change #[repr(transparent)] #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct MountPropagationFlags: c::c_ulong { diff --git a/vendor/rustix/src/backend/libc/net/syscalls.rs b/vendor/rustix/src/backend/libc/net/syscalls.rs index 97b862033..33411c01a 100644 --- a/vendor/rustix/src/backend/libc/net/syscalls.rs +++ b/vendor/rustix/src/backend/libc/net/syscalls.rs @@ -100,7 +100,7 @@ pub(crate) fn sendto_v4( send_recv_len(buf.len()), bitflags_bits!(flags), as_ptr(&encode_sockaddr_v4(addr)).cast::<c::sockaddr>(), - size_of::<SocketAddrV4>() as _, + size_of::<c::sockaddr_in>() as c::socklen_t, )) } } @@ -119,7 +119,7 @@ pub(crate) fn sendto_v6( send_recv_len(buf.len()), bitflags_bits!(flags), as_ptr(&encode_sockaddr_v6(addr)).cast::<c::sockaddr>(), - size_of::<SocketAddrV6>() as _, + size_of::<c::sockaddr_in6>() as c::socklen_t, )) } } diff --git a/vendor/rustix/src/backend/libc/pipe/types.rs b/vendor/rustix/src/backend/libc/pipe/types.rs index 1004e41f7..d5cc73962 100644 --- a/vendor/rustix/src/backend/libc/pipe/types.rs +++ b/vendor/rustix/src/backend/libc/pipe/types.rs @@ -7,7 +7,7 @@ use {crate::backend::c, bitflags::bitflags}; bitflags! { /// `O_*` constants for use with [`pipe_with`]. /// - /// [`pipe_with`]: crate::io::pipe_with + /// [`pipe_with`]: crate::pipe::pipe_with #[repr(transparent)] #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct PipeFlags: u32 { @@ -34,8 +34,8 @@ bitflags! { #[cfg(linux_kernel)] bitflags! { - /// `SPLICE_F_*` constants for use with [`splice`], [`vmsplice`], - /// and [`tee`]. + /// `SPLICE_F_*` constants for use with [`splice`], [`vmsplice`], and + /// [`tee`]. #[repr(transparent)] #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct SpliceFlags: c::c_uint { diff --git a/vendor/rustix/src/backend/libc/process/mod.rs b/vendor/rustix/src/backend/libc/process/mod.rs index b89096199..39803b521 100644 --- a/vendor/rustix/src/backend/libc/process/mod.rs +++ b/vendor/rustix/src/backend/libc/process/mod.rs @@ -1,4 +1,4 @@ -#[cfg(any(linux_kernel, target_os = "dragonfly", target_os = "fuchsia"))] +#[cfg(any(freebsdlike, linux_kernel, target_os = "fuchsia"))] pub(crate) mod cpu_set; #[cfg(not(windows))] pub(crate) mod syscalls; diff --git a/vendor/rustix/src/backend/libc/process/syscalls.rs b/vendor/rustix/src/backend/libc/process/syscalls.rs index ec31e0ea7..46fd18211 100644 --- a/vendor/rustix/src/backend/libc/process/syscalls.rs +++ b/vendor/rustix/src/backend/libc/process/syscalls.rs @@ -1,6 +1,6 @@ //! libc syscalls supporting `rustix::process`. -#[cfg(any(linux_kernel, target_os = "dragonfly", target_os = "fuchsia"))] +#[cfg(any(freebsdlike, linux_kernel, target_os = "fuchsia"))] use super::types::RawCpuSet; use crate::backend::c; #[cfg(not(any(target_os = "wasi", target_os = "fuchsia")))] @@ -72,6 +72,14 @@ use { super::super::conv::ret_owned_fd, crate::process::PidfdFlags, crate::process::PidfdGetfdFlags, }; +#[cfg(any(linux_kernel, target_os = "dragonfly"))] +#[inline] +pub(crate) fn sched_getcpu() -> usize { + let r = unsafe { libc::sched_getcpu() }; + debug_assert!(r >= 0); + r as usize +} + #[cfg(feature = "fs")] #[cfg(not(target_os = "wasi"))] pub(crate) fn chdir(path: &CStr) -> io::Result<()> { @@ -181,7 +189,7 @@ pub(crate) fn getpgrp() -> Pid { } } -#[cfg(any(linux_kernel, target_os = "dragonfly", target_os = "fuchsia"))] +#[cfg(any(freebsdlike, linux_kernel, target_os = "fuchsia"))] #[inline] pub(crate) fn sched_getaffinity(pid: Option<Pid>, cpuset: &mut RawCpuSet) -> io::Result<()> { unsafe { @@ -193,7 +201,7 @@ pub(crate) fn sched_getaffinity(pid: Option<Pid>, cpuset: &mut RawCpuSet) -> io: } } -#[cfg(any(linux_kernel, target_os = "dragonfly", target_os = "fuchsia"))] +#[cfg(any(freebsdlike, linux_kernel, target_os = "fuchsia"))] #[inline] pub(crate) fn sched_setaffinity(pid: Option<Pid>, cpuset: &RawCpuSet) -> io::Result<()> { unsafe { diff --git a/vendor/rustix/src/backend/libc/process/types.rs b/vendor/rustix/src/backend/libc/process/types.rs index 8689c414a..f914128df 100644 --- a/vendor/rustix/src/backend/libc/process/types.rs +++ b/vendor/rustix/src/backend/libc/process/types.rs @@ -155,10 +155,12 @@ pub type RawCpuid = u32; #[cfg(freebsdlike)] pub type RawId = c::id_t; -#[cfg(any(linux_kernel, target_os = "dragonfly", target_os = "fuchsia"))] +#[cfg(any(linux_kernel, target_os = "fuchsia"))] pub(crate) type RawCpuSet = c::cpu_set_t; +#[cfg(freebsdlike)] +pub(crate) type RawCpuSet = c::cpuset_t; -#[cfg(any(linux_kernel, target_os = "dragonfly", target_os = "fuchsia"))] +#[cfg(any(freebsdlike, linux_kernel, target_os = "fuchsia"))] #[inline] pub(crate) fn raw_cpu_set_new() -> RawCpuSet { let mut set = unsafe { core::mem::zeroed() }; @@ -166,7 +168,5 @@ pub(crate) fn raw_cpu_set_new() -> RawCpuSet { set } -#[cfg(any(linux_kernel, target_os = "fuchsia"))] +#[cfg(any(freebsdlike, linux_kernel, target_os = "fuchsia"))] pub(crate) const CPU_SETSIZE: usize = c::CPU_SETSIZE as usize; -#[cfg(target_os = "dragonfly")] -pub(crate) const CPU_SETSIZE: usize = 256; diff --git a/vendor/rustix/src/backend/libc/termios/syscalls.rs b/vendor/rustix/src/backend/libc/termios/syscalls.rs index 35d4e2349..a833aea8d 100644 --- a/vendor/rustix/src/backend/libc/termios/syscalls.rs +++ b/vendor/rustix/src/backend/libc/termios/syscalls.rs @@ -115,6 +115,15 @@ pub(crate) fn tcgetattr(fd: BorrowedFd<'_>) -> io::Result<Termios> { pub(crate) fn tcgetpgrp(fd: BorrowedFd<'_>) -> io::Result<Pid> { unsafe { let pid = ret_pid_t(c::tcgetpgrp(borrowed_fd(fd)))?; + + // This doesn't appear to be documented, but on Linux, it appears + // `tcsetpgrp` can succceed and set the pid to 0 if we pass it a + // pseudo-terminal device fd. For now, translate it into `OPNOTSUPP`. + #[cfg(linux_kernel)] + if pid == 0 { + return Err(io::Errno::OPNOTSUPP); + } + Ok(Pid::from_raw_unchecked(pid)) } } diff --git a/vendor/rustix/src/backend/libc/time/types.rs b/vendor/rustix/src/backend/libc/time/types.rs index 1514b02d0..5254c6bc7 100644 --- a/vendor/rustix/src/backend/libc/time/types.rs +++ b/vendor/rustix/src/backend/libc/time/types.rs @@ -83,9 +83,11 @@ bitflags! { #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct TimerfdFlags: u32 { /// `TFD_NONBLOCK` + #[doc(alias = "TFD_NONBLOCK")] const NONBLOCK = bitcast!(c::TFD_NONBLOCK); /// `TFD_CLOEXEC` + #[doc(alias = "TFD_CLOEXEC")] const CLOEXEC = bitcast!(c::TFD_CLOEXEC); /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags> @@ -102,10 +104,12 @@ bitflags! { #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct TimerfdTimerFlags: u32 { /// `TFD_TIMER_ABSTIME` + #[doc(alias = "TFD_TIMER_ABSTIME")] const ABSTIME = bitcast!(c::TFD_TIMER_ABSTIME); /// `TFD_TIMER_CANCEL_ON_SET` #[cfg(linux_kernel)] + #[doc(alias = "TFD_TIMER_CANCEL_ON_SET")] const CANCEL_ON_SET = bitcast!(c::TFD_TIMER_CANCEL_ON_SET); /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags> @@ -127,6 +131,7 @@ pub enum TimerfdClockId { /// epoch, 1970-01-01T00:00:00Z. The clock is externally settable, so it is /// not monotonic. Successive reads may see decreasing times, so it isn't /// reliable for measuring durations. + #[doc(alias = "CLOCK_REALTIME")] Realtime = bitcast!(c::CLOCK_REALTIME), /// `CLOCK_MONOTONIC`—A clock that tells an abstract time. @@ -137,12 +142,14 @@ pub enum TimerfdClockId { /// /// This clock does not advance while the system is suspended; see /// `Boottime` for a clock that does. + #[doc(alias = "CLOCK_MONOTONIC")] Monotonic = bitcast!(c::CLOCK_MONOTONIC), /// `CLOCK_BOOTTIME`—Like `Monotonic`, but advances while suspended. /// /// This clock is similar to `Monotonic`, but does advance while the system /// is suspended. + #[doc(alias = "CLOCK_BOOTTIME")] Boottime = bitcast!(c::CLOCK_BOOTTIME), /// `CLOCK_REALTIME_ALARM`—Like `Realtime`, but wakes a suspended system. @@ -150,6 +157,7 @@ pub enum TimerfdClockId { /// This clock is like `Realtime`, but can wake up a suspended system. /// /// Use of this clock requires the `CAP_WAKE_ALARM` Linux capability. + #[doc(alias = "CLOCK_REALTIME_ALARM")] RealtimeAlarm = bitcast!(c::CLOCK_REALTIME_ALARM), /// `CLOCK_BOOTTIME_ALARM`—Like `Boottime`, but wakes a suspended system. @@ -157,6 +165,7 @@ pub enum TimerfdClockId { /// This clock is like `Boottime`, but can wake up a suspended system. /// /// Use of this clock requires the `CAP_WAKE_ALARM` Linux capability. + #[doc(alias = "CLOCK_BOOTTIME_ALARM")] BoottimeAlarm = bitcast!(c::CLOCK_BOOTTIME_ALARM), } diff --git a/vendor/rustix/src/backend/linux_raw/arch/x86.rs b/vendor/rustix/src/backend/linux_raw/arch/x86.rs index 581cde278..e789181cc 100644 --- a/vendor/rustix/src/backend/linux_raw/arch/x86.rs +++ b/vendor/rustix/src/backend/linux_raw/arch/x86.rs @@ -148,10 +148,10 @@ pub(in crate::backend) unsafe fn indirect_syscall5( // clobbered as the return value anyway. asm!( "push esi", - "push DWORD PTR [eax + 0]", - "mov esi, DWORD PTR [eax + 4]", - "mov eax, DWORD PTR [eax + 8]", - "call DWORD PTR [esp]", + "push [eax + 0]", + "mov esi, [eax + 4]", + "mov eax, [eax + 8]", + "call [esp]", "pop esi", "pop esi", inout("eax") &[callee as _, a3.to_asm(), nr.to_asm()] => r0, @@ -186,11 +186,11 @@ pub(in crate::backend) unsafe fn indirect_syscall6( asm!( "push ebp", "push esi", - "push DWORD PTR [eax + 0]", - "mov esi, DWORD PTR [eax + 4]", - "mov ebp, DWORD PTR [eax + 8]", - "mov eax, DWORD PTR [eax + 12]", - "call DWORD PTR [esp]", + "push [eax + 0]", + "mov esi, [eax + 4]", + "mov ebp, [eax + 8]", + "mov eax, [eax + 12]", + "call [esp]", "pop esi", "pop esi", "pop ebp", @@ -441,9 +441,9 @@ pub(in crate::backend) unsafe fn syscall6( asm!( "push ebp", "push esi", - "mov esi, DWORD PTR [eax + 0]", - "mov ebp, DWORD PTR [eax + 4]", - "mov eax, DWORD PTR [eax + 8]", + "mov esi, [eax + 0]", + "mov ebp, [eax + 4]", + "mov eax, [eax + 8]", "int $$0x80", "pop esi", "pop ebp", @@ -472,9 +472,9 @@ pub(in crate::backend) unsafe fn syscall6_readonly( asm!( "push ebp", "push esi", - "mov esi, DWORD PTR [eax + 0]", - "mov ebp, DWORD PTR [eax + 4]", - "mov eax, DWORD PTR [eax + 8]", + "mov esi, [eax + 0]", + "mov ebp, [eax + 4]", + "mov eax, [eax + 8]", "int $$0x80", "pop esi", "pop ebp", diff --git a/vendor/rustix/src/backend/linux_raw/c.rs b/vendor/rustix/src/backend/linux_raw/c.rs index 01c5eafb1..edc9eb862 100644 --- a/vendor/rustix/src/backend/linux_raw/c.rs +++ b/vendor/rustix/src/backend/linux_raw/c.rs @@ -29,6 +29,7 @@ pub(crate) use linux_raw_sys::general::epoll_event; not(feature = "use-explicitly-provided-auxv"), any( feature = "param", + feature = "process", feature = "runtime", feature = "time", target_arch = "x86", @@ -142,6 +143,8 @@ pub(crate) const EXIT_SUCCESS: c_int = 0; pub(crate) const EXIT_FAILURE: c_int = 1; #[cfg(feature = "process")] pub(crate) const EXIT_SIGNALED_SIGABRT: c_int = 128 + linux_raw_sys::general::SIGABRT as c_int; +#[cfg(feature = "runtime")] +pub(crate) const CLONE_CHILD_SETTID: c_int = linux_raw_sys::general::CLONE_CHILD_SETTID as c_int; #[cfg(feature = "process")] pub(crate) use linux_raw_sys::{ @@ -266,6 +269,14 @@ pub(crate) const CLOCK_THREAD_CPUTIME_ID: c_int = linux_raw_sys::general::CLOCK_THREAD_CPUTIME_ID as _; pub(crate) const CLOCK_PROCESS_CPUTIME_ID: c_int = linux_raw_sys::general::CLOCK_PROCESS_CPUTIME_ID as _; +#[cfg(any(feature = "thread", feature = "time", target_arch = "x86"))] +pub(crate) const CLOCK_BOOTTIME: c_int = linux_raw_sys::general::CLOCK_BOOTTIME as _; +#[cfg(any(feature = "thread", feature = "time", target_arch = "x86"))] +pub(crate) const CLOCK_BOOTTIME_ALARM: c_int = linux_raw_sys::general::CLOCK_BOOTTIME_ALARM as _; +#[cfg(any(feature = "thread", feature = "time", target_arch = "x86"))] +pub(crate) const CLOCK_TAI: c_int = linux_raw_sys::general::CLOCK_TAI as _; +#[cfg(any(feature = "thread", feature = "time", target_arch = "x86"))] +pub(crate) const CLOCK_REALTIME_ALARM: c_int = linux_raw_sys::general::CLOCK_REALTIME_ALARM as _; #[cfg(feature = "system")] mod reboot_symbols { diff --git a/vendor/rustix/src/backend/linux_raw/conv.rs b/vendor/rustix/src/backend/linux_raw/conv.rs index 4b3c15d7a..f0de45a2b 100644 --- a/vendor/rustix/src/backend/linux_raw/conv.rs +++ b/vendor/rustix/src/backend/linux_raw/conv.rs @@ -15,7 +15,7 @@ use super::c; use super::fd::{AsRawFd, BorrowedFd, FromRawFd, RawFd}; -#[cfg(feature = "runtime")] +#[cfg(any(feature = "event", feature = "runtime"))] use super::io::errno::try_decode_error; #[cfg(target_pointer_width = "64")] use super::io::errno::try_decode_u64; @@ -303,6 +303,7 @@ pub(super) fn socklen_t<'a, Num: ArgNumber>(i: socklen_t) -> ArgReg<'a, Num> { not(feature = "use-explicitly-provided-auxv"), any( feature = "param", + feature = "process", feature = "runtime", feature = "time", target_arch = "x86", @@ -622,7 +623,6 @@ impl<'a, Num: ArgNumber> From<crate::backend::mm::types::MlockFlags> for ArgReg< } #[cfg(feature = "mm")] -#[cfg(any(linux_kernel, freebsdlike, netbsdlike))] impl<'a, Num: ArgNumber> From<crate::backend::mm::types::MlockAllFlags> for ArgReg<'a, Num> { #[inline] fn from(flags: crate::backend::mm::types::MlockAllFlags) -> Self { @@ -874,7 +874,7 @@ pub(super) unsafe fn ret(raw: RetReg<R0>) -> io::Result<()> { /// /// The caller must ensure that this is the return value of a syscall which /// doesn't return on success. -#[cfg(feature = "runtime")] +#[cfg(any(feature = "event", feature = "runtime"))] #[inline] pub(super) unsafe fn ret_error(raw: RetReg<R0>) -> io::Errno { try_decode_error(raw) diff --git a/vendor/rustix/src/backend/linux_raw/event/epoll.rs b/vendor/rustix/src/backend/linux_raw/event/epoll.rs index 6aa84d7aa..fb6a04c8e 100644 --- a/vendor/rustix/src/backend/linux_raw/event/epoll.rs +++ b/vendor/rustix/src/backend/linux_raw/event/epoll.rs @@ -262,8 +262,8 @@ pub fn wait(epoll: impl AsFd, event_list: &mut EventVec, timeout: c::c_int) -> i /// An iterator over the `Event`s in an `EventVec`. pub struct Iter<'a> { /// Use `Copied` to copy the struct, since `Event` is `packed` on some - /// platforms, and it's common for users to directly destructure it, - /// which would lead to errors about forming references to packed fields. + /// platforms, and it's common for users to directly destructure it, which + /// would lead to errors about forming references to packed fields. iter: core::iter::Copied<slice::Iter<'a, Event>>, } diff --git a/vendor/rustix/src/backend/linux_raw/event/poll_fd.rs b/vendor/rustix/src/backend/linux_raw/event/poll_fd.rs index 51c222e62..9de43f263 100644 --- a/vendor/rustix/src/backend/linux_raw/event/poll_fd.rs +++ b/vendor/rustix/src/backend/linux_raw/event/poll_fd.rs @@ -4,7 +4,7 @@ use bitflags::bitflags; bitflags! { /// `POLL*` flags for use with [`poll`]. /// - /// [`poll`]: crate::io::poll + /// [`poll`]: crate::event::poll #[repr(transparent)] #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct PollFlags: u16 { diff --git a/vendor/rustix/src/backend/linux_raw/event/syscalls.rs b/vendor/rustix/src/backend/linux_raw/event/syscalls.rs index 6cb8d3d96..0ae775339 100644 --- a/vendor/rustix/src/backend/linux_raw/event/syscalls.rs +++ b/vendor/rustix/src/backend/linux_raw/event/syscalls.rs @@ -9,7 +9,7 @@ use crate::backend::c; #[cfg(feature = "alloc")] use crate::backend::conv::pass_usize; use crate::backend::conv::{ - by_ref, c_int, c_uint, raw_fd, ret, ret_owned_fd, ret_usize, slice_mut, zero, + by_ref, c_int, c_uint, raw_fd, ret, ret_error, ret_owned_fd, ret_usize, slice_mut, zero, }; use crate::event::{epoll, EventfdFlags, PollFd}; use crate::fd::{BorrowedFd, OwnedFd}; @@ -131,3 +131,22 @@ pub(crate) fn epoll_wait( pub(crate) fn eventfd(initval: u32, flags: EventfdFlags) -> io::Result<OwnedFd> { unsafe { ret_owned_fd(syscall_readonly!(__NR_eventfd2, c_uint(initval), flags)) } } + +#[inline] +pub(crate) fn pause() { + unsafe { + #[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))] + let error = ret_error(syscall_readonly!( + __NR_ppoll, + zero(), + zero(), + zero(), + zero() + )); + + #[cfg(not(any(target_arch = "aarch64", target_arch = "riscv64")))] + let error = ret_error(syscall_readonly!(__NR_pause)); + + debug_assert_eq!(error, io::Errno::INTR); + } +} diff --git a/vendor/rustix/src/backend/linux_raw/event/types.rs b/vendor/rustix/src/backend/linux_raw/event/types.rs index eb34bd0b3..01611f673 100644 --- a/vendor/rustix/src/backend/linux_raw/event/types.rs +++ b/vendor/rustix/src/backend/linux_raw/event/types.rs @@ -4,7 +4,7 @@ use bitflags::bitflags; bitflags! { /// `EFD_*` flags for use with [`eventfd`]. /// - /// [`eventfd`]: crate::io::eventfd + /// [`eventfd`]: crate::event::eventfd #[repr(transparent)] #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct EventfdFlags: c::c_uint { diff --git a/vendor/rustix/src/backend/linux_raw/fs/dir.rs b/vendor/rustix/src/backend/linux_raw/fs/dir.rs index ea1017957..dbddd58f1 100644 --- a/vendor/rustix/src/backend/linux_raw/fs/dir.rs +++ b/vendor/rustix/src/backend/linux_raw/fs/dir.rs @@ -32,8 +32,26 @@ pub struct Dir { } impl Dir { - /// Construct a `Dir` that reads entries from the given directory - /// file descriptor. + /// Take ownership of `fd` and construct a `Dir` that reads entries from + /// the given directory file descriptor. + #[inline] + pub fn new<Fd: Into<OwnedFd>>(fd: Fd) -> io::Result<Self> { + Self::_new(fd.into()) + } + + #[inline] + fn _new(fd: OwnedFd) -> io::Result<Self> { + Ok(Self { + fd, + any_errors: false, + rewind: false, + buf: Vec::new(), + pos: 0, + }) + } + + /// Borrow `fd` and construct a `Dir` that reads entries from the given + /// directory file descriptor. #[inline] pub fn read_from<Fd: AsFd>(fd: Fd) -> io::Result<Self> { Self::_read_from(fd.as_fd()) @@ -157,6 +175,7 @@ impl Dir { })) } + #[must_use] fn read_more(&mut self) -> Option<io::Result<()>> { // The first few times we're called, we allocate a relatively small // buffer, because many directories are small. If we're called more, @@ -292,5 +311,5 @@ fn dir_iterator_handles_io_errors() { crate::io::dup2(&file_fd, &mut dir.fd).unwrap(); assert!(matches!(dir.next(), Some(Err(_)))); - assert!(matches!(dir.next(), None)); + assert!(dir.next().is_none()); } diff --git a/vendor/rustix/src/backend/linux_raw/fs/mod.rs b/vendor/rustix/src/backend/linux_raw/fs/mod.rs index ba72c5b6d..9f53c5dba 100644 --- a/vendor/rustix/src/backend/linux_raw/fs/mod.rs +++ b/vendor/rustix/src/backend/linux_raw/fs/mod.rs @@ -6,8 +6,8 @@ pub(crate) mod syscalls; pub(crate) mod types; // TODO: Fix linux-raw-sys to define ioctl codes for sparc. -#[cfg(all(linux_kernel, any(target_arch = "sparc", target_arch = "sparc64")))] +#[cfg(any(target_arch = "sparc", target_arch = "sparc64"))] pub(crate) const EXT4_IOC_RESIZE_FS: u32 = 0x8008_6610; -#[cfg(all(linux_kernel, not(any(target_arch = "sparc", target_arch = "sparc64"))))] +#[cfg(not(any(target_arch = "sparc", target_arch = "sparc64")))] pub(crate) use linux_raw_sys::ioctl::EXT4_IOC_RESIZE_FS; diff --git a/vendor/rustix/src/backend/linux_raw/fs/syscalls.rs b/vendor/rustix/src/backend/linux_raw/fs/syscalls.rs index f856fa8b0..5f15f5c93 100644 --- a/vendor/rustix/src/backend/linux_raw/fs/syscalls.rs +++ b/vendor/rustix/src/backend/linux_raw/fs/syscalls.rs @@ -8,9 +8,11 @@ use crate::backend::c; use crate::backend::conv::fs::oflags_for_open_how; +#[cfg(not(feature = "linux_4_11"))] +use crate::backend::conv::zero; use crate::backend::conv::{ by_ref, c_int, c_uint, dev_t, opt_mut, pass_usize, raw_fd, ret, ret_c_int, ret_c_uint, - ret_infallible, ret_owned_fd, ret_usize, size_of, slice, slice_mut, zero, + ret_infallible, ret_owned_fd, ret_usize, size_of, slice, slice_mut, }; #[cfg(target_pointer_width = "64")] use crate::backend::conv::{loff_t, loff_t_from_u64, ret_u64}; @@ -839,13 +841,15 @@ pub(crate) fn statx( } } +#[cfg(not(feature = "linux_4_11"))] #[inline] pub(crate) fn is_statx_available() -> bool { unsafe { // Call `statx` with null pointers so that if it fails for any reason - // other than `EFAULT`, we know it's not supported. + // other than `EFAULT`, we know it's not supported. This can use + // "readonly" because we don't pass it a buffer to mutate. matches!( - ret(syscall!( + ret(syscall_readonly!( __NR_statx, raw_fd(AT_FDCWD), zero(), @@ -957,7 +961,6 @@ pub(crate) fn readlink(path: &CStr, buf: &mut [u8]) -> io::Result<usize> { } } -#[cfg(any(feature = "alloc", all(linux_kernel, feature = "procfs")))] #[inline] pub(crate) fn readlinkat( dirfd: BorrowedFd<'_>, diff --git a/vendor/rustix/src/backend/linux_raw/fs/types.rs b/vendor/rustix/src/backend/linux_raw/fs/types.rs index 85fe018a3..71ee9f52e 100644 --- a/vendor/rustix/src/backend/linux_raw/fs/types.rs +++ b/vendor/rustix/src/backend/linux_raw/fs/types.rs @@ -197,13 +197,13 @@ bitflags! { /// `O_DIRECTORY` const DIRECTORY = linux_raw_sys::general::O_DIRECTORY; - /// `O_DSYNC`. Linux 2.6.32 only supports `O_SYNC`. + /// `O_DSYNC`. const DSYNC = linux_raw_sys::general::O_SYNC; /// `O_EXCL` const EXCL = linux_raw_sys::general::O_EXCL; - /// `O_FSYNC`. Linux 2.6.32 only supports `O_SYNC`. + /// `O_FSYNC`. const FSYNC = linux_raw_sys::general::O_SYNC; /// `O_NOFOLLOW` @@ -226,7 +226,7 @@ bitflags! { /// `O_NOCTTY` const NOCTTY = linux_raw_sys::general::O_NOCTTY; - /// `O_RSYNC`. Linux 2.6.32 only supports `O_SYNC`. + /// `O_RSYNC`. const RSYNC = linux_raw_sys::general::O_SYNC; /// `O_SYNC` diff --git a/vendor/rustix/src/backend/linux_raw/io/errno.rs b/vendor/rustix/src/backend/linux_raw/io/errno.rs index 8247faa1c..6771ba2b2 100644 --- a/vendor/rustix/src/backend/linux_raw/io/errno.rs +++ b/vendor/rustix/src/backend/linux_raw/io/errno.rs @@ -236,7 +236,7 @@ pub(in crate::backend) unsafe fn try_decode_void<Num: RetNumber>( /// # Safety /// /// This must only be used with syscalls which do not return on success. -#[cfg(feature = "runtime")] +#[cfg(any(feature = "event", feature = "runtime"))] #[inline] pub(in crate::backend) unsafe fn try_decode_error<Num: RetNumber>(raw: RetReg<Num>) -> io::Errno { debug_assert!(raw.is_in_range(-4095..0)); diff --git a/vendor/rustix/src/backend/linux_raw/mm/syscalls.rs b/vendor/rustix/src/backend/linux_raw/mm/syscalls.rs index 3d4274cfe..361f11157 100644 --- a/vendor/rustix/src/backend/linux_raw/mm/syscalls.rs +++ b/vendor/rustix/src/backend/linux_raw/mm/syscalls.rs @@ -6,10 +6,8 @@ #![allow(unsafe_code)] #![allow(clippy::undocumented_unsafe_blocks)] -#[cfg(any(linux_kernel, freebsdlike, netbsdlike))] -use super::types::MlockAllFlags; use super::types::{ - Advice, MapFlags, MlockFlags, MprotectFlags, MremapFlags, MsyncFlags, ProtFlags, + Advice, MapFlags, MlockAllFlags, MlockFlags, MprotectFlags, MremapFlags, MsyncFlags, ProtFlags, UserfaultfdFlags, }; use crate::backend::c; @@ -221,7 +219,6 @@ pub(crate) unsafe fn userfaultfd(flags: UserfaultfdFlags) -> io::Result<OwnedFd> /// returns successfully; the pages are guaranteed to stay in RAM until later /// unlocked. #[inline] -#[cfg(any(linux_kernel, freebsdlike, netbsdlike))] pub(crate) fn mlockall(flags: MlockAllFlags) -> io::Result<()> { // When `mlockall` is used with `MCL_ONFAULT | MCL_FUTURE`, the ordering // of `mlockall` with respect to arbitrary loads may be significant, @@ -235,7 +232,6 @@ pub(crate) fn mlockall(flags: MlockAllFlags) -> io::Result<()> { /// Unlocks all pages mapped into the address space of the calling process. #[inline] -#[cfg(any(linux_kernel, freebsdlike, netbsdlike))] pub(crate) fn munlockall() -> io::Result<()> { unsafe { ret(syscall_readonly!(__NR_munlockall)) } } diff --git a/vendor/rustix/src/backend/linux_raw/mm/types.rs b/vendor/rustix/src/backend/linux_raw/mm/types.rs index b5e36640d..68898f58b 100644 --- a/vendor/rustix/src/backend/linux_raw/mm/types.rs +++ b/vendor/rustix/src/backend/linux_raw/mm/types.rs @@ -6,7 +6,7 @@ bitflags! { /// /// For `PROT_NONE`, use `ProtFlags::empty()`. /// - /// [`mmap`]: crate::io::mmap + /// [`mmap`]: crate::mm::mmap #[repr(transparent)] #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct ProtFlags: u32 { @@ -27,7 +27,7 @@ bitflags! { /// /// For `PROT_NONE`, use `MprotectFlags::empty()`. /// - /// [`mprotect`]: crate::io::mprotect + /// [`mprotect`]: crate::mm::mprotect #[repr(transparent)] #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct MprotectFlags: u32 { @@ -66,8 +66,8 @@ bitflags! { /// /// For `MAP_ANONYMOUS` (aka `MAP_ANON`), see [`mmap_anonymous`]. /// - /// [`mmap`]: crate::io::mmap - /// [`mmap_anonymous`]: crates::io::mmap_anonymous + /// [`mmap`]: crate::mm::mmap + /// [`mmap_anonymous`]: crates::mm::mmap_anonymous #[repr(transparent)] #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct MapFlags: u32 { @@ -116,8 +116,8 @@ bitflags! { /// /// For `MREMAP_FIXED`, see [`mremap_fixed`]. /// - /// [`mremap`]: crate::io::mremap - /// [`mremap_fixed`]: crate::io::mremap_fixed + /// [`mremap`]: crate::mm::mremap + /// [`mremap_fixed`]: crate::mm::mremap_fixed #[repr(transparent)] #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct MremapFlags: u32 { @@ -134,7 +134,7 @@ bitflags! { bitflags! { /// `MS_*` flags for use with [`msync`]. /// - /// [`msync`]: crate::io::msync + /// [`msync`]: crate::mm::msync #[repr(transparent)] #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct MsyncFlags: u32 { @@ -156,7 +156,7 @@ bitflags! { bitflags! { /// `MLOCK_*` flags for use with [`mlock_with`]. /// - /// [`mlock_with`]: crate::io::mlock_with + /// [`mlock_with`]: crate::mm::mlock_with #[repr(transparent)] #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct MlockFlags: u32 { @@ -212,9 +212,9 @@ pub enum Advice { LinuxMergeable = linux_raw_sys::general::MADV_MERGEABLE, /// `MADV_UNMERGEABLE` LinuxUnmergeable = linux_raw_sys::general::MADV_UNMERGEABLE, - /// `MADV_HUGEPAGE` (since Linux 2.6.38) + /// `MADV_HUGEPAGE` LinuxHugepage = linux_raw_sys::general::MADV_HUGEPAGE, - /// `MADV_NOHUGEPAGE` (since Linux 2.6.38) + /// `MADV_NOHUGEPAGE` LinuxNoHugepage = linux_raw_sys::general::MADV_NOHUGEPAGE, /// `MADV_DONTDUMP` (since Linux 3.4) LinuxDontDump = linux_raw_sys::general::MADV_DONTDUMP, @@ -249,7 +249,7 @@ impl Advice { bitflags! { /// `O_*` flags for use with [`userfaultfd`]. /// - /// [`userfaultfd`]: crate::io::userfaultfd + /// [`userfaultfd`]: crate::mm::userfaultfd #[repr(transparent)] #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct UserfaultfdFlags: c::c_uint { @@ -263,7 +263,6 @@ bitflags! { } } -#[cfg(any(linux_kernel, freebsdlike, netbsdlike))] bitflags! { /// `MCL_*` flags for use with [`mlockall`]. /// diff --git a/vendor/rustix/src/backend/linux_raw/mod.rs b/vendor/rustix/src/backend/linux_raw/mod.rs index 388f573dc..0d4e5332d 100644 --- a/vendor/rustix/src/backend/linux_raw/mod.rs +++ b/vendor/rustix/src/backend/linux_raw/mod.rs @@ -18,9 +18,9 @@ mod arch; mod conv; mod reg; -#[cfg(any(feature = "time", target_arch = "x86"))] +#[cfg(any(feature = "time", feature = "process", target_arch = "x86"))] mod vdso; -#[cfg(any(feature = "time", target_arch = "x86"))] +#[cfg(any(feature = "time", feature = "process", target_arch = "x86"))] mod vdso_wrappers; #[cfg(feature = "event")] @@ -32,6 +32,7 @@ pub(crate) mod event; not(feature = "use-explicitly-provided-auxv"), any( feature = "param", + feature = "process", feature = "runtime", feature = "time", target_arch = "x86", @@ -52,6 +53,7 @@ pub(crate) mod mount; // for deprecated mount functions in "fs" pub(crate) mod net; #[cfg(any( feature = "param", + feature = "process", feature = "runtime", feature = "time", target_arch = "x86", diff --git a/vendor/rustix/src/backend/linux_raw/mount/types.rs b/vendor/rustix/src/backend/linux_raw/mount/types.rs index 3a797ab77..43a2f7b49 100644 --- a/vendor/rustix/src/backend/linux_raw/mount/types.rs +++ b/vendor/rustix/src/backend/linux_raw/mount/types.rs @@ -292,9 +292,9 @@ bitflags! { } bitflags! { - /// `MS_*` constants for use with [`change_mount`]. + /// `MS_*` constants for use with [`mount_change`]. /// - /// [`change_mount`]: crate::mount::change_mount + /// [`mount_change`]: crate::mount::mount_change #[repr(transparent)] #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct MountPropagationFlags: c::c_uint { diff --git a/vendor/rustix/src/backend/linux_raw/param/auxv.rs b/vendor/rustix/src/backend/linux_raw/param/auxv.rs index fbbcdea29..b9ac27eec 100644 --- a/vendor/rustix/src/backend/linux_raw/param/auxv.rs +++ b/vendor/rustix/src/backend/linux_raw/param/auxv.rs @@ -25,7 +25,7 @@ use linux_raw_sys::general::{ }; #[cfg(feature = "runtime")] use linux_raw_sys::general::{ - AT_EGID, AT_ENTRY, AT_EUID, AT_GID, AT_PHDR, AT_PHENT, AT_PHNUM, AT_SECURE, AT_UID, + AT_EGID, AT_ENTRY, AT_EUID, AT_GID, AT_PHDR, AT_PHENT, AT_PHNUM, AT_RANDOM, AT_SECURE, AT_UID, }; #[cfg(feature = "param")] @@ -145,6 +145,19 @@ pub(crate) fn entry() -> usize { entry } +#[cfg(feature = "runtime")] +#[inline] +pub(crate) fn random() -> *const [u8; 16] { + let mut random = RANDOM.load(Relaxed); + + if random.is_null() { + init_auxv(); + random = RANDOM.load(Relaxed); + } + + random +} + static PAGE_SIZE: AtomicUsize = AtomicUsize::new(0); static CLOCK_TICKS_PER_SECOND: AtomicUsize = AtomicUsize::new(0); static HWCAP: AtomicUsize = AtomicUsize::new(0); @@ -161,6 +174,8 @@ static PHENT: AtomicUsize = AtomicUsize::new(0); static PHNUM: AtomicUsize = AtomicUsize::new(0); #[cfg(feature = "runtime")] static ENTRY: AtomicUsize = AtomicUsize::new(0); +#[cfg(feature = "runtime")] +static RANDOM: AtomicPtr<[u8; 16]> = AtomicPtr::new(null_mut()); #[cfg(feature = "alloc")] fn pr_get_auxv() -> crate::io::Result<Vec<u8>> { @@ -207,7 +222,7 @@ fn init_auxv() { Ok(buffer) => { // SAFETY: We assume the kernel returns a valid auxv. unsafe { - init_from_aux_iter(AuxPointer(buffer.as_ptr().cast())); + init_from_aux_iter(AuxPointer(buffer.as_ptr().cast())).unwrap(); } return; } @@ -235,6 +250,7 @@ fn init_auxv() { /// Process auxv entries from the open file `auxv`. #[cfg(feature = "alloc")] #[cold] +#[must_use] fn init_from_auxv_file(auxv: OwnedFd) -> Option<()> { let mut buffer = Vec::<u8>::with_capacity(512); loop { @@ -271,6 +287,7 @@ fn init_from_auxv_file(auxv: OwnedFd) -> Option<()> { /// The buffer contains `Elf_aux_t` elements, though it need not be aligned; /// function uses `read_unaligned` to read from it. #[cold] +#[must_use] unsafe fn init_from_aux_iter(aux_iter: impl Iterator<Item = Elf_auxv_t>) -> Option<()> { let mut pagesz = 0; let mut clktck = 0; @@ -296,6 +313,8 @@ unsafe fn init_from_aux_iter(aux_iter: impl Iterator<Item = Elf_auxv_t>) -> Opti let mut gid = None; #[cfg(feature = "runtime")] let mut egid = None; + #[cfg(feature = "runtime")] + let mut random = null_mut(); for Elf_auxv_t { a_type, a_val } in aux_iter { match a_type as _ { @@ -307,7 +326,11 @@ unsafe fn init_from_aux_iter(aux_iter: impl Iterator<Item = Elf_auxv_t>) -> Opti AT_SYSINFO_EHDR => sysinfo_ehdr = check_elf_base(a_val as *mut _)?.as_ptr(), AT_BASE => { - let _ = check_elf_base(a_val.cast())?; + // The `AT_BASE` value can be NULL in a static executable that + // doesn't use a dynamic linker. If so, ignore it. + if !a_val.is_null() { + let _ = check_elf_base(a_val.cast())?; + } } #[cfg(feature = "runtime")] @@ -328,6 +351,8 @@ unsafe fn init_from_aux_iter(aux_iter: impl Iterator<Item = Elf_auxv_t>) -> Opti AT_PHENT => phent = a_val as usize, #[cfg(feature = "runtime")] AT_ENTRY => entry = a_val as usize, + #[cfg(feature = "runtime")] + AT_RANDOM => random = check_raw_pointer::<[u8; 16]>(a_val as *mut _)?.as_ptr(), AT_NULL => break, _ => (), @@ -361,6 +386,8 @@ unsafe fn init_from_aux_iter(aux_iter: impl Iterator<Item = Elf_auxv_t>) -> Opti PHNUM.store(phnum, Relaxed); #[cfg(feature = "runtime")] ENTRY.store(entry, Relaxed); + #[cfg(feature = "runtime")] + RANDOM.store(random, Relaxed); Some(()) } @@ -371,6 +398,7 @@ unsafe fn init_from_aux_iter(aux_iter: impl Iterator<Item = Elf_auxv_t>) -> Opti /// which hopefully holds the value of the kernel-provided vDSO in memory. Do a /// series of checks to be as sure as we can that it's safe to use. #[cold] +#[must_use] unsafe fn check_elf_base(base: *const Elf_Ehdr) -> Option<NonNull<Elf_Ehdr>> { // If we're reading a 64-bit auxv on a 32-bit platform, we'll see a zero // `a_val` because `AT_*` values are never greater than `u32::MAX`. Zero is @@ -471,7 +499,7 @@ impl Iterator for AuxFile { Ok(0) => panic!("unexpected end of auxv file"), Ok(n) => slice = &mut slice[n..], Err(crate::io::Errno::INTR) => continue, - Err(err) => Err(err).unwrap(), + Err(err) => panic!("{:?}", err), } } Some(unsafe { read_unaligned(buf.as_ptr().cast()) }) diff --git a/vendor/rustix/src/backend/linux_raw/param/init.rs b/vendor/rustix/src/backend/linux_raw/param/init.rs index a63212507..fe29e9c04 100644 --- a/vendor/rustix/src/backend/linux_raw/param/init.rs +++ b/vendor/rustix/src/backend/linux_raw/param/init.rs @@ -18,7 +18,7 @@ use linux_raw_sys::general::{ AT_CLKTCK, AT_EXECFN, AT_HWCAP, AT_HWCAP2, AT_NULL, AT_PAGESZ, AT_SYSINFO_EHDR, }; #[cfg(feature = "runtime")] -use linux_raw_sys::general::{AT_ENTRY, AT_PHDR, AT_PHENT, AT_PHNUM, AT_SECURE}; +use linux_raw_sys::general::{AT_ENTRY, AT_PHDR, AT_PHENT, AT_PHNUM, AT_RANDOM, AT_SECURE}; #[cfg(feature = "param")] #[inline] @@ -84,6 +84,12 @@ pub(crate) fn entry() -> usize { unsafe { ENTRY.load(Ordering::Relaxed) } } +#[cfg(feature = "runtime")] +#[inline] +pub(crate) fn random() -> *const [u8; 16] { + unsafe { RANDOM.load(Ordering::Relaxed) } +} + static mut PAGE_SIZE: AtomicUsize = AtomicUsize::new(0); static mut CLOCK_TICKS_PER_SECOND: AtomicUsize = AtomicUsize::new(0); static mut HWCAP: AtomicUsize = AtomicUsize::new(0); @@ -103,6 +109,8 @@ static mut PHENT: AtomicUsize = AtomicUsize::new(0); static mut PHNUM: AtomicUsize = AtomicUsize::new(0); #[cfg(feature = "runtime")] static mut ENTRY: AtomicUsize = AtomicUsize::new(0); +#[cfg(feature = "runtime")] +static mut RANDOM: AtomicPtr<[u8; 16]> = AtomicPtr::new(NonNull::dangling().as_ptr()); /// When "use-explicitly-provided-auxv" is enabled, we export a function to be /// called during initialization, and passed a pointer to the original @@ -152,6 +160,8 @@ unsafe fn init_from_auxp(mut auxp: *const Elf_auxv_t) { AT_PHENT => PHENT.store(a_val as usize, Ordering::Relaxed), #[cfg(feature = "runtime")] AT_ENTRY => ENTRY.store(a_val as usize, Ordering::Relaxed), + #[cfg(feature = "runtime")] + AT_RANDOM => RANDOM.store(a_val.cast::<[u8; 16]>(), Ordering::Relaxed), AT_NULL => break, _ => (), diff --git a/vendor/rustix/src/backend/linux_raw/param/libc_auxv.rs b/vendor/rustix/src/backend/linux_raw/param/libc_auxv.rs index 311cf961b..cfdd7a543 100644 --- a/vendor/rustix/src/backend/linux_raw/param/libc_auxv.rs +++ b/vendor/rustix/src/backend/linux_raw/param/libc_auxv.rs @@ -33,6 +33,8 @@ const AT_PHNUM: c::c_ulong = 5; #[cfg(feature = "runtime")] const AT_ENTRY: c::c_ulong = 9; const AT_HWCAP: c::c_ulong = 16; +#[cfg(feature = "runtime")] +const AT_RANDOM: c::c_ulong = 25; const AT_HWCAP2: c::c_ulong = 26; const AT_SECURE: c::c_ulong = 23; const AT_EXECFN: c::c_ulong = 31; @@ -68,6 +70,8 @@ fn test_abi() { const_assert_eq!(self::AT_PHNUM, ::libc::AT_PHNUM); #[cfg(feature = "runtime")] const_assert_eq!(self::AT_ENTRY, ::libc::AT_ENTRY); + #[cfg(feature = "runtime")] + const_assert_eq!(self::AT_RANDOM, ::libc::AT_RANDOM); } #[cfg(feature = "param")] @@ -163,3 +167,9 @@ pub(in super::super) fn sysinfo_ehdr() -> *const Elf_Ehdr { pub(crate) fn entry() -> usize { unsafe { getauxval(AT_ENTRY) as usize } } + +#[cfg(feature = "runtime")] +#[inline] +pub(crate) fn random() -> *const [u8; 16] { + unsafe { getauxval(AT_RANDOM) as *const [u8; 16] } +} diff --git a/vendor/rustix/src/backend/linux_raw/pipe/types.rs b/vendor/rustix/src/backend/linux_raw/pipe/types.rs index fdddb89e1..cfcb75477 100644 --- a/vendor/rustix/src/backend/linux_raw/pipe/types.rs +++ b/vendor/rustix/src/backend/linux_raw/pipe/types.rs @@ -5,7 +5,7 @@ use core::marker::PhantomData; bitflags! { /// `O_*` constants for use with [`pipe_with`]. /// - /// [`pipe_with`]: crate::io::pipe_with + /// [`pipe_with`]: crate::pipe::pipe_with #[repr(transparent)] #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct PipeFlags: c::c_uint { diff --git a/vendor/rustix/src/backend/linux_raw/process/syscalls.rs b/vendor/rustix/src/backend/linux_raw/process/syscalls.rs index 931f2ff2a..130ee4c93 100644 --- a/vendor/rustix/src/backend/linux_raw/process/syscalls.rs +++ b/vendor/rustix/src/backend/linux_raw/process/syscalls.rs @@ -36,6 +36,32 @@ use {crate::backend::conv::ret_c_uint_infallible, crate::fs::Mode}; #[cfg(feature = "alloc")] use {crate::backend::conv::slice_just_addr_mut, crate::process::Gid}; +// `sched_getcpu` has special optimizations via the vDSO on some architectures. +#[cfg(any( + target_arch = "x86_64", + target_arch = "x86", + target_arch = "riscv64", + target_arch = "powerpc64" +))] +pub(crate) use crate::backend::vdso_wrappers::sched_getcpu; + +// `sched_getcpu` on platforms without a vDSO entry for it. +#[cfg(not(any( + target_arch = "x86_64", + target_arch = "x86", + target_arch = "riscv64", + target_arch = "powerpc64" +)))] +#[inline] +pub(crate) fn sched_getcpu() -> usize { + let mut cpu = MaybeUninit::<u32>::uninit(); + unsafe { + let r = ret(syscall!(__NR_getcpu, &mut cpu, zero(), zero())); + debug_assert!(r.is_ok()); + cpu.assume_init() as usize + } +} + #[cfg(feature = "fs")] #[inline] pub(crate) fn chdir(filename: &CStr) -> io::Result<()> { diff --git a/vendor/rustix/src/backend/linux_raw/runtime/syscalls.rs b/vendor/rustix/src/backend/linux_raw/runtime/syscalls.rs index 1bc461c04..12162fd32 100644 --- a/vendor/rustix/src/backend/linux_raw/runtime/syscalls.rs +++ b/vendor/rustix/src/backend/linux_raw/runtime/syscalls.rs @@ -9,8 +9,8 @@ use crate::backend::c; #[cfg(target_arch = "x86")] use crate::backend::conv::by_mut; use crate::backend::conv::{ - by_ref, c_int, c_uint, ret, ret_c_int, ret_c_int_infallible, ret_error, ret_void_star, size_of, - zero, + by_ref, c_int, c_uint, ret, ret_c_int, ret_c_int_infallible, ret_error, ret_infallible, + ret_void_star, size_of, zero, }; #[cfg(feature = "fs")] use crate::fd::BorrowedFd; @@ -18,8 +18,8 @@ use crate::ffi::CStr; #[cfg(feature = "fs")] use crate::fs::AtFlags; use crate::io; -use crate::pid::Pid; -use crate::runtime::{How, Sigaction, Siginfo, Sigset, Stack}; +use crate::pid::{Pid, RawPid}; +use crate::runtime::{Fork, How, Sigaction, Siginfo, Sigset, Stack}; use crate::signal::Signal; use crate::timespec::Timespec; use crate::utils::option_as_ptr; @@ -28,21 +28,53 @@ use core::mem::MaybeUninit; #[cfg(target_pointer_width = "32")] use linux_raw_sys::general::__kernel_old_timespec; use linux_raw_sys::general::kernel_sigset_t; -use linux_raw_sys::prctl::PR_SET_NAME; #[cfg(target_arch = "x86_64")] -use {crate::backend::conv::ret_infallible, linux_raw_sys::general::ARCH_SET_FS}; +use linux_raw_sys::general::ARCH_SET_FS; +use linux_raw_sys::prctl::PR_SET_NAME; #[inline] -pub(crate) unsafe fn fork() -> io::Result<Option<Pid>> { +pub(crate) unsafe fn fork() -> io::Result<Fork> { + let mut child_pid = MaybeUninit::<RawPid>::uninit(); + + // Unix `fork` only returns the child PID in the parent; we'd like it in + // the child too, so set `CLONE_CHILD_SETTID` and pass in the address of + // a memory location to store it to in the child. + // + // Architectures differ on the order of the parameters. + #[cfg(target_arch = "x86_64")] let pid = ret_c_int(syscall_readonly!( __NR_clone, - c_int(c::SIGCHLD), - zero(), + c_int(c::SIGCHLD | c::CLONE_CHILD_SETTID), zero(), zero(), + &mut child_pid, zero() ))?; - Ok(Pid::from_raw(pid)) + #[cfg(any( + target_arch = "aarch64", + target_arch = "arm", + target_arch = "mips", + target_arch = "mips32r6", + target_arch = "mips64", + target_arch = "mips64r6", + target_arch = "powerpc64", + target_arch = "riscv64", + target_arch = "x86" + ))] + let pid = ret_c_int(syscall_readonly!( + __NR_clone, + c_int(c::SIGCHLD | c::CLONE_CHILD_SETTID), + zero(), + zero(), + zero(), + &mut child_pid + ))?; + + Ok(if let Some(pid) = Pid::from_raw(pid) { + Fork::Parent(pid) + } else { + Fork::Child(Pid::from_raw_unchecked(child_pid.assume_init())) + }) } #[cfg(feature = "fs")] @@ -167,6 +199,30 @@ pub(crate) unsafe fn sigprocmask(how: How, new: Option<&Sigset>) -> io::Result<S } #[inline] +pub(crate) fn sigpending() -> Sigset { + let mut pending = MaybeUninit::<Sigset>::uninit(); + unsafe { + ret_infallible(syscall!( + __NR_rt_sigpending, + &mut pending, + size_of::<kernel_sigset_t, _>() + )); + pending.assume_init() + } +} + +#[inline] +pub(crate) fn sigsuspend(set: &Sigset) -> io::Result<()> { + unsafe { + ret(syscall_readonly!( + __NR_rt_sigsuspend, + by_ref(set), + size_of::<kernel_sigset_t, _>() + )) + } +} + +#[inline] pub(crate) fn sigwait(set: &Sigset) -> io::Result<Signal> { unsafe { match Signal::from_raw(ret_c_int(syscall_readonly!( @@ -268,6 +324,6 @@ pub(crate) fn exit_group(code: c::c_int) -> ! { #[inline] pub(crate) unsafe fn brk(addr: *mut c::c_void) -> io::Result<*mut c_void> { - // Don't mark this `readonly`, so that loads don't get reordered past it. + // This is non-`readonly`, to prevent loads from being reordered past it. ret_void_star(syscall!(__NR_brk, addr)) } diff --git a/vendor/rustix/src/backend/linux_raw/termios/syscalls.rs b/vendor/rustix/src/backend/linux_raw/termios/syscalls.rs index d2fe91236..5a24c0a74 100644 --- a/vendor/rustix/src/backend/linux_raw/termios/syscalls.rs +++ b/vendor/rustix/src/backend/linux_raw/termios/syscalls.rs @@ -86,6 +86,14 @@ pub(crate) fn tcgetpgrp(fd: BorrowedFd<'_>) -> io::Result<Pid> { let mut result = MaybeUninit::<c::pid_t>::uninit(); ret(syscall!(__NR_ioctl, fd, c_uint(TIOCGPGRP), &mut result))?; let pid = result.assume_init(); + + // This doesn't appear to be documented, but it appears `tcsetpgrp` can + // succceed and set the pid to 0 if we pass it a pseudo-terminal device + // fd. For now, fail with `OPNOTSUPP`. + if pid == 0 { + return Err(io::Errno::OPNOTSUPP); + } + Ok(Pid::from_raw_unchecked(pid)) } } @@ -166,7 +174,7 @@ pub(crate) fn tcgetsid(fd: BorrowedFd<'_>) -> io::Result<Pid> { #[inline] pub(crate) fn tcsetwinsize(fd: BorrowedFd<'_>, winsize: Winsize) -> io::Result<()> { unsafe { - ret(syscall!( + ret(syscall_readonly!( __NR_ioctl, fd, c_uint(TIOCSWINSZ), @@ -177,7 +185,15 @@ pub(crate) fn tcsetwinsize(fd: BorrowedFd<'_>, winsize: Winsize) -> io::Result<( #[inline] pub(crate) fn tcsetpgrp(fd: BorrowedFd<'_>, pid: Pid) -> io::Result<()> { - unsafe { ret(syscall!(__NR_ioctl, fd, c_uint(TIOCSPGRP), pid)) } + let raw_pid: c::c_int = pid.as_raw_nonzero().get(); + unsafe { + ret(syscall_readonly!( + __NR_ioctl, + fd, + c_uint(TIOCSPGRP), + by_ref(&raw_pid) + )) + } } /// A wrapper around a conceptual `cfsetspeed` which handles an arbitrary diff --git a/vendor/rustix/src/backend/linux_raw/time/syscalls.rs b/vendor/rustix/src/backend/linux_raw/time/syscalls.rs index 27c3652a4..d20bcfac6 100644 --- a/vendor/rustix/src/backend/linux_raw/time/syscalls.rs +++ b/vendor/rustix/src/backend/linux_raw/time/syscalls.rs @@ -104,7 +104,7 @@ unsafe fn clock_settime_old(which_clock: ClockId, timespec: Timespec) -> io::Res #[cfg(feature = "time")] #[inline] pub(crate) fn timerfd_create(clockid: TimerfdClockId, flags: TimerfdFlags) -> io::Result<OwnedFd> { - unsafe { ret_owned_fd(syscall!(__NR_timerfd_create, clockid, flags)) } + unsafe { ret_owned_fd(syscall_readonly!(__NR_timerfd_create, clockid, flags)) } } #[cfg(feature = "time")] diff --git a/vendor/rustix/src/backend/linux_raw/time/types.rs b/vendor/rustix/src/backend/linux_raw/time/types.rs index f3e653b0a..c26812c5d 100644 --- a/vendor/rustix/src/backend/linux_raw/time/types.rs +++ b/vendor/rustix/src/backend/linux_raw/time/types.rs @@ -16,9 +16,11 @@ bitflags! { #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct TimerfdFlags: c::c_uint { /// `TFD_NONBLOCK` + #[doc(alias = "TFD_NONBLOCK")] const NONBLOCK = linux_raw_sys::general::TFD_NONBLOCK; /// `TFD_CLOEXEC` + #[doc(alias = "TFD_CLOEXEC")] const CLOEXEC = linux_raw_sys::general::TFD_CLOEXEC; /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags> @@ -34,9 +36,11 @@ bitflags! { #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct TimerfdTimerFlags: c::c_uint { /// `TFD_TIMER_ABSTIME` + #[doc(alias = "TFD_TIMER_ABSTIME")] const ABSTIME = linux_raw_sys::general::TFD_TIMER_ABSTIME; /// `TFD_TIMER_CANCEL_ON_SET` + #[doc(alias = "TFD_TIMER_CANCEL_ON_SET")] const CANCEL_ON_SET = linux_raw_sys::general::TFD_TIMER_CANCEL_ON_SET; /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags> @@ -57,6 +61,7 @@ pub enum TimerfdClockId { /// epoch, 1970-01-01T00:00:00Z. The clock is externally settable, so it is /// not monotonic. Successive reads may see decreasing times, so it isn't /// reliable for measuring durations. + #[doc(alias = "CLOCK_REALTIME")] Realtime = linux_raw_sys::general::CLOCK_REALTIME, /// `CLOCK_MONOTONIC`—A clock that tells an abstract time. @@ -67,12 +72,14 @@ pub enum TimerfdClockId { /// /// This clock does not advance while the system is suspended; see /// `Boottime` for a clock that does. + #[doc(alias = "CLOCK_MONOTONIC")] Monotonic = linux_raw_sys::general::CLOCK_MONOTONIC, /// `CLOCK_BOOTTIME`—Like `Monotonic`, but advances while suspended. /// /// This clock is similar to `Monotonic`, but does advance while the system /// is suspended. + #[doc(alias = "CLOCK_BOOTTIME")] Boottime = linux_raw_sys::general::CLOCK_BOOTTIME, /// `CLOCK_REALTIME_ALARM`—Like `Realtime`, but wakes a suspended system. @@ -80,6 +87,7 @@ pub enum TimerfdClockId { /// This clock is like `Realtime`, but can wake up a suspended system. /// /// Use of this clock requires the `CAP_WAKE_ALARM` Linux capability. + #[doc(alias = "CLOCK_REALTIME_ALARM")] RealtimeAlarm = linux_raw_sys::general::CLOCK_REALTIME_ALARM, /// `CLOCK_BOOTTIME_ALARM`—Like `Boottime`, but wakes a suspended system. @@ -87,5 +95,6 @@ pub enum TimerfdClockId { /// This clock is like `Boottime`, but can wake up a suspended system. /// /// Use of this clock requires the `CAP_WAKE_ALARM` Linux capability. + #[doc(alias = "CLOCK_BOOTTIME_ALARM")] BoottimeAlarm = linux_raw_sys::general::CLOCK_BOOTTIME_ALARM, } diff --git a/vendor/rustix/src/backend/linux_raw/vdso_wrappers.rs b/vendor/rustix/src/backend/linux_raw/vdso_wrappers.rs index 601dc1855..441738f8d 100644 --- a/vendor/rustix/src/backend/linux_raw/vdso_wrappers.rs +++ b/vendor/rustix/src/backend/linux_raw/vdso_wrappers.rs @@ -14,6 +14,14 @@ use super::reg::{ArgReg, RetReg, SyscallNumber, A0, A1, A2, A3, A4, A5, R0}; use super::vdso; #[cfg(target_arch = "x86")] use core::arch::global_asm; +#[cfg(feature = "process")] +#[cfg(any( + target_arch = "x86_64", + target_arch = "x86", + target_arch = "riscv64", + target_arch = "powerpc64" +))] +use core::ffi::c_void; use core::mem::transmute; use core::ptr::null_mut; use core::sync::atomic::AtomicPtr; @@ -21,14 +29,25 @@ use core::sync::atomic::Ordering::Relaxed; #[cfg(target_pointer_width = "32")] #[cfg(feature = "time")] use linux_raw_sys::general::timespec as __kernel_old_timespec; +#[cfg(any( + all( + feature = "process", + any( + target_arch = "x86_64", + target_arch = "x86", + target_arch = "riscv64", + target_arch = "powerpc64" + ) + ), + feature = "time" +))] +use {super::c, super::conv::ret, core::mem::MaybeUninit}; #[cfg(feature = "time")] use { - super::c, - super::conv::{c_int, ret}, + super::conv::c_int, crate::clockid::{ClockId, DynamicClockId}, crate::io, crate::timespec::Timespec, - core::mem::MaybeUninit, linux_raw_sys::general::{__kernel_clockid_t, __kernel_timespec}, }; @@ -67,14 +86,10 @@ pub(crate) fn clock_gettime_dynamic(which_clock: DynamicClockId<'_>) -> io::Resu ((!fd.as_raw_fd() << 3) | CLOCKFD) as __kernel_clockid_t } - DynamicClockId::RealtimeAlarm => { - linux_raw_sys::general::CLOCK_REALTIME_ALARM as __kernel_clockid_t - } - DynamicClockId::Tai => linux_raw_sys::general::CLOCK_TAI as __kernel_clockid_t, - DynamicClockId::Boottime => linux_raw_sys::general::CLOCK_BOOTTIME as __kernel_clockid_t, - DynamicClockId::BoottimeAlarm => { - linux_raw_sys::general::CLOCK_BOOTTIME_ALARM as __kernel_clockid_t - } + DynamicClockId::RealtimeAlarm => c::CLOCK_REALTIME_ALARM as __kernel_clockid_t, + DynamicClockId::Tai => c::CLOCK_TAI as __kernel_clockid_t, + DynamicClockId::Boottime => c::CLOCK_BOOTTIME as __kernel_clockid_t, + DynamicClockId::BoottimeAlarm => c::CLOCK_BOOTTIME_ALARM as __kernel_clockid_t, }; // SAFETY: `CLOCK_GETTIME` contains either null or the address of a @@ -96,6 +111,30 @@ pub(crate) fn clock_gettime_dynamic(which_clock: DynamicClockId<'_>) -> io::Resu } } +#[cfg(feature = "process")] +#[cfg(any( + target_arch = "x86_64", + target_arch = "x86", + target_arch = "riscv64", + target_arch = "powerpc64" +))] +#[inline] +pub(crate) fn sched_getcpu() -> usize { + // SAFETY: `GETCPU` contains either null or the address of a function with + // an ABI like libc `getcpu`, and calling it has the side effect of writing + // to the result buffers, and no others. + unsafe { + let mut cpu = MaybeUninit::<u32>::uninit(); + let callee = match transmute(GETCPU.load(Relaxed)) { + Some(callee) => callee, + None => init_getcpu(), + }; + let r0 = callee(cpu.as_mut_ptr(), null_mut(), null_mut()); + debug_assert_eq!(r0, 0); + cpu.assume_init() as usize + } +} + #[cfg(target_arch = "x86")] pub(super) mod x86_via_vdso { use super::{transmute, ArgReg, Relaxed, RetReg, SyscallNumber, A0, A1, A2, A3, A4, A5, R0}; @@ -223,6 +262,15 @@ pub(super) mod x86_via_vdso { #[cfg(feature = "time")] type ClockGettimeType = unsafe extern "C" fn(c::c_int, *mut Timespec) -> c::c_int; +#[cfg(feature = "process")] +#[cfg(any( + target_arch = "x86_64", + target_arch = "x86", + target_arch = "riscv64", + target_arch = "powerpc64" +))] +type GetcpuType = unsafe extern "C" fn(*mut u32, *mut u32, *mut c_void) -> c::c_int; + /// The underlying syscall functions are only called from asm, using the /// special syscall calling convention to pass arguments and return values, /// which the signature here doesn't reflect. @@ -239,6 +287,22 @@ fn init_clock_gettime() -> ClockGettimeType { unsafe { transmute(CLOCK_GETTIME.load(Relaxed)) } } +/// Initialize `GETCPU` and return its value. +#[cfg(feature = "process")] +#[cfg(any( + target_arch = "x86_64", + target_arch = "x86", + target_arch = "riscv64", + target_arch = "powerpc64" +))] +#[cold] +fn init_getcpu() -> GetcpuType { + init(); + // SAFETY: Load the function address from static storage that we just + // initialized. + unsafe { transmute(GETCPU.load(Relaxed)) } +} + /// Initialize `SYSCALL` and return its value. #[cfg(target_arch = "x86")] #[cold] @@ -254,6 +318,14 @@ fn init_syscall() -> SyscallType { struct Function; #[cfg(feature = "time")] static mut CLOCK_GETTIME: AtomicPtr<Function> = AtomicPtr::new(null_mut()); +#[cfg(feature = "process")] +#[cfg(any( + target_arch = "x86_64", + target_arch = "x86", + target_arch = "riscv64", + target_arch = "powerpc64" +))] +static mut GETCPU: AtomicPtr<Function> = AtomicPtr::new(null_mut()); #[cfg(target_arch = "x86")] static mut SYSCALL: AtomicPtr<Function> = AtomicPtr::new(null_mut()); @@ -315,6 +387,24 @@ unsafe fn _rustix_clock_gettime_via_syscall( ret(syscall!(__NR_clock_gettime, c_int(clockid), res)) } +#[cfg(feature = "process")] +#[cfg(any( + target_arch = "x86_64", + target_arch = "x86", + target_arch = "riscv64", + target_arch = "powerpc64" +))] +unsafe extern "C" fn rustix_getcpu_via_syscall( + cpu: *mut u32, + node: *mut u32, + unused: *mut c_void, +) -> c::c_int { + match ret(syscall!(__NR_getcpu, cpu, node, unused)) { + Ok(()) => 0, + Err(err) => err.raw_os_error().wrapping_neg(), + } +} + #[cfg(target_arch = "x86")] extern "C" { /// A symbol pointing to an `int 0x80` instruction. This “function” is only @@ -361,6 +451,24 @@ fn minimal_init() { .ok(); } + #[cfg(feature = "process")] + #[cfg(any( + target_arch = "x86_64", + target_arch = "x86", + target_arch = "riscv64", + target_arch = "powerpc64" + ))] + { + GETCPU + .compare_exchange( + null_mut(), + rustix_getcpu_via_syscall as *mut Function, + Relaxed, + Relaxed, + ) + .ok(); + } + #[cfg(target_arch = "x86")] { SYSCALL @@ -430,6 +538,60 @@ fn init() { } } + #[cfg(feature = "process")] + #[cfg(any( + target_arch = "x86_64", + target_arch = "x86", + target_arch = "riscv64", + target_arch = "powerpc64" + ))] + { + // Look up the platform-specific `getcpu` symbol as documented + // [here]. + // + // [here]: https://man7.org/linux/man-pages/man7/vdso.7.html + #[cfg(target_arch = "x86_64")] + let ptr = vdso.sym(cstr!("LINUX_2.6"), cstr!("__vdso_getcpu")); + #[cfg(target_arch = "x86")] + let ptr = vdso.sym(cstr!("LINUX_2.6"), cstr!("__vdso_getcpu")); + #[cfg(target_arch = "riscv64")] + let ptr = vdso.sym(cstr!("LINUX_4.15"), cstr!("__kernel_getcpu")); + #[cfg(target_arch = "powerpc64")] + let ptr = vdso.sym(cstr!("LINUX_2.6.15"), cstr!("__kernel_getcpu")); + + #[cfg(any( + target_arch = "x86_64", + target_arch = "riscv64", + target_arch = "powerpc64" + ))] + let ok = true; + + // On 32-bit x86, the symbol doesn't appear present sometimes. + #[cfg(target_arch = "x86")] + let ok = !ptr.is_null(); + + #[cfg(any( + target_arch = "aarch64", + target_arch = "arm", + target_arch = "mips", + target_arch = "mips32r6", + target_arch = "mips64", + target_arch = "mips64r6" + ))] + let ok = false; + + if ok { + assert!(!ptr.is_null()); + + // SAFETY: Store the computed function addresses in static + // storage so that we don't need to compute it again (but if + // we do, it doesn't hurt anything). + unsafe { + GETCPU.store(ptr.cast(), Relaxed); + } + } + } + // On x86, also look up the vsyscall entry point. #[cfg(target_arch = "x86")] { diff --git a/vendor/rustix/src/clockid.rs b/vendor/rustix/src/clockid.rs index 033444d9c..b392d6a14 100644 --- a/vendor/rustix/src/clockid.rs +++ b/vendor/rustix/src/clockid.rs @@ -11,18 +11,22 @@ use crate::fd::BorrowedFd; /// [`clock_gettime`]: crate::time::clock_gettime #[cfg(not(any(apple, target_os = "wasi")))] #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] -#[cfg_attr(not(target_os = "dragonfly"), repr(i32))] +#[cfg_attr(not(any(target_os = "aix", target_os = "dragonfly")), repr(i32))] #[cfg_attr(target_os = "dragonfly", repr(u64))] +#[cfg_attr(target_os = "aix", repr(i64))] #[non_exhaustive] pub enum ClockId { /// `CLOCK_REALTIME` + #[doc(alias = "CLOCK_REALTIME")] Realtime = bitcast!(c::CLOCK_REALTIME), /// `CLOCK_MONOTONIC` + #[doc(alias = "CLOCK_MONOTONIC")] Monotonic = bitcast!(c::CLOCK_MONOTONIC), /// `CLOCK_UPTIME` #[cfg(any(freebsdlike, target_os = "openbsd"))] + #[doc(alias = "CLOCK_UPTIME")] Uptime = c::CLOCK_UPTIME, /// `CLOCK_PROCESS_CPUTIME_ID` @@ -32,6 +36,7 @@ pub enum ClockId { target_os = "redox", target_os = "vita" )))] + #[doc(alias = "CLOCK_PROCESS_CPUTIME_ID")] ProcessCPUTime = c::CLOCK_PROCESS_CPUTIME_ID, /// `CLOCK_THREAD_CPUTIME_ID` @@ -41,19 +46,48 @@ pub enum ClockId { target_os = "redox", target_os = "vita" )))] + #[doc(alias = "CLOCK_THREAD_CPUTIME_ID")] ThreadCPUTime = c::CLOCK_THREAD_CPUTIME_ID, /// `CLOCK_REALTIME_COARSE` #[cfg(any(linux_kernel, target_os = "freebsd"))] + #[doc(alias = "CLOCK_REALTIME_COARSE")] RealtimeCoarse = c::CLOCK_REALTIME_COARSE, /// `CLOCK_MONOTONIC_COARSE` #[cfg(any(linux_kernel, target_os = "freebsd"))] + #[doc(alias = "CLOCK_MONOTONIC_COARSE")] MonotonicCoarse = c::CLOCK_MONOTONIC_COARSE, /// `CLOCK_MONOTONIC_RAW` #[cfg(linux_kernel)] + #[doc(alias = "CLOCK_MONOTONIC_RAW")] MonotonicRaw = c::CLOCK_MONOTONIC_RAW, + + /// `CLOCK_REALTIME_ALARM` + #[cfg(linux_kernel)] + #[doc(alias = "CLOCK_REALTIME_ALARM")] + RealtimeAlarm = bitcast!(c::CLOCK_REALTIME_ALARM), + + /// `CLOCK_TAI`, available on Linux >= 3.10 + #[cfg(all(linux_kernel, feature = "linux_4_11"))] + #[doc(alias = "CLOCK_TAI")] + Tai = bitcast!(c::CLOCK_TAI), + + /// `CLOCK_BOOTTIME` + /// + /// On FreeBSD, use [`Self::Uptime`], as `CLOCK_BOOTTIME` is an alias for + /// `CLOCK_UPTIME`. + /// + /// [`Self::Uptime`]: https://docs.rs/rustix/*/x86_64-unknown-freebsd/rustix/time/enum.ClockId.html#variant.Uptime + #[cfg(any(linux_kernel, target_os = "fuchsia", target_os = "openbsd"))] + #[doc(alias = "CLOCK_BOOTTIME")] + Boottime = bitcast!(c::CLOCK_BOOTTIME), + + /// `CLOCK_BOOTTIME_ALARM` + #[cfg(any(linux_kernel, target_os = "fuchsia"))] + #[doc(alias = "CLOCK_BOOTTIME_ALARM")] + BoottimeAlarm = bitcast!(c::CLOCK_BOOTTIME_ALARM), } /// `CLOCK_*` constants for use with [`clock_gettime`]. @@ -70,15 +104,19 @@ pub enum ClockId { #[non_exhaustive] pub enum ClockId { /// `CLOCK_REALTIME` + #[doc(alias = "CLOCK_REALTIME")] Realtime = c::CLOCK_REALTIME, /// `CLOCK_MONOTONIC` + #[doc(alias = "CLOCK_MONOTONIC")] Monotonic = c::CLOCK_MONOTONIC, /// `CLOCK_PROCESS_CPUTIME_ID` + #[doc(alias = "CLOCK_PROCESS_CPUTIME_ID")] ProcessCPUTime = c::CLOCK_PROCESS_CPUTIME_ID, /// `CLOCK_THREAD_CPUTIME_ID` + #[doc(alias = "CLOCK_THREAD_CPUTIME_ID")] ThreadCPUTime = c::CLOCK_THREAD_CPUTIME_ID, } @@ -99,24 +137,28 @@ pub enum DynamicClockId<'a> { /// Linux dynamic clocks. Dynamic(BorrowedFd<'a>), - /// `CLOCK_REALTIME_ALARM`, available on Linux >= 3.0 + /// `CLOCK_REALTIME_ALARM` #[cfg(linux_kernel)] + #[doc(alias = "CLOCK_REALTIME_ALARM")] RealtimeAlarm, /// `CLOCK_TAI`, available on Linux >= 3.10 #[cfg(linux_kernel)] + #[doc(alias = "CLOCK_TAI")] Tai, - /// `CLOCK_BOOTTIME`, available on Linux >= 2.6.39 + /// `CLOCK_BOOTTIME` #[cfg(any( freebsdlike, linux_kernel, target_os = "fuchsia", target_os = "openbsd" ))] + #[doc(alias = "CLOCK_BOOTTIME")] Boottime, - /// `CLOCK_BOOTTIME_ALARM`, available on Linux >= 2.6.39 + /// `CLOCK_BOOTTIME_ALARM` #[cfg(any(linux_kernel, target_os = "fuchsia"))] + #[doc(alias = "CLOCK_BOOTTIME_ALARM")] BoottimeAlarm, } diff --git a/vendor/rustix/src/event/mod.rs b/vendor/rustix/src/event/mod.rs index b0b62e0a6..b6b7f9971 100644 --- a/vendor/rustix/src/event/mod.rs +++ b/vendor/rustix/src/event/mod.rs @@ -9,6 +9,8 @@ mod eventfd; #[cfg(all(feature = "alloc", bsd))] pub mod kqueue; +#[cfg(not(any(windows, target_os = "redox", target_os = "wasi")))] +mod pause; mod poll; #[cfg(solarish)] pub mod port; @@ -22,4 +24,6 @@ pub use crate::backend::event::epoll; target_os = "espidf" ))] pub use eventfd::{eventfd, EventfdFlags}; +#[cfg(not(any(windows, target_os = "redox", target_os = "wasi")))] +pub use pause::*; pub use poll::{poll, PollFd, PollFlags}; diff --git a/vendor/rustix/src/event/pause.rs b/vendor/rustix/src/event/pause.rs new file mode 100644 index 000000000..f19108490 --- /dev/null +++ b/vendor/rustix/src/event/pause.rs @@ -0,0 +1,31 @@ +use crate::backend; + +/// `pause()` +/// +/// The POSIX `pause` interface returns an error code, but the only thing +/// `pause` does is sleep until interrupted by a signal, so it always +/// returns the same thing with the same error code, so in rustix, the +/// return value is omitted. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// - [Apple] +/// - [FreeBSD] +/// - [NetBSD] +/// - [OpenBSD] +/// - [DragonFly BSD] +/// - [illumos] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/pause.html +/// [Linux]: https://man7.org/linux/man-pages/man2/pause.2.html +/// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/pause.3.html +/// [FreeBSD]: https://man.freebsd.org/cgi/man.cgi?query=pause&sektion=3 +/// [NetBSD]: https://man.netbsd.org/pause.3 +/// [OpenBSD]: https://man.openbsd.org/pause.3 +/// [DragonFly BSD]: https://man.dragonflybsd.org/?command=pause§ion=3 +/// [illumos]: https://illumos.org/man/2/pause +#[inline] +pub fn pause() { + backend::event::syscalls::pause() +} diff --git a/vendor/rustix/src/fs/abs.rs b/vendor/rustix/src/fs/abs.rs index 8953f351e..fb6c8c338 100644 --- a/vendor/rustix/src/fs/abs.rs +++ b/vendor/rustix/src/fs/abs.rs @@ -269,10 +269,10 @@ pub fn statfs<P: path::Arg>(path: P) -> io::Result<StatFs> { /// `statvfs`—Queries filesystem metadata, POSIX version. /// -/// Compared to [`statfs`], this function often provides less information, -/// but it is more portable. But even so, filesystems are very diverse and not -/// all the fields are meaningful for every filesystem. And `f_fsid` doesn't -/// seem to have a clear meaning anywhere. +/// Compared to [`statfs`], this function often provides less information, but +/// it is more portable. But even so, filesystems are very diverse and not all +/// the fields are meaningful for every filesystem. And `f_fsid` doesn't seem +/// to have a clear meaning anywhere. /// /// # References /// - [POSIX] diff --git a/vendor/rustix/src/fs/at.rs b/vendor/rustix/src/fs/at.rs index f40c46ce6..4163692d1 100644 --- a/vendor/rustix/src/fs/at.rs +++ b/vendor/rustix/src/fs/at.rs @@ -6,6 +6,7 @@ //! [`cwd`]: crate::fs::CWD use crate::fd::OwnedFd; +use crate::ffi::CStr; #[cfg(not(any(target_os = "espidf", target_os = "vita")))] use crate::fs::Access; #[cfg(not(target_os = "espidf"))] @@ -14,7 +15,7 @@ use crate::fs::AtFlags; use crate::fs::CloneFlags; #[cfg(linux_kernel)] use crate::fs::RenameFlags; -#[cfg(not(any(target_os = "aix", target_os = "espidf")))] +#[cfg(not(target_os = "espidf"))] use crate::fs::Stat; #[cfg(not(any(apple, target_os = "espidf", target_os = "vita", target_os = "wasi")))] use crate::fs::{Dev, FileType}; @@ -22,14 +23,11 @@ use crate::fs::{Dev, FileType}; use crate::fs::{Gid, Uid}; use crate::fs::{Mode, OFlags}; use crate::{backend, io, path}; -use backend::fd::AsFd; +use backend::fd::{AsFd, BorrowedFd}; +use core::mem::MaybeUninit; +use core::slice; #[cfg(feature = "alloc")] -use { - crate::ffi::{CStr, CString}, - crate::path::SMALL_PATH_BUFFER_SIZE, - alloc::vec::Vec, - backend::fd::BorrowedFd, -}; +use {crate::ffi::CString, crate::path::SMALL_PATH_BUFFER_SIZE, alloc::vec::Vec}; #[cfg(not(any(target_os = "espidf", target_os = "vita")))] use {crate::fs::Timestamps, crate::timespec::Nsecs}; @@ -134,6 +132,48 @@ fn _readlinkat(dirfd: BorrowedFd<'_>, path: &CStr, mut buffer: Vec<u8>) -> io::R } } +/// `readlinkat(fd, path)`—Reads the contents of a symlink, without +/// allocating. +/// +/// This is the "raw" version which avoids allocating, but which is +/// significantly trickier to use; most users should use plain [`readlinkat`]. +/// +/// This version writes bytes into the buffer and returns two slices, one +/// containing the written bytes, and one containint the remaining +/// uninitialized space. If the number of written bytes is equal to the length +/// of the buffer, it means the buffer wasn't big enough to hold the full +/// string, and callers should try again with a bigger buffer. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/readlinkat.html +/// [Linux]: https://man7.org/linux/man-pages/man2/readlinkat.2.html +#[inline] +pub fn readlinkat_raw<P: path::Arg, Fd: AsFd>( + dirfd: Fd, + path: P, + buf: &mut [MaybeUninit<u8>], +) -> io::Result<(&mut [u8], &mut [MaybeUninit<u8>])> { + path.into_with_c_str(|path| _readlinkat_raw(dirfd.as_fd(), path, buf)) +} + +#[allow(unsafe_code)] +fn _readlinkat_raw<'a>( + dirfd: BorrowedFd<'_>, + path: &CStr, + buf: &'a mut [MaybeUninit<u8>], +) -> io::Result<(&'a mut [u8], &'a mut [MaybeUninit<u8>])> { + let n = backend::fs::syscalls::readlinkat(dirfd.as_fd(), path, buf)?; + unsafe { + Ok(( + slice::from_raw_parts_mut(buf.as_mut_ptr().cast::<u8>(), n), + &mut buf[n..], + )) + } +} + /// `mkdirat(fd, path, mode)`—Creates a directory. /// /// # References @@ -288,8 +328,7 @@ pub fn symlinkat<P: path::Arg, Q: path::Arg, Fd: AsFd>( /// [Linux]: https://man7.org/linux/man-pages/man2/fstatat.2.html /// [`Mode::from_raw_mode`]: crate::fs::Mode::from_raw_mode /// [`FileType::from_raw_mode`]: crate::fs::FileType::from_raw_mode -// TODO: Add `stat64xat` to upstream libc bindings and reenable this for AIX. -#[cfg(not(any(target_os = "aix", target_os = "espidf")))] +#[cfg(not(target_os = "espidf"))] #[inline] #[doc(alias = "fstatat")] pub fn statat<P: path::Arg, Fd: AsFd>(dirfd: Fd, path: P, flags: AtFlags) -> io::Result<Stat> { diff --git a/vendor/rustix/src/fs/memfd_create.rs b/vendor/rustix/src/fs/memfd_create.rs index 83d1ff51e..97154d208 100644 --- a/vendor/rustix/src/fs/memfd_create.rs +++ b/vendor/rustix/src/fs/memfd_create.rs @@ -2,7 +2,7 @@ use crate::fd::OwnedFd; use crate::{backend, io, path}; use backend::fs::types::MemfdFlags; -/// `memfd_create(path, flags)` +/// `memfd_create(name, flags)` /// /// # References /// - [Linux] @@ -13,6 +13,6 @@ use backend::fs::types::MemfdFlags; /// [glibc]: https://www.gnu.org/software/libc/manual/html_node/Memory_002dmapped-I_002fO.html#index-memfd_005fcreate /// [FreeBSD]: https://man.freebsd.org/cgi/man.cgi?memfd_create #[inline] -pub fn memfd_create<P: path::Arg>(path: P, flags: MemfdFlags) -> io::Result<OwnedFd> { - path.into_with_c_str(|path| backend::fs::syscalls::memfd_create(path, flags)) +pub fn memfd_create<P: path::Arg>(name: P, flags: MemfdFlags) -> io::Result<OwnedFd> { + name.into_with_c_str(|name| backend::fs::syscalls::memfd_create(name, flags)) } diff --git a/vendor/rustix/src/io/fcntl.rs b/vendor/rustix/src/io/fcntl.rs index 1880ac7db..31eb84cef 100644 --- a/vendor/rustix/src/io/fcntl.rs +++ b/vendor/rustix/src/io/fcntl.rs @@ -105,8 +105,8 @@ pub fn fcntl_dupfd_cloexec<Fd: AsFd>(fd: Fd, min: RawFd) -> io::Result<OwnedFd> backend::io::syscalls::fcntl_dupfd_cloexec(fd.as_fd(), min) } -/// `fcntl(fd, F_DUPFD)`—Creates a new `OwnedFd` instance, with value at least -/// `min`, that shares the same underlying [file description] as `fd`. +/// `fcntl(fd, F_DUPFD)`—Creates a new `OwnedFd` instance, with value at +/// least `min`, that shares the same underlying [file description] as `fd`. /// /// POSIX guarantees that `F_DUPFD` will use the lowest unused file descriptor /// which is at least `min`, however it is not safe in general to rely on this, diff --git a/vendor/rustix/src/ioctl/bsd.rs b/vendor/rustix/src/ioctl/bsd.rs index 66b75b54b..2639d81fc 100644 --- a/vendor/rustix/src/ioctl/bsd.rs +++ b/vendor/rustix/src/ioctl/bsd.rs @@ -1,4 +1,4 @@ -//! `ioctl` opcode behavior for Linux platforms. +//! `ioctl` opcode behavior for BSD platforms. use super::{Direction, RawOpcode}; @@ -18,7 +18,10 @@ pub(super) const fn compose_opcode( dir | num | (group << 8) | ((size & IOCPARAM_MASK) << 16) } +// `IOC_VOID` pub const NONE: RawOpcode = 0x2000_0000; -pub const WRITE: RawOpcode = 0x4000_0000; -pub const READ: RawOpcode = 0x8000_0000; +// `IOC_OUT` ("out" is from the perspective of the kernel) +pub const READ: RawOpcode = 0x4000_0000; +// `IOC_IN` +pub const WRITE: RawOpcode = 0x8000_0000; pub const IOCPARAM_MASK: RawOpcode = 0x1FFF; diff --git a/vendor/rustix/src/ioctl/mod.rs b/vendor/rustix/src/ioctl/mod.rs index ce62d75c4..b56b82b41 100644 --- a/vendor/rustix/src/ioctl/mod.rs +++ b/vendor/rustix/src/ioctl/mod.rs @@ -65,15 +65,14 @@ use bsd as platform; /// `ioctl` call is safe to make. /// /// # References -/// -/// - [Linux] -/// - [WinSock2] -/// - [FreeBSD] -/// - [NetBSD] -/// - [OpenBSD] -/// - [Apple] -/// - [Solaris] -/// - [illumos] +/// - [Linux] +/// - [WinSock2] +/// - [FreeBSD] +/// - [NetBSD] +/// - [OpenBSD] +/// - [Apple] +/// - [Solaris] +/// - [illumos] /// /// [Linux]: https://man7.org/linux/man-pages/man2/ioctl.2.html /// [Winsock2]: https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-ioctlsocket diff --git a/vendor/rustix/src/ioctl/patterns.rs b/vendor/rustix/src/ioctl/patterns.rs index 7bc5c4e86..6cf7ebd61 100644 --- a/vendor/rustix/src/ioctl/patterns.rs +++ b/vendor/rustix/src/ioctl/patterns.rs @@ -153,6 +153,50 @@ unsafe impl<Opcode: CompileTimeOpcode, Input> Ioctl for Setter<Opcode, Input> { } } +/// Implements an “updater” pattern for `ioctl`s. +/// +/// The ioctl takes a reference to a struct that it reads its input from, +/// then writes output to the same struct. +pub struct Updater<'a, Opcode, Value> { + /// Reference to input/output data. + value: &'a mut Value, + + /// The opcode. + _opcode: PhantomData<Opcode>, +} + +impl<'a, Opcode: CompileTimeOpcode, Value> Updater<'a, Opcode, Value> { + /// Create a new pointer updater-style `ioctl` object. + /// + /// # Safety + /// + /// - `Opcode` must provide a valid opcode. + /// - For this opcode, `Value` must be the type that the kernel expects to + /// get. + #[inline] + pub unsafe fn new(value: &'a mut Value) -> Self { + Self { + value, + _opcode: PhantomData, + } + } +} + +unsafe impl<'a, Opcode: CompileTimeOpcode, T> Ioctl for Updater<'a, Opcode, T> { + type Output = (); + + const IS_MUTATING: bool = true; + const OPCODE: self::Opcode = Opcode::OPCODE; + + fn as_ptr(&mut self) -> *mut c::c_void { + (self.value as *mut T).cast() + } + + unsafe fn output_from_ptr(_output: IoctlOutput, _ptr: *mut c::c_void) -> Result<()> { + Ok(()) + } +} + /// Trait for something that provides an `ioctl` opcode at compile time. pub trait CompileTimeOpcode { /// The opcode. diff --git a/vendor/rustix/src/lib.rs b/vendor/rustix/src/lib.rs index 03f37d96e..170e3f958 100644 --- a/vendor/rustix/src/lib.rs +++ b/vendor/rustix/src/lib.rs @@ -305,6 +305,7 @@ pub(crate) mod mount; not(feature = "use-explicitly-provided-auxv"), any( feature = "param", + feature = "process", feature = "runtime", feature = "time", target_arch = "x86", @@ -322,6 +323,7 @@ pub(crate) mod fs; not(feature = "use-explicitly-provided-auxv"), any( feature = "param", + feature = "process", feature = "runtime", feature = "time", target_arch = "x86", @@ -353,6 +355,7 @@ mod signal; #[cfg(not(windows))] #[cfg(any( feature = "fs", + feature = "process", feature = "runtime", feature = "thread", feature = "time", @@ -362,6 +365,7 @@ mod signal; not(feature = "use-explicitly-provided-auxv"), any( feature = "param", + feature = "process", feature = "runtime", feature = "time", target_arch = "x86", diff --git a/vendor/rustix/src/mm/mmap.rs b/vendor/rustix/src/mm/mmap.rs index 22137a930..3f6523fde 100644 --- a/vendor/rustix/src/mm/mmap.rs +++ b/vendor/rustix/src/mm/mmap.rs @@ -157,8 +157,8 @@ pub unsafe fn munmap(ptr: *mut c_void, len: usize) -> io::Result<()> { backend::mm::syscalls::munmap(ptr, len) } -/// `mremap(old_address, old_size, new_size, flags)`—Resize, modify, -/// and/or move a memory mapping. +/// `mremap(old_address, old_size, new_size, flags)`—Resize, modify, and/or +/// move a memory mapping. /// /// For moving a mapping to a fixed address (`MREMAP_FIXED`), see /// [`mremap_fixed`]. diff --git a/vendor/rustix/src/net/send_recv/msg.rs b/vendor/rustix/src/net/send_recv/msg.rs index ea91cbfec..78fb8654c 100644 --- a/vendor/rustix/src/net/send_recv/msg.rs +++ b/vendor/rustix/src/net/send_recv/msg.rs @@ -17,7 +17,34 @@ use core::{ptr, slice}; use super::{RecvFlags, SendFlags, SocketAddrAny, SocketAddrV4, SocketAddrV6}; -/// Macro for defining the amount of space used by CMSGs. +/// Macro for defining the amount of space to allocate in a buffer for use with +/// [`RecvAncillaryBuffer::new`] and [`SendAncillaryBuffer::new`]. +/// +/// # Examples +/// +/// Allocate a buffer for a single file descriptor: +/// ``` +/// # use rustix::cmsg_space; +/// let mut space = [0; rustix::cmsg_space!(ScmRights(1))]; +/// ``` +/// +/// Allocate a buffer for credentials: +/// ``` +/// # #[cfg(linux_kernel)] +/// # { +/// # use rustix::cmsg_space; +/// let mut space = [0; rustix::cmsg_space!(ScmCredentials(1))]; +/// # } +/// ``` +/// +/// Allocate a buffer for two file descriptors and credentials: +/// ``` +/// # #[cfg(linux_kernel)] +/// # { +/// # use rustix::cmsg_space; +/// let mut space = [0; rustix::cmsg_space!(ScmRights(2), ScmCredentials(1))]; +/// # } +/// ``` #[macro_export] macro_rules! cmsg_space { // Base Rules @@ -33,12 +60,41 @@ macro_rules! cmsg_space { }; // Combo Rules - (($($($x:tt)*),+)) => { + ($firstid:ident($firstex:expr), $($restid:ident($restex:expr)),*) => {{ + // We only have to add `cmsghdr` alignment once; all other times we can + // use `cmsg_aligned_space`. + let sum = $crate::cmsg_space!($firstid($firstex)); $( - cmsg_space!($($x)*) + - )+ - 0 + let sum = sum + $crate::cmsg_aligned_space!($restid($restex)); + )* + sum + }}; +} + +/// Like `cmsg_space`, but doesn't add padding for `cmsghdr` alignment. +#[doc(hidden)] +#[macro_export] +macro_rules! cmsg_aligned_space { + // Base Rules + (ScmRights($len:expr)) => { + $crate::net::__cmsg_aligned_space( + $len * ::core::mem::size_of::<$crate::fd::BorrowedFd<'static>>(), + ) + }; + (ScmCredentials($len:expr)) => { + $crate::net::__cmsg_aligned_space( + $len * ::core::mem::size_of::<$crate::net::UCred>(), + ) }; + + // Combo Rules + ($firstid:ident($firstex:expr), $($restid:ident($restex:expr)),*) => {{ + let sum = cmsg_aligned_space!($firstid($firstex)); + $( + let sum = sum + cmsg_aligned_space!($restid($restex)); + )* + sum + }}; } #[doc(hidden)] @@ -47,6 +103,11 @@ pub const fn __cmsg_space(len: usize) -> usize { // `&[u8]` to the required alignment boundary. let len = len + align_of::<c::cmsghdr>(); + __cmsg_aligned_space(len) +} + +#[doc(hidden)] +pub const fn __cmsg_aligned_space(len: usize) -> usize { // Convert `len` to `u32` for `CMSG_SPACE`. This would be `try_into()` if // we could call that in a `const fn`. let converted_len = len as u32; @@ -97,6 +158,10 @@ pub enum RecvAncillaryMessage<'a> { /// Buffer for sending ancillary messages with [`sendmsg`], [`sendmsg_v4`], /// [`sendmsg_v6`], [`sendmsg_unix`], and [`sendmsg_any`]. +/// +/// Use the [`push`] function to add messages to send. +/// +/// [`push`]: SendAncillaryBuffer::push pub struct SendAncillaryBuffer<'buf, 'slice, 'fd> { /// Raw byte buffer for messages. buffer: &'buf mut [u8], @@ -126,6 +191,44 @@ impl Default for SendAncillaryBuffer<'_, '_, '_> { impl<'buf, 'slice, 'fd> SendAncillaryBuffer<'buf, 'slice, 'fd> { /// Create a new, empty `SendAncillaryBuffer` from a raw byte buffer. + /// + /// The buffer size may be computed with [`cmsg_space`], or it may be + /// zero for an empty buffer, however in that case, consider `default()` + /// instead, or even using [`send`] instead of `sendmsg`. + /// + /// # Examples + /// + /// Allocate a buffer for a single file descriptor: + /// ``` + /// # use rustix::cmsg_space; + /// # use rustix::net::SendAncillaryBuffer; + /// let mut space = [0; rustix::cmsg_space!(ScmRights(1))]; + /// let mut cmsg_buffer = SendAncillaryBuffer::new(&mut space); + /// ``` + /// + /// Allocate a buffer for credentials: + /// ``` + /// # #[cfg(linux_kernel)] + /// # { + /// # use rustix::cmsg_space; + /// # use rustix::net::SendAncillaryBuffer; + /// let mut space = [0; rustix::cmsg_space!(ScmCredentials(1))]; + /// let mut cmsg_buffer = SendAncillaryBuffer::new(&mut space); + /// # } + /// ``` + /// + /// Allocate a buffer for two file descriptors and credentials: + /// ``` + /// # #[cfg(linux_kernel)] + /// # { + /// # use rustix::cmsg_space; + /// # use rustix::net::SendAncillaryBuffer; + /// let mut space = [0; rustix::cmsg_space!(ScmRights(2), ScmCredentials(1))]; + /// let mut cmsg_buffer = SendAncillaryBuffer::new(&mut space); + /// # } + /// ``` + /// + /// [`send`]: crate::net::send #[inline] pub fn new(buffer: &'buf mut [u8]) -> Self { Self { @@ -229,6 +332,10 @@ impl<'slice, 'fd> Extend<SendAncillaryMessage<'slice, 'fd>> } /// Buffer for receiving ancillary messages with [`recvmsg`]. +/// +/// Use the [`drain`] function to iterate over the received messages. +/// +/// [`drain`]: RecvAncillaryBuffer::drain #[derive(Default)] pub struct RecvAncillaryBuffer<'buf> { /// Raw byte buffer for messages. @@ -249,6 +356,44 @@ impl<'buf> From<&'buf mut [u8]> for RecvAncillaryBuffer<'buf> { impl<'buf> RecvAncillaryBuffer<'buf> { /// Create a new, empty `RecvAncillaryBuffer` from a raw byte buffer. + /// + /// The buffer size may be computed with [`cmsg_space`], or it may be + /// zero for an empty buffer, however in that case, consider `default()` + /// instead, or even using [`recv`] instead of `recvmsg`. + /// + /// # Examples + /// + /// Allocate a buffer for a single file descriptor: + /// ``` + /// # use rustix::cmsg_space; + /// # use rustix::net::RecvAncillaryBuffer; + /// let mut space = [0; rustix::cmsg_space!(ScmRights(1))]; + /// let mut cmsg_buffer = RecvAncillaryBuffer::new(&mut space); + /// ``` + /// + /// Allocate a buffer for credentials: + /// ``` + /// # #[cfg(linux_kernel)] + /// # { + /// # use rustix::cmsg_space; + /// # use rustix::net::RecvAncillaryBuffer; + /// let mut space = [0; rustix::cmsg_space!(ScmCredentials(1))]; + /// let mut cmsg_buffer = RecvAncillaryBuffer::new(&mut space); + /// # } + /// ``` + /// + /// Allocate a buffer for two file descriptors and credentials: + /// ``` + /// # #[cfg(linux_kernel)] + /// # { + /// # use rustix::cmsg_space; + /// # use rustix::net::RecvAncillaryBuffer; + /// let mut space = [0; rustix::cmsg_space!(ScmRights(2), ScmCredentials(1))]; + /// let mut cmsg_buffer = RecvAncillaryBuffer::new(&mut space); + /// # } + /// ``` + /// + /// [`recv`]: crate::net::recv #[inline] pub fn new(buffer: &'buf mut [u8]) -> Self { Self { @@ -311,6 +456,12 @@ impl Drop for RecvAncillaryBuffer<'_> { /// boundary. #[inline] fn align_for_cmsghdr(buffer: &mut [u8]) -> &mut [u8] { + // If the buffer is empty, we won't be writing anything into it, so it + // doesn't need to be aligned. + if buffer.is_empty() { + return buffer; + } + let align = align_of::<c::cmsghdr>(); let addr = buffer.as_ptr() as usize; let adjusted = (addr + (align - 1)) & align.wrapping_neg(); diff --git a/vendor/rustix/src/net/types.rs b/vendor/rustix/src/net/types.rs index 711174354..ad60e36cb 100644 --- a/vendor/rustix/src/net/types.rs +++ b/vendor/rustix/src/net/types.rs @@ -69,7 +69,7 @@ impl AddressFamily { /// # References /// - [Linux] /// - /// [Linux]: https://man7.org/linux/man-pages/man7/ip.7.html> + /// [Linux]: https://man7.org/linux/man-pages/man7/ip.7.html pub const INET: Self = Self(c::AF_INET as _); /// `AF_INET6` /// diff --git a/vendor/rustix/src/pipe.rs b/vendor/rustix/src/pipe.rs index 5f0175c85..b0a978385 100644 --- a/vendor/rustix/src/pipe.rs +++ b/vendor/rustix/src/pipe.rs @@ -116,10 +116,10 @@ pub fn pipe_with(flags: PipeFlags) -> io::Result<(OwnedFd, OwnedFd)> { /// `fd_in` to the file descriptor `fd_out`, where one of the file descriptors /// must refer to a pipe. /// -/// `off_*` must be `None` if the corresponding fd refers to a pipe. -/// Otherwise its value points to the starting offset to the file, from which -/// the data is read/written. On success, the number of bytes read/written is -/// added to the offset. +/// `off_*` must be `None` if the corresponding fd refers to a pipe. Otherwise +/// its value points to the starting offset to the file, from which the data is +/// read/written. On success, the number of bytes read/written is added to the +/// offset. /// /// Passing `None` causes the read/write to start from the file offset, and the /// file offset is adjusted appropriately. @@ -143,11 +143,11 @@ pub fn splice<FdIn: AsFd, FdOut: AsFd>( /// `vmsplice(fd, bufs, flags)`—Transfer data between memory and a pipe. /// -/// If `fd` is the write end of the pipe, -/// the function maps the memory pointer at by `bufs` to the pipe. +/// If `fd` is the write end of the pipe, the function maps the memory pointer +/// at by `bufs` to the pipe. /// -/// If `fd` is the read end of the pipe, -/// the function writes data from the pipe to said memory. +/// If `fd` is the read end of the pipe, the function writes data from the pipe +/// to said memory. /// /// # Safety /// diff --git a/vendor/rustix/src/process/mod.rs b/vendor/rustix/src/process/mod.rs index 195216c3a..5fbc1f3b7 100644 --- a/vendor/rustix/src/process/mod.rs +++ b/vendor/rustix/src/process/mod.rs @@ -32,7 +32,7 @@ mod procctl; target_os = "wasi" )))] mod rlimit; -#[cfg(any(linux_kernel, target_os = "dragonfly", target_os = "fuchsia"))] +#[cfg(any(freebsdlike, linux_kernel, target_os = "fuchsia"))] mod sched; mod sched_yield; #[cfg(not(target_os = "wasi"))] // WASI doesn't have umask. @@ -71,7 +71,7 @@ pub use procctl::*; target_os = "wasi" )))] pub use rlimit::*; -#[cfg(any(linux_kernel, target_os = "dragonfly", target_os = "fuchsia"))] +#[cfg(any(freebsdlike, linux_kernel, target_os = "fuchsia"))] pub use sched::*; pub use sched_yield::sched_yield; #[cfg(not(target_os = "wasi"))] diff --git a/vendor/rustix/src/process/sched.rs b/vendor/rustix/src/process/sched.rs index b7dcd58cc..d6a303af5 100644 --- a/vendor/rustix/src/process/sched.rs +++ b/vendor/rustix/src/process/sched.rs @@ -108,3 +108,18 @@ pub fn sched_getaffinity(pid: Option<Pid>) -> io::Result<CpuSet> { let mut cpuset = CpuSet::new(); backend::process::syscalls::sched_getaffinity(pid, &mut cpuset.cpu_set).and(Ok(cpuset)) } + +/// `sched_getcpu()`—Get the CPU that the current thread is currently on. +/// +/// # References +/// - [Linux] +/// - [DragonFly BSD] +/// +/// [Linux]: https://man7.org/linux/man-pages/man2/sched_getcpu.2.html +/// [DragonFly BSD]: https://man.dragonflybsd.org/?command=sched_getcpu§ion=2 +// FreeBSD added `sched_getcpu` in 13.0. +#[cfg(any(linux_kernel, target_os = "dragonfly"))] +#[inline] +pub fn sched_getcpu() -> usize { + backend::process::syscalls::sched_getcpu() +} diff --git a/vendor/rustix/src/process/wait.rs b/vendor/rustix/src/process/wait.rs index ccb90ae43..4d0e6e25d 100644 --- a/vendor/rustix/src/process/wait.rs +++ b/vendor/rustix/src/process/wait.rs @@ -37,7 +37,7 @@ bitflags! { /// Return immediately if no child has exited. const NOHANG = bitcast!(backend::process::wait::WNOHANG); /// Return if a stopped child has been resumed by delivery of - /// [`Signal::Cont`] + /// [`Signal::Cont`]. const CONTINUED = bitcast!(backend::process::wait::WCONTINUED); /// Wait for processed that have exited. const EXITED = bitcast!(backend::process::wait::WEXITED); diff --git a/vendor/rustix/src/procfs.rs b/vendor/rustix/src/procfs.rs index fb35a2028..38f091197 100644 --- a/vendor/rustix/src/procfs.rs +++ b/vendor/rustix/src/procfs.rs @@ -226,8 +226,8 @@ fn is_mountpoint(file: BorrowedFd<'_>) -> bool { /// Open a directory in `/proc`, mapping all errors to `io::Errno::NOTSUP`. fn proc_opendirat<P: crate::path::Arg, Fd: AsFd>(dirfd: Fd, path: P) -> io::Result<OwnedFd> { - // We could add `PATH`|`NOATIME` here but Linux 2.6.32 doesn't support it. - // Also for `NOATIME` see the comment in `open_and_check_file`. + // We don't add `PATH` here because that disables `DIRECTORY`. And we don't + // add `NOATIME` for the same reason as the comment in `open_and_check_file`. let oflags = OFlags::NOFOLLOW | OFlags::DIRECTORY | OFlags::CLOEXEC | OFlags::NOCTTY; openat(dirfd, path, oflags, Mode::empty()).map_err(|_err| io::Errno::NOTSUP) } diff --git a/vendor/rustix/src/runtime.rs b/vendor/rustix/src/runtime.rs index 3c754a62f..18315db64 100644 --- a/vendor/rustix/src/runtime.rs +++ b/vendor/rustix/src/runtime.rs @@ -229,6 +229,19 @@ pub fn entry() -> usize { backend::param::auxv::entry() } +/// `getauxval(AT_RANDOM)`—Returns the address of 16 pseudorandom bytes. +/// +/// These bytes are for use by libc. For anything else, use the `rand` crate. +/// +/// # References +/// - [Linux] +/// +/// [Linux]: https://man7.org/linux/man-pages/man3/getauxval.3.html +#[inline] +pub fn random() -> *const [u8; 16] { + backend::param::auxv::random() +} + #[cfg(linux_raw)] pub use backend::runtime::tls::StartupTlsInfo; @@ -315,10 +328,18 @@ pub use backend::runtime::tls::StartupTlsInfo; /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/fork.html /// [Linux]: https://man7.org/linux/man-pages/man2/fork.2.html /// [async-signal-safe]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_04_03 -pub unsafe fn fork() -> io::Result<Option<Pid>> { +pub unsafe fn fork() -> io::Result<Fork> { backend::runtime::syscalls::fork() } +/// Regular Unix `fork` doesn't tell the child its own PID because it assumes +/// the child can just do `getpid`. That's true, but it's more fun if it +/// doesn't have to. +pub enum Fork { + Child(Pid), + Parent(Pid), +} + /// `execveat(dirfd, path.as_c_str(), argv, envp, flags)`—Execute a new /// command using the current process. /// @@ -435,6 +456,28 @@ pub unsafe fn sigprocmask(how: How, set: Option<&Sigset>) -> io::Result<Sigset> backend::runtime::syscalls::sigprocmask(how, set) } +/// `sigpending()`—Query the pending signals. +/// +/// # References +/// - [Linux `sigpending`] +/// +/// [Linux `sigpending`]: https://man7.org/linux/man-pages/man2/sigpending.2.html +#[inline] +pub fn sigpending() -> Sigset { + backend::runtime::syscalls::sigpending() +} + +/// `sigsuspend(set)`—Suspend the calling thread and wait for signals. +/// +/// # References +/// - [Linux `sigsuspend`] +/// +/// [Linux `sigsuspend`]: https://man7.org/linux/man-pages/man2/sigsuspend.2.html +#[inline] +pub fn sigsuspend(set: &Sigset) -> io::Result<()> { + backend::runtime::syscalls::sigsuspend(set) +} + /// `sigwait(set)`—Wait for signals. /// /// # Safety @@ -452,7 +495,7 @@ pub unsafe fn sigwait(set: &Sigset) -> io::Result<Signal> { backend::runtime::syscalls::sigwait(set) } -/// `sigwait(set)`—Wait for signals, returning a [`Siginfo`]. +/// `sigwaitinfo(set)`—Wait for signals, returning a [`Siginfo`]. /// /// # Safety /// @@ -493,7 +536,8 @@ pub unsafe fn sigtimedwait(set: &Sigset, timeout: Option<Timespec>) -> io::Resul /// whether the `AT_SECURE` AUX value is set, and whether the initial real UID /// and GID differ from the initial effective UID and GID. /// -/// The meaning of “secure execution” mode is beyond the scope of this comment. +/// The meaning of “secure execution” mode is beyond the scope of this +/// comment. /// /// # References /// - [Linux] @@ -523,3 +567,31 @@ pub fn linux_secure() -> bool { pub unsafe fn brk(addr: *mut c_void) -> io::Result<*mut c_void> { backend::runtime::syscalls::brk(addr) } + +/// `__SIGRTMIN`—The start of the realtime signal range. +/// +/// This is the raw `SIGRTMIN` value from the OS, which is not the same as the +/// `SIGRTMIN` macro provided by libc. Don't use this unless you are +/// implementing libc. +#[cfg(linux_raw)] +pub const SIGRTMIN: u32 = linux_raw_sys::general::SIGRTMIN; + +/// `__SIGRTMAX`—The last of the realtime signal range. +/// +/// This is the raw `SIGRTMAX` value from the OS, which is not the same as the +/// `SIGRTMAX` macro provided by libc. Don't use this unless you are +/// implementing libc. +#[cfg(linux_raw)] +pub const SIGRTMAX: u32 = { + // Use the actual `SIGRTMAX` value on platforms which define it. + #[cfg(not(any(target_arch = "arm", target_arch = "x86", target_arch = "x86_64")))] + { + linux_raw_sys::general::SIGRTMAX + } + + // On platfoms that don't, derive it from `_NSIG`. + #[cfg(any(target_arch = "arm", target_arch = "x86", target_arch = "x86_64"))] + { + linux_raw_sys::general::_NSIG - 1 + } +}; diff --git a/vendor/rustix/src/termios/tc.rs b/vendor/rustix/src/termios/tc.rs index cd5902c1a..58ba2c220 100644 --- a/vendor/rustix/src/termios/tc.rs +++ b/vendor/rustix/src/termios/tc.rs @@ -1,9 +1,10 @@ use crate::fd::AsFd; -use crate::pid::Pid; #[cfg(not(target_os = "espidf"))] use crate::termios::{Action, OptionalActions, QueueSelector, Termios, Winsize}; use crate::{backend, io}; +pub use crate::pid::Pid; + /// `tcgetattr(fd)`—Get terminal attributes. /// /// Also known as the `TCGETS` (or `TCGETS2` on Linux) operation with `ioctl`. @@ -44,6 +45,11 @@ pub fn tcgetwinsize<Fd: AsFd>(fd: Fd) -> io::Result<Winsize> { /// /// Also known as the `TIOCGPGRP` operation with `ioctl`. /// +/// On Linux, if `fd` is a pseudo-terminal, the underlying system call here can +/// return a pid of 0, which rustix's `Pid` type doesn't support. So rustix +/// instead handles this case by failing with [`io::Errno::OPNOTSUPP`] if the +/// pid is 0. +/// /// # References /// - [POSIX] /// - [Linux] diff --git a/vendor/rustix/src/thread/prctl.rs b/vendor/rustix/src/thread/prctl.rs index 999764cb1..9d9e6b2d5 100644 --- a/vendor/rustix/src/thread/prctl.rs +++ b/vendor/rustix/src/thread/prctl.rs @@ -86,6 +86,9 @@ const PR_SET_NAME: c_int = 15; /// Set the name of the calling thread. /// +/// Unlike `pthread_setname_np`, this function silently truncates the name to +/// 16 bytes, as the Linux syscall does. +/// /// # References /// - [`prctl(PR_SET_NAME,...)`] /// |