From 9835e2ae736235810b4ea1c162ca5e65c547e770 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 18 May 2024 04:49:50 +0200 Subject: Merging upstream version 1.71.1+dfsg1. Signed-off-by: Daniel Baumann --- vendor/rustix/src/backend/libc/conv.rs | 18 +- vendor/rustix/src/backend/libc/fs/dir.rs | 172 ++--------- vendor/rustix/src/backend/libc/fs/syscalls.rs | 342 ++++++++++++++++++--- vendor/rustix/src/backend/libc/fs/types.rs | 35 ++- vendor/rustix/src/backend/libc/io/syscalls.rs | 192 ++++++------ vendor/rustix/src/backend/libc/io/types.rs | 11 +- vendor/rustix/src/backend/libc/mm/types.rs | 2 +- vendor/rustix/src/backend/libc/mod.rs | 4 - vendor/rustix/src/backend/libc/net/send_recv.rs | 10 +- vendor/rustix/src/backend/libc/net/syscalls.rs | 118 ++++--- vendor/rustix/src/backend/libc/net/types.rs | 26 +- vendor/rustix/src/backend/libc/offset.rs | 20 +- vendor/rustix/src/backend/libc/process/syscalls.rs | 94 +++++- vendor/rustix/src/backend/libc/process/types.rs | 27 +- vendor/rustix/src/backend/libc/rand/syscalls.rs | 6 +- vendor/rustix/src/backend/libc/termios/syscalls.rs | 4 +- vendor/rustix/src/backend/libc/termios/types.rs | 230 ++++++-------- vendor/rustix/src/backend/libc/time/types.rs | 22 +- vendor/rustix/src/backend/libc/weak.rs | 226 -------------- vendor/rustix/src/backend/libc/winsock_c.rs | 73 ++--- .../src/backend/linux_raw/arch/inline/mod.rs | 4 + .../src/backend/linux_raw/arch/outline/mod.rs | 12 +- vendor/rustix/src/backend/linux_raw/c.rs | 20 +- vendor/rustix/src/backend/linux_raw/conv.rs | 32 +- vendor/rustix/src/backend/linux_raw/fs/inotify.rs | 2 +- vendor/rustix/src/backend/linux_raw/fs/syscalls.rs | 168 +++++++++- vendor/rustix/src/backend/linux_raw/fs/types.rs | 5 +- vendor/rustix/src/backend/linux_raw/io/errno.rs | 2 +- vendor/rustix/src/backend/linux_raw/io/syscalls.rs | 4 +- vendor/rustix/src/backend/linux_raw/mm/types.rs | 2 +- vendor/rustix/src/backend/linux_raw/mod.rs | 5 - .../rustix/src/backend/linux_raw/net/send_recv.rs | 10 +- .../rustix/src/backend/linux_raw/net/syscalls.rs | 61 +++- vendor/rustix/src/backend/linux_raw/net/types.rs | 25 +- .../src/backend/linux_raw/process/syscalls.rs | 97 +++++- .../rustix/src/backend/linux_raw/process/types.rs | 9 +- .../rustix/src/backend/linux_raw/process/wait.rs | 31 +- .../src/backend/linux_raw/runtime/syscalls.rs | 148 ++++++++- .../src/backend/linux_raw/termios/syscalls.rs | 8 +- .../src/backend/linux_raw/thread/syscalls.rs | 2 +- vendor/rustix/src/backend/linux_raw/time/types.rs | 2 +- vendor/rustix/src/backend/linux_raw/vdso.rs | 2 +- .../rustix/src/backend/linux_raw/vdso_wrappers.rs | 2 +- vendor/rustix/src/backend/linux_raw/weak.rs | 228 -------------- 44 files changed, 1397 insertions(+), 1116 deletions(-) delete mode 100644 vendor/rustix/src/backend/libc/weak.rs delete mode 100644 vendor/rustix/src/backend/linux_raw/weak.rs (limited to 'vendor/rustix/src/backend') diff --git a/vendor/rustix/src/backend/libc/conv.rs b/vendor/rustix/src/backend/libc/conv.rs index 1e74ea9ba..b827d0bbc 100644 --- a/vendor/rustix/src/backend/libc/conv.rs +++ b/vendor/rustix/src/backend/libc/conv.rs @@ -88,20 +88,22 @@ pub(super) fn ret_u32(raw: c::c_int) -> io::Result { } #[inline] -pub(super) fn ret_ssize_t(raw: c::ssize_t) -> io::Result { +pub(super) fn ret_usize(raw: c::ssize_t) -> io::Result { if raw == -1 { Err(io::Errno::last_os_error()) } else { - Ok(raw) + debug_assert!(raw >= 0); + Ok(raw as usize) } } #[inline] -pub(super) fn syscall_ret_ssize_t(raw: c::c_long) -> io::Result { +pub(super) fn syscall_ret_usize(raw: c::c_long) -> io::Result { if raw == -1 { Err(io::Errno::last_os_error()) } else { - Ok(raw as c::ssize_t) + debug_assert!(raw >= 0); + Ok(raw as c::ssize_t as usize) } } @@ -210,13 +212,13 @@ pub(super) fn send_recv_len(len: usize) -> i32 { /// Convert the return value of a `send` or `recv` call. #[cfg(not(windows))] #[inline] -pub(super) fn ret_send_recv(len: isize) -> io::Result { - ret_ssize_t(len) +pub(super) fn ret_send_recv(len: isize) -> io::Result { + ret_usize(len) } /// Convert the return value of a `send` or `recv` call. #[cfg(windows)] #[inline] -pub(super) fn ret_send_recv(len: i32) -> io::Result { - ret_ssize_t(len as isize) +pub(super) fn ret_send_recv(len: i32) -> io::Result { + ret_usize(len as isize) } diff --git a/vendor/rustix/src/backend/libc/fs/dir.rs b/vendor/rustix/src/backend/libc/fs/dir.rs index d1c901323..b6eb32580 100644 --- a/vendor/rustix/src/backend/libc/fs/dir.rs +++ b/vendor/rustix/src/backend/libc/fs/dir.rs @@ -1,11 +1,10 @@ use super::super::c; use super::super::conv::owned_fd; +use super::super::offset::libc_ino_t; #[cfg(not(any(solarish, target_os = "haiku")))] use super::types::FileType; use crate::fd::{AsFd, BorrowedFd}; -use crate::ffi::CStr; -#[cfg(target_os = "wasi")] -use crate::ffi::CString; +use crate::ffi::{CStr, CString}; use crate::fs::{fcntl_getfl, fstat, openat, Mode, OFlags, Stat}; #[cfg(not(any( solarish, @@ -22,14 +21,11 @@ use crate::io; use crate::process::fchdir; #[cfg(target_os = "wasi")] use alloc::borrow::ToOwned; -#[cfg(not(any(linux_like, target_os = "openbsd")))] -use c::dirent as libc_dirent; #[cfg(not(linux_like))] use c::readdir as libc_readdir; #[cfg(linux_like)] -use c::{dirent64 as libc_dirent, readdir64 as libc_readdir}; +use c::readdir64 as libc_readdir; use core::fmt; -use core::mem::zeroed; use core::ptr::NonNull; use libc_errno::{errno, set_errno, Errno}; @@ -91,16 +87,24 @@ impl Dir { } else { // We successfully read an entry. unsafe { + let dirent = &*dirent_ptr; + // We have our own copy of OpenBSD's dirent; check that the // layout minimally matches libc's. #[cfg(target_os = "openbsd")] - check_dirent_layout(&*dirent_ptr); + check_dirent_layout(dirent); let result = DirEntry { - dirent: read_dirent(&*dirent_ptr.cast()), + #[cfg(not(any(solarish, target_os = "aix", target_os = "haiku")))] + d_type: dirent.d_type, + + #[cfg(not(any(freebsdlike, netbsdlike)))] + d_ino: dirent.d_ino, + + #[cfg(any(freebsdlike, netbsdlike))] + d_fileno: dirent.d_fileno, - #[cfg(target_os = "wasi")] - name: CStr::from_ptr((*dirent_ptr).d_name.as_ptr()).to_owned(), + name: CStr::from_ptr(dirent.d_name.as_ptr()).to_owned(), }; Some(Ok(result)) @@ -142,130 +146,6 @@ impl Dir { } } -// A `dirent` pointer returned from `readdir` may not point to a full `dirent` -// struct, as the name is NUL-terminated and memory may not be allocated for -// the full extent of the struct. Copy the fields one at a time. -unsafe fn read_dirent(input: &libc_dirent) -> libc_dirent { - #[cfg(not(any(solarish, target_os = "aix", target_os = "haiku")))] - let d_type = input.d_type; - - #[cfg(not(any( - apple, - freebsdlike, - target_os = "aix", - target_os = "haiku", - target_os = "netbsd", - target_os = "wasi", - )))] - let d_off = input.d_off; - - #[cfg(target_os = "aix")] - let d_offset = input.d_offset; - - #[cfg(not(any(freebsdlike, netbsdlike)))] - let d_ino = input.d_ino; - - #[cfg(any(freebsdlike, netbsdlike))] - let d_fileno = input.d_fileno; - - #[cfg(not(any(target_os = "dragonfly", target_os = "wasi")))] - let d_reclen = input.d_reclen; - - #[cfg(any(bsd, target_os = "aix"))] - let d_namlen = input.d_namlen; - - #[cfg(apple)] - let d_seekoff = input.d_seekoff; - - #[cfg(target_os = "haiku")] - let d_dev = input.d_dev; - #[cfg(target_os = "haiku")] - let d_pdev = input.d_pdev; - #[cfg(target_os = "haiku")] - let d_pino = input.d_pino; - - // Construct the input. Rust will give us an error if any OS has a input - // with a field that we missed here. And we can avoid blindly copying the - // whole `d_name` field, which may not be entirely allocated. - #[cfg_attr(target_os = "wasi", allow(unused_mut))] - #[cfg(not(freebsdlike))] - let mut dirent = libc_dirent { - #[cfg(not(any(solarish, target_os = "aix", target_os = "haiku")))] - d_type, - #[cfg(not(any( - apple, - target_os = "aix", - target_os = "freebsd", // Until FreeBSD 12 - target_os = "haiku", - target_os = "netbsd", - target_os = "wasi", - )))] - d_off, - #[cfg(target_os = "aix")] - d_offset, - #[cfg(not(any(netbsdlike, target_os = "freebsd")))] - d_ino, - #[cfg(any(netbsdlike, target_os = "freebsd"))] - d_fileno, - #[cfg(not(target_os = "wasi"))] - d_reclen, - #[cfg(any(apple, netbsdlike, target_os = "aix", target_os = "freebsd"))] - d_namlen, - #[cfg(apple)] - d_seekoff, - // The `d_name` field is NUL-terminated, and we need to be careful not - // to read bytes past the NUL, even though they're within the nominal - // extent of the `struct dirent`, because they may not be allocated. So - // don't read it from `dirent_ptr`. - // - // In theory this could use `MaybeUninit::uninit().assume_init()`, but - // that [invokes undefined behavior]. - // - // [invokes undefined behavior]: https://doc.rust-lang.org/stable/core/mem/union.MaybeUninit.html#initialization-invariant - d_name: zeroed(), - #[cfg(target_os = "openbsd")] - __d_padding: zeroed(), - #[cfg(target_os = "haiku")] - d_dev, - #[cfg(target_os = "haiku")] - d_pdev, - #[cfg(target_os = "haiku")] - d_pino, - }; - /* - pub d_ino: ino_t, - pub d_pino: i64, - pub d_reclen: ::c_ushort, - pub d_name: [::c_char; 1024], // Max length is _POSIX_PATH_MAX - */ - - // On dragonfly and FreeBSD 12, `dirent` has some non-public padding fields - // so we can't directly initialize it. - #[cfg(freebsdlike)] - let mut dirent = { - let mut dirent: libc_dirent = zeroed(); - dirent.d_fileno = d_fileno; - dirent.d_namlen = d_namlen; - dirent.d_type = d_type; - #[cfg(target_os = "freebsd")] - { - dirent.d_reclen = d_reclen; - } - dirent - }; - - // Copy from d_name, reading up to and including the first NUL. - #[cfg(not(target_os = "wasi"))] - { - let name_len = CStr::from_ptr(input.d_name.as_ptr()) - .to_bytes_with_nul() - .len(); - dirent.d_name[..name_len].copy_from_slice(&input.d_name[..name_len]); - } - - dirent -} - /// `Dir` implements `Send` but not `Sync`, because we use `readdir` which is /// not guaranteed to be thread-safe. Users can wrap this in a `Mutex` if they /// need `Sync`, which is effectively what'd need to do to implement `Sync` @@ -299,9 +179,15 @@ impl fmt::Debug for Dir { /// `struct dirent` #[derive(Debug)] pub struct DirEntry { - dirent: libc_dirent, + #[cfg(not(any(solarish, target_os = "aix", target_os = "haiku")))] + d_type: u8, + + #[cfg(not(any(freebsdlike, netbsdlike)))] + d_ino: libc_ino_t, + + #[cfg(any(freebsdlike, netbsdlike))] + d_fileno: libc_ino_t, - #[cfg(target_os = "wasi")] name: CString, } @@ -309,12 +195,6 @@ impl DirEntry { /// Returns the file name of this directory entry. #[inline] pub fn file_name(&self) -> &CStr { - #[cfg(not(target_os = "wasi"))] - unsafe { - CStr::from_ptr(self.dirent.d_name.as_ptr()) - } - - #[cfg(target_os = "wasi")] &self.name } @@ -322,14 +202,14 @@ impl DirEntry { #[cfg(not(any(solarish, target_os = "aix", target_os = "haiku")))] #[inline] pub fn file_type(&self) -> FileType { - FileType::from_dirent_d_type(self.dirent.d_type) + FileType::from_dirent_d_type(self.d_type) } /// Return the inode number of this directory entry. #[cfg(not(any(freebsdlike, netbsdlike)))] #[inline] pub fn ino(&self) -> u64 { - self.dirent.d_ino as u64 + self.d_ino as u64 } /// Return the inode number of this directory entry. @@ -337,7 +217,7 @@ impl DirEntry { #[inline] pub fn ino(&self) -> u64 { #[allow(clippy::useless_conversion)] - self.dirent.d_fileno.into() + self.d_fileno.into() } } diff --git a/vendor/rustix/src/backend/libc/fs/syscalls.rs b/vendor/rustix/src/backend/libc/fs/syscalls.rs index 77b49ee3e..40c160182 100644 --- a/vendor/rustix/src/backend/libc/fs/syscalls.rs +++ b/vendor/rustix/src/backend/libc/fs/syscalls.rs @@ -1,11 +1,9 @@ //! libc syscalls supporting `rustix::fs`. use super::super::c; -use super::super::conv::{ - borrowed_fd, c_str, ret, ret_c_int, ret_off_t, ret_owned_fd, ret_ssize_t, -}; +use super::super::conv::{borrowed_fd, c_str, ret, ret_c_int, ret_off_t, ret_owned_fd, ret_usize}; #[cfg(any(target_os = "android", target_os = "linux"))] -use super::super::conv::{syscall_ret, syscall_ret_owned_fd, syscall_ret_ssize_t}; +use super::super::conv::{syscall_ret, syscall_ret_owned_fd, syscall_ret_usize}; #[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))] use super::super::offset::libc_fallocate; #[cfg(not(any( @@ -38,7 +36,7 @@ use super::super::offset::{libc_fstat, libc_fstatat, libc_ftruncate, libc_lseek, target_os = "wasi", )))] use super::super::offset::{libc_fstatfs, libc_statfs}; -#[cfg(not(any(solarish, target_os = "haiku", target_os = "redox", target_os = "wasi")))] +#[cfg(not(any(target_os = "haiku", target_os = "redox", target_os = "wasi")))] use super::super::offset::{libc_fstatvfs, libc_statvfs}; #[cfg(all( any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), @@ -49,8 +47,6 @@ use crate::fd::{BorrowedFd, OwnedFd}; use crate::ffi::CStr; #[cfg(apple)] use crate::ffi::CString; -#[cfg(not(solarish))] -use crate::fs::Access; #[cfg(not(any( apple, netbsdlike, @@ -87,12 +83,14 @@ use crate::fs::SealFlags; target_os = "wasi", )))] use crate::fs::StatFs; +#[cfg(any(apple, target_os = "android", target_os = "linux"))] +use crate::fs::XattrFlags; #[cfg(any(target_os = "android", target_os = "linux"))] use crate::fs::{cwd, RenameFlags, ResolveFlags, Statx, StatxFlags}; +use crate::fs::{Access, Mode, OFlags, Stat, Timestamps}; #[cfg(not(any(apple, target_os = "redox", target_os = "wasi")))] use crate::fs::{Dev, FileType}; -use crate::fs::{Mode, OFlags, Stat, Timestamps}; -#[cfg(not(any(solarish, target_os = "haiku", target_os = "redox", target_os = "wasi")))] +#[cfg(not(any(target_os = "haiku", target_os = "redox", target_os = "wasi")))] use crate::fs::{StatVfs, StatVfsMountFlags}; use crate::io::{self, SeekFrom}; #[cfg(not(target_os = "wasi"))] @@ -162,7 +160,7 @@ pub(crate) fn openat( mode: Mode, ) -> io::Result { // Work around . - // GLIBC versions before 2.25 don't handle `O_TMPFILE` correctly. + // glibc versions before 2.25 don't handle `O_TMPFILE` correctly. #[cfg(all(unix, target_env = "gnu"))] if oflags.contains(OFlags::TMPFILE) && crate::backend::if_glibc_is_less_than_2_25() { return openat_via_syscall(dirfd, path, oflags, mode); @@ -196,7 +194,7 @@ pub(crate) fn statfs(filename: &CStr) -> io::Result { } } -#[cfg(not(any(solarish, target_os = "haiku", target_os = "redox", target_os = "wasi")))] +#[cfg(not(any(target_os = "haiku", target_os = "redox", target_os = "wasi")))] #[inline] pub(crate) fn statvfs(filename: &CStr) -> io::Result { unsafe { @@ -210,13 +208,12 @@ pub(crate) fn statvfs(filename: &CStr) -> io::Result { #[inline] pub(crate) fn readlinkat(dirfd: BorrowedFd<'_>, path: &CStr, buf: &mut [u8]) -> io::Result { unsafe { - ret_ssize_t(c::readlinkat( + ret_usize(c::readlinkat( borrowed_fd(dirfd), c_str(path), buf.as_mut_ptr().cast::(), buf.len(), )) - .map(|nread| nread as usize) } } @@ -237,14 +234,13 @@ pub(crate) fn getdents_uninit( buf: &mut [MaybeUninit], ) -> io::Result { unsafe { - syscall_ret_ssize_t(c::syscall( + syscall_ret_usize(c::syscall( c::SYS_getdents64, fd, buf.as_mut_ptr().cast::(), buf.len(), )) } - .map(|nread| nread as usize) } #[cfg(not(target_os = "redox"))] @@ -402,7 +398,7 @@ fn statat_old(dirfd: BorrowedFd<'_>, path: &CStr, flags: AtFlags) -> io::Result< } } -#[cfg(not(any(solarish, target_os = "emscripten", target_os = "redox")))] +#[cfg(not(any(target_os = "emscripten", target_os = "redox")))] pub(crate) fn accessat( dirfd: BorrowedFd<'_>, path: &CStr, @@ -549,7 +545,7 @@ pub(crate) fn utimensat( flags_arg, ) != 0 { - // Translate expected errno codes into ad-hoc integer + // Translate expected `errno` codes into ad-hoc integer // values suitable for exit statuses. let code = match libc_errno::errno().0 { c::EACCES => 2, @@ -573,7 +569,8 @@ pub(crate) fn utimensat( let mut wstatus = 0; let _ = ret_c_int(c::waitpid(child_pid, &mut wstatus, 0))?; if c::WIFEXITED(wstatus) { - // Translate our ad-hoc exit statuses back to errno codes. + // Translate our ad-hoc exit statuses back to `errno` + // codes. match c::WEXITSTATUS(wstatus) { 0 => Ok(()), 2 => Err(io::Errno::ACCESS), @@ -769,7 +766,7 @@ pub(crate) fn copy_file_range( null_mut() }; let copied = unsafe { - syscall_ret_ssize_t(c::syscall( + syscall_ret_usize(c::syscall( c::SYS_copy_file_range, borrowed_fd(fd_in), off_in_ptr, @@ -785,7 +782,7 @@ pub(crate) fn copy_file_range( if let Some(off_out) = off_out { *off_out = off_out_val as u64; } - Ok(copied as usize) + Ok(copied) } #[cfg(not(any( @@ -961,23 +958,23 @@ pub(crate) fn flock(fd: BorrowedFd<'_>, operation: FlockOperation) -> io::Result #[cfg(any(target_os = "android", target_os = "linux"))] pub(crate) fn syncfs(fd: BorrowedFd<'_>) -> io::Result<()> { - unsafe { ret(c::syncfs(borrowed_fd(fd))) } -} - -#[cfg(not(any(solarish, target_os = "redox", target_os = "wasi")))] -pub(crate) fn sync() { - // TODO: Remove this when upstream libc adds `sync`. + // Some versions of Android libc lack a `syncfs` function. #[cfg(target_os = "android")] unsafe { - syscall_ret(c::syscall(c::SYS_sync)).ok(); + syscall_ret(c::syscall(c::SYS_syncfs, borrowed_fd(fd))) } #[cfg(not(target_os = "android"))] unsafe { - c::sync() + ret(c::syncfs(borrowed_fd(fd))) } } +#[cfg(not(any(target_os = "redox", target_os = "wasi")))] +pub(crate) fn sync() { + unsafe { c::sync() } +} + pub(crate) fn fstat(fd: BorrowedFd<'_>) -> io::Result { // 32-bit and mips64 Linux: `struct stat64` is not y2038 compatible; use // `statx`. @@ -1033,7 +1030,7 @@ pub(crate) fn fstatfs(fd: BorrowedFd<'_>) -> io::Result { } } -#[cfg(not(any(solarish, target_os = "haiku", target_os = "redox", target_os = "wasi")))] +#[cfg(not(any(target_os = "haiku", target_os = "redox", target_os = "wasi")))] pub(crate) fn fstatvfs(fd: BorrowedFd<'_>) -> io::Result { let mut statvfs = MaybeUninit::::uninit(); unsafe { @@ -1042,7 +1039,7 @@ pub(crate) fn fstatvfs(fd: BorrowedFd<'_>) -> io::Result { } } -#[cfg(not(any(solarish, target_os = "haiku", target_os = "redox", target_os = "wasi")))] +#[cfg(not(any(target_os = "haiku", target_os = "redox", target_os = "wasi")))] fn libc_statvfs_to_statvfs(from: libc_statvfs) -> StatVfs { StatVfs { f_bsize: from.f_bsize as u64, @@ -1322,13 +1319,12 @@ pub(crate) fn sendfile( count: usize, ) -> io::Result { unsafe { - let nsent = ret_ssize_t(c::sendfile64( + ret_usize(c::sendfile64( borrowed_fd(out_fd), borrowed_fd(in_fd), offset.map_or(null_mut(), crate::utils::as_mut_ptr).cast(), count, - ))?; - Ok(nsent as usize) + )) } } @@ -1525,7 +1521,7 @@ pub(crate) fn statx( // // [it's deprecated]: https://patchwork.kernel.org/project/linux-fsdevel/patch/20200505095915.11275-7-mszeredi@redhat.com/ #[cfg(not(any(target_os = "android", target_env = "musl")))] - const STATX__RESERVED: u32 = libc::STATX__RESERVED as u32; + const STATX__RESERVED: u32 = c::STATX__RESERVED as u32; #[cfg(any(target_os = "android", target_env = "musl"))] const STATX__RESERVED: u32 = linux_raw_sys::general::STATX__RESERVED; if (mask.bits() & STATX__RESERVED) == STATX__RESERVED { @@ -1638,11 +1634,11 @@ pub(crate) fn getpath(fd: BorrowedFd<'_>) -> io::Result { // instead. let mut buf = alloc::vec![0; c::PATH_MAX as usize]; - // From the [macOS `fcntl` man page]: + // From the [macOS `fcntl` manual page]: // `F_GETPATH` - Get the path of the file descriptor `Fildes`. The argument // must be a buffer of size `MAXPATHLEN` or greater. // - // [macOS `fcntl` man page]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/fcntl.2.html + // [macOS `fcntl` manual page]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/fcntl.2.html unsafe { ret(c::fcntl(borrowed_fd(fd), c::F_GETPATH, buf.as_mut_ptr()))?; } @@ -1659,7 +1655,7 @@ pub(crate) fn getpath(fd: BorrowedFd<'_>) -> io::Result { #[cfg(apple)] pub(crate) fn fcntl_rdadvise(fd: BorrowedFd<'_>, offset: u64, len: u64) -> io::Result<()> { - // From the [macOS `fcntl` man page]: + // From the [macOS `fcntl` manual page]: // `F_RDADVISE` - Issue an advisory read async with no copy to user. // // The `F_RDADVISE` command operates on the following structure which holds @@ -1672,7 +1668,7 @@ pub(crate) fn fcntl_rdadvise(fd: BorrowedFd<'_>, offset: u64, len: u64) -> io::R // }; // ``` // - // [macOS `fcntl` man page]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/fcntl.2.html + // [macOS `fcntl` manual page]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/fcntl.2.html let ra_offset = match offset.try_into() { Ok(len) => len, // If this conversion fails, the user is providing an offset outside @@ -1808,3 +1804,273 @@ pub(crate) fn mount( pub(crate) fn unmount(target: &CStr, flags: super::types::UnmountFlags) -> io::Result<()> { unsafe { ret(c::umount2(target.as_ptr(), flags.bits())) } } + +#[cfg(any(apple, target_os = "android", target_os = "linux"))] +pub(crate) fn getxattr(path: &CStr, name: &CStr, value: &mut [u8]) -> io::Result { + let value_ptr = value.as_mut_ptr(); + + #[cfg(not(apple))] + unsafe { + ret_usize(c::getxattr( + path.as_ptr(), + name.as_ptr(), + value_ptr.cast::(), + value.len(), + )) + } + + #[cfg(apple)] + unsafe { + ret_usize(c::getxattr( + path.as_ptr(), + name.as_ptr(), + value_ptr.cast::(), + value.len(), + 0, + 0, + )) + } +} + +#[cfg(any(apple, target_os = "android", target_os = "linux"))] +pub(crate) fn lgetxattr(path: &CStr, name: &CStr, value: &mut [u8]) -> io::Result { + let value_ptr = value.as_mut_ptr(); + + #[cfg(not(apple))] + unsafe { + ret_usize(c::lgetxattr( + path.as_ptr(), + name.as_ptr(), + value_ptr.cast::(), + value.len(), + )) + } + + #[cfg(apple)] + unsafe { + ret_usize(c::getxattr( + path.as_ptr(), + name.as_ptr(), + value_ptr.cast::(), + value.len(), + 0, + c::XATTR_NOFOLLOW, + )) + } +} + +#[cfg(any(apple, target_os = "android", target_os = "linux"))] +pub(crate) fn fgetxattr(fd: BorrowedFd<'_>, name: &CStr, value: &mut [u8]) -> io::Result { + let value_ptr = value.as_mut_ptr(); + + #[cfg(not(apple))] + unsafe { + ret_usize(c::fgetxattr( + borrowed_fd(fd), + name.as_ptr(), + value_ptr.cast::(), + value.len(), + )) + } + + #[cfg(apple)] + unsafe { + ret_usize(c::fgetxattr( + borrowed_fd(fd), + name.as_ptr(), + value_ptr.cast::(), + value.len(), + 0, + 0, + )) + } +} + +#[cfg(any(apple, target_os = "android", target_os = "linux"))] +pub(crate) fn setxattr( + path: &CStr, + name: &CStr, + value: &[u8], + flags: XattrFlags, +) -> io::Result<()> { + #[cfg(not(apple))] + unsafe { + ret(c::setxattr( + path.as_ptr(), + name.as_ptr(), + value.as_ptr().cast::(), + value.len(), + flags.bits() as i32, + )) + } + + #[cfg(apple)] + unsafe { + ret(c::setxattr( + path.as_ptr(), + name.as_ptr(), + value.as_ptr().cast::(), + value.len(), + 0, + flags.bits() as i32, + )) + } +} + +#[cfg(any(apple, target_os = "android", target_os = "linux"))] +pub(crate) fn lsetxattr( + path: &CStr, + name: &CStr, + value: &[u8], + flags: XattrFlags, +) -> io::Result<()> { + #[cfg(not(apple))] + unsafe { + ret(c::lsetxattr( + path.as_ptr(), + name.as_ptr(), + value.as_ptr().cast::(), + value.len(), + flags.bits() as i32, + )) + } + + #[cfg(apple)] + unsafe { + ret(c::setxattr( + path.as_ptr(), + name.as_ptr(), + value.as_ptr().cast::(), + value.len(), + 0, + flags.bits() as i32 | c::XATTR_NOFOLLOW, + )) + } +} + +#[cfg(any(apple, target_os = "android", target_os = "linux"))] +pub(crate) fn fsetxattr( + fd: BorrowedFd<'_>, + name: &CStr, + value: &[u8], + flags: XattrFlags, +) -> io::Result<()> { + #[cfg(not(apple))] + unsafe { + ret(c::fsetxattr( + borrowed_fd(fd), + name.as_ptr(), + value.as_ptr().cast::(), + value.len(), + flags.bits() as i32, + )) + } + + #[cfg(apple)] + unsafe { + ret(c::fsetxattr( + borrowed_fd(fd), + name.as_ptr(), + value.as_ptr().cast::(), + value.len(), + 0, + flags.bits() as i32, + )) + } +} + +#[cfg(any(apple, target_os = "android", target_os = "linux"))] +pub(crate) fn listxattr(path: &CStr, list: &mut [c::c_char]) -> io::Result { + #[cfg(not(apple))] + unsafe { + ret_usize(c::listxattr(path.as_ptr(), list.as_mut_ptr(), list.len())) + } + + #[cfg(apple)] + unsafe { + ret_usize(c::listxattr( + path.as_ptr(), + list.as_mut_ptr(), + list.len(), + 0, + )) + } +} + +#[cfg(any(apple, target_os = "android", target_os = "linux"))] +pub(crate) fn llistxattr(path: &CStr, list: &mut [c::c_char]) -> io::Result { + #[cfg(not(apple))] + unsafe { + ret_usize(c::llistxattr(path.as_ptr(), list.as_mut_ptr(), list.len())) + } + + #[cfg(apple)] + unsafe { + ret_usize(c::listxattr( + path.as_ptr(), + list.as_mut_ptr(), + list.len(), + c::XATTR_NOFOLLOW, + )) + } +} + +#[cfg(any(apple, target_os = "android", target_os = "linux"))] +pub(crate) fn flistxattr(fd: BorrowedFd<'_>, list: &mut [c::c_char]) -> io::Result { + let fd = borrowed_fd(fd); + + #[cfg(not(apple))] + unsafe { + ret_usize(c::flistxattr(fd, list.as_mut_ptr(), list.len())) + } + + #[cfg(apple)] + unsafe { + ret_usize(c::flistxattr(fd, list.as_mut_ptr(), list.len(), 0)) + } +} + +#[cfg(any(apple, target_os = "android", target_os = "linux"))] +pub(crate) fn removexattr(path: &CStr, name: &CStr) -> io::Result<()> { + #[cfg(not(apple))] + unsafe { + ret(c::removexattr(path.as_ptr(), name.as_ptr())) + } + + #[cfg(apple)] + unsafe { + ret(c::removexattr(path.as_ptr(), name.as_ptr(), 0)) + } +} + +#[cfg(any(apple, target_os = "android", target_os = "linux"))] +pub(crate) fn lremovexattr(path: &CStr, name: &CStr) -> io::Result<()> { + #[cfg(not(apple))] + unsafe { + ret(c::lremovexattr(path.as_ptr(), name.as_ptr())) + } + + #[cfg(apple)] + unsafe { + ret(c::removexattr( + path.as_ptr(), + name.as_ptr(), + c::XATTR_NOFOLLOW, + )) + } +} + +#[cfg(any(apple, target_os = "android", target_os = "linux"))] +pub(crate) fn fremovexattr(fd: BorrowedFd<'_>, name: &CStr) -> io::Result<()> { + let fd = borrowed_fd(fd); + + #[cfg(not(apple))] + unsafe { + ret(c::fremovexattr(fd, name.as_ptr())) + } + + #[cfg(apple)] + unsafe { + ret(c::fremovexattr(fd, name.as_ptr(), 0)) + } +} diff --git a/vendor/rustix/src/backend/libc/fs/types.rs b/vendor/rustix/src/backend/libc/fs/types.rs index f635f2cca..0cf7fe8ff 100644 --- a/vendor/rustix/src/backend/libc/fs/types.rs +++ b/vendor/rustix/src/backend/libc/fs/types.rs @@ -138,8 +138,8 @@ bitflags! { } impl Mode { - /// Construct a `Mode` from the mode bits of the `st_mode` field of - /// a `Stat`. + /// Construct a `Mode` from the mode bits of the `st_mode` field of a + /// `Stat`. #[inline] pub const fn from_raw_mode(st_mode: RawMode) -> Self { Self::from_bits_truncate(st_mode) @@ -334,7 +334,9 @@ mod copyfile { #[cfg(apple)] bitflags! { - /// `COPYFILE_*` constants. + /// `COPYFILE_*` constants for use with [`fcopyfile`]. + /// + /// [`fcopyfile`]: crate::fs::fcopyfile pub struct CopyfileFlags: c::c_uint { /// `COPYFILE_ACL` const ACL = copyfile::ACL; @@ -440,6 +442,7 @@ pub enum FileType { impl FileType { /// Construct a `FileType` from the `S_IFMT` bits of the `st_mode` field of /// a `Stat`. + #[inline] pub const fn from_raw_mode(st_mode: RawMode) -> Self { match (st_mode as c::mode_t) & c::S_IFMT { c::S_IFREG => Self::RegularFile, @@ -456,6 +459,7 @@ impl FileType { } /// Construct an `st_mode` value from `Stat`. + #[inline] pub const fn as_raw_mode(self) -> RawMode { match self { Self::RegularFile => c::S_IFREG as RawMode, @@ -473,6 +477,7 @@ impl FileType { /// Construct a `FileType` from the `d_type` field of a `c::dirent`. #[cfg(not(any(solarish, target_os = "haiku", target_os = "redox")))] + #[inline] pub(crate) const fn from_dirent_d_type(d_type: u8) -> Self { match d_type { c::DT_REG => Self::RegularFile, @@ -773,43 +778,43 @@ bitflags! { } } -#[cfg(not(any(solarish, target_os = "haiku", target_os = "redox", target_os = "wasi")))] +#[cfg(not(any(target_os = "haiku", target_os = "redox", target_os = "wasi")))] bitflags! { /// `ST_*` constants for use with [`StatVfs`]. pub struct StatVfsMountFlags: u64 { /// `ST_MANDLOCK` #[cfg(any(target_os = "android", target_os = "emscripten", target_os = "fuchsia", target_os = "linux"))] - const MANDLOCK = libc::ST_MANDLOCK as u64; + const MANDLOCK = c::ST_MANDLOCK as u64; /// `ST_NOATIME` #[cfg(any(target_os = "android", target_os = "emscripten", target_os = "fuchsia", target_os = "linux"))] - const NOATIME = libc::ST_NOATIME as u64; + const NOATIME = c::ST_NOATIME as u64; /// `ST_NODEV` #[cfg(any(target_os = "aix", target_os = "android", target_os = "emscripten", target_os = "fuchsia", target_os = "linux"))] - const NODEV = libc::ST_NODEV as u64; + const NODEV = c::ST_NODEV as u64; /// `ST_NODIRATIME` #[cfg(any(target_os = "android", target_os = "emscripten", target_os = "fuchsia", target_os = "linux"))] - const NODIRATIME = libc::ST_NODIRATIME as u64; + const NODIRATIME = c::ST_NODIRATIME as u64; /// `ST_NOEXEC` #[cfg(any(target_os = "android", target_os = "emscripten", target_os = "fuchsia", target_os = "linux"))] - const NOEXEC = libc::ST_NOEXEC as u64; + const NOEXEC = c::ST_NOEXEC as u64; /// `ST_NOSUID` - const NOSUID = libc::ST_NOSUID as u64; + const NOSUID = c::ST_NOSUID as u64; /// `ST_RDONLY` - const RDONLY = libc::ST_RDONLY as u64; + const RDONLY = c::ST_RDONLY as u64; /// `ST_RELATIME` #[cfg(any(target_os = "android", all(target_os = "linux", target_env = "gnu")))] - const RELATIME = libc::ST_RELATIME as u64; + const RELATIME = c::ST_RELATIME as u64; /// `ST_SYNCHRONOUS` #[cfg(any(target_os = "android", target_os = "emscripten", target_os = "fuchsia", target_os = "linux"))] - const SYNCHRONOUS = libc::ST_SYNCHRONOUS as u64; + const SYNCHRONOUS = c::ST_SYNCHRONOUS as u64; } } @@ -915,7 +920,7 @@ pub type StatFs = c::statfs64; /// /// [`statvfs`]: crate::fs::statvfs /// [`fstatvfs`]: crate::fs::fstatvfs -#[cfg(not(any(solarish, target_os = "haiku", target_os = "redox", target_os = "wasi")))] +#[cfg(not(any(target_os = "haiku", target_os = "redox", target_os = "wasi")))] #[allow(missing_docs)] pub struct StatVfs { pub f_bsize: u64, @@ -1106,7 +1111,7 @@ bitflags! { bitflags! { /// `MS_*` constants for use with [`change_mount`]. /// - /// [`change_mount`]: crate::fs::mount::change_mount. + /// [`change_mount`]: crate::fs::mount::change_mount pub struct MountPropagationFlags: c::c_ulong { /// `MS_SHARED` const SHARED = c::MS_SHARED; diff --git a/vendor/rustix/src/backend/libc/io/syscalls.rs b/vendor/rustix/src/backend/libc/io/syscalls.rs index 03f9294d9..b74a63fa3 100644 --- a/vendor/rustix/src/backend/libc/io/syscalls.rs +++ b/vendor/rustix/src/backend/libc/io/syscalls.rs @@ -3,9 +3,12 @@ use super::super::c; #[cfg(any(target_os = "android", target_os = "linux"))] use super::super::conv::syscall_ret_owned_fd; -use super::super::conv::{ - borrowed_fd, ret, ret_c_int, ret_discarded_fd, ret_owned_fd, ret_ssize_t, -}; +#[cfg(any( + target_os = "android", + all(target_os = "linux", not(target_env = "gnu")), +))] +use super::super::conv::syscall_ret_usize; +use super::super::conv::{borrowed_fd, ret, ret_c_int, ret_discarded_fd, ret_owned_fd, ret_usize}; use super::super::offset::{libc_pread, libc_pwrite}; #[cfg(not(any(target_os = "haiku", target_os = "redox", target_os = "solaris")))] use super::super::offset::{libc_preadv, libc_pwritev}; @@ -18,11 +21,18 @@ use crate::io::kqueue::Event; use crate::io::port::Event; #[cfg(not(any(target_os = "aix", target_os = "wasi")))] use crate::io::DupFlags; +#[cfg(any( + target_os = "android", + target_os = "freebsd", + target_os = "illumos", + target_os = "linux" +))] +use crate::io::EventfdFlags; #[cfg(not(any(apple, target_os = "aix", target_os = "haiku", target_os = "wasi")))] use crate::io::PipeFlags; use crate::io::{self, FdFlags, IoSlice, IoSliceMut, PollFd}; #[cfg(any(target_os = "android", target_os = "linux"))] -use crate::io::{EventfdFlags, IoSliceRaw, ReadWriteFlags, SpliceFlags}; +use crate::io::{IoSliceRaw, ReadWriteFlags, SpliceFlags}; use core::cmp::min; use core::convert::TryInto; use core::mem::MaybeUninit; @@ -32,25 +42,23 @@ use core::ptr; use libc_errno::errno; pub(crate) fn read(fd: BorrowedFd<'_>, buf: &mut [u8]) -> io::Result { - let nread = unsafe { - ret_ssize_t(c::read( + unsafe { + ret_usize(c::read( borrowed_fd(fd), buf.as_mut_ptr().cast(), min(buf.len(), READ_LIMIT), - ))? - }; - Ok(nread as usize) + )) + } } pub(crate) fn write(fd: BorrowedFd<'_>, buf: &[u8]) -> io::Result { - let nwritten = unsafe { - ret_ssize_t(c::write( + unsafe { + ret_usize(c::write( borrowed_fd(fd), buf.as_ptr().cast(), min(buf.len(), READ_LIMIT), - ))? - }; - Ok(nwritten as usize) + )) + } } pub(crate) fn pread(fd: BorrowedFd<'_>, buf: &mut [u8], offset: u64) -> io::Result { @@ -59,15 +67,14 @@ pub(crate) fn pread(fd: BorrowedFd<'_>, buf: &mut [u8], offset: u64) -> io::Resu // Silently cast; we'll get `EINVAL` if the value is negative. let offset = offset as i64; - let nread = unsafe { - ret_ssize_t(libc_pread( + unsafe { + ret_usize(libc_pread( borrowed_fd(fd), buf.as_mut_ptr().cast(), len, offset, - ))? - }; - Ok(nread as usize) + )) + } } pub(crate) fn pwrite(fd: BorrowedFd<'_>, buf: &[u8], offset: u64) -> io::Result { @@ -76,37 +83,34 @@ pub(crate) fn pwrite(fd: BorrowedFd<'_>, buf: &[u8], offset: u64) -> io::Result< // Silently cast; we'll get `EINVAL` if the value is negative. let offset = offset as i64; - let nwritten = unsafe { - ret_ssize_t(libc_pwrite( + unsafe { + ret_usize(libc_pwrite( borrowed_fd(fd), buf.as_ptr().cast(), len, offset, - ))? - }; - Ok(nwritten as usize) + )) + } } pub(crate) fn readv(fd: BorrowedFd<'_>, bufs: &mut [IoSliceMut]) -> io::Result { - let nread = unsafe { - ret_ssize_t(c::readv( + unsafe { + ret_usize(c::readv( borrowed_fd(fd), bufs.as_ptr().cast::(), min(bufs.len(), max_iov()) as c::c_int, - ))? - }; - Ok(nread as usize) + )) + } } pub(crate) fn writev(fd: BorrowedFd<'_>, bufs: &[IoSlice]) -> io::Result { - let nwritten = unsafe { - ret_ssize_t(c::writev( + unsafe { + ret_usize(c::writev( borrowed_fd(fd), bufs.as_ptr().cast::(), min(bufs.len(), max_iov()) as c::c_int, - ))? - }; - Ok(nwritten as usize) + )) + } } #[cfg(not(any(target_os = "haiku", target_os = "redox", target_os = "solaris")))] @@ -117,30 +121,28 @@ pub(crate) fn preadv( ) -> io::Result { // Silently cast; we'll get `EINVAL` if the value is negative. let offset = offset as i64; - let nread = unsafe { - ret_ssize_t(libc_preadv( + unsafe { + ret_usize(libc_preadv( borrowed_fd(fd), bufs.as_ptr().cast::(), min(bufs.len(), max_iov()) as c::c_int, offset, - ))? - }; - Ok(nread as usize) + )) + } } #[cfg(not(any(target_os = "haiku", target_os = "redox", target_os = "solaris")))] pub(crate) fn pwritev(fd: BorrowedFd<'_>, bufs: &[IoSlice], offset: u64) -> io::Result { // Silently cast; we'll get `EINVAL` if the value is negative. let offset = offset as i64; - let nwritten = unsafe { - ret_ssize_t(libc_pwritev( + unsafe { + ret_usize(libc_pwritev( borrowed_fd(fd), bufs.as_ptr().cast::(), min(bufs.len(), max_iov()) as c::c_int, offset, - ))? - }; - Ok(nwritten as usize) + )) + } } #[cfg(all(target_os = "linux", target_env = "gnu"))] @@ -152,20 +154,19 @@ pub(crate) fn preadv2( ) -> io::Result { // Silently cast; we'll get `EINVAL` if the value is negative. let offset = offset as i64; - let nread = unsafe { - ret_ssize_t(libc_preadv2( + unsafe { + ret_usize(libc_preadv2( borrowed_fd(fd), bufs.as_ptr().cast::(), min(bufs.len(), max_iov()) as c::c_int, offset, flags.bits(), - ))? - }; - Ok(nread as usize) + )) + } } /// At present, `libc` only has `preadv2` defined for glibc. On other -/// ABIs, use `libc::syscall`. +/// ABIs, use `c::syscall`. #[cfg(any( target_os = "android", all(target_os = "linux", not(target_env = "gnu")), @@ -179,17 +180,16 @@ pub(crate) fn preadv2( ) -> io::Result { // Silently cast; we'll get `EINVAL` if the value is negative. let offset = offset as i64; - let nread = unsafe { - ret_ssize_t(libc::syscall( - libc::SYS_preadv2, + unsafe { + syscall_ret_usize(c::syscall( + c::SYS_preadv2, borrowed_fd(fd), bufs.as_ptr().cast::(), min(bufs.len(), max_iov()) as c::c_int, offset, flags.bits(), - ) as c::ssize_t)? - }; - Ok(nread as usize) + )) + } } #[cfg(all(target_os = "linux", target_env = "gnu"))] @@ -201,20 +201,19 @@ pub(crate) fn pwritev2( ) -> io::Result { // Silently cast; we'll get `EINVAL` if the value is negative. let offset = offset as i64; - let nwritten = unsafe { - ret_ssize_t(libc_pwritev2( + unsafe { + ret_usize(libc_pwritev2( borrowed_fd(fd), bufs.as_ptr().cast::(), min(bufs.len(), max_iov()) as c::c_int, offset, flags.bits(), - ))? - }; - Ok(nwritten as usize) + )) + } } /// At present, `libc` only has `pwritev2` defined for glibc. On other -/// ABIs, use `libc::syscall`. +/// ABIs, use `c::syscall`. #[cfg(any( target_os = "android", all(target_os = "linux", not(target_env = "gnu")), @@ -228,25 +227,24 @@ pub(crate) fn pwritev2( ) -> io::Result { // Silently cast; we'll get `EINVAL` if the value is negative. let offset = offset as i64; - let nwritten = unsafe { - ret_ssize_t(libc::syscall( - libc::SYS_pwritev2, + unsafe { + syscall_ret_usize(c::syscall( + c::SYS_pwritev2, borrowed_fd(fd), bufs.as_ptr().cast::(), min(bufs.len(), max_iov()) as c::c_int, offset, flags.bits(), - ) as c::ssize_t)? - }; - Ok(nwritten as usize) + )) + } } // These functions are derived from Rust's library/std/src/sys/unix/fd.rs at // revision 326ef470a8b379a180d6dc4bbef08990698a737a. // The maximum read limit on most POSIX-like systems is `SSIZE_MAX`, with the -// man page quoting that if the count of bytes to read is greater than -// `SSIZE_MAX` the result is "unspecified". +// manual page quoting that if the count of bytes to read is greater than +// `SSIZE_MAX` the result is “unspecified”. // // On macOS, however, apparently the 64-bit libc is either buggy or // intentionally showing odd behavior by rejecting any read with a size larger @@ -293,6 +291,11 @@ pub(crate) fn eventfd(initval: u32, flags: EventfdFlags) -> io::Result unsafe { syscall_ret_owned_fd(c::syscall(c::SYS_eventfd2, initval, flags.bits())) } } +#[cfg(any(target_os = "freebsd", target_os = "illumos"))] +pub(crate) fn eventfd(initval: u32, flags: EventfdFlags) -> io::Result { + unsafe { ret_owned_fd(c::eventfd(initval, flags.bits())) } +} + #[cfg(any(target_os = "android", target_os = "linux"))] #[inline] pub(crate) fn ioctl_blksszget(fd: BorrowedFd) -> io::Result { @@ -338,13 +341,15 @@ pub(crate) fn ioctl_fionbio(fd: BorrowedFd<'_>, value: bool) -> io::Result<()> { #[cfg(any(target_os = "android", target_os = "linux"))] pub(crate) fn ioctl_ficlone(fd: BorrowedFd<'_>, src_fd: BorrowedFd<'_>) -> io::Result<()> { - // TODO: Enable `ioctl_ficlone` for android when upstream is updated. - // TODO: Enable `ioctl_ficlone` for more architectures when upstream is - // updated. - #[cfg(all( - target_os = "linux", - any(target_arch = "x86", target_arch = "x86_64", target_arch = "aarch64") - ))] + // TODO: Enable this on mips and power once libc is updated. + #[cfg(not(any( + target_arch = "mips", + target_arch = "mips64", + target_arch = "powerpc", + target_arch = "powerpc64", + target_arch = "sparc", + target_arch = "sparc64" + )))] unsafe { ret(c::ioctl( borrowed_fd(fd), @@ -352,10 +357,15 @@ pub(crate) fn ioctl_ficlone(fd: BorrowedFd<'_>, src_fd: BorrowedFd<'_>) -> io::R borrowed_fd(src_fd), )) } - #[cfg(not(all( - target_os = "linux", - any(target_arch = "x86", target_arch = "x86_64", target_arch = "aarch64") - )))] + + #[cfg(any( + target_arch = "mips", + target_arch = "mips64", + target_arch = "powerpc", + target_arch = "powerpc64", + target_arch = "sparc", + target_arch = "sparc64" + ))] { let _ = fd; let _ = src_fd; @@ -475,7 +485,13 @@ pub(crate) fn dup3(fd: BorrowedFd<'_>, new: &mut OwnedFd, _flags: DupFlags) -> i #[cfg(apple)] pub(crate) fn ioctl_fioclex(fd: BorrowedFd<'_>) -> io::Result<()> { - unsafe { ret(c::ioctl(borrowed_fd(fd), c::FIOCLEX)) } + unsafe { + ret(c::ioctl( + borrowed_fd(fd), + c::FIOCLEX, + core::ptr::null_mut::(), + )) + } } #[cfg(not(any(target_os = "haiku", target_os = "redox", target_os = "wasi")))] @@ -565,17 +581,16 @@ pub fn splice( .map(|off| (off as *mut u64).cast()) .unwrap_or(ptr::null_mut()); - ret_ssize_t(unsafe { - c::splice( + unsafe { + ret_usize(c::splice( borrowed_fd(fd_in), off_in, borrowed_fd(fd_out), off_out, len, flags.bits(), - ) - }) - .map(|spliced| spliced as usize) + )) + } } #[cfg(any(target_os = "android", target_os = "linux"))] @@ -585,13 +600,12 @@ pub unsafe fn vmsplice( bufs: &[IoSliceRaw], flags: SpliceFlags, ) -> io::Result { - ret_ssize_t(c::vmsplice( + ret_usize(c::vmsplice( borrowed_fd(fd), bufs.as_ptr().cast::(), min(bufs.len(), max_iov()), flags.bits(), )) - .map(|spliced| spliced as usize) } #[cfg(solarish)] diff --git a/vendor/rustix/src/backend/libc/io/types.rs b/vendor/rustix/src/backend/libc/io/types.rs index cbdd734b9..90a5e15b5 100644 --- a/vendor/rustix/src/backend/libc/io/types.rs +++ b/vendor/rustix/src/backend/libc/io/types.rs @@ -87,7 +87,12 @@ bitflags! { } } -#[cfg(any(target_os = "android", target_os = "linux"))] +#[cfg(any( + target_os = "android", + target_os = "freebsd", + target_os = "illumos", + target_os = "linux" +))] bitflags! { /// `EFD_*` flags for use with [`eventfd`]. /// @@ -129,7 +134,7 @@ pub struct IoSliceRaw<'a> { #[cfg(any(target_os = "android", target_os = "linux"))] impl<'a> IoSliceRaw<'a> { - /// Creates a new IoSlice wrapping a byte slice. + /// Creates a new `IoSlice` wrapping a byte slice. pub fn from_slice(buf: &'a [u8]) -> Self { IoSliceRaw { _buf: c::iovec { @@ -140,7 +145,7 @@ impl<'a> IoSliceRaw<'a> { } } - /// Creates a new IoSlice wrapping a mutable byte slice. + /// Creates a new `IoSlice` wrapping a mutable byte slice. pub fn from_slice_mut(buf: &'a mut [u8]) -> Self { IoSliceRaw { _buf: c::iovec { diff --git a/vendor/rustix/src/backend/libc/mm/types.rs b/vendor/rustix/src/backend/libc/mm/types.rs index cd6e521d2..798fda86b 100644 --- a/vendor/rustix/src/backend/libc/mm/types.rs +++ b/vendor/rustix/src/backend/libc/mm/types.rs @@ -346,9 +346,9 @@ pub enum Advice { } #[cfg(target_os = "emscripten")] +#[allow(non_upper_case_globals)] impl Advice { /// `POSIX_MADV_DONTNEED` - #[allow(non_upper_case_globals)] pub const DontNeed: Self = Self::Normal; } diff --git a/vendor/rustix/src/backend/libc/mod.rs b/vendor/rustix/src/backend/libc/mod.rs index 1961d1291..f3433903d 100644 --- a/vendor/rustix/src/backend/libc/mod.rs +++ b/vendor/rustix/src/backend/libc/mod.rs @@ -11,10 +11,6 @@ // one platform where it's redundant on another. #![allow(clippy::useless_conversion)] -#[cfg(not(any(windows, target_os = "wasi")))] -#[macro_use] -mod weak; - mod conv; mod offset; diff --git a/vendor/rustix/src/backend/libc/net/send_recv.rs b/vendor/rustix/src/backend/libc/net/send_recv.rs index 114807808..49c6f2c22 100644 --- a/vendor/rustix/src/backend/libc/net/send_recv.rs +++ b/vendor/rustix/src/backend/libc/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: i32 { /// `MSG_CONFIRM` #[cfg(not(any( @@ -37,7 +40,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: i32 { #[cfg(not(any(apple, solarish, windows, target_os = "haiku")))] /// `MSG_CMSG_CLOEXEC` diff --git a/vendor/rustix/src/backend/libc/net/syscalls.rs b/vendor/rustix/src/backend/libc/net/syscalls.rs index ed4494394..ac260e552 100644 --- a/vendor/rustix/src/backend/libc/net/syscalls.rs +++ b/vendor/rustix/src/backend/libc/net/syscalls.rs @@ -12,7 +12,7 @@ use super::read_sockaddr::{maybe_read_sockaddr_os, read_sockaddr_os}; #[cfg(not(any(target_os = "redox", target_os = "wasi")))] use super::send_recv::{RecvFlags, SendFlags}; #[cfg(not(any(target_os = "redox", target_os = "wasi")))] -use super::types::{AcceptFlags, AddressFamily, Protocol, Shutdown, SocketFlags, SocketType}; +use super::types::{AddressFamily, Protocol, Shutdown, SocketFlags, SocketType}; #[cfg(not(any(target_os = "redox", target_os = "wasi")))] use super::write_sockaddr::{encode_sockaddr_v4, encode_sockaddr_v6}; use crate::fd::{BorrowedFd, OwnedFd}; @@ -26,28 +26,26 @@ use core::ptr::null_mut; #[cfg(not(any(target_os = "redox", target_os = "wasi")))] pub(crate) fn recv(fd: BorrowedFd<'_>, buf: &mut [u8], flags: RecvFlags) -> io::Result { - let nrecv = unsafe { + unsafe { ret_send_recv(c::recv( borrowed_fd(fd), buf.as_mut_ptr().cast(), send_recv_len(buf.len()), flags.bits(), - ))? - }; - Ok(nrecv as usize) + )) + } } #[cfg(not(any(target_os = "redox", target_os = "wasi")))] pub(crate) fn send(fd: BorrowedFd<'_>, buf: &[u8], flags: SendFlags) -> io::Result { - let nwritten = unsafe { + unsafe { ret_send_recv(c::send( borrowed_fd(fd), buf.as_ptr().cast(), send_recv_len(buf.len()), flags.bits(), - ))? - }; - Ok(nwritten as usize) + )) + } } #[cfg(not(any(target_os = "redox", target_os = "wasi")))] @@ -65,18 +63,20 @@ pub(crate) fn recvfrom( // `AF_UNSPEC` so that we can detect this case. initialize_family_to_unspec(storage.as_mut_ptr()); - let nread = ret_send_recv(c::recvfrom( + ret_send_recv(c::recvfrom( borrowed_fd(fd), buf.as_mut_ptr().cast(), send_recv_len(buf.len()), flags.bits(), storage.as_mut_ptr().cast(), &mut len, - ))?; - Ok(( - nread as usize, - maybe_read_sockaddr_os(storage.as_ptr(), len.try_into().unwrap()), )) + .map(|nread| { + ( + nread, + maybe_read_sockaddr_os(storage.as_ptr(), len.try_into().unwrap()), + ) + }) } } @@ -87,7 +87,7 @@ pub(crate) fn sendto_v4( flags: SendFlags, addr: &SocketAddrV4, ) -> io::Result { - let nwritten = unsafe { + unsafe { ret_send_recv(c::sendto( borrowed_fd(fd), buf.as_ptr().cast(), @@ -95,9 +95,8 @@ pub(crate) fn sendto_v4( flags.bits(), as_ptr(&encode_sockaddr_v4(addr)).cast::(), size_of::() as _, - ))? - }; - Ok(nwritten as usize) + )) + } } #[cfg(not(any(target_os = "redox", target_os = "wasi")))] @@ -107,7 +106,7 @@ pub(crate) fn sendto_v6( flags: SendFlags, addr: &SocketAddrV6, ) -> io::Result { - let nwritten = unsafe { + unsafe { ret_send_recv(c::sendto( borrowed_fd(fd), buf.as_ptr().cast(), @@ -115,9 +114,8 @@ pub(crate) fn sendto_v6( flags.bits(), as_ptr(&encode_sockaddr_v6(addr)).cast::(), size_of::() as _, - ))? - }; - Ok(nwritten as usize) + )) + } } #[cfg(not(any(windows, target_os = "redox", target_os = "wasi")))] @@ -127,7 +125,7 @@ pub(crate) fn sendto_unix( flags: SendFlags, addr: &SocketAddrUnix, ) -> io::Result { - let nwritten = unsafe { + unsafe { ret_send_recv(c::sendto( borrowed_fd(fd), buf.as_ptr().cast(), @@ -135,9 +133,8 @@ pub(crate) fn sendto_unix( flags.bits(), as_ptr(&addr.unix).cast(), addr.addr_len(), - ))? - }; - Ok(nwritten as usize) + )) + } } #[cfg(not(any(target_os = "redox", target_os = "wasi")))] @@ -257,7 +254,7 @@ pub(crate) fn accept(sockfd: BorrowedFd<'_>) -> io::Result { target_os = "redox", target_os = "wasi", )))] -pub(crate) fn accept_with(sockfd: BorrowedFd<'_>, flags: AcceptFlags) -> io::Result { +pub(crate) fn accept_with(sockfd: BorrowedFd<'_>, flags: SocketFlags) -> io::Result { unsafe { let owned_fd = ret_owned_fd(c::accept4( borrowed_fd(sockfd), @@ -295,7 +292,7 @@ pub(crate) fn acceptfrom(sockfd: BorrowedFd<'_>) -> io::Result<(OwnedFd, Option< )))] pub(crate) fn acceptfrom_with( sockfd: BorrowedFd<'_>, - flags: AcceptFlags, + flags: SocketFlags, ) -> io::Result<(OwnedFd, Option)> { unsafe { let mut storage = MaybeUninit::::uninit(); @@ -314,18 +311,18 @@ pub(crate) fn acceptfrom_with( } /// Darwin lacks `accept4`, but does have `accept`. We define -/// `AcceptFlags` to have no flags, so we can discard it here. +/// `SocketFlags` to have no flags, so we can discard it here. #[cfg(any(apple, windows, target_os = "haiku"))] -pub(crate) fn accept_with(sockfd: BorrowedFd<'_>, _flags: AcceptFlags) -> io::Result { +pub(crate) fn accept_with(sockfd: BorrowedFd<'_>, _flags: SocketFlags) -> io::Result { accept(sockfd) } /// Darwin lacks `accept4`, but does have `accept`. We define -/// `AcceptFlags` to have no flags, so we can discard it here. +/// `SocketFlags` to have no flags, so we can discard it here. #[cfg(any(apple, windows, target_os = "haiku"))] pub(crate) fn acceptfrom_with( sockfd: BorrowedFd<'_>, - _flags: AcceptFlags, + _flags: SocketFlags, ) -> io::Result<(OwnedFd, Option)> { acceptfrom(sockfd) } @@ -555,7 +552,7 @@ pub(crate) mod sockopt { // Rust's musl libc bindings deprecated `time_t` while they // transition to 64-bit `time_t`. What we want here is just - // "whatever type `timeval`'s `tv_sec` is", so we're ok using + // “whatever type `timeval`'s `tv_sec` is”, so we're ok using // the deprecated type. #[allow(deprecated)] let tv_sec = timeout.as_secs().try_into().unwrap_or(c::time_t::MAX); @@ -647,15 +644,52 @@ pub(crate) mod sockopt { } #[inline] - pub(crate) fn get_socket_error(fd: BorrowedFd<'_>) -> io::Result> { + pub(crate) fn get_socket_error(fd: BorrowedFd<'_>) -> io::Result> { 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 { + 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::INVAL)?; + setsockopt(fd, c::SOL_SOCKET as _, c::SO_RCVBUF, size) + } + + #[inline] + pub(crate) fn get_socket_recv_buffer_size(fd: BorrowedFd<'_>) -> io::Result { + 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::INVAL)?; + setsockopt(fd, c::SOL_SOCKET as _, c::SO_SNDBUF, size) + } + + #[inline] + pub(crate) fn get_socket_send_buffer_size(fd: BorrowedFd<'_>) -> io::Result { + 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) @@ -790,6 +824,20 @@ pub(crate) mod sockopt { setsockopt(fd, c::IPPROTO_IPV6 as _, IPV6_DROP_MEMBERSHIP, mreq) } + #[inline] + pub(crate) fn get_ipv6_unicast_hops(fd: BorrowedFd<'_>) -> io::Result { + 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) -> 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/libc/net/types.rs b/vendor/rustix/src/backend/libc/net/types.rs index 54f60ca50..d1d769cb4 100644 --- a/vendor/rustix/src/backend/libc/net/types.rs +++ b/vendor/rustix/src/backend/libc/net/types.rs @@ -53,6 +53,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 _); @@ -123,7 +124,6 @@ impl AddressFamily { )))] pub const ROSE: Self = Self(c::AF_ROSE as _); /// `AF_DECnet` - #[allow(non_upper_case_globals)] #[cfg(not(target_os = "haiku"))] pub const DECnet: Self = Self(c::AF_DECnet as _); /// `AF_NETBEUI` @@ -294,7 +294,10 @@ impl AddressFamily { #[doc(hidden)] pub type RawProtocol = i32; -/// `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); @@ -464,25 +467,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_int { - /// `SOCK_NONBLOCK` - #[cfg(not(any(apple, windows, target_os = "haiku")))] - const NONBLOCK = c::SOCK_NONBLOCK; - - /// `SOCK_CLOEXEC` - #[cfg(not(any(apple, windows, target_os = "haiku")))] - const CLOEXEC = c::SOCK_CLOEXEC; - } -} - -bitflags! { - /// `SOCK_*` constants for use with [`socket`]. - /// - /// [`socket`]: crate::net::socket pub struct SocketFlags: c::c_int { /// `SOCK_NONBLOCK` #[cfg(not(any(apple, windows, target_os = "haiku")))] diff --git a/vendor/rustix/src/backend/libc/offset.rs b/vendor/rustix/src/backend/libc/offset.rs index 9747eb954..d7a803415 100644 --- a/vendor/rustix/src/backend/libc/offset.rs +++ b/vendor/rustix/src/backend/libc/offset.rs @@ -6,15 +6,15 @@ use super::c; #[cfg(not(any(linux_like, windows)))] #[cfg(feature = "fs")] pub(super) use c::{ - fstat as libc_fstat, fstatat as libc_fstatat, ftruncate as libc_ftruncate, lseek as libc_lseek, - off_t as libc_off_t, + fstat as libc_fstat, fstatat as libc_fstatat, ftruncate as libc_ftruncate, ino_t as libc_ino_t, + lseek as libc_lseek, off_t as libc_off_t, }; #[cfg(linux_like)] #[cfg(feature = "fs")] pub(super) use c::{ fstat64 as libc_fstat, fstatat64 as libc_fstatat, ftruncate64 as libc_ftruncate, - lseek64 as libc_lseek, off64_t as libc_off_t, + ino64_t as libc_ino_t, lseek64 as libc_lseek, off64_t as libc_off_t, }; #[cfg(linux_like)] @@ -36,12 +36,11 @@ pub(super) use c::{rlimit as libc_rlimit, RLIM_INFINITY as LIBC_RLIM_INFINITY}; #[cfg(not(any(linux_like, windows, target_os = "fuchsia", target_os = "wasi")))] pub(super) use c::{getrlimit as libc_getrlimit, setrlimit as libc_setrlimit}; -// TODO: Add `RLIM64_INFINITY` to upstream libc. #[cfg(linux_like)] -pub(super) const LIBC_RLIM_INFINITY: u64 = !0_u64; - -#[cfg(linux_like)] -pub(super) use c::{getrlimit64 as libc_getrlimit, setrlimit64 as libc_setrlimit}; +pub(super) use c::{ + getrlimit64 as libc_getrlimit, setrlimit64 as libc_setrlimit, + RLIM64_INFINITY as LIBC_RLIM_INFINITY, +}; #[cfg(linux_like)] #[cfg(feature = "mm")] @@ -269,7 +268,7 @@ mod readwrite_pv { #[cfg(apple)] pub(super) use readwrite_pv::{preadv as libc_preadv, pwritev as libc_pwritev}; -// GLIBC added `preadv64v2` and `pwritev64v2` in version 2.26. +// glibc added `preadv64v2` and `pwritev64v2` in version 2.26. #[cfg(all(target_os = "linux", target_env = "gnu"))] mod readwrite_pv64v2 { use super::c; @@ -300,7 +299,7 @@ mod readwrite_pv64v2 { offset: c::off64_t, flags: c::c_int, ) -> c::ssize_t { - // Older GLIBC lacks `preadv64v2`, so use the `weak!` mechanism to + // Older glibc lacks `preadv64v2`, so use the `weak!` mechanism to // test for it, and call back to `c::syscall`. We don't use // `weak_or_syscall` here because we need to pass the 64-bit offset // specially. @@ -395,7 +394,6 @@ pub(super) use c::posix_fallocate64 as libc_posix_fallocate; pub(super) use {c::fstatfs as libc_fstatfs, c::statfs as libc_statfs}; #[cfg(not(any( linux_like, - solarish, windows, target_os = "haiku", target_os = "redox", diff --git a/vendor/rustix/src/backend/libc/process/syscalls.rs b/vendor/rustix/src/backend/libc/process/syscalls.rs index d208bda7a..d8f4fe3a4 100644 --- a/vendor/rustix/src/backend/libc/process/syscalls.rs +++ b/vendor/rustix/src/backend/libc/process/syscalls.rs @@ -5,7 +5,7 @@ use super::super::c; use super::super::conv::borrowed_fd; use super::super::conv::{c_str, ret, ret_c_int, ret_discarded_char_ptr}; #[cfg(not(target_os = "wasi"))] -use super::super::conv::{ret_infallible, ret_pid_t}; +use super::super::conv::{ret_infallible, ret_pid_t, ret_usize}; #[cfg(any(target_os = "android", target_os = "linux"))] use super::super::conv::{syscall_ret, syscall_ret_u32}; #[cfg(any( @@ -23,6 +23,8 @@ use crate::ffi::CStr; #[cfg(feature = "fs")] use crate::fs::Mode; use crate::io; +#[cfg(any(target_os = "android", target_os = "linux"))] +use crate::process::Sysinfo; #[cfg(not(any(target_os = "wasi", target_os = "redox", target_os = "openbsd")))] use crate::process::{WaitId, WaitidOptions, WaitidStatus}; use core::mem::MaybeUninit; @@ -37,12 +39,12 @@ use { use { super::super::offset::{libc_getrlimit, libc_rlimit, libc_setrlimit, LIBC_RLIM_INFINITY}, crate::process::{Resource, Rlimit}, - core::convert::TryInto, }; #[cfg(not(target_os = "wasi"))] use { super::types::RawUname, crate::process::{Gid, Pid, RawNonZeroPid, RawPid, Signal, Uid, WaitOptions, WaitStatus}, + core::convert::TryInto, }; #[cfg(not(target_os = "wasi"))] @@ -55,6 +57,11 @@ pub(crate) fn fchdir(dirfd: BorrowedFd<'_>) -> io::Result<()> { unsafe { ret(c::fchdir(borrowed_fd(dirfd))) } } +#[cfg(not(any(target_os = "fuchsia", target_os = "wasi")))] +pub(crate) fn chroot(path: &CStr) -> io::Result<()> { + unsafe { ret(c::chroot(c_str(path))) } +} + #[cfg(not(target_os = "wasi"))] pub(crate) fn getcwd(buf: &mut [u8]) -> io::Result<()> { unsafe { ret_discarded_char_ptr(c::getcwd(buf.as_mut_ptr().cast(), buf.len())) } @@ -62,7 +69,7 @@ pub(crate) fn getcwd(buf: &mut [u8]) -> io::Result<()> { #[cfg(any(target_os = "android", target_os = "linux"))] pub(crate) fn membarrier_query() -> MembarrierQuery { - // GLIBC does not have a wrapper for `membarrier`; [the documentation] + // glibc does not have a wrapper for `membarrier`; [the documentation] // says to use `syscall`. // // [the documentation]: https://man7.org/linux/man-pages/man2/membarrier.2.html#NOTES @@ -164,6 +171,12 @@ pub(crate) fn getpgid(pid: Option) -> io::Result { } } +#[cfg(not(target_os = "wasi"))] +#[inline] +pub(crate) fn setpgid(pid: Option, pgid: Option) -> io::Result<()> { + unsafe { ret(c::setpgid(Pid::as_raw(pid) as _, Pid::as_raw(pgid) as _)) } +} + #[cfg(not(target_os = "wasi"))] #[inline] #[must_use] @@ -426,7 +439,9 @@ pub(crate) fn waitid(id: WaitId<'_>, options: WaitidOptions) -> io::Result io::Result> { - let mut status = MaybeUninit::::uninit(); + // `waitid` can return successfully without initializing the struct (no + // children found when using `WNOHANG`) + let mut status = MaybeUninit::::zeroed(); unsafe { ret(c::waitid( c::P_ALL, @@ -442,7 +457,9 @@ fn _waitid_all(options: WaitidOptions) -> io::Result> { #[cfg(not(any(target_os = "wasi", target_os = "redox", target_os = "openbsd")))] #[inline] fn _waitid_pid(pid: Pid, options: WaitidOptions) -> io::Result> { - let mut status = MaybeUninit::::uninit(); + // `waitid` can return successfully without initializing the struct (no + // children found when using `WNOHANG`) + let mut status = MaybeUninit::::zeroed(); unsafe { ret(c::waitid( c::P_PID, @@ -458,7 +475,9 @@ fn _waitid_pid(pid: Pid, options: WaitidOptions) -> io::Result, options: WaitidOptions) -> io::Result> { - let mut status = MaybeUninit::::uninit(); + // `waitid` can return successfully without initializing the struct (no + // children found when using `WNOHANG`) + let mut status = MaybeUninit::::zeroed(); unsafe { ret(c::waitid( c::P_PIDFD, @@ -481,6 +500,13 @@ fn _waitid_pidfd(fd: BorrowedFd<'_>, options: WaitidOptions) -> io::Result) -> Option { let status = status.assume_init(); + // `si_pid` is supposedly the better way to check that the struct has been + // filled, e.g. the Linux manpage says about the `WNOHANG` case “zero out + // the si_pid field before the call and check for a nonzero value”. + // But e.g. NetBSD/OpenBSD don't have it exposed in the libc crate for now, and + // some platforms don't have it at all. For simplicity, always check + // `si_signo`. We have zero-initialized the whole struct, and all kernels + // should set `SIGCHLD` here. if status.si_signo == 0 { None } else { @@ -502,6 +528,16 @@ pub(crate) fn exit_group(code: c::c_int) -> ! { } } +#[cfg(not(any(target_os = "redox", target_os = "wasi")))] +#[inline] +pub(crate) fn getsid(pid: Option) -> io::Result { + unsafe { + let pid = ret_pid_t(c::getsid(Pid::as_raw(pid) as _))?; + debug_assert_ne!(pid, 0); + Ok(Pid::from_raw_nonzero(RawNonZeroPid::new_unchecked(pid))) + } +} + #[cfg(not(target_os = "wasi"))] #[inline] pub(crate) fn setsid() -> io::Result { @@ -535,6 +571,24 @@ pub(crate) fn kill_current_process_group(sig: Signal) -> io::Result<()> { unsafe { ret(c::kill(0, sig as i32)) } } +#[cfg(not(target_os = "wasi"))] +#[inline] +pub(crate) fn test_kill_process(pid: Pid) -> io::Result<()> { + unsafe { ret(c::kill(pid.as_raw_nonzero().get(), 0)) } +} + +#[cfg(not(target_os = "wasi"))] +#[inline] +pub(crate) fn test_kill_process_group(pid: Pid) -> io::Result<()> { + unsafe { ret(c::kill(pid.as_raw_nonzero().get().wrapping_neg(), 0)) } +} + +#[cfg(not(target_os = "wasi"))] +#[inline] +pub(crate) fn test_kill_current_process_group() -> io::Result<()> { + unsafe { ret(c::kill(0, 0)) } +} + #[cfg(any(target_os = "android", target_os = "linux"))] #[inline] pub(crate) unsafe fn prctl( @@ -561,10 +615,36 @@ pub(crate) unsafe fn procctl( #[cfg(target_os = "linux")] pub(crate) fn pidfd_open(pid: Pid, flags: PidfdFlags) -> io::Result { unsafe { - syscall_ret_owned_fd(libc::syscall( + syscall_ret_owned_fd(c::syscall( c::SYS_pidfd_open, pid.as_raw_nonzero().get(), flags.bits(), )) } } + +#[cfg(not(target_os = "wasi"))] +pub(crate) fn getgroups(buf: &mut [Gid]) -> io::Result { + let len = buf.len().try_into().map_err(|_| io::Errno::NOMEM)?; + + unsafe { ret_usize(c::getgroups(len, buf.as_mut_ptr().cast()) as isize) } +} + +#[cfg(any(target_os = "android", target_os = "linux"))] +pub(crate) fn sysinfo() -> Sysinfo { + let mut info = MaybeUninit::::uninit(); + unsafe { + ret_infallible(c::sysinfo(info.as_mut_ptr())); + info.assume_init() + } +} + +#[cfg(not(any(target_os = "emscripten", target_os = "redox", target_os = "wasi")))] +pub(crate) fn sethostname(name: &[u8]) -> io::Result<()> { + unsafe { + ret(c::sethostname( + name.as_ptr().cast(), + name.len().try_into().map_err(|_| io::Errno::INVAL)?, + )) + } +} diff --git a/vendor/rustix/src/backend/libc/process/types.rs b/vendor/rustix/src/backend/libc/process/types.rs index 203186b20..e7f10dbff 100644 --- a/vendor/rustix/src/backend/libc/process/types.rs +++ b/vendor/rustix/src/backend/libc/process/types.rs @@ -1,5 +1,9 @@ use super::super::c; +/// `sysinfo` +#[cfg(any(target_os = "android", target_os = "linux"))] +pub type Sysinfo = c::sysinfo; + /// A command for use with [`membarrier`] and [`membarrier_cpu`]. /// /// For `MEMBARRIER_CMD_QUERY`, see [`membarrier_query`]. @@ -7,8 +11,6 @@ use super::super::c; /// [`membarrier`]: crate::process::membarrier /// [`membarrier_cpu`]: crate::process::membarrier_cpu /// [`membarrier_query`]: crate::process::membarrier_query -// TODO: These are not yet exposed through libc, so we define the -// constants ourselves. #[cfg(any(target_os = "android", target_os = "linux"))] #[derive(Copy, Clone, Eq, PartialEq, Debug)] #[repr(u32)] @@ -16,23 +18,24 @@ pub enum MembarrierCommand { /// `MEMBARRIER_CMD_GLOBAL` #[doc(alias = "Shared")] #[doc(alias = "MEMBARRIER_CMD_SHARED")] - Global = 1, + Global = c::MEMBARRIER_CMD_GLOBAL as u32, /// `MEMBARRIER_CMD_GLOBAL_EXPEDITED` - GlobalExpedited = 2, + GlobalExpedited = c::MEMBARRIER_CMD_GLOBAL_EXPEDITED as u32, /// `MEMBARRIER_CMD_REGISTER_GLOBAL_EXPEDITED` - RegisterGlobalExpedited = 4, + RegisterGlobalExpedited = c::MEMBARRIER_CMD_REGISTER_GLOBAL_EXPEDITED as u32, /// `MEMBARRIER_CMD_PRIVATE_EXPEDITED` - PrivateExpedited = 8, + PrivateExpedited = c::MEMBARRIER_CMD_PRIVATE_EXPEDITED as u32, /// `MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED` - RegisterPrivateExpedited = 16, + RegisterPrivateExpedited = c::MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED as u32, /// `MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE` - PrivateExpeditedSyncCore = 32, + PrivateExpeditedSyncCore = c::MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE as u32, /// `MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_SYNC_CORE` - RegisterPrivateExpeditedSyncCore = 64, + RegisterPrivateExpeditedSyncCore = + c::MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_SYNC_CORE as u32, /// `MEMBARRIER_CMD_PRIVATE_EXPEDITED_RSEQ` (since Linux 5.10) - PrivateExpeditedRseq = 128, + PrivateExpeditedRseq = c::MEMBARRIER_CMD_PRIVATE_EXPEDITED_RSEQ as u32, /// `MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_RSEQ` (since Linux 5.10) - RegisterPrivateExpeditedRseq = 256, + RegisterPrivateExpeditedRseq = c::MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_RSEQ as u32, } /// A resource value for use with [`getrlimit`], [`setrlimit`], and @@ -98,9 +101,9 @@ pub enum Resource { } #[cfg(apple)] +#[allow(non_upper_case_globals)] impl Resource { /// `RLIMIT_RSS` - #[allow(non_upper_case_globals)] pub const Rss: Self = Self::As; } diff --git a/vendor/rustix/src/backend/libc/rand/syscalls.rs b/vendor/rustix/src/backend/libc/rand/syscalls.rs index ce1746055..2dcff139e 100644 --- a/vendor/rustix/src/backend/libc/rand/syscalls.rs +++ b/vendor/rustix/src/backend/libc/rand/syscalls.rs @@ -1,7 +1,7 @@ //! libc syscalls supporting `rustix::rand`. #[cfg(any(target_os = "android", target_os = "linux"))] -use {super::super::c, super::super::conv::ret_ssize_t, crate::io, crate::rand::GetRandomFlags}; +use {super::super::c, super::super::conv::ret_usize, crate::io, crate::rand::GetRandomFlags}; #[cfg(any(target_os = "android", target_os = "linux"))] pub(crate) fn getrandom(buf: &mut [u8], flags: GetRandomFlags) -> io::Result { @@ -10,7 +10,5 @@ pub(crate) fn getrandom(buf: &mut [u8], flags: GetRandomFlags) -> io::Result c::ssize_t } - let nread = - unsafe { ret_ssize_t(getrandom(buf.as_mut_ptr().cast(), buf.len(), flags.bits()))? }; - Ok(nread as usize) + unsafe { ret_usize(getrandom(buf.as_mut_ptr().cast(), buf.len(), flags.bits())) } } diff --git a/vendor/rustix/src/backend/libc/termios/syscalls.rs b/vendor/rustix/src/backend/libc/termios/syscalls.rs index 097d368ed..dba73c960 100644 --- a/vendor/rustix/src/backend/libc/termios/syscalls.rs +++ b/vendor/rustix/src/backend/libc/termios/syscalls.rs @@ -193,8 +193,8 @@ pub(crate) fn isatty(fd: BorrowedFd<'_>) -> bool { // Use the return value of `isatty` alone. We don't check `errno` because // we return `bool` rather than `io::Result`, because we assume // `BorrrowedFd` protects us from `EBADF`, and any other reasonably - // anticipated errno value would end up interpreted as "assume it's not a - // terminal" anyway. + // anticipated `errno` value would end up interpreted as “assume it's not a + // terminal” anyway. unsafe { c::isatty(borrowed_fd(fd)) != 0 } } diff --git a/vendor/rustix/src/backend/libc/termios/types.rs b/vendor/rustix/src/backend/libc/termios/types.rs index bbacdbea0..fdb7fc644 100644 --- a/vendor/rustix/src/backend/libc/termios/types.rs +++ b/vendor/rustix/src/backend/libc/termios/types.rs @@ -171,64 +171,52 @@ pub const VLNEXT: usize = c::VLNEXT as usize; pub const VEOL2: usize = c::VEOL2 as usize; /// `IGNBRK` -#[cfg(not(apple))] -pub const IGNBRK: c::c_uint = c::IGNBRK; +pub const IGNBRK: Tcflag = c::IGNBRK; /// `BRKINT` -#[cfg(not(apple))] -pub const BRKINT: c::c_uint = c::BRKINT; +pub const BRKINT: Tcflag = c::BRKINT; /// `IGNPAR` -#[cfg(not(apple))] -pub const IGNPAR: c::c_uint = c::IGNPAR; +pub const IGNPAR: Tcflag = c::IGNPAR; /// `PARMRK` -#[cfg(not(apple))] -pub const PARMRK: c::c_uint = c::PARMRK; +pub const PARMRK: Tcflag = c::PARMRK; /// `INPCK` -#[cfg(not(apple))] -pub const INPCK: c::c_uint = c::INPCK; +pub const INPCK: Tcflag = c::INPCK; /// `ISTRIP` -#[cfg(not(apple))] -pub const ISTRIP: c::c_uint = c::ISTRIP; +pub const ISTRIP: Tcflag = c::ISTRIP; /// `INLCR` -#[cfg(not(apple))] -pub const INLCR: c::c_uint = c::INLCR; +pub const INLCR: Tcflag = c::INLCR; /// `IGNCR` -#[cfg(not(apple))] -pub const IGNCR: c::c_uint = c::IGNCR; +pub const IGNCR: Tcflag = c::IGNCR; /// `ICRNL` -#[cfg(not(apple))] -pub const ICRNL: c::c_uint = c::ICRNL; +pub const ICRNL: Tcflag = c::ICRNL; /// `IUCLC` #[cfg(any(solarish, target_os = "haiku"))] -pub const IUCLC: c::c_uint = c::IUCLC; +pub const IUCLC: Tcflag = c::IUCLC; /// `IXON` -#[cfg(not(apple))] -pub const IXON: c::c_uint = c::IXON; +pub const IXON: Tcflag = c::IXON; /// `IXANY` -#[cfg(not(any(apple, target_os = "redox")))] -pub const IXANY: c::c_uint = c::IXANY; +#[cfg(not(target_os = "redox"))] +pub const IXANY: Tcflag = c::IXANY; /// `IXOFF` -#[cfg(not(apple))] -pub const IXOFF: c::c_uint = c::IXOFF; +pub const IXOFF: Tcflag = c::IXOFF; /// `IMAXBEL` -#[cfg(not(any(apple, target_os = "haiku", target_os = "redox")))] -pub const IMAXBEL: c::c_uint = c::IMAXBEL; +#[cfg(not(any(target_os = "haiku", target_os = "redox")))] +pub const IMAXBEL: Tcflag = c::IMAXBEL; /// `IUTF8` #[cfg(not(any( - apple, solarish, target_os = "aix", target_os = "dragonfly", @@ -239,11 +227,10 @@ pub const IMAXBEL: c::c_uint = c::IMAXBEL; target_os = "openbsd", target_os = "redox", )))] -pub const IUTF8: c::c_uint = c::IUTF8; +pub const IUTF8: Tcflag = c::IUTF8; /// `OPOST` -#[cfg(not(apple))] -pub const OPOST: c::c_uint = c::OPOST; +pub const OPOST: Tcflag = c::OPOST; /// `OLCUC` #[cfg(not(any( @@ -254,51 +241,47 @@ pub const OPOST: c::c_uint = c::OPOST; target_os = "netbsd", target_os = "redox", )))] -pub const OLCUC: c::c_uint = c::OLCUC; +pub const OLCUC: Tcflag = c::OLCUC; /// `ONLCR` -#[cfg(not(apple))] -pub const ONLCR: c::c_uint = c::ONLCR; +pub const ONLCR: Tcflag = c::ONLCR; /// `OCRNL` -#[cfg(not(apple))] -pub const OCRNL: c::c_uint = c::OCRNL; +pub const OCRNL: Tcflag = c::OCRNL; /// `ONOCR` -#[cfg(not(apple))] -pub const ONOCR: c::c_uint = c::ONOCR; +pub const ONOCR: Tcflag = c::ONOCR; /// `ONLRET` -#[cfg(not(apple))] -pub const ONLRET: c::c_uint = c::ONLRET; +pub const ONLRET: Tcflag = c::ONLRET; /// `OFILL` #[cfg(not(bsd))] -pub const OFILL: c::c_uint = c::OFILL; +pub const OFILL: Tcflag = c::OFILL; /// `OFDEL` #[cfg(not(bsd))] -pub const OFDEL: c::c_uint = c::OFDEL; +pub const OFDEL: Tcflag = c::OFDEL; /// `NLDLY` #[cfg(not(any(bsd, solarish, target_os = "redox")))] -pub const NLDLY: c::c_uint = c::NLDLY; +pub const NLDLY: Tcflag = c::NLDLY; /// `NL0` #[cfg(not(any(bsd, solarish, target_os = "fuchsia", target_os = "redox")))] -pub const NL0: c::c_uint = c::NL0; +pub const NL0: Tcflag = c::NL0; /// `NL1` #[cfg(not(any(bsd, solarish, target_os = "fuchsia", target_os = "redox")))] -pub const NL1: c::c_uint = c::NL1; +pub const NL1: Tcflag = c::NL1; /// `CRDLY` #[cfg(not(any(bsd, solarish, target_os = "redox")))] -pub const CRDLY: c::c_uint = c::CRDLY; +pub const CRDLY: Tcflag = c::CRDLY; /// `CR0` #[cfg(not(any(bsd, solarish, target_os = "fuchsia", target_os = "redox")))] -pub const CR0: c::c_uint = c::CR0; +pub const CR0: Tcflag = c::CR0; /// `CR1` #[cfg(not(any( @@ -309,7 +292,7 @@ pub const CR0: c::c_uint = c::CR0; target_os = "fuchsia", target_os = "redox", )))] -pub const CR1: c::c_uint = c::CR1; +pub const CR1: Tcflag = c::CR1; /// `CR2` #[cfg(not(any( @@ -320,7 +303,7 @@ pub const CR1: c::c_uint = c::CR1; target_os = "fuchsia", target_os = "redox", )))] -pub const CR2: c::c_uint = c::CR2; +pub const CR2: Tcflag = c::CR2; /// `CR3` #[cfg(not(any( @@ -331,28 +314,21 @@ pub const CR2: c::c_uint = c::CR2; target_os = "fuchsia", target_os = "redox", )))] -pub const CR3: c::c_uint = c::CR3; +pub const CR3: Tcflag = c::CR3; /// `TABDLY` -#[cfg(not(any( - apple, - netbsdlike, - solarish, - target_os = "dragonfly", - target_os = "redox", -)))] -pub const TABDLY: c::c_uint = c::TABDLY; +#[cfg(not(any(netbsdlike, solarish, target_os = "dragonfly", target_os = "redox",)))] +pub const TABDLY: Tcflag = c::TABDLY; /// `TAB0` #[cfg(not(any( - apple, netbsdlike, solarish, target_os = "dragonfly", target_os = "fuchsia", target_os = "redox", )))] -pub const TAB0: c::c_uint = c::TAB0; +pub const TAB0: Tcflag = c::TAB0; /// `TAB1` #[cfg(not(any( @@ -363,7 +339,7 @@ pub const TAB0: c::c_uint = c::TAB0; target_os = "fuchsia", target_os = "redox", )))] -pub const TAB1: c::c_uint = c::TAB1; +pub const TAB1: Tcflag = c::TAB1; /// `TAB2` #[cfg(not(any( @@ -374,7 +350,7 @@ pub const TAB1: c::c_uint = c::TAB1; target_os = "fuchsia", target_os = "redox", )))] -pub const TAB2: c::c_uint = c::TAB2; +pub const TAB2: Tcflag = c::TAB2; /// `TAB3` #[cfg(not(any( @@ -385,15 +361,15 @@ pub const TAB2: c::c_uint = c::TAB2; target_os = "fuchsia", target_os = "redox", )))] -pub const TAB3: c::c_uint = c::TAB3; +pub const TAB3: Tcflag = c::TAB3; /// `BSDLY` #[cfg(not(any(bsd, solarish, target_os = "redox")))] -pub const BSDLY: c::c_uint = c::BSDLY; +pub const BSDLY: Tcflag = c::BSDLY; /// `BS0` #[cfg(not(any(bsd, solarish, target_os = "fuchsia", target_os = "redox")))] -pub const BS0: c::c_uint = c::BS0; +pub const BS0: Tcflag = c::BS0; /// `BS1` #[cfg(not(any( @@ -404,15 +380,15 @@ pub const BS0: c::c_uint = c::BS0; target_os = "fuchsia", target_os = "redox", )))] -pub const BS1: c::c_uint = c::BS1; +pub const BS1: Tcflag = c::BS1; /// `FFDLY` #[cfg(not(any(target_env = "musl", bsd, solarish, target_os = "redox")))] -pub const FFDLY: c::c_uint = c::FFDLY; +pub const FFDLY: Tcflag = c::FFDLY; /// `FF0` #[cfg(not(any(bsd, solarish, target_os = "fuchsia", target_os = "redox")))] -pub const FF0: c::c_uint = c::FF0; +pub const FF0: Tcflag = c::FF0; /// `FF1` #[cfg(not(any( @@ -423,15 +399,15 @@ pub const FF0: c::c_uint = c::FF0; target_os = "fuchsia", target_os = "redox", )))] -pub const FF1: c::c_uint = c::FF1; +pub const FF1: Tcflag = c::FF1; /// `VTDLY` #[cfg(not(any(target_env = "musl", bsd, solarish, target_os = "redox")))] -pub const VTDLY: c::c_uint = c::VTDLY; +pub const VTDLY: Tcflag = c::VTDLY; /// `VT0` #[cfg(not(any(bsd, solarish, target_os = "fuchsia", target_os = "redox")))] -pub const VT0: c::c_uint = c::VT0; +pub const VT0: Tcflag = c::VT0; /// `VT1` #[cfg(not(any( @@ -442,7 +418,7 @@ pub const VT0: c::c_uint = c::VT0; target_os = "fuchsia", target_os = "redox", )))] -pub const VT1: c::c_uint = c::VT1; +pub const VT1: Tcflag = c::VT1; /// `B0` pub const B0: Speed = c::B0; @@ -594,111 +570,90 @@ pub const B4000000: Speed = c::B4000000; /// `BOTHER` #[cfg(any(target_os = "android", target_os = "linux"))] -pub const BOTHER: c::c_uint = c::BOTHER; +pub const BOTHER: Speed = c::BOTHER; /// `CSIZE` -#[cfg(not(apple))] -pub const CSIZE: c::c_uint = c::CSIZE; +pub const CSIZE: Tcflag = c::CSIZE; /// `CS5` -#[cfg(not(apple))] -pub const CS5: c::c_uint = c::CS5; +pub const CS5: Tcflag = c::CS5; /// `CS6` -#[cfg(not(apple))] -pub const CS6: c::c_uint = c::CS6; +pub const CS6: Tcflag = c::CS6; /// `CS7` -#[cfg(not(apple))] -pub const CS7: c::c_uint = c::CS7; +pub const CS7: Tcflag = c::CS7; /// `CS8` -#[cfg(not(apple))] -pub const CS8: c::c_uint = c::CS8; +pub const CS8: Tcflag = c::CS8; /// `CSTOPB` -#[cfg(not(apple))] -pub const CSTOPB: c::c_uint = c::CSTOPB; +pub const CSTOPB: Tcflag = c::CSTOPB; /// `CREAD` -#[cfg(not(apple))] -pub const CREAD: c::c_uint = c::CREAD; +pub const CREAD: Tcflag = c::CREAD; /// `PARENB` -#[cfg(not(apple))] -pub const PARENB: c::c_uint = c::PARENB; +pub const PARENB: Tcflag = c::PARENB; /// `PARODD` -#[cfg(not(apple))] -pub const PARODD: c::c_uint = c::PARODD; +pub const PARODD: Tcflag = c::PARODD; /// `HUPCL` -#[cfg(not(apple))] -pub const HUPCL: c::c_uint = c::HUPCL; +pub const HUPCL: Tcflag = c::HUPCL; /// `CLOCAL` -#[cfg(not(apple))] -pub const CLOCAL: c::c_uint = c::CLOCAL; +pub const CLOCAL: Tcflag = c::CLOCAL; /// `ISIG` -#[cfg(not(apple))] -pub const ISIG: c::c_uint = c::ISIG; +pub const ISIG: Tcflag = c::ISIG; /// `ICANON`—A flag for the `c_lflag` field of [`Termios`] indicating /// canonical mode. pub const ICANON: Tcflag = c::ICANON; /// `ECHO` -#[cfg(not(apple))] -pub const ECHO: c::c_uint = c::ECHO; +pub const ECHO: Tcflag = c::ECHO; /// `ECHOE` -#[cfg(not(apple))] -pub const ECHOE: c::c_uint = c::ECHOE; +pub const ECHOE: Tcflag = c::ECHOE; /// `ECHOK` -#[cfg(not(apple))] -pub const ECHOK: c::c_uint = c::ECHOK; +pub const ECHOK: Tcflag = c::ECHOK; /// `ECHONL` -#[cfg(not(apple))] -pub const ECHONL: c::c_uint = c::ECHONL; +pub const ECHONL: Tcflag = c::ECHONL; /// `NOFLSH` -#[cfg(not(apple))] -pub const NOFLSH: c::c_uint = c::NOFLSH; +pub const NOFLSH: Tcflag = c::NOFLSH; /// `TOSTOP` -#[cfg(not(apple))] -pub const TOSTOP: c::c_uint = c::TOSTOP; +pub const TOSTOP: Tcflag = c::TOSTOP; /// `IEXTEN` -#[cfg(not(apple))] -pub const IEXTEN: c::c_uint = c::IEXTEN; +pub const IEXTEN: Tcflag = c::IEXTEN; /// `EXTA` #[cfg(not(any( - apple, solarish, target_os = "emscripten", target_os = "haiku", target_os = "redox", )))] -pub const EXTA: c::c_uint = c::EXTA; +pub const EXTA: Speed = c::EXTA; /// `EXTB` #[cfg(not(any( - apple, solarish, target_os = "emscripten", target_os = "haiku", target_os = "redox", )))] -pub const EXTB: c::c_uint = c::EXTB; +pub const EXTB: Speed = c::EXTB; /// `CBAUD` #[cfg(not(any(bsd, target_os = "haiku", target_os = "redox")))] -pub const CBAUD: c::c_uint = c::CBAUD; +pub const CBAUD: Tcflag = c::CBAUD; /// `CBAUDEX` #[cfg(not(any( @@ -708,7 +663,7 @@ pub const CBAUD: c::c_uint = c::CBAUD; target_os = "haiku", target_os = "redox", )))] -pub const CBAUDEX: c::c_uint = c::CBAUDEX; +pub const CBAUDEX: Tcflag = c::CBAUDEX; /// `CIBAUD` #[cfg(not(any( @@ -719,12 +674,13 @@ pub const CBAUDEX: c::c_uint = c::CBAUDEX; target_os = "haiku", target_os = "redox", )))] -pub const CIBAUD: c::tcflag_t = c::CIBAUD; +pub const CIBAUD: Tcflag = c::CIBAUD; /// `CIBAUD` -// TODO: Upstream this. +// glibc on powerpc lacks a definition for `CIBAUD`, even though the Linux +// headers and Musl on powerpc both have one. So define it manually. #[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))] -pub const CIBAUD: c::tcflag_t = 0o77600000; +pub const CIBAUD: Tcflag = 0o77600000; /// `CMSPAR` #[cfg(not(any( @@ -735,39 +691,39 @@ pub const CIBAUD: c::tcflag_t = 0o77600000; target_os = "haiku", target_os = "redox", )))] -pub const CMSPAR: c::c_uint = c::CMSPAR; +pub const CMSPAR: Tcflag = c::CMSPAR; /// `CRTSCTS` -#[cfg(not(any(apple, target_os = "aix", target_os = "redox")))] -pub const CRTSCTS: c::c_uint = c::CRTSCTS; +#[cfg(not(any(target_os = "aix", target_os = "redox")))] +pub const CRTSCTS: Tcflag = c::CRTSCTS; /// `XCASE` #[cfg(any(target_arch = "s390x", target_os = "haiku"))] -pub const XCASE: c::c_uint = c::XCASE; +pub const XCASE: Tcflag = c::XCASE; /// `ECHOCTL` -#[cfg(not(any(apple, target_os = "redox")))] -pub const ECHOCTL: c::c_uint = c::ECHOCTL; +#[cfg(not(any(target_os = "redox")))] +pub const ECHOCTL: Tcflag = c::ECHOCTL; /// `ECHOPRT` -#[cfg(not(any(apple, target_os = "redox")))] -pub const ECHOPRT: c::c_uint = c::ECHOPRT; +#[cfg(not(any(target_os = "redox")))] +pub const ECHOPRT: Tcflag = c::ECHOPRT; /// `ECHOKE` -#[cfg(not(any(apple, target_os = "redox")))] -pub const ECHOKE: c::c_uint = c::ECHOKE; +#[cfg(not(any(target_os = "redox")))] +pub const ECHOKE: Tcflag = c::ECHOKE; /// `FLUSHO` -#[cfg(not(any(apple, target_os = "redox")))] -pub const FLUSHO: c::c_uint = c::FLUSHO; +#[cfg(not(any(target_os = "redox")))] +pub const FLUSHO: Tcflag = c::FLUSHO; /// `PENDIN` -#[cfg(not(any(apple, target_os = "redox")))] -pub const PENDIN: c::c_uint = c::PENDIN; +#[cfg(not(any(target_os = "redox")))] +pub const PENDIN: Tcflag = c::PENDIN; /// `EXTPROC` -#[cfg(not(any(apple, target_os = "aix", target_os = "haiku", target_os = "redox")))] -pub const EXTPROC: c::c_uint = c::EXTPROC; +#[cfg(not(any(target_os = "aix", target_os = "haiku", target_os = "redox")))] +pub const EXTPROC: Tcflag = c::EXTPROC; /// `XTABS` #[cfg(not(any( @@ -777,4 +733,4 @@ pub const EXTPROC: c::c_uint = c::EXTPROC; target_os = "haiku", target_os = "redox", )))] -pub const XTABS: c::c_uint = c::XTABS; +pub const XTABS: Tcflag = c::XTABS; diff --git a/vendor/rustix/src/backend/libc/time/types.rs b/vendor/rustix/src/backend/libc/time/types.rs index 47cd85701..c78aeb21a 100644 --- a/vendor/rustix/src/backend/libc/time/types.rs +++ b/vendor/rustix/src/backend/libc/time/types.rs @@ -108,7 +108,7 @@ impl From for LibcTimespec { /// `CLOCK_*` constants for use with [`clock_gettime`]. /// -/// These constants are always supported at runtime so `clock_gettime` never +/// These constants are always supported at runtime, so `clock_gettime` never /// has to fail with `INVAL` due to an unsupported clock. See /// [`DynamicClockId`] for a greater set of clocks, with the caveat that not /// all of them are always supported. @@ -153,7 +153,7 @@ pub enum ClockId { /// `CLOCK_*` constants for use with [`clock_gettime`]. /// -/// These constants are always supported at runtime so `clock_gettime` never +/// These constants are always supported at runtime, so `clock_gettime` never /// has to fail with `INVAL` due to an unsupported clock. See /// [`DynamicClockId`] for a greater set of clocks, with the caveat that not /// all of them are always supported. @@ -209,7 +209,11 @@ pub enum DynamicClockId<'a> { BoottimeAlarm, } -/// `struct itimerspec` +/// `struct itimerspec` for use with [`timerfd_gettime`] and +/// [`timerfd_settime`]. +/// +/// [`timerfd_gettime`]: crate::time::timerfd_gettime +/// [`timerfd_settime`]: crate::time::timerfd_settime #[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))] #[cfg(not(all( any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), @@ -217,7 +221,11 @@ pub enum DynamicClockId<'a> { )))] pub type Itimerspec = c::itimerspec; -/// `struct itimerspec` +/// `struct itimerspec` for use with [`timerfd_gettime`] and +/// [`timerfd_settime`]. +/// +/// [`timerfd_gettime`]: crate::time::timerfd_gettime +/// [`timerfd_settime`]: crate::time::timerfd_settime #[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))] #[cfg(all( any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), @@ -286,6 +294,8 @@ impl From for LibcItimerspec { #[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))] bitflags! { /// `TFD_*` flags for use with [`timerfd_create`]. + /// + /// [`timerfd_create`]: crate::time::timerfd_create pub struct TimerfdFlags: c::c_int { /// `TFD_NONBLOCK` const NONBLOCK = c::TFD_NONBLOCK; @@ -298,6 +308,8 @@ bitflags! { #[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))] bitflags! { /// `TFD_TIMER_*` flags for use with [`timerfd_settime`]. + /// + /// [`timerfd_settime`]: crate::time::timerfd_settime pub struct TimerfdTimerFlags: c::c_int { /// `TFD_TIMER_ABSTIME` const ABSTIME = c::TFD_TIMER_ABSTIME; @@ -316,7 +328,7 @@ bitflags! { #[repr(i32)] #[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/libc/weak.rs b/vendor/rustix/src/backend/libc/weak.rs deleted file mode 100644 index b7f185da3..000000000 --- a/vendor/rustix/src/backend/libc/weak.rs +++ /dev/null @@ -1,226 +0,0 @@ -// Implementation derived from `weak` in Rust's -// library/std/src/sys/unix/weak.rs at revision -// fd0cb0cdc21dd9c06025277d772108f8d42cb25f. - -//! 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 $ret> = - $crate::backend::weak::Weak::new(concat!(stringify!($name), '\0')); - ) -} - -pub(crate) struct Weak { - name: &'static str, - addr: AtomicPtr, - _marker: marker::PhantomData, -} - -impl Weak { - pub(crate) const fn new(name: &'static str) -> Self { - Self { - name, - addr: AtomicPtr::new(INVALID), - _marker: marker::PhantomData, - } - } - - pub(crate) fn get(&self) -> Option { - assert_eq!(mem::size_of::(), mem::size_of::()); - 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 { - 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 AsSyscallArg for *mut T { - type SyscallArgType = *mut T; - fn into_syscall_arg(self) -> Self::SyscallArgType { self } - } - impl 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),*) - } - } - ) -} diff --git a/vendor/rustix/src/backend/libc/winsock_c.rs b/vendor/rustix/src/backend/libc/winsock_c.rs index 521a7bbb1..a30f2c86f 100644 --- a/vendor/rustix/src/backend/libc/winsock_c.rs +++ b/vendor/rustix/src/backend/libc/winsock_c.rs @@ -5,52 +5,26 @@ use windows_sys::Win32::Networking::WinSock; -pub(crate) use libc::{ - c_char, c_int, c_long, c_longlong, c_schar, c_short, c_uchar, c_uint, c_ulong, c_ulonglong, - c_ushort, c_void, ssize_t, -}; -pub(crate) type socklen_t = i32; +// Define the basic C types. With Rust 1.64, we can use these from `core::ffi`. +pub(crate) type c_schar = i8; +pub(crate) type c_uchar = u8; +pub(crate) type c_short = i16; +pub(crate) type c_ushort = u16; +pub(crate) type c_int = i32; +pub(crate) type c_uint = u32; +pub(crate) type c_longlong = i64; +pub(crate) type c_ulonglong = u64; +pub(crate) type ssize_t = isize; +pub(crate) type c_char = i8; +pub(crate) type c_long = i32; +pub(crate) type c_ulong = u32; +pub(crate) use core::ffi::c_void; -// windows-sys declares these constants as unsigned. For better compatibility -// with Unix-family APIs, redeclare them as signed. Filed upstream: -// +// windows-sys declares these constants as u16. For better compatibility +// with Unix-family APIs, redeclare them as u32. pub(crate) const AF_INET: i32 = WinSock::AF_INET as _; pub(crate) const AF_INET6: i32 = WinSock::AF_INET6 as _; pub(crate) const AF_UNSPEC: i32 = WinSock::AF_UNSPEC as _; -pub(crate) const SO_TYPE: i32 = WinSock::SO_TYPE as _; -pub(crate) const SO_REUSEADDR: i32 = WinSock::SO_REUSEADDR as _; -pub(crate) const SO_BROADCAST: i32 = WinSock::SO_BROADCAST as _; -pub(crate) const SO_LINGER: i32 = WinSock::SO_LINGER as _; -pub(crate) const SOL_SOCKET: i32 = WinSock::SOL_SOCKET as _; -pub(crate) const SO_RCVTIMEO: i32 = WinSock::SO_RCVTIMEO as _; -pub(crate) const SO_SNDTIMEO: i32 = WinSock::SO_SNDTIMEO as _; -pub(crate) const SO_ERROR: i32 = WinSock::SO_ERROR as _; -pub(crate) const IP_TTL: i32 = WinSock::IP_TTL as _; -pub(crate) const TCP_NODELAY: i32 = WinSock::TCP_NODELAY as _; -pub(crate) const IP_ADD_MEMBERSHIP: i32 = WinSock::IP_ADD_MEMBERSHIP as _; -pub(crate) const IP_DROP_MEMBERSHIP: i32 = WinSock::IP_DROP_MEMBERSHIP as _; -pub(crate) const IP_MULTICAST_TTL: i32 = WinSock::IP_MULTICAST_TTL as _; -pub(crate) const IP_MULTICAST_LOOP: i32 = WinSock::IP_MULTICAST_LOOP as _; -pub(crate) const IPV6_ADD_MEMBERSHIP: i32 = WinSock::IPV6_ADD_MEMBERSHIP as _; -pub(crate) const IPV6_DROP_MEMBERSHIP: i32 = WinSock::IPV6_DROP_MEMBERSHIP as _; -pub(crate) const IPV6_MULTICAST_LOOP: i32 = WinSock::IPV6_MULTICAST_LOOP as _; -pub(crate) const IPV6_V6ONLY: i32 = WinSock::IPV6_V6ONLY as _; -pub(crate) const POLLERR: i16 = WinSock::POLLERR as _; -pub(crate) const POLLIN: i16 = WinSock::POLLIN as _; -pub(crate) const POLLNVAL: i16 = WinSock::POLLNVAL as _; -pub(crate) const POLLHUP: i16 = WinSock::POLLHUP as _; -pub(crate) const POLLPRI: i16 = WinSock::POLLPRI as _; -pub(crate) const POLLOUT: i16 = WinSock::POLLOUT as _; -pub(crate) const POLLRDNORM: i16 = WinSock::POLLRDNORM as _; -pub(crate) const POLLWRNORM: i16 = WinSock::POLLWRNORM as _; -pub(crate) const POLLRDBAND: i16 = WinSock::POLLRDBAND as _; -pub(crate) const POLLWRBAND: i16 = WinSock::POLLWRBAND as _; - -// As above, cast the types for better compatibility, and also rename these to -// their Unix names. -pub(crate) const SHUT_RDWR: i32 = WinSock::SD_BOTH as _; -pub(crate) const SHUT_RD: i32 = WinSock::SD_RECEIVE as _; -pub(crate) const SHUT_WR: i32 = WinSock::SD_SEND as _; // Include the contents of `WinSock`, renaming as needed to match POSIX. // @@ -58,11 +32,16 @@ pub(crate) const SHUT_WR: i32 = WinSock::SD_SEND as _; // `WSAECANCELLED` will be removed in the future. // pub(crate) use WinSock::{ - closesocket as close, ioctlsocket as ioctl, WSAPoll as poll, ADDRESS_FAMILY as sa_family_t, - ADDRINFOA as addrinfo, IN6_ADDR as in6_addr, IN_ADDR as in_addr, IPV6_MREQ as ipv6_mreq, - IP_MREQ as ip_mreq, LINGER as linger, SOCKADDR as sockaddr, SOCKADDR_IN as sockaddr_in, - SOCKADDR_IN6 as sockaddr_in6, SOCKADDR_STORAGE as sockaddr_storage, WSAEACCES as EACCES, - WSAEADDRINUSE as EADDRINUSE, WSAEADDRNOTAVAIL as EADDRNOTAVAIL, + closesocket as close, ioctlsocket as ioctl, socklen_t, WSAPoll as poll, + ADDRESS_FAMILY as sa_family_t, ADDRINFOA as addrinfo, IN6_ADDR as in6_addr, IN_ADDR as in_addr, + IPV6_ADD_MEMBERSHIP, IPV6_DROP_MEMBERSHIP, IPV6_MREQ as ipv6_mreq, IPV6_MULTICAST_LOOP, + IPV6_V6ONLY, IP_ADD_MEMBERSHIP, IP_DROP_MEMBERSHIP, IP_MREQ as ip_mreq, IP_MULTICAST_LOOP, + IP_MULTICAST_TTL, IP_TTL, LINGER as linger, POLLERR, POLLHUP, POLLIN, POLLNVAL, POLLOUT, + POLLPRI, POLLRDBAND, POLLRDNORM, POLLWRBAND, POLLWRNORM, SD_BOTH as SHUT_RDWR, + SD_RECEIVE as SHUT_RD, SD_SEND as SHUT_WR, SOCKADDR as sockaddr, SOCKADDR_IN as sockaddr_in, + SOCKADDR_IN6 as sockaddr_in6, SOCKADDR_STORAGE as sockaddr_storage, SOL_SOCKET, SO_BROADCAST, + SO_ERROR, SO_LINGER, SO_RCVTIMEO, SO_REUSEADDR, SO_SNDTIMEO, SO_TYPE, TCP_NODELAY, + WSAEACCES as EACCES, WSAEADDRINUSE as EADDRINUSE, WSAEADDRNOTAVAIL as EADDRNOTAVAIL, WSAEAFNOSUPPORT as EAFNOSUPPORT, WSAEALREADY as EALREADY, WSAEBADF as EBADF, WSAECONNABORTED as ECONNABORTED, WSAECONNREFUSED as ECONNREFUSED, WSAECONNRESET as ECONNRESET, WSAEDESTADDRREQ as EDESTADDRREQ, WSAEDISCON as EDISCON, WSAEDQUOT as EDQUOT, 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 @@ -189,6 +189,11 @@ pub(super) fn slice_just_addr(v: &[T]) -> ArgReg raw_arg(mut_ptr.cast()) } +#[inline] +pub(super) fn slice_just_addr_mut(v: &mut [T]) -> ArgReg { + raw_arg(v.as_mut_ptr().cast()) +} + #[inline] pub(super) fn slice( v: &[T], @@ -313,6 +318,14 @@ impl<'a, Num: ArgNumber> From for ArgReg<'a, Num> { } } +#[cfg(feature = "fs")] +impl<'a, Num: ArgNumber> From for ArgReg<'a, Num> { + #[inline] + fn from(flags: crate::fs::XattrFlags) -> Self { + c_uint(flags.bits()) + } +} + #[cfg(feature = "fs")] impl<'a, Num: ArgNumber> From for ArgReg<'a, Num> { #[inline] @@ -615,9 +628,9 @@ impl<'a, Num: ArgNumber> From for ArgReg<'a, Num> { } #[cfg(feature = "net")] -impl<'a, Num: ArgNumber> From for ArgReg<'a, Num> { +impl<'a, Num: ArgNumber> From 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> for ArgReg<'a, Num> { } } +impl<'a, Num: ArgNumber, T> From<&'a mut [MaybeUninit]> for ArgReg<'a, Num> { + #[inline] + fn from(t: &'a mut [MaybeUninit]) -> Self { + raw_arg(t.as_mut_ptr().cast()) + } +} + #[cfg(feature = "fs")] #[cfg(any(target_os = "android", target_os = "linux"))] impl<'a, Num: ArgNumber> From for ArgReg<'a, Num> { @@ -713,6 +733,14 @@ impl<'a, Num: ArgNumber> From for ArgReg<'a, Num> { } } +#[cfg(feature = "runtime")] +impl<'a, Num: ArgNumber> From 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 { 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 { + 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 { + 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 { + 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 { + 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 { + 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 { + 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() + size_of::() )) } #[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 { } #[inline] -pub(crate) fn accept_with(fd: BorrowedFd<'_>, flags: AcceptFlags) -> io::Result { +pub(crate) fn accept_with(fd: BorrowedFd<'_>, flags: SocketFlags) -> io::Result { #[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, - flags: AcceptFlags, + flags: SocketFlags, ) -> io::Result<(OwnedFd, Option)> { #[cfg(not(target_arch = "x86"))] unsafe { @@ -1066,15 +1066,52 @@ pub(crate) mod sockopt { } #[inline] - pub(crate) fn get_socket_error(fd: BorrowedFd<'_>) -> io::Result> { + pub(crate) fn get_socket_error(fd: BorrowedFd<'_>) -> io::Result> { 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 { + 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 { + 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 { + 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) @@ -1199,6 +1236,20 @@ pub(crate) mod sockopt { setsockopt(fd, c::IPPROTO_IPV6 as _, c::IPV6_DROP_MEMBERSHIP, mreq) } + #[inline] + pub(crate) fn get_ipv6_unicast_hops(fd: BorrowedFd<'_>) -> io::Result { + 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) -> 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; @@ -42,6 +44,11 @@ pub(crate) fn fchdir(fd: BorrowedFd<'_>) -> io::Result<()> { unsafe { ret(syscall_readonly!(__NR_fchdir, fd)) } } +#[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 { let (buf_addr_mut, buf_len) = slice_mut(buf); @@ -115,6 +122,17 @@ pub(crate) fn getpgid(pid: Option) -> io::Result { } } +#[inline] +pub(crate) fn setpgid(pid: Option, pgid: Option) -> 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. @@ -541,7 +559,9 @@ pub(crate) fn waitid(id: WaitId<'_>, options: WaitidOptions) -> io::Result io::Result> { - let mut status = MaybeUninit::::uninit(); + // `waitid` can return successfully without initializing the struct (no + // children found when using `WNOHANG`) + let mut status = MaybeUninit::::zeroed(); unsafe { ret(syscall!( __NR_waitid, @@ -558,7 +578,9 @@ fn _waitid_all(options: WaitidOptions) -> io::Result> { #[inline] fn _waitid_pid(pid: Pid, options: WaitidOptions) -> io::Result> { - let mut status = MaybeUninit::::uninit(); + // `waitid` can return successfully without initializing the struct (no + // children found when using `WNOHANG`) + let mut status = MaybeUninit::::zeroed(); unsafe { ret(syscall!( __NR_waitid, @@ -575,7 +597,9 @@ fn _waitid_pid(pid: Pid, options: WaitidOptions) -> io::Result, options: WaitidOptions) -> io::Result> { - let mut status = MaybeUninit::::uninit(); + // `waitid` can return successfully without initializing the struct (no + // children found when using `WNOHANG`) + let mut status = MaybeUninit::::zeroed(); unsafe { ret(syscall!( __NR_waitid, @@ -597,9 +621,10 @@ fn _waitid_pidfd(fd: BorrowedFd<'_>, options: WaitidOptions) -> io::Result) -> Option { 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)) @@ -612,6 +637,17 @@ pub(crate) fn exit_group(code: c::c_int) -> ! { unsafe { syscall_noreturn!(__NR_exit_group, c_int(code)) } } +#[inline] +pub(crate) fn getsid(pid: Option) -> io::Result { + 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 { unsafe { @@ -638,6 +674,27 @@ pub(crate) fn kill_current_process_group(sig: Signal) -> io::Result<()> { unsafe { ret(syscall_readonly!(__NR_kill, pass_usize(0), sig)) } } +#[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, @@ -659,3 +716,31 @@ pub(crate) fn pidfd_open(pid: Pid, flags: PidfdFlags) -> io::Result { )) } } + +#[inline] +pub(crate) fn getgroups(buf: &mut [Gid]) -> io::Result { + 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::::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) -> io::Result { + let mut old = MaybeUninit::::uninit(); + let new = optional_as_ptr(new.as_ref()); + ret(syscall!( + __NR_rt_sigaction, + signal, + new, + &mut old, + size_of::() + ))?; + Ok(old.assume_init()) +} + +#[inline] +pub(crate) unsafe fn sigaltstack(new: Option) -> io::Result { + let mut old = MaybeUninit::::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 { + let mut old = MaybeUninit::::uninit(); + ret(syscall!( + __NR_rt_sigprocmask, + how, + by_ref(set), + &mut old, + size_of::() + ))?; + Ok(old.assume_init()) +} + +#[inline] +pub(crate) fn sigwait(set: &Sigset) -> io::Result { + unsafe { + match Signal::from_raw(ret_c_int(syscall_readonly!( + __NR_rt_sigtimedwait, + by_ref(set), + zero(), + zero(), + size_of::() + ))?) { + Some(signum) => Ok(signum), + None => Err(io::Errno::NOTSUP), + } + } +} + +#[inline] +pub(crate) fn sigwaitinfo(set: &Sigset) -> io::Result { + let mut info = MaybeUninit::::uninit(); + unsafe { + let _signum = ret_c_int(syscall!( + __NR_rt_sigtimedwait, + by_ref(set), + &mut info, + zero(), + size_of::() + ))?; + Ok(info.assume_init()) + } +} + +#[inline] +pub(crate) fn sigtimedwait(set: &Sigset, timeout: Option) -> io::Result { + let mut info = MaybeUninit::::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::() + )) { + 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::() + ))?; + Ok(info.assume_init()) + } +} + +#[cfg(target_pointer_width = "32")] +unsafe fn sigtimedwait_old( + set: &Sigset, + timeout: Option, + info: &mut MaybeUninit, +) -> 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::() + ))?; + + 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 { // 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 { 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], ) -> 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 { .as_ptr(); num_dyn = phdr.p_memsz / size_of::(); } 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 $ret> = - $crate::backend::weak::Weak::new(concat!(stringify!($name), '\0')); - ) -} - -pub(crate) struct Weak { - name: &'static str, - addr: AtomicPtr, - _marker: marker::PhantomData, -} - -impl Weak { - pub(crate) const fn new(name: &'static str) -> Self { - Self { - name, - addr: AtomicPtr::new(INVALID), - _marker: marker::PhantomData, - } - } - - pub(crate) fn get(&self) -> Option { - assert_eq!(mem::size_of::(), mem::size_of::()); - 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 { - 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 AsSyscallArg for *mut T { - type SyscallArgType = *mut T; - fn into_syscall_arg(self) -> Self::SyscallArgType { self } - } - impl 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),*) - } - } - ) -} -- cgit v1.2.3