Merge pull request #19214 from mlugg/fuck-usingnamespace

std: fuck usingnamespace
This commit is contained in:
Matthew Lugg
2024-03-08 21:59:07 +00:00
committed by GitHub
9 changed files with 2957 additions and 3053 deletions

View File

@@ -291,7 +291,8 @@ set(ZIG_STAGE2_SOURCES
"${CMAKE_SOURCE_DIR}/lib/std/os/linux/errno/generic.zig"
"${CMAKE_SOURCE_DIR}/lib/std/os/linux/x86_64.zig"
"${CMAKE_SOURCE_DIR}/lib/std/os/linux.zig"
"${CMAKE_SOURCE_DIR}/lib/std/os/linux/io_uring.zig"
"${CMAKE_SOURCE_DIR}/lib/std/os/linux/IoUring.zig"
"${CMAKE_SOURCE_DIR}/lib/std/os/linux/io_uring_sqe.zig"
"${CMAKE_SOURCE_DIR}/lib/std/os/linux/x86_64.zig"
"${CMAKE_SOURCE_DIR}/lib/std/os/windows.zig"
"${CMAKE_SOURCE_DIR}/lib/std/os/windows/ntstatus.zig"

View File

@@ -1494,38 +1494,33 @@ pub const speed_t = switch (native_os) {
pub const whence_t = if (native_os == .wasi) std.os.wasi.whence_t else c_int;
// Unix-like systems
pub usingnamespace switch (native_os) {
.netbsd, .windows => struct {},
else => struct {
pub const DIR = opaque {};
pub extern "c" fn opendir(pathname: [*:0]const u8) ?*DIR;
pub extern "c" fn fdopendir(fd: c_int) ?*DIR;
pub extern "c" fn rewinddir(dp: *DIR) void;
pub extern "c" fn closedir(dp: *DIR) c_int;
pub extern "c" fn telldir(dp: *DIR) c_long;
pub extern "c" fn seekdir(dp: *DIR, loc: c_long) void;
pub const DIR = opaque {};
pub extern "c" fn opendir(pathname: [*:0]const u8) ?*DIR;
pub extern "c" fn fdopendir(fd: c_int) ?*DIR;
pub extern "c" fn rewinddir(dp: *DIR) void;
pub extern "c" fn closedir(dp: *DIR) c_int;
pub extern "c" fn telldir(dp: *DIR) c_long;
pub extern "c" fn seekdir(dp: *DIR, loc: c_long) void;
pub extern "c" fn clock_gettime(clk_id: c_int, tp: *c.timespec) c_int;
pub extern "c" fn clock_getres(clk_id: c_int, tp: *c.timespec) c_int;
pub extern "c" fn gettimeofday(noalias tv: ?*c.timeval, noalias tz: ?*c.timezone) c_int;
pub extern "c" fn nanosleep(rqtp: *const c.timespec, rmtp: ?*c.timespec) c_int;
pub extern "c" fn clock_gettime(clk_id: c_int, tp: *c.timespec) c_int;
pub extern "c" fn clock_getres(clk_id: c_int, tp: *c.timespec) c_int;
pub extern "c" fn gettimeofday(noalias tv: ?*c.timeval, noalias tz: ?*c.timezone) c_int;
pub extern "c" fn nanosleep(rqtp: *const c.timespec, rmtp: ?*c.timespec) c_int;
pub extern "c" fn getrusage(who: c_int, usage: *c.rusage) c_int;
pub extern "c" fn getrusage(who: c_int, usage: *c.rusage) c_int;
pub extern "c" fn sched_yield() c_int;
pub extern "c" fn sched_yield() c_int;
pub extern "c" fn sigaction(sig: c_int, noalias act: ?*const c.Sigaction, noalias oact: ?*c.Sigaction) c_int;
pub extern "c" fn sigprocmask(how: c_int, noalias set: ?*const c.sigset_t, noalias oset: ?*c.sigset_t) c_int;
pub extern "c" fn sigfillset(set: ?*c.sigset_t) void;
pub extern "c" fn sigwait(set: ?*c.sigset_t, sig: ?*c_int) c_int;
pub extern "c" fn sigaction(sig: c_int, noalias act: ?*const c.Sigaction, noalias oact: ?*c.Sigaction) c_int;
pub extern "c" fn sigprocmask(how: c_int, noalias set: ?*const c.sigset_t, noalias oset: ?*c.sigset_t) c_int;
pub extern "c" fn sigfillset(set: ?*c.sigset_t) void;
pub extern "c" fn sigwait(set: ?*c.sigset_t, sig: ?*c_int) c_int;
pub extern "c" fn socket(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int;
pub extern "c" fn socket(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int;
pub extern "c" fn alarm(seconds: c_uint) c_uint;
pub extern "c" fn alarm(seconds: c_uint) c_uint;
pub extern "c" fn msync(addr: *align(page_size) const anyopaque, len: usize, flags: c_int) c_int;
},
};
pub extern "c" fn msync(addr: *align(page_size) const anyopaque, len: usize, flags: c_int) c_int;
pub const fstat = switch (native_os) {
.macos => switch (native_arch) {
@@ -1863,16 +1858,14 @@ pub extern "c" fn setlogmask(maskpri: c_int) c_int;
pub extern "c" fn if_nametoindex([*:0]const u8) c_int;
pub usingnamespace if (builtin.target.isAndroid()) struct {
// android bionic libc does not implement getcontext,
// and std.os.linux.getcontext also cannot be built for
// bionic libc currently.
} else if (native_os == .linux and builtin.target.isMusl()) struct {
// musl does not implement getcontext
pub const getcontext = std.os.linux.getcontext;
} else struct {
pub extern "c" fn getcontext(ucp: *std.os.ucontext_t) c_int;
};
pub const getcontext = if (builtin.target.isAndroid())
@compileError("android bionic libc does not implement getcontext")
else if (native_os == .linux and builtin.target.isMusl())
std.os.linux.getcontext
else
struct {
extern fn getcontext(ucp: *std.os.ucontext_t) c_int;
}.getcontext;
pub const max_align_t = if (native_abi == .msvc)
f64

View File

@@ -894,11 +894,6 @@ comptime {
std.debug.assert(@sizeOf(siginfo_t) == 136);
}
pub usingnamespace switch (builtin.cpu.arch) {
.x86_64 => struct {},
else => struct {},
};
pub const ucontext_t = switch (builtin.cpu.arch) {
.x86_64 => extern struct {
sc_rdi: c_long,

File diff suppressed because it is too large Load Diff

View File

@@ -383,25 +383,24 @@ pub const O = switch (native_arch) {
else => @compileError("missing std.os.linux.O constants for this architecture"),
};
pub usingnamespace @import("linux/io_uring.zig");
/// Set by startup code, used by `getauxval`.
pub var elf_aux_maybe: ?[*]std.elf.Auxv = null;
pub usingnamespace if (switch (builtin.zig_backend) {
const extern_getauxval = switch (builtin.zig_backend) {
// Calling extern functions is not yet supported with these backends
.stage2_aarch64, .stage2_arm, .stage2_riscv64, .stage2_sparc64 => false,
else => !builtin.link_libc,
}) struct {
/// See `std.elf` for the constants.
/// This matches the libc getauxval function.
pub extern fn getauxval(index: usize) usize;
comptime {
};
comptime {
if (extern_getauxval) {
@export(getauxvalImpl, .{ .name = "getauxval", .linkage = .Weak });
}
} else struct {
pub const getauxval = getauxvalImpl;
};
}
pub const getauxval = if (extern_getauxval) struct {
extern fn getauxval(index: usize) usize;
}.getauxval else getauxvalImpl;
fn getauxvalImpl(index: usize) callconv(.C) usize {
const auxv = elf_aux_maybe orelse return 0;
@@ -2823,284 +2822,282 @@ pub const AF = struct {
pub const MAX = PF.MAX;
};
pub const SO = struct {
pub usingnamespace if (is_mips) struct {
pub const DEBUG = 1;
pub const REUSEADDR = 0x0004;
pub const KEEPALIVE = 0x0008;
pub const DONTROUTE = 0x0010;
pub const BROADCAST = 0x0020;
pub const LINGER = 0x0080;
pub const OOBINLINE = 0x0100;
pub const REUSEPORT = 0x0200;
pub const SNDBUF = 0x1001;
pub const RCVBUF = 0x1002;
pub const SNDLOWAT = 0x1003;
pub const RCVLOWAT = 0x1004;
pub const RCVTIMEO = 0x1006;
pub const SNDTIMEO = 0x1005;
pub const ERROR = 0x1007;
pub const TYPE = 0x1008;
pub const ACCEPTCONN = 0x1009;
pub const PROTOCOL = 0x1028;
pub const DOMAIN = 0x1029;
pub const NO_CHECK = 11;
pub const PRIORITY = 12;
pub const BSDCOMPAT = 14;
pub const PASSCRED = 17;
pub const PEERCRED = 18;
pub const PEERSEC = 30;
pub const SNDBUFFORCE = 31;
pub const RCVBUFFORCE = 33;
pub const SECURITY_AUTHENTICATION = 22;
pub const SECURITY_ENCRYPTION_TRANSPORT = 23;
pub const SECURITY_ENCRYPTION_NETWORK = 24;
pub const BINDTODEVICE = 25;
pub const ATTACH_FILTER = 26;
pub const DETACH_FILTER = 27;
pub const GET_FILTER = ATTACH_FILTER;
pub const PEERNAME = 28;
pub const TIMESTAMP_OLD = 29;
pub const PASSSEC = 34;
pub const TIMESTAMPNS_OLD = 35;
pub const MARK = 36;
pub const TIMESTAMPING_OLD = 37;
pub const RXQ_OVFL = 40;
pub const WIFI_STATUS = 41;
pub const PEEK_OFF = 42;
pub const NOFCS = 43;
pub const LOCK_FILTER = 44;
pub const SELECT_ERR_QUEUE = 45;
pub const BUSY_POLL = 46;
pub const MAX_PACING_RATE = 47;
pub const BPF_EXTENSIONS = 48;
pub const INCOMING_CPU = 49;
pub const ATTACH_BPF = 50;
pub const DETACH_BPF = DETACH_FILTER;
pub const ATTACH_REUSEPORT_CBPF = 51;
pub const ATTACH_REUSEPORT_EBPF = 52;
pub const CNX_ADVICE = 53;
pub const MEMINFO = 55;
pub const INCOMING_NAPI_ID = 56;
pub const COOKIE = 57;
pub const PEERGROUPS = 59;
pub const ZEROCOPY = 60;
pub const TXTIME = 61;
pub const BINDTOIFINDEX = 62;
pub const TIMESTAMP_NEW = 63;
pub const TIMESTAMPNS_NEW = 64;
pub const TIMESTAMPING_NEW = 65;
pub const RCVTIMEO_NEW = 66;
pub const SNDTIMEO_NEW = 67;
pub const DETACH_REUSEPORT_BPF = 68;
} else if (is_ppc or is_ppc64) struct {
pub const DEBUG = 1;
pub const REUSEADDR = 2;
pub const TYPE = 3;
pub const ERROR = 4;
pub const DONTROUTE = 5;
pub const BROADCAST = 6;
pub const SNDBUF = 7;
pub const RCVBUF = 8;
pub const KEEPALIVE = 9;
pub const OOBINLINE = 10;
pub const NO_CHECK = 11;
pub const PRIORITY = 12;
pub const LINGER = 13;
pub const BSDCOMPAT = 14;
pub const REUSEPORT = 15;
pub const RCVLOWAT = 16;
pub const SNDLOWAT = 17;
pub const RCVTIMEO = 18;
pub const SNDTIMEO = 19;
pub const PASSCRED = 20;
pub const PEERCRED = 21;
pub const ACCEPTCONN = 30;
pub const PEERSEC = 31;
pub const SNDBUFFORCE = 32;
pub const RCVBUFFORCE = 33;
pub const PROTOCOL = 38;
pub const DOMAIN = 39;
pub const SECURITY_AUTHENTICATION = 22;
pub const SECURITY_ENCRYPTION_TRANSPORT = 23;
pub const SECURITY_ENCRYPTION_NETWORK = 24;
pub const BINDTODEVICE = 25;
pub const ATTACH_FILTER = 26;
pub const DETACH_FILTER = 27;
pub const GET_FILTER = ATTACH_FILTER;
pub const PEERNAME = 28;
pub const TIMESTAMP_OLD = 29;
pub const PASSSEC = 34;
pub const TIMESTAMPNS_OLD = 35;
pub const MARK = 36;
pub const TIMESTAMPING_OLD = 37;
pub const RXQ_OVFL = 40;
pub const WIFI_STATUS = 41;
pub const PEEK_OFF = 42;
pub const NOFCS = 43;
pub const LOCK_FILTER = 44;
pub const SELECT_ERR_QUEUE = 45;
pub const BUSY_POLL = 46;
pub const MAX_PACING_RATE = 47;
pub const BPF_EXTENSIONS = 48;
pub const INCOMING_CPU = 49;
pub const ATTACH_BPF = 50;
pub const DETACH_BPF = DETACH_FILTER;
pub const ATTACH_REUSEPORT_CBPF = 51;
pub const ATTACH_REUSEPORT_EBPF = 52;
pub const CNX_ADVICE = 53;
pub const MEMINFO = 55;
pub const INCOMING_NAPI_ID = 56;
pub const COOKIE = 57;
pub const PEERGROUPS = 59;
pub const ZEROCOPY = 60;
pub const TXTIME = 61;
pub const BINDTOIFINDEX = 62;
pub const TIMESTAMP_NEW = 63;
pub const TIMESTAMPNS_NEW = 64;
pub const TIMESTAMPING_NEW = 65;
pub const RCVTIMEO_NEW = 66;
pub const SNDTIMEO_NEW = 67;
pub const DETACH_REUSEPORT_BPF = 68;
} else if (is_sparc) struct {
pub const DEBUG = 1;
pub const REUSEADDR = 4;
pub const TYPE = 4104;
pub const ERROR = 4103;
pub const DONTROUTE = 16;
pub const BROADCAST = 32;
pub const SNDBUF = 4097;
pub const RCVBUF = 4098;
pub const KEEPALIVE = 8;
pub const OOBINLINE = 256;
pub const NO_CHECK = 11;
pub const PRIORITY = 12;
pub const LINGER = 128;
pub const BSDCOMPAT = 1024;
pub const REUSEPORT = 512;
pub const PASSCRED = 2;
pub const PEERCRED = 64;
pub const RCVLOWAT = 2048;
pub const SNDLOWAT = 4096;
pub const RCVTIMEO = 8192;
pub const SNDTIMEO = 16384;
pub const ACCEPTCONN = 32768;
pub const PEERSEC = 30;
pub const SNDBUFFORCE = 4106;
pub const RCVBUFFORCE = 4107;
pub const PROTOCOL = 4136;
pub const DOMAIN = 4137;
pub const SECURITY_AUTHENTICATION = 20481;
pub const SECURITY_ENCRYPTION_TRANSPORT = 20482;
pub const SECURITY_ENCRYPTION_NETWORK = 20484;
pub const BINDTODEVICE = 13;
pub const ATTACH_FILTER = 26;
pub const DETACH_FILTER = 27;
pub const GET_FILTER = 26;
pub const PEERNAME = 28;
pub const TIMESTAMP_OLD = 29;
pub const PASSSEC = 31;
pub const TIMESTAMPNS_OLD = 33;
pub const MARK = 34;
pub const TIMESTAMPING_OLD = 35;
pub const RXQ_OVFL = 36;
pub const WIFI_STATUS = 37;
pub const PEEK_OFF = 38;
pub const NOFCS = 39;
pub const LOCK_FILTER = 40;
pub const SELECT_ERR_QUEUE = 41;
pub const BUSY_POLL = 48;
pub const MAX_PACING_RATE = 49;
pub const BPF_EXTENSIONS = 50;
pub const INCOMING_CPU = 51;
pub const ATTACH_BPF = 52;
pub const DETACH_BPF = 27;
pub const ATTACH_REUSEPORT_CBPF = 53;
pub const ATTACH_REUSEPORT_EBPF = 54;
pub const CNX_ADVICE = 55;
pub const MEMINFO = 57;
pub const INCOMING_NAPI_ID = 58;
pub const COOKIE = 59;
pub const PEERGROUPS = 61;
pub const ZEROCOPY = 62;
pub const TXTIME = 63;
pub const BINDTOIFINDEX = 65;
pub const TIMESTAMP_NEW = 70;
pub const TIMESTAMPNS_NEW = 66;
pub const TIMESTAMPING_NEW = 67;
pub const RCVTIMEO_NEW = 68;
pub const SNDTIMEO_NEW = 69;
pub const DETACH_REUSEPORT_BPF = 71;
} else struct {
pub const DEBUG = 1;
pub const REUSEADDR = 2;
pub const TYPE = 3;
pub const ERROR = 4;
pub const DONTROUTE = 5;
pub const BROADCAST = 6;
pub const SNDBUF = 7;
pub const RCVBUF = 8;
pub const KEEPALIVE = 9;
pub const OOBINLINE = 10;
pub const NO_CHECK = 11;
pub const PRIORITY = 12;
pub const LINGER = 13;
pub const BSDCOMPAT = 14;
pub const REUSEPORT = 15;
pub const PASSCRED = 16;
pub const PEERCRED = 17;
pub const RCVLOWAT = 18;
pub const SNDLOWAT = 19;
pub const RCVTIMEO = 20;
pub const SNDTIMEO = 21;
pub const ACCEPTCONN = 30;
pub const PEERSEC = 31;
pub const SNDBUFFORCE = 32;
pub const RCVBUFFORCE = 33;
pub const PROTOCOL = 38;
pub const DOMAIN = 39;
pub const SECURITY_AUTHENTICATION = 22;
pub const SECURITY_ENCRYPTION_TRANSPORT = 23;
pub const SECURITY_ENCRYPTION_NETWORK = 24;
pub const BINDTODEVICE = 25;
pub const ATTACH_FILTER = 26;
pub const DETACH_FILTER = 27;
pub const GET_FILTER = ATTACH_FILTER;
pub const PEERNAME = 28;
pub const TIMESTAMP_OLD = 29;
pub const PASSSEC = 34;
pub const TIMESTAMPNS_OLD = 35;
pub const MARK = 36;
pub const TIMESTAMPING_OLD = 37;
pub const RXQ_OVFL = 40;
pub const WIFI_STATUS = 41;
pub const PEEK_OFF = 42;
pub const NOFCS = 43;
pub const LOCK_FILTER = 44;
pub const SELECT_ERR_QUEUE = 45;
pub const BUSY_POLL = 46;
pub const MAX_PACING_RATE = 47;
pub const BPF_EXTENSIONS = 48;
pub const INCOMING_CPU = 49;
pub const ATTACH_BPF = 50;
pub const DETACH_BPF = DETACH_FILTER;
pub const ATTACH_REUSEPORT_CBPF = 51;
pub const ATTACH_REUSEPORT_EBPF = 52;
pub const CNX_ADVICE = 53;
pub const MEMINFO = 55;
pub const INCOMING_NAPI_ID = 56;
pub const COOKIE = 57;
pub const PEERGROUPS = 59;
pub const ZEROCOPY = 60;
pub const TXTIME = 61;
pub const BINDTOIFINDEX = 62;
pub const TIMESTAMP_NEW = 63;
pub const TIMESTAMPNS_NEW = 64;
pub const TIMESTAMPING_NEW = 65;
pub const RCVTIMEO_NEW = 66;
pub const SNDTIMEO_NEW = 67;
pub const DETACH_REUSEPORT_BPF = 68;
};
pub const SO = if (is_mips) struct {
pub const DEBUG = 1;
pub const REUSEADDR = 0x0004;
pub const KEEPALIVE = 0x0008;
pub const DONTROUTE = 0x0010;
pub const BROADCAST = 0x0020;
pub const LINGER = 0x0080;
pub const OOBINLINE = 0x0100;
pub const REUSEPORT = 0x0200;
pub const SNDBUF = 0x1001;
pub const RCVBUF = 0x1002;
pub const SNDLOWAT = 0x1003;
pub const RCVLOWAT = 0x1004;
pub const RCVTIMEO = 0x1006;
pub const SNDTIMEO = 0x1005;
pub const ERROR = 0x1007;
pub const TYPE = 0x1008;
pub const ACCEPTCONN = 0x1009;
pub const PROTOCOL = 0x1028;
pub const DOMAIN = 0x1029;
pub const NO_CHECK = 11;
pub const PRIORITY = 12;
pub const BSDCOMPAT = 14;
pub const PASSCRED = 17;
pub const PEERCRED = 18;
pub const PEERSEC = 30;
pub const SNDBUFFORCE = 31;
pub const RCVBUFFORCE = 33;
pub const SECURITY_AUTHENTICATION = 22;
pub const SECURITY_ENCRYPTION_TRANSPORT = 23;
pub const SECURITY_ENCRYPTION_NETWORK = 24;
pub const BINDTODEVICE = 25;
pub const ATTACH_FILTER = 26;
pub const DETACH_FILTER = 27;
pub const GET_FILTER = ATTACH_FILTER;
pub const PEERNAME = 28;
pub const TIMESTAMP_OLD = 29;
pub const PASSSEC = 34;
pub const TIMESTAMPNS_OLD = 35;
pub const MARK = 36;
pub const TIMESTAMPING_OLD = 37;
pub const RXQ_OVFL = 40;
pub const WIFI_STATUS = 41;
pub const PEEK_OFF = 42;
pub const NOFCS = 43;
pub const LOCK_FILTER = 44;
pub const SELECT_ERR_QUEUE = 45;
pub const BUSY_POLL = 46;
pub const MAX_PACING_RATE = 47;
pub const BPF_EXTENSIONS = 48;
pub const INCOMING_CPU = 49;
pub const ATTACH_BPF = 50;
pub const DETACH_BPF = DETACH_FILTER;
pub const ATTACH_REUSEPORT_CBPF = 51;
pub const ATTACH_REUSEPORT_EBPF = 52;
pub const CNX_ADVICE = 53;
pub const MEMINFO = 55;
pub const INCOMING_NAPI_ID = 56;
pub const COOKIE = 57;
pub const PEERGROUPS = 59;
pub const ZEROCOPY = 60;
pub const TXTIME = 61;
pub const BINDTOIFINDEX = 62;
pub const TIMESTAMP_NEW = 63;
pub const TIMESTAMPNS_NEW = 64;
pub const TIMESTAMPING_NEW = 65;
pub const RCVTIMEO_NEW = 66;
pub const SNDTIMEO_NEW = 67;
pub const DETACH_REUSEPORT_BPF = 68;
} else if (is_ppc or is_ppc64) struct {
pub const DEBUG = 1;
pub const REUSEADDR = 2;
pub const TYPE = 3;
pub const ERROR = 4;
pub const DONTROUTE = 5;
pub const BROADCAST = 6;
pub const SNDBUF = 7;
pub const RCVBUF = 8;
pub const KEEPALIVE = 9;
pub const OOBINLINE = 10;
pub const NO_CHECK = 11;
pub const PRIORITY = 12;
pub const LINGER = 13;
pub const BSDCOMPAT = 14;
pub const REUSEPORT = 15;
pub const RCVLOWAT = 16;
pub const SNDLOWAT = 17;
pub const RCVTIMEO = 18;
pub const SNDTIMEO = 19;
pub const PASSCRED = 20;
pub const PEERCRED = 21;
pub const ACCEPTCONN = 30;
pub const PEERSEC = 31;
pub const SNDBUFFORCE = 32;
pub const RCVBUFFORCE = 33;
pub const PROTOCOL = 38;
pub const DOMAIN = 39;
pub const SECURITY_AUTHENTICATION = 22;
pub const SECURITY_ENCRYPTION_TRANSPORT = 23;
pub const SECURITY_ENCRYPTION_NETWORK = 24;
pub const BINDTODEVICE = 25;
pub const ATTACH_FILTER = 26;
pub const DETACH_FILTER = 27;
pub const GET_FILTER = ATTACH_FILTER;
pub const PEERNAME = 28;
pub const TIMESTAMP_OLD = 29;
pub const PASSSEC = 34;
pub const TIMESTAMPNS_OLD = 35;
pub const MARK = 36;
pub const TIMESTAMPING_OLD = 37;
pub const RXQ_OVFL = 40;
pub const WIFI_STATUS = 41;
pub const PEEK_OFF = 42;
pub const NOFCS = 43;
pub const LOCK_FILTER = 44;
pub const SELECT_ERR_QUEUE = 45;
pub const BUSY_POLL = 46;
pub const MAX_PACING_RATE = 47;
pub const BPF_EXTENSIONS = 48;
pub const INCOMING_CPU = 49;
pub const ATTACH_BPF = 50;
pub const DETACH_BPF = DETACH_FILTER;
pub const ATTACH_REUSEPORT_CBPF = 51;
pub const ATTACH_REUSEPORT_EBPF = 52;
pub const CNX_ADVICE = 53;
pub const MEMINFO = 55;
pub const INCOMING_NAPI_ID = 56;
pub const COOKIE = 57;
pub const PEERGROUPS = 59;
pub const ZEROCOPY = 60;
pub const TXTIME = 61;
pub const BINDTOIFINDEX = 62;
pub const TIMESTAMP_NEW = 63;
pub const TIMESTAMPNS_NEW = 64;
pub const TIMESTAMPING_NEW = 65;
pub const RCVTIMEO_NEW = 66;
pub const SNDTIMEO_NEW = 67;
pub const DETACH_REUSEPORT_BPF = 68;
} else if (is_sparc) struct {
pub const DEBUG = 1;
pub const REUSEADDR = 4;
pub const TYPE = 4104;
pub const ERROR = 4103;
pub const DONTROUTE = 16;
pub const BROADCAST = 32;
pub const SNDBUF = 4097;
pub const RCVBUF = 4098;
pub const KEEPALIVE = 8;
pub const OOBINLINE = 256;
pub const NO_CHECK = 11;
pub const PRIORITY = 12;
pub const LINGER = 128;
pub const BSDCOMPAT = 1024;
pub const REUSEPORT = 512;
pub const PASSCRED = 2;
pub const PEERCRED = 64;
pub const RCVLOWAT = 2048;
pub const SNDLOWAT = 4096;
pub const RCVTIMEO = 8192;
pub const SNDTIMEO = 16384;
pub const ACCEPTCONN = 32768;
pub const PEERSEC = 30;
pub const SNDBUFFORCE = 4106;
pub const RCVBUFFORCE = 4107;
pub const PROTOCOL = 4136;
pub const DOMAIN = 4137;
pub const SECURITY_AUTHENTICATION = 20481;
pub const SECURITY_ENCRYPTION_TRANSPORT = 20482;
pub const SECURITY_ENCRYPTION_NETWORK = 20484;
pub const BINDTODEVICE = 13;
pub const ATTACH_FILTER = 26;
pub const DETACH_FILTER = 27;
pub const GET_FILTER = 26;
pub const PEERNAME = 28;
pub const TIMESTAMP_OLD = 29;
pub const PASSSEC = 31;
pub const TIMESTAMPNS_OLD = 33;
pub const MARK = 34;
pub const TIMESTAMPING_OLD = 35;
pub const RXQ_OVFL = 36;
pub const WIFI_STATUS = 37;
pub const PEEK_OFF = 38;
pub const NOFCS = 39;
pub const LOCK_FILTER = 40;
pub const SELECT_ERR_QUEUE = 41;
pub const BUSY_POLL = 48;
pub const MAX_PACING_RATE = 49;
pub const BPF_EXTENSIONS = 50;
pub const INCOMING_CPU = 51;
pub const ATTACH_BPF = 52;
pub const DETACH_BPF = 27;
pub const ATTACH_REUSEPORT_CBPF = 53;
pub const ATTACH_REUSEPORT_EBPF = 54;
pub const CNX_ADVICE = 55;
pub const MEMINFO = 57;
pub const INCOMING_NAPI_ID = 58;
pub const COOKIE = 59;
pub const PEERGROUPS = 61;
pub const ZEROCOPY = 62;
pub const TXTIME = 63;
pub const BINDTOIFINDEX = 65;
pub const TIMESTAMP_NEW = 70;
pub const TIMESTAMPNS_NEW = 66;
pub const TIMESTAMPING_NEW = 67;
pub const RCVTIMEO_NEW = 68;
pub const SNDTIMEO_NEW = 69;
pub const DETACH_REUSEPORT_BPF = 71;
} else struct {
pub const DEBUG = 1;
pub const REUSEADDR = 2;
pub const TYPE = 3;
pub const ERROR = 4;
pub const DONTROUTE = 5;
pub const BROADCAST = 6;
pub const SNDBUF = 7;
pub const RCVBUF = 8;
pub const KEEPALIVE = 9;
pub const OOBINLINE = 10;
pub const NO_CHECK = 11;
pub const PRIORITY = 12;
pub const LINGER = 13;
pub const BSDCOMPAT = 14;
pub const REUSEPORT = 15;
pub const PASSCRED = 16;
pub const PEERCRED = 17;
pub const RCVLOWAT = 18;
pub const SNDLOWAT = 19;
pub const RCVTIMEO = 20;
pub const SNDTIMEO = 21;
pub const ACCEPTCONN = 30;
pub const PEERSEC = 31;
pub const SNDBUFFORCE = 32;
pub const RCVBUFFORCE = 33;
pub const PROTOCOL = 38;
pub const DOMAIN = 39;
pub const SECURITY_AUTHENTICATION = 22;
pub const SECURITY_ENCRYPTION_TRANSPORT = 23;
pub const SECURITY_ENCRYPTION_NETWORK = 24;
pub const BINDTODEVICE = 25;
pub const ATTACH_FILTER = 26;
pub const DETACH_FILTER = 27;
pub const GET_FILTER = ATTACH_FILTER;
pub const PEERNAME = 28;
pub const TIMESTAMP_OLD = 29;
pub const PASSSEC = 34;
pub const TIMESTAMPNS_OLD = 35;
pub const MARK = 36;
pub const TIMESTAMPING_OLD = 37;
pub const RXQ_OVFL = 40;
pub const WIFI_STATUS = 41;
pub const PEEK_OFF = 42;
pub const NOFCS = 43;
pub const LOCK_FILTER = 44;
pub const SELECT_ERR_QUEUE = 45;
pub const BUSY_POLL = 46;
pub const MAX_PACING_RATE = 47;
pub const BPF_EXTENSIONS = 48;
pub const INCOMING_CPU = 49;
pub const ATTACH_BPF = 50;
pub const DETACH_BPF = DETACH_FILTER;
pub const ATTACH_REUSEPORT_CBPF = 51;
pub const ATTACH_REUSEPORT_EBPF = 52;
pub const CNX_ADVICE = 53;
pub const MEMINFO = 55;
pub const INCOMING_NAPI_ID = 56;
pub const COOKIE = 57;
pub const PEERGROUPS = 59;
pub const ZEROCOPY = 60;
pub const TXTIME = 61;
pub const BINDTOIFINDEX = 62;
pub const TIMESTAMP_NEW = 63;
pub const TIMESTAMPNS_NEW = 64;
pub const TIMESTAMPING_NEW = 65;
pub const RCVTIMEO_NEW = 66;
pub const SNDTIMEO_NEW = 67;
pub const DETACH_REUSEPORT_BPF = 68;
};
pub const SCM = struct {
@@ -4189,22 +4186,9 @@ pub const IORING_SETUP_SINGLE_ISSUER = 1 << 12;
pub const IORING_SETUP_DEFER_TASKRUN = 1 << 13;
/// IO submission data structure (Submission Queue Entry)
pub const io_uring_sqe = extern struct {
opcode: IORING_OP,
flags: u8,
ioprio: u16,
fd: i32,
off: u64,
addr: u64,
len: u32,
rw_flags: u32,
user_data: u64,
buf_index: u16,
personality: u16,
splice_fd_in: i32,
addr3: u64,
resv: u64,
};
pub const io_uring_sqe = @import("linux/io_uring_sqe.zig").io_uring_sqe;
pub const IoUring = @import("linux/IoUring.zig");
/// If sqe->file_index is set to this for opcodes that instantiate a new
/// direct descriptor (like openat/openat2/accept), then io_uring will allocate

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,579 @@
//! Contains only the definition of `io_uring_sqe`.
//! Split into its own file to compartmentalize the initialization methods.
const std = @import("../../std.zig");
const os = std.os;
const linux = os.linux;
pub const io_uring_sqe = extern struct {
opcode: linux.IORING_OP,
flags: u8,
ioprio: u16,
fd: i32,
off: u64,
addr: u64,
len: u32,
rw_flags: u32,
user_data: u64,
buf_index: u16,
personality: u16,
splice_fd_in: i32,
addr3: u64,
resv: u64,
pub fn prep_nop(sqe: *linux.io_uring_sqe) void {
sqe.* = .{
.opcode = .NOP,
.flags = 0,
.ioprio = 0,
.fd = 0,
.off = 0,
.addr = 0,
.len = 0,
.rw_flags = 0,
.user_data = 0,
.buf_index = 0,
.personality = 0,
.splice_fd_in = 0,
.addr3 = 0,
.resv = 0,
};
}
pub fn prep_fsync(sqe: *linux.io_uring_sqe, fd: os.fd_t, flags: u32) void {
sqe.* = .{
.opcode = .FSYNC,
.flags = 0,
.ioprio = 0,
.fd = fd,
.off = 0,
.addr = 0,
.len = 0,
.rw_flags = flags,
.user_data = 0,
.buf_index = 0,
.personality = 0,
.splice_fd_in = 0,
.addr3 = 0,
.resv = 0,
};
}
pub fn prep_rw(
sqe: *linux.io_uring_sqe,
op: linux.IORING_OP,
fd: os.fd_t,
addr: u64,
len: usize,
offset: u64,
) void {
sqe.* = .{
.opcode = op,
.flags = 0,
.ioprio = 0,
.fd = fd,
.off = offset,
.addr = addr,
.len = @intCast(len),
.rw_flags = 0,
.user_data = 0,
.buf_index = 0,
.personality = 0,
.splice_fd_in = 0,
.addr3 = 0,
.resv = 0,
};
}
pub fn prep_read(sqe: *linux.io_uring_sqe, fd: os.fd_t, buffer: []u8, offset: u64) void {
sqe.prep_rw(.READ, fd, @intFromPtr(buffer.ptr), buffer.len, offset);
}
pub fn prep_write(sqe: *linux.io_uring_sqe, fd: os.fd_t, buffer: []const u8, offset: u64) void {
sqe.prep_rw(.WRITE, fd, @intFromPtr(buffer.ptr), buffer.len, offset);
}
pub fn prep_splice(sqe: *linux.io_uring_sqe, fd_in: os.fd_t, off_in: u64, fd_out: os.fd_t, off_out: u64, len: usize) void {
sqe.prep_rw(.SPLICE, fd_out, undefined, len, off_out);
sqe.addr = off_in;
sqe.splice_fd_in = fd_in;
}
pub fn prep_readv(
sqe: *linux.io_uring_sqe,
fd: os.fd_t,
iovecs: []const os.iovec,
offset: u64,
) void {
sqe.prep_rw(.READV, fd, @intFromPtr(iovecs.ptr), iovecs.len, offset);
}
pub fn prep_writev(
sqe: *linux.io_uring_sqe,
fd: os.fd_t,
iovecs: []const os.iovec_const,
offset: u64,
) void {
sqe.prep_rw(.WRITEV, fd, @intFromPtr(iovecs.ptr), iovecs.len, offset);
}
pub fn prep_read_fixed(sqe: *linux.io_uring_sqe, fd: os.fd_t, buffer: *os.iovec, offset: u64, buffer_index: u16) void {
sqe.prep_rw(.READ_FIXED, fd, @intFromPtr(buffer.iov_base), buffer.iov_len, offset);
sqe.buf_index = buffer_index;
}
pub fn prep_write_fixed(sqe: *linux.io_uring_sqe, fd: os.fd_t, buffer: *os.iovec, offset: u64, buffer_index: u16) void {
sqe.prep_rw(.WRITE_FIXED, fd, @intFromPtr(buffer.iov_base), buffer.iov_len, offset);
sqe.buf_index = buffer_index;
}
pub fn prep_accept(
sqe: *linux.io_uring_sqe,
fd: os.fd_t,
addr: ?*os.sockaddr,
addrlen: ?*os.socklen_t,
flags: u32,
) void {
// `addr` holds a pointer to `sockaddr`, and `addr2` holds a pointer to socklen_t`.
// `addr2` maps to `sqe.off` (u64) instead of `sqe.len` (which is only a u32).
sqe.prep_rw(.ACCEPT, fd, @intFromPtr(addr), 0, @intFromPtr(addrlen));
sqe.rw_flags = flags;
}
pub fn prep_accept_direct(
sqe: *linux.io_uring_sqe,
fd: os.fd_t,
addr: ?*os.sockaddr,
addrlen: ?*os.socklen_t,
flags: u32,
file_index: u32,
) void {
prep_accept(sqe, fd, addr, addrlen, flags);
__io_uring_set_target_fixed_file(sqe, file_index);
}
pub fn prep_multishot_accept_direct(
sqe: *linux.io_uring_sqe,
fd: os.fd_t,
addr: ?*os.sockaddr,
addrlen: ?*os.socklen_t,
flags: u32,
) void {
prep_multishot_accept(sqe, fd, addr, addrlen, flags);
__io_uring_set_target_fixed_file(sqe, linux.IORING_FILE_INDEX_ALLOC);
}
fn __io_uring_set_target_fixed_file(sqe: *linux.io_uring_sqe, file_index: u32) void {
const sqe_file_index: u32 = if (file_index == linux.IORING_FILE_INDEX_ALLOC)
linux.IORING_FILE_INDEX_ALLOC
else
// 0 means no fixed files, indexes should be encoded as "index + 1"
file_index + 1;
// This filed is overloaded in liburing:
// splice_fd_in: i32
// sqe_file_index: u32
sqe.splice_fd_in = @bitCast(sqe_file_index);
}
pub fn prep_connect(
sqe: *linux.io_uring_sqe,
fd: os.fd_t,
addr: *const os.sockaddr,
addrlen: os.socklen_t,
) void {
// `addrlen` maps to `sqe.off` (u64) instead of `sqe.len` (which is only a u32).
sqe.prep_rw(.CONNECT, fd, @intFromPtr(addr), 0, addrlen);
}
pub fn prep_epoll_ctl(
sqe: *linux.io_uring_sqe,
epfd: os.fd_t,
fd: os.fd_t,
op: u32,
ev: ?*linux.epoll_event,
) void {
sqe.prep_rw(.EPOLL_CTL, epfd, @intFromPtr(ev), op, @intCast(fd));
}
pub fn prep_recv(sqe: *linux.io_uring_sqe, fd: os.fd_t, buffer: []u8, flags: u32) void {
sqe.prep_rw(.RECV, fd, @intFromPtr(buffer.ptr), buffer.len, 0);
sqe.rw_flags = flags;
}
pub fn prep_send(sqe: *linux.io_uring_sqe, fd: os.fd_t, buffer: []const u8, flags: u32) void {
sqe.prep_rw(.SEND, fd, @intFromPtr(buffer.ptr), buffer.len, 0);
sqe.rw_flags = flags;
}
pub fn prep_send_zc(sqe: *linux.io_uring_sqe, fd: os.fd_t, buffer: []const u8, flags: u32, zc_flags: u16) void {
sqe.prep_rw(.SEND_ZC, fd, @intFromPtr(buffer.ptr), buffer.len, 0);
sqe.rw_flags = flags;
sqe.ioprio = zc_flags;
}
pub fn prep_send_zc_fixed(sqe: *linux.io_uring_sqe, fd: os.fd_t, buffer: []const u8, flags: u32, zc_flags: u16, buf_index: u16) void {
prep_send_zc(sqe, fd, buffer, flags, zc_flags);
sqe.ioprio |= linux.IORING_RECVSEND_FIXED_BUF;
sqe.buf_index = buf_index;
}
pub fn prep_sendmsg_zc(
sqe: *linux.io_uring_sqe,
fd: os.fd_t,
msg: *const os.msghdr_const,
flags: u32,
) void {
prep_sendmsg(sqe, fd, msg, flags);
sqe.opcode = .SENDMSG_ZC;
}
pub fn prep_recvmsg(
sqe: *linux.io_uring_sqe,
fd: os.fd_t,
msg: *os.msghdr,
flags: u32,
) void {
sqe.prep_rw(.RECVMSG, fd, @intFromPtr(msg), 1, 0);
sqe.rw_flags = flags;
}
pub fn prep_sendmsg(
sqe: *linux.io_uring_sqe,
fd: os.fd_t,
msg: *const os.msghdr_const,
flags: u32,
) void {
sqe.prep_rw(.SENDMSG, fd, @intFromPtr(msg), 1, 0);
sqe.rw_flags = flags;
}
pub fn prep_openat(
sqe: *linux.io_uring_sqe,
fd: os.fd_t,
path: [*:0]const u8,
flags: linux.O,
mode: os.mode_t,
) void {
sqe.prep_rw(.OPENAT, fd, @intFromPtr(path), mode, 0);
sqe.rw_flags = @bitCast(flags);
}
pub fn prep_openat_direct(
sqe: *linux.io_uring_sqe,
fd: os.fd_t,
path: [*:0]const u8,
flags: linux.O,
mode: os.mode_t,
file_index: u32,
) void {
prep_openat(sqe, fd, path, flags, mode);
__io_uring_set_target_fixed_file(sqe, file_index);
}
pub fn prep_close(sqe: *linux.io_uring_sqe, fd: os.fd_t) void {
sqe.* = .{
.opcode = .CLOSE,
.flags = 0,
.ioprio = 0,
.fd = fd,
.off = 0,
.addr = 0,
.len = 0,
.rw_flags = 0,
.user_data = 0,
.buf_index = 0,
.personality = 0,
.splice_fd_in = 0,
.addr3 = 0,
.resv = 0,
};
}
pub fn prep_close_direct(sqe: *linux.io_uring_sqe, file_index: u32) void {
prep_close(sqe, 0);
__io_uring_set_target_fixed_file(sqe, file_index);
}
pub fn prep_timeout(
sqe: *linux.io_uring_sqe,
ts: *const os.linux.kernel_timespec,
count: u32,
flags: u32,
) void {
sqe.prep_rw(.TIMEOUT, -1, @intFromPtr(ts), 1, count);
sqe.rw_flags = flags;
}
pub fn prep_timeout_remove(sqe: *linux.io_uring_sqe, timeout_user_data: u64, flags: u32) void {
sqe.* = .{
.opcode = .TIMEOUT_REMOVE,
.flags = 0,
.ioprio = 0,
.fd = -1,
.off = 0,
.addr = timeout_user_data,
.len = 0,
.rw_flags = flags,
.user_data = 0,
.buf_index = 0,
.personality = 0,
.splice_fd_in = 0,
.addr3 = 0,
.resv = 0,
};
}
pub fn prep_link_timeout(
sqe: *linux.io_uring_sqe,
ts: *const os.linux.kernel_timespec,
flags: u32,
) void {
sqe.prep_rw(.LINK_TIMEOUT, -1, @intFromPtr(ts), 1, 0);
sqe.rw_flags = flags;
}
pub fn prep_poll_add(
sqe: *linux.io_uring_sqe,
fd: os.fd_t,
poll_mask: u32,
) void {
sqe.prep_rw(.POLL_ADD, fd, @intFromPtr(@as(?*anyopaque, null)), 0, 0);
// Poll masks previously used to comprise of 16 bits in the flags union of
// a SQE, but were then extended to comprise of 32 bits in order to make
// room for additional option flags. To ensure that the correct bits of
// poll masks are consistently and properly read across multiple kernel
// versions, poll masks are enforced to be little-endian.
// https://www.spinics.net/lists/io-uring/msg02848.html
sqe.rw_flags = std.mem.nativeToLittle(u32, poll_mask);
}
pub fn prep_poll_remove(
sqe: *linux.io_uring_sqe,
target_user_data: u64,
) void {
sqe.prep_rw(.POLL_REMOVE, -1, target_user_data, 0, 0);
}
pub fn prep_poll_update(
sqe: *linux.io_uring_sqe,
old_user_data: u64,
new_user_data: u64,
poll_mask: u32,
flags: u32,
) void {
sqe.prep_rw(.POLL_REMOVE, -1, old_user_data, flags, new_user_data);
// Poll masks previously used to comprise of 16 bits in the flags union of
// a SQE, but were then extended to comprise of 32 bits in order to make
// room for additional option flags. To ensure that the correct bits of
// poll masks are consistently and properly read across multiple kernel
// versions, poll masks are enforced to be little-endian.
// https://www.spinics.net/lists/io-uring/msg02848.html
sqe.rw_flags = std.mem.nativeToLittle(u32, poll_mask);
}
pub fn prep_fallocate(
sqe: *linux.io_uring_sqe,
fd: os.fd_t,
mode: i32,
offset: u64,
len: u64,
) void {
sqe.* = .{
.opcode = .FALLOCATE,
.flags = 0,
.ioprio = 0,
.fd = fd,
.off = offset,
.addr = len,
.len = @intCast(mode),
.rw_flags = 0,
.user_data = 0,
.buf_index = 0,
.personality = 0,
.splice_fd_in = 0,
.addr3 = 0,
.resv = 0,
};
}
pub fn prep_statx(
sqe: *linux.io_uring_sqe,
fd: os.fd_t,
path: [*:0]const u8,
flags: u32,
mask: u32,
buf: *linux.Statx,
) void {
sqe.prep_rw(.STATX, fd, @intFromPtr(path), mask, @intFromPtr(buf));
sqe.rw_flags = flags;
}
pub fn prep_cancel(
sqe: *linux.io_uring_sqe,
cancel_user_data: u64,
flags: u32,
) void {
sqe.prep_rw(.ASYNC_CANCEL, -1, cancel_user_data, 0, 0);
sqe.rw_flags = flags;
}
pub fn prep_shutdown(
sqe: *linux.io_uring_sqe,
sockfd: os.socket_t,
how: u32,
) void {
sqe.prep_rw(.SHUTDOWN, sockfd, 0, how, 0);
}
pub fn prep_renameat(
sqe: *linux.io_uring_sqe,
old_dir_fd: os.fd_t,
old_path: [*:0]const u8,
new_dir_fd: os.fd_t,
new_path: [*:0]const u8,
flags: u32,
) void {
sqe.prep_rw(
.RENAMEAT,
old_dir_fd,
@intFromPtr(old_path),
0,
@intFromPtr(new_path),
);
sqe.len = @bitCast(new_dir_fd);
sqe.rw_flags = flags;
}
pub fn prep_unlinkat(
sqe: *linux.io_uring_sqe,
dir_fd: os.fd_t,
path: [*:0]const u8,
flags: u32,
) void {
sqe.prep_rw(.UNLINKAT, dir_fd, @intFromPtr(path), 0, 0);
sqe.rw_flags = flags;
}
pub fn prep_mkdirat(
sqe: *linux.io_uring_sqe,
dir_fd: os.fd_t,
path: [*:0]const u8,
mode: os.mode_t,
) void {
sqe.prep_rw(.MKDIRAT, dir_fd, @intFromPtr(path), mode, 0);
}
pub fn prep_symlinkat(
sqe: *linux.io_uring_sqe,
target: [*:0]const u8,
new_dir_fd: os.fd_t,
link_path: [*:0]const u8,
) void {
sqe.prep_rw(
.SYMLINKAT,
new_dir_fd,
@intFromPtr(target),
0,
@intFromPtr(link_path),
);
}
pub fn prep_linkat(
sqe: *linux.io_uring_sqe,
old_dir_fd: os.fd_t,
old_path: [*:0]const u8,
new_dir_fd: os.fd_t,
new_path: [*:0]const u8,
flags: u32,
) void {
sqe.prep_rw(
.LINKAT,
old_dir_fd,
@intFromPtr(old_path),
0,
@intFromPtr(new_path),
);
sqe.len = @bitCast(new_dir_fd);
sqe.rw_flags = flags;
}
pub fn prep_provide_buffers(
sqe: *linux.io_uring_sqe,
buffers: [*]u8,
buffer_len: usize,
num: usize,
group_id: usize,
buffer_id: usize,
) void {
const ptr = @intFromPtr(buffers);
sqe.prep_rw(.PROVIDE_BUFFERS, @intCast(num), ptr, buffer_len, buffer_id);
sqe.buf_index = @intCast(group_id);
}
pub fn prep_remove_buffers(
sqe: *linux.io_uring_sqe,
num: usize,
group_id: usize,
) void {
sqe.prep_rw(.REMOVE_BUFFERS, @intCast(num), 0, 0, 0);
sqe.buf_index = @intCast(group_id);
}
pub fn prep_multishot_accept(
sqe: *linux.io_uring_sqe,
fd: os.fd_t,
addr: ?*os.sockaddr,
addrlen: ?*os.socklen_t,
flags: u32,
) void {
prep_accept(sqe, fd, addr, addrlen, flags);
sqe.ioprio |= linux.IORING_ACCEPT_MULTISHOT;
}
pub fn prep_socket(
sqe: *linux.io_uring_sqe,
domain: u32,
socket_type: u32,
protocol: u32,
flags: u32,
) void {
sqe.prep_rw(.SOCKET, @intCast(domain), 0, protocol, socket_type);
sqe.rw_flags = flags;
}
pub fn prep_socket_direct(
sqe: *linux.io_uring_sqe,
domain: u32,
socket_type: u32,
protocol: u32,
flags: u32,
file_index: u32,
) void {
prep_socket(sqe, domain, socket_type, protocol, flags);
__io_uring_set_target_fixed_file(sqe, file_index);
}
pub fn prep_socket_direct_alloc(
sqe: *linux.io_uring_sqe,
domain: u32,
socket_type: u32,
protocol: u32,
flags: u32,
) void {
prep_socket(sqe, domain, socket_type, protocol, flags);
__io_uring_set_target_fixed_file(sqe, linux.IORING_FILE_INDEX_ALLOC);
}
pub fn prep_waitid(
sqe: *linux.io_uring_sqe,
id_type: linux.P,
id: i32,
infop: *linux.siginfo_t,
options: u32,
flags: u32,
) void {
sqe.prep_rw(.WAITID, id, 0, @intFromEnum(id_type), @intFromPtr(infop));
sqe.rw_flags = flags;
sqe.splice_fd_in = @bitCast(options);
}
};

View File

@@ -120,3 +120,7 @@ test "fadvise" {
const ret = linux.fadvise(file.handle, 0, 0, linux.POSIX_FADV.SEQUENTIAL);
try expectEqual(@as(usize, 0), ret);
}
test {
_ = linux.IoUring;
}

View File

@@ -3796,290 +3796,300 @@ pub const EXCEPTION_RECORD = extern struct {
ExceptionInformation: [15]usize,
};
pub usingnamespace switch (native_arch) {
.x86 => struct {
pub const FLOATING_SAVE_AREA = extern struct {
ControlWord: DWORD,
StatusWord: DWORD,
TagWord: DWORD,
ErrorOffset: DWORD,
ErrorSelector: DWORD,
DataOffset: DWORD,
DataSelector: DWORD,
RegisterArea: [80]BYTE,
Cr0NpxState: DWORD,
};
pub const CONTEXT = extern struct {
ContextFlags: DWORD,
Dr0: DWORD,
Dr1: DWORD,
Dr2: DWORD,
Dr3: DWORD,
Dr6: DWORD,
Dr7: DWORD,
FloatSave: FLOATING_SAVE_AREA,
SegGs: DWORD,
SegFs: DWORD,
SegEs: DWORD,
SegDs: DWORD,
Edi: DWORD,
Esi: DWORD,
Ebx: DWORD,
Edx: DWORD,
Ecx: DWORD,
Eax: DWORD,
Ebp: DWORD,
Eip: DWORD,
SegCs: DWORD,
EFlags: DWORD,
Esp: DWORD,
SegSs: DWORD,
ExtendedRegisters: [512]BYTE,
pub fn getRegs(ctx: *const CONTEXT) struct { bp: usize, ip: usize } {
return .{ .bp = ctx.Ebp, .ip = ctx.Eip };
}
};
pub const FLOATING_SAVE_AREA = switch (native_arch) {
.x86 => extern struct {
ControlWord: DWORD,
StatusWord: DWORD,
TagWord: DWORD,
ErrorOffset: DWORD,
ErrorSelector: DWORD,
DataOffset: DWORD,
DataSelector: DWORD,
RegisterArea: [80]BYTE,
Cr0NpxState: DWORD,
},
.x86_64 => struct {
pub const M128A = extern struct {
else => @compileError("FLOATING_SAVE_AREA only defined on x86"),
};
pub const M128A = switch (native_arch) {
.x86_64 => extern struct {
Low: ULONGLONG,
High: LONGLONG,
},
else => @compileError("M128A only defined on x86_64"),
};
pub const XMM_SAVE_AREA32 = switch (native_arch) {
.x86_64 => extern struct {
ControlWord: WORD,
StatusWord: WORD,
TagWord: BYTE,
Reserved1: BYTE,
ErrorOpcode: WORD,
ErrorOffset: DWORD,
ErrorSelector: WORD,
Reserved2: WORD,
DataOffset: DWORD,
DataSelector: WORD,
Reserved3: WORD,
MxCsr: DWORD,
MxCsr_Mask: DWORD,
FloatRegisters: [8]M128A,
XmmRegisters: [16]M128A,
Reserved4: [96]BYTE,
},
else => @compileError("XMM_SAVE_AREA32 only defined on x86_64"),
};
pub const NEON128 = switch (native_arch) {
.aarch64 => extern union {
DUMMYSTRUCTNAME: extern struct {
Low: ULONGLONG,
High: LONGLONG,
};
pub const XMM_SAVE_AREA32 = extern struct {
ControlWord: WORD,
StatusWord: WORD,
TagWord: BYTE,
Reserved1: BYTE,
ErrorOpcode: WORD,
ErrorOffset: DWORD,
ErrorSelector: WORD,
Reserved2: WORD,
DataOffset: DWORD,
DataSelector: WORD,
Reserved3: WORD,
MxCsr: DWORD,
MxCsr_Mask: DWORD,
FloatRegisters: [8]M128A,
XmmRegisters: [16]M128A,
Reserved4: [96]BYTE,
};
pub const CONTEXT = extern struct {
P1Home: DWORD64 align(16),
P2Home: DWORD64,
P3Home: DWORD64,
P4Home: DWORD64,
P5Home: DWORD64,
P6Home: DWORD64,
ContextFlags: DWORD,
MxCsr: DWORD,
SegCs: WORD,
SegDs: WORD,
SegEs: WORD,
SegFs: WORD,
SegGs: WORD,
SegSs: WORD,
EFlags: DWORD,
Dr0: DWORD64,
Dr1: DWORD64,
Dr2: DWORD64,
Dr3: DWORD64,
Dr6: DWORD64,
Dr7: DWORD64,
Rax: DWORD64,
Rcx: DWORD64,
Rdx: DWORD64,
Rbx: DWORD64,
Rsp: DWORD64,
Rbp: DWORD64,
Rsi: DWORD64,
Rdi: DWORD64,
R8: DWORD64,
R9: DWORD64,
R10: DWORD64,
R11: DWORD64,
R12: DWORD64,
R13: DWORD64,
R14: DWORD64,
R15: DWORD64,
Rip: DWORD64,
DUMMYUNIONNAME: extern union {
FltSave: XMM_SAVE_AREA32,
FloatSave: XMM_SAVE_AREA32,
DUMMYSTRUCTNAME: extern struct {
Header: [2]M128A,
Legacy: [8]M128A,
Xmm0: M128A,
Xmm1: M128A,
Xmm2: M128A,
Xmm3: M128A,
Xmm4: M128A,
Xmm5: M128A,
Xmm6: M128A,
Xmm7: M128A,
Xmm8: M128A,
Xmm9: M128A,
Xmm10: M128A,
Xmm11: M128A,
Xmm12: M128A,
Xmm13: M128A,
Xmm14: M128A,
Xmm15: M128A,
},
},
VectorRegister: [26]M128A,
VectorControl: DWORD64,
DebugControl: DWORD64,
LastBranchToRip: DWORD64,
LastBranchFromRip: DWORD64,
LastExceptionToRip: DWORD64,
LastExceptionFromRip: DWORD64,
pub fn getRegs(ctx: *const CONTEXT) struct { bp: usize, ip: usize, sp: usize } {
return .{ .bp = ctx.Rbp, .ip = ctx.Rip, .sp = ctx.Rsp };
}
pub fn setIp(ctx: *CONTEXT, ip: usize) void {
ctx.Rip = ip;
}
pub fn setSp(ctx: *CONTEXT, sp: usize) void {
ctx.Rsp = sp;
}
};
pub const RUNTIME_FUNCTION = extern struct {
BeginAddress: DWORD,
EndAddress: DWORD,
UnwindData: DWORD,
};
pub const KNONVOLATILE_CONTEXT_POINTERS = extern struct {
FloatingContext: [16]?*M128A,
IntegerContext: [16]?*ULONG64,
};
},
D: [2]f64,
S: [4]f32,
H: [8]WORD,
B: [16]BYTE,
},
.aarch64 => struct {
pub const NEON128 = extern union {
else => @compileError("NEON128 only defined on aarch64"),
};
pub const CONTEXT = switch (native_arch) {
.x86 => extern struct {
ContextFlags: DWORD,
Dr0: DWORD,
Dr1: DWORD,
Dr2: DWORD,
Dr3: DWORD,
Dr6: DWORD,
Dr7: DWORD,
FloatSave: FLOATING_SAVE_AREA,
SegGs: DWORD,
SegFs: DWORD,
SegEs: DWORD,
SegDs: DWORD,
Edi: DWORD,
Esi: DWORD,
Ebx: DWORD,
Edx: DWORD,
Ecx: DWORD,
Eax: DWORD,
Ebp: DWORD,
Eip: DWORD,
SegCs: DWORD,
EFlags: DWORD,
Esp: DWORD,
SegSs: DWORD,
ExtendedRegisters: [512]BYTE,
pub fn getRegs(ctx: *const CONTEXT) struct { bp: usize, ip: usize } {
return .{ .bp = ctx.Ebp, .ip = ctx.Eip };
}
},
.x86_64 => extern struct {
P1Home: DWORD64 align(16),
P2Home: DWORD64,
P3Home: DWORD64,
P4Home: DWORD64,
P5Home: DWORD64,
P6Home: DWORD64,
ContextFlags: DWORD,
MxCsr: DWORD,
SegCs: WORD,
SegDs: WORD,
SegEs: WORD,
SegFs: WORD,
SegGs: WORD,
SegSs: WORD,
EFlags: DWORD,
Dr0: DWORD64,
Dr1: DWORD64,
Dr2: DWORD64,
Dr3: DWORD64,
Dr6: DWORD64,
Dr7: DWORD64,
Rax: DWORD64,
Rcx: DWORD64,
Rdx: DWORD64,
Rbx: DWORD64,
Rsp: DWORD64,
Rbp: DWORD64,
Rsi: DWORD64,
Rdi: DWORD64,
R8: DWORD64,
R9: DWORD64,
R10: DWORD64,
R11: DWORD64,
R12: DWORD64,
R13: DWORD64,
R14: DWORD64,
R15: DWORD64,
Rip: DWORD64,
DUMMYUNIONNAME: extern union {
FltSave: XMM_SAVE_AREA32,
FloatSave: XMM_SAVE_AREA32,
DUMMYSTRUCTNAME: extern struct {
Low: ULONGLONG,
High: LONGLONG,
Header: [2]M128A,
Legacy: [8]M128A,
Xmm0: M128A,
Xmm1: M128A,
Xmm2: M128A,
Xmm3: M128A,
Xmm4: M128A,
Xmm5: M128A,
Xmm6: M128A,
Xmm7: M128A,
Xmm8: M128A,
Xmm9: M128A,
Xmm10: M128A,
Xmm11: M128A,
Xmm12: M128A,
Xmm13: M128A,
Xmm14: M128A,
Xmm15: M128A,
},
D: [2]f64,
S: [4]f32,
H: [8]WORD,
B: [16]BYTE,
};
},
VectorRegister: [26]M128A,
VectorControl: DWORD64,
DebugControl: DWORD64,
LastBranchToRip: DWORD64,
LastBranchFromRip: DWORD64,
LastExceptionToRip: DWORD64,
LastExceptionFromRip: DWORD64,
pub const CONTEXT = extern struct {
ContextFlags: ULONG align(16),
Cpsr: ULONG,
DUMMYUNIONNAME: extern union {
DUMMYSTRUCTNAME: extern struct {
X0: DWORD64,
X1: DWORD64,
X2: DWORD64,
X3: DWORD64,
X4: DWORD64,
X5: DWORD64,
X6: DWORD64,
X7: DWORD64,
X8: DWORD64,
X9: DWORD64,
X10: DWORD64,
X11: DWORD64,
X12: DWORD64,
X13: DWORD64,
X14: DWORD64,
X15: DWORD64,
X16: DWORD64,
X17: DWORD64,
X18: DWORD64,
X19: DWORD64,
X20: DWORD64,
X21: DWORD64,
X22: DWORD64,
X23: DWORD64,
X24: DWORD64,
X25: DWORD64,
X26: DWORD64,
X27: DWORD64,
X28: DWORD64,
Fp: DWORD64,
Lr: DWORD64,
},
X: [31]DWORD64,
},
Sp: DWORD64,
Pc: DWORD64,
V: [32]NEON128,
Fpcr: DWORD,
Fpsr: DWORD,
Bcr: [8]DWORD,
Bvr: [8]DWORD64,
Wcr: [2]DWORD,
Wvr: [2]DWORD64,
pub fn getRegs(ctx: *const CONTEXT) struct { bp: usize, ip: usize, sp: usize } {
return .{ .bp = ctx.Rbp, .ip = ctx.Rip, .sp = ctx.Rsp };
}
pub fn getRegs(ctx: *const CONTEXT) struct { bp: usize, ip: usize, sp: usize } {
return .{
.bp = ctx.DUMMYUNIONNAME.DUMMYSTRUCTNAME.Fp,
.ip = ctx.Pc,
.sp = ctx.Sp,
};
}
pub fn setIp(ctx: *CONTEXT, ip: usize) void {
ctx.Rip = ip;
}
pub fn setIp(ctx: *CONTEXT, ip: usize) void {
ctx.Pc = ip;
}
pub fn setSp(ctx: *CONTEXT, sp: usize) void {
ctx.Sp = sp;
}
};
pub const RUNTIME_FUNCTION = extern struct {
BeginAddress: DWORD,
DUMMYUNIONNAME: extern union {
UnwindData: DWORD,
DUMMYSTRUCTNAME: packed struct {
Flag: u2,
FunctionLength: u11,
RegF: u3,
RegI: u4,
H: u1,
CR: u2,
FrameSize: u9,
},
},
};
pub const KNONVOLATILE_CONTEXT_POINTERS = extern struct {
X19: ?*DWORD64,
X20: ?*DWORD64,
X21: ?*DWORD64,
X22: ?*DWORD64,
X23: ?*DWORD64,
X24: ?*DWORD64,
X25: ?*DWORD64,
X26: ?*DWORD64,
X27: ?*DWORD64,
X28: ?*DWORD64,
Fp: ?*DWORD64,
Lr: ?*DWORD64,
D8: ?*DWORD64,
D9: ?*DWORD64,
D10: ?*DWORD64,
D11: ?*DWORD64,
D12: ?*DWORD64,
D13: ?*DWORD64,
D14: ?*DWORD64,
D15: ?*DWORD64,
};
pub fn setSp(ctx: *CONTEXT, sp: usize) void {
ctx.Rsp = sp;
}
},
else => struct {},
.aarch64 => extern struct {
ContextFlags: ULONG align(16),
Cpsr: ULONG,
DUMMYUNIONNAME: extern union {
DUMMYSTRUCTNAME: extern struct {
X0: DWORD64,
X1: DWORD64,
X2: DWORD64,
X3: DWORD64,
X4: DWORD64,
X5: DWORD64,
X6: DWORD64,
X7: DWORD64,
X8: DWORD64,
X9: DWORD64,
X10: DWORD64,
X11: DWORD64,
X12: DWORD64,
X13: DWORD64,
X14: DWORD64,
X15: DWORD64,
X16: DWORD64,
X17: DWORD64,
X18: DWORD64,
X19: DWORD64,
X20: DWORD64,
X21: DWORD64,
X22: DWORD64,
X23: DWORD64,
X24: DWORD64,
X25: DWORD64,
X26: DWORD64,
X27: DWORD64,
X28: DWORD64,
Fp: DWORD64,
Lr: DWORD64,
},
X: [31]DWORD64,
},
Sp: DWORD64,
Pc: DWORD64,
V: [32]NEON128,
Fpcr: DWORD,
Fpsr: DWORD,
Bcr: [8]DWORD,
Bvr: [8]DWORD64,
Wcr: [2]DWORD,
Wvr: [2]DWORD64,
pub fn getRegs(ctx: *const CONTEXT) struct { bp: usize, ip: usize, sp: usize } {
return .{
.bp = ctx.DUMMYUNIONNAME.DUMMYSTRUCTNAME.Fp,
.ip = ctx.Pc,
.sp = ctx.Sp,
};
}
pub fn setIp(ctx: *CONTEXT, ip: usize) void {
ctx.Pc = ip;
}
pub fn setSp(ctx: *CONTEXT, sp: usize) void {
ctx.Sp = sp;
}
},
else => @compileError("CONTEXT is not defined for this architecture"),
};
pub const RUNTIME_FUNCTION = switch (native_arch) {
.x86_64 => extern struct {
BeginAddress: DWORD,
EndAddress: DWORD,
UnwindData: DWORD,
},
.aarch64 => extern struct {
BeginAddress: DWORD,
DUMMYUNIONNAME: extern union {
UnwindData: DWORD,
DUMMYSTRUCTNAME: packed struct {
Flag: u2,
FunctionLength: u11,
RegF: u3,
RegI: u4,
H: u1,
CR: u2,
FrameSize: u9,
},
},
},
else => @compileError("RUNTIME_FUNCTION is not defined for this architecture"),
};
pub const KNONVOLATILE_CONTEXT_POINTERS = switch (native_arch) {
.x86_64 => extern struct {
FloatingContext: [16]?*M128A,
IntegerContext: [16]?*ULONG64,
},
.aarch64 => extern struct {
X19: ?*DWORD64,
X20: ?*DWORD64,
X21: ?*DWORD64,
X22: ?*DWORD64,
X23: ?*DWORD64,
X24: ?*DWORD64,
X25: ?*DWORD64,
X26: ?*DWORD64,
X27: ?*DWORD64,
X28: ?*DWORD64,
Fp: ?*DWORD64,
Lr: ?*DWORD64,
D8: ?*DWORD64,
D9: ?*DWORD64,
D10: ?*DWORD64,
D11: ?*DWORD64,
D12: ?*DWORD64,
D13: ?*DWORD64,
D14: ?*DWORD64,
D15: ?*DWORD64,
},
else => @compileError("KNONVOLATILE_CONTEXT_POINTERS is not defined for this architecture"),
};
pub const EXCEPTION_POINTERS = extern struct {