From ef24de24a82fe681581cc130f342363c47c0969a Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 7 Jun 2024 07:48:48 +0200 Subject: Merging upstream version 1.75.0+dfsg1. Signed-off-by: Daniel Baumann --- vendor/rustix/src/backend/libc/c.rs | 296 +++--- vendor/rustix/src/backend/libc/conv.rs | 11 +- vendor/rustix/src/backend/libc/event/epoll.rs | 24 +- vendor/rustix/src/backend/libc/event/mod.rs | 2 +- vendor/rustix/src/backend/libc/event/poll_fd.rs | 2 +- vendor/rustix/src/backend/libc/event/types.rs | 2 +- vendor/rustix/src/backend/libc/fs/dir.rs | 158 ++- vendor/rustix/src/backend/libc/fs/inotify.rs | 25 +- vendor/rustix/src/backend/libc/fs/mod.rs | 1 + vendor/rustix/src/backend/libc/fs/syscalls.rs | 143 ++- vendor/rustix/src/backend/libc/fs/types.rs | 100 +- vendor/rustix/src/backend/libc/io/errno.rs | 107 +- vendor/rustix/src/backend/libc/io/syscalls.rs | 16 +- vendor/rustix/src/backend/libc/io/types.rs | 6 +- vendor/rustix/src/backend/libc/mm/syscalls.rs | 22 + vendor/rustix/src/backend/libc/mm/types.rs | 38 +- vendor/rustix/src/backend/libc/mod.rs | 13 +- vendor/rustix/src/backend/libc/mount/types.rs | 72 +- vendor/rustix/src/backend/libc/net/addr.rs | 10 +- vendor/rustix/src/backend/libc/net/ext.rs | 8 +- vendor/rustix/src/backend/libc/net/mod.rs | 10 +- vendor/rustix/src/backend/libc/net/msghdr.rs | 2 +- .../rustix/src/backend/libc/net/read_sockaddr.rs | 71 +- vendor/rustix/src/backend/libc/net/send_recv.rs | 16 +- vendor/rustix/src/backend/libc/net/sockopt.rs | 1065 ++++++++++++++++++++ vendor/rustix/src/backend/libc/net/syscalls.rs | 700 ++----------- .../rustix/src/backend/libc/net/write_sockaddr.rs | 15 +- vendor/rustix/src/backend/libc/param/auxv.rs | 2 +- vendor/rustix/src/backend/libc/pipe/types.rs | 5 +- vendor/rustix/src/backend/libc/process/mod.rs | 2 +- vendor/rustix/src/backend/libc/process/syscalls.rs | 105 +- vendor/rustix/src/backend/libc/process/types.rs | 8 + vendor/rustix/src/backend/libc/pty/syscalls.rs | 6 +- vendor/rustix/src/backend/libc/rand/types.rs | 2 +- vendor/rustix/src/backend/libc/shm/mod.rs | 2 + vendor/rustix/src/backend/libc/shm/syscalls.rs | 25 + vendor/rustix/src/backend/libc/shm/types.rs | 30 + vendor/rustix/src/backend/libc/system/syscalls.rs | 9 + vendor/rustix/src/backend/libc/termios/syscalls.rs | 44 +- vendor/rustix/src/backend/libc/thread/syscalls.rs | 17 +- vendor/rustix/src/backend/libc/time/types.rs | 4 +- 41 files changed, 2132 insertions(+), 1064 deletions(-) create mode 100644 vendor/rustix/src/backend/libc/net/sockopt.rs create mode 100644 vendor/rustix/src/backend/libc/shm/mod.rs create mode 100644 vendor/rustix/src/backend/libc/shm/syscalls.rs create mode 100644 vendor/rustix/src/backend/libc/shm/types.rs (limited to 'vendor/rustix/src/backend/libc') diff --git a/vendor/rustix/src/backend/libc/c.rs b/vendor/rustix/src/backend/libc/c.rs index eb89fa43a..f788cb120 100644 --- a/vendor/rustix/src/backend/libc/c.rs +++ b/vendor/rustix/src/backend/libc/c.rs @@ -86,6 +86,11 @@ 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; +// TODO: Remove once https://github.com/rust-lang/libc/pull/3377 is merged and released. +#[cfg(target_os = "netbsd")] +#[cfg(feature = "net")] +pub(crate) const SO_NOSIGPIPE: c_int = 0x0800; + // 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 @@ -109,7 +114,12 @@ pub(super) use libc::fallocate64 as fallocate; #[cfg(not(any(target_arch = "aarch64", target_arch = "riscv64")))] #[cfg(any(linux_like, target_os = "aix"))] pub(super) use libc::open64 as open; -#[cfg(any(linux_kernel, target_os = "aix", target_os = "l4re"))] +#[cfg(any( + linux_kernel, + target_os = "aix", + target_os = "hurd", + target_os = "l4re" +))] 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}; @@ -123,7 +133,7 @@ pub(super) use libc::{ rlimit64 as rlimit, setrlimit64 as setrlimit, statfs64 as statfs, statvfs64 as statvfs, RLIM_INFINITY, }; -#[cfg(linux_like)] +#[cfg(any(linux_like, target_os = "hurd"))] pub(super) use libc::{ fstat64 as fstat, fstatat64 as fstatat, fstatfs64 as fstatfs, fstatvfs64 as fstatvfs, ftruncate64 as ftruncate, getrlimit64 as getrlimit, ino64_t as ino_t, lseek64 as lseek, @@ -144,11 +154,16 @@ pub(super) use libc::{ target_arch = "mips64r6" ) )))] -#[cfg(any(linux_like, target_os = "aix"))] +#[cfg(any(linux_like, target_os = "aix", target_os = "hurd"))] pub(super) use libc::{lstat64 as lstat, stat64 as stat}; -#[cfg(any(linux_kernel, target_os = "aix", target_os = "emscripten"))] +#[cfg(any( + linux_kernel, + target_os = "aix", + target_os = "hurd", + target_os = "emscripten" +))] pub(super) use libc::{pread64 as pread, pwrite64 as pwrite}; -#[cfg(any(target_os = "linux", target_os = "emscripten"))] +#[cfg(any(target_os = "linux", target_os = "hurd", target_os = "emscripten"))] pub(super) use libc::{preadv64 as preadv, pwritev64 as pwritev}; #[cfg(all(target_os = "linux", target_env = "gnu"))] @@ -209,25 +224,6 @@ pub(super) unsafe fn prlimit( prlimit64(pid, resource, new_limit, old_limit) } -// 64-bit offsets on 32-bit platforms are passed in endianness-specific -// lo/hi pairs. See src/backend/linux_raw/conv.rs for details. -#[cfg(all(linux_kernel, target_endian = "little", target_pointer_width = "32"))] -fn lo(x: i64) -> usize { - (x >> 32) as usize -} -#[cfg(all(linux_kernel, target_endian = "little", target_pointer_width = "32"))] -fn hi(x: i64) -> usize { - x as usize -} -#[cfg(all(linux_kernel, target_endian = "big", target_pointer_width = "32"))] -fn lo(x: i64) -> usize { - x as usize -} -#[cfg(all(linux_kernel, target_endian = "big", target_pointer_width = "32"))] -fn hi(x: i64) -> usize { - (x >> 32) as usize -} - #[cfg(target_os = "android")] mod readwrite_pv64 { use super::*; @@ -248,31 +244,18 @@ mod readwrite_pv64 { if let Some(fun) = preadv64.get() { fun(fd, iov, iovcnt, offset) } else { - #[cfg(target_pointer_width = "32")] - { - syscall! { - fn preadv( - fd: libc::c_int, - iov: *const libc::iovec, - iovcnt: libc::c_int, - offset_hi: usize, - offset_lo: usize - ) via SYS_preadv -> libc::ssize_t - } - preadv(fd, iov, iovcnt, hi(offset), lo(offset)) - } - #[cfg(target_pointer_width = "64")] - { - syscall! { - fn preadv( - fd: libc::c_int, - iov: *const libc::iovec, - iovcnt: libc::c_int, - offset: libc::off_t - ) via SYS_preadv -> libc::ssize_t - } - preadv(fd, iov, iovcnt, offset) + // Unlike the plain "p" functions, the "pv" functions pass their + // offset in an endian-independent way, and always in two registers. + syscall! { + fn preadv( + fd: libc::c_int, + iov: *const libc::iovec, + iovcnt: libc::c_int, + offset_lo: usize, + offset_hi: usize + ) via SYS_preadv -> libc::ssize_t } + preadv(fd, iov, iovcnt, offset as usize, (offset >> 32) as usize) } } pub(in super::super) unsafe fn pwritev64( @@ -288,38 +271,25 @@ mod readwrite_pv64 { if let Some(fun) = pwritev64.get() { fun(fd, iov, iovcnt, offset) } else { - #[cfg(target_pointer_width = "32")] - { - syscall! { - fn pwritev( - fd: libc::c_int, - iov: *const libc::iovec, - iovcnt: libc::c_int, - offset_hi: usize, - offset_lo: usize - ) via SYS_pwritev -> libc::ssize_t - } - pwritev(fd, iov, iovcnt, hi(offset), lo(offset)) - } - #[cfg(target_pointer_width = "64")] - { - syscall! { - fn pwritev( - fd: libc::c_int, - iov: *const libc::iovec, - iovcnt: libc::c_int, - offset: libc::off_t - ) via SYS_pwritev -> libc::ssize_t - } - pwritev(fd, iov, iovcnt, offset) + // Unlike the plain "p" functions, the "pv" functions pass their + // offset in an endian-independent way, and always in two registers. + syscall! { + fn pwritev( + fd: libc::c_int, + iov: *const libc::iovec, + iovcnt: libc::c_int, + offset_lo: usize, + offset_hi: usize + ) via SYS_pwritev -> libc::ssize_t } + pwritev(fd, iov, iovcnt, offset as usize, (offset >> 32) as usize) } } } #[cfg(target_os = "android")] pub(super) use readwrite_pv64::{preadv64 as preadv, pwritev64 as pwritev}; -// macOS added preadv and pwritev in version 11.0 +// macOS added `preadv` and `pwritev` in version 11.0. #[cfg(apple)] mod readwrite_pv { weakcall! { @@ -363,33 +333,26 @@ mod readwrite_pv64v2 { if let Some(fun) = preadv64v2.get() { fun(fd, iov, iovcnt, offset, flags) } else { - #[cfg(target_pointer_width = "32")] - { - syscall! { - fn preadv2( - fd: libc::c_int, - iov: *const libc::iovec, - iovcnt: libc::c_int, - offset_hi: usize, - offset_lo: usize, - flags: libc::c_int - ) via SYS_preadv2 -> libc::ssize_t - } - preadv2(fd, iov, iovcnt, hi(offset), lo(offset), flags) - } - #[cfg(target_pointer_width = "64")] - { - syscall! { - fn preadv2( - fd: libc::c_int, - iov: *const libc::iovec, - iovcnt: libc::c_int, - offset: libc::off_t, - flags: libc::c_int - ) via SYS_preadv2 -> libc::ssize_t - } - preadv2(fd, iov, iovcnt, offset, flags) + // Unlike the plain "p" functions, the "pv" functions pass their + // offset in an endian-independent way, and always in two registers. + syscall! { + fn preadv2( + fd: libc::c_int, + iov: *const libc::iovec, + iovcnt: libc::c_int, + offset_lo: usize, + offset_hi: usize, + flags: libc::c_int + ) via SYS_preadv2 -> libc::ssize_t } + preadv2( + fd, + iov, + iovcnt, + offset as usize, + (offset >> 32) as usize, + flags, + ) } } pub(in super::super) unsafe fn pwritev64v2( @@ -406,33 +369,26 @@ mod readwrite_pv64v2 { if let Some(fun) = pwritev64v2.get() { fun(fd, iov, iovcnt, offset, flags) } else { - #[cfg(target_pointer_width = "32")] - { - syscall! { - fn pwritev2( - fd: libc::c_int, - iov: *const libc::iovec, - iovec: libc::c_int, - offset_hi: usize, - offset_lo: usize, - flags: libc::c_int - ) via SYS_pwritev2 -> libc::ssize_t - } - pwritev2(fd, iov, iovcnt, hi(offset), lo(offset), flags) - } - #[cfg(target_pointer_width = "64")] - { - syscall! { - fn pwritev2( - fd: libc::c_int, - iov:*const libc::iovec, - iovcnt: libc::c_int, - offset: libc::off_t, - flags: libc::c_int - ) via SYS_pwritev2 -> libc::ssize_t - } - pwritev2(fd, iov, iovcnt, offset, flags) + // Unlike the plain "p" functions, the "pv" functions pass their + // offset in an endian-independent way, and always in two registers. + syscall! { + fn pwritev2( + fd: libc::c_int, + iov: *const libc::iovec, + iovec: libc::c_int, + offset_lo: usize, + offset_hi: usize, + flags: libc::c_int + ) via SYS_pwritev2 -> libc::ssize_t } + pwritev2( + fd, + iov, + iovcnt, + offset as usize, + (offset >> 32) as usize, + flags, + ) } } } @@ -455,33 +411,26 @@ mod readwrite_pv64v2 { offset: libc::off64_t, flags: libc::c_int, ) -> libc::ssize_t { - #[cfg(target_pointer_width = "32")] - { - syscall! { - fn preadv2( - fd: libc::c_int, - iov: *const libc::iovec, - iovcnt: libc::c_int, - offset_hi: usize, - offset_lo: usize, - flags: libc::c_int - ) via SYS_preadv2 -> libc::ssize_t - } - preadv2(fd, iov, iovcnt, hi(offset), lo(offset), flags) - } - #[cfg(target_pointer_width = "64")] - { - syscall! { - fn preadv2( - fd: libc::c_int, - iov: *const libc::iovec, - iovcnt: libc::c_int, - offset: libc::off_t, - flags: libc::c_int - ) via SYS_preadv2 -> libc::ssize_t - } - preadv2(fd, iov, iovcnt, offset, flags) + // Unlike the plain "p" functions, the "pv" functions pass their offset + // in an endian-independent way, and always in two registers. + syscall! { + fn preadv2( + fd: libc::c_int, + iov: *const libc::iovec, + iovcnt: libc::c_int, + offset_lo: usize, + offset_hi: usize, + flags: libc::c_int + ) via SYS_preadv2 -> libc::ssize_t } + preadv2( + fd, + iov, + iovcnt, + offset as usize, + (offset >> 32) as usize, + flags, + ) } pub(in super::super) unsafe fn pwritev64v2( fd: libc::c_int, @@ -490,33 +439,26 @@ mod readwrite_pv64v2 { offset: libc::off64_t, flags: libc::c_int, ) -> libc::ssize_t { - #[cfg(target_pointer_width = "32")] - { - syscall! { - fn pwritev2( - fd: libc::c_int, - iov: *const libc::iovec, - iovcnt: libc::c_int, - offset_hi: usize, - offset_lo: usize, - flags: libc::c_int - ) via SYS_pwritev2 -> libc::ssize_t - } - pwritev2(fd, iov, iovcnt, hi(offset), lo(offset), flags) - } - #[cfg(target_pointer_width = "64")] - { - syscall! { - fn pwritev2( - fd: libc::c_int, - iov:*const libc::iovec, - iovcnt: libc::c_int, - offset: libc::off_t, - flags: libc::c_int - ) via SYS_pwritev2 -> libc::ssize_t - } - pwritev2(fd, iov, iovcnt, offset, flags) + // Unlike the plain "p" functions, the "pv" functions pass their offset + // in an endian-independent way, and always in two registers. + syscall! { + fn pwritev2( + fd: libc::c_int, + iov: *const libc::iovec, + iovcnt: libc::c_int, + offset_lo: usize, + offset_hi: usize, + flags: libc::c_int + ) via SYS_pwritev2 -> libc::ssize_t } + pwritev2( + fd, + iov, + iovcnt, + offset as usize, + (offset >> 32) as usize, + flags, + ) } } #[cfg(any( diff --git a/vendor/rustix/src/backend/libc/conv.rs b/vendor/rustix/src/backend/libc/conv.rs index 19bf0a7db..253951002 100644 --- a/vendor/rustix/src/backend/libc/conv.rs +++ b/vendor/rustix/src/backend/libc/conv.rs @@ -16,7 +16,7 @@ pub(super) fn c_str(c: &CStr) -> *const c::c_char { c.as_ptr() } -#[cfg(not(any(windows, target_os = "espidf", target_os = "wasi")))] +#[cfg(not(any(windows, target_os = "espidf", target_os = "vita", target_os = "wasi")))] #[inline] pub(super) fn no_fd() -> LibcFd { -1 @@ -192,7 +192,13 @@ pub(super) fn msg_iov_len(len: usize) -> c::size_t { /// Convert the value to the `msg_iovlen` field of a `msghdr` struct. #[cfg(all( - not(any(windows, target_os = "espidf", target_os = "redox", target_os = "wasi")), + not(any( + windows, + target_os = "espidf", + target_os = "redox", + target_os = "vita", + target_os = "wasi" + )), not(any( target_os = "android", all(target_os = "linux", not(target_env = "musl")) @@ -232,6 +238,7 @@ pub(crate) fn msg_control_len(len: usize) -> c::socklen_t { target_os = "haiku", target_os = "nto", target_os = "redox", + target_os = "vita", target_os = "wasi", )))] #[inline] diff --git a/vendor/rustix/src/backend/libc/event/epoll.rs b/vendor/rustix/src/backend/libc/event/epoll.rs index a6087a167..b41b05711 100644 --- a/vendor/rustix/src/backend/libc/event/epoll.rs +++ b/vendor/rustix/src/backend/libc/event/epoll.rs @@ -1,8 +1,4 @@ -//! epoll support. -//! -//! This is an experiment, and it isn't yet clear whether epoll is the right -//! level of abstraction at which to introduce safety. But it works fairly well -//! in simple examples 🙂. +//! Linux `epoll` support. //! //! # Examples //! @@ -74,10 +70,13 @@ //! ``` use crate::backend::c; -use crate::backend::conv::{ret, ret_owned_fd, ret_u32}; +#[cfg(feature = "alloc")] +use crate::backend::conv::ret_u32; +use crate::backend::conv::{ret, ret_owned_fd}; use crate::fd::{AsFd, AsRawFd, OwnedFd}; use crate::io; use crate::utils::as_mut_ptr; +#[cfg(feature = "alloc")] use alloc::vec::Vec; use bitflags::bitflags; use core::ffi::c_void; @@ -93,7 +92,7 @@ bitflags! { /// `EPOLL_CLOEXEC` const CLOEXEC = bitcast!(c::EPOLL_CLOEXEC); - /// + /// const _ = !0; } } @@ -149,7 +148,7 @@ bitflags! { #[cfg(not(target_os = "android"))] const EXCLUSIVE = bitcast!(c::EPOLLEXCLUSIVE); - /// + /// const _ = !0; } } @@ -257,6 +256,8 @@ pub fn delete(epoll: impl AsFd, source: impl AsFd) -> io::Result<()> { /// /// For each event of interest, an element is written to `events`. On /// success, this returns the number of written elements. +#[cfg(feature = "alloc")] +#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] pub fn wait(epoll: impl AsFd, event_list: &mut EventVec, timeout: c::c_int) -> io::Result<()> { // SAFETY: We're calling `epoll_wait` via FFI and we know how it // behaves. @@ -312,8 +313,8 @@ pub struct Event { pub data: EventData, } -/// Data assocated with an [`Event`]. This can either be a 64-bit integer value -/// or a pointer which preserves pointer provenance. +/// Data associated with an [`Event`]. This can either be a 64-bit integer +/// value or a pointer which preserves pointer provenance. #[repr(C)] #[derive(Copy, Clone)] pub union EventData { @@ -395,10 +396,12 @@ struct SixtyFourBitPointer { } /// A vector of `Event`s, plus context for interpreting them. +#[cfg(feature = "alloc")] pub struct EventVec { events: Vec, } +#[cfg(feature = "alloc")] impl EventVec { /// Constructs an `EventVec` from raw pointer, length, and capacity. /// @@ -473,6 +476,7 @@ impl EventVec { } } +#[cfg(feature = "alloc")] impl<'a> IntoIterator for &'a EventVec { type IntoIter = Iter<'a>; type Item = Event; diff --git a/vendor/rustix/src/backend/libc/event/mod.rs b/vendor/rustix/src/backend/libc/event/mod.rs index 44e8a090a..6aed4612a 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(all(feature = "alloc", linux_kernel))] +#[cfg(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 3f795d5aa..42f94f3c7 100644 --- a/vendor/rustix/src/backend/libc/event/poll_fd.rs +++ b/vendor/rustix/src/backend/libc/event/poll_fd.rs @@ -48,7 +48,7 @@ bitflags! { )] const RDHUP = c::POLLRDHUP; - /// + /// const _ = !0; } } diff --git a/vendor/rustix/src/backend/libc/event/types.rs b/vendor/rustix/src/backend/libc/event/types.rs index af052a434..ea4776667 100644 --- a/vendor/rustix/src/backend/libc/event/types.rs +++ b/vendor/rustix/src/backend/libc/event/types.rs @@ -31,7 +31,7 @@ bitflags! { #[cfg(not(target_os = "espidf"))] const SEMAPHORE = bitcast!(c::EFD_SEMAPHORE); - /// + /// const _ = !0; } } diff --git a/vendor/rustix/src/backend/libc/fs/dir.rs b/vendor/rustix/src/backend/libc/fs/dir.rs index 6cfeb242b..0df1ea1b5 100644 --- a/vendor/rustix/src/backend/libc/fs/dir.rs +++ b/vendor/rustix/src/backend/libc/fs/dir.rs @@ -1,37 +1,51 @@ -#[cfg(not(any(solarish, target_os = "haiku", target_os = "nto")))] +#[cfg(not(any(solarish, target_os = "haiku", target_os = "nto", target_os = "vita")))] use super::types::FileType; use crate::backend::c; use crate::backend::conv::owned_fd; use crate::fd::{AsFd, BorrowedFd}; use crate::ffi::{CStr, CString}; -use crate::fs::{fcntl_getfl, fstat, openat, Mode, OFlags, Stat}; +use crate::fs::{fcntl_getfl, openat, Mode, OFlags}; +#[cfg(not(target_os = "vita"))] +use crate::fs::{fstat, Stat}; #[cfg(not(any( solarish, target_os = "haiku", target_os = "netbsd", target_os = "nto", target_os = "redox", + target_os = "vita", target_os = "wasi", )))] use crate::fs::{fstatfs, StatFs}; -#[cfg(not(any(solarish, target_os = "haiku", target_os = "redox", target_os = "wasi")))] +#[cfg(not(any( + solarish, + target_os = "haiku", + target_os = "redox", + target_os = "vita", + target_os = "wasi" +)))] use crate::fs::{fstatvfs, StatVfs}; use crate::io; -#[cfg(not(any(target_os = "fuchsia", target_os = "wasi")))] +#[cfg(not(any(target_os = "fuchsia", target_os = "vita", target_os = "wasi")))] #[cfg(feature = "process")] use crate::process::fchdir; use alloc::borrow::ToOwned; -#[cfg(not(linux_like))] +#[cfg(not(any(linux_like, target_os = "hurd")))] use c::readdir as libc_readdir; -#[cfg(linux_like)] +#[cfg(any(linux_like, target_os = "hurd"))] use c::readdir64 as libc_readdir; use core::fmt; use core::ptr::NonNull; use libc_errno::{errno, set_errno, Errno}; /// `DIR*` -#[repr(transparent)] -pub struct Dir(NonNull); +pub struct Dir { + /// The `libc` `DIR` pointer. + libc_dir: NonNull, + + /// Have we seen any errors in this iteration? + any_errors: bool, +} impl Dir { /// Construct a `Dir` that reads entries from the given directory @@ -42,21 +56,38 @@ impl Dir { } #[inline] + #[allow(unused_mut)] fn _read_from(fd: BorrowedFd<'_>) -> io::Result { + let mut any_errors = false; + // Given an arbitrary `OwnedFd`, it's impossible to know whether the // user holds a `dup`'d copy which could continue to modify the // file description state, which would cause Undefined Behavior after // our call to `fdopendir`. To prevent this, we obtain an independent // `OwnedFd`. let flags = fcntl_getfl(fd)?; - let fd_for_dir = openat(fd, cstr!("."), flags | OFlags::CLOEXEC, Mode::empty())?; + let fd_for_dir = match openat(fd, cstr!("."), flags | OFlags::CLOEXEC, Mode::empty()) { + Ok(fd) => fd, + #[cfg(not(target_os = "wasi"))] + Err(io::Errno::NOENT) => { + // If "." doesn't exist, it means the directory was removed. + // We treat that as iterating through a directory with no + // entries. + any_errors = true; + crate::io::dup(fd)? + } + Err(err) => return Err(err), + }; let raw = owned_fd(fd_for_dir); unsafe { let libc_dir = c::fdopendir(raw); if let Some(libc_dir) = NonNull::new(libc_dir) { - Ok(Self(libc_dir)) + Ok(Self { + libc_dir, + any_errors, + }) } else { let err = io::Errno::last_os_error(); let _ = c::close(raw); @@ -68,13 +99,19 @@ impl Dir { /// `rewinddir(self)` #[inline] pub fn rewind(&mut self) { - unsafe { c::rewinddir(self.0.as_ptr()) } + self.any_errors = false; + unsafe { c::rewinddir(self.libc_dir.as_ptr()) } } /// `readdir(self)`, where `None` means the end of the directory. pub fn read(&mut self) -> Option> { + // If we've seen errors, don't continue to try to read anyting further. + if self.any_errors { + return None; + } + set_errno(Errno(0)); - let dirent_ptr = unsafe { libc_readdir(self.0.as_ptr()) }; + let dirent_ptr = unsafe { libc_readdir(self.libc_dir.as_ptr()) }; if dirent_ptr.is_null() { let curr_errno = errno().0; if curr_errno == 0 { @@ -82,6 +119,7 @@ impl Dir { None } else { // `errno` is unknown or non-zero, so an error occurred. + self.any_errors = true; Some(Err(io::Errno(curr_errno))) } } else { @@ -99,11 +137,12 @@ impl Dir { solarish, target_os = "aix", target_os = "haiku", - target_os = "nto" + target_os = "nto", + target_os = "vita" )))] d_type: dirent.d_type, - #[cfg(not(any(freebsdlike, netbsdlike)))] + #[cfg(not(any(freebsdlike, netbsdlike, target_os = "vita")))] d_ino: dirent.d_ino, #[cfg(any(freebsdlike, netbsdlike))] @@ -118,9 +157,10 @@ impl Dir { } /// `fstat(self)` + #[cfg(not(target_os = "vita"))] #[inline] pub fn stat(&self) -> io::Result { - fstat(unsafe { BorrowedFd::borrow_raw(c::dirfd(self.0.as_ptr())) }) + fstat(unsafe { BorrowedFd::borrow_raw(c::dirfd(self.libc_dir.as_ptr())) }) } /// `fstatfs(self)` @@ -130,27 +170,34 @@ impl Dir { target_os = "netbsd", target_os = "nto", target_os = "redox", + target_os = "vita", target_os = "wasi", )))] #[inline] pub fn statfs(&self) -> io::Result { - fstatfs(unsafe { BorrowedFd::borrow_raw(c::dirfd(self.0.as_ptr())) }) + fstatfs(unsafe { BorrowedFd::borrow_raw(c::dirfd(self.libc_dir.as_ptr())) }) } /// `fstatvfs(self)` - #[cfg(not(any(solarish, target_os = "haiku", target_os = "redox", target_os = "wasi")))] + #[cfg(not(any( + solarish, + target_os = "haiku", + target_os = "redox", + target_os = "vita", + target_os = "wasi" + )))] #[inline] pub fn statvfs(&self) -> io::Result { - fstatvfs(unsafe { BorrowedFd::borrow_raw(c::dirfd(self.0.as_ptr())) }) + fstatvfs(unsafe { BorrowedFd::borrow_raw(c::dirfd(self.libc_dir.as_ptr())) }) } /// `fchdir(self)` #[cfg(feature = "process")] - #[cfg(not(any(target_os = "fuchsia", target_os = "wasi")))] + #[cfg(not(any(target_os = "fuchsia", target_os = "vita", target_os = "wasi")))] #[cfg_attr(doc_cfg, doc(cfg(feature = "process")))] #[inline] pub fn chdir(&self) -> io::Result<()> { - fchdir(unsafe { BorrowedFd::borrow_raw(c::dirfd(self.0.as_ptr())) }) + fchdir(unsafe { BorrowedFd::borrow_raw(c::dirfd(self.libc_dir.as_ptr())) }) } } @@ -163,7 +210,7 @@ unsafe impl Send for Dir {} impl Drop for Dir { #[inline] fn drop(&mut self) { - unsafe { c::closedir(self.0.as_ptr()) }; + unsafe { c::closedir(self.libc_dir.as_ptr()) }; } } @@ -178,19 +225,26 @@ impl Iterator for Dir { impl fmt::Debug for Dir { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("Dir") - .field("fd", unsafe { &c::dirfd(self.0.as_ptr()) }) - .finish() + let mut s = f.debug_struct("Dir"); + #[cfg(not(target_os = "vita"))] + s.field("fd", unsafe { &c::dirfd(self.libc_dir.as_ptr()) }); + s.finish() } } /// `struct dirent` #[derive(Debug)] pub struct DirEntry { - #[cfg(not(any(solarish, target_os = "aix", target_os = "haiku", target_os = "nto")))] + #[cfg(not(any( + solarish, + target_os = "aix", + target_os = "haiku", + target_os = "nto", + target_os = "vita" + )))] d_type: u8, - #[cfg(not(any(freebsdlike, netbsdlike)))] + #[cfg(not(any(freebsdlike, netbsdlike, target_os = "vita")))] d_ino: c::ino_t, #[cfg(any(freebsdlike, netbsdlike))] @@ -207,14 +261,20 @@ impl DirEntry { } /// Returns the type of this directory entry. - #[cfg(not(any(solarish, target_os = "aix", target_os = "haiku", target_os = "nto")))] + #[cfg(not(any( + solarish, + target_os = "aix", + target_os = "haiku", + target_os = "nto", + target_os = "vita" + )))] #[inline] pub fn file_type(&self) -> FileType { FileType::from_dirent_d_type(self.d_type) } /// Return the inode number of this directory entry. - #[cfg(not(any(freebsdlike, netbsdlike)))] + #[cfg(not(any(freebsdlike, netbsdlike, target_os = "vita")))] #[inline] pub fn ino(&self) -> u64 { self.d_ino as u64 @@ -293,3 +353,45 @@ fn check_dirent_layout(dirent: &c::dirent) { } ); } + +#[test] +fn dir_iterator_handles_io_errors() { + // create a dir, keep the FD, then delete the dir + let tmp = tempfile::tempdir().unwrap(); + let fd = crate::fs::openat( + crate::fs::CWD, + tmp.path(), + crate::fs::OFlags::RDONLY | crate::fs::OFlags::CLOEXEC, + crate::fs::Mode::empty(), + ) + .unwrap(); + + let file_fd = crate::fs::openat( + &fd, + tmp.path().join("test.txt"), + crate::fs::OFlags::WRONLY | crate::fs::OFlags::CREATE, + crate::fs::Mode::RWXU, + ) + .unwrap(); + + let mut dir = Dir::read_from(&fd).unwrap(); + + // Reach inside the `Dir` and replace its directory with a file, which + // will cause the subsequent `readdir` to fail. + unsafe { + let raw_fd = c::dirfd(dir.libc_dir.as_ptr()); + let mut owned_fd: crate::fd::OwnedFd = crate::fd::FromRawFd::from_raw_fd(raw_fd); + crate::io::dup2(&file_fd, &mut owned_fd).unwrap(); + core::mem::forget(owned_fd); + } + + // FreeBSD and macOS seem to read some directory entries before we call + // `.next()`. + #[cfg(any(apple, freebsdlike))] + { + dir.rewind(); + } + + assert!(matches!(dir.next(), Some(Err(_)))); + assert!(matches!(dir.next(), None)); +} diff --git a/vendor/rustix/src/backend/libc/fs/inotify.rs b/vendor/rustix/src/backend/libc/fs/inotify.rs index fea2fad06..2044bd945 100644 --- a/vendor/rustix/src/backend/libc/fs/inotify.rs +++ b/vendor/rustix/src/backend/libc/fs/inotify.rs @@ -18,7 +18,7 @@ bitflags! { /// `IN_NONBLOCK` const NONBLOCK = bitcast!(c::IN_NONBLOCK); - /// + /// const _ = !0; } } @@ -38,7 +38,7 @@ bitflags! { const CLOSE_NOWRITE = c::IN_CLOSE_NOWRITE; /// `IN_CLOSE_WRITE` const CLOSE_WRITE = c::IN_CLOSE_WRITE; - /// `IN_CREATE ` + /// `IN_CREATE` const CREATE = c::IN_CREATE; /// `IN_DELETE` const DELETE = c::IN_DELETE; @@ -75,7 +75,7 @@ bitflags! { /// `IN_ONLYDIR` const ONLYDIR = c::IN_ONLYDIR; - /// + /// const _ = !0; } } @@ -90,23 +90,22 @@ pub fn inotify_init(flags: CreateFlags) -> io::Result { unsafe { ret_owned_fd(c::inotify_init1(bitflags_bits!(flags))) } } -/// `inotify_add_watch(self, path, flags)`—Adds a watch to inotify +/// `inotify_add_watch(self, path, flags)`—Adds a watch to inotify. /// -/// This registers or updates a watch for the filesystem path `path` -/// and returns a watch descriptor corresponding to this watch. +/// This registers or updates a watch for the filesystem path `path` and +/// returns a watch descriptor corresponding to this watch. /// -/// Note: Due to the existence of hardlinks, providing two -/// different paths to this method may result in it returning -/// the same watch descriptor. An application should keep track of this -/// externally to avoid logic errors. +/// Note: Due to the existence of hardlinks, providing two different paths to +/// this method may result in it returning the same watch descriptor. An +/// application should keep track of this externally to avoid logic errors. pub fn inotify_add_watch( inot: BorrowedFd<'_>, path: P, flags: WatchFlags, ) -> io::Result { path.into_with_c_str(|path| { - // SAFETY: The fd and path we are passing is guaranteed valid by the type - // system. + // 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), @@ -117,7 +116,7 @@ pub fn inotify_add_watch( }) } -/// `inotify_rm_watch(self, wd)`—Removes a watch from this inotify +/// `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. diff --git a/vendor/rustix/src/backend/libc/fs/mod.rs b/vendor/rustix/src/backend/libc/fs/mod.rs index 9a0b1d3e5..c17e8636f 100644 --- a/vendor/rustix/src/backend/libc/fs/mod.rs +++ b/vendor/rustix/src/backend/libc/fs/mod.rs @@ -6,6 +6,7 @@ pub mod inotify; target_os = "espidf", target_os = "haiku", target_os = "redox", + target_os = "vita", target_os = "wasi" )))] pub(crate) mod makedev; diff --git a/vendor/rustix/src/backend/libc/fs/syscalls.rs b/vendor/rustix/src/backend/libc/fs/syscalls.rs index 5df25daa9..5e0b62f8e 100644 --- a/vendor/rustix/src/backend/libc/fs/syscalls.rs +++ b/vendor/rustix/src/backend/libc/fs/syscalls.rs @@ -1,13 +1,20 @@ //! libc syscalls supporting `rustix::fs`. use crate::backend::c; -#[cfg(any(apple, linux_kernel, feature = "alloc"))] +#[cfg(any( + apple, + linux_kernel, + feature = "alloc", + all(linux_kernel, feature = "procfs") +))] 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)] use crate::ffi::CString; +#[cfg(not(any(target_os = "espidf", target_os = "vita")))] +use crate::fs::Access; #[cfg(not(any( apple, netbsdlike, @@ -16,6 +23,7 @@ use crate::ffi::CString; target_os = "espidf", target_os = "haiku", target_os = "redox", + target_os = "vita", )))] use crate::fs::Advice; #[cfg(not(any(target_os = "espidf", target_os = "redox")))] @@ -28,9 +36,10 @@ use crate::fs::AtFlags; target_os = "espidf", target_os = "nto", target_os = "redox", + target_os = "vita", )))] use crate::fs::FallocateFlags; -#[cfg(not(any(target_os = "espidf", target_os = "wasi")))] +#[cfg(not(any(target_os = "espidf", target_os = "vita", target_os = "wasi")))] use crate::fs::FlockOperation; #[cfg(any(linux_kernel, target_os = "freebsd"))] use crate::fs::MemfdFlags; @@ -43,12 +52,19 @@ use crate::fs::SealFlags; target_os = "netbsd", target_os = "nto", target_os = "redox", + target_os = "vita", target_os = "wasi", )))] use crate::fs::StatFs; -#[cfg(not(target_os = "espidf"))] -use crate::fs::{Access, Timestamps}; -#[cfg(not(any(apple, target_os = "espidf", target_os = "redox", target_os = "wasi")))] +#[cfg(not(any(target_os = "espidf", target_os = "vita")))] +use crate::fs::Timestamps; +#[cfg(not(any( + apple, + target_os = "espidf", + target_os = "redox", + target_os = "vita", + target_os = "wasi" +)))] use crate::fs::{Dev, FileType}; use crate::fs::{Mode, OFlags, SeekFrom, Stat}; #[cfg(not(any(target_os = "haiku", target_os = "redox", target_os = "wasi")))] @@ -125,7 +141,7 @@ fn open_via_syscall(path: &CStr, oflags: OFlags, mode: Mode) -> io::Result io::Result { // Work around . // glibc versions before 2.25 don't handle `O_TMPFILE` correctly. - #[cfg(all(unix, target_env = "gnu"))] + #[cfg(all(unix, target_env = "gnu", not(target_os = "hurd")))] if oflags.contains(OFlags::TMPFILE) && crate::backend::if_glibc_is_less_than_2_25() { return open_via_syscall(path, oflags, mode); } @@ -153,7 +169,7 @@ pub(crate) fn open(path: &CStr, oflags: OFlags, mode: Mode) -> io::Result, path: &CStr, @@ -188,7 +204,7 @@ pub(crate) fn openat( ) -> io::Result { // Work around . // glibc versions before 2.25 don't handle `O_TMPFILE` correctly. - #[cfg(all(unix, target_env = "gnu"))] + #[cfg(all(unix, target_env = "gnu", not(target_os = "hurd")))] if oflags.contains(OFlags::TMPFILE) && crate::backend::if_glibc_is_less_than_2_25() { return openat_via_syscall(dirfd, path, oflags, mode); } @@ -227,6 +243,7 @@ pub(crate) fn openat( target_os = "netbsd", target_os = "nto", target_os = "redox", + target_os = "vita", target_os = "wasi", )))] #[inline] @@ -258,7 +275,10 @@ pub(crate) fn readlink(path: &CStr, buf: &mut [u8]) -> io::Result { } } -#[cfg(all(feature = "alloc", not(target_os = "redox")))] +#[cfg(all( + any(feature = "alloc", all(linux_kernel, feature = "procfs")), + not(target_os = "redox") +))] #[inline] pub(crate) fn readlinkat( dirfd: BorrowedFd<'_>, @@ -501,8 +521,6 @@ pub(crate) fn renameat2( } } -/// At present, `libc` only has `renameat2` defined for glibc. On other -/// ABIs, `RenameFlags` has no flags defined, and we use plain `renameat`. #[cfg(any( target_os = "android", all(target_os = "linux", not(target_env = "gnu")), @@ -515,8 +533,32 @@ pub(crate) fn renameat2( new_path: &CStr, flags: RenameFlags, ) -> io::Result<()> { - assert!(flags.is_empty()); - renameat(old_dirfd, old_path, new_dirfd, new_path) + // At present, `libc` only has `renameat2` defined for glibc. If we have + // no flags, we can use plain `renameat`, but otherwise we use `syscall!`. + // to call `renameat2` ourselves. + if flags.is_empty() { + renameat(old_dirfd, old_path, new_dirfd, new_path) + } else { + syscall! { + fn renameat2( + olddirfd: c::c_int, + oldpath: *const c::c_char, + newdirfd: c::c_int, + newpath: *const c::c_char, + flags: c::c_uint + ) via SYS_renameat2 -> c::c_int + } + + unsafe { + ret(renameat2( + borrowed_fd(old_dirfd), + c_str(old_path), + borrowed_fd(new_dirfd), + c_str(new_path), + flags.bits(), + )) + } + } } pub(crate) fn symlink(old_path: &CStr, new_path: &CStr) -> io::Result<()> { @@ -680,12 +722,17 @@ fn statat_old(dirfd: BorrowedFd<'_>, path: &CStr, flags: AtFlags) -> io::Result< } } -#[cfg(not(any(target_os = "espidf", target_os = "emscripten")))] +#[cfg(not(any(target_os = "espidf", target_os = "emscripten", target_os = "vita")))] pub(crate) fn access(path: &CStr, access: Access) -> io::Result<()> { unsafe { ret(c::access(c_str(path), access.bits())) } } -#[cfg(not(any(target_os = "emscripten", target_os = "espidf", target_os = "redox")))] +#[cfg(not(any( + target_os = "emscripten", + target_os = "espidf", + target_os = "redox", + target_os = "vita" +)))] pub(crate) fn accessat( dirfd: BorrowedFd<'_>, path: &CStr, @@ -751,7 +798,7 @@ pub(crate) fn accessat( Ok(()) } -#[cfg(not(any(target_os = "espidf", target_os = "redox")))] +#[cfg(not(any(target_os = "espidf", target_os = "redox", target_os = "vita")))] pub(crate) fn utimensat( dirfd: BorrowedFd<'_>, path: &CStr, @@ -831,8 +878,8 @@ pub(crate) fn utimensat( )); } - // `setattrlistat` was introduced in 10.13 along with `utimensat`, so if - // we don't have `utimensat`, we don't have `setattrlistat` either. + // `setattrlistat` was introduced in 10.13 along with `utimensat`, so + // if we don't have `utimensat`, we don't have `setattrlistat` either. // Emulate it using `fork`, and `fchdir` and [`setattrlist`]. // // [`setattrlist`]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/setattrlist.2.html @@ -925,7 +972,11 @@ fn utimensat_old( .tv_sec .try_into() .map_err(|_| io::Errno::OVERFLOW)?, - tv_nsec: times.last_access.tv_nsec, + tv_nsec: times + .last_access + .tv_nsec + .try_into() + .map_err(|_| io::Errno::OVERFLOW)?, }, c::timespec { tv_sec: times @@ -933,7 +984,11 @@ fn utimensat_old( .tv_sec .try_into() .map_err(|_| io::Errno::OVERFLOW)?, - tv_nsec: times.last_modification.tv_nsec, + tv_nsec: times + .last_modification + .tv_nsec + .try_into() + .map_err(|_| io::Errno::OVERFLOW)?, }, ]; unsafe { @@ -1054,7 +1109,13 @@ pub(crate) fn chownat( } } -#[cfg(not(any(apple, target_os = "espidf", target_os = "redox", target_os = "wasi")))] +#[cfg(not(any( + apple, + target_os = "espidf", + target_os = "redox", + target_os = "vita", + target_os = "wasi" +)))] pub(crate) fn mknodat( dirfd: BorrowedFd<'_>, path: &CStr, @@ -1133,6 +1194,7 @@ pub(crate) fn copy_file_range( target_os = "espidf", target_os = "haiku", target_os = "redox", + target_os = "vita", )))] pub(crate) fn fadvise(fd: BorrowedFd<'_>, offset: u64, len: u64, advice: Advice) -> io::Result<()> { let offset = offset as i64; @@ -1189,6 +1251,7 @@ pub(crate) fn fcntl_add_seals(fd: BorrowedFd<'_>, seals: SealFlags) -> io::Resul target_os = "espidf", target_os = "fuchsia", target_os = "redox", + target_os = "vita", target_os = "wasi" )))] #[inline] @@ -1234,8 +1297,8 @@ pub(crate) fn seek(fd: BorrowedFd<'_>, pos: SeekFrom) -> io::Result { SeekFrom::Hole(offset) => (c::SEEK_HOLE, offset), }; - // ESP-IDF doesn't support 64-bit offsets. - #[cfg(target_os = "espidf")] + // ESP-IDF and Vita don't support 64-bit offsets. + #[cfg(any(target_os = "espidf", target_os = "vita"))] let offset: i32 = offset.try_into().map_err(|_| io::Errno::OVERFLOW)?; let offset = unsafe { ret_off_t(c::lseek(borrowed_fd(fd), offset, whence))? }; @@ -1302,7 +1365,12 @@ pub(crate) fn fchown(fd: BorrowedFd<'_>, owner: Option, group: Option) } } -#[cfg(not(any(target_os = "espidf", target_os = "solaris", target_os = "wasi")))] +#[cfg(not(any( + target_os = "espidf", + target_os = "solaris", + target_os = "vita", + target_os = "wasi" +)))] pub(crate) fn flock(fd: BorrowedFd<'_>, operation: FlockOperation) -> io::Result<()> { unsafe { ret(c::flock(borrowed_fd(fd), operation as c::c_int)) } } @@ -1324,7 +1392,12 @@ pub(crate) fn syncfs(fd: BorrowedFd<'_>) -> io::Result<()> { unsafe { ret(syncfs(borrowed_fd(fd))) } } -#[cfg(not(any(target_os = "espidf", target_os = "redox", target_os = "wasi")))] +#[cfg(not(any( + target_os = "espidf", + target_os = "redox", + target_os = "vita", + target_os = "wasi" +)))] pub(crate) fn sync() { unsafe { c::sync() } } @@ -1392,6 +1465,7 @@ fn fstat_old(fd: BorrowedFd<'_>) -> io::Result { target_os = "netbsd", target_os = "nto", target_os = "redox", + target_os = "vita", target_os = "wasi", )))] pub(crate) fn fstatfs(fd: BorrowedFd<'_>) -> io::Result { @@ -1431,7 +1505,7 @@ fn libc_statvfs_to_statvfs(from: c::statvfs) -> StatVfs { } } -#[cfg(not(target_os = "espidf"))] +#[cfg(not(any(target_os = "espidf", target_os = "vita")))] pub(crate) fn futimens(fd: BorrowedFd<'_>, times: &Timestamps) -> io::Result<()> { // Old 32-bit version: libc has `futimens` but it is not y2038 safe by // default. But there may be a `__futimens64` we can use. @@ -1507,7 +1581,11 @@ fn futimens_old(fd: BorrowedFd<'_>, times: &Timestamps) -> io::Result<()> { .tv_sec .try_into() .map_err(|_| io::Errno::OVERFLOW)?, - tv_nsec: times.last_access.tv_nsec, + tv_nsec: times + .last_access + .tv_nsec + .try_into() + .map_err(|_| io::Errno::OVERFLOW)?, }, c::timespec { tv_sec: times @@ -1515,7 +1593,11 @@ fn futimens_old(fd: BorrowedFd<'_>, times: &Timestamps) -> io::Result<()> { .tv_sec .try_into() .map_err(|_| io::Errno::OVERFLOW)?, - tv_nsec: times.last_modification.tv_nsec, + tv_nsec: times + .last_modification + .tv_nsec + .try_into() + .map_err(|_| io::Errno::OVERFLOW)?, }, ]; @@ -1531,6 +1613,7 @@ fn futimens_old(fd: BorrowedFd<'_>, times: &Timestamps) -> io::Result<()> { target_os = "espidf", target_os = "nto", target_os = "redox", + target_os = "vita", )))] pub(crate) fn fallocate( fd: BorrowedFd<'_>, @@ -1557,7 +1640,8 @@ pub(crate) fn fallocate( assert!(mode.is_empty()); let err = unsafe { c::posix_fallocate(borrowed_fd(fd), offset, len) }; - // `posix_fallocate` returns its error status rather than using `errno`. + // `posix_fallocate` returns its error status rather than using + // `errno`. if err == 0 { Ok(()) } else { @@ -1607,6 +1691,7 @@ pub(crate) fn fsync(fd: BorrowedFd<'_>) -> io::Result<()> { target_os = "espidf", target_os = "haiku", target_os = "redox", + target_os = "vita", )))] pub(crate) fn fdatasync(fd: BorrowedFd<'_>) -> io::Result<()> { unsafe { ret(c::fdatasync(borrowed_fd(fd))) } diff --git a/vendor/rustix/src/backend/libc/fs/types.rs b/vendor/rustix/src/backend/libc/fs/types.rs index cf86861dc..876757715 100644 --- a/vendor/rustix/src/backend/libc/fs/types.rs +++ b/vendor/rustix/src/backend/libc/fs/types.rs @@ -1,7 +1,7 @@ use crate::backend::c; use bitflags::bitflags; -#[cfg(not(target_os = "espidf"))] +#[cfg(not(any(target_os = "espidf", target_os = "vita")))] bitflags! { /// `*_OK` constants for use with [`accessat`]. /// @@ -21,7 +21,7 @@ bitflags! { /// `F_OK` const EXISTS = c::F_OK; - /// + /// const _ = !0; } } @@ -77,7 +77,7 @@ bitflags! { #[cfg(all(target_os = "linux", target_env = "gnu"))] const STATX_DONT_SYNC = bitcast!(c::AT_STATX_DONT_SYNC); - /// + /// const _ = !0; } } @@ -92,66 +92,66 @@ bitflags! { #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct Mode: RawMode { /// `S_IRWXU` - #[cfg(not(target_os = "espidf"))] + #[cfg(not(any(target_os = "espidf", target_os = "vita")))] const RWXU = c::S_IRWXU as RawMode; /// `S_IRUSR` - #[cfg(not(target_os = "espidf"))] + #[cfg(not(any(target_os = "espidf", target_os = "vita")))] const RUSR = c::S_IRUSR as RawMode; /// `S_IWUSR` - #[cfg(not(target_os = "espidf"))] + #[cfg(not(any(target_os = "espidf", target_os = "vita")))] const WUSR = c::S_IWUSR as RawMode; /// `S_IXUSR` - #[cfg(not(target_os = "espidf"))] + #[cfg(not(any(target_os = "espidf", target_os = "vita")))] const XUSR = c::S_IXUSR as RawMode; /// `S_IRWXG` - #[cfg(not(target_os = "espidf"))] + #[cfg(not(any(target_os = "espidf", target_os = "vita")))] const RWXG = c::S_IRWXG as RawMode; /// `S_IRGRP` - #[cfg(not(target_os = "espidf"))] + #[cfg(not(any(target_os = "espidf", target_os = "vita")))] const RGRP = c::S_IRGRP as RawMode; /// `S_IWGRP` - #[cfg(not(target_os = "espidf"))] + #[cfg(not(any(target_os = "espidf", target_os = "vita")))] const WGRP = c::S_IWGRP as RawMode; /// `S_IXGRP` - #[cfg(not(target_os = "espidf"))] + #[cfg(not(any(target_os = "espidf", target_os = "vita")))] const XGRP = c::S_IXGRP as RawMode; /// `S_IRWXO` - #[cfg(not(target_os = "espidf"))] + #[cfg(not(any(target_os = "espidf", target_os = "vita")))] const RWXO = c::S_IRWXO as RawMode; /// `S_IROTH` - #[cfg(not(target_os = "espidf"))] + #[cfg(not(any(target_os = "espidf", target_os = "vita")))] const ROTH = c::S_IROTH as RawMode; /// `S_IWOTH` - #[cfg(not(target_os = "espidf"))] + #[cfg(not(any(target_os = "espidf", target_os = "vita")))] const WOTH = c::S_IWOTH as RawMode; /// `S_IXOTH` - #[cfg(not(target_os = "espidf"))] + #[cfg(not(any(target_os = "espidf", target_os = "vita")))] const XOTH = c::S_IXOTH as RawMode; /// `S_ISUID` - #[cfg(not(target_os = "espidf"))] + #[cfg(not(any(target_os = "espidf", target_os = "vita")))] const SUID = c::S_ISUID as RawMode; /// `S_ISGID` - #[cfg(not(target_os = "espidf"))] + #[cfg(not(any(target_os = "espidf", target_os = "vita")))] const SGID = c::S_ISGID as RawMode; /// `S_ISVTX` - #[cfg(not(target_os = "espidf"))] + #[cfg(not(any(target_os = "espidf", target_os = "vita")))] const SVTX = c::S_ISVTX as RawMode; - /// + /// const _ = !0; } } @@ -213,9 +213,9 @@ bitflags! { /// Similar to `ACCMODE`, but just includes the read/write flags, and /// no other flags. /// - /// Some implementations include `O_PATH` in `O_ACCMODE`, when + /// On some platforms, `PATH` may be included in `ACCMODE`, when /// sometimes we really just want the read/write bits. Caution is - /// indicated, as the presence of `O_PATH` may mean that the read/write + /// indicated, as the presence of `PATH` may mean that the read/write /// bits don't have their usual meaning. const RWMODE = bitcast!(c::O_RDONLY | c::O_WRONLY | c::O_RDWR); @@ -231,7 +231,7 @@ bitflags! { const DIRECTORY = bitcast!(c::O_DIRECTORY); /// `O_DSYNC` - #[cfg(not(any(target_os = "dragonfly", target_os = "espidf", target_os = "l4re", target_os = "redox")))] + #[cfg(not(any(target_os = "dragonfly", target_os = "espidf", target_os = "l4re", target_os = "redox", target_os = "vita")))] const DSYNC = bitcast!(c::O_DSYNC); /// `O_EXCL` @@ -263,7 +263,7 @@ bitflags! { const RDWR = bitcast!(c::O_RDWR); /// `O_NOCTTY` - #[cfg(not(any(target_os = "espidf", target_os = "l4re", target_os = "redox")))] + #[cfg(not(any(target_os = "espidf", target_os = "l4re", target_os = "redox", target_os = "vita")))] const NOCTTY = bitcast!(c::O_NOCTTY); /// `O_RSYNC` @@ -328,7 +328,7 @@ bitflags! { #[cfg(target_os = "freebsd")] const EMPTY_PATH = bitcast!(c::O_EMPTY_PATH); - /// + /// const _ = !0; } } @@ -347,7 +347,7 @@ bitflags! { /// `CLONE_NOOWNERCOPY` const NOOWNERCOPY = 2; - /// + /// const _ = !0; } } @@ -392,7 +392,7 @@ bitflags! { /// `COPYFILE_ALL` const ALL = copyfile::ALL; - /// + /// const _ = !0; } } @@ -423,7 +423,7 @@ bitflags! { /// `RESOLVE_CACHED` (since Linux 5.12) const CACHED = 0x20; - /// + /// const _ = !0; } } @@ -445,7 +445,7 @@ bitflags! { /// `RENAME_WHITEOUT` const WHITEOUT = bitcast!(c::RENAME_WHITEOUT); - /// + /// const _ = !0; } } @@ -527,7 +527,8 @@ impl FileType { target_os = "espidf", target_os = "haiku", target_os = "nto", - target_os = "redox" + target_os = "redox", + target_os = "vita" )))] #[inline] pub(crate) const fn from_dirent_d_type(d_type: u8) -> Self { @@ -558,6 +559,7 @@ impl FileType { target_os = "espidf", target_os = "haiku", target_os = "redox", + target_os = "vita", )))] #[derive(Debug, Copy, Clone, Eq, PartialEq)] #[repr(u32)] @@ -623,7 +625,7 @@ bitflags! { /// `MFD_HUGE_16GB` const HUGE_16GB = c::MFD_HUGE_16GB; - /// + /// const _ = !0; } } @@ -638,19 +640,19 @@ bitflags! { #[repr(transparent)] #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct SealFlags: u32 { - /// `F_SEAL_SEAL`. + /// `F_SEAL_SEAL` const SEAL = bitcast!(c::F_SEAL_SEAL); - /// `F_SEAL_SHRINK`. + /// `F_SEAL_SHRINK` const SHRINK = bitcast!(c::F_SEAL_SHRINK); - /// `F_SEAL_GROW`. + /// `F_SEAL_GROW` const GROW = bitcast!(c::F_SEAL_GROW); - /// `F_SEAL_WRITE`. + /// `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); - /// + /// const _ = !0; } } @@ -711,7 +713,7 @@ bitflags! { /// `STATX_ALL` const ALL = c::STATX_ALL; - /// + /// const _ = !0; } } @@ -772,7 +774,7 @@ bitflags! { /// `STATX_ALL` const ALL = 0xfff; - /// + /// const _ = !0; } } @@ -783,7 +785,8 @@ bitflags! { target_os = "aix", target_os = "espidf", target_os = "nto", - target_os = "redox" + target_os = "redox", + target_os = "vita" )))] bitflags! { /// `FALLOC_FL_*` constants for use with [`fallocate`]. @@ -797,6 +800,7 @@ bitflags! { bsd, target_os = "aix", target_os = "haiku", + target_os = "hurd", target_os = "wasi", )))] const KEEP_SIZE = bitcast!(c::FALLOC_FL_KEEP_SIZE); @@ -805,6 +809,7 @@ bitflags! { bsd, target_os = "aix", target_os = "haiku", + target_os = "hurd", target_os = "wasi", )))] const PUNCH_HOLE = bitcast!(c::FALLOC_FL_PUNCH_HOLE); @@ -815,6 +820,7 @@ bitflags! { target_os = "emscripten", target_os = "fuchsia", target_os = "haiku", + target_os = "hurd", target_os = "l4re", target_os = "linux", target_os = "wasi", @@ -825,6 +831,7 @@ bitflags! { bsd, target_os = "aix", target_os = "haiku", + target_os = "hurd", target_os = "emscripten", target_os = "wasi", )))] @@ -834,6 +841,7 @@ bitflags! { bsd, target_os = "aix", target_os = "haiku", + target_os = "hurd", target_os = "emscripten", target_os = "wasi", )))] @@ -843,6 +851,7 @@ bitflags! { bsd, target_os = "aix", target_os = "haiku", + target_os = "hurd", target_os = "emscripten", target_os = "wasi", )))] @@ -852,12 +861,13 @@ bitflags! { bsd, target_os = "aix", target_os = "haiku", + target_os = "hurd", target_os = "emscripten", target_os = "wasi", )))] const UNSHARE_RANGE = bitcast!(c::FALLOC_FL_UNSHARE_RANGE); - /// + /// const _ = !0; } } @@ -894,11 +904,11 @@ bitflags! { const NOEXEC = c::ST_NOEXEC as u64; /// `ST_NOSUID` - #[cfg(not(target_os = "espidf"))] + #[cfg(not(any(target_os = "espidf", target_os = "vita")))] const NOSUID = c::ST_NOSUID as u64; /// `ST_RDONLY` - #[cfg(not(target_os = "espidf"))] + #[cfg(not(any(target_os = "espidf", target_os = "vita")))] const RDONLY = c::ST_RDONLY as u64; /// `ST_RELATIME` @@ -909,7 +919,7 @@ bitflags! { #[cfg(any(linux_kernel, target_os = "emscripten", target_os = "fuchsia"))] const SYNCHRONOUS = c::ST_SYNCHRONOUS as u64; - /// + /// const _ = !0; } } @@ -918,7 +928,7 @@ bitflags! { /// /// [`flock`]: crate::fs::flock /// [`fcntl_lock`]: crate::fs::fcntl_lock -#[cfg(not(any(target_os = "espidf", target_os = "wasi")))] +#[cfg(not(any(target_os = "espidf", target_os = "vita", target_os = "wasi")))] #[derive(Clone, Copy, Debug, PartialEq, Eq)] #[repr(u32)] pub enum FlockOperation { @@ -940,7 +950,7 @@ pub enum FlockOperation { /// /// [`statat`]: crate::fs::statat /// [`fstat`]: crate::fs::fstat -#[cfg(not(linux_like))] +#[cfg(not(any(linux_like, target_os = "hurd")))] pub type Stat = c::stat; /// `struct stat` for use with [`statat`] and [`fstat`]. @@ -949,6 +959,7 @@ pub type Stat = c::stat; /// [`fstat`]: crate::fs::fstat #[cfg(any( all(linux_kernel, target_pointer_width = "64"), + target_os = "hurd", target_os = "emscripten", target_os = "l4re", ))] @@ -996,6 +1007,7 @@ pub struct Stat { target_os = "netbsd", target_os = "nto", target_os = "redox", + target_os = "vita", target_os = "wasi", )))] #[allow(clippy::module_name_repetitions)] diff --git a/vendor/rustix/src/backend/libc/io/errno.rs b/vendor/rustix/src/backend/libc/io/errno.rs index 1448fe7bd..731086b4f 100644 --- a/vendor/rustix/src/backend/libc/io/errno.rs +++ b/vendor/rustix/src/backend/libc/io/errno.rs @@ -52,7 +52,9 @@ impl Errno { target_os = "aix", target_os = "espidf", target_os = "haiku", + target_os = "hurd", target_os = "l4re", + target_os = "vita", target_os = "wasi", )))] pub const ADV: Self = Self(c::EADV); @@ -74,7 +76,9 @@ impl Errno { target_os = "aix", target_os = "espidf", target_os = "haiku", + target_os = "hurd", target_os = "l4re", + target_os = "vita", target_os = "wasi", )))] pub const BADE: Self = Self(c::EBADE); @@ -87,7 +91,9 @@ impl Errno { target_os = "aix", target_os = "espidf", target_os = "haiku", + target_os = "hurd", target_os = "l4re", + target_os = "vita", target_os = "wasi", )))] pub const BADFD: Self = Self(c::EBADFD); @@ -101,7 +107,9 @@ impl Errno { target_os = "aix", target_os = "espidf", target_os = "haiku", + target_os = "hurd", target_os = "l4re", + target_os = "vita", target_os = "wasi", )))] pub const BADR: Self = Self(c::EBADR); @@ -115,7 +123,9 @@ impl Errno { target_os = "aix", target_os = "espidf", target_os = "haiku", + target_os = "hurd", target_os = "l4re", + target_os = "vita", target_os = "wasi", )))] pub const BADRQC: Self = Self(c::EBADRQC); @@ -126,7 +136,9 @@ impl Errno { target_os = "aix", target_os = "espidf", target_os = "haiku", + target_os = "hurd", target_os = "l4re", + target_os = "vita", target_os = "wasi", )))] pub const BADSLT: Self = Self(c::EBADSLT); @@ -137,7 +149,9 @@ impl Errno { target_os = "aix", target_os = "espidf", target_os = "haiku", + target_os = "hurd", target_os = "l4re", + target_os = "vita", target_os = "wasi", )))] pub const BFONT: Self = Self(c::EBFONT); @@ -159,7 +173,9 @@ impl Errno { windows, target_os = "espidf", target_os = "haiku", + target_os = "hurd", target_os = "l4re", + target_os = "vita", target_os = "wasi" )))] pub const CHRNG: Self = Self(c::ECHRNG); @@ -170,7 +186,9 @@ impl Errno { target_os = "aix", target_os = "espidf", target_os = "haiku", + target_os = "hurd", target_os = "l4re", + target_os = "vita", target_os = "wasi", )))] pub const COMM: Self = Self(c::ECOMM); @@ -191,6 +209,8 @@ impl Errno { target_os = "android", target_os = "espidf", target_os = "haiku", + target_os = "hurd", + target_os = "vita", target_os = "wasi", )))] pub const DEADLOCK: Self = Self(c::EDEADLOCK); @@ -214,8 +234,10 @@ impl Errno { target_os = "aix", target_os = "espidf", target_os = "haiku", + target_os = "hurd", target_os = "l4re", target_os = "nto", + target_os = "vita", target_os = "wasi", )))] pub const DOTDOT: Self = Self(c::EDOTDOT); @@ -246,9 +268,11 @@ impl Errno { target_os = "android", target_os = "espidf", target_os = "haiku", + target_os = "hurd", target_os = "l4re", target_os = "nto", target_os = "redox", + target_os = "vita", target_os = "wasi", )))] pub const HWPOISON: Self = Self(c::EHWPOISON); @@ -293,8 +317,10 @@ impl Errno { target_os = "aix", target_os = "espidf", target_os = "haiku", + target_os = "hurd", target_os = "l4re", target_os = "nto", + target_os = "vita", target_os = "wasi", )))] pub const ISNAM: Self = Self(c::EISNAM); @@ -306,8 +332,10 @@ impl Errno { target_os = "aix", target_os = "espidf", target_os = "haiku", + target_os = "hurd", target_os = "l4re", target_os = "nto", + target_os = "vita", target_os = "wasi", )))] pub const KEYEXPIRED: Self = Self(c::EKEYEXPIRED); @@ -319,8 +347,10 @@ impl Errno { target_os = "aix", target_os = "espidf", target_os = "haiku", + target_os = "hurd", target_os = "l4re", target_os = "nto", + target_os = "vita", target_os = "wasi", )))] pub const KEYREJECTED: Self = Self(c::EKEYREJECTED); @@ -332,8 +362,10 @@ impl Errno { target_os = "aix", target_os = "espidf", target_os = "haiku", + target_os = "hurd", target_os = "l4re", target_os = "nto", + target_os = "vita", target_os = "wasi", )))] pub const KEYREVOKED: Self = Self(c::EKEYREVOKED); @@ -343,7 +375,9 @@ impl Errno { windows, target_os = "espidf", target_os = "haiku", + target_os = "hurd", target_os = "l4re", + target_os = "vita", target_os = "wasi" )))] pub const L2HLT: Self = Self(c::EL2HLT); @@ -353,7 +387,9 @@ impl Errno { windows, target_os = "espidf", target_os = "haiku", + target_os = "hurd", target_os = "l4re", + target_os = "vita", target_os = "wasi" )))] pub const L2NSYNC: Self = Self(c::EL2NSYNC); @@ -363,7 +399,9 @@ impl Errno { windows, target_os = "espidf", target_os = "haiku", + target_os = "hurd", target_os = "l4re", + target_os = "vita", target_os = "wasi" )))] pub const L3HLT: Self = Self(c::EL3HLT); @@ -373,7 +411,9 @@ impl Errno { windows, target_os = "espidf", target_os = "haiku", + target_os = "hurd", target_os = "l4re", + target_os = "vita", target_os = "wasi" )))] pub const L3RST: Self = Self(c::EL3RST); @@ -384,7 +424,9 @@ impl Errno { target_os = "aix", target_os = "espidf", target_os = "haiku", + target_os = "hurd", target_os = "l4re", + target_os = "vita", target_os = "wasi", )))] pub const LIBACC: Self = Self(c::ELIBACC); @@ -395,7 +437,9 @@ impl Errno { target_os = "aix", target_os = "espidf", target_os = "haiku", + target_os = "hurd", target_os = "l4re", + target_os = "vita", target_os = "wasi", )))] pub const LIBBAD: Self = Self(c::ELIBBAD); @@ -407,6 +451,7 @@ impl Errno { target_os = "espidf", target_os = "haiku", target_os = "l4re", + target_os = "vita", target_os = "wasi", )))] pub const LIBEXEC: Self = Self(c::ELIBEXEC); @@ -417,7 +462,9 @@ impl Errno { target_os = "aix", target_os = "espidf", target_os = "haiku", + target_os = "hurd", target_os = "l4re", + target_os = "vita", target_os = "wasi", )))] pub const LIBMAX: Self = Self(c::ELIBMAX); @@ -428,7 +475,9 @@ impl Errno { target_os = "aix", target_os = "espidf", target_os = "haiku", + target_os = "hurd", target_os = "l4re", + target_os = "vita", target_os = "wasi", )))] pub const LIBSCN: Self = Self(c::ELIBSCN); @@ -438,7 +487,9 @@ impl Errno { windows, target_os = "espidf", target_os = "haiku", + target_os = "hurd", target_os = "l4re", + target_os = "vita", target_os = "wasi" )))] pub const LNRNG: Self = Self(c::ELNRNG); @@ -452,8 +503,10 @@ impl Errno { target_os = "aix", target_os = "espidf", target_os = "haiku", + target_os = "hurd", target_os = "l4re", target_os = "nto", + target_os = "vita", target_os = "wasi", )))] pub const MEDIUMTYPE: Self = Self(c::EMEDIUMTYPE); @@ -478,8 +531,10 @@ impl Errno { target_os = "aix", target_os = "espidf", target_os = "haiku", + target_os = "hurd", target_os = "l4re", target_os = "nto", + target_os = "vita", target_os = "wasi", )))] pub const NAVAIL: Self = Self(c::ENAVAIL); @@ -503,7 +558,9 @@ impl Errno { target_os = "aix", target_os = "espidf", target_os = "haiku", + target_os = "hurd", target_os = "l4re", + target_os = "vita", target_os = "wasi", )))] pub const NOANO: Self = Self(c::ENOANO); @@ -519,7 +576,9 @@ impl Errno { windows, target_os = "espidf", target_os = "haiku", + target_os = "hurd", target_os = "l4re", + target_os = "vita", target_os = "wasi" )))] pub const NOCSI: Self = Self(c::ENOCSI); @@ -549,8 +608,10 @@ impl Errno { target_os = "aix", target_os = "espidf", target_os = "haiku", + target_os = "hurd", target_os = "l4re", target_os = "nto", + target_os = "vita", target_os = "wasi", )))] pub const NOKEY: Self = Self(c::ENOKEY); @@ -568,8 +629,10 @@ impl Errno { target_os = "aix", target_os = "espidf", target_os = "haiku", + target_os = "hurd", target_os = "l4re", target_os = "nto", + target_os = "vita", target_os = "wasi", )))] pub const NOMEDIUM: Self = Self(c::ENOMEDIUM); @@ -589,7 +652,9 @@ impl Errno { target_os = "aix", target_os = "espidf", target_os = "haiku", + target_os = "hurd", target_os = "l4re", + target_os = "vita", target_os = "wasi", )))] pub const NONET: Self = Self(c::ENONET); @@ -600,7 +665,9 @@ impl Errno { target_os = "aix", target_os = "espidf", target_os = "haiku", + target_os = "hurd", target_os = "l4re", + target_os = "vita", target_os = "wasi", )))] pub const NOPKG: Self = Self(c::ENOPKG); @@ -634,7 +701,13 @@ impl Errno { #[cfg(not(windows))] pub const NOSYS: Self = Self(c::ENOSYS); /// `ENOTBLK` - #[cfg(not(any(windows, target_os = "espidf", target_os = "haiku", target_os = "wasi")))] + #[cfg(not(any( + windows, + target_os = "espidf", + target_os = "haiku", + target_os = "vita", + target_os = "wasi" + )))] pub const NOTBLK: Self = Self(c::ENOTBLK); /// `ENOTCAPABLE` #[cfg(any(target_os = "freebsd", target_os = "wasi"))] @@ -654,8 +727,10 @@ impl Errno { target_os = "aix", target_os = "espidf", target_os = "haiku", + target_os = "hurd", target_os = "l4re", target_os = "nto", + target_os = "vita", target_os = "wasi", )))] pub const NOTNAM: Self = Self(c::ENOTNAM); @@ -684,7 +759,9 @@ impl Errno { target_os = "aix", target_os = "espidf", target_os = "haiku", + target_os = "hurd", target_os = "l4re", + target_os = "vita", target_os = "wasi", )))] pub const NOTUNIQ: Self = Self(c::ENOTUNIQ); @@ -751,7 +828,9 @@ impl Errno { target_os = "aix", target_os = "espidf", target_os = "haiku", + target_os = "hurd", target_os = "l4re", + target_os = "vita", target_os = "wasi", )))] pub const REMCHG: Self = Self(c::EREMCHG); @@ -760,6 +839,7 @@ impl Errno { target_os = "espidf", target_os = "haiku", target_os = "l4re", + target_os = "vita", target_os = "wasi" )))] pub const REMOTE: Self = Self(c::EREMOTE); @@ -771,8 +851,10 @@ impl Errno { target_os = "aix", target_os = "espidf", target_os = "haiku", + target_os = "hurd", target_os = "l4re", target_os = "nto", + target_os = "vita", target_os = "wasi", )))] pub const REMOTEIO: Self = Self(c::EREMOTEIO); @@ -782,7 +864,9 @@ impl Errno { windows, target_os = "espidf", target_os = "haiku", + target_os = "hurd", target_os = "l4re", + target_os = "vita", target_os = "wasi" )))] pub const RESTART: Self = Self(c::ERESTART); @@ -795,9 +879,11 @@ impl Errno { target_os = "android", target_os = "espidf", target_os = "haiku", + target_os = "hurd", target_os = "l4re", target_os = "nto", target_os = "redox", + target_os = "vita", target_os = "wasi", )))] pub const RFKILL: Self = Self(c::ERFKILL); @@ -808,13 +894,19 @@ impl Errno { #[cfg(bsd)] pub const RPCMISMATCH: Self = Self(c::ERPCMISMATCH); /// `ESHUTDOWN` - #[cfg(not(any(target_os = "espidf", target_os = "l4re", target_os = "wasi")))] + #[cfg(not(any( + target_os = "espidf", + target_os = "l4re", + target_os = "vita", + target_os = "wasi" + )))] pub const SHUTDOWN: Self = Self(c::ESHUTDOWN); /// `ESOCKTNOSUPPORT` #[cfg(not(any( target_os = "espidf", target_os = "haiku", target_os = "l4re", + target_os = "vita", target_os = "wasi" )))] pub const SOCKTNOSUPPORT: Self = Self(c::ESOCKTNOSUPPORT); @@ -831,7 +923,9 @@ impl Errno { target_os = "aix", target_os = "espidf", target_os = "haiku", + target_os = "hurd", target_os = "l4re", + target_os = "vita", target_os = "wasi", )))] pub const SRMNT: Self = Self(c::ESRMNT); @@ -844,7 +938,9 @@ impl Errno { target_os = "aix", target_os = "espidf", target_os = "haiku", + target_os = "hurd", target_os = "l4re", + target_os = "vita", target_os = "wasi", )))] pub const STRPIPE: Self = Self(c::ESTRPIPE); @@ -877,8 +973,10 @@ impl Errno { target_os = "aix", target_os = "espidf", target_os = "haiku", + target_os = "hurd", target_os = "l4re", target_os = "nto", + target_os = "vita", target_os = "wasi", )))] pub const UCLEAN: Self = Self(c::EUCLEAN); @@ -888,7 +986,9 @@ impl Errno { windows, target_os = "espidf", target_os = "haiku", + target_os = "hurd", target_os = "l4re", + target_os = "vita", target_os = "wasi" )))] pub const UNATCH: Self = Self(c::EUNATCH); @@ -897,6 +997,7 @@ impl Errno { target_os = "espidf", target_os = "haiku", target_os = "l4re", + target_os = "vita", target_os = "wasi" )))] pub const USERS: Self = Self(c::EUSERS); @@ -912,7 +1013,9 @@ impl Errno { target_os = "aix", target_os = "espidf", target_os = "haiku", + target_os = "hurd", target_os = "l4re", + target_os = "vita", target_os = "wasi", )))] pub const XFULL: Self = Self(c::EXFULL); diff --git a/vendor/rustix/src/backend/libc/io/syscalls.rs b/vendor/rustix/src/backend/libc/io/syscalls.rs index 19ecfa9b6..8d5aefadc 100644 --- a/vendor/rustix/src/backend/libc/io/syscalls.rs +++ b/vendor/rustix/src/backend/libc/io/syscalls.rs @@ -9,6 +9,7 @@ use crate::fd::{AsFd, BorrowedFd, OwnedFd, RawFd}; target_os = "aix", target_os = "espidf", target_os = "nto", + target_os = "vita", target_os = "wasi" )))] use crate::io::DupFlags; @@ -51,8 +52,8 @@ pub(crate) fn pread(fd: BorrowedFd<'_>, buf: &mut [u8], offset: u64) -> io::Resu // Silently cast; we'll get `EINVAL` if the value is negative. let offset = offset as i64; - // ESP-IDF doesn't support 64-bit offsets. - #[cfg(target_os = "espidf")] + // ESP-IDF and Vita don't support 64-bit offsets. + #[cfg(any(target_os = "espidf", target_os = "vita"))] let offset: i32 = offset.try_into().map_err(|_| io::Errno::OVERFLOW)?; unsafe { @@ -71,8 +72,8 @@ pub(crate) fn pwrite(fd: BorrowedFd<'_>, buf: &[u8], offset: u64) -> io::Result< // Silently cast; we'll get `EINVAL` if the value is negative. let offset = offset as i64; - // ESP-IDF doesn't support 64-bit offsets. - #[cfg(target_os = "espidf")] + // ESP-IDF and Vita don't support 64-bit offsets. + #[cfg(any(target_os = "espidf", target_os = "vita"))] let offset: i32 = offset.try_into().map_err(|_| io::Errno::OVERFLOW)?; unsafe { ret_usize(c::pwrite(borrowed_fd(fd), buf.as_ptr().cast(), len, offset)) } @@ -105,7 +106,8 @@ pub(crate) fn writev(fd: BorrowedFd<'_>, bufs: &[IoSlice<'_>]) -> io::Result, @@ -129,7 +131,8 @@ pub(crate) fn preadv( target_os = "haiku", target_os = "nto", target_os = "redox", - target_os = "solaris" + target_os = "solaris", + target_os = "vita" )))] pub(crate) fn pwritev(fd: BorrowedFd<'_>, bufs: &[IoSlice<'_>], offset: u64) -> io::Result { // Silently cast; we'll get `EINVAL` if the value is negative. @@ -316,6 +319,7 @@ pub(crate) fn dup2(fd: BorrowedFd<'_>, new: &mut OwnedFd) -> io::Result<()> { target_os = "haiku", target_os = "nto", target_os = "redox", + target_os = "vita", target_os = "wasi", )))] pub(crate) fn dup3(fd: BorrowedFd<'_>, new: &mut OwnedFd, flags: DupFlags) -> io::Result<()> { diff --git a/vendor/rustix/src/backend/libc/io/types.rs b/vendor/rustix/src/backend/libc/io/types.rs index eaf3eae71..510206f98 100644 --- a/vendor/rustix/src/backend/libc/io/types.rs +++ b/vendor/rustix/src/backend/libc/io/types.rs @@ -12,7 +12,7 @@ bitflags! { /// `FD_CLOEXEC` const CLOEXEC = bitcast!(c::FD_CLOEXEC); - /// + /// const _ = !0; } } @@ -37,7 +37,7 @@ bitflags! { /// `RWF_APPEND` (since Linux 4.16) const APPEND = linux_raw_sys::general::RWF_APPEND; - /// + /// const _ = !0; } } @@ -59,7 +59,7 @@ bitflags! { )))] // Android 5.0 has dup3, but libc doesn't have bindings const CLOEXEC = bitcast!(c::O_CLOEXEC); - /// + /// const _ = !0; } } diff --git a/vendor/rustix/src/backend/libc/mm/syscalls.rs b/vendor/rustix/src/backend/libc/mm/syscalls.rs index 4b23a58b7..33bc9cac1 100644 --- a/vendor/rustix/src/backend/libc/mm/syscalls.rs +++ b/vendor/rustix/src/backend/libc/mm/syscalls.rs @@ -2,6 +2,8 @@ #[cfg(not(target_os = "redox"))] use super::types::Advice; +#[cfg(any(linux_kernel, freebsdlike, netbsdlike))] +use super::types::MlockAllFlags; #[cfg(any(target_os = "emscripten", target_os = "linux"))] use super::types::MremapFlags; use super::types::{MapFlags, MprotectFlags, MsyncFlags, ProtFlags}; @@ -220,3 +222,23 @@ pub(crate) unsafe fn userfaultfd(flags: UserfaultfdFlags) -> io::Result } ret_owned_fd(userfaultfd(bitflags_bits!(flags))) } + +/// Locks all pages mapped into the address space of the calling process. +/// +/// This includes the pages of the code, data, and stack segment, as well as +/// shared libraries, user space kernel data, shared memory, and memory-mapped +/// files. All mapped pages are guaranteed to be resident in RAM when the call +/// returns successfully; the pages are guaranteed to stay in RAM until later +/// unlocked. +#[inline] +#[cfg(any(linux_kernel, freebsdlike, netbsdlike))] +pub(crate) fn mlockall(flags: MlockAllFlags) -> io::Result<()> { + unsafe { ret(c::mlockall(bitflags_bits!(flags))) } +} + +/// Unlocks all pages mapped into the address space of the calling process. +#[inline] +#[cfg(any(linux_kernel, freebsdlike, netbsdlike))] +pub(crate) fn munlockall() -> io::Result<()> { + unsafe { ret(c::munlockall()) } +} diff --git a/vendor/rustix/src/backend/libc/mm/types.rs b/vendor/rustix/src/backend/libc/mm/types.rs index f0b4ad593..ef335d27a 100644 --- a/vendor/rustix/src/backend/libc/mm/types.rs +++ b/vendor/rustix/src/backend/libc/mm/types.rs @@ -17,7 +17,7 @@ bitflags! { /// `PROT_EXEC` const EXEC = bitcast!(c::PROT_EXEC); - /// + /// const _ = !0; } } @@ -59,7 +59,7 @@ bitflags! { #[cfg(all(linux_kernel, any(target_arch = "sparc", target_arch = "sparc64")))] const ADI = linux_raw_sys::general::PROT_ADI; - /// + /// const _ = !0; } } @@ -231,7 +231,7 @@ bitflags! { #[cfg(any())] const UNINITIALIZED = bitcast!(c::MAP_UNINITIALIZED); - /// + /// const _ = !0; } } @@ -250,7 +250,7 @@ bitflags! { /// `MREMAP_MAYMOVE` const MAYMOVE = bitcast!(c::MREMAP_MAYMOVE); - /// + /// const _ = !0; } } @@ -272,7 +272,7 @@ bitflags! { /// written). const INVALIDATE = bitcast!(c::MS_INVALIDATE); - /// + /// const _ = !0; } } @@ -288,7 +288,7 @@ bitflags! { /// `MLOCK_ONFAULT` const ONFAULT = bitcast!(c::MLOCK_ONFAULT); - /// + /// const _ = !0; } } @@ -438,7 +438,31 @@ bitflags! { /// `O_NONBLOCK` const NONBLOCK = bitcast!(c::O_NONBLOCK); - /// + /// + const _ = !0; + } +} + +#[cfg(any(linux_kernel, freebsdlike, netbsdlike))] +bitflags! { + /// `MCL_*` flags for use with [`mlockall`]. + /// + /// [`mlockall`]: crate::mm::mlockall + #[repr(transparent)] + #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] + pub struct MlockAllFlags: u32 { + // libc doesn't define `MCL_ONFAULT` yet. + // const ONFAULT = libc::MCL_ONFAULT; + /// Lock all pages which will become mapped into the address space of + /// the process in the future. These could be, for instance, new pages + /// required by a growing heap and stack as well as new memory-mapped + /// files or shared memory regions. + const FUTURE = bitcast!(libc::MCL_FUTURE); + /// Lock all pages which are currently mapped into the address space of + /// the process. + const CURRENT = bitcast!(libc::MCL_CURRENT); + + /// const _ = !0; } } diff --git a/vendor/rustix/src/backend/libc/mod.rs b/vendor/rustix/src/backend/libc/mod.rs index 59fc3bea1..729eb2489 100644 --- a/vendor/rustix/src/backend/libc/mod.rs +++ b/vendor/rustix/src/backend/libc/mod.rs @@ -111,7 +111,7 @@ pub(crate) mod io; #[cfg(linux_kernel)] #[cfg(feature = "io_uring")] pub(crate) mod io_uring; -#[cfg(not(any(windows, target_os = "espidf", target_os = "wasi")))] +#[cfg(not(any(windows, target_os = "espidf", target_os = "vita", target_os = "wasi")))] #[cfg(feature = "mm")] pub(crate) mod mm; #[cfg(linux_kernel)] @@ -148,7 +148,7 @@ pub(crate) mod rand; #[cfg(not(target_os = "wasi"))] #[cfg(feature = "system")] pub(crate) mod system; -#[cfg(not(windows))] +#[cfg(not(any(windows, target_os = "vita")))] #[cfg(feature = "termios")] pub(crate) mod termios; #[cfg(not(windows))] @@ -184,6 +184,15 @@ pub(crate) mod pid; #[cfg(any(feature = "process", feature = "thread"))] #[cfg(linux_kernel)] pub(crate) mod prctl; +#[cfg(not(any( + windows, + target_os = "android", + target_os = "espidf", + target_os = "vita", + target_os = "wasi" +)))] +#[cfg(feature = "shm")] +pub(crate) mod shm; #[cfg(any(feature = "fs", feature = "thread", feature = "process"))] #[cfg(not(any(windows, target_os = "wasi")))] pub(crate) mod ugid; diff --git a/vendor/rustix/src/backend/libc/mount/types.rs b/vendor/rustix/src/backend/libc/mount/types.rs index 069a94444..d4f9c2da7 100644 --- a/vendor/rustix/src/backend/libc/mount/types.rs +++ b/vendor/rustix/src/backend/libc/mount/types.rs @@ -55,7 +55,7 @@ bitflags! { /// `MS_SYNCHRONOUS` const SYNCHRONOUS = c::MS_SYNCHRONOUS; - /// + /// const _ = !0; } } @@ -77,7 +77,7 @@ bitflags! { /// `UMOUNT_NOFOLLOW` const NOFOLLOW = bitcast!(c::UMOUNT_NOFOLLOW); - /// + /// const _ = !0; } } @@ -92,9 +92,9 @@ bitflags! { #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct FsOpenFlags: c::c_uint { /// `FSOPEN_CLOEXEC` - const FSOPEN_CLOEXEC = 0x00000001; + const FSOPEN_CLOEXEC = 0x0000_0001; - /// + /// const _ = !0; } } @@ -109,9 +109,9 @@ bitflags! { #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct FsMountFlags: c::c_uint { /// `FSMOUNT_CLOEXEC` - const FSMOUNT_CLOEXEC = 0x00000001; + const FSMOUNT_CLOEXEC = 0x0000_0001; - /// + /// const _ = !0; } } @@ -157,42 +157,42 @@ bitflags! { #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct MountAttrFlags: c::c_uint { /// `MOUNT_ATTR_RDONLY` - const MOUNT_ATTR_RDONLY = 0x00000001; + const MOUNT_ATTR_RDONLY = 0x0000_0001; /// `MOUNT_ATTR_NOSUID` - const MOUNT_ATTR_NOSUID = 0x00000002; + const MOUNT_ATTR_NOSUID = 0x0000_0002; /// `MOUNT_ATTR_NODEV` - const MOUNT_ATTR_NODEV = 0x00000004; + const MOUNT_ATTR_NODEV = 0x0000_0004; /// `MOUNT_ATTR_NOEXEC` - const MOUNT_ATTR_NOEXEC = 0x00000008; + const MOUNT_ATTR_NOEXEC = 0x0000_0008; /// `MOUNT_ATTR__ATIME` - const MOUNT_ATTR__ATIME = 0x00000070; + const MOUNT_ATTR__ATIME = 0x0000_0070; /// `MOUNT_ATTR_RELATIME` - const MOUNT_ATTR_RELATIME = 0x00000000; + const MOUNT_ATTR_RELATIME = 0x0000_0000; /// `MOUNT_ATTR_NOATIME` - const MOUNT_ATTR_NOATIME = 0x00000010; + const MOUNT_ATTR_NOATIME = 0x0000_0010; /// `MOUNT_ATTR_STRICTATIME` - const MOUNT_ATTR_STRICTATIME = 0x00000020; + const MOUNT_ATTR_STRICTATIME = 0x0000_0020; /// `MOUNT_ATTR_NODIRATIME` - const MOUNT_ATTR_NODIRATIME = 0x00000080; + const MOUNT_ATTR_NODIRATIME = 0x0000_0080; /// `MOUNT_ATTR_NOUSER` - const MOUNT_ATTR_IDMAP = 0x00100000; + const MOUNT_ATTR_IDMAP = 0x0010_0000; /// `MOUNT_ATTR__ATIME_FLAGS` - const MOUNT_ATTR_NOSYMFOLLOW = 0x00200000; + const MOUNT_ATTR_NOSYMFOLLOW = 0x0020_0000; /// `MOUNT_ATTR__ATIME_FLAGS` const MOUNT_ATTR_SIZE_VER0 = 32; - /// + /// const _ = !0; } } @@ -207,34 +207,34 @@ bitflags! { #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct MoveMountFlags: c::c_uint { /// `MOVE_MOUNT_F_EMPTY_PATH` - const MOVE_MOUNT_F_SYMLINKS = 0x00000001; + const MOVE_MOUNT_F_SYMLINKS = 0x0000_0001; /// `MOVE_MOUNT_F_AUTOMOUNTS` - const MOVE_MOUNT_F_AUTOMOUNTS = 0x00000002; + const MOVE_MOUNT_F_AUTOMOUNTS = 0x0000_0002; /// `MOVE_MOUNT_F_EMPTY_PATH` - const MOVE_MOUNT_F_EMPTY_PATH = 0x00000004; + const MOVE_MOUNT_F_EMPTY_PATH = 0x0000_0004; /// `MOVE_MOUNT_T_SYMLINKS` - const MOVE_MOUNT_T_SYMLINKS = 0x00000010; + const MOVE_MOUNT_T_SYMLINKS = 0x0000_0010; /// `MOVE_MOUNT_T_AUTOMOUNTS` - const MOVE_MOUNT_T_AUTOMOUNTS = 0x00000020; + const MOVE_MOUNT_T_AUTOMOUNTS = 0x0000_0020; /// `MOVE_MOUNT_T_EMPTY_PATH` - const MOVE_MOUNT_T_EMPTY_PATH = 0x00000040; + const MOVE_MOUNT_T_EMPTY_PATH = 0x0000_0040; /// `MOVE_MOUNT__MASK` - const MOVE_MOUNT_SET_GROUP = 0x00000100; + const MOVE_MOUNT_SET_GROUP = 0x0000_0100; // TODO: add when linux 6.5 is released // /// `MOVE_MOUNT_BENEATH` - // const MOVE_MOUNT_BENEATH = 0x00000200; + // const MOVE_MOUNT_BENEATH = 0x0000_0200; /// `MOVE_MOUNT__MASK` - const MOVE_MOUNT__MASK = 0x00000377; + const MOVE_MOUNT__MASK = 0x0000_0377; - /// + /// const _ = !0; } } @@ -266,7 +266,7 @@ bitflags! { /// `AT_SYMLINK_NOFOLLOW` const AT_SYMLINK_NOFOLLOW = c::AT_SYMLINK_NOFOLLOW as c::c_uint; - /// + /// const _ = !0; } } @@ -281,18 +281,18 @@ bitflags! { #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct FsPickFlags: c::c_uint { /// `FSPICK_CLOEXEC` - const FSPICK_CLOEXEC = 0x00000001; + const FSPICK_CLOEXEC = 0x0000_0001; /// `FSPICK_SYMLINK_NOFOLLOW` - const FSPICK_SYMLINK_NOFOLLOW = 0x00000002; + const FSPICK_SYMLINK_NOFOLLOW = 0x0000_0002; /// `FSPICK_NO_AUTOMOUNT` - const FSPICK_NO_AUTOMOUNT = 0x00000004; + const FSPICK_NO_AUTOMOUNT = 0x0000_0004; /// `FSPICK_EMPTY_PATH` - const FSPICK_EMPTY_PATH = 0x00000008; + const FSPICK_EMPTY_PATH = 0x0000_0008; - /// + /// const _ = !0; } } @@ -318,7 +318,7 @@ bitflags! { /// `MS_REC` const REC = c::MS_REC; - /// + /// const _ = !0; } } @@ -331,7 +331,7 @@ bitflags! { const REMOUNT = c::MS_REMOUNT; const MOVE = c::MS_MOVE; - /// + /// const _ = !0; } } diff --git a/vendor/rustix/src/backend/libc/net/addr.rs b/vendor/rustix/src/backend/libc/net/addr.rs index 6a140d767..719a549b1 100644 --- a/vendor/rustix/src/backend/libc/net/addr.rs +++ b/vendor/rustix/src/backend/libc/net/addr.rs @@ -78,6 +78,8 @@ impl SocketAddrUnix { c::sockaddr_un { #[cfg(any(bsd, target_os = "aix", target_os = "haiku", target_os = "nto"))] sun_len: 0, + #[cfg(target_os = "vita")] + ss_len: 0, sun_family: c::AF_UNIX as _, #[cfg(any(bsd, target_os = "nto"))] sun_path: [0; 104], @@ -210,12 +212,15 @@ pub(crate) fn offsetof_sun_path() -> usize { let z = c::sockaddr_un { #[cfg(any(bsd, target_os = "aix", target_os = "haiku", target_os = "nto"))] sun_len: 0_u8, + #[cfg(target_os = "vita")] + ss_len: 0, #[cfg(any( bsd, target_os = "aix", target_os = "espidf", target_os = "haiku", - target_os = "nto" + target_os = "nto", + target_os = "vita" ))] sun_family: 0_u8, #[cfg(not(any( @@ -223,7 +228,8 @@ pub(crate) fn offsetof_sun_path() -> usize { target_os = "aix", target_os = "espidf", target_os = "haiku", - target_os = "nto" + target_os = "nto", + target_os = "vita" )))] sun_family: 0_u16, #[cfg(any(bsd, target_os = "nto"))] diff --git a/vendor/rustix/src/backend/libc/net/ext.rs b/vendor/rustix/src/backend/libc/net/ext.rs index eb7c20d7d..2e11c051d 100644 --- a/vendor/rustix/src/backend/libc/net/ext.rs +++ b/vendor/rustix/src/backend/libc/net/ext.rs @@ -83,7 +83,8 @@ pub(crate) const fn sockaddr_in6_new( target_os = "aix", target_os = "espidf", target_os = "haiku", - target_os = "nto" + target_os = "nto", + target_os = "vita" ))] sin6_len: u8, sin6_family: c::sa_family_t, @@ -98,7 +99,8 @@ pub(crate) const fn sockaddr_in6_new( target_os = "aix", target_os = "espidf", target_os = "haiku", - target_os = "nto" + target_os = "nto", + target_os = "vita" ))] sin6_len, sin6_family, @@ -108,6 +110,8 @@ pub(crate) const fn sockaddr_in6_new( sin6_scope_id, #[cfg(solarish)] __sin6_src_id: 0, + #[cfg(target_os = "vita")] + sin6_vport: 0, } } diff --git a/vendor/rustix/src/backend/libc/net/mod.rs b/vendor/rustix/src/backend/libc/net/mod.rs index 65c7d0654..d7ab68d52 100644 --- a/vendor/rustix/src/backend/libc/net/mod.rs +++ b/vendor/rustix/src/backend/libc/net/mod.rs @@ -1,8 +1,16 @@ pub(crate) mod addr; pub(crate) mod ext; -#[cfg(not(any(windows, target_os = "espidf", target_os = "redox", target_os = "wasi")))] +#[cfg(not(any( + windows, + target_os = "espidf", + target_os = "redox", + target_os = "vita", + target_os = "wasi" +)))] pub(crate) mod msghdr; pub(crate) mod read_sockaddr; pub(crate) mod send_recv; +#[cfg(not(any(target_os = "redox", target_os = "wasi")))] +pub(crate) mod sockopt; pub(crate) mod syscalls; pub(crate) mod write_sockaddr; diff --git a/vendor/rustix/src/backend/libc/net/msghdr.rs b/vendor/rustix/src/backend/libc/net/msghdr.rs index 2ccd7f20c..dd9b156a5 100644 --- a/vendor/rustix/src/backend/libc/net/msghdr.rs +++ b/vendor/rustix/src/backend/libc/net/msghdr.rs @@ -114,7 +114,7 @@ pub(crate) fn with_unix_msghdr( ) -> R { f({ let mut h = zero_msghdr(); - h.msg_name = as_ptr(addr) as _; + h.msg_name = as_ptr(&addr.unix) as _; h.msg_namelen = addr.addr_len(); h.msg_iov = iov.as_ptr() as _; h.msg_iovlen = msg_iov_len(iov.len()); diff --git a/vendor/rustix/src/backend/libc/net/read_sockaddr.rs b/vendor/rustix/src/backend/libc/net/read_sockaddr.rs index 604f24928..6da7a50dd 100644 --- a/vendor/rustix/src/backend/libc/net/read_sockaddr.rs +++ b/vendor/rustix/src/backend/libc/net/read_sockaddr.rs @@ -1,5 +1,5 @@ -//! The BSD sockets API requires us to read the `ss_family` field before -//! we can interpret the rest of a `sockaddr` produced by the kernel. +//! The BSD sockets API requires us to read the `ss_family` field before we can +//! interpret the rest of a `sockaddr` produced by the kernel. #[cfg(unix)] use super::addr::SocketAddrUnix; @@ -14,14 +14,40 @@ use core::mem::size_of; // This must match the header of `sockaddr`. #[repr(C)] struct sockaddr_header { - #[cfg(any(bsd, target_os = "haiku"))] + #[cfg(any( + bsd, + target_os = "aix", + target_os = "espidf", + target_os = "haiku", + target_os = "nto", + target_os = "vita" + ))] sa_len: u8, - #[cfg(any(bsd, target_os = "haiku"))] + #[cfg(any( + bsd, + target_os = "aix", + target_os = "espidf", + target_os = "haiku", + target_os = "nto", + target_os = "vita" + ))] ss_family: u8, - #[cfg(not(any(bsd, target_os = "haiku")))] + #[cfg(not(any( + bsd, + target_os = "aix", + target_os = "espidf", + target_os = "haiku", + target_os = "nto", + target_os = "vita" + )))] ss_family: u16, } +/// Read the `ss_family` field from a socket address returned from the OS. +/// +/// # Safety +/// +/// `storage` must point to a valid socket address returned from the OS. #[inline] unsafe fn read_ss_family(storage: *const c::sockaddr_storage) -> u16 { // Assert that we know the layout of `sockaddr`. @@ -31,7 +57,8 @@ unsafe fn read_ss_family(storage: *const c::sockaddr_storage) -> u16 { target_os = "aix", target_os = "espidf", target_os = "haiku", - target_os = "nto" + target_os = "nto", + target_os = "vita" ))] sa_len: 0_u8, #[cfg(any( @@ -39,7 +66,8 @@ unsafe fn read_ss_family(storage: *const c::sockaddr_storage) -> u16 { target_os = "aix", target_os = "espidf", target_os = "haiku", - target_os = "nto" + target_os = "nto", + target_os = "vita" ))] sa_family: 0_u8, #[cfg(not(any( @@ -47,7 +75,8 @@ unsafe fn read_ss_family(storage: *const c::sockaddr_storage) -> u16 { target_os = "aix", target_os = "espidf", target_os = "haiku", - target_os = "nto" + target_os = "nto", + target_os = "vita" )))] sa_family: 0_u16, #[cfg(not(target_os = "haiku"))] @@ -138,10 +167,10 @@ pub(crate) unsafe fn read_sockaddr( // Otherwise we expect a NUL-terminated filesystem path. // Trim off unused bytes from the end of `path_bytes`. - let path_bytes = if cfg!(target_os = "freebsd") { - // FreeBSD sometimes sets the length to longer than the length - // of the NUL-terminated string. Find the NUL and truncate the - // string accordingly. + let path_bytes = if cfg!(any(solarish, target_os = "freebsd")) { + // FreeBSD and illumos sometimes set the length to longer + // than the length of the NUL-terminated string. Find the + // NUL and truncate the string accordingly. &decode.sun_path[..decode .sun_path .iter() @@ -168,6 +197,11 @@ pub(crate) unsafe fn read_sockaddr( } } +/// Read an optional socket address returned from the OS. +/// +/// # Safety +/// +/// `storage` must point to a valid socket address returned from the OS. pub(crate) unsafe fn maybe_read_sockaddr_os( storage: *const c::sockaddr_storage, len: usize, @@ -185,6 +219,11 @@ pub(crate) unsafe fn maybe_read_sockaddr_os( } } +/// Read a socket address returned from the OS. +/// +/// # Safety +/// +/// `storage` must point to a valid socket address returned from the OS. pub(crate) unsafe fn read_sockaddr_os( storage: *const c::sockaddr_storage, len: usize, @@ -250,10 +289,10 @@ unsafe fn inner_read_sockaddr_os( assert_eq!(decode.sun_path[len - 1 - offsetof_sun_path], 0); let path_bytes = &decode.sun_path[..len - 1 - offsetof_sun_path]; - // FreeBSD sometimes sets the length to longer than the length - // of the NUL-terminated string. Find the NUL and truncate the - // string accordingly. - #[cfg(target_os = "freebsd")] + // FreeBSD and illumos sometimes set the length to longer than + // the length of the NUL-terminated string. Find the NUL and + // truncate the string accordingly. + #[cfg(any(solarish, target_os = "freebsd"))] let path_bytes = &path_bytes[..path_bytes.iter().position(|b| *b == 0).unwrap()]; SocketAddrAny::Unix( diff --git a/vendor/rustix/src/backend/libc/net/send_recv.rs b/vendor/rustix/src/backend/libc/net/send_recv.rs index 76dc97e78..5dc60ddcd 100644 --- a/vendor/rustix/src/backend/libc/net/send_recv.rs +++ b/vendor/rustix/src/backend/libc/net/send_recv.rs @@ -2,7 +2,8 @@ use crate::backend::c; use bitflags::bitflags; bitflags! { - /// `MSG_* flags for use with [`send`], [`send_to`], and related functions. + /// `MSG_*` flags for use with [`send`], [`send_to`], and related + /// functions. /// /// [`send`]: crate::net::send /// [`sendto`]: crate::net::sendto @@ -18,6 +19,7 @@ bitflags! { target_os = "espidf", target_os = "nto", target_os = "haiku", + target_os = "vita", )))] const CONFIRM = bitcast!(c::MSG_CONFIRM); /// `MSG_DONTROUTE` @@ -36,21 +38,23 @@ bitflags! { target_os = "aix", target_os = "haiku", target_os = "nto", + target_os = "vita", )))] const MORE = bitcast!(c::MSG_MORE); - #[cfg(not(any(apple, windows)))] + #[cfg(not(any(apple, windows, target_os = "vita")))] /// `MSG_NOSIGNAL` const NOSIGNAL = bitcast!(c::MSG_NOSIGNAL); /// `MSG_OOB` const OOB = bitcast!(c::MSG_OOB); - /// + /// const _ = !0; } } bitflags! { - /// `MSG_* flags for use with [`recv`], [`recvfrom`], and related functions. + /// `MSG_*` flags for use with [`recv`], [`recvfrom`], and related + /// functions. /// /// [`recv`]: crate::net::recv /// [`recvfrom`]: crate::net::recvfrom @@ -65,6 +69,7 @@ bitflags! { target_os = "espidf", target_os = "haiku", target_os = "nto", + target_os = "vita", )))] /// `MSG_CMSG_CLOEXEC` const CMSG_CLOEXEC = bitcast!(c::MSG_CMSG_CLOEXEC); @@ -80,6 +85,7 @@ bitflags! { target_os = "espidf", target_os = "haiku", target_os = "nto", + target_os = "vita", )))] const ERRQUEUE = bitcast!(c::MSG_ERRQUEUE); /// `MSG_OOB` @@ -91,7 +97,7 @@ bitflags! { /// `MSG_WAITALL` const WAITALL = bitcast!(c::MSG_WAITALL); - /// + /// const _ = !0; } } diff --git a/vendor/rustix/src/backend/libc/net/sockopt.rs b/vendor/rustix/src/backend/libc/net/sockopt.rs new file mode 100644 index 000000000..cff2ca288 --- /dev/null +++ b/vendor/rustix/src/backend/libc/net/sockopt.rs @@ -0,0 +1,1065 @@ +//! libc syscalls supporting `rustix::net::sockopt`. + +use super::ext::{in6_addr_new, in_addr_new}; +use crate::backend::c; +use crate::backend::conv::{borrowed_fd, ret}; +use crate::fd::BorrowedFd; +#[cfg(feature = "alloc")] +#[cfg(any( + linux_like, + target_os = "freebsd", + target_os = "fuchsia", + target_os = "illumos" +))] +use crate::ffi::CStr; +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", + target_os = "vita", +)))] +use crate::net::AddressFamily; +#[cfg(any( + linux_kernel, + target_os = "freebsd", + target_os = "fuchsia", + target_os = "openbsd", + target_os = "redox", + target_env = "newlib" +))] +use crate::net::Protocol; +#[cfg(any( + linux_kernel, + target_os = "freebsd", + target_os = "fuchsia", + target_os = "openbsd", + target_os = "redox", + target_env = "newlib" +))] +use crate::net::RawProtocol; +use crate::net::{Ipv4Addr, Ipv6Addr, SocketType}; +#[cfg(any(linux_kernel, target_os = "fuchsia"))] +use crate::net::{SocketAddrAny, SocketAddrStorage, SocketAddrV4}; +#[cfg(linux_kernel)] +use crate::net::{SocketAddrV6, UCred}; +use crate::utils::as_mut_ptr; +#[cfg(feature = "alloc")] +#[cfg(any( + linux_like, + target_os = "freebsd", + target_os = "fuchsia", + target_os = "illumos" +))] +use alloc::borrow::ToOwned; +#[cfg(feature = "alloc")] +#[cfg(any( + linux_like, + target_os = "freebsd", + target_os = "fuchsia", + target_os = "illumos" +))] +use alloc::string::String; +#[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::mem::{size_of, MaybeUninit}; +use core::time::Duration; +#[cfg(windows)] +use windows_sys::Win32::Foundation::BOOL; + +#[inline] +fn getsockopt(fd: BorrowedFd<'_>, level: i32, optname: i32) -> io::Result { + let mut optlen = core::mem::size_of::().try_into().unwrap(); + debug_assert!( + optlen as usize >= core::mem::size_of::(), + "Socket APIs don't ever use `bool` directly" + ); + + let mut value = MaybeUninit::::zeroed(); + getsockopt_raw(fd, level, optname, &mut value, &mut optlen)?; + + // On Windows at least, `getsockopt` has been observed writing 1 + // byte on at least (`IPPROTO_TCP`, `TCP_NODELAY`), even though + // Windows' documentation says that should write a 4-byte `BOOL`. + // So, we initialize the memory to zeros above, and just assert + // that `getsockopt` doesn't write too many bytes here. + assert!( + optlen as usize <= size_of::(), + "unexpected getsockopt size" + ); + + unsafe { Ok(value.assume_init()) } +} + +#[inline] +fn getsockopt_raw( + fd: BorrowedFd<'_>, + level: i32, + optname: i32, + value: &mut MaybeUninit, + optlen: &mut c::socklen_t, +) -> io::Result<()> { + unsafe { + ret(c::getsockopt( + borrowed_fd(fd), + level, + optname, + as_mut_ptr(value).cast(), + optlen, + )) + } +} + +#[inline] +fn setsockopt(fd: BorrowedFd<'_>, level: i32, optname: i32, value: T) -> io::Result<()> { + let optlen = core::mem::size_of::().try_into().unwrap(); + debug_assert!( + optlen as usize >= core::mem::size_of::(), + "Socket APIs don't ever use `bool` directly" + ); + setsockopt_raw(fd, level, optname, &value, optlen) +} + +#[inline] +fn setsockopt_raw( + fd: BorrowedFd<'_>, + level: i32, + optname: i32, + ptr: *const T, + optlen: c::socklen_t, +) -> io::Result<()> { + unsafe { + ret(c::setsockopt( + borrowed_fd(fd), + level, + optname, + ptr.cast(), + optlen, + )) + } +} + +#[inline] +pub(crate) fn get_socket_type(fd: BorrowedFd<'_>) -> io::Result { + getsockopt(fd, c::SOL_SOCKET, c::SO_TYPE) +} + +#[inline] +pub(crate) fn set_socket_reuseaddr(fd: BorrowedFd<'_>, reuseaddr: bool) -> io::Result<()> { + setsockopt(fd, c::SOL_SOCKET, c::SO_REUSEADDR, from_bool(reuseaddr)) +} + +#[inline] +pub(crate) fn get_socket_reuseaddr(fd: BorrowedFd<'_>) -> io::Result { + getsockopt(fd, c::SOL_SOCKET, c::SO_REUSEADDR).map(to_bool) +} + +#[inline] +pub(crate) fn set_socket_broadcast(fd: BorrowedFd<'_>, broadcast: bool) -> io::Result<()> { + setsockopt(fd, c::SOL_SOCKET, c::SO_BROADCAST, from_bool(broadcast)) +} + +#[inline] +pub(crate) fn get_socket_broadcast(fd: BorrowedFd<'_>) -> io::Result { + getsockopt(fd, c::SOL_SOCKET, c::SO_BROADCAST).map(to_bool) +} + +#[inline] +pub(crate) fn set_socket_linger(fd: BorrowedFd<'_>, linger: Option) -> io::Result<()> { + // Convert `linger` to seconds, rounding up. + let l_linger = if let Some(linger) = linger { + duration_to_secs(linger)? + } else { + 0 + }; + let linger = c::linger { + l_onoff: linger.is_some().into(), + l_linger, + }; + setsockopt(fd, c::SOL_SOCKET, c::SO_LINGER, linger) +} + +#[inline] +pub(crate) fn get_socket_linger(fd: BorrowedFd<'_>) -> io::Result> { + let linger: c::linger = getsockopt(fd, c::SOL_SOCKET, c::SO_LINGER)?; + Ok((linger.l_onoff != 0).then(|| Duration::from_secs(linger.l_linger as u64))) +} + +#[cfg(linux_kernel)] +#[inline] +pub(crate) fn set_socket_passcred(fd: BorrowedFd<'_>, passcred: bool) -> io::Result<()> { + setsockopt(fd, c::SOL_SOCKET, c::SO_PASSCRED, from_bool(passcred)) +} + +#[cfg(linux_kernel)] +#[inline] +pub(crate) fn get_socket_passcred(fd: BorrowedFd<'_>) -> io::Result { + getsockopt(fd, c::SOL_SOCKET, c::SO_PASSCRED).map(to_bool) +} + +#[inline] +pub(crate) fn set_socket_timeout( + fd: BorrowedFd<'_>, + id: Timeout, + timeout: Option, +) -> io::Result<()> { + let optname = match id { + Timeout::Recv => c::SO_RCVTIMEO, + Timeout::Send => c::SO_SNDTIMEO, + }; + + #[cfg(not(windows))] + let timeout = match timeout { + Some(timeout) => { + if timeout == Duration::ZERO { + return Err(io::Errno::INVAL); + } + + // Rust's musl libc bindings deprecated `time_t` while they + // transition to 64-bit `time_t`. What we want here is just + // “whatever type `timeval`'s `tv_sec` is”, so we're ok using + // the deprecated type. + #[allow(deprecated)] + let tv_sec = timeout.as_secs().try_into().unwrap_or(c::time_t::MAX); + + // `subsec_micros` rounds down, so we use `subsec_nanos` and + // manually round up. + let mut timeout = c::timeval { + tv_sec, + tv_usec: ((timeout.subsec_nanos() + 999) / 1000) as _, + }; + if timeout.tv_sec == 0 && timeout.tv_usec == 0 { + timeout.tv_usec = 1; + } + timeout + } + None => c::timeval { + tv_sec: 0, + tv_usec: 0, + }, + }; + + #[cfg(windows)] + let timeout: u32 = match timeout { + Some(timeout) => { + if timeout == Duration::ZERO { + return Err(io::Errno::INVAL); + } + + // `as_millis` rounds down, so we use `as_nanos` and + // manually round up. + let mut timeout: u32 = ((timeout.as_nanos() + 999_999) / 1_000_000) + .try_into() + .map_err(|_convert_err| io::Errno::INVAL)?; + if timeout == 0 { + timeout = 1; + } + timeout + } + None => 0, + }; + + setsockopt(fd, c::SOL_SOCKET, optname, timeout) +} + +#[inline] +pub(crate) fn get_socket_timeout(fd: BorrowedFd<'_>, id: Timeout) -> io::Result> { + let optname = match id { + Timeout::Recv => c::SO_RCVTIMEO, + Timeout::Send => c::SO_SNDTIMEO, + }; + + #[cfg(not(windows))] + { + let timeout: c::timeval = getsockopt(fd, c::SOL_SOCKET, optname)?; + if timeout.tv_sec == 0 && timeout.tv_usec == 0 { + Ok(None) + } else { + Ok(Some( + Duration::from_secs(timeout.tv_sec as u64) + + Duration::from_micros(timeout.tv_usec as u64), + )) + } + } + + #[cfg(windows)] + { + let timeout: u32 = getsockopt(fd, c::SOL_SOCKET, optname)?; + if timeout == 0 { + Ok(None) + } else { + Ok(Some(Duration::from_millis(timeout as u64))) + } + } +} + +#[cfg(any(apple, freebsdlike, target_os = "netbsd"))] +#[inline] +pub(crate) fn get_socket_nosigpipe(fd: BorrowedFd<'_>) -> io::Result { + getsockopt(fd, c::SOL_SOCKET, c::SO_NOSIGPIPE).map(to_bool) +} + +#[cfg(any(apple, freebsdlike, target_os = "netbsd"))] +#[inline] +pub(crate) fn set_socket_nosigpipe(fd: BorrowedFd<'_>, val: bool) -> io::Result<()> { + setsockopt(fd, c::SOL_SOCKET, c::SO_NOSIGPIPE, from_bool(val)) +} + +#[inline] +pub(crate) fn get_socket_error(fd: BorrowedFd<'_>) -> io::Result> { + let err: c::c_int = getsockopt(fd, c::SOL_SOCKET, c::SO_ERROR)?; + Ok(if err == 0 { + Ok(()) + } else { + Err(io::Errno::from_raw_os_error(err)) + }) +} + +#[inline] +pub(crate) fn set_socket_keepalive(fd: BorrowedFd<'_>, keepalive: bool) -> io::Result<()> { + setsockopt(fd, c::SOL_SOCKET, c::SO_KEEPALIVE, from_bool(keepalive)) +} + +#[inline] +pub(crate) fn get_socket_keepalive(fd: BorrowedFd<'_>) -> io::Result { + getsockopt(fd, c::SOL_SOCKET, c::SO_KEEPALIVE).map(to_bool) +} + +#[inline] +pub(crate) fn set_socket_recv_buffer_size(fd: BorrowedFd<'_>, size: usize) -> io::Result<()> { + let size: c::c_int = size.try_into().map_err(|_| io::Errno::INVAL)?; + setsockopt(fd, c::SOL_SOCKET, c::SO_RCVBUF, size) +} + +#[inline] +pub(crate) fn get_socket_recv_buffer_size(fd: BorrowedFd<'_>) -> io::Result { + getsockopt(fd, c::SOL_SOCKET, c::SO_RCVBUF).map(|size: u32| size as usize) +} + +#[inline] +pub(crate) fn set_socket_send_buffer_size(fd: BorrowedFd<'_>, size: usize) -> io::Result<()> { + let size: c::c_int = size.try_into().map_err(|_| io::Errno::INVAL)?; + setsockopt(fd, c::SOL_SOCKET, c::SO_SNDBUF, size) +} + +#[inline] +pub(crate) fn get_socket_send_buffer_size(fd: BorrowedFd<'_>) -> io::Result { + getsockopt(fd, c::SOL_SOCKET, c::SO_SNDBUF).map(|size: u32| size as usize) +} + +#[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", + target_os = "vita", +)))] +pub(crate) fn get_socket_domain(fd: BorrowedFd<'_>) -> io::Result { + let domain: c::c_int = getsockopt(fd, c::SOL_SOCKET, 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 { + getsockopt(fd, c::SOL_SOCKET, c::SO_ACCEPTCONN).map(to_bool) +} + +#[inline] +pub(crate) fn set_socket_oobinline(fd: BorrowedFd<'_>, value: bool) -> io::Result<()> { + setsockopt(fd, c::SOL_SOCKET, c::SO_OOBINLINE, from_bool(value)) +} + +#[inline] +pub(crate) fn get_socket_oobinline(fd: BorrowedFd<'_>) -> io::Result { + getsockopt(fd, c::SOL_SOCKET, c::SO_OOBINLINE).map(to_bool) +} + +#[cfg(not(any(solarish, windows)))] +#[inline] +pub(crate) fn set_socket_reuseport(fd: BorrowedFd<'_>, value: bool) -> io::Result<()> { + setsockopt(fd, c::SOL_SOCKET, c::SO_REUSEPORT, from_bool(value)) +} + +#[cfg(not(any(solarish, windows)))] +#[inline] +pub(crate) fn get_socket_reuseport(fd: BorrowedFd<'_>) -> io::Result { + getsockopt(fd, c::SOL_SOCKET, c::SO_REUSEPORT).map(to_bool) +} + +#[cfg(target_os = "freebsd")] +#[inline] +pub(crate) fn set_socket_reuseport_lb(fd: BorrowedFd<'_>, value: bool) -> io::Result<()> { + setsockopt(fd, c::SOL_SOCKET, c::SO_REUSEPORT_LB, from_bool(value)) +} + +#[cfg(target_os = "freebsd")] +#[inline] +pub(crate) fn get_socket_reuseport_lb(fd: BorrowedFd<'_>) -> io::Result { + getsockopt(fd, c::SOL_SOCKET, c::SO_REUSEPORT_LB).map(to_bool) +} + +#[cfg(any( + linux_kernel, + target_os = "freebsd", + target_os = "fuchsia", + target_os = "openbsd", + target_os = "redox", + target_env = "newlib" +))] +#[inline] +pub(crate) fn get_socket_protocol(fd: BorrowedFd<'_>) -> io::Result> { + getsockopt(fd, c::SOL_SOCKET, c::SO_PROTOCOL) + .map(|raw| RawProtocol::new(raw).map(Protocol::from_raw)) +} + +#[cfg(target_os = "linux")] +#[inline] +pub(crate) fn get_socket_cookie(fd: BorrowedFd<'_>) -> io::Result { + getsockopt(fd, c::SOL_SOCKET, c::SO_COOKIE) +} + +#[cfg(target_os = "linux")] +#[inline] +pub(crate) fn get_socket_incoming_cpu(fd: BorrowedFd<'_>) -> io::Result { + getsockopt(fd, c::SOL_SOCKET, c::SO_INCOMING_CPU) +} + +#[cfg(target_os = "linux")] +#[inline] +pub(crate) fn set_socket_incoming_cpu(fd: BorrowedFd<'_>, value: u32) -> io::Result<()> { + setsockopt(fd, c::SOL_SOCKET, c::SO_INCOMING_CPU, value) +} + +#[inline] +pub(crate) fn set_ip_ttl(fd: BorrowedFd<'_>, ttl: u32) -> io::Result<()> { + setsockopt(fd, c::IPPROTO_IP, c::IP_TTL, ttl) +} + +#[inline] +pub(crate) fn get_ip_ttl(fd: BorrowedFd<'_>) -> io::Result { + getsockopt(fd, c::IPPROTO_IP, c::IP_TTL) +} + +#[inline] +pub(crate) fn set_ipv6_v6only(fd: BorrowedFd<'_>, only_v6: bool) -> io::Result<()> { + setsockopt(fd, c::IPPROTO_IPV6, c::IPV6_V6ONLY, from_bool(only_v6)) +} + +#[inline] +pub(crate) fn get_ipv6_v6only(fd: BorrowedFd<'_>) -> io::Result { + getsockopt(fd, c::IPPROTO_IPV6, c::IPV6_V6ONLY).map(to_bool) +} + +#[inline] +pub(crate) fn set_ip_multicast_loop(fd: BorrowedFd<'_>, multicast_loop: bool) -> io::Result<()> { + setsockopt( + fd, + c::IPPROTO_IP, + c::IP_MULTICAST_LOOP, + from_bool(multicast_loop), + ) +} + +#[inline] +pub(crate) fn get_ip_multicast_loop(fd: BorrowedFd<'_>) -> io::Result { + getsockopt(fd, c::IPPROTO_IP, c::IP_MULTICAST_LOOP).map(to_bool) +} + +#[inline] +pub(crate) fn set_ip_multicast_ttl(fd: BorrowedFd<'_>, multicast_ttl: u32) -> io::Result<()> { + setsockopt(fd, c::IPPROTO_IP, c::IP_MULTICAST_TTL, multicast_ttl) +} + +#[inline] +pub(crate) fn get_ip_multicast_ttl(fd: BorrowedFd<'_>) -> io::Result { + getsockopt(fd, c::IPPROTO_IP, c::IP_MULTICAST_TTL) +} + +#[inline] +pub(crate) fn set_ipv6_multicast_loop(fd: BorrowedFd<'_>, multicast_loop: bool) -> io::Result<()> { + setsockopt( + fd, + c::IPPROTO_IPV6, + c::IPV6_MULTICAST_LOOP, + from_bool(multicast_loop), + ) +} + +#[inline] +pub(crate) fn get_ipv6_multicast_loop(fd: BorrowedFd<'_>) -> io::Result { + getsockopt(fd, c::IPPROTO_IPV6, c::IPV6_MULTICAST_LOOP).map(to_bool) +} + +#[inline] +pub(crate) fn set_ipv6_multicast_hops(fd: BorrowedFd<'_>, multicast_hops: u32) -> io::Result<()> { + setsockopt(fd, c::IPPROTO_IP, c::IPV6_MULTICAST_HOPS, multicast_hops) +} + +#[inline] +pub(crate) fn get_ipv6_multicast_hops(fd: BorrowedFd<'_>) -> io::Result { + getsockopt(fd, c::IPPROTO_IP, c::IPV6_MULTICAST_HOPS) +} + +#[inline] +pub(crate) fn set_ip_add_membership( + fd: BorrowedFd<'_>, + multiaddr: &Ipv4Addr, + interface: &Ipv4Addr, +) -> io::Result<()> { + let mreq = to_ip_mreq(multiaddr, interface); + setsockopt(fd, c::IPPROTO_IP, c::IP_ADD_MEMBERSHIP, mreq) +} + +#[cfg(any( + apple, + freebsdlike, + linux_like, + target_os = "fuchsia", + target_os = "openbsd" +))] +#[inline] +pub(crate) fn set_ip_add_membership_with_ifindex( + fd: BorrowedFd<'_>, + multiaddr: &Ipv4Addr, + address: &Ipv4Addr, + ifindex: i32, +) -> io::Result<()> { + let mreqn = to_ip_mreqn(multiaddr, address, ifindex); + setsockopt(fd, c::IPPROTO_IP, c::IP_ADD_MEMBERSHIP, mreqn) +} + +#[cfg(any(apple, freebsdlike, linux_like, solarish, target_os = "aix"))] +#[inline] +pub(crate) fn set_ip_add_source_membership( + fd: BorrowedFd<'_>, + multiaddr: &Ipv4Addr, + interface: &Ipv4Addr, + sourceaddr: &Ipv4Addr, +) -> io::Result<()> { + let mreq_source = to_imr_source(multiaddr, interface, sourceaddr); + setsockopt(fd, c::IPPROTO_IP, c::IP_ADD_SOURCE_MEMBERSHIP, mreq_source) +} + +#[cfg(any(apple, freebsdlike, linux_like, solarish, target_os = "aix"))] +#[inline] +pub(crate) fn set_ip_drop_source_membership( + fd: BorrowedFd<'_>, + multiaddr: &Ipv4Addr, + interface: &Ipv4Addr, + sourceaddr: &Ipv4Addr, +) -> io::Result<()> { + let mreq_source = to_imr_source(multiaddr, interface, sourceaddr); + setsockopt(fd, c::IPPROTO_IP, c::IP_DROP_SOURCE_MEMBERSHIP, mreq_source) +} + +#[inline] +pub(crate) fn set_ipv6_add_membership( + fd: BorrowedFd<'_>, + multiaddr: &Ipv6Addr, + interface: u32, +) -> io::Result<()> { + #[cfg(not(any( + bsd, + solarish, + target_os = "haiku", + target_os = "l4re", + target_os = "nto" + )))] + use c::IPV6_ADD_MEMBERSHIP; + #[cfg(any( + bsd, + solarish, + target_os = "haiku", + target_os = "l4re", + target_os = "nto" + ))] + use c::IPV6_JOIN_GROUP as IPV6_ADD_MEMBERSHIP; + + let mreq = to_ipv6mr(multiaddr, interface); + setsockopt(fd, c::IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, mreq) +} + +#[inline] +pub(crate) fn set_ip_drop_membership( + fd: BorrowedFd<'_>, + multiaddr: &Ipv4Addr, + interface: &Ipv4Addr, +) -> io::Result<()> { + let mreq = to_ip_mreq(multiaddr, interface); + setsockopt(fd, c::IPPROTO_IP, c::IP_DROP_MEMBERSHIP, mreq) +} + +#[cfg(any( + apple, + freebsdlike, + linux_like, + target_os = "fuchsia", + target_os = "openbsd" +))] +#[inline] +pub(crate) fn set_ip_drop_membership_with_ifindex( + fd: BorrowedFd<'_>, + multiaddr: &Ipv4Addr, + address: &Ipv4Addr, + ifindex: i32, +) -> io::Result<()> { + let mreqn = to_ip_mreqn(multiaddr, address, ifindex); + setsockopt(fd, c::IPPROTO_IP, c::IP_DROP_MEMBERSHIP, mreqn) +} + +#[inline] +pub(crate) fn set_ipv6_drop_membership( + fd: BorrowedFd<'_>, + multiaddr: &Ipv6Addr, + interface: u32, +) -> io::Result<()> { + #[cfg(not(any( + bsd, + solarish, + target_os = "haiku", + target_os = "l4re", + target_os = "nto" + )))] + use c::IPV6_DROP_MEMBERSHIP; + #[cfg(any( + bsd, + solarish, + target_os = "haiku", + target_os = "l4re", + target_os = "nto" + ))] + use c::IPV6_LEAVE_GROUP as IPV6_DROP_MEMBERSHIP; + + let mreq = to_ipv6mr(multiaddr, interface); + setsockopt(fd, c::IPPROTO_IPV6, IPV6_DROP_MEMBERSHIP, mreq) +} + +#[inline] +pub(crate) fn get_ipv6_unicast_hops(fd: BorrowedFd<'_>) -> io::Result { + getsockopt(fd, c::IPPROTO_IPV6, c::IPV6_UNICAST_HOPS).map(|hops: c::c_int| hops as u8) +} + +#[inline] +pub(crate) fn set_ipv6_unicast_hops(fd: BorrowedFd<'_>, hops: Option) -> io::Result<()> { + let hops = match hops { + Some(hops) => hops as c::c_int, + None => -1, + }; + setsockopt(fd, c::IPPROTO_IPV6, c::IPV6_UNICAST_HOPS, hops) +} + +#[cfg(any( + bsd, + linux_like, + target_os = "aix", + target_os = "fuchsia", + target_os = "haiku", + target_os = "nto", + target_env = "newlib" +))] +#[inline] +pub(crate) fn set_ip_tos(fd: BorrowedFd<'_>, value: u8) -> io::Result<()> { + setsockopt(fd, c::IPPROTO_IP, c::IP_TOS, i32::from(value)) +} + +#[cfg(any( + bsd, + linux_like, + target_os = "aix", + target_os = "fuchsia", + target_os = "haiku", + target_os = "nto", + target_env = "newlib" +))] +#[inline] +pub(crate) fn get_ip_tos(fd: BorrowedFd<'_>) -> io::Result { + let value: i32 = getsockopt(fd, c::IPPROTO_IP, c::IP_TOS)?; + Ok(value as u8) +} + +#[cfg(any(apple, linux_like, target_os = "freebsd", target_os = "fuchsia"))] +#[inline] +pub(crate) fn set_ip_recvtos(fd: BorrowedFd<'_>, value: bool) -> io::Result<()> { + setsockopt(fd, c::IPPROTO_IP, c::IP_RECVTOS, from_bool(value)) +} + +#[cfg(any(apple, linux_like, target_os = "freebsd", target_os = "fuchsia"))] +#[inline] +pub(crate) fn get_ip_recvtos(fd: BorrowedFd<'_>) -> io::Result { + getsockopt(fd, c::IPPROTO_IP, c::IP_RECVTOS).map(to_bool) +} + +#[cfg(any( + bsd, + linux_like, + target_os = "aix", + target_os = "fuchsia", + target_os = "nto" +))] +#[inline] +pub(crate) fn set_ipv6_recvtclass(fd: BorrowedFd<'_>, value: bool) -> io::Result<()> { + setsockopt(fd, c::IPPROTO_IPV6, c::IPV6_RECVTCLASS, from_bool(value)) +} + +#[cfg(any( + bsd, + linux_like, + target_os = "aix", + target_os = "fuchsia", + target_os = "nto" +))] +#[inline] +pub(crate) fn get_ipv6_recvtclass(fd: BorrowedFd<'_>) -> io::Result { + getsockopt(fd, c::IPPROTO_IPV6, c::IPV6_RECVTCLASS).map(to_bool) +} + +#[cfg(any(linux_kernel, target_os = "fuchsia"))] +#[inline] +pub(crate) fn set_ip_freebind(fd: BorrowedFd<'_>, value: bool) -> io::Result<()> { + setsockopt(fd, c::IPPROTO_IP, c::IP_FREEBIND, from_bool(value)) +} + +#[cfg(any(linux_kernel, target_os = "fuchsia"))] +#[inline] +pub(crate) fn get_ip_freebind(fd: BorrowedFd<'_>) -> io::Result { + getsockopt(fd, c::IPPROTO_IP, c::IP_FREEBIND).map(to_bool) +} + +#[cfg(linux_kernel)] +#[inline] +pub(crate) fn set_ipv6_freebind(fd: BorrowedFd<'_>, value: bool) -> io::Result<()> { + setsockopt(fd, c::IPPROTO_IPV6, c::IPV6_FREEBIND, from_bool(value)) +} + +#[cfg(linux_kernel)] +#[inline] +pub(crate) fn get_ipv6_freebind(fd: BorrowedFd<'_>) -> io::Result { + getsockopt(fd, c::IPPROTO_IPV6, c::IPV6_FREEBIND).map(to_bool) +} + +#[cfg(any(linux_kernel, target_os = "fuchsia"))] +#[inline] +pub(crate) fn get_ip_original_dst(fd: BorrowedFd<'_>) -> io::Result { + let level = c::IPPROTO_IP; + let optname = c::SO_ORIGINAL_DST; + let mut value = MaybeUninit::::uninit(); + let mut optlen = core::mem::size_of_val(&value).try_into().unwrap(); + + getsockopt_raw(fd, level, optname, &mut value, &mut optlen)?; + + let any = unsafe { SocketAddrAny::read(value.as_ptr(), optlen as usize)? }; + match any { + SocketAddrAny::V4(v4) => Ok(v4), + _ => unreachable!(), + } +} + +#[cfg(linux_kernel)] +#[inline] +pub(crate) fn get_ipv6_original_dst(fd: BorrowedFd<'_>) -> io::Result { + let level = c::IPPROTO_IPV6; + let optname = c::IP6T_SO_ORIGINAL_DST; + let mut value = MaybeUninit::::uninit(); + let mut optlen = core::mem::size_of_val(&value).try_into().unwrap(); + + getsockopt_raw(fd, level, optname, &mut value, &mut optlen)?; + + let any = unsafe { SocketAddrAny::read(value.as_ptr(), optlen as usize)? }; + match any { + SocketAddrAny::V6(v6) => Ok(v6), + _ => unreachable!(), + } +} + +#[cfg(not(any( + solarish, + windows, + target_os = "espidf", + target_os = "haiku", + target_os = "vita" +)))] +#[inline] +pub(crate) fn set_ipv6_tclass(fd: BorrowedFd<'_>, value: u32) -> io::Result<()> { + setsockopt(fd, c::IPPROTO_IPV6, c::IPV6_TCLASS, value) +} + +#[cfg(not(any( + solarish, + windows, + target_os = "espidf", + target_os = "haiku", + target_os = "vita" +)))] +#[inline] +pub(crate) fn get_ipv6_tclass(fd: BorrowedFd<'_>) -> io::Result { + getsockopt(fd, c::IPPROTO_IPV6, c::IPV6_TCLASS) +} + +#[inline] +pub(crate) fn set_tcp_nodelay(fd: BorrowedFd<'_>, nodelay: bool) -> io::Result<()> { + setsockopt(fd, c::IPPROTO_TCP, c::TCP_NODELAY, from_bool(nodelay)) +} + +#[inline] +pub(crate) fn get_tcp_nodelay(fd: BorrowedFd<'_>) -> io::Result { + getsockopt(fd, c::IPPROTO_TCP, c::TCP_NODELAY).map(to_bool) +} + +#[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, 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 { + getsockopt(fd, c::IPPROTO_TCP, 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, 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 { + let secs: c::c_uint = getsockopt(fd, c::IPPROTO_TCP, 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, 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 { + let secs: c::c_uint = getsockopt(fd, c::IPPROTO_TCP, c::TCP_KEEPINTVL)?; + Ok(Duration::from_secs(secs as u64)) +} + +#[inline] +#[cfg(any(linux_like, target_os = "fuchsia"))] +pub(crate) fn set_tcp_user_timeout(fd: BorrowedFd<'_>, value: u32) -> io::Result<()> { + setsockopt(fd, c::IPPROTO_TCP, c::TCP_USER_TIMEOUT, value) +} + +#[inline] +#[cfg(any(linux_like, target_os = "fuchsia"))] +pub(crate) fn get_tcp_user_timeout(fd: BorrowedFd<'_>) -> io::Result { + getsockopt(fd, c::IPPROTO_TCP, c::TCP_USER_TIMEOUT) +} + +#[cfg(any(linux_like, target_os = "fuchsia"))] +#[inline] +pub(crate) fn set_tcp_quickack(fd: BorrowedFd<'_>, value: bool) -> io::Result<()> { + setsockopt(fd, c::IPPROTO_TCP, c::TCP_QUICKACK, from_bool(value)) +} + +#[cfg(any(linux_like, target_os = "fuchsia"))] +#[inline] +pub(crate) fn get_tcp_quickack(fd: BorrowedFd<'_>) -> io::Result { + getsockopt(fd, c::IPPROTO_TCP, c::TCP_QUICKACK).map(to_bool) +} + +#[cfg(any( + linux_like, + target_os = "freebsd", + target_os = "fuchsia", + target_os = "illumos" +))] +#[inline] +pub(crate) fn set_tcp_congestion(fd: BorrowedFd<'_>, value: &str) -> io::Result<()> { + let level = c::IPPROTO_TCP; + let optname = c::TCP_CONGESTION; + let optlen = value.len().try_into().unwrap(); + setsockopt_raw(fd, level, optname, value.as_ptr(), optlen) +} + +#[cfg(feature = "alloc")] +#[cfg(any( + linux_like, + target_os = "freebsd", + target_os = "fuchsia", + target_os = "illumos" +))] +#[inline] +pub(crate) fn get_tcp_congestion(fd: BorrowedFd<'_>) -> io::Result { + let level = c::IPPROTO_TCP; + let optname = c::TCP_CONGESTION; + const OPTLEN: c::socklen_t = 16; + let mut value = MaybeUninit::<[MaybeUninit; OPTLEN as usize]>::uninit(); + let mut optlen = OPTLEN; + getsockopt_raw(fd, level, optname, &mut value, &mut optlen)?; + unsafe { + let value = value.assume_init(); + let slice: &[u8] = core::mem::transmute(&value[..optlen as usize]); + assert!(slice.iter().any(|b| *b == b'\0')); + Ok( + core::str::from_utf8(CStr::from_ptr(slice.as_ptr().cast()).to_bytes()) + .unwrap() + .to_owned(), + ) + } +} + +#[cfg(any(linux_like, target_os = "fuchsia"))] +#[inline] +pub(crate) fn set_tcp_thin_linear_timeouts(fd: BorrowedFd<'_>, value: bool) -> io::Result<()> { + setsockopt( + fd, + c::IPPROTO_TCP, + c::TCP_THIN_LINEAR_TIMEOUTS, + from_bool(value), + ) +} + +#[cfg(any(linux_like, target_os = "fuchsia"))] +#[inline] +pub(crate) fn get_tcp_thin_linear_timeouts(fd: BorrowedFd<'_>) -> io::Result { + getsockopt(fd, c::IPPROTO_TCP, c::TCP_THIN_LINEAR_TIMEOUTS).map(to_bool) +} + +#[cfg(any(linux_like, solarish, target_os = "fuchsia"))] +#[inline] +pub(crate) fn set_tcp_cork(fd: BorrowedFd<'_>, value: bool) -> io::Result<()> { + setsockopt(fd, c::IPPROTO_TCP, c::TCP_CORK, from_bool(value)) +} + +#[cfg(any(linux_like, solarish, target_os = "fuchsia"))] +#[inline] +pub(crate) fn get_tcp_cork(fd: BorrowedFd<'_>) -> io::Result { + getsockopt(fd, c::IPPROTO_TCP, c::TCP_CORK).map(to_bool) +} + +#[cfg(linux_kernel)] +#[inline] +pub(crate) fn get_socket_peercred(fd: BorrowedFd<'_>) -> io::Result { + getsockopt(fd, c::SOL_SOCKET, c::SO_PEERCRED) +} + +#[inline] +fn to_ip_mreq(multiaddr: &Ipv4Addr, interface: &Ipv4Addr) -> c::ip_mreq { + c::ip_mreq { + imr_multiaddr: to_imr_addr(multiaddr), + imr_interface: to_imr_addr(interface), + } +} + +#[cfg(any( + apple, + freebsdlike, + linux_like, + target_os = "fuchsia", + target_os = "openbsd" +))] +#[inline] +fn to_ip_mreqn(multiaddr: &Ipv4Addr, address: &Ipv4Addr, ifindex: i32) -> c::ip_mreqn { + c::ip_mreqn { + imr_multiaddr: to_imr_addr(multiaddr), + imr_address: to_imr_addr(address), + imr_ifindex: ifindex, + } +} + +#[cfg(any(apple, freebsdlike, linux_like, solarish, target_os = "aix"))] +#[inline] +fn to_imr_source( + multiaddr: &Ipv4Addr, + interface: &Ipv4Addr, + sourceaddr: &Ipv4Addr, +) -> c::ip_mreq_source { + c::ip_mreq_source { + imr_multiaddr: to_imr_addr(multiaddr), + imr_interface: to_imr_addr(interface), + imr_sourceaddr: to_imr_addr(sourceaddr), + } +} + +#[inline] +fn to_imr_addr(addr: &Ipv4Addr) -> c::in_addr { + in_addr_new(u32::from_ne_bytes(addr.octets())) +} + +#[inline] +fn to_ipv6mr(multiaddr: &Ipv6Addr, interface: u32) -> c::ipv6_mreq { + c::ipv6_mreq { + ipv6mr_multiaddr: to_ipv6mr_multiaddr(multiaddr), + ipv6mr_interface: to_ipv6mr_interface(interface), + } +} + +#[inline] +fn to_ipv6mr_multiaddr(multiaddr: &Ipv6Addr) -> c::in6_addr { + in6_addr_new(multiaddr.octets()) +} + +#[cfg(target_os = "android")] +#[inline] +fn to_ipv6mr_interface(interface: u32) -> c::c_int { + interface as c::c_int +} + +#[cfg(not(target_os = "android"))] +#[inline] +fn to_ipv6mr_interface(interface: u32) -> c::c_uint { + interface as c::c_uint +} + +// `getsockopt` and `setsockopt` represent boolean values as integers. +#[cfg(not(windows))] +type RawSocketBool = c::c_int; +#[cfg(windows)] +type RawSocketBool = BOOL; + +// Wrap `RawSocketBool` in a newtype to discourage misuse. +#[repr(transparent)] +#[derive(Copy, Clone)] +struct SocketBool(RawSocketBool); + +// Convert from a `bool` to a `SocketBool`. +#[inline] +fn from_bool(value: bool) -> SocketBool { + SocketBool(value.into()) +} + +// Convert from a `SocketBool` to a `bool`. +#[inline] +fn to_bool(value: SocketBool) -> bool { + value.0 != 0 +} + +/// Convert to seconds, rounding up if necessary. +#[inline] +fn duration_to_secs>(duration: Duration) -> io::Result { + 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/syscalls.rs b/vendor/rustix/src/backend/libc/net/syscalls.rs index 2e968ba3e..97b862033 100644 --- a/vendor/rustix/src/backend/libc/net/syscalls.rs +++ b/vendor/rustix/src/backend/libc/net/syscalls.rs @@ -2,7 +2,6 @@ #[cfg(unix)] use super::addr::SocketAddrUnix; -use super::ext::{in6_addr_new, in_addr_new}; use crate::backend::c; use crate::backend::conv::{borrowed_fd, ret, ret_owned_fd, ret_send_recv, send_recv_len}; use crate::fd::{BorrowedFd, OwnedFd}; @@ -10,7 +9,13 @@ use crate::io; use crate::net::{SocketAddrAny, SocketAddrV4, SocketAddrV6}; use crate::utils::as_ptr; use core::mem::{size_of, MaybeUninit}; -#[cfg(not(any(windows, target_os = "espidf", target_os = "redox", target_os = "wasi")))] +#[cfg(not(any( + windows, + target_os = "espidf", + target_os = "redox", + target_os = "vita", + target_os = "wasi" +)))] use { super::msghdr::{with_noaddr_msghdr, with_recv_msghdr, with_v4_msghdr, with_v6_msghdr}, crate::io::{IoSlice, IoSliceMut}, @@ -243,6 +248,19 @@ pub(crate) fn connect_unix(sockfd: BorrowedFd<'_>, addr: &SocketAddrUnix) -> io: } } +#[cfg(not(any(target_os = "redox", target_os = "wasi")))] +pub(crate) fn connect_unspec(sockfd: BorrowedFd<'_>) -> io::Result<()> { + debug_assert_eq!(c::AF_UNSPEC, 0); + let addr = MaybeUninit::::zeroed(); + unsafe { + ret(c::connect( + borrowed_fd(sockfd), + as_ptr(&addr).cast(), + size_of::() as c::socklen_t, + )) + } +} + #[cfg(not(any(target_os = "redox", target_os = "wasi")))] pub(crate) fn listen(sockfd: BorrowedFd<'_>, backlog: c::c_int) -> io::Result<()> { unsafe { ret(c::listen(borrowed_fd(sockfd), backlog)) } @@ -256,7 +274,13 @@ pub(crate) fn accept(sockfd: BorrowedFd<'_>) -> io::Result { } } -#[cfg(not(any(windows, target_os = "espidf", target_os = "redox", target_os = "wasi")))] +#[cfg(not(any( + windows, + target_os = "espidf", + target_os = "redox", + target_os = "vita", + target_os = "wasi" +)))] pub(crate) fn recvmsg( sockfd: BorrowedFd<'_>, iov: &mut [IoSliceMut<'_>], @@ -288,7 +312,13 @@ pub(crate) fn recvmsg( }) } -#[cfg(not(any(windows, target_os = "espidf", target_os = "redox", target_os = "wasi")))] +#[cfg(not(any( + windows, + target_os = "espidf", + target_os = "redox", + target_os = "vita", + target_os = "wasi" +)))] pub(crate) fn sendmsg( sockfd: BorrowedFd<'_>, iov: &[IoSlice<'_>], @@ -304,7 +334,13 @@ pub(crate) fn sendmsg( }) } -#[cfg(not(any(windows, target_os = "espidf", target_os = "redox", target_os = "wasi")))] +#[cfg(not(any( + windows, + target_os = "espidf", + target_os = "redox", + target_os = "vita", + target_os = "wasi" +)))] pub(crate) fn sendmsg_v4( sockfd: BorrowedFd<'_>, addr: &SocketAddrV4, @@ -321,7 +357,13 @@ pub(crate) fn sendmsg_v4( }) } -#[cfg(not(any(windows, target_os = "espidf", target_os = "redox", target_os = "wasi")))] +#[cfg(not(any( + windows, + target_os = "espidf", + target_os = "redox", + target_os = "vita", + target_os = "wasi" +)))] pub(crate) fn sendmsg_v6( sockfd: BorrowedFd<'_>, addr: &SocketAddrV6, @@ -338,7 +380,10 @@ pub(crate) fn sendmsg_v6( }) } -#[cfg(all(unix, not(any(target_os = "espidf", target_os = "redox"))))] +#[cfg(all( + unix, + not(any(target_os = "espidf", target_os = "redox", target_os = "vita")) +))] pub(crate) fn sendmsg_unix( sockfd: BorrowedFd<'_>, addr: &SocketAddrUnix, @@ -363,6 +408,7 @@ pub(crate) fn sendmsg_unix( target_os = "haiku", target_os = "redox", target_os = "nto", + target_os = "vita", target_os = "wasi", )))] pub(crate) fn accept_with(sockfd: BorrowedFd<'_>, flags: SocketFlags) -> io::Result { @@ -402,6 +448,7 @@ pub(crate) fn acceptfrom(sockfd: BorrowedFd<'_>) -> io::Result<(OwnedFd, Option< target_os = "haiku", target_os = "nto", target_os = "redox", + target_os = "vita", target_os = "wasi", )))] pub(crate) fn acceptfrom_with( @@ -432,7 +479,8 @@ pub(crate) fn acceptfrom_with( target_os = "aix", target_os = "espidf", target_os = "haiku", - target_os = "nto" + target_os = "nto", + target_os = "vita", ))] pub(crate) fn accept_with(sockfd: BorrowedFd<'_>, _flags: SocketFlags) -> io::Result { accept(sockfd) @@ -446,7 +494,8 @@ pub(crate) fn accept_with(sockfd: BorrowedFd<'_>, _flags: SocketFlags) -> io::Re target_os = "aix", target_os = "espidf", target_os = "haiku", - target_os = "nto" + target_os = "nto", + target_os = "vita", ))] pub(crate) fn acceptfrom_with( sockfd: BorrowedFd<'_>, @@ -515,636 +564,3 @@ pub(crate) fn socketpair( Ok((fd0, fd1)) } } - -#[cfg(not(any(target_os = "redox", target_os = "wasi")))] -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; - - #[inline] - fn getsockopt(fd: BorrowedFd<'_>, level: i32, optname: i32) -> io::Result { - use super::*; - - let mut optlen = core::mem::size_of::().try_into().unwrap(); - debug_assert!( - optlen as usize >= core::mem::size_of::(), - "Socket APIs don't ever use `bool` directly" - ); - - unsafe { - let mut value = core::mem::zeroed::(); - ret(c::getsockopt( - borrowed_fd(fd), - level, - optname, - as_mut_ptr(&mut value).cast(), - &mut optlen, - ))?; - // On Windows at least, `getsockopt` has been observed writing 1 - // byte on at least (`IPPROTO_TCP`, `TCP_NODELAY`), even though - // Windows' documentation says that should write a 4-byte `BOOL`. - // So, we initialize the memory to zeros above, and just assert - // that `getsockopt` doesn't write too many bytes here. - assert!( - optlen as usize <= size_of::(), - "unexpected getsockopt size" - ); - Ok(value) - } - } - - #[inline] - fn setsockopt( - fd: BorrowedFd<'_>, - level: i32, - optname: i32, - value: T, - ) -> io::Result<()> { - use super::*; - - let optlen = core::mem::size_of::().try_into().unwrap(); - debug_assert!( - optlen as usize >= core::mem::size_of::(), - "Socket APIs don't ever use `bool` directly" - ); - - unsafe { - ret(c::setsockopt( - borrowed_fd(fd), - level, - optname, - as_ptr(&value).cast(), - optlen, - )) - } - } - - #[inline] - pub(crate) fn get_socket_type(fd: BorrowedFd<'_>) -> io::Result { - getsockopt(fd, c::SOL_SOCKET as _, c::SO_TYPE) - } - - #[inline] - pub(crate) fn set_socket_reuseaddr(fd: BorrowedFd<'_>, reuseaddr: bool) -> io::Result<()> { - setsockopt( - fd, - c::SOL_SOCKET as _, - c::SO_REUSEADDR, - from_bool(reuseaddr), - ) - } - - #[inline] - pub(crate) fn get_socket_reuseaddr(fd: BorrowedFd<'_>) -> io::Result { - 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, - c::SOL_SOCKET as _, - c::SO_BROADCAST, - from_bool(broadcast), - ) - } - - #[inline] - pub(crate) fn get_socket_broadcast(fd: BorrowedFd<'_>) -> io::Result { - getsockopt(fd, c::SOL_SOCKET as _, c::SO_BROADCAST).map(to_bool) - } - - #[inline] - pub(crate) fn set_socket_linger( - fd: BorrowedFd<'_>, - linger: Option, - ) -> io::Result<()> { - // Convert `linger` to seconds, rounding up. - let l_linger = if let Some(linger) = linger { - duration_to_secs(linger)? - } else { - 0 - }; - let linger = c::linger { - l_onoff: linger.is_some() as _, - l_linger, - }; - setsockopt(fd, c::SOL_SOCKET as _, c::SO_LINGER, linger) - } - - #[inline] - pub(crate) fn get_socket_linger(fd: BorrowedFd<'_>) -> io::Result> { - let linger: c::linger = getsockopt(fd, c::SOL_SOCKET as _, c::SO_LINGER)?; - Ok((linger.l_onoff != 0).then(|| Duration::from_secs(linger.l_linger as u64))) - } - - #[cfg(linux_kernel)] - #[inline] - pub(crate) fn set_socket_passcred(fd: BorrowedFd<'_>, passcred: bool) -> io::Result<()> { - setsockopt(fd, c::SOL_SOCKET as _, c::SO_PASSCRED, from_bool(passcred)) - } - - #[cfg(linux_kernel)] - #[inline] - pub(crate) fn get_socket_passcred(fd: BorrowedFd<'_>) -> io::Result { - getsockopt(fd, c::SOL_SOCKET as _, c::SO_PASSCRED).map(to_bool) - } - - #[inline] - pub(crate) fn set_socket_timeout( - fd: BorrowedFd<'_>, - id: Timeout, - timeout: Option, - ) -> io::Result<()> { - let optname = match id { - Timeout::Recv => c::SO_RCVTIMEO, - Timeout::Send => c::SO_SNDTIMEO, - }; - - #[cfg(not(windows))] - let timeout = match timeout { - Some(timeout) => { - if timeout == Duration::ZERO { - return Err(io::Errno::INVAL); - } - - // Rust's musl libc bindings deprecated `time_t` while they - // transition to 64-bit `time_t`. What we want here is just - // “whatever type `timeval`'s `tv_sec` is”, so we're ok using - // the deprecated type. - #[allow(deprecated)] - let tv_sec = timeout.as_secs().try_into().unwrap_or(c::time_t::MAX); - - // `subsec_micros` rounds down, so we use `subsec_nanos` and - // manually round up. - let mut timeout = c::timeval { - tv_sec, - tv_usec: ((timeout.subsec_nanos() + 999) / 1000) as _, - }; - if timeout.tv_sec == 0 && timeout.tv_usec == 0 { - timeout.tv_usec = 1; - } - timeout - } - None => c::timeval { - tv_sec: 0, - tv_usec: 0, - }, - }; - - #[cfg(windows)] - let timeout: u32 = match timeout { - Some(timeout) => { - if timeout == Duration::ZERO { - return Err(io::Errno::INVAL); - } - - // `as_millis` rounds down, so we use `as_nanos` and - // manually round up. - let mut timeout: u32 = ((timeout.as_nanos() + 999_999) / 1_000_000) - .try_into() - .map_err(|_convert_err| io::Errno::INVAL)?; - if timeout == 0 { - timeout = 1; - } - timeout - } - None => 0, - }; - - setsockopt(fd, c::SOL_SOCKET, optname, timeout) - } - - #[inline] - pub(crate) fn get_socket_timeout( - fd: BorrowedFd<'_>, - id: Timeout, - ) -> io::Result> { - let optname = match id { - Timeout::Recv => c::SO_RCVTIMEO, - Timeout::Send => c::SO_SNDTIMEO, - }; - - #[cfg(not(windows))] - { - let timeout: c::timeval = getsockopt(fd, c::SOL_SOCKET, optname)?; - if timeout.tv_sec == 0 && timeout.tv_usec == 0 { - Ok(None) - } else { - Ok(Some( - Duration::from_secs(timeout.tv_sec as u64) - + Duration::from_micros(timeout.tv_usec as u64), - )) - } - } - - #[cfg(windows)] - { - let timeout: u32 = getsockopt(fd, c::SOL_SOCKET, optname)?; - if timeout == 0 { - Ok(None) - } else { - Ok(Some(Duration::from_millis(timeout as u64))) - } - } - } - - #[cfg(any(apple, target_os = "freebsd"))] - #[inline] - pub(crate) fn get_socket_nosigpipe(fd: BorrowedFd<'_>) -> io::Result { - getsockopt(fd, c::SOL_SOCKET, c::SO_NOSIGPIPE).map(to_bool) - } - - #[cfg(any(apple, target_os = "freebsd"))] - #[inline] - pub(crate) fn set_socket_nosigpipe(fd: BorrowedFd<'_>, val: bool) -> io::Result<()> { - setsockopt(fd, c::SOL_SOCKET, c::SO_NOSIGPIPE, from_bool(val)) - } - - #[inline] - pub(crate) fn get_socket_error(fd: BorrowedFd<'_>) -> io::Result> { - let err: c::c_int = getsockopt(fd, c::SOL_SOCKET as _, c::SO_ERROR)?; - Ok(if err == 0 { - Ok(()) - } else { - Err(io::Errno::from_raw_os_error(err)) - }) - } - - #[inline] - pub(crate) fn set_socket_keepalive(fd: BorrowedFd<'_>, keepalive: bool) -> io::Result<()> { - setsockopt( - fd, - c::SOL_SOCKET as _, - c::SO_KEEPALIVE, - from_bool(keepalive), - ) - } - - #[inline] - pub(crate) fn get_socket_keepalive(fd: BorrowedFd<'_>) -> io::Result { - getsockopt(fd, c::SOL_SOCKET as _, c::SO_KEEPALIVE).map(to_bool) - } - - #[inline] - pub(crate) fn set_socket_recv_buffer_size(fd: BorrowedFd<'_>, size: usize) -> io::Result<()> { - let size: c::c_int = size.try_into().map_err(|_| io::Errno::INVAL)?; - setsockopt(fd, c::SOL_SOCKET as _, c::SO_RCVBUF, size) - } - - #[inline] - pub(crate) fn get_socket_recv_buffer_size(fd: BorrowedFd<'_>) -> io::Result { - getsockopt(fd, c::SOL_SOCKET as _, c::SO_RCVBUF).map(|size: u32| size as usize) - } - - #[inline] - pub(crate) fn set_socket_send_buffer_size(fd: BorrowedFd<'_>, size: usize) -> io::Result<()> { - let size: c::c_int = size.try_into().map_err(|_| io::Errno::INVAL)?; - setsockopt(fd, c::SOL_SOCKET as _, c::SO_SNDBUF, size) - } - - #[inline] - pub(crate) fn get_socket_send_buffer_size(fd: BorrowedFd<'_>) -> io::Result { - getsockopt(fd, c::SOL_SOCKET as _, c::SO_SNDBUF).map(|size: u32| size as usize) - } - - #[inline] - #[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 { - 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 { - 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) - } - - #[inline] - pub(crate) fn get_ip_ttl(fd: BorrowedFd<'_>) -> io::Result { - getsockopt(fd, c::IPPROTO_IP as _, c::IP_TTL) - } - - #[inline] - pub(crate) fn set_ipv6_v6only(fd: BorrowedFd<'_>, only_v6: bool) -> io::Result<()> { - setsockopt(fd, c::IPPROTO_IPV6 as _, c::IPV6_V6ONLY, from_bool(only_v6)) - } - - #[inline] - pub(crate) fn get_ipv6_v6only(fd: BorrowedFd<'_>) -> io::Result { - getsockopt(fd, c::IPPROTO_IPV6 as _, c::IPV6_V6ONLY).map(to_bool) - } - - #[inline] - pub(crate) fn set_ip_multicast_loop( - fd: BorrowedFd<'_>, - multicast_loop: bool, - ) -> io::Result<()> { - setsockopt( - fd, - c::IPPROTO_IP as _, - c::IP_MULTICAST_LOOP, - from_bool(multicast_loop), - ) - } - - #[inline] - pub(crate) fn get_ip_multicast_loop(fd: BorrowedFd<'_>) -> io::Result { - getsockopt(fd, c::IPPROTO_IP as _, c::IP_MULTICAST_LOOP).map(to_bool) - } - - #[inline] - pub(crate) fn set_ip_multicast_ttl(fd: BorrowedFd<'_>, multicast_ttl: u32) -> io::Result<()> { - setsockopt(fd, c::IPPROTO_IP as _, c::IP_MULTICAST_TTL, multicast_ttl) - } - - #[inline] - pub(crate) fn get_ip_multicast_ttl(fd: BorrowedFd<'_>) -> io::Result { - getsockopt(fd, c::IPPROTO_IP as _, c::IP_MULTICAST_TTL) - } - - #[inline] - pub(crate) fn set_ipv6_multicast_loop( - fd: BorrowedFd<'_>, - multicast_loop: bool, - ) -> io::Result<()> { - setsockopt( - fd, - c::IPPROTO_IPV6 as _, - c::IPV6_MULTICAST_LOOP, - from_bool(multicast_loop), - ) - } - - #[inline] - pub(crate) fn get_ipv6_multicast_loop(fd: BorrowedFd<'_>) -> io::Result { - getsockopt(fd, c::IPPROTO_IPV6 as _, c::IPV6_MULTICAST_LOOP).map(to_bool) - } - - #[inline] - pub(crate) fn set_ipv6_multicast_hops( - fd: BorrowedFd<'_>, - multicast_hops: u32, - ) -> io::Result<()> { - setsockopt( - fd, - c::IPPROTO_IP as _, - c::IPV6_MULTICAST_HOPS, - multicast_hops, - ) - } - - #[inline] - pub(crate) fn get_ipv6_multicast_hops(fd: BorrowedFd<'_>) -> io::Result { - getsockopt(fd, c::IPPROTO_IP as _, c::IPV6_MULTICAST_HOPS) - } - - #[inline] - pub(crate) fn set_ip_add_membership( - fd: BorrowedFd<'_>, - multiaddr: &Ipv4Addr, - interface: &Ipv4Addr, - ) -> io::Result<()> { - let mreq = to_imr(multiaddr, interface); - setsockopt(fd, c::IPPROTO_IP as _, c::IP_ADD_MEMBERSHIP, mreq) - } - - #[inline] - pub(crate) fn set_ipv6_add_membership( - fd: BorrowedFd<'_>, - multiaddr: &Ipv6Addr, - interface: u32, - ) -> io::Result<()> { - #[cfg(not(any( - bsd, - solarish, - target_os = "haiku", - target_os = "l4re", - target_os = "nto" - )))] - use c::IPV6_ADD_MEMBERSHIP; - #[cfg(any( - bsd, - solarish, - target_os = "haiku", - target_os = "l4re", - target_os = "nto" - ))] - use c::IPV6_JOIN_GROUP as IPV6_ADD_MEMBERSHIP; - - let mreq = to_ipv6mr(multiaddr, interface); - setsockopt(fd, c::IPPROTO_IPV6 as _, IPV6_ADD_MEMBERSHIP, mreq) - } - - #[inline] - pub(crate) fn set_ip_drop_membership( - fd: BorrowedFd<'_>, - multiaddr: &Ipv4Addr, - interface: &Ipv4Addr, - ) -> io::Result<()> { - let mreq = to_imr(multiaddr, interface); - setsockopt(fd, c::IPPROTO_IP as _, c::IP_DROP_MEMBERSHIP, mreq) - } - - #[inline] - pub(crate) fn set_ipv6_drop_membership( - fd: BorrowedFd<'_>, - multiaddr: &Ipv6Addr, - interface: u32, - ) -> io::Result<()> { - #[cfg(not(any( - bsd, - solarish, - target_os = "haiku", - target_os = "l4re", - target_os = "nto" - )))] - use c::IPV6_DROP_MEMBERSHIP; - #[cfg(any( - bsd, - solarish, - target_os = "haiku", - target_os = "l4re", - target_os = "nto" - ))] - use c::IPV6_LEAVE_GROUP as IPV6_DROP_MEMBERSHIP; - - let mreq = to_ipv6mr(multiaddr, interface); - setsockopt(fd, c::IPPROTO_IPV6 as _, IPV6_DROP_MEMBERSHIP, mreq) - } - - #[inline] - pub(crate) fn get_ipv6_unicast_hops(fd: BorrowedFd<'_>) -> io::Result { - getsockopt(fd, c::IPPROTO_IPV6 as _, c::IPV6_UNICAST_HOPS).map(|hops: c::c_int| hops as u8) - } - - #[inline] - pub(crate) fn set_ipv6_unicast_hops(fd: BorrowedFd<'_>, hops: Option) -> io::Result<()> { - let hops = match hops { - Some(hops) => hops as c::c_int, - None => -1, - }; - setsockopt(fd, c::IPPROTO_IPV6 as _, c::IPV6_UNICAST_HOPS, hops) - } - - #[inline] - pub(crate) fn set_tcp_nodelay(fd: BorrowedFd<'_>, nodelay: bool) -> io::Result<()> { - setsockopt(fd, c::IPPROTO_TCP as _, c::TCP_NODELAY, from_bool(nodelay)) - } - - #[inline] - pub(crate) fn get_tcp_nodelay(fd: BorrowedFd<'_>) -> io::Result { - getsockopt(fd, c::IPPROTO_TCP as _, c::TCP_NODELAY).map(to_bool) - } - - #[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 { - 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 { - 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 { - 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), - imr_interface: to_imr_addr(interface), - } - } - - #[inline] - fn to_imr_addr(addr: &Ipv4Addr) -> c::in_addr { - in_addr_new(u32::from_ne_bytes(addr.octets())) - } - - #[inline] - fn to_ipv6mr(multiaddr: &Ipv6Addr, interface: u32) -> c::ipv6_mreq { - c::ipv6_mreq { - ipv6mr_multiaddr: to_ipv6mr_multiaddr(multiaddr), - ipv6mr_interface: to_ipv6mr_interface(interface), - } - } - - #[inline] - fn to_ipv6mr_multiaddr(multiaddr: &Ipv6Addr) -> c::in6_addr { - in6_addr_new(multiaddr.octets()) - } - - #[cfg(target_os = "android")] - #[inline] - fn to_ipv6mr_interface(interface: u32) -> c::c_int { - interface as c::c_int - } - - #[cfg(not(target_os = "android"))] - #[inline] - fn to_ipv6mr_interface(interface: u32) -> c::c_uint { - interface as c::c_uint - } - - // `getsockopt` and `setsockopt` represent boolean values as integers. - #[cfg(not(windows))] - type RawSocketBool = c::c_int; - #[cfg(windows)] - type RawSocketBool = BOOL; - - // Wrap `RawSocketBool` in a newtype to discourage misuse. - #[repr(transparent)] - #[derive(Copy, Clone)] - struct SocketBool(RawSocketBool); - - // Convert from a `bool` to a `SocketBool`. - #[inline] - fn from_bool(value: bool) -> SocketBool { - SocketBool(value as _) - } - - // Convert from a `SocketBool` to a `bool`. - #[inline] - fn to_bool(value: SocketBool) -> bool { - value.0 != 0 - } - - /// Convert to seconds, rounding up if necessary. - #[inline] - fn duration_to_secs>(duration: Duration) -> io::Result { - 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 a354d9a85..2eee98cb8 100644 --- a/vendor/rustix/src/backend/libc/net/write_sockaddr.rs +++ b/vendor/rustix/src/backend/libc/net/write_sockaddr.rs @@ -1,5 +1,5 @@ -//! The BSD sockets API requires us to read the `ss_family` field before -//! we can interpret the rest of a `sockaddr` produced by the kernel. +//! The BSD sockets API requires us to read the `ss_family` field before we can +//! interpret the rest of a `sockaddr` produced by the kernel. use super::addr::SocketAddrStorage; #[cfg(unix)] @@ -29,15 +29,20 @@ pub(crate) fn encode_sockaddr_v4(v4: &SocketAddrV4) -> c::sockaddr_in { target_os = "espidf", target_os = "haiku", target_os = "nto", + target_os = "vita", ))] sin_len: size_of::() as _, sin_family: c::AF_INET as _, sin_port: u16::to_be(v4.port()), sin_addr: in_addr_new(u32::from_ne_bytes(v4.ip().octets())), - #[cfg(not(target_os = "haiku"))] + #[cfg(not(any(target_os = "haiku", target_os = "vita")))] sin_zero: [0; 8_usize], #[cfg(target_os = "haiku")] sin_zero: [0; 24_usize], + #[cfg(target_os = "vita")] + sin_zero: [0; 6_usize], + #[cfg(target_os = "vita")] + sin_vport: 0, } } @@ -54,6 +59,7 @@ pub(crate) fn encode_sockaddr_v6(v6: &SocketAddrV6) -> c::sockaddr_in6 { target_os = "espidf", target_os = "haiku", target_os = "nto", + target_os = "vita" ))] { sockaddr_in6_new( @@ -70,7 +76,8 @@ pub(crate) fn encode_sockaddr_v6(v6: &SocketAddrV6) -> c::sockaddr_in6 { target_os = "aix", target_os = "espidf", target_os = "haiku", - target_os = "nto" + target_os = "nto", + target_os = "vita" )))] { sockaddr_in6_new( diff --git a/vendor/rustix/src/backend/libc/param/auxv.rs b/vendor/rustix/src/backend/libc/param/auxv.rs index 0eeb972cc..880a1d43f 100644 --- a/vendor/rustix/src/backend/libc/param/auxv.rs +++ b/vendor/rustix/src/backend/libc/param/auxv.rs @@ -17,7 +17,7 @@ pub(crate) fn page_size() -> usize { unsafe { c::sysconf(c::_SC_PAGESIZE) as usize } } -#[cfg(not(target_os = "wasi"))] +#[cfg(not(any(target_os = "vita", target_os = "wasi")))] #[inline] pub(crate) fn clock_ticks_per_second() -> u64 { unsafe { c::sysconf(c::_SC_CLK_TCK) as u64 } diff --git a/vendor/rustix/src/backend/libc/pipe/types.rs b/vendor/rustix/src/backend/libc/pipe/types.rs index 7f5634b17..1004e41f7 100644 --- a/vendor/rustix/src/backend/libc/pipe/types.rs +++ b/vendor/rustix/src/backend/libc/pipe/types.rs @@ -21,12 +21,13 @@ bitflags! { target_os = "nto", target_os = "openbsd", target_os = "redox", + target_os = "vita", )))] const DIRECT = bitcast!(c::O_DIRECT); /// `O_NONBLOCK` const NONBLOCK = bitcast!(c::O_NONBLOCK); - /// + /// const _ = !0; } } @@ -47,7 +48,7 @@ bitflags! { /// `SPLICE_F_GIFT` const GIFT = c::SPLICE_F_GIFT; - /// + /// const _ = !0; } } diff --git a/vendor/rustix/src/backend/libc/process/mod.rs b/vendor/rustix/src/backend/libc/process/mod.rs index 4d9a9f0a0..b89096199 100644 --- a/vendor/rustix/src/backend/libc/process/mod.rs +++ b/vendor/rustix/src/backend/libc/process/mod.rs @@ -3,5 +3,5 @@ pub(crate) mod cpu_set; #[cfg(not(windows))] pub(crate) mod syscalls; pub(crate) mod types; -#[cfg(not(any(target_os = "espidf", target_os = "wasi")))] +#[cfg(not(any(target_os = "espidf", target_os = "vita", target_os = "wasi")))] pub(crate) mod wait; diff --git a/vendor/rustix/src/backend/libc/process/syscalls.rs b/vendor/rustix/src/backend/libc/process/syscalls.rs index dd71801d5..ec31e0ea7 100644 --- a/vendor/rustix/src/backend/libc/process/syscalls.rs +++ b/vendor/rustix/src/backend/libc/process/syscalls.rs @@ -13,6 +13,7 @@ use crate::backend::conv::ret_discarded_char_ptr; target_os = "espidf", target_os = "fuchsia", target_os = "redox", + target_os = "vita", target_os = "wasi" )))] use crate::backend::conv::ret_infallible; @@ -36,16 +37,24 @@ use crate::io; 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")))] +#[cfg(not(any(target_os = "espidf", target_os = "wasi")))] +use crate::process::Signal; +#[cfg(not(any( + target_os = "espidf", + target_os = "fuchsia", + target_os = "vita", + target_os = "wasi" +)))] use crate::process::Uid; #[cfg(linux_kernel)] use crate::process::{Cpuid, MembarrierCommand, MembarrierQuery}; -#[cfg(not(any(target_os = "espidf", target_os = "wasi")))] -use crate::process::{RawPid, Signal, WaitOptions, WaitStatus}; +#[cfg(not(any(target_os = "espidf", target_os = "vita", target_os = "wasi")))] +use crate::process::{RawPid, WaitOptions, WaitStatus}; #[cfg(not(any( target_os = "espidf", target_os = "fuchsia", target_os = "redox", + target_os = "vita", target_os = "wasi" )))] use crate::process::{Resource, Rlimit}; @@ -53,6 +62,7 @@ use crate::process::{Resource, Rlimit}; target_os = "espidf", target_os = "redox", target_os = "openbsd", + target_os = "vita", target_os = "wasi" )))] use crate::process::{WaitId, WaitidOptions, WaitidStatus}; @@ -209,7 +219,7 @@ pub(crate) fn umask(mask: Mode) -> Mode { unsafe { Mode::from_bits_retain(c::umask(mask.bits() as c::mode_t).into()) } } -#[cfg(not(any(target_os = "fuchsia", target_os = "wasi")))] +#[cfg(not(any(target_os = "fuchsia", target_os = "vita", target_os = "wasi")))] #[inline] pub(crate) fn nice(inc: i32) -> io::Result { libc_errno::set_errno(libc_errno::Errno(0)); @@ -221,7 +231,12 @@ pub(crate) fn nice(inc: i32) -> io::Result { } } -#[cfg(not(any(target_os = "espidf", target_os = "fuchsia", target_os = "wasi")))] +#[cfg(not(any( + target_os = "espidf", + target_os = "fuchsia", + target_os = "vita", + target_os = "wasi" +)))] #[inline] pub(crate) fn getpriority_user(uid: Uid) -> io::Result { libc_errno::set_errno(libc_errno::Errno(0)); @@ -233,7 +248,12 @@ pub(crate) fn getpriority_user(uid: Uid) -> io::Result { } } -#[cfg(not(any(target_os = "espidf", target_os = "fuchsia", target_os = "wasi")))] +#[cfg(not(any( + target_os = "espidf", + target_os = "fuchsia", + target_os = "vita", + target_os = "wasi" +)))] #[inline] pub(crate) fn getpriority_pgrp(pgid: Option) -> io::Result { libc_errno::set_errno(libc_errno::Errno(0)); @@ -245,7 +265,12 @@ pub(crate) fn getpriority_pgrp(pgid: Option) -> io::Result { } } -#[cfg(not(any(target_os = "espidf", target_os = "fuchsia", target_os = "wasi")))] +#[cfg(not(any( + target_os = "espidf", + target_os = "fuchsia", + target_os = "vita", + target_os = "wasi" +)))] #[inline] pub(crate) fn getpriority_process(pid: Option) -> io::Result { libc_errno::set_errno(libc_errno::Errno(0)); @@ -257,13 +282,23 @@ pub(crate) fn getpriority_process(pid: Option) -> io::Result { } } -#[cfg(not(any(target_os = "espidf", target_os = "fuchsia", target_os = "wasi")))] +#[cfg(not(any( + target_os = "espidf", + target_os = "fuchsia", + target_os = "vita", + target_os = "wasi" +)))] #[inline] pub(crate) fn setpriority_user(uid: Uid, priority: i32) -> io::Result<()> { unsafe { ret(c::setpriority(c::PRIO_USER, uid.as_raw() as _, priority)) } } -#[cfg(not(any(target_os = "espidf", target_os = "fuchsia", target_os = "wasi")))] +#[cfg(not(any( + target_os = "espidf", + target_os = "fuchsia", + target_os = "vita", + target_os = "wasi" +)))] #[inline] pub(crate) fn setpriority_pgrp(pgid: Option, priority: i32) -> io::Result<()> { unsafe { @@ -275,7 +310,12 @@ pub(crate) fn setpriority_pgrp(pgid: Option, priority: i32) -> io::Result<( } } -#[cfg(not(any(target_os = "espidf", target_os = "fuchsia", target_os = "wasi")))] +#[cfg(not(any( + target_os = "espidf", + target_os = "fuchsia", + target_os = "vita", + target_os = "wasi" +)))] #[inline] pub(crate) fn setpriority_process(pid: Option, priority: i32) -> io::Result<()> { unsafe { @@ -291,6 +331,7 @@ pub(crate) fn setpriority_process(pid: Option, priority: i32) -> io::Result target_os = "espidf", target_os = "fuchsia", target_os = "redox", + target_os = "vita", target_os = "wasi" )))] #[inline] @@ -306,6 +347,7 @@ pub(crate) fn getrlimit(limit: Resource) -> Rlimit { target_os = "espidf", target_os = "fuchsia", target_os = "redox", + target_os = "vita", target_os = "wasi" )))] #[inline] @@ -335,6 +377,7 @@ pub(crate) fn prlimit(pid: Option, limit: Resource, new: Rlimit) -> io::Res target_os = "espidf", target_os = "fuchsia", target_os = "redox", + target_os = "vita", target_os = "wasi" )))] fn rlimit_from_libc(lim: c::rlimit) -> Rlimit { @@ -356,6 +399,7 @@ fn rlimit_from_libc(lim: c::rlimit) -> Rlimit { target_os = "espidf", target_os = "fuchsia", target_os = "redox", + target_os = "vita", target_os = "wasi" )))] fn rlimit_to_libc(lim: Rlimit) -> io::Result { @@ -371,13 +415,13 @@ fn rlimit_to_libc(lim: Rlimit) -> io::Result { Ok(c::rlimit { rlim_cur, rlim_max }) } -#[cfg(not(any(target_os = "espidf", target_os = "wasi")))] +#[cfg(not(any(target_os = "espidf", target_os = "vita", target_os = "wasi")))] #[inline] pub(crate) fn wait(waitopts: WaitOptions) -> io::Result> { _waitpid(!0, waitopts) } -#[cfg(not(any(target_os = "espidf", target_os = "wasi")))] +#[cfg(not(any(target_os = "espidf", target_os = "vita", target_os = "wasi")))] #[inline] pub(crate) fn waitpid( pid: Option, @@ -386,7 +430,13 @@ pub(crate) fn waitpid( _waitpid(Pid::as_raw(pid), waitopts) } -#[cfg(not(any(target_os = "espidf", target_os = "wasi")))] +#[cfg(not(any(target_os = "espidf", target_os = "vita", target_os = "wasi")))] +#[inline] +pub(crate) fn waitpgid(pgid: Pid, waitopts: WaitOptions) -> io::Result> { + _waitpid(-pgid.as_raw_nonzero().get(), waitopts) +} + +#[cfg(not(any(target_os = "espidf", target_os = "vita", target_os = "wasi")))] #[inline] pub(crate) fn _waitpid( pid: RawPid, @@ -403,6 +453,7 @@ pub(crate) fn _waitpid( target_os = "espidf", target_os = "redox", target_os = "openbsd", + target_os = "vita", target_os = "wasi" )))] #[inline] @@ -411,6 +462,7 @@ pub(crate) fn waitid(id: WaitId<'_>, options: WaitidOptions) -> io::Result _waitid_all(options), WaitId::Pid(pid) => _waitid_pid(pid, options), + WaitId::Pgid(pgid) => _waitid_pgid(pgid, options), #[cfg(target_os = "linux")] WaitId::PidFd(fd) => _waitid_pidfd(fd, options), #[cfg(not(target_os = "linux"))] @@ -422,6 +474,7 @@ pub(crate) fn waitid(id: WaitId<'_>, options: WaitidOptions) -> io::Result io::Result> { target_os = "espidf", target_os = "redox", target_os = "openbsd", + target_os = "vita", target_os = "wasi" )))] #[inline] @@ -464,6 +518,30 @@ fn _waitid_pid(pid: Pid, options: WaitidOptions) -> io::Result, options: WaitidOptions) -> io::Result> { + // `waitid` can return successfully without initializing the struct (no + // children found when using `WNOHANG`) + let mut status = MaybeUninit::::zeroed(); + unsafe { + ret(c::waitid( + c::P_PGID, + Pid::as_raw(pgid) as _, + status.as_mut_ptr(), + options.bits() as _, + ))? + }; + + Ok(unsafe { cvt_waitid_status(status) }) +} + #[cfg(target_os = "linux")] #[inline] fn _waitid_pidfd(fd: BorrowedFd<'_>, options: WaitidOptions) -> io::Result> { @@ -492,6 +570,7 @@ fn _waitid_pidfd(fd: BorrowedFd<'_>, options: WaitidOptions) -> io::Result, mut buffer: Vec) -> io::Result { @@ -87,7 +88,8 @@ pub(crate) fn ptsname(fd: BorrowedFd<'_>, mut buffer: Vec) -> io::Result + /// const _ = !0; } } diff --git a/vendor/rustix/src/backend/libc/shm/mod.rs b/vendor/rustix/src/backend/libc/shm/mod.rs new file mode 100644 index 000000000..1e0181a99 --- /dev/null +++ b/vendor/rustix/src/backend/libc/shm/mod.rs @@ -0,0 +1,2 @@ +pub(crate) mod syscalls; +pub(crate) mod types; diff --git a/vendor/rustix/src/backend/libc/shm/syscalls.rs b/vendor/rustix/src/backend/libc/shm/syscalls.rs new file mode 100644 index 000000000..b0d907ff2 --- /dev/null +++ b/vendor/rustix/src/backend/libc/shm/syscalls.rs @@ -0,0 +1,25 @@ +use crate::ffi::CStr; + +use crate::backend::c; +use crate::backend::conv::{c_str, ret, ret_owned_fd}; +use crate::fd::OwnedFd; +use crate::fs::Mode; +use crate::io; +use crate::shm::ShmOFlags; + +pub(crate) fn shm_open(name: &CStr, oflags: ShmOFlags, mode: Mode) -> io::Result { + // On this platforms, `mode_t` is `u16` and can't be passed directly to a + // variadic function. + #[cfg(apple)] + let mode: c::c_uint = mode.bits().into(); + + // Otherwise, cast to `mode_t` as that's what `open` is documented to take. + #[cfg(not(apple))] + let mode: c::mode_t = mode.bits() as _; + + unsafe { ret_owned_fd(c::shm_open(c_str(name), bitflags_bits!(oflags), mode)) } +} + +pub(crate) fn shm_unlink(name: &CStr) -> io::Result<()> { + unsafe { ret(c::shm_unlink(c_str(name))) } +} diff --git a/vendor/rustix/src/backend/libc/shm/types.rs b/vendor/rustix/src/backend/libc/shm/types.rs new file mode 100644 index 000000000..6575ef523 --- /dev/null +++ b/vendor/rustix/src/backend/libc/shm/types.rs @@ -0,0 +1,30 @@ +use crate::backend::c; +use bitflags::bitflags; + +bitflags! { + /// `O_*` constants for use with [`shm_open`]. + /// + /// [`shm_open`]: crate:shm::shm_open + #[repr(transparent)] + #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] + pub struct ShmOFlags: u32 { + /// `O_CREAT` + #[doc(alias = "CREAT")] + const CREATE = bitcast!(c::O_CREAT); + + /// `O_EXCL` + const EXCL = bitcast!(c::O_EXCL); + + /// `O_RDONLY` + const RDONLY = bitcast!(c::O_RDONLY); + + /// `O_RDWR` + const RDWR = bitcast!(c::O_RDWR); + + /// `O_TRUNC` + const TRUNC = bitcast!(c::O_TRUNC); + + /// + const _ = !0; + } +} diff --git a/vendor/rustix/src/backend/libc/system/syscalls.rs b/vendor/rustix/src/backend/libc/system/syscalls.rs index 27efd2653..05d674b2c 100644 --- a/vendor/rustix/src/backend/libc/system/syscalls.rs +++ b/vendor/rustix/src/backend/libc/system/syscalls.rs @@ -4,6 +4,8 @@ use super::types::RawUname; use crate::backend::c; #[cfg(not(target_os = "wasi"))] use crate::backend::conv::ret_infallible; +#[cfg(target_os = "linux")] +use crate::system::RebootCommand; #[cfg(linux_kernel)] use crate::system::Sysinfo; use core::mem::MaybeUninit; @@ -11,6 +13,7 @@ use core::mem::MaybeUninit; target_os = "emscripten", target_os = "espidf", target_os = "redox", + target_os = "vita", target_os = "wasi" )))] use {crate::backend::conv::ret, crate::io}; @@ -46,6 +49,7 @@ pub(crate) fn sysinfo() -> Sysinfo { target_os = "emscripten", target_os = "espidf", target_os = "redox", + target_os = "vita", target_os = "wasi" )))] pub(crate) fn sethostname(name: &[u8]) -> io::Result<()> { @@ -56,3 +60,8 @@ pub(crate) fn sethostname(name: &[u8]) -> io::Result<()> { )) } } + +#[cfg(target_os = "linux")] +pub(crate) fn reboot(cmd: RebootCommand) -> io::Result<()> { + unsafe { ret(c::reboot(cmd as i32)) } +} diff --git a/vendor/rustix/src/backend/libc/termios/syscalls.rs b/vendor/rustix/src/backend/libc/termios/syscalls.rs index df96595cd..35d4e2349 100644 --- a/vendor/rustix/src/backend/libc/termios/syscalls.rs +++ b/vendor/rustix/src/backend/libc/termios/syscalls.rs @@ -40,6 +40,13 @@ pub(crate) fn tcgetattr(fd: BorrowedFd<'_>) -> io::Result { let termios2 = unsafe { let mut termios2 = MaybeUninit::::uninit(); + // QEMU's `TCGETS2` doesn't currently set `input_speed` or + // `output_speed` on PowerPC, so zero out the fields ourselves. + #[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))] + { + termios2.write(core::mem::zeroed()); + } + ret(c::ioctl( borrowed_fd(fd), c::TCGETS2 as _, @@ -60,6 +67,33 @@ pub(crate) fn tcgetattr(fd: BorrowedFd<'_>) -> io::Result { input_speed: termios2.c_ispeed, output_speed: termios2.c_ospeed, }; + + // QEMU's `TCGETS2` doesn't currently set `input_speed` or + // `output_speed` on PowerPC, so set them manually if we can. + #[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))] + { + use crate::termios::speed; + + if result.output_speed == 0 && (termios2.c_cflag & c::CBAUD) != c::BOTHER { + if let Some(output_speed) = speed::decode(termios2.c_cflag & c::CBAUD) { + result.output_speed = output_speed; + } + } + if result.input_speed == 0 + && ((termios2.c_cflag & c::CIBAUD) >> c::IBSHIFT) != c::BOTHER + { + // For input speeds, `B0` is special-cased to mean the input + // speed is the same as the output speed. + if ((termios2.c_cflag & c::CIBAUD) >> c::IBSHIFT) == c::B0 { + result.input_speed = result.output_speed; + } else if let Some(input_speed) = + speed::decode((termios2.c_cflag & c::CIBAUD) >> c::IBSHIFT) + { + result.input_speed = input_speed; + } + } + } + result.special_codes.0[..termios2.c_cc.len()].copy_from_slice(&termios2.c_cc); Ok(result) @@ -110,12 +144,12 @@ pub(crate) fn tcsetattr( // linux-raw-sys' ioctl-generation script for sparc isn't working yet, // so as a temporary workaround, declare these manually. #[cfg(any(target_arch = "sparc", target_arch = "sparc64"))] - const TCSETS: u32 = 0x80245409; + const TCSETS: u32 = 0x8024_5409; #[cfg(any(target_arch = "sparc", target_arch = "sparc64"))] - const TCSETS2: u32 = 0x802c540d; + const TCSETS2: u32 = 0x802c_540d; - // Translate from `optional_actions` into an ioctl request code. On MIPS, - // `optional_actions` already has `TCGETS` added to it. + // Translate from `optional_actions` into an ioctl request code. On + // MIPS, `optional_actions` already has `TCGETS` added to it. let request = TCSETS2 + if cfg!(any( target_arch = "mips", @@ -341,7 +375,7 @@ pub(crate) fn cfmakeraw(termios: &mut Termios) { pub(crate) fn isatty(fd: BorrowedFd<'_>) -> bool { // Use the return value of `isatty` alone. We don't check `errno` because // we return `bool` rather than `io::Result`, because we assume - // `BorrrowedFd` protects us from `EBADF`, and any other reasonably + // `BorrowedFd` protects us from `EBADF`, and any other reasonably // anticipated `errno` value would end up interpreted as “assume it's not a // terminal” anyway. unsafe { c::isatty(borrowed_fd(fd)) != 0 } diff --git a/vendor/rustix/src/backend/libc/thread/syscalls.rs b/vendor/rustix/src/backend/libc/thread/syscalls.rs index 846f0e2a8..33750f405 100644 --- a/vendor/rustix/src/backend/libc/thread/syscalls.rs +++ b/vendor/rustix/src/backend/libc/thread/syscalls.rs @@ -24,6 +24,7 @@ use { target_os = "haiku", target_os = "openbsd", target_os = "redox", + target_os = "vita", target_os = "wasi", )))] use {crate::thread::ClockId, core::ptr::null_mut}; @@ -42,6 +43,7 @@ weak!(fn __nanosleep64(*const LibcTimespec, *mut LibcTimespec) -> c::c_int); target_os = "haiku", target_os = "openbsd", target_os = "redox", + target_os = "vita", target_os = "wasi", )))] #[inline] @@ -92,7 +94,12 @@ pub(crate) fn clock_nanosleep_relative(id: ClockId, request: &Timespec) -> Nanos #[cfg(all( fix_y2038, - not(any(apple, target_os = "emscripten", target_os = "haiku")) + not(any( + apple, + target_os = "emscripten", + target_os = "haiku", + target_os = "vita" + )) ))] fn clock_nanosleep_relative_old(id: ClockId, request: &Timespec) -> NanosleepRelativeResult { let tv_sec = match request.tv_sec.try_into() { @@ -137,6 +144,7 @@ fn clock_nanosleep_relative_old(id: ClockId, request: &Timespec) -> NanosleepRel target_os = "haiku", target_os = "openbsd", target_os = "redox", + target_os = "vita", target_os = "wasi", )))] #[inline] @@ -180,7 +188,12 @@ pub(crate) fn clock_nanosleep_absolute(id: ClockId, request: &Timespec) -> io::R #[cfg(all( fix_y2038, - not(any(apple, target_os = "emscripten", target_os = "haiku")) + not(any( + apple, + target_os = "emscripten", + target_os = "haiku", + target_os = "vita" + )) ))] fn clock_nanosleep_absolute_old(id: ClockId, request: &Timespec) -> io::Result<()> { let flags = c::TIMER_ABSTIME; diff --git a/vendor/rustix/src/backend/libc/time/types.rs b/vendor/rustix/src/backend/libc/time/types.rs index 4d8c6bdab..1514b02d0 100644 --- a/vendor/rustix/src/backend/libc/time/types.rs +++ b/vendor/rustix/src/backend/libc/time/types.rs @@ -88,7 +88,7 @@ bitflags! { /// `TFD_CLOEXEC` const CLOEXEC = bitcast!(c::TFD_CLOEXEC); - /// + /// const _ = !0; } } @@ -108,7 +108,7 @@ bitflags! { #[cfg(linux_kernel)] const CANCEL_ON_SET = bitcast!(c::TFD_TIMER_CANCEL_ON_SET); - /// + /// const _ = !0; } } -- cgit v1.2.3