Sha256: 7e40703cc3a020377a4a23bc8651bdf1d65b8f62e174eafb85d27d246f86c39d

Contents?: true

Size: 1.99 KB

Versions: 4

Compression:

Stored size: 1.99 KB

Contents

//! linux_raw syscalls supporting `rustix::io_uring`.
//!
//! # Safety
//!
//! See the `rustix::backend::syscalls` module documentation for details.
#![allow(unsafe_code, clippy::undocumented_unsafe_blocks)]

use crate::backend::conv::{by_mut, c_uint, pass_usize, ret_c_uint, ret_owned_fd};
use crate::fd::{BorrowedFd, OwnedFd};
use crate::io;
use crate::io_uring::{io_uring_params, IoringEnterFlags, IoringRegisterFlags, IoringRegisterOp};
use core::ffi::c_void;

#[inline]
pub(crate) fn io_uring_setup(entries: u32, params: &mut io_uring_params) -> io::Result<OwnedFd> {
    unsafe {
        ret_owned_fd(syscall!(
            __NR_io_uring_setup,
            c_uint(entries),
            by_mut(params)
        ))
    }
}

#[inline]
pub(crate) unsafe fn io_uring_register(
    fd: BorrowedFd<'_>,
    opcode: IoringRegisterOp,
    arg: *const c_void,
    nr_args: u32,
) -> io::Result<u32> {
    ret_c_uint(syscall_readonly!(
        __NR_io_uring_register,
        fd,
        c_uint(opcode as u32),
        arg,
        c_uint(nr_args)
    ))
}

#[inline]
pub(crate) unsafe fn io_uring_register_with(
    fd: BorrowedFd<'_>,
    opcode: IoringRegisterOp,
    flags: IoringRegisterFlags,
    arg: *const c_void,
    nr_args: u32,
) -> io::Result<u32> {
    ret_c_uint(syscall_readonly!(
        __NR_io_uring_register,
        fd,
        c_uint((opcode as u32) | bitflags_bits!(flags)),
        arg,
        c_uint(nr_args)
    ))
}

#[inline]
pub(crate) unsafe fn io_uring_enter(
    fd: BorrowedFd<'_>,
    to_submit: u32,
    min_complete: u32,
    flags: IoringEnterFlags,
    arg: *const c_void,
    size: usize,
) -> io::Result<u32> {
    // This is not `_readonly` because `io_uring_enter` waits for I/O to
    // complete, and I/O could involve writing to memory buffers, which
    // could be a side effect depended on by the caller.
    ret_c_uint(syscall!(
        __NR_io_uring_enter,
        fd,
        c_uint(to_submit),
        c_uint(min_complete),
        flags,
        arg,
        pass_usize(size)
    ))
}

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
wasmtime-29.0.0 ./ext/cargo-vendor/rustix-0.38.44/src/backend/linux_raw/io_uring/syscalls.rs
wasmtime-28.0.0 ./ext/cargo-vendor/rustix-0.38.43/src/backend/linux_raw/io_uring/syscalls.rs
wasmtime-27.0.0 ./ext/cargo-vendor/rustix-0.38.41/src/backend/linux_raw/io_uring/syscalls.rs
wasmtime-26.0.0 ./ext/cargo-vendor/rustix-0.38.37/src/backend/linux_raw/io_uring/syscalls.rs