| 1 |
//! linux_raw syscalls supporting `rustix::io_uring`. |
| 2 |
//! |
| 3 |
//! # Safety |
| 4 |
//! |
| 5 |
//! See the `rustix::backend::syscalls` module documentation for details. |
| 6 |
#![allow(unsafe_code, clippy::undocumented_unsafe_blocks)] |
| 7 |
|
| 8 |
use crate::backend::conv::{by_mut, c_uint, pass_usize, ret_c_uint, ret_owned_fd}; |
| 9 |
use crate::fd::{BorrowedFd, OwnedFd}; |
| 10 |
use crate::io; |
| 11 |
use crate::io_uring::{io_uring_params, IoringEnterFlags, IoringRegisterOp}; |
| 12 |
use core::ffi::c_void; |
| 13 |
|
| 14 |
#[inline] |
| 15 |
pub(crate) fn io_uring_setup(entries: u32, params: &mut io_uring_params) -> io::Result<OwnedFd> { |
| 16 |
unsafe { |
| 17 |
ret_owned_fd(syscall!( |
| 18 |
__NR_io_uring_setup, |
| 19 |
c_uint(entries), |
| 20 |
by_mut(params) |
| 21 |
)) |
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
#[inline] |
| 26 |
pub(crate) unsafe fn io_uring_register( |
| 27 |
fd: BorrowedFd<'_>, |
| 28 |
opcode: IoringRegisterOp, |
| 29 |
arg: *const c_void, |
| 30 |
nr_args: u32, |
| 31 |
) -> io::Result<u32> { |
| 32 |
ret_c_uint(syscall_readonly!( |
| 33 |
__NR_io_uring_register, |
| 34 |
fd, |
| 35 |
c_uint(opcode as u32), |
| 36 |
arg, |
| 37 |
c_uint(nr_args) |
| 38 |
)) |
| 39 |
} |
| 40 |
|
| 41 |
#[inline] |
| 42 |
pub(crate) unsafe fn io_uring_enter( |
| 43 |
fd: BorrowedFd<'_>, |
| 44 |
to_submit: u32, |
| 45 |
min_complete: u32, |
| 46 |
flags: IoringEnterFlags, |
| 47 |
arg: *const c_void, |
| 48 |
size: usize, |
| 49 |
) -> io::Result<u32> { |
| 50 |
// This is not `_readonly` because `io_uring_enter` waits for I/O to |
| 51 |
// complete, and I/O could involve writing to memory buffers, which |
| 52 |
// could be a side effect depended on by the caller. |
| 53 |
ret_c_uint(syscall!( |
| 54 |
__NR_io_uring_enter, |
| 55 |
fd, |
| 56 |
c_uint(to_submit), |
| 57 |
c_uint(min_complete), |
| 58 |
flags, |
| 59 |
arg, |
| 60 |
pass_usize(size) |
| 61 |
)) |
| 62 |
} |