From 0ccf82fab1ba49cbf05ff344f0c8586c4fa5df9a Mon Sep 17 00:00:00 2001 From: Josh Megnauth Date: Tue, 1 Dec 2026 15:21:51 -0500 Subject: [PATCH] redox: Unmask SOCK_RAW, msghdr Awaiting: rust-lang/libc#5796 https://github.com/rust-lang/libc/blob/e0df01841e52d5d4b144a918b0a47db545f5645a/src/unix/redox/mod.rs#L141-L158 https://github.com/rust-lang/libc/blob/e0df01841e52d5d4b144a918b0a47db545f5645a/src/unix/redox/mod.rs#L721-L735 https://github.com/rust-lang/libc/blob/e0df01841e52d5d4b144a918b0a47db545f5645a/src/unix/redox/mod.rs#L954-L1001 https://github.com/rust-lang/libc/blob/e0df01841e52d5d4b144a918b0a47db545f5645a/src/unix/redox/mod.rs#L1282-L1289 https://github.com/rust-lang/libc/blob/e0df01841e52d5d4b144a918b0a47db545f5645a/src/unix/redox/mod.rs#L1580-L1597 --- src/lib.rs | 41 +++++++++++-------------- src/socket.rs | 64 +++++++++++++++++++++----------------- src/sys/unix.rs | 81 ++++++++++++++++++++++--------------------------- tests/socket.rs | 51 ++++++++++++++++--------------- 4 files changed, 116 insertions(+), 121 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 95404d69..c7965cca 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -61,11 +61,11 @@ #![doc(test(attr(deny(warnings))))] use std::fmt; -#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))] +#[cfg(not(any(target_os = "wasi", target_os = "horizon")))] use std::io::IoSlice; -#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))] +#[cfg(not(any(target_os = "wasi", target_os = "horizon")))] use std::marker::PhantomData; -#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))] +#[cfg(not(any(target_os = "wasi", target_os = "horizon")))] use std::mem; use std::mem::MaybeUninit; use std::net::SocketAddr; @@ -296,12 +296,7 @@ impl Type { /// Type corresponding to `SOCK_RAW`. #[cfg(all( feature = "all", - not(any( - target_os = "redox", - target_os = "espidf", - target_os = "wasi", - target_os = "horizon" - )) + not(any(target_os = "espidf", target_os = "wasi", target_os = "horizon")) ))] pub const RAW: Type = Type(sys::SOCK_RAW); } @@ -387,11 +382,11 @@ impl From for c_int { /// Flags for incoming messages. /// /// Flags provide additional information about incoming messages. -#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))] +#[cfg(not(any(target_os = "wasi", target_os = "horizon")))] #[derive(Copy, Clone, Eq, PartialEq)] pub struct RecvFlags(c_int); -#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))] +#[cfg(not(any(target_os = "wasi", target_os = "horizon")))] impl RecvFlags { /// Check if the message contains a truncated datagram. /// @@ -455,7 +450,6 @@ pub struct TcpKeepalive { time: Option, #[cfg(not(any( target_os = "openbsd", - target_os = "redox", target_os = "solaris", all(target_os = "nto", not(target_env = "nto71_iosock")), target_os = "espidf", @@ -466,7 +460,6 @@ pub struct TcpKeepalive { interval: Option, #[cfg(not(any( target_os = "openbsd", - target_os = "redox", target_os = "solaris", all(target_os = "nto", not(target_env = "nto71_iosock")), target_os = "espidf", @@ -485,7 +478,6 @@ impl TcpKeepalive { time: None, #[cfg(not(any( target_os = "openbsd", - target_os = "redox", target_os = "solaris", all(target_os = "nto", not(target_env = "nto71_iosock")), target_os = "espidf", @@ -496,7 +488,6 @@ impl TcpKeepalive { interval: None, #[cfg(not(any( target_os = "openbsd", - target_os = "redox", target_os = "solaris", all(target_os = "nto", not(target_env = "nto71_iosock")), target_os = "espidf", @@ -550,6 +541,7 @@ impl TcpKeepalive { target_os = "windows", target_os = "cygwin", target_os = "nuttx", + target_os = "redox", all(target_os = "wasi", not(target_env = "p1")), ))] pub const fn with_interval(self, interval: Duration) -> Self { @@ -582,6 +574,7 @@ impl TcpKeepalive { target_os = "cygwin", target_os = "windows", target_os = "nuttx", + target_os = "redox", all(target_os = "wasi", not(target_env = "p1")), ) ))] @@ -597,7 +590,7 @@ impl TcpKeepalive { /// /// This wraps `msghdr` on Unix and `WSAMSG` on Windows. Also see [`MsgHdrMut`] /// for the variant used by `recvmsg(2)`. -#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))] +#[cfg(not(any(target_os = "wasi", target_os = "horizon")))] #[repr(transparent)] pub struct MsgHdr<'addr, 'bufs, 'control> { inner: sys::msghdr, @@ -605,7 +598,7 @@ pub struct MsgHdr<'addr, 'bufs, 'control> { _lifetimes: PhantomData<(&'addr SockAddr, &'bufs IoSlice<'bufs>, &'control [u8])>, } -#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))] +#[cfg(not(any(target_os = "wasi", target_os = "horizon")))] impl<'addr, 'bufs, 'control> MsgHdr<'addr, 'bufs, 'control> { /// Create a new `MsgHdr` with all empty/zero fields. #[allow(clippy::new_without_default)] @@ -660,21 +653,21 @@ impl<'addr, 'bufs, 'control> MsgHdr<'addr, 'bufs, 'control> { } } -#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))] +#[cfg(not(any(target_os = "wasi", target_os = "horizon")))] impl<'name, 'bufs, 'control> fmt::Debug for MsgHdr<'name, 'bufs, 'control> { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { "MsgHdr".fmt(fmt) } } -#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))] +#[cfg(not(any(target_os = "wasi", target_os = "horizon")))] unsafe impl Send for MsgHdr<'_, '_, '_> {} /// Configuration of a `recvmsg(2)` system call. /// /// This wraps `msghdr` on Unix and `WSAMSG` on Windows. Also see [`MsgHdr`] for /// the variant used by `sendmsg(2)`. -#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))] +#[cfg(not(any(target_os = "wasi", target_os = "horizon")))] #[repr(transparent)] pub struct MsgHdrMut<'addr, 'bufs, 'control> { inner: sys::msghdr, @@ -686,7 +679,7 @@ pub struct MsgHdrMut<'addr, 'bufs, 'control> { )>, } -#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))] +#[cfg(not(any(target_os = "wasi", target_os = "horizon")))] impl<'addr, 'bufs, 'control> MsgHdrMut<'addr, 'bufs, 'control> { /// Create a new `MsgHdrMut` with all empty/zero fields. #[allow(clippy::new_without_default)] @@ -743,18 +736,18 @@ impl<'addr, 'bufs, 'control> MsgHdrMut<'addr, 'bufs, 'control> { } } -#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))] +#[cfg(not(any(target_os = "wasi", target_os = "horizon")))] impl<'name, 'bufs, 'control> fmt::Debug for MsgHdrMut<'name, 'bufs, 'control> { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { "MsgHdrMut".fmt(fmt) } } -#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))] +#[cfg(not(any(target_os = "wasi", target_os = "horizon")))] unsafe impl Send for MsgHdrMut<'_, '_, '_> {} #[test] -#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))] +#[cfg(not(any(target_os = "wasi", target_os = "horizon")))] fn regression_673() { // NOTE: ideally this would be moved into the tests directory, but at the // time of writing Miri doesn't support recvmsg. diff --git a/src/socket.rs b/src/socket.rs index 7ea57f4b..49a6de1e 100644 --- a/src/socket.rs +++ b/src/socket.rs @@ -8,7 +8,7 @@ use std::fmt; use std::io::{self, Read, Write}; -#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))] +#[cfg(not(any(target_os = "wasi", target_os = "horizon")))] use std::io::{IoSlice, IoSliceMut}; use std::mem::MaybeUninit; #[cfg(not(any(target_os = "nuttx")))] @@ -21,10 +21,10 @@ use std::os::windows::io::{FromRawSocket, IntoRawSocket}; use std::time::Duration; use crate::sys::{self, c_int, getsockopt, setsockopt, Bool}; -#[cfg(all(unix, not(any(target_os = "redox", target_os = "horizon"))))] +#[cfg(all(unix, not(target_os = "horizon")))] use crate::MsgHdrMut; use crate::{Domain, Protocol, SockAddr, TcpKeepalive, Type}; -#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))] +#[cfg(not(any(target_os = "wasi", target_os = "horizon")))] use crate::{MaybeUninitSlice, MsgHdr, RecvFlags}; /// Owned wrapper around a system socket. @@ -470,7 +470,7 @@ impl Socket { /// Note that the [`io::Read::read_vectored`] implementation calls this /// function with `buf`s of type `&mut [IoSliceMut]`, allowing initialised /// buffers to be used without using `unsafe`. - #[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))] + #[cfg(not(any(target_os = "wasi", target_os = "horizon")))] pub fn recv_vectored( &self, bufs: &mut [MaybeUninitSlice<'_>], @@ -489,7 +489,7 @@ impl Socket { /// as [`recv_vectored`]. /// /// [`recv_vectored`]: Socket::recv_vectored - #[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))] + #[cfg(not(any(target_os = "wasi", target_os = "horizon")))] pub fn recv_vectored_with_flags( &self, bufs: &mut [MaybeUninitSlice<'_>], @@ -554,7 +554,7 @@ impl Socket { /// as [`recv_vectored`]. /// /// [`recv_vectored`]: Socket::recv_vectored - #[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))] + #[cfg(not(any(target_os = "wasi", target_os = "horizon")))] pub fn recv_from_vectored( &self, bufs: &mut [MaybeUninitSlice<'_>], @@ -573,7 +573,7 @@ impl Socket { /// as [`recv_vectored`]. /// /// [`recv_vectored`]: Socket::recv_vectored - #[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))] + #[cfg(not(any(target_os = "wasi", target_os = "horizon")))] pub fn recv_from_vectored_with_flags( &self, bufs: &mut [MaybeUninitSlice<'_>], @@ -632,7 +632,7 @@ impl Socket { /// /// for an example (in C++). #[doc = man_links!(recvmsg(2))] - #[cfg(all(unix, not(any(target_os = "redox", target_os = "horizon"))))] + #[cfg(all(unix, not(target_os = "horizon")))] pub fn recvmsg(&self, msg: &mut MsgHdrMut<'_, '_, '_>, flags: sys::c_int) -> io::Result { sys::recvmsg(self.as_raw(), msg, flags) } @@ -657,7 +657,7 @@ impl Socket { } /// Send data to the connected peer. Returns the amount of bytes written. - #[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))] + #[cfg(not(any(target_os = "wasi", target_os = "horizon")))] pub fn send_vectored(&self, bufs: &[IoSlice<'_>]) -> io::Result { self.send_vectored_with_flags(bufs, 0) } @@ -667,7 +667,7 @@ impl Socket { #[doc = man_links!(sendmsg(2))] /// /// [`send_vectored`]: Socket::send_vectored - #[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))] + #[cfg(not(any(target_os = "wasi", target_os = "horizon")))] pub fn send_vectored_with_flags( &self, bufs: &[IoSlice<'_>], @@ -683,7 +683,6 @@ impl Socket { /// /// [`send`]: Socket::send /// [`out_of_band_inline`]: Socket::out_of_band_inline - #[cfg_attr(target_os = "redox", allow(rustdoc::broken_intra_doc_links))] #[cfg(not(target_os = "wasi"))] pub fn send_out_of_band(&self, buf: &[u8]) -> io::Result { self.send_with_flags(buf, sys::MSG_OOB) @@ -714,7 +713,7 @@ impl Socket { /// Send data to a peer listening on `addr`. Returns the amount of bytes /// written. #[doc = man_links!(sendmsg(2))] - #[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))] + #[cfg(not(any(target_os = "wasi", target_os = "horizon")))] pub fn send_to_vectored(&self, bufs: &[IoSlice<'_>], addr: &SockAddr) -> io::Result { self.send_to_vectored_with_flags(bufs, addr, 0) } @@ -723,7 +722,7 @@ impl Socket { /// arbitrary flags to the underlying `sendmsg`/`WSASendTo` call. /// /// [`send_to_vectored`]: Socket::send_to_vectored - #[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))] + #[cfg(not(any(target_os = "wasi", target_os = "horizon")))] pub fn send_to_vectored_with_flags( &self, bufs: &[IoSlice<'_>], @@ -735,7 +734,7 @@ impl Socket { /// Send a message on a socket using a message structure. #[doc = man_links!(sendmsg(2))] - #[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))] + #[cfg(not(any(target_os = "wasi", target_os = "horizon")))] pub fn sendmsg(&self, msg: &MsgHdr<'_, '_, '_>, flags: sys::c_int) -> io::Result { sys::sendmsg(self.as_raw(), msg, flags) } @@ -784,6 +783,7 @@ fn set_common_flags(socket: Socket) -> io::Result { target_os = "linux", target_os = "netbsd", target_os = "openbsd", + target_os = "redox", target_os = "espidf", target_os = "vita", target_os = "cygwin", @@ -972,7 +972,7 @@ impl Socket { /// For more information about this option, see [`set_out_of_band_inline`]. /// /// [`set_out_of_band_inline`]: Socket::set_out_of_band_inline - #[cfg(not(any(target_os = "redox", target_os = "wasi")))] + #[cfg(not(target_os = "wasi"))] pub fn out_of_band_inline(&self) -> io::Result { unsafe { getsockopt::(self.as_raw(), sys::SOL_SOCKET, sys::SO_OOBINLINE) @@ -986,7 +986,7 @@ impl Socket { /// receive data stream. Otherwise, out-of-band data is passed only when the /// `MSG_OOB` flag is set during receiving. As per RFC6093, TCP sockets /// using the Urgent mechanism are encouraged to set this flag. - #[cfg(not(any(target_os = "redox", target_os = "wasi")))] + #[cfg(not(target_os = "wasi"))] pub fn set_out_of_band_inline(&self, oob_inline: bool) -> io::Result<()> { unsafe { setsockopt( @@ -1003,7 +1003,7 @@ impl Socket { /// For more information about this option, see [`set_passcred`]. /// /// [`set_passcred`]: Socket::set_passcred - #[cfg(any(target_os = "linux", target_os = "cygwin"))] + #[cfg(any(target_os = "linux", target_os = "redox", target_os = "cygwin"))] pub fn passcred(&self) -> io::Result { unsafe { getsockopt::(self.as_raw(), sys::SOL_SOCKET, sys::SO_PASSCRED) @@ -1015,7 +1015,7 @@ impl Socket { /// /// If this option is enabled, enables the receiving of the `SCM_CREDENTIALS` /// control messages. - #[cfg(any(target_os = "linux", target_os = "cygwin"))] + #[cfg(any(target_os = "linux", target_os = "redox", target_os = "cygwin"))] pub fn set_passcred(&self, passcred: bool) -> io::Result<()> { unsafe { setsockopt( @@ -1034,7 +1034,12 @@ impl Socket { /// [`set_priority`]: Socket::set_priority #[cfg(all( feature = "all", - any(target_os = "linux", target_os = "android", target_os = "fuchsia") + any( + target_os = "linux", + target_os = "android", + target_os = "fuchsia", + target_os = "redox" + ) ))] pub fn priority(&self) -> io::Result { unsafe { @@ -1049,7 +1054,12 @@ impl Socket { /// queueing discipline. #[cfg(all( feature = "all", - any(target_os = "linux", target_os = "android", target_os = "fuchsia") + any( + target_os = "linux", + target_os = "android", + target_os = "fuchsia", + target_os = "redox" + ) ))] pub fn set_priority(&self, priority: u32) -> io::Result<()> { unsafe { @@ -1662,7 +1672,6 @@ impl Socket { /// documents that not all versions of windows support `IP_TOS`. #[cfg(not(any( target_os = "fuchsia", - target_os = "redox", target_os = "solaris", target_os = "haiku", target_os = "wasi", @@ -1681,7 +1690,6 @@ impl Socket { /// [`set_tos_v4`]: Socket::set_tos_v4 #[cfg(not(any( target_os = "fuchsia", - target_os = "redox", target_os = "solaris", target_os = "haiku", target_os = "wasi", @@ -1705,7 +1713,6 @@ impl Socket { target_os = "illumos", target_os = "netbsd", target_os = "openbsd", - target_os = "redox", target_os = "solaris", target_os = "haiku", all(target_os = "nto", not(target_env = "nto71_iosock")), @@ -1740,7 +1747,6 @@ impl Socket { target_os = "illumos", target_os = "netbsd", target_os = "openbsd", - target_os = "redox", target_os = "solaris", target_os = "haiku", all(target_os = "nto", not(target_env = "nto71_iosock")), @@ -2322,6 +2328,7 @@ impl Socket { target_os = "watchos", target_os = "cygwin", target_os = "nuttx", + target_os = "redox", all(target_os = "wasi", not(target_env = "p1")), ) ))] @@ -2356,6 +2363,7 @@ impl Socket { target_os = "cygwin", target_os = "windows", target_os = "nuttx", + target_os = "redox", all(target_os = "wasi", not(target_env = "p1")), ) ))] @@ -2456,7 +2464,7 @@ impl Read for Socket { self.recv(buf) } - #[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))] + #[cfg(not(any(target_os = "wasi", target_os = "horizon")))] fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { // Safety: both `IoSliceMut` and `MaybeUninitSlice` promise to have the // same layout, that of `iovec`/`WSABUF`. Furthermore, `recv_vectored` @@ -2474,7 +2482,7 @@ impl<'a> Read for &'a Socket { self.recv(buf) } - #[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))] + #[cfg(not(any(target_os = "wasi", target_os = "horizon")))] fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { // Safety: see other `Read::read` impl. let bufs = unsafe { &mut *(bufs as *mut [IoSliceMut<'_>] as *mut [MaybeUninitSlice<'_>]) }; @@ -2487,7 +2495,7 @@ impl Write for Socket { self.send(buf) } - #[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))] + #[cfg(not(any(target_os = "wasi", target_os = "horizon")))] fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result { self.send_vectored(bufs) } @@ -2502,7 +2510,7 @@ impl<'a> Write for &'a Socket { self.send(buf) } - #[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))] + #[cfg(not(any(target_os = "wasi", target_os = "horizon")))] fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result { self.send_vectored(bufs) } diff --git a/src/sys/unix.rs b/src/sys/unix.rs index 8a8940f0..32c7222b 100644 --- a/src/sys/unix.rs +++ b/src/sys/unix.rs @@ -9,7 +9,7 @@ use std::cmp::min; #[cfg(not(target_os = "wasi"))] use std::ffi::OsStr; -#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))] +#[cfg(not(any(target_os = "wasi", target_os = "horizon")))] use std::io::IoSlice; use std::marker::PhantomData; use std::mem::{self, size_of, MaybeUninit}; @@ -70,7 +70,7 @@ use libc::{in6_addr, in_addr}; #[cfg(not(target_os = "wasi"))] use crate::SockAddrStorage; use crate::{Domain, Protocol, SockAddr, TcpKeepalive, Type}; -#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))] +#[cfg(not(any(target_os = "wasi", target_os = "horizon")))] use crate::{MsgHdr, MsgHdrMut, RecvFlags}; pub(crate) use std::ffi::c_int; @@ -92,12 +92,7 @@ pub(crate) use libc::AF_IUCV; pub(crate) use libc::SOCK_DCCP; #[cfg(all( feature = "all", - not(any( - target_os = "redox", - target_os = "espidf", - target_os = "wasi", - target_os = "horizon" - )) + not(any(target_os = "espidf", target_os = "wasi", target_os = "horizon")) ))] pub(crate) use libc::SOCK_RAW; #[cfg(all( @@ -133,14 +128,9 @@ pub(crate) use libc::{ sa_family_t, sockaddr, sockaddr_in, sockaddr_in6, sockaddr_storage, socklen_t, }; // Used in `RecvFlags`. -#[cfg(not(any( - target_os = "redox", - target_os = "espidf", - target_os = "wasi", - target_os = "horizon" -)))] +#[cfg(not(any(target_os = "espidf", target_os = "wasi", target_os = "horizon")))] pub(crate) use libc::MSG_TRUNC; -#[cfg(not(any(target_os = "redox", target_os = "wasi")))] +#[cfg(not(target_os = "wasi"))] pub(crate) use libc::SO_OOBINLINE; // Used in `Socket`. #[cfg(not(any(target_os = "nuttx")))] @@ -156,11 +146,11 @@ pub(crate) use libc::IPV6_HDRINCL; target_os = "illumos", target_os = "netbsd", target_os = "openbsd", - target_os = "redox", target_os = "solaris", target_os = "haiku", target_os = "espidf", target_os = "vita", + target_os = "redox", target_os = "wasi", target_os = "cygwin", target_os = "horizon" @@ -202,7 +192,6 @@ pub(crate) use libc::IP_HDRINCL; target_os = "illumos", target_os = "netbsd", target_os = "openbsd", - target_os = "redox", target_os = "solaris", target_os = "haiku", target_os = "hurd", @@ -217,7 +206,6 @@ pub(crate) use libc::IP_HDRINCL; pub(crate) use libc::IP_RECVTOS; #[cfg(not(any( target_os = "fuchsia", - target_os = "redox", target_os = "solaris", target_os = "haiku", target_os = "wasi", @@ -239,11 +227,16 @@ pub(crate) use libc::SO_LINGER; target_os = "watchos", ))] pub(crate) use libc::SO_LINGER_SEC as SO_LINGER; -#[cfg(any(target_os = "linux", target_os = "cygwin"))] +#[cfg(any(target_os = "linux", target_os = "redox", target_os = "cygwin"))] pub(crate) use libc::SO_PASSCRED; #[cfg(all( feature = "all", - any(target_os = "linux", target_os = "android", target_os = "fuchsia") + any( + target_os = "linux", + target_os = "android", + target_os = "fuchsia", + target_os = "redox" + ) ))] pub(crate) use libc::SO_PRIORITY; pub(crate) use libc::{ @@ -330,6 +323,7 @@ pub(crate) use libc::{IPV6_MULTICAST_HOPS, IPV6_MULTICAST_IF, IP_MULTICAST_IF, M target_os = "watchos", target_os = "cygwin", target_os = "nuttx", + target_os = "redox", all(target_os = "wasi", not(target_env = "p1")), ) ))] @@ -415,6 +409,7 @@ const TCP_CA_NAME_MAX: usize = 16; ) ), target_os = "android", + target_os = "redox", ))] type IovLen = usize; @@ -556,15 +551,9 @@ impl_debug!( libc::SOCK_DGRAM, #[cfg(all(feature = "all", target_os = "linux"))] libc::SOCK_DCCP, - #[cfg(not(any( - target_os = "redox", - target_os = "espidf", - target_os = "wasi", - target_os = "horizon" - )))] + #[cfg(not(any(target_os = "espidf", target_os = "wasi", target_os = "horizon")))] libc::SOCK_RAW, #[cfg(not(any( - target_os = "redox", target_os = "haiku", target_os = "espidf", target_os = "wasi", @@ -626,7 +615,7 @@ impl_debug!( ); /// Unix-only API. -#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))] +#[cfg(not(any(target_os = "wasi", target_os = "horizon")))] impl RecvFlags { /// Check if the message terminates a record. /// @@ -679,7 +668,7 @@ impl RecvFlags { } } -#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))] +#[cfg(not(any(target_os = "wasi", target_os = "horizon")))] impl std::fmt::Debug for RecvFlags { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let mut s = f.debug_struct("RecvFlags"); @@ -829,39 +818,39 @@ pub(crate) fn iucv_sockaddr(userid: &str, name: &str) -> io::Result { } // Used in `MsgHdr`. -#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))] +#[cfg(not(any(target_os = "wasi", target_os = "horizon")))] pub(crate) use libc::msghdr; -#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))] +#[cfg(not(any(target_os = "wasi", target_os = "horizon")))] pub(crate) fn set_msghdr_name(msg: &mut msghdr, name: *mut SockAddrStorage, name_len: socklen_t) { msg.msg_name = name as *mut _; msg.msg_namelen = name_len; } -#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))] +#[cfg(not(any(target_os = "wasi", target_os = "horizon")))] #[allow(clippy::unnecessary_cast)] // IovLen type can be `usize`. pub(crate) fn set_msghdr_iov(msg: &mut msghdr, ptr: *mut libc::iovec, len: usize) { msg.msg_iov = ptr; msg.msg_iovlen = min(len, IovLen::MAX as usize) as IovLen; } -#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))] +#[cfg(not(any(target_os = "wasi", target_os = "horizon")))] pub(crate) fn set_msghdr_control(msg: &mut msghdr, ptr: *mut libc::c_void, len: usize) { msg.msg_control = ptr; msg.msg_controllen = len as _; } -#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))] +#[cfg(not(any(target_os = "wasi", target_os = "horizon")))] pub(crate) fn set_msghdr_flags(msg: &mut msghdr, flags: c_int) { msg.msg_flags = flags; } -#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))] +#[cfg(not(any(target_os = "wasi", target_os = "horizon")))] pub(crate) fn msghdr_flags(msg: &msghdr) -> RecvFlags { RecvFlags(msg.msg_flags) } -#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))] +#[cfg(not(any(target_os = "wasi", target_os = "horizon")))] pub(crate) fn msghdr_control_len(msg: &msghdr) -> usize { msg.msg_controllen as _ } @@ -1198,7 +1187,7 @@ pub(crate) fn peek_sender(fd: RawSocket) -> io::Result { Ok(sender) } -#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))] +#[cfg(not(any(target_os = "wasi", target_os = "horizon")))] pub(crate) fn recv_vectored( fd: RawSocket, bufs: &mut [crate::MaybeUninitSlice<'_>], @@ -1209,7 +1198,7 @@ pub(crate) fn recv_vectored( Ok((n, msg.flags())) } -#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))] +#[cfg(not(any(target_os = "wasi", target_os = "horizon")))] pub(crate) fn recv_from_vectored( fd: RawSocket, bufs: &mut [crate::MaybeUninitSlice<'_>], @@ -1231,7 +1220,7 @@ pub(crate) fn recv_from_vectored( Ok((n, msg.flags(), addr)) } -#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))] +#[cfg(not(any(target_os = "wasi", target_os = "horizon")))] pub(crate) fn recvmsg( fd: RawSocket, msg: &mut MsgHdrMut<'_, '_, '_>, @@ -1250,7 +1239,7 @@ pub(crate) fn send(fd: RawSocket, buf: &[u8], flags: c_int) -> io::Result .map(|n| n as usize) } -#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))] +#[cfg(not(any(target_os = "wasi", target_os = "horizon")))] pub(crate) fn send_vectored( fd: RawSocket, bufs: &[IoSlice<'_>], @@ -1277,7 +1266,7 @@ pub(crate) fn send_to( .map(|n| n as usize) } -#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))] +#[cfg(not(any(target_os = "wasi", target_os = "horizon")))] pub(crate) fn send_to_vectored( fd: RawSocket, bufs: &[IoSlice<'_>], @@ -1288,7 +1277,7 @@ pub(crate) fn send_to_vectored( sendmsg(fd, &msg, flags) } -#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))] +#[cfg(not(any(target_os = "wasi", target_os = "horizon")))] pub(crate) fn sendmsg(fd: RawSocket, msg: &MsgHdr<'_, '_, '_>, flags: c_int) -> io::Result { syscall!(sendmsg(fd, &msg.inner, flags)).map(|n| n as usize) } @@ -1378,6 +1367,7 @@ pub(crate) fn set_tcp_keepalive(fd: RawSocket, keepalive: &TcpKeepalive) -> io:: target_os = "watchos", target_os = "cygwin", target_os = "nuttx", + target_os = "redox", all(target_os = "wasi", not(target_env = "p1")), ))] { @@ -1729,7 +1719,7 @@ impl crate::Socket { /// For more information about this option, see [`set_tcp_mss`]. /// /// [`set_tcp_mss`]: crate::Socket::set_tcp_mss - #[cfg(all(feature = "all", not(any(target_os = "redox", target_os = "wasi"))))] + #[cfg(all(feature = "all", not(target_os = "wasi")))] pub fn tcp_mss(&self) -> io::Result { unsafe { getsockopt::(self.as_raw(), libc::IPPROTO_TCP, libc::TCP_MAXSEG) @@ -1741,7 +1731,7 @@ impl crate::Socket { /// /// The `TCP_MAXSEG` option denotes the TCP Maximum Segment Size and is only /// available on TCP sockets. - #[cfg(all(feature = "all", not(any(target_os = "redox", target_os = "wasi"))))] + #[cfg(all(feature = "all", not(target_os = "wasi")))] pub fn set_tcp_mss(&self, mss: u32) -> io::Result<()> { unsafe { setsockopt( @@ -1763,6 +1753,7 @@ impl crate::Socket { target_os = "freebsd", target_os = "fuchsia", target_os = "linux", + target_os = "redox", target_os = "cygwin", ) ))] @@ -1783,6 +1774,7 @@ impl crate::Socket { // target_os = "freebsd", target_os = "fuchsia", target_os = "linux", + target_os = "redox", ) ))] pub fn domain(&self) -> io::Result { @@ -1798,6 +1790,7 @@ impl crate::Socket { target_os = "freebsd", target_os = "fuchsia", target_os = "linux", + target_os = "redox", ) ))] pub fn protocol(&self) -> io::Result> { diff --git a/tests/socket.rs b/tests/socket.rs index 0f390e3a..6994b6b9 100644 --- a/tests/socket.rs +++ b/tests/socket.rs @@ -14,7 +14,7 @@ ))] use std::fs::File; use std::io; -#[cfg(not(any(target_os = "redox", target_os = "vita", target_os = "wasi")))] +#[cfg(not(any(target_os = "vita", target_os = "wasi")))] use std::io::IoSlice; use std::io::Read; use std::io::Write; @@ -22,7 +22,7 @@ use std::io::Write; use std::mem::MaybeUninit; use std::mem::{self}; use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4, TcpStream}; -#[cfg(not(any(target_os = "redox", target_os = "vita")))] +#[cfg(not(target_os = "vita"))] use std::net::{Ipv6Addr, SocketAddrV6}; #[cfg(all( feature = "all", @@ -55,7 +55,7 @@ use std::{env, fs}; #[cfg(windows)] use windows_sys::Win32::Foundation::{GetHandleInformation, HANDLE_FLAG_INHERIT}; -#[cfg(not(any(target_os = "redox", target_os = "vita", target_os = "wasi")))] +#[cfg(not(any(target_os = "vita", target_os = "wasi")))] use socket2::MaybeUninitSlice; #[cfg(not(target_os = "vita"))] use socket2::TcpKeepalive; @@ -103,7 +103,7 @@ fn type_fmt_debug() { (Type::DGRAM, "SOCK_DGRAM"), #[cfg(all(feature = "all", not(target_os = "wasi")))] (Type::SEQPACKET, "SOCK_SEQPACKET"), - #[cfg(all(feature = "all", not(any(target_os = "redox", target_os = "wasi"))))] + #[cfg(all(feature = "all", not(target_os = "wasi")))] (Type::RAW, "SOCK_RAW"), (500.into(), "500"), ]; @@ -728,7 +728,7 @@ fn out_of_band() { } #[test] -#[cfg(not(any(target_os = "redox", target_os = "vita", target_os = "wasi")))] // WASI: SO_RCVTIMEO excluded, used in test setup. +#[cfg(not(any(target_os = "vita", target_os = "wasi")))] // WASI: SO_RCVTIMEO excluded, used in test setup. fn udp_peek_sender() { let (socket_a, socket_b) = udp_pair_unconnected(); @@ -743,7 +743,7 @@ fn udp_peek_sender() { } #[test] -#[cfg(not(any(target_os = "redox", target_os = "vita", target_os = "wasi")))] +#[cfg(not(any(target_os = "vita", target_os = "wasi")))] fn send_recv_vectored() { let (socket_a, socket_b) = udp_pair_connected(); @@ -775,9 +775,9 @@ fn send_recv_vectored() { ]) .unwrap(); assert_eq!(received, 23); - #[cfg(all(unix, not(target_os = "redox")))] + #[cfg(unix)] assert_eq!(flags.is_end_of_record(), false); - #[cfg(all(unix, not(target_os = "redox")))] + #[cfg(unix)] assert_eq!(flags.is_out_of_band(), false); assert_eq!(flags.is_truncated(), false); @@ -790,7 +790,7 @@ fn send_recv_vectored() { } #[test] -#[cfg(not(any(target_os = "redox", target_os = "vita", target_os = "wasi")))] +#[cfg(not(any(target_os = "vita", target_os = "wasi")))] fn send_from_recv_to_vectored() { let (socket_a, socket_b) = udp_pair_unconnected(); let addr_a = socket_a.local_addr().unwrap(); @@ -822,9 +822,9 @@ fn send_from_recv_to_vectored() { .unwrap(); assert_eq!(received, 18); - #[cfg(all(unix, not(target_os = "redox")))] + #[cfg(unix)] assert_eq!(flags.is_end_of_record(), false); - #[cfg(all(unix, not(target_os = "redox")))] + #[cfg(unix)] assert_eq!(flags.is_out_of_band(), false); assert_eq!(flags.is_truncated(), false); #[cfg(all(feature = "all", any(target_os = "android", target_os = "linux")))] @@ -843,7 +843,7 @@ fn send_from_recv_to_vectored() { } #[test] -#[cfg(not(any(target_os = "redox", target_os = "vita", target_os = "wasi")))] +#[cfg(not(any(target_os = "vita", target_os = "wasi")))] fn sendmsg() { let (socket_a, socket_b) = udp_pair_unconnected(); @@ -861,7 +861,7 @@ fn sendmsg() { } #[test] -#[cfg(not(any(target_os = "redox", target_os = "vita", target_os = "wasi")))] +#[cfg(not(any(target_os = "vita", target_os = "wasi")))] fn recv_vectored_truncated() { let (socket_a, socket_b) = udp_pair_connected(); @@ -881,7 +881,7 @@ fn recv_vectored_truncated() { } #[test] -#[cfg(not(any(target_os = "redox", target_os = "vita", target_os = "wasi")))] +#[cfg(not(any(target_os = "vita", target_os = "wasi")))] fn recv_from_vectored_truncated() { let (socket_a, socket_b) = udp_pair_unconnected(); let addr_a = socket_a.local_addr().unwrap(); @@ -907,7 +907,7 @@ fn recv_from_vectored_truncated() { } /// Create a pair of non-connected UDP sockets suitable for unit tests. -#[cfg(not(any(target_os = "redox", target_os = "vita")))] +#[cfg(not(target_os = "vita"))] fn udp_pair_unconnected() -> (Socket, Socket) { // Use ephemeral ports assigned by the OS. let unspecified_addr = SocketAddrV6::new(Ipv6Addr::LOCALHOST, 0, 0, 0); @@ -935,7 +935,7 @@ fn udp_pair_unconnected() -> (Socket, Socket) { } /// Create a pair of connected UDP sockets suitable for unit tests. -#[cfg(not(any(target_os = "redox", target_os = "vita")))] +#[cfg(not(target_os = "vita"))] fn udp_pair_connected() -> (Socket, Socket) { let (socket_a, socket_b) = udp_pair_unconnected(); @@ -967,6 +967,7 @@ fn tcp_keepalive() { target_os = "tvos", target_os = "watchos", target_os = "windows", + target_os = "redox", ) ))] let params = params.with_interval(Duration::from_secs(30)); @@ -984,7 +985,8 @@ fn tcp_keepalive() { target_os = "netbsd", target_os = "tvos", target_os = "watchos", - target_os = "windows" + target_os = "windows", + target_os = "redox", ) ))] let params = params.with_retries(10); @@ -1016,6 +1018,7 @@ fn tcp_keepalive() { target_os = "netbsd", target_os = "tvos", target_os = "watchos", + target_os = "redox", ) ))] assert_eq!( @@ -1039,6 +1042,7 @@ fn tcp_keepalive() { target_os = "tvos", target_os = "watchos", target_os = "windows", + target_os = "redox", ) ))] assert_eq!(socket.tcp_keepalive_retries().unwrap(), 10); @@ -1260,6 +1264,7 @@ fn sendfile() { target_os = "freebsd", target_os = "fuchsia", target_os = "linux", + target_os = "redox", ) ))] fn is_listener() { @@ -1279,6 +1284,7 @@ fn is_listener() { // target_os = "freebsd", target_os = "fuchsia", target_os = "linux", + target_os = "redox", ) ))] fn domain() { @@ -1300,6 +1306,7 @@ fn domain() { target_os = "freebsd", target_os = "fuchsia", target_os = "linux", + target_os = "redox", target_os = "windows", ) ))] @@ -1450,7 +1457,7 @@ test!( set_send_buffer_size(SET_BUF_SIZE), GET_BUF_SIZE ); -#[cfg(not(any(target_os = "redox", target_os = "wasi")))] +#[cfg(not(target_os = "wasi"))] test!(out_of_band_inline, set_out_of_band_inline(true)); test!(reuse_address, set_reuse_address(true)); #[cfg(all(feature = "all", windows))] @@ -1468,11 +1475,7 @@ test!(exclusive_address, set_exclusive_address(true)); test!(reuse_port, set_reuse_port(true)); #[cfg(all(feature = "all", target_os = "freebsd"))] test!(reuse_port_lb, set_reuse_port_lb(true)); -#[cfg(all( - feature = "all", - unix, - not(any(target_os = "redox", target_os = "cygwin")), -))] +#[cfg(all(feature = "all", unix, not(target_os = "cygwin"),))] test!( #[cfg_attr(target_os = "linux", ignore = "Different value returned")] tcp_mss, @@ -1526,7 +1529,6 @@ test!(IPv4 min_ttl_v4, set_min_ttl_v4(50)); #[cfg(not(any( target_os = "fuchsia", - target_os = "redox", target_os = "solaris", target_os = "haiku", target_os = "cygwin", @@ -1541,7 +1543,6 @@ test!(IPv4 tos_v4, set_tos_v4(96)); target_os = "illumos", target_os = "netbsd", target_os = "openbsd", - target_os = "redox", target_os = "solaris", target_os = "windows", target_os = "vita",