bytecodealliance / rustix

Safe Rust bindings to POSIX-ish APIs
Other
1.4k stars 142 forks source link

add io_uring_sqe64,io_uring_sqe128,io_uring_cqe16,io_uring_cqe32 #997

Open ghost opened 6 months ago

ghost commented 6 months ago
#[repr(C)]
#[derive(Clone, Copy)]
pub struct IoUringSqe<T: Copy> {
    pub opcode: rustix::io_uring::IoringOp,
    pub flags: rustix::io_uring::IoringSqeFlags,
    pub ioprio: rustix::io_uring::ioprio_union,
    pub fd: rustix::fd::RawFd,
    pub off_or_addr2: rustix::io_uring::off_or_addr2_union,
    pub addr_or_splice_off_in: rustix::io_uring::addr_or_splice_off_in_union,
    pub len: rustix::io_uring::len_union,
    pub op_flags: rustix::io_uring::op_flags_union,
    pub user_data: rustix::io_uring::io_uring_user_data,
    pub buf: rustix::io_uring::buf_union,
    pub personality: u16,
    pub splice_fd_in_or_file_index: rustix::io_uring::splice_fd_in_or_file_index_union,
    pub addr3_or_cmd: addr3_or_cmd_union<T>,
}

#[repr(C)]
#[derive(Copy, Clone)]
pub union addr3_or_cmd_union<T: Copy> {
    pub addr3: rustix::io_uring::addr3_struct,
    pub cmd: T,
}

pub type IoUringSqe64 = IoUringSqe<()>;
pub type IoUringSqe128 = IoUringSqe<[u8; 80]>;

#[repr(C)]
#[derive(Clone, Copy)]
pub struct IoUringCqe<T: Copy> {
    pub user_data: rustix::io_uring::io_uring_user_data,
    pub res: i32,
    pub flags: rustix::io_uring::IoringCqeFlags,
    pub big_cqe: T,
}

pub type IoUringCqe16 = IoUringCqe<()>;
pub type IoUringCqe32 = IoUringCqe<[u64; 2]>;
ghost commented 6 months ago

These structures originally had a fixed length, but for various reasons, kernel developers used flexible arrays. However, in Rust, we can use generics to make them better.