Skip to content

Commit

Permalink
Fix mistakes, switch to libc fork
Browse files Browse the repository at this point in the history
  • Loading branch information
arctic-alpaca committed Nov 28, 2023
1 parent 1611ece commit abc8a5c
Show file tree
Hide file tree
Showing 11 changed files with 16 additions and 18 deletions.
9 changes: 6 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,17 @@ once_cell = { version = "1.5.2", optional = true }
#linux-raw-sys = { version = "0.4.11", default-features = false, features = ["general", "errno", "ioctl", "no_std", "elf"] }
linux-raw-sys = { git = "https://github.com/arctic-alpaca/linux-raw-sys", branch = "v0.4.11", version = "0.4.11", default-features = false, features = ["general", "errno", "ioctl", "no_std", "elf"] }
libc_errno = { package = "errno", version = "0.3.8", default-features = false, optional = true }
libc = { version = "0.2.150", default-features = false, features = ["extra_traits"], optional = true }
#libc = { version = "0.2.150", default-features = false, features = ["extra_traits"], optional = true }
libc = { git = "https://github.com/arctic-alpaca/libc", default-features = false, features = ["extra_traits"], optional = true }

# Dependencies for platforms where only libc is supported:
#
# On all other Unix-family platforms, and under Miri, we always use the libc
# backend, so enable its dependencies unconditionally.
[target.'cfg(all(not(windows), any(rustix_use_libc, miri, not(all(target_os = "linux", target_endian = "little", any(target_arch = "arm", all(target_arch = "aarch64", target_pointer_width = "64"), target_arch = "riscv64", all(rustix_use_experimental_asm, target_arch = "powerpc64"), all(rustix_use_experimental_asm, target_arch = "mips"), all(rustix_use_experimental_asm, target_arch = "mips32r6"), all(rustix_use_experimental_asm, target_arch = "mips64"), all(rustix_use_experimental_asm, target_arch = "mips64r6"), target_arch = "x86", all(target_arch = "x86_64", target_pointer_width = "64")))))))'.dependencies]
libc_errno = { package = "errno", version = "0.3.8", default-features = false }
libc = { version = "0.2.150", default-features = false, features = ["extra_traits"] }
#libc = { version = "0.2.150", default-features = false, features = ["extra_traits"] }
libc = { git = "https://github.com/arctic-alpaca/libc", default-features = false, features = ["extra_traits"] }

# Additional dependencies for Linux with the libc backend:
#
Expand Down Expand Up @@ -76,7 +78,8 @@ default-features = false

[dev-dependencies]
tempfile = "3.5.0"
libc = "0.2.150"
#libc = "0.2.150"
libc = {git = "https://github.com/arctic-alpaca/libc"}
libc_errno = { package = "errno", version = "0.3.8", default-features = false }
serial_test = "2.0.0"
memoffset = "0.9.0"
Expand Down
1 change: 1 addition & 0 deletions src/backend/libc/net/msghdr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ pub(crate) fn with_unix_msghdr<R>(
}

/// Create a message header intended to send with an IPv6 address.
#[cfg(target_os = "linux")]
pub(crate) fn with_xdp_msghdr<R>(
addr: &SocketAddrXdp,
iov: &[IoSlice<'_>],
Expand Down
4 changes: 2 additions & 2 deletions src/backend/libc/net/read_sockaddr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,12 @@ pub(crate) unsafe fn read_sockaddr(
return Err(io::Errno::INVAL);
}
let decode = &*storage.cast::<c::sockaddr_xdp>();
SocketAddrAny::Xdp(SocketAddrXdp::new(
Ok(SocketAddrAny::Xdp(SocketAddrXdp::new(
SockaddrXdpFlags::from_bits_retain(decode.sxdp_flags),
u32::from_be(decode.sxdp_ifindex),
u32::from_be(decode.sxdp_queue_id),
u32::from_be(decode.sxdp_shared_umem_fd),
))
)))
}
_ => Err(io::Errno::INVAL),
}
Expand Down
1 change: 0 additions & 1 deletion src/backend/libc/net/sockopt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ use alloc::borrow::ToOwned;
target_os = "illumos"
))]
use alloc::string::String;
use bitflags::Flags;
#[cfg(apple)]
use c::TCP_KEEPALIVE as TCP_KEEPIDLE;
#[cfg(not(any(apple, target_os = "openbsd", target_os = "haiku", target_os = "nto")))]
Expand Down
6 changes: 3 additions & 3 deletions src/backend/libc/net/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ pub(crate) fn sendto_unix(
}
}

