diff options
Diffstat (limited to 'vendor/rustix/src/backend')
100 files changed, 1757 insertions, 1252 deletions
diff --git a/vendor/rustix/src/backend/libc/c.rs b/vendor/rustix/src/backend/libc/c.rs index f9e94416c..eb89fa43a 100644 --- a/vendor/rustix/src/backend/libc/c.rs +++ b/vendor/rustix/src/backend/libc/c.rs @@ -1,3 +1,5 @@ +//! Libc and supplemental types and constants. + #![allow(unused_imports)] // Import everything from libc, but we'll add some stuff and override some @@ -12,6 +14,10 @@ pub(crate) const PROC_SUPER_MAGIC: u32 = 0x0000_9fa0; #[cfg(all(linux_kernel, target_env = "musl"))] pub(crate) const NFS_SUPER_MAGIC: u32 = 0x0000_6969; +#[cfg(feature = "process")] +#[cfg(not(any(target_os = "espidf", target_os = "wasi")))] +pub(crate) const EXIT_SIGNALED_SIGABRT: c_int = 128 + SIGABRT as c_int; + // TODO: Upstream these. #[cfg(all(linux_kernel, feature = "net"))] pub(crate) const ETH_P_TSN: c_int = linux_raw_sys::if_ether::ETH_P_TSN as _; @@ -77,6 +83,9 @@ pub(crate) const IUCLC: tcflag_t = linux_raw_sys::general::IUCLC as _; #[cfg(all(linux_kernel, feature = "termios"))] pub(crate) const XCASE: tcflag_t = linux_raw_sys::general::XCASE as _; +#[cfg(target_os = "aix")] +pub(crate) const MSG_DONTWAIT: c_int = libc::MSG_NONBLOCK; + // On PowerPC, the regular `termios` has the `termios2` fields and there is no // `termios2`. linux-raw-sys has aliases `termios2` to `termios` to cover this // difference, but we still need to manually import it since `libc` doesn't @@ -104,13 +113,15 @@ pub(super) use libc::open64 as open; pub(super) use libc::posix_fallocate64 as posix_fallocate; #[cfg(any(all(linux_like, not(target_os = "android")), target_os = "aix"))] pub(super) use libc::{blkcnt64_t as blkcnt_t, rlim64_t as rlim_t}; +// TODO: AIX has `stat64x`, `fstat64x`, `lstat64x`, and `stat64xat`; add them +// to the upstream libc crate and implement rustix's `statat` etc. with them. #[cfg(target_os = "aix")] pub(super) use libc::{ - blksize64_t as blksize_t, fstat64 as fstat, fstatat, fstatfs64 as fstatfs, - fstatvfs64 as fstatvfs, ftruncate64 as ftruncate, getrlimit64 as getrlimit, ino_t, - lseek64 as lseek, mmap, off64_t as off_t, openat, posix_fadvise64 as posix_fadvise, preadv, - pwritev, rlimit64 as rlimit, setrlimit64 as setrlimit, statfs64 as statfs, - statvfs64 as statvfs, RLIM_INFINITY, + blksize64_t as blksize_t, fstat64 as fstat, fstatfs64 as fstatfs, fstatvfs64 as fstatvfs, + ftruncate64 as ftruncate, getrlimit64 as getrlimit, ino_t, lseek64 as lseek, mmap, + off64_t as off_t, openat, posix_fadvise64 as posix_fadvise, preadv, pwritev, + rlimit64 as rlimit, setrlimit64 as setrlimit, statfs64 as statfs, statvfs64 as statvfs, + RLIM_INFINITY, }; #[cfg(linux_like)] pub(super) use libc::{ diff --git a/vendor/rustix/src/backend/libc/conv.rs b/vendor/rustix/src/backend/libc/conv.rs index baf2a05ed..19bf0a7db 100644 --- a/vendor/rustix/src/backend/libc/conv.rs +++ b/vendor/rustix/src/backend/libc/conv.rs @@ -3,7 +3,7 @@ //! for converting between rustix's types and libc types. use super::c; -#[cfg(not(any(windows, target_os = "espidf")))] +#[cfg(all(feature = "alloc", not(any(windows, target_os = "espidf"))))] use super::fd::IntoRawFd; use super::fd::{AsRawFd, BorrowedFd, FromRawFd, LibcFd, OwnedFd, RawFd}; #[cfg(not(windows))] @@ -27,7 +27,10 @@ pub(super) fn borrowed_fd(fd: BorrowedFd<'_>) -> LibcFd { fd.as_raw_fd() as LibcFd } -#[cfg(not(any(windows, target_os = "espidf", target_os = "redox")))] +#[cfg(all( + feature = "alloc", + not(any(windows, target_os = "espidf", target_os = "redox")) +))] #[inline] pub(super) fn owned_fd(fd: OwnedFd) -> LibcFd { fd.into_raw_fd() as LibcFd @@ -133,7 +136,7 @@ pub(super) fn ret_discarded_fd(raw: LibcFd) -> io::Result<()> { } } -#[cfg(not(any(windows, target_os = "wasi")))] +#[cfg(all(feature = "alloc", not(any(windows, target_os = "wasi"))))] #[inline] pub(super) fn ret_discarded_char_ptr(raw: *mut c::c_char) -> io::Result<()> { if raw.is_null() { @@ -205,6 +208,7 @@ pub(crate) fn msg_iov_len(len: usize) -> c::c_int { bsd, solarish, target_env = "musl", + target_os = "aix", target_os = "emscripten", target_os = "fuchsia", target_os = "haiku", @@ -221,6 +225,7 @@ pub(crate) fn msg_control_len(len: usize) -> c::socklen_t { solarish, windows, target_env = "musl", + target_os = "aix", target_os = "emscripten", target_os = "espidf", target_os = "fuchsia", diff --git a/vendor/rustix/src/backend/libc/event/epoll.rs b/vendor/rustix/src/backend/libc/event/epoll.rs index c59a38cd4..a6087a167 100644 --- a/vendor/rustix/src/backend/libc/event/epoll.rs +++ b/vendor/rustix/src/backend/libc/event/epoll.rs @@ -92,6 +92,9 @@ bitflags! { pub struct CreateFlags: u32 { /// `EPOLL_CLOEXEC` const CLOEXEC = bitcast!(c::EPOLL_CLOEXEC); + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -145,6 +148,9 @@ bitflags! { /// `EPOLLEXCLUSIVE` #[cfg(not(target_os = "android"))] const EXCLUSIVE = bitcast!(c::EPOLLEXCLUSIVE); + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -160,11 +166,11 @@ pub fn create(flags: CreateFlags) -> io::Result<OwnedFd> { unsafe { ret_owned_fd(c::epoll_create1(bitflags_bits!(flags))) } } -/// `epoll_ctl(self, EPOLL_CTL_ADD, data, event)`—Adds an element to an -/// epoll object. +/// `epoll_ctl(self, EPOLL_CTL_ADD, data, event)`—Adds an element to an epoll +/// object. /// -/// This registers interest in any of the events set in `events` occurring -/// on the file descriptor associated with `data`. +/// This registers interest in any of the events set in `events` occurring on +/// the file descriptor associated with `data`. /// /// If [`delete`] is not called on the I/O source passed into this function /// before the I/O source is `close`d, then the `epoll` will act as if the I/O @@ -198,8 +204,8 @@ pub fn add( } } -/// `epoll_ctl(self, EPOLL_CTL_MOD, target, event)`—Modifies an element in -/// a given epoll object. +/// `epoll_ctl(self, EPOLL_CTL_MOD, target, event)`—Modifies an element in a +/// given epoll object. /// /// This sets the events of interest with `target` to `events`. #[doc(alias = "epoll_ctl")] @@ -229,8 +235,8 @@ pub fn modify( } } -/// `epoll_ctl(self, EPOLL_CTL_DEL, target, NULL)`—Removes an element in -/// a given epoll object. +/// `epoll_ctl(self, EPOLL_CTL_DEL, target, NULL)`—Removes an element in a +/// given epoll object. #[doc(alias = "epoll_ctl")] pub fn delete(epoll: impl AsFd, source: impl AsFd) -> io::Result<()> { // SAFETY: We're calling `epoll_ctl` via FFI and we know how it @@ -341,8 +347,8 @@ impl EventData { /// Return the value as a `u64`. /// - /// If the stored value was a pointer, the pointer is zero-extended to - /// a `u64`. + /// If the stored value was a pointer, the pointer is zero-extended to a + /// `u64`. #[inline] pub fn u64(self) -> u64 { unsafe { self.as_u64 } diff --git a/vendor/rustix/src/backend/libc/event/mod.rs b/vendor/rustix/src/backend/libc/event/mod.rs index 6aed4612a..44e8a090a 100644 --- a/vendor/rustix/src/backend/libc/event/mod.rs +++ b/vendor/rustix/src/backend/libc/event/mod.rs @@ -5,5 +5,5 @@ pub(crate) mod types; #[cfg_attr(windows, path = "windows_syscalls.rs")] pub(crate) mod syscalls; -#[cfg(linux_kernel)] +#[cfg(all(feature = "alloc", linux_kernel))] pub mod epoll; diff --git a/vendor/rustix/src/backend/libc/event/poll_fd.rs b/vendor/rustix/src/backend/libc/event/poll_fd.rs index a06812aaa..3f795d5aa 100644 --- a/vendor/rustix/src/backend/libc/event/poll_fd.rs +++ b/vendor/rustix/src/backend/libc/event/poll_fd.rs @@ -47,6 +47,9 @@ bitflags! { not(any(target_arch = "sparc", target_arch = "sparc64"))), )] const RDHUP = c::POLLRDHUP; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -112,7 +115,7 @@ impl<'fd> PollFd<'fd> { /// Returns the ready events. #[inline] pub fn revents(&self) -> PollFlags { - // Use `unwrap()` here because in theory we know we know all the bits + // Use `.unwrap()` here because in theory we know we know all the bits // the OS might set here, but OS's have added extensions in the past. PollFlags::from_bits(self.pollfd.revents).unwrap() } @@ -123,7 +126,7 @@ impl<'fd> AsFd for PollFd<'fd> { #[inline] fn as_fd(&self) -> BorrowedFd<'_> { // SAFETY: Our constructors and `set_fd` require `pollfd.fd` to be - // valid for the `fd lifetime. + // valid for the `'fd` lifetime. unsafe { BorrowedFd::borrow_raw(self.pollfd.fd) } } } @@ -133,7 +136,7 @@ impl<'fd> AsSocket for PollFd<'fd> { #[inline] fn as_socket(&self) -> BorrowedFd<'_> { // SAFETY: Our constructors and `set_fd` require `pollfd.fd` to be - // valid for the `fd lifetime. + // valid for the `'fd` lifetime. unsafe { BorrowedFd::borrow_raw(self.pollfd.fd as RawFd) } } } diff --git a/vendor/rustix/src/backend/libc/event/syscalls.rs b/vendor/rustix/src/backend/libc/event/syscalls.rs index eac88d4bb..f2dcdf5ad 100644 --- a/vendor/rustix/src/backend/libc/event/syscalls.rs +++ b/vendor/rustix/src/backend/libc/event/syscalls.rs @@ -5,7 +5,7 @@ use crate::backend::conv::ret_c_int; #[cfg(any(apple, netbsdlike, target_os = "dragonfly", target_os = "solaris"))] use crate::backend::conv::ret_owned_fd; use crate::event::PollFd; -#[cfg(any(linux_kernel, bsd, solarish))] +#[cfg(any(linux_kernel, bsd, solarish, target_os = "espidf"))] use crate::fd::OwnedFd; use crate::io; #[cfg(any(bsd, solarish))] @@ -15,12 +15,22 @@ use { crate::backend::conv::ret, crate::event::port::Event, crate::utils::as_mut_ptr, core::ptr::null_mut, }; -#[cfg(any(linux_kernel, target_os = "freebsd", target_os = "illumos"))] +#[cfg(any( + linux_kernel, + target_os = "freebsd", + target_os = "illumos", + target_os = "espidf" +))] use {crate::backend::conv::ret_owned_fd, crate::event::EventfdFlags}; -#[cfg(bsd)] +#[cfg(all(feature = "alloc", bsd))] use {crate::event::kqueue::Event, crate::utils::as_ptr, core::ptr::null}; -#[cfg(any(linux_kernel, target_os = "freebsd", target_os = "illumos"))] +#[cfg(any( + linux_kernel, + target_os = "freebsd", + target_os = "illumos", + target_os = "espidf" +))] pub(crate) fn eventfd(initval: u32, flags: EventfdFlags) -> io::Result<OwnedFd> { #[cfg(linux_kernel)] unsafe { @@ -45,18 +55,18 @@ pub(crate) fn eventfd(initval: u32, flags: EventfdFlags) -> io::Result<OwnedFd> ret_owned_fd(eventfd(initval, bitflags_bits!(flags))) } - #[cfg(target_os = "illumos")] + #[cfg(any(target_os = "illumos", target_os = "espidf"))] unsafe { ret_owned_fd(c::eventfd(initval, bitflags_bits!(flags))) } } -#[cfg(bsd)] +#[cfg(all(feature = "alloc", bsd))] pub(crate) fn kqueue() -> io::Result<OwnedFd> { unsafe { ret_owned_fd(c::kqueue()) } } -#[cfg(bsd)] +#[cfg(all(feature = "alloc", bsd))] pub(crate) unsafe fn kevent( kq: BorrowedFd<'_>, changelist: &[Event], @@ -137,7 +147,7 @@ pub(crate) fn port_get( Ok(Event(unsafe { event.assume_init() })) } -#[cfg(solarish)] +#[cfg(all(feature = "alloc", solarish))] pub(crate) fn port_getn( port: BorrowedFd<'_>, timeout: Option<&mut c::timespec>, diff --git a/vendor/rustix/src/backend/libc/event/types.rs b/vendor/rustix/src/backend/libc/event/types.rs index 632b1be63..af052a434 100644 --- a/vendor/rustix/src/backend/libc/event/types.rs +++ b/vendor/rustix/src/backend/libc/event/types.rs @@ -1,7 +1,19 @@ #[cfg(any(linux_kernel, target_os = "freebsd", target_os = "illumos"))] -use {crate::backend::c, bitflags::bitflags}; +use crate::backend::c; +#[cfg(any( + linux_kernel, + target_os = "freebsd", + target_os = "illumos", + target_os = "espidf" +))] +use bitflags::bitflags; -#[cfg(any(linux_kernel, target_os = "freebsd", target_os = "illumos"))] +#[cfg(any( + linux_kernel, + target_os = "freebsd", + target_os = "illumos", + target_os = "espidf" +))] bitflags! { /// `EFD_*` flags for use with [`eventfd`]. /// @@ -10,10 +22,16 @@ bitflags! { #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct EventfdFlags: u32 { /// `EFD_CLOEXEC` + #[cfg(not(target_os = "espidf"))] const CLOEXEC = bitcast!(c::EFD_CLOEXEC); /// `EFD_NONBLOCK` + #[cfg(not(target_os = "espidf"))] const NONBLOCK = bitcast!(c::EFD_NONBLOCK); /// `EFD_SEMAPHORE` + #[cfg(not(target_os = "espidf"))] const SEMAPHORE = bitcast!(c::EFD_SEMAPHORE); + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } diff --git a/vendor/rustix/src/backend/libc/fs/inotify.rs b/vendor/rustix/src/backend/libc/fs/inotify.rs index 05d4d904f..fea2fad06 100644 --- a/vendor/rustix/src/backend/libc/fs/inotify.rs +++ b/vendor/rustix/src/backend/libc/fs/inotify.rs @@ -17,6 +17,9 @@ bitflags! { const CLOEXEC = bitcast!(c::IN_CLOEXEC); /// `IN_NONBLOCK` const NONBLOCK = bitcast!(c::IN_NONBLOCK); + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -71,6 +74,9 @@ bitflags! { const ONESHOT = c::IN_ONESHOT; /// `IN_ONLYDIR` const ONLYDIR = c::IN_ONLYDIR; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -98,22 +104,23 @@ pub fn inotify_add_watch<P: crate::path::Arg>( path: P, flags: WatchFlags, ) -> io::Result<i32> { - let path = path.as_cow_c_str().unwrap(); - // SAFETY: The fd and path we are passing is guaranteed valid by the type - // system. - unsafe { - ret_c_int(c::inotify_add_watch( - borrowed_fd(inot), - c_str(&path), - flags.bits(), - )) - } + path.into_with_c_str(|path| { + // SAFETY: The fd and path we are passing is guaranteed valid by the type + // system. + unsafe { + ret_c_int(c::inotify_add_watch( + borrowed_fd(inot), + c_str(path), + flags.bits(), + )) + } + }) } /// `inotify_rm_watch(self, wd)`—Removes a watch from this inotify /// -/// The watch descriptor provided should have previously been returned -/// by [`inotify_add_watch`] and not previously have been removed. +/// The watch descriptor provided should have previously been returned by +/// [`inotify_add_watch`] and not previously have been removed. #[doc(alias = "inotify_rm_watch")] pub fn inotify_remove_watch(inot: BorrowedFd<'_>, wd: i32) -> io::Result<()> { // Android's `inotify_rm_watch` takes `u32` despite that diff --git a/vendor/rustix/src/backend/libc/fs/makedev.rs b/vendor/rustix/src/backend/libc/fs/makedev.rs index 640d5005b..aa1210283 100644 --- a/vendor/rustix/src/backend/libc/fs/makedev.rs +++ b/vendor/rustix/src/backend/libc/fs/makedev.rs @@ -30,8 +30,8 @@ pub(crate) fn makedev(maj: u32, min: u32) -> Dev { #[cfg(all(target_os = "android", target_pointer_width = "32"))] #[inline] pub(crate) fn makedev(maj: u32, min: u32) -> Dev { - // 32-bit Android's `dev_t` is 32-bit, but its `st_dev` is 64-bit, - // so we do it ourselves. + // 32-bit Android's `dev_t` is 32-bit, but its `st_dev` is 64-bit, so we do + // it ourselves. ((u64::from(maj) & 0xffff_f000_u64) << 32) | ((u64::from(maj) & 0x0000_0fff_u64) << 8) | ((u64::from(min) & 0xffff_ff00_u64) << 12) @@ -86,8 +86,8 @@ pub(crate) fn major(dev: Dev) -> u32 { #[cfg(all(target_os = "android", target_pointer_width = "32"))] #[inline] pub(crate) fn major(dev: Dev) -> u32 { - // 32-bit Android's `dev_t` is 32-bit, but its `st_dev` is 64-bit, - // so we do it ourselves. + // 32-bit Android's `dev_t` is 32-bit, but its `st_dev` is 64-bit, so we do + // it ourselves. (((dev >> 31 >> 1) & 0xffff_f000) | ((dev >> 8) & 0x0000_0fff)) as u32 } @@ -125,8 +125,8 @@ pub(crate) fn minor(dev: Dev) -> u32 { #[cfg(all(target_os = "android", target_pointer_width = "32"))] #[inline] pub(crate) fn minor(dev: Dev) -> u32 { - // 32-bit Android's `dev_t` is 32-bit, but its `st_dev` is 64-bit, - // so we do it ourselves. + // 32-bit Android's `dev_t` is 32-bit, but its `st_dev` is 64-bit, so we do + // it ourselves. (((dev >> 12) & 0xffff_ff00) | (dev & 0x0000_00ff)) as u32 } diff --git a/vendor/rustix/src/backend/libc/fs/mod.rs b/vendor/rustix/src/backend/libc/fs/mod.rs index 17b4da70f..9a0b1d3e5 100644 --- a/vendor/rustix/src/backend/libc/fs/mod.rs +++ b/vendor/rustix/src/backend/libc/fs/mod.rs @@ -1,4 +1,4 @@ -#[cfg(not(any(target_os = "espidf", target_os = "redox")))] +#[cfg(all(feature = "alloc", not(any(target_os = "espidf", target_os = "redox"))))] pub(crate) mod dir; #[cfg(linux_kernel)] pub mod inotify; @@ -12,3 +12,11 @@ pub(crate) mod makedev; #[cfg(not(windows))] pub(crate) mod syscalls; pub(crate) mod types; + +// TODO: Fix linux-raw-sys to define ioctl codes for sparc. +#[cfg(all(linux_kernel, any(target_arch = "sparc", target_arch = "sparc64")))] +pub(crate) const EXT4_IOC_RESIZE_FS: crate::ioctl::RawOpcode = 0x8008_6610; + +#[cfg(all(linux_kernel, not(any(target_arch = "sparc", target_arch = "sparc64"))))] +pub(crate) const EXT4_IOC_RESIZE_FS: crate::ioctl::RawOpcode = + linux_raw_sys::ioctl::EXT4_IOC_RESIZE_FS as crate::ioctl::RawOpcode; diff --git a/vendor/rustix/src/backend/libc/fs/syscalls.rs b/vendor/rustix/src/backend/libc/fs/syscalls.rs index 698bf34ad..5df25daa9 100644 --- a/vendor/rustix/src/backend/libc/fs/syscalls.rs +++ b/vendor/rustix/src/backend/libc/fs/syscalls.rs @@ -1,9 +1,9 @@ //! libc syscalls supporting `rustix::fs`. use crate::backend::c; -use crate::backend::conv::{ - borrowed_fd, c_str, ret, ret_c_int, ret_off_t, ret_owned_fd, ret_usize, -}; +#[cfg(any(apple, linux_kernel, feature = "alloc"))] +use crate::backend::conv::ret_usize; +use crate::backend::conv::{borrowed_fd, c_str, ret, ret_c_int, ret_off_t, ret_owned_fd}; use crate::fd::{BorrowedFd, OwnedFd}; use crate::ffi::CStr; #[cfg(apple)] @@ -90,6 +90,7 @@ fn open_via_syscall(path: &CStr, oflags: OFlags, mode: Mode) -> io::Result<Owned target_arch = "aarch64", target_arch = "riscv32", target_arch = "riscv64", + target_arch = "csky", target_arch = "loongarch64" ))] { @@ -101,6 +102,7 @@ fn open_via_syscall(path: &CStr, oflags: OFlags, mode: Mode) -> io::Result<Owned target_arch = "aarch64", target_arch = "riscv32", target_arch = "riscv64", + target_arch = "csky", target_arch = "loongarch64" )))] unsafe { @@ -128,8 +130,8 @@ pub(crate) fn open(path: &CStr, oflags: OFlags, mode: Mode) -> io::Result<OwnedF return open_via_syscall(path, oflags, mode); } - // On these platforms, `mode_t` is `u16` and can't be passed directly to - // a variadic function. + // On these platforms, `mode_t` is `u16` and can't be passed directly to a + // variadic function. #[cfg(any( apple, freebsdlike, @@ -191,8 +193,8 @@ pub(crate) fn openat( return openat_via_syscall(dirfd, path, oflags, mode); } - // On these platforms, `mode_t` is `u16` and can't be passed directly to - // a variadic function. + // On these platforms, `mode_t` is `u16` and can't be passed directly to a + // variadic function. #[cfg(any( apple, freebsdlike, @@ -246,6 +248,7 @@ pub(crate) fn statvfs(filename: &CStr) -> io::Result<StatVfs> { } } +#[cfg(feature = "alloc")] #[inline] pub(crate) fn readlink(path: &CStr, buf: &mut [u8]) -> io::Result<usize> { unsafe { @@ -255,7 +258,7 @@ pub(crate) fn readlink(path: &CStr, buf: &mut [u8]) -> io::Result<usize> { } } -#[cfg(not(target_os = "redox"))] +#[cfg(all(feature = "alloc", not(target_os = "redox")))] #[inline] pub(crate) fn readlinkat( dirfd: BorrowedFd<'_>, @@ -615,7 +618,7 @@ pub(crate) fn lstat(path: &CStr) -> io::Result<Stat> { } } -#[cfg(not(any(target_os = "espidf", target_os = "redox")))] +#[cfg(not(any(target_os = "aix", target_os = "espidf", target_os = "redox")))] pub(crate) fn statat(dirfd: BorrowedFd<'_>, path: &CStr, flags: AtFlags) -> io::Result<Stat> { // See the comments in `fstat` about using `crate::fs::statx` here. #[cfg(all( @@ -785,9 +788,6 @@ pub(crate) fn utimensat( unsafe { use crate::utils::as_ptr; - // Assert that `Timestamps` has the expected layout. - let _ = core::mem::transmute::<Timestamps, [c::timespec; 2]>(times.clone()); - ret(c::utimensat( borrowed_fd(dirfd), c_str(path), @@ -823,9 +823,6 @@ pub(crate) fn utimensat( // If we have `utimensat`, use it. if let Some(have_utimensat) = utimensat.get() { - // Assert that `Timestamps` has the expected layout. - let _ = core::mem::transmute::<Timestamps, [c::timespec; 2]>(times.clone()); - return ret(have_utimensat( borrowed_fd(dirfd), c_str(path), @@ -1094,9 +1091,6 @@ pub(crate) fn copy_file_range( ) via SYS_copy_file_range -> c::ssize_t } - #[cfg(test)] - assert_eq_size!(c::loff_t, u64); - let mut off_in_val: c::loff_t = 0; let mut off_out_val: c::loff_t = 0; // Silently cast; we'll get `EINVAL` if the value is negative. @@ -1234,9 +1228,9 @@ pub(crate) fn seek(fd: BorrowedFd<'_>, pos: SeekFrom) -> io::Result<u64> { } SeekFrom::End(offset) => (c::SEEK_END, offset), SeekFrom::Current(offset) => (c::SEEK_CUR, offset), - #[cfg(any(freebsdlike, target_os = "linux", target_os = "solaris"))] + #[cfg(any(apple, freebsdlike, linux_kernel, solarish))] SeekFrom::Data(offset) => (c::SEEK_DATA, offset), - #[cfg(any(freebsdlike, target_os = "linux", target_os = "solaris"))] + #[cfg(any(apple, freebsdlike, linux_kernel, solarish))] SeekFrom::Hole(offset) => (c::SEEK_HOLE, offset), }; @@ -1273,6 +1267,14 @@ pub(crate) fn fchmod(fd: BorrowedFd<'_>, mode: Mode) -> io::Result<()> { unsafe { ret(fchmod(borrowed_fd(fd), mode.bits() as c::mode_t)) } } +#[cfg(not(target_os = "wasi"))] +pub(crate) fn chown(path: &CStr, owner: Option<Uid>, group: Option<Gid>) -> io::Result<()> { + unsafe { + let (ow, gr) = crate::ugid::translate_fchown_args(owner, group); + ret(c::chown(c_str(path), ow, gr)) + } +} + #[cfg(linux_kernel)] pub(crate) fn fchown(fd: BorrowedFd<'_>, owner: Option<Uid>, group: Option<Gid>) -> io::Result<()> { // Use `c::syscall` rather than `c::fchown` because some libc @@ -1420,7 +1422,10 @@ fn libc_statvfs_to_statvfs(from: c::statvfs) -> StatVfs { f_files: from.f_files as u64, f_ffree: from.f_ffree as u64, f_favail: from.f_ffree as u64, + #[cfg(not(target_os = "aix"))] f_fsid: from.f_fsid as u64, + #[cfg(target_os = "aix")] + f_fsid: ((from.f_fsid.val[0] as u64) << 32) | from.f_fsid.val[1], f_flag: StatVfsMountFlags::from_bits_retain(from.f_flag as u64), f_namemax: from.f_namemax as u64, } @@ -1453,9 +1458,6 @@ pub(crate) fn futimens(fd: BorrowedFd<'_>, times: &Timestamps) -> io::Result<()> unsafe { use crate::utils::as_ptr; - // Assert that `Timestamps` has the expected layout. - let _ = core::mem::transmute::<Timestamps, [c::timespec; 2]>(times.clone()); - ret(c::futimens(borrowed_fd(fd), as_ptr(times).cast())) } @@ -1480,9 +1482,6 @@ pub(crate) fn futimens(fd: BorrowedFd<'_>, times: &Timestamps) -> io::Result<()> // If we have `futimens`, use it. if let Some(have_futimens) = futimens.get() { - // Assert that `Timestamps` has the expected layout. - let _ = core::mem::transmute::<Timestamps, [c::timespec; 2]>(times.clone()); - return ret(have_futimens(borrowed_fd(fd), as_ptr(times).cast())); } @@ -2049,12 +2048,12 @@ pub(crate) fn fcntl_fullfsync(fd: BorrowedFd<'_>) -> io::Result<()> { } #[cfg(apple)] -pub(crate) fn fcntl_nocache(fd: BorrowedFd, value: bool) -> io::Result<()> { +pub(crate) fn fcntl_nocache(fd: BorrowedFd<'_>, value: bool) -> io::Result<()> { unsafe { ret(c::fcntl(borrowed_fd(fd), c::F_NOCACHE, value as c::c_int)) } } #[cfg(apple)] -pub(crate) fn fcntl_global_nocache(fd: BorrowedFd, value: bool) -> io::Result<()> { +pub(crate) fn fcntl_global_nocache(fd: BorrowedFd<'_>, value: bool) -> io::Result<()> { unsafe { ret(c::fcntl( borrowed_fd(fd), @@ -2420,51 +2419,15 @@ pub(crate) fn fremovexattr(fd: BorrowedFd<'_>, name: &CStr) -> io::Result<()> { } } -#[cfg(linux_kernel)] -#[inline] -pub(crate) fn ioctl_blksszget(fd: BorrowedFd) -> io::Result<u32> { - let mut result = MaybeUninit::<c::c_uint>::uninit(); - unsafe { - ret(c::ioctl(borrowed_fd(fd), c::BLKSSZGET, result.as_mut_ptr()))?; - Ok(result.assume_init() as u32) - } -} - -#[cfg(linux_kernel)] -#[inline] -pub(crate) fn ioctl_blkpbszget(fd: BorrowedFd) -> io::Result<u32> { - let mut result = MaybeUninit::<c::c_uint>::uninit(); - unsafe { - ret(c::ioctl( - borrowed_fd(fd), - c::BLKPBSZGET, - result.as_mut_ptr(), - ))?; - Ok(result.assume_init() as u32) - } -} - -// Sparc lacks `FICLONE`. -#[cfg(all(linux_kernel, not(any(target_arch = "sparc", target_arch = "sparc64"))))] -pub(crate) fn ioctl_ficlone(fd: BorrowedFd<'_>, src_fd: BorrowedFd<'_>) -> io::Result<()> { - unsafe { - ret(c::ioctl( - borrowed_fd(fd), - c::FICLONE as _, - borrowed_fd(src_fd), - )) - } -} - -#[cfg(linux_kernel)] -#[inline] -pub(crate) fn ext4_ioc_resize_fs(fd: BorrowedFd<'_>, blocks: u64) -> io::Result<()> { - // TODO: Fix linux-raw-sys to define ioctl codes for sparc. - #[cfg(any(target_arch = "sparc", target_arch = "sparc64"))] - const EXT4_IOC_RESIZE_FS: u32 = 0x8008_6610; - - #[cfg(not(any(target_arch = "sparc", target_arch = "sparc64")))] - use linux_raw_sys::ioctl::EXT4_IOC_RESIZE_FS; +#[test] +fn test_sizes() { + #[cfg(linux_kernel)] + assert_eq_size!(c::loff_t, u64); - unsafe { ret(c::ioctl(borrowed_fd(fd), EXT4_IOC_RESIZE_FS as _, &blocks)) } + // Assert that `Timestamps` has the expected layout. If we're not fixing + // y2038, libc's type should match ours. If we are, it's smaller. + #[cfg(not(fix_y2038))] + assert_eq_size!([c::timespec; 2], Timestamps); + #[cfg(fix_y2038)] + assert!(core::mem::size_of::<[c::timespec; 2]>() < core::mem::size_of::<Timestamps>()); } diff --git a/vendor/rustix/src/backend/libc/fs/types.rs b/vendor/rustix/src/backend/libc/fs/types.rs index 955bdaa29..cf86861dc 100644 --- a/vendor/rustix/src/backend/libc/fs/types.rs +++ b/vendor/rustix/src/backend/libc/fs/types.rs @@ -20,6 +20,9 @@ bitflags! { /// `F_OK` const EXISTS = c::F_OK; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -73,6 +76,9 @@ bitflags! { /// `AT_STATX_DONT_SYNC` #[cfg(all(target_os = "linux", target_env = "gnu"))] const STATX_DONT_SYNC = bitcast!(c::AT_STATX_DONT_SYNC); + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -86,64 +92,67 @@ bitflags! { #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct Mode: RawMode { /// `S_IRWXU` - #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags. + #[cfg(not(target_os = "espidf"))] const RWXU = c::S_IRWXU as RawMode; /// `S_IRUSR` - #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags. + #[cfg(not(target_os = "espidf"))] const RUSR = c::S_IRUSR as RawMode; /// `S_IWUSR` - #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags. + #[cfg(not(target_os = "espidf"))] const WUSR = c::S_IWUSR as RawMode; /// `S_IXUSR` - #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags. + #[cfg(not(target_os = "espidf"))] const XUSR = c::S_IXUSR as RawMode; /// `S_IRWXG` - #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags. + #[cfg(not(target_os = "espidf"))] const RWXG = c::S_IRWXG as RawMode; /// `S_IRGRP` - #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags. + #[cfg(not(target_os = "espidf"))] const RGRP = c::S_IRGRP as RawMode; /// `S_IWGRP` - #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags. + #[cfg(not(target_os = "espidf"))] const WGRP = c::S_IWGRP as RawMode; /// `S_IXGRP` - #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags. + #[cfg(not(target_os = "espidf"))] const XGRP = c::S_IXGRP as RawMode; /// `S_IRWXO` - #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags. + #[cfg(not(target_os = "espidf"))] const RWXO = c::S_IRWXO as RawMode; /// `S_IROTH` - #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags. + #[cfg(not(target_os = "espidf"))] const ROTH = c::S_IROTH as RawMode; /// `S_IWOTH` - #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags. + #[cfg(not(target_os = "espidf"))] const WOTH = c::S_IWOTH as RawMode; /// `S_IXOTH` - #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags. + #[cfg(not(target_os = "espidf"))] const XOTH = c::S_IXOTH as RawMode; /// `S_ISUID` - #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags. + #[cfg(not(target_os = "espidf"))] const SUID = c::S_ISUID as RawMode; /// `S_ISGID` - #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags. + #[cfg(not(target_os = "espidf"))] const SGID = c::S_ISGID as RawMode; /// `S_ISVTX` - #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags. + #[cfg(not(target_os = "espidf"))] const SVTX = c::S_ISVTX as RawMode; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -249,6 +258,8 @@ bitflags! { const WRONLY = bitcast!(c::O_WRONLY); /// `O_RDWR` + /// + /// This is not equal to `RDONLY | WRONLY`. It's a distinct flag. const RDWR = bitcast!(c::O_RDWR); /// `O_NOCTTY` @@ -316,6 +327,9 @@ bitflags! { /// `O_EMPTY_PATH` #[cfg(target_os = "freebsd")] const EMPTY_PATH = bitcast!(c::O_EMPTY_PATH); + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -332,6 +346,9 @@ bitflags! { /// `CLONE_NOOWNERCOPY` const NOOWNERCOPY = 2; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -374,6 +391,9 @@ bitflags! { /// `COPYFILE_ALL` const ALL = copyfile::ALL; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -402,6 +422,9 @@ bitflags! { /// `RESOLVE_CACHED` (since Linux 5.12) const CACHED = 0x20; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -421,6 +444,9 @@ bitflags! { /// `RENAME_WHITEOUT` const WHITEOUT = bitcast!(c::RENAME_WHITEOUT); + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -497,6 +523,7 @@ impl FileType { /// Construct a `FileType` from the `d_type` field of a `c::dirent`. #[cfg(not(any( solarish, + target_os = "aix", target_os = "espidf", target_os = "haiku", target_os = "nto", @@ -595,6 +622,9 @@ bitflags! { const HUGE_2GB = c::MFD_HUGE_2GB; /// `MFD_HUGE_16GB` const HUGE_16GB = c::MFD_HUGE_16GB; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -608,17 +638,20 @@ bitflags! { #[repr(transparent)] #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct SealFlags: u32 { - /// `F_SEAL_SEAL`. - const SEAL = bitcast!(c::F_SEAL_SEAL); - /// `F_SEAL_SHRINK`. - const SHRINK = bitcast!(c::F_SEAL_SHRINK); - /// `F_SEAL_GROW`. - const GROW = bitcast!(c::F_SEAL_GROW); - /// `F_SEAL_WRITE`. - const WRITE = bitcast!(c::F_SEAL_WRITE); - /// `F_SEAL_FUTURE_WRITE` (since Linux 5.1) - #[cfg(linux_kernel)] - const FUTURE_WRITE = bitcast!(c::F_SEAL_FUTURE_WRITE); + /// `F_SEAL_SEAL`. + const SEAL = bitcast!(c::F_SEAL_SEAL); + /// `F_SEAL_SHRINK`. + const SHRINK = bitcast!(c::F_SEAL_SHRINK); + /// `F_SEAL_GROW`. + const GROW = bitcast!(c::F_SEAL_GROW); + /// `F_SEAL_WRITE`. + const WRITE = bitcast!(c::F_SEAL_WRITE); + /// `F_SEAL_FUTURE_WRITE` (since Linux 5.1) + #[cfg(linux_kernel)] + const FUTURE_WRITE = bitcast!(c::F_SEAL_FUTURE_WRITE); + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -677,6 +710,9 @@ bitflags! { /// `STATX_ALL` const ALL = c::STATX_ALL; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -735,6 +771,9 @@ bitflags! { /// `STATX_ALL` const ALL = 0xfff; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -817,6 +856,9 @@ bitflags! { target_os = "wasi", )))] const UNSHARE_RANGE = bitcast!(c::FALLOC_FL_UNSHARE_RANGE); + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -866,6 +908,9 @@ bitflags! { /// `ST_SYNCHRONOUS` #[cfg(any(linux_kernel, target_os = "emscripten", target_os = "fuchsia"))] const SYNCHRONOUS = c::ST_SYNCHRONOUS as u64; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } diff --git a/vendor/rustix/src/backend/libc/io/errno.rs b/vendor/rustix/src/backend/libc/io/errno.rs index aabd45f8c..1448fe7bd 100644 --- a/vendor/rustix/src/backend/libc/io/errno.rs +++ b/vendor/rustix/src/backend/libc/io/errno.rs @@ -6,10 +6,32 @@ use crate::backend::c; use libc_errno::errno; -/// The error type for `rustix` APIs. +/// `errno`—An error code. /// -/// This is similar to `std::io::Error`, but only holds an OS error code, -/// and no extra error value. +/// The error type for `rustix` APIs. This is similar to [`std::io::Error`], +/// but only holds an OS error code, and no extra error value. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// - [Winsock2] +/// - [FreeBSD] +/// - [NetBSD] +/// - [OpenBSD] +/// - [DragonFly BSD] +/// - [illumos] +/// - [glibc] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/errno.html +/// [Linux]: https://man7.org/linux/man-pages/man3/errno.3.html +/// [Winsock2]: https://learn.microsoft.com/en-us/windows/win32/winsock/windows-sockets-error-codes-2 +/// [FreeBSD]: https://man.freebsd.org/cgi/man.cgi?errno +/// [NetBSD]: https://man.netbsd.org/errno.2 +/// [OpenBSD]: https://man.openbsd.org/errno.2 +/// [DragonFly BSD]: https://man.dragonflybsd.org/?command=errno§ion=2 +/// [illumos]: https://illumos.org/man/3C/errno +/// [glibc]: https://www.gnu.org/software/libc/manual/html_node/Error-Codes.html +/// [`std::io::Error`]: Result #[repr(transparent)] #[doc(alias = "errno")] #[derive(Eq, PartialEq, Hash, Copy, Clone)] diff --git a/vendor/rustix/src/backend/libc/io/syscalls.rs b/vendor/rustix/src/backend/libc/io/syscalls.rs index 362af11ee..19ecfa9b6 100644 --- a/vendor/rustix/src/backend/libc/io/syscalls.rs +++ b/vendor/rustix/src/backend/libc/io/syscalls.rs @@ -15,6 +15,7 @@ use crate::io::DupFlags; #[cfg(linux_kernel)] use crate::io::ReadWriteFlags; use crate::io::{self, FdFlags}; +use crate::ioctl::{IoctlOutput, RawOpcode}; use core::cmp::min; #[cfg(all(feature = "fs", feature = "net"))] use libc_errno::errno; @@ -78,7 +79,7 @@ pub(crate) fn pwrite(fd: BorrowedFd<'_>, buf: &[u8], offset: u64) -> io::Result< } #[cfg(not(target_os = "espidf"))] -pub(crate) fn readv(fd: BorrowedFd<'_>, bufs: &mut [IoSliceMut]) -> io::Result<usize> { +pub(crate) fn readv(fd: BorrowedFd<'_>, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> { unsafe { ret_usize(c::readv( borrowed_fd(fd), @@ -89,7 +90,7 @@ pub(crate) fn readv(fd: BorrowedFd<'_>, bufs: &mut [IoSliceMut]) -> io::Result<u } #[cfg(not(target_os = "espidf"))] -pub(crate) fn writev(fd: BorrowedFd<'_>, bufs: &[IoSlice]) -> io::Result<usize> { +pub(crate) fn writev(fd: BorrowedFd<'_>, bufs: &[IoSlice<'_>]) -> io::Result<usize> { unsafe { ret_usize(c::writev( borrowed_fd(fd), @@ -108,7 +109,7 @@ pub(crate) fn writev(fd: BorrowedFd<'_>, bufs: &[IoSlice]) -> io::Result<usize> )))] pub(crate) fn preadv( fd: BorrowedFd<'_>, - bufs: &mut [IoSliceMut], + bufs: &mut [IoSliceMut<'_>], offset: u64, ) -> io::Result<usize> { // Silently cast; we'll get `EINVAL` if the value is negative. @@ -130,7 +131,7 @@ pub(crate) fn preadv( target_os = "redox", target_os = "solaris" )))] -pub(crate) fn pwritev(fd: BorrowedFd<'_>, bufs: &[IoSlice], offset: u64) -> io::Result<usize> { +pub(crate) fn pwritev(fd: BorrowedFd<'_>, bufs: &[IoSlice<'_>], offset: u64) -> io::Result<usize> { // Silently cast; we'll get `EINVAL` if the value is negative. let offset = offset as i64; unsafe { @@ -146,7 +147,7 @@ pub(crate) fn pwritev(fd: BorrowedFd<'_>, bufs: &[IoSlice], offset: u64) -> io:: #[cfg(linux_kernel)] pub(crate) fn preadv2( fd: BorrowedFd<'_>, - bufs: &mut [IoSliceMut], + bufs: &mut [IoSliceMut<'_>], offset: u64, flags: ReadWriteFlags, ) -> io::Result<usize> { @@ -166,7 +167,7 @@ pub(crate) fn preadv2( #[cfg(linux_kernel)] pub(crate) fn pwritev2( fd: BorrowedFd<'_>, - bufs: &[IoSlice], + bufs: &[IoSlice<'_>], offset: u64, flags: ReadWriteFlags, ) -> io::Result<usize> { @@ -203,25 +204,22 @@ pub(crate) unsafe fn close(raw_fd: RawFd) { let _ = c::close(raw_fd as c::c_int); } -#[cfg(not(target_os = "espidf"))] -pub(crate) fn ioctl_fionread(fd: BorrowedFd<'_>) -> io::Result<u64> { - use core::mem::MaybeUninit; - - let mut nread = MaybeUninit::<c::c_int>::uninit(); - unsafe { - ret(c::ioctl(borrowed_fd(fd), c::FIONREAD, nread.as_mut_ptr()))?; - // `FIONREAD` returns the number of bytes silently casted to a `c_int`, - // even when this is lossy. The best we can do is convert it back to a - // `u64` without sign-extending it back first. - Ok(u64::from(nread.assume_init() as c::c_uint)) - } +#[inline] +pub(crate) unsafe fn ioctl( + fd: BorrowedFd<'_>, + request: RawOpcode, + arg: *mut c::c_void, +) -> io::Result<IoctlOutput> { + ret_c_int(c::ioctl(borrowed_fd(fd), request, arg)) } -pub(crate) fn ioctl_fionbio(fd: BorrowedFd<'_>, value: bool) -> io::Result<()> { - unsafe { - let data = value as c::c_int; - ret(c::ioctl(borrowed_fd(fd), c::FIONBIO, &data)) - } +#[inline] +pub(crate) unsafe fn ioctl_readonly( + fd: BorrowedFd<'_>, + request: RawOpcode, + arg: *mut c::c_void, +) -> io::Result<IoctlOutput> { + ioctl(fd, request, arg) } #[cfg(not(any(target_os = "redox", target_os = "wasi")))] @@ -302,11 +300,13 @@ pub(crate) fn dup(fd: BorrowedFd<'_>) -> io::Result<OwnedFd> { unsafe { ret_owned_fd(c::dup(borrowed_fd(fd))) } } +#[allow(clippy::needless_pass_by_ref_mut)] #[cfg(not(target_os = "wasi"))] pub(crate) fn dup2(fd: BorrowedFd<'_>, new: &mut OwnedFd) -> io::Result<()> { unsafe { ret_discarded_fd(c::dup2(borrowed_fd(fd), borrowed_fd(new.as_fd()))) } } +#[allow(clippy::needless_pass_by_ref_mut)] #[cfg(not(any( apple, target_os = "aix", @@ -342,14 +342,3 @@ pub(crate) fn dup3(fd: BorrowedFd<'_>, new: &mut OwnedFd, _flags: DupFlags) -> i // have an `&mut OwnedFd` which means `fd` doesn't alias it. dup2(fd, new) } - -#[cfg(apple)] -pub(crate) fn ioctl_fioclex(fd: BorrowedFd<'_>) -> io::Result<()> { - unsafe { - ret(c::ioctl( - borrowed_fd(fd), - c::FIOCLEX, - core::ptr::null_mut::<u8>(), - )) - } -} diff --git a/vendor/rustix/src/backend/libc/io/types.rs b/vendor/rustix/src/backend/libc/io/types.rs index 8743336f2..eaf3eae71 100644 --- a/vendor/rustix/src/backend/libc/io/types.rs +++ b/vendor/rustix/src/backend/libc/io/types.rs @@ -11,6 +11,9 @@ bitflags! { pub struct FdFlags: u32 { /// `FD_CLOEXEC` const CLOEXEC = bitcast!(c::FD_CLOEXEC); + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -33,6 +36,9 @@ bitflags! { const NOWAIT = linux_raw_sys::general::RWF_NOWAIT; /// `RWF_APPEND` (since Linux 4.16) const APPEND = linux_raw_sys::general::RWF_APPEND; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -52,5 +58,8 @@ bitflags! { target_os = "redox", )))] // Android 5.0 has dup3, but libc doesn't have bindings const CLOEXEC = bitcast!(c::O_CLOEXEC); + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } diff --git a/vendor/rustix/src/backend/libc/io/windows_syscalls.rs b/vendor/rustix/src/backend/libc/io/windows_syscalls.rs index c87a2a247..049221d2f 100644 --- a/vendor/rustix/src/backend/libc/io/windows_syscalls.rs +++ b/vendor/rustix/src/backend/libc/io/windows_syscalls.rs @@ -1,27 +1,30 @@ //! Windows system calls in the `io` module. use crate::backend::c; -use crate::backend::conv::{borrowed_fd, ret}; +use crate::backend::conv::{borrowed_fd, ret_c_int}; use crate::backend::fd::LibcFd; use crate::fd::{BorrowedFd, RawFd}; use crate::io; -use core::mem::MaybeUninit; +use crate::ioctl::{IoctlOutput, RawOpcode}; pub(crate) unsafe fn close(raw_fd: RawFd) { let _ = c::close(raw_fd as LibcFd); } -pub(crate) fn ioctl_fionread(fd: BorrowedFd<'_>) -> io::Result<u64> { - let mut nread = MaybeUninit::<c::c_ulong>::uninit(); - unsafe { - ret(c::ioctl(borrowed_fd(fd), c::FIONREAD, nread.as_mut_ptr()))?; - Ok(u64::from(nread.assume_init())) - } +#[inline] +pub(crate) unsafe fn ioctl( + fd: BorrowedFd<'_>, + request: RawOpcode, + arg: *mut c::c_void, +) -> io::Result<IoctlOutput> { + ret_c_int(c::ioctl(borrowed_fd(fd), request, arg.cast())) } -pub(crate) fn ioctl_fionbio(fd: BorrowedFd<'_>, value: bool) -> io::Result<()> { - unsafe { - let mut data = value as c::c_uint; - ret(c::ioctl(borrowed_fd(fd), c::FIONBIO, &mut data)) - } +#[inline] +pub(crate) unsafe fn ioctl_readonly( + fd: BorrowedFd<'_>, + request: RawOpcode, + arg: *mut c::c_void, +) -> io::Result<IoctlOutput> { + ioctl(fd, request, arg) } diff --git a/vendor/rustix/src/backend/libc/mm/types.rs b/vendor/rustix/src/backend/libc/mm/types.rs index 6a41cbe56..f0b4ad593 100644 --- a/vendor/rustix/src/backend/libc/mm/types.rs +++ b/vendor/rustix/src/backend/libc/mm/types.rs @@ -16,6 +16,9 @@ bitflags! { const WRITE = bitcast!(c::PROT_WRITE); /// `PROT_EXEC` const EXEC = bitcast!(c::PROT_EXEC); + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -55,6 +58,9 @@ bitflags! { /// `PROT_ADI` #[cfg(all(linux_kernel, any(target_arch = "sparc", target_arch = "sparc64")))] const ADI = linux_raw_sys::general::PROT_ADI; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -74,6 +80,7 @@ bitflags! { #[cfg(not(any( bsd, solarish, + target_os = "aix", target_os = "android", target_os = "emscripten", target_os = "fuchsia", @@ -88,6 +95,7 @@ bitflags! { #[cfg(not(any( bsd, solarish, + target_os = "aix", target_os = "haiku", target_os = "nto", target_os = "redox", @@ -99,6 +107,7 @@ bitflags! { #[cfg(not(any( bsd, solarish, + target_os = "aix", target_os = "android", target_os = "emscripten", target_os = "fuchsia", @@ -111,6 +120,7 @@ bitflags! { #[cfg(not(any( bsd, solarish, + target_os = "aix", target_os = "haiku", target_os = "nto", target_os = "redox", @@ -120,6 +130,7 @@ bitflags! { #[cfg(not(any( bsd, solarish, + target_os = "aix", target_os = "haiku", target_os = "nto", target_os = "redox", @@ -129,6 +140,7 @@ bitflags! { #[cfg(not(any( bsd, solarish, + target_os = "aix", target_os = "android", target_os = "emscripten", target_os = "fuchsia", @@ -141,6 +153,7 @@ bitflags! { #[cfg(not(any( bsd, solarish, + target_os = "aix", target_os = "android", target_os = "emscripten", target_os = "fuchsia", @@ -153,6 +166,7 @@ bitflags! { #[cfg(not(any( bsd, solarish, + target_os = "aix", target_os = "haiku", target_os = "nto", target_os = "redox", @@ -162,7 +176,12 @@ bitflags! { #[cfg(freebsdlike)] const NOCORE = bitcast!(c::MAP_NOCORE); /// `MAP_NORESERVE` - #[cfg(not(any(freebsdlike, target_os = "nto", target_os = "redox")))] + #[cfg(not(any( + freebsdlike, + target_os = "aix", + target_os = "nto", + target_os = "redox", + )))] const NORESERVE = bitcast!(c::MAP_NORESERVE); /// `MAP_NOSYNC` #[cfg(freebsdlike)] @@ -171,6 +190,7 @@ bitflags! { #[cfg(not(any( bsd, solarish, + target_os = "aix", target_os = "haiku", target_os = "nto", target_os = "redox", @@ -180,6 +200,7 @@ bitflags! { #[cfg(not(any( apple, solarish, + target_os = "aix", target_os = "dragonfly", target_os = "haiku", target_os = "netbsd", @@ -193,6 +214,7 @@ bitflags! { #[cfg(not(any( bsd, solarish, + target_os = "aix", target_os = "android", target_os = "emscripten", target_os = "fuchsia", @@ -208,6 +230,9 @@ bitflags! { /// `MAP_UNINITIALIZED` #[cfg(any())] const UNINITIALIZED = bitcast!(c::MAP_UNINITIALIZED); + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -224,6 +249,9 @@ bitflags! { pub struct MremapFlags: u32 { /// `MREMAP_MAYMOVE` const MAYMOVE = bitcast!(c::MREMAP_MAYMOVE); + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -243,6 +271,9 @@ bitflags! { /// file (so that they can be updated with the fresh values just /// written). const INVALIDATE = bitcast!(c::MS_INVALIDATE); + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -256,6 +287,9 @@ bitflags! { pub struct MlockFlags: u32 { /// `MLOCK_ONFAULT` const ONFAULT = bitcast!(c::MLOCK_ONFAULT); + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -403,5 +437,8 @@ bitflags! { const CLOEXEC = bitcast!(c::O_CLOEXEC); /// `O_NONBLOCK` const NONBLOCK = bitcast!(c::O_NONBLOCK); + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } diff --git a/vendor/rustix/src/backend/libc/mount/types.rs b/vendor/rustix/src/backend/libc/mount/types.rs index 660e6ae37..069a94444 100644 --- a/vendor/rustix/src/backend/libc/mount/types.rs +++ b/vendor/rustix/src/backend/libc/mount/types.rs @@ -54,6 +54,9 @@ bitflags! { /// `MS_SYNCHRONOUS` const SYNCHRONOUS = c::MS_SYNCHRONOUS; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -73,6 +76,9 @@ bitflags! { const EXPIRE = bitcast!(c::MNT_EXPIRE); /// `UMOUNT_NOFOLLOW` const NOFOLLOW = bitcast!(c::UMOUNT_NOFOLLOW); + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -85,9 +91,11 @@ bitflags! { #[repr(transparent)] #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct FsOpenFlags: c::c_uint { - /// `FSOPEN_CLOEXEC` const FSOPEN_CLOEXEC = 0x00000001; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -102,6 +110,9 @@ bitflags! { pub struct FsMountFlags: c::c_uint { /// `FSMOUNT_CLOEXEC` const FSMOUNT_CLOEXEC = 0x00000001; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -180,6 +191,9 @@ bitflags! { /// `MOUNT_ATTR__ATIME_FLAGS` const MOUNT_ATTR_SIZE_VER0 = 32; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -219,6 +233,9 @@ bitflags! { /// `MOVE_MOUNT__MASK` const MOVE_MOUNT__MASK = 0x00000377; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -248,6 +265,9 @@ bitflags! { /// `AT_SYMLINK_NOFOLLOW` const AT_SYMLINK_NOFOLLOW = c::AT_SYMLINK_NOFOLLOW as c::c_uint; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -271,6 +291,9 @@ bitflags! { /// `FSPICK_EMPTY_PATH` const FSPICK_EMPTY_PATH = 0x00000008; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -294,6 +317,9 @@ bitflags! { const UNBINDABLE = c::MS_UNBINDABLE; /// `MS_REC` const REC = c::MS_REC; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -304,6 +330,9 @@ bitflags! { pub(crate) struct InternalMountFlags: c::c_ulong { const REMOUNT = c::MS_REMOUNT; const MOVE = c::MS_MOVE; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } diff --git a/vendor/rustix/src/backend/libc/net/addr.rs b/vendor/rustix/src/backend/libc/net/addr.rs index bd2e7dafe..6a140d767 100644 --- a/vendor/rustix/src/backend/libc/net/addr.rs +++ b/vendor/rustix/src/backend/libc/net/addr.rs @@ -76,15 +76,17 @@ impl SocketAddrUnix { fn init() -> c::sockaddr_un { c::sockaddr_un { - #[cfg(any(bsd, target_os = "haiku", target_os = "nto"))] + #[cfg(any(bsd, target_os = "aix", target_os = "haiku", target_os = "nto"))] sun_len: 0, sun_family: c::AF_UNIX as _, #[cfg(any(bsd, target_os = "nto"))] sun_path: [0; 104], - #[cfg(not(any(bsd, target_os = "haiku", target_os = "nto")))] + #[cfg(not(any(bsd, target_os = "aix", target_os = "haiku", target_os = "nto")))] sun_path: [0; 108], #[cfg(target_os = "haiku")] sun_path: [0; 126], + #[cfg(target_os = "aix")] + sun_path: [0; 1023], } } @@ -159,9 +161,7 @@ impl Eq for SocketAddrUnix {} impl PartialOrd for SocketAddrUnix { #[inline] fn partial_cmp(&self, other: &Self) -> Option<Ordering> { - let self_len = self.len() - offsetof_sun_path(); - let other_len = other.len() - offsetof_sun_path(); - self.unix.sun_path[..self_len].partial_cmp(&other.unix.sun_path[..other_len]) + Some(self.cmp(other)) } } @@ -208,18 +208,32 @@ pub type SocketAddrStorage = c::sockaddr_storage; #[inline] pub(crate) fn offsetof_sun_path() -> usize { let z = c::sockaddr_un { - #[cfg(any(bsd, target_os = "haiku", target_os = "nto"))] + #[cfg(any(bsd, target_os = "aix", target_os = "haiku", target_os = "nto"))] sun_len: 0_u8, - #[cfg(any(bsd, target_os = "espidf", target_os = "haiku", target_os = "nto"))] + #[cfg(any( + bsd, + target_os = "aix", + target_os = "espidf", + target_os = "haiku", + target_os = "nto" + ))] sun_family: 0_u8, - #[cfg(not(any(bsd, target_os = "espidf", target_os = "haiku", target_os = "nto")))] + #[cfg(not(any( + bsd, + target_os = "aix", + target_os = "espidf", + target_os = "haiku", + target_os = "nto" + )))] sun_family: 0_u16, #[cfg(any(bsd, target_os = "nto"))] sun_path: [0; 104], - #[cfg(not(any(bsd, target_os = "haiku", target_os = "nto")))] + #[cfg(not(any(bsd, target_os = "aix", target_os = "haiku", target_os = "nto")))] sun_path: [0; 108], #[cfg(target_os = "haiku")] sun_path: [0; 126], + #[cfg(target_os = "aix")] + sun_path: [0; 1023], }; (crate::utils::as_ptr(&z.sun_path) as usize) - (crate::utils::as_ptr(&z) as usize) } diff --git a/vendor/rustix/src/backend/libc/net/ext.rs b/vendor/rustix/src/backend/libc/net/ext.rs index 50bd89db6..eb7c20d7d 100644 --- a/vendor/rustix/src/backend/libc/net/ext.rs +++ b/vendor/rustix/src/backend/libc/net/ext.rs @@ -78,7 +78,14 @@ pub(crate) const fn sockaddr_in6_sin6_scope_id(addr: &c::sockaddr_in6) -> u32 { #[cfg(not(windows))] #[inline] pub(crate) const fn sockaddr_in6_new( - #[cfg(any(bsd, target_os = "espidf", target_os = "haiku", target_os = "nto"))] sin6_len: u8, + #[cfg(any( + bsd, + target_os = "aix", + target_os = "espidf", + target_os = "haiku", + target_os = "nto" + ))] + sin6_len: u8, sin6_family: c::sa_family_t, sin6_port: u16, sin6_flowinfo: u32, @@ -86,7 +93,13 @@ pub(crate) const fn sockaddr_in6_new( sin6_scope_id: u32, ) -> c::sockaddr_in6 { c::sockaddr_in6 { - #[cfg(any(bsd, target_os = "espidf", target_os = "haiku", target_os = "nto"))] + #[cfg(any( + bsd, + target_os = "aix", + target_os = "espidf", + target_os = "haiku", + target_os = "nto" + ))] sin6_len, sin6_family, sin6_port, diff --git a/vendor/rustix/src/backend/libc/net/msghdr.rs b/vendor/rustix/src/backend/libc/net/msghdr.rs index e3f873747..2ccd7f20c 100644 --- a/vendor/rustix/src/backend/libc/net/msghdr.rs +++ b/vendor/rustix/src/backend/libc/net/msghdr.rs @@ -24,7 +24,7 @@ pub(crate) fn with_recv_msghdr<R>( let namelen = size_of::<c::sockaddr_storage>() as c::socklen_t; let mut msghdr = { - let mut h: c::msghdr = unsafe { zeroed() }; + let mut h = zero_msghdr(); h.msg_name = name.as_mut_ptr().cast(); h.msg_namelen = namelen; h.msg_iov = iov.as_mut_ptr().cast(); @@ -53,7 +53,7 @@ pub(crate) fn with_noaddr_msghdr<R>( f: impl FnOnce(c::msghdr) -> R, ) -> R { f({ - let mut h: c::msghdr = unsafe { zeroed() }; + let mut h = zero_msghdr(); h.msg_iov = iov.as_ptr() as _; h.msg_iovlen = msg_iov_len(iov.len()); h.msg_control = control.as_control_ptr().cast(); @@ -69,10 +69,10 @@ pub(crate) fn with_v4_msghdr<R>( control: &mut SendAncillaryBuffer<'_, '_, '_>, f: impl FnOnce(c::msghdr) -> R, ) -> R { - let encoded = unsafe { encode_sockaddr_v4(addr) }; + let encoded = encode_sockaddr_v4(addr); f({ - let mut h: c::msghdr = unsafe { zeroed() }; + let mut h = zero_msghdr(); h.msg_name = as_ptr(&encoded) as _; h.msg_namelen = size_of::<SocketAddrV4>() as _; h.msg_iov = iov.as_ptr() as _; @@ -90,10 +90,10 @@ pub(crate) fn with_v6_msghdr<R>( control: &mut SendAncillaryBuffer<'_, '_, '_>, f: impl FnOnce(c::msghdr) -> R, ) -> R { - let encoded = unsafe { encode_sockaddr_v6(addr) }; + let encoded = encode_sockaddr_v6(addr); f({ - let mut h: c::msghdr = unsafe { zeroed() }; + let mut h = zero_msghdr(); h.msg_name = as_ptr(&encoded) as _; h.msg_namelen = size_of::<SocketAddrV6>() as _; h.msg_iov = iov.as_ptr() as _; @@ -113,7 +113,7 @@ pub(crate) fn with_unix_msghdr<R>( f: impl FnOnce(c::msghdr) -> R, ) -> R { f({ - let mut h: c::msghdr = unsafe { zeroed() }; + let mut h = zero_msghdr(); h.msg_name = as_ptr(addr) as _; h.msg_namelen = addr.addr_len(); h.msg_iov = iov.as_ptr() as _; @@ -123,3 +123,12 @@ pub(crate) fn with_unix_msghdr<R>( h }) } + +/// Create a zero-initialized message header struct value. +#[cfg(all(unix, not(target_os = "redox")))] +pub(crate) fn zero_msghdr() -> c::msghdr { + // SAFETY: We can't initialize all the fields by value because on some + // platforms the `msghdr` struct in the libc crate contains private padding + // fields. But it is still a C type that's meant to be zero-initializable. + unsafe { zeroed() } +} diff --git a/vendor/rustix/src/backend/libc/net/read_sockaddr.rs b/vendor/rustix/src/backend/libc/net/read_sockaddr.rs index cde851af6..604f24928 100644 --- a/vendor/rustix/src/backend/libc/net/read_sockaddr.rs +++ b/vendor/rustix/src/backend/libc/net/read_sockaddr.rs @@ -26,11 +26,29 @@ struct sockaddr_header { unsafe fn read_ss_family(storage: *const c::sockaddr_storage) -> u16 { // Assert that we know the layout of `sockaddr`. let _ = c::sockaddr { - #[cfg(any(bsd, target_os = "espidf", target_os = "haiku", target_os = "nto"))] + #[cfg(any( + bsd, + target_os = "aix", + target_os = "espidf", + target_os = "haiku", + target_os = "nto" + ))] sa_len: 0_u8, - #[cfg(any(bsd, target_os = "espidf", target_os = "haiku", target_os = "nto"))] + #[cfg(any( + bsd, + target_os = "aix", + target_os = "espidf", + target_os = "haiku", + target_os = "nto" + ))] sa_family: 0_u8, - #[cfg(not(any(bsd, target_os = "espidf", target_os = "haiku", target_os = "nto")))] + #[cfg(not(any( + bsd, + target_os = "aix", + target_os = "espidf", + target_os = "haiku", + target_os = "nto" + )))] sa_family: 0_u16, #[cfg(not(target_os = "haiku"))] sa_data: [0; 14], diff --git a/vendor/rustix/src/backend/libc/net/send_recv.rs b/vendor/rustix/src/backend/libc/net/send_recv.rs index 26543a1fd..76dc97e78 100644 --- a/vendor/rustix/src/backend/libc/net/send_recv.rs +++ b/vendor/rustix/src/backend/libc/net/send_recv.rs @@ -14,6 +14,7 @@ bitflags! { bsd, solarish, windows, + target_os = "aix", target_os = "espidf", target_os = "nto", target_os = "haiku", @@ -32,6 +33,7 @@ bitflags! { bsd, solarish, windows, + target_os = "aix", target_os = "haiku", target_os = "nto", )))] @@ -41,6 +43,9 @@ bitflags! { const NOSIGNAL = bitcast!(c::MSG_NOSIGNAL); /// `MSG_OOB` const OOB = bitcast!(c::MSG_OOB); + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -52,7 +57,15 @@ bitflags! { #[repr(transparent)] #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct RecvFlags: u32 { - #[cfg(not(any(apple, solarish, windows, target_os = "espidf", target_os = "haiku", target_os = "nto")))] + #[cfg(not(any( + apple, + solarish, + windows, + target_os = "aix", + target_os = "espidf", + target_os = "haiku", + target_os = "nto", + )))] /// `MSG_CMSG_CLOEXEC` const CMSG_CLOEXEC = bitcast!(c::MSG_CMSG_CLOEXEC); /// `MSG_DONTWAIT` @@ -63,6 +76,7 @@ bitflags! { bsd, solarish, windows, + target_os = "aix", target_os = "espidf", target_os = "haiku", target_os = "nto", @@ -76,5 +90,8 @@ bitflags! { const TRUNC = bitcast!(c::MSG_TRUNC); /// `MSG_WAITALL` const WAITALL = bitcast!(c::MSG_WAITALL); + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } diff --git a/vendor/rustix/src/backend/libc/net/syscalls.rs b/vendor/rustix/src/backend/libc/net/syscalls.rs index b4550583c..2e968ba3e 100644 --- a/vendor/rustix/src/backend/libc/net/syscalls.rs +++ b/vendor/rustix/src/backend/libc/net/syscalls.rs @@ -358,6 +358,7 @@ pub(crate) fn sendmsg_unix( #[cfg(not(any( apple, windows, + target_os = "aix", target_os = "espidf", target_os = "haiku", target_os = "redox", @@ -396,6 +397,7 @@ pub(crate) fn acceptfrom(sockfd: BorrowedFd<'_>) -> io::Result<(OwnedFd, Option< #[cfg(not(any( apple, windows, + target_os = "aix", target_os = "espidf", target_os = "haiku", target_os = "nto", @@ -427,6 +429,7 @@ pub(crate) fn acceptfrom_with( #[cfg(any( apple, windows, + target_os = "aix", target_os = "espidf", target_os = "haiku", target_os = "nto" @@ -440,6 +443,7 @@ pub(crate) fn accept_with(sockfd: BorrowedFd<'_>, _flags: SocketFlags) -> io::Re #[cfg(any( apple, windows, + target_os = "aix", target_os = "espidf", target_os = "haiku", target_os = "nto" @@ -517,8 +521,24 @@ pub(crate) mod sockopt { use super::{c, in6_addr_new, in_addr_new, BorrowedFd}; use crate::io; use crate::net::sockopt::Timeout; + #[cfg(not(any( + apple, + windows, + target_os = "aix", + target_os = "dragonfly", + target_os = "emscripten", + target_os = "espidf", + target_os = "haiku", + target_os = "netbsd", + target_os = "nto", + )))] + use crate::net::AddressFamily; use crate::net::{Ipv4Addr, Ipv6Addr, SocketType}; use crate::utils::as_mut_ptr; + #[cfg(apple)] + use c::TCP_KEEPALIVE as TCP_KEEPIDLE; + #[cfg(not(any(apple, target_os = "openbsd", target_os = "haiku", target_os = "nto")))] + use c::TCP_KEEPIDLE; use core::time::Duration; #[cfg(windows)] use windows_sys::Win32::Foundation::BOOL; @@ -597,6 +617,11 @@ pub(crate) mod sockopt { } #[inline] + pub(crate) fn get_socket_reuseaddr(fd: BorrowedFd<'_>) -> io::Result<bool> { + getsockopt(fd, c::SOL_SOCKET as _, c::SO_REUSEADDR).map(to_bool) + } + + #[inline] pub(crate) fn set_socket_broadcast(fd: BorrowedFd<'_>, broadcast: bool) -> io::Result<()> { setsockopt( fd, @@ -618,11 +643,7 @@ pub(crate) mod sockopt { ) -> io::Result<()> { // Convert `linger` to seconds, rounding up. let l_linger = if let Some(linger) = linger { - let mut l_linger = linger.as_secs(); - if linger.subsec_nanos() != 0 { - l_linger = l_linger.checked_add(1).ok_or(io::Errno::INVAL)?; - } - l_linger.try_into().map_err(|_e| io::Errno::INVAL)? + duration_to_secs(linger)? } else { 0 }; @@ -810,6 +831,31 @@ pub(crate) mod sockopt { } #[inline] + #[cfg(not(any( + apple, + windows, + target_os = "aix", + target_os = "dragonfly", + target_os = "emscripten", + target_os = "espidf", + target_os = "haiku", + target_os = "netbsd", + target_os = "nto", + )))] + pub(crate) fn get_socket_domain(fd: BorrowedFd<'_>) -> io::Result<AddressFamily> { + let domain: c::c_int = getsockopt(fd, c::SOL_SOCKET as _, c::SO_DOMAIN)?; + Ok(AddressFamily( + domain.try_into().map_err(|_| io::Errno::OPNOTSUPP)?, + )) + } + + #[inline] + #[cfg(not(apple))] // Apple platforms declare the constant, but do not actually implement it. + pub(crate) fn get_socket_acceptconn(fd: BorrowedFd<'_>) -> io::Result<bool> { + getsockopt(fd, c::SOL_SOCKET as _, c::SO_ACCEPTCONN).map(to_bool) + } + + #[inline] pub(crate) fn set_ip_ttl(fd: BorrowedFd<'_>, ttl: u32) -> io::Result<()> { setsockopt(fd, c::IPPROTO_IP as _, c::IP_TTL, ttl) } @@ -992,6 +1038,46 @@ pub(crate) mod sockopt { } #[inline] + #[cfg(not(any(target_os = "openbsd", target_os = "haiku", target_os = "nto")))] + pub(crate) fn set_tcp_keepcnt(fd: BorrowedFd<'_>, count: u32) -> io::Result<()> { + setsockopt(fd, c::IPPROTO_TCP as _, c::TCP_KEEPCNT, count) + } + + #[inline] + #[cfg(not(any(target_os = "openbsd", target_os = "haiku", target_os = "nto")))] + pub(crate) fn get_tcp_keepcnt(fd: BorrowedFd<'_>) -> io::Result<u32> { + getsockopt(fd, c::IPPROTO_TCP as _, c::TCP_KEEPCNT) + } + + #[inline] + #[cfg(not(any(target_os = "openbsd", target_os = "haiku", target_os = "nto")))] + pub(crate) fn set_tcp_keepidle(fd: BorrowedFd<'_>, duration: Duration) -> io::Result<()> { + let secs: c::c_uint = duration_to_secs(duration)?; + setsockopt(fd, c::IPPROTO_TCP as _, TCP_KEEPIDLE, secs) + } + + #[inline] + #[cfg(not(any(target_os = "openbsd", target_os = "haiku", target_os = "nto")))] + pub(crate) fn get_tcp_keepidle(fd: BorrowedFd<'_>) -> io::Result<Duration> { + let secs: c::c_uint = getsockopt(fd, c::IPPROTO_TCP as _, TCP_KEEPIDLE)?; + Ok(Duration::from_secs(secs as u64)) + } + + #[inline] + #[cfg(not(any(target_os = "openbsd", target_os = "haiku", target_os = "nto")))] + pub(crate) fn set_tcp_keepintvl(fd: BorrowedFd<'_>, duration: Duration) -> io::Result<()> { + let secs: c::c_uint = duration_to_secs(duration)?; + setsockopt(fd, c::IPPROTO_TCP as _, c::TCP_KEEPINTVL, secs) + } + + #[inline] + #[cfg(not(any(target_os = "openbsd", target_os = "haiku", target_os = "nto")))] + pub(crate) fn get_tcp_keepintvl(fd: BorrowedFd<'_>) -> io::Result<Duration> { + let secs: c::c_uint = getsockopt(fd, c::IPPROTO_TCP as _, c::TCP_KEEPINTVL)?; + Ok(Duration::from_secs(secs as u64)) + } + + #[inline] fn to_imr(multiaddr: &Ipv4Addr, interface: &Ipv4Addr) -> c::ip_mreq { c::ip_mreq { imr_multiaddr: to_imr_addr(multiaddr), @@ -1051,4 +1137,14 @@ pub(crate) mod sockopt { fn to_bool(value: SocketBool) -> bool { value.0 != 0 } + + /// Convert to seconds, rounding up if necessary. + #[inline] + fn duration_to_secs<T: TryFrom<u64>>(duration: Duration) -> io::Result<T> { + let mut secs = duration.as_secs(); + if duration.subsec_nanos() != 0 { + secs = secs.checked_add(1).ok_or(io::Errno::INVAL)?; + } + T::try_from(secs).map_err(|_e| io::Errno::INVAL) + } } diff --git a/vendor/rustix/src/backend/libc/net/write_sockaddr.rs b/vendor/rustix/src/backend/libc/net/write_sockaddr.rs index 46f0ef40a..a354d9a85 100644 --- a/vendor/rustix/src/backend/libc/net/write_sockaddr.rs +++ b/vendor/rustix/src/backend/libc/net/write_sockaddr.rs @@ -21,9 +21,15 @@ pub(crate) unsafe fn write_sockaddr( } } -pub(crate) unsafe fn encode_sockaddr_v4(v4: &SocketAddrV4) -> c::sockaddr_in { +pub(crate) fn encode_sockaddr_v4(v4: &SocketAddrV4) -> c::sockaddr_in { c::sockaddr_in { - #[cfg(any(bsd, target_os = "espidf", target_os = "haiku", target_os = "nto"))] + #[cfg(any( + bsd, + target_os = "aix", + target_os = "espidf", + target_os = "haiku", + target_os = "nto", + ))] sin_len: size_of::<c::sockaddr_in>() as _, sin_family: c::AF_INET as _, sin_port: u16::to_be(v4.port()), @@ -41,8 +47,14 @@ unsafe fn write_sockaddr_v4(v4: &SocketAddrV4, storage: *mut SocketAddrStorage) size_of::<c::sockaddr_in>() } -pub(crate) unsafe fn encode_sockaddr_v6(v6: &SocketAddrV6) -> c::sockaddr_in6 { - #[cfg(any(bsd, target_os = "espidf", target_os = "haiku", target_os = "nto"))] +pub(crate) fn encode_sockaddr_v6(v6: &SocketAddrV6) -> c::sockaddr_in6 { + #[cfg(any( + bsd, + target_os = "aix", + target_os = "espidf", + target_os = "haiku", + target_os = "nto", + ))] { sockaddr_in6_new( size_of::<c::sockaddr_in6>() as _, @@ -53,7 +65,13 @@ pub(crate) unsafe fn encode_sockaddr_v6(v6: &SocketAddrV6) -> c::sockaddr_in6 { v6.scope_id(), ) } - #[cfg(not(any(bsd, target_os = "espidf", target_os = "haiku", target_os = "nto")))] + #[cfg(not(any( + bsd, + target_os = "aix", + target_os = "espidf", + target_os = "haiku", + target_os = "nto" + )))] { sockaddr_in6_new( c::AF_INET6 as _, diff --git a/vendor/rustix/src/backend/libc/pipe/syscalls.rs b/vendor/rustix/src/backend/libc/pipe/syscalls.rs index 24262cc9a..cff932d55 100644 --- a/vendor/rustix/src/backend/libc/pipe/syscalls.rs +++ b/vendor/rustix/src/backend/libc/pipe/syscalls.rs @@ -55,9 +55,9 @@ pub(crate) fn pipe_with(flags: PipeFlags) -> io::Result<(OwnedFd, OwnedFd)> { #[cfg(linux_kernel)] #[inline] pub fn splice( - fd_in: BorrowedFd, + fd_in: BorrowedFd<'_>, off_in: Option<&mut u64>, - fd_out: BorrowedFd, + fd_out: BorrowedFd<'_>, off_out: Option<&mut u64>, len: usize, flags: SpliceFlags, @@ -80,8 +80,8 @@ pub fn splice( #[cfg(linux_kernel)] #[inline] pub unsafe fn vmsplice( - fd: BorrowedFd, - bufs: &[IoSliceRaw], + fd: BorrowedFd<'_>, + bufs: &[IoSliceRaw<'_>], flags: SpliceFlags, ) -> io::Result<usize> { ret_usize(c::vmsplice( @@ -95,8 +95,8 @@ pub unsafe fn vmsplice( #[cfg(linux_kernel)] #[inline] pub fn tee( - fd_in: BorrowedFd, - fd_out: BorrowedFd, + fd_in: BorrowedFd<'_>, + fd_out: BorrowedFd<'_>, len: usize, flags: SpliceFlags, ) -> io::Result<usize> { diff --git a/vendor/rustix/src/backend/libc/pipe/types.rs b/vendor/rustix/src/backend/libc/pipe/types.rs index 3fa0464e0..7f5634b17 100644 --- a/vendor/rustix/src/backend/libc/pipe/types.rs +++ b/vendor/rustix/src/backend/libc/pipe/types.rs @@ -25,6 +25,9 @@ bitflags! { const DIRECT = bitcast!(c::O_DIRECT); /// `O_NONBLOCK` const NONBLOCK = bitcast!(c::O_NONBLOCK); + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -43,6 +46,9 @@ bitflags! { const MORE = c::SPLICE_F_MORE; /// `SPLICE_F_GIFT` const GIFT = c::SPLICE_F_GIFT; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } diff --git a/vendor/rustix/src/backend/libc/process/syscalls.rs b/vendor/rustix/src/backend/libc/process/syscalls.rs index a84385cf1..dd71801d5 100644 --- a/vendor/rustix/src/backend/libc/process/syscalls.rs +++ b/vendor/rustix/src/backend/libc/process/syscalls.rs @@ -3,9 +3,11 @@ #[cfg(any(linux_kernel, target_os = "dragonfly", target_os = "fuchsia"))] use super::types::RawCpuSet; use crate::backend::c; +#[cfg(not(any(target_os = "wasi", target_os = "fuchsia")))] +use crate::backend::conv::borrowed_fd; #[cfg(feature = "fs")] use crate::backend::conv::c_str; -#[cfg(all(feature = "fs", not(target_os = "wasi")))] +#[cfg(all(feature = "alloc", feature = "fs", not(target_os = "wasi")))] use crate::backend::conv::ret_discarded_char_ptr; #[cfg(not(any( target_os = "espidf", @@ -14,12 +16,14 @@ use crate::backend::conv::ret_discarded_char_ptr; target_os = "wasi" )))] use crate::backend::conv::ret_infallible; +#[cfg(not(target_os = "wasi"))] +use crate::backend::conv::ret_pid_t; #[cfg(linux_kernel)] use crate::backend::conv::ret_u32; -#[cfg(not(target_os = "wasi"))] -use crate::backend::conv::{borrowed_fd, ret_pid_t, ret_usize}; +#[cfg(all(feature = "alloc", not(target_os = "wasi")))] +use crate::backend::conv::ret_usize; use crate::backend::conv::{ret, ret_c_int}; -#[cfg(not(target_os = "wasi"))] +#[cfg(not(any(target_os = "wasi", target_os = "fuchsia")))] use crate::fd::BorrowedFd; #[cfg(target_os = "linux")] use crate::fd::{AsRawFd, OwnedFd, RawFd}; @@ -28,12 +32,14 @@ use crate::ffi::CStr; #[cfg(feature = "fs")] use crate::fs::Mode; use crate::io; +#[cfg(all(feature = "alloc", not(target_os = "wasi")))] +use crate::process::Gid; +#[cfg(not(target_os = "wasi"))] +use crate::process::Pid; #[cfg(not(any(target_os = "espidf", target_os = "fuchsia", target_os = "wasi")))] use crate::process::Uid; #[cfg(linux_kernel)] use crate::process::{Cpuid, MembarrierCommand, MembarrierQuery}; -#[cfg(not(target_os = "wasi"))] -use crate::process::{Gid, Pid}; #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] use crate::process::{RawPid, Signal, WaitOptions, WaitStatus}; #[cfg(not(any( @@ -73,7 +79,7 @@ pub(crate) fn chroot(path: &CStr) -> io::Result<()> { unsafe { ret(c::chroot(c_str(path))) } } -#[cfg(feature = "fs")] +#[cfg(all(feature = "alloc", feature = "fs"))] #[cfg(not(target_os = "wasi"))] pub(crate) fn getcwd(buf: &mut [MaybeUninit<u8>]) -> io::Result<()> { unsafe { ret_discarded_char_ptr(c::getcwd(buf.as_mut_ptr().cast(), buf.len())) } @@ -612,20 +618,9 @@ pub(crate) fn pidfd_getfd( } } -#[cfg(not(target_os = "wasi"))] +#[cfg(all(feature = "alloc", not(target_os = "wasi")))] pub(crate) fn getgroups(buf: &mut [Gid]) -> io::Result<usize> { 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(not(any( - target_os = "aix", - target_os = "espidf", - target_os = "redox", - target_os = "wasi" -)))] -#[inline] -pub(crate) fn ioctl_tiocsctty(fd: BorrowedFd<'_>) -> io::Result<()> { - unsafe { ret(c::ioctl(borrowed_fd(fd), c::TIOCSCTTY as _, &0_u32)) } -} diff --git a/vendor/rustix/src/backend/libc/process/types.rs b/vendor/rustix/src/backend/libc/process/types.rs index 9c543acd0..26bae3498 100644 --- a/vendor/rustix/src/backend/libc/process/types.rs +++ b/vendor/rustix/src/backend/libc/process/types.rs @@ -141,11 +141,6 @@ impl Resource { pub const Rss: Self = Self::As; } -pub const EXIT_SUCCESS: c::c_int = c::EXIT_SUCCESS; -pub const EXIT_FAILURE: c::c_int = c::EXIT_FAILURE; -#[cfg(not(any(target_os = "espidf", target_os = "wasi")))] -pub const EXIT_SIGNALED_SIGABRT: c::c_int = 128 + c::SIGABRT; - /// A CPU identifier as a raw integer. #[cfg(linux_kernel)] pub type RawCpuid = u32; diff --git a/vendor/rustix/src/backend/libc/pty/syscalls.rs b/vendor/rustix/src/backend/libc/pty/syscalls.rs index 6688ddb26..cf566045d 100644 --- a/vendor/rustix/src/backend/libc/pty/syscalls.rs +++ b/vendor/rustix/src/backend/libc/pty/syscalls.rs @@ -4,9 +4,10 @@ use crate::backend::c; use crate::backend::conv::{borrowed_fd, ret}; use crate::fd::BorrowedFd; use crate::io; -#[cfg(not(target_os = "android"))] -use {crate::backend::conv::ret_owned_fd, crate::fd::OwnedFd, crate::pty::OpenptFlags}; -#[cfg(any(apple, linux_like, target_os = "freebsd", target_os = "fuchsia"))] +#[cfg(all( + feature = "alloc", + any(apple, linux_like, target_os = "freebsd", target_os = "fuchsia") +))] use { crate::ffi::{CStr, CString}, crate::path::SMALL_PATH_BUFFER_SIZE, @@ -15,14 +16,20 @@ use { }; #[cfg(not(linux_kernel))] +use crate::{backend::conv::ret_owned_fd, fd::OwnedFd, pty::OpenptFlags}; + +#[cfg(not(linux_kernel))] #[inline] pub(crate) fn openpt(flags: OpenptFlags) -> io::Result<OwnedFd> { unsafe { ret_owned_fd(c::posix_openpt(flags.bits() as _)) } } -#[cfg(any(apple, linux_like, target_os = "freebsd", target_os = "fuchsia"))] +#[cfg(all( + feature = "alloc", + any(apple, linux_like, target_os = "freebsd", target_os = "fuchsia") +))] #[inline] -pub(crate) fn ptsname(fd: BorrowedFd, mut buffer: Vec<u8>) -> io::Result<CString> { +pub(crate) fn ptsname(fd: BorrowedFd<'_>, mut buffer: Vec<u8>) -> io::Result<CString> { // This code would benefit from having a better way to read into // uninitialized memory, but that requires `unsafe`. buffer.clear(); @@ -86,18 +93,12 @@ pub(crate) fn ptsname(fd: BorrowedFd, mut buffer: Vec<u8>) -> io::Result<CString } #[inline] -pub(crate) fn unlockpt(fd: BorrowedFd) -> io::Result<()> { +pub(crate) fn unlockpt(fd: BorrowedFd<'_>) -> io::Result<()> { unsafe { ret(c::unlockpt(borrowed_fd(fd))) } } #[cfg(not(linux_kernel))] #[inline] -pub(crate) fn grantpt(fd: BorrowedFd) -> io::Result<()> { +pub(crate) fn grantpt(fd: BorrowedFd<'_>) -> io::Result<()> { unsafe { ret(c::grantpt(borrowed_fd(fd))) } } - -#[cfg(target_os = "linux")] -#[inline] -pub(crate) fn ioctl_tiocgptpeer(fd: BorrowedFd, flags: OpenptFlags) -> io::Result<OwnedFd> { - unsafe { ret_owned_fd(c::ioctl(borrowed_fd(fd), c::TIOCGPTPEER, flags.bits())) } -} diff --git a/vendor/rustix/src/backend/libc/rand/types.rs b/vendor/rustix/src/backend/libc/rand/types.rs index 730cf3a34..cd436b618 100644 --- a/vendor/rustix/src/backend/libc/rand/types.rs +++ b/vendor/rustix/src/backend/libc/rand/types.rs @@ -17,5 +17,8 @@ bitflags! { const NONBLOCK = c::GRND_NONBLOCK; /// `GRND_INSECURE` const INSECURE = c::GRND_INSECURE; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } diff --git a/vendor/rustix/src/backend/libc/termios/syscalls.rs b/vendor/rustix/src/backend/libc/termios/syscalls.rs index ea284927f..df96595cd 100644 --- a/vendor/rustix/src/backend/libc/termios/syscalls.rs +++ b/vendor/rustix/src/backend/libc/termios/syscalls.rs @@ -9,7 +9,7 @@ use crate::backend::c; use crate::backend::conv::ret_pid_t; use crate::backend::conv::{borrowed_fd, ret}; use crate::fd::BorrowedFd; -#[cfg(feature = "procfs")] +#[cfg(all(feature = "alloc", feature = "procfs"))] #[cfg(not(any(target_os = "fuchsia", target_os = "wasi")))] use crate::ffi::CStr; #[cfg(any( @@ -33,19 +33,21 @@ pub(crate) fn tcgetattr(fd: BorrowedFd<'_>) -> io::Result<Termios> { // If we have `TCGETS2`, use it, so that we fill in the `c_ispeed` and // `c_ospeed` fields. #[cfg(linux_kernel)] - unsafe { + { use crate::termios::{ControlModes, InputModes, LocalModes, OutputModes, SpecialCodes}; - use core::mem::zeroed; + use crate::utils::default_array; - let mut termios2 = MaybeUninit::<c::termios2>::uninit(); + let termios2 = unsafe { + let mut termios2 = MaybeUninit::<c::termios2>::uninit(); - ret(c::ioctl( - borrowed_fd(fd), - c::TCGETS2 as _, - termios2.as_mut_ptr(), - ))?; + ret(c::ioctl( + borrowed_fd(fd), + c::TCGETS2 as _, + termios2.as_mut_ptr(), + ))?; - let termios2 = termios2.assume_init(); + termios2.assume_init() + }; // Convert from the Linux `termios2` to our `Termios`. let mut result = Termios { @@ -54,7 +56,7 @@ pub(crate) fn tcgetattr(fd: BorrowedFd<'_>) -> io::Result<Termios> { control_modes: ControlModes::from_bits_retain(termios2.c_cflag), local_modes: LocalModes::from_bits_retain(termios2.c_lflag), line_discipline: termios2.c_line, - special_codes: SpecialCodes(zeroed()), + special_codes: SpecialCodes(default_array()), input_speed: termios2.c_ispeed, output_speed: termios2.c_ospeed, }; @@ -90,16 +92,16 @@ pub(crate) fn tcsetpgrp(fd: BorrowedFd<'_>, pid: Pid) -> io::Result<()> { #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] pub(crate) fn tcsetattr( - fd: BorrowedFd, + fd: BorrowedFd<'_>, optional_actions: OptionalActions, termios: &Termios, ) -> io::Result<()> { // If we have `TCSETS2`, use it, so that we use the `c_ispeed` and // `c_ospeed` fields. #[cfg(linux_kernel)] - unsafe { + { use crate::termios::speed; - use core::mem::zeroed; + use crate::utils::default_array; use linux_raw_sys::general::{termios2, BOTHER, CBAUD, IBSHIFT}; #[cfg(not(any(target_arch = "sparc", target_arch = "sparc64")))] @@ -134,7 +136,7 @@ pub(crate) fn tcsetattr( c_cflag: termios.control_modes.bits(), c_lflag: termios.local_modes.bits(), c_line: termios.line_discipline, - c_cc: zeroed(), + c_cc: default_array(), c_ispeed: input_speed, c_ospeed: output_speed, }; @@ -149,7 +151,7 @@ pub(crate) fn tcsetattr( .c_cc .copy_from_slice(&termios.special_codes.0[..nccs]); - ret(c::ioctl(borrowed_fd(fd), request as _, &termios2)) + unsafe { ret(c::ioctl(borrowed_fd(fd), request as _, &termios2)) } } #[cfg(not(linux_kernel))] @@ -163,27 +165,27 @@ pub(crate) fn tcsetattr( } #[cfg(not(target_os = "wasi"))] -pub(crate) fn tcsendbreak(fd: BorrowedFd) -> io::Result<()> { +pub(crate) fn tcsendbreak(fd: BorrowedFd<'_>) -> io::Result<()> { unsafe { ret(c::tcsendbreak(borrowed_fd(fd), 0)) } } #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] -pub(crate) fn tcdrain(fd: BorrowedFd) -> io::Result<()> { +pub(crate) fn tcdrain(fd: BorrowedFd<'_>) -> io::Result<()> { unsafe { ret(c::tcdrain(borrowed_fd(fd))) } } #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] -pub(crate) fn tcflush(fd: BorrowedFd, queue_selector: QueueSelector) -> io::Result<()> { +pub(crate) fn tcflush(fd: BorrowedFd<'_>, queue_selector: QueueSelector) -> io::Result<()> { unsafe { ret(c::tcflush(borrowed_fd(fd), queue_selector as _)) } } #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] -pub(crate) fn tcflow(fd: BorrowedFd, action: Action) -> io::Result<()> { +pub(crate) fn tcflow(fd: BorrowedFd<'_>, action: Action) -> io::Result<()> { unsafe { ret(c::tcflow(borrowed_fd(fd), action as _)) } } #[cfg(not(target_os = "wasi"))] -pub(crate) fn tcgetsid(fd: BorrowedFd) -> io::Result<Pid> { +pub(crate) fn tcgetsid(fd: BorrowedFd<'_>) -> io::Result<Pid> { unsafe { let pid = ret_pid_t(c::tcgetsid(borrowed_fd(fd)))?; Ok(Pid::from_raw_unchecked(pid)) @@ -191,12 +193,12 @@ pub(crate) fn tcgetsid(fd: BorrowedFd) -> io::Result<Pid> { } #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] -pub(crate) fn tcsetwinsize(fd: BorrowedFd, winsize: Winsize) -> io::Result<()> { +pub(crate) fn tcsetwinsize(fd: BorrowedFd<'_>, winsize: Winsize) -> io::Result<()> { unsafe { ret(c::ioctl(borrowed_fd(fd), c::TIOCSWINSZ, &winsize)) } } #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] -pub(crate) fn tcgetwinsize(fd: BorrowedFd) -> io::Result<Winsize> { +pub(crate) fn tcgetwinsize(fd: BorrowedFd<'_>) -> io::Result<Winsize> { unsafe { let mut buf = MaybeUninit::<Winsize>::uninit(); ret(c::ioctl( @@ -208,26 +210,6 @@ pub(crate) fn tcgetwinsize(fd: BorrowedFd) -> io::Result<Winsize> { } } -#[cfg(not(any( - target_os = "espidf", - target_os = "haiku", - target_os = "redox", - target_os = "wasi" -)))] -pub(crate) fn ioctl_tiocexcl(fd: BorrowedFd) -> io::Result<()> { - unsafe { ret(c::ioctl(borrowed_fd(fd), c::TIOCEXCL as _)) } -} - -#[cfg(not(any( - target_os = "espidf", - target_os = "haiku", - target_os = "redox", - target_os = "wasi" -)))] -pub(crate) fn ioctl_tiocnxcl(fd: BorrowedFd) -> io::Result<()> { - unsafe { ret(c::ioctl(borrowed_fd(fd), c::TIOCNXCL as _)) } -} - #[cfg(not(any(target_os = "espidf", target_os = "nto", target_os = "wasi")))] #[inline] pub(crate) fn set_speed(termios: &mut Termios, arbitrary_speed: u32) -> io::Result<()> { @@ -365,7 +347,7 @@ pub(crate) fn isatty(fd: BorrowedFd<'_>) -> bool { unsafe { c::isatty(borrowed_fd(fd)) != 0 } } -#[cfg(feature = "procfs")] +#[cfg(all(feature = "alloc", feature = "procfs"))] #[cfg(not(any(target_os = "fuchsia", target_os = "wasi")))] pub(crate) fn ttyname(dirfd: BorrowedFd<'_>, buf: &mut [MaybeUninit<u8>]) -> io::Result<usize> { unsafe { diff --git a/vendor/rustix/src/backend/libc/thread/futex.rs b/vendor/rustix/src/backend/libc/thread/futex.rs new file mode 100644 index 000000000..44d96f0f6 --- /dev/null +++ b/vendor/rustix/src/backend/libc/thread/futex.rs @@ -0,0 +1,43 @@ +use crate::backend::c; + +bitflags::bitflags! { + /// `FUTEX_*` flags for use with [`futex`]. + /// + /// [`futex`]: crate::thread::futex + #[repr(transparent)] + #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] + pub struct FutexFlags: u32 { + /// `FUTEX_PRIVATE_FLAG` + const PRIVATE = bitcast!(c::FUTEX_PRIVATE_FLAG); + /// `FUTEX_CLOCK_REALTIME` + const CLOCK_REALTIME = bitcast!(c::FUTEX_CLOCK_REALTIME); + } +} + +/// `FUTEX_*` operations for use with [`futex`]. +/// +/// [`futex`]: crate::thread::futex +#[derive(Debug, Copy, Clone, Eq, PartialEq)] +#[repr(u32)] +pub enum FutexOperation { + /// `FUTEX_WAIT` + Wait = bitcast!(c::FUTEX_WAIT), + /// `FUTEX_WAKE` + Wake = bitcast!(c::FUTEX_WAKE), + /// `FUTEX_FD` + Fd = bitcast!(c::FUTEX_FD), + /// `FUTEX_REQUEUE` + Requeue = bitcast!(c::FUTEX_REQUEUE), + /// `FUTEX_CMP_REQUEUE` + CmpRequeue = bitcast!(c::FUTEX_CMP_REQUEUE), + /// `FUTEX_WAKE_OP` + WakeOp = bitcast!(c::FUTEX_WAKE_OP), + /// `FUTEX_LOCK_PI` + LockPi = bitcast!(c::FUTEX_LOCK_PI), + /// `FUTEX_UNLOCK_PI` + UnlockPi = bitcast!(c::FUTEX_UNLOCK_PI), + /// `FUTEX_TRYLOCK_PI` + TrylockPi = bitcast!(c::FUTEX_TRYLOCK_PI), + /// `FUTEX_WAIT_BITSET` + WaitBitset = bitcast!(c::FUTEX_WAIT_BITSET), +} diff --git a/vendor/rustix/src/backend/libc/thread/mod.rs b/vendor/rustix/src/backend/libc/thread/mod.rs index 40e0d1135..4f8c87cd2 100644 --- a/vendor/rustix/src/backend/libc/thread/mod.rs +++ b/vendor/rustix/src/backend/libc/thread/mod.rs @@ -1,2 +1,4 @@ +#[cfg(linux_kernel)] +pub(crate) mod futex; #[cfg(not(windows))] pub(crate) mod syscalls; diff --git a/vendor/rustix/src/backend/libc/thread/syscalls.rs b/vendor/rustix/src/backend/libc/thread/syscalls.rs index 5260c39f4..846f0e2a8 100644 --- a/vendor/rustix/src/backend/libc/thread/syscalls.rs +++ b/vendor/rustix/src/backend/libc/thread/syscalls.rs @@ -10,9 +10,10 @@ use crate::timespec::LibcTimespec; use core::mem::MaybeUninit; #[cfg(linux_kernel)] use { - crate::backend::conv::{borrowed_fd, ret_c_int}, + crate::backend::conv::{borrowed_fd, ret_c_int, ret_usize}, crate::fd::BorrowedFd, crate::pid::Pid, + crate::thread::{FutexFlags, FutexOperation}, crate::utils::as_mut_ptr, }; #[cfg(not(any( @@ -279,7 +280,7 @@ pub(crate) fn gettid() -> Pid { #[cfg(linux_kernel)] #[inline] -pub(crate) fn setns(fd: BorrowedFd, nstype: c::c_int) -> io::Result<c::c_int> { +pub(crate) fn setns(fd: BorrowedFd<'_>, nstype: c::c_int) -> io::Result<c::c_int> { // `setns` wasn't supported in glibc until 2.14, and musl until 0.9.5, // so use `syscall`. weak_or_syscall! { @@ -390,3 +391,120 @@ pub(crate) fn setresgid_thread( unsafe { ret(setresgid(rgid.as_raw(), egid.as_raw(), sgid.as_raw())) } } + +// TODO: This could be de-multiplexed. +#[cfg(linux_kernel)] +pub(crate) unsafe fn futex( + uaddr: *mut u32, + op: FutexOperation, + flags: FutexFlags, + val: u32, + utime: *const Timespec, + uaddr2: *mut u32, + val3: u32, +) -> io::Result<usize> { + #[cfg(all( + target_pointer_width = "32", + not(any(target_arch = "aarch64", target_arch = "x86_64")) + ))] + { + // TODO: Upstream this to the libc crate. + #[allow(non_upper_case_globals)] + const SYS_futex_time64: i32 = linux_raw_sys::general::__NR_futex_time64 as i32; + + syscall! { + fn futex_time64( + uaddr: *mut u32, + futex_op: c::c_int, + val: u32, + timeout: *const Timespec, + uaddr2: *mut u32, + val3: u32 + ) via SYS_futex_time64 -> c::ssize_t + } + + ret_usize(futex_time64( + uaddr, + op as i32 | flags.bits() as i32, + val, + utime, + uaddr2, + val3, + )) + .or_else(|err| { + // See the comments in `rustix_clock_gettime_via_syscall` about + // emulation. + if err == io::Errno::NOSYS { + futex_old(uaddr, op, flags, val, utime, uaddr2, val3) + } else { + Err(err) + } + }) + } + + #[cfg(any( + target_pointer_width = "64", + target_arch = "aarch64", + target_arch = "x86_64" + ))] + { + syscall! { + fn futex( + uaddr: *mut u32, + futex_op: c::c_int, + val: u32, + timeout: *const linux_raw_sys::general::__kernel_timespec, + uaddr2: *mut u32, + val3: u32 + ) via SYS_futex -> c::c_long + } + + ret_usize(futex( + uaddr, + op as i32 | flags.bits() as i32, + val, + utime.cast(), + uaddr2, + val3, + ) as isize) + } +} + +#[cfg(linux_kernel)] +#[cfg(all( + target_pointer_width = "32", + not(any(target_arch = "aarch64", target_arch = "x86_64")) +))] +unsafe fn futex_old( + uaddr: *mut u32, + op: FutexOperation, + flags: FutexFlags, + val: u32, + utime: *const Timespec, + uaddr2: *mut u32, + val3: u32, +) -> io::Result<usize> { + syscall! { + fn futex( + uaddr: *mut u32, + futex_op: c::c_int, + val: u32, + timeout: *const linux_raw_sys::general::__kernel_old_timespec, + uaddr2: *mut u32, + val3: u32 + ) via SYS_futex -> c::c_long + } + + let old_utime = linux_raw_sys::general::__kernel_old_timespec { + tv_sec: (*utime).tv_sec.try_into().map_err(|_| io::Errno::INVAL)?, + tv_nsec: (*utime).tv_nsec.try_into().map_err(|_| io::Errno::INVAL)?, + }; + ret_usize(futex( + uaddr, + op as i32 | flags.bits() as i32, + val, + &old_utime, + uaddr2, + val3, + ) as isize) +} diff --git a/vendor/rustix/src/backend/libc/time/syscalls.rs b/vendor/rustix/src/backend/libc/time/syscalls.rs index 603a3b108..6b1c9fd03 100644 --- a/vendor/rustix/src/backend/libc/time/syscalls.rs +++ b/vendor/rustix/src/backend/libc/time/syscalls.rs @@ -109,7 +109,7 @@ pub(crate) fn clock_gettime(id: ClockId) -> Timespec { clock_gettime_old(id) } - // Use `unwrap()` here because `clock_getres` can fail if the clock itself + // Use `.unwrap()` here because `clock_getres` can fail if the clock itself // overflows a number of seconds, but if that happens, the monotonic clocks // can't maintain their invariants, or the realtime clocks aren't properly // configured. diff --git a/vendor/rustix/src/backend/libc/time/types.rs b/vendor/rustix/src/backend/libc/time/types.rs index 75cc61217..4d8c6bdab 100644 --- a/vendor/rustix/src/backend/libc/time/types.rs +++ b/vendor/rustix/src/backend/libc/time/types.rs @@ -25,11 +25,12 @@ pub type Itimerspec = c::itimerspec; /// [`timerfd_settime`]: crate::time::timerfd_settime #[cfg(any(linux_kernel, target_os = "fuchsia"))] #[cfg(fix_y2038)] -#[allow(missing_docs)] #[repr(C)] #[derive(Debug, Clone)] pub struct Itimerspec { + /// The interval of an interval timer. pub it_interval: Timespec, + /// Time remaining in the current interval. pub it_value: Timespec, } @@ -86,6 +87,9 @@ bitflags! { /// `TFD_CLOEXEC` const CLOEXEC = bitcast!(c::TFD_CLOEXEC); + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -103,6 +107,9 @@ bitflags! { /// `TFD_TIMER_CANCEL_ON_SET` #[cfg(linux_kernel)] const CANCEL_ON_SET = bitcast!(c::TFD_TIMER_CANCEL_ON_SET); + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -116,10 +123,10 @@ bitflags! { pub enum TimerfdClockId { /// `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 - /// it is not monotonic. Successive reads may see decreasing times, so it - /// isn't reliable for measuring durations. + /// 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 it is + /// not monotonic. Successive reads may see decreasing times, so it isn't + /// reliable for measuring durations. Realtime = bitcast!(c::CLOCK_REALTIME), /// `CLOCK_MONOTONIC`—A clock that tells an abstract time. diff --git a/vendor/rustix/src/backend/linux_raw/arch/asm/aarch64.rs b/vendor/rustix/src/backend/linux_raw/arch/aarch64.rs index 0f4465d51..d4cf2472e 100644 --- a/vendor/rustix/src/backend/linux_raw/arch/asm/aarch64.rs +++ b/vendor/rustix/src/backend/linux_raw/arch/aarch64.rs @@ -53,7 +53,7 @@ pub(in crate::backend) unsafe fn syscall1_noreturn(nr: SyscallNumber<'_>, a0: Ar "svc 0", in("x8") nr.to_asm(), in("x0") a0.to_asm(), - options(noreturn) + options(nostack, noreturn) ) } diff --git a/vendor/rustix/src/backend/linux_raw/arch/asm/arm.rs b/vendor/rustix/src/backend/linux_raw/arch/arm.rs index 9695c6028..77c1f82f4 100644 --- a/vendor/rustix/src/backend/linux_raw/arch/asm/arm.rs +++ b/vendor/rustix/src/backend/linux_raw/arch/arm.rs @@ -50,7 +50,7 @@ pub(in crate::backend) unsafe fn syscall1_noreturn(nr: SyscallNumber<'_>, a0: Ar "svc 0", in("r7") nr.to_asm(), in("r0") a0.to_asm(), - options(noreturn) + options(nostack, noreturn) ) } diff --git a/vendor/rustix/src/backend/linux_raw/arch/asm/mod.rs b/vendor/rustix/src/backend/linux_raw/arch/asm/mod.rs deleted file mode 100644 index 3ea8eb74d..000000000 --- a/vendor/rustix/src/backend/linux_raw/arch/asm/mod.rs +++ /dev/null @@ -1,24 +0,0 @@ -//! Inline asm for making system calls. -//! -//! 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")] -#[cfg_attr(all(target_arch = "arm", thumb_mode), path = "thumb.rs")] -#[cfg_attr(target_arch = "mips", path = "mips.rs")] -#[cfg_attr(target_arch = "mips32r6", path = "mips32r6.rs")] -#[cfg_attr(target_arch = "mips64", path = "mips64.rs")] -#[cfg_attr(target_arch = "mips64r6", path = "mips64r6.rs")] -#[cfg_attr(target_arch = "powerpc64", path = "powerpc64.rs")] -#[cfg_attr(target_arch = "riscv64", path = "riscv64.rs")] -#[cfg_attr(target_arch = "x86", path = "x86.rs")] -#[cfg_attr(target_arch = "x86_64", path = "x86_64.rs")] -mod target_arch; - -pub(in crate::backend) use target_arch::*; diff --git a/vendor/rustix/src/backend/linux_raw/arch/asm/mips.rs b/vendor/rustix/src/backend/linux_raw/arch/mips.rs index b39a16847..37932e02b 100644 --- a/vendor/rustix/src/backend/linux_raw/arch/asm/mips.rs +++ b/vendor/rustix/src/backend/linux_raw/arch/mips.rs @@ -103,7 +103,7 @@ pub(in crate::backend) unsafe fn syscall1_noreturn(nr: SyscallNumber<'_>, a0: Ar "syscall", in("$2" /*$v0*/) nr.to_asm(), in("$4" /*$a0*/) a0.to_asm(), - options(noreturn) + options(nostack, noreturn) ) } diff --git a/vendor/rustix/src/backend/linux_raw/arch/asm/mips32r6.rs b/vendor/rustix/src/backend/linux_raw/arch/mips32r6.rs index 718e94fa7..c2d92447b 100644 --- a/vendor/rustix/src/backend/linux_raw/arch/asm/mips32r6.rs +++ b/vendor/rustix/src/backend/linux_raw/arch/mips32r6.rs @@ -103,7 +103,7 @@ pub(in crate::backend) unsafe fn syscall1_noreturn(nr: SyscallNumber<'_>, a0: Ar "syscall", in("$2" /*$v0*/) nr.to_asm(), in("$4" /*$a0*/) a0.to_asm(), - options(noreturn) + options(nostack, noreturn) ) } diff --git a/vendor/rustix/src/backend/linux_raw/arch/asm/mips64.rs b/vendor/rustix/src/backend/linux_raw/arch/mips64.rs index d3c7d341f..244daf3ef 100644 --- a/vendor/rustix/src/backend/linux_raw/arch/asm/mips64.rs +++ b/vendor/rustix/src/backend/linux_raw/arch/mips64.rs @@ -103,7 +103,7 @@ pub(in crate::backend) unsafe fn syscall1_noreturn(nr: SyscallNumber<'_>, a0: Ar "syscall", in("$2" /*$v0*/) nr.to_asm(), in("$4" /*$a0*/) a0.to_asm(), - options(noreturn) + options(nostack, noreturn) ) } diff --git a/vendor/rustix/src/backend/linux_raw/arch/asm/mips64r6.rs b/vendor/rustix/src/backend/linux_raw/arch/mips64r6.rs index 0a2ebebce..8c06d9ee9 100644 --- a/vendor/rustix/src/backend/linux_raw/arch/asm/mips64r6.rs +++ b/vendor/rustix/src/backend/linux_raw/arch/mips64r6.rs @@ -107,7 +107,7 @@ pub(in crate::backend) unsafe fn syscall1_noreturn(nr: SyscallNumber<'_>, a0: Ar "syscall", in("$2" /*$v0*/) nr.to_asm(), in("$4" /*$a0*/) a0.to_asm(), - options(noreturn) + options(nostack, noreturn) ) } diff --git a/vendor/rustix/src/backend/linux_raw/arch/mod.rs b/vendor/rustix/src/backend/linux_raw/arch/mod.rs index 31a8c11f9..ac9e25fa7 100644 --- a/vendor/rustix/src/backend/linux_raw/arch/mod.rs +++ b/vendor/rustix/src/backend/linux_raw/arch/mod.rs @@ -3,6 +3,14 @@ //! This module also has a `choose` submodule which chooses a scheme and is //! what most of the `rustix` syscalls use. //! +//! 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 +//! //! # Safety //! //! This contains the inline `asm` statements performing the syscall @@ -15,6 +23,17 @@ // These functions always use the machine's syscall instruction, even when it // isn't the fastest option available. +#[cfg_attr(target_arch = "aarch64", path = "aarch64.rs")] +#[cfg_attr(all(target_arch = "arm", not(thumb_mode)), path = "arm.rs")] +#[cfg_attr(all(target_arch = "arm", thumb_mode), path = "thumb.rs")] +#[cfg_attr(target_arch = "mips", path = "mips.rs")] +#[cfg_attr(target_arch = "mips32r6", path = "mips32r6.rs")] +#[cfg_attr(target_arch = "mips64", path = "mips64.rs")] +#[cfg_attr(target_arch = "mips64r6", path = "mips64r6.rs")] +#[cfg_attr(target_arch = "powerpc64", path = "powerpc64.rs")] +#[cfg_attr(target_arch = "riscv64", path = "riscv64.rs")] +#[cfg_attr(target_arch = "x86", path = "x86.rs")] +#[cfg_attr(target_arch = "x86_64", path = "x86_64.rs")] pub(in crate::backend) mod asm; // On most architectures, the architecture syscall instruction is fast, so use diff --git a/vendor/rustix/src/backend/linux_raw/arch/asm/powerpc64.rs b/vendor/rustix/src/backend/linux_raw/arch/powerpc64.rs index 8cca7dca7..14866c2dd 100644 --- a/vendor/rustix/src/backend/linux_raw/arch/asm/powerpc64.rs +++ b/vendor/rustix/src/backend/linux_raw/arch/powerpc64.rs @@ -15,7 +15,7 @@ use crate::backend::reg::{ use core::arch::asm; #[inline] -pub(in crate::backend) unsafe fn syscall0_readonly(nr: SyscallNumber) -> RetReg<R0> { +pub(in crate::backend) unsafe fn syscall0_readonly(nr: SyscallNumber<'_>) -> RetReg<R0> { let r0; asm!( "sc", @@ -98,7 +98,7 @@ pub(in crate::backend) unsafe fn syscall1_noreturn(nr: SyscallNumber<'_>, a0: Ar "sc", in("r0") nr.to_asm(), in("r3") a0.to_asm(), - options(noreturn) + options(nostack, noreturn) ) } diff --git a/vendor/rustix/src/backend/linux_raw/arch/asm/riscv64.rs b/vendor/rustix/src/backend/linux_raw/arch/riscv64.rs index b1e306266..7b8533d75 100644 --- a/vendor/rustix/src/backend/linux_raw/arch/asm/riscv64.rs +++ b/vendor/rustix/src/backend/linux_raw/arch/riscv64.rs @@ -50,7 +50,7 @@ pub(in crate::backend) unsafe fn syscall1_noreturn(nr: SyscallNumber<'_>, a0: Ar "ecall", in("a7") nr.to_asm(), in("a0") a0.to_asm(), - options(noreturn) + options(nostack, noreturn) ); } diff --git a/vendor/rustix/src/backend/linux_raw/arch/asm/thumb.rs b/vendor/rustix/src/backend/linux_raw/arch/thumb.rs index 398a73dfe..73f9c1c26 100644 --- a/vendor/rustix/src/backend/linux_raw/arch/asm/thumb.rs +++ b/vendor/rustix/src/backend/linux_raw/arch/thumb.rs @@ -67,7 +67,7 @@ pub(in crate::backend) unsafe fn syscall1_noreturn(nr: SyscallNumber<'_>, a0: Ar "svc 0", nr = in(reg) nr.to_asm(), in("r0") a0.to_asm(), - options(noreturn) + options(nostack, noreturn) ) } diff --git a/vendor/rustix/src/backend/linux_raw/arch/asm/x86.rs b/vendor/rustix/src/backend/linux_raw/arch/x86.rs index ddef4a854..581cde278 100644 --- a/vendor/rustix/src/backend/linux_raw/arch/asm/x86.rs +++ b/vendor/rustix/src/backend/linux_raw/arch/x86.rs @@ -144,8 +144,8 @@ pub(in crate::backend) unsafe fn indirect_syscall5( let r0; // Oof. a3 should go in esi, and `asm!` won't let us use that register as // an operand. And we can't request stack slots. And there are no other - // registers free. Use eax as a temporary pointer to a slice, since it - // gets clobbered as the return value anyway. + // registers free. Use eax as a temporary pointer to a slice, since it gets + // clobbered as the return value anyway. asm!( "push esi", "push DWORD PTR [eax + 0]", @@ -163,7 +163,6 @@ pub(in crate::backend) unsafe fn indirect_syscall5( FromAsm::from_asm(r0) } -#[allow(clippy::too_many_arguments)] #[inline] pub(in crate::backend) unsafe fn indirect_syscall6( callee: SyscallType, @@ -248,7 +247,7 @@ pub(in crate::backend) unsafe fn syscall1_noreturn(nr: SyscallNumber<'_>, a0: Ar "int $$0x80", in("eax") nr.to_asm(), in("ebx") a0.to_asm(), - options(noreturn) + options(nostack, noreturn) ) } diff --git a/vendor/rustix/src/backend/linux_raw/arch/asm/x86_64.rs b/vendor/rustix/src/backend/linux_raw/arch/x86_64.rs index 084f5fee4..62f35d90f 100644 --- a/vendor/rustix/src/backend/linux_raw/arch/asm/x86_64.rs +++ b/vendor/rustix/src/backend/linux_raw/arch/x86_64.rs @@ -58,7 +58,7 @@ pub(in crate::backend) unsafe fn syscall1_noreturn(nr: SyscallNumber<'_>, a0: Ar "syscall", in("rax") nr.to_asm(), in("rdi") a0.to_asm(), - options(noreturn) + options(nostack, noreturn) ) } diff --git a/vendor/rustix/src/backend/linux_raw/c.rs b/vendor/rustix/src/backend/linux_raw/c.rs index f336392bb..65ddb1466 100644 --- a/vendor/rustix/src/backend/linux_raw/c.rs +++ b/vendor/rustix/src/backend/linux_raw/c.rs @@ -9,6 +9,7 @@ pub type size_t = usize; pub(crate) use linux_raw_sys::ctypes::*; pub(crate) use linux_raw_sys::errno::EINVAL; +pub(crate) use linux_raw_sys::ioctl::{FIONBIO, FIONREAD}; // Import the kernel's `uid_t` and `gid_t` if they're 32-bit. #[cfg(not(any(target_arch = "arm", target_arch = "sparc", target_arch = "x86")))] pub(crate) use linux_raw_sys::general::{__kernel_gid_t as gid_t, __kernel_uid_t as uid_t}; @@ -25,7 +26,7 @@ pub(crate) use linux_raw_sys::general::epoll_event; feature = "fs", all( not(feature = "use-libc-auxv"), - not(target_vendor = "mustang"), + not(feature = "use-explicitly-provided-auxv"), any( feature = "param", feature = "runtime", @@ -39,6 +40,8 @@ pub(crate) use linux_raw_sys::general::{ XATTR_REPLACE, }; +pub(crate) use linux_raw_sys::ioctl::{BLKPBSZGET, BLKSSZGET, FICLONE}; + #[cfg(feature = "io_uring")] pub(crate) use linux_raw_sys::{general::open_how, io_uring::*}; @@ -65,10 +68,10 @@ pub(crate) use linux_raw_sys::{ 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, SCM_CREDENTIALS, SCM_RIGHTS, 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_NEW as SO_RCVTIMEO, SO_RCVTIMEO_OLD, - SO_REUSEADDR, SO_SNDBUF, SO_SNDTIMEO_NEW, SO_SNDTIMEO_NEW as SO_SNDTIMEO, SO_SNDTIMEO_OLD, - SO_TYPE, TCP_NODELAY, + SOCK_SEQPACKET, SOCK_STREAM, SOL_SOCKET, SO_BROADCAST, SO_DOMAIN, SO_ERROR, SO_KEEPALIVE, + SO_LINGER, SO_PASSCRED, SO_RCVBUF, SO_RCVTIMEO_NEW, SO_RCVTIMEO_NEW as SO_RCVTIMEO, + SO_RCVTIMEO_OLD, SO_REUSEADDR, SO_SNDBUF, SO_SNDTIMEO_NEW, SO_SNDTIMEO_NEW as SO_SNDTIMEO, + SO_SNDTIMEO_OLD, SO_TYPE, TCP_NODELAY, }, netlink::*, }; @@ -76,12 +79,25 @@ pub(crate) use linux_raw_sys::{ #[cfg(any(feature = "process", feature = "runtime"))] pub(crate) use linux_raw_sys::general::siginfo_t; +#[cfg(any(feature = "process", feature = "runtime"))] +pub(crate) const EXIT_SUCCESS: c_int = 0; +#[cfg(any(feature = "process", feature = "runtime"))] +pub(crate) const EXIT_FAILURE: c_int = 1; #[cfg(feature = "process")] -pub(crate) use linux_raw_sys::general::{ - CLD_CONTINUED, CLD_DUMPED, CLD_EXITED, CLD_KILLED, CLD_STOPPED, CLD_TRAPPED, - O_NONBLOCK as PIDFD_NONBLOCK, P_ALL, P_PID, P_PIDFD, +pub(crate) const EXIT_SIGNALED_SIGABRT: c_int = 128 + linux_raw_sys::general::SIGABRT as c_int; + +#[cfg(feature = "process")] +pub(crate) use linux_raw_sys::{ + general::{ + CLD_CONTINUED, CLD_DUMPED, CLD_EXITED, CLD_KILLED, CLD_STOPPED, CLD_TRAPPED, + O_NONBLOCK as PIDFD_NONBLOCK, P_ALL, P_PID, P_PIDFD, + }, + ioctl::TIOCSCTTY, }; +#[cfg(feature = "pty")] +pub(crate) use linux_raw_sys::ioctl::TIOCGPTPEER; + #[cfg(feature = "termios")] pub(crate) use linux_raw_sys::{ general::{ @@ -99,7 +115,7 @@ pub(crate) use linux_raw_sys::{ VKILL, VLNEXT, VMIN, VQUIT, VREPRINT, VSTART, VSTOP, VSUSP, VSWTC, VT0, VT1, VTDLY, VTIME, VWERASE, XCASE, XTABS, }, - ioctl::{TCGETS2, TCSETS2, TCSETSF2, TCSETSW2}, + ioctl::{TCGETS2, TCSETS2, TCSETSF2, TCSETSW2, TIOCEXCL, TIOCNXCL}, }; // On MIPS, `TCSANOW` et al have `TCSETS` added to them, so we need it to diff --git a/vendor/rustix/src/backend/linux_raw/conv.rs b/vendor/rustix/src/backend/linux_raw/conv.rs index c87136f8f..f915db140 100644 --- a/vendor/rustix/src/backend/linux_raw/conv.rs +++ b/vendor/rustix/src/backend/linux_raw/conv.rs @@ -186,45 +186,45 @@ pub(super) fn no_fd<'a, Num: ArgNumber>() -> ArgReg<'a, Num> { } #[inline] -pub(super) fn slice_just_addr<T: Sized, Num: ArgNumber>(v: &[T]) -> ArgReg<Num> { +pub(super) fn slice_just_addr<T: Sized, Num: ArgNumber>(v: &[T]) -> ArgReg<'_, Num> { let mut_ptr = v.as_ptr() as *mut T; raw_arg(mut_ptr.cast()) } #[inline] -pub(super) fn slice_just_addr_mut<T: Sized, Num: ArgNumber>(v: &mut [T]) -> ArgReg<Num> { +pub(super) fn slice_just_addr_mut<T: Sized, Num: ArgNumber>(v: &mut [T]) -> ArgReg<'_, Num> { raw_arg(v.as_mut_ptr().cast()) } #[inline] pub(super) fn slice<T: Sized, Num0: ArgNumber, Num1: ArgNumber>( v: &[T], -) -> (ArgReg<Num0>, ArgReg<Num1>) { +) -> (ArgReg<'_, Num0>, ArgReg<'_, Num1>) { (slice_just_addr(v), pass_usize(v.len())) } #[inline] pub(super) fn slice_mut<T: Sized, Num0: ArgNumber, Num1: ArgNumber>( v: &mut [T], -) -> (ArgReg<Num0>, ArgReg<Num1>) { +) -> (ArgReg<'_, Num0>, ArgReg<'_, Num1>) { (raw_arg(v.as_mut_ptr().cast()), pass_usize(v.len())) } #[inline] -pub(super) fn by_ref<T: Sized, Num: ArgNumber>(t: &T) -> ArgReg<Num> { +pub(super) fn by_ref<T: Sized, Num: ArgNumber>(t: &T) -> ArgReg<'_, Num> { let mut_ptr = as_ptr(t) as *mut T; raw_arg(mut_ptr.cast()) } #[inline] -pub(super) fn by_mut<T: Sized, Num: ArgNumber>(t: &mut T) -> ArgReg<Num> { +pub(super) fn by_mut<T: Sized, Num: ArgNumber>(t: &mut T) -> ArgReg<'_, Num> { raw_arg(as_mut_ptr(t).cast()) } /// Convert an optional mutable reference into a `usize` for passing to a /// syscall. #[inline] -pub(super) fn opt_mut<T: Sized, Num: ArgNumber>(t: Option<&mut T>) -> ArgReg<Num> { +pub(super) fn opt_mut<T: Sized, Num: ArgNumber>(t: Option<&mut T>) -> ArgReg<'_, Num> { // This optimizes into the equivalent of `transmute(t)`, and has the // advantage of not requiring `unsafe`. match t { @@ -237,7 +237,7 @@ pub(super) fn opt_mut<T: Sized, Num: ArgNumber>(t: Option<&mut T>) -> ArgReg<Num /// syscall. #[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))] #[inline] -pub(super) fn opt_ref<T: Sized, Num: ArgNumber>(t: Option<&T>) -> ArgReg<Num> { +pub(super) fn opt_ref<T: Sized, Num: ArgNumber>(t: Option<&T>) -> ArgReg<'_, Num> { // This optimizes into the equivalent of `transmute(t)`, and has the // advantage of not requiring `unsafe`. match t { @@ -300,7 +300,7 @@ pub(super) fn socklen_t<'a, Num: ArgNumber>(i: socklen_t) -> ArgReg<'a, Num> { feature = "fs", all( not(feature = "use-libc-auxv"), - not(target_vendor = "mustang"), + not(feature = "use-explicitly-provided-auxv"), any( feature = "param", feature = "runtime", @@ -581,7 +581,7 @@ impl<'a, Num: ArgNumber> From<crate::event::EventfdFlags> for ArgReg<'a, Num> { } } -#[cfg(feature = "event")] +#[cfg(all(feature = "alloc", feature = "event"))] impl<'a, Num: ArgNumber> From<crate::event::epoll::CreateFlags> for ArgReg<'a, Num> { #[inline] fn from(flags: crate::event::epoll::CreateFlags) -> Self { diff --git a/vendor/rustix/src/backend/linux_raw/elf.rs b/vendor/rustix/src/backend/linux_raw/elf.rs deleted file mode 100644 index 415f79f88..000000000 --- a/vendor/rustix/src/backend/linux_raw/elf.rs +++ /dev/null @@ -1,181 +0,0 @@ -//! The ELF ABI. 🧝 - -#![allow(non_snake_case)] -#![cfg_attr( - all(not(target_vendor = "mustang"), feature = "use-libc-auxv"), - allow(dead_code) -)] - -pub(super) const SELFMAG: usize = 4; -pub(super) const ELFMAG: [u8; SELFMAG] = [0x7f, b'E', b'L', b'F']; -pub(super) const EI_CLASS: usize = 4; -pub(super) const EI_DATA: usize = 5; -pub(super) const EI_VERSION: usize = 6; -pub(super) const EI_OSABI: usize = 7; -pub(super) const EI_ABIVERSION: usize = 8; -pub(super) const EV_CURRENT: u8 = 1; -#[cfg(target_pointer_width = "32")] -pub(super) const ELFCLASS: u8 = 1; // ELFCLASS32 -#[cfg(target_pointer_width = "64")] -pub(super) const ELFCLASS: u8 = 2; // ELFCLASS64 -#[cfg(target_endian = "little")] -pub(super) const ELFDATA: u8 = 1; // ELFDATA2LSB -#[cfg(target_endian = "big")] -pub(super) const ELFDATA: u8 = 2; // ELFDATA2MSB -pub(super) const ELFOSABI_SYSV: u8 = 0; -pub(super) const ELFOSABI_LINUX: u8 = 3; -// At present all of our supported platforms use 0. -pub(super) const ELFABIVERSION: u8 = 0; -pub(super) const ET_DYN: u16 = 3; -pub(super) const EI_NIDENT: usize = 16; -pub(super) const SHN_UNDEF: u16 = 0; -pub(super) const SHN_ABS: u16 = 0xfff1; -pub(super) const PN_XNUM: u16 = 0xffff; -pub(super) const PT_LOAD: u32 = 1; -pub(super) const PT_DYNAMIC: u32 = 2; -pub(super) const PT_INTERP: u32 = 3; -pub(super) const PT_PHDR: u32 = 6; -pub(super) const PT_TLS: u32 = 7; -pub(super) const PT_GNU_STACK: u32 = 0x6474_e551; -pub(super) const PT_GNU_RELRO: u32 = 0x6474_e552; -pub(super) const PF_X: u32 = 1; -pub(super) const PF_W: u32 = 2; -pub(super) const PF_R: u32 = 4; -pub(super) const DT_NULL: i32 = 0; -pub(super) const DT_HASH: i32 = 4; -pub(super) const DT_STRTAB: i32 = 5; -pub(super) const DT_SYMTAB: i32 = 6; -pub(super) const DT_SYMENT: i32 = 11; -pub(super) const DT_VERSYM: i32 = 0x6fff_fff0; -pub(super) const DT_VERDEF: i32 = 0x6fff_fffc; -pub(super) const STB_WEAK: u8 = 2; -pub(super) const STB_GLOBAL: u8 = 1; -pub(super) const STT_NOTYPE: u8 = 0; -pub(super) const STT_FUNC: u8 = 2; -pub(super) const STN_UNDEF: u32 = 0; -pub(super) const VER_FLG_BASE: u16 = 0x1; -pub(super) const VER_DEF_CURRENT: u16 = 1; -pub(super) const STV_DEFAULT: u8 = 0; -#[cfg(target_arch = "arm")] -pub(super) const EM_CURRENT: u16 = 40; // EM_ARM -#[cfg(target_arch = "x86")] -pub(super) const EM_CURRENT: u16 = 3; // EM_386 -#[cfg(target_arch = "powerpc64")] -pub(super) const EM_CURRENT: u16 = 21; // EM_PPC64 -#[cfg(any( - target_arch = "mips", - target_arch = "mips32r6", - target_arch = "mips64", - target_arch = "mips64r6" -))] -pub(super) const EM_CURRENT: u16 = 8; // EM_MIPS -#[cfg(target_arch = "x86_64")] -pub(super) const EM_CURRENT: u16 = 62; // EM_X86_64 -#[cfg(target_arch = "aarch64")] -pub(super) const EM_CURRENT: u16 = 183; // EM_AARCH64 -#[cfg(target_arch = "riscv64")] -pub(super) const EM_CURRENT: u16 = 243; // EM_RISCV - -#[inline] -pub(super) const fn ELF_ST_VISIBILITY(o: u8) -> u8 { - o & 0x03 -} - -#[inline] -pub(super) const fn ELF_ST_BIND(val: u8) -> u8 { - val >> 4 -} - -#[inline] -pub(super) const fn ELF_ST_TYPE(val: u8) -> u8 { - val & 0xf -} - -#[repr(C)] -pub(super) struct Elf_Ehdr { - pub(super) e_ident: [u8; EI_NIDENT], - pub(super) e_type: u16, - pub(super) e_machine: u16, - pub(super) e_version: u32, - pub(super) e_entry: usize, - pub(super) e_phoff: usize, - pub(super) e_shoff: usize, - pub(super) e_flags: u32, - pub(super) e_ehsize: u16, - pub(super) e_phentsize: u16, - pub(super) e_phnum: u16, - pub(super) e_shentsize: u16, - pub(super) e_shnum: u16, - pub(super) e_shstrndx: u16, -} - -#[cfg(target_pointer_width = "32")] -#[repr(C)] -pub(super) struct Elf_Phdr { - pub(super) p_type: u32, - pub(super) p_offset: usize, - pub(super) p_vaddr: usize, - pub(super) p_paddr: usize, - pub(super) p_filesz: usize, - pub(super) p_memsz: usize, - pub(super) p_flags: u32, - pub(super) p_align: usize, -} - -#[cfg(target_pointer_width = "64")] -#[repr(C)] -pub(super) struct Elf_Phdr { - pub(super) p_type: u32, - pub(super) p_flags: u32, - pub(super) p_offset: usize, - pub(super) p_vaddr: usize, - pub(super) p_paddr: usize, - pub(super) p_filesz: usize, - pub(super) p_memsz: usize, - pub(super) p_align: usize, -} - -#[cfg(target_pointer_width = "32")] -#[repr(C)] -pub(super) struct Elf_Sym { - pub(super) st_name: u32, - pub(super) st_value: usize, - pub(super) st_size: usize, - pub(super) st_info: u8, - pub(super) st_other: u8, - pub(super) st_shndx: u16, -} - -#[cfg(target_pointer_width = "64")] -#[repr(C)] -pub(super) struct Elf_Sym { - pub(super) st_name: u32, - pub(super) st_info: u8, - pub(super) st_other: u8, - pub(super) st_shndx: u16, - pub(super) st_value: usize, - pub(super) st_size: usize, -} - -#[repr(C)] -pub(super) struct Elf_Dyn { - pub(super) d_tag: i32, - pub(super) d_val: usize, -} - -#[repr(C)] -pub(super) struct Elf_Verdef { - pub(super) vd_version: u16, - pub(super) vd_flags: u16, - pub(super) vd_ndx: u16, - pub(super) vd_cnt: u16, - pub(super) vd_hash: u32, - pub(super) vd_aux: u32, - pub(super) vd_next: u32, -} - -#[repr(C)] -pub(super) struct Elf_Verdaux { - pub(super) vda_name: u32, - pub(super) _vda_next: u32, -} diff --git a/vendor/rustix/src/backend/linux_raw/event/epoll.rs b/vendor/rustix/src/backend/linux_raw/event/epoll.rs index 6577feb51..ecd48b784 100644 --- a/vendor/rustix/src/backend/linux_raw/event/epoll.rs +++ b/vendor/rustix/src/backend/linux_raw/event/epoll.rs @@ -92,6 +92,9 @@ bitflags! { pub struct CreateFlags: c::c_uint { /// `EPOLL_CLOEXEC` const CLOEXEC = linux_raw_sys::general::EPOLL_CLOEXEC; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -144,6 +147,9 @@ bitflags! { /// `EPOLLEXCLUSIVE` const EXCLUSIVE = linux_raw_sys::general::EPOLLEXCLUSIVE as u32; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -160,8 +166,8 @@ pub fn create(flags: CreateFlags) -> io::Result<OwnedFd> { /// `epoll_ctl(self, EPOLL_CTL_ADD, data, event)`—Adds an element to an /// epoll object. /// -/// This registers interest in any of the events set in `events` occurring -/// on the file descriptor associated with `data`. +/// This registers interest in any of the events set in `events` occurring on +/// the file descriptor associated with `data`. /// /// If [`delete`] is not called on the I/O source passed into this function /// before the I/O source is `close`d, then the `epoll` will act as if the I/O @@ -191,8 +197,8 @@ pub fn add( } } -/// `epoll_ctl(self, EPOLL_CTL_MOD, target, event)`—Modifies an element in -/// a given epoll object. +/// `epoll_ctl(self, EPOLL_CTL_MOD, target, event)`—Modifies an element in a +/// given epoll object. /// /// This sets the events of interest with `target` to `events`. #[doc(alias = "epoll_ctl")] @@ -218,8 +224,8 @@ pub fn modify( } } -/// `epoll_ctl(self, EPOLL_CTL_DEL, target, NULL)`—Removes an element in -/// a given epoll object. +/// `epoll_ctl(self, EPOLL_CTL_DEL, target, NULL)`—Removes an element in a +/// given epoll object. #[doc(alias = "epoll_ctl")] #[inline] pub fn delete(epoll: impl AsFd, source: impl AsFd) -> io::Result<()> { @@ -317,8 +323,8 @@ impl EventData { /// Return the value as a `u64`. /// - /// If the stored value was a pointer, the pointer is zero-extended to - /// a `u64`. + /// If the stored value was a pointer, the pointer is zero-extended to a + /// `u64`. #[inline] pub fn u64(self) -> u64 { unsafe { self.as_u64 } diff --git a/vendor/rustix/src/backend/linux_raw/event/mod.rs b/vendor/rustix/src/backend/linux_raw/event/mod.rs index 605de2538..4148a8c7f 100644 --- a/vendor/rustix/src/backend/linux_raw/event/mod.rs +++ b/vendor/rustix/src/backend/linux_raw/event/mod.rs @@ -1,3 +1,4 @@ +#[cfg(feature = "alloc")] pub mod epoll; pub(crate) mod poll_fd; pub(crate) mod syscalls; diff --git a/vendor/rustix/src/backend/linux_raw/event/poll_fd.rs b/vendor/rustix/src/backend/linux_raw/event/poll_fd.rs index 906efe0ef..c56c9152d 100644 --- a/vendor/rustix/src/backend/linux_raw/event/poll_fd.rs +++ b/vendor/rustix/src/backend/linux_raw/event/poll_fd.rs @@ -30,6 +30,9 @@ bitflags! { const NVAL = linux_raw_sys::general::POLLNVAL as u16; /// `POLLRDHUP` const RDHUP = linux_raw_sys::general::POLLRDHUP as u16; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -81,7 +84,7 @@ impl<'fd> PollFd<'fd> { /// Returns the ready events. #[inline] pub fn revents(&self) -> PollFlags { - // Use `unwrap()` here because in theory we know we know all the bits + // Use `.unwrap()` here because in theory we know we know all the bits // the OS might set here, but OS's have added extensions in the past. PollFlags::from_bits(self.revents).unwrap() } diff --git a/vendor/rustix/src/backend/linux_raw/event/syscalls.rs b/vendor/rustix/src/backend/linux_raw/event/syscalls.rs index 6d6b35d75..a8003b004 100644 --- a/vendor/rustix/src/backend/linux_raw/event/syscalls.rs +++ b/vendor/rustix/src/backend/linux_raw/event/syscalls.rs @@ -3,17 +3,20 @@ //! # Safety //! //! See the `rustix::backend` module documentation for details. -#![allow(unsafe_code)] -#![allow(clippy::undocumented_unsafe_blocks)] +#![allow(unsafe_code, clippy::undocumented_unsafe_blocks)] use crate::backend::c; -use crate::backend::conv::{ - by_ref, c_int, c_uint, pass_usize, raw_fd, ret, ret_owned_fd, ret_usize, slice_mut, zero, -}; -use crate::event::{epoll, EventfdFlags, PollFd}; -use crate::fd::{BorrowedFd, OwnedFd}; +use crate::backend::conv::{c_int, c_uint, ret_owned_fd, ret_usize, slice_mut}; +use crate::event::{EventfdFlags, PollFd}; +use crate::fd::OwnedFd; use crate::io; -use linux_raw_sys::general::{EPOLL_CTL_ADD, EPOLL_CTL_DEL, EPOLL_CTL_MOD}; +#[cfg(feature = "alloc")] +use { + crate::backend::conv::{by_ref, pass_usize, raw_fd, ret, zero}, + crate::event::epoll, + crate::fd::BorrowedFd, + linux_raw_sys::general::{EPOLL_CTL_ADD, EPOLL_CTL_DEL, EPOLL_CTL_MOD}, +}; #[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))] use { crate::backend::conv::{opt_ref, size_of}, @@ -49,11 +52,13 @@ pub(crate) fn poll(fds: &mut [PollFd<'_>], timeout: c::c_int) -> io::Result<usiz } } +#[cfg(feature = "alloc")] #[inline] pub(crate) fn epoll_create(flags: epoll::CreateFlags) -> io::Result<OwnedFd> { unsafe { ret_owned_fd(syscall_readonly!(__NR_epoll_create1, flags)) } } +#[cfg(feature = "alloc")] #[inline] pub(crate) unsafe fn epoll_add( epfd: BorrowedFd<'_>, @@ -69,6 +74,7 @@ pub(crate) unsafe fn epoll_add( )) } +#[cfg(feature = "alloc")] #[inline] pub(crate) unsafe fn epoll_mod( epfd: BorrowedFd<'_>, @@ -84,6 +90,7 @@ pub(crate) unsafe fn epoll_mod( )) } +#[cfg(feature = "alloc")] #[inline] pub(crate) unsafe fn epoll_del(epfd: BorrowedFd<'_>, fd: c::c_int) -> io::Result<()> { ret(syscall_readonly!( @@ -95,6 +102,7 @@ pub(crate) unsafe fn epoll_del(epfd: BorrowedFd<'_>, fd: c::c_int) -> io::Result )) } +#[cfg(feature = "alloc")] #[inline] pub(crate) fn epoll_wait( epfd: BorrowedFd<'_>, diff --git a/vendor/rustix/src/backend/linux_raw/event/types.rs b/vendor/rustix/src/backend/linux_raw/event/types.rs index e6273959c..3821f8f64 100644 --- a/vendor/rustix/src/backend/linux_raw/event/types.rs +++ b/vendor/rustix/src/backend/linux_raw/event/types.rs @@ -14,5 +14,8 @@ bitflags! { const NONBLOCK = linux_raw_sys::general::EFD_NONBLOCK; /// `EFD_SEMAPHORE` const SEMAPHORE = linux_raw_sys::general::EFD_SEMAPHORE; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } diff --git a/vendor/rustix/src/backend/linux_raw/fs/inotify.rs b/vendor/rustix/src/backend/linux_raw/fs/inotify.rs index cb9d87b82..ef205ffdf 100644 --- a/vendor/rustix/src/backend/linux_raw/fs/inotify.rs +++ b/vendor/rustix/src/backend/linux_raw/fs/inotify.rs @@ -17,6 +17,9 @@ bitflags! { const CLOEXEC = linux_raw_sys::general::IN_CLOEXEC; /// `IN_NONBLOCK` const NONBLOCK = linux_raw_sys::general::IN_NONBLOCK; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -71,6 +74,9 @@ bitflags! { const ONESHOT = linux_raw_sys::general::IN_ONESHOT; /// `IN_ONLYDIR` const ONLYDIR = linux_raw_sys::general::IN_ONLYDIR; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -99,14 +105,13 @@ pub fn inotify_add_watch<P: crate::path::Arg>( path: P, flags: WatchFlags, ) -> io::Result<i32> { - let path = path.as_cow_c_str().unwrap(); - syscalls::inotify_add_watch(inot, &path, flags) + path.into_with_c_str(|path| syscalls::inotify_add_watch(inot, path, flags)) } /// `inotify_rm_watch(self, wd)`—Removes a watch from this inotify /// -/// The watch descriptor provided should have previously been returned -/// by [`inotify_add_watch`] and not previously have been removed. +/// The watch descriptor provided should have previously been returned by +/// [`inotify_add_watch`] and not previously have been removed. #[doc(alias = "inotify_rm_watch")] #[inline] pub fn inotify_remove_watch(inot: BorrowedFd<'_>, wd: i32) -> io::Result<()> { diff --git a/vendor/rustix/src/backend/linux_raw/fs/mod.rs b/vendor/rustix/src/backend/linux_raw/fs/mod.rs index acf43ce4f..ba72c5b6d 100644 --- a/vendor/rustix/src/backend/linux_raw/fs/mod.rs +++ b/vendor/rustix/src/backend/linux_raw/fs/mod.rs @@ -1,5 +1,13 @@ +#[cfg(feature = "alloc")] pub(crate) mod dir; pub mod inotify; pub(crate) mod makedev; pub(crate) mod syscalls; pub(crate) mod types; + +// TODO: Fix linux-raw-sys to define ioctl codes for sparc. +#[cfg(all(linux_kernel, any(target_arch = "sparc", target_arch = "sparc64")))] +pub(crate) const EXT4_IOC_RESIZE_FS: u32 = 0x8008_6610; + +#[cfg(all(linux_kernel, not(any(target_arch = "sparc", target_arch = "sparc64"))))] +pub(crate) use linux_raw_sys::ioctl::EXT4_IOC_RESIZE_FS; diff --git a/vendor/rustix/src/backend/linux_raw/fs/syscalls.rs b/vendor/rustix/src/backend/linux_raw/fs/syscalls.rs index b3d4cd66c..e72afb8ab 100644 --- a/vendor/rustix/src/backend/linux_raw/fs/syscalls.rs +++ b/vendor/rustix/src/backend/linux_raw/fs/syscalls.rs @@ -32,15 +32,14 @@ use crate::fs::{ StatVfsMountFlags, StatxFlags, Timestamps, Uid, XattrFlags, }; use crate::io; -use core::mem::{transmute, zeroed, MaybeUninit}; +use core::mem::MaybeUninit; #[cfg(any(target_arch = "mips64", target_arch = "mips64r6"))] use linux_raw_sys::general::stat as linux_stat64; use linux_raw_sys::general::{ - __kernel_fsid_t, __kernel_timespec, open_how, statx, AT_EACCESS, AT_FDCWD, AT_REMOVEDIR, - AT_SYMLINK_NOFOLLOW, F_ADD_SEALS, F_GETFL, F_GET_SEALS, F_SETFL, SEEK_CUR, SEEK_DATA, SEEK_END, - SEEK_HOLE, SEEK_SET, STATX__RESERVED, + __kernel_fsid_t, open_how, statx, AT_EACCESS, AT_FDCWD, AT_REMOVEDIR, AT_SYMLINK_NOFOLLOW, + F_ADD_SEALS, F_GETFL, F_GET_SEALS, F_SETFL, SEEK_CUR, SEEK_DATA, SEEK_END, SEEK_HOLE, SEEK_SET, + STATX__RESERVED, }; -use linux_raw_sys::ioctl::{BLKPBSZGET, BLKSSZGET, EXT4_IOC_RESIZE_FS, FICLONE}; #[cfg(target_pointer_width = "32")] use { crate::backend::conv::{hi, lo, slice_just_addr}, @@ -160,6 +159,30 @@ pub(crate) fn chownat( } #[inline] +pub(crate) fn chown(path: &CStr, owner: Option<Uid>, group: Option<Gid>) -> io::Result<()> { + // Most architectures have a `chown` syscall. + #[cfg(not(any(target_arch = "aarch64", target_arch = "riscv64")))] + unsafe { + let (ow, gr) = crate::ugid::translate_fchown_args(owner, group); + ret(syscall_readonly!(__NR_chown, path, c_uint(ow), c_uint(gr))) + } + + // Aarch64 and RISC-V don't, so use `fchownat`. + #[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))] + unsafe { + let (ow, gr) = crate::ugid::translate_fchown_args(owner, group); + ret(syscall_readonly!( + __NR_fchownat, + raw_fd(AT_FDCWD), + path, + c_uint(ow), + c_uint(gr), + zero() + )) + } +} + +#[inline] pub(crate) fn fchown(fd: BorrowedFd<'_>, owner: Option<Uid>, group: Option<Gid>) -> io::Result<()> { unsafe { let (ow, gr) = crate::ugid::translate_fchown_args(owner, group); @@ -207,9 +230,7 @@ pub(crate) fn seek(fd: BorrowedFd<'_>, pos: SeekFrom) -> io::Result<u64> { } SeekFrom::End(offset) => (SEEK_END, offset), SeekFrom::Current(offset) => (SEEK_CUR, offset), - #[cfg(target_os = "linux")] SeekFrom::Data(offset) => (SEEK_DATA, offset), - #[cfg(target_os = "linux")] SeekFrom::Hole(offset) => (SEEK_HOLE, offset), }; _seek(fd, offset, whence) @@ -915,6 +936,7 @@ fn statfs_to_statvfs(statfs: StatFs) -> StatVfs { } } +#[cfg(feature = "alloc")] #[inline] pub(crate) fn readlink(path: &CStr, buf: &mut [u8]) -> io::Result<usize> { let (buf_addr_mut, buf_len) = slice_mut(buf); @@ -929,6 +951,7 @@ pub(crate) fn readlink(path: &CStr, buf: &mut [u8]) -> io::Result<usize> { } } +#[cfg(feature = "alloc")] #[inline] pub(crate) fn readlinkat( dirfd: BorrowedFd<'_>, @@ -1028,38 +1051,37 @@ pub(crate) fn fcntl_lock(fd: BorrowedFd<'_>, operation: FlockOperation) -> io::R FlockOperation::NonBlockingUnlock => (F_SETLK, F_UNLCK), }; - unsafe { - let lock = flock { - l_type: l_type as _, + let lock = flock { + l_type: l_type as _, - // When `l_len` is zero, this locks all the bytes from - // `l_whence`/`l_start` to the end of the file, even as the - // file grows dynamically. - l_whence: SEEK_SET as _, - l_start: 0, - l_len: 0, + // When `l_len` is zero, this locks all the bytes from + // `l_whence`/`l_start` to the end of the file, even as the + // file grows dynamically. + l_whence: SEEK_SET as _, + l_start: 0, + l_len: 0, - ..zeroed() - }; + // Unused. + l_pid: 0, + }; - #[cfg(target_pointer_width = "32")] - { - ret(syscall_readonly!( - __NR_fcntl64, - fd, - c_uint(cmd), - by_ref(&lock) - )) - } - #[cfg(target_pointer_width = "64")] - { - ret(syscall_readonly!( - __NR_fcntl, - fd, - c_uint(cmd), - by_ref(&lock) - )) - } + #[cfg(target_pointer_width = "32")] + unsafe { + ret(syscall_readonly!( + __NR_fcntl64, + fd, + c_uint(cmd), + by_ref(&lock) + )) + } + #[cfg(target_pointer_width = "64")] + unsafe { + ret(syscall_readonly!( + __NR_fcntl, + fd, + c_uint(cmd), + by_ref(&lock) + )) } } @@ -1235,6 +1257,7 @@ pub(crate) fn mkdirat(dirfd: BorrowedFd<'_>, path: &CStr, mode: Mode) -> io::Res unsafe { ret(syscall_readonly!(__NR_mkdirat, dirfd, path, mode)) } } +#[cfg(feature = "alloc")] #[inline] pub(crate) fn getdents(fd: BorrowedFd<'_>, dirent: &mut [u8]) -> io::Result<usize> { let (dirent_addr_mut, dirent_len) = slice_mut(dirent); @@ -1269,9 +1292,6 @@ fn _utimensat( times: &Timestamps, flags: AtFlags, ) -> io::Result<()> { - // Assert that `Timestamps` has the expected layout. - let _ = unsafe { transmute::<Timestamps, [__kernel_timespec; 2]>(times.clone()) }; - // `utimensat_time64` was introduced in Linux 5.1. The old `utimensat` // syscall is not y2038-compatible on 32-bit architectures. #[cfg(target_pointer_width = "32")] @@ -1626,37 +1646,10 @@ pub(crate) fn fremovexattr(fd: BorrowedFd<'_>, name: &CStr) -> io::Result<()> { unsafe { ret(syscall_readonly!(__NR_fremovexattr, fd, name)) } } -#[inline] -pub(crate) fn ioctl_blksszget(fd: BorrowedFd) -> io::Result<u32> { - let mut result = MaybeUninit::<c::c_uint>::uninit(); - unsafe { - ret(syscall!(__NR_ioctl, fd, c_uint(BLKSSZGET), &mut result))?; - Ok(result.assume_init() as u32) - } -} - -#[inline] -pub(crate) fn ioctl_blkpbszget(fd: BorrowedFd) -> io::Result<u32> { - let mut result = MaybeUninit::<c::c_uint>::uninit(); - unsafe { - ret(syscall!(__NR_ioctl, fd, c_uint(BLKPBSZGET), &mut result))?; - Ok(result.assume_init() as u32) - } -} - -#[inline] -pub(crate) fn ioctl_ficlone(fd: BorrowedFd<'_>, src_fd: BorrowedFd<'_>) -> io::Result<()> { - unsafe { ret(syscall_readonly!(__NR_ioctl, fd, c_uint(FICLONE), src_fd)) } -} +#[test] +fn test_sizes() { + assert_eq_size!(linux_raw_sys::general::__kernel_loff_t, u64); -#[inline] -pub(crate) fn ext4_ioc_resize_fs(fd: BorrowedFd<'_>, blocks: u64) -> io::Result<()> { - unsafe { - ret(syscall_readonly!( - __NR_ioctl, - fd, - c_uint(EXT4_IOC_RESIZE_FS), - by_ref(&blocks) - )) - } + // Assert that `Timestamps` has the expected layout. + assert_eq_size!([linux_raw_sys::general::__kernel_timespec; 2], Timestamps); } diff --git a/vendor/rustix/src/backend/linux_raw/fs/types.rs b/vendor/rustix/src/backend/linux_raw/fs/types.rs index e18dc0b4d..6e2e14f1e 100644 --- a/vendor/rustix/src/backend/linux_raw/fs/types.rs +++ b/vendor/rustix/src/backend/linux_raw/fs/types.rs @@ -19,6 +19,9 @@ bitflags! { /// `F_OK` const EXISTS = linux_raw_sys::general::F_OK; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -57,6 +60,9 @@ bitflags! { /// `AT_STATX_DONT_SYNC` const STATX_DONT_SYNC = linux_raw_sys::general::AT_STATX_DONT_SYNC; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -113,6 +119,9 @@ bitflags! { /// `S_ISVTX` const SVTX = linux_raw_sys::general::S_ISVTX; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -210,6 +219,8 @@ bitflags! { const WRONLY = linux_raw_sys::general::O_WRONLY; /// `O_RDWR` + /// + /// This is not equal to `RDONLY | WRONLY`. It's a distinct flag. const RDWR = linux_raw_sys::general::O_RDWR; /// `O_NOCTTY` @@ -238,6 +249,9 @@ bitflags! { /// `O_DIRECT` const DIRECT = linux_raw_sys::general::O_DIRECT; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -265,6 +279,9 @@ bitflags! { /// `RESOLVE_CACHED` (since Linux 5.12) const CACHED = linux_raw_sys::general::RESOLVE_CACHED as u64; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -283,6 +300,9 @@ bitflags! { /// `RENAME_WHITEOUT` const WHITEOUT = linux_raw_sys::general::RENAME_WHITEOUT; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -432,6 +452,9 @@ bitflags! { const HUGE_2GB = linux_raw_sys::general::MFD_HUGE_2GB; /// `MFD_HUGE_16GB` const HUGE_16GB = linux_raw_sys::general::MFD_HUGE_16GB; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -444,16 +467,19 @@ bitflags! { #[repr(transparent)] #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct SealFlags: u32 { - /// `F_SEAL_SEAL`. - const SEAL = linux_raw_sys::general::F_SEAL_SEAL; - /// `F_SEAL_SHRINK`. - const SHRINK = linux_raw_sys::general::F_SEAL_SHRINK; - /// `F_SEAL_GROW`. - const GROW = linux_raw_sys::general::F_SEAL_GROW; - /// `F_SEAL_WRITE`. - const WRITE = linux_raw_sys::general::F_SEAL_WRITE; - /// `F_SEAL_FUTURE_WRITE` (since Linux 5.1) - const FUTURE_WRITE = linux_raw_sys::general::F_SEAL_FUTURE_WRITE; + /// `F_SEAL_SEAL`. + const SEAL = linux_raw_sys::general::F_SEAL_SEAL; + /// `F_SEAL_SHRINK`. + const SHRINK = linux_raw_sys::general::F_SEAL_SHRINK; + /// `F_SEAL_GROW`. + const GROW = linux_raw_sys::general::F_SEAL_GROW; + /// `F_SEAL_WRITE`. + const WRITE = linux_raw_sys::general::F_SEAL_WRITE; + /// `F_SEAL_FUTURE_WRITE` (since Linux 5.1) + const FUTURE_WRITE = linux_raw_sys::general::F_SEAL_FUTURE_WRITE; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -511,6 +537,9 @@ bitflags! { /// `STATX_ALL` const ALL = linux_raw_sys::general::STATX_ALL; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -535,6 +564,9 @@ bitflags! { const INSERT_RANGE = linux_raw_sys::general::FALLOC_FL_INSERT_RANGE; /// `FALLOC_FL_UNSHARE_RANGE` const UNSHARE_RANGE = linux_raw_sys::general::FALLOC_FL_UNSHARE_RANGE; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -569,6 +601,9 @@ bitflags! { /// `ST_SYNCHRONOUS` const SYNCHRONOUS = linux_raw_sys::general::MS_SYNCHRONOUS as u64; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } diff --git a/vendor/rustix/src/backend/linux_raw/io/errno.rs b/vendor/rustix/src/backend/linux_raw/io/errno.rs index af057e2da..7730a7237 100644 --- a/vendor/rustix/src/backend/linux_raw/io/errno.rs +++ b/vendor/rustix/src/backend/linux_raw/io/errno.rs @@ -16,10 +16,32 @@ use crate::backend::reg::{RetNumber, RetReg}; use crate::io; use linux_raw_sys::errno; -/// The error type for `rustix` APIs. +/// `errno`—An error code. /// -/// This is similar to `std::io::Error`, but only holds an OS error code, -/// and no extra error value. +/// The error type for `rustix` APIs. This is similar to [`std::io::Error`], +/// but only holds an OS error code, and no extra error value. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// - [Winsock2] +/// - [FreeBSD] +/// - [NetBSD] +/// - [OpenBSD] +/// - [DragonFly BSD] +/// - [illumos] +/// - [glibc] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/errno.html +/// [Linux]: https://man7.org/linux/man-pages/man3/errno.3.html +/// [Winsock2]: https://learn.microsoft.com/en-us/windows/win32/winsock/windows-sockets-error-codes-2 +/// [FreeBSD]: https://man.freebsd.org/cgi/man.cgi?errno +/// [NetBSD]: https://man.netbsd.org/errno.2 +/// [OpenBSD]: https://man.openbsd.org/errno.2 +/// [DragonFly BSD]: https://man.dragonflybsd.org/?command=errno§ion=2 +/// [illumos]: https://illumos.org/man/3C/errno +/// [glibc]: https://www.gnu.org/software/libc/manual/html_node/Error-Codes.html +/// [`std::io::Error`]: Result #[repr(transparent)] #[doc(alias = "errno")] #[derive(Eq, PartialEq, Hash, Copy, Clone)] diff --git a/vendor/rustix/src/backend/linux_raw/io/syscalls.rs b/vendor/rustix/src/backend/linux_raw/io/syscalls.rs index 88eed3d72..d2cbba0c3 100644 --- a/vendor/rustix/src/backend/linux_raw/io/syscalls.rs +++ b/vendor/rustix/src/backend/linux_raw/io/syscalls.rs @@ -10,16 +10,11 @@ use crate::backend::conv::loff_t_from_u64; #[cfg(all( target_pointer_width = "32", - any( - target_arch = "arm", - target_arch = "mips", - target_arch = "mips32r6", - target_arch = "power" - ), + any(target_arch = "arm", target_arch = "mips", target_arch = "mips32r6"), ))] use crate::backend::conv::zero; use crate::backend::conv::{ - by_ref, c_uint, raw_fd, ret, ret_c_uint, ret_discarded_fd, ret_owned_fd, ret_usize, slice, + c_uint, raw_fd, ret, ret_c_int, ret_c_uint, ret_discarded_fd, ret_owned_fd, ret_usize, slice, slice_mut, }; #[cfg(target_pointer_width = "32")] @@ -27,12 +22,11 @@ use crate::backend::conv::{hi, lo}; use crate::backend::{c, MAX_IOV}; use crate::fd::{AsFd, BorrowedFd, OwnedFd, RawFd}; use crate::io::{self, DupFlags, FdFlags, IoSlice, IoSliceMut, ReadWriteFlags}; +use crate::ioctl::{IoctlOutput, RawOpcode}; #[cfg(all(feature = "fs", feature = "net"))] use crate::net::{RecvFlags, SendFlags}; use core::cmp; -use core::mem::MaybeUninit; use linux_raw_sys::general::{F_DUPFD_CLOEXEC, F_GETFD, F_SETFD}; -use linux_raw_sys::ioctl::{FIONBIO, FIONREAD}; #[inline] pub(crate) fn read(fd: BorrowedFd<'_>, buf: &mut [u8]) -> io::Result<usize> { @@ -48,12 +42,7 @@ pub(crate) fn pread(fd: BorrowedFd<'_>, buf: &mut [u8], pos: u64) -> io::Result< // <https://github.com/torvalds/linux/blob/fcadab740480e0e0e9fa9bd272acd409884d431a/arch/arm64/kernel/sys32.c#L75> #[cfg(all( target_pointer_width = "32", - any( - target_arch = "arm", - target_arch = "mips", - target_arch = "mips32r6", - target_arch = "power" - ), + any(target_arch = "arm", target_arch = "mips", target_arch = "mips32r6"), ))] unsafe { ret_usize(syscall!( @@ -68,12 +57,7 @@ pub(crate) fn pread(fd: BorrowedFd<'_>, buf: &mut [u8], pos: u64) -> io::Result< } #[cfg(all( target_pointer_width = "32", - not(any( - target_arch = "arm", - target_arch = "mips", - target_arch = "mips32r6", - target_arch = "power" - )), + not(any(target_arch = "arm", target_arch = "mips", target_arch = "mips32r6")), ))] unsafe { ret_usize(syscall!( @@ -183,12 +167,7 @@ pub(crate) fn pwrite(fd: BorrowedFd<'_>, buf: &[u8], pos: u64) -> io::Result<usi // <https://github.com/torvalds/linux/blob/fcadab740480e0e0e9fa9bd272acd409884d431a/arch/arm64/kernel/sys32.c#L81-L83> #[cfg(all( target_pointer_width = "32", - any( - target_arch = "arm", - target_arch = "mips", - target_arch = "mips32r6", - target_arch = "power" - ), + any(target_arch = "arm", target_arch = "mips", target_arch = "mips32r6"), ))] unsafe { ret_usize(syscall_readonly!( @@ -203,12 +182,7 @@ pub(crate) fn pwrite(fd: BorrowedFd<'_>, buf: &[u8], pos: u64) -> io::Result<usi } #[cfg(all( target_pointer_width = "32", - not(any( - target_arch = "arm", - target_arch = "mips", - target_arch = "mips32r6", - target_arch = "power" - )), + not(any(target_arch = "arm", target_arch = "mips", target_arch = "mips32r6")), ))] unsafe { ret_usize(syscall_readonly!( @@ -307,25 +281,21 @@ pub(crate) unsafe fn close(fd: RawFd) { } #[inline] -pub(crate) fn ioctl_fionread(fd: BorrowedFd<'_>) -> io::Result<u64> { - unsafe { - let mut result = MaybeUninit::<c::c_int>::uninit(); - ret(syscall!(__NR_ioctl, fd, c_uint(FIONREAD), &mut result))?; - Ok(result.assume_init() as u64) - } +pub(crate) unsafe fn ioctl( + fd: BorrowedFd<'_>, + request: RawOpcode, + arg: *mut c::c_void, +) -> io::Result<IoctlOutput> { + ret_c_int(syscall!(__NR_ioctl, fd, c_uint(request), arg)) } #[inline] -pub(crate) fn ioctl_fionbio(fd: BorrowedFd<'_>, value: bool) -> io::Result<()> { - unsafe { - let data = c::c_int::from(value); - ret(syscall_readonly!( - __NR_ioctl, - fd, - c_uint(FIONBIO), - by_ref(&data) - )) - } +pub(crate) unsafe fn ioctl_readonly( + fd: BorrowedFd<'_>, + request: RawOpcode, + arg: *mut c::c_void, +) -> io::Result<IoctlOutput> { + ret_c_int(syscall_readonly!(__NR_ioctl, fd, c_uint(request), arg)) } #[cfg(all(feature = "fs", feature = "net"))] @@ -376,6 +346,7 @@ pub(crate) fn dup(fd: BorrowedFd<'_>) -> io::Result<OwnedFd> { unsafe { ret_owned_fd(syscall_readonly!(__NR_dup, fd)) } } +#[allow(clippy::needless_pass_by_ref_mut)] #[inline] pub(crate) fn dup2(fd: BorrowedFd<'_>, new: &mut OwnedFd) -> io::Result<()> { #[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))] @@ -392,6 +363,7 @@ pub(crate) fn dup2(fd: BorrowedFd<'_>, new: &mut OwnedFd) -> io::Result<()> { } } +#[allow(clippy::needless_pass_by_ref_mut)] #[inline] pub(crate) fn dup3(fd: BorrowedFd<'_>, new: &mut OwnedFd, flags: DupFlags) -> io::Result<()> { unsafe { ret_discarded_fd(syscall_readonly!(__NR_dup3, fd, new.as_fd(), flags)) } diff --git a/vendor/rustix/src/backend/linux_raw/io/types.rs b/vendor/rustix/src/backend/linux_raw/io/types.rs index c06134440..fb7e913a0 100644 --- a/vendor/rustix/src/backend/linux_raw/io/types.rs +++ b/vendor/rustix/src/backend/linux_raw/io/types.rs @@ -11,6 +11,9 @@ bitflags! { pub struct FdFlags: c::c_uint { /// `FD_CLOEXEC` const CLOEXEC = linux_raw_sys::general::FD_CLOEXEC; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -32,6 +35,9 @@ bitflags! { const NOWAIT = linux_raw_sys::general::RWF_NOWAIT; /// `RWF_APPEND` (since Linux 4.16) const APPEND = linux_raw_sys::general::RWF_APPEND; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -44,5 +50,8 @@ bitflags! { pub struct DupFlags: c::c_uint { /// `O_CLOEXEC` const CLOEXEC = linux_raw_sys::general::O_CLOEXEC; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } diff --git a/vendor/rustix/src/backend/linux_raw/io_uring/syscalls.rs b/vendor/rustix/src/backend/linux_raw/io_uring/syscalls.rs index 90c82c129..d10cd1395 100644 --- a/vendor/rustix/src/backend/linux_raw/io_uring/syscalls.rs +++ b/vendor/rustix/src/backend/linux_raw/io_uring/syscalls.rs @@ -3,8 +3,7 @@ //! # Safety //! //! See the `rustix::backend::syscalls` module documentation for details. -#![allow(unsafe_code)] -#![allow(clippy::undocumented_unsafe_blocks)] +#![allow(unsafe_code, clippy::undocumented_unsafe_blocks)] use crate::backend::conv::{by_mut, c_uint, pass_usize, ret_c_uint, ret_owned_fd}; use crate::fd::{BorrowedFd, OwnedFd}; diff --git a/vendor/rustix/src/backend/linux_raw/mm/types.rs b/vendor/rustix/src/backend/linux_raw/mm/types.rs index 2d5eebc58..0dfb41050 100644 --- a/vendor/rustix/src/backend/linux_raw/mm/types.rs +++ b/vendor/rustix/src/backend/linux_raw/mm/types.rs @@ -16,6 +16,9 @@ bitflags! { const WRITE = linux_raw_sys::general::PROT_WRITE; /// `PROT_EXEC` const EXEC = linux_raw_sys::general::PROT_EXEC; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -52,6 +55,9 @@ bitflags! { /// `PROT_ADI` #[cfg(any(target_arch = "sparc", target_arch = "sparc64"))] const ADI = linux_raw_sys::general::PROT_ADI; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -99,6 +105,9 @@ bitflags! { /// `MAP_UNINITIALIZED` #[cfg(not(any(target_arch = "mips", target_arch = "mips32r6", target_arch = "mips64", target_arch = "mips64r6")))] const UNINITIALIZED = linux_raw_sys::general::MAP_UNINITIALIZED; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -116,6 +125,9 @@ bitflags! { const MAYMOVE = linux_raw_sys::general::MREMAP_MAYMOVE; /// `MREMAP_DONTUNMAP` (since Linux 5.7) const DONTUNMAP = linux_raw_sys::general::MREMAP_DONTUNMAP; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -135,6 +147,9 @@ bitflags! { /// file (so that they can be updated with the fresh values just /// written). const INVALIDATE = linux_raw_sys::general::MS_INVALIDATE; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -147,6 +162,9 @@ bitflags! { pub struct MlockFlags: u32 { /// `MLOCK_ONFAULT` const ONFAULT = linux_raw_sys::general::MLOCK_ONFAULT; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -239,5 +257,8 @@ bitflags! { const CLOEXEC = linux_raw_sys::general::O_CLOEXEC; /// `O_NONBLOCK` const NONBLOCK = linux_raw_sys::general::O_NONBLOCK; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } diff --git a/vendor/rustix/src/backend/linux_raw/mod.rs b/vendor/rustix/src/backend/linux_raw/mod.rs index c3018930f..9a07467f4 100644 --- a/vendor/rustix/src/backend/linux_raw/mod.rs +++ b/vendor/rustix/src/backend/linux_raw/mod.rs @@ -17,13 +17,6 @@ #[macro_use] mod arch; mod conv; -#[cfg(any( - feature = "param", - feature = "runtime", - feature = "time", - target_arch = "x86" -))] -mod elf; mod reg; #[cfg(any(feature = "time", target_arch = "x86"))] mod vdso; @@ -36,7 +29,7 @@ pub(crate) mod event; feature = "fs", all( not(feature = "use-libc-auxv"), - not(target_vendor = "mustang"), + not(feature = "use-explicitly-provided-auxv"), any( feature = "param", feature = "runtime", @@ -104,7 +97,7 @@ pub(crate) mod prctl; feature = "thread", all( not(feature = "use-libc-auxv"), - not(target_vendor = "mustang"), + not(feature = "use-explicitly-provided-auxv"), any( feature = "param", feature = "runtime", diff --git a/vendor/rustix/src/backend/linux_raw/mount/types.rs b/vendor/rustix/src/backend/linux_raw/mount/types.rs index 808710c13..221f8f315 100644 --- a/vendor/rustix/src/backend/linux_raw/mount/types.rs +++ b/vendor/rustix/src/backend/linux_raw/mount/types.rs @@ -56,6 +56,9 @@ bitflags! { /// `MS_NOSYMFOLLOW` const NOSYMFOLLOW = linux_raw_sys::general::MS_NOSYMFOLLOW; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -74,6 +77,9 @@ bitflags! { const EXPIRE = linux_raw_sys::general::MNT_EXPIRE; /// `UMOUNT_NOFOLLOW` const NOFOLLOW = linux_raw_sys::general::UMOUNT_NOFOLLOW; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -85,9 +91,11 @@ bitflags! { #[repr(transparent)] #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct FsOpenFlags: c::c_uint { - /// `FSOPEN_CLOEXEC` const FSOPEN_CLOEXEC = linux_raw_sys::general::FSOPEN_CLOEXEC; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -101,6 +109,9 @@ bitflags! { pub struct FsMountFlags: c::c_uint { /// `FSMOUNT_CLOEXEC` const FSMOUNT_CLOEXEC = linux_raw_sys::general::FSMOUNT_CLOEXEC; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -177,6 +188,9 @@ bitflags! { /// `MOUNT_ATTR__ATIME_FLAGS` const MOUNT_ATTR_SIZE_VER0 = linux_raw_sys::general::MOUNT_ATTR_SIZE_VER0; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -215,6 +229,9 @@ bitflags! { /// `MOVE_MOUNT__MASK` const MOVE_MOUNT__MASK = linux_raw_sys::general::MOVE_MOUNT__MASK; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -243,6 +260,9 @@ bitflags! { /// `AT_SYMLINK_NOFOLLOW` const AT_SYMLINK_NOFOLLOW = linux_raw_sys::general::AT_SYMLINK_NOFOLLOW; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -265,6 +285,9 @@ bitflags! { /// `FSPICK_EMPTY_PATH` const FSPICK_EMPTY_PATH = linux_raw_sys::general::FSPICK_EMPTY_PATH; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -287,6 +310,9 @@ bitflags! { const UNBINDABLE = linux_raw_sys::general::MS_UNBINDABLE; /// `MS_REC` const REC = linux_raw_sys::general::MS_REC; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -296,6 +322,9 @@ bitflags! { pub(crate) struct InternalMountFlags: c::c_uint { const REMOUNT = linux_raw_sys::general::MS_REMOUNT; const MOVE = linux_raw_sys::general::MS_MOVE; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } diff --git a/vendor/rustix/src/backend/linux_raw/net/addr.rs b/vendor/rustix/src/backend/linux_raw/net/addr.rs index 4a203ed16..e6b307a16 100644 --- a/vendor/rustix/src/backend/linux_raw/net/addr.rs +++ b/vendor/rustix/src/backend/linux_raw/net/addr.rs @@ -117,9 +117,7 @@ impl Eq for SocketAddrUnix {} impl PartialOrd for SocketAddrUnix { #[inline] fn partial_cmp(&self, other: &Self) -> Option<Ordering> { - let self_len = self.len() - offsetof_sun_path(); - let other_len = other.len() - offsetof_sun_path(); - self.unix.sun_path[..self_len].partial_cmp(&other.unix.sun_path[..other_len]) + Some(self.cmp(other)) } } diff --git a/vendor/rustix/src/backend/linux_raw/net/msghdr.rs b/vendor/rustix/src/backend/linux_raw/net/msghdr.rs index 3c435bcfa..659093920 100644 --- a/vendor/rustix/src/backend/linux_raw/net/msghdr.rs +++ b/vendor/rustix/src/backend/linux_raw/net/msghdr.rs @@ -12,7 +12,7 @@ use crate::io::{self, IoSlice, IoSliceMut}; use crate::net::{RecvAncillaryBuffer, SendAncillaryBuffer, SocketAddrV4, SocketAddrV6}; use crate::utils::as_ptr; -use core::mem::{size_of, zeroed, MaybeUninit}; +use core::mem::{size_of, MaybeUninit}; use core::ptr::null_mut; fn msg_iov_len(len: usize) -> c::size_t { @@ -42,9 +42,7 @@ pub(crate) fn with_recv_msghdr<R>( msg_iovlen: msg_iov_len(iov.len()), msg_control: control.as_control_ptr().cast(), msg_controllen: msg_control_len(control.control_len()), - - // Zero-initialize any padding bytes. - ..unsafe { zeroed() } + msg_flags: 0, }; let res = f(&mut msghdr); @@ -72,9 +70,7 @@ pub(crate) fn with_noaddr_msghdr<R>( msg_iovlen: msg_iov_len(iov.len()), msg_control: control.as_control_ptr().cast(), msg_controllen: msg_control_len(control.control_len()), - - // Zero-initialize any padding bytes. - ..unsafe { zeroed() } + msg_flags: 0, }) } @@ -85,7 +81,7 @@ pub(crate) fn with_v4_msghdr<R>( control: &mut SendAncillaryBuffer<'_, '_, '_>, f: impl FnOnce(c::msghdr) -> R, ) -> R { - let encoded = unsafe { encode_sockaddr_v4(addr) }; + let encoded = encode_sockaddr_v4(addr); f(c::msghdr { msg_name: as_ptr(&encoded) as _, @@ -94,9 +90,7 @@ pub(crate) fn with_v4_msghdr<R>( msg_iovlen: msg_iov_len(iov.len()), msg_control: control.as_control_ptr().cast(), msg_controllen: msg_control_len(control.control_len()), - - // Zero-initialize any padding bytes. - ..unsafe { zeroed() } + msg_flags: 0, }) } @@ -107,7 +101,7 @@ pub(crate) fn with_v6_msghdr<R>( control: &mut SendAncillaryBuffer<'_, '_, '_>, f: impl FnOnce(c::msghdr) -> R, ) -> R { - let encoded = unsafe { encode_sockaddr_v6(addr) }; + let encoded = encode_sockaddr_v6(addr); f(c::msghdr { msg_name: as_ptr(&encoded) as _, @@ -116,9 +110,7 @@ pub(crate) fn with_v6_msghdr<R>( msg_iovlen: msg_iov_len(iov.len()), msg_control: control.as_control_ptr().cast(), msg_controllen: msg_control_len(control.control_len()), - - // Zero-initialize any padding bytes. - ..unsafe { zeroed() } + msg_flags: 0, }) } @@ -136,8 +128,19 @@ pub(crate) fn with_unix_msghdr<R>( msg_iovlen: msg_iov_len(iov.len()), msg_control: control.as_control_ptr().cast(), msg_controllen: msg_control_len(control.control_len()), - - // Zero-initialize any padding bytes. - ..unsafe { zeroed() } + msg_flags: 0, }) } + +/// Create a zero-initialized message header struct value. +pub(crate) fn zero_msghdr() -> c::msghdr { + c::msghdr { + msg_name: null_mut(), + msg_namelen: 0, + msg_iov: null_mut(), + msg_iovlen: 0, + msg_control: null_mut(), + msg_controllen: 0, + msg_flags: 0, + } +} 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 6e39a13aa..43b35341a 100644 --- a/vendor/rustix/src/backend/linux_raw/net/send_recv.rs +++ b/vendor/rustix/src/backend/linux_raw/net/send_recv.rs @@ -23,6 +23,9 @@ bitflags! { const NOSIGNAL = c::MSG_NOSIGNAL; /// `MSG_OOB` const OOB = c::MSG_OOB; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -48,5 +51,8 @@ bitflags! { const TRUNC = c::MSG_TRUNC; /// `MSG_WAITALL` const WAITALL = c::MSG_WAITALL; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } diff --git a/vendor/rustix/src/backend/linux_raw/net/syscalls.rs b/vendor/rustix/src/backend/linux_raw/net/syscalls.rs index df35e63c8..e5ebcc1dd 100644 --- a/vendor/rustix/src/backend/linux_raw/net/syscalls.rs +++ b/vendor/rustix/src/backend/linux_raw/net/syscalls.rs @@ -3,8 +3,7 @@ //! # Safety //! //! See the `rustix::backend` module documentation for details. -#![allow(unsafe_code)] -#![allow(clippy::undocumented_unsafe_blocks)] +#![allow(unsafe_code, clippy::undocumented_unsafe_blocks)] use super::msghdr::{ with_noaddr_msghdr, with_recv_msghdr, with_unix_msghdr, with_v4_msghdr, with_v6_msghdr, @@ -51,7 +50,7 @@ pub(crate) fn socket( ret_owned_fd(syscall_readonly!( __NR_socketcall, x86_sys(SYS_SOCKET), - slice_just_addr::<ArgReg<SocketArg>, _>(&[ + slice_just_addr::<ArgReg<'_, SocketArg>, _>(&[ family.into(), type_.into(), protocol.into(), @@ -81,7 +80,7 @@ pub(crate) fn socket_with( ret_owned_fd(syscall_readonly!( __NR_socketcall, x86_sys(SYS_SOCKET), - slice_just_addr::<ArgReg<SocketArg>, _>(&[ + slice_just_addr::<ArgReg<'_, SocketArg>, _>(&[ family.into(), (type_, flags).into(), protocol.into(), @@ -116,7 +115,7 @@ pub(crate) fn socketpair( ret(syscall!( __NR_socketcall, x86_sys(SYS_SOCKETPAIR), - slice_just_addr::<ArgReg<SocketArg>, _>(&[ + slice_just_addr::<ArgReg<'_, SocketArg>, _>(&[ family.into(), (type_, flags).into(), protocol.into(), @@ -140,7 +139,7 @@ pub(crate) fn accept(fd: BorrowedFd<'_>) -> io::Result<OwnedFd> { let fd = ret_owned_fd(syscall_readonly!( __NR_socketcall, x86_sys(SYS_ACCEPT), - slice_just_addr::<ArgReg<SocketArg>, _>(&[fd.into(), zero(), zero()]) + slice_just_addr::<ArgReg<'_, SocketArg>, _>(&[fd.into(), zero(), zero()]) ))?; Ok(fd) } @@ -158,7 +157,7 @@ pub(crate) fn accept_with(fd: BorrowedFd<'_>, flags: SocketFlags) -> io::Result< let fd = ret_owned_fd(syscall_readonly!( __NR_socketcall, x86_sys(SYS_ACCEPT4), - slice_just_addr::<ArgReg<SocketArg>, _>(&[fd.into(), zero(), zero(), flags.into()]) + slice_just_addr::<ArgReg<'_, SocketArg>, _>(&[fd.into(), zero(), zero(), flags.into()]) ))?; Ok(fd) } @@ -188,7 +187,7 @@ pub(crate) fn acceptfrom(fd: BorrowedFd<'_>) -> io::Result<(OwnedFd, Option<Sock let fd = ret_owned_fd(syscall!( __NR_socketcall, x86_sys(SYS_ACCEPT), - slice_just_addr::<ArgReg<SocketArg>, _>(&[ + slice_just_addr::<ArgReg<'_, SocketArg>, _>(&[ fd.into(), (&mut storage).into(), by_mut(&mut addrlen), @@ -229,7 +228,7 @@ pub(crate) fn acceptfrom_with( let fd = ret_owned_fd(syscall!( __NR_socketcall, x86_sys(SYS_ACCEPT4), - slice_just_addr::<ArgReg<SocketArg>, _>(&[ + slice_just_addr::<ArgReg<'_, SocketArg>, _>(&[ fd.into(), (&mut storage).into(), by_mut(&mut addrlen), @@ -262,7 +261,7 @@ pub(crate) fn recvmsg( ret_usize(syscall!( __NR_socketcall, x86_sys(SYS_RECVMSG), - slice_just_addr::<ArgReg<SocketArg>, _>(&[ + slice_just_addr::<ArgReg<'_, SocketArg>, _>(&[ sockfd.into(), by_mut(msghdr), msg_flags.into(), @@ -301,7 +300,7 @@ pub(crate) fn sendmsg( ret_usize(syscall!( __NR_socketcall, x86_sys(SYS_SENDMSG), - slice_just_addr::<ArgReg<SocketArg>, _>(&[ + slice_just_addr::<ArgReg<'_, SocketArg>, _>(&[ sockfd.into(), by_ref(&msghdr), msg_flags.into() @@ -331,7 +330,7 @@ pub(crate) fn sendmsg_v4( ret_usize(syscall!( __NR_socketcall, x86_sys(SYS_SENDMSG), - slice_just_addr::<ArgReg<SocketArg>, _>(&[ + slice_just_addr::<ArgReg<'_, SocketArg>, _>(&[ sockfd.into(), by_ref(&msghdr), msg_flags.into(), @@ -361,7 +360,7 @@ pub(crate) fn sendmsg_v6( ret_usize(syscall!( __NR_socketcall, x86_sys(SYS_SENDMSG), - slice_just_addr::<ArgReg<SocketArg>, _>(&[ + slice_just_addr::<ArgReg<'_, SocketArg>, _>(&[ sockfd.into(), by_ref(&msghdr), msg_flags.into() @@ -391,7 +390,7 @@ pub(crate) fn sendmsg_unix( ret_usize(syscall!( __NR_socketcall, x86_sys(SYS_SENDMSG), - slice_just_addr::<ArgReg<SocketArg>, _>(&[ + slice_just_addr::<ArgReg<'_, SocketArg>, _>(&[ sockfd.into(), by_ref(&msghdr), msg_flags.into() @@ -418,7 +417,7 @@ pub(crate) fn shutdown(fd: BorrowedFd<'_>, how: Shutdown) -> io::Result<()> { ret(syscall_readonly!( __NR_socketcall, x86_sys(SYS_SHUTDOWN), - slice_just_addr::<ArgReg<SocketArg>, _>(&[fd.into(), c_uint(how as c::c_uint)]) + slice_just_addr::<ArgReg<'_, SocketArg>, _>(&[fd.into(), c_uint(how as c::c_uint)]) )) } } @@ -461,7 +460,12 @@ pub(crate) fn send(fd: BorrowedFd<'_>, buf: &[u8], flags: SendFlags) -> io::Resu ret_usize(syscall_readonly!( __NR_socketcall, x86_sys(SYS_SEND), - slice_just_addr::<ArgReg<SocketArg>, _>(&[fd.into(), buf_addr, buf_len, flags.into()]) + slice_just_addr::<ArgReg<'_, SocketArg>, _>(&[ + fd.into(), + buf_addr, + buf_len, + flags.into() + ]) )) } } @@ -492,7 +496,7 @@ pub(crate) fn sendto_v4( ret_usize(syscall_readonly!( __NR_socketcall, x86_sys(SYS_SENDTO), - slice_just_addr::<ArgReg<SocketArg>, _>(&[ + slice_just_addr::<ArgReg<'_, SocketArg>, _>(&[ fd.into(), buf_addr, buf_len, @@ -530,7 +534,7 @@ pub(crate) fn sendto_v6( ret_usize(syscall_readonly!( __NR_socketcall, x86_sys(SYS_SENDTO), - slice_just_addr::<ArgReg<SocketArg>, _>(&[ + slice_just_addr::<ArgReg<'_, SocketArg>, _>(&[ fd.into(), buf_addr, buf_len, @@ -568,7 +572,7 @@ pub(crate) fn sendto_unix( ret_usize(syscall_readonly!( __NR_socketcall, x86_sys(SYS_SENDTO), - slice_just_addr::<ArgReg<SocketArg>, _>(&[ + slice_just_addr::<ArgReg<'_, SocketArg>, _>(&[ fd.into(), buf_addr, buf_len, @@ -618,7 +622,7 @@ pub(crate) fn recv(fd: BorrowedFd<'_>, buf: &mut [u8], flags: RecvFlags) -> io:: ret_usize(syscall!( __NR_socketcall, x86_sys(SYS_RECV), - slice_just_addr::<ArgReg<SocketArg>, _>(&[ + slice_just_addr::<ArgReg<'_, SocketArg>, _>(&[ fd.into(), buf_addr_mut, buf_len, @@ -659,7 +663,7 @@ pub(crate) fn recvfrom( let nread = ret_usize(syscall!( __NR_socketcall, x86_sys(SYS_RECVFROM), - slice_just_addr::<ArgReg<SocketArg>, _>(&[ + slice_just_addr::<ArgReg<'_, SocketArg>, _>(&[ fd.into(), buf_addr_mut, buf_len, @@ -700,7 +704,7 @@ pub(crate) fn getpeername(fd: BorrowedFd<'_>) -> io::Result<Option<SocketAddrAny ret(syscall!( __NR_socketcall, x86_sys(SYS_GETPEERNAME), - slice_just_addr::<ArgReg<SocketArg>, _>(&[ + slice_just_addr::<ArgReg<'_, SocketArg>, _>(&[ fd.into(), (&mut storage).into(), by_mut(&mut addrlen), @@ -737,7 +741,7 @@ pub(crate) fn getsockname(fd: BorrowedFd<'_>) -> io::Result<SocketAddrAny> { ret(syscall!( __NR_socketcall, x86_sys(SYS_GETSOCKNAME), - slice_just_addr::<ArgReg<SocketArg>, _>(&[ + slice_just_addr::<ArgReg<'_, SocketArg>, _>(&[ fd.into(), (&mut storage).into(), by_mut(&mut addrlen), @@ -766,7 +770,7 @@ pub(crate) fn bind_v4(fd: BorrowedFd<'_>, addr: &SocketAddrV4) -> io::Result<()> ret(syscall_readonly!( __NR_socketcall, x86_sys(SYS_BIND), - slice_just_addr::<ArgReg<SocketArg>, _>(&[ + slice_just_addr::<ArgReg<'_, SocketArg>, _>(&[ fd.into(), by_ref(&encode_sockaddr_v4(addr)), size_of::<sockaddr_in, _>(), @@ -791,7 +795,7 @@ pub(crate) fn bind_v6(fd: BorrowedFd<'_>, addr: &SocketAddrV6) -> io::Result<()> ret(syscall_readonly!( __NR_socketcall, x86_sys(SYS_BIND), - slice_just_addr::<ArgReg<SocketArg>, _>(&[ + slice_just_addr::<ArgReg<'_, SocketArg>, _>(&[ fd.into(), by_ref(&encode_sockaddr_v6(addr)), size_of::<sockaddr_in6, _>(), @@ -816,7 +820,7 @@ pub(crate) fn bind_unix(fd: BorrowedFd<'_>, addr: &SocketAddrUnix) -> io::Result ret(syscall_readonly!( __NR_socketcall, x86_sys(SYS_BIND), - slice_just_addr::<ArgReg<SocketArg>, _>(&[ + slice_just_addr::<ArgReg<'_, SocketArg>, _>(&[ fd.into(), by_ref(&addr.unix), socklen_t(addr.addr_len()), @@ -841,7 +845,7 @@ pub(crate) fn connect_v4(fd: BorrowedFd<'_>, addr: &SocketAddrV4) -> io::Result< ret(syscall_readonly!( __NR_socketcall, x86_sys(SYS_CONNECT), - slice_just_addr::<ArgReg<SocketArg>, _>(&[ + slice_just_addr::<ArgReg<'_, SocketArg>, _>(&[ fd.into(), by_ref(&encode_sockaddr_v4(addr)), size_of::<sockaddr_in, _>(), @@ -866,7 +870,7 @@ pub(crate) fn connect_v6(fd: BorrowedFd<'_>, addr: &SocketAddrV6) -> io::Result< ret(syscall_readonly!( __NR_socketcall, x86_sys(SYS_CONNECT), - slice_just_addr::<ArgReg<SocketArg>, _>(&[ + slice_just_addr::<ArgReg<'_, SocketArg>, _>(&[ fd.into(), by_ref(&encode_sockaddr_v6(addr)), size_of::<sockaddr_in6, _>(), @@ -891,7 +895,7 @@ pub(crate) fn connect_unix(fd: BorrowedFd<'_>, addr: &SocketAddrUnix) -> io::Res ret(syscall_readonly!( __NR_socketcall, x86_sys(SYS_CONNECT), - slice_just_addr::<ArgReg<SocketArg>, _>(&[ + slice_just_addr::<ArgReg<'_, SocketArg>, _>(&[ fd.into(), by_ref(&addr.unix), socklen_t(addr.addr_len()), @@ -911,7 +915,7 @@ pub(crate) fn listen(fd: BorrowedFd<'_>, backlog: c::c_int) -> io::Result<()> { ret(syscall_readonly!( __NR_socketcall, x86_sys(SYS_LISTEN), - slice_just_addr::<ArgReg<SocketArg>, _>(&[fd.into(), c_int(backlog)]) + slice_just_addr::<ArgReg<'_, SocketArg>, _>(&[fd.into(), c_int(backlog)]) )) } } @@ -920,10 +924,11 @@ pub(crate) mod sockopt { use super::{c, BorrowedFd}; use crate::io; use crate::net::sockopt::Timeout; - use crate::net::{Ipv4Addr, Ipv6Addr, SocketType}; + use crate::net::{AddressFamily, Ipv4Addr, Ipv6Addr, SocketType}; use c::{SO_RCVTIMEO_NEW, SO_RCVTIMEO_OLD, SO_SNDTIMEO_NEW, SO_SNDTIMEO_OLD}; use core::time::Duration; use linux_raw_sys::general::{__kernel_timespec, timeval}; + use linux_raw_sys::net::{SO_ACCEPTCONN, TCP_KEEPCNT, TCP_KEEPIDLE, TCP_KEEPINTVL}; #[inline] fn getsockopt<T: Copy>(fd: BorrowedFd<'_>, level: u32, optname: u32) -> io::Result<T> { @@ -960,7 +965,7 @@ pub(crate) mod sockopt { ret(syscall!( __NR_socketcall, x86_sys(SYS_GETSOCKOPT), - slice_just_addr::<ArgReg<SocketArg>, _>(&[ + slice_just_addr::<ArgReg<'_, SocketArg>, _>(&[ fd.into(), c_uint(level), c_uint(optname), @@ -1008,7 +1013,7 @@ pub(crate) mod sockopt { ret(syscall_readonly!( __NR_socketcall, x86_sys(SYS_SETSOCKOPT), - slice_just_addr::<ArgReg<SocketArg>, _>(&[ + slice_just_addr::<ArgReg<'_, SocketArg>, _>(&[ fd.into(), c_uint(level), c_uint(optname), @@ -1035,6 +1040,11 @@ pub(crate) mod sockopt { } #[inline] + pub(crate) fn get_socket_reuseaddr(fd: BorrowedFd<'_>) -> io::Result<bool> { + getsockopt(fd, c::SOL_SOCKET as _, c::SO_REUSEADDR).map(to_bool) + } + + #[inline] pub(crate) fn set_socket_broadcast(fd: BorrowedFd<'_>, broadcast: bool) -> io::Result<()> { setsockopt( fd, @@ -1056,11 +1066,7 @@ pub(crate) mod sockopt { ) -> io::Result<()> { // Convert `linger` to seconds, rounding up. let l_linger = if let Some(linger) = linger { - let mut l_linger = linger.as_secs(); - if linger.subsec_nanos() != 0 { - l_linger = l_linger.checked_add(1).ok_or(io::Errno::INVAL)?; - } - l_linger.try_into().map_err(|_e| io::Errno::INVAL)? + duration_to_secs(linger)? } else { 0 }; @@ -1272,6 +1278,19 @@ pub(crate) mod sockopt { } #[inline] + pub(crate) fn get_socket_domain(fd: BorrowedFd<'_>) -> io::Result<AddressFamily> { + let domain: c::c_int = getsockopt(fd, c::SOL_SOCKET as _, c::SO_DOMAIN)?; + Ok(AddressFamily( + domain.try_into().map_err(|_| io::Errno::OPNOTSUPP)?, + )) + } + + #[inline] + pub(crate) fn get_socket_acceptconn(fd: BorrowedFd<'_>) -> io::Result<bool> { + getsockopt(fd, c::SOL_SOCKET as _, SO_ACCEPTCONN).map(to_bool) + } + + #[inline] pub(crate) fn set_ip_ttl(fd: BorrowedFd<'_>, ttl: u32) -> io::Result<()> { setsockopt(fd, c::IPPROTO_IP as _, c::IP_TTL, ttl) } @@ -1420,6 +1439,40 @@ pub(crate) mod sockopt { } #[inline] + pub(crate) fn set_tcp_keepcnt(fd: BorrowedFd<'_>, count: u32) -> io::Result<()> { + setsockopt(fd, c::IPPROTO_TCP as _, TCP_KEEPCNT, count) + } + + #[inline] + pub(crate) fn get_tcp_keepcnt(fd: BorrowedFd<'_>) -> io::Result<u32> { + getsockopt(fd, c::IPPROTO_TCP as _, TCP_KEEPCNT) + } + + #[inline] + pub(crate) fn set_tcp_keepidle(fd: BorrowedFd<'_>, duration: Duration) -> io::Result<()> { + let secs: c::c_uint = duration_to_secs(duration)?; + setsockopt(fd, c::IPPROTO_TCP as _, TCP_KEEPIDLE, secs) + } + + #[inline] + pub(crate) fn get_tcp_keepidle(fd: BorrowedFd<'_>) -> io::Result<Duration> { + let secs: c::c_uint = getsockopt(fd, c::IPPROTO_TCP as _, TCP_KEEPIDLE)?; + Ok(Duration::from_secs(secs as u64)) + } + + #[inline] + pub(crate) fn set_tcp_keepintvl(fd: BorrowedFd<'_>, duration: Duration) -> io::Result<()> { + let secs: c::c_uint = duration_to_secs(duration)?; + setsockopt(fd, c::IPPROTO_TCP as _, TCP_KEEPINTVL, secs) + } + + #[inline] + pub(crate) fn get_tcp_keepintvl(fd: BorrowedFd<'_>) -> io::Result<Duration> { + let secs: c::c_uint = getsockopt(fd, c::IPPROTO_TCP as _, TCP_KEEPINTVL)?; + Ok(Duration::from_secs(secs as u64)) + } + + #[inline] fn to_imr(multiaddr: &Ipv4Addr, interface: &Ipv4Addr) -> c::ip_mreq { c::ip_mreq { imr_multiaddr: to_imr_addr(multiaddr), @@ -1465,4 +1518,14 @@ pub(crate) mod sockopt { fn to_bool(value: c::c_uint) -> bool { value != 0 } + + /// Convert to seconds, rounding up if necessary. + #[inline] + fn duration_to_secs<T: TryFrom<u64>>(duration: Duration) -> io::Result<T> { + let mut secs = duration.as_secs(); + if duration.subsec_nanos() != 0 { + secs = secs.checked_add(1).ok_or(io::Errno::INVAL)?; + } + T::try_from(secs).map_err(|_e| io::Errno::INVAL) + } } diff --git a/vendor/rustix/src/backend/linux_raw/net/write_sockaddr.rs b/vendor/rustix/src/backend/linux_raw/net/write_sockaddr.rs index 28da05cd0..417f76e43 100644 --- a/vendor/rustix/src/backend/linux_raw/net/write_sockaddr.rs +++ b/vendor/rustix/src/backend/linux_raw/net/write_sockaddr.rs @@ -17,7 +17,7 @@ pub(crate) unsafe fn write_sockaddr( } } -pub(crate) unsafe fn encode_sockaddr_v4(v4: &SocketAddrV4) -> c::sockaddr_in { +pub(crate) fn encode_sockaddr_v4(v4: &SocketAddrV4) -> c::sockaddr_in { c::sockaddr_in { sin_family: c::AF_INET as _, sin_port: u16::to_be(v4.port()), @@ -34,7 +34,7 @@ unsafe fn write_sockaddr_v4(v4: &SocketAddrV4, storage: *mut SocketAddrStorage) size_of::<c::sockaddr_in>() } -pub(crate) unsafe fn encode_sockaddr_v6(v6: &SocketAddrV6) -> c::sockaddr_in6 { +pub(crate) fn encode_sockaddr_v6(v6: &SocketAddrV6) -> c::sockaddr_in6 { c::sockaddr_in6 { sin6_family: c::AF_INET6 as _, sin6_port: u16::to_be(v6.port()), diff --git a/vendor/rustix/src/backend/linux_raw/param/auxv.rs b/vendor/rustix/src/backend/linux_raw/param/auxv.rs index 144ff10cd..8b0423ae4 100644 --- a/vendor/rustix/src/backend/linux_raw/param/auxv.rs +++ b/vendor/rustix/src/backend/linux_raw/param/auxv.rs @@ -6,24 +6,23 @@ #![allow(unsafe_code)] use crate::backend::c; -use crate::backend::elf::*; use crate::fd::OwnedFd; #[cfg(feature = "param")] use crate::ffi::CStr; use crate::fs::{Mode, OFlags}; use crate::utils::{as_ptr, check_raw_pointer}; +#[cfg(feature = "alloc")] use alloc::vec::Vec; -use core::ffi::c_void; use core::mem::size_of; use core::ptr::{null_mut, read_unaligned, NonNull}; -#[cfg(feature = "runtime")] -use core::slice; use core::sync::atomic::Ordering::Relaxed; use core::sync::atomic::{AtomicPtr, AtomicUsize}; +use linux_raw_sys::elf::*; use linux_raw_sys::general::{ - AT_BASE, AT_CLKTCK, AT_EXECFN, AT_HWCAP, AT_HWCAP2, AT_NULL, AT_PAGESZ, AT_PHDR, AT_PHENT, - AT_PHNUM, AT_SYSINFO_EHDR, + AT_BASE, AT_CLKTCK, AT_EXECFN, AT_HWCAP, AT_HWCAP2, AT_NULL, AT_PAGESZ, AT_SYSINFO_EHDR, }; +#[cfg(feature = "runtime")] +use linux_raw_sys::general::{AT_ENTRY, AT_PHDR, AT_PHENT, AT_PHNUM}; #[cfg(feature = "param")] #[inline] @@ -83,31 +82,23 @@ pub(crate) fn linux_execfn() -> &'static CStr { #[cfg(feature = "runtime")] #[inline] -pub(crate) fn exe_phdrs() -> (*const c::c_void, usize) { +pub(crate) fn exe_phdrs() -> (*const c::c_void, usize, usize) { let mut phdr = PHDR.load(Relaxed); + let mut phent = PHENT.load(Relaxed); let mut phnum = PHNUM.load(Relaxed); if phdr.is_null() || phnum == 0 { init_auxv(); phdr = PHDR.load(Relaxed); + phent = PHENT.load(Relaxed); phnum = PHNUM.load(Relaxed); } - (phdr.cast(), phnum) + (phdr.cast(), phent, phnum) } -#[cfg(feature = "runtime")] -#[inline] -pub(in super::super) fn exe_phdrs_slice() -> &'static [Elf_Phdr] { - let (phdr, phnum) = exe_phdrs(); - - // SAFETY: We assume the `AT_PHDR` and `AT_PHNUM` values provided by the - // kernel form a valid slice. - unsafe { slice::from_raw_parts(phdr.cast(), phnum) } -} - -/// `AT_SYSINFO_EHDR` isn't present on all platforms in all configurations, -/// so if we don't see it, this function returns a null pointer. +/// `AT_SYSINFO_EHDR` isn't present on all platforms in all configurations, so +/// if we don't see it, this function returns a null pointer. #[inline] pub(in super::super) fn sysinfo_ehdr() -> *const Elf_Ehdr { let mut ehdr = SYSINFO_EHDR.load(Relaxed); @@ -120,15 +111,35 @@ pub(in super::super) fn sysinfo_ehdr() -> *const Elf_Ehdr { ehdr } +#[cfg(feature = "runtime")] +#[inline] +pub(crate) fn entry() -> usize { + let mut entry = ENTRY.load(Relaxed); + + if entry == 0 { + init_auxv(); + entry = ENTRY.load(Relaxed); + } + + entry +} + static PAGE_SIZE: AtomicUsize = AtomicUsize::new(0); static CLOCK_TICKS_PER_SECOND: AtomicUsize = AtomicUsize::new(0); static HWCAP: AtomicUsize = AtomicUsize::new(0); static HWCAP2: AtomicUsize = AtomicUsize::new(0); +static EXECFN: AtomicPtr<c::c_char> = AtomicPtr::new(null_mut()); static SYSINFO_EHDR: AtomicPtr<Elf_Ehdr> = AtomicPtr::new(null_mut()); +#[cfg(feature = "runtime")] static PHDR: AtomicPtr<Elf_Phdr> = AtomicPtr::new(null_mut()); +#[cfg(feature = "runtime")] +static PHENT: AtomicUsize = AtomicUsize::new(0); +#[cfg(feature = "runtime")] static PHNUM: AtomicUsize = AtomicUsize::new(0); -static EXECFN: AtomicPtr<c::c_char> = AtomicPtr::new(null_mut()); +#[cfg(feature = "runtime")] +static ENTRY: AtomicUsize = AtomicUsize::new(0); +#[cfg(feature = "alloc")] fn pr_get_auxv() -> crate::io::Result<Vec<u8>> { use super::super::conv::{c_int, pass_usize, ret_usize}; const PR_GET_AUXV: c::c_int = 0x41555856; @@ -138,7 +149,9 @@ fn pr_get_auxv() -> crate::io::Result<Vec<u8>> { __NR_prctl, c_int(PR_GET_AUXV), buffer.as_ptr(), - pass_usize(buffer.len()) + pass_usize(buffer.len()), + pass_usize(0), + pass_usize(0) ))? }; if len <= buffer.len() { @@ -151,28 +164,33 @@ fn pr_get_auxv() -> crate::io::Result<Vec<u8>> { __NR_prctl, c_int(PR_GET_AUXV), buffer.as_ptr(), - pass_usize(buffer.len()) + pass_usize(buffer.len()), + pass_usize(0), + pass_usize(0) ))? }; assert_eq!(len, buffer.len()); return Ok(buffer); } -/// On non-Mustang platforms, we read the aux vector via the `prctl` -/// `PR_GET_AUXV`, with a fallback to /proc/self/auxv for kernels that don't -/// support `PR_GET_AUXV`. +/// If we don't have "use-explicitly-provided-auxv" or "use-libc-auxv", we +/// read the aux vector via the `prctl` `PR_GET_AUXV`, with a fallback to +/// /proc/self/auxv for kernels that don't support `PR_GET_AUXV`. #[cold] fn init_auxv() { - match pr_get_auxv() { - Ok(buffer) => { - // SAFETY: We assume the kernel returns a valid auxv. - unsafe { - init_from_auxp(buffer.as_ptr().cast()); + #[cfg(feature = "alloc")] + { + match pr_get_auxv() { + Ok(buffer) => { + // SAFETY: We assume the kernel returns a valid auxv. + unsafe { + init_from_aux_iter(AuxPointer(buffer.as_ptr().cast())); + } + return; + } + Err(_) => { + // Fall back to /proc/self/auxv on error. } - return; - } - Err(_) => { - // Fall back to /proc/self/auxv on error. } } @@ -182,10 +200,17 @@ fn init_auxv() { // auxv records. let file = crate::fs::open("/proc/self/auxv", OFlags::RDONLY, Mode::empty()).unwrap(); - let _ = init_from_auxv_file(file); + #[cfg(feature = "alloc")] + init_from_auxv_file(file).unwrap(); + + #[cfg(not(feature = "alloc"))] + unsafe { + init_from_aux_iter(AuxFile(file)).unwrap(); + } } /// Process auxv entries from the open file `auxv`. +#[cfg(feature = "alloc")] #[cold] fn init_from_auxv_file(auxv: OwnedFd) -> Option<()> { let mut buffer = Vec::<u8>::with_capacity(512); @@ -211,7 +236,7 @@ fn init_from_auxv_file(auxv: OwnedFd) -> Option<()> { } // SAFETY: We loaded from an auxv file into the buffer. - unsafe { init_from_auxp(buffer.as_ptr().cast()) } + unsafe { init_from_aux_iter(AuxPointer(buffer.as_ptr().cast())) } } /// Process auxv entries from the auxv array pointed to by `auxp`. @@ -223,37 +248,50 @@ fn init_from_auxv_file(auxv: OwnedFd) -> Option<()> { /// The buffer contains `Elf_aux_t` elements, though it need not be aligned; /// function uses `read_unaligned` to read from it. #[cold] -unsafe fn init_from_auxp(mut auxp: *const Elf_auxv_t) -> Option<()> { +unsafe fn init_from_aux_iter(aux_iter: impl Iterator<Item = Elf_auxv_t>) -> Option<()> { let mut pagesz = 0; let mut clktck = 0; let mut hwcap = 0; let mut hwcap2 = 0; - let mut phdr = null_mut(); - let mut phnum = 0; let mut execfn = null_mut(); let mut sysinfo_ehdr = null_mut(); + #[cfg(feature = "runtime")] + let mut phdr = null_mut(); + #[cfg(feature = "runtime")] + let mut phnum = 0; + #[cfg(feature = "runtime")] let mut phent = 0; + #[cfg(feature = "runtime")] + let mut entry = 0; - loop { - let Elf_auxv_t { a_type, a_val } = read_unaligned(auxp); - + for Elf_auxv_t { a_type, a_val } in aux_iter { match a_type as _ { AT_PAGESZ => pagesz = a_val as usize, AT_CLKTCK => clktck = a_val as usize, AT_HWCAP => hwcap = a_val as usize, AT_HWCAP2 => hwcap2 = a_val as usize, + AT_EXECFN => execfn = check_raw_pointer::<c::c_char>(a_val as *mut _)?.as_ptr(), + AT_SYSINFO_EHDR => sysinfo_ehdr = check_elf_base(a_val as *mut _)?.as_ptr(), + + AT_BASE => { + let _ = check_elf_base(a_val.cast())?; + } + + #[cfg(feature = "runtime")] AT_PHDR => phdr = check_raw_pointer::<Elf_Phdr>(a_val as *mut _)?.as_ptr(), + #[cfg(feature = "runtime")] AT_PHNUM => phnum = a_val as usize, + #[cfg(feature = "runtime")] AT_PHENT => phent = a_val as usize, - AT_EXECFN => execfn = check_raw_pointer::<c::c_char>(a_val as *mut _)?.as_ptr(), - AT_BASE => check_interpreter_base(a_val.cast())?, - AT_SYSINFO_EHDR => sysinfo_ehdr = check_vdso_base(a_val as *mut _)?.as_ptr(), + #[cfg(feature = "runtime")] + AT_ENTRY => entry = a_val as usize, + AT_NULL => break, _ => (), } - auxp = auxp.add(1); } + #[cfg(feature = "runtime")] assert_eq!(phent, size_of::<Elf_Phdr>()); // The base and sysinfo_ehdr (if present) matches our platform. Accept @@ -262,86 +300,29 @@ unsafe fn init_from_auxp(mut auxp: *const Elf_auxv_t) -> Option<()> { CLOCK_TICKS_PER_SECOND.store(clktck, Relaxed); HWCAP.store(hwcap, Relaxed); HWCAP2.store(hwcap2, Relaxed); - PHDR.store(phdr, Relaxed); - PHNUM.store(phnum, Relaxed); EXECFN.store(execfn, Relaxed); SYSINFO_EHDR.store(sysinfo_ehdr, Relaxed); + #[cfg(feature = "runtime")] + PHDR.store(phdr, Relaxed); + #[cfg(feature = "runtime")] + PHNUM.store(phnum, Relaxed); + #[cfg(feature = "runtime")] + ENTRY.store(entry, Relaxed); Some(()) } -/// Check that `base` is a valid pointer to the program interpreter. -/// -/// `base` is some value we got from a `AT_BASE` aux record somewhere, -/// which hopefully holds the value of the program interpreter in memory. Do a -/// series of checks to be as sure as we can that it's safe to use. -#[cold] -unsafe fn check_interpreter_base(base: *const Elf_Ehdr) -> Option<()> { - check_elf_base(base)?; - Some(()) -} - /// Check that `base` is a valid pointer to the kernel-provided vDSO. /// /// `base` is some value we got from a `AT_SYSINFO_EHDR` aux record somewhere, /// which hopefully holds the value of the kernel-provided vDSO in memory. Do a /// series of checks to be as sure as we can that it's safe to use. #[cold] -unsafe fn check_vdso_base(base: *const Elf_Ehdr) -> Option<NonNull<Elf_Ehdr>> { - // In theory, we could check that we're not attempting to parse our own ELF - // image, as an additional check. However, older Linux toolchains don't - // support this, and Rust's `#[linkage = "extern_weak"]` isn't stable yet, - // so just disable this for now. - /* - { - extern "C" { - static __ehdr_start: c::c_void; - } - - let ehdr_start: *const c::c_void = &__ehdr_start; - if base == ehdr_start { - return None; - } - } - */ - - let hdr = check_elf_base(base)?; - - // Check that the ELF is not writable, since that would indicate that this - // isn't the ELF we think it is. Here we're just using `clock_getres` just - // as an arbitrary system call which writes to a buffer and fails with - // `EFAULT` if the buffer is not writable. - { - use crate::backend::conv::{c_uint, ret}; - if ret(syscall!( - __NR_clock_getres, - c_uint(linux_raw_sys::general::CLOCK_MONOTONIC), - base - )) != Err(crate::io::Errno::FAULT) - { - // We can't gracefully fail here because we would seem to have just - // mutated some unknown memory. - #[cfg(feature = "std")] - { - std::process::abort(); - } - #[cfg(all(not(feature = "std"), feature = "rustc-dep-of-std"))] - { - core::intrinsics::abort(); - } - } - } - - Some(hdr) -} - -/// Check that `base` is a valid pointer to an ELF image. -#[cold] unsafe fn check_elf_base(base: *const Elf_Ehdr) -> Option<NonNull<Elf_Ehdr>> { - // If we're reading a 64-bit auxv on a 32-bit platform, we'll see - // a zero `a_val` because `AT_*` values are never greater than - // `u32::MAX`. Zero is used by libc's `getauxval` to indicate - // errors, so it should never be a valid value. + // If we're reading a 64-bit auxv on a 32-bit platform, we'll see a zero + // `a_val` because `AT_*` values are never greater than `u32::MAX`. Zero is + // used by libc's `getauxval` to indicate errors, so it should never be a + // valid value. if base.is_null() { return None; } @@ -400,15 +381,46 @@ unsafe fn check_elf_base(base: *const Elf_Ehdr) -> Option<NonNull<Elf_Ehdr>> { Some(NonNull::new_unchecked(as_ptr(hdr) as *mut _)) } -// ELF ABI +// Aux reading utilities + +// Read auxv records from an array in memory. +struct AuxPointer(*const Elf_auxv_t); -#[repr(C)] -#[derive(Copy, Clone)] -struct Elf_auxv_t { - a_type: usize, +impl Iterator for AuxPointer { + type Item = Elf_auxv_t; - // Some of the values in the auxv array are pointers, so we make `a_val` a - // pointer, in order to preserve their provenance. For the values which are - // integers, we cast this to `usize`. - a_val: *const c_void, + #[cold] + fn next(&mut self) -> Option<Self::Item> { + unsafe { + let value = read_unaligned(self.0); + self.0 = self.0.add(1); + Some(value) + } + } +} + +// Read auxv records from a file. +#[cfg(not(feature = "alloc"))] +struct AuxFile(OwnedFd); + +#[cfg(not(feature = "alloc"))] +impl Iterator for AuxFile { + type Item = Elf_auxv_t; + + // This implementation does lots of `read`s and it isn't amazing, but + // hopefully we won't use it often. + #[cold] + fn next(&mut self) -> Option<Self::Item> { + let mut buf = [0_u8; size_of::<Self::Item>()]; + let mut slice = &mut buf[..]; + while !slice.is_empty() { + match crate::io::read(&self.0, slice) { + Ok(0) => panic!("unexpected end of auxv file"), + Ok(n) => slice = &mut slice[n..], + Err(crate::io::Errno::INTR) => continue, + Err(err) => Err(err).unwrap(), + } + } + Some(unsafe { read_unaligned(buf.as_ptr().cast()) }) + } } diff --git a/vendor/rustix/src/backend/linux_raw/param/init.rs b/vendor/rustix/src/backend/linux_raw/param/init.rs new file mode 100644 index 000000000..46aae009a --- /dev/null +++ b/vendor/rustix/src/backend/linux_raw/param/init.rs @@ -0,0 +1,149 @@ +//! Linux auxv `init` function, for "use-explicitly-provided-auxv" mode. +//! +//! # Safety +//! +//! This uses raw pointers to locate and read the kernel-provided auxv array. +#![allow(unsafe_code)] + +use crate::backend::c; +#[cfg(feature = "param")] +use crate::ffi::CStr; +use core::ffi::c_void; +use core::ptr::{null_mut, read, NonNull}; +use core::sync::atomic::{AtomicPtr, AtomicUsize, Ordering}; +use linux_raw_sys::elf::*; +use linux_raw_sys::general::{ + AT_CLKTCK, AT_EXECFN, AT_HWCAP, AT_HWCAP2, AT_NULL, AT_PAGESZ, AT_SYSINFO_EHDR, +}; +#[cfg(feature = "runtime")] +use linux_raw_sys::general::{AT_ENTRY, AT_PHDR, AT_PHENT, AT_PHNUM}; + +#[cfg(feature = "param")] +#[inline] +pub(crate) fn page_size() -> usize { + unsafe { PAGE_SIZE.load(Ordering::Relaxed) } +} + +#[cfg(feature = "param")] +#[inline] +pub(crate) fn clock_ticks_per_second() -> u64 { + unsafe { CLOCK_TICKS_PER_SECOND.load(Ordering::Relaxed) as u64 } +} + +#[cfg(feature = "param")] +#[inline] +pub(crate) fn linux_hwcap() -> (usize, usize) { + unsafe { + ( + HWCAP.load(Ordering::Relaxed), + HWCAP2.load(Ordering::Relaxed), + ) + } +} + +#[cfg(feature = "param")] +#[inline] +pub(crate) fn linux_execfn() -> &'static CStr { + let execfn = unsafe { EXECFN.load(Ordering::Relaxed) }; + + // SAFETY: We initialize `EXECFN` to a valid `CStr` pointer, and we assume + // the `AT_EXECFN` value provided by the kernel points to a valid C string. + unsafe { CStr::from_ptr(execfn.cast()) } +} + +#[cfg(feature = "runtime")] +#[inline] +pub(crate) fn exe_phdrs() -> (*const c_void, usize, usize) { + unsafe { + ( + PHDR.load(Ordering::Relaxed).cast(), + PHENT.load(Ordering::Relaxed), + PHNUM.load(Ordering::Relaxed), + ) + } +} + +/// `AT_SYSINFO_EHDR` isn't present on all platforms in all configurations, so +/// if we don't see it, this function returns a null pointer. +#[inline] +pub(in super::super) fn sysinfo_ehdr() -> *const Elf_Ehdr { + unsafe { SYSINFO_EHDR.load(Ordering::Relaxed) } +} + +#[cfg(feature = "runtime")] +#[inline] +pub(crate) fn entry() -> usize { + unsafe { ENTRY.load(Ordering::Relaxed) } +} + +static mut PAGE_SIZE: AtomicUsize = AtomicUsize::new(0); +static mut CLOCK_TICKS_PER_SECOND: AtomicUsize = AtomicUsize::new(0); +static mut HWCAP: AtomicUsize = AtomicUsize::new(0); +static mut HWCAP2: AtomicUsize = AtomicUsize::new(0); +static mut SYSINFO_EHDR: AtomicPtr<Elf_Ehdr> = AtomicPtr::new(null_mut()); +// Initialize `EXECFN` to a valid `CStr` pointer so that we don't need to check +// for null on every `execfn` call. +static mut EXECFN: AtomicPtr<c::c_char> = AtomicPtr::new(b"\0".as_ptr() as _); +// Use `dangling` so that we can always treat it like an empty slice. +#[cfg(feature = "runtime")] +static mut PHDR: AtomicPtr<Elf_Phdr> = AtomicPtr::new(NonNull::dangling().as_ptr()); +#[cfg(feature = "runtime")] +static mut PHENT: AtomicUsize = AtomicUsize::new(0); +#[cfg(feature = "runtime")] +static mut PHNUM: AtomicUsize = AtomicUsize::new(0); +#[cfg(feature = "runtime")] +static mut ENTRY: AtomicUsize = AtomicUsize::new(0); + +/// When "use-explicitly-provided-auxv" is enabled, we export a function to be +/// called during initialization, and passed a pointer to the original +/// environment variable block set up by the OS. +pub(crate) unsafe fn init(envp: *mut *mut u8) { + init_from_envp(envp); +} + +/// # Safety +/// +/// This must be passed a pointer to the environment variable buffer +/// provided by the kernel, which is followed in memory by the auxv array. +unsafe fn init_from_envp(mut envp: *mut *mut u8) { + while !(*envp).is_null() { + envp = envp.add(1); + } + init_from_auxp(envp.add(1).cast()) +} + +/// Process auxv entries from the auxv array pointed to by `auxp`. +/// +/// # Safety +/// +/// This must be passed a pointer to an auxv array. +/// +/// The buffer contains `Elf_aux_t` elements, though it need not be aligned; +/// function uses `read_unaligned` to read from it. +unsafe fn init_from_auxp(mut auxp: *const Elf_auxv_t) { + loop { + let Elf_auxv_t { a_type, a_val } = read(auxp); + + match a_type as _ { + AT_PAGESZ => PAGE_SIZE.store(a_val as usize, Ordering::Relaxed), + AT_CLKTCK => CLOCK_TICKS_PER_SECOND.store(a_val as usize, Ordering::Relaxed), + AT_HWCAP => HWCAP.store(a_val as usize, Ordering::Relaxed), + AT_HWCAP2 => HWCAP2.store(a_val as usize, Ordering::Relaxed), + AT_EXECFN => EXECFN.store(a_val.cast::<c::c_char>(), Ordering::Relaxed), + AT_SYSINFO_EHDR => SYSINFO_EHDR.store(a_val.cast::<Elf_Ehdr>(), Ordering::Relaxed), + + #[cfg(feature = "runtime")] + AT_PHDR => PHDR.store(a_val.cast::<Elf_Phdr>(), Ordering::Relaxed), + #[cfg(feature = "runtime")] + AT_PHNUM => PHNUM.store(a_val as usize, Ordering::Relaxed), + #[cfg(feature = "runtime")] + AT_PHENT => PHENT.store(a_val as usize, Ordering::Relaxed), + #[cfg(feature = "runtime")] + AT_ENTRY => ENTRY.store(a_val as usize, Ordering::Relaxed), + + AT_NULL => break, + _ => (), + } + auxp = auxp.add(1); + } +} diff --git a/vendor/rustix/src/backend/linux_raw/param/libc_auxv.rs b/vendor/rustix/src/backend/linux_raw/param/libc_auxv.rs index 97739fcb5..0e6ca6ed5 100644 --- a/vendor/rustix/src/backend/linux_raw/param/libc_auxv.rs +++ b/vendor/rustix/src/backend/linux_raw/param/libc_auxv.rs @@ -6,35 +6,39 @@ #![allow(unsafe_code)] use crate::backend::c; -use crate::backend::elf::*; #[cfg(feature = "param")] use crate::ffi::CStr; #[cfg(not(feature = "runtime"))] use core::ptr::null; -#[cfg(feature = "runtime")] -use core::slice; +use linux_raw_sys::elf::*; // `getauxval` wasn't supported in glibc until 2.16. Also this lets us use // `*mut` as the return type to preserve strict provenance. #[cfg(not(feature = "runtime"))] weak!(fn getauxval(c::c_ulong) -> *mut c::c_void); -// With the "runtime" feature, go ahead and depend on `getauxval` existing -// so that we never fail. +// With the "runtime" feature, go ahead and depend on `getauxval` existing so +// that we never fail. #[cfg(feature = "runtime")] extern "C" { fn getauxval(type_: c::c_ulong) -> *mut c::c_void; } +#[cfg(feature = "runtime")] const AT_PHDR: c::c_ulong = 3; +#[cfg(feature = "runtime")] +const AT_PHENT: c::c_ulong = 4; +#[cfg(feature = "runtime")] const AT_PHNUM: c::c_ulong = 5; +#[cfg(feature = "runtime")] +const AT_ENTRY: c::c_ulong = 9; const AT_HWCAP: c::c_ulong = 16; const AT_HWCAP2: c::c_ulong = 26; const AT_EXECFN: c::c_ulong = 31; const AT_SYSINFO_EHDR: c::c_ulong = 33; -// Declare `sysconf` ourselves so that we don't depend on all of libc -// just for this. +// Declare `sysconf` ourselves so that we don't depend on all of libc just for +// this. extern "C" { fn sysconf(name: c::c_int) -> c::c_long; } @@ -52,12 +56,16 @@ const _SC_CLK_TCK: c::c_int = 2; fn test_abi() { const_assert_eq!(self::_SC_PAGESIZE, ::libc::_SC_PAGESIZE); const_assert_eq!(self::_SC_CLK_TCK, ::libc::_SC_CLK_TCK); - const_assert_eq!(self::AT_PHDR, ::libc::AT_PHDR); - const_assert_eq!(self::AT_PHNUM, ::libc::AT_PHNUM); const_assert_eq!(self::AT_HWCAP, ::libc::AT_HWCAP); const_assert_eq!(self::AT_HWCAP2, ::libc::AT_HWCAP2); const_assert_eq!(self::AT_EXECFN, ::libc::AT_EXECFN); const_assert_eq!(self::AT_SYSINFO_EHDR, ::libc::AT_SYSINFO_EHDR); + #[cfg(feature = "runtime")] + const_assert_eq!(self::AT_PHDR, ::libc::AT_PHDR); + #[cfg(feature = "runtime")] + const_assert_eq!(self::AT_PHNUM, ::libc::AT_PHNUM); + #[cfg(feature = "runtime")] + const_assert_eq!(self::AT_ENTRY, ::libc::AT_ENTRY); } #[cfg(feature = "param")] @@ -114,24 +122,15 @@ pub(crate) fn linux_execfn() -> &'static CStr { #[cfg(feature = "runtime")] #[inline] -pub(crate) fn exe_phdrs() -> (*const c::c_void, usize) { +pub(crate) fn exe_phdrs() -> (*const c::c_void, usize, usize) { unsafe { let phdr = getauxval(AT_PHDR) as *const c::c_void; + let phent = getauxval(AT_PHENT) as usize; let phnum = getauxval(AT_PHNUM) as usize; - (phdr, phnum) + (phdr, phent, phnum) } } -#[cfg(feature = "runtime")] -#[inline] -pub(in super::super) fn exe_phdrs_slice() -> &'static [Elf_Phdr] { - let (phdr, phnum) = exe_phdrs(); - - // SAFETY: We assume the `AT_PHDR` and `AT_PHNUM` values provided by the - // kernel form a valid slice. - unsafe { slice::from_raw_parts(phdr.cast(), phnum) } -} - /// `AT_SYSINFO_EHDR` isn't present on all platforms in all configurations, /// so if we don't see it, this function returns a null pointer. #[inline] @@ -150,3 +149,9 @@ pub(in super::super) fn sysinfo_ehdr() -> *const Elf_Ehdr { getauxval(AT_SYSINFO_EHDR) as *const Elf_Ehdr } } + +#[cfg(feature = "runtime")] +#[inline] +pub(crate) fn entry() -> usize { + unsafe { getauxval(AT_ENTRY) as usize } +} diff --git a/vendor/rustix/src/backend/linux_raw/param/mod.rs b/vendor/rustix/src/backend/linux_raw/param/mod.rs index 956282074..365f01604 100644 --- a/vendor/rustix/src/backend/linux_raw/param/mod.rs +++ b/vendor/rustix/src/backend/linux_raw/param/mod.rs @@ -1,12 +1,15 @@ -// On Mustang, origin is in control of program startup and can access the -// incoming aux values on the stack. +// With "use-explicitly-provided-auxv" enabled, we expect to be initialized +// with an explicit `rustix::param::init` call. // // With "use-libc-auxv" enabled, use libc's `getauxval`. // // Otherwise, we read aux values from /proc/self/auxv. -#[cfg_attr(target_vendor = "mustang", path = "mustang_auxv.rs")] +#[cfg_attr(feature = "use-explicitly-provided-auxv", path = "init.rs")] #[cfg_attr( - all(not(target_vendor = "mustang"), feature = "use-libc-auxv"), + all( + not(feature = "use-explicitly-provided-auxv"), + feature = "use-libc-auxv" + ), path = "libc_auxv.rs" )] pub(crate) mod auxv; diff --git a/vendor/rustix/src/backend/linux_raw/param/mustang_auxv.rs b/vendor/rustix/src/backend/linux_raw/param/mustang_auxv.rs deleted file mode 100644 index f45a25faf..000000000 --- a/vendor/rustix/src/backend/linux_raw/param/mustang_auxv.rs +++ /dev/null @@ -1,159 +0,0 @@ -//! Linux auxv support, for Mustang. -//! -//! # Safety -//! -//! This uses raw pointers to locate and read the kernel-provided auxv array. -#![allow(unsafe_code)] - -use crate::backend::c; -use crate::backend::elf::*; -#[cfg(feature = "param")] -use crate::ffi::CStr; -use core::ffi::c_void; -use core::mem::size_of; -use core::ptr::{null, read}; -#[cfg(feature = "runtime")] -use core::slice; -use linux_raw_sys::general::{ - AT_CLKTCK, AT_EXECFN, AT_HWCAP, AT_HWCAP2, AT_NULL, AT_PAGESZ, AT_PHDR, AT_PHENT, AT_PHNUM, - AT_SYSINFO_EHDR, -}; - -#[cfg(feature = "param")] -#[inline] -pub(crate) fn page_size() -> usize { - // SAFETY: This is initialized during program startup. - unsafe { PAGE_SIZE } -} - -#[cfg(feature = "param")] -#[inline] -pub(crate) fn clock_ticks_per_second() -> u64 { - // SAFETY: This is initialized during program startup. - unsafe { CLOCK_TICKS_PER_SECOND as u64 } -} - -#[cfg(feature = "param")] -#[inline] -pub(crate) fn linux_hwcap() -> (usize, usize) { - // SAFETY: This is initialized during program startup. - unsafe { (HWCAP, HWCAP2) } -} - -#[cfg(feature = "param")] -#[inline] -pub(crate) fn linux_execfn() -> &'static CStr { - // SAFETY: This is initialized during program startup. And we - // assume it's a valid pointer to a NUL-terminated string. - unsafe { CStr::from_ptr(EXECFN.0.cast()) } -} - -#[cfg(feature = "runtime")] -#[inline] -pub(crate) fn exe_phdrs() -> (*const c_void, usize) { - // SAFETY: This is initialized during program startup. - unsafe { (PHDR.0.cast(), PHNUM) } -} - -#[cfg(feature = "runtime")] -#[inline] -pub(in super::super) fn exe_phdrs_slice() -> &'static [Elf_Phdr] { - let (phdr, phnum) = exe_phdrs(); - - // SAFETY: We assume the `AT_PHDR` and `AT_PHNUM` values provided by the - // kernel form a valid slice. - unsafe { slice::from_raw_parts(phdr.cast(), phnum) } -} - -/// `AT_SYSINFO_EHDR` isn't present on all platforms in all configurations, -/// so if we don't see it, this function returns a null pointer. -#[inline] -pub(in super::super) fn sysinfo_ehdr() -> *const Elf_Ehdr { - // SAFETY: This is initialized during program startup. - unsafe { SYSINFO_EHDR.0 } -} - -/// A const pointer to `T` that implements [`Sync`]. -#[repr(transparent)] -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub struct SyncConstPtr<T>(*const T); -unsafe impl<T> Sync for SyncConstPtr<T> {} - -impl<T> SyncConstPtr<T> { - /// Creates a `SyncConstPointer` from a raw pointer. - /// - /// Behavior is undefined if `ptr` is actually not - /// safe to share across threads. - pub const unsafe fn new(ptr: *const T) -> Self { - Self(ptr) - } -} - -static mut PAGE_SIZE: usize = 0; -static mut CLOCK_TICKS_PER_SECOND: usize = 0; -static mut HWCAP: usize = 0; -static mut HWCAP2: usize = 0; -static mut SYSINFO_EHDR: SyncConstPtr<Elf_Ehdr> = unsafe { SyncConstPtr::new(null()) }; -static mut PHDR: SyncConstPtr<Elf_Phdr> = unsafe { SyncConstPtr::new(null()) }; -static mut PHNUM: usize = 0; -static mut EXECFN: SyncConstPtr<c::c_char> = unsafe { SyncConstPtr::new(null()) }; - -/// On mustang, we export a function to be called during initialization, and -/// passed a pointer to the original environment variable block set up by the -/// OS. -pub(crate) unsafe fn init(envp: *mut *mut u8) { - init_from_envp(envp); -} - -/// # Safety -/// -/// This must be passed a pointer to the environment variable buffer -/// provided by the kernel, which is followed in memory by the auxv array. -unsafe fn init_from_envp(mut envp: *mut *mut u8) { - while !(*envp).is_null() { - envp = envp.add(1); - } - init_from_auxp(envp.add(1).cast()) -} - -/// Process auxv entries from the auxv array pointed to by `auxp`. -/// -/// # Safety -/// -/// This must be passed a pointer to an auxv array. -/// -/// The buffer contains `Elf_aux_t` elements, though it need not be aligned; -/// function uses `read_unaligned` to read from it. -unsafe fn init_from_auxp(mut auxp: *const Elf_auxv_t) { - loop { - let Elf_auxv_t { a_type, a_val } = read(auxp); - - match a_type as _ { - AT_PAGESZ => PAGE_SIZE = a_val as usize, - AT_CLKTCK => CLOCK_TICKS_PER_SECOND = a_val as usize, - AT_HWCAP => HWCAP = a_val as usize, - AT_HWCAP2 => HWCAP2 = a_val as usize, - AT_PHDR => PHDR = SyncConstPtr::new(a_val.cast::<Elf_Phdr>()), - AT_PHNUM => PHNUM = a_val as usize, - AT_PHENT => assert_eq!(a_val as usize, size_of::<Elf_Phdr>()), - AT_EXECFN => EXECFN = SyncConstPtr::new(a_val.cast::<c::c_char>()), - AT_SYSINFO_EHDR => SYSINFO_EHDR = SyncConstPtr::new(a_val.cast::<Elf_Ehdr>()), - AT_NULL => break, - _ => (), - } - auxp = auxp.add(1); - } -} - -// ELF ABI - -#[repr(C)] -#[derive(Copy, Clone)] -struct Elf_auxv_t { - a_type: usize, - - // Some of the values in the auxv array are pointers, so we make `a_val` a - // pointer, in order to preserve their provenance. For the values which are - // integers, we cast this to `usize`. - a_val: *const c_void, -} diff --git a/vendor/rustix/src/backend/linux_raw/pid/syscalls.rs b/vendor/rustix/src/backend/linux_raw/pid/syscalls.rs index f36bac048..9665ab3e9 100644 --- a/vendor/rustix/src/backend/linux_raw/pid/syscalls.rs +++ b/vendor/rustix/src/backend/linux_raw/pid/syscalls.rs @@ -3,8 +3,7 @@ //! # Safety //! //! See the `rustix::backend` module documentation for details. -#![allow(unsafe_code)] -#![allow(clippy::undocumented_unsafe_blocks)] +#![allow(unsafe_code, clippy::undocumented_unsafe_blocks)] use crate::backend::conv::ret_usize_infallible; use crate::pid::{Pid, RawPid}; diff --git a/vendor/rustix/src/backend/linux_raw/pipe/syscalls.rs b/vendor/rustix/src/backend/linux_raw/pipe/syscalls.rs index e05094237..ec3e459be 100644 --- a/vendor/rustix/src/backend/linux_raw/pipe/syscalls.rs +++ b/vendor/rustix/src/backend/linux_raw/pipe/syscalls.rs @@ -3,8 +3,7 @@ //! # Safety //! //! See the `rustix::backend` module documentation for details. -#![allow(unsafe_code)] -#![allow(clippy::undocumented_unsafe_blocks)] +#![allow(unsafe_code, clippy::undocumented_unsafe_blocks)] use crate::backend::conv::{c_int, c_uint, opt_mut, pass_usize, ret, ret_usize, slice}; use crate::backend::{c, MAX_IOV}; @@ -59,9 +58,9 @@ pub(crate) fn pipe_with(flags: PipeFlags) -> io::Result<(OwnedFd, OwnedFd)> { #[inline] pub fn splice( - fd_in: BorrowedFd, + fd_in: BorrowedFd<'_>, off_in: Option<&mut u64>, - fd_out: BorrowedFd, + fd_out: BorrowedFd<'_>, off_out: Option<&mut u64>, len: usize, flags: SpliceFlags, @@ -81,8 +80,8 @@ pub fn splice( #[inline] pub unsafe fn vmsplice( - fd: BorrowedFd, - bufs: &[IoSliceRaw], + fd: BorrowedFd<'_>, + bufs: &[IoSliceRaw<'_>], flags: SpliceFlags, ) -> io::Result<usize> { let (bufs_addr, bufs_len) = slice(&bufs[..cmp::min(bufs.len(), MAX_IOV)]); @@ -91,8 +90,8 @@ pub unsafe fn vmsplice( #[inline] pub fn tee( - fd_in: BorrowedFd, - fd_out: BorrowedFd, + fd_in: BorrowedFd<'_>, + fd_out: BorrowedFd<'_>, len: usize, flags: SpliceFlags, ) -> io::Result<usize> { diff --git a/vendor/rustix/src/backend/linux_raw/pipe/types.rs b/vendor/rustix/src/backend/linux_raw/pipe/types.rs index 90d2d79ab..c950b5d0a 100644 --- a/vendor/rustix/src/backend/linux_raw/pipe/types.rs +++ b/vendor/rustix/src/backend/linux_raw/pipe/types.rs @@ -15,6 +15,9 @@ bitflags! { const DIRECT = linux_raw_sys::general::O_DIRECT; /// `O_NONBLOCK` const NONBLOCK = linux_raw_sys::general::O_NONBLOCK; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -32,6 +35,9 @@ bitflags! { const MORE = linux_raw_sys::general::SPLICE_F_MORE; /// `SPLICE_F_GIFT` const GIFT = linux_raw_sys::general::SPLICE_F_GIFT; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } diff --git a/vendor/rustix/src/backend/linux_raw/prctl/syscalls.rs b/vendor/rustix/src/backend/linux_raw/prctl/syscalls.rs index 193f4b7b4..1410d5128 100644 --- a/vendor/rustix/src/backend/linux_raw/prctl/syscalls.rs +++ b/vendor/rustix/src/backend/linux_raw/prctl/syscalls.rs @@ -3,8 +3,7 @@ //! # Safety //! //! See the `rustix::backend` module documentation for details. -#![allow(unsafe_code)] -#![allow(clippy::undocumented_unsafe_blocks)] +#![allow(unsafe_code, clippy::undocumented_unsafe_blocks)] use crate::backend::c; use crate::backend::conv::{c_int, ret_c_int}; diff --git a/vendor/rustix/src/backend/linux_raw/process/syscalls.rs b/vendor/rustix/src/backend/linux_raw/process/syscalls.rs index 5ec2755ff..c0416bf5a 100644 --- a/vendor/rustix/src/backend/linux_raw/process/syscalls.rs +++ b/vendor/rustix/src/backend/linux_raw/process/syscalls.rs @@ -3,17 +3,16 @@ //! # Safety //! //! See the `rustix::backend` module documentation for details. -#![allow(unsafe_code)] -#![allow(clippy::undocumented_unsafe_blocks)] +#![allow(unsafe_code, clippy::undocumented_unsafe_blocks)] use super::types::RawCpuSet; use crate::backend::c; -#[cfg(feature = "fs")] +#[cfg(all(feature = "alloc", feature = "fs"))] use crate::backend::conv::slice_mut; use crate::backend::conv::{ by_mut, by_ref, c_int, c_uint, negative_pid, pass_usize, raw_fd, ret, ret_c_int, ret_c_int_infallible, ret_c_uint, ret_infallible, ret_owned_fd, ret_usize, size_of, - slice_just_addr, slice_just_addr_mut, zero, + slice_just_addr, zero, }; use crate::fd::{AsRawFd, BorrowedFd, OwnedFd, RawFd}; #[cfg(feature = "fs")] @@ -21,8 +20,8 @@ use crate::ffi::CStr; use crate::io; use crate::pid::RawPid; use crate::process::{ - Cpuid, Gid, MembarrierCommand, MembarrierQuery, Pid, PidfdFlags, PidfdGetfdFlags, Resource, - Rlimit, Uid, WaitId, WaitOptions, WaitStatus, WaitidOptions, WaitidStatus, + Cpuid, MembarrierCommand, MembarrierQuery, Pid, PidfdFlags, PidfdGetfdFlags, Resource, Rlimit, + Uid, WaitId, WaitOptions, WaitStatus, WaitidOptions, WaitidStatus, }; use crate::signal::Signal; use crate::utils::as_mut_ptr; @@ -32,9 +31,10 @@ use linux_raw_sys::general::{ membarrier_cmd, membarrier_cmd_flag, rlimit, rlimit64, PRIO_PGRP, PRIO_PROCESS, PRIO_USER, RLIM64_INFINITY, RLIM_INFINITY, }; -use linux_raw_sys::ioctl::TIOCSCTTY; #[cfg(feature = "fs")] use {crate::backend::conv::ret_c_uint_infallible, crate::fs::Mode}; +#[cfg(feature = "alloc")] +use {crate::backend::conv::slice_just_addr_mut, crate::process::Gid}; #[cfg(feature = "fs")] #[inline] @@ -53,7 +53,7 @@ pub(crate) fn chroot(filename: &CStr) -> io::Result<()> { unsafe { ret(syscall_readonly!(__NR_chroot, filename)) } } -#[cfg(feature = "fs")] +#[cfg(all(feature = "alloc", feature = "fs"))] #[inline] pub(crate) fn getcwd(buf: &mut [MaybeUninit<u8>]) -> io::Result<usize> { let (buf_addr_mut, buf_len) = slice_mut(buf); @@ -365,12 +365,12 @@ pub(crate) fn prlimit(pid: Option<Pid>, limit: Resource, new: Rlimit) -> io::Res /// Convert a Rust [`Rlimit`] to a C `rlimit64`. #[inline] fn rlimit_from_linux(lim: rlimit64) -> Rlimit { - let current = if lim.rlim_cur == RLIM64_INFINITY as _ { + let current = if lim.rlim_cur as u64 == RLIM64_INFINITY as u64 { None } else { Some(lim.rlim_cur) }; - let maximum = if lim.rlim_max == RLIM64_INFINITY as _ { + let maximum = if lim.rlim_max as u64 == RLIM64_INFINITY as u64 { None } else { Some(lim.rlim_max) @@ -395,12 +395,12 @@ fn rlimit_to_linux(lim: Rlimit) -> rlimit64 { /// Like `rlimit_from_linux` but uses Linux's old 32-bit `rlimit`. #[allow(clippy::useless_conversion)] fn rlimit_from_linux_old(lim: rlimit) -> Rlimit { - let current = if lim.rlim_cur == RLIM_INFINITY as _ { + let current = if lim.rlim_cur as u32 == RLIM_INFINITY as u32 { None } else { Some(lim.rlim_cur.into()) }; - let maximum = if lim.rlim_max == RLIM_INFINITY as _ { + let maximum = if lim.rlim_max as u32 == RLIM_INFINITY as u32 { None } else { Some(lim.rlim_max.into()) @@ -610,6 +610,7 @@ pub(crate) fn pidfd_open(pid: Pid, flags: PidfdFlags) -> io::Result<OwnedFd> { unsafe { ret_owned_fd(syscall_readonly!(__NR_pidfd_open, pid, flags)) } } +#[cfg(feature = "alloc")] #[inline] pub(crate) fn getgroups(buf: &mut [Gid]) -> io::Result<usize> { let len = buf.len().try_into().map_err(|_| io::Errno::NOMEM)?; @@ -622,15 +623,3 @@ pub(crate) fn getgroups(buf: &mut [Gid]) -> io::Result<usize> { )) } } - -#[inline] -pub(crate) fn ioctl_tiocsctty(fd: BorrowedFd<'_>) -> io::Result<()> { - unsafe { - ret(syscall_readonly!( - __NR_ioctl, - fd, - c_uint(TIOCSCTTY), - by_ref(&0_u32) - )) - } -} diff --git a/vendor/rustix/src/backend/linux_raw/process/types.rs b/vendor/rustix/src/backend/linux_raw/process/types.rs index f31749b83..841668a60 100644 --- a/vendor/rustix/src/backend/linux_raw/process/types.rs +++ b/vendor/rustix/src/backend/linux_raw/process/types.rs @@ -1,4 +1,3 @@ -use crate::backend::c; use linux_raw_sys::general::membarrier_cmd; /// A command for use with [`membarrier`] and [`membarrier_cpu`]. @@ -78,15 +77,6 @@ pub enum Resource { Rttime = linux_raw_sys::general::RLIMIT_RTTIME, } -/// `EXIT_SUCCESS` -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 a [`Signal::Abort`] signal. -/// -/// [`Signal::Abort`]: crate::process::Signal::Abort -pub const EXIT_SIGNALED_SIGABRT: c::c_int = 128 + linux_raw_sys::general::SIGABRT as i32; - /// A CPU identifier as a raw integer. pub type RawCpuid = u32; diff --git a/vendor/rustix/src/backend/linux_raw/pty/syscalls.rs b/vendor/rustix/src/backend/linux_raw/pty/syscalls.rs index 529564c34..b64344fb9 100644 --- a/vendor/rustix/src/backend/linux_raw/pty/syscalls.rs +++ b/vendor/rustix/src/backend/linux_raw/pty/syscalls.rs @@ -3,22 +3,21 @@ //! # Safety //! //! See the `rustix::backend` module documentation for details. -#![allow(unsafe_code)] -#![allow(clippy::undocumented_unsafe_blocks)] +#![allow(unsafe_code, clippy::undocumented_unsafe_blocks)] -use crate::backend::c; -use crate::backend::conv::{by_ref, c_uint, ret, ret_owned_fd}; -use crate::fd::{BorrowedFd, OwnedFd}; -use crate::ffi::CString; +use crate::backend::conv::{by_ref, c_uint, ret}; +use crate::fd::BorrowedFd; use crate::io; -use crate::path::DecInt; -use crate::pty::OpenptFlags; -use alloc::vec::Vec; -use core::mem::MaybeUninit; -use linux_raw_sys::ioctl::{TIOCGPTN, TIOCGPTPEER, TIOCSPTLCK}; +use linux_raw_sys::ioctl::TIOCSPTLCK; +#[cfg(feature = "alloc")] +use { + crate::backend::c, crate::ffi::CString, crate::path::DecInt, alloc::vec::Vec, + core::mem::MaybeUninit, linux_raw_sys::ioctl::TIOCGPTN, +}; +#[cfg(feature = "alloc")] #[inline] -pub(crate) fn ptsname(fd: BorrowedFd, mut buffer: Vec<u8>) -> io::Result<CString> { +pub(crate) fn ptsname(fd: BorrowedFd<'_>, mut buffer: Vec<u8>) -> io::Result<CString> { unsafe { let mut n = MaybeUninit::<c::c_int>::uninit(); ret(syscall!(__NR_ioctl, fd, c_uint(TIOCGPTN), &mut n))?; @@ -32,7 +31,7 @@ pub(crate) fn ptsname(fd: BorrowedFd, mut buffer: Vec<u8>) -> io::Result<CString } #[inline] -pub(crate) fn unlockpt(fd: BorrowedFd) -> io::Result<()> { +pub(crate) fn unlockpt(fd: BorrowedFd<'_>) -> io::Result<()> { unsafe { ret(syscall_readonly!( __NR_ioctl, @@ -42,16 +41,3 @@ pub(crate) fn unlockpt(fd: BorrowedFd) -> io::Result<()> { )) } } - -#[cfg(target_os = "linux")] -#[inline] -pub(crate) fn ioctl_tiocgptpeer(fd: BorrowedFd, flags: OpenptFlags) -> io::Result<OwnedFd> { - unsafe { - ret_owned_fd(syscall_readonly!( - __NR_ioctl, - fd, - c_uint(TIOCGPTPEER), - flags - )) - } -} diff --git a/vendor/rustix/src/backend/linux_raw/rand/syscalls.rs b/vendor/rustix/src/backend/linux_raw/rand/syscalls.rs index 95a6efcff..e744f3193 100644 --- a/vendor/rustix/src/backend/linux_raw/rand/syscalls.rs +++ b/vendor/rustix/src/backend/linux_raw/rand/syscalls.rs @@ -3,8 +3,7 @@ //! # Safety //! //! See the `rustix::backend` module documentation for details. -#![allow(unsafe_code)] -#![allow(clippy::undocumented_unsafe_blocks)] +#![allow(unsafe_code, clippy::undocumented_unsafe_blocks)] use crate::backend::conv::{ret_usize, slice_mut}; use crate::io; diff --git a/vendor/rustix/src/backend/linux_raw/rand/types.rs b/vendor/rustix/src/backend/linux_raw/rand/types.rs index 21e950015..47b996d30 100644 --- a/vendor/rustix/src/backend/linux_raw/rand/types.rs +++ b/vendor/rustix/src/backend/linux_raw/rand/types.rs @@ -13,5 +13,8 @@ bitflags! { const NONBLOCK = linux_raw_sys::general::GRND_NONBLOCK; /// `GRND_INSECURE` const INSECURE = linux_raw_sys::general::GRND_INSECURE; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } diff --git a/vendor/rustix/src/backend/linux_raw/runtime/syscalls.rs b/vendor/rustix/src/backend/linux_raw/runtime/syscalls.rs index f82e2187b..c1ff3d239 100644 --- a/vendor/rustix/src/backend/linux_raw/runtime/syscalls.rs +++ b/vendor/rustix/src/backend/linux_raw/runtime/syscalls.rs @@ -3,8 +3,7 @@ //! # Safety //! //! See the `rustix::backend` module documentation for details. -#![allow(unsafe_code)] -#![allow(clippy::undocumented_unsafe_blocks)] +#![allow(unsafe_code, clippy::undocumented_unsafe_blocks)] use crate::backend::c; #[cfg(target_arch = "x86")] @@ -93,7 +92,10 @@ pub(crate) mod tls { ret_infallible(syscall_readonly!( __NR_arch_prctl, c_uint(ARCH_SET_FS), - data + data, + zero(), + zero(), + zero() )) } @@ -105,7 +107,14 @@ pub(crate) mod tls { #[inline] pub(crate) unsafe fn set_thread_name(name: &CStr) -> io::Result<()> { - ret(syscall_readonly!(__NR_prctl, c_uint(PR_SET_NAME), name)) + ret(syscall_readonly!( + __NR_prctl, + c_uint(PR_SET_NAME), + name, + zero(), + zero(), + zero() + )) } #[inline] diff --git a/vendor/rustix/src/backend/linux_raw/runtime/tls.rs b/vendor/rustix/src/backend/linux_raw/runtime/tls.rs index 763971591..ad1634894 100644 --- a/vendor/rustix/src/backend/linux_raw/runtime/tls.rs +++ b/vendor/rustix/src/backend/linux_raw/runtime/tls.rs @@ -7,9 +7,9 @@ #![allow(unsafe_code)] use crate::backend::c; -use crate::backend::elf::*; -use crate::backend::param::auxv::exe_phdrs_slice; -use core::ptr::null; +use crate::backend::param::auxv::exe_phdrs; +use core::ptr::{null, NonNull}; +use linux_raw_sys::elf::*; /// For use with [`set_thread_area`]. /// @@ -22,26 +22,41 @@ pub(crate) fn startup_tls_info() -> StartupTlsInfo { let mut tls_phdr = null(); let mut stack_size = 0; - let phdrs = exe_phdrs_slice(); + let (first_phdr, phent, phnum) = exe_phdrs(); + let mut current_phdr = first_phdr.cast::<Elf_Phdr>(); // SAFETY: We assume the phdr array pointer and length the kernel provided // to the process describe a valid phdr array. unsafe { - for phdr in phdrs { + let phdrs_end = current_phdr.cast::<u8>().add(phnum * phent).cast(); + while current_phdr != phdrs_end { + let phdr = &*current_phdr; + current_phdr = current_phdr.cast::<u8>().add(phent).cast(); + match phdr.p_type { - PT_PHDR => base = phdrs.as_ptr().cast::<u8>().sub(phdr.p_vaddr), + PT_PHDR => base = first_phdr.cast::<u8>().sub(phdr.p_vaddr), PT_TLS => tls_phdr = phdr, PT_GNU_STACK => stack_size = phdr.p_memsz, _ => {} } } - StartupTlsInfo { - addr: base.cast::<u8>().add((*tls_phdr).p_vaddr).cast(), - mem_size: (*tls_phdr).p_memsz, - file_size: (*tls_phdr).p_filesz, - align: (*tls_phdr).p_align, - stack_size, + if tls_phdr.is_null() { + StartupTlsInfo { + addr: NonNull::dangling().as_ptr(), + mem_size: 0, + file_size: 0, + align: 1, + stack_size: 0, + } + } else { + StartupTlsInfo { + addr: base.cast::<u8>().add((*tls_phdr).p_vaddr).cast(), + mem_size: (*tls_phdr).p_memsz, + file_size: (*tls_phdr).p_filesz, + align: (*tls_phdr).p_align, + stack_size, + } } } } diff --git a/vendor/rustix/src/backend/linux_raw/system/syscalls.rs b/vendor/rustix/src/backend/linux_raw/system/syscalls.rs index 514751d6f..947d5168e 100644 --- a/vendor/rustix/src/backend/linux_raw/system/syscalls.rs +++ b/vendor/rustix/src/backend/linux_raw/system/syscalls.rs @@ -3,8 +3,7 @@ //! # Safety //! //! See the `rustix::backend` module documentation for details. -#![allow(unsafe_code)] -#![allow(clippy::undocumented_unsafe_blocks)] +#![allow(unsafe_code, clippy::undocumented_unsafe_blocks)] use super::types::RawUname; use crate::backend::conv::{ret, ret_infallible, slice}; diff --git a/vendor/rustix/src/backend/linux_raw/termios/syscalls.rs b/vendor/rustix/src/backend/linux_raw/termios/syscalls.rs index 8f030e1c3..09100441f 100644 --- a/vendor/rustix/src/backend/linux_raw/termios/syscalls.rs +++ b/vendor/rustix/src/backend/linux_raw/termios/syscalls.rs @@ -3,27 +3,25 @@ //! # Safety //! //! See the `rustix::backend` module documentation for details. -#![allow(unsafe_code)] -#![allow(clippy::undocumented_unsafe_blocks)] +#![allow(unsafe_code, clippy::undocumented_unsafe_blocks)] use crate::backend::c; use crate::backend::conv::{by_ref, c_uint, ret}; use crate::fd::BorrowedFd; use crate::io; use crate::pid::Pid; -#[cfg(feature = "procfs")] +#[cfg(all(feature = "alloc", feature = "procfs"))] use crate::procfs; use crate::termios::{ Action, ControlModes, InputModes, LocalModes, OptionalActions, OutputModes, QueueSelector, SpecialCodeIndex, Termios, Winsize, }; -#[cfg(feature = "procfs")] +#[cfg(all(feature = "alloc", feature = "procfs"))] use crate::{ffi::CStr, fs::FileType, path::DecInt}; use core::mem::MaybeUninit; use linux_raw_sys::general::IBSHIFT; use linux_raw_sys::ioctl::{ - TCFLSH, TCSBRK, TCXONC, TIOCEXCL, TIOCGPGRP, TIOCGSID, TIOCGWINSZ, TIOCNXCL, TIOCSPGRP, - TIOCSWINSZ, + TCFLSH, TCSBRK, TCXONC, TIOCGPGRP, TIOCGSID, TIOCGWINSZ, TIOCSPGRP, TIOCSWINSZ, }; #[inline] @@ -56,7 +54,7 @@ pub(crate) fn tcgetpgrp(fd: BorrowedFd<'_>) -> io::Result<Pid> { #[inline] pub(crate) fn tcsetattr( - fd: BorrowedFd, + fd: BorrowedFd<'_>, optional_actions: OptionalActions, termios: &Termios, ) -> io::Result<()> { @@ -84,17 +82,17 @@ pub(crate) fn tcsetattr( } #[inline] -pub(crate) fn tcsendbreak(fd: BorrowedFd) -> io::Result<()> { +pub(crate) fn tcsendbreak(fd: BorrowedFd<'_>) -> io::Result<()> { unsafe { ret(syscall_readonly!(__NR_ioctl, fd, c_uint(TCSBRK), c_uint(0))) } } #[inline] -pub(crate) fn tcdrain(fd: BorrowedFd) -> io::Result<()> { +pub(crate) fn tcdrain(fd: BorrowedFd<'_>) -> io::Result<()> { unsafe { ret(syscall_readonly!(__NR_ioctl, fd, c_uint(TCSBRK), c_uint(1))) } } #[inline] -pub(crate) fn tcflush(fd: BorrowedFd, queue_selector: QueueSelector) -> io::Result<()> { +pub(crate) fn tcflush(fd: BorrowedFd<'_>, queue_selector: QueueSelector) -> io::Result<()> { unsafe { ret(syscall_readonly!( __NR_ioctl, @@ -106,7 +104,7 @@ pub(crate) fn tcflush(fd: BorrowedFd, queue_selector: QueueSelector) -> io::Resu } #[inline] -pub(crate) fn tcflow(fd: BorrowedFd, action: Action) -> io::Result<()> { +pub(crate) fn tcflow(fd: BorrowedFd<'_>, action: Action) -> io::Result<()> { unsafe { ret(syscall_readonly!( __NR_ioctl, @@ -118,7 +116,7 @@ pub(crate) fn tcflow(fd: BorrowedFd, action: Action) -> io::Result<()> { } #[inline] -pub(crate) fn tcgetsid(fd: BorrowedFd) -> io::Result<Pid> { +pub(crate) fn tcgetsid(fd: BorrowedFd<'_>) -> io::Result<Pid> { unsafe { let mut result = MaybeUninit::<c::pid_t>::uninit(); ret(syscall!(__NR_ioctl, fd, c_uint(TIOCGSID), &mut result))?; @@ -128,7 +126,7 @@ pub(crate) fn tcgetsid(fd: BorrowedFd) -> io::Result<Pid> { } #[inline] -pub(crate) fn tcsetwinsize(fd: BorrowedFd, winsize: Winsize) -> io::Result<()> { +pub(crate) fn tcsetwinsize(fd: BorrowedFd<'_>, winsize: Winsize) -> io::Result<()> { unsafe { ret(syscall!( __NR_ioctl, @@ -144,16 +142,6 @@ pub(crate) fn tcsetpgrp(fd: BorrowedFd<'_>, pid: Pid) -> io::Result<()> { unsafe { ret(syscall!(__NR_ioctl, fd, c_uint(TIOCSPGRP), pid)) } } -#[inline] -pub(crate) fn ioctl_tiocexcl(fd: BorrowedFd<'_>) -> io::Result<()> { - unsafe { ret(syscall_readonly!(__NR_ioctl, fd, c_uint(TIOCEXCL))) } -} - -#[inline] -pub(crate) fn ioctl_tiocnxcl(fd: BorrowedFd<'_>) -> io::Result<()> { - unsafe { ret(syscall_readonly!(__NR_ioctl, fd, c_uint(TIOCNXCL))) } -} - /// A wrapper around a conceptual `cfsetspeed` which handles an arbitrary /// integer speed value. #[inline] @@ -240,8 +228,7 @@ pub(crate) fn isatty(fd: BorrowedFd<'_>) -> bool { tcgetwinsize(fd).is_ok() } -#[cfg(feature = "procfs")] -#[allow(unsafe_code)] +#[cfg(all(feature = "alloc", feature = "procfs"))] pub(crate) fn ttyname(fd: BorrowedFd<'_>, buf: &mut [MaybeUninit<u8>]) -> io::Result<usize> { let fd_stat = crate::backend::fs::syscalls::fstat(fd)?; @@ -256,7 +243,7 @@ pub(crate) fn ttyname(fd: BorrowedFd<'_>, buf: &mut [MaybeUninit<u8>]) -> io::Re // Get a fd to '/proc/self/fd'. let proc_self_fd = procfs::proc_self_fd()?; - // Gather the ttyname by reading the 'fd' file inside 'proc_self_fd'. + // Gather the ttyname by reading the "fd" file inside `proc_self_fd`. let r = crate::backend::fs::syscalls::readlinkat( proc_self_fd, DecInt::from_fd(fd).as_c_str(), diff --git a/vendor/rustix/src/backend/linux_raw/thread/futex.rs b/vendor/rustix/src/backend/linux_raw/thread/futex.rs index 4cde309a5..263e98070 100644 --- a/vendor/rustix/src/backend/linux_raw/thread/futex.rs +++ b/vendor/rustix/src/backend/linux_raw/thread/futex.rs @@ -9,6 +9,10 @@ bitflags::bitflags! { const PRIVATE = linux_raw_sys::general::FUTEX_PRIVATE_FLAG; /// `FUTEX_CLOCK_REALTIME` const CLOCK_REALTIME = linux_raw_sys::general::FUTEX_CLOCK_REALTIME; + + // This deliberately lacks a `const _ = !0`, so that users can use + // `from_bits_truncate` to extract the `SocketFlags` from a flags + // value that also includes a `SocketType`. } } diff --git a/vendor/rustix/src/backend/linux_raw/thread/mod.rs b/vendor/rustix/src/backend/linux_raw/thread/mod.rs index 8bb80c33a..6a002c632 100644 --- a/vendor/rustix/src/backend/linux_raw/thread/mod.rs +++ b/vendor/rustix/src/backend/linux_raw/thread/mod.rs @@ -1,4 +1,2 @@ -mod futex; +pub(crate) mod futex; pub(crate) mod syscalls; - -pub use futex::{FutexFlags, FutexOperation}; diff --git a/vendor/rustix/src/backend/linux_raw/thread/syscalls.rs b/vendor/rustix/src/backend/linux_raw/thread/syscalls.rs index f23b7c2df..0095eed79 100644 --- a/vendor/rustix/src/backend/linux_raw/thread/syscalls.rs +++ b/vendor/rustix/src/backend/linux_raw/thread/syscalls.rs @@ -3,8 +3,7 @@ //! # Safety //! //! See the `rustix::backend` module documentation for details. -#![allow(unsafe_code)] -#![allow(clippy::undocumented_unsafe_blocks)] +#![allow(unsafe_code, clippy::undocumented_unsafe_blocks)] use crate::backend::c; use crate::backend::conv::{ @@ -274,7 +273,7 @@ unsafe fn futex_old( } #[inline] -pub(crate) fn setns(fd: BorrowedFd, nstype: c::c_int) -> io::Result<c::c_int> { +pub(crate) fn setns(fd: BorrowedFd<'_>, nstype: c::c_int) -> io::Result<c::c_int> { unsafe { ret_c_int(syscall_readonly!(__NR_setns, fd, c_int(nstype))) } } diff --git a/vendor/rustix/src/backend/linux_raw/time/syscalls.rs b/vendor/rustix/src/backend/linux_raw/time/syscalls.rs index 634ce2674..27c3652a4 100644 --- a/vendor/rustix/src/backend/linux_raw/time/syscalls.rs +++ b/vendor/rustix/src/backend/linux_raw/time/syscalls.rs @@ -3,8 +3,7 @@ //! # Safety //! //! See the `rustix::backend` module documentation for details. -#![allow(unsafe_code)] -#![allow(clippy::undocumented_unsafe_blocks)] +#![allow(unsafe_code, clippy::undocumented_unsafe_blocks)] use crate::backend::conv::{ret, ret_infallible}; use crate::clockid::ClockId; diff --git a/vendor/rustix/src/backend/linux_raw/time/types.rs b/vendor/rustix/src/backend/linux_raw/time/types.rs index 62cb167e6..ab43aed7c 100644 --- a/vendor/rustix/src/backend/linux_raw/time/types.rs +++ b/vendor/rustix/src/backend/linux_raw/time/types.rs @@ -20,6 +20,9 @@ bitflags! { /// `TFD_CLOEXEC` const CLOEXEC = linux_raw_sys::general::TFD_CLOEXEC; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -35,6 +38,9 @@ bitflags! { /// `TFD_TIMER_CANCEL_ON_SET` const CANCEL_ON_SET = linux_raw_sys::general::TFD_TIMER_CANCEL_ON_SET; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -47,10 +53,10 @@ bitflags! { pub enum TimerfdClockId { /// `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 - /// it is not monotonic. Successive reads may see decreasing times, so it - /// isn't reliable for measuring durations. + /// 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 it is + /// not monotonic. Successive reads may see decreasing times, so it isn't + /// reliable for measuring durations. Realtime = linux_raw_sys::general::CLOCK_REALTIME, /// `CLOCK_MONOTONIC`—A clock that tells an abstract time. diff --git a/vendor/rustix/src/backend/linux_raw/ugid/syscalls.rs b/vendor/rustix/src/backend/linux_raw/ugid/syscalls.rs index 12ff6dce1..5f1551e7c 100644 --- a/vendor/rustix/src/backend/linux_raw/ugid/syscalls.rs +++ b/vendor/rustix/src/backend/linux_raw/ugid/syscalls.rs @@ -3,8 +3,7 @@ //! # Safety //! //! See the `rustix::backend` module documentation for details. -#![allow(unsafe_code)] -#![allow(clippy::undocumented_unsafe_blocks)] +#![allow(unsafe_code, clippy::undocumented_unsafe_blocks)] use crate::backend::c; use crate::backend::conv::ret_usize_infallible; diff --git a/vendor/rustix/src/backend/linux_raw/vdso.rs b/vendor/rustix/src/backend/linux_raw/vdso.rs index 606aee7d1..1b0ae5375 100644 --- a/vendor/rustix/src/backend/linux_raw/vdso.rs +++ b/vendor/rustix/src/backend/linux_raw/vdso.rs @@ -13,12 +13,12 @@ #![allow(unsafe_code)] use super::c; -use super::elf::*; use crate::ffi::CStr; use crate::utils::check_raw_pointer; use core::ffi::c_void; use core::mem::size_of; use core::ptr::{null, null_mut}; +use linux_raw_sys::elf::*; pub(super) struct Vdso { // Load information @@ -143,28 +143,31 @@ fn init_from_sysinfo_ehdr() -> Option<Vdso> { match d.d_tag { DT_STRTAB => { vdso.symstrings = - check_raw_pointer::<u8>(vdso.addr_from_elf(d.d_val)? as *mut _)?.as_ptr(); + check_raw_pointer::<u8>(vdso.addr_from_elf(d.d_un.d_ptr)? as *mut _)? + .as_ptr(); } DT_SYMTAB => { vdso.symtab = - check_raw_pointer::<Elf_Sym>(vdso.addr_from_elf(d.d_val)? as *mut _)? + check_raw_pointer::<Elf_Sym>(vdso.addr_from_elf(d.d_un.d_ptr)? as *mut _)? .as_ptr(); } DT_HASH => { - hash = - check_raw_pointer::<u32>(vdso.addr_from_elf(d.d_val)? as *mut _)?.as_ptr(); + hash = check_raw_pointer::<u32>(vdso.addr_from_elf(d.d_un.d_ptr)? as *mut _)? + .as_ptr(); } DT_VERSYM => { vdso.versym = - check_raw_pointer::<u16>(vdso.addr_from_elf(d.d_val)? as *mut _)?.as_ptr(); + check_raw_pointer::<u16>(vdso.addr_from_elf(d.d_un.d_ptr)? as *mut _)? + .as_ptr(); } DT_VERDEF => { - vdso.verdef = - check_raw_pointer::<Elf_Verdef>(vdso.addr_from_elf(d.d_val)? as *mut _)? - .as_ptr(); + vdso.verdef = check_raw_pointer::<Elf_Verdef>( + vdso.addr_from_elf(d.d_un.d_ptr)? as *mut _, + )? + .as_ptr(); } DT_SYMENT => { - if d.d_val != size_of::<Elf_Sym>() { + if d.d_un.d_ptr != size_of::<Elf_Sym>() { return None; // Failed } } @@ -194,8 +197,8 @@ fn init_from_sysinfo_ehdr() -> Option<Vdso> { impl Vdso { /// Parse the vDSO. /// - /// Returns `None` if the vDSO can't be located or if it doesn't conform - /// to our expectations. + /// Returns `None` if the vDSO can't be located or if it doesn't conform to + /// our expectations. #[inline] pub(super) fn new() -> Option<Self> { init_from_sysinfo_ehdr() diff --git a/vendor/rustix/src/backend/linux_raw/vdso_wrappers.rs b/vendor/rustix/src/backend/linux_raw/vdso_wrappers.rs index 316d26a1c..1ff50415b 100644 --- a/vendor/rustix/src/backend/linux_raw/vdso_wrappers.rs +++ b/vendor/rustix/src/backend/linux_raw/vdso_wrappers.rs @@ -287,11 +287,10 @@ unsafe fn _rustix_clock_gettime_via_syscall_old( clockid: c::c_int, res: *mut Timespec, ) -> io::Result<()> { - // Ordinarily `rustix` doesn't like to emulate system calls, but in - // the case of time APIs, it's specific to Linux, specific to - // 32-bit architectures *and* specific to old kernel versions, and - // it's not that hard to fix up here, so that no other code needs - // to worry about this. + // Ordinarily `rustix` doesn't like to emulate system calls, but in the + // case of time APIs, it's specific to Linux, specific to 32-bit + // architectures *and* specific to old kernel versions, and it's not that + // hard to fix up here, so that no other code needs to worry about this. let mut old_result = MaybeUninit::<__kernel_old_timespec>::uninit(); let r0 = syscall!(__NR_clock_gettime, c_int(clockid), &mut old_result); match ret(r0) { |