From d3b1bf4654bf9ecd2cc1f9d2ae7ede4f5341990f Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Mon, 9 Oct 2023 19:59:50 -0700 Subject: [PATCH] Fixes needed by io_uring. - Have the `io_uring` module export more types used in opcode entries. - Define a conversion from `SocketAddr` to `SocketAddrAny`. - Add comments to the `fadvise` implementation. --- src/backend/linux_raw/fs/syscalls.rs | 6 +++++ src/io_uring.rs | 36 ++++++++++++++++++++++++++++ src/net/socket_addr_any.rs | 12 +++++++++- 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/src/backend/linux_raw/fs/syscalls.rs b/src/backend/linux_raw/fs/syscalls.rs index 880d3927a..f856fa8b0 100644 --- a/src/backend/linux_raw/fs/syscalls.rs +++ b/src/backend/linux_raw/fs/syscalls.rs @@ -378,6 +378,7 @@ pub(crate) fn fadvise(fd: BorrowedFd<'_>, pos: u64, len: u64, advice: Advice) -> lo(len) )) } + // On mips, the arguments are not reordered, and padding is inserted // instead to ensure alignment. #[cfg(any(target_arch = "mips", target_arch = "mips32r6"))] @@ -393,6 +394,9 @@ pub(crate) fn fadvise(fd: BorrowedFd<'_>, pos: u64, len: u64, advice: Advice) -> advice )) } + + // For all other 32-bit architectures, use `fadvise64_64` so that we get a + // 64-bit length. #[cfg(all( target_pointer_width = "32", not(any( @@ -413,6 +417,8 @@ pub(crate) fn fadvise(fd: BorrowedFd<'_>, pos: u64, len: u64, advice: Advice) -> advice )) } + + // On 64-bit architectures, use `fadvise64` which is sufficient. #[cfg(target_pointer_width = "64")] unsafe { ret(syscall_readonly!( diff --git a/src/io_uring.rs b/src/io_uring.rs index c166e747a..f1b5a26d9 100644 --- a/src/io_uring.rs +++ b/src/io_uring.rs @@ -35,6 +35,40 @@ use linux_raw_sys::net; pub use crate::fs::{Advice, AtFlags, OFlags, RenameFlags, ResolveFlags, Statx}; pub use crate::net::{RecvFlags, SendFlags, SocketFlags}; pub use crate::timespec::Timespec; +pub use linux_raw_sys::general::sigset_t; + +pub use net::{__kernel_sockaddr_storage as sockaddr_storage, msghdr, sockaddr, socklen_t}; + +// Declare the `c_char` type for use with entries that take pointers +// to C strings. Define it as unsigned or signed according to the platform +// so that we match what Rust's `CStr` uses. +// +// When we can update to linux-raw-sys 0.5, we can remove this, as its +// `c_char` type will declare this. +/// The C `char` type. +#[cfg(any( + target_arch = "aarch64", + target_arch = "arm", + target_arch = "msp430", + target_arch = "powerpc", + target_arch = "powerpc64", + target_arch = "riscv32", + target_arch = "riscv64", + target_arch = "s390x", +))] +#[allow(non_camel_case_types)] +pub type c_char = u8; +/// The C `char` type. +#[cfg(any( + target_arch = "mips", + target_arch = "mips64", + target_arch = "sparc64", + target_arch = "x86", + target_arch = "x86_64", + target_arch = "xtensa", +))] +#[allow(non_camel_case_types)] +pub type c_char = i8; mod sys { pub(super) use linux_raw_sys::io_uring::*; @@ -1393,6 +1427,8 @@ impl Default for register_or_sqe_op_or_sqe_flags_union { fn io_uring_layouts() { use sys as c; + check_renamed_type!(io_uring_ptr, u64); + check_renamed_type!(off_or_addr2_union, io_uring_sqe__bindgen_ty_1); check_renamed_type!(addr_or_splice_off_in_union, io_uring_sqe__bindgen_ty_2); check_renamed_type!(addr3_or_cmd_union, io_uring_sqe__bindgen_ty_6); diff --git a/src/net/socket_addr_any.rs b/src/net/socket_addr_any.rs index 7cb124e4c..a649015f4 100644 --- a/src/net/socket_addr_any.rs +++ b/src/net/socket_addr_any.rs @@ -11,7 +11,7 @@ #[cfg(unix)] use crate::net::SocketAddrUnix; -use crate::net::{AddressFamily, SocketAddrV4, SocketAddrV6}; +use crate::net::{AddressFamily, SocketAddr, SocketAddrV4, SocketAddrV6}; use crate::{backend, io}; #[cfg(feature = "std")] use core::fmt; @@ -32,6 +32,16 @@ pub enum SocketAddrAny { Unix(SocketAddrUnix), } +impl From for SocketAddrAny { + #[inline] + fn from(from: SocketAddr) -> Self { + match from { + SocketAddr::V4(v4) => Self::V4(v4), + SocketAddr::V6(v6) => Self::V6(v6), + } + } +} + impl From for SocketAddrAny { #[inline] fn from(from: SocketAddrV4) -> Self {