mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-05-07 00:51:55 -04:00
std.c reorganization
It is now composed of these main sections:
* Declarations that are shared among all operating systems.
* Declarations that have the same name, but different type signatures
depending on the operating system. Often multiple operating systems
share the same type signatures however.
* Declarations that are specific to a single operating system.
- These are imported one per line so you can see where they come from,
protected by a comptime block to prevent accessing the wrong one.
Closes #19352 by changing the convention to making types `void` and
functions `{}`, so that it becomes possible to update `@hasDecl` sites
to use `@TypeOf(f) != void` or `T != void`. Happily, this ended up
removing some duplicate logic and update some bitrotted feature
detection checks.
A handful of types have been modified to gain namespacing and type
safety. This is a breaking change.
Oh, and the last usage of `usingnamespace` site is eliminated.
This commit is contained in:
@@ -404,7 +404,6 @@ set(ZIG_STAGE2_SOURCES
|
||||
lib/std/buf_map.zig
|
||||
lib/std/builtin.zig
|
||||
lib/std/c.zig
|
||||
lib/std/c/linux.zig
|
||||
lib/std/coff.zig
|
||||
lib/std/crypto.zig
|
||||
lib/std/crypto/blake3.zig
|
||||
|
||||
@@ -1349,16 +1349,16 @@ fn maybeUpdateSize(resize_flag: bool) void {
|
||||
}
|
||||
} else {
|
||||
var winsize: posix.winsize = .{
|
||||
.ws_row = 0,
|
||||
.ws_col = 0,
|
||||
.ws_xpixel = 0,
|
||||
.ws_ypixel = 0,
|
||||
.row = 0,
|
||||
.col = 0,
|
||||
.xpixel = 0,
|
||||
.ypixel = 0,
|
||||
};
|
||||
|
||||
const err = posix.system.ioctl(fd, posix.T.IOCGWINSZ, @intFromPtr(&winsize));
|
||||
if (posix.errno(err) == .SUCCESS) {
|
||||
global_progress.rows = winsize.ws_row;
|
||||
global_progress.cols = winsize.ws_col;
|
||||
global_progress.rows = winsize.row;
|
||||
global_progress.cols = winsize.col;
|
||||
} else {
|
||||
std.log.debug("failed to determine terminal size; using conservative guess 80x25", .{});
|
||||
global_progress.rows = 25;
|
||||
|
||||
+28
-24
@@ -196,7 +196,10 @@ const DarwinImpl = struct {
|
||||
var timeout_overflowed = false;
|
||||
|
||||
const addr: *const anyopaque = ptr;
|
||||
const flags = c.UL_COMPARE_AND_WAIT | c.ULF_NO_ERRNO;
|
||||
const flags: c.UL = .{
|
||||
.op = .COMPARE_AND_WAIT,
|
||||
.NO_ERRNO = true,
|
||||
};
|
||||
const status = blk: {
|
||||
if (supports_ulock_wait2) {
|
||||
break :blk c.__ulock_wait2(flags, addr, expect, timeout_ns, 0);
|
||||
@@ -228,10 +231,11 @@ const DarwinImpl = struct {
|
||||
}
|
||||
|
||||
fn wake(ptr: *const atomic.Value(u32), max_waiters: u32) void {
|
||||
var flags: u32 = c.UL_COMPARE_AND_WAIT | c.ULF_NO_ERRNO;
|
||||
if (max_waiters > 1) {
|
||||
flags |= c.ULF_WAKE_ALL;
|
||||
}
|
||||
const flags: c.UL = .{
|
||||
.op = .COMPARE_AND_WAIT,
|
||||
.NO_ERRNO = true,
|
||||
.WAKE_ALL = max_waiters > 1,
|
||||
};
|
||||
|
||||
while (true) {
|
||||
const addr: *const anyopaque = ptr;
|
||||
@@ -242,7 +246,7 @@ const DarwinImpl = struct {
|
||||
.INTR => continue, // spurious wake()
|
||||
.FAULT => unreachable, // __ulock_wake doesn't generate EFAULT according to darwin pthread_cond_t
|
||||
.NOENT => return, // nothing was woken up
|
||||
.ALREADY => unreachable, // only for ULF_WAKE_THREAD
|
||||
.ALREADY => unreachable, // only for UL.Op.WAKE_THREAD
|
||||
else => unreachable,
|
||||
}
|
||||
}
|
||||
@@ -254,8 +258,8 @@ const LinuxImpl = struct {
|
||||
fn wait(ptr: *const atomic.Value(u32), expect: u32, timeout: ?u64) error{Timeout}!void {
|
||||
var ts: linux.timespec = undefined;
|
||||
if (timeout) |timeout_ns| {
|
||||
ts.tv_sec = @as(@TypeOf(ts.tv_sec), @intCast(timeout_ns / std.time.ns_per_s));
|
||||
ts.tv_nsec = @as(@TypeOf(ts.tv_nsec), @intCast(timeout_ns % std.time.ns_per_s));
|
||||
ts.sec = @as(@TypeOf(ts.sec), @intCast(timeout_ns / std.time.ns_per_s));
|
||||
ts.nsec = @as(@TypeOf(ts.nsec), @intCast(timeout_ns % std.time.ns_per_s));
|
||||
}
|
||||
|
||||
const rc = linux.futex_wait(
|
||||
@@ -306,10 +310,10 @@ const FreebsdImpl = struct {
|
||||
tm_ptr = &tm;
|
||||
tm_size = @sizeOf(@TypeOf(tm));
|
||||
|
||||
tm._flags = 0; // use relative time not UMTX_ABSTIME
|
||||
tm._clockid = c.CLOCK.MONOTONIC;
|
||||
tm._timeout.tv_sec = @as(@TypeOf(tm._timeout.tv_sec), @intCast(timeout_ns / std.time.ns_per_s));
|
||||
tm._timeout.tv_nsec = @as(@TypeOf(tm._timeout.tv_nsec), @intCast(timeout_ns % std.time.ns_per_s));
|
||||
tm.flags = 0; // use relative time not UMTX_ABSTIME
|
||||
tm.clockid = .MONOTONIC;
|
||||
tm.timeout.sec = @as(@TypeOf(tm.timeout.sec), @intCast(timeout_ns / std.time.ns_per_s));
|
||||
tm.timeout.nsec = @as(@TypeOf(tm.timeout.nsec), @intCast(timeout_ns % std.time.ns_per_s));
|
||||
}
|
||||
|
||||
const rc = c._umtx_op(
|
||||
@@ -356,16 +360,16 @@ const OpenbsdImpl = struct {
|
||||
fn wait(ptr: *const atomic.Value(u32), expect: u32, timeout: ?u64) error{Timeout}!void {
|
||||
var ts: c.timespec = undefined;
|
||||
if (timeout) |timeout_ns| {
|
||||
ts.tv_sec = @as(@TypeOf(ts.tv_sec), @intCast(timeout_ns / std.time.ns_per_s));
|
||||
ts.tv_nsec = @as(@TypeOf(ts.tv_nsec), @intCast(timeout_ns % std.time.ns_per_s));
|
||||
ts.sec = @as(@TypeOf(ts.sec), @intCast(timeout_ns / std.time.ns_per_s));
|
||||
ts.nsec = @as(@TypeOf(ts.nsec), @intCast(timeout_ns % std.time.ns_per_s));
|
||||
}
|
||||
|
||||
const rc = c.futex(
|
||||
@as(*const volatile u32, @ptrCast(&ptr.raw)),
|
||||
c.FUTEX_WAIT | c.FUTEX_PRIVATE_FLAG,
|
||||
c.FUTEX.WAIT | c.FUTEX.PRIVATE_FLAG,
|
||||
@as(c_int, @bitCast(expect)),
|
||||
if (timeout != null) &ts else null,
|
||||
null, // FUTEX_WAIT takes no requeue address
|
||||
null, // FUTEX.WAIT takes no requeue address
|
||||
);
|
||||
|
||||
switch (std.posix.errno(rc)) {
|
||||
@@ -387,10 +391,10 @@ const OpenbsdImpl = struct {
|
||||
fn wake(ptr: *const atomic.Value(u32), max_waiters: u32) void {
|
||||
const rc = c.futex(
|
||||
@as(*const volatile u32, @ptrCast(&ptr.raw)),
|
||||
c.FUTEX_WAKE | c.FUTEX_PRIVATE_FLAG,
|
||||
c.FUTEX.WAKE | c.FUTEX.PRIVATE_FLAG,
|
||||
std.math.cast(c_int, max_waiters) orelse std.math.maxInt(c_int),
|
||||
null, // FUTEX_WAKE takes no timeout ptr
|
||||
null, // FUTEX_WAKE takes no requeue address
|
||||
null, // FUTEX.WAKE takes no timeout ptr
|
||||
null, // FUTEX.WAKE takes no requeue address
|
||||
);
|
||||
|
||||
// returns number of threads woken up.
|
||||
@@ -540,12 +544,12 @@ const PosixImpl = struct {
|
||||
var ts: c.timespec = undefined;
|
||||
if (timeout) |timeout_ns| {
|
||||
std.posix.clock_gettime(c.CLOCK.REALTIME, &ts) catch unreachable;
|
||||
ts.tv_sec +|= @as(@TypeOf(ts.tv_sec), @intCast(timeout_ns / std.time.ns_per_s));
|
||||
ts.tv_nsec += @as(@TypeOf(ts.tv_nsec), @intCast(timeout_ns % std.time.ns_per_s));
|
||||
ts.sec +|= @as(@TypeOf(ts.sec), @intCast(timeout_ns / std.time.ns_per_s));
|
||||
ts.nsec += @as(@TypeOf(ts.nsec), @intCast(timeout_ns % std.time.ns_per_s));
|
||||
|
||||
if (ts.tv_nsec >= std.time.ns_per_s) {
|
||||
ts.tv_sec +|= 1;
|
||||
ts.tv_nsec -= std.time.ns_per_s;
|
||||
if (ts.nsec >= std.time.ns_per_s) {
|
||||
ts.sec +|= 1;
|
||||
ts.nsec -= std.time.ns_per_s;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -103,8 +103,8 @@ const SingleThreadedImpl = struct {
|
||||
}
|
||||
};
|
||||
|
||||
// SRWLOCK on windows is almost always faster than Futex solution.
|
||||
// It also implements an efficient Condition with requeue support for us.
|
||||
/// SRWLOCK on windows is almost always faster than Futex solution.
|
||||
/// It also implements an efficient Condition with requeue support for us.
|
||||
const WindowsImpl = struct {
|
||||
srwlock: windows.SRWLOCK = .{},
|
||||
|
||||
@@ -123,7 +123,7 @@ const WindowsImpl = struct {
|
||||
const windows = std.os.windows;
|
||||
};
|
||||
|
||||
// os_unfair_lock on darwin supports priority inheritance and is generally faster than Futex solutions.
|
||||
/// os_unfair_lock on darwin supports priority inheritance and is generally faster than Futex solutions.
|
||||
const DarwinImpl = struct {
|
||||
oul: c.os_unfair_lock = .{},
|
||||
|
||||
|
||||
+7950
-211
File diff suppressed because it is too large
Load Diff
+935
-2116
File diff suppressed because it is too large
Load Diff
@@ -1,51 +0,0 @@
|
||||
// See C headers in
|
||||
// lib/libc/include/aarch64-macos.12-gnu/mach/arm/_structs.h
|
||||
// lib/libc/include/aarch64-macos.13-none/arm/_mcontext.h
|
||||
|
||||
pub const mcontext_t = extern struct {
|
||||
es: exception_state,
|
||||
ss: thread_state,
|
||||
ns: neon_state,
|
||||
};
|
||||
|
||||
pub const exception_state = extern struct {
|
||||
far: u64, // Virtual Fault Address
|
||||
esr: u32, // Exception syndrome
|
||||
exception: u32, // Number of arm exception taken
|
||||
};
|
||||
|
||||
pub const thread_state = extern struct {
|
||||
regs: [29]u64, // General purpose registers
|
||||
fp: u64, // Frame pointer x29
|
||||
lr: u64, // Link register x30
|
||||
sp: u64, // Stack pointer x31
|
||||
pc: u64, // Program counter
|
||||
cpsr: u32, // Current program status register
|
||||
__pad: u32,
|
||||
};
|
||||
|
||||
pub const neon_state = extern struct {
|
||||
q: [32]u128,
|
||||
fpsr: u32,
|
||||
fpcr: u32,
|
||||
};
|
||||
|
||||
pub const EXC_TYPES_COUNT = 14;
|
||||
pub const EXC_MASK_MACHINE = 0;
|
||||
|
||||
pub const ARM_THREAD_STATE = 1;
|
||||
pub const ARM_UNIFIED_THREAD_STATE = ARM_THREAD_STATE;
|
||||
pub const ARM_VFP_STATE = 2;
|
||||
pub const ARM_EXCEPTION_STATE = 3;
|
||||
pub const ARM_DEBUG_STATE = 4;
|
||||
pub const THREAD_STATE_NONE = 5;
|
||||
pub const ARM_THREAD_STATE64 = 6;
|
||||
pub const ARM_EXCEPTION_STATE64 = 7;
|
||||
pub const ARM_THREAD_STATE_LAST = 8;
|
||||
pub const ARM_THREAD_STATE32 = 9;
|
||||
pub const ARM_DEBUG_STATE32 = 14;
|
||||
pub const ARM_DEBUG_STATE64 = 15;
|
||||
pub const ARM_NEON_STATE = 16;
|
||||
pub const ARM_NEON_STATE64 = 17;
|
||||
pub const ARM_CPMU_STATE64 = 18;
|
||||
pub const ARM_PAGEIN_STATE = 27;
|
||||
@@ -1,47 +0,0 @@
|
||||
// Common Security Services Manager
|
||||
// Security.framework/Headers/cssm*.h
|
||||
|
||||
// Schema Management Name Space Range Definition
|
||||
pub const DB_RECORDTYPE_SCHEMA_START = 0x00000000;
|
||||
pub const DB_RECORDTYPE_SCHEMA_END = DB_RECORDTYPE_SCHEMA_START + 4;
|
||||
|
||||
// Open Group Application Name Space Range Definition
|
||||
pub const DB_RECORDTYPE_OPEN_GROUP_START = 0x0000000A;
|
||||
pub const DB_RECORDTYPE_OPEN_GROUP_END = DB_RECORDTYPE_OPEN_GROUP_START + 8;
|
||||
|
||||
// Industry At Large Application Name Space Range Definition
|
||||
pub const DB_RECORDTYPE_APP_DEFINED_START = 0x80000000;
|
||||
pub const DB_RECORDTYPE_APP_DEFINED_END = 0xffffffff;
|
||||
|
||||
pub const DB_RECORDTYPE = enum(u32) {
|
||||
// Record Types defined in the Schema Management Name Space
|
||||
SCHEMA_INFO = DB_RECORDTYPE_SCHEMA_START + 0,
|
||||
SCHEMA_INDEXES = DB_RECORDTYPE_SCHEMA_START + 1,
|
||||
SCHEMA_ATTRIBUTES = DB_RECORDTYPE_SCHEMA_START + 2,
|
||||
SCHEMA_PARSING_MODULE = DB_RECORDTYPE_SCHEMA_START + 3,
|
||||
|
||||
// Record Types defined in the Open Group Application Name Space
|
||||
ANY = DB_RECORDTYPE_OPEN_GROUP_START + 0,
|
||||
CERT = DB_RECORDTYPE_OPEN_GROUP_START + 1,
|
||||
CRL = DB_RECORDTYPE_OPEN_GROUP_START + 2,
|
||||
POLICY = DB_RECORDTYPE_OPEN_GROUP_START + 3,
|
||||
GENERIC = DB_RECORDTYPE_OPEN_GROUP_START + 4,
|
||||
PUBLIC_KEY = DB_RECORDTYPE_OPEN_GROUP_START + 5,
|
||||
PRIVATE_KEY = DB_RECORDTYPE_OPEN_GROUP_START + 6,
|
||||
SYMMETRIC_KEY = DB_RECORDTYPE_OPEN_GROUP_START + 7,
|
||||
ALL_KEYS = DB_RECORDTYPE_OPEN_GROUP_START + 8,
|
||||
|
||||
// AppleFileDL record types
|
||||
GENERIC_PASSWORD = DB_RECORDTYPE_APP_DEFINED_START + 0,
|
||||
INTERNET_PASSWORD = DB_RECORDTYPE_APP_DEFINED_START + 1,
|
||||
APPLESHARE_PASSWORD = DB_RECORDTYPE_APP_DEFINED_START + 2,
|
||||
|
||||
X509_CERTIFICATE = DB_RECORDTYPE_APP_DEFINED_START + 0x1000,
|
||||
USER_TRUST,
|
||||
X509_CRL,
|
||||
UNLOCK_REFERRAL,
|
||||
EXTENDED_ATTRIBUTE,
|
||||
METADATA = DB_RECORDTYPE_APP_DEFINED_START + 0x8000,
|
||||
|
||||
_,
|
||||
};
|
||||
@@ -1,91 +0,0 @@
|
||||
const c = @import("../darwin.zig");
|
||||
|
||||
pub const mcontext_t = extern struct {
|
||||
es: exception_state,
|
||||
ss: thread_state,
|
||||
fs: float_state,
|
||||
};
|
||||
|
||||
pub const exception_state = extern struct {
|
||||
trapno: u16,
|
||||
cpu: u16,
|
||||
err: u32,
|
||||
faultvaddr: u64,
|
||||
};
|
||||
|
||||
pub const thread_state = extern struct {
|
||||
rax: u64,
|
||||
rbx: u64,
|
||||
rcx: u64,
|
||||
rdx: u64,
|
||||
rdi: u64,
|
||||
rsi: u64,
|
||||
rbp: u64,
|
||||
rsp: u64,
|
||||
r8: u64,
|
||||
r9: u64,
|
||||
r10: u64,
|
||||
r11: u64,
|
||||
r12: u64,
|
||||
r13: u64,
|
||||
r14: u64,
|
||||
r15: u64,
|
||||
rip: u64,
|
||||
rflags: u64,
|
||||
cs: u64,
|
||||
fs: u64,
|
||||
gs: u64,
|
||||
};
|
||||
|
||||
const stmm_reg = [16]u8;
|
||||
const xmm_reg = [16]u8;
|
||||
pub const float_state = extern struct {
|
||||
reserved: [2]c_int,
|
||||
fcw: u16,
|
||||
fsw: u16,
|
||||
ftw: u8,
|
||||
rsrv1: u8,
|
||||
fop: u16,
|
||||
ip: u32,
|
||||
cs: u16,
|
||||
rsrv2: u16,
|
||||
dp: u32,
|
||||
ds: u16,
|
||||
rsrv3: u16,
|
||||
mxcsr: u32,
|
||||
mxcsrmask: u32,
|
||||
stmm: [8]stmm_reg,
|
||||
xmm: [16]xmm_reg,
|
||||
rsrv4: [96]u8,
|
||||
reserved1: c_int,
|
||||
};
|
||||
|
||||
pub const THREAD_STATE = 4;
|
||||
pub const THREAD_STATE_COUNT: c.mach_msg_type_number_t = @sizeOf(thread_state) / @sizeOf(c_int);
|
||||
|
||||
pub const EXC_TYPES_COUNT = 14;
|
||||
pub const EXC_MASK_MACHINE = 0;
|
||||
|
||||
pub const x86_THREAD_STATE32 = 1;
|
||||
pub const x86_FLOAT_STATE32 = 2;
|
||||
pub const x86_EXCEPTION_STATE32 = 3;
|
||||
pub const x86_THREAD_STATE64 = 4;
|
||||
pub const x86_FLOAT_STATE64 = 5;
|
||||
pub const x86_EXCEPTION_STATE64 = 6;
|
||||
pub const x86_THREAD_STATE = 7;
|
||||
pub const x86_FLOAT_STATE = 8;
|
||||
pub const x86_EXCEPTION_STATE = 9;
|
||||
pub const x86_DEBUG_STATE32 = 10;
|
||||
pub const x86_DEBUG_STATE64 = 11;
|
||||
pub const x86_DEBUG_STATE = 12;
|
||||
pub const THREAD_STATE_NONE = 13;
|
||||
pub const x86_AVX_STATE32 = 16;
|
||||
pub const x86_AVX_STATE64 = (x86_AVX_STATE32 + 1);
|
||||
pub const x86_AVX_STATE = (x86_AVX_STATE32 + 2);
|
||||
pub const x86_AVX512_STATE32 = 19;
|
||||
pub const x86_AVX512_STATE64 = (x86_AVX512_STATE32 + 1);
|
||||
pub const x86_AVX512_STATE = (x86_AVX512_STATE32 + 2);
|
||||
pub const x86_PAGEIN_STATE = 22;
|
||||
pub const x86_THREAD_FULL_STATE64 = 23;
|
||||
pub const x86_INSTRUCTION_STATE = 24;
|
||||
pub const x86_LAST_BRANCH_STATE = 25;
|
||||
+16
-970
File diff suppressed because it is too large
Load Diff
@@ -1,180 +0,0 @@
|
||||
const std = @import("../std.zig");
|
||||
const maxInt = std.math.maxInt;
|
||||
const emscripten = std.os.emscripten;
|
||||
|
||||
pub const AF = emscripten.AF;
|
||||
pub const CLOCK = emscripten.CLOCK;
|
||||
pub const CPU_COUNT = emscripten.CPU_COUNT;
|
||||
pub const E = emscripten.E;
|
||||
pub const F = emscripten.F;
|
||||
pub const FD_CLOEXEC = emscripten.FD_CLOEXEC;
|
||||
pub const F_OK = emscripten.F_OK;
|
||||
pub const Flock = emscripten.Flock;
|
||||
pub const IFNAMESIZE = emscripten.IFNAMESIZE;
|
||||
pub const IOV_MAX = emscripten.IOV_MAX;
|
||||
pub const IPPROTO = emscripten.IPPROTO;
|
||||
pub const LOCK = emscripten.LOCK;
|
||||
pub const MADV = emscripten.MADV;
|
||||
pub const MSF = emscripten.MSF;
|
||||
pub const MSG = emscripten.MSG;
|
||||
pub const NAME_MAX = emscripten.NAME_MAX;
|
||||
pub const PATH_MAX = emscripten.PATH_MAX;
|
||||
pub const POLL = emscripten.POLL;
|
||||
pub const PROT = emscripten.PROT;
|
||||
pub const REG = emscripten.REG;
|
||||
pub const RLIM = emscripten.RLIM;
|
||||
pub const R_OK = emscripten.R_OK;
|
||||
pub const S = emscripten.S;
|
||||
pub const SA = emscripten.SA;
|
||||
pub const SEEK = emscripten.SEEK;
|
||||
pub const SHUT = emscripten.SHUT;
|
||||
pub const SIG = emscripten.SIG;
|
||||
pub const SIOCGIFINDEX = emscripten.SIOCGIFINDEX;
|
||||
pub const SO = emscripten.SO;
|
||||
pub const SOCK = emscripten.SOCK;
|
||||
pub const SOL = emscripten.SOL;
|
||||
pub const STDERR_FILENO = emscripten.STDERR_FILENO;
|
||||
pub const STDIN_FILENO = emscripten.STDIN_FILENO;
|
||||
pub const STDOUT_FILENO = emscripten.STDOUT_FILENO;
|
||||
pub const Sigaction = emscripten.Sigaction;
|
||||
pub const TCP = emscripten.TCP;
|
||||
pub const TCSA = emscripten.TCSA;
|
||||
pub const W = emscripten.W;
|
||||
pub const W_OK = emscripten.W_OK;
|
||||
pub const X_OK = emscripten.X_OK;
|
||||
pub const addrinfo = emscripten.addrinfo;
|
||||
pub const blkcnt_t = emscripten.blkcnt_t;
|
||||
pub const blksize_t = emscripten.blksize_t;
|
||||
pub const clock_t = emscripten.clock_t;
|
||||
pub const cpu_set_t = emscripten.cpu_set_t;
|
||||
pub const dev_t = emscripten.dev_t;
|
||||
pub const dl_phdr_info = emscripten.dl_phdr_info;
|
||||
pub const empty_sigset = emscripten.empty_sigset;
|
||||
pub const fd_t = emscripten.fd_t;
|
||||
pub const gid_t = emscripten.gid_t;
|
||||
pub const ifreq = emscripten.ifreq;
|
||||
pub const ino_t = emscripten.ino_t;
|
||||
pub const mcontext_t = emscripten.mcontext_t;
|
||||
pub const mode_t = emscripten.mode_t;
|
||||
pub const msghdr = emscripten.msghdr;
|
||||
pub const msghdr_const = emscripten.msghdr_const;
|
||||
pub const nfds_t = emscripten.nfds_t;
|
||||
pub const nlink_t = emscripten.nlink_t;
|
||||
pub const off_t = emscripten.off_t;
|
||||
pub const pid_t = emscripten.pid_t;
|
||||
pub const pollfd = emscripten.pollfd;
|
||||
pub const rlim_t = emscripten.rlim_t;
|
||||
pub const rlimit = emscripten.rlimit;
|
||||
pub const rlimit_resource = emscripten.rlimit_resource;
|
||||
pub const rusage = emscripten.rusage;
|
||||
pub const siginfo_t = emscripten.siginfo_t;
|
||||
pub const sigset_t = emscripten.sigset_t;
|
||||
pub const sockaddr = emscripten.sockaddr;
|
||||
pub const socklen_t = emscripten.socklen_t;
|
||||
pub const stack_t = emscripten.stack_t;
|
||||
pub const time_t = emscripten.time_t;
|
||||
pub const timespec = emscripten.timespec;
|
||||
pub const timeval = emscripten.timeval;
|
||||
pub const timezone = emscripten.timezone;
|
||||
pub const ucontext_t = emscripten.ucontext_t;
|
||||
pub const uid_t = emscripten.uid_t;
|
||||
pub const utsname = emscripten.utsname;
|
||||
|
||||
pub const _errno = struct {
|
||||
extern "c" fn __errno_location() *c_int;
|
||||
}.__errno_location;
|
||||
|
||||
pub const Stat = emscripten.Stat;
|
||||
|
||||
pub const AI = struct {
|
||||
pub const PASSIVE = 0x01;
|
||||
pub const CANONNAME = 0x02;
|
||||
pub const NUMERICHOST = 0x04;
|
||||
pub const V4MAPPED = 0x08;
|
||||
pub const ALL = 0x10;
|
||||
pub const ADDRCONFIG = 0x20;
|
||||
pub const NUMERICSERV = 0x400;
|
||||
};
|
||||
|
||||
pub const NI = struct {
|
||||
pub const NUMERICHOST = 0x01;
|
||||
pub const NUMERICSERV = 0x02;
|
||||
pub const NOFQDN = 0x04;
|
||||
pub const NAMEREQD = 0x08;
|
||||
pub const DGRAM = 0x10;
|
||||
pub const NUMERICSCOPE = 0x100;
|
||||
pub const MAXHOST = 255;
|
||||
pub const MAXSERV = 32;
|
||||
};
|
||||
|
||||
pub const EAI = enum(c_int) {
|
||||
BADFLAGS = -1,
|
||||
NONAME = -2,
|
||||
AGAIN = -3,
|
||||
FAIL = -4,
|
||||
FAMILY = -6,
|
||||
SOCKTYPE = -7,
|
||||
SERVICE = -8,
|
||||
MEMORY = -10,
|
||||
SYSTEM = -11,
|
||||
OVERFLOW = -12,
|
||||
|
||||
NODATA = -5,
|
||||
ADDRFAMILY = -9,
|
||||
INPROGRESS = -100,
|
||||
CANCELED = -101,
|
||||
NOTCANCELED = -102,
|
||||
ALLDONE = -103,
|
||||
INTR = -104,
|
||||
IDN_ENCODE = -105,
|
||||
|
||||
_,
|
||||
};
|
||||
|
||||
pub const fopen64 = std.c.fopen;
|
||||
pub const fstat64 = std.c.fstat;
|
||||
pub const fstatat64 = std.c.fstatat;
|
||||
pub const ftruncate64 = std.c.ftruncate;
|
||||
pub const getrlimit64 = std.c.getrlimit;
|
||||
pub const lseek64 = std.c.lseek;
|
||||
pub const mmap64 = std.c.mmap;
|
||||
pub const open64 = std.c.open;
|
||||
pub const openat64 = std.c.openat;
|
||||
pub const pread64 = std.c.pread;
|
||||
pub const preadv64 = std.c.preadv;
|
||||
pub const pwrite64 = std.c.pwrite;
|
||||
pub const pwritev64 = std.c.pwritev;
|
||||
pub const setrlimit64 = std.c.setrlimit;
|
||||
|
||||
pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int;
|
||||
pub extern "c" fn pipe2(fds: *[2]fd_t, flags: std.c.O) c_int;
|
||||
pub extern "c" fn getentropy(buffer: [*]u8, size: usize) c_int;
|
||||
|
||||
pub const pthread_attr_t = extern struct {
|
||||
__size: [56]u8,
|
||||
__align: c_long,
|
||||
};
|
||||
|
||||
pub const pthread_key_t = c_uint;
|
||||
pub const sem_t = extern struct {
|
||||
__size: [__SIZEOF_SEM_T]u8 align(@alignOf(usize)),
|
||||
};
|
||||
|
||||
const __SIZEOF_SEM_T = 4 * @sizeOf(usize);
|
||||
|
||||
pub const RTLD = struct {
|
||||
pub const LAZY = 1;
|
||||
pub const NOW = 2;
|
||||
pub const NOLOAD = 4;
|
||||
pub const NODELETE = 4096;
|
||||
pub const GLOBAL = 256;
|
||||
pub const LOCAL = 0;
|
||||
};
|
||||
|
||||
pub const dirent = extern struct {
|
||||
ino: c_uint,
|
||||
off: c_uint,
|
||||
reclen: c_ushort,
|
||||
type: u8,
|
||||
name: [256]u8,
|
||||
};
|
||||
+36
-1517
File diff suppressed because it is too large
Load Diff
+15
-858
@@ -4,152 +4,29 @@ const builtin = @import("builtin");
|
||||
const maxInt = std.math.maxInt;
|
||||
const iovec = std.posix.iovec;
|
||||
const iovec_const = std.posix.iovec_const;
|
||||
const socklen_t = std.c.socklen_t;
|
||||
const fd_t = std.c.fd_t;
|
||||
const PATH_MAX = std.c.PATH_MAX;
|
||||
const uid_t = std.c.uid_t;
|
||||
const gid_t = std.c.gid_t;
|
||||
const dev_t = std.c.dev_t;
|
||||
const ino_t = std.c.ino_t;
|
||||
|
||||
comptime {
|
||||
assert(builtin.os.tag == .haiku); // Prevent access of std.c symbols on wrong OS.
|
||||
}
|
||||
|
||||
pub extern "root" fn _errnop() *i32;
|
||||
pub extern "root" fn find_directory(which: directory_which, volume: i32, createIt: bool, path_ptr: [*]u8, length: i32) u64;
|
||||
|
||||
pub extern "root" fn find_thread(thread_name: ?*anyopaque) i32;
|
||||
|
||||
pub extern "root" fn get_system_info(system_info: *system_info) usize;
|
||||
|
||||
pub extern "root" fn _get_team_info(team: i32, team_info: *team_info, size: usize) i32;
|
||||
|
||||
pub extern "root" fn _get_next_area_info(team: i32, cookie: *i64, area_info: *area_info, size: usize) i32;
|
||||
|
||||
// TODO revisit if abi changes or better option becomes apparent
|
||||
pub extern "root" fn _get_next_image_info(team: i32, cookie: *i32, image_info: *image_info, size: usize) i32;
|
||||
|
||||
pub const sem_t = extern struct {
|
||||
type: i32,
|
||||
u: extern union {
|
||||
named_sem_id: i32,
|
||||
unnamed_sem: i32,
|
||||
},
|
||||
padding: [2]i32,
|
||||
};
|
||||
|
||||
pub const pthread_attr_t = extern struct {
|
||||
__detach_state: i32,
|
||||
__sched_priority: i32,
|
||||
__stack_size: i32,
|
||||
__guard_size: i32,
|
||||
__stack_address: ?*anyopaque,
|
||||
};
|
||||
|
||||
pub const EAI = enum(i32) {
|
||||
/// address family for hostname not supported
|
||||
ADDRFAMILY = 1,
|
||||
|
||||
/// name could not be resolved at this time
|
||||
AGAIN = 2,
|
||||
|
||||
/// flags parameter had an invalid value
|
||||
BADFLAGS = 3,
|
||||
|
||||
/// non-recoverable failure in name resolution
|
||||
FAIL = 4,
|
||||
|
||||
/// address family not recognized
|
||||
FAMILY = 5,
|
||||
|
||||
/// memory allocation failure
|
||||
MEMORY = 6,
|
||||
|
||||
/// no address associated with hostname
|
||||
NODATA = 7,
|
||||
|
||||
/// name does not resolve
|
||||
NONAME = 8,
|
||||
|
||||
/// service not recognized for socket type
|
||||
SERVICE = 9,
|
||||
|
||||
/// intended socket type was not recognized
|
||||
SOCKTYPE = 10,
|
||||
|
||||
/// system error returned in errno
|
||||
SYSTEM = 11,
|
||||
|
||||
/// invalid value for hints
|
||||
BADHINTS = 12,
|
||||
|
||||
/// resolved protocol is unknown
|
||||
PROTOCOL = 13,
|
||||
|
||||
/// argument buffer overflow
|
||||
OVERFLOW = 14,
|
||||
|
||||
_,
|
||||
};
|
||||
|
||||
pub const EAI_MAX = 15;
|
||||
|
||||
pub const AI = struct {
|
||||
pub const NUMERICSERV = 0x00000008;
|
||||
};
|
||||
|
||||
pub const AI_NUMERICSERV = AI.NUMERICSERV;
|
||||
|
||||
pub const fd_t = i32;
|
||||
|
||||
pub const socklen_t = u32;
|
||||
|
||||
// Modes and flags for dlopen()
|
||||
// include/dlfcn.h
|
||||
|
||||
pub const RTLD = struct {
|
||||
/// relocations are performed as needed
|
||||
pub const LAZY = 0;
|
||||
/// the file gets relocated at load time
|
||||
pub const NOW = 1;
|
||||
/// all symbols are available
|
||||
pub const GLOBAL = 2;
|
||||
/// symbols are not available for relocating any other object
|
||||
pub const LOCAL = 0;
|
||||
};
|
||||
|
||||
pub const dl_phdr_info = extern struct {
|
||||
dlpi_addr: usize,
|
||||
dlpi_name: ?[*:0]const u8,
|
||||
dlpi_phdr: [*]std.elf.Phdr,
|
||||
dlpi_phnum: u16,
|
||||
};
|
||||
|
||||
pub const Flock = extern struct {
|
||||
type: i16,
|
||||
whence: i16,
|
||||
start: off_t,
|
||||
len: off_t,
|
||||
pid: pid_t,
|
||||
};
|
||||
|
||||
pub const msghdr = extern struct {
|
||||
/// optional address
|
||||
msg_name: ?*sockaddr,
|
||||
|
||||
/// size of address
|
||||
msg_namelen: socklen_t,
|
||||
|
||||
/// scatter/gather array
|
||||
msg_iov: [*]iovec,
|
||||
|
||||
/// # elements in msg_iov
|
||||
msg_iovlen: i32,
|
||||
|
||||
/// ancillary data
|
||||
msg_control: ?*anyopaque,
|
||||
|
||||
/// ancillary data buffer len
|
||||
msg_controllen: socklen_t,
|
||||
|
||||
/// flags on received message
|
||||
msg_flags: i32,
|
||||
};
|
||||
|
||||
pub const B_OS_NAME_LENGTH = 32; // OS.h
|
||||
|
||||
pub const area_info = extern struct {
|
||||
area: u32,
|
||||
name: [B_OS_NAME_LENGTH]u8,
|
||||
name: [32]u8,
|
||||
size: usize,
|
||||
lock: u32,
|
||||
protection: u32,
|
||||
@@ -161,9 +38,6 @@ pub const area_info = extern struct {
|
||||
address: *anyopaque,
|
||||
};
|
||||
|
||||
pub const MAXPATHLEN = PATH_MAX;
|
||||
pub const MAXNAMLEN = NAME_MAX;
|
||||
|
||||
pub const image_info = extern struct {
|
||||
id: u32,
|
||||
image_type: u32,
|
||||
@@ -173,7 +47,7 @@ pub const image_info = extern struct {
|
||||
term_routine: *anyopaque,
|
||||
device: i32,
|
||||
node: i64,
|
||||
name: [MAXPATHLEN]u8,
|
||||
name: [PATH_MAX]u8,
|
||||
text: *anyopaque,
|
||||
data: *anyopaque,
|
||||
text_size: i32,
|
||||
@@ -223,473 +97,18 @@ pub const team_info = extern struct {
|
||||
gid: gid_t,
|
||||
};
|
||||
|
||||
pub const in_port_t = u16;
|
||||
pub const sa_family_t = u8;
|
||||
|
||||
pub const sockaddr = extern struct {
|
||||
/// total length
|
||||
len: u8,
|
||||
/// address family
|
||||
family: sa_family_t,
|
||||
/// actually longer; address value
|
||||
data: [14]u8,
|
||||
|
||||
pub const SS_MAXSIZE = 128;
|
||||
pub const storage = extern struct {
|
||||
len: u8 align(8),
|
||||
family: sa_family_t,
|
||||
padding: [126]u8 = undefined,
|
||||
|
||||
comptime {
|
||||
assert(@sizeOf(storage) == SS_MAXSIZE);
|
||||
assert(@alignOf(storage) == 8);
|
||||
}
|
||||
};
|
||||
|
||||
pub const in = extern struct {
|
||||
len: u8 = @sizeOf(in),
|
||||
family: sa_family_t = AF.INET,
|
||||
port: in_port_t,
|
||||
addr: u32,
|
||||
zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
|
||||
};
|
||||
|
||||
pub const in6 = extern struct {
|
||||
len: u8 = @sizeOf(in6),
|
||||
family: sa_family_t = AF.INET6,
|
||||
port: in_port_t,
|
||||
flowinfo: u32,
|
||||
addr: [16]u8,
|
||||
scope_id: u32,
|
||||
};
|
||||
|
||||
pub const un = extern struct {
|
||||
len: u8 = @sizeOf(un),
|
||||
family: sa_family_t = AF.UNIX,
|
||||
path: [104]u8,
|
||||
};
|
||||
};
|
||||
|
||||
pub const CTL = struct {};
|
||||
|
||||
pub const KERN = struct {};
|
||||
|
||||
pub const IOV_MAX = 1024;
|
||||
|
||||
pub const PATH_MAX = 1024;
|
||||
/// NOTE: Contains room for the terminating null character (despite the POSIX
|
||||
/// definition saying that NAME_MAX does not include the terminating null).
|
||||
pub const NAME_MAX = 256; // limits.h
|
||||
|
||||
pub const STDIN_FILENO = 0;
|
||||
pub const STDOUT_FILENO = 1;
|
||||
pub const STDERR_FILENO = 2;
|
||||
|
||||
pub const PROT = struct {
|
||||
pub const READ = 0x01;
|
||||
pub const WRITE = 0x02;
|
||||
pub const EXEC = 0x04;
|
||||
pub const NONE = 0x00;
|
||||
};
|
||||
|
||||
pub const MSF = struct {
|
||||
pub const ASYNC = 1;
|
||||
pub const INVALIDATE = 2;
|
||||
pub const SYNC = 4;
|
||||
};
|
||||
|
||||
pub const W = struct {
|
||||
pub const NOHANG = 0x1;
|
||||
pub const UNTRACED = 0x2;
|
||||
pub const CONTINUED = 0x4;
|
||||
pub const EXITED = 0x08;
|
||||
pub const STOPPED = 0x10;
|
||||
pub const NOWAIT = 0x20;
|
||||
|
||||
pub fn EXITSTATUS(s: u32) u8 {
|
||||
return @as(u8, @intCast(s & 0xff));
|
||||
}
|
||||
|
||||
pub fn TERMSIG(s: u32) u32 {
|
||||
return (s >> 8) & 0xff;
|
||||
}
|
||||
|
||||
pub fn STOPSIG(s: u32) u32 {
|
||||
return (s >> 16) & 0xff;
|
||||
}
|
||||
|
||||
pub fn IFEXITED(s: u32) bool {
|
||||
return (s & ~@as(u32, 0xff)) == 0;
|
||||
}
|
||||
|
||||
pub fn IFSTOPPED(s: u32) bool {
|
||||
return ((s >> 16) & 0xff) != 0;
|
||||
}
|
||||
|
||||
pub fn IFSIGNALED(s: u32) bool {
|
||||
return ((s >> 8) & 0xff) != 0;
|
||||
}
|
||||
};
|
||||
|
||||
// access function
|
||||
pub const F_OK = 0; // test for existence of file
|
||||
pub const X_OK = 1; // test for execute or search permission
|
||||
pub const W_OK = 2; // test for write permission
|
||||
pub const R_OK = 4; // test for read permission
|
||||
|
||||
pub const F = struct {
|
||||
pub const DUPFD = 0x0001;
|
||||
pub const GETFD = 0x0002;
|
||||
pub const SETFD = 0x0004;
|
||||
pub const GETFL = 0x0008;
|
||||
pub const SETFL = 0x0010;
|
||||
|
||||
pub const GETLK = 0x0020;
|
||||
pub const SETLK = 0x0080;
|
||||
pub const SETLKW = 0x0100;
|
||||
pub const DUPFD_CLOEXEC = 0x0200;
|
||||
|
||||
pub const RDLCK = 0x0040;
|
||||
pub const UNLCK = 0x0200;
|
||||
pub const WRLCK = 0x0400;
|
||||
};
|
||||
|
||||
pub const LOCK = struct {
|
||||
pub const SH = 0x01;
|
||||
pub const EX = 0x02;
|
||||
pub const NB = 0x04;
|
||||
pub const UN = 0x08;
|
||||
};
|
||||
|
||||
pub const FD_CLOEXEC = 1;
|
||||
|
||||
pub const SEEK = struct {
|
||||
pub const SET = 0;
|
||||
pub const CUR = 1;
|
||||
pub const END = 2;
|
||||
};
|
||||
|
||||
pub const SOCK = struct {
|
||||
pub const STREAM = 1;
|
||||
pub const DGRAM = 2;
|
||||
pub const RAW = 3;
|
||||
pub const SEQPACKET = 5;
|
||||
|
||||
/// WARNING: this flag is not supported by windows socket functions directly,
|
||||
/// it is only supported by std.os.socket. Be sure that this value does
|
||||
/// not share any bits with any of the `SOCK` values.
|
||||
pub const CLOEXEC = 0x10000;
|
||||
/// WARNING: this flag is not supported by windows socket functions directly,
|
||||
/// it is only supported by std.os.socket. Be sure that this value does
|
||||
/// not share any bits with any of the `SOCK` values.
|
||||
pub const NONBLOCK = 0x20000;
|
||||
};
|
||||
|
||||
pub const SO = struct {
|
||||
pub const ACCEPTCONN = 0x00000001;
|
||||
pub const BROADCAST = 0x00000002;
|
||||
pub const DEBUG = 0x00000004;
|
||||
pub const DONTROUTE = 0x00000008;
|
||||
pub const KEEPALIVE = 0x00000010;
|
||||
pub const OOBINLINE = 0x00000020;
|
||||
pub const REUSEADDR = 0x00000040;
|
||||
pub const REUSEPORT = 0x00000080;
|
||||
pub const USELOOPBACK = 0x00000100;
|
||||
pub const LINGER = 0x00000200;
|
||||
|
||||
pub const SNDBUF = 0x40000001;
|
||||
pub const SNDLOWAT = 0x40000002;
|
||||
pub const SNDTIMEO = 0x40000003;
|
||||
pub const RCVBUF = 0x40000004;
|
||||
pub const RCVLOWAT = 0x40000005;
|
||||
pub const RCVTIMEO = 0x40000006;
|
||||
pub const ERROR = 0x40000007;
|
||||
pub const TYPE = 0x40000008;
|
||||
pub const NONBLOCK = 0x40000009;
|
||||
pub const BINDTODEVICE = 0x4000000a;
|
||||
pub const PEERCRED = 0x4000000b;
|
||||
};
|
||||
|
||||
pub const SOL = struct {
|
||||
pub const SOCKET = -1;
|
||||
};
|
||||
|
||||
pub const PF = struct {
|
||||
pub const UNSPEC = AF.UNSPEC;
|
||||
pub const INET = AF.INET;
|
||||
pub const ROUTE = AF.ROUTE;
|
||||
pub const LINK = AF.LINK;
|
||||
pub const INET6 = AF.INET6;
|
||||
pub const LOCAL = AF.LOCAL;
|
||||
pub const UNIX = AF.UNIX;
|
||||
pub const BLUETOOTH = AF.BLUETOOTH;
|
||||
};
|
||||
|
||||
pub const AF = struct {
|
||||
pub const UNSPEC = 0;
|
||||
pub const INET = 1;
|
||||
pub const APPLETALK = 2;
|
||||
pub const ROUTE = 3;
|
||||
pub const LINK = 4;
|
||||
pub const INET6 = 5;
|
||||
pub const DLI = 6;
|
||||
pub const IPX = 7;
|
||||
pub const NOTIFY = 8;
|
||||
pub const LOCAL = 9;
|
||||
pub const UNIX = LOCAL;
|
||||
pub const BLUETOOTH = 10;
|
||||
pub const MAX = 11;
|
||||
};
|
||||
|
||||
pub const DT = struct {};
|
||||
|
||||
/// add event to kq (implies enable)
|
||||
pub const EV_ADD = 0x0001;
|
||||
|
||||
/// delete event from kq
|
||||
pub const EV_DELETE = 0x0002;
|
||||
|
||||
/// enable event
|
||||
pub const EV_ENABLE = 0x0004;
|
||||
|
||||
/// disable event (not reported)
|
||||
pub const EV_DISABLE = 0x0008;
|
||||
|
||||
/// only report one occurrence
|
||||
pub const EV_ONESHOT = 0x0010;
|
||||
|
||||
/// clear event state after reporting
|
||||
pub const EV_CLEAR = 0x0020;
|
||||
|
||||
/// force immediate event output
|
||||
/// ... with or without EV_ERROR
|
||||
/// ... use KEVENT_FLAG_ERROR_EVENTS
|
||||
/// on syscalls supporting flags
|
||||
pub const EV_RECEIPT = 0x0040;
|
||||
|
||||
/// disable event after reporting
|
||||
pub const EV_DISPATCH = 0x0080;
|
||||
|
||||
pub const EVFILT_READ = -1;
|
||||
pub const EVFILT_WRITE = -2;
|
||||
|
||||
/// attached to aio requests
|
||||
pub const EVFILT_AIO = -3;
|
||||
|
||||
/// attached to vnodes
|
||||
pub const EVFILT_VNODE = -4;
|
||||
|
||||
/// attached to struct proc
|
||||
pub const EVFILT_PROC = -5;
|
||||
|
||||
/// attached to struct proc
|
||||
pub const EVFILT_SIGNAL = -6;
|
||||
|
||||
/// timers
|
||||
pub const EVFILT_TIMER = -7;
|
||||
|
||||
/// Process descriptors
|
||||
pub const EVFILT_PROCDESC = -8;
|
||||
|
||||
/// Filesystem events
|
||||
pub const EVFILT_FS = -9;
|
||||
|
||||
pub const EVFILT_LIO = -10;
|
||||
|
||||
/// User events
|
||||
pub const EVFILT_USER = -11;
|
||||
|
||||
/// Sendfile events
|
||||
pub const EVFILT_SENDFILE = -12;
|
||||
|
||||
pub const EVFILT_EMPTY = -13;
|
||||
|
||||
pub const T = struct {
|
||||
pub const CGETA = 0x8000;
|
||||
pub const CSETA = 0x8001;
|
||||
pub const CSETAF = 0x8002;
|
||||
pub const CSETAW = 0x8003;
|
||||
pub const CWAITEVENT = 0x8004;
|
||||
pub const CSBRK = 0x8005;
|
||||
pub const CFLSH = 0x8006;
|
||||
pub const CXONC = 0x8007;
|
||||
pub const CQUERYCONNECTED = 0x8008;
|
||||
pub const CGETBITS = 0x8009;
|
||||
pub const CSETDTR = 0x8010;
|
||||
pub const CSETRTS = 0x8011;
|
||||
pub const IOCGWINSZ = 0x8012;
|
||||
pub const IOCSWINSZ = 0x8013;
|
||||
pub const CVTIME = 0x8014;
|
||||
pub const IOCGPGRP = 0x8015;
|
||||
pub const IOCSPGRP = 0x8016;
|
||||
pub const IOCSCTTY = 0x8017;
|
||||
pub const IOCMGET = 0x8018;
|
||||
pub const IOCMSET = 0x8019;
|
||||
pub const IOCSBRK = 0x8020;
|
||||
pub const IOCCBRK = 0x8021;
|
||||
pub const IOCMBIS = 0x8022;
|
||||
pub const IOCMBIC = 0x8023;
|
||||
pub const IOCGSID = 0x8024;
|
||||
|
||||
pub const FIONREAD = 0xbe000001;
|
||||
pub const FIONBIO = 0xbe000000;
|
||||
};
|
||||
|
||||
pub const winsize = extern struct {
|
||||
ws_row: u16,
|
||||
ws_col: u16,
|
||||
ws_xpixel: u16,
|
||||
ws_ypixel: u16,
|
||||
};
|
||||
|
||||
pub const S = struct {
|
||||
pub const IFMT = 0o170000;
|
||||
pub const IFSOCK = 0o140000;
|
||||
pub const IFLNK = 0o120000;
|
||||
pub const IFREG = 0o100000;
|
||||
pub const IFBLK = 0o060000;
|
||||
pub const IFDIR = 0o040000;
|
||||
pub const IFCHR = 0o020000;
|
||||
pub const IFIFO = 0o010000;
|
||||
pub const INDEX_DIR = 0o4000000000;
|
||||
|
||||
pub const IUMSK = 0o7777;
|
||||
pub const ISUID = 0o4000;
|
||||
pub const ISGID = 0o2000;
|
||||
pub const ISVTX = 0o1000;
|
||||
pub const IRWXU = 0o700;
|
||||
pub const IRUSR = 0o400;
|
||||
pub const IWUSR = 0o200;
|
||||
pub const IXUSR = 0o100;
|
||||
pub const IRWXG = 0o070;
|
||||
pub const IRGRP = 0o040;
|
||||
pub const IWGRP = 0o020;
|
||||
pub const IXGRP = 0o010;
|
||||
pub const IRWXO = 0o007;
|
||||
pub const IROTH = 0o004;
|
||||
pub const IWOTH = 0o002;
|
||||
pub const IXOTH = 0o001;
|
||||
|
||||
pub fn ISREG(m: u32) bool {
|
||||
return m & IFMT == IFREG;
|
||||
}
|
||||
|
||||
pub fn ISLNK(m: u32) bool {
|
||||
return m & IFMT == IFLNK;
|
||||
}
|
||||
|
||||
pub fn ISBLK(m: u32) bool {
|
||||
return m & IFMT == IFBLK;
|
||||
}
|
||||
|
||||
pub fn ISDIR(m: u32) bool {
|
||||
return m & IFMT == IFDIR;
|
||||
}
|
||||
|
||||
pub fn ISCHR(m: u32) bool {
|
||||
return m & IFMT == IFCHR;
|
||||
}
|
||||
|
||||
pub fn ISFIFO(m: u32) bool {
|
||||
return m & IFMT == IFIFO;
|
||||
}
|
||||
|
||||
pub fn ISSOCK(m: u32) bool {
|
||||
return m & IFMT == IFSOCK;
|
||||
}
|
||||
|
||||
pub fn ISINDEX(m: u32) bool {
|
||||
return m & INDEX_DIR == INDEX_DIR;
|
||||
}
|
||||
};
|
||||
|
||||
pub const HOST_NAME_MAX = 255;
|
||||
|
||||
pub const addrinfo = extern struct {
|
||||
flags: i32,
|
||||
family: i32,
|
||||
socktype: i32,
|
||||
protocol: i32,
|
||||
addrlen: socklen_t,
|
||||
canonname: ?[*:0]u8,
|
||||
addr: ?*sockaddr,
|
||||
next: ?*addrinfo,
|
||||
};
|
||||
|
||||
pub const IPPROTO = struct {
|
||||
pub const IP = 0;
|
||||
pub const HOPOPTS = 0;
|
||||
pub const ICMP = 1;
|
||||
pub const IGMP = 2;
|
||||
pub const TCP = 6;
|
||||
pub const UDP = 17;
|
||||
pub const IPV6 = 41;
|
||||
pub const ROUTING = 43;
|
||||
pub const FRAGMENT = 44;
|
||||
pub const ESP = 50;
|
||||
pub const AH = 51;
|
||||
pub const ICMPV6 = 58;
|
||||
pub const NONE = 59;
|
||||
pub const DSTOPTS = 60;
|
||||
pub const ETHERIP = 97;
|
||||
pub const RAW = 255;
|
||||
pub const MAX = 256;
|
||||
};
|
||||
|
||||
pub const rlimit_resource = enum(i32) {
|
||||
CORE = 0,
|
||||
CPU = 1,
|
||||
DATA = 2,
|
||||
FSIZE = 3,
|
||||
NOFILE = 4,
|
||||
STACK = 5,
|
||||
AS = 6,
|
||||
NOVMON = 7,
|
||||
_,
|
||||
};
|
||||
|
||||
pub const rlim_t = i64;
|
||||
|
||||
pub const RLIM = struct {
|
||||
/// No limit
|
||||
pub const INFINITY: rlim_t = (1 << 63) - 1;
|
||||
|
||||
pub const SAVED_MAX = INFINITY;
|
||||
pub const SAVED_CUR = INFINITY;
|
||||
};
|
||||
|
||||
pub const rlimit = extern struct {
|
||||
/// Soft limit
|
||||
cur: rlim_t,
|
||||
/// Hard limit
|
||||
max: rlim_t,
|
||||
};
|
||||
|
||||
pub const SHUT = struct {
|
||||
pub const RD = 0;
|
||||
pub const WR = 1;
|
||||
pub const RDWR = 2;
|
||||
};
|
||||
|
||||
// TODO fill out if needed
|
||||
pub const directory_which = enum(i32) {
|
||||
B_USER_SETTINGS_DIRECTORY = 0xbbe,
|
||||
|
||||
_,
|
||||
};
|
||||
|
||||
pub const MSG_NOSIGNAL = 0x0800;
|
||||
|
||||
// /system/develop/headers/os/kernel/OS.h
|
||||
|
||||
pub const area_id = i32;
|
||||
pub const port_id = i32;
|
||||
pub const sem_id = i32;
|
||||
pub const team_id = i32;
|
||||
pub const thread_id = i32;
|
||||
|
||||
// /system/develop/headers/os/support/Errors.h
|
||||
|
||||
pub const E = enum(i32) {
|
||||
pub const B_GENERAL_ERROR_BASE: i32 = std.math.minInt(i32);
|
||||
pub const B_OS_ERROR_BASE = B_GENERAL_ERROR_BASE + 0x1000;
|
||||
@@ -847,13 +266,9 @@ pub const E = enum(i32) {
|
||||
_,
|
||||
};
|
||||
|
||||
// /system/develop/headers/os/support/SupportDefs.h
|
||||
|
||||
pub const status_t = i32;
|
||||
|
||||
// /system/develop/headers/posix/arch/*/signal.h
|
||||
|
||||
pub const vregs = switch (builtin.cpu.arch) {
|
||||
pub const mcontext_t = switch (builtin.cpu.arch) {
|
||||
.arm, .thumb => extern struct {
|
||||
r0: u32,
|
||||
r1: u32,
|
||||
@@ -1116,8 +531,6 @@ pub const vregs = switch (builtin.cpu.arch) {
|
||||
else => void,
|
||||
};
|
||||
|
||||
// /system/develop/headers/posix/dirent.h
|
||||
|
||||
pub const DirEnt = extern struct {
|
||||
/// device
|
||||
dev: dev_t,
|
||||
@@ -1135,259 +548,3 @@ pub const DirEnt = extern struct {
|
||||
return @ptrCast(&dirent.name);
|
||||
}
|
||||
};
|
||||
|
||||
// /system/develop/headers/posix/errno.h
|
||||
|
||||
extern "root" fn _errnop() *i32;
|
||||
pub const _errno = _errnop;
|
||||
|
||||
// /system/develop/headers/posix/poll.h
|
||||
|
||||
pub const nfds_t = usize;
|
||||
|
||||
pub const pollfd = extern struct {
|
||||
fd: i32,
|
||||
events: i16,
|
||||
revents: i16,
|
||||
};
|
||||
|
||||
pub const POLL = struct {
|
||||
/// any readable data available
|
||||
pub const IN = 0x0001;
|
||||
/// file descriptor is writeable
|
||||
pub const OUT = 0x0002;
|
||||
pub const RDNORM = IN;
|
||||
pub const WRNORM = OUT;
|
||||
/// priority readable data
|
||||
pub const RDBAND = 0x0008;
|
||||
/// priority data can be written
|
||||
pub const WRBAND = 0x0010;
|
||||
/// high priority readable data
|
||||
pub const PRI = 0x0020;
|
||||
|
||||
/// errors pending
|
||||
pub const ERR = 0x0004;
|
||||
/// disconnected
|
||||
pub const HUP = 0x0080;
|
||||
/// invalid file descriptor
|
||||
pub const NVAL = 0x1000;
|
||||
};
|
||||
|
||||
// /system/develop/headers/posix/signal.h
|
||||
|
||||
pub const sigset_t = u64;
|
||||
pub const empty_sigset: sigset_t = 0;
|
||||
pub const filled_sigset = ~@as(sigset_t, 0);
|
||||
|
||||
pub const SIG = struct {
|
||||
pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
|
||||
pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
|
||||
pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
|
||||
|
||||
pub const HOLD: ?Sigaction.handler_fn = @ptrFromInt(3);
|
||||
|
||||
pub const HUP = 1;
|
||||
pub const INT = 2;
|
||||
pub const QUIT = 3;
|
||||
pub const ILL = 4;
|
||||
pub const CHLD = 5;
|
||||
pub const ABRT = 6;
|
||||
pub const IOT = ABRT;
|
||||
pub const PIPE = 7;
|
||||
pub const FPE = 8;
|
||||
pub const KILL = 9;
|
||||
pub const STOP = 10;
|
||||
pub const SEGV = 11;
|
||||
pub const CONT = 12;
|
||||
pub const TSTP = 13;
|
||||
pub const ALRM = 14;
|
||||
pub const TERM = 15;
|
||||
pub const TTIN = 16;
|
||||
pub const TTOU = 17;
|
||||
pub const USR1 = 18;
|
||||
pub const USR2 = 19;
|
||||
pub const WINCH = 20;
|
||||
pub const KILLTHR = 21;
|
||||
pub const TRAP = 22;
|
||||
pub const POLL = 23;
|
||||
pub const PROF = 24;
|
||||
pub const SYS = 25;
|
||||
pub const URG = 26;
|
||||
pub const VTALRM = 27;
|
||||
pub const XCPU = 28;
|
||||
pub const XFSZ = 29;
|
||||
pub const BUS = 30;
|
||||
pub const RESERVED1 = 31;
|
||||
pub const RESERVED2 = 32;
|
||||
|
||||
pub const BLOCK = 1;
|
||||
pub const UNBLOCK = 2;
|
||||
pub const SETMASK = 3;
|
||||
};
|
||||
|
||||
pub const siginfo_t = extern struct {
|
||||
signo: i32,
|
||||
code: i32,
|
||||
errno: i32,
|
||||
|
||||
pid: pid_t,
|
||||
uid: uid_t,
|
||||
addr: *allowzero anyopaque,
|
||||
};
|
||||
|
||||
/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
|
||||
pub const Sigaction = extern struct {
|
||||
pub const handler_fn = *align(1) const fn (i32) callconv(.C) void;
|
||||
pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.C) void;
|
||||
|
||||
/// signal handler
|
||||
handler: extern union {
|
||||
handler: handler_fn,
|
||||
sigaction: sigaction_fn,
|
||||
},
|
||||
|
||||
/// signal mask to apply
|
||||
mask: sigset_t,
|
||||
|
||||
/// see signal options
|
||||
flags: i32,
|
||||
|
||||
/// will be passed to the signal handler, BeOS extension
|
||||
userdata: *allowzero anyopaque = undefined,
|
||||
};
|
||||
|
||||
pub const SA = struct {
|
||||
pub const NOCLDSTOP = 0x01;
|
||||
pub const NOCLDWAIT = 0x02;
|
||||
pub const RESETHAND = 0x04;
|
||||
pub const NODEFER = 0x08;
|
||||
pub const RESTART = 0x10;
|
||||
pub const ONSTACK = 0x20;
|
||||
pub const SIGINFO = 0x40;
|
||||
pub const NOMASK = NODEFER;
|
||||
pub const STACK = ONSTACK;
|
||||
pub const ONESHOT = RESETHAND;
|
||||
};
|
||||
|
||||
pub const SS = struct {
|
||||
pub const ONSTACK = 0x1;
|
||||
pub const DISABLE = 0x2;
|
||||
};
|
||||
|
||||
pub const MINSIGSTKSZ = 8192;
|
||||
pub const SIGSTKSZ = 16384;
|
||||
|
||||
pub const stack_t = extern struct {
|
||||
sp: [*]u8,
|
||||
size: isize,
|
||||
flags: i32,
|
||||
};
|
||||
|
||||
pub const NSIG = 65;
|
||||
|
||||
pub const mcontext_t = vregs;
|
||||
|
||||
pub const ucontext_t = extern struct {
|
||||
link: ?*ucontext_t,
|
||||
sigmask: sigset_t,
|
||||
stack: stack_t,
|
||||
mcontext: mcontext_t,
|
||||
};
|
||||
|
||||
// /system/develop/headers/posix/sys/stat.h
|
||||
|
||||
pub const Stat = extern struct {
|
||||
dev: dev_t,
|
||||
ino: ino_t,
|
||||
mode: mode_t,
|
||||
nlink: nlink_t,
|
||||
uid: uid_t,
|
||||
gid: gid_t,
|
||||
size: off_t,
|
||||
rdev: dev_t,
|
||||
blksize: blksize_t,
|
||||
atim: timespec,
|
||||
mtim: timespec,
|
||||
ctim: timespec,
|
||||
crtim: timespec,
|
||||
type: u32,
|
||||
blocks: blkcnt_t,
|
||||
|
||||
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;
|
||||
}
|
||||
pub fn birthtime(self: @This()) timespec {
|
||||
return self.crtim;
|
||||
}
|
||||
};
|
||||
|
||||
// /system/develop/headers/posix/sys/types.h
|
||||
|
||||
pub const blkcnt_t = i64;
|
||||
pub const blksize_t = i32;
|
||||
pub const fsblkcnt_t = i64;
|
||||
pub const fsfilcnt_t = i64;
|
||||
pub const off_t = i64;
|
||||
pub const ino_t = i64;
|
||||
pub const cnt_t = i32;
|
||||
pub const dev_t = i32;
|
||||
pub const pid_t = i32;
|
||||
pub const id_t = i32;
|
||||
|
||||
pub const uid_t = u32;
|
||||
pub const gid_t = u32;
|
||||
pub const mode_t = u32;
|
||||
pub const umode_t = u32;
|
||||
pub const nlink_t = i32;
|
||||
|
||||
pub const clockid_t = i32;
|
||||
pub const timer_t = *opaque {};
|
||||
|
||||
// /system/develop/headers/posix/time.h
|
||||
|
||||
pub const clock_t = i32;
|
||||
pub const suseconds_t = i32;
|
||||
pub const useconds_t = u32;
|
||||
|
||||
pub const time_t = isize;
|
||||
|
||||
pub const CLOCKS_PER_SEC = 1_000_000;
|
||||
pub const CLK_TCK = CLOCKS_PER_SEC;
|
||||
pub const TIME_UTC = 1;
|
||||
|
||||
pub const CLOCK = struct {
|
||||
/// system-wide monotonic clock (aka system time)
|
||||
pub const MONOTONIC: clockid_t = 0;
|
||||
/// system-wide real time clock
|
||||
pub const REALTIME: clockid_t = -1;
|
||||
/// clock measuring the used CPU time of the current process
|
||||
pub const PROCESS_CPUTIME_ID: clockid_t = -2;
|
||||
/// clock measuring the used CPU time of the current thread
|
||||
pub const THREAD_CPUTIME_ID: clockid_t = -3;
|
||||
};
|
||||
|
||||
pub const timespec = extern struct {
|
||||
/// seconds
|
||||
tv_sec: time_t,
|
||||
/// and nanoseconds
|
||||
tv_nsec: isize,
|
||||
};
|
||||
|
||||
pub const itimerspec = extern struct {
|
||||
interval: timespec,
|
||||
value: timespec,
|
||||
};
|
||||
|
||||
// /system/develop/headers/private/system/syscalls.h
|
||||
|
||||
pub extern "root" fn _kern_get_current_team() team_id;
|
||||
pub extern "root" fn _kern_open_dir(fd: fd_t, path: [*:0]const u8) fd_t;
|
||||
pub extern "root" fn _kern_read_dir(fd: fd_t, buffer: [*]u8, bufferSize: usize, maxCount: u32) isize;
|
||||
pub extern "root" fn _kern_rewind_dir(fd: fd_t) status_t;
|
||||
pub extern "root" fn _kern_read_stat(fd: fd_t, path: [*:0]const u8, traverseLink: bool, stat: *Stat, statSize: usize) status_t;
|
||||
|
||||
@@ -1,358 +0,0 @@
|
||||
const std = @import("../std.zig");
|
||||
const builtin = @import("builtin");
|
||||
const native_abi = builtin.abi;
|
||||
const native_arch = builtin.cpu.arch;
|
||||
const linux = std.os.linux;
|
||||
const iovec = std.posix.iovec;
|
||||
const iovec_const = std.posix.iovec_const;
|
||||
const FILE = std.c.FILE;
|
||||
|
||||
pub const AF = linux.AF;
|
||||
pub const ARCH = linux.ARCH;
|
||||
pub const CLOCK = linux.CLOCK;
|
||||
pub const CPU_COUNT = linux.CPU_COUNT;
|
||||
pub const E = linux.E;
|
||||
pub const Elf_Symndx = linux.Elf_Symndx;
|
||||
pub const F = linux.F;
|
||||
pub const FD_CLOEXEC = linux.FD_CLOEXEC;
|
||||
pub const F_OK = linux.F_OK;
|
||||
pub const Flock = linux.Flock;
|
||||
pub const HOST_NAME_MAX = linux.HOST_NAME_MAX;
|
||||
pub const IFNAMESIZE = linux.IFNAMESIZE;
|
||||
pub const IOV_MAX = linux.IOV_MAX;
|
||||
pub const IPPROTO = linux.IPPROTO;
|
||||
pub const LOCK = linux.LOCK;
|
||||
pub const MADV = linux.MADV;
|
||||
pub const MSF = linux.MSF;
|
||||
pub const MMAP2_UNIT = linux.MMAP2_UNIT;
|
||||
pub const MSG = linux.MSG;
|
||||
pub const NAME_MAX = linux.NAME_MAX;
|
||||
pub const PATH_MAX = linux.PATH_MAX;
|
||||
pub const POLL = linux.POLL;
|
||||
pub const PROT = linux.PROT;
|
||||
pub const REG = linux.REG;
|
||||
pub const RLIM = linux.RLIM;
|
||||
pub const R_OK = linux.R_OK;
|
||||
pub const S = linux.S;
|
||||
pub const SA = linux.SA;
|
||||
pub const SC = linux.SC;
|
||||
pub const SEEK = linux.SEEK;
|
||||
pub const SHUT = linux.SHUT;
|
||||
pub const SIG = linux.SIG;
|
||||
pub const SIOCGIFINDEX = linux.SIOCGIFINDEX;
|
||||
pub const SO = linux.SO;
|
||||
pub const SOCK = linux.SOCK;
|
||||
pub const SOL = linux.SOL;
|
||||
pub const STDERR_FILENO = linux.STDERR_FILENO;
|
||||
pub const STDIN_FILENO = linux.STDIN_FILENO;
|
||||
pub const STDOUT_FILENO = linux.STDOUT_FILENO;
|
||||
pub const SYS = linux.SYS;
|
||||
pub const Sigaction = linux.Sigaction;
|
||||
pub const T = linux.T;
|
||||
pub const TCP = linux.TCP;
|
||||
pub const TCSA = linux.TCSA;
|
||||
pub const TFD = linux.TFD;
|
||||
pub const VDSO = linux.VDSO;
|
||||
pub const W = linux.W;
|
||||
pub const W_OK = linux.W_OK;
|
||||
pub const X_OK = linux.X_OK;
|
||||
pub const addrinfo = linux.addrinfo;
|
||||
pub const blkcnt_t = linux.blkcnt_t;
|
||||
pub const blksize_t = linux.blksize_t;
|
||||
pub const clock_t = linux.clock_t;
|
||||
pub const cpu_set_t = linux.cpu_set_t;
|
||||
pub const dev_t = linux.dev_t;
|
||||
pub const dl_phdr_info = linux.dl_phdr_info;
|
||||
pub const empty_sigset = linux.empty_sigset;
|
||||
pub const epoll_event = linux.epoll_event;
|
||||
pub const fd_t = linux.fd_t;
|
||||
pub const gid_t = linux.gid_t;
|
||||
pub const ifreq = linux.ifreq;
|
||||
pub const ino_t = linux.ino_t;
|
||||
pub const itimerspec = linux.itimerspec;
|
||||
pub const mcontext_t = linux.mcontext_t;
|
||||
pub const mode_t = linux.mode_t;
|
||||
pub const msghdr = linux.msghdr;
|
||||
pub const msghdr_const = linux.msghdr_const;
|
||||
pub const nfds_t = linux.nfds_t;
|
||||
pub const nlink_t = linux.nlink_t;
|
||||
pub const off_t = linux.off_t;
|
||||
pub const perf_event_attr = linux.perf_event_attr;
|
||||
pub const pid_t = linux.pid_t;
|
||||
pub const pollfd = linux.pollfd;
|
||||
pub const rlim_t = linux.rlim_t;
|
||||
pub const rlimit = linux.rlimit;
|
||||
pub const rlimit_resource = linux.rlimit_resource;
|
||||
pub const rusage = linux.rusage;
|
||||
pub const siginfo_t = linux.siginfo_t;
|
||||
pub const sigset_t = linux.sigset_t;
|
||||
pub const sockaddr = linux.sockaddr;
|
||||
pub const socklen_t = linux.socklen_t;
|
||||
pub const stack_t = linux.stack_t;
|
||||
pub const time_t = linux.time_t;
|
||||
pub const timespec = linux.timespec;
|
||||
pub const timeval = linux.timeval;
|
||||
pub const timezone = linux.timezone;
|
||||
pub const ucontext_t = linux.ucontext_t;
|
||||
pub const uid_t = linux.uid_t;
|
||||
pub const user_desc = linux.user_desc;
|
||||
pub const utsname = linux.utsname;
|
||||
pub const winsize = linux.winsize;
|
||||
pub const PR = linux.PR;
|
||||
|
||||
pub const _errno = switch (native_abi) {
|
||||
.android => struct {
|
||||
extern fn __errno() *c_int;
|
||||
}.__errno,
|
||||
else => struct {
|
||||
extern "c" fn __errno_location() *c_int;
|
||||
}.__errno_location,
|
||||
};
|
||||
|
||||
pub const Stat = switch (native_arch) {
|
||||
.sparc64 => extern struct {
|
||||
dev: u64,
|
||||
__pad1: u16,
|
||||
ino: ino_t,
|
||||
mode: u32,
|
||||
nlink: u32,
|
||||
|
||||
uid: u32,
|
||||
gid: u32,
|
||||
rdev: u64,
|
||||
__pad2: u16,
|
||||
|
||||
size: off_t,
|
||||
blksize: isize,
|
||||
blocks: i64,
|
||||
|
||||
atim: timespec,
|
||||
mtim: timespec,
|
||||
ctim: timespec,
|
||||
__reserved: [2]usize,
|
||||
|
||||
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;
|
||||
}
|
||||
},
|
||||
.mips, .mipsel => extern struct {
|
||||
dev: dev_t,
|
||||
__pad0: [2]u32,
|
||||
ino: ino_t,
|
||||
mode: mode_t,
|
||||
nlink: nlink_t,
|
||||
uid: uid_t,
|
||||
gid: gid_t,
|
||||
rdev: dev_t,
|
||||
__pad1: [2]u32,
|
||||
size: off_t,
|
||||
atim: timespec,
|
||||
mtim: timespec,
|
||||
ctim: timespec,
|
||||
blksize: blksize_t,
|
||||
__pad3: u32,
|
||||
blocks: blkcnt_t,
|
||||
__pad4: [14]u32,
|
||||
|
||||
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;
|
||||
}
|
||||
},
|
||||
|
||||
else => std.os.linux.Stat, // libc stat is the same as kernel stat.
|
||||
};
|
||||
|
||||
pub const AI = struct {
|
||||
pub const PASSIVE = 0x01;
|
||||
pub const CANONNAME = 0x02;
|
||||
pub const NUMERICHOST = 0x04;
|
||||
pub const V4MAPPED = 0x08;
|
||||
pub const ALL = 0x10;
|
||||
pub const ADDRCONFIG = 0x20;
|
||||
pub const NUMERICSERV = 0x400;
|
||||
};
|
||||
|
||||
pub const NI = struct {
|
||||
pub const NUMERICHOST = 0x01;
|
||||
pub const NUMERICSERV = 0x02;
|
||||
pub const NOFQDN = 0x04;
|
||||
pub const NAMEREQD = 0x08;
|
||||
pub const DGRAM = 0x10;
|
||||
pub const NUMERICSCOPE = 0x100;
|
||||
};
|
||||
|
||||
pub const EAI = enum(c_int) {
|
||||
BADFLAGS = -1,
|
||||
NONAME = -2,
|
||||
AGAIN = -3,
|
||||
FAIL = -4,
|
||||
FAMILY = -6,
|
||||
SOCKTYPE = -7,
|
||||
SERVICE = -8,
|
||||
MEMORY = -10,
|
||||
SYSTEM = -11,
|
||||
OVERFLOW = -12,
|
||||
|
||||
NODATA = -5,
|
||||
ADDRFAMILY = -9,
|
||||
INPROGRESS = -100,
|
||||
CANCELED = -101,
|
||||
NOTCANCELED = -102,
|
||||
ALLDONE = -103,
|
||||
INTR = -104,
|
||||
IDN_ENCODE = -105,
|
||||
|
||||
_,
|
||||
};
|
||||
|
||||
pub const passwd = extern struct {
|
||||
pw_name: ?[*:0]const u8, // username
|
||||
pw_passwd: ?[*:0]const u8, // user password
|
||||
pw_uid: uid_t, // user ID
|
||||
pw_gid: gid_t, // group ID
|
||||
pw_gecos: ?[*:0]const u8, // user information
|
||||
pw_dir: ?[*:0]const u8, // home directory
|
||||
pw_shell: ?[*:0]const u8, // shell program
|
||||
};
|
||||
|
||||
pub extern "c" fn getpwnam(name: [*:0]const u8) ?*passwd;
|
||||
pub extern "c" fn getpwuid(uid: uid_t) ?*passwd;
|
||||
|
||||
pub extern "c" fn fallocate64(fd: fd_t, mode: c_int, offset: off_t, len: off_t) c_int;
|
||||
pub extern "c" fn fopen64(noalias filename: [*:0]const u8, noalias modes: [*:0]const u8) ?*FILE;
|
||||
pub extern "c" fn fstat64(fd: fd_t, buf: *Stat) c_int;
|
||||
pub extern "c" fn fstatat64(dirfd: fd_t, noalias path: [*:0]const u8, noalias stat_buf: *Stat, flags: u32) c_int;
|
||||
pub extern "c" fn ftruncate64(fd: c_int, length: off_t) c_int;
|
||||
pub extern "c" fn getrlimit64(resource: rlimit_resource, rlim: *rlimit) c_int;
|
||||
pub extern "c" fn lseek64(fd: fd_t, offset: i64, whence: c_int) i64;
|
||||
pub extern "c" fn mmap64(addr: ?*align(std.mem.page_size) anyopaque, len: usize, prot: c_uint, flags: c_uint, fd: fd_t, offset: i64) *anyopaque;
|
||||
pub extern "c" fn open64(path: [*:0]const u8, oflag: linux.O, ...) c_int;
|
||||
pub extern "c" fn openat64(fd: c_int, path: [*:0]const u8, oflag: linux.O, ...) c_int;
|
||||
pub extern "c" fn pread64(fd: fd_t, buf: [*]u8, nbyte: usize, offset: i64) isize;
|
||||
pub extern "c" fn preadv64(fd: c_int, iov: [*]const iovec, iovcnt: c_uint, offset: i64) isize;
|
||||
pub extern "c" fn pwrite64(fd: fd_t, buf: [*]const u8, nbyte: usize, offset: i64) isize;
|
||||
pub extern "c" fn pwritev64(fd: c_int, iov: [*]const iovec_const, iovcnt: c_uint, offset: i64) isize;
|
||||
pub extern "c" fn sendfile64(out_fd: fd_t, in_fd: fd_t, offset: ?*i64, count: usize) isize;
|
||||
pub extern "c" fn setrlimit64(resource: rlimit_resource, rlim: *const rlimit) c_int;
|
||||
|
||||
pub extern "c" fn getrandom(buf_ptr: [*]u8, buf_len: usize, flags: c_uint) isize;
|
||||
pub extern "c" fn sched_getaffinity(pid: c_int, size: usize, set: *cpu_set_t) c_int;
|
||||
pub extern "c" fn eventfd(initval: c_uint, flags: c_uint) c_int;
|
||||
pub extern "c" fn epoll_ctl(epfd: fd_t, op: c_uint, fd: fd_t, event: ?*epoll_event) c_int;
|
||||
pub extern "c" fn epoll_create1(flags: c_uint) c_int;
|
||||
pub extern "c" fn epoll_wait(epfd: fd_t, events: [*]epoll_event, maxevents: c_uint, timeout: c_int) c_int;
|
||||
pub extern "c" fn epoll_pwait(
|
||||
epfd: fd_t,
|
||||
events: [*]epoll_event,
|
||||
maxevents: c_int,
|
||||
timeout: c_int,
|
||||
sigmask: *const sigset_t,
|
||||
) c_int;
|
||||
pub extern "c" fn inotify_init1(flags: c_uint) c_int;
|
||||
pub extern "c" fn inotify_add_watch(fd: fd_t, pathname: [*:0]const u8, mask: u32) c_int;
|
||||
pub extern "c" fn inotify_rm_watch(fd: fd_t, wd: c_int) c_int;
|
||||
|
||||
/// See std.elf for constants for this
|
||||
pub extern "c" fn getauxval(__type: c_ulong) c_ulong;
|
||||
|
||||
pub const dl_iterate_phdr_callback = *const fn (info: *dl_phdr_info, size: usize, data: ?*anyopaque) callconv(.C) c_int;
|
||||
|
||||
pub extern "c" fn dl_iterate_phdr(callback: dl_iterate_phdr_callback, data: ?*anyopaque) c_int;
|
||||
|
||||
pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int;
|
||||
|
||||
pub extern "c" fn memfd_create(name: [*:0]const u8, flags: c_uint) c_int;
|
||||
pub extern "c" fn pipe2(fds: *[2]fd_t, flags: linux.O) c_int;
|
||||
|
||||
pub extern "c" fn fallocate(fd: fd_t, mode: c_int, offset: off_t, len: off_t) c_int;
|
||||
|
||||
pub extern "c" fn sendfile(
|
||||
out_fd: fd_t,
|
||||
in_fd: fd_t,
|
||||
offset: ?*off_t,
|
||||
count: usize,
|
||||
) isize;
|
||||
|
||||
pub extern "c" fn copy_file_range(fd_in: fd_t, off_in: ?*i64, fd_out: fd_t, off_out: ?*i64, len: usize, flags: c_uint) isize;
|
||||
|
||||
pub extern "c" fn signalfd(fd: fd_t, mask: *const sigset_t, flags: c_uint) c_int;
|
||||
|
||||
pub extern "c" fn prlimit(pid: pid_t, resource: rlimit_resource, new_limit: *const rlimit, old_limit: *rlimit) c_int;
|
||||
pub extern "c" fn posix_memalign(memptr: *?*anyopaque, alignment: usize, size: usize) c_int;
|
||||
pub extern "c" fn malloc_usable_size(?*const anyopaque) usize;
|
||||
|
||||
pub extern "c" fn mincore(
|
||||
addr: *align(std.mem.page_size) anyopaque,
|
||||
length: usize,
|
||||
vec: [*]u8,
|
||||
) c_int;
|
||||
|
||||
pub extern "c" fn madvise(
|
||||
addr: *align(std.mem.page_size) anyopaque,
|
||||
length: usize,
|
||||
advice: c_uint,
|
||||
) c_int;
|
||||
|
||||
pub const pthread_attr_t = extern struct {
|
||||
__size: [56]u8,
|
||||
__align: c_long,
|
||||
};
|
||||
|
||||
pub const pthread_key_t = c_uint;
|
||||
pub const sem_t = extern struct {
|
||||
__size: [__SIZEOF_SEM_T]u8 align(@alignOf(usize)),
|
||||
};
|
||||
|
||||
const __SIZEOF_SEM_T = 4 * @sizeOf(usize);
|
||||
|
||||
pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8) c_int;
|
||||
pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) c_int;
|
||||
|
||||
pub const RTLD = struct {
|
||||
pub const LAZY = 1;
|
||||
pub const NOW = 2;
|
||||
pub const NOLOAD = 4;
|
||||
pub const NODELETE = 4096;
|
||||
pub const GLOBAL = 256;
|
||||
pub const LOCAL = 0;
|
||||
};
|
||||
|
||||
pub const dirent = extern struct {
|
||||
ino: c_uint,
|
||||
off: c_uint,
|
||||
reclen: c_ushort,
|
||||
type: u8,
|
||||
name: [256]u8,
|
||||
};
|
||||
pub const dirent64 = extern struct {
|
||||
ino: c_ulong,
|
||||
off: c_ulong,
|
||||
reclen: c_ushort,
|
||||
type: u8,
|
||||
name: [256]u8,
|
||||
};
|
||||
|
||||
pub extern "c" fn timerfd_create(clockid: c_int, flags: c_int) c_int;
|
||||
pub extern "c" fn timerfd_settime(
|
||||
fd: c_int,
|
||||
flags: c_int,
|
||||
new_value: *const itimerspec,
|
||||
old_value: ?*itimerspec,
|
||||
) c_int;
|
||||
pub extern "c" fn timerfd_gettime(fd: c_int, curr_value: *itimerspec) c_int;
|
||||
+7
-1173
File diff suppressed because it is too large
Load Diff
+36
-1106
File diff suppressed because it is too large
Load Diff
+22
-1479
File diff suppressed because it is too large
Load Diff
@@ -1,162 +0,0 @@
|
||||
const builtin = @import("builtin");
|
||||
const std = @import("../std.zig");
|
||||
const wasi = std.os.wasi;
|
||||
|
||||
extern threadlocal var errno: c_int;
|
||||
|
||||
pub fn _errno() *c_int {
|
||||
return &errno;
|
||||
}
|
||||
|
||||
pub const PATH_MAX = 4096;
|
||||
|
||||
pub const mode_t = u32;
|
||||
pub const time_t = i64;
|
||||
|
||||
pub const timespec = extern struct {
|
||||
tv_sec: time_t,
|
||||
tv_nsec: isize,
|
||||
|
||||
pub fn fromTimestamp(tm: wasi.timestamp_t) timespec {
|
||||
const tv_sec: wasi.timestamp_t = tm / 1_000_000_000;
|
||||
const tv_nsec = tm - tv_sec * 1_000_000_000;
|
||||
return .{
|
||||
.tv_sec = @as(time_t, @intCast(tv_sec)),
|
||||
.tv_nsec = @as(isize, @intCast(tv_nsec)),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn toTimestamp(ts: timespec) wasi.timestamp_t {
|
||||
return @as(wasi.timestamp_t, @intCast(ts.tv_sec * 1_000_000_000)) +
|
||||
@as(wasi.timestamp_t, @intCast(ts.tv_nsec));
|
||||
}
|
||||
};
|
||||
|
||||
pub const STDIN_FILENO = 0;
|
||||
pub const STDOUT_FILENO = 1;
|
||||
pub const STDERR_FILENO = 2;
|
||||
|
||||
pub const E = wasi.errno_t;
|
||||
|
||||
pub const CLOCK = wasi.clockid_t;
|
||||
pub const IOV_MAX = 1024;
|
||||
pub const S = struct {
|
||||
pub const IEXEC = @compileError("TODO audit this");
|
||||
pub const IFBLK = 0x6000;
|
||||
pub const IFCHR = 0x2000;
|
||||
pub const IFDIR = 0x4000;
|
||||
pub const IFIFO = 0xc000;
|
||||
pub const IFLNK = 0xa000;
|
||||
pub const IFMT = IFBLK | IFCHR | IFDIR | IFIFO | IFLNK | IFREG | IFSOCK;
|
||||
pub const IFREG = 0x8000;
|
||||
/// There's no concept of UNIX domain socket but we define this value here
|
||||
/// in order to line with other OSes.
|
||||
pub const IFSOCK = 0x1;
|
||||
};
|
||||
pub const fd_t = wasi.fd_t;
|
||||
pub const pid_t = c_int;
|
||||
pub const uid_t = u32;
|
||||
pub const gid_t = u32;
|
||||
pub const off_t = i64;
|
||||
pub const ino_t = wasi.inode_t;
|
||||
pub const dev_t = wasi.device_t;
|
||||
pub const nlink_t = c_ulonglong;
|
||||
pub const blksize_t = c_long;
|
||||
pub const blkcnt_t = c_longlong;
|
||||
|
||||
pub const Stat = extern struct {
|
||||
dev: dev_t,
|
||||
ino: ino_t,
|
||||
nlink: nlink_t,
|
||||
mode: mode_t,
|
||||
uid: uid_t,
|
||||
gid: gid_t,
|
||||
__pad0: c_uint = 0,
|
||||
rdev: dev_t,
|
||||
size: off_t,
|
||||
blksize: blksize_t,
|
||||
blocks: blkcnt_t,
|
||||
atim: timespec,
|
||||
mtim: timespec,
|
||||
ctim: timespec,
|
||||
__reserved: [3]c_longlong = [3]c_longlong{ 0, 0, 0 },
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
pub fn fromFilestat(stat: wasi.filestat_t) Stat {
|
||||
return .{
|
||||
.dev = stat.dev,
|
||||
.ino = stat.ino,
|
||||
.mode = switch (stat.filetype) {
|
||||
.UNKNOWN => 0,
|
||||
.BLOCK_DEVICE => S.IFBLK,
|
||||
.CHARACTER_DEVICE => S.IFCHR,
|
||||
.DIRECTORY => S.IFDIR,
|
||||
.REGULAR_FILE => S.IFREG,
|
||||
.SOCKET_DGRAM => S.IFSOCK,
|
||||
.SOCKET_STREAM => S.IFIFO,
|
||||
.SYMBOLIC_LINK => S.IFLNK,
|
||||
_ => 0,
|
||||
},
|
||||
.nlink = stat.nlink,
|
||||
.size = @intCast(stat.size),
|
||||
.atim = timespec.fromTimestamp(stat.atim),
|
||||
.mtim = timespec.fromTimestamp(stat.mtim),
|
||||
.ctim = timespec.fromTimestamp(stat.ctim),
|
||||
|
||||
.uid = 0,
|
||||
.gid = 0,
|
||||
.rdev = 0,
|
||||
.blksize = 0,
|
||||
.blocks = 0,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
pub const F = struct {
|
||||
pub const GETFD = 1;
|
||||
pub const SETFD = 2;
|
||||
pub const GETFL = 3;
|
||||
pub const SETFL = 4;
|
||||
};
|
||||
|
||||
pub const FD_CLOEXEC = 1;
|
||||
|
||||
pub const F_OK = 0;
|
||||
pub const X_OK = 1;
|
||||
pub const W_OK = 2;
|
||||
pub const R_OK = 4;
|
||||
|
||||
pub const SEEK = struct {
|
||||
pub const SET: wasi.whence_t = .SET;
|
||||
pub const CUR: wasi.whence_t = .CUR;
|
||||
pub const END: wasi.whence_t = .END;
|
||||
};
|
||||
|
||||
pub const nfds_t = usize;
|
||||
|
||||
pub const pollfd = extern struct {
|
||||
fd: fd_t,
|
||||
events: i16,
|
||||
revents: i16,
|
||||
};
|
||||
|
||||
pub const POLL = struct {
|
||||
pub const RDNORM = 0x1;
|
||||
pub const WRNORM = 0x2;
|
||||
pub const IN = RDNORM;
|
||||
pub const OUT = WRNORM;
|
||||
pub const ERR = 0x1000;
|
||||
pub const HUP = 0x2000;
|
||||
pub const NVAL = 0x4000;
|
||||
};
|
||||
@@ -1,226 +0,0 @@
|
||||
//! The reference for these types and values is Microsoft Windows's ucrt (Universal C RunTime).
|
||||
const std = @import("../std.zig");
|
||||
const ws2_32 = std.os.windows.ws2_32;
|
||||
const windows = std.os.windows;
|
||||
|
||||
pub extern "c" fn _errno() *c_int;
|
||||
|
||||
pub extern "c" fn _msize(memblock: ?*anyopaque) usize;
|
||||
|
||||
// TODO: copied the else case and removed the socket function (because its in ws2_32)
|
||||
// need to verify which of these is actually supported on windows
|
||||
pub extern "c" fn clock_getres(clk_id: c_int, tp: *timespec) c_int;
|
||||
pub extern "c" fn clock_gettime(clk_id: c_int, tp: *timespec) c_int;
|
||||
pub extern "c" fn getrusage(who: c_int, usage: *rusage) c_int;
|
||||
pub extern "c" fn gettimeofday(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int;
|
||||
pub extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int;
|
||||
pub extern "c" fn sched_yield() c_int;
|
||||
pub extern "c" fn sigaction(sig: c_int, noalias act: ?*const Sigaction, noalias oact: ?*Sigaction) c_int;
|
||||
pub extern "c" fn sigprocmask(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*sigset_t) c_int;
|
||||
pub extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *Stat) c_int;
|
||||
pub extern "c" fn sigfillset(set: ?*sigset_t) void;
|
||||
pub extern "c" fn alarm(seconds: c_uint) c_uint;
|
||||
pub extern "c" fn sigwait(set: ?*sigset_t, sig: ?*c_int) c_int;
|
||||
|
||||
pub const fd_t = windows.HANDLE;
|
||||
pub const ino_t = windows.LARGE_INTEGER;
|
||||
pub const pid_t = windows.HANDLE;
|
||||
pub const mode_t = u0;
|
||||
|
||||
pub const PATH_MAX = 260;
|
||||
|
||||
pub const time_t = c_longlong;
|
||||
|
||||
pub const timespec = extern struct {
|
||||
tv_sec: time_t,
|
||||
tv_nsec: c_long,
|
||||
};
|
||||
|
||||
pub const timeval = extern struct {
|
||||
tv_sec: c_long,
|
||||
tv_usec: c_long,
|
||||
};
|
||||
|
||||
pub const Stat = @compileError("TODO windows Stat definition");
|
||||
|
||||
pub const sig_atomic_t = c_int;
|
||||
|
||||
pub const sigset_t = @compileError("TODO windows sigset_t definition");
|
||||
pub const Sigaction = @compileError("TODO windows Sigaction definition");
|
||||
pub const timezone = @compileError("TODO windows timezone definition");
|
||||
pub const rusage = @compileError("TODO windows rusage definition");
|
||||
|
||||
/// maximum signal number + 1
|
||||
pub const NSIG = 23;
|
||||
|
||||
/// Signal types
|
||||
pub const SIG = struct {
|
||||
/// interrupt
|
||||
pub const INT = 2;
|
||||
/// illegal instruction - invalid function image
|
||||
pub const ILL = 4;
|
||||
/// floating point exception
|
||||
pub const FPE = 8;
|
||||
/// segment violation
|
||||
pub const SEGV = 11;
|
||||
/// Software termination signal from kill
|
||||
pub const TERM = 15;
|
||||
/// Ctrl-Break sequence
|
||||
pub const BREAK = 21;
|
||||
/// abnormal termination triggered by abort call
|
||||
pub const ABRT = 22;
|
||||
/// SIGABRT compatible with other platforms, same as SIGABRT
|
||||
pub const ABRT_COMPAT = 6;
|
||||
|
||||
// Signal action codes
|
||||
/// default signal action
|
||||
pub const DFL = 0;
|
||||
/// ignore signal
|
||||
pub const IGN = 1;
|
||||
/// return current value
|
||||
pub const GET = 2;
|
||||
/// signal gets error
|
||||
pub const SGE = 3;
|
||||
/// acknowledge
|
||||
pub const ACK = 4;
|
||||
/// Signal error value (returned by signal call on error)
|
||||
pub const ERR = -1;
|
||||
};
|
||||
|
||||
pub const SEEK = struct {
|
||||
pub const SET = 0;
|
||||
pub const CUR = 1;
|
||||
pub const END = 2;
|
||||
};
|
||||
|
||||
/// Basic memory protection flags
|
||||
pub const PROT = struct {
|
||||
/// page can not be accessed
|
||||
pub const NONE = 0x0;
|
||||
/// page can be read
|
||||
pub const READ = 0x1;
|
||||
/// page can be written
|
||||
pub const WRITE = 0x2;
|
||||
/// page can be executed
|
||||
pub const EXEC = 0x4;
|
||||
};
|
||||
|
||||
pub const E = enum(u16) {
|
||||
/// No error occurred.
|
||||
SUCCESS = 0,
|
||||
PERM = 1,
|
||||
NOENT = 2,
|
||||
SRCH = 3,
|
||||
INTR = 4,
|
||||
IO = 5,
|
||||
NXIO = 6,
|
||||
@"2BIG" = 7,
|
||||
NOEXEC = 8,
|
||||
BADF = 9,
|
||||
CHILD = 10,
|
||||
AGAIN = 11,
|
||||
NOMEM = 12,
|
||||
ACCES = 13,
|
||||
FAULT = 14,
|
||||
BUSY = 16,
|
||||
EXIST = 17,
|
||||
XDEV = 18,
|
||||
NODEV = 19,
|
||||
NOTDIR = 20,
|
||||
ISDIR = 21,
|
||||
NFILE = 23,
|
||||
MFILE = 24,
|
||||
NOTTY = 25,
|
||||
FBIG = 27,
|
||||
NOSPC = 28,
|
||||
SPIPE = 29,
|
||||
ROFS = 30,
|
||||
MLINK = 31,
|
||||
PIPE = 32,
|
||||
DOM = 33,
|
||||
/// Also means `DEADLOCK`.
|
||||
DEADLK = 36,
|
||||
NAMETOOLONG = 38,
|
||||
NOLCK = 39,
|
||||
NOSYS = 40,
|
||||
NOTEMPTY = 41,
|
||||
|
||||
INVAL = 22,
|
||||
RANGE = 34,
|
||||
ILSEQ = 42,
|
||||
|
||||
// POSIX Supplement
|
||||
ADDRINUSE = 100,
|
||||
ADDRNOTAVAIL = 101,
|
||||
AFNOSUPPORT = 102,
|
||||
ALREADY = 103,
|
||||
BADMSG = 104,
|
||||
CANCELED = 105,
|
||||
CONNABORTED = 106,
|
||||
CONNREFUSED = 107,
|
||||
CONNRESET = 108,
|
||||
DESTADDRREQ = 109,
|
||||
HOSTUNREACH = 110,
|
||||
IDRM = 111,
|
||||
INPROGRESS = 112,
|
||||
ISCONN = 113,
|
||||
LOOP = 114,
|
||||
MSGSIZE = 115,
|
||||
NETDOWN = 116,
|
||||
NETRESET = 117,
|
||||
NETUNREACH = 118,
|
||||
NOBUFS = 119,
|
||||
NODATA = 120,
|
||||
NOLINK = 121,
|
||||
NOMSG = 122,
|
||||
NOPROTOOPT = 123,
|
||||
NOSR = 124,
|
||||
NOSTR = 125,
|
||||
NOTCONN = 126,
|
||||
NOTRECOVERABLE = 127,
|
||||
NOTSOCK = 128,
|
||||
NOTSUP = 129,
|
||||
OPNOTSUPP = 130,
|
||||
OTHER = 131,
|
||||
OVERFLOW = 132,
|
||||
OWNERDEAD = 133,
|
||||
PROTO = 134,
|
||||
PROTONOSUPPORT = 135,
|
||||
PROTOTYPE = 136,
|
||||
TIME = 137,
|
||||
TIMEDOUT = 138,
|
||||
TXTBSY = 139,
|
||||
WOULDBLOCK = 140,
|
||||
DQUOT = 10069,
|
||||
_,
|
||||
};
|
||||
|
||||
pub const STRUNCATE = 80;
|
||||
|
||||
pub const F_OK = 0;
|
||||
|
||||
pub const in_port_t = u16;
|
||||
pub const sa_family_t = ws2_32.ADDRESS_FAMILY;
|
||||
pub const socklen_t = ws2_32.socklen_t;
|
||||
|
||||
pub const sockaddr = ws2_32.sockaddr;
|
||||
|
||||
pub const in6_addr = [16]u8;
|
||||
pub const in_addr = u32;
|
||||
|
||||
pub const addrinfo = ws2_32.addrinfo;
|
||||
pub const AF = ws2_32.AF;
|
||||
pub const MSG = ws2_32.MSG;
|
||||
pub const SOCK = ws2_32.SOCK;
|
||||
pub const TCP = ws2_32.TCP;
|
||||
pub const IPPROTO = ws2_32.IPPROTO;
|
||||
pub const BTHPROTO_RFCOMM = ws2_32.BTHPROTO_RFCOMM;
|
||||
|
||||
pub const nfds_t = c_ulong;
|
||||
pub const pollfd = ws2_32.pollfd;
|
||||
pub const POLL = ws2_32.POLL;
|
||||
pub const SOL = ws2_32.SOL;
|
||||
pub const SO = ws2_32.SO;
|
||||
pub const PVD_CONFIG = ws2_32.PVD_CONFIG;
|
||||
|
||||
pub const IFNAMESIZE = 30;
|
||||
@@ -42,7 +42,7 @@ pub fn rescanMac(cb: *Bundle, gpa: Allocator) RescanMacError!void {
|
||||
|
||||
const table_header = try reader.readStructEndian(TableHeader, .big);
|
||||
|
||||
if (@as(std.c.cssm.DB_RECORDTYPE, @enumFromInt(table_header.table_id)) != .X509_CERTIFICATE) {
|
||||
if (@as(std.c.DB_RECORDTYPE, @enumFromInt(table_header.table_id)) != .X509_CERTIFICATE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,39 +11,19 @@ const posix = std.posix;
|
||||
|
||||
/// We use this as a layer of indirection because global const pointers cannot
|
||||
/// point to thread-local variables.
|
||||
pub const interface = std.Random{
|
||||
pub const interface: std.Random = .{
|
||||
.ptr = undefined,
|
||||
.fillFn = tlsCsprngFill,
|
||||
};
|
||||
|
||||
const os_has_fork = switch (native_os) {
|
||||
.dragonfly,
|
||||
.freebsd,
|
||||
.ios,
|
||||
.kfreebsd,
|
||||
.linux,
|
||||
.macos,
|
||||
.netbsd,
|
||||
.openbsd,
|
||||
.solaris,
|
||||
.illumos,
|
||||
.tvos,
|
||||
.watchos,
|
||||
.visionos,
|
||||
.haiku,
|
||||
=> true,
|
||||
|
||||
else => false,
|
||||
};
|
||||
const os_has_arc4random = builtin.link_libc and @hasDecl(std.c, "arc4random_buf");
|
||||
const want_fork_safety = os_has_fork and !os_has_arc4random and
|
||||
std.options.crypto_fork_safety;
|
||||
const os_has_fork = @TypeOf(posix.fork) != void;
|
||||
const os_has_arc4random = builtin.link_libc and (@TypeOf(std.c.arc4random_buf) != void);
|
||||
const want_fork_safety = os_has_fork and !os_has_arc4random and std.options.crypto_fork_safety;
|
||||
const maybe_have_wipe_on_fork = builtin.os.isAtLeast(.linux, .{
|
||||
.major = 4,
|
||||
.minor = 14,
|
||||
.patch = 0,
|
||||
}) orelse true;
|
||||
const is_haiku = native_os == .haiku;
|
||||
|
||||
const Rng = std.Random.DefaultCsprng;
|
||||
|
||||
@@ -65,7 +45,7 @@ var install_atfork_handler = std.once(struct {
|
||||
threadlocal var wipe_mem: []align(mem.page_size) u8 = &[_]u8{};
|
||||
|
||||
fn tlsCsprngFill(_: *anyopaque, buffer: []u8) void {
|
||||
if (builtin.link_libc and @hasDecl(std.c, "arc4random_buf")) {
|
||||
if (os_has_arc4random) {
|
||||
// arc4random is already a thread-local CSPRNG.
|
||||
return std.c.arc4random_buf(buffer.ptr, buffer.len);
|
||||
}
|
||||
@@ -78,7 +58,7 @@ fn tlsCsprngFill(_: *anyopaque, buffer: []u8) void {
|
||||
|
||||
if (wipe_mem.len == 0) {
|
||||
// Not initialized yet.
|
||||
if (want_fork_safety and maybe_have_wipe_on_fork or is_haiku) {
|
||||
if (want_fork_safety and maybe_have_wipe_on_fork) {
|
||||
// Allocate a per-process page, madvise operates with page
|
||||
// granularity.
|
||||
wipe_mem = posix.mmap(
|
||||
|
||||
+22
-28
@@ -201,11 +201,7 @@ pub fn dumpCurrentStackTrace(start_addr: ?usize) void {
|
||||
}
|
||||
}
|
||||
|
||||
pub const have_ucontext = @hasDecl(posix.system, "ucontext_t") and
|
||||
(native_os != .linux or switch (builtin.cpu.arch) {
|
||||
.mips, .mipsel, .mips64, .mips64el, .riscv64 => false,
|
||||
else => true,
|
||||
});
|
||||
pub const have_ucontext = posix.ucontext_t != void;
|
||||
|
||||
/// Platform-specific thread state. This contains register state, and on some platforms
|
||||
/// information about the stack. This is not safe to trivially copy, because some platforms
|
||||
@@ -237,14 +233,7 @@ pub fn relocateContext(context: *ThreadContext) void {
|
||||
};
|
||||
}
|
||||
|
||||
pub const have_getcontext = native_os != .openbsd and native_os != .haiku and
|
||||
!builtin.target.isAndroid() and
|
||||
(native_os != .linux or switch (builtin.cpu.arch) {
|
||||
.x86,
|
||||
.x86_64,
|
||||
=> true,
|
||||
else => builtin.link_libc and !builtin.target.isMusl(),
|
||||
});
|
||||
pub const have_getcontext = @TypeOf(posix.system.getcontext) != void;
|
||||
|
||||
/// Capture the current context. The register values in the context will reflect the
|
||||
/// state after the platform `getcontext` function returns.
|
||||
@@ -704,7 +693,7 @@ pub const StackIterator = struct {
|
||||
}
|
||||
|
||||
return true;
|
||||
} else if (@hasDecl(posix.system, "msync") and native_os != .wasi and native_os != .emscripten) {
|
||||
} else if (have_msync) {
|
||||
posix.msync(aligned_memory, posix.MSF.ASYNC) catch |err| {
|
||||
switch (err) {
|
||||
error.UnmappedMemory => return false,
|
||||
@@ -853,6 +842,11 @@ pub const StackIterator = struct {
|
||||
}
|
||||
};
|
||||
|
||||
const have_msync = switch (native_os) {
|
||||
.wasi, .emscripten, .windows => false,
|
||||
else => true,
|
||||
};
|
||||
|
||||
pub fn writeCurrentStackTrace(
|
||||
out_stream: anytype,
|
||||
debug_info: *DebugInfo,
|
||||
@@ -2078,15 +2072,15 @@ pub const DebugInfo = struct {
|
||||
if (posix.dl_iterate_phdr(&ctx, error{Found}, struct {
|
||||
fn callback(info: *posix.dl_phdr_info, size: usize, context: *CtxTy) !void {
|
||||
_ = size;
|
||||
if (context.address < info.dlpi_addr) return;
|
||||
const phdrs = info.dlpi_phdr[0..info.dlpi_phnum];
|
||||
if (context.address < info.addr) return;
|
||||
const phdrs = info.phdr[0..info.phnum];
|
||||
for (phdrs) |*phdr| {
|
||||
if (phdr.p_type != elf.PT_LOAD) continue;
|
||||
|
||||
const seg_start = info.dlpi_addr +% phdr.p_vaddr;
|
||||
const seg_start = info.addr +% phdr.p_vaddr;
|
||||
const seg_end = seg_start + phdr.p_memsz;
|
||||
if (context.address >= seg_start and context.address < seg_end) {
|
||||
context.name = mem.sliceTo(info.dlpi_name, 0) orelse "";
|
||||
context.name = mem.sliceTo(info.name, 0) orelse "";
|
||||
break;
|
||||
}
|
||||
} else return;
|
||||
@@ -2118,30 +2112,30 @@ pub const DebugInfo = struct {
|
||||
fn callback(info: *posix.dl_phdr_info, size: usize, context: *CtxTy) !void {
|
||||
_ = size;
|
||||
// The base address is too high
|
||||
if (context.address < info.dlpi_addr)
|
||||
if (context.address < info.addr)
|
||||
return;
|
||||
|
||||
const phdrs = info.dlpi_phdr[0..info.dlpi_phnum];
|
||||
const phdrs = info.phdr[0..info.phnum];
|
||||
for (phdrs) |*phdr| {
|
||||
if (phdr.p_type != elf.PT_LOAD) continue;
|
||||
|
||||
// Overflowing addition is used to handle the case of VSDOs having a p_vaddr = 0xffffffffff700000
|
||||
const seg_start = info.dlpi_addr +% phdr.p_vaddr;
|
||||
const seg_start = info.addr +% phdr.p_vaddr;
|
||||
const seg_end = seg_start + phdr.p_memsz;
|
||||
if (context.address >= seg_start and context.address < seg_end) {
|
||||
// Android libc uses NULL instead of an empty string to mark the
|
||||
// main program
|
||||
context.name = mem.sliceTo(info.dlpi_name, 0) orelse "";
|
||||
context.base_address = info.dlpi_addr;
|
||||
context.name = mem.sliceTo(info.name, 0) orelse "";
|
||||
context.base_address = info.addr;
|
||||
break;
|
||||
}
|
||||
} else return;
|
||||
|
||||
for (info.dlpi_phdr[0..info.dlpi_phnum]) |phdr| {
|
||||
for (info.phdr[0..info.phnum]) |phdr| {
|
||||
switch (phdr.p_type) {
|
||||
elf.PT_NOTE => {
|
||||
// Look for .note.gnu.build-id
|
||||
const note_bytes = @as([*]const u8, @ptrFromInt(info.dlpi_addr + phdr.p_vaddr))[0..phdr.p_memsz];
|
||||
const note_bytes = @as([*]const u8, @ptrFromInt(info.addr + phdr.p_vaddr))[0..phdr.p_memsz];
|
||||
const name_size = mem.readInt(u32, note_bytes[0..4], native_endian);
|
||||
if (name_size != 4) continue;
|
||||
const desc_size = mem.readInt(u32, note_bytes[4..8], native_endian);
|
||||
@@ -2151,7 +2145,7 @@ pub const DebugInfo = struct {
|
||||
context.build_id = note_bytes[16..][0..desc_size];
|
||||
},
|
||||
elf.PT_GNU_EH_FRAME => {
|
||||
context.gnu_eh_frame = @as([*]const u8, @ptrFromInt(info.dlpi_addr + phdr.p_vaddr))[0..phdr.p_memsz];
|
||||
context.gnu_eh_frame = @as([*]const u8, @ptrFromInt(info.addr + phdr.p_vaddr))[0..phdr.p_memsz];
|
||||
},
|
||||
else => {},
|
||||
}
|
||||
@@ -2592,7 +2586,7 @@ pub const have_segfault_handling_support = switch (native_os) {
|
||||
.windows,
|
||||
=> true,
|
||||
|
||||
.freebsd, .openbsd => @hasDecl(std.c, "ucontext_t"),
|
||||
.freebsd, .openbsd => have_ucontext,
|
||||
else => false,
|
||||
};
|
||||
|
||||
@@ -2742,7 +2736,7 @@ fn handleSegfaultWindowsExtra(
|
||||
label: ?[]const u8,
|
||||
) noreturn {
|
||||
const exception_address = @intFromPtr(info.ExceptionRecord.ExceptionAddress);
|
||||
if (@hasDecl(windows, "CONTEXT")) {
|
||||
if (windows.CONTEXT != void) {
|
||||
nosuspend switch (panic_stage) {
|
||||
0 => {
|
||||
panic_stage = 1;
|
||||
|
||||
@@ -440,7 +440,7 @@ pub const DlDynLib = struct {
|
||||
|
||||
pub fn openZ(path_c: [*:0]const u8) Error!DlDynLib {
|
||||
return .{
|
||||
.handle = std.c.dlopen(path_c, std.c.RTLD.LAZY) orelse {
|
||||
.handle = std.c.dlopen(path_c, .{ .LAZY = true }) orelse {
|
||||
return error.FileNotFound;
|
||||
},
|
||||
};
|
||||
|
||||
+1
-5
@@ -1082,11 +1082,7 @@ pub const Addr = switch (@sizeOf(usize)) {
|
||||
8 => Elf64_Addr,
|
||||
else => @compileError("expected pointer size of 32 or 64"),
|
||||
};
|
||||
pub const Half = switch (@sizeOf(usize)) {
|
||||
4 => Elf32_Half,
|
||||
8 => Elf64_Half,
|
||||
else => @compileError("expected pointer size of 32 or 64"),
|
||||
};
|
||||
pub const Half = u16;
|
||||
|
||||
/// Machine architectures.
|
||||
///
|
||||
|
||||
+12
-13
@@ -178,7 +178,8 @@ pub const Iterator = switch (native_os) {
|
||||
self.end_index = @as(usize, @intCast(rc));
|
||||
}
|
||||
const bsd_entry = @as(*align(1) posix.system.dirent, @ptrCast(&self.buf[self.index]));
|
||||
const next_index = self.index + if (@hasDecl(posix.system.dirent, "reclen")) bsd_entry.reclen() else bsd_entry.reclen;
|
||||
const next_index = self.index +
|
||||
if (@hasField(posix.system.dirent, "reclen")) bsd_entry.reclen else bsd_entry.reclen();
|
||||
self.index = next_index;
|
||||
|
||||
const name = @as([*]u8, @ptrCast(&bsd_entry.name))[0..bsd_entry.namlen];
|
||||
@@ -880,16 +881,14 @@ pub fn openFileZ(self: Dir, sub_path: [*:0]const u8, flags: File.OpenFlags) File
|
||||
const fd = try posix.openatZ(self.fd, sub_path, os_flags, 0);
|
||||
errdefer posix.close(fd);
|
||||
|
||||
if (@hasDecl(posix.system, "LOCK")) {
|
||||
if (!has_flock_open_flags and flags.lock != .none) {
|
||||
// TODO: integrate async I/O
|
||||
const lock_nonblocking: i32 = if (flags.lock_nonblocking) posix.LOCK.NB else 0;
|
||||
try posix.flock(fd, switch (flags.lock) {
|
||||
.none => unreachable,
|
||||
.shared => posix.LOCK.SH | lock_nonblocking,
|
||||
.exclusive => posix.LOCK.EX | lock_nonblocking,
|
||||
});
|
||||
}
|
||||
if (!has_flock_open_flags and flags.lock != .none) {
|
||||
// TODO: integrate async I/O
|
||||
const lock_nonblocking: i32 = if (flags.lock_nonblocking) posix.LOCK.NB else 0;
|
||||
try posix.flock(fd, switch (flags.lock) {
|
||||
.none => unreachable,
|
||||
.shared => posix.LOCK.SH | lock_nonblocking,
|
||||
.exclusive => posix.LOCK.EX | lock_nonblocking,
|
||||
});
|
||||
}
|
||||
|
||||
if (has_flock_open_flags and flags.lock_nonblocking) {
|
||||
@@ -2539,8 +2538,8 @@ const CopyFileRawError = error{SystemResources} || posix.CopyFileRangeError || p
|
||||
// The copy starts at offset 0, the initial offsets are preserved.
|
||||
// No metadata is transferred over.
|
||||
fn copy_file(fd_in: posix.fd_t, fd_out: posix.fd_t, maybe_size: ?u64) CopyFileRawError!void {
|
||||
if (comptime builtin.target.isDarwin()) {
|
||||
const rc = posix.system.fcopyfile(fd_in, fd_out, null, posix.system.COPYFILE_DATA);
|
||||
if (builtin.target.isDarwin()) {
|
||||
const rc = posix.system.fcopyfile(fd_in, fd_out, null, .{ .DATA = true });
|
||||
switch (posix.errno(rc)) {
|
||||
.SUCCESS => return,
|
||||
.INVAL => unreachable,
|
||||
|
||||
+21
-21
@@ -420,9 +420,9 @@ pub const Stat = struct {
|
||||
|
||||
break :k .unknown;
|
||||
},
|
||||
.atime = @as(i128, atime.tv_sec) * std.time.ns_per_s + atime.tv_nsec,
|
||||
.mtime = @as(i128, mtime.tv_sec) * std.time.ns_per_s + mtime.tv_nsec,
|
||||
.ctime = @as(i128, ctime.tv_sec) * std.time.ns_per_s + ctime.tv_nsec,
|
||||
.atime = @as(i128, atime.sec) * std.time.ns_per_s + atime.nsec,
|
||||
.mtime = @as(i128, mtime.sec) * std.time.ns_per_s + mtime.nsec,
|
||||
.ctime = @as(i128, ctime.sec) * std.time.ns_per_s + ctime.nsec,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -791,13 +791,13 @@ pub const MetadataUnix = struct {
|
||||
/// Returns the last time the file was accessed in nanoseconds since UTC 1970-01-01
|
||||
pub fn accessed(self: Self) i128 {
|
||||
const atime = self.stat.atime();
|
||||
return @as(i128, atime.tv_sec) * std.time.ns_per_s + atime.tv_nsec;
|
||||
return @as(i128, atime.sec) * std.time.ns_per_s + atime.nsec;
|
||||
}
|
||||
|
||||
/// Returns the last time the file was modified in nanoseconds since UTC 1970-01-01
|
||||
pub fn modified(self: Self) i128 {
|
||||
const mtime = self.stat.mtime();
|
||||
return @as(i128, mtime.tv_sec) * std.time.ns_per_s + mtime.tv_nsec;
|
||||
return @as(i128, mtime.sec) * std.time.ns_per_s + mtime.nsec;
|
||||
}
|
||||
|
||||
/// Returns the time the file was created in nanoseconds since UTC 1970-01-01.
|
||||
@@ -807,17 +807,17 @@ pub const MetadataUnix = struct {
|
||||
const birthtime = self.stat.birthtime();
|
||||
|
||||
// If the filesystem doesn't support this the value *should* be:
|
||||
// On FreeBSD: tv_nsec = 0, tv_sec = -1
|
||||
// On NetBSD and OpenBSD: tv_nsec = 0, tv_sec = 0
|
||||
// On FreeBSD: nsec = 0, sec = -1
|
||||
// On NetBSD and OpenBSD: nsec = 0, sec = 0
|
||||
// On MacOS, it is set to ctime -- we cannot detect this!!
|
||||
switch (builtin.os.tag) {
|
||||
.freebsd => if (birthtime.tv_sec == -1 and birthtime.tv_nsec == 0) return null,
|
||||
.netbsd, .openbsd => if (birthtime.tv_sec == 0 and birthtime.tv_nsec == 0) return null,
|
||||
.freebsd => if (birthtime.sec == -1 and birthtime.nsec == 0) return null,
|
||||
.netbsd, .openbsd => if (birthtime.sec == 0 and birthtime.nsec == 0) return null,
|
||||
.macos => {},
|
||||
else => @compileError("Creation time detection not implemented for OS"),
|
||||
}
|
||||
|
||||
return @as(i128, birthtime.tv_sec) * std.time.ns_per_s + birthtime.tv_nsec;
|
||||
return @as(i128, birthtime.sec) * std.time.ns_per_s + birthtime.nsec;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -858,19 +858,19 @@ pub const MetadataLinux = struct {
|
||||
|
||||
/// Returns the last time the file was accessed in nanoseconds since UTC 1970-01-01
|
||||
pub fn accessed(self: Self) i128 {
|
||||
return @as(i128, self.statx.atime.tv_sec) * std.time.ns_per_s + self.statx.atime.tv_nsec;
|
||||
return @as(i128, self.statx.atime.sec) * std.time.ns_per_s + self.statx.atime.nsec;
|
||||
}
|
||||
|
||||
/// Returns the last time the file was modified in nanoseconds since UTC 1970-01-01
|
||||
pub fn modified(self: Self) i128 {
|
||||
return @as(i128, self.statx.mtime.tv_sec) * std.time.ns_per_s + self.statx.mtime.tv_nsec;
|
||||
return @as(i128, self.statx.mtime.sec) * std.time.ns_per_s + self.statx.mtime.nsec;
|
||||
}
|
||||
|
||||
/// Returns the time the file was created in nanoseconds since UTC 1970-01-01.
|
||||
/// Returns null if this is not supported by the filesystem, or on kernels before than version 4.11
|
||||
pub fn created(self: Self) ?i128 {
|
||||
if (self.statx.mask & std.os.linux.STATX_BTIME == 0) return null;
|
||||
return @as(i128, self.statx.btime.tv_sec) * std.time.ns_per_s + self.statx.btime.tv_nsec;
|
||||
return @as(i128, self.statx.btime.sec) * std.time.ns_per_s + self.statx.btime.nsec;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1026,12 +1026,12 @@ pub fn metadata(self: File) MetadataError!Metadata {
|
||||
|
||||
// Hacky conversion from timespec to statx_timestamp
|
||||
stx.atime = std.mem.zeroes(l.statx_timestamp);
|
||||
stx.atime.tv_sec = st.atim.tv_sec;
|
||||
stx.atime.tv_nsec = @as(u32, @intCast(st.atim.tv_nsec)); // Guaranteed to succeed (tv_nsec is always below 10^9)
|
||||
stx.atime.sec = st.atim.sec;
|
||||
stx.atime.nsec = @as(u32, @intCast(st.atim.nsec)); // Guaranteed to succeed (nsec is always below 10^9)
|
||||
|
||||
stx.mtime = std.mem.zeroes(l.statx_timestamp);
|
||||
stx.mtime.tv_sec = st.mtim.tv_sec;
|
||||
stx.mtime.tv_nsec = @as(u32, @intCast(st.mtim.tv_nsec));
|
||||
stx.mtime.sec = st.mtim.sec;
|
||||
stx.mtime.nsec = @as(u32, @intCast(st.mtim.nsec));
|
||||
|
||||
stx.mask = l.STATX_BASIC_STATS | l.STATX_MTIME;
|
||||
},
|
||||
@@ -1072,12 +1072,12 @@ pub fn updateTimes(
|
||||
}
|
||||
const times = [2]posix.timespec{
|
||||
posix.timespec{
|
||||
.tv_sec = math.cast(isize, @divFloor(atime, std.time.ns_per_s)) orelse maxInt(isize),
|
||||
.tv_nsec = math.cast(isize, @mod(atime, std.time.ns_per_s)) orelse maxInt(isize),
|
||||
.sec = math.cast(isize, @divFloor(atime, std.time.ns_per_s)) orelse maxInt(isize),
|
||||
.nsec = math.cast(isize, @mod(atime, std.time.ns_per_s)) orelse maxInt(isize),
|
||||
},
|
||||
posix.timespec{
|
||||
.tv_sec = math.cast(isize, @divFloor(mtime, std.time.ns_per_s)) orelse maxInt(isize),
|
||||
.tv_nsec = math.cast(isize, @mod(mtime, std.time.ns_per_s)) orelse maxInt(isize),
|
||||
.sec = math.cast(isize, @divFloor(mtime, std.time.ns_per_s)) orelse maxInt(isize),
|
||||
.nsec = math.cast(isize, @mod(mtime, std.time.ns_per_s)) orelse maxInt(isize),
|
||||
},
|
||||
};
|
||||
try posix.futimens(self.handle, ×);
|
||||
|
||||
+7
-4
@@ -40,15 +40,18 @@ const CAllocator = struct {
|
||||
}
|
||||
|
||||
pub const supports_malloc_size = @TypeOf(malloc_size) != void;
|
||||
pub const malloc_size = if (@hasDecl(c, "malloc_size"))
|
||||
pub const malloc_size = if (@TypeOf(c.malloc_size) != void)
|
||||
c.malloc_size
|
||||
else if (@hasDecl(c, "malloc_usable_size"))
|
||||
else if (@TypeOf(c.malloc_usable_size) != void)
|
||||
c.malloc_usable_size
|
||||
else if (@hasDecl(c, "_msize"))
|
||||
else if (@TypeOf(c._msize) != void)
|
||||
c._msize
|
||||
else {};
|
||||
|
||||
pub const supports_posix_memalign = @hasDecl(c, "posix_memalign");
|
||||
pub const supports_posix_memalign = switch (builtin.os.tag) {
|
||||
.dragonfly, .netbsd, .freebsd, .solaris, .openbsd, .linux, .macos, .ios, .tvos, .watchos, .visionos => true,
|
||||
else => false,
|
||||
};
|
||||
|
||||
fn getHeader(ptr: [*]u8) *[*]u8 {
|
||||
return @as(*[*]u8, @ptrFromInt(@intFromPtr(ptr) - @sizeOf(usize)));
|
||||
|
||||
+12
-14
@@ -248,14 +248,13 @@ pub const Address = extern union {
|
||||
posix.SO.REUSEADDR,
|
||||
&mem.toBytes(@as(c_int, 1)),
|
||||
);
|
||||
switch (native_os) {
|
||||
.windows => {},
|
||||
else => try posix.setsockopt(
|
||||
if (@hasDecl(posix.SO, "REUSEPORT")) {
|
||||
try posix.setsockopt(
|
||||
sockfd,
|
||||
posix.SOL.SOCKET,
|
||||
posix.SO.REUSEPORT,
|
||||
&mem.toBytes(@as(c_int, 1)),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -853,8 +852,8 @@ pub fn getAddressList(allocator: mem.Allocator, name: []const u8, port: u16) Get
|
||||
defer allocator.free(port_c);
|
||||
|
||||
const ws2_32 = windows.ws2_32;
|
||||
const hints = posix.addrinfo{
|
||||
.flags = ws2_32.AI.NUMERICSERV,
|
||||
const hints: posix.addrinfo = .{
|
||||
.flags = .{ .NUMERICSERV = true },
|
||||
.family = posix.AF.UNSPEC,
|
||||
.socktype = posix.SOCK.STREAM,
|
||||
.protocol = posix.IPPROTO.TCP,
|
||||
@@ -925,8 +924,8 @@ pub fn getAddressList(allocator: mem.Allocator, name: []const u8, port: u16) Get
|
||||
defer allocator.free(port_c);
|
||||
|
||||
const sys = if (native_os == .windows) windows.ws2_32 else posix.system;
|
||||
const hints = posix.addrinfo{
|
||||
.flags = sys.AI.NUMERICSERV,
|
||||
const hints: posix.addrinfo = .{
|
||||
.flags = .{ .NUMERICSERV = true },
|
||||
.family = posix.AF.UNSPEC,
|
||||
.socktype = posix.SOCK.STREAM,
|
||||
.protocol = posix.IPPROTO.TCP,
|
||||
@@ -985,7 +984,6 @@ pub fn getAddressList(allocator: mem.Allocator, name: []const u8, port: u16) Get
|
||||
}
|
||||
|
||||
if (native_os == .linux) {
|
||||
const flags = std.c.AI.NUMERICSERV;
|
||||
const family = posix.AF.UNSPEC;
|
||||
var lookup_addrs = std.ArrayList(LookupAddr).init(allocator);
|
||||
defer lookup_addrs.deinit();
|
||||
@@ -993,7 +991,7 @@ pub fn getAddressList(allocator: mem.Allocator, name: []const u8, port: u16) Get
|
||||
var canon = std.ArrayList(u8).init(arena);
|
||||
defer canon.deinit();
|
||||
|
||||
try linuxLookupName(&lookup_addrs, &canon, name, family, flags, port);
|
||||
try linuxLookupName(&lookup_addrs, &canon, name, family, .{ .NUMERICSERV = true }, port);
|
||||
|
||||
result.addrs = try arena.alloc(Address, lookup_addrs.items.len);
|
||||
if (canon.items.len != 0) {
|
||||
@@ -1028,7 +1026,7 @@ fn linuxLookupName(
|
||||
canon: *std.ArrayList(u8),
|
||||
opt_name: ?[]const u8,
|
||||
family: posix.sa_family_t,
|
||||
flags: u32,
|
||||
flags: posix.AI,
|
||||
port: u16,
|
||||
) !void {
|
||||
if (opt_name) |name| {
|
||||
@@ -1037,7 +1035,7 @@ fn linuxLookupName(
|
||||
try canon.appendSlice(name);
|
||||
if (Address.parseExpectingFamily(name, family, port)) |addr| {
|
||||
try addrs.append(LookupAddr{ .addr = addr });
|
||||
} else |name_err| if ((flags & std.c.AI.NUMERICHOST) != 0) {
|
||||
} else |name_err| if (flags.NUMERICHOST) {
|
||||
return name_err;
|
||||
} else {
|
||||
try linuxLookupNameFromHosts(addrs, canon, name, family, port);
|
||||
@@ -1269,10 +1267,10 @@ fn addrCmpLessThan(context: void, b: LookupAddr, a: LookupAddr) bool {
|
||||
fn linuxLookupNameFromNull(
|
||||
addrs: *std.ArrayList(LookupAddr),
|
||||
family: posix.sa_family_t,
|
||||
flags: u32,
|
||||
flags: posix.AI,
|
||||
port: u16,
|
||||
) !void {
|
||||
if ((flags & std.c.AI.PASSIVE) != 0) {
|
||||
if (flags.PASSIVE) {
|
||||
if (family != posix.AF.INET6) {
|
||||
(try addrs.addOne()).* = LookupAddr{
|
||||
.addr = Address.initIp4([1]u8{0} ** 4, port),
|
||||
|
||||
+5
-3
@@ -23,6 +23,7 @@ const fs = std.fs;
|
||||
const dl = @import("dynamic_library.zig");
|
||||
const max_path_bytes = std.fs.max_path_bytes;
|
||||
const posix = std.posix;
|
||||
const native_os = builtin.os.tag;
|
||||
|
||||
pub const linux = @import("os/linux.zig");
|
||||
pub const plan9 = @import("os/plan9.zig");
|
||||
@@ -33,7 +34,7 @@ pub const windows = @import("os/windows.zig");
|
||||
|
||||
test {
|
||||
_ = linux;
|
||||
if (builtin.os.tag == .uefi) {
|
||||
if (native_os == .uefi) {
|
||||
_ = uefi;
|
||||
}
|
||||
_ = wasi;
|
||||
@@ -48,7 +49,7 @@ pub var environ: [][*:0]u8 = undefined;
|
||||
/// Populated by startup code before main().
|
||||
/// Not available on WASI or Windows without libc. See `std.process.argsAlloc`
|
||||
/// or `std.process.argsWithAllocator` for a cross-platform alternative.
|
||||
pub var argv: [][*:0]u8 = if (builtin.link_libc) undefined else switch (builtin.os.tag) {
|
||||
pub var argv: [][*:0]u8 = if (builtin.link_libc) undefined else switch (native_os) {
|
||||
.windows => @compileError("argv isn't supported on Windows: use std.process.argsAlloc instead"),
|
||||
.wasi => @compileError("argv isn't supported on WASI: use std.process.argsAlloc instead"),
|
||||
else => undefined,
|
||||
@@ -103,7 +104,7 @@ pub fn getFdPath(fd: std.posix.fd_t, out_buffer: *[max_path_bytes]u8) std.posix.
|
||||
if (!comptime isGetFdPathSupportedOnTarget(builtin.os)) {
|
||||
@compileError("querying for canonical path of a handle is unsupported on this host");
|
||||
}
|
||||
switch (builtin.os.tag) {
|
||||
switch (native_os) {
|
||||
.windows => {
|
||||
var wide_buf: [windows.PATH_MAX_WIDE]u16 = undefined;
|
||||
const wide_slice = try windows.GetFinalPathNameByHandle(fd, .{}, wide_buf[0..]);
|
||||
@@ -150,6 +151,7 @@ pub fn getFdPath(fd: std.posix.fd_t, out_buffer: *[max_path_bytes]u8) std.posix.
|
||||
const target = posix.readlinkZ(proc_path, out_buffer) catch |err| switch (err) {
|
||||
error.UnsupportedReparsePointType => unreachable,
|
||||
error.NotLink => unreachable,
|
||||
error.InvalidUtf8 => unreachable, // WASI-only
|
||||
else => |e| return e,
|
||||
};
|
||||
return target;
|
||||
|
||||
+28
-292
@@ -1,10 +1,14 @@
|
||||
const std = @import("std");
|
||||
const builtin = @import("builtin");
|
||||
const wasi = std.os.wasi;
|
||||
const linux = std.os.linux;
|
||||
const iovec = std.posix.iovec;
|
||||
const iovec_const = std.posix.iovec_const;
|
||||
const c = std.c;
|
||||
|
||||
// TODO: go through this file and delete all the bits that are identical to linux because they can
|
||||
// be merged in the std.c namespace.
|
||||
|
||||
pub const FILE = c.FILE;
|
||||
|
||||
var __stack_chk_guard: usize = 0;
|
||||
@@ -23,124 +27,9 @@ comptime {
|
||||
}
|
||||
}
|
||||
|
||||
pub const PF = struct {
|
||||
pub const UNSPEC = 0;
|
||||
pub const LOCAL = 1;
|
||||
pub const UNIX = LOCAL;
|
||||
pub const FILE = LOCAL;
|
||||
pub const INET = 2;
|
||||
pub const AX25 = 3;
|
||||
pub const IPX = 4;
|
||||
pub const APPLETALK = 5;
|
||||
pub const NETROM = 6;
|
||||
pub const BRIDGE = 7;
|
||||
pub const ATMPVC = 8;
|
||||
pub const X25 = 9;
|
||||
pub const INET6 = 10;
|
||||
pub const ROSE = 11;
|
||||
pub const DECnet = 12;
|
||||
pub const NETBEUI = 13;
|
||||
pub const SECURITY = 14;
|
||||
pub const KEY = 15;
|
||||
pub const NETLINK = 16;
|
||||
pub const ROUTE = PF.NETLINK;
|
||||
pub const PACKET = 17;
|
||||
pub const ASH = 18;
|
||||
pub const ECONET = 19;
|
||||
pub const ATMSVC = 20;
|
||||
pub const RDS = 21;
|
||||
pub const SNA = 22;
|
||||
pub const IRDA = 23;
|
||||
pub const PPPOX = 24;
|
||||
pub const WANPIPE = 25;
|
||||
pub const LLC = 26;
|
||||
pub const IB = 27;
|
||||
pub const MPLS = 28;
|
||||
pub const CAN = 29;
|
||||
pub const TIPC = 30;
|
||||
pub const BLUETOOTH = 31;
|
||||
pub const IUCV = 32;
|
||||
pub const RXRPC = 33;
|
||||
pub const ISDN = 34;
|
||||
pub const PHONET = 35;
|
||||
pub const IEEE802154 = 36;
|
||||
pub const CAIF = 37;
|
||||
pub const ALG = 38;
|
||||
pub const NFC = 39;
|
||||
pub const VSOCK = 40;
|
||||
pub const KCM = 41;
|
||||
pub const QIPCRTR = 42;
|
||||
pub const SMC = 43;
|
||||
pub const XDP = 44;
|
||||
pub const MAX = 45;
|
||||
};
|
||||
|
||||
pub const AF = struct {
|
||||
pub const UNSPEC = PF.UNSPEC;
|
||||
pub const LOCAL = PF.LOCAL;
|
||||
pub const UNIX = AF.LOCAL;
|
||||
pub const FILE = AF.LOCAL;
|
||||
pub const INET = PF.INET;
|
||||
pub const AX25 = PF.AX25;
|
||||
pub const IPX = PF.IPX;
|
||||
pub const APPLETALK = PF.APPLETALK;
|
||||
pub const NETROM = PF.NETROM;
|
||||
pub const BRIDGE = PF.BRIDGE;
|
||||
pub const ATMPVC = PF.ATMPVC;
|
||||
pub const X25 = PF.X25;
|
||||
pub const INET6 = PF.INET6;
|
||||
pub const ROSE = PF.ROSE;
|
||||
pub const DECnet = PF.DECnet;
|
||||
pub const NETBEUI = PF.NETBEUI;
|
||||
pub const SECURITY = PF.SECURITY;
|
||||
pub const KEY = PF.KEY;
|
||||
pub const NETLINK = PF.NETLINK;
|
||||
pub const ROUTE = PF.ROUTE;
|
||||
pub const PACKET = PF.PACKET;
|
||||
pub const ASH = PF.ASH;
|
||||
pub const ECONET = PF.ECONET;
|
||||
pub const ATMSVC = PF.ATMSVC;
|
||||
pub const RDS = PF.RDS;
|
||||
pub const SNA = PF.SNA;
|
||||
pub const IRDA = PF.IRDA;
|
||||
pub const PPPOX = PF.PPPOX;
|
||||
pub const WANPIPE = PF.WANPIPE;
|
||||
pub const LLC = PF.LLC;
|
||||
pub const IB = PF.IB;
|
||||
pub const MPLS = PF.MPLS;
|
||||
pub const CAN = PF.CAN;
|
||||
pub const TIPC = PF.TIPC;
|
||||
pub const BLUETOOTH = PF.BLUETOOTH;
|
||||
pub const IUCV = PF.IUCV;
|
||||
pub const RXRPC = PF.RXRPC;
|
||||
pub const ISDN = PF.ISDN;
|
||||
pub const PHONET = PF.PHONET;
|
||||
pub const IEEE802154 = PF.IEEE802154;
|
||||
pub const CAIF = PF.CAIF;
|
||||
pub const ALG = PF.ALG;
|
||||
pub const NFC = PF.NFC;
|
||||
pub const VSOCK = PF.VSOCK;
|
||||
pub const KCM = PF.KCM;
|
||||
pub const QIPCRTR = PF.QIPCRTR;
|
||||
pub const SMC = PF.SMC;
|
||||
pub const XDP = PF.XDP;
|
||||
pub const MAX = PF.MAX;
|
||||
};
|
||||
|
||||
pub const CLOCK = struct {
|
||||
pub const REALTIME = 0;
|
||||
pub const MONOTONIC = 1;
|
||||
pub const PROCESS_CPUTIME_ID = 2;
|
||||
pub const THREAD_CPUTIME_ID = 3;
|
||||
pub const MONOTONIC_RAW = 4;
|
||||
pub const REALTIME_COARSE = 5;
|
||||
pub const MONOTONIC_COARSE = 6;
|
||||
pub const BOOTTIME = 7;
|
||||
pub const REALTIME_ALARM = 8;
|
||||
pub const BOOTTIME_ALARM = 9;
|
||||
pub const SGI_CYCLE = 10;
|
||||
pub const TAI = 11;
|
||||
};
|
||||
pub const PF = linux.PF;
|
||||
pub const AF = linux.AF;
|
||||
pub const CLOCK = linux.CLOCK;
|
||||
|
||||
pub const CPU_SETSIZE = 128;
|
||||
pub const cpu_set_t = [CPU_SETSIZE / @sizeOf(usize)]usize;
|
||||
@@ -368,41 +257,7 @@ pub const IOV_MAX = 1024;
|
||||
|
||||
pub const IPPORT_RESERVED = 1024;
|
||||
|
||||
pub const IPPROTO = struct {
|
||||
pub const IP = 0;
|
||||
pub const HOPOPTS = 0;
|
||||
pub const ICMP = 1;
|
||||
pub const IGMP = 2;
|
||||
pub const IPIP = 4;
|
||||
pub const TCP = 6;
|
||||
pub const EGP = 8;
|
||||
pub const PUP = 12;
|
||||
pub const UDP = 17;
|
||||
pub const IDP = 22;
|
||||
pub const TP = 29;
|
||||
pub const DCCP = 33;
|
||||
pub const IPV6 = 41;
|
||||
pub const ROUTING = 43;
|
||||
pub const FRAGMENT = 44;
|
||||
pub const RSVP = 46;
|
||||
pub const GRE = 47;
|
||||
pub const ESP = 50;
|
||||
pub const AH = 51;
|
||||
pub const ICMPV6 = 58;
|
||||
pub const NONE = 59;
|
||||
pub const DSTOPTS = 60;
|
||||
pub const MTP = 92;
|
||||
pub const BEETPH = 94;
|
||||
pub const ENCAP = 98;
|
||||
pub const PIM = 103;
|
||||
pub const COMP = 108;
|
||||
pub const SCTP = 132;
|
||||
pub const MH = 135;
|
||||
pub const UDPLITE = 136;
|
||||
pub const MPLS = 137;
|
||||
pub const RAW = 255;
|
||||
pub const MAX = 256;
|
||||
};
|
||||
pub const IPPROTO = linux.IPPROTO;
|
||||
|
||||
pub const LOCK = struct {
|
||||
pub const SH = 1;
|
||||
@@ -494,10 +349,7 @@ pub const RLIM = struct {
|
||||
pub const SAVED_CUR = INFINITY;
|
||||
};
|
||||
|
||||
pub const rlimit = extern struct {
|
||||
cur: rlim_t,
|
||||
max: rlim_t,
|
||||
};
|
||||
pub const rlimit = c.rlimit;
|
||||
|
||||
pub const rlimit_resource = enum(c_int) {
|
||||
CPU,
|
||||
@@ -544,8 +396,8 @@ pub const rusage = extern struct {
|
||||
};
|
||||
|
||||
pub const timeval = extern struct {
|
||||
tv_sec: i64,
|
||||
tv_usec: i32,
|
||||
sec: i64,
|
||||
usec: i32,
|
||||
};
|
||||
|
||||
pub const REG = struct {
|
||||
@@ -929,112 +781,13 @@ pub const TCP = struct {
|
||||
pub const REPAIR_OFF_NO_WP = -1;
|
||||
};
|
||||
|
||||
pub const TCSA = enum(c_uint) {
|
||||
NOW,
|
||||
DRAIN,
|
||||
FLUSH,
|
||||
_,
|
||||
};
|
||||
pub const TCSA = std.posix.TCSA;
|
||||
pub const addrinfo = c.addrinfo;
|
||||
|
||||
pub const addrinfo = extern struct {
|
||||
flags: i32,
|
||||
family: i32,
|
||||
socktype: i32,
|
||||
protocol: i32,
|
||||
addrlen: socklen_t,
|
||||
addr: ?*sockaddr,
|
||||
canonname: ?[*:0]u8,
|
||||
next: ?*addrinfo,
|
||||
};
|
||||
|
||||
pub const in_port_t = u16;
|
||||
pub const sa_family_t = u16;
|
||||
pub const socklen_t = u32;
|
||||
|
||||
pub const sockaddr = extern struct {
|
||||
family: sa_family_t,
|
||||
data: [14]u8,
|
||||
|
||||
pub const SS_MAXSIZE = 128;
|
||||
pub const storage = extern struct {
|
||||
family: sa_family_t align(8),
|
||||
padding: [SS_MAXSIZE - @sizeOf(sa_family_t)]u8 = undefined,
|
||||
|
||||
comptime {
|
||||
std.debug.assert(@sizeOf(storage) == SS_MAXSIZE);
|
||||
std.debug.assert(@alignOf(storage) == 8);
|
||||
}
|
||||
};
|
||||
|
||||
/// IPv4 socket address
|
||||
pub const in = extern struct {
|
||||
family: sa_family_t = AF.INET,
|
||||
port: in_port_t,
|
||||
addr: u32,
|
||||
zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
|
||||
};
|
||||
|
||||
/// IPv6 socket address
|
||||
pub const in6 = extern struct {
|
||||
family: sa_family_t = AF.INET6,
|
||||
port: in_port_t,
|
||||
flowinfo: u32,
|
||||
addr: [16]u8,
|
||||
scope_id: u32,
|
||||
};
|
||||
|
||||
/// UNIX domain socket address
|
||||
pub const un = extern struct {
|
||||
family: sa_family_t = AF.UNIX,
|
||||
path: [108]u8,
|
||||
};
|
||||
|
||||
/// Packet socket address
|
||||
pub const ll = extern struct {
|
||||
family: sa_family_t = AF.PACKET,
|
||||
protocol: u16,
|
||||
ifindex: i32,
|
||||
hatype: u16,
|
||||
pkttype: u8,
|
||||
halen: u8,
|
||||
addr: [8]u8,
|
||||
};
|
||||
|
||||
/// Netlink socket address
|
||||
pub const nl = extern struct {
|
||||
family: sa_family_t = AF.NETLINK,
|
||||
__pad1: c_ushort = 0,
|
||||
|
||||
/// port ID
|
||||
pid: u32,
|
||||
|
||||
/// multicast groups mask
|
||||
groups: u32,
|
||||
};
|
||||
|
||||
pub const xdp = extern struct {
|
||||
family: u16 = AF.XDP,
|
||||
flags: u16,
|
||||
ifindex: u32,
|
||||
queue_id: u32,
|
||||
shared_umem_fd: u32,
|
||||
};
|
||||
|
||||
/// Address structure for vSockets
|
||||
pub const vm = extern struct {
|
||||
family: sa_family_t = AF.VSOCK,
|
||||
reserved1: u16 = 0,
|
||||
port: u32,
|
||||
cid: u32,
|
||||
flags: u8,
|
||||
|
||||
/// The total size of this structure should be exactly the same as that of struct sockaddr.
|
||||
zero: [3]u8 = [_]u8{0} ** 3,
|
||||
comptime {
|
||||
std.debug.assert(@sizeOf(vm) == @sizeOf(sockaddr));
|
||||
}
|
||||
};
|
||||
};
|
||||
pub const in_port_t = c.in_port_t;
|
||||
pub const sa_family_t = c.sa_family_t;
|
||||
pub const socklen_t = c.socklen_t;
|
||||
pub const sockaddr = c.sockaddr;
|
||||
|
||||
pub const blksize_t = i32;
|
||||
pub const nlink_t = u32;
|
||||
@@ -1046,16 +799,16 @@ pub const dev_t = u32;
|
||||
pub const blkcnt_t = i32;
|
||||
|
||||
pub const pid_t = i32;
|
||||
pub const fd_t = i32;
|
||||
pub const fd_t = c.fd_t;
|
||||
pub const uid_t = u32;
|
||||
pub const gid_t = u32;
|
||||
pub const clock_t = i32;
|
||||
|
||||
pub const dl_phdr_info = extern struct {
|
||||
dlpi_addr: usize,
|
||||
dlpi_name: ?[*:0]const u8,
|
||||
dlpi_phdr: [*]std.elf.Phdr,
|
||||
dlpi_phnum: u16,
|
||||
addr: usize,
|
||||
name: ?[*:0]const u8,
|
||||
phdr: [*]std.elf.Phdr,
|
||||
phnum: u16,
|
||||
};
|
||||
|
||||
pub const mcontext_t = extern struct {
|
||||
@@ -1065,25 +818,8 @@ pub const mcontext_t = extern struct {
|
||||
cr2: usize,
|
||||
};
|
||||
|
||||
pub const msghdr = extern struct {
|
||||
name: ?*sockaddr,
|
||||
namelen: socklen_t,
|
||||
iov: [*]iovec,
|
||||
iovlen: i32,
|
||||
control: ?*anyopaque,
|
||||
controllen: socklen_t,
|
||||
flags: i32,
|
||||
};
|
||||
|
||||
pub const msghdr_const = extern struct {
|
||||
name: ?*const sockaddr,
|
||||
namelen: socklen_t,
|
||||
iov: [*]const iovec_const,
|
||||
iovlen: i32,
|
||||
control: ?*const anyopaque,
|
||||
controllen: socklen_t,
|
||||
flags: i32,
|
||||
};
|
||||
pub const msghdr = std.c.msghdr;
|
||||
pub const msghdr_const = std.c.msghdr;
|
||||
|
||||
pub const nfds_t = usize;
|
||||
pub const pollfd = extern struct {
|
||||
@@ -1099,13 +835,13 @@ pub const stack_t = extern struct {
|
||||
};
|
||||
|
||||
pub const timespec = extern struct {
|
||||
tv_sec: time_t,
|
||||
tv_nsec: isize,
|
||||
sec: time_t,
|
||||
nsec: isize,
|
||||
};
|
||||
|
||||
pub const timezone = extern struct {
|
||||
tz_minuteswest: i32,
|
||||
tz_dsttime: i32,
|
||||
minuteswest: i32,
|
||||
dsttime: i32,
|
||||
};
|
||||
|
||||
pub const ucontext_t = extern struct {
|
||||
|
||||
+69
-71
@@ -20,6 +20,7 @@ const is_ppc64 = native_arch.isPPC64();
|
||||
const is_sparc = native_arch.isSPARC();
|
||||
const iovec = std.posix.iovec;
|
||||
const iovec_const = std.posix.iovec_const;
|
||||
const winsize = std.posix.winsize;
|
||||
const ACCMODE = std.posix.ACCMODE;
|
||||
|
||||
test {
|
||||
@@ -44,7 +45,10 @@ const arch_bits = switch (native_arch) {
|
||||
.mips64, .mips64el => @import("linux/mips64.zig"),
|
||||
.powerpc, .powerpcle => @import("linux/powerpc.zig"),
|
||||
.powerpc64, .powerpc64le => @import("linux/powerpc64.zig"),
|
||||
else => struct {},
|
||||
else => struct {
|
||||
pub const ucontext_t = void;
|
||||
pub const getcontext = {};
|
||||
},
|
||||
};
|
||||
pub const syscall0 = syscall_bits.syscall0;
|
||||
pub const syscall1 = syscall_bits.syscall1;
|
||||
@@ -586,7 +590,7 @@ pub fn futex2_waitv(
|
||||
/// Optional absolute timeout.
|
||||
timeout: ?*const timespec,
|
||||
/// Clock to be used for the timeout, realtime or monotonic.
|
||||
clockid: i32,
|
||||
clockid: clockid_t,
|
||||
) usize {
|
||||
return syscall5(
|
||||
.futex_waitv,
|
||||
@@ -612,7 +616,7 @@ pub fn futex2_wait(
|
||||
/// Optional absolute timeout.
|
||||
timeout: *const timespec,
|
||||
/// Clock to be used for the timeout, realtime or monotonic.
|
||||
clockid: i32,
|
||||
clockid: clockid_t,
|
||||
) usize {
|
||||
return syscall6(
|
||||
.futex_wait,
|
||||
@@ -843,8 +847,8 @@ pub fn poll(fds: [*]pollfd, n: nfds_t, timeout: i32) usize {
|
||||
n,
|
||||
@intFromPtr(if (timeout >= 0)
|
||||
×pec{
|
||||
.tv_sec = @divTrunc(timeout, 1000),
|
||||
.tv_nsec = @rem(timeout, 1000) * 1000000,
|
||||
.sec = @divTrunc(timeout, 1000),
|
||||
.nsec = @rem(timeout, 1000) * 1000000,
|
||||
}
|
||||
else
|
||||
null),
|
||||
@@ -1362,10 +1366,10 @@ pub fn flock(fd: fd_t, operation: i32) usize {
|
||||
}
|
||||
|
||||
// We must follow the C calling convention when we call into the VDSO
|
||||
const VdsoClockGettime = *align(1) const fn (i32, *timespec) callconv(.C) usize;
|
||||
const VdsoClockGettime = *align(1) const fn (clockid_t, *timespec) callconv(.C) usize;
|
||||
var vdso_clock_gettime: ?VdsoClockGettime = &init_vdso_clock_gettime;
|
||||
|
||||
pub fn clock_gettime(clk_id: i32, tp: *timespec) usize {
|
||||
pub fn clock_gettime(clk_id: clockid_t, tp: *timespec) usize {
|
||||
if (@hasDecl(VDSO, "CGT_SYM")) {
|
||||
const ptr = @atomicLoad(?VdsoClockGettime, &vdso_clock_gettime, .unordered);
|
||||
if (ptr) |f| {
|
||||
@@ -1376,10 +1380,10 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) usize {
|
||||
}
|
||||
}
|
||||
}
|
||||
return syscall2(.clock_gettime, @as(usize, @bitCast(@as(isize, clk_id))), @intFromPtr(tp));
|
||||
return syscall2(.clock_gettime, @intFromEnum(clk_id), @intFromPtr(tp));
|
||||
}
|
||||
|
||||
fn init_vdso_clock_gettime(clk: i32, ts: *timespec) callconv(.C) usize {
|
||||
fn init_vdso_clock_gettime(clk: clockid_t, ts: *timespec) callconv(.C) usize {
|
||||
const ptr: ?VdsoClockGettime = @ptrFromInt(vdso.lookup(VDSO.CGT_VER, VDSO.CGT_SYM));
|
||||
// Note that we may not have a VDSO at all, update the stub address anyway
|
||||
// so that clock_gettime will fall back on the good old (and slow) syscall
|
||||
@@ -1962,8 +1966,12 @@ pub fn eventfd(count: u32, flags: u32) usize {
|
||||
return syscall2(.eventfd2, count, flags);
|
||||
}
|
||||
|
||||
pub fn timerfd_create(clockid: i32, flags: TFD) usize {
|
||||
return syscall2(.timerfd_create, @bitCast(@as(isize, clockid)), @as(u32, @bitCast(flags)));
|
||||
pub fn timerfd_create(clockid: clockid_t, flags: TFD) usize {
|
||||
return syscall2(
|
||||
.timerfd_create,
|
||||
@intFromEnum(clockid),
|
||||
@as(u32, @bitCast(flags)),
|
||||
);
|
||||
}
|
||||
|
||||
pub const itimerspec = extern struct {
|
||||
@@ -4029,19 +4037,22 @@ pub const EPOLL = struct {
|
||||
pub const ET = (@as(u32, 1) << 31);
|
||||
};
|
||||
|
||||
pub const CLOCK = struct {
|
||||
pub const REALTIME = 0;
|
||||
pub const MONOTONIC = 1;
|
||||
pub const PROCESS_CPUTIME_ID = 2;
|
||||
pub const THREAD_CPUTIME_ID = 3;
|
||||
pub const MONOTONIC_RAW = 4;
|
||||
pub const REALTIME_COARSE = 5;
|
||||
pub const MONOTONIC_COARSE = 6;
|
||||
pub const BOOTTIME = 7;
|
||||
pub const REALTIME_ALARM = 8;
|
||||
pub const BOOTTIME_ALARM = 9;
|
||||
pub const SGI_CYCLE = 10;
|
||||
pub const TAI = 11;
|
||||
pub const CLOCK = clockid_t;
|
||||
|
||||
pub const clockid_t = enum(u32) {
|
||||
REALTIME = 0,
|
||||
MONOTONIC = 1,
|
||||
PROCESS_CPUTIME_ID = 2,
|
||||
THREAD_CPUTIME_ID = 3,
|
||||
MONOTONIC_RAW = 4,
|
||||
REALTIME_COARSE = 5,
|
||||
MONOTONIC_COARSE = 6,
|
||||
BOOTTIME = 7,
|
||||
REALTIME_ALARM = 8,
|
||||
BOOTTIME_ALARM = 9,
|
||||
SGI_CYCLE = 10,
|
||||
TAI = 11,
|
||||
_,
|
||||
};
|
||||
|
||||
pub const CSIGNAL = 0x000000ff;
|
||||
@@ -4417,13 +4428,6 @@ pub const TFD = switch (native_arch) {
|
||||
},
|
||||
};
|
||||
|
||||
pub const winsize = extern struct {
|
||||
ws_row: u16,
|
||||
ws_col: u16,
|
||||
ws_xpixel: u16,
|
||||
ws_ypixel: u16,
|
||||
};
|
||||
|
||||
/// NSIG is the total number of signals defined.
|
||||
/// As signal numbers are sequential, NSIG is one greater than the largest defined signal number.
|
||||
pub const NSIG = if (is_mips) 128 else 65;
|
||||
@@ -4597,13 +4601,13 @@ pub const sockaddr = extern struct {
|
||||
};
|
||||
|
||||
pub const mmsghdr = extern struct {
|
||||
msg_hdr: msghdr,
|
||||
msg_len: u32,
|
||||
hdr: msghdr,
|
||||
len: u32,
|
||||
};
|
||||
|
||||
pub const mmsghdr_const = extern struct {
|
||||
msg_hdr: msghdr_const,
|
||||
msg_len: u32,
|
||||
hdr: msghdr_const,
|
||||
len: u32,
|
||||
};
|
||||
|
||||
pub const epoll_data = extern union {
|
||||
@@ -4748,10 +4752,10 @@ pub const dirent64 = extern struct {
|
||||
};
|
||||
|
||||
pub const dl_phdr_info = extern struct {
|
||||
dlpi_addr: usize,
|
||||
dlpi_name: ?[*:0]const u8,
|
||||
dlpi_phdr: [*]std.elf.Phdr,
|
||||
dlpi_phnum: u16,
|
||||
addr: usize,
|
||||
name: ?[*:0]const u8,
|
||||
phdr: [*]std.elf.Phdr,
|
||||
phnum: u16,
|
||||
};
|
||||
|
||||
pub const CPU_SETSIZE = 128;
|
||||
@@ -4777,9 +4781,11 @@ pub const SIGSTKSZ = switch (native_arch) {
|
||||
else => @compileError("SIGSTKSZ not defined for this architecture"),
|
||||
};
|
||||
|
||||
pub const SS_ONSTACK = 1;
|
||||
pub const SS_DISABLE = 2;
|
||||
pub const SS_AUTODISARM = 1 << 31;
|
||||
pub const SS = struct {
|
||||
pub const ONSTACK = 1;
|
||||
pub const DISABLE = 2;
|
||||
pub const AUTODISARM = 1 << 31;
|
||||
};
|
||||
|
||||
pub const stack_t = if (is_mips)
|
||||
// IRIX compatible stack_t
|
||||
@@ -5493,8 +5499,8 @@ pub const STATX_ATTR_ENCRYPTED = 0x0800;
|
||||
pub const STATX_ATTR_AUTOMOUNT = 0x1000;
|
||||
|
||||
pub const statx_timestamp = extern struct {
|
||||
tv_sec: i64,
|
||||
tv_nsec: u32,
|
||||
sec: i64,
|
||||
nsec: u32,
|
||||
__pad1: u32,
|
||||
};
|
||||
|
||||
@@ -5562,7 +5568,7 @@ pub const Statx = extern struct {
|
||||
};
|
||||
|
||||
pub const addrinfo = extern struct {
|
||||
flags: i32,
|
||||
flags: AI,
|
||||
family: i32,
|
||||
socktype: i32,
|
||||
protocol: i32,
|
||||
@@ -5572,6 +5578,18 @@ pub const addrinfo = extern struct {
|
||||
next: ?*addrinfo,
|
||||
};
|
||||
|
||||
pub const AI = packed struct(u32) {
|
||||
PASSIVE: bool = false,
|
||||
CANONNAME: bool = false,
|
||||
NUMERICHOST: bool = false,
|
||||
V4MAPPED: bool = false,
|
||||
ALL: bool = false,
|
||||
ADDRCONFIG: bool = false,
|
||||
_6: u4 = 0,
|
||||
NUMERICSERV: bool = false,
|
||||
_: u21 = 0,
|
||||
};
|
||||
|
||||
pub const IPPORT_RESERVED = 1024;
|
||||
|
||||
pub const IPPROTO = struct {
|
||||
@@ -6028,12 +6046,7 @@ pub const V = switch (native_arch) {
|
||||
},
|
||||
};
|
||||
|
||||
pub const TCSA = enum(c_uint) {
|
||||
NOW,
|
||||
DRAIN,
|
||||
FLUSH,
|
||||
_,
|
||||
};
|
||||
pub const TCSA = std.posix.TCSA;
|
||||
|
||||
pub const termios = switch (native_arch) {
|
||||
.powerpc, .powerpcle, .powerpc64, .powerpc64le => extern struct {
|
||||
@@ -6097,55 +6110,40 @@ else
|
||||
enum(c_int) {
|
||||
/// Per-process CPU limit, in seconds.
|
||||
CPU,
|
||||
|
||||
/// Largest file that can be created, in bytes.
|
||||
FSIZE,
|
||||
|
||||
/// Maximum size of data segment, in bytes.
|
||||
DATA,
|
||||
|
||||
/// Maximum size of stack segment, in bytes.
|
||||
STACK,
|
||||
|
||||
/// Largest core file that can be created, in bytes.
|
||||
CORE,
|
||||
|
||||
/// Largest resident set size, in bytes.
|
||||
/// This affects swapping; processes that are exceeding their
|
||||
/// resident set size will be more likely to have physical memory
|
||||
/// taken from them.
|
||||
RSS,
|
||||
|
||||
/// Number of processes.
|
||||
NPROC,
|
||||
|
||||
/// Number of open files.
|
||||
NOFILE,
|
||||
|
||||
/// Locked-in-memory address space.
|
||||
MEMLOCK,
|
||||
|
||||
/// Address space limit.
|
||||
AS,
|
||||
|
||||
/// Maximum number of file locks.
|
||||
LOCKS,
|
||||
|
||||
/// Maximum number of pending signals.
|
||||
SIGPENDING,
|
||||
|
||||
/// Maximum bytes in POSIX message queues.
|
||||
MSGQUEUE,
|
||||
|
||||
/// Maximum nice priority allowed to raise to.
|
||||
/// Nice levels 19 .. -20 correspond to 0 .. 39
|
||||
/// values of this resource limit.
|
||||
NICE,
|
||||
|
||||
/// Maximum realtime priority allowed for non-privileged
|
||||
/// processes.
|
||||
RTPRIO,
|
||||
|
||||
/// Maximum CPU time in µs that a process scheduled under a real-time
|
||||
/// scheduling policy may consume without making a blocking system
|
||||
/// call before being forcibly descheduled.
|
||||
@@ -6223,13 +6221,13 @@ pub const POSIX_FADV = switch (native_arch) {
|
||||
|
||||
/// The timespec struct used by the kernel.
|
||||
pub const kernel_timespec = if (@sizeOf(usize) >= 8) timespec else extern struct {
|
||||
tv_sec: i64,
|
||||
tv_nsec: i64,
|
||||
sec: i64,
|
||||
nsec: i64,
|
||||
};
|
||||
|
||||
pub const timespec = extern struct {
|
||||
tv_sec: isize,
|
||||
tv_nsec: isize,
|
||||
sec: isize,
|
||||
nsec: isize,
|
||||
};
|
||||
|
||||
pub const XDP = struct {
|
||||
@@ -7102,7 +7100,7 @@ pub const perf_event_attr = extern struct {
|
||||
/// Defines size of the user stack to dump on samples.
|
||||
sample_stack_user: u32 = 0,
|
||||
|
||||
clockid: i32 = 0,
|
||||
clockid: clockid_t = 0,
|
||||
/// Defines set of regs to dump for each sample
|
||||
/// state captured on:
|
||||
/// - precise = 0: PMU interrupt
|
||||
|
||||
@@ -2261,7 +2261,7 @@ test "timeout (after a relative time)" {
|
||||
|
||||
const ms = 10;
|
||||
const margin = 5;
|
||||
const ts: linux.kernel_timespec = .{ .tv_sec = 0, .tv_nsec = ms * 1000000 };
|
||||
const ts: linux.kernel_timespec = .{ .sec = 0, .nsec = ms * 1000000 };
|
||||
|
||||
const started = std.time.milliTimestamp();
|
||||
const sqe = try ring.timeout(0x55555555, &ts, 0, 0);
|
||||
@@ -2290,7 +2290,7 @@ test "timeout (after a number of completions)" {
|
||||
};
|
||||
defer ring.deinit();
|
||||
|
||||
const ts: linux.kernel_timespec = .{ .tv_sec = 3, .tv_nsec = 0 };
|
||||
const ts: linux.kernel_timespec = .{ .sec = 3, .nsec = 0 };
|
||||
const count_completions: u64 = 1;
|
||||
const sqe_timeout = try ring.timeout(0x66666666, &ts, count_completions, 0);
|
||||
try testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe_timeout.opcode);
|
||||
@@ -2323,7 +2323,7 @@ test "timeout_remove" {
|
||||
};
|
||||
defer ring.deinit();
|
||||
|
||||
const ts: linux.kernel_timespec = .{ .tv_sec = 3, .tv_nsec = 0 };
|
||||
const ts: linux.kernel_timespec = .{ .sec = 3, .nsec = 0 };
|
||||
const sqe_timeout = try ring.timeout(0x88888888, &ts, 0, 0);
|
||||
try testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe_timeout.opcode);
|
||||
try testing.expectEqual(@as(u64, 0x88888888), sqe_timeout.user_data);
|
||||
@@ -2391,7 +2391,7 @@ test "accept/connect/recv/link_timeout" {
|
||||
const sqe_recv = try ring.recv(0xffffffff, socket_test_harness.server, .{ .buffer = buffer_recv[0..] }, 0);
|
||||
sqe_recv.flags |= linux.IOSQE_IO_LINK;
|
||||
|
||||
const ts = linux.kernel_timespec{ .tv_sec = 0, .tv_nsec = 1000000 };
|
||||
const ts = linux.kernel_timespec{ .sec = 0, .nsec = 1000000 };
|
||||
_ = try ring.link_timeout(0x22222222, &ts, 0);
|
||||
|
||||
const nr_wait = try ring.submit();
|
||||
@@ -4248,7 +4248,7 @@ test "copy_cqes with wrapping sq.cqes buffer" {
|
||||
{
|
||||
for (0..2) |_| {
|
||||
const sqe = try ring.get_sqe();
|
||||
sqe.prep_timeout(&.{ .tv_sec = 0, .tv_nsec = 10000 }, 0, 0);
|
||||
sqe.prep_timeout(&.{ .sec = 0, .nsec = 10000 }, 0, 0);
|
||||
try testing.expect(try ring.submit() == 1);
|
||||
}
|
||||
var cqe_count: u32 = 0;
|
||||
@@ -4265,7 +4265,7 @@ test "copy_cqes with wrapping sq.cqes buffer" {
|
||||
for (1..1024) |i| {
|
||||
for (0..4) |_| {
|
||||
const sqe = try ring.get_sqe();
|
||||
sqe.prep_timeout(&.{ .tv_sec = 0, .tv_nsec = 10000 }, 0, 0);
|
||||
sqe.prep_timeout(&.{ .sec = 0, .nsec = 10000 }, 0, 0);
|
||||
try testing.expect(try ring.submit() == 1);
|
||||
}
|
||||
var cqe_count: u32 = 0;
|
||||
|
||||
@@ -277,13 +277,13 @@ pub const Stat = extern struct {
|
||||
};
|
||||
|
||||
pub const timeval = extern struct {
|
||||
tv_sec: i32,
|
||||
tv_usec: i32,
|
||||
sec: i32,
|
||||
usec: i32,
|
||||
};
|
||||
|
||||
pub const timezone = extern struct {
|
||||
tz_minuteswest: i32,
|
||||
tz_dsttime: i32,
|
||||
minuteswest: i32,
|
||||
dsttime: i32,
|
||||
};
|
||||
|
||||
pub const mcontext_t = extern struct {
|
||||
@@ -319,4 +319,7 @@ pub const ucontext_t = extern struct {
|
||||
regspace: [64]u64,
|
||||
};
|
||||
|
||||
/// TODO
|
||||
pub const getcontext = {};
|
||||
|
||||
pub const Elf_Symndx = u32;
|
||||
|
||||
@@ -236,13 +236,13 @@ pub const Stat = extern struct {
|
||||
};
|
||||
|
||||
pub const timeval = extern struct {
|
||||
tv_sec: isize,
|
||||
tv_usec: isize,
|
||||
sec: isize,
|
||||
usec: isize,
|
||||
};
|
||||
|
||||
pub const timezone = extern struct {
|
||||
tz_minuteswest: i32,
|
||||
tz_dsttime: i32,
|
||||
minuteswest: i32,
|
||||
dsttime: i32,
|
||||
};
|
||||
|
||||
pub const mcontext_t = extern struct {
|
||||
@@ -264,4 +264,7 @@ pub const ucontext_t = extern struct {
|
||||
mcontext: mcontext_t,
|
||||
};
|
||||
|
||||
/// TODO
|
||||
pub const getcontext = {};
|
||||
|
||||
pub const Elf_Symndx = u32;
|
||||
|
||||
@@ -326,13 +326,13 @@ pub const Stat = extern struct {
|
||||
};
|
||||
|
||||
pub const timeval = extern struct {
|
||||
tv_sec: isize,
|
||||
tv_usec: isize,
|
||||
sec: isize,
|
||||
usec: isize,
|
||||
};
|
||||
|
||||
pub const timezone = extern struct {
|
||||
tz_minuteswest: i32,
|
||||
tz_dsttime: i32,
|
||||
minuteswest: i32,
|
||||
dsttime: i32,
|
||||
};
|
||||
|
||||
pub const Elf_Symndx = u32;
|
||||
@@ -396,3 +396,9 @@ pub const rlimit_resource = enum(c_int) {
|
||||
|
||||
_,
|
||||
};
|
||||
|
||||
/// TODO
|
||||
pub const ucontext_t = void;
|
||||
|
||||
/// TODO
|
||||
pub const getcontext = {};
|
||||
|
||||
@@ -311,13 +311,13 @@ pub const Stat = extern struct {
|
||||
};
|
||||
|
||||
pub const timeval = extern struct {
|
||||
tv_sec: isize,
|
||||
tv_usec: isize,
|
||||
sec: isize,
|
||||
usec: isize,
|
||||
};
|
||||
|
||||
pub const timezone = extern struct {
|
||||
tz_minuteswest: i32,
|
||||
tz_dsttime: i32,
|
||||
minuteswest: i32,
|
||||
dsttime: i32,
|
||||
};
|
||||
|
||||
pub const Elf_Symndx = u32;
|
||||
@@ -381,3 +381,9 @@ pub const rlimit_resource = enum(c_int) {
|
||||
|
||||
_,
|
||||
};
|
||||
|
||||
/// TODO
|
||||
pub const ucontext_t = void;
|
||||
|
||||
/// TODO
|
||||
pub const getcontext = {};
|
||||
|
||||
@@ -249,13 +249,13 @@ pub const Stat = extern struct {
|
||||
};
|
||||
|
||||
pub const timeval = extern struct {
|
||||
tv_sec: time_t,
|
||||
tv_usec: isize,
|
||||
sec: time_t,
|
||||
usec: isize,
|
||||
};
|
||||
|
||||
pub const timezone = extern struct {
|
||||
tz_minuteswest: i32,
|
||||
tz_dsttime: i32,
|
||||
minuteswest: i32,
|
||||
dsttime: i32,
|
||||
};
|
||||
|
||||
pub const greg_t = u32;
|
||||
@@ -290,3 +290,6 @@ pub const ucontext_t = extern struct {
|
||||
pub const Elf_Symndx = u32;
|
||||
|
||||
pub const MMAP2_UNIT = 4096;
|
||||
|
||||
/// TODO
|
||||
pub const getcontext = {};
|
||||
|
||||
@@ -249,13 +249,13 @@ pub const Stat = extern struct {
|
||||
};
|
||||
|
||||
pub const timeval = extern struct {
|
||||
tv_sec: isize,
|
||||
tv_usec: isize,
|
||||
sec: isize,
|
||||
usec: isize,
|
||||
};
|
||||
|
||||
pub const timezone = extern struct {
|
||||
tz_minuteswest: i32,
|
||||
tz_dsttime: i32,
|
||||
minuteswest: i32,
|
||||
dsttime: i32,
|
||||
};
|
||||
|
||||
pub const greg_t = u64;
|
||||
@@ -298,3 +298,6 @@ pub const ucontext_t = extern struct {
|
||||
};
|
||||
|
||||
pub const Elf_Symndx = u32;
|
||||
|
||||
/// TODO
|
||||
pub const getcontext = {};
|
||||
|
||||
@@ -151,8 +151,8 @@ pub const dev_t = usize;
|
||||
pub const blkcnt_t = isize;
|
||||
|
||||
pub const timeval = extern struct {
|
||||
tv_sec: time_t,
|
||||
tv_usec: i64,
|
||||
sec: time_t,
|
||||
usec: i64,
|
||||
};
|
||||
|
||||
pub const Flock = extern struct {
|
||||
@@ -223,3 +223,9 @@ pub const Stat = extern struct {
|
||||
pub const Elf_Symndx = u32;
|
||||
|
||||
pub const VDSO = struct {};
|
||||
|
||||
/// TODO
|
||||
pub const ucontext_t = void;
|
||||
|
||||
/// TODO
|
||||
pub const getcontext = {};
|
||||
|
||||
@@ -301,13 +301,13 @@ pub const Stat = extern struct {
|
||||
};
|
||||
|
||||
pub const timeval = extern struct {
|
||||
tv_sec: isize,
|
||||
tv_usec: i32,
|
||||
sec: isize,
|
||||
usec: i32,
|
||||
};
|
||||
|
||||
pub const timezone = extern struct {
|
||||
tz_minuteswest: i32,
|
||||
tz_dsttime: i32,
|
||||
minuteswest: i32,
|
||||
dsttime: i32,
|
||||
};
|
||||
|
||||
// TODO I'm not sure if the code below is correct, need someone with more
|
||||
@@ -412,6 +412,9 @@ pub const ucontext_t = extern struct {
|
||||
sigset: sigset_t,
|
||||
};
|
||||
|
||||
/// TODO
|
||||
pub const getcontext = {};
|
||||
|
||||
pub const rlimit_resource = enum(c_int) {
|
||||
/// Per-process CPU limit, in seconds.
|
||||
CPU,
|
||||
|
||||
@@ -41,8 +41,8 @@ test "timer" {
|
||||
try expect(linux.E.init(timer_fd) == .SUCCESS);
|
||||
|
||||
const time_interval = linux.timespec{
|
||||
.tv_sec = 0,
|
||||
.tv_nsec = 2000000,
|
||||
.sec = 0,
|
||||
.nsec = 2000000,
|
||||
};
|
||||
|
||||
const new_time = linux.itimerspec{
|
||||
|
||||
@@ -267,13 +267,13 @@ pub const Stat = extern struct {
|
||||
};
|
||||
|
||||
pub const timeval = extern struct {
|
||||
tv_sec: i32,
|
||||
tv_usec: i32,
|
||||
sec: i32,
|
||||
usec: i32,
|
||||
};
|
||||
|
||||
pub const timezone = extern struct {
|
||||
tz_minuteswest: i32,
|
||||
tz_dsttime: i32,
|
||||
minuteswest: i32,
|
||||
dsttime: i32,
|
||||
};
|
||||
|
||||
pub const mcontext_t = extern struct {
|
||||
|
||||
@@ -272,13 +272,13 @@ pub const Stat = extern struct {
|
||||
};
|
||||
|
||||
pub const timeval = extern struct {
|
||||
tv_sec: isize,
|
||||
tv_usec: isize,
|
||||
sec: isize,
|
||||
usec: isize,
|
||||
};
|
||||
|
||||
pub const timezone = extern struct {
|
||||
tz_minuteswest: i32,
|
||||
tz_dsttime: i32,
|
||||
minuteswest: i32,
|
||||
dsttime: i32,
|
||||
};
|
||||
|
||||
pub const Elf_Symndx = u32;
|
||||
|
||||
@@ -676,23 +676,27 @@ pub const MSG = struct {
|
||||
pub const MAXIOVLEN = 16;
|
||||
};
|
||||
|
||||
pub const AI = struct {
|
||||
pub const PASSIVE = 1;
|
||||
pub const CANONNAME = 2;
|
||||
pub const NUMERICHOST = 4;
|
||||
pub const NUMERICSERV = 8;
|
||||
pub const DNS_ONLY = 16;
|
||||
pub const ALL = 256;
|
||||
pub const ADDRCONFIG = 1024;
|
||||
pub const V4MAPPED = 2048;
|
||||
pub const NON_AUTHORITATIVE = 16384;
|
||||
pub const SECURE = 32768;
|
||||
pub const RETURN_PREFERRED_NAMES = 65536;
|
||||
pub const FQDN = 131072;
|
||||
pub const FILESERVER = 262144;
|
||||
pub const DISABLE_IDN_ENCODING = 524288;
|
||||
pub const EXTENDED = 2147483648;
|
||||
pub const RESOLUTION_HANDLE = 1073741824;
|
||||
pub const AI = packed struct(u32) {
|
||||
PASSIVE: bool = false,
|
||||
CANONNAME: bool = false,
|
||||
NUMERICHOST: bool = false,
|
||||
NUMERICSERV: bool = false,
|
||||
DNS_ONLY: bool = false,
|
||||
_5: u3 = 0,
|
||||
ALL: bool = false,
|
||||
_9: u1 = 0,
|
||||
ADDRCONFIG: bool = false,
|
||||
V4MAPPED: bool = false,
|
||||
_12: u2 = 0,
|
||||
NON_AUTHORITATIVE: bool = false,
|
||||
SECURE: bool = false,
|
||||
RETURN_PREFERRED_NAMES: bool = false,
|
||||
FQDN: bool = false,
|
||||
FILESERVER: bool = false,
|
||||
DISABLE_IDN_ENCODING: bool = false,
|
||||
_20: u10 = 0,
|
||||
RESOLUTION_HANDLE: bool = false,
|
||||
EXTENDED: bool = false,
|
||||
};
|
||||
|
||||
pub const FIONBIO = -2147195266;
|
||||
@@ -1068,8 +1072,8 @@ pub const sockproto = extern struct {
|
||||
};
|
||||
|
||||
pub const linger = extern struct {
|
||||
l_onoff: u16,
|
||||
l_linger: u16,
|
||||
onoff: u16,
|
||||
linger: u16,
|
||||
};
|
||||
|
||||
pub const WSANETWORKEVENTS = extern struct {
|
||||
@@ -1080,7 +1084,7 @@ pub const WSANETWORKEVENTS = extern struct {
|
||||
pub const addrinfo = addrinfoa;
|
||||
|
||||
pub const addrinfoa = extern struct {
|
||||
flags: i32,
|
||||
flags: AI,
|
||||
family: i32,
|
||||
socktype: i32,
|
||||
protocol: i32,
|
||||
@@ -1091,17 +1095,17 @@ pub const addrinfoa = extern struct {
|
||||
};
|
||||
|
||||
pub const addrinfoexA = extern struct {
|
||||
ai_flags: i32,
|
||||
ai_family: i32,
|
||||
ai_socktype: i32,
|
||||
ai_protocol: i32,
|
||||
ai_addrlen: usize,
|
||||
ai_canonname: [*:0]u8,
|
||||
ai_addr: *sockaddr,
|
||||
ai_blob: *anyopaque,
|
||||
ai_bloblen: usize,
|
||||
ai_provider: *GUID,
|
||||
ai_next: *addrinfoexA,
|
||||
flags: AI,
|
||||
family: i32,
|
||||
socktype: i32,
|
||||
protocol: i32,
|
||||
addrlen: usize,
|
||||
canonname: [*:0]u8,
|
||||
addr: *sockaddr,
|
||||
blob: *anyopaque,
|
||||
bloblen: usize,
|
||||
provider: *GUID,
|
||||
next: *addrinfoexA,
|
||||
};
|
||||
|
||||
pub const sockaddr = extern struct {
|
||||
@@ -1264,8 +1268,8 @@ pub const hostent = extern struct {
|
||||
};
|
||||
|
||||
pub const timeval = extern struct {
|
||||
tv_sec: LONG,
|
||||
tv_usec: LONG,
|
||||
sec: LONG,
|
||||
usec: LONG,
|
||||
};
|
||||
|
||||
// https://docs.microsoft.com/en-au/windows/win32/winsock/windows-sockets-error-codes-2
|
||||
|
||||
+72
-67
@@ -50,6 +50,7 @@ else switch (native_os) {
|
||||
|
||||
pub const AF = system.AF;
|
||||
pub const AF_SUN = system.AF_SUN;
|
||||
pub const AI = system.AI;
|
||||
pub const ARCH = system.ARCH;
|
||||
pub const AT = system.AT;
|
||||
pub const AT_SUN = system.AT_SUN;
|
||||
@@ -72,10 +73,10 @@ pub const Kevent = system.Kevent;
|
||||
pub const LOCK = system.LOCK;
|
||||
pub const MADV = system.MADV;
|
||||
pub const MAP = system.MAP;
|
||||
pub const MSF = system.MSF;
|
||||
pub const MAX_ADDR_LEN = system.MAX_ADDR_LEN;
|
||||
pub const MFD = system.MFD;
|
||||
pub const MMAP2_UNIT = system.MMAP2_UNIT;
|
||||
pub const MSF = system.MSF;
|
||||
pub const MSG = system.MSG;
|
||||
pub const NAME_MAX = system.NAME_MAX;
|
||||
pub const O = system.O;
|
||||
@@ -90,7 +91,6 @@ pub const RR = system.RR;
|
||||
pub const S = system.S;
|
||||
pub const SA = system.SA;
|
||||
pub const SC = system.SC;
|
||||
pub const _SC = system._SC;
|
||||
pub const SEEK = system.SEEK;
|
||||
pub const SHUT = system.SHUT;
|
||||
pub const SIG = system.SIG;
|
||||
@@ -105,20 +105,22 @@ pub const SYS = system.SYS;
|
||||
pub const Sigaction = system.Sigaction;
|
||||
pub const Stat = system.Stat;
|
||||
pub const T = system.T;
|
||||
pub const TCSA = system.TCSA;
|
||||
pub const TCP = system.TCP;
|
||||
pub const VDSO = system.VDSO;
|
||||
pub const W = system.W;
|
||||
pub const _SC = system._SC;
|
||||
pub const addrinfo = system.addrinfo;
|
||||
pub const blkcnt_t = system.blkcnt_t;
|
||||
pub const blksize_t = system.blksize_t;
|
||||
pub const clock_t = system.clock_t;
|
||||
pub const clockid_t = system.clockid_t;
|
||||
pub const cpu_set_t = system.cpu_set_t;
|
||||
pub const dev_t = system.dev_t;
|
||||
pub const dl_phdr_info = system.dl_phdr_info;
|
||||
pub const empty_sigset = system.empty_sigset;
|
||||
pub const filled_sigset = system.filled_sigset;
|
||||
pub const fd_t = system.fd_t;
|
||||
pub const file_obj = system.file_obj;
|
||||
pub const filled_sigset = system.filled_sigset;
|
||||
pub const gid_t = system.gid_t;
|
||||
pub const ifreq = system.ifreq;
|
||||
pub const ino_t = system.ino_t;
|
||||
@@ -131,10 +133,9 @@ pub const nlink_t = system.nlink_t;
|
||||
pub const off_t = system.off_t;
|
||||
pub const pid_t = system.pid_t;
|
||||
pub const pollfd = system.pollfd;
|
||||
pub const port_t = system.port_t;
|
||||
pub const port_event = system.port_event;
|
||||
pub const port_notify = system.port_notify;
|
||||
pub const file_obj = system.file_obj;
|
||||
pub const port_t = system.port_t;
|
||||
pub const rlim_t = system.rlim_t;
|
||||
pub const rlimit = system.rlimit;
|
||||
pub const rlimit_resource = system.rlimit_resource;
|
||||
@@ -154,7 +155,6 @@ pub const ucontext_t = system.ucontext_t;
|
||||
pub const uid_t = system.uid_t;
|
||||
pub const user_desc = system.user_desc;
|
||||
pub const utsname = system.utsname;
|
||||
pub const winsize = system.winsize;
|
||||
|
||||
pub const termios = system.termios;
|
||||
pub const CSIZE = system.CSIZE;
|
||||
@@ -188,6 +188,20 @@ pub const ACCMODE = enum(u2) {
|
||||
RDWR = 2,
|
||||
};
|
||||
|
||||
pub const TCSA = enum(c_uint) {
|
||||
NOW,
|
||||
DRAIN,
|
||||
FLUSH,
|
||||
_,
|
||||
};
|
||||
|
||||
pub const winsize = extern struct {
|
||||
row: u16,
|
||||
col: u16,
|
||||
xpixel: u16,
|
||||
ypixel: u16,
|
||||
};
|
||||
|
||||
pub const LOG = struct {
|
||||
/// system is unusable
|
||||
pub const EMERG = 0;
|
||||
@@ -226,6 +240,8 @@ pub fn errno(rc: anytype) E {
|
||||
|
||||
/// Closes the file descriptor.
|
||||
///
|
||||
/// Asserts the file descriptor is open.
|
||||
///
|
||||
/// This function is not capable of returning any indication of failure. An
|
||||
/// application which wants to ensure writes have succeeded before closing must
|
||||
/// call `fsync` before `close`.
|
||||
@@ -239,13 +255,6 @@ pub fn close(fd: fd_t) void {
|
||||
_ = std.os.wasi.fd_close(fd);
|
||||
return;
|
||||
}
|
||||
if (builtin.target.isDarwin()) {
|
||||
// This avoids the EINTR problem.
|
||||
switch (errno(std.c.@"close$NOCANCEL"(fd))) {
|
||||
.BADF => unreachable, // Always a race condition.
|
||||
else => return,
|
||||
}
|
||||
}
|
||||
switch (errno(system.close(fd))) {
|
||||
.BADF => unreachable, // Always a race condition.
|
||||
.INTR => return, // This is still a success. See https://github.com/ziglang/zig/issues/2425
|
||||
@@ -571,7 +580,15 @@ pub fn getrandom(buffer: []u8) GetRandomError!void {
|
||||
if (native_os == .windows) {
|
||||
return windows.RtlGenRandom(buffer);
|
||||
}
|
||||
if (native_os == .linux or native_os == .freebsd) {
|
||||
if (builtin.link_libc and @TypeOf(system.arc4random_buf) != void) {
|
||||
system.arc4random_buf(buffer.ptr, buffer.len);
|
||||
return;
|
||||
}
|
||||
if (native_os == .wasi) switch (wasi.random_get(buffer.ptr, buffer.len)) {
|
||||
.SUCCESS => return,
|
||||
else => |err| return unexpectedErrno(err),
|
||||
};
|
||||
if (@TypeOf(system.getrandom) != void) {
|
||||
var buf = buffer;
|
||||
const use_c = native_os != .linux or
|
||||
std.c.versionCheck(std.SemanticVersion{ .major = 2, .minor = 25, .patch = 0 });
|
||||
@@ -603,17 +620,7 @@ pub fn getrandom(buffer: []u8) GetRandomError!void {
|
||||
else => return unexpectedErrno(err),
|
||||
}
|
||||
}
|
||||
switch (native_os) {
|
||||
.netbsd, .openbsd, .macos, .ios, .tvos, .watchos, .visionos => {
|
||||
system.arc4random_buf(buffer.ptr, buffer.len);
|
||||
return;
|
||||
},
|
||||
.wasi => switch (wasi.random_get(buffer.ptr, buffer.len)) {
|
||||
.SUCCESS => return,
|
||||
else => |err| return unexpectedErrno(err),
|
||||
},
|
||||
else => return getRandomBytesDevURandom(buffer),
|
||||
}
|
||||
return getRandomBytesDevURandom(buffer);
|
||||
}
|
||||
|
||||
fn getRandomBytesDevURandom(buf: []u8) !void {
|
||||
@@ -3430,7 +3437,7 @@ pub fn isatty(handle: fd_t) bool {
|
||||
}
|
||||
if (native_os == .linux) {
|
||||
while (true) {
|
||||
var wsz: linux.winsize = undefined;
|
||||
var wsz: winsize = undefined;
|
||||
const fd: usize = @bitCast(@as(isize, handle));
|
||||
const rc = linux.syscall3(.ioctl, fd, linux.T.IOCGWINSZ, @intFromPtr(&wsz));
|
||||
switch (linux.E.init(rc)) {
|
||||
@@ -4929,8 +4936,7 @@ pub fn pipe() PipeError![2]fd_t {
|
||||
}
|
||||
|
||||
pub fn pipe2(flags: O) PipeError![2]fd_t {
|
||||
// https://github.com/ziglang/zig/issues/19352
|
||||
if (@hasDecl(system, "pipe2")) {
|
||||
if (@TypeOf(system.pipe2) != void) {
|
||||
var fds: [2]fd_t = undefined;
|
||||
switch (errno(system.pipe2(&fds, flags))) {
|
||||
.SUCCESS => return fds,
|
||||
@@ -5438,8 +5444,8 @@ pub fn realpathW(pathname: []const u16, out_buffer: *[max_path_bytes]u8) RealPat
|
||||
/// Spurious wakeups are possible and no precision of timing is guaranteed.
|
||||
pub fn nanosleep(seconds: u64, nanoseconds: u64) void {
|
||||
var req = timespec{
|
||||
.tv_sec = cast(isize, seconds) orelse maxInt(isize),
|
||||
.tv_nsec = cast(isize, nanoseconds) orelse maxInt(isize),
|
||||
.sec = cast(isize, seconds) orelse maxInt(isize),
|
||||
.nsec = cast(isize, nanoseconds) orelse maxInt(isize),
|
||||
};
|
||||
var rem: timespec = undefined;
|
||||
while (true) {
|
||||
@@ -5511,10 +5517,10 @@ pub fn dl_iterate_phdr(
|
||||
} else unreachable;
|
||||
|
||||
var info = dl_phdr_info{
|
||||
.dlpi_addr = base_address,
|
||||
.dlpi_name = "/proc/self/exe",
|
||||
.dlpi_phdr = phdrs.ptr,
|
||||
.dlpi_phnum = ehdr.e_phnum,
|
||||
.addr = base_address,
|
||||
.name = "/proc/self/exe",
|
||||
.phdr = phdrs.ptr,
|
||||
.phnum = ehdr.e_phnum,
|
||||
};
|
||||
|
||||
return callback(&info, @sizeOf(dl_phdr_info), context);
|
||||
@@ -5522,24 +5528,24 @@ pub fn dl_iterate_phdr(
|
||||
|
||||
// Last return value from the callback function.
|
||||
while (it.next()) |entry| {
|
||||
var dlpi_phdr: [*]elf.Phdr = undefined;
|
||||
var dlpi_phnum: u16 = undefined;
|
||||
var phdr: [*]elf.Phdr = undefined;
|
||||
var phnum: u16 = undefined;
|
||||
|
||||
if (entry.l_addr != 0) {
|
||||
const elf_header: *elf.Ehdr = @ptrFromInt(entry.l_addr);
|
||||
dlpi_phdr = @ptrFromInt(entry.l_addr + elf_header.e_phoff);
|
||||
dlpi_phnum = elf_header.e_phnum;
|
||||
phdr = @ptrFromInt(entry.l_addr + elf_header.e_phoff);
|
||||
phnum = elf_header.e_phnum;
|
||||
} else {
|
||||
// This is the running ELF image
|
||||
dlpi_phdr = @ptrFromInt(elf_base + ehdr.e_phoff);
|
||||
dlpi_phnum = ehdr.e_phnum;
|
||||
phdr = @ptrFromInt(elf_base + ehdr.e_phoff);
|
||||
phnum = ehdr.e_phnum;
|
||||
}
|
||||
|
||||
var info = dl_phdr_info{
|
||||
.dlpi_addr = entry.l_addr,
|
||||
.dlpi_name = entry.l_name,
|
||||
.dlpi_phdr = dlpi_phdr,
|
||||
.dlpi_phnum = dlpi_phnum,
|
||||
.addr = entry.l_addr,
|
||||
.name = entry.l_name,
|
||||
.phdr = phdr,
|
||||
.phnum = phnum,
|
||||
};
|
||||
|
||||
try callback(&info, @sizeOf(dl_phdr_info), context);
|
||||
@@ -5549,15 +5555,14 @@ pub fn dl_iterate_phdr(
|
||||
pub const ClockGetTimeError = error{UnsupportedClock} || UnexpectedError;
|
||||
|
||||
/// TODO: change this to return the timespec as a return value
|
||||
/// TODO: look into making clk_id an enum
|
||||
pub fn clock_gettime(clk_id: i32, tp: *timespec) ClockGetTimeError!void {
|
||||
pub fn clock_gettime(clock_id: clockid_t, tp: *timespec) ClockGetTimeError!void {
|
||||
if (native_os == .wasi and !builtin.link_libc) {
|
||||
var ts: timestamp_t = undefined;
|
||||
switch (system.clock_time_get(@bitCast(clk_id), 1, &ts)) {
|
||||
switch (system.clock_time_get(clock_id, 1, &ts)) {
|
||||
.SUCCESS => {
|
||||
tp.* = .{
|
||||
.tv_sec = @intCast(ts / std.time.ns_per_s),
|
||||
.tv_nsec = @intCast(ts % std.time.ns_per_s),
|
||||
.sec = @intCast(ts / std.time.ns_per_s),
|
||||
.nsec = @intCast(ts % std.time.ns_per_s),
|
||||
};
|
||||
},
|
||||
.INVAL => return error.UnsupportedClock,
|
||||
@@ -5566,15 +5571,15 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) ClockGetTimeError!void {
|
||||
return;
|
||||
}
|
||||
if (native_os == .windows) {
|
||||
if (clk_id == CLOCK.REALTIME) {
|
||||
if (clock_id == .REALTIME) {
|
||||
var ft: windows.FILETIME = undefined;
|
||||
windows.kernel32.GetSystemTimeAsFileTime(&ft);
|
||||
// FileTime has a granularity of 100 nanoseconds and uses the NTFS/Windows epoch.
|
||||
const ft64 = (@as(u64, ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
|
||||
const ft_per_s = std.time.ns_per_s / 100;
|
||||
tp.* = .{
|
||||
.tv_sec = @as(i64, @intCast(ft64 / ft_per_s)) + std.time.epoch.windows,
|
||||
.tv_nsec = @as(c_long, @intCast(ft64 % ft_per_s)) * 100,
|
||||
.sec = @as(i64, @intCast(ft64 / ft_per_s)) + std.time.epoch.windows,
|
||||
.nsec = @as(c_long, @intCast(ft64 % ft_per_s)) * 100,
|
||||
};
|
||||
return;
|
||||
} else {
|
||||
@@ -5583,7 +5588,7 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) ClockGetTimeError!void {
|
||||
}
|
||||
}
|
||||
|
||||
switch (errno(system.clock_gettime(clk_id, tp))) {
|
||||
switch (errno(system.clock_gettime(clock_id, tp))) {
|
||||
.SUCCESS => return,
|
||||
.FAULT => unreachable,
|
||||
.INVAL => return error.UnsupportedClock,
|
||||
@@ -5591,13 +5596,13 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) ClockGetTimeError!void {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn clock_getres(clk_id: i32, res: *timespec) ClockGetTimeError!void {
|
||||
pub fn clock_getres(clock_id: clockid_t, res: *timespec) ClockGetTimeError!void {
|
||||
if (native_os == .wasi and !builtin.link_libc) {
|
||||
var ts: timestamp_t = undefined;
|
||||
switch (system.clock_res_get(@bitCast(clk_id), &ts)) {
|
||||
switch (system.clock_res_get(@bitCast(clock_id), &ts)) {
|
||||
.SUCCESS => res.* = .{
|
||||
.tv_sec = @intCast(ts / std.time.ns_per_s),
|
||||
.tv_nsec = @intCast(ts % std.time.ns_per_s),
|
||||
.sec = @intCast(ts / std.time.ns_per_s),
|
||||
.nsec = @intCast(ts % std.time.ns_per_s),
|
||||
},
|
||||
.INVAL => return error.UnsupportedClock,
|
||||
else => |err| return unexpectedErrno(err),
|
||||
@@ -5605,7 +5610,7 @@ pub fn clock_getres(clk_id: i32, res: *timespec) ClockGetTimeError!void {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (errno(system.clock_getres(clk_id, res))) {
|
||||
switch (errno(system.clock_getres(clock_id, res))) {
|
||||
.SUCCESS => return,
|
||||
.FAULT => unreachable,
|
||||
.INVAL => return error.UnsupportedClock,
|
||||
@@ -5666,7 +5671,7 @@ pub fn sigprocmask(flags: u32, noalias set: ?*const sigset_t, noalias oldset: ?*
|
||||
}
|
||||
|
||||
pub const FutimensError = error{
|
||||
/// times is NULL, or both tv_nsec values are UTIME_NOW, and either:
|
||||
/// times is NULL, or both nsec values are UTIME_NOW, and either:
|
||||
/// * the effective user ID of the caller does not match the owner
|
||||
/// of the file, the caller does not have write access to the
|
||||
/// file, and the caller is not privileged (Linux: does not have
|
||||
@@ -5678,8 +5683,8 @@ pub const FutimensError = error{
|
||||
/// The caller attempted to change one or both timestamps to a value
|
||||
/// other than the current time, or to change one of the timestamps
|
||||
/// to the current time while leaving the other timestamp unchanged,
|
||||
/// (i.e., times is not NULL, neither tv_nsec field is UTIME_NOW,
|
||||
/// and neither tv_nsec field is UTIME_OMIT) and either:
|
||||
/// (i.e., times is not NULL, neither nsec field is UTIME_NOW,
|
||||
/// and neither nsec field is UTIME_OMIT) and either:
|
||||
/// * the caller's effective user ID does not match the owner of
|
||||
/// file, and the caller is not privileged (Linux: does not have
|
||||
/// the CAP_FOWNER capability); or,
|
||||
@@ -5794,9 +5799,9 @@ pub fn res_mkquery(
|
||||
|
||||
// Make a reasonably unpredictable id
|
||||
var ts: timespec = undefined;
|
||||
clock_gettime(CLOCK.REALTIME, &ts) catch {};
|
||||
const UInt = std.meta.Int(.unsigned, @bitSizeOf(@TypeOf(ts.tv_nsec)));
|
||||
const unsec: UInt = @bitCast(ts.tv_nsec);
|
||||
clock_gettime(.REALTIME, &ts) catch {};
|
||||
const UInt = std.meta.Int(.unsigned, @bitSizeOf(@TypeOf(ts.nsec)));
|
||||
const unsec: UInt = @bitCast(ts.nsec);
|
||||
const id: u32 = @truncate(unsec + unsec / 65536);
|
||||
q[0] = @truncate(id / 256);
|
||||
q[1] = @truncate(id);
|
||||
@@ -7195,8 +7200,8 @@ pub const TimerFdCreateError = error{
|
||||
pub const TimerFdGetError = error{InvalidHandle} || UnexpectedError;
|
||||
pub const TimerFdSetError = TimerFdGetError || error{Canceled};
|
||||
|
||||
pub fn timerfd_create(clokid: i32, flags: system.TFD) TimerFdCreateError!fd_t {
|
||||
const rc = system.timerfd_create(clokid, @bitCast(flags));
|
||||
pub fn timerfd_create(clock_id: clockid_t, flags: system.TFD) TimerFdCreateError!fd_t {
|
||||
const rc = system.timerfd_create(clock_id, @bitCast(flags));
|
||||
return switch (errno(rc)) {
|
||||
.SUCCESS => @intCast(rc),
|
||||
.INVAL => unreachable,
|
||||
|
||||
+13
-14
@@ -483,7 +483,8 @@ test "sigaltstack" {
|
||||
|
||||
// If the type is not available use void to avoid erroring out when `iter_fn` is
|
||||
// analyzed
|
||||
const dl_phdr_info = if (@hasDecl(posix.system, "dl_phdr_info")) posix.dl_phdr_info else anyopaque;
|
||||
const have_dl_phdr_info = posix.system.dl_phdr_info != void;
|
||||
const dl_phdr_info = if (have_dl_phdr_info) posix.dl_phdr_info else anyopaque;
|
||||
|
||||
const IterFnError = error{
|
||||
MissingPtLoadSegment,
|
||||
@@ -498,24 +499,24 @@ fn iter_fn(info: *dl_phdr_info, size: usize, counter: *usize) IterFnError!void {
|
||||
counter.* += @as(usize, 1);
|
||||
|
||||
// The image should contain at least a PT_LOAD segment
|
||||
if (info.dlpi_phnum < 1) return error.MissingPtLoadSegment;
|
||||
if (info.phnum < 1) return error.MissingPtLoadSegment;
|
||||
|
||||
// Quick & dirty validation of the phdr pointers, make sure we're not
|
||||
// pointing to some random gibberish
|
||||
var i: usize = 0;
|
||||
var found_load = false;
|
||||
while (i < info.dlpi_phnum) : (i += 1) {
|
||||
const phdr = info.dlpi_phdr[i];
|
||||
while (i < info.phnum) : (i += 1) {
|
||||
const phdr = info.phdr[i];
|
||||
|
||||
if (phdr.p_type != elf.PT_LOAD) continue;
|
||||
|
||||
const reloc_addr = info.dlpi_addr + phdr.p_vaddr;
|
||||
const reloc_addr = info.addr + phdr.p_vaddr;
|
||||
// Find the ELF header
|
||||
const elf_header = @as(*elf.Ehdr, @ptrFromInt(reloc_addr - phdr.p_offset));
|
||||
// Validate the magic
|
||||
if (!mem.eql(u8, elf_header.e_ident[0..4], elf.MAGIC)) return error.BadElfMagic;
|
||||
// Consistency check
|
||||
if (elf_header.e_phnum != info.dlpi_phnum) return error.FailedConsistencyCheck;
|
||||
if (elf_header.e_phnum != info.phnum) return error.FailedConsistencyCheck;
|
||||
|
||||
found_load = true;
|
||||
break;
|
||||
@@ -774,12 +775,10 @@ test "fsync" {
|
||||
}
|
||||
|
||||
test "getrlimit and setrlimit" {
|
||||
if (!@hasDecl(posix.system, "rlimit")) {
|
||||
return error.SkipZigTest;
|
||||
}
|
||||
if (posix.system.rlimit_resource == void) return error.SkipZigTest;
|
||||
|
||||
inline for (std.meta.fields(posix.rlimit_resource)) |field| {
|
||||
const resource = @as(posix.rlimit_resource, @enumFromInt(field.value));
|
||||
inline for (@typeInfo(posix.rlimit_resource).Enum.fields) |field| {
|
||||
const resource: posix.rlimit_resource = @enumFromInt(field.value);
|
||||
const limit = try posix.getrlimit(resource);
|
||||
|
||||
// XNU kernel does not support RLIMIT_STACK if a custom stack is active,
|
||||
@@ -1116,18 +1115,18 @@ test "access smoke test" {
|
||||
test "timerfd" {
|
||||
if (native_os != .linux) return error.SkipZigTest;
|
||||
|
||||
const tfd = try posix.timerfd_create(linux.CLOCK.MONOTONIC, .{ .CLOEXEC = true });
|
||||
const tfd = try posix.timerfd_create(.MONOTONIC, .{ .CLOEXEC = true });
|
||||
defer posix.close(tfd);
|
||||
|
||||
// Fire event 10_000_000ns = 10ms after the posix.timerfd_settime call.
|
||||
var sit: linux.itimerspec = .{ .it_interval = .{ .tv_sec = 0, .tv_nsec = 0 }, .it_value = .{ .tv_sec = 0, .tv_nsec = 10 * (1000 * 1000) } };
|
||||
var sit: linux.itimerspec = .{ .it_interval = .{ .sec = 0, .nsec = 0 }, .it_value = .{ .sec = 0, .nsec = 10 * (1000 * 1000) } };
|
||||
try posix.timerfd_settime(tfd, .{}, &sit, null);
|
||||
|
||||
var fds: [1]posix.pollfd = .{.{ .fd = tfd, .events = linux.POLL.IN, .revents = 0 }};
|
||||
try expectEqual(@as(usize, 1), try posix.poll(&fds, -1)); // -1 => infinite waiting
|
||||
|
||||
const git = try posix.timerfd_gettime(tfd);
|
||||
const expect_disarmed_timer: linux.itimerspec = .{ .it_interval = .{ .tv_sec = 0, .tv_nsec = 0 }, .it_value = .{ .tv_sec = 0, .tv_nsec = 0 } };
|
||||
const expect_disarmed_timer: linux.itimerspec = .{ .it_interval = .{ .sec = 0, .nsec = 0 }, .it_value = .{ .sec = 0, .nsec = 0 } };
|
||||
try expectEqual(expect_disarmed_timer, git);
|
||||
}
|
||||
|
||||
|
||||
+1
-4
@@ -1789,10 +1789,7 @@ pub fn cleanExit() void {
|
||||
/// On some systems, this raises the limit before seeing ProcessFdQuotaExceeded
|
||||
/// errors. On other systems, this does nothing.
|
||||
pub fn raiseFileDescriptorLimit() void {
|
||||
const have_rlimit = switch (native_os) {
|
||||
.windows, .wasi => false,
|
||||
else => true,
|
||||
};
|
||||
const have_rlimit = posix.rlimit_resource != void;
|
||||
if (!have_rlimit) return;
|
||||
|
||||
var lim = posix.getrlimit(.NOFILE) catch return; // Oh well; we tried.
|
||||
|
||||
+7
-7
@@ -115,10 +115,10 @@ pub fn nanoTimestamp() i128 {
|
||||
},
|
||||
else => {
|
||||
var ts: posix.timespec = undefined;
|
||||
posix.clock_gettime(posix.CLOCK.REALTIME, &ts) catch |err| switch (err) {
|
||||
posix.clock_gettime(.REALTIME, &ts) catch |err| switch (err) {
|
||||
error.UnsupportedClock, error.Unexpected => return 0, // "Precision of timing depends on hardware and OS".
|
||||
};
|
||||
return (@as(i128, ts.tv_sec) * ns_per_s) + ts.tv_nsec;
|
||||
return (@as(i128, ts.sec) * ns_per_s) + ts.nsec;
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -229,9 +229,9 @@ pub const Instant = struct {
|
||||
return std.math.order(self.timestamp, other.timestamp);
|
||||
}
|
||||
|
||||
var ord = std.math.order(self.timestamp.tv_sec, other.timestamp.tv_sec);
|
||||
var ord = std.math.order(self.timestamp.sec, other.timestamp.sec);
|
||||
if (ord == .eq) {
|
||||
ord = std.math.order(self.timestamp.tv_nsec, other.timestamp.tv_nsec);
|
||||
ord = std.math.order(self.timestamp.nsec, other.timestamp.nsec);
|
||||
}
|
||||
return ord;
|
||||
}
|
||||
@@ -267,9 +267,9 @@ pub const Instant = struct {
|
||||
}
|
||||
|
||||
// Convert timespec diff to ns
|
||||
const seconds = @as(u64, @intCast(self.timestamp.tv_sec - earlier.timestamp.tv_sec));
|
||||
const elapsed = (seconds * ns_per_s) + @as(u32, @intCast(self.timestamp.tv_nsec));
|
||||
return elapsed - @as(u32, @intCast(earlier.timestamp.tv_nsec));
|
||||
const seconds = @as(u64, @intCast(self.timestamp.sec - earlier.timestamp.sec));
|
||||
const elapsed = (seconds * ns_per_s) + @as(u32, @intCast(self.timestamp.nsec));
|
||||
return elapsed - @as(u32, @intCast(earlier.timestamp.nsec));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user