mirror of
https://github.com/ziglang/zig.git
synced 2026-02-12 20:37:54 +00:00
std: add linux kernel definitions for io_uring
This commit is contained in:
parent
ae604b4464
commit
4565f50efe
@ -967,3 +967,129 @@ pub const stack_t = extern struct {
|
||||
ss_flags: i32,
|
||||
ss_size: isize,
|
||||
};
|
||||
|
||||
pub const io_uring_params = extern struct {
|
||||
sq_entries: u32,
|
||||
cq_entries: u32,
|
||||
flags: u32,
|
||||
sq_thread_cpu: u32,
|
||||
sq_thread_idle: u32,
|
||||
resv: [5]u32,
|
||||
sq_off: io_sqring_offsets,
|
||||
cq_off: io_cqring_offsets,
|
||||
};
|
||||
|
||||
// io_uring_params.flags
|
||||
|
||||
/// io_context is polled
|
||||
pub const IORING_SETUP_IOPOLL = (1 << 0);
|
||||
|
||||
/// SQ poll thread
|
||||
pub const IORING_SETUP_SQPOLL = (1 << 1);
|
||||
|
||||
/// sq_thread_cpu is valid
|
||||
pub const IORING_SETUP_SQ_AFF = (1 << 2);
|
||||
|
||||
pub const io_sqring_offsets = extern struct {
|
||||
/// offset of ring head
|
||||
head: u32,
|
||||
|
||||
/// offset of ring tail
|
||||
tail: u32,
|
||||
|
||||
/// ring mask value
|
||||
ring_mask: u32,
|
||||
|
||||
/// entries in ring
|
||||
ring_entries: u32,
|
||||
|
||||
/// ring flags
|
||||
flags: u32,
|
||||
|
||||
/// number of sqes not submitted
|
||||
dropped: u32,
|
||||
|
||||
/// sqe index array
|
||||
array: u32,
|
||||
|
||||
resv1: u32,
|
||||
resv2: u64,
|
||||
};
|
||||
|
||||
// io_sqring_offsets.flags
|
||||
|
||||
/// needs io_uring_enter wakeup
|
||||
pub const IORING_SQ_NEED_WAKEUP = 1 << 0;
|
||||
|
||||
pub const io_cqring_offsets = extern struct {
|
||||
head: u32,
|
||||
tail: u32,
|
||||
ring_mask: u32,
|
||||
ring_entries: u32,
|
||||
overflow: u32,
|
||||
cqes: u32,
|
||||
resv: [2]u64,
|
||||
};
|
||||
|
||||
pub const io_uring_sqe = extern struct {
|
||||
opcode: u8,
|
||||
flags: u8,
|
||||
ioprio: u16,
|
||||
fd: i32,
|
||||
off: u64,
|
||||
addr: u64,
|
||||
len: u32,
|
||||
pub const union1 = extern union {
|
||||
rw_flags: kernel_rwf,
|
||||
fsync_flags: u32,
|
||||
poll_event: u16,
|
||||
};
|
||||
union1: union1,
|
||||
user_data: u64,
|
||||
pub const union2 = extern union {
|
||||
buf_index: u16,
|
||||
__pad2: [3]u64,
|
||||
};
|
||||
union2: union2,
|
||||
};
|
||||
|
||||
// io_uring_sqe.flags
|
||||
|
||||
/// use fixed fileset
|
||||
pub const IOSQE_FIXED_FILE = (1 << 0);
|
||||
|
||||
pub const IORING_OP_NOP = 0;
|
||||
pub const IORING_OP_READV = 1;
|
||||
pub const IORING_OP_WRITEV = 2;
|
||||
pub const IORING_OP_FSYNC = 3;
|
||||
pub const IORING_OP_READ_FIXED = 4;
|
||||
pub const IORING_OP_WRITE_FIXED = 5;
|
||||
pub const IORING_OP_POLL_ADD = 6;
|
||||
pub const IORING_OP_POLL_REMOVE = 7;
|
||||
|
||||
// io_uring_sqe.fsync_flags
|
||||
pub const IORING_FSYNC_DATASYNC = (1 << 0);
|
||||
|
||||
// IO completion data structure (Completion Queue Entry)
|
||||
pub const io_uring_cqe = extern struct {
|
||||
/// io_uring_sqe.data submission passed back
|
||||
user_data: u64,
|
||||
|
||||
/// result code for this event
|
||||
res: i32,
|
||||
flags: u32,
|
||||
};
|
||||
|
||||
pub const IORING_OFF_SQ_RING = 0;
|
||||
pub const IORING_OFF_CQ_RING = 0x8000000;
|
||||
pub const IORING_OFF_SQES = 0x10000000;
|
||||
|
||||
// io_uring_enter flags
|
||||
pub const IORING_ENTER_GETEVENTS = (1 << 0);
|
||||
pub const IORING_ENTER_SQ_WAKEUP = (1 << 1);
|
||||
|
||||
// io_uring_register opcodes and arguments
|
||||
pub const IORING_REGISTER_BUFFERS = 0;
|
||||
pub const IORING_UNREGISTER_BUFFERS = 1;
|
||||
pub const IORING_REGISTER_FILES = 2;
|
||||
pub const IORING_UNREGISTER_FILES = 3;
|
||||
|
||||
@ -895,6 +895,18 @@ pub fn dl_iterate_phdr(comptime T: type, callback: extern fn (info: *dl_phdr_inf
|
||||
return last_r;
|
||||
}
|
||||
|
||||
pub fn io_uring_setup(entries: u32, p: *io_uring_params) usize {
|
||||
return syscall2(SYS_io_uring_setup, entries, @ptrToInt(p));
|
||||
}
|
||||
|
||||
pub fn io_uring_enter(fd: i32, to_submit: u32, min_complete: u32, flags: u32, sig: ?*sigset_t) usize {
|
||||
return syscall6(SYS_io_uring_enter, @bitCast(usize, isize(fd)), to_submit, min_complete, flags, @ptrToInt(sig), NSIG / 8);
|
||||
}
|
||||
|
||||
pub fn io_uring_register(fd: i32, opcode: u32, arg: ?*const c_void, nr_args: u32) usize {
|
||||
return syscall4(SYS_io_uring_register, @bitCast(usize, isize(fd)), opcode, @ptrToInt(arg), nr_args);
|
||||
}
|
||||
|
||||
test "" {
|
||||
if (is_the_target) {
|
||||
_ = @import("linux/test.zig");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user