1 // Copyright 2020 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 use std::io::Error;
6 use std::os::unix::io::RawFd;
7 use std::ptr::null_mut;
8
9 use libc::{c_int, c_long, c_void, syscall, SYS_io_uring_enter, SYS_io_uring_setup};
10
11 use crate::bindings::*;
12
13 /// Returns the system error as the result;
14 pub type Result<T> = std::result::Result<T, c_int>;
15
io_uring_setup(num_entries: usize, params: &io_uring_params) -> Result<RawFd>16 pub unsafe fn io_uring_setup(num_entries: usize, params: &io_uring_params) -> Result<RawFd> {
17 let ret = syscall(
18 SYS_io_uring_setup as c_long,
19 num_entries as c_int,
20 params as *const _,
21 );
22 if ret < 0 {
23 return Err(Error::last_os_error().raw_os_error().unwrap());
24 }
25 Ok(ret as RawFd)
26 }
27
io_uring_enter(fd: RawFd, to_submit: u64, to_wait: u64, flags: u32) -> Result<()>28 pub unsafe fn io_uring_enter(fd: RawFd, to_submit: u64, to_wait: u64, flags: u32) -> Result<()> {
29 let ret = syscall(
30 SYS_io_uring_enter as c_long,
31 fd,
32 to_submit as c_int,
33 to_wait as c_int,
34 flags as c_int,
35 null_mut::<*mut c_void>(),
36 );
37 if ret < 0 {
38 return Err(Error::last_os_error().raw_os_error().unwrap());
39 }
40 Ok(())
41 }
42