diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 02:49:50 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 02:49:50 +0000 |
commit | 9835e2ae736235810b4ea1c162ca5e65c547e770 (patch) | |
tree | 3fcebf40ed70e581d776a8a4c65923e8ec20e026 /vendor/rustix/src/backend/linux_raw | |
parent | Releasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff) | |
download | rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip |
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/rustix/src/backend/linux_raw')
24 files changed, 575 insertions, 306 deletions
diff --git a/vendor/rustix/src/backend/linux_raw/arch/inline/mod.rs b/vendor/rustix/src/backend/linux_raw/arch/inline/mod.rs index 524c449d9..4783747ac 100644 --- a/vendor/rustix/src/backend/linux_raw/arch/inline/mod.rs +++ b/vendor/rustix/src/backend/linux_raw/arch/inline/mod.rs @@ -3,6 +3,10 @@ //! Compilers should really have intrinsics for making system calls. They're //! much like regular calls, with custom calling conventions, and calling //! conventions are otherwise the compiler's job. But for now, use inline asm. +//! +//! The calling conventions for Linux syscalls are [documented here]. +//! +//! [documented here]: https://man7.org/linux/man-pages/man2/syscall.2.html #[cfg_attr(target_arch = "aarch64", path = "aarch64.rs")] #[cfg_attr(all(target_arch = "arm", not(thumb_mode)), path = "arm.rs")] diff --git a/vendor/rustix/src/backend/linux_raw/arch/outline/mod.rs b/vendor/rustix/src/backend/linux_raw/arch/outline/mod.rs index a6a5f270d..5e6f5e1f5 100644 --- a/vendor/rustix/src/backend/linux_raw/arch/outline/mod.rs +++ b/vendor/rustix/src/backend/linux_raw/arch/outline/mod.rs @@ -1,9 +1,13 @@ //! Declare functions defined in out-of-line ("outline") asm files. //! -//! Kernel calling conventions differ from userspace calling conventions, -//! so we also define inline function wrappers which reorder the arguments -//! so that they match with the kernel convention as closely as possible, -//! to minimize the amount of out-of-line code we need. +//! Kernel calling conventions differ from userspace calling conventions, so we +//! also define inline function wrappers which reorder the arguments so that +//! they match with the kernel convention as closely as possible, to minimize +//! the amount of out-of-line code we need. +//! +//! This is needed in order to support our MSRV of 1.48, which doesn't support +//! inline asm. When using newer Rust versions, inline asm code is used instead +//! and these outline libraries are unused. #[cfg(target_arch = "x86")] mod x86; diff --git a/vendor/rustix/src/backend/linux_raw/c.rs b/vendor/rustix/src/backend/linux_raw/c.rs index e7263305a..89fee82f9 100644 --- a/vendor/rustix/src/backend/linux_raw/c.rs +++ b/vendor/rustix/src/backend/linux_raw/c.rs @@ -14,18 +14,20 @@ pub(crate) use linux_raw_sys::general::{ AF_BLUETOOTH, AF_BRIDGE, AF_CAN, AF_ECONET, AF_IEEE802154, AF_INET, AF_INET6, AF_IPX, AF_IRDA, AF_ISDN, AF_IUCV, AF_KEY, AF_LLC, AF_NETBEUI, AF_NETLINK, AF_NETROM, AF_PACKET, AF_PHONET, AF_PPPOX, AF_RDS, AF_ROSE, AF_RXRPC, AF_SECURITY, AF_SNA, AF_TIPC, AF_UNIX, AF_UNSPEC, - AF_WANPIPE, AF_X25, IPPROTO_AH, IPPROTO_BEETPH, IPPROTO_COMP, IPPROTO_DCCP, IPPROTO_EGP, + AF_WANPIPE, AF_X25, CLD_CONTINUED, CLD_DUMPED, CLD_EXITED, CLD_KILLED, CLD_STOPPED, + CLD_TRAPPED, IPPROTO_AH, IPPROTO_BEETPH, IPPROTO_COMP, IPPROTO_DCCP, IPPROTO_EGP, IPPROTO_ENCAP, IPPROTO_ESP, IPPROTO_ETHERNET, IPPROTO_FRAGMENT, IPPROTO_GRE, IPPROTO_ICMP, IPPROTO_ICMPV6, IPPROTO_IDP, IPPROTO_IGMP, IPPROTO_IP, IPPROTO_IPIP, IPPROTO_IPV6, IPPROTO_MH, IPPROTO_MPLS, IPPROTO_MPTCP, IPPROTO_MTP, IPPROTO_PIM, IPPROTO_PUP, IPPROTO_RAW, IPPROTO_ROUTING, IPPROTO_RSVP, IPPROTO_SCTP, IPPROTO_TCP, IPPROTO_TP, IPPROTO_UDP, - IPPROTO_UDPLITE, IPV6_ADD_MEMBERSHIP, IPV6_DROP_MEMBERSHIP, IPV6_MULTICAST_LOOP, IPV6_V6ONLY, - IP_ADD_MEMBERSHIP, IP_DROP_MEMBERSHIP, IP_MULTICAST_LOOP, IP_MULTICAST_TTL, IP_TTL, - MSG_CMSG_CLOEXEC, MSG_CONFIRM, MSG_DONTROUTE, MSG_DONTWAIT, MSG_EOR, MSG_ERRQUEUE, MSG_MORE, - MSG_NOSIGNAL, MSG_OOB, MSG_PEEK, MSG_TRUNC, MSG_WAITALL, O_CLOEXEC, O_NONBLOCK, - O_NONBLOCK as PIDFD_NONBLOCK, P_ALL, P_PID, P_PIDFD, SHUT_RD, SHUT_RDWR, SHUT_WR, SOCK_DGRAM, - SOCK_RAW, SOCK_RDM, SOCK_SEQPACKET, SOCK_STREAM, SOL_SOCKET, SO_BROADCAST, SO_ERROR, SO_LINGER, - SO_PASSCRED, SO_RCVTIMEO_NEW, SO_RCVTIMEO_OLD, SO_REUSEADDR, SO_SNDTIMEO_NEW, SO_SNDTIMEO_OLD, - SO_TYPE, TCP_NODELAY, + IPPROTO_UDPLITE, IPV6_ADD_MEMBERSHIP, IPV6_DROP_MEMBERSHIP, IPV6_MULTICAST_LOOP, + IPV6_UNICAST_HOPS, IPV6_V6ONLY, IP_ADD_MEMBERSHIP, IP_DROP_MEMBERSHIP, IP_MULTICAST_LOOP, + IP_MULTICAST_TTL, IP_TTL, MSG_CMSG_CLOEXEC, MSG_CONFIRM, MSG_DONTROUTE, MSG_DONTWAIT, MSG_EOR, + MSG_ERRQUEUE, MSG_MORE, MSG_NOSIGNAL, MSG_OOB, MSG_PEEK, MSG_TRUNC, MSG_WAITALL, O_CLOEXEC, + O_NONBLOCK, O_NONBLOCK as PIDFD_NONBLOCK, P_ALL, P_PID, P_PIDFD, SHUT_RD, SHUT_RDWR, SHUT_WR, + SOCK_DGRAM, SOCK_RAW, SOCK_RDM, SOCK_SEQPACKET, SOCK_STREAM, SOL_SOCKET, SO_BROADCAST, + SO_ERROR, SO_KEEPALIVE, SO_LINGER, SO_PASSCRED, SO_RCVBUF, SO_RCVTIMEO_NEW, SO_RCVTIMEO_OLD, + SO_REUSEADDR, SO_SNDBUF, SO_SNDTIMEO_NEW, SO_SNDTIMEO_OLD, SO_TYPE, TCP_NODELAY, }; pub(crate) use linux_raw_sys::general::{NFS_SUPER_MAGIC, PROC_SUPER_MAGIC, UTIME_NOW, UTIME_OMIT}; +pub(crate) use linux_raw_sys::general::{XATTR_CREATE, XATTR_REPLACE}; diff --git a/vendor/rustix/src/backend/linux_raw/conv.rs b/vendor/rustix/src/backend/linux_raw/conv.rs index b9fe725bb..f02b5c046 100644 --- a/vendor/rustix/src/backend/linux_raw/conv.rs +++ b/vendor/rustix/src/backend/linux_raw/conv.rs @@ -190,6 +190,11 @@ pub(super) fn slice_just_addr<T: Sized, Num: ArgNumber>(v: &[T]) -> ArgReg<Num> } #[inline] +pub(super) fn slice_just_addr_mut<T: Sized, Num: ArgNumber>(v: &mut [T]) -> ArgReg<Num> { + raw_arg(v.as_mut_ptr().cast()) +} + +#[inline] pub(super) fn slice<T: Sized, Num0: ArgNumber, Num1: ArgNumber>( v: &[T], ) -> (ArgReg<Num0>, ArgReg<Num1>) { @@ -314,6 +319,14 @@ impl<'a, Num: ArgNumber> From<crate::fs::AtFlags> for ArgReg<'a, Num> { } #[cfg(feature = "fs")] +impl<'a, Num: ArgNumber> From<crate::fs::XattrFlags> for ArgReg<'a, Num> { + #[inline] + fn from(flags: crate::fs::XattrFlags) -> Self { + c_uint(flags.bits()) + } +} + +#[cfg(feature = "fs")] impl<'a, Num: ArgNumber> From<crate::fs::inotify::CreateFlags> for ArgReg<'a, Num> { #[inline] fn from(flags: crate::fs::inotify::CreateFlags) -> Self { @@ -615,9 +628,9 @@ impl<'a, Num: ArgNumber> From<crate::net::SendFlags> for ArgReg<'a, Num> { } #[cfg(feature = "net")] -impl<'a, Num: ArgNumber> From<crate::net::AcceptFlags> for ArgReg<'a, Num> { +impl<'a, Num: ArgNumber> From<crate::net::SocketFlags> for ArgReg<'a, Num> { #[inline] - fn from(flags: crate::net::AcceptFlags) -> Self { + fn from(flags: crate::net::SocketFlags) -> Self { c_uint(flags.bits()) } } @@ -681,6 +694,13 @@ impl<'a, Num: ArgNumber, T> From<&'a mut MaybeUninit<T>> for ArgReg<'a, Num> { } } +impl<'a, Num: ArgNumber, T> From<&'a mut [MaybeUninit<T>]> for ArgReg<'a, Num> { + #[inline] + fn from(t: &'a mut [MaybeUninit<T>]) -> Self { + raw_arg(t.as_mut_ptr().cast()) + } +} + #[cfg(feature = "fs")] #[cfg(any(target_os = "android", target_os = "linux"))] impl<'a, Num: ArgNumber> From<crate::backend::fs::types::MountFlagsArg> for ArgReg<'a, Num> { @@ -713,6 +733,14 @@ impl<'a, Num: ArgNumber> From<crate::process::Gid> for ArgReg<'a, Num> { } } +#[cfg(feature = "runtime")] +impl<'a, Num: ArgNumber> From<crate::runtime::How> for ArgReg<'a, Num> { + #[inline] + fn from(flags: crate::runtime::How) -> Self { + c_uint(flags as u32) + } +} + /// Convert a `usize` returned from a syscall that effectively returns `()` on /// success. /// diff --git a/vendor/rustix/src/backend/linux_raw/fs/inotify.rs b/vendor/rustix/src/backend/linux_raw/fs/inotify.rs index 4221565a6..a3c274741 100644 --- a/vendor/rustix/src/backend/linux_raw/fs/inotify.rs +++ b/vendor/rustix/src/backend/linux_raw/fs/inotify.rs @@ -80,7 +80,7 @@ pub fn inotify_init(flags: CreateFlags) -> io::Result<OwnedFd> { syscalls::inotify_init1(flags) } -/// `inotify_add_watch(self, path, flags)`—Adds a watch to inotify +/// `inotify_add_watch(self, path, flags)`—Adds a watch to inotify. /// /// This registers or updates a watch for the filesystem path `path` /// and returns a watch descriptor corresponding to this watch. diff --git a/vendor/rustix/src/backend/linux_raw/fs/syscalls.rs b/vendor/rustix/src/backend/linux_raw/fs/syscalls.rs index 8bd9ccc27..d0d855cc1 100644 --- a/vendor/rustix/src/backend/linux_raw/fs/syscalls.rs +++ b/vendor/rustix/src/backend/linux_raw/fs/syscalls.rs @@ -10,7 +10,7 @@ use super::super::c; use super::super::conv::{ by_ref, c_int, c_uint, dev_t, oflags_for_open_how, opt_mut, pass_usize, raw_fd, ret, ret_c_int, - ret_c_uint, ret_infallible, ret_owned_fd, ret_usize, size_of, slice_mut, zero, + ret_c_uint, ret_infallible, ret_owned_fd, ret_usize, size_of, slice, slice_mut, zero, }; #[cfg(target_pointer_width = "64")] use super::super::conv::{loff_t, loff_t_from_u64, ret_u64}; @@ -26,7 +26,7 @@ use crate::ffi::CStr; use crate::fs::{ inotify, Access, Advice, AtFlags, FallocateFlags, FileType, FlockOperation, MemfdFlags, Mode, OFlags, RenameFlags, ResolveFlags, SealFlags, Stat, StatFs, StatVfs, StatVfsMountFlags, - StatxFlags, Timestamps, + StatxFlags, Timestamps, XattrFlags, }; use crate::io::{self, SeekFrom}; use crate::process::{Gid, Uid}; @@ -1392,6 +1392,30 @@ pub(crate) fn accessat( access: Access, flags: AtFlags, ) -> io::Result<()> { + if !flags + .difference(AtFlags::EACCESS | AtFlags::SYMLINK_NOFOLLOW) + .is_empty() + { + return Err(io::Errno::INVAL); + } + + // Linux's `faccessat` syscall doesn't have a flags argument, so if we have + // any flags, use the newer `faccessat2` which does. Unless we're on + // Android where using newer system calls can cause seccomp to abort the + // process. + #[cfg(not(target_os = "android"))] + if !flags.is_empty() { + return unsafe { + ret(syscall_readonly!( + __NR_faccessat2, + dirfd, + path, + access, + flags + )) + }; + } + // Linux's `faccessat` doesn't have a flags parameter. If we have // `AT_EACCESS` and we're not setuid or setgid, we can emulate it. if flags.is_empty() @@ -1402,11 +1426,6 @@ pub(crate) fn accessat( return unsafe { ret(syscall_readonly!(__NR_faccessat, dirfd, path, access)) }; } - if flags.bits() != AT_EACCESS { - return Err(io::Errno::INVAL); - } - - // TODO: Use faccessat2 in newer Linux versions. Err(io::Errno::NOSYS) } @@ -1510,3 +1529,138 @@ pub(crate) fn inotify_add_watch( pub(crate) fn inotify_rm_watch(infd: BorrowedFd<'_>, wfd: i32) -> io::Result<()> { unsafe { ret(syscall_readonly!(__NR_inotify_rm_watch, infd, c_int(wfd))) } } + +#[inline] +pub(crate) fn getxattr(path: &CStr, name: &CStr, value: &mut [u8]) -> io::Result<usize> { + let (value_addr_mut, value_len) = slice_mut(value); + unsafe { + ret_usize(syscall!( + __NR_getxattr, + path, + name, + value_addr_mut, + value_len + )) + } +} + +#[inline] +pub(crate) fn lgetxattr(path: &CStr, name: &CStr, value: &mut [u8]) -> io::Result<usize> { + let (value_addr_mut, value_len) = slice_mut(value); + unsafe { + ret_usize(syscall!( + __NR_lgetxattr, + path, + name, + value_addr_mut, + value_len + )) + } +} + +#[inline] +pub(crate) fn fgetxattr(fd: BorrowedFd<'_>, name: &CStr, value: &mut [u8]) -> io::Result<usize> { + let (value_addr_mut, value_len) = slice_mut(value); + unsafe { + ret_usize(syscall!( + __NR_fgetxattr, + fd, + name, + value_addr_mut, + value_len + )) + } +} + +#[inline] +pub(crate) fn setxattr( + path: &CStr, + name: &CStr, + value: &[u8], + flags: XattrFlags, +) -> io::Result<()> { + let (value_addr, value_len) = slice(value); + unsafe { + ret(syscall_readonly!( + __NR_setxattr, + path, + name, + value_addr, + value_len, + flags + )) + } +} + +#[inline] +pub(crate) fn lsetxattr( + path: &CStr, + name: &CStr, + value: &[u8], + flags: XattrFlags, +) -> io::Result<()> { + let (value_addr, value_len) = slice(value); + unsafe { + ret(syscall_readonly!( + __NR_lsetxattr, + path, + name, + value_addr, + value_len, + flags + )) + } +} + +#[inline] +pub(crate) fn fsetxattr( + fd: BorrowedFd<'_>, + name: &CStr, + value: &[u8], + flags: XattrFlags, +) -> io::Result<()> { + let (value_addr, value_len) = slice(value); + unsafe { + ret(syscall_readonly!( + __NR_fsetxattr, + fd, + name, + value_addr, + value_len, + flags + )) + } +} + +#[inline] +pub(crate) fn listxattr(path: &CStr, list: &mut [c::c_char]) -> io::Result<usize> { + let (list_addr_mut, list_len) = slice_mut(list); + unsafe { ret_usize(syscall!(__NR_listxattr, path, list_addr_mut, list_len)) } +} + +#[inline] +pub(crate) fn llistxattr(path: &CStr, list: &mut [c::c_char]) -> io::Result<usize> { + let (list_addr_mut, list_len) = slice_mut(list); + unsafe { ret_usize(syscall!(__NR_llistxattr, path, list_addr_mut, list_len)) } +} + +#[inline] +pub(crate) fn flistxattr(fd: BorrowedFd<'_>, list: &mut [c::c_char]) -> io::Result<usize> { + let (list_addr_mut, list_len) = slice_mut(list); + unsafe { ret_usize(syscall!(__NR_flistxattr, fd, list_addr_mut, list_len)) } +} + +#[inline] +pub(crate) fn removexattr(path: &CStr, name: &CStr) -> io::Result<()> { + unsafe { ret(syscall!(__NR_removexattr, path, name)) } +} + +#[inline] +pub(crate) fn lremovexattr(path: &CStr, name: &CStr) -> io::Result<()> { + unsafe { ret(syscall!(__NR_lremovexattr, path, name)) } +} + +#[inline] +pub(crate) fn fremovexattr(fd: BorrowedFd<'_>, name: &CStr) -> io::Result<()> { + unsafe { ret(syscall!(__NR_fremovexattr, fd, name)) } +} diff --git a/vendor/rustix/src/backend/linux_raw/fs/types.rs b/vendor/rustix/src/backend/linux_raw/fs/types.rs index 9bafb8ac0..68bb9ed46 100644 --- a/vendor/rustix/src/backend/linux_raw/fs/types.rs +++ b/vendor/rustix/src/backend/linux_raw/fs/types.rs @@ -288,6 +288,7 @@ pub enum FileType { Symlink = linux_raw_sys::general::S_IFLNK as isize, /// `S_IFIFO` + #[doc(alias = "IFO")] Fifo = linux_raw_sys::general::S_IFIFO as isize, /// `S_IFSOCK` @@ -335,7 +336,7 @@ impl FileType { } } - /// Construct a `FileType` from the `d_type` field of a `dirent`. + /// Construct a `FileType` from the `d_type` field of a `c::dirent`. #[inline] pub(crate) const fn from_dirent_d_type(d_type: u8) -> Self { match d_type as u32 { @@ -645,7 +646,7 @@ pub type StatxTimestamp = linux_raw_sys::general::statx_timestamp; )))] pub type RawMode = linux_raw_sys::general::__kernel_mode_t; -/// `mode_t +/// `mode_t` #[cfg(any( target_arch = "x86", target_arch = "sparc", diff --git a/vendor/rustix/src/backend/linux_raw/io/errno.rs b/vendor/rustix/src/backend/linux_raw/io/errno.rs index b01910138..9db14d06e 100644 --- a/vendor/rustix/src/backend/linux_raw/io/errno.rs +++ b/vendor/rustix/src/backend/linux_raw/io/errno.rs @@ -60,7 +60,7 @@ impl Errno { Self::from_errno(raw as u32) } - /// Convert from a C errno value (which is positive) to an `Errno`. + /// Convert from a C `errno` value (which is positive) to an `Errno`. const fn from_errno(raw: u32) -> Self { // We store error values in negated form, so that we don't have to negate // them after every syscall. diff --git a/vendor/rustix/src/backend/linux_raw/io/syscalls.rs b/vendor/rustix/src/backend/linux_raw/io/syscalls.rs index 3acf9ffdb..c76fb0635 100644 --- a/vendor/rustix/src/backend/linux_raw/io/syscalls.rs +++ b/vendor/rustix/src/backend/linux_raw/io/syscalls.rs @@ -36,7 +36,7 @@ use linux_raw_sys::ioctl::{BLKPBSZGET, BLKSSZGET, FICLONE, FIONBIO, FIONREAD, TI #[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))] use { super::super::conv::{opt_ref, size_of}, - linux_raw_sys::general::{__kernel_timespec, sigset_t}, + linux_raw_sys::general::{__kernel_timespec, kernel_sigset_t}, }; #[inline] @@ -555,7 +555,7 @@ pub(crate) fn poll(fds: &mut [PollFd<'_>], timeout: c::c_int) -> io::Result<usiz fds_len, opt_ref(timeout.as_ref()), zero(), - size_of::<sigset_t, _>() + size_of::<kernel_sigset_t, _>() )) } #[cfg(not(any(target_arch = "aarch64", target_arch = "riscv64")))] diff --git a/vendor/rustix/src/backend/linux_raw/mm/types.rs b/vendor/rustix/src/backend/linux_raw/mm/types.rs index a58dd76be..a34c41f4f 100644 --- a/vendor/rustix/src/backend/linux_raw/mm/types.rs +++ b/vendor/rustix/src/backend/linux_raw/mm/types.rs @@ -197,12 +197,12 @@ pub enum Advice { LinuxPopulateWrite = linux_raw_sys::general::MADV_POPULATE_WRITE, } +#[allow(non_upper_case_globals)] impl Advice { /// `POSIX_MADV_DONTNEED` /// /// On Linux, this is mapped to `POSIX_MADV_NORMAL` because /// Linux's `MADV_DONTNEED` differs from `POSIX_MADV_DONTNEED`. See /// `LinuxDontNeed` for the Linux behavior. - #[allow(non_upper_case_globals)] pub const DontNeed: Self = Self::Normal; } diff --git a/vendor/rustix/src/backend/linux_raw/mod.rs b/vendor/rustix/src/backend/linux_raw/mod.rs index 1b91fc3ab..e7e073e32 100644 --- a/vendor/rustix/src/backend/linux_raw/mod.rs +++ b/vendor/rustix/src/backend/linux_raw/mod.rs @@ -14,11 +14,6 @@ //! such as which pointers are array slices, out parameters, or in-out //! parameters, which integers are owned or borrowed file descriptors, etc. -// Weak symbols used by the use-libc-auxv feature for glibc 2.15 support. -#[cfg(feature = "use-libc-auxv")] -#[macro_use] -mod weak; - #[macro_use] mod arch; mod conv; diff --git a/vendor/rustix/src/backend/linux_raw/net/send_recv.rs b/vendor/rustix/src/backend/linux_raw/net/send_recv.rs index 888e81e2b..fb82eaef3 100644 --- a/vendor/rustix/src/backend/linux_raw/net/send_recv.rs +++ b/vendor/rustix/src/backend/linux_raw/net/send_recv.rs @@ -2,7 +2,10 @@ use super::super::c; use bitflags::bitflags; bitflags! { - /// `MSG_*` + /// `MSG_* flags for use with [`send`], [`send_to`], and related functions. + /// + /// [`send`]: crate::net::send + /// [`sendto`]: crate::net::sendto pub struct SendFlags: u32 { /// `MSG_CONFIRM` const CONFIRM = c::MSG_CONFIRM; @@ -22,7 +25,10 @@ bitflags! { } bitflags! { - /// `MSG_*` + /// `MSG_* flags for use with [`recv`], [`recvfrom`], and related functions. + /// + /// [`recv`]: crate::net::recv + /// [`recvfrom`]: crate::net::recvfrom pub struct RecvFlags: u32 { /// `MSG_CMSG_CLOEXEC` const CMSG_CLOEXEC = c::MSG_CMSG_CLOEXEC; diff --git a/vendor/rustix/src/backend/linux_raw/net/syscalls.rs b/vendor/rustix/src/backend/linux_raw/net/syscalls.rs index 6093cd3a5..7fe9f0ef4 100644 --- a/vendor/rustix/src/backend/linux_raw/net/syscalls.rs +++ b/vendor/rustix/src/backend/linux_raw/net/syscalls.rs @@ -13,7 +13,7 @@ use super::super::conv::{ }; use super::read_sockaddr::{initialize_family_to_unspec, maybe_read_sockaddr_os, read_sockaddr_os}; use super::send_recv::{RecvFlags, SendFlags}; -use super::types::{AcceptFlags, AddressFamily, Protocol, Shutdown, SocketFlags, SocketType}; +use super::types::{AddressFamily, Protocol, Shutdown, SocketFlags, SocketType}; use super::write_sockaddr::{encode_sockaddr_v4, encode_sockaddr_v6}; use crate::fd::{BorrowedFd, OwnedFd}; use crate::io; @@ -143,7 +143,7 @@ pub(crate) fn accept(fd: BorrowedFd<'_>) -> io::Result<OwnedFd> { } #[inline] -pub(crate) fn accept_with(fd: BorrowedFd<'_>, flags: AcceptFlags) -> io::Result<OwnedFd> { +pub(crate) fn accept_with(fd: BorrowedFd<'_>, flags: SocketFlags) -> io::Result<OwnedFd> { #[cfg(not(target_arch = "x86"))] unsafe { let fd = ret_owned_fd(syscall_readonly!(__NR_accept4, fd, zero(), zero(), flags))?; @@ -200,7 +200,7 @@ pub(crate) fn acceptfrom(fd: BorrowedFd<'_>) -> io::Result<(OwnedFd, Option<Sock #[inline] pub(crate) fn acceptfrom_with( fd: BorrowedFd<'_>, - flags: AcceptFlags, + flags: SocketFlags, ) -> io::Result<(OwnedFd, Option<SocketAddrAny>)> { #[cfg(not(target_arch = "x86"))] unsafe { @@ -1066,16 +1066,53 @@ pub(crate) mod sockopt { } #[inline] - pub(crate) fn get_socket_error(fd: BorrowedFd<'_>) -> io::Result<Result<(), crate::io::Errno>> { + pub(crate) fn get_socket_error(fd: BorrowedFd<'_>) -> io::Result<Result<(), io::Errno>> { let err: c::c_int = getsockopt(fd, c::SOL_SOCKET as _, c::SO_ERROR)?; Ok(if err == 0 { Ok(()) } else { - Err(crate::io::Errno::from_raw_os_error(err)) + Err(io::Errno::from_raw_os_error(err)) }) } #[inline] + pub(crate) fn set_socket_keepalive(fd: BorrowedFd<'_>, keepalive: bool) -> io::Result<()> { + setsockopt( + fd, + c::SOL_SOCKET as _, + c::SO_KEEPALIVE, + from_bool(keepalive), + ) + } + + #[inline] + pub(crate) fn get_socket_keepalive(fd: BorrowedFd<'_>) -> io::Result<bool> { + getsockopt(fd, c::SOL_SOCKET as _, c::SO_KEEPALIVE).map(to_bool) + } + + #[inline] + pub(crate) fn set_socket_recv_buffer_size(fd: BorrowedFd<'_>, size: usize) -> io::Result<()> { + let size: c::c_int = size.try_into().map_err(|_| io::Errno::OVERFLOW)?; + setsockopt(fd, c::SOL_SOCKET as _, c::SO_RCVBUF, size) + } + + #[inline] + pub(crate) fn get_socket_recv_buffer_size(fd: BorrowedFd<'_>) -> io::Result<usize> { + getsockopt(fd, c::SOL_SOCKET as _, c::SO_RCVBUF).map(|size: u32| size as usize) + } + + #[inline] + pub(crate) fn set_socket_send_buffer_size(fd: BorrowedFd<'_>, size: usize) -> io::Result<()> { + let size: c::c_int = size.try_into().map_err(|_| io::Errno::OVERFLOW)?; + setsockopt(fd, c::SOL_SOCKET as _, c::SO_SNDBUF, size) + } + + #[inline] + pub(crate) fn get_socket_send_buffer_size(fd: BorrowedFd<'_>) -> io::Result<usize> { + getsockopt(fd, c::SOL_SOCKET as _, c::SO_SNDBUF).map(|size: u32| size as usize) + } + + #[inline] pub(crate) fn set_ip_ttl(fd: BorrowedFd<'_>, ttl: u32) -> io::Result<()> { setsockopt(fd, c::IPPROTO_IP as _, c::IP_TTL, ttl) } @@ -1200,6 +1237,20 @@ pub(crate) mod sockopt { } #[inline] + pub(crate) fn get_ipv6_unicast_hops(fd: BorrowedFd<'_>) -> io::Result<u8> { + getsockopt(fd, c::IPPROTO_IPV6 as _, c::IPV6_UNICAST_HOPS).map(|hops: c::c_int| hops as u8) + } + + #[inline] + pub(crate) fn set_ipv6_unicast_hops(fd: BorrowedFd<'_>, hops: Option<u8>) -> io::Result<()> { + let hops = match hops { + Some(hops) => hops as c::c_int, + None => -1, + }; + setsockopt(fd, c::IPPROTO_IPV6 as _, c::IPV6_UNICAST_HOPS, hops) + } + + #[inline] pub(crate) fn set_tcp_nodelay(fd: BorrowedFd<'_>, nodelay: bool) -> io::Result<()> { setsockopt(fd, c::IPPROTO_TCP as _, c::TCP_NODELAY, from_bool(nodelay)) } diff --git a/vendor/rustix/src/backend/linux_raw/net/types.rs b/vendor/rustix/src/backend/linux_raw/net/types.rs index b8f786b3f..3f0b571a5 100644 --- a/vendor/rustix/src/backend/linux_raw/net/types.rs +++ b/vendor/rustix/src/backend/linux_raw/net/types.rs @@ -52,6 +52,7 @@ pub type RawAddressFamily = c::sa_family_t; pub struct AddressFamily(pub(crate) RawAddressFamily); #[rustfmt::skip] +#[allow(non_upper_case_globals)] impl AddressFamily { /// `AF_UNSPEC` pub const UNSPEC: Self = Self(c::AF_UNSPEC as _); @@ -81,7 +82,6 @@ impl AddressFamily { /// `AF_ROSE` pub const ROSE: Self = Self(c::AF_ROSE as _); /// `AF_DECnet` - #[allow(non_upper_case_globals)] pub const DECnet: Self = Self(c::AF_DECnet as _); /// `AF_NETBEUI` pub const NETBEUI: Self = Self(c::AF_NETBEUI as _); @@ -143,7 +143,10 @@ impl AddressFamily { #[doc(hidden)] pub type RawProtocol = u32; -/// `IPPROTO_*` +/// `IPPROTO_*` constants for use with [`socket`] and [`socket_with`]. +/// +/// [`socket`]: crate::net::socket +/// [`socket_with`]: crate::net::socket_with #[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)] #[repr(transparent)] pub struct Protocol(pub(crate) RawProtocol); @@ -232,7 +235,7 @@ impl Protocol { #[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)] #[repr(u32)] pub enum Shutdown { - /// `SHUT_WR`—Disable further read operations. + /// `SHUT_RD`—Disable further read operations. Read = c::SHUT_RD, /// `SHUT_WR`—Disable further write operations. Write = c::SHUT_WR, @@ -241,22 +244,12 @@ pub enum Shutdown { } bitflags! { - /// `SOCK_*` constants for use with [`accept_with`] and [`acceptfrom_with`]. + /// `SOCK_*` constants for use with [`socket_with`], [`accept_with`] and + /// [`acceptfrom_with`]. /// + /// [`socket_with`]: crate::net::socket_with /// [`accept_with`]: crate::net::accept_with /// [`acceptfrom_with`]: crate::net::acceptfrom_with - pub struct AcceptFlags: c::c_uint { - /// `SOCK_NONBLOCK` - const NONBLOCK = c::O_NONBLOCK; - /// `SOCK_CLOEXEC` - const CLOEXEC = c::O_CLOEXEC; - } -} - -bitflags! { - /// `SOCK_*` constants for use with [`socket`]. - /// - /// [`socket`]: crate::net::socket pub struct SocketFlags: c::c_uint { /// `SOCK_NONBLOCK` const NONBLOCK = c::O_NONBLOCK; diff --git a/vendor/rustix/src/backend/linux_raw/process/syscalls.rs b/vendor/rustix/src/backend/linux_raw/process/syscalls.rs index f86f8e5b9..0eb6489e7 100644 --- a/vendor/rustix/src/backend/linux_raw/process/syscalls.rs +++ b/vendor/rustix/src/backend/linux_raw/process/syscalls.rs @@ -9,7 +9,8 @@ use super::super::c; use super::super::conv::{ by_mut, by_ref, c_int, c_uint, negative_pid, pass_usize, ret, ret_c_int, ret_c_uint, - ret_infallible, ret_usize, ret_usize_infallible, size_of, slice_just_addr, slice_mut, zero, + ret_infallible, ret_usize, ret_usize_infallible, size_of, slice, slice_just_addr, + slice_just_addr_mut, slice_mut, zero, }; use super::types::{RawCpuSet, RawUname}; use crate::backend::conv::ret_owned_fd; @@ -18,7 +19,8 @@ use crate::ffi::CStr; use crate::io; use crate::process::{ Cpuid, Gid, MembarrierCommand, MembarrierQuery, Pid, PidfdFlags, RawNonZeroPid, RawPid, - Resource, Rlimit, Signal, Uid, WaitId, WaitOptions, WaitStatus, WaitidOptions, WaitidStatus, + Resource, Rlimit, Signal, Sysinfo, Uid, WaitId, WaitOptions, WaitStatus, WaitidOptions, + WaitidStatus, }; use core::convert::TryInto; use core::mem::MaybeUninit; @@ -43,6 +45,11 @@ pub(crate) fn fchdir(fd: BorrowedFd<'_>) -> io::Result<()> { } #[inline] +pub(crate) fn chroot(filename: &CStr) -> io::Result<()> { + unsafe { ret(syscall_readonly!(__NR_chroot, filename)) } +} + +#[inline] pub(crate) fn getcwd(buf: &mut [u8]) -> io::Result<usize> { let (buf_addr_mut, buf_len) = slice_mut(buf); unsafe { ret_usize(syscall!(__NR_getcwd, buf_addr_mut, buf_len)) } @@ -116,6 +123,17 @@ pub(crate) fn getpgid(pid: Option<Pid>) -> io::Result<Pid> { } #[inline] +pub(crate) fn setpgid(pid: Option<Pid>, pgid: Option<Pid>) -> io::Result<()> { + unsafe { + ret(syscall_readonly!( + __NR_setpgid, + c_uint(Pid::as_raw(pid)), + c_uint(Pid::as_raw(pgid)) + )) + } +} + +#[inline] pub(crate) fn getpgrp() -> Pid { // Use the `getpgrp` syscall if available. #[cfg(not(any(target_arch = "aarch64", target_arch = "riscv64")))] @@ -541,7 +559,9 @@ pub(crate) fn waitid(id: WaitId<'_>, options: WaitidOptions) -> io::Result<Optio #[inline] fn _waitid_all(options: WaitidOptions) -> io::Result<Option<WaitidStatus>> { - let mut status = MaybeUninit::<c::siginfo_t>::uninit(); + // `waitid` can return successfully without initializing the struct (no + // children found when using `WNOHANG`) + let mut status = MaybeUninit::<c::siginfo_t>::zeroed(); unsafe { ret(syscall!( __NR_waitid, @@ -558,7 +578,9 @@ fn _waitid_all(options: WaitidOptions) -> io::Result<Option<WaitidStatus>> { #[inline] fn _waitid_pid(pid: Pid, options: WaitidOptions) -> io::Result<Option<WaitidStatus>> { - let mut status = MaybeUninit::<c::siginfo_t>::uninit(); + // `waitid` can return successfully without initializing the struct (no + // children found when using `WNOHANG`) + let mut status = MaybeUninit::<c::siginfo_t>::zeroed(); unsafe { ret(syscall!( __NR_waitid, @@ -575,7 +597,9 @@ fn _waitid_pid(pid: Pid, options: WaitidOptions) -> io::Result<Option<WaitidStat #[inline] fn _waitid_pidfd(fd: BorrowedFd<'_>, options: WaitidOptions) -> io::Result<Option<WaitidStatus>> { - let mut status = MaybeUninit::<c::siginfo_t>::uninit(); + // `waitid` can return successfully without initializing the struct (no + // children found when using `WNOHANG`) + let mut status = MaybeUninit::<c::siginfo_t>::zeroed(); unsafe { ret(syscall!( __NR_waitid, @@ -597,9 +621,10 @@ fn _waitid_pidfd(fd: BorrowedFd<'_>, options: WaitidOptions) -> io::Result<Optio /// The caller must ensure that `status` is initialized and that `waitid` /// returned successfully. #[inline] +#[rustfmt::skip] unsafe fn cvt_waitid_status(status: MaybeUninit<c::siginfo_t>) -> Option<WaitidStatus> { let status = status.assume_init(); - if status.__bindgen_anon_1.__bindgen_anon_1.si_signo == 0 { + if status.__bindgen_anon_1.__bindgen_anon_1._sifields._sigchld._pid == 0 { None } else { Some(WaitidStatus(status)) @@ -613,6 +638,17 @@ pub(crate) fn exit_group(code: c::c_int) -> ! { } #[inline] +pub(crate) fn getsid(pid: Option<Pid>) -> io::Result<Pid> { + unsafe { + let pid = ret_usize(syscall_readonly!(__NR_getsid, c_uint(Pid::as_raw(pid))))?; + debug_assert!(pid > 0); + Ok(Pid::from_raw_nonzero(RawNonZeroPid::new_unchecked( + pid as u32, + ))) + } +} + +#[inline] pub(crate) fn setsid() -> io::Result<Pid> { unsafe { let pid = ret_usize(syscall_readonly!(__NR_setsid))?; @@ -639,6 +675,27 @@ pub(crate) fn kill_current_process_group(sig: Signal) -> io::Result<()> { } #[inline] +pub(crate) fn test_kill_process(pid: Pid) -> io::Result<()> { + unsafe { ret(syscall_readonly!(__NR_kill, pid, pass_usize(0))) } +} + +#[inline] +pub(crate) fn test_kill_process_group(pid: Pid) -> io::Result<()> { + unsafe { + ret(syscall_readonly!( + __NR_kill, + negative_pid(pid), + pass_usize(0) + )) + } +} + +#[inline] +pub(crate) fn test_kill_current_process_group() -> io::Result<()> { + unsafe { ret(syscall_readonly!(__NR_kill, pass_usize(0), pass_usize(0))) } +} + +#[inline] pub(crate) unsafe fn prctl( option: c::c_int, arg2: *mut c::c_void, @@ -659,3 +716,31 @@ pub(crate) fn pidfd_open(pid: Pid, flags: PidfdFlags) -> io::Result<OwnedFd> { )) } } + +#[inline] +pub(crate) fn getgroups(buf: &mut [Gid]) -> io::Result<usize> { + let len = buf.len().try_into().map_err(|_| io::Errno::NOMEM)?; + + unsafe { + ret_usize(syscall!( + __NR_getgroups, + c_int(len), + slice_just_addr_mut(buf) + )) + } +} + +#[inline] +pub(crate) fn sysinfo() -> Sysinfo { + let mut info = MaybeUninit::<Sysinfo>::uninit(); + unsafe { + ret_infallible(syscall!(__NR_sysinfo, &mut info)); + info.assume_init() + } +} + +#[inline] +pub(crate) fn sethostname(name: &[u8]) -> io::Result<()> { + let (ptr, len) = slice(name); + unsafe { ret(syscall_readonly!(__NR_sethostname, ptr, len)) } +} diff --git a/vendor/rustix/src/backend/linux_raw/process/types.rs b/vendor/rustix/src/backend/linux_raw/process/types.rs index 53e2c7db1..efdaddbae 100644 --- a/vendor/rustix/src/backend/linux_raw/process/types.rs +++ b/vendor/rustix/src/backend/linux_raw/process/types.rs @@ -1,6 +1,9 @@ use super::super::c; use linux_raw_sys::general::membarrier_cmd; +/// `sysinfo` +pub type Sysinfo = linux_raw_sys::general::sysinfo; + /// A command for use with [`membarrier`] and [`membarrier_cpu`]. /// /// For `MEMBARRIER_CMD_QUERY`, see [`membarrier_query`]. @@ -78,10 +81,12 @@ pub enum Resource { Rttime = linux_raw_sys::general::RLIMIT_RTTIME, } -/// A signal number for use with [`kill_process`] and [`kill_process_group`]. +/// A signal number for use with [`kill_process`], [`kill_process_group`], +/// and [`kill_current_process_group`]. /// /// [`kill_process`]: crate::process::kill_process /// [`kill_process_group`]: crate::process::kill_process_group +/// [`kill_current_process_group`]: crate::process::kill_current_process_group #[derive(Copy, Clone, Debug, Eq, PartialEq)] #[repr(u32)] pub enum Signal { @@ -206,7 +211,7 @@ impl Signal { pub const EXIT_SUCCESS: c::c_int = 0; /// `EXIT_FAILURE` pub const EXIT_FAILURE: c::c_int = 1; -/// The status value of a child terminated with `SIGABRT`. +/// The status value of a child terminated with a [`Signal::Abort`] signal. pub const EXIT_SIGNALED_SIGABRT: c::c_int = 128 + linux_raw_sys::general::SIGABRT as i32; /// A process identifier as a raw integer. diff --git a/vendor/rustix/src/backend/linux_raw/process/wait.rs b/vendor/rustix/src/backend/linux_raw/process/wait.rs index edc564a9f..9af7f2b5e 100644 --- a/vendor/rustix/src/backend/linux_raw/process/wait.rs +++ b/vendor/rustix/src/backend/linux_raw/process/wait.rs @@ -1,8 +1,9 @@ // The functions replacing the C macros use the same names as in libc. -#![allow(non_snake_case)] +#![allow(non_snake_case, unsafe_code)] +use linux_raw_sys::ctypes::c_int; pub(crate) use linux_raw_sys::general::{ - WCONTINUED, WEXITED, WNOHANG, WNOWAIT, WSTOPPED, WUNTRACED, + siginfo_t, WCONTINUED, WEXITED, WNOHANG, WNOWAIT, WSTOPPED, WUNTRACED, }; #[inline] @@ -39,3 +40,29 @@ pub(crate) fn WIFEXITED(status: u32) -> bool { pub(crate) fn WEXITSTATUS(status: u32) -> u32 { (status >> 8) & 0xff } + +pub(crate) trait SiginfoExt { + fn si_code(&self) -> c_int; + unsafe fn si_status(&self) -> c_int; +} + +impl SiginfoExt for siginfo_t { + #[inline] + fn si_code(&self) -> c_int { + // SAFETY: This is technically a union access, but it's only a union + // with padding. + unsafe { self.__bindgen_anon_1.__bindgen_anon_1.si_code } + } + + /// Return the exit status or signal number recorded in a `siginfo_t`. + /// + /// # Safety + /// + /// `si_signo` must equal `SIGCHLD` (as it is guaranteed to do after a + /// `waitid` call). + #[inline] + #[rustfmt::skip] + unsafe fn si_status(&self) -> c_int { + self.__bindgen_anon_1.__bindgen_anon_1._sifields._sigchld._status + } +} diff --git a/vendor/rustix/src/backend/linux_raw/runtime/syscalls.rs b/vendor/rustix/src/backend/linux_raw/runtime/syscalls.rs index a331786f9..74363fc32 100644 --- a/vendor/rustix/src/backend/linux_raw/runtime/syscalls.rs +++ b/vendor/rustix/src/backend/linux_raw/runtime/syscalls.rs @@ -9,15 +9,25 @@ use super::super::c; #[cfg(target_arch = "x86")] use super::super::conv::by_mut; -use super::super::conv::{c_int, c_uint, ret, ret_c_uint, ret_error, ret_usize_infallible, zero}; +use super::super::conv::{ + by_ref, c_int, c_uint, ret, ret_c_int, ret_c_uint, ret_error, ret_usize_infallible, size_of, + zero, +}; #[cfg(feature = "fs")] use crate::fd::BorrowedFd; use crate::ffi::CStr; #[cfg(feature = "fs")] use crate::fs::AtFlags; use crate::io; -use crate::process::{Pid, RawNonZeroPid}; -use linux_raw_sys::general::{__kernel_pid_t, PR_SET_NAME, SIGCHLD}; +use crate::process::{Pid, RawNonZeroPid, Signal}; +use crate::runtime::{How, Sigaction, Siginfo, Sigset, Stack, Timespec}; +use crate::utils::optional_as_ptr; +#[cfg(target_pointer_width = "32")] +use core::convert::TryInto; +use core::mem::MaybeUninit; +#[cfg(target_pointer_width = "32")] +use linux_raw_sys::general::__kernel_old_timespec; +use linux_raw_sys::general::{__kernel_pid_t, kernel_sigset_t, PR_SET_NAME, SIGCHLD}; #[cfg(target_arch = "x86_64")] use {super::super::conv::ret_infallible, linux_raw_sys::general::ARCH_SET_FS}; @@ -105,3 +115,135 @@ pub(crate) mod tls { unsafe { syscall_noreturn!(__NR_exit, c_int(code)) } } } + +#[inline] +pub(crate) unsafe fn sigaction(signal: Signal, new: Option<Sigaction>) -> io::Result<Sigaction> { + let mut old = MaybeUninit::<Sigaction>::uninit(); + let new = optional_as_ptr(new.as_ref()); + ret(syscall!( + __NR_rt_sigaction, + signal, + new, + &mut old, + size_of::<kernel_sigset_t, _>() + ))?; + Ok(old.assume_init()) +} + +#[inline] +pub(crate) unsafe fn sigaltstack(new: Option<Stack>) -> io::Result<Stack> { + let mut old = MaybeUninit::<Stack>::uninit(); + let new = optional_as_ptr(new.as_ref()); + ret(syscall!(__NR_sigaltstack, new, &mut old))?; + Ok(old.assume_init()) +} + +#[inline] +pub(crate) unsafe fn tkill(tid: Pid, sig: Signal) -> io::Result<()> { + ret(syscall_readonly!(__NR_tkill, tid, sig)) +} + +#[inline] +pub(crate) unsafe fn sigprocmask(how: How, set: &Sigset) -> io::Result<Sigset> { + let mut old = MaybeUninit::<Sigset>::uninit(); + ret(syscall!( + __NR_rt_sigprocmask, + how, + by_ref(set), + &mut old, + size_of::<kernel_sigset_t, _>() + ))?; + Ok(old.assume_init()) +} + +#[inline] +pub(crate) fn sigwait(set: &Sigset) -> io::Result<Signal> { + unsafe { + match Signal::from_raw(ret_c_int(syscall_readonly!( + __NR_rt_sigtimedwait, + by_ref(set), + zero(), + zero(), + size_of::<kernel_sigset_t, _>() + ))?) { + Some(signum) => Ok(signum), + None => Err(io::Errno::NOTSUP), + } + } +} + +#[inline] +pub(crate) fn sigwaitinfo(set: &Sigset) -> io::Result<Siginfo> { + let mut info = MaybeUninit::<Siginfo>::uninit(); + unsafe { + let _signum = ret_c_int(syscall!( + __NR_rt_sigtimedwait, + by_ref(set), + &mut info, + zero(), + size_of::<kernel_sigset_t, _>() + ))?; + Ok(info.assume_init()) + } +} + +#[inline] +pub(crate) fn sigtimedwait(set: &Sigset, timeout: Option<Timespec>) -> io::Result<Siginfo> { + let mut info = MaybeUninit::<Siginfo>::uninit(); + let timeout_ptr = optional_as_ptr(timeout.as_ref()); + + #[cfg(target_pointer_width = "32")] + unsafe { + match ret_c_int(syscall!( + __NR_rt_sigtimedwait_time64, + by_ref(set), + &mut info, + timeout_ptr, + size_of::<kernel_sigset_t, _>() + )) { + Ok(_signum) => (), + Err(io::Errno::NOSYS) => sigtimedwait_old(set, timeout, &mut info)?, + Err(err) => return Err(err), + } + Ok(info.assume_init()) + } + + #[cfg(target_pointer_width = "64")] + unsafe { + let _signum = ret_c_int(syscall!( + __NR_rt_sigtimedwait, + by_ref(set), + &mut info, + timeout_ptr, + size_of::<kernel_sigset_t, _>() + ))?; + Ok(info.assume_init()) + } +} + +#[cfg(target_pointer_width = "32")] +unsafe fn sigtimedwait_old( + set: &Sigset, + timeout: Option<Timespec>, + info: &mut MaybeUninit<Siginfo>, +) -> io::Result<()> { + let old_timeout = match timeout { + Some(timeout) => Some(__kernel_old_timespec { + tv_sec: timeout.tv_sec.try_into().map_err(|_| io::Errno::OVERFLOW)?, + tv_nsec: timeout.tv_nsec as _, + }), + None => None, + }; + + let old_timeout_ptr = optional_as_ptr(old_timeout.as_ref()); + + let _signum = ret_c_int(syscall!( + __NR_rt_sigtimedwait, + by_ref(set), + info, + old_timeout_ptr, + size_of::<kernel_sigset_t, _>() + ))?; + + Ok(()) +} diff --git a/vendor/rustix/src/backend/linux_raw/termios/syscalls.rs b/vendor/rustix/src/backend/linux_raw/termios/syscalls.rs index f5643f3c3..3c8cbb0c9 100644 --- a/vendor/rustix/src/backend/linux_raw/termios/syscalls.rs +++ b/vendor/rustix/src/backend/linux_raw/termios/syscalls.rs @@ -207,9 +207,9 @@ pub(crate) fn cfgetispeed(termios: &Termios) -> u32 { #[inline] pub(crate) fn cfmakeraw(termios: &mut Termios) { - // From the Linux [`cfmakeraw` man page]: + // From the Linux [`cfmakeraw` manual page]: // - // [`cfmakeraw` man page]: https://man7.org/linux/man-pages/man3/cfmakeraw.3.html + // [`cfmakeraw` manual page]: https://man7.org/linux/man-pages/man3/cfmakeraw.3.html termios.c_iflag &= !(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON); termios.c_oflag &= !OPOST; termios.c_lflag &= !(ECHO | ECHONL | ICANON | ISIG | IEXTEN); @@ -269,7 +269,7 @@ pub(crate) fn ttyname(fd: BorrowedFd<'_>, buf: &mut [u8]) -> io::Result<usize> { // Quick check: if `fd` isn't a character device, it's not a tty. if FileType::from_raw_mode(fd_stat.st_mode) != FileType::CharacterDevice { - return Err(crate::io::Errno::NOTTY); + return Err(io::Errno::NOTTY); } // Check that `fd` is really a tty. @@ -295,7 +295,7 @@ pub(crate) fn ttyname(fd: BorrowedFd<'_>, buf: &mut [u8]) -> io::Result<usize> { let path_stat = super::super::fs::syscalls::stat(path)?; if path_stat.st_dev != fd_stat.st_dev || path_stat.st_ino != fd_stat.st_ino { - return Err(crate::io::Errno::NODEV); + return Err(io::Errno::NODEV); } Ok(r) diff --git a/vendor/rustix/src/backend/linux_raw/thread/syscalls.rs b/vendor/rustix/src/backend/linux_raw/thread/syscalls.rs index af2c9ee8a..1895c8c6d 100644 --- a/vendor/rustix/src/backend/linux_raw/thread/syscalls.rs +++ b/vendor/rustix/src/backend/linux_raw/thread/syscalls.rs @@ -302,7 +302,7 @@ pub(crate) fn capget( data: &mut [MaybeUninit<linux_raw_sys::general::__user_cap_data_struct>], ) -> io::Result<()> { let header: *mut _ = header; - unsafe { ret(syscall!(__NR_capget, header, data.as_mut_ptr())) } + unsafe { ret(syscall!(__NR_capget, header, data)) } } #[cfg(any(target_os = "android", target_os = "linux"))] diff --git a/vendor/rustix/src/backend/linux_raw/time/types.rs b/vendor/rustix/src/backend/linux_raw/time/types.rs index 5a0fcc6f5..fcdd7f6d6 100644 --- a/vendor/rustix/src/backend/linux_raw/time/types.rs +++ b/vendor/rustix/src/backend/linux_raw/time/types.rs @@ -114,7 +114,7 @@ bitflags! { #[repr(u32)] #[non_exhaustive] pub enum TimerfdClockId { - /// `CLOCK_REALTIME`—A clock that tells the "real" time. + /// `CLOCK_REALTIME`—A clock that tells the “real” time. /// /// This is a clock that tells the amount of time elapsed since the /// Unix epoch, 1970-01-01T00:00:00Z. The clock is externally settable, so diff --git a/vendor/rustix/src/backend/linux_raw/vdso.rs b/vendor/rustix/src/backend/linux_raw/vdso.rs index 480378b50..606aee7d1 100644 --- a/vendor/rustix/src/backend/linux_raw/vdso.rs +++ b/vendor/rustix/src/backend/linux_raw/vdso.rs @@ -117,7 +117,7 @@ fn init_from_sysinfo_ehdr() -> Option<Vdso> { .as_ptr(); num_dyn = phdr.p_memsz / size_of::<Elf_Dyn>(); } else if phdr.p_type == PT_INTERP || phdr.p_type == PT_GNU_RELRO { - // Don't trust any ELF image that has an "interpreter" or that uses + // Don't trust any ELF image that has an “interpreter” or that uses // RELRO, which is likely to be a user ELF image rather and not the // kernel vDSO. return None; diff --git a/vendor/rustix/src/backend/linux_raw/vdso_wrappers.rs b/vendor/rustix/src/backend/linux_raw/vdso_wrappers.rs index 5b2e084ea..97d5862a0 100644 --- a/vendor/rustix/src/backend/linux_raw/vdso_wrappers.rs +++ b/vendor/rustix/src/backend/linux_raw/vdso_wrappers.rs @@ -293,7 +293,7 @@ unsafe fn _rustix_clock_gettime_via_syscall( ret(syscall!(__NR_clock_gettime, c_int(clockid), res)) } -/// A symbol pointing to an `int 0x80` instruction. This "function" is only +/// A symbol pointing to an `int 0x80` instruction. This “function” is only /// called from assembly, and only with the x86 syscall calling convention, /// so its signature here is not its true signature. #[cfg(all(asm, target_arch = "x86"))] diff --git a/vendor/rustix/src/backend/linux_raw/weak.rs b/vendor/rustix/src/backend/linux_raw/weak.rs deleted file mode 100644 index ae7d6832e..000000000 --- a/vendor/rustix/src/backend/linux_raw/weak.rs +++ /dev/null @@ -1,228 +0,0 @@ -// Implementation derived from `weak` in Rust's -// library/std/src/sys/unix/weak.rs at revision -// fd0cb0cdc21dd9c06025277d772108f8d42cb25f. - -#![allow(unsafe_code)] - -//! Support for "weak linkage" to symbols on Unix -//! -//! Some I/O operations we do in libstd require newer versions of OSes but we -//! need to maintain binary compatibility with older releases for now. In order -//! to use the new functionality when available we use this module for -//! detection. -//! -//! One option to use here is weak linkage, but that is unfortunately only -//! really workable on Linux. Hence, use dlsym to get the symbol value at -//! runtime. This is also done for compatibility with older versions of glibc, -//! and to avoid creating dependencies on `GLIBC_PRIVATE` symbols. It assumes -//! that we've been dynamically linked to the library the symbol comes from, -//! but that is currently always the case for things like libpthread/libc. -//! -//! A long time ago this used weak linkage for the `__pthread_get_minstack` -//! symbol, but that caused Debian to detect an unnecessarily strict versioned -//! dependency on libc6 (#23628). - -// There are a variety of `#[cfg]`s controlling which targets are involved in -// each instance of `weak!` and `syscall!`. Rather than trying to unify all of -// that, we'll just allow that some unix targets don't use this module at all. -#![allow(dead_code, unused_macros)] -#![allow(clippy::doc_markdown)] - -use crate::ffi::CStr; -use core::ffi::c_void; -use core::ptr::null_mut; -use core::sync::atomic::{self, AtomicPtr, Ordering}; -use core::{marker, mem}; - -const NULL: *mut c_void = null_mut(); -const INVALID: *mut c_void = 1 as *mut c_void; - -macro_rules! weak { - ($vis:vis fn $name:ident($($t:ty),*) -> $ret:ty) => ( - #[allow(non_upper_case_globals)] - $vis static $name: $crate::backend::weak::Weak<unsafe extern fn($($t),*) -> $ret> = - $crate::backend::weak::Weak::new(concat!(stringify!($name), '\0')); - ) -} - -pub(crate) struct Weak<F> { - name: &'static str, - addr: AtomicPtr<c_void>, - _marker: marker::PhantomData<F>, -} - -impl<F> Weak<F> { - pub(crate) const fn new(name: &'static str) -> Self { - Self { - name, - addr: AtomicPtr::new(INVALID), - _marker: marker::PhantomData, - } - } - - pub(crate) fn get(&self) -> Option<F> { - assert_eq!(mem::size_of::<F>(), mem::size_of::<usize>()); - unsafe { - // Relaxed is fine here because we fence before reading through the - // pointer (see the comment below). - match self.addr.load(Ordering::Relaxed) { - INVALID => self.initialize(), - NULL => None, - addr => { - let func = mem::transmute_copy::<*mut c_void, F>(&addr); - // The caller is presumably going to read through this value - // (by calling the function we've dlsymed). This means we'd - // need to have loaded it with at least C11's consume - // ordering in order to be guaranteed that the data we read - // from the pointer isn't from before the pointer was - // stored. Rust has no equivalent to memory_order_consume, - // so we use an acquire fence (sorry, ARM). - // - // Now, in practice this likely isn't needed even on CPUs - // where relaxed and consume mean different things. The - // symbols we're loading are probably present (or not) at - // init, and even if they aren't the runtime dynamic loader - // is extremely likely have sufficient barriers internally - // (possibly implicitly, for example the ones provided by - // invoking `mprotect`). - // - // That said, none of that's *guaranteed*, and so we fence. - atomic::fence(Ordering::Acquire); - Some(func) - } - } - } - } - - // Cold because it should only happen during first-time initialization. - #[cold] - unsafe fn initialize(&self) -> Option<F> { - let val = fetch(self.name); - // This synchronizes with the acquire fence in `get`. - self.addr.store(val, Ordering::Release); - - match val { - NULL => None, - addr => Some(mem::transmute_copy::<*mut c_void, F>(&addr)), - } - } -} - -unsafe fn fetch(name: &str) -> *mut c_void { - let name = match CStr::from_bytes_with_nul(name.as_bytes()) { - Ok(c_str) => c_str, - Err(..) => return null_mut(), - }; - libc::dlsym(libc::RTLD_DEFAULT, name.as_ptr()) -} - -#[cfg(not(any(target_os = "android", target_os = "linux")))] -macro_rules! syscall { - (fn $name:ident($($arg_name:ident: $t:ty),*) via $_sys_name:ident -> $ret:ty) => ( - unsafe fn $name($($arg_name: $t),*) -> $ret { - weak! { fn $name($($t),*) -> $ret } - - if let Some(fun) = $name.get() { - fun($($arg_name),*) - } else { - libc_errno::set_errno(libc_errno::Errno(libc::ENOSYS)); - -1 - } - } - ) -} - -#[cfg(any(target_os = "android", target_os = "linux"))] -macro_rules! syscall { - (fn $name:ident($($arg_name:ident: $t:ty),*) via $sys_name:ident -> $ret:ty) => ( - unsafe fn $name($($arg_name:$t),*) -> $ret { - // This looks like a hack, but concat_idents only accepts idents - // (not paths). - use libc::*; - - trait AsSyscallArg { - type SyscallArgType; - fn into_syscall_arg(self) -> Self::SyscallArgType; - } - - // Pass pointer types as pointers, to preserve provenance. - impl<T> AsSyscallArg for *mut T { - type SyscallArgType = *mut T; - fn into_syscall_arg(self) -> Self::SyscallArgType { self } - } - impl<T> AsSyscallArg for *const T { - type SyscallArgType = *const T; - fn into_syscall_arg(self) -> Self::SyscallArgType { self } - } - - // Pass `BorrowedFd` values as the integer value. - impl AsSyscallArg for $crate::fd::BorrowedFd<'_> { - type SyscallArgType = c::c_long; - fn into_syscall_arg(self) -> Self::SyscallArgType { - $crate::fd::AsRawFd::as_raw_fd(&self) as _ - } - } - - // Coerce integer values into `c_long`. - impl AsSyscallArg for i32 { - type SyscallArgType = c::c_long; - fn into_syscall_arg(self) -> Self::SyscallArgType { self as _ } - } - impl AsSyscallArg for u32 { - type SyscallArgType = c::c_long; - fn into_syscall_arg(self) -> Self::SyscallArgType { self as _ } - } - impl AsSyscallArg for usize { - type SyscallArgType = c::c_long; - fn into_syscall_arg(self) -> Self::SyscallArgType { self as _ } - } - - // `concat_idents is unstable, so we take an extra `sys_name` - // parameter and have our users do the concat for us for now. - /* - syscall( - concat_idents!(SYS_, $name), - $($arg_name.into_syscall_arg()),* - ) as $ret - */ - - syscall($sys_name, $($arg_name.into_syscall_arg()),*) as $ret - } - ) -} - -macro_rules! weakcall { - ($vis:vis fn $name:ident($($arg_name:ident: $t:ty),*) -> $ret:ty) => ( - $vis unsafe fn $name($($arg_name: $t),*) -> $ret { - weak! { fn $name($($t),*) -> $ret } - - // Use a weak symbol from libc when possible, allowing `LD_PRELOAD` - // interposition, but if it's not found just fail. - if let Some(fun) = $name.get() { - fun($($arg_name),*) - } else { - libc_errno::set_errno(libc_errno::Errno(libc::ENOSYS)); - -1 - } - } - ) -} - -/// A combination of `weakcall` and `syscall`. Use the libc function if it's -/// available, and fall back to `libc::syscall` otherwise. -macro_rules! weak_or_syscall { - ($vis:vis fn $name:ident($($arg_name:ident: $t:ty),*) via $sys_name:ident -> $ret:ty) => ( - $vis unsafe fn $name($($arg_name: $t),*) -> $ret { - weak! { fn $name($($t),*) -> $ret } - - // Use a weak symbol from libc when possible, allowing `LD_PRELOAD` - // interposition, but if it's not found just fail. - if let Some(fun) = $name.get() { - fun($($arg_name),*) - } else { - syscall! { fn $name($($arg_name: $t),*) via $sys_name -> $ret } - $name($($arg_name),*) - } - } - ) -} |