mirror of
https://github.com/ziglang/zig.git
synced 2026-01-30 11:13:38 +00:00
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.
This commit is contained in:
parent
81e2034d4a
commit
3deda15e21
@ -424,13 +424,9 @@ set(ZIG_STAGE2_SOURCES
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/meta/trait.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/multi_array_list.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/os.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/os/bits.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/os/bits/linux.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/os/bits/linux/errno/generic.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/os/bits/linux/netlink.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/os/bits/linux/prctl.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/os/bits/linux/securebits.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/os/bits/linux/x86_64.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/os/linux.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/os/linux/errno/generic.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/os/linux/x86_64.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/os/linux.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/os/linux/io_uring.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/os/linux/x86_64.zig"
|
||||
|
||||
@ -133,7 +133,7 @@ pub const AtomicMutex = struct {
|
||||
.linux => {
|
||||
switch (linux.getErrno(linux.futex_wait(
|
||||
@ptrCast(*const i32, &m.state),
|
||||
linux.FUTEX_PRIVATE_FLAG | linux.FUTEX_WAIT,
|
||||
linux.FUTEX.PRIVATE_FLAG | linux.FUTEX.WAIT,
|
||||
@enumToInt(new_state),
|
||||
null,
|
||||
))) {
|
||||
@ -155,7 +155,7 @@ pub const AtomicMutex = struct {
|
||||
.linux => {
|
||||
switch (linux.getErrno(linux.futex_wake(
|
||||
@ptrCast(*const i32, &m.state),
|
||||
linux.FUTEX_PRIVATE_FLAG | linux.FUTEX_WAKE,
|
||||
linux.FUTEX.PRIVATE_FLAG | linux.FUTEX.WAKE,
|
||||
1,
|
||||
))) {
|
||||
.SUCCESS => {},
|
||||
|
||||
@ -194,7 +194,7 @@ pub const AtomicEvent = struct {
|
||||
_ = wake_count;
|
||||
const waiting = std.math.maxInt(i32); // wake_count
|
||||
const ptr = @ptrCast(*const i32, waiters);
|
||||
const rc = linux.futex_wake(ptr, linux.FUTEX_WAKE | linux.FUTEX_PRIVATE_FLAG, waiting);
|
||||
const rc = linux.futex_wake(ptr, linux.FUTEX.WAKE | linux.FUTEX.PRIVATE_FLAG, waiting);
|
||||
assert(linux.getErrno(rc) == .SUCCESS);
|
||||
}
|
||||
|
||||
@ -213,7 +213,7 @@ pub const AtomicEvent = struct {
|
||||
return;
|
||||
const expected = @intCast(i32, waiting);
|
||||
const ptr = @ptrCast(*const i32, waiters);
|
||||
const rc = linux.futex_wait(ptr, linux.FUTEX_WAIT | linux.FUTEX_PRIVATE_FLAG, expected, ts_ptr);
|
||||
const rc = linux.futex_wait(ptr, linux.FUTEX.WAIT | linux.FUTEX.PRIVATE_FLAG, expected, ts_ptr);
|
||||
switch (linux.getErrno(rc)) {
|
||||
.SUCCESS => continue,
|
||||
.TIMEDOUT => return error.TimedOut,
|
||||
|
||||
@ -10,8 +10,6 @@ test {
|
||||
_ = tokenizer;
|
||||
}
|
||||
|
||||
pub usingnamespace @import("os/bits.zig");
|
||||
|
||||
pub usingnamespace switch (std.Target.current.os.tag) {
|
||||
.linux => @import("c/linux.zig"),
|
||||
.windows => @import("c/windows.zig"),
|
||||
|
||||
@ -4,8 +4,6 @@ const builtin = @import("builtin");
|
||||
const macho = std.macho;
|
||||
const native_arch = builtin.target.cpu.arch;
|
||||
|
||||
usingnamespace @import("../os/bits.zig");
|
||||
|
||||
extern "c" fn __error() *c_int;
|
||||
pub extern "c" fn NSVersionOfRunTimeLibrary(library_name: [*:0]const u8) u32;
|
||||
pub extern "c" fn _NSGetExecutablePath(buf: [*:0]u8, bufsize: *u32) c_int;
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
usingnamespace @import("../os/bits.zig");
|
||||
|
||||
extern threadlocal var errno: c_int;
|
||||
|
||||
pub fn _errno() *c_int {
|
||||
|
||||
@ -948,8 +948,8 @@ fn mapWholeFile(file: File) ![]align(mem.page_size) const u8 {
|
||||
const mapped_mem = try os.mmap(
|
||||
null,
|
||||
file_len,
|
||||
os.PROT_READ,
|
||||
os.MAP_SHARED,
|
||||
os.PROT.READ,
|
||||
os.MAP.SHARED,
|
||||
file.handle,
|
||||
0,
|
||||
);
|
||||
@ -1498,12 +1498,12 @@ pub fn attachSegfaultHandler() void {
|
||||
var act = os.Sigaction{
|
||||
.handler = .{ .sigaction = handleSegfaultLinux },
|
||||
.mask = os.empty_sigset,
|
||||
.flags = (os.SA_SIGINFO | os.SA_RESTART | os.SA_RESETHAND),
|
||||
.flags = (os.SA.SIGINFO | os.SA.RESTART | os.SA.RESETHAND),
|
||||
};
|
||||
|
||||
os.sigaction(os.SIGSEGV, &act, null);
|
||||
os.sigaction(os.SIGILL, &act, null);
|
||||
os.sigaction(os.SIGBUS, &act, null);
|
||||
os.sigaction(os.SIG.SEGV, &act, null);
|
||||
os.sigaction(os.SIG.ILL, &act, null);
|
||||
os.sigaction(os.SIG.BUS, &act, null);
|
||||
}
|
||||
|
||||
fn resetSegfaultHandler() void {
|
||||
@ -1515,13 +1515,13 @@ fn resetSegfaultHandler() void {
|
||||
return;
|
||||
}
|
||||
var act = os.Sigaction{
|
||||
.handler = .{ .sigaction = os.SIG_DFL },
|
||||
.handler = .{ .sigaction = os.SIG.DFL },
|
||||
.mask = os.empty_sigset,
|
||||
.flags = 0,
|
||||
};
|
||||
os.sigaction(os.SIGSEGV, &act, null);
|
||||
os.sigaction(os.SIGILL, &act, null);
|
||||
os.sigaction(os.SIGBUS, &act, null);
|
||||
os.sigaction(os.SIG.SEGV, &act, null);
|
||||
os.sigaction(os.SIG.ILL, &act, null);
|
||||
os.sigaction(os.SIG.BUS, &act, null);
|
||||
}
|
||||
|
||||
fn 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
|
||||
nosuspend {
|
||||
const stderr = io.getStdErr().writer();
|
||||
_ = switch (sig) {
|
||||
os.SIGSEGV => stderr.print("Segmentation fault at address 0x{x}\n", .{addr}),
|
||||
os.SIGILL => stderr.print("Illegal instruction at address 0x{x}\n", .{addr}),
|
||||
os.SIGBUS => stderr.print("Bus error at address 0x{x}\n", .{addr}),
|
||||
os.SIG.SEGV => stderr.print("Segmentation fault at address 0x{x}\n", .{addr}),
|
||||
os.SIG.ILL => stderr.print("Illegal instruction at address 0x{x}\n", .{addr}),
|
||||
os.SIG.BUS => stderr.print("Bus error at address 0x{x}\n", .{addr}),
|
||||
else => unreachable,
|
||||
} catch os.abort();
|
||||
}
|
||||
@ -1552,20 +1552,20 @@ fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const c_v
|
||||
switch (native_arch) {
|
||||
.i386 => {
|
||||
const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr));
|
||||
const ip = @intCast(usize, ctx.mcontext.gregs[os.REG_EIP]);
|
||||
const bp = @intCast(usize, ctx.mcontext.gregs[os.REG_EBP]);
|
||||
const ip = @intCast(usize, ctx.mcontext.gregs[os.REG.EIP]);
|
||||
const bp = @intCast(usize, ctx.mcontext.gregs[os.REG.EBP]);
|
||||
dumpStackTraceFromBase(bp, ip);
|
||||
},
|
||||
.x86_64 => {
|
||||
const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr));
|
||||
const ip = switch (native_os) {
|
||||
.linux, .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG_RIP]),
|
||||
.linux, .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG.RIP]),
|
||||
.freebsd => @intCast(usize, ctx.mcontext.rip),
|
||||
.openbsd => @intCast(usize, ctx.sc_rip),
|
||||
else => unreachable,
|
||||
};
|
||||
const bp = switch (native_os) {
|
||||
.linux, .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG_RBP]),
|
||||
.linux, .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG.RBP]),
|
||||
.openbsd => @intCast(usize, ctx.sc_rbp),
|
||||
.freebsd => @intCast(usize, ctx.mcontext.rbp),
|
||||
else => unreachable,
|
||||
|
||||
@ -907,35 +907,35 @@ pub const Dir = struct {
|
||||
return self.openFileW(path_w.span(), flags);
|
||||
}
|
||||
|
||||
var os_flags: u32 = os.O_CLOEXEC;
|
||||
var os_flags: u32 = os.O.CLOEXEC;
|
||||
// Use the O_ locking flags if the os supports them to acquire the lock
|
||||
// atomically.
|
||||
const has_flock_open_flags = @hasDecl(os, "O_EXLOCK");
|
||||
const has_flock_open_flags = @hasDecl(os.O, "EXLOCK");
|
||||
if (has_flock_open_flags) {
|
||||
// Note that the O_NONBLOCK flag is removed after the openat() call
|
||||
// is successful.
|
||||
const nonblocking_lock_flag: u32 = if (flags.lock_nonblocking)
|
||||
os.O_NONBLOCK
|
||||
os.O.NONBLOCK
|
||||
else
|
||||
0;
|
||||
os_flags |= switch (flags.lock) {
|
||||
.None => @as(u32, 0),
|
||||
.Shared => os.O_SHLOCK | nonblocking_lock_flag,
|
||||
.Exclusive => os.O_EXLOCK | nonblocking_lock_flag,
|
||||
.Shared => os.O.SHLOCK | nonblocking_lock_flag,
|
||||
.Exclusive => os.O.EXLOCK | nonblocking_lock_flag,
|
||||
};
|
||||
}
|
||||
if (@hasDecl(os, "O_LARGEFILE")) {
|
||||
os_flags |= os.O_LARGEFILE;
|
||||
if (@hasDecl(os.O, "LARGEFILE")) {
|
||||
os_flags |= os.O.LARGEFILE;
|
||||
}
|
||||
if (!flags.allow_ctty) {
|
||||
os_flags |= os.O_NOCTTY;
|
||||
os_flags |= os.O.NOCTTY;
|
||||
}
|
||||
os_flags |= if (flags.write and flags.read)
|
||||
@as(u32, os.O_RDWR)
|
||||
@as(u32, os.O.RDWR)
|
||||
else if (flags.write)
|
||||
@as(u32, os.O_WRONLY)
|
||||
@as(u32, os.O.WRONLY)
|
||||
else
|
||||
@as(u32, os.O_RDONLY);
|
||||
@as(u32, os.O.RDONLY);
|
||||
const fd = if (flags.intended_io_mode != .blocking)
|
||||
try std.event.Loop.instance.?.openatZ(self.fd, sub_path, os_flags, 0)
|
||||
else
|
||||
@ -947,11 +947,11 @@ pub const Dir = struct {
|
||||
if (builtin.target.os.tag != .wasi) {
|
||||
if (!has_flock_open_flags and flags.lock != .None) {
|
||||
// TODO: integrate async I/O
|
||||
const lock_nonblocking = if (flags.lock_nonblocking) os.LOCK_NB else @as(i32, 0);
|
||||
const lock_nonblocking = if (flags.lock_nonblocking) os.LOCK.NB else @as(i32, 0);
|
||||
try os.flock(fd, switch (flags.lock) {
|
||||
.None => unreachable,
|
||||
.Shared => os.LOCK_SH | lock_nonblocking,
|
||||
.Exclusive => os.LOCK_EX | lock_nonblocking,
|
||||
.Shared => os.LOCK.SH | lock_nonblocking,
|
||||
.Exclusive => os.LOCK.EX | lock_nonblocking,
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -963,7 +963,7 @@ pub const Dir = struct {
|
||||
error.PermissionDenied => unreachable,
|
||||
else => |e| return e,
|
||||
};
|
||||
fl_flags &= ~@as(usize, os.O_NONBLOCK);
|
||||
fl_flags &= ~@as(usize, os.O.NONBLOCK);
|
||||
_ = os.fcntl(fd, os.F_SETFL, fl_flags) catch |err| switch (err) {
|
||||
error.FileBusy => unreachable,
|
||||
error.Locked => unreachable,
|
||||
@ -1038,7 +1038,7 @@ pub const Dir = struct {
|
||||
/// Same as `createFile` but WASI only.
|
||||
pub fn createFileWasi(self: Dir, sub_path: []const u8, flags: File.CreateFlags) File.OpenError!File {
|
||||
const w = os.wasi;
|
||||
var oflags = w.O_CREAT;
|
||||
var oflags = w.O.CREAT;
|
||||
var base: w.rights_t = w.RIGHT_FD_WRITE |
|
||||
w.RIGHT_FD_DATASYNC |
|
||||
w.RIGHT_FD_SEEK |
|
||||
@ -1054,10 +1054,10 @@ pub const Dir = struct {
|
||||
base |= w.RIGHT_FD_READ;
|
||||
}
|
||||
if (flags.truncate) {
|
||||
oflags |= w.O_TRUNC;
|
||||
oflags |= w.O.TRUNC;
|
||||
}
|
||||
if (flags.exclusive) {
|
||||
oflags |= w.O_EXCL;
|
||||
oflags |= w.O.EXCL;
|
||||
}
|
||||
const fd = try os.openatWasi(self.fd, sub_path, 0x0, oflags, 0x0, base, 0x0);
|
||||
return File{ .handle = fd };
|
||||
@ -1072,24 +1072,24 @@ pub const Dir = struct {
|
||||
|
||||
// Use the O_ locking flags if the os supports them to acquire the lock
|
||||
// atomically.
|
||||
const has_flock_open_flags = @hasDecl(os, "O_EXLOCK");
|
||||
const has_flock_open_flags = @hasDecl(os.O, "EXLOCK");
|
||||
// Note that the O_NONBLOCK flag is removed after the openat() call
|
||||
// is successful.
|
||||
const nonblocking_lock_flag: u32 = if (has_flock_open_flags and flags.lock_nonblocking)
|
||||
os.O_NONBLOCK
|
||||
os.O.NONBLOCK
|
||||
else
|
||||
0;
|
||||
const lock_flag: u32 = if (has_flock_open_flags) switch (flags.lock) {
|
||||
.None => @as(u32, 0),
|
||||
.Shared => os.O_SHLOCK | nonblocking_lock_flag,
|
||||
.Exclusive => os.O_EXLOCK | nonblocking_lock_flag,
|
||||
.Shared => os.O.SHLOCK | nonblocking_lock_flag,
|
||||
.Exclusive => os.O.EXLOCK | nonblocking_lock_flag,
|
||||
} else 0;
|
||||
|
||||
const O_LARGEFILE = if (@hasDecl(os, "O_LARGEFILE")) os.O_LARGEFILE else 0;
|
||||
const os_flags = lock_flag | O_LARGEFILE | os.O_CREAT | os.O_CLOEXEC |
|
||||
(if (flags.truncate) @as(u32, os.O_TRUNC) else 0) |
|
||||
(if (flags.read) @as(u32, os.O_RDWR) else os.O_WRONLY) |
|
||||
(if (flags.exclusive) @as(u32, os.O_EXCL) else 0);
|
||||
const O_LARGEFILE = if (@hasDecl(os.O, "LARGEFILE")) os.O.LARGEFILE else 0;
|
||||
const os_flags = lock_flag | O_LARGEFILE | os.O.CREAT | os.O.CLOEXEC |
|
||||
(if (flags.truncate) @as(u32, os.O.TRUNC) else 0) |
|
||||
(if (flags.read) @as(u32, os.O.RDWR) else os.O.WRONLY) |
|
||||
(if (flags.exclusive) @as(u32, os.O.EXCL) else 0);
|
||||
const fd = if (flags.intended_io_mode != .blocking)
|
||||
try std.event.Loop.instance.?.openatZ(self.fd, sub_path_c, os_flags, flags.mode)
|
||||
else
|
||||
@ -1101,11 +1101,11 @@ pub const Dir = struct {
|
||||
if (builtin.target.os.tag != .wasi) {
|
||||
if (!has_flock_open_flags and flags.lock != .None) {
|
||||
// TODO: integrate async I/O
|
||||
const lock_nonblocking = if (flags.lock_nonblocking) os.LOCK_NB else @as(i32, 0);
|
||||
const lock_nonblocking = if (flags.lock_nonblocking) os.LOCK.NB else @as(i32, 0);
|
||||
try os.flock(fd, switch (flags.lock) {
|
||||
.None => unreachable,
|
||||
.Shared => os.LOCK_SH | lock_nonblocking,
|
||||
.Exclusive => os.LOCK_EX | lock_nonblocking,
|
||||
.Shared => os.LOCK.SH | lock_nonblocking,
|
||||
.Exclusive => os.LOCK.EX | lock_nonblocking,
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -1117,7 +1117,7 @@ pub const Dir = struct {
|
||||
error.PermissionDenied => unreachable,
|
||||
else => |e| return e,
|
||||
};
|
||||
fl_flags &= ~@as(usize, os.O_NONBLOCK);
|
||||
fl_flags &= ~@as(usize, os.O.NONBLOCK);
|
||||
_ = os.fcntl(fd, os.F_SETFL, fl_flags) catch |err| switch (err) {
|
||||
error.FileBusy => unreachable,
|
||||
error.Locked => unreachable,
|
||||
@ -1262,7 +1262,7 @@ pub const Dir = struct {
|
||||
return self.realpathW(pathname_w.span(), out_buffer);
|
||||
}
|
||||
|
||||
const flags = if (builtin.os.tag == .linux) os.O_PATH | os.O_NONBLOCK | os.O_CLOEXEC else os.O_NONBLOCK | os.O_CLOEXEC;
|
||||
const flags = if (builtin.os.tag == .linux) os.O.PATH | os.O.NONBLOCK | os.O.CLOEXEC else os.O.NONBLOCK | os.O.CLOEXEC;
|
||||
const fd = os.openatZ(self.fd, pathname, flags, 0) catch |err| switch (err) {
|
||||
error.FileLocksNotSupported => unreachable,
|
||||
else => |e| return e,
|
||||
@ -1423,7 +1423,7 @@ pub const Dir = struct {
|
||||
// TODO do we really need all the rights here?
|
||||
const inheriting: w.rights_t = w.RIGHT_ALL ^ w.RIGHT_SOCK_SHUTDOWN;
|
||||
|
||||
const result = os.openatWasi(self.fd, sub_path, symlink_flags, w.O_DIRECTORY, 0x0, base, inheriting);
|
||||
const result = os.openatWasi(self.fd, sub_path, symlink_flags, w.O.DIRECTORY, 0x0, base, inheriting);
|
||||
const fd = result catch |err| switch (err) {
|
||||
error.FileTooBig => unreachable, // can't happen for directories
|
||||
error.IsDir => unreachable, // we're providing O_DIRECTORY
|
||||
@ -1442,12 +1442,12 @@ pub const Dir = struct {
|
||||
const sub_path_w = try os.windows.cStrToPrefixedFileW(sub_path_c);
|
||||
return self.openDirW(sub_path_w.span().ptr, args);
|
||||
}
|
||||
const symlink_flags: u32 = if (args.no_follow) os.O_NOFOLLOW else 0x0;
|
||||
const symlink_flags: u32 = if (args.no_follow) os.O.NOFOLLOW else 0x0;
|
||||
if (!args.iterate) {
|
||||
const O_PATH = if (@hasDecl(os, "O_PATH")) os.O_PATH else 0;
|
||||
return self.openDirFlagsZ(sub_path_c, os.O_DIRECTORY | os.O_RDONLY | os.O_CLOEXEC | O_PATH | symlink_flags);
|
||||
const O_PATH = if (@hasDecl(os.O, "PATH")) os.O.PATH else 0;
|
||||
return self.openDirFlagsZ(sub_path_c, os.O.DIRECTORY | os.O.RDONLY | os.O.CLOEXEC | O_PATH | symlink_flags);
|
||||
} else {
|
||||
return self.openDirFlagsZ(sub_path_c, os.O_DIRECTORY | os.O_RDONLY | os.O_CLOEXEC | symlink_flags);
|
||||
return self.openDirFlagsZ(sub_path_c, os.O.DIRECTORY | os.O.RDONLY | os.O.CLOEXEC | symlink_flags);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2132,7 +2132,7 @@ pub fn cwd() Dir {
|
||||
} else if (builtin.os.tag == .wasi and !builtin.link_libc) {
|
||||
@compileError("WASI doesn't have a concept of cwd(); use std.fs.wasi.PreopenList to get available Dir handles instead");
|
||||
} else {
|
||||
return Dir{ .fd = os.AT_FDCWD };
|
||||
return Dir{ .fd = os.AT.FDCWD };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -329,14 +329,14 @@ pub const File = struct {
|
||||
os.FILETYPE_REGULAR_FILE => Kind.File,
|
||||
os.FILETYPE_SOCKET_STREAM, os.FILETYPE_SOCKET_DGRAM => Kind.UnixDomainSocket,
|
||||
else => Kind.Unknown,
|
||||
} else switch (st.mode & os.S_IFMT) {
|
||||
os.S_IFBLK => Kind.BlockDevice,
|
||||
os.S_IFCHR => Kind.CharacterDevice,
|
||||
os.S_IFDIR => Kind.Directory,
|
||||
os.S_IFIFO => Kind.NamedPipe,
|
||||
os.S_IFLNK => Kind.SymLink,
|
||||
os.S_IFREG => Kind.File,
|
||||
os.S_IFSOCK => Kind.UnixDomainSocket,
|
||||
} else switch (st.mode & os.S.IFMT) {
|
||||
os.S.IFBLK => Kind.BlockDevice,
|
||||
os.S.IFCHR => Kind.CharacterDevice,
|
||||
os.S.IFDIR => Kind.Directory,
|
||||
os.S.IFIFO => Kind.NamedPipe,
|
||||
os.S.IFLNK => Kind.SymLink,
|
||||
os.S.IFREG => Kind.File,
|
||||
os.S.IFSOCK => Kind.UnixDomainSocket,
|
||||
else => Kind.Unknown,
|
||||
},
|
||||
.atime = @as(i128, atime.tv_sec) * std.time.ns_per_s + atime.tv_nsec,
|
||||
|
||||
@ -304,8 +304,8 @@ const PageAllocator = struct {
|
||||
const slice = os.mmap(
|
||||
hint,
|
||||
alloc_len,
|
||||
os.PROT_READ | os.PROT_WRITE,
|
||||
os.MAP_PRIVATE | os.MAP_ANONYMOUS,
|
||||
os.PROT.READ | os.PROT.WRITE,
|
||||
os.MAP.PRIVATE | os.MAP.ANONYMOUS,
|
||||
-1,
|
||||
0,
|
||||
) catch return error.OutOfMemory;
|
||||
|
||||
131
lib/std/os.zig
131
lib/std/os.zig
@ -16,7 +16,7 @@
|
||||
|
||||
const root = @import("root");
|
||||
const std = @import("std.zig");
|
||||
const builtin = std.builtin;
|
||||
const builtin = @import("builtin");
|
||||
const assert = std.debug.assert;
|
||||
const math = std.math;
|
||||
const mem = std.mem;
|
||||
@ -24,12 +24,12 @@ const elf = std.elf;
|
||||
const dl = @import("dynamic_library.zig");
|
||||
const MAX_PATH_BYTES = std.fs.MAX_PATH_BYTES;
|
||||
|
||||
pub const darwin = @import("os/darwin.zig");
|
||||
pub const dragonfly = @import("os/dragonfly.zig");
|
||||
pub const freebsd = @import("os/freebsd.zig");
|
||||
pub const haiku = @import("os/haiku.zig");
|
||||
pub const netbsd = @import("os/netbsd.zig");
|
||||
pub const openbsd = @import("os/openbsd.zig");
|
||||
pub const darwin = std.c;
|
||||
pub const dragonfly = std.c;
|
||||
pub const freebsd = std.c;
|
||||
pub const haiku = std.c;
|
||||
pub const netbsd = std.c;
|
||||
pub const openbsd = std.c;
|
||||
pub const linux = @import("os/linux.zig");
|
||||
pub const uefi = @import("os/uefi.zig");
|
||||
pub const wasi = @import("os/wasi.zig");
|
||||
@ -73,7 +73,102 @@ else switch (builtin.os.tag) {
|
||||
else => struct {},
|
||||
};
|
||||
|
||||
pub usingnamespace @import("os/bits.zig");
|
||||
const bits = switch (builtin.os.tag) {
|
||||
.macos, .ios, .tvos, .watchos => std.c,
|
||||
.dragonfly => @import("os/bits/dragonfly.zig"),
|
||||
.freebsd => @import("os/bits/freebsd.zig"),
|
||||
.haiku => @import("os/bits/haiku.zig"),
|
||||
.linux => linux,
|
||||
.netbsd => @import("os/bits/netbsd.zig"),
|
||||
.openbsd => @import("os/bits/openbsd.zig"),
|
||||
.wasi => @import("os/bits/wasi.zig"),
|
||||
.windows => @import("os/bits/windows.zig"),
|
||||
else => struct {},
|
||||
};
|
||||
pub const E = bits.E;
|
||||
pub const ARCH = bits.ARCH;
|
||||
pub const Elf_Symndx = bits.Elf_Symndx;
|
||||
pub const F = bits.F;
|
||||
pub const Flock = bits.Flock;
|
||||
pub const LOCK = bits.LOCK;
|
||||
pub const MAP = bits.MAP;
|
||||
pub const MMAP2_UNIT = bits.MMAP2_UNIT;
|
||||
pub const O = bits.O;
|
||||
pub const REG = bits.REG;
|
||||
pub const SC = bits.SC;
|
||||
pub const SYS = bits.SYS;
|
||||
pub const VDSO = bits.VDSO;
|
||||
pub const blkcnt_t = bits.blkcnt_t;
|
||||
pub const blksize_t = bits.blksize_t;
|
||||
pub const dev_t = bits.dev_t;
|
||||
pub const ino_t = bits.ino_t;
|
||||
pub const kernel_stat = bits.kernel_stat;
|
||||
pub const libc_stat = bits.libc_stat;
|
||||
pub const mcontext_t = bits.mcontext_t;
|
||||
pub const mode_t = bits.mode_t;
|
||||
pub const msghdr = bits.msghdr;
|
||||
pub const msghdr_const = bits.msghdr_const;
|
||||
pub const nlink_t = bits.nlink_t;
|
||||
pub const off_t = bits.off_t;
|
||||
pub const time_t = bits.time_t;
|
||||
pub const timespec = bits.timespec;
|
||||
pub const timeval = bits.timeval;
|
||||
pub const timezone = bits.timezone;
|
||||
pub const ucontext_t = bits.ucontext_t;
|
||||
pub const user_desc = bits.user_desc;
|
||||
pub const pid_t = bits.pid_t;
|
||||
pub const fd_t = bits.fd_t;
|
||||
pub const uid_t = bits.uid_t;
|
||||
pub const gid_t = bits.gid_t;
|
||||
pub const clock_t = bits.clock_t;
|
||||
pub const NAME_MAX = bits.NAME_MAX;
|
||||
pub const PATH_MAX = bits.PATH_MAX;
|
||||
pub const IOV_MAX = bits.IOV_MAX;
|
||||
pub const MAX_ADDR_LEN = bits.MAX_ADDR_LEN;
|
||||
pub const STDIN_FILENO = bits.STDIN_FILENO;
|
||||
pub const STDOUT_FILENO = bits.STDIN_FILENO;
|
||||
pub const STDERR_FILENO = bits.STDIN_FILENO;
|
||||
pub const AT = bits.AT;
|
||||
pub const PROT = bits.PROT;
|
||||
pub const CLOCK = bits.CLOCK;
|
||||
pub const dl_phdr_info = bits.dl_phdr_info;
|
||||
pub const Sigaction = bits.Sigaction;
|
||||
pub const rlimit_resource = bits.rlimit_resource;
|
||||
pub const SIG = bits.SIG;
|
||||
pub const rlimit = bits.rlimit;
|
||||
pub const empty_sigset = bits.empty_sigset;
|
||||
pub const S = bits.S;
|
||||
pub const siginfo_t = bits.siginfo_t;
|
||||
pub const SA = bits.SA;
|
||||
|
||||
pub const iovec = extern struct {
|
||||
iov_base: [*]u8,
|
||||
iov_len: usize,
|
||||
};
|
||||
|
||||
pub const iovec_const = extern struct {
|
||||
iov_base: [*]const u8,
|
||||
iov_len: usize,
|
||||
};
|
||||
|
||||
pub const LOG = struct {
|
||||
/// system is unusable
|
||||
pub const EMERG = 0;
|
||||
/// action must be taken immediately
|
||||
pub const ALERT = 1;
|
||||
/// critical conditions
|
||||
pub const CRIT = 2;
|
||||
/// error conditions
|
||||
pub const ERR = 3;
|
||||
/// warning conditions
|
||||
pub const WARNING = 4;
|
||||
/// normal but significant condition
|
||||
pub const NOTICE = 5;
|
||||
/// informational
|
||||
pub const INFO = 6;
|
||||
/// debug-level messages
|
||||
pub const DEBUG = 7;
|
||||
};
|
||||
|
||||
pub const socket_t = if (builtin.os.tag == .windows) windows.ws2_32.SOCKET else fd_t;
|
||||
|
||||
@ -136,7 +231,7 @@ pub fn getrandom(buffer: []u8) GetRandomError!void {
|
||||
if (builtin.os.tag == .linux or builtin.os.tag == .freebsd) {
|
||||
var buf = buffer;
|
||||
const use_c = builtin.os.tag != .linux or
|
||||
std.c.versionCheck(builtin.Version{ .major = 2, .minor = 25, .patch = 0 }).ok;
|
||||
std.c.versionCheck(std.builtin.Version{ .major = 2, .minor = 25, .patch = 0 }).ok;
|
||||
|
||||
while (buf.len != 0) {
|
||||
const res = if (use_c) blk: {
|
||||
@ -210,11 +305,11 @@ pub fn abort() noreturn {
|
||||
windows.kernel32.ExitProcess(3);
|
||||
}
|
||||
if (!builtin.link_libc and builtin.os.tag == .linux) {
|
||||
raise(SIGABRT) catch {};
|
||||
raise(SIG.ABRT) catch {};
|
||||
|
||||
// TODO the rest of the implementation of abort() from musl libc here
|
||||
|
||||
raise(SIGKILL) catch {};
|
||||
raise(SIG.KILL) catch {};
|
||||
exit(127);
|
||||
}
|
||||
if (builtin.os.tag == .uefi) {
|
||||
@ -239,15 +334,15 @@ pub fn raise(sig: u8) RaiseError!void {
|
||||
}
|
||||
|
||||
if (builtin.os.tag == .linux) {
|
||||
var set: linux.sigset_t = undefined;
|
||||
var set: bits.sigset_t = undefined;
|
||||
// block application signals
|
||||
_ = linux.sigprocmask(SIG_BLOCK, &linux.app_mask, &set);
|
||||
_ = linux.sigprocmask(SIG.BLOCK, &linux.app_mask, &set);
|
||||
|
||||
const tid = linux.gettid();
|
||||
const rc = linux.tkill(tid, sig);
|
||||
|
||||
// restore signal mask
|
||||
_ = linux.sigprocmask(SIG_SETMASK, &set, null);
|
||||
_ = linux.sigprocmask(SIG.SETMASK, &set, null);
|
||||
|
||||
switch (errno(rc)) {
|
||||
.SUCCESS => return,
|
||||
@ -2676,7 +2771,7 @@ pub fn isatty(handle: fd_t) bool {
|
||||
while (true) {
|
||||
var wsz: linux.winsize = undefined;
|
||||
const fd = @bitCast(usize, @as(isize, handle));
|
||||
const rc = linux.syscall3(.ioctl, fd, linux.TIOCGWINSZ, @ptrToInt(&wsz));
|
||||
const rc = linux.syscall3(.ioctl, fd, linux.T.IOCGWINSZ, @ptrToInt(&wsz));
|
||||
switch (linux.getErrno(rc)) {
|
||||
.SUCCESS => return true,
|
||||
.INTR => continue,
|
||||
@ -4679,7 +4774,7 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) ClockGetTimeError!void {
|
||||
return;
|
||||
}
|
||||
if (std.Target.current.os.tag == .windows) {
|
||||
if (clk_id == CLOCK_REALTIME) {
|
||||
if (clk_id == CLOCK.REALTIME) {
|
||||
var ft: windows.FILETIME = undefined;
|
||||
windows.kernel32.GetSystemTimeAsFileTime(&ft);
|
||||
// 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 {
|
||||
};
|
||||
return;
|
||||
} else {
|
||||
// TODO POSIX implementation of CLOCK_MONOTONIC on Windows.
|
||||
// TODO POSIX implementation of CLOCK.MONOTONIC on Windows.
|
||||
return error.UnsupportedClock;
|
||||
}
|
||||
}
|
||||
@ -4929,7 +5024,7 @@ pub fn res_mkquery(
|
||||
|
||||
// Make a reasonably unpredictable id
|
||||
var ts: timespec = undefined;
|
||||
clock_gettime(CLOCK_REALTIME, &ts) catch {};
|
||||
clock_gettime(CLOCK.REALTIME, &ts) catch {};
|
||||
const UInt = std.meta.Int(.unsigned, std.meta.bitCount(@TypeOf(ts.tv_nsec)));
|
||||
const unsec = @bitCast(UInt, ts.tv_nsec);
|
||||
const id = @truncate(u32, unsec + unsec / 65536);
|
||||
|
||||
@ -1,22 +0,0 @@
|
||||
//! Platform-dependent types and values that are used along with OS-specific APIs.
|
||||
//! These are imported into `std.c`, `std.os`, and `std.os.linux`.
|
||||
//! Root source files can define `os.bits` and these will additionally be added
|
||||
//! to the namespace.
|
||||
|
||||
const std = @import("std");
|
||||
const root = @import("root");
|
||||
|
||||
pub usingnamespace switch (std.Target.current.os.tag) {
|
||||
.macos, .ios, .tvos, .watchos => @import("bits/darwin.zig"),
|
||||
.dragonfly => @import("bits/dragonfly.zig"),
|
||||
.freebsd => @import("bits/freebsd.zig"),
|
||||
.haiku => @import("bits/haiku.zig"),
|
||||
.linux => @import("bits/linux.zig"),
|
||||
.netbsd => @import("bits/netbsd.zig"),
|
||||
.openbsd => @import("bits/openbsd.zig"),
|
||||
.wasi => @import("bits/wasi.zig"),
|
||||
.windows => @import("bits/windows.zig"),
|
||||
else => struct {},
|
||||
};
|
||||
|
||||
pub usingnamespace if (@hasDecl(root, "os") and @hasDecl(root.os, "bits")) root.os.bits else struct {};
|
||||
@ -2,8 +2,6 @@ const std = @import("../../std.zig");
|
||||
const assert = std.debug.assert;
|
||||
const maxInt = std.math.maxInt;
|
||||
|
||||
pub usingnamespace @import("posix.zig");
|
||||
|
||||
// See: https://opensource.apple.com/source/xnu/xnu-6153.141.1/bsd/sys/_types.h.auto.html
|
||||
// TODO: audit mode_t/pid_t, should likely be u16/i32
|
||||
pub const fd_t = c_int;
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
const std = @import("../../std.zig");
|
||||
const maxInt = std.math.maxInt;
|
||||
|
||||
pub usingnamespace @import("posix.zig");
|
||||
|
||||
pub fn S_ISCHR(m: u32) bool {
|
||||
return m & S_IFMT == S_IFCHR;
|
||||
}
|
||||
|
||||
@ -2,8 +2,6 @@ const std = @import("../../std.zig");
|
||||
const builtin = @import("builtin");
|
||||
const maxInt = std.math.maxInt;
|
||||
|
||||
pub usingnamespace @import("posix.zig");
|
||||
|
||||
pub const blksize_t = i32;
|
||||
pub const blkcnt_t = i64;
|
||||
pub const clockid_t = i32;
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
const std = @import("../../std.zig");
|
||||
const maxInt = std.math.maxInt;
|
||||
|
||||
pub usingnamespace @import("posix.zig");
|
||||
|
||||
pub const fd_t = c_int;
|
||||
pub const pid_t = c_int;
|
||||
pub const uid_t = u32;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -448,94 +448,145 @@ pub const SYS = enum(usize) {
|
||||
_,
|
||||
};
|
||||
|
||||
pub const O_CREAT = 0o100;
|
||||
pub const O_EXCL = 0o200;
|
||||
pub const O_NOCTTY = 0o400;
|
||||
pub const O_TRUNC = 0o1000;
|
||||
pub const O_APPEND = 0o2000;
|
||||
pub const O_NONBLOCK = 0o4000;
|
||||
pub const O_DSYNC = 0o10000;
|
||||
pub const O_SYNC = 0o4010000;
|
||||
pub const O_RSYNC = 0o4010000;
|
||||
pub const O_DIRECTORY = 0o200000;
|
||||
pub const O_NOFOLLOW = 0o400000;
|
||||
pub const O_CLOEXEC = 0o2000000;
|
||||
pub const O = struct {
|
||||
pub const RDONLY = 0o0;
|
||||
pub const WRONLY = 0o1;
|
||||
pub const RDWR = 0o2;
|
||||
|
||||
pub const O_ASYNC = 0o20000;
|
||||
pub const O_DIRECT = 0o40000;
|
||||
pub const O_LARGEFILE = 0o100000;
|
||||
pub const O_NOATIME = 0o1000000;
|
||||
pub const O_PATH = 0o10000000;
|
||||
pub const O_TMPFILE = 0o20200000;
|
||||
pub const O_NDELAY = O_NONBLOCK;
|
||||
pub const CREAT = 0o100;
|
||||
pub const EXCL = 0o200;
|
||||
pub const NOCTTY = 0o400;
|
||||
pub const TRUNC = 0o1000;
|
||||
pub const APPEND = 0o2000;
|
||||
pub const NONBLOCK = 0o4000;
|
||||
pub const DSYNC = 0o10000;
|
||||
pub const SYNC = 0o4010000;
|
||||
pub const RSYNC = 0o4010000;
|
||||
pub const DIRECTORY = 0o200000;
|
||||
pub const NOFOLLOW = 0o400000;
|
||||
pub const CLOEXEC = 0o2000000;
|
||||
|
||||
pub const F_DUPFD = 0;
|
||||
pub const F_GETFD = 1;
|
||||
pub const F_SETFD = 2;
|
||||
pub const F_GETFL = 3;
|
||||
pub const F_SETFL = 4;
|
||||
pub const ASYNC = 0o20000;
|
||||
pub const DIRECT = 0o40000;
|
||||
pub const LARGEFILE = 0o100000;
|
||||
pub const NOATIME = 0o1000000;
|
||||
pub const PATH = 0o10000000;
|
||||
pub const TMPFILE = 0o20200000;
|
||||
pub const NDELAY = NONBLOCK;
|
||||
};
|
||||
|
||||
pub const F_SETOWN = 8;
|
||||
pub const F_GETOWN = 9;
|
||||
pub const F_SETSIG = 10;
|
||||
pub const F_GETSIG = 11;
|
||||
pub const F = struct {
|
||||
pub const DUPFD = 0;
|
||||
pub const GETFD = 1;
|
||||
pub const SETFD = 2;
|
||||
pub const GETFL = 3;
|
||||
pub const SETFL = 4;
|
||||
pub const SETOWN = 8;
|
||||
pub const GETOWN = 9;
|
||||
pub const SETSIG = 10;
|
||||
pub const GETSIG = 11;
|
||||
pub const GETLK = 12;
|
||||
pub const SETLK = 13;
|
||||
pub const SETLKW = 14;
|
||||
pub const SETOWN_EX = 15;
|
||||
pub const GETOWN_EX = 16;
|
||||
pub const GETOWNER_UIDS = 17;
|
||||
|
||||
pub const F_GETLK = 12;
|
||||
pub const F_SETLK = 13;
|
||||
pub const F_SETLKW = 14;
|
||||
pub const RDLCK = 0;
|
||||
pub const WRLCK = 1;
|
||||
pub const UNLCK = 2;
|
||||
};
|
||||
|
||||
pub const F_RDLCK = 0;
|
||||
pub const F_WRLCK = 1;
|
||||
pub const F_UNLCK = 2;
|
||||
pub const LOCK = struct {
|
||||
pub const SH = 1;
|
||||
pub const EX = 2;
|
||||
pub const NB = 4;
|
||||
pub const UN = 8;
|
||||
};
|
||||
|
||||
pub const LOCK_SH = 1;
|
||||
pub const LOCK_EX = 2;
|
||||
pub const LOCK_UN = 8;
|
||||
pub const LOCK_NB = 4;
|
||||
pub const MAP = struct {
|
||||
/// Share changes
|
||||
pub const SHARED = 0x01;
|
||||
|
||||
pub const F_SETOWN_EX = 15;
|
||||
pub const F_GETOWN_EX = 16;
|
||||
/// Changes are private
|
||||
pub const PRIVATE = 0x02;
|
||||
|
||||
pub const F_GETOWNER_UIDS = 17;
|
||||
/// share + validate extension flags
|
||||
pub const SHARED_VALIDATE = 0x03;
|
||||
|
||||
pub const MAP_NORESERVE = 0x4000;
|
||||
pub const MAP_GROWSDOWN = 0x0100;
|
||||
pub const MAP_DENYWRITE = 0x0800;
|
||||
pub const MAP_EXECUTABLE = 0x1000;
|
||||
pub const MAP_LOCKED = 0x2000;
|
||||
pub const MAP_32BIT = 0x40;
|
||||
/// Mask for type of mapping
|
||||
pub const TYPE = 0x0f;
|
||||
|
||||
/// Interpret addr exactly
|
||||
pub const FIXED = 0x10;
|
||||
|
||||
/// don't use a file
|
||||
pub const ANONYMOUS = if (is_mips) 0x800 else 0x20;
|
||||
|
||||
/// populate (prefault) pagetables
|
||||
pub const POPULATE = if (is_mips) 0x10000 else 0x8000;
|
||||
|
||||
/// do not block on IO
|
||||
pub const NONBLOCK = if (is_mips) 0x20000 else 0x10000;
|
||||
|
||||
/// give out an address that is best suited for process/thread stacks
|
||||
pub const STACK = if (is_mips) 0x40000 else 0x20000;
|
||||
|
||||
/// create a huge page mapping
|
||||
pub const HUGETLB = if (is_mips) 0x80000 else 0x40000;
|
||||
|
||||
/// perform synchronous page faults for the mapping
|
||||
pub const SYNC = 0x80000;
|
||||
|
||||
/// FIXED which doesn't unmap underlying mapping
|
||||
pub const FIXED_NOREPLACE = 0x100000;
|
||||
|
||||
/// For anonymous mmap, memory could be uninitialized
|
||||
pub const UNINITIALIZED = 0x4000000;
|
||||
|
||||
pub const NORESERVE = 0x4000;
|
||||
pub const GROWSDOWN = 0x0100;
|
||||
pub const DENYWRITE = 0x0800;
|
||||
pub const EXECUTABLE = 0x1000;
|
||||
pub const LOCKED = 0x2000;
|
||||
pub const @"32BIT" = 0x40;
|
||||
};
|
||||
|
||||
pub const MMAP2_UNIT = 4096;
|
||||
|
||||
pub const VDSO_CGT_SYM = "__vdso_clock_gettime";
|
||||
pub const VDSO_CGT_VER = "LINUX_2.6";
|
||||
pub const VDSO = struct {
|
||||
pub const CGT_SYM = "__vdso_clock_gettime";
|
||||
pub const CGT_VER = "LINUX_2.6";
|
||||
};
|
||||
|
||||
pub const ARCH = struct {};
|
||||
|
||||
pub const Flock = extern struct {
|
||||
l_type: i16,
|
||||
l_whence: i16,
|
||||
l_start: off_t,
|
||||
l_len: off_t,
|
||||
l_pid: pid_t,
|
||||
type: i16,
|
||||
whence: i16,
|
||||
start: off_t,
|
||||
len: off_t,
|
||||
pid: pid_t,
|
||||
};
|
||||
|
||||
pub const msghdr = extern struct {
|
||||
msg_name: ?*sockaddr,
|
||||
msg_namelen: socklen_t,
|
||||
msg_iov: [*]iovec,
|
||||
msg_iovlen: i32,
|
||||
msg_control: ?*c_void,
|
||||
msg_controllen: socklen_t,
|
||||
msg_flags: i32,
|
||||
name: ?*sockaddr,
|
||||
namelen: socklen_t,
|
||||
iov: [*]iovec,
|
||||
iovlen: i32,
|
||||
control: ?*c_void,
|
||||
controllen: socklen_t,
|
||||
flags: i32,
|
||||
};
|
||||
|
||||
pub const msghdr_const = extern struct {
|
||||
msg_name: ?*const sockaddr,
|
||||
msg_namelen: socklen_t,
|
||||
msg_iov: [*]iovec_const,
|
||||
msg_iovlen: i32,
|
||||
msg_control: ?*c_void,
|
||||
msg_controllen: socklen_t,
|
||||
msg_flags: i32,
|
||||
name: ?*const sockaddr,
|
||||
namelen: socklen_t,
|
||||
iov: [*]iovec_const,
|
||||
iovlen: i32,
|
||||
control: ?*c_void,
|
||||
controllen: socklen_t,
|
||||
flags: i32,
|
||||
};
|
||||
|
||||
pub const blksize_t = i32;
|
||||
@ -604,25 +655,27 @@ pub const mcontext_t = extern struct {
|
||||
cr2: usize,
|
||||
};
|
||||
|
||||
pub const REG_GS = 0;
|
||||
pub const REG_FS = 1;
|
||||
pub const REG_ES = 2;
|
||||
pub const REG_DS = 3;
|
||||
pub const REG_EDI = 4;
|
||||
pub const REG_ESI = 5;
|
||||
pub const REG_EBP = 6;
|
||||
pub const REG_ESP = 7;
|
||||
pub const REG_EBX = 8;
|
||||
pub const REG_EDX = 9;
|
||||
pub const REG_ECX = 10;
|
||||
pub const REG_EAX = 11;
|
||||
pub const REG_TRAPNO = 12;
|
||||
pub const REG_ERR = 13;
|
||||
pub const REG_EIP = 14;
|
||||
pub const REG_CS = 15;
|
||||
pub const REG_EFL = 16;
|
||||
pub const REG_UESP = 17;
|
||||
pub const REG_SS = 18;
|
||||
pub const REG = struct {
|
||||
pub const GS = 0;
|
||||
pub const FS = 1;
|
||||
pub const ES = 2;
|
||||
pub const DS = 3;
|
||||
pub const EDI = 4;
|
||||
pub const ESI = 5;
|
||||
pub const EBP = 6;
|
||||
pub const ESP = 7;
|
||||
pub const EBX = 8;
|
||||
pub const EDX = 9;
|
||||
pub const ECX = 10;
|
||||
pub const EAX = 11;
|
||||
pub const TRAPNO = 12;
|
||||
pub const ERR = 13;
|
||||
pub const EIP = 14;
|
||||
pub const CS = 15;
|
||||
pub const EFL = 16;
|
||||
pub const UESP = 17;
|
||||
pub const SS = 18;
|
||||
};
|
||||
|
||||
pub const ucontext_t = extern struct {
|
||||
flags: usize,
|
||||
@ -647,24 +700,26 @@ pub const user_desc = packed struct {
|
||||
useable: u1,
|
||||
};
|
||||
|
||||
// socketcall() call numbers
|
||||
pub const SC_socket = 1;
|
||||
pub const SC_bind = 2;
|
||||
pub const SC_connect = 3;
|
||||
pub const SC_listen = 4;
|
||||
pub const SC_accept = 5;
|
||||
pub const SC_getsockname = 6;
|
||||
pub const SC_getpeername = 7;
|
||||
pub const SC_socketpair = 8;
|
||||
pub const SC_send = 9;
|
||||
pub const SC_recv = 10;
|
||||
pub const SC_sendto = 11;
|
||||
pub const SC_recvfrom = 12;
|
||||
pub const SC_shutdown = 13;
|
||||
pub const SC_setsockopt = 14;
|
||||
pub const SC_getsockopt = 15;
|
||||
pub const SC_sendmsg = 16;
|
||||
pub const SC_recvmsg = 17;
|
||||
pub const SC_accept4 = 18;
|
||||
pub const SC_recvmmsg = 19;
|
||||
pub const SC_sendmmsg = 20;
|
||||
/// socketcall() call numbers
|
||||
pub const SC = struct {
|
||||
pub const socket = 1;
|
||||
pub const bind = 2;
|
||||
pub const connect = 3;
|
||||
pub const listen = 4;
|
||||
pub const accept = 5;
|
||||
pub const getsockname = 6;
|
||||
pub const getpeername = 7;
|
||||
pub const socketpair = 8;
|
||||
pub const send = 9;
|
||||
pub const recv = 10;
|
||||
pub const sendto = 11;
|
||||
pub const recvfrom = 12;
|
||||
pub const shutdown = 13;
|
||||
pub const setsockopt = 14;
|
||||
pub const getsockopt = 15;
|
||||
pub const sendmsg = 16;
|
||||
pub const recvmsg = 17;
|
||||
pub const accept4 = 18;
|
||||
pub const recvmmsg = 19;
|
||||
pub const sendmmsg = 20;
|
||||
};
|
||||
|
||||
@ -1,498 +0,0 @@
|
||||
usingnamespace @import("../linux.zig");
|
||||
|
||||
/// Routing/device hook
|
||||
pub const NETLINK_ROUTE = 0;
|
||||
|
||||
/// Unused number
|
||||
pub const NETLINK_UNUSED = 1;
|
||||
|
||||
/// Reserved for user mode socket protocols
|
||||
pub const NETLINK_USERSOCK = 2;
|
||||
|
||||
/// Unused number, formerly ip_queue
|
||||
pub const NETLINK_FIREWALL = 3;
|
||||
|
||||
/// socket monitoring
|
||||
pub const NETLINK_SOCK_DIAG = 4;
|
||||
|
||||
/// netfilter/iptables ULOG
|
||||
pub const NETLINK_NFLOG = 5;
|
||||
|
||||
/// ipsec
|
||||
pub const NETLINK_XFRM = 6;
|
||||
|
||||
/// SELinux event notifications
|
||||
pub const NETLINK_SELINUX = 7;
|
||||
|
||||
/// Open-iSCSI
|
||||
pub const NETLINK_ISCSI = 8;
|
||||
|
||||
/// auditing
|
||||
pub const NETLINK_AUDIT = 9;
|
||||
|
||||
pub const NETLINK_FIB_LOOKUP = 10;
|
||||
|
||||
pub const NETLINK_CONNECTOR = 11;
|
||||
|
||||
/// netfilter subsystem
|
||||
pub const NETLINK_NETFILTER = 12;
|
||||
|
||||
pub const NETLINK_IP6_FW = 13;
|
||||
|
||||
/// DECnet routing messages
|
||||
pub const NETLINK_DNRTMSG = 14;
|
||||
|
||||
/// Kernel messages to userspace
|
||||
pub const NETLINK_KOBJECT_UEVENT = 15;
|
||||
|
||||
pub const NETLINK_GENERIC = 16;
|
||||
|
||||
// leave room for NETLINK_DM (DM Events)
|
||||
|
||||
/// SCSI Transports
|
||||
pub const NETLINK_SCSITRANSPORT = 18;
|
||||
|
||||
pub const NETLINK_ECRYPTFS = 19;
|
||||
|
||||
pub const NETLINK_RDMA = 20;
|
||||
|
||||
/// Crypto layer
|
||||
pub const NETLINK_CRYPTO = 21;
|
||||
|
||||
/// SMC monitoring
|
||||
pub const NETLINK_SMC = 22;
|
||||
|
||||
// Flags values
|
||||
|
||||
/// It is request message.
|
||||
pub const NLM_F_REQUEST = 0x01;
|
||||
|
||||
/// Multipart message, terminated by NLMSG_DONE
|
||||
pub const NLM_F_MULTI = 0x02;
|
||||
|
||||
/// Reply with ack, with zero or error code
|
||||
pub const NLM_F_ACK = 0x04;
|
||||
|
||||
/// Echo this request
|
||||
pub const NLM_F_ECHO = 0x08;
|
||||
|
||||
/// Dump was inconsistent due to sequence change
|
||||
pub const NLM_F_DUMP_INTR = 0x10;
|
||||
|
||||
/// Dump was filtered as requested
|
||||
pub const NLM_F_DUMP_FILTERED = 0x20;
|
||||
|
||||
// Modifiers to GET request
|
||||
|
||||
/// specify tree root
|
||||
pub const NLM_F_ROOT = 0x100;
|
||||
|
||||
/// return all matching
|
||||
pub const NLM_F_MATCH = 0x200;
|
||||
|
||||
/// atomic GET
|
||||
pub const NLM_F_ATOMIC = 0x400;
|
||||
pub const NLM_F_DUMP = NLM_F_ROOT | NLM_F_MATCH;
|
||||
|
||||
// Modifiers to NEW request
|
||||
|
||||
/// Override existing
|
||||
pub const NLM_F_REPLACE = 0x100;
|
||||
|
||||
/// Do not touch, if it exists
|
||||
pub const NLM_F_EXCL = 0x200;
|
||||
|
||||
/// Create, if it does not exist
|
||||
pub const NLM_F_CREATE = 0x400;
|
||||
|
||||
/// Add to end of list
|
||||
pub const NLM_F_APPEND = 0x800;
|
||||
|
||||
// Modifiers to DELETE request
|
||||
|
||||
/// Do not delete recursively
|
||||
pub const NLM_F_NONREC = 0x100;
|
||||
|
||||
// Flags for ACK message
|
||||
|
||||
/// request was capped
|
||||
pub const NLM_F_CAPPED = 0x100;
|
||||
|
||||
/// extended ACK TVLs were included
|
||||
pub const NLM_F_ACK_TLVS = 0x200;
|
||||
|
||||
pub const NetlinkMessageType = enum(u16) {
|
||||
/// < 0x10: reserved control messages
|
||||
pub const MIN_TYPE = 0x10;
|
||||
|
||||
/// Nothing.
|
||||
NOOP = 0x1,
|
||||
|
||||
/// Error
|
||||
ERROR = 0x2,
|
||||
|
||||
/// End of a dump
|
||||
DONE = 0x3,
|
||||
|
||||
/// Data lost
|
||||
OVERRUN = 0x4,
|
||||
|
||||
// rtlink types
|
||||
|
||||
RTM_NEWLINK = 16,
|
||||
RTM_DELLINK,
|
||||
RTM_GETLINK,
|
||||
RTM_SETLINK,
|
||||
|
||||
RTM_NEWADDR = 20,
|
||||
RTM_DELADDR,
|
||||
RTM_GETADDR,
|
||||
|
||||
RTM_NEWROUTE = 24,
|
||||
RTM_DELROUTE,
|
||||
RTM_GETROUTE,
|
||||
|
||||
RTM_NEWNEIGH = 28,
|
||||
RTM_DELNEIGH,
|
||||
RTM_GETNEIGH,
|
||||
|
||||
RTM_NEWRULE = 32,
|
||||
RTM_DELRULE,
|
||||
RTM_GETRULE,
|
||||
|
||||
RTM_NEWQDISC = 36,
|
||||
RTM_DELQDISC,
|
||||
RTM_GETQDISC,
|
||||
|
||||
RTM_NEWTCLASS = 40,
|
||||
RTM_DELTCLASS,
|
||||
RTM_GETTCLASS,
|
||||
|
||||
RTM_NEWTFILTER = 44,
|
||||
RTM_DELTFILTER,
|
||||
RTM_GETTFILTER,
|
||||
|
||||
RTM_NEWACTION = 48,
|
||||
RTM_DELACTION,
|
||||
RTM_GETACTION,
|
||||
|
||||
RTM_NEWPREFIX = 52,
|
||||
|
||||
RTM_GETMULTICAST = 58,
|
||||
|
||||
RTM_GETANYCAST = 62,
|
||||
|
||||
RTM_NEWNEIGHTBL = 64,
|
||||
RTM_GETNEIGHTBL = 66,
|
||||
RTM_SETNEIGHTBL,
|
||||
|
||||
RTM_NEWNDUSEROPT = 68,
|
||||
|
||||
RTM_NEWADDRLABEL = 72,
|
||||
RTM_DELADDRLABEL,
|
||||
RTM_GETADDRLABEL,
|
||||
|
||||
RTM_GETDCB = 78,
|
||||
RTM_SETDCB,
|
||||
|
||||
RTM_NEWNETCONF = 80,
|
||||
RTM_DELNETCONF,
|
||||
RTM_GETNETCONF = 82,
|
||||
|
||||
RTM_NEWMDB = 84,
|
||||
RTM_DELMDB = 85,
|
||||
RTM_GETMDB = 86,
|
||||
|
||||
RTM_NEWNSID = 88,
|
||||
RTM_DELNSID = 89,
|
||||
RTM_GETNSID = 90,
|
||||
|
||||
RTM_NEWSTATS = 92,
|
||||
RTM_GETSTATS = 94,
|
||||
|
||||
RTM_NEWCACHEREPORT = 96,
|
||||
|
||||
RTM_NEWCHAIN = 100,
|
||||
RTM_DELCHAIN,
|
||||
RTM_GETCHAIN,
|
||||
|
||||
RTM_NEWNEXTHOP = 104,
|
||||
RTM_DELNEXTHOP,
|
||||
RTM_GETNEXTHOP,
|
||||
|
||||
_,
|
||||
};
|
||||
|
||||
/// Netlink socket address
|
||||
pub const sockaddr_nl = extern struct {
|
||||
family: sa_family_t = AF_NETLINK,
|
||||
__pad1: c_ushort = 0,
|
||||
|
||||
/// port ID
|
||||
pid: u32,
|
||||
|
||||
/// multicast groups mask
|
||||
groups: u32,
|
||||
};
|
||||
|
||||
/// Netlink message header
|
||||
/// Specified in RFC 3549 Section 2.3.2
|
||||
pub const nlmsghdr = extern struct {
|
||||
/// Length of message including header
|
||||
len: u32,
|
||||
|
||||
/// Message content
|
||||
@"type": NetlinkMessageType,
|
||||
|
||||
/// Additional flags
|
||||
flags: u16,
|
||||
|
||||
/// Sequence number
|
||||
seq: u32,
|
||||
|
||||
/// Sending process port ID
|
||||
pid: u32,
|
||||
};
|
||||
|
||||
pub const ifinfomsg = extern struct {
|
||||
family: u8,
|
||||
__pad1: u8 = 0,
|
||||
|
||||
/// ARPHRD_*
|
||||
@"type": c_ushort,
|
||||
|
||||
/// Link index
|
||||
index: c_int,
|
||||
|
||||
/// IFF_* flags
|
||||
flags: c_uint,
|
||||
|
||||
/// IFF_* change mask
|
||||
change: c_uint,
|
||||
};
|
||||
|
||||
pub const rtattr = extern struct {
|
||||
/// Length of option
|
||||
len: c_ushort,
|
||||
|
||||
/// Type of option
|
||||
@"type": IFLA,
|
||||
|
||||
pub const ALIGNTO = 4;
|
||||
};
|
||||
|
||||
pub const IFLA = enum(c_ushort) {
|
||||
UNSPEC,
|
||||
ADDRESS,
|
||||
BROADCAST,
|
||||
IFNAME,
|
||||
MTU,
|
||||
LINK,
|
||||
QDISC,
|
||||
STATS,
|
||||
COST,
|
||||
PRIORITY,
|
||||
MASTER,
|
||||
|
||||
/// Wireless Extension event
|
||||
WIRELESS,
|
||||
|
||||
/// Protocol specific information for a link
|
||||
PROTINFO,
|
||||
|
||||
TXQLEN,
|
||||
MAP,
|
||||
WEIGHT,
|
||||
OPERSTATE,
|
||||
LINKMODE,
|
||||
LINKINFO,
|
||||
NET_NS_PID,
|
||||
IFALIAS,
|
||||
|
||||
/// Number of VFs if device is SR-IOV PF
|
||||
NUM_VF,
|
||||
|
||||
VFINFO_LIST,
|
||||
STATS64,
|
||||
VF_PORTS,
|
||||
PORT_SELF,
|
||||
AF_SPEC,
|
||||
|
||||
/// Group the device belongs to
|
||||
GROUP,
|
||||
|
||||
NET_NS_FD,
|
||||
|
||||
/// Extended info mask, VFs, etc
|
||||
EXT_MASK,
|
||||
|
||||
/// Promiscuity count: > 0 means acts PROMISC
|
||||
PROMISCUITY,
|
||||
|
||||
NUM_TX_QUEUES,
|
||||
NUM_RX_QUEUES,
|
||||
CARRIER,
|
||||
PHYS_PORT_ID,
|
||||
CARRIER_CHANGES,
|
||||
PHYS_SWITCH_ID,
|
||||
LINK_NETNSID,
|
||||
PHYS_PORT_NAME,
|
||||
PROTO_DOWN,
|
||||
GSO_MAX_SEGS,
|
||||
GSO_MAX_SIZE,
|
||||
PAD,
|
||||
XDP,
|
||||
EVENT,
|
||||
|
||||
NEW_NETNSID,
|
||||
IF_NETNSID,
|
||||
|
||||
CARRIER_UP_COUNT,
|
||||
CARRIER_DOWN_COUNT,
|
||||
NEW_IFINDEX,
|
||||
MIN_MTU,
|
||||
MAX_MTU,
|
||||
|
||||
_,
|
||||
|
||||
pub const TARGET_NETNSID: IFLA = .IF_NETNSID;
|
||||
};
|
||||
|
||||
pub const rtnl_link_ifmap = extern struct {
|
||||
mem_start: u64,
|
||||
mem_end: u64,
|
||||
base_addr: u64,
|
||||
irq: u16,
|
||||
dma: u8,
|
||||
port: u8,
|
||||
};
|
||||
|
||||
pub const rtnl_link_stats = extern struct {
|
||||
/// total packets received
|
||||
rx_packets: u32,
|
||||
|
||||
/// total packets transmitted
|
||||
tx_packets: u32,
|
||||
|
||||
/// total bytes received
|
||||
rx_bytes: u32,
|
||||
|
||||
/// total bytes transmitted
|
||||
tx_bytes: u32,
|
||||
|
||||
/// bad packets received
|
||||
rx_errors: u32,
|
||||
|
||||
/// packet transmit problems
|
||||
tx_errors: u32,
|
||||
|
||||
/// no space in linux buffers
|
||||
rx_dropped: u32,
|
||||
|
||||
/// no space available in linux
|
||||
tx_dropped: u32,
|
||||
|
||||
/// multicast packets received
|
||||
multicast: u32,
|
||||
|
||||
collisions: u32,
|
||||
|
||||
// detailed rx_errors
|
||||
|
||||
rx_length_errors: u32,
|
||||
|
||||
/// receiver ring buff overflow
|
||||
rx_over_errors: u32,
|
||||
|
||||
/// recved pkt with crc error
|
||||
rx_crc_errors: u32,
|
||||
|
||||
/// recv'd frame alignment error
|
||||
rx_frame_errors: u32,
|
||||
|
||||
/// recv'r fifo overrun
|
||||
rx_fifo_errors: u32,
|
||||
|
||||
/// receiver missed packet
|
||||
rx_missed_errors: u32,
|
||||
|
||||
// detailed tx_errors
|
||||
tx_aborted_errors: u32,
|
||||
tx_carrier_errors: u32,
|
||||
tx_fifo_errors: u32,
|
||||
tx_heartbeat_errors: u32,
|
||||
tx_window_errors: u32,
|
||||
|
||||
// for cslip etc
|
||||
|
||||
rx_compressed: u32,
|
||||
tx_compressed: u32,
|
||||
|
||||
/// dropped, no handler found
|
||||
rx_nohandler: u32,
|
||||
};
|
||||
|
||||
pub const rtnl_link_stats64 = extern struct {
|
||||
/// total packets received
|
||||
rx_packets: u64,
|
||||
|
||||
/// total packets transmitted
|
||||
tx_packets: u64,
|
||||
|
||||
/// total bytes received
|
||||
rx_bytes: u64,
|
||||
|
||||
/// total bytes transmitted
|
||||
tx_bytes: u64,
|
||||
|
||||
/// bad packets received
|
||||
rx_errors: u64,
|
||||
|
||||
/// packet transmit problems
|
||||
tx_errors: u64,
|
||||
|
||||
/// no space in linux buffers
|
||||
rx_dropped: u64,
|
||||
|
||||
/// no space available in linux
|
||||
tx_dropped: u64,
|
||||
|
||||
/// multicast packets received
|
||||
multicast: u64,
|
||||
|
||||
collisions: u64,
|
||||
|
||||
// detailed rx_errors
|
||||
|
||||
rx_length_errors: u64,
|
||||
|
||||
/// receiver ring buff overflow
|
||||
rx_over_errors: u64,
|
||||
|
||||
/// recved pkt with crc error
|
||||
rx_crc_errors: u64,
|
||||
|
||||
/// recv'd frame alignment error
|
||||
rx_frame_errors: u64,
|
||||
|
||||
/// recv'r fifo overrun
|
||||
rx_fifo_errors: u64,
|
||||
|
||||
/// receiver missed packet
|
||||
rx_missed_errors: u64,
|
||||
|
||||
// detailed tx_errors
|
||||
tx_aborted_errors: u64,
|
||||
tx_carrier_errors: u64,
|
||||
tx_fifo_errors: u64,
|
||||
tx_heartbeat_errors: u64,
|
||||
tx_window_errors: u64,
|
||||
|
||||
// for cslip etc
|
||||
|
||||
rx_compressed: u64,
|
||||
tx_compressed: u64,
|
||||
|
||||
/// dropped, no handler found
|
||||
rx_nohandler: u64,
|
||||
};
|
||||
@ -1,234 +0,0 @@
|
||||
pub const PR = enum(i32) {
|
||||
SET_PDEATHSIG = 1,
|
||||
GET_PDEATHSIG = 2,
|
||||
|
||||
GET_DUMPABLE = 3,
|
||||
SET_DUMPABLE = 4,
|
||||
|
||||
GET_UNALIGN = 5,
|
||||
SET_UNALIGN = 6,
|
||||
|
||||
GET_KEEPCAPS = 7,
|
||||
SET_KEEPCAPS = 8,
|
||||
|
||||
GET_FPEMU = 9,
|
||||
SET_FPEMU = 10,
|
||||
|
||||
GET_FPEXC = 11,
|
||||
SET_FPEXC = 12,
|
||||
|
||||
GET_TIMING = 13,
|
||||
SET_TIMING = 14,
|
||||
|
||||
SET_NAME = 15,
|
||||
GET_NAME = 16,
|
||||
|
||||
GET_ENDIAN = 19,
|
||||
SET_ENDIAN = 20,
|
||||
|
||||
GET_SECCOMP = 21,
|
||||
SET_SECCOMP = 22,
|
||||
|
||||
CAPBSET_READ = 23,
|
||||
CAPBSET_DROP = 24,
|
||||
|
||||
GET_TSC = 25,
|
||||
SET_TSC = 26,
|
||||
|
||||
GET_SECUREBITS = 27,
|
||||
SET_SECUREBITS = 28,
|
||||
|
||||
SET_TIMERSLACK = 29,
|
||||
GET_TIMERSLACK = 30,
|
||||
|
||||
TASK_PERF_EVENTS_DISABLE = 31,
|
||||
TASK_PERF_EVENTS_ENABLE = 32,
|
||||
|
||||
MCE_KILL = 33,
|
||||
|
||||
MCE_KILL_GET = 34,
|
||||
|
||||
SET_MM = 35,
|
||||
|
||||
SET_PTRACER = 0x59616d61,
|
||||
|
||||
SET_CHILD_SUBREAPER = 36,
|
||||
GET_CHILD_SUBREAPER = 37,
|
||||
|
||||
SET_NO_NEW_PRIVS = 38,
|
||||
GET_NO_NEW_PRIVS = 39,
|
||||
|
||||
GET_TID_ADDRESS = 40,
|
||||
|
||||
SET_THP_DISABLE = 41,
|
||||
GET_THP_DISABLE = 42,
|
||||
|
||||
MPX_ENABLE_MANAGEMENT = 43,
|
||||
MPX_DISABLE_MANAGEMENT = 44,
|
||||
|
||||
SET_FP_MODE = 45,
|
||||
GET_FP_MODE = 46,
|
||||
|
||||
CAP_AMBIENT = 47,
|
||||
|
||||
SVE_SET_VL = 50,
|
||||
SVE_GET_VL = 51,
|
||||
|
||||
GET_SPECULATION_CTRL = 52,
|
||||
SET_SPECULATION_CTRL = 53,
|
||||
|
||||
_,
|
||||
};
|
||||
|
||||
pub const PR_SET_PDEATHSIG = @enumToInt(PR.SET_PDEATHSIG);
|
||||
pub const PR_GET_PDEATHSIG = @enumToInt(PR.GET_PDEATHSIG);
|
||||
|
||||
pub const PR_GET_DUMPABLE = @enumToInt(PR.GET_DUMPABLE);
|
||||
pub const PR_SET_DUMPABLE = @enumToInt(PR.SET_DUMPABLE);
|
||||
|
||||
pub const PR_GET_UNALIGN = @enumToInt(PR.GET_UNALIGN);
|
||||
pub const PR_SET_UNALIGN = @enumToInt(PR.SET_UNALIGN);
|
||||
pub const PR_UNALIGN_NOPRINT = 1;
|
||||
pub const PR_UNALIGN_SIGBUS = 2;
|
||||
|
||||
pub const PR_GET_KEEPCAPS = @enumToInt(PR.GET_KEEPCAPS);
|
||||
pub const PR_SET_KEEPCAPS = @enumToInt(PR.SET_KEEPCAPS);
|
||||
|
||||
pub const PR_GET_FPEMU = @enumToInt(PR.GET_FPEMU);
|
||||
pub const PR_SET_FPEMU = @enumToInt(PR.SET_FPEMU);
|
||||
pub const PR_FPEMU_NOPRINT = 1;
|
||||
pub const PR_FPEMU_SIGFPE = 2;
|
||||
|
||||
pub const PR_GET_FPEXC = @enumToInt(PR.GET_FPEXC);
|
||||
pub const PR_SET_FPEXC = @enumToInt(PR.SET_FPEXC);
|
||||
pub const PR_FP_EXC_SW_ENABLE = 0x80;
|
||||
pub const PR_FP_EXC_DIV = 0x010000;
|
||||
pub const PR_FP_EXC_OVF = 0x020000;
|
||||
pub const PR_FP_EXC_UND = 0x040000;
|
||||
pub const PR_FP_EXC_RES = 0x080000;
|
||||
pub const PR_FP_EXC_INV = 0x100000;
|
||||
pub const PR_FP_EXC_DISABLED = 0;
|
||||
pub const PR_FP_EXC_NONRECOV = 1;
|
||||
pub const PR_FP_EXC_ASYNC = 2;
|
||||
pub const PR_FP_EXC_PRECISE = 3;
|
||||
|
||||
pub const PR_GET_TIMING = @enumToInt(PR.GET_TIMING);
|
||||
pub const PR_SET_TIMING = @enumToInt(PR.SET_TIMING);
|
||||
pub const PR_TIMING_STATISTICAL = 0;
|
||||
pub const PR_TIMING_TIMESTAMP = 1;
|
||||
|
||||
pub const PR_SET_NAME = @enumToInt(PR.SET_NAME);
|
||||
pub const PR_GET_NAME = @enumToInt(PR.GET_NAME);
|
||||
|
||||
pub const PR_GET_ENDIAN = @enumToInt(PR.GET_ENDIAN);
|
||||
pub const PR_SET_ENDIAN = @enumToInt(PR.SET_ENDIAN);
|
||||
pub const PR_ENDIAN_BIG = 0;
|
||||
pub const PR_ENDIAN_LITTLE = 1;
|
||||
pub const PR_ENDIAN_PPC_LITTLE = 2;
|
||||
|
||||
pub const PR_GET_SECCOMP = @enumToInt(PR.GET_SECCOMP);
|
||||
pub const PR_SET_SECCOMP = @enumToInt(PR.SET_SECCOMP);
|
||||
|
||||
pub const PR_CAPBSET_READ = @enumToInt(PR.CAPBSET_READ);
|
||||
pub const PR_CAPBSET_DROP = @enumToInt(PR.CAPBSET_DROP);
|
||||
|
||||
pub const PR_GET_TSC = @enumToInt(PR.GET_TSC);
|
||||
pub const PR_SET_TSC = @enumToInt(PR.SET_TSC);
|
||||
pub const PR_TSC_ENABLE = 1;
|
||||
pub const PR_TSC_SIGSEGV = 2;
|
||||
|
||||
pub const PR_GET_SECUREBITS = @enumToInt(PR.GET_SECUREBITS);
|
||||
pub const PR_SET_SECUREBITS = @enumToInt(PR.SET_SECUREBITS);
|
||||
|
||||
pub const PR_SET_TIMERSLACK = @enumToInt(PR.SET_TIMERSLACK);
|
||||
pub const PR_GET_TIMERSLACK = @enumToInt(PR.GET_TIMERSLACK);
|
||||
|
||||
pub const PR_TASK_PERF_EVENTS_DISABLE = @enumToInt(PR.TASK_PERF_EVENTS_DISABLE);
|
||||
pub const PR_TASK_PERF_EVENTS_ENABLE = @enumToInt(PR.TASK_PERF_EVENTS_ENABLE);
|
||||
|
||||
pub const PR_MCE_KILL = @enumToInt(PR.MCE_KILL);
|
||||
pub const PR_MCE_KILL_CLEAR = 0;
|
||||
pub const PR_MCE_KILL_SET = 1;
|
||||
|
||||
pub const PR_MCE_KILL_LATE = 0;
|
||||
pub const PR_MCE_KILL_EARLY = 1;
|
||||
pub const PR_MCE_KILL_DEFAULT = 2;
|
||||
|
||||
pub const PR_MCE_KILL_GET = @enumToInt(PR.MCE_KILL_GET);
|
||||
|
||||
pub const PR_SET_MM = @enumToInt(PR.SET_MM);
|
||||
pub const PR_SET_MM_START_CODE = 1;
|
||||
pub const PR_SET_MM_END_CODE = 2;
|
||||
pub const PR_SET_MM_START_DATA = 3;
|
||||
pub const PR_SET_MM_END_DATA = 4;
|
||||
pub const PR_SET_MM_START_STACK = 5;
|
||||
pub const PR_SET_MM_START_BRK = 6;
|
||||
pub const PR_SET_MM_BRK = 7;
|
||||
pub const PR_SET_MM_ARG_START = 8;
|
||||
pub const PR_SET_MM_ARG_END = 9;
|
||||
pub const PR_SET_MM_ENV_START = 10;
|
||||
pub const PR_SET_MM_ENV_END = 11;
|
||||
pub const PR_SET_MM_AUXV = 12;
|
||||
pub const PR_SET_MM_EXE_FILE = 13;
|
||||
pub const PR_SET_MM_MAP = 14;
|
||||
pub const PR_SET_MM_MAP_SIZE = 15;
|
||||
|
||||
pub const prctl_mm_map = extern struct {
|
||||
start_code: u64,
|
||||
end_code: u64,
|
||||
start_data: u64,
|
||||
end_data: u64,
|
||||
start_brk: u64,
|
||||
brk: u64,
|
||||
start_stack: u64,
|
||||
arg_start: u64,
|
||||
arg_end: u64,
|
||||
env_start: u64,
|
||||
env_end: u64,
|
||||
auxv: *u64,
|
||||
auxv_size: u32,
|
||||
exe_fd: u32,
|
||||
};
|
||||
|
||||
pub const PR_SET_PTRACER = @enumToInt(PR.SET_PTRACER);
|
||||
pub const PR_SET_PTRACER_ANY = std.math.maxInt(c_ulong);
|
||||
|
||||
pub const PR_SET_CHILD_SUBREAPER = @enumToInt(PR.SET_CHILD_SUBREAPER);
|
||||
pub const PR_GET_CHILD_SUBREAPER = @enumToInt(PR.GET_CHILD_SUBREAPER);
|
||||
|
||||
pub const PR_SET_NO_NEW_PRIVS = @enumToInt(PR.SET_NO_NEW_PRIVS);
|
||||
pub const PR_GET_NO_NEW_PRIVS = @enumToInt(PR.GET_NO_NEW_PRIVS);
|
||||
|
||||
pub const PR_GET_TID_ADDRESS = @enumToInt(PR.GET_TID_ADDRESS);
|
||||
|
||||
pub const PR_SET_THP_DISABLE = @enumToInt(PR.SET_THP_DISABLE);
|
||||
pub const PR_GET_THP_DISABLE = @enumToInt(PR.GET_THP_DISABLE);
|
||||
|
||||
pub const PR_MPX_ENABLE_MANAGEMENT = @enumToInt(PR.MPX_ENABLE_MANAGEMENT);
|
||||
pub const PR_MPX_DISABLE_MANAGEMENT = @enumToInt(PR.MPX_DISABLE_MANAGEMENT);
|
||||
|
||||
pub const PR_SET_FP_MODE = @enumToInt(PR.SET_FP_MODE);
|
||||
pub const PR_GET_FP_MODE = @enumToInt(PR.GET_FP_MODE);
|
||||
pub const PR_FP_MODE_FR = 1 << 0;
|
||||
pub const PR_FP_MODE_FRE = 1 << 1;
|
||||
|
||||
pub const PR_CAP_AMBIENT = @enumToInt(PR.CAP_AMBIENT);
|
||||
pub const PR_CAP_AMBIENT_IS_SET = 1;
|
||||
pub const PR_CAP_AMBIENT_RAISE = 2;
|
||||
pub const PR_CAP_AMBIENT_LOWER = 3;
|
||||
pub const PR_CAP_AMBIENT_CLEAR_ALL = 4;
|
||||
|
||||
pub const PR_SVE_SET_VL = @enumToInt(PR.SVE_SET_VL);
|
||||
pub const PR_SVE_SET_VL_ONEXEC = 1 << 18;
|
||||
pub const PR_SVE_GET_VL = @enumToInt(PR.SVE_GET_VL);
|
||||
pub const PR_SVE_VL_LEN_MASK = 0xffff;
|
||||
pub const PR_SVE_VL_INHERIT = 1 << 17;
|
||||
|
||||
pub const PR_GET_SPECULATION_CTRL = @enumToInt(PR.GET_SPECULATION_CTRL);
|
||||
pub const PR_SET_SPECULATION_CTRL = @enumToInt(PR.SET_SPECULATION_CTRL);
|
||||
pub const PR_SPEC_STORE_BYPASS = 0;
|
||||
pub const PR_SPEC_NOT_AFFECTED = 0;
|
||||
pub const PR_SPEC_PRCTL = 1 << 0;
|
||||
pub const PR_SPEC_ENABLE = 1 << 1;
|
||||
pub const PR_SPEC_DISABLE = 1 << 2;
|
||||
pub const PR_SPEC_FORCE_DISABLE = 1 << 3;
|
||||
@ -1,35 +0,0 @@
|
||||
fn issecure_mask(comptime x: comptime_int) comptime_int {
|
||||
return 1 << x;
|
||||
}
|
||||
|
||||
pub const SECUREBITS_DEFAULT = 0x00000000;
|
||||
|
||||
pub const SECURE_NOROOT = 0;
|
||||
pub const SECURE_NOROOT_LOCKED = 1;
|
||||
|
||||
pub const SECBIT_NOROOT = issecure_mask(SECURE_NOROOT);
|
||||
pub const SECBIT_NOROOT_LOCKED = issecure_mask(SECURE_NOROOT_LOCKED);
|
||||
|
||||
pub const SECURE_NO_SETUID_FIXUP = 2;
|
||||
pub const SECURE_NO_SETUID_FIXUP_LOCKED = 3;
|
||||
|
||||
pub const SECBIT_NO_SETUID_FIXUP = issecure_mask(SECURE_NO_SETUID_FIXUP);
|
||||
pub const SECBIT_NO_SETUID_FIXUP_LOCKED = issecure_mask(SECURE_NO_SETUID_FIXUP_LOCKED);
|
||||
|
||||
pub const SECURE_KEEP_CAPS = 4;
|
||||
pub const SECURE_KEEP_CAPS_LOCKED = 5;
|
||||
|
||||
pub const SECBIT_KEEP_CAPS = issecure_mask(SECURE_KEEP_CAPS);
|
||||
pub const SECBIT_KEEP_CAPS_LOCKED = issecure_mask(SECURE_KEEP_CAPS_LOCKED);
|
||||
|
||||
pub const SECURE_NO_CAP_AMBIENT_RAISE = 6;
|
||||
pub const SECURE_NO_CAP_AMBIENT_RAISE_LOCKED = 7;
|
||||
|
||||
pub const SECBIT_NO_CAP_AMBIENT_RAISE = issecure_mask(SECURE_NO_CAP_AMBIENT_RAISE);
|
||||
pub const SECBIT_NO_CAP_AMBIENT_RAISE_LOCKED = issecure_mask(SECURE_NO_CAP_AMBIENT_RAISE_LOCKED);
|
||||
|
||||
pub const SECURE_ALL_BITS = issecure_mask(SECURE_NOROOT) |
|
||||
issecure_mask(SECURE_NO_SETUID_FIXUP) |
|
||||
issecure_mask(SECURE_KEEP_CAPS) |
|
||||
issecure_mask(SECURE_NO_CAP_AMBIENT_RAISE);
|
||||
pub const SECURE_ALL_LOCKS = SECURE_ALL_BITS << 1;
|
||||
@ -1,638 +0,0 @@
|
||||
// x86-64-specific declarations that are intended to be imported into the POSIX namespace.
|
||||
const std = @import("../../../std.zig");
|
||||
const pid_t = linux.pid_t;
|
||||
const uid_t = linux.uid_t;
|
||||
const gid_t = linux.gid_t;
|
||||
const clock_t = linux.clock_t;
|
||||
const stack_t = linux.stack_t;
|
||||
const sigset_t = linux.sigset_t;
|
||||
|
||||
const linux = std.os.linux;
|
||||
const sockaddr = linux.sockaddr;
|
||||
const socklen_t = linux.socklen_t;
|
||||
const iovec = linux.iovec;
|
||||
const iovec_const = linux.iovec_const;
|
||||
|
||||
pub const mode_t = usize;
|
||||
pub const time_t = isize;
|
||||
|
||||
pub const SYS = enum(usize) {
|
||||
read = 0,
|
||||
write = 1,
|
||||
open = 2,
|
||||
close = 3,
|
||||
stat = 4,
|
||||
fstat = 5,
|
||||
lstat = 6,
|
||||
poll = 7,
|
||||
lseek = 8,
|
||||
mmap = 9,
|
||||
mprotect = 10,
|
||||
munmap = 11,
|
||||
brk = 12,
|
||||
rt_sigaction = 13,
|
||||
rt_sigprocmask = 14,
|
||||
rt_sigreturn = 15,
|
||||
ioctl = 16,
|
||||
pread = 17,
|
||||
pwrite = 18,
|
||||
readv = 19,
|
||||
writev = 20,
|
||||
access = 21,
|
||||
pipe = 22,
|
||||
select = 23,
|
||||
sched_yield = 24,
|
||||
mremap = 25,
|
||||
msync = 26,
|
||||
mincore = 27,
|
||||
madvise = 28,
|
||||
shmget = 29,
|
||||
shmat = 30,
|
||||
shmctl = 31,
|
||||
dup = 32,
|
||||
dup2 = 33,
|
||||
pause = 34,
|
||||
nanosleep = 35,
|
||||
getitimer = 36,
|
||||
alarm = 37,
|
||||
setitimer = 38,
|
||||
getpid = 39,
|
||||
sendfile = 40,
|
||||
socket = 41,
|
||||
connect = 42,
|
||||
accept = 43,
|
||||
sendto = 44,
|
||||
recvfrom = 45,
|
||||
sendmsg = 46,
|
||||
recvmsg = 47,
|
||||
shutdown = 48,
|
||||
bind = 49,
|
||||
listen = 50,
|
||||
getsockname = 51,
|
||||
getpeername = 52,
|
||||
socketpair = 53,
|
||||
setsockopt = 54,
|
||||
getsockopt = 55,
|
||||
clone = 56,
|
||||
fork = 57,
|
||||
vfork = 58,
|
||||
execve = 59,
|
||||
exit = 60,
|
||||
wait4 = 61,
|
||||
kill = 62,
|
||||
uname = 63,
|
||||
semget = 64,
|
||||
semop = 65,
|
||||
semctl = 66,
|
||||
shmdt = 67,
|
||||
msgget = 68,
|
||||
msgsnd = 69,
|
||||
msgrcv = 70,
|
||||
msgctl = 71,
|
||||
fcntl = 72,
|
||||
flock = 73,
|
||||
fsync = 74,
|
||||
fdatasync = 75,
|
||||
truncate = 76,
|
||||
ftruncate = 77,
|
||||
getdents = 78,
|
||||
getcwd = 79,
|
||||
chdir = 80,
|
||||
fchdir = 81,
|
||||
rename = 82,
|
||||
mkdir = 83,
|
||||
rmdir = 84,
|
||||
creat = 85,
|
||||
link = 86,
|
||||
unlink = 87,
|
||||
symlink = 88,
|
||||
readlink = 89,
|
||||
chmod = 90,
|
||||
fchmod = 91,
|
||||
chown = 92,
|
||||
fchown = 93,
|
||||
lchown = 94,
|
||||
umask = 95,
|
||||
gettimeofday = 96,
|
||||
getrlimit = 97,
|
||||
getrusage = 98,
|
||||
sysinfo = 99,
|
||||
times = 100,
|
||||
ptrace = 101,
|
||||
getuid = 102,
|
||||
syslog = 103,
|
||||
getgid = 104,
|
||||
setuid = 105,
|
||||
setgid = 106,
|
||||
geteuid = 107,
|
||||
getegid = 108,
|
||||
setpgid = 109,
|
||||
getppid = 110,
|
||||
getpgrp = 111,
|
||||
setsid = 112,
|
||||
setreuid = 113,
|
||||
setregid = 114,
|
||||
getgroups = 115,
|
||||
setgroups = 116,
|
||||
setresuid = 117,
|
||||
getresuid = 118,
|
||||
setresgid = 119,
|
||||
getresgid = 120,
|
||||
getpgid = 121,
|
||||
setfsuid = 122,
|
||||
setfsgid = 123,
|
||||
getsid = 124,
|
||||
capget = 125,
|
||||
capset = 126,
|
||||
rt_sigpending = 127,
|
||||
rt_sigtimedwait = 128,
|
||||
rt_sigqueueinfo = 129,
|
||||
rt_sigsuspend = 130,
|
||||
sigaltstack = 131,
|
||||
utime = 132,
|
||||
mknod = 133,
|
||||
uselib = 134,
|
||||
personality = 135,
|
||||
ustat = 136,
|
||||
statfs = 137,
|
||||
fstatfs = 138,
|
||||
sysfs = 139,
|
||||
getpriority = 140,
|
||||
setpriority = 141,
|
||||
sched_setparam = 142,
|
||||
sched_getparam = 143,
|
||||
sched_setscheduler = 144,
|
||||
sched_getscheduler = 145,
|
||||
sched_get_priority_max = 146,
|
||||
sched_get_priority_min = 147,
|
||||
sched_rr_get_interval = 148,
|
||||
mlock = 149,
|
||||
munlock = 150,
|
||||
mlockall = 151,
|
||||
munlockall = 152,
|
||||
vhangup = 153,
|
||||
modify_ldt = 154,
|
||||
pivot_root = 155,
|
||||
_sysctl = 156,
|
||||
prctl = 157,
|
||||
arch_prctl = 158,
|
||||
adjtimex = 159,
|
||||
setrlimit = 160,
|
||||
chroot = 161,
|
||||
sync = 162,
|
||||
acct = 163,
|
||||
settimeofday = 164,
|
||||
mount = 165,
|
||||
umount2 = 166,
|
||||
swapon = 167,
|
||||
swapoff = 168,
|
||||
reboot = 169,
|
||||
sethostname = 170,
|
||||
setdomainname = 171,
|
||||
iopl = 172,
|
||||
ioperm = 173,
|
||||
create_module = 174,
|
||||
init_module = 175,
|
||||
delete_module = 176,
|
||||
get_kernel_syms = 177,
|
||||
query_module = 178,
|
||||
quotactl = 179,
|
||||
nfsservctl = 180,
|
||||
getpmsg = 181,
|
||||
putpmsg = 182,
|
||||
afs_syscall = 183,
|
||||
tuxcall = 184,
|
||||
security = 185,
|
||||
gettid = 186,
|
||||
readahead = 187,
|
||||
setxattr = 188,
|
||||
lsetxattr = 189,
|
||||
fsetxattr = 190,
|
||||
getxattr = 191,
|
||||
lgetxattr = 192,
|
||||
fgetxattr = 193,
|
||||
listxattr = 194,
|
||||
llistxattr = 195,
|
||||
flistxattr = 196,
|
||||
removexattr = 197,
|
||||
lremovexattr = 198,
|
||||
fremovexattr = 199,
|
||||
tkill = 200,
|
||||
time = 201,
|
||||
futex = 202,
|
||||
sched_setaffinity = 203,
|
||||
sched_getaffinity = 204,
|
||||
set_thread_area = 205,
|
||||
io_setup = 206,
|
||||
io_destroy = 207,
|
||||
io_getevents = 208,
|
||||
io_submit = 209,
|
||||
io_cancel = 210,
|
||||
get_thread_area = 211,
|
||||
lookup_dcookie = 212,
|
||||
epoll_create = 213,
|
||||
epoll_ctl_old = 214,
|
||||
epoll_wait_old = 215,
|
||||
remap_file_pages = 216,
|
||||
getdents64 = 217,
|
||||
set_tid_address = 218,
|
||||
restart_syscall = 219,
|
||||
semtimedop = 220,
|
||||
fadvise64 = 221,
|
||||
timer_create = 222,
|
||||
timer_settime = 223,
|
||||
timer_gettime = 224,
|
||||
timer_getoverrun = 225,
|
||||
timer_delete = 226,
|
||||
clock_settime = 227,
|
||||
clock_gettime = 228,
|
||||
clock_getres = 229,
|
||||
clock_nanosleep = 230,
|
||||
exit_group = 231,
|
||||
epoll_wait = 232,
|
||||
epoll_ctl = 233,
|
||||
tgkill = 234,
|
||||
utimes = 235,
|
||||
vserver = 236,
|
||||
mbind = 237,
|
||||
set_mempolicy = 238,
|
||||
get_mempolicy = 239,
|
||||
mq_open = 240,
|
||||
mq_unlink = 241,
|
||||
mq_timedsend = 242,
|
||||
mq_timedreceive = 243,
|
||||
mq_notify = 244,
|
||||
mq_getsetattr = 245,
|
||||
kexec_load = 246,
|
||||
waitid = 247,
|
||||
add_key = 248,
|
||||
request_key = 249,
|
||||
keyctl = 250,
|
||||
ioprio_set = 251,
|
||||
ioprio_get = 252,
|
||||
inotify_init = 253,
|
||||
inotify_add_watch = 254,
|
||||
inotify_rm_watch = 255,
|
||||
migrate_pages = 256,
|
||||
openat = 257,
|
||||
mkdirat = 258,
|
||||
mknodat = 259,
|
||||
fchownat = 260,
|
||||
futimesat = 261,
|
||||
fstatat = 262,
|
||||
unlinkat = 263,
|
||||
renameat = 264,
|
||||
linkat = 265,
|
||||
symlinkat = 266,
|
||||
readlinkat = 267,
|
||||
fchmodat = 268,
|
||||
faccessat = 269,
|
||||
pselect6 = 270,
|
||||
ppoll = 271,
|
||||
unshare = 272,
|
||||
set_robust_list = 273,
|
||||
get_robust_list = 274,
|
||||
splice = 275,
|
||||
tee = 276,
|
||||
sync_file_range = 277,
|
||||
vmsplice = 278,
|
||||
move_pages = 279,
|
||||
utimensat = 280,
|
||||
epoll_pwait = 281,
|
||||
signalfd = 282,
|
||||
timerfd_create = 283,
|
||||
eventfd = 284,
|
||||
fallocate = 285,
|
||||
timerfd_settime = 286,
|
||||
timerfd_gettime = 287,
|
||||
accept4 = 288,
|
||||
signalfd4 = 289,
|
||||
eventfd2 = 290,
|
||||
epoll_create1 = 291,
|
||||
dup3 = 292,
|
||||
pipe2 = 293,
|
||||
inotify_init1 = 294,
|
||||
preadv = 295,
|
||||
pwritev = 296,
|
||||
rt_tgsigqueueinfo = 297,
|
||||
perf_event_open = 298,
|
||||
recvmmsg = 299,
|
||||
fanotify_init = 300,
|
||||
fanotify_mark = 301,
|
||||
prlimit64 = 302,
|
||||
name_to_handle_at = 303,
|
||||
open_by_handle_at = 304,
|
||||
clock_adjtime = 305,
|
||||
syncfs = 306,
|
||||
sendmmsg = 307,
|
||||
setns = 308,
|
||||
getcpu = 309,
|
||||
process_vm_readv = 310,
|
||||
process_vm_writev = 311,
|
||||
kcmp = 312,
|
||||
finit_module = 313,
|
||||
sched_setattr = 314,
|
||||
sched_getattr = 315,
|
||||
renameat2 = 316,
|
||||
seccomp = 317,
|
||||
getrandom = 318,
|
||||
memfd_create = 319,
|
||||
kexec_file_load = 320,
|
||||
bpf = 321,
|
||||
execveat = 322,
|
||||
userfaultfd = 323,
|
||||
membarrier = 324,
|
||||
mlock2 = 325,
|
||||
copy_file_range = 326,
|
||||
preadv2 = 327,
|
||||
pwritev2 = 328,
|
||||
pkey_mprotect = 329,
|
||||
pkey_alloc = 330,
|
||||
pkey_free = 331,
|
||||
statx = 332,
|
||||
io_pgetevents = 333,
|
||||
rseq = 334,
|
||||
pidfd_send_signal = 424,
|
||||
io_uring_setup = 425,
|
||||
io_uring_enter = 426,
|
||||
io_uring_register = 427,
|
||||
open_tree = 428,
|
||||
move_mount = 429,
|
||||
fsopen = 430,
|
||||
fsconfig = 431,
|
||||
fsmount = 432,
|
||||
fspick = 433,
|
||||
pidfd_open = 434,
|
||||
clone3 = 435,
|
||||
close_range = 436,
|
||||
openat2 = 437,
|
||||
pidfd_getfd = 438,
|
||||
faccessat2 = 439,
|
||||
process_madvise = 440,
|
||||
epoll_pwait2 = 441,
|
||||
|
||||
_,
|
||||
};
|
||||
|
||||
pub const O_CREAT = 0o100;
|
||||
pub const O_EXCL = 0o200;
|
||||
pub const O_NOCTTY = 0o400;
|
||||
pub const O_TRUNC = 0o1000;
|
||||
pub const O_APPEND = 0o2000;
|
||||
pub const O_NONBLOCK = 0o4000;
|
||||
pub const O_DSYNC = 0o10000;
|
||||
pub const O_SYNC = 0o4010000;
|
||||
pub const O_RSYNC = 0o4010000;
|
||||
pub const O_DIRECTORY = 0o200000;
|
||||
pub const O_NOFOLLOW = 0o400000;
|
||||
pub const O_CLOEXEC = 0o2000000;
|
||||
|
||||
pub const O_ASYNC = 0o20000;
|
||||
pub const O_DIRECT = 0o40000;
|
||||
pub const O_LARGEFILE = 0;
|
||||
pub const O_NOATIME = 0o1000000;
|
||||
pub const O_PATH = 0o10000000;
|
||||
pub const O_TMPFILE = 0o20200000;
|
||||
pub const O_NDELAY = O_NONBLOCK;
|
||||
|
||||
pub const F_DUPFD = 0;
|
||||
pub const F_GETFD = 1;
|
||||
pub const F_SETFD = 2;
|
||||
pub const F_GETFL = 3;
|
||||
pub const F_SETFL = 4;
|
||||
|
||||
pub const F_SETOWN = 8;
|
||||
pub const F_GETOWN = 9;
|
||||
pub const F_SETSIG = 10;
|
||||
pub const F_GETSIG = 11;
|
||||
|
||||
pub const F_GETLK = 5;
|
||||
pub const F_SETLK = 6;
|
||||
pub const F_SETLKW = 7;
|
||||
|
||||
pub const F_SETOWN_EX = 15;
|
||||
pub const F_GETOWN_EX = 16;
|
||||
|
||||
pub const F_GETOWNER_UIDS = 17;
|
||||
|
||||
/// only give out 32bit addresses
|
||||
pub const MAP_32BIT = 0x40;
|
||||
|
||||
/// stack-like segment
|
||||
pub const MAP_GROWSDOWN = 0x0100;
|
||||
|
||||
/// ETXTBSY
|
||||
pub const MAP_DENYWRITE = 0x0800;
|
||||
|
||||
/// mark it as an executable
|
||||
pub const MAP_EXECUTABLE = 0x1000;
|
||||
|
||||
/// pages are locked
|
||||
pub const MAP_LOCKED = 0x2000;
|
||||
|
||||
/// don't check for reservations
|
||||
pub const MAP_NORESERVE = 0x4000;
|
||||
|
||||
pub const VDSO_CGT_SYM = "__vdso_clock_gettime";
|
||||
pub const VDSO_CGT_VER = "LINUX_2.6";
|
||||
pub const VDSO_GETCPU_SYM = "__vdso_getcpu";
|
||||
pub const VDSO_GETCPU_VER = "LINUX_2.6";
|
||||
|
||||
pub const ARCH_SET_GS = 0x1001;
|
||||
pub const ARCH_SET_FS = 0x1002;
|
||||
pub const ARCH_GET_FS = 0x1003;
|
||||
pub const ARCH_GET_GS = 0x1004;
|
||||
|
||||
pub const REG_R8 = 0;
|
||||
pub const REG_R9 = 1;
|
||||
pub const REG_R10 = 2;
|
||||
pub const REG_R11 = 3;
|
||||
pub const REG_R12 = 4;
|
||||
pub const REG_R13 = 5;
|
||||
pub const REG_R14 = 6;
|
||||
pub const REG_R15 = 7;
|
||||
pub const REG_RDI = 8;
|
||||
pub const REG_RSI = 9;
|
||||
pub const REG_RBP = 10;
|
||||
pub const REG_RBX = 11;
|
||||
pub const REG_RDX = 12;
|
||||
pub const REG_RAX = 13;
|
||||
pub const REG_RCX = 14;
|
||||
pub const REG_RSP = 15;
|
||||
pub const REG_RIP = 16;
|
||||
pub const REG_EFL = 17;
|
||||
pub const REG_CSGSFS = 18;
|
||||
pub const REG_ERR = 19;
|
||||
pub const REG_TRAPNO = 20;
|
||||
pub const REG_OLDMASK = 21;
|
||||
pub const REG_CR2 = 22;
|
||||
|
||||
pub const LOCK_SH = 1;
|
||||
pub const LOCK_EX = 2;
|
||||
pub const LOCK_UN = 8;
|
||||
pub const LOCK_NB = 4;
|
||||
|
||||
pub const F_RDLCK = 0;
|
||||
pub const F_WRLCK = 1;
|
||||
pub const F_UNLCK = 2;
|
||||
|
||||
pub const Flock = extern struct {
|
||||
l_type: i16,
|
||||
l_whence: i16,
|
||||
l_start: off_t,
|
||||
l_len: off_t,
|
||||
l_pid: pid_t,
|
||||
};
|
||||
|
||||
pub const msghdr = extern struct {
|
||||
msg_name: ?*sockaddr,
|
||||
msg_namelen: socklen_t,
|
||||
msg_iov: [*]iovec,
|
||||
msg_iovlen: i32,
|
||||
__pad1: i32 = 0,
|
||||
msg_control: ?*c_void,
|
||||
msg_controllen: socklen_t,
|
||||
__pad2: socklen_t = 0,
|
||||
msg_flags: i32,
|
||||
};
|
||||
|
||||
pub const msghdr_const = extern struct {
|
||||
msg_name: ?*const sockaddr,
|
||||
msg_namelen: socklen_t,
|
||||
msg_iov: [*]iovec_const,
|
||||
msg_iovlen: i32,
|
||||
__pad1: i32 = 0,
|
||||
msg_control: ?*c_void,
|
||||
msg_controllen: socklen_t,
|
||||
__pad2: socklen_t = 0,
|
||||
msg_flags: i32,
|
||||
};
|
||||
|
||||
pub const off_t = i64;
|
||||
pub const ino_t = u64;
|
||||
pub const dev_t = u64;
|
||||
|
||||
// The `stat` definition used by the Linux kernel.
|
||||
pub const kernel_stat = extern struct {
|
||||
dev: dev_t,
|
||||
ino: ino_t,
|
||||
nlink: usize,
|
||||
|
||||
mode: u32,
|
||||
uid: uid_t,
|
||||
gid: gid_t,
|
||||
__pad0: u32,
|
||||
rdev: dev_t,
|
||||
size: off_t,
|
||||
blksize: isize,
|
||||
blocks: i64,
|
||||
|
||||
atim: timespec,
|
||||
mtim: timespec,
|
||||
ctim: timespec,
|
||||
__unused: [3]isize,
|
||||
|
||||
pub fn atime(self: @This()) timespec {
|
||||
return self.atim;
|
||||
}
|
||||
|
||||
pub fn mtime(self: @This()) timespec {
|
||||
return self.mtim;
|
||||
}
|
||||
|
||||
pub fn ctime(self: @This()) timespec {
|
||||
return self.ctim;
|
||||
}
|
||||
};
|
||||
|
||||
// The `stat64` definition used by the libc.
|
||||
pub const libc_stat = kernel_stat;
|
||||
|
||||
pub const timespec = extern struct {
|
||||
tv_sec: isize,
|
||||
tv_nsec: isize,
|
||||
};
|
||||
|
||||
pub const timeval = extern struct {
|
||||
tv_sec: isize,
|
||||
tv_usec: isize,
|
||||
};
|
||||
|
||||
pub const timezone = extern struct {
|
||||
tz_minuteswest: i32,
|
||||
tz_dsttime: i32,
|
||||
};
|
||||
|
||||
pub const Elf_Symndx = u32;
|
||||
|
||||
pub const greg_t = usize;
|
||||
pub const gregset_t = [23]greg_t;
|
||||
pub const fpstate = extern struct {
|
||||
cwd: u16,
|
||||
swd: u16,
|
||||
ftw: u16,
|
||||
fop: u16,
|
||||
rip: usize,
|
||||
rdp: usize,
|
||||
mxcsr: u32,
|
||||
mxcr_mask: u32,
|
||||
st: [8]extern struct {
|
||||
significand: [4]u16,
|
||||
exponent: u16,
|
||||
padding: [3]u16 = undefined,
|
||||
},
|
||||
xmm: [16]extern struct {
|
||||
element: [4]u32,
|
||||
},
|
||||
padding: [24]u32 = undefined,
|
||||
};
|
||||
pub const fpregset_t = *fpstate;
|
||||
pub const sigcontext = extern struct {
|
||||
r8: usize,
|
||||
r9: usize,
|
||||
r10: usize,
|
||||
r11: usize,
|
||||
r12: usize,
|
||||
r13: usize,
|
||||
r14: usize,
|
||||
r15: usize,
|
||||
|
||||
rdi: usize,
|
||||
rsi: usize,
|
||||
rbp: usize,
|
||||
rbx: usize,
|
||||
rdx: usize,
|
||||
rax: usize,
|
||||
rcx: usize,
|
||||
rsp: usize,
|
||||
rip: usize,
|
||||
eflags: usize,
|
||||
|
||||
cs: u16,
|
||||
gs: u16,
|
||||
fs: u16,
|
||||
pad0: u16 = undefined,
|
||||
|
||||
err: usize,
|
||||
trapno: usize,
|
||||
oldmask: usize,
|
||||
cr2: usize,
|
||||
|
||||
fpstate: *fpstate,
|
||||
reserved1: [8]usize = undefined,
|
||||
};
|
||||
|
||||
pub const mcontext_t = extern struct {
|
||||
gregs: gregset_t,
|
||||
fpregs: fpregset_t,
|
||||
reserved1: [8]usize = undefined,
|
||||
};
|
||||
|
||||
pub const ucontext_t = extern struct {
|
||||
flags: usize,
|
||||
link: *ucontext_t,
|
||||
stack: stack_t,
|
||||
mcontext: mcontext_t,
|
||||
sigmask: sigset_t,
|
||||
fpregs_mem: [64]usize,
|
||||
};
|
||||
@ -1,77 +0,0 @@
|
||||
usingnamespace @import("../linux.zig");
|
||||
|
||||
pub const XDP_SHARED_UMEM = (1 << 0);
|
||||
pub const XDP_COPY = (1 << 1);
|
||||
pub const XDP_ZEROCOPY = (1 << 2);
|
||||
|
||||
pub const XDP_UMEM_UNALIGNED_CHUNK_FLAG = (1 << 0);
|
||||
|
||||
pub const sockaddr_xdp = extern struct {
|
||||
family: u16 = AF_XDP,
|
||||
flags: u16,
|
||||
ifindex: u32,
|
||||
queue_id: u32,
|
||||
shared_umem_fd: u32,
|
||||
};
|
||||
|
||||
pub const XDP_USE_NEED_WAKEUP = (1 << 3);
|
||||
|
||||
pub const xdp_ring_offset = extern struct {
|
||||
producer: u64,
|
||||
consumer: u64,
|
||||
desc: u64,
|
||||
flags: u64,
|
||||
};
|
||||
|
||||
pub const xdp_mmap_offsets = extern struct {
|
||||
rx: xdp_ring_offset,
|
||||
tx: xdp_ring_offset,
|
||||
fr: xdp_ring_offset,
|
||||
cr: xdp_ring_offset,
|
||||
};
|
||||
|
||||
pub const XDP_MMAP_OFFSETS = 1;
|
||||
pub const XDP_RX_RING = 2;
|
||||
pub const XDP_TX_RING = 3;
|
||||
pub const XDP_UMEM_REG = 4;
|
||||
pub const XDP_UMEM_FILL_RING = 5;
|
||||
pub const XDP_UMEM_COMPLETION_RING = 6;
|
||||
pub const XDP_STATISTICS = 7;
|
||||
pub const XDP_OPTIONS = 8;
|
||||
|
||||
pub const xdp_umem_reg = extern struct {
|
||||
addr: u64,
|
||||
len: u64,
|
||||
chunk_size: u32,
|
||||
headroom: u32,
|
||||
flags: u32,
|
||||
};
|
||||
|
||||
pub const xdp_statistics = extern struct {
|
||||
rx_dropped: u64,
|
||||
rx_invalid_descs: u64,
|
||||
tx_invalid_descs: u64,
|
||||
rx_ring_full: u64,
|
||||
rx_fill_ring_empty_descs: u64,
|
||||
tx_ring_empty_descs: u64,
|
||||
};
|
||||
|
||||
pub const xdp_options = extern struct {
|
||||
flags: u32,
|
||||
};
|
||||
|
||||
pub const XDP_OPTIONS_ZEROCOPY = (1 << 0);
|
||||
|
||||
pub const XDP_PGOFF_RX_RING = 0;
|
||||
pub const XDP_PGOFF_TX_RING = 0x80000000;
|
||||
pub const XDP_UMEM_PGOFF_FILL_RING = 0x100000000;
|
||||
pub const XDP_UMEM_PGOFF_COMPLETION_RING = 0x180000000;
|
||||
|
||||
pub const XSK_UNALIGNED_BUF_OFFSET_SHIFT = 48;
|
||||
pub const XSK_UNALIGNED_BUF_ADDR_MASK = (1 << XSK_UNALIGNED_BUF_OFFSET_SHIFT) - 1;
|
||||
|
||||
pub const xdp_desc = extern struct {
|
||||
addr: u64,
|
||||
len: u32,
|
||||
options: u32,
|
||||
};
|
||||
@ -2,8 +2,6 @@ const std = @import("../../std.zig");
|
||||
const builtin = std.builtin;
|
||||
const maxInt = std.math.maxInt;
|
||||
|
||||
pub usingnamespace @import("posix.zig");
|
||||
|
||||
pub const blkcnt_t = i64;
|
||||
pub const blksize_t = i32;
|
||||
pub const clock_t = u32;
|
||||
|
||||
@ -2,8 +2,6 @@ const std = @import("../../std.zig");
|
||||
const builtin = std.builtin;
|
||||
const maxInt = std.math.maxInt;
|
||||
|
||||
pub usingnamespace @import("posix.zig");
|
||||
|
||||
pub const blkcnt_t = i64;
|
||||
pub const blksize_t = i32;
|
||||
pub const clock_t = i64;
|
||||
|
||||
@ -1,28 +0,0 @@
|
||||
pub const iovec = extern struct {
|
||||
iov_base: [*]u8,
|
||||
iov_len: usize,
|
||||
};
|
||||
|
||||
pub const iovec_const = extern struct {
|
||||
iov_base: [*]const u8,
|
||||
iov_len: usize,
|
||||
};
|
||||
|
||||
// syslog
|
||||
|
||||
/// system is unusable
|
||||
pub const LOG_EMERG = 0;
|
||||
/// action must be taken immediately
|
||||
pub const LOG_ALERT = 1;
|
||||
/// critical conditions
|
||||
pub const LOG_CRIT = 2;
|
||||
/// error conditions
|
||||
pub const LOG_ERR = 3;
|
||||
/// warning conditions
|
||||
pub const LOG_WARNING = 4;
|
||||
/// normal but significant condition
|
||||
pub const LOG_NOTICE = 5;
|
||||
/// informational
|
||||
pub const LOG_INFO = 6;
|
||||
/// debug-level messages
|
||||
pub const LOG_DEBUG = 7;
|
||||
@ -1,6 +1,5 @@
|
||||
// Convenience types and consts used by std.os module
|
||||
const builtin = @import("builtin");
|
||||
const posix = @import("posix.zig");
|
||||
pub const iovec = posix.iovec;
|
||||
pub const iovec_const = posix.iovec_const;
|
||||
|
||||
@ -87,10 +86,12 @@ pub const ADVICE_DONTNEED: advice_t = 4;
|
||||
pub const ADVICE_NOREUSE: advice_t = 5;
|
||||
|
||||
pub const clockid_t = u32;
|
||||
pub const CLOCK_REALTIME: clockid_t = 0;
|
||||
pub const CLOCK_MONOTONIC: clockid_t = 1;
|
||||
pub const CLOCK_PROCESS_CPUTIME_ID: clockid_t = 2;
|
||||
pub const CLOCK_THREAD_CPUTIME_ID: clockid_t = 3;
|
||||
pub const CLOCK = struct {
|
||||
pub const REALTIME: clockid_t = 0;
|
||||
pub const MONOTONIC: clockid_t = 1;
|
||||
pub const PROCESS_CPUTIME_ID: clockid_t = 2;
|
||||
pub const THREAD_CPUTIME_ID: clockid_t = 3;
|
||||
};
|
||||
|
||||
pub const device_t = u64;
|
||||
|
||||
|
||||
@ -3,11 +3,6 @@
|
||||
usingnamespace @import("../windows/bits.zig");
|
||||
const ws2_32 = @import("../windows/ws2_32.zig");
|
||||
|
||||
// TODO: Stop using os.iovec in std.fs et al on Windows in the future
|
||||
const posix = @import("posix.zig");
|
||||
pub const iovec = posix.iovec;
|
||||
pub const iovec_const = posix.iovec_const;
|
||||
|
||||
pub const fd_t = HANDLE;
|
||||
pub const ino_t = LARGE_INTEGER;
|
||||
pub const pid_t = HANDLE;
|
||||
|
||||
@ -1,3 +0,0 @@
|
||||
const std = @import("../std.zig");
|
||||
pub usingnamespace std.c;
|
||||
pub usingnamespace @import("bits.zig");
|
||||
@ -1,3 +0,0 @@
|
||||
const std = @import("../std.zig");
|
||||
pub usingnamespace std.c;
|
||||
pub usingnamespace @import("bits.zig");
|
||||
@ -1,3 +0,0 @@
|
||||
const std = @import("../std.zig");
|
||||
pub usingnamespace std.c;
|
||||
pub usingnamespace @import("bits.zig");
|
||||
@ -1,3 +0,0 @@
|
||||
const std = @import("../std.zig");
|
||||
pub usingnamespace std.c;
|
||||
pub usingnamespace @import("bits.zig");
|
||||
3405
lib/std/os/linux.zig
3405
lib/std/os/linux.zig
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,3 @@
|
||||
usingnamespace @import("../bits/linux.zig");
|
||||
|
||||
pub fn syscall0(number: SYS) usize {
|
||||
return asm volatile ("svc #0"
|
||||
: [ret] "={r0}" (-> usize),
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
usingnamespace @import("../bits/linux.zig");
|
||||
|
||||
pub fn syscall0(number: SYS) usize {
|
||||
return asm volatile ("svc #0"
|
||||
: [ret] "={x0}" (-> usize),
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
usingnamespace @import("../bits/linux.zig");
|
||||
|
||||
pub fn syscall0(number: SYS) usize {
|
||||
return asm volatile ("int $0x80"
|
||||
: [ret] "={eax}" (-> usize),
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
usingnamespace @import("../bits/linux.zig");
|
||||
|
||||
pub fn syscall0(number: SYS) usize {
|
||||
return asm volatile (
|
||||
\\ syscall
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
usingnamespace @import("../bits/linux.zig");
|
||||
|
||||
pub fn syscall0(number: SYS) usize {
|
||||
return asm volatile (
|
||||
\\ sc
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
usingnamespace @import("../bits/linux.zig");
|
||||
|
||||
pub fn syscall0(number: SYS) usize {
|
||||
return asm volatile (
|
||||
\\ sc
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
usingnamespace @import("../bits/linux.zig");
|
||||
|
||||
pub fn syscall0(number: SYS) usize {
|
||||
return asm volatile ("ecall"
|
||||
: [ret] "={x10}" (-> usize),
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
usingnamespace @import("../bits/linux.zig");
|
||||
|
||||
pub fn syscall_pipe(fd: *[2]i32) usize {
|
||||
return asm volatile (
|
||||
\\ mov %[arg], %%g3
|
||||
|
||||
@ -135,7 +135,7 @@ pub fn setThreadPointer(addr: usize) void {
|
||||
);
|
||||
},
|
||||
.x86_64 => {
|
||||
const rc = std.os.linux.syscall2(.arch_prctl, std.os.linux.ARCH_SET_FS, addr);
|
||||
const rc = std.os.linux.syscall2(.arch_prctl, std.os.linux.ARCH.SET_FS, addr);
|
||||
assert(rc == 0);
|
||||
},
|
||||
.aarch64 => {
|
||||
@ -319,8 +319,8 @@ pub fn initStaticTLS(phdrs: []elf.Phdr) void {
|
||||
const alloc_tls_area = os.mmap(
|
||||
null,
|
||||
tls_image.alloc_size + tls_image.alloc_align - 1,
|
||||
os.PROT_READ | os.PROT_WRITE,
|
||||
os.MAP_PRIVATE | os.MAP_ANONYMOUS,
|
||||
os.PROT.READ | os.PROT.WRITE,
|
||||
os.MAP.PRIVATE | os.MAP.ANONYMOUS,
|
||||
-1,
|
||||
0,
|
||||
) catch os.abort();
|
||||
|
||||
@ -1,4 +1,16 @@
|
||||
usingnamespace @import("../bits/linux.zig");
|
||||
const std = @import("../../std.zig");
|
||||
const linux = std.os.linux;
|
||||
|
||||
const pid_t = linux.pid_t;
|
||||
const uid_t = linux.uid_t;
|
||||
const gid_t = linux.gid_t;
|
||||
const clock_t = linux.clock_t;
|
||||
const stack_t = linux.stack_t;
|
||||
const sigset_t = linux.sigset_t;
|
||||
const sockaddr = linux.sockaddr;
|
||||
const socklen_t = linux.socklen_t;
|
||||
const iovec = linux.iovec;
|
||||
const iovec_const = linux.iovec_const;
|
||||
|
||||
pub fn syscall0(number: SYS) usize {
|
||||
return asm volatile ("syscall"
|
||||
@ -97,3 +109,681 @@ pub fn restore_rt() callconv(.Naked) void {
|
||||
: "rcx", "r11", "memory"
|
||||
);
|
||||
}
|
||||
|
||||
pub const mode_t = usize;
|
||||
pub const time_t = isize;
|
||||
|
||||
pub const SYS = enum(usize) {
|
||||
read = 0,
|
||||
write = 1,
|
||||
open = 2,
|
||||
close = 3,
|
||||
stat = 4,
|
||||
fstat = 5,
|
||||
lstat = 6,
|
||||
poll = 7,
|
||||
lseek = 8,
|
||||
mmap = 9,
|
||||
mprotect = 10,
|
||||
munmap = 11,
|
||||
brk = 12,
|
||||
rt_sigaction = 13,
|
||||
rt_sigprocmask = 14,
|
||||
rt_sigreturn = 15,
|
||||
ioctl = 16,
|
||||
pread = 17,
|
||||
pwrite = 18,
|
||||
readv = 19,
|
||||
writev = 20,
|
||||
access = 21,
|
||||
pipe = 22,
|
||||
select = 23,
|
||||
sched_yield = 24,
|
||||
mremap = 25,
|
||||
msync = 26,
|
||||
mincore = 27,
|
||||
madvise = 28,
|
||||
shmget = 29,
|
||||
shmat = 30,
|
||||
shmctl = 31,
|
||||
dup = 32,
|
||||
dup2 = 33,
|
||||
pause = 34,
|
||||
nanosleep = 35,
|
||||
getitimer = 36,
|
||||
alarm = 37,
|
||||
setitimer = 38,
|
||||
getpid = 39,
|
||||
sendfile = 40,
|
||||
socket = 41,
|
||||
connect = 42,
|
||||
accept = 43,
|
||||
sendto = 44,
|
||||
recvfrom = 45,
|
||||
sendmsg = 46,
|
||||
recvmsg = 47,
|
||||
shutdown = 48,
|
||||
bind = 49,
|
||||
listen = 50,
|
||||
getsockname = 51,
|
||||
getpeername = 52,
|
||||
socketpair = 53,
|
||||
setsockopt = 54,
|
||||
getsockopt = 55,
|
||||
clone = 56,
|
||||
fork = 57,
|
||||
vfork = 58,
|
||||
execve = 59,
|
||||
exit = 60,
|
||||
wait4 = 61,
|
||||
kill = 62,
|
||||
uname = 63,
|
||||
semget = 64,
|
||||
semop = 65,
|
||||
semctl = 66,
|
||||
shmdt = 67,
|
||||
msgget = 68,
|
||||
msgsnd = 69,
|
||||
msgrcv = 70,
|
||||
msgctl = 71,
|
||||
fcntl = 72,
|
||||
flock = 73,
|
||||
fsync = 74,
|
||||
fdatasync = 75,
|
||||
truncate = 76,
|
||||
ftruncate = 77,
|
||||
getdents = 78,
|
||||
getcwd = 79,
|
||||
chdir = 80,
|
||||
fchdir = 81,
|
||||
rename = 82,
|
||||
mkdir = 83,
|
||||
rmdir = 84,
|
||||
creat = 85,
|
||||
link = 86,
|
||||
unlink = 87,
|
||||
symlink = 88,
|
||||
readlink = 89,
|
||||
chmod = 90,
|
||||
fchmod = 91,
|
||||
chown = 92,
|
||||
fchown = 93,
|
||||
lchown = 94,
|
||||
umask = 95,
|
||||
gettimeofday = 96,
|
||||
getrlimit = 97,
|
||||
getrusage = 98,
|
||||
sysinfo = 99,
|
||||
times = 100,
|
||||
ptrace = 101,
|
||||
getuid = 102,
|
||||
syslog = 103,
|
||||
getgid = 104,
|
||||
setuid = 105,
|
||||
setgid = 106,
|
||||
geteuid = 107,
|
||||
getegid = 108,
|
||||
setpgid = 109,
|
||||
getppid = 110,
|
||||
getpgrp = 111,
|
||||
setsid = 112,
|
||||
setreuid = 113,
|
||||
setregid = 114,
|
||||
getgroups = 115,
|
||||
setgroups = 116,
|
||||
setresuid = 117,
|
||||
getresuid = 118,
|
||||
setresgid = 119,
|
||||
getresgid = 120,
|
||||
getpgid = 121,
|
||||
setfsuid = 122,
|
||||
setfsgid = 123,
|
||||
getsid = 124,
|
||||
capget = 125,
|
||||
capset = 126,
|
||||
rt_sigpending = 127,
|
||||
rt_sigtimedwait = 128,
|
||||
rt_sigqueueinfo = 129,
|
||||
rt_sigsuspend = 130,
|
||||
sigaltstack = 131,
|
||||
utime = 132,
|
||||
mknod = 133,
|
||||
uselib = 134,
|
||||
personality = 135,
|
||||
ustat = 136,
|
||||
statfs = 137,
|
||||
fstatfs = 138,
|
||||
sysfs = 139,
|
||||
getpriority = 140,
|
||||
setpriority = 141,
|
||||
sched_setparam = 142,
|
||||
sched_getparam = 143,
|
||||
sched_setscheduler = 144,
|
||||
sched_getscheduler = 145,
|
||||
sched_get_priority_max = 146,
|
||||
sched_get_priority_min = 147,
|
||||
sched_rr_get_interval = 148,
|
||||
mlock = 149,
|
||||
munlock = 150,
|
||||
mlockall = 151,
|
||||
munlockall = 152,
|
||||
vhangup = 153,
|
||||
modify_ldt = 154,
|
||||
pivot_root = 155,
|
||||
_sysctl = 156,
|
||||
prctl = 157,
|
||||
arch_prctl = 158,
|
||||
adjtimex = 159,
|
||||
setrlimit = 160,
|
||||
chroot = 161,
|
||||
sync = 162,
|
||||
acct = 163,
|
||||
settimeofday = 164,
|
||||
mount = 165,
|
||||
umount2 = 166,
|
||||
swapon = 167,
|
||||
swapoff = 168,
|
||||
reboot = 169,
|
||||
sethostname = 170,
|
||||
setdomainname = 171,
|
||||
iopl = 172,
|
||||
ioperm = 173,
|
||||
create_module = 174,
|
||||
init_module = 175,
|
||||
delete_module = 176,
|
||||
get_kernel_syms = 177,
|
||||
query_module = 178,
|
||||
quotactl = 179,
|
||||
nfsservctl = 180,
|
||||
getpmsg = 181,
|
||||
putpmsg = 182,
|
||||
afs_syscall = 183,
|
||||
tuxcall = 184,
|
||||
security = 185,
|
||||
gettid = 186,
|
||||
readahead = 187,
|
||||
setxattr = 188,
|
||||
lsetxattr = 189,
|
||||
fsetxattr = 190,
|
||||
getxattr = 191,
|
||||
lgetxattr = 192,
|
||||
fgetxattr = 193,
|
||||
listxattr = 194,
|
||||
llistxattr = 195,
|
||||
flistxattr = 196,
|
||||
removexattr = 197,
|
||||
lremovexattr = 198,
|
||||
fremovexattr = 199,
|
||||
tkill = 200,
|
||||
time = 201,
|
||||
futex = 202,
|
||||
sched_setaffinity = 203,
|
||||
sched_getaffinity = 204,
|
||||
set_thread_area = 205,
|
||||
io_setup = 206,
|
||||
io_destroy = 207,
|
||||
io_getevents = 208,
|
||||
io_submit = 209,
|
||||
io_cancel = 210,
|
||||
get_thread_area = 211,
|
||||
lookup_dcookie = 212,
|
||||
epoll_create = 213,
|
||||
epoll_ctl_old = 214,
|
||||
epoll_wait_old = 215,
|
||||
remap_file_pages = 216,
|
||||
getdents64 = 217,
|
||||
set_tid_address = 218,
|
||||
restart_syscall = 219,
|
||||
semtimedop = 220,
|
||||
fadvise64 = 221,
|
||||
timer_create = 222,
|
||||
timer_settime = 223,
|
||||
timer_gettime = 224,
|
||||
timer_getoverrun = 225,
|
||||
timer_delete = 226,
|
||||
clock_settime = 227,
|
||||
clock_gettime = 228,
|
||||
clock_getres = 229,
|
||||
clock_nanosleep = 230,
|
||||
exit_group = 231,
|
||||
epoll_wait = 232,
|
||||
epoll_ctl = 233,
|
||||
tgkill = 234,
|
||||
utimes = 235,
|
||||
vserver = 236,
|
||||
mbind = 237,
|
||||
set_mempolicy = 238,
|
||||
get_mempolicy = 239,
|
||||
mq_open = 240,
|
||||
mq_unlink = 241,
|
||||
mq_timedsend = 242,
|
||||
mq_timedreceive = 243,
|
||||
mq_notify = 244,
|
||||
mq_getsetattr = 245,
|
||||
kexec_load = 246,
|
||||
waitid = 247,
|
||||
add_key = 248,
|
||||
request_key = 249,
|
||||
keyctl = 250,
|
||||
ioprio_set = 251,
|
||||
ioprio_get = 252,
|
||||
inotify_init = 253,
|
||||
inotify_add_watch = 254,
|
||||
inotify_rm_watch = 255,
|
||||
migrate_pages = 256,
|
||||
openat = 257,
|
||||
mkdirat = 258,
|
||||
mknodat = 259,
|
||||
fchownat = 260,
|
||||
futimesat = 261,
|
||||
fstatat = 262,
|
||||
unlinkat = 263,
|
||||
renameat = 264,
|
||||
linkat = 265,
|
||||
symlinkat = 266,
|
||||
readlinkat = 267,
|
||||
fchmodat = 268,
|
||||
faccessat = 269,
|
||||
pselect6 = 270,
|
||||
ppoll = 271,
|
||||
unshare = 272,
|
||||
set_robust_list = 273,
|
||||
get_robust_list = 274,
|
||||
splice = 275,
|
||||
tee = 276,
|
||||
sync_file_range = 277,
|
||||
vmsplice = 278,
|
||||
move_pages = 279,
|
||||
utimensat = 280,
|
||||
epoll_pwait = 281,
|
||||
signalfd = 282,
|
||||
timerfd_create = 283,
|
||||
eventfd = 284,
|
||||
fallocate = 285,
|
||||
timerfd_settime = 286,
|
||||
timerfd_gettime = 287,
|
||||
accept4 = 288,
|
||||
signalfd4 = 289,
|
||||
eventfd2 = 290,
|
||||
epoll_create1 = 291,
|
||||
dup3 = 292,
|
||||
pipe2 = 293,
|
||||
inotify_init1 = 294,
|
||||
preadv = 295,
|
||||
pwritev = 296,
|
||||
rt_tgsigqueueinfo = 297,
|
||||
perf_event_open = 298,
|
||||
recvmmsg = 299,
|
||||
fanotify_init = 300,
|
||||
fanotify_mark = 301,
|
||||
prlimit64 = 302,
|
||||
name_to_handle_at = 303,
|
||||
open_by_handle_at = 304,
|
||||
clock_adjtime = 305,
|
||||
syncfs = 306,
|
||||
sendmmsg = 307,
|
||||
setns = 308,
|
||||
getcpu = 309,
|
||||
process_vm_readv = 310,
|
||||
process_vm_writev = 311,
|
||||
kcmp = 312,
|
||||
finit_module = 313,
|
||||
sched_setattr = 314,
|
||||
sched_getattr = 315,
|
||||
renameat2 = 316,
|
||||
seccomp = 317,
|
||||
getrandom = 318,
|
||||
memfd_create = 319,
|
||||
kexec_file_load = 320,
|
||||
bpf = 321,
|
||||
execveat = 322,
|
||||
userfaultfd = 323,
|
||||
membarrier = 324,
|
||||
mlock2 = 325,
|
||||
copy_file_range = 326,
|
||||
preadv2 = 327,
|
||||
pwritev2 = 328,
|
||||
pkey_mprotect = 329,
|
||||
pkey_alloc = 330,
|
||||
pkey_free = 331,
|
||||
statx = 332,
|
||||
io_pgetevents = 333,
|
||||
rseq = 334,
|
||||
pidfd_send_signal = 424,
|
||||
io_uring_setup = 425,
|
||||
io_uring_enter = 426,
|
||||
io_uring_register = 427,
|
||||
open_tree = 428,
|
||||
move_mount = 429,
|
||||
fsopen = 430,
|
||||
fsconfig = 431,
|
||||
fsmount = 432,
|
||||
fspick = 433,
|
||||
pidfd_open = 434,
|
||||
clone3 = 435,
|
||||
close_range = 436,
|
||||
openat2 = 437,
|
||||
pidfd_getfd = 438,
|
||||
faccessat2 = 439,
|
||||
process_madvise = 440,
|
||||
epoll_pwait2 = 441,
|
||||
|
||||
_,
|
||||
};
|
||||
|
||||
pub const O = struct {
|
||||
pub const RDONLY = 0o0;
|
||||
pub const WRONLY = 0o1;
|
||||
pub const RDWR = 0o2;
|
||||
|
||||
pub const CREAT = 0o100;
|
||||
pub const EXCL = 0o200;
|
||||
pub const NOCTTY = 0o400;
|
||||
pub const TRUNC = 0o1000;
|
||||
pub const APPEND = 0o2000;
|
||||
pub const NONBLOCK = 0o4000;
|
||||
pub const DSYNC = 0o10000;
|
||||
pub const SYNC = 0o4010000;
|
||||
pub const RSYNC = 0o4010000;
|
||||
pub const DIRECTORY = 0o200000;
|
||||
pub const NOFOLLOW = 0o400000;
|
||||
pub const CLOEXEC = 0o2000000;
|
||||
|
||||
pub const ASYNC = 0o20000;
|
||||
pub const DIRECT = 0o40000;
|
||||
pub const LARGEFILE = 0;
|
||||
pub const NOATIME = 0o1000000;
|
||||
pub const PATH = 0o10000000;
|
||||
pub const TMPFILE = 0o20200000;
|
||||
pub const NDELAY = NONBLOCK;
|
||||
};
|
||||
|
||||
pub const F = struct {
|
||||
pub const DUPFD = 0;
|
||||
pub const GETFD = 1;
|
||||
pub const SETFD = 2;
|
||||
pub const GETFL = 3;
|
||||
pub const SETFL = 4;
|
||||
pub const GETLK = 5;
|
||||
pub const SETLK = 6;
|
||||
pub const SETLKW = 7;
|
||||
pub const SETOWN = 8;
|
||||
pub const GETOWN = 9;
|
||||
pub const SETSIG = 10;
|
||||
pub const GETSIG = 11;
|
||||
|
||||
pub const SETOWN_EX = 15;
|
||||
pub const GETOWN_EX = 16;
|
||||
pub const GETOWNER_UIDS = 17;
|
||||
|
||||
pub const RDLCK = 0;
|
||||
pub const WRLCK = 1;
|
||||
pub const UNLCK = 2;
|
||||
};
|
||||
|
||||
pub const MAP = struct {
|
||||
/// Share changes
|
||||
pub const SHARED = 0x01;
|
||||
|
||||
/// Changes are private
|
||||
pub const PRIVATE = 0x02;
|
||||
|
||||
/// share + validate extension flags
|
||||
pub const SHARED_VALIDATE = 0x03;
|
||||
|
||||
/// Mask for type of mapping
|
||||
pub const TYPE = 0x0f;
|
||||
|
||||
/// Interpret addr exactly
|
||||
pub const FIXED = 0x10;
|
||||
|
||||
/// don't use a file
|
||||
pub const ANONYMOUS = 0x20;
|
||||
|
||||
/// populate (prefault) pagetables
|
||||
pub const POPULATE = 0x8000;
|
||||
|
||||
/// do not block on IO
|
||||
pub const NONBLOCK = 0x10000;
|
||||
|
||||
/// give out an address that is best suited for process/thread stacks
|
||||
pub const STACK = 0x20000;
|
||||
|
||||
/// create a huge page mapping
|
||||
pub const HUGETLB = 0x40000;
|
||||
|
||||
/// perform synchronous page faults for the mapping
|
||||
pub const SYNC = 0x80000;
|
||||
|
||||
/// FIXED which doesn't unmap underlying mapping
|
||||
pub const FIXED_NOREPLACE = 0x100000;
|
||||
|
||||
/// For anonymous mmap, memory could be uninitialized
|
||||
pub const UNINITIALIZED = 0x4000000;
|
||||
/// only give out 32bit addresses
|
||||
pub const @"32BIT" = 0x40;
|
||||
|
||||
/// stack-like segment
|
||||
pub const GROWSDOWN = 0x0100;
|
||||
|
||||
/// ETXTBSY
|
||||
pub const DENYWRITE = 0x0800;
|
||||
|
||||
/// mark it as an executable
|
||||
pub const EXECUTABLE = 0x1000;
|
||||
|
||||
/// pages are locked
|
||||
pub const LOCKED = 0x2000;
|
||||
|
||||
/// don't check for reservations
|
||||
pub const NORESERVE = 0x4000;
|
||||
};
|
||||
|
||||
pub const VDSO = struct {
|
||||
pub const CGT_SYM = "__vdso_clock_gettime";
|
||||
pub const CGT_VER = "LINUX_2.6";
|
||||
|
||||
pub const GETCPU_SYM = "__vdso_getcpu";
|
||||
pub const GETCPU_VER = "LINUX_2.6";
|
||||
};
|
||||
|
||||
pub const ARCH = struct {
|
||||
pub const SET_GS = 0x1001;
|
||||
pub const SET_FS = 0x1002;
|
||||
pub const GET_FS = 0x1003;
|
||||
pub const GET_GS = 0x1004;
|
||||
};
|
||||
|
||||
pub const REG = struct {
|
||||
pub const R8 = 0;
|
||||
pub const R9 = 1;
|
||||
pub const R10 = 2;
|
||||
pub const R11 = 3;
|
||||
pub const R12 = 4;
|
||||
pub const R13 = 5;
|
||||
pub const R14 = 6;
|
||||
pub const R15 = 7;
|
||||
pub const RDI = 8;
|
||||
pub const RSI = 9;
|
||||
pub const RBP = 10;
|
||||
pub const RBX = 11;
|
||||
pub const RDX = 12;
|
||||
pub const RAX = 13;
|
||||
pub const RCX = 14;
|
||||
pub const RSP = 15;
|
||||
pub const RIP = 16;
|
||||
pub const EFL = 17;
|
||||
pub const CSGSFS = 18;
|
||||
pub const ERR = 19;
|
||||
pub const TRAPNO = 20;
|
||||
pub const OLDMASK = 21;
|
||||
pub const CR2 = 22;
|
||||
};
|
||||
|
||||
pub const LOCK = struct {
|
||||
pub const SH = 1;
|
||||
pub const EX = 2;
|
||||
pub const NB = 4;
|
||||
pub const UN = 8;
|
||||
};
|
||||
|
||||
pub const Flock = extern struct {
|
||||
type: i16,
|
||||
whence: i16,
|
||||
start: off_t,
|
||||
len: off_t,
|
||||
pid: pid_t,
|
||||
};
|
||||
|
||||
pub const msghdr = extern struct {
|
||||
name: ?*sockaddr,
|
||||
namelen: socklen_t,
|
||||
iov: [*]iovec,
|
||||
iovlen: i32,
|
||||
__pad1: i32 = 0,
|
||||
control: ?*c_void,
|
||||
controllen: socklen_t,
|
||||
__pad2: socklen_t = 0,
|
||||
flags: i32,
|
||||
};
|
||||
|
||||
pub const msghdr_const = extern struct {
|
||||
name: ?*const sockaddr,
|
||||
namelen: socklen_t,
|
||||
iov: [*]iovec_const,
|
||||
iovlen: i32,
|
||||
__pad1: i32 = 0,
|
||||
control: ?*c_void,
|
||||
controllen: socklen_t,
|
||||
__pad2: socklen_t = 0,
|
||||
flags: i32,
|
||||
};
|
||||
|
||||
pub const off_t = i64;
|
||||
pub const ino_t = u64;
|
||||
pub const dev_t = u64;
|
||||
|
||||
// The `stat` definition used by the Linux kernel.
|
||||
pub const kernel_stat = extern struct {
|
||||
dev: dev_t,
|
||||
ino: ino_t,
|
||||
nlink: usize,
|
||||
|
||||
mode: u32,
|
||||
uid: uid_t,
|
||||
gid: gid_t,
|
||||
__pad0: u32,
|
||||
rdev: dev_t,
|
||||
size: off_t,
|
||||
blksize: isize,
|
||||
blocks: i64,
|
||||
|
||||
atim: timespec,
|
||||
mtim: timespec,
|
||||
ctim: timespec,
|
||||
__unused: [3]isize,
|
||||
|
||||
pub fn atime(self: @This()) timespec {
|
||||
return self.atim;
|
||||
}
|
||||
|
||||
pub fn mtime(self: @This()) timespec {
|
||||
return self.mtim;
|
||||
}
|
||||
|
||||
pub fn ctime(self: @This()) timespec {
|
||||
return self.ctim;
|
||||
}
|
||||
};
|
||||
|
||||
// The `stat64` definition used by the libc.
|
||||
pub const libc_stat = kernel_stat;
|
||||
|
||||
pub const timespec = extern struct {
|
||||
tv_sec: isize,
|
||||
tv_nsec: isize,
|
||||
};
|
||||
|
||||
pub const timeval = extern struct {
|
||||
tv_sec: isize,
|
||||
tv_usec: isize,
|
||||
};
|
||||
|
||||
pub const timezone = extern struct {
|
||||
tz_minuteswest: i32,
|
||||
tz_dsttime: i32,
|
||||
};
|
||||
|
||||
pub const Elf_Symndx = u32;
|
||||
|
||||
pub const greg_t = usize;
|
||||
pub const gregset_t = [23]greg_t;
|
||||
pub const fpstate = extern struct {
|
||||
cwd: u16,
|
||||
swd: u16,
|
||||
ftw: u16,
|
||||
fop: u16,
|
||||
rip: usize,
|
||||
rdp: usize,
|
||||
mxcsr: u32,
|
||||
mxcr_mask: u32,
|
||||
st: [8]extern struct {
|
||||
significand: [4]u16,
|
||||
exponent: u16,
|
||||
padding: [3]u16 = undefined,
|
||||
},
|
||||
xmm: [16]extern struct {
|
||||
element: [4]u32,
|
||||
},
|
||||
padding: [24]u32 = undefined,
|
||||
};
|
||||
pub const fpregset_t = *fpstate;
|
||||
pub const sigcontext = extern struct {
|
||||
r8: usize,
|
||||
r9: usize,
|
||||
r10: usize,
|
||||
r11: usize,
|
||||
r12: usize,
|
||||
r13: usize,
|
||||
r14: usize,
|
||||
r15: usize,
|
||||
|
||||
rdi: usize,
|
||||
rsi: usize,
|
||||
rbp: usize,
|
||||
rbx: usize,
|
||||
rdx: usize,
|
||||
rax: usize,
|
||||
rcx: usize,
|
||||
rsp: usize,
|
||||
rip: usize,
|
||||
eflags: usize,
|
||||
|
||||
cs: u16,
|
||||
gs: u16,
|
||||
fs: u16,
|
||||
pad0: u16 = undefined,
|
||||
|
||||
err: usize,
|
||||
trapno: usize,
|
||||
oldmask: usize,
|
||||
cr2: usize,
|
||||
|
||||
fpstate: *fpstate,
|
||||
reserved1: [8]usize = undefined,
|
||||
};
|
||||
|
||||
pub const mcontext_t = extern struct {
|
||||
gregs: gregset_t,
|
||||
fpregs: fpregset_t,
|
||||
reserved1: [8]usize = undefined,
|
||||
};
|
||||
|
||||
pub const ucontext_t = extern struct {
|
||||
flags: usize,
|
||||
link: *ucontext_t,
|
||||
stack: stack_t,
|
||||
mcontext: mcontext_t,
|
||||
sigmask: sigset_t,
|
||||
fpregs_mem: [64]usize,
|
||||
};
|
||||
|
||||
@ -1,3 +0,0 @@
|
||||
const std = @import("../std.zig");
|
||||
pub usingnamespace std.c;
|
||||
pub usingnamespace @import("bits.zig");
|
||||
@ -1,3 +0,0 @@
|
||||
const std = @import("../std.zig");
|
||||
pub usingnamespace std.c;
|
||||
pub usingnamespace @import("bits.zig");
|
||||
@ -4,8 +4,6 @@
|
||||
const std = @import("std");
|
||||
const assert = std.debug.assert;
|
||||
|
||||
pub usingnamespace @import("bits.zig");
|
||||
|
||||
comptime {
|
||||
assert(@alignOf(i8) == 1);
|
||||
assert(@alignOf(u8) == 1);
|
||||
|
||||
@ -24,7 +24,7 @@ pub fn sleep(nanoseconds: u64) void {
|
||||
const w = std.os.wasi;
|
||||
const userdata: w.userdata_t = 0x0123_45678;
|
||||
const clock = w.subscription_clock_t{
|
||||
.id = w.CLOCK_MONOTONIC,
|
||||
.id = w.CLOCK.MONOTONIC,
|
||||
.timeout = nanoseconds,
|
||||
.precision = 0,
|
||||
.flags = 0,
|
||||
@ -152,7 +152,7 @@ pub const Timer = struct {
|
||||
/// At some point we may change our minds on RAW, but for now we're
|
||||
/// sticking with posix standard MONOTONIC. For more information, see:
|
||||
/// https://github.com/ziglang/zig/pull/933
|
||||
const monotonic_clock_id = os.CLOCK_MONOTONIC;
|
||||
const monotonic_clock_id = os.CLOCK.MONOTONIC;
|
||||
|
||||
/// Initialize the timer structure.
|
||||
/// Can only fail when running in a hostile environment that intentionally injects
|
||||
@ -161,7 +161,7 @@ pub const Timer = struct {
|
||||
pub fn start() Error!Timer {
|
||||
// This gives us an opportunity to grab the counter frequency in windows.
|
||||
// On Windows: QueryPerformanceCounter will succeed on anything >= XP/2000.
|
||||
// On Posix: CLOCK_MONOTONIC will only fail if the monotonic counter is not
|
||||
// On Posix: CLOCK.MONOTONIC will only fail if the monotonic counter is not
|
||||
// supported, or if the timespec pointer is out of bounds, which should be
|
||||
// impossible here barring cosmic rays or other such occurrences of
|
||||
// incredibly bad luck.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user