io_uring_syscall 0.1.2

linux io_uring syscall
Documentation
#![no_std]
#![allow(clippy::missing_safety_doc)]

use core::ffi::c_void;

use do_syscall::{do_syscall1, do_syscall2, do_syscall4, do_syscall6};

#[cfg(all(target_arch = "x86_64", target_os = "linux"))]
const NR_IO_URING_SETUP: u64 = 425;
#[cfg(all(target_arch = "aarch64", target_os = "linux"))]
const NR_IO_URING_SETUP: u64 = 425;
#[cfg(all(target_arch = "x86_64", target_os = "linux"))]
const NR_IO_URING_ENTER: u64 = 426;
#[cfg(all(target_arch = "aarch64", target_os = "linux"))]
const NR_IO_URING_ENTER: u64 = 426;
#[cfg(all(target_arch = "x86_64", target_os = "linux"))]
const NR_IO_URING_REGISTER: u64 = 427;
#[cfg(all(target_arch = "aarch64", target_os = "linux"))]
const NR_IO_URING_REGISTER: u64 = 427;
#[cfg(all(target_arch = "x86_64", target_os = "linux"))]
const NR_MMAP: u64 = 9;
#[cfg(all(target_arch = "aarch64", target_os = "linux"))]
const NR_MMAP: u64 = 222;
#[cfg(all(target_arch = "x86_64", target_os = "linux"))]
const NR_MUNMAP: u64 = 11;
#[cfg(all(target_arch = "aarch64", target_os = "linux"))]
const NR_MUNMAP: u64 = 215;
#[cfg(all(target_arch = "x86_64", target_os = "linux"))]
const NR_CLOSE: u64 = 3;
#[cfg(all(target_arch = "aarch64", target_os = "linux"))]
const NR_CLOSE: u64 = 57;

pub unsafe fn io_uring_setup(entries: u32, p: *mut c_void) -> i32 {
    do_syscall2(NR_IO_URING_SETUP, entries as _, p as _) as _
}

pub unsafe fn io_uring_enter2(
    fd: u32,
    to_submit: u32,
    min_complete: u32,
    flags: u32,
    sig: *mut c_void,
    sz: usize,
) -> i32 {
    do_syscall6(
        NR_IO_URING_ENTER,
        fd as _,
        to_submit as _,
        min_complete as _,
        flags as _,
        sig as _,
        sz as _,
    ) as _
}

pub unsafe fn io_uring_register(fd: u32, opcode: u32, arg: *mut c_void, nr_args: u32) -> i32 {
    do_syscall4(
        NR_IO_URING_REGISTER,
        fd as _,
        opcode as _,
        arg as _,
        nr_args as _,
    ) as _
}

pub unsafe fn mmap(
    addr: *mut c_void,
    length: usize,
    prot: i32,
    flags: i32,
    fd: i32,
    offset: isize,
) -> *mut c_void {
    do_syscall6(
        NR_MMAP,
        addr as _,
        length as _,
        prot as _,
        flags as _,
        fd as _,
        offset as _,
    ) as _
}

pub unsafe fn munmap(addr: *mut c_void, length: usize) -> i32 {
    do_syscall2(NR_MUNMAP, addr as _, length as _) as _
}

pub unsafe fn close(fd: i32) -> i32 {
    do_syscall1(NR_CLOSE, fd as _) as _
}