#[cfg(not(any(target_os = "redox", target_os = "wasi")))]
#[cfg(target_os = "linux")]
pub(crate) fn sendto_xdp(
fd: BorrowedFd<'_>,
buf: &[u8],
Expand Down Expand Up @@ -245,8 +245,8 @@ pub(crate) fn bind_xdp(sockfd: BorrowedFd<'_>, addr: &SocketAddrXdp) -> io::Resu
unsafe {
ret(c::bind(
borrowed_fd(sockfd),
as_ptr(&encode_sockaddr_xdp(xdp)).cast(),
size_of::<c::sockaddr_xdp, _>(),
as_ptr(&encode_sockaddr_xdp(addr)).cast(),
size_of::<c::sockaddr_xdp>() as c::socklen_t,
))
}
}
Expand Down
1 change: 0 additions & 1 deletion src/backend/libc/net/write_sockaddr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use crate::backend::c;
#[cfg(target_os = "linux")]
use crate::net::xdp::SocketAddrXdp;
use crate::net::{SocketAddrAny, SocketAddrV4, SocketAddrV6};
use bitflags::Flags;
use core::mem::size_of;

pub(crate) unsafe fn write_sockaddr(
Expand Down
1 change: 0 additions & 1 deletion src/backend/linux_raw/net/sockopt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use crate::net::{
use alloc::borrow::ToOwned;
#[cfg(feature = "alloc")]
use alloc::string::String;
use bitflags::Flags;
use core::mem::MaybeUninit;
use core::time::Duration;
use linux_raw_sys::general::{__kernel_old_timeval, __kernel_sock_timeval};
Expand Down
1 change: 1 addition & 0 deletions src/backend/linux_raw/net/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,7 @@ pub(crate) fn sendto_unix(
}
}

#[cfg(target_os = "linux")]
#[inline]
pub(crate) fn sendto_xdp(
fd: BorrowedFd<'_>,
Expand Down
1 change: 0 additions & 1 deletion src/backend/linux_raw/net/write_sockaddr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crate::backend::c;
#[cfg(target_os = "linux")]
use crate::net::xdp::SocketAddrXdp;
use crate::net::{SocketAddrAny, SocketAddrStorage, SocketAddrUnix, SocketAddrV4, SocketAddrV6};
use bitflags::Flags;
use core::mem::size_of;

pub(crate) unsafe fn write_sockaddr(
Expand Down
4 changes: 2 additions & 2 deletions src/net/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::net::{SocketAddr, SocketAddrAny, SocketAddrV4, SocketAddrV6};
use crate::{backend, io};
use backend::fd::{AsFd, BorrowedFd};

use crate::io::Errno;
#[cfg(target_os = "linux")]
use crate::net::xdp::SocketAddrXdp;
pub use crate::net::{AddressFamily, Protocol, Shutdown, SocketFlags, SocketType};
#[cfg(unix)]
Expand Down Expand Up @@ -281,7 +281,7 @@ pub fn bind_unix<Fd: AsFd>(sockfd: Fd, addr: &SocketAddrUnix) -> io::Result<()>
/// - [Linux]
///
/// [Linux]: https://man7.org/linux/man-pages/man2/bind.2.html
#[cfg(unix)]
#[cfg(target_os = "linux")]
#[inline]
#[doc(alias = "bind")]
pub fn bind_xdp<Fd: AsFd>(sockfd: Fd, addr: &SocketAddrXdp) -> io::Result<()> {
Expand Down
5 changes: 1 addition & 4 deletions src/net/sockopt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,8 @@
#![doc(alias = "getsockopt")]
#![doc(alias = "setsockopt")]

use crate::net::xdp::{XdpMmapOffsets, XdpUmemReg};
#[cfg(target_os = "linux")]
use crate::net::xdp::{XdpOptionsFlags, XdpStatistics};
use crate::net::xdp::{XdpMmapOffsets, XdpOptionsFlags, XdpStatistics, XdpUmemReg};
#[cfg(not(any(
apple,
windows,
Expand Down Expand Up @@ -185,8 +184,6 @@ use alloc::string::String;
use backend::c;
use backend::fd::AsFd;
use core::time::Duration;
#[cfg(target_os = "linux")]
use linux_raw_sys::xdp::xdp_mmap_offsets;

/// Timeout identifier for use with [`set_socket_timeout`] and
/// [`get_socket_timeout`].
Expand Down

0 comments on commit abc8a5c

Please sign in to comment.