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