use core::ops::BitOr;
#[repr(i64)]
pub enum Syscall {
IoUringSetup = 425,
IoUringEnter = 426,
IoUringRegister = 427,
}
#[repr(u8)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum OpCode {
Nop = 0,
Readv = 1,
Writev = 2,
Fsync = 3,
ReadFixed = 4,
WriteFixed = 5,
PollAdd = 6,
PollRemove = 7,
SyncFileRange = 8,
Sendmsg = 9,
Recvmsg = 10,
Timeout = 11,
TimeoutRemove = 12,
Accept = 13,
AsyncCancel = 14,
LinkTimeout = 15,
Connect = 16,
Fallocate = 17,
Openat = 18,
Close = 19,
FilesUpdate = 20,
Statx = 21,
Read = 22,
Write = 23,
Fadvise = 24,
Madvise = 25,
Send = 26,
Recv = 27,
Openat2 = 28,
EpollCtl = 29,
Splice = 30,
ProvideBuffers = 31,
RemoveBuffers = 32,
Tee = 33,
Shutdown = 34,
Renameat = 35,
Unlinkat = 36,
Mkdirat = 37,
Symlinkat = 38,
Linkat = 39,
MsgRing = 40,
Fsetxattr = 41,
Setxattr = 42,
Fgetxattr = 43,
Getxattr = 44,
Socket = 45,
UringCmd = 46,
SendZc = 47,
SendMsgZc = 48,
}
#[repr(u32)]
#[derive(Debug, Clone, Copy)]
pub enum Setup {
IoPoll = 1 << 0,
SqPoll = 1 << 1,
SqAff = 1 << 2,
CqSize = 1 << 3,
Clamp = 1 << 4,
AttachWq = 1 << 5,
RDisabled = 1 << 6,
}
impl Setup {
pub const fn as_u32(self) -> u32 {
self as u32
}
pub const fn combine(self, other: Self) -> u32 {
self as u32 | other as u32
}
}
#[repr(u32)]
#[derive(Debug, Clone, Copy)]
pub enum Enter {
GetEvents = 1 << 0,
SqWakeup = 1 << 1,
SqWait = 1 << 2,
ExtArg = 1 << 3,
}
impl Enter {
pub const fn as_u32(self) -> u32 {
self as u32
}
pub const fn combine(self, other: Self) -> u32 {
self as u32 | other as u32
}
}
#[repr(u32)]
#[derive(Debug, Clone, Copy)]
pub enum Features {
SingleMmap = 1 << 0,
NoDrop = 1 << 1,
SubmitStable = 1 << 2,
RwCurPos = 1 << 3,
CurPersonality = 1 << 4,
FastPoll = 1 << 5,
Poll32Bits = 1 << 6,
SqPollNonFixed = 1 << 7,
ExtArg = 1 << 8,
NativeWorkers = 1 << 9,
RsrcTags = 1 << 10,
}
impl Features {
pub fn is_set(self, features: u32) -> bool {
features & (self as u32) != 0
}
}
#[repr(u64)]
#[derive(Debug, Clone, Copy)]
pub enum MmapOffset {
SqRing = 0,
CqRing = 0x8000000,
Sqes = 0x10000000,
}
impl MmapOffset {
pub const fn as_u64(self) -> u64 {
self as u64
}
}
#[repr(u8)]
#[derive(Debug, Clone, Copy)]
pub enum Submit {
FixedFile = 1 << 0,
IoDrain = 1 << 1,
IoLink = 1 << 2,
IoHardlink = 1 << 3,
Async = 1 << 4,
BufferSelect = 1 << 5,
CqeSkipSuccess = 1 << 6,
}
#[repr(u16)]
#[derive(Debug, Clone, Copy)]
pub enum SubmitExt {
Multishot = 1 << 0,
}
impl Submit {
pub const fn as_u8(self) -> u8 {
self as u8
}
pub const fn combine(self, other: Self) -> u8 {
self as u8 | other as u8
}
}
#[repr(u32)]
#[derive(Debug, Clone, Copy)]
pub enum Complete {
Buffer = 1 << 0,
More = 1 << 1,
SockNonempty = 1 << 2,
Notif = 1 << 3,
}
impl Complete {
pub fn is_set(self, flags: u32) -> bool {
flags & (self as u32) != 0
}
}
#[repr(u32)]
#[derive(Debug, Clone, Copy)]
pub enum AcceptFlag {
NonBlock = 0x800,
CloExec = 0x80000,
}
impl AcceptFlag {
pub const fn as_u32(self) -> u32 {
self as u32
}
}
#[repr(i32)]
#[derive(Debug, Clone, Copy)]
pub enum SocketDomain {
Unix = 1,
Inet = 2,
Inet6 = 10,
}
#[repr(i32)]
#[derive(Debug, Clone, Copy)]
pub enum SocketType {
Stream = 1,
Dgram = 2,
Raw = 3,
Rdm = 4,
SeqPacket = 5,
}
impl SocketType {
pub const fn with_flags(self, flags: i32) -> i32 {
self as i32 | flags
}
}
pub const SOCK_NONBLOCK: i32 = 0x800;
pub const SOCK_CLOEXEC: i32 = 0x80000;
#[repr(u32)]
#[derive(Debug, Clone, Copy)]
pub enum Register {
Buffers = 0,
UnregisterBuffers = 1,
Files = 2,
UnregisterFiles = 3,
EventFd = 4,
UnregisterEventFd = 5,
FilesUpdate = 6,
EventFdAsync = 7,
Probe = 8,
Personality = 9,
UnregisterPersonality = 10,
Restrictions = 11,
EnableRings = 12,
}
#[repr(i32)]
#[derive(Debug, Clone, Copy)]
pub enum Prot {
None = 0x0,
Read = 0x1,
Write = 0x2,
Exec = 0x4,
}
impl Prot {
pub const fn as_i32(self) -> i32 {
self as i32
}
}
impl BitOr for Prot {
type Output = i32;
fn bitor(self, rhs: Self) -> Self::Output {
self as i32 | rhs as i32
}
}
#[repr(i32)]
#[derive(Debug, Clone, Copy)]
pub enum Map {
Shared = 0x01,
Private = 0x02,
Fixed = 0x10,
Anonymous = 0x20,
Populate = 0x8000,
}
impl Map {
pub const fn as_i32(self) -> i32 {
self as i32
}
}
impl BitOr for Map {
type Output = i32;
fn bitor(self, rhs: Self) -> Self::Output {
self as i32 | rhs as i32
}
}
pub const MAP_FAILED: *mut core::ffi::c_void = !0 as *mut core::ffi::c_void;
#[repr(i32)]
#[derive(Debug, Clone, Copy)]
pub enum Madvise {
Normal = 0,
Random = 1,
Sequential = 2,
WillNeed = 3,
DontNeed = 4,
Remove = 9,
DontFork = 10,
DoFork = 11,
Mergeable = 12,
Unmergeable = 13,
HugePage = 14,
NoHugePage = 15,
DontDump = 16,
DoDump = 17,
HwPoison = 100,
}
#[repr(C)]
pub struct Sqe {
pub opcode: u8, pub flags: u8, pub ioprio: u16,
pub fd: i32,
pub off: u64,
pub addr: u64,
pub len: u32,
pub rw_flags: u32,
pub user_data: u64,
pub buf_index: u16,
pub personality: u16,
pub splice_fd_in: i32,
pub __pad2: [u64; 2],
}
impl Sqe {
pub fn set_opcode(&mut self, op: OpCode) {
self.opcode = op as u8;
}
pub fn set_flags(&mut self, flags: u8) {
self.flags = flags;
}
pub fn add_flag(&mut self, flag: Submit) {
self.flags |= flag as u8;
}
}
#[repr(C)]
pub struct Cqe {
pub user_data: u64,
pub res: i32,
pub flags: u32, }
impl Cqe {
pub fn has_flag(&self, flag: Complete) -> bool {
self.flags & (flag as u32) != 0
}
}
#[repr(C)]
pub struct SqringOffsets {
pub head: u32,
pub tail: u32,
pub ring_mask: u32,
pub ring_entries: u32,
pub flags: u32,
pub dropped: u32,
pub array: u32,
pub resv1: u32,
pub resv2: u64,
}
#[repr(C)]
pub struct CqringOffsets {
pub head: u32,
pub tail: u32,
pub ring_mask: u32,
pub ring_entries: u32,
pub overflow: u32,
pub cqes: u32,
pub flags: u32,
pub resv1: u32,
pub resv2: u64,
}
#[repr(C)]
pub struct Params {
pub sq_entries: u32,
pub cq_entries: u32,
pub flags: u32, pub sq_thread_cpu: u32,
pub sq_thread_idle: u32,
pub features: u32, pub wq_fd: u32,
pub resv: [u32; 3],
pub sq_off: SqringOffsets,
pub cq_off: CqringOffsets,
}
impl Params {
pub fn has_feature(&self, feature: Features) -> bool {
self.features & (feature as u32) != 0
}
}