authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-08-24 13:43:41-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-09-01 17:54:06-07:00
log3deda15e21ea3a8138d5b628f2649bbbfe7fa910
tree5ed1e0a60bd284984e328f49858c96063f1ff608
parent81e2034d4ad935185344030e5ecedbd1388a65e9

std.os reorganization, avoiding `usingnamespace`

The main purpose of this branch is to explore avoiding the `usingnamespace` feature of the zig language, specifically with regards to `std.os` and related functionality. If this experiment is successful, it will provide a data point on whether or not it would be practical to entirely remove `usingnamespace` from the language. In this commit, `usingnamespace` has been completely eliminated from the Linux x86_64 compilation path, aside from io_uring. The behavior tests pass, however that's as far as this branch goes. It is very breaking, and a lot more work is needed before it could be considered mergeable. I wanted to put a pull requset up early so that zig programmers have time to provide feedback. This is progress towards closing #6600 since it clarifies where the actual "owner" of each declaration is, and reduces the number of different ways to import the same declarations. One of the main organizational strategies used here is to do namespacing with real namespaces (e.g. structs) rather than by having declarations share a common prefix (the C strategy). It's no coincidence that `usingnamespace` has similar semantics to `#include` and becomes much less necessary when using proper namespaces.

53 files changed, 5199 insertions(+), 5025 deletions(-)

CMakeLists.txt+3-7
...@@ -424,13 +424,9 @@ set(ZIG_STAGE2_SOURCES...@@ -424,13 +424,9 @@ set(ZIG_STAGE2_SOURCES
424 "${CMAKE_SOURCE_DIR}/lib/std/meta/trait.zig"424 "${CMAKE_SOURCE_DIR}/lib/std/meta/trait.zig"
425 "${CMAKE_SOURCE_DIR}/lib/std/multi_array_list.zig"425 "${CMAKE_SOURCE_DIR}/lib/std/multi_array_list.zig"
426 "${CMAKE_SOURCE_DIR}/lib/std/os.zig"426 "${CMAKE_SOURCE_DIR}/lib/std/os.zig"
427 "${CMAKE_SOURCE_DIR}/lib/std/os/bits.zig"427 "${CMAKE_SOURCE_DIR}/lib/std/os/linux.zig"
428 "${CMAKE_SOURCE_DIR}/lib/std/os/bits/linux.zig"428 "${CMAKE_SOURCE_DIR}/lib/std/os/linux/errno/generic.zig"
429 "${CMAKE_SOURCE_DIR}/lib/std/os/bits/linux/errno/generic.zig"429 "${CMAKE_SOURCE_DIR}/lib/std/os/linux/x86_64.zig"
430 "${CMAKE_SOURCE_DIR}/lib/std/os/bits/linux/netlink.zig"
431 "${CMAKE_SOURCE_DIR}/lib/std/os/bits/linux/prctl.zig"
432 "${CMAKE_SOURCE_DIR}/lib/std/os/bits/linux/securebits.zig"
433 "${CMAKE_SOURCE_DIR}/lib/std/os/bits/linux/x86_64.zig"
434 "${CMAKE_SOURCE_DIR}/lib/std/os/linux.zig"430 "${CMAKE_SOURCE_DIR}/lib/std/os/linux.zig"
435 "${CMAKE_SOURCE_DIR}/lib/std/os/linux/io_uring.zig"431 "${CMAKE_SOURCE_DIR}/lib/std/os/linux/io_uring.zig"
436 "${CMAKE_SOURCE_DIR}/lib/std/os/linux/x86_64.zig"432 "${CMAKE_SOURCE_DIR}/lib/std/os/linux/x86_64.zig"
lib/std/Thread/Mutex.zig+2-2
...@@ -133,7 +133,7 @@ pub const AtomicMutex = struct {...@@ -133,7 +133,7 @@ pub const AtomicMutex = struct {
133 .linux => {133 .linux => {
134 switch (linux.getErrno(linux.futex_wait(134 switch (linux.getErrno(linux.futex_wait(
135 @ptrCast(*const i32, &m.state),135 @ptrCast(*const i32, &m.state),
136 linux.FUTEX_PRIVATE_FLAG | linux.FUTEX_WAIT,136 linux.FUTEX.PRIVATE_FLAG | linux.FUTEX.WAIT,
137 @enumToInt(new_state),137 @enumToInt(new_state),
138 null,138 null,
139 ))) {139 ))) {
...@@ -155,7 +155,7 @@ pub const AtomicMutex = struct {...@@ -155,7 +155,7 @@ pub const AtomicMutex = struct {
155 .linux => {155 .linux => {
156 switch (linux.getErrno(linux.futex_wake(156 switch (linux.getErrno(linux.futex_wake(
157 @ptrCast(*const i32, &m.state),157 @ptrCast(*const i32, &m.state),
158 linux.FUTEX_PRIVATE_FLAG | linux.FUTEX_WAKE,158 linux.FUTEX.PRIVATE_FLAG | linux.FUTEX.WAKE,
159 1,159 1,
160 ))) {160 ))) {
161 .SUCCESS => {},161 .SUCCESS => {},
lib/std/Thread/StaticResetEvent.zig+2-2
...@@ -194,7 +194,7 @@ pub const AtomicEvent = struct {...@@ -194,7 +194,7 @@ pub const AtomicEvent = struct {
194 _ = wake_count;194 _ = wake_count;
195 const waiting = std.math.maxInt(i32); // wake_count195 const waiting = std.math.maxInt(i32); // wake_count
196 const ptr = @ptrCast(*const i32, waiters);196 const ptr = @ptrCast(*const i32, waiters);
197 const rc = linux.futex_wake(ptr, linux.FUTEX_WAKE | linux.FUTEX_PRIVATE_FLAG, waiting);197 const rc = linux.futex_wake(ptr, linux.FUTEX.WAKE | linux.FUTEX.PRIVATE_FLAG, waiting);
198 assert(linux.getErrno(rc) == .SUCCESS);198 assert(linux.getErrno(rc) == .SUCCESS);
199 }199 }
200200
...@@ -213,7 +213,7 @@ pub const AtomicEvent = struct {...@@ -213,7 +213,7 @@ pub const AtomicEvent = struct {
213 return;213 return;
214 const expected = @intCast(i32, waiting);214 const expected = @intCast(i32, waiting);
215 const ptr = @ptrCast(*const i32, waiters);215 const ptr = @ptrCast(*const i32, waiters);
216 const rc = linux.futex_wait(ptr, linux.FUTEX_WAIT | linux.FUTEX_PRIVATE_FLAG, expected, ts_ptr);216 const rc = linux.futex_wait(ptr, linux.FUTEX.WAIT | linux.FUTEX.PRIVATE_FLAG, expected, ts_ptr);
217 switch (linux.getErrno(rc)) {217 switch (linux.getErrno(rc)) {
218 .SUCCESS => continue,218 .SUCCESS => continue,
219 .TIMEDOUT => return error.TimedOut,219 .TIMEDOUT => return error.TimedOut,
lib/std/c.zig-2
...@@ -10,8 +10,6 @@ test {...@@ -10,8 +10,6 @@ test {
10 _ = tokenizer;10 _ = tokenizer;
11}11}
1212
13pub usingnamespace @import("os/bits.zig");
14
15pub usingnamespace switch (std.Target.current.os.tag) {13pub usingnamespace switch (std.Target.current.os.tag) {
16 .linux => @import("c/linux.zig"),14 .linux => @import("c/linux.zig"),
17 .windows => @import("c/windows.zig"),15 .windows => @import("c/windows.zig"),
lib/std/c/darwin.zig-2
...@@ -4,8 +4,6 @@ const builtin = @import("builtin");...@@ -4,8 +4,6 @@ const builtin = @import("builtin");
4const macho = std.macho;4const macho = std.macho;
5const native_arch = builtin.target.cpu.arch;5const native_arch = builtin.target.cpu.arch;
66
7usingnamespace @import("../os/bits.zig");
8
9extern "c" fn __error() *c_int;7extern "c" fn __error() *c_int;
10pub extern "c" fn NSVersionOfRunTimeLibrary(library_name: [*:0]const u8) u32;8pub extern "c" fn NSVersionOfRunTimeLibrary(library_name: [*:0]const u8) u32;
11pub extern "c" fn _NSGetExecutablePath(buf: [*:0]u8, bufsize: *u32) c_int;9pub extern "c" fn _NSGetExecutablePath(buf: [*:0]u8, bufsize: *u32) c_int;
lib/std/c/wasi.zig-2
...@@ -1,5 +1,3 @@...@@ -1,5 +1,3 @@
1usingnamespace @import("../os/bits.zig");
2
3extern threadlocal var errno: c_int;1extern threadlocal var errno: c_int;
42
5pub fn _errno() *c_int {3pub fn _errno() *c_int {
lib/std/debug.zig+17-17
...@@ -948,8 +948,8 @@ fn mapWholeFile(file: File) ![]align(mem.page_size) const u8 {...@@ -948,8 +948,8 @@ fn mapWholeFile(file: File) ![]align(mem.page_size) const u8 {
948 const mapped_mem = try os.mmap(948 const mapped_mem = try os.mmap(
949 null,949 null,
950 file_len,950 file_len,
951 os.PROT_READ,951 os.PROT.READ,
952 os.MAP_SHARED,952 os.MAP.SHARED,
953 file.handle,953 file.handle,
954 0,954 0,
955 );955 );
...@@ -1498,12 +1498,12 @@ pub fn attachSegfaultHandler() void {...@@ -1498,12 +1498,12 @@ pub fn attachSegfaultHandler() void {
1498 var act = os.Sigaction{1498 var act = os.Sigaction{
1499 .handler = .{ .sigaction = handleSegfaultLinux },1499 .handler = .{ .sigaction = handleSegfaultLinux },
1500 .mask = os.empty_sigset,1500 .mask = os.empty_sigset,
1501 .flags = (os.SA_SIGINFO | os.SA_RESTART | os.SA_RESETHAND),1501 .flags = (os.SA.SIGINFO | os.SA.RESTART | os.SA.RESETHAND),
1502 };1502 };
15031503
1504 os.sigaction(os.SIGSEGV, &act, null);1504 os.sigaction(os.SIG.SEGV, &act, null);
1505 os.sigaction(os.SIGILL, &act, null);1505 os.sigaction(os.SIG.ILL, &act, null);
1506 os.sigaction(os.SIGBUS, &act, null);1506 os.sigaction(os.SIG.BUS, &act, null);
1507}1507}
15081508
1509fn resetSegfaultHandler() void {1509fn resetSegfaultHandler() void {
...@@ -1515,13 +1515,13 @@ fn resetSegfaultHandler() void {...@@ -1515,13 +1515,13 @@ fn resetSegfaultHandler() void {
1515 return;1515 return;
1516 }1516 }
1517 var act = os.Sigaction{1517 var act = os.Sigaction{
1518 .handler = .{ .sigaction = os.SIG_DFL },1518 .handler = .{ .sigaction = os.SIG.DFL },
1519 .mask = os.empty_sigset,1519 .mask = os.empty_sigset,
1520 .flags = 0,1520 .flags = 0,
1521 };1521 };
1522 os.sigaction(os.SIGSEGV, &act, null);1522 os.sigaction(os.SIG.SEGV, &act, null);
1523 os.sigaction(os.SIGILL, &act, null);1523 os.sigaction(os.SIG.ILL, &act, null);
1524 os.sigaction(os.SIGBUS, &act, null);1524 os.sigaction(os.SIG.BUS, &act, null);
1525}1525}
15261526
1527fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const c_void) callconv(.C) noreturn {1527fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const c_void) callconv(.C) noreturn {
...@@ -1542,9 +1542,9 @@ fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const c_v...@@ -1542,9 +1542,9 @@ fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const c_v
1542 nosuspend {1542 nosuspend {
1543 const stderr = io.getStdErr().writer();1543 const stderr = io.getStdErr().writer();
1544 _ = switch (sig) {1544 _ = switch (sig) {
1545 os.SIGSEGV => stderr.print("Segmentation fault at address 0x{x}\n", .{addr}),1545 os.SIG.SEGV => stderr.print("Segmentation fault at address 0x{x}\n", .{addr}),
1546 os.SIGILL => stderr.print("Illegal instruction at address 0x{x}\n", .{addr}),1546 os.SIG.ILL => stderr.print("Illegal instruction at address 0x{x}\n", .{addr}),
1547 os.SIGBUS => stderr.print("Bus error at address 0x{x}\n", .{addr}),1547 os.SIG.BUS => stderr.print("Bus error at address 0x{x}\n", .{addr}),
1548 else => unreachable,1548 else => unreachable,
1549 } catch os.abort();1549 } catch os.abort();
1550 }1550 }
...@@ -1552,20 +1552,20 @@ fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const c_v...@@ -1552,20 +1552,20 @@ fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const c_v
1552 switch (native_arch) {1552 switch (native_arch) {
1553 .i386 => {1553 .i386 => {
1554 const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr));1554 const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr));
1555 const ip = @intCast(usize, ctx.mcontext.gregs[os.REG_EIP]);1555 const ip = @intCast(usize, ctx.mcontext.gregs[os.REG.EIP]);
1556 const bp = @intCast(usize, ctx.mcontext.gregs[os.REG_EBP]);1556 const bp = @intCast(usize, ctx.mcontext.gregs[os.REG.EBP]);
1557 dumpStackTraceFromBase(bp, ip);1557 dumpStackTraceFromBase(bp, ip);
1558 },1558 },
1559 .x86_64 => {1559 .x86_64 => {
1560 const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr));1560 const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr));
1561 const ip = switch (native_os) {1561 const ip = switch (native_os) {
1562 .linux, .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG_RIP]),1562 .linux, .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG.RIP]),
1563 .freebsd => @intCast(usize, ctx.mcontext.rip),1563 .freebsd => @intCast(usize, ctx.mcontext.rip),
1564 .openbsd => @intCast(usize, ctx.sc_rip),1564 .openbsd => @intCast(usize, ctx.sc_rip),
1565 else => unreachable,1565 else => unreachable,
1566 };1566 };
1567 const bp = switch (native_os) {1567 const bp = switch (native_os) {
1568 .linux, .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG_RBP]),1568 .linux, .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG.RBP]),
1569 .openbsd => @intCast(usize, ctx.sc_rbp),1569 .openbsd => @intCast(usize, ctx.sc_rbp),
1570 .freebsd => @intCast(usize, ctx.mcontext.rbp),1570 .freebsd => @intCast(usize, ctx.mcontext.rbp),
1571 else => unreachable,1571 else => unreachable,
lib/std/fs.zig+38-38
...@@ -907,35 +907,35 @@ pub const Dir = struct {...@@ -907,35 +907,35 @@ pub const Dir = struct {
907 return self.openFileW(path_w.span(), flags);907 return self.openFileW(path_w.span(), flags);
908 }908 }
909909
910 var os_flags: u32 = os.O_CLOEXEC;910 var os_flags: u32 = os.O.CLOEXEC;
911 // Use the O_ locking flags if the os supports them to acquire the lock911 // Use the O_ locking flags if the os supports them to acquire the lock
912 // atomically.912 // atomically.
913 const has_flock_open_flags = @hasDecl(os, "O_EXLOCK");913 const has_flock_open_flags = @hasDecl(os.O, "EXLOCK");
914 if (has_flock_open_flags) {914 if (has_flock_open_flags) {
915 // Note that the O_NONBLOCK flag is removed after the openat() call915 // Note that the O_NONBLOCK flag is removed after the openat() call
916 // is successful.916 // is successful.
917 const nonblocking_lock_flag: u32 = if (flags.lock_nonblocking)917 const nonblocking_lock_flag: u32 = if (flags.lock_nonblocking)
918 os.O_NONBLOCK918 os.O.NONBLOCK
919 else919 else
920 0;920 0;
921 os_flags |= switch (flags.lock) {921 os_flags |= switch (flags.lock) {
922 .None => @as(u32, 0),922 .None => @as(u32, 0),
923 .Shared => os.O_SHLOCK | nonblocking_lock_flag,923 .Shared => os.O.SHLOCK | nonblocking_lock_flag,
924 .Exclusive => os.O_EXLOCK | nonblocking_lock_flag,924 .Exclusive => os.O.EXLOCK | nonblocking_lock_flag,
925 };925 };
926 }926 }
927 if (@hasDecl(os, "O_LARGEFILE")) {927 if (@hasDecl(os.O, "LARGEFILE")) {
928 os_flags |= os.O_LARGEFILE;928 os_flags |= os.O.LARGEFILE;
929 }929 }
930 if (!flags.allow_ctty) {930 if (!flags.allow_ctty) {
931 os_flags |= os.O_NOCTTY;931 os_flags |= os.O.NOCTTY;
932 }932 }
933 os_flags |= if (flags.write and flags.read)933 os_flags |= if (flags.write and flags.read)
934 @as(u32, os.O_RDWR)934 @as(u32, os.O.RDWR)
935 else if (flags.write)935 else if (flags.write)
936 @as(u32, os.O_WRONLY)936 @as(u32, os.O.WRONLY)
937 else937 else
938 @as(u32, os.O_RDONLY);938 @as(u32, os.O.RDONLY);
939 const fd = if (flags.intended_io_mode != .blocking)939 const fd = if (flags.intended_io_mode != .blocking)
940 try std.event.Loop.instance.?.openatZ(self.fd, sub_path, os_flags, 0)940 try std.event.Loop.instance.?.openatZ(self.fd, sub_path, os_flags, 0)
941 else941 else
...@@ -947,11 +947,11 @@ pub const Dir = struct {...@@ -947,11 +947,11 @@ pub const Dir = struct {
947 if (builtin.target.os.tag != .wasi) {947 if (builtin.target.os.tag != .wasi) {
948 if (!has_flock_open_flags and flags.lock != .None) {948 if (!has_flock_open_flags and flags.lock != .None) {
949 // TODO: integrate async I/O949 // TODO: integrate async I/O
950 const lock_nonblocking = if (flags.lock_nonblocking) os.LOCK_NB else @as(i32, 0);950 const lock_nonblocking = if (flags.lock_nonblocking) os.LOCK.NB else @as(i32, 0);
951 try os.flock(fd, switch (flags.lock) {951 try os.flock(fd, switch (flags.lock) {
952 .None => unreachable,952 .None => unreachable,
953 .Shared => os.LOCK_SH | lock_nonblocking,953 .Shared => os.LOCK.SH | lock_nonblocking,
954 .Exclusive => os.LOCK_EX | lock_nonblocking,954 .Exclusive => os.LOCK.EX | lock_nonblocking,
955 });955 });
956 }956 }
957 }957 }
...@@ -963,7 +963,7 @@ pub const Dir = struct {...@@ -963,7 +963,7 @@ pub const Dir = struct {
963 error.PermissionDenied => unreachable,963 error.PermissionDenied => unreachable,
964 else => |e| return e,964 else => |e| return e,
965 };965 };
966 fl_flags &= ~@as(usize, os.O_NONBLOCK);966 fl_flags &= ~@as(usize, os.O.NONBLOCK);
967 _ = os.fcntl(fd, os.F_SETFL, fl_flags) catch |err| switch (err) {967 _ = os.fcntl(fd, os.F_SETFL, fl_flags) catch |err| switch (err) {
968 error.FileBusy => unreachable,968 error.FileBusy => unreachable,
969 error.Locked => unreachable,969 error.Locked => unreachable,
...@@ -1038,7 +1038,7 @@ pub const Dir = struct {...@@ -1038,7 +1038,7 @@ pub const Dir = struct {
1038 /// Same as `createFile` but WASI only.1038 /// Same as `createFile` but WASI only.
1039 pub fn createFileWasi(self: Dir, sub_path: []const u8, flags: File.CreateFlags) File.OpenError!File {1039 pub fn createFileWasi(self: Dir, sub_path: []const u8, flags: File.CreateFlags) File.OpenError!File {
1040 const w = os.wasi;1040 const w = os.wasi;
1041 var oflags = w.O_CREAT;1041 var oflags = w.O.CREAT;
1042 var base: w.rights_t = w.RIGHT_FD_WRITE |1042 var base: w.rights_t = w.RIGHT_FD_WRITE |
1043 w.RIGHT_FD_DATASYNC |1043 w.RIGHT_FD_DATASYNC |
1044 w.RIGHT_FD_SEEK |1044 w.RIGHT_FD_SEEK |
...@@ -1054,10 +1054,10 @@ pub const Dir = struct {...@@ -1054,10 +1054,10 @@ pub const Dir = struct {
1054 base |= w.RIGHT_FD_READ;1054 base |= w.RIGHT_FD_READ;
1055 }1055 }
1056 if (flags.truncate) {1056 if (flags.truncate) {
1057 oflags |= w.O_TRUNC;1057 oflags |= w.O.TRUNC;
1058 }1058 }
1059 if (flags.exclusive) {1059 if (flags.exclusive) {
1060 oflags |= w.O_EXCL;1060 oflags |= w.O.EXCL;
1061 }1061 }
1062 const fd = try os.openatWasi(self.fd, sub_path, 0x0, oflags, 0x0, base, 0x0);1062 const fd = try os.openatWasi(self.fd, sub_path, 0x0, oflags, 0x0, base, 0x0);
1063 return File{ .handle = fd };1063 return File{ .handle = fd };
...@@ -1072,24 +1072,24 @@ pub const Dir = struct {...@@ -1072,24 +1072,24 @@ pub const Dir = struct {
10721072
1073 // Use the O_ locking flags if the os supports them to acquire the lock1073 // Use the O_ locking flags if the os supports them to acquire the lock
1074 // atomically.1074 // atomically.
1075 const has_flock_open_flags = @hasDecl(os, "O_EXLOCK");1075 const has_flock_open_flags = @hasDecl(os.O, "EXLOCK");
1076 // Note that the O_NONBLOCK flag is removed after the openat() call1076 // Note that the O_NONBLOCK flag is removed after the openat() call
1077 // is successful.1077 // is successful.
1078 const nonblocking_lock_flag: u32 = if (has_flock_open_flags and flags.lock_nonblocking)1078 const nonblocking_lock_flag: u32 = if (has_flock_open_flags and flags.lock_nonblocking)
1079 os.O_NONBLOCK1079 os.O.NONBLOCK
1080 else1080 else
1081 0;1081 0;
1082 const lock_flag: u32 = if (has_flock_open_flags) switch (flags.lock) {1082 const lock_flag: u32 = if (has_flock_open_flags) switch (flags.lock) {
1083 .None => @as(u32, 0),1083 .None => @as(u32, 0),
1084 .Shared => os.O_SHLOCK | nonblocking_lock_flag,1084 .Shared => os.O.SHLOCK | nonblocking_lock_flag,
1085 .Exclusive => os.O_EXLOCK | nonblocking_lock_flag,1085 .Exclusive => os.O.EXLOCK | nonblocking_lock_flag,
1086 } else 0;1086 } else 0;
10871087
1088 const O_LARGEFILE = if (@hasDecl(os, "O_LARGEFILE")) os.O_LARGEFILE else 0;1088 const O_LARGEFILE = if (@hasDecl(os.O, "LARGEFILE")) os.O.LARGEFILE else 0;
1089 const os_flags = lock_flag | O_LARGEFILE | os.O_CREAT | os.O_CLOEXEC |1089 const os_flags = lock_flag | O_LARGEFILE | os.O.CREAT | os.O.CLOEXEC |
1090 (if (flags.truncate) @as(u32, os.O_TRUNC) else 0) |1090 (if (flags.truncate) @as(u32, os.O.TRUNC) else 0) |
1091 (if (flags.read) @as(u32, os.O_RDWR) else os.O_WRONLY) |1091 (if (flags.read) @as(u32, os.O.RDWR) else os.O.WRONLY) |
1092 (if (flags.exclusive) @as(u32, os.O_EXCL) else 0);1092 (if (flags.exclusive) @as(u32, os.O.EXCL) else 0);
1093 const fd = if (flags.intended_io_mode != .blocking)1093 const fd = if (flags.intended_io_mode != .blocking)
1094 try std.event.Loop.instance.?.openatZ(self.fd, sub_path_c, os_flags, flags.mode)1094 try std.event.Loop.instance.?.openatZ(self.fd, sub_path_c, os_flags, flags.mode)
1095 else1095 else
...@@ -1101,11 +1101,11 @@ pub const Dir = struct {...@@ -1101,11 +1101,11 @@ pub const Dir = struct {
1101 if (builtin.target.os.tag != .wasi) {1101 if (builtin.target.os.tag != .wasi) {
1102 if (!has_flock_open_flags and flags.lock != .None) {1102 if (!has_flock_open_flags and flags.lock != .None) {
1103 // TODO: integrate async I/O1103 // TODO: integrate async I/O
1104 const lock_nonblocking = if (flags.lock_nonblocking) os.LOCK_NB else @as(i32, 0);1104 const lock_nonblocking = if (flags.lock_nonblocking) os.LOCK.NB else @as(i32, 0);
1105 try os.flock(fd, switch (flags.lock) {1105 try os.flock(fd, switch (flags.lock) {
1106 .None => unreachable,1106 .None => unreachable,
1107 .Shared => os.LOCK_SH | lock_nonblocking,1107 .Shared => os.LOCK.SH | lock_nonblocking,
1108 .Exclusive => os.LOCK_EX | lock_nonblocking,1108 .Exclusive => os.LOCK.EX | lock_nonblocking,
1109 });1109 });
1110 }1110 }
1111 }1111 }
...@@ -1117,7 +1117,7 @@ pub const Dir = struct {...@@ -1117,7 +1117,7 @@ pub const Dir = struct {
1117 error.PermissionDenied => unreachable,1117 error.PermissionDenied => unreachable,
1118 else => |e| return e,1118 else => |e| return e,
1119 };1119 };
1120 fl_flags &= ~@as(usize, os.O_NONBLOCK);1120 fl_flags &= ~@as(usize, os.O.NONBLOCK);
1121 _ = os.fcntl(fd, os.F_SETFL, fl_flags) catch |err| switch (err) {1121 _ = os.fcntl(fd, os.F_SETFL, fl_flags) catch |err| switch (err) {
1122 error.FileBusy => unreachable,1122 error.FileBusy => unreachable,
1123 error.Locked => unreachable,1123 error.Locked => unreachable,
...@@ -1262,7 +1262,7 @@ pub const Dir = struct {...@@ -1262,7 +1262,7 @@ pub const Dir = struct {
1262 return self.realpathW(pathname_w.span(), out_buffer);1262 return self.realpathW(pathname_w.span(), out_buffer);
1263 }1263 }
12641264
1265 const flags = if (builtin.os.tag == .linux) os.O_PATH | os.O_NONBLOCK | os.O_CLOEXEC else os.O_NONBLOCK | os.O_CLOEXEC;1265 const flags = if (builtin.os.tag == .linux) os.O.PATH | os.O.NONBLOCK | os.O.CLOEXEC else os.O.NONBLOCK | os.O.CLOEXEC;
1266 const fd = os.openatZ(self.fd, pathname, flags, 0) catch |err| switch (err) {1266 const fd = os.openatZ(self.fd, pathname, flags, 0) catch |err| switch (err) {
1267 error.FileLocksNotSupported => unreachable,1267 error.FileLocksNotSupported => unreachable,
1268 else => |e| return e,1268 else => |e| return e,
...@@ -1423,7 +1423,7 @@ pub const Dir = struct {...@@ -1423,7 +1423,7 @@ pub const Dir = struct {
1423 // TODO do we really need all the rights here?1423 // TODO do we really need all the rights here?
1424 const inheriting: w.rights_t = w.RIGHT_ALL ^ w.RIGHT_SOCK_SHUTDOWN;1424 const inheriting: w.rights_t = w.RIGHT_ALL ^ w.RIGHT_SOCK_SHUTDOWN;
14251425
1426 const result = os.openatWasi(self.fd, sub_path, symlink_flags, w.O_DIRECTORY, 0x0, base, inheriting);1426 const result = os.openatWasi(self.fd, sub_path, symlink_flags, w.O.DIRECTORY, 0x0, base, inheriting);
1427 const fd = result catch |err| switch (err) {1427 const fd = result catch |err| switch (err) {
1428 error.FileTooBig => unreachable, // can't happen for directories1428 error.FileTooBig => unreachable, // can't happen for directories
1429 error.IsDir => unreachable, // we're providing O_DIRECTORY1429 error.IsDir => unreachable, // we're providing O_DIRECTORY
...@@ -1442,12 +1442,12 @@ pub const Dir = struct {...@@ -1442,12 +1442,12 @@ pub const Dir = struct {
1442 const sub_path_w = try os.windows.cStrToPrefixedFileW(sub_path_c);1442 const sub_path_w = try os.windows.cStrToPrefixedFileW(sub_path_c);
1443 return self.openDirW(sub_path_w.span().ptr, args);1443 return self.openDirW(sub_path_w.span().ptr, args);
1444 }1444 }
1445 const symlink_flags: u32 = if (args.no_follow) os.O_NOFOLLOW else 0x0;1445 const symlink_flags: u32 = if (args.no_follow) os.O.NOFOLLOW else 0x0;
1446 if (!args.iterate) {1446 if (!args.iterate) {
1447 const O_PATH = if (@hasDecl(os, "O_PATH")) os.O_PATH else 0;1447 const O_PATH = if (@hasDecl(os.O, "PATH")) os.O.PATH else 0;
1448 return self.openDirFlagsZ(sub_path_c, os.O_DIRECTORY | os.O_RDONLY | os.O_CLOEXEC | O_PATH | symlink_flags);1448 return self.openDirFlagsZ(sub_path_c, os.O.DIRECTORY | os.O.RDONLY | os.O.CLOEXEC | O_PATH | symlink_flags);
1449 } else {1449 } else {
1450 return self.openDirFlagsZ(sub_path_c, os.O_DIRECTORY | os.O_RDONLY | os.O_CLOEXEC | symlink_flags);1450 return self.openDirFlagsZ(sub_path_c, os.O.DIRECTORY | os.O.RDONLY | os.O.CLOEXEC | symlink_flags);
1451 }1451 }
1452 }1452 }
14531453
...@@ -2132,7 +2132,7 @@ pub fn cwd() Dir {...@@ -2132,7 +2132,7 @@ pub fn cwd() Dir {
2132 } else if (builtin.os.tag == .wasi and !builtin.link_libc) {2132 } else if (builtin.os.tag == .wasi and !builtin.link_libc) {
2133 @compileError("WASI doesn't have a concept of cwd(); use std.fs.wasi.PreopenList to get available Dir handles instead");2133 @compileError("WASI doesn't have a concept of cwd(); use std.fs.wasi.PreopenList to get available Dir handles instead");
2134 } else {2134 } else {
2135 return Dir{ .fd = os.AT_FDCWD };2135 return Dir{ .fd = os.AT.FDCWD };
2136 }2136 }
2137}2137}
21382138
lib/std/fs/file.zig+8-8
...@@ -329,14 +329,14 @@ pub const File = struct {...@@ -329,14 +329,14 @@ pub const File = struct {
329 os.FILETYPE_REGULAR_FILE => Kind.File,329 os.FILETYPE_REGULAR_FILE => Kind.File,
330 os.FILETYPE_SOCKET_STREAM, os.FILETYPE_SOCKET_DGRAM => Kind.UnixDomainSocket,330 os.FILETYPE_SOCKET_STREAM, os.FILETYPE_SOCKET_DGRAM => Kind.UnixDomainSocket,
331 else => Kind.Unknown,331 else => Kind.Unknown,
332 } else switch (st.mode & os.S_IFMT) {332 } else switch (st.mode & os.S.IFMT) {
333 os.S_IFBLK => Kind.BlockDevice,333 os.S.IFBLK => Kind.BlockDevice,
334 os.S_IFCHR => Kind.CharacterDevice,334 os.S.IFCHR => Kind.CharacterDevice,
335 os.S_IFDIR => Kind.Directory,335 os.S.IFDIR => Kind.Directory,
336 os.S_IFIFO => Kind.NamedPipe,336 os.S.IFIFO => Kind.NamedPipe,
337 os.S_IFLNK => Kind.SymLink,337 os.S.IFLNK => Kind.SymLink,
338 os.S_IFREG => Kind.File,338 os.S.IFREG => Kind.File,
339 os.S_IFSOCK => Kind.UnixDomainSocket,339 os.S.IFSOCK => Kind.UnixDomainSocket,
340 else => Kind.Unknown,340 else => Kind.Unknown,
341 },341 },
342 .atime = @as(i128, atime.tv_sec) * std.time.ns_per_s + atime.tv_nsec,342 .atime = @as(i128, atime.tv_sec) * std.time.ns_per_s + atime.tv_nsec,
lib/std/heap.zig+2-2
...@@ -304,8 +304,8 @@ const PageAllocator = struct {...@@ -304,8 +304,8 @@ const PageAllocator = struct {
304 const slice = os.mmap(304 const slice = os.mmap(
305 hint,305 hint,
306 alloc_len,306 alloc_len,
307 os.PROT_READ | os.PROT_WRITE,307 os.PROT.READ | os.PROT.WRITE,
308 os.MAP_PRIVATE | os.MAP_ANONYMOUS,308 os.MAP.PRIVATE | os.MAP.ANONYMOUS,
309 -1,309 -1,
310 0,310 0,
311 ) catch return error.OutOfMemory;311 ) catch return error.OutOfMemory;
lib/std/os.zig+113-18
...@@ -16,7 +16,7 @@...@@ -16,7 +16,7 @@
1616
17const root = @import("root");17const root = @import("root");
18const std = @import("std.zig");18const std = @import("std.zig");
19const builtin = std.builtin;19const builtin = @import("builtin");
20const assert = std.debug.assert;20const assert = std.debug.assert;
21const math = std.math;21const math = std.math;
22const mem = std.mem;22const mem = std.mem;
...@@ -24,12 +24,12 @@ const elf = std.elf;...@@ -24,12 +24,12 @@ const elf = std.elf;
24const dl = @import("dynamic_library.zig");24const dl = @import("dynamic_library.zig");
25const MAX_PATH_BYTES = std.fs.MAX_PATH_BYTES;25const MAX_PATH_BYTES = std.fs.MAX_PATH_BYTES;
2626
27pub const darwin = @import("os/darwin.zig");27pub const darwin = std.c;
28pub const dragonfly = @import("os/dragonfly.zig");28pub const dragonfly = std.c;
29pub const freebsd = @import("os/freebsd.zig");29pub const freebsd = std.c;
30pub const haiku = @import("os/haiku.zig");30pub const haiku = std.c;
31pub const netbsd = @import("os/netbsd.zig");31pub const netbsd = std.c;
32pub const openbsd = @import("os/openbsd.zig");32pub const openbsd = std.c;
33pub const linux = @import("os/linux.zig");33pub const linux = @import("os/linux.zig");
34pub const uefi = @import("os/uefi.zig");34pub const uefi = @import("os/uefi.zig");
35pub const wasi = @import("os/wasi.zig");35pub const wasi = @import("os/wasi.zig");
...@@ -73,7 +73,102 @@ else switch (builtin.os.tag) {...@@ -73,7 +73,102 @@ else switch (builtin.os.tag) {
73 else => struct {},73 else => struct {},
74};74};
7575
76pub usingnamespace @import("os/bits.zig");76const bits = switch (builtin.os.tag) {
77 .macos, .ios, .tvos, .watchos => std.c,
78 .dragonfly => @import("os/bits/dragonfly.zig"),
79 .freebsd => @import("os/bits/freebsd.zig"),
80 .haiku => @import("os/bits/haiku.zig"),
81 .linux => linux,
82 .netbsd => @import("os/bits/netbsd.zig"),
83 .openbsd => @import("os/bits/openbsd.zig"),
84 .wasi => @import("os/bits/wasi.zig"),
85 .windows => @import("os/bits/windows.zig"),
86 else => struct {},
87};
88pub const E = bits.E;
89pub const ARCH = bits.ARCH;
90pub const Elf_Symndx = bits.Elf_Symndx;
91pub const F = bits.F;
92pub const Flock = bits.Flock;
93pub const LOCK = bits.LOCK;
94pub const MAP = bits.MAP;
95pub const MMAP2_UNIT = bits.MMAP2_UNIT;
96pub const O = bits.O;
97pub const REG = bits.REG;
98pub const SC = bits.SC;
99pub const SYS = bits.SYS;
100pub const VDSO = bits.VDSO;
101pub const blkcnt_t = bits.blkcnt_t;
102pub const blksize_t = bits.blksize_t;
103pub const dev_t = bits.dev_t;
104pub const ino_t = bits.ino_t;
105pub const kernel_stat = bits.kernel_stat;
106pub const libc_stat = bits.libc_stat;
107pub const mcontext_t = bits.mcontext_t;
108pub const mode_t = bits.mode_t;
109pub const msghdr = bits.msghdr;
110pub const msghdr_const = bits.msghdr_const;
111pub const nlink_t = bits.nlink_t;
112pub const off_t = bits.off_t;
113pub const time_t = bits.time_t;
114pub const timespec = bits.timespec;
115pub const timeval = bits.timeval;
116pub const timezone = bits.timezone;
117pub const ucontext_t = bits.ucontext_t;
118pub const user_desc = bits.user_desc;
119pub const pid_t = bits.pid_t;
120pub const fd_t = bits.fd_t;
121pub const uid_t = bits.uid_t;
122pub const gid_t = bits.gid_t;
123pub const clock_t = bits.clock_t;
124pub const NAME_MAX = bits.NAME_MAX;
125pub const PATH_MAX = bits.PATH_MAX;
126pub const IOV_MAX = bits.IOV_MAX;
127pub const MAX_ADDR_LEN = bits.MAX_ADDR_LEN;
128pub const STDIN_FILENO = bits.STDIN_FILENO;
129pub const STDOUT_FILENO = bits.STDIN_FILENO;
130pub const STDERR_FILENO = bits.STDIN_FILENO;
131pub const AT = bits.AT;
132pub const PROT = bits.PROT;
133pub const CLOCK = bits.CLOCK;
134pub const dl_phdr_info = bits.dl_phdr_info;
135pub const Sigaction = bits.Sigaction;
136pub const rlimit_resource = bits.rlimit_resource;
137pub const SIG = bits.SIG;
138pub const rlimit = bits.rlimit;
139pub const empty_sigset = bits.empty_sigset;
140pub const S = bits.S;
141pub const siginfo_t = bits.siginfo_t;
142pub const SA = bits.SA;
143
144pub const iovec = extern struct {
145 iov_base: [*]u8,
146 iov_len: usize,
147};
148
149pub const iovec_const = extern struct {
150 iov_base: [*]const u8,
151 iov_len: usize,
152};
153
154pub const LOG = struct {
155 /// system is unusable
156 pub const EMERG = 0;
157 /// action must be taken immediately
158 pub const ALERT = 1;
159 /// critical conditions
160 pub const CRIT = 2;
161 /// error conditions
162 pub const ERR = 3;
163 /// warning conditions
164 pub const WARNING = 4;
165 /// normal but significant condition
166 pub const NOTICE = 5;
167 /// informational
168 pub const INFO = 6;
169 /// debug-level messages
170 pub const DEBUG = 7;
171};
77172
78pub const socket_t = if (builtin.os.tag == .windows) windows.ws2_32.SOCKET else fd_t;173pub const socket_t = if (builtin.os.tag == .windows) windows.ws2_32.SOCKET else fd_t;
79174
...@@ -136,7 +231,7 @@ pub fn getrandom(buffer: []u8) GetRandomError!void {...@@ -136,7 +231,7 @@ pub fn getrandom(buffer: []u8) GetRandomError!void {
136 if (builtin.os.tag == .linux or builtin.os.tag == .freebsd) {231 if (builtin.os.tag == .linux or builtin.os.tag == .freebsd) {
137 var buf = buffer;232 var buf = buffer;
138 const use_c = builtin.os.tag != .linux or233 const use_c = builtin.os.tag != .linux or
139 std.c.versionCheck(builtin.Version{ .major = 2, .minor = 25, .patch = 0 }).ok;234 std.c.versionCheck(std.builtin.Version{ .major = 2, .minor = 25, .patch = 0 }).ok;
140235
141 while (buf.len != 0) {236 while (buf.len != 0) {
142 const res = if (use_c) blk: {237 const res = if (use_c) blk: {
...@@ -210,11 +305,11 @@ pub fn abort() noreturn {...@@ -210,11 +305,11 @@ pub fn abort() noreturn {
210 windows.kernel32.ExitProcess(3);305 windows.kernel32.ExitProcess(3);
211 }306 }
212 if (!builtin.link_libc and builtin.os.tag == .linux) {307 if (!builtin.link_libc and builtin.os.tag == .linux) {
213 raise(SIGABRT) catch {};308 raise(SIG.ABRT) catch {};
214309
215 // TODO the rest of the implementation of abort() from musl libc here310 // TODO the rest of the implementation of abort() from musl libc here
216311
217 raise(SIGKILL) catch {};312 raise(SIG.KILL) catch {};
218 exit(127);313 exit(127);
219 }314 }
220 if (builtin.os.tag == .uefi) {315 if (builtin.os.tag == .uefi) {
...@@ -239,15 +334,15 @@ pub fn raise(sig: u8) RaiseError!void {...@@ -239,15 +334,15 @@ pub fn raise(sig: u8) RaiseError!void {
239 }334 }
240335
241 if (builtin.os.tag == .linux) {336 if (builtin.os.tag == .linux) {
242 var set: linux.sigset_t = undefined;337 var set: bits.sigset_t = undefined;
243 // block application signals338 // block application signals
244 _ = linux.sigprocmask(SIG_BLOCK, &linux.app_mask, &set);339 _ = linux.sigprocmask(SIG.BLOCK, &linux.app_mask, &set);
245340
246 const tid = linux.gettid();341 const tid = linux.gettid();
247 const rc = linux.tkill(tid, sig);342 const rc = linux.tkill(tid, sig);
248343
249 // restore signal mask344 // restore signal mask
250 _ = linux.sigprocmask(SIG_SETMASK, &set, null);345 _ = linux.sigprocmask(SIG.SETMASK, &set, null);
251346
252 switch (errno(rc)) {347 switch (errno(rc)) {
253 .SUCCESS => return,348 .SUCCESS => return,
...@@ -2676,7 +2771,7 @@ pub fn isatty(handle: fd_t) bool {...@@ -2676,7 +2771,7 @@ pub fn isatty(handle: fd_t) bool {
2676 while (true) {2771 while (true) {
2677 var wsz: linux.winsize = undefined;2772 var wsz: linux.winsize = undefined;
2678 const fd = @bitCast(usize, @as(isize, handle));2773 const fd = @bitCast(usize, @as(isize, handle));
2679 const rc = linux.syscall3(.ioctl, fd, linux.TIOCGWINSZ, @ptrToInt(&wsz));2774 const rc = linux.syscall3(.ioctl, fd, linux.T.IOCGWINSZ, @ptrToInt(&wsz));
2680 switch (linux.getErrno(rc)) {2775 switch (linux.getErrno(rc)) {
2681 .SUCCESS => return true,2776 .SUCCESS => return true,
2682 .INTR => continue,2777 .INTR => continue,
...@@ -4679,7 +4774,7 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) ClockGetTimeError!void {...@@ -4679,7 +4774,7 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) ClockGetTimeError!void {
4679 return;4774 return;
4680 }4775 }
4681 if (std.Target.current.os.tag == .windows) {4776 if (std.Target.current.os.tag == .windows) {
4682 if (clk_id == CLOCK_REALTIME) {4777 if (clk_id == CLOCK.REALTIME) {
4683 var ft: windows.FILETIME = undefined;4778 var ft: windows.FILETIME = undefined;
4684 windows.kernel32.GetSystemTimeAsFileTime(&ft);4779 windows.kernel32.GetSystemTimeAsFileTime(&ft);
4685 // FileTime has a granularity of 100 nanoseconds and uses the NTFS/Windows epoch.4780 // FileTime has a granularity of 100 nanoseconds and uses the NTFS/Windows epoch.
...@@ -4691,7 +4786,7 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) ClockGetTimeError!void {...@@ -4691,7 +4786,7 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) ClockGetTimeError!void {
4691 };4786 };
4692 return;4787 return;
4693 } else {4788 } else {
4694 // TODO POSIX implementation of CLOCK_MONOTONIC on Windows.4789 // TODO POSIX implementation of CLOCK.MONOTONIC on Windows.
4695 return error.UnsupportedClock;4790 return error.UnsupportedClock;
4696 }4791 }
4697 }4792 }
...@@ -4929,7 +5024,7 @@ pub fn res_mkquery(...@@ -4929,7 +5024,7 @@ pub fn res_mkquery(
49295024
4930 // Make a reasonably unpredictable id5025 // Make a reasonably unpredictable id
4931 var ts: timespec = undefined;5026 var ts: timespec = undefined;
4932 clock_gettime(CLOCK_REALTIME, &ts) catch {};5027 clock_gettime(CLOCK.REALTIME, &ts) catch {};
4933 const UInt = std.meta.Int(.unsigned, std.meta.bitCount(@TypeOf(ts.tv_nsec)));5028 const UInt = std.meta.Int(.unsigned, std.meta.bitCount(@TypeOf(ts.tv_nsec)));
4934 const unsec = @bitCast(UInt, ts.tv_nsec);5029 const unsec = @bitCast(UInt, ts.tv_nsec);
4935 const id = @truncate(u32, unsec + unsec / 65536);5030 const id = @truncate(u32, unsec + unsec / 65536);
lib/std/os/bits.zig deleted-22
...@@ -1,22 +0,0 @@
1//! Platform-dependent types and values that are used along with OS-specific APIs.
2//! These are imported into `std.c`, `std.os`, and `std.os.linux`.
3//! Root source files can define `os.bits` and these will additionally be added
4//! to the namespace.
5
6const std = @import("std");
7const root = @import("root");
8
9pub usingnamespace switch (std.Target.current.os.tag) {
10 .macos, .ios, .tvos, .watchos => @import("bits/darwin.zig"),
11 .dragonfly => @import("bits/dragonfly.zig"),
12 .freebsd => @import("bits/freebsd.zig"),
13 .haiku => @import("bits/haiku.zig"),
14 .linux => @import("bits/linux.zig"),
15 .netbsd => @import("bits/netbsd.zig"),
16 .openbsd => @import("bits/openbsd.zig"),
17 .wasi => @import("bits/wasi.zig"),
18 .windows => @import("bits/windows.zig"),
19 else => struct {},
20};
21
22pub usingnamespace if (@hasDecl(root, "os") and @hasDecl(root.os, "bits")) root.os.bits else struct {};
lib/std/os/bits/darwin.zig-2
...@@ -2,8 +2,6 @@ const std = @import("../../std.zig");...@@ -2,8 +2,6 @@ const std = @import("../../std.zig");
2const assert = std.debug.assert;2const assert = std.debug.assert;
3const maxInt = std.math.maxInt;3const maxInt = std.math.maxInt;
44
5pub usingnamespace @import("posix.zig");
6
7// See: https://opensource.apple.com/source/xnu/xnu-6153.141.1/bsd/sys/_types.h.auto.html5// See: https://opensource.apple.com/source/xnu/xnu-6153.141.1/bsd/sys/_types.h.auto.html
8// TODO: audit mode_t/pid_t, should likely be u16/i326// TODO: audit mode_t/pid_t, should likely be u16/i32
9pub const fd_t = c_int;7pub const fd_t = c_int;
lib/std/os/bits/dragonfly.zig-2
...@@ -1,8 +1,6 @@...@@ -1,8 +1,6 @@
1const std = @import("../../std.zig");1const std = @import("../../std.zig");
2const maxInt = std.math.maxInt;2const maxInt = std.math.maxInt;
33
4pub usingnamespace @import("posix.zig");
5
6pub fn S_ISCHR(m: u32) bool {4pub fn S_ISCHR(m: u32) bool {
7 return m & S_IFMT == S_IFCHR;5 return m & S_IFMT == S_IFCHR;
8}6}
lib/std/os/bits/freebsd.zig-2
...@@ -2,8 +2,6 @@ const std = @import("../../std.zig");...@@ -2,8 +2,6 @@ const std = @import("../../std.zig");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const maxInt = std.math.maxInt;3const maxInt = std.math.maxInt;
44
5pub usingnamespace @import("posix.zig");
6
7pub const blksize_t = i32;5pub const blksize_t = i32;
8pub const blkcnt_t = i64;6pub const blkcnt_t = i64;
9pub const clockid_t = i32;7pub const clockid_t = i32;
lib/std/os/bits/haiku.zig-2
...@@ -1,8 +1,6 @@...@@ -1,8 +1,6 @@
1const std = @import("../../std.zig");1const std = @import("../../std.zig");
2const maxInt = std.math.maxInt;2const maxInt = std.math.maxInt;
33
4pub usingnamespace @import("posix.zig");
5
6pub const fd_t = c_int;4pub const fd_t = c_int;
7pub const pid_t = c_int;5pub const pid_t = c_int;
8pub const uid_t = u32;6pub const uid_t = u32;
lib/std/os/bits/linux.zig deleted-2455
...@@ -1,2455 +0,0 @@
1const std = @import("../../std.zig");
2const maxInt = std.math.maxInt;
3const arch = @import("builtin").target.cpu.arch;
4pub usingnamespace @import("posix.zig");
5
6pub const E = switch (arch) {
7 .mips, .mipsel => @import("linux/errno/mips.zig").E,
8 .sparc, .sparcel, .sparcv9 => @import("linux/errno/sparc.zig").E,
9 else => @import("linux/errno/generic.zig").E,
10};
11
12pub usingnamespace switch (arch) {
13 .i386 => @import("linux/i386.zig"),
14 .x86_64 => @import("linux/x86_64.zig"),
15 .aarch64 => @import("linux/arm64.zig"),
16 .arm, .thumb => @import("linux/arm-eabi.zig"),
17 .riscv64 => @import("linux/riscv64.zig"),
18 .sparcv9 => @import("linux/sparc64.zig"),
19 .mips, .mipsel => @import("linux/mips.zig"),
20 .powerpc => @import("linux/powerpc.zig"),
21 .powerpc64, .powerpc64le => @import("linux/powerpc64.zig"),
22 else => struct {},
23};
24
25pub usingnamespace @import("linux/netlink.zig");
26pub usingnamespace @import("linux/prctl.zig");
27pub usingnamespace @import("linux/securebits.zig");
28pub usingnamespace @import("linux/xdp.zig");
29
30const is_mips = arch.isMIPS();
31const is_ppc = arch.isPPC();
32const is_ppc64 = arch.isPPC64();
33const is_sparc = arch.isSPARC();
34
35pub const pid_t = i32;
36pub const fd_t = i32;
37pub const uid_t = u32;
38pub const gid_t = u32;
39pub const clock_t = isize;
40
41pub const NAME_MAX = 255;
42pub const PATH_MAX = 4096;
43pub const IOV_MAX = 1024;
44
45/// Largest hardware address length
46/// e.g. a mac address is a type of hardware address
47pub const MAX_ADDR_LEN = 32;
48
49pub const STDIN_FILENO = 0;
50pub const STDOUT_FILENO = 1;
51pub const STDERR_FILENO = 2;
52
53/// Special value used to indicate openat should use the current working directory
54pub const AT_FDCWD = -100;
55
56/// Do not follow symbolic links
57pub const AT_SYMLINK_NOFOLLOW = 0x100;
58
59/// Remove directory instead of unlinking file
60pub const AT_REMOVEDIR = 0x200;
61
62/// Follow symbolic links.
63pub const AT_SYMLINK_FOLLOW = 0x400;
64
65/// Suppress terminal automount traversal
66pub const AT_NO_AUTOMOUNT = 0x800;
67
68/// Allow empty relative pathname
69pub const AT_EMPTY_PATH = 0x1000;
70
71/// Type of synchronisation required from statx()
72pub const AT_STATX_SYNC_TYPE = 0x6000;
73
74/// - Do whatever stat() does
75pub const AT_STATX_SYNC_AS_STAT = 0x0000;
76
77/// - Force the attributes to be sync'd with the server
78pub const AT_STATX_FORCE_SYNC = 0x2000;
79
80/// - Don't sync attributes with the server
81pub const AT_STATX_DONT_SYNC = 0x4000;
82
83/// Apply to the entire subtree
84pub const AT_RECURSIVE = 0x8000;
85
86/// Default is extend size
87pub const FALLOC_FL_KEEP_SIZE = 0x01;
88
89/// De-allocates range
90pub const FALLOC_FL_PUNCH_HOLE = 0x02;
91
92/// Reserved codepoint
93pub const FALLOC_FL_NO_HIDE_STALE = 0x04;
94
95/// Removes a range of a file without leaving a hole in the file
96pub const FALLOC_FL_COLLAPSE_RANGE = 0x08;
97
98/// Converts a range of file to zeros preferably without issuing data IO
99pub const FALLOC_FL_ZERO_RANGE = 0x10;
100
101/// Inserts space within the file size without overwriting any existing data
102pub const FALLOC_FL_INSERT_RANGE = 0x20;
103
104/// Unshares shared blocks within the file size without overwriting any existing data
105pub const FALLOC_FL_UNSHARE_RANGE = 0x40;
106
107pub const FUTEX_WAIT = 0;
108pub const FUTEX_WAKE = 1;
109pub const FUTEX_FD = 2;
110pub const FUTEX_REQUEUE = 3;
111pub const FUTEX_CMP_REQUEUE = 4;
112pub const FUTEX_WAKE_OP = 5;
113pub const FUTEX_LOCK_PI = 6;
114pub const FUTEX_UNLOCK_PI = 7;
115pub const FUTEX_TRYLOCK_PI = 8;
116pub const FUTEX_WAIT_BITSET = 9;
117pub const FUTEX_WAKE_BITSET = 10;
118pub const FUTEX_WAIT_REQUEUE_PI = 11;
119pub const FUTEX_CMP_REQUEUE_PI = 12;
120
121pub const FUTEX_PRIVATE_FLAG = 128;
122
123pub const FUTEX_CLOCK_REALTIME = 256;
124
125/// page can not be accessed
126pub const PROT_NONE = 0x0;
127
128/// page can be read
129pub const PROT_READ = 0x1;
130
131/// page can be written
132pub const PROT_WRITE = 0x2;
133
134/// page can be executed
135pub const PROT_EXEC = 0x4;
136
137/// page may be used for atomic ops
138pub const PROT_SEM = switch (arch) {
139 // TODO: also xtensa
140 .mips, .mipsel, .mips64, .mips64el => 0x10,
141 else => 0x8,
142};
143
144/// mprotect flag: extend change to start of growsdown vma
145pub const PROT_GROWSDOWN = 0x01000000;
146
147/// mprotect flag: extend change to end of growsup vma
148pub const PROT_GROWSUP = 0x02000000;
149
150/// Share changes
151pub const MAP_SHARED = 0x01;
152
153/// Changes are private
154pub const MAP_PRIVATE = 0x02;
155
156/// share + validate extension flags
157pub const MAP_SHARED_VALIDATE = 0x03;
158
159/// Mask for type of mapping
160pub const MAP_TYPE = 0x0f;
161
162/// Interpret addr exactly
163pub const MAP_FIXED = 0x10;
164
165/// don't use a file
166pub const MAP_ANONYMOUS = if (is_mips) 0x800 else 0x20;
167
168// MAP_ 0x0100 - 0x4000 flags are per architecture
169
170/// populate (prefault) pagetables
171pub const MAP_POPULATE = if (is_mips) 0x10000 else 0x8000;
172
173/// do not block on IO
174pub const MAP_NONBLOCK = if (is_mips) 0x20000 else 0x10000;
175
176/// give out an address that is best suited for process/thread stacks
177pub const MAP_STACK = if (is_mips) 0x40000 else 0x20000;
178
179/// create a huge page mapping
180pub const MAP_HUGETLB = if (is_mips) 0x80000 else 0x40000;
181
182/// perform synchronous page faults for the mapping
183pub const MAP_SYNC = 0x80000;
184
185/// MAP_FIXED which doesn't unmap underlying mapping
186pub const MAP_FIXED_NOREPLACE = 0x100000;
187
188/// For anonymous mmap, memory could be uninitialized
189pub const MAP_UNINITIALIZED = 0x4000000;
190
191pub const FD_CLOEXEC = 1;
192
193pub const F_OK = 0;
194pub const X_OK = 1;
195pub const W_OK = 2;
196pub const R_OK = 4;
197
198pub const WNOHANG = 1;
199pub const WUNTRACED = 2;
200pub const WSTOPPED = 2;
201pub const WEXITED = 4;
202pub const WCONTINUED = 8;
203pub const WNOWAIT = 0x1000000;
204
205// waitid id types
206pub const P = enum(c_uint) {
207 ALL = 0,
208 PID = 1,
209 PGID = 2,
210 PIDFD = 3,
211 _,
212};
213
214pub usingnamespace if (is_mips)
215 struct {
216 pub const SA_NOCLDSTOP = 1;
217 pub const SA_NOCLDWAIT = 0x10000;
218 pub const SA_SIGINFO = 8;
219 pub const SA_RESTART = 0x10000000;
220 pub const SA_RESETHAND = 0x80000000;
221 pub const SA_ONSTACK = 0x08000000;
222 pub const SA_NODEFER = 0x40000000;
223 pub const SA_RESTORER = 0x04000000;
224
225 pub const SIG_BLOCK = 1;
226 pub const SIG_UNBLOCK = 2;
227 pub const SIG_SETMASK = 3;
228 }
229else if (is_sparc)
230 struct {
231 pub const SA_NOCLDSTOP = 0x8;
232 pub const SA_NOCLDWAIT = 0x100;
233 pub const SA_SIGINFO = 0x200;
234 pub const SA_RESTART = 0x2;
235 pub const SA_RESETHAND = 0x4;
236 pub const SA_ONSTACK = 0x1;
237 pub const SA_NODEFER = 0x20;
238 pub const SA_RESTORER = 0x04000000;
239
240 pub const SIG_BLOCK = 1;
241 pub const SIG_UNBLOCK = 2;
242 pub const SIG_SETMASK = 4;
243 }
244else
245 struct {
246 pub const SA_NOCLDSTOP = 1;
247 pub const SA_NOCLDWAIT = 2;
248 pub const SA_SIGINFO = 4;
249 pub const SA_RESTART = 0x10000000;
250 pub const SA_RESETHAND = 0x80000000;
251 pub const SA_ONSTACK = 0x08000000;
252 pub const SA_NODEFER = 0x40000000;
253 pub const SA_RESTORER = 0x04000000;
254
255 pub const SIG_BLOCK = 0;
256 pub const SIG_UNBLOCK = 1;
257 pub const SIG_SETMASK = 2;
258 };
259
260pub usingnamespace if (is_sparc) struct {
261 pub const SIGHUP = 1;
262 pub const SIGINT = 2;
263 pub const SIGQUIT = 3;
264 pub const SIGILL = 4;
265 pub const SIGTRAP = 5;
266 pub const SIGABRT = 6;
267 pub const SIGEMT = 7;
268 pub const SIGFPE = 8;
269 pub const SIGKILL = 9;
270 pub const SIGBUS = 10;
271 pub const SIGSEGV = 11;
272 pub const SIGSYS = 12;
273 pub const SIGPIPE = 13;
274 pub const SIGALRM = 14;
275 pub const SIGTERM = 15;
276 pub const SIGURG = 16;
277 pub const SIGSTOP = 17;
278 pub const SIGTSTP = 18;
279 pub const SIGCONT = 19;
280 pub const SIGCHLD = 20;
281 pub const SIGTTIN = 21;
282 pub const SIGTTOU = 22;
283 pub const SIGPOLL = 23;
284 pub const SIGXCPU = 24;
285 pub const SIGXFSZ = 25;
286 pub const SIGVTALRM = 26;
287 pub const SIGPROF = 27;
288 pub const SIGWINCH = 28;
289 pub const SIGLOST = 29;
290 pub const SIGUSR1 = 30;
291 pub const SIGUSR2 = 31;
292 pub const SIGIOT = SIGABRT;
293 pub const SIGCLD = SIGCHLD;
294 pub const SIGPWR = SIGLOST;
295 pub const SIGIO = SIGPOLL;
296} else struct {
297 pub const SIGHUP = 1;
298 pub const SIGINT = 2;
299 pub const SIGQUIT = 3;
300 pub const SIGILL = 4;
301 pub const SIGTRAP = 5;
302 pub const SIGABRT = 6;
303 pub const SIGIOT = SIGABRT;
304 pub const SIGBUS = 7;
305 pub const SIGFPE = 8;
306 pub const SIGKILL = 9;
307 pub const SIGUSR1 = 10;
308 pub const SIGSEGV = 11;
309 pub const SIGUSR2 = 12;
310 pub const SIGPIPE = 13;
311 pub const SIGALRM = 14;
312 pub const SIGTERM = 15;
313 pub const SIGSTKFLT = 16;
314 pub const SIGCHLD = 17;
315 pub const SIGCONT = 18;
316 pub const SIGSTOP = 19;
317 pub const SIGTSTP = 20;
318 pub const SIGTTIN = 21;
319 pub const SIGTTOU = 22;
320 pub const SIGURG = 23;
321 pub const SIGXCPU = 24;
322 pub const SIGXFSZ = 25;
323 pub const SIGVTALRM = 26;
324 pub const SIGPROF = 27;
325 pub const SIGWINCH = 28;
326 pub const SIGIO = 29;
327 pub const SIGPOLL = 29;
328 pub const SIGPWR = 30;
329 pub const SIGSYS = 31;
330 pub const SIGUNUSED = SIGSYS;
331};
332
333pub const O_RDONLY = 0o0;
334pub const O_WRONLY = 0o1;
335pub const O_RDWR = 0o2;
336
337pub const kernel_rwf = u32;
338
339/// high priority request, poll if possible
340pub const RWF_HIPRI: kernel_rwf = 0x00000001;
341
342/// per-IO O_DSYNC
343pub const RWF_DSYNC: kernel_rwf = 0x00000002;
344
345/// per-IO O_SYNC
346pub const RWF_SYNC: kernel_rwf = 0x00000004;
347
348/// per-IO, return -EAGAIN if operation would block
349pub const RWF_NOWAIT: kernel_rwf = 0x00000008;
350
351/// per-IO O_APPEND
352pub const RWF_APPEND: kernel_rwf = 0x00000010;
353
354pub const SEEK_SET = 0;
355pub const SEEK_CUR = 1;
356pub const SEEK_END = 2;
357
358pub const SHUT_RD = 0;
359pub const SHUT_WR = 1;
360pub const SHUT_RDWR = 2;
361
362pub const SOCK_STREAM = if (is_mips) 2 else 1;
363pub const SOCK_DGRAM = if (is_mips) 1 else 2;
364pub const SOCK_RAW = 3;
365pub const SOCK_RDM = 4;
366pub const SOCK_SEQPACKET = 5;
367pub const SOCK_DCCP = 6;
368pub const SOCK_PACKET = 10;
369pub const SOCK_CLOEXEC = 0o2000000;
370pub const SOCK_NONBLOCK = if (is_mips) 0o200 else 0o4000;
371
372pub const PF_UNSPEC = 0;
373pub const PF_LOCAL = 1;
374pub const PF_UNIX = PF_LOCAL;
375pub const PF_FILE = PF_LOCAL;
376pub const PF_INET = 2;
377pub const PF_AX25 = 3;
378pub const PF_IPX = 4;
379pub const PF_APPLETALK = 5;
380pub const PF_NETROM = 6;
381pub const PF_BRIDGE = 7;
382pub const PF_ATMPVC = 8;
383pub const PF_X25 = 9;
384pub const PF_INET6 = 10;
385pub const PF_ROSE = 11;
386pub const PF_DECnet = 12;
387pub const PF_NETBEUI = 13;
388pub const PF_SECURITY = 14;
389pub const PF_KEY = 15;
390pub const PF_NETLINK = 16;
391pub const PF_ROUTE = PF_NETLINK;
392pub const PF_PACKET = 17;
393pub const PF_ASH = 18;
394pub const PF_ECONET = 19;
395pub const PF_ATMSVC = 20;
396pub const PF_RDS = 21;
397pub const PF_SNA = 22;
398pub const PF_IRDA = 23;
399pub const PF_PPPOX = 24;
400pub const PF_WANPIPE = 25;
401pub const PF_LLC = 26;
402pub const PF_IB = 27;
403pub const PF_MPLS = 28;
404pub const PF_CAN = 29;
405pub const PF_TIPC = 30;
406pub const PF_BLUETOOTH = 31;
407pub const PF_IUCV = 32;
408pub const PF_RXRPC = 33;
409pub const PF_ISDN = 34;
410pub const PF_PHONET = 35;
411pub const PF_IEEE802154 = 36;
412pub const PF_CAIF = 37;
413pub const PF_ALG = 38;
414pub const PF_NFC = 39;
415pub const PF_VSOCK = 40;
416pub const PF_KCM = 41;
417pub const PF_QIPCRTR = 42;
418pub const PF_SMC = 43;
419pub const PF_XDP = 44;
420pub const PF_MAX = 45;
421
422pub const AF_UNSPEC = PF_UNSPEC;
423pub const AF_LOCAL = PF_LOCAL;
424pub const AF_UNIX = AF_LOCAL;
425pub const AF_FILE = AF_LOCAL;
426pub const AF_INET = PF_INET;
427pub const AF_AX25 = PF_AX25;
428pub const AF_IPX = PF_IPX;
429pub const AF_APPLETALK = PF_APPLETALK;
430pub const AF_NETROM = PF_NETROM;
431pub const AF_BRIDGE = PF_BRIDGE;
432pub const AF_ATMPVC = PF_ATMPVC;
433pub const AF_X25 = PF_X25;
434pub const AF_INET6 = PF_INET6;
435pub const AF_ROSE = PF_ROSE;
436pub const AF_DECnet = PF_DECnet;
437pub const AF_NETBEUI = PF_NETBEUI;
438pub const AF_SECURITY = PF_SECURITY;
439pub const AF_KEY = PF_KEY;
440pub const AF_NETLINK = PF_NETLINK;
441pub const AF_ROUTE = PF_ROUTE;
442pub const AF_PACKET = PF_PACKET;
443pub const AF_ASH = PF_ASH;
444pub const AF_ECONET = PF_ECONET;
445pub const AF_ATMSVC = PF_ATMSVC;
446pub const AF_RDS = PF_RDS;
447pub const AF_SNA = PF_SNA;
448pub const AF_IRDA = PF_IRDA;
449pub const AF_PPPOX = PF_PPPOX;
450pub const AF_WANPIPE = PF_WANPIPE;
451pub const AF_LLC = PF_LLC;
452pub const AF_IB = PF_IB;
453pub const AF_MPLS = PF_MPLS;
454pub const AF_CAN = PF_CAN;
455pub const AF_TIPC = PF_TIPC;
456pub const AF_BLUETOOTH = PF_BLUETOOTH;
457pub const AF_IUCV = PF_IUCV;
458pub const AF_RXRPC = PF_RXRPC;
459pub const AF_ISDN = PF_ISDN;
460pub const AF_PHONET = PF_PHONET;
461pub const AF_IEEE802154 = PF_IEEE802154;
462pub const AF_CAIF = PF_CAIF;
463pub const AF_ALG = PF_ALG;
464pub const AF_NFC = PF_NFC;
465pub const AF_VSOCK = PF_VSOCK;
466pub const AF_KCM = PF_KCM;
467pub const AF_QIPCRTR = PF_QIPCRTR;
468pub const AF_SMC = PF_SMC;
469pub const AF_XDP = PF_XDP;
470pub const AF_MAX = PF_MAX;
471
472pub usingnamespace if (is_mips)
473 struct {}
474else if (is_ppc or is_ppc64)
475 struct {
476 pub const SO_DEBUG = 1;
477 pub const SO_REUSEADDR = 2;
478 pub const SO_TYPE = 3;
479 pub const SO_ERROR = 4;
480 pub const SO_DONTROUTE = 5;
481 pub const SO_BROADCAST = 6;
482 pub const SO_SNDBUF = 7;
483 pub const SO_RCVBUF = 8;
484 pub const SO_KEEPALIVE = 9;
485 pub const SO_OOBINLINE = 10;
486 pub const SO_NO_CHECK = 11;
487 pub const SO_PRIORITY = 12;
488 pub const SO_LINGER = 13;
489 pub const SO_BSDCOMPAT = 14;
490 pub const SO_REUSEPORT = 15;
491 pub const SO_RCVLOWAT = 16;
492 pub const SO_SNDLOWAT = 17;
493 pub const SO_RCVTIMEO = 18;
494 pub const SO_SNDTIMEO = 19;
495 pub const SO_PASSCRED = 20;
496 pub const SO_PEERCRED = 21;
497 pub const SO_ACCEPTCONN = 30;
498 pub const SO_PEERSEC = 31;
499 pub const SO_SNDBUFFORCE = 32;
500 pub const SO_RCVBUFFORCE = 33;
501 pub const SO_PROTOCOL = 38;
502 pub const SO_DOMAIN = 39;
503 }
504else
505 struct {
506 pub const SO_DEBUG = 1;
507 pub const SO_REUSEADDR = 2;
508 pub const SO_TYPE = 3;
509 pub const SO_ERROR = 4;
510 pub const SO_DONTROUTE = 5;
511 pub const SO_BROADCAST = 6;
512 pub const SO_SNDBUF = 7;
513 pub const SO_RCVBUF = 8;
514 pub const SO_KEEPALIVE = 9;
515 pub const SO_OOBINLINE = 10;
516 pub const SO_NO_CHECK = 11;
517 pub const SO_PRIORITY = 12;
518 pub const SO_LINGER = 13;
519 pub const SO_BSDCOMPAT = 14;
520 pub const SO_REUSEPORT = 15;
521 pub const SO_PASSCRED = 16;
522 pub const SO_PEERCRED = 17;
523 pub const SO_RCVLOWAT = 18;
524 pub const SO_SNDLOWAT = 19;
525 pub const SO_RCVTIMEO = 20;
526 pub const SO_SNDTIMEO = 21;
527 pub const SO_ACCEPTCONN = 30;
528 pub const SO_PEERSEC = 31;
529 pub const SO_SNDBUFFORCE = 32;
530 pub const SO_RCVBUFFORCE = 33;
531 pub const SO_PROTOCOL = 38;
532 pub const SO_DOMAIN = 39;
533 };
534
535pub const SO_SECURITY_AUTHENTICATION = 22;
536pub const SO_SECURITY_ENCRYPTION_TRANSPORT = 23;
537pub const SO_SECURITY_ENCRYPTION_NETWORK = 24;
538
539pub const SO_BINDTODEVICE = 25;
540
541pub const SO_ATTACH_FILTER = 26;
542pub const SO_DETACH_FILTER = 27;
543pub const SO_GET_FILTER = SO_ATTACH_FILTER;
544
545pub const SO_PEERNAME = 28;
546pub const SO_TIMESTAMP_OLD = 29;
547pub const SO_PASSSEC = 34;
548pub const SO_TIMESTAMPNS_OLD = 35;
549pub const SO_MARK = 36;
550pub const SO_TIMESTAMPING_OLD = 37;
551
552pub const SO_RXQ_OVFL = 40;
553pub const SO_WIFI_STATUS = 41;
554pub const SCM_WIFI_STATUS = SO_WIFI_STATUS;
555pub const SO_PEEK_OFF = 42;
556pub const SO_NOFCS = 43;
557pub const SO_LOCK_FILTER = 44;
558pub const SO_SELECT_ERR_QUEUE = 45;
559pub const SO_BUSY_POLL = 46;
560pub const SO_MAX_PACING_RATE = 47;
561pub const SO_BPF_EXTENSIONS = 48;
562pub const SO_INCOMING_CPU = 49;
563pub const SO_ATTACH_BPF = 50;
564pub const SO_DETACH_BPF = SO_DETACH_FILTER;
565pub const SO_ATTACH_REUSEPORT_CBPF = 51;
566pub const SO_ATTACH_REUSEPORT_EBPF = 52;
567pub const SO_CNX_ADVICE = 53;
568pub const SCM_TIMESTAMPING_OPT_STATS = 54;
569pub const SO_MEMINFO = 55;
570pub const SO_INCOMING_NAPI_ID = 56;
571pub const SO_COOKIE = 57;
572pub const SCM_TIMESTAMPING_PKTINFO = 58;
573pub const SO_PEERGROUPS = 59;
574pub const SO_ZEROCOPY = 60;
575pub const SO_TXTIME = 61;
576pub const SCM_TXTIME = SO_TXTIME;
577pub const SO_BINDTOIFINDEX = 62;
578pub const SO_TIMESTAMP_NEW = 63;
579pub const SO_TIMESTAMPNS_NEW = 64;
580pub const SO_TIMESTAMPING_NEW = 65;
581pub const SO_RCVTIMEO_NEW = 66;
582pub const SO_SNDTIMEO_NEW = 67;
583pub const SO_DETACH_REUSEPORT_BPF = 68;
584
585pub const SOL_SOCKET = if (is_mips) 65535 else 1;
586
587pub const SOL_IP = 0;
588pub const SOL_IPV6 = 41;
589pub const SOL_ICMPV6 = 58;
590
591pub const SOL_RAW = 255;
592pub const SOL_DECNET = 261;
593pub const SOL_X25 = 262;
594pub const SOL_PACKET = 263;
595pub const SOL_ATM = 264;
596pub const SOL_AAL = 265;
597pub const SOL_IRDA = 266;
598pub const SOL_NETBEUI = 267;
599pub const SOL_LLC = 268;
600pub const SOL_DCCP = 269;
601pub const SOL_NETLINK = 270;
602pub const SOL_TIPC = 271;
603pub const SOL_RXRPC = 272;
604pub const SOL_PPPOL2TP = 273;
605pub const SOL_BLUETOOTH = 274;
606pub const SOL_PNPIPE = 275;
607pub const SOL_RDS = 276;
608pub const SOL_IUCV = 277;
609pub const SOL_CAIF = 278;
610pub const SOL_ALG = 279;
611pub const SOL_NFC = 280;
612pub const SOL_KCM = 281;
613pub const SOL_TLS = 282;
614pub const SOL_XDP = 283;
615
616pub const SOMAXCONN = 128;
617
618pub const IP_TOS = 1;
619pub const IP_TTL = 2;
620pub const IP_HDRINCL = 3;
621pub const IP_OPTIONS = 4;
622pub const IP_ROUTER_ALERT = 5;
623pub const IP_RECVOPTS = 6;
624pub const IP_RETOPTS = 7;
625pub const IP_PKTINFO = 8;
626pub const IP_PKTOPTIONS = 9;
627pub const IP_PMTUDISC = 10;
628pub const IP_MTU_DISCOVER = 10;
629pub const IP_RECVERR = 11;
630pub const IP_RECVTTL = 12;
631pub const IP_RECVTOS = 13;
632pub const IP_MTU = 14;
633pub const IP_FREEBIND = 15;
634pub const IP_IPSEC_POLICY = 16;
635pub const IP_XFRM_POLICY = 17;
636pub const IP_PASSSEC = 18;
637pub const IP_TRANSPARENT = 19;
638pub const IP_ORIGDSTADDR = 20;
639pub const IP_RECVORIGDSTADDR = IP_ORIGDSTADDR;
640pub const IP_MINTTL = 21;
641pub const IP_NODEFRAG = 22;
642pub const IP_CHECKSUM = 23;
643pub const IP_BIND_ADDRESS_NO_PORT = 24;
644pub const IP_RECVFRAGSIZE = 25;
645pub const IP_MULTICAST_IF = 32;
646pub const IP_MULTICAST_TTL = 33;
647pub const IP_MULTICAST_LOOP = 34;
648pub const IP_ADD_MEMBERSHIP = 35;
649pub const IP_DROP_MEMBERSHIP = 36;
650pub const IP_UNBLOCK_SOURCE = 37;
651pub const IP_BLOCK_SOURCE = 38;
652pub const IP_ADD_SOURCE_MEMBERSHIP = 39;
653pub const IP_DROP_SOURCE_MEMBERSHIP = 40;
654pub const IP_MSFILTER = 41;
655pub const IP_MULTICAST_ALL = 49;
656pub const IP_UNICAST_IF = 50;
657
658pub const IP_RECVRETOPTS = IP_RETOPTS;
659
660pub const IP_PMTUDISC_DONT = 0;
661pub const IP_PMTUDISC_WANT = 1;
662pub const IP_PMTUDISC_DO = 2;
663pub const IP_PMTUDISC_PROBE = 3;
664pub const IP_PMTUDISC_INTERFACE = 4;
665pub const IP_PMTUDISC_OMIT = 5;
666
667pub const IP_DEFAULT_MULTICAST_TTL = 1;
668pub const IP_DEFAULT_MULTICAST_LOOP = 1;
669pub const IP_MAX_MEMBERSHIPS = 20;
670
671// IPv6 socket options
672
673pub const IPV6_ADDRFORM = 1;
674pub const IPV6_2292PKTINFO = 2;
675pub const IPV6_2292HOPOPTS = 3;
676pub const IPV6_2292DSTOPTS = 4;
677pub const IPV6_2292RTHDR = 5;
678pub const IPV6_2292PKTOPTIONS = 6;
679pub const IPV6_CHECKSUM = 7;
680pub const IPV6_2292HOPLIMIT = 8;
681pub const IPV6_NEXTHOP = 9;
682pub const IPV6_AUTHHDR = 10;
683pub const IPV6_FLOWINFO = 11;
684
685pub const IPV6_UNICAST_HOPS = 16;
686pub const IPV6_MULTICAST_IF = 17;
687pub const IPV6_MULTICAST_HOPS = 18;
688pub const IPV6_MULTICAST_LOOP = 19;
689pub const IPV6_ADD_MEMBERSHIP = 20;
690pub const IPV6_DROP_MEMBERSHIP = 21;
691pub const IPV6_ROUTER_ALERT = 22;
692pub const IPV6_MTU_DISCOVER = 23;
693pub const IPV6_MTU = 24;
694pub const IPV6_RECVERR = 25;
695pub const IPV6_V6ONLY = 26;
696pub const IPV6_JOIN_ANYCAST = 27;
697pub const IPV6_LEAVE_ANYCAST = 28;
698
699// IPV6_MTU_DISCOVER values
700pub const IPV6_PMTUDISC_DONT = 0;
701pub const IPV6_PMTUDISC_WANT = 1;
702pub const IPV6_PMTUDISC_DO = 2;
703pub const IPV6_PMTUDISC_PROBE = 3;
704pub const IPV6_PMTUDISC_INTERFACE = 4;
705pub const IPV6_PMTUDISC_OMIT = 5;
706
707// Flowlabel
708pub const IPV6_FLOWLABEL_MGR = 32;
709pub const IPV6_FLOWINFO_SEND = 33;
710pub const IPV6_IPSEC_POLICY = 34;
711pub const IPV6_XFRM_POLICY = 35;
712pub const IPV6_HDRINCL = 36;
713
714// Advanced API (RFC3542) (1)
715pub const IPV6_RECVPKTINFO = 49;
716pub const IPV6_PKTINFO = 50;
717pub const IPV6_RECVHOPLIMIT = 51;
718pub const IPV6_HOPLIMIT = 52;
719pub const IPV6_RECVHOPOPTS = 53;
720pub const IPV6_HOPOPTS = 54;
721pub const IPV6_RTHDRDSTOPTS = 55;
722pub const IPV6_RECVRTHDR = 56;
723pub const IPV6_RTHDR = 57;
724pub const IPV6_RECVDSTOPTS = 58;
725pub const IPV6_DSTOPTS = 59;
726pub const IPV6_RECVPATHMTU = 60;
727pub const IPV6_PATHMTU = 61;
728pub const IPV6_DONTFRAG = 62;
729
730// Advanced API (RFC3542) (2)
731pub const IPV6_RECVTCLASS = 66;
732pub const IPV6_TCLASS = 67;
733
734pub const IPV6_AUTOFLOWLABEL = 70;
735
736// RFC5014: Source address selection
737pub const IPV6_ADDR_PREFERENCES = 72;
738
739pub const IPV6_PREFER_SRC_TMP = 0x0001;
740pub const IPV6_PREFER_SRC_PUBLIC = 0x0002;
741pub const IPV6_PREFER_SRC_PUBTMP_DEFAULT = 0x0100;
742pub const IPV6_PREFER_SRC_COA = 0x0004;
743pub const IPV6_PREFER_SRC_HOME = 0x0400;
744pub const IPV6_PREFER_SRC_CGA = 0x0008;
745pub const IPV6_PREFER_SRC_NONCGA = 0x0800;
746
747// RFC5082: Generalized Ttl Security Mechanism
748pub const IPV6_MINHOPCOUNT = 73;
749
750pub const IPV6_ORIGDSTADDR = 74;
751pub const IPV6_RECVORIGDSTADDR = IPV6_ORIGDSTADDR;
752pub const IPV6_TRANSPARENT = 75;
753pub const IPV6_UNICAST_IF = 76;
754pub const IPV6_RECVFRAGSIZE = 77;
755pub const IPV6_FREEBIND = 78;
756
757pub const MSG_OOB = 0x0001;
758pub const MSG_PEEK = 0x0002;
759pub const MSG_DONTROUTE = 0x0004;
760pub const MSG_CTRUNC = 0x0008;
761pub const MSG_PROXY = 0x0010;
762pub const MSG_TRUNC = 0x0020;
763pub const MSG_DONTWAIT = 0x0040;
764pub const MSG_EOR = 0x0080;
765pub const MSG_WAITALL = 0x0100;
766pub const MSG_FIN = 0x0200;
767pub const MSG_SYN = 0x0400;
768pub const MSG_CONFIRM = 0x0800;
769pub const MSG_RST = 0x1000;
770pub const MSG_ERRQUEUE = 0x2000;
771pub const MSG_NOSIGNAL = 0x4000;
772pub const MSG_MORE = 0x8000;
773pub const MSG_WAITFORONE = 0x10000;
774pub const MSG_BATCH = 0x40000;
775pub const MSG_ZEROCOPY = 0x4000000;
776pub const MSG_FASTOPEN = 0x20000000;
777pub const MSG_CMSG_CLOEXEC = 0x40000000;
778
779pub const DT_UNKNOWN = 0;
780pub const DT_FIFO = 1;
781pub const DT_CHR = 2;
782pub const DT_DIR = 4;
783pub const DT_BLK = 6;
784pub const DT_REG = 8;
785pub const DT_LNK = 10;
786pub const DT_SOCK = 12;
787pub const DT_WHT = 14;
788
789pub const TCGETS = if (is_mips) 0x540D else 0x5401;
790pub const TCSETS = 0x5402;
791pub const TCSETSW = 0x5403;
792pub const TCSETSF = 0x5404;
793pub const TCGETA = 0x5405;
794pub const TCSETA = 0x5406;
795pub const TCSETAW = 0x5407;
796pub const TCSETAF = 0x5408;
797pub const TCSBRK = 0x5409;
798pub const TCXONC = 0x540A;
799pub const TCFLSH = 0x540B;
800pub const TIOCEXCL = 0x540C;
801pub const TIOCNXCL = 0x540D;
802pub const TIOCSCTTY = 0x540E;
803pub const TIOCGPGRP = 0x540F;
804pub const TIOCSPGRP = 0x5410;
805pub const TIOCOUTQ = if (is_mips) 0x7472 else 0x5411;
806pub const TIOCSTI = 0x5412;
807pub const TIOCGWINSZ = if (is_mips or is_ppc64) 0x40087468 else 0x5413;
808pub const TIOCSWINSZ = if (is_mips or is_ppc64) 0x80087467 else 0x5414;
809pub const TIOCMGET = 0x5415;
810pub const TIOCMBIS = 0x5416;
811pub const TIOCMBIC = 0x5417;
812pub const TIOCMSET = 0x5418;
813pub const TIOCGSOFTCAR = 0x5419;
814pub const TIOCSSOFTCAR = 0x541A;
815pub const FIONREAD = if (is_mips) 0x467F else 0x541B;
816pub const TIOCINQ = FIONREAD;
817pub const TIOCLINUX = 0x541C;
818pub const TIOCCONS = 0x541D;
819pub const TIOCGSERIAL = 0x541E;
820pub const TIOCSSERIAL = 0x541F;
821pub const TIOCPKT = 0x5420;
822pub const FIONBIO = 0x5421;
823pub const TIOCNOTTY = 0x5422;
824pub const TIOCSETD = 0x5423;
825pub const TIOCGETD = 0x5424;
826pub const TCSBRKP = 0x5425;
827pub const TIOCSBRK = 0x5427;
828pub const TIOCCBRK = 0x5428;
829pub const TIOCGSID = 0x5429;
830pub const TIOCGRS485 = 0x542E;
831pub const TIOCSRS485 = 0x542F;
832pub const TIOCGPTN = 0x80045430;
833pub const TIOCSPTLCK = 0x40045431;
834pub const TIOCGDEV = 0x80045432;
835pub const TCGETX = 0x5432;
836pub const TCSETX = 0x5433;
837pub const TCSETXF = 0x5434;
838pub const TCSETXW = 0x5435;
839pub const TIOCSIG = 0x40045436;
840pub const TIOCVHANGUP = 0x5437;
841pub const TIOCGPKT = 0x80045438;
842pub const TIOCGPTLCK = 0x80045439;
843pub const TIOCGEXCL = 0x80045440;
844
845pub const EPOLL_CLOEXEC = O_CLOEXEC;
846
847pub const EPOLL_CTL_ADD = 1;
848pub const EPOLL_CTL_DEL = 2;
849pub const EPOLL_CTL_MOD = 3;
850
851pub const EPOLLIN = 0x001;
852pub const EPOLLPRI = 0x002;
853pub const EPOLLOUT = 0x004;
854pub const EPOLLRDNORM = 0x040;
855pub const EPOLLRDBAND = 0x080;
856pub const EPOLLWRNORM = if (is_mips) 0x004 else 0x100;
857pub const EPOLLWRBAND = if (is_mips) 0x100 else 0x200;
858pub const EPOLLMSG = 0x400;
859pub const EPOLLERR = 0x008;
860pub const EPOLLHUP = 0x010;
861pub const EPOLLRDHUP = 0x2000;
862pub const EPOLLEXCLUSIVE = (@as(u32, 1) << 28);
863pub const EPOLLWAKEUP = (@as(u32, 1) << 29);
864pub const EPOLLONESHOT = (@as(u32, 1) << 30);
865pub const EPOLLET = (@as(u32, 1) << 31);
866
867pub const CLOCK_REALTIME = 0;
868pub const CLOCK_MONOTONIC = 1;
869pub const CLOCK_PROCESS_CPUTIME_ID = 2;
870pub const CLOCK_THREAD_CPUTIME_ID = 3;
871pub const CLOCK_MONOTONIC_RAW = 4;
872pub const CLOCK_REALTIME_COARSE = 5;
873pub const CLOCK_MONOTONIC_COARSE = 6;
874pub const CLOCK_BOOTTIME = 7;
875pub const CLOCK_REALTIME_ALARM = 8;
876pub const CLOCK_BOOTTIME_ALARM = 9;
877pub const CLOCK_SGI_CYCLE = 10;
878pub const CLOCK_TAI = 11;
879
880pub const CSIGNAL = 0x000000ff;
881pub const CLONE_VM = 0x00000100;
882pub const CLONE_FS = 0x00000200;
883pub const CLONE_FILES = 0x00000400;
884pub const CLONE_SIGHAND = 0x00000800;
885pub const CLONE_PIDFD = 0x00001000;
886pub const CLONE_PTRACE = 0x00002000;
887pub const CLONE_VFORK = 0x00004000;
888pub const CLONE_PARENT = 0x00008000;
889pub const CLONE_THREAD = 0x00010000;
890pub const CLONE_NEWNS = 0x00020000;
891pub const CLONE_SYSVSEM = 0x00040000;
892pub const CLONE_SETTLS = 0x00080000;
893pub const CLONE_PARENT_SETTID = 0x00100000;
894pub const CLONE_CHILD_CLEARTID = 0x00200000;
895pub const CLONE_DETACHED = 0x00400000;
896pub const CLONE_UNTRACED = 0x00800000;
897pub const CLONE_CHILD_SETTID = 0x01000000;
898pub const CLONE_NEWCGROUP = 0x02000000;
899pub const CLONE_NEWUTS = 0x04000000;
900pub const CLONE_NEWIPC = 0x08000000;
901pub const CLONE_NEWUSER = 0x10000000;
902pub const CLONE_NEWPID = 0x20000000;
903pub const CLONE_NEWNET = 0x40000000;
904pub const CLONE_IO = 0x80000000;
905
906// Flags for the clone3() syscall.
907
908/// Clear any signal handler and reset to SIG_DFL.
909pub const CLONE_CLEAR_SIGHAND = 0x100000000;
910/// Clone into a specific cgroup given the right permissions.
911pub const CLONE_INTO_CGROUP = 0x200000000;
912
913// cloning flags intersect with CSIGNAL so can be used with unshare and clone3 syscalls only.
914
915/// New time namespace
916pub const CLONE_NEWTIME = 0x00000080;
917
918pub const EFD_SEMAPHORE = 1;
919pub const EFD_CLOEXEC = O_CLOEXEC;
920pub const EFD_NONBLOCK = O_NONBLOCK;
921
922pub const MS_RDONLY = 1;
923pub const MS_NOSUID = 2;
924pub const MS_NODEV = 4;
925pub const MS_NOEXEC = 8;
926pub const MS_SYNCHRONOUS = 16;
927pub const MS_REMOUNT = 32;
928pub const MS_MANDLOCK = 64;
929pub const MS_DIRSYNC = 128;
930pub const MS_NOATIME = 1024;
931pub const MS_NODIRATIME = 2048;
932pub const MS_BIND = 4096;
933pub const MS_MOVE = 8192;
934pub const MS_REC = 16384;
935pub const MS_SILENT = 32768;
936pub const MS_POSIXACL = (1 << 16);
937pub const MS_UNBINDABLE = (1 << 17);
938pub const MS_PRIVATE = (1 << 18);
939pub const MS_SLAVE = (1 << 19);
940pub const MS_SHARED = (1 << 20);
941pub const MS_RELATIME = (1 << 21);
942pub const MS_KERNMOUNT = (1 << 22);
943pub const MS_I_VERSION = (1 << 23);
944pub const MS_STRICTATIME = (1 << 24);
945pub const MS_LAZYTIME = (1 << 25);
946pub const MS_NOREMOTELOCK = (1 << 27);
947pub const MS_NOSEC = (1 << 28);
948pub const MS_BORN = (1 << 29);
949pub const MS_ACTIVE = (1 << 30);
950pub const MS_NOUSER = (1 << 31);
951
952pub const MS_RMT_MASK = (MS_RDONLY | MS_SYNCHRONOUS | MS_MANDLOCK | MS_I_VERSION | MS_LAZYTIME);
953
954pub const MS_MGC_VAL = 0xc0ed0000;
955pub const MS_MGC_MSK = 0xffff0000;
956
957pub const MNT_FORCE = 1;
958pub const MNT_DETACH = 2;
959pub const MNT_EXPIRE = 4;
960pub const UMOUNT_NOFOLLOW = 8;
961
962pub const IN_CLOEXEC = O_CLOEXEC;
963pub const IN_NONBLOCK = O_NONBLOCK;
964
965pub const IN_ACCESS = 0x00000001;
966pub const IN_MODIFY = 0x00000002;
967pub const IN_ATTRIB = 0x00000004;
968pub const IN_CLOSE_WRITE = 0x00000008;
969pub const IN_CLOSE_NOWRITE = 0x00000010;
970pub const IN_CLOSE = IN_CLOSE_WRITE | IN_CLOSE_NOWRITE;
971pub const IN_OPEN = 0x00000020;
972pub const IN_MOVED_FROM = 0x00000040;
973pub const IN_MOVED_TO = 0x00000080;
974pub const IN_MOVE = IN_MOVED_FROM | IN_MOVED_TO;
975pub const IN_CREATE = 0x00000100;
976pub const IN_DELETE = 0x00000200;
977pub const IN_DELETE_SELF = 0x00000400;
978pub const IN_MOVE_SELF = 0x00000800;
979pub const IN_ALL_EVENTS = 0x00000fff;
980
981pub const IN_UNMOUNT = 0x00002000;
982pub const IN_Q_OVERFLOW = 0x00004000;
983pub const IN_IGNORED = 0x00008000;
984
985pub const IN_ONLYDIR = 0x01000000;
986pub const IN_DONT_FOLLOW = 0x02000000;
987pub const IN_EXCL_UNLINK = 0x04000000;
988pub const IN_MASK_ADD = 0x20000000;
989
990pub const IN_ISDIR = 0x40000000;
991pub const IN_ONESHOT = 0x80000000;
992
993pub const S_IFMT = 0o170000;
994
995pub const S_IFDIR = 0o040000;
996pub const S_IFCHR = 0o020000;
997pub const S_IFBLK = 0o060000;
998pub const S_IFREG = 0o100000;
999pub const S_IFIFO = 0o010000;
1000pub const S_IFLNK = 0o120000;
1001pub const S_IFSOCK = 0o140000;
1002
1003pub const S_ISUID = 0o4000;
1004pub const S_ISGID = 0o2000;
1005pub const S_ISVTX = 0o1000;
1006pub const S_IRUSR = 0o400;
1007pub const S_IWUSR = 0o200;
1008pub const S_IXUSR = 0o100;
1009pub const S_IRWXU = 0o700;
1010pub const S_IRGRP = 0o040;
1011pub const S_IWGRP = 0o020;
1012pub const S_IXGRP = 0o010;
1013pub const S_IRWXG = 0o070;
1014pub const S_IROTH = 0o004;
1015pub const S_IWOTH = 0o002;
1016pub const S_IXOTH = 0o001;
1017pub const S_IRWXO = 0o007;
1018
1019pub fn S_ISREG(m: u32) bool {
1020 return m & S_IFMT == S_IFREG;
1021}
1022
1023pub fn S_ISDIR(m: u32) bool {
1024 return m & S_IFMT == S_IFDIR;
1025}
1026
1027pub fn S_ISCHR(m: u32) bool {
1028 return m & S_IFMT == S_IFCHR;
1029}
1030
1031pub fn S_ISBLK(m: u32) bool {
1032 return m & S_IFMT == S_IFBLK;
1033}
1034
1035pub fn S_ISFIFO(m: u32) bool {
1036 return m & S_IFMT == S_IFIFO;
1037}
1038
1039pub fn S_ISLNK(m: u32) bool {
1040 return m & S_IFMT == S_IFLNK;
1041}
1042
1043pub fn S_ISSOCK(m: u32) bool {
1044 return m & S_IFMT == S_IFSOCK;
1045}
1046
1047pub const UTIME_NOW = 0x3fffffff;
1048pub const UTIME_OMIT = 0x3ffffffe;
1049
1050pub const TFD_NONBLOCK = O_NONBLOCK;
1051pub const TFD_CLOEXEC = O_CLOEXEC;
1052
1053pub const TFD_TIMER_ABSTIME = 1;
1054pub const TFD_TIMER_CANCEL_ON_SET = (1 << 1);
1055
1056pub fn WEXITSTATUS(s: u32) u8 {
1057 return @intCast(u8, (s & 0xff00) >> 8);
1058}
1059pub fn WTERMSIG(s: u32) u32 {
1060 return s & 0x7f;
1061}
1062pub fn WSTOPSIG(s: u32) u32 {
1063 return WEXITSTATUS(s);
1064}
1065pub fn WIFEXITED(s: u32) bool {
1066 return WTERMSIG(s) == 0;
1067}
1068pub fn WIFSTOPPED(s: u32) bool {
1069 return @truncate(u16, ((s & 0xffff) *% 0x10001) >> 8) > 0x7f00;
1070}
1071pub fn WIFSIGNALED(s: u32) bool {
1072 return (s & 0xffff) -% 1 < 0xff;
1073}
1074
1075pub const winsize = extern struct {
1076 ws_row: u16,
1077 ws_col: u16,
1078 ws_xpixel: u16,
1079 ws_ypixel: u16,
1080};
1081
1082/// NSIG is the total number of signals defined.
1083/// As signal numbers are sequential, NSIG is one greater than the largest defined signal number.
1084pub const NSIG = if (is_mips) 128 else 65;
1085
1086pub const sigset_t = [1024 / 32]u32;
1087
1088pub const all_mask: sigset_t = [_]u32{0xffffffff} ** sigset_t.len;
1089pub const app_mask: sigset_t = [2]u32{ 0xfffffffc, 0x7fffffff } ++ [_]u32{0xffffffff} ** 30;
1090
1091pub const k_sigaction = switch (arch) {
1092 .mips, .mipsel => extern struct {
1093 flags: c_uint,
1094 handler: ?fn (c_int) callconv(.C) void,
1095 mask: [4]c_ulong,
1096 restorer: fn () callconv(.C) void,
1097 },
1098 .mips64, .mips64el => extern struct {
1099 flags: c_uint,
1100 handler: ?fn (c_int) callconv(.C) void,
1101 mask: [2]c_ulong,
1102 restorer: fn () callconv(.C) void,
1103 },
1104 else => extern struct {
1105 handler: ?fn (c_int) callconv(.C) void,
1106 flags: c_ulong,
1107 restorer: fn () callconv(.C) void,
1108 mask: [2]c_uint,
1109 },
1110};
1111
1112/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
1113pub const Sigaction = extern struct {
1114 pub const handler_fn = fn (c_int) callconv(.C) void;
1115 pub const sigaction_fn = fn (c_int, *const siginfo_t, ?*const c_void) callconv(.C) void;
1116
1117 handler: extern union {
1118 handler: ?handler_fn,
1119 sigaction: ?sigaction_fn,
1120 },
1121 mask: sigset_t,
1122 flags: c_uint,
1123 restorer: ?fn () callconv(.C) void = null,
1124};
1125
1126pub const SIG_ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize));
1127pub const SIG_DFL = @intToPtr(?Sigaction.sigaction_fn, 0);
1128pub const SIG_IGN = @intToPtr(?Sigaction.sigaction_fn, 1);
1129
1130pub const empty_sigset = [_]u32{0} ** @typeInfo(sigset_t).Array.len;
1131
1132pub const SFD_CLOEXEC = O_CLOEXEC;
1133pub const SFD_NONBLOCK = O_NONBLOCK;
1134
1135pub const signalfd_siginfo = extern struct {
1136 signo: u32,
1137 errno: i32,
1138 code: i32,
1139 pid: u32,
1140 uid: uid_t,
1141 fd: i32,
1142 tid: u32,
1143 band: u32,
1144 overrun: u32,
1145 trapno: u32,
1146 status: i32,
1147 int: i32,
1148 ptr: u64,
1149 utime: u64,
1150 stime: u64,
1151 addr: u64,
1152 addr_lsb: u16,
1153 __pad2: u16,
1154 syscall: i32,
1155 call_addr: u64,
1156 arch: u32,
1157 __pad: [28]u8,
1158};
1159
1160pub const in_port_t = u16;
1161pub const sa_family_t = u16;
1162pub const socklen_t = u32;
1163
1164pub const sockaddr = extern struct {
1165 family: sa_family_t,
1166 data: [14]u8,
1167};
1168
1169pub const sockaddr_storage = std.x.os.Socket.Address.Native.Storage;
1170
1171/// IPv4 socket address
1172pub const sockaddr_in = extern struct {
1173 family: sa_family_t = AF_INET,
1174 port: in_port_t,
1175 addr: u32,
1176 zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
1177};
1178
1179/// IPv6 socket address
1180pub const sockaddr_in6 = extern struct {
1181 family: sa_family_t = AF_INET6,
1182 port: in_port_t,
1183 flowinfo: u32,
1184 addr: [16]u8,
1185 scope_id: u32,
1186};
1187
1188/// UNIX domain socket address
1189pub const sockaddr_un = extern struct {
1190 family: sa_family_t = AF_UNIX,
1191 path: [108]u8,
1192};
1193
1194pub const mmsghdr = extern struct {
1195 msg_hdr: msghdr,
1196 msg_len: u32,
1197};
1198
1199pub const mmsghdr_const = extern struct {
1200 msg_hdr: msghdr_const,
1201 msg_len: u32,
1202};
1203
1204pub const epoll_data = extern union {
1205 ptr: usize,
1206 fd: i32,
1207 @"u32": u32,
1208 @"u64": u64,
1209};
1210
1211// On x86_64 the structure is packed so that it matches the definition of its
1212// 32bit counterpart
1213pub const epoll_event = switch (arch) {
1214 .x86_64 => packed struct {
1215 events: u32,
1216 data: epoll_data,
1217 },
1218 else => extern struct {
1219 events: u32,
1220 data: epoll_data,
1221 },
1222};
1223
1224pub const _LINUX_CAPABILITY_VERSION_1 = 0x19980330;
1225pub const _LINUX_CAPABILITY_U32S_1 = 1;
1226
1227pub const _LINUX_CAPABILITY_VERSION_2 = 0x20071026;
1228pub const _LINUX_CAPABILITY_U32S_2 = 2;
1229
1230pub const _LINUX_CAPABILITY_VERSION_3 = 0x20080522;
1231pub const _LINUX_CAPABILITY_U32S_3 = 2;
1232
1233pub const VFS_CAP_REVISION_MASK = 0xFF000000;
1234pub const VFS_CAP_REVISION_SHIFT = 24;
1235pub const VFS_CAP_FLAGS_MASK = ~VFS_CAP_REVISION_MASK;
1236pub const VFS_CAP_FLAGS_EFFECTIVE = 0x000001;
1237
1238pub const VFS_CAP_REVISION_1 = 0x01000000;
1239pub const VFS_CAP_U32_1 = 1;
1240pub const XATTR_CAPS_SZ_1 = @sizeOf(u32) * (1 + 2 * VFS_CAP_U32_1);
1241
1242pub const VFS_CAP_REVISION_2 = 0x02000000;
1243pub const VFS_CAP_U32_2 = 2;
1244pub const XATTR_CAPS_SZ_2 = @sizeOf(u32) * (1 + 2 * VFS_CAP_U32_2);
1245
1246pub const XATTR_CAPS_SZ = XATTR_CAPS_SZ_2;
1247pub const VFS_CAP_U32 = VFS_CAP_U32_2;
1248pub const VFS_CAP_REVISION = VFS_CAP_REVISION_2;
1249
1250pub const vfs_cap_data = extern struct {
1251 //all of these are mandated as little endian
1252 //when on disk.
1253 const Data = struct {
1254 permitted: u32,
1255 inheritable: u32,
1256 };
1257
1258 magic_etc: u32,
1259 data: [VFS_CAP_U32]Data,
1260};
1261
1262pub const CAP_CHOWN = 0;
1263pub const CAP_DAC_OVERRIDE = 1;
1264pub const CAP_DAC_READ_SEARCH = 2;
1265pub const CAP_FOWNER = 3;
1266pub const CAP_FSETID = 4;
1267pub const CAP_KILL = 5;
1268pub const CAP_SETGID = 6;
1269pub const CAP_SETUID = 7;
1270pub const CAP_SETPCAP = 8;
1271pub const CAP_LINUX_IMMUTABLE = 9;
1272pub const CAP_NET_BIND_SERVICE = 10;
1273pub const CAP_NET_BROADCAST = 11;
1274pub const CAP_NET_ADMIN = 12;
1275pub const CAP_NET_RAW = 13;
1276pub const CAP_IPC_LOCK = 14;
1277pub const CAP_IPC_OWNER = 15;
1278pub const CAP_SYS_MODULE = 16;
1279pub const CAP_SYS_RAWIO = 17;
1280pub const CAP_SYS_CHROOT = 18;
1281pub const CAP_SYS_PTRACE = 19;
1282pub const CAP_SYS_PACCT = 20;
1283pub const CAP_SYS_ADMIN = 21;
1284pub const CAP_SYS_BOOT = 22;
1285pub const CAP_SYS_NICE = 23;
1286pub const CAP_SYS_RESOURCE = 24;
1287pub const CAP_SYS_TIME = 25;
1288pub const CAP_SYS_TTY_CONFIG = 26;
1289pub const CAP_MKNOD = 27;
1290pub const CAP_LEASE = 28;
1291pub const CAP_AUDIT_WRITE = 29;
1292pub const CAP_AUDIT_CONTROL = 30;
1293pub const CAP_SETFCAP = 31;
1294pub const CAP_MAC_OVERRIDE = 32;
1295pub const CAP_MAC_ADMIN = 33;
1296pub const CAP_SYSLOG = 34;
1297pub const CAP_WAKE_ALARM = 35;
1298pub const CAP_BLOCK_SUSPEND = 36;
1299pub const CAP_AUDIT_READ = 37;
1300pub const CAP_LAST_CAP = CAP_AUDIT_READ;
1301
1302pub fn cap_valid(x: u8) bool {
1303 return x >= 0 and x <= CAP_LAST_CAP;
1304}
1305
1306pub fn CAP_TO_MASK(cap: u8) u32 {
1307 return @as(u32, 1) << @intCast(u5, cap & 31);
1308}
1309
1310pub fn CAP_TO_INDEX(cap: u8) u8 {
1311 return cap >> 5;
1312}
1313
1314pub const cap_t = extern struct {
1315 hdrp: *cap_user_header_t,
1316 datap: *cap_user_data_t,
1317};
1318
1319pub const cap_user_header_t = extern struct {
1320 version: u32,
1321 pid: usize,
1322};
1323
1324pub const cap_user_data_t = extern struct {
1325 effective: u32,
1326 permitted: u32,
1327 inheritable: u32,
1328};
1329
1330pub const inotify_event = extern struct {
1331 wd: i32,
1332 mask: u32,
1333 cookie: u32,
1334 len: u32,
1335 //name: [?]u8,
1336};
1337
1338pub const dirent64 = extern struct {
1339 d_ino: u64,
1340 d_off: u64,
1341 d_reclen: u16,
1342 d_type: u8,
1343 d_name: u8, // field address is the address of first byte of name https://github.com/ziglang/zig/issues/173
1344
1345 pub fn reclen(self: dirent64) u16 {
1346 return self.d_reclen;
1347 }
1348};
1349
1350pub const dl_phdr_info = extern struct {
1351 dlpi_addr: usize,
1352 dlpi_name: ?[*:0]const u8,
1353 dlpi_phdr: [*]std.elf.Phdr,
1354 dlpi_phnum: u16,
1355};
1356
1357pub const CPU_SETSIZE = 128;
1358pub const cpu_set_t = [CPU_SETSIZE / @sizeOf(usize)]usize;
1359pub const cpu_count_t = std.meta.Int(.unsigned, std.math.log2(CPU_SETSIZE * 8));
1360
1361pub fn CPU_COUNT(set: cpu_set_t) cpu_count_t {
1362 var sum: cpu_count_t = 0;
1363 for (set) |x| {
1364 sum += @popCount(usize, x);
1365 }
1366 return sum;
1367}
1368
1369// TODO port these over
1370//#define CPU_SET(i, set) CPU_SET_S(i,sizeof(cpu_set_t),set)
1371//#define CPU_CLR(i, set) CPU_CLR_S(i,sizeof(cpu_set_t),set)
1372//#define CPU_ISSET(i, set) CPU_ISSET_S(i,sizeof(cpu_set_t),set)
1373//#define CPU_AND(d,s1,s2) CPU_AND_S(sizeof(cpu_set_t),d,s1,s2)
1374//#define CPU_OR(d,s1,s2) CPU_OR_S(sizeof(cpu_set_t),d,s1,s2)
1375//#define CPU_XOR(d,s1,s2) CPU_XOR_S(sizeof(cpu_set_t),d,s1,s2)
1376//#define CPU_COUNT(set) CPU_COUNT_S(sizeof(cpu_set_t),set)
1377//#define CPU_ZERO(set) CPU_ZERO_S(sizeof(cpu_set_t),set)
1378//#define CPU_EQUAL(s1,s2) CPU_EQUAL_S(sizeof(cpu_set_t),s1,s2)
1379
1380pub const MINSIGSTKSZ = switch (arch) {
1381 .i386, .x86_64, .arm, .mipsel => 2048,
1382 .aarch64 => 5120,
1383 else => @compileError("MINSIGSTKSZ not defined for this architecture"),
1384};
1385pub const SIGSTKSZ = switch (arch) {
1386 .i386, .x86_64, .arm, .mipsel => 8192,
1387 .aarch64 => 16384,
1388 else => @compileError("SIGSTKSZ not defined for this architecture"),
1389};
1390
1391pub const SS_ONSTACK = 1;
1392pub const SS_DISABLE = 2;
1393pub const SS_AUTODISARM = 1 << 31;
1394
1395pub const stack_t = if (is_mips)
1396 // IRIX compatible stack_t
1397 extern struct {
1398 ss_sp: [*]u8,
1399 ss_size: usize,
1400 ss_flags: i32,
1401 }
1402else
1403 extern struct {
1404 ss_sp: [*]u8,
1405 ss_flags: i32,
1406 ss_size: usize,
1407 };
1408
1409pub const sigval = extern union {
1410 int: i32,
1411 ptr: *c_void,
1412};
1413
1414const siginfo_fields_union = extern union {
1415 pad: [128 - 2 * @sizeOf(c_int) - @sizeOf(c_long)]u8,
1416 common: extern struct {
1417 first: extern union {
1418 piduid: extern struct {
1419 pid: pid_t,
1420 uid: uid_t,
1421 },
1422 timer: extern struct {
1423 timerid: i32,
1424 overrun: i32,
1425 },
1426 },
1427 second: extern union {
1428 value: sigval,
1429 sigchld: extern struct {
1430 status: i32,
1431 utime: clock_t,
1432 stime: clock_t,
1433 },
1434 },
1435 },
1436 sigfault: extern struct {
1437 addr: *c_void,
1438 addr_lsb: i16,
1439 first: extern union {
1440 addr_bnd: extern struct {
1441 lower: *c_void,
1442 upper: *c_void,
1443 },
1444 pkey: u32,
1445 },
1446 },
1447 sigpoll: extern struct {
1448 band: isize,
1449 fd: i32,
1450 },
1451 sigsys: extern struct {
1452 call_addr: *c_void,
1453 syscall: i32,
1454 arch: u32,
1455 },
1456};
1457
1458pub const siginfo_t = if (is_mips)
1459 extern struct {
1460 signo: i32,
1461 code: i32,
1462 errno: i32,
1463 fields: siginfo_fields_union,
1464 }
1465else
1466 extern struct {
1467 signo: i32,
1468 errno: i32,
1469 code: i32,
1470 fields: siginfo_fields_union,
1471 };
1472
1473pub const io_uring_params = extern struct {
1474 sq_entries: u32,
1475 cq_entries: u32,
1476 flags: u32,
1477 sq_thread_cpu: u32,
1478 sq_thread_idle: u32,
1479 features: u32,
1480 wq_fd: u32,
1481 resv: [3]u32,
1482 sq_off: io_sqring_offsets,
1483 cq_off: io_cqring_offsets,
1484};
1485
1486// io_uring_params.features flags
1487
1488pub const IORING_FEAT_SINGLE_MMAP = 1 << 0;
1489pub const IORING_FEAT_NODROP = 1 << 1;
1490pub const IORING_FEAT_SUBMIT_STABLE = 1 << 2;
1491pub const IORING_FEAT_RW_CUR_POS = 1 << 3;
1492pub const IORING_FEAT_CUR_PERSONALITY = 1 << 4;
1493pub const IORING_FEAT_FAST_POLL = 1 << 5;
1494pub const IORING_FEAT_POLL_32BITS = 1 << 6;
1495
1496// io_uring_params.flags
1497
1498/// io_context is polled
1499pub const IORING_SETUP_IOPOLL = 1 << 0;
1500
1501/// SQ poll thread
1502pub const IORING_SETUP_SQPOLL = 1 << 1;
1503
1504/// sq_thread_cpu is valid
1505pub const IORING_SETUP_SQ_AFF = 1 << 2;
1506
1507/// app defines CQ size
1508pub const IORING_SETUP_CQSIZE = 1 << 3;
1509
1510/// clamp SQ/CQ ring sizes
1511pub const IORING_SETUP_CLAMP = 1 << 4;
1512
1513/// attach to existing wq
1514pub const IORING_SETUP_ATTACH_WQ = 1 << 5;
1515
1516/// start with ring disabled
1517pub const IORING_SETUP_R_DISABLED = 1 << 6;
1518
1519pub const io_sqring_offsets = extern struct {
1520 /// offset of ring head
1521 head: u32,
1522
1523 /// offset of ring tail
1524 tail: u32,
1525
1526 /// ring mask value
1527 ring_mask: u32,
1528
1529 /// entries in ring
1530 ring_entries: u32,
1531
1532 /// ring flags
1533 flags: u32,
1534
1535 /// number of sqes not submitted
1536 dropped: u32,
1537
1538 /// sqe index array
1539 array: u32,
1540
1541 resv1: u32,
1542 resv2: u64,
1543};
1544
1545// io_sqring_offsets.flags
1546
1547/// needs io_uring_enter wakeup
1548pub const IORING_SQ_NEED_WAKEUP = 1 << 0;
1549
1550/// kernel has cqes waiting beyond the cq ring
1551pub const IORING_SQ_CQ_OVERFLOW = 1 << 1;
1552
1553pub const io_cqring_offsets = extern struct {
1554 head: u32,
1555 tail: u32,
1556 ring_mask: u32,
1557 ring_entries: u32,
1558 overflow: u32,
1559 cqes: u32,
1560 resv: [2]u64,
1561};
1562
1563pub const io_uring_sqe = extern struct {
1564 opcode: IORING_OP,
1565 flags: u8,
1566 ioprio: u16,
1567 fd: i32,
1568 off: u64,
1569 addr: u64,
1570 len: u32,
1571 rw_flags: u32,
1572 user_data: u64,
1573 buf_index: u16,
1574 personality: u16,
1575 splice_fd_in: i32,
1576 __pad2: [2]u64,
1577};
1578
1579pub const IOSQE_BIT = enum(u8) {
1580 FIXED_FILE,
1581 IO_DRAIN,
1582 IO_LINK,
1583 IO_HARDLINK,
1584 ASYNC,
1585 BUFFER_SELECT,
1586
1587 _,
1588};
1589
1590// io_uring_sqe.flags
1591
1592/// use fixed fileset
1593pub const IOSQE_FIXED_FILE = 1 << @enumToInt(IOSQE_BIT.FIXED_FILE);
1594
1595/// issue after inflight IO
1596pub const IOSQE_IO_DRAIN = 1 << @enumToInt(IOSQE_BIT.IO_DRAIN);
1597
1598/// links next sqe
1599pub const IOSQE_IO_LINK = 1 << @enumToInt(IOSQE_BIT.IO_LINK);
1600
1601/// like LINK, but stronger
1602pub const IOSQE_IO_HARDLINK = 1 << @enumToInt(IOSQE_BIT.IO_HARDLINK);
1603
1604/// always go async
1605pub const IOSQE_ASYNC = 1 << @enumToInt(IOSQE_BIT.ASYNC);
1606
1607/// select buffer from buf_group
1608pub const IOSQE_BUFFER_SELECT = 1 << @enumToInt(IOSQE_BIT.BUFFER_SELECT);
1609
1610pub const IORING_OP = enum(u8) {
1611 NOP,
1612 READV,
1613 WRITEV,
1614 FSYNC,
1615 READ_FIXED,
1616 WRITE_FIXED,
1617 POLL_ADD,
1618 POLL_REMOVE,
1619 SYNC_FILE_RANGE,
1620 SENDMSG,
1621 RECVMSG,
1622 TIMEOUT,
1623 TIMEOUT_REMOVE,
1624 ACCEPT,
1625 ASYNC_CANCEL,
1626 LINK_TIMEOUT,
1627 CONNECT,
1628 FALLOCATE,
1629 OPENAT,
1630 CLOSE,
1631 FILES_UPDATE,
1632 STATX,
1633 READ,
1634 WRITE,
1635 FADVISE,
1636 MADVISE,
1637 SEND,
1638 RECV,
1639 OPENAT2,
1640 EPOLL_CTL,
1641 SPLICE,
1642 PROVIDE_BUFFERS,
1643 REMOVE_BUFFERS,
1644 TEE,
1645
1646 _,
1647};
1648
1649// io_uring_sqe.fsync_flags
1650pub const IORING_FSYNC_DATASYNC = 1 << 0;
1651
1652// io_uring_sqe.timeout_flags
1653pub const IORING_TIMEOUT_ABS = 1 << 0;
1654
1655// IO completion data structure (Completion Queue Entry)
1656pub const io_uring_cqe = extern struct {
1657 /// io_uring_sqe.data submission passed back
1658 user_data: u64,
1659
1660 /// result code for this event
1661 res: i32,
1662 flags: u32,
1663
1664 pub fn err(self: io_uring_cqe) E {
1665 if (self.res > -4096 and self.res < 0) {
1666 return @intToEnum(E, -self.res);
1667 }
1668 return .SUCCESS;
1669 }
1670};
1671
1672// io_uring_cqe.flags
1673
1674/// If set, the upper 16 bits are the buffer ID
1675pub const IORING_CQE_F_BUFFER = 1 << 0;
1676
1677pub const IORING_OFF_SQ_RING = 0;
1678pub const IORING_OFF_CQ_RING = 0x8000000;
1679pub const IORING_OFF_SQES = 0x10000000;
1680
1681// io_uring_enter flags
1682pub const IORING_ENTER_GETEVENTS = 1 << 0;
1683pub const IORING_ENTER_SQ_WAKEUP = 1 << 1;
1684
1685// io_uring_register opcodes and arguments
1686pub const IORING_REGISTER = enum(u8) {
1687 REGISTER_BUFFERS,
1688 UNREGISTER_BUFFERS,
1689 REGISTER_FILES,
1690 UNREGISTER_FILES,
1691 REGISTER_EVENTFD,
1692 UNREGISTER_EVENTFD,
1693 REGISTER_FILES_UPDATE,
1694 REGISTER_EVENTFD_ASYNC,
1695 REGISTER_PROBE,
1696 REGISTER_PERSONALITY,
1697 UNREGISTER_PERSONALITY,
1698 REGISTER_RESTRICTIONS,
1699 REGISTER_ENABLE_RINGS,
1700
1701 _,
1702};
1703
1704pub const io_uring_files_update = extern struct {
1705 offset: u32,
1706 resv: u32,
1707 fds: u64,
1708};
1709
1710pub const IO_URING_OP_SUPPORTED = 1 << 0;
1711
1712pub const io_uring_probe_op = extern struct {
1713 op: IORING_OP,
1714
1715 resv: u8,
1716
1717 /// IO_URING_OP_* flags
1718 flags: u16,
1719
1720 resv2: u32,
1721};
1722
1723pub const io_uring_probe = extern struct {
1724 /// last opcode supported
1725 last_op: IORING_OP,
1726
1727 /// Number of io_uring_probe_op following
1728 ops_len: u8,
1729
1730 resv: u16,
1731 resv2: u32[3],
1732
1733 // Followed by up to `ops_len` io_uring_probe_op structures
1734};
1735
1736pub const io_uring_restriction = extern struct {
1737 opcode: u16,
1738 arg: extern union {
1739 /// IORING_RESTRICTION_REGISTER_OP
1740 register_op: IORING_REGISTER,
1741
1742 /// IORING_RESTRICTION_SQE_OP
1743 sqe_op: IORING_OP,
1744
1745 /// IORING_RESTRICTION_SQE_FLAGS_*
1746 sqe_flags: u8,
1747 },
1748 resv: u8,
1749 resv2: u32[3],
1750};
1751
1752/// io_uring_restriction->opcode values
1753pub const IORING_RESTRICTION = enum(u8) {
1754 /// Allow an io_uring_register(2) opcode
1755 REGISTER_OP = 0,
1756
1757 /// Allow an sqe opcode
1758 SQE_OP = 1,
1759
1760 /// Allow sqe flags
1761 SQE_FLAGS_ALLOWED = 2,
1762
1763 /// Require sqe flags (these flags must be set on each submission)
1764 SQE_FLAGS_REQUIRED = 3,
1765
1766 _,
1767};
1768
1769pub const utsname = extern struct {
1770 sysname: [64:0]u8,
1771 nodename: [64:0]u8,
1772 release: [64:0]u8,
1773 version: [64:0]u8,
1774 machine: [64:0]u8,
1775 domainname: [64:0]u8,
1776};
1777pub const HOST_NAME_MAX = 64;
1778
1779pub const STATX_TYPE = 0x0001;
1780pub const STATX_MODE = 0x0002;
1781pub const STATX_NLINK = 0x0004;
1782pub const STATX_UID = 0x0008;
1783pub const STATX_GID = 0x0010;
1784pub const STATX_ATIME = 0x0020;
1785pub const STATX_MTIME = 0x0040;
1786pub const STATX_CTIME = 0x0080;
1787pub const STATX_INO = 0x0100;
1788pub const STATX_SIZE = 0x0200;
1789pub const STATX_BLOCKS = 0x0400;
1790pub const STATX_BASIC_STATS = 0x07ff;
1791
1792pub const STATX_BTIME = 0x0800;
1793
1794pub const STATX_ATTR_COMPRESSED = 0x0004;
1795pub const STATX_ATTR_IMMUTABLE = 0x0010;
1796pub const STATX_ATTR_APPEND = 0x0020;
1797pub const STATX_ATTR_NODUMP = 0x0040;
1798pub const STATX_ATTR_ENCRYPTED = 0x0800;
1799pub const STATX_ATTR_AUTOMOUNT = 0x1000;
1800
1801pub const statx_timestamp = extern struct {
1802 tv_sec: i64,
1803 tv_nsec: u32,
1804 __pad1: u32,
1805};
1806
1807/// Renamed to `Statx` to not conflict with the `statx` function.
1808pub const Statx = extern struct {
1809 /// Mask of bits indicating filled fields
1810 mask: u32,
1811
1812 /// Block size for filesystem I/O
1813 blksize: u32,
1814
1815 /// Extra file attribute indicators
1816 attributes: u64,
1817
1818 /// Number of hard links
1819 nlink: u32,
1820
1821 /// User ID of owner
1822 uid: uid_t,
1823
1824 /// Group ID of owner
1825 gid: gid_t,
1826
1827 /// File type and mode
1828 mode: u16,
1829 __pad1: u16,
1830
1831 /// Inode number
1832 ino: u64,
1833
1834 /// Total size in bytes
1835 size: u64,
1836
1837 /// Number of 512B blocks allocated
1838 blocks: u64,
1839
1840 /// Mask to show what's supported in `attributes`.
1841 attributes_mask: u64,
1842
1843 /// Last access file timestamp
1844 atime: statx_timestamp,
1845
1846 /// Creation file timestamp
1847 btime: statx_timestamp,
1848
1849 /// Last status change file timestamp
1850 ctime: statx_timestamp,
1851
1852 /// Last modification file timestamp
1853 mtime: statx_timestamp,
1854
1855 /// Major ID, if this file represents a device.
1856 rdev_major: u32,
1857
1858 /// Minor ID, if this file represents a device.
1859 rdev_minor: u32,
1860
1861 /// Major ID of the device containing the filesystem where this file resides.
1862 dev_major: u32,
1863
1864 /// Minor ID of the device containing the filesystem where this file resides.
1865 dev_minor: u32,
1866
1867 __pad2: [14]u64,
1868};
1869
1870pub const addrinfo = extern struct {
1871 flags: i32,
1872 family: i32,
1873 socktype: i32,
1874 protocol: i32,
1875 addrlen: socklen_t,
1876 addr: ?*sockaddr,
1877 canonname: ?[*:0]u8,
1878 next: ?*addrinfo,
1879};
1880
1881pub const IPPORT_RESERVED = 1024;
1882
1883pub const IPPROTO_IP = 0;
1884pub const IPPROTO_HOPOPTS = 0;
1885pub const IPPROTO_ICMP = 1;
1886pub const IPPROTO_IGMP = 2;
1887pub const IPPROTO_IPIP = 4;
1888pub const IPPROTO_TCP = 6;
1889pub const IPPROTO_EGP = 8;
1890pub const IPPROTO_PUP = 12;
1891pub const IPPROTO_UDP = 17;
1892pub const IPPROTO_IDP = 22;
1893pub const IPPROTO_TP = 29;
1894pub const IPPROTO_DCCP = 33;
1895pub const IPPROTO_IPV6 = 41;
1896pub const IPPROTO_ROUTING = 43;
1897pub const IPPROTO_FRAGMENT = 44;
1898pub const IPPROTO_RSVP = 46;
1899pub const IPPROTO_GRE = 47;
1900pub const IPPROTO_ESP = 50;
1901pub const IPPROTO_AH = 51;
1902pub const IPPROTO_ICMPV6 = 58;
1903pub const IPPROTO_NONE = 59;
1904pub const IPPROTO_DSTOPTS = 60;
1905pub const IPPROTO_MTP = 92;
1906pub const IPPROTO_BEETPH = 94;
1907pub const IPPROTO_ENCAP = 98;
1908pub const IPPROTO_PIM = 103;
1909pub const IPPROTO_COMP = 108;
1910pub const IPPROTO_SCTP = 132;
1911pub const IPPROTO_MH = 135;
1912pub const IPPROTO_UDPLITE = 136;
1913pub const IPPROTO_MPLS = 137;
1914pub const IPPROTO_RAW = 255;
1915pub const IPPROTO_MAX = 256;
1916
1917pub const RR_A = 1;
1918pub const RR_CNAME = 5;
1919pub const RR_AAAA = 28;
1920
1921/// Turn off Nagle's algorithm
1922pub const TCP_NODELAY = 1;
1923/// Limit MSS
1924pub const TCP_MAXSEG = 2;
1925/// Never send partially complete segments.
1926pub const TCP_CORK = 3;
1927/// Start keeplives after this period, in seconds
1928pub const TCP_KEEPIDLE = 4;
1929/// Interval between keepalives
1930pub const TCP_KEEPINTVL = 5;
1931/// Number of keepalives before death
1932pub const TCP_KEEPCNT = 6;
1933/// Number of SYN retransmits
1934pub const TCP_SYNCNT = 7;
1935/// Life time of orphaned FIN-WAIT-2 state
1936pub const TCP_LINGER2 = 8;
1937/// Wake up listener only when data arrive
1938pub const TCP_DEFER_ACCEPT = 9;
1939/// Bound advertised window
1940pub const TCP_WINDOW_CLAMP = 10;
1941/// Information about this connection.
1942pub const TCP_INFO = 11;
1943/// Block/reenable quick acks
1944pub const TCP_QUICKACK = 12;
1945/// Congestion control algorithm
1946pub const TCP_CONGESTION = 13;
1947/// TCP MD5 Signature (RFC2385)
1948pub const TCP_MD5SIG = 14;
1949/// Use linear timeouts for thin streams
1950pub const TCP_THIN_LINEAR_TIMEOUTS = 16;
1951/// Fast retrans. after 1 dupack
1952pub const TCP_THIN_DUPACK = 17;
1953/// How long for loss retry before timeout
1954pub const TCP_USER_TIMEOUT = 18;
1955/// TCP sock is under repair right now
1956pub const TCP_REPAIR = 19;
1957pub const TCP_REPAIR_QUEUE = 20;
1958pub const TCP_QUEUE_SEQ = 21;
1959pub const TCP_REPAIR_OPTIONS = 22;
1960/// Enable FastOpen on listeners
1961pub const TCP_FASTOPEN = 23;
1962pub const TCP_TIMESTAMP = 24;
1963/// limit number of unsent bytes in write queue
1964pub const TCP_NOTSENT_LOWAT = 25;
1965/// Get Congestion Control (optional) info
1966pub const TCP_CC_INFO = 26;
1967/// Record SYN headers for new connections
1968pub const TCP_SAVE_SYN = 27;
1969/// Get SYN headers recorded for connection
1970pub const TCP_SAVED_SYN = 28;
1971/// Get/set window parameters
1972pub const TCP_REPAIR_WINDOW = 29;
1973/// Attempt FastOpen with connect
1974pub const TCP_FASTOPEN_CONNECT = 30;
1975/// Attach a ULP to a TCP connection
1976pub const TCP_ULP = 31;
1977/// TCP MD5 Signature with extensions
1978pub const TCP_MD5SIG_EXT = 32;
1979/// Set the key for Fast Open (cookie)
1980pub const TCP_FASTOPEN_KEY = 33;
1981/// Enable TFO without a TFO cookie
1982pub const TCP_FASTOPEN_NO_COOKIE = 34;
1983pub const TCP_ZEROCOPY_RECEIVE = 35;
1984/// Notify bytes available to read as a cmsg on read
1985pub const TCP_INQ = 36;
1986pub const TCP_CM_INQ = TCP_INQ;
1987/// delay outgoing packets by XX usec
1988pub const TCP_TX_DELAY = 37;
1989
1990pub const TCP_REPAIR_ON = 1;
1991pub const TCP_REPAIR_OFF = 0;
1992/// Turn off without window probes
1993pub const TCP_REPAIR_OFF_NO_WP = -1;
1994
1995pub const tcp_repair_opt = extern struct {
1996 opt_code: u32,
1997 opt_val: u32,
1998};
1999
2000pub const tcp_repair_window = extern struct {
2001 snd_wl1: u32,
2002 snd_wnd: u32,
2003 max_window: u32,
2004 rcv_wnd: u32,
2005 rcv_wup: u32,
2006};
2007
2008pub const TcpRepairOption = enum {
2009 TCP_NO_QUEUE,
2010 TCP_RECV_QUEUE,
2011 TCP_SEND_QUEUE,
2012 TCP_QUEUES_NR,
2013};
2014
2015/// why fastopen failed from client perspective
2016pub const tcp_fastopen_client_fail = enum {
2017 /// catch-all
2018 TFO_STATUS_UNSPEC,
2019 /// if not in TFO_CLIENT_NO_COOKIE mode
2020 TFO_COOKIE_UNAVAILABLE,
2021 /// SYN-ACK did not ack SYN data
2022 TFO_DATA_NOT_ACKED,
2023 /// SYN-ACK did not ack SYN data after timeout
2024 TFO_SYN_RETRANSMITTED,
2025};
2026
2027/// for TCP_INFO socket option
2028pub const TCPI_OPT_TIMESTAMPS = 1;
2029pub const TCPI_OPT_SACK = 2;
2030pub const TCPI_OPT_WSCALE = 4;
2031/// ECN was negociated at TCP session init
2032pub const TCPI_OPT_ECN = 8;
2033/// we received at least one packet with ECT
2034pub const TCPI_OPT_ECN_SEEN = 16;
2035/// SYN-ACK acked data in SYN sent or rcvd
2036pub const TCPI_OPT_SYN_DATA = 32;
2037
2038pub const nfds_t = usize;
2039pub const pollfd = extern struct {
2040 fd: fd_t,
2041 events: i16,
2042 revents: i16,
2043};
2044
2045pub const POLLIN = 0x001;
2046pub const POLLPRI = 0x002;
2047pub const POLLOUT = 0x004;
2048pub const POLLERR = 0x008;
2049pub const POLLHUP = 0x010;
2050pub const POLLNVAL = 0x020;
2051pub const POLLRDNORM = 0x040;
2052pub const POLLRDBAND = 0x080;
2053
2054pub const MFD_CLOEXEC = 0x0001;
2055pub const MFD_ALLOW_SEALING = 0x0002;
2056pub const MFD_HUGETLB = 0x0004;
2057pub const MFD_ALL_FLAGS = MFD_CLOEXEC | MFD_ALLOW_SEALING | MFD_HUGETLB;
2058
2059pub const HUGETLB_FLAG_ENCODE_SHIFT = 26;
2060pub const HUGETLB_FLAG_ENCODE_MASK = 0x3f;
2061pub const HUGETLB_FLAG_ENCODE_64KB = 16 << HUGETLB_FLAG_ENCODE_SHIFT;
2062pub const HUGETLB_FLAG_ENCODE_512KB = 19 << HUGETLB_FLAG_ENCODE_SHIFT;
2063pub const HUGETLB_FLAG_ENCODE_1MB = 20 << HUGETLB_FLAG_ENCODE_SHIFT;
2064pub const HUGETLB_FLAG_ENCODE_2MB = 21 << HUGETLB_FLAG_ENCODE_SHIFT;
2065pub const HUGETLB_FLAG_ENCODE_8MB = 23 << HUGETLB_FLAG_ENCODE_SHIFT;
2066pub const HUGETLB_FLAG_ENCODE_16MB = 24 << HUGETLB_FLAG_ENCODE_SHIFT;
2067pub const HUGETLB_FLAG_ENCODE_32MB = 25 << HUGETLB_FLAG_ENCODE_SHIFT;
2068pub const HUGETLB_FLAG_ENCODE_256MB = 28 << HUGETLB_FLAG_ENCODE_SHIFT;
2069pub const HUGETLB_FLAG_ENCODE_512MB = 29 << HUGETLB_FLAG_ENCODE_SHIFT;
2070pub const HUGETLB_FLAG_ENCODE_1GB = 30 << HUGETLB_FLAG_ENCODE_SHIFT;
2071pub const HUGETLB_FLAG_ENCODE_2GB = 31 << HUGETLB_FLAG_ENCODE_SHIFT;
2072pub const HUGETLB_FLAG_ENCODE_16GB = 34 << HUGETLB_FLAG_ENCODE_SHIFT;
2073
2074pub const MFD_HUGE_SHIFT = HUGETLB_FLAG_ENCODE_SHIFT;
2075pub const MFD_HUGE_MASK = HUGETLB_FLAG_ENCODE_MASK;
2076pub const MFD_HUGE_64KB = HUGETLB_FLAG_ENCODE_64KB;
2077pub const MFD_HUGE_512KB = HUGETLB_FLAG_ENCODE_512KB;
2078pub const MFD_HUGE_1MB = HUGETLB_FLAG_ENCODE_1MB;
2079pub const MFD_HUGE_2MB = HUGETLB_FLAG_ENCODE_2MB;
2080pub const MFD_HUGE_8MB = HUGETLB_FLAG_ENCODE_8MB;
2081pub const MFD_HUGE_16MB = HUGETLB_FLAG_ENCODE_16MB;
2082pub const MFD_HUGE_32MB = HUGETLB_FLAG_ENCODE_32MB;
2083pub const MFD_HUGE_256MB = HUGETLB_FLAG_ENCODE_256MB;
2084pub const MFD_HUGE_512MB = HUGETLB_FLAG_ENCODE_512MB;
2085pub const MFD_HUGE_1GB = HUGETLB_FLAG_ENCODE_1GB;
2086pub const MFD_HUGE_2GB = HUGETLB_FLAG_ENCODE_2GB;
2087pub const MFD_HUGE_16GB = HUGETLB_FLAG_ENCODE_16GB;
2088
2089pub const RUSAGE_SELF = 0;
2090pub const RUSAGE_CHILDREN = -1;
2091pub const RUSAGE_THREAD = 1;
2092
2093pub const rusage = extern struct {
2094 utime: timeval,
2095 stime: timeval,
2096 maxrss: isize,
2097 ixrss: isize,
2098 idrss: isize,
2099 isrss: isize,
2100 minflt: isize,
2101 majflt: isize,
2102 nswap: isize,
2103 inblock: isize,
2104 oublock: isize,
2105 msgsnd: isize,
2106 msgrcv: isize,
2107 nsignals: isize,
2108 nvcsw: isize,
2109 nivcsw: isize,
2110 __reserved: [16]isize = [1]isize{0} ** 16,
2111};
2112
2113pub const cc_t = u8;
2114pub const speed_t = u32;
2115pub const tcflag_t = u32;
2116
2117pub const NCCS = 32;
2118
2119pub const B0 = 0o0000000;
2120pub const B50 = 0o0000001;
2121pub const B75 = 0o0000002;
2122pub const B110 = 0o0000003;
2123pub const B134 = 0o0000004;
2124pub const B150 = 0o0000005;
2125pub const B200 = 0o0000006;
2126pub const B300 = 0o0000007;
2127pub const B600 = 0o0000010;
2128pub const B1200 = 0o0000011;
2129pub const B1800 = 0o0000012;
2130pub const B2400 = 0o0000013;
2131pub const B4800 = 0o0000014;
2132pub const B9600 = 0o0000015;
2133pub const B19200 = 0o0000016;
2134pub const B38400 = 0o0000017;
2135pub const BOTHER = 0o0010000;
2136pub const B57600 = 0o0010001;
2137pub const B115200 = 0o0010002;
2138pub const B230400 = 0o0010003;
2139pub const B460800 = 0o0010004;
2140pub const B500000 = 0o0010005;
2141pub const B576000 = 0o0010006;
2142pub const B921600 = 0o0010007;
2143pub const B1000000 = 0o0010010;
2144pub const B1152000 = 0o0010011;
2145pub const B1500000 = 0o0010012;
2146pub const B2000000 = 0o0010013;
2147pub const B2500000 = 0o0010014;
2148pub const B3000000 = 0o0010015;
2149pub const B3500000 = 0o0010016;
2150pub const B4000000 = 0o0010017;
2151
2152pub usingnamespace switch (arch) {
2153 .powerpc, .powerpc64, .powerpc64le => struct {
2154 pub const VINTR = 0;
2155 pub const VQUIT = 1;
2156 pub const VERASE = 2;
2157 pub const VKILL = 3;
2158 pub const VEOF = 4;
2159 pub const VMIN = 5;
2160 pub const VEOL = 6;
2161 pub const VTIME = 7;
2162 pub const VEOL2 = 8;
2163 pub const VSWTC = 9;
2164 pub const VWERASE = 10;
2165 pub const VREPRINT = 11;
2166 pub const VSUSP = 12;
2167 pub const VSTART = 13;
2168 pub const VSTOP = 14;
2169 pub const VLNEXT = 15;
2170 pub const VDISCARD = 16;
2171 },
2172 .sparc, .sparcv9 => struct {
2173 pub const VINTR = 0;
2174 pub const VQUIT = 1;
2175 pub const VERASE = 2;
2176 pub const VKILL = 3;
2177 pub const VEOF = 4;
2178 pub const VEOL = 5;
2179 pub const VEOL2 = 6;
2180 pub const VSWTC = 7;
2181 pub const VSTART = 8;
2182 pub const VSTOP = 9;
2183 pub const VSUSP = 10;
2184 pub const VDSUSP = 11;
2185 pub const VREPRINT = 12;
2186 pub const VDISCARD = 13;
2187 pub const VWERASE = 14;
2188 pub const VLNEXT = 15;
2189 pub const VMIN = VEOF;
2190 pub const VTIME = VEOL;
2191 },
2192 .mips, .mipsel, .mips64, .mips64el => struct {
2193 pub const VINTR = 0;
2194 pub const VQUIT = 1;
2195 pub const VERASE = 2;
2196 pub const VKILL = 3;
2197 pub const VMIN = 4;
2198 pub const VTIME = 5;
2199 pub const VEOL2 = 6;
2200 pub const VSWTC = 7;
2201 pub const VSWTCH = 7;
2202 pub const VSTART = 8;
2203 pub const VSTOP = 9;
2204 pub const VSUSP = 10;
2205 pub const VREPRINT = 12;
2206 pub const VDISCARD = 13;
2207 pub const VWERASE = 14;
2208 pub const VLNEXT = 15;
2209 pub const VEOF = 16;
2210 pub const VEOL = 17;
2211 },
2212 else => struct {
2213 pub const VINTR = 0;
2214 pub const VQUIT = 1;
2215 pub const VERASE = 2;
2216 pub const VKILL = 3;
2217 pub const VEOF = 4;
2218 pub const VTIME = 5;
2219 pub const VMIN = 6;
2220 pub const VSWTC = 7;
2221 pub const VSTART = 8;
2222 pub const VSTOP = 9;
2223 pub const VSUSP = 10;
2224 pub const VEOL = 11;
2225 pub const VREPRINT = 12;
2226 pub const VDISCARD = 13;
2227 pub const VWERASE = 14;
2228 pub const VLNEXT = 15;
2229 pub const VEOL2 = 16;
2230 },
2231};
2232
2233pub const IGNBRK = 1;
2234pub const BRKINT = 2;
2235pub const IGNPAR = 4;
2236pub const PARMRK = 8;
2237pub const INPCK = 16;
2238pub const ISTRIP = 32;
2239pub const INLCR = 64;
2240pub const IGNCR = 128;
2241pub const ICRNL = 256;
2242pub const IUCLC = 512;
2243pub const IXON = 1024;
2244pub const IXANY = 2048;
2245pub const IXOFF = 4096;
2246pub const IMAXBEL = 8192;
2247pub const IUTF8 = 16384;
2248
2249pub const OPOST = 1;
2250pub const OLCUC = 2;
2251pub const ONLCR = 4;
2252pub const OCRNL = 8;
2253pub const ONOCR = 16;
2254pub const ONLRET = 32;
2255pub const OFILL = 64;
2256pub const OFDEL = 128;
2257pub const VTDLY = 16384;
2258pub const VT0 = 0;
2259pub const VT1 = 16384;
2260
2261pub const CSIZE = 48;
2262pub const CS5 = 0;
2263pub const CS6 = 16;
2264pub const CS7 = 32;
2265pub const CS8 = 48;
2266pub const CSTOPB = 64;
2267pub const CREAD = 128;
2268pub const PARENB = 256;
2269pub const PARODD = 512;
2270pub const HUPCL = 1024;
2271pub const CLOCAL = 2048;
2272
2273pub const ISIG = 1;
2274pub const ICANON = 2;
2275pub const ECHO = 8;
2276pub const ECHOE = 16;
2277pub const ECHOK = 32;
2278pub const ECHONL = 64;
2279pub const NOFLSH = 128;
2280pub const TOSTOP = 256;
2281pub const IEXTEN = 32768;
2282
2283pub const TCSA = enum(c_uint) {
2284 NOW,
2285 DRAIN,
2286 FLUSH,
2287 _,
2288};
2289
2290pub const termios = extern struct {
2291 iflag: tcflag_t,
2292 oflag: tcflag_t,
2293 cflag: tcflag_t,
2294 lflag: tcflag_t,
2295 line: cc_t,
2296 cc: [NCCS]cc_t,
2297 ispeed: speed_t,
2298 ospeed: speed_t,
2299};
2300
2301pub const SIOCGIFINDEX = 0x8933;
2302pub const IFNAMESIZE = 16;
2303
2304pub const ifmap = extern struct {
2305 mem_start: u32,
2306 mem_end: u32,
2307 base_addr: u16,
2308 irq: u8,
2309 dma: u8,
2310 port: u8,
2311};
2312
2313pub const ifreq = extern struct {
2314 ifrn: extern union {
2315 name: [IFNAMESIZE]u8,
2316 },
2317 ifru: extern union {
2318 addr: sockaddr,
2319 dstaddr: sockaddr,
2320 broadaddr: sockaddr,
2321 netmask: sockaddr,
2322 hwaddr: sockaddr,
2323 flags: i16,
2324 ivalue: i32,
2325 mtu: i32,
2326 map: ifmap,
2327 slave: [IFNAMESIZE - 1:0]u8,
2328 newname: [IFNAMESIZE - 1:0]u8,
2329 data: ?[*]u8,
2330 },
2331};
2332
2333// doc comments copied from musl
2334pub const rlimit_resource = enum(c_int) {
2335 /// Per-process CPU limit, in seconds.
2336 CPU,
2337
2338 /// Largest file that can be created, in bytes.
2339 FSIZE,
2340
2341 /// Maximum size of data segment, in bytes.
2342 DATA,
2343
2344 /// Maximum size of stack segment, in bytes.
2345 STACK,
2346
2347 /// Largest core file that can be created, in bytes.
2348 CORE,
2349
2350 /// Largest resident set size, in bytes.
2351 /// This affects swapping; processes that are exceeding their
2352 /// resident set size will be more likely to have physical memory
2353 /// taken from them.
2354 RSS,
2355
2356 /// Number of processes.
2357 NPROC,
2358
2359 /// Number of open files.
2360 NOFILE,
2361
2362 /// Locked-in-memory address space.
2363 MEMLOCK,
2364
2365 /// Address space limit.
2366 AS,
2367
2368 /// Maximum number of file locks.
2369 LOCKS,
2370
2371 /// Maximum number of pending signals.
2372 SIGPENDING,
2373
2374 /// Maximum bytes in POSIX message queues.
2375 MSGQUEUE,
2376
2377 /// Maximum nice priority allowed to raise to.
2378 /// Nice levels 19 .. -20 correspond to 0 .. 39
2379 /// values of this resource limit.
2380 NICE,
2381
2382 /// Maximum realtime priority allowed for non-priviledged
2383 /// processes.
2384 RTPRIO,
2385
2386 /// Maximum CPU time in µs that a process scheduled under a real-time
2387 /// scheduling policy may consume without making a blocking system
2388 /// call before being forcibly descheduled.
2389 RTTIME,
2390
2391 _,
2392};
2393
2394pub const rlim_t = u64;
2395
2396/// No limit
2397pub const RLIM_INFINITY = ~@as(rlim_t, 0);
2398
2399pub const RLIM_SAVED_MAX = RLIM_INFINITY;
2400pub const RLIM_SAVED_CUR = RLIM_INFINITY;
2401
2402pub const rlimit = extern struct {
2403 /// Soft limit
2404 cur: rlim_t,
2405 /// Hard limit
2406 max: rlim_t,
2407};
2408
2409pub const MADV_NORMAL = 0;
2410pub const MADV_RANDOM = 1;
2411pub const MADV_SEQUENTIAL = 2;
2412pub const MADV_WILLNEED = 3;
2413pub const MADV_DONTNEED = 4;
2414pub const MADV_FREE = 8;
2415pub const MADV_REMOVE = 9;
2416pub const MADV_DONTFORK = 10;
2417pub const MADV_DOFORK = 11;
2418pub const MADV_MERGEABLE = 12;
2419pub const MADV_UNMERGEABLE = 13;
2420pub const MADV_HUGEPAGE = 14;
2421pub const MADV_NOHUGEPAGE = 15;
2422pub const MADV_DONTDUMP = 16;
2423pub const MADV_DODUMP = 17;
2424pub const MADV_WIPEONFORK = 18;
2425pub const MADV_KEEPONFORK = 19;
2426pub const MADV_COLD = 20;
2427pub const MADV_PAGEOUT = 21;
2428pub const MADV_HWPOISON = 100;
2429pub const MADV_SOFT_OFFLINE = 101;
2430
2431pub const POSIX_FADV_NORMAL = 0;
2432pub const POSIX_FADV_RANDOM = 1;
2433pub const POSIX_FADV_SEQUENTIAL = 2;
2434pub const POSIX_FADV_WILLNEED = 3;
2435pub usingnamespace switch (arch) {
2436 .s390x => if (@typeInfo(usize).Int.bits == 64)
2437 struct {
2438 pub const POSIX_FADV_DONTNEED = 6;
2439 pub const POSIX_FADV_NOREUSE = 7;
2440 }
2441 else
2442 struct {
2443 pub const POSIX_FADV_DONTNEED = 4;
2444 pub const POSIX_FADV_NOREUSE = 5;
2445 },
2446 else => struct {
2447 pub const POSIX_FADV_DONTNEED = 4;
2448 pub const POSIX_FADV_NOREUSE = 5;
2449 },
2450};
2451
2452pub const __kernel_timespec = extern struct {
2453 tv_sec: i64,
2454 tv_nsec: i64,
2455};
lib/std/os/bits/linux/errno/generic.zig deleted-460
...@@ -1,460 +0,0 @@
1pub const E = enum(u16) {
2 /// No error occurred.
3 /// Same code used for `NSROK`.
4 SUCCESS = 0,
5
6 /// Operation not permitted
7 PERM = 1,
8
9 /// No such file or directory
10 NOENT = 2,
11
12 /// No such process
13 SRCH = 3,
14
15 /// Interrupted system call
16 INTR = 4,
17
18 /// I/O error
19 IO = 5,
20
21 /// No such device or address
22 NXIO = 6,
23
24 /// Arg list too long
25 @"2BIG" = 7,
26
27 /// Exec format error
28 NOEXEC = 8,
29
30 /// Bad file number
31 BADF = 9,
32
33 /// No child processes
34 CHILD = 10,
35
36 /// Try again
37 /// Also means: WOULDBLOCK: operation would block
38 AGAIN = 11,
39
40 /// Out of memory
41 NOMEM = 12,
42
43 /// Permission denied
44 ACCES = 13,
45
46 /// Bad address
47 FAULT = 14,
48
49 /// Block device required
50 NOTBLK = 15,
51
52 /// Device or resource busy
53 BUSY = 16,
54
55 /// File exists
56 EXIST = 17,
57
58 /// Cross-device link
59 XDEV = 18,
60
61 /// No such device
62 NODEV = 19,
63
64 /// Not a directory
65 NOTDIR = 20,
66
67 /// Is a directory
68 ISDIR = 21,
69
70 /// Invalid argument
71 INVAL = 22,
72
73 /// File table overflow
74 NFILE = 23,
75
76 /// Too many open files
77 MFILE = 24,
78
79 /// Not a typewriter
80 NOTTY = 25,
81
82 /// Text file busy
83 TXTBSY = 26,
84
85 /// File too large
86 FBIG = 27,
87
88 /// No space left on device
89 NOSPC = 28,
90
91 /// Illegal seek
92 SPIPE = 29,
93
94 /// Read-only file system
95 ROFS = 30,
96
97 /// Too many links
98 MLINK = 31,
99
100 /// Broken pipe
101 PIPE = 32,
102
103 /// Math argument out of domain of func
104 DOM = 33,
105
106 /// Math result not representable
107 RANGE = 34,
108
109 /// Resource deadlock would occur
110 DEADLK = 35,
111
112 /// File name too long
113 NAMETOOLONG = 36,
114
115 /// No record locks available
116 NOLCK = 37,
117
118 /// Function not implemented
119 NOSYS = 38,
120
121 /// Directory not empty
122 NOTEMPTY = 39,
123
124 /// Too many symbolic links encountered
125 LOOP = 40,
126
127 /// No message of desired type
128 NOMSG = 42,
129
130 /// Identifier removed
131 IDRM = 43,
132
133 /// Channel number out of range
134 CHRNG = 44,
135
136 /// Level 2 not synchronized
137 L2NSYNC = 45,
138
139 /// Level 3 halted
140 L3HLT = 46,
141
142 /// Level 3 reset
143 L3RST = 47,
144
145 /// Link number out of range
146 LNRNG = 48,
147
148 /// Protocol driver not attached
149 UNATCH = 49,
150
151 /// No CSI structure available
152 NOCSI = 50,
153
154 /// Level 2 halted
155 L2HLT = 51,
156
157 /// Invalid exchange
158 BADE = 52,
159
160 /// Invalid request descriptor
161 BADR = 53,
162
163 /// Exchange full
164 XFULL = 54,
165
166 /// No anode
167 NOANO = 55,
168
169 /// Invalid request code
170 BADRQC = 56,
171
172 /// Invalid slot
173 BADSLT = 57,
174
175 /// Bad font file format
176 BFONT = 59,
177
178 /// Device not a stream
179 NOSTR = 60,
180
181 /// No data available
182 NODATA = 61,
183
184 /// Timer expired
185 TIME = 62,
186
187 /// Out of streams resources
188 NOSR = 63,
189
190 /// Machine is not on the network
191 NONET = 64,
192
193 /// Package not installed
194 NOPKG = 65,
195
196 /// Object is remote
197 REMOTE = 66,
198
199 /// Link has been severed
200 NOLINK = 67,
201
202 /// Advertise error
203 ADV = 68,
204
205 /// Srmount error
206 SRMNT = 69,
207
208 /// Communication error on send
209 COMM = 70,
210
211 /// Protocol error
212 PROTO = 71,
213
214 /// Multihop attempted
215 MULTIHOP = 72,
216
217 /// RFS specific error
218 DOTDOT = 73,
219
220 /// Not a data message
221 BADMSG = 74,
222
223 /// Value too large for defined data type
224 OVERFLOW = 75,
225
226 /// Name not unique on network
227 NOTUNIQ = 76,
228
229 /// File descriptor in bad state
230 BADFD = 77,
231
232 /// Remote address changed
233 REMCHG = 78,
234
235 /// Can not access a needed shared library
236 LIBACC = 79,
237
238 /// Accessing a corrupted shared library
239 LIBBAD = 80,
240
241 /// .lib section in a.out corrupted
242 LIBSCN = 81,
243
244 /// Attempting to link in too many shared libraries
245 LIBMAX = 82,
246
247 /// Cannot exec a shared library directly
248 LIBEXEC = 83,
249
250 /// Illegal byte sequence
251 ILSEQ = 84,
252
253 /// Interrupted system call should be restarted
254 RESTART = 85,
255
256 /// Streams pipe error
257 STRPIPE = 86,
258
259 /// Too many users
260 USERS = 87,
261
262 /// Socket operation on non-socket
263 NOTSOCK = 88,
264
265 /// Destination address required
266 DESTADDRREQ = 89,
267
268 /// Message too long
269 MSGSIZE = 90,
270
271 /// Protocol wrong type for socket
272 PROTOTYPE = 91,
273
274 /// Protocol not available
275 NOPROTOOPT = 92,
276
277 /// Protocol not supported
278 PROTONOSUPPORT = 93,
279
280 /// Socket type not supported
281 SOCKTNOSUPPORT = 94,
282
283 /// Operation not supported on transport endpoint
284 /// This code also means `NOTSUP`.
285 OPNOTSUPP = 95,
286
287 /// Protocol family not supported
288 PFNOSUPPORT = 96,
289
290 /// Address family not supported by protocol
291 AFNOSUPPORT = 97,
292
293 /// Address already in use
294 ADDRINUSE = 98,
295
296 /// Cannot assign requested address
297 ADDRNOTAVAIL = 99,
298
299 /// Network is down
300 NETDOWN = 100,
301
302 /// Network is unreachable
303 NETUNREACH = 101,
304
305 /// Network dropped connection because of reset
306 NETRESET = 102,
307
308 /// Software caused connection abort
309 CONNABORTED = 103,
310
311 /// Connection reset by peer
312 CONNRESET = 104,
313
314 /// No buffer space available
315 NOBUFS = 105,
316
317 /// Transport endpoint is already connected
318 ISCONN = 106,
319
320 /// Transport endpoint is not connected
321 NOTCONN = 107,
322
323 /// Cannot send after transport endpoint shutdown
324 SHUTDOWN = 108,
325
326 /// Too many references: cannot splice
327 TOOMANYREFS = 109,
328
329 /// Connection timed out
330 TIMEDOUT = 110,
331
332 /// Connection refused
333 CONNREFUSED = 111,
334
335 /// Host is down
336 HOSTDOWN = 112,
337
338 /// No route to host
339 HOSTUNREACH = 113,
340
341 /// Operation already in progress
342 ALREADY = 114,
343
344 /// Operation now in progress
345 INPROGRESS = 115,
346
347 /// Stale NFS file handle
348 STALE = 116,
349
350 /// Structure needs cleaning
351 UCLEAN = 117,
352
353 /// Not a XENIX named type file
354 NOTNAM = 118,
355
356 /// No XENIX semaphores available
357 NAVAIL = 119,
358
359 /// Is a named type file
360 ISNAM = 120,
361
362 /// Remote I/O error
363 REMOTEIO = 121,
364
365 /// Quota exceeded
366 DQUOT = 122,
367
368 /// No medium found
369 NOMEDIUM = 123,
370
371 /// Wrong medium type
372 MEDIUMTYPE = 124,
373
374 /// Operation canceled
375 CANCELED = 125,
376
377 /// Required key not available
378 NOKEY = 126,
379
380 /// Key has expired
381 KEYEXPIRED = 127,
382
383 /// Key has been revoked
384 KEYREVOKED = 128,
385
386 /// Key was rejected by service
387 KEYREJECTED = 129,
388
389 // for robust mutexes
390
391 /// Owner died
392 OWNERDEAD = 130,
393
394 /// State not recoverable
395 NOTRECOVERABLE = 131,
396
397 /// Operation not possible due to RF-kill
398 RFKILL = 132,
399
400 /// Memory page has hardware error
401 HWPOISON = 133,
402
403 // nameserver query return codes
404
405 /// DNS server returned answer with no data
406 NSRNODATA = 160,
407
408 /// DNS server claims query was misformatted
409 NSRFORMERR = 161,
410
411 /// DNS server returned general failure
412 NSRSERVFAIL = 162,
413
414 /// Domain name not found
415 NSRNOTFOUND = 163,
416
417 /// DNS server does not implement requested operation
418 NSRNOTIMP = 164,
419
420 /// DNS server refused query
421 NSRREFUSED = 165,
422
423 /// Misformatted DNS query
424 NSRBADQUERY = 166,
425
426 /// Misformatted domain name
427 NSRBADNAME = 167,
428
429 /// Unsupported address family
430 NSRBADFAMILY = 168,
431
432 /// Misformatted DNS reply
433 NSRBADRESP = 169,
434
435 /// Could not contact DNS servers
436 NSRCONNREFUSED = 170,
437
438 /// Timeout while contacting DNS servers
439 NSRTIMEOUT = 171,
440
441 /// End of file
442 NSROF = 172,
443
444 /// Error reading file
445 NSRFILE = 173,
446
447 /// Out of memory
448 NSRNOMEM = 174,
449
450 /// Application terminated lookup
451 NSRDESTRUCTION = 175,
452
453 /// Domain name is too long
454 NSRQUERYDOMAINTOOLONG = 176,
455
456 /// Domain name is too long
457 NSRCNAMELOOP = 177,
458
459 _,
460};
lib/std/os/bits/linux/errno/mips.zig deleted-141
...@@ -1,141 +0,0 @@
1//! These are MIPS ABI compatible.
2pub const E = enum(i32) {
3 /// No error occurred.
4 SUCCESS = 0,
5
6 PERM = 1,
7 NOENT = 2,
8 SRCH = 3,
9 INTR = 4,
10 IO = 5,
11 NXIO = 6,
12 @"2BIG" = 7,
13 NOEXEC = 8,
14 BADF = 9,
15 CHILD = 10,
16 /// Also used for WOULDBLOCK.
17 AGAIN = 11,
18 NOMEM = 12,
19 ACCES = 13,
20 FAULT = 14,
21 NOTBLK = 15,
22 BUSY = 16,
23 EXIST = 17,
24 XDEV = 18,
25 NODEV = 19,
26 NOTDIR = 20,
27 ISDIR = 21,
28 INVAL = 22,
29 NFILE = 23,
30 MFILE = 24,
31 NOTTY = 25,
32 TXTBSY = 26,
33 FBIG = 27,
34 NOSPC = 28,
35 SPIPE = 29,
36 ROFS = 30,
37 MLINK = 31,
38 PIPE = 32,
39 DOM = 33,
40 RANGE = 34,
41
42 NOMSG = 35,
43 IDRM = 36,
44 CHRNG = 37,
45 L2NSYNC = 38,
46 L3HLT = 39,
47 L3RST = 40,
48 LNRNG = 41,
49 UNATCH = 42,
50 NOCSI = 43,
51 L2HLT = 44,
52 DEADLK = 45,
53 NOLCK = 46,
54 BADE = 50,
55 BADR = 51,
56 XFULL = 52,
57 NOANO = 53,
58 BADRQC = 54,
59 BADSLT = 55,
60 DEADLOCK = 56,
61 BFONT = 59,
62 NOSTR = 60,
63 NODATA = 61,
64 TIME = 62,
65 NOSR = 63,
66 NONET = 64,
67 NOPKG = 65,
68 REMOTE = 66,
69 NOLINK = 67,
70 ADV = 68,
71 SRMNT = 69,
72 COMM = 70,
73 PROTO = 71,
74 DOTDOT = 73,
75 MULTIHOP = 74,
76 BADMSG = 77,
77 NAMETOOLONG = 78,
78 OVERFLOW = 79,
79 NOTUNIQ = 80,
80 BADFD = 81,
81 REMCHG = 82,
82 LIBACC = 83,
83 LIBBAD = 84,
84 LIBSCN = 85,
85 LIBMAX = 86,
86 LIBEXEC = 87,
87 ILSEQ = 88,
88 NOSYS = 89,
89 LOOP = 90,
90 RESTART = 91,
91 STRPIPE = 92,
92 NOTEMPTY = 93,
93 USERS = 94,
94 NOTSOCK = 95,
95 DESTADDRREQ = 96,
96 MSGSIZE = 97,
97 PROTOTYPE = 98,
98 NOPROTOOPT = 99,
99 PROTONOSUPPORT = 120,
100 SOCKTNOSUPPORT = 121,
101 OPNOTSUPP = 122,
102 PFNOSUPPORT = 123,
103 AFNOSUPPORT = 124,
104 ADDRINUSE = 125,
105 ADDRNOTAVAIL = 126,
106 NETDOWN = 127,
107 NETUNREACH = 128,
108 NETRESET = 129,
109 CONNABORTED = 130,
110 CONNRESET = 131,
111 NOBUFS = 132,
112 ISCONN = 133,
113 NOTCONN = 134,
114 UCLEAN = 135,
115 NOTNAM = 137,
116 NAVAIL = 138,
117 ISNAM = 139,
118 REMOTEIO = 140,
119 SHUTDOWN = 143,
120 TOOMANYREFS = 144,
121 TIMEDOUT = 145,
122 CONNREFUSED = 146,
123 HOSTDOWN = 147,
124 HOSTUNREACH = 148,
125 ALREADY = 149,
126 INPROGRESS = 150,
127 STALE = 151,
128 CANCELED = 158,
129 NOMEDIUM = 159,
130 MEDIUMTYPE = 160,
131 NOKEY = 161,
132 KEYEXPIRED = 162,
133 KEYREVOKED = 163,
134 KEYREJECTED = 164,
135 OWNERDEAD = 165,
136 NOTRECOVERABLE = 166,
137 RFKILL = 167,
138 HWPOISON = 168,
139 DQUOT = 1133,
140 _,
141};
lib/std/os/bits/linux/errno/sparc.zig deleted-144
...@@ -1,144 +0,0 @@
1//! These match the SunOS error numbering scheme.
2pub const E = enum(i32) {
3 /// No error occurred.
4 SUCCESS = 0,
5
6 PERM = 1,
7 NOENT = 2,
8 SRCH = 3,
9 INTR = 4,
10 IO = 5,
11 NXIO = 6,
12 @"2BIG" = 7,
13 NOEXEC = 8,
14 BADF = 9,
15 CHILD = 10,
16 /// Also used for WOULDBLOCK
17 AGAIN = 11,
18 NOMEM = 12,
19 ACCES = 13,
20 FAULT = 14,
21 NOTBLK = 15,
22 BUSY = 16,
23 EXIST = 17,
24 XDEV = 18,
25 NODEV = 19,
26 NOTDIR = 20,
27 ISDIR = 21,
28 INVAL = 22,
29 NFILE = 23,
30 MFILE = 24,
31 NOTTY = 25,
32 TXTBSY = 26,
33 FBIG = 27,
34 NOSPC = 28,
35 SPIPE = 29,
36 ROFS = 30,
37 MLINK = 31,
38 PIPE = 32,
39 DOM = 33,
40 RANGE = 34,
41
42 INPROGRESS = 36,
43 ALREADY = 37,
44 NOTSOCK = 38,
45 DESTADDRREQ = 39,
46 MSGSIZE = 40,
47 PROTOTYPE = 41,
48 NOPROTOOPT = 42,
49 PROTONOSUPPORT = 43,
50 SOCKTNOSUPPORT = 44,
51 /// Also used for NOTSUP
52 OPNOTSUPP = 45,
53 PFNOSUPPORT = 46,
54 AFNOSUPPORT = 47,
55 ADDRINUSE = 48,
56 ADDRNOTAVAIL = 49,
57 NETDOWN = 50,
58 NETUNREACH = 51,
59 NETRESET = 52,
60 CONNABORTED = 53,
61 CONNRESET = 54,
62 NOBUFS = 55,
63 ISCONN = 56,
64 NOTCONN = 57,
65 SHUTDOWN = 58,
66 TOOMANYREFS = 59,
67 TIMEDOUT = 60,
68 CONNREFUSED = 61,
69 LOOP = 62,
70 NAMETOOLONG = 63,
71 HOSTDOWN = 64,
72 HOSTUNREACH = 65,
73 NOTEMPTY = 66,
74 PROCLIM = 67,
75 USERS = 68,
76 DQUOT = 69,
77 STALE = 70,
78 REMOTE = 71,
79 NOSTR = 72,
80 TIME = 73,
81 NOSR = 74,
82 NOMSG = 75,
83 BADMSG = 76,
84 IDRM = 77,
85 DEADLK = 78,
86 NOLCK = 79,
87 NONET = 80,
88 RREMOTE = 81,
89 NOLINK = 82,
90 ADV = 83,
91 SRMNT = 84,
92 COMM = 85,
93 PROTO = 86,
94 MULTIHOP = 87,
95 DOTDOT = 88,
96 REMCHG = 89,
97 NOSYS = 90,
98 STRPIPE = 91,
99 OVERFLOW = 92,
100 BADFD = 93,
101 CHRNG = 94,
102 L2NSYNC = 95,
103 L3HLT = 96,
104 L3RST = 97,
105 LNRNG = 98,
106 UNATCH = 99,
107 NOCSI = 100,
108 L2HLT = 101,
109 BADE = 102,
110 BADR = 103,
111 XFULL = 104,
112 NOANO = 105,
113 BADRQC = 106,
114 BADSLT = 107,
115 DEADLOCK = 108,
116 BFONT = 109,
117 LIBEXEC = 110,
118 NODATA = 111,
119 LIBBAD = 112,
120 NOPKG = 113,
121 LIBACC = 114,
122 NOTUNIQ = 115,
123 RESTART = 116,
124 UCLEAN = 117,
125 NOTNAM = 118,
126 NAVAIL = 119,
127 ISNAM = 120,
128 REMOTEIO = 121,
129 ILSEQ = 122,
130 LIBMAX = 123,
131 LIBSCN = 124,
132 NOMEDIUM = 125,
133 MEDIUMTYPE = 126,
134 CANCELED = 127,
135 NOKEY = 128,
136 KEYEXPIRED = 129,
137 KEYREVOKED = 130,
138 KEYREJECTED = 131,
139 OWNERDEAD = 132,
140 NOTRECOVERABLE = 133,
141 RFKILL = 134,
142 HWPOISON = 135,
143 _,
144};
lib/std/os/bits/linux/i386.zig+172-117
...@@ -448,94 +448,145 @@ pub const SYS = enum(usize) {...@@ -448,94 +448,145 @@ pub const SYS = enum(usize) {
448 _,448 _,
449};449};
450450
451pub const O_CREAT = 0o100;451pub const O = struct {
452pub const O_EXCL = 0o200;452 pub const RDONLY = 0o0;
453pub const O_NOCTTY = 0o400;453 pub const WRONLY = 0o1;
454pub const O_TRUNC = 0o1000;454 pub const RDWR = 0o2;
455pub const O_APPEND = 0o2000;455
456pub const O_NONBLOCK = 0o4000;456 pub const CREAT = 0o100;
457pub const O_DSYNC = 0o10000;457 pub const EXCL = 0o200;
458pub const O_SYNC = 0o4010000;458 pub const NOCTTY = 0o400;
459pub const O_RSYNC = 0o4010000;459 pub const TRUNC = 0o1000;
460pub const O_DIRECTORY = 0o200000;460 pub const APPEND = 0o2000;
461pub const O_NOFOLLOW = 0o400000;461 pub const NONBLOCK = 0o4000;
462pub const O_CLOEXEC = 0o2000000;462 pub const DSYNC = 0o10000;
463463 pub const SYNC = 0o4010000;
464pub const O_ASYNC = 0o20000;464 pub const RSYNC = 0o4010000;
465pub const O_DIRECT = 0o40000;465 pub const DIRECTORY = 0o200000;
466pub const O_LARGEFILE = 0o100000;466 pub const NOFOLLOW = 0o400000;
467pub const O_NOATIME = 0o1000000;467 pub const CLOEXEC = 0o2000000;
468pub const O_PATH = 0o10000000;468
469pub const O_TMPFILE = 0o20200000;469 pub const ASYNC = 0o20000;
470pub const O_NDELAY = O_NONBLOCK;470 pub const DIRECT = 0o40000;
471471 pub const LARGEFILE = 0o100000;
472pub const F_DUPFD = 0;472 pub const NOATIME = 0o1000000;
473pub const F_GETFD = 1;473 pub const PATH = 0o10000000;
474pub const F_SETFD = 2;474 pub const TMPFILE = 0o20200000;
475pub const F_GETFL = 3;475 pub const NDELAY = NONBLOCK;
476pub const F_SETFL = 4;476};
477477
478pub const F_SETOWN = 8;478pub const F = struct {
479pub const F_GETOWN = 9;479 pub const DUPFD = 0;
480pub const F_SETSIG = 10;480 pub const GETFD = 1;
481pub const F_GETSIG = 11;481 pub const SETFD = 2;
482482 pub const GETFL = 3;
483pub const F_GETLK = 12;483 pub const SETFL = 4;
484pub const F_SETLK = 13;484 pub const SETOWN = 8;
485pub const F_SETLKW = 14;485 pub const GETOWN = 9;
486486 pub const SETSIG = 10;
487pub const F_RDLCK = 0;487 pub const GETSIG = 11;
488pub const F_WRLCK = 1;488 pub const GETLK = 12;
489pub const F_UNLCK = 2;489 pub const SETLK = 13;
490490 pub const SETLKW = 14;
491pub const LOCK_SH = 1;491 pub const SETOWN_EX = 15;
492pub const LOCK_EX = 2;492 pub const GETOWN_EX = 16;
493pub const LOCK_UN = 8;493 pub const GETOWNER_UIDS = 17;
494pub const LOCK_NB = 4;494
495495 pub const RDLCK = 0;
496pub const F_SETOWN_EX = 15;496 pub const WRLCK = 1;
497pub const F_GETOWN_EX = 16;497 pub const UNLCK = 2;
498498};
499pub const F_GETOWNER_UIDS = 17;499
500500pub const LOCK = struct {
501pub const MAP_NORESERVE = 0x4000;501 pub const SH = 1;
502pub const MAP_GROWSDOWN = 0x0100;502 pub const EX = 2;
503pub const MAP_DENYWRITE = 0x0800;503 pub const NB = 4;
504pub const MAP_EXECUTABLE = 0x1000;504 pub const UN = 8;
505pub const MAP_LOCKED = 0x2000;505};
506pub const MAP_32BIT = 0x40;506
507pub const MAP = struct {
508 /// Share changes
509 pub const SHARED = 0x01;
510
511 /// Changes are private
512 pub const PRIVATE = 0x02;
513
514 /// share + validate extension flags
515 pub const SHARED_VALIDATE = 0x03;
516
517 /// Mask for type of mapping
518 pub const TYPE = 0x0f;
519
520 /// Interpret addr exactly
521 pub const FIXED = 0x10;
522
523 /// don't use a file
524 pub const ANONYMOUS = if (is_mips) 0x800 else 0x20;
525
526 /// populate (prefault) pagetables
527 pub const POPULATE = if (is_mips) 0x10000 else 0x8000;
528
529 /// do not block on IO
530 pub const NONBLOCK = if (is_mips) 0x20000 else 0x10000;
531
532 /// give out an address that is best suited for process/thread stacks
533 pub const STACK = if (is_mips) 0x40000 else 0x20000;
534
535 /// create a huge page mapping
536 pub const HUGETLB = if (is_mips) 0x80000 else 0x40000;
537
538 /// perform synchronous page faults for the mapping
539 pub const SYNC = 0x80000;
540
541 /// FIXED which doesn't unmap underlying mapping
542 pub const FIXED_NOREPLACE = 0x100000;
543
544 /// For anonymous mmap, memory could be uninitialized
545 pub const UNINITIALIZED = 0x4000000;
546
547 pub const NORESERVE = 0x4000;
548 pub const GROWSDOWN = 0x0100;
549 pub const DENYWRITE = 0x0800;
550 pub const EXECUTABLE = 0x1000;
551 pub const LOCKED = 0x2000;
552 pub const @"32BIT" = 0x40;
553};
507554
508pub const MMAP2_UNIT = 4096;555pub const MMAP2_UNIT = 4096;
509556
510pub const VDSO_CGT_SYM = "__vdso_clock_gettime";557pub const VDSO = struct {
511pub const VDSO_CGT_VER = "LINUX_2.6";558 pub const CGT_SYM = "__vdso_clock_gettime";
559 pub const CGT_VER = "LINUX_2.6";
560};
561
562pub const ARCH = struct {};
512563
513pub const Flock = extern struct {564pub const Flock = extern struct {
514 l_type: i16,565 type: i16,
515 l_whence: i16,566 whence: i16,
516 l_start: off_t,567 start: off_t,
517 l_len: off_t,568 len: off_t,
518 l_pid: pid_t,569 pid: pid_t,
519};570};
520571
521pub const msghdr = extern struct {572pub const msghdr = extern struct {
522 msg_name: ?*sockaddr,573 name: ?*sockaddr,
523 msg_namelen: socklen_t,574 namelen: socklen_t,
524 msg_iov: [*]iovec,575 iov: [*]iovec,
525 msg_iovlen: i32,576 iovlen: i32,
526 msg_control: ?*c_void,577 control: ?*c_void,
527 msg_controllen: socklen_t,578 controllen: socklen_t,
528 msg_flags: i32,579 flags: i32,
529};580};
530581
531pub const msghdr_const = extern struct {582pub const msghdr_const = extern struct {
532 msg_name: ?*const sockaddr,583 name: ?*const sockaddr,
533 msg_namelen: socklen_t,584 namelen: socklen_t,
534 msg_iov: [*]iovec_const,585 iov: [*]iovec_const,
535 msg_iovlen: i32,586 iovlen: i32,
536 msg_control: ?*c_void,587 control: ?*c_void,
537 msg_controllen: socklen_t,588 controllen: socklen_t,
538 msg_flags: i32,589 flags: i32,
539};590};
540591
541pub const blksize_t = i32;592pub const blksize_t = i32;
...@@ -604,25 +655,27 @@ pub const mcontext_t = extern struct {...@@ -604,25 +655,27 @@ pub const mcontext_t = extern struct {
604 cr2: usize,655 cr2: usize,
605};656};
606657
607pub const REG_GS = 0;658pub const REG = struct {
608pub const REG_FS = 1;659 pub const GS = 0;
609pub const REG_ES = 2;660 pub const FS = 1;
610pub const REG_DS = 3;661 pub const ES = 2;
611pub const REG_EDI = 4;662 pub const DS = 3;
612pub const REG_ESI = 5;663 pub const EDI = 4;
613pub const REG_EBP = 6;664 pub const ESI = 5;
614pub const REG_ESP = 7;665 pub const EBP = 6;
615pub const REG_EBX = 8;666 pub const ESP = 7;
616pub const REG_EDX = 9;667 pub const EBX = 8;
617pub const REG_ECX = 10;668 pub const EDX = 9;
618pub const REG_EAX = 11;669 pub const ECX = 10;
619pub const REG_TRAPNO = 12;670 pub const EAX = 11;
620pub const REG_ERR = 13;671 pub const TRAPNO = 12;
621pub const REG_EIP = 14;672 pub const ERR = 13;
622pub const REG_CS = 15;673 pub const EIP = 14;
623pub const REG_EFL = 16;674 pub const CS = 15;
624pub const REG_UESP = 17;675 pub const EFL = 16;
625pub const REG_SS = 18;676 pub const UESP = 17;
677 pub const SS = 18;
678};
626679
627pub const ucontext_t = extern struct {680pub const ucontext_t = extern struct {
628 flags: usize,681 flags: usize,
...@@ -647,24 +700,26 @@ pub const user_desc = packed struct {...@@ -647,24 +700,26 @@ pub const user_desc = packed struct {
647 useable: u1,700 useable: u1,
648};701};
649702
650// socketcall() call numbers703/// socketcall() call numbers
651pub const SC_socket = 1;704pub const SC = struct {
652pub const SC_bind = 2;705 pub const socket = 1;
653pub const SC_connect = 3;706 pub const bind = 2;
654pub const SC_listen = 4;707 pub const connect = 3;
655pub const SC_accept = 5;708 pub const listen = 4;
656pub const SC_getsockname = 6;709 pub const accept = 5;
657pub const SC_getpeername = 7;710 pub const getsockname = 6;
658pub const SC_socketpair = 8;711 pub const getpeername = 7;
659pub const SC_send = 9;712 pub const socketpair = 8;
660pub const SC_recv = 10;713 pub const send = 9;
661pub const SC_sendto = 11;714 pub const recv = 10;
662pub const SC_recvfrom = 12;715 pub const sendto = 11;
663pub const SC_shutdown = 13;716 pub const recvfrom = 12;
664pub const SC_setsockopt = 14;717 pub const shutdown = 13;
665pub const SC_getsockopt = 15;718 pub const setsockopt = 14;
666pub const SC_sendmsg = 16;719 pub const getsockopt = 15;
667pub const SC_recvmsg = 17;720 pub const sendmsg = 16;
668pub const SC_accept4 = 18;721 pub const recvmsg = 17;
669pub const SC_recvmmsg = 19;722 pub const accept4 = 18;
670pub const SC_sendmmsg = 20;723 pub const recvmmsg = 19;
724 pub const sendmmsg = 20;
725};
lib/std/os/bits/linux/netlink.zig deleted-498
...@@ -1,498 +0,0 @@
1usingnamespace @import("../linux.zig");
2
3/// Routing/device hook
4pub const NETLINK_ROUTE = 0;
5
6/// Unused number
7pub const NETLINK_UNUSED = 1;
8
9/// Reserved for user mode socket protocols
10pub const NETLINK_USERSOCK = 2;
11
12/// Unused number, formerly ip_queue
13pub const NETLINK_FIREWALL = 3;
14
15/// socket monitoring
16pub const NETLINK_SOCK_DIAG = 4;
17
18/// netfilter/iptables ULOG
19pub const NETLINK_NFLOG = 5;
20
21/// ipsec
22pub const NETLINK_XFRM = 6;
23
24/// SELinux event notifications
25pub const NETLINK_SELINUX = 7;
26
27/// Open-iSCSI
28pub const NETLINK_ISCSI = 8;
29
30/// auditing
31pub const NETLINK_AUDIT = 9;
32
33pub const NETLINK_FIB_LOOKUP = 10;
34
35pub const NETLINK_CONNECTOR = 11;
36
37/// netfilter subsystem
38pub const NETLINK_NETFILTER = 12;
39
40pub const NETLINK_IP6_FW = 13;
41
42/// DECnet routing messages
43pub const NETLINK_DNRTMSG = 14;
44
45/// Kernel messages to userspace
46pub const NETLINK_KOBJECT_UEVENT = 15;
47
48pub const NETLINK_GENERIC = 16;
49
50// leave room for NETLINK_DM (DM Events)
51
52/// SCSI Transports
53pub const NETLINK_SCSITRANSPORT = 18;
54
55pub const NETLINK_ECRYPTFS = 19;
56
57pub const NETLINK_RDMA = 20;
58
59/// Crypto layer
60pub const NETLINK_CRYPTO = 21;
61
62/// SMC monitoring
63pub const NETLINK_SMC = 22;
64
65// Flags values
66
67/// It is request message.
68pub const NLM_F_REQUEST = 0x01;
69
70/// Multipart message, terminated by NLMSG_DONE
71pub const NLM_F_MULTI = 0x02;
72
73/// Reply with ack, with zero or error code
74pub const NLM_F_ACK = 0x04;
75
76/// Echo this request
77pub const NLM_F_ECHO = 0x08;
78
79/// Dump was inconsistent due to sequence change
80pub const NLM_F_DUMP_INTR = 0x10;
81
82/// Dump was filtered as requested
83pub const NLM_F_DUMP_FILTERED = 0x20;
84
85// Modifiers to GET request
86
87/// specify tree root
88pub const NLM_F_ROOT = 0x100;
89
90/// return all matching
91pub const NLM_F_MATCH = 0x200;
92
93/// atomic GET
94pub const NLM_F_ATOMIC = 0x400;
95pub const NLM_F_DUMP = NLM_F_ROOT | NLM_F_MATCH;
96
97// Modifiers to NEW request
98
99/// Override existing
100pub const NLM_F_REPLACE = 0x100;
101
102/// Do not touch, if it exists
103pub const NLM_F_EXCL = 0x200;
104
105/// Create, if it does not exist
106pub const NLM_F_CREATE = 0x400;
107
108/// Add to end of list
109pub const NLM_F_APPEND = 0x800;
110
111// Modifiers to DELETE request
112
113/// Do not delete recursively
114pub const NLM_F_NONREC = 0x100;
115
116// Flags for ACK message
117
118/// request was capped
119pub const NLM_F_CAPPED = 0x100;
120
121/// extended ACK TVLs were included
122pub const NLM_F_ACK_TLVS = 0x200;
123
124pub const NetlinkMessageType = enum(u16) {
125 /// < 0x10: reserved control messages
126 pub const MIN_TYPE = 0x10;
127
128 /// Nothing.
129 NOOP = 0x1,
130
131 /// Error
132 ERROR = 0x2,
133
134 /// End of a dump
135 DONE = 0x3,
136
137 /// Data lost
138 OVERRUN = 0x4,
139
140 // rtlink types
141
142 RTM_NEWLINK = 16,
143 RTM_DELLINK,
144 RTM_GETLINK,
145 RTM_SETLINK,
146
147 RTM_NEWADDR = 20,
148 RTM_DELADDR,
149 RTM_GETADDR,
150
151 RTM_NEWROUTE = 24,
152 RTM_DELROUTE,
153 RTM_GETROUTE,
154
155 RTM_NEWNEIGH = 28,
156 RTM_DELNEIGH,
157 RTM_GETNEIGH,
158
159 RTM_NEWRULE = 32,
160 RTM_DELRULE,
161 RTM_GETRULE,
162
163 RTM_NEWQDISC = 36,
164 RTM_DELQDISC,
165 RTM_GETQDISC,
166
167 RTM_NEWTCLASS = 40,
168 RTM_DELTCLASS,
169 RTM_GETTCLASS,
170
171 RTM_NEWTFILTER = 44,
172 RTM_DELTFILTER,
173 RTM_GETTFILTER,
174
175 RTM_NEWACTION = 48,
176 RTM_DELACTION,
177 RTM_GETACTION,
178
179 RTM_NEWPREFIX = 52,
180
181 RTM_GETMULTICAST = 58,
182
183 RTM_GETANYCAST = 62,
184
185 RTM_NEWNEIGHTBL = 64,
186 RTM_GETNEIGHTBL = 66,
187 RTM_SETNEIGHTBL,
188
189 RTM_NEWNDUSEROPT = 68,
190
191 RTM_NEWADDRLABEL = 72,
192 RTM_DELADDRLABEL,
193 RTM_GETADDRLABEL,
194
195 RTM_GETDCB = 78,
196 RTM_SETDCB,
197
198 RTM_NEWNETCONF = 80,
199 RTM_DELNETCONF,
200 RTM_GETNETCONF = 82,
201
202 RTM_NEWMDB = 84,
203 RTM_DELMDB = 85,
204 RTM_GETMDB = 86,
205
206 RTM_NEWNSID = 88,
207 RTM_DELNSID = 89,
208 RTM_GETNSID = 90,
209
210 RTM_NEWSTATS = 92,
211 RTM_GETSTATS = 94,
212
213 RTM_NEWCACHEREPORT = 96,
214
215 RTM_NEWCHAIN = 100,
216 RTM_DELCHAIN,
217 RTM_GETCHAIN,
218
219 RTM_NEWNEXTHOP = 104,
220 RTM_DELNEXTHOP,
221 RTM_GETNEXTHOP,
222
223 _,
224};
225
226/// Netlink socket address
227pub const sockaddr_nl = extern struct {
228 family: sa_family_t = AF_NETLINK,
229 __pad1: c_ushort = 0,
230
231 /// port ID
232 pid: u32,
233
234 /// multicast groups mask
235 groups: u32,
236};
237
238/// Netlink message header
239/// Specified in RFC 3549 Section 2.3.2
240pub const nlmsghdr = extern struct {
241 /// Length of message including header
242 len: u32,
243
244 /// Message content
245 @"type": NetlinkMessageType,
246
247 /// Additional flags
248 flags: u16,
249
250 /// Sequence number
251 seq: u32,
252
253 /// Sending process port ID
254 pid: u32,
255};
256
257pub const ifinfomsg = extern struct {
258 family: u8,
259 __pad1: u8 = 0,
260
261 /// ARPHRD_*
262 @"type": c_ushort,
263
264 /// Link index
265 index: c_int,
266
267 /// IFF_* flags
268 flags: c_uint,
269
270 /// IFF_* change mask
271 change: c_uint,
272};
273
274pub const rtattr = extern struct {
275 /// Length of option
276 len: c_ushort,
277
278 /// Type of option
279 @"type": IFLA,
280
281 pub const ALIGNTO = 4;
282};
283
284pub const IFLA = enum(c_ushort) {
285 UNSPEC,
286 ADDRESS,
287 BROADCAST,
288 IFNAME,
289 MTU,
290 LINK,
291 QDISC,
292 STATS,
293 COST,
294 PRIORITY,
295 MASTER,
296
297 /// Wireless Extension event
298 WIRELESS,
299
300 /// Protocol specific information for a link
301 PROTINFO,
302
303 TXQLEN,
304 MAP,
305 WEIGHT,
306 OPERSTATE,
307 LINKMODE,
308 LINKINFO,
309 NET_NS_PID,
310 IFALIAS,
311
312 /// Number of VFs if device is SR-IOV PF
313 NUM_VF,
314
315 VFINFO_LIST,
316 STATS64,
317 VF_PORTS,
318 PORT_SELF,
319 AF_SPEC,
320
321 /// Group the device belongs to
322 GROUP,
323
324 NET_NS_FD,
325
326 /// Extended info mask, VFs, etc
327 EXT_MASK,
328
329 /// Promiscuity count: > 0 means acts PROMISC
330 PROMISCUITY,
331
332 NUM_TX_QUEUES,
333 NUM_RX_QUEUES,
334 CARRIER,
335 PHYS_PORT_ID,
336 CARRIER_CHANGES,
337 PHYS_SWITCH_ID,
338 LINK_NETNSID,
339 PHYS_PORT_NAME,
340 PROTO_DOWN,
341 GSO_MAX_SEGS,
342 GSO_MAX_SIZE,
343 PAD,
344 XDP,
345 EVENT,
346
347 NEW_NETNSID,
348 IF_NETNSID,
349
350 CARRIER_UP_COUNT,
351 CARRIER_DOWN_COUNT,
352 NEW_IFINDEX,
353 MIN_MTU,
354 MAX_MTU,
355
356 _,
357
358 pub const TARGET_NETNSID: IFLA = .IF_NETNSID;
359};
360
361pub const rtnl_link_ifmap = extern struct {
362 mem_start: u64,
363 mem_end: u64,
364 base_addr: u64,
365 irq: u16,
366 dma: u8,
367 port: u8,
368};
369
370pub const rtnl_link_stats = extern struct {
371 /// total packets received
372 rx_packets: u32,
373
374 /// total packets transmitted
375 tx_packets: u32,
376
377 /// total bytes received
378 rx_bytes: u32,
379
380 /// total bytes transmitted
381 tx_bytes: u32,
382
383 /// bad packets received
384 rx_errors: u32,
385
386 /// packet transmit problems
387 tx_errors: u32,
388
389 /// no space in linux buffers
390 rx_dropped: u32,
391
392 /// no space available in linux
393 tx_dropped: u32,
394
395 /// multicast packets received
396 multicast: u32,
397
398 collisions: u32,
399
400 // detailed rx_errors
401
402 rx_length_errors: u32,
403
404 /// receiver ring buff overflow
405 rx_over_errors: u32,
406
407 /// recved pkt with crc error
408 rx_crc_errors: u32,
409
410 /// recv'd frame alignment error
411 rx_frame_errors: u32,
412
413 /// recv'r fifo overrun
414 rx_fifo_errors: u32,
415
416 /// receiver missed packet
417 rx_missed_errors: u32,
418
419 // detailed tx_errors
420 tx_aborted_errors: u32,
421 tx_carrier_errors: u32,
422 tx_fifo_errors: u32,
423 tx_heartbeat_errors: u32,
424 tx_window_errors: u32,
425
426 // for cslip etc
427
428 rx_compressed: u32,
429 tx_compressed: u32,
430
431 /// dropped, no handler found
432 rx_nohandler: u32,
433};
434
435pub const rtnl_link_stats64 = extern struct {
436 /// total packets received
437 rx_packets: u64,
438
439 /// total packets transmitted
440 tx_packets: u64,
441
442 /// total bytes received
443 rx_bytes: u64,
444
445 /// total bytes transmitted
446 tx_bytes: u64,
447
448 /// bad packets received
449 rx_errors: u64,
450
451 /// packet transmit problems
452 tx_errors: u64,
453
454 /// no space in linux buffers
455 rx_dropped: u64,
456
457 /// no space available in linux
458 tx_dropped: u64,
459
460 /// multicast packets received
461 multicast: u64,
462
463 collisions: u64,
464
465 // detailed rx_errors
466
467 rx_length_errors: u64,
468
469 /// receiver ring buff overflow
470 rx_over_errors: u64,
471
472 /// recved pkt with crc error
473 rx_crc_errors: u64,
474
475 /// recv'd frame alignment error
476 rx_frame_errors: u64,
477
478 /// recv'r fifo overrun
479 rx_fifo_errors: u64,
480
481 /// receiver missed packet
482 rx_missed_errors: u64,
483
484 // detailed tx_errors
485 tx_aborted_errors: u64,
486 tx_carrier_errors: u64,
487 tx_fifo_errors: u64,
488 tx_heartbeat_errors: u64,
489 tx_window_errors: u64,
490
491 // for cslip etc
492
493 rx_compressed: u64,
494 tx_compressed: u64,
495
496 /// dropped, no handler found
497 rx_nohandler: u64,
498};
lib/std/os/bits/linux/prctl.zig deleted-234
...@@ -1,234 +0,0 @@
1pub const PR = enum(i32) {
2 SET_PDEATHSIG = 1,
3 GET_PDEATHSIG = 2,
4
5 GET_DUMPABLE = 3,
6 SET_DUMPABLE = 4,
7
8 GET_UNALIGN = 5,
9 SET_UNALIGN = 6,
10
11 GET_KEEPCAPS = 7,
12 SET_KEEPCAPS = 8,
13
14 GET_FPEMU = 9,
15 SET_FPEMU = 10,
16
17 GET_FPEXC = 11,
18 SET_FPEXC = 12,
19
20 GET_TIMING = 13,
21 SET_TIMING = 14,
22
23 SET_NAME = 15,
24 GET_NAME = 16,
25
26 GET_ENDIAN = 19,
27 SET_ENDIAN = 20,
28
29 GET_SECCOMP = 21,
30 SET_SECCOMP = 22,
31
32 CAPBSET_READ = 23,
33 CAPBSET_DROP = 24,
34
35 GET_TSC = 25,
36 SET_TSC = 26,
37
38 GET_SECUREBITS = 27,
39 SET_SECUREBITS = 28,
40
41 SET_TIMERSLACK = 29,
42 GET_TIMERSLACK = 30,
43
44 TASK_PERF_EVENTS_DISABLE = 31,
45 TASK_PERF_EVENTS_ENABLE = 32,
46
47 MCE_KILL = 33,
48
49 MCE_KILL_GET = 34,
50
51 SET_MM = 35,
52
53 SET_PTRACER = 0x59616d61,
54
55 SET_CHILD_SUBREAPER = 36,
56 GET_CHILD_SUBREAPER = 37,
57
58 SET_NO_NEW_PRIVS = 38,
59 GET_NO_NEW_PRIVS = 39,
60
61 GET_TID_ADDRESS = 40,
62
63 SET_THP_DISABLE = 41,
64 GET_THP_DISABLE = 42,
65
66 MPX_ENABLE_MANAGEMENT = 43,
67 MPX_DISABLE_MANAGEMENT = 44,
68
69 SET_FP_MODE = 45,
70 GET_FP_MODE = 46,
71
72 CAP_AMBIENT = 47,
73
74 SVE_SET_VL = 50,
75 SVE_GET_VL = 51,
76
77 GET_SPECULATION_CTRL = 52,
78 SET_SPECULATION_CTRL = 53,
79
80 _,
81};
82
83pub const PR_SET_PDEATHSIG = @enumToInt(PR.SET_PDEATHSIG);
84pub const PR_GET_PDEATHSIG = @enumToInt(PR.GET_PDEATHSIG);
85
86pub const PR_GET_DUMPABLE = @enumToInt(PR.GET_DUMPABLE);
87pub const PR_SET_DUMPABLE = @enumToInt(PR.SET_DUMPABLE);
88
89pub const PR_GET_UNALIGN = @enumToInt(PR.GET_UNALIGN);
90pub const PR_SET_UNALIGN = @enumToInt(PR.SET_UNALIGN);
91pub const PR_UNALIGN_NOPRINT = 1;
92pub const PR_UNALIGN_SIGBUS = 2;
93
94pub const PR_GET_KEEPCAPS = @enumToInt(PR.GET_KEEPCAPS);
95pub const PR_SET_KEEPCAPS = @enumToInt(PR.SET_KEEPCAPS);
96
97pub const PR_GET_FPEMU = @enumToInt(PR.GET_FPEMU);
98pub const PR_SET_FPEMU = @enumToInt(PR.SET_FPEMU);
99pub const PR_FPEMU_NOPRINT = 1;
100pub const PR_FPEMU_SIGFPE = 2;
101
102pub const PR_GET_FPEXC = @enumToInt(PR.GET_FPEXC);
103pub const PR_SET_FPEXC = @enumToInt(PR.SET_FPEXC);
104pub const PR_FP_EXC_SW_ENABLE = 0x80;
105pub const PR_FP_EXC_DIV = 0x010000;
106pub const PR_FP_EXC_OVF = 0x020000;
107pub const PR_FP_EXC_UND = 0x040000;
108pub const PR_FP_EXC_RES = 0x080000;
109pub const PR_FP_EXC_INV = 0x100000;
110pub const PR_FP_EXC_DISABLED = 0;
111pub const PR_FP_EXC_NONRECOV = 1;
112pub const PR_FP_EXC_ASYNC = 2;
113pub const PR_FP_EXC_PRECISE = 3;
114
115pub const PR_GET_TIMING = @enumToInt(PR.GET_TIMING);
116pub const PR_SET_TIMING = @enumToInt(PR.SET_TIMING);
117pub const PR_TIMING_STATISTICAL = 0;
118pub const PR_TIMING_TIMESTAMP = 1;
119
120pub const PR_SET_NAME = @enumToInt(PR.SET_NAME);
121pub const PR_GET_NAME = @enumToInt(PR.GET_NAME);
122
123pub const PR_GET_ENDIAN = @enumToInt(PR.GET_ENDIAN);
124pub const PR_SET_ENDIAN = @enumToInt(PR.SET_ENDIAN);
125pub const PR_ENDIAN_BIG = 0;
126pub const PR_ENDIAN_LITTLE = 1;
127pub const PR_ENDIAN_PPC_LITTLE = 2;
128
129pub const PR_GET_SECCOMP = @enumToInt(PR.GET_SECCOMP);
130pub const PR_SET_SECCOMP = @enumToInt(PR.SET_SECCOMP);
131
132pub const PR_CAPBSET_READ = @enumToInt(PR.CAPBSET_READ);
133pub const PR_CAPBSET_DROP = @enumToInt(PR.CAPBSET_DROP);
134
135pub const PR_GET_TSC = @enumToInt(PR.GET_TSC);
136pub const PR_SET_TSC = @enumToInt(PR.SET_TSC);
137pub const PR_TSC_ENABLE = 1;
138pub const PR_TSC_SIGSEGV = 2;
139
140pub const PR_GET_SECUREBITS = @enumToInt(PR.GET_SECUREBITS);
141pub const PR_SET_SECUREBITS = @enumToInt(PR.SET_SECUREBITS);
142
143pub const PR_SET_TIMERSLACK = @enumToInt(PR.SET_TIMERSLACK);
144pub const PR_GET_TIMERSLACK = @enumToInt(PR.GET_TIMERSLACK);
145
146pub const PR_TASK_PERF_EVENTS_DISABLE = @enumToInt(PR.TASK_PERF_EVENTS_DISABLE);
147pub const PR_TASK_PERF_EVENTS_ENABLE = @enumToInt(PR.TASK_PERF_EVENTS_ENABLE);
148
149pub const PR_MCE_KILL = @enumToInt(PR.MCE_KILL);
150pub const PR_MCE_KILL_CLEAR = 0;
151pub const PR_MCE_KILL_SET = 1;
152
153pub const PR_MCE_KILL_LATE = 0;
154pub const PR_MCE_KILL_EARLY = 1;
155pub const PR_MCE_KILL_DEFAULT = 2;
156
157pub const PR_MCE_KILL_GET = @enumToInt(PR.MCE_KILL_GET);
158
159pub const PR_SET_MM = @enumToInt(PR.SET_MM);
160pub const PR_SET_MM_START_CODE = 1;
161pub const PR_SET_MM_END_CODE = 2;
162pub const PR_SET_MM_START_DATA = 3;
163pub const PR_SET_MM_END_DATA = 4;
164pub const PR_SET_MM_START_STACK = 5;
165pub const PR_SET_MM_START_BRK = 6;
166pub const PR_SET_MM_BRK = 7;
167pub const PR_SET_MM_ARG_START = 8;
168pub const PR_SET_MM_ARG_END = 9;
169pub const PR_SET_MM_ENV_START = 10;
170pub const PR_SET_MM_ENV_END = 11;
171pub const PR_SET_MM_AUXV = 12;
172pub const PR_SET_MM_EXE_FILE = 13;
173pub const PR_SET_MM_MAP = 14;
174pub const PR_SET_MM_MAP_SIZE = 15;
175
176pub const prctl_mm_map = extern struct {
177 start_code: u64,
178 end_code: u64,
179 start_data: u64,
180 end_data: u64,
181 start_brk: u64,
182 brk: u64,
183 start_stack: u64,
184 arg_start: u64,
185 arg_end: u64,
186 env_start: u64,
187 env_end: u64,
188 auxv: *u64,
189 auxv_size: u32,
190 exe_fd: u32,
191};
192
193pub const PR_SET_PTRACER = @enumToInt(PR.SET_PTRACER);
194pub const PR_SET_PTRACER_ANY = std.math.maxInt(c_ulong);
195
196pub const PR_SET_CHILD_SUBREAPER = @enumToInt(PR.SET_CHILD_SUBREAPER);
197pub const PR_GET_CHILD_SUBREAPER = @enumToInt(PR.GET_CHILD_SUBREAPER);
198
199pub const PR_SET_NO_NEW_PRIVS = @enumToInt(PR.SET_NO_NEW_PRIVS);
200pub const PR_GET_NO_NEW_PRIVS = @enumToInt(PR.GET_NO_NEW_PRIVS);
201
202pub const PR_GET_TID_ADDRESS = @enumToInt(PR.GET_TID_ADDRESS);
203
204pub const PR_SET_THP_DISABLE = @enumToInt(PR.SET_THP_DISABLE);
205pub const PR_GET_THP_DISABLE = @enumToInt(PR.GET_THP_DISABLE);
206
207pub const PR_MPX_ENABLE_MANAGEMENT = @enumToInt(PR.MPX_ENABLE_MANAGEMENT);
208pub const PR_MPX_DISABLE_MANAGEMENT = @enumToInt(PR.MPX_DISABLE_MANAGEMENT);
209
210pub const PR_SET_FP_MODE = @enumToInt(PR.SET_FP_MODE);
211pub const PR_GET_FP_MODE = @enumToInt(PR.GET_FP_MODE);
212pub const PR_FP_MODE_FR = 1 << 0;
213pub const PR_FP_MODE_FRE = 1 << 1;
214
215pub const PR_CAP_AMBIENT = @enumToInt(PR.CAP_AMBIENT);
216pub const PR_CAP_AMBIENT_IS_SET = 1;
217pub const PR_CAP_AMBIENT_RAISE = 2;
218pub const PR_CAP_AMBIENT_LOWER = 3;
219pub const PR_CAP_AMBIENT_CLEAR_ALL = 4;
220
221pub const PR_SVE_SET_VL = @enumToInt(PR.SVE_SET_VL);
222pub const PR_SVE_SET_VL_ONEXEC = 1 << 18;
223pub const PR_SVE_GET_VL = @enumToInt(PR.SVE_GET_VL);
224pub const PR_SVE_VL_LEN_MASK = 0xffff;
225pub const PR_SVE_VL_INHERIT = 1 << 17;
226
227pub const PR_GET_SPECULATION_CTRL = @enumToInt(PR.GET_SPECULATION_CTRL);
228pub const PR_SET_SPECULATION_CTRL = @enumToInt(PR.SET_SPECULATION_CTRL);
229pub const PR_SPEC_STORE_BYPASS = 0;
230pub const PR_SPEC_NOT_AFFECTED = 0;
231pub const PR_SPEC_PRCTL = 1 << 0;
232pub const PR_SPEC_ENABLE = 1 << 1;
233pub const PR_SPEC_DISABLE = 1 << 2;
234pub const PR_SPEC_FORCE_DISABLE = 1 << 3;
lib/std/os/bits/linux/securebits.zig deleted-35
...@@ -1,35 +0,0 @@
1fn issecure_mask(comptime x: comptime_int) comptime_int {
2 return 1 << x;
3}
4
5pub const SECUREBITS_DEFAULT = 0x00000000;
6
7pub const SECURE_NOROOT = 0;
8pub const SECURE_NOROOT_LOCKED = 1;
9
10pub const SECBIT_NOROOT = issecure_mask(SECURE_NOROOT);
11pub const SECBIT_NOROOT_LOCKED = issecure_mask(SECURE_NOROOT_LOCKED);
12
13pub const SECURE_NO_SETUID_FIXUP = 2;
14pub const SECURE_NO_SETUID_FIXUP_LOCKED = 3;
15
16pub const SECBIT_NO_SETUID_FIXUP = issecure_mask(SECURE_NO_SETUID_FIXUP);
17pub const SECBIT_NO_SETUID_FIXUP_LOCKED = issecure_mask(SECURE_NO_SETUID_FIXUP_LOCKED);
18
19pub const SECURE_KEEP_CAPS = 4;
20pub const SECURE_KEEP_CAPS_LOCKED = 5;
21
22pub const SECBIT_KEEP_CAPS = issecure_mask(SECURE_KEEP_CAPS);
23pub const SECBIT_KEEP_CAPS_LOCKED = issecure_mask(SECURE_KEEP_CAPS_LOCKED);
24
25pub const SECURE_NO_CAP_AMBIENT_RAISE = 6;
26pub const SECURE_NO_CAP_AMBIENT_RAISE_LOCKED = 7;
27
28pub const SECBIT_NO_CAP_AMBIENT_RAISE = issecure_mask(SECURE_NO_CAP_AMBIENT_RAISE);
29pub const SECBIT_NO_CAP_AMBIENT_RAISE_LOCKED = issecure_mask(SECURE_NO_CAP_AMBIENT_RAISE_LOCKED);
30
31pub const SECURE_ALL_BITS = issecure_mask(SECURE_NOROOT) |
32 issecure_mask(SECURE_NO_SETUID_FIXUP) |
33 issecure_mask(SECURE_KEEP_CAPS) |
34 issecure_mask(SECURE_NO_CAP_AMBIENT_RAISE);
35pub const SECURE_ALL_LOCKS = SECURE_ALL_BITS << 1;
lib/std/os/bits/linux/x86_64.zig deleted-638
...@@ -1,638 +0,0 @@
1// x86-64-specific declarations that are intended to be imported into the POSIX namespace.
2const std = @import("../../../std.zig");
3const pid_t = linux.pid_t;
4const uid_t = linux.uid_t;
5const gid_t = linux.gid_t;
6const clock_t = linux.clock_t;
7const stack_t = linux.stack_t;
8const sigset_t = linux.sigset_t;
9
10const linux = std.os.linux;
11const sockaddr = linux.sockaddr;
12const socklen_t = linux.socklen_t;
13const iovec = linux.iovec;
14const iovec_const = linux.iovec_const;
15
16pub const mode_t = usize;
17pub const time_t = isize;
18
19pub const SYS = enum(usize) {
20 read = 0,
21 write = 1,
22 open = 2,
23 close = 3,
24 stat = 4,
25 fstat = 5,
26 lstat = 6,
27 poll = 7,
28 lseek = 8,
29 mmap = 9,
30 mprotect = 10,
31 munmap = 11,
32 brk = 12,
33 rt_sigaction = 13,
34 rt_sigprocmask = 14,
35 rt_sigreturn = 15,
36 ioctl = 16,
37 pread = 17,
38 pwrite = 18,
39 readv = 19,
40 writev = 20,
41 access = 21,
42 pipe = 22,
43 select = 23,
44 sched_yield = 24,
45 mremap = 25,
46 msync = 26,
47 mincore = 27,
48 madvise = 28,
49 shmget = 29,
50 shmat = 30,
51 shmctl = 31,
52 dup = 32,
53 dup2 = 33,
54 pause = 34,
55 nanosleep = 35,
56 getitimer = 36,
57 alarm = 37,
58 setitimer = 38,
59 getpid = 39,
60 sendfile = 40,
61 socket = 41,
62 connect = 42,
63 accept = 43,
64 sendto = 44,
65 recvfrom = 45,
66 sendmsg = 46,
67 recvmsg = 47,
68 shutdown = 48,
69 bind = 49,
70 listen = 50,
71 getsockname = 51,
72 getpeername = 52,
73 socketpair = 53,
74 setsockopt = 54,
75 getsockopt = 55,
76 clone = 56,
77 fork = 57,
78 vfork = 58,
79 execve = 59,
80 exit = 60,
81 wait4 = 61,
82 kill = 62,
83 uname = 63,
84 semget = 64,
85 semop = 65,
86 semctl = 66,
87 shmdt = 67,
88 msgget = 68,
89 msgsnd = 69,
90 msgrcv = 70,
91 msgctl = 71,
92 fcntl = 72,
93 flock = 73,
94 fsync = 74,
95 fdatasync = 75,
96 truncate = 76,
97 ftruncate = 77,
98 getdents = 78,
99 getcwd = 79,
100 chdir = 80,
101 fchdir = 81,
102 rename = 82,
103 mkdir = 83,
104 rmdir = 84,
105 creat = 85,
106 link = 86,
107 unlink = 87,
108 symlink = 88,
109 readlink = 89,
110 chmod = 90,
111 fchmod = 91,
112 chown = 92,
113 fchown = 93,
114 lchown = 94,
115 umask = 95,
116 gettimeofday = 96,
117 getrlimit = 97,
118 getrusage = 98,
119 sysinfo = 99,
120 times = 100,
121 ptrace = 101,
122 getuid = 102,
123 syslog = 103,
124 getgid = 104,
125 setuid = 105,
126 setgid = 106,
127 geteuid = 107,
128 getegid = 108,
129 setpgid = 109,
130 getppid = 110,
131 getpgrp = 111,
132 setsid = 112,
133 setreuid = 113,
134 setregid = 114,
135 getgroups = 115,
136 setgroups = 116,
137 setresuid = 117,
138 getresuid = 118,
139 setresgid = 119,
140 getresgid = 120,
141 getpgid = 121,
142 setfsuid = 122,
143 setfsgid = 123,
144 getsid = 124,
145 capget = 125,
146 capset = 126,
147 rt_sigpending = 127,
148 rt_sigtimedwait = 128,
149 rt_sigqueueinfo = 129,
150 rt_sigsuspend = 130,
151 sigaltstack = 131,
152 utime = 132,
153 mknod = 133,
154 uselib = 134,
155 personality = 135,
156 ustat = 136,
157 statfs = 137,
158 fstatfs = 138,
159 sysfs = 139,
160 getpriority = 140,
161 setpriority = 141,
162 sched_setparam = 142,
163 sched_getparam = 143,
164 sched_setscheduler = 144,
165 sched_getscheduler = 145,
166 sched_get_priority_max = 146,
167 sched_get_priority_min = 147,
168 sched_rr_get_interval = 148,
169 mlock = 149,
170 munlock = 150,
171 mlockall = 151,
172 munlockall = 152,
173 vhangup = 153,
174 modify_ldt = 154,
175 pivot_root = 155,
176 _sysctl = 156,
177 prctl = 157,
178 arch_prctl = 158,
179 adjtimex = 159,
180 setrlimit = 160,
181 chroot = 161,
182 sync = 162,
183 acct = 163,
184 settimeofday = 164,
185 mount = 165,
186 umount2 = 166,
187 swapon = 167,
188 swapoff = 168,
189 reboot = 169,
190 sethostname = 170,
191 setdomainname = 171,
192 iopl = 172,
193 ioperm = 173,
194 create_module = 174,
195 init_module = 175,
196 delete_module = 176,
197 get_kernel_syms = 177,
198 query_module = 178,
199 quotactl = 179,
200 nfsservctl = 180,
201 getpmsg = 181,
202 putpmsg = 182,
203 afs_syscall = 183,
204 tuxcall = 184,
205 security = 185,
206 gettid = 186,
207 readahead = 187,
208 setxattr = 188,
209 lsetxattr = 189,
210 fsetxattr = 190,
211 getxattr = 191,
212 lgetxattr = 192,
213 fgetxattr = 193,
214 listxattr = 194,
215 llistxattr = 195,
216 flistxattr = 196,
217 removexattr = 197,
218 lremovexattr = 198,
219 fremovexattr = 199,
220 tkill = 200,
221 time = 201,
222 futex = 202,
223 sched_setaffinity = 203,
224 sched_getaffinity = 204,
225 set_thread_area = 205,
226 io_setup = 206,
227 io_destroy = 207,
228 io_getevents = 208,
229 io_submit = 209,
230 io_cancel = 210,
231 get_thread_area = 211,
232 lookup_dcookie = 212,
233 epoll_create = 213,
234 epoll_ctl_old = 214,
235 epoll_wait_old = 215,
236 remap_file_pages = 216,
237 getdents64 = 217,
238 set_tid_address = 218,
239 restart_syscall = 219,
240 semtimedop = 220,
241 fadvise64 = 221,
242 timer_create = 222,
243 timer_settime = 223,
244 timer_gettime = 224,
245 timer_getoverrun = 225,
246 timer_delete = 226,
247 clock_settime = 227,
248 clock_gettime = 228,
249 clock_getres = 229,
250 clock_nanosleep = 230,
251 exit_group = 231,
252 epoll_wait = 232,
253 epoll_ctl = 233,
254 tgkill = 234,
255 utimes = 235,
256 vserver = 236,
257 mbind = 237,
258 set_mempolicy = 238,
259 get_mempolicy = 239,
260 mq_open = 240,
261 mq_unlink = 241,
262 mq_timedsend = 242,
263 mq_timedreceive = 243,
264 mq_notify = 244,
265 mq_getsetattr = 245,
266 kexec_load = 246,
267 waitid = 247,
268 add_key = 248,
269 request_key = 249,
270 keyctl = 250,
271 ioprio_set = 251,
272 ioprio_get = 252,
273 inotify_init = 253,
274 inotify_add_watch = 254,
275 inotify_rm_watch = 255,
276 migrate_pages = 256,
277 openat = 257,
278 mkdirat = 258,
279 mknodat = 259,
280 fchownat = 260,
281 futimesat = 261,
282 fstatat = 262,
283 unlinkat = 263,
284 renameat = 264,
285 linkat = 265,
286 symlinkat = 266,
287 readlinkat = 267,
288 fchmodat = 268,
289 faccessat = 269,
290 pselect6 = 270,
291 ppoll = 271,
292 unshare = 272,
293 set_robust_list = 273,
294 get_robust_list = 274,
295 splice = 275,
296 tee = 276,
297 sync_file_range = 277,
298 vmsplice = 278,
299 move_pages = 279,
300 utimensat = 280,
301 epoll_pwait = 281,
302 signalfd = 282,
303 timerfd_create = 283,
304 eventfd = 284,
305 fallocate = 285,
306 timerfd_settime = 286,
307 timerfd_gettime = 287,
308 accept4 = 288,
309 signalfd4 = 289,
310 eventfd2 = 290,
311 epoll_create1 = 291,
312 dup3 = 292,
313 pipe2 = 293,
314 inotify_init1 = 294,
315 preadv = 295,
316 pwritev = 296,
317 rt_tgsigqueueinfo = 297,
318 perf_event_open = 298,
319 recvmmsg = 299,
320 fanotify_init = 300,
321 fanotify_mark = 301,
322 prlimit64 = 302,
323 name_to_handle_at = 303,
324 open_by_handle_at = 304,
325 clock_adjtime = 305,
326 syncfs = 306,
327 sendmmsg = 307,
328 setns = 308,
329 getcpu = 309,
330 process_vm_readv = 310,
331 process_vm_writev = 311,
332 kcmp = 312,
333 finit_module = 313,
334 sched_setattr = 314,
335 sched_getattr = 315,
336 renameat2 = 316,
337 seccomp = 317,
338 getrandom = 318,
339 memfd_create = 319,
340 kexec_file_load = 320,
341 bpf = 321,
342 execveat = 322,
343 userfaultfd = 323,
344 membarrier = 324,
345 mlock2 = 325,
346 copy_file_range = 326,
347 preadv2 = 327,
348 pwritev2 = 328,
349 pkey_mprotect = 329,
350 pkey_alloc = 330,
351 pkey_free = 331,
352 statx = 332,
353 io_pgetevents = 333,
354 rseq = 334,
355 pidfd_send_signal = 424,
356 io_uring_setup = 425,
357 io_uring_enter = 426,
358 io_uring_register = 427,
359 open_tree = 428,
360 move_mount = 429,
361 fsopen = 430,
362 fsconfig = 431,
363 fsmount = 432,
364 fspick = 433,
365 pidfd_open = 434,
366 clone3 = 435,
367 close_range = 436,
368 openat2 = 437,
369 pidfd_getfd = 438,
370 faccessat2 = 439,
371 process_madvise = 440,
372 epoll_pwait2 = 441,
373
374 _,
375};
376
377pub const O_CREAT = 0o100;
378pub const O_EXCL = 0o200;
379pub const O_NOCTTY = 0o400;
380pub const O_TRUNC = 0o1000;
381pub const O_APPEND = 0o2000;
382pub const O_NONBLOCK = 0o4000;
383pub const O_DSYNC = 0o10000;
384pub const O_SYNC = 0o4010000;
385pub const O_RSYNC = 0o4010000;
386pub const O_DIRECTORY = 0o200000;
387pub const O_NOFOLLOW = 0o400000;
388pub const O_CLOEXEC = 0o2000000;
389
390pub const O_ASYNC = 0o20000;
391pub const O_DIRECT = 0o40000;
392pub const O_LARGEFILE = 0;
393pub const O_NOATIME = 0o1000000;
394pub const O_PATH = 0o10000000;
395pub const O_TMPFILE = 0o20200000;
396pub const O_NDELAY = O_NONBLOCK;
397
398pub const F_DUPFD = 0;
399pub const F_GETFD = 1;
400pub const F_SETFD = 2;
401pub const F_GETFL = 3;
402pub const F_SETFL = 4;
403
404pub const F_SETOWN = 8;
405pub const F_GETOWN = 9;
406pub const F_SETSIG = 10;
407pub const F_GETSIG = 11;
408
409pub const F_GETLK = 5;
410pub const F_SETLK = 6;
411pub const F_SETLKW = 7;
412
413pub const F_SETOWN_EX = 15;
414pub const F_GETOWN_EX = 16;
415
416pub const F_GETOWNER_UIDS = 17;
417
418/// only give out 32bit addresses
419pub const MAP_32BIT = 0x40;
420
421/// stack-like segment
422pub const MAP_GROWSDOWN = 0x0100;
423
424/// ETXTBSY
425pub const MAP_DENYWRITE = 0x0800;
426
427/// mark it as an executable
428pub const MAP_EXECUTABLE = 0x1000;
429
430/// pages are locked
431pub const MAP_LOCKED = 0x2000;
432
433/// don't check for reservations
434pub const MAP_NORESERVE = 0x4000;
435
436pub const VDSO_CGT_SYM = "__vdso_clock_gettime";
437pub const VDSO_CGT_VER = "LINUX_2.6";
438pub const VDSO_GETCPU_SYM = "__vdso_getcpu";
439pub const VDSO_GETCPU_VER = "LINUX_2.6";
440
441pub const ARCH_SET_GS = 0x1001;
442pub const ARCH_SET_FS = 0x1002;
443pub const ARCH_GET_FS = 0x1003;
444pub const ARCH_GET_GS = 0x1004;
445
446pub const REG_R8 = 0;
447pub const REG_R9 = 1;
448pub const REG_R10 = 2;
449pub const REG_R11 = 3;
450pub const REG_R12 = 4;
451pub const REG_R13 = 5;
452pub const REG_R14 = 6;
453pub const REG_R15 = 7;
454pub const REG_RDI = 8;
455pub const REG_RSI = 9;
456pub const REG_RBP = 10;
457pub const REG_RBX = 11;
458pub const REG_RDX = 12;
459pub const REG_RAX = 13;
460pub const REG_RCX = 14;
461pub const REG_RSP = 15;
462pub const REG_RIP = 16;
463pub const REG_EFL = 17;
464pub const REG_CSGSFS = 18;
465pub const REG_ERR = 19;
466pub const REG_TRAPNO = 20;
467pub const REG_OLDMASK = 21;
468pub const REG_CR2 = 22;
469
470pub const LOCK_SH = 1;
471pub const LOCK_EX = 2;
472pub const LOCK_UN = 8;
473pub const LOCK_NB = 4;
474
475pub const F_RDLCK = 0;
476pub const F_WRLCK = 1;
477pub const F_UNLCK = 2;
478
479pub const Flock = extern struct {
480 l_type: i16,
481 l_whence: i16,
482 l_start: off_t,
483 l_len: off_t,
484 l_pid: pid_t,
485};
486
487pub const msghdr = extern struct {
488 msg_name: ?*sockaddr,
489 msg_namelen: socklen_t,
490 msg_iov: [*]iovec,
491 msg_iovlen: i32,
492 __pad1: i32 = 0,
493 msg_control: ?*c_void,
494 msg_controllen: socklen_t,
495 __pad2: socklen_t = 0,
496 msg_flags: i32,
497};
498
499pub const msghdr_const = extern struct {
500 msg_name: ?*const sockaddr,
501 msg_namelen: socklen_t,
502 msg_iov: [*]iovec_const,
503 msg_iovlen: i32,
504 __pad1: i32 = 0,
505 msg_control: ?*c_void,
506 msg_controllen: socklen_t,
507 __pad2: socklen_t = 0,
508 msg_flags: i32,
509};
510
511pub const off_t = i64;
512pub const ino_t = u64;
513pub const dev_t = u64;
514
515// The `stat` definition used by the Linux kernel.
516pub const kernel_stat = extern struct {
517 dev: dev_t,
518 ino: ino_t,
519 nlink: usize,
520
521 mode: u32,
522 uid: uid_t,
523 gid: gid_t,
524 __pad0: u32,
525 rdev: dev_t,
526 size: off_t,
527 blksize: isize,
528 blocks: i64,
529
530 atim: timespec,
531 mtim: timespec,
532 ctim: timespec,
533 __unused: [3]isize,
534
535 pub fn atime(self: @This()) timespec {
536 return self.atim;
537 }
538
539 pub fn mtime(self: @This()) timespec {
540 return self.mtim;
541 }
542
543 pub fn ctime(self: @This()) timespec {
544 return self.ctim;
545 }
546};
547
548// The `stat64` definition used by the libc.
549pub const libc_stat = kernel_stat;
550
551pub const timespec = extern struct {
552 tv_sec: isize,
553 tv_nsec: isize,
554};
555
556pub const timeval = extern struct {
557 tv_sec: isize,
558 tv_usec: isize,
559};
560
561pub const timezone = extern struct {
562 tz_minuteswest: i32,
563 tz_dsttime: i32,
564};
565
566pub const Elf_Symndx = u32;
567
568pub const greg_t = usize;
569pub const gregset_t = [23]greg_t;
570pub const fpstate = extern struct {
571 cwd: u16,
572 swd: u16,
573 ftw: u16,
574 fop: u16,
575 rip: usize,
576 rdp: usize,
577 mxcsr: u32,
578 mxcr_mask: u32,
579 st: [8]extern struct {
580 significand: [4]u16,
581 exponent: u16,
582 padding: [3]u16 = undefined,
583 },
584 xmm: [16]extern struct {
585 element: [4]u32,
586 },
587 padding: [24]u32 = undefined,
588};
589pub const fpregset_t = *fpstate;
590pub const sigcontext = extern struct {
591 r8: usize,
592 r9: usize,
593 r10: usize,
594 r11: usize,
595 r12: usize,
596 r13: usize,
597 r14: usize,
598 r15: usize,
599
600 rdi: usize,
601 rsi: usize,
602 rbp: usize,
603 rbx: usize,
604 rdx: usize,
605 rax: usize,
606 rcx: usize,
607 rsp: usize,
608 rip: usize,
609 eflags: usize,
610
611 cs: u16,
612 gs: u16,
613 fs: u16,
614 pad0: u16 = undefined,
615
616 err: usize,
617 trapno: usize,
618 oldmask: usize,
619 cr2: usize,
620
621 fpstate: *fpstate,
622 reserved1: [8]usize = undefined,
623};
624
625pub const mcontext_t = extern struct {
626 gregs: gregset_t,
627 fpregs: fpregset_t,
628 reserved1: [8]usize = undefined,
629};
630
631pub const ucontext_t = extern struct {
632 flags: usize,
633 link: *ucontext_t,
634 stack: stack_t,
635 mcontext: mcontext_t,
636 sigmask: sigset_t,
637 fpregs_mem: [64]usize,
638};
lib/std/os/bits/linux/xdp.zig deleted-77
...@@ -1,77 +0,0 @@
1usingnamespace @import("../linux.zig");
2
3pub const XDP_SHARED_UMEM = (1 << 0);
4pub const XDP_COPY = (1 << 1);
5pub const XDP_ZEROCOPY = (1 << 2);
6
7pub const XDP_UMEM_UNALIGNED_CHUNK_FLAG = (1 << 0);
8
9pub const sockaddr_xdp = extern struct {
10 family: u16 = AF_XDP,
11 flags: u16,
12 ifindex: u32,
13 queue_id: u32,
14 shared_umem_fd: u32,
15};
16
17pub const XDP_USE_NEED_WAKEUP = (1 << 3);
18
19pub const xdp_ring_offset = extern struct {
20 producer: u64,
21 consumer: u64,
22 desc: u64,
23 flags: u64,
24};
25
26pub const xdp_mmap_offsets = extern struct {
27 rx: xdp_ring_offset,
28 tx: xdp_ring_offset,
29 fr: xdp_ring_offset,
30 cr: xdp_ring_offset,
31};
32
33pub const XDP_MMAP_OFFSETS = 1;
34pub const XDP_RX_RING = 2;
35pub const XDP_TX_RING = 3;
36pub const XDP_UMEM_REG = 4;
37pub const XDP_UMEM_FILL_RING = 5;
38pub const XDP_UMEM_COMPLETION_RING = 6;
39pub const XDP_STATISTICS = 7;
40pub const XDP_OPTIONS = 8;
41
42pub const xdp_umem_reg = extern struct {
43 addr: u64,
44 len: u64,
45 chunk_size: u32,
46 headroom: u32,
47 flags: u32,
48};
49
50pub const xdp_statistics = extern struct {
51 rx_dropped: u64,
52 rx_invalid_descs: u64,
53 tx_invalid_descs: u64,
54 rx_ring_full: u64,
55 rx_fill_ring_empty_descs: u64,
56 tx_ring_empty_descs: u64,
57};
58
59pub const xdp_options = extern struct {
60 flags: u32,
61};
62
63pub const XDP_OPTIONS_ZEROCOPY = (1 << 0);
64
65pub const XDP_PGOFF_RX_RING = 0;
66pub const XDP_PGOFF_TX_RING = 0x80000000;
67pub const XDP_UMEM_PGOFF_FILL_RING = 0x100000000;
68pub const XDP_UMEM_PGOFF_COMPLETION_RING = 0x180000000;
69
70pub const XSK_UNALIGNED_BUF_OFFSET_SHIFT = 48;
71pub const XSK_UNALIGNED_BUF_ADDR_MASK = (1 << XSK_UNALIGNED_BUF_OFFSET_SHIFT) - 1;
72
73pub const xdp_desc = extern struct {
74 addr: u64,
75 len: u32,
76 options: u32,
77};
lib/std/os/bits/netbsd.zig-2
...@@ -2,8 +2,6 @@ const std = @import("../../std.zig");...@@ -2,8 +2,6 @@ const std = @import("../../std.zig");
2const builtin = std.builtin;2const builtin = std.builtin;
3const maxInt = std.math.maxInt;3const maxInt = std.math.maxInt;
44
5pub usingnamespace @import("posix.zig");
6
7pub const blkcnt_t = i64;5pub const blkcnt_t = i64;
8pub const blksize_t = i32;6pub const blksize_t = i32;
9pub const clock_t = u32;7pub const clock_t = u32;
lib/std/os/bits/openbsd.zig-2
...@@ -2,8 +2,6 @@ const std = @import("../../std.zig");...@@ -2,8 +2,6 @@ const std = @import("../../std.zig");
2const builtin = std.builtin;2const builtin = std.builtin;
3const maxInt = std.math.maxInt;3const maxInt = std.math.maxInt;
44
5pub usingnamespace @import("posix.zig");
6
7pub const blkcnt_t = i64;5pub const blkcnt_t = i64;
8pub const blksize_t = i32;6pub const blksize_t = i32;
9pub const clock_t = i64;7pub const clock_t = i64;
lib/std/os/bits/posix.zig deleted-28
...@@ -1,28 +0,0 @@
1pub const iovec = extern struct {
2 iov_base: [*]u8,
3 iov_len: usize,
4};
5
6pub const iovec_const = extern struct {
7 iov_base: [*]const u8,
8 iov_len: usize,
9};
10
11// syslog
12
13/// system is unusable
14pub const LOG_EMERG = 0;
15/// action must be taken immediately
16pub const LOG_ALERT = 1;
17/// critical conditions
18pub const LOG_CRIT = 2;
19/// error conditions
20pub const LOG_ERR = 3;
21/// warning conditions
22pub const LOG_WARNING = 4;
23/// normal but significant condition
24pub const LOG_NOTICE = 5;
25/// informational
26pub const LOG_INFO = 6;
27/// debug-level messages
28pub const LOG_DEBUG = 7;
lib/std/os/bits/wasi.zig+6-5
...@@ -1,6 +1,5 @@...@@ -1,6 +1,5 @@
1// Convenience types and consts used by std.os module1// Convenience types and consts used by std.os module
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const posix = @import("posix.zig");
4pub const iovec = posix.iovec;3pub const iovec = posix.iovec;
5pub const iovec_const = posix.iovec_const;4pub const iovec_const = posix.iovec_const;
65
...@@ -87,10 +86,12 @@ pub const ADVICE_DONTNEED: advice_t = 4;...@@ -87,10 +86,12 @@ pub const ADVICE_DONTNEED: advice_t = 4;
87pub const ADVICE_NOREUSE: advice_t = 5;86pub const ADVICE_NOREUSE: advice_t = 5;
8887
89pub const clockid_t = u32;88pub const clockid_t = u32;
90pub const CLOCK_REALTIME: clockid_t = 0;89pub const CLOCK = struct {
91pub const CLOCK_MONOTONIC: clockid_t = 1;90 pub const REALTIME: clockid_t = 0;
92pub const CLOCK_PROCESS_CPUTIME_ID: clockid_t = 2;91 pub const MONOTONIC: clockid_t = 1;
93pub const CLOCK_THREAD_CPUTIME_ID: clockid_t = 3;92 pub const PROCESS_CPUTIME_ID: clockid_t = 2;
93 pub const THREAD_CPUTIME_ID: clockid_t = 3;
94};
9495
95pub const device_t = u64;96pub const device_t = u64;
9697
lib/std/os/bits/windows.zig-5
...@@ -3,11 +3,6 @@...@@ -3,11 +3,6 @@
3usingnamespace @import("../windows/bits.zig");3usingnamespace @import("../windows/bits.zig");
4const ws2_32 = @import("../windows/ws2_32.zig");4const ws2_32 = @import("../windows/ws2_32.zig");
55
6// TODO: Stop using os.iovec in std.fs et al on Windows in the future
7const posix = @import("posix.zig");
8pub const iovec = posix.iovec;
9pub const iovec_const = posix.iovec_const;
10
11pub const fd_t = HANDLE;6pub const fd_t = HANDLE;
12pub const ino_t = LARGE_INTEGER;7pub const ino_t = LARGE_INTEGER;
13pub const pid_t = HANDLE;8pub const pid_t = HANDLE;
lib/std/os/darwin.zig deleted-3
...@@ -1,3 +0,0 @@
1const std = @import("../std.zig");
2pub usingnamespace std.c;
3pub usingnamespace @import("bits.zig");
lib/std/os/dragonfly.zig deleted-3
...@@ -1,3 +0,0 @@
1const std = @import("../std.zig");
2pub usingnamespace std.c;
3pub usingnamespace @import("bits.zig");
lib/std/os/freebsd.zig deleted-3
...@@ -1,3 +0,0 @@
1const std = @import("../std.zig");
2pub usingnamespace std.c;
3pub usingnamespace @import("bits.zig");
lib/std/os/haiku.zig deleted-3
...@@ -1,3 +0,0 @@
1const std = @import("../std.zig");
2pub usingnamespace std.c;
3pub usingnamespace @import("bits.zig");
lib/std/os/linux.zig+3394-11
...@@ -13,13 +13,22 @@ const vdso = @import("linux/vdso.zig");...@@ -13,13 +13,22 @@ const vdso = @import("linux/vdso.zig");
13const dl = @import("../dynamic_library.zig");13const dl = @import("../dynamic_library.zig");
14const native_arch = std.Target.current.cpu.arch;14const native_arch = std.Target.current.cpu.arch;
15const native_endian = native_arch.endian();15const native_endian = native_arch.endian();
16const is_mips = native_arch.isMIPS();
17const is_ppc = native_arch.isPPC();
18const is_ppc64 = native_arch.isPPC64();
19const is_sparc = native_arch.isSPARC();
1620
17pub usingnamespace switch (native_arch) {21test {
22 if (std.Target.current.os.tag == .linux) {
23 _ = @import("linux/test.zig");
24 }
25}
26
27const arch_bits = switch (native_arch) {
18 .i386 => @import("linux/i386.zig"),28 .i386 => @import("linux/i386.zig"),
19 .x86_64 => @import("linux/x86_64.zig"),29 .x86_64 => @import("linux/x86_64.zig"),
20 .aarch64 => @import("linux/arm64.zig"),30 .aarch64 => @import("linux/arm64.zig"),
21 .arm => @import("linux/arm-eabi.zig"),31 .arm, .thumb => @import("linux/arm-eabi.zig"),
22 .thumb => @import("linux/thumb.zig"),
23 .riscv64 => @import("linux/riscv64.zig"),32 .riscv64 => @import("linux/riscv64.zig"),
24 .sparcv9 => @import("linux/sparc64.zig"),33 .sparcv9 => @import("linux/sparc64.zig"),
25 .mips, .mipsel => @import("linux/mips.zig"),34 .mips, .mipsel => @import("linux/mips.zig"),
...@@ -27,7 +36,48 @@ pub usingnamespace switch (native_arch) {...@@ -27,7 +36,48 @@ pub usingnamespace switch (native_arch) {
27 .powerpc64, .powerpc64le => @import("linux/powerpc64.zig"),36 .powerpc64, .powerpc64le => @import("linux/powerpc64.zig"),
28 else => struct {},37 else => struct {},
29};38};
30pub usingnamespace @import("bits.zig");39pub const syscall0 = arch_bits.syscall0;
40pub const syscall1 = arch_bits.syscall1;
41pub const syscall2 = arch_bits.syscall2;
42pub const syscall3 = arch_bits.syscall3;
43pub const syscall4 = arch_bits.syscall4;
44pub const syscall5 = arch_bits.syscall5;
45pub const syscall6 = arch_bits.syscall6;
46pub const clone = arch_bits.clone;
47pub const restore = arch_bits.restore;
48pub const restore_rt = arch_bits.restore_rt;
49
50pub const ARCH = arch_bits.ARCH;
51pub const Elf_Symndx = arch_bits.Elf_Symndx;
52pub const F = arch_bits.F;
53pub const Flock = arch_bits.Flock;
54pub const LOCK = arch_bits.LOCK;
55pub const MAP = arch_bits.MAP;
56pub const MMAP2_UNIT = arch_bits.MMAP2_UNIT;
57pub const O = arch_bits.O;
58pub const REG = arch_bits.REG;
59pub const SC = arch_bits.SC;
60pub const SYS = arch_bits.SYS;
61pub const VDSO = arch_bits.VDSO;
62pub const blkcnt_t = arch_bits.blkcnt_t;
63pub const blksize_t = arch_bits.blksize_t;
64pub const dev_t = arch_bits.dev_t;
65pub const ino_t = arch_bits.ino_t;
66pub const kernel_stat = arch_bits.kernel_stat;
67pub const libc_stat = arch_bits.libc_stat;
68pub const mcontext_t = arch_bits.mcontext_t;
69pub const mode_t = arch_bits.mode_t;
70pub const msghdr = arch_bits.msghdr;
71pub const msghdr_const = arch_bits.msghdr_const;
72pub const nlink_t = arch_bits.nlink_t;
73pub const off_t = arch_bits.off_t;
74pub const time_t = arch_bits.time_t;
75pub const timespec = arch_bits.timespec;
76pub const timeval = arch_bits.timeval;
77pub const timezone = arch_bits.timezone;
78pub const ucontext_t = arch_bits.ucontext_t;
79pub const user_desc = arch_bits.user_desc;
80
31pub const tls = @import("linux/tls.zig");81pub const tls = @import("linux/tls.zig");
32pub const pie = @import("linux/start_pie.zig");82pub const pie = @import("linux/start_pie.zig");
33pub const BPF = @import("linux/bpf.zig");83pub const BPF = @import("linux/bpf.zig");
...@@ -931,18 +981,18 @@ pub fn sigprocmask(flags: u32, noalias set: ?*const sigset_t, noalias oldset: ?*...@@ -931,18 +981,18 @@ pub fn sigprocmask(flags: u32, noalias set: ?*const sigset_t, noalias oldset: ?*
931981
932pub fn sigaction(sig: u6, noalias act: ?*const Sigaction, noalias oact: ?*Sigaction) usize {982pub fn sigaction(sig: u6, noalias act: ?*const Sigaction, noalias oact: ?*Sigaction) usize {
933 assert(sig >= 1);983 assert(sig >= 1);
934 assert(sig != SIGKILL);984 assert(sig != SIG.KILL);
935 assert(sig != SIGSTOP);985 assert(sig != SIG.STOP);
936986
937 var ksa: k_sigaction = undefined;987 var ksa: k_sigaction = undefined;
938 var oldksa: k_sigaction = undefined;988 var oldksa: k_sigaction = undefined;
939 const mask_size = @sizeOf(@TypeOf(ksa.mask));989 const mask_size = @sizeOf(@TypeOf(ksa.mask));
940990
941 if (act) |new| {991 if (act) |new| {
942 const restorer_fn = if ((new.flags & SA_SIGINFO) != 0) restore_rt else restore;992 const restorer_fn = if ((new.flags & SA.SIGINFO) != 0) restore_rt else restore;
943 ksa = k_sigaction{993 ksa = k_sigaction{
944 .handler = new.handler.handler,994 .handler = new.handler.handler,
945 .flags = new.flags | SA_RESTORER,995 .flags = new.flags | SA.RESTORER,
946 .mask = undefined,996 .mask = undefined,
947 .restorer = @ptrCast(fn () callconv(.C) void, restorer_fn),997 .restorer = @ptrCast(fn () callconv(.C) void, restorer_fn),
948 };998 };
...@@ -1531,8 +1581,3341 @@ pub fn fadvise(fd: fd_t, offset: i64, len: i64, advice: usize) usize {...@@ -1531,8 +1581,3341 @@ pub fn fadvise(fd: fd_t, offset: i64, len: i64, advice: usize) usize {
1531 }1581 }
1532}1582}
15331583
1534test {1584pub const E = switch (native_arch) {
1535 if (std.Target.current.os.tag == .linux) {1585 .mips, .mipsel => @import("linux/errno/mips.zig").E,
1536 _ = @import("linux/test.zig");1586 .sparc, .sparcel, .sparcv9 => @import("linux/errno/sparc.zig").E,
1587 else => @import("linux/errno/generic.zig").E,
1588};
1589
1590pub const pid_t = i32;
1591pub const fd_t = i32;
1592pub const uid_t = u32;
1593pub const gid_t = u32;
1594pub const clock_t = isize;
1595
1596pub const NAME_MAX = 255;
1597pub const PATH_MAX = 4096;
1598pub const IOV_MAX = 1024;
1599
1600/// Largest hardware address length
1601/// e.g. a mac address is a type of hardware address
1602pub const MAX_ADDR_LEN = 32;
1603
1604pub const STDIN_FILENO = 0;
1605pub const STDOUT_FILENO = 1;
1606pub const STDERR_FILENO = 2;
1607
1608pub const AT = struct {
1609 /// Special value used to indicate openat should use the current working directory
1610 pub const FDCWD = -100;
1611
1612 /// Do not follow symbolic links
1613 pub const SYMLINK_NOFOLLOW = 0x100;
1614
1615 /// Remove directory instead of unlinking file
1616 pub const REMOVEDIR = 0x200;
1617
1618 /// Follow symbolic links.
1619 pub const SYMLINK_FOLLOW = 0x400;
1620
1621 /// Suppress terminal automount traversal
1622 pub const NO_AUTOMOUNT = 0x800;
1623
1624 /// Allow empty relative pathname
1625 pub const EMPTY_PATH = 0x1000;
1626
1627 /// Type of synchronisation required from statx()
1628 pub const STATX_SYNC_TYPE = 0x6000;
1629
1630 /// - Do whatever stat() does
1631 pub const STATX_SYNC_AS_STAT = 0x0000;
1632
1633 /// - Force the attributes to be sync'd with the server
1634 pub const STATX_FORCE_SYNC = 0x2000;
1635
1636 /// - Don't sync attributes with the server
1637 pub const STATX_DONT_SYNC = 0x4000;
1638
1639 /// Apply to the entire subtree
1640 pub const RECURSIVE = 0x8000;
1641};
1642
1643pub const FALLOC = struct {
1644 /// Default is extend size
1645 pub const FL_KEEP_SIZE = 0x01;
1646
1647 /// De-allocates range
1648 pub const FL_PUNCH_HOLE = 0x02;
1649
1650 /// Reserved codepoint
1651 pub const FL_NO_HIDE_STALE = 0x04;
1652
1653 /// Removes a range of a file without leaving a hole in the file
1654 pub const FL_COLLAPSE_RANGE = 0x08;
1655
1656 /// Converts a range of file to zeros preferably without issuing data IO
1657 pub const FL_ZERO_RANGE = 0x10;
1658
1659 /// Inserts space within the file size without overwriting any existing data
1660 pub const FL_INSERT_RANGE = 0x20;
1661
1662 /// Unshares shared blocks within the file size without overwriting any existing data
1663 pub const FL_UNSHARE_RANGE = 0x40;
1664};
1665
1666pub const FUTEX = struct {
1667 pub const WAIT = 0;
1668 pub const WAKE = 1;
1669 pub const FD = 2;
1670 pub const REQUEUE = 3;
1671 pub const CMP_REQUEUE = 4;
1672 pub const WAKE_OP = 5;
1673 pub const LOCK_PI = 6;
1674 pub const UNLOCK_PI = 7;
1675 pub const TRYLOCK_PI = 8;
1676 pub const WAIT_BITSET = 9;
1677 pub const WAKE_BITSET = 10;
1678 pub const WAIT_REQUEUE_PI = 11;
1679 pub const CMP_REQUEUE_PI = 12;
1680
1681 pub const PRIVATE_FLAG = 128;
1682
1683 pub const CLOCK_REALTIME = 256;
1684};
1685
1686pub const PROT = struct {
1687 /// page can not be accessed
1688 pub const NONE = 0x0;
1689
1690 /// page can be read
1691 pub const READ = 0x1;
1692
1693 /// page can be written
1694 pub const WRITE = 0x2;
1695
1696 /// page can be executed
1697 pub const EXEC = 0x4;
1698
1699 /// page may be used for atomic ops
1700 pub const SEM = switch (native_arch) {
1701 // TODO: also xtensa
1702 .mips, .mipsel, .mips64, .mips64el => 0x10,
1703 else => 0x8,
1704 };
1705
1706 /// mprotect flag: extend change to start of growsdown vma
1707 pub const GROWSDOWN = 0x01000000;
1708
1709 /// mprotect flag: extend change to end of growsup vma
1710 pub const GROWSUP = 0x02000000;
1711};
1712
1713pub const FD_CLOEXEC = 1;
1714
1715pub const F_OK = 0;
1716pub const X_OK = 1;
1717pub const W_OK = 2;
1718pub const R_OK = 4;
1719
1720pub const W = struct {
1721 pub const NOHANG = 1;
1722 pub const UNTRACED = 2;
1723 pub const STOPPED = 2;
1724 pub const EXITED = 4;
1725 pub const CONTINUED = 8;
1726 pub const NOWAIT = 0x1000000;
1727
1728 pub fn EXITSTATUS(s: u32) u8 {
1729 return @intCast(u8, (s & 0xff00) >> 8);
1730 }
1731 pub fn TERMSIG(s: u32) u32 {
1732 return s & 0x7f;
1733 }
1734 pub fn STOPSIG(s: u32) u32 {
1735 return WEXITSTATUS(s);
1736 }
1737 pub fn IFEXITED(s: u32) bool {
1738 return WTERMSIG(s) == 0;
1739 }
1740 pub fn IFSTOPPED(s: u32) bool {
1741 return @intCast(u16, ((s & 0xffff) *% 0x10001) >> 8) > 0x7f00;
1742 }
1743 pub fn IFSIGNALED(s: u32) bool {
1744 return (s & 0xffff) -% 1 < 0xff;
1745 }
1746};
1747
1748// waitid id types
1749pub const P = enum(c_uint) {
1750 ALL = 0,
1751 PID = 1,
1752 PGID = 2,
1753 PIDFD = 3,
1754 _,
1755};
1756
1757pub const SA = if (is_mips) struct {
1758 pub const NOCLDSTOP = 1;
1759 pub const NOCLDWAIT = 0x10000;
1760 pub const SIGINFO = 8;
1761 pub const RESTART = 0x10000000;
1762 pub const RESETHAND = 0x80000000;
1763 pub const ONSTACK = 0x08000000;
1764 pub const NODEFER = 0x40000000;
1765 pub const RESTORER = 0x04000000;
1766} else if (is_sparc) struct {
1767 pub const NOCLDSTOP = 0x8;
1768 pub const NOCLDWAIT = 0x100;
1769 pub const SIGINFO = 0x200;
1770 pub const RESTART = 0x2;
1771 pub const RESETHAND = 0x4;
1772 pub const ONSTACK = 0x1;
1773 pub const NODEFER = 0x20;
1774 pub const RESTORER = 0x04000000;
1775} else struct {
1776 pub const NOCLDSTOP = 1;
1777 pub const NOCLDWAIT = 2;
1778 pub const SIGINFO = 4;
1779 pub const RESTART = 0x10000000;
1780 pub const RESETHAND = 0x80000000;
1781 pub const ONSTACK = 0x08000000;
1782 pub const NODEFER = 0x40000000;
1783 pub const RESTORER = 0x04000000;
1784};
1785
1786pub const SIG = if (is_mips) struct {
1787 pub const BLOCK = 1;
1788 pub const UNBLOCK = 2;
1789 pub const SETMASK = 3;
1790
1791 pub const HUP = 1;
1792 pub const INT = 2;
1793 pub const QUIT = 3;
1794 pub const ILL = 4;
1795 pub const TRAP = 5;
1796 pub const ABRT = 6;
1797 pub const IOT = ABRT;
1798 pub const BUS = 7;
1799 pub const FPE = 8;
1800 pub const KILL = 9;
1801 pub const USR1 = 10;
1802 pub const SEGV = 11;
1803 pub const USR2 = 12;
1804 pub const PIPE = 13;
1805 pub const ALRM = 14;
1806 pub const TERM = 15;
1807 pub const STKFLT = 16;
1808 pub const CHLD = 17;
1809 pub const CONT = 18;
1810 pub const STOP = 19;
1811 pub const TSTP = 20;
1812 pub const TTIN = 21;
1813 pub const TTOU = 22;
1814 pub const URG = 23;
1815 pub const XCPU = 24;
1816 pub const XFSZ = 25;
1817 pub const VTALRM = 26;
1818 pub const PROF = 27;
1819 pub const WINCH = 28;
1820 pub const IO = 29;
1821 pub const POLL = 29;
1822 pub const PWR = 30;
1823 pub const SYS = 31;
1824 pub const UNUSED = SIG.SYS;
1825
1826 pub const ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize));
1827 pub const DFL = @intToPtr(?Sigaction.sigaction_fn, 0);
1828 pub const IGN = @intToPtr(?Sigaction.sigaction_fn, 1);
1829} else if (is_sparc) struct {
1830 pub const BLOCK = 1;
1831 pub const UNBLOCK = 2;
1832 pub const SETMASK = 4;
1833
1834 pub const HUP = 1;
1835 pub const INT = 2;
1836 pub const QUIT = 3;
1837 pub const ILL = 4;
1838 pub const TRAP = 5;
1839 pub const ABRT = 6;
1840 pub const EMT = 7;
1841 pub const FPE = 8;
1842 pub const KILL = 9;
1843 pub const BUS = 10;
1844 pub const SEGV = 11;
1845 pub const SYS = 12;
1846 pub const PIPE = 13;
1847 pub const ALRM = 14;
1848 pub const TERM = 15;
1849 pub const URG = 16;
1850 pub const STOP = 17;
1851 pub const TSTP = 18;
1852 pub const CONT = 19;
1853 pub const CHLD = 20;
1854 pub const TTIN = 21;
1855 pub const TTOU = 22;
1856 pub const POLL = 23;
1857 pub const XCPU = 24;
1858 pub const XFSZ = 25;
1859 pub const VTALRM = 26;
1860 pub const PROF = 27;
1861 pub const WINCH = 28;
1862 pub const LOST = 29;
1863 pub const USR1 = 30;
1864 pub const USR2 = 31;
1865 pub const IOT = ABRT;
1866 pub const CLD = CHLD;
1867 pub const PWR = LOST;
1868 pub const IO = POLL;
1869
1870 pub const ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize));
1871 pub const DFL = @intToPtr(?Sigaction.sigaction_fn, 0);
1872 pub const IGN = @intToPtr(?Sigaction.sigaction_fn, 1);
1873} else struct {
1874 pub const BLOCK = 0;
1875 pub const UNBLOCK = 1;
1876 pub const SETMASK = 2;
1877
1878 pub const HUP = 1;
1879 pub const INT = 2;
1880 pub const QUIT = 3;
1881 pub const ILL = 4;
1882 pub const TRAP = 5;
1883 pub const ABRT = 6;
1884 pub const IOT = ABRT;
1885 pub const BUS = 7;
1886 pub const FPE = 8;
1887 pub const KILL = 9;
1888 pub const USR1 = 10;
1889 pub const SEGV = 11;
1890 pub const USR2 = 12;
1891 pub const PIPE = 13;
1892 pub const ALRM = 14;
1893 pub const TERM = 15;
1894 pub const STKFLT = 16;
1895 pub const CHLD = 17;
1896 pub const CONT = 18;
1897 pub const STOP = 19;
1898 pub const TSTP = 20;
1899 pub const TTIN = 21;
1900 pub const TTOU = 22;
1901 pub const URG = 23;
1902 pub const XCPU = 24;
1903 pub const XFSZ = 25;
1904 pub const VTALRM = 26;
1905 pub const PROF = 27;
1906 pub const WINCH = 28;
1907 pub const IO = 29;
1908 pub const POLL = 29;
1909 pub const PWR = 30;
1910 pub const SYS = 31;
1911 pub const UNUSED = SIG.SYS;
1912
1913 pub const ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize));
1914 pub const DFL = @intToPtr(?Sigaction.sigaction_fn, 0);
1915 pub const IGN = @intToPtr(?Sigaction.sigaction_fn, 1);
1916};
1917
1918pub const kernel_rwf = u32;
1919
1920pub const RWF = struct {
1921 /// high priority request, poll if possible
1922 pub const HIPRI: kernel_rwf = 0x00000001;
1923
1924 /// per-IO O_DSYNC
1925 pub const DSYNC: kernel_rwf = 0x00000002;
1926
1927 /// per-IO O_SYNC
1928 pub const SYNC: kernel_rwf = 0x00000004;
1929
1930 /// per-IO, return -EAGAIN if operation would block
1931 pub const NOWAIT: kernel_rwf = 0x00000008;
1932
1933 /// per-IO O_APPEND
1934 pub const APPEND: kernel_rwf = 0x00000010;
1935};
1936
1937pub const SEEK = struct {
1938 pub const SET = 0;
1939 pub const CUR = 1;
1940 pub const END = 2;
1941};
1942
1943pub const SHUT = struct {
1944 pub const RD = 0;
1945 pub const WR = 1;
1946 pub const RDWR = 2;
1947};
1948
1949pub const SOCK = struct {
1950 pub const STREAM = if (is_mips) 2 else 1;
1951 pub const DGRAM = if (is_mips) 1 else 2;
1952 pub const RAW = 3;
1953 pub const RDM = 4;
1954 pub const SEQPACKET = 5;
1955 pub const DCCP = 6;
1956 pub const PACKET = 10;
1957 pub const CLOEXEC = 0o2000000;
1958 pub const NONBLOCK = if (is_mips) 0o200 else 0o4000;
1959};
1960
1961pub const PF = struct {
1962 pub const UNSPEC = 0;
1963 pub const LOCAL = 1;
1964 pub const UNIX = PF_LOCAL;
1965 pub const FILE = PF_LOCAL;
1966 pub const INET = 2;
1967 pub const AX25 = 3;
1968 pub const IPX = 4;
1969 pub const APPLETALK = 5;
1970 pub const NETROM = 6;
1971 pub const BRIDGE = 7;
1972 pub const ATMPVC = 8;
1973 pub const X25 = 9;
1974 pub const INET6 = 10;
1975 pub const ROSE = 11;
1976 pub const DECnet = 12;
1977 pub const NETBEUI = 13;
1978 pub const SECURITY = 14;
1979 pub const KEY = 15;
1980 pub const NETLINK = 16;
1981 pub const ROUTE = PF_NETLINK;
1982 pub const PACKET = 17;
1983 pub const ASH = 18;
1984 pub const ECONET = 19;
1985 pub const ATMSVC = 20;
1986 pub const RDS = 21;
1987 pub const SNA = 22;
1988 pub const IRDA = 23;
1989 pub const PPPOX = 24;
1990 pub const WANPIPE = 25;
1991 pub const LLC = 26;
1992 pub const IB = 27;
1993 pub const MPLS = 28;
1994 pub const CAN = 29;
1995 pub const TIPC = 30;
1996 pub const BLUETOOTH = 31;
1997 pub const IUCV = 32;
1998 pub const RXRPC = 33;
1999 pub const ISDN = 34;
2000 pub const PHONET = 35;
2001 pub const IEEE802154 = 36;
2002 pub const CAIF = 37;
2003 pub const ALG = 38;
2004 pub const NFC = 39;
2005 pub const VSOCK = 40;
2006 pub const KCM = 41;
2007 pub const QIPCRTR = 42;
2008 pub const SMC = 43;
2009 pub const XDP = 44;
2010 pub const MAX = 45;
2011};
2012
2013pub const AF = struct {
2014 pub const UNSPEC = PF.UNSPEC;
2015 pub const LOCAL = PF.LOCAL;
2016 pub const UNIX = AF.LOCAL;
2017 pub const FILE = AF.LOCAL;
2018 pub const INET = PF.INET;
2019 pub const AX25 = PF.AX25;
2020 pub const IPX = PF.IPX;
2021 pub const APPLETALK = PF.APPLETALK;
2022 pub const NETROM = PF.NETROM;
2023 pub const BRIDGE = PF.BRIDGE;
2024 pub const ATMPVC = PF.ATMPVC;
2025 pub const X25 = PF.X25;
2026 pub const INET6 = PF.INET6;
2027 pub const ROSE = PF.ROSE;
2028 pub const DECnet = PF.DECnet;
2029 pub const NETBEUI = PF.NETBEUI;
2030 pub const SECURITY = PF.SECURITY;
2031 pub const KEY = PF.KEY;
2032 pub const NETLINK = PF.NETLINK;
2033 pub const ROUTE = PF.ROUTE;
2034 pub const PACKET = PF.PACKET;
2035 pub const ASH = PF.ASH;
2036 pub const ECONET = PF.ECONET;
2037 pub const ATMSVC = PF.ATMSVC;
2038 pub const RDS = PF.RDS;
2039 pub const SNA = PF.SNA;
2040 pub const IRDA = PF.IRDA;
2041 pub const PPPOX = PF.PPPOX;
2042 pub const WANPIPE = PF.WANPIPE;
2043 pub const LLC = PF.LLC;
2044 pub const IB = PF.IB;
2045 pub const MPLS = PF.MPLS;
2046 pub const CAN = PF.CAN;
2047 pub const TIPC = PF.TIPC;
2048 pub const BLUETOOTH = PF.BLUETOOTH;
2049 pub const IUCV = PF.IUCV;
2050 pub const RXRPC = PF.RXRPC;
2051 pub const ISDN = PF.ISDN;
2052 pub const PHONET = PF.PHONET;
2053 pub const IEEE802154 = PF.IEEE802154;
2054 pub const CAIF = PF.CAIF;
2055 pub const ALG = PF.ALG;
2056 pub const NFC = PF.NFC;
2057 pub const VSOCK = PF.VSOCK;
2058 pub const KCM = PF.KCM;
2059 pub const QIPCRTR = PF.QIPCRTR;
2060 pub const SMC = PF.SMC;
2061 pub const XDP = PF.XDP;
2062 pub const MAX = PF.MAX;
2063};
2064
2065pub const SO = if (is_mips) struct {
2066 pub const SECURITY_AUTHENTICATION = 22;
2067 pub const SECURITY_ENCRYPTION_TRANSPORT = 23;
2068 pub const SECURITY_ENCRYPTION_NETWORK = 24;
2069
2070 pub const BINDTODEVICE = 25;
2071
2072 pub const ATTACH_FILTER = 26;
2073 pub const DETACH_FILTER = 27;
2074 pub const GET_FILTER = ATTACH_FILTER;
2075
2076 pub const PEERNAME = 28;
2077 pub const TIMESTAMP_OLD = 29;
2078 pub const PASSSEC = 34;
2079 pub const TIMESTAMPNS_OLD = 35;
2080 pub const MARK = 36;
2081 pub const TIMESTAMPING_OLD = 37;
2082
2083 pub const RXQ_OVFL = 40;
2084 pub const WIFI_STATUS = 41;
2085 pub const PEEK_OFF = 42;
2086 pub const NOFCS = 43;
2087 pub const LOCK_FILTER = 44;
2088 pub const SELECT_ERR_QUEUE = 45;
2089 pub const BUSY_POLL = 46;
2090 pub const MAX_PACING_RATE = 47;
2091 pub const BPF_EXTENSIONS = 48;
2092 pub const INCOMING_CPU = 49;
2093 pub const ATTACH_BPF = 50;
2094 pub const DETACH_BPF = DETACH_FILTER;
2095 pub const ATTACH_REUSEPORT_CBPF = 51;
2096 pub const ATTACH_REUSEPORT_EBPF = 52;
2097 pub const CNX_ADVICE = 53;
2098 pub const MEMINFO = 55;
2099 pub const INCOMING_NAPI_ID = 56;
2100 pub const COOKIE = 57;
2101 pub const PEERGROUPS = 59;
2102 pub const ZEROCOPY = 60;
2103 pub const TXTIME = 61;
2104 pub const BINDTOIFINDEX = 62;
2105 pub const TIMESTAMP_NEW = 63;
2106 pub const TIMESTAMPNS_NEW = 64;
2107 pub const TIMESTAMPING_NEW = 65;
2108 pub const RCVTIMEO_NEW = 66;
2109 pub const SNDTIMEO_NEW = 67;
2110 pub const DETACH_REUSEPORT_BPF = 68;
2111} else if (is_ppc or is_ppc64) struct {
2112 pub const DEBUG = 1;
2113 pub const REUSEADDR = 2;
2114 pub const TYPE = 3;
2115 pub const ERROR = 4;
2116 pub const DONTROUTE = 5;
2117 pub const BROADCAST = 6;
2118 pub const SNDBUF = 7;
2119 pub const RCVBUF = 8;
2120 pub const KEEPALIVE = 9;
2121 pub const OOBINLINE = 10;
2122 pub const NO_CHECK = 11;
2123 pub const PRIORITY = 12;
2124 pub const LINGER = 13;
2125 pub const BSDCOMPAT = 14;
2126 pub const REUSEPORT = 15;
2127 pub const RCVLOWAT = 16;
2128 pub const SNDLOWAT = 17;
2129 pub const RCVTIMEO = 18;
2130 pub const SNDTIMEO = 19;
2131 pub const PASSCRED = 20;
2132 pub const PEERCRED = 21;
2133 pub const ACCEPTCONN = 30;
2134 pub const PEERSEC = 31;
2135 pub const SNDBUFFORCE = 32;
2136 pub const RCVBUFFORCE = 33;
2137 pub const PROTOCOL = 38;
2138 pub const DOMAIN = 39;
2139
2140 pub const SECURITY_AUTHENTICATION = 22;
2141 pub const SECURITY_ENCRYPTION_TRANSPORT = 23;
2142 pub const SECURITY_ENCRYPTION_NETWORK = 24;
2143
2144 pub const BINDTODEVICE = 25;
2145
2146 pub const ATTACH_FILTER = 26;
2147 pub const DETACH_FILTER = 27;
2148 pub const GET_FILTER = ATTACH_FILTER;
2149
2150 pub const PEERNAME = 28;
2151 pub const TIMESTAMP_OLD = 29;
2152 pub const PASSSEC = 34;
2153 pub const TIMESTAMPNS_OLD = 35;
2154 pub const MARK = 36;
2155 pub const TIMESTAMPING_OLD = 37;
2156
2157 pub const RXQ_OVFL = 40;
2158 pub const WIFI_STATUS = 41;
2159 pub const PEEK_OFF = 42;
2160 pub const NOFCS = 43;
2161 pub const LOCK_FILTER = 44;
2162 pub const SELECT_ERR_QUEUE = 45;
2163 pub const BUSY_POLL = 46;
2164 pub const MAX_PACING_RATE = 47;
2165 pub const BPF_EXTENSIONS = 48;
2166 pub const INCOMING_CPU = 49;
2167 pub const ATTACH_BPF = 50;
2168 pub const DETACH_BPF = DETACH_FILTER;
2169 pub const ATTACH_REUSEPORT_CBPF = 51;
2170 pub const ATTACH_REUSEPORT_EBPF = 52;
2171 pub const CNX_ADVICE = 53;
2172 pub const MEMINFO = 55;
2173 pub const INCOMING_NAPI_ID = 56;
2174 pub const COOKIE = 57;
2175 pub const PEERGROUPS = 59;
2176 pub const ZEROCOPY = 60;
2177 pub const TXTIME = 61;
2178 pub const BINDTOIFINDEX = 62;
2179 pub const TIMESTAMP_NEW = 63;
2180 pub const TIMESTAMPNS_NEW = 64;
2181 pub const TIMESTAMPING_NEW = 65;
2182 pub const RCVTIMEO_NEW = 66;
2183 pub const SNDTIMEO_NEW = 67;
2184 pub const DETACH_REUSEPORT_BPF = 68;
2185} else struct {
2186 pub const DEBUG = 1;
2187 pub const REUSEADDR = 2;
2188 pub const TYPE = 3;
2189 pub const ERROR = 4;
2190 pub const DONTROUTE = 5;
2191 pub const BROADCAST = 6;
2192 pub const SNDBUF = 7;
2193 pub const RCVBUF = 8;
2194 pub const KEEPALIVE = 9;
2195 pub const OOBINLINE = 10;
2196 pub const NO_CHECK = 11;
2197 pub const PRIORITY = 12;
2198 pub const LINGER = 13;
2199 pub const BSDCOMPAT = 14;
2200 pub const REUSEPORT = 15;
2201 pub const PASSCRED = 16;
2202 pub const PEERCRED = 17;
2203 pub const RCVLOWAT = 18;
2204 pub const SNDLOWAT = 19;
2205 pub const RCVTIMEO = 20;
2206 pub const SNDTIMEO = 21;
2207 pub const ACCEPTCONN = 30;
2208 pub const PEERSEC = 31;
2209 pub const SNDBUFFORCE = 32;
2210 pub const RCVBUFFORCE = 33;
2211 pub const PROTOCOL = 38;
2212 pub const DOMAIN = 39;
2213
2214 pub const SECURITY_AUTHENTICATION = 22;
2215 pub const SECURITY_ENCRYPTION_TRANSPORT = 23;
2216 pub const SECURITY_ENCRYPTION_NETWORK = 24;
2217
2218 pub const BINDTODEVICE = 25;
2219
2220 pub const ATTACH_FILTER = 26;
2221 pub const DETACH_FILTER = 27;
2222 pub const GET_FILTER = ATTACH_FILTER;
2223
2224 pub const PEERNAME = 28;
2225 pub const TIMESTAMP_OLD = 29;
2226 pub const PASSSEC = 34;
2227 pub const TIMESTAMPNS_OLD = 35;
2228 pub const MARK = 36;
2229 pub const TIMESTAMPING_OLD = 37;
2230
2231 pub const RXQ_OVFL = 40;
2232 pub const WIFI_STATUS = 41;
2233 pub const PEEK_OFF = 42;
2234 pub const NOFCS = 43;
2235 pub const LOCK_FILTER = 44;
2236 pub const SELECT_ERR_QUEUE = 45;
2237 pub const BUSY_POLL = 46;
2238 pub const MAX_PACING_RATE = 47;
2239 pub const BPF_EXTENSIONS = 48;
2240 pub const INCOMING_CPU = 49;
2241 pub const ATTACH_BPF = 50;
2242 pub const DETACH_BPF = DETACH_FILTER;
2243 pub const ATTACH_REUSEPORT_CBPF = 51;
2244 pub const ATTACH_REUSEPORT_EBPF = 52;
2245 pub const CNX_ADVICE = 53;
2246 pub const MEMINFO = 55;
2247 pub const INCOMING_NAPI_ID = 56;
2248 pub const COOKIE = 57;
2249 pub const PEERGROUPS = 59;
2250 pub const ZEROCOPY = 60;
2251 pub const TXTIME = 61;
2252 pub const BINDTOIFINDEX = 62;
2253 pub const TIMESTAMP_NEW = 63;
2254 pub const TIMESTAMPNS_NEW = 64;
2255 pub const TIMESTAMPING_NEW = 65;
2256 pub const RCVTIMEO_NEW = 66;
2257 pub const SNDTIMEO_NEW = 67;
2258 pub const DETACH_REUSEPORT_BPF = 68;
2259};
2260
2261pub const SCM = struct {
2262 pub const WIFI_STATUS = SO.WIFI_STATUS;
2263 pub const TIMESTAMPING_OPT_STATS = 54;
2264 pub const TIMESTAMPING_PKTINFO = 58;
2265 pub const TXTIME = SO.TXTIME;
2266};
2267
2268pub const SOL = struct {
2269 pub const SOCKET = if (is_mips) 65535 else 1;
2270
2271 pub const IP = 0;
2272 pub const IPV6 = 41;
2273 pub const ICMPV6 = 58;
2274
2275 pub const RAW = 255;
2276 pub const DECNET = 261;
2277 pub const X25 = 262;
2278 pub const PACKET = 263;
2279 pub const ATM = 264;
2280 pub const AAL = 265;
2281 pub const IRDA = 266;
2282 pub const NETBEUI = 267;
2283 pub const LLC = 268;
2284 pub const DCCP = 269;
2285 pub const NETLINK = 270;
2286 pub const TIPC = 271;
2287 pub const RXRPC = 272;
2288 pub const PPPOL2TP = 273;
2289 pub const BLUETOOTH = 274;
2290 pub const PNPIPE = 275;
2291 pub const RDS = 276;
2292 pub const IUCV = 277;
2293 pub const CAIF = 278;
2294 pub const ALG = 279;
2295 pub const NFC = 280;
2296 pub const KCM = 281;
2297 pub const TLS = 282;
2298 pub const XDP = 283;
2299};
2300
2301pub const SOMAXCONN = 128;
2302
2303pub const IP = struct {
2304 pub const TOS = 1;
2305 pub const TTL = 2;
2306 pub const HDRINCL = 3;
2307 pub const OPTIONS = 4;
2308 pub const ROUTER_ALERT = 5;
2309 pub const RECVOPTS = 6;
2310 pub const RETOPTS = 7;
2311 pub const PKTINFO = 8;
2312 pub const PKTOPTIONS = 9;
2313 pub const PMTUDISC = 10;
2314 pub const MTU_DISCOVER = 10;
2315 pub const RECVERR = 11;
2316 pub const RECVTTL = 12;
2317 pub const RECVTOS = 13;
2318 pub const MTU = 14;
2319 pub const FREEBIND = 15;
2320 pub const IPSEC_POLICY = 16;
2321 pub const XFRM_POLICY = 17;
2322 pub const PASSSEC = 18;
2323 pub const TRANSPARENT = 19;
2324 pub const ORIGDSTADDR = 20;
2325 pub const RECVORIGDSTADDR = IP_ORIGDSTADDR;
2326 pub const MINTTL = 21;
2327 pub const NODEFRAG = 22;
2328 pub const CHECKSUM = 23;
2329 pub const BIND_ADDRESS_NO_PORT = 24;
2330 pub const RECVFRAGSIZE = 25;
2331 pub const MULTICAST_IF = 32;
2332 pub const MULTICAST_TTL = 33;
2333 pub const MULTICAST_LOOP = 34;
2334 pub const ADD_MEMBERSHIP = 35;
2335 pub const DROP_MEMBERSHIP = 36;
2336 pub const UNBLOCK_SOURCE = 37;
2337 pub const BLOCK_SOURCE = 38;
2338 pub const ADD_SOURCE_MEMBERSHIP = 39;
2339 pub const DROP_SOURCE_MEMBERSHIP = 40;
2340 pub const MSFILTER = 41;
2341 pub const MULTICAST_ALL = 49;
2342 pub const UNICAST_IF = 50;
2343
2344 pub const RECVRETOPTS = IP_RETOPTS;
2345
2346 pub const PMTUDISC_DONT = 0;
2347 pub const PMTUDISC_WANT = 1;
2348 pub const PMTUDISC_DO = 2;
2349 pub const PMTUDISC_PROBE = 3;
2350 pub const PMTUDISC_INTERFACE = 4;
2351 pub const PMTUDISC_OMIT = 5;
2352
2353 pub const DEFAULT_MULTICAST_TTL = 1;
2354 pub const DEFAULT_MULTICAST_LOOP = 1;
2355 pub const MAX_MEMBERSHIPS = 20;
2356};
2357
2358/// IPv6 socket options
2359pub const IPV6 = struct {
2360 pub const ADDRFORM = 1;
2361 pub const @"2292PKTINFO" = 2;
2362 pub const @"2292HOPOPTS" = 3;
2363 pub const @"2292DSTOPTS" = 4;
2364 pub const @"2292RTHDR" = 5;
2365 pub const @"2292PKTOPTIONS" = 6;
2366 pub const CHECKSUM = 7;
2367 pub const @"2292HOPLIMIT" = 8;
2368 pub const NEXTHOP = 9;
2369 pub const AUTHHDR = 10;
2370 pub const FLOWINFO = 11;
2371
2372 pub const UNICAST_HOPS = 16;
2373 pub const MULTICAST_IF = 17;
2374 pub const MULTICAST_HOPS = 18;
2375 pub const MULTICAST_LOOP = 19;
2376 pub const ADD_MEMBERSHIP = 20;
2377 pub const DROP_MEMBERSHIP = 21;
2378 pub const ROUTER_ALERT = 22;
2379 pub const MTU_DISCOVER = 23;
2380 pub const MTU = 24;
2381 pub const RECVERR = 25;
2382 pub const V6ONLY = 26;
2383 pub const JOIN_ANYCAST = 27;
2384 pub const LEAVE_ANYCAST = 28;
2385
2386 // IPV6_MTU_DISCOVER values
2387 pub const PMTUDISC_DONT = 0;
2388 pub const PMTUDISC_WANT = 1;
2389 pub const PMTUDISC_DO = 2;
2390 pub const PMTUDISC_PROBE = 3;
2391 pub const PMTUDISC_INTERFACE = 4;
2392 pub const PMTUDISC_OMIT = 5;
2393
2394 // Flowlabel
2395 pub const FLOWLABEL_MGR = 32;
2396 pub const FLOWINFO_SEND = 33;
2397 pub const IPSEC_POLICY = 34;
2398 pub const XFRM_POLICY = 35;
2399 pub const HDRINCL = 36;
2400
2401 // Advanced API (RFC3542) (1)
2402 pub const RECVPKTINFO = 49;
2403 pub const PKTINFO = 50;
2404 pub const RECVHOPLIMIT = 51;
2405 pub const HOPLIMIT = 52;
2406 pub const RECVHOPOPTS = 53;
2407 pub const HOPOPTS = 54;
2408 pub const RTHDRDSTOPTS = 55;
2409 pub const RECVRTHDR = 56;
2410 pub const RTHDR = 57;
2411 pub const RECVDSTOPTS = 58;
2412 pub const DSTOPTS = 59;
2413 pub const RECVPATHMTU = 60;
2414 pub const PATHMTU = 61;
2415 pub const DONTFRAG = 62;
2416
2417 // Advanced API (RFC3542) (2)
2418 pub const RECVTCLASS = 66;
2419 pub const TCLASS = 67;
2420
2421 pub const AUTOFLOWLABEL = 70;
2422
2423 // RFC5014: Source address selection
2424 pub const ADDR_PREFERENCES = 72;
2425
2426 pub const PREFER_SRC_TMP = 0x0001;
2427 pub const PREFER_SRC_PUBLIC = 0x0002;
2428 pub const PREFER_SRC_PUBTMP_DEFAULT = 0x0100;
2429 pub const PREFER_SRC_COA = 0x0004;
2430 pub const PREFER_SRC_HOME = 0x0400;
2431 pub const PREFER_SRC_CGA = 0x0008;
2432 pub const PREFER_SRC_NONCGA = 0x0800;
2433
2434 // RFC5082: Generalized Ttl Security Mechanism
2435 pub const MINHOPCOUNT = 73;
2436
2437 pub const ORIGDSTADDR = 74;
2438 pub const RECVORIGDSTADDR = IPV6_ORIGDSTADDR;
2439 pub const TRANSPARENT = 75;
2440 pub const UNICAST_IF = 76;
2441 pub const RECVFRAGSIZE = 77;
2442 pub const FREEBIND = 78;
2443};
2444
2445pub const MSG = struct {
2446 pub const OOB = 0x0001;
2447 pub const PEEK = 0x0002;
2448 pub const DONTROUTE = 0x0004;
2449 pub const CTRUNC = 0x0008;
2450 pub const PROXY = 0x0010;
2451 pub const TRUNC = 0x0020;
2452 pub const DONTWAIT = 0x0040;
2453 pub const EOR = 0x0080;
2454 pub const WAITALL = 0x0100;
2455 pub const FIN = 0x0200;
2456 pub const SYN = 0x0400;
2457 pub const CONFIRM = 0x0800;
2458 pub const RST = 0x1000;
2459 pub const ERRQUEUE = 0x2000;
2460 pub const NOSIGNAL = 0x4000;
2461 pub const MORE = 0x8000;
2462 pub const WAITFORONE = 0x10000;
2463 pub const BATCH = 0x40000;
2464 pub const ZEROCOPY = 0x4000000;
2465 pub const FASTOPEN = 0x20000000;
2466 pub const CMSG_CLOEXEC = 0x40000000;
2467};
2468
2469pub const DT = struct {
2470 pub const UNKNOWN = 0;
2471 pub const FIFO = 1;
2472 pub const CHR = 2;
2473 pub const DIR = 4;
2474 pub const BLK = 6;
2475 pub const REG = 8;
2476 pub const LNK = 10;
2477 pub const SOCK = 12;
2478 pub const WHT = 14;
2479};
2480
2481pub const T = struct {
2482 pub const CGETS = if (is_mips) 0x540D else 0x5401;
2483 pub const CSETS = 0x5402;
2484 pub const CSETSW = 0x5403;
2485 pub const CSETSF = 0x5404;
2486 pub const CGETA = 0x5405;
2487 pub const CSETA = 0x5406;
2488 pub const CSETAW = 0x5407;
2489 pub const CSETAF = 0x5408;
2490 pub const CSBRK = 0x5409;
2491 pub const CXONC = 0x540A;
2492 pub const CFLSH = 0x540B;
2493 pub const IOCEXCL = 0x540C;
2494 pub const IOCNXCL = 0x540D;
2495 pub const IOCSCTTY = 0x540E;
2496 pub const IOCGPGRP = 0x540F;
2497 pub const IOCSPGRP = 0x5410;
2498 pub const IOCOUTQ = if (is_mips) 0x7472 else 0x5411;
2499 pub const IOCSTI = 0x5412;
2500 pub const IOCGWINSZ = if (is_mips or is_ppc64) 0x40087468 else 0x5413;
2501 pub const IOCSWINSZ = if (is_mips or is_ppc64) 0x80087467 else 0x5414;
2502 pub const IOCMGET = 0x5415;
2503 pub const IOCMBIS = 0x5416;
2504 pub const IOCMBIC = 0x5417;
2505 pub const IOCMSET = 0x5418;
2506 pub const IOCGSOFTCAR = 0x5419;
2507 pub const IOCSSOFTCAR = 0x541A;
2508 pub const FIONREAD = if (is_mips) 0x467F else 0x541B;
2509 pub const IOCINQ = FIONREAD;
2510 pub const IOCLINUX = 0x541C;
2511 pub const IOCCONS = 0x541D;
2512 pub const IOCGSERIAL = 0x541E;
2513 pub const IOCSSERIAL = 0x541F;
2514 pub const IOCPKT = 0x5420;
2515 pub const FIONBIO = 0x5421;
2516 pub const IOCNOTTY = 0x5422;
2517 pub const IOCSETD = 0x5423;
2518 pub const IOCGETD = 0x5424;
2519 pub const CSBRKP = 0x5425;
2520 pub const IOCSBRK = 0x5427;
2521 pub const IOCCBRK = 0x5428;
2522 pub const IOCGSID = 0x5429;
2523 pub const IOCGRS485 = 0x542E;
2524 pub const IOCSRS485 = 0x542F;
2525 pub const IOCGPTN = 0x80045430;
2526 pub const IOCSPTLCK = 0x40045431;
2527 pub const IOCGDEV = 0x80045432;
2528 pub const CGETX = 0x5432;
2529 pub const CSETX = 0x5433;
2530 pub const CSETXF = 0x5434;
2531 pub const CSETXW = 0x5435;
2532 pub const IOCSIG = 0x40045436;
2533 pub const IOCVHANGUP = 0x5437;
2534 pub const IOCGPKT = 0x80045438;
2535 pub const IOCGPTLCK = 0x80045439;
2536 pub const IOCGEXCL = 0x80045440;
2537};
2538
2539pub const EPOLL = struct {
2540 pub const CLOEXEC = O.CLOEXEC;
2541
2542 pub const CTL_ADD = 1;
2543 pub const CTL_DEL = 2;
2544 pub const CTL_MOD = 3;
2545
2546 pub const IN = 0x001;
2547 pub const PRI = 0x002;
2548 pub const OUT = 0x004;
2549 pub const RDNORM = 0x040;
2550 pub const RDBAND = 0x080;
2551 pub const WRNORM = if (is_mips) 0x004 else 0x100;
2552 pub const WRBAND = if (is_mips) 0x100 else 0x200;
2553 pub const MSG = 0x400;
2554 pub const ERR = 0x008;
2555 pub const HUP = 0x010;
2556 pub const RDHUP = 0x2000;
2557 pub const EXCLUSIVE = (@as(u32, 1) << 28);
2558 pub const WAKEUP = (@as(u32, 1) << 29);
2559 pub const ONESHOT = (@as(u32, 1) << 30);
2560 pub const ET = (@as(u32, 1) << 31);
2561};
2562
2563pub const CLOCK = struct {
2564 pub const REALTIME = 0;
2565 pub const MONOTONIC = 1;
2566 pub const PROCESS_CPUTIME_ID = 2;
2567 pub const THREAD_CPUTIME_ID = 3;
2568 pub const MONOTONIC_RAW = 4;
2569 pub const REALTIME_COARSE = 5;
2570 pub const MONOTONIC_COARSE = 6;
2571 pub const BOOTTIME = 7;
2572 pub const REALTIME_ALARM = 8;
2573 pub const BOOTTIME_ALARM = 9;
2574 pub const SGI_CYCLE = 10;
2575 pub const TAI = 11;
2576};
2577
2578pub const CSIGNAL = 0x000000ff;
2579
2580pub const CLONE = struct {
2581 pub const VM = 0x00000100;
2582 pub const FS = 0x00000200;
2583 pub const FILES = 0x00000400;
2584 pub const SIGHAND = 0x00000800;
2585 pub const PIDFD = 0x00001000;
2586 pub const PTRACE = 0x00002000;
2587 pub const VFORK = 0x00004000;
2588 pub const PARENT = 0x00008000;
2589 pub const THREAD = 0x00010000;
2590 pub const NEWNS = 0x00020000;
2591 pub const SYSVSEM = 0x00040000;
2592 pub const SETTLS = 0x00080000;
2593 pub const PARENT_SETTID = 0x00100000;
2594 pub const CHILD_CLEARTID = 0x00200000;
2595 pub const DETACHED = 0x00400000;
2596 pub const UNTRACED = 0x00800000;
2597 pub const CHILD_SETTID = 0x01000000;
2598 pub const NEWCGROUP = 0x02000000;
2599 pub const NEWUTS = 0x04000000;
2600 pub const NEWIPC = 0x08000000;
2601 pub const NEWUSER = 0x10000000;
2602 pub const NEWPID = 0x20000000;
2603 pub const NEWNET = 0x40000000;
2604 pub const IO = 0x80000000;
2605
2606 // Flags for the clone3() syscall.
2607
2608 /// Clear any signal handler and reset to SIG_DFL.
2609 pub const CLEAR_SIGHAND = 0x100000000;
2610 /// Clone into a specific cgroup given the right permissions.
2611 pub const INTO_CGROUP = 0x200000000;
2612
2613 // cloning flags intersect with CSIGNAL so can be used with unshare and clone3 syscalls only.
2614
2615 /// New time namespace
2616 pub const NEWTIME = 0x00000080;
2617};
2618
2619pub const EFD = struct {
2620 pub const SEMAPHORE = 1;
2621 pub const CLOEXEC = O.CLOEXEC;
2622 pub const NONBLOCK = O.NONBLOCK;
2623};
2624
2625pub const MS = struct {
2626 pub const RDONLY = 1;
2627 pub const NOSUID = 2;
2628 pub const NODEV = 4;
2629 pub const NOEXEC = 8;
2630 pub const SYNCHRONOUS = 16;
2631 pub const REMOUNT = 32;
2632 pub const MANDLOCK = 64;
2633 pub const DIRSYNC = 128;
2634 pub const NOATIME = 1024;
2635 pub const NODIRATIME = 2048;
2636 pub const BIND = 4096;
2637 pub const MOVE = 8192;
2638 pub const REC = 16384;
2639 pub const SILENT = 32768;
2640 pub const POSIXACL = (1 << 16);
2641 pub const UNBINDABLE = (1 << 17);
2642 pub const PRIVATE = (1 << 18);
2643 pub const SLAVE = (1 << 19);
2644 pub const SHARED = (1 << 20);
2645 pub const RELATIME = (1 << 21);
2646 pub const KERNMOUNT = (1 << 22);
2647 pub const I_VERSION = (1 << 23);
2648 pub const STRICTATIME = (1 << 24);
2649 pub const LAZYTIME = (1 << 25);
2650 pub const NOREMOTELOCK = (1 << 27);
2651 pub const NOSEC = (1 << 28);
2652 pub const BORN = (1 << 29);
2653 pub const ACTIVE = (1 << 30);
2654 pub const NOUSER = (1 << 31);
2655
2656 pub const RMT_MASK = (RDONLY | SYNCHRONOUS | MANDLOCK | I_VERSION | LAZYTIME);
2657
2658 pub const MGC_VAL = 0xc0ed0000;
2659 pub const MGC_MSK = 0xffff0000;
2660};
2661
2662pub const MNT = struct {
2663 pub const FORCE = 1;
2664 pub const DETACH = 2;
2665 pub const EXPIRE = 4;
2666};
2667
2668pub const UMOUNT_NOFOLLOW = 8;
2669
2670pub const IN = struct {
2671 pub const CLOEXEC = O.CLOEXEC;
2672 pub const NONBLOCK = O.NONBLOCK;
2673
2674 pub const ACCESS = 0x00000001;
2675 pub const MODIFY = 0x00000002;
2676 pub const ATTRIB = 0x00000004;
2677 pub const CLOSE_WRITE = 0x00000008;
2678 pub const CLOSE_NOWRITE = 0x00000010;
2679 pub const CLOSE = CLOSE_WRITE | CLOSE_NOWRITE;
2680 pub const OPEN = 0x00000020;
2681 pub const MOVED_FROM = 0x00000040;
2682 pub const MOVED_TO = 0x00000080;
2683 pub const MOVE = MOVED_FROM | MOVED_TO;
2684 pub const CREATE = 0x00000100;
2685 pub const DELETE = 0x00000200;
2686 pub const DELETE_SELF = 0x00000400;
2687 pub const MOVE_SELF = 0x00000800;
2688 pub const ALL_EVENTS = 0x00000fff;
2689
2690 pub const UNMOUNT = 0x00002000;
2691 pub const Q_OVERFLOW = 0x00004000;
2692 pub const IGNORED = 0x00008000;
2693
2694 pub const ONLYDIR = 0x01000000;
2695 pub const DONT_FOLLOW = 0x02000000;
2696 pub const EXCL_UNLINK = 0x04000000;
2697 pub const MASK_ADD = 0x20000000;
2698
2699 pub const ISDIR = 0x40000000;
2700 pub const ONESHOT = 0x80000000;
2701};
2702
2703pub const S = struct {
2704 pub const IFMT = 0o170000;
2705
2706 pub const IFDIR = 0o040000;
2707 pub const IFCHR = 0o020000;
2708 pub const IFBLK = 0o060000;
2709 pub const IFREG = 0o100000;
2710 pub const IFIFO = 0o010000;
2711 pub const IFLNK = 0o120000;
2712 pub const IFSOCK = 0o140000;
2713
2714 pub const ISUID = 0o4000;
2715 pub const ISGID = 0o2000;
2716 pub const ISVTX = 0o1000;
2717 pub const IRUSR = 0o400;
2718 pub const IWUSR = 0o200;
2719 pub const IXUSR = 0o100;
2720 pub const IRWXU = 0o700;
2721 pub const IRGRP = 0o040;
2722 pub const IWGRP = 0o020;
2723 pub const IXGRP = 0o010;
2724 pub const IRWXG = 0o070;
2725 pub const IROTH = 0o004;
2726 pub const IWOTH = 0o002;
2727 pub const IXOTH = 0o001;
2728 pub const IRWXO = 0o007;
2729
2730 pub fn ISREG(m: u32) bool {
2731 return m & IFMT == IFREG;
2732 }
2733
2734 pub fn ISDIR(m: u32) bool {
2735 return m & IFMT == IFDIR;
2736 }
2737
2738 pub fn ISCHR(m: u32) bool {
2739 return m & IFMT == IFCHR;
2740 }
2741
2742 pub fn ISBLK(m: u32) bool {
2743 return m & IFMT == IFBLK;
2744 }
2745
2746 pub fn ISFIFO(m: u32) bool {
2747 return m & IFMT == IFIFO;
2748 }
2749
2750 pub fn ISLNK(m: u32) bool {
2751 return m & IFMT == IFLNK;
2752 }
2753
2754 pub fn ISSOCK(m: u32) bool {
2755 return m & IFMT == IFSOCK;
2756 }
2757};
2758
2759pub const UTIME = struct {
2760 pub const NOW = 0x3fffffff;
2761 pub const OMIT = 0x3ffffffe;
2762};
2763
2764pub const TFD = struct {
2765 pub const NONBLOCK = O.NONBLOCK;
2766 pub const CLOEXEC = O.CLOEXEC;
2767
2768 pub const TIMER_ABSTIME = 1;
2769 pub const TIMER_CANCEL_ON_SET = (1 << 1);
2770};
2771
2772pub const winsize = extern struct {
2773 ws_row: u16,
2774 ws_col: u16,
2775 ws_xpixel: u16,
2776 ws_ypixel: u16,
2777};
2778
2779/// NSIG is the total number of signals defined.
2780/// As signal numbers are sequential, NSIG is one greater than the largest defined signal number.
2781pub const NSIG = if (is_mips) 128 else 65;
2782
2783pub const sigset_t = [1024 / 32]u32;
2784
2785pub const all_mask: sigset_t = [_]u32{0xffffffff} ** sigset_t.len;
2786pub const app_mask: sigset_t = [2]u32{ 0xfffffffc, 0x7fffffff } ++ [_]u32{0xffffffff} ** 30;
2787
2788pub const k_sigaction = switch (native_arch) {
2789 .mips, .mipsel => extern struct {
2790 flags: c_uint,
2791 handler: ?fn (c_int) callconv(.C) void,
2792 mask: [4]c_ulong,
2793 restorer: fn () callconv(.C) void,
2794 },
2795 .mips64, .mips64el => extern struct {
2796 flags: c_uint,
2797 handler: ?fn (c_int) callconv(.C) void,
2798 mask: [2]c_ulong,
2799 restorer: fn () callconv(.C) void,
2800 },
2801 else => extern struct {
2802 handler: ?fn (c_int) callconv(.C) void,
2803 flags: c_ulong,
2804 restorer: fn () callconv(.C) void,
2805 mask: [2]c_uint,
2806 },
2807};
2808
2809/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
2810pub const Sigaction = extern struct {
2811 pub const handler_fn = fn (c_int) callconv(.C) void;
2812 pub const sigaction_fn = fn (c_int, *const siginfo_t, ?*const c_void) callconv(.C) void;
2813
2814 handler: extern union {
2815 handler: ?handler_fn,
2816 sigaction: ?sigaction_fn,
2817 },
2818 mask: sigset_t,
2819 flags: c_uint,
2820 restorer: ?fn () callconv(.C) void = null,
2821};
2822
2823pub const empty_sigset = [_]u32{0} ** @typeInfo(sigset_t).Array.len;
2824
2825pub const SFD = struct {
2826 pub const CLOEXEC = O.CLOEXEC;
2827 pub const NONBLOCK = O.NONBLOCK;
2828};
2829
2830pub const signalfd_siginfo = extern struct {
2831 signo: u32,
2832 errno: i32,
2833 code: i32,
2834 pid: u32,
2835 uid: uid_t,
2836 fd: i32,
2837 tid: u32,
2838 band: u32,
2839 overrun: u32,
2840 trapno: u32,
2841 status: i32,
2842 int: i32,
2843 ptr: u64,
2844 utime: u64,
2845 stime: u64,
2846 addr: u64,
2847 addr_lsb: u16,
2848 __pad2: u16,
2849 syscall: i32,
2850 call_addr: u64,
2851 native_arch: u32,
2852 __pad: [28]u8,
2853};
2854
2855pub const in_port_t = u16;
2856pub const sa_family_t = u16;
2857pub const socklen_t = u32;
2858
2859pub const sockaddr = extern struct {
2860 family: sa_family_t,
2861 data: [14]u8,
2862};
2863
2864pub const sockaddr_storage = std.x.os.Socket.Address.Native.Storage;
2865
2866/// IPv4 socket address
2867pub const sockaddr_in = extern struct {
2868 family: sa_family_t = AF_INET,
2869 port: in_port_t,
2870 addr: u32,
2871 zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
2872};
2873
2874/// IPv6 socket address
2875pub const sockaddr_in6 = extern struct {
2876 family: sa_family_t = AF_INET6,
2877 port: in_port_t,
2878 flowinfo: u32,
2879 addr: [16]u8,
2880 scope_id: u32,
2881};
2882
2883/// UNIX domain socket address
2884pub const sockaddr_un = extern struct {
2885 family: sa_family_t = AF_UNIX,
2886 path: [108]u8,
2887};
2888
2889pub const mmsghdr = extern struct {
2890 msg_hdr: msghdr,
2891 msg_len: u32,
2892};
2893
2894pub const mmsghdr_const = extern struct {
2895 msg_hdr: msghdr_const,
2896 msg_len: u32,
2897};
2898
2899pub const epoll_data = extern union {
2900 ptr: usize,
2901 fd: i32,
2902 @"u32": u32,
2903 @"u64": u64,
2904};
2905
2906// On x86_64 the structure is packed so that it matches the definition of its
2907// 32bit counterpart
2908pub const epoll_event = switch (native_arch) {
2909 .x86_64 => packed struct {
2910 events: u32,
2911 data: epoll_data,
2912 },
2913 else => extern struct {
2914 events: u32,
2915 data: epoll_data,
2916 },
2917};
2918
2919pub const VFS_CAP_REVISION_MASK = 0xFF000000;
2920pub const VFS_CAP_REVISION_SHIFT = 24;
2921pub const VFS_CAP_FLAGS_MASK = ~VFS_CAP_REVISION_MASK;
2922pub const VFS_CAP_FLAGS_EFFECTIVE = 0x000001;
2923
2924pub const VFS_CAP_REVISION_1 = 0x01000000;
2925pub const VFS_CAP_U32_1 = 1;
2926pub const XATTR_CAPS_SZ_1 = @sizeOf(u32) * (1 + 2 * VFS_CAP_U32_1);
2927
2928pub const VFS_CAP_REVISION_2 = 0x02000000;
2929pub const VFS_CAP_U32_2 = 2;
2930pub const XATTR_CAPS_SZ_2 = @sizeOf(u32) * (1 + 2 * VFS_CAP_U32_2);
2931
2932pub const XATTR_CAPS_SZ = XATTR_CAPS_SZ_2;
2933pub const VFS_CAP_U32 = VFS_CAP_U32_2;
2934pub const VFS_CAP_REVISION = VFS_CAP_REVISION_2;
2935
2936pub const vfs_cap_data = extern struct {
2937 //all of these are mandated as little endian
2938 //when on disk.
2939 const Data = struct {
2940 permitted: u32,
2941 inheritable: u32,
2942 };
2943
2944 magic_etc: u32,
2945 data: [VFS_CAP_U32]Data,
2946};
2947
2948pub const CAP = struct {
2949 pub const CHOWN = 0;
2950 pub const DAC_OVERRIDE = 1;
2951 pub const DAC_READ_SEARCH = 2;
2952 pub const FOWNER = 3;
2953 pub const FSETID = 4;
2954 pub const KILL = 5;
2955 pub const SETGID = 6;
2956 pub const SETUID = 7;
2957 pub const SETPCAP = 8;
2958 pub const LINUX_IMMUTABLE = 9;
2959 pub const NET_BIND_SERVICE = 10;
2960 pub const NET_BROADCAST = 11;
2961 pub const NET_ADMIN = 12;
2962 pub const NET_RAW = 13;
2963 pub const IPC_LOCK = 14;
2964 pub const IPC_OWNER = 15;
2965 pub const SYS_MODULE = 16;
2966 pub const SYS_RAWIO = 17;
2967 pub const SYS_CHROOT = 18;
2968 pub const SYS_PTRACE = 19;
2969 pub const SYS_PACCT = 20;
2970 pub const SYS_ADMIN = 21;
2971 pub const SYS_BOOT = 22;
2972 pub const SYS_NICE = 23;
2973 pub const SYS_RESOURCE = 24;
2974 pub const SYS_TIME = 25;
2975 pub const SYS_TTY_CONFIG = 26;
2976 pub const MKNOD = 27;
2977 pub const LEASE = 28;
2978 pub const AUDIT_WRITE = 29;
2979 pub const AUDIT_CONTROL = 30;
2980 pub const SETFCAP = 31;
2981 pub const MAC_OVERRIDE = 32;
2982 pub const MAC_ADMIN = 33;
2983 pub const SYSLOG = 34;
2984 pub const WAKE_ALARM = 35;
2985 pub const BLOCK_SUSPEND = 36;
2986 pub const AUDIT_READ = 37;
2987 pub const LAST_CAP = AUDIT_READ;
2988
2989 pub fn valid(x: u8) bool {
2990 return x >= 0 and x <= LAST_CAP;
2991 }
2992
2993 pub fn TO_MASK(cap: u8) u32 {
2994 return @as(u32, 1) << @intCast(u5, cap & 31);
2995 }
2996
2997 pub fn TO_INDEX(cap: u8) u8 {
2998 return cap >> 5;
2999 }
3000};
3001
3002pub const cap_t = extern struct {
3003 hdrp: *cap_user_header_t,
3004 datap: *cap_user_data_t,
3005};
3006
3007pub const cap_user_header_t = extern struct {
3008 version: u32,
3009 pid: usize,
3010};
3011
3012pub const cap_user_data_t = extern struct {
3013 effective: u32,
3014 permitted: u32,
3015 inheritable: u32,
3016};
3017
3018pub const inotify_event = extern struct {
3019 wd: i32,
3020 mask: u32,
3021 cookie: u32,
3022 len: u32,
3023 //name: [?]u8,
3024};
3025
3026pub const dirent64 = extern struct {
3027 d_ino: u64,
3028 d_off: u64,
3029 d_reclen: u16,
3030 d_type: u8,
3031 d_name: u8, // field address is the address of first byte of name https://github.com/ziglang/zig/issues/173
3032
3033 pub fn reclen(self: dirent64) u16 {
3034 return self.d_reclen;
3035 }
3036};
3037
3038pub const dl_phdr_info = extern struct {
3039 dlpi_addr: usize,
3040 dlpi_name: ?[*:0]const u8,
3041 dlpi_phdr: [*]std.elf.Phdr,
3042 dlpi_phnum: u16,
3043};
3044
3045pub const CPU_SETSIZE = 128;
3046pub const cpu_set_t = [CPU_SETSIZE / @sizeOf(usize)]usize;
3047pub const cpu_count_t = std.meta.Int(.unsigned, std.math.log2(CPU_SETSIZE * 8));
3048
3049pub fn CPU_COUNT(set: cpu_set_t) cpu_count_t {
3050 var sum: cpu_count_t = 0;
3051 for (set) |x| {
3052 sum += @popCount(usize, x);
1537 }3053 }
3054 return sum;
1538}3055}
3056
3057pub const MINSIGSTKSZ = switch (native_arch) {
3058 .i386, .x86_64, .arm, .mipsel => 2048,
3059 .aarch64 => 5120,
3060 else => @compileError("MINSIGSTKSZ not defined for this architecture"),
3061};
3062pub const SIGSTKSZ = switch (native_arch) {
3063 .i386, .x86_64, .arm, .mipsel => 8192,
3064 .aarch64 => 16384,
3065 else => @compileError("SIGSTKSZ not defined for this architecture"),
3066};
3067
3068pub const SS_ONSTACK = 1;
3069pub const SS_DISABLE = 2;
3070pub const SS_AUTODISARM = 1 << 31;
3071
3072pub const stack_t = if (is_mips)
3073 // IRIX compatible stack_t
3074 extern struct {
3075 ss_sp: [*]u8,
3076 ss_size: usize,
3077 ss_flags: i32,
3078 }
3079else
3080 extern struct {
3081 ss_sp: [*]u8,
3082 ss_flags: i32,
3083 ss_size: usize,
3084 };
3085
3086pub const sigval = extern union {
3087 int: i32,
3088 ptr: *c_void,
3089};
3090
3091const siginfo_fields_union = extern union {
3092 pad: [128 - 2 * @sizeOf(c_int) - @sizeOf(c_long)]u8,
3093 common: extern struct {
3094 first: extern union {
3095 piduid: extern struct {
3096 pid: pid_t,
3097 uid: uid_t,
3098 },
3099 timer: extern struct {
3100 timerid: i32,
3101 overrun: i32,
3102 },
3103 },
3104 second: extern union {
3105 value: sigval,
3106 sigchld: extern struct {
3107 status: i32,
3108 utime: clock_t,
3109 stime: clock_t,
3110 },
3111 },
3112 },
3113 sigfault: extern struct {
3114 addr: *c_void,
3115 addr_lsb: i16,
3116 first: extern union {
3117 addr_bnd: extern struct {
3118 lower: *c_void,
3119 upper: *c_void,
3120 },
3121 pkey: u32,
3122 },
3123 },
3124 sigpoll: extern struct {
3125 band: isize,
3126 fd: i32,
3127 },
3128 sigsys: extern struct {
3129 call_addr: *c_void,
3130 syscall: i32,
3131 native_arch: u32,
3132 },
3133};
3134
3135pub const siginfo_t = if (is_mips)
3136 extern struct {
3137 signo: i32,
3138 code: i32,
3139 errno: i32,
3140 fields: siginfo_fields_union,
3141 }
3142else
3143 extern struct {
3144 signo: i32,
3145 errno: i32,
3146 code: i32,
3147 fields: siginfo_fields_union,
3148 };
3149
3150pub const io_uring_params = extern struct {
3151 sq_entries: u32,
3152 cq_entries: u32,
3153 flags: u32,
3154 sq_thread_cpu: u32,
3155 sq_thread_idle: u32,
3156 features: u32,
3157 wq_fd: u32,
3158 resv: [3]u32,
3159 sq_off: io_sqring_offsets,
3160 cq_off: io_cqring_offsets,
3161};
3162
3163// io_uring_params.features flags
3164
3165pub const IORING_FEAT_SINGLE_MMAP = 1 << 0;
3166pub const IORING_FEAT_NODROP = 1 << 1;
3167pub const IORING_FEAT_SUBMIT_STABLE = 1 << 2;
3168pub const IORING_FEAT_RW_CUR_POS = 1 << 3;
3169pub const IORING_FEAT_CUR_PERSONALITY = 1 << 4;
3170pub const IORING_FEAT_FAST_POLL = 1 << 5;
3171pub const IORING_FEAT_POLL_32BITS = 1 << 6;
3172
3173// io_uring_params.flags
3174
3175/// io_context is polled
3176pub const IORING_SETUP_IOPOLL = 1 << 0;
3177
3178/// SQ poll thread
3179pub const IORING_SETUP_SQPOLL = 1 << 1;
3180
3181/// sq_thread_cpu is valid
3182pub const IORING_SETUP_SQ_AFF = 1 << 2;
3183
3184/// app defines CQ size
3185pub const IORING_SETUP_CQSIZE = 1 << 3;
3186
3187/// clamp SQ/CQ ring sizes
3188pub const IORING_SETUP_CLAMP = 1 << 4;
3189
3190/// attach to existing wq
3191pub const IORING_SETUP_ATTACH_WQ = 1 << 5;
3192
3193/// start with ring disabled
3194pub const IORING_SETUP_R_DISABLED = 1 << 6;
3195
3196pub const io_sqring_offsets = extern struct {
3197 /// offset of ring head
3198 head: u32,
3199
3200 /// offset of ring tail
3201 tail: u32,
3202
3203 /// ring mask value
3204 ring_mask: u32,
3205
3206 /// entries in ring
3207 ring_entries: u32,
3208
3209 /// ring flags
3210 flags: u32,
3211
3212 /// number of sqes not submitted
3213 dropped: u32,
3214
3215 /// sqe index array
3216 array: u32,
3217
3218 resv1: u32,
3219 resv2: u64,
3220};
3221
3222// io_sqring_offsets.flags
3223
3224/// needs io_uring_enter wakeup
3225pub const IORING_SQ_NEED_WAKEUP = 1 << 0;
3226
3227/// kernel has cqes waiting beyond the cq ring
3228pub const IORING_SQ_CQ_OVERFLOW = 1 << 1;
3229
3230pub const io_cqring_offsets = extern struct {
3231 head: u32,
3232 tail: u32,
3233 ring_mask: u32,
3234 ring_entries: u32,
3235 overflow: u32,
3236 cqes: u32,
3237 resv: [2]u64,
3238};
3239
3240pub const io_uring_sqe = extern struct {
3241 opcode: IORING_OP,
3242 flags: u8,
3243 ioprio: u16,
3244 fd: i32,
3245 off: u64,
3246 addr: u64,
3247 len: u32,
3248 rw_flags: u32,
3249 user_data: u64,
3250 buf_index: u16,
3251 personality: u16,
3252 splice_fd_in: i32,
3253 __pad2: [2]u64,
3254};
3255
3256pub const IOSQE_BIT = enum(u8) {
3257 FIXED_FILE,
3258 IO_DRAIN,
3259 IO_LINK,
3260 IO_HARDLINK,
3261 ASYNC,
3262 BUFFER_SELECT,
3263
3264 _,
3265};
3266
3267// io_uring_sqe.flags
3268
3269/// use fixed fileset
3270pub const IOSQE_FIXED_FILE = 1 << @enumToInt(IOSQE_BIT.FIXED_FILE);
3271
3272/// issue after inflight IO
3273pub const IOSQE_IO_DRAIN = 1 << @enumToInt(IOSQE_BIT.IO_DRAIN);
3274
3275/// links next sqe
3276pub const IOSQE_IO_LINK = 1 << @enumToInt(IOSQE_BIT.IO_LINK);
3277
3278/// like LINK, but stronger
3279pub const IOSQE_IO_HARDLINK = 1 << @enumToInt(IOSQE_BIT.IO_HARDLINK);
3280
3281/// always go async
3282pub const IOSQE_ASYNC = 1 << @enumToInt(IOSQE_BIT.ASYNC);
3283
3284/// select buffer from buf_group
3285pub const IOSQE_BUFFER_SELECT = 1 << @enumToInt(IOSQE_BIT.BUFFER_SELECT);
3286
3287pub const IORING_OP = enum(u8) {
3288 NOP,
3289 READV,
3290 WRITEV,
3291 FSYNC,
3292 READ_FIXED,
3293 WRITE_FIXED,
3294 POLL_ADD,
3295 POLL_REMOVE,
3296 SYNC_FILE_RANGE,
3297 SENDMSG,
3298 RECVMSG,
3299 TIMEOUT,
3300 TIMEOUT_REMOVE,
3301 ACCEPT,
3302 ASYNC_CANCEL,
3303 LINK_TIMEOUT,
3304 CONNECT,
3305 FALLOCATE,
3306 OPENAT,
3307 CLOSE,
3308 FILES_UPDATE,
3309 STATX,
3310 READ,
3311 WRITE,
3312 FADVISE,
3313 MADVISE,
3314 SEND,
3315 RECV,
3316 OPENAT2,
3317 EPOLL_CTL,
3318 SPLICE,
3319 PROVIDE_BUFFERS,
3320 REMOVE_BUFFERS,
3321 TEE,
3322
3323 _,
3324};
3325
3326// io_uring_sqe.fsync_flags
3327pub const IORING_FSYNC_DATASYNC = 1 << 0;
3328
3329// io_uring_sqe.timeout_flags
3330pub const IORING_TIMEOUT_ABS = 1 << 0;
3331
3332// IO completion data structure (Completion Queue Entry)
3333pub const io_uring_cqe = extern struct {
3334 /// io_uring_sqe.data submission passed back
3335 user_data: u64,
3336
3337 /// result code for this event
3338 res: i32,
3339 flags: u32,
3340
3341 pub fn err(self: io_uring_cqe) E {
3342 if (self.res > -4096 and self.res < 0) {
3343 return @intToEnum(E, -self.res);
3344 }
3345 return .SUCCESS;
3346 }
3347};
3348
3349// io_uring_cqe.flags
3350
3351/// If set, the upper 16 bits are the buffer ID
3352pub const IORING_CQE_F_BUFFER = 1 << 0;
3353
3354pub const IORING_OFF_SQ_RING = 0;
3355pub const IORING_OFF_CQ_RING = 0x8000000;
3356pub const IORING_OFF_SQES = 0x10000000;
3357
3358// io_uring_enter flags
3359pub const IORING_ENTER_GETEVENTS = 1 << 0;
3360pub const IORING_ENTER_SQ_WAKEUP = 1 << 1;
3361
3362// io_uring_register opcodes and arguments
3363pub const IORING_REGISTER = enum(u8) {
3364 REGISTER_BUFFERS,
3365 UNREGISTER_BUFFERS,
3366 REGISTER_FILES,
3367 UNREGISTER_FILES,
3368 REGISTER_EVENTFD,
3369 UNREGISTER_EVENTFD,
3370 REGISTER_FILES_UPDATE,
3371 REGISTER_EVENTFD_ASYNC,
3372 REGISTER_PROBE,
3373 REGISTER_PERSONALITY,
3374 UNREGISTER_PERSONALITY,
3375 REGISTER_RESTRICTIONS,
3376 REGISTER_ENABLE_RINGS,
3377
3378 _,
3379};
3380
3381pub const io_uring_files_update = extern struct {
3382 offset: u32,
3383 resv: u32,
3384 fds: u64,
3385};
3386
3387pub const IO_URING_OP_SUPPORTED = 1 << 0;
3388
3389pub const io_uring_probe_op = extern struct {
3390 op: IORING_OP,
3391
3392 resv: u8,
3393
3394 /// IO_URING_OP_* flags
3395 flags: u16,
3396
3397 resv2: u32,
3398};
3399
3400pub const io_uring_probe = extern struct {
3401 /// last opcode supported
3402 last_op: IORING_OP,
3403
3404 /// Number of io_uring_probe_op following
3405 ops_len: u8,
3406
3407 resv: u16,
3408 resv2: u32[3],
3409
3410 // Followed by up to `ops_len` io_uring_probe_op structures
3411};
3412
3413pub const io_uring_restriction = extern struct {
3414 opcode: u16,
3415 arg: extern union {
3416 /// IORING_RESTRICTION_REGISTER_OP
3417 register_op: IORING_REGISTER,
3418
3419 /// IORING_RESTRICTION_SQE_OP
3420 sqe_op: IORING_OP,
3421
3422 /// IORING_RESTRICTION_SQE_FLAGS_*
3423 sqe_flags: u8,
3424 },
3425 resv: u8,
3426 resv2: u32[3],
3427};
3428
3429/// io_uring_restriction->opcode values
3430pub const IORING_RESTRICTION = enum(u8) {
3431 /// Allow an io_uring_register(2) opcode
3432 REGISTER_OP = 0,
3433
3434 /// Allow an sqe opcode
3435 SQE_OP = 1,
3436
3437 /// Allow sqe flags
3438 SQE_FLAGS_ALLOWED = 2,
3439
3440 /// Require sqe flags (these flags must be set on each submission)
3441 SQE_FLAGS_REQUIRED = 3,
3442
3443 _,
3444};
3445
3446pub const utsname = extern struct {
3447 sysname: [64:0]u8,
3448 nodename: [64:0]u8,
3449 release: [64:0]u8,
3450 version: [64:0]u8,
3451 machine: [64:0]u8,
3452 domainname: [64:0]u8,
3453};
3454pub const HOST_NAME_MAX = 64;
3455
3456pub const STATX_TYPE = 0x0001;
3457pub const STATX_MODE = 0x0002;
3458pub const STATX_NLINK = 0x0004;
3459pub const STATX_UID = 0x0008;
3460pub const STATX_GID = 0x0010;
3461pub const STATX_ATIME = 0x0020;
3462pub const STATX_MTIME = 0x0040;
3463pub const STATX_CTIME = 0x0080;
3464pub const STATX_INO = 0x0100;
3465pub const STATX_SIZE = 0x0200;
3466pub const STATX_BLOCKS = 0x0400;
3467pub const STATX_BASIC_STATS = 0x07ff;
3468
3469pub const STATX_BTIME = 0x0800;
3470
3471pub const STATX_ATTR_COMPRESSED = 0x0004;
3472pub const STATX_ATTR_IMMUTABLE = 0x0010;
3473pub const STATX_ATTR_APPEND = 0x0020;
3474pub const STATX_ATTR_NODUMP = 0x0040;
3475pub const STATX_ATTR_ENCRYPTED = 0x0800;
3476pub const STATX_ATTR_AUTOMOUNT = 0x1000;
3477
3478pub const statx_timestamp = extern struct {
3479 tv_sec: i64,
3480 tv_nsec: u32,
3481 __pad1: u32,
3482};
3483
3484/// Renamed to `Statx` to not conflict with the `statx` function.
3485pub const Statx = extern struct {
3486 /// Mask of bits indicating filled fields
3487 mask: u32,
3488
3489 /// Block size for filesystem I/O
3490 blksize: u32,
3491
3492 /// Extra file attribute indicators
3493 attributes: u64,
3494
3495 /// Number of hard links
3496 nlink: u32,
3497
3498 /// User ID of owner
3499 uid: uid_t,
3500
3501 /// Group ID of owner
3502 gid: gid_t,
3503
3504 /// File type and mode
3505 mode: u16,
3506 __pad1: u16,
3507
3508 /// Inode number
3509 ino: u64,
3510
3511 /// Total size in bytes
3512 size: u64,
3513
3514 /// Number of 512B blocks allocated
3515 blocks: u64,
3516
3517 /// Mask to show what's supported in `attributes`.
3518 attributes_mask: u64,
3519
3520 /// Last access file timestamp
3521 atime: statx_timestamp,
3522
3523 /// Creation file timestamp
3524 btime: statx_timestamp,
3525
3526 /// Last status change file timestamp
3527 ctime: statx_timestamp,
3528
3529 /// Last modification file timestamp
3530 mtime: statx_timestamp,
3531
3532 /// Major ID, if this file represents a device.
3533 rdev_major: u32,
3534
3535 /// Minor ID, if this file represents a device.
3536 rdev_minor: u32,
3537
3538 /// Major ID of the device containing the filesystem where this file resides.
3539 dev_major: u32,
3540
3541 /// Minor ID of the device containing the filesystem where this file resides.
3542 dev_minor: u32,
3543
3544 __pad2: [14]u64,
3545};
3546
3547pub const addrinfo = extern struct {
3548 flags: i32,
3549 family: i32,
3550 socktype: i32,
3551 protocol: i32,
3552 addrlen: socklen_t,
3553 addr: ?*sockaddr,
3554 canonname: ?[*:0]u8,
3555 next: ?*addrinfo,
3556};
3557
3558pub const IPPORT_RESERVED = 1024;
3559
3560pub const IPPROTO_IP = 0;
3561pub const IPPROTO_HOPOPTS = 0;
3562pub const IPPROTO_ICMP = 1;
3563pub const IPPROTO_IGMP = 2;
3564pub const IPPROTO_IPIP = 4;
3565pub const IPPROTO_TCP = 6;
3566pub const IPPROTO_EGP = 8;
3567pub const IPPROTO_PUP = 12;
3568pub const IPPROTO_UDP = 17;
3569pub const IPPROTO_IDP = 22;
3570pub const IPPROTO_TP = 29;
3571pub const IPPROTO_DCCP = 33;
3572pub const IPPROTO_IPV6 = 41;
3573pub const IPPROTO_ROUTING = 43;
3574pub const IPPROTO_FRAGMENT = 44;
3575pub const IPPROTO_RSVP = 46;
3576pub const IPPROTO_GRE = 47;
3577pub const IPPROTO_ESP = 50;
3578pub const IPPROTO_AH = 51;
3579pub const IPPROTO_ICMPV6 = 58;
3580pub const IPPROTO_NONE = 59;
3581pub const IPPROTO_DSTOPTS = 60;
3582pub const IPPROTO_MTP = 92;
3583pub const IPPROTO_BEETPH = 94;
3584pub const IPPROTO_ENCAP = 98;
3585pub const IPPROTO_PIM = 103;
3586pub const IPPROTO_COMP = 108;
3587pub const IPPROTO_SCTP = 132;
3588pub const IPPROTO_MH = 135;
3589pub const IPPROTO_UDPLITE = 136;
3590pub const IPPROTO_MPLS = 137;
3591pub const IPPROTO_RAW = 255;
3592pub const IPPROTO_MAX = 256;
3593
3594pub const RR_A = 1;
3595pub const RR_CNAME = 5;
3596pub const RR_AAAA = 28;
3597
3598/// Turn off Nagle's algorithm
3599pub const TCP_NODELAY = 1;
3600/// Limit MSS
3601pub const TCP_MAXSEG = 2;
3602/// Never send partially complete segments.
3603pub const TCP_CORK = 3;
3604/// Start keeplives after this period, in seconds
3605pub const TCP_KEEPIDLE = 4;
3606/// Interval between keepalives
3607pub const TCP_KEEPINTVL = 5;
3608/// Number of keepalives before death
3609pub const TCP_KEEPCNT = 6;
3610/// Number of SYN retransmits
3611pub const TCP_SYNCNT = 7;
3612/// Life time of orphaned FIN-WAIT-2 state
3613pub const TCP_LINGER2 = 8;
3614/// Wake up listener only when data arrive
3615pub const TCP_DEFER_ACCEPT = 9;
3616/// Bound advertised window
3617pub const TCP_WINDOW_CLAMP = 10;
3618/// Information about this connection.
3619pub const TCP_INFO = 11;
3620/// Block/reenable quick acks
3621pub const TCP_QUICKACK = 12;
3622/// Congestion control algorithm
3623pub const TCP_CONGESTION = 13;
3624/// TCP MD5 Signature (RFC2385)
3625pub const TCP_MD5SIG = 14;
3626/// Use linear timeouts for thin streams
3627pub const TCP_THIN_LINEAR_TIMEOUTS = 16;
3628/// Fast retrans. after 1 dupack
3629pub const TCP_THIN_DUPACK = 17;
3630/// How long for loss retry before timeout
3631pub const TCP_USER_TIMEOUT = 18;
3632/// TCP sock is under repair right now
3633pub const TCP_REPAIR = 19;
3634pub const TCP_REPAIR_QUEUE = 20;
3635pub const TCP_QUEUE_SEQ = 21;
3636pub const TCP_REPAIR_OPTIONS = 22;
3637/// Enable FastOpen on listeners
3638pub const TCP_FASTOPEN = 23;
3639pub const TCP_TIMESTAMP = 24;
3640/// limit number of unsent bytes in write queue
3641pub const TCP_NOTSENT_LOWAT = 25;
3642/// Get Congestion Control (optional) info
3643pub const TCP_CC_INFO = 26;
3644/// Record SYN headers for new connections
3645pub const TCP_SAVE_SYN = 27;
3646/// Get SYN headers recorded for connection
3647pub const TCP_SAVED_SYN = 28;
3648/// Get/set window parameters
3649pub const TCP_REPAIR_WINDOW = 29;
3650/// Attempt FastOpen with connect
3651pub const TCP_FASTOPEN_CONNECT = 30;
3652/// Attach a ULP to a TCP connection
3653pub const TCP_ULP = 31;
3654/// TCP MD5 Signature with extensions
3655pub const TCP_MD5SIG_EXT = 32;
3656/// Set the key for Fast Open (cookie)
3657pub const TCP_FASTOPEN_KEY = 33;
3658/// Enable TFO without a TFO cookie
3659pub const TCP_FASTOPEN_NO_COOKIE = 34;
3660pub const TCP_ZEROCOPY_RECEIVE = 35;
3661/// Notify bytes available to read as a cmsg on read
3662pub const TCP_INQ = 36;
3663pub const TCP_CM_INQ = TCP_INQ;
3664/// delay outgoing packets by XX usec
3665pub const TCP_TX_DELAY = 37;
3666
3667pub const TCP_REPAIR_ON = 1;
3668pub const TCP_REPAIR_OFF = 0;
3669/// Turn off without window probes
3670pub const TCP_REPAIR_OFF_NO_WP = -1;
3671
3672pub const tcp_repair_opt = extern struct {
3673 opt_code: u32,
3674 opt_val: u32,
3675};
3676
3677pub const tcp_repair_window = extern struct {
3678 snd_wl1: u32,
3679 snd_wnd: u32,
3680 max_window: u32,
3681 rcv_wnd: u32,
3682 rcv_wup: u32,
3683};
3684
3685pub const TcpRepairOption = enum {
3686 TCP_NO_QUEUE,
3687 TCP_RECV_QUEUE,
3688 TCP_SEND_QUEUE,
3689 TCP_QUEUES_NR,
3690};
3691
3692/// why fastopen failed from client perspective
3693pub const tcp_fastopen_client_fail = enum {
3694 /// catch-all
3695 TFO_STATUS_UNSPEC,
3696 /// if not in TFO_CLIENT_NO_COOKIE mode
3697 TFO_COOKIE_UNAVAILABLE,
3698 /// SYN-ACK did not ack SYN data
3699 TFO_DATA_NOT_ACKED,
3700 /// SYN-ACK did not ack SYN data after timeout
3701 TFO_SYN_RETRANSMITTED,
3702};
3703
3704/// for TCP_INFO socket option
3705pub const TCPI_OPT_TIMESTAMPS = 1;
3706pub const TCPI_OPT_SACK = 2;
3707pub const TCPI_OPT_WSCALE = 4;
3708/// ECN was negociated at TCP session init
3709pub const TCPI_OPT_ECN = 8;
3710/// we received at least one packet with ECT
3711pub const TCPI_OPT_ECN_SEEN = 16;
3712/// SYN-ACK acked data in SYN sent or rcvd
3713pub const TCPI_OPT_SYN_DATA = 32;
3714
3715pub const nfds_t = usize;
3716pub const pollfd = extern struct {
3717 fd: fd_t,
3718 events: i16,
3719 revents: i16,
3720};
3721
3722pub const POLLIN = 0x001;
3723pub const POLLPRI = 0x002;
3724pub const POLLOUT = 0x004;
3725pub const POLLERR = 0x008;
3726pub const POLLHUP = 0x010;
3727pub const POLLNVAL = 0x020;
3728pub const POLLRDNORM = 0x040;
3729pub const POLLRDBAND = 0x080;
3730
3731pub const MFD_CLOEXEC = 0x0001;
3732pub const MFD_ALLOW_SEALING = 0x0002;
3733pub const MFD_HUGETLB = 0x0004;
3734pub const MFD_ALL_FLAGS = MFD_CLOEXEC | MFD_ALLOW_SEALING | MFD_HUGETLB;
3735
3736pub const HUGETLB_FLAG_ENCODE_SHIFT = 26;
3737pub const HUGETLB_FLAG_ENCODE_MASK = 0x3f;
3738pub const HUGETLB_FLAG_ENCODE_64KB = 16 << HUGETLB_FLAG_ENCODE_SHIFT;
3739pub const HUGETLB_FLAG_ENCODE_512KB = 19 << HUGETLB_FLAG_ENCODE_SHIFT;
3740pub const HUGETLB_FLAG_ENCODE_1MB = 20 << HUGETLB_FLAG_ENCODE_SHIFT;
3741pub const HUGETLB_FLAG_ENCODE_2MB = 21 << HUGETLB_FLAG_ENCODE_SHIFT;
3742pub const HUGETLB_FLAG_ENCODE_8MB = 23 << HUGETLB_FLAG_ENCODE_SHIFT;
3743pub const HUGETLB_FLAG_ENCODE_16MB = 24 << HUGETLB_FLAG_ENCODE_SHIFT;
3744pub const HUGETLB_FLAG_ENCODE_32MB = 25 << HUGETLB_FLAG_ENCODE_SHIFT;
3745pub const HUGETLB_FLAG_ENCODE_256MB = 28 << HUGETLB_FLAG_ENCODE_SHIFT;
3746pub const HUGETLB_FLAG_ENCODE_512MB = 29 << HUGETLB_FLAG_ENCODE_SHIFT;
3747pub const HUGETLB_FLAG_ENCODE_1GB = 30 << HUGETLB_FLAG_ENCODE_SHIFT;
3748pub const HUGETLB_FLAG_ENCODE_2GB = 31 << HUGETLB_FLAG_ENCODE_SHIFT;
3749pub const HUGETLB_FLAG_ENCODE_16GB = 34 << HUGETLB_FLAG_ENCODE_SHIFT;
3750
3751pub const MFD_HUGE_SHIFT = HUGETLB_FLAG_ENCODE_SHIFT;
3752pub const MFD_HUGE_MASK = HUGETLB_FLAG_ENCODE_MASK;
3753pub const MFD_HUGE_64KB = HUGETLB_FLAG_ENCODE_64KB;
3754pub const MFD_HUGE_512KB = HUGETLB_FLAG_ENCODE_512KB;
3755pub const MFD_HUGE_1MB = HUGETLB_FLAG_ENCODE_1MB;
3756pub const MFD_HUGE_2MB = HUGETLB_FLAG_ENCODE_2MB;
3757pub const MFD_HUGE_8MB = HUGETLB_FLAG_ENCODE_8MB;
3758pub const MFD_HUGE_16MB = HUGETLB_FLAG_ENCODE_16MB;
3759pub const MFD_HUGE_32MB = HUGETLB_FLAG_ENCODE_32MB;
3760pub const MFD_HUGE_256MB = HUGETLB_FLAG_ENCODE_256MB;
3761pub const MFD_HUGE_512MB = HUGETLB_FLAG_ENCODE_512MB;
3762pub const MFD_HUGE_1GB = HUGETLB_FLAG_ENCODE_1GB;
3763pub const MFD_HUGE_2GB = HUGETLB_FLAG_ENCODE_2GB;
3764pub const MFD_HUGE_16GB = HUGETLB_FLAG_ENCODE_16GB;
3765
3766pub const RUSAGE_SELF = 0;
3767pub const RUSAGE_CHILDREN = -1;
3768pub const RUSAGE_THREAD = 1;
3769
3770pub const rusage = extern struct {
3771 utime: timeval,
3772 stime: timeval,
3773 maxrss: isize,
3774 ixrss: isize,
3775 idrss: isize,
3776 isrss: isize,
3777 minflt: isize,
3778 majflt: isize,
3779 nswap: isize,
3780 inblock: isize,
3781 oublock: isize,
3782 msgsnd: isize,
3783 msgrcv: isize,
3784 nsignals: isize,
3785 nvcsw: isize,
3786 nivcsw: isize,
3787 __reserved: [16]isize = [1]isize{0} ** 16,
3788};
3789
3790pub const cc_t = u8;
3791pub const speed_t = u32;
3792pub const tcflag_t = u32;
3793
3794pub const NCCS = 32;
3795
3796pub const B0 = 0o0000000;
3797pub const B50 = 0o0000001;
3798pub const B75 = 0o0000002;
3799pub const B110 = 0o0000003;
3800pub const B134 = 0o0000004;
3801pub const B150 = 0o0000005;
3802pub const B200 = 0o0000006;
3803pub const B300 = 0o0000007;
3804pub const B600 = 0o0000010;
3805pub const B1200 = 0o0000011;
3806pub const B1800 = 0o0000012;
3807pub const B2400 = 0o0000013;
3808pub const B4800 = 0o0000014;
3809pub const B9600 = 0o0000015;
3810pub const B19200 = 0o0000016;
3811pub const B38400 = 0o0000017;
3812pub const BOTHER = 0o0010000;
3813pub const B57600 = 0o0010001;
3814pub const B115200 = 0o0010002;
3815pub const B230400 = 0o0010003;
3816pub const B460800 = 0o0010004;
3817pub const B500000 = 0o0010005;
3818pub const B576000 = 0o0010006;
3819pub const B921600 = 0o0010007;
3820pub const B1000000 = 0o0010010;
3821pub const B1152000 = 0o0010011;
3822pub const B1500000 = 0o0010012;
3823pub const B2000000 = 0o0010013;
3824pub const B2500000 = 0o0010014;
3825pub const B3000000 = 0o0010015;
3826pub const B3500000 = 0o0010016;
3827pub const B4000000 = 0o0010017;
3828
3829pub const V = switch (native_arch) {
3830 .powerpc, .powerpc64, .powerpc64le => struct {
3831 pub const INTR = 0;
3832 pub const QUIT = 1;
3833 pub const ERASE = 2;
3834 pub const KILL = 3;
3835 pub const EOF = 4;
3836 pub const MIN = 5;
3837 pub const EOL = 6;
3838 pub const TIME = 7;
3839 pub const EOL2 = 8;
3840 pub const SWTC = 9;
3841 pub const WERASE = 10;
3842 pub const REPRINT = 11;
3843 pub const SUSP = 12;
3844 pub const START = 13;
3845 pub const STOP = 14;
3846 pub const LNEXT = 15;
3847 pub const DISCARD = 16;
3848 },
3849 .sparc, .sparcv9 => struct {
3850 pub const INTR = 0;
3851 pub const QUIT = 1;
3852 pub const ERASE = 2;
3853 pub const KILL = 3;
3854 pub const EOF = 4;
3855 pub const EOL = 5;
3856 pub const EOL2 = 6;
3857 pub const SWTC = 7;
3858 pub const START = 8;
3859 pub const STOP = 9;
3860 pub const SUSP = 10;
3861 pub const DSUSP = 11;
3862 pub const REPRINT = 12;
3863 pub const DISCARD = 13;
3864 pub const WERASE = 14;
3865 pub const LNEXT = 15;
3866 pub const MIN = VEOF;
3867 pub const TIME = VEOL;
3868 },
3869 .mips, .mipsel, .mips64, .mips64el => struct {
3870 pub const INTR = 0;
3871 pub const QUIT = 1;
3872 pub const ERASE = 2;
3873 pub const KILL = 3;
3874 pub const MIN = 4;
3875 pub const TIME = 5;
3876 pub const EOL2 = 6;
3877 pub const SWTC = 7;
3878 pub const SWTCH = 7;
3879 pub const START = 8;
3880 pub const STOP = 9;
3881 pub const SUSP = 10;
3882 pub const REPRINT = 12;
3883 pub const DISCARD = 13;
3884 pub const WERASE = 14;
3885 pub const LNEXT = 15;
3886 pub const EOF = 16;
3887 pub const EOL = 17;
3888 },
3889 else => struct {
3890 pub const INTR = 0;
3891 pub const QUIT = 1;
3892 pub const ERASE = 2;
3893 pub const KILL = 3;
3894 pub const EOF = 4;
3895 pub const TIME = 5;
3896 pub const MIN = 6;
3897 pub const SWTC = 7;
3898 pub const START = 8;
3899 pub const STOP = 9;
3900 pub const SUSP = 10;
3901 pub const EOL = 11;
3902 pub const REPRINT = 12;
3903 pub const DISCARD = 13;
3904 pub const WERASE = 14;
3905 pub const LNEXT = 15;
3906 pub const EOL2 = 16;
3907 },
3908};
3909
3910pub const IGNBRK = 1;
3911pub const BRKINT = 2;
3912pub const IGNPAR = 4;
3913pub const PARMRK = 8;
3914pub const INPCK = 16;
3915pub const ISTRIP = 32;
3916pub const INLCR = 64;
3917pub const IGNCR = 128;
3918pub const ICRNL = 256;
3919pub const IUCLC = 512;
3920pub const IXON = 1024;
3921pub const IXANY = 2048;
3922pub const IXOFF = 4096;
3923pub const IMAXBEL = 8192;
3924pub const IUTF8 = 16384;
3925
3926pub const OPOST = 1;
3927pub const OLCUC = 2;
3928pub const ONLCR = 4;
3929pub const OCRNL = 8;
3930pub const ONOCR = 16;
3931pub const ONLRET = 32;
3932pub const OFILL = 64;
3933pub const OFDEL = 128;
3934pub const VTDLY = 16384;
3935pub const VT0 = 0;
3936pub const VT1 = 16384;
3937
3938pub const CSIZE = 48;
3939pub const CS5 = 0;
3940pub const CS6 = 16;
3941pub const CS7 = 32;
3942pub const CS8 = 48;
3943pub const CSTOPB = 64;
3944pub const CREAD = 128;
3945pub const PARENB = 256;
3946pub const PARODD = 512;
3947pub const HUPCL = 1024;
3948pub const CLOCAL = 2048;
3949
3950pub const ISIG = 1;
3951pub const ICANON = 2;
3952pub const ECHO = 8;
3953pub const ECHOE = 16;
3954pub const ECHOK = 32;
3955pub const ECHONL = 64;
3956pub const NOFLSH = 128;
3957pub const TOSTOP = 256;
3958pub const IEXTEN = 32768;
3959
3960pub const TCSA = enum(c_uint) {
3961 NOW,
3962 DRAIN,
3963 FLUSH,
3964 _,
3965};
3966
3967pub const termios = extern struct {
3968 iflag: tcflag_t,
3969 oflag: tcflag_t,
3970 cflag: tcflag_t,
3971 lflag: tcflag_t,
3972 line: cc_t,
3973 cc: [NCCS]cc_t,
3974 ispeed: speed_t,
3975 ospeed: speed_t,
3976};
3977
3978pub const SIOCGIFINDEX = 0x8933;
3979pub const IFNAMESIZE = 16;
3980
3981pub const ifmap = extern struct {
3982 mem_start: u32,
3983 mem_end: u32,
3984 base_addr: u16,
3985 irq: u8,
3986 dma: u8,
3987 port: u8,
3988};
3989
3990pub const ifreq = extern struct {
3991 ifrn: extern union {
3992 name: [IFNAMESIZE]u8,
3993 },
3994 ifru: extern union {
3995 addr: sockaddr,
3996 dstaddr: sockaddr,
3997 broadaddr: sockaddr,
3998 netmask: sockaddr,
3999 hwaddr: sockaddr,
4000 flags: i16,
4001 ivalue: i32,
4002 mtu: i32,
4003 map: ifmap,
4004 slave: [IFNAMESIZE - 1:0]u8,
4005 newname: [IFNAMESIZE - 1:0]u8,
4006 data: ?[*]u8,
4007 },
4008};
4009
4010// doc comments copied from musl
4011pub const rlimit_resource = enum(c_int) {
4012 /// Per-process CPU limit, in seconds.
4013 CPU,
4014
4015 /// Largest file that can be created, in bytes.
4016 FSIZE,
4017
4018 /// Maximum size of data segment, in bytes.
4019 DATA,
4020
4021 /// Maximum size of stack segment, in bytes.
4022 STACK,
4023
4024 /// Largest core file that can be created, in bytes.
4025 CORE,
4026
4027 /// Largest resident set size, in bytes.
4028 /// This affects swapping; processes that are exceeding their
4029 /// resident set size will be more likely to have physical memory
4030 /// taken from them.
4031 RSS,
4032
4033 /// Number of processes.
4034 NPROC,
4035
4036 /// Number of open files.
4037 NOFILE,
4038
4039 /// Locked-in-memory address space.
4040 MEMLOCK,
4041
4042 /// Address space limit.
4043 AS,
4044
4045 /// Maximum number of file locks.
4046 LOCKS,
4047
4048 /// Maximum number of pending signals.
4049 SIGPENDING,
4050
4051 /// Maximum bytes in POSIX message queues.
4052 MSGQUEUE,
4053
4054 /// Maximum nice priority allowed to raise to.
4055 /// Nice levels 19 .. -20 correspond to 0 .. 39
4056 /// values of this resource limit.
4057 NICE,
4058
4059 /// Maximum realtime priority allowed for non-priviledged
4060 /// processes.
4061 RTPRIO,
4062
4063 /// Maximum CPU time in µs that a process scheduled under a real-time
4064 /// scheduling policy may consume without making a blocking system
4065 /// call before being forcibly descheduled.
4066 RTTIME,
4067
4068 _,
4069};
4070
4071pub const rlim_t = u64;
4072
4073/// No limit
4074pub const RLIM_INFINITY = ~@as(rlim_t, 0);
4075
4076pub const RLIM_SAVED_MAX = RLIM_INFINITY;
4077pub const RLIM_SAVED_CUR = RLIM_INFINITY;
4078
4079pub const rlimit = extern struct {
4080 /// Soft limit
4081 cur: rlim_t,
4082 /// Hard limit
4083 max: rlim_t,
4084};
4085
4086pub const MADV = struct {
4087 pub const NORMAL = 0;
4088 pub const RANDOM = 1;
4089 pub const SEQUENTIAL = 2;
4090 pub const WILLNEED = 3;
4091 pub const DONTNEED = 4;
4092 pub const FREE = 8;
4093 pub const REMOVE = 9;
4094 pub const DONTFORK = 10;
4095 pub const DOFORK = 11;
4096 pub const MERGEABLE = 12;
4097 pub const UNMERGEABLE = 13;
4098 pub const HUGEPAGE = 14;
4099 pub const NOHUGEPAGE = 15;
4100 pub const DONTDUMP = 16;
4101 pub const DODUMP = 17;
4102 pub const WIPEONFORK = 18;
4103 pub const KEEPONFORK = 19;
4104 pub const COLD = 20;
4105 pub const PAGEOUT = 21;
4106 pub const HWPOISON = 100;
4107 pub const SOFT_OFFLINE = 101;
4108};
4109
4110pub const POSIX_FADV = switch (native_arch) {
4111 .s390x => if (@typeInfo(usize).Int.bits == 64) struct {
4112 pub const NORMAL = 0;
4113 pub const RANDOM = 1;
4114 pub const SEQUENTIAL = 2;
4115 pub const WILLNEED = 3;
4116 pub const DONTNEED = 6;
4117 pub const NOREUSE = 7;
4118 } else struct {
4119 pub const NORMAL = 0;
4120 pub const RANDOM = 1;
4121 pub const SEQUENTIAL = 2;
4122 pub const WILLNEED = 3;
4123 pub const DONTNEED = 4;
4124 pub const NOREUSE = 5;
4125 },
4126 else => struct {
4127 pub const NORMAL = 0;
4128 pub const RANDOM = 1;
4129 pub const SEQUENTIAL = 2;
4130 pub const WILLNEED = 3;
4131 pub const DONTNEED = 4;
4132 pub const NOREUSE = 5;
4133 },
4134};
4135
4136pub const __kernel_timespec = extern struct {
4137 tv_sec: i64,
4138 tv_nsec: i64,
4139};
4140
4141pub const XDP = struct {
4142 pub const SHARED_UMEM = (1 << 0);
4143 pub const COPY = (1 << 1);
4144 pub const ZEROCOPY = (1 << 2);
4145 pub const UMEM_UNALIGNED_CHUNK_FLAG = (1 << 0);
4146 pub const USE_NEED_WAKEUP = (1 << 3);
4147
4148 pub const MMAP_OFFSETS = 1;
4149 pub const RX_RING = 2;
4150 pub const TX_RING = 3;
4151 pub const UMEM_REG = 4;
4152 pub const UMEM_FILL_RING = 5;
4153 pub const UMEM_COMPLETION_RING = 6;
4154 pub const STATISTICS = 7;
4155 pub const OPTIONS = 8;
4156
4157 pub const OPTIONS_ZEROCOPY = (1 << 0);
4158
4159 pub const PGOFF_RX_RING = 0;
4160 pub const PGOFF_TX_RING = 0x80000000;
4161 pub const UMEM_PGOFF_FILL_RING = 0x100000000;
4162 pub const UMEM_PGOFF_COMPLETION_RING = 0x180000000;
4163};
4164
4165pub const sockaddr_xdp = extern struct {
4166 family: u16 = AF_XDP,
4167 flags: u16,
4168 ifindex: u32,
4169 queue_id: u32,
4170 shared_umem_fd: u32,
4171};
4172
4173pub const xdp_ring_offset = extern struct {
4174 producer: u64,
4175 consumer: u64,
4176 desc: u64,
4177 flags: u64,
4178};
4179
4180pub const xdp_mmap_offsets = extern struct {
4181 rx: xdp_ring_offset,
4182 tx: xdp_ring_offset,
4183 fr: xdp_ring_offset,
4184 cr: xdp_ring_offset,
4185};
4186
4187pub const xdp_umem_reg = extern struct {
4188 addr: u64,
4189 len: u64,
4190 chunk_size: u32,
4191 headroom: u32,
4192 flags: u32,
4193};
4194
4195pub const xdp_statistics = extern struct {
4196 rx_dropped: u64,
4197 rx_invalid_descs: u64,
4198 tx_invalid_descs: u64,
4199 rx_ring_full: u64,
4200 rx_fill_ring_empty_descs: u64,
4201 tx_ring_empty_descs: u64,
4202};
4203
4204pub const xdp_options = extern struct {
4205 flags: u32,
4206};
4207
4208pub const XSK_UNALIGNED_BUF_OFFSET_SHIFT = 48;
4209pub const XSK_UNALIGNED_BUF_ADDR_MASK = (1 << XSK_UNALIGNED_BUF_OFFSET_SHIFT) - 1;
4210
4211pub const xdp_desc = extern struct {
4212 addr: u64,
4213 len: u32,
4214 options: u32,
4215};
4216
4217fn issecure_mask(comptime x: comptime_int) comptime_int {
4218 return 1 << x;
4219}
4220
4221pub const SECUREBITS_DEFAULT = 0x00000000;
4222
4223pub const SECURE_NOROOT = 0;
4224pub const SECURE_NOROOT_LOCKED = 1;
4225
4226pub const SECBIT_NOROOT = issecure_mask(SECURE_NOROOT);
4227pub const SECBIT_NOROOT_LOCKED = issecure_mask(SECURE_NOROOT_LOCKED);
4228
4229pub const SECURE_NO_SETUID_FIXUP = 2;
4230pub const SECURE_NO_SETUID_FIXUP_LOCKED = 3;
4231
4232pub const SECBIT_NO_SETUID_FIXUP = issecure_mask(SECURE_NO_SETUID_FIXUP);
4233pub const SECBIT_NO_SETUID_FIXUP_LOCKED = issecure_mask(SECURE_NO_SETUID_FIXUP_LOCKED);
4234
4235pub const SECURE_KEEP_CAPS = 4;
4236pub const SECURE_KEEP_CAPS_LOCKED = 5;
4237
4238pub const SECBIT_KEEP_CAPS = issecure_mask(SECURE_KEEP_CAPS);
4239pub const SECBIT_KEEP_CAPS_LOCKED = issecure_mask(SECURE_KEEP_CAPS_LOCKED);
4240
4241pub const SECURE_NO_CAP_AMBIENT_RAISE = 6;
4242pub const SECURE_NO_CAP_AMBIENT_RAISE_LOCKED = 7;
4243
4244pub const SECBIT_NO_CAP_AMBIENT_RAISE = issecure_mask(SECURE_NO_CAP_AMBIENT_RAISE);
4245pub const SECBIT_NO_CAP_AMBIENT_RAISE_LOCKED = issecure_mask(SECURE_NO_CAP_AMBIENT_RAISE_LOCKED);
4246
4247pub const SECURE_ALL_BITS = issecure_mask(SECURE_NOROOT) |
4248 issecure_mask(SECURE_NO_SETUID_FIXUP) |
4249 issecure_mask(SECURE_KEEP_CAPS) |
4250 issecure_mask(SECURE_NO_CAP_AMBIENT_RAISE);
4251pub const SECURE_ALL_LOCKS = SECURE_ALL_BITS << 1;
4252
4253pub const PR = enum(i32) {
4254 SET_PDEATHSIG = 1,
4255 GET_PDEATHSIG = 2,
4256
4257 GET_DUMPABLE = 3,
4258 SET_DUMPABLE = 4,
4259
4260 GET_UNALIGN = 5,
4261 SET_UNALIGN = 6,
4262
4263 GET_KEEPCAPS = 7,
4264 SET_KEEPCAPS = 8,
4265
4266 GET_FPEMU = 9,
4267 SET_FPEMU = 10,
4268
4269 GET_FPEXC = 11,
4270 SET_FPEXC = 12,
4271
4272 GET_TIMING = 13,
4273 SET_TIMING = 14,
4274
4275 SET_NAME = 15,
4276 GET_NAME = 16,
4277
4278 GET_ENDIAN = 19,
4279 SET_ENDIAN = 20,
4280
4281 GET_SECCOMP = 21,
4282 SET_SECCOMP = 22,
4283
4284 CAPBSET_READ = 23,
4285 CAPBSET_DROP = 24,
4286
4287 GET_TSC = 25,
4288 SET_TSC = 26,
4289
4290 GET_SECUREBITS = 27,
4291 SET_SECUREBITS = 28,
4292
4293 SET_TIMERSLACK = 29,
4294 GET_TIMERSLACK = 30,
4295
4296 TASK_PERF_EVENTS_DISABLE = 31,
4297 TASK_PERF_EVENTS_ENABLE = 32,
4298
4299 MCE_KILL = 33,
4300
4301 MCE_KILL_GET = 34,
4302
4303 SET_MM = 35,
4304
4305 SET_PTRACER = 0x59616d61,
4306
4307 SET_CHILD_SUBREAPER = 36,
4308 GET_CHILD_SUBREAPER = 37,
4309
4310 SET_NO_NEW_PRIVS = 38,
4311 GET_NO_NEW_PRIVS = 39,
4312
4313 GET_TID_ADDRESS = 40,
4314
4315 SET_THP_DISABLE = 41,
4316 GET_THP_DISABLE = 42,
4317
4318 MPX_ENABLE_MANAGEMENT = 43,
4319 MPX_DISABLE_MANAGEMENT = 44,
4320
4321 SET_FP_MODE = 45,
4322 GET_FP_MODE = 46,
4323
4324 CAP_AMBIENT = 47,
4325
4326 SVE_SET_VL = 50,
4327 SVE_GET_VL = 51,
4328
4329 GET_SPECULATION_CTRL = 52,
4330 SET_SPECULATION_CTRL = 53,
4331
4332 _,
4333
4334 pub const UNALIGN_NOPRINT = 1;
4335 pub const UNALIGN_SIGBUS = 2;
4336
4337 pub const FPEMU_NOPRINT = 1;
4338 pub const FPEMU_SIGFPE = 2;
4339
4340 pub const FP_EXC_SW_ENABLE = 0x80;
4341 pub const FP_EXC_DIV = 0x010000;
4342 pub const FP_EXC_OVF = 0x020000;
4343 pub const FP_EXC_UND = 0x040000;
4344 pub const FP_EXC_RES = 0x080000;
4345 pub const FP_EXC_INV = 0x100000;
4346 pub const FP_EXC_DISABLED = 0;
4347 pub const FP_EXC_NONRECOV = 1;
4348 pub const FP_EXC_ASYNC = 2;
4349 pub const FP_EXC_PRECISE = 3;
4350
4351 pub const TIMING_STATISTICAL = 0;
4352 pub const TIMING_TIMESTAMP = 1;
4353
4354 pub const ENDIAN_BIG = 0;
4355 pub const ENDIAN_LITTLE = 1;
4356 pub const ENDIAN_PPC_LITTLE = 2;
4357
4358 pub const TSC_ENABLE = 1;
4359 pub const TSC_SIGSEGV = 2;
4360
4361 pub const MCE_KILL_CLEAR = 0;
4362 pub const MCE_KILL_SET = 1;
4363
4364 pub const MCE_KILL_LATE = 0;
4365 pub const MCE_KILL_EARLY = 1;
4366 pub const MCE_KILL_DEFAULT = 2;
4367
4368 pub const SET_MM_START_CODE = 1;
4369 pub const SET_MM_END_CODE = 2;
4370 pub const SET_MM_START_DATA = 3;
4371 pub const SET_MM_END_DATA = 4;
4372 pub const SET_MM_START_STACK = 5;
4373 pub const SET_MM_START_BRK = 6;
4374 pub const SET_MM_BRK = 7;
4375 pub const SET_MM_ARG_START = 8;
4376 pub const SET_MM_ARG_END = 9;
4377 pub const SET_MM_ENV_START = 10;
4378 pub const SET_MM_ENV_END = 11;
4379 pub const SET_MM_AUXV = 12;
4380 pub const SET_MM_EXE_FILE = 13;
4381 pub const SET_MM_MAP = 14;
4382 pub const SET_MM_MAP_SIZE = 15;
4383
4384 pub const SET_PTRACER_ANY = std.math.maxInt(c_ulong);
4385
4386 pub const FP_MODE_FR = 1 << 0;
4387 pub const FP_MODE_FRE = 1 << 1;
4388
4389 pub const CAP_AMBIENT_IS_SET = 1;
4390 pub const CAP_AMBIENT_RAISE = 2;
4391 pub const CAP_AMBIENT_LOWER = 3;
4392 pub const CAP_AMBIENT_CLEAR_ALL = 4;
4393
4394 pub const SVE_SET_VL_ONEXEC = 1 << 18;
4395 pub const SVE_VL_LEN_MASK = 0xffff;
4396 pub const SVE_VL_INHERIT = 1 << 17;
4397
4398 pub const SPEC_STORE_BYPASS = 0;
4399 pub const SPEC_NOT_AFFECTED = 0;
4400 pub const SPEC_PRCTL = 1 << 0;
4401 pub const SPEC_ENABLE = 1 << 1;
4402 pub const SPEC_DISABLE = 1 << 2;
4403 pub const SPEC_FORCE_DISABLE = 1 << 3;
4404};
4405
4406pub const prctl_mm_map = extern struct {
4407 start_code: u64,
4408 end_code: u64,
4409 start_data: u64,
4410 end_data: u64,
4411 start_brk: u64,
4412 brk: u64,
4413 start_stack: u64,
4414 arg_start: u64,
4415 arg_end: u64,
4416 env_start: u64,
4417 env_end: u64,
4418 auxv: *u64,
4419 auxv_size: u32,
4420 exe_fd: u32,
4421};
4422
4423pub const NETLINK = struct {
4424
4425 /// Routing/device hook
4426 pub const ROUTE = 0;
4427
4428 /// Unused number
4429 pub const UNUSED = 1;
4430
4431 /// Reserved for user mode socket protocols
4432 pub const USERSOCK = 2;
4433
4434 /// Unused number, formerly ip_queue
4435 pub const FIREWALL = 3;
4436
4437 /// socket monitoring
4438 pub const SOCK_DIAG = 4;
4439
4440 /// netfilter/iptables ULOG
4441 pub const NFLOG = 5;
4442
4443 /// ipsec
4444 pub const XFRM = 6;
4445
4446 /// SELinux event notifications
4447 pub const SELINUX = 7;
4448
4449 /// Open-iSCSI
4450 pub const ISCSI = 8;
4451
4452 /// auditing
4453 pub const AUDIT = 9;
4454
4455 pub const FIB_LOOKUP = 10;
4456
4457 pub const CONNECTOR = 11;
4458
4459 /// netfilter subsystem
4460 pub const NETFILTER = 12;
4461
4462 pub const IP6_FW = 13;
4463
4464 /// DECnet routing messages
4465 pub const DNRTMSG = 14;
4466
4467 /// Kernel messages to userspace
4468 pub const KOBJECT_UEVENT = 15;
4469
4470 pub const GENERIC = 16;
4471
4472 // leave room for NETLINK_DM (DM Events)
4473
4474 /// SCSI Transports
4475 pub const SCSITRANSPORT = 18;
4476
4477 pub const ECRYPTFS = 19;
4478
4479 pub const RDMA = 20;
4480
4481 /// Crypto layer
4482 pub const CRYPTO = 21;
4483
4484 /// SMC monitoring
4485 pub const SMC = 22;
4486};
4487
4488// Flags values
4489
4490/// It is request message.
4491pub const NLM_F_REQUEST = 0x01;
4492
4493/// Multipart message, terminated by NLMSG_DONE
4494pub const NLM_F_MULTI = 0x02;
4495
4496/// Reply with ack, with zero or error code
4497pub const NLM_F_ACK = 0x04;
4498
4499/// Echo this request
4500pub const NLM_F_ECHO = 0x08;
4501
4502/// Dump was inconsistent due to sequence change
4503pub const NLM_F_DUMP_INTR = 0x10;
4504
4505/// Dump was filtered as requested
4506pub const NLM_F_DUMP_FILTERED = 0x20;
4507
4508// Modifiers to GET request
4509
4510/// specify tree root
4511pub const NLM_F_ROOT = 0x100;
4512
4513/// return all matching
4514pub const NLM_F_MATCH = 0x200;
4515
4516/// atomic GET
4517pub const NLM_F_ATOMIC = 0x400;
4518pub const NLM_F_DUMP = NLM_F_ROOT | NLM_F_MATCH;
4519
4520// Modifiers to NEW request
4521
4522/// Override existing
4523pub const NLM_F_REPLACE = 0x100;
4524
4525/// Do not touch, if it exists
4526pub const NLM_F_EXCL = 0x200;
4527
4528/// Create, if it does not exist
4529pub const NLM_F_CREATE = 0x400;
4530
4531/// Add to end of list
4532pub const NLM_F_APPEND = 0x800;
4533
4534// Modifiers to DELETE request
4535
4536/// Do not delete recursively
4537pub const NLM_F_NONREC = 0x100;
4538
4539// Flags for ACK message
4540
4541/// request was capped
4542pub const NLM_F_CAPPED = 0x100;
4543
4544/// extended ACK TVLs were included
4545pub const NLM_F_ACK_TLVS = 0x200;
4546
4547pub const NetlinkMessageType = enum(u16) {
4548 /// < 0x10: reserved control messages
4549 pub const MIN_TYPE = 0x10;
4550
4551 /// Nothing.
4552 NOOP = 0x1,
4553
4554 /// Error
4555 ERROR = 0x2,
4556
4557 /// End of a dump
4558 DONE = 0x3,
4559
4560 /// Data lost
4561 OVERRUN = 0x4,
4562
4563 // rtlink types
4564
4565 RTM_NEWLINK = 16,
4566 RTM_DELLINK,
4567 RTM_GETLINK,
4568 RTM_SETLINK,
4569
4570 RTM_NEWADDR = 20,
4571 RTM_DELADDR,
4572 RTM_GETADDR,
4573
4574 RTM_NEWROUTE = 24,
4575 RTM_DELROUTE,
4576 RTM_GETROUTE,
4577
4578 RTM_NEWNEIGH = 28,
4579 RTM_DELNEIGH,
4580 RTM_GETNEIGH,
4581
4582 RTM_NEWRULE = 32,
4583 RTM_DELRULE,
4584 RTM_GETRULE,
4585
4586 RTM_NEWQDISC = 36,
4587 RTM_DELQDISC,
4588 RTM_GETQDISC,
4589
4590 RTM_NEWTCLASS = 40,
4591 RTM_DELTCLASS,
4592 RTM_GETTCLASS,
4593
4594 RTM_NEWTFILTER = 44,
4595 RTM_DELTFILTER,
4596 RTM_GETTFILTER,
4597
4598 RTM_NEWACTION = 48,
4599 RTM_DELACTION,
4600 RTM_GETACTION,
4601
4602 RTM_NEWPREFIX = 52,
4603
4604 RTM_GETMULTICAST = 58,
4605
4606 RTM_GETANYCAST = 62,
4607
4608 RTM_NEWNEIGHTBL = 64,
4609 RTM_GETNEIGHTBL = 66,
4610 RTM_SETNEIGHTBL,
4611
4612 RTM_NEWNDUSEROPT = 68,
4613
4614 RTM_NEWADDRLABEL = 72,
4615 RTM_DELADDRLABEL,
4616 RTM_GETADDRLABEL,
4617
4618 RTM_GETDCB = 78,
4619 RTM_SETDCB,
4620
4621 RTM_NEWNETCONF = 80,
4622 RTM_DELNETCONF,
4623 RTM_GETNETCONF = 82,
4624
4625 RTM_NEWMDB = 84,
4626 RTM_DELMDB = 85,
4627 RTM_GETMDB = 86,
4628
4629 RTM_NEWNSID = 88,
4630 RTM_DELNSID = 89,
4631 RTM_GETNSID = 90,
4632
4633 RTM_NEWSTATS = 92,
4634 RTM_GETSTATS = 94,
4635
4636 RTM_NEWCACHEREPORT = 96,
4637
4638 RTM_NEWCHAIN = 100,
4639 RTM_DELCHAIN,
4640 RTM_GETCHAIN,
4641
4642 RTM_NEWNEXTHOP = 104,
4643 RTM_DELNEXTHOP,
4644 RTM_GETNEXTHOP,
4645
4646 _,
4647};
4648
4649/// Netlink socket address
4650pub const sockaddr_nl = extern struct {
4651 family: sa_family_t = AF_NETLINK,
4652 __pad1: c_ushort = 0,
4653
4654 /// port ID
4655 pid: u32,
4656
4657 /// multicast groups mask
4658 groups: u32,
4659};
4660
4661/// Netlink message header
4662/// Specified in RFC 3549 Section 2.3.2
4663pub const nlmsghdr = extern struct {
4664 /// Length of message including header
4665 len: u32,
4666
4667 /// Message content
4668 @"type": NetlinkMessageType,
4669
4670 /// Additional flags
4671 flags: u16,
4672
4673 /// Sequence number
4674 seq: u32,
4675
4676 /// Sending process port ID
4677 pid: u32,
4678};
4679
4680pub const ifinfomsg = extern struct {
4681 family: u8,
4682 __pad1: u8 = 0,
4683
4684 /// ARPHRD_*
4685 @"type": c_ushort,
4686
4687 /// Link index
4688 index: c_int,
4689
4690 /// IFF_* flags
4691 flags: c_uint,
4692
4693 /// IFF_* change mask
4694 change: c_uint,
4695};
4696
4697pub const rtattr = extern struct {
4698 /// Length of option
4699 len: c_ushort,
4700
4701 /// Type of option
4702 @"type": IFLA,
4703
4704 pub const ALIGNTO = 4;
4705};
4706
4707pub const IFLA = enum(c_ushort) {
4708 UNSPEC,
4709 ADDRESS,
4710 BROADCAST,
4711 IFNAME,
4712 MTU,
4713 LINK,
4714 QDISC,
4715 STATS,
4716 COST,
4717 PRIORITY,
4718 MASTER,
4719
4720 /// Wireless Extension event
4721 WIRELESS,
4722
4723 /// Protocol specific information for a link
4724 PROTINFO,
4725
4726 TXQLEN,
4727 MAP,
4728 WEIGHT,
4729 OPERSTATE,
4730 LINKMODE,
4731 LINKINFO,
4732 NET_NS_PID,
4733 IFALIAS,
4734
4735 /// Number of VFs if device is SR-IOV PF
4736 NUM_VF,
4737
4738 VFINFO_LIST,
4739 STATS64,
4740 VF_PORTS,
4741 PORT_SELF,
4742 AF_SPEC,
4743
4744 /// Group the device belongs to
4745 GROUP,
4746
4747 NET_NS_FD,
4748
4749 /// Extended info mask, VFs, etc
4750 EXT_MASK,
4751
4752 /// Promiscuity count: > 0 means acts PROMISC
4753 PROMISCUITY,
4754
4755 NUM_TX_QUEUES,
4756 NUM_RX_QUEUES,
4757 CARRIER,
4758 PHYS_PORT_ID,
4759 CARRIER_CHANGES,
4760 PHYS_SWITCH_ID,
4761 LINK_NETNSID,
4762 PHYS_PORT_NAME,
4763 PROTO_DOWN,
4764 GSO_MAX_SEGS,
4765 GSO_MAX_SIZE,
4766 PAD,
4767 XDP,
4768 EVENT,
4769
4770 NEW_NETNSID,
4771 IF_NETNSID,
4772
4773 CARRIER_UP_COUNT,
4774 CARRIER_DOWN_COUNT,
4775 NEW_IFINDEX,
4776 MIN_MTU,
4777 MAX_MTU,
4778
4779 _,
4780
4781 pub const TARGET_NETNSID: IFLA = .IF_NETNSID;
4782};
4783
4784pub const rtnl_link_ifmap = extern struct {
4785 mem_start: u64,
4786 mem_end: u64,
4787 base_addr: u64,
4788 irq: u16,
4789 dma: u8,
4790 port: u8,
4791};
4792
4793pub const rtnl_link_stats = extern struct {
4794 /// total packets received
4795 rx_packets: u32,
4796
4797 /// total packets transmitted
4798 tx_packets: u32,
4799
4800 /// total bytes received
4801 rx_bytes: u32,
4802
4803 /// total bytes transmitted
4804 tx_bytes: u32,
4805
4806 /// bad packets received
4807 rx_errors: u32,
4808
4809 /// packet transmit problems
4810 tx_errors: u32,
4811
4812 /// no space in linux buffers
4813 rx_dropped: u32,
4814
4815 /// no space available in linux
4816 tx_dropped: u32,
4817
4818 /// multicast packets received
4819 multicast: u32,
4820
4821 collisions: u32,
4822
4823 // detailed rx_errors
4824
4825 rx_length_errors: u32,
4826
4827 /// receiver ring buff overflow
4828 rx_over_errors: u32,
4829
4830 /// recved pkt with crc error
4831 rx_crc_errors: u32,
4832
4833 /// recv'd frame alignment error
4834 rx_frame_errors: u32,
4835
4836 /// recv'r fifo overrun
4837 rx_fifo_errors: u32,
4838
4839 /// receiver missed packet
4840 rx_missed_errors: u32,
4841
4842 // detailed tx_errors
4843 tx_aborted_errors: u32,
4844 tx_carrier_errors: u32,
4845 tx_fifo_errors: u32,
4846 tx_heartbeat_errors: u32,
4847 tx_window_errors: u32,
4848
4849 // for cslip etc
4850
4851 rx_compressed: u32,
4852 tx_compressed: u32,
4853
4854 /// dropped, no handler found
4855 rx_nohandler: u32,
4856};
4857
4858pub const rtnl_link_stats64 = extern struct {
4859 /// total packets received
4860 rx_packets: u64,
4861
4862 /// total packets transmitted
4863 tx_packets: u64,
4864
4865 /// total bytes received
4866 rx_bytes: u64,
4867
4868 /// total bytes transmitted
4869 tx_bytes: u64,
4870
4871 /// bad packets received
4872 rx_errors: u64,
4873
4874 /// packet transmit problems
4875 tx_errors: u64,
4876
4877 /// no space in linux buffers
4878 rx_dropped: u64,
4879
4880 /// no space available in linux
4881 tx_dropped: u64,
4882
4883 /// multicast packets received
4884 multicast: u64,
4885
4886 collisions: u64,
4887
4888 // detailed rx_errors
4889
4890 rx_length_errors: u64,
4891
4892 /// receiver ring buff overflow
4893 rx_over_errors: u64,
4894
4895 /// recved pkt with crc error
4896 rx_crc_errors: u64,
4897
4898 /// recv'd frame alignment error
4899 rx_frame_errors: u64,
4900
4901 /// recv'r fifo overrun
4902 rx_fifo_errors: u64,
4903
4904 /// receiver missed packet
4905 rx_missed_errors: u64,
4906
4907 // detailed tx_errors
4908 tx_aborted_errors: u64,
4909 tx_carrier_errors: u64,
4910 tx_fifo_errors: u64,
4911 tx_heartbeat_errors: u64,
4912 tx_window_errors: u64,
4913
4914 // for cslip etc
4915
4916 rx_compressed: u64,
4917 tx_compressed: u64,
4918
4919 /// dropped, no handler found
4920 rx_nohandler: u64,
4921};
lib/std/os/linux/arm-eabi.zig-2
...@@ -1,5 +1,3 @@...@@ -1,5 +1,3 @@
1usingnamespace @import("../bits/linux.zig");
2
3pub fn syscall0(number: SYS) usize {1pub fn syscall0(number: SYS) usize {
4 return asm volatile ("svc #0"2 return asm volatile ("svc #0"
5 : [ret] "={r0}" (-> usize),3 : [ret] "={r0}" (-> usize),
lib/std/os/linux/arm64.zig-2
...@@ -1,5 +1,3 @@...@@ -1,5 +1,3 @@
1usingnamespace @import("../bits/linux.zig");
2
3pub fn syscall0(number: SYS) usize {1pub fn syscall0(number: SYS) usize {
4 return asm volatile ("svc #0"2 return asm volatile ("svc #0"
5 : [ret] "={x0}" (-> usize),3 : [ret] "={x0}" (-> usize),
lib/std/os/linux/errno/generic.zig created+460
...@@ -0,0 +1,460 @@
1pub const E = enum(u16) {
2 /// No error occurred.
3 /// Same code used for `NSROK`.
4 SUCCESS = 0,
5
6 /// Operation not permitted
7 PERM = 1,
8
9 /// No such file or directory
10 NOENT = 2,
11
12 /// No such process
13 SRCH = 3,
14
15 /// Interrupted system call
16 INTR = 4,
17
18 /// I/O error
19 IO = 5,
20
21 /// No such device or address
22 NXIO = 6,
23
24 /// Arg list too long
25 @"2BIG" = 7,
26
27 /// Exec format error
28 NOEXEC = 8,
29
30 /// Bad file number
31 BADF = 9,
32
33 /// No child processes
34 CHILD = 10,
35
36 /// Try again
37 /// Also means: WOULDBLOCK: operation would block
38 AGAIN = 11,
39
40 /// Out of memory
41 NOMEM = 12,
42
43 /// Permission denied
44 ACCES = 13,
45
46 /// Bad address
47 FAULT = 14,
48
49 /// Block device required
50 NOTBLK = 15,
51
52 /// Device or resource busy
53 BUSY = 16,
54
55 /// File exists
56 EXIST = 17,
57
58 /// Cross-device link
59 XDEV = 18,
60
61 /// No such device
62 NODEV = 19,
63
64 /// Not a directory
65 NOTDIR = 20,
66
67 /// Is a directory
68 ISDIR = 21,
69
70 /// Invalid argument
71 INVAL = 22,
72
73 /// File table overflow
74 NFILE = 23,
75
76 /// Too many open files
77 MFILE = 24,
78
79 /// Not a typewriter
80 NOTTY = 25,
81
82 /// Text file busy
83 TXTBSY = 26,
84
85 /// File too large
86 FBIG = 27,
87
88 /// No space left on device
89 NOSPC = 28,
90
91 /// Illegal seek
92 SPIPE = 29,
93
94 /// Read-only file system
95 ROFS = 30,
96
97 /// Too many links
98 MLINK = 31,
99
100 /// Broken pipe
101 PIPE = 32,
102
103 /// Math argument out of domain of func
104 DOM = 33,
105
106 /// Math result not representable
107 RANGE = 34,
108
109 /// Resource deadlock would occur
110 DEADLK = 35,
111
112 /// File name too long
113 NAMETOOLONG = 36,
114
115 /// No record locks available
116 NOLCK = 37,
117
118 /// Function not implemented
119 NOSYS = 38,
120
121 /// Directory not empty
122 NOTEMPTY = 39,
123
124 /// Too many symbolic links encountered
125 LOOP = 40,
126
127 /// No message of desired type
128 NOMSG = 42,
129
130 /// Identifier removed
131 IDRM = 43,
132
133 /// Channel number out of range
134 CHRNG = 44,
135
136 /// Level 2 not synchronized
137 L2NSYNC = 45,
138
139 /// Level 3 halted
140 L3HLT = 46,
141
142 /// Level 3 reset
143 L3RST = 47,
144
145 /// Link number out of range
146 LNRNG = 48,
147
148 /// Protocol driver not attached
149 UNATCH = 49,
150
151 /// No CSI structure available
152 NOCSI = 50,
153
154 /// Level 2 halted
155 L2HLT = 51,
156
157 /// Invalid exchange
158 BADE = 52,
159
160 /// Invalid request descriptor
161 BADR = 53,
162
163 /// Exchange full
164 XFULL = 54,
165
166 /// No anode
167 NOANO = 55,
168
169 /// Invalid request code
170 BADRQC = 56,
171
172 /// Invalid slot
173 BADSLT = 57,
174
175 /// Bad font file format
176 BFONT = 59,
177
178 /// Device not a stream
179 NOSTR = 60,
180
181 /// No data available
182 NODATA = 61,
183
184 /// Timer expired
185 TIME = 62,
186
187 /// Out of streams resources
188 NOSR = 63,
189
190 /// Machine is not on the network
191 NONET = 64,
192
193 /// Package not installed
194 NOPKG = 65,
195
196 /// Object is remote
197 REMOTE = 66,
198
199 /// Link has been severed
200 NOLINK = 67,
201
202 /// Advertise error
203 ADV = 68,
204
205 /// Srmount error
206 SRMNT = 69,
207
208 /// Communication error on send
209 COMM = 70,
210
211 /// Protocol error
212 PROTO = 71,
213
214 /// Multihop attempted
215 MULTIHOP = 72,
216
217 /// RFS specific error
218 DOTDOT = 73,
219
220 /// Not a data message
221 BADMSG = 74,
222
223 /// Value too large for defined data type
224 OVERFLOW = 75,
225
226 /// Name not unique on network
227 NOTUNIQ = 76,
228
229 /// File descriptor in bad state
230 BADFD = 77,
231
232 /// Remote address changed
233 REMCHG = 78,
234
235 /// Can not access a needed shared library
236 LIBACC = 79,
237
238 /// Accessing a corrupted shared library
239 LIBBAD = 80,
240
241 /// .lib section in a.out corrupted
242 LIBSCN = 81,
243
244 /// Attempting to link in too many shared libraries
245 LIBMAX = 82,
246
247 /// Cannot exec a shared library directly
248 LIBEXEC = 83,
249
250 /// Illegal byte sequence
251 ILSEQ = 84,
252
253 /// Interrupted system call should be restarted
254 RESTART = 85,
255
256 /// Streams pipe error
257 STRPIPE = 86,
258
259 /// Too many users
260 USERS = 87,
261
262 /// Socket operation on non-socket
263 NOTSOCK = 88,
264
265 /// Destination address required
266 DESTADDRREQ = 89,
267
268 /// Message too long
269 MSGSIZE = 90,
270
271 /// Protocol wrong type for socket
272 PROTOTYPE = 91,
273
274 /// Protocol not available
275 NOPROTOOPT = 92,
276
277 /// Protocol not supported
278 PROTONOSUPPORT = 93,
279
280 /// Socket type not supported
281 SOCKTNOSUPPORT = 94,
282
283 /// Operation not supported on transport endpoint
284 /// This code also means `NOTSUP`.
285 OPNOTSUPP = 95,
286
287 /// Protocol family not supported
288 PFNOSUPPORT = 96,
289
290 /// Address family not supported by protocol
291 AFNOSUPPORT = 97,
292
293 /// Address already in use
294 ADDRINUSE = 98,
295
296 /// Cannot assign requested address
297 ADDRNOTAVAIL = 99,
298
299 /// Network is down
300 NETDOWN = 100,
301
302 /// Network is unreachable
303 NETUNREACH = 101,
304
305 /// Network dropped connection because of reset
306 NETRESET = 102,
307
308 /// Software caused connection abort
309 CONNABORTED = 103,
310
311 /// Connection reset by peer
312 CONNRESET = 104,
313
314 /// No buffer space available
315 NOBUFS = 105,
316
317 /// Transport endpoint is already connected
318 ISCONN = 106,
319
320 /// Transport endpoint is not connected
321 NOTCONN = 107,
322
323 /// Cannot send after transport endpoint shutdown
324 SHUTDOWN = 108,
325
326 /// Too many references: cannot splice
327 TOOMANYREFS = 109,
328
329 /// Connection timed out
330 TIMEDOUT = 110,
331
332 /// Connection refused
333 CONNREFUSED = 111,
334
335 /// Host is down
336 HOSTDOWN = 112,
337
338 /// No route to host
339 HOSTUNREACH = 113,
340
341 /// Operation already in progress
342 ALREADY = 114,
343
344 /// Operation now in progress
345 INPROGRESS = 115,
346
347 /// Stale NFS file handle
348 STALE = 116,
349
350 /// Structure needs cleaning
351 UCLEAN = 117,
352
353 /// Not a XENIX named type file
354 NOTNAM = 118,
355
356 /// No XENIX semaphores available
357 NAVAIL = 119,
358
359 /// Is a named type file
360 ISNAM = 120,
361
362 /// Remote I/O error
363 REMOTEIO = 121,
364
365 /// Quota exceeded
366 DQUOT = 122,
367
368 /// No medium found
369 NOMEDIUM = 123,
370
371 /// Wrong medium type
372 MEDIUMTYPE = 124,
373
374 /// Operation canceled
375 CANCELED = 125,
376
377 /// Required key not available
378 NOKEY = 126,
379
380 /// Key has expired
381 KEYEXPIRED = 127,
382
383 /// Key has been revoked
384 KEYREVOKED = 128,
385
386 /// Key was rejected by service
387 KEYREJECTED = 129,
388
389 // for robust mutexes
390
391 /// Owner died
392 OWNERDEAD = 130,
393
394 /// State not recoverable
395 NOTRECOVERABLE = 131,
396
397 /// Operation not possible due to RF-kill
398 RFKILL = 132,
399
400 /// Memory page has hardware error
401 HWPOISON = 133,
402
403 // nameserver query return codes
404
405 /// DNS server returned answer with no data
406 NSRNODATA = 160,
407
408 /// DNS server claims query was misformatted
409 NSRFORMERR = 161,
410
411 /// DNS server returned general failure
412 NSRSERVFAIL = 162,
413
414 /// Domain name not found
415 NSRNOTFOUND = 163,
416
417 /// DNS server does not implement requested operation
418 NSRNOTIMP = 164,
419
420 /// DNS server refused query
421 NSRREFUSED = 165,
422
423 /// Misformatted DNS query
424 NSRBADQUERY = 166,
425
426 /// Misformatted domain name
427 NSRBADNAME = 167,
428
429 /// Unsupported address family
430 NSRBADFAMILY = 168,
431
432 /// Misformatted DNS reply
433 NSRBADRESP = 169,
434
435 /// Could not contact DNS servers
436 NSRCONNREFUSED = 170,
437
438 /// Timeout while contacting DNS servers
439 NSRTIMEOUT = 171,
440
441 /// End of file
442 NSROF = 172,
443
444 /// Error reading file
445 NSRFILE = 173,
446
447 /// Out of memory
448 NSRNOMEM = 174,
449
450 /// Application terminated lookup
451 NSRDESTRUCTION = 175,
452
453 /// Domain name is too long
454 NSRQUERYDOMAINTOOLONG = 176,
455
456 /// Domain name is too long
457 NSRCNAMELOOP = 177,
458
459 _,
460};
lib/std/os/linux/errno/mips.zig created+141
...@@ -0,0 +1,141 @@
1//! These are MIPS ABI compatible.
2pub const E = enum(i32) {
3 /// No error occurred.
4 SUCCESS = 0,
5
6 PERM = 1,
7 NOENT = 2,
8 SRCH = 3,
9 INTR = 4,
10 IO = 5,
11 NXIO = 6,
12 @"2BIG" = 7,
13 NOEXEC = 8,
14 BADF = 9,
15 CHILD = 10,
16 /// Also used for WOULDBLOCK.
17 AGAIN = 11,
18 NOMEM = 12,
19 ACCES = 13,
20 FAULT = 14,
21 NOTBLK = 15,
22 BUSY = 16,
23 EXIST = 17,
24 XDEV = 18,
25 NODEV = 19,
26 NOTDIR = 20,
27 ISDIR = 21,
28 INVAL = 22,
29 NFILE = 23,
30 MFILE = 24,
31 NOTTY = 25,
32 TXTBSY = 26,
33 FBIG = 27,
34 NOSPC = 28,
35 SPIPE = 29,
36 ROFS = 30,
37 MLINK = 31,
38 PIPE = 32,
39 DOM = 33,
40 RANGE = 34,
41
42 NOMSG = 35,
43 IDRM = 36,
44 CHRNG = 37,
45 L2NSYNC = 38,
46 L3HLT = 39,
47 L3RST = 40,
48 LNRNG = 41,
49 UNATCH = 42,
50 NOCSI = 43,
51 L2HLT = 44,
52 DEADLK = 45,
53 NOLCK = 46,
54 BADE = 50,
55 BADR = 51,
56 XFULL = 52,
57 NOANO = 53,
58 BADRQC = 54,
59 BADSLT = 55,
60 DEADLOCK = 56,
61 BFONT = 59,
62 NOSTR = 60,
63 NODATA = 61,
64 TIME = 62,
65 NOSR = 63,
66 NONET = 64,
67 NOPKG = 65,
68 REMOTE = 66,
69 NOLINK = 67,
70 ADV = 68,
71 SRMNT = 69,
72 COMM = 70,
73 PROTO = 71,
74 DOTDOT = 73,
75 MULTIHOP = 74,
76 BADMSG = 77,
77 NAMETOOLONG = 78,
78 OVERFLOW = 79,
79 NOTUNIQ = 80,
80 BADFD = 81,
81 REMCHG = 82,
82 LIBACC = 83,
83 LIBBAD = 84,
84 LIBSCN = 85,
85 LIBMAX = 86,
86 LIBEXEC = 87,
87 ILSEQ = 88,
88 NOSYS = 89,
89 LOOP = 90,
90 RESTART = 91,
91 STRPIPE = 92,
92 NOTEMPTY = 93,
93 USERS = 94,
94 NOTSOCK = 95,
95 DESTADDRREQ = 96,
96 MSGSIZE = 97,
97 PROTOTYPE = 98,
98 NOPROTOOPT = 99,
99 PROTONOSUPPORT = 120,
100 SOCKTNOSUPPORT = 121,
101 OPNOTSUPP = 122,
102 PFNOSUPPORT = 123,
103 AFNOSUPPORT = 124,
104 ADDRINUSE = 125,
105 ADDRNOTAVAIL = 126,
106 NETDOWN = 127,
107 NETUNREACH = 128,
108 NETRESET = 129,
109 CONNABORTED = 130,
110 CONNRESET = 131,
111 NOBUFS = 132,
112 ISCONN = 133,
113 NOTCONN = 134,
114 UCLEAN = 135,
115 NOTNAM = 137,
116 NAVAIL = 138,
117 ISNAM = 139,
118 REMOTEIO = 140,
119 SHUTDOWN = 143,
120 TOOMANYREFS = 144,
121 TIMEDOUT = 145,
122 CONNREFUSED = 146,
123 HOSTDOWN = 147,
124 HOSTUNREACH = 148,
125 ALREADY = 149,
126 INPROGRESS = 150,
127 STALE = 151,
128 CANCELED = 158,
129 NOMEDIUM = 159,
130 MEDIUMTYPE = 160,
131 NOKEY = 161,
132 KEYEXPIRED = 162,
133 KEYREVOKED = 163,
134 KEYREJECTED = 164,
135 OWNERDEAD = 165,
136 NOTRECOVERABLE = 166,
137 RFKILL = 167,
138 HWPOISON = 168,
139 DQUOT = 1133,
140 _,
141};
lib/std/os/linux/errno/sparc.zig created+144
...@@ -0,0 +1,144 @@
1//! These match the SunOS error numbering scheme.
2pub const E = enum(i32) {
3 /// No error occurred.
4 SUCCESS = 0,
5
6 PERM = 1,
7 NOENT = 2,
8 SRCH = 3,
9 INTR = 4,
10 IO = 5,
11 NXIO = 6,
12 @"2BIG" = 7,
13 NOEXEC = 8,
14 BADF = 9,
15 CHILD = 10,
16 /// Also used for WOULDBLOCK
17 AGAIN = 11,
18 NOMEM = 12,
19 ACCES = 13,
20 FAULT = 14,
21 NOTBLK = 15,
22 BUSY = 16,
23 EXIST = 17,
24 XDEV = 18,
25 NODEV = 19,
26 NOTDIR = 20,
27 ISDIR = 21,
28 INVAL = 22,
29 NFILE = 23,
30 MFILE = 24,
31 NOTTY = 25,
32 TXTBSY = 26,
33 FBIG = 27,
34 NOSPC = 28,
35 SPIPE = 29,
36 ROFS = 30,
37 MLINK = 31,
38 PIPE = 32,
39 DOM = 33,
40 RANGE = 34,
41
42 INPROGRESS = 36,
43 ALREADY = 37,
44 NOTSOCK = 38,
45 DESTADDRREQ = 39,
46 MSGSIZE = 40,
47 PROTOTYPE = 41,
48 NOPROTOOPT = 42,
49 PROTONOSUPPORT = 43,
50 SOCKTNOSUPPORT = 44,
51 /// Also used for NOTSUP
52 OPNOTSUPP = 45,
53 PFNOSUPPORT = 46,
54 AFNOSUPPORT = 47,
55 ADDRINUSE = 48,
56 ADDRNOTAVAIL = 49,
57 NETDOWN = 50,
58 NETUNREACH = 51,
59 NETRESET = 52,
60 CONNABORTED = 53,
61 CONNRESET = 54,
62 NOBUFS = 55,
63 ISCONN = 56,
64 NOTCONN = 57,
65 SHUTDOWN = 58,
66 TOOMANYREFS = 59,
67 TIMEDOUT = 60,
68 CONNREFUSED = 61,
69 LOOP = 62,
70 NAMETOOLONG = 63,
71 HOSTDOWN = 64,
72 HOSTUNREACH = 65,
73 NOTEMPTY = 66,
74 PROCLIM = 67,
75 USERS = 68,
76 DQUOT = 69,
77 STALE = 70,
78 REMOTE = 71,
79 NOSTR = 72,
80 TIME = 73,
81 NOSR = 74,
82 NOMSG = 75,
83 BADMSG = 76,
84 IDRM = 77,
85 DEADLK = 78,
86 NOLCK = 79,
87 NONET = 80,
88 RREMOTE = 81,
89 NOLINK = 82,
90 ADV = 83,
91 SRMNT = 84,
92 COMM = 85,
93 PROTO = 86,
94 MULTIHOP = 87,
95 DOTDOT = 88,
96 REMCHG = 89,
97 NOSYS = 90,
98 STRPIPE = 91,
99 OVERFLOW = 92,
100 BADFD = 93,
101 CHRNG = 94,
102 L2NSYNC = 95,
103 L3HLT = 96,
104 L3RST = 97,
105 LNRNG = 98,
106 UNATCH = 99,
107 NOCSI = 100,
108 L2HLT = 101,
109 BADE = 102,
110 BADR = 103,
111 XFULL = 104,
112 NOANO = 105,
113 BADRQC = 106,
114 BADSLT = 107,
115 DEADLOCK = 108,
116 BFONT = 109,
117 LIBEXEC = 110,
118 NODATA = 111,
119 LIBBAD = 112,
120 NOPKG = 113,
121 LIBACC = 114,
122 NOTUNIQ = 115,
123 RESTART = 116,
124 UCLEAN = 117,
125 NOTNAM = 118,
126 NAVAIL = 119,
127 ISNAM = 120,
128 REMOTEIO = 121,
129 ILSEQ = 122,
130 LIBMAX = 123,
131 LIBSCN = 124,
132 NOMEDIUM = 125,
133 MEDIUMTYPE = 126,
134 CANCELED = 127,
135 NOKEY = 128,
136 KEYEXPIRED = 129,
137 KEYREVOKED = 130,
138 KEYREJECTED = 131,
139 OWNERDEAD = 132,
140 NOTRECOVERABLE = 133,
141 RFKILL = 134,
142 HWPOISON = 135,
143 _,
144};
lib/std/os/linux/i386.zig-2
...@@ -1,5 +1,3 @@...@@ -1,5 +1,3 @@
1usingnamespace @import("../bits/linux.zig");
2
3pub fn syscall0(number: SYS) usize {1pub fn syscall0(number: SYS) usize {
4 return asm volatile ("int $0x80"2 return asm volatile ("int $0x80"
5 : [ret] "={eax}" (-> usize),3 : [ret] "={eax}" (-> usize),
lib/std/os/linux/mips.zig-2
...@@ -1,5 +1,3 @@...@@ -1,5 +1,3 @@
1usingnamespace @import("../bits/linux.zig");
2
3pub fn syscall0(number: SYS) usize {1pub fn syscall0(number: SYS) usize {
4 return asm volatile (2 return asm volatile (
5 \\ syscall3 \\ syscall
lib/std/os/linux/powerpc.zig-2
...@@ -1,5 +1,3 @@...@@ -1,5 +1,3 @@
1usingnamespace @import("../bits/linux.zig");
2
3pub fn syscall0(number: SYS) usize {1pub fn syscall0(number: SYS) usize {
4 return asm volatile (2 return asm volatile (
5 \\ sc3 \\ sc
lib/std/os/linux/powerpc64.zig-2
...@@ -1,5 +1,3 @@...@@ -1,5 +1,3 @@
1usingnamespace @import("../bits/linux.zig");
2
3pub fn syscall0(number: SYS) usize {1pub fn syscall0(number: SYS) usize {
4 return asm volatile (2 return asm volatile (
5 \\ sc3 \\ sc
lib/std/os/linux/riscv64.zig-2
...@@ -1,5 +1,3 @@...@@ -1,5 +1,3 @@
1usingnamespace @import("../bits/linux.zig");
2
3pub fn syscall0(number: SYS) usize {1pub fn syscall0(number: SYS) usize {
4 return asm volatile ("ecall"2 return asm volatile ("ecall"
5 : [ret] "={x10}" (-> usize),3 : [ret] "={x10}" (-> usize),
lib/std/os/linux/sparc64.zig-2
...@@ -1,5 +1,3 @@...@@ -1,5 +1,3 @@
1usingnamespace @import("../bits/linux.zig");
2
3pub fn syscall_pipe(fd: *[2]i32) usize {1pub fn syscall_pipe(fd: *[2]i32) usize {
4 return asm volatile (2 return asm volatile (
5 \\ mov %[arg], %%g33 \\ mov %[arg], %%g3
lib/std/os/linux/tls.zig+3-3
...@@ -135,7 +135,7 @@ pub fn setThreadPointer(addr: usize) void {...@@ -135,7 +135,7 @@ pub fn setThreadPointer(addr: usize) void {
135 );135 );
136 },136 },
137 .x86_64 => {137 .x86_64 => {
138 const rc = std.os.linux.syscall2(.arch_prctl, std.os.linux.ARCH_SET_FS, addr);138 const rc = std.os.linux.syscall2(.arch_prctl, std.os.linux.ARCH.SET_FS, addr);
139 assert(rc == 0);139 assert(rc == 0);
140 },140 },
141 .aarch64 => {141 .aarch64 => {
...@@ -319,8 +319,8 @@ pub fn initStaticTLS(phdrs: []elf.Phdr) void {...@@ -319,8 +319,8 @@ pub fn initStaticTLS(phdrs: []elf.Phdr) void {
319 const alloc_tls_area = os.mmap(319 const alloc_tls_area = os.mmap(
320 null,320 null,
321 tls_image.alloc_size + tls_image.alloc_align - 1,321 tls_image.alloc_size + tls_image.alloc_align - 1,
322 os.PROT_READ | os.PROT_WRITE,322 os.PROT.READ | os.PROT.WRITE,
323 os.MAP_PRIVATE | os.MAP_ANONYMOUS,323 os.MAP.PRIVATE | os.MAP.ANONYMOUS,
324 -1,324 -1,
325 0,325 0,
326 ) catch os.abort();326 ) catch os.abort();
lib/std/os/linux/x86_64.zig+691-1
...@@ -1,4 +1,16 @@...@@ -1,4 +1,16 @@
1usingnamespace @import("../bits/linux.zig");1const std = @import("../../std.zig");
2const linux = std.os.linux;
3
4const pid_t = linux.pid_t;
5const uid_t = linux.uid_t;
6const gid_t = linux.gid_t;
7const clock_t = linux.clock_t;
8const stack_t = linux.stack_t;
9const sigset_t = linux.sigset_t;
10const sockaddr = linux.sockaddr;
11const socklen_t = linux.socklen_t;
12const iovec = linux.iovec;
13const iovec_const = linux.iovec_const;
214
3pub fn syscall0(number: SYS) usize {15pub fn syscall0(number: SYS) usize {
4 return asm volatile ("syscall"16 return asm volatile ("syscall"
...@@ -97,3 +109,681 @@ pub fn restore_rt() callconv(.Naked) void {...@@ -97,3 +109,681 @@ pub fn restore_rt() callconv(.Naked) void {
97 : "rcx", "r11", "memory"109 : "rcx", "r11", "memory"
98 );110 );
99}111}
112
113pub const mode_t = usize;
114pub const time_t = isize;
115
116pub const SYS = enum(usize) {
117 read = 0,
118 write = 1,
119 open = 2,
120 close = 3,
121 stat = 4,
122 fstat = 5,
123 lstat = 6,
124 poll = 7,
125 lseek = 8,
126 mmap = 9,
127 mprotect = 10,
128 munmap = 11,
129 brk = 12,
130 rt_sigaction = 13,
131 rt_sigprocmask = 14,
132 rt_sigreturn = 15,
133 ioctl = 16,
134 pread = 17,
135 pwrite = 18,
136 readv = 19,
137 writev = 20,
138 access = 21,
139 pipe = 22,
140 select = 23,
141 sched_yield = 24,
142 mremap = 25,
143 msync = 26,
144 mincore = 27,
145 madvise = 28,
146 shmget = 29,
147 shmat = 30,
148 shmctl = 31,
149 dup = 32,
150 dup2 = 33,
151 pause = 34,
152 nanosleep = 35,
153 getitimer = 36,
154 alarm = 37,
155 setitimer = 38,
156 getpid = 39,
157 sendfile = 40,
158 socket = 41,
159 connect = 42,
160 accept = 43,
161 sendto = 44,
162 recvfrom = 45,
163 sendmsg = 46,
164 recvmsg = 47,
165 shutdown = 48,
166 bind = 49,
167 listen = 50,
168 getsockname = 51,
169 getpeername = 52,
170 socketpair = 53,
171 setsockopt = 54,
172 getsockopt = 55,
173 clone = 56,
174 fork = 57,
175 vfork = 58,
176 execve = 59,
177 exit = 60,
178 wait4 = 61,
179 kill = 62,
180 uname = 63,
181 semget = 64,
182 semop = 65,
183 semctl = 66,
184 shmdt = 67,
185 msgget = 68,
186 msgsnd = 69,
187 msgrcv = 70,
188 msgctl = 71,
189 fcntl = 72,
190 flock = 73,
191 fsync = 74,
192 fdatasync = 75,
193 truncate = 76,
194 ftruncate = 77,
195 getdents = 78,
196 getcwd = 79,
197 chdir = 80,
198 fchdir = 81,
199 rename = 82,
200 mkdir = 83,
201 rmdir = 84,
202 creat = 85,
203 link = 86,
204 unlink = 87,
205 symlink = 88,
206 readlink = 89,
207 chmod = 90,
208 fchmod = 91,
209 chown = 92,
210 fchown = 93,
211 lchown = 94,
212 umask = 95,
213 gettimeofday = 96,
214 getrlimit = 97,
215 getrusage = 98,
216 sysinfo = 99,
217 times = 100,
218 ptrace = 101,
219 getuid = 102,
220 syslog = 103,
221 getgid = 104,
222 setuid = 105,
223 setgid = 106,
224 geteuid = 107,
225 getegid = 108,
226 setpgid = 109,
227 getppid = 110,
228 getpgrp = 111,
229 setsid = 112,
230 setreuid = 113,
231 setregid = 114,
232 getgroups = 115,
233 setgroups = 116,
234 setresuid = 117,
235 getresuid = 118,
236 setresgid = 119,
237 getresgid = 120,
238 getpgid = 121,
239 setfsuid = 122,
240 setfsgid = 123,
241 getsid = 124,
242 capget = 125,
243 capset = 126,
244 rt_sigpending = 127,
245 rt_sigtimedwait = 128,
246 rt_sigqueueinfo = 129,
247 rt_sigsuspend = 130,
248 sigaltstack = 131,
249 utime = 132,
250 mknod = 133,
251 uselib = 134,
252 personality = 135,
253 ustat = 136,
254 statfs = 137,
255 fstatfs = 138,
256 sysfs = 139,
257 getpriority = 140,
258 setpriority = 141,
259 sched_setparam = 142,
260 sched_getparam = 143,
261 sched_setscheduler = 144,
262 sched_getscheduler = 145,
263 sched_get_priority_max = 146,
264 sched_get_priority_min = 147,
265 sched_rr_get_interval = 148,
266 mlock = 149,
267 munlock = 150,
268 mlockall = 151,
269 munlockall = 152,
270 vhangup = 153,
271 modify_ldt = 154,
272 pivot_root = 155,
273 _sysctl = 156,
274 prctl = 157,
275 arch_prctl = 158,
276 adjtimex = 159,
277 setrlimit = 160,
278 chroot = 161,
279 sync = 162,
280 acct = 163,
281 settimeofday = 164,
282 mount = 165,
283 umount2 = 166,
284 swapon = 167,
285 swapoff = 168,
286 reboot = 169,
287 sethostname = 170,
288 setdomainname = 171,
289 iopl = 172,
290 ioperm = 173,
291 create_module = 174,
292 init_module = 175,
293 delete_module = 176,
294 get_kernel_syms = 177,
295 query_module = 178,
296 quotactl = 179,
297 nfsservctl = 180,
298 getpmsg = 181,
299 putpmsg = 182,
300 afs_syscall = 183,
301 tuxcall = 184,
302 security = 185,
303 gettid = 186,
304 readahead = 187,
305 setxattr = 188,
306 lsetxattr = 189,
307 fsetxattr = 190,
308 getxattr = 191,
309 lgetxattr = 192,
310 fgetxattr = 193,
311 listxattr = 194,
312 llistxattr = 195,
313 flistxattr = 196,
314 removexattr = 197,
315 lremovexattr = 198,
316 fremovexattr = 199,
317 tkill = 200,
318 time = 201,
319 futex = 202,
320 sched_setaffinity = 203,
321 sched_getaffinity = 204,
322 set_thread_area = 205,
323 io_setup = 206,
324 io_destroy = 207,
325 io_getevents = 208,
326 io_submit = 209,
327 io_cancel = 210,
328 get_thread_area = 211,
329 lookup_dcookie = 212,
330 epoll_create = 213,
331 epoll_ctl_old = 214,
332 epoll_wait_old = 215,
333 remap_file_pages = 216,
334 getdents64 = 217,
335 set_tid_address = 218,
336 restart_syscall = 219,
337 semtimedop = 220,
338 fadvise64 = 221,
339 timer_create = 222,
340 timer_settime = 223,
341 timer_gettime = 224,
342 timer_getoverrun = 225,
343 timer_delete = 226,
344 clock_settime = 227,
345 clock_gettime = 228,
346 clock_getres = 229,
347 clock_nanosleep = 230,
348 exit_group = 231,
349 epoll_wait = 232,
350 epoll_ctl = 233,
351 tgkill = 234,
352 utimes = 235,
353 vserver = 236,
354 mbind = 237,
355 set_mempolicy = 238,
356 get_mempolicy = 239,
357 mq_open = 240,
358 mq_unlink = 241,
359 mq_timedsend = 242,
360 mq_timedreceive = 243,
361 mq_notify = 244,
362 mq_getsetattr = 245,
363 kexec_load = 246,
364 waitid = 247,
365 add_key = 248,
366 request_key = 249,
367 keyctl = 250,
368 ioprio_set = 251,
369 ioprio_get = 252,
370 inotify_init = 253,
371 inotify_add_watch = 254,
372 inotify_rm_watch = 255,
373 migrate_pages = 256,
374 openat = 257,
375 mkdirat = 258,
376 mknodat = 259,
377 fchownat = 260,
378 futimesat = 261,
379 fstatat = 262,
380 unlinkat = 263,
381 renameat = 264,
382 linkat = 265,
383 symlinkat = 266,
384 readlinkat = 267,
385 fchmodat = 268,
386 faccessat = 269,
387 pselect6 = 270,
388 ppoll = 271,
389 unshare = 272,
390 set_robust_list = 273,
391 get_robust_list = 274,
392 splice = 275,
393 tee = 276,
394 sync_file_range = 277,
395 vmsplice = 278,
396 move_pages = 279,
397 utimensat = 280,
398 epoll_pwait = 281,
399 signalfd = 282,
400 timerfd_create = 283,
401 eventfd = 284,
402 fallocate = 285,
403 timerfd_settime = 286,
404 timerfd_gettime = 287,
405 accept4 = 288,
406 signalfd4 = 289,
407 eventfd2 = 290,
408 epoll_create1 = 291,
409 dup3 = 292,
410 pipe2 = 293,
411 inotify_init1 = 294,
412 preadv = 295,
413 pwritev = 296,
414 rt_tgsigqueueinfo = 297,
415 perf_event_open = 298,
416 recvmmsg = 299,
417 fanotify_init = 300,
418 fanotify_mark = 301,
419 prlimit64 = 302,
420 name_to_handle_at = 303,
421 open_by_handle_at = 304,
422 clock_adjtime = 305,
423 syncfs = 306,
424 sendmmsg = 307,
425 setns = 308,
426 getcpu = 309,
427 process_vm_readv = 310,
428 process_vm_writev = 311,
429 kcmp = 312,
430 finit_module = 313,
431 sched_setattr = 314,
432 sched_getattr = 315,
433 renameat2 = 316,
434 seccomp = 317,
435 getrandom = 318,
436 memfd_create = 319,
437 kexec_file_load = 320,
438 bpf = 321,
439 execveat = 322,
440 userfaultfd = 323,
441 membarrier = 324,
442 mlock2 = 325,
443 copy_file_range = 326,
444 preadv2 = 327,
445 pwritev2 = 328,
446 pkey_mprotect = 329,
447 pkey_alloc = 330,
448 pkey_free = 331,
449 statx = 332,
450 io_pgetevents = 333,
451 rseq = 334,
452 pidfd_send_signal = 424,
453 io_uring_setup = 425,
454 io_uring_enter = 426,
455 io_uring_register = 427,
456 open_tree = 428,
457 move_mount = 429,
458 fsopen = 430,
459 fsconfig = 431,
460 fsmount = 432,
461 fspick = 433,
462 pidfd_open = 434,
463 clone3 = 435,
464 close_range = 436,
465 openat2 = 437,
466 pidfd_getfd = 438,
467 faccessat2 = 439,
468 process_madvise = 440,
469 epoll_pwait2 = 441,
470
471 _,
472};
473
474pub const O = struct {
475 pub const RDONLY = 0o0;
476 pub const WRONLY = 0o1;
477 pub const RDWR = 0o2;
478
479 pub const CREAT = 0o100;
480 pub const EXCL = 0o200;
481 pub const NOCTTY = 0o400;
482 pub const TRUNC = 0o1000;
483 pub const APPEND = 0o2000;
484 pub const NONBLOCK = 0o4000;
485 pub const DSYNC = 0o10000;
486 pub const SYNC = 0o4010000;
487 pub const RSYNC = 0o4010000;
488 pub const DIRECTORY = 0o200000;
489 pub const NOFOLLOW = 0o400000;
490 pub const CLOEXEC = 0o2000000;
491
492 pub const ASYNC = 0o20000;
493 pub const DIRECT = 0o40000;
494 pub const LARGEFILE = 0;
495 pub const NOATIME = 0o1000000;
496 pub const PATH = 0o10000000;
497 pub const TMPFILE = 0o20200000;
498 pub const NDELAY = NONBLOCK;
499};
500
501pub const F = struct {
502 pub const DUPFD = 0;
503 pub const GETFD = 1;
504 pub const SETFD = 2;
505 pub const GETFL = 3;
506 pub const SETFL = 4;
507 pub const GETLK = 5;
508 pub const SETLK = 6;
509 pub const SETLKW = 7;
510 pub const SETOWN = 8;
511 pub const GETOWN = 9;
512 pub const SETSIG = 10;
513 pub const GETSIG = 11;
514
515 pub const SETOWN_EX = 15;
516 pub const GETOWN_EX = 16;
517 pub const GETOWNER_UIDS = 17;
518
519 pub const RDLCK = 0;
520 pub const WRLCK = 1;
521 pub const UNLCK = 2;
522};
523
524pub const MAP = struct {
525 /// Share changes
526 pub const SHARED = 0x01;
527
528 /// Changes are private
529 pub const PRIVATE = 0x02;
530
531 /// share + validate extension flags
532 pub const SHARED_VALIDATE = 0x03;
533
534 /// Mask for type of mapping
535 pub const TYPE = 0x0f;
536
537 /// Interpret addr exactly
538 pub const FIXED = 0x10;
539
540 /// don't use a file
541 pub const ANONYMOUS = 0x20;
542
543 /// populate (prefault) pagetables
544 pub const POPULATE = 0x8000;
545
546 /// do not block on IO
547 pub const NONBLOCK = 0x10000;
548
549 /// give out an address that is best suited for process/thread stacks
550 pub const STACK = 0x20000;
551
552 /// create a huge page mapping
553 pub const HUGETLB = 0x40000;
554
555 /// perform synchronous page faults for the mapping
556 pub const SYNC = 0x80000;
557
558 /// FIXED which doesn't unmap underlying mapping
559 pub const FIXED_NOREPLACE = 0x100000;
560
561 /// For anonymous mmap, memory could be uninitialized
562 pub const UNINITIALIZED = 0x4000000;
563 /// only give out 32bit addresses
564 pub const @"32BIT" = 0x40;
565
566 /// stack-like segment
567 pub const GROWSDOWN = 0x0100;
568
569 /// ETXTBSY
570 pub const DENYWRITE = 0x0800;
571
572 /// mark it as an executable
573 pub const EXECUTABLE = 0x1000;
574
575 /// pages are locked
576 pub const LOCKED = 0x2000;
577
578 /// don't check for reservations
579 pub const NORESERVE = 0x4000;
580};
581
582pub const VDSO = struct {
583 pub const CGT_SYM = "__vdso_clock_gettime";
584 pub const CGT_VER = "LINUX_2.6";
585
586 pub const GETCPU_SYM = "__vdso_getcpu";
587 pub const GETCPU_VER = "LINUX_2.6";
588};
589
590pub const ARCH = struct {
591 pub const SET_GS = 0x1001;
592 pub const SET_FS = 0x1002;
593 pub const GET_FS = 0x1003;
594 pub const GET_GS = 0x1004;
595};
596
597pub const REG = struct {
598 pub const R8 = 0;
599 pub const R9 = 1;
600 pub const R10 = 2;
601 pub const R11 = 3;
602 pub const R12 = 4;
603 pub const R13 = 5;
604 pub const R14 = 6;
605 pub const R15 = 7;
606 pub const RDI = 8;
607 pub const RSI = 9;
608 pub const RBP = 10;
609 pub const RBX = 11;
610 pub const RDX = 12;
611 pub const RAX = 13;
612 pub const RCX = 14;
613 pub const RSP = 15;
614 pub const RIP = 16;
615 pub const EFL = 17;
616 pub const CSGSFS = 18;
617 pub const ERR = 19;
618 pub const TRAPNO = 20;
619 pub const OLDMASK = 21;
620 pub const CR2 = 22;
621};
622
623pub const LOCK = struct {
624 pub const SH = 1;
625 pub const EX = 2;
626 pub const NB = 4;
627 pub const UN = 8;
628};
629
630pub const Flock = extern struct {
631 type: i16,
632 whence: i16,
633 start: off_t,
634 len: off_t,
635 pid: pid_t,
636};
637
638pub const msghdr = extern struct {
639 name: ?*sockaddr,
640 namelen: socklen_t,
641 iov: [*]iovec,
642 iovlen: i32,
643 __pad1: i32 = 0,
644 control: ?*c_void,
645 controllen: socklen_t,
646 __pad2: socklen_t = 0,
647 flags: i32,
648};
649
650pub const msghdr_const = extern struct {
651 name: ?*const sockaddr,
652 namelen: socklen_t,
653 iov: [*]iovec_const,
654 iovlen: i32,
655 __pad1: i32 = 0,
656 control: ?*c_void,
657 controllen: socklen_t,
658 __pad2: socklen_t = 0,
659 flags: i32,
660};
661
662pub const off_t = i64;
663pub const ino_t = u64;
664pub const dev_t = u64;
665
666// The `stat` definition used by the Linux kernel.
667pub const kernel_stat = extern struct {
668 dev: dev_t,
669 ino: ino_t,
670 nlink: usize,
671
672 mode: u32,
673 uid: uid_t,
674 gid: gid_t,
675 __pad0: u32,
676 rdev: dev_t,
677 size: off_t,
678 blksize: isize,
679 blocks: i64,
680
681 atim: timespec,
682 mtim: timespec,
683 ctim: timespec,
684 __unused: [3]isize,
685
686 pub fn atime(self: @This()) timespec {
687 return self.atim;
688 }
689
690 pub fn mtime(self: @This()) timespec {
691 return self.mtim;
692 }
693
694 pub fn ctime(self: @This()) timespec {
695 return self.ctim;
696 }
697};
698
699// The `stat64` definition used by the libc.
700pub const libc_stat = kernel_stat;
701
702pub const timespec = extern struct {
703 tv_sec: isize,
704 tv_nsec: isize,
705};
706
707pub const timeval = extern struct {
708 tv_sec: isize,
709 tv_usec: isize,
710};
711
712pub const timezone = extern struct {
713 tz_minuteswest: i32,
714 tz_dsttime: i32,
715};
716
717pub const Elf_Symndx = u32;
718
719pub const greg_t = usize;
720pub const gregset_t = [23]greg_t;
721pub const fpstate = extern struct {
722 cwd: u16,
723 swd: u16,
724 ftw: u16,
725 fop: u16,
726 rip: usize,
727 rdp: usize,
728 mxcsr: u32,
729 mxcr_mask: u32,
730 st: [8]extern struct {
731 significand: [4]u16,
732 exponent: u16,
733 padding: [3]u16 = undefined,
734 },
735 xmm: [16]extern struct {
736 element: [4]u32,
737 },
738 padding: [24]u32 = undefined,
739};
740pub const fpregset_t = *fpstate;
741pub const sigcontext = extern struct {
742 r8: usize,
743 r9: usize,
744 r10: usize,
745 r11: usize,
746 r12: usize,
747 r13: usize,
748 r14: usize,
749 r15: usize,
750
751 rdi: usize,
752 rsi: usize,
753 rbp: usize,
754 rbx: usize,
755 rdx: usize,
756 rax: usize,
757 rcx: usize,
758 rsp: usize,
759 rip: usize,
760 eflags: usize,
761
762 cs: u16,
763 gs: u16,
764 fs: u16,
765 pad0: u16 = undefined,
766
767 err: usize,
768 trapno: usize,
769 oldmask: usize,
770 cr2: usize,
771
772 fpstate: *fpstate,
773 reserved1: [8]usize = undefined,
774};
775
776pub const mcontext_t = extern struct {
777 gregs: gregset_t,
778 fpregs: fpregset_t,
779 reserved1: [8]usize = undefined,
780};
781
782pub const ucontext_t = extern struct {
783 flags: usize,
784 link: *ucontext_t,
785 stack: stack_t,
786 mcontext: mcontext_t,
787 sigmask: sigset_t,
788 fpregs_mem: [64]usize,
789};
lib/std/os/netbsd.zig deleted-3
...@@ -1,3 +0,0 @@
1const std = @import("../std.zig");
2pub usingnamespace std.c;
3pub usingnamespace @import("bits.zig");
lib/std/os/openbsd.zig deleted-3
...@@ -1,3 +0,0 @@
1const std = @import("../std.zig");
2pub usingnamespace std.c;
3pub usingnamespace @import("bits.zig");
lib/std/os/wasi.zig-2
...@@ -4,8 +4,6 @@...@@ -4,8 +4,6 @@
4const std = @import("std");4const std = @import("std");
5const assert = std.debug.assert;5const assert = std.debug.assert;
66
7pub usingnamespace @import("bits.zig");
8
9comptime {7comptime {
10 assert(@alignOf(i8) == 1);8 assert(@alignOf(i8) == 1);
11 assert(@alignOf(u8) == 1);9 assert(@alignOf(u8) == 1);
lib/std/time.zig+3-3
...@@ -24,7 +24,7 @@ pub fn sleep(nanoseconds: u64) void {...@@ -24,7 +24,7 @@ pub fn sleep(nanoseconds: u64) void {
24 const w = std.os.wasi;24 const w = std.os.wasi;
25 const userdata: w.userdata_t = 0x0123_45678;25 const userdata: w.userdata_t = 0x0123_45678;
26 const clock = w.subscription_clock_t{26 const clock = w.subscription_clock_t{
27 .id = w.CLOCK_MONOTONIC,27 .id = w.CLOCK.MONOTONIC,
28 .timeout = nanoseconds,28 .timeout = nanoseconds,
29 .precision = 0,29 .precision = 0,
30 .flags = 0,30 .flags = 0,
...@@ -152,7 +152,7 @@ pub const Timer = struct {...@@ -152,7 +152,7 @@ pub const Timer = struct {
152 /// At some point we may change our minds on RAW, but for now we're152 /// At some point we may change our minds on RAW, but for now we're
153 /// sticking with posix standard MONOTONIC. For more information, see:153 /// sticking with posix standard MONOTONIC. For more information, see:
154 /// https://github.com/ziglang/zig/pull/933154 /// https://github.com/ziglang/zig/pull/933
155 const monotonic_clock_id = os.CLOCK_MONOTONIC;155 const monotonic_clock_id = os.CLOCK.MONOTONIC;
156156
157 /// Initialize the timer structure.157 /// Initialize the timer structure.
158 /// Can only fail when running in a hostile environment that intentionally injects158 /// Can only fail when running in a hostile environment that intentionally injects
...@@ -161,7 +161,7 @@ pub const Timer = struct {...@@ -161,7 +161,7 @@ pub const Timer = struct {
161 pub fn start() Error!Timer {161 pub fn start() Error!Timer {
162 // This gives us an opportunity to grab the counter frequency in windows.162 // This gives us an opportunity to grab the counter frequency in windows.
163 // On Windows: QueryPerformanceCounter will succeed on anything >= XP/2000.163 // On Windows: QueryPerformanceCounter will succeed on anything >= XP/2000.
164 // On Posix: CLOCK_MONOTONIC will only fail if the monotonic counter is not164 // On Posix: CLOCK.MONOTONIC will only fail if the monotonic counter is not
165 // supported, or if the timespec pointer is out of bounds, which should be165 // supported, or if the timespec pointer is out of bounds, which should be
166 // impossible here barring cosmic rays or other such occurrences of166 // impossible here barring cosmic rays or other such occurrences of
167 // incredibly bad luck.167 // incredibly bad luck.