diff options
Diffstat (limited to 'vendor/rustix/src/backend/libc/io')
-rw-r--r-- | vendor/rustix/src/backend/libc/io/epoll.rs | 531 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/io/errno.rs | 527 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/io/poll_fd.rs | 4 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/io/syscalls.rs | 226 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/io/types.rs | 39 |
5 files changed, 439 insertions, 888 deletions
diff --git a/vendor/rustix/src/backend/libc/io/epoll.rs b/vendor/rustix/src/backend/libc/io/epoll.rs index 3205a613f..62a3c742b 100644 --- a/vendor/rustix/src/backend/libc/io/epoll.rs +++ b/vendor/rustix/src/backend/libc/io/epoll.rs @@ -6,17 +6,17 @@ //! //! # Examples //! -//! ```rust,no_run +//! ```no_run //! # #![cfg_attr(io_lifetimes_use_std, feature(io_safety))] //! # #[cfg(feature = "net")] //! # fn main() -> std::io::Result<()> { //! use io_lifetimes::AsFd; -//! use rustix::io::epoll::{self, Epoll}; -//! use rustix::io::{ioctl_fionbio, read, write}; +//! use rustix::io::{epoll, ioctl_fionbio, read, write}; //! use rustix::net::{ //! accept, bind_v4, listen, socket, AddressFamily, Ipv4Addr, Protocol, SocketAddrV4, //! SocketType, //! }; +//! use std::collections::HashMap; //! use std::os::unix::io::AsRawFd; //! //! // Create a socket and listen on it. @@ -26,29 +26,40 @@ //! //! // Create an epoll object. Using `Owning` here means the epoll object will //! // take ownership of the file descriptors registered with it. -//! let epoll = Epoll::new(epoll::CreateFlags::CLOEXEC, epoll::Owning::new())?; -//! -//! // Remember the socket raw fd, which we use for comparisons only. -//! let raw_listen_sock = listen_sock.as_fd().as_raw_fd(); +//! let epoll = epoll::epoll_create(epoll::CreateFlags::CLOEXEC)?; //! //! // Register the socket with the epoll object. -//! epoll.add(listen_sock, epoll::EventFlags::IN)?; +//! epoll::epoll_add(&epoll, &listen_sock, 1, epoll::EventFlags::IN)?; +//! +//! // Keep track of the sockets we've opened. +//! let mut next_id = 2; +//! let mut sockets = HashMap::new(); //! //! // Process events. //! let mut event_list = epoll::EventVec::with_capacity(4); //! loop { -//! epoll.wait(&mut event_list, -1)?; +//! epoll::epoll_wait(&epoll, &mut event_list, -1)?; //! for (_event_flags, target) in &event_list { -//! if target.as_raw_fd() == raw_listen_sock { +//! if target == 1 { //! // Accept a new connection, set it to non-blocking, and //! // register to be notified when it's ready to write to. -//! let conn_sock = accept(&*target)?; +//! let conn_sock = accept(&listen_sock)?; //! ioctl_fionbio(&conn_sock, true)?; -//! epoll.add(conn_sock, epoll::EventFlags::OUT | epoll::EventFlags::ET)?; +//! epoll::epoll_add( +//! &epoll, +//! &conn_sock, +//! next_id, +//! epoll::EventFlags::OUT | epoll::EventFlags::ET, +//! )?; +//! +//! // Keep track of the socket. +//! sockets.insert(next_id, conn_sock); +//! next_id += 1; //! } else { //! // Write a message to the stream and then unregister it. -//! write(&*target, b"hello\n")?; -//! let _ = epoll.del(target)?; +//! let target = sockets.remove(&target).unwrap(); +//! write(&target, b"hello\n")?; +//! let _ = epoll::epoll_del(&epoll, &target)?; //! } //! } //! } @@ -59,17 +70,12 @@ use super::super::c; use super::super::conv::{ret, ret_owned_fd, ret_u32}; -use crate::fd::{AsFd, AsRawFd, BorrowedFd, OwnedFd, RawFd}; -#[cfg(not(feature = "rustc-dep-of-std"))] -use crate::fd::{FromRawFd, IntoRawFd}; +use crate::fd::{AsFd, AsRawFd, OwnedFd}; use crate::io; use alloc::vec::Vec; use bitflags::bitflags; use core::convert::TryInto; -use core::fmt; -use core::marker::PhantomData; -use core::ops::Deref; -use core::ptr::{null, null_mut}; +use core::ptr::null_mut; bitflags! { /// `EPOLL_*` for use with [`Epoll::new`]. @@ -98,6 +104,24 @@ bitflags! { /// `EPOLLHUP` const HUP = c::EPOLLHUP as u32; + /// `EPOLLRDNORM` + const RDNORM = c::EPOLLRDNORM as u32; + + /// `EPOLLRDBAND` + const RDBAND = c::EPOLLRDBAND as u32; + + /// `EPOLLWRNORM` + const WRNORM = c::EPOLLWRNORM as u32; + + /// `EPOLLWRBAND` + const WRBAND = c::EPOLLWRBAND as u32; + + /// `EPOLLMSG` + const MSG = c::EPOLLMSG as u32; + + /// `EPOLLRDHUP` + const RDHUP = c::EPOLLRDHUP as u32; + /// `EPOLLET` const ET = c::EPOLLET as u32; @@ -113,360 +137,136 @@ bitflags! { } } -/// A reference to a `T`. -pub struct Ref<'a, T> { - t: T, - _phantom: PhantomData<&'a T>, -} - -impl<'a, T> Ref<'a, T> { - #[inline] - fn new(t: T) -> Self { - Self { - t, - _phantom: PhantomData, - } - } - - #[inline] - fn consume(self) -> T { - self.t - } -} - -impl<'a, T> Deref for Ref<'a, T> { - type Target = T; - - #[inline] - fn deref(&self) -> &T { - &self.t - } -} - -impl<'a, T: fmt::Debug> fmt::Debug for Ref<'a, T> { - fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { - self.t.fmt(fmt) - } -} - -/// A trait for data stored within an [`Epoll`] instance. -pub trait Context { - /// The type of an element owned by this context. - type Data; - - /// The type of a value used to refer to an element owned by this context. - type Target: AsFd; - - /// Assume ownership of `data`, and returning a `Target`. - fn acquire<'call>(&self, data: Self::Data) -> Ref<'call, Self::Target>; - - /// Encode `target` as a `u64`. The only requirement on this value is that - /// it be decodable by `decode`. - fn encode(&self, target: Ref<'_, Self::Target>) -> u64; - - /// Decode `raw`, which is a value encoded by `encode`, into a `Target`. - /// - /// # Safety - /// - /// `raw` must be a `u64` value returned from `encode`, from the same - /// context, and within the context's lifetime. - unsafe fn decode<'call>(&self, raw: u64) -> Ref<'call, Self::Target>; - - /// Release ownership of the value referred to by `target` and return it. - fn release(&self, target: Ref<'_, Self::Target>) -> Self::Data; -} - -/// A type implementing [`Context`] where the `Data` type is `BorrowedFd<'a>`. -pub struct Borrowing<'a> { - _phantom: PhantomData<BorrowedFd<'a>>, -} - -impl<'a> Context for Borrowing<'a> { - type Data = BorrowedFd<'a>; - type Target = BorrowedFd<'a>; - - #[inline] - fn acquire<'call>(&self, data: Self::Data) -> Ref<'call, Self::Target> { - Ref::new(data) - } - - #[inline] - fn encode(&self, target: Ref<'_, Self::Target>) -> u64 { - target.as_raw_fd() as u64 - } - - #[inline] - unsafe fn decode<'call>(&self, raw: u64) -> Ref<'call, Self::Target> { - Ref::new(BorrowedFd::<'a>::borrow_raw(raw as RawFd)) - } - - #[inline] - fn release(&self, target: Ref<'_, Self::Target>) -> Self::Data { - target.consume() - } -} - -/// A type implementing [`Context`] where the `Data` type is `T`, a type -/// implementing `From<OwnedFd>` and `From<T> for OwnedFd`. +/// `epoll_create1(flags)`—Creates a new `Epoll`. /// -/// This may be used with [`OwnedFd`], or higher-level types like -/// [`std::fs::File`] or [`std::net::TcpStream`]. -#[cfg(not(feature = "rustc-dep-of-std"))] -pub struct Owning<'context, T: Into<OwnedFd> + From<OwnedFd>> { - _phantom: PhantomData<&'context T>, +/// Use the [`CreateFlags::CLOEXEC`] flag to prevent the resulting file +/// descriptor from being implicitly passed across `exec` boundaries. +#[inline] +#[doc(alias = "epoll_create1")] +pub fn epoll_create(flags: CreateFlags) -> io::Result<OwnedFd> { + // SAFETY: We're calling `epoll_create1` via FFI and we know how it + // behaves. + unsafe { ret_owned_fd(c::epoll_create1(flags.bits())) } } -#[cfg(not(feature = "rustc-dep-of-std"))] -impl<'context, T: Into<OwnedFd> + From<OwnedFd>> Owning<'context, T> { - /// Creates a new empty `Owning`. - #[allow(clippy::new_without_default)] // This is a specialized type that doesn't need to be generically constructible. - #[inline] - pub fn new() -> Self { - Self { - _phantom: PhantomData, - } - } -} - -#[cfg(not(feature = "rustc-dep-of-std"))] -impl<'context, T: AsFd + Into<OwnedFd> + From<OwnedFd>> Context for Owning<'context, T> { - type Data = T; - type Target = BorrowedFd<'context>; - - #[inline] - fn acquire<'call>(&self, data: Self::Data) -> Ref<'call, Self::Target> { - let fd: OwnedFd = data.into(); - let raw_fd = fd.into_raw_fd(); - // Safety: `epoll` will assign ownership of the file descriptor to the - // kernel epoll object. We use `Into<OwnedFd>`+`IntoRawFd` to consume - // the `Data` and extract the raw file descriptor and then "borrow" it - // with `borrow_raw` knowing that the borrow won't outlive the - // kernel epoll object. - unsafe { Ref::new(BorrowedFd::<'context>::borrow_raw(raw_fd)) } - } - - #[inline] - fn encode(&self, target: Ref<'_, Self::Target>) -> u64 { - target.as_fd().as_raw_fd() as u64 - } - - #[inline] - unsafe fn decode<'call>(&self, raw: u64) -> Ref<'call, Self::Target> { - Ref::new(BorrowedFd::<'context>::borrow_raw(raw as RawFd)) - } - - #[inline] - fn release(&self, target: Ref<'_, Self::Target>) -> Self::Data { - // The file descriptor was held by the kernel epoll object and is now - // being released, so we can create a new `OwnedFd` that assumes - // ownership. - let raw_fd = target.consume().as_raw_fd(); - unsafe { T::from(OwnedFd::from_raw_fd(raw_fd).into()) } - } -} - -/// An "epoll", an interface to an OS object allowing one to repeatedly wait -/// for events from a set of file descriptors efficiently. -pub struct Epoll<Context: self::Context> { - epoll_fd: OwnedFd, - context: Context, -} - -impl<Context: self::Context> Epoll<Context> { - /// `epoll_create1(flags)`—Creates a new `Epoll`. - /// - /// Use the [`CreateFlags::CLOEXEC`] flag to prevent the resulting file - /// descriptor from being implicitly passed across `exec` boundaries. - #[inline] - #[doc(alias = "epoll_create1")] - pub fn new(flags: CreateFlags, context: Context) -> io::Result<Self> { - // Safety: We're calling `epoll_create1` via FFI and we know how it - // behaves. - unsafe { - Ok(Self { - epoll_fd: ret_owned_fd(c::epoll_create1(flags.bits()))?, - context, - }) - } - } - - /// `epoll_ctl(self, EPOLL_CTL_ADD, data, event)`—Adds an element to an - /// `Epoll`. - /// - /// This registers interest in any of the events set in `events` occurring - /// on the file descriptor associated with `data`. - #[doc(alias = "epoll_ctl")] - pub fn add( - &self, - data: Context::Data, - event_flags: EventFlags, - ) -> io::Result<Ref<'_, Context::Target>> { - // Safety: We're calling `epoll_ctl` via FFI and we know how it - // behaves. - unsafe { - let target = self.context.acquire(data); - let raw_fd = target.as_fd().as_raw_fd(); - let encoded = self.context.encode(target); - ret(c::epoll_ctl( - self.epoll_fd.as_fd().as_raw_fd(), - c::EPOLL_CTL_ADD, - raw_fd, - &mut c::epoll_event { - events: event_flags.bits(), - r#u64: encoded, - }, - ))?; - Ok(self.context.decode(encoded)) - } - } - - /// `epoll_ctl(self, EPOLL_CTL_MOD, target, event)`—Modifies an element in - /// this `Epoll`. - /// - /// This sets the events of interest with `target` to `events`. - #[doc(alias = "epoll_ctl")] - pub fn mod_( - &self, - target: Ref<'_, Context::Target>, - event_flags: EventFlags, - ) -> io::Result<()> { - let raw_fd = target.as_fd().as_raw_fd(); - let encoded = self.context.encode(target); - // Safety: We're calling `epoll_ctl` via FFI and we know how it - // behaves. - unsafe { - ret(c::epoll_ctl( - self.epoll_fd.as_fd().as_raw_fd(), - c::EPOLL_CTL_MOD, - raw_fd, - &mut c::epoll_event { - events: event_flags.bits(), - r#u64: encoded, - }, - )) - } - } - - /// `epoll_ctl(self, EPOLL_CTL_DEL, target, NULL)`—Removes an element in - /// this `Epoll`. - /// - /// This also returns the owning `Data`. - #[doc(alias = "epoll_ctl")] - pub fn del(&self, target: Ref<'_, Context::Target>) -> io::Result<Context::Data> { - // Safety: We're calling `epoll_ctl` via FFI and we know how it - // behaves. - unsafe { - let raw_fd = target.as_fd().as_raw_fd(); - ret(c::epoll_ctl( - self.epoll_fd.as_fd().as_raw_fd(), - c::EPOLL_CTL_DEL, - raw_fd, - null_mut(), - ))?; - } - Ok(self.context.release(target)) - } - - /// `epoll_wait(self, events, timeout)`—Waits for registered events of - /// interest. - /// - /// For each event of interest, an element is written to `events`. On - /// success, this returns the number of written elements. - #[doc(alias = "epoll_wait")] - pub fn wait<'context>( - &'context self, - event_list: &mut EventVec<'context, Context>, - timeout: c::c_int, - ) -> io::Result<()> { - // Safety: We're calling `epoll_wait` via FFI and we know how it - // behaves. - unsafe { - event_list.events.set_len(0); - let nfds = ret_u32(c::epoll_wait( - self.epoll_fd.as_fd().as_raw_fd(), - event_list.events.as_mut_ptr().cast::<c::epoll_event>(), - event_list.events.capacity().try_into().unwrap_or(i32::MAX), - timeout, - ))?; - event_list.events.set_len(nfds as usize); - event_list.context = &self.context; - } - - Ok(()) - } -} - -#[cfg(not(feature = "rustc-dep-of-std"))] -impl<'context, T: AsFd + Into<OwnedFd> + From<OwnedFd>> AsRawFd for Epoll<Owning<'context, T>> { - fn as_raw_fd(&self) -> RawFd { - self.epoll_fd.as_raw_fd() - } -} - -#[cfg(not(feature = "rustc-dep-of-std"))] -impl<'context, T: AsFd + Into<OwnedFd> + From<OwnedFd>> IntoRawFd for Epoll<Owning<'context, T>> { - fn into_raw_fd(self) -> RawFd { - self.epoll_fd.into_raw_fd() - } -} - -#[cfg(not(feature = "rustc-dep-of-std"))] -impl<'context, T: AsFd + Into<OwnedFd> + From<OwnedFd>> FromRawFd for Epoll<Owning<'context, T>> { - unsafe fn from_raw_fd(fd: RawFd) -> Self { - Self { - epoll_fd: OwnedFd::from_raw_fd(fd), - context: Owning::new(), - } +/// `epoll_ctl(self, EPOLL_CTL_ADD, data, event)`—Adds an element to an +/// `Epoll`. +/// +/// Note that if `epoll_del` is not called on the I/O source passed into +/// this function before the I/O source is `close`d, then the `epoll` will +/// act as if the I/O source is still registered with it. This can lead to +/// spurious events being returned from `epoll_wait`. If a file descriptor +/// is an `Arc<dyn SystemResource>`, then `epoll` can be thought to maintain +/// a `Weak<dyn SystemResource>` to the file descriptor. +#[doc(alias = "epoll_ctl")] +pub fn epoll_add( + epoll: impl AsFd, + source: impl AsFd, + data: u64, + event_flags: EventFlags, +) -> io::Result<()> { + // SAFETY: We're calling `epoll_ctl` via FFI and we know how it + // behaves. + unsafe { + let raw_fd = source.as_fd().as_raw_fd(); + ret(c::epoll_ctl( + epoll.as_fd().as_raw_fd(), + c::EPOLL_CTL_ADD, + raw_fd, + &mut c::epoll_event { + events: event_flags.bits(), + r#u64: data, + }, + )) } } -#[cfg(not(feature = "rustc-dep-of-std"))] -impl<'context, T: AsFd + Into<OwnedFd> + From<OwnedFd>> AsFd for Epoll<Owning<'context, T>> { - fn as_fd(&self) -> BorrowedFd<'_> { - self.epoll_fd.as_fd() +/// `epoll_ctl(self, EPOLL_CTL_MOD, target, event)`—Modifies an element in +/// this `Epoll`. +/// +/// This sets the events of interest with `target` to `events`. +#[doc(alias = "epoll_ctl")] +pub fn epoll_mod( + epoll: impl AsFd, + source: impl AsFd, + data: u64, + event_flags: EventFlags, +) -> io::Result<()> { + let raw_fd = source.as_fd().as_raw_fd(); + + // SAFETY: We're calling `epoll_ctl` via FFI and we know how it + // behaves. + unsafe { + ret(c::epoll_ctl( + epoll.as_fd().as_raw_fd(), + c::EPOLL_CTL_MOD, + raw_fd, + &mut c::epoll_event { + events: event_flags.bits(), + r#u64: data, + }, + )) } } -#[cfg(not(feature = "rustc-dep-of-std"))] -impl<'context, T: AsFd + Into<OwnedFd> + From<OwnedFd>> From<Epoll<Owning<'context, T>>> - for OwnedFd -{ - fn from(epoll: Epoll<Owning<'context, T>>) -> Self { - epoll.epoll_fd +/// `epoll_ctl(self, EPOLL_CTL_DEL, target, NULL)`—Removes an element in +/// this `Epoll`. +#[doc(alias = "epoll_ctl")] +pub fn epoll_del(epoll: impl AsFd, source: impl AsFd) -> io::Result<()> { + // SAFETY: We're calling `epoll_ctl` via FFI and we know how it + // behaves. + unsafe { + let raw_fd = source.as_fd().as_raw_fd(); + ret(c::epoll_ctl( + epoll.as_fd().as_raw_fd(), + c::EPOLL_CTL_DEL, + raw_fd, + null_mut(), + )) } } -#[cfg(not(feature = "rustc-dep-of-std"))] -impl<'context, T: AsFd + Into<OwnedFd> + From<OwnedFd>> From<OwnedFd> - for Epoll<Owning<'context, T>> -{ - fn from(fd: OwnedFd) -> Self { - Self { - epoll_fd: fd, - context: Owning::new(), - } - } +/// `epoll_wait(self, events, timeout)`—Waits for registered events of +/// interest. +/// +/// For each event of interest, an element is written to `events`. On +/// success, this returns the number of written elements. +pub fn epoll_wait( + epoll: impl AsFd, + event_list: &mut EventVec, + timeout: c::c_int, +) -> io::Result<()> { + // SAFETY: We're calling `epoll_wait` via FFI and we know how it + // behaves. + unsafe { + event_list.events.set_len(0); + let nfds = ret_u32(c::epoll_wait( + epoll.as_fd().as_raw_fd(), + event_list.events.as_mut_ptr().cast::<c::epoll_event>(), + event_list.events.capacity().try_into().unwrap_or(i32::MAX), + timeout, + ))?; + event_list.events.set_len(nfds as usize); + } + + Ok(()) } /// An iterator over the `Event`s in an `EventVec`. -pub struct Iter<'context, Context: self::Context> { - iter: core::slice::Iter<'context, Event>, - context: *const Context, - _phantom: PhantomData<&'context Context>, +pub struct Iter<'a> { + iter: core::slice::Iter<'a, Event>, } -impl<'context, Context: self::Context> Iterator for Iter<'context, Context> { - type Item = (EventFlags, Ref<'context, Context::Target>); +impl<'a> Iterator for Iter<'a> { + type Item = (EventFlags, u64); fn next(&mut self) -> Option<Self::Item> { - // Safety: `self.context` is guaranteed to be valid because we hold + // SAFETY: `self.context` is guaranteed to be valid because we hold // `'context` for it. And we know this event is associated with this // context because `wait` sets both. - self.iter.next().map(|event| { - (event.event_flags, unsafe { - (*self.context).decode(event.encoded) - }) - }) + self.iter + .next() + .map(|event| (event.event_flags, event.data)) } } @@ -485,27 +285,22 @@ impl<'context, Context: self::Context> Iterator for Iter<'context, Context> { )] struct Event { // Match the layout of `c::epoll_event`. We just use a `u64` instead of - // the full union; `Context` implementations will simply need to deal with - // casting the value into and out of the `u64` themselves. + // the full union. event_flags: EventFlags, - encoded: u64, + data: u64, } /// A vector of `Event`s, plus context for interpreting them. -pub struct EventVec<'context, Context: self::Context> { +pub struct EventVec { events: Vec<Event>, - context: *const Context, - _phantom: PhantomData<&'context Context>, } -impl<'context, Context: self::Context> EventVec<'context, Context> { +impl EventVec { /// Constructs an `EventVec` with memory for `capacity` `Event`s. #[inline] pub fn with_capacity(capacity: usize) -> Self { Self { events: Vec::with_capacity(capacity), - context: null(), - _phantom: PhantomData, } } @@ -541,11 +336,9 @@ impl<'context, Context: self::Context> EventVec<'context, Context> { /// Returns an iterator over the `Event`s in this `EventVec`. #[inline] - pub fn iter(&self) -> Iter<'_, Context> { + pub fn iter(&self) -> Iter<'_> { Iter { iter: self.events.iter(), - context: self.context, - _phantom: PhantomData, } } @@ -562,9 +355,9 @@ impl<'context, Context: self::Context> EventVec<'context, Context> { } } -impl<'context, Context: self::Context> IntoIterator for &'context EventVec<'context, Context> { - type IntoIter = Iter<'context, Context>; - type Item = (EventFlags, Ref<'context, Context::Target>); +impl<'a> IntoIterator for &'a EventVec { + type IntoIter = Iter<'a>; + type Item = (EventFlags, u64); #[inline] fn into_iter(self) -> Self::IntoIter { diff --git a/vendor/rustix/src/backend/libc/io/errno.rs b/vendor/rustix/src/backend/libc/io/errno.rs index 25323771c..9e808c0b4 100644 --- a/vendor/rustix/src/backend/libc/io/errno.rs +++ b/vendor/rustix/src/backend/libc/io/errno.rs @@ -25,15 +25,10 @@ impl Errno { pub const ADDRNOTAVAIL: Self = Self(c::EADDRNOTAVAIL); /// `EADV` #[cfg(not(any( + bsd, windows, target_os = "aix", - target_os = "dragonfly", - target_os = "freebsd", target_os = "haiku", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", target_os = "wasi", )))] pub const ADV: Self = Self(c::EADV); @@ -44,26 +39,14 @@ impl Errno { /// `EALREADY` pub const ALREADY: Self = Self(c::EALREADY); /// `EAUTH` - #[cfg(any( - target_os = "dragonfly", - target_os = "freebsd", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", - ))] + #[cfg(bsd)] pub const AUTH: Self = Self(c::EAUTH); /// `EBADE` #[cfg(not(any( + bsd, windows, target_os = "aix", - target_os = "dragonfly", - target_os = "freebsd", target_os = "haiku", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", target_os = "wasi", )))] pub const BADE: Self = Self(c::EBADE); @@ -71,15 +54,10 @@ impl Errno { pub const BADF: Self = Self(c::EBADF); /// `EBADFD` #[cfg(not(any( + bsd, windows, target_os = "aix", - target_os = "dragonfly", - target_os = "freebsd", target_os = "haiku", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", target_os = "wasi", )))] pub const BADFD: Self = Self(c::EBADFD); @@ -88,67 +66,40 @@ impl Errno { pub const BADMSG: Self = Self(c::EBADMSG); /// `EBADR` #[cfg(not(any( + bsd, windows, target_os = "aix", - target_os = "dragonfly", - target_os = "freebsd", target_os = "haiku", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", target_os = "wasi", )))] pub const BADR: Self = Self(c::EBADR); /// `EBADRPC` - #[cfg(any( - target_os = "dragonfly", - target_os = "freebsd", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", - ))] + #[cfg(bsd)] pub const BADRPC: Self = Self(c::EBADRPC); /// `EBADRQC` #[cfg(not(any( + bsd, windows, target_os = "aix", - target_os = "dragonfly", - target_os = "freebsd", target_os = "haiku", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", target_os = "wasi", )))] pub const BADRQC: Self = Self(c::EBADRQC); /// `EBADSLT` #[cfg(not(any( + bsd, windows, target_os = "aix", - target_os = "dragonfly", - target_os = "freebsd", target_os = "haiku", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", target_os = "wasi", )))] pub const BADSLT: Self = Self(c::EBADSLT); /// `EBFONT` #[cfg(not(any( + bsd, windows, target_os = "aix", - target_os = "dragonfly", - target_os = "freebsd", target_os = "haiku", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", target_os = "wasi", )))] pub const BFONT: Self = Self(c::EBFONT); @@ -164,29 +115,14 @@ impl Errno { #[cfg(not(windows))] pub const CHILD: Self = Self(c::ECHILD); /// `ECHRNG` - #[cfg(not(any( - windows, - target_os = "dragonfly", - target_os = "freebsd", - target_os = "haiku", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", - target_os = "wasi", - )))] + #[cfg(not(any(bsd, windows, target_os = "haiku", target_os = "wasi")))] pub const CHRNG: Self = Self(c::ECHRNG); /// `ECOMM` #[cfg(not(any( + bsd, windows, target_os = "aix", - target_os = "dragonfly", - target_os = "freebsd", target_os = "haiku", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", target_os = "wasi", )))] pub const COMM: Self = Self(c::ECOMM); @@ -201,16 +137,11 @@ impl Errno { pub const DEADLK: Self = Self(c::EDEADLK); /// `EDEADLOCK` #[cfg(not(any( + bsd, windows, target_os = "aix", target_os = "android", - target_os = "dragonfly", - target_os = "freebsd", target_os = "haiku", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", target_os = "wasi", )))] pub const DEADLOCK: Self = Self(c::EDEADLOCK); @@ -223,21 +154,15 @@ impl Errno { #[cfg(not(windows))] pub const DOM: Self = Self(c::EDOM); /// `EDOOFUS` - #[cfg(any(target_os = "dragonfly", target_os = "freebsd"))] + #[cfg(freebsdlike)] pub const DOOFUS: Self = Self(c::EDOOFUS); /// `EDOTDOT` #[cfg(not(any( + bsd, + solarish, windows, target_os = "aix", - target_os = "dragonfly", - target_os = "freebsd", target_os = "haiku", - target_os = "illumos", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", - target_os = "solaris", target_os = "wasi", )))] pub const DOTDOT: Self = Self(c::EDOTDOT); @@ -252,15 +177,7 @@ impl Errno { #[cfg(not(windows))] pub const FBIG: Self = Self(c::EFBIG); /// `EFTYPE` - #[cfg(any( - target_env = "newlib", - target_os = "dragonfly", - target_os = "freebsd", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", - ))] + #[cfg(any(bsd, target_env = "newlib"))] pub const FTYPE: Self = Self(c::EFTYPE); /// `EHOSTDOWN` #[cfg(not(target_os = "wasi"))] @@ -269,19 +186,13 @@ impl Errno { pub const HOSTUNREACH: Self = Self(c::EHOSTUNREACH); /// `EHWPOISON` #[cfg(not(any( + bsd, + solarish, windows, target_os = "aix", target_os = "android", - target_os = "dragonfly", - target_os = "freebsd", target_os = "haiku", - target_os = "illumos", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", target_os = "redox", - target_os = "solaris", target_os = "wasi", )))] pub const HWPOISON: Self = Self(c::EHWPOISON); @@ -318,218 +229,113 @@ impl Errno { pub const ISDIR: Self = Self(c::EISDIR); /// `EISNAM` #[cfg(not(any( + bsd, + solarish, windows, target_os = "aix", - target_os = "dragonfly", - target_os = "freebsd", target_os = "haiku", - target_os = "illumos", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", - target_os = "solaris", target_os = "wasi", )))] pub const ISNAM: Self = Self(c::EISNAM); /// `EKEYEXPIRED` #[cfg(not(any( + bsd, + solarish, windows, target_os = "aix", - target_os = "dragonfly", - target_os = "freebsd", target_os = "haiku", - target_os = "illumos", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", - target_os = "solaris", target_os = "wasi", )))] pub const KEYEXPIRED: Self = Self(c::EKEYEXPIRED); /// `EKEYREJECTED` #[cfg(not(any( + bsd, + solarish, windows, target_os = "aix", - target_os = "dragonfly", - target_os = "freebsd", target_os = "haiku", - target_os = "illumos", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", - target_os = "solaris", target_os = "wasi", )))] pub const KEYREJECTED: Self = Self(c::EKEYREJECTED); /// `EKEYREVOKED` #[cfg(not(any( + bsd, + solarish, windows, target_os = "aix", - target_os = "dragonfly", - target_os = "freebsd", target_os = "haiku", - target_os = "illumos", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", - target_os = "solaris", target_os = "wasi", )))] pub const KEYREVOKED: Self = Self(c::EKEYREVOKED); /// `EL2HLT` - #[cfg(not(any( - windows, - target_os = "dragonfly", - target_os = "freebsd", - target_os = "haiku", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", - target_os = "wasi", - )))] + #[cfg(not(any(bsd, windows, target_os = "haiku", target_os = "wasi")))] pub const L2HLT: Self = Self(c::EL2HLT); /// `EL2NSYNC` - #[cfg(not(any( - windows, - target_os = "dragonfly", - target_os = "freebsd", - target_os = "haiku", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", - target_os = "wasi", - )))] + #[cfg(not(any(bsd, windows, target_os = "haiku", target_os = "wasi")))] pub const L2NSYNC: Self = Self(c::EL2NSYNC); /// `EL3HLT` - #[cfg(not(any( - windows, - target_os = "dragonfly", - target_os = "freebsd", - target_os = "haiku", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", - target_os = "wasi", - )))] + #[cfg(not(any(bsd, windows, target_os = "haiku", target_os = "wasi")))] pub const L3HLT: Self = Self(c::EL3HLT); /// `EL3RST` - #[cfg(not(any( - windows, - target_os = "dragonfly", - target_os = "freebsd", - target_os = "haiku", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", - target_os = "wasi", - )))] + #[cfg(not(any(bsd, windows, target_os = "haiku", target_os = "wasi")))] pub const L3RST: Self = Self(c::EL3RST); /// `ELIBACC` #[cfg(not(any( + bsd, windows, target_os = "aix", - target_os = "dragonfly", - target_os = "freebsd", target_os = "haiku", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", target_os = "wasi", )))] pub const LIBACC: Self = Self(c::ELIBACC); /// `ELIBBAD` #[cfg(not(any( + bsd, windows, target_os = "aix", - target_os = "dragonfly", - target_os = "freebsd", target_os = "haiku", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", target_os = "wasi", )))] pub const LIBBAD: Self = Self(c::ELIBBAD); /// `ELIBEXEC` #[cfg(not(any( + bsd, windows, target_os = "aix", - target_os = "dragonfly", - target_os = "freebsd", target_os = "haiku", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", target_os = "wasi", )))] pub const LIBEXEC: Self = Self(c::ELIBEXEC); /// `ELIBMAX` #[cfg(not(any( + bsd, windows, target_os = "aix", - target_os = "dragonfly", - target_os = "freebsd", target_os = "haiku", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", target_os = "wasi", )))] pub const LIBMAX: Self = Self(c::ELIBMAX); /// `ELIBSCN` #[cfg(not(any( + bsd, windows, target_os = "aix", - target_os = "dragonfly", - target_os = "freebsd", target_os = "haiku", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", target_os = "wasi", )))] pub const LIBSCN: Self = Self(c::ELIBSCN); /// `ELNRNG` - #[cfg(not(any( - windows, - target_os = "dragonfly", - target_os = "freebsd", - target_os = "haiku", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", - target_os = "wasi", - )))] + #[cfg(not(any(bsd, windows, target_os = "haiku", target_os = "wasi")))] pub const LNRNG: Self = Self(c::ELNRNG); /// `ELOOP` pub const LOOP: Self = Self(c::ELOOP); /// `EMEDIUMTYPE` #[cfg(not(any( + bsd, + solarish, windows, target_os = "aix", - target_os = "dragonfly", - target_os = "freebsd", target_os = "haiku", - target_os = "illumos", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", - target_os = "solaris", target_os = "wasi", )))] pub const MEDIUMTYPE: Self = Self(c::EMEDIUMTYPE); @@ -547,29 +353,16 @@ impl Errno { pub const NAMETOOLONG: Self = Self(c::ENAMETOOLONG); /// `ENAVAIL` #[cfg(not(any( + bsd, + solarish, windows, target_os = "aix", - target_os = "dragonfly", - target_os = "freebsd", target_os = "haiku", - target_os = "illumos", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", - target_os = "solaris", target_os = "wasi", )))] pub const NAVAIL: Self = Self(c::ENAVAIL); /// `ENEEDAUTH` - #[cfg(any( - target_os = "dragonfly", - target_os = "freebsd", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", - ))] + #[cfg(bsd)] pub const NEEDAUTH: Self = Self(c::ENEEDAUTH); /// `ENETDOWN` pub const NETDOWN: Self = Self(c::ENETDOWN); @@ -582,49 +375,25 @@ impl Errno { pub const NFILE: Self = Self(c::ENFILE); /// `ENOANO` #[cfg(not(any( + bsd, windows, target_os = "aix", - target_os = "dragonfly", - target_os = "freebsd", target_os = "haiku", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", target_os = "wasi", )))] pub const NOANO: Self = Self(c::ENOANO); /// `ENOATTR` - #[cfg(any( - target_os = "dragonfly", - target_os = "freebsd", - target_os = "haiku", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", - ))] + #[cfg(any(bsd, target_os = "haiku"))] pub const NOATTR: Self = Self(c::ENOATTR); /// `ENOBUFS` pub const NOBUFS: Self = Self(c::ENOBUFS); /// `ENOCSI` - #[cfg(not(any( - windows, - target_os = "dragonfly", - target_os = "freebsd", - target_os = "haiku", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", - target_os = "wasi", - )))] + #[cfg(not(any(bsd, windows, target_os = "haiku", target_os = "wasi")))] pub const NOCSI: Self = Self(c::ENOCSI); /// `ENODATA` #[cfg(not(any( + freebsdlike, windows, - target_os = "dragonfly", - target_os = "freebsd", target_os = "haiku", target_os = "openbsd", target_os = "wasi", @@ -641,17 +410,11 @@ impl Errno { pub const NOEXEC: Self = Self(c::ENOEXEC); /// `ENOKEY` #[cfg(not(any( + solarish, + bsd, windows, target_os = "aix", - target_os = "dragonfly", - target_os = "freebsd", target_os = "haiku", - target_os = "illumos", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", - target_os = "solaris", target_os = "wasi", )))] pub const NOKEY: Self = Self(c::ENOKEY); @@ -663,17 +426,11 @@ impl Errno { pub const NOLINK: Self = Self(c::ENOLINK); /// `ENOMEDIUM` #[cfg(not(any( + bsd, + solarish, windows, target_os = "aix", - target_os = "dragonfly", - target_os = "freebsd", target_os = "haiku", - target_os = "illumos", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", - target_os = "solaris", target_os = "wasi", )))] pub const NOMEDIUM: Self = Self(c::ENOMEDIUM); @@ -688,29 +445,19 @@ impl Errno { pub const NOMSG: Self = Self(c::ENOMSG); /// `ENONET` #[cfg(not(any( + bsd, windows, target_os = "aix", - target_os = "dragonfly", - target_os = "freebsd", target_os = "haiku", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", target_os = "wasi", )))] pub const NONET: Self = Self(c::ENONET); /// `ENOPKG` #[cfg(not(any( + bsd, windows, target_os = "aix", - target_os = "dragonfly", - target_os = "freebsd", target_os = "haiku", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", target_os = "wasi", )))] pub const NOPKG: Self = Self(c::ENOPKG); @@ -721,9 +468,8 @@ impl Errno { pub const NOSPC: Self = Self(c::ENOSPC); /// `ENOSR` #[cfg(not(any( + freebsdlike, windows, - target_os = "dragonfly", - target_os = "freebsd", target_os = "haiku", target_os = "openbsd", target_os = "wasi", @@ -731,9 +477,8 @@ impl Errno { pub const NOSR: Self = Self(c::ENOSR); /// `ENOSTR` #[cfg(not(any( + freebsdlike, windows, - target_os = "dragonfly", - target_os = "freebsd", target_os = "haiku", target_os = "openbsd", target_os = "wasi", @@ -757,27 +502,16 @@ impl Errno { pub const NOTEMPTY: Self = Self(c::ENOTEMPTY); /// `ENOTNAM` #[cfg(not(any( + bsd, + solarish, windows, target_os = "aix", - target_os = "dragonfly", - target_os = "freebsd", target_os = "haiku", - target_os = "illumos", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", - target_os = "solaris", target_os = "wasi", )))] pub const NOTNAM: Self = Self(c::ENOTNAM); /// `ENOTRECOVERABLE` - #[cfg(not(any( - windows, - target_os = "dragonfly", - target_os = "haiku", - target_os = "netbsd" - )))] + #[cfg(not(any(freebsdlike, netbsdlike, windows, target_os = "haiku")))] pub const NOTRECOVERABLE: Self = Self(c::ENOTRECOVERABLE); /// `ENOTSOCK` pub const NOTSOCK: Self = Self(c::ENOTSOCK); @@ -789,15 +523,10 @@ impl Errno { pub const NOTTY: Self = Self(c::ENOTTY); /// `ENOTUNIQ` #[cfg(not(any( + bsd, windows, target_os = "aix", - target_os = "dragonfly", - target_os = "freebsd", target_os = "haiku", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", target_os = "wasi", )))] pub const NOTUNIQ: Self = Self(c::ENOTUNIQ); @@ -810,12 +539,7 @@ impl Errno { #[cfg(not(windows))] pub const OVERFLOW: Self = Self(c::EOVERFLOW); /// `EOWNERDEAD` - #[cfg(not(any( - windows, - target_os = "haiku", - target_os = "dragonfly", - target_os = "netbsd" - )))] + #[cfg(not(any(freebsdlike, netbsdlike, windows, target_os = "haiku")))] pub const OWNERDEAD: Self = Self(c::EOWNERDEAD); /// `EPERM` #[cfg(not(windows))] @@ -827,44 +551,16 @@ impl Errno { #[cfg(not(windows))] pub const PIPE: Self = Self(c::EPIPE); /// `EPROCLIM` - #[cfg(any( - target_os = "dragonfly", - target_os = "freebsd", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", - ))] + #[cfg(bsd)] pub const PROCLIM: Self = Self(c::EPROCLIM); /// `EPROCUNAVAIL` - #[cfg(any( - target_os = "dragonfly", - target_os = "freebsd", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", - ))] + #[cfg(bsd)] pub const PROCUNAVAIL: Self = Self(c::EPROCUNAVAIL); /// `EPROGMISMATCH` - #[cfg(any( - target_os = "dragonfly", - target_os = "freebsd", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", - ))] + #[cfg(bsd)] pub const PROGMISMATCH: Self = Self(c::EPROGMISMATCH); /// `EPROGUNAVAIL` - #[cfg(any( - target_os = "dragonfly", - target_os = "freebsd", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", - ))] + #[cfg(bsd)] pub const PROGUNAVAIL: Self = Self(c::EPROGUNAVAIL); /// `EPROTO` #[cfg(not(windows))] @@ -884,15 +580,10 @@ impl Errno { pub const REFUSED: Self = Self(c::EREFUSED); /// `EREMCHG` #[cfg(not(any( + bsd, windows, target_os = "aix", - target_os = "dragonfly", - target_os = "freebsd", target_os = "haiku", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", target_os = "wasi", )))] pub const REMCHG: Self = Self(c::EREMCHG); @@ -901,48 +592,26 @@ impl Errno { pub const REMOTE: Self = Self(c::EREMOTE); /// `EREMOTEIO` #[cfg(not(any( + bsd, + solarish, windows, target_os = "aix", - target_os = "dragonfly", - target_os = "freebsd", target_os = "haiku", - target_os = "illumos", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", - target_os = "solaris", target_os = "wasi", )))] pub const REMOTEIO: Self = Self(c::EREMOTEIO); /// `ERESTART` - #[cfg(not(any( - windows, - target_os = "dragonfly", - target_os = "freebsd", - target_os = "haiku", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", - target_os = "wasi", - )))] + #[cfg(not(any(bsd, windows, target_os = "haiku", target_os = "wasi")))] pub const RESTART: Self = Self(c::ERESTART); /// `ERFKILL` #[cfg(not(any( + bsd, + solarish, windows, target_os = "aix", target_os = "android", - target_os = "dragonfly", - target_os = "freebsd", target_os = "haiku", - target_os = "illumos", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", target_os = "redox", - target_os = "solaris", target_os = "wasi", )))] pub const RFKILL: Self = Self(c::ERFKILL); @@ -950,14 +619,7 @@ impl Errno { #[cfg(not(windows))] pub const ROFS: Self = Self(c::EROFS); /// `ERPCMISMATCH` - #[cfg(any( - target_os = "dragonfly", - target_os = "freebsd", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", - ))] + #[cfg(bsd)] pub const RPCMISMATCH: Self = Self(c::ERPCMISMATCH); /// `ESHUTDOWN` #[cfg(not(target_os = "wasi"))] @@ -973,15 +635,10 @@ impl Errno { pub const SRCH: Self = Self(c::ESRCH); /// `ESRMNT` #[cfg(not(any( + bsd, windows, target_os = "aix", - target_os = "dragonfly", - target_os = "freebsd", target_os = "haiku", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", target_os = "wasi", )))] pub const SRMNT: Self = Self(c::ESRMNT); @@ -989,26 +646,15 @@ impl Errno { pub const STALE: Self = Self(c::ESTALE); /// `ESTRPIPE` #[cfg(not(any( + bsd, windows, target_os = "aix", - target_os = "dragonfly", - target_os = "freebsd", target_os = "haiku", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", target_os = "wasi", )))] pub const STRPIPE: Self = Self(c::ESTRPIPE); /// `ETIME` - #[cfg(not(any( - windows, - target_os = "dragonfly", - target_os = "freebsd", - target_os = "openbsd", - target_os = "wasi", - )))] + #[cfg(not(any(freebsdlike, windows, target_os = "openbsd", target_os = "wasi")))] pub const TIME: Self = Self(c::ETIME); /// `ETIMEDOUT` pub const TIMEDOUT: Self = Self(c::ETIMEDOUT); @@ -1024,32 +670,16 @@ impl Errno { pub const TXTBSY: Self = Self(c::ETXTBSY); /// `EUCLEAN` #[cfg(not(any( + bsd, + solarish, windows, target_os = "aix", - target_os = "dragonfly", - target_os = "freebsd", target_os = "haiku", - target_os = "illumos", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", - target_os = "solaris", target_os = "wasi", )))] pub const UCLEAN: Self = Self(c::EUCLEAN); /// `EUNATCH` - #[cfg(not(any( - windows, - target_os = "dragonfly", - target_os = "freebsd", - target_os = "haiku", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", - target_os = "wasi", - )))] + #[cfg(not(any(bsd, windows, target_os = "haiku", target_os = "wasi")))] pub const UNATCH: Self = Self(c::EUNATCH); /// `EUSERS` #[cfg(not(any(target_os = "haiku", target_os = "wasi")))] @@ -1061,15 +691,10 @@ impl Errno { pub const XDEV: Self = Self(c::EXDEV); /// `EXFULL` #[cfg(not(any( + bsd, windows, target_os = "aix", - target_os = "dragonfly", - target_os = "freebsd", target_os = "haiku", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", target_os = "wasi", )))] pub const XFULL: Self = Self(c::EXFULL); diff --git a/vendor/rustix/src/backend/libc/io/poll_fd.rs b/vendor/rustix/src/backend/libc/io/poll_fd.rs index c516a9309..a0568c60a 100644 --- a/vendor/rustix/src/backend/libc/io/poll_fd.rs +++ b/vendor/rustix/src/backend/libc/io/poll_fd.rs @@ -119,7 +119,7 @@ impl<'fd> PollFd<'fd> { impl<'fd> AsFd for PollFd<'fd> { #[inline] fn as_fd(&self) -> BorrowedFd<'_> { - // Safety: Our constructors and `set_fd` require `pollfd.fd` to be + // SAFETY: Our constructors and `set_fd` require `pollfd.fd` to be // valid for the `fd lifetime. unsafe { BorrowedFd::borrow_raw(self.pollfd.fd) } } @@ -129,7 +129,7 @@ impl<'fd> AsFd for PollFd<'fd> { impl<'fd> io_lifetimes::AsSocket for PollFd<'fd> { #[inline] fn as_socket(&self) -> BorrowedFd<'_> { - // Safety: Our constructors and `set_fd` require `pollfd.fd` to be + // SAFETY: Our constructors and `set_fd` require `pollfd.fd` to be // valid for the `fd lifetime. unsafe { BorrowedFd::borrow_raw(self.pollfd.fd as RawFd) } } diff --git a/vendor/rustix/src/backend/libc/io/syscalls.rs b/vendor/rustix/src/backend/libc/io/syscalls.rs index 3774e700a..03f9294d9 100644 --- a/vendor/rustix/src/backend/libc/io/syscalls.rs +++ b/vendor/rustix/src/backend/libc/io/syscalls.rs @@ -12,15 +12,13 @@ use super::super::offset::{libc_preadv, libc_pwritev}; #[cfg(all(target_os = "linux", target_env = "gnu"))] use super::super::offset::{libc_preadv2, libc_pwritev2}; use crate::fd::{AsFd, BorrowedFd, OwnedFd, RawFd}; +#[cfg(bsd)] +use crate::io::kqueue::Event; +#[cfg(solarish)] +use crate::io::port::Event; #[cfg(not(any(target_os = "aix", target_os = "wasi")))] use crate::io::DupFlags; -#[cfg(not(any( - target_os = "aix", - target_os = "haiku", - target_os = "ios", - target_os = "macos", - target_os = "wasi" -)))] +#[cfg(not(any(apple, target_os = "aix", target_os = "haiku", target_os = "wasi")))] use crate::io::PipeFlags; use crate::io::{self, FdFlags, IoSlice, IoSliceMut, PollFd}; #[cfg(any(target_os = "android", target_os = "linux"))] @@ -167,7 +165,7 @@ pub(crate) fn preadv2( } /// At present, `libc` only has `preadv2` defined for glibc. On other -/// ABIs, `ReadWriteFlags` has no flags defined, and we use plain `preadv`. +/// ABIs, use `libc::syscall`. #[cfg(any( target_os = "android", all(target_os = "linux", not(target_env = "gnu")), @@ -179,8 +177,19 @@ pub(crate) fn preadv2( offset: u64, flags: ReadWriteFlags, ) -> io::Result<usize> { - assert!(flags.is_empty()); - preadv(fd, bufs, offset) + // Silently cast; we'll get `EINVAL` if the value is negative. + let offset = offset as i64; + let nread = unsafe { + ret_ssize_t(libc::syscall( + libc::SYS_preadv2, + borrowed_fd(fd), + bufs.as_ptr().cast::<c::iovec>(), + min(bufs.len(), max_iov()) as c::c_int, + offset, + flags.bits(), + ) as c::ssize_t)? + }; + Ok(nread as usize) } #[cfg(all(target_os = "linux", target_env = "gnu"))] @@ -205,7 +214,7 @@ pub(crate) fn pwritev2( } /// At present, `libc` only has `pwritev2` defined for glibc. On other -/// ABIs, `ReadWriteFlags` has no flags defined, and we use plain `pwritev`. +/// ABIs, use `libc::syscall`. #[cfg(any( target_os = "android", all(target_os = "linux", not(target_env = "gnu")), @@ -217,12 +226,23 @@ pub(crate) fn pwritev2( offset: u64, flags: ReadWriteFlags, ) -> io::Result<usize> { - assert!(flags.is_empty()); - pwritev(fd, bufs, offset) + // Silently cast; we'll get `EINVAL` if the value is negative. + let offset = offset as i64; + let nwritten = unsafe { + ret_ssize_t(libc::syscall( + libc::SYS_pwritev2, + borrowed_fd(fd), + bufs.as_ptr().cast::<c::iovec>(), + min(bufs.len(), max_iov()) as c::c_int, + offset, + flags.bits(), + ) as c::ssize_t)? + }; + Ok(nwritten as usize) } // These functions are derived from Rust's library/std/src/sys/unix/fd.rs at -// revision a77da2d454e6caa227a85b16410b95f93495e7e0. +// revision 326ef470a8b379a180d6dc4bbef08990698a737a. // The maximum read limit on most POSIX-like systems is `SSIZE_MAX`, with the // man page quoting that if the count of bytes to read is greater than @@ -237,33 +257,28 @@ const READ_LIMIT: usize = c::c_int::MAX as usize - 1; #[cfg(not(target_os = "macos"))] const READ_LIMIT: usize = c::ssize_t::MAX as usize; -#[cfg(any( - target_os = "dragonfly", - target_os = "freebsd", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", -))] +#[cfg(bsd)] const fn max_iov() -> usize { c::IOV_MAX as usize } -#[cfg(any(target_os = "android", target_os = "emscripten", target_os = "linux"))] +#[cfg(any( + target_os = "android", + target_os = "emscripten", + target_os = "linux", + target_os = "nto" +))] const fn max_iov() -> usize { c::UIO_MAXIOV as usize } #[cfg(not(any( + bsd, target_os = "android", - target_os = "dragonfly", target_os = "emscripten", - target_os = "freebsd", - target_os = "ios", target_os = "linux", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", + target_os = "nto", + target_os = "horizon", )))] const fn max_iov() -> usize { 16 // The minimum value required by POSIX. @@ -321,6 +336,33 @@ pub(crate) fn ioctl_fionbio(fd: BorrowedFd<'_>, value: bool) -> io::Result<()> { } } +#[cfg(any(target_os = "android", target_os = "linux"))] +pub(crate) fn ioctl_ficlone(fd: BorrowedFd<'_>, src_fd: BorrowedFd<'_>) -> io::Result<()> { + // TODO: Enable `ioctl_ficlone` for android when upstream is updated. + // TODO: Enable `ioctl_ficlone` for more architectures when upstream is + // updated. + #[cfg(all( + target_os = "linux", + any(target_arch = "x86", target_arch = "x86_64", target_arch = "aarch64") + ))] + unsafe { + ret(c::ioctl( + borrowed_fd(fd), + c::FICLONE as _, + borrowed_fd(src_fd), + )) + } + #[cfg(not(all( + target_os = "linux", + any(target_arch = "x86", target_arch = "x86_64", target_arch = "aarch64") + )))] + { + let _ = fd; + let _ = src_fd; + Err(io::Errno::NOSYS) + } +} + #[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)> { @@ -398,12 +440,11 @@ pub(crate) fn dup2(fd: BorrowedFd<'_>, new: &mut OwnedFd) -> io::Result<()> { } #[cfg(not(any( + apple, target_os = "aix", target_os = "android", target_os = "dragonfly", target_os = "haiku", - target_os = "ios", - target_os = "macos", target_os = "redox", target_os = "wasi", )))] @@ -418,11 +459,10 @@ pub(crate) fn dup3(fd: BorrowedFd<'_>, new: &mut OwnedFd, flags: DupFlags) -> io } #[cfg(any( + apple, target_os = "android", target_os = "dragonfly", target_os = "haiku", - target_os = "ios", - target_os = "macos", target_os = "redox", ))] pub(crate) fn dup3(fd: BorrowedFd<'_>, new: &mut OwnedFd, _flags: DupFlags) -> io::Result<()> { @@ -433,7 +473,7 @@ pub(crate) fn dup3(fd: BorrowedFd<'_>, new: &mut OwnedFd, _flags: DupFlags) -> i dup2(fd, new) } -#[cfg(any(target_os = "ios", target_os = "macos"))] +#[cfg(apple)] pub(crate) fn ioctl_fioclex(fd: BorrowedFd<'_>) -> io::Result<()> { unsafe { ret(c::ioctl(borrowed_fd(fd), c::FIOCLEX)) } } @@ -448,6 +488,34 @@ pub(crate) fn ioctl_tiocnxcl(fd: BorrowedFd) -> io::Result<()> { unsafe { ret(c::ioctl(borrowed_fd(fd), c::TIOCNXCL as _)) } } +#[cfg(bsd)] +pub(crate) fn kqueue() -> io::Result<OwnedFd> { + unsafe { ret_owned_fd(c::kqueue()) } +} + +#[cfg(bsd)] +pub(crate) unsafe fn kevent( + kq: BorrowedFd<'_>, + changelist: &[Event], + eventlist: &mut [MaybeUninit<Event>], + timeout: Option<&c::timespec>, +) -> io::Result<c::c_int> { + ret_c_int(c::kevent( + borrowed_fd(kq), + changelist.as_ptr() as *const _, + changelist + .len() + .try_into() + .map_err(|_| io::Errno::OVERFLOW)?, + eventlist.as_mut_ptr() as *mut _, + eventlist + .len() + .try_into() + .map_err(|_| io::Errno::OVERFLOW)?, + timeout.map_or(core::ptr::null(), |t| t as *const _), + )) +} + #[cfg(not(target_os = "wasi"))] pub(crate) fn pipe() -> io::Result<(OwnedFd, OwnedFd)> { unsafe { @@ -458,13 +526,7 @@ pub(crate) fn pipe() -> io::Result<(OwnedFd, OwnedFd)> { } } -#[cfg(not(any( - target_os = "aix", - target_os = "haiku", - target_os = "ios", - target_os = "macos", - target_os = "wasi" -)))] +#[cfg(not(any(apple, target_os = "aix", target_os = "haiku", target_os = "wasi")))] pub(crate) fn pipe_with(flags: PipeFlags) -> io::Result<(OwnedFd, OwnedFd)> { unsafe { let mut result = MaybeUninit::<[OwnedFd; 2]>::uninit(); @@ -531,3 +593,85 @@ pub unsafe fn vmsplice( )) .map(|spliced| spliced as usize) } + +#[cfg(solarish)] +pub(crate) fn port_create() -> io::Result<OwnedFd> { + unsafe { ret_owned_fd(c::port_create()) } +} + +#[cfg(solarish)] +pub(crate) unsafe fn port_associate( + port: BorrowedFd<'_>, + source: c::c_int, + object: c::uintptr_t, + events: c::c_int, + user: *mut c::c_void, +) -> io::Result<()> { + ret(c::port_associate( + borrowed_fd(port), + source, + object, + events, + user, + )) +} + +#[cfg(solarish)] +pub(crate) unsafe fn port_dissociate( + port: BorrowedFd<'_>, + source: c::c_int, + object: c::uintptr_t, +) -> io::Result<()> { + ret(c::port_dissociate(borrowed_fd(port), source, object)) +} + +#[cfg(solarish)] +pub(crate) fn port_get( + port: BorrowedFd<'_>, + timeout: Option<&mut c::timespec>, +) -> io::Result<Event> { + let mut event = MaybeUninit::<c::port_event>::uninit(); + let timeout = timeout.map_or(core::ptr::null_mut(), |t| t as *mut _); + + unsafe { + ret(c::port_get(borrowed_fd(port), event.as_mut_ptr(), timeout))?; + } + + // If we're done, initialize the event and return it. + Ok(Event(unsafe { event.assume_init() })) +} + +#[cfg(solarish)] +pub(crate) fn port_getn( + port: BorrowedFd<'_>, + timeout: Option<&mut c::timespec>, + events: &mut Vec<Event>, + mut nget: u32, +) -> io::Result<()> { + let timeout = timeout.map_or(core::ptr::null_mut(), |t| t as *mut _); + unsafe { + ret(c::port_getn( + borrowed_fd(port), + events.as_mut_ptr().cast(), + events.len().try_into().unwrap(), + &mut nget, + timeout, + ))?; + } + + // Update the vector length. + unsafe { + events.set_len(nget.try_into().unwrap()); + } + + Ok(()) +} + +#[cfg(solarish)] +pub(crate) fn port_send( + port: BorrowedFd<'_>, + events: c::c_int, + userdata: *mut c::c_void, +) -> io::Result<()> { + unsafe { ret(c::port_send(borrowed_fd(port), events, userdata)) } +} diff --git a/vendor/rustix/src/backend/libc/io/types.rs b/vendor/rustix/src/backend/libc/io/types.rs index 46d5f6332..cbdd734b9 100644 --- a/vendor/rustix/src/backend/libc/io/types.rs +++ b/vendor/rustix/src/backend/libc/io/types.rs @@ -22,20 +22,15 @@ bitflags! { /// [`pwritev2`]: crate::io::pwritev pub struct ReadWriteFlags: c::c_int { /// `RWF_DSYNC` (since Linux 4.7) - #[cfg(all(target_os = "linux", target_env = "gnu"))] - const DSYNC = c::RWF_DSYNC; + const DSYNC = linux_raw_sys::general::RWF_DSYNC as c::c_int; /// `RWF_HIPRI` (since Linux 4.6) - #[cfg(all(target_os = "linux", target_env = "gnu"))] - const HIPRI = c::RWF_HIPRI; + const HIPRI = linux_raw_sys::general::RWF_HIPRI as c::c_int; /// `RWF_SYNC` (since Linux 4.7) - #[cfg(all(target_os = "linux", target_env = "gnu"))] - const SYNC = c::RWF_SYNC; + const SYNC = linux_raw_sys::general::RWF_SYNC as c::c_int; /// `RWF_NOWAIT` (since Linux 4.14) - #[cfg(all(target_os = "linux", target_env = "gnu"))] - const NOWAIT = c::RWF_NOWAIT; + const NOWAIT = linux_raw_sys::general::RWF_NOWAIT as c::c_int; /// `RWF_APPEND` (since Linux 4.16) - #[cfg(all(target_os = "linux", target_env = "gnu"))] - const APPEND = c::RWF_APPEND; + const APPEND = linux_raw_sys::general::RWF_APPEND as c::c_int; } } @@ -62,16 +57,16 @@ bitflags! { pub struct DupFlags: c::c_int { /// `O_CLOEXEC` #[cfg(not(any( + apple, + target_os = "aix", target_os = "android", - target_os = "ios", - target_os = "macos", target_os = "redox", )))] // Android 5.0 has dup3, but libc doesn't have bindings const CLOEXEC = c::O_CLOEXEC; } } -#[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "wasi")))] +#[cfg(not(any(apple, target_os = "wasi")))] bitflags! { /// `O_*` constants for use with [`pipe_with`]. /// @@ -81,11 +76,10 @@ bitflags! { const CLOEXEC = c::O_CLOEXEC; /// `O_DIRECT` #[cfg(not(any( + solarish, target_os = "haiku", - target_os = "illumos", target_os = "openbsd", target_os = "redox", - target_os = "solaris", )))] const DIRECT = c::O_DIRECT; /// `O_NONBLOCK` @@ -109,13 +103,7 @@ bitflags! { } /// `PIPE_BUF`—The maximum size of a write to a pipe guaranteed to be atomic. -#[cfg(not(any( - target_os = "haiku", - target_os = "illumos", - target_os = "redox", - target_os = "solaris", - target_os = "wasi", -)))] +#[cfg(not(any(solarish, target_os = "haiku", target_os = "redox", target_os = "wasi")))] pub const PIPE_BUF: usize = c::PIPE_BUF; #[cfg(not(any(windows, target_os = "redox")))] @@ -128,9 +116,10 @@ pub(crate) const STDOUT_FILENO: c::c_int = c::STDOUT_FILENO; pub(crate) const STDERR_FILENO: c::c_int = c::STDERR_FILENO; /// A buffer type used with `vmsplice`. -/// It is guaranteed to be ABI compatible with the iovec type on Unix platforms and WSABUF on Windows. -/// Unlike `IoSlice` and `IoSliceMut` it is semantically like a raw pointer, -/// and therefore can be shared or mutated as needed. +/// It is guaranteed to be ABI compatible with the iovec type on Unix platforms +/// and `WSABUF` on Windows. Unlike `IoSlice` and `IoSliceMut` it is +/// semantically like a raw pointer, and therefore can be shared or mutated as +/// needed. #[cfg(any(target_os = "android", target_os = "linux"))] #[repr(transparent)] pub struct IoSliceRaw<'a> { |