diff options
Diffstat (limited to 'vendor/rustix/src/backend/libc')
33 files changed, 1902 insertions, 824 deletions
diff --git a/vendor/rustix/src/backend/libc/c.rs b/vendor/rustix/src/backend/libc/c.rs index 90d3c26f3..f9e94416c 100644 --- a/vendor/rustix/src/backend/libc/c.rs +++ b/vendor/rustix/src/backend/libc/c.rs @@ -12,10 +12,6 @@ pub(crate) const PROC_SUPER_MAGIC: u32 = 0x0000_9fa0; #[cfg(all(linux_kernel, target_env = "musl"))] pub(crate) const NFS_SUPER_MAGIC: u32 = 0x0000_6969; -// Submitted upstream in <https://github.com/rust-lang/libc/pull/3272>. -#[cfg(all(linux_kernel, feature = "net"))] -pub(crate) const IPPROTO_ETHERNET: c_int = linux_raw_sys::net::IPPROTO_ETHERNET as _; - // TODO: Upstream these. #[cfg(all(linux_kernel, feature = "net"))] pub(crate) const ETH_P_TSN: c_int = linux_raw_sys::if_ether::ETH_P_TSN as _; @@ -66,7 +62,9 @@ pub(crate) const ETH_P_MCTP: c_int = linux_raw_sys::if_ether::ETH_P_MCTP as _; linux_kernel, any( target_arch = "mips", + target_arch = "mips32r6", target_arch = "mips64", + target_arch = "mips64r6", target_arch = "sparc", target_arch = "sparc64" ) @@ -97,8 +95,6 @@ pub(crate) use { #[cfg(target_os = "vxworks")] pub(super) use libc::_Vx_ticks64_t as _Vx_ticks_t; -#[cfg(target_os = "aix")] -pub(super) use libc::blksize64_t as blksize_t; #[cfg(linux_kernel)] pub(super) use libc::fallocate64 as fallocate; #[cfg(not(any(target_arch = "aarch64", target_arch = "riscv64")))] @@ -108,7 +104,15 @@ pub(super) use libc::open64 as open; pub(super) use libc::posix_fallocate64 as posix_fallocate; #[cfg(any(all(linux_like, not(target_os = "android")), target_os = "aix"))] pub(super) use libc::{blkcnt64_t as blkcnt_t, rlim64_t as rlim_t}; -#[cfg(any(linux_like, target_os = "aix"))] +#[cfg(target_os = "aix")] +pub(super) use libc::{ + blksize64_t as blksize_t, fstat64 as fstat, fstatat, fstatfs64 as fstatfs, + fstatvfs64 as fstatvfs, ftruncate64 as ftruncate, getrlimit64 as getrlimit, ino_t, + lseek64 as lseek, mmap, off64_t as off_t, openat, posix_fadvise64 as posix_fadvise, preadv, + pwritev, rlimit64 as rlimit, setrlimit64 as setrlimit, statfs64 as statfs, + statvfs64 as statvfs, RLIM_INFINITY, +}; +#[cfg(linux_like)] 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, @@ -121,12 +125,19 @@ pub(super) use libc::{ host_info64_t as host_info_t, host_statistics64 as host_statistics, vm_statistics64_t as vm_statistics_t, }; -#[cfg(not(all(linux_kernel, any(target_pointer_width = "32", target_arch = "mips64"))))] +#[cfg(not(all( + linux_kernel, + any( + target_pointer_width = "32", + target_arch = "mips64", + target_arch = "mips64r6" + ) +)))] #[cfg(any(linux_like, target_os = "aix"))] pub(super) use libc::{lstat64 as lstat, stat64 as stat}; #[cfg(any(linux_kernel, target_os = "aix", target_os = "emscripten"))] pub(super) use libc::{pread64 as pread, pwrite64 as pwrite}; -#[cfg(any(target_os = "aix", target_os = "linux", target_os = "emscripten"))] +#[cfg(any(target_os = "linux", target_os = "emscripten"))] pub(super) use libc::{preadv64 as preadv, pwritev64 as pwritev}; #[cfg(all(target_os = "linux", target_env = "gnu"))] diff --git a/vendor/rustix/src/backend/libc/conv.rs b/vendor/rustix/src/backend/libc/conv.rs index d6bcc16ee..baf2a05ed 100644 --- a/vendor/rustix/src/backend/libc/conv.rs +++ b/vendor/rustix/src/backend/libc/conv.rs @@ -2,10 +2,10 @@ //! `c_uint`, or libc-specific pointer types. This module provides functions //! for converting between rustix's types and libc types. -#![allow(dead_code)] - use super::c; -use super::fd::{AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, LibcFd, OwnedFd, RawFd}; +#[cfg(not(any(windows, target_os = "espidf")))] +use super::fd::IntoRawFd; +use super::fd::{AsRawFd, BorrowedFd, FromRawFd, LibcFd, OwnedFd, RawFd}; #[cfg(not(windows))] use crate::ffi::CStr; use crate::io; @@ -16,7 +16,7 @@ pub(super) fn c_str(c: &CStr) -> *const c::c_char { c.as_ptr() } -#[cfg(not(windows))] +#[cfg(not(any(windows, target_os = "espidf", target_os = "wasi")))] #[inline] pub(super) fn no_fd() -> LibcFd { -1 @@ -27,6 +27,7 @@ pub(super) fn borrowed_fd(fd: BorrowedFd<'_>) -> LibcFd { fd.as_raw_fd() as LibcFd } +#[cfg(not(any(windows, target_os = "espidf", target_os = "redox")))] #[inline] pub(super) fn owned_fd(fd: OwnedFd) -> LibcFd { fd.into_raw_fd() as LibcFd @@ -41,6 +42,7 @@ pub(super) fn ret(raw: c::c_int) -> io::Result<()> { } } +#[cfg(apple)] #[inline] pub(super) fn nonnegative_ret(raw: c::c_int) -> io::Result<()> { if raw >= 0 { @@ -50,6 +52,7 @@ pub(super) fn nonnegative_ret(raw: c::c_int) -> io::Result<()> { } } +#[cfg(not(any(windows, target_os = "wasi")))] #[inline] pub(super) unsafe fn ret_infallible(raw: c::c_int) { debug_assert_eq!(raw, 0, "unexpected error: {:?}", io::Errno::last_os_error()); @@ -64,6 +67,7 @@ pub(super) fn ret_c_int(raw: c::c_int) -> io::Result<c::c_int> { } } +#[cfg(linux_kernel)] #[inline] pub(super) fn ret_u32(raw: c::c_int) -> io::Result<u32> { if raw == -1 { @@ -94,7 +98,7 @@ pub(super) fn ret_off_t(raw: c::off_t) -> io::Result<c::off_t> { } } -#[cfg(not(windows))] +#[cfg(not(any(windows, target_os = "wasi")))] #[inline] pub(super) fn ret_pid_t(raw: c::pid_t) -> io::Result<c::pid_t> { if raw == -1 { @@ -119,6 +123,7 @@ pub(super) unsafe fn ret_owned_fd(raw: LibcFd) -> io::Result<OwnedFd> { } } +#[cfg(not(any(windows, target_os = "wasi")))] #[inline] pub(super) fn ret_discarded_fd(raw: LibcFd) -> io::Result<()> { if raw == !0 { @@ -128,6 +133,7 @@ pub(super) fn ret_discarded_fd(raw: LibcFd) -> io::Result<()> { } } +#[cfg(not(any(windows, target_os = "wasi")))] #[inline] pub(super) fn ret_discarded_char_ptr(raw: *mut c::c_char) -> io::Result<()> { if raw.is_null() { @@ -138,7 +144,7 @@ pub(super) fn ret_discarded_char_ptr(raw: *mut c::c_char) -> io::Result<()> { } /// Convert the buffer-length argument value of a `send` or `recv` call. -#[cfg(not(windows))] +#[cfg(not(any(windows, target_os = "redox", target_os = "wasi")))] #[inline] pub(super) fn send_recv_len(len: usize) -> usize { len @@ -155,7 +161,7 @@ pub(super) fn send_recv_len(len: usize) -> i32 { } /// Convert the return value of a `send` or `recv` call. -#[cfg(not(windows))] +#[cfg(not(any(windows, target_os = "redox", target_os = "wasi")))] #[inline] pub(super) fn ret_send_recv(len: isize) -> io::Result<usize> { ret_usize(len) @@ -170,7 +176,7 @@ pub(super) fn ret_send_recv(len: i32) -> io::Result<usize> { /// Convert the value to the `msg_iovlen` field of a `msghdr` struct. #[cfg(all( - not(any(windows, target_os = "wasi")), + not(any(windows, target_os = "espidf", target_os = "redox", target_os = "wasi")), any( target_os = "android", all(target_os = "linux", not(target_env = "musl")) @@ -183,7 +189,7 @@ 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 = "wasi")), + not(any(windows, target_os = "espidf", target_os = "redox", target_os = "wasi")), not(any( target_os = "android", all(target_os = "linux", not(target_env = "musl")) @@ -200,8 +206,9 @@ pub(crate) fn msg_iov_len(len: usize) -> c::c_int { solarish, target_env = "musl", target_os = "emscripten", + target_os = "fuchsia", target_os = "haiku", - target_os = "fuchsia" + target_os = "nto", ))] #[inline] pub(crate) fn msg_control_len(len: usize) -> c::socklen_t { @@ -212,12 +219,15 @@ pub(crate) fn msg_control_len(len: usize) -> c::socklen_t { #[cfg(not(any( bsd, solarish, + windows, target_env = "musl", target_os = "emscripten", - target_os = "haiku", + target_os = "espidf", target_os = "fuchsia", - windows, - target_os = "wasi" + target_os = "haiku", + target_os = "nto", + target_os = "redox", + target_os = "wasi", )))] #[inline] pub(crate) fn msg_control_len(len: usize) -> c::size_t { diff --git a/vendor/rustix/src/backend/libc/event/poll_fd.rs b/vendor/rustix/src/backend/libc/event/poll_fd.rs index 49a6d1126..a06812aaa 100644 --- a/vendor/rustix/src/backend/libc/event/poll_fd.rs +++ b/vendor/rustix/src/backend/libc/event/poll_fd.rs @@ -26,18 +26,20 @@ bitflags! { /// `POLLRDNORM` const RDNORM = c::POLLRDNORM; /// `POLLWRNORM` + #[cfg(not(target_os = "l4re"))] const WRNORM = c::POLLWRNORM; /// `POLLRDBAND` - #[cfg(not(target_os = "wasi"))] + #[cfg(not(any(target_os = "l4re", target_os = "wasi")))] const RDBAND = c::POLLRDBAND; /// `POLLWRBAND` - #[cfg(not(target_os = "wasi"))] + #[cfg(not(any(target_os = "l4re", target_os = "wasi")))] const WRBAND = c::POLLWRBAND; /// `POLLERR` const ERR = c::POLLERR; /// `POLLHUP` const HUP = c::POLLHUP; /// `POLLNVAL` + #[cfg(not(target_os = "espidf"))] const NVAL = c::POLLNVAL; /// `POLLRDHUP` #[cfg(all( diff --git a/vendor/rustix/src/backend/libc/event/syscalls.rs b/vendor/rustix/src/backend/libc/event/syscalls.rs index 11f6af83e..eac88d4bb 100644 --- a/vendor/rustix/src/backend/libc/event/syscalls.rs +++ b/vendor/rustix/src/backend/libc/event/syscalls.rs @@ -33,7 +33,19 @@ pub(crate) fn eventfd(initval: u32, flags: EventfdFlags) -> io::Result<OwnedFd> ret_owned_fd(eventfd2(initval, bitflags_bits!(flags))) } - #[cfg(any(target_os = "freebsd", target_os = "illumos"))] + // `eventfd` was added in FreeBSD 13, so it isn't available on FreeBSD 12. + #[cfg(target_os = "freebsd")] + unsafe { + weakcall! { + fn eventfd( + initval: c::c_uint, + flags: c::c_int + ) -> c::c_int + } + ret_owned_fd(eventfd(initval, bitflags_bits!(flags))) + } + + #[cfg(target_os = "illumos")] unsafe { ret_owned_fd(c::eventfd(initval, bitflags_bits!(flags))) } diff --git a/vendor/rustix/src/backend/libc/fs/dir.rs b/vendor/rustix/src/backend/libc/fs/dir.rs index c8a4d77c9..6cfeb242b 100644 --- a/vendor/rustix/src/backend/libc/fs/dir.rs +++ b/vendor/rustix/src/backend/libc/fs/dir.rs @@ -1,4 +1,4 @@ -#[cfg(not(any(solarish, target_os = "haiku")))] +#[cfg(not(any(solarish, target_os = "haiku", target_os = "nto")))] use super::types::FileType; use crate::backend::c; use crate::backend::conv::owned_fd; @@ -9,6 +9,7 @@ use crate::fs::{fcntl_getfl, fstat, openat, Mode, OFlags, Stat}; solarish, target_os = "haiku", target_os = "netbsd", + target_os = "nto", target_os = "redox", target_os = "wasi", )))] @@ -94,7 +95,12 @@ impl Dir { check_dirent_layout(dirent); let result = DirEntry { - #[cfg(not(any(solarish, target_os = "aix", target_os = "haiku")))] + #[cfg(not(any( + solarish, + target_os = "aix", + target_os = "haiku", + target_os = "nto" + )))] d_type: dirent.d_type, #[cfg(not(any(freebsdlike, netbsdlike)))] @@ -122,6 +128,7 @@ impl Dir { solarish, target_os = "haiku", target_os = "netbsd", + target_os = "nto", target_os = "redox", target_os = "wasi", )))] @@ -180,7 +187,7 @@ impl fmt::Debug for Dir { /// `struct dirent` #[derive(Debug)] pub struct DirEntry { - #[cfg(not(any(solarish, target_os = "aix", target_os = "haiku")))] + #[cfg(not(any(solarish, target_os = "aix", target_os = "haiku", target_os = "nto")))] d_type: u8, #[cfg(not(any(freebsdlike, netbsdlike)))] @@ -200,7 +207,7 @@ impl DirEntry { } /// Returns the type of this directory entry. - #[cfg(not(any(solarish, target_os = "aix", target_os = "haiku")))] + #[cfg(not(any(solarish, target_os = "aix", target_os = "haiku", target_os = "nto")))] #[inline] pub fn file_type(&self) -> FileType { FileType::from_dirent_d_type(self.d_type) @@ -242,11 +249,13 @@ struct libc_dirent { #[cfg(target_os = "openbsd")] fn check_dirent_layout(dirent: &c::dirent) { use crate::utils::as_ptr; - use core::mem::{align_of, size_of}; // Check that the basic layouts match. - assert_eq!(size_of::<libc_dirent>(), size_of::<c::dirent>()); - assert_eq!(align_of::<libc_dirent>(), align_of::<c::dirent>()); + #[cfg(test)] + { + assert_eq_size!(libc_dirent, c::dirent); + assert_eq_size!(libc_dirent, c::dirent); + } // Check that the field offsets match. assert_eq!( diff --git a/vendor/rustix/src/backend/libc/fs/mod.rs b/vendor/rustix/src/backend/libc/fs/mod.rs index 28579c993..17b4da70f 100644 --- a/vendor/rustix/src/backend/libc/fs/mod.rs +++ b/vendor/rustix/src/backend/libc/fs/mod.rs @@ -1,8 +1,13 @@ -#[cfg(not(target_os = "redox"))] +#[cfg(not(any(target_os = "espidf", target_os = "redox")))] pub(crate) mod dir; #[cfg(linux_kernel)] pub mod inotify; -#[cfg(not(any(target_os = "haiku", target_os = "redox", target_os = "wasi")))] +#[cfg(not(any( + target_os = "espidf", + target_os = "haiku", + target_os = "redox", + target_os = "wasi" +)))] pub(crate) mod makedev; #[cfg(not(windows))] pub(crate) mod syscalls; diff --git a/vendor/rustix/src/backend/libc/fs/syscalls.rs b/vendor/rustix/src/backend/libc/fs/syscalls.rs index bdba777e9..698bf34ad 100644 --- a/vendor/rustix/src/backend/libc/fs/syscalls.rs +++ b/vendor/rustix/src/backend/libc/fs/syscalls.rs @@ -13,21 +13,24 @@ use crate::ffi::CString; netbsdlike, solarish, target_os = "dragonfly", + target_os = "espidf", target_os = "haiku", target_os = "redox", )))] use crate::fs::Advice; -#[cfg(not(target_os = "redox"))] +#[cfg(not(any(target_os = "espidf", target_os = "redox")))] use crate::fs::AtFlags; #[cfg(not(any( netbsdlike, solarish, target_os = "aix", target_os = "dragonfly", + target_os = "espidf", + target_os = "nto", target_os = "redox", )))] use crate::fs::FallocateFlags; -#[cfg(not(target_os = "wasi"))] +#[cfg(not(any(target_os = "espidf", target_os = "wasi")))] use crate::fs::FlockOperation; #[cfg(any(linux_kernel, target_os = "freebsd"))] use crate::fs::MemfdFlags; @@ -35,30 +38,26 @@ use crate::fs::MemfdFlags; use crate::fs::SealFlags; #[cfg(not(any( solarish, + target_os = "espidf", target_os = "haiku", target_os = "netbsd", + target_os = "nto", target_os = "redox", target_os = "wasi", )))] use crate::fs::StatFs; -use crate::fs::{Access, Mode, OFlags, SeekFrom, Stat, Timestamps}; -#[cfg(not(any(apple, target_os = "redox", target_os = "wasi")))] +#[cfg(not(target_os = "espidf"))] +use crate::fs::{Access, Timestamps}; +#[cfg(not(any(apple, target_os = "espidf", target_os = "redox", 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")))] use crate::fs::{StatVfs, StatVfsMountFlags}; use crate::io; -#[cfg(all( - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", -))] +#[cfg(all(target_env = "gnu", fix_y2038))] use crate::timespec::LibcTimespec; #[cfg(not(target_os = "wasi"))] use crate::ugid::{Gid, Uid}; -#[cfg(not(all( - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", -)))] -use crate::utils::as_ptr; #[cfg(apple)] use alloc::vec; use core::mem::MaybeUninit; @@ -75,15 +74,9 @@ use { core::ptr::null, }; -#[cfg(all( - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", -))] +#[cfg(all(target_env = "gnu", fix_y2038))] weak!(fn __utimensat64(c::c_int, *const c::c_char, *const LibcTimespec, c::c_int) -> c::c_int); -#[cfg(all( - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", -))] +#[cfg(all(target_env = "gnu", fix_y2038))] weak!(fn __futimens64(c::c_int, *const LibcTimespec) -> c::c_int); /// Use a direct syscall (via libc) for `open`. @@ -91,14 +84,25 @@ weak!(fn __futimens64(c::c_int, *const LibcTimespec) -> c::c_int); /// This is only currently necessary as a workaround for old glibc; see below. #[cfg(all(unix, target_env = "gnu"))] fn open_via_syscall(path: &CStr, oflags: OFlags, mode: Mode) -> io::Result<OwnedFd> { - // Linux on aarch64 and riscv64 has no `open` syscall so use `openat`. - #[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))] + // Linux on aarch64, loongarch64 and riscv64 has no `open` syscall so use + // `openat`. + #[cfg(any( + target_arch = "aarch64", + target_arch = "riscv32", + target_arch = "riscv64", + target_arch = "loongarch64" + ))] { openat_via_syscall(CWD, path, oflags, mode) } // Use the `open` syscall. - #[cfg(not(any(target_arch = "aarch64", target_arch = "riscv64")))] + #[cfg(not(any( + target_arch = "aarch64", + target_arch = "riscv32", + target_arch = "riscv64", + target_arch = "loongarch64" + )))] unsafe { syscall! { fn open( @@ -216,8 +220,10 @@ pub(crate) fn openat( #[cfg(not(any( solarish, + target_os = "espidf", target_os = "haiku", target_os = "netbsd", + target_os = "nto", target_os = "redox", target_os = "wasi", )))] @@ -243,11 +249,9 @@ pub(crate) fn statvfs(filename: &CStr) -> io::Result<StatVfs> { #[inline] pub(crate) fn readlink(path: &CStr, buf: &mut [u8]) -> io::Result<usize> { unsafe { - ret_usize(c::readlink( - c_str(path), - buf.as_mut_ptr().cast::<c::c_char>(), - buf.len(), - )) + ret_usize( + c::readlink(c_str(path), buf.as_mut_ptr().cast::<c::c_char>(), buf.len()) as isize, + ) } } @@ -264,7 +268,7 @@ pub(crate) fn readlinkat( c_str(path), buf.as_mut_ptr().cast::<c::c_char>(), buf.len(), - )) + ) as isize) } } @@ -308,7 +312,7 @@ pub(crate) fn link(old_path: &CStr, new_path: &CStr) -> io::Result<()> { unsafe { ret(c::link(c_str(old_path), c_str(new_path))) } } -#[cfg(not(target_os = "redox"))] +#[cfg(not(any(target_os = "espidf", target_os = "redox")))] pub(crate) fn linkat( old_dirfd: BorrowedFd<'_>, old_path: &CStr, @@ -371,7 +375,7 @@ pub(crate) fn unlink(path: &CStr) -> io::Result<()> { unsafe { ret(c::unlink(c_str(path))) } } -#[cfg(not(target_os = "redox"))] +#[cfg(not(any(target_os = "espidf", target_os = "redox")))] pub(crate) fn unlinkat(dirfd: BorrowedFd<'_>, path: &CStr, flags: AtFlags) -> io::Result<()> { // macOS <= 10.9 lacks `unlinkat`. #[cfg(target_os = "macos")] @@ -533,7 +537,14 @@ pub(crate) fn symlinkat( pub(crate) fn stat(path: &CStr) -> io::Result<Stat> { // See the comments in `fstat` about using `crate::fs::statx` here. - #[cfg(all(linux_kernel, any(target_pointer_width = "32", target_arch = "mips64")))] + #[cfg(all( + linux_kernel, + any( + target_pointer_width = "32", + target_arch = "mips64", + target_arch = "mips64r6" + ) + ))] { match crate::fs::statx( crate::fs::CWD, @@ -549,7 +560,14 @@ pub(crate) fn stat(path: &CStr) -> io::Result<Stat> { // Main version: libc is y2038 safe. Or, the platform is not y2038 safe and // there's nothing practical we can do. - #[cfg(not(all(linux_kernel, any(target_pointer_width = "32", target_arch = "mips64"))))] + #[cfg(not(all( + linux_kernel, + any( + target_pointer_width = "32", + target_arch = "mips64", + target_arch = "mips64r6" + ) + )))] unsafe { let mut stat = MaybeUninit::<Stat>::uninit(); ret(c::stat(c_str(path), stat.as_mut_ptr()))?; @@ -559,7 +577,14 @@ pub(crate) fn stat(path: &CStr) -> io::Result<Stat> { pub(crate) fn lstat(path: &CStr) -> io::Result<Stat> { // See the comments in `fstat` about using `crate::fs::statx` here. - #[cfg(all(linux_kernel, any(target_pointer_width = "32", target_arch = "mips64")))] + #[cfg(all( + linux_kernel, + any( + target_pointer_width = "32", + target_arch = "mips64", + target_arch = "mips64r6" + ) + ))] { match crate::fs::statx( crate::fs::CWD, @@ -568,14 +593,21 @@ pub(crate) fn lstat(path: &CStr) -> io::Result<Stat> { StatxFlags::BASIC_STATS, ) { Ok(x) => statx_to_stat(x), - Err(io::Errno::NOSYS) => statat_old(crate::fs::CWD, path, AtFlags::empty()), + Err(io::Errno::NOSYS) => statat_old(crate::fs::CWD, path, AtFlags::SYMLINK_NOFOLLOW), Err(err) => Err(err), } } // Main version: libc is y2038 safe. Or, the platform is not y2038 safe and // there's nothing practical we can do. - #[cfg(not(all(linux_kernel, any(target_pointer_width = "32", target_arch = "mips64"))))] + #[cfg(not(all( + linux_kernel, + any( + target_pointer_width = "32", + target_arch = "mips64", + target_arch = "mips64r6" + ) + )))] unsafe { let mut stat = MaybeUninit::<Stat>::uninit(); ret(c::lstat(c_str(path), stat.as_mut_ptr()))?; @@ -583,10 +615,17 @@ pub(crate) fn lstat(path: &CStr) -> io::Result<Stat> { } } -#[cfg(not(target_os = "redox"))] +#[cfg(not(any(target_os = "espidf", target_os = "redox")))] pub(crate) fn statat(dirfd: BorrowedFd<'_>, path: &CStr, flags: AtFlags) -> io::Result<Stat> { // See the comments in `fstat` about using `crate::fs::statx` here. - #[cfg(all(linux_kernel, any(target_pointer_width = "32", target_arch = "mips64")))] + #[cfg(all( + linux_kernel, + any( + target_pointer_width = "32", + target_arch = "mips64", + target_arch = "mips64r6" + ) + ))] { match crate::fs::statx(dirfd, path, flags, StatxFlags::BASIC_STATS) { Ok(x) => statx_to_stat(x), @@ -597,7 +636,14 @@ pub(crate) fn statat(dirfd: BorrowedFd<'_>, path: &CStr, flags: AtFlags) -> io:: // Main version: libc is y2038 safe. Or, the platform is not y2038 safe and // there's nothing practical we can do. - #[cfg(not(all(linux_kernel, any(target_pointer_width = "32", target_arch = "mips64"))))] + #[cfg(not(all( + linux_kernel, + any( + target_pointer_width = "32", + target_arch = "mips64", + target_arch = "mips64r6" + ) + )))] unsafe { let mut stat = MaybeUninit::<Stat>::uninit(); ret(c::fstatat( @@ -610,7 +656,14 @@ pub(crate) fn statat(dirfd: BorrowedFd<'_>, path: &CStr, flags: AtFlags) -> io:: } } -#[cfg(all(linux_kernel, any(target_pointer_width = "32", target_arch = "mips64")))] +#[cfg(all( + linux_kernel, + any( + target_pointer_width = "32", + target_arch = "mips64", + target_arch = "mips64r6" + ) +))] fn statat_old(dirfd: BorrowedFd<'_>, path: &CStr, flags: AtFlags) -> io::Result<Stat> { unsafe { let mut result = MaybeUninit::<c::stat64>::uninit(); @@ -624,12 +677,12 @@ fn statat_old(dirfd: BorrowedFd<'_>, path: &CStr, flags: AtFlags) -> io::Result< } } -#[cfg(not(target_os = "emscripten"))] +#[cfg(not(any(target_os = "espidf", target_os = "emscripten")))] 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 = "redox")))] +#[cfg(not(any(target_os = "emscripten", target_os = "espidf", target_os = "redox")))] pub(crate) fn accessat( dirfd: BorrowedFd<'_>, path: &CStr, @@ -695,47 +748,43 @@ pub(crate) fn accessat( Ok(()) } -#[cfg(not(target_os = "redox"))] +#[cfg(not(any(target_os = "espidf", target_os = "redox")))] pub(crate) fn utimensat( dirfd: BorrowedFd<'_>, path: &CStr, times: &Timestamps, flags: AtFlags, ) -> io::Result<()> { - // 32-bit gnu version: libc has `utimensat` but it is not y2038 safe by - // default. - #[cfg(all( - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", - ))] - unsafe { + // Old 32-bit version: libc has `utimensat` but it is not y2038 safe by + // default. But there may be a `__utimensat16` we can use. + #[cfg(fix_y2038)] + { + #[cfg(target_env = "gnu")] if let Some(libc_utimensat) = __utimensat64.get() { let libc_times: [LibcTimespec; 2] = [ times.last_access.clone().into(), times.last_modification.clone().into(), ]; - ret(libc_utimensat( - borrowed_fd(dirfd), - c_str(path), - libc_times.as_ptr(), - bitflags_bits!(flags), - )) - } else { - utimensat_old(dirfd, path, times, flags) + unsafe { + return ret(libc_utimensat( + borrowed_fd(dirfd), + c_str(path), + libc_times.as_ptr(), + bitflags_bits!(flags), + )); + } } + + utimensat_old(dirfd, path, times, flags) } // Main version: libc is y2038 safe and has `utimensat`. Or, the platform // is not y2038 safe and there's nothing practical we can do. - #[cfg(not(any( - apple, - all( - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", - ) - )))] + #[cfg(not(any(apple, fix_y2038)))] unsafe { + use crate::utils::as_ptr; + // Assert that `Timestamps` has the expected layout. let _ = core::mem::transmute::<Timestamps, [c::timespec; 2]>(times.clone()); @@ -747,9 +796,11 @@ pub(crate) fn utimensat( )) } - // `utimensat` was introduced in macOS 10.13. + // Apple version: `utimensat` was introduced in macOS 10.13. #[cfg(apple)] unsafe { + use crate::utils::as_ptr; + // ABI details weak! { fn utimensat( @@ -863,11 +914,8 @@ pub(crate) fn utimensat( } } -#[cfg(all( - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", -))] -unsafe fn utimensat_old( +#[cfg(fix_y2038)] +fn utimensat_old( dirfd: BorrowedFd<'_>, path: &CStr, times: &Timestamps, @@ -891,12 +939,14 @@ unsafe fn utimensat_old( tv_nsec: times.last_modification.tv_nsec, }, ]; - ret(c::utimensat( - borrowed_fd(dirfd), - c_str(path), - old_times.as_ptr(), - bitflags_bits!(flags), - )) + unsafe { + ret(c::utimensat( + borrowed_fd(dirfd), + c_str(path), + old_times.as_ptr(), + bitflags_bits!(flags), + )) + } } #[cfg(not(target_os = "wasi"))] @@ -904,7 +954,12 @@ pub(crate) fn chmod(path: &CStr, mode: Mode) -> io::Result<()> { unsafe { ret(c::chmod(c_str(path), mode.bits() as c::mode_t)) } } -#[cfg(not(any(linux_kernel, target_os = "redox", target_os = "wasi")))] +#[cfg(not(any( + linux_kernel, + target_os = "espidf", + target_os = "redox", + target_os = "wasi" +)))] pub(crate) fn chmodat( dirfd: BorrowedFd<'_>, path: &CStr, @@ -982,7 +1037,7 @@ pub(crate) fn fclonefileat( } } -#[cfg(not(any(target_os = "redox", target_os = "wasi")))] +#[cfg(not(any(target_os = "espidf", target_os = "redox", target_os = "wasi")))] pub(crate) fn chownat( dirfd: BorrowedFd<'_>, path: &CStr, @@ -1002,7 +1057,7 @@ pub(crate) fn chownat( } } -#[cfg(not(any(apple, target_os = "redox", target_os = "wasi")))] +#[cfg(not(any(apple, target_os = "espidf", target_os = "redox", target_os = "wasi")))] pub(crate) fn mknodat( dirfd: BorrowedFd<'_>, path: &CStr, @@ -1039,7 +1094,8 @@ pub(crate) fn copy_file_range( ) via SYS_copy_file_range -> c::ssize_t } - assert_eq!(size_of::<c::loff_t>(), size_of::<u64>()); + #[cfg(test)] + assert_eq_size!(c::loff_t, u64); let mut off_in_val: c::loff_t = 0; let mut off_out_val: c::loff_t = 0; @@ -1080,6 +1136,7 @@ pub(crate) fn copy_file_range( netbsdlike, solarish, target_os = "dragonfly", + target_os = "espidf", target_os = "haiku", target_os = "redox", )))] @@ -1135,6 +1192,7 @@ pub(crate) fn fcntl_add_seals(fd: BorrowedFd<'_>, seals: SealFlags) -> io::Resul #[cfg(not(any( target_os = "emscripten", + target_os = "espidf", target_os = "fuchsia", target_os = "redox", target_os = "wasi" @@ -1168,7 +1226,7 @@ pub(crate) fn fcntl_lock(fd: BorrowedFd<'_>, operation: FlockOperation) -> io::R } pub(crate) fn seek(fd: BorrowedFd<'_>, pos: SeekFrom) -> io::Result<u64> { - let (whence, offset): (c::c_int, c::off_t) = match pos { + let (whence, offset) = match pos { SeekFrom::Start(pos) => { let pos: u64 = pos; // Silently cast; we'll get `EINVAL` if the value is negative. @@ -1181,6 +1239,11 @@ pub(crate) fn seek(fd: BorrowedFd<'_>, pos: SeekFrom) -> io::Result<u64> { #[cfg(any(freebsdlike, target_os = "linux", target_os = "solaris"))] SeekFrom::Hole(offset) => (c::SEEK_HOLE, offset), }; + + // ESP-IDF doesn't support 64-bit offsets. + #[cfg(target_os = "espidf")] + let offset: i32 = offset.try_into().map_err(|_| io::Errno::OVERFLOW)?; + let offset = unsafe { ret_off_t(c::lseek(borrowed_fd(fd), offset, whence))? }; Ok(offset as u64) } @@ -1237,7 +1300,7 @@ pub(crate) fn fchown(fd: BorrowedFd<'_>, owner: Option<Uid>, group: Option<Gid>) } } -#[cfg(not(any(target_os = "solaris", target_os = "wasi")))] +#[cfg(not(any(target_os = "espidf", target_os = "solaris", 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)) } } @@ -1259,7 +1322,7 @@ pub(crate) fn syncfs(fd: BorrowedFd<'_>) -> io::Result<()> { unsafe { ret(syncfs(borrowed_fd(fd))) } } -#[cfg(not(any(target_os = "redox", target_os = "wasi")))] +#[cfg(not(any(target_os = "espidf", target_os = "redox", target_os = "wasi")))] pub(crate) fn sync() { unsafe { c::sync() } } @@ -1271,7 +1334,14 @@ pub(crate) fn fstat(fd: BorrowedFd<'_>) -> io::Result<Stat> { // And, some old platforms don't support `statx`, and some fail with a // confusing error code, so we call `crate::fs::statx` to handle that. If // `statx` isn't available, fall back to the buggy system call. - #[cfg(all(linux_kernel, any(target_pointer_width = "32", target_arch = "mips64")))] + #[cfg(all( + linux_kernel, + any( + target_pointer_width = "32", + target_arch = "mips64", + target_arch = "mips64r6" + ) + ))] { match crate::fs::statx(fd, cstr!(""), AtFlags::EMPTY_PATH, StatxFlags::BASIC_STATS) { Ok(x) => statx_to_stat(x), @@ -1282,7 +1352,14 @@ pub(crate) fn fstat(fd: BorrowedFd<'_>) -> io::Result<Stat> { // Main version: libc is y2038 safe. Or, the platform is not y2038 safe and // there's nothing practical we can do. - #[cfg(not(all(linux_kernel, any(target_pointer_width = "32", target_arch = "mips64"))))] + #[cfg(not(all( + linux_kernel, + any( + target_pointer_width = "32", + target_arch = "mips64", + target_arch = "mips64r6" + ) + )))] unsafe { let mut stat = MaybeUninit::<Stat>::uninit(); ret(c::fstat(borrowed_fd(fd), stat.as_mut_ptr()))?; @@ -1290,7 +1367,14 @@ pub(crate) fn fstat(fd: BorrowedFd<'_>) -> io::Result<Stat> { } } -#[cfg(all(linux_kernel, any(target_pointer_width = "32", target_arch = "mips64")))] +#[cfg(all( + linux_kernel, + any( + target_pointer_width = "32", + target_arch = "mips64", + target_arch = "mips64r6" + ) +))] fn fstat_old(fd: BorrowedFd<'_>) -> io::Result<Stat> { unsafe { let mut result = MaybeUninit::<c::stat64>::uninit(); @@ -1301,8 +1385,10 @@ fn fstat_old(fd: BorrowedFd<'_>) -> io::Result<Stat> { #[cfg(not(any( solarish, + target_os = "espidf", target_os = "haiku", target_os = "netbsd", + target_os = "nto", target_os = "redox", target_os = "wasi", )))] @@ -1340,44 +1426,44 @@ fn libc_statvfs_to_statvfs(from: c::statvfs) -> StatVfs { } } +#[cfg(not(target_os = "espidf"))] pub(crate) fn futimens(fd: BorrowedFd<'_>, times: &Timestamps) -> io::Result<()> { - // 32-bit gnu version: libc has `futimens` but it is not y2038 safe by default. - #[cfg(all( - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", - ))] - unsafe { + // Old 32-bit version: libc has `futimens` but it is not y2038 safe by + // default. But there may be a `__futimens64` we can use. + #[cfg(fix_y2038)] + { + #[cfg(target_env = "gnu")] if let Some(libc_futimens) = __futimens64.get() { let libc_times: [LibcTimespec; 2] = [ times.last_access.clone().into(), times.last_modification.clone().into(), ]; - ret(libc_futimens(borrowed_fd(fd), libc_times.as_ptr())) - } else { - futimens_old(fd, times) + unsafe { + return ret(libc_futimens(borrowed_fd(fd), libc_times.as_ptr())); + } } + + futimens_old(fd, times) } // Main version: libc is y2038 safe and has `futimens`. Or, the platform // is not y2038 safe and there's nothing practical we can do. - #[cfg(not(any( - apple, - all( - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", - ) - )))] + #[cfg(not(any(apple, fix_y2038)))] unsafe { + use crate::utils::as_ptr; + // Assert that `Timestamps` has the expected layout. let _ = core::mem::transmute::<Timestamps, [c::timespec; 2]>(times.clone()); ret(c::futimens(borrowed_fd(fd), as_ptr(times).cast())) } - // `futimens` was introduced in macOS 10.13. + // Apple version: `futimens` was introduced in macOS 10.13. #[cfg(apple)] unsafe { + use crate::utils::as_ptr; + // ABI details. weak! { fn futimens(c::c_int, *const c::timespec) -> c::c_int @@ -1413,11 +1499,8 @@ pub(crate) fn futimens(fd: BorrowedFd<'_>, times: &Timestamps) -> io::Result<()> } } -#[cfg(all( - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", -))] -unsafe fn futimens_old(fd: BorrowedFd<'_>, times: &Timestamps) -> io::Result<()> { +#[cfg(fix_y2038)] +fn futimens_old(fd: BorrowedFd<'_>, times: &Timestamps) -> io::Result<()> { let old_times = [ c::timespec { tv_sec: times @@ -1437,7 +1520,7 @@ unsafe fn futimens_old(fd: BorrowedFd<'_>, times: &Timestamps) -> io::Result<()> }, ]; - ret(c::futimens(borrowed_fd(fd), old_times.as_ptr())) + unsafe { ret(c::futimens(borrowed_fd(fd), old_times.as_ptr())) } } #[cfg(not(any( @@ -1446,6 +1529,8 @@ unsafe fn futimens_old(fd: BorrowedFd<'_>, times: &Timestamps) -> io::Result<()> solarish, target_os = "aix", target_os = "dragonfly", + target_os = "espidf", + target_os = "nto", target_os = "redox", )))] pub(crate) fn fallocate( @@ -1520,6 +1605,7 @@ pub(crate) fn fsync(fd: BorrowedFd<'_>) -> io::Result<()> { #[cfg(not(any( apple, target_os = "dragonfly", + target_os = "espidf", target_os = "haiku", target_os = "redox", )))] @@ -1648,7 +1734,7 @@ fn statx_to_stat(x: crate::fs::Statx) -> io::Result<Stat> { /// Convert from a Linux `statx` value to rustix's `Stat`. /// /// mips64' `struct stat64` in libc has private fields, and `stx_blocks` -#[cfg(all(linux_kernel, target_arch = "mips64"))] +#[cfg(all(linux_kernel, any(target_arch = "mips64", target_arch = "mips64r6")))] fn statx_to_stat(x: crate::fs::Statx) -> io::Result<Stat> { let mut result: Stat = unsafe { core::mem::zeroed() }; @@ -1720,7 +1806,7 @@ fn stat64_to_stat(s64: c::stat64) -> io::Result<Stat> { /// /// mips64' `struct stat64` in libc has private fields, and `st_blocks` has /// type `i64`. -#[cfg(all(linux_kernel, target_arch = "mips64"))] +#[cfg(all(linux_kernel, any(target_arch = "mips64", target_arch = "mips64r6")))] fn stat64_to_stat(s64: c::stat64) -> io::Result<Stat> { let mut result: Stat = unsafe { core::mem::zeroed() }; @@ -1962,6 +2048,22 @@ pub(crate) fn fcntl_fullfsync(fd: BorrowedFd<'_>) -> io::Result<()> { unsafe { ret(c::fcntl(borrowed_fd(fd), c::F_FULLFSYNC)) } } +#[cfg(apple)] +pub(crate) fn fcntl_nocache(fd: BorrowedFd, value: bool) -> io::Result<()> { + unsafe { ret(c::fcntl(borrowed_fd(fd), c::F_NOCACHE, value as c::c_int)) } +} + +#[cfg(apple)] +pub(crate) fn fcntl_global_nocache(fd: BorrowedFd, value: bool) -> io::Result<()> { + unsafe { + ret(c::fcntl( + borrowed_fd(fd), + c::F_GLOBAL_NOCACHE, + value as c::c_int, + )) + } +} + /// Convert `times` from a `futimens`/`utimensat` argument into `setattrlist` /// arguments. #[cfg(apple)] @@ -2048,30 +2150,6 @@ struct Attrlist { forkattr: Attrgroup, } -#[cfg(linux_kernel)] -pub(crate) fn mount( - source: Option<&CStr>, - target: &CStr, - file_system_type: Option<&CStr>, - flags: super::types::MountFlagsArg, - data: Option<&CStr>, -) -> io::Result<()> { - unsafe { - ret(c::mount( - source.map_or_else(null, CStr::as_ptr), - target.as_ptr(), - file_system_type.map_or_else(null, CStr::as_ptr), - flags.0, - data.map_or_else(null, CStr::as_ptr).cast(), - )) - } -} - -#[cfg(linux_kernel)] -pub(crate) fn unmount(target: &CStr, flags: super::types::UnmountFlags) -> io::Result<()> { - unsafe { ret(c::umount2(target.as_ptr(), bitflags_bits!(flags))) } -} - #[cfg(any(apple, linux_kernel))] pub(crate) fn getxattr(path: &CStr, name: &CStr, value: &mut [u8]) -> io::Result<usize> { let value_ptr = value.as_mut_ptr(); diff --git a/vendor/rustix/src/backend/libc/fs/types.rs b/vendor/rustix/src/backend/libc/fs/types.rs index b52f0e210..955bdaa29 100644 --- a/vendor/rustix/src/backend/libc/fs/types.rs +++ b/vendor/rustix/src/backend/libc/fs/types.rs @@ -1,6 +1,7 @@ use crate::backend::c; use bitflags::bitflags; +#[cfg(not(target_os = "espidf"))] bitflags! { /// `*_OK` constants for use with [`accessat`]. /// @@ -22,7 +23,7 @@ bitflags! { } } -#[cfg(not(target_os = "redox"))] +#[cfg(not(any(target_os = "espidf", target_os = "redox")))] bitflags! { /// `AT_*` constants for use with [`openat`], [`statat`], and other `*at` /// functions. @@ -85,67 +86,68 @@ bitflags! { #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct Mode: RawMode { /// `S_IRWXU` - #[cfg(not(target_os = "wasi"))] // WASI doesn't have Unix-style mode flags. + #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags. const RWXU = c::S_IRWXU as RawMode; /// `S_IRUSR` - #[cfg(not(target_os = "wasi"))] // WASI doesn't have Unix-style mode flags. + #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags. const RUSR = c::S_IRUSR as RawMode; /// `S_IWUSR` - #[cfg(not(target_os = "wasi"))] // WASI doesn't have Unix-style mode flags. + #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags. const WUSR = c::S_IWUSR as RawMode; /// `S_IXUSR` - #[cfg(not(target_os = "wasi"))] // WASI doesn't have Unix-style mode flags. + #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags. const XUSR = c::S_IXUSR as RawMode; /// `S_IRWXG` - #[cfg(not(target_os = "wasi"))] // WASI doesn't have Unix-style mode flags. + #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags. const RWXG = c::S_IRWXG as RawMode; /// `S_IRGRP` - #[cfg(not(target_os = "wasi"))] // WASI doesn't have Unix-style mode flags. + #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags. const RGRP = c::S_IRGRP as RawMode; /// `S_IWGRP` - #[cfg(not(target_os = "wasi"))] // WASI doesn't have Unix-style mode flags. + #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags. const WGRP = c::S_IWGRP as RawMode; /// `S_IXGRP` - #[cfg(not(target_os = "wasi"))] // WASI doesn't have Unix-style mode flags. + #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags. const XGRP = c::S_IXGRP as RawMode; /// `S_IRWXO` - #[cfg(not(target_os = "wasi"))] // WASI doesn't have Unix-style mode flags. + #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags. const RWXO = c::S_IRWXO as RawMode; /// `S_IROTH` - #[cfg(not(target_os = "wasi"))] // WASI doesn't have Unix-style mode flags. + #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags. const ROTH = c::S_IROTH as RawMode; /// `S_IWOTH` - #[cfg(not(target_os = "wasi"))] // WASI doesn't have Unix-style mode flags. + #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags. const WOTH = c::S_IWOTH as RawMode; /// `S_IXOTH` - #[cfg(not(target_os = "wasi"))] // WASI doesn't have Unix-style mode flags. + #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags. const XOTH = c::S_IXOTH as RawMode; /// `S_ISUID` - #[cfg(not(target_os = "wasi"))] // WASI doesn't have Unix-style mode flags. + #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags. const SUID = c::S_ISUID as RawMode; /// `S_ISGID` - #[cfg(not(target_os = "wasi"))] // WASI doesn't have Unix-style mode flags. + #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags. const SGID = c::S_ISGID as RawMode; /// `S_ISVTX` - #[cfg(not(target_os = "wasi"))] // WASI doesn't have Unix-style mode flags. + #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags. const SVTX = c::S_ISVTX as RawMode; } } +#[cfg(not(target_os = "espidf"))] impl Mode { /// Construct a `Mode` from the mode bits of the `st_mode` field of a /// `Stat`. @@ -161,6 +163,7 @@ impl Mode { } } +#[cfg(not(target_os = "espidf"))] impl From<RawMode> for Mode { /// Support conversions from raw mode values to `Mode`. /// @@ -174,6 +177,7 @@ impl From<RawMode> for Mode { } } +#[cfg(not(target_os = "espidf"))] impl From<Mode> for RawMode { /// Support conversions from `Mode` to raw mode values. /// @@ -214,10 +218,11 @@ bitflags! { const CREATE = bitcast!(c::O_CREAT); /// `O_DIRECTORY` + #[cfg(not(target_os = "espidf"))] const DIRECTORY = bitcast!(c::O_DIRECTORY); /// `O_DSYNC` - #[cfg(not(any(target_os = "dragonfly", target_os = "redox")))] + #[cfg(not(any(target_os = "dragonfly", target_os = "espidf", target_os = "l4re", target_os = "redox")))] const DSYNC = bitcast!(c::O_DSYNC); /// `O_EXCL` @@ -231,6 +236,7 @@ bitflags! { const FSYNC = bitcast!(c::O_FSYNC); /// `O_NOFOLLOW` + #[cfg(not(target_os = "espidf"))] const NOFOLLOW = bitcast!(c::O_NOFOLLOW); /// `O_NONBLOCK` @@ -246,7 +252,7 @@ bitflags! { const RDWR = bitcast!(c::O_RDWR); /// `O_NOCTTY` - #[cfg(not(target_os = "redox"))] + #[cfg(not(any(target_os = "espidf", target_os = "l4re", target_os = "redox")))] const NOCTTY = bitcast!(c::O_NOCTTY); /// `O_RSYNC` @@ -259,7 +265,7 @@ bitflags! { const RSYNC = bitcast!(c::O_RSYNC); /// `O_SYNC` - #[cfg(not(target_os = "redox"))] + #[cfg(not(any(target_os = "l4re", target_os = "redox")))] const SYNC = bitcast!(c::O_SYNC); /// `O_TRUNC` @@ -489,7 +495,13 @@ impl FileType { } /// Construct a `FileType` from the `d_type` field of a `c::dirent`. - #[cfg(not(any(solarish, target_os = "haiku", target_os = "redox")))] + #[cfg(not(any( + solarish, + target_os = "espidf", + target_os = "haiku", + target_os = "nto", + target_os = "redox" + )))] #[inline] pub(crate) const fn from_dirent_d_type(d_type: u8) -> Self { match d_type { @@ -516,6 +528,7 @@ impl FileType { netbsdlike, solarish, target_os = "dragonfly", + target_os = "espidf", target_os = "haiku", target_os = "redox", )))] @@ -725,7 +738,14 @@ bitflags! { } } -#[cfg(not(any(netbsdlike, solarish, target_os = "aix", target_os = "redox")))] +#[cfg(not(any( + netbsdlike, + solarish, + target_os = "aix", + target_os = "espidf", + target_os = "nto", + target_os = "redox" +)))] bitflags! { /// `FALLOC_FL_*` constants for use with [`fallocate`]. /// @@ -753,10 +773,11 @@ bitflags! { #[cfg(not(any( bsd, target_os = "aix", - target_os = "haiku", - target_os = "linux", target_os = "emscripten", target_os = "fuchsia", + target_os = "haiku", + target_os = "l4re", + target_os = "linux", target_os = "wasi", )))] const NO_HIDE_STALE = bitcast!(c::FALLOC_FL_NO_HIDE_STALE); @@ -831,9 +852,11 @@ bitflags! { const NOEXEC = c::ST_NOEXEC as u64; /// `ST_NOSUID` + #[cfg(not(target_os = "espidf"))] const NOSUID = c::ST_NOSUID as u64; /// `ST_RDONLY` + #[cfg(not(target_os = "espidf"))] const RDONLY = c::ST_RDONLY as u64; /// `ST_RELATIME` @@ -850,7 +873,7 @@ bitflags! { /// /// [`flock`]: crate::fs::flock /// [`fcntl_lock`]: crate::fs::fcntl_lock -#[cfg(not(target_os = "wasi"))] +#[cfg(not(any(target_os = "espidf", target_os = "wasi")))] #[derive(Clone, Copy, Debug, PartialEq, Eq)] #[repr(u32)] pub enum FlockOperation { @@ -923,8 +946,10 @@ pub struct Stat { #[cfg(not(any( linux_like, solarish, + target_os = "espidf", target_os = "haiku", target_os = "netbsd", + target_os = "nto", target_os = "redox", target_os = "wasi", )))] @@ -1062,10 +1087,16 @@ pub type FsWord = u32; pub type FsWord = u64; /// `__fsword_t` -// s390x uses `u32` for `statfs` entries, even though `__fsword_t` is `u64`. -#[cfg(all(target_os = "linux", target_arch = "s390x"))] +// s390x uses `u32` for `statfs` entries on glibc, even though `__fsword_t` is +// `u64`. +#[cfg(all(target_os = "linux", target_arch = "s390x", target_env = "gnu"))] pub type FsWord = u32; +/// `__fsword_t` +// s390x uses `u64` for `statfs` entries on musl. +#[cfg(all(target_os = "linux", target_arch = "s390x", target_env = "musl"))] +pub type FsWord = u64; + /// `copyfile_state_t`—State for use with [`fcopyfile`]. /// /// [`fcopyfile`]: crate::fs::fcopyfile @@ -1074,112 +1105,3 @@ pub type FsWord = u32; #[repr(transparent)] #[derive(Copy, Clone)] pub struct copyfile_state_t(pub(crate) *mut c::c_void); - -#[cfg(linux_kernel)] -bitflags! { - /// `MS_*` constants for use with [`mount`]. - /// - /// [`mount`]: crate::fs::mount - #[repr(transparent)] - #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] - pub struct MountFlags: c::c_ulong { - /// `MS_BIND` - const BIND = c::MS_BIND; - - /// `MS_DIRSYNC` - const DIRSYNC = c::MS_DIRSYNC; - - /// `MS_LAZYTIME` - const LAZYTIME = c::MS_LAZYTIME; - - /// `MS_MANDLOCK` - #[doc(alias = "MANDLOCK")] - const PERMIT_MANDATORY_FILE_LOCKING = c::MS_MANDLOCK; - - /// `MS_NOATIME` - const NOATIME = c::MS_NOATIME; - - /// `MS_NODEV` - const NODEV = c::MS_NODEV; - - /// `MS_NODIRATIME` - const NODIRATIME = c::MS_NODIRATIME; - - /// `MS_NOEXEC` - const NOEXEC = c::MS_NOEXEC; - - /// `MS_NOSUID` - const NOSUID = c::MS_NOSUID; - - /// `MS_RDONLY` - const RDONLY = c::MS_RDONLY; - - /// `MS_REC` - const REC = c::MS_REC; - - /// `MS_RELATIME` - const RELATIME = c::MS_RELATIME; - - /// `MS_SILENT` - const SILENT = c::MS_SILENT; - - /// `MS_STRICTATIME` - const STRICTATIME = c::MS_STRICTATIME; - - /// `MS_SYNCHRONOUS` - const SYNCHRONOUS = c::MS_SYNCHRONOUS; - } -} - -#[cfg(linux_kernel)] -bitflags! { - /// `MS_*` constants for use with [`change_mount`]. - /// - /// [`change_mount`]: crate::fs::mount::change_mount - #[repr(transparent)] - #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] - pub struct MountPropagationFlags: c::c_ulong { - /// `MS_SHARED` - const SHARED = c::MS_SHARED; - /// `MS_PRIVATE` - const PRIVATE = c::MS_PRIVATE; - /// `MS_SLAVE` - const SLAVE = c::MS_SLAVE; - /// `MS_UNBINDABLE` - const UNBINDABLE = c::MS_UNBINDABLE; - /// `MS_REC` - const REC = c::MS_REC; - } -} - -#[cfg(linux_kernel)] -bitflags! { - #[repr(transparent)] - #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] - pub(crate) struct InternalMountFlags: c::c_ulong { - const REMOUNT = c::MS_REMOUNT; - const MOVE = c::MS_MOVE; - } -} - -#[cfg(linux_kernel)] -pub(crate) struct MountFlagsArg(pub(crate) c::c_ulong); - -#[cfg(linux_kernel)] -bitflags! { - /// `MNT_*` constants for use with [`unmount`]. - /// - /// [`unmount`]: crate::fs::mount::unmount - #[repr(transparent)] - #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] - pub struct UnmountFlags: u32 { - /// `MNT_FORCE` - const FORCE = bitcast!(c::MNT_FORCE); - /// `MNT_DETACH` - const DETACH = bitcast!(c::MNT_DETACH); - /// `MNT_EXPIRE` - const EXPIRE = bitcast!(c::MNT_EXPIRE); - /// `UMOUNT_NOFOLLOW` - const NOFOLLOW = bitcast!(c::UMOUNT_NOFOLLOW); - } -} diff --git a/vendor/rustix/src/backend/libc/io/errno.rs b/vendor/rustix/src/backend/libc/io/errno.rs index 71fba49e9..aabd45f8c 100644 --- a/vendor/rustix/src/backend/libc/io/errno.rs +++ b/vendor/rustix/src/backend/libc/io/errno.rs @@ -28,15 +28,19 @@ impl Errno { bsd, windows, target_os = "aix", + target_os = "espidf", target_os = "haiku", + target_os = "l4re", target_os = "wasi", )))] pub const ADV: Self = Self(c::EADV); /// `EAFNOSUPPORT` + #[cfg(not(target_os = "l4re"))] pub const AFNOSUPPORT: Self = Self(c::EAFNOSUPPORT); /// `EAGAIN` pub const AGAIN: Self = Self(c::EAGAIN); /// `EALREADY` + #[cfg(not(target_os = "l4re"))] pub const ALREADY: Self = Self(c::EALREADY); /// `EAUTH` #[cfg(bsd)] @@ -46,7 +50,9 @@ impl Errno { bsd, windows, target_os = "aix", + target_os = "espidf", target_os = "haiku", + target_os = "l4re", target_os = "wasi", )))] pub const BADE: Self = Self(c::EBADE); @@ -57,19 +63,23 @@ impl Errno { bsd, windows, target_os = "aix", + target_os = "espidf", target_os = "haiku", + target_os = "l4re", target_os = "wasi", )))] pub const BADFD: Self = Self(c::EBADFD); /// `EBADMSG` - #[cfg(not(windows))] + #[cfg(not(any(windows, target_os = "l4re")))] pub const BADMSG: Self = Self(c::EBADMSG); /// `EBADR` #[cfg(not(any( bsd, windows, target_os = "aix", + target_os = "espidf", target_os = "haiku", + target_os = "l4re", target_os = "wasi", )))] pub const BADR: Self = Self(c::EBADR); @@ -81,7 +91,9 @@ impl Errno { bsd, windows, target_os = "aix", + target_os = "espidf", target_os = "haiku", + target_os = "l4re", target_os = "wasi", )))] pub const BADRQC: Self = Self(c::EBADRQC); @@ -90,7 +102,9 @@ impl Errno { bsd, windows, target_os = "aix", + target_os = "espidf", target_os = "haiku", + target_os = "l4re", target_os = "wasi", )))] pub const BADSLT: Self = Self(c::EBADSLT); @@ -99,7 +113,9 @@ impl Errno { bsd, windows, target_os = "aix", + target_os = "espidf", target_os = "haiku", + target_os = "l4re", target_os = "wasi", )))] pub const BFONT: Self = Self(c::EBFONT); @@ -107,6 +123,7 @@ impl Errno { #[cfg(not(windows))] pub const BUSY: Self = Self(c::EBUSY); /// `ECANCELED` + #[cfg(not(target_os = "l4re"))] pub const CANCELED: Self = Self(c::ECANCELED); /// `ECAPMODE` #[cfg(target_os = "freebsd")] @@ -115,14 +132,23 @@ impl Errno { #[cfg(not(windows))] pub const CHILD: Self = Self(c::ECHILD); /// `ECHRNG` - #[cfg(not(any(bsd, windows, target_os = "haiku", target_os = "wasi")))] + #[cfg(not(any( + bsd, + windows, + target_os = "espidf", + target_os = "haiku", + target_os = "l4re", + target_os = "wasi" + )))] pub const CHRNG: Self = Self(c::ECHRNG); /// `ECOMM` #[cfg(not(any( bsd, windows, target_os = "aix", + target_os = "espidf", target_os = "haiku", + target_os = "l4re", target_os = "wasi", )))] pub const COMM: Self = Self(c::ECOMM); @@ -141,11 +167,13 @@ impl Errno { windows, target_os = "aix", target_os = "android", + target_os = "espidf", target_os = "haiku", target_os = "wasi", )))] pub const DEADLOCK: Self = Self(c::EDEADLOCK); /// `EDESTADDRREQ` + #[cfg(not(target_os = "l4re"))] pub const DESTADDRREQ: Self = Self(c::EDESTADDRREQ); /// `EDISCON` #[cfg(windows)] @@ -162,7 +190,10 @@ impl Errno { solarish, windows, target_os = "aix", + target_os = "espidf", target_os = "haiku", + target_os = "l4re", + target_os = "nto", target_os = "wasi", )))] pub const DOTDOT: Self = Self(c::EDOTDOT); @@ -180,7 +211,7 @@ impl Errno { #[cfg(any(bsd, target_env = "newlib"))] pub const FTYPE: Self = Self(c::EFTYPE); /// `EHOSTDOWN` - #[cfg(not(target_os = "wasi"))] + #[cfg(not(any(target_os = "l4re", target_os = "wasi")))] pub const HOSTDOWN: Self = Self(c::EHOSTDOWN); /// `EHOSTUNREACH` pub const HOSTUNREACH: Self = Self(c::EHOSTUNREACH); @@ -191,18 +222,22 @@ impl Errno { windows, target_os = "aix", target_os = "android", + target_os = "espidf", target_os = "haiku", + target_os = "l4re", + target_os = "nto", target_os = "redox", target_os = "wasi", )))] pub const HWPOISON: Self = Self(c::EHWPOISON); /// `EIDRM` - #[cfg(not(windows))] + #[cfg(not(any(windows, target_os = "l4re")))] pub const IDRM: Self = Self(c::EIDRM); /// `EILSEQ` - #[cfg(not(windows))] + #[cfg(not(any(windows, target_os = "l4re")))] pub const ILSEQ: Self = Self(c::EILSEQ); /// `EINPROGRESS` + #[cfg(not(target_os = "l4re"))] pub const INPROGRESS: Self = Self(c::EINPROGRESS); /// `EINTR` /// @@ -223,6 +258,7 @@ impl Errno { #[cfg(not(windows))] pub const IO: Self = Self(c::EIO); /// `EISCONN` + #[cfg(not(target_os = "l4re"))] pub const ISCONN: Self = Self(c::EISCONN); /// `EISDIR` #[cfg(not(windows))] @@ -233,7 +269,10 @@ impl Errno { solarish, windows, target_os = "aix", + target_os = "espidf", target_os = "haiku", + target_os = "l4re", + target_os = "nto", target_os = "wasi", )))] pub const ISNAM: Self = Self(c::EISNAM); @@ -243,7 +282,10 @@ impl Errno { solarish, windows, target_os = "aix", + target_os = "espidf", target_os = "haiku", + target_os = "l4re", + target_os = "nto", target_os = "wasi", )))] pub const KEYEXPIRED: Self = Self(c::EKEYEXPIRED); @@ -253,7 +295,10 @@ impl Errno { solarish, windows, target_os = "aix", + target_os = "espidf", target_os = "haiku", + target_os = "l4re", + target_os = "nto", target_os = "wasi", )))] pub const KEYREJECTED: Self = Self(c::EKEYREJECTED); @@ -263,28 +308,61 @@ impl Errno { solarish, windows, target_os = "aix", + target_os = "espidf", target_os = "haiku", + target_os = "l4re", + target_os = "nto", target_os = "wasi", )))] pub const KEYREVOKED: Self = Self(c::EKEYREVOKED); /// `EL2HLT` - #[cfg(not(any(bsd, windows, target_os = "haiku", target_os = "wasi")))] + #[cfg(not(any( + bsd, + windows, + target_os = "espidf", + target_os = "haiku", + target_os = "l4re", + target_os = "wasi" + )))] pub const L2HLT: Self = Self(c::EL2HLT); /// `EL2NSYNC` - #[cfg(not(any(bsd, windows, target_os = "haiku", target_os = "wasi")))] + #[cfg(not(any( + bsd, + windows, + target_os = "espidf", + target_os = "haiku", + target_os = "l4re", + target_os = "wasi" + )))] pub const L2NSYNC: Self = Self(c::EL2NSYNC); /// `EL3HLT` - #[cfg(not(any(bsd, windows, target_os = "haiku", target_os = "wasi")))] + #[cfg(not(any( + bsd, + windows, + target_os = "espidf", + target_os = "haiku", + target_os = "l4re", + target_os = "wasi" + )))] pub const L3HLT: Self = Self(c::EL3HLT); /// `EL3RST` - #[cfg(not(any(bsd, windows, target_os = "haiku", target_os = "wasi")))] + #[cfg(not(any( + bsd, + windows, + target_os = "espidf", + target_os = "haiku", + target_os = "l4re", + target_os = "wasi" + )))] pub const L3RST: Self = Self(c::EL3RST); /// `ELIBACC` #[cfg(not(any( bsd, windows, target_os = "aix", + target_os = "espidf", target_os = "haiku", + target_os = "l4re", target_os = "wasi", )))] pub const LIBACC: Self = Self(c::ELIBACC); @@ -293,7 +371,9 @@ impl Errno { bsd, windows, target_os = "aix", + target_os = "espidf", target_os = "haiku", + target_os = "l4re", target_os = "wasi", )))] pub const LIBBAD: Self = Self(c::ELIBBAD); @@ -302,7 +382,9 @@ impl Errno { bsd, windows, target_os = "aix", + target_os = "espidf", target_os = "haiku", + target_os = "l4re", target_os = "wasi", )))] pub const LIBEXEC: Self = Self(c::ELIBEXEC); @@ -311,7 +393,9 @@ impl Errno { bsd, windows, target_os = "aix", + target_os = "espidf", target_os = "haiku", + target_os = "l4re", target_os = "wasi", )))] pub const LIBMAX: Self = Self(c::ELIBMAX); @@ -320,12 +404,21 @@ impl Errno { bsd, windows, target_os = "aix", + target_os = "espidf", target_os = "haiku", + target_os = "l4re", target_os = "wasi", )))] pub const LIBSCN: Self = Self(c::ELIBSCN); /// `ELNRNG` - #[cfg(not(any(bsd, windows, target_os = "haiku", target_os = "wasi")))] + #[cfg(not(any( + bsd, + windows, + target_os = "espidf", + target_os = "haiku", + target_os = "l4re", + target_os = "wasi" + )))] pub const LNRNG: Self = Self(c::ELNRNG); /// `ELOOP` pub const LOOP: Self = Self(c::ELOOP); @@ -335,7 +428,10 @@ impl Errno { solarish, windows, target_os = "aix", + target_os = "espidf", target_os = "haiku", + target_os = "l4re", + target_os = "nto", target_os = "wasi", )))] pub const MEDIUMTYPE: Self = Self(c::EMEDIUMTYPE); @@ -345,9 +441,10 @@ impl Errno { #[cfg(not(windows))] pub const MLINK: Self = Self(c::EMLINK); /// `EMSGSIZE` + #[cfg(not(target_os = "l4re"))] pub const MSGSIZE: Self = Self(c::EMSGSIZE); /// `EMULTIHOP` - #[cfg(not(any(windows, target_os = "openbsd")))] + #[cfg(not(any(windows, target_os = "l4re", target_os = "openbsd")))] pub const MULTIHOP: Self = Self(c::EMULTIHOP); /// `ENAMETOOLONG` pub const NAMETOOLONG: Self = Self(c::ENAMETOOLONG); @@ -357,7 +454,10 @@ impl Errno { solarish, windows, target_os = "aix", + target_os = "espidf", target_os = "haiku", + target_os = "l4re", + target_os = "nto", target_os = "wasi", )))] pub const NAVAIL: Self = Self(c::ENAVAIL); @@ -367,6 +467,7 @@ impl Errno { /// `ENETDOWN` pub const NETDOWN: Self = Self(c::ENETDOWN); /// `ENETRESET` + #[cfg(not(target_os = "l4re"))] pub const NETRESET: Self = Self(c::ENETRESET); /// `ENETUNREACH` pub const NETUNREACH: Self = Self(c::ENETUNREACH); @@ -378,7 +479,9 @@ impl Errno { bsd, windows, target_os = "aix", + target_os = "espidf", target_os = "haiku", + target_os = "l4re", target_os = "wasi", )))] pub const NOANO: Self = Self(c::ENOANO); @@ -386,9 +489,17 @@ impl Errno { #[cfg(any(bsd, target_os = "haiku"))] pub const NOATTR: Self = Self(c::ENOATTR); /// `ENOBUFS` + #[cfg(not(target_os = "l4re"))] pub const NOBUFS: Self = Self(c::ENOBUFS); /// `ENOCSI` - #[cfg(not(any(bsd, windows, target_os = "haiku", target_os = "wasi")))] + #[cfg(not(any( + bsd, + windows, + target_os = "espidf", + target_os = "haiku", + target_os = "l4re", + target_os = "wasi" + )))] pub const NOCSI: Self = Self(c::ENOCSI); /// `ENODATA` #[cfg(not(any( @@ -414,15 +525,18 @@ impl Errno { bsd, windows, target_os = "aix", + target_os = "espidf", target_os = "haiku", + target_os = "l4re", + target_os = "nto", target_os = "wasi", )))] pub const NOKEY: Self = Self(c::ENOKEY); /// `ENOLCK` - #[cfg(not(windows))] + #[cfg(not(any(windows, target_os = "l4re")))] pub const NOLCK: Self = Self(c::ENOLCK); /// `ENOLINK` - #[cfg(not(any(windows, target_os = "openbsd")))] + #[cfg(not(any(windows, target_os = "l4re", target_os = "openbsd")))] pub const NOLINK: Self = Self(c::ENOLINK); /// `ENOMEDIUM` #[cfg(not(any( @@ -430,7 +544,10 @@ impl Errno { solarish, windows, target_os = "aix", + target_os = "espidf", target_os = "haiku", + target_os = "l4re", + target_os = "nto", target_os = "wasi", )))] pub const NOMEDIUM: Self = Self(c::ENOMEDIUM); @@ -441,14 +558,16 @@ impl Errno { #[cfg(windows)] pub const NOMORE: Self = Self(c::ENOMORE); /// `ENOMSG` - #[cfg(not(windows))] + #[cfg(not(any(windows, target_os = "l4re")))] pub const NOMSG: Self = Self(c::ENOMSG); /// `ENONET` #[cfg(not(any( bsd, windows, target_os = "aix", + target_os = "espidf", target_os = "haiku", + target_os = "l4re", target_os = "wasi", )))] pub const NONET: Self = Self(c::ENONET); @@ -457,11 +576,14 @@ impl Errno { bsd, windows, target_os = "aix", + target_os = "espidf", target_os = "haiku", + target_os = "l4re", target_os = "wasi", )))] pub const NOPKG: Self = Self(c::ENOPKG); /// `ENOPROTOOPT` + #[cfg(not(target_os = "l4re"))] pub const NOPROTOOPT: Self = Self(c::ENOPROTOOPT); /// `ENOSPC` #[cfg(not(windows))] @@ -471,6 +593,7 @@ impl Errno { freebsdlike, windows, target_os = "haiku", + target_os = "l4re", target_os = "openbsd", target_os = "wasi", )))] @@ -480,6 +603,7 @@ impl Errno { freebsdlike, windows, target_os = "haiku", + target_os = "l4re", target_os = "openbsd", target_os = "wasi", )))] @@ -488,7 +612,7 @@ impl Errno { #[cfg(not(windows))] pub const NOSYS: Self = Self(c::ENOSYS); /// `ENOTBLK` - #[cfg(not(any(windows, target_os = "haiku", target_os = "wasi")))] + #[cfg(not(any(windows, target_os = "espidf", target_os = "haiku", target_os = "wasi")))] pub const NOTBLK: Self = Self(c::ENOTBLK); /// `ENOTCAPABLE` #[cfg(any(target_os = "freebsd", target_os = "wasi"))] @@ -506,14 +630,24 @@ impl Errno { solarish, windows, target_os = "aix", + target_os = "espidf", target_os = "haiku", + target_os = "l4re", + target_os = "nto", target_os = "wasi", )))] pub const NOTNAM: Self = Self(c::ENOTNAM); /// `ENOTRECOVERABLE` - #[cfg(not(any(freebsdlike, netbsdlike, windows, target_os = "haiku")))] + #[cfg(not(any( + freebsdlike, + netbsdlike, + windows, + target_os = "haiku", + target_os = "l4re" + )))] pub const NOTRECOVERABLE: Self = Self(c::ENOTRECOVERABLE); /// `ENOTSOCK` + #[cfg(not(target_os = "l4re"))] pub const NOTSOCK: Self = Self(c::ENOTSOCK); /// `ENOTSUP` #[cfg(not(any(windows, target_os = "haiku", target_os = "redox")))] @@ -526,7 +660,9 @@ impl Errno { bsd, windows, target_os = "aix", + target_os = "espidf", target_os = "haiku", + target_os = "l4re", target_os = "wasi", )))] pub const NOTUNIQ: Self = Self(c::ENOTUNIQ); @@ -536,16 +672,22 @@ impl Errno { /// `EOPNOTSUPP` pub const OPNOTSUPP: Self = Self(c::EOPNOTSUPP); /// `EOVERFLOW` - #[cfg(not(windows))] + #[cfg(not(any(windows, target_os = "l4re")))] pub const OVERFLOW: Self = Self(c::EOVERFLOW); /// `EOWNERDEAD` - #[cfg(not(any(freebsdlike, netbsdlike, windows, target_os = "haiku")))] + #[cfg(not(any( + freebsdlike, + netbsdlike, + windows, + target_os = "haiku", + target_os = "l4re" + )))] pub const OWNERDEAD: Self = Self(c::EOWNERDEAD); /// `EPERM` #[cfg(not(windows))] pub const PERM: Self = Self(c::EPERM); /// `EPFNOSUPPORT` - #[cfg(not(target_os = "wasi"))] + #[cfg(not(any(target_os = "l4re", target_os = "wasi")))] pub const PFNOSUPPORT: Self = Self(c::EPFNOSUPPORT); /// `EPIPE` #[cfg(not(windows))] @@ -563,11 +705,13 @@ impl Errno { #[cfg(bsd)] pub const PROGUNAVAIL: Self = Self(c::EPROGUNAVAIL); /// `EPROTO` - #[cfg(not(windows))] + #[cfg(not(any(windows, target_os = "l4re")))] pub const PROTO: Self = Self(c::EPROTO); /// `EPROTONOSUPPORT` + #[cfg(not(target_os = "l4re"))] pub const PROTONOSUPPORT: Self = Self(c::EPROTONOSUPPORT); /// `EPROTOTYPE` + #[cfg(not(target_os = "l4re"))] pub const PROTOTYPE: Self = Self(c::EPROTOTYPE); /// `EPROVIDERFAILEDINIT` #[cfg(windows)] @@ -583,12 +727,19 @@ impl Errno { bsd, windows, target_os = "aix", + target_os = "espidf", target_os = "haiku", + target_os = "l4re", target_os = "wasi", )))] pub const REMCHG: Self = Self(c::EREMCHG); /// `EREMOTE` - #[cfg(not(any(target_os = "haiku", target_os = "wasi")))] + #[cfg(not(any( + target_os = "espidf", + target_os = "haiku", + target_os = "l4re", + target_os = "wasi" + )))] pub const REMOTE: Self = Self(c::EREMOTE); /// `EREMOTEIO` #[cfg(not(any( @@ -596,12 +747,22 @@ impl Errno { solarish, windows, target_os = "aix", + target_os = "espidf", target_os = "haiku", + target_os = "l4re", + target_os = "nto", target_os = "wasi", )))] pub const REMOTEIO: Self = Self(c::EREMOTEIO); /// `ERESTART` - #[cfg(not(any(bsd, windows, target_os = "haiku", target_os = "wasi")))] + #[cfg(not(any( + bsd, + windows, + target_os = "espidf", + target_os = "haiku", + target_os = "l4re", + target_os = "wasi" + )))] pub const RESTART: Self = Self(c::ERESTART); /// `ERFKILL` #[cfg(not(any( @@ -610,7 +771,10 @@ impl Errno { windows, target_os = "aix", target_os = "android", + target_os = "espidf", target_os = "haiku", + target_os = "l4re", + target_os = "nto", target_os = "redox", target_os = "wasi", )))] @@ -622,10 +786,15 @@ impl Errno { #[cfg(bsd)] pub const RPCMISMATCH: Self = Self(c::ERPCMISMATCH); /// `ESHUTDOWN` - #[cfg(not(target_os = "wasi"))] + #[cfg(not(any(target_os = "espidf", target_os = "l4re", target_os = "wasi")))] pub const SHUTDOWN: Self = Self(c::ESHUTDOWN); /// `ESOCKTNOSUPPORT` - #[cfg(not(any(target_os = "haiku", target_os = "wasi")))] + #[cfg(not(any( + target_os = "espidf", + target_os = "haiku", + target_os = "l4re", + target_os = "wasi" + )))] pub const SOCKTNOSUPPORT: Self = Self(c::ESOCKTNOSUPPORT); /// `ESPIPE` #[cfg(not(windows))] @@ -638,7 +807,9 @@ impl Errno { bsd, windows, target_os = "aix", + target_os = "espidf", target_os = "haiku", + target_os = "l4re", target_os = "wasi", )))] pub const SRMNT: Self = Self(c::ESRMNT); @@ -649,12 +820,20 @@ impl Errno { bsd, windows, target_os = "aix", + target_os = "espidf", target_os = "haiku", + target_os = "l4re", target_os = "wasi", )))] pub const STRPIPE: Self = Self(c::ESTRPIPE); /// `ETIME` - #[cfg(not(any(freebsdlike, windows, target_os = "openbsd", target_os = "wasi")))] + #[cfg(not(any( + freebsdlike, + windows, + target_os = "l4re", + target_os = "openbsd", + target_os = "wasi" + )))] pub const TIME: Self = Self(c::ETIME); /// `ETIMEDOUT` pub const TIMEDOUT: Self = Self(c::ETIMEDOUT); @@ -663,7 +842,7 @@ impl Errno { #[doc(alias = "2BIG")] pub const TOOBIG: Self = Self(c::E2BIG); /// `ETOOMANYREFS` - #[cfg(not(any(target_os = "haiku", target_os = "wasi")))] + #[cfg(not(any(target_os = "haiku", target_os = "l4re", target_os = "wasi")))] pub const TOOMANYREFS: Self = Self(c::ETOOMANYREFS); /// `ETXTBSY` #[cfg(not(windows))] @@ -674,15 +853,30 @@ impl Errno { solarish, windows, target_os = "aix", + target_os = "espidf", target_os = "haiku", + target_os = "l4re", + target_os = "nto", target_os = "wasi", )))] pub const UCLEAN: Self = Self(c::EUCLEAN); /// `EUNATCH` - #[cfg(not(any(bsd, windows, target_os = "haiku", target_os = "wasi")))] + #[cfg(not(any( + bsd, + windows, + target_os = "espidf", + target_os = "haiku", + target_os = "l4re", + target_os = "wasi" + )))] pub const UNATCH: Self = Self(c::EUNATCH); /// `EUSERS` - #[cfg(not(any(target_os = "haiku", target_os = "wasi")))] + #[cfg(not(any( + target_os = "espidf", + target_os = "haiku", + target_os = "l4re", + target_os = "wasi" + )))] pub const USERS: Self = Self(c::EUSERS); /// `EWOULDBLOCK` pub const WOULDBLOCK: Self = Self(c::EWOULDBLOCK); @@ -694,7 +888,9 @@ impl Errno { bsd, windows, target_os = "aix", + target_os = "espidf", target_os = "haiku", + target_os = "l4re", 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 6ac1fa593..362af11ee 100644 --- a/vendor/rustix/src/backend/libc/io/syscalls.rs +++ b/vendor/rustix/src/backend/libc/io/syscalls.rs @@ -1,19 +1,28 @@ //! libc syscalls supporting `rustix::io`. -use crate::backend::conv::{ - borrowed_fd, ret, ret_c_int, ret_discarded_fd, ret_owned_fd, ret_usize, -}; -use crate::backend::{c, MAX_IOV}; +use crate::backend::c; +#[cfg(not(target_os = "wasi"))] +use crate::backend::conv::ret_discarded_fd; +use crate::backend::conv::{borrowed_fd, ret, ret_c_int, ret_owned_fd, ret_usize}; use crate::fd::{AsFd, BorrowedFd, OwnedFd, RawFd}; -#[cfg(not(any(target_os = "aix", target_os = "wasi")))] +#[cfg(not(any( + target_os = "aix", + target_os = "espidf", + target_os = "nto", + target_os = "wasi" +)))] use crate::io::DupFlags; #[cfg(linux_kernel)] use crate::io::ReadWriteFlags; -use crate::io::{self, FdFlags, IoSlice, IoSliceMut}; +use crate::io::{self, FdFlags}; use core::cmp::min; -use core::mem::MaybeUninit; #[cfg(all(feature = "fs", feature = "net"))] use libc_errno::errno; +#[cfg(not(target_os = "espidf"))] +use { + crate::backend::MAX_IOV, + crate::io::{IoSlice, IoSliceMut}, +}; pub(crate) fn read(fd: BorrowedFd<'_>, buf: &mut [u8]) -> io::Result<usize> { unsafe { @@ -41,6 +50,10 @@ 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")] + let offset: i32 = offset.try_into().map_err(|_| io::Errno::OVERFLOW)?; + unsafe { ret_usize(c::pread( borrowed_fd(fd), @@ -57,9 +70,14 @@ 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")] + 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)) } } +#[cfg(not(target_os = "espidf"))] pub(crate) fn readv(fd: BorrowedFd<'_>, bufs: &mut [IoSliceMut]) -> io::Result<usize> { unsafe { ret_usize(c::readv( @@ -70,6 +88,7 @@ pub(crate) fn readv(fd: BorrowedFd<'_>, bufs: &mut [IoSliceMut]) -> io::Result<u } } +#[cfg(not(target_os = "espidf"))] pub(crate) fn writev(fd: BorrowedFd<'_>, bufs: &[IoSlice]) -> io::Result<usize> { unsafe { ret_usize(c::writev( @@ -80,7 +99,13 @@ pub(crate) fn writev(fd: BorrowedFd<'_>, bufs: &[IoSlice]) -> io::Result<usize> } } -#[cfg(not(any(target_os = "haiku", target_os = "redox", target_os = "solaris")))] +#[cfg(not(any( + target_os = "espidf", + target_os = "haiku", + target_os = "nto", + target_os = "redox", + target_os = "solaris" +)))] pub(crate) fn preadv( fd: BorrowedFd<'_>, bufs: &mut [IoSliceMut], @@ -98,7 +123,13 @@ pub(crate) fn preadv( } } -#[cfg(not(any(target_os = "haiku", target_os = "redox", target_os = "solaris")))] +#[cfg(not(any( + target_os = "espidf", + target_os = "haiku", + target_os = "nto", + target_os = "redox", + target_os = "solaris" +)))] pub(crate) fn pwritev(fd: BorrowedFd<'_>, bufs: &[IoSlice], offset: u64) -> io::Result<usize> { // Silently cast; we'll get `EINVAL` if the value is negative. let offset = offset as i64; @@ -172,7 +203,10 @@ pub(crate) unsafe fn close(raw_fd: RawFd) { let _ = c::close(raw_fd as c::c_int); } +#[cfg(not(target_os = "espidf"))] pub(crate) fn ioctl_fionread(fd: BorrowedFd<'_>) -> io::Result<u64> { + use core::mem::MaybeUninit; + let mut nread = MaybeUninit::<c::c_int>::uninit(); unsafe { ret(c::ioctl(borrowed_fd(fd), c::FIONREAD, nread.as_mut_ptr()))?; @@ -193,6 +227,8 @@ pub(crate) fn ioctl_fionbio(fd: BorrowedFd<'_>, value: bool) -> io::Result<()> { #[cfg(not(any(target_os = "redox", target_os = "wasi")))] #[cfg(all(feature = "fs", feature = "net"))] pub(crate) fn is_read_write(fd: BorrowedFd<'_>) -> io::Result<(bool, bool)> { + use core::mem::MaybeUninit; + let (mut read, mut write) = crate::fs::fd::_is_file_read_write(fd)?; let mut not_socket = false; if read { @@ -251,11 +287,16 @@ pub(crate) fn fcntl_setfd(fd: BorrowedFd<'_>, flags: FdFlags) -> io::Result<()> unsafe { ret(c::fcntl(borrowed_fd(fd), c::F_SETFD, flags.bits())) } } -#[cfg(not(target_os = "wasi"))] +#[cfg(not(any(target_os = "espidf", target_os = "wasi")))] pub(crate) fn fcntl_dupfd_cloexec(fd: BorrowedFd<'_>, min: RawFd) -> io::Result<OwnedFd> { unsafe { ret_owned_fd(c::fcntl(borrowed_fd(fd), c::F_DUPFD_CLOEXEC, min)) } } +#[cfg(target_os = "espidf")] +pub(crate) fn fcntl_dupfd(fd: BorrowedFd<'_>, min: RawFd) -> io::Result<OwnedFd> { + unsafe { ret_owned_fd(c::fcntl(borrowed_fd(fd), c::F_DUPFD, min)) } +} + #[cfg(not(target_os = "wasi"))] pub(crate) fn dup(fd: BorrowedFd<'_>) -> io::Result<OwnedFd> { unsafe { ret_owned_fd(c::dup(borrowed_fd(fd))) } @@ -271,7 +312,9 @@ pub(crate) fn dup2(fd: BorrowedFd<'_>, new: &mut OwnedFd) -> io::Result<()> { target_os = "aix", target_os = "android", target_os = "dragonfly", + target_os = "espidf", target_os = "haiku", + target_os = "nto", target_os = "redox", target_os = "wasi", )))] diff --git a/vendor/rustix/src/backend/libc/mm/types.rs b/vendor/rustix/src/backend/libc/mm/types.rs index e4fecfccd..6a41cbe56 100644 --- a/vendor/rustix/src/backend/libc/mm/types.rs +++ b/vendor/rustix/src/backend/libc/mm/types.rs @@ -40,6 +40,21 @@ bitflags! { /// `PROT_GROWSDOWN` #[cfg(linux_kernel)] const GROWSDOWN = bitcast!(c::PROT_GROWSDOWN); + /// `PROT_SEM` + #[cfg(linux_kernel)] + const SEM = linux_raw_sys::general::PROT_SEM; + /// `PROT_BTI` + #[cfg(all(linux_kernel, target_arch = "aarch64"))] + const BTI = linux_raw_sys::general::PROT_BTI; + /// `PROT_MTE` + #[cfg(all(linux_kernel, target_arch = "aarch64"))] + const MTE = linux_raw_sys::general::PROT_MTE; + /// `PROT_SAO` + #[cfg(all(linux_kernel, any(target_arch = "powerpc", target_arch = "powerpc64")))] + const SAO = linux_raw_sys::general::PROT_SAO; + /// `PROT_ADI` + #[cfg(all(linux_kernel, any(target_arch = "sparc", target_arch = "sparc64")))] + const ADI = linux_raw_sys::general::PROT_ADI; } } @@ -63,6 +78,7 @@ bitflags! { target_os = "emscripten", target_os = "fuchsia", target_os = "haiku", + target_os = "nto", target_os = "redox", )))] const SHARED_VALIDATE = bitcast!(c::MAP_SHARED_VALIDATE); @@ -73,6 +89,7 @@ bitflags! { bsd, solarish, target_os = "haiku", + target_os = "nto", target_os = "redox", )))] const DENYWRITE = bitcast!(c::MAP_DENYWRITE); @@ -86,6 +103,7 @@ bitflags! { target_os = "emscripten", target_os = "fuchsia", target_os = "haiku", + target_os = "nto", target_os = "redox", )))] const FIXED_NOREPLACE = bitcast!(c::MAP_FIXED_NOREPLACE); @@ -94,6 +112,7 @@ bitflags! { bsd, solarish, target_os = "haiku", + target_os = "nto", target_os = "redox", )))] const GROWSDOWN = bitcast!(c::MAP_GROWSDOWN); @@ -102,6 +121,7 @@ bitflags! { bsd, solarish, target_os = "haiku", + target_os = "nto", target_os = "redox", )))] const HUGETLB = bitcast!(c::MAP_HUGETLB); @@ -113,6 +133,7 @@ bitflags! { target_os = "emscripten", target_os = "fuchsia", target_os = "haiku", + target_os = "nto", target_os = "redox", )))] const HUGE_2MB = bitcast!(c::MAP_HUGE_2MB); @@ -124,6 +145,7 @@ bitflags! { target_os = "emscripten", target_os = "fuchsia", target_os = "haiku", + target_os = "nto", target_os = "redox", )))] const HUGE_1GB = bitcast!(c::MAP_HUGE_1GB); @@ -132,6 +154,7 @@ bitflags! { bsd, solarish, target_os = "haiku", + target_os = "nto", target_os = "redox", )))] const LOCKED = bitcast!(c::MAP_LOCKED); @@ -139,7 +162,7 @@ bitflags! { #[cfg(freebsdlike)] const NOCORE = bitcast!(c::MAP_NOCORE); /// `MAP_NORESERVE` - #[cfg(not(any(freebsdlike, target_os = "redox")))] + #[cfg(not(any(freebsdlike, target_os = "nto", target_os = "redox")))] const NORESERVE = bitcast!(c::MAP_NORESERVE); /// `MAP_NOSYNC` #[cfg(freebsdlike)] @@ -149,6 +172,7 @@ bitflags! { bsd, solarish, target_os = "haiku", + target_os = "nto", target_os = "redox", )))] const POPULATE = bitcast!(c::MAP_POPULATE); @@ -173,10 +197,11 @@ bitflags! { target_os = "emscripten", target_os = "fuchsia", target_os = "haiku", + target_os = "nto", target_os = "redox", all( linux_kernel, - any(target_arch = "mips", target_arch = "mips64"), + any(target_arch = "mips", target_arch = "mips32r6", target_arch = "mips64", target_arch = "mips64r6"), ) )))] const SYNC = bitcast!(c::MAP_SYNC); @@ -308,7 +333,15 @@ pub enum Advice { #[cfg(linux_kernel)] LinuxHwPoison = bitcast!(c::MADV_HWPOISON), /// `MADV_SOFT_OFFLINE` - #[cfg(all(linux_kernel, not(any(target_arch = "mips", target_arch = "mips64"))))] + #[cfg(all( + linux_kernel, + not(any( + target_arch = "mips", + target_arch = "mips32r6", + target_arch = "mips64", + target_arch = "mips64r6" + )) + ))] LinuxSoftOffline = bitcast!(c::MADV_SOFT_OFFLINE), /// `MADV_MERGEABLE` #[cfg(linux_kernel)] diff --git a/vendor/rustix/src/backend/libc/mod.rs b/vendor/rustix/src/backend/libc/mod.rs index 357f99484..59fc3bea1 100644 --- a/vendor/rustix/src/backend/libc/mod.rs +++ b/vendor/rustix/src/backend/libc/mod.rs @@ -111,13 +111,19 @@ pub(crate) mod io; #[cfg(linux_kernel)] #[cfg(feature = "io_uring")] pub(crate) mod io_uring; -#[cfg(not(any(windows, target_os = "wasi")))] +#[cfg(not(any(windows, target_os = "espidf", target_os = "wasi")))] #[cfg(feature = "mm")] pub(crate) mod mm; +#[cfg(linux_kernel)] +#[cfg(feature = "mount")] +pub(crate) mod mount; +#[cfg(linux_kernel)] +#[cfg(all(feature = "fs", not(feature = "mount")))] +pub(crate) mod mount; // for deprecated mount functions in "fs" #[cfg(not(any(target_os = "redox", target_os = "wasi")))] #[cfg(feature = "net")] pub(crate) mod net; -#[cfg(not(windows))] +#[cfg(not(any(windows, target_os = "espidf")))] #[cfg(any( feature = "param", feature = "runtime", @@ -148,7 +154,7 @@ pub(crate) mod termios; #[cfg(not(windows))] #[cfg(feature = "thread")] pub(crate) mod thread; -#[cfg(not(windows))] +#[cfg(not(any(windows, target_os = "espidf")))] #[cfg(feature = "time")] pub(crate) mod time; @@ -193,6 +199,7 @@ const MAX_IOV: usize = c::UIO_MAXIOV as usize; linux_kernel, windows, target_os = "emscripten", + target_os = "espidf", target_os = "nto", target_os = "horizon", )))] diff --git a/vendor/rustix/src/backend/libc/mount/mod.rs b/vendor/rustix/src/backend/libc/mount/mod.rs new file mode 100644 index 000000000..1e0181a99 --- /dev/null +++ b/vendor/rustix/src/backend/libc/mount/mod.rs @@ -0,0 +1,2 @@ +pub(crate) mod syscalls; +pub(crate) mod types; diff --git a/vendor/rustix/src/backend/libc/mount/syscalls.rs b/vendor/rustix/src/backend/libc/mount/syscalls.rs new file mode 100644 index 000000000..26cdb52dc --- /dev/null +++ b/vendor/rustix/src/backend/libc/mount/syscalls.rs @@ -0,0 +1,272 @@ +use crate::backend::c; +use crate::backend::conv::ret; +#[cfg(feature = "mount")] +use crate::backend::conv::{borrowed_fd, c_str, ret_owned_fd}; +#[cfg(feature = "mount")] +use crate::fd::{BorrowedFd, OwnedFd}; +use crate::ffi::CStr; +use crate::io; +use core::ptr::null; + +#[cfg(linux_kernel)] +pub(crate) fn mount( + source: Option<&CStr>, + target: &CStr, + file_system_type: Option<&CStr>, + flags: super::types::MountFlagsArg, + data: Option<&CStr>, +) -> io::Result<()> { + unsafe { + ret(c::mount( + source.map_or_else(null, CStr::as_ptr), + target.as_ptr(), + file_system_type.map_or_else(null, CStr::as_ptr), + flags.0, + data.map_or_else(null, CStr::as_ptr).cast(), + )) + } +} + +#[cfg(linux_kernel)] +pub(crate) fn unmount(target: &CStr, flags: super::types::UnmountFlags) -> io::Result<()> { + unsafe { ret(c::umount2(target.as_ptr(), bitflags_bits!(flags))) } +} + +#[cfg(linux_kernel)] +#[cfg(feature = "mount")] +pub(crate) fn fsopen(fs_name: &CStr, flags: super::types::FsOpenFlags) -> io::Result<OwnedFd> { + syscall! { + fn fsopen( + fs_name: *const c::c_char, + flags: c::c_uint + ) via SYS_fsopen -> c::c_int + } + unsafe { ret_owned_fd(fsopen(c_str(fs_name), flags.bits())) } +} + +#[cfg(linux_kernel)] +#[cfg(feature = "mount")] +pub(crate) fn fsmount( + fs_fd: BorrowedFd<'_>, + flags: super::types::FsMountFlags, + attr_flags: super::types::MountAttrFlags, +) -> io::Result<()> { + syscall! { + fn fsmount( + fs_fd: c::c_int, + flags: c::c_uint, + attr_flags: c::c_uint + ) via SYS_fsmount -> c::c_int + } + unsafe { ret(fsmount(borrowed_fd(fs_fd), flags.bits(), attr_flags.bits())) } +} + +#[cfg(linux_kernel)] +#[cfg(feature = "mount")] +pub(crate) fn move_mount( + from_dfd: BorrowedFd<'_>, + from_pathname: &CStr, + to_dfd: BorrowedFd<'_>, + to_pathname: &CStr, + flags: super::types::MoveMountFlags, +) -> io::Result<()> { + syscall! { + fn move_mount( + from_dfd: c::c_int, + from_pathname: *const c::c_char, + to_dfd: c::c_int, + to_pathname: *const c::c_char, + flags: c::c_uint + ) via SYS_move_mount -> c::c_int + } + unsafe { + ret(move_mount( + borrowed_fd(from_dfd), + c_str(from_pathname), + borrowed_fd(to_dfd), + c_str(to_pathname), + flags.bits(), + )) + } +} + +#[cfg(linux_kernel)] +#[cfg(feature = "mount")] +pub(crate) fn open_tree( + dfd: BorrowedFd<'_>, + filename: &CStr, + flags: super::types::OpenTreeFlags, +) -> io::Result<OwnedFd> { + syscall! { + fn open_tree( + dfd: c::c_int, + filename: *const c::c_char, + flags: c::c_uint + ) via SYS_open_tree -> c::c_int + } + + unsafe { ret_owned_fd(open_tree(borrowed_fd(dfd), c_str(filename), flags.bits())) } +} + +#[cfg(linux_kernel)] +#[cfg(feature = "mount")] +pub(crate) fn fspick( + dfd: BorrowedFd<'_>, + path: &CStr, + flags: super::types::FsPickFlags, +) -> io::Result<OwnedFd> { + syscall! { + fn fspick( + dfd: c::c_int, + path: *const c::c_char, + flags: c::c_uint + ) via SYS_fspick -> c::c_int + } + + unsafe { ret_owned_fd(fspick(borrowed_fd(dfd), c_str(path), flags.bits())) } +} + +#[cfg(feature = "mount")] +#[cfg(linux_kernel)] +syscall! { + fn fsconfig( + fs_fd: c::c_int, + cmd: c::c_uint, + key: *const c::c_char, + val: *const c::c_char, + aux: c::c_int + ) via SYS_fsconfig -> c::c_int +} + +#[cfg(linux_kernel)] +#[cfg(feature = "mount")] +pub(crate) fn fsconfig_set_flag(fs_fd: BorrowedFd<'_>, key: &CStr) -> io::Result<()> { + unsafe { + ret(fsconfig( + borrowed_fd(fs_fd), + super::types::FsConfigCmd::SetFlag as _, + c_str(key), + null(), + 0, + )) + } +} + +#[cfg(linux_kernel)] +#[cfg(feature = "mount")] +pub(crate) fn fsconfig_set_string( + fs_fd: BorrowedFd<'_>, + key: &CStr, + value: &CStr, +) -> io::Result<()> { + unsafe { + ret(fsconfig( + borrowed_fd(fs_fd), + super::types::FsConfigCmd::SetString as _, + c_str(key), + c_str(value), + 0, + )) + } +} + +#[cfg(linux_kernel)] +#[cfg(feature = "mount")] +pub(crate) fn fsconfig_set_binary( + fs_fd: BorrowedFd<'_>, + key: &CStr, + value: &[u8], +) -> io::Result<()> { + unsafe { + ret(fsconfig( + borrowed_fd(fs_fd), + super::types::FsConfigCmd::SetBinary as _, + c_str(key), + value.as_ptr().cast(), + value.len().try_into().map_err(|_| io::Errno::OVERFLOW)?, + )) + } +} + +#[cfg(linux_kernel)] +#[cfg(feature = "mount")] +pub(crate) fn fsconfig_set_fd( + fs_fd: BorrowedFd<'_>, + key: &CStr, + fd: BorrowedFd<'_>, +) -> io::Result<()> { + unsafe { + ret(fsconfig( + borrowed_fd(fs_fd), + super::types::FsConfigCmd::SetFd as _, + c_str(key), + null(), + borrowed_fd(fd), + )) + } +} + +#[cfg(linux_kernel)] +#[cfg(feature = "mount")] +pub(crate) fn fsconfig_set_path( + fs_fd: BorrowedFd<'_>, + key: &CStr, + path: &CStr, + fd: BorrowedFd<'_>, +) -> io::Result<()> { + unsafe { + ret(fsconfig( + borrowed_fd(fs_fd), + super::types::FsConfigCmd::SetPath as _, + c_str(key), + c_str(path), + borrowed_fd(fd), + )) + } +} + +#[cfg(linux_kernel)] +#[cfg(feature = "mount")] +pub(crate) fn fsconfig_set_path_empty( + fs_fd: BorrowedFd<'_>, + key: &CStr, + fd: BorrowedFd<'_>, +) -> io::Result<()> { + unsafe { + ret(fsconfig( + borrowed_fd(fs_fd), + super::types::FsConfigCmd::SetPathEmpty as _, + c_str(key), + c_str(cstr!("")), + borrowed_fd(fd), + )) + } +} + +#[cfg(linux_kernel)] +#[cfg(feature = "mount")] +pub(crate) fn fsconfig_create(fs_fd: BorrowedFd<'_>) -> io::Result<()> { + unsafe { + ret(fsconfig( + borrowed_fd(fs_fd), + super::types::FsConfigCmd::Create as _, + null(), + null(), + 0, + )) + } +} + +#[cfg(linux_kernel)] +#[cfg(feature = "mount")] +pub(crate) fn fsconfig_reconfigure(fs_fd: BorrowedFd<'_>) -> io::Result<()> { + unsafe { + ret(fsconfig( + borrowed_fd(fs_fd), + super::types::FsConfigCmd::Reconfigure as _, + null(), + null(), + 0, + )) + } +} diff --git a/vendor/rustix/src/backend/libc/mount/types.rs b/vendor/rustix/src/backend/libc/mount/types.rs new file mode 100644 index 000000000..660e6ae37 --- /dev/null +++ b/vendor/rustix/src/backend/libc/mount/types.rs @@ -0,0 +1,311 @@ +use crate::backend::c; +use bitflags::bitflags; + +#[cfg(linux_kernel)] +bitflags! { + /// `MS_*` constants for use with [`mount`]. + /// + /// [`mount`]: crate::mount::mount + #[repr(transparent)] + #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] + pub struct MountFlags: c::c_ulong { + /// `MS_BIND` + const BIND = c::MS_BIND; + + /// `MS_DIRSYNC` + const DIRSYNC = c::MS_DIRSYNC; + + /// `MS_LAZYTIME` + const LAZYTIME = c::MS_LAZYTIME; + + /// `MS_MANDLOCK` + #[doc(alias = "MANDLOCK")] + const PERMIT_MANDATORY_FILE_LOCKING = c::MS_MANDLOCK; + + /// `MS_NOATIME` + const NOATIME = c::MS_NOATIME; + + /// `MS_NODEV` + const NODEV = c::MS_NODEV; + + /// `MS_NODIRATIME` + const NODIRATIME = c::MS_NODIRATIME; + + /// `MS_NOEXEC` + const NOEXEC = c::MS_NOEXEC; + + /// `MS_NOSUID` + const NOSUID = c::MS_NOSUID; + + /// `MS_RDONLY` + const RDONLY = c::MS_RDONLY; + + /// `MS_REC` + const REC = c::MS_REC; + + /// `MS_RELATIME` + const RELATIME = c::MS_RELATIME; + + /// `MS_SILENT` + const SILENT = c::MS_SILENT; + + /// `MS_STRICTATIME` + const STRICTATIME = c::MS_STRICTATIME; + + /// `MS_SYNCHRONOUS` + const SYNCHRONOUS = c::MS_SYNCHRONOUS; + } +} + +#[cfg(linux_kernel)] +bitflags! { + /// `MNT_*` constants for use with [`unmount`]. + /// + /// [`unmount`]: crate::mount::unmount + #[repr(transparent)] + #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] + pub struct UnmountFlags: u32 { + /// `MNT_FORCE` + const FORCE = bitcast!(c::MNT_FORCE); + /// `MNT_DETACH` + const DETACH = bitcast!(c::MNT_DETACH); + /// `MNT_EXPIRE` + const EXPIRE = bitcast!(c::MNT_EXPIRE); + /// `UMOUNT_NOFOLLOW` + const NOFOLLOW = bitcast!(c::UMOUNT_NOFOLLOW); + } +} + +#[cfg(feature = "mount")] +#[cfg(linux_kernel)] +bitflags! { + /// `FSOPEN_*` constants for use with [`fsopen`]. + /// + /// [`fsopen`]: crate::mount::fsopen + #[repr(transparent)] + #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] + pub struct FsOpenFlags: c::c_uint { + + /// `FSOPEN_CLOEXEC` + const FSOPEN_CLOEXEC = 0x00000001; + } +} + +#[cfg(feature = "mount")] +#[cfg(linux_kernel)] +bitflags! { + /// `FSMOUNT_*` constants for use with [`fsmount`]. + /// + /// [`fsmount`]: crate::mount::fsmount + #[repr(transparent)] + #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] + pub struct FsMountFlags: c::c_uint { + /// `FSMOUNT_CLOEXEC` + const FSMOUNT_CLOEXEC = 0x00000001; + } +} + +/// `FSCONFIG_*` constants for use with the `fsconfig` syscall. +#[cfg(feature = "mount")] +#[cfg(linux_kernel)] +#[derive(Debug, Copy, Clone, Eq, PartialEq)] +#[repr(u32)] +pub(crate) enum FsConfigCmd { + /// `FSCONFIG_SET_FLAG` + SetFlag = 0, + + /// `FSCONFIG_SET_STRING` + SetString = 1, + + /// `FSCONFIG_SET_BINARY` + SetBinary = 2, + + /// `FSCONFIG_SET_PATH` + SetPath = 3, + + /// `FSCONFIG_SET_PATH_EMPTY` + SetPathEmpty = 4, + + /// `FSCONFIG_SET_FD` + SetFd = 5, + + /// `FSCONFIG_CMD_CREATE` + Create = 6, + + /// `FSCONFIG_CMD_RECONFIGURE` + Reconfigure = 7, +} + +#[cfg(feature = "mount")] +#[cfg(linux_kernel)] +bitflags! { + /// `MOUNT_ATTR_*` constants for use with [`fsmount`]. + /// + /// [`fsmount`]: crate::mount::fsmount + #[repr(transparent)] + #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] + pub struct MountAttrFlags: c::c_uint { + /// `MOUNT_ATTR_RDONLY` + const MOUNT_ATTR_RDONLY = 0x00000001; + + /// `MOUNT_ATTR_NOSUID` + const MOUNT_ATTR_NOSUID = 0x00000002; + + /// `MOUNT_ATTR_NODEV` + const MOUNT_ATTR_NODEV = 0x00000004; + + /// `MOUNT_ATTR_NOEXEC` + const MOUNT_ATTR_NOEXEC = 0x00000008; + + /// `MOUNT_ATTR__ATIME` + const MOUNT_ATTR__ATIME = 0x00000070; + + /// `MOUNT_ATTR_RELATIME` + const MOUNT_ATTR_RELATIME = 0x00000000; + + /// `MOUNT_ATTR_NOATIME` + const MOUNT_ATTR_NOATIME = 0x00000010; + + /// `MOUNT_ATTR_STRICTATIME` + const MOUNT_ATTR_STRICTATIME = 0x00000020; + + /// `MOUNT_ATTR_NODIRATIME` + const MOUNT_ATTR_NODIRATIME = 0x00000080; + + /// `MOUNT_ATTR_NOUSER` + const MOUNT_ATTR_IDMAP = 0x00100000; + + /// `MOUNT_ATTR__ATIME_FLAGS` + const MOUNT_ATTR_NOSYMFOLLOW = 0x00200000; + + /// `MOUNT_ATTR__ATIME_FLAGS` + const MOUNT_ATTR_SIZE_VER0 = 32; + } +} + +#[cfg(feature = "mount")] +#[cfg(linux_kernel)] +bitflags! { + /// `MOVE_MOUNT_*` constants for use with [`move_mount`]. + /// + /// [`move_mount`]: crate::mount::move_mount + #[repr(transparent)] + #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] + pub struct MoveMountFlags: c::c_uint { + /// `MOVE_MOUNT_F_EMPTY_PATH` + const MOVE_MOUNT_F_SYMLINKS = 0x00000001; + + /// `MOVE_MOUNT_F_AUTOMOUNTS` + const MOVE_MOUNT_F_AUTOMOUNTS = 0x00000002; + + /// `MOVE_MOUNT_F_EMPTY_PATH` + const MOVE_MOUNT_F_EMPTY_PATH = 0x00000004; + + /// `MOVE_MOUNT_T_SYMLINKS` + const MOVE_MOUNT_T_SYMLINKS = 0x00000010; + + /// `MOVE_MOUNT_T_AUTOMOUNTS` + const MOVE_MOUNT_T_AUTOMOUNTS = 0x00000020; + + /// `MOVE_MOUNT_T_EMPTY_PATH` + const MOVE_MOUNT_T_EMPTY_PATH = 0x00000040; + + /// `MOVE_MOUNT__MASK` + const MOVE_MOUNT_SET_GROUP = 0x00000100; + + // TODO: add when linux 6.5 is released + // /// `MOVE_MOUNT_BENEATH` + // const MOVE_MOUNT_BENEATH = 0x00000200; + + /// `MOVE_MOUNT__MASK` + const MOVE_MOUNT__MASK = 0x00000377; + } +} + +#[cfg(feature = "mount")] +#[cfg(linux_kernel)] +bitflags! { + /// `OPENTREE_*` constants for use with [`open_tree`]. + /// + /// [`open_tree`]: crate::mount::open_tree + #[repr(transparent)] + #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] + pub struct OpenTreeFlags: c::c_uint { + /// `OPENTREE_CLONE` + const OPEN_TREE_CLONE = 1; + + /// `OPENTREE_CLOEXEC` + const OPEN_TREE_CLOEXEC = c::O_CLOEXEC as c::c_uint; + + /// `AT_EMPTY_PATH` + const AT_EMPTY_PATH = c::AT_EMPTY_PATH as c::c_uint; + + /// `AT_NO_AUTOMOUNT` + const AT_NO_AUTOMOUNT = c::AT_NO_AUTOMOUNT as c::c_uint; + + /// `AT_RECURSIVE` + const AT_RECURSIVE = c::AT_RECURSIVE as c::c_uint; + + /// `AT_SYMLINK_NOFOLLOW` + const AT_SYMLINK_NOFOLLOW = c::AT_SYMLINK_NOFOLLOW as c::c_uint; + } +} + +#[cfg(feature = "mount")] +#[cfg(linux_kernel)] +bitflags! { + /// `FSPICK_*` constants for use with [`fspick`]. + /// + /// [`fspick`]: crate::mount::fspick + #[repr(transparent)] + #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] + pub struct FsPickFlags: c::c_uint { + /// `FSPICK_CLOEXEC` + const FSPICK_CLOEXEC = 0x00000001; + + /// `FSPICK_SYMLINK_NOFOLLOW` + const FSPICK_SYMLINK_NOFOLLOW = 0x00000002; + + /// `FSPICK_NO_AUTOMOUNT` + const FSPICK_NO_AUTOMOUNT = 0x00000004; + + /// `FSPICK_EMPTY_PATH` + const FSPICK_EMPTY_PATH = 0x00000008; + } +} + +#[cfg(linux_kernel)] +bitflags! { + /// `MS_*` constants for use with [`change_mount`]. + /// + /// [`change_mount`]: crate::mount::change_mount + #[repr(transparent)] + #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] + pub struct MountPropagationFlags: c::c_ulong { + /// `MS_SILENT` + const SILENT = c::MS_SILENT; + /// `MS_SHARED` + const SHARED = c::MS_SHARED; + /// `MS_PRIVATE` + const PRIVATE = c::MS_PRIVATE; + /// `MS_SLAVE` + const SLAVE = c::MS_SLAVE; + /// `MS_UNBINDABLE` + const UNBINDABLE = c::MS_UNBINDABLE; + /// `MS_REC` + const REC = c::MS_REC; + } +} + +#[cfg(linux_kernel)] +bitflags! { + #[repr(transparent)] + #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] + pub(crate) struct InternalMountFlags: c::c_ulong { + const REMOUNT = c::MS_REMOUNT; + const MOVE = c::MS_MOVE; + } +} + +#[cfg(linux_kernel)] +pub(crate) struct MountFlagsArg(pub(crate) c::c_ulong); diff --git a/vendor/rustix/src/backend/libc/net/addr.rs b/vendor/rustix/src/backend/libc/net/addr.rs index bf7d239de..bd2e7dafe 100644 --- a/vendor/rustix/src/backend/libc/net/addr.rs +++ b/vendor/rustix/src/backend/libc/net/addr.rs @@ -76,12 +76,12 @@ impl SocketAddrUnix { fn init() -> c::sockaddr_un { c::sockaddr_un { - #[cfg(any(bsd, target_os = "haiku"))] + #[cfg(any(bsd, target_os = "haiku", target_os = "nto"))] sun_len: 0, sun_family: c::AF_UNIX as _, - #[cfg(bsd)] + #[cfg(any(bsd, target_os = "nto"))] sun_path: [0; 104], - #[cfg(not(any(bsd, target_os = "haiku")))] + #[cfg(not(any(bsd, target_os = "haiku", target_os = "nto")))] sun_path: [0; 108], #[cfg(target_os = "haiku")] sun_path: [0; 126], @@ -208,15 +208,15 @@ pub type SocketAddrStorage = c::sockaddr_storage; #[inline] pub(crate) fn offsetof_sun_path() -> usize { let z = c::sockaddr_un { - #[cfg(any(bsd, target_os = "haiku"))] + #[cfg(any(bsd, target_os = "haiku", target_os = "nto"))] sun_len: 0_u8, - #[cfg(any(bsd, target_os = "haiku"))] + #[cfg(any(bsd, target_os = "espidf", target_os = "haiku", target_os = "nto"))] sun_family: 0_u8, - #[cfg(not(any(bsd, target_os = "haiku")))] + #[cfg(not(any(bsd, target_os = "espidf", target_os = "haiku", target_os = "nto")))] sun_family: 0_u16, - #[cfg(bsd)] + #[cfg(any(bsd, target_os = "nto"))] sun_path: [0; 104], - #[cfg(not(any(bsd, target_os = "haiku")))] + #[cfg(not(any(bsd, target_os = "haiku", target_os = "nto")))] sun_path: [0; 108], #[cfg(target_os = "haiku")] sun_path: [0; 126], diff --git a/vendor/rustix/src/backend/libc/net/ext.rs b/vendor/rustix/src/backend/libc/net/ext.rs index 4b2d10756..50bd89db6 100644 --- a/vendor/rustix/src/backend/libc/net/ext.rs +++ b/vendor/rustix/src/backend/libc/net/ext.rs @@ -78,7 +78,7 @@ pub(crate) const fn sockaddr_in6_sin6_scope_id(addr: &c::sockaddr_in6) -> u32 { #[cfg(not(windows))] #[inline] pub(crate) const fn sockaddr_in6_new( - #[cfg(any(bsd, target_os = "haiku"))] sin6_len: u8, + #[cfg(any(bsd, target_os = "espidf", target_os = "haiku", target_os = "nto"))] sin6_len: u8, sin6_family: c::sa_family_t, sin6_port: u16, sin6_flowinfo: u32, @@ -86,7 +86,7 @@ pub(crate) const fn sockaddr_in6_new( sin6_scope_id: u32, ) -> c::sockaddr_in6 { c::sockaddr_in6 { - #[cfg(any(bsd, target_os = "haiku"))] + #[cfg(any(bsd, target_os = "espidf", target_os = "haiku", target_os = "nto"))] sin6_len, sin6_family, sin6_port, diff --git a/vendor/rustix/src/backend/libc/net/mod.rs b/vendor/rustix/src/backend/libc/net/mod.rs index 1b68f1b26..65c7d0654 100644 --- a/vendor/rustix/src/backend/libc/net/mod.rs +++ b/vendor/rustix/src/backend/libc/net/mod.rs @@ -1,6 +1,6 @@ pub(crate) mod addr; pub(crate) mod ext; -#[cfg(not(any(target_os = "redox", target_os = "wasi", windows)))] +#[cfg(not(any(windows, target_os = "espidf", target_os = "redox", target_os = "wasi")))] pub(crate) mod msghdr; pub(crate) mod read_sockaddr; pub(crate) mod send_recv; diff --git a/vendor/rustix/src/backend/libc/net/read_sockaddr.rs b/vendor/rustix/src/backend/libc/net/read_sockaddr.rs index c3b23e8c2..cde851af6 100644 --- a/vendor/rustix/src/backend/libc/net/read_sockaddr.rs +++ b/vendor/rustix/src/backend/libc/net/read_sockaddr.rs @@ -26,11 +26,11 @@ struct sockaddr_header { unsafe fn read_ss_family(storage: *const c::sockaddr_storage) -> u16 { // Assert that we know the layout of `sockaddr`. let _ = c::sockaddr { - #[cfg(any(bsd, target_os = "haiku"))] + #[cfg(any(bsd, target_os = "espidf", target_os = "haiku", target_os = "nto"))] sa_len: 0_u8, - #[cfg(any(bsd, target_os = "haiku"))] + #[cfg(any(bsd, target_os = "espidf", target_os = "haiku", target_os = "nto"))] sa_family: 0_u8, - #[cfg(not(any(bsd, target_os = "haiku")))] + #[cfg(not(any(bsd, target_os = "espidf", target_os = "haiku", target_os = "nto")))] sa_family: 0_u16, #[cfg(not(target_os = "haiku"))] sa_data: [0; 14], diff --git a/vendor/rustix/src/backend/libc/net/send_recv.rs b/vendor/rustix/src/backend/libc/net/send_recv.rs index e91017e97..26543a1fd 100644 --- a/vendor/rustix/src/backend/libc/net/send_recv.rs +++ b/vendor/rustix/src/backend/libc/net/send_recv.rs @@ -14,6 +14,8 @@ bitflags! { bsd, solarish, windows, + target_os = "espidf", + target_os = "nto", target_os = "haiku", )))] const CONFIRM = bitcast!(c::MSG_CONFIRM); @@ -31,6 +33,7 @@ bitflags! { solarish, windows, target_os = "haiku", + target_os = "nto", )))] const MORE = bitcast!(c::MSG_MORE); #[cfg(not(any(apple, windows)))] @@ -49,7 +52,7 @@ bitflags! { #[repr(transparent)] #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct RecvFlags: u32 { - #[cfg(not(any(apple, solarish, windows, target_os = "haiku")))] + #[cfg(not(any(apple, solarish, windows, target_os = "espidf", target_os = "haiku", target_os = "nto")))] /// `MSG_CMSG_CLOEXEC` const CMSG_CLOEXEC = bitcast!(c::MSG_CMSG_CLOEXEC); /// `MSG_DONTWAIT` @@ -60,7 +63,9 @@ bitflags! { bsd, solarish, windows, + target_os = "espidf", target_os = "haiku", + target_os = "nto", )))] const ERRQUEUE = bitcast!(c::MSG_ERRQUEUE); /// `MSG_OOB` diff --git a/vendor/rustix/src/backend/libc/net/syscalls.rs b/vendor/rustix/src/backend/libc/net/syscalls.rs index 63067ff38..b4550583c 100644 --- a/vendor/rustix/src/backend/libc/net/syscalls.rs +++ b/vendor/rustix/src/backend/libc/net/syscalls.rs @@ -10,7 +10,7 @@ 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 = "redox", target_os = "wasi")))] +#[cfg(not(any(windows, target_os = "espidf", target_os = "redox", target_os = "wasi")))] use { super::msghdr::{with_noaddr_msghdr, with_recv_msghdr, with_v4_msghdr, with_v6_msghdr}, crate::io::{IoSlice, IoSliceMut}, @@ -256,7 +256,7 @@ pub(crate) fn accept(sockfd: BorrowedFd<'_>) -> io::Result<OwnedFd> { } } -#[cfg(not(any(windows, target_os = "redox", target_os = "wasi")))] +#[cfg(not(any(windows, target_os = "espidf", target_os = "redox", target_os = "wasi")))] pub(crate) fn recvmsg( sockfd: BorrowedFd<'_>, iov: &mut [IoSliceMut<'_>], @@ -288,7 +288,7 @@ pub(crate) fn recvmsg( }) } -#[cfg(not(any(windows, target_os = "redox", target_os = "wasi")))] +#[cfg(not(any(windows, target_os = "espidf", target_os = "redox", target_os = "wasi")))] pub(crate) fn sendmsg( sockfd: BorrowedFd<'_>, iov: &[IoSlice<'_>], @@ -304,7 +304,7 @@ pub(crate) fn sendmsg( }) } -#[cfg(not(any(windows, target_os = "redox", target_os = "wasi")))] +#[cfg(not(any(windows, target_os = "espidf", target_os = "redox", target_os = "wasi")))] pub(crate) fn sendmsg_v4( sockfd: BorrowedFd<'_>, addr: &SocketAddrV4, @@ -321,7 +321,7 @@ pub(crate) fn sendmsg_v4( }) } -#[cfg(not(any(windows, target_os = "redox", target_os = "wasi")))] +#[cfg(not(any(windows, target_os = "espidf", target_os = "redox", target_os = "wasi")))] pub(crate) fn sendmsg_v6( sockfd: BorrowedFd<'_>, addr: &SocketAddrV6, @@ -338,7 +338,7 @@ pub(crate) fn sendmsg_v6( }) } -#[cfg(all(unix, not(target_os = "redox")))] +#[cfg(all(unix, not(any(target_os = "espidf", target_os = "redox"))))] pub(crate) fn sendmsg_unix( sockfd: BorrowedFd<'_>, addr: &SocketAddrUnix, @@ -358,8 +358,10 @@ pub(crate) fn sendmsg_unix( #[cfg(not(any( apple, windows, + target_os = "espidf", target_os = "haiku", target_os = "redox", + target_os = "nto", target_os = "wasi", )))] pub(crate) fn accept_with(sockfd: BorrowedFd<'_>, flags: SocketFlags) -> io::Result<OwnedFd> { @@ -394,7 +396,9 @@ pub(crate) fn acceptfrom(sockfd: BorrowedFd<'_>) -> io::Result<(OwnedFd, Option< #[cfg(not(any( apple, windows, + target_os = "espidf", target_os = "haiku", + target_os = "nto", target_os = "redox", target_os = "wasi", )))] @@ -420,14 +424,26 @@ pub(crate) fn acceptfrom_with( /// Darwin lacks `accept4`, but does have `accept`. We define /// `SocketFlags` to have no flags, so we can discard it here. -#[cfg(any(apple, windows, target_os = "haiku"))] +#[cfg(any( + apple, + windows, + target_os = "espidf", + target_os = "haiku", + target_os = "nto" +))] pub(crate) fn accept_with(sockfd: BorrowedFd<'_>, _flags: SocketFlags) -> io::Result<OwnedFd> { accept(sockfd) } /// Darwin lacks `accept4`, but does have `accept`. We define /// `SocketFlags` to have no flags, so we can discard it here. -#[cfg(any(apple, windows, target_os = "haiku"))] +#[cfg(any( + apple, + windows, + target_os = "espidf", + target_os = "haiku", + target_os = "nto" +))] pub(crate) fn acceptfrom_with( sockfd: BorrowedFd<'_>, _flags: SocketFlags, @@ -893,9 +909,21 @@ pub(crate) mod sockopt { multiaddr: &Ipv6Addr, interface: u32, ) -> io::Result<()> { - #[cfg(not(any(bsd, solarish, target_os = "haiku", target_os = "l4re")))] + #[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"))] + #[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); @@ -918,9 +946,21 @@ pub(crate) mod sockopt { multiaddr: &Ipv6Addr, interface: u32, ) -> io::Result<()> { - #[cfg(not(any(bsd, solarish, target_os = "haiku", target_os = "l4re")))] + #[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"))] + #[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); diff --git a/vendor/rustix/src/backend/libc/net/write_sockaddr.rs b/vendor/rustix/src/backend/libc/net/write_sockaddr.rs index efb5a4e14..46f0ef40a 100644 --- a/vendor/rustix/src/backend/libc/net/write_sockaddr.rs +++ b/vendor/rustix/src/backend/libc/net/write_sockaddr.rs @@ -23,7 +23,7 @@ pub(crate) unsafe fn write_sockaddr( pub(crate) unsafe fn encode_sockaddr_v4(v4: &SocketAddrV4) -> c::sockaddr_in { c::sockaddr_in { - #[cfg(any(bsd, target_os = "haiku"))] + #[cfg(any(bsd, target_os = "espidf", target_os = "haiku", target_os = "nto"))] sin_len: size_of::<c::sockaddr_in>() as _, sin_family: c::AF_INET as _, sin_port: u16::to_be(v4.port()), @@ -42,7 +42,7 @@ unsafe fn write_sockaddr_v4(v4: &SocketAddrV4, storage: *mut SocketAddrStorage) } pub(crate) unsafe fn encode_sockaddr_v6(v6: &SocketAddrV6) -> c::sockaddr_in6 { - #[cfg(any(bsd, target_os = "haiku"))] + #[cfg(any(bsd, target_os = "espidf", target_os = "haiku", target_os = "nto"))] { sockaddr_in6_new( size_of::<c::sockaddr_in6>() as _, @@ -53,7 +53,7 @@ pub(crate) unsafe fn encode_sockaddr_v6(v6: &SocketAddrV6) -> c::sockaddr_in6 { v6.scope_id(), ) } - #[cfg(not(any(bsd, target_os = "haiku")))] + #[cfg(not(any(bsd, target_os = "espidf", target_os = "haiku", target_os = "nto")))] { sockaddr_in6_new( c::AF_INET6 as _, diff --git a/vendor/rustix/src/backend/libc/pipe/syscalls.rs b/vendor/rustix/src/backend/libc/pipe/syscalls.rs index c5ded9174..24262cc9a 100644 --- a/vendor/rustix/src/backend/libc/pipe/syscalls.rs +++ b/vendor/rustix/src/backend/libc/pipe/syscalls.rs @@ -2,7 +2,14 @@ use crate::backend::c; use crate::backend::conv::ret; use crate::fd::OwnedFd; use crate::io; -#[cfg(not(any(apple, target_os = "aix", target_os = "haiku", target_os = "wasi")))] +#[cfg(not(any( + apple, + target_os = "aix", + target_os = "espidf", + target_os = "haiku", + target_os = "nto", + target_os = "wasi" +)))] use crate::pipe::PipeFlags; use core::mem::MaybeUninit; #[cfg(linux_kernel)] @@ -11,7 +18,7 @@ use { crate::backend::MAX_IOV, crate::fd::BorrowedFd, crate::pipe::{IoSliceRaw, SpliceFlags}, - crate::utils::optional_as_mut_ptr, + crate::utils::option_as_mut_ptr, core::cmp::min, }; @@ -25,7 +32,14 @@ pub(crate) fn pipe() -> io::Result<(OwnedFd, OwnedFd)> { } } -#[cfg(not(any(apple, target_os = "aix", target_os = "haiku", target_os = "wasi")))] +#[cfg(not(any( + apple, + target_os = "aix", + target_os = "espidf", + target_os = "haiku", + target_os = "nto", + target_os = "wasi" +)))] pub(crate) fn pipe_with(flags: PipeFlags) -> io::Result<(OwnedFd, OwnedFd)> { unsafe { let mut result = MaybeUninit::<[OwnedFd; 2]>::uninit(); @@ -48,8 +62,8 @@ pub fn splice( len: usize, flags: SpliceFlags, ) -> io::Result<usize> { - let off_in = optional_as_mut_ptr(off_in).cast(); - let off_out = optional_as_mut_ptr(off_out).cast(); + let off_in = option_as_mut_ptr(off_in).cast(); + let off_out = option_as_mut_ptr(off_out).cast(); unsafe { ret_usize(c::splice( diff --git a/vendor/rustix/src/backend/libc/pipe/types.rs b/vendor/rustix/src/backend/libc/pipe/types.rs index f48d8041b..3fa0464e0 100644 --- a/vendor/rustix/src/backend/libc/pipe/types.rs +++ b/vendor/rustix/src/backend/libc/pipe/types.rs @@ -16,7 +16,9 @@ bitflags! { /// `O_DIRECT` #[cfg(not(any( solarish, + target_os = "espidf", target_os = "haiku", + target_os = "nto", target_os = "openbsd", target_os = "redox", )))] @@ -85,9 +87,8 @@ impl<'a> IoSliceRaw<'a> { #[cfg(not(any(apple, target_os = "wasi")))] #[test] fn test_types() { - use core::mem::size_of; - assert_eq!(size_of::<PipeFlags>(), size_of::<c::c_int>()); + assert_eq_size!(PipeFlags, c::c_int); #[cfg(linux_kernel)] - assert_eq!(size_of::<SpliceFlags>(), size_of::<c::c_int>()); + assert_eq_size!(SpliceFlags, c::c_int); } diff --git a/vendor/rustix/src/backend/libc/process/mod.rs b/vendor/rustix/src/backend/libc/process/mod.rs index 24f43d443..4d9a9f0a0 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(target_os = "wasi"))] +#[cfg(not(any(target_os = "espidf", 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 0aa29b0b1..a84385cf1 100644 --- a/vendor/rustix/src/backend/libc/process/syscalls.rs +++ b/vendor/rustix/src/backend/libc/process/syscalls.rs @@ -3,14 +3,21 @@ #[cfg(any(linux_kernel, target_os = "dragonfly", target_os = "fuchsia"))] use super::types::RawCpuSet; use crate::backend::c; -#[cfg(not(any(target_os = "fuchsia", target_os = "redox", target_os = "wasi")))] +#[cfg(feature = "fs")] +use crate::backend::conv::c_str; +#[cfg(all(feature = "fs", not(target_os = "wasi")))] +use crate::backend::conv::ret_discarded_char_ptr; +#[cfg(not(any( + target_os = "espidf", + target_os = "fuchsia", + target_os = "redox", + target_os = "wasi" +)))] use crate::backend::conv::ret_infallible; #[cfg(linux_kernel)] use crate::backend::conv::ret_u32; #[cfg(not(target_os = "wasi"))] use crate::backend::conv::{borrowed_fd, ret_pid_t, ret_usize}; -#[cfg(feature = "fs")] -use crate::backend::conv::{c_str, ret_discarded_char_ptr}; use crate::backend::conv::{ret, ret_c_int}; #[cfg(not(target_os = "wasi"))] use crate::fd::BorrowedFd; @@ -21,15 +28,27 @@ use crate::ffi::CStr; #[cfg(feature = "fs")] use crate::fs::Mode; use crate::io; -#[cfg(not(any(target_os = "fuchsia", target_os = "wasi")))] +#[cfg(not(any(target_os = "espidf", target_os = "fuchsia", target_os = "wasi")))] use crate::process::Uid; #[cfg(linux_kernel)] use crate::process::{Cpuid, MembarrierCommand, MembarrierQuery}; #[cfg(not(target_os = "wasi"))] -use crate::process::{Gid, Pid, RawPid, Signal, WaitOptions, WaitStatus}; -#[cfg(not(any(target_os = "fuchsia", target_os = "redox", target_os = "wasi")))] +use crate::process::{Gid, Pid}; +#[cfg(not(any(target_os = "espidf", target_os = "wasi")))] +use crate::process::{RawPid, Signal, WaitOptions, WaitStatus}; +#[cfg(not(any( + target_os = "espidf", + target_os = "fuchsia", + target_os = "redox", + target_os = "wasi" +)))] use crate::process::{Resource, Rlimit}; -#[cfg(not(any(target_os = "redox", target_os = "openbsd", target_os = "wasi")))] +#[cfg(not(any( + target_os = "espidf", + target_os = "redox", + target_os = "openbsd", + target_os = "wasi" +)))] use crate::process::{WaitId, WaitidOptions, WaitidStatus}; use core::mem::MaybeUninit; #[cfg(target_os = "linux")] @@ -43,7 +62,7 @@ pub(crate) fn chdir(path: &CStr) -> io::Result<()> { unsafe { ret(c::chdir(c_str(path))) } } -#[cfg(not(any(target_os = "wasi", target_os = "fuchsia")))] +#[cfg(not(any(target_os = "fuchsia", target_os = "wasi")))] pub(crate) fn fchdir(dirfd: BorrowedFd<'_>) -> io::Result<()> { unsafe { ret(c::fchdir(borrowed_fd(dirfd))) } } @@ -196,7 +215,7 @@ pub(crate) fn nice(inc: i32) -> io::Result<i32> { } } -#[cfg(not(any(target_os = "fuchsia", target_os = "wasi")))] +#[cfg(not(any(target_os = "espidf", target_os = "fuchsia", target_os = "wasi")))] #[inline] pub(crate) fn getpriority_user(uid: Uid) -> io::Result<i32> { libc_errno::set_errno(libc_errno::Errno(0)); @@ -208,7 +227,7 @@ pub(crate) fn getpriority_user(uid: Uid) -> io::Result<i32> { } } -#[cfg(not(any(target_os = "fuchsia", target_os = "wasi")))] +#[cfg(not(any(target_os = "espidf", target_os = "fuchsia", target_os = "wasi")))] #[inline] pub(crate) fn getpriority_pgrp(pgid: Option<Pid>) -> io::Result<i32> { libc_errno::set_errno(libc_errno::Errno(0)); @@ -220,7 +239,7 @@ pub(crate) fn getpriority_pgrp(pgid: Option<Pid>) -> io::Result<i32> { } } -#[cfg(not(any(target_os = "fuchsia", target_os = "wasi")))] +#[cfg(not(any(target_os = "espidf", target_os = "fuchsia", target_os = "wasi")))] #[inline] pub(crate) fn getpriority_process(pid: Option<Pid>) -> io::Result<i32> { libc_errno::set_errno(libc_errno::Errno(0)); @@ -232,13 +251,13 @@ pub(crate) fn getpriority_process(pid: Option<Pid>) -> io::Result<i32> { } } -#[cfg(not(any(target_os = "fuchsia", target_os = "wasi")))] +#[cfg(not(any(target_os = "espidf", target_os = "fuchsia", 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 = "fuchsia", target_os = "wasi")))] +#[cfg(not(any(target_os = "espidf", target_os = "fuchsia", target_os = "wasi")))] #[inline] pub(crate) fn setpriority_pgrp(pgid: Option<Pid>, priority: i32) -> io::Result<()> { unsafe { @@ -250,7 +269,7 @@ pub(crate) fn setpriority_pgrp(pgid: Option<Pid>, priority: i32) -> io::Result<( } } -#[cfg(not(any(target_os = "fuchsia", target_os = "wasi")))] +#[cfg(not(any(target_os = "espidf", target_os = "fuchsia", target_os = "wasi")))] #[inline] pub(crate) fn setpriority_process(pid: Option<Pid>, priority: i32) -> io::Result<()> { unsafe { @@ -262,7 +281,12 @@ pub(crate) fn setpriority_process(pid: Option<Pid>, priority: i32) -> io::Result } } -#[cfg(not(any(target_os = "fuchsia", target_os = "redox", target_os = "wasi")))] +#[cfg(not(any( + target_os = "espidf", + target_os = "fuchsia", + target_os = "redox", + target_os = "wasi" +)))] #[inline] pub(crate) fn getrlimit(limit: Resource) -> Rlimit { let mut result = MaybeUninit::<c::rlimit>::uninit(); @@ -272,7 +296,12 @@ pub(crate) fn getrlimit(limit: Resource) -> Rlimit { } } -#[cfg(not(any(target_os = "fuchsia", target_os = "redox", target_os = "wasi")))] +#[cfg(not(any( + target_os = "espidf", + target_os = "fuchsia", + target_os = "redox", + target_os = "wasi" +)))] #[inline] pub(crate) fn setrlimit(limit: Resource, new: Rlimit) -> io::Result<()> { let lim = rlimit_to_libc(new)?; @@ -296,7 +325,12 @@ pub(crate) fn prlimit(pid: Option<Pid>, limit: Resource, new: Rlimit) -> io::Res } /// Convert a Rust [`Rlimit`] to a C `c::rlimit`. -#[cfg(not(any(target_os = "fuchsia", target_os = "redox", target_os = "wasi")))] +#[cfg(not(any( + target_os = "espidf", + target_os = "fuchsia", + target_os = "redox", + target_os = "wasi" +)))] fn rlimit_from_libc(lim: c::rlimit) -> Rlimit { let current = if lim.rlim_cur == c::RLIM_INFINITY { None @@ -312,7 +346,12 @@ fn rlimit_from_libc(lim: c::rlimit) -> Rlimit { } /// Convert a C `c::rlimit` to a Rust `Rlimit`. -#[cfg(not(any(target_os = "fuchsia", target_os = "redox", target_os = "wasi")))] +#[cfg(not(any( + target_os = "espidf", + target_os = "fuchsia", + target_os = "redox", + target_os = "wasi" +)))] fn rlimit_to_libc(lim: Rlimit) -> io::Result<c::rlimit> { let Rlimit { current, maximum } = lim; let rlim_cur = match current { @@ -326,13 +365,13 @@ fn rlimit_to_libc(lim: Rlimit) -> io::Result<c::rlimit> { Ok(c::rlimit { rlim_cur, rlim_max }) } -#[cfg(not(target_os = "wasi"))] +#[cfg(not(any(target_os = "espidf", target_os = "wasi")))] #[inline] pub(crate) fn wait(waitopts: WaitOptions) -> io::Result<Option<(Pid, WaitStatus)>> { _waitpid(!0, waitopts) } -#[cfg(not(target_os = "wasi"))] +#[cfg(not(any(target_os = "espidf", target_os = "wasi")))] #[inline] pub(crate) fn waitpid( pid: Option<Pid>, @@ -341,7 +380,7 @@ pub(crate) fn waitpid( _waitpid(Pid::as_raw(pid), waitopts) } -#[cfg(not(target_os = "wasi"))] +#[cfg(not(any(target_os = "espidf", target_os = "wasi")))] #[inline] pub(crate) fn _waitpid( pid: RawPid, @@ -354,7 +393,12 @@ pub(crate) fn _waitpid( } } -#[cfg(not(any(target_os = "wasi", target_os = "redox", target_os = "openbsd")))] +#[cfg(not(any( + target_os = "espidf", + target_os = "redox", + target_os = "openbsd", + target_os = "wasi" +)))] #[inline] pub(crate) fn waitid(id: WaitId<'_>, options: WaitidOptions) -> io::Result<Option<WaitidStatus>> { // Get the id to wait on. @@ -368,7 +412,12 @@ pub(crate) fn waitid(id: WaitId<'_>, options: WaitidOptions) -> io::Result<Optio } } -#[cfg(not(any(target_os = "wasi", target_os = "redox", target_os = "openbsd")))] +#[cfg(not(any( + target_os = "espidf", + target_os = "redox", + target_os = "openbsd", + target_os = "wasi" +)))] #[inline] fn _waitid_all(options: WaitidOptions) -> io::Result<Option<WaitidStatus>> { // `waitid` can return successfully without initializing the struct (no @@ -386,7 +435,12 @@ fn _waitid_all(options: WaitidOptions) -> io::Result<Option<WaitidStatus>> { Ok(unsafe { cvt_waitid_status(status) }) } -#[cfg(not(any(target_os = "wasi", target_os = "redox", target_os = "openbsd")))] +#[cfg(not(any( + target_os = "espidf", + target_os = "redox", + target_os = "openbsd", + target_os = "wasi" +)))] #[inline] fn _waitid_pid(pid: Pid, options: WaitidOptions) -> io::Result<Option<WaitidStatus>> { // `waitid` can return successfully without initializing the struct (no @@ -428,7 +482,12 @@ fn _waitid_pidfd(fd: BorrowedFd<'_>, options: WaitidOptions) -> io::Result<Optio /// /// The caller must ensure that `status` is initialized and that `waitid` /// returned successfully. -#[cfg(not(any(target_os = "wasi", target_os = "redox", target_os = "openbsd")))] +#[cfg(not(any( + target_os = "espidf", + target_os = "openbsd", + target_os = "redox", + target_os = "wasi" +)))] #[inline] unsafe fn cvt_waitid_status(status: MaybeUninit<c::siginfo_t>) -> Option<WaitidStatus> { let status = status.assume_init(); @@ -464,13 +523,13 @@ pub(crate) fn setsid() -> io::Result<Pid> { } } -#[cfg(not(target_os = "wasi"))] +#[cfg(not(any(target_os = "espidf", target_os = "wasi")))] #[inline] pub(crate) fn kill_process(pid: Pid, sig: Signal) -> io::Result<()> { unsafe { ret(c::kill(pid.as_raw_nonzero().get(), sig as i32)) } } -#[cfg(not(target_os = "wasi"))] +#[cfg(not(any(target_os = "espidf", target_os = "wasi")))] #[inline] pub(crate) fn kill_process_group(pid: Pid, sig: Signal) -> io::Result<()> { unsafe { @@ -481,25 +540,24 @@ pub(crate) fn kill_process_group(pid: Pid, sig: Signal) -> io::Result<()> { } } -#[cfg(not(target_os = "wasi"))] +#[cfg(not(any(target_os = "espidf", target_os = "wasi")))] #[inline] pub(crate) fn kill_current_process_group(sig: Signal) -> io::Result<()> { unsafe { ret(c::kill(0, sig as i32)) } } -#[cfg(not(target_os = "wasi"))] -#[inline] +#[cfg(not(any(target_os = "espidf", target_os = "wasi")))] pub(crate) fn test_kill_process(pid: Pid) -> io::Result<()> { unsafe { ret(c::kill(pid.as_raw_nonzero().get(), 0)) } } -#[cfg(not(target_os = "wasi"))] +#[cfg(not(any(target_os = "espidf", target_os = "wasi")))] #[inline] pub(crate) fn test_kill_process_group(pid: Pid) -> io::Result<()> { unsafe { ret(c::kill(pid.as_raw_nonzero().get().wrapping_neg(), 0)) } } -#[cfg(not(target_os = "wasi"))] +#[cfg(not(any(target_os = "espidf", target_os = "wasi")))] #[inline] pub(crate) fn test_kill_current_process_group() -> io::Result<()> { unsafe { ret(c::kill(0, 0)) } @@ -561,7 +619,12 @@ pub(crate) fn getgroups(buf: &mut [Gid]) -> io::Result<usize> { unsafe { ret_usize(c::getgroups(len, buf.as_mut_ptr().cast()) as isize) } } -#[cfg(not(any(target_os = "redox", target_os = "wasi")))] +#[cfg(not(any( + target_os = "aix", + target_os = "espidf", + target_os = "redox", + target_os = "wasi" +)))] #[inline] pub(crate) fn ioctl_tiocsctty(fd: BorrowedFd<'_>) -> io::Result<()> { unsafe { ret(c::ioctl(borrowed_fd(fd), c::TIOCSCTTY as _, &0_u32)) } diff --git a/vendor/rustix/src/backend/libc/process/types.rs b/vendor/rustix/src/backend/libc/process/types.rs index 980c0effe..9c543acd0 100644 --- a/vendor/rustix/src/backend/libc/process/types.rs +++ b/vendor/rustix/src/backend/libc/process/types.rs @@ -40,9 +40,15 @@ pub enum MembarrierCommand { /// [`getrlimit`]: crate::process::getrlimit /// [`setrlimit`]: crate::process::setrlimit /// [`prlimit`]: crate::process::prlimit -#[cfg(not(any(target_os = "fuchsia", target_os = "redox", target_os = "wasi")))] +#[cfg(not(any( + target_os = "espidf", + target_os = "fuchsia", + target_os = "redox", + target_os = "wasi" +)))] #[derive(Copy, Clone, Debug, Eq, PartialEq)] -#[repr(u32)] +#[cfg_attr(not(target_os = "l4re"), repr(u32))] +#[cfg_attr(target_os = "l4re", repr(u64))] pub enum Resource { /// `RLIMIT_CPU` Cpu = bitcast!(c::RLIMIT_CPU), @@ -56,7 +62,8 @@ pub enum Resource { #[cfg(not(target_os = "haiku"))] Core = bitcast!(c::RLIMIT_CORE), /// `RLIMIT_RSS` - #[cfg(not(any(apple, solarish, target_os = "haiku")))] + // "nto" has `RLIMIT_RSS`, but it has the same value as `RLIMIT_AS`. + #[cfg(not(any(apple, solarish, target_os = "nto", target_os = "haiku")))] Rss = bitcast!(c::RLIMIT_RSS), /// `RLIMIT_NPROC` #[cfg(not(any(solarish, target_os = "haiku")))] @@ -70,19 +77,49 @@ pub enum Resource { #[cfg(not(target_os = "openbsd"))] As = bitcast!(c::RLIMIT_AS), /// `RLIMIT_LOCKS` - #[cfg(not(any(bsd, solarish, target_os = "aix", target_os = "haiku")))] + #[cfg(not(any( + bsd, + solarish, + target_os = "aix", + target_os = "haiku", + target_os = "nto" + )))] Locks = bitcast!(c::RLIMIT_LOCKS), /// `RLIMIT_SIGPENDING` - #[cfg(not(any(bsd, solarish, target_os = "aix", target_os = "haiku")))] + #[cfg(not(any( + bsd, + solarish, + target_os = "aix", + target_os = "haiku", + target_os = "nto" + )))] Sigpending = bitcast!(c::RLIMIT_SIGPENDING), /// `RLIMIT_MSGQUEUE` - #[cfg(not(any(bsd, solarish, target_os = "aix", target_os = "haiku")))] + #[cfg(not(any( + bsd, + solarish, + target_os = "aix", + target_os = "haiku", + target_os = "nto" + )))] Msgqueue = bitcast!(c::RLIMIT_MSGQUEUE), /// `RLIMIT_NICE` - #[cfg(not(any(bsd, solarish, target_os = "aix", target_os = "haiku")))] + #[cfg(not(any( + bsd, + solarish, + target_os = "aix", + target_os = "haiku", + target_os = "nto" + )))] Nice = bitcast!(c::RLIMIT_NICE), /// `RLIMIT_RTPRIO` - #[cfg(not(any(bsd, solarish, target_os = "aix", target_os = "haiku")))] + #[cfg(not(any( + bsd, + solarish, + target_os = "aix", + target_os = "haiku", + target_os = "nto" + )))] Rtprio = bitcast!(c::RLIMIT_RTPRIO), /// `RLIMIT_RTTIME` #[cfg(not(any( @@ -92,6 +129,7 @@ pub enum Resource { target_os = "android", target_os = "emscripten", target_os = "haiku", + target_os = "nto", )))] Rttime = bitcast!(c::RLIMIT_RTTIME), } @@ -105,7 +143,7 @@ impl Resource { pub const EXIT_SUCCESS: c::c_int = c::EXIT_SUCCESS; pub const EXIT_FAILURE: c::c_int = c::EXIT_FAILURE; -#[cfg(not(target_os = "wasi"))] +#[cfg(not(any(target_os = "espidf", target_os = "wasi")))] pub const EXIT_SIGNALED_SIGABRT: c::c_int = 128 + c::SIGABRT; /// A CPU identifier as a raw integer. diff --git a/vendor/rustix/src/backend/libc/pty/syscalls.rs b/vendor/rustix/src/backend/libc/pty/syscalls.rs index 178201ead..6688ddb26 100644 --- a/vendor/rustix/src/backend/libc/pty/syscalls.rs +++ b/vendor/rustix/src/backend/libc/pty/syscalls.rs @@ -31,9 +31,26 @@ pub(crate) fn ptsname(fd: BorrowedFd, mut buffer: Vec<u8>) -> io::Result<CString loop { // On platforms with `ptsname_r`, use it. - #[cfg(any(target_os = "freebsd", linux_like, target_os = "fuchsia"))] + #[cfg(any(linux_like, target_os = "fuchsia"))] let r = unsafe { c::ptsname_r(borrowed_fd(fd), buffer.as_mut_ptr().cast(), buffer.len()) }; + // FreeBSD 12 doesn't have `ptsname_r`. + #[cfg(target_os = "freebsd")] + let r = unsafe { + weak! { + fn ptsname_r( + c::c_int, + *mut c::c_char, + c::size_t + ) -> c::c_int + } + if let Some(func) = ptsname_r.get() { + func(borrowed_fd(fd), buffer.as_mut_ptr().cast(), buffer.len()) + } else { + libc::ENOSYS + } + }; + // MacOS 10.13.4 has `ptsname_r`; use it if we have it, otherwise fall // back to calling the underlying ioctl directly. #[cfg(apple)] @@ -45,7 +62,7 @@ pub(crate) fn ptsname(fd: BorrowedFd, mut buffer: Vec<u8>) -> io::Result<CString } else { // The size declared in the `TIOCPTYGNAME` macro in sys/ttycom.h is 128. let mut name: [u8; 128] = [0_u8; 128]; - match c::ioctl(borrowed_fd(fd), c::TIOCPTYGNAME as u64, &mut name) { + match c::ioctl(borrowed_fd(fd), c::TIOCPTYGNAME as _, &mut name) { 0 => { let len = CStr::from_ptr(name.as_ptr().cast()).to_bytes().len(); std::ptr::copy_nonoverlapping(name.as_ptr(), buffer.as_mut_ptr(), len + 1); diff --git a/vendor/rustix/src/backend/libc/system/syscalls.rs b/vendor/rustix/src/backend/libc/system/syscalls.rs index a731e9302..27efd2653 100644 --- a/vendor/rustix/src/backend/libc/system/syscalls.rs +++ b/vendor/rustix/src/backend/libc/system/syscalls.rs @@ -7,7 +7,12 @@ use crate::backend::conv::ret_infallible; #[cfg(linux_kernel)] use crate::system::Sysinfo; use core::mem::MaybeUninit; -#[cfg(not(any(target_os = "emscripten", target_os = "redox", target_os = "wasi")))] +#[cfg(not(any( + target_os = "emscripten", + target_os = "espidf", + target_os = "redox", + target_os = "wasi" +)))] use {crate::backend::conv::ret, crate::io}; #[cfg(not(target_os = "wasi"))] @@ -15,7 +20,15 @@ use {crate::backend::conv::ret, crate::io}; pub(crate) fn uname() -> RawUname { let mut uname = MaybeUninit::<RawUname>::uninit(); unsafe { - ret_infallible(c::uname(uname.as_mut_ptr())); + let r = c::uname(uname.as_mut_ptr()); + + // On POSIX, `uname` is documented to return non-negative on success + // instead of the usual 0, though some specific systems do document + // that they always use zero allowing us to skip this check. + #[cfg(not(any(apple, freebsdlike, linux_like, target_os = "netbsd")))] + let r = core::cmp::min(r, 0); + + ret_infallible(r); uname.assume_init() } } @@ -29,7 +42,12 @@ pub(crate) fn sysinfo() -> Sysinfo { } } -#[cfg(not(any(target_os = "emscripten", target_os = "redox", target_os = "wasi")))] +#[cfg(not(any( + target_os = "emscripten", + target_os = "espidf", + target_os = "redox", + target_os = "wasi" +)))] pub(crate) fn sethostname(name: &[u8]) -> io::Result<()> { unsafe { ret(c::sethostname( diff --git a/vendor/rustix/src/backend/libc/termios/syscalls.rs b/vendor/rustix/src/backend/libc/termios/syscalls.rs index d4182f4fe..ea284927f 100644 --- a/vendor/rustix/src/backend/libc/termios/syscalls.rs +++ b/vendor/rustix/src/backend/libc/termios/syscalls.rs @@ -5,21 +5,30 @@ //! See the `rustix::backend::syscalls` module documentation for details. use crate::backend::c; -use crate::backend::conv::{borrowed_fd, ret, ret_pid_t}; +#[cfg(not(target_os = "wasi"))] +use crate::backend::conv::ret_pid_t; +use crate::backend::conv::{borrowed_fd, ret}; use crate::fd::BorrowedFd; #[cfg(feature = "procfs")] #[cfg(not(any(target_os = "fuchsia", target_os = "wasi")))] use crate::ffi::CStr; +#[cfg(any( + not(target_os = "espidf"), + all( + feature = "procfs", + not(any(target_os = "fuchsia", target_os = "wasi")) + ) +))] use core::mem::MaybeUninit; #[cfg(not(target_os = "wasi"))] +use {crate::io, crate::pid::Pid}; +#[cfg(not(any(target_os = "espidf", target_os = "wasi")))] use { - crate::io, - crate::pid::Pid, crate::termios::{Action, OptionalActions, QueueSelector, Termios, Winsize}, crate::utils::as_mut_ptr, }; -#[cfg(not(target_os = "wasi"))] +#[cfg(not(any(target_os = "espidf", target_os = "wasi")))] pub(crate) fn tcgetattr(fd: BorrowedFd<'_>) -> io::Result<Termios> { // If we have `TCGETS2`, use it, so that we fill in the `c_ispeed` and // `c_ospeed` fields. @@ -32,7 +41,7 @@ pub(crate) fn tcgetattr(fd: BorrowedFd<'_>) -> io::Result<Termios> { ret(c::ioctl( borrowed_fd(fd), - c::TCGETS2.into(), + c::TCGETS2 as _, termios2.as_mut_ptr(), ))?; @@ -58,6 +67,8 @@ pub(crate) fn tcgetattr(fd: BorrowedFd<'_>) -> io::Result<Termios> { unsafe { let mut result = MaybeUninit::<Termios>::uninit(); + // `result` is a `Termios` which starts with the same layout as + // `libc::termios`, so we can cast the pointer. ret(c::tcgetattr(borrowed_fd(fd), result.as_mut_ptr().cast()))?; Ok(result.assume_init()) @@ -77,7 +88,7 @@ pub(crate) fn tcsetpgrp(fd: BorrowedFd<'_>, pid: Pid) -> io::Result<()> { unsafe { ret(c::tcsetpgrp(borrowed_fd(fd), pid.as_raw_nonzero().get())) } } -#[cfg(not(target_os = "wasi"))] +#[cfg(not(any(target_os = "espidf", target_os = "wasi")))] pub(crate) fn tcsetattr( fd: BorrowedFd, optional_actions: OptionalActions, @@ -104,7 +115,12 @@ pub(crate) fn tcsetattr( // 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", target_arch = "mips64")) { + + if cfg!(any( + target_arch = "mips", + target_arch = "mips32r6", + target_arch = "mips64", + target_arch = "mips64r6" + )) { optional_actions as u32 - TCSETS } else { optional_actions as u32 @@ -151,17 +167,17 @@ pub(crate) fn tcsendbreak(fd: BorrowedFd) -> io::Result<()> { unsafe { ret(c::tcsendbreak(borrowed_fd(fd), 0)) } } -#[cfg(not(target_os = "wasi"))] +#[cfg(not(any(target_os = "espidf", target_os = "wasi")))] pub(crate) fn tcdrain(fd: BorrowedFd) -> io::Result<()> { unsafe { ret(c::tcdrain(borrowed_fd(fd))) } } -#[cfg(not(target_os = "wasi"))] +#[cfg(not(any(target_os = "espidf", target_os = "wasi")))] pub(crate) fn tcflush(fd: BorrowedFd, queue_selector: QueueSelector) -> io::Result<()> { unsafe { ret(c::tcflush(borrowed_fd(fd), queue_selector as _)) } } -#[cfg(not(target_os = "wasi"))] +#[cfg(not(any(target_os = "espidf", target_os = "wasi")))] pub(crate) fn tcflow(fd: BorrowedFd, action: Action) -> io::Result<()> { unsafe { ret(c::tcflow(borrowed_fd(fd), action as _)) } } @@ -174,12 +190,12 @@ pub(crate) fn tcgetsid(fd: BorrowedFd) -> io::Result<Pid> { } } -#[cfg(not(target_os = "wasi"))] +#[cfg(not(any(target_os = "espidf", target_os = "wasi")))] pub(crate) fn tcsetwinsize(fd: BorrowedFd, winsize: Winsize) -> io::Result<()> { unsafe { ret(c::ioctl(borrowed_fd(fd), c::TIOCSWINSZ, &winsize)) } } -#[cfg(not(target_os = "wasi"))] +#[cfg(not(any(target_os = "espidf", target_os = "wasi")))] pub(crate) fn tcgetwinsize(fd: BorrowedFd) -> io::Result<Winsize> { unsafe { let mut buf = MaybeUninit::<Winsize>::uninit(); @@ -192,17 +208,27 @@ pub(crate) fn tcgetwinsize(fd: BorrowedFd) -> io::Result<Winsize> { } } -#[cfg(not(any(target_os = "haiku", target_os = "redox", target_os = "wasi")))] +#[cfg(not(any( + target_os = "espidf", + target_os = "haiku", + target_os = "redox", + target_os = "wasi" +)))] pub(crate) fn ioctl_tiocexcl(fd: BorrowedFd) -> io::Result<()> { unsafe { ret(c::ioctl(borrowed_fd(fd), c::TIOCEXCL as _)) } } -#[cfg(not(any(target_os = "haiku", target_os = "redox", target_os = "wasi")))] +#[cfg(not(any( + target_os = "espidf", + target_os = "haiku", + target_os = "redox", + target_os = "wasi" +)))] pub(crate) fn ioctl_tiocnxcl(fd: BorrowedFd) -> io::Result<()> { unsafe { ret(c::ioctl(borrowed_fd(fd), c::TIOCNXCL as _)) } } -#[cfg(not(target_os = "wasi"))] +#[cfg(not(any(target_os = "espidf", target_os = "nto", target_os = "wasi")))] #[inline] pub(crate) fn set_speed(termios: &mut Termios, arbitrary_speed: u32) -> io::Result<()> { #[cfg(bsd)] @@ -244,7 +270,7 @@ pub(crate) fn set_speed(termios: &mut Termios, arbitrary_speed: u32) -> io::Resu } } -#[cfg(not(target_os = "wasi"))] +#[cfg(not(any(target_os = "espidf", target_os = "wasi")))] #[inline] pub(crate) fn set_output_speed(termios: &mut Termios, arbitrary_speed: u32) -> io::Result<()> { #[cfg(bsd)] @@ -284,7 +310,7 @@ pub(crate) fn set_output_speed(termios: &mut Termios, arbitrary_speed: u32) -> i } } -#[cfg(not(target_os = "wasi"))] +#[cfg(not(any(target_os = "espidf", target_os = "wasi")))] #[inline] pub(crate) fn set_input_speed(termios: &mut Termios, arbitrary_speed: u32) -> io::Result<()> { #[cfg(bsd)] @@ -324,7 +350,7 @@ pub(crate) fn set_input_speed(termios: &mut Termios, arbitrary_speed: u32) -> io } } -#[cfg(not(target_os = "wasi"))] +#[cfg(not(any(target_os = "espidf", target_os = "nto", target_os = "wasi")))] #[inline] pub(crate) fn cfmakeraw(termios: &mut Termios) { unsafe { c::cfmakeraw(as_mut_ptr(termios).cast()) } diff --git a/vendor/rustix/src/backend/libc/thread/syscalls.rs b/vendor/rustix/src/backend/libc/thread/syscalls.rs index 6066fd0d4..5260c39f4 100644 --- a/vendor/rustix/src/backend/libc/thread/syscalls.rs +++ b/vendor/rustix/src/backend/libc/thread/syscalls.rs @@ -5,10 +5,7 @@ use crate::backend::conv::ret; use crate::io; #[cfg(not(target_os = "redox"))] use crate::thread::{NanosleepRelativeResult, Timespec}; -#[cfg(all( - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", -))] +#[cfg(all(target_env = "gnu", fix_y2038))] use crate::timespec::LibcTimespec; use core::mem::MaybeUninit; #[cfg(linux_kernel)] @@ -22,6 +19,7 @@ use { apple, freebsdlike, target_os = "emscripten", + target_os = "espidf", target_os = "haiku", target_os = "openbsd", target_os = "redox", @@ -29,21 +27,16 @@ use { )))] use {crate::thread::ClockId, core::ptr::null_mut}; -#[cfg(all( - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", -))] +#[cfg(all(target_env = "gnu", fix_y2038))] weak!(fn __clock_nanosleep_time64(c::clockid_t, c::c_int, *const LibcTimespec, *mut LibcTimespec) -> c::c_int); -#[cfg(all( - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", -))] +#[cfg(all(target_env = "gnu", fix_y2038))] weak!(fn __nanosleep64(*const LibcTimespec, *mut LibcTimespec) -> c::c_int); #[cfg(not(any( apple, target_os = "dragonfly", target_os = "emscripten", + target_os = "espidf", target_os = "freebsd", // FreeBSD 12 has clock_nanosleep, but libc targets FreeBSD 11. target_os = "haiku", target_os = "openbsd", @@ -52,41 +45,38 @@ weak!(fn __nanosleep64(*const LibcTimespec, *mut LibcTimespec) -> c::c_int); )))] #[inline] pub(crate) fn clock_nanosleep_relative(id: ClockId, request: &Timespec) -> NanosleepRelativeResult { - let flags = 0; - - // 32-bit gnu version: libc has `clock_nanosleep` but it is not y2038 safe - // by default. - #[cfg(all( - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", - ))] - unsafe { - let mut remain = MaybeUninit::<LibcTimespec>::uninit(); - + // Old 32-bit version: libc has `clock_nanosleep` but it is not y2038 safe + // by default. But there may be a `__clock_nanosleep_time64` we can use. + #[cfg(fix_y2038)] + { + #[cfg(target_env = "gnu")] if let Some(libc_clock_nanosleep) = __clock_nanosleep_time64.get() { - match libc_clock_nanosleep( - id as c::clockid_t, - flags, - &request.clone().into(), - remain.as_mut_ptr(), - ) { - 0 => NanosleepRelativeResult::Ok, - err if err == io::Errno::INTR.0 => { - NanosleepRelativeResult::Interrupted(remain.assume_init().into()) - } - err => NanosleepRelativeResult::Err(io::Errno(err)), + let flags = 0; + let mut remain = MaybeUninit::<LibcTimespec>::uninit(); + + unsafe { + return match libc_clock_nanosleep( + id as c::clockid_t, + flags, + &request.clone().into(), + remain.as_mut_ptr(), + ) { + 0 => NanosleepRelativeResult::Ok, + err if err == io::Errno::INTR.0 => { + NanosleepRelativeResult::Interrupted(remain.assume_init().into()) + } + err => NanosleepRelativeResult::Err(io::Errno(err)), + }; } - } else { - clock_nanosleep_relative_old(id, request) } + + clock_nanosleep_relative_old(id, request) } // Main version: libc is y2038 safe and has `clock_nanosleep`. - #[cfg(not(all( - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", - )))] + #[cfg(not(fix_y2038))] unsafe { + let flags = 0; let mut remain = MaybeUninit::<Timespec>::uninit(); match c::clock_nanosleep(id as c::clockid_t, flags, request, remain.as_mut_ptr()) { @@ -100,10 +90,10 @@ pub(crate) fn clock_nanosleep_relative(id: ClockId, request: &Timespec) -> Nanos } #[cfg(all( - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", + fix_y2038, + not(any(apple, target_os = "emscripten", target_os = "haiku")) ))] -unsafe fn clock_nanosleep_relative_old(id: ClockId, request: &Timespec) -> NanosleepRelativeResult { +fn clock_nanosleep_relative_old(id: ClockId, request: &Timespec) -> NanosleepRelativeResult { let tv_sec = match request.tv_sec.try_into() { Ok(tv_sec) => tv_sec, Err(_) => return NanosleepRelativeResult::Err(io::Errno::OVERFLOW), @@ -116,22 +106,24 @@ unsafe fn clock_nanosleep_relative_old(id: ClockId, request: &Timespec) -> Nanos let mut old_remain = MaybeUninit::<c::timespec>::uninit(); let flags = 0; - match c::clock_nanosleep( - id as c::clockid_t, - flags, - &old_request, - old_remain.as_mut_ptr(), - ) { - 0 => NanosleepRelativeResult::Ok, - err if err == io::Errno::INTR.0 => { - let old_remain = old_remain.assume_init(); - let remain = Timespec { - tv_sec: old_remain.tv_sec.into(), - tv_nsec: old_remain.tv_nsec.into(), - }; - NanosleepRelativeResult::Interrupted(remain) + unsafe { + match c::clock_nanosleep( + id as c::clockid_t, + flags, + &old_request, + old_remain.as_mut_ptr(), + ) { + 0 => NanosleepRelativeResult::Ok, + err if err == io::Errno::INTR.0 => { + let old_remain = old_remain.assume_init(); + let remain = Timespec { + tv_sec: old_remain.tv_sec.into(), + tv_nsec: old_remain.tv_nsec.into(), + }; + NanosleepRelativeResult::Interrupted(remain) + } + err => NanosleepRelativeResult::Err(io::Errno(err)), } - err => NanosleepRelativeResult::Err(io::Errno(err)), } } @@ -139,6 +131,7 @@ unsafe fn clock_nanosleep_relative_old(id: ClockId, request: &Timespec) -> Nanos apple, target_os = "dragonfly", target_os = "emscripten", + target_os = "espidf", target_os = "freebsd", // FreeBSD 12 has clock_nanosleep, but libc targets FreeBSD 11. target_os = "haiku", target_os = "openbsd", @@ -147,46 +140,46 @@ unsafe fn clock_nanosleep_relative_old(id: ClockId, request: &Timespec) -> Nanos )))] #[inline] pub(crate) fn clock_nanosleep_absolute(id: ClockId, request: &Timespec) -> io::Result<()> { - let flags = c::TIMER_ABSTIME; - - // 32-bit gnu version: libc has `clock_nanosleep` but it is not y2038 safe - // by default. - #[cfg(all( - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", - ))] + // Old 32-bit version: libc has `clock_nanosleep` but it is not y2038 safe + // by default. But there may be a `__clock_nanosleep_time64` we can use. + #[cfg(fix_y2038)] { + #[cfg(target_env = "gnu")] if let Some(libc_clock_nanosleep) = __clock_nanosleep_time64.get() { - match unsafe { - libc_clock_nanosleep( - id as c::clockid_t, - flags, - &request.clone().into(), - null_mut(), - ) - } { - 0 => Ok(()), - err => Err(io::Errno(err)), + let flags = c::TIMER_ABSTIME; + unsafe { + return match { + libc_clock_nanosleep( + id as c::clockid_t, + flags, + &request.clone().into(), + null_mut(), + ) + } { + 0 => Ok(()), + err => Err(io::Errno(err)), + }; } - } else { - clock_nanosleep_absolute_old(id, request) } + + clock_nanosleep_absolute_old(id, request) } // Main version: libc is y2038 safe and has `clock_nanosleep`. - #[cfg(not(all( - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", - )))] - match unsafe { c::clock_nanosleep(id as c::clockid_t, flags, request, null_mut()) } { - 0 => Ok(()), - err => Err(io::Errno(err)), + #[cfg(not(fix_y2038))] + { + let flags = c::TIMER_ABSTIME; + + match unsafe { c::clock_nanosleep(id as c::clockid_t, flags as _, request, null_mut()) } { + 0 => Ok(()), + err => Err(io::Errno(err)), + } } } #[cfg(all( - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", + fix_y2038, + not(any(apple, target_os = "emscripten", target_os = "haiku")) ))] fn clock_nanosleep_absolute_old(id: ClockId, request: &Timespec) -> io::Result<()> { let flags = c::TIMER_ABSTIME; @@ -204,33 +197,29 @@ fn clock_nanosleep_absolute_old(id: ClockId, request: &Timespec) -> io::Result<( #[cfg(not(target_os = "redox"))] #[inline] pub(crate) fn nanosleep(request: &Timespec) -> NanosleepRelativeResult { - // 32-bit gnu version: libc has `nanosleep` but it is not y2038 safe by - // default. - #[cfg(all( - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", - ))] - unsafe { - let mut remain = MaybeUninit::<LibcTimespec>::uninit(); - + // Old 32-bit version: libc has `nanosleep` but it is not y2038 safe by + // default. But there may be a `__nanosleep64` we can use. + #[cfg(fix_y2038)] + { + #[cfg(target_env = "gnu")] if let Some(libc_nanosleep) = __nanosleep64.get() { - match ret(libc_nanosleep(&request.clone().into(), remain.as_mut_ptr())) { - Ok(()) => NanosleepRelativeResult::Ok, - Err(io::Errno::INTR) => { - NanosleepRelativeResult::Interrupted(remain.assume_init().into()) - } - Err(err) => NanosleepRelativeResult::Err(err), + let mut remain = MaybeUninit::<LibcTimespec>::uninit(); + unsafe { + return match ret(libc_nanosleep(&request.clone().into(), remain.as_mut_ptr())) { + Ok(()) => NanosleepRelativeResult::Ok, + Err(io::Errno::INTR) => { + NanosleepRelativeResult::Interrupted(remain.assume_init().into()) + } + Err(err) => NanosleepRelativeResult::Err(err), + }; } - } else { - nanosleep_old(request) } + + nanosleep_old(request) } // Main version: libc is y2038 safe and has `nanosleep`. - #[cfg(not(all( - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", - )))] + #[cfg(not(fix_y2038))] unsafe { let mut remain = MaybeUninit::<Timespec>::uninit(); @@ -242,11 +231,8 @@ pub(crate) fn nanosleep(request: &Timespec) -> NanosleepRelativeResult { } } -#[cfg(all( - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", -))] -unsafe fn nanosleep_old(request: &Timespec) -> NanosleepRelativeResult { +#[cfg(fix_y2038)] +fn nanosleep_old(request: &Timespec) -> NanosleepRelativeResult { let tv_sec = match request.tv_sec.try_into() { Ok(tv_sec) => tv_sec, Err(_) => return NanosleepRelativeResult::Err(io::Errno::OVERFLOW), @@ -258,17 +244,19 @@ unsafe fn nanosleep_old(request: &Timespec) -> NanosleepRelativeResult { let old_request = c::timespec { tv_sec, tv_nsec }; let mut old_remain = MaybeUninit::<c::timespec>::uninit(); - match ret(c::nanosleep(&old_request, old_remain.as_mut_ptr())) { - Ok(()) => NanosleepRelativeResult::Ok, - Err(io::Errno::INTR) => { - let old_remain = old_remain.assume_init(); - let remain = Timespec { - tv_sec: old_remain.tv_sec.into(), - tv_nsec: old_remain.tv_nsec.into(), - }; - NanosleepRelativeResult::Interrupted(remain) + unsafe { + match ret(c::nanosleep(&old_request, old_remain.as_mut_ptr())) { + Ok(()) => NanosleepRelativeResult::Ok, + Err(io::Errno::INTR) => { + let old_remain = old_remain.assume_init(); + let remain = Timespec { + tv_sec: old_remain.tv_sec.into(), + tv_nsec: old_remain.tv_nsec.into(), + }; + NanosleepRelativeResult::Interrupted(remain) + } + Err(err) => NanosleepRelativeResult::Err(err), } - Err(err) => NanosleepRelativeResult::Err(err), } } diff --git a/vendor/rustix/src/backend/libc/time/syscalls.rs b/vendor/rustix/src/backend/libc/time/syscalls.rs index 14ca22b2d..603a3b108 100644 --- a/vendor/rustix/src/backend/libc/time/syscalls.rs +++ b/vendor/rustix/src/backend/libc/time/syscalls.rs @@ -2,13 +2,14 @@ use crate::backend::c; use crate::backend::conv::ret; +#[cfg(any(linux_kernel, target_os = "fuchsia"))] +#[cfg(feature = "time")] +#[cfg(any(all(target_env = "gnu", fix_y2038), not(fix_y2038)))] +use crate::backend::time::types::LibcItimerspec; #[cfg(not(target_os = "wasi"))] use crate::clockid::{ClockId, DynamicClockId}; use crate::io; -#[cfg(all( - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", -))] +#[cfg(all(target_env = "gnu", fix_y2038))] use crate::timespec::LibcTimespec; use crate::timespec::Timespec; use core::mem::MaybeUninit; @@ -16,36 +17,22 @@ use core::mem::MaybeUninit; #[cfg(feature = "time")] use { crate::backend::conv::{borrowed_fd, ret_owned_fd}, - crate::backend::time::types::LibcItimerspec, crate::fd::{BorrowedFd, OwnedFd}, crate::time::{Itimerspec, TimerfdClockId, TimerfdFlags, TimerfdTimerFlags}, }; -#[cfg(all( - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", -))] +#[cfg(all(target_env = "gnu", fix_y2038))] weak!(fn __clock_gettime64(c::clockid_t, *mut LibcTimespec) -> c::c_int); -#[cfg(all( - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", -))] +#[cfg(all(target_env = "gnu", fix_y2038))] weak!(fn __clock_settime64(c::clockid_t, *const LibcTimespec) -> c::c_int); -#[cfg(all( - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", -))] +#[cfg(all(target_env = "gnu", fix_y2038))] weak!(fn __clock_getres64(c::clockid_t, *mut LibcTimespec) -> c::c_int); -#[cfg(all( - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", -))] +#[cfg(any(linux_kernel, target_os = "fuchsia"))] +#[cfg(all(target_env = "gnu", fix_y2038))] #[cfg(feature = "time")] weak!(fn __timerfd_gettime64(c::c_int, *mut LibcItimerspec) -> c::c_int); -#[cfg(all( - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", -))] +#[cfg(any(linux_kernel, target_os = "fuchsia"))] +#[cfg(all(target_env = "gnu", fix_y2038))] #[cfg(feature = "time")] weak!(fn __timerfd_settime64(c::c_int, c::c_int, *const LibcItimerspec, *mut LibcItimerspec) -> c::c_int); @@ -53,28 +40,24 @@ weak!(fn __timerfd_settime64(c::c_int, c::c_int, *const LibcItimerspec, *mut Lib #[inline] #[must_use] pub(crate) fn clock_getres(id: ClockId) -> Timespec { - // 32-bit gnu version: libc has `clock_getres` but it is not y2038 safe by - // default. - #[cfg(all( - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", - ))] - unsafe { - let mut timespec = MaybeUninit::<LibcTimespec>::uninit(); - + // Old 32-bit version: libc has `clock_getres` but it is not y2038 safe by + // default. But there may be a `__clock_getres64` we can use. + #[cfg(fix_y2038)] + { + #[cfg(target_env = "gnu")] if let Some(libc_clock_getres) = __clock_getres64.get() { - ret(libc_clock_getres(id as c::clockid_t, timespec.as_mut_ptr())).unwrap(); - timespec.assume_init().into() - } else { - clock_getres_old(id) + let mut timespec = MaybeUninit::<LibcTimespec>::uninit(); + unsafe { + ret(libc_clock_getres(id as c::clockid_t, timespec.as_mut_ptr())).unwrap(); + return timespec.assume_init().into(); + } } + + clock_getres_old(id) } // Main version: libc is y2038 safe and has `clock_getres`. - #[cfg(not(all( - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", - )))] + #[cfg(not(fix_y2038))] unsafe { let mut timespec = MaybeUninit::<Timespec>::uninit(); let _ = c::clock_getres(id as c::clockid_t, timespec.as_mut_ptr()); @@ -82,19 +65,20 @@ pub(crate) fn clock_getres(id: ClockId) -> Timespec { } } -#[cfg(all( - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", -))] +#[cfg(fix_y2038)] #[must_use] -unsafe fn clock_getres_old(id: ClockId) -> Timespec { +fn clock_getres_old(id: ClockId) -> Timespec { let mut old_timespec = MaybeUninit::<c::timespec>::uninit(); - ret(c::clock_getres( - id as c::clockid_t, - old_timespec.as_mut_ptr(), - )) - .unwrap(); - let old_timespec = old_timespec.assume_init(); + + let old_timespec = unsafe { + ret(c::clock_getres( + id as c::clockid_t, + old_timespec.as_mut_ptr(), + )) + .unwrap(); + old_timespec.assume_init() + }; + Timespec { tv_sec: old_timespec.tv_sec.into(), tv_nsec: old_timespec.tv_nsec.into(), @@ -105,33 +89,31 @@ unsafe fn clock_getres_old(id: ClockId) -> Timespec { #[inline] #[must_use] pub(crate) fn clock_gettime(id: ClockId) -> Timespec { - #[cfg(all( - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", - ))] - unsafe { - let mut timespec = MaybeUninit::<LibcTimespec>::uninit(); - + // Old 32-bit version: libc has `clock_gettime` but it is not y2038 safe by + // default. But there may be a `__clock_gettime64` we can use. + #[cfg(fix_y2038)] + { + #[cfg(target_env = "gnu")] if let Some(libc_clock_gettime) = __clock_gettime64.get() { - ret(libc_clock_gettime( - id as c::clockid_t, - timespec.as_mut_ptr(), - )) - .unwrap(); - timespec.assume_init().into() - } else { - clock_gettime_old(id) + let mut timespec = MaybeUninit::<LibcTimespec>::uninit(); + unsafe { + ret(libc_clock_gettime( + id as c::clockid_t, + timespec.as_mut_ptr(), + )) + .unwrap(); + return timespec.assume_init().into(); + } } + + clock_gettime_old(id) } // Use `unwrap()` here because `clock_getres` can fail if the clock itself // overflows a number of seconds, but if that happens, the monotonic clocks // can't maintain their invariants, or the realtime clocks aren't properly // configured. - #[cfg(not(all( - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", - )))] + #[cfg(not(fix_y2038))] unsafe { let mut timespec = MaybeUninit::<Timespec>::uninit(); ret(c::clock_gettime(id as c::clockid_t, timespec.as_mut_ptr())).unwrap(); @@ -139,19 +121,20 @@ pub(crate) fn clock_gettime(id: ClockId) -> Timespec { } } -#[cfg(all( - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", -))] +#[cfg(fix_y2038)] #[must_use] -unsafe fn clock_gettime_old(id: ClockId) -> Timespec { +fn clock_gettime_old(id: ClockId) -> Timespec { let mut old_timespec = MaybeUninit::<c::timespec>::uninit(); - ret(c::clock_gettime( - id as c::clockid_t, - old_timespec.as_mut_ptr(), - )) - .unwrap(); - let old_timespec = old_timespec.assume_init(); + + let old_timespec = unsafe { + ret(c::clock_gettime( + id as c::clockid_t, + old_timespec.as_mut_ptr(), + )) + .unwrap(); + old_timespec.assume_init() + }; + Timespec { tv_sec: old_timespec.tv_sec.into(), tv_nsec: old_timespec.tv_nsec.into(), @@ -161,83 +144,85 @@ unsafe fn clock_gettime_old(id: ClockId) -> Timespec { #[cfg(not(target_os = "wasi"))] #[inline] pub(crate) fn clock_gettime_dynamic(id: DynamicClockId<'_>) -> io::Result<Timespec> { - unsafe { - let id: c::clockid_t = match id { - DynamicClockId::Known(id) => id as c::clockid_t, - - #[cfg(linux_kernel)] - DynamicClockId::Dynamic(fd) => { - use crate::fd::AsRawFd; - const CLOCKFD: i32 = 3; - (!fd.as_raw_fd() << 3) | CLOCKFD - } + let id: c::clockid_t = match id { + DynamicClockId::Known(id) => id as c::clockid_t, + + #[cfg(linux_kernel)] + DynamicClockId::Dynamic(fd) => { + use crate::fd::AsRawFd; + const CLOCKFD: i32 = 3; + (!fd.as_raw_fd() << 3) | CLOCKFD + } - #[cfg(not(linux_kernel))] - DynamicClockId::Dynamic(_fd) => { - // Dynamic clocks are not supported on this platform. - return Err(io::Errno::INVAL); - } + #[cfg(not(linux_kernel))] + DynamicClockId::Dynamic(_fd) => { + // Dynamic clocks are not supported on this platform. + return Err(io::Errno::INVAL); + } - #[cfg(linux_kernel)] - DynamicClockId::RealtimeAlarm => c::CLOCK_REALTIME_ALARM, + #[cfg(linux_kernel)] + DynamicClockId::RealtimeAlarm => c::CLOCK_REALTIME_ALARM, - #[cfg(linux_kernel)] - DynamicClockId::Tai => c::CLOCK_TAI, + #[cfg(linux_kernel)] + DynamicClockId::Tai => c::CLOCK_TAI, - #[cfg(any(linux_kernel, target_os = "openbsd"))] - DynamicClockId::Boottime => c::CLOCK_BOOTTIME, + #[cfg(any( + freebsdlike, + linux_kernel, + target_os = "fuchsia", + target_os = "openbsd" + ))] + DynamicClockId::Boottime => c::CLOCK_BOOTTIME, - #[cfg(linux_kernel)] - DynamicClockId::BoottimeAlarm => c::CLOCK_BOOTTIME_ALARM, - }; + #[cfg(any(linux_kernel, target_os = "fuchsia"))] + DynamicClockId::BoottimeAlarm => c::CLOCK_BOOTTIME_ALARM, + }; - #[cfg(all( - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", - ))] - { + // Old 32-bit version: libc has `clock_gettime` but it is not y2038 + // safe by default. But there may be a `__clock_gettime64` we can use. + #[cfg(fix_y2038)] + { + #[cfg(target_env = "gnu")] + if let Some(libc_clock_gettime) = __clock_gettime64.get() { let mut timespec = MaybeUninit::<LibcTimespec>::uninit(); - - if let Some(libc_clock_gettime) = __clock_gettime64.get() { + unsafe { ret(libc_clock_gettime( id as c::clockid_t, timespec.as_mut_ptr(), ))?; - Ok(timespec.assume_init().into()) - } else { - clock_gettime_dynamic_old(id) + return Ok(timespec.assume_init().into()); } } - #[cfg(not(all( - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", - )))] - { - let mut timespec = MaybeUninit::<Timespec>::uninit(); + clock_gettime_dynamic_old(id) + } + + // Main version: libc is y2038 safe and has `clock_gettime`. + #[cfg(not(fix_y2038))] + unsafe { + let mut timespec = MaybeUninit::<Timespec>::uninit(); - ret(c::clock_gettime(id as c::clockid_t, timespec.as_mut_ptr()))?; + ret(c::clock_gettime(id as c::clockid_t, timespec.as_mut_ptr()))?; - Ok(timespec.assume_init()) - } + Ok(timespec.assume_init()) } } -#[cfg(all( - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", -))] +#[cfg(fix_y2038)] #[inline] -unsafe fn clock_gettime_dynamic_old(id: c::clockid_t) -> io::Result<Timespec> { +fn clock_gettime_dynamic_old(id: c::clockid_t) -> io::Result<Timespec> { let mut old_timespec = MaybeUninit::<c::timespec>::uninit(); - ret(c::clock_gettime( - id as c::clockid_t, - old_timespec.as_mut_ptr(), - ))?; + let old_timespec = unsafe { + ret(c::clock_gettime( + id as c::clockid_t, + old_timespec.as_mut_ptr(), + ))?; + + old_timespec.assume_init() + }; - let old_timespec = old_timespec.assume_init(); Ok(Timespec { tv_sec: old_timespec.tv_sec.into(), tv_nsec: old_timespec.tv_nsec.into(), @@ -251,25 +236,25 @@ unsafe fn clock_gettime_dynamic_old(id: c::clockid_t) -> io::Result<Timespec> { )))] #[inline] pub(crate) fn clock_settime(id: ClockId, timespec: Timespec) -> io::Result<()> { - #[cfg(all( - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", - ))] - unsafe { + // Old 32-bit version: libc has `clock_gettime` but it is not y2038 safe by + // default. But there may be a `__clock_settime64` we can use. + #[cfg(fix_y2038)] + { + #[cfg(target_env = "gnu")] if let Some(libc_clock_settime) = __clock_settime64.get() { - let mut new_timespec = core::mem::zeroed::<LibcTimespec>(); - new_timespec.tv_sec = timespec.tv_sec; - new_timespec.tv_nsec = timespec.tv_nsec as _; - ret(libc_clock_settime(id as c::clockid_t, &new_timespec)) - } else { - clock_settime_old(id, timespec) + unsafe { + let mut new_timespec = core::mem::zeroed::<LibcTimespec>(); + new_timespec.tv_sec = timespec.tv_sec; + new_timespec.tv_nsec = timespec.tv_nsec as _; + return ret(libc_clock_settime(id as c::clockid_t, &new_timespec)); + } } + + clock_settime_old(id, timespec) } - #[cfg(not(all( - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", - )))] + // Main version: libc is y2038 safe and has `clock_settime`. + #[cfg(not(fix_y2038))] unsafe { ret(c::clock_settime(id as c::clockid_t, ×pec)) } @@ -280,11 +265,8 @@ pub(crate) fn clock_settime(id: ClockId, timespec: Timespec) -> io::Result<()> { target_os = "wasi", all(apple, not(target_os = "macos")) )))] -#[cfg(all( - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", -))] -unsafe fn clock_settime_old(id: ClockId, timespec: Timespec) -> io::Result<()> { +#[cfg(fix_y2038)] +fn clock_settime_old(id: ClockId, timespec: Timespec) -> io::Result<()> { let old_timespec = c::timespec { tv_sec: timespec .tv_sec @@ -292,7 +274,8 @@ unsafe fn clock_settime_old(id: ClockId, timespec: Timespec) -> io::Result<()> { .map_err(|_| io::Errno::OVERFLOW)?, tv_nsec: timespec.tv_nsec as _, }; - ret(c::clock_settime(id as c::clockid_t, &old_timespec)) + + unsafe { ret(c::clock_settime(id as c::clockid_t, &old_timespec)) } } #[cfg(any(linux_kernel, target_os = "fuchsia"))] @@ -308,31 +291,30 @@ pub(crate) fn timerfd_settime( flags: TimerfdTimerFlags, new_value: &Itimerspec, ) -> io::Result<Itimerspec> { - let mut result = MaybeUninit::<LibcItimerspec>::uninit(); - - #[cfg(all( - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", - ))] - unsafe { + // Old 32-bit version: libc has `timerfd_settime` but it is not y2038 safe + // by default. But there may be a `__timerfd_settime64` we can use. + #[cfg(fix_y2038)] + { + #[cfg(target_env = "gnu")] if let Some(libc_timerfd_settime) = __timerfd_settime64.get() { - ret(libc_timerfd_settime( - borrowed_fd(fd), - bitflags_bits!(flags), - &new_value.clone().into(), - result.as_mut_ptr(), - ))?; - Ok(result.assume_init().into()) - } else { - timerfd_settime_old(fd, flags, new_value) + let mut result = MaybeUninit::<LibcItimerspec>::uninit(); + unsafe { + ret(libc_timerfd_settime( + borrowed_fd(fd), + bitflags_bits!(flags), + &new_value.clone().into(), + result.as_mut_ptr(), + ))?; + return Ok(result.assume_init().into()); + } } + + timerfd_settime_old(fd, flags, new_value) } - #[cfg(not(all( - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", - )))] + #[cfg(not(fix_y2038))] unsafe { + let mut result = MaybeUninit::<LibcItimerspec>::uninit(); ret(c::timerfd_settime( borrowed_fd(fd), bitflags_bits!(flags), @@ -344,12 +326,9 @@ pub(crate) fn timerfd_settime( } #[cfg(any(linux_kernel, target_os = "fuchsia"))] -#[cfg(all( - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", -))] +#[cfg(fix_y2038)] #[cfg(feature = "time")] -unsafe fn timerfd_settime_old( +fn timerfd_settime_old( fd: BorrowedFd<'_>, flags: TimerfdTimerFlags, new_value: &Itimerspec, @@ -384,14 +363,16 @@ unsafe fn timerfd_settime_old( }, }; - ret(c::timerfd_settime( - borrowed_fd(fd), - bitflags_bits!(flags), - &old_new_value, - old_result.as_mut_ptr(), - ))?; + let old_result = unsafe { + ret(c::timerfd_settime( + borrowed_fd(fd), + bitflags_bits!(flags), + &old_new_value, + old_result.as_mut_ptr(), + ))?; + old_result.assume_init() + }; - let old_result = old_result.assume_init(); Ok(Itimerspec { it_interval: Timespec { tv_sec: old_result @@ -415,43 +396,41 @@ unsafe fn timerfd_settime_old( #[cfg(any(linux_kernel, target_os = "fuchsia"))] #[cfg(feature = "time")] pub(crate) fn timerfd_gettime(fd: BorrowedFd<'_>) -> io::Result<Itimerspec> { - let mut result = MaybeUninit::<LibcItimerspec>::uninit(); - - #[cfg(all( - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", - ))] - unsafe { + // Old 32-bit version: libc has `timerfd_gettime` but it is not y2038 safe + // by default. But there may be a `__timerfd_gettime64` we can use. + #[cfg(fix_y2038)] + { + #[cfg(target_env = "gnu")] if let Some(libc_timerfd_gettime) = __timerfd_gettime64.get() { - ret(libc_timerfd_gettime(borrowed_fd(fd), result.as_mut_ptr()))?; - Ok(result.assume_init().into()) - } else { - timerfd_gettime_old(fd) + let mut result = MaybeUninit::<LibcItimerspec>::uninit(); + unsafe { + ret(libc_timerfd_gettime(borrowed_fd(fd), result.as_mut_ptr()))?; + return Ok(result.assume_init().into()); + } } + + timerfd_gettime_old(fd) } - #[cfg(not(all( - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", - )))] + #[cfg(not(fix_y2038))] unsafe { + let mut result = MaybeUninit::<LibcItimerspec>::uninit(); ret(c::timerfd_gettime(borrowed_fd(fd), result.as_mut_ptr()))?; Ok(result.assume_init()) } } #[cfg(any(linux_kernel, target_os = "fuchsia"))] -#[cfg(all( - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", -))] +#[cfg(fix_y2038)] #[cfg(feature = "time")] -unsafe fn timerfd_gettime_old(fd: BorrowedFd<'_>) -> io::Result<Itimerspec> { +fn timerfd_gettime_old(fd: BorrowedFd<'_>) -> io::Result<Itimerspec> { let mut old_result = MaybeUninit::<c::itimerspec>::uninit(); - ret(c::timerfd_gettime(borrowed_fd(fd), old_result.as_mut_ptr()))?; + let old_result = unsafe { + ret(c::timerfd_gettime(borrowed_fd(fd), old_result.as_mut_ptr()))?; + old_result.assume_init() + }; - let old_result = old_result.assume_init(); Ok(Itimerspec { it_interval: Timespec { tv_sec: old_result diff --git a/vendor/rustix/src/backend/libc/time/types.rs b/vendor/rustix/src/backend/libc/time/types.rs index e1d4a8736..75cc61217 100644 --- a/vendor/rustix/src/backend/libc/time/types.rs +++ b/vendor/rustix/src/backend/libc/time/types.rs @@ -1,15 +1,10 @@ #[cfg(any(linux_kernel, target_os = "fuchsia"))] use crate::backend::c; -#[cfg(all( - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", -))] +#[cfg(any(linux_kernel, target_os = "fuchsia"))] +#[cfg(fix_y2038)] use crate::timespec::LibcTimespec; #[cfg(any(linux_kernel, target_os = "fuchsia"))] -#[cfg(all( - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", -))] +#[cfg(fix_y2038)] use crate::timespec::Timespec; #[cfg(any(linux_kernel, target_os = "fuchsia"))] use bitflags::bitflags; @@ -20,10 +15,7 @@ use bitflags::bitflags; /// [`timerfd_gettime`]: crate::time::timerfd_gettime /// [`timerfd_settime`]: crate::time::timerfd_settime #[cfg(any(linux_kernel, target_os = "fuchsia"))] -#[cfg(not(all( - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", -)))] +#[cfg(not(fix_y2038))] pub type Itimerspec = c::itimerspec; /// `struct itimerspec` for use with [`timerfd_gettime`] and @@ -32,10 +24,7 @@ pub type Itimerspec = c::itimerspec; /// [`timerfd_gettime`]: crate::time::timerfd_gettime /// [`timerfd_settime`]: crate::time::timerfd_settime #[cfg(any(linux_kernel, target_os = "fuchsia"))] -#[cfg(all( - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", -))] +#[cfg(fix_y2038)] #[allow(missing_docs)] #[repr(C)] #[derive(Debug, Clone)] @@ -46,19 +35,13 @@ pub struct Itimerspec { /// On most platforms, `LibcItimerspec` is just `Itimerspec`. #[cfg(any(linux_kernel, target_os = "fuchsia"))] -#[cfg(not(all( - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", -)))] +#[cfg(not(fix_y2038))] pub(crate) type LibcItimerspec = Itimerspec; /// On 32-bit glibc platforms, `LibcTimespec` differs from `Timespec`, so we /// define our own struct, with bidirectional `From` impls. #[cfg(any(linux_kernel, target_os = "fuchsia"))] -#[cfg(all( - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", -))] +#[cfg(fix_y2038)] #[repr(C)] #[derive(Debug, Clone)] pub(crate) struct LibcItimerspec { @@ -67,10 +50,7 @@ pub(crate) struct LibcItimerspec { } #[cfg(any(linux_kernel, target_os = "fuchsia"))] -#[cfg(all( - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", -))] +#[cfg(fix_y2038)] impl From<LibcItimerspec> for Itimerspec { #[inline] fn from(t: LibcItimerspec) -> Self { @@ -82,10 +62,7 @@ impl From<LibcItimerspec> for Itimerspec { } #[cfg(any(linux_kernel, target_os = "fuchsia"))] -#[cfg(all( - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", -))] +#[cfg(fix_y2038)] impl From<Itimerspec> for LibcItimerspec { #[inline] fn from(t: Itimerspec) -> Self { @@ -179,7 +156,6 @@ pub enum TimerfdClockId { #[cfg(any(linux_kernel, target_os = "fuchsia"))] #[test] fn test_types() { - use core::mem::size_of; - assert_eq!(size_of::<TimerfdFlags>(), size_of::<c::c_int>()); - assert_eq!(size_of::<TimerfdTimerFlags>(), size_of::<c::c_int>()); + assert_eq_size!(TimerfdFlags, c::c_int); + assert_eq_size!(TimerfdTimerFlags, c::c_int); } |