diff options
Diffstat (limited to 'vendor/rustix/src')
166 files changed, 4013 insertions, 1873 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) { diff --git a/vendor/rustix/src/bitcast.rs b/vendor/rustix/src/bitcast.rs index 3924c29d5..735101766 100644 --- a/vendor/rustix/src/bitcast.rs +++ b/vendor/rustix/src/bitcast.rs @@ -1,6 +1,7 @@ +#![allow(unused_macros)] + // Ensure that the source and destination types are both primitive integer // types and the same size, and then bitcast. -#[allow(unused_macros)] macro_rules! bitcast { ($x:expr) => {{ if false { @@ -24,7 +25,6 @@ macro_rules! bitcast { /// Return a [`bitcast`] of the value of `$x.bits()`, where `$x` is a /// `bitflags` type. -#[allow(unused_macros)] macro_rules! bitflags_bits { ($x:expr) => {{ bitcast!($x.bits()) diff --git a/vendor/rustix/src/check_types.rs b/vendor/rustix/src/check_types.rs index 861d7d7b5..bea04e0b7 100644 --- a/vendor/rustix/src/check_types.rs +++ b/vendor/rustix/src/check_types.rs @@ -1,3 +1,5 @@ +//! Macros for checking that types have the same layout as other types. + #![allow(unused_macros)] /// Check that the size and alignment of a type match the `sys` bindings. @@ -77,9 +79,9 @@ macro_rules! check_struct { // Check that we have all the fields. if false { + #[allow(unreachable_code)] let _test = $name { - // SAFETY: This code is guarded by `if false`. - $($field: unsafe { core::mem::zeroed() }),* + $($field: panic!()),* }; } diff --git a/vendor/rustix/src/event/kqueue.rs b/vendor/rustix/src/event/kqueue.rs index ff0ffddc0..05ee4d71b 100644 --- a/vendor/rustix/src/event/kqueue.rs +++ b/vendor/rustix/src/event/kqueue.rs @@ -99,6 +99,12 @@ impl Event { self.inner.udata as _ } + /// Get the raw data for this event. + pub fn data(&self) -> i64 { + // On some bsds, data is an isize and not an i64 + self.inner.data as _ + } + /// Get the filter of this event. pub fn filter(&self) -> EventFilter { match self.inner.filter as _ { @@ -256,6 +262,9 @@ bitflags::bitflags! { /// TODO const ERROR = c::EV_ERROR as _; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -284,6 +293,9 @@ bitflags::bitflags! { /// The link count of the file has changed. const LINK = c::NOTE_LINK; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -301,11 +313,14 @@ bitflags::bitflags! { /// The process executed a new process. const EXEC = c::NOTE_EXEC; - /// Follow the process through `fork()` calls (write only). + /// Follow the process through `fork` calls (write only). const TRACK = c::NOTE_TRACK; /// An error has occurred with following the process. const TRACKERR = c::NOTE_TRACKERR; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -335,6 +350,9 @@ bitflags::bitflags! { /// Trigger the event. const TRIGGER = c::NOTE_TRIGGER; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } diff --git a/vendor/rustix/src/event/mod.rs b/vendor/rustix/src/event/mod.rs index 192afdcaa..03abc9f12 100644 --- a/vendor/rustix/src/event/mod.rs +++ b/vendor/rustix/src/event/mod.rs @@ -1,15 +1,25 @@ //! Event operations. -#[cfg(any(linux_kernel, target_os = "freebsd", target_os = "illumos"))] +#[cfg(any( + linux_kernel, + target_os = "freebsd", + target_os = "illumos", + target_os = "espidf" +))] mod eventfd; -#[cfg(bsd)] +#[cfg(all(feature = "alloc", bsd))] pub mod kqueue; mod poll; #[cfg(solarish)] pub mod port; -#[cfg(linux_kernel)] +#[cfg(all(feature = "alloc", linux_kernel))] pub use crate::backend::event::epoll; -#[cfg(any(linux_kernel, target_os = "freebsd", target_os = "illumos"))] +#[cfg(any( + linux_kernel, + target_os = "freebsd", + target_os = "illumos", + target_os = "espidf" +))] pub use eventfd::{eventfd, EventfdFlags}; pub use poll::{poll, PollFd, PollFlags}; diff --git a/vendor/rustix/src/event/port.rs b/vendor/rustix/src/event/port.rs index b04f7c496..39fe5ac16 100644 --- a/vendor/rustix/src/event/port.rs +++ b/vendor/rustix/src/event/port.rs @@ -72,8 +72,8 @@ pub unsafe fn port_associate_fd( ) } -/// `port_dissociate(_, PORT_SOURCE_FD, _)`—Dissociates a file descriptor from -/// a port. +/// `port_dissociate(_, PORT_SOURCE_FD, _)`—Dissociates a file descriptor +/// from a port. /// /// # Safety /// @@ -116,6 +116,7 @@ pub fn port_get(port: impl AsFd, timeout: Option<Duration>) -> io::Result<Event> /// /// [OpenSolaris]: https://www.unix.com/man-page/opensolaris/3C/port_getn/ /// [illumos]: https://illumos.org/man/3C/port_getn +#[cfg(feature = "alloc")] pub fn port_getn( port: impl AsFd, events: &mut Vec<Event>, diff --git a/vendor/rustix/src/ffi.rs b/vendor/rustix/src/ffi.rs index bd04a9cb4..ef9f87d81 100644 --- a/vendor/rustix/src/ffi.rs +++ b/vendor/rustix/src/ffi.rs @@ -9,8 +9,7 @@ pub use { // If we don't have std, we can depend on core and alloc having these features // in Rust 1.64+. +#[cfg(all(feature = "alloc", not(feature = "std")))] +pub use alloc::ffi::{CString, NulError}; #[cfg(not(feature = "std"))] -pub use { - alloc::ffi::{CString, NulError}, - core::ffi::{c_char, CStr, FromBytesWithNulError}, -}; +pub use core::ffi::{c_char, CStr, FromBytesWithNulError}; diff --git a/vendor/rustix/src/fs/abs.rs b/vendor/rustix/src/fs/abs.rs index 81e991772..f57bd00fe 100644 --- a/vendor/rustix/src/fs/abs.rs +++ b/vendor/rustix/src/fs/abs.rs @@ -1,7 +1,6 @@ //! POSIX-style filesystem functions which operate on bare paths. use crate::fd::OwnedFd; -use crate::ffi::{CStr, CString}; #[cfg(not(target_os = "espidf"))] use crate::fs::Access; #[cfg(not(any( @@ -17,9 +16,15 @@ use crate::fs::StatFs; #[cfg(not(any(target_os = "haiku", target_os = "redox", target_os = "wasi")))] use crate::fs::StatVfs; use crate::fs::{Mode, OFlags, Stat}; -use crate::path::SMALL_PATH_BUFFER_SIZE; +#[cfg(not(target_os = "wasi"))] +use crate::ugid::{Gid, Uid}; use crate::{backend, io, path}; -use alloc::vec::Vec; +#[cfg(feature = "alloc")] +use { + crate::ffi::{CStr, CString}, + crate::path::SMALL_PATH_BUFFER_SIZE, + alloc::vec::Vec, +}; /// `open(path, oflags, mode)`—Opens a file. /// @@ -101,11 +106,13 @@ pub fn lstat<P: path::Arg>(path: P) -> io::Result<Stat> { /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/readlink.html /// [Linux]: https://man7.org/linux/man-pages/man2/readlink.2.html +#[cfg(feature = "alloc")] #[inline] pub fn readlink<P: path::Arg, B: Into<Vec<u8>>>(path: P, reuse: B) -> io::Result<CString> { path.into_with_c_str(|path| _readlink(path, reuse.into())) } +#[cfg(feature = "alloc")] fn _readlink(path: &CStr, 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`. @@ -170,12 +177,21 @@ pub fn rmdir<P: path::Arg>(path: P) -> io::Result<()> { /// `link(old_path, new_path)`—Creates a hard link. /// +/// POSIX leaves it implementation-defined whether `link` follows a symlink in +/// `old_path`, or creates a new link to the symbolic link itself. On platforms +/// which have it, [`linkat`] avoids this problem since it has an [`AtFlags`] +/// paramter and the [`AtFlags::SYMLINK_FOLLOW`] flag determines whether +/// symlinks should be followed. +/// /// # References /// - [POSIX] /// - [Linux] /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/link.html /// [Linux]: https://man7.org/linux/man-pages/man2/link.2.html +/// [`linkat`]: crate::fs::linkat +/// [`AtFlags`]: crate::fs::AtFlags +/// [`AtFlags::SYMLINK_FOLLOW`]: crate::fs::AtFlags::SYMLINK_FOLLOW #[inline] pub fn link<P: path::Arg, Q: path::Arg>(old_path: P, new_path: Q) -> io::Result<()> { old_path.into_with_c_str(|old_path| { @@ -266,3 +282,17 @@ pub fn statfs<P: path::Arg>(path: P) -> io::Result<StatFs> { pub fn statvfs<P: path::Arg>(path: P) -> io::Result<StatVfs> { path.into_with_c_str(backend::fs::syscalls::statvfs) } + +/// `chown(path, owner, group)`—Sets open file or directory ownership. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/chown.html +/// [Linux]: https://man7.org/linux/man-pages/man2/chown.2.html +#[cfg(not(target_os = "wasi"))] +#[inline] +pub fn chown<P: path::Arg>(path: P, owner: Option<Uid>, group: Option<Gid>) -> io::Result<()> { + path.into_with_c_str(|path| backend::fs::syscalls::chown(path, owner, group)) +} diff --git a/vendor/rustix/src/fs/at.rs b/vendor/rustix/src/fs/at.rs index 5bd90fab5..0434b56ef 100644 --- a/vendor/rustix/src/fs/at.rs +++ b/vendor/rustix/src/fs/at.rs @@ -3,26 +3,32 @@ //! The `dirfd` argument to these functions may be a file descriptor for a //! directory, or the special value [`CWD`]. //! -//! [`cwd`]: crate::fs::cwd::CWD +//! [`cwd`]: crate::fs::CWD use crate::fd::OwnedFd; -use crate::ffi::{CStr, CString}; #[cfg(apple)] use crate::fs::CloneFlags; #[cfg(not(any(apple, target_os = "espidf", target_os = "wasi")))] use crate::fs::FileType; #[cfg(linux_kernel)] use crate::fs::RenameFlags; +#[cfg(not(any(target_os = "aix", target_os = "espidf")))] +use crate::fs::Stat; #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] use crate::fs::{Gid, Uid}; use crate::fs::{Mode, OFlags}; -use crate::path::SMALL_PATH_BUFFER_SIZE; use crate::{backend, io, path}; -use alloc::vec::Vec; -use backend::fd::{AsFd, BorrowedFd}; +use backend::fd::AsFd; +#[cfg(feature = "alloc")] +use { + crate::ffi::{CStr, CString}, + crate::path::SMALL_PATH_BUFFER_SIZE, + alloc::vec::Vec, + backend::fd::BorrowedFd, +}; #[cfg(not(target_os = "espidf"))] use { - crate::fs::{Access, AtFlags, Stat, Timestamps}, + crate::fs::{Access, AtFlags, Timestamps}, crate::timespec::Nsecs, }; @@ -76,6 +82,7 @@ pub fn openat<P: path::Arg, Fd: AsFd>( /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/readlinkat.html /// [Linux]: https://man7.org/linux/man-pages/man2/readlinkat.2.html +#[cfg(feature = "alloc")] #[inline] pub fn readlinkat<P: path::Arg, Fd: AsFd, B: Into<Vec<u8>>>( dirfd: Fd, @@ -85,6 +92,7 @@ pub fn readlinkat<P: path::Arg, Fd: AsFd, B: Into<Vec<u8>>>( path.into_with_c_str(|path| _readlinkat(dirfd.as_fd(), path, reuse.into())) } +#[cfg(feature = "alloc")] #[allow(unsafe_code)] fn _readlinkat(dirfd: BorrowedFd<'_>, path: &CStr, mut buffer: Vec<u8>) -> io::Result<CString> { buffer.clear(); @@ -96,8 +104,10 @@ fn _readlinkat(dirfd: BorrowedFd<'_>, path: &CStr, mut buffer: Vec<u8>) -> io::R debug_assert!(nread <= buffer.capacity()); if nread < buffer.capacity() { - // SAFETY from the man page: + // SAFETY: From the [documentation]: // "On success, these calls return the number of bytes placed in buf." + // + // [documentation]: https://man7.org/linux/man-pages/man2/readlinkat.2.html unsafe { buffer.set_len(nread); } @@ -280,7 +290,8 @@ pub fn symlinkat<P: path::Arg, Q: path::Arg, Fd: AsFd>( /// [Linux]: https://man7.org/linux/man-pages/man2/fstatat.2.html /// [`Mode::from_raw_mode`]: crate::fs::Mode::from_raw_mode /// [`FileType::from_raw_mode`]: crate::fs::FileType::from_raw_mode -#[cfg(not(target_os = "espidf"))] +// TODO: Add `stat64xat` to upstream libc bindings and reenable this for AIX. +#[cfg(not(any(target_os = "aix", target_os = "espidf")))] #[inline] #[doc(alias = "fstatat")] pub fn statat<P: path::Arg, Fd: AsFd>(dirfd: Fd, path: P, flags: AtFlags) -> io::Result<Stat> { diff --git a/vendor/rustix/src/fs/fcntl.rs b/vendor/rustix/src/fs/fcntl.rs index f7f4790cb..facbc9fa3 100644 --- a/vendor/rustix/src/fs/fcntl.rs +++ b/vendor/rustix/src/fs/fcntl.rs @@ -15,7 +15,7 @@ use crate::{backend, io}; use backend::fd::AsFd; use backend::fs::types::OFlags; -// These `fcntl` functions like in the `io` module because they're not specific +// These `fcntl` functions live in the `io` module because they're not specific // to files, directories, or memfd objects. We re-export them here in the `fs` // module because the other the `fcntl` functions are here. #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] diff --git a/vendor/rustix/src/fs/fd.rs b/vendor/rustix/src/fs/fd.rs index 43b2e57b1..94de43daa 100644 --- a/vendor/rustix/src/fs/fd.rs +++ b/vendor/rustix/src/fs/fd.rs @@ -105,7 +105,7 @@ pub fn tell<Fd: AsFd>(fd: Fd) -> io::Result<u64> { backend::fs::syscalls::tell(fd.as_fd()) } -/// `fchmod(fd)`—Sets open file or directory permissions. +/// `fchmod(fd, mode)`—Sets open file or directory permissions. /// /// This implementation does not support `O_PATH` file descriptors, even on /// platforms where the host libc emulates it. @@ -122,7 +122,7 @@ pub fn fchmod<Fd: AsFd>(fd: Fd, mode: Mode) -> io::Result<()> { backend::fs::syscalls::fchmod(fd.as_fd(), mode) } -/// `fchown(fd)`—Sets open file or directory ownership. +/// `fchown(fd, owner, group)`—Sets open file or directory ownership. /// /// # References /// - [POSIX] @@ -256,7 +256,7 @@ pub(crate) fn _is_file_read_write(fd: BorrowedFd<'_>) -> io::Result<(bool, bool) let mode = backend::fs::syscalls::fcntl_getfl(fd)?; // Check for `O_PATH`. - #[cfg(any(linux_kernel, target_os = "fuchsia", target_os = "emscripten"))] + #[cfg(any(linux_kernel, target_os = "emscripten", target_os = "fuchsia"))] if mode.contains(OFlags::PATH) { return Ok((false, false)); } diff --git a/vendor/rustix/src/fs/ioctl.rs b/vendor/rustix/src/fs/ioctl.rs index 28e0c8588..75222752f 100644 --- a/vendor/rustix/src/fs/ioctl.rs +++ b/vendor/rustix/src/fs/ioctl.rs @@ -1,11 +1,17 @@ //! Filesystem-oriented `ioctl` functions. +#![allow(unsafe_code)] + #[cfg(linux_kernel)] use { crate::fd::AsFd, - crate::{backend, io}, + crate::{backend, io, ioctl}, + backend::c, }; +#[cfg(all(linux_kernel, not(any(target_arch = "sparc", target_arch = "sparc64"))))] +use crate::fd::{AsRawFd, BorrowedFd}; + /// `ioctl(fd, BLKSSZGET)`—Returns the logical block size of a block device. /// /// This is mentioned in the [Linux `openat` manual page]. @@ -15,7 +21,11 @@ use { #[inline] #[doc(alias = "BLKSSZGET")] pub fn ioctl_blksszget<Fd: AsFd>(fd: Fd) -> io::Result<u32> { - backend::fs::syscalls::ioctl_blksszget(fd.as_fd()) + // SAFETY: BLZSSZGET is a getter opcode that gets a u32. + unsafe { + let ctl = ioctl::Getter::<ioctl::BadOpcode<{ c::BLKSSZGET }>, c::c_uint>::new(); + ioctl::ioctl(fd, ctl) + } } /// `ioctl(fd, BLKPBSZGET)`—Returns the physical block size of a block device. @@ -23,7 +33,11 @@ pub fn ioctl_blksszget<Fd: AsFd>(fd: Fd) -> io::Result<u32> { #[inline] #[doc(alias = "BLKPBSZGET")] pub fn ioctl_blkpbszget<Fd: AsFd>(fd: Fd) -> io::Result<u32> { - backend::fs::syscalls::ioctl_blkpbszget(fd.as_fd()) + // SAFETY: BLKPBSZGET is a getter opcode that gets a u32. + unsafe { + let ctl = ioctl::Getter::<ioctl::BadOpcode<{ c::BLKPBSZGET }>, c::c_uint>::new(); + ioctl::ioctl(fd, ctl) + } } /// `ioctl(fd, FICLONE, src_fd)`—Share data between open files. @@ -38,7 +52,7 @@ pub fn ioctl_blkpbszget<Fd: AsFd>(fd: Fd) -> io::Result<u32> { #[inline] #[doc(alias = "FICLONE")] pub fn ioctl_ficlone<Fd: AsFd, SrcFd: AsFd>(fd: Fd, src_fd: SrcFd) -> io::Result<()> { - backend::fs::syscalls::ioctl_ficlone(fd.as_fd(), src_fd.as_fd()) + unsafe { ioctl::ioctl(fd, Ficlone(src_fd.as_fd())) } } /// `ioctl(fd, EXT4_IOC_RESIZE_FS, blocks)`—Resize ext4 filesystem on fd. @@ -46,5 +60,33 @@ pub fn ioctl_ficlone<Fd: AsFd, SrcFd: AsFd>(fd: Fd, src_fd: SrcFd) -> io::Result #[inline] #[doc(alias = "EXT4_IOC_RESIZE_FS")] pub fn ext4_ioc_resize_fs<Fd: AsFd>(fd: Fd, blocks: u64) -> io::Result<()> { - backend::fs::syscalls::ext4_ioc_resize_fs(fd.as_fd(), blocks) + // SAFETY: EXT4_IOC_RESIZE_FS is a pointer setter opcode. + unsafe { + let ctl = ioctl::Setter::<ioctl::BadOpcode<{ backend::fs::EXT4_IOC_RESIZE_FS }>, u64>::new( + blocks, + ); + ioctl::ioctl(fd, ctl) + } +} + +#[cfg(all(linux_kernel, not(any(target_arch = "sparc", target_arch = "sparc64"))))] +struct Ficlone<'a>(BorrowedFd<'a>); + +#[cfg(all(linux_kernel, not(any(target_arch = "sparc", target_arch = "sparc64"))))] +unsafe impl ioctl::Ioctl for Ficlone<'_> { + type Output = (); + + const IS_MUTATING: bool = false; + const OPCODE: ioctl::Opcode = ioctl::Opcode::old(c::FICLONE as ioctl::RawOpcode); + + fn as_ptr(&mut self) -> *mut c::c_void { + self.0.as_raw_fd() as *mut c::c_void + } + + unsafe fn output_from_ptr( + _: ioctl::IoctlOutput, + _: *mut c::c_void, + ) -> io::Result<Self::Output> { + Ok(()) + } } diff --git a/vendor/rustix/src/fs/mod.rs b/vendor/rustix/src/fs/mod.rs index fbfaa12c9..1ea0d1351 100644 --- a/vendor/rustix/src/fs/mod.rs +++ b/vendor/rustix/src/fs/mod.rs @@ -9,7 +9,7 @@ mod copy_file_range; #[cfg(not(any(target_os = "espidf", target_os = "redox")))] #[cfg(not(target_os = "haiku"))] // Haiku needs <https://github.com/rust-lang/rust/pull/112371> mod cwd; -#[cfg(not(any(target_os = "espidf", target_os = "redox")))] +#[cfg(all(feature = "alloc", not(any(target_os = "espidf", target_os = "redox"))))] mod dir; #[cfg(not(any( apple, @@ -71,7 +71,7 @@ pub use copy_file_range::copy_file_range; #[cfg(not(any(target_os = "espidf", target_os = "redox")))] #[cfg(not(target_os = "haiku"))] // Haiku needs <https://github.com/rust-lang/rust/pull/112371> pub use cwd::*; -#[cfg(not(any(target_os = "espidf", target_os = "redox")))] +#[cfg(all(feature = "alloc", not(any(target_os = "espidf", target_os = "redox"))))] pub use dir::{Dir, DirEntry}; #[cfg(not(any( apple, diff --git a/vendor/rustix/src/fs/mount.rs b/vendor/rustix/src/fs/mount.rs index d1e6a8238..0f04b7f69 100644 --- a/vendor/rustix/src/fs/mount.rs +++ b/vendor/rustix/src/fs/mount.rs @@ -3,43 +3,53 @@ //! These have been moved to a new `rustix::mount` module. #[deprecated(note = "rustix::fs::UnmountFlags` moved to `rustix::mount::UnmountFlags`.")] +#[doc(hidden)] pub use crate::mount::UnmountFlags; #[deprecated(note = "rustix::fs::MountFlags` moved to `rustix::mount::MountFlags`.")] +#[doc(hidden)] pub use crate::mount::MountFlags; #[deprecated( note = "rustix::fs::MountPropagationFlags` moved to `rustix::mount::MountPropagationFlags`." )] +#[doc(hidden)] pub use crate::mount::MountPropagationFlags; #[deprecated(note = "`rustix::fs::mount` moved to `rustix::mount::mount`.")] +#[doc(hidden)] pub use crate::mount::mount; #[deprecated(note = "`rustix::fs::unmount` moved to `rustix::mount::unmount`.")] +#[doc(hidden)] pub use crate::mount::unmount; #[deprecated( note = "`rustix::fs::remount` is renamed and moved to `rustix::mount::mount_remount`." )] +#[doc(hidden)] pub use crate::mount::mount_remount as remount; #[deprecated( note = "`rustix::fs::bind_mount` is renamed and moved to `rustix::mount::mount_bind`." )] +#[doc(hidden)] pub use crate::mount::mount_bind as bind_mount; #[deprecated( note = "`rustix::fs::recursive_bind_mount` is renamed and moved to `rustix::mount::mount_recursive_bind`." )] +#[doc(hidden)] pub use crate::mount::mount_recursive_bind as recursive_bind_mount; #[deprecated( note = "`rustix::fs::change_mount` is renamed and moved to `rustix::mount::mount_change`." )] +#[doc(hidden)] pub use crate::mount::mount_change as change_mount; #[deprecated( note = "`rustix::fs::move_mount` is renamed and moved to `rustix::mount::mount_move`." )] +#[doc(hidden)] pub use crate::mount::mount_move as move_mount; diff --git a/vendor/rustix/src/fs/raw_dir.rs b/vendor/rustix/src/fs/raw_dir.rs index 3131e0649..fd8aefa3a 100644 --- a/vendor/rustix/src/fs/raw_dir.rs +++ b/vendor/rustix/src/fs/raw_dir.rs @@ -136,7 +136,7 @@ impl<'buf, Fd: AsFd> RawDir<'buf, Fd> { } } -/// A raw directory entry, similar to `std::fs::DirEntry`. +/// A raw directory entry, similar to [`std::fs::DirEntry`]. /// /// Unlike the std version, this may represent the `.` or `..` entries. pub struct RawDirEntry<'a> { @@ -193,10 +193,10 @@ impl<'buf, Fd: AsFd> RawDir<'buf, Fd> { /// with GAT support once one becomes available. #[allow(unsafe_code)] #[allow(clippy::should_implement_trait)] - pub fn next(&mut self) -> Option<io::Result<RawDirEntry>> { + pub fn next(&mut self) -> Option<io::Result<RawDirEntry<'_>>> { if self.is_buffer_empty() { match getdents_uninit(self.fd.as_fd(), self.buf) { - Ok(bytes_read) if bytes_read == 0 => return None, + Ok(0) => return None, Ok(bytes_read) => { self.initialized = bytes_read; self.offset = 0; diff --git a/vendor/rustix/src/fs/seek_from.rs b/vendor/rustix/src/fs/seek_from.rs index cca23ed62..c08abd2e6 100644 --- a/vendor/rustix/src/fs/seek_from.rs +++ b/vendor/rustix/src/fs/seek_from.rs @@ -4,9 +4,12 @@ /// Enumeration of possible methods to seek within an I/O object. /// -/// It is used by the [`Seek`] trait. +/// It is used by the [`seek`] function. /// -/// [`Seek`]: std::io::Seek +/// This is similar to [`std::io::SeekFrom`], however it adds platform-specific +/// seek options. +/// +/// [`seek`]: crate::fs::seek #[derive(Copy, PartialEq, Eq, Clone, Debug)] #[cfg_attr(staged_api, stable(feature = "rust1", since = "1.0.0"))] pub enum SeekFrom { @@ -30,19 +33,21 @@ pub enum SeekFrom { #[cfg_attr(staged_api, stable(feature = "rust1", since = "1.0.0"))] Current(#[cfg_attr(staged_api, stable(feature = "rust1", since = "1.0.0"))] i64), - /// Sets the offset to the current position plus the specified number of bytes, - /// plus the distance to the next byte which is not in a hole. + /// Sets the offset to the current position plus the specified number of + /// bytes, plus the distance to the next byte which is not in a hole. /// - /// If the offset is in a hole at the end of the file, the seek will produce - /// an `NXIO` error. - #[cfg(any(freebsdlike, target_os = "linux", target_os = "solaris"))] + /// If the offset is in a hole at the end of the file, the seek will fail + /// with [`Errno::NXIO`]. + /// + /// [`Errno::NXIO`]: crate::io::Errno::NXIO + #[cfg(any(apple, freebsdlike, linux_kernel, solarish))] Data(i64), - /// Sets the offset to the current position plus the specified number of bytes, - /// plus the distance to the next byte which is in a hole. + /// Sets the offset to the current position plus the specified number of + /// bytes, plus the distance to the next byte which is in a hole. /// - /// If there is no hole past the offset, it will be set to the end of the file - /// i.e. there is an implicit hole at the end of any file. - #[cfg(any(freebsdlike, target_os = "linux", target_os = "solaris"))] + /// If there is no hole past the offset, it will be set to the end of the + /// file i.e. there is an implicit hole at the end of any file. + #[cfg(any(apple, freebsdlike, linux_kernel, solarish))] Hole(i64), } diff --git a/vendor/rustix/src/fs/statx.rs b/vendor/rustix/src/fs/statx.rs index 32ae84ed3..1791697af 100644 --- a/vendor/rustix/src/fs/statx.rs +++ b/vendor/rustix/src/fs/statx.rs @@ -21,6 +21,35 @@ use compat::statx as _statx; /// # References /// - [Linux] /// +/// # Examples +/// +/// ``` +/// # use std::path::Path; +/// # use std::io; +/// # use rustix::fs::{AtFlags, StatxFlags}; +/// # use rustix::fd::BorrowedFd; +/// /// Try to determine if the provided path is a mount root. Will return `Ok(None)` if +/// /// the kernel is not new enough to support statx() or [`libc::STATX_ATTR_MOUNT_ROOT`]. +/// fn is_mountpoint(root: BorrowedFd<'_>, path: &Path) -> io::Result<Option<bool>> { +/// use rustix::fs::{AtFlags, StatxFlags}; +/// +/// let mountroot_flag = libc::STATX_ATTR_MOUNT_ROOT as u64; +/// match rustix::fs::statx( +/// root, +/// path, +/// AtFlags::NO_AUTOMOUNT | AtFlags::SYMLINK_NOFOLLOW, +/// StatxFlags::empty(), +/// ) { +/// Ok(r) => { +/// let present = (r.stx_attributes_mask & mountroot_flag) > 0; +/// Ok(present.then(|| r.stx_attributes & mountroot_flag > 0)) +/// } +/// Err(e) if e == rustix::io::Errno::NOSYS => Ok(None), +/// Err(e) => Err(e.into()), +/// } +/// } +/// ``` +/// /// [Linux]: https://man7.org/linux/man-pages/man2/statx.2.html #[inline] pub fn statx<P: path::Arg, Fd: AsFd>( diff --git a/vendor/rustix/src/fs/xattr.rs b/vendor/rustix/src/fs/xattr.rs index 01fe7d569..53612f71f 100644 --- a/vendor/rustix/src/fs/xattr.rs +++ b/vendor/rustix/src/fs/xattr.rs @@ -14,6 +14,9 @@ bitflags! { /// `XATTR_REPLACE` const REPLACE = c::XATTR_REPLACE as c::c_uint; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } diff --git a/vendor/rustix/src/io/errno.rs b/vendor/rustix/src/io/errno.rs index 7640d3111..2b72de005 100644 --- a/vendor/rustix/src/io/errno.rs +++ b/vendor/rustix/src/io/errno.rs @@ -12,31 +12,6 @@ use std::error; /// A specialized [`Result`] type for `rustix` APIs. pub type Result<T> = result::Result<T, Errno>; -/// `errno`—An error code. -/// -/// 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 pub use backend::io::errno::Errno; impl Errno { diff --git a/vendor/rustix/src/io/ioctl.rs b/vendor/rustix/src/io/ioctl.rs index d9bfa1fb3..e85719a4d 100644 --- a/vendor/rustix/src/io/ioctl.rs +++ b/vendor/rustix/src/io/ioctl.rs @@ -6,7 +6,10 @@ //! Some ioctls, such as those related to filesystems, terminals, and //! processes, live in other top-level API modules. -use crate::{backend, io}; +#![allow(unsafe_code)] + +use crate::{backend, io, ioctl}; +use backend::c; use backend::fd::AsFd; /// `ioctl(fd, FIOCLEX, NULL)`—Set the close-on-exec flag. @@ -26,7 +29,11 @@ use backend::fd::AsFd; #[doc(alias = "FIOCLEX")] #[doc(alias = "FD_CLOEXEC")] pub fn ioctl_fioclex<Fd: AsFd>(fd: Fd) -> io::Result<()> { - backend::io::syscalls::ioctl_fioclex(fd.as_fd()) + // SAFETY: FIOCLEX is a no-argument setter opcode. + unsafe { + let ctl = ioctl::NoArg::<ioctl::BadOpcode<{ c::FIOCLEX }>>::new(); + ioctl::ioctl(fd, ctl) + } } /// `ioctl(fd, FIONBIO, &value)`—Enables or disables non-blocking mode. @@ -42,7 +49,11 @@ pub fn ioctl_fioclex<Fd: AsFd>(fd: Fd) -> io::Result<()> { #[inline] #[doc(alias = "FIONBIO")] pub fn ioctl_fionbio<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> { - backend::io::syscalls::ioctl_fionbio(fd.as_fd(), value) + // SAFETY: FIONBIO is a pointer setter opcode. + unsafe { + let ctl = ioctl::Setter::<ioctl::BadOpcode<{ c::FIONBIO }>, c::c_int>::new(value.into()); + ioctl::ioctl(fd, ctl) + } } /// `ioctl(fd, FIONREAD)`—Returns the number of bytes ready to be read. @@ -66,5 +77,9 @@ pub fn ioctl_fionbio<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> { #[inline] #[doc(alias = "FIONREAD")] pub fn ioctl_fionread<Fd: AsFd>(fd: Fd) -> io::Result<u64> { - backend::io::syscalls::ioctl_fionread(fd.as_fd()) + // SAFETY: FIONREAD is a getter opcode that gets a c_int. + unsafe { + let ctl = ioctl::Getter::<ioctl::BadOpcode<{ c::FIONREAD }>, c::c_int>::new(); + ioctl::ioctl(fd, ctl).map(|n| n as u64) + } } diff --git a/vendor/rustix/src/io_uring.rs b/vendor/rustix/src/io_uring.rs index 93feb2780..09a4d6d62 100644 --- a/vendor/rustix/src/io_uring.rs +++ b/vendor/rustix/src/io_uring.rs @@ -27,7 +27,7 @@ use crate::fd::{AsFd, BorrowedFd, OwnedFd, RawFd}; use crate::{backend, io}; use core::ffi::c_void; -use core::mem::{zeroed, MaybeUninit}; +use core::mem::MaybeUninit; use core::ptr::{null_mut, write_bytes}; use linux_raw_sys::net; @@ -120,6 +120,12 @@ bitflags::bitflags! { /// `IORING_ENTER_EXT_ARG` const EXT_ARG = sys::IORING_ENTER_EXT_ARG; + + /// `IORING_ENTER_REGISTERED_RING` + const REGISTERED_RING = sys::IORING_ENTER_REGISTERED_RING; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -455,6 +461,9 @@ bitflags::bitflags! { /// `IORING_SETUP_DEFER_TASKRUN` const DEFER_TASKRUN = sys::IORING_SETUP_DEFER_TASKRUN; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -483,6 +492,9 @@ bitflags::bitflags! { /// `1 << IOSQE_CQE_SKIP_SUCCESS_BIT` const CQE_SKIP_SUCCESS = 1 << sys::IOSQE_CQE_SKIP_SUCCESS_BIT as u8; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -502,6 +514,9 @@ bitflags::bitflags! { /// `IORING_CQE_F_NOTIF` const NOTIF = bitcast!(sys::IORING_CQE_F_NOTIF); + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -512,6 +527,9 @@ bitflags::bitflags! { pub struct IoringFsyncFlags: u32 { /// `IORING_FSYNC_DATASYNC` const DATASYNC = sys::IORING_FSYNC_DATASYNC; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -544,6 +562,9 @@ bitflags::bitflags! { /// `IORING_LINK_TIMEOUT_UPDATE` const LINK_TIMEOUT_UPDATE = sys::IORING_LINK_TIMEOUT_UPDATE; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -554,6 +575,9 @@ bitflags::bitflags! { pub struct SpliceFlags: u32 { /// `SPLICE_F_FD_IN_FIXED` const FD_IN_FIXED = sys::SPLICE_F_FD_IN_FIXED; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -564,6 +588,9 @@ bitflags::bitflags! { pub struct IoringMsgringFlags: u32 { /// `IORING_MSG_RING_CQE_SKIP` const CQE_SKIP = sys::IORING_MSG_RING_CQE_SKIP; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -583,6 +610,9 @@ bitflags::bitflags! { /// `IORING_ASYNC_CANCEL_FD` const FD_FIXED = sys::IORING_ASYNC_CANCEL_FD_FIXED; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -629,6 +659,9 @@ bitflags::bitflags! { /// `IORING_FEAT_LINKED_FILE` const LINKED_FILE = sys::IORING_FEAT_LINKED_FILE; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -639,6 +672,9 @@ bitflags::bitflags! { pub struct IoringOpFlags: u16 { /// `IO_URING_OP_SUPPORTED` const SUPPORTED = sys::IO_URING_OP_SUPPORTED as _; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -649,6 +685,9 @@ bitflags::bitflags! { pub struct IoringRsrcFlags: u32 { /// `IORING_RSRC_REGISTER_SPARSE` const REGISTER_SPARSE = sys::IORING_RSRC_REGISTER_SPARSE as _; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -665,6 +704,9 @@ bitflags::bitflags! { /// `IORING_SQ_TASKRUN` const TASKRUN = sys::IORING_SQ_TASKRUN; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -675,6 +717,9 @@ bitflags::bitflags! { pub struct IoringCqFlags: u32 { /// `IORING_CQ_EVENTFD_DISABLED` const EVENTFD_DISABLED = sys::IORING_CQ_EVENTFD_DISABLED; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -694,6 +739,9 @@ bitflags::bitflags! { /// `IORING_POLL_ADD_LEVEL` const ADD_LEVEL = sys::IORING_POLL_ADD_LEVEL; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -714,6 +762,9 @@ bitflags::bitflags! { /// `IORING_SEND_ZC_REPORT_USAGE` (since Linux 6.2) const ZC_REPORT_USAGE = sys::IORING_SEND_ZC_REPORT_USAGE as _; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -734,6 +785,9 @@ bitflags::bitflags! { /// /// See also [`IoringSendFlags::FIXED_BUF`]. const FIXED_BUF = sys::IORING_RECVSEND_FIXED_BUF as _; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -744,6 +798,9 @@ bitflags::bitflags! { pub struct IoringAcceptFlags: u16 { /// `IORING_ACCEPT_MULTISHOT` const MULTISHOT = sys::IORING_ACCEPT_MULTISHOT as _; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -766,6 +823,9 @@ bitflags::bitflags! { /// `MSG_ERRQUEUE` const ERRQUEUE = net::MSG_ERRQUEUE; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -1245,72 +1305,63 @@ pub struct io_uring_buf { impl Default for ioprio_union { #[inline] fn default() -> Self { - // SAFETY: All of Linux's io_uring structs may be zero-initialized. - unsafe { zeroed::<Self>() } + default_union!(ioprio_union, ioprio) } } impl Default for len_union { #[inline] fn default() -> Self { - // SAFETY: All of Linux's io_uring structs may be zero-initialized. - unsafe { zeroed::<Self>() } + default_union!(len_union, len) } } impl Default for off_or_addr2_union { #[inline] fn default() -> Self { - // SAFETY: All of Linux's io_uring structs may be zero-initialized. - unsafe { zeroed::<Self>() } + default_union!(off_or_addr2_union, off) } } impl Default for addr_or_splice_off_in_union { #[inline] fn default() -> Self { - // SAFETY: All of Linux's io_uring structs may be zero-initialized. - unsafe { zeroed::<Self>() } + default_union!(addr_or_splice_off_in_union, splice_off_in) } } impl Default for addr3_or_cmd_union { #[inline] fn default() -> Self { - // SAFETY: All of Linux's io_uring structs may be zero-initialized. - unsafe { zeroed::<Self>() } + default_union!(addr3_or_cmd_union, addr3) } } impl Default for op_flags_union { #[inline] fn default() -> Self { - // SAFETY: All of Linux's io_uring structs may be zero-initialized. - unsafe { zeroed::<Self>() } + default_union!(op_flags_union, sync_range_flags) } } impl Default for buf_union { #[inline] fn default() -> Self { - // SAFETY: All of Linux's io_uring structs may be zero-initialized. - unsafe { zeroed::<Self>() } + default_union!(buf_union, buf_index) } } impl Default for splice_fd_in_or_file_index_union { #[inline] fn default() -> Self { - // SAFETY: All of Linux's io_uring structs may be zero-initialized. - unsafe { zeroed::<Self>() } + default_union!(splice_fd_in_or_file_index_union, splice_fd_in) } } impl Default for register_or_sqe_op_or_sqe_flags_union { #[inline] fn default() -> Self { - // SAFETY: All of Linux's io_uring structs may be zero-initialized. - unsafe { zeroed::<Self>() } + default_union!(register_or_sqe_op_or_sqe_flags_union, sqe_flags) } } diff --git a/vendor/rustix/src/ioctl/bsd.rs b/vendor/rustix/src/ioctl/bsd.rs new file mode 100644 index 000000000..66b75b54b --- /dev/null +++ b/vendor/rustix/src/ioctl/bsd.rs @@ -0,0 +1,24 @@ +//! `ioctl` opcode behavior for Linux platforms. + +use super::{Direction, RawOpcode}; + +pub(super) const fn compose_opcode( + dir: Direction, + group: RawOpcode, + num: RawOpcode, + size: RawOpcode, +) -> RawOpcode { + let dir = match dir { + Direction::None => NONE, + Direction::Read => READ, + Direction::Write => WRITE, + Direction::ReadWrite => READ | WRITE, + }; + + dir | num | (group << 8) | ((size & IOCPARAM_MASK) << 16) +} + +pub const NONE: RawOpcode = 0x2000_0000; +pub const WRITE: RawOpcode = 0x4000_0000; +pub const READ: RawOpcode = 0x8000_0000; +pub const IOCPARAM_MASK: RawOpcode = 0x1FFF; diff --git a/vendor/rustix/src/ioctl/linux.rs b/vendor/rustix/src/ioctl/linux.rs new file mode 100644 index 000000000..9dc278656 --- /dev/null +++ b/vendor/rustix/src/ioctl/linux.rs @@ -0,0 +1,83 @@ +//! `ioctl` opcode behavior for Linux platforms. + +use super::{Direction, RawOpcode}; +use consts::*; + +/// Compose an opcode from its component parts. +pub(super) const fn compose_opcode( + dir: Direction, + group: RawOpcode, + num: RawOpcode, + size: RawOpcode, +) -> RawOpcode { + macro_rules! shift_and_mask { + ($val:expr, $shift:expr, $mask:expr) => {{ + ($val << $shift) & $mask + }}; + } + + let dir = match dir { + Direction::None => NONE, + Direction::Read => READ, + Direction::Write => WRITE, + Direction::ReadWrite => READ | WRITE, + }; + + shift_and_mask!(group, GROUP_SHIFT, GROUP_MASK) + | shift_and_mask!(num, NUM_SHIFT, NUM_MASK) + | shift_and_mask!(size, SIZE_SHIFT, SIZE_MASK) + | shift_and_mask!(dir, DIR_SHIFT, DIR_MASK) +} + +const NUM_BITS: RawOpcode = 8; +const GROUP_BITS: RawOpcode = 8; + +const NUM_SHIFT: RawOpcode = 0; +const GROUP_SHIFT: RawOpcode = NUM_SHIFT + NUM_BITS; +const SIZE_SHIFT: RawOpcode = GROUP_SHIFT + GROUP_BITS; +const DIR_SHIFT: RawOpcode = SIZE_SHIFT + SIZE_BITS; + +const NUM_MASK: RawOpcode = (1 << NUM_BITS) - 1; +const GROUP_MASK: RawOpcode = (1 << GROUP_BITS) - 1; +const SIZE_MASK: RawOpcode = (1 << SIZE_BITS) - 1; +const DIR_MASK: RawOpcode = (1 << DIR_BITS) - 1; + +#[cfg(any( + target_arch = "x86", + target_arch = "arm", + target_arch = "s390x", + target_arch = "x86_64", + target_arch = "aarch64", + target_arch = "riscv32", + target_arch = "riscv64", + target_arch = "loongarch64" +))] +mod consts { + use super::RawOpcode; + + pub(super) const NONE: RawOpcode = 0; + pub(super) const READ: RawOpcode = 2; + pub(super) const WRITE: RawOpcode = 1; + pub(super) const SIZE_BITS: RawOpcode = 14; + pub(super) const DIR_BITS: RawOpcode = 2; +} + +#[cfg(any( + target_arch = "mips", + target_arch = "mips32r6", + target_arch = "mips64", + target_arch = "mips64r6", + target_arch = "powerpc", + target_arch = "powerpc64", + target_arch = "sparc", + target_arch = "sparc64" +))] +mod consts { + use super::RawOpcode; + + pub(super) const NONE: RawOpcode = 1; + pub(super) const READ: RawOpcode = 2; + pub(super) const WRITE: RawOpcode = 4; + pub(super) const SIZE_BITS: RawOpcode = 13; + pub(super) const DIR_BITS: RawOpcode = 3; +} diff --git a/vendor/rustix/src/ioctl/mod.rs b/vendor/rustix/src/ioctl/mod.rs new file mode 100644 index 000000000..bf2215ab6 --- /dev/null +++ b/vendor/rustix/src/ioctl/mod.rs @@ -0,0 +1,338 @@ +//! Unsafe `ioctl` API. +//! +//! Unix systems expose a number of `ioctl`'s. `ioctl`s have been adopted as a +//! general purpose system call for making calls into the kernel. In addition +//! to the wide variety of system calls that are included by default in the +//! kernel, many drivers expose their own `ioctl`'s for controlling their +//! behavior, some of which are proprietary. Therefore it is impossible to make +//! a safe interface for every `ioctl` call, as they all have wildly varying +//! semantics. +//! +//! This module provides an unsafe interface to write your own `ioctl` API. To +//! start, create a type that implements [`Ioctl`]. Then, pass it to [`ioctl`] +//! to make the `ioctl` call. + +#![allow(unsafe_code)] + +use crate::backend::c; +use crate::fd::{AsFd, BorrowedFd}; +use crate::io::Result; + +#[cfg(any(linux_kernel, bsd))] +use core::mem; + +pub use patterns::*; + +mod patterns; + +#[cfg(linux_kernel)] +mod linux; + +#[cfg(bsd)] +mod bsd; + +#[cfg(linux_kernel)] +use linux as platform; + +#[cfg(bsd)] +use bsd as platform; + +/// Perform an `ioctl` call. +/// +/// `ioctl` was originally intended to act as a way of modifying the behavior +/// of files, but has since been adopted as a general purpose system call for +/// making calls into the kernel. In addition to the default calls exposed by +/// generic file descriptors, many drivers expose their own `ioctl` calls for +/// controlling their behavior, some of which are proprietary. +/// +/// This crate exposes many other `ioctl` interfaces with safe and idiomatic +/// wrappers, like [`ioctl_fionbio`](crate::io::ioctl_fionbio) and +/// [`ioctl_fionread`](crate::io::ioctl_fionread). It is recommended to use +/// those instead of this function, as they are safer and more idiomatic. +/// For other cases, implement the [`Ioctl`] API and pass it to this function. +/// +/// See documentation for [`Ioctl`] for more information. +/// +/// # Safety +/// +/// While [`Ioctl`] takes much of the unsafety out of `ioctl` calls, it is +/// still unsafe to call this code with arbitrary device drivers, as it is up +/// to the device driver to implement the `ioctl` call correctly. It is on the +/// onus of the protocol between the user and the driver to ensure that the +/// `ioctl` call is safe to make. +/// +/// # References +/// +/// - [Linux] +/// - [WinSock2] +/// - [FreeBSD] +/// - [NetBSD] +/// - [OpenBSD] +/// - [Apple] +/// - [Solaris] +/// - [illumos] +/// +/// [Linux]: https://man7.org/linux/man-pages/man2/ioctl.2.html +/// [Winsock2]: https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-ioctlsocket +/// [FreeBSD]: https://man.freebsd.org/cgi/man.cgi?query=ioctl&sektion=2 +/// [NetBSD]: https://man.netbsd.org/ioctl.2 +/// [OpenBSD]: https://man.openbsd.org/ioctl.2 +/// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/ioctl.2.html +/// [Solaris]: https://docs.oracle.com/cd/E23824_01/html/821-1463/ioctl-2.html +/// [illumos]: https://illumos.org/man/2/ioctl +#[inline] +pub unsafe fn ioctl<F: AsFd, I: Ioctl>(fd: F, mut ioctl: I) -> Result<I::Output> { + let fd = fd.as_fd(); + let request = I::OPCODE.raw(); + let arg = ioctl.as_ptr(); + + // SAFETY: The variant of `Ioctl` asserts that this is a valid IOCTL call to + // make. + let output = if I::IS_MUTATING { + _ioctl(fd, request, arg)? + } else { + _ioctl_readonly(fd, request, arg)? + }; + + // SAFETY: The variant of `Ioctl` asserts that this is a valid pointer to the + // output data. + I::output_from_ptr(output, arg) +} + +unsafe fn _ioctl( + fd: BorrowedFd<'_>, + request: RawOpcode, + arg: *mut c::c_void, +) -> Result<IoctlOutput> { + crate::backend::io::syscalls::ioctl(fd, request, arg) +} + +unsafe fn _ioctl_readonly( + fd: BorrowedFd<'_>, + request: RawOpcode, + arg: *mut c::c_void, +) -> Result<IoctlOutput> { + crate::backend::io::syscalls::ioctl_readonly(fd, request, arg) +} + +/// A trait defining the properties of an `ioctl` command. +/// +/// Objects implementing this trait can be passed to [`ioctl`] to make an +/// `ioctl` call. The contents of the object represent the inputs to the +/// `ioctl` call. The inputs must be convertible to a pointer through the +/// `as_ptr` method. In most cases, this involves either casting a number to a +/// pointer, or creating a pointer to the actual data. The latter case is +/// necessary for `ioctl` calls that modify userspace data. +/// +/// # Safety +/// +/// This trait is unsafe to implement because it is impossible to guarantee +/// that the `ioctl` call is safe. The `ioctl` call may be proprietary, or it +/// may be unsafe to call in certain circumstances. +/// +/// By implementing this trait, you guarantee that: +/// +/// - The `ioctl` call expects the input provided by `as_ptr` and produces the +/// output as indicated by `output`. +/// - That `output_from_ptr` can safely take the pointer from `as_ptr` and cast +/// it to the correct type, *only* after the `ioctl` call. +/// - That `OPCODE` uniquely identifies the `ioctl` call. +/// - That, for whatever platforms you are targeting, the `ioctl` call is safe +/// to make. +/// - If `IS_MUTATING` is false, that no userspace data will be modified by the +/// `ioctl` call. +pub unsafe trait Ioctl { + /// The type of the output data. + /// + /// Given a pointer, one should be able to construct an instance of this + /// type. + type Output; + + /// The opcode used by this `ioctl` command. + /// + /// There are different types of opcode depending on the operation. See + /// documentation for the [`Opcode`] struct for more information. + const OPCODE: Opcode; + + /// Does the `ioctl` mutate any data in the userspace? + /// + /// If the `ioctl` call does not mutate any data in the userspace, then + /// making this `false` enables optimizations that can make the call + /// faster. When in doubt, set this to `true`. + /// + /// # Safety + /// + /// This should only be set to `false` if the `ioctl` call does not mutate + /// any data in the userspace. Undefined behavior may occur if this is set + /// to `false` when it should be `true`. + const IS_MUTATING: bool; + + /// Get a pointer to the data to be passed to the `ioctl` command. + /// + /// See trait-level documentation for more information. + fn as_ptr(&mut self) -> *mut c::c_void; + + /// Cast the output data to the correct type. + /// + /// # Safety + /// + /// The `extract_output` value must be the resulting value after a + /// successful `ioctl` call, and `out` is the direct return value of an + /// `ioctl` call that did not fail. In this case `extract_output` is the + /// pointer that was passed to the `ioctl` call. + unsafe fn output_from_ptr( + out: IoctlOutput, + extract_output: *mut c::c_void, + ) -> Result<Self::Output>; +} + +/// The opcode used by an `Ioctl`. +#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] +pub struct Opcode { + /// The raw opcode. + raw: RawOpcode, +} + +impl Opcode { + /// Create a new old `Opcode` from a raw opcode. + /// + /// Rather than being a composition of several attributes, old opcodes are + /// just numbers. In general most drivers follow stricter conventions, but + /// older drivers may still use this strategy. + #[inline] + pub const fn old(raw: RawOpcode) -> Self { + Self { raw } + } + + /// Create a new opcode from a direction, group, number and size. + #[cfg(any(linux_kernel, bsd))] + #[inline] + pub const fn from_components( + direction: Direction, + group: u8, + number: u8, + data_size: usize, + ) -> Self { + if data_size > RawOpcode::MAX as usize { + panic!("data size is too large"); + } + + Self::old(platform::compose_opcode( + direction, + group as RawOpcode, + number as RawOpcode, + data_size as RawOpcode, + )) + } + + /// Create a new non-mutating opcode from a group, a number and the type of + /// data. + #[cfg(any(linux_kernel, bsd))] + #[inline] + pub const fn none<T>(group: u8, number: u8) -> Self { + Self::from_components(Direction::None, group, number, mem::size_of::<T>()) + } + + /// Create a new reading opcode from a group, a number and the type of + /// data. + #[cfg(any(linux_kernel, bsd))] + #[inline] + pub const fn read<T>(group: u8, number: u8) -> Self { + Self::from_components(Direction::Read, group, number, mem::size_of::<T>()) + } + + /// Create a new writing opcode from a group, a number and the type of + /// data. + #[cfg(any(linux_kernel, bsd))] + #[inline] + pub const fn write<T>(group: u8, number: u8) -> Self { + Self::from_components(Direction::Write, group, number, mem::size_of::<T>()) + } + + /// Create a new reading and writing opcode from a group, a number and the + /// type of data. + #[cfg(any(linux_kernel, bsd))] + #[inline] + pub const fn read_write<T>(group: u8, number: u8) -> Self { + Self::from_components(Direction::ReadWrite, group, number, mem::size_of::<T>()) + } + + /// Get the raw opcode. + #[inline] + pub fn raw(self) -> RawOpcode { + self.raw + } +} + +/// The direction that an `ioctl` is going. +/// +/// Note that this is relative to userspace. `Read` means reading data from the +/// kernel, and write means the kernel writing data to userspace. +#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] +pub enum Direction { + /// None of the above. + None, + + /// Read data from the kernel. + Read, + + /// Write data to the kernel. + Write, + + /// Read and write data to the kernel. + ReadWrite, +} + +/// The type used by the `ioctl` to signify the output. +pub type IoctlOutput = c::c_int; + +/// The type used by the `ioctl` to signify the command. +pub type RawOpcode = _RawOpcode; + +// Under raw Linux, this is an `unsigned int`. +#[cfg(linux_raw)] +type _RawOpcode = c::c_uint; + +// On libc Linux with GNU libc or uclibc, this is an `unsigned long`. +#[cfg(all( + not(linux_raw), + target_os = "linux", + any(target_env = "gnu", target_env = "uclibc") +))] +type _RawOpcode = c::c_ulong; + +// Musl uses `c_int`. +#[cfg(all( + not(linux_raw), + target_os = "linux", + not(target_env = "gnu"), + not(target_env = "uclibc") +))] +type _RawOpcode = c::c_int; + +// Android uses `c_int`. +#[cfg(all(not(linux_raw), target_os = "android"))] +type _RawOpcode = c::c_int; + +// BSD, Haiku, and Redox use `unsigned long`. +#[cfg(any(bsd, target_os = "redox", target_os = "haiku"))] +type _RawOpcode = c::c_ulong; + +// AIX, Emscripten, Fuchsia, Solaris, and WASI use a `int`. +#[cfg(any( + solarish, + target_os = "aix", + target_os = "fuchsia", + target_os = "emscripten", + target_os = "wasi", + target_os = "nto" +))] +type _RawOpcode = c::c_int; + +// ESP-IDF uses a `c_uint`. +#[cfg(target_os = "espidf")] +type _RawOpcode = c::c_uint; + +// Windows has `ioctlsocket`, which uses `i32`. +#[cfg(windows)] +type _RawOpcode = i32; diff --git a/vendor/rustix/src/ioctl/patterns.rs b/vendor/rustix/src/ioctl/patterns.rs new file mode 100644 index 000000000..4b33d7d80 --- /dev/null +++ b/vendor/rustix/src/ioctl/patterns.rs @@ -0,0 +1,202 @@ +//! Implements typical patterns for `ioctl` usage. + +use super::{Ioctl, IoctlOutput, Opcode, RawOpcode}; + +use crate::backend::c; +use crate::io::Result; + +use core::marker::PhantomData; +use core::{fmt, mem}; + +/// Implements an `ioctl` with no real arguments. +pub struct NoArg<Opcode> { + /// The opcode. + _opcode: PhantomData<Opcode>, +} + +impl<Opcode: CompileTimeOpcode> fmt::Debug for NoArg<Opcode> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_tuple("NoArg").field(&Opcode::OPCODE).finish() + } +} + +impl<Opcode: CompileTimeOpcode> NoArg<Opcode> { + /// Create a new no-argument `ioctl` object. + /// + /// # Safety + /// + /// - `Opcode` must provide a valid opcode. + #[inline] + pub unsafe fn new() -> Self { + Self { + _opcode: PhantomData, + } + } +} + +unsafe impl<Opcode: CompileTimeOpcode> Ioctl for NoArg<Opcode> { + type Output = (); + + const IS_MUTATING: bool = false; + const OPCODE: self::Opcode = Opcode::OPCODE; + + fn as_ptr(&mut self) -> *mut c::c_void { + core::ptr::null_mut() + } + + unsafe fn output_from_ptr(_: IoctlOutput, _: *mut c::c_void) -> Result<Self::Output> { + Ok(()) + } +} + +/// Implements the traditional "getter" pattern for `ioctl`s. +/// +/// Some `ioctl`s just read data into the userspace. As this is a popular +/// pattern this structure implements it. +pub struct Getter<Opcode, Output> { + /// The output data. + output: mem::MaybeUninit<Output>, + + /// The opcode. + _opcode: PhantomData<Opcode>, +} + +impl<Opcode: CompileTimeOpcode, Output> fmt::Debug for Getter<Opcode, Output> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_tuple("Getter").field(&Opcode::OPCODE).finish() + } +} + +impl<Opcode: CompileTimeOpcode, Output> Getter<Opcode, Output> { + /// Create a new getter-style `ioctl` object. + /// + /// # Safety + /// + /// - `Opcode` must provide a valid opcode. + /// - For this opcode, `Output` must be the type that the kernel expects to + /// write into. + #[inline] + pub unsafe fn new() -> Self { + Self { + output: mem::MaybeUninit::uninit(), + _opcode: PhantomData, + } + } +} + +unsafe impl<Opcode: CompileTimeOpcode, Output> Ioctl for Getter<Opcode, Output> { + type Output = Output; + + const IS_MUTATING: bool = true; + const OPCODE: self::Opcode = Opcode::OPCODE; + + fn as_ptr(&mut self) -> *mut c::c_void { + self.output.as_mut_ptr().cast() + } + + unsafe fn output_from_ptr(_: IoctlOutput, ptr: *mut c::c_void) -> Result<Self::Output> { + Ok(ptr.cast::<Output>().read()) + } +} + +/// Implements the pattern for `ioctl`s where a pointer argument is given to +/// the `ioctl`. +/// +/// The opcode must be read-only. +pub struct Setter<Opcode, Input> { + /// The input data. + input: Input, + + /// The opcode. + _opcode: PhantomData<Opcode>, +} + +impl<Opcode: CompileTimeOpcode, Input: fmt::Debug> fmt::Debug for Setter<Opcode, Input> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_tuple("Setter") + .field(&Opcode::OPCODE) + .field(&self.input) + .finish() + } +} + +impl<Opcode: CompileTimeOpcode, Input> Setter<Opcode, Input> { + /// Create a new pointer setter-style `ioctl` object. + /// + /// # Safety + /// + /// - `Opcode` must provide a valid opcode. + /// - For this opcode, `Input` must be the type that the kernel expects to + /// get. + #[inline] + pub unsafe fn new(input: Input) -> Self { + Self { + input, + _opcode: PhantomData, + } + } +} + +unsafe impl<Opcode: CompileTimeOpcode, Input> Ioctl for Setter<Opcode, Input> { + type Output = (); + + const IS_MUTATING: bool = false; + const OPCODE: self::Opcode = Opcode::OPCODE; + + fn as_ptr(&mut self) -> *mut c::c_void { + &mut self.input as *mut Input as *mut c::c_void + } + + unsafe fn output_from_ptr(_: IoctlOutput, _: *mut c::c_void) -> Result<Self::Output> { + Ok(()) + } +} + +/// Trait for something that provides an `ioctl` opcode at compile time. +pub trait CompileTimeOpcode { + /// The opcode. + const OPCODE: Opcode; +} + +/// Provides a bad opcode at compile time. +pub struct BadOpcode<const OPCODE: RawOpcode>; + +impl<const OPCODE: RawOpcode> CompileTimeOpcode for BadOpcode<OPCODE> { + const OPCODE: Opcode = Opcode::old(OPCODE); +} + +/// Provides a read code at compile time. +#[cfg(any(linux_kernel, bsd))] +pub struct ReadOpcode<const GROUP: u8, const NUM: u8, Data>(Data); + +#[cfg(any(linux_kernel, bsd))] +impl<const GROUP: u8, const NUM: u8, Data> CompileTimeOpcode for ReadOpcode<GROUP, NUM, Data> { + const OPCODE: Opcode = Opcode::read::<Data>(GROUP, NUM); +} + +/// Provides a write code at compile time. +#[cfg(any(linux_kernel, bsd))] +pub struct WriteOpcode<const GROUP: u8, const NUM: u8, Data>(Data); + +#[cfg(any(linux_kernel, bsd))] +impl<const GROUP: u8, const NUM: u8, Data> CompileTimeOpcode for WriteOpcode<GROUP, NUM, Data> { + const OPCODE: Opcode = Opcode::write::<Data>(GROUP, NUM); +} + +/// Provides a read/write code at compile time. +#[cfg(any(linux_kernel, bsd))] +pub struct ReadWriteOpcode<const GROUP: u8, const NUM: u8, Data>(Data); + +#[cfg(any(linux_kernel, bsd))] +impl<const GROUP: u8, const NUM: u8, Data> CompileTimeOpcode for ReadWriteOpcode<GROUP, NUM, Data> { + const OPCODE: Opcode = Opcode::read_write::<Data>(GROUP, NUM); +} + +/// Provides a `None` code at compile time. +#[cfg(any(linux_kernel, bsd))] +pub struct NoneOpcode<const GROUP: u8, const NUM: u8, Data>(Data); + +#[cfg(any(linux_kernel, bsd))] +impl<const GROUP: u8, const NUM: u8, Data> CompileTimeOpcode for NoneOpcode<GROUP, NUM, Data> { + const OPCODE: Opcode = Opcode::none::<Data>(GROUP, NUM); +} diff --git a/vendor/rustix/src/lib.rs b/vendor/rustix/src/lib.rs index 988525e5f..a23006f9c 100644 --- a/vendor/rustix/src/lib.rs +++ b/vendor/rustix/src/lib.rs @@ -55,7 +55,8 @@ //! - Path arguments use [`Arg`], so they accept any string type. //! - File descriptors are passed and returned via [`AsFd`] and [`OwnedFd`] //! instead of bare integers, ensuring I/O safety. -//! - Constants use `enum`s and [`bitflags`] types. +//! - Constants use `enum`s and [`bitflags`] types, and enable [support for +//! externally defined flags]. //! - Multiplexed functions (eg. `fcntl`, `ioctl`, etc.) are de-multiplexed. //! - Variadic functions (eg. `openat`, etc.) are presented as non-variadic. //! - Functions that return strings automatically allocate sufficient memory @@ -93,6 +94,7 @@ //! [I/O-safe]: https://github.com/rust-lang/rfcs/blob/master/text/3128-io-safety.md //! [`Result`]: https://doc.rust-lang.org/stable/std/result/enum.Result.html //! [`Arg`]: https://docs.rs/rustix/*/rustix/path/trait.Arg.html +//! [support for externally defined flags]: https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags #![deny(missing_docs)] #![allow(stable_features)] @@ -102,10 +104,11 @@ #![cfg_attr(all(wasi_ext, target_os = "wasi", feature = "std"), feature(wasi_ext))] #![cfg_attr(core_ffi_c, feature(core_ffi_c))] #![cfg_attr(core_c_str, feature(core_c_str))] -#![cfg_attr(alloc_c_string, feature(alloc_c_string))] -#![cfg_attr(alloc_ffi, feature(alloc_ffi))] +#![cfg_attr(all(feature = "alloc", alloc_c_string), feature(alloc_c_string))] +#![cfg_attr(all(feature = "alloc", alloc_ffi), feature(alloc_ffi))] #![cfg_attr(not(feature = "std"), no_std)] #![cfg_attr(feature = "rustc-dep-of-std", feature(ip))] +#![cfg_attr(feature = "rustc-dep-of-std", allow(internal_features))] #![cfg_attr( any(feature = "rustc-dep-of-std", core_intrinsics), feature(core_intrinsics) @@ -120,7 +123,7 @@ // conditionalizing all the `use`s for them. #![cfg_attr(any(target_os = "redox", target_os = "wasi"), allow(unused_imports))] -#[cfg(not(feature = "rustc-dep-of-std"))] +#[cfg(all(feature = "alloc", not(feature = "rustc-dep-of-std")))] extern crate alloc; // Use `static_assertions` macros if we have them, or a polyfill otherwise. @@ -137,6 +140,7 @@ mod static_assertions; #[cfg(not(windows))] #[macro_use] pub(crate) mod cstr; +#[macro_use] pub(crate) mod utils; // Polyfill for `std` in `no_std` builds. #[cfg_attr(feature = "std", path = "maybe_polyfill/std/mod.rs")] @@ -189,20 +193,7 @@ pub mod event; #[cfg(not(windows))] pub mod ffi; #[cfg(not(windows))] -#[cfg(any( - feature = "fs", - all( - linux_raw, - not(feature = "use-libc-auxv"), - not(target_vendor = "mustang"), - any( - feature = "param", - feature = "runtime", - feature = "time", - target_arch = "x86", - ) - ) -))] +#[cfg(feature = "fs")] #[cfg_attr(doc_cfg, doc(cfg(feature = "fs")))] pub mod fs; pub mod io; @@ -210,6 +201,7 @@ pub mod io; #[cfg(feature = "io_uring")] #[cfg_attr(doc_cfg, doc(cfg(feature = "io_uring")))] pub mod io_uring; +pub mod ioctl; #[cfg(not(any(windows, target_os = "espidf", target_os = "wasi")))] #[cfg(feature = "mm")] #[cfg_attr(doc_cfg, doc(cfg(feature = "mm")))] @@ -227,22 +219,7 @@ pub mod net; #[cfg_attr(doc_cfg, doc(cfg(feature = "param")))] pub mod param; #[cfg(not(windows))] -#[cfg(any( - feature = "fs", - feature = "mount", - feature = "net", - all( - linux_raw, - not(feature = "use-libc-auxv"), - not(target_vendor = "mustang"), - any( - feature = "param", - feature = "runtime", - feature = "time", - target_arch = "x86", - ) - ) -))] +#[cfg(any(feature = "fs", feature = "mount", feature = "net"))] #[cfg_attr( doc_cfg, doc(cfg(any(feature = "fs", feature = "mount", feature = "net"))) @@ -294,7 +271,7 @@ pub mod time; #[cfg(not(windows))] #[cfg(feature = "runtime")] #[cfg(linux_raw)] -#[doc(hidden)] +#[cfg_attr(not(document_experimental_runtime_api), doc(hidden))] #[cfg_attr(doc_cfg, doc(cfg(feature = "runtime")))] pub mod runtime; @@ -304,6 +281,40 @@ pub mod runtime; #[cfg(all(feature = "fs", not(feature = "mount")))] pub(crate) mod mount; +// Declare "fs" as a non-public module if "fs" isn't enabled but we need it for +// reading procfs. +#[cfg(not(windows))] +#[cfg(not(feature = "fs"))] +#[cfg(all( + linux_raw, + not(feature = "use-libc-auxv"), + not(feature = "use-explicitly-provided-auxv"), + any( + feature = "param", + feature = "runtime", + feature = "time", + target_arch = "x86", + ) +))] +#[cfg_attr(doc_cfg, doc(cfg(feature = "fs")))] +pub(crate) mod fs; + +// Similarly, declare `path` as a non-public module if needed. +#[cfg(not(windows))] +#[cfg(not(any(feature = "fs", feature = "mount", feature = "net")))] +#[cfg(all( + linux_raw, + not(feature = "use-libc-auxv"), + not(feature = "use-explicitly-provided-auxv"), + any( + feature = "param", + feature = "runtime", + feature = "time", + target_arch = "x86", + ) +))] +pub(crate) mod path; + // Private modules used by multiple public modules. #[cfg(not(any(windows, target_os = "espidf")))] #[cfg(any(feature = "thread", feature = "time", target_arch = "x86"))] @@ -333,7 +344,7 @@ mod signal; all( linux_raw, not(feature = "use-libc-auxv"), - not(target_vendor = "mustang"), + not(feature = "use-explicitly-provided-auxv"), any( feature = "param", feature = "runtime", @@ -351,7 +362,7 @@ mod timespec; all( linux_raw, 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/maybe_polyfill/no_std/mod.rs b/vendor/rustix/src/maybe_polyfill/no_std/mod.rs index ab088d862..84bf5b764 100644 --- a/vendor/rustix/src/maybe_polyfill/no_std/mod.rs +++ b/vendor/rustix/src/maybe_polyfill/no_std/mod.rs @@ -1,11 +1,12 @@ //! Polyfill of parts of the standard library for `no_std` builds. //! -//! All code in this subtree is derived from the standard library and licensed MIT or Apache 2.0 -//! at your option. +//! All code in this subtree is derived from the standard library and licensed +//! MIT or Apache 2.0 at your option. //! -//! This implementation is used when `std` is not available and polyfills the necessary items from -//! `std`. When the `std` feature is specified (so the standard library is available), the file -//! `src/polyfill/std` is used instead, which just imports the respective items from `std`. +//! This implementation is used when `std` is not available and polyfills the +//! necessary items from `std`. When the `std` feature is specified (so the +//! standard library is available), the file `src/polyfill/std` is used +//! instead, which just imports the respective items from `std`. #[cfg(not(windows))] pub mod io; diff --git a/vendor/rustix/src/maybe_polyfill/no_std/net/ip_addr.rs b/vendor/rustix/src/maybe_polyfill/no_std/net/ip_addr.rs index ffa5302e3..81415e960 100644 --- a/vendor/rustix/src/maybe_polyfill/no_std/net/ip_addr.rs +++ b/vendor/rustix/src/maybe_polyfill/no_std/net/ip_addr.rs @@ -1653,7 +1653,7 @@ impl Ipv6Addr { && !self.is_benchmarking() } - /// Returns the address's multicast scope if the address is multicast. + /// Returns the address' multicast scope if the address is multicast. /// /// # Examples /// diff --git a/vendor/rustix/src/maybe_polyfill/no_std/os/fd/owned.rs b/vendor/rustix/src/maybe_polyfill/no_std/os/fd/owned.rs index 90b6f4712..fffe34bff 100644 --- a/vendor/rustix/src/maybe_polyfill/no_std/os/fd/owned.rs +++ b/vendor/rustix/src/maybe_polyfill/no_std/os/fd/owned.rs @@ -115,6 +115,42 @@ impl OwnedFd { } } +impl BorrowedFd<'_> { + /// Creates a new `OwnedFd` instance that shares the same underlying file + /// description as the existing `BorrowedFd` instance. + #[cfg(not(any(target_arch = "wasm32", target_os = "hermit")))] + #[cfg_attr(staged_api, stable(feature = "io_safety", since = "1.63.0"))] + pub fn try_clone_to_owned(&self) -> crate::io::Result<OwnedFd> { + // Avoid using file descriptors below 3 as they are used for stdio + + // We want to atomically duplicate this file descriptor and set the + // CLOEXEC flag, and currently that's done via F_DUPFD_CLOEXEC. This + // is a POSIX flag that was added to Linux in 2.6.24. + #[cfg(not(target_os = "espidf"))] + let fd = crate::io::fcntl_dupfd_cloexec(self, 3)?; + + // For ESP-IDF, F_DUPFD is used instead, because the CLOEXEC semantics + // will never be supported, as this is a bare metal framework with + // no capabilities for multi-process execution. While F_DUPFD is also + // not supported yet, it might be (currently it returns ENOSYS). + #[cfg(target_os = "espidf")] + let fd = crate::io::fcntl_dupfd(self, 3)?; + + Ok(fd) + } + + /// Creates a new `OwnedFd` instance that shares the same underlying file + /// description as the existing `BorrowedFd` instance. + #[cfg(any(target_arch = "wasm32", target_os = "hermit"))] + #[cfg_attr(staged_api, stable(feature = "io_safety", since = "1.63.0"))] + pub fn try_clone_to_owned(&self) -> crate::io::Result<OwnedFd> { + Err(crate::io::const_io_error!( + crate::io::ErrorKind::Unsupported, + "operation not supported on WASI yet", + )) + } +} + #[cfg_attr(staged_api, unstable(feature = "io_safety", issue = "87074"))] impl AsRawFd for BorrowedFd<'_> { #[inline] diff --git a/vendor/rustix/src/maybe_polyfill/std/mod.rs b/vendor/rustix/src/maybe_polyfill/std/mod.rs index 92b5cab5b..bcaceb9fb 100644 --- a/vendor/rustix/src/maybe_polyfill/std/mod.rs +++ b/vendor/rustix/src/maybe_polyfill/std/mod.rs @@ -1,8 +1,10 @@ -//! Imports from `std` that would be polyfilled for `no_std` builds (see `src/polyfill/no_std`). +//! Imports from `std` that would be polyfilled for `no_std` builds (see +//! `src/polyfill/no_std`). //! -//! This implementation is used when `std` is available and just imports the necessary items from -//! `std`. For `no_std` builds, the file `src/polyfill/no_std` is used instead, which doesn't -//! depend on the standard library. +//! This implementation is used when `std` is available and just imports the +//! necessary items from `std`. For `no_std` builds, the file +//! `src/polyfill/no_std` is used instead, which doesn't depend on the standard +//! library. #[cfg(not(windows))] pub mod io { diff --git a/vendor/rustix/src/net/send_recv/msg.rs b/vendor/rustix/src/net/send_recv/msg.rs index 5fefb2e24..431aefa03 100644 --- a/vendor/rustix/src/net/send_recv/msg.rs +++ b/vendor/rustix/src/net/send_recv/msg.rs @@ -107,8 +107,8 @@ impl<'buf, 'slice, 'fd> SendAncillaryBuffer<'buf, 'slice, 'fd> { /// Returns a pointer to the message data. pub(crate) fn as_control_ptr(&mut self) -> *mut u8 { - // When the length is zero, we may be using a `&[]` address, which - // may be an invalid but non-null pointer, and on some platforms, that + // When the length is zero, we may be using a `&[]` address, which may + // be an invalid but non-null pointer, and on some platforms, that // causes `sendmsg` to fail with `EFAULT` or `EINVAL` #[cfg(not(linux_kernel))] if self.length == 0 { @@ -227,8 +227,8 @@ impl<'buf> RecvAncillaryBuffer<'buf> { /// Returns a pointer to the message data. pub(crate) fn as_control_ptr(&mut self) -> *mut u8 { - // When the length is zero, we may be using a `&[]` address, which - // may be an invalid but non-null pointer, and on some platforms, that + // When the length is zero, we may be using a `&[]` address, which may + // be an invalid but non-null pointer, and on some platforms, that // causes `sendmsg` to fail with `EFAULT` or `EINVAL` #[cfg(not(linux_kernel))] if self.buffer.is_empty() { @@ -686,9 +686,9 @@ impl<T> DoubleEndedIterator for AncillaryIter<'_, T> { mod messages { use crate::backend::c; + use crate::backend::net::msghdr; use core::iter::FusedIterator; use core::marker::PhantomData; - use core::mem::zeroed; use core::ptr::NonNull; /// An iterator over the messages in an ancillary buffer. @@ -709,7 +709,7 @@ mod messages { /// Create a new iterator over messages from a byte buffer. pub(super) fn new(buf: &'buf mut [u8]) -> Self { let msghdr = { - let mut h: c::msghdr = unsafe { zeroed() }; + let mut h = msghdr::zero_msghdr(); h.msg_control = buf.as_mut_ptr().cast(); h.msg_controllen = buf.len().try_into().expect("buffer too large for msghdr"); h diff --git a/vendor/rustix/src/net/socket.rs b/vendor/rustix/src/net/socket.rs index 23cc00aed..8727ca53b 100644 --- a/vendor/rustix/src/net/socket.rs +++ b/vendor/rustix/src/net/socket.rs @@ -13,7 +13,8 @@ pub use backend::net::addr::SocketAddrUnix; /// however it is not safe in general to rely on this, as file descriptors may /// be unexpectedly allocated on other threads or in libraries. /// -/// To pass extra flags such as [`SocketFlags::CLOEXEC`], use [`socket_with`]. +/// To pass extra flags such as [`SocketFlags::CLOEXEC`] or +/// [`SocketFlags::NONBLOCK`], use [`socket_with`]. /// /// # References /// - [Beej's Guide to Network Programming] @@ -82,6 +83,7 @@ pub fn socket( /// [DragonFly BSD]: https://man.dragonflybsd.org/?command=socket§ion=2 /// [illumos]: https://illumos.org/man/3SOCKET/socket /// [glibc]: https://www.gnu.org/software/libc/manual/html_node/Creating-a-Socket.html +#[doc(alias("socket"))] #[inline] pub fn socket_with( domain: AddressFamily, @@ -271,6 +273,10 @@ pub fn bind_unix<Fd: AsFd>(sockfd: Fd, addr: &SocketAddrUnix) -> io::Result<()> /// `connect(sockfd, addr)`—Initiates a connection to an IP address. /// +/// On Windows, a non-blocking socket returns [`Errno::WOULDBLOCK`] if the +/// connection cannot be completed immediately, rather than +/// `Errno::INPROGRESS`. +/// /// # References /// - [Beej's Guide to Network Programming] /// - [POSIX] @@ -295,6 +301,7 @@ pub fn bind_unix<Fd: AsFd>(sockfd: Fd, addr: &SocketAddrUnix) -> io::Result<()> /// [DragonFly BSD]: https://man.dragonflybsd.org/?command=connect§ion=2 /// [illumos]: https://illumos.org/man/3SOCKET/connect /// [glibc]: https://www.gnu.org/software/libc/manual/html_node/Connecting.html +/// [`Errno::WOULDBLOCK`]: io::Errno::WOULDBLOCK pub fn connect<Fd: AsFd>(sockfd: Fd, addr: &SocketAddr) -> io::Result<()> { _connect(sockfd.as_fd(), addr) } diff --git a/vendor/rustix/src/net/sockopt.rs b/vendor/rustix/src/net/sockopt.rs index b21d4a35c..1939155d9 100644 --- a/vendor/rustix/src/net/sockopt.rs +++ b/vendor/rustix/src/net/sockopt.rs @@ -6,6 +6,18 @@ #![doc(alias = "getsockopt")] #![doc(alias = "setsockopt")] +#[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::{backend, io}; use backend::c; @@ -103,6 +115,44 @@ pub fn set_socket_reuseaddr<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> { backend::net::syscalls::sockopt::set_socket_reuseaddr(fd.as_fd(), value) } +/// `getsockopt(fd, SOL_SOCKET, SO_REUSEADDR)` +/// +/// # References +/// - [POSIX `getsockopt`] +/// - [POSIX `sys/socket.h`] +/// - [Linux `getsockopt`] +/// - [Linux `socket`] +/// - [Winsock2 `getsockopt`] +/// - [Winsock2 `SOL_SOCKET` options] +/// - [Apple] +/// - [FreeBSD] +/// - [NetBSD] +/// - [OpenBSD] +/// - [DragonFly BSD] +/// - [illumos] +/// - [glibc `getsockopt`] +/// - [glibc `SOL_SOCKET` Options] +/// +/// [POSIX `getsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html +/// [POSIX `sys/socket.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_socket.h.html +/// [Linux `getsockopt`]: https://man7.org/linux/man-pages/man2/getsockopt.2.html +/// [Linux `socket`]: https://man7.org/linux/man-pages/man7/socket.7.html +/// [Winsock2 `getsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-getsockopt +/// [Winsock2 `SOL_SOCKET` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/sol-socket-socket-options +/// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/getsockopt.2.html +/// [FreeBSD]: https://man.freebsd.org/cgi/man.cgi?query=getsockopt&sektion=2 +/// [NetBSD]: https://man.netbsd.org/getsockopt.2 +/// [OpenBSD]: https://man.openbsd.org/getsockopt.2 +/// [DragonFly BSD]: https://man.dragonflybsd.org/?command=getsockopt§ion=2 +/// [illumos]: https://illumos.org/man/3SOCKET/getsockopt +/// [glibc `getsockopt`]: https://www.gnu.org/software/libc/manual/html_node/Socket-Option-Functions.html +/// [glibc `SOL_SOCKET` options]: https://www.gnu.org/software/libc/manual/html_node/Socket_002dLevel-Options.html +#[inline] +#[doc(alias = "SO_REUSEADDR")] +pub fn get_socket_reuseaddr<Fd: AsFd>(fd: Fd) -> io::Result<bool> { + backend::net::syscalls::sockopt::get_socket_reuseaddr(fd.as_fd()) +} + /// `setsockopt(fd, SOL_SOCKET, SO_BROADCAST, broadcast)` /// /// # References @@ -712,6 +762,92 @@ pub fn get_socket_send_buffer_size<Fd: AsFd>(fd: Fd) -> io::Result<usize> { backend::net::syscalls::sockopt::get_socket_send_buffer_size(fd.as_fd()) } +/// `getsockopt(fd, SOL_SOCKET, SO_DOMAIN)` +/// +/// # References +/// - [POSIX `getsockopt`] +/// - [POSIX `sys/socket.h`] +/// - [Linux `getsockopt`] +/// - [Linux `socket`] +/// - [Winsock2 `getsockopt`] +/// - [Winsock2 `SOL_SOCKET` options] +/// - [Apple] +/// - [FreeBSD] +/// - [NetBSD] +/// - [OpenBSD] +/// - [DragonFly BSD] +/// - [illumos] +/// - [glibc `getsockopt`] +/// - [glibc `SOL_SOCKET` Options] +/// +/// [POSIX `getsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html +/// [POSIX `sys/socket.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_socket.h.html +/// [Linux `getsockopt`]: https://man7.org/linux/man-pages/man2/getsockopt.2.html +/// [Linux `socket`]: https://man7.org/linux/man-pages/man7/socket.7.html +/// [Winsock2 `getsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-getsockopt +/// [Winsock2 `SOL_SOCKET` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/sol-socket-socket-options +/// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/getsockopt.2.html +/// [FreeBSD]: https://man.freebsd.org/cgi/man.cgi?query=getsockopt&sektion=2 +/// [NetBSD]: https://man.netbsd.org/getsockopt.2 +/// [OpenBSD]: https://man.openbsd.org/getsockopt.2 +/// [DragonFly BSD]: https://man.dragonflybsd.org/?command=getsockopt§ion=2 +/// [illumos]: https://illumos.org/man/3SOCKET/getsockopt +/// [glibc `getsockopt`]: https://www.gnu.org/software/libc/manual/html_node/Socket-Option-Functions.html +/// [glibc `SOL_SOCKET` options]: https://www.gnu.org/software/libc/manual/html_node/Socket_002dLevel-Options.html +#[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", +)))] +#[inline] +#[doc(alias = "SO_DOMAIN")] +pub fn get_socket_domain<Fd: AsFd>(fd: Fd) -> io::Result<AddressFamily> { + backend::net::syscalls::sockopt::get_socket_domain(fd.as_fd()) +} + +/// `getsockopt(fd, SOL_SOCKET, SO_ACCEPTCONN)` +/// +/// # References +/// - [POSIX `getsockopt`] +/// - [POSIX `sys/socket.h`] +/// - [Linux `getsockopt`] +/// - [Linux `socket`] +/// - [Winsock2 `getsockopt`] +/// - [Winsock2 `SOL_SOCKET` options] +/// - [FreeBSD] +/// - [NetBSD] +/// - [OpenBSD] +/// - [DragonFly BSD] +/// - [illumos] +/// - [glibc `getsockopt`] +/// - [glibc `SOL_SOCKET` Options] +/// +/// [POSIX `getsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html +/// [POSIX `sys/socket.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_socket.h.html +/// [Linux `getsockopt`]: https://man7.org/linux/man-pages/man2/getsockopt.2.html +/// [Linux `socket`]: https://man7.org/linux/man-pages/man7/socket.7.html +/// [Winsock2 `getsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-getsockopt +/// [Winsock2 `SOL_SOCKET` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/sol-socket-socket-options +/// [FreeBSD]: https://man.freebsd.org/cgi/man.cgi?query=getsockopt&sektion=2 +/// [NetBSD]: https://man.netbsd.org/getsockopt.2 +/// [OpenBSD]: https://man.openbsd.org/getsockopt.2 +/// [DragonFly BSD]: https://man.dragonflybsd.org/?command=getsockopt§ion=2 +/// [illumos]: https://illumos.org/man/3SOCKET/getsockopt +/// [glibc `getsockopt`]: https://www.gnu.org/software/libc/manual/html_node/Socket-Option-Functions.html +/// [glibc `SOL_SOCKET` options]: https://www.gnu.org/software/libc/manual/html_node/Socket_002dLevel-Options.html +#[cfg(not(apple))] // Apple platforms declare the constant, but do not actually implement it. +#[inline] +#[doc(alias = "SO_ACCEPTCONN")] +pub fn get_socket_acceptconn<Fd: AsFd>(fd: Fd) -> io::Result<bool> { + backend::net::syscalls::sockopt::get_socket_acceptconn(fd.as_fd()) +} + /// `setsockopt(fd, IPPROTO_IP, IP_TTL, ttl)` /// /// # References @@ -1629,6 +1765,268 @@ pub fn get_tcp_nodelay<Fd: AsFd>(fd: Fd) -> io::Result<bool> { backend::net::syscalls::sockopt::get_tcp_nodelay(fd.as_fd()) } +/// `setsockopt(fd, IPPROTO_TCP, TCP_KEEPCNT, count)` +/// +/// # References +/// - [POSIX `getsockopt`] +/// - [POSIX `netinet/tcp.h`] +/// - [Linux `getsockopt`] +/// - [Linux `tcp`] +/// - [Winsock2 `getsockopt`] +/// - [Winsock2 `IPPROTO_TCP` options] +/// - [Apple `getsockopt`] +/// - [Apple `tcp`] +/// - [FreeBSD `getsockopt`] +/// - [FreeBSD `tcp`] +/// - [NetBSD `getsockopt`] +/// - [NetBSD `tcp`] +/// - [DragonFly BSD `getsockopt`] +/// - [DragonFly BSD `tcp`] +/// - [illumos `getsockopt`] +/// - [illumos `tcp`] +/// +/// [POSIX `getsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html +/// [POSIX `netinet/tcp.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_tcp.h.html +/// [Linux `getsockopt`]: https://man7.org/linux/man-pages/man2/getsockopt.2.html +/// [Linux `tcp`]: https://man7.org/linux/man-pages/man7/tcp.7.html +/// [Winsock2 `getsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-getsockopt +/// [Winsock2 `IPPROTO_TCP` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-tcp-socket-options +/// [Apple `getsockopt`]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/getsockopt.2.html +/// [Apple `tcp`]: https://opensource.apple.com/source/xnu/xnu-7195.81.3/bsd/man/man4/tcp.4.auto.html +/// [FreeBSD `getsockopt`]: https://man.freebsd.org/cgi/man.cgi?query=getsockopt&sektion=2 +/// [FreeBSD `tcp`]: https://man.freebsd.org/cgi/man.cgi?query=tcp&sektion=4 +/// [NetBSD `getsockopt`]: https://man.netbsd.org/getsockopt.2 +/// [NetBSD `tcp`]: https://man.netbsd.org/tcp.4 +/// [DragonFly BSD `getsockopt`]: https://man.dragonflybsd.org/?command=getsockopt§ion=2 +/// [DragonFly BSD `tcp`]: https://man.dragonflybsd.org/?command=tcp§ion=4 +/// [illumos `getsockopt`]: https://illumos.org/man/3SOCKET/getsockopt +/// [illumos `tcp`]: https://illumos.org/man/4P/tcp +#[inline] +#[cfg(not(any(target_os = "openbsd", target_os = "haiku", target_os = "nto")))] +#[doc(alias = "TCP_KEEPCNT")] +pub fn set_tcp_keepcnt<Fd: AsFd>(fd: Fd, count: u32) -> io::Result<()> { + backend::net::syscalls::sockopt::set_tcp_keepcnt(fd.as_fd(), count) +} + +/// `getsockopt(fd, IPPROTO_TCP, TCP_KEEPCNT)` +/// +/// # References +/// - [POSIX `getsockopt`] +/// - [POSIX `netinet/tcp.h`] +/// - [Linux `getsockopt`] +/// - [Linux `tcp`] +/// - [Winsock2 `getsockopt`] +/// - [Winsock2 `IPPROTO_TCP` options] +/// - [Apple `getsockopt`] +/// - [Apple `tcp`] +/// - [FreeBSD `getsockopt`] +/// - [FreeBSD `tcp`] +/// - [NetBSD `getsockopt`] +/// - [NetBSD `tcp`] +/// - [DragonFly BSD `getsockopt`] +/// - [DragonFly BSD `tcp`] +/// - [illumos `getsockopt`] +/// - [illumos `tcp`] +/// +/// [POSIX `getsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html +/// [POSIX `netinet/tcp.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_tcp.h.html +/// [Linux `getsockopt`]: https://man7.org/linux/man-pages/man2/getsockopt.2.html +/// [Linux `tcp`]: https://man7.org/linux/man-pages/man7/tcp.7.html +/// [Winsock2 `getsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-getsockopt +/// [Winsock2 `IPPROTO_TCP` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-tcp-socket-options +/// [Apple `getsockopt`]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/getsockopt.2.html +/// [Apple `tcp`]: https://opensource.apple.com/source/xnu/xnu-7195.81.3/bsd/man/man4/tcp.4.auto.html +/// [FreeBSD `getsockopt`]: https://man.freebsd.org/cgi/man.cgi?query=getsockopt&sektion=2 +/// [FreeBSD `tcp`]: https://man.freebsd.org/cgi/man.cgi?query=tcp&sektion=4 +/// [NetBSD `getsockopt`]: https://man.netbsd.org/getsockopt.2 +/// [NetBSD `tcp`]: https://man.netbsd.org/tcp.4 +/// [DragonFly BSD `getsockopt`]: https://man.dragonflybsd.org/?command=getsockopt§ion=2 +/// [DragonFly BSD `tcp`]: https://man.dragonflybsd.org/?command=tcp§ion=4 +/// [illumos `getsockopt`]: https://illumos.org/man/3SOCKET/getsockopt +/// [illumos `tcp`]: https://illumos.org/man/4P/tcp +#[inline] +#[cfg(not(any(target_os = "openbsd", target_os = "haiku", target_os = "nto")))] +#[doc(alias = "TCP_KEEPCNT")] +pub fn get_tcp_keepcnt<Fd: AsFd>(fd: Fd) -> io::Result<u32> { + backend::net::syscalls::sockopt::get_tcp_keepcnt(fd.as_fd()) +} + +/// `setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, duration)` +/// +/// `TCP_KEEPALIVE` on Apple platforms. +/// +/// # References +/// - [POSIX `getsockopt`] +/// - [POSIX `netinet/tcp.h`] +/// - [Linux `getsockopt`] +/// - [Linux `tcp`] +/// - [Winsock2 `getsockopt`] +/// - [Winsock2 `IPPROTO_TCP` options] +/// - [Apple `getsockopt`] +/// - [Apple `tcp`] +/// - [FreeBSD `getsockopt`] +/// - [FreeBSD `tcp`] +/// - [NetBSD `getsockopt`] +/// - [NetBSD `tcp`] +/// - [DragonFly BSD `getsockopt`] +/// - [DragonFly BSD `tcp`] +/// - [illumos `getsockopt`] +/// - [illumos `tcp`] +/// +/// [POSIX `getsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html +/// [POSIX `netinet/tcp.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_tcp.h.html +/// [Linux `getsockopt`]: https://man7.org/linux/man-pages/man2/getsockopt.2.html +/// [Linux `tcp`]: https://man7.org/linux/man-pages/man7/tcp.7.html +/// [Winsock2 `getsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-getsockopt +/// [Winsock2 `IPPROTO_TCP` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-tcp-socket-options +/// [Apple `getsockopt`]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/getsockopt.2.html +/// [Apple `tcp`]: https://opensource.apple.com/source/xnu/xnu-7195.81.3/bsd/man/man4/tcp.4.auto.html +/// [FreeBSD `getsockopt`]: https://man.freebsd.org/cgi/man.cgi?query=getsockopt&sektion=2 +/// [FreeBSD `tcp`]: https://man.freebsd.org/cgi/man.cgi?query=tcp&sektion=4 +/// [NetBSD `getsockopt`]: https://man.netbsd.org/getsockopt.2 +/// [NetBSD `tcp`]: https://man.netbsd.org/tcp.4 +/// [DragonFly BSD `getsockopt`]: https://man.dragonflybsd.org/?command=getsockopt§ion=2 +/// [DragonFly BSD `tcp`]: https://man.dragonflybsd.org/?command=tcp§ion=4 +/// [illumos `getsockopt`]: https://illumos.org/man/3SOCKET/getsockopt +/// [illumos `tcp`]: https://illumos.org/man/4P/tcp +#[inline] +#[cfg(not(any(target_os = "openbsd", target_os = "haiku", target_os = "nto")))] +#[doc(alias = "TCP_KEEPIDLE")] +pub fn set_tcp_keepidle<Fd: AsFd>(fd: Fd, duration: Duration) -> io::Result<()> { + backend::net::syscalls::sockopt::set_tcp_keepidle(fd.as_fd(), duration) +} + +/// `getsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE)` +/// +/// `TCP_KEEPALIVE` on Apple platforms. +/// +/// # References +/// - [POSIX `getsockopt`] +/// - [POSIX `netinet/tcp.h`] +/// - [Linux `getsockopt`] +/// - [Linux `tcp`] +/// - [Winsock2 `getsockopt`] +/// - [Winsock2 `IPPROTO_TCP` options] +/// - [Apple `getsockopt`] +/// - [Apple `tcp`] +/// - [FreeBSD `getsockopt`] +/// - [FreeBSD `tcp`] +/// - [NetBSD `getsockopt`] +/// - [NetBSD `tcp`] +/// - [DragonFly BSD `getsockopt`] +/// - [DragonFly BSD `tcp`] +/// - [illumos `getsockopt`] +/// - [illumos `tcp`] +/// +/// [POSIX `getsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html +/// [POSIX `netinet/tcp.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_tcp.h.html +/// [Linux `getsockopt`]: https://man7.org/linux/man-pages/man2/getsockopt.2.html +/// [Linux `tcp`]: https://man7.org/linux/man-pages/man7/tcp.7.html +/// [Winsock2 `getsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-getsockopt +/// [Winsock2 `IPPROTO_TCP` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-tcp-socket-options +/// [Apple `getsockopt`]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/getsockopt.2.html +/// [Apple `tcp`]: https://opensource.apple.com/source/xnu/xnu-7195.81.3/bsd/man/man4/tcp.4.auto.html +/// [FreeBSD `getsockopt`]: https://man.freebsd.org/cgi/man.cgi?query=getsockopt&sektion=2 +/// [FreeBSD `tcp`]: https://man.freebsd.org/cgi/man.cgi?query=tcp&sektion=4 +/// [NetBSD `getsockopt`]: https://man.netbsd.org/getsockopt.2 +/// [NetBSD `tcp`]: https://man.netbsd.org/tcp.4 +/// [DragonFly BSD `getsockopt`]: https://man.dragonflybsd.org/?command=getsockopt§ion=2 +/// [DragonFly BSD `tcp`]: https://man.dragonflybsd.org/?command=tcp§ion=4 +/// [illumos `getsockopt`]: https://illumos.org/man/3SOCKET/getsockopt +/// [illumos `tcp`]: https://illumos.org/man/4P/tcp +#[inline] +#[cfg(not(any(target_os = "openbsd", target_os = "haiku", target_os = "nto")))] +#[doc(alias = "TCP_KEEPIDLE")] +pub fn get_tcp_keepidle<Fd: AsFd>(fd: Fd) -> io::Result<Duration> { + backend::net::syscalls::sockopt::get_tcp_keepidle(fd.as_fd()) +} + +/// `setsockopt(fd, IPPROTO_TCP, TCP_KEEPINTVL, duration)` +/// +/// # References +/// - [POSIX `getsockopt`] +/// - [POSIX `netinet/tcp.h`] +/// - [Linux `getsockopt`] +/// - [Linux `tcp`] +/// - [Winsock2 `getsockopt`] +/// - [Winsock2 `IPPROTO_TCP` options] +/// - [Apple `getsockopt`] +/// - [Apple `tcp`] +/// - [FreeBSD `getsockopt`] +/// - [FreeBSD `tcp`] +/// - [NetBSD `getsockopt`] +/// - [NetBSD `tcp`] +/// - [DragonFly BSD `getsockopt`] +/// - [DragonFly BSD `tcp`] +/// - [illumos `getsockopt`] +/// - [illumos `tcp`] +/// +/// [POSIX `getsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html +/// [POSIX `netinet/tcp.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_tcp.h.html +/// [Linux `getsockopt`]: https://man7.org/linux/man-pages/man2/getsockopt.2.html +/// [Linux `tcp`]: https://man7.org/linux/man-pages/man7/tcp.7.html +/// [Winsock2 `getsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-getsockopt +/// [Winsock2 `IPPROTO_TCP` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-tcp-socket-options +/// [Apple `getsockopt`]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/getsockopt.2.html +/// [Apple `tcp`]: https://opensource.apple.com/source/xnu/xnu-7195.81.3/bsd/man/man4/tcp.4.auto.html +/// [FreeBSD `getsockopt`]: https://man.freebsd.org/cgi/man.cgi?query=getsockopt&sektion=2 +/// [FreeBSD `tcp`]: https://man.freebsd.org/cgi/man.cgi?query=tcp&sektion=4 +/// [NetBSD `getsockopt`]: https://man.netbsd.org/getsockopt.2 +/// [NetBSD `tcp`]: https://man.netbsd.org/tcp.4 +/// [DragonFly BSD `getsockopt`]: https://man.dragonflybsd.org/?command=getsockopt§ion=2 +/// [DragonFly BSD `tcp`]: https://man.dragonflybsd.org/?command=tcp§ion=4 +/// [illumos `getsockopt`]: https://illumos.org/man/3SOCKET/getsockopt +/// [illumos `tcp`]: https://illumos.org/man/4P/tcp +#[inline] +#[cfg(not(any(target_os = "openbsd", target_os = "haiku", target_os = "nto")))] +#[doc(alias = "TCP_KEEPINTVL")] +pub fn set_tcp_keepintvl<Fd: AsFd>(fd: Fd, duration: Duration) -> io::Result<()> { + backend::net::syscalls::sockopt::set_tcp_keepintvl(fd.as_fd(), duration) +} + +/// `getsockopt(fd, IPPROTO_TCP, TCP_KEEPINTVL)` +/// +/// # References +/// - [POSIX `getsockopt`] +/// - [POSIX `netinet/tcp.h`] +/// - [Linux `getsockopt`] +/// - [Linux `tcp`] +/// - [Winsock2 `getsockopt`] +/// - [Winsock2 `IPPROTO_TCP` options] +/// - [Apple `getsockopt`] +/// - [Apple `tcp`] +/// - [FreeBSD `getsockopt`] +/// - [FreeBSD `tcp`] +/// - [NetBSD `getsockopt`] +/// - [NetBSD `tcp`] +/// - [DragonFly BSD `getsockopt`] +/// - [DragonFly BSD `tcp`] +/// - [illumos `getsockopt`] +/// - [illumos `tcp`] +/// +/// [POSIX `getsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html +/// [POSIX `netinet/tcp.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_tcp.h.html +/// [Linux `getsockopt`]: https://man7.org/linux/man-pages/man2/getsockopt.2.html +/// [Linux `tcp`]: https://man7.org/linux/man-pages/man7/tcp.7.html +/// [Winsock2 `getsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-getsockopt +/// [Winsock2 `IPPROTO_TCP` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-tcp-socket-options +/// [Apple `getsockopt`]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/getsockopt.2.html +/// [Apple `tcp`]: https://opensource.apple.com/source/xnu/xnu-7195.81.3/bsd/man/man4/tcp.4.auto.html +/// [FreeBSD `getsockopt`]: https://man.freebsd.org/cgi/man.cgi?query=getsockopt&sektion=2 +/// [FreeBSD `tcp`]: https://man.freebsd.org/cgi/man.cgi?query=tcp&sektion=4 +/// [NetBSD `getsockopt`]: https://man.netbsd.org/getsockopt.2 +/// [NetBSD `tcp`]: https://man.netbsd.org/tcp.4 +/// [DragonFly BSD `getsockopt`]: https://man.dragonflybsd.org/?command=getsockopt§ion=2 +/// [DragonFly BSD `tcp`]: https://man.dragonflybsd.org/?command=tcp§ion=4 +/// [illumos `getsockopt`]: https://illumos.org/man/3SOCKET/getsockopt +/// [illumos `tcp`]: https://illumos.org/man/4P/tcp +#[inline] +#[cfg(not(any(target_os = "openbsd", target_os = "haiku", target_os = "nto")))] +#[doc(alias = "TCP_KEEPINTVL")] +pub fn get_tcp_keepintvl<Fd: AsFd>(fd: Fd) -> io::Result<Duration> { + backend::net::syscalls::sockopt::get_tcp_keepintvl(fd.as_fd()) +} + #[test] fn test_sizes() { use c::c_int; diff --git a/vendor/rustix/src/net/types.rs b/vendor/rustix/src/net/types.rs index a2c019b42..53116f9c8 100644 --- a/vendor/rustix/src/net/types.rs +++ b/vendor/rustix/src/net/types.rs @@ -1,10 +1,9 @@ -#![allow(unsafe_code)] +//! Types and constants for `rustix::net`. use crate::backend::c; use bitflags::bitflags; /// A type for holding raw integer socket types. -#[doc(hidden)] pub type RawSocketType = u32; /// `SOCK_*` constants for use with [`socket`]. @@ -48,10 +47,14 @@ impl SocketType { } /// A type for holding raw integer address families. -#[doc(hidden)] pub type RawAddressFamily = c::sa_family_t; -/// `AF_*` constants. +/// `AF_*` constants for use with [`socket`], [`socket_with`], and +/// [`socketpair`]. +/// +/// [`socket`]: crate::net::socket() +/// [`socket_with`]: crate::net::socket_with +/// [`socketpair`]: crate::net::socketpair() #[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)] #[repr(transparent)] pub struct AddressFamily(pub(crate) RawAddressFamily); @@ -85,6 +88,7 @@ impl AddressFamily { bsd, solarish, windows, + target_os = "aix", target_os = "espidf", target_os = "haiku", target_os = "nto", @@ -98,13 +102,17 @@ impl AddressFamily { bsd, solarish, windows, + target_os = "aix", target_os = "espidf", target_os = "haiku", target_os = "nto", )))] pub const AX25: Self = Self(c::AF_AX25 as _); /// `AF_IPX` - #[cfg(not(target_os = "espidf"))] + #[cfg(not(any( + target_os = "espidf", + target_os = "aix", + )))] pub const IPX: Self = Self(c::AF_IPX as _); /// `AF_APPLETALK` #[cfg(not(target_os = "espidf"))] @@ -114,6 +122,7 @@ impl AddressFamily { bsd, solarish, windows, + target_os = "aix", target_os = "espidf", target_os = "haiku", target_os = "nto", @@ -124,6 +133,7 @@ impl AddressFamily { bsd, solarish, windows, + target_os = "aix", target_os = "espidf", target_os = "haiku", target_os = "nto", @@ -134,6 +144,7 @@ impl AddressFamily { bsd, solarish, windows, + target_os = "aix", target_os = "espidf", target_os = "haiku", target_os = "nto", @@ -143,6 +154,7 @@ impl AddressFamily { #[cfg(not(any( bsd, windows, + target_os = "aix", target_os = "espidf", target_os = "haiku", target_os = "nto", @@ -153,6 +165,7 @@ impl AddressFamily { bsd, solarish, windows, + target_os = "aix", target_os = "espidf", target_os = "haiku", target_os = "nto", @@ -166,6 +179,7 @@ impl AddressFamily { bsd, solarish, windows, + target_os = "aix", target_os = "espidf", target_os = "haiku", target_os = "nto", @@ -176,6 +190,7 @@ impl AddressFamily { bsd, solarish, windows, + target_os = "aix", target_os = "espidf", target_os = "haiku", target_os = "nto", @@ -185,6 +200,7 @@ impl AddressFamily { #[cfg(not(any( bsd, windows, + target_os = "aix", target_os = "espidf", target_os = "haiku", target_os = "nto", @@ -199,6 +215,7 @@ impl AddressFamily { #[cfg(not(any( bsd, windows, + target_os = "aix", target_os = "espidf", target_os = "haiku", target_os = "nto", @@ -209,6 +226,7 @@ impl AddressFamily { bsd, solarish, windows, + target_os = "aix", target_os = "espidf", target_os = "haiku", target_os = "nto", @@ -219,6 +237,7 @@ impl AddressFamily { bsd, solarish, windows, + target_os = "aix", target_os = "espidf", target_os = "haiku", target_os = "nto", @@ -229,6 +248,7 @@ impl AddressFamily { bsd, solarish, windows, + target_os = "aix", target_os = "espidf", target_os = "haiku", target_os = "nto", @@ -239,6 +259,7 @@ impl AddressFamily { bsd, solarish, windows, + target_os = "aix", target_os = "espidf", target_os = "haiku", target_os = "nto", @@ -251,6 +272,7 @@ impl AddressFamily { #[cfg(not(any( bsd, solarish, + target_os = "aix", target_os = "espidf", target_os = "haiku", target_os = "nto", @@ -261,6 +283,7 @@ impl AddressFamily { bsd, solarish, windows, + target_os = "aix", target_os = "espidf", target_os = "haiku", target_os = "nto", @@ -271,6 +294,7 @@ impl AddressFamily { bsd, solarish, windows, + target_os = "aix", target_os = "espidf", target_os = "haiku", target_os = "nto", @@ -281,6 +305,7 @@ impl AddressFamily { bsd, solarish, windows, + target_os = "aix", target_os = "espidf", target_os = "haiku", target_os = "nto", @@ -291,6 +316,7 @@ impl AddressFamily { bsd, solarish, windows, + target_os = "aix", target_os = "espidf", target_os = "haiku", target_os = "nto", @@ -301,19 +327,27 @@ impl AddressFamily { bsd, solarish, windows, + target_os = "aix", target_os = "espidf", target_os = "haiku", target_os = "nto", )))] pub const TIPC: Self = Self(c::AF_TIPC as _); /// `AF_BLUETOOTH` - #[cfg(not(any(apple, solarish, windows, target_os = "espidf")))] + #[cfg(not(any( + apple, + solarish, + windows, + target_os = "aix", + target_os = "espidf", + )))] pub const BLUETOOTH: Self = Self(c::AF_BLUETOOTH as _); /// `AF_IUCV` #[cfg(not(any( bsd, solarish, windows, + target_os = "aix", target_os = "espidf", target_os = "haiku", target_os = "nto", @@ -324,19 +358,27 @@ impl AddressFamily { bsd, solarish, windows, + target_os = "aix", target_os = "espidf", target_os = "haiku", target_os = "nto", )))] pub const RXRPC: Self = Self(c::AF_RXRPC as _); /// `AF_ISDN` - #[cfg(not(any(solarish, windows, target_os = "espidf", target_os = "haiku")))] + #[cfg(not(any( + solarish, + windows, + target_os = "aix", + target_os = "espidf", + target_os = "haiku", + )))] pub const ISDN: Self = Self(c::AF_ISDN as _); /// `AF_PHONET` #[cfg(not(any( bsd, solarish, windows, + target_os = "aix", target_os = "espidf", target_os = "haiku", target_os = "nto", @@ -347,6 +389,7 @@ impl AddressFamily { bsd, solarish, windows, + target_os = "aix", target_os = "espidf", target_os = "haiku", target_os = "nto", @@ -410,7 +453,7 @@ impl AddressFamily { #[cfg(any(bsd, solarish, target_os = "aix", target_os = "nto"))] pub const IMPLINK: Self = Self(c::AF_IMPLINK as _); /// `AF_IEEE80211` - #[cfg(any(apple, freebsdlike, linuxlike, target_os = "netbsd"))] + #[cfg(any(apple, freebsdlike, target_os = "netbsd"))] pub const IEEE80211: Self = Self(c::AF_IEEE80211 as _); /// `AF_INET6_SDP` #[cfg(target_os = "freebsd")] @@ -437,7 +480,7 @@ impl AddressFamily { #[cfg(any(netbsdlike, target_os = "dragonfly", target_os = "emscripten", target_os = "fuchsia"))] pub const MPLS: Self = Self(c::AF_MPLS as _); /// `AF_NATM` - #[cfg(any(bsd, target_os = "aix", target_os = "nto"))] + #[cfg(any(bsd, target_os = "nto"))] pub const NATM: Self = Self(c::AF_NATM as _); /// `AF_NBS` #[cfg(solarish)] @@ -497,7 +540,7 @@ impl AddressFamily { #[cfg(target_os = "freebsd")] pub const SCLUSTER: Self = Self(c::AF_SCLUSTER as _); /// `AF_SIP` - #[cfg(any(apple, target_os = "freebsd", target_os = "opensbd"))] + #[cfg(any(apple, target_os = "freebsd", target_os = "openbsd"))] pub const SIP: Self = Self(c::AF_SIP as _); /// `AF_SLOW` #[cfg(target_os = "freebsd")] @@ -532,9 +575,15 @@ impl AddressFamily { } /// A type for holding raw integer protocols. -#[doc(hidden)] pub type RawProtocol = core::num::NonZeroU32; +const fn new_raw_protocol(u: u32) -> RawProtocol { + match RawProtocol::new(u) { + Some(p) => p, + None => panic!("new_raw_protocol: protocol must be non-zero"), + } +} + /// `IPPROTO_*` and other constants for use with [`socket`], [`socket_with`], /// and [`socketpair`] when a nondefault value is desired. See the [`ipproto`], /// [`sysproto`], and [`netlink`] modules for possible values. @@ -555,104 +604,105 @@ pub struct Protocol(pub(crate) RawProtocol); /// /// For `IPPROTO_IP`, pass `None` as the `protocol` argument. pub mod ipproto { - use super::{Protocol, RawProtocol}; + use super::{new_raw_protocol, Protocol}; use crate::backend::c; /// `IPPROTO_ICMP` - pub const ICMP: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_ICMP as _) }); + pub const ICMP: Protocol = Protocol(new_raw_protocol(c::IPPROTO_ICMP as _)); /// `IPPROTO_IGMP` #[cfg(not(any(solarish, target_os = "espidf", target_os = "haiku")))] - pub const IGMP: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_IGMP as _) }); + pub const IGMP: Protocol = Protocol(new_raw_protocol(c::IPPROTO_IGMP as _)); /// `IPPROTO_IPIP` #[cfg(not(any(solarish, windows, target_os = "espidf", target_os = "haiku")))] - pub const IPIP: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_IPIP as _) }); + pub const IPIP: Protocol = Protocol(new_raw_protocol(c::IPPROTO_IPIP as _)); /// `IPPROTO_TCP` - pub const TCP: Protocol = Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_TCP as _) }); + pub const TCP: Protocol = Protocol(new_raw_protocol(c::IPPROTO_TCP as _)); /// `IPPROTO_EGP` #[cfg(not(any(solarish, target_os = "espidf", target_os = "haiku")))] - pub const EGP: Protocol = Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_EGP as _) }); + pub const EGP: Protocol = Protocol(new_raw_protocol(c::IPPROTO_EGP as _)); /// `IPPROTO_PUP` #[cfg(not(any(solarish, target_os = "espidf", target_os = "haiku")))] - pub const PUP: Protocol = Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_PUP as _) }); + pub const PUP: Protocol = Protocol(new_raw_protocol(c::IPPROTO_PUP as _)); /// `IPPROTO_UDP` - pub const UDP: Protocol = Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_UDP as _) }); + pub const UDP: Protocol = Protocol(new_raw_protocol(c::IPPROTO_UDP as _)); /// `IPPROTO_IDP` #[cfg(not(any(solarish, target_os = "espidf", target_os = "haiku")))] - pub const IDP: Protocol = Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_IDP as _) }); + pub const IDP: Protocol = Protocol(new_raw_protocol(c::IPPROTO_IDP as _)); /// `IPPROTO_TP` #[cfg(not(any(solarish, windows, target_os = "espidf", target_os = "haiku")))] - pub const TP: Protocol = Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_TP as _) }); + pub const TP: Protocol = Protocol(new_raw_protocol(c::IPPROTO_TP as _)); /// `IPPROTO_DCCP` #[cfg(not(any( apple, solarish, windows, + target_os = "aix", target_os = "dragonfly", target_os = "espidf", target_os = "haiku", target_os = "nto", target_os = "openbsd", )))] - pub const DCCP: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_DCCP as _) }); + pub const DCCP: Protocol = Protocol(new_raw_protocol(c::IPPROTO_DCCP as _)); /// `IPPROTO_IPV6` - pub const IPV6: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_IPV6 as _) }); + pub const IPV6: Protocol = Protocol(new_raw_protocol(c::IPPROTO_IPV6 as _)); /// `IPPROTO_RSVP` #[cfg(not(any(solarish, windows, target_os = "espidf", target_os = "haiku")))] - pub const RSVP: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_RSVP as _) }); + pub const RSVP: Protocol = Protocol(new_raw_protocol(c::IPPROTO_RSVP as _)); /// `IPPROTO_GRE` #[cfg(not(any(solarish, windows, target_os = "espidf", target_os = "haiku")))] - pub const GRE: Protocol = Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_GRE as _) }); + pub const GRE: Protocol = Protocol(new_raw_protocol(c::IPPROTO_GRE as _)); /// `IPPROTO_ESP` #[cfg(not(any(solarish, target_os = "espidf", target_os = "haiku")))] - pub const ESP: Protocol = Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_ESP as _) }); + pub const ESP: Protocol = Protocol(new_raw_protocol(c::IPPROTO_ESP as _)); /// `IPPROTO_AH` #[cfg(not(any(solarish, target_os = "espidf", target_os = "haiku")))] - pub const AH: Protocol = Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_AH as _) }); + pub const AH: Protocol = Protocol(new_raw_protocol(c::IPPROTO_AH as _)); /// `IPPROTO_MTP` #[cfg(not(any( solarish, netbsdlike, windows, + target_os = "aix", target_os = "espidf", target_os = "haiku", target_os = "nto", )))] - pub const MTP: Protocol = Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_MTP as _) }); + pub const MTP: Protocol = Protocol(new_raw_protocol(c::IPPROTO_MTP as _)); /// `IPPROTO_BEETPH` #[cfg(not(any( bsd, solarish, windows, + target_os = "aix", target_os = "espidf", target_os = "haiku", target_os = "nto" )))] - pub const BEETPH: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_BEETPH as _) }); + pub const BEETPH: Protocol = Protocol(new_raw_protocol(c::IPPROTO_BEETPH as _)); /// `IPPROTO_ENCAP` - #[cfg(not(any(solarish, windows, target_os = "espidf", target_os = "haiku")))] - pub const ENCAP: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_ENCAP as _) }); + #[cfg(not(any( + solarish, + windows, + target_os = "aix", + target_os = "espidf", + target_os = "haiku", + )))] + pub const ENCAP: Protocol = Protocol(new_raw_protocol(c::IPPROTO_ENCAP as _)); /// `IPPROTO_PIM` - #[cfg(not(any(solarish, target_os = "espidf", target_os = "haiku")))] - pub const PIM: Protocol = Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_PIM as _) }); + #[cfg(not(any(solarish, target_os = "aix", target_os = "espidf", target_os = "haiku")))] + pub const PIM: Protocol = Protocol(new_raw_protocol(c::IPPROTO_PIM as _)); /// `IPPROTO_COMP` #[cfg(not(any( bsd, solarish, windows, + target_os = "aix", target_os = "espidf", target_os = "haiku", target_os = "nto" )))] - pub const COMP: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_COMP as _) }); + pub const COMP: Protocol = Protocol(new_raw_protocol(c::IPPROTO_COMP as _)); /// `IPPROTO_SCTP` #[cfg(not(any( solarish, @@ -661,61 +711,57 @@ pub mod ipproto { target_os = "haiku", target_os = "openbsd" )))] - pub const SCTP: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_SCTP as _) }); + pub const SCTP: Protocol = Protocol(new_raw_protocol(c::IPPROTO_SCTP as _)); /// `IPPROTO_UDPLITE` #[cfg(not(any( apple, netbsdlike, solarish, windows, + target_os = "aix", target_os = "dragonfly", target_os = "espidf", target_os = "haiku", target_os = "nto", )))] - pub const UDPLITE: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_UDPLITE as _) }); + pub const UDPLITE: Protocol = Protocol(new_raw_protocol(c::IPPROTO_UDPLITE as _)); /// `IPPROTO_MPLS` #[cfg(not(any( apple, solarish, windows, + target_os = "aix", target_os = "dragonfly", target_os = "espidf", target_os = "haiku", target_os = "netbsd", target_os = "nto", )))] - pub const MPLS: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_MPLS as _) }); + pub const MPLS: Protocol = Protocol(new_raw_protocol(c::IPPROTO_MPLS as _)); /// `IPPROTO_ETHERNET` #[cfg(linux_kernel)] - pub const ETHERNET: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_ETHERNET as _) }); + pub const ETHERNET: Protocol = Protocol(new_raw_protocol(c::IPPROTO_ETHERNET as _)); /// `IPPROTO_RAW` #[cfg(not(target_os = "espidf"))] - pub const RAW: Protocol = Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_RAW as _) }); + pub const RAW: Protocol = Protocol(new_raw_protocol(c::IPPROTO_RAW as _)); /// `IPPROTO_MPTCP` #[cfg(not(any( bsd, solarish, windows, + target_os = "aix", target_os = "emscripten", target_os = "espidf", target_os = "fuchsia", target_os = "haiku", target_os = "nto", )))] - pub const MPTCP: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_MPTCP as _) }); + pub const MPTCP: Protocol = Protocol(new_raw_protocol(c::IPPROTO_MPTCP as _)); /// `IPPROTO_FRAGMENT` #[cfg(not(any(solarish, target_os = "espidf", target_os = "haiku")))] - pub const FRAGMENT: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_FRAGMENT as _) }); + pub const FRAGMENT: Protocol = Protocol(new_raw_protocol(c::IPPROTO_FRAGMENT as _)); /// `IPPROTO_ICMPV6` - pub const ICMPV6: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_ICMPV6 as _) }); + pub const ICMPV6: Protocol = Protocol(new_raw_protocol(c::IPPROTO_ICMPV6 as _)); /// `IPPROTO_MH` #[cfg(not(any( apple, @@ -727,30 +773,27 @@ pub mod ipproto { target_os = "haiku", target_os = "nto", )))] - pub const MH: Protocol = Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_MH as _) }); + pub const MH: Protocol = Protocol(new_raw_protocol(c::IPPROTO_MH as _)); /// `IPPROTO_ROUTING` #[cfg(not(any(solarish, target_os = "espidf", target_os = "haiku")))] - pub const ROUTING: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_ROUTING as _) }); + pub const ROUTING: Protocol = Protocol(new_raw_protocol(c::IPPROTO_ROUTING as _)); } /// `SYSPROTO_*` constants. pub mod sysproto { #[cfg(apple)] use { - super::{Protocol, RawProtocol}, + super::{new_raw_protocol, Protocol}, crate::backend::c, }; /// `SYSPROTO_EVENT` #[cfg(apple)] - pub const EVENT: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked(c::SYSPROTO_EVENT as _) }); + pub const EVENT: Protocol = Protocol(new_raw_protocol(c::SYSPROTO_EVENT as _)); /// `SYSPROTO_CONTROL` #[cfg(apple)] - pub const CONTROL: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked(c::SYSPROTO_CONTROL as _) }); + pub const CONTROL: Protocol = Protocol(new_raw_protocol(c::SYSPROTO_CONTROL as _)); } /// `NETLINK_*` constants. @@ -759,566 +802,478 @@ pub mod sysproto { pub mod netlink { #[cfg(linux_kernel)] use { - super::{Protocol, RawProtocol}, + super::{new_raw_protocol, Protocol}, crate::backend::c, }; /// `NETLINK_UNUSED` #[cfg(linux_kernel)] - pub const UNUSED: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_UNUSED as _) }); + pub const UNUSED: Protocol = Protocol(new_raw_protocol(c::NETLINK_UNUSED as _)); /// `NETLINK_USERSOCK` #[cfg(linux_kernel)] - pub const USERSOCK: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_USERSOCK as _) }); + pub const USERSOCK: Protocol = Protocol(new_raw_protocol(c::NETLINK_USERSOCK as _)); /// `NETLINK_FIREWALL` #[cfg(linux_kernel)] - pub const FIREWALL: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_FIREWALL as _) }); + pub const FIREWALL: Protocol = Protocol(new_raw_protocol(c::NETLINK_FIREWALL as _)); /// `NETLINK_SOCK_DIAG` #[cfg(linux_kernel)] - pub const SOCK_DIAG: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_SOCK_DIAG as _) }); + pub const SOCK_DIAG: Protocol = Protocol(new_raw_protocol(c::NETLINK_SOCK_DIAG as _)); /// `NETLINK_NFLOG` #[cfg(linux_kernel)] - pub const NFLOG: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_NFLOG as _) }); + pub const NFLOG: Protocol = Protocol(new_raw_protocol(c::NETLINK_NFLOG as _)); /// `NETLINK_XFRM` #[cfg(linux_kernel)] - pub const XFRM: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_XFRM as _) }); + pub const XFRM: Protocol = Protocol(new_raw_protocol(c::NETLINK_XFRM as _)); /// `NETLINK_SELINUX` #[cfg(linux_kernel)] - pub const SELINUX: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_SELINUX as _) }); + pub const SELINUX: Protocol = Protocol(new_raw_protocol(c::NETLINK_SELINUX as _)); /// `NETLINK_ISCSI` #[cfg(linux_kernel)] - pub const ISCSI: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_ISCSI as _) }); + pub const ISCSI: Protocol = Protocol(new_raw_protocol(c::NETLINK_ISCSI as _)); /// `NETLINK_AUDIT` #[cfg(linux_kernel)] - pub const AUDIT: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_AUDIT as _) }); + pub const AUDIT: Protocol = Protocol(new_raw_protocol(c::NETLINK_AUDIT as _)); /// `NETLINK_FIB_LOOKUP` #[cfg(linux_kernel)] - pub const FIB_LOOKUP: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_FIB_LOOKUP as _) }); + pub const FIB_LOOKUP: Protocol = Protocol(new_raw_protocol(c::NETLINK_FIB_LOOKUP as _)); /// `NETLINK_CONNECTOR` #[cfg(linux_kernel)] - pub const CONNECTOR: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_CONNECTOR as _) }); + pub const CONNECTOR: Protocol = Protocol(new_raw_protocol(c::NETLINK_CONNECTOR as _)); /// `NETLINK_NETFILTER` #[cfg(linux_kernel)] - pub const NETFILTER: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_NETFILTER as _) }); + pub const NETFILTER: Protocol = Protocol(new_raw_protocol(c::NETLINK_NETFILTER as _)); /// `NETLINK_IP6_FW` #[cfg(linux_kernel)] - pub const IP6_FW: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_IP6_FW as _) }); + pub const IP6_FW: Protocol = Protocol(new_raw_protocol(c::NETLINK_IP6_FW as _)); /// `NETLINK_DNRTMSG` #[cfg(linux_kernel)] - pub const DNRTMSG: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_DNRTMSG as _) }); + pub const DNRTMSG: Protocol = Protocol(new_raw_protocol(c::NETLINK_DNRTMSG as _)); /// `NETLINK_KOBJECT_UEVENT` #[cfg(linux_kernel)] - pub const KOBJECT_UEVENT: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_KOBJECT_UEVENT as _) }); + pub const KOBJECT_UEVENT: Protocol = Protocol(new_raw_protocol(c::NETLINK_KOBJECT_UEVENT as _)); /// `NETLINK_GENERIC` // This is defined on FreeBSD too, but it has the value 0, so it doesn't // fit in or `NonZeroU32`. It's unclear whether FreeBSD intends // `NETLINK_GENERIC` to be the default when Linux has `NETLINK_ROUTE` // as the default. #[cfg(linux_kernel)] - pub const GENERIC: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_GENERIC as _) }); + pub const GENERIC: Protocol = Protocol(new_raw_protocol(c::NETLINK_GENERIC as _)); /// `NETLINK_SCSITRANSPORT` #[cfg(linux_kernel)] - pub const SCSITRANSPORT: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_SCSITRANSPORT as _) }); + pub const SCSITRANSPORT: Protocol = Protocol(new_raw_protocol(c::NETLINK_SCSITRANSPORT as _)); /// `NETLINK_ECRYPTFS` #[cfg(linux_kernel)] - pub const ECRYPTFS: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_ECRYPTFS as _) }); + pub const ECRYPTFS: Protocol = Protocol(new_raw_protocol(c::NETLINK_ECRYPTFS as _)); /// `NETLINK_RDMA` #[cfg(linux_kernel)] - pub const RDMA: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_RDMA as _) }); + pub const RDMA: Protocol = Protocol(new_raw_protocol(c::NETLINK_RDMA as _)); /// `NETLINK_CRYPTO` #[cfg(linux_kernel)] - pub const CRYPTO: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_CRYPTO as _) }); + pub const CRYPTO: Protocol = Protocol(new_raw_protocol(c::NETLINK_CRYPTO as _)); /// `NETLINK_INET_DIAG` #[cfg(linux_kernel)] - pub const INET_DIAG: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_INET_DIAG as _) }); + pub const INET_DIAG: Protocol = Protocol(new_raw_protocol(c::NETLINK_INET_DIAG as _)); /// `NETLINK_ADD_MEMBERSHIP` #[cfg(linux_kernel)] - pub const ADD_MEMBERSHIP: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_ADD_MEMBERSHIP as _) }); + pub const ADD_MEMBERSHIP: Protocol = Protocol(new_raw_protocol(c::NETLINK_ADD_MEMBERSHIP as _)); /// `NETLINK_DROP_MEMBERSHIP` #[cfg(linux_kernel)] pub const DROP_MEMBERSHIP: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_DROP_MEMBERSHIP as _) }); + Protocol(new_raw_protocol(c::NETLINK_DROP_MEMBERSHIP as _)); /// `NETLINK_PKTINFO` #[cfg(linux_kernel)] - pub const PKTINFO: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_PKTINFO as _) }); + pub const PKTINFO: Protocol = Protocol(new_raw_protocol(c::NETLINK_PKTINFO as _)); /// `NETLINK_BROADCAST_ERROR` #[cfg(linux_kernel)] pub const BROADCAST_ERROR: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_BROADCAST_ERROR as _) }); + Protocol(new_raw_protocol(c::NETLINK_BROADCAST_ERROR as _)); /// `NETLINK_NO_ENOBUFS` #[cfg(linux_kernel)] - pub const NO_ENOBUFS: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_NO_ENOBUFS as _) }); + pub const NO_ENOBUFS: Protocol = Protocol(new_raw_protocol(c::NETLINK_NO_ENOBUFS as _)); /// `NETLINK_RX_RING` #[cfg(linux_kernel)] - pub const RX_RING: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_RX_RING as _) }); + pub const RX_RING: Protocol = Protocol(new_raw_protocol(c::NETLINK_RX_RING as _)); /// `NETLINK_TX_RING` #[cfg(linux_kernel)] - pub const TX_RING: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_TX_RING as _) }); + pub const TX_RING: Protocol = Protocol(new_raw_protocol(c::NETLINK_TX_RING as _)); /// `NETLINK_LISTEN_ALL_NSID` #[cfg(linux_kernel)] pub const LISTEN_ALL_NSID: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_LISTEN_ALL_NSID as _) }); + Protocol(new_raw_protocol(c::NETLINK_LISTEN_ALL_NSID as _)); /// `NETLINK_LIST_MEMBERSHIPS` #[cfg(linux_kernel)] pub const LIST_MEMBERSHIPS: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_LIST_MEMBERSHIPS as _) }); + Protocol(new_raw_protocol(c::NETLINK_LIST_MEMBERSHIPS as _)); /// `NETLINK_CAP_ACK` #[cfg(linux_kernel)] - pub const CAP_ACK: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_CAP_ACK as _) }); + pub const CAP_ACK: Protocol = Protocol(new_raw_protocol(c::NETLINK_CAP_ACK as _)); /// `NETLINK_EXT_ACK` #[cfg(linux_kernel)] - pub const EXT_ACK: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_EXT_ACK as _) }); + pub const EXT_ACK: Protocol = Protocol(new_raw_protocol(c::NETLINK_EXT_ACK as _)); /// `NETLINK_GET_STRICT_CHK` #[cfg(linux_kernel)] - pub const GET_STRICT_CHK: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_GET_STRICT_CHK as _) }); + pub const GET_STRICT_CHK: Protocol = Protocol(new_raw_protocol(c::NETLINK_GET_STRICT_CHK as _)); } /// `ETH_P_*` constants. -/// // These are translated into 16-bit big-endian form because that's what the -// `AddressFamily::PACKET` address family [expects]. +// [`AddressFamily::PACKET`] address family [expects]. // // [expects]: https://man7.org/linux/man-pages/man7/packet.7.html pub mod eth { #[cfg(linux_kernel)] use { - super::{Protocol, RawProtocol}, + super::{new_raw_protocol, Protocol}, crate::backend::c, }; /// `ETH_P_LOOP` #[cfg(linux_kernel)] - pub const LOOP: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_LOOP as u16).to_be() as u32) }); + pub const LOOP: Protocol = Protocol(new_raw_protocol((c::ETH_P_LOOP as u16).to_be() as u32)); /// `ETH_P_PUP` #[cfg(linux_kernel)] - pub const PUP: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_PUP as u16).to_be() as u32) }); + pub const PUP: Protocol = Protocol(new_raw_protocol((c::ETH_P_PUP as u16).to_be() as u32)); /// `ETH_P_PUPAT` #[cfg(linux_kernel)] - pub const PUPAT: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_PUPAT as u16).to_be() as u32) }); + pub const PUPAT: Protocol = Protocol(new_raw_protocol((c::ETH_P_PUPAT as u16).to_be() as u32)); /// `ETH_P_TSN` #[cfg(linux_kernel)] - pub const TSN: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_TSN as u16).to_be() as u32) }); + pub const TSN: Protocol = Protocol(new_raw_protocol((c::ETH_P_TSN as u16).to_be() as u32)); /// `ETH_P_ERSPAN2` #[cfg(linux_kernel)] pub const ERSPAN2: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_ERSPAN2 as u16).to_be() as u32) }); + Protocol(new_raw_protocol((c::ETH_P_ERSPAN2 as u16).to_be() as u32)); /// `ETH_P_IP` #[cfg(linux_kernel)] - pub const IP: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_IP as u16).to_be() as u32) }); + pub const IP: Protocol = Protocol(new_raw_protocol((c::ETH_P_IP as u16).to_be() as u32)); /// `ETH_P_X25` #[cfg(linux_kernel)] - pub const X25: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_X25 as u16).to_be() as u32) }); + pub const X25: Protocol = Protocol(new_raw_protocol((c::ETH_P_X25 as u16).to_be() as u32)); /// `ETH_P_ARP` #[cfg(linux_kernel)] - pub const ARP: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_ARP as u16).to_be() as u32) }); + pub const ARP: Protocol = Protocol(new_raw_protocol((c::ETH_P_ARP as u16).to_be() as u32)); /// `ETH_P_BPQ` #[cfg(linux_kernel)] - pub const BPQ: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_BPQ as u16).to_be() as u32) }); + pub const BPQ: Protocol = Protocol(new_raw_protocol((c::ETH_P_BPQ as u16).to_be() as u32)); /// `ETH_P_IEEEPUP` #[cfg(linux_kernel)] pub const IEEEPUP: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_IEEEPUP as u16).to_be() as u32) }); + Protocol(new_raw_protocol((c::ETH_P_IEEEPUP as u16).to_be() as u32)); /// `ETH_P_IEEEPUPAT` #[cfg(linux_kernel)] pub const IEEEPUPAT: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_IEEEPUPAT as u16).to_be() as u32) }); + Protocol(new_raw_protocol((c::ETH_P_IEEEPUPAT as u16).to_be() as u32)); /// `ETH_P_BATMAN` #[cfg(linux_kernel)] pub const BATMAN: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_BATMAN as u16).to_be() as u32) }); + Protocol(new_raw_protocol((c::ETH_P_BATMAN as u16).to_be() as u32)); /// `ETH_P_DEC` #[cfg(linux_kernel)] - pub const DEC: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_DEC as u16).to_be() as u32) }); + pub const DEC: Protocol = Protocol(new_raw_protocol((c::ETH_P_DEC as u16).to_be() as u32)); /// `ETH_P_DNA_DL` #[cfg(linux_kernel)] pub const DNA_DL: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_DNA_DL as u16).to_be() as u32) }); + Protocol(new_raw_protocol((c::ETH_P_DNA_DL as u16).to_be() as u32)); /// `ETH_P_DNA_RC` #[cfg(linux_kernel)] pub const DNA_RC: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_DNA_RC as u16).to_be() as u32) }); + Protocol(new_raw_protocol((c::ETH_P_DNA_RC as u16).to_be() as u32)); /// `ETH_P_DNA_RT` #[cfg(linux_kernel)] pub const DNA_RT: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_DNA_RT as u16).to_be() as u32) }); + Protocol(new_raw_protocol((c::ETH_P_DNA_RT as u16).to_be() as u32)); /// `ETH_P_LAT` #[cfg(linux_kernel)] - pub const LAT: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_LAT as u16).to_be() as u32) }); + pub const LAT: Protocol = Protocol(new_raw_protocol((c::ETH_P_LAT as u16).to_be() as u32)); /// `ETH_P_DIAG` #[cfg(linux_kernel)] - pub const DIAG: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_DIAG as u16).to_be() as u32) }); + pub const DIAG: Protocol = Protocol(new_raw_protocol((c::ETH_P_DIAG as u16).to_be() as u32)); /// `ETH_P_CUST` #[cfg(linux_kernel)] - pub const CUST: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_CUST as u16).to_be() as u32) }); + pub const CUST: Protocol = Protocol(new_raw_protocol((c::ETH_P_CUST as u16).to_be() as u32)); /// `ETH_P_SCA` #[cfg(linux_kernel)] - pub const SCA: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_SCA as u16).to_be() as u32) }); + pub const SCA: Protocol = Protocol(new_raw_protocol((c::ETH_P_SCA as u16).to_be() as u32)); /// `ETH_P_TEB` #[cfg(linux_kernel)] - pub const TEB: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_TEB as u16).to_be() as u32) }); + pub const TEB: Protocol = Protocol(new_raw_protocol((c::ETH_P_TEB as u16).to_be() as u32)); /// `ETH_P_RARP` #[cfg(linux_kernel)] - pub const RARP: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_RARP as u16).to_be() as u32) }); + pub const RARP: Protocol = Protocol(new_raw_protocol((c::ETH_P_RARP as u16).to_be() as u32)); /// `ETH_P_ATALK` #[cfg(linux_kernel)] - pub const ATALK: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_ATALK as u16).to_be() as u32) }); + pub const ATALK: Protocol = Protocol(new_raw_protocol((c::ETH_P_ATALK as u16).to_be() as u32)); /// `ETH_P_AARP` #[cfg(linux_kernel)] - pub const AARP: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_AARP as u16).to_be() as u32) }); + pub const AARP: Protocol = Protocol(new_raw_protocol((c::ETH_P_AARP as u16).to_be() as u32)); /// `ETH_P_8021Q` #[cfg(linux_kernel)] pub const P_8021Q: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_8021Q as u16).to_be() as u32) }); + Protocol(new_raw_protocol((c::ETH_P_8021Q as u16).to_be() as u32)); /// `ETH_P_ERSPAN` #[cfg(linux_kernel)] pub const ERSPAN: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_ERSPAN as u16).to_be() as u32) }); + Protocol(new_raw_protocol((c::ETH_P_ERSPAN as u16).to_be() as u32)); /// `ETH_P_IPX` #[cfg(linux_kernel)] - pub const IPX: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_IPX as u16).to_be() as u32) }); + pub const IPX: Protocol = Protocol(new_raw_protocol((c::ETH_P_IPX as u16).to_be() as u32)); /// `ETH_P_IPV6` #[cfg(linux_kernel)] - pub const IPV6: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_IPV6 as u16).to_be() as u32) }); + pub const IPV6: Protocol = Protocol(new_raw_protocol((c::ETH_P_IPV6 as u16).to_be() as u32)); /// `ETH_P_PAUSE` #[cfg(linux_kernel)] - pub const PAUSE: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_PAUSE as u16).to_be() as u32) }); + pub const PAUSE: Protocol = Protocol(new_raw_protocol((c::ETH_P_PAUSE as u16).to_be() as u32)); /// `ETH_P_SLOW` #[cfg(linux_kernel)] - pub const SLOW: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_SLOW as u16).to_be() as u32) }); + pub const SLOW: Protocol = Protocol(new_raw_protocol((c::ETH_P_SLOW as u16).to_be() as u32)); /// `ETH_P_WCCP` #[cfg(linux_kernel)] - pub const WCCP: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_WCCP as u16).to_be() as u32) }); + pub const WCCP: Protocol = Protocol(new_raw_protocol((c::ETH_P_WCCP as u16).to_be() as u32)); /// `ETH_P_MPLS_UC` #[cfg(linux_kernel)] pub const MPLS_UC: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_MPLS_UC as u16).to_be() as u32) }); + Protocol(new_raw_protocol((c::ETH_P_MPLS_UC as u16).to_be() as u32)); /// `ETH_P_MPLS_MC` #[cfg(linux_kernel)] pub const MPLS_MC: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_MPLS_MC as u16).to_be() as u32) }); + Protocol(new_raw_protocol((c::ETH_P_MPLS_MC as u16).to_be() as u32)); /// `ETH_P_ATMMPOA` #[cfg(linux_kernel)] pub const ATMMPOA: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_ATMMPOA as u16).to_be() as u32) }); + Protocol(new_raw_protocol((c::ETH_P_ATMMPOA as u16).to_be() as u32)); /// `ETH_P_PPP_DISC` #[cfg(linux_kernel)] pub const PPP_DISC: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_PPP_DISC as u16).to_be() as u32) }); + Protocol(new_raw_protocol((c::ETH_P_PPP_DISC as u16).to_be() as u32)); /// `ETH_P_PPP_SES` #[cfg(linux_kernel)] pub const PPP_SES: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_PPP_SES as u16).to_be() as u32) }); + Protocol(new_raw_protocol((c::ETH_P_PPP_SES as u16).to_be() as u32)); /// `ETH_P_LINK_CTL` #[cfg(linux_kernel)] pub const LINK_CTL: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_LINK_CTL as u16).to_be() as u32) }); + Protocol(new_raw_protocol((c::ETH_P_LINK_CTL as u16).to_be() as u32)); /// `ETH_P_ATMFATE` #[cfg(linux_kernel)] pub const ATMFATE: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_ATMFATE as u16).to_be() as u32) }); + Protocol(new_raw_protocol((c::ETH_P_ATMFATE as u16).to_be() as u32)); /// `ETH_P_PAE` #[cfg(linux_kernel)] - pub const PAE: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_PAE as u16).to_be() as u32) }); + pub const PAE: Protocol = Protocol(new_raw_protocol((c::ETH_P_PAE as u16).to_be() as u32)); /// `ETH_P_PROFINET` #[cfg(linux_kernel)] pub const PROFINET: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_PROFINET as u16).to_be() as u32) }); + Protocol(new_raw_protocol((c::ETH_P_PROFINET as u16).to_be() as u32)); /// `ETH_P_REALTEK` #[cfg(linux_kernel)] pub const REALTEK: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_REALTEK as u16).to_be() as u32) }); + Protocol(new_raw_protocol((c::ETH_P_REALTEK as u16).to_be() as u32)); /// `ETH_P_AOE` #[cfg(linux_kernel)] - pub const AOE: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_AOE as u16).to_be() as u32) }); + pub const AOE: Protocol = Protocol(new_raw_protocol((c::ETH_P_AOE as u16).to_be() as u32)); /// `ETH_P_ETHERCAT` #[cfg(linux_kernel)] pub const ETHERCAT: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_ETHERCAT as u16).to_be() as u32) }); + Protocol(new_raw_protocol((c::ETH_P_ETHERCAT as u16).to_be() as u32)); /// `ETH_P_8021AD` #[cfg(linux_kernel)] pub const P_8021AD: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_8021AD as u16).to_be() as u32) }); + Protocol(new_raw_protocol((c::ETH_P_8021AD as u16).to_be() as u32)); /// `ETH_P_802_EX1` #[cfg(linux_kernel)] pub const P_802_EX1: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_802_EX1 as u16).to_be() as u32) }); + Protocol(new_raw_protocol((c::ETH_P_802_EX1 as u16).to_be() as u32)); /// `ETH_P_PREAUTH` #[cfg(linux_kernel)] pub const PREAUTH: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_PREAUTH as u16).to_be() as u32) }); + Protocol(new_raw_protocol((c::ETH_P_PREAUTH as u16).to_be() as u32)); /// `ETH_P_TIPC` #[cfg(linux_kernel)] - pub const TIPC: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_TIPC as u16).to_be() as u32) }); + pub const TIPC: Protocol = Protocol(new_raw_protocol((c::ETH_P_TIPC as u16).to_be() as u32)); /// `ETH_P_LLDP` #[cfg(linux_kernel)] - pub const LLDP: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_LLDP as u16).to_be() as u32) }); + pub const LLDP: Protocol = Protocol(new_raw_protocol((c::ETH_P_LLDP as u16).to_be() as u32)); /// `ETH_P_MRP` #[cfg(linux_kernel)] - pub const MRP: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_MRP as u16).to_be() as u32) }); + pub const MRP: Protocol = Protocol(new_raw_protocol((c::ETH_P_MRP as u16).to_be() as u32)); /// `ETH_P_MACSEC` #[cfg(linux_kernel)] pub const MACSEC: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_MACSEC as u16).to_be() as u32) }); + Protocol(new_raw_protocol((c::ETH_P_MACSEC as u16).to_be() as u32)); /// `ETH_P_8021AH` #[cfg(linux_kernel)] pub const P_8021AH: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_8021AH as u16).to_be() as u32) }); + Protocol(new_raw_protocol((c::ETH_P_8021AH as u16).to_be() as u32)); /// `ETH_P_MVRP` #[cfg(linux_kernel)] - pub const MVRP: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_MVRP as u16).to_be() as u32) }); + pub const MVRP: Protocol = Protocol(new_raw_protocol((c::ETH_P_MVRP as u16).to_be() as u32)); /// `ETH_P_1588` #[cfg(linux_kernel)] - pub const P_1588: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_1588 as u16).to_be() as u32) }); + pub const P_1588: Protocol = Protocol(new_raw_protocol((c::ETH_P_1588 as u16).to_be() as u32)); /// `ETH_P_NCSI` #[cfg(linux_kernel)] - pub const NCSI: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_NCSI as u16).to_be() as u32) }); + pub const NCSI: Protocol = Protocol(new_raw_protocol((c::ETH_P_NCSI as u16).to_be() as u32)); /// `ETH_P_PRP` #[cfg(linux_kernel)] - pub const PRP: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_PRP as u16).to_be() as u32) }); + pub const PRP: Protocol = Protocol(new_raw_protocol((c::ETH_P_PRP as u16).to_be() as u32)); /// `ETH_P_CFM` #[cfg(linux_kernel)] - pub const CFM: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_CFM as u16).to_be() as u32) }); + pub const CFM: Protocol = Protocol(new_raw_protocol((c::ETH_P_CFM as u16).to_be() as u32)); /// `ETH_P_FCOE` #[cfg(linux_kernel)] - pub const FCOE: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_FCOE as u16).to_be() as u32) }); + pub const FCOE: Protocol = Protocol(new_raw_protocol((c::ETH_P_FCOE as u16).to_be() as u32)); /// `ETH_P_IBOE` #[cfg(linux_kernel)] - pub const IBOE: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_IBOE as u16).to_be() as u32) }); + pub const IBOE: Protocol = Protocol(new_raw_protocol((c::ETH_P_IBOE as u16).to_be() as u32)); /// `ETH_P_TDLS` #[cfg(linux_kernel)] - pub const TDLS: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_TDLS as u16).to_be() as u32) }); + pub const TDLS: Protocol = Protocol(new_raw_protocol((c::ETH_P_TDLS as u16).to_be() as u32)); /// `ETH_P_FIP` #[cfg(linux_kernel)] - pub const FIP: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_FIP as u16).to_be() as u32) }); + pub const FIP: Protocol = Protocol(new_raw_protocol((c::ETH_P_FIP as u16).to_be() as u32)); /// `ETH_P_80221` #[cfg(linux_kernel)] pub const P_80221: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_80221 as u16).to_be() as u32) }); + Protocol(new_raw_protocol((c::ETH_P_80221 as u16).to_be() as u32)); /// `ETH_P_HSR` #[cfg(linux_kernel)] - pub const HSR: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_HSR as u16).to_be() as u32) }); + pub const HSR: Protocol = Protocol(new_raw_protocol((c::ETH_P_HSR as u16).to_be() as u32)); /// `ETH_P_NSH` #[cfg(linux_kernel)] - pub const NSH: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_NSH as u16).to_be() as u32) }); + pub const NSH: Protocol = Protocol(new_raw_protocol((c::ETH_P_NSH as u16).to_be() as u32)); /// `ETH_P_LOOPBACK` #[cfg(linux_kernel)] pub const LOOPBACK: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_LOOPBACK as u16).to_be() as u32) }); + Protocol(new_raw_protocol((c::ETH_P_LOOPBACK as u16).to_be() as u32)); /// `ETH_P_QINQ1` #[cfg(linux_kernel)] - pub const QINQ1: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_QINQ1 as u16).to_be() as u32) }); + pub const QINQ1: Protocol = Protocol(new_raw_protocol((c::ETH_P_QINQ1 as u16).to_be() as u32)); /// `ETH_P_QINQ2` #[cfg(linux_kernel)] - pub const QINQ2: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_QINQ2 as u16).to_be() as u32) }); + pub const QINQ2: Protocol = Protocol(new_raw_protocol((c::ETH_P_QINQ2 as u16).to_be() as u32)); /// `ETH_P_QINQ3` #[cfg(linux_kernel)] - pub const QINQ3: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_QINQ3 as u16).to_be() as u32) }); + pub const QINQ3: Protocol = Protocol(new_raw_protocol((c::ETH_P_QINQ3 as u16).to_be() as u32)); /// `ETH_P_EDSA` #[cfg(linux_kernel)] - pub const EDSA: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_EDSA as u16).to_be() as u32) }); + pub const EDSA: Protocol = Protocol(new_raw_protocol((c::ETH_P_EDSA as u16).to_be() as u32)); /// `ETH_P_DSA_8021Q` #[cfg(linux_kernel)] pub const DSA_8021Q: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_DSA_8021Q as u16).to_be() as u32) }); + Protocol(new_raw_protocol((c::ETH_P_DSA_8021Q as u16).to_be() as u32)); /// `ETH_P_DSA_A5PSW` #[cfg(linux_kernel)] pub const DSA_A5PSW: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_DSA_A5PSW as u16).to_be() as u32) }); + Protocol(new_raw_protocol((c::ETH_P_DSA_A5PSW as u16).to_be() as u32)); /// `ETH_P_IFE` #[cfg(linux_kernel)] - pub const IFE: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_IFE as u16).to_be() as u32) }); + pub const IFE: Protocol = Protocol(new_raw_protocol((c::ETH_P_IFE as u16).to_be() as u32)); /// `ETH_P_AF_IUCV` #[cfg(linux_kernel)] pub const AF_IUCV: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_AF_IUCV as u16).to_be() as u32) }); + Protocol(new_raw_protocol((c::ETH_P_AF_IUCV as u16).to_be() as u32)); /// `ETH_P_802_3_MIN` #[cfg(linux_kernel)] pub const P_802_3_MIN: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_802_3_MIN as u16).to_be() as u32) }); + Protocol(new_raw_protocol((c::ETH_P_802_3_MIN as u16).to_be() as u32)); /// `ETH_P_802_3` #[cfg(linux_kernel)] pub const P_802_3: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_802_3 as u16).to_be() as u32) }); + Protocol(new_raw_protocol((c::ETH_P_802_3 as u16).to_be() as u32)); /// `ETH_P_AX25` #[cfg(linux_kernel)] - pub const AX25: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_AX25 as u16).to_be() as u32) }); + pub const AX25: Protocol = Protocol(new_raw_protocol((c::ETH_P_AX25 as u16).to_be() as u32)); /// `ETH_P_ALL` #[cfg(linux_kernel)] - pub const ALL: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_ALL as u16).to_be() as u32) }); + pub const ALL: Protocol = Protocol(new_raw_protocol((c::ETH_P_ALL as u16).to_be() as u32)); /// `ETH_P_802_2` #[cfg(linux_kernel)] pub const P_802_2: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_802_2 as u16).to_be() as u32) }); + Protocol(new_raw_protocol((c::ETH_P_802_2 as u16).to_be() as u32)); /// `ETH_P_SNAP` #[cfg(linux_kernel)] - pub const SNAP: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_SNAP as u16).to_be() as u32) }); + pub const SNAP: Protocol = Protocol(new_raw_protocol((c::ETH_P_SNAP as u16).to_be() as u32)); /// `ETH_P_DDCMP` #[cfg(linux_kernel)] - pub const DDCMP: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_DDCMP as u16).to_be() as u32) }); + pub const DDCMP: Protocol = Protocol(new_raw_protocol((c::ETH_P_DDCMP as u16).to_be() as u32)); /// `ETH_P_WAN_PPP` #[cfg(linux_kernel)] pub const WAN_PPP: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_WAN_PPP as u16).to_be() as u32) }); + Protocol(new_raw_protocol((c::ETH_P_WAN_PPP as u16).to_be() as u32)); /// `ETH_P_PPP_MP` #[cfg(linux_kernel)] pub const PPP_MP: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_PPP_MP as u16).to_be() as u32) }); + Protocol(new_raw_protocol((c::ETH_P_PPP_MP as u16).to_be() as u32)); /// `ETH_P_LOCALTALK` #[cfg(linux_kernel)] pub const LOCALTALK: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_LOCALTALK as u16).to_be() as u32) }); + Protocol(new_raw_protocol((c::ETH_P_LOCALTALK as u16).to_be() as u32)); /// `ETH_P_CAN` #[cfg(linux_kernel)] - pub const CAN: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_CAN as u16).to_be() as u32) }); + pub const CAN: Protocol = Protocol(new_raw_protocol((c::ETH_P_CAN as u16).to_be() as u32)); /// `ETH_P_CANFD` #[cfg(linux_kernel)] - pub const CANFD: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_CANFD as u16).to_be() as u32) }); + pub const CANFD: Protocol = Protocol(new_raw_protocol((c::ETH_P_CANFD as u16).to_be() as u32)); /// `ETH_P_CANXL` #[cfg(linux_kernel)] - pub const CANXL: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_CANXL as u16).to_be() as u32) }); + pub const CANXL: Protocol = Protocol(new_raw_protocol((c::ETH_P_CANXL as u16).to_be() as u32)); /// `ETH_P_PPPTALK` #[cfg(linux_kernel)] pub const PPPTALK: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_PPPTALK as u16).to_be() as u32) }); + Protocol(new_raw_protocol((c::ETH_P_PPPTALK as u16).to_be() as u32)); /// `ETH_P_TR_802_2` #[cfg(linux_kernel)] pub const TR_802_2: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_TR_802_2 as u16).to_be() as u32) }); + Protocol(new_raw_protocol((c::ETH_P_TR_802_2 as u16).to_be() as u32)); /// `ETH_P_MOBITEX` #[cfg(linux_kernel)] pub const MOBITEX: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_MOBITEX as u16).to_be() as u32) }); + Protocol(new_raw_protocol((c::ETH_P_MOBITEX as u16).to_be() as u32)); /// `ETH_P_CONTROL` #[cfg(linux_kernel)] pub const CONTROL: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_CONTROL as u16).to_be() as u32) }); + Protocol(new_raw_protocol((c::ETH_P_CONTROL as u16).to_be() as u32)); /// `ETH_P_IRDA` #[cfg(linux_kernel)] - pub const IRDA: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_IRDA as u16).to_be() as u32) }); + pub const IRDA: Protocol = Protocol(new_raw_protocol((c::ETH_P_IRDA as u16).to_be() as u32)); /// `ETH_P_ECONET` #[cfg(linux_kernel)] pub const ECONET: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_ECONET as u16).to_be() as u32) }); + Protocol(new_raw_protocol((c::ETH_P_ECONET as u16).to_be() as u32)); /// `ETH_P_HDLC` #[cfg(linux_kernel)] - pub const HDLC: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_HDLC as u16).to_be() as u32) }); + pub const HDLC: Protocol = Protocol(new_raw_protocol((c::ETH_P_HDLC as u16).to_be() as u32)); /// `ETH_P_ARCNET` #[cfg(linux_kernel)] pub const ARCNET: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_ARCNET as u16).to_be() as u32) }); + Protocol(new_raw_protocol((c::ETH_P_ARCNET as u16).to_be() as u32)); /// `ETH_P_DSA` #[cfg(linux_kernel)] - pub const DSA: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_DSA as u16).to_be() as u32) }); + pub const DSA: Protocol = Protocol(new_raw_protocol((c::ETH_P_DSA as u16).to_be() as u32)); /// `ETH_P_TRAILER` #[cfg(linux_kernel)] pub const TRAILER: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_TRAILER as u16).to_be() as u32) }); + Protocol(new_raw_protocol((c::ETH_P_TRAILER as u16).to_be() as u32)); /// `ETH_P_PHONET` #[cfg(linux_kernel)] pub const PHONET: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_PHONET as u16).to_be() as u32) }); + Protocol(new_raw_protocol((c::ETH_P_PHONET as u16).to_be() as u32)); /// `ETH_P_IEEE802154` #[cfg(linux_kernel)] - pub const IEEE802154: Protocol = Protocol(unsafe { - RawProtocol::new_unchecked((c::ETH_P_IEEE802154 as u16).to_be() as u32) - }); + pub const IEEE802154: Protocol = + Protocol(new_raw_protocol((c::ETH_P_IEEE802154 as u16).to_be() as u32)); /// `ETH_P_CAIF` #[cfg(linux_kernel)] - pub const CAIF: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_CAIF as u16).to_be() as u32) }); + pub const CAIF: Protocol = Protocol(new_raw_protocol((c::ETH_P_CAIF as u16).to_be() as u32)); /// `ETH_P_XDSA` #[cfg(linux_kernel)] - pub const XDSA: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_XDSA as u16).to_be() as u32) }); + pub const XDSA: Protocol = Protocol(new_raw_protocol((c::ETH_P_XDSA as u16).to_be() as u32)); /// `ETH_P_MAP` #[cfg(linux_kernel)] - pub const MAP: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_MAP as u16).to_be() as u32) }); + pub const MAP: Protocol = Protocol(new_raw_protocol((c::ETH_P_MAP as u16).to_be() as u32)); /// `ETH_P_MCTP` #[cfg(linux_kernel)] - pub const MCTP: Protocol = - Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_MCTP as u16).to_be() as u32) }); + pub const MCTP: Protocol = Protocol(new_raw_protocol((c::ETH_P_MCTP as u16).to_be() as u32)); } #[rustfmt::skip] @@ -1361,12 +1316,23 @@ bitflags! { #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct SocketFlags: c::c_uint { /// `SOCK_NONBLOCK` - #[cfg(not(any(apple, windows, target_os = "espidf", target_os = "haiku", target_os = "nto")))] + #[cfg(not(any( + apple, + windows, + target_os = "aix", + target_os = "espidf", + target_os = "haiku", + target_os = "nto", + )))] const NONBLOCK = bitcast!(c::SOCK_NONBLOCK); /// `SOCK_CLOEXEC` - #[cfg(not(any(apple, windows, target_os = "haiku")))] + #[cfg(not(any(apple, windows, target_os = "aix", target_os = "haiku")))] const CLOEXEC = bitcast!(c::SOCK_CLOEXEC); + + // 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`. } } @@ -1375,8 +1341,8 @@ fn test_sizes() { use c::c_int; use core::mem::transmute; - // Backend code needs to cast these to `c_int` so make sure that cast - // isn't lossy. + // Backend code needs to cast these to `c_int` so make sure that cast isn't + // lossy. assert_eq_size!(RawProtocol, c_int); assert_eq_size!(Protocol, c_int); assert_eq_size!(Option<RawProtocol>, c_int); @@ -1385,13 +1351,14 @@ fn test_sizes() { assert_eq_size!(SocketType, c_int); assert_eq_size!(SocketFlags, c_int); - // Rustix doesn't depend on `Option<Protocol>` matching the ABI of - // a raw integer for correctness, but it should work nonetheless. + // Rustix doesn't depend on `Option<Protocol>` matching the ABI of a raw + // integer for correctness, but it should work nonetheless. + #[allow(unsafe_code)] unsafe { let t: Option<Protocol> = None; - assert_eq!(0_u32, transmute(t)); + assert_eq!(0_u32, transmute::<Option<Protocol>, u32>(t)); let t: Option<Protocol> = Some(Protocol::from_raw(RawProtocol::new(4567).unwrap())); - assert_eq!(4567_u32, transmute(t)); + assert_eq!(4567_u32, transmute::<Option<Protocol>, u32>(t)); } } diff --git a/vendor/rustix/src/param/init.rs b/vendor/rustix/src/param/init.rs index d261fabd2..09d7c96bd 100644 --- a/vendor/rustix/src/param/init.rs +++ b/vendor/rustix/src/param/init.rs @@ -2,8 +2,8 @@ //! //! # Safety //! -//! On mustang, or on any non-glibc non-musl platform, the `init` function must -//! be called before any other function in this module. It is unsafe because it +//! When "use-explicitly-provided-auxv" is enabled, the `init` function must be +//! called before any other function in this module. It is unsafe because it //! operates on raw pointers. #![allow(unsafe_code)] diff --git a/vendor/rustix/src/param/mod.rs b/vendor/rustix/src/param/mod.rs index dde09772a..905eae7e3 100644 --- a/vendor/rustix/src/param/mod.rs +++ b/vendor/rustix/src/param/mod.rs @@ -6,9 +6,9 @@ //! between different processes on the same system. mod auxv; -#[cfg(target_vendor = "mustang")] +#[cfg(feature = "use-explicitly-provided-auxv")] mod init; pub use auxv::*; -#[cfg(target_vendor = "mustang")] +#[cfg(feature = "use-explicitly-provided-auxv")] pub use init::init; diff --git a/vendor/rustix/src/path/arg.rs b/vendor/rustix/src/path/arg.rs index 64091611c..3b0ad91ae 100644 --- a/vendor/rustix/src/path/arg.rs +++ b/vendor/rustix/src/path/arg.rs @@ -5,16 +5,13 @@ //! to rustix APIs with string arguments, and it allows rustix to implement //! NUL-termination without the need for copying where possible. -use crate::ffi::{CStr, CString}; +use crate::ffi::CStr; use crate::io; #[cfg(feature = "itoa")] use crate::path::DecInt; use crate::path::SMALL_PATH_BUFFER_SIZE; -use alloc::borrow::Cow; -#[cfg(feature = "itoa")] +#[cfg(all(feature = "alloc", feature = "itoa"))] use alloc::borrow::ToOwned; -use alloc::string::String; -use alloc::vec::Vec; use core::mem::MaybeUninit; use core::{ptr, slice, str}; #[cfg(feature = "std")] @@ -29,6 +26,10 @@ use std::os::vxworks::ext::ffi::{OsStrExt, OsStringExt}; use std::os::wasi::ffi::{OsStrExt, OsStringExt}; #[cfg(feature = "std")] use std::path::{Component, Components, Iter, Path, PathBuf}; +#[cfg(feature = "alloc")] +use {crate::ffi::CString, alloc::borrow::Cow}; +#[cfg(feature = "alloc")] +use {alloc::string::String, alloc::vec::Vec}; /// A trait for passing path arguments. /// @@ -65,15 +66,18 @@ pub trait Arg { /// Returns a view of this string as a string slice. fn as_str(&self) -> io::Result<&str>; - /// Returns a potentially-lossy rendering of this string as a `Cow<'_, - /// str>`. + /// Returns a potentially-lossy rendering of this string as a + /// `Cow<'_, str>`. + #[cfg(feature = "alloc")] fn to_string_lossy(&self) -> Cow<'_, str>; /// Returns a view of this string as a maybe-owned [`CStr`]. + #[cfg(feature = "alloc")] fn as_cow_c_str(&self) -> io::Result<Cow<'_, CStr>>; /// Consumes `self` and returns a view of this string as a maybe-owned /// [`CStr`]. + #[cfg(feature = "alloc")] fn into_c_str<'b>(self) -> io::Result<Cow<'b, CStr>> where Self: 'b; @@ -91,11 +95,13 @@ impl Arg for &str { Ok(self) } + #[cfg(feature = "alloc")] #[inline] fn to_string_lossy(&self) -> Cow<'_, str> { Cow::Borrowed(self) } + #[cfg(feature = "alloc")] #[inline] fn as_cow_c_str(&self) -> io::Result<Cow<'_, CStr>> { Ok(Cow::Owned( @@ -103,6 +109,7 @@ impl Arg for &str { )) } + #[cfg(feature = "alloc")] #[inline] fn into_c_str<'b>(self) -> io::Result<Cow<'b, CStr>> where @@ -123,17 +130,20 @@ impl Arg for &str { } } +#[cfg(feature = "alloc")] impl Arg for &String { #[inline] fn as_str(&self) -> io::Result<&str> { Ok(self) } + #[cfg(feature = "alloc")] #[inline] fn to_string_lossy(&self) -> Cow<'_, str> { Cow::Borrowed(self) } + #[cfg(feature = "alloc")] #[inline] fn as_cow_c_str(&self) -> io::Result<Cow<'_, CStr>> { Ok(Cow::Owned( @@ -141,6 +151,7 @@ impl Arg for &String { )) } + #[cfg(feature = "alloc")] #[inline] fn into_c_str<'b>(self) -> io::Result<Cow<'b, CStr>> where @@ -159,17 +170,20 @@ impl Arg for &String { } } +#[cfg(feature = "alloc")] impl Arg for String { #[inline] fn as_str(&self) -> io::Result<&str> { Ok(self) } + #[cfg(feature = "alloc")] #[inline] fn to_string_lossy(&self) -> Cow<'_, str> { Cow::Borrowed(self) } + #[cfg(feature = "alloc")] #[inline] fn as_cow_c_str(&self) -> io::Result<Cow<'_, CStr>> { Ok(Cow::Owned( @@ -177,6 +191,7 @@ impl Arg for String { )) } + #[cfg(feature = "alloc")] #[inline] fn into_c_str<'b>(self) -> io::Result<Cow<'b, CStr>> where @@ -204,11 +219,13 @@ impl Arg for &OsStr { self.to_str().ok_or(io::Errno::INVAL) } + #[cfg(feature = "alloc")] #[inline] fn to_string_lossy(&self) -> Cow<'_, str> { OsStr::to_string_lossy(self) } + #[cfg(feature = "alloc")] #[inline] fn as_cow_c_str(&self) -> io::Result<Cow<'_, CStr>> { Ok(Cow::Owned( @@ -216,6 +233,7 @@ impl Arg for &OsStr { )) } + #[cfg(feature = "alloc")] #[inline] fn into_c_str<'b>(self) -> io::Result<Cow<'b, CStr>> where @@ -243,11 +261,13 @@ impl Arg for &OsString { OsString::as_os_str(self).to_str().ok_or(io::Errno::INVAL) } + #[cfg(feature = "alloc")] #[inline] fn to_string_lossy(&self) -> Cow<'_, str> { self.as_os_str().to_string_lossy() } + #[cfg(feature = "alloc")] #[inline] fn as_cow_c_str(&self) -> io::Result<Cow<'_, CStr>> { Ok(Cow::Owned( @@ -256,6 +276,7 @@ impl Arg for &OsString { )) } + #[cfg(feature = "alloc")] #[inline] fn into_c_str<'b>(self) -> io::Result<Cow<'b, CStr>> where @@ -281,11 +302,13 @@ impl Arg for OsString { self.as_os_str().to_str().ok_or(io::Errno::INVAL) } + #[cfg(feature = "alloc")] #[inline] fn to_string_lossy(&self) -> Cow<'_, str> { self.as_os_str().to_string_lossy() } + #[cfg(feature = "alloc")] #[inline] fn as_cow_c_str(&self) -> io::Result<Cow<'_, CStr>> { Ok(Cow::Owned( @@ -293,6 +316,7 @@ impl Arg for OsString { )) } + #[cfg(feature = "alloc")] #[inline] fn into_c_str<'b>(self) -> io::Result<Cow<'b, CStr>> where @@ -320,11 +344,13 @@ impl Arg for &Path { self.as_os_str().to_str().ok_or(io::Errno::INVAL) } + #[cfg(feature = "alloc")] #[inline] fn to_string_lossy(&self) -> Cow<'_, str> { Path::to_string_lossy(self) } + #[cfg(feature = "alloc")] #[inline] fn as_cow_c_str(&self) -> io::Result<Cow<'_, CStr>> { Ok(Cow::Owned( @@ -332,6 +358,7 @@ impl Arg for &Path { )) } + #[cfg(feature = "alloc")] #[inline] fn into_c_str<'b>(self) -> io::Result<Cow<'b, CStr>> where @@ -362,11 +389,13 @@ impl Arg for &PathBuf { .ok_or(io::Errno::INVAL) } + #[cfg(feature = "alloc")] #[inline] fn to_string_lossy(&self) -> Cow<'_, str> { self.as_path().to_string_lossy() } + #[cfg(feature = "alloc")] #[inline] fn as_cow_c_str(&self) -> io::Result<Cow<'_, CStr>> { Ok(Cow::Owned( @@ -375,6 +404,7 @@ impl Arg for &PathBuf { )) } + #[cfg(feature = "alloc")] #[inline] fn into_c_str<'b>(self) -> io::Result<Cow<'b, CStr>> where @@ -400,11 +430,13 @@ impl Arg for PathBuf { self.as_os_str().to_str().ok_or(io::Errno::INVAL) } + #[cfg(feature = "alloc")] #[inline] fn to_string_lossy(&self) -> Cow<'_, str> { self.as_os_str().to_string_lossy() } + #[cfg(feature = "alloc")] #[inline] fn as_cow_c_str(&self) -> io::Result<Cow<'_, CStr>> { Ok(Cow::Owned( @@ -412,6 +444,7 @@ impl Arg for PathBuf { )) } + #[cfg(feature = "alloc")] #[inline] fn into_c_str<'b>(self) -> io::Result<Cow<'b, CStr>> where @@ -441,16 +474,19 @@ impl Arg for &CStr { self.to_str().map_err(|_utf8_err| io::Errno::INVAL) } + #[cfg(feature = "alloc")] #[inline] fn to_string_lossy(&self) -> Cow<'_, str> { CStr::to_string_lossy(self) } + #[cfg(feature = "alloc")] #[inline] fn as_cow_c_str(&self) -> io::Result<Cow<'_, CStr>> { Ok(Cow::Borrowed(self)) } + #[cfg(feature = "alloc")] #[inline] fn into_c_str<'b>(self) -> io::Result<Cow<'b, CStr>> where @@ -469,22 +505,26 @@ impl Arg for &CStr { } } +#[cfg(feature = "alloc")] impl Arg for &CString { #[inline] fn as_str(&self) -> io::Result<&str> { unimplemented!() } + #[cfg(feature = "alloc")] #[inline] fn to_string_lossy(&self) -> Cow<'_, str> { unimplemented!() } + #[cfg(feature = "alloc")] #[inline] fn as_cow_c_str(&self) -> io::Result<Cow<'_, CStr>> { Ok(Cow::Borrowed(self)) } + #[cfg(feature = "alloc")] #[inline] fn into_c_str<'b>(self) -> io::Result<Cow<'b, CStr>> where @@ -503,22 +543,26 @@ impl Arg for &CString { } } +#[cfg(feature = "alloc")] impl Arg for CString { #[inline] fn as_str(&self) -> io::Result<&str> { self.to_str().map_err(|_utf8_err| io::Errno::INVAL) } + #[cfg(feature = "alloc")] #[inline] fn to_string_lossy(&self) -> Cow<'_, str> { CStr::to_string_lossy(self) } + #[cfg(feature = "alloc")] #[inline] fn as_cow_c_str(&self) -> io::Result<Cow<'_, CStr>> { Ok(Cow::Borrowed(self)) } + #[cfg(feature = "alloc")] #[inline] fn into_c_str<'b>(self) -> io::Result<Cow<'b, CStr>> where @@ -537,17 +581,20 @@ impl Arg for CString { } } +#[cfg(feature = "alloc")] impl<'a> Arg for Cow<'a, str> { #[inline] fn as_str(&self) -> io::Result<&str> { Ok(self) } + #[cfg(feature = "alloc")] #[inline] fn to_string_lossy(&self) -> Cow<'_, str> { Cow::Borrowed(self) } + #[cfg(feature = "alloc")] #[inline] fn as_cow_c_str(&self) -> io::Result<Cow<'_, CStr>> { Ok(Cow::Owned( @@ -555,6 +602,7 @@ impl<'a> Arg for Cow<'a, str> { )) } + #[cfg(feature = "alloc")] #[inline] fn into_c_str<'b>(self) -> io::Result<Cow<'b, CStr>> where @@ -580,17 +628,20 @@ impl<'a> Arg for Cow<'a, str> { } #[cfg(feature = "std")] +#[cfg(feature = "alloc")] impl<'a> Arg for Cow<'a, OsStr> { #[inline] fn as_str(&self) -> io::Result<&str> { (**self).to_str().ok_or(io::Errno::INVAL) } + #[cfg(feature = "alloc")] #[inline] fn to_string_lossy(&self) -> Cow<'_, str> { (**self).to_string_lossy() } + #[cfg(feature = "alloc")] #[inline] fn as_cow_c_str(&self) -> io::Result<Cow<'_, CStr>> { Ok(Cow::Owned( @@ -598,6 +649,7 @@ impl<'a> Arg for Cow<'a, OsStr> { )) } + #[cfg(feature = "alloc")] #[inline] fn into_c_str<'b>(self) -> io::Result<Cow<'b, CStr>> where @@ -622,23 +674,27 @@ impl<'a> Arg for Cow<'a, OsStr> { } } +#[cfg(feature = "alloc")] impl<'a> Arg for Cow<'a, CStr> { #[inline] fn as_str(&self) -> io::Result<&str> { self.to_str().map_err(|_utf8_err| io::Errno::INVAL) } + #[cfg(feature = "alloc")] #[inline] fn to_string_lossy(&self) -> Cow<'_, str> { let borrow: &CStr = core::borrow::Borrow::borrow(self); borrow.to_string_lossy() } + #[cfg(feature = "alloc")] #[inline] fn as_cow_c_str(&self) -> io::Result<Cow<'_, CStr>> { Ok(Cow::Borrowed(self)) } + #[cfg(feature = "alloc")] #[inline] fn into_c_str<'b>(self) -> io::Result<Cow<'b, CStr>> where @@ -664,11 +720,13 @@ impl<'a> Arg for Component<'a> { self.as_os_str().to_str().ok_or(io::Errno::INVAL) } + #[cfg(feature = "alloc")] #[inline] fn to_string_lossy(&self) -> Cow<'_, str> { self.as_os_str().to_string_lossy() } + #[cfg(feature = "alloc")] #[inline] fn as_cow_c_str(&self) -> io::Result<Cow<'_, CStr>> { Ok(Cow::Owned( @@ -676,6 +734,7 @@ impl<'a> Arg for Component<'a> { )) } + #[cfg(feature = "alloc")] #[inline] fn into_c_str<'b>(self) -> io::Result<Cow<'b, CStr>> where @@ -703,11 +762,13 @@ impl<'a> Arg for Components<'a> { self.as_path().to_str().ok_or(io::Errno::INVAL) } + #[cfg(feature = "alloc")] #[inline] fn to_string_lossy(&self) -> Cow<'_, str> { self.as_path().to_string_lossy() } + #[cfg(feature = "alloc")] #[inline] fn as_cow_c_str(&self) -> io::Result<Cow<'_, CStr>> { Ok(Cow::Owned( @@ -716,6 +777,7 @@ impl<'a> Arg for Components<'a> { )) } + #[cfg(feature = "alloc")] #[inline] fn into_c_str<'b>(self) -> io::Result<Cow<'b, CStr>> where @@ -744,11 +806,13 @@ impl<'a> Arg for Iter<'a> { self.as_path().to_str().ok_or(io::Errno::INVAL) } + #[cfg(feature = "alloc")] #[inline] fn to_string_lossy(&self) -> Cow<'_, str> { self.as_path().to_string_lossy() } + #[cfg(feature = "alloc")] #[inline] fn as_cow_c_str(&self) -> io::Result<Cow<'_, CStr>> { Ok(Cow::Owned( @@ -757,6 +821,7 @@ impl<'a> Arg for Iter<'a> { )) } + #[cfg(feature = "alloc")] #[inline] fn into_c_str<'b>(self) -> io::Result<Cow<'b, CStr>> where @@ -784,11 +849,13 @@ impl Arg for &[u8] { str::from_utf8(self).map_err(|_utf8_err| io::Errno::INVAL) } + #[cfg(feature = "alloc")] #[inline] fn to_string_lossy(&self) -> Cow<'_, str> { String::from_utf8_lossy(self) } + #[cfg(feature = "alloc")] #[inline] fn as_cow_c_str(&self) -> io::Result<Cow<'_, CStr>> { Ok(Cow::Owned( @@ -796,6 +863,7 @@ impl Arg for &[u8] { )) } + #[cfg(feature = "alloc")] #[inline] fn into_c_str<'b>(self) -> io::Result<Cow<'b, CStr>> where @@ -816,17 +884,20 @@ impl Arg for &[u8] { } } +#[cfg(feature = "alloc")] impl Arg for &Vec<u8> { #[inline] fn as_str(&self) -> io::Result<&str> { str::from_utf8(self).map_err(|_utf8_err| io::Errno::INVAL) } + #[cfg(feature = "alloc")] #[inline] fn to_string_lossy(&self) -> Cow<'_, str> { String::from_utf8_lossy(self) } + #[cfg(feature = "alloc")] #[inline] fn as_cow_c_str(&self) -> io::Result<Cow<'_, CStr>> { Ok(Cow::Owned( @@ -834,6 +905,7 @@ impl Arg for &Vec<u8> { )) } + #[cfg(feature = "alloc")] #[inline] fn into_c_str<'b>(self) -> io::Result<Cow<'b, CStr>> where @@ -854,17 +926,20 @@ impl Arg for &Vec<u8> { } } +#[cfg(feature = "alloc")] impl Arg for Vec<u8> { #[inline] fn as_str(&self) -> io::Result<&str> { str::from_utf8(self).map_err(|_utf8_err| io::Errno::INVAL) } + #[cfg(feature = "alloc")] #[inline] fn to_string_lossy(&self) -> Cow<'_, str> { String::from_utf8_lossy(self) } + #[cfg(feature = "alloc")] #[inline] fn as_cow_c_str(&self) -> io::Result<Cow<'_, CStr>> { Ok(Cow::Owned( @@ -872,6 +947,7 @@ impl Arg for Vec<u8> { )) } + #[cfg(feature = "alloc")] #[inline] fn into_c_str<'b>(self) -> io::Result<Cow<'b, CStr>> where @@ -899,16 +975,19 @@ impl Arg for DecInt { Ok(self.as_str()) } + #[cfg(feature = "alloc")] #[inline] fn to_string_lossy(&self) -> Cow<'_, str> { Cow::Borrowed(self.as_str()) } + #[cfg(feature = "alloc")] #[inline] fn as_cow_c_str(&self) -> io::Result<Cow<'_, CStr>> { Ok(Cow::Borrowed(self.as_c_str())) } + #[cfg(feature = "alloc")] #[inline] fn into_c_str<'b>(self) -> io::Result<Cow<'b, CStr>> where @@ -961,19 +1040,58 @@ where } // SAFETY: we just wrote the bytes above and they will remain valid for the - // duration of f b/c buf doesn't get dropped until the end of the function. + // duration of `f` b/c buf doesn't get dropped until the end of the + // function. match CStr::from_bytes_with_nul(unsafe { slice::from_raw_parts(buf_ptr, bytes.len() + 1) }) { Ok(s) => f(s), Err(_) => Err(io::Errno::INVAL), } } -/// The slow path which handles any length. In theory OS's only support up -/// to `PATH_MAX`, but we let the OS enforce that. +/// The slow path which handles any length. In theory OS's only support up to +/// `PATH_MAX`, but we let the OS enforce that. +#[allow(unsafe_code, clippy::int_plus_one)] #[cold] fn with_c_str_slow_path<T, F>(bytes: &[u8], f: F) -> io::Result<T> where F: FnOnce(&CStr) -> io::Result<T>, { - f(&CString::new(bytes).map_err(|_cstr_err| io::Errno::INVAL)?) + #[cfg(feature = "alloc")] + { + f(&CString::new(bytes).map_err(|_cstr_err| io::Errno::INVAL)?) + } + + #[cfg(not(feature = "alloc"))] + { + #[cfg(libc)] + const LARGE_PATH_BUFFER_SIZE: usize = libc::PATH_MAX as usize; + #[cfg(linux_raw)] + const LARGE_PATH_BUFFER_SIZE: usize = linux_raw_sys::general::PATH_MAX as usize; + + // Taken from + // <https://github.com/rust-lang/rust/blob/a00f8ba7fcac1b27341679c51bf5a3271fa82df3/library/std/src/sys/common/small_c_string.rs> + let mut buf = MaybeUninit::<[u8; LARGE_PATH_BUFFER_SIZE]>::uninit(); + let buf_ptr = buf.as_mut_ptr().cast::<u8>(); + + // This helps test our safety condition below. + if bytes.len() + 1 > LARGE_PATH_BUFFER_SIZE { + return Err(io::Errno::NAMETOOLONG); + } + + // SAFETY: `bytes.len() < LARGE_PATH_BUFFER_SIZE` which means we have space + // for `bytes.len() + 1` u8s: + unsafe { + ptr::copy_nonoverlapping(bytes.as_ptr(), buf_ptr, bytes.len()); + buf_ptr.add(bytes.len()).write(0); + } + + // SAFETY: we just wrote the bytes above and they will remain valid for the + // duration of `f` b/c buf doesn't get dropped until the end of the + // function. + match CStr::from_bytes_with_nul(unsafe { slice::from_raw_parts(buf_ptr, bytes.len() + 1) }) + { + Ok(s) => f(s), + Err(_) => Err(io::Errno::INVAL), + } + } } diff --git a/vendor/rustix/src/pid.rs b/vendor/rustix/src/pid.rs index 1b1da6521..3911e4c7a 100644 --- a/vendor/rustix/src/pid.rs +++ b/vendor/rustix/src/pid.rs @@ -1,3 +1,5 @@ +//! The `Pid` type. + #![allow(unsafe_code)] use crate::backend::c; @@ -17,21 +19,21 @@ pub struct Pid(NonZeroI32); impl Pid { /// A `Pid` corresponding to the init process (pid 1). - pub const INIT: Self = Self( - // SAFETY: One is non-zero. - unsafe { NonZeroI32::new_unchecked(1) }, - ); + pub const INIT: Self = Self(match NonZeroI32::new(1) { + Some(n) => n, + None => panic!("unreachable"), + }); /// Converts a `RawPid` into a `Pid`. /// /// Returns `Some` for strictly positive `RawPid`s. Otherwise, returns /// `None`. /// - /// This is always safe because a `Pid` is a number without any guarantees - /// for the kernel. Non-child `Pid`s are always racy for any syscalls, - /// but can only cause logic errors. If you want race-free access or - /// control to non-child processes, please consider other mechanisms - /// like [pidfd] on Linux. + /// This is safe because a `Pid` is a number without any guarantees for the + /// kernel. Non-child `Pid`s are always racy for any syscalls, but can only + /// cause logic errors. If you want race-free access to or control of + /// non-child processes, please consider other mechanisms like [pidfd] on + /// Linux. /// /// [pidfd]: https://man7.org/linux/man-pages/man2/pidfd_open.2.html #[inline] diff --git a/vendor/rustix/src/pipe.rs b/vendor/rustix/src/pipe.rs index 1817401c2..2a45b7a9d 100644 --- a/vendor/rustix/src/pipe.rs +++ b/vendor/rustix/src/pipe.rs @@ -106,20 +106,20 @@ pub fn pipe_with(flags: PipeFlags) -> io::Result<(OwnedFd, OwnedFd)> { backend::pipe::syscalls::pipe_with(flags) } -/// `splice(fd_in, off_in, fd_out, off_out, len, flags)`—Transfer data between -/// a file and a pipe. +/// `splice(fd_in, off_in, fd_out, off_out, len, flags)`—Transfer data +/// between a file and a pipe. /// /// This function transfers up to `len` bytes of data from the file descriptor /// `fd_in` to the file descriptor `fd_out`, where one of the file descriptors /// must refer to a pipe. /// /// `off_*` must be `None` if the corresponding fd refers to a pipe. -/// Otherwise its value points to the starting offset to the file, -/// from which the data is read/written. -/// on success the number of bytes read/written is added to the offset. +/// Otherwise its value points to the starting offset to the file, from which +/// the data is read/written. On success, the number of bytes read/written is +/// added to the offset. /// -/// passing `None` causes the read/write to start from the file offset, -/// and the file offset is adjusted appropriately. +/// Passing `None` causes the read/write to start from the file offset, and the +/// file offset is adjusted appropriately. /// /// # References /// - [Linux] @@ -165,7 +165,7 @@ pub fn splice<FdIn: AsFd, FdOut: AsFd>( #[inline] pub unsafe fn vmsplice<PipeFd: AsFd>( fd: PipeFd, - bufs: &[IoSliceRaw], + bufs: &[IoSliceRaw<'_>], flags: SpliceFlags, ) -> io::Result<usize> { backend::pipe::syscalls::vmsplice(fd.as_fd(), bufs, flags) @@ -192,7 +192,7 @@ pub fn tee<FdIn: AsFd, FdOut: AsFd>( backend::pipe::syscalls::tee(fd_in.as_fd(), fd_out.as_fd(), len, flags) } -/// `ioctl(fd, F_GETPIPE_SZ)`—Return the buffer capacity of a pipe. +/// `fnctl(fd, F_GETPIPE_SZ)`—Return the buffer capacity of a pipe. /// /// # References /// - [Linux] @@ -204,7 +204,7 @@ pub fn fcntl_getpipe_size<Fd: AsFd>(fd: Fd) -> io::Result<usize> { backend::pipe::syscalls::fcntl_getpipe_sz(fd.as_fd()) } -/// `ioctl(fd, F_SETPIPE_SZ)`—Set the buffer capacity of a pipe. +/// `fnctl(fd, F_SETPIPE_SZ)`—Set the buffer capacity of a pipe. /// /// # References /// - [Linux] diff --git a/vendor/rustix/src/prctl.rs b/vendor/rustix/src/prctl.rs index 49cb062d6..6aedf3018 100644 --- a/vendor/rustix/src/prctl.rs +++ b/vendor/rustix/src/prctl.rs @@ -25,6 +25,9 @@ bitflags! { const DATA_AUTHENTICATION_KEY_B = linux_raw_sys::prctl::PR_PAC_APDBKEY; /// `PR_PAC_APGAKEY`—Generic authentication `A` key. const GENERIC_AUTHENTICATION_KEY_A = linux_raw_sys::prctl::PR_PAC_APGAKEY; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } diff --git a/vendor/rustix/src/process/chdir.rs b/vendor/rustix/src/process/chdir.rs index 0da0b5c2e..b110afef8 100644 --- a/vendor/rustix/src/process/chdir.rs +++ b/vendor/rustix/src/process/chdir.rs @@ -1,11 +1,13 @@ #[cfg(not(target_os = "fuchsia"))] use crate::backend::fd::AsFd; +#[cfg(feature = "fs")] +use crate::path; #[cfg(any(feature = "fs", not(target_os = "fuchsia")))] use crate::{backend, io}; -#[cfg(feature = "fs")] +#[cfg(all(feature = "alloc", feature = "fs"))] use { crate::ffi::{CStr, CString}, - crate::path::{self, SMALL_PATH_BUFFER_SIZE}, + crate::path::SMALL_PATH_BUFFER_SIZE, alloc::vec::Vec, }; @@ -48,7 +50,7 @@ pub fn fchdir<Fd: AsFd>(fd: Fd) -> io::Result<()> { /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getcwd.html /// [Linux]: https://man7.org/linux/man-pages/man3/getcwd.3.html -#[cfg(feature = "fs")] +#[cfg(all(feature = "alloc", feature = "fs"))] #[cfg(not(target_os = "wasi"))] #[cfg_attr(doc_cfg, doc(cfg(feature = "fs")))] #[inline] @@ -56,7 +58,7 @@ pub fn getcwd<B: Into<Vec<u8>>>(reuse: B) -> io::Result<CString> { _getcwd(reuse.into()) } -#[cfg(feature = "fs")] +#[cfg(all(feature = "alloc", feature = "fs"))] #[allow(unsafe_code)] fn _getcwd(mut buffer: Vec<u8>) -> io::Result<CString> { buffer.clear(); diff --git a/vendor/rustix/src/process/exit.rs b/vendor/rustix/src/process/exit.rs index 5533dbabb..95b78c4a1 100644 --- a/vendor/rustix/src/process/exit.rs +++ b/vendor/rustix/src/process/exit.rs @@ -10,7 +10,7 @@ use crate::backend; /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/stdlib.h.html /// [Linux]: https://man7.org/linux/man-pages/man3/exit.3.html -pub const EXIT_SUCCESS: i32 = backend::process::types::EXIT_SUCCESS; +pub const EXIT_SUCCESS: i32 = backend::c::EXIT_SUCCESS; /// `EXIT_FAILURE` for use with [`exit`]. /// @@ -22,7 +22,7 @@ pub const EXIT_SUCCESS: i32 = backend::process::types::EXIT_SUCCESS; /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/stdlib.h.html /// [Linux]: https://man7.org/linux/man-pages/man3/exit.3.html -pub const EXIT_FAILURE: i32 = backend::process::types::EXIT_FAILURE; +pub const EXIT_FAILURE: i32 = backend::c::EXIT_FAILURE; /// The exit status used by a process terminated with a [`Signal::Abort`] /// signal. @@ -33,4 +33,4 @@ pub const EXIT_FAILURE: i32 = backend::process::types::EXIT_FAILURE; /// [Linux]: https://tldp.org/LDP/abs/html/exitcodes.html /// [`Signal::Abort`]: crate::process::Signal::Abort #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] -pub const EXIT_SIGNALED_SIGABRT: i32 = backend::process::types::EXIT_SIGNALED_SIGABRT; +pub const EXIT_SIGNALED_SIGABRT: i32 = backend::c::EXIT_SIGNALED_SIGABRT; diff --git a/vendor/rustix/src/process/id.rs b/vendor/rustix/src/process/id.rs index 4cacf1ab0..4ed33a6c8 100644 --- a/vendor/rustix/src/process/id.rs +++ b/vendor/rustix/src/process/id.rs @@ -8,6 +8,7 @@ #![allow(unsafe_code)] use crate::{backend, io}; +#[cfg(feature = "alloc")] use alloc::vec::Vec; #[cfg(linux_kernel)] use backend::process::types::RawCpuid; @@ -208,12 +209,11 @@ pub fn setsid() -> io::Result<Pid> { /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getgroups.html /// [Linux]: https://man7.org/linux/man-pages/man2/getgroups.2.html +#[cfg(feature = "alloc")] pub fn getgroups() -> io::Result<Vec<Gid>> { - let mut buffer = Vec::new(); - // This code would benefit from having a better way to read into // uninitialized memory, but that requires `unsafe`. - buffer.reserve(8); + let mut buffer = Vec::with_capacity(8); buffer.resize(buffer.capacity(), Gid::ROOT); loop { diff --git a/vendor/rustix/src/process/ioctl.rs b/vendor/rustix/src/process/ioctl.rs index cde6b5b3c..3c9d90255 100644 --- a/vendor/rustix/src/process/ioctl.rs +++ b/vendor/rustix/src/process/ioctl.rs @@ -1,4 +1,13 @@ -use crate::{backend, io}; +//! Process-oriented `ioctl`s. +//! +//! # Safety +//! +//! This module invokes `ioctl`s. + +#![allow(unsafe_code)] + +use crate::{backend, io, ioctl}; +use backend::c; use backend::fd::AsFd; /// `ioctl(fd, TIOCSCTTY, 0)`—Sets the controlling terminal for the processs. @@ -17,5 +26,27 @@ use backend::fd::AsFd; #[inline] #[doc(alias = "TIOCSCTTY")] pub fn ioctl_tiocsctty<Fd: AsFd>(fd: Fd) -> io::Result<()> { - backend::process::syscalls::ioctl_tiocsctty(fd.as_fd()) + unsafe { ioctl::ioctl(fd, Tiocsctty) } +} + +#[cfg(not(any(windows, target_os = "aix", target_os = "redox", target_os = "wasi")))] +struct Tiocsctty; + +#[cfg(not(any(windows, target_os = "aix", target_os = "redox", target_os = "wasi")))] +unsafe impl ioctl::Ioctl for Tiocsctty { + type Output = (); + + const IS_MUTATING: bool = false; + const OPCODE: ioctl::Opcode = ioctl::Opcode::old(c::TIOCSCTTY as ioctl::RawOpcode); + + fn as_ptr(&mut self) -> *mut c::c_void { + (&0u32) as *const u32 as *mut c::c_void + } + + unsafe fn output_from_ptr( + _: ioctl::IoctlOutput, + _: *mut c::c_void, + ) -> io::Result<Self::Output> { + Ok(()) + } } diff --git a/vendor/rustix/src/process/membarrier.rs b/vendor/rustix/src/process/membarrier.rs index df9f1a44c..9c42bbd85 100644 --- a/vendor/rustix/src/process/membarrier.rs +++ b/vendor/rustix/src/process/membarrier.rs @@ -14,26 +14,29 @@ bitflags::bitflags! { #[repr(transparent)] #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct MembarrierQuery: u32 { - /// `MEMBARRIER_CMD_GLOBAL` (also known as `MEMBARRIER_CMD_SHARED`) - #[doc(alias = "SHARED")] - #[doc(alias = "MEMBARRIER_CMD_SHARED")] - const GLOBAL = MembarrierCommand::Global as _; - /// `MEMBARRIER_CMD_GLOBAL_EXPEDITED` - const GLOBAL_EXPEDITED = MembarrierCommand::GlobalExpedited as _; - /// `MEMBARRIER_CMD_REGISTER_GLOBAL_EXPEDITED` - const REGISTER_GLOBAL_EXPEDITED = MembarrierCommand::RegisterGlobalExpedited as _; - /// `MEMBARRIER_CMD_PRIVATE_EXPEDITED` - const PRIVATE_EXPEDITED = MembarrierCommand::PrivateExpedited as _; - /// `MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED` - const REGISTER_PRIVATE_EXPEDITED = MembarrierCommand::RegisterPrivateExpedited as _; - /// `MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE` - const PRIVATE_EXPEDITED_SYNC_CORE = MembarrierCommand::PrivateExpeditedSyncCore as _; - /// `MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_SYNC_CORE` - const REGISTER_PRIVATE_EXPEDITED_SYNC_CORE = MembarrierCommand::RegisterPrivateExpeditedSyncCore as _; - /// `MEMBARRIER_CMD_PRIVATE_EXPEDITED_RSEQ` (since Linux 5.10) - const PRIVATE_EXPEDITED_RSEQ = MembarrierCommand::PrivateExpeditedRseq as _; - /// `MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_RSEQ` (since Linux 5.10) - const REGISTER_PRIVATE_EXPEDITED_RSEQ = MembarrierCommand::RegisterPrivateExpeditedRseq as _; + /// `MEMBARRIER_CMD_GLOBAL` (also known as `MEMBARRIER_CMD_SHARED`) + #[doc(alias = "SHARED")] + #[doc(alias = "MEMBARRIER_CMD_SHARED")] + const GLOBAL = MembarrierCommand::Global as _; + /// `MEMBARRIER_CMD_GLOBAL_EXPEDITED` + const GLOBAL_EXPEDITED = MembarrierCommand::GlobalExpedited as _; + /// `MEMBARRIER_CMD_REGISTER_GLOBAL_EXPEDITED` + const REGISTER_GLOBAL_EXPEDITED = MembarrierCommand::RegisterGlobalExpedited as _; + /// `MEMBARRIER_CMD_PRIVATE_EXPEDITED` + const PRIVATE_EXPEDITED = MembarrierCommand::PrivateExpedited as _; + /// `MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED` + const REGISTER_PRIVATE_EXPEDITED = MembarrierCommand::RegisterPrivateExpedited as _; + /// `MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE` + const PRIVATE_EXPEDITED_SYNC_CORE = MembarrierCommand::PrivateExpeditedSyncCore as _; + /// `MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_SYNC_CORE` + const REGISTER_PRIVATE_EXPEDITED_SYNC_CORE = MembarrierCommand::RegisterPrivateExpeditedSyncCore as _; + /// `MEMBARRIER_CMD_PRIVATE_EXPEDITED_RSEQ` (since Linux 5.10) + const PRIVATE_EXPEDITED_RSEQ = MembarrierCommand::PrivateExpeditedRseq as _; + /// `MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_RSEQ` (since Linux 5.10) + const REGISTER_PRIVATE_EXPEDITED_RSEQ = MembarrierCommand::RegisterPrivateExpeditedRseq as _; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -51,9 +54,9 @@ impl MembarrierQuery { /// `membarrier(MEMBARRIER_CMD_QUERY, 0, 0)`—Query the supported `membarrier` /// commands. /// -/// This function doesn't return a `Result` because it always succeeds; if -/// the underlying OS doesn't support the `membarrier` syscall, it returns -/// an empty `MembarrierQuery` value. +/// This function doesn't return a `Result` because it always succeeds; if the +/// underlying OS doesn't support the `membarrier` syscall, it returns an empty +/// `MembarrierQuery` value. /// /// # References /// - [Linux] diff --git a/vendor/rustix/src/process/mod.rs b/vendor/rustix/src/process/mod.rs index 9c62f127e..55eed1ac8 100644 --- a/vendor/rustix/src/process/mod.rs +++ b/vendor/rustix/src/process/mod.rs @@ -7,7 +7,7 @@ mod chroot; mod exit; #[cfg(not(target_os = "wasi"))] // WASI doesn't have get[gpu]id. mod id; -#[cfg(not(target_os = "espidf"))] +#[cfg(not(any(target_os = "aix", target_os = "espidf")))] mod ioctl; #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] mod kill; @@ -45,7 +45,7 @@ pub use chroot::*; pub use exit::*; #[cfg(not(target_os = "wasi"))] pub use id::*; -#[cfg(not(target_os = "espidf"))] +#[cfg(not(any(target_os = "aix", target_os = "espidf")))] pub use ioctl::*; #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] pub use kill::*; diff --git a/vendor/rustix/src/process/pidfd.rs b/vendor/rustix/src/process/pidfd.rs index fb8298117..0548055fc 100644 --- a/vendor/rustix/src/process/pidfd.rs +++ b/vendor/rustix/src/process/pidfd.rs @@ -11,11 +11,14 @@ bitflags::bitflags! { pub struct PidfdFlags: backend::c::c_uint { /// `PIDFD_NONBLOCK`. const NONBLOCK = backend::c::PIDFD_NONBLOCK; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } -/// `syscall(SYS_pidfd_open, pid, flags)`—Creates a file descriptor for -/// a process. +/// `syscall(SYS_pidfd_open, pid, flags)`—Creates a file descriptor for a +/// process. /// /// # References /// - [Linux] diff --git a/vendor/rustix/src/process/pidfd_getfd.rs b/vendor/rustix/src/process/pidfd_getfd.rs index 7234810c2..27d4f1986 100644 --- a/vendor/rustix/src/process/pidfd_getfd.rs +++ b/vendor/rustix/src/process/pidfd_getfd.rs @@ -1,3 +1,5 @@ +//! The [`pidfd_getfd`] function and supporting types. + #![allow(unsafe_code)] use crate::fd::OwnedFd; use crate::{backend, io}; @@ -15,11 +17,14 @@ bitflags::bitflags! { /// All flags are reserved for future use. #[repr(transparent)] #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] - pub struct PidfdGetfdFlags: backend::c::c_uint {} + pub struct PidfdGetfdFlags: backend::c::c_uint { + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; + } } /// `syscall(SYS_pidfd_getfd, pidfd, flags)`—Obtain a duplicate of another -/// process's file descriptor. +/// process' file descriptor. /// /// # References /// - [Linux] diff --git a/vendor/rustix/src/process/prctl.rs b/vendor/rustix/src/process/prctl.rs index d79657e98..59be7020f 100644 --- a/vendor/rustix/src/process/prctl.rs +++ b/vendor/rustix/src/process/prctl.rs @@ -96,7 +96,7 @@ impl TryFrom<i32> for DumpableBehavior { } } -/// Get the current state of the calling process's `dumpable` attribute. +/// Get the current state of the calling process' `dumpable` attribute. /// /// # References /// - [`prctl(PR_GET_DUMPABLE,...)`] @@ -148,6 +148,9 @@ bitflags! { /// Generate a [`Signal::Bus`] signal on unaligned user access. #[doc(alias = "PR_UNALIGN_SIGBUS")] const SIGBUS = 2; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -670,7 +673,7 @@ pub unsafe fn set_virtual_memory_map_address( #[inline] #[doc(alias = "PR_SET_MM")] #[doc(alias = "PR_SET_MM_EXE_FILE")] -pub fn set_executable_file(fd: BorrowedFd) -> io::Result<()> { +pub fn set_executable_file(fd: BorrowedFd<'_>) -> io::Result<()> { let fd = usize::try_from(fd.as_raw_fd()).map_err(|_r| io::Errno::RANGE)?; unsafe { prctl_3args(PR_SET_MM, PR_SET_MM_EXE_FILE as *mut _, fd as *mut _) }.map(|_r| ()) } diff --git a/vendor/rustix/src/process/procctl.rs b/vendor/rustix/src/process/procctl.rs index 8da53d383..5225f16f7 100644 --- a/vendor/rustix/src/process/procctl.rs +++ b/vendor/rustix/src/process/procctl.rs @@ -229,6 +229,9 @@ bitflags! { const OWNED = 1; /// The process is the root of the reaper tree (pid 1). const REALINIT = 2; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } diff --git a/vendor/rustix/src/process/wait.rs b/vendor/rustix/src/process/wait.rs index 72b37d6d4..b43bd03d6 100644 --- a/vendor/rustix/src/process/wait.rs +++ b/vendor/rustix/src/process/wait.rs @@ -22,6 +22,9 @@ bitflags! { /// Return if a stopped child has been resumed by delivery of /// [`Signal::Cont`]. const CONTINUED = bitcast!(backend::process::wait::WCONTINUED); + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -42,6 +45,9 @@ bitflags! { const NOWAIT = bitcast!(backend::process::wait::WNOWAIT); /// Wait for processes that have been stopped. const STOPPED = bitcast!(backend::process::wait::WSTOPPED); + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -170,7 +176,7 @@ impl WaitidStatus { /// Returns the number of the signal that stopped the process, /// if the process was stopped by a signal. #[inline] - #[cfg(not(any(target_os = "netbsd", target_os = "fuchsia", target_os = "emscripten")))] + #[cfg(not(any(target_os = "emscripten", target_os = "fuchsia", target_os = "netbsd")))] pub fn stopping_signal(&self) -> Option<u32> { if self.stopped() { Some(self.si_status() as _) @@ -182,7 +188,7 @@ impl WaitidStatus { /// Returns the number of the signal that trapped the process, /// if the process was trapped by a signal. #[inline] - #[cfg(not(any(target_os = "netbsd", target_os = "fuchsia", target_os = "emscripten")))] + #[cfg(not(any(target_os = "emscripten", target_os = "fuchsia", target_os = "netbsd")))] pub fn trapping_signal(&self) -> Option<u32> { if self.trapped() { Some(self.si_status() as _) @@ -194,7 +200,7 @@ impl WaitidStatus { /// Returns the exit status number returned by the process, /// if it exited normally. #[inline] - #[cfg(not(any(target_os = "netbsd", target_os = "fuchsia", target_os = "emscripten")))] + #[cfg(not(any(target_os = "emscripten", target_os = "fuchsia", target_os = "netbsd")))] pub fn exit_status(&self) -> Option<u32> { if self.exited() { Some(self.si_status() as _) @@ -206,7 +212,7 @@ impl WaitidStatus { /// Returns the number of the signal that terminated the process, /// if the process was terminated by a signal. #[inline] - #[cfg(not(any(target_os = "netbsd", target_os = "fuchsia", target_os = "emscripten")))] + #[cfg(not(any(target_os = "emscripten", target_os = "fuchsia", target_os = "netbsd")))] pub fn terminating_signal(&self) -> Option<u32> { if self.killed() || self.dumped() { Some(self.si_status() as _) @@ -231,7 +237,7 @@ impl WaitidStatus { self.0.si_code } - #[cfg(not(any(target_os = "netbsd", target_os = "fuchsia", target_os = "emscripten")))] + #[cfg(not(any(target_os = "emscripten", target_os = "fuchsia", target_os = "netbsd")))] #[allow(unsafe_code)] fn si_status(&self) -> backend::c::c_int { // SAFETY: POSIX [specifies] that the `siginfo_t` returned by a diff --git a/vendor/rustix/src/procfs.rs b/vendor/rustix/src/procfs.rs index 010b93126..14ad631a7 100644 --- a/vendor/rustix/src/procfs.rs +++ b/vendor/rustix/src/procfs.rs @@ -20,9 +20,8 @@ use crate::backend::pid::syscalls::getpid; use crate::fd::{AsFd, BorrowedFd, OwnedFd}; -use crate::ffi::CStr; use crate::fs::{ - fstat, fstatfs, major, openat, renameat, Dir, FileType, Mode, OFlags, Stat, CWD, + fstat, fstatfs, major, openat, renameat, FileType, FsWord, Mode, OFlags, Stat, CWD, PROC_SUPER_MAGIC, }; use crate::io; @@ -31,6 +30,8 @@ use crate::path::DecInt; use core::lazy::OnceCell; #[cfg(not(feature = "rustc-dep-of-std"))] use once_cell::sync::OnceCell; +#[cfg(feature = "alloc")] +use {crate::ffi::CStr, crate::fs::Dir}; /// Linux's procfs always uses inode 1 for its root directory. const PROC_ROOT_INO: u64 = 1; @@ -41,6 +42,7 @@ enum Kind { Proc, Pid, Fd, + #[cfg(feature = "alloc")] File, } @@ -67,6 +69,7 @@ fn check_proc_entry_with_stat( match kind { Kind::Proc => check_proc_root(entry, &entry_stat)?, Kind::Pid | Kind::Fd => check_proc_subdir(entry, &entry_stat, proc_stat)?, + #[cfg(feature = "alloc")] Kind::File => check_proc_file(&entry_stat, proc_stat)?, } @@ -94,6 +97,7 @@ fn check_proc_entry_with_stat( return Err(io::Errno::NOTSUP); } } + #[cfg(feature = "alloc")] Kind::File => { // Check that files in procfs don't have extraneous hard links to // them (which might indicate hard links to other things). @@ -149,6 +153,7 @@ fn check_proc_subdir( Ok(()) } +#[cfg(feature = "alloc")] fn check_proc_file(stat: &Stat, proc_stat: Option<&Stat>) -> io::Result<()> { // Check that we have a regular file. if FileType::from_raw_mode(stat.st_mode) != FileType::RegularFile { @@ -178,7 +183,7 @@ fn check_proc_nonroot(stat: &Stat, proc_stat: Option<&Stat>) -> io::Result<()> { fn check_procfs(file: BorrowedFd<'_>) -> io::Result<()> { let statfs = fstatfs(file)?; let f_type = statfs.f_type; - if f_type != PROC_SUPER_MAGIC.into() { + if f_type != FsWord::from(PROC_SUPER_MAGIC) { return Err(io::Errno::NOTSUP); } @@ -309,6 +314,7 @@ fn new_static_fd(fd: OwnedFd, stat: Stat) -> (OwnedFd, Stat) { /// - [Linux] /// /// [Linux]: https://man7.org/linux/man-pages/man5/proc.5.html +#[cfg(feature = "alloc")] fn proc_self_fdinfo() -> io::Result<(BorrowedFd<'static>, &'static Stat)> { static PROC_SELF_FDINFO: StaticFd = StaticFd::new(); @@ -338,12 +344,14 @@ fn proc_self_fdinfo() -> io::Result<(BorrowedFd<'static>, &'static Stat)> { /// - [Linux] /// /// [Linux]: https://man7.org/linux/man-pages/man5/proc.5.html +#[cfg(feature = "alloc")] #[inline] #[cfg_attr(doc_cfg, doc(cfg(feature = "procfs")))] pub fn proc_self_fdinfo_fd<Fd: AsFd>(fd: Fd) -> io::Result<OwnedFd> { _proc_self_fdinfo(fd.as_fd()) } +#[cfg(feature = "alloc")] fn _proc_self_fdinfo(fd: BorrowedFd<'_>) -> io::Result<OwnedFd> { let (proc_self_fdinfo, proc_self_fdinfo_stat) = proc_self_fdinfo()?; let fd_str = DecInt::from_fd(fd); @@ -361,6 +369,7 @@ fn _proc_self_fdinfo(fd: BorrowedFd<'_>) -> io::Result<OwnedFd> { /// /// [Linux]: https://man7.org/linux/man-pages/man5/proc.5.html /// [Linux pagemap]: https://www.kernel.org/doc/Documentation/vm/pagemap.txt +#[cfg(feature = "alloc")] #[inline] #[cfg_attr(doc_cfg, doc(cfg(feature = "procfs")))] pub fn proc_self_pagemap() -> io::Result<OwnedFd> { @@ -376,6 +385,7 @@ pub fn proc_self_pagemap() -> io::Result<OwnedFd> { /// - [Linux] /// /// [Linux]: https://man7.org/linux/man-pages/man5/proc.5.html +#[cfg(feature = "alloc")] #[inline] #[cfg_attr(doc_cfg, doc(cfg(feature = "procfs")))] pub fn proc_self_maps() -> io::Result<OwnedFd> { @@ -391,6 +401,7 @@ pub fn proc_self_maps() -> io::Result<OwnedFd> { /// - [Linux] /// /// [Linux]: https://man7.org/linux/man-pages/man5/proc.5.html +#[cfg(feature = "alloc")] #[inline] #[cfg_attr(doc_cfg, doc(cfg(feature = "procfs")))] pub fn proc_self_status() -> io::Result<OwnedFd> { @@ -398,13 +409,15 @@ pub fn proc_self_status() -> io::Result<OwnedFd> { } /// Open a file under `/proc/self`. +#[cfg(feature = "alloc")] fn proc_self_file(name: &CStr) -> io::Result<OwnedFd> { let (proc_self, proc_self_stat) = proc_self()?; open_and_check_file(proc_self, proc_self_stat, name) } /// Open a procfs file within in `dir` and check it for bind mounts. -fn open_and_check_file(dir: BorrowedFd, dir_stat: &Stat, name: &CStr) -> io::Result<OwnedFd> { +#[cfg(feature = "alloc")] +fn open_and_check_file(dir: BorrowedFd<'_>, dir_stat: &Stat, name: &CStr) -> io::Result<OwnedFd> { let (_, proc_stat) = proc()?; // Don't use `NOATIME`, because it [requires us to own the file], and when @@ -418,10 +431,10 @@ fn open_and_check_file(dir: BorrowedFd, dir_stat: &Stat, name: &CStr) -> io::Res let file_stat = fstat(&file)?; // `is_mountpoint` only works on directory mount points, not file mount - // points. To detect file mount points, scan the parent directory to see - // if we can find a regular file with an inode and name that matches the - // file we just opened. If we can't find it, there could be a file bind - // mount on top of the file we want. + // points. To detect file mount points, scan the parent directory to see if + // we can find a regular file with an inode and name that matches the file + // we just opened. If we can't find it, there could be a file bind mount on + // top of the file we want. // // As we scan, we also check for ".", to make sure it's the same directory // as our original directory, to detect mount points, since diff --git a/vendor/rustix/src/pty.rs b/vendor/rustix/src/pty.rs index 5040ca2c1..a63fbfeef 100644 --- a/vendor/rustix/src/pty.rs +++ b/vendor/rustix/src/pty.rs @@ -5,13 +5,21 @@ //! //! [rustix-openpty crate]: https://crates.io/crates/rustix-openpty +#![allow(unsafe_code)] + use crate::backend::c; use crate::fd::{AsFd, OwnedFd}; use crate::fs::OFlags; use crate::{backend, io}; -#[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::CString, alloc::vec::Vec}; +#[cfg(target_os = "linux")] +use crate::{fd::FromRawFd, ioctl}; + bitflags::bitflags! { /// `O_*` flags for use with [`openpt`] and [`ioctl_tiocgptpeer`]. /// @@ -32,6 +40,9 @@ bitflags::bitflags! { /// rustix supports it on Linux, and FreeBSD and NetBSD support it. #[cfg(any(linux_kernel, target_os = "freebsd", target_os = "netbsd"))] const CLOEXEC = c::O_CLOEXEC as c::c_uint; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -102,9 +113,12 @@ pub fn openpt(flags: OpenptFlags) -> io::Result<OwnedFd> { /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/ptsname.html /// [Linux]: https://man7.org/linux/man-pages/man3/ptsname.3.html /// [glibc]: https://www.gnu.org/software/libc/manual/html_node/Allocation.html#index-ptsname +#[cfg(all( + feature = "alloc", + any(apple, linux_like, target_os = "freebsd", target_os = "fuchsia") +))] #[inline] #[doc(alias = "ptsname_r")] -#[cfg(any(apple, linux_like, target_os = "freebsd", target_os = "fuchsia"))] pub fn ptsname<Fd: AsFd, B: Into<Vec<u8>>>(fd: Fd, reuse: B) -> io::Result<CString> { backend::pty::syscalls::ptsname(fd.as_fd(), reuse.into()) } @@ -166,5 +180,27 @@ pub fn grantpt<Fd: AsFd>(fd: Fd) -> io::Result<()> { #[cfg(target_os = "linux")] #[inline] pub fn ioctl_tiocgptpeer<Fd: AsFd>(fd: Fd, flags: OpenptFlags) -> io::Result<OwnedFd> { - backend::pty::syscalls::ioctl_tiocgptpeer(fd.as_fd(), flags) + unsafe { ioctl::ioctl(fd, Tiocgptpeer(flags)) } +} + +#[cfg(target_os = "linux")] +struct Tiocgptpeer(OpenptFlags); + +#[cfg(target_os = "linux")] +unsafe impl ioctl::Ioctl for Tiocgptpeer { + type Output = OwnedFd; + + const IS_MUTATING: bool = false; + const OPCODE: ioctl::Opcode = ioctl::Opcode::old(c::TIOCGPTPEER as ioctl::RawOpcode); + + fn as_ptr(&mut self) -> *mut c::c_void { + self.0.bits() as *mut c::c_void + } + + unsafe fn output_from_ptr( + ret: ioctl::IoctlOutput, + _arg: *mut c::c_void, + ) -> io::Result<Self::Output> { + Ok(OwnedFd::from_raw_fd(ret)) + } } diff --git a/vendor/rustix/src/rand/getrandom.rs b/vendor/rustix/src/rand/getrandom.rs index c66e50d56..3fed0dd08 100644 --- a/vendor/rustix/src/rand/getrandom.rs +++ b/vendor/rustix/src/rand/getrandom.rs @@ -1,6 +1,5 @@ use crate::{backend, io}; -/// `GRND_*` constants for use with [`getrandom`]. pub use backend::rand::types::GetRandomFlags; /// `getrandom(buf, flags)`—Reads a sequence of random bytes. diff --git a/vendor/rustix/src/runtime.rs b/vendor/rustix/src/runtime.rs index 9c850d5e3..2cb0eba54 100644 --- a/vendor/rustix/src/runtime.rs +++ b/vendor/rustix/src/runtime.rs @@ -1,9 +1,12 @@ -//! Low-level implementation details for libc-like runtime libraries such as -//! [origin]. +//! Experimental low-level implementation details for libc-like runtime +//! libraries such as [Origin]. //! //! Do not use the functions in this module unless you've read all of their -//! code, *and* you know all the relevant internal implementation details of -//! any libc in the process they'll be used. +//! code. They don't always behave the same way as functions with similar names +//! in `libc`. Sometimes information about the differences is included in the +//! Linux documentation under "C library/kernel differences" sections. And, if +//! there is a libc in the process, these functions may have surprising +//! interactions with it. //! //! These functions are for implementing thread-local storage (TLS), managing //! threads, loaded libraries, and other process-wide resources. Most of @@ -14,7 +17,7 @@ //! The API for these functions is not stable, and this module is //! `doc(hidden)`. //! -//! [origin]: https://github.com/sunfishcode/mustang/tree/main/origin +//! [Origin]: https://github.com/sunfishcode/origin#readme //! //! # Safety //! @@ -34,13 +37,14 @@ use crate::io; #[cfg(linux_raw)] use crate::pid::Pid; #[cfg(linux_raw)] -use crate::signal::Signal; -#[cfg(linux_raw)] #[cfg(feature = "fs")] use backend::fd::AsFd; #[cfg(linux_raw)] use core::ffi::c_void; +#[cfg(linux_raw)] +pub use crate::signal::Signal; + /// `sigaction` #[cfg(linux_raw)] pub type Sigaction = linux_raw_sys::general::kernel_sigaction; @@ -142,7 +146,7 @@ pub unsafe fn exit_thread(status: i32) -> ! { /// /// This is equivalent to `_exit` and `_Exit` in libc. /// -/// This does not all any `__cxa_atexit`, `atexit`, or any other destructors. +/// This does not call any `__cxa_atexit`, `atexit`, or any other destructors. /// Most programs should use [`std::process::exit`] instead of calling this /// directly. /// @@ -161,25 +165,70 @@ pub fn exit_group(status: i32) -> ! { backend::runtime::syscalls::exit_group(status) } +/// `EXIT_SUCCESS` for use with [`exit_group`]. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/stdlib.h.html +/// [Linux]: https://man7.org/linux/man-pages/man3/exit.3.html +pub const EXIT_SUCCESS: i32 = backend::c::EXIT_SUCCESS; + +/// `EXIT_FAILURE` for use with [`exit_group`]. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/stdlib.h.html +/// [Linux]: https://man7.org/linux/man-pages/man3/exit.3.html +pub const EXIT_FAILURE: i32 = backend::c::EXIT_FAILURE; + /// Return fields from the main executable segment headers ("phdrs") relevant /// to initializing TLS provided to the program at startup. +/// +/// `addr` will always be non-null, even when the TLS data is absent, ao that +/// the `addr` and `file_size` parameters are suitable for creating a slice +/// with `slice::from_raw_parts`. #[inline] pub fn startup_tls_info() -> StartupTlsInfo { backend::runtime::tls::startup_tls_info() } -/// `(getauxval(AT_PHDR), getauxval(AT_PHNUM))`—Returns the address and -/// number of ELF segment headers for the main executable. +/// `(getauxval(AT_PHDR), getauxval(AT_PHENT), getauxval(AT_PHNUM))`—Returns +/// the address, ELF segment header size, and number of ELF segment headers for +/// the main executable. /// /// # References /// - [Linux] /// /// [Linux]: https://man7.org/linux/man-pages/man3/getauxval.3.html #[inline] -pub fn exe_phdrs() -> (*const c_void, usize) { +pub fn exe_phdrs() -> (*const c_void, usize, usize) { backend::param::auxv::exe_phdrs() } +/// `getauxval(AT_ENTRY)`—Returns the address of the program entrypoint. +/// +/// Most code interested in the program entrypoint address should instead use a +/// symbol reference to `_start`. That will be properly PC-relative or +/// relocated if needed, and will come with appropriate pointer type and +/// pointer provenance. +/// +/// This function is intended only for use in code that implements those +/// relocations, to compute the ASLR offset. It has type `usize`, so it doesn't +/// carry any provenance, and it shouldn't be used to dereference memory. +/// +/// # References +/// - [Linux] +/// +/// [Linux]: https://man7.org/linux/man-pages/man3/getauxval.3.html +#[inline] +pub fn entry() -> usize { + backend::param::auxv::entry() +} + #[cfg(linux_raw)] pub use backend::runtime::tls::StartupTlsInfo; @@ -224,13 +273,19 @@ pub use backend::runtime::tls::StartupTlsInfo; /// that could cause undefined behavior. The extent to which this also /// applies to Rust functions is unclear at this time. /// +/// - And more. +/// /// # Safety /// /// The child must avoid accessing any memory shared with the parent in a /// way that invokes undefined behavior. It must avoid accessing any threading /// runtime functions in a way that invokes undefined behavior. And it must /// avoid invoking any undefined behavior through any function that is not -/// guaranteed to be async-signal-safe. +/// guaranteed to be async-signal-safe. But, what does async-signal-safe even +/// mean in a Rust program? This documentation does not have all the answers. +/// +/// So you're on your own. And on top of all the troubles with `fork` in +/// general, this wrapper implementation is highly experimental. /// /// # References /// - [POSIX] diff --git a/vendor/rustix/src/system.rs b/vendor/rustix/src/system.rs index 9346f5560..1f7f39ce4 100644 --- a/vendor/rustix/src/system.rs +++ b/vendor/rustix/src/system.rs @@ -102,25 +102,25 @@ impl fmt::Debug for Uname { { write!( fmt, - "{} {} {} {} {}", - self.sysname().to_string_lossy(), - self.nodename().to_string_lossy(), - self.release().to_string_lossy(), - self.version().to_string_lossy(), - self.machine().to_string_lossy(), + "{:?} {:?} {:?} {:?} {:?}", + self.sysname(), + self.nodename(), + self.release(), + self.version(), + self.machine(), ) } #[cfg(linux_kernel)] { write!( fmt, - "{} {} {} {} {} {}", - self.sysname().to_string_lossy(), - self.nodename().to_string_lossy(), - self.release().to_string_lossy(), - self.version().to_string_lossy(), - self.machine().to_string_lossy(), - self.domainname().to_string_lossy(), + "{:?} {:?} {:?} {:?} {:?} {:?}", + self.sysname(), + self.nodename(), + self.release(), + self.version(), + self.machine(), + self.domainname(), ) } } diff --git a/vendor/rustix/src/termios/ioctl.rs b/vendor/rustix/src/termios/ioctl.rs index 1c60cb9a4..620ae4c71 100644 --- a/vendor/rustix/src/termios/ioctl.rs +++ b/vendor/rustix/src/termios/ioctl.rs @@ -1,7 +1,10 @@ //! Terminal-related `ioctl` functions. +#![allow(unsafe_code)] + use crate::fd::AsFd; -use crate::{backend, io}; +use crate::{backend, io, ioctl}; +use backend::c; /// `ioctl(fd, TIOCEXCL)`—Enables exclusive mode on a terminal. /// @@ -19,7 +22,11 @@ use crate::{backend, io}; #[inline] #[doc(alias = "TIOCEXCL")] pub fn ioctl_tiocexcl<Fd: AsFd>(fd: Fd) -> io::Result<()> { - backend::termios::syscalls::ioctl_tiocexcl(fd.as_fd()) + // SAFETY: TIOCEXCL is a no-argument setter opcode. + unsafe { + let ctl = ioctl::NoArg::<ioctl::BadOpcode<{ c::TIOCEXCL as _ }>>::new(); + ioctl::ioctl(fd, ctl) + } } /// `ioctl(fd, TIOCNXCL)`—Disables exclusive mode on a terminal. @@ -38,5 +45,9 @@ pub fn ioctl_tiocexcl<Fd: AsFd>(fd: Fd) -> io::Result<()> { #[inline] #[doc(alias = "TIOCNXCL")] pub fn ioctl_tiocnxcl<Fd: AsFd>(fd: Fd) -> io::Result<()> { - backend::termios::syscalls::ioctl_tiocnxcl(fd.as_fd()) + // SAFETY: TIOCNXCL is a no-argument setter opcode. + unsafe { + let ctl = ioctl::NoArg::<ioctl::BadOpcode<{ c::TIOCNXCL as _ }>>::new(); + ioctl::ioctl(fd, ctl) + } } diff --git a/vendor/rustix/src/termios/tty.rs b/vendor/rustix/src/termios/tty.rs index 00787a568..56aab9fcf 100644 --- a/vendor/rustix/src/termios/tty.rs +++ b/vendor/rustix/src/termios/tty.rs @@ -2,7 +2,7 @@ use crate::backend; use backend::fd::AsFd; -#[cfg(feature = "procfs")] +#[cfg(all(feature = "alloc", feature = "procfs"))] #[cfg(not(any(target_os = "fuchsia", target_os = "wasi")))] use { crate::ffi::CString, crate::io, crate::path::SMALL_PATH_BUFFER_SIZE, alloc::vec::Vec, @@ -33,7 +33,7 @@ pub fn isatty<Fd: AsFd>(fd: Fd) -> bool { /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/ttyname.html /// [Linux]: https://man7.org/linux/man-pages/man3/ttyname.3.html #[cfg(not(any(target_os = "fuchsia", target_os = "wasi")))] -#[cfg(feature = "procfs")] +#[cfg(all(feature = "alloc", feature = "procfs"))] #[cfg_attr(doc_cfg, doc(cfg(feature = "procfs")))] #[doc(alias = "ttyname_r")] #[inline] @@ -42,7 +42,7 @@ pub fn ttyname<Fd: AsFd, B: Into<Vec<u8>>>(dirfd: Fd, reuse: B) -> io::Result<CS } #[cfg(not(any(target_os = "fuchsia", target_os = "wasi")))] -#[cfg(feature = "procfs")] +#[cfg(all(feature = "alloc", feature = "procfs"))] #[allow(unsafe_code)] fn _ttyname(dirfd: BorrowedFd<'_>, mut buffer: Vec<u8>) -> io::Result<CString> { buffer.clear(); @@ -54,9 +54,10 @@ fn _ttyname(dirfd: BorrowedFd<'_>, mut buffer: Vec<u8>) -> io::Result<CString> { buffer.reserve(buffer.capacity() + 1); // use `Vec` reallocation strategy to grow capacity exponentially } Ok(len) => { - // SAFETY: assume the backend returns the length of the string + // SAFETY: assume the backend returns the length of the string excluding the + // NUL. unsafe { - buffer.set_len(len); + buffer.set_len(len + 1); } // SAFETY: diff --git a/vendor/rustix/src/termios/types.rs b/vendor/rustix/src/termios/types.rs index 8b7d473cf..0c44ed2e8 100644 --- a/vendor/rustix/src/termios/types.rs +++ b/vendor/rustix/src/termios/types.rs @@ -292,6 +292,9 @@ bitflags! { target_os = "redox", )))] const IUTF8 = c::IUTF8; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -504,6 +507,9 @@ bitflags! { target_os = "redox", )))] const VT1 = c::VT1; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -564,6 +570,9 @@ bitflags! { target_os = "redox", )))] const CMSPAR = c::CMSPAR; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -627,6 +636,9 @@ bitflags! { /// `IEXTEN` const IEXTEN = c::IEXTEN; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } diff --git a/vendor/rustix/src/thread/futex.rs b/vendor/rustix/src/thread/futex.rs index 7c4399f7a..47947c8b5 100644 --- a/vendor/rustix/src/thread/futex.rs +++ b/vendor/rustix/src/thread/futex.rs @@ -9,7 +9,7 @@ use crate::thread::Timespec; use crate::{backend, io}; -pub use backend::thread::{FutexFlags, FutexOperation}; +pub use backend::thread::futex::{FutexFlags, FutexOperation}; /// `futex(uaddr, op, val, utime, uaddr2, val3)` /// diff --git a/vendor/rustix/src/thread/id.rs b/vendor/rustix/src/thread/id.rs index fa3bcfb8d..11193c9d1 100644 --- a/vendor/rustix/src/thread/id.rs +++ b/vendor/rustix/src/thread/id.rs @@ -1,7 +1,8 @@ -use crate::pid::Pid; -use crate::ugid::{Gid, Uid}; use crate::{backend, io}; +pub use crate::pid::{Pid, RawPid}; +pub use crate::ugid::{Gid, RawGid, RawUid, Uid}; + /// `gettid()`—Returns the thread ID. /// /// This returns the OS thread ID, which is not necessarily the same as the @@ -69,7 +70,7 @@ pub fn set_thread_res_uid(ruid: Uid, euid: Uid, suid: Uid) -> io::Result<()> { /// /// # Warning /// -/// This is not the setxid you are looking for... POSIX requires xids to be +/// This is not the setxid you are looking for… POSIX requires xids to be /// process granular, but on Linux they are per-thread. Thus, this call only /// changes the xid for the current *thread*, not the entire process even /// though that is in violation of the POSIX standard. @@ -94,7 +95,7 @@ pub fn set_thread_gid(gid: Gid) -> io::Result<()> { /// /// # Warning /// -/// This is not the setresxid you are looking for... POSIX requires xids to be +/// This is not the setresxid you are looking for… POSIX requires xids to be /// process granular, but on Linux they are per-thread. Thus, this call only /// changes the xid for the current *thread*, not the entire process even /// though that is in violation of the POSIX standard. diff --git a/vendor/rustix/src/thread/libcap.rs b/vendor/rustix/src/thread/libcap.rs index 8d2368720..19f81a904 100644 --- a/vendor/rustix/src/thread/libcap.rs +++ b/vendor/rustix/src/thread/libcap.rs @@ -102,6 +102,9 @@ bitflags! { const BPF = 1 << linux_raw_sys::general::CAP_BPF; /// `CAP_CHECKPOINT_RESTORE` const CHECKPOINT_RESTORE = 1 << linux_raw_sys::general::CAP_CHECKPOINT_RESTORE; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } diff --git a/vendor/rustix/src/thread/mod.rs b/vendor/rustix/src/thread/mod.rs index fa4897025..6f19635f0 100644 --- a/vendor/rustix/src/thread/mod.rs +++ b/vendor/rustix/src/thread/mod.rs @@ -2,7 +2,7 @@ #[cfg(not(target_os = "redox"))] mod clock; -#[cfg(linux_raw)] +#[cfg(linux_kernel)] mod futex; #[cfg(linux_kernel)] mod id; @@ -15,10 +15,13 @@ mod setns; #[cfg(not(target_os = "redox"))] pub use clock::*; -#[cfg(linux_raw)] +#[cfg(linux_kernel)] pub use futex::{futex, FutexFlags, FutexOperation}; #[cfg(linux_kernel)] -pub use id::{gettid, set_thread_gid, set_thread_res_gid, set_thread_res_uid, set_thread_uid}; +pub use id::{ + gettid, set_thread_gid, set_thread_res_gid, set_thread_res_uid, set_thread_uid, Gid, Pid, + RawGid, RawPid, RawUid, Uid, +}; #[cfg(linux_kernel)] pub use libcap::{capabilities, set_capabilities, CapabilityFlags, CapabilitySets}; #[cfg(linux_kernel)] diff --git a/vendor/rustix/src/thread/prctl.rs b/vendor/rustix/src/thread/prctl.rs index a9f411640..b2d40d65c 100644 --- a/vendor/rustix/src/thread/prctl.rs +++ b/vendor/rustix/src/thread/prctl.rs @@ -19,7 +19,9 @@ use bitflags::bitflags; use crate::backend::c::{c_int, c_uint, c_void}; use crate::backend::prctl::syscalls; -use crate::ffi::{CStr, CString}; +use crate::ffi::CStr; +#[cfg(feature = "alloc")] +use crate::ffi::CString; use crate::io; use crate::pid::Pid; use crate::prctl::{ @@ -61,6 +63,7 @@ pub fn set_keep_capabilities(enable: bool) -> io::Result<()> { // PR_GET_NAME/PR_SET_NAME // +#[cfg(feature = "alloc")] const PR_GET_NAME: c_int = 16; /// Get the name of the calling thread. @@ -70,6 +73,7 @@ const PR_GET_NAME: c_int = 16; /// /// [`prctl(PR_GET_NAME,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] +#[cfg(feature = "alloc")] pub fn name() -> io::Result<CString> { let mut buffer = [0_u8; 16]; unsafe { prctl_2args(PR_GET_NAME, buffer.as_mut_ptr().cast())? }; @@ -134,8 +138,8 @@ impl TryFrom<i32> for SecureComputingMode { /// computing mode, then this call will cause a [`Signal::Kill`] signal to be /// sent to the process. If the caller is in filter mode, and this system call /// is allowed by the seccomp filters, it returns -/// [`SecureComputingMode::Filter`]; otherwise, the process is killed with -/// a [`Signal::Kill`] signal. +/// [`SecureComputingMode::Filter`]; otherwise, the process is killed with a +/// [`Signal::Kill`] signal. /// /// Since Linux 3.8, the Seccomp field of the `/proc/[pid]/status` file /// provides a method of obtaining the same information, without the risk that @@ -414,28 +418,33 @@ bitflags! { #[repr(transparent)] #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct CapabilitiesSecureBits: u32 { - /// If this bit is set, then the kernel does not grant capabilities when - /// a `set-user-ID-root` program is executed, or when a process with an effective or real - /// UID of 0 calls `execve`. + /// If this bit is set, then the kernel does not grant capabilities + /// when a `set-user-ID-root` program is executed, or when a process + /// with an effective or real UID of 0 calls `execve`. const NO_ROOT = 1_u32 << 0; /// Set [`NO_ROOT`] irreversibly. const NO_ROOT_LOCKED = 1_u32 << 1; - /// Setting this flag stops the kernel from adjusting the process's permitted, effective, - /// and ambient capability sets when the thread's effective and filesystem UIDs are switched - /// between zero and nonzero values. + /// Setting this flag stops the kernel from adjusting the process' + /// permitted, effective, and ambient capability sets when the thread's + /// effective and filesystem UIDs are switched between zero and nonzero + /// values. const NO_SETUID_FIXUP = 1_u32 << 2; /// Set [`NO_SETUID_FIXUP`] irreversibly. const NO_SETUID_FIXUP_LOCKED = 1_u32 << 3; - /// Setting this flag allows a thread that has one or more 0 UIDs to retain capabilities in - /// its permitted set when it switches all of its UIDs to nonzero values. + /// Setting this flag allows a thread that has one or more 0 UIDs to + /// retain capabilities in its permitted set when it switches all of + /// its UIDs to nonzero values. const KEEP_CAPS = 1_u32 << 4; /// Set [`KEEP_CAPS`] irreversibly. const KEEP_CAPS_LOCKED = 1_u32 << 5; - /// Setting this flag disallows raising ambient capabilities via the `prctl`'s - /// `PR_CAP_AMBIENT_RAISE` operation. + /// Setting this flag disallows raising ambient capabilities via the + /// `prctl`'s `PR_CAP_AMBIENT_RAISE` operation. const NO_CAP_AMBIENT_RAISE = 1_u32 << 6; /// Set [`NO_CAP_AMBIENT_RAISE`] irreversibly. const NO_CAP_AMBIENT_RAISE_LOCKED = 1_u32 << 7; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -743,6 +752,9 @@ bitflags! { const TCF_SYNC = 1_u32 << 1; /// Asynchronous tag check fault mode. const TCF_ASYNC = 1_u32 << 2; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } diff --git a/vendor/rustix/src/thread/setns.rs b/vendor/rustix/src/thread/setns.rs index 2dd522a14..4568912b2 100644 --- a/vendor/rustix/src/thread/setns.rs +++ b/vendor/rustix/src/thread/setns.rs @@ -30,6 +30,9 @@ bitflags! { const PROCESS_ID = CLONE_NEWPID; /// Network name space. const NETWORK = CLONE_NEWNET; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -82,6 +85,9 @@ bitflags! { const NEWUTS = CLONE_NEWUTS; /// `CLONE_SYSVSEM`. const SYSVSEM = CLONE_SYSVSEM; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -96,7 +102,7 @@ bitflags! { /// /// [Linux]: https://man7.org/linux/man-pages/man2/setns.2.html pub fn move_into_link_name_space( - fd: BorrowedFd, + fd: BorrowedFd<'_>, allowed_type: Option<LinkNameSpaceType>, ) -> io::Result<()> { let allowed_type = allowed_type.map_or(0, |t| t as c_int); @@ -113,7 +119,7 @@ pub fn move_into_link_name_space( /// /// [Linux]: https://man7.org/linux/man-pages/man2/setns.2.html pub fn move_into_thread_name_spaces( - fd: BorrowedFd, + fd: BorrowedFd<'_>, allowed_types: ThreadNameSpaceType, ) -> io::Result<()> { syscalls::setns(fd, allowed_types.bits() as c_int).map(|_r| ()) diff --git a/vendor/rustix/src/utils.rs b/vendor/rustix/src/utils.rs index c5258394d..d21ed88b6 100644 --- a/vendor/rustix/src/utils.rs +++ b/vendor/rustix/src/utils.rs @@ -1,4 +1,7 @@ +//! Miscellaneous minor utilities. + #![allow(dead_code)] +#![allow(unused_macros)] use core::ffi::c_void; use core::mem::{align_of, size_of}; @@ -46,3 +49,34 @@ pub(crate) fn check_raw_pointer<T>(value: *mut c_void) -> Option<NonNull<T>> { NonNull::new(value.cast()) } + +/// Create an array value containing all default values, inferring the type. +#[inline] +pub(crate) fn default_array<T: Default + Copy, const N: usize>() -> [T; N] { + [T::default(); N] +} + +/// Create a union value containing a default value in one of its arms. +/// +/// The field names a union field which must have the same size as the union +/// itself. +macro_rules! default_union { + ($union:ident, $field:ident) => {{ + let u = $union { + $field: Default::default(), + }; + + // Assert that the given field initializes the whole union. + #[cfg(test)] + unsafe { + let field_value = u.$field; + assert_eq!( + core::mem::size_of_val(&u), + core::mem::size_of_val(&field_value) + ); + const_assert_eq!(memoffset::offset_of_union!($union, $field), 0); + } + + u + }}; +} diff --git a/vendor/rustix/src/weak.rs b/vendor/rustix/src/weak.rs index b75b1f12a..3cda8e6c9 100644 --- a/vendor/rustix/src/weak.rs +++ b/vendor/rustix/src/weak.rs @@ -184,7 +184,7 @@ macro_rules! syscall { // Pass `BorrowedFd` values as the integer value. impl AsSyscallArg for $crate::fd::BorrowedFd<'_> { - type SyscallArgType = ::libc::c_long; + type SyscallArgType = ::libc::c_int; fn into_syscall_arg(self) -> Self::SyscallArgType { $crate::fd::AsRawFd::as_raw_fd(&self) as _ } @@ -192,31 +192,31 @@ macro_rules! syscall { // Coerce integer values into `c_long`. impl AsSyscallArg for i8 { - type SyscallArgType = ::libc::c_long; - fn into_syscall_arg(self) -> Self::SyscallArgType { self as _ } + type SyscallArgType = ::libc::c_int; + fn into_syscall_arg(self) -> Self::SyscallArgType { self.into() } } impl AsSyscallArg for u8 { - type SyscallArgType = ::libc::c_long; - fn into_syscall_arg(self) -> Self::SyscallArgType { self as _ } + type SyscallArgType = ::libc::c_int; + fn into_syscall_arg(self) -> Self::SyscallArgType { self.into() } } impl AsSyscallArg for i16 { - type SyscallArgType = ::libc::c_long; - fn into_syscall_arg(self) -> Self::SyscallArgType { self as _ } + type SyscallArgType = ::libc::c_int; + fn into_syscall_arg(self) -> Self::SyscallArgType { self.into() } } impl AsSyscallArg for u16 { - type SyscallArgType = ::libc::c_long; - fn into_syscall_arg(self) -> Self::SyscallArgType { self as _ } + type SyscallArgType = ::libc::c_int; + fn into_syscall_arg(self) -> Self::SyscallArgType { self.into() } } impl AsSyscallArg for i32 { - type SyscallArgType = ::libc::c_long; - fn into_syscall_arg(self) -> Self::SyscallArgType { self as _ } + type SyscallArgType = ::libc::c_int; + fn into_syscall_arg(self) -> Self::SyscallArgType { self } } impl AsSyscallArg for u32 { - type SyscallArgType = ::libc::c_long; - fn into_syscall_arg(self) -> Self::SyscallArgType { self as _ } + type SyscallArgType = ::libc::c_uint; + fn into_syscall_arg(self) -> Self::SyscallArgType { self } } impl AsSyscallArg for usize { - type SyscallArgType = ::libc::c_long; + type SyscallArgType = ::libc::c_ulong; fn into_syscall_arg(self) -> Self::SyscallArgType { self as _ } } @@ -225,12 +225,12 @@ macro_rules! syscall { #[cfg(target_pointer_width = "64")] impl AsSyscallArg for i64 { type SyscallArgType = ::libc::c_long; - fn into_syscall_arg(self) -> Self::SyscallArgType { self as _ } + fn into_syscall_arg(self) -> Self::SyscallArgType { self } } #[cfg(target_pointer_width = "64")] impl AsSyscallArg for u64 { - type SyscallArgType = ::libc::c_long; - fn into_syscall_arg(self) -> Self::SyscallArgType { self as _ } + type SyscallArgType = ::libc::c_ulong; + fn into_syscall_arg(self) -> Self::SyscallArgType { self } } // `concat_idents` is [unstable], so we take an extra `sys_name` |