Skip to content

Commit

Permalink
Fixes needed by io_uring.
Browse files Browse the repository at this point in the history
 - 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.
  • Loading branch information
sunfishcode committed Oct 10, 2023
1 parent 1a9d129 commit d3b1bf4
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/backend/linux_raw/fs/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))]
Expand All @@ -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(
Expand All @@ -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!(
Expand Down
36 changes: 36 additions & 0 deletions src/io_uring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 11 additions & 1 deletion src/net/socket_addr_any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,6 +32,16 @@ pub enum SocketAddrAny {
Unix(SocketAddrUnix),
}

impl From<SocketAddr> for SocketAddrAny {
#[inline]
fn from(from: SocketAddr) -> Self {
match from {
SocketAddr::V4(v4) => Self::V4(v4),
SocketAddr::V6(v6) => Self::V6(v6),
}
}
}

impl From<SocketAddrV4> for SocketAddrAny {
#[inline]
fn from(from: SocketAddrV4) -> Self {
Expand Down

0 comments on commit d3b1bf4

Please sign in to comment.