Commit e8c4e79499
Changed files (48)
lib
std
c
crypto
Certificate
Bundle
os
posix
lib/std/c/darwin/aarch64.zig
@@ -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;
lib/std/c/darwin/cssm.zig
@@ -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,
-
- _,
-};
lib/std/c/darwin/x86_64.zig
@@ -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;
lib/std/c/darwin.zig
@@ -1,24 +1,30 @@
-const std = @import("../std.zig");
+const std = @import("std");
const builtin = @import("builtin");
-const assert = std.debug.assert;
-const macho = std.macho;
const native_arch = builtin.target.cpu.arch;
-const maxInt = std.math.maxInt;
+const assert = std.debug.assert;
+const AF = std.c.AF;
+const PROT = std.c.PROT;
+const fd_t = std.c.fd_t;
const iovec_const = std.posix.iovec_const;
+const mode_t = std.c.mode_t;
+const off_t = std.c.off_t;
+const pid_t = std.c.pid_t;
+const pthread_attr_t = std.c.pthread_attr_t;
+const sigset_t = std.c.segset_t;
+const timespec = std.c.timespec;
+const sf_hdtr = std.c.sf_hdtr;
+
+comptime {
+ assert(builtin.os.tag.isDarwin()); // Prevent access of std.c symbols on wrong OS.
+}
-pub const aarch64 = @import("darwin/aarch64.zig");
-pub const x86_64 = @import("darwin/x86_64.zig");
-pub const cssm = @import("darwin/cssm.zig");
+pub const mach_port_t = c_uint;
-const arch_bits = switch (native_arch) {
- .aarch64 => @import("darwin/aarch64.zig"),
- .x86_64 => @import("darwin/x86_64.zig"),
- else => struct {},
+pub const THREAD_STATE_NONE = switch (native_arch) {
+ .aarch64 => 5,
+ .x86_64 => 13,
};
-pub const EXC_TYPES_COUNT = arch_bits.EXC_TYPES_COUNT;
-pub const THREAD_STATE_NONE = arch_bits.THREAD_STATE_NONE;
-
pub const EXC = enum(exception_type_t) {
NULL = 0,
/// Could not access memory
@@ -47,49 +53,61 @@ pub const EXC = enum(exception_type_t) {
GUARD = 12,
/// Abnormal process exited to corpse state
CORPSE_NOTIFY = 13,
+
+ pub const TYPES_COUNT = @typeInfo(EXC).Enum.fields.len;
+ pub const SOFT_SIGNAL = 0x10003;
+
+ pub const MASK = packed struct(u32) {
+ BAD_ACCESS: bool = false,
+ BAD_INSTRUCTION: bool = false,
+ ARITHMETIC: bool = false,
+ EMULATION: bool = false,
+ SOFTWARE: bool = false,
+ BREAKPOINT: bool = false,
+ SYSCALL: bool = false,
+ MACH_SYSCALL: bool = false,
+ RPC_ALERT: bool = false,
+ CRASH: bool = false,
+ RESOURCE: bool = false,
+ GUARD: bool = false,
+ CORPSE_NOTIFY: bool = false,
+
+ pub const MACHINE: MASK = @bitCast(@as(u32, 0));
+
+ pub const ALL: MASK = .{
+ .BAD_ACCESS = true,
+ .BAD_INSTRUCTION = true,
+ .ARITHMETIC = true,
+ .EMULATION = true,
+ .SOFTWARE = true,
+ .BREAKPOINT = true,
+ .SYSCALL = true,
+ .MACH_SYSCALL = true,
+ .RPC_ALERT = true,
+ .CRASH = true,
+ .RESOURCE = true,
+ .GUARD = true,
+ .CORPSE_NOTIFY = true,
+ };
+ };
+};
+
+pub const EXCEPTION = enum(u32) {
+ /// Send a catch_exception_raise message including the identity.
+ DEFAULT = 1,
+ /// Send a catch_exception_raise_state message including the
+ /// thread state.
+ STATE = 2,
+ /// Send a catch_exception_raise_state_identity message including
+ /// the thread identity and state.
+ STATE_IDENTITY = 3,
+ /// Send a catch_exception_raise_identity_protected message including protected task
+ /// and thread identity.
+ IDENTITY_PROTECTED = 4,
+
+ _,
};
-pub const EXC_SOFT_SIGNAL = 0x10003;
-
-pub const EXC_MASK_BAD_ACCESS = 1 << @intFromEnum(EXC.BAD_ACCESS);
-pub const EXC_MASK_BAD_INSTRUCTION = 1 << @intFromEnum(EXC.BAD_INSTRUCTION);
-pub const EXC_MASK_ARITHMETIC = 1 << @intFromEnum(EXC.ARITHMETIC);
-pub const EXC_MASK_EMULATION = 1 << @intFromEnum(EXC.EMULATION);
-pub const EXC_MASK_SOFTWARE = 1 << @intFromEnum(EXC.SOFTWARE);
-pub const EXC_MASK_BREAKPOINT = 1 << @intFromEnum(EXC.BREAKPOINT);
-pub const EXC_MASK_SYSCALL = 1 << @intFromEnum(EXC.SYSCALL);
-pub const EXC_MASK_MACH_SYSCALL = 1 << @intFromEnum(EXC.MACH_SYSCALL);
-pub const EXC_MASK_RPC_ALERT = 1 << @intFromEnum(EXC.RPC_ALERT);
-pub const EXC_MASK_CRASH = 1 << @intFromEnum(EXC.CRASH);
-pub const EXC_MASK_RESOURCE = 1 << @intFromEnum(EXC.RESOURCE);
-pub const EXC_MASK_GUARD = 1 << @intFromEnum(EXC.GUARD);
-pub const EXC_MASK_CORPSE_NOTIFY = 1 << @intFromEnum(EXC.CORPSE_NOTIFY);
-pub const EXC_MASK_MACHINE = arch_bits.EXC_MASK_MACHINE;
-
-pub const EXC_MASK_ALL = EXC_MASK_BAD_ACCESS |
- EXC_MASK_BAD_INSTRUCTION |
- EXC_MASK_ARITHMETIC |
- EXC_MASK_EMULATION |
- EXC_MASK_SOFTWARE |
- EXC_MASK_BREAKPOINT |
- EXC_MASK_SYSCALL |
- EXC_MASK_MACH_SYSCALL |
- EXC_MASK_RPC_ALERT |
- EXC_MASK_RESOURCE |
- EXC_MASK_GUARD |
- EXC_MASK_MACHINE;
-
-/// Send a catch_exception_raise message including the identity.
-pub const EXCEPTION_DEFAULT = 1;
-/// Send a catch_exception_raise_state message including the
-/// thread state.
-pub const EXCEPTION_STATE = 2;
-/// Send a catch_exception_raise_state_identity message including
-/// the thread identity and state.
-pub const EXCEPTION_STATE_IDENTITY = 3;
-/// Send a catch_exception_raise_identity_protected message including protected task
-/// and thread identity.
-pub const EXCEPTION_IDENTITY_PROTECTED = 4;
/// Prefer sending a catch_exception_raice_backtrace message, if applicable.
pub const MACH_EXCEPTION_BACKTRACE_PREFERRED = 0x20000000;
/// include additional exception specific errors, not used yet.
@@ -141,19 +159,109 @@ pub const MACH_RCV_SYNC_PEEK = 0x00008000;
pub const MACH_MSG_STRICT_REPLY = 0x00000200;
-pub const ucontext_t = extern struct {
- onstack: c_int,
- sigmask: sigset_t,
- stack: stack_t,
- link: ?*ucontext_t,
- mcsize: u64,
- mcontext: *mcontext_t,
- __mcontext_data: mcontext_t,
+pub const exception_type_t = c_int;
+
+pub const mcontext_t = switch (native_arch) {
+ .aarch64 => extern struct {
+ es: exception_state,
+ ss: thread_state,
+ ns: neon_state,
+ },
+ .x86_64 => extern struct {
+ es: exception_state,
+ ss: thread_state,
+ fs: float_state,
+ },
+ else => @compileError("unsupported arch"),
};
-pub const mcontext_t = arch_bits.mcontext_t;
+pub const exception_state = switch (native_arch) {
+ .aarch64 => extern struct {
+ far: u64, // Virtual Fault Address
+ esr: u32, // Exception syndrome
+ exception: u32, // Number of arm exception taken
+ },
+ .x86_64 => extern struct {
+ trapno: u16,
+ cpu: u16,
+ err: u32,
+ faultvaddr: u64,
+ },
+ else => @compileError("unsupported arch"),
+};
+
+pub const thread_state = switch (native_arch) {
+ .aarch64 => extern struct {
+ /// General purpose registers
+ regs: [29]u64,
+ /// Frame pointer x29
+ fp: u64,
+ /// Link register x30
+ lr: u64,
+ /// Stack pointer x31
+ sp: u64,
+ /// Program counter
+ pc: u64,
+ /// Current program status register
+ cpsr: u32,
+ __pad: u32,
+ },
+ .x86_64 => 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,
+ },
+ else => @compileError("unsupported arch"),
+};
+
+pub const neon_state = extern struct {
+ q: [32]u128,
+ fpsr: u32,
+ fpcr: u32,
+};
+
+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 stmm_reg = [16]u8;
+pub const xmm_reg = [16]u8;
-extern "c" fn __error() *c_int;
pub extern "c" fn NSVersionOfRunTimeLibrary(library_name: [*:0]const u8) u32;
pub extern "c" fn _NSGetExecutablePath(buf: [*:0]u8, bufsize: *u32) c_int;
pub extern "c" fn _dyld_image_count() u32;
@@ -161,23 +269,22 @@ pub extern "c" fn _dyld_get_image_header(image_index: u32) ?*mach_header;
pub extern "c" fn _dyld_get_image_vmaddr_slide(image_index: u32) usize;
pub extern "c" fn _dyld_get_image_name(image_index: u32) [*:0]const u8;
-pub const COPYFILE_ACL = 1 << 0;
-pub const COPYFILE_STAT = 1 << 1;
-pub const COPYFILE_XATTR = 1 << 2;
-pub const COPYFILE_DATA = 1 << 3;
+pub const COPYFILE = packed struct(u32) {
+ ACL: bool = false,
+ STAT: bool = false,
+ XATTR: bool = false,
+ DATA: bool = false,
+ _: u28 = 0,
+};
pub const copyfile_state_t = *opaque {};
-pub extern "c" fn fcopyfile(from: fd_t, to: fd_t, state: ?copyfile_state_t, flags: u32) c_int;
-
+pub extern "c" fn fcopyfile(from: fd_t, to: fd_t, state: ?copyfile_state_t, flags: COPYFILE) c_int;
pub extern "c" fn __getdirentries64(fd: c_int, buf_ptr: [*]u8, buf_len: usize, basep: *i64) isize;
pub extern "c" fn mach_absolute_time() u64;
pub extern "c" fn mach_continuous_time() u64;
pub extern "c" fn mach_timebase_info(tinfo: ?*mach_timebase_info_data) kern_return_t;
-pub extern "c" fn malloc_size(?*const anyopaque) usize;
-pub extern "c" fn posix_memalign(memptr: *?*anyopaque, alignment: usize, size: usize) c_int;
-
pub extern "c" fn kevent64(
kq: c_int,
changelist: [*]const kevent64_s,
@@ -188,34 +295,15 @@ pub extern "c" fn kevent64(
timeout: ?*const timespec,
) c_int;
-const mach_hdr = if (@sizeOf(usize) == 8) mach_header_64 else mach_header;
-
-/// The value of the link editor defined symbol _MH_EXECUTE_SYM is the address
-/// of the mach header in a Mach-O executable file type. It does not appear in
-/// any file type other than a MH_EXECUTE file type. The type of the symbol is
-/// absolute as the header is not part of any section.
-/// This symbol is populated when linking the system's libc, which is guaranteed
-/// on this operating system. However when building object files or libraries,
-/// the system libc won't be linked until the final executable. So we
-/// export a weak symbol here, to be overridden by the real one.
-var dummy_execute_header: mach_hdr = undefined;
-pub extern var _mh_execute_header: mach_hdr;
-comptime {
- if (builtin.target.isDarwin()) {
- @export(dummy_execute_header, .{ .name = "_mh_execute_header", .linkage = .weak });
- }
-}
-
-pub const mach_header_64 = macho.mach_header_64;
-pub const mach_header = macho.mach_header;
+pub const mach_hdr = if (@sizeOf(usize) == 8) mach_header_64 else mach_header;
-pub const _errno = __error;
+pub const mach_header_64 = std.macho.mach_header_64;
+pub const mach_header = std.macho.mach_header;
pub extern "c" fn @"close$NOCANCEL"(fd: fd_t) c_int;
pub extern "c" fn mach_host_self() mach_port_t;
pub extern "c" fn clock_get_time(clock_serv: clock_serv_t, cur_time: *mach_timespec_t) kern_return_t;
-pub const exception_type_t = c_int;
pub const exception_data_type_t = integer_t;
pub const exception_data_t = ?*mach_exception_data_type_t;
pub const mach_exception_data_type_t = i64;
@@ -679,6 +767,7 @@ pub const task_vm_info = extern struct {
// added for rev5
decompressions: integer_t,
};
+
pub const task_vm_info_data_t = task_vm_info;
pub const vm_prot_t = c_int;
@@ -745,13 +834,6 @@ pub extern "c" fn vm_machine_attribute(
value: *vm_machine_attribute_val_t,
) kern_return_t;
-pub const sf_hdtr = extern struct {
- headers: [*]const iovec_const,
- hdr_cnt: c_int,
- trailers: [*]const iovec_const,
- trl_cnt: c_int,
-};
-
pub extern "c" fn sendfile(
in_fd: fd_t,
out_fd: fd_t,
@@ -765,69 +847,6 @@ pub fn sigaddset(set: *sigset_t, signo: u5) void {
set.* |= @as(u32, 1) << (signo - 1);
}
-pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int;
-
-pub const IFNAMESIZE = 16;
-
-pub const AI = struct {
- /// get address to use bind()
- pub const PASSIVE = 0x00000001;
- /// fill ai_canonname
- pub const CANONNAME = 0x00000002;
- /// prevent host name resolution
- pub const NUMERICHOST = 0x00000004;
- /// prevent service name resolution
- pub const NUMERICSERV = 0x00001000;
-};
-
-pub const EAI = enum(c_int) {
- /// address family for hostname not supported
- ADDRFAMILY = 1,
-
- /// temporary failure in name resolution
- AGAIN = 2,
-
- /// invalid value for ai_flags
- BADFLAGS = 3,
-
- /// non-recoverable failure in name resolution
- FAIL = 4,
-
- /// ai_family not supported
- FAMILY = 5,
-
- /// memory allocation failure
- MEMORY = 6,
-
- /// no address associated with hostname
- NODATA = 7,
-
- /// hostname nor servname provided, or not known
- NONAME = 8,
-
- /// servname not supported for ai_socktype
- SERVICE = 9,
-
- /// ai_socktype not supported
- 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 qos_class_t = enum(c_uint) {
/// highest priority QOS class for critical tasks
QOS_CLASS_USER_INTERACTIVE = 0x21,
@@ -843,23 +862,6 @@ pub const qos_class_t = enum(c_uint) {
QOS_CLASS_UNSPECIFIED = 0x00,
};
-pub const sem_t = c_int;
-
-pub const pthread_attr_t = extern struct {
- __sig: c_long,
- __opaque: [56]u8,
-};
-
-pub extern "c" fn pthread_threadid_np(thread: ?std.c.pthread_t, thread_id: *u64) c_int;
-pub extern "c" fn pthread_setname_np(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 extern "c" fn pthread_attr_set_qos_class_np(attr: *pthread_attr_t, qos_class: qos_class_t, relative_priority: c_int) c_int;
-pub extern "c" fn pthread_attr_get_qos_class_np(attr: *pthread_attr_t, qos_class: *qos_class_t, relative_priority: *c_int) c_int;
-pub extern "c" fn pthread_set_qos_class_self_np(qos_class: qos_class_t, relative_priority: c_int) c_int;
-pub extern "c" fn pthread_get_qos_class_np(pthread: std.c.pthread_t, qos_class: *qos_class_t, relative_priority: *c_int) c_int;
-
-pub extern "c" fn arc4random_buf(buf: [*]u8, len: usize) void;
-
// Grand Central Dispatch is exposed by libSystem.
pub extern "c" fn dispatch_release(object: *anyopaque) void;
@@ -881,38 +883,37 @@ pub extern fn dispatch_once_f(
function: dispatch_function_t,
) void;
-// Undocumented futex-like API available on darwin 16+
-// (macOS 10.12+, iOS 10.0+, tvOS 10.0+, watchOS 3.0+, catalyst 13.0+).
-//
-// [ulock.h]: https://github.com/apple/darwin-xnu/blob/master/bsd/sys/ulock.h
-// [sys_ulock.c]: https://github.com/apple/darwin-xnu/blob/master/bsd/kern/sys_ulock.c
-
-pub const UL_COMPARE_AND_WAIT = 1;
-pub const UL_UNFAIR_LOCK = 2;
-
-// Obsolete/deprecated
-pub const UL_OSSPINLOCK = UL_COMPARE_AND_WAIT;
-pub const UL_HANDOFFLOCK = UL_UNFAIR_LOCK;
-
-pub const ULF_WAKE_ALL = 0x100;
-pub const ULF_WAKE_THREAD = 0x200;
-pub const ULF_WAIT_WORKQ_DATA_CONTENTION = 0x10000;
-pub const ULF_WAIT_CANCEL_POINT = 0x20000;
-pub const ULF_NO_ERRNO = 0x1000000;
-
-// The following are only supported on darwin 19+
-// (macOS 10.15+, iOS 13.0+)
-pub const UL_COMPARE_AND_WAIT_SHARED = 3;
-pub const UL_UNFAIR_LOCK64_SHARED = 4;
-pub const UL_COMPARE_AND_WAIT64 = 5;
-pub const UL_COMPARE_AND_WAIT64_SHARED = 6;
-pub const ULF_WAIT_ADAPTIVE_SPIN = 0x40000;
-
-pub extern "c" fn __ulock_wait2(op: u32, addr: ?*const anyopaque, val: u64, timeout_ns: u64, val2: u64) c_int;
-pub extern "c" fn __ulock_wait(op: u32, addr: ?*const anyopaque, val: u64, timeout_us: u32) c_int;
-pub extern "c" fn __ulock_wake(op: u32, addr: ?*const anyopaque, val: u64) c_int;
-
-pub const OS_UNFAIR_LOCK_INIT = os_unfair_lock{};
+/// Undocumented futex-like API available on darwin 16+
+/// (macOS 10.12+, iOS 10.0+, tvOS 10.0+, watchOS 3.0+, catalyst 13.0+).
+///
+/// [ulock.h]: https://github.com/apple/darwin-xnu/blob/master/bsd/sys/ulock.h
+/// [sys_ulock.c]: https://github.com/apple/darwin-xnu/blob/master/bsd/kern/sys_ulock.c
+pub const UL = packed struct(u32) {
+ op: Op,
+ WAKE_ALL: bool = false,
+ WAKE_THREAD: bool = false,
+ _10: u6 = 0,
+ WAIT_WORKQ_DATA_CONTENTION: bool = false,
+ WAIT_CANCEL_POINT: bool = false,
+ WAIT_ADAPTIVE_SPIN: bool = false,
+ _19: u5 = 0,
+ NO_ERRNO: bool = false,
+ _: u7 = 0,
+
+ pub const Op = enum(u8) {
+ COMPARE_AND_WAIT = 1,
+ UNFAIR_LOCK = 2,
+ COMPARE_AND_WAIT_SHARED = 3,
+ UNFAIR_LOCK64_SHARED = 4,
+ COMPARE_AND_WAIT64 = 5,
+ COMPARE_AND_WAIT64_SHARED = 6,
+ };
+};
+
+pub extern "c" fn __ulock_wait2(op: UL, addr: ?*const anyopaque, val: u64, timeout_ns: u64, val2: u64) c_int;
+pub extern "c" fn __ulock_wait(op: UL, addr: ?*const anyopaque, val: u64, timeout_us: u32) c_int;
+pub extern "c" fn __ulock_wake(op: UL, addr: ?*const anyopaque, val: u64) c_int;
+
pub const os_unfair_lock_t = *os_unfair_lock;
pub const os_unfair_lock = extern struct {
_os_unfair_lock_opaque: u32 = 0,
@@ -924,2416 +925,1234 @@ pub extern "c" fn os_unfair_lock_trylock(o: os_unfair_lock_t) bool;
pub extern "c" fn os_unfair_lock_assert_owner(o: os_unfair_lock_t) void;
pub extern "c" fn os_unfair_lock_assert_not_owner(o: os_unfair_lock_t) void;
-// See: https://opensource.apple.com/source/xnu/xnu-6153.141.1/bsd/sys/_types.h.auto.html
-// TODO: audit mode_t/pid_t, should likely be u16/i32
-pub const blkcnt_t = i64;
-pub const blksize_t = i32;
-pub const dev_t = i32;
-pub const fd_t = c_int;
-pub const pid_t = c_int;
-pub const mode_t = c_uint;
-pub const uid_t = u32;
-pub const gid_t = u32;
-
-// machine/_types.h
-pub const clock_t = c_ulong;
-pub const time_t = c_long;
-
-pub const in_port_t = u16;
-pub const sa_family_t = u8;
-pub const socklen_t = u32;
-pub const sockaddr = extern struct {
- len: u8,
- family: sa_family_t,
- 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,
- };
-
- /// UNIX domain socket
- pub const un = extern struct {
- len: u8 = @sizeOf(un),
- family: sa_family_t = AF.UNIX,
- path: [104]u8,
- };
-};
-pub const timeval = extern struct {
- tv_sec: c_long,
- tv_usec: i32,
-};
-
-pub const timezone = extern struct {
- tz_minuteswest: i32,
- tz_dsttime: i32,
-};
-
-pub const mach_timebase_info_data = extern struct {
- numer: u32,
- denom: u32,
-};
+pub fn getKernError(err: kern_return_t) KernE {
+ return @as(KernE, @enumFromInt(@as(u32, @truncate(@as(usize, @intCast(err))))));
+}
-pub const off_t = i64;
-pub const ino_t = u64;
+pub fn unexpectedKernError(err: KernE) std.posix.UnexpectedError {
+ if (std.posix.unexpected_error_tracing) {
+ std.debug.print("unexpected error: {d}\n", .{@intFromEnum(err)});
+ std.debug.dumpCurrentStackTrace(null);
+ }
+ return error.Unexpected;
+}
-pub const Flock = extern struct {
- start: off_t,
- len: off_t,
- pid: pid_t,
- type: i16,
- whence: i16,
-};
+pub const MachError = error{
+ /// Not enough permissions held to perform the requested kernel
+ /// call.
+ PermissionDenied,
+} || std.posix.UnexpectedError;
-pub const Stat = extern struct {
- dev: i32,
- mode: u16,
- nlink: u16,
- ino: ino_t,
- uid: uid_t,
- gid: gid_t,
- rdev: i32,
- atimespec: timespec,
- mtimespec: timespec,
- ctimespec: timespec,
- birthtimespec: timespec,
- size: off_t,
- blocks: i64,
- blksize: i32,
- flags: u32,
- gen: u32,
- lspare: i32,
- qspare: [2]i64,
+pub const MachTask = extern struct {
+ port: mach_port_name_t,
- pub fn atime(self: @This()) timespec {
- return self.atimespec;
+ pub fn isValid(self: MachTask) bool {
+ return self.port != TASK_NULL;
}
- pub fn mtime(self: @This()) timespec {
- return self.mtimespec;
+ pub fn pidForTask(self: MachTask) MachError!std.c.pid_t {
+ var pid: std.c.pid_t = undefined;
+ switch (getKernError(pid_for_task(self.port, &pid))) {
+ .SUCCESS => return pid,
+ .FAILURE => return error.PermissionDenied,
+ else => |err| return unexpectedKernError(err),
+ }
}
- pub fn ctime(self: @This()) timespec {
- return self.ctimespec;
+ pub fn allocatePort(self: MachTask, right: MACH_PORT_RIGHT) MachError!MachTask {
+ var out_port: mach_port_name_t = undefined;
+ switch (getKernError(mach_port_allocate(
+ self.port,
+ @intFromEnum(right),
+ &out_port,
+ ))) {
+ .SUCCESS => return .{ .port = out_port },
+ .FAILURE => return error.PermissionDenied,
+ else => |err| return unexpectedKernError(err),
+ }
}
- pub fn birthtime(self: @This()) timespec {
- return self.birthtimespec;
+ pub fn deallocatePort(self: MachTask, port: MachTask) void {
+ _ = getKernError(mach_port_deallocate(self.port, port.port));
}
-};
-
-pub const timespec = extern struct {
- tv_sec: isize,
- tv_nsec: isize,
-};
-
-pub const sigset_t = u32;
-pub const empty_sigset: sigset_t = 0;
-
-pub const SIG = struct {
- pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
- pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
- pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
- pub const HOLD: ?Sigaction.handler_fn = @ptrFromInt(5);
-
- /// block specified signal set
- pub const BLOCK = 1;
- /// unblock specified signal set
- pub const UNBLOCK = 2;
- /// set specified signal set
- pub const SETMASK = 3;
- /// hangup
- pub const HUP = 1;
- /// interrupt
- pub const INT = 2;
- /// quit
- pub const QUIT = 3;
- /// illegal instruction (not reset when caught)
- pub const ILL = 4;
- /// trace trap (not reset when caught)
- pub const TRAP = 5;
- /// abort()
- pub const ABRT = 6;
- /// pollable event ([XSR] generated, not supported)
- pub const POLL = 7;
- /// compatibility
- pub const IOT = ABRT;
- /// EMT instruction
- pub const EMT = 7;
- /// floating point exception
- pub const FPE = 8;
- /// kill (cannot be caught or ignored)
- pub const KILL = 9;
- /// bus error
- pub const BUS = 10;
- /// segmentation violation
- pub const SEGV = 11;
- /// bad argument to system call
- pub const SYS = 12;
- /// write on a pipe with no one to read it
- pub const PIPE = 13;
- /// alarm clock
- pub const ALRM = 14;
- /// software termination signal from kill
- pub const TERM = 15;
- /// urgent condition on IO channel
- pub const URG = 16;
- /// sendable stop signal not from tty
- pub const STOP = 17;
- /// stop signal from tty
- pub const TSTP = 18;
- /// continue a stopped process
- pub const CONT = 19;
- /// to parent on child stop or exit
- pub const CHLD = 20;
- /// to readers pgrp upon background tty read
- pub const TTIN = 21;
- /// like TTIN for output if (tp->t_local<OSTOP)
- pub const TTOU = 22;
- /// input/output possible signal
- pub const IO = 23;
- /// exceeded CPU time limit
- pub const XCPU = 24;
- /// exceeded file size limit
- pub const XFSZ = 25;
- /// virtual time alarm
- pub const VTALRM = 26;
- /// profiling time alarm
- pub const PROF = 27;
- /// window size changes
- pub const WINCH = 28;
- /// information request
- pub const INFO = 29;
- /// user defined signal 1
- pub const USR1 = 30;
- /// user defined signal 2
- pub const USR2 = 31;
-};
-
-pub const siginfo_t = extern struct {
- signo: c_int,
- errno: c_int,
- code: c_int,
- pid: pid_t,
- uid: uid_t,
- status: c_int,
- addr: *allowzero anyopaque,
- value: extern union {
- int: c_int,
- ptr: *anyopaque,
- },
- si_band: c_long,
- _pad: [7]c_ulong,
-};
-/// Renamed from `sigaction` to `Sigaction` to avoid conflict with function name.
-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;
-
- handler: extern union {
- handler: ?handler_fn,
- sigaction: ?sigaction_fn,
- },
- mask: sigset_t,
- flags: c_uint,
-};
+ pub fn insertRight(self: MachTask, port: MachTask, msg: MACH_MSG_TYPE) !void {
+ switch (getKernError(mach_port_insert_right(
+ self.port,
+ port.port,
+ port.port,
+ @intFromEnum(msg),
+ ))) {
+ .SUCCESS => return,
+ .FAILURE => return error.PermissionDenied,
+ else => |err| return unexpectedKernError(err),
+ }
+ }
-pub const dirent = extern struct {
- ino: u64,
- seekoff: u64,
- reclen: u16,
- namlen: u16,
- type: u8,
- name: [1024]u8,
-};
+ pub const PortInfo = struct {
+ mask: exception_mask_t,
+ masks: [EXC.TYPES_COUNT]exception_mask_t,
+ ports: [EXC.TYPES_COUNT]mach_port_t,
+ behaviors: [EXC.TYPES_COUNT]exception_behavior_t,
+ flavors: [EXC.TYPES_COUNT]thread_state_flavor_t,
+ count: mach_msg_type_number_t,
+ };
-/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.
-pub const Kevent = extern struct {
- ident: usize,
- filter: i16,
- flags: u16,
- fflags: u32,
- data: isize,
- udata: usize,
-};
+ pub fn getExceptionPorts(self: MachTask, mask: exception_mask_t) !PortInfo {
+ var info = PortInfo{
+ .mask = mask,
+ .masks = undefined,
+ .ports = undefined,
+ .behaviors = undefined,
+ .flavors = undefined,
+ .count = 0,
+ };
+ info.count = info.ports.len / @sizeOf(mach_port_t);
-// sys/types.h on macos uses #pragma pack(4) so these checks are
-// to make sure the struct is laid out the same. These values were
-// produced from C code using the offsetof macro.
-comptime {
- if (builtin.target.isDarwin()) {
- assert(@offsetOf(Kevent, "ident") == 0);
- assert(@offsetOf(Kevent, "filter") == 8);
- assert(@offsetOf(Kevent, "flags") == 10);
- assert(@offsetOf(Kevent, "fflags") == 12);
- assert(@offsetOf(Kevent, "data") == 16);
- assert(@offsetOf(Kevent, "udata") == 24);
+ switch (getKernError(task_get_exception_ports(
+ self.port,
+ info.mask,
+ &info.masks,
+ &info.count,
+ &info.ports,
+ &info.behaviors,
+ &info.flavors,
+ ))) {
+ .SUCCESS => return info,
+ .FAILURE => return error.PermissionDenied,
+ else => |err| return unexpectedKernError(err),
+ }
}
-}
-
-pub const kevent64_s = extern struct {
- ident: u64,
- filter: i16,
- flags: u16,
- fflags: u32,
- data: i64,
- udata: u64,
- ext: [2]u64,
-};
-// sys/types.h on macos uses #pragma pack() so these checks are
-// to make sure the struct is laid out the same. These values were
-// produced from C code using the offsetof macro.
-comptime {
- if (builtin.target.isDarwin()) {
- assert(@offsetOf(kevent64_s, "ident") == 0);
- assert(@offsetOf(kevent64_s, "filter") == 8);
- assert(@offsetOf(kevent64_s, "flags") == 10);
- assert(@offsetOf(kevent64_s, "fflags") == 12);
- assert(@offsetOf(kevent64_s, "data") == 16);
- assert(@offsetOf(kevent64_s, "udata") == 24);
- assert(@offsetOf(kevent64_s, "ext") == 32);
+ pub fn setExceptionPorts(
+ self: MachTask,
+ mask: exception_mask_t,
+ new_port: MachTask,
+ behavior: exception_behavior_t,
+ new_flavor: thread_state_flavor_t,
+ ) !void {
+ switch (getKernError(task_set_exception_ports(
+ self.port,
+ mask,
+ new_port.port,
+ behavior,
+ new_flavor,
+ ))) {
+ .SUCCESS => return,
+ .FAILURE => return error.PermissionDenied,
+ else => |err| return unexpectedKernError(err),
+ }
}
-}
-
-pub const mach_port_t = c_uint;
-pub const clock_serv_t = mach_port_t;
-pub const clock_res_t = c_int;
-pub const mach_port_name_t = natural_t;
-pub const natural_t = c_uint;
-pub const mach_timespec_t = extern struct {
- tv_sec: c_uint,
- tv_nsec: clock_res_t,
-};
-pub const kern_return_t = c_int;
-pub const host_t = mach_port_t;
-pub const integer_t = c_int;
-pub const task_flavor_t = natural_t;
-pub const task_info_t = *integer_t;
-pub const task_name_t = mach_port_name_t;
-pub const vm_address_t = vm_offset_t;
-pub const vm_size_t = mach_vm_size_t;
-pub const vm_machine_attribute_t = usize;
-pub const vm_machine_attribute_val_t = isize;
-
-pub const CALENDAR_CLOCK = 1;
-pub const PATH_MAX = 1024;
-pub const NAME_MAX = 255;
-pub const IOV_MAX = 16;
-
-pub const STDIN_FILENO = 0;
-pub const STDOUT_FILENO = 1;
-pub const STDERR_FILENO = 2;
-
-pub const PROT = struct {
- /// [MC2] no permissions
- pub const NONE: vm_prot_t = 0x00;
- /// [MC2] pages can be read
- pub const READ: vm_prot_t = 0x01;
- /// [MC2] pages can be written
- pub const WRITE: vm_prot_t = 0x02;
- /// [MC2] pages can be executed
- pub const EXEC: vm_prot_t = 0x04;
- /// When a caller finds that they cannot obtain write permission on a
- /// mapped entry, the following flag can be used. The entry will be
- /// made "needs copy" effectively copying the object (using COW),
- /// and write permission will be added to the maximum protections for
- /// the associated entry.
- pub const COPY: vm_prot_t = 0x10;
-};
+ pub const RegionInfo = struct {
+ pub const Tag = enum {
+ basic,
+ extended,
+ top,
+ };
-pub const MSF = struct {
- pub const ASYNC = 0x1;
- pub const INVALIDATE = 0x2;
- // invalidate, leave mapped
- pub const KILLPAGES = 0x4;
- // deactivate, leave mapped
- pub const DEACTIVATE = 0x8;
- pub const SYNC = 0x10;
-};
-
-pub const SA = struct {
- /// take signal on signal stack
- pub const ONSTACK = 0x0001;
- /// restart system on signal return
- pub const RESTART = 0x0002;
- /// reset to SIG.DFL when taking signal
- pub const RESETHAND = 0x0004;
- /// do not generate SIG.CHLD on child stop
- pub const NOCLDSTOP = 0x0008;
- /// don't mask the signal we're delivering
- pub const NODEFER = 0x0010;
- /// don't keep zombies around
- pub const NOCLDWAIT = 0x0020;
- /// signal handler with SIGINFO args
- pub const SIGINFO = 0x0040;
- /// do not bounce off kernel's sigtramp
- pub const USERTRAMP = 0x0100;
- /// signal handler with SIGINFO args with 64bit regs information
- pub const @"64REGSET" = 0x0200;
-};
-
-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 = 0x0;
- pub const CUR = 0x1;
- pub const END = 0x2;
-};
+ base_addr: u64,
+ tag: Tag,
+ info: union {
+ basic: vm_region_basic_info_64,
+ extended: vm_region_extended_info,
+ top: vm_region_top_info,
+ },
+ };
-pub const DT = struct {
- pub const UNKNOWN = 0;
- pub const FIFO = 1;
- pub const CHR = 2;
- pub const DIR = 4;
- pub const BLK = 6;
- pub const REG = 8;
- pub const LNK = 10;
- pub const SOCK = 12;
- pub const WHT = 14;
-};
+ pub fn getRegionInfo(
+ task: MachTask,
+ address: u64,
+ len: usize,
+ tag: RegionInfo.Tag,
+ ) MachError!RegionInfo {
+ var info: RegionInfo = .{
+ .base_addr = address,
+ .tag = tag,
+ .info = undefined,
+ };
+ switch (tag) {
+ .basic => info.info = .{ .basic = undefined },
+ .extended => info.info = .{ .extended = undefined },
+ .top => info.info = .{ .top = undefined },
+ }
+ var base_len: mach_vm_size_t = if (len == 1) 2 else len;
+ var objname: mach_port_t = undefined;
+ var count: mach_msg_type_number_t = switch (tag) {
+ .basic => VM_REGION_BASIC_INFO_COUNT,
+ .extended => VM_REGION_EXTENDED_INFO_COUNT,
+ .top => VM_REGION_TOP_INFO_COUNT,
+ };
+ switch (getKernError(mach_vm_region(
+ task.port,
+ &info.base_addr,
+ &base_len,
+ switch (tag) {
+ .basic => VM_REGION_BASIC_INFO_64,
+ .extended => VM_REGION_EXTENDED_INFO,
+ .top => VM_REGION_TOP_INFO,
+ },
+ switch (tag) {
+ .basic => @as(vm_region_info_t, @ptrCast(&info.info.basic)),
+ .extended => @as(vm_region_info_t, @ptrCast(&info.info.extended)),
+ .top => @as(vm_region_info_t, @ptrCast(&info.info.top)),
+ },
+ &count,
+ &objname,
+ ))) {
+ .SUCCESS => return info,
+ .FAILURE => return error.PermissionDenied,
+ else => |err| return unexpectedKernError(err),
+ }
+ }
-/// no flag value
-pub const KEVENT_FLAG_NONE = 0x000;
+ pub const RegionSubmapInfo = struct {
+ pub const Tag = enum {
+ short,
+ full,
+ };
-/// immediate timeout
-pub const KEVENT_FLAG_IMMEDIATE = 0x001;
+ tag: Tag,
+ base_addr: u64,
+ info: union {
+ short: vm_region_submap_short_info_64,
+ full: vm_region_submap_info_64,
+ },
+ };
-/// output events only include change
-pub const KEVENT_FLAG_ERROR_EVENTS = 0x002;
+ pub fn getRegionSubmapInfo(
+ task: MachTask,
+ address: u64,
+ len: usize,
+ nesting_depth: u32,
+ tag: RegionSubmapInfo.Tag,
+ ) MachError!RegionSubmapInfo {
+ var info: RegionSubmapInfo = .{
+ .base_addr = address,
+ .tag = tag,
+ .info = undefined,
+ };
+ switch (tag) {
+ .short => info.info = .{ .short = undefined },
+ .full => info.info = .{ .full = undefined },
+ }
+ var nesting = nesting_depth;
+ var base_len: mach_vm_size_t = if (len == 1) 2 else len;
+ var count: mach_msg_type_number_t = switch (tag) {
+ .short => VM_REGION_SUBMAP_SHORT_INFO_COUNT_64,
+ .full => VM_REGION_SUBMAP_INFO_COUNT_64,
+ };
+ switch (getKernError(mach_vm_region_recurse(
+ task.port,
+ &info.base_addr,
+ &base_len,
+ &nesting,
+ switch (tag) {
+ .short => @as(vm_region_recurse_info_t, @ptrCast(&info.info.short)),
+ .full => @as(vm_region_recurse_info_t, @ptrCast(&info.info.full)),
+ },
+ &count,
+ ))) {
+ .SUCCESS => return info,
+ .FAILURE => return error.PermissionDenied,
+ else => |err| return unexpectedKernError(err),
+ }
+ }
-/// add event to kq (implies enable)
-pub const EV_ADD = 0x0001;
+ pub fn getCurrProtection(task: MachTask, address: u64, len: usize) MachError!vm_prot_t {
+ const info = try task.getRegionSubmapInfo(address, len, 0, .short);
+ return info.info.short.protection;
+ }
-/// delete event from kq
-pub const EV_DELETE = 0x0002;
+ pub fn setMaxProtection(task: MachTask, address: u64, len: usize, prot: vm_prot_t) MachError!void {
+ return task.setProtectionImpl(address, len, true, prot);
+ }
-/// enable event
-pub const EV_ENABLE = 0x0004;
+ pub fn setCurrProtection(task: MachTask, address: u64, len: usize, prot: vm_prot_t) MachError!void {
+ return task.setProtectionImpl(address, len, false, prot);
+ }
-/// disable event (not reported)
-pub const EV_DISABLE = 0x0008;
+ fn setProtectionImpl(task: MachTask, address: u64, len: usize, set_max: bool, prot: vm_prot_t) MachError!void {
+ switch (getKernError(mach_vm_protect(task.port, address, len, @intFromBool(set_max), prot))) {
+ .SUCCESS => return,
+ .FAILURE => return error.PermissionDenied,
+ else => |err| return unexpectedKernError(err),
+ }
+ }
-/// only report one occurrence
-pub const EV_ONESHOT = 0x0010;
+ /// Will write to VM even if current protection attributes specifically prohibit
+ /// us from doing so, by temporarily setting protection level to a level with VM_PROT_COPY
+ /// variant, and resetting after a successful or unsuccessful write.
+ pub fn writeMemProtected(task: MachTask, address: u64, buf: []const u8, arch: std.Target.Cpu.Arch) MachError!usize {
+ const curr_prot = try task.getCurrProtection(address, buf.len);
+ try task.setCurrProtection(
+ address,
+ buf.len,
+ PROT.READ | PROT.WRITE | PROT.COPY,
+ );
+ defer {
+ task.setCurrProtection(address, buf.len, curr_prot) catch {};
+ }
+ return task.writeMem(address, buf, arch);
+ }
-/// clear event state after reporting
-pub const EV_CLEAR = 0x0020;
+ pub fn writeMem(task: MachTask, address: u64, buf: []const u8, arch: std.Target.Cpu.Arch) MachError!usize {
+ const count = buf.len;
+ var total_written: usize = 0;
+ var curr_addr = address;
+ const page_size = try getPageSize(task); // TODO we probably can assume value here
+ var out_buf = buf[0..];
-/// force immediate event output
-/// ... with or without EV_ERROR
-/// ... use KEVENT_FLAG_ERROR_EVENTS
-/// on syscalls supporting flags
-pub const EV_RECEIPT = 0x0040;
+ while (total_written < count) {
+ const curr_size = maxBytesLeftInPage(page_size, curr_addr, count - total_written);
+ switch (getKernError(mach_vm_write(
+ task.port,
+ curr_addr,
+ @intFromPtr(out_buf.ptr),
+ @as(mach_msg_type_number_t, @intCast(curr_size)),
+ ))) {
+ .SUCCESS => {},
+ .FAILURE => return error.PermissionDenied,
+ else => |err| return unexpectedKernError(err),
+ }
-/// disable event after reporting
-pub const EV_DISPATCH = 0x0080;
+ switch (arch) {
+ .aarch64 => {
+ var mattr_value: vm_machine_attribute_val_t = MATTR_VAL_CACHE_FLUSH;
+ switch (getKernError(vm_machine_attribute(
+ task.port,
+ curr_addr,
+ curr_size,
+ MATTR_CACHE,
+ &mattr_value,
+ ))) {
+ .SUCCESS => {},
+ .FAILURE => return error.PermissionDenied,
+ else => |err| return unexpectedKernError(err),
+ }
+ },
+ .x86_64 => {},
+ else => unreachable,
+ }
-/// unique kevent per udata value
-pub const EV_UDATA_SPECIFIC = 0x0100;
+ out_buf = out_buf[curr_size..];
+ total_written += curr_size;
+ curr_addr += curr_size;
+ }
-/// ... in combination with EV_DELETE
-/// will defer delete until udata-specific
-/// event enabled. EINPROGRESS will be
-/// returned to indicate the deferral
-pub const EV_DISPATCH2 = EV_DISPATCH | EV_UDATA_SPECIFIC;
+ return total_written;
+ }
-/// report that source has vanished
-/// ... only valid with EV_DISPATCH2
-pub const EV_VANISHED = 0x0200;
+ pub fn readMem(task: MachTask, address: u64, buf: []u8) MachError!usize {
+ const count = buf.len;
+ var total_read: usize = 0;
+ var curr_addr = address;
+ const page_size = try getPageSize(task); // TODO we probably can assume value here
+ var out_buf = buf[0..];
-/// reserved by system
-pub const EV_SYSFLAGS = 0xF000;
+ while (total_read < count) {
+ const curr_size = maxBytesLeftInPage(page_size, curr_addr, count - total_read);
+ var curr_bytes_read: mach_msg_type_number_t = 0;
+ var vm_memory: vm_offset_t = undefined;
+ switch (getKernError(mach_vm_read(task.port, curr_addr, curr_size, &vm_memory, &curr_bytes_read))) {
+ .SUCCESS => {},
+ .FAILURE => return error.PermissionDenied,
+ else => |err| return unexpectedKernError(err),
+ }
-/// filter-specific flag
-pub const EV_FLAG0 = 0x1000;
+ @memcpy(out_buf[0..curr_bytes_read], @as([*]const u8, @ptrFromInt(vm_memory)));
+ _ = vm_deallocate(mach_task_self(), vm_memory, curr_bytes_read);
-/// filter-specific flag
-pub const EV_FLAG1 = 0x2000;
+ out_buf = out_buf[curr_bytes_read..];
+ curr_addr += curr_bytes_read;
+ total_read += curr_bytes_read;
+ }
-/// EOF detected
-pub const EV_EOF = 0x8000;
+ return total_read;
+ }
-/// error, data contains errno
-pub const EV_ERROR = 0x4000;
+ fn maxBytesLeftInPage(page_size: usize, address: u64, count: usize) usize {
+ var left = count;
+ if (page_size > 0) {
+ const page_offset = address % page_size;
+ const bytes_left_in_page = page_size - page_offset;
+ if (count > bytes_left_in_page) {
+ left = bytes_left_in_page;
+ }
+ }
+ return left;
+ }
-pub const EV_POLL = EV_FLAG0;
-pub const EV_OOBAND = EV_FLAG1;
+ fn getPageSize(task: MachTask) MachError!usize {
+ if (task.isValid()) {
+ var info_count = TASK_VM_INFO_COUNT;
+ var vm_info: task_vm_info_data_t = undefined;
+ switch (getKernError(task_info(
+ task.port,
+ TASK_VM_INFO,
+ @as(task_info_t, @ptrCast(&vm_info)),
+ &info_count,
+ ))) {
+ .SUCCESS => return @as(usize, @intCast(vm_info.page_size)),
+ else => {},
+ }
+ }
+ var page_size: vm_size_t = undefined;
+ switch (getKernError(_host_page_size(mach_host_self(), &page_size))) {
+ .SUCCESS => return page_size,
+ else => |err| return unexpectedKernError(err),
+ }
+ }
-pub const EVFILT_READ = -1;
-pub const EVFILT_WRITE = -2;
+ pub fn basicTaskInfo(task: MachTask) MachError!mach_task_basic_info {
+ var info: mach_task_basic_info = undefined;
+ var count = MACH_TASK_BASIC_INFO_COUNT;
+ switch (getKernError(task_info(
+ task.port,
+ MACH_TASK_BASIC_INFO,
+ @as(task_info_t, @ptrCast(&info)),
+ &count,
+ ))) {
+ .SUCCESS => return info,
+ else => |err| return unexpectedKernError(err),
+ }
+ }
-/// 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;
-
-/// Mach portsets
-pub const EVFILT_MACHPORT = -8;
-
-/// Filesystem events
-pub const EVFILT_FS = -9;
-
-/// User events
-pub const EVFILT_USER = -10;
-
-/// Virtual memory events
-pub const EVFILT_VM = -12;
-
-/// Exception events
-pub const EVFILT_EXCEPT = -15;
-
-pub const EVFILT_SYSCOUNT = 17;
-
-/// On input, NOTE_TRIGGER causes the event to be triggered for output.
-pub const NOTE_TRIGGER = 0x01000000;
-
-/// ignore input fflags
-pub const NOTE_FFNOP = 0x00000000;
-
-/// and fflags
-pub const NOTE_FFAND = 0x40000000;
-
-/// or fflags
-pub const NOTE_FFOR = 0x80000000;
-
-/// copy fflags
-pub const NOTE_FFCOPY = 0xc0000000;
-
-/// mask for operations
-pub const NOTE_FFCTRLMASK = 0xc0000000;
-pub const NOTE_FFLAGSMASK = 0x00ffffff;
-
-/// low water mark
-pub const NOTE_LOWAT = 0x00000001;
-
-/// OOB data
-pub const NOTE_OOB = 0x00000002;
-
-/// vnode was removed
-pub const NOTE_DELETE = 0x00000001;
-
-/// data contents changed
-pub const NOTE_WRITE = 0x00000002;
-
-/// size increased
-pub const NOTE_EXTEND = 0x00000004;
-
-/// attributes changed
-pub const NOTE_ATTRIB = 0x00000008;
-
-/// link count changed
-pub const NOTE_LINK = 0x00000010;
-
-/// vnode was renamed
-pub const NOTE_RENAME = 0x00000020;
-
-/// vnode access was revoked
-pub const NOTE_REVOKE = 0x00000040;
-
-/// No specific vnode event: to test for EVFILT_READ activation
-pub const NOTE_NONE = 0x00000080;
-
-/// vnode was unlocked by flock(2)
-pub const NOTE_FUNLOCK = 0x00000100;
-
-/// process exited
-pub const NOTE_EXIT = 0x80000000;
-
-/// process forked
-pub const NOTE_FORK = 0x40000000;
-
-/// process exec'd
-pub const NOTE_EXEC = 0x20000000;
+ pub fn @"resume"(task: MachTask) MachError!void {
+ switch (getKernError(task_resume(task.port))) {
+ .SUCCESS => {},
+ else => |err| return unexpectedKernError(err),
+ }
+ }
-/// shared with EVFILT_SIGNAL
-pub const NOTE_SIGNAL = 0x08000000;
+ pub fn @"suspend"(task: MachTask) MachError!void {
+ switch (getKernError(task_suspend(task.port))) {
+ .SUCCESS => {},
+ else => |err| return unexpectedKernError(err),
+ }
+ }
-/// exit status to be returned, valid for child process only
-pub const NOTE_EXITSTATUS = 0x04000000;
+ const ThreadList = struct {
+ buf: []MachThread,
-/// provide details on reasons for exit
-pub const NOTE_EXIT_DETAIL = 0x02000000;
+ pub fn deinit(list: ThreadList) void {
+ const self_task = machTaskForSelf();
+ _ = vm_deallocate(
+ self_task.port,
+ @intFromPtr(list.buf.ptr),
+ @as(vm_size_t, @intCast(list.buf.len * @sizeOf(mach_port_t))),
+ );
+ }
+ };
-/// mask for signal & exit status
-pub const NOTE_PDATAMASK = 0x000fffff;
-pub const NOTE_PCTRLMASK = (~NOTE_PDATAMASK);
+ pub fn getThreads(task: MachTask) MachError!ThreadList {
+ var thread_list: mach_port_array_t = undefined;
+ var thread_count: mach_msg_type_number_t = undefined;
+ switch (getKernError(task_threads(task.port, &thread_list, &thread_count))) {
+ .SUCCESS => return ThreadList{ .buf = @as([*]MachThread, @ptrCast(thread_list))[0..thread_count] },
+ else => |err| return unexpectedKernError(err),
+ }
+ }
+};
-pub const NOTE_EXIT_DETAIL_MASK = 0x00070000;
-pub const NOTE_EXIT_DECRYPTFAIL = 0x00010000;
-pub const NOTE_EXIT_MEMORY = 0x00020000;
-pub const NOTE_EXIT_CSERROR = 0x00040000;
+pub const MachThread = extern struct {
+ port: mach_port_t,
-/// will react on memory pressure
-pub const NOTE_VM_PRESSURE = 0x80000000;
+ pub fn isValid(thread: MachThread) bool {
+ return thread.port != THREAD_NULL;
+ }
-/// will quit on memory pressure, possibly after cleaning up dirty state
-pub const NOTE_VM_PRESSURE_TERMINATE = 0x40000000;
+ pub fn getBasicInfo(thread: MachThread) MachError!thread_basic_info {
+ var info: thread_basic_info = undefined;
+ var count = THREAD_BASIC_INFO_COUNT;
+ switch (getKernError(thread_info(
+ thread.port,
+ THREAD_BASIC_INFO,
+ @as(thread_info_t, @ptrCast(&info)),
+ &count,
+ ))) {
+ .SUCCESS => return info,
+ else => |err| return unexpectedKernError(err),
+ }
+ }
-/// will quit immediately on memory pressure
-pub const NOTE_VM_PRESSURE_SUDDEN_TERMINATE = 0x20000000;
+ pub fn getIdentifierInfo(thread: MachThread) MachError!thread_identifier_info {
+ var info: thread_identifier_info = undefined;
+ var count = THREAD_IDENTIFIER_INFO_COUNT;
+ switch (getKernError(thread_info(
+ thread.port,
+ THREAD_IDENTIFIER_INFO,
+ @as(thread_info_t, @ptrCast(&info)),
+ &count,
+ ))) {
+ .SUCCESS => return info,
+ else => |err| return unexpectedKernError(err),
+ }
+ }
+};
-/// there was an error
-pub const NOTE_VM_ERROR = 0x10000000;
+pub fn machTaskForPid(pid: std.c.pid_t) MachError!MachTask {
+ var port: mach_port_name_t = undefined;
+ switch (getKernError(task_for_pid(mach_task_self(), pid, &port))) {
+ .SUCCESS => {},
+ .FAILURE => return error.PermissionDenied,
+ else => |err| return unexpectedKernError(err),
+ }
+ return MachTask{ .port = port };
+}
-/// data is seconds
-pub const NOTE_SECONDS = 0x00000001;
+pub fn machTaskForSelf() MachTask {
+ return .{ .port = mach_task_self() };
+}
-/// data is microseconds
-pub const NOTE_USECONDS = 0x00000002;
+pub const os_signpost_id_t = u64;
-/// data is nanoseconds
-pub const NOTE_NSECONDS = 0x00000004;
-
-/// absolute timeout
-pub const NOTE_ABSOLUTE = 0x00000008;
-
-/// ext[1] holds leeway for power aware timers
-pub const NOTE_LEEWAY = 0x00000010;
-
-/// system does minimal timer coalescing
-pub const NOTE_CRITICAL = 0x00000020;
-
-/// system does maximum timer coalescing
-pub const NOTE_BACKGROUND = 0x00000040;
-pub const NOTE_MACH_CONTINUOUS_TIME = 0x00000080;
-
-/// data is mach absolute time units
-pub const NOTE_MACHTIME = 0x00000100;
-
-pub const AF = struct {
- pub const UNSPEC = 0;
- pub const LOCAL = 1;
- pub const UNIX = LOCAL;
- pub const INET = 2;
- pub const SYS_CONTROL = 2;
- pub const IMPLINK = 3;
- pub const PUP = 4;
- pub const CHAOS = 5;
- pub const NS = 6;
- pub const ISO = 7;
- pub const OSI = ISO;
- pub const ECMA = 8;
- pub const DATAKIT = 9;
- pub const CCITT = 10;
- pub const SNA = 11;
- pub const DECnet = 12;
- pub const DLI = 13;
- pub const LAT = 14;
- pub const HYLINK = 15;
- pub const APPLETALK = 16;
- pub const ROUTE = 17;
- pub const LINK = 18;
- pub const XTP = 19;
- pub const COIP = 20;
- pub const CNT = 21;
- pub const RTIP = 22;
- pub const IPX = 23;
- pub const SIP = 24;
- pub const PIP = 25;
- pub const ISDN = 28;
- pub const E164 = ISDN;
- pub const KEY = 29;
- pub const INET6 = 30;
- pub const NATM = 31;
- pub const SYSTEM = 32;
- pub const NETBIOS = 33;
- pub const PPP = 34;
- pub const MAX = 40;
-};
+pub const OS_SIGNPOST_ID_NULL: os_signpost_id_t = 0;
+pub const OS_SIGNPOST_ID_INVALID: os_signpost_id_t = !0;
+pub const OS_SIGNPOST_ID_EXCLUSIVE: os_signpost_id_t = 0xeeeeb0b5b2b2eeee;
-pub const PF = struct {
- pub const UNSPEC = AF.UNSPEC;
- pub const LOCAL = AF.LOCAL;
- pub const UNIX = PF.LOCAL;
- pub const INET = AF.INET;
- pub const IMPLINK = AF.IMPLINK;
- pub const PUP = AF.PUP;
- pub const CHAOS = AF.CHAOS;
- pub const NS = AF.NS;
- pub const ISO = AF.ISO;
- pub const OSI = AF.ISO;
- pub const ECMA = AF.ECMA;
- pub const DATAKIT = AF.DATAKIT;
- pub const CCITT = AF.CCITT;
- pub const SNA = AF.SNA;
- pub const DECnet = AF.DECnet;
- pub const DLI = AF.DLI;
- pub const LAT = AF.LAT;
- pub const HYLINK = AF.HYLINK;
- pub const APPLETALK = AF.APPLETALK;
- pub const ROUTE = AF.ROUTE;
- pub const LINK = AF.LINK;
- pub const XTP = AF.XTP;
- pub const COIP = AF.COIP;
- pub const CNT = AF.CNT;
- pub const SIP = AF.SIP;
- pub const IPX = AF.IPX;
- pub const RTIP = AF.RTIP;
- pub const PIP = AF.PIP;
- pub const ISDN = AF.ISDN;
- pub const KEY = AF.KEY;
- pub const INET6 = AF.INET6;
- pub const NATM = AF.NATM;
- pub const SYSTEM = AF.SYSTEM;
- pub const NETBIOS = AF.NETBIOS;
- pub const PPP = AF.PPP;
- pub const MAX = AF.MAX;
+pub const os_log_t = opaque {};
+pub const os_log_type_t = enum(u8) {
+ /// default messages always captures
+ OS_LOG_TYPE_DEFAULT = 0x00,
+ /// messages with additional infos
+ OS_LOG_TYPE_INFO = 0x01,
+ /// debug messages
+ OS_LOG_TYPE_DEBUG = 0x02,
+ /// error messages
+ OS_LOG_TYPE_ERROR = 0x10,
+ /// unexpected conditions messages
+ OS_LOG_TYPE_FAULT = 0x11,
};
-pub const SYSPROTO_EVENT = 1;
-pub const SYSPROTO_CONTROL = 2;
+pub const OS_LOG_CATEGORY_POINTS_OF_INTEREST: *const u8 = "PointsOfInterest";
+pub const OS_LOG_CATEGORY_DYNAMIC_TRACING: *const u8 = "DynamicTracing";
+pub const OS_LOG_CATEGORY_DYNAMIC_STACK_TRACING: *const u8 = "DynamicStackTracing";
-pub const SOCK = struct {
- pub const STREAM = 1;
- pub const DGRAM = 2;
- pub const RAW = 3;
- pub const RDM = 4;
- pub const SEQPACKET = 5;
- pub const MAXADDRLEN = 255;
-
- /// Not actually supported by Darwin, but Zig supplies a shim.
- /// This numerical value is not ABI-stable. It need only not conflict
- /// with any other `SOCK` bits.
- pub const CLOEXEC = 1 << 15;
- /// Not actually supported by Darwin, but Zig supplies a shim.
- /// This numerical value is not ABI-stable. It need only not conflict
- /// with any other `SOCK` bits.
- pub const NONBLOCK = 1 << 16;
-};
+pub extern "c" fn os_log_create(subsystem: [*]const u8, category: [*]const u8) os_log_t;
+pub extern "c" fn os_log_type_enabled(log: os_log_t, tpe: os_log_type_t) bool;
+pub extern "c" fn os_signpost_id_generate(log: os_log_t) os_signpost_id_t;
+pub extern "c" fn os_signpost_interval_begin(log: os_log_t, signpos: os_signpost_id_t, func: [*]const u8, ...) void;
+pub extern "c" fn os_signpost_interval_end(log: os_log_t, signpos: os_signpost_id_t, func: [*]const u8, ...) void;
+pub extern "c" fn os_signpost_id_make_with_pointer(log: os_log_t, ptr: ?*anyopaque) os_signpost_id_t;
+pub extern "c" fn os_signpost_enabled(log: os_log_t) bool;
-pub const IPPROTO = struct {
- pub const ICMP = 1;
- pub const ICMPV6 = 58;
- pub const TCP = 6;
- pub const UDP = 17;
- pub const IP = 0;
- pub const IPV6 = 41;
-};
+pub extern "c" fn pthread_setname_np(name: [*:0]const u8) c_int;
+pub extern "c" fn pthread_attr_set_qos_class_np(attr: *pthread_attr_t, qos_class: qos_class_t, relative_priority: c_int) c_int;
+pub extern "c" fn pthread_attr_get_qos_class_np(attr: *pthread_attr_t, qos_class: *qos_class_t, relative_priority: *c_int) c_int;
+pub extern "c" fn pthread_set_qos_class_self_np(qos_class: qos_class_t, relative_priority: c_int) c_int;
+pub extern "c" fn pthread_get_qos_class_np(pthread: std.c.pthread_t, qos_class: *qos_class_t, relative_priority: *c_int) c_int;
-pub const SOL = struct {
- pub const SOCKET = 0xffff;
+pub const mach_timebase_info_data = extern struct {
+ numer: u32,
+ denom: u32,
};
-pub const SO = struct {
- pub const DEBUG = 0x0001;
- pub const ACCEPTCONN = 0x0002;
- pub const REUSEADDR = 0x0004;
- pub const KEEPALIVE = 0x0008;
- pub const DONTROUTE = 0x0010;
- pub const BROADCAST = 0x0020;
- pub const USELOOPBACK = 0x0040;
- pub const LINGER = 0x1080;
- pub const OOBINLINE = 0x0100;
- pub const REUSEPORT = 0x0200;
- pub const ACCEPTFILTER = 0x1000;
- pub const SNDBUF = 0x1001;
- pub const RCVBUF = 0x1002;
- pub const SNDLOWAT = 0x1003;
- pub const RCVLOWAT = 0x1004;
- pub const SNDTIMEO = 0x1005;
- pub const RCVTIMEO = 0x1006;
- pub const ERROR = 0x1007;
- pub const TYPE = 0x1008;
-
- pub const NREAD = 0x1020;
- pub const NKE = 0x1021;
- pub const NOSIGPIPE = 0x1022;
- pub const NOADDRERR = 0x1023;
- pub const NWRITE = 0x1024;
- pub const REUSESHAREUID = 0x1025;
+pub const kevent64_s = extern struct {
+ ident: u64,
+ filter: i16,
+ flags: u16,
+ fflags: u32,
+ data: i64,
+ udata: u64,
+ ext: [2]u64,
};
-pub const W = struct {
- /// [XSI] no hang in wait/no child to reap
- pub const NOHANG = 0x00000001;
- /// [XSI] notify on stop, untraced child
- pub const UNTRACED = 0x00000002;
-
- pub fn EXITSTATUS(x: u32) u8 {
- return @as(u8, @intCast(x >> 8));
- }
- pub fn TERMSIG(x: u32) u32 {
- return status(x);
- }
- pub fn STOPSIG(x: u32) u32 {
- return x >> 8;
- }
- pub fn IFEXITED(x: u32) bool {
- return status(x) == 0;
- }
- pub fn IFSTOPPED(x: u32) bool {
- return status(x) == stopped and STOPSIG(x) != 0x13;
- }
- pub fn IFSIGNALED(x: u32) bool {
- return status(x) != stopped and status(x) != 0;
+// sys/types.h on macos uses #pragma pack() so these checks are
+// to make sure the struct is laid out the same. These values were
+// produced from C code using the offsetof macro.
+comptime {
+ if (builtin.target.isDarwin()) {
+ assert(@offsetOf(kevent64_s, "ident") == 0);
+ assert(@offsetOf(kevent64_s, "filter") == 8);
+ assert(@offsetOf(kevent64_s, "flags") == 10);
+ assert(@offsetOf(kevent64_s, "fflags") == 12);
+ assert(@offsetOf(kevent64_s, "data") == 16);
+ assert(@offsetOf(kevent64_s, "udata") == 24);
+ assert(@offsetOf(kevent64_s, "ext") == 32);
}
+}
- fn status(x: u32) u32 {
- return x & 0o177;
- }
- const stopped = 0o177;
+pub const clock_serv_t = mach_port_t;
+pub const clock_res_t = c_int;
+pub const mach_port_name_t = natural_t;
+pub const natural_t = c_uint;
+pub const mach_timespec_t = extern struct {
+ sec: c_uint,
+ nsec: clock_res_t,
};
+pub const kern_return_t = c_int;
+pub const host_t = mach_port_t;
+pub const integer_t = c_int;
+pub const task_flavor_t = natural_t;
+pub const task_info_t = *integer_t;
+pub const task_name_t = mach_port_name_t;
+pub const vm_address_t = vm_offset_t;
+pub const vm_size_t = mach_vm_size_t;
+pub const vm_machine_attribute_t = usize;
+pub const vm_machine_attribute_val_t = isize;
-pub const E = enum(u16) {
- /// No error occurred.
- SUCCESS = 0,
-
- /// Operation not permitted
- PERM = 1,
-
- /// No such file or directory
- NOENT = 2,
-
- /// No such process
- SRCH = 3,
-
- /// Interrupted system call
- INTR = 4,
-
- /// Input/output error
- IO = 5,
-
- /// Device not configured
- NXIO = 6,
-
- /// Argument list too long
- @"2BIG" = 7,
-
- /// Exec format error
- NOEXEC = 8,
-
- /// Bad file descriptor
- BADF = 9,
-
- /// No child processes
- CHILD = 10,
-
- /// Resource deadlock avoided
- DEADLK = 11,
-
- /// Cannot allocate memory
- NOMEM = 12,
-
- /// Permission denied
- ACCES = 13,
-
- /// Bad address
- FAULT = 14,
-
- /// Block device required
- NOTBLK = 15,
-
- /// Device / Resource busy
- BUSY = 16,
-
- /// File exists
- EXIST = 17,
-
- /// Cross-device link
- XDEV = 18,
+pub const CALENDAR_CLOCK = 1;
- /// Operation not supported by device
- NODEV = 19,
+/// no flag value
+pub const KEVENT_FLAG_NONE = 0x000;
+/// immediate timeout
+pub const KEVENT_FLAG_IMMEDIATE = 0x001;
+/// output events only include change
+pub const KEVENT_FLAG_ERROR_EVENTS = 0x002;
- /// Not a directory
- NOTDIR = 20,
-
- /// Is a directory
- ISDIR = 21,
-
- /// Invalid argument
- INVAL = 22,
-
- /// Too many open files in system
- NFILE = 23,
-
- /// Too many open files
- MFILE = 24,
-
- /// Inappropriate ioctl for device
- NOTTY = 25,
-
- /// Text file busy
- TXTBSY = 26,
-
- /// File too large
- FBIG = 27,
-
- /// No space left on device
- NOSPC = 28,
-
- /// Illegal seek
- SPIPE = 29,
-
- /// Read-only file system
- ROFS = 30,
-
- /// Too many links
- MLINK = 31,
-
- /// Broken pipe
- PIPE = 32,
-
- // math software
-
- /// Numerical argument out of domain
- DOM = 33,
-
- /// Result too large
- RANGE = 34,
-
- // non-blocking and interrupt i/o
-
- /// Resource temporarily unavailable
- /// This is the same code used for `WOULDBLOCK`.
- AGAIN = 35,
-
- /// Operation now in progress
- INPROGRESS = 36,
-
- /// Operation already in progress
- ALREADY = 37,
-
- // ipc/network software -- argument errors
-
- /// Socket operation on non-socket
- NOTSOCK = 38,
-
- /// Destination address required
- DESTADDRREQ = 39,
-
- /// Message too long
- MSGSIZE = 40,
-
- /// Protocol wrong type for socket
- PROTOTYPE = 41,
-
- /// Protocol not available
- NOPROTOOPT = 42,
-
- /// Protocol not supported
- PROTONOSUPPORT = 43,
-
- /// Socket type not supported
- SOCKTNOSUPPORT = 44,
-
- /// Operation not supported
- /// The same code is used for `NOTSUP`.
- OPNOTSUPP = 45,
-
- /// Protocol family not supported
- PFNOSUPPORT = 46,
-
- /// Address family not supported by protocol family
- AFNOSUPPORT = 47,
-
- /// Address already in use
- ADDRINUSE = 48,
- /// Can't assign requested address
-
- // ipc/network software -- operational errors
- ADDRNOTAVAIL = 49,
-
- /// Network is down
- NETDOWN = 50,
-
- /// Network is unreachable
- NETUNREACH = 51,
-
- /// Network dropped connection on reset
- NETRESET = 52,
-
- /// Software caused connection abort
- CONNABORTED = 53,
-
- /// Connection reset by peer
- CONNRESET = 54,
-
- /// No buffer space available
- NOBUFS = 55,
-
- /// Socket is already connected
- ISCONN = 56,
-
- /// Socket is not connected
- NOTCONN = 57,
-
- /// Can't send after socket shutdown
- SHUTDOWN = 58,
-
- /// Too many references: can't splice
- TOOMANYREFS = 59,
-
- /// Operation timed out
- TIMEDOUT = 60,
-
- /// Connection refused
- CONNREFUSED = 61,
-
- /// Too many levels of symbolic links
- LOOP = 62,
-
- /// File name too long
- NAMETOOLONG = 63,
-
- /// Host is down
- HOSTDOWN = 64,
-
- /// No route to host
- HOSTUNREACH = 65,
- /// Directory not empty
-
- // quotas & mush
- NOTEMPTY = 66,
-
- /// Too many processes
- PROCLIM = 67,
-
- /// Too many users
- USERS = 68,
- /// Disc quota exceeded
-
- // Network File System
- DQUOT = 69,
-
- /// Stale NFS file handle
- STALE = 70,
-
- /// Too many levels of remote in path
- REMOTE = 71,
-
- /// RPC struct is bad
- BADRPC = 72,
-
- /// RPC version wrong
- RPCMISMATCH = 73,
-
- /// RPC prog. not avail
- PROGUNAVAIL = 74,
-
- /// Program version wrong
- PROGMISMATCH = 75,
-
- /// Bad procedure for program
- PROCUNAVAIL = 76,
-
- /// No locks available
- NOLCK = 77,
-
- /// Function not implemented
- NOSYS = 78,
-
- /// Inappropriate file type or format
- FTYPE = 79,
-
- /// Authentication error
- AUTH = 80,
-
- /// Need authenticator
- NEEDAUTH = 81,
-
- // Intelligent device errors
-
- /// Device power is off
- PWROFF = 82,
-
- /// Device error, e.g. paper out
- DEVERR = 83,
-
- /// Value too large to be stored in data type
- OVERFLOW = 84,
-
- // Program loading errors
-
- /// Bad executable
- BADEXEC = 85,
-
- /// Bad CPU type in executable
- BADARCH = 86,
-
- /// Shared library version mismatch
- SHLIBVERS = 87,
-
- /// Malformed Macho file
- BADMACHO = 88,
-
- /// Operation canceled
- CANCELED = 89,
-
- /// Identifier removed
- IDRM = 90,
-
- /// No message of desired type
- NOMSG = 91,
-
- /// Illegal byte sequence
- ILSEQ = 92,
-
- /// Attribute not found
- NOATTR = 93,
-
- /// Bad message
- BADMSG = 94,
-
- /// Reserved
- MULTIHOP = 95,
-
- /// No message available on STREAM
- NODATA = 96,
-
- /// Reserved
- NOLINK = 97,
-
- /// No STREAM resources
- NOSR = 98,
-
- /// Not a STREAM
- NOSTR = 99,
-
- /// Protocol error
- PROTO = 100,
-
- /// STREAM ioctl timeout
- TIME = 101,
-
- /// No such policy registered
- NOPOLICY = 103,
-
- /// State not recoverable
- NOTRECOVERABLE = 104,
-
- /// Previous owner died
- OWNERDEAD = 105,
-
- /// Interface output queue is full
- QFULL = 106,
-
- _,
-};
-
-/// Kernel return values
-pub const KernE = enum(u32) {
- SUCCESS = 0,
-
- /// Specified address is not currently valid
- INVALID_ADDRESS = 1,
-
- /// Specified memory is valid, but does not permit the
- /// required forms of access.
- PROTECTION_FAILURE = 2,
-
- /// The address range specified is already in use, or
- /// no address range of the size specified could be
- /// found.
- NO_SPACE = 3,
-
- /// The function requested was not applicable to this
- /// type of argument, or an argument is invalid
- INVALID_ARGUMENT = 4,
-
- /// The function could not be performed. A catch-all.
- FAILURE = 5,
-
- /// A system resource could not be allocated to fulfill
- /// this request. This failure may not be permanent.
- RESOURCE_SHORTAGE = 6,
-
- /// The task in question does not hold receive rights
- /// for the port argument.
- NOT_RECEIVER = 7,
-
- /// Bogus access restriction.
- NO_ACCESS = 8,
-
- /// During a page fault, the target address refers to a
- /// memory object that has been destroyed. This
- /// failure is permanent.
- MEMORY_FAILURE = 9,
-
- /// During a page fault, the memory object indicated
- /// that the data could not be returned. This failure
- /// may be temporary; future attempts to access this
- /// same data may succeed, as defined by the memory
- /// object.
- MEMORY_ERROR = 10,
-
- /// The receive right is already a member of the portset.
- ALREADY_IN_SET = 11,
-
- /// The receive right is not a member of a port set.
- NOT_IN_SET = 12,
-
- /// The name already denotes a right in the task.
- NAME_EXISTS = 13,
-
- /// The operation was aborted. Ipc code will
- /// catch this and reflect it as a message error.
- ABORTED = 14,
-
- /// The name doesn't denote a right in the task.
- INVALID_NAME = 15,
-
- /// Target task isn't an active task.
- INVALID_TASK = 16,
-
- /// The name denotes a right, but not an appropriate right.
- INVALID_RIGHT = 17,
-
- /// A blatant range error.
- INVALID_VALUE = 18,
-
- /// Operation would overflow limit on user-references.
- UREFS_OVERFLOW = 19,
-
- /// The supplied (port) capability is improper.
- INVALID_CAPABILITY = 20,
-
- /// The task already has send or receive rights
- /// for the port under another name.
- RIGHT_EXISTS = 21,
-
- /// Target host isn't actually a host.
- INVALID_HOST = 22,
-
- /// An attempt was made to supply "precious" data
- /// for memory that is already present in a
- /// memory object.
- MEMORY_PRESENT = 23,
-
- /// A page was requested of a memory manager via
- /// memory_object_data_request for an object using
- /// a MEMORY_OBJECT_COPY_CALL strategy, with the
- /// VM_PROT_WANTS_COPY flag being used to specify
- /// that the page desired is for a copy of the
- /// object, and the memory manager has detected
- /// the page was pushed into a copy of the object
- /// while the kernel was walking the shadow chain
- /// from the copy to the object. This error code
- /// is delivered via memory_object_data_error
- /// and is handled by the kernel (it forces the
- /// kernel to restart the fault). It will not be
- /// seen by users.
- MEMORY_DATA_MOVED = 24,
-
- /// A strategic copy was attempted of an object
- /// upon which a quicker copy is now possible.
- /// The caller should retry the copy using
- /// vm_object_copy_quickly. This error code
- /// is seen only by the kernel.
- MEMORY_RESTART_COPY = 25,
-
- /// An argument applied to assert processor set privilege
- /// was not a processor set control port.
- INVALID_PROCESSOR_SET = 26,
-
- /// The specified scheduling attributes exceed the thread's
- /// limits.
- POLICY_LIMIT = 27,
-
- /// The specified scheduling policy is not currently
- /// enabled for the processor set.
- INVALID_POLICY = 28,
-
- /// The external memory manager failed to initialize the
- /// memory object.
- INVALID_OBJECT = 29,
-
- /// A thread is attempting to wait for an event for which
- /// there is already a waiting thread.
- ALREADY_WAITING = 30,
-
- /// An attempt was made to destroy the default processor
- /// set.
- DEFAULT_SET = 31,
-
- /// An attempt was made to fetch an exception port that is
- /// protected, or to abort a thread while processing a
- /// protected exception.
- EXCEPTION_PROTECTED = 32,
-
- /// A ledger was required but not supplied.
- INVALID_LEDGER = 33,
-
- /// The port was not a memory cache control port.
- INVALID_MEMORY_CONTROL = 34,
-
- /// An argument supplied to assert security privilege
- /// was not a host security port.
- INVALID_SECURITY = 35,
-
- /// thread_depress_abort was called on a thread which
- /// was not currently depressed.
- NOT_DEPRESSED = 36,
-
- /// Object has been terminated and is no longer available
- TERMINATED = 37,
-
- /// Lock set has been destroyed and is no longer available.
- LOCK_SET_DESTROYED = 38,
-
- /// The thread holding the lock terminated before releasing
- /// the lock
- LOCK_UNSTABLE = 39,
-
- /// The lock is already owned by another thread
- LOCK_OWNED = 40,
-
- /// The lock is already owned by the calling thread
- LOCK_OWNED_SELF = 41,
-
- /// Semaphore has been destroyed and is no longer available.
- SEMAPHORE_DESTROYED = 42,
-
- /// Return from RPC indicating the target server was
- /// terminated before it successfully replied
- RPC_SERVER_TERMINATED = 43,
-
- /// Terminate an orphaned activation.
- RPC_TERMINATE_ORPHAN = 44,
-
- /// Allow an orphaned activation to continue executing.
- RPC_CONTINUE_ORPHAN = 45,
-
- /// Empty thread activation (No thread linked to it)
- NOT_SUPPORTED = 46,
-
- /// Remote node down or inaccessible.
- NODE_DOWN = 47,
-
- /// A signalled thread was not actually waiting.
- NOT_WAITING = 48,
-
- /// Some thread-oriented operation (semaphore_wait) timed out
- OPERATION_TIMED_OUT = 49,
-
- /// During a page fault, indicates that the page was rejected
- /// as a result of a signature check.
- CODESIGN_ERROR = 50,
-
- /// The requested property cannot be changed at this time.
- POLICY_STATIC = 51,
-
- /// The provided buffer is of insufficient size for the requested data.
- INSUFFICIENT_BUFFER_SIZE = 52,
-
- /// Denied by security policy
- DENIED = 53,
-
- /// The KC on which the function is operating is missing
- MISSING_KC = 54,
-
- /// The KC on which the function is operating is invalid
- INVALID_KC = 55,
-
- /// A search or query operation did not return a result
- NOT_FOUND = 56,
-
- _,
-};
-
-pub const mach_msg_return_t = kern_return_t;
-
-pub fn getMachMsgError(err: mach_msg_return_t) MachMsgE {
- return @as(MachMsgE, @enumFromInt(@as(u32, @truncate(@as(usize, @intCast(err))))));
-}
-
-/// All special error code bits defined below.
-pub const MACH_MSG_MASK: u32 = 0x3e00;
-/// No room in IPC name space for another capability name.
-pub const MACH_MSG_IPC_SPACE: u32 = 0x2000;
-/// No room in VM address space for out-of-line memory.
-pub const MACH_MSG_VM_SPACE: u32 = 0x1000;
-/// Kernel resource shortage handling out-of-line memory.
-pub const MACH_MSG_IPC_KERNEL: u32 = 0x800;
-/// Kernel resource shortage handling an IPC capability.
-pub const MACH_MSG_VM_KERNEL: u32 = 0x400;
-
-/// Mach msg return values
-pub const MachMsgE = enum(u32) {
- SUCCESS = 0x00000000,
-
- /// Thread is waiting to send. (Internal use only.)
- SEND_IN_PROGRESS = 0x10000001,
- /// Bogus in-line data.
- SEND_INVALID_DATA = 0x10000002,
- /// Bogus destination port.
- SEND_INVALID_DEST = 0x10000003,
- /// Message not sent before timeout expired.
- SEND_TIMED_OUT = 0x10000004,
- /// Bogus voucher port.
- SEND_INVALID_VOUCHER = 0x10000005,
- /// Software interrupt.
- SEND_INTERRUPTED = 0x10000007,
- /// Data doesn't contain a complete message.
- SEND_MSG_TOO_SMALL = 0x10000008,
- /// Bogus reply port.
- SEND_INVALID_REPLY = 0x10000009,
- /// Bogus port rights in the message body.
- SEND_INVALID_RIGHT = 0x1000000a,
- /// Bogus notify port argument.
- SEND_INVALID_NOTIFY = 0x1000000b,
- /// Invalid out-of-line memory pointer.
- SEND_INVALID_MEMORY = 0x1000000c,
- /// No message buffer is available.
- SEND_NO_BUFFER = 0x1000000d,
- /// Send is too large for port
- SEND_TOO_LARGE = 0x1000000e,
- /// Invalid msg-type specification.
- SEND_INVALID_TYPE = 0x1000000f,
- /// A field in the header had a bad value.
- SEND_INVALID_HEADER = 0x10000010,
- /// The trailer to be sent does not match kernel format.
- SEND_INVALID_TRAILER = 0x10000011,
- /// The sending thread context did not match the context on the dest port
- SEND_INVALID_CONTEXT = 0x10000012,
- /// compatibility: no longer a returned error
- SEND_INVALID_RT_OOL_SIZE = 0x10000015,
- /// The destination port doesn't accept ports in body
- SEND_NO_GRANT_DEST = 0x10000016,
- /// Message send was rejected by message filter
- SEND_MSG_FILTERED = 0x10000017,
-
- /// Thread is waiting for receive. (Internal use only.)
- RCV_IN_PROGRESS = 0x10004001,
- /// Bogus name for receive port/port-set.
- RCV_INVALID_NAME = 0x10004002,
- /// Didn't get a message within the timeout value.
- RCV_TIMED_OUT = 0x10004003,
- /// Message buffer is not large enough for inline data.
- RCV_TOO_LARGE = 0x10004004,
- /// Software interrupt.
- RCV_INTERRUPTED = 0x10004005,
- /// compatibility: no longer a returned error
- RCV_PORT_CHANGED = 0x10004006,
- /// Bogus notify port argument.
- RCV_INVALID_NOTIFY = 0x10004007,
- /// Bogus message buffer for inline data.
- RCV_INVALID_DATA = 0x10004008,
- /// Port/set was sent away/died during receive.
- RCV_PORT_DIED = 0x10004009,
- /// compatibility: no longer a returned error
- RCV_IN_SET = 0x1000400a,
- /// Error receiving message header. See special bits.
- RCV_HEADER_ERROR = 0x1000400b,
- /// Error receiving message body. See special bits.
- RCV_BODY_ERROR = 0x1000400c,
- /// Invalid msg-type specification in scatter list.
- RCV_INVALID_TYPE = 0x1000400d,
- /// Out-of-line overwrite region is not large enough
- RCV_SCATTER_SMALL = 0x1000400e,
- /// trailer type or number of trailer elements not supported
- RCV_INVALID_TRAILER = 0x1000400f,
- /// Waiting for receive with timeout. (Internal use only.)
- RCV_IN_PROGRESS_TIMED = 0x10004011,
- /// invalid reply port used in a STRICT_REPLY message
- RCV_INVALID_REPLY = 0x10004012,
-};
-
-pub const SIGSTKSZ = 131072;
-pub const MINSIGSTKSZ = 32768;
-
-pub const SS_ONSTACK = 1;
-pub const SS_DISABLE = 4;
-
-pub const stack_t = extern struct {
- sp: [*]u8,
- size: isize,
- flags: i32,
-};
-
-pub const S = struct {
- pub const IFMT = 0o170000;
-
- pub const IFIFO = 0o010000;
- pub const IFCHR = 0o020000;
- pub const IFDIR = 0o040000;
- pub const IFBLK = 0o060000;
- pub const IFREG = 0o100000;
- pub const IFLNK = 0o120000;
- pub const IFSOCK = 0o140000;
- pub const IFWHT = 0o160000;
-
- 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 ISFIFO(m: u32) bool {
- return m & IFMT == IFIFO;
- }
-
- pub fn ISCHR(m: u32) bool {
- return m & IFMT == IFCHR;
- }
-
- pub fn ISDIR(m: u32) bool {
- return m & IFMT == IFDIR;
- }
-
- pub fn ISBLK(m: u32) bool {
- return m & IFMT == IFBLK;
- }
-
- pub fn ISREG(m: u32) bool {
- return m & IFMT == IFREG;
- }
-
- pub fn ISLNK(m: u32) bool {
- return m & IFMT == IFLNK;
- }
-
- pub fn ISSOCK(m: u32) bool {
- return m & IFMT == IFSOCK;
- }
-
- pub fn IWHT(m: u32) bool {
- return m & IFMT == IFWHT;
- }
-};
-
-pub const HOST_NAME_MAX = 72;
-
-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 RTLD = struct {
- pub const LAZY = 0x1;
- pub const NOW = 0x2;
- pub const LOCAL = 0x4;
- pub const GLOBAL = 0x8;
- pub const NOLOAD = 0x10;
- pub const NODELETE = 0x80;
- pub const FIRST = 0x100;
-
- pub const NEXT = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -1)))));
- pub const DEFAULT = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -2)))));
- pub const SELF = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -3)))));
- pub const MAIN_ONLY = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -5)))));
-};
-
-pub const F = struct {
- /// duplicate file descriptor
- pub const DUPFD = 0;
- /// get file descriptor flags
- pub const GETFD = 1;
- /// set file descriptor flags
- pub const SETFD = 2;
- /// get file status flags
- pub const GETFL = 3;
- /// set file status flags
- pub const SETFL = 4;
- /// get SIGIO/SIGURG proc/pgrp
- pub const GETOWN = 5;
- /// set SIGIO/SIGURG proc/pgrp
- pub const SETOWN = 6;
- /// get record locking information
- pub const GETLK = 7;
- /// set record locking information
- pub const SETLK = 8;
- /// F.SETLK; wait if blocked
- pub const SETLKW = 9;
- /// F.SETLK; wait if blocked, return on timeout
- pub const SETLKWTIMEOUT = 10;
- pub const FLUSH_DATA = 40;
- /// Used for regression test
- pub const CHKCLEAN = 41;
- /// Preallocate storage
- pub const PREALLOCATE = 42;
- /// Truncate a file without zeroing space
- pub const SETSIZE = 43;
- /// Issue an advisory read async with no copy to user
- pub const RDADVISE = 44;
- /// turn read ahead off/on for this fd
- pub const RDAHEAD = 45;
- /// turn data caching off/on for this fd
- pub const NOCACHE = 48;
- /// file offset to device offset
- pub const LOG2PHYS = 49;
- /// return the full path of the fd
- pub const GETPATH = 50;
- /// fsync + ask the drive to flush to the media
- pub const FULLFSYNC = 51;
- /// find which component (if any) is a package
- pub const PATHPKG_CHECK = 52;
- /// "freeze" all fs operations
- pub const FREEZE_FS = 53;
- /// "thaw" all fs operations
- pub const THAW_FS = 54;
- /// turn data caching off/on (globally) for this file
- pub const GLOBAL_NOCACHE = 55;
- /// add detached signatures
- pub const ADDSIGS = 59;
- /// add signature from same file (used by dyld for shared libs)
- pub const ADDFILESIGS = 61;
- /// used in conjunction with F.NOCACHE to indicate that DIRECT, synchronous writes
- /// should not be used (i.e. its ok to temporarily create cached pages)
- pub const NODIRECT = 62;
- ///Get the protection class of a file from the EA, returns int
- pub const GETPROTECTIONCLASS = 63;
- ///Set the protection class of a file for the EA, requires int
- pub const SETPROTECTIONCLASS = 64;
- ///file offset to device offset, extended
- pub const LOG2PHYS_EXT = 65;
- ///get record locking information, per-process
- pub const GETLKPID = 66;
- ///Mark the file as being the backing store for another filesystem
- pub const SETBACKINGSTORE = 70;
- ///return the full path of the FD, but error in specific mtmd circumstances
- pub const GETPATH_MTMINFO = 71;
- ///Returns the code directory, with associated hashes, to the caller
- pub const GETCODEDIR = 72;
- ///No SIGPIPE generated on EPIPE
- pub const SETNOSIGPIPE = 73;
- ///Status of SIGPIPE for this fd
- pub const GETNOSIGPIPE = 74;
- ///For some cases, we need to rewrap the key for AKS/MKB
- pub const TRANSCODEKEY = 75;
- ///file being written to a by single writer... if throttling enabled, writes
- ///may be broken into smaller chunks with throttling in between
- pub const SINGLE_WRITER = 76;
- ///Get the protection version number for this filesystem
- pub const GETPROTECTIONLEVEL = 77;
- ///Add detached code signatures (used by dyld for shared libs)
- pub const FINDSIGS = 78;
- ///Add signature from same file, only if it is signed by Apple (used by dyld for simulator)
- pub const ADDFILESIGS_FOR_DYLD_SIM = 83;
- ///fsync + issue barrier to drive
- pub const BARRIERFSYNC = 85;
- ///Add signature from same file, return end offset in structure on success
- pub const ADDFILESIGS_RETURN = 97;
- ///Check if Library Validation allows this Mach-O file to be mapped into the calling process
- pub const CHECK_LV = 98;
- ///Deallocate a range of the file
- pub const PUNCHHOLE = 99;
- ///Trim an active file
- pub const TRIM_ACTIVE_FILE = 100;
- ///mark the dup with FD_CLOEXEC
- pub const DUPFD_CLOEXEC = 67;
- /// shared or read lock
- pub const RDLCK = 1;
- /// unlock
- pub const UNLCK = 2;
- /// exclusive or write lock
- pub const WRLCK = 3;
-};
-
-pub const FCNTL_FS_SPECIFIC_BASE = 0x00010000;
-
-///close-on-exec flag
-pub const FD_CLOEXEC = 1;
-
-pub const LOCK = struct {
- pub const SH = 1;
- pub const EX = 2;
- pub const UN = 8;
- pub const NB = 4;
-};
-
-pub const nfds_t = u32;
-pub const pollfd = extern struct {
- fd: fd_t,
- events: i16,
- revents: i16,
-};
-
-pub const POLL = struct {
- pub const IN = 0x001;
- pub const PRI = 0x002;
- pub const OUT = 0x004;
- pub const RDNORM = 0x040;
- pub const WRNORM = OUT;
- pub const RDBAND = 0x080;
- pub const WRBAND = 0x100;
-
- pub const EXTEND = 0x0200;
- pub const ATTRIB = 0x0400;
- pub const NLINK = 0x0800;
- pub const WRITE = 0x1000;
-
- pub const ERR = 0x008;
- pub const HUP = 0x010;
- pub const NVAL = 0x020;
-
- pub const STANDARD = IN | PRI | OUT | RDNORM | RDBAND | WRBAND | ERR | HUP | NVAL;
-};
-
-pub const CLOCK = struct {
- pub const REALTIME = 0;
- pub const MONOTONIC = 6;
- pub const MONOTONIC_RAW = 4;
- pub const MONOTONIC_RAW_APPROX = 5;
- pub const UPTIME_RAW = 8;
- pub const UPTIME_RAW_APPROX = 9;
- pub const PROCESS_CPUTIME_ID = 12;
- pub const THREAD_CPUTIME_ID = 16;
-};
-
-/// Max open files per process
-/// https://opensource.apple.com/source/xnu/xnu-4903.221.2/bsd/sys/syslimits.h.auto.html
-pub const OPEN_MAX = 10240;
-
-pub const rusage = extern struct {
- utime: timeval,
- stime: timeval,
- maxrss: isize,
- ixrss: isize,
- idrss: isize,
- isrss: isize,
- minflt: isize,
- majflt: isize,
- nswap: isize,
- inblock: isize,
- oublock: isize,
- msgsnd: isize,
- msgrcv: isize,
- nsignals: isize,
- nvcsw: isize,
- nivcsw: isize,
-
- pub const SELF = 0;
- pub const CHILDREN = -1;
-};
-
-pub const rlimit_resource = enum(c_int) {
- CPU = 0,
- FSIZE = 1,
- DATA = 2,
- STACK = 3,
- CORE = 4,
- RSS = 5,
- MEMLOCK = 6,
- NPROC = 7,
- NOFILE = 8,
- _,
-
- pub const AS: rlimit_resource = .RSS;
-};
-
-pub const rlim_t = u64;
-
-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;
-};
-
-pub const TCSA = enum(c_uint) {
- NOW,
- DRAIN,
- FLUSH,
- _,
-};
-
-pub const winsize = extern struct {
- ws_row: u16,
- ws_col: u16,
- ws_xpixel: u16,
- ws_ypixel: u16,
-};
-
-pub const T = struct {
- pub const IOCGWINSZ = ior(0x40000000, 't', 104, @sizeOf(winsize));
-};
-pub const IOCPARM_MASK = 0x1fff;
-
-fn ior(inout: u32, group: usize, num: usize, len: usize) usize {
- return (inout | ((len & IOCPARM_MASK) << 16) | ((group) << 8) | (num));
-}
-
-// CPU families mapping
-pub const CPUFAMILY = enum(u32) {
- UNKNOWN = 0,
- POWERPC_G3 = 0xcee41549,
- POWERPC_G4 = 0x77c184ae,
- POWERPC_G5 = 0xed76d8aa,
- INTEL_6_13 = 0xaa33392b,
- INTEL_PENRYN = 0x78ea4fbc,
- INTEL_NEHALEM = 0x6b5a4cd2,
- INTEL_WESTMERE = 0x573b5eec,
- INTEL_SANDYBRIDGE = 0x5490b78c,
- INTEL_IVYBRIDGE = 0x1f65e835,
- INTEL_HASWELL = 0x10b282dc,
- INTEL_BROADWELL = 0x582ed09c,
- INTEL_SKYLAKE = 0x37fc219f,
- INTEL_KABYLAKE = 0x0f817246,
- ARM_9 = 0xe73283ae,
- ARM_11 = 0x8ff620d8,
- ARM_XSCALE = 0x53b005f5,
- ARM_12 = 0xbd1b0ae9,
- ARM_13 = 0x0cc90e64,
- ARM_14 = 0x96077ef1,
- ARM_15 = 0xa8511bca,
- ARM_SWIFT = 0x1e2d6381,
- ARM_CYCLONE = 0x37a09642,
- ARM_TYPHOON = 0x2c91a47e,
- ARM_TWISTER = 0x92fb37c8,
- ARM_HURRICANE = 0x67ceee93,
- ARM_MONSOON_MISTRAL = 0xe81e7ef6,
- ARM_VORTEX_TEMPEST = 0x07d34b9f,
- ARM_LIGHTNING_THUNDER = 0x462504d2,
- ARM_FIRESTORM_ICESTORM = 0x1b588bb3,
- ARM_BLIZZARD_AVALANCHE = 0xda33d83d,
- ARM_EVEREST_SAWTOOTH = 0x8765edea,
- _,
-};
-
-pub const PT = struct {
- pub const TRACE_ME = 0;
- pub const READ_I = 1;
- pub const READ_D = 2;
- pub const READ_U = 3;
- pub const WRITE_I = 4;
- pub const WRITE_D = 5;
- pub const WRITE_U = 6;
- pub const CONTINUE = 7;
- pub const KILL = 8;
- pub const STEP = 9;
- pub const DETACH = 11;
- pub const SIGEXC = 12;
- pub const THUPDATE = 13;
- pub const ATTACHEXC = 14;
- pub const FORCEQUOTA = 30;
- pub const DENY_ATTACH = 31;
-};
-
-pub const caddr_t = ?[*]u8;
-
-pub extern "c" fn ptrace(request: c_int, pid: pid_t, addr: caddr_t, data: c_int) c_int;
-
-pub const POSIX_SPAWN = struct {
- pub const RESETIDS = 0x0001;
- pub const SETPGROUP = 0x0002;
- pub const SETSIGDEF = 0x0004;
- pub const SETSIGMASK = 0x0008;
- pub const SETEXEC = 0x0040;
- pub const START_SUSPENDED = 0x0080;
- pub const DISABLE_ASLR = 0x0100;
- pub const SETSID = 0x0400;
- pub const RESLIDE = 0x0800;
- pub const CLOEXEC_DEFAULT = 0x4000;
-};
-
-pub const posix_spawnattr_t = *opaque {};
-pub const posix_spawn_file_actions_t = *opaque {};
-pub extern "c" fn posix_spawnattr_init(attr: *posix_spawnattr_t) c_int;
-pub extern "c" fn posix_spawnattr_destroy(attr: *posix_spawnattr_t) c_int;
-pub extern "c" fn posix_spawnattr_setflags(attr: *posix_spawnattr_t, flags: c_short) c_int;
-pub extern "c" fn posix_spawnattr_getflags(attr: *const posix_spawnattr_t, flags: *c_short) c_int;
-pub extern "c" fn posix_spawn_file_actions_init(actions: *posix_spawn_file_actions_t) c_int;
-pub extern "c" fn posix_spawn_file_actions_destroy(actions: *posix_spawn_file_actions_t) c_int;
-pub extern "c" fn posix_spawn_file_actions_addclose(actions: *posix_spawn_file_actions_t, filedes: fd_t) c_int;
-pub extern "c" fn posix_spawn_file_actions_addopen(
- actions: *posix_spawn_file_actions_t,
- filedes: fd_t,
- path: [*:0]const u8,
- oflag: c_int,
- mode: mode_t,
-) c_int;
-pub extern "c" fn posix_spawn_file_actions_adddup2(
- actions: *posix_spawn_file_actions_t,
- filedes: fd_t,
- newfiledes: fd_t,
-) c_int;
-pub extern "c" fn posix_spawn_file_actions_addinherit_np(actions: *posix_spawn_file_actions_t, filedes: fd_t) c_int;
-pub extern "c" fn posix_spawn_file_actions_addchdir_np(actions: *posix_spawn_file_actions_t, path: [*:0]const u8) c_int;
-pub extern "c" fn posix_spawn_file_actions_addfchdir_np(actions: *posix_spawn_file_actions_t, filedes: fd_t) c_int;
-pub extern "c" fn posix_spawn(
- pid: *pid_t,
- path: [*:0]const u8,
- actions: ?*const posix_spawn_file_actions_t,
- attr: ?*const posix_spawnattr_t,
- argv: [*:null]?[*:0]const u8,
- env: [*:null]?[*:0]const u8,
-) c_int;
-pub extern "c" fn posix_spawnp(
- pid: *pid_t,
- path: [*:0]const u8,
- actions: ?*const posix_spawn_file_actions_t,
- attr: ?*const posix_spawnattr_t,
- argv: [*:null]?[*:0]const u8,
- env: [*:null]?[*:0]const u8,
-) c_int;
-
-pub fn getKernError(err: kern_return_t) KernE {
- return @as(KernE, @enumFromInt(@as(u32, @truncate(@as(usize, @intCast(err))))));
-}
-
-pub fn unexpectedKernError(err: KernE) std.posix.UnexpectedError {
- if (std.posix.unexpected_error_tracing) {
- std.debug.print("unexpected error: {d}\n", .{@intFromEnum(err)});
- std.debug.dumpCurrentStackTrace(null);
- }
- return error.Unexpected;
-}
-
-pub const MachError = error{
- /// Not enough permissions held to perform the requested kernel
- /// call.
- PermissionDenied,
-} || std.posix.UnexpectedError;
-
-pub const MachTask = extern struct {
- port: mach_port_name_t,
-
- pub fn isValid(self: MachTask) bool {
- return self.port != TASK_NULL;
- }
-
- pub fn pidForTask(self: MachTask) MachError!std.c.pid_t {
- var pid: std.c.pid_t = undefined;
- switch (getKernError(pid_for_task(self.port, &pid))) {
- .SUCCESS => return pid,
- .FAILURE => return error.PermissionDenied,
- else => |err| return unexpectedKernError(err),
- }
- }
-
- pub fn allocatePort(self: MachTask, right: MACH_PORT_RIGHT) MachError!MachTask {
- var out_port: mach_port_name_t = undefined;
- switch (getKernError(mach_port_allocate(
- self.port,
- @intFromEnum(right),
- &out_port,
- ))) {
- .SUCCESS => return .{ .port = out_port },
- .FAILURE => return error.PermissionDenied,
- else => |err| return unexpectedKernError(err),
- }
- }
-
- pub fn deallocatePort(self: MachTask, port: MachTask) void {
- _ = getKernError(mach_port_deallocate(self.port, port.port));
- }
-
- pub fn insertRight(self: MachTask, port: MachTask, msg: MACH_MSG_TYPE) !void {
- switch (getKernError(mach_port_insert_right(
- self.port,
- port.port,
- port.port,
- @intFromEnum(msg),
- ))) {
- .SUCCESS => return,
- .FAILURE => return error.PermissionDenied,
- else => |err| return unexpectedKernError(err),
- }
- }
-
- pub const PortInfo = struct {
- mask: exception_mask_t,
- masks: [EXC_TYPES_COUNT]exception_mask_t,
- ports: [EXC_TYPES_COUNT]mach_port_t,
- behaviors: [EXC_TYPES_COUNT]exception_behavior_t,
- flavors: [EXC_TYPES_COUNT]thread_state_flavor_t,
- count: mach_msg_type_number_t,
- };
-
- pub fn getExceptionPorts(self: MachTask, mask: exception_mask_t) !PortInfo {
- var info = PortInfo{
- .mask = mask,
- .masks = undefined,
- .ports = undefined,
- .behaviors = undefined,
- .flavors = undefined,
- .count = 0,
- };
- info.count = info.ports.len / @sizeOf(mach_port_t);
-
- switch (getKernError(task_get_exception_ports(
- self.port,
- info.mask,
- &info.masks,
- &info.count,
- &info.ports,
- &info.behaviors,
- &info.flavors,
- ))) {
- .SUCCESS => return info,
- .FAILURE => return error.PermissionDenied,
- else => |err| return unexpectedKernError(err),
- }
- }
-
- pub fn setExceptionPorts(
- self: MachTask,
- mask: exception_mask_t,
- new_port: MachTask,
- behavior: exception_behavior_t,
- new_flavor: thread_state_flavor_t,
- ) !void {
- switch (getKernError(task_set_exception_ports(
- self.port,
- mask,
- new_port.port,
- behavior,
- new_flavor,
- ))) {
- .SUCCESS => return,
- .FAILURE => return error.PermissionDenied,
- else => |err| return unexpectedKernError(err),
- }
- }
-
- pub const RegionInfo = struct {
- pub const Tag = enum {
- basic,
- extended,
- top,
- };
-
- base_addr: u64,
- tag: Tag,
- info: union {
- basic: vm_region_basic_info_64,
- extended: vm_region_extended_info,
- top: vm_region_top_info,
- },
- };
-
- pub fn getRegionInfo(
- task: MachTask,
- address: u64,
- len: usize,
- tag: RegionInfo.Tag,
- ) MachError!RegionInfo {
- var info: RegionInfo = .{
- .base_addr = address,
- .tag = tag,
- .info = undefined,
- };
- switch (tag) {
- .basic => info.info = .{ .basic = undefined },
- .extended => info.info = .{ .extended = undefined },
- .top => info.info = .{ .top = undefined },
- }
- var base_len: mach_vm_size_t = if (len == 1) 2 else len;
- var objname: mach_port_t = undefined;
- var count: mach_msg_type_number_t = switch (tag) {
- .basic => VM_REGION_BASIC_INFO_COUNT,
- .extended => VM_REGION_EXTENDED_INFO_COUNT,
- .top => VM_REGION_TOP_INFO_COUNT,
- };
- switch (getKernError(mach_vm_region(
- task.port,
- &info.base_addr,
- &base_len,
- switch (tag) {
- .basic => VM_REGION_BASIC_INFO_64,
- .extended => VM_REGION_EXTENDED_INFO,
- .top => VM_REGION_TOP_INFO,
- },
- switch (tag) {
- .basic => @as(vm_region_info_t, @ptrCast(&info.info.basic)),
- .extended => @as(vm_region_info_t, @ptrCast(&info.info.extended)),
- .top => @as(vm_region_info_t, @ptrCast(&info.info.top)),
- },
- &count,
- &objname,
- ))) {
- .SUCCESS => return info,
- .FAILURE => return error.PermissionDenied,
- else => |err| return unexpectedKernError(err),
- }
- }
-
- pub const RegionSubmapInfo = struct {
- pub const Tag = enum {
- short,
- full,
- };
-
- tag: Tag,
- base_addr: u64,
- info: union {
- short: vm_region_submap_short_info_64,
- full: vm_region_submap_info_64,
- },
- };
-
- pub fn getRegionSubmapInfo(
- task: MachTask,
- address: u64,
- len: usize,
- nesting_depth: u32,
- tag: RegionSubmapInfo.Tag,
- ) MachError!RegionSubmapInfo {
- var info: RegionSubmapInfo = .{
- .base_addr = address,
- .tag = tag,
- .info = undefined,
- };
- switch (tag) {
- .short => info.info = .{ .short = undefined },
- .full => info.info = .{ .full = undefined },
- }
- var nesting = nesting_depth;
- var base_len: mach_vm_size_t = if (len == 1) 2 else len;
- var count: mach_msg_type_number_t = switch (tag) {
- .short => VM_REGION_SUBMAP_SHORT_INFO_COUNT_64,
- .full => VM_REGION_SUBMAP_INFO_COUNT_64,
- };
- switch (getKernError(mach_vm_region_recurse(
- task.port,
- &info.base_addr,
- &base_len,
- &nesting,
- switch (tag) {
- .short => @as(vm_region_recurse_info_t, @ptrCast(&info.info.short)),
- .full => @as(vm_region_recurse_info_t, @ptrCast(&info.info.full)),
- },
- &count,
- ))) {
- .SUCCESS => return info,
- .FAILURE => return error.PermissionDenied,
- else => |err| return unexpectedKernError(err),
- }
- }
-
- pub fn getCurrProtection(task: MachTask, address: u64, len: usize) MachError!vm_prot_t {
- const info = try task.getRegionSubmapInfo(address, len, 0, .short);
- return info.info.short.protection;
- }
-
- pub fn setMaxProtection(task: MachTask, address: u64, len: usize, prot: vm_prot_t) MachError!void {
- return task.setProtectionImpl(address, len, true, prot);
- }
-
- pub fn setCurrProtection(task: MachTask, address: u64, len: usize, prot: vm_prot_t) MachError!void {
- return task.setProtectionImpl(address, len, false, prot);
- }
-
- fn setProtectionImpl(task: MachTask, address: u64, len: usize, set_max: bool, prot: vm_prot_t) MachError!void {
- switch (getKernError(mach_vm_protect(task.port, address, len, @intFromBool(set_max), prot))) {
- .SUCCESS => return,
- .FAILURE => return error.PermissionDenied,
- else => |err| return unexpectedKernError(err),
- }
- }
-
- /// Will write to VM even if current protection attributes specifically prohibit
- /// us from doing so, by temporarily setting protection level to a level with VM_PROT_COPY
- /// variant, and resetting after a successful or unsuccessful write.
- pub fn writeMemProtected(task: MachTask, address: u64, buf: []const u8, arch: std.Target.Cpu.Arch) MachError!usize {
- const curr_prot = try task.getCurrProtection(address, buf.len);
- try task.setCurrProtection(
- address,
- buf.len,
- PROT.READ | PROT.WRITE | PROT.COPY,
- );
- defer {
- task.setCurrProtection(address, buf.len, curr_prot) catch {};
- }
- return task.writeMem(address, buf, arch);
- }
-
- pub fn writeMem(task: MachTask, address: u64, buf: []const u8, arch: std.Target.Cpu.Arch) MachError!usize {
- const count = buf.len;
- var total_written: usize = 0;
- var curr_addr = address;
- const page_size = try getPageSize(task); // TODO we probably can assume value here
- var out_buf = buf[0..];
-
- while (total_written < count) {
- const curr_size = maxBytesLeftInPage(page_size, curr_addr, count - total_written);
- switch (getKernError(mach_vm_write(
- task.port,
- curr_addr,
- @intFromPtr(out_buf.ptr),
- @as(mach_msg_type_number_t, @intCast(curr_size)),
- ))) {
- .SUCCESS => {},
- .FAILURE => return error.PermissionDenied,
- else => |err| return unexpectedKernError(err),
- }
-
- switch (arch) {
- .aarch64 => {
- var mattr_value: vm_machine_attribute_val_t = MATTR_VAL_CACHE_FLUSH;
- switch (getKernError(vm_machine_attribute(
- task.port,
- curr_addr,
- curr_size,
- MATTR_CACHE,
- &mattr_value,
- ))) {
- .SUCCESS => {},
- .FAILURE => return error.PermissionDenied,
- else => |err| return unexpectedKernError(err),
- }
- },
- .x86_64 => {},
- else => unreachable,
- }
-
- out_buf = out_buf[curr_size..];
- total_written += curr_size;
- curr_addr += curr_size;
- }
-
- return total_written;
- }
-
- pub fn readMem(task: MachTask, address: u64, buf: []u8) MachError!usize {
- const count = buf.len;
- var total_read: usize = 0;
- var curr_addr = address;
- const page_size = try getPageSize(task); // TODO we probably can assume value here
- var out_buf = buf[0..];
-
- while (total_read < count) {
- const curr_size = maxBytesLeftInPage(page_size, curr_addr, count - total_read);
- var curr_bytes_read: mach_msg_type_number_t = 0;
- var vm_memory: vm_offset_t = undefined;
- switch (getKernError(mach_vm_read(task.port, curr_addr, curr_size, &vm_memory, &curr_bytes_read))) {
- .SUCCESS => {},
- .FAILURE => return error.PermissionDenied,
- else => |err| return unexpectedKernError(err),
- }
-
- @memcpy(out_buf[0..curr_bytes_read], @as([*]const u8, @ptrFromInt(vm_memory)));
- _ = vm_deallocate(mach_task_self(), vm_memory, curr_bytes_read);
+pub const SYSPROTO_EVENT = 1;
+pub const SYSPROTO_CONTROL = 2;
+/// Kernel return values
+pub const KernE = enum(u32) {
+ SUCCESS = 0,
+ /// Specified address is not currently valid
+ INVALID_ADDRESS = 1,
+ /// Specified memory is valid, but does not permit the
+ /// required forms of access.
+ PROTECTION_FAILURE = 2,
+ /// The address range specified is already in use, or
+ /// no address range of the size specified could be
+ /// found.
+ NO_SPACE = 3,
+ /// The function requested was not applicable to this
+ /// type of argument, or an argument is invalid
+ INVALID_ARGUMENT = 4,
+ /// The function could not be performed. A catch-all.
+ FAILURE = 5,
+ /// A system resource could not be allocated to fulfill
+ /// this request. This failure may not be permanent.
+ RESOURCE_SHORTAGE = 6,
+ /// The task in question does not hold receive rights
+ /// for the port argument.
+ NOT_RECEIVER = 7,
+ /// Bogus access restriction.
+ NO_ACCESS = 8,
+ /// During a page fault, the target address refers to a
+ /// memory object that has been destroyed. This
+ /// failure is permanent.
+ MEMORY_FAILURE = 9,
+ /// During a page fault, the memory object indicated
+ /// that the data could not be returned. This failure
+ /// may be temporary; future attempts to access this
+ /// same data may succeed, as defined by the memory
+ /// object.
+ MEMORY_ERROR = 10,
+ /// The receive right is already a member of the portset.
+ ALREADY_IN_SET = 11,
+ /// The receive right is not a member of a port set.
+ NOT_IN_SET = 12,
+ /// The name already denotes a right in the task.
+ NAME_EXISTS = 13,
+ /// The operation was aborted. Ipc code will
+ /// catch this and reflect it as a message error.
+ ABORTED = 14,
+ /// The name doesn't denote a right in the task.
+ INVALID_NAME = 15,
+ /// Target task isn't an active task.
+ INVALID_TASK = 16,
+ /// The name denotes a right, but not an appropriate right.
+ INVALID_RIGHT = 17,
+ /// A blatant range error.
+ INVALID_VALUE = 18,
+ /// Operation would overflow limit on user-references.
+ UREFS_OVERFLOW = 19,
+ /// The supplied (port) capability is improper.
+ INVALID_CAPABILITY = 20,
+ /// The task already has send or receive rights
+ /// for the port under another name.
+ RIGHT_EXISTS = 21,
+ /// Target host isn't actually a host.
+ INVALID_HOST = 22,
+ /// An attempt was made to supply "precious" data
+ /// for memory that is already present in a
+ /// memory object.
+ MEMORY_PRESENT = 23,
+ /// A page was requested of a memory manager via
+ /// memory_object_data_request for an object using
+ /// a MEMORY_OBJECT_COPY_CALL strategy, with the
+ /// VM_PROT_WANTS_COPY flag being used to specify
+ /// that the page desired is for a copy of the
+ /// object, and the memory manager has detected
+ /// the page was pushed into a copy of the object
+ /// while the kernel was walking the shadow chain
+ /// from the copy to the object. This error code
+ /// is delivered via memory_object_data_error
+ /// and is handled by the kernel (it forces the
+ /// kernel to restart the fault). It will not be
+ /// seen by users.
+ MEMORY_DATA_MOVED = 24,
+ /// A strategic copy was attempted of an object
+ /// upon which a quicker copy is now possible.
+ /// The caller should retry the copy using
+ /// vm_object_copy_quickly. This error code
+ /// is seen only by the kernel.
+ MEMORY_RESTART_COPY = 25,
+ /// An argument applied to assert processor set privilege
+ /// was not a processor set control port.
+ INVALID_PROCESSOR_SET = 26,
+ /// The specified scheduling attributes exceed the thread's
+ /// limits.
+ POLICY_LIMIT = 27,
+ /// The specified scheduling policy is not currently
+ /// enabled for the processor set.
+ INVALID_POLICY = 28,
+ /// The external memory manager failed to initialize the
+ /// memory object.
+ INVALID_OBJECT = 29,
+ /// A thread is attempting to wait for an event for which
+ /// there is already a waiting thread.
+ ALREADY_WAITING = 30,
+ /// An attempt was made to destroy the default processor
+ /// set.
+ DEFAULT_SET = 31,
+ /// An attempt was made to fetch an exception port that is
+ /// protected, or to abort a thread while processing a
+ /// protected exception.
+ EXCEPTION_PROTECTED = 32,
+ /// A ledger was required but not supplied.
+ INVALID_LEDGER = 33,
+ /// The port was not a memory cache control port.
+ INVALID_MEMORY_CONTROL = 34,
+ /// An argument supplied to assert security privilege
+ /// was not a host security port.
+ INVALID_SECURITY = 35,
+ /// thread_depress_abort was called on a thread which
+ /// was not currently depressed.
+ NOT_DEPRESSED = 36,
+ /// Object has been terminated and is no longer available
+ TERMINATED = 37,
+ /// Lock set has been destroyed and is no longer available.
+ LOCK_SET_DESTROYED = 38,
+ /// The thread holding the lock terminated before releasing
+ /// the lock
+ LOCK_UNSTABLE = 39,
+ /// The lock is already owned by another thread
+ LOCK_OWNED = 40,
+ /// The lock is already owned by the calling thread
+ LOCK_OWNED_SELF = 41,
+ /// Semaphore has been destroyed and is no longer available.
+ SEMAPHORE_DESTROYED = 42,
+ /// Return from RPC indicating the target server was
+ /// terminated before it successfully replied
+ RPC_SERVER_TERMINATED = 43,
+ /// Terminate an orphaned activation.
+ RPC_TERMINATE_ORPHAN = 44,
+ /// Allow an orphaned activation to continue executing.
+ RPC_CONTINUE_ORPHAN = 45,
+ /// Empty thread activation (No thread linked to it)
+ NOT_SUPPORTED = 46,
+ /// Remote node down or inaccessible.
+ NODE_DOWN = 47,
+ /// A signalled thread was not actually waiting.
+ NOT_WAITING = 48,
+ /// Some thread-oriented operation (semaphore_wait) timed out
+ OPERATION_TIMED_OUT = 49,
+ /// During a page fault, indicates that the page was rejected
+ /// as a result of a signature check.
+ CODESIGN_ERROR = 50,
+ /// The requested property cannot be changed at this time.
+ POLICY_STATIC = 51,
+ /// The provided buffer is of insufficient size for the requested data.
+ INSUFFICIENT_BUFFER_SIZE = 52,
+ /// Denied by security policy
+ DENIED = 53,
+ /// The KC on which the function is operating is missing
+ MISSING_KC = 54,
+ /// The KC on which the function is operating is invalid
+ INVALID_KC = 55,
+ /// A search or query operation did not return a result
+ NOT_FOUND = 56,
+ _,
+};
- out_buf = out_buf[curr_bytes_read..];
- curr_addr += curr_bytes_read;
- total_read += curr_bytes_read;
- }
+pub const mach_msg_return_t = kern_return_t;
- return total_read;
- }
+pub fn getMachMsgError(err: mach_msg_return_t) MachMsgE {
+ return @as(MachMsgE, @enumFromInt(@as(u32, @truncate(@as(usize, @intCast(err))))));
+}
- fn maxBytesLeftInPage(page_size: usize, address: u64, count: usize) usize {
- var left = count;
- if (page_size > 0) {
- const page_offset = address % page_size;
- const bytes_left_in_page = page_size - page_offset;
- if (count > bytes_left_in_page) {
- left = bytes_left_in_page;
- }
- }
- return left;
- }
+/// All special error code bits defined below.
+pub const MACH_MSG_MASK: u32 = 0x3e00;
+/// No room in IPC name space for another capability name.
+pub const MACH_MSG_IPC_SPACE: u32 = 0x2000;
+/// No room in VM address space for out-of-line memory.
+pub const MACH_MSG_VM_SPACE: u32 = 0x1000;
+/// Kernel resource shortage handling out-of-line memory.
+pub const MACH_MSG_IPC_KERNEL: u32 = 0x800;
+/// Kernel resource shortage handling an IPC capability.
+pub const MACH_MSG_VM_KERNEL: u32 = 0x400;
- fn getPageSize(task: MachTask) MachError!usize {
- if (task.isValid()) {
- var info_count = TASK_VM_INFO_COUNT;
- var vm_info: task_vm_info_data_t = undefined;
- switch (getKernError(task_info(
- task.port,
- TASK_VM_INFO,
- @as(task_info_t, @ptrCast(&vm_info)),
- &info_count,
- ))) {
- .SUCCESS => return @as(usize, @intCast(vm_info.page_size)),
- else => {},
- }
- }
- var page_size: vm_size_t = undefined;
- switch (getKernError(_host_page_size(mach_host_self(), &page_size))) {
- .SUCCESS => return page_size,
- else => |err| return unexpectedKernError(err),
- }
- }
+/// Mach msg return values
+pub const MachMsgE = enum(u32) {
+ SUCCESS = 0x00000000,
- pub fn basicTaskInfo(task: MachTask) MachError!mach_task_basic_info {
- var info: mach_task_basic_info = undefined;
- var count = MACH_TASK_BASIC_INFO_COUNT;
- switch (getKernError(task_info(
- task.port,
- MACH_TASK_BASIC_INFO,
- @as(task_info_t, @ptrCast(&info)),
- &count,
- ))) {
- .SUCCESS => return info,
- else => |err| return unexpectedKernError(err),
- }
- }
+ /// Thread is waiting to send. (Internal use only.)
+ SEND_IN_PROGRESS = 0x10000001,
+ /// Bogus in-line data.
+ SEND_INVALID_DATA = 0x10000002,
+ /// Bogus destination port.
+ SEND_INVALID_DEST = 0x10000003,
+ /// Message not sent before timeout expired.
+ SEND_TIMED_OUT = 0x10000004,
+ /// Bogus voucher port.
+ SEND_INVALID_VOUCHER = 0x10000005,
+ /// Software interrupt.
+ SEND_INTERRUPTED = 0x10000007,
+ /// Data doesn't contain a complete message.
+ SEND_MSG_TOO_SMALL = 0x10000008,
+ /// Bogus reply port.
+ SEND_INVALID_REPLY = 0x10000009,
+ /// Bogus port rights in the message body.
+ SEND_INVALID_RIGHT = 0x1000000a,
+ /// Bogus notify port argument.
+ SEND_INVALID_NOTIFY = 0x1000000b,
+ /// Invalid out-of-line memory pointer.
+ SEND_INVALID_MEMORY = 0x1000000c,
+ /// No message buffer is available.
+ SEND_NO_BUFFER = 0x1000000d,
+ /// Send is too large for port
+ SEND_TOO_LARGE = 0x1000000e,
+ /// Invalid msg-type specification.
+ SEND_INVALID_TYPE = 0x1000000f,
+ /// A field in the header had a bad value.
+ SEND_INVALID_HEADER = 0x10000010,
+ /// The trailer to be sent does not match kernel format.
+ SEND_INVALID_TRAILER = 0x10000011,
+ /// The sending thread context did not match the context on the dest port
+ SEND_INVALID_CONTEXT = 0x10000012,
+ /// compatibility: no longer a returned error
+ SEND_INVALID_RT_OOL_SIZE = 0x10000015,
+ /// The destination port doesn't accept ports in body
+ SEND_NO_GRANT_DEST = 0x10000016,
+ /// Message send was rejected by message filter
+ SEND_MSG_FILTERED = 0x10000017,
- pub fn @"resume"(task: MachTask) MachError!void {
- switch (getKernError(task_resume(task.port))) {
- .SUCCESS => {},
- else => |err| return unexpectedKernError(err),
- }
- }
+ /// Thread is waiting for receive. (Internal use only.)
+ RCV_IN_PROGRESS = 0x10004001,
+ /// Bogus name for receive port/port-set.
+ RCV_INVALID_NAME = 0x10004002,
+ /// Didn't get a message within the timeout value.
+ RCV_TIMED_OUT = 0x10004003,
+ /// Message buffer is not large enough for inline data.
+ RCV_TOO_LARGE = 0x10004004,
+ /// Software interrupt.
+ RCV_INTERRUPTED = 0x10004005,
+ /// compatibility: no longer a returned error
+ RCV_PORT_CHANGED = 0x10004006,
+ /// Bogus notify port argument.
+ RCV_INVALID_NOTIFY = 0x10004007,
+ /// Bogus message buffer for inline data.
+ RCV_INVALID_DATA = 0x10004008,
+ /// Port/set was sent away/died during receive.
+ RCV_PORT_DIED = 0x10004009,
+ /// compatibility: no longer a returned error
+ RCV_IN_SET = 0x1000400a,
+ /// Error receiving message header. See special bits.
+ RCV_HEADER_ERROR = 0x1000400b,
+ /// Error receiving message body. See special bits.
+ RCV_BODY_ERROR = 0x1000400c,
+ /// Invalid msg-type specification in scatter list.
+ RCV_INVALID_TYPE = 0x1000400d,
+ /// Out-of-line overwrite region is not large enough
+ RCV_SCATTER_SMALL = 0x1000400e,
+ /// trailer type or number of trailer elements not supported
+ RCV_INVALID_TRAILER = 0x1000400f,
+ /// Waiting for receive with timeout. (Internal use only.)
+ RCV_IN_PROGRESS_TIMED = 0x10004011,
+ /// invalid reply port used in a STRICT_REPLY message
+ RCV_INVALID_REPLY = 0x10004012,
+};
- pub fn @"suspend"(task: MachTask) MachError!void {
- switch (getKernError(task_suspend(task.port))) {
- .SUCCESS => {},
- else => |err| return unexpectedKernError(err),
- }
- }
+pub const FCNTL_FS_SPECIFIC_BASE = 0x00010000;
- const ThreadList = struct {
- buf: []MachThread,
+/// Max open files per process
+/// https://opensource.apple.com/source/xnu/xnu-4903.221.2/bsd/sys/syslimits.h.auto.html
+pub const OPEN_MAX = 10240;
- pub fn deinit(list: ThreadList) void {
- const self_task = machTaskForSelf();
- _ = vm_deallocate(
- self_task.port,
- @intFromPtr(list.buf.ptr),
- @as(vm_size_t, @intCast(list.buf.len * @sizeOf(mach_port_t))),
- );
- }
- };
+// CPU families mapping
+pub const CPUFAMILY = enum(u32) {
+ UNKNOWN = 0,
+ POWERPC_G3 = 0xcee41549,
+ POWERPC_G4 = 0x77c184ae,
+ POWERPC_G5 = 0xed76d8aa,
+ INTEL_6_13 = 0xaa33392b,
+ INTEL_PENRYN = 0x78ea4fbc,
+ INTEL_NEHALEM = 0x6b5a4cd2,
+ INTEL_WESTMERE = 0x573b5eec,
+ INTEL_SANDYBRIDGE = 0x5490b78c,
+ INTEL_IVYBRIDGE = 0x1f65e835,
+ INTEL_HASWELL = 0x10b282dc,
+ INTEL_BROADWELL = 0x582ed09c,
+ INTEL_SKYLAKE = 0x37fc219f,
+ INTEL_KABYLAKE = 0x0f817246,
+ ARM_9 = 0xe73283ae,
+ ARM_11 = 0x8ff620d8,
+ ARM_XSCALE = 0x53b005f5,
+ ARM_12 = 0xbd1b0ae9,
+ ARM_13 = 0x0cc90e64,
+ ARM_14 = 0x96077ef1,
+ ARM_15 = 0xa8511bca,
+ ARM_SWIFT = 0x1e2d6381,
+ ARM_CYCLONE = 0x37a09642,
+ ARM_TYPHOON = 0x2c91a47e,
+ ARM_TWISTER = 0x92fb37c8,
+ ARM_HURRICANE = 0x67ceee93,
+ ARM_MONSOON_MISTRAL = 0xe81e7ef6,
+ ARM_VORTEX_TEMPEST = 0x07d34b9f,
+ ARM_LIGHTNING_THUNDER = 0x462504d2,
+ ARM_FIRESTORM_ICESTORM = 0x1b588bb3,
+ ARM_BLIZZARD_AVALANCHE = 0xda33d83d,
+ ARM_EVEREST_SAWTOOTH = 0x8765edea,
+ _,
+};
- pub fn getThreads(task: MachTask) MachError!ThreadList {
- var thread_list: mach_port_array_t = undefined;
- var thread_count: mach_msg_type_number_t = undefined;
- switch (getKernError(task_threads(task.port, &thread_list, &thread_count))) {
- .SUCCESS => return ThreadList{ .buf = @as([*]MachThread, @ptrCast(thread_list))[0..thread_count] },
- else => |err| return unexpectedKernError(err),
- }
- }
+pub const PT = struct {
+ pub const TRACE_ME = 0;
+ pub const READ_I = 1;
+ pub const READ_D = 2;
+ pub const READ_U = 3;
+ pub const WRITE_I = 4;
+ pub const WRITE_D = 5;
+ pub const WRITE_U = 6;
+ pub const CONTINUE = 7;
+ pub const KILL = 8;
+ pub const STEP = 9;
+ pub const DETACH = 11;
+ pub const SIGEXC = 12;
+ pub const THUPDATE = 13;
+ pub const ATTACHEXC = 14;
+ pub const FORCEQUOTA = 30;
+ pub const DENY_ATTACH = 31;
};
-pub const MachThread = extern struct {
- port: mach_port_t,
+pub const caddr_t = ?[*]u8;
- pub fn isValid(thread: MachThread) bool {
- return thread.port != THREAD_NULL;
- }
+pub extern "c" fn ptrace(request: c_int, pid: pid_t, addr: caddr_t, data: c_int) c_int;
- pub fn getBasicInfo(thread: MachThread) MachError!thread_basic_info {
- var info: thread_basic_info = undefined;
- var count = THREAD_BASIC_INFO_COUNT;
- switch (getKernError(thread_info(
- thread.port,
- THREAD_BASIC_INFO,
- @as(thread_info_t, @ptrCast(&info)),
- &count,
- ))) {
- .SUCCESS => return info,
- else => |err| return unexpectedKernError(err),
- }
- }
+pub const POSIX_SPAWN = struct {
+ pub const RESETIDS = 0x0001;
+ pub const SETPGROUP = 0x0002;
+ pub const SETSIGDEF = 0x0004;
+ pub const SETSIGMASK = 0x0008;
+ pub const SETEXEC = 0x0040;
+ pub const START_SUSPENDED = 0x0080;
+ pub const DISABLE_ASLR = 0x0100;
+ pub const SETSID = 0x0400;
+ pub const RESLIDE = 0x0800;
+ pub const CLOEXEC_DEFAULT = 0x4000;
+};
- pub fn getIdentifierInfo(thread: MachThread) MachError!thread_identifier_info {
- var info: thread_identifier_info = undefined;
- var count = THREAD_IDENTIFIER_INFO_COUNT;
- switch (getKernError(thread_info(
- thread.port,
- THREAD_IDENTIFIER_INFO,
- @as(thread_info_t, @ptrCast(&info)),
- &count,
- ))) {
- .SUCCESS => return info,
- else => |err| return unexpectedKernError(err),
- }
- }
+pub const posix_spawnattr_t = *opaque {};
+pub const posix_spawn_file_actions_t = *opaque {};
+pub extern "c" fn posix_spawnattr_init(attr: *posix_spawnattr_t) c_int;
+pub extern "c" fn posix_spawnattr_destroy(attr: *posix_spawnattr_t) c_int;
+pub extern "c" fn posix_spawnattr_setflags(attr: *posix_spawnattr_t, flags: c_short) c_int;
+pub extern "c" fn posix_spawnattr_getflags(attr: *const posix_spawnattr_t, flags: *c_short) c_int;
+pub extern "c" fn posix_spawn_file_actions_init(actions: *posix_spawn_file_actions_t) c_int;
+pub extern "c" fn posix_spawn_file_actions_destroy(actions: *posix_spawn_file_actions_t) c_int;
+pub extern "c" fn posix_spawn_file_actions_addclose(actions: *posix_spawn_file_actions_t, filedes: fd_t) c_int;
+pub extern "c" fn posix_spawn_file_actions_addopen(
+ actions: *posix_spawn_file_actions_t,
+ filedes: fd_t,
+ path: [*:0]const u8,
+ oflag: c_int,
+ mode: mode_t,
+) c_int;
+pub extern "c" fn posix_spawn_file_actions_adddup2(
+ actions: *posix_spawn_file_actions_t,
+ filedes: fd_t,
+ newfiledes: fd_t,
+) c_int;
+pub extern "c" fn posix_spawn_file_actions_addinherit_np(actions: *posix_spawn_file_actions_t, filedes: fd_t) c_int;
+pub extern "c" fn posix_spawn_file_actions_addchdir_np(actions: *posix_spawn_file_actions_t, path: [*:0]const u8) c_int;
+pub extern "c" fn posix_spawn_file_actions_addfchdir_np(actions: *posix_spawn_file_actions_t, filedes: fd_t) c_int;
+pub extern "c" fn posix_spawn(
+ pid: *pid_t,
+ path: [*:0]const u8,
+ actions: ?*const posix_spawn_file_actions_t,
+ attr: ?*const posix_spawnattr_t,
+ argv: [*:null]?[*:0]const u8,
+ env: [*:null]?[*:0]const u8,
+) c_int;
+pub extern "c" fn posix_spawnp(
+ pid: *pid_t,
+ path: [*:0]const u8,
+ actions: ?*const posix_spawn_file_actions_t,
+ attr: ?*const posix_spawnattr_t,
+ argv: [*:null]?[*:0]const u8,
+ env: [*:null]?[*:0]const u8,
+) c_int;
+
+pub const E = enum(u16) {
+ /// No error occurred.
+ SUCCESS = 0,
+ /// Operation not permitted
+ PERM = 1,
+ /// No such file or directory
+ NOENT = 2,
+ /// No such process
+ SRCH = 3,
+ /// Interrupted system call
+ INTR = 4,
+ /// Input/output error
+ IO = 5,
+ /// Device not configured
+ NXIO = 6,
+ /// Argument list too long
+ @"2BIG" = 7,
+ /// Exec format error
+ NOEXEC = 8,
+ /// Bad file descriptor
+ BADF = 9,
+ /// No child processes
+ CHILD = 10,
+ /// Resource deadlock avoided
+ DEADLK = 11,
+ /// Cannot allocate memory
+ NOMEM = 12,
+ /// Permission denied
+ ACCES = 13,
+ /// Bad address
+ FAULT = 14,
+ /// Block device required
+ NOTBLK = 15,
+ /// Device / Resource busy
+ BUSY = 16,
+ /// File exists
+ EXIST = 17,
+ /// Cross-device link
+ XDEV = 18,
+ /// Operation not supported by device
+ NODEV = 19,
+ /// Not a directory
+ NOTDIR = 20,
+ /// Is a directory
+ ISDIR = 21,
+ /// Invalid argument
+ INVAL = 22,
+ /// Too many open files in system
+ NFILE = 23,
+ /// Too many open files
+ MFILE = 24,
+ /// Inappropriate ioctl for device
+ NOTTY = 25,
+ /// Text file busy
+ TXTBSY = 26,
+ /// File too large
+ FBIG = 27,
+ /// No space left on device
+ NOSPC = 28,
+ /// Illegal seek
+ SPIPE = 29,
+ /// Read-only file system
+ ROFS = 30,
+ /// Too many links
+ MLINK = 31,
+ /// Broken pipe
+ PIPE = 32,
+ // math software
+ /// Numerical argument out of domain
+ DOM = 33,
+ /// Result too large
+ RANGE = 34,
+ // non-blocking and interrupt i/o
+ /// Resource temporarily unavailable
+ /// This is the same code used for `WOULDBLOCK`.
+ AGAIN = 35,
+ /// Operation now in progress
+ INPROGRESS = 36,
+ /// Operation already in progress
+ ALREADY = 37,
+ // ipc/network software -- argument errors
+ /// Socket operation on non-socket
+ NOTSOCK = 38,
+ /// Destination address required
+ DESTADDRREQ = 39,
+ /// Message too long
+ MSGSIZE = 40,
+ /// Protocol wrong type for socket
+ PROTOTYPE = 41,
+ /// Protocol not available
+ NOPROTOOPT = 42,
+ /// Protocol not supported
+ PROTONOSUPPORT = 43,
+ /// Socket type not supported
+ SOCKTNOSUPPORT = 44,
+ /// Operation not supported
+ /// The same code is used for `NOTSUP`.
+ OPNOTSUPP = 45,
+ /// Protocol family not supported
+ PFNOSUPPORT = 46,
+ /// Address family not supported by protocol family
+ AFNOSUPPORT = 47,
+ /// Address already in use
+ ADDRINUSE = 48,
+ /// Can't assign requested address
+ // ipc/network software -- operational errors
+ ADDRNOTAVAIL = 49,
+ /// Network is down
+ NETDOWN = 50,
+ /// Network is unreachable
+ NETUNREACH = 51,
+ /// Network dropped connection on reset
+ NETRESET = 52,
+ /// Software caused connection abort
+ CONNABORTED = 53,
+ /// Connection reset by peer
+ CONNRESET = 54,
+ /// No buffer space available
+ NOBUFS = 55,
+ /// Socket is already connected
+ ISCONN = 56,
+ /// Socket is not connected
+ NOTCONN = 57,
+ /// Can't send after socket shutdown
+ SHUTDOWN = 58,
+ /// Too many references: can't splice
+ TOOMANYREFS = 59,
+ /// Operation timed out
+ TIMEDOUT = 60,
+ /// Connection refused
+ CONNREFUSED = 61,
+ /// Too many levels of symbolic links
+ LOOP = 62,
+ /// File name too long
+ NAMETOOLONG = 63,
+ /// Host is down
+ HOSTDOWN = 64,
+ /// No route to host
+ HOSTUNREACH = 65,
+ /// Directory not empty
+ // quotas & mush
+ NOTEMPTY = 66,
+ /// Too many processes
+ PROCLIM = 67,
+ /// Too many users
+ USERS = 68,
+ /// Disc quota exceeded
+ // Network File System
+ DQUOT = 69,
+ /// Stale NFS file handle
+ STALE = 70,
+ /// Too many levels of remote in path
+ REMOTE = 71,
+ /// RPC struct is bad
+ BADRPC = 72,
+ /// RPC version wrong
+ RPCMISMATCH = 73,
+ /// RPC prog. not avail
+ PROGUNAVAIL = 74,
+ /// Program version wrong
+ PROGMISMATCH = 75,
+ /// Bad procedure for program
+ PROCUNAVAIL = 76,
+ /// No locks available
+ NOLCK = 77,
+ /// Function not implemented
+ NOSYS = 78,
+ /// Inappropriate file type or format
+ FTYPE = 79,
+ /// Authentication error
+ AUTH = 80,
+ /// Need authenticator
+ NEEDAUTH = 81,
+ // Intelligent device errors
+ /// Device power is off
+ PWROFF = 82,
+ /// Device error, e.g. paper out
+ DEVERR = 83,
+ /// Value too large to be stored in data type
+ OVERFLOW = 84,
+ // Program loading errors
+ /// Bad executable
+ BADEXEC = 85,
+ /// Bad CPU type in executable
+ BADARCH = 86,
+ /// Shared library version mismatch
+ SHLIBVERS = 87,
+ /// Malformed Macho file
+ BADMACHO = 88,
+ /// Operation canceled
+ CANCELED = 89,
+ /// Identifier removed
+ IDRM = 90,
+ /// No message of desired type
+ NOMSG = 91,
+ /// Illegal byte sequence
+ ILSEQ = 92,
+ /// Attribute not found
+ NOATTR = 93,
+ /// Bad message
+ BADMSG = 94,
+ /// Reserved
+ MULTIHOP = 95,
+ /// No message available on STREAM
+ NODATA = 96,
+ /// Reserved
+ NOLINK = 97,
+ /// No STREAM resources
+ NOSR = 98,
+ /// Not a STREAM
+ NOSTR = 99,
+ /// Protocol error
+ PROTO = 100,
+ /// STREAM ioctl timeout
+ TIME = 101,
+ /// No such policy registered
+ NOPOLICY = 103,
+ /// State not recoverable
+ NOTRECOVERABLE = 104,
+ /// Previous owner died
+ OWNERDEAD = 105,
+ /// Interface output queue is full
+ QFULL = 106,
+ _,
};
-pub fn machTaskForPid(pid: std.c.pid_t) MachError!MachTask {
- var port: mach_port_name_t = undefined;
- switch (getKernError(task_for_pid(mach_task_self(), pid, &port))) {
- .SUCCESS => {},
- .FAILURE => return error.PermissionDenied,
- else => |err| return unexpectedKernError(err),
- }
- return MachTask{ .port = port };
-}
+/// From Common Security Services Manager
+/// Security.framework/Headers/cssm*.h
+pub const DB_RECORDTYPE = enum(u32) {
+ // Record Types defined in the Schema Management Name Space
+ SCHEMA_INFO = SCHEMA_START + 0,
+ SCHEMA_INDEXES = SCHEMA_START + 1,
+ SCHEMA_ATTRIBUTES = SCHEMA_START + 2,
+ SCHEMA_PARSING_MODULE = SCHEMA_START + 3,
+
+ // Record Types defined in the Open Group Application Name Space
+ ANY = OPEN_GROUP_START + 0,
+ CERT = OPEN_GROUP_START + 1,
+ CRL = OPEN_GROUP_START + 2,
+ POLICY = OPEN_GROUP_START + 3,
+ GENERIC = OPEN_GROUP_START + 4,
+ PUBLIC_KEY = OPEN_GROUP_START + 5,
+ PRIVATE_KEY = OPEN_GROUP_START + 6,
+ SYMMETRIC_KEY = OPEN_GROUP_START + 7,
+ ALL_KEYS = OPEN_GROUP_START + 8,
+
+ // AppleFileDL record types
+ GENERIC_PASSWORD = APP_DEFINED_START + 0,
+ INTERNET_PASSWORD = APP_DEFINED_START + 1,
+ APPLESHARE_PASSWORD = APP_DEFINED_START + 2,
+
+ X509_CERTIFICATE = APP_DEFINED_START + 0x1000,
+ USER_TRUST,
+ X509_CRL,
+ UNLOCK_REFERRAL,
+ EXTENDED_ATTRIBUTE,
+ METADATA = APP_DEFINED_START + 0x8000,
-pub fn machTaskForSelf() MachTask {
- return .{ .port = mach_task_self() };
-}
+ _,
-pub const os_signpost_id_t = u64;
+ // Schema Management Name Space Range Definition
+ pub const SCHEMA_START = 0x00000000;
+ pub const SCHEMA_END = SCHEMA_START + 4;
-pub const OS_SIGNPOST_ID_NULL: os_signpost_id_t = 0;
-pub const OS_SIGNPOST_ID_INVALID: os_signpost_id_t = !0;
-pub const OS_SIGNPOST_ID_EXCLUSIVE: os_signpost_id_t = 0xeeeeb0b5b2b2eeee;
+ // Open Group Application Name Space Range Definition
+ pub const OPEN_GROUP_START = 0x0000000A;
+ pub const OPEN_GROUP_END = OPEN_GROUP_START + 8;
-pub const os_log_t = opaque {};
-pub const os_log_type_t = enum(u8) {
- /// default messages always captures
- OS_LOG_TYPE_DEFAULT = 0x00,
- /// messages with additional infos
- OS_LOG_TYPE_INFO = 0x01,
- /// debug messages
- OS_LOG_TYPE_DEBUG = 0x02,
- /// error messages
- OS_LOG_TYPE_ERROR = 0x10,
- /// unexpected conditions messages
- OS_LOG_TYPE_FAULT = 0x11,
+ // Industry At Large Application Name Space Range Definition
+ pub const APP_DEFINED_START = 0x80000000;
+ pub const APP_DEFINED_END = 0xffffffff;
};
-
-pub const OS_LOG_CATEGORY_POINTS_OF_INTEREST: *const u8 = "PointsOfInterest";
-pub const OS_LOG_CATEGORY_DYNAMIC_TRACING: *const u8 = "DynamicTracing";
-pub const OS_LOG_CATEGORY_DYNAMIC_STACK_TRACING: *const u8 = "DynamicStackTracing";
-
-pub extern "c" fn os_log_create(subsystem: [*]const u8, category: [*]const u8) os_log_t;
-pub extern "c" fn os_log_type_enabled(log: os_log_t, tpe: os_log_type_t) bool;
-pub extern "c" fn os_signpost_id_generate(log: os_log_t) os_signpost_id_t;
-pub extern "c" fn os_signpost_interval_begin(log: os_log_t, signpos: os_signpost_id_t, func: [*]const u8, ...) void;
-pub extern "c" fn os_signpost_interval_end(log: os_log_t, signpos: os_signpost_id_t, func: [*]const u8, ...) void;
-pub extern "c" fn os_signpost_id_make_with_pointer(log: os_log_t, ptr: ?*anyopaque) os_signpost_id_t;
-pub extern "c" fn os_signpost_enabled(log: os_log_t) bool;
lib/std/c/dragonfly.zig
@@ -1,63 +1,16 @@
-const builtin = @import("builtin");
const std = @import("../std.zig");
-const assert = std.debug.assert;
-const maxInt = std.math.maxInt;
-const iovec = std.posix.iovec;
-extern "c" threadlocal var errno: c_int;
-pub fn _errno() *c_int {
- return &errno;
-}
-
-pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) c_int;
-pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int;
-pub extern "c" fn getrandom(buf_ptr: [*]u8, buf_len: usize, flags: c_uint) isize;
-pub extern "c" fn pipe2(fds: *[2]fd_t, flags: std.c.O) c_int;
-pub extern "c" fn arc4random_buf(buf: [*]u8, len: usize) void;
-
-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;
+const SIG = std.c.SIG;
+const gid_t = std.c.gid_t;
+const iovec = std.c.iovec;
+const pid_t = std.c.pid_t;
+const socklen_t = std.c.socklen_t;
+const uid_t = std.c.uid_t;
pub extern "c" fn lwp_gettid() c_int;
-
-pub extern "c" fn posix_memalign(memptr: *?*anyopaque, alignment: usize, size: usize) c_int;
-
-pub const pthread_attr_t = extern struct { // copied from freebsd
- __size: [56]u8,
- __align: c_long,
-};
-
-pub const sem_t = ?*opaque {};
-
-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 extern "c" fn umtx_sleep(ptr: *const volatile c_int, value: c_int, timeout: c_int) c_int;
pub extern "c" fn umtx_wakeup(ptr: *const volatile c_int, count: c_int) c_int;
-// See:
-// - https://gitweb.dragonflybsd.org/dragonfly.git/blob/HEAD:/include/unistd.h
-// - https://gitweb.dragonflybsd.org/dragonfly.git/blob/HEAD:/sys/sys/types.h
-// TODO: mode_t should probably be changed to a u16, audit pid_t/off_t as well
-pub const fd_t = c_int;
-pub const pid_t = c_int;
-pub const off_t = c_long;
-pub const mode_t = c_uint;
-pub const uid_t = u32;
-pub const gid_t = u32;
-pub const time_t = isize;
-pub const suseconds_t = c_long;
-
-pub const ucontext_t = extern struct {
- sigmask: sigset_t,
- mcontext: mcontext_t,
- link: ?*ucontext_t,
- stack: stack_t,
- cofunc: ?*fn (?*ucontext_t, ?*anyopaque) void,
- arg: ?*void,
- _spare: [4]c_int,
-};
-
pub const mcontext_t = extern struct {
onstack: register_t, // XXX - sigcontext compat.
rdi: register_t,
@@ -201,707 +154,23 @@ pub const E = enum(u16) {
_,
};
-pub const STDIN_FILENO = 0;
-pub const STDOUT_FILENO = 1;
-pub const STDERR_FILENO = 2;
-
-pub const PROT = struct {
- pub const NONE = 0;
- pub const READ = 1;
- pub const WRITE = 2;
- pub const EXEC = 4;
-};
-
-pub const MSF = struct {
- pub const ASYNC = 1;
- pub const INVALIDATE = 2;
- pub const SYNC = 4;
-};
-
-pub const W = struct {
- pub const NOHANG = 0x0001;
- pub const UNTRACED = 0x0002;
- pub const CONTINUED = 0x0004;
- pub const STOPPED = UNTRACED;
- pub const NOWAIT = 0x0008;
- pub const EXITED = 0x0010;
- pub const TRAPPED = 0x0020;
-
- pub fn EXITSTATUS(s: u32) u8 {
- return @as(u8, @intCast((s & 0xff00) >> 8));
- }
- pub fn TERMSIG(s: u32) u32 {
- return s & 0x7f;
- }
- pub fn STOPSIG(s: u32) u32 {
- return EXITSTATUS(s);
- }
- pub fn IFEXITED(s: u32) bool {
- return TERMSIG(s) == 0;
- }
- pub fn IFSTOPPED(s: u32) bool {
- return @as(u16, @truncate((((s & 0xffff) *% 0x10001) >> 8))) > 0x7f00;
- }
- pub fn IFSIGNALED(s: u32) bool {
- return (s & 0xffff) -% 1 < 0xff;
- }
-};
-
-pub const SA = struct {
- pub const ONSTACK = 0x0001;
- pub const RESTART = 0x0002;
- pub const RESETHAND = 0x0004;
- pub const NODEFER = 0x0010;
- pub const NOCLDWAIT = 0x0020;
- pub const SIGINFO = 0x0040;
-};
-
-pub const PATH_MAX = 1024;
-pub const NAME_MAX = 255;
-pub const IOV_MAX = KERN.IOV_MAX;
-
-pub const ino_t = c_ulong;
-
-pub const Stat = extern struct {
- ino: ino_t,
- nlink: c_uint,
- dev: c_uint,
- mode: c_ushort,
- padding1: u16,
- uid: uid_t,
- gid: gid_t,
- rdev: c_uint,
- atim: timespec,
- mtim: timespec,
- ctim: timespec,
- size: c_ulong,
- blocks: i64,
- blksize: u32,
- flags: u32,
- gen: u32,
- lspare: i32,
- qspare1: i64,
- qspare2: i64,
- 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 const timespec = extern struct {
- tv_sec: c_long,
- tv_nsec: c_long,
-};
-
-pub const timeval = extern struct {
- /// seconds
- tv_sec: time_t,
- /// microseconds
- tv_usec: suseconds_t,
-};
-
-pub const CTL = struct {
- pub const UNSPEC = 0;
- pub const KERN = 1;
- pub const VM = 2;
- pub const VFS = 3;
- pub const NET = 4;
- pub const DEBUG = 5;
- pub const HW = 6;
- pub const MACHDEP = 7;
- pub const USER = 8;
- pub const LWKT = 10;
- pub const MAXID = 11;
- pub const MAXNAME = 12;
-};
-
-pub const KERN = struct {
- pub const PROC_ALL = 0;
- pub const OSTYPE = 1;
- pub const PROC_PID = 1;
- pub const OSRELEASE = 2;
- pub const PROC_PGRP = 2;
- pub const OSREV = 3;
- pub const PROC_SESSION = 3;
- pub const VERSION = 4;
- pub const PROC_TTY = 4;
- pub const MAXVNODES = 5;
- pub const PROC_UID = 5;
- pub const MAXPROC = 6;
- pub const PROC_RUID = 6;
- pub const MAXFILES = 7;
- pub const PROC_ARGS = 7;
- pub const ARGMAX = 8;
- pub const PROC_CWD = 8;
- pub const PROC_PATHNAME = 9;
- pub const SECURELVL = 9;
- pub const PROC_SIGTRAMP = 10;
- pub const HOSTNAME = 10;
- pub const HOSTID = 11;
- pub const CLOCKRATE = 12;
- pub const VNODE = 13;
- pub const PROC = 14;
- pub const FILE = 15;
- pub const PROC_FLAGMASK = 16;
- pub const PROF = 16;
- pub const PROC_FLAG_LWP = 16;
- pub const POSIX1 = 17;
- pub const NGROUPS = 18;
- pub const JOB_CONTROL = 19;
- pub const SAVED_IDS = 20;
- pub const BOOTTIME = 21;
- pub const NISDOMAINNAME = 22;
- pub const UPDATEINTERVAL = 23;
- pub const OSRELDATE = 24;
- pub const NTP_PLL = 25;
- pub const BOOTFILE = 26;
- pub const MAXFILESPERPROC = 27;
- pub const MAXPROCPERUID = 28;
- pub const DUMPDEV = 29;
- pub const IPC = 30;
- pub const DUMMY = 31;
- pub const PS_STRINGS = 32;
- pub const USRSTACK = 33;
- pub const LOGSIGEXIT = 34;
- pub const IOV_MAX = 35;
- pub const MAXPOSIXLOCKSPERUID = 36;
- pub const MAXID = 37;
-};
-
-pub const HOST_NAME_MAX = 255;
-
-// 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 SEEK = struct {
- pub const SET = 0;
- pub const CUR = 1;
- pub const END = 2;
- pub const DATA = 3;
- pub const HOLE = 4;
-};
-
-pub const F = struct {
- pub const ULOCK = 0;
- pub const LOCK = 1;
- pub const TLOCK = 2;
- pub const TEST = 3;
-
- pub const DUPFD = 0;
- pub const GETFD = 1;
- pub const RDLCK = 1;
- pub const SETFD = 2;
- pub const UNLCK = 2;
- pub const WRLCK = 3;
- pub const GETFL = 3;
- pub const SETFL = 4;
- pub const GETOWN = 5;
- pub const SETOWN = 6;
- pub const GETLK = 7;
- pub const SETLK = 8;
- pub const SETLKW = 9;
- pub const DUP2FD = 10;
- pub const DUPFD_CLOEXEC = 17;
- pub const DUP2FD_CLOEXEC = 18;
- pub const GETPATH = 19;
-};
-
-pub const FD_CLOEXEC = 1;
-
-pub const dirent = extern struct {
- fileno: c_ulong,
- namlen: u16,
- type: u8,
- unused1: u8,
- unused2: u32,
- name: [256]u8,
-
- pub fn reclen(self: dirent) u16 {
- return (@offsetOf(dirent, "name") + self.namlen + 1 + 7) & ~@as(u16, 7);
- }
-};
-
-pub const DT = struct {
- pub const UNKNOWN = 0;
- pub const FIFO = 1;
- pub const CHR = 2;
- pub const DIR = 4;
- pub const BLK = 6;
- pub const REG = 8;
- pub const LNK = 10;
- pub const SOCK = 12;
- pub const WHT = 14;
- pub const DBF = 15;
-};
-
-pub const CLOCK = struct {
- pub const REALTIME = 0;
- pub const VIRTUAL = 1;
- pub const PROF = 2;
- pub const MONOTONIC = 4;
- pub const UPTIME = 5;
- pub const UPTIME_PRECISE = 7;
- pub const UPTIME_FAST = 8;
- pub const REALTIME_PRECISE = 9;
- pub const REALTIME_FAST = 10;
- pub const MONOTONIC_PRECISE = 11;
- pub const MONOTONIC_FAST = 12;
- pub const SECOND = 13;
- pub const THREAD_CPUTIME_ID = 14;
- pub const PROCESS_CPUTIME_ID = 15;
-};
-
-pub const sockaddr = extern struct {
- len: u8,
- family: sa_family_t,
- 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 Kevent = extern struct {
- ident: usize,
- filter: c_short,
- flags: c_ushort,
- fflags: c_uint,
- data: isize,
- udata: usize,
-};
-
-pub const EVFILT_FS = -10;
-pub const EVFILT_USER = -9;
-pub const EVFILT_EXCEPT = -8;
-pub const EVFILT_TIMER = -7;
-pub const EVFILT_SIGNAL = -6;
-pub const EVFILT_PROC = -5;
-pub const EVFILT_VNODE = -4;
-pub const EVFILT_AIO = -3;
-pub const EVFILT_WRITE = -2;
-pub const EVFILT_READ = -1;
-pub const EVFILT_SYSCOUNT = 10;
-pub const EVFILT_MARKER = 15;
-
-pub const EV_ADD = 1;
-pub const EV_DELETE = 2;
-pub const EV_ENABLE = 4;
-pub const EV_DISABLE = 8;
-pub const EV_ONESHOT = 16;
-pub const EV_CLEAR = 32;
-pub const EV_RECEIPT = 64;
-pub const EV_DISPATCH = 128;
-pub const EV_NODATA = 4096;
-pub const EV_FLAG1 = 8192;
-pub const EV_ERROR = 16384;
-pub const EV_EOF = 32768;
-pub const EV_SYSFLAGS = 61440;
-
-pub const NOTE_FFNOP = 0;
-pub const NOTE_TRACK = 1;
-pub const NOTE_DELETE = 1;
-pub const NOTE_LOWAT = 1;
-pub const NOTE_TRACKERR = 2;
-pub const NOTE_OOB = 2;
-pub const NOTE_WRITE = 2;
-pub const NOTE_EXTEND = 4;
-pub const NOTE_CHILD = 4;
-pub const NOTE_ATTRIB = 8;
-pub const NOTE_LINK = 16;
-pub const NOTE_RENAME = 32;
-pub const NOTE_REVOKE = 64;
-pub const NOTE_PDATAMASK = 1048575;
-pub const NOTE_FFLAGSMASK = 16777215;
-pub const NOTE_TRIGGER = 16777216;
-pub const NOTE_EXEC = 536870912;
-pub const NOTE_FFAND = 1073741824;
-pub const NOTE_FORK = 1073741824;
-pub const NOTE_EXIT = 2147483648;
-pub const NOTE_FFOR = 2147483648;
-pub const NOTE_FFCTRLMASK = 3221225472;
-pub const NOTE_FFCOPY = 3221225472;
-pub const NOTE_PCTRLMASK = 4026531840;
-
-pub const TCSA = enum(c_uint) {
- NOW,
- DRAIN,
- FLUSH,
- _,
-};
-
-pub const stack_t = extern struct {
- sp: [*]u8,
- size: isize,
- flags: i32,
-};
-
-pub const S = struct {
- pub const IREAD = IRUSR;
- pub const IEXEC = IXUSR;
- pub const IWRITE = IWUSR;
- pub const IXOTH = 1;
- pub const IWOTH = 2;
- pub const IROTH = 4;
- pub const IRWXO = 7;
- pub const IXGRP = 8;
- pub const IWGRP = 16;
- pub const IRGRP = 32;
- pub const IRWXG = 56;
- pub const IXUSR = 64;
- pub const IWUSR = 128;
- pub const IRUSR = 256;
- pub const IRWXU = 448;
- pub const ISTXT = 512;
- pub const BLKSIZE = 512;
- pub const ISVTX = 512;
- pub const ISGID = 1024;
- pub const ISUID = 2048;
- pub const IFIFO = 4096;
- pub const IFCHR = 8192;
- pub const IFDIR = 16384;
- pub const IFBLK = 24576;
- pub const IFREG = 32768;
- pub const IFDB = 36864;
- pub const IFLNK = 40960;
- pub const IFSOCK = 49152;
- pub const IFWHT = 57344;
- pub const IFMT = 61440;
-
- pub fn ISCHR(m: u32) bool {
- return m & IFMT == IFCHR;
- }
-};
-
pub const BADSIG = SIG.ERR;
-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 BLOCK = 1;
- pub const UNBLOCK = 2;
- pub const SETMASK = 3;
-
- pub const IOT = ABRT;
- pub const HUP = 1;
- pub const INT = 2;
- pub const QUIT = 3;
- pub const ILL = 4;
- pub const TRAP = 5;
- pub const ABRT = 6;
- pub const EMT = 7;
- pub const FPE = 8;
- pub const KILL = 9;
- pub const BUS = 10;
- pub const SEGV = 11;
- pub const SYS = 12;
- pub const PIPE = 13;
- pub const ALRM = 14;
- pub const TERM = 15;
- pub const URG = 16;
- pub const STOP = 17;
- pub const TSTP = 18;
- pub const CONT = 19;
- pub const CHLD = 20;
- pub const TTIN = 21;
- pub const TTOU = 22;
- pub const IO = 23;
- pub const XCPU = 24;
- pub const XFSZ = 25;
- pub const VTALRM = 26;
- pub const PROF = 27;
- pub const WINCH = 28;
- pub const INFO = 29;
- pub const USR1 = 30;
- pub const USR2 = 31;
- pub const THR = 32;
- pub const CKPT = 33;
- pub const CKPTEXIT = 34;
-};
-
-pub const siginfo_t = extern struct {
- signo: c_int,
- errno: c_int,
- code: c_int,
- pid: c_int,
- uid: uid_t,
- status: c_int,
- addr: *allowzero anyopaque,
- value: sigval,
- band: c_long,
- __spare__: [7]c_int,
-};
-
-pub const sigval = extern union {
- sival_int: c_int,
- sival_ptr: ?*anyopaque,
-};
-
-pub const _SIG_WORDS = 4;
-
-pub const sigset_t = extern struct {
- __bits: [_SIG_WORDS]c_uint,
-};
-
-pub const empty_sigset = sigset_t{ .__bits = [_]c_uint{0} ** _SIG_WORDS };
-
-pub const sig_atomic_t = c_int;
-
-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,
- },
- flags: c_uint,
- mask: sigset_t,
-};
-
pub const sig_t = *const fn (i32) callconv(.C) void;
-pub const SOCK = struct {
- pub const STREAM = 1;
- pub const DGRAM = 2;
- pub const RAW = 3;
- pub const RDM = 4;
- pub const SEQPACKET = 5;
- pub const MAXADDRLEN = 255;
- pub const CLOEXEC = 0x10000000;
- pub const NONBLOCK = 0x20000000;
-};
-
-pub const SO = struct {
- pub const DEBUG = 0x0001;
- pub const ACCEPTCONN = 0x0002;
- pub const REUSEADDR = 0x0004;
- pub const KEEPALIVE = 0x0008;
- pub const DONTROUTE = 0x0010;
- pub const BROADCAST = 0x0020;
- pub const USELOOPBACK = 0x0040;
- pub const LINGER = 0x0080;
- pub const OOBINLINE = 0x0100;
- pub const REUSEPORT = 0x0200;
- pub const TIMESTAMP = 0x0400;
- pub const NOSIGPIPE = 0x0800;
- pub const ACCEPTFILTER = 0x1000;
- pub const RERROR = 0x2000;
- pub const PASSCRED = 0x4000;
-
- pub const SNDBUF = 0x1001;
- pub const RCVBUF = 0x1002;
- pub const SNDLOWAT = 0x1003;
- pub const RCVLOWAT = 0x1004;
- pub const SNDTIMEO = 0x1005;
- pub const RCVTIMEO = 0x1006;
- pub const ERROR = 0x1007;
- pub const TYPE = 0x1008;
- pub const SNDSPACE = 0x100a;
- pub const CPUHINT = 0x1030;
-};
-
-pub const SOL = struct {
- pub const SOCKET = 0xffff;
-};
-
-pub const PF = struct {
- pub const INET6 = AF.INET6;
- pub const IMPLINK = AF.IMPLINK;
- pub const ROUTE = AF.ROUTE;
- pub const ISO = AF.ISO;
- pub const PIP = AF.pseudo_PIP;
- pub const CHAOS = AF.CHAOS;
- pub const DATAKIT = AF.DATAKIT;
- pub const INET = AF.INET;
- pub const APPLETALK = AF.APPLETALK;
- pub const SIP = AF.SIP;
- pub const OSI = AF.ISO;
- pub const CNT = AF.CNT;
- pub const LINK = AF.LINK;
- pub const HYLINK = AF.HYLINK;
- pub const MAX = AF.MAX;
- pub const KEY = AF.pseudo_KEY;
- pub const PUP = AF.PUP;
- pub const COIP = AF.COIP;
- pub const SNA = AF.SNA;
- pub const LOCAL = AF.LOCAL;
- pub const NETBIOS = AF.NETBIOS;
- pub const NATM = AF.NATM;
- pub const BLUETOOTH = AF.BLUETOOTH;
- pub const UNSPEC = AF.UNSPEC;
- pub const NETGRAPH = AF.NETGRAPH;
- pub const ECMA = AF.ECMA;
- pub const IPX = AF.IPX;
- pub const DLI = AF.DLI;
- pub const ATM = AF.ATM;
- pub const CCITT = AF.CCITT;
- pub const ISDN = AF.ISDN;
- pub const RTIP = AF.pseudo_RTIP;
- pub const LAT = AF.LAT;
- pub const UNIX = PF.LOCAL;
- pub const XTP = AF.pseudo_XTP;
- pub const DECnet = AF.DECnet;
-};
-
-pub const AF = struct {
- pub const UNSPEC = 0;
- pub const OSI = ISO;
- pub const UNIX = LOCAL;
- pub const LOCAL = 1;
- pub const INET = 2;
- pub const IMPLINK = 3;
- pub const PUP = 4;
- pub const CHAOS = 5;
- pub const NETBIOS = 6;
- pub const ISO = 7;
- pub const ECMA = 8;
- pub const DATAKIT = 9;
- pub const CCITT = 10;
- pub const SNA = 11;
- pub const DLI = 13;
- pub const LAT = 14;
- pub const HYLINK = 15;
- pub const APPLETALK = 16;
- pub const ROUTE = 17;
- pub const LINK = 18;
- pub const COIP = 20;
- pub const CNT = 21;
- pub const IPX = 23;
- pub const SIP = 24;
- pub const ISDN = 26;
- pub const INET6 = 28;
- pub const NATM = 29;
- pub const ATM = 30;
- pub const NETGRAPH = 32;
- pub const BLUETOOTH = 33;
- pub const MPLS = 34;
- pub const MAX = 36;
-};
-
-pub const in_port_t = u16;
-pub const sa_family_t = u8;
-pub const socklen_t = u32;
-
-pub const EAI = enum(c_int) {
- ADDRFAMILY = 1,
- AGAIN = 2,
- BADFLAGS = 3,
- FAIL = 4,
- FAMILY = 5,
- MEMORY = 6,
- NODATA = 7,
- NONAME = 8,
- SERVICE = 9,
- SOCKTYPE = 10,
- SYSTEM = 11,
- BADHINTS = 12,
- PROTOCOL = 13,
- OVERFLOW = 14,
- _,
-};
-
-pub const IFNAMESIZE = 16;
-
-pub const AI = struct {
- pub const PASSIVE = 0x00000001;
- pub const CANONNAME = 0x00000002;
- pub const NUMERICHOST = 0x00000004;
- pub const NUMERICSERV = 0x00000008;
- pub const MASK = PASSIVE | CANONNAME | NUMERICHOST | NUMERICSERV | ADDRCONFIG;
- pub const ALL = 0x00000100;
- pub const V4MAPPED_CFG = 0x00000200;
- pub const ADDRCONFIG = 0x00000400;
- pub const V4MAPPED = 0x00000800;
- pub const DEFAULT = V4MAPPED_CFG | ADDRCONFIG;
-};
-
-pub const RTLD = struct {
- pub const LAZY = 1;
- pub const NOW = 2;
- pub const MODEMASK = 0x3;
- pub const GLOBAL = 0x100;
- pub const LOCAL = 0;
- pub const TRACE = 0x200;
- pub const NODELETE = 0x01000;
- pub const NOLOAD = 0x02000;
-
- pub const NEXT = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -1)))));
- pub const DEFAULT = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -2)))));
- pub const SELF = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -3)))));
- pub const ALL = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -4)))));
-};
-
-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 cmsghdr = extern struct {
- cmsg_len: socklen_t,
- cmsg_level: c_int,
- cmsg_type: c_int,
-};
-pub const msghdr = extern struct {
- msg_name: ?*anyopaque,
- msg_namelen: socklen_t,
- msg_iov: [*]iovec,
- msg_iovlen: c_int,
- msg_control: ?*anyopaque,
- msg_controllen: socklen_t,
- msg_flags: c_int,
+ len: socklen_t,
+ level: c_int,
+ type: c_int,
};
+
pub const cmsgcred = extern struct {
- cmcred_pid: pid_t,
- cmcred_uid: uid_t,
- cmcred_euid: uid_t,
- cmcred_gid: gid_t,
- cmcred_ngroups: c_short,
- cmcred_groups: [16]gid_t,
+ pid: pid_t,
+ uid: uid_t,
+ euid: uid_t,
+ gid: gid_t,
+ ngroups: c_short,
+ groups: [16]gid_t,
};
pub const sf_hdtr = extern struct {
headers: [*]iovec,
@@ -919,226 +188,3 @@ pub const POSIX_MADV_RANDOM = 1;
pub const POSIX_MADV_DONTNEED = 4;
pub const POSIX_MADV_NORMAL = 0;
pub const POSIX_MADV_WILLNEED = 3;
-
-pub const MADV = struct {
- pub const SEQUENTIAL = 2;
- pub const CONTROL_END = SETMAP;
- pub const DONTNEED = 4;
- pub const RANDOM = 1;
- pub const WILLNEED = 3;
- pub const NORMAL = 0;
- pub const CONTROL_START = INVAL;
- pub const FREE = 5;
- pub const NOSYNC = 6;
- pub const AUTOSYNC = 7;
- pub const NOCORE = 8;
- pub const CORE = 9;
- pub const INVAL = 10;
- pub const SETMAP = 11;
-};
-
-pub const LOCK = struct {
- pub const SH = 1;
- pub const EX = 2;
- pub const UN = 8;
- pub const NB = 4;
-};
-
-pub const Flock = extern struct {
- start: off_t,
- len: off_t,
- pid: pid_t,
- type: c_short,
- whence: c_short,
-};
-
-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 ICMP = 1;
- pub const TCP = 6;
- pub const UDP = 17;
- pub const IPV6 = 41;
- pub const RAW = 255;
- pub const HOPOPTS = 0;
- pub const IGMP = 2;
- pub const GGP = 3;
- pub const IPV4 = 4;
- pub const IPIP = IPV4;
- pub const ST = 7;
- pub const EGP = 8;
- pub const PIGP = 9;
- pub const RCCMON = 10;
- pub const NVPII = 11;
- pub const PUP = 12;
- pub const ARGUS = 13;
- pub const EMCON = 14;
- pub const XNET = 15;
- pub const CHAOS = 16;
- pub const MUX = 18;
- pub const MEAS = 19;
- pub const HMP = 20;
- pub const PRM = 21;
- pub const IDP = 22;
- pub const TRUNK1 = 23;
- pub const TRUNK2 = 24;
- pub const LEAF1 = 25;
- pub const LEAF2 = 26;
- pub const RDP = 27;
- pub const IRTP = 28;
- pub const TP = 29;
- pub const BLT = 30;
- pub const NSP = 31;
- pub const INP = 32;
- pub const SEP = 33;
- pub const @"3PC" = 34;
- pub const IDPR = 35;
- pub const XTP = 36;
- pub const DDP = 37;
- pub const CMTP = 38;
- pub const TPXX = 39;
- pub const IL = 40;
- pub const SDRP = 42;
- pub const ROUTING = 43;
- pub const FRAGMENT = 44;
- pub const IDRP = 45;
- pub const RSVP = 46;
- pub const GRE = 47;
- pub const MHRP = 48;
- pub const BHA = 49;
- pub const ESP = 50;
- pub const AH = 51;
- pub const INLSP = 52;
- pub const SWIPE = 53;
- pub const NHRP = 54;
- pub const MOBILE = 55;
- pub const TLSP = 56;
- pub const SKIP = 57;
- pub const ICMPV6 = 58;
- pub const NONE = 59;
- pub const DSTOPTS = 60;
- pub const AHIP = 61;
- pub const CFTP = 62;
- pub const HELLO = 63;
- pub const SATEXPAK = 64;
- pub const KRYPTOLAN = 65;
- pub const RVD = 66;
- pub const IPPC = 67;
- pub const ADFS = 68;
- pub const SATMON = 69;
- pub const VISA = 70;
- pub const IPCV = 71;
- pub const CPNX = 72;
- pub const CPHB = 73;
- pub const WSN = 74;
- pub const PVP = 75;
- pub const BRSATMON = 76;
- pub const ND = 77;
- pub const WBMON = 78;
- pub const WBEXPAK = 79;
- pub const EON = 80;
- pub const VMTP = 81;
- pub const SVMTP = 82;
- pub const VINES = 83;
- pub const TTP = 84;
- pub const IGP = 85;
- pub const DGP = 86;
- pub const TCF = 87;
- pub const IGRP = 88;
- pub const OSPFIGP = 89;
- pub const SRPC = 90;
- pub const LARP = 91;
- pub const MTP = 92;
- pub const AX25 = 93;
- pub const IPEIP = 94;
- pub const MICP = 95;
- pub const SCCSP = 96;
- pub const ETHERIP = 97;
- pub const ENCAP = 98;
- pub const APES = 99;
- pub const GMTP = 100;
- pub const IPCOMP = 108;
- pub const PIM = 103;
- pub const CARP = 112;
- pub const PGM = 113;
- pub const PFSYNC = 240;
- pub const DIVERT = 254;
- pub const MAX = 256;
- pub const DONE = 257;
- pub const UNKNOWN = 258;
-};
-
-pub const rlimit_resource = enum(c_int) {
- CPU = 0,
- FSIZE = 1,
- DATA = 2,
- STACK = 3,
- CORE = 4,
- RSS = 5,
- MEMLOCK = 6,
- NPROC = 7,
- NOFILE = 8,
- SBSIZE = 9,
- VMEM = 10,
- POSIXLOCKS = 11,
- _,
-
- pub const AS: rlimit_resource = .VMEM;
-};
-
-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;
-};
-
-pub const nfds_t = u32;
-
-pub const pollfd = extern struct {
- fd: fd_t,
- events: i16,
- revents: i16,
-};
-
-pub const POLL = struct {
- /// Requestable events.
- pub const IN = 0x0001;
- pub const PRI = 0x0002;
- pub const OUT = 0x0004;
- pub const RDNORM = 0x0040;
- pub const WRNORM = OUT;
- pub const RDBAND = 0x0080;
- pub const WRBAND = 0x0100;
-
- /// These events are set if they occur regardless of whether they were requested.
- pub const ERR = 0x0008;
- pub const HUP = 0x0010;
- pub const NVAL = 0x0020;
-};
lib/std/c/emscripten.zig
@@ -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,
-};
lib/std/c/freebsd.zig
@@ -1,36 +1,33 @@
+const builtin = @import("builtin");
const std = @import("../std.zig");
const assert = std.debug.assert;
-const builtin = @import("builtin");
-const maxInt = std.math.maxInt;
-const iovec = std.posix.iovec;
-const iovec_const = std.posix.iovec_const;
-
-extern "c" fn __error() *c_int;
-pub const _errno = __error;
-
-pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) isize;
-pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int;
-pub extern "c" fn getrandom(buf_ptr: [*]u8, buf_len: usize, flags: c_uint) isize;
-pub extern "c" fn pthread_getthreadid_np() c_int;
-pub extern "c" fn pthread_set_name_np(thread: std.c.pthread_t, name: [*:0]const u8) void;
-pub extern "c" fn pthread_get_name_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) void;
-pub extern "c" fn pipe2(fds: *[2]fd_t, flags: std.c.O) c_int;
-pub extern "c" fn arc4random_buf(buf: [*]u8, len: usize) void;
-
-pub extern "c" fn posix_memalign(memptr: *?*anyopaque, alignment: usize, size: usize) c_int;
-pub extern "c" fn malloc_usable_size(?*const anyopaque) usize;
+const PATH_MAX = std.c.PATH_MAX;
+const blkcnt_t = std.c.blkcnt_t;
+const blksize_t = std.c.blksize_t;
+const dev_t = std.c.dev_t;
+const fd_t = std.c.fd_t;
+const gid_t = std.c.gid_t;
+const ino_t = std.c.ino_t;
+const iovec_const = std.posix.iovec_const;
+const mode_t = std.c.mode_t;
+const nlink_t = std.c.nlink_t;
+const off_t = std.c.off_t;
+const pid_t = std.c.pid_t;
+const sockaddr = std.c.sockaddr;
+const time_t = std.c.time_t;
+const timespec = std.c.timespec;
+const uid_t = std.c.uid_t;
+const sf_hdtr = std.c.sf_hdtr;
+const clockid_t = std.c.clockid_t;
-pub extern "c" fn getpid() pid_t;
+comptime {
+ assert(builtin.os.tag == .freebsd or builtin.os.tag == .kfreebsd); // Prevent access of std.c symbols on wrong OS.
+}
pub extern "c" fn kinfo_getfile(pid: pid_t, cntp: *c_int) ?[*]kinfo_file;
+pub extern "c" fn copy_file_range(fd_in: fd_t, off_in: ?*off_t, fd_out: fd_t, off_out: ?*off_t, len: usize, flags: u32) usize;
-pub const sf_hdtr = extern struct {
- headers: [*]const iovec_const,
- hdr_cnt: c_int,
- trailers: [*]const iovec_const,
- trl_cnt: c_int,
-};
pub extern "c" fn sendfile(
in_fd: fd_t,
out_fd: fd_t,
@@ -41,23 +38,6 @@ pub extern "c" fn sendfile(
flags: u32,
) c_int;
-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 const pthread_attr_t = extern struct {
- inner: ?*anyopaque = null,
-};
-
-pub const sem_t = extern struct {
- _magic: u32,
- _kern: extern struct {
- _count: u32,
- _flags: u32,
- },
- _padding: u32,
-};
-
-// https://github.com/freebsd/freebsd-src/blob/main/sys/sys/umtx.h
pub const UMTX_OP = enum(c_int) {
LOCK = 0,
UNLOCK = 1,
@@ -90,213 +70,14 @@ pub const UMTX_OP = enum(c_int) {
pub const UMTX_ABSTIME = 0x01;
pub const _umtx_time = extern struct {
- _timeout: timespec,
- _flags: u32,
- _clockid: u32,
+ timeout: timespec,
+ flags: u32,
+ clockid: clockid_t,
};
pub extern "c" fn _umtx_op(obj: usize, op: c_int, val: c_ulong, uaddr: usize, uaddr2: usize) c_int;
-pub const EAI = enum(c_int) {
- /// 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 IFNAMESIZE = 16;
-
-pub const AI = struct {
- /// get address to use bind()
- pub const PASSIVE = 0x00000001;
- /// fill ai_canonname
- pub const CANONNAME = 0x00000002;
- /// prevent host name resolution
- pub const NUMERICHOST = 0x00000004;
- /// prevent service name resolution
- pub const NUMERICSERV = 0x00000008;
- /// valid flags for addrinfo (not a standard def, apps should not use it)
- pub const MASK = (PASSIVE | CANONNAME | NUMERICHOST | NUMERICSERV | ADDRCONFIG | ALL | V4MAPPED);
- /// IPv6 and IPv4-mapped (with V4MAPPED)
- pub const ALL = 0x00000100;
- /// accept IPv4-mapped if kernel supports
- pub const V4MAPPED_CFG = 0x00000200;
- /// only if any address is assigned
- pub const ADDRCONFIG = 0x00000400;
- /// accept IPv4-mapped IPv6 address
- pub const V4MAPPED = 0x00000800;
- /// special recommended flags for getipnodebyname
- pub const DEFAULT = (V4MAPPED_CFG | ADDRCONFIG);
-};
-
-pub const blksize_t = i32;
-pub const blkcnt_t = i64;
-pub const clockid_t = i32;
pub const fflags_t = u32;
-pub const fsblkcnt_t = u64;
-pub const fsfilcnt_t = u64;
-pub const nlink_t = u64;
-pub const fd_t = i32;
-pub const pid_t = i32;
-pub const uid_t = u32;
-pub const gid_t = u32;
-pub const mode_t = u16;
-pub const off_t = i64;
-pub const ino_t = u64;
-pub const dev_t = u64;
-pub const time_t = i64;
-// The signedness is not constant across different architectures.
-pub const clock_t = isize;
-
-pub const socklen_t = u32;
-pub const suseconds_t = c_long;
-
-/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.
-pub const Kevent = extern struct {
- /// Identifier for this event.
- ident: usize,
- /// Filter for event.
- filter: i16,
- /// Action flags for kqueue.
- flags: u16,
- /// Filter flag value.
- fflags: u32,
- /// Filter data value.
- data: i64,
- /// Opaque user data identifier.
- udata: usize,
- /// Future extensions.
- _ext: [4]u64 = [_]u64{0} ** 4,
-};
-
-// Modes and flags for dlopen()
-// include/dlfcn.h
-
-pub const RTLD = struct {
- /// Bind function calls lazily.
- pub const LAZY = 1;
- /// Bind function calls immediately.
- pub const NOW = 2;
- pub const MODEMASK = 0x3;
- /// Make symbols globally available.
- pub const GLOBAL = 0x100;
- /// Opposite of GLOBAL, and the default.
- pub const LOCAL = 0;
- /// Trace loaded objects and exit.
- pub const TRACE = 0x200;
- /// Do not remove members.
- pub const NODELETE = 0x01000;
- /// Do not load if not already loaded.
- pub const NOLOAD = 0x02000;
-};
-
-pub const dl_phdr_info = extern struct {
- /// Module relocation base.
- dlpi_addr: if (builtin.target.ptrBitWidth() == 32) std.elf.Elf32_Addr else std.elf.Elf64_Addr,
- /// Module name.
- dlpi_name: ?[*:0]const u8,
- /// Pointer to module's phdr.
- dlpi_phdr: [*]std.elf.Phdr,
- /// Number of entries in phdr.
- dlpi_phnum: u16,
- /// Total number of loads.
- dlpi_adds: u64,
- /// Total number of unloads.
- dlpi_subs: u64,
- dlpi_tls_modid: usize,
- dlpi_tls_data: ?*anyopaque,
-};
-
-pub const Flock = extern struct {
- /// Starting offset.
- start: off_t,
- /// Number of consecutive bytes to be locked.
- /// A value of 0 means to the end of the file.
- len: off_t,
- /// Lock owner.
- pid: pid_t,
- /// Lock type.
- type: i16,
- /// Type of the start member.
- whence: i16,
- /// Remote system id or zero for local.
- sysid: i32,
-};
-
-pub const msghdr = extern struct {
- /// Optional address.
- msg_name: ?*sockaddr,
- /// Size of address.
- msg_namelen: socklen_t,
- /// Scatter/gather array.
- msg_iov: [*]iovec,
- /// Number of elements in msg_iov.
- msg_iovlen: i32,
- /// Ancillary data.
- msg_control: ?*anyopaque,
- /// Ancillary data buffer length.
- msg_controllen: socklen_t,
- /// Flags on received message.
- msg_flags: i32,
-};
-
-pub const msghdr_const = extern struct {
- /// Optional address.
- msg_name: ?*const sockaddr,
- /// Size of address.
- msg_namelen: socklen_t,
- /// Scatter/gather array.
- msg_iov: [*]iovec_const,
- /// Number of elements in msg_iov.
- msg_iovlen: i32,
- /// Ancillary data.
- msg_control: ?*anyopaque,
- /// Ancillary data buffer length.
- msg_controllen: socklen_t,
- /// Flags on received message.
- msg_flags: i32,
-};
pub const Stat = extern struct {
/// The inode's device.
@@ -352,81 +133,8 @@ pub const Stat = extern struct {
}
};
-pub const timespec = extern struct {
- tv_sec: isize,
- tv_nsec: isize,
-};
-
-pub const timeval = extern struct {
- /// seconds
- tv_sec: time_t,
- /// microseconds
- tv_usec: suseconds_t,
-};
-
-pub const dirent = extern struct {
- /// File number of entry.
- fileno: ino_t,
- /// Directory offset of entry.
- off: off_t,
- /// Length of this record.
- reclen: u16,
- /// File type, one of DT_.
- type: u8,
- pad0: u8 = 0,
- /// Length of the name member.
- namlen: u16,
- pad1: u16 = 0,
- /// Name of entry.
- name: [255:0]u8,
-};
-
-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 fsblkcnt_t = u64;
+pub const fsfilcnt_t = u64;
pub const CAP_RIGHTS_VERSION = 0;
@@ -540,788 +248,18 @@ pub const kinfo_file = extern struct {
_cap_spare: u64,
/// Path to file, if any.
path: [PATH_MAX - 1:0]u8,
-};
-
-pub const KINFO_FILE_SIZE = 1392;
-comptime {
- std.debug.assert(@sizeOf(kinfo_file) == KINFO_FILE_SIZE);
- std.debug.assert(@alignOf(kinfo_file) == @sizeOf(u64));
-}
-
-pub const CTL = struct {
- pub const KERN = 1;
- pub const DEBUG = 5;
-};
-
-pub const KERN = struct {
- pub const PROC = 14; // struct: process entries
- pub const PROC_PATHNAME = 12; // path to executable
- pub const PROC_FILEDESC = 33; // file descriptors for process
- pub const IOV_MAX = 35;
-};
-
-pub const PATH_MAX = 1024;
-pub const IOV_MAX = KERN.IOV_MAX;
-
-pub const STDIN_FILENO = 0;
-pub const STDOUT_FILENO = 1;
-pub const STDERR_FILENO = 2;
-
-pub const PROT = struct {
- pub const NONE = 0;
- pub const READ = 1;
- pub const WRITE = 2;
- pub const EXEC = 4;
-};
-
-pub const CLOCK = struct {
- pub const REALTIME = 0;
- pub const VIRTUAL = 1;
- pub const PROF = 2;
- pub const MONOTONIC = 4;
- pub const UPTIME = 5;
- pub const UPTIME_PRECISE = 7;
- pub const UPTIME_FAST = 8;
- pub const REALTIME_PRECISE = 9;
- pub const REALTIME_FAST = 10;
- pub const MONOTONIC_PRECISE = 11;
- pub const MONOTONIC_FAST = 12;
- pub const SECOND = 13;
- pub const THREAD_CPUTIME_ID = 14;
- pub const PROCESS_CPUTIME_ID = 15;
-};
-
-pub const MADV = struct {
- pub const NORMAL = 0;
- pub const RANDOM = 1;
- pub const SEQUENTIAL = 2;
- pub const WILLNEED = 3;
- pub const DONTNEED = 4;
- pub const FREE = 5;
- pub const NOSYNC = 6;
- pub const AUTOSYNC = 7;
- pub const NOCORE = 8;
- pub const CORE = 9;
- pub const PROTECT = 10;
-};
-
-pub const MSF = struct {
- pub const ASYNC = 1;
- pub const INVALIDATE = 2;
- pub const SYNC = 4;
-};
-
-pub const W = struct {
- pub const NOHANG = 1;
- pub const UNTRACED = 2;
- pub const STOPPED = UNTRACED;
- pub const CONTINUED = 4;
- pub const NOWAIT = 8;
- pub const EXITED = 16;
- pub const TRAPPED = 32;
-
- pub fn EXITSTATUS(s: u32) u8 {
- return @as(u8, @intCast((s & 0xff00) >> 8));
- }
- pub fn TERMSIG(s: u32) u32 {
- return s & 0x7f;
- }
- pub fn STOPSIG(s: u32) u32 {
- return EXITSTATUS(s);
- }
- pub fn IFEXITED(s: u32) bool {
- return TERMSIG(s) == 0;
- }
- pub fn IFSTOPPED(s: u32) bool {
- return @as(u16, @truncate((((s & 0xffff) *% 0x10001) >> 8))) > 0x7f00;
- }
- pub fn IFSIGNALED(s: u32) bool {
- return (s & 0xffff) -% 1 < 0xff;
- }
-};
-
-pub const SA = struct {
- pub const ONSTACK = 0x0001;
- pub const RESTART = 0x0002;
- pub const RESETHAND = 0x0004;
- pub const NOCLDSTOP = 0x0008;
- pub const NODEFER = 0x0010;
- pub const NOCLDWAIT = 0x0020;
- pub const SIGINFO = 0x0040;
-};
-
-pub const SIG = struct {
- pub const HUP = 1;
- pub const INT = 2;
- pub const QUIT = 3;
- pub const ILL = 4;
- pub const TRAP = 5;
- pub const ABRT = 6;
- pub const IOT = ABRT;
- pub const EMT = 7;
- pub const FPE = 8;
- pub const KILL = 9;
- pub const BUS = 10;
- pub const SEGV = 11;
- pub const SYS = 12;
- pub const PIPE = 13;
- pub const ALRM = 14;
- pub const TERM = 15;
- pub const URG = 16;
- pub const STOP = 17;
- pub const TSTP = 18;
- pub const CONT = 19;
- pub const CHLD = 20;
- pub const TTIN = 21;
- pub const TTOU = 22;
- pub const IO = 23;
- pub const XCPU = 24;
- pub const XFSZ = 25;
- pub const VTALRM = 26;
- pub const PROF = 27;
- pub const WINCH = 28;
- pub const INFO = 29;
- pub const USR1 = 30;
- pub const USR2 = 31;
- pub const THR = 32;
- pub const LWP = THR;
- pub const LIBRT = 33;
-
- pub const RTMIN = 65;
- pub const RTMAX = 126;
-
- pub const BLOCK = 1;
- pub const UNBLOCK = 2;
- pub const SETMASK = 3;
-
- 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 WORDS = 4;
- pub const MAXSIG = 128;
-
- pub inline fn IDX(sig: usize) usize {
- return sig - 1;
- }
- pub inline fn WORD(sig: usize) usize {
- return IDX(sig) >> 5;
- }
- pub inline fn BIT(sig: usize) usize {
- return 1 << (IDX(sig) & 31);
- }
- pub inline fn VALID(sig: usize) usize {
- return sig <= MAXSIG and sig > 0;
+ comptime {
+ assert(@sizeOf(@This()) == KINFO_FILE_SIZE);
+ assert(@alignOf(@This()) == @sizeOf(u64));
}
};
-pub const sigval = extern union {
- int: c_int,
- ptr: ?*anyopaque,
-};
-
-pub const sigset_t = extern struct {
- __bits: [SIG.WORDS]u32,
-};
-
-pub const empty_sigset = sigset_t{ .__bits = [_]u32{0} ** SIG.WORDS };
-
-// 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
-
-/// Command flags for fcntl(2).
-pub const F = struct {
- /// Duplicate file descriptor.
- pub const DUPFD = 0;
- /// Get file descriptor flags.
- pub const GETFD = 1;
- /// Set file descriptor flags.
- pub const SETFD = 2;
- /// Get file status flags.
- pub const GETFL = 3;
- /// Set file status flags.
- pub const SETFL = 4;
-
- /// Get SIGIO/SIGURG proc/pgrrp.
- pub const GETOWN = 5;
- /// Set SIGIO/SIGURG proc/pgrrp.
- pub const SETOWN = 6;
-
- /// Get record locking information.
- pub const GETLK = 11;
- /// Set record locking information.
- pub const SETLK = 12;
- /// Set record locking information and wait if blocked.
- pub const SETLKW = 13;
-
- /// Debugging support for remote locks.
- pub const SETLK_REMOTE = 14;
- /// Read ahead.
- pub const READAHEAD = 15;
-
- /// DUPFD with FD_CLOEXEC set.
- pub const DUPFD_CLOEXEC = 17;
- /// DUP2FD with FD_CLOEXEC set.
- pub const DUP2FD_CLOEXEC = 18;
-
- pub const ADD_SEALS = 19;
- pub const GET_SEALS = 20;
- /// Return `kinfo_file` for a file descriptor.
- pub const KINFO = 22;
-
- // Seals (ADD_SEALS, GET_SEALS)
- /// Prevent adding sealings.
- pub const SEAL_SEAL = 0x0001;
- /// May not shrink
- pub const SEAL_SHRINK = 0x0002;
- /// May not grow.
- pub const SEAL_GROW = 0x0004;
- /// May not write.
- pub const SEAL_WRITE = 0x0008;
-
- // Record locking flags (GETLK, SETLK, SETLKW).
- /// Shared or read lock.
- pub const RDLCK = 1;
- /// Unlock.
- pub const UNLCK = 2;
- /// Exclusive or write lock.
- pub const WRLCK = 3;
- /// Purge locks for a given system ID.
- pub const UNLCKSYS = 4;
- /// Cancel an async lock request.
- pub const CANCEL = 5;
-
- pub const SETOWN_EX = 15;
- pub const GETOWN_EX = 16;
-
- pub const GETOWNER_UIDS = 17;
-};
-
-pub const LOCK = struct {
- pub const SH = 1;
- pub const EX = 2;
- pub const UN = 8;
- pub const NB = 4;
-};
-
-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 RDM = 4;
- pub const SEQPACKET = 5;
-
- pub const CLOEXEC = 0x10000000;
- pub const NONBLOCK = 0x20000000;
-};
-
-pub const SO = struct {
- pub const DEBUG = 0x00000001;
- pub const ACCEPTCONN = 0x00000002;
- pub const REUSEADDR = 0x00000004;
- pub const KEEPALIVE = 0x00000008;
- pub const DONTROUTE = 0x00000010;
- pub const BROADCAST = 0x00000020;
- pub const USELOOPBACK = 0x00000040;
- pub const LINGER = 0x00000080;
- pub const OOBINLINE = 0x00000100;
- pub const REUSEPORT = 0x00000200;
- pub const TIMESTAMP = 0x00000400;
- pub const NOSIGPIPE = 0x00000800;
- pub const ACCEPTFILTER = 0x00001000;
- pub const BINTIME = 0x00002000;
- pub const NO_OFFLOAD = 0x00004000;
- pub const NO_DDP = 0x00008000;
- pub const REUSEPORT_LB = 0x00010000;
-
- pub const SNDBUF = 0x1001;
- pub const RCVBUF = 0x1002;
- pub const SNDLOWAT = 0x1003;
- pub const RCVLOWAT = 0x1004;
- pub const SNDTIMEO = 0x1005;
- pub const RCVTIMEO = 0x1006;
- pub const ERROR = 0x1007;
- pub const TYPE = 0x1008;
- pub const LABEL = 0x1009;
- pub const PEERLABEL = 0x1010;
- pub const LISTENQLIMIT = 0x1011;
- pub const LISTENQLEN = 0x1012;
- pub const LISTENINCQLEN = 0x1013;
- pub const SETFIB = 0x1014;
- pub const USER_COOKIE = 0x1015;
- pub const PROTOCOL = 0x1016;
- pub const PROTOTYPE = PROTOCOL;
- pub const TS_CLOCK = 0x1017;
- pub const MAX_PACING_RATE = 0x1018;
- pub const DOMAIN = 0x1019;
-};
-
-pub const SOL = struct {
- pub const SOCKET = 0xffff;
-};
-
-pub const PF = struct {
- pub const UNSPEC = AF.UNSPEC;
- pub const LOCAL = AF.LOCAL;
- pub const UNIX = PF.LOCAL;
- pub const INET = AF.INET;
- pub const IMPLINK = AF.IMPLINK;
- pub const PUP = AF.PUP;
- pub const CHAOS = AF.CHAOS;
- pub const NETBIOS = AF.NETBIOS;
- pub const ISO = AF.ISO;
- pub const OSI = AF.ISO;
- pub const ECMA = AF.ECMA;
- pub const DATAKIT = AF.DATAKIT;
- pub const CCITT = AF.CCITT;
- pub const DECnet = AF.DECnet;
- pub const DLI = AF.DLI;
- pub const LAT = AF.LAT;
- pub const HYLINK = AF.HYLINK;
- pub const APPLETALK = AF.APPLETALK;
- pub const ROUTE = AF.ROUTE;
- pub const LINK = AF.LINK;
- pub const XTP = AF.pseudo_XTP;
- pub const COIP = AF.COIP;
- pub const CNT = AF.CNT;
- pub const SIP = AF.SIP;
- pub const IPX = AF.IPX;
- pub const RTIP = AF.pseudo_RTIP;
- pub const PIP = AF.pseudo_PIP;
- pub const ISDN = AF.ISDN;
- pub const KEY = AF.pseudo_KEY;
- pub const INET6 = AF.pseudo_INET6;
- pub const NATM = AF.NATM;
- pub const ATM = AF.ATM;
- pub const NETGRAPH = AF.NETGRAPH;
- pub const SLOW = AF.SLOW;
- pub const SCLUSTER = AF.SCLUSTER;
- pub const ARP = AF.ARP;
- pub const BLUETOOTH = AF.BLUETOOTH;
- pub const IEEE80211 = AF.IEEE80211;
- pub const INET_SDP = AF.INET_SDP;
- pub const INET6_SDP = AF.INET6_SDP;
- pub const MAX = AF.MAX;
-};
-
-pub const AF = struct {
- pub const UNSPEC = 0;
- pub const UNIX = 1;
- pub const LOCAL = UNIX;
- pub const FILE = LOCAL;
- pub const INET = 2;
- pub const IMPLINK = 3;
- pub const PUP = 4;
- pub const CHAOS = 5;
- pub const NETBIOS = 6;
- pub const ISO = 7;
- pub const OSI = ISO;
- pub const ECMA = 8;
- pub const DATAKIT = 9;
- pub const CCITT = 10;
- pub const SNA = 11;
- pub const DECnet = 12;
- pub const DLI = 13;
- pub const LAT = 14;
- pub const HYLINK = 15;
- pub const APPLETALK = 16;
- pub const ROUTE = 17;
- pub const LINK = 18;
- pub const pseudo_XTP = 19;
- pub const COIP = 20;
- pub const CNT = 21;
- pub const pseudo_RTIP = 22;
- pub const IPX = 23;
- pub const SIP = 24;
- pub const pseudo_PIP = 25;
- pub const ISDN = 26;
- pub const E164 = ISDN;
- pub const pseudo_KEY = 27;
- pub const INET6 = 28;
- pub const NATM = 29;
- pub const ATM = 30;
- pub const pseudo_HDRCMPLT = 31;
- pub const NETGRAPH = 32;
- pub const SLOW = 33;
- pub const SCLUSTER = 34;
- pub const ARP = 35;
- pub const BLUETOOTH = 36;
- pub const IEEE80211 = 37;
- pub const INET_SDP = 40;
- pub const INET6_SDP = 42;
- pub const MAX = 42;
-};
-
-pub const DT = struct {
- pub const UNKNOWN = 0;
- pub const FIFO = 1;
- pub const CHR = 2;
- pub const DIR = 4;
- pub const BLK = 6;
- pub const REG = 8;
- pub const LNK = 10;
- pub const SOCK = 12;
- pub const WHT = 14;
-};
-
-/// 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;
-
-/// error, event data contains errno
-pub const EV_ERROR = 0x4000;
-
-/// 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;
-
-/// On input, NOTE_TRIGGER causes the event to be triggered for output.
-pub const NOTE_TRIGGER = 0x01000000;
-
-/// ignore input fflags
-pub const NOTE_FFNOP = 0x00000000;
-
-/// and fflags
-pub const NOTE_FFAND = 0x40000000;
-
-/// or fflags
-pub const NOTE_FFOR = 0x80000000;
-
-/// copy fflags
-pub const NOTE_FFCOPY = 0xc0000000;
-
-/// mask for operations
-pub const NOTE_FFCTRLMASK = 0xc0000000;
-pub const NOTE_FFLAGSMASK = 0x00ffffff;
-
-/// low water mark
-pub const NOTE_LOWAT = 0x00000001;
-
-/// behave like poll()
-pub const NOTE_FILE_POLL = 0x00000002;
-
-/// vnode was removed
-pub const NOTE_DELETE = 0x00000001;
-
-/// data contents changed
-pub const NOTE_WRITE = 0x00000002;
-
-/// size increased
-pub const NOTE_EXTEND = 0x00000004;
-
-/// attributes changed
-pub const NOTE_ATTRIB = 0x00000008;
-
-/// link count changed
-pub const NOTE_LINK = 0x00000010;
-
-/// vnode was renamed
-pub const NOTE_RENAME = 0x00000020;
-
-/// vnode access was revoked
-pub const NOTE_REVOKE = 0x00000040;
-
-/// vnode was opened
-pub const NOTE_OPEN = 0x00000080;
-
-/// file closed, fd did not allow write
-pub const NOTE_CLOSE = 0x00000100;
-
-/// file closed, fd did allow write
-pub const NOTE_CLOSE_WRITE = 0x00000200;
-
-/// file was read
-pub const NOTE_READ = 0x00000400;
-
-/// process exited
-pub const NOTE_EXIT = 0x80000000;
-
-/// process forked
-pub const NOTE_FORK = 0x40000000;
-
-/// process exec'd
-pub const NOTE_EXEC = 0x20000000;
-
-/// mask for signal & exit status
-pub const NOTE_PDATAMASK = 0x000fffff;
-pub const NOTE_PCTRLMASK = (~NOTE_PDATAMASK);
-
-/// data is seconds
-pub const NOTE_SECONDS = 0x00000001;
-
-/// data is milliseconds
-pub const NOTE_MSECONDS = 0x00000002;
-
-/// data is microseconds
-pub const NOTE_USECONDS = 0x00000004;
-
-/// data is nanoseconds
-pub const NOTE_NSECONDS = 0x00000008;
-
-/// timeout is absolute
-pub const NOTE_ABSTIME = 0x00000010;
-
-pub const T = struct {
- pub const IOCEXCL = 0x2000740d;
- pub const IOCNXCL = 0x2000740e;
- pub const IOCSCTTY = 0x20007461;
- pub const IOCGPGRP = 0x40047477;
- pub const IOCSPGRP = 0x80047476;
- pub const IOCOUTQ = 0x40047473;
- pub const IOCSTI = 0x80017472;
- pub const IOCGWINSZ = 0x40087468;
- pub const IOCSWINSZ = 0x80087467;
- pub const IOCMGET = 0x4004746a;
- pub const IOCMBIS = 0x8004746c;
- pub const IOCMBIC = 0x8004746b;
- pub const IOCMSET = 0x8004746d;
- pub const FIONREAD = 0x4004667f;
- pub const IOCCONS = 0x80047462;
- pub const IOCPKT = 0x80047470;
- pub const FIONBIO = 0x8004667e;
- pub const IOCNOTTY = 0x20007471;
- pub const IOCSETD = 0x8004741b;
- pub const IOCGETD = 0x4004741a;
- pub const IOCSBRK = 0x2000747b;
- pub const IOCCBRK = 0x2000747a;
- pub const IOCGSID = 0x40047463;
- pub const IOCGPTN = 0x4004740f;
- pub const IOCSIG = 0x2004745f;
-};
-
-pub const TCSA = enum(c_uint) {
- NOW,
- DRAIN,
- FLUSH,
- _,
-};
-
-pub const winsize = extern struct {
- ws_row: u16,
- ws_col: u16,
- ws_xpixel: u16,
- ws_ypixel: u16,
-};
-
-const NSIG = 32;
-
-/// 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,
- },
-
- /// see signal options
- flags: c_uint,
-
- /// signal mask to apply
- mask: sigset_t,
-};
-
-pub const siginfo_t = extern struct {
- // Signal number.
- signo: c_int,
- // Errno association.
- errno: c_int,
- /// Signal code.
- ///
- /// Cause of signal, one of the SI_ macros or signal-specific values, i.e.
- /// one of the FPE_... values for SIGFPE.
- /// This value is equivalent to the second argument to an old-style FreeBSD
- /// signal handler.
- code: c_int,
- /// Sending process.
- pid: pid_t,
- /// Sender's ruid.
- uid: uid_t,
- /// Exit value.
- status: c_int,
- /// Faulting instruction.
- addr: *allowzero anyopaque,
- /// Signal value.
- value: sigval,
- reason: extern union {
- fault: extern struct {
- /// Machine specific trap code.
- trapno: c_int,
- },
- timer: extern struct {
- timerid: c_int,
- overrun: c_int,
- },
- mesgq: extern struct {
- mqd: c_int,
- },
- poll: extern struct {
- /// Band event for SIGPOLL. UNUSED.
- band: c_long,
- },
- spare: extern struct {
- spare1: c_long,
- spare2: [7]c_int,
- },
- },
-};
-
-pub const mcontext_t = switch (builtin.cpu.arch) {
- .x86_64 => extern struct {
- onstack: u64,
- rdi: u64,
- rsi: u64,
- rdx: u64,
- rcx: u64,
- r8: u64,
- r9: u64,
- rax: u64,
- rbx: u64,
- rbp: u64,
- r10: u64,
- r11: u64,
- r12: u64,
- r13: u64,
- r14: u64,
- r15: u64,
- trapno: u32,
- fs: u16,
- gs: u16,
- addr: u64,
- flags: u32,
- es: u16,
- ds: u16,
- err: u64,
- rip: u64,
- cs: u64,
- rflags: u64,
- rsp: u64,
- ss: u64,
- len: u64,
- fpformat: u64,
- ownedfp: u64,
- fpstate: [64]u64 align(16),
- fsbase: u64,
- gsbase: u64,
- xfpustate: u64,
- xfpustate_len: u64,
- spare: [4]u64,
- },
- .aarch64 => extern struct {
- gpregs: extern struct {
- x: [30]u64,
- lr: u64,
- sp: u64,
- elr: u64,
- spsr: u32,
- _pad: u32,
- },
- fpregs: extern struct {
- q: [32]u128,
- sr: u32,
- cr: u32,
- flags: u32,
- _pad: u32,
- },
- flags: u32,
- _pad: u32,
- _spare: [8]u64,
- },
- else => struct {},
-};
-
-pub const REG = switch (builtin.cpu.arch) {
- .aarch64 => struct {
- pub const FP = 29;
- pub const SP = 31;
- pub const PC = 32;
- },
- .arm => struct {
- pub const FP = 11;
- pub const SP = 13;
- pub const PC = 15;
- },
- .x86_64 => struct {
- pub const RBP = 12;
- pub const RIP = 21;
- pub const RSP = 24;
- },
- else => struct {},
-};
+pub const KINFO_FILE_SIZE = 1392;
-pub const ucontext_t = extern struct {
- sigmask: sigset_t,
- mcontext: mcontext_t,
- link: ?*ucontext_t,
- stack: stack_t,
- flags: c_int,
- __spare__: [4]c_int,
+pub const MFD = struct {
+ pub const CLOEXEC = 0x0001;
+ pub const ALLOW_SEALING = 0x0002;
};
pub const E = enum(u16) {
@@ -1453,422 +391,3 @@ pub const E = enum(u16) {
INTEGRITY = 97, // Integrity check failed
_,
};
-
-pub const MINSIGSTKSZ = switch (builtin.cpu.arch) {
- .x86, .x86_64 => 2048,
- .arm, .aarch64 => 4096,
- else => @compileError("MINSIGSTKSZ not defined for this architecture"),
-};
-pub const SIGSTKSZ = MINSIGSTKSZ + 32768;
-
-pub const SS_ONSTACK = 1;
-pub const SS_DISABLE = 4;
-
-pub const stack_t = extern struct {
- /// Signal stack base.
- sp: *anyopaque,
- /// Signal stack length.
- size: usize,
- /// SS_DISABLE and/or SS_ONSTACK.
- flags: i32,
-};
-
-pub const S = struct {
- pub const IFMT = 0o170000;
-
- pub const IFIFO = 0o010000;
- pub const IFCHR = 0o020000;
- pub const IFDIR = 0o040000;
- pub const IFBLK = 0o060000;
- pub const IFREG = 0o100000;
- pub const IFLNK = 0o120000;
- pub const IFSOCK = 0o140000;
- pub const IFWHT = 0o160000;
-
- 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 ISFIFO(m: u32) bool {
- return m & IFMT == IFIFO;
- }
-
- pub fn ISCHR(m: u32) bool {
- return m & IFMT == IFCHR;
- }
-
- pub fn ISDIR(m: u32) bool {
- return m & IFMT == IFDIR;
- }
-
- pub fn ISBLK(m: u32) bool {
- return m & IFMT == IFBLK;
- }
-
- pub fn ISREG(m: u32) bool {
- return m & IFMT == IFREG;
- }
-
- pub fn ISLNK(m: u32) bool {
- return m & IFMT == IFLNK;
- }
-
- pub fn ISSOCK(m: u32) bool {
- return m & IFMT == IFSOCK;
- }
-
- pub fn IWHT(m: u32) bool {
- return m & IFMT == IFWHT;
- }
-};
-
-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 {
- /// dummy for IP
- pub const IP = 0;
- /// control message protocol
- pub const ICMP = 1;
- /// tcp
- pub const TCP = 6;
- /// user datagram protocol
- pub const UDP = 17;
- /// IP6 header
- pub const IPV6 = 41;
- /// raw IP packet
- pub const RAW = 255;
- /// IP6 hop-by-hop options
- pub const HOPOPTS = 0;
- /// group mgmt protocol
- pub const IGMP = 2;
- /// gateway^2 (deprecated)
- pub const GGP = 3;
- /// IPv4 encapsulation
- pub const IPV4 = 4;
- /// for compatibility
- pub const IPIP = IPV4;
- /// Stream protocol II
- pub const ST = 7;
- /// exterior gateway protocol
- pub const EGP = 8;
- /// private interior gateway
- pub const PIGP = 9;
- /// BBN RCC Monitoring
- pub const RCCMON = 10;
- /// network voice protocol
- pub const NVPII = 11;
- /// pup
- pub const PUP = 12;
- /// Argus
- pub const ARGUS = 13;
- /// EMCON
- pub const EMCON = 14;
- /// Cross Net Debugger
- pub const XNET = 15;
- /// Chaos
- pub const CHAOS = 16;
- /// Multiplexing
- pub const MUX = 18;
- /// DCN Measurement Subsystems
- pub const MEAS = 19;
- /// Host Monitoring
- pub const HMP = 20;
- /// Packet Radio Measurement
- pub const PRM = 21;
- /// xns idp
- pub const IDP = 22;
- /// Trunk-1
- pub const TRUNK1 = 23;
- /// Trunk-2
- pub const TRUNK2 = 24;
- /// Leaf-1
- pub const LEAF1 = 25;
- /// Leaf-2
- pub const LEAF2 = 26;
- /// Reliable Data
- pub const RDP = 27;
- /// Reliable Transaction
- pub const IRTP = 28;
- /// tp-4 w/ class negotiation
- pub const TP = 29;
- /// Bulk Data Transfer
- pub const BLT = 30;
- /// Network Services
- pub const NSP = 31;
- /// Merit Internodal
- pub const INP = 32;
- /// Datagram Congestion Control Protocol
- pub const DCCP = 33;
- /// Third Party Connect
- pub const @"3PC" = 34;
- /// InterDomain Policy Routing
- pub const IDPR = 35;
- /// XTP
- pub const XTP = 36;
- /// Datagram Delivery
- pub const DDP = 37;
- /// Control Message Transport
- pub const CMTP = 38;
- /// TP++ Transport
- pub const TPXX = 39;
- /// IL transport protocol
- pub const IL = 40;
- /// Source Demand Routing
- pub const SDRP = 42;
- /// IP6 routing header
- pub const ROUTING = 43;
- /// IP6 fragmentation header
- pub const FRAGMENT = 44;
- /// InterDomain Routing
- pub const IDRP = 45;
- /// resource reservation
- pub const RSVP = 46;
- /// General Routing Encap.
- pub const GRE = 47;
- /// Mobile Host Routing
- pub const MHRP = 48;
- /// BHA
- pub const BHA = 49;
- /// IP6 Encap Sec. Payload
- pub const ESP = 50;
- /// IP6 Auth Header
- pub const AH = 51;
- /// Integ. Net Layer Security
- pub const INLSP = 52;
- /// IP with encryption
- pub const SWIPE = 53;
- /// Next Hop Resolution
- pub const NHRP = 54;
- /// IP Mobility
- pub const MOBILE = 55;
- /// Transport Layer Security
- pub const TLSP = 56;
- /// SKIP
- pub const SKIP = 57;
- /// ICMP6
- pub const ICMPV6 = 58;
- /// IP6 no next header
- pub const NONE = 59;
- /// IP6 destination option
- pub const DSTOPTS = 60;
- /// any host internal protocol
- pub const AHIP = 61;
- /// CFTP
- pub const CFTP = 62;
- /// "hello" routing protocol
- pub const HELLO = 63;
- /// SATNET/Backroom EXPAK
- pub const SATEXPAK = 64;
- /// Kryptolan
- pub const KRYPTOLAN = 65;
- /// Remote Virtual Disk
- pub const RVD = 66;
- /// Pluribus Packet Core
- pub const IPPC = 67;
- /// Any distributed FS
- pub const ADFS = 68;
- /// Satnet Monitoring
- pub const SATMON = 69;
- /// VISA Protocol
- pub const VISA = 70;
- /// Packet Core Utility
- pub const IPCV = 71;
- /// Comp. Prot. Net. Executive
- pub const CPNX = 72;
- /// Comp. Prot. HeartBeat
- pub const CPHB = 73;
- /// Wang Span Network
- pub const WSN = 74;
- /// Packet Video Protocol
- pub const PVP = 75;
- /// BackRoom SATNET Monitoring
- pub const BRSATMON = 76;
- /// Sun net disk proto (temp.)
- pub const ND = 77;
- /// WIDEBAND Monitoring
- pub const WBMON = 78;
- /// WIDEBAND EXPAK
- pub const WBEXPAK = 79;
- /// ISO cnlp
- pub const EON = 80;
- /// VMTP
- pub const VMTP = 81;
- /// Secure VMTP
- pub const SVMTP = 82;
- /// Banyon VINES
- pub const VINES = 83;
- /// TTP
- pub const TTP = 84;
- /// NSFNET-IGP
- pub const IGP = 85;
- /// dissimilar gateway prot.
- pub const DGP = 86;
- /// TCF
- pub const TCF = 87;
- /// Cisco/GXS IGRP
- pub const IGRP = 88;
- /// OSPFIGP
- pub const OSPFIGP = 89;
- /// Strite RPC protocol
- pub const SRPC = 90;
- /// Locus Address Resoloution
- pub const LARP = 91;
- /// Multicast Transport
- pub const MTP = 92;
- /// AX.25 Frames
- pub const AX25 = 93;
- /// IP encapsulated in IP
- pub const IPEIP = 94;
- /// Mobile Int.ing control
- pub const MICP = 95;
- /// Semaphore Comm. security
- pub const SCCSP = 96;
- /// Ethernet IP encapsulation
- pub const ETHERIP = 97;
- /// encapsulation header
- pub const ENCAP = 98;
- /// any private encr. scheme
- pub const APES = 99;
- /// GMTP
- pub const GMTP = 100;
- /// payload compression (IPComp)
- pub const IPCOMP = 108;
- /// SCTP
- pub const SCTP = 132;
- /// IPv6 Mobility Header
- pub const MH = 135;
- /// UDP-Lite
- pub const UDPLITE = 136;
- /// IP6 Host Identity Protocol
- pub const HIP = 139;
- /// IP6 Shim6 Protocol
- pub const SHIM6 = 140;
- /// Protocol Independent Mcast
- pub const PIM = 103;
- /// CARP
- pub const CARP = 112;
- /// PGM
- pub const PGM = 113;
- /// MPLS-in-IP
- pub const MPLS = 137;
- /// PFSYNC
- pub const PFSYNC = 240;
- /// Reserved
- pub const RESERVED_253 = 253;
- /// Reserved
- pub const RESERVED_254 = 254;
-};
-
-pub const rlimit_resource = enum(c_int) {
- CPU = 0,
- FSIZE = 1,
- DATA = 2,
- STACK = 3,
- CORE = 4,
- RSS = 5,
- MEMLOCK = 6,
- NPROC = 7,
- NOFILE = 8,
- SBSIZE = 9,
- VMEM = 10,
- NPTS = 11,
- SWAP = 12,
- KQUEUES = 13,
- UMTXP = 14,
- _,
-
- pub const AS: rlimit_resource = .VMEM;
-};
-
-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;
-};
-
-pub const nfds_t = u32;
-
-pub const pollfd = extern struct {
- fd: fd_t,
- events: i16,
- revents: i16,
-};
-
-pub const POLL = struct {
- /// any readable data available.
- pub const IN = 0x0001;
- /// OOB/Urgent readable data.
- pub const PRI = 0x0002;
- /// file descriptor is writeable.
- pub const OUT = 0x0004;
- /// non-OOB/URG data available.
- pub const RDNORM = 0x0040;
- /// no write type differentiation.
- pub const WRNORM = OUT;
- /// OOB/Urgent readable data.
- pub const RDBAND = 0x0080;
- /// OOB/Urgent data can be written.
- pub const WRBAND = 0x0100;
- /// like IN, except ignore EOF.
- pub const INIGNEOF = 0x2000;
- /// some poll error occurred.
- pub const ERR = 0x0008;
- /// file descriptor was "hung up".
- pub const HUP = 0x0010;
- /// requested events "invalid".
- pub const NVAL = 0x0020;
-
- pub const STANDARD = IN | PRI | OUT | RDNORM | RDBAND | WRBAND | ERR | HUP | NVAL;
-};
-
-pub const NAME_MAX = 255;
-
-pub const MFD = struct {
- pub const CLOEXEC = 0x0001;
- pub const ALLOW_SEALING = 0x0002;
-};
-
-pub extern "c" fn memfd_create(name: [*:0]const u8, flags: c_uint) c_int;
-pub extern "c" fn copy_file_range(fd_in: fd_t, off_in: ?*off_t, fd_out: fd_t, off_out: ?*off_t, len: usize, flags: u32) usize;
-pub extern "c" fn eventfd(initval: c_uint, flags: c_uint) c_int;
-pub extern "c" fn dup3(old: c_int, new: c_int, flags: c_uint) c_int;
lib/std/c/haiku.zig
@@ -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;
lib/std/c/linux.zig
@@ -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;
lib/std/c/netbsd.zig
@@ -1,786 +1,14 @@
const std = @import("../std.zig");
-const assert = std.debug.assert;
-const builtin = @import("builtin");
-const maxInt = std.math.maxInt;
-const iovec = std.posix.iovec;
-const iovec_const = std.posix.iovec_const;
-const timezone = std.c.timezone;
-const rusage = std.c.rusage;
+const clock_t = std.c.clock_t;
+const pid_t = std.c.pid_t;
+const pthread_t = std.c.pthread_t;
+const sigval_t = std.c.sigval_t;
+const uid_t = std.c.uid_t;
-extern "c" fn __errno() *c_int;
-pub const _errno = __errno;
-
-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 _lwp_self() lwpid_t;
-
-pub extern "c" fn pipe2(fds: *[2]fd_t, flags: std.c.O) c_int;
-pub extern "c" fn arc4random_buf(buf: [*]u8, len: usize) void;
-
-pub extern "c" fn __getdents30(fd: c_int, buf_ptr: [*]u8, nbytes: usize) c_int;
-pub const getdents = __getdents30;
-
-pub extern "c" fn __sigaltstack14(ss: ?*stack_t, old_ss: ?*stack_t) c_int;
-pub const sigaltstack = __sigaltstack14;
-
-pub extern "c" fn posix_memalign(memptr: *?*anyopaque, alignment: usize, size: usize) c_int;
-
-pub const pthread_spin_t = switch (builtin.cpu.arch) {
- .aarch64, .aarch64_be, .aarch64_32 => u8,
- .mips, .mipsel, .mips64, .mips64el => u32,
- .powerpc, .powerpc64, .powerpc64le => i32,
- .x86, .x86_64 => u8,
- .arm, .armeb, .thumb, .thumbeb => i32,
- .sparc, .sparcel, .sparc64 => u8,
- .riscv32, .riscv64 => u32,
- else => @compileError("undefined pthread_spin_t for this arch"),
-};
-
-pub const padded_pthread_spin_t = switch (builtin.cpu.arch) {
- .x86, .x86_64 => u32,
- .sparc, .sparcel, .sparc64 => u32,
- else => pthread_spin_t,
-};
-
-pub const pthread_attr_t = extern struct {
- pta_magic: u32,
- pta_flags: i32,
- pta_private: ?*anyopaque,
-};
-
-pub const sem_t = ?*opaque {};
-
-pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8, arg: ?*anyopaque) c_int;
-pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) c_int;
-
-pub const blkcnt_t = i64;
-pub const blksize_t = i32;
-pub const clock_t = u32;
-pub const dev_t = u64;
-pub const fd_t = i32;
-pub const gid_t = u32;
-pub const ino_t = u64;
-pub const mode_t = u32;
-pub const nlink_t = u32;
-pub const off_t = i64;
-pub const pid_t = i32;
-pub const socklen_t = u32;
-pub const time_t = i64;
-pub const uid_t = u32;
pub const lwpid_t = i32;
-pub const suseconds_t = c_int;
-
-/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.
-pub const Kevent = extern struct {
- ident: usize,
- filter: i32,
- flags: u32,
- fflags: u32,
- data: i64,
- udata: usize,
-};
-
-pub const RTLD = struct {
- pub const LAZY = 1;
- pub const NOW = 2;
- pub const GLOBAL = 0x100;
- pub const LOCAL = 0x200;
- pub const NODELETE = 0x01000;
- pub const NOLOAD = 0x02000;
-
- pub const NEXT = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -1)))));
- pub const DEFAULT = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -2)))));
- pub const SELF = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -3)))));
-};
-
-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 {
- start: off_t,
- len: off_t,
- pid: pid_t,
- type: i16,
- whence: i16,
-};
-
-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 EAI = enum(c_int) {
- /// 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 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 msghdr_const = extern struct {
- /// optional address
- msg_name: ?*const sockaddr,
-
- /// size of address
- msg_namelen: socklen_t,
-
- /// scatter/gather array
- msg_iov: [*]const iovec_const,
-
- /// # elements in msg_iov
- msg_iovlen: i32,
-
- /// ancillary data
- msg_control: ?*const anyopaque,
-
- /// ancillary data buffer len
- msg_controllen: socklen_t,
-
- /// flags on received message
- msg_flags: i32,
-};
-
-/// The stat structure used by libc.
-pub const Stat = extern struct {
- dev: dev_t,
- mode: mode_t,
- ino: ino_t,
- nlink: nlink_t,
- uid: uid_t,
- gid: gid_t,
- rdev: dev_t,
- atim: timespec,
- mtim: timespec,
- ctim: timespec,
- birthtim: timespec,
- size: off_t,
- blocks: blkcnt_t,
- blksize: blksize_t,
- flags: u32,
- gen: u32,
- __spare: [2]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;
- }
-
- pub fn birthtime(self: @This()) timespec {
- return self.birthtim;
- }
-};
-
-pub const timespec = extern struct {
- tv_sec: i64,
- tv_nsec: isize,
-};
-
-pub const timeval = extern struct {
- /// seconds
- tv_sec: time_t,
- /// microseconds
- tv_usec: suseconds_t,
-};
-
-pub const MAXNAMLEN = 511;
-
-pub const dirent = extern struct {
- fileno: ino_t,
- reclen: u16,
- namlen: u16,
- type: u8,
- name: [MAXNAMLEN + 1]u8,
-};
-
-pub const SOCK = struct {
- pub const STREAM = 1;
- pub const DGRAM = 2;
- pub const RAW = 3;
- pub const RDM = 4;
- pub const SEQPACKET = 5;
- pub const CONN_DGRAM = 6;
- pub const DCCP = CONN_DGRAM;
-
- pub const CLOEXEC = 0x10000000;
- pub const NONBLOCK = 0x20000000;
- pub const NOSIGPIPE = 0x40000000;
- pub const FLAGS_MASK = 0xf0000000;
-};
-
-pub const SO = struct {
- pub const DEBUG = 0x0001;
- pub const ACCEPTCONN = 0x0002;
- pub const REUSEADDR = 0x0004;
- pub const KEEPALIVE = 0x0008;
- pub const DONTROUTE = 0x0010;
- pub const BROADCAST = 0x0020;
- pub const USELOOPBACK = 0x0040;
- pub const LINGER = 0x0080;
- pub const OOBINLINE = 0x0100;
- pub const REUSEPORT = 0x0200;
- pub const NOSIGPIPE = 0x0800;
- pub const ACCEPTFILTER = 0x1000;
- pub const TIMESTAMP = 0x2000;
- pub const RERROR = 0x4000;
-
- pub const SNDBUF = 0x1001;
- pub const RCVBUF = 0x1002;
- pub const SNDLOWAT = 0x1003;
- pub const RCVLOWAT = 0x1004;
- pub const ERROR = 0x1007;
- pub const TYPE = 0x1008;
- pub const OVERFLOWED = 0x1009;
-
- pub const NOHEADER = 0x100a;
- pub const SNDTIMEO = 0x100b;
- pub const RCVTIMEO = 0x100c;
-};
-
-pub const SOL = struct {
- pub const SOCKET = 0xffff;
-};
-
-pub const PF = struct {
- pub const UNSPEC = AF.UNSPEC;
- pub const LOCAL = AF.LOCAL;
- pub const UNIX = PF.LOCAL;
- pub const INET = AF.INET;
- pub const IMPLINK = AF.IMPLINK;
- pub const PUP = AF.PUP;
- pub const CHAOS = AF.CHAOS;
- pub const NS = AF.NS;
- pub const ISO = AF.ISO;
- pub const OSI = AF.ISO;
- pub const ECMA = AF.ECMA;
- pub const DATAKIT = AF.DATAKIT;
- pub const CCITT = AF.CCITT;
- pub const SNA = AF.SNA;
- pub const DECnet = AF.DECnet;
- pub const DLI = AF.DLI;
- pub const LAT = AF.LAT;
- pub const HYLINK = AF.HYLINK;
- pub const APPLETALK = AF.APPLETALK;
- pub const OROUTE = AF.OROUTE;
- pub const LINK = AF.LINK;
- pub const COIP = AF.COIP;
- pub const CNT = AF.CNT;
- pub const INET6 = AF.INET6;
- pub const IPX = AF.IPX;
- pub const ISDN = AF.ISDN;
- pub const E164 = AF.E164;
- pub const NATM = AF.NATM;
- pub const ARP = AF.ARP;
- pub const BLUETOOTH = AF.BLUETOOTH;
- pub const MPLS = AF.MPLS;
- pub const ROUTE = AF.ROUTE;
- pub const CAN = AF.CAN;
- pub const ETHER = AF.ETHER;
- pub const MAX = AF.MAX;
-};
-
-pub const AF = struct {
- pub const UNSPEC = 0;
- pub const LOCAL = 1;
- pub const UNIX = LOCAL;
- pub const INET = 2;
- pub const IMPLINK = 3;
- pub const PUP = 4;
- pub const CHAOS = 5;
- pub const NS = 6;
- pub const ISO = 7;
- pub const OSI = ISO;
- pub const ECMA = 8;
- pub const DATAKIT = 9;
- pub const CCITT = 10;
- pub const SNA = 11;
- pub const DECnet = 12;
- pub const DLI = 13;
- pub const LAT = 14;
- pub const HYLINK = 15;
- pub const APPLETALK = 16;
- pub const OROUTE = 17;
- pub const LINK = 18;
- pub const COIP = 20;
- pub const CNT = 21;
- pub const IPX = 23;
- pub const INET6 = 24;
- pub const ISDN = 26;
- pub const E164 = ISDN;
- pub const NATM = 27;
- pub const ARP = 28;
- pub const BLUETOOTH = 31;
- pub const IEEE80211 = 32;
- pub const MPLS = 33;
- pub const ROUTE = 34;
- pub const CAN = 35;
- pub const ETHER = 36;
- pub const MAX = 37;
-};
-
-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,
- };
-
- /// Definitions for UNIX IPC domain.
- pub const un = extern struct {
- /// total sockaddr length
- len: u8 = @sizeOf(un),
-
- family: sa_family_t = AF.LOCAL,
-
- /// path name
- path: [104]u8,
- };
-};
-
-pub const IFNAMESIZE = 16;
-
-pub const AI = struct {
- /// get address to use bind()
- pub const PASSIVE = 0x00000001;
- /// fill ai_canonname
- pub const CANONNAME = 0x00000002;
- /// prevent host name resolution
- pub const NUMERICHOST = 0x00000004;
- /// prevent service name resolution
- pub const NUMERICSERV = 0x00000008;
- /// only if any address is assigned
- pub const ADDRCONFIG = 0x00000400;
-};
-
-pub const CTL = struct {
- pub const KERN = 1;
- pub const DEBUG = 5;
-};
-
-pub const KERN = struct {
- pub const PROC_ARGS = 48; // struct: process argv/env
- pub const PROC_PATHNAME = 5; // path to executable
- pub const IOV_MAX = 38;
-};
-
-pub const PATH_MAX = 1024;
-pub const NAME_MAX = 255;
-pub const IOV_MAX = KERN.IOV_MAX;
-
-pub const STDIN_FILENO = 0;
-pub const STDOUT_FILENO = 1;
-pub const STDERR_FILENO = 2;
-
-pub const PROT = struct {
- pub const NONE = 0;
- pub const READ = 1;
- pub const WRITE = 2;
- pub const EXEC = 4;
-};
-
-pub const CLOCK = struct {
- pub const REALTIME = 0;
- pub const VIRTUAL = 1;
- pub const PROF = 2;
- pub const MONOTONIC = 3;
- pub const THREAD_CPUTIME_ID = 0x20000000;
- pub const PROCESS_CPUTIME_ID = 0x40000000;
-};
-
-pub const MSF = struct {
- pub const ASYNC = 1;
- pub const INVALIDATE = 2;
- pub const SYNC = 4;
-};
-
-pub const W = struct {
- pub const NOHANG = 0x00000001;
- pub const UNTRACED = 0x00000002;
- pub const STOPPED = UNTRACED;
- pub const CONTINUED = 0x00000010;
- pub const NOWAIT = 0x00010000;
- pub const EXITED = 0x00000020;
- pub const TRAPPED = 0x00000040;
-
- pub fn EXITSTATUS(s: u32) u8 {
- return @as(u8, @intCast((s >> 8) & 0xff));
- }
- pub fn TERMSIG(s: u32) u32 {
- return s & 0x7f;
- }
- pub fn STOPSIG(s: u32) u32 {
- return EXITSTATUS(s);
- }
- pub fn IFEXITED(s: u32) bool {
- return TERMSIG(s) == 0;
- }
- pub fn IFCONTINUED(s: u32) bool {
- return ((s & 0x7f) == 0xffff);
- }
-
- pub fn IFSTOPPED(s: u32) bool {
- return ((s & 0x7f != 0x7f) and !IFCONTINUED(s));
- }
-
- pub fn IFSIGNALED(s: u32) bool {
- return !IFSTOPPED(s) and !IFCONTINUED(s) and !IFEXITED(s);
- }
-};
-
-pub const SA = struct {
- pub const ONSTACK = 0x0001;
- pub const RESTART = 0x0002;
- pub const RESETHAND = 0x0004;
- pub const NOCLDSTOP = 0x0008;
- pub const NODEFER = 0x0010;
- pub const NOCLDWAIT = 0x0020;
- pub const SIGINFO = 0x0040;
-};
-
-// 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 = 0;
- pub const GETFD = 1;
- pub const SETFD = 2;
- pub const GETFL = 3;
- pub const SETFL = 4;
- pub const GETOWN = 5;
- pub const SETOWN = 6;
- pub const GETLK = 7;
- pub const SETLK = 8;
- pub const SETLKW = 9;
- pub const CLOSEM = 10;
- pub const MAXFD = 11;
- pub const DUPFD_CLOEXEC = 12;
- pub const GETNOSIGPIPE = 13;
- pub const SETNOSIGPIPE = 14;
- pub const GETPATH = 15;
-
- pub const RDLCK = 1;
- pub const WRLCK = 3;
- pub const UNLCK = 2;
-};
-
-pub const LOCK = struct {
- pub const SH = 1;
- pub const EX = 2;
- pub const UN = 8;
- pub const NB = 4;
-};
-
-pub const FD_CLOEXEC = 1;
-
-pub const SEEK = struct {
- pub const SET = 0;
- pub const CUR = 1;
- pub const END = 2;
-};
-
-pub const DT = struct {
- pub const UNKNOWN = 0;
- pub const FIFO = 1;
- pub const CHR = 2;
- pub const DIR = 4;
- pub const BLK = 6;
- pub const REG = 8;
- pub const LNK = 10;
- pub const SOCK = 12;
- pub const WHT = 14;
-};
-
-/// 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 = 0;
-pub const EVFILT_WRITE = 1;
-
-/// attached to aio requests
-pub const EVFILT_AIO = 2;
-
-/// attached to vnodes
-pub const EVFILT_VNODE = 3;
-
-/// attached to struct proc
-pub const EVFILT_PROC = 4;
-
-/// attached to struct proc
-pub const EVFILT_SIGNAL = 5;
-
-/// timers
-pub const EVFILT_TIMER = 6;
-
-/// Filesystem events
-pub const EVFILT_FS = 7;
-
-/// User events
-pub const EVFILT_USER = 1;
-
-/// On input, NOTE_TRIGGER causes the event to be triggered for output.
-pub const NOTE_TRIGGER = 0x08000000;
-
-/// low water mark
-pub const NOTE_LOWAT = 0x00000001;
-
-/// vnode was removed
-pub const NOTE_DELETE = 0x00000001;
-
-/// data contents changed
-pub const NOTE_WRITE = 0x00000002;
-
-/// size increased
-pub const NOTE_EXTEND = 0x00000004;
-
-/// attributes changed
-pub const NOTE_ATTRIB = 0x00000008;
-
-/// link count changed
-pub const NOTE_LINK = 0x00000010;
-
-/// vnode was renamed
-pub const NOTE_RENAME = 0x00000020;
-
-/// vnode access was revoked
-pub const NOTE_REVOKE = 0x00000040;
-
-/// process exited
-pub const NOTE_EXIT = 0x80000000;
-
-/// process forked
-pub const NOTE_FORK = 0x40000000;
-
-/// process exec'd
-pub const NOTE_EXEC = 0x20000000;
-
-/// mask for signal & exit status
-pub const NOTE_PDATAMASK = 0x000fffff;
-pub const NOTE_PCTRLMASK = 0xf0000000;
-
-pub const T = struct {
- pub const IOCCBRK = 0x2000747a;
- pub const IOCCDTR = 0x20007478;
- pub const IOCCONS = 0x80047462;
- pub const IOCDCDTIMESTAMP = 0x40107458;
- pub const IOCDRAIN = 0x2000745e;
- pub const IOCEXCL = 0x2000740d;
- pub const IOCEXT = 0x80047460;
- pub const IOCFLAG_CDTRCTS = 0x10;
- pub const IOCFLAG_CLOCAL = 0x2;
- pub const IOCFLAG_CRTSCTS = 0x4;
- pub const IOCFLAG_MDMBUF = 0x8;
- pub const IOCFLAG_SOFTCAR = 0x1;
- pub const IOCFLUSH = 0x80047410;
- pub const IOCGETA = 0x402c7413;
- pub const IOCGETD = 0x4004741a;
- pub const IOCGFLAGS = 0x4004745d;
- pub const IOCGLINED = 0x40207442;
- pub const IOCGPGRP = 0x40047477;
- pub const IOCGQSIZE = 0x40047481;
- pub const IOCGRANTPT = 0x20007447;
- pub const IOCGSID = 0x40047463;
- pub const IOCGSIZE = 0x40087468;
- pub const IOCGWINSZ = 0x40087468;
- pub const IOCMBIC = 0x8004746b;
- pub const IOCMBIS = 0x8004746c;
- pub const IOCMGET = 0x4004746a;
- pub const IOCMSET = 0x8004746d;
- pub const IOCM_CAR = 0x40;
- pub const IOCM_CD = 0x40;
- pub const IOCM_CTS = 0x20;
- pub const IOCM_DSR = 0x100;
- pub const IOCM_DTR = 0x2;
- pub const IOCM_LE = 0x1;
- pub const IOCM_RI = 0x80;
- pub const IOCM_RNG = 0x80;
- pub const IOCM_RTS = 0x4;
- pub const IOCM_SR = 0x10;
- pub const IOCM_ST = 0x8;
- pub const IOCNOTTY = 0x20007471;
- pub const IOCNXCL = 0x2000740e;
- pub const IOCOUTQ = 0x40047473;
- pub const IOCPKT = 0x80047470;
- pub const IOCPKT_DATA = 0x0;
- pub const IOCPKT_DOSTOP = 0x20;
- pub const IOCPKT_FLUSHREAD = 0x1;
- pub const IOCPKT_FLUSHWRITE = 0x2;
- pub const IOCPKT_IOCTL = 0x40;
- pub const IOCPKT_NOSTOP = 0x10;
- pub const IOCPKT_START = 0x8;
- pub const IOCPKT_STOP = 0x4;
- pub const IOCPTMGET = 0x40287446;
- pub const IOCPTSNAME = 0x40287448;
- pub const IOCRCVFRAME = 0x80087445;
- pub const IOCREMOTE = 0x80047469;
- pub const IOCSBRK = 0x2000747b;
- pub const IOCSCTTY = 0x20007461;
- pub const IOCSDTR = 0x20007479;
- pub const IOCSETA = 0x802c7414;
- pub const IOCSETAF = 0x802c7416;
- pub const IOCSETAW = 0x802c7415;
- pub const IOCSETD = 0x8004741b;
- pub const IOCSFLAGS = 0x8004745c;
- pub const IOCSIG = 0x2000745f;
- pub const IOCSLINED = 0x80207443;
- pub const IOCSPGRP = 0x80047476;
- pub const IOCSQSIZE = 0x80047480;
- pub const IOCSSIZE = 0x80087467;
- pub const IOCSTART = 0x2000746e;
- pub const IOCSTAT = 0x80047465;
- pub const IOCSTI = 0x80017472;
- pub const IOCSTOP = 0x2000746f;
- pub const IOCSWINSZ = 0x80087467;
- pub const IOCUCNTL = 0x80047466;
- pub const IOCXMTFRAME = 0x80087444;
-};
-
-pub const TCSA = enum(c_uint) {
- NOW,
- DRAIN,
- FLUSH,
- _,
-};
+pub extern "c" fn _lwp_self() lwpid_t;
+pub extern "c" fn pthread_setname_np(thread: pthread_t, name: [*:0]const u8, arg: ?*anyopaque) c_int;
pub const TCIFLUSH = 1;
pub const TCOFLUSH = 2;
@@ -790,104 +18,6 @@ pub const TCOON = 2;
pub const TCIOFF = 3;
pub const TCION = 4;
-pub const winsize = extern struct {
- ws_row: u16,
- ws_col: u16,
- ws_xpixel: u16,
- ws_ypixel: u16,
-};
-
-const NSIG = 32;
-
-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 WORDS = 4;
- pub const MAXSIG = 128;
-
- pub const BLOCK = 1;
- pub const UNBLOCK = 2;
- pub const SETMASK = 3;
-
- pub const HUP = 1;
- pub const INT = 2;
- pub const QUIT = 3;
- pub const ILL = 4;
- pub const TRAP = 5;
- pub const ABRT = 6;
- pub const IOT = ABRT;
- pub const EMT = 7;
- pub const FPE = 8;
- pub const KILL = 9;
- pub const BUS = 10;
- pub const SEGV = 11;
- pub const SYS = 12;
- pub const PIPE = 13;
- pub const ALRM = 14;
- pub const TERM = 15;
- pub const URG = 16;
- pub const STOP = 17;
- pub const TSTP = 18;
- pub const CONT = 19;
- pub const CHLD = 20;
- pub const TTIN = 21;
- pub const TTOU = 22;
- pub const IO = 23;
- pub const XCPU = 24;
- pub const XFSZ = 25;
- pub const VTALRM = 26;
- pub const PROF = 27;
- pub const WINCH = 28;
- pub const INFO = 29;
- pub const USR1 = 30;
- pub const USR2 = 31;
- pub const PWR = 32;
-
- pub const RTMIN = 33;
- pub const RTMAX = 63;
-
- pub inline fn IDX(sig: usize) usize {
- return sig - 1;
- }
- pub inline fn WORD(sig: usize) usize {
- return IDX(sig) >> 5;
- }
- pub inline fn BIT(sig: usize) usize {
- return 1 << (IDX(sig) & 31);
- }
- pub inline fn VALID(sig: usize) usize {
- return sig <= MAXSIG and sig > 0;
- }
-};
-
-/// 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,
- /// signal options
- flags: c_uint,
-};
-
-pub const sigval_t = extern union {
- int: i32,
- ptr: ?*anyopaque,
-};
-
-pub const siginfo_t = extern union {
- pad: [128]u8,
- info: _ksiginfo,
-};
-
pub const _ksiginfo = extern struct {
signo: i32,
code: i32,
@@ -933,85 +63,6 @@ pub const _ksiginfo = extern struct {
} align(@sizeOf(usize)),
};
-pub const sigset_t = extern struct {
- __bits: [SIG.WORDS]u32,
-};
-
-pub const empty_sigset = sigset_t{ .__bits = [_]u32{0} ** SIG.WORDS };
-
-pub const mcontext_t = switch (builtin.cpu.arch) {
- .aarch64 => extern struct {
- gregs: [35]u64,
- fregs: [528]u8 align(16),
- spare: [8]u64,
- },
- .x86_64 => extern struct {
- gregs: [26]u64,
- mc_tlsbase: u64,
- fpregs: [512]u8 align(8),
- },
- else => struct {},
-};
-
-pub const REG = switch (builtin.cpu.arch) {
- .aarch64 => struct {
- pub const FP = 29;
- pub const SP = 31;
- pub const PC = 32;
- },
- .arm => struct {
- pub const FP = 11;
- pub const SP = 13;
- pub const PC = 15;
- },
- .x86_64 => struct {
- pub const RDI = 0;
- pub const RSI = 1;
- pub const RDX = 2;
- pub const RCX = 3;
- pub const R8 = 4;
- pub const R9 = 5;
- pub const R10 = 6;
- pub const R11 = 7;
- pub const R12 = 8;
- pub const R13 = 9;
- pub const R14 = 10;
- pub const R15 = 11;
- pub const RBP = 12;
- pub const RBX = 13;
- pub const RAX = 14;
- pub const GS = 15;
- pub const FS = 16;
- pub const ES = 17;
- pub const DS = 18;
- pub const TRAPNO = 19;
- pub const ERR = 20;
- pub const RIP = 21;
- pub const CS = 22;
- pub const RFLAGS = 23;
- pub const RSP = 24;
- pub const SS = 25;
- },
- else => struct {},
-};
-
-pub const ucontext_t = extern struct {
- flags: u32,
- link: ?*ucontext_t,
- sigmask: sigset_t,
- stack: stack_t,
- mcontext: mcontext_t,
- __pad: [
- switch (builtin.cpu.arch) {
- .x86 => 4,
- .mips, .mipsel, .mips64, .mips64el => 14,
- .arm, .armeb, .thumb, .thumbeb => 1,
- .sparc, .sparcel, .sparc64 => if (@sizeOf(usize) == 4) 43 else 8,
- else => 0,
- }
- ]u32,
-};
-
pub const E = enum(u16) {
/// No error occurred.
SUCCESS = 0,
@@ -1150,220 +201,3 @@ pub const E = enum(u16) {
_,
};
-
-pub const MINSIGSTKSZ = 8192;
-pub const SIGSTKSZ = MINSIGSTKSZ + 32768;
-
-pub const SS_ONSTACK = 1;
-pub const SS_DISABLE = 4;
-
-pub const stack_t = extern struct {
- sp: [*]u8,
- size: isize,
- flags: i32,
-};
-
-pub const S = struct {
- pub const IFMT = 0o170000;
-
- pub const IFIFO = 0o010000;
- pub const IFCHR = 0o020000;
- pub const IFDIR = 0o040000;
- pub const IFBLK = 0o060000;
- pub const IFREG = 0o100000;
- pub const IFLNK = 0o120000;
- pub const IFSOCK = 0o140000;
- pub const IFWHT = 0o160000;
-
- 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 ISFIFO(m: u32) bool {
- return m & IFMT == IFIFO;
- }
-
- pub fn ISCHR(m: u32) bool {
- return m & IFMT == IFCHR;
- }
-
- pub fn ISDIR(m: u32) bool {
- return m & IFMT == IFDIR;
- }
-
- pub fn ISBLK(m: u32) bool {
- return m & IFMT == IFBLK;
- }
-
- pub fn ISREG(m: u32) bool {
- return m & IFMT == IFREG;
- }
-
- pub fn ISLNK(m: u32) bool {
- return m & IFMT == IFLNK;
- }
-
- pub fn ISSOCK(m: u32) bool {
- return m & IFMT == IFSOCK;
- }
-
- pub fn IWHT(m: u32) bool {
- return m & IFMT == IFWHT;
- }
-};
-
-pub const HOST_NAME_MAX = 255;
-
-pub const IPPROTO = struct {
- /// dummy for IP
- pub const IP = 0;
- /// IP6 hop-by-hop options
- pub const HOPOPTS = 0;
- /// control message protocol
- pub const ICMP = 1;
- /// group mgmt protocol
- pub const IGMP = 2;
- /// gateway^2 (deprecated)
- pub const GGP = 3;
- /// IP header
- pub const IPV4 = 4;
- /// IP inside IP
- pub const IPIP = 4;
- /// tcp
- pub const TCP = 6;
- /// exterior gateway protocol
- pub const EGP = 8;
- /// pup
- pub const PUP = 12;
- /// user datagram protocol
- pub const UDP = 17;
- /// xns idp
- pub const IDP = 22;
- /// tp-4 w/ class negotiation
- pub const TP = 29;
- /// DCCP
- pub const DCCP = 33;
- /// IP6 header
- pub const IPV6 = 41;
- /// IP6 routing header
- pub const ROUTING = 43;
- /// IP6 fragmentation header
- pub const FRAGMENT = 44;
- /// resource reservation
- pub const RSVP = 46;
- /// GRE encaps RFC 1701
- pub const GRE = 47;
- /// encap. security payload
- pub const ESP = 50;
- /// authentication header
- pub const AH = 51;
- /// IP Mobility RFC 2004
- pub const MOBILE = 55;
- /// IPv6 ICMP
- pub const IPV6_ICMP = 58;
- /// ICMP6
- pub const ICMPV6 = 58;
- /// IP6 no next header
- pub const NONE = 59;
- /// IP6 destination option
- pub const DSTOPTS = 60;
- /// ISO cnlp
- pub const EON = 80;
- /// Ethernet-in-IP
- pub const ETHERIP = 97;
- /// encapsulation header
- pub const ENCAP = 98;
- /// Protocol indep. multicast
- pub const PIM = 103;
- /// IP Payload Comp. Protocol
- pub const IPCOMP = 108;
- /// VRRP RFC 2338
- pub const VRRP = 112;
- /// Common Address Resolution Protocol
- pub const CARP = 112;
- /// L2TPv3
- pub const L2TP = 115;
- /// SCTP
- pub const SCTP = 132;
- /// PFSYNC
- pub const PFSYNC = 240;
- /// raw IP packet
- pub const RAW = 255;
-};
-
-pub const rlimit_resource = enum(c_int) {
- CPU = 0,
- FSIZE = 1,
- DATA = 2,
- STACK = 3,
- CORE = 4,
- RSS = 5,
- MEMLOCK = 6,
- NPROC = 7,
- NOFILE = 8,
- SBSIZE = 9,
- VMEM = 10,
- NTHR = 11,
- _,
-
- pub const AS: rlimit_resource = .VMEM;
-};
-
-pub const rlim_t = u64;
-
-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;
-};
-
-pub const nfds_t = u32;
-
-pub const pollfd = extern struct {
- fd: fd_t,
- events: i16,
- revents: i16,
-};
-
-pub const POLL = struct {
- /// Testable events (may be specified in events field).
- pub const IN = 0x0001;
- pub const PRI = 0x0002;
- pub const OUT = 0x0004;
- pub const RDNORM = 0x0040;
- pub const WRNORM = OUT;
- pub const RDBAND = 0x0080;
- pub const WRBAND = 0x0100;
-
- /// Non-testable events (may not be specified in events field).
- pub const ERR = 0x0008;
- pub const HUP = 0x0010;
- pub const NVAL = 0x0020;
-};
lib/std/c/openbsd.zig
@@ -4,50 +4,35 @@ const maxInt = std.math.maxInt;
const builtin = @import("builtin");
const iovec = std.posix.iovec;
const iovec_const = std.posix.iovec_const;
+const passwd = std.c.passwd;
+const timespec = std.c.timespec;
+const uid_t = std.c.uid_t;
+const pid_t = std.c.pid_t;
-extern "c" fn __errno() *c_int;
-pub const _errno = __errno;
-
-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 arc4random_buf(buf: [*]u8, len: usize) void;
-
-pub extern "c" fn getthrid() pid_t;
-pub extern "c" fn pipe2(fds: *[2]fd_t, flags: std.c.O) c_int;
-
-pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) c_int;
-pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int;
+comptime {
+ assert(builtin.os.tag == .openbsd); // Prevent access of std.c symbols on wrong OS.
+}
pub const pthread_spinlock_t = extern struct {
inner: ?*anyopaque = null,
};
-pub const pthread_attr_t = extern struct {
- inner: ?*anyopaque = null,
-};
-pub const pthread_key_t = c_int;
-
-pub const sem_t = ?*opaque {};
-
-pub extern "c" fn posix_memalign(memptr: *?*anyopaque, alignment: usize, size: usize) c_int;
pub extern "c" fn pledge(promises: ?[*:0]const u8, execpromises: ?[*:0]const u8) c_int;
pub extern "c" fn unveil(path: ?[*:0]const u8, permissions: ?[*:0]const u8) c_int;
+pub extern "c" fn getthrid() pid_t;
-pub extern "c" fn pthread_set_name_np(thread: std.c.pthread_t, name: [*:0]const u8) void;
-pub extern "c" fn pthread_get_name_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) void;
-
-// https://github.com/openbsd/src/blob/2207c4325726fdc5c4bcd0011af0fdf7d3dab137/sys/sys/futex.h
-pub const FUTEX_WAIT = 1;
-pub const FUTEX_WAKE = 2;
-pub const FUTEX_REQUEUE = 3;
-pub const FUTEX_PRIVATE_FLAG = 128;
+pub const FUTEX = struct {
+ pub const WAIT = 1;
+ pub const WAKE = 2;
+ pub const REQUEUE = 3;
+ pub const PRIVATE_FLAG = 128;
+};
pub extern "c" fn futex(uaddr: ?*const volatile u32, op: c_int, val: c_int, timeout: ?*const timespec, uaddr2: ?*const volatile u32) c_int;
pub const login_cap_t = extern struct {
- lc_class: ?[*:0]const u8,
- lc_cap: ?[*:0]const u8,
- lc_style: ?[*:0]const u8,
+ class: ?[*:0]const u8,
+ cap: ?[*:0]const u8,
+ style: ?[*:0]const u8,
};
pub extern "c" fn login_getclass(class: ?[*:0]const u8) ?*login_cap_t;
@@ -94,21 +79,6 @@ pub extern "c" fn auth_cat(file: [*:0]const u8) c_int;
pub extern "c" fn auth_checknologin(lc: *login_cap_t) void;
// TODO: auth_set_va_list requires zig support for va_list type (#515)
-pub const passwd = extern struct {
- pw_name: ?[*:0]const u8, // user name
- pw_passwd: ?[*:0]const u8, // encrypted password
- pw_uid: uid_t, // user uid
- pw_gid: gid_t, // user gid
- pw_change: time_t, // password change time
- pw_class: ?[*:0]const u8, // user access class
- pw_gecos: ?[*:0]const u8, // Honeywell login info
- pw_dir: ?[*:0]const u8, // home directory
- pw_shell: ?[*:0]const u8, // default shell
- pw_expire: time_t, // account expiration
-};
-
-pub extern "c" fn getpwuid(uid: uid_t) ?*passwd;
-pub extern "c" fn getpwnam(name: [*:0]const u8) ?*passwd;
pub extern "c" fn getpwuid_shadow(uid: uid_t) ?*passwd;
pub extern "c" fn getpwnam_shadow(name: [*:0]const u8) ?*passwd;
pub extern "c" fn getpwnam_r(name: [*:0]const u8, pw: *passwd, buf: [*]u8, buflen: usize, pwretp: *?*passwd) c_int;
@@ -125,622 +95,14 @@ pub extern "c" fn bcrypt_newhash(pass: [*:0]const u8, log_rounds: c_int, hash: [
pub extern "c" fn bcrypt_checkpass(pass: [*:0]const u8, goodhash: [*:0]const u8) c_int;
pub extern "c" fn pw_dup(pw: *const passwd) ?*passwd;
-pub const blkcnt_t = i64;
-pub const blksize_t = i32;
-pub const clock_t = i64;
-pub const dev_t = i32;
-pub const fd_t = c_int;
-pub const gid_t = u32;
-pub const ino_t = u64;
-pub const mode_t = u32;
-pub const nlink_t = u32;
-pub const off_t = i64;
-pub const pid_t = i32;
-pub const socklen_t = u32;
-pub const time_t = i64;
-pub const uid_t = u32;
-
-/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.
-pub const Kevent = extern struct {
- ident: usize,
- filter: c_short,
- flags: u16,
- fflags: c_uint,
- data: i64,
- udata: usize,
-};
-
-// Modes and flags for dlopen()
-// include/dlfcn.h
-
-pub const RTLD = struct {
- /// Bind function calls lazily.
- pub const LAZY = 1;
- /// Bind function calls immediately.
- pub const NOW = 2;
- /// Make symbols globally available.
- pub const GLOBAL = 0x100;
- /// Opposite of GLOBAL, and the default.
- pub const LOCAL = 0x000;
- /// Trace loaded objects and exit.
- pub const TRACE = 0x200;
-};
-
-pub const dl_phdr_info = extern struct {
- dlpi_addr: std.elf.Addr,
- dlpi_name: ?[*:0]const u8,
- dlpi_phdr: [*]std.elf.Phdr,
- dlpi_phnum: std.elf.Half,
-};
-
-pub const Flock = extern struct {
- start: off_t,
- len: off_t,
- pid: pid_t,
- type: c_short,
- whence: c_short,
-};
-
-pub const addrinfo = extern struct {
- flags: c_int,
- family: c_int,
- socktype: c_int,
- protocol: c_int,
- addrlen: socklen_t,
- addr: ?*sockaddr,
- canonname: ?[*:0]u8,
- next: ?*addrinfo,
-};
-
-pub const EAI = enum(c_int) {
- /// address family for hostname not supported
- ADDRFAMILY = -9,
-
- /// name could not be resolved at this time
- AGAIN = -3,
-
- /// flags parameter had an invalid value
- BADFLAGS = -1,
-
- /// non-recoverable failure in name resolution
- FAIL = -4,
-
- /// address family not recognized
- FAMILY = -6,
-
- /// memory allocation failure
- MEMORY = -10,
-
- /// no address associated with hostname
- NODATA = -5,
-
- /// name does not resolve
- NONAME = -2,
-
- /// service not recognized for socket type
- SERVICE = -8,
-
- /// intended socket type was not recognized
- SOCKTYPE = -7,
-
- /// 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 msghdr = extern struct {
- /// optional address
- name: ?*sockaddr,
- /// size of address
- namelen: socklen_t,
- /// scatter/gather array
- iov: [*]iovec,
- /// # elements in iov
- iovlen: c_uint,
- /// ancillary data
- control: ?*anyopaque,
- /// ancillary data buffer len
- controllen: socklen_t,
- /// flags on received message
- flags: c_int,
-};
-
-pub const msghdr_const = extern struct {
- /// optional address
- name: ?*const sockaddr,
- /// size of address
- namelen: socklen_t,
- /// scatter/gather array
- iov: [*]const iovec_const,
- /// # elements in iov
- iovlen: c_uint,
- /// ancillary data
- control: ?*const anyopaque,
- /// ancillary data buffer len
- controllen: socklen_t,
- /// flags on received message
- flags: c_int,
-};
-
-pub const Stat = extern struct {
- mode: mode_t,
- dev: dev_t,
- ino: ino_t,
- nlink: nlink_t,
- uid: uid_t,
- gid: gid_t,
- rdev: dev_t,
- atim: timespec,
- mtim: timespec,
- ctim: timespec,
- size: off_t,
- blocks: blkcnt_t,
- blksize: blksize_t,
- flags: u32,
- gen: u32,
- birthtim: timespec,
-
- 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.birthtim;
- }
-};
-
-pub const timespec = extern struct {
- tv_sec: time_t,
- tv_nsec: c_long,
-};
-
-pub const timeval = extern struct {
- tv_sec: time_t,
- tv_usec: c_long,
-};
-
-pub const timezone = extern struct {
- tz_minuteswest: c_int,
- tz_dsttime: c_int,
-};
-
-pub const MAXNAMLEN = 255;
-
-pub const dirent = extern struct {
- fileno: ino_t,
- off: off_t,
- reclen: u16,
- type: u8,
- namlen: u8,
- _: u32 align(1) = 0,
- name: [MAXNAMLEN + 1]u8,
-};
-
-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 = 256;
- pub const storage = extern struct {
- len: u8 align(8),
- family: sa_family_t,
- padding: [254]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,
- };
-
- /// Definitions for UNIX IPC domain.
- pub const un = extern struct {
- /// total sockaddr length
- len: u8 = @sizeOf(un),
-
- family: sa_family_t = AF.LOCAL,
-
- /// path name
- path: [104]u8,
- };
-};
-
-pub const IFNAMESIZE = 16;
-
-pub const AI = struct {
- /// get address to use bind()
- pub const PASSIVE = 1;
- /// fill ai_canonname
- pub const CANONNAME = 2;
- /// prevent host name resolution
- pub const NUMERICHOST = 4;
- /// prevent service name resolution
- pub const NUMERICSERV = 16;
- /// only if any address is assigned
- pub const ADDRCONFIG = 64;
-};
-
-pub const PATH_MAX = 1024;
-pub const NAME_MAX = 255;
-pub const IOV_MAX = 1024;
-
-pub const STDIN_FILENO = 0;
-pub const STDOUT_FILENO = 1;
-pub const STDERR_FILENO = 2;
-
-pub const PROT = struct {
- pub const NONE = 0;
- pub const READ = 1;
- pub const WRITE = 2;
- pub const EXEC = 4;
-};
-
-pub const CLOCK = struct {
- pub const REALTIME = 0;
- pub const PROCESS_CPUTIME_ID = 2;
- pub const MONOTONIC = 3;
- pub const THREAD_CPUTIME_ID = 4;
-};
-
-pub const MSF = struct {
- pub const ASYNC = 1;
- pub const INVALIDATE = 2;
- pub const SYNC = 4;
-};
-
-pub const W = struct {
- pub const NOHANG = 1;
- pub const UNTRACED = 2;
- pub const CONTINUED = 8;
-
- pub fn EXITSTATUS(s: u32) u8 {
- return @as(u8, @intCast((s >> 8) & 0xff));
- }
- pub fn TERMSIG(s: u32) u32 {
- return (s & 0x7f);
- }
- pub fn STOPSIG(s: u32) u32 {
- return EXITSTATUS(s);
- }
- pub fn IFEXITED(s: u32) bool {
- return TERMSIG(s) == 0;
- }
-
- pub fn IFCONTINUED(s: u32) bool {
- return ((s & 0o177777) == 0o177777);
- }
-
- pub fn IFSTOPPED(s: u32) bool {
- return (s & 0xff == 0o177);
- }
-
- pub fn IFSIGNALED(s: u32) bool {
- return (((s) & 0o177) != 0o177) and (((s) & 0o177) != 0);
- }
-};
-
-pub const SA = struct {
- pub const ONSTACK = 0x0001;
- pub const RESTART = 0x0002;
- pub const RESETHAND = 0x0004;
- pub const NOCLDSTOP = 0x0008;
- pub const NODEFER = 0x0010;
- pub const NOCLDWAIT = 0x0020;
- pub const SIGINFO = 0x0040;
-};
-
-// 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 = 0;
- pub const GETFD = 1;
- pub const SETFD = 2;
- pub const GETFL = 3;
- pub const SETFL = 4;
-
- pub const GETOWN = 5;
- pub const SETOWN = 6;
-
- pub const GETLK = 7;
- pub const SETLK = 8;
- pub const SETLKW = 9;
-
- pub const RDLCK = 1;
- pub const UNLCK = 2;
- pub const WRLCK = 3;
-};
-
-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 RDM = 4;
- pub const SEQPACKET = 5;
-
- pub const CLOEXEC = 0x8000;
- pub const NONBLOCK = 0x4000;
-};
-
-pub const SO = struct {
- pub const DEBUG = 0x0001;
- pub const ACCEPTCONN = 0x0002;
- pub const REUSEADDR = 0x0004;
- pub const KEEPALIVE = 0x0008;
- pub const DONTROUTE = 0x0010;
- pub const BROADCAST = 0x0020;
- pub const USELOOPBACK = 0x0040;
- pub const LINGER = 0x0080;
- pub const OOBINLINE = 0x0100;
- pub const REUSEPORT = 0x0200;
- pub const TIMESTAMP = 0x0800;
- pub const BINDANY = 0x1000;
- pub const ZEROIZE = 0x2000;
- pub const SNDBUF = 0x1001;
- pub const RCVBUF = 0x1002;
- pub const SNDLOWAT = 0x1003;
- pub const RCVLOWAT = 0x1004;
- pub const SNDTIMEO = 0x1005;
- pub const RCVTIMEO = 0x1006;
- pub const ERROR = 0x1007;
- pub const TYPE = 0x1008;
- pub const NETPROC = 0x1020;
- pub const RTABLE = 0x1021;
- pub const PEERCRED = 0x1022;
- pub const SPLICE = 0x1023;
- pub const DOMAIN = 0x1024;
- pub const PROTOCOL = 0x1025;
-};
-
-pub const SOL = struct {
- pub const SOCKET = 0xffff;
-};
-
-pub const PF = struct {
- pub const UNSPEC = AF.UNSPEC;
- pub const LOCAL = AF.LOCAL;
- pub const UNIX = AF.UNIX;
- pub const INET = AF.INET;
- pub const APPLETALK = AF.APPLETALK;
- pub const INET6 = AF.INET6;
- pub const DECnet = AF.DECnet;
- pub const KEY = AF.KEY;
- pub const ROUTE = AF.ROUTE;
- pub const SNA = AF.SNA;
- pub const MPLS = AF.MPLS;
- pub const BLUETOOTH = AF.BLUETOOTH;
- pub const ISDN = AF.ISDN;
- pub const MAX = AF.MAX;
-};
-
-pub const AF = struct {
- pub const UNSPEC = 0;
- pub const UNIX = 1;
- pub const LOCAL = UNIX;
- pub const INET = 2;
- pub const APPLETALK = 16;
- pub const INET6 = 24;
- pub const KEY = 30;
- pub const ROUTE = 17;
- pub const SNA = 11;
- pub const MPLS = 33;
- pub const BLUETOOTH = 32;
- pub const ISDN = 26;
- pub const MAX = 36;
-};
-
-pub const DT = struct {
- pub const UNKNOWN = 0;
- pub const FIFO = 1;
- pub const CHR = 2;
- pub const DIR = 4;
- pub const BLK = 6;
- pub const REG = 8;
- pub const LNK = 10;
- pub const SOCK = 12;
- pub const WHT = 14; // XXX
-};
-
-pub const EV_ADD = 0x0001;
-pub const EV_DELETE = 0x0002;
-pub const EV_ENABLE = 0x0004;
-pub const EV_DISABLE = 0x0008;
-pub const EV_ONESHOT = 0x0010;
-pub const EV_CLEAR = 0x0020;
-pub const EV_RECEIPT = 0x0040;
-pub const EV_DISPATCH = 0x0080;
-pub const EV_FLAG1 = 0x2000;
-pub const EV_ERROR = 0x4000;
-pub const EV_EOF = 0x8000;
-
-pub const EVFILT_READ = -1;
-pub const EVFILT_WRITE = -2;
-pub const EVFILT_AIO = -3;
-pub const EVFILT_VNODE = -4;
-pub const EVFILT_PROC = -5;
-pub const EVFILT_SIGNAL = -6;
-pub const EVFILT_TIMER = -7;
-pub const EVFILT_EXCEPT = -9;
-
-// data/hint flags for EVFILT_{READ|WRITE}
-pub const NOTE_LOWAT = 0x0001;
-pub const NOTE_EOF = 0x0002;
-
-// data/hint flags for EVFILT_EXCEPT and EVFILT_{READ|WRITE}
-pub const NOTE_OOB = 0x0004;
-
-// data/hint flags for EVFILT_VNODE
-pub const NOTE_DELETE = 0x0001;
-pub const NOTE_WRITE = 0x0002;
-pub const NOTE_EXTEND = 0x0004;
-pub const NOTE_ATTRIB = 0x0008;
-pub const NOTE_LINK = 0x0010;
-pub const NOTE_RENAME = 0x0020;
-pub const NOTE_REVOKE = 0x0040;
-pub const NOTE_TRUNCATE = 0x0080;
-
-// data/hint flags for EVFILT_PROC
-pub const NOTE_EXIT = 0x80000000;
-pub const NOTE_FORK = 0x40000000;
-pub const NOTE_EXEC = 0x20000000;
-pub const NOTE_PDATAMASK = 0x000fffff;
-pub const NOTE_PCTRLMASK = 0xf0000000;
-pub const NOTE_TRACK = 0x00000001;
-pub const NOTE_TRACKERR = 0x00000002;
-pub const NOTE_CHILD = 0x00000004;
-
-// data/hint flags for EVFILT_DEVICE
-pub const NOTE_CHANGE = 0x00000001;
-
-pub const T = struct {
- pub const IOCCBRK = 0x2000747a;
- pub const IOCCDTR = 0x20007478;
- pub const IOCCONS = 0x80047462;
- pub const IOCDCDTIMESTAMP = 0x40107458;
- pub const IOCDRAIN = 0x2000745e;
- pub const IOCEXCL = 0x2000740d;
- pub const IOCEXT = 0x80047460;
- pub const IOCFLAG_CDTRCTS = 0x10;
- pub const IOCFLAG_CLOCAL = 0x2;
- pub const IOCFLAG_CRTSCTS = 0x4;
- pub const IOCFLAG_MDMBUF = 0x8;
- pub const IOCFLAG_SOFTCAR = 0x1;
- pub const IOCFLUSH = 0x80047410;
- pub const IOCGETA = 0x402c7413;
- pub const IOCGETD = 0x4004741a;
- pub const IOCGFLAGS = 0x4004745d;
- pub const IOCGLINED = 0x40207442;
- pub const IOCGPGRP = 0x40047477;
- pub const IOCGQSIZE = 0x40047481;
- pub const IOCGRANTPT = 0x20007447;
- pub const IOCGSID = 0x40047463;
- pub const IOCGSIZE = 0x40087468;
- pub const IOCGWINSZ = 0x40087468;
- pub const IOCMBIC = 0x8004746b;
- pub const IOCMBIS = 0x8004746c;
- pub const IOCMGET = 0x4004746a;
- pub const IOCMSET = 0x8004746d;
- pub const IOCM_CAR = 0x40;
- pub const IOCM_CD = 0x40;
- pub const IOCM_CTS = 0x20;
- pub const IOCM_DSR = 0x100;
- pub const IOCM_DTR = 0x2;
- pub const IOCM_LE = 0x1;
- pub const IOCM_RI = 0x80;
- pub const IOCM_RNG = 0x80;
- pub const IOCM_RTS = 0x4;
- pub const IOCM_SR = 0x10;
- pub const IOCM_ST = 0x8;
- pub const IOCNOTTY = 0x20007471;
- pub const IOCNXCL = 0x2000740e;
- pub const IOCOUTQ = 0x40047473;
- pub const IOCPKT = 0x80047470;
- pub const IOCPKT_DATA = 0x0;
- pub const IOCPKT_DOSTOP = 0x20;
- pub const IOCPKT_FLUSHREAD = 0x1;
- pub const IOCPKT_FLUSHWRITE = 0x2;
- pub const IOCPKT_IOCTL = 0x40;
- pub const IOCPKT_NOSTOP = 0x10;
- pub const IOCPKT_START = 0x8;
- pub const IOCPKT_STOP = 0x4;
- pub const IOCPTMGET = 0x40287446;
- pub const IOCPTSNAME = 0x40287448;
- pub const IOCRCVFRAME = 0x80087445;
- pub const IOCREMOTE = 0x80047469;
- pub const IOCSBRK = 0x2000747b;
- pub const IOCSCTTY = 0x20007461;
- pub const IOCSDTR = 0x20007479;
- pub const IOCSETA = 0x802c7414;
- pub const IOCSETAF = 0x802c7416;
- pub const IOCSETAW = 0x802c7415;
- pub const IOCSETD = 0x8004741b;
- pub const IOCSFLAGS = 0x8004745c;
- pub const IOCSIG = 0x2000745f;
- pub const IOCSLINED = 0x80207443;
- pub const IOCSPGRP = 0x80047476;
- pub const IOCSQSIZE = 0x80047480;
- pub const IOCSSIZE = 0x80087467;
- pub const IOCSTART = 0x2000746e;
- pub const IOCSTAT = 0x80047465;
- pub const IOCSTI = 0x80017472;
- pub const IOCSTOP = 0x2000746f;
- pub const IOCSWINSZ = 0x80087467;
- pub const IOCUCNTL = 0x80047466;
- pub const IOCXMTFRAME = 0x80087444;
-};
-
-// BSD Authentication
-pub const auth_item_t = c_int;
-
-pub const AUTHV = struct {
- pub const ALL: auth_item_t = 0;
- pub const CHALLENGE: auth_item_t = 1;
- pub const CLASS: auth_item_t = 2;
- pub const NAME: auth_item_t = 3;
- pub const SERVICE: auth_item_t = 4;
- pub const STYLE: auth_item_t = 5;
- pub const INTERACTIVE: auth_item_t = 6;
+pub const auth_item_t = enum(c_int) {
+ ALL = 0,
+ CHALLENGE = 1,
+ CLASS = 2,
+ NAME = 3,
+ SERVICE = 4,
+ STYLE = 5,
+ INTERACTIVE = 6,
};
pub const BI = struct {
@@ -770,132 +132,20 @@ pub const AUTH = struct {
pub const ALLOW: c_int = (OKAY | ROOTOKAY | SECURE);
};
-pub const TCSA = enum(c_uint) {
- NOW,
- DRAIN,
- FLUSH,
- _,
-};
-
-pub const TCIFLUSH = 1;
-pub const TCOFLUSH = 2;
-pub const TCIOFLUSH = 3;
-pub const TCOOFF = 1;
-pub const TCOON = 2;
-pub const TCIOFF = 3;
-pub const TCION = 4;
-
-pub const winsize = extern struct {
- ws_row: c_ushort,
- ws_col: c_ushort,
- ws_xpixel: c_ushort,
- ws_ypixel: c_ushort,
-};
-
-const NSIG = 33;
-
-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 CATCH: ?Sigaction.handler_fn = @ptrFromInt(2);
- 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 TRAP = 5;
- pub const ABRT = 6;
- pub const IOT = ABRT;
- pub const EMT = 7;
- pub const FPE = 8;
- pub const KILL = 9;
- pub const BUS = 10;
- pub const SEGV = 11;
- pub const SYS = 12;
- pub const PIPE = 13;
- pub const ALRM = 14;
- pub const TERM = 15;
- pub const URG = 16;
- pub const STOP = 17;
- pub const TSTP = 18;
- pub const CONT = 19;
- pub const CHLD = 20;
- pub const TTIN = 21;
- pub const TTOU = 22;
- pub const IO = 23;
- pub const XCPU = 24;
- pub const XFSZ = 25;
- pub const VTALRM = 26;
- pub const PROF = 27;
- pub const WINCH = 28;
- pub const INFO = 29;
- pub const USR1 = 30;
- pub const USR2 = 31;
- pub const PWR = 32;
-
- pub const BLOCK = 1;
- pub const UNBLOCK = 2;
- pub const SETMASK = 3;
-};
-
-/// 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,
- /// signal options
- flags: c_uint,
-};
-
-pub const sigval = extern union {
- int: c_int,
- ptr: ?*anyopaque,
+pub const TCFLUSH = enum(u32) {
+ none = 0,
+ I = 1,
+ O = 2,
+ IO = 3,
};
-pub const siginfo_t = extern struct {
- signo: c_int,
- code: c_int,
- errno: c_int,
- data: extern union {
- proc: extern struct {
- pid: pid_t,
- pdata: extern union {
- kill: extern struct {
- uid: uid_t,
- value: sigval,
- },
- cld: extern struct {
- utime: clock_t,
- stime: clock_t,
- status: c_int,
- },
- },
- },
- fault: extern struct {
- addr: *allowzero anyopaque,
- trapno: c_int,
- },
- __pad: [128 - 3 * @sizeOf(c_int)]u8,
- },
+pub const TCIO = enum(u32) {
+ OOFF = 1,
+ OON = 2,
+ IOFF = 3,
+ ION = 4,
};
-comptime {
- if (@sizeOf(usize) == 4)
- std.debug.assert(@sizeOf(siginfo_t) == 128)
- else
- // Take into account the padding between errno and data fields.
- std.debug.assert(@sizeOf(siginfo_t) == 136);
-}
-
pub const ucontext_t = switch (builtin.cpu.arch) {
.x86_64 => extern struct {
sc_rdi: c_long,
@@ -943,9 +193,6 @@ pub const ucontext_t = switch (builtin.cpu.arch) {
else => @compileError("missing ucontext_t type definition"),
};
-pub const sigset_t = c_uint;
-pub const empty_sigset: sigset_t = 0;
-
pub const E = enum(u16) {
/// No error occurred.
SUCCESS = 0,
@@ -1070,327 +317,10 @@ pub const E = enum(u16) {
_,
};
-const _MAX_PAGE_SHIFT = switch (builtin.cpu.arch) {
+pub const MAX_PAGE_SHIFT = switch (builtin.cpu.arch) {
.x86 => 12,
.sparc64 => 13,
};
-pub const MINSIGSTKSZ = 1 << _MAX_PAGE_SHIFT;
-pub const SIGSTKSZ = MINSIGSTKSZ + (1 << _MAX_PAGE_SHIFT) * 4;
-
-pub const SS_ONSTACK = 0x0001;
-pub const SS_DISABLE = 0x0004;
-
-pub const stack_t = extern struct {
- sp: [*]u8,
- size: usize,
- flags: c_int,
-};
-
-pub const S = struct {
- pub const IFMT = 0o170000;
-
- pub const IFIFO = 0o010000;
- pub const IFCHR = 0o020000;
- pub const IFDIR = 0o040000;
- pub const IFBLK = 0o060000;
- pub const IFREG = 0o100000;
- pub const IFLNK = 0o120000;
- pub const IFSOCK = 0o140000;
-
- 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 ISFIFO(m: u32) bool {
- return m & IFMT == IFIFO;
- }
-
- pub fn ISCHR(m: u32) bool {
- return m & IFMT == IFCHR;
- }
-
- pub fn ISDIR(m: u32) bool {
- return m & IFMT == IFDIR;
- }
-
- pub fn ISBLK(m: u32) bool {
- return m & IFMT == IFBLK;
- }
-
- pub fn ISREG(m: u32) bool {
- return m & IFMT == IFREG;
- }
-
- pub fn ISLNK(m: u32) bool {
- return m & IFMT == IFLNK;
- }
-
- pub fn ISSOCK(m: u32) bool {
- return m & IFMT == IFSOCK;
- }
-};
-
-pub const HOST_NAME_MAX = 255;
-
-pub const IPPROTO = struct {
- /// dummy for IP
- pub const IP = 0;
- /// IP6 hop-by-hop options
- pub const HOPOPTS = IP;
- /// control message protocol
- pub const ICMP = 1;
- /// group mgmt protocol
- pub const IGMP = 2;
- /// gateway^2 (deprecated)
- pub const GGP = 3;
- /// IP header
- pub const IPV4 = IPIP;
- /// IP inside IP
- pub const IPIP = 4;
- /// tcp
- pub const TCP = 6;
- /// exterior gateway protocol
- pub const EGP = 8;
- /// pup
- pub const PUP = 12;
- /// user datagram protocol
- pub const UDP = 17;
- /// xns idp
- pub const IDP = 22;
- /// tp-4 w/ class negotiation
- pub const TP = 29;
- /// IP6 header
- pub const IPV6 = 41;
- /// IP6 routing header
- pub const ROUTING = 43;
- /// IP6 fragmentation header
- pub const FRAGMENT = 44;
- /// resource reservation
- pub const RSVP = 46;
- /// GRE encaps RFC 1701
- pub const GRE = 47;
- /// encap. security payload
- pub const ESP = 50;
- /// authentication header
- pub const AH = 51;
- /// IP Mobility RFC 2004
- pub const MOBILE = 55;
- /// IPv6 ICMP
- pub const IPV6_ICMP = 58;
- /// ICMP6
- pub const ICMPV6 = 58;
- /// IP6 no next header
- pub const NONE = 59;
- /// IP6 destination option
- pub const DSTOPTS = 60;
- /// ISO cnlp
- pub const EON = 80;
- /// Ethernet-in-IP
- pub const ETHERIP = 97;
- /// encapsulation header
- pub const ENCAP = 98;
- /// Protocol indep. multicast
- pub const PIM = 103;
- /// IP Payload Comp. Protocol
- pub const IPCOMP = 108;
- /// VRRP RFC 2338
- pub const VRRP = 112;
- /// Common Address Resolution Protocol
- pub const CARP = 112;
- /// PFSYNC
- pub const PFSYNC = 240;
- /// raw IP packet
- pub const RAW = 255;
-};
-
-pub const rlimit_resource = enum(c_int) {
- CPU,
- FSIZE,
- DATA,
- STACK,
- CORE,
- RSS,
- MEMLOCK,
- NPROC,
- NOFILE,
-
- _,
-};
-
-pub const rlim_t = u64;
-
-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;
-};
-
-pub const nfds_t = c_uint;
-
-pub const pollfd = extern struct {
- fd: fd_t,
- events: c_short,
- revents: c_short,
-};
-
-pub const POLL = struct {
- pub const IN = 0x0001;
- pub const PRI = 0x0002;
- pub const OUT = 0x0004;
- pub const ERR = 0x0008;
- pub const HUP = 0x0010;
- pub const NVAL = 0x0020;
- pub const RDNORM = 0x0040;
- pub const NORM = RDNORM;
- pub const WRNORM = OUT;
- pub const RDBAND = 0x0080;
- pub const WRBAND = 0x0100;
-};
-
-pub const CTL = struct {
- pub const UNSPEC = 0;
- pub const KERN = 1;
- pub const VM = 2;
- pub const FS = 3;
- pub const NET = 4;
- pub const DEBUG = 5;
- pub const HW = 6;
- pub const MACHDEP = 7;
-
- pub const DDB = 9;
- pub const VFS = 10;
-};
-
-pub const KERN = struct {
- pub const OSTYPE = 1;
- pub const OSRELEASE = 2;
- pub const OSREV = 3;
- pub const VERSION = 4;
- pub const MAXVNODES = 5;
- pub const MAXPROC = 6;
- pub const MAXFILES = 7;
- pub const ARGMAX = 8;
- pub const SECURELVL = 9;
- pub const HOSTNAME = 10;
- pub const HOSTID = 11;
- pub const CLOCKRATE = 12;
-
- pub const PROF = 16;
- pub const POSIX1 = 17;
- pub const NGROUPS = 18;
- pub const JOB_CONTROL = 19;
- pub const SAVED_IDS = 20;
- pub const BOOTTIME = 21;
- pub const DOMAINNAME = 22;
- pub const MAXPARTITIONS = 23;
- pub const RAWPARTITION = 24;
- pub const MAXTHREAD = 25;
- pub const NTHREADS = 26;
- pub const OSVERSION = 27;
- pub const SOMAXCONN = 28;
- pub const SOMINCONN = 29;
-
- pub const NOSUIDCOREDUMP = 32;
- pub const FSYNC = 33;
- pub const SYSVMSG = 34;
- pub const SYSVSEM = 35;
- pub const SYSVSHM = 36;
-
- pub const MSGBUFSIZE = 38;
- pub const MALLOCSTATS = 39;
- pub const CPTIME = 40;
- pub const NCHSTATS = 41;
- pub const FORKSTAT = 42;
- pub const NSELCOLL = 43;
- pub const TTY = 44;
- pub const CCPU = 45;
- pub const FSCALE = 46;
- pub const NPROCS = 47;
- pub const MSGBUF = 48;
- pub const POOL = 49;
- pub const STACKGAPRANDOM = 50;
- pub const SYSVIPC_INFO = 51;
- pub const ALLOWKMEM = 52;
- pub const WITNESSWATCH = 53;
- pub const SPLASSERT = 54;
- pub const PROC_ARGS = 55;
- pub const NFILES = 56;
- pub const TTYCOUNT = 57;
- pub const NUMVNODES = 58;
- pub const MBSTAT = 59;
- pub const WITNESS = 60;
- pub const SEMINFO = 61;
- pub const SHMINFO = 62;
- pub const INTRCNT = 63;
- pub const WATCHDOG = 64;
- pub const ALLOWDT = 65;
- pub const PROC = 66;
- pub const MAXCLUSTERS = 67;
- pub const EVCOUNT = 68;
- pub const TIMECOUNTER = 69;
- pub const MAXLOCKSPERUID = 70;
- pub const CPTIME2 = 71;
- pub const CACHEPCT = 72;
- pub const FILE = 73;
- pub const WXABORT = 74;
- pub const CONSDEV = 75;
- pub const NETLIVELOCKS = 76;
- pub const POOL_DEBUG = 77;
- pub const PROC_CWD = 78;
- pub const PROC_NOBROADCASTKILL = 79;
- pub const PROC_VMMAP = 80;
- pub const GLOBAL_PTRACE = 81;
- pub const CONSBUFSIZE = 82;
- pub const CONSBUF = 83;
- pub const AUDIO = 84;
- pub const CPUSTATS = 85;
- pub const PFSTATUS = 86;
- pub const TIMEOUT_STATS = 87;
- pub const UTC_OFFSET = 88;
- pub const VIDEO = 89;
-
- pub const PROC_ALL = 0;
- pub const PROC_PID = 1;
- pub const PROC_PGRP = 2;
- pub const PROC_SESSION = 3;
- pub const PROC_TTY = 4;
- pub const PROC_UID = 5;
- pub const PROC_RUID = 6;
- pub const PROC_KTHREAD = 7;
- pub const PROC_SHOW_THREADS = 0x40000000;
-
- pub const PROC_ARGV = 1;
- pub const PROC_NARGV = 2;
- pub const PROC_ENV = 3;
- pub const PROC_NENV = 4;
-};
pub const HW = struct {
pub const MACHINE = 1;
lib/std/c/solaris.zig
@@ -1,61 +1,29 @@
+const builtin = @import("builtin");
const std = @import("../std.zig");
const assert = std.debug.assert;
-const builtin = @import("builtin");
-const maxInt = std.math.maxInt;
-const iovec = std.posix.iovec;
-const iovec_const = std.posix.iovec_const;
-const timezone = std.c.timezone;
+const SO = std.c.SO;
+const fd_t = std.c.fd_t;
+const gid_t = std.c.gid_t;
+const ino_t = std.c.ino_t;
+const mode_t = std.c.mode_t;
+const off_t = std.c.off_t;
+const pid_t = std.c.pid_t;
+const pthread_t = std.c.pthread_t;
+const sockaddr = std.c.sockaddr;
+const socklen_t = std.c.socklen_t;
+const timespec = std.c.timespec;
+const uid_t = std.c.uid_t;
+const IFNAMESIZE = std.c.IFNAMESIZE;
-extern "c" fn ___errno() *c_int;
-pub const _errno = ___errno;
-
-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;
+comptime {
+ assert(builtin.os.tag == .solaris or builtin.os.tag == .illumos); // Prevent access of std.c symbols on wrong OS.
+}
-pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) usize;
-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 arc4random_buf(buf: [*]u8, len: usize) void;
-pub extern "c" fn posix_memalign(memptr: *?*anyopaque, alignment: usize, size: usize) c_int;
+pub extern "c" fn pthread_setname_np(thread: pthread_t, name: [*:0]const u8, arg: ?*anyopaque) c_int;
pub extern "c" fn sysconf(sc: c_int) i64;
-pub extern "c" fn signalfd(fd: fd_t, mask: *const sigset_t, flags: u32) c_int;
-pub extern "c" fn madvise(address: [*]u8, len: usize, advise: u32) c_int;
-
-pub const pthread_attr_t = extern struct {
- mutexattr: ?*anyopaque = null,
-};
-pub const pthread_key_t = c_int;
-pub const sem_t = extern struct {
- count: u32 = 0,
- type: u16 = 0,
- magic: u16 = 0x534d,
- __pad1: [3]u64 = [_]u64{0} ** 3,
- __pad2: [2]u64 = [_]u64{0} ** 2,
-};
-
-pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8, arg: ?*anyopaque) c_int;
-pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) c_int;
-
-pub const blkcnt_t = i64;
-pub const blksize_t = i32;
-pub const clock_t = i64;
-pub const dev_t = i32;
-pub const fd_t = c_int;
-pub const gid_t = u32;
-pub const ino_t = u64;
-pub const mode_t = u32;
-pub const nlink_t = u32;
-pub const off_t = i64;
-pub const pid_t = i32;
-pub const socklen_t = u32;
-pub const time_t = i64;
-pub const suseconds_t = i64;
-pub const uid_t = u32;
pub const major_t = u32;
pub const minor_t = u32;
-pub const port_t = c_int;
-pub const nfds_t = usize;
pub const id_t = i32;
pub const taskid_t = id_t;
pub const projid_t = id_t;
@@ -63,896 +31,18 @@ pub const poolid_t = id_t;
pub const zoneid_t = id_t;
pub const ctid_t = id_t;
-pub const dl_phdr_info = extern struct {
- dlpi_addr: std.elf.Addr,
- dlpi_name: ?[*:0]const u8,
- dlpi_phdr: [*]std.elf.Phdr,
- dlpi_phnum: std.elf.Half,
- /// Incremented when a new object is mapped into the process.
- dlpi_adds: u64,
- /// Incremented when an object is unmapped from the process.
- dlpi_subs: u64,
-};
-
-pub const RTLD = struct {
- pub const LAZY = 0x00001;
- pub const NOW = 0x00002;
- pub const NOLOAD = 0x00004;
- pub const GLOBAL = 0x00100;
- pub const LOCAL = 0x00000;
- pub const PARENT = 0x00200;
- pub const GROUP = 0x00400;
- pub const WORLD = 0x00800;
- pub const NODELETE = 0x01000;
- pub const FIRST = 0x02000;
- pub const CONFGEN = 0x10000;
-
- pub const NEXT = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -1)))));
- pub const DEFAULT = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -2)))));
- pub const SELF = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -3)))));
- pub const PROBE = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -4)))));
-};
-
-pub const Flock = extern struct {
- type: c_short,
- whence: c_short,
- start: off_t,
- // len == 0 means until end of file.
- len: off_t,
- sysid: c_int,
- pid: pid_t,
- __pad: [4]c_long,
-};
-
-pub const utsname = extern struct {
- sysname: [256:0]u8,
- nodename: [256:0]u8,
- release: [256:0]u8,
- version: [256:0]u8,
- machine: [256:0]u8,
- domainname: [256:0]u8,
-};
-
-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 EAI = enum(c_int) {
- /// 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,
- /// argument buffer overflow
- OVERFLOW = 12,
- /// resolved protocol is unknown
- PROTOCOL = 13,
-
- _,
-};
-
-pub const EAI_MAX = 14;
-
-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 msghdr_const = extern struct {
- /// optional address
- msg_name: ?*const sockaddr,
- /// size of address
- msg_namelen: socklen_t,
- /// scatter/gather array
- msg_iov: [*]const iovec_const,
- /// # elements in msg_iov
- msg_iovlen: i32,
- /// ancillary data
- msg_control: ?*const anyopaque,
- /// ancillary data buffer len
- msg_controllen: socklen_t,
- /// flags on received message
- msg_flags: i32,
-};
-
pub const cmsghdr = extern struct {
- cmsg_len: socklen_t,
- cmsg_level: i32,
- cmsg_type: i32,
+ len: socklen_t,
+ level: i32,
+ type: i32,
};
-/// The stat structure used by libc.
-pub const Stat = extern struct {
- dev: dev_t,
- ino: ino_t,
- mode: mode_t,
- nlink: nlink_t,
- uid: uid_t,
- gid: gid_t,
- rdev: dev_t,
- size: off_t,
- atim: timespec,
- mtim: timespec,
- ctim: timespec,
- blksize: blksize_t,
- blocks: blkcnt_t,
- fstype: [16]u8,
-
- 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 const timespec = extern struct {
- tv_sec: i64,
- tv_nsec: isize,
-};
-
-pub const timeval = extern struct {
- /// seconds
- tv_sec: time_t,
- /// microseconds
- tv_usec: suseconds_t,
-};
-
-pub const MAXNAMLEN = 511;
-
-pub const dirent = extern struct {
- /// Inode number of entry.
- ino: ino_t,
- /// Offset of this entry on disk.
- off: off_t,
- /// Length of this record.
- reclen: u16,
- /// File name.
- name: [MAXNAMLEN:0]u8,
-};
-
-pub const SOCK = struct {
- /// Datagram.
- pub const DGRAM = 1;
- /// STREAM.
- pub const STREAM = 2;
- /// Raw-protocol interface.
- pub const RAW = 4;
- /// Reliably-delivered message.
- pub const RDM = 5;
- /// Sequenced packed stream.
- pub const SEQPACKET = 6;
-
- pub const NONBLOCK = 0x100000;
- pub const NDELAY = 0x200000;
- pub const CLOEXEC = 0x080000;
-};
-
-pub const SO = struct {
- pub const DEBUG = 0x0001;
- pub const ACCEPTCONN = 0x0002;
- pub const REUSEADDR = 0x0004;
- pub const KEEPALIVE = 0x0008;
- pub const DONTROUTE = 0x0010;
- pub const BROADCAST = 0x0020;
- pub const USELOOPBACK = 0x0040;
- pub const LINGER = 0x0080;
- pub const OOBINLINE = 0x0100;
- pub const DGRAM_ERRIND = 0x0200;
- pub const RECVUCRED = 0x0400;
-
- pub const SNDBUF = 0x1001;
- pub const RCVBUF = 0x1002;
- pub const SNDLOWAT = 0x1003;
- pub const RCVLOWAT = 0x1004;
- pub const SNDTIMEO = 0x1005;
- pub const RCVTIMEO = 0x1006;
- pub const ERROR = 0x1007;
- pub const TYPE = 0x1008;
- pub const PROTOTYPE = 0x1009;
- pub const ANON_MLP = 0x100a;
- pub const MAC_EXEMPT = 0x100b;
- pub const DOMAIN = 0x100c;
- pub const RCVPSH = 0x100d;
-
- pub const SECATTR = 0x1011;
- pub const TIMESTAMP = 0x1013;
- pub const ALLZONES = 0x1014;
- pub const EXCLBIND = 0x1015;
- pub const MAC_IMPLICIT = 0x1016;
- pub const VRRP = 0x1017;
-};
-
-pub const SOMAXCONN = 128;
-
pub const SCM = struct {
pub const UCRED = 0x1012;
pub const RIGHTS = 0x1010;
pub const TIMESTAMP = SO.TIMESTAMP;
};
-pub const AF = struct {
- pub const UNSPEC = 0;
- pub const UNIX = 1;
- pub const LOCAL = UNIX;
- pub const FILE = UNIX;
- pub const INET = 2;
- pub const IMPLINK = 3;
- pub const PUP = 4;
- pub const CHAOS = 5;
- pub const NS = 6;
- pub const NBS = 7;
- pub const ECMA = 8;
- pub const DATAKIT = 9;
- pub const CCITT = 10;
- pub const SNA = 11;
- pub const DECnet = 12;
- pub const DLI = 13;
- pub const LAT = 14;
- pub const HYLINK = 15;
- pub const APPLETALK = 16;
- pub const NIT = 17;
- pub const @"802" = 18;
- pub const OSI = 19;
- pub const X25 = 20;
- pub const OSINET = 21;
- pub const GOSIP = 22;
- pub const IPX = 23;
- pub const ROUTE = 24;
- pub const LINK = 25;
- pub const INET6 = 26;
- pub const KEY = 27;
- pub const NCA = 28;
- pub const POLICY = 29;
- pub const INET_OFFLOAD = 30;
- pub const TRILL = 31;
- pub const PACKET = 32;
- pub const LX_NETLINK = 33;
- pub const MAX = 33;
-};
-
-pub const SOL = struct {
- pub const SOCKET = 0xffff;
- pub const ROUTE = 0xfffe;
- pub const PACKET = 0xfffd;
- pub const FILTER = 0xfffc;
-};
-
-pub const PF = struct {
- pub const UNSPEC = AF.UNSPEC;
- pub const UNIX = AF.UNIX;
- pub const LOCAL = UNIX;
- pub const FILE = UNIX;
- pub const INET = AF.INET;
- pub const IMPLINK = AF.IMPLINK;
- pub const PUP = AF.PUP;
- pub const CHAOS = AF.CHAOS;
- pub const NS = AF.NS;
- pub const NBS = AF.NBS;
- pub const ECMA = AF.ECMA;
- pub const DATAKIT = AF.DATAKIT;
- pub const CCITT = AF.CCITT;
- pub const SNA = AF.SNA;
- pub const DECnet = AF.DECnet;
- pub const DLI = AF.DLI;
- pub const LAT = AF.LAT;
- pub const HYLINK = AF.HYLINK;
- pub const APPLETALK = AF.APPLETALK;
- pub const NIT = AF.NIT;
- pub const @"802" = AF.@"802";
- pub const OSI = AF.OSI;
- pub const X25 = AF.X25;
- pub const OSINET = AF.OSINET;
- pub const GOSIP = AF.GOSIP;
- pub const IPX = AF.IPX;
- pub const ROUTE = AF.ROUTE;
- pub const LINK = AF.LINK;
- pub const INET6 = AF.INET6;
- pub const KEY = AF.KEY;
- pub const NCA = AF.NCA;
- pub const POLICY = AF.POLICY;
- pub const TRILL = AF.TRILL;
- pub const PACKET = AF.PACKET;
- pub const LX_NETLINK = AF.LX_NETLINK;
- pub const MAX = AF.MAX;
-};
-
-pub const in_port_t = u16;
-pub const sa_family_t = u16;
-
-pub const sockaddr = extern struct {
- /// address family
- family: sa_family_t,
-
- /// actually longer; address value
- data: [14]u8,
-
- pub const SS_MAXSIZE = 256;
- pub const storage = extern struct {
- family: sa_family_t align(8),
- padding: [254]u8 = undefined,
-
- comptime {
- assert(@sizeOf(storage) == SS_MAXSIZE);
- assert(@alignOf(storage) == 8);
- }
- };
-
- 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 },
- };
-
- pub const in6 = extern struct {
- family: sa_family_t = AF.INET6,
- port: in_port_t,
- flowinfo: u32,
- addr: [16]u8,
- scope_id: u32,
- __src_id: u32 = 0,
- };
-
- /// Definitions for UNIX IPC domain.
- pub const un = extern struct {
- family: sa_family_t = AF.UNIX,
- path: [108]u8,
- };
-};
-
-pub const AI = struct {
- /// IPv4-mapped IPv6 address
- pub const V4MAPPED = 0x0001;
- pub const ALL = 0x0002;
- /// only if any address is assigned
- pub const ADDRCONFIG = 0x0004;
- /// get address to use bind()
- pub const PASSIVE = 0x0008;
- /// fill ai_canonname
- pub const CANONNAME = 0x0010;
- /// prevent host name resolution
- pub const NUMERICHOST = 0x0020;
- /// prevent service name resolution
- pub const NUMERICSERV = 0x0040;
-};
-
-pub const NI = struct {
- pub const NOFQDN = 0x0001;
- pub const NUMERICHOST = 0x0002;
- pub const NAMEREQD = 0x0004;
- pub const NUMERICSERV = 0x0008;
- pub const DGRAM = 0x0010;
- pub const WITHSCOPEID = 0x0020;
- pub const NUMERICSCOPE = 0x0040;
-
- pub const MAXHOST = 1025;
- pub const MAXSERV = 32;
-};
-
-pub const NAME_MAX = 255;
-pub const PATH_MAX = 1024;
-pub const IOV_MAX = 1024;
-
-pub const STDIN_FILENO = 0;
-pub const STDOUT_FILENO = 1;
-pub const STDERR_FILENO = 2;
-
-pub const PROT = struct {
- pub const NONE = 0;
- pub const READ = 1;
- pub const WRITE = 2;
- pub const EXEC = 4;
-};
-
-pub const CLOCK = struct {
- pub const VIRTUAL = 1;
- pub const THREAD_CPUTIME_ID = 2;
- pub const REALTIME = 3;
- pub const MONOTONIC = 4;
- pub const PROCESS_CPUTIME_ID = 5;
- pub const HIGHRES = MONOTONIC;
- pub const PROF = THREAD_CPUTIME_ID;
-};
-
-pub const MSF = struct {
- pub const ASYNC = 1;
- pub const INVALIDATE = 2;
- pub const SYNC = 4;
-};
-
-pub const MADV = struct {
- /// no further special treatment
- pub const NORMAL = 0;
- /// expect random page references
- pub const RANDOM = 1;
- /// expect sequential page references
- pub const SEQUENTIAL = 2;
- /// will need these pages
- pub const WILLNEED = 3;
- /// don't need these pages
- pub const DONTNEED = 4;
- /// contents can be freed
- pub const FREE = 5;
- /// default access
- pub const ACCESS_DEFAULT = 6;
- /// next LWP to access heavily
- pub const ACCESS_LWP = 7;
- /// many processes to access heavily
- pub const ACCESS_MANY = 8;
- /// contents will be purged
- pub const PURGE = 9;
-};
-
-pub const W = struct {
- pub const EXITED = 0o001;
- pub const TRAPPED = 0o002;
- pub const UNTRACED = 0o004;
- pub const STOPPED = UNTRACED;
- pub const CONTINUED = 0o010;
- pub const NOHANG = 0o100;
- pub const NOWAIT = 0o200;
-
- pub fn EXITSTATUS(s: u32) u8 {
- return @as(u8, @intCast((s >> 8) & 0xff));
- }
- pub fn TERMSIG(s: u32) u32 {
- return s & 0x7f;
- }
- pub fn STOPSIG(s: u32) u32 {
- return EXITSTATUS(s);
- }
- pub fn IFEXITED(s: u32) bool {
- return TERMSIG(s) == 0;
- }
-
- pub fn IFCONTINUED(s: u32) bool {
- return ((s & 0o177777) == 0o177777);
- }
-
- pub fn IFSTOPPED(s: u32) bool {
- return (s & 0x00ff != 0o177) and !(s & 0xff00 != 0);
- }
-
- pub fn IFSIGNALED(s: u32) bool {
- return s & 0x00ff > 0 and s & 0xff00 == 0;
- }
-};
-
-pub const SA = struct {
- pub const ONSTACK = 0x00000001;
- pub const RESETHAND = 0x00000002;
- pub const RESTART = 0x00000004;
- pub const SIGINFO = 0x00000008;
- pub const NODEFER = 0x00000010;
- pub const NOCLDWAIT = 0x00010000;
-};
-
-// 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 {
- /// Unlock a previously locked region
- pub const ULOCK = 0;
- /// Lock a region for exclusive use
- pub const LOCK = 1;
- /// Test and lock a region for exclusive use
- pub const TLOCK = 2;
- /// Test a region for other processes locks
- pub const TEST = 3;
-
- /// Duplicate fildes
- pub const DUPFD = 0;
- /// Get fildes flags
- pub const GETFD = 1;
- /// Set fildes flags
- pub const SETFD = 2;
- /// Get file flags
- pub const GETFL = 3;
- /// Get file flags including open-only flags
- pub const GETXFL = 45;
- /// Set file flags
- pub const SETFL = 4;
-
- /// Unused
- pub const CHKFL = 8;
- /// Duplicate fildes at third arg
- pub const DUP2FD = 9;
- /// Like DUP2FD with O_CLOEXEC set EINVAL is fildes matches arg1
- pub const DUP2FD_CLOEXEC = 36;
- /// Like DUPFD with O_CLOEXEC set
- pub const DUPFD_CLOEXEC = 37;
-
- /// Is the file desc. a stream ?
- pub const ISSTREAM = 13;
- /// Turn on private access to file
- pub const PRIV = 15;
- /// Turn off private access to file
- pub const NPRIV = 16;
- /// UFS quota call
- pub const QUOTACTL = 17;
- /// Get number of BLKSIZE blocks allocated
- pub const BLOCKS = 18;
- /// Get optimal I/O block size
- pub const BLKSIZE = 19;
- /// Get owner (socket emulation)
- pub const GETOWN = 23;
- /// Set owner (socket emulation)
- pub const SETOWN = 24;
- /// Object reuse revoke access to file desc.
- pub const REVOKE = 25;
- /// Does vp have NFS locks private to lock manager
- pub const HASREMOTELOCKS = 26;
-
- /// Set file lock
- pub const SETLK = 6;
- /// Set file lock and wait
- pub const SETLKW = 7;
- /// Allocate file space
- pub const ALLOCSP = 10;
- /// Free file space
- pub const FREESP = 11;
- /// Get file lock
- pub const GETLK = 14;
- /// Get file lock owned by file
- pub const OFD_GETLK = 47;
- /// Set file lock owned by file
- pub const OFD_SETLK = 48;
- /// Set file lock owned by file and wait
- pub const OFD_SETLKW = 49;
- /// Set a file share reservation
- pub const SHARE = 40;
- /// Remove a file share reservation
- pub const UNSHARE = 41;
- /// Create Poison FD
- pub const BADFD = 46;
-
- /// Read lock
- pub const RDLCK = 1;
- /// Write lock
- pub const WRLCK = 2;
- /// Remove lock(s)
- pub const UNLCK = 3;
- /// remove remote locks for a given system
- pub const UNLKSYS = 4;
-
- // f_access values
- /// Read-only share access
- pub const RDACC = 0x1;
- /// Write-only share access
- pub const WRACC = 0x2;
- /// Read-Write share access
- pub const RWACC = 0x3;
-
- // f_deny values
- /// Don't deny others access
- pub const NODNY = 0x0;
- /// Deny others read share access
- pub const RDDNY = 0x1;
- /// Deny others write share access
- pub const WRDNY = 0x2;
- /// Deny others read or write share access
- pub const RWDNY = 0x3;
- /// private flag: Deny delete share access
- pub const RMDNY = 0x4;
-};
-
-pub const LOCK = struct {
- pub const SH = 1;
- pub const EX = 2;
- pub const NB = 4;
- pub const UN = 8;
-};
-
-pub const FD_CLOEXEC = 1;
-
-pub const SEEK = struct {
- pub const SET = 0;
- pub const CUR = 1;
- pub const END = 2;
- pub const DATA = 3;
- pub const HOLE = 4;
-};
-
-fn tioc(t: u16, num: u8) u16 {
- return (t << 8) | num;
-}
-
-pub const T = struct {
- pub const CGETA = tioc('T', 1);
- pub const CSETA = tioc('T', 2);
- pub const CSETAW = tioc('T', 3);
- pub const CSETAF = tioc('T', 4);
- pub const CSBRK = tioc('T', 5);
- pub const CXONC = tioc('T', 6);
- pub const CFLSH = tioc('T', 7);
- pub const IOCGWINSZ = tioc('T', 104);
- pub const IOCSWINSZ = tioc('T', 103);
- // Softcarrier ioctls
- pub const IOCGSOFTCAR = tioc('T', 105);
- pub const IOCSSOFTCAR = tioc('T', 106);
- // termios ioctls
- pub const CGETS = tioc('T', 13);
- pub const CSETS = tioc('T', 14);
- pub const CSANOW = tioc('T', 14);
- pub const CSETSW = tioc('T', 15);
- pub const CSADRAIN = tioc('T', 15);
- pub const CSETSF = tioc('T', 16);
- pub const IOCSETLD = tioc('T', 123);
- pub const IOCGETLD = tioc('T', 124);
- // NTP PPS ioctls
- pub const IOCGPPS = tioc('T', 125);
- pub const IOCSPPS = tioc('T', 126);
- pub const IOCGPPSEV = tioc('T', 127);
-
- pub const IOCGETD = tioc('t', 0);
- pub const IOCSETD = tioc('t', 1);
- pub const IOCHPCL = tioc('t', 2);
- pub const IOCGETP = tioc('t', 8);
- pub const IOCSETP = tioc('t', 9);
- pub const IOCSETN = tioc('t', 10);
- pub const IOCEXCL = tioc('t', 13);
- pub const IOCNXCL = tioc('t', 14);
- pub const IOCFLUSH = tioc('t', 16);
- pub const IOCSETC = tioc('t', 17);
- pub const IOCGETC = tioc('t', 18);
- /// bis local mode bits
- pub const IOCLBIS = tioc('t', 127);
- /// bic local mode bits
- pub const IOCLBIC = tioc('t', 126);
- /// set entire local mode word
- pub const IOCLSET = tioc('t', 125);
- /// get local modes
- pub const IOCLGET = tioc('t', 124);
- /// set break bit
- pub const IOCSBRK = tioc('t', 123);
- /// clear break bit
- pub const IOCCBRK = tioc('t', 122);
- /// set data terminal ready
- pub const IOCSDTR = tioc('t', 121);
- /// clear data terminal ready
- pub const IOCCDTR = tioc('t', 120);
- /// set local special chars
- pub const IOCSLTC = tioc('t', 117);
- /// get local special chars
- pub const IOCGLTC = tioc('t', 116);
- /// driver output queue size
- pub const IOCOUTQ = tioc('t', 115);
- /// void tty association
- pub const IOCNOTTY = tioc('t', 113);
- /// get a ctty
- pub const IOCSCTTY = tioc('t', 132);
- /// stop output, like ^S
- pub const IOCSTOP = tioc('t', 111);
- /// start output, like ^Q
- pub const IOCSTART = tioc('t', 110);
- /// get pgrp of tty
- pub const IOCGPGRP = tioc('t', 20);
- /// set pgrp of tty
- pub const IOCSPGRP = tioc('t', 21);
- /// get session id on ctty
- pub const IOCGSID = tioc('t', 22);
- /// simulate terminal input
- pub const IOCSTI = tioc('t', 23);
- /// set all modem bits
- pub const IOCMSET = tioc('t', 26);
- /// bis modem bits
- pub const IOCMBIS = tioc('t', 27);
- /// bic modem bits
- pub const IOCMBIC = tioc('t', 28);
- /// get all modem bits
- pub const IOCMGET = tioc('t', 29);
-};
-
-pub const winsize = extern struct {
- ws_row: u16,
- ws_col: u16,
- ws_xpixel: u16,
- ws_ypixel: u16,
-};
-
-const NSIG = 75;
-
-pub const SIG = struct {
- pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
- pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
- pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
- pub const HOLD: ?Sigaction.handler_fn = @ptrFromInt(2);
-
- pub const WORDS = 4;
- pub const MAXSIG = 75;
-
- pub const SIG_BLOCK = 1;
- pub const SIG_UNBLOCK = 2;
- pub const SIG_SETMASK = 3;
-
- pub const HUP = 1;
- pub const INT = 2;
- pub const QUIT = 3;
- pub const ILL = 4;
- pub const TRAP = 5;
- pub const IOT = 6;
- pub const ABRT = 6;
- pub const EMT = 7;
- pub const FPE = 8;
- pub const KILL = 9;
- pub const BUS = 10;
- pub const SEGV = 11;
- pub const SYS = 12;
- pub const PIPE = 13;
- pub const ALRM = 14;
- pub const TERM = 15;
- pub const USR1 = 16;
- pub const USR2 = 17;
- pub const CLD = 18;
- pub const CHLD = 18;
- pub const PWR = 19;
- pub const WINCH = 20;
- pub const URG = 21;
- pub const POLL = 22;
- pub const IO = .POLL;
- pub const STOP = 23;
- pub const TSTP = 24;
- pub const CONT = 25;
- pub const TTIN = 26;
- pub const TTOU = 27;
- pub const VTALRM = 28;
- pub const PROF = 29;
- pub const XCPU = 30;
- pub const XFSZ = 31;
- pub const WAITING = 32;
- pub const LWP = 33;
- pub const FREEZE = 34;
- pub const THAW = 35;
- pub const CANCEL = 36;
- pub const LOST = 37;
- pub const XRES = 38;
- pub const JVM1 = 39;
- pub const JVM2 = 40;
- pub const INFO = 41;
-
- pub const RTMIN = 42;
- pub const RTMAX = 74;
-
- pub inline fn IDX(sig: usize) usize {
- return sig - 1;
- }
- pub inline fn WORD(sig: usize) usize {
- return IDX(sig) >> 5;
- }
- pub inline fn BIT(sig: usize) usize {
- return 1 << (IDX(sig) & 31);
- }
- pub inline fn VALID(sig: usize) usize {
- return sig <= MAXSIG and sig > 0;
- }
-};
-
-/// 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 options
- flags: c_uint,
- /// signal handler
- handler: extern union {
- handler: ?handler_fn,
- sigaction: ?sigaction_fn,
- },
- /// signal mask to apply
- mask: sigset_t,
-};
-
-pub const sigval_t = extern union {
- int: c_int,
- ptr: ?*anyopaque,
-};
-
-pub const siginfo_t = extern struct {
- signo: c_int,
- code: c_int,
- errno: c_int,
- // 64bit architectures insert 4bytes of padding here, this is done by
- // correctly aligning the reason field
- reason: extern union {
- proc: extern struct {
- pid: pid_t,
- pdata: extern union {
- kill: extern struct {
- uid: uid_t,
- value: sigval_t,
- },
- cld: extern struct {
- utime: clock_t,
- status: c_int,
- stime: clock_t,
- },
- },
- contract: ctid_t,
- zone: zoneid_t,
- },
- fault: extern struct {
- addr: *allowzero anyopaque,
- trapno: c_int,
- pc: ?*anyopaque,
- },
- file: extern struct {
- // fd not currently available for SIGPOLL.
- fd: c_int,
- band: c_long,
- },
- prof: extern struct {
- addr: ?*anyopaque,
- timestamp: timespec,
- syscall: c_short,
- sysarg: u8,
- fault: u8,
- args: [8]c_long,
- state: [10]c_int,
- },
- rctl: extern struct {
- entity: i32,
- },
- __pad: [256 - 4 * @sizeOf(c_int)]u8,
- } align(@sizeOf(usize)),
-};
-
-comptime {
- std.debug.assert(@sizeOf(siginfo_t) == 256);
- std.debug.assert(@alignOf(siginfo_t) == @sizeOf(usize));
-}
-
-pub const sigset_t = extern struct {
- __bits: [SIG.WORDS]u32,
-};
-
-pub const empty_sigset = sigset_t{ .__bits = [_]u32{0} ** SIG.WORDS };
-
pub const fpregset_t = extern union {
regs: [130]u32,
chip_state: extern struct {
@@ -976,393 +66,11 @@ pub const fpregset_t = extern union {
},
};
-pub const mcontext_t = extern struct {
- gregs: [28]u64,
- fpregs: fpregset_t,
-};
-
-pub const REG = struct {
- pub const R15 = 0;
- pub const R14 = 1;
- pub const R13 = 2;
- pub const R12 = 3;
- pub const R11 = 4;
- pub const R10 = 5;
- pub const R9 = 6;
- pub const R8 = 7;
- pub const RDI = 8;
- pub const RSI = 9;
- pub const RBP = 10;
- pub const RBX = 11;
- pub const RDX = 12;
- pub const RCX = 13;
- pub const RAX = 14;
- pub const RIP = 17;
- pub const RSP = 20;
-};
-
-pub const ucontext_t = extern struct {
- flags: u64,
- link: ?*ucontext_t,
- sigmask: sigset_t,
- stack: stack_t,
- mcontext: mcontext_t,
- brand_data: [3]?*anyopaque,
- filler: [2]i64,
-};
-
pub const GETCONTEXT = 0;
pub const SETCONTEXT = 1;
pub const GETUSTACK = 2;
pub const SETUSTACK = 3;
-pub const E = enum(u16) {
- /// No error occurred.
- SUCCESS = 0,
- /// Not super-user
- PERM = 1,
- /// No such file or directory
- NOENT = 2,
- /// No such process
- SRCH = 3,
- /// interrupted system call
- INTR = 4,
- /// I/O error
- IO = 5,
- /// No such device or address
- NXIO = 6,
- /// Arg list too long
- @"2BIG" = 7,
- /// Exec format error
- NOEXEC = 8,
- /// Bad file number
- BADF = 9,
- /// No children
- CHILD = 10,
- /// Resource temporarily unavailable.
- /// also: WOULDBLOCK: Operation would block.
- AGAIN = 11,
- /// Not enough core
- NOMEM = 12,
- /// Permission denied
- ACCES = 13,
- /// Bad address
- FAULT = 14,
- /// Block device required
- NOTBLK = 15,
- /// Mount device busy
- BUSY = 16,
- /// File exists
- EXIST = 17,
- /// Cross-device link
- XDEV = 18,
- /// No such device
- NODEV = 19,
- /// Not a directory
- NOTDIR = 20,
- /// Is a directory
- ISDIR = 21,
- /// Invalid argument
- INVAL = 22,
- /// File table overflow
- NFILE = 23,
- /// Too many open files
- MFILE = 24,
- /// Inappropriate ioctl for device
- NOTTY = 25,
- /// Text file busy
- TXTBSY = 26,
- /// File too large
- FBIG = 27,
- /// No space left on device
- NOSPC = 28,
- /// Illegal seek
- SPIPE = 29,
- /// Read only file system
- ROFS = 30,
- /// Too many links
- MLINK = 31,
- /// Broken pipe
- PIPE = 32,
- /// Math arg out of domain of func
- DOM = 33,
- /// Math result not representable
- RANGE = 34,
- /// No message of desired type
- NOMSG = 35,
- /// Identifier removed
- IDRM = 36,
- /// Channel number out of range
- CHRNG = 37,
- /// Level 2 not synchronized
- L2NSYNC = 38,
- /// Level 3 halted
- L3HLT = 39,
- /// Level 3 reset
- L3RST = 40,
- /// Link number out of range
- LNRNG = 41,
- /// Protocol driver not attached
- UNATCH = 42,
- /// No CSI structure available
- NOCSI = 43,
- /// Level 2 halted
- L2HLT = 44,
- /// Deadlock condition.
- DEADLK = 45,
- /// No record locks available.
- NOLCK = 46,
- /// Operation canceled
- CANCELED = 47,
- /// Operation not supported
- NOTSUP = 48,
-
- // Filesystem Quotas
- /// Disc quota exceeded
- DQUOT = 49,
-
- // Convergent Error Returns
- /// invalid exchange
- BADE = 50,
- /// invalid request descriptor
- BADR = 51,
- /// exchange full
- XFULL = 52,
- /// no anode
- NOANO = 53,
- /// invalid request code
- BADRQC = 54,
- /// invalid slot
- BADSLT = 55,
- /// file locking deadlock error
- DEADLOCK = 56,
- /// bad font file fmt
- BFONT = 57,
-
- // Interprocess Robust Locks
- /// process died with the lock
- OWNERDEAD = 58,
- /// lock is not recoverable
- NOTRECOVERABLE = 59,
- /// locked lock was unmapped
- LOCKUNMAPPED = 72,
- /// Facility is not active
- NOTACTIVE = 73,
- /// multihop attempted
- MULTIHOP = 74,
- /// trying to read unreadable message
- BADMSG = 77,
- /// path name is too long
- NAMETOOLONG = 78,
- /// value too large to be stored in data type
- OVERFLOW = 79,
- /// given log. name not unique
- NOTUNIQ = 80,
- /// f.d. invalid for this operation
- BADFD = 81,
- /// Remote address changed
- REMCHG = 82,
-
- // Stream Problems
- /// Device not a stream
- NOSTR = 60,
- /// no data (for no delay io)
- NODATA = 61,
- /// timer expired
- TIME = 62,
- /// out of streams resources
- NOSR = 63,
- /// Machine is not on the network
- NONET = 64,
- /// Package not installed
- NOPKG = 65,
- /// The object is remote
- REMOTE = 66,
- /// the link has been severed
- NOLINK = 67,
- /// advertise error
- ADV = 68,
- /// srmount error
- SRMNT = 69,
- /// Communication error on send
- COMM = 70,
- /// Protocol error
- PROTO = 71,
-
- // Shared Library Problems
- /// Can't access a needed shared lib.
- LIBACC = 83,
- /// Accessing a corrupted shared lib.
- LIBBAD = 84,
- /// .lib section in a.out corrupted.
- LIBSCN = 85,
- /// Attempting to link in too many libs.
- LIBMAX = 86,
- /// Attempting to exec a shared library.
- LIBEXEC = 87,
- /// Illegal byte sequence.
- ILSEQ = 88,
- /// Unsupported file system operation
- NOSYS = 89,
- /// Symbolic link loop
- LOOP = 90,
- /// Restartable system call
- RESTART = 91,
- /// if pipe/FIFO, don't sleep in stream head
- STRPIPE = 92,
- /// directory not empty
- NOTEMPTY = 93,
- /// Too many users (for UFS)
- USERS = 94,
-
- // BSD Networking Software
- // Argument Errors
- /// Socket operation on non-socket
- NOTSOCK = 95,
- /// Destination address required
- DESTADDRREQ = 96,
- /// Message too long
- MSGSIZE = 97,
- /// Protocol wrong type for socket
- PROTOTYPE = 98,
- /// Protocol not available
- NOPROTOOPT = 99,
- /// Protocol not supported
- PROTONOSUPPORT = 120,
- /// Socket type not supported
- SOCKTNOSUPPORT = 121,
- /// Operation not supported on socket
- OPNOTSUPP = 122,
- /// Protocol family not supported
- PFNOSUPPORT = 123,
- /// Address family not supported by
- AFNOSUPPORT = 124,
- /// Address already in use
- ADDRINUSE = 125,
- /// Can't assign requested address
- ADDRNOTAVAIL = 126,
-
- // Operational Errors
- /// Network is down
- NETDOWN = 127,
- /// Network is unreachable
- NETUNREACH = 128,
- /// Network dropped connection because
- NETRESET = 129,
- /// Software caused connection abort
- CONNABORTED = 130,
- /// Connection reset by peer
- CONNRESET = 131,
- /// No buffer space available
- NOBUFS = 132,
- /// Socket is already connected
- ISCONN = 133,
- /// Socket is not connected
- NOTCONN = 134,
- /// Can't send after socket shutdown
- SHUTDOWN = 143,
- /// Too many references: can't splice
- TOOMANYREFS = 144,
- /// Connection timed out
- TIMEDOUT = 145,
- /// Connection refused
- CONNREFUSED = 146,
- /// Host is down
- HOSTDOWN = 147,
- /// No route to host
- HOSTUNREACH = 148,
- /// operation already in progress
- ALREADY = 149,
- /// operation now in progress
- INPROGRESS = 150,
-
- // SUN Network File System
- /// Stale NFS file handle
- STALE = 151,
-
- _,
-};
-
-pub const MINSIGSTKSZ = 2048;
-pub const SIGSTKSZ = 8192;
-
-pub const SS_ONSTACK = 0x1;
-pub const SS_DISABLE = 0x2;
-
-pub const stack_t = extern struct {
- sp: [*]u8,
- size: isize,
- flags: i32,
-};
-
-pub const S = struct {
- pub const IFMT = 0o170000;
-
- pub const IFIFO = 0o010000;
- pub const IFCHR = 0o020000;
- pub const IFDIR = 0o040000;
- pub const IFBLK = 0o060000;
- pub const IFREG = 0o100000;
- pub const IFLNK = 0o120000;
- pub const IFSOCK = 0o140000;
- /// SunOS 2.6 Door
- pub const IFDOOR = 0o150000;
- /// Solaris 10 Event Port
- pub const IFPORT = 0o160000;
-
- 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 ISFIFO(m: u32) bool {
- return m & IFMT == IFIFO;
- }
-
- pub fn ISCHR(m: u32) bool {
- return m & IFMT == IFCHR;
- }
-
- pub fn ISDIR(m: u32) bool {
- return m & IFMT == IFDIR;
- }
-
- pub fn ISBLK(m: u32) bool {
- return m & IFMT == IFBLK;
- }
-
- pub fn ISREG(m: u32) bool {
- return m & IFMT == IFREG;
- }
-
- pub fn ISLNK(m: u32) bool {
- return m & IFMT == IFLNK;
- }
-
- pub fn ISSOCK(m: u32) bool {
- return m & IFMT == IFSOCK;
- }
-
- pub fn ISDOOR(m: u32) bool {
- return m & IFMT == IFDOOR;
- }
-
- pub fn ISPORT(m: u32) bool {
- return m & IFMT == IFPORT;
- }
-};
-
pub const POSIX_FADV = struct {
pub const NORMAL = 0;
pub const RANDOM = 1;
@@ -1372,67 +80,6 @@ pub const POSIX_FADV = struct {
pub const NOREUSE = 5;
};
-pub const HOST_NAME_MAX = 255;
-
-pub const IPPROTO = struct {
- /// dummy for IP
- pub const IP = 0;
- /// Hop by hop header for IPv6
- pub const HOPOPTS = 0;
- /// control message protocol
- pub const ICMP = 1;
- /// group control protocol
- pub const IGMP = 2;
- /// gateway^2 (deprecated)
- pub const GGP = 3;
- /// IP in IP encapsulation
- pub const ENCAP = 4;
- /// tcp
- pub const TCP = 6;
- /// exterior gateway protocol
- pub const EGP = 8;
- /// pup
- pub const PUP = 12;
- /// user datagram protocol
- pub const UDP = 17;
- /// xns idp
- pub const IDP = 22;
- /// IPv6 encapsulated in IP
- pub const IPV6 = 41;
- /// Routing header for IPv6
- pub const ROUTING = 43;
- /// Fragment header for IPv6
- pub const FRAGMENT = 44;
- /// rsvp
- pub const RSVP = 46;
- /// IPsec Encap. Sec. Payload
- pub const ESP = 50;
- /// IPsec Authentication Hdr.
- pub const AH = 51;
- /// ICMP for IPv6
- pub const ICMPV6 = 58;
- /// No next header for IPv6
- pub const NONE = 59;
- /// Destination options
- pub const DSTOPTS = 60;
- /// "hello" routing protocol
- pub const HELLO = 63;
- /// UNOFFICIAL net disk proto
- pub const ND = 77;
- /// ISO clnp
- pub const EON = 80;
- /// OSPF
- pub const OSPF = 89;
- /// PIM routing protocol
- pub const PIM = 103;
- /// Stream Control
- pub const SCTP = 132;
- /// raw IP packet
- pub const RAW = 255;
- /// Sockets Direct Protocol
- pub const PROTO_SDP = 257;
-};
-
pub const priority = enum(c_int) {
PROCESS = 0,
PGRP = 1,
@@ -1446,93 +93,6 @@ pub const priority = enum(c_int) {
CONTRACT = 9,
};
-pub const rlimit_resource = enum(c_int) {
- CPU = 0,
- FSIZE = 1,
- DATA = 2,
- STACK = 3,
- CORE = 4,
- NOFILE = 5,
- VMEM = 6,
- _,
-
- pub const AS: rlimit_resource = .VMEM;
-};
-
-pub const rlim_t = u64;
-
-pub const RLIM = struct {
- /// No limit
- pub const INFINITY: rlim_t = (1 << 63) - 3;
- pub const SAVED_MAX: rlim_t = (1 << 63) - 2;
- pub const SAVED_CUR: rlim_t = (1 << 63) - 1;
-};
-
-pub const rlimit = extern struct {
- /// Soft limit
- cur: rlim_t,
- /// Hard limit
- max: rlim_t,
-};
-
-pub const rusage = extern struct {
- utime: timeval,
- stime: timeval,
- maxrss: isize,
- ixrss: isize,
- idrss: isize,
- isrss: isize,
- minflt: isize,
- majflt: isize,
- nswap: isize,
- inblock: isize,
- oublock: isize,
- msgsnd: isize,
- msgrcv: isize,
- nsignals: isize,
- nvcsw: isize,
- nivcsw: isize,
-
- pub const SELF = 0;
- pub const CHILDREN = -1;
- pub const THREAD = 1;
-};
-
-pub const SHUT = struct {
- pub const RD = 0;
- pub const WR = 1;
- pub const RDWR = 2;
-};
-
-pub const pollfd = extern struct {
- fd: fd_t,
- events: i16,
- revents: i16,
-};
-
-/// Testable events (may be specified in ::pollfd::events).
-pub const POLL = struct {
- pub const IN = 0x0001;
- pub const PRI = 0x0002;
- pub const OUT = 0x0004;
- pub const RDNORM = 0x0040;
- pub const WRNORM = .OUT;
- pub const RDBAND = 0x0080;
- pub const WRBAND = 0x0100;
- /// Read-side hangup.
- pub const RDHUP = 0x4000;
-
- /// Non-testable events (may not be specified in events).
- pub const ERR = 0x0008;
- pub const HUP = 0x0010;
- pub const NVAL = 0x0020;
-
- /// Events to control `/dev/poll` (not specified in revents)
- pub const REMOVE = 0x0800;
- pub const ONESHOT = 0x1000;
- pub const ET = 0x2000;
-};
-
/// Extensions to the ELF auxiliary vector.
pub const AT_SUN = struct {
/// effective user id
@@ -1594,7 +154,6 @@ pub const AF_SUN = struct {
pub const NOPLM = 0x00000004;
};
-// TODO: Add sysconf numbers when the other OSs do.
pub const _SC = struct {
pub const NPROCESSORS_ONLN = 15;
};
@@ -1702,17 +261,6 @@ pub const FILE_EVENT = struct {
}
};
-pub const port_event = extern struct {
- events: u32,
- /// Event source.
- source: u16,
- __pad: u16,
- /// Source-specific object.
- object: ?*anyopaque,
- /// User cookie.
- cookie: ?*anyopaque,
-};
-
pub const port_notify = extern struct {
/// Bind request(s) to port.
port: u32,
@@ -1734,9 +282,6 @@ pub const file_obj = extern struct {
// struct ifreq is marked obsolete, with struct lifreq preferred for interface requests.
// Here we alias lifreq to ifreq to avoid chainging existing code in os and x.os.IPv6.
pub const SIOCGLIFINDEX = IOWR('i', 133, lifreq);
-pub const SIOCGIFINDEX = SIOCGLIFINDEX;
-pub const MAX_HDW_LEN = 64;
-pub const IFNAMESIZE = 32;
pub const lif_nd_req = extern struct {
addr: sockaddr.storage,
@@ -1746,7 +291,7 @@ pub const lif_nd_req = extern struct {
hdw_len: i32,
flags: i32,
__pad: i32,
- hdw_addr: [MAX_HDW_LEN]u8,
+ hdw_addr: [64]u8,
};
pub const lif_ifinfo_req = extern struct {
@@ -1806,8 +351,6 @@ pub const lifreq = extern struct {
},
};
-pub const ifreq = lifreq;
-
const IoCtlCommand = enum(u32) {
none = 0x20000000, // no parameters
write = 0x40000000, // copy out parameters
lib/std/c/wasi.zig
@@ -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;
-};
lib/std/c/windows.zig
@@ -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;
lib/std/crypto/Certificate/Bundle/macos.zig
@@ -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;
}
lib/std/crypto/tlcsprng.zig
@@ -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(
lib/std/fs/Dir.zig
@@ -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,
lib/std/fs/File.zig
@@ -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, ×);
lib/std/os/linux/arm-eabi.zig
@@ -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;
lib/std/os/linux/arm64.zig
@@ -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;
lib/std/os/linux/IoUring.zig
@@ -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;
lib/std/os/linux/mips.zig
@@ -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 = {};
lib/std/os/linux/mips64.zig
@@ -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 = {};
lib/std/os/linux/powerpc.zig
@@ -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 = {};
lib/std/os/linux/powerpc64.zig
@@ -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 = {};
lib/std/os/linux/riscv64.zig
@@ -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 = {};
lib/std/os/linux/sparc64.zig
@@ -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,
lib/std/os/linux/test.zig
@@ -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{
lib/std/os/linux/x86.zig
@@ -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 {
lib/std/os/linux/x86_64.zig
@@ -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;
lib/std/os/windows/ws2_32.zig
@@ -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
lib/std/os/emscripten.zig
@@ -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 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 TCSA = std.posix.TCSA;
+pub const addrinfo = c.addrinfo;
-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 {
lib/std/os/linux.zig
@@ -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
lib/std/posix/test.zig
@@ -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);
}
lib/std/Thread/Futex.zig
@@ -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;
}
}
lib/std/Thread/Mutex.zig
@@ -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 = .{},
lib/std/c.zig
@@ -1,14 +1,43 @@
const std = @import("std");
const builtin = @import("builtin");
const c = @This();
+const maxInt = std.math.maxInt;
+const assert = std.debug.assert;
const page_size = std.mem.page_size;
const iovec = std.posix.iovec;
const iovec_const = std.posix.iovec_const;
-const wasi = @import("c/wasi.zig");
+const winsize = std.posix.winsize;
const native_abi = builtin.abi;
const native_arch = builtin.cpu.arch;
const native_os = builtin.os.tag;
const linux = std.os.linux;
+const emscripten = std.os.emscripten;
+const wasi = std.os.wasi;
+const windows = std.os.windows;
+const ws2_32 = std.os.windows.ws2_32;
+const darwin = @import("c/darwin.zig");
+const freebsd = @import("c/freebsd.zig");
+const solaris = @import("c/solaris.zig");
+const netbsd = @import("c/netbsd.zig");
+const dragonfly = @import("c/dragonfly.zig");
+const haiku = @import("c/haiku.zig");
+const openbsd = @import("c/openbsd.zig");
+
+/// The value of the link editor defined symbol _MH_EXECUTE_SYM is the address
+/// of the mach header in a Mach-O executable file type. It does not appear in
+/// any file type other than a MH_EXECUTE file type. The type of the symbol is
+/// absolute as the header is not part of any section.
+/// This symbol is populated when linking the system's libc, which is guaranteed
+/// on this operating system. However when building object files or libraries,
+/// the system libc won't be linked until the final executable. So we
+/// export a weak symbol here, to be overridden by the real one.
+pub extern var _mh_execute_header: mach_hdr;
+var dummy_execute_header: mach_hdr = undefined;
+comptime {
+ if (native_os.isDarwin()) {
+ @export(dummy_execute_header, .{ .name = "_mh_execute_header", .linkage = .weak });
+ }
+}
/// If not linking libc, returns false.
/// If linking musl libc, returns true.
@@ -26,25 +55,6572 @@ pub inline fn versionCheck(comptime glibc_version: std.SemanticVersion) bool {
.gt, .eq => true,
.lt => false,
};
- } else {
- break :blk false;
+ } else {
+ break :blk false;
+ }
+ };
+}
+
+pub const ino_t = switch (native_os) {
+ .linux => linux.ino_t,
+ .emscripten => emscripten.ino_t,
+ .wasi => wasi.inode_t,
+ .windows => windows.LARGE_INTEGER,
+ .haiku => i64,
+ else => u64,
+};
+
+pub const off_t = switch (native_os) {
+ .linux => linux.off_t,
+ .emscripten => emscripten.off_t,
+ else => i64,
+};
+
+pub const timespec = switch (native_os) {
+ .linux => linux.timespec,
+ .emscripten => emscripten.timespec,
+ .wasi => extern struct {
+ sec: time_t,
+ nsec: isize,
+
+ pub fn fromTimestamp(tm: wasi.timestamp_t) timespec {
+ const sec: wasi.timestamp_t = tm / 1_000_000_000;
+ const nsec = tm - sec * 1_000_000_000;
+ return .{
+ .sec = @as(time_t, @intCast(sec)),
+ .nsec = @as(isize, @intCast(nsec)),
+ };
+ }
+
+ pub fn toTimestamp(ts: timespec) wasi.timestamp_t {
+ return @as(wasi.timestamp_t, @intCast(ts.sec * 1_000_000_000)) +
+ @as(wasi.timestamp_t, @intCast(ts.nsec));
+ }
+ },
+ .windows => extern struct {
+ sec: time_t,
+ nsec: c_long,
+ },
+ .dragonfly, .freebsd, .kfreebsd, .macos, .ios, .tvos, .watchos, .visionos => extern struct {
+ sec: isize,
+ nsec: isize,
+ },
+ .netbsd, .solaris, .illumos => extern struct {
+ sec: i64,
+ nsec: isize,
+ },
+ .openbsd, .haiku => extern struct {
+ sec: time_t,
+ nsec: isize,
+ },
+ else => void,
+};
+
+pub const dev_t = switch (native_os) {
+ .linux => linux.dev_t,
+ .emscripten => emscripten.dev_t,
+ .wasi => wasi.device_t,
+ .openbsd, .haiku, .solaris, .illumos, .macos, .ios, .tvos, .watchos, .visionos => i32,
+ .netbsd, .freebsd, .kfreebsd => u64,
+ else => void,
+};
+
+pub const mode_t = switch (native_os) {
+ .linux => linux.mode_t,
+ .emscripten => emscripten.mode_t,
+ .openbsd, .haiku, .netbsd, .solaris, .illumos, .wasi => u32,
+ .freebsd, .kfreebsd, .macos, .ios, .tvos, .watchos, .visionos => u16,
+ else => u0,
+};
+
+pub const nlink_t = switch (native_os) {
+ .linux => linux.nlink_t,
+ .emscripten => emscripten.nlink_t,
+ .wasi => c_ulonglong,
+ .freebsd, .kfreebsd => u64,
+ .openbsd, .netbsd, .solaris, .illumos => u32,
+ .haiku => i32,
+ else => void,
+};
+
+pub const uid_t = switch (native_os) {
+ .linux => linux.uid_t,
+ .emscripten => emscripten.uid_t,
+ else => u32,
+};
+
+pub const gid_t = switch (native_os) {
+ .linux => linux.gid_t,
+ .emscripten => emscripten.gid_t,
+ else => u32,
+};
+
+pub const blksize_t = switch (native_os) {
+ .linux => linux.blksize_t,
+ .emscripten => emscripten.blksize_t,
+ .wasi => c_long,
+ else => i32,
+};
+
+pub const passwd = switch (native_os) {
+ .linux => extern struct {
+ name: ?[*:0]const u8, // username
+ passwd: ?[*:0]const u8, // user password
+ uid: uid_t, // user ID
+ gid: gid_t, // group ID
+ gecos: ?[*:0]const u8, // user information
+ dir: ?[*:0]const u8, // home directory
+ shell: ?[*:0]const u8, // shell program
+ },
+ .openbsd => extern struct {
+ name: ?[*:0]const u8, // user name
+ passwd: ?[*:0]const u8, // encrypted password
+ uid: uid_t, // user uid
+ gid: gid_t, // user gid
+ change: time_t, // password change time
+ class: ?[*:0]const u8, // user access class
+ gecos: ?[*:0]const u8, // Honeywell login info
+ dir: ?[*:0]const u8, // home directory
+ shell: ?[*:0]const u8, // default shell
+ expire: time_t, // account expiration
+ },
+ else => void,
+};
+
+pub const blkcnt_t = switch (native_os) {
+ .linux => linux.blkcnt_t,
+ .emscripten => emscripten.blkcnt_t,
+ .wasi => c_longlong,
+ else => i64,
+};
+
+pub const fd_t = switch (native_os) {
+ .linux => linux.fd_t,
+ .wasi => wasi.fd_t,
+ .windows => windows.HANDLE,
+ else => i32,
+};
+
+pub const ARCH = switch (native_os) {
+ .linux => linux.ARCH,
+ else => void,
+};
+pub const CLOCK = clockid_t;
+pub const clockid_t = switch (native_os) {
+ .linux, .emscripten => linux.clockid_t,
+ .wasi => wasi.clockid_t,
+ .macos, .ios, .tvos, .watchos, .visionos => enum(u32) {
+ REALTIME = 0,
+ MONOTONIC = 6,
+ MONOTONIC_RAW = 4,
+ MONOTONIC_RAW_APPROX = 5,
+ UPTIME_RAW = 8,
+ UPTIME_RAW_APPROX = 9,
+ PROCESS_CPUTIME_ID = 12,
+ THREAD_CPUTIME_ID = 16,
+ _,
+ },
+ .haiku => enum(i32) {
+ /// system-wide monotonic clock (aka system time)
+ MONOTONIC = 0,
+ /// system-wide real time clock
+ REALTIME = -1,
+ /// clock measuring the used CPU time of the current process
+ PROCESS_CPUTIME_ID = -2,
+ /// clock measuring the used CPU time of the current thread
+ THREAD_CPUTIME_ID = -3,
+ },
+ .freebsd, .kfreebsd => enum(u32) {
+ REALTIME = 0,
+ VIRTUAL = 1,
+ PROF = 2,
+ MONOTONIC = 4,
+ UPTIME = 5,
+ UPTIME_PRECISE = 7,
+ UPTIME_FAST = 8,
+ REALTIME_PRECISE = 9,
+ REALTIME_FAST = 10,
+ MONOTONIC_PRECISE = 11,
+ MONOTONIC_FAST = 12,
+ SECOND = 13,
+ THREAD_CPUTIME_ID = 14,
+ PROCESS_CPUTIME_ID = 15,
+ },
+ .solaris, .illumos => enum(u32) {
+ VIRTUAL = 1,
+ THREAD_CPUTIME_ID = 2,
+ REALTIME = 3,
+ MONOTONIC = 4,
+ PROCESS_CPUTIME_ID = 5,
+ },
+ .netbsd => enum(u32) {
+ REALTIME = 0,
+ VIRTUAL = 1,
+ PROF = 2,
+ MONOTONIC = 3,
+ THREAD_CPUTIME_ID = 0x20000000,
+ PROCESS_CPUTIME_ID = 0x40000000,
+ },
+ .dragonfly => enum(u32) {
+ REALTIME = 0,
+ VIRTUAL = 1,
+ PROF = 2,
+ MONOTONIC = 4,
+ UPTIME = 5,
+ UPTIME_PRECISE = 7,
+ UPTIME_FAST = 8,
+ REALTIME_PRECISE = 9,
+ REALTIME_FAST = 10,
+ MONOTONIC_PRECISE = 11,
+ MONOTONIC_FAST = 12,
+ SECOND = 13,
+ THREAD_CPUTIME_ID = 14,
+ PROCESS_CPUTIME_ID = 15,
+ },
+ .openbsd => enum(u32) {
+ REALTIME = 0,
+ PROCESS_CPUTIME_ID = 2,
+ MONOTONIC = 3,
+ THREAD_CPUTIME_ID = 4,
+ },
+ else => void,
+};
+pub const CPU_COUNT = switch (native_os) {
+ .linux => linux.CPU_COUNT,
+ .emscripten => emscripten.CPU_COUNT,
+ else => void,
+};
+pub const E = switch (native_os) {
+ .linux => linux.E,
+ .emscripten => emscripten.E,
+ .wasi => wasi.errno_t,
+ .windows => 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,
+ _,
+ },
+ .macos, .ios, .tvos, .watchos, .visionos => darwin.E,
+ .freebsd, .kfreebsd => freebsd.E,
+ .solaris, .illumos => enum(u16) {
+ /// No error occurred.
+ SUCCESS = 0,
+ /// Not super-user
+ PERM = 1,
+ /// No such file or directory
+ NOENT = 2,
+ /// No such process
+ SRCH = 3,
+ /// interrupted system call
+ INTR = 4,
+ /// I/O error
+ IO = 5,
+ /// No such device or address
+ NXIO = 6,
+ /// Arg list too long
+ @"2BIG" = 7,
+ /// Exec format error
+ NOEXEC = 8,
+ /// Bad file number
+ BADF = 9,
+ /// No children
+ CHILD = 10,
+ /// Resource temporarily unavailable.
+ /// also: WOULDBLOCK: Operation would block.
+ AGAIN = 11,
+ /// Not enough core
+ NOMEM = 12,
+ /// Permission denied
+ ACCES = 13,
+ /// Bad address
+ FAULT = 14,
+ /// Block device required
+ NOTBLK = 15,
+ /// Mount device busy
+ BUSY = 16,
+ /// File exists
+ EXIST = 17,
+ /// Cross-device link
+ XDEV = 18,
+ /// No such device
+ NODEV = 19,
+ /// Not a directory
+ NOTDIR = 20,
+ /// Is a directory
+ ISDIR = 21,
+ /// Invalid argument
+ INVAL = 22,
+ /// File table overflow
+ NFILE = 23,
+ /// Too many open files
+ MFILE = 24,
+ /// Inappropriate ioctl for device
+ NOTTY = 25,
+ /// Text file busy
+ TXTBSY = 26,
+ /// File too large
+ FBIG = 27,
+ /// No space left on device
+ NOSPC = 28,
+ /// Illegal seek
+ SPIPE = 29,
+ /// Read only file system
+ ROFS = 30,
+ /// Too many links
+ MLINK = 31,
+ /// Broken pipe
+ PIPE = 32,
+ /// Math arg out of domain of func
+ DOM = 33,
+ /// Math result not representable
+ RANGE = 34,
+ /// No message of desired type
+ NOMSG = 35,
+ /// Identifier removed
+ IDRM = 36,
+ /// Channel number out of range
+ CHRNG = 37,
+ /// Level 2 not synchronized
+ L2NSYNC = 38,
+ /// Level 3 halted
+ L3HLT = 39,
+ /// Level 3 reset
+ L3RST = 40,
+ /// Link number out of range
+ LNRNG = 41,
+ /// Protocol driver not attached
+ UNATCH = 42,
+ /// No CSI structure available
+ NOCSI = 43,
+ /// Level 2 halted
+ L2HLT = 44,
+ /// Deadlock condition.
+ DEADLK = 45,
+ /// No record locks available.
+ NOLCK = 46,
+ /// Operation canceled
+ CANCELED = 47,
+ /// Operation not supported
+ NOTSUP = 48,
+
+ // Filesystem Quotas
+ /// Disc quota exceeded
+ DQUOT = 49,
+
+ // Convergent Error Returns
+ /// invalid exchange
+ BADE = 50,
+ /// invalid request descriptor
+ BADR = 51,
+ /// exchange full
+ XFULL = 52,
+ /// no anode
+ NOANO = 53,
+ /// invalid request code
+ BADRQC = 54,
+ /// invalid slot
+ BADSLT = 55,
+ /// file locking deadlock error
+ DEADLOCK = 56,
+ /// bad font file fmt
+ BFONT = 57,
+
+ // Interprocess Robust Locks
+ /// process died with the lock
+ OWNERDEAD = 58,
+ /// lock is not recoverable
+ NOTRECOVERABLE = 59,
+ /// locked lock was unmapped
+ LOCKUNMAPPED = 72,
+ /// Facility is not active
+ NOTACTIVE = 73,
+ /// multihop attempted
+ MULTIHOP = 74,
+ /// trying to read unreadable message
+ BADMSG = 77,
+ /// path name is too long
+ NAMETOOLONG = 78,
+ /// value too large to be stored in data type
+ OVERFLOW = 79,
+ /// given log. name not unique
+ NOTUNIQ = 80,
+ /// f.d. invalid for this operation
+ BADFD = 81,
+ /// Remote address changed
+ REMCHG = 82,
+
+ // Stream Problems
+ /// Device not a stream
+ NOSTR = 60,
+ /// no data (for no delay io)
+ NODATA = 61,
+ /// timer expired
+ TIME = 62,
+ /// out of streams resources
+ NOSR = 63,
+ /// Machine is not on the network
+ NONET = 64,
+ /// Package not installed
+ NOPKG = 65,
+ /// The object is remote
+ REMOTE = 66,
+ /// the link has been severed
+ NOLINK = 67,
+ /// advertise error
+ ADV = 68,
+ /// srmount error
+ SRMNT = 69,
+ /// Communication error on send
+ COMM = 70,
+ /// Protocol error
+ PROTO = 71,
+
+ // Shared Library Problems
+ /// Can't access a needed shared lib.
+ LIBACC = 83,
+ /// Accessing a corrupted shared lib.
+ LIBBAD = 84,
+ /// .lib section in a.out corrupted.
+ LIBSCN = 85,
+ /// Attempting to link in too many libs.
+ LIBMAX = 86,
+ /// Attempting to exec a shared library.
+ LIBEXEC = 87,
+ /// Illegal byte sequence.
+ ILSEQ = 88,
+ /// Unsupported file system operation
+ NOSYS = 89,
+ /// Symbolic link loop
+ LOOP = 90,
+ /// Restartable system call
+ RESTART = 91,
+ /// if pipe/FIFO, don't sleep in stream head
+ STRPIPE = 92,
+ /// directory not empty
+ NOTEMPTY = 93,
+ /// Too many users (for UFS)
+ USERS = 94,
+
+ // BSD Networking Software
+ // Argument Errors
+ /// Socket operation on non-socket
+ NOTSOCK = 95,
+ /// Destination address required
+ DESTADDRREQ = 96,
+ /// Message too long
+ MSGSIZE = 97,
+ /// Protocol wrong type for socket
+ PROTOTYPE = 98,
+ /// Protocol not available
+ NOPROTOOPT = 99,
+ /// Protocol not supported
+ PROTONOSUPPORT = 120,
+ /// Socket type not supported
+ SOCKTNOSUPPORT = 121,
+ /// Operation not supported on socket
+ OPNOTSUPP = 122,
+ /// Protocol family not supported
+ PFNOSUPPORT = 123,
+ /// Address family not supported by
+ AFNOSUPPORT = 124,
+ /// Address already in use
+ ADDRINUSE = 125,
+ /// Can't assign requested address
+ ADDRNOTAVAIL = 126,
+
+ // Operational Errors
+ /// Network is down
+ NETDOWN = 127,
+ /// Network is unreachable
+ NETUNREACH = 128,
+ /// Network dropped connection because
+ NETRESET = 129,
+ /// Software caused connection abort
+ CONNABORTED = 130,
+ /// Connection reset by peer
+ CONNRESET = 131,
+ /// No buffer space available
+ NOBUFS = 132,
+ /// Socket is already connected
+ ISCONN = 133,
+ /// Socket is not connected
+ NOTCONN = 134,
+ /// Can't send after socket shutdown
+ SHUTDOWN = 143,
+ /// Too many references: can't splice
+ TOOMANYREFS = 144,
+ /// Connection timed out
+ TIMEDOUT = 145,
+ /// Connection refused
+ CONNREFUSED = 146,
+ /// Host is down
+ HOSTDOWN = 147,
+ /// No route to host
+ HOSTUNREACH = 148,
+ /// operation already in progress
+ ALREADY = 149,
+ /// operation now in progress
+ INPROGRESS = 150,
+
+ // SUN Network File System
+ /// Stale NFS file handle
+ STALE = 151,
+
+ _,
+ },
+ .netbsd => netbsd.E,
+ .dragonfly => dragonfly.E,
+ .haiku => haiku.E,
+ .openbsd => openbsd.E,
+ else => void,
+};
+pub const Elf_Symndx = switch (native_os) {
+ .linux => linux.Elf_Symndx,
+ else => void,
+};
+/// Command flags for fcntl(2).
+pub const F = switch (native_os) {
+ .linux => linux.F,
+ .emscripten => emscripten.F,
+ .wasi => struct {
+ pub const GETFD = 1;
+ pub const SETFD = 2;
+ pub const GETFL = 3;
+ pub const SETFL = 4;
+ },
+ .macos, .ios, .tvos, .watchos, .visionos => struct {
+ /// duplicate file descriptor
+ pub const DUPFD = 0;
+ /// get file descriptor flags
+ pub const GETFD = 1;
+ /// set file descriptor flags
+ pub const SETFD = 2;
+ /// get file status flags
+ pub const GETFL = 3;
+ /// set file status flags
+ pub const SETFL = 4;
+ /// get SIGIO/SIGURG proc/pgrp
+ pub const GETOWN = 5;
+ /// set SIGIO/SIGURG proc/pgrp
+ pub const SETOWN = 6;
+ /// get record locking information
+ pub const GETLK = 7;
+ /// set record locking information
+ pub const SETLK = 8;
+ /// F.SETLK; wait if blocked
+ pub const SETLKW = 9;
+ /// F.SETLK; wait if blocked, return on timeout
+ pub const SETLKWTIMEOUT = 10;
+ pub const FLUSH_DATA = 40;
+ /// Used for regression test
+ pub const CHKCLEAN = 41;
+ /// Preallocate storage
+ pub const PREALLOCATE = 42;
+ /// Truncate a file without zeroing space
+ pub const SETSIZE = 43;
+ /// Issue an advisory read async with no copy to user
+ pub const RDADVISE = 44;
+ /// turn read ahead off/on for this fd
+ pub const RDAHEAD = 45;
+ /// turn data caching off/on for this fd
+ pub const NOCACHE = 48;
+ /// file offset to device offset
+ pub const LOG2PHYS = 49;
+ /// return the full path of the fd
+ pub const GETPATH = 50;
+ /// fsync + ask the drive to flush to the media
+ pub const FULLFSYNC = 51;
+ /// find which component (if any) is a package
+ pub const PATHPKG_CHECK = 52;
+ /// "freeze" all fs operations
+ pub const FREEZE_FS = 53;
+ /// "thaw" all fs operations
+ pub const THAW_FS = 54;
+ /// turn data caching off/on (globally) for this file
+ pub const GLOBAL_NOCACHE = 55;
+ /// add detached signatures
+ pub const ADDSIGS = 59;
+ /// add signature from same file (used by dyld for shared libs)
+ pub const ADDFILESIGS = 61;
+ /// used in conjunction with F.NOCACHE to indicate that DIRECT, synchronous writes
+ /// should not be used (i.e. its ok to temporarily create cached pages)
+ pub const NODIRECT = 62;
+ ///Get the protection class of a file from the EA, returns int
+ pub const GETPROTECTIONCLASS = 63;
+ ///Set the protection class of a file for the EA, requires int
+ pub const SETPROTECTIONCLASS = 64;
+ ///file offset to device offset, extended
+ pub const LOG2PHYS_EXT = 65;
+ ///get record locking information, per-process
+ pub const GETLKPID = 66;
+ ///Mark the file as being the backing store for another filesystem
+ pub const SETBACKINGSTORE = 70;
+ ///return the full path of the FD, but error in specific mtmd circumstances
+ pub const GETPATH_MTMINFO = 71;
+ ///Returns the code directory, with associated hashes, to the caller
+ pub const GETCODEDIR = 72;
+ ///No SIGPIPE generated on EPIPE
+ pub const SETNOSIGPIPE = 73;
+ ///Status of SIGPIPE for this fd
+ pub const GETNOSIGPIPE = 74;
+ ///For some cases, we need to rewrap the key for AKS/MKB
+ pub const TRANSCODEKEY = 75;
+ ///file being written to a by single writer... if throttling enabled, writes
+ ///may be broken into smaller chunks with throttling in between
+ pub const SINGLE_WRITER = 76;
+ ///Get the protection version number for this filesystem
+ pub const GETPROTECTIONLEVEL = 77;
+ ///Add detached code signatures (used by dyld for shared libs)
+ pub const FINDSIGS = 78;
+ ///Add signature from same file, only if it is signed by Apple (used by dyld for simulator)
+ pub const ADDFILESIGS_FOR_DYLD_SIM = 83;
+ ///fsync + issue barrier to drive
+ pub const BARRIERFSYNC = 85;
+ ///Add signature from same file, return end offset in structure on success
+ pub const ADDFILESIGS_RETURN = 97;
+ ///Check if Library Validation allows this Mach-O file to be mapped into the calling process
+ pub const CHECK_LV = 98;
+ ///Deallocate a range of the file
+ pub const PUNCHHOLE = 99;
+ ///Trim an active file
+ pub const TRIM_ACTIVE_FILE = 100;
+ ///mark the dup with FD_CLOEXEC
+ pub const DUPFD_CLOEXEC = 67;
+ /// shared or read lock
+ pub const RDLCK = 1;
+ /// unlock
+ pub const UNLCK = 2;
+ /// exclusive or write lock
+ pub const WRLCK = 3;
+ },
+ .freebsd, .kfreebsd => struct {
+ /// Duplicate file descriptor.
+ pub const DUPFD = 0;
+ /// Get file descriptor flags.
+ pub const GETFD = 1;
+ /// Set file descriptor flags.
+ pub const SETFD = 2;
+ /// Get file status flags.
+ pub const GETFL = 3;
+ /// Set file status flags.
+ pub const SETFL = 4;
+
+ /// Get SIGIO/SIGURG proc/pgrrp.
+ pub const GETOWN = 5;
+ /// Set SIGIO/SIGURG proc/pgrrp.
+ pub const SETOWN = 6;
+
+ /// Get record locking information.
+ pub const GETLK = 11;
+ /// Set record locking information.
+ pub const SETLK = 12;
+ /// Set record locking information and wait if blocked.
+ pub const SETLKW = 13;
+
+ /// Debugging support for remote locks.
+ pub const SETLK_REMOTE = 14;
+ /// Read ahead.
+ pub const READAHEAD = 15;
+
+ /// DUPFD with FD_CLOEXEC set.
+ pub const DUPFD_CLOEXEC = 17;
+ /// DUP2FD with FD_CLOEXEC set.
+ pub const DUP2FD_CLOEXEC = 18;
+
+ pub const ADD_SEALS = 19;
+ pub const GET_SEALS = 20;
+ /// Return `kinfo_file` for a file descriptor.
+ pub const KINFO = 22;
+
+ // Seals (ADD_SEALS, GET_SEALS)
+ /// Prevent adding sealings.
+ pub const SEAL_SEAL = 0x0001;
+ /// May not shrink
+ pub const SEAL_SHRINK = 0x0002;
+ /// May not grow.
+ pub const SEAL_GROW = 0x0004;
+ /// May not write.
+ pub const SEAL_WRITE = 0x0008;
+
+ // Record locking flags (GETLK, SETLK, SETLKW).
+ /// Shared or read lock.
+ pub const RDLCK = 1;
+ /// Unlock.
+ pub const UNLCK = 2;
+ /// Exclusive or write lock.
+ pub const WRLCK = 3;
+ /// Purge locks for a given system ID.
+ pub const UNLCKSYS = 4;
+ /// Cancel an async lock request.
+ pub const CANCEL = 5;
+
+ pub const SETOWN_EX = 15;
+ pub const GETOWN_EX = 16;
+
+ pub const GETOWNER_UIDS = 17;
+ },
+ .solaris, .illumos => struct {
+ /// Unlock a previously locked region
+ pub const ULOCK = 0;
+ /// Lock a region for exclusive use
+ pub const LOCK = 1;
+ /// Test and lock a region for exclusive use
+ pub const TLOCK = 2;
+ /// Test a region for other processes locks
+ pub const TEST = 3;
+
+ /// Duplicate fildes
+ pub const DUPFD = 0;
+ /// Get fildes flags
+ pub const GETFD = 1;
+ /// Set fildes flags
+ pub const SETFD = 2;
+ /// Get file flags
+ pub const GETFL = 3;
+ /// Get file flags including open-only flags
+ pub const GETXFL = 45;
+ /// Set file flags
+ pub const SETFL = 4;
+
+ /// Unused
+ pub const CHKFL = 8;
+ /// Duplicate fildes at third arg
+ pub const DUP2FD = 9;
+ /// Like DUP2FD with O_CLOEXEC set EINVAL is fildes matches arg1
+ pub const DUP2FD_CLOEXEC = 36;
+ /// Like DUPFD with O_CLOEXEC set
+ pub const DUPFD_CLOEXEC = 37;
+
+ /// Is the file desc. a stream ?
+ pub const ISSTREAM = 13;
+ /// Turn on private access to file
+ pub const PRIV = 15;
+ /// Turn off private access to file
+ pub const NPRIV = 16;
+ /// UFS quota call
+ pub const QUOTACTL = 17;
+ /// Get number of BLKSIZE blocks allocated
+ pub const BLOCKS = 18;
+ /// Get optimal I/O block size
+ pub const BLKSIZE = 19;
+ /// Get owner (socket emulation)
+ pub const GETOWN = 23;
+ /// Set owner (socket emulation)
+ pub const SETOWN = 24;
+ /// Object reuse revoke access to file desc.
+ pub const REVOKE = 25;
+ /// Does vp have NFS locks private to lock manager
+ pub const HASREMOTELOCKS = 26;
+
+ /// Set file lock
+ pub const SETLK = 6;
+ /// Set file lock and wait
+ pub const SETLKW = 7;
+ /// Allocate file space
+ pub const ALLOCSP = 10;
+ /// Free file space
+ pub const FREESP = 11;
+ /// Get file lock
+ pub const GETLK = 14;
+ /// Get file lock owned by file
+ pub const OFD_GETLK = 47;
+ /// Set file lock owned by file
+ pub const OFD_SETLK = 48;
+ /// Set file lock owned by file and wait
+ pub const OFD_SETLKW = 49;
+ /// Set a file share reservation
+ pub const SHARE = 40;
+ /// Remove a file share reservation
+ pub const UNSHARE = 41;
+ /// Create Poison FD
+ pub const BADFD = 46;
+
+ /// Read lock
+ pub const RDLCK = 1;
+ /// Write lock
+ pub const WRLCK = 2;
+ /// Remove lock(s)
+ pub const UNLCK = 3;
+ /// remove remote locks for a given system
+ pub const UNLKSYS = 4;
+
+ // f_access values
+ /// Read-only share access
+ pub const RDACC = 0x1;
+ /// Write-only share access
+ pub const WRACC = 0x2;
+ /// Read-Write share access
+ pub const RWACC = 0x3;
+
+ // f_deny values
+ /// Don't deny others access
+ pub const NODNY = 0x0;
+ /// Deny others read share access
+ pub const RDDNY = 0x1;
+ /// Deny others write share access
+ pub const WRDNY = 0x2;
+ /// Deny others read or write share access
+ pub const RWDNY = 0x3;
+ /// private flag: Deny delete share access
+ pub const RMDNY = 0x4;
+ },
+ .netbsd => struct {
+ pub const DUPFD = 0;
+ pub const GETFD = 1;
+ pub const SETFD = 2;
+ pub const GETFL = 3;
+ pub const SETFL = 4;
+ pub const GETOWN = 5;
+ pub const SETOWN = 6;
+ pub const GETLK = 7;
+ pub const SETLK = 8;
+ pub const SETLKW = 9;
+ pub const CLOSEM = 10;
+ pub const MAXFD = 11;
+ pub const DUPFD_CLOEXEC = 12;
+ pub const GETNOSIGPIPE = 13;
+ pub const SETNOSIGPIPE = 14;
+ pub const GETPATH = 15;
+
+ pub const RDLCK = 1;
+ pub const WRLCK = 3;
+ pub const UNLCK = 2;
+ },
+ .dragonfly => struct {
+ pub const ULOCK = 0;
+ pub const LOCK = 1;
+ pub const TLOCK = 2;
+ pub const TEST = 3;
+
+ pub const DUPFD = 0;
+ pub const GETFD = 1;
+ pub const RDLCK = 1;
+ pub const SETFD = 2;
+ pub const UNLCK = 2;
+ pub const WRLCK = 3;
+ pub const GETFL = 3;
+ pub const SETFL = 4;
+ pub const GETOWN = 5;
+ pub const SETOWN = 6;
+ pub const GETLK = 7;
+ pub const SETLK = 8;
+ pub const SETLKW = 9;
+ pub const DUP2FD = 10;
+ pub const DUPFD_CLOEXEC = 17;
+ pub const DUP2FD_CLOEXEC = 18;
+ pub const GETPATH = 19;
+ },
+ .haiku => 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;
+ },
+ .openbsd => struct {
+ pub const DUPFD = 0;
+ pub const GETFD = 1;
+ pub const SETFD = 2;
+ pub const GETFL = 3;
+ pub const SETFL = 4;
+
+ pub const GETOWN = 5;
+ pub const SETOWN = 6;
+
+ pub const GETLK = 7;
+ pub const SETLK = 8;
+ pub const SETLKW = 9;
+
+ pub const RDLCK = 1;
+ pub const UNLCK = 2;
+ pub const WRLCK = 3;
+ },
+ else => void,
+};
+pub const FD_CLOEXEC = switch (native_os) {
+ .linux => linux.FD_CLOEXEC,
+ .emscripten => emscripten.FD_CLOEXEC,
+ else => 1,
+};
+
+/// Test for existence of file.
+pub const F_OK = switch (native_os) {
+ .linux => linux.F_OK,
+ .emscripten => emscripten.F_OK,
+ else => 0,
+};
+/// Test for execute or search permission.
+pub const X_OK = switch (native_os) {
+ .linux => linux.X_OK,
+ .emscripten => emscripten.X_OK,
+ else => 1,
+};
+/// Test for write permission.
+pub const W_OK = switch (native_os) {
+ .linux => linux.W_OK,
+ .emscripten => emscripten.W_OK,
+ else => 2,
+};
+/// Test for read permission.
+pub const R_OK = switch (native_os) {
+ .linux => linux.R_OK,
+ .emscripten => emscripten.R_OK,
+ else => 4,
+};
+
+pub const Flock = switch (native_os) {
+ .linux => linux.Flock,
+ .emscripten => emscripten.Flock,
+ .openbsd, .dragonfly, .netbsd, .macos, .ios, .tvos, .watchos, .visionos => extern struct {
+ start: off_t,
+ len: off_t,
+ pid: pid_t,
+ type: i16,
+ whence: i16,
+ },
+ .freebsd, .kfreebsd => extern struct {
+ /// Starting offset.
+ start: off_t,
+ /// Number of consecutive bytes to be locked.
+ /// A value of 0 means to the end of the file.
+ len: off_t,
+ /// Lock owner.
+ pid: pid_t,
+ /// Lock type.
+ type: i16,
+ /// Type of the start member.
+ whence: i16,
+ /// Remote system id or zero for local.
+ sysid: i32,
+ },
+ .solaris, .illumos => extern struct {
+ type: c_short,
+ whence: c_short,
+ start: off_t,
+ // len == 0 means until end of file.
+ len: off_t,
+ sysid: c_int,
+ pid: pid_t,
+ __pad: [4]c_long,
+ },
+ .haiku => extern struct {
+ type: i16,
+ whence: i16,
+ start: off_t,
+ len: off_t,
+ pid: pid_t,
+ },
+ else => void,
+};
+pub const HOST_NAME_MAX = switch (native_os) {
+ .linux => linux.HOST_NAME_MAX,
+ .macos, .ios, .tvos, .watchos, .visionos => 72,
+ .openbsd, .haiku, .dragonfly, .netbsd, .solaris, .illumos, .freebsd, .kfreebsd => 255,
+ else => {},
+};
+pub const IOV_MAX = switch (native_os) {
+ .linux => linux.IOV_MAX,
+ .emscripten => emscripten.IOV_MAX,
+ .openbsd, .haiku, .solaris, .illumos, .wasi => 1024,
+ .macos, .ios, .tvos, .watchos, .visionos => 16,
+ .dragonfly, .netbsd, .freebsd, .kfreebsd => KERN.IOV_MAX,
+ else => {},
+};
+pub const CTL = switch (native_os) {
+ .freebsd, .kfreebsd => struct {
+ pub const KERN = 1;
+ pub const DEBUG = 5;
+ },
+ .netbsd => struct {
+ pub const KERN = 1;
+ pub const DEBUG = 5;
+ },
+ .dragonfly => struct {
+ pub const UNSPEC = 0;
+ pub const KERN = 1;
+ pub const VM = 2;
+ pub const VFS = 3;
+ pub const NET = 4;
+ pub const DEBUG = 5;
+ pub const HW = 6;
+ pub const MACHDEP = 7;
+ pub const USER = 8;
+ pub const LWKT = 10;
+ pub const MAXID = 11;
+ pub const MAXNAME = 12;
+ },
+ .openbsd => struct {
+ pub const UNSPEC = 0;
+ pub const KERN = 1;
+ pub const VM = 2;
+ pub const FS = 3;
+ pub const NET = 4;
+ pub const DEBUG = 5;
+ pub const HW = 6;
+ pub const MACHDEP = 7;
+
+ pub const DDB = 9;
+ pub const VFS = 10;
+ },
+ else => void,
+};
+pub const KERN = switch (native_os) {
+ .freebsd, .kfreebsd => struct {
+ /// struct: process entries
+ pub const PROC = 14;
+ /// path to executable
+ pub const PROC_PATHNAME = 12;
+ /// file descriptors for process
+ pub const PROC_FILEDESC = 33;
+ pub const IOV_MAX = 35;
+ },
+ .netbsd => struct {
+ /// struct: process argv/env
+ pub const PROC_ARGS = 48;
+ /// path to executable
+ pub const PROC_PATHNAME = 5;
+ pub const IOV_MAX = 38;
+ },
+ .dragonfly => struct {
+ pub const PROC_ALL = 0;
+ pub const OSTYPE = 1;
+ pub const PROC_PID = 1;
+ pub const OSRELEASE = 2;
+ pub const PROC_PGRP = 2;
+ pub const OSREV = 3;
+ pub const PROC_SESSION = 3;
+ pub const VERSION = 4;
+ pub const PROC_TTY = 4;
+ pub const MAXVNODES = 5;
+ pub const PROC_UID = 5;
+ pub const MAXPROC = 6;
+ pub const PROC_RUID = 6;
+ pub const MAXFILES = 7;
+ pub const PROC_ARGS = 7;
+ pub const ARGMAX = 8;
+ pub const PROC_CWD = 8;
+ pub const PROC_PATHNAME = 9;
+ pub const SECURELVL = 9;
+ pub const PROC_SIGTRAMP = 10;
+ pub const HOSTNAME = 10;
+ pub const HOSTID = 11;
+ pub const CLOCKRATE = 12;
+ pub const VNODE = 13;
+ pub const PROC = 14;
+ pub const FILE = 15;
+ pub const PROC_FLAGMASK = 16;
+ pub const PROF = 16;
+ pub const PROC_FLAG_LWP = 16;
+ pub const POSIX1 = 17;
+ pub const NGROUPS = 18;
+ pub const JOB_CONTROL = 19;
+ pub const SAVED_IDS = 20;
+ pub const BOOTTIME = 21;
+ pub const NISDOMAINNAME = 22;
+ pub const UPDATEINTERVAL = 23;
+ pub const OSRELDATE = 24;
+ pub const NTP_PLL = 25;
+ pub const BOOTFILE = 26;
+ pub const MAXFILESPERPROC = 27;
+ pub const MAXPROCPERUID = 28;
+ pub const DUMPDEV = 29;
+ pub const IPC = 30;
+ pub const DUMMY = 31;
+ pub const PS_STRINGS = 32;
+ pub const USRSTACK = 33;
+ pub const LOGSIGEXIT = 34;
+ pub const IOV_MAX = 35;
+ pub const MAXPOSIXLOCKSPERUID = 36;
+ pub const MAXID = 37;
+ },
+ .openbsd => struct {
+ pub const OSTYPE = 1;
+ pub const OSRELEASE = 2;
+ pub const OSREV = 3;
+ pub const VERSION = 4;
+ pub const MAXVNODES = 5;
+ pub const MAXPROC = 6;
+ pub const MAXFILES = 7;
+ pub const ARGMAX = 8;
+ pub const SECURELVL = 9;
+ pub const HOSTNAME = 10;
+ pub const HOSTID = 11;
+ pub const CLOCKRATE = 12;
+
+ pub const PROF = 16;
+ pub const POSIX1 = 17;
+ pub const NGROUPS = 18;
+ pub const JOB_CONTROL = 19;
+ pub const SAVED_IDS = 20;
+ pub const BOOTTIME = 21;
+ pub const DOMAINNAME = 22;
+ pub const MAXPARTITIONS = 23;
+ pub const RAWPARTITION = 24;
+ pub const MAXTHREAD = 25;
+ pub const NTHREADS = 26;
+ pub const OSVERSION = 27;
+ pub const SOMAXCONN = 28;
+ pub const SOMINCONN = 29;
+
+ pub const NOSUIDCOREDUMP = 32;
+ pub const FSYNC = 33;
+ pub const SYSVMSG = 34;
+ pub const SYSVSEM = 35;
+ pub const SYSVSHM = 36;
+
+ pub const MSGBUFSIZE = 38;
+ pub const MALLOCSTATS = 39;
+ pub const CPTIME = 40;
+ pub const NCHSTATS = 41;
+ pub const FORKSTAT = 42;
+ pub const NSELCOLL = 43;
+ pub const TTY = 44;
+ pub const CCPU = 45;
+ pub const FSCALE = 46;
+ pub const NPROCS = 47;
+ pub const MSGBUF = 48;
+ pub const POOL = 49;
+ pub const STACKGAPRANDOM = 50;
+ pub const SYSVIPC_INFO = 51;
+ pub const ALLOWKMEM = 52;
+ pub const WITNESSWATCH = 53;
+ pub const SPLASSERT = 54;
+ pub const PROC_ARGS = 55;
+ pub const NFILES = 56;
+ pub const TTYCOUNT = 57;
+ pub const NUMVNODES = 58;
+ pub const MBSTAT = 59;
+ pub const WITNESS = 60;
+ pub const SEMINFO = 61;
+ pub const SHMINFO = 62;
+ pub const INTRCNT = 63;
+ pub const WATCHDOG = 64;
+ pub const ALLOWDT = 65;
+ pub const PROC = 66;
+ pub const MAXCLUSTERS = 67;
+ pub const EVCOUNT = 68;
+ pub const TIMECOUNTER = 69;
+ pub const MAXLOCKSPERUID = 70;
+ pub const CPTIME2 = 71;
+ pub const CACHEPCT = 72;
+ pub const FILE = 73;
+ pub const WXABORT = 74;
+ pub const CONSDEV = 75;
+ pub const NETLIVELOCKS = 76;
+ pub const POOL_DEBUG = 77;
+ pub const PROC_CWD = 78;
+ pub const PROC_NOBROADCASTKILL = 79;
+ pub const PROC_VMMAP = 80;
+ pub const GLOBAL_PTRACE = 81;
+ pub const CONSBUFSIZE = 82;
+ pub const CONSBUF = 83;
+ pub const AUDIO = 84;
+ pub const CPUSTATS = 85;
+ pub const PFSTATUS = 86;
+ pub const TIMEOUT_STATS = 87;
+ pub const UTC_OFFSET = 88;
+ pub const VIDEO = 89;
+
+ pub const PROC_ALL = 0;
+ pub const PROC_PID = 1;
+ pub const PROC_PGRP = 2;
+ pub const PROC_SESSION = 3;
+ pub const PROC_TTY = 4;
+ pub const PROC_UID = 5;
+ pub const PROC_RUID = 6;
+ pub const PROC_KTHREAD = 7;
+ pub const PROC_SHOW_THREADS = 0x40000000;
+
+ pub const PROC_ARGV = 1;
+ pub const PROC_NARGV = 2;
+ pub const PROC_ENV = 3;
+ pub const PROC_NENV = 4;
+ },
+ else => void,
+};
+pub const LOCK = switch (native_os) {
+ .linux => linux.LOCK,
+ .emscripten => emscripten.LOCK,
+ else => struct {
+ pub const SH = 1;
+ pub const EX = 2;
+ pub const NB = 4;
+ pub const UN = 8;
+ },
+};
+pub const MADV = switch (native_os) {
+ .linux => linux.MADV,
+ .emscripten => emscripten.MADV,
+ .freebsd, .kfreebsd => struct {
+ pub const NORMAL = 0;
+ pub const RANDOM = 1;
+ pub const SEQUENTIAL = 2;
+ pub const WILLNEED = 3;
+ pub const DONTNEED = 4;
+ pub const FREE = 5;
+ pub const NOSYNC = 6;
+ pub const AUTOSYNC = 7;
+ pub const NOCORE = 8;
+ pub const CORE = 9;
+ pub const PROTECT = 10;
+ },
+ .solaris, .illumos => struct {
+ /// no further special treatment
+ pub const NORMAL = 0;
+ /// expect random page references
+ pub const RANDOM = 1;
+ /// expect sequential page references
+ pub const SEQUENTIAL = 2;
+ /// will need these pages
+ pub const WILLNEED = 3;
+ /// don't need these pages
+ pub const DONTNEED = 4;
+ /// contents can be freed
+ pub const FREE = 5;
+ /// default access
+ pub const ACCESS_DEFAULT = 6;
+ /// next LWP to access heavily
+ pub const ACCESS_LWP = 7;
+ /// many processes to access heavily
+ pub const ACCESS_MANY = 8;
+ /// contents will be purged
+ pub const PURGE = 9;
+ },
+ .dragonfly => struct {
+ pub const SEQUENTIAL = 2;
+ pub const CONTROL_END = SETMAP;
+ pub const DONTNEED = 4;
+ pub const RANDOM = 1;
+ pub const WILLNEED = 3;
+ pub const NORMAL = 0;
+ pub const CONTROL_START = INVAL;
+ pub const FREE = 5;
+ pub const NOSYNC = 6;
+ pub const AUTOSYNC = 7;
+ pub const NOCORE = 8;
+ pub const CORE = 9;
+ pub const INVAL = 10;
+ pub const SETMAP = 11;
+ },
+ else => void,
+};
+pub const MSF = switch (native_os) {
+ .linux => linux.MSF,
+ .emscripten => emscripten.MSF,
+ .macos, .ios, .tvos, .watchos, .visionos => struct {
+ pub const ASYNC = 0x1;
+ pub const INVALIDATE = 0x2;
+ /// invalidate, leave mapped
+ pub const KILLPAGES = 0x4;
+ /// deactivate, leave mapped
+ pub const DEACTIVATE = 0x8;
+ pub const SYNC = 0x10;
+ },
+ .openbsd, .haiku, .dragonfly, .netbsd, .solaris, .illumos, .freebsd, .kfreebsd => struct {
+ pub const ASYNC = 1;
+ pub const INVALIDATE = 2;
+ pub const SYNC = 4;
+ },
+ else => void,
+};
+pub const MMAP2_UNIT = switch (native_os) {
+ .linux => linux.MMAP2_UNIT,
+ else => void,
+};
+pub const NAME_MAX = switch (native_os) {
+ .linux => linux.NAME_MAX,
+ .emscripten => emscripten.NAME_MAX,
+ // Haiku's headers make this 256, to contain room for the terminating null
+ // character, but POSIX definition says that NAME_MAX does not include the
+ // terminating null.
+ .haiku, .openbsd, .dragonfly, .netbsd, .solaris, .illumos, .freebsd, .kfreebsd, .macos, .ios, .tvos, .watchos, .visionos => 255,
+ else => {},
+};
+pub const PATH_MAX = switch (native_os) {
+ .linux => linux.PATH_MAX,
+ .emscripten => emscripten.PATH_MAX,
+ .wasi => 4096,
+ .windows => 260,
+ .openbsd, .haiku, .dragonfly, .netbsd, .solaris, .illumos, .freebsd, .kfreebsd, .macos, .ios, .tvos, .watchos, .visionos => 1024,
+ else => {},
+};
+
+pub const POLL = switch (native_os) {
+ .linux => linux.POLL,
+ .emscripten => emscripten.POLL,
+ .wasi => 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;
+ },
+ .windows => ws2_32.POLL,
+ .macos, .ios, .tvos, .watchos, .visionos => struct {
+ pub const IN = 0x001;
+ pub const PRI = 0x002;
+ pub const OUT = 0x004;
+ pub const RDNORM = 0x040;
+ pub const WRNORM = OUT;
+ pub const RDBAND = 0x080;
+ pub const WRBAND = 0x100;
+
+ pub const EXTEND = 0x0200;
+ pub const ATTRIB = 0x0400;
+ pub const NLINK = 0x0800;
+ pub const WRITE = 0x1000;
+
+ pub const ERR = 0x008;
+ pub const HUP = 0x010;
+ pub const NVAL = 0x020;
+
+ pub const STANDARD = IN | PRI | OUT | RDNORM | RDBAND | WRBAND | ERR | HUP | NVAL;
+ },
+ .freebsd, .kfreebsd => struct {
+ /// any readable data available.
+ pub const IN = 0x0001;
+ /// OOB/Urgent readable data.
+ pub const PRI = 0x0002;
+ /// file descriptor is writeable.
+ pub const OUT = 0x0004;
+ /// non-OOB/URG data available.
+ pub const RDNORM = 0x0040;
+ /// no write type differentiation.
+ pub const WRNORM = OUT;
+ /// OOB/Urgent readable data.
+ pub const RDBAND = 0x0080;
+ /// OOB/Urgent data can be written.
+ pub const WRBAND = 0x0100;
+ /// like IN, except ignore EOF.
+ pub const INIGNEOF = 0x2000;
+ /// some poll error occurred.
+ pub const ERR = 0x0008;
+ /// file descriptor was "hung up".
+ pub const HUP = 0x0010;
+ /// requested events "invalid".
+ pub const NVAL = 0x0020;
+
+ pub const STANDARD = IN | PRI | OUT | RDNORM | RDBAND | WRBAND | ERR | HUP | NVAL;
+ },
+ .solaris, .illumos => struct {
+ pub const IN = 0x0001;
+ pub const PRI = 0x0002;
+ pub const OUT = 0x0004;
+ pub const RDNORM = 0x0040;
+ pub const WRNORM = .OUT;
+ pub const RDBAND = 0x0080;
+ pub const WRBAND = 0x0100;
+ /// Read-side hangup.
+ pub const RDHUP = 0x4000;
+
+ /// Non-testable events (may not be specified in events).
+ pub const ERR = 0x0008;
+ pub const HUP = 0x0010;
+ pub const NVAL = 0x0020;
+
+ /// Events to control `/dev/poll` (not specified in revents)
+ pub const REMOVE = 0x0800;
+ pub const ONESHOT = 0x1000;
+ pub const ET = 0x2000;
+ },
+ .dragonfly, .netbsd => struct {
+ /// Testable events (may be specified in events field).
+ pub const IN = 0x0001;
+ pub const PRI = 0x0002;
+ pub const OUT = 0x0004;
+ pub const RDNORM = 0x0040;
+ pub const WRNORM = OUT;
+ pub const RDBAND = 0x0080;
+ pub const WRBAND = 0x0100;
+
+ /// Non-testable events (may not be specified in events field).
+ pub const ERR = 0x0008;
+ pub const HUP = 0x0010;
+ pub const NVAL = 0x0020;
+ },
+ .haiku => 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;
+ },
+ .openbsd => struct {
+ pub const IN = 0x0001;
+ pub const PRI = 0x0002;
+ pub const OUT = 0x0004;
+ pub const ERR = 0x0008;
+ pub const HUP = 0x0010;
+ pub const NVAL = 0x0020;
+ pub const RDNORM = 0x0040;
+ pub const NORM = RDNORM;
+ pub const WRNORM = OUT;
+ pub const RDBAND = 0x0080;
+ pub const WRBAND = 0x0100;
+ },
+ else => void,
+};
+
+/// Basic memory protection flags
+pub const PROT = switch (native_os) {
+ .linux => linux.PROT,
+ .emscripten => emscripten.PROT,
+ .openbsd, .haiku, .dragonfly, .netbsd, .solaris, .illumos, .freebsd, .kfreebsd, .windows => 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;
+ },
+ .macos, .ios, .tvos, .watchos, .visionos => struct {
+ /// [MC2] no permissions
+ pub const NONE: vm_prot_t = 0x00;
+ /// [MC2] pages can be read
+ pub const READ: vm_prot_t = 0x01;
+ /// [MC2] pages can be written
+ pub const WRITE: vm_prot_t = 0x02;
+ /// [MC2] pages can be executed
+ pub const EXEC: vm_prot_t = 0x04;
+ /// When a caller finds that they cannot obtain write permission on a
+ /// mapped entry, the following flag can be used. The entry will be
+ /// made "needs copy" effectively copying the object (using COW),
+ /// and write permission will be added to the maximum protections for
+ /// the associated entry.
+ pub const COPY: vm_prot_t = 0x10;
+ },
+ else => void,
+};
+
+pub const REG = switch (native_os) {
+ .linux => linux.REG,
+ .emscripten => emscripten.REG,
+ .freebsd, .kfreebsd => switch (builtin.cpu.arch) {
+ .aarch64 => struct {
+ pub const FP = 29;
+ pub const SP = 31;
+ pub const PC = 32;
+ },
+ .arm => struct {
+ pub const FP = 11;
+ pub const SP = 13;
+ pub const PC = 15;
+ },
+ .x86_64 => struct {
+ pub const RBP = 12;
+ pub const RIP = 21;
+ pub const RSP = 24;
+ },
+ else => struct {},
+ },
+ .solaris, .illumos => struct {
+ pub const R15 = 0;
+ pub const R14 = 1;
+ pub const R13 = 2;
+ pub const R12 = 3;
+ pub const R11 = 4;
+ pub const R10 = 5;
+ pub const R9 = 6;
+ pub const R8 = 7;
+ pub const RDI = 8;
+ pub const RSI = 9;
+ pub const RBP = 10;
+ pub const RBX = 11;
+ pub const RDX = 12;
+ pub const RCX = 13;
+ pub const RAX = 14;
+ pub const RIP = 17;
+ pub const RSP = 20;
+ },
+ .netbsd => switch (builtin.cpu.arch) {
+ .aarch64 => struct {
+ pub const FP = 29;
+ pub const SP = 31;
+ pub const PC = 32;
+ },
+ .arm => struct {
+ pub const FP = 11;
+ pub const SP = 13;
+ pub const PC = 15;
+ },
+ .x86_64 => struct {
+ pub const RDI = 0;
+ pub const RSI = 1;
+ pub const RDX = 2;
+ pub const RCX = 3;
+ pub const R8 = 4;
+ pub const R9 = 5;
+ pub const R10 = 6;
+ pub const R11 = 7;
+ pub const R12 = 8;
+ pub const R13 = 9;
+ pub const R14 = 10;
+ pub const R15 = 11;
+ pub const RBP = 12;
+ pub const RBX = 13;
+ pub const RAX = 14;
+ pub const GS = 15;
+ pub const FS = 16;
+ pub const ES = 17;
+ pub const DS = 18;
+ pub const TRAPNO = 19;
+ pub const ERR = 20;
+ pub const RIP = 21;
+ pub const CS = 22;
+ pub const RFLAGS = 23;
+ pub const RSP = 24;
+ pub const SS = 25;
+ },
+ else => struct {},
+ },
+ else => struct {},
+};
+pub const RLIM = switch (native_os) {
+ .linux => linux.RLIM,
+ .emscripten => emscripten.RLIM,
+ .openbsd, .haiku, .dragonfly, .netbsd, .freebsd, .kfreebsd, .macos, .ios, .tvos, .watchos, .visionos => struct {
+ /// No limit
+ pub const INFINITY: rlim_t = (1 << 63) - 1;
+
+ pub const SAVED_MAX = INFINITY;
+ pub const SAVED_CUR = INFINITY;
+ },
+ .solaris, .illumos => struct {
+ /// No limit
+ pub const INFINITY: rlim_t = (1 << 63) - 3;
+ pub const SAVED_MAX: rlim_t = (1 << 63) - 2;
+ pub const SAVED_CUR: rlim_t = (1 << 63) - 1;
+ },
+ else => void,
+};
+pub const S = switch (native_os) {
+ .linux => linux.S,
+ .emscripten => emscripten.S,
+ .wasi => 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;
+ },
+ .macos, .ios, .tvos, .watchos, .visionos => struct {
+ pub const IFMT = 0o170000;
+
+ pub const IFIFO = 0o010000;
+ pub const IFCHR = 0o020000;
+ pub const IFDIR = 0o040000;
+ pub const IFBLK = 0o060000;
+ pub const IFREG = 0o100000;
+ pub const IFLNK = 0o120000;
+ pub const IFSOCK = 0o140000;
+ pub const IFWHT = 0o160000;
+
+ 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 ISFIFO(m: u32) bool {
+ return m & IFMT == IFIFO;
+ }
+
+ pub fn ISCHR(m: u32) bool {
+ return m & IFMT == IFCHR;
+ }
+
+ pub fn ISDIR(m: u32) bool {
+ return m & IFMT == IFDIR;
+ }
+
+ pub fn ISBLK(m: u32) bool {
+ return m & IFMT == IFBLK;
+ }
+
+ pub fn ISREG(m: u32) bool {
+ return m & IFMT == IFREG;
+ }
+
+ pub fn ISLNK(m: u32) bool {
+ return m & IFMT == IFLNK;
+ }
+
+ pub fn ISSOCK(m: u32) bool {
+ return m & IFMT == IFSOCK;
+ }
+
+ pub fn IWHT(m: u32) bool {
+ return m & IFMT == IFWHT;
+ }
+ },
+ .freebsd, .kfreebsd => struct {
+ pub const IFMT = 0o170000;
+
+ pub const IFIFO = 0o010000;
+ pub const IFCHR = 0o020000;
+ pub const IFDIR = 0o040000;
+ pub const IFBLK = 0o060000;
+ pub const IFREG = 0o100000;
+ pub const IFLNK = 0o120000;
+ pub const IFSOCK = 0o140000;
+ pub const IFWHT = 0o160000;
+
+ 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 ISFIFO(m: u32) bool {
+ return m & IFMT == IFIFO;
+ }
+
+ pub fn ISCHR(m: u32) bool {
+ return m & IFMT == IFCHR;
+ }
+
+ pub fn ISDIR(m: u32) bool {
+ return m & IFMT == IFDIR;
+ }
+
+ pub fn ISBLK(m: u32) bool {
+ return m & IFMT == IFBLK;
+ }
+
+ pub fn ISREG(m: u32) bool {
+ return m & IFMT == IFREG;
+ }
+
+ pub fn ISLNK(m: u32) bool {
+ return m & IFMT == IFLNK;
+ }
+
+ pub fn ISSOCK(m: u32) bool {
+ return m & IFMT == IFSOCK;
+ }
+
+ pub fn IWHT(m: u32) bool {
+ return m & IFMT == IFWHT;
+ }
+ },
+ .solaris, .illumos => struct {
+ pub const IFMT = 0o170000;
+
+ pub const IFIFO = 0o010000;
+ pub const IFCHR = 0o020000;
+ pub const IFDIR = 0o040000;
+ pub const IFBLK = 0o060000;
+ pub const IFREG = 0o100000;
+ pub const IFLNK = 0o120000;
+ pub const IFSOCK = 0o140000;
+ /// SunOS 2.6 Door
+ pub const IFDOOR = 0o150000;
+ /// Solaris 10 Event Port
+ pub const IFPORT = 0o160000;
+
+ 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 ISFIFO(m: u32) bool {
+ return m & IFMT == IFIFO;
+ }
+
+ pub fn ISCHR(m: u32) bool {
+ return m & IFMT == IFCHR;
+ }
+
+ pub fn ISDIR(m: u32) bool {
+ return m & IFMT == IFDIR;
+ }
+
+ pub fn ISBLK(m: u32) bool {
+ return m & IFMT == IFBLK;
+ }
+
+ pub fn ISREG(m: u32) bool {
+ return m & IFMT == IFREG;
+ }
+
+ pub fn ISLNK(m: u32) bool {
+ return m & IFMT == IFLNK;
+ }
+
+ pub fn ISSOCK(m: u32) bool {
+ return m & IFMT == IFSOCK;
+ }
+
+ pub fn ISDOOR(m: u32) bool {
+ return m & IFMT == IFDOOR;
+ }
+
+ pub fn ISPORT(m: u32) bool {
+ return m & IFMT == IFPORT;
+ }
+ },
+ .netbsd => struct {
+ pub const IFMT = 0o170000;
+
+ pub const IFIFO = 0o010000;
+ pub const IFCHR = 0o020000;
+ pub const IFDIR = 0o040000;
+ pub const IFBLK = 0o060000;
+ pub const IFREG = 0o100000;
+ pub const IFLNK = 0o120000;
+ pub const IFSOCK = 0o140000;
+ pub const IFWHT = 0o160000;
+
+ 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 ISFIFO(m: u32) bool {
+ return m & IFMT == IFIFO;
+ }
+
+ pub fn ISCHR(m: u32) bool {
+ return m & IFMT == IFCHR;
+ }
+
+ pub fn ISDIR(m: u32) bool {
+ return m & IFMT == IFDIR;
+ }
+
+ pub fn ISBLK(m: u32) bool {
+ return m & IFMT == IFBLK;
+ }
+
+ pub fn ISREG(m: u32) bool {
+ return m & IFMT == IFREG;
+ }
+
+ pub fn ISLNK(m: u32) bool {
+ return m & IFMT == IFLNK;
+ }
+
+ pub fn ISSOCK(m: u32) bool {
+ return m & IFMT == IFSOCK;
+ }
+
+ pub fn IWHT(m: u32) bool {
+ return m & IFMT == IFWHT;
+ }
+ },
+ .dragonfly => struct {
+ pub const IREAD = IRUSR;
+ pub const IEXEC = IXUSR;
+ pub const IWRITE = IWUSR;
+ pub const IXOTH = 1;
+ pub const IWOTH = 2;
+ pub const IROTH = 4;
+ pub const IRWXO = 7;
+ pub const IXGRP = 8;
+ pub const IWGRP = 16;
+ pub const IRGRP = 32;
+ pub const IRWXG = 56;
+ pub const IXUSR = 64;
+ pub const IWUSR = 128;
+ pub const IRUSR = 256;
+ pub const IRWXU = 448;
+ pub const ISTXT = 512;
+ pub const BLKSIZE = 512;
+ pub const ISVTX = 512;
+ pub const ISGID = 1024;
+ pub const ISUID = 2048;
+ pub const IFIFO = 4096;
+ pub const IFCHR = 8192;
+ pub const IFDIR = 16384;
+ pub const IFBLK = 24576;
+ pub const IFREG = 32768;
+ pub const IFDB = 36864;
+ pub const IFLNK = 40960;
+ pub const IFSOCK = 49152;
+ pub const IFWHT = 57344;
+ pub const IFMT = 61440;
+
+ pub fn ISCHR(m: u32) bool {
+ return m & IFMT == IFCHR;
+ }
+ },
+ .haiku => 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;
+ }
+ },
+ .openbsd => struct {
+ pub const IFMT = 0o170000;
+
+ pub const IFIFO = 0o010000;
+ pub const IFCHR = 0o020000;
+ pub const IFDIR = 0o040000;
+ pub const IFBLK = 0o060000;
+ pub const IFREG = 0o100000;
+ pub const IFLNK = 0o120000;
+ pub const IFSOCK = 0o140000;
+
+ 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 ISFIFO(m: u32) bool {
+ return m & IFMT == IFIFO;
+ }
+
+ pub fn ISCHR(m: u32) bool {
+ return m & IFMT == IFCHR;
+ }
+
+ pub fn ISDIR(m: u32) bool {
+ return m & IFMT == IFDIR;
+ }
+
+ pub fn ISBLK(m: u32) bool {
+ return m & IFMT == IFBLK;
+ }
+
+ pub fn ISREG(m: u32) bool {
+ return m & IFMT == IFREG;
+ }
+
+ pub fn ISLNK(m: u32) bool {
+ return m & IFMT == IFLNK;
+ }
+
+ pub fn ISSOCK(m: u32) bool {
+ return m & IFMT == IFSOCK;
+ }
+ },
+ else => void,
+};
+pub const SA = switch (native_os) {
+ .linux => linux.SA,
+ .emscripten => emscripten.SA,
+ .macos, .ios, .tvos, .watchos, .visionos => struct {
+ /// take signal on signal stack
+ pub const ONSTACK = 0x0001;
+ /// restart system on signal return
+ pub const RESTART = 0x0002;
+ /// reset to SIG.DFL when taking signal
+ pub const RESETHAND = 0x0004;
+ /// do not generate SIG.CHLD on child stop
+ pub const NOCLDSTOP = 0x0008;
+ /// don't mask the signal we're delivering
+ pub const NODEFER = 0x0010;
+ /// don't keep zombies around
+ pub const NOCLDWAIT = 0x0020;
+ /// signal handler with SIGINFO args
+ pub const SIGINFO = 0x0040;
+ /// do not bounce off kernel's sigtramp
+ pub const USERTRAMP = 0x0100;
+ /// signal handler with SIGINFO args with 64bit regs information
+ pub const @"64REGSET" = 0x0200;
+ },
+ .freebsd, .kfreebsd => struct {
+ pub const ONSTACK = 0x0001;
+ pub const RESTART = 0x0002;
+ pub const RESETHAND = 0x0004;
+ pub const NOCLDSTOP = 0x0008;
+ pub const NODEFER = 0x0010;
+ pub const NOCLDWAIT = 0x0020;
+ pub const SIGINFO = 0x0040;
+ },
+ .solaris, .illumos => struct {
+ pub const ONSTACK = 0x00000001;
+ pub const RESETHAND = 0x00000002;
+ pub const RESTART = 0x00000004;
+ pub const SIGINFO = 0x00000008;
+ pub const NODEFER = 0x00000010;
+ pub const NOCLDWAIT = 0x00010000;
+ },
+ .netbsd => struct {
+ pub const ONSTACK = 0x0001;
+ pub const RESTART = 0x0002;
+ pub const RESETHAND = 0x0004;
+ pub const NOCLDSTOP = 0x0008;
+ pub const NODEFER = 0x0010;
+ pub const NOCLDWAIT = 0x0020;
+ pub const SIGINFO = 0x0040;
+ },
+ .dragonfly => struct {
+ pub const ONSTACK = 0x0001;
+ pub const RESTART = 0x0002;
+ pub const RESETHAND = 0x0004;
+ pub const NODEFER = 0x0010;
+ pub const NOCLDWAIT = 0x0020;
+ pub const SIGINFO = 0x0040;
+ },
+ .haiku => 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;
+ },
+ .openbsd => struct {
+ pub const ONSTACK = 0x0001;
+ pub const RESTART = 0x0002;
+ pub const RESETHAND = 0x0004;
+ pub const NOCLDSTOP = 0x0008;
+ pub const NODEFER = 0x0010;
+ pub const NOCLDWAIT = 0x0020;
+ pub const SIGINFO = 0x0040;
+ },
+ else => void,
+};
+pub const sigval_t = switch (native_os) {
+ .netbsd, .solaris, .illumos => extern union {
+ int: i32,
+ ptr: ?*anyopaque,
+ },
+ else => void,
+};
+
+pub const SC = switch (native_os) {
+ .linux => linux.SC,
+ else => void,
+};
+pub const SEEK = switch (native_os) {
+ .linux => linux.SEEK,
+ .emscripten => emscripten.SEEK,
+ .wasi => struct {
+ pub const SET: wasi.whence_t = .SET;
+ pub const CUR: wasi.whence_t = .CUR;
+ pub const END: wasi.whence_t = .END;
+ },
+ .openbsd, .haiku, .netbsd, .freebsd, .kfreebsd, .macos, .ios, .tvos, .watchos, .visionos, .windows => struct {
+ pub const SET = 0;
+ pub const CUR = 1;
+ pub const END = 2;
+ },
+ .dragonfly, .solaris, .illumos => struct {
+ pub const SET = 0;
+ pub const CUR = 1;
+ pub const END = 2;
+ pub const DATA = 3;
+ pub const HOLE = 4;
+ },
+ else => void,
+};
+pub const SHUT = switch (native_os) {
+ .linux => linux.SHUT,
+ .emscripten => emscripten.SHUT,
+ else => struct {
+ pub const RD = 0;
+ pub const WR = 1;
+ pub const RDWR = 2;
+ },
+};
+
+/// Signal types
+pub const SIG = switch (native_os) {
+ .linux => linux.SIG,
+ .emscripten => emscripten.SIG,
+ .windows => 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;
+ },
+ .macos, .ios, .tvos, .watchos, .visionos => struct {
+ pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
+ pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
+ pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
+ pub const HOLD: ?Sigaction.handler_fn = @ptrFromInt(5);
+
+ /// block specified signal set
+ pub const BLOCK = 1;
+ /// unblock specified signal set
+ pub const UNBLOCK = 2;
+ /// set specified signal set
+ pub const SETMASK = 3;
+ /// hangup
+ pub const HUP = 1;
+ /// interrupt
+ pub const INT = 2;
+ /// quit
+ pub const QUIT = 3;
+ /// illegal instruction (not reset when caught)
+ pub const ILL = 4;
+ /// trace trap (not reset when caught)
+ pub const TRAP = 5;
+ /// abort()
+ pub const ABRT = 6;
+ /// pollable event ([XSR] generated, not supported)
+ pub const POLL = 7;
+ /// compatibility
+ pub const IOT = ABRT;
+ /// EMT instruction
+ pub const EMT = 7;
+ /// floating point exception
+ pub const FPE = 8;
+ /// kill (cannot be caught or ignored)
+ pub const KILL = 9;
+ /// bus error
+ pub const BUS = 10;
+ /// segmentation violation
+ pub const SEGV = 11;
+ /// bad argument to system call
+ pub const SYS = 12;
+ /// write on a pipe with no one to read it
+ pub const PIPE = 13;
+ /// alarm clock
+ pub const ALRM = 14;
+ /// software termination signal from kill
+ pub const TERM = 15;
+ /// urgent condition on IO channel
+ pub const URG = 16;
+ /// sendable stop signal not from tty
+ pub const STOP = 17;
+ /// stop signal from tty
+ pub const TSTP = 18;
+ /// continue a stopped process
+ pub const CONT = 19;
+ /// to parent on child stop or exit
+ pub const CHLD = 20;
+ /// to readers pgrp upon background tty read
+ pub const TTIN = 21;
+ /// like TTIN for output if (tp->t_local<OSTOP)
+ pub const TTOU = 22;
+ /// input/output possible signal
+ pub const IO = 23;
+ /// exceeded CPU time limit
+ pub const XCPU = 24;
+ /// exceeded file size limit
+ pub const XFSZ = 25;
+ /// virtual time alarm
+ pub const VTALRM = 26;
+ /// profiling time alarm
+ pub const PROF = 27;
+ /// window size changes
+ pub const WINCH = 28;
+ /// information request
+ pub const INFO = 29;
+ /// user defined signal 1
+ pub const USR1 = 30;
+ /// user defined signal 2
+ pub const USR2 = 31;
+ },
+ .freebsd, .kfreebsd => struct {
+ pub const HUP = 1;
+ pub const INT = 2;
+ pub const QUIT = 3;
+ pub const ILL = 4;
+ pub const TRAP = 5;
+ pub const ABRT = 6;
+ pub const IOT = ABRT;
+ pub const EMT = 7;
+ pub const FPE = 8;
+ pub const KILL = 9;
+ pub const BUS = 10;
+ pub const SEGV = 11;
+ pub const SYS = 12;
+ pub const PIPE = 13;
+ pub const ALRM = 14;
+ pub const TERM = 15;
+ pub const URG = 16;
+ pub const STOP = 17;
+ pub const TSTP = 18;
+ pub const CONT = 19;
+ pub const CHLD = 20;
+ pub const TTIN = 21;
+ pub const TTOU = 22;
+ pub const IO = 23;
+ pub const XCPU = 24;
+ pub const XFSZ = 25;
+ pub const VTALRM = 26;
+ pub const PROF = 27;
+ pub const WINCH = 28;
+ pub const INFO = 29;
+ pub const USR1 = 30;
+ pub const USR2 = 31;
+ pub const THR = 32;
+ pub const LWP = THR;
+ pub const LIBRT = 33;
+
+ pub const RTMIN = 65;
+ pub const RTMAX = 126;
+
+ pub const BLOCK = 1;
+ pub const UNBLOCK = 2;
+ pub const SETMASK = 3;
+
+ 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 WORDS = 4;
+ pub const MAXSIG = 128;
+
+ pub inline fn IDX(sig: usize) usize {
+ return sig - 1;
+ }
+ pub inline fn WORD(sig: usize) usize {
+ return IDX(sig) >> 5;
+ }
+ pub inline fn BIT(sig: usize) usize {
+ return 1 << (IDX(sig) & 31);
+ }
+ pub inline fn VALID(sig: usize) usize {
+ return sig <= MAXSIG and sig > 0;
+ }
+ },
+ .solaris, .illumos => struct {
+ pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
+ pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
+ pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
+ pub const HOLD: ?Sigaction.handler_fn = @ptrFromInt(2);
+
+ pub const WORDS = 4;
+ pub const MAXSIG = 75;
+
+ pub const SIG_BLOCK = 1;
+ pub const SIG_UNBLOCK = 2;
+ pub const SIG_SETMASK = 3;
+
+ pub const HUP = 1;
+ pub const INT = 2;
+ pub const QUIT = 3;
+ pub const ILL = 4;
+ pub const TRAP = 5;
+ pub const IOT = 6;
+ pub const ABRT = 6;
+ pub const EMT = 7;
+ pub const FPE = 8;
+ pub const KILL = 9;
+ pub const BUS = 10;
+ pub const SEGV = 11;
+ pub const SYS = 12;
+ pub const PIPE = 13;
+ pub const ALRM = 14;
+ pub const TERM = 15;
+ pub const USR1 = 16;
+ pub const USR2 = 17;
+ pub const CLD = 18;
+ pub const CHLD = 18;
+ pub const PWR = 19;
+ pub const WINCH = 20;
+ pub const URG = 21;
+ pub const POLL = 22;
+ pub const IO = .POLL;
+ pub const STOP = 23;
+ pub const TSTP = 24;
+ pub const CONT = 25;
+ pub const TTIN = 26;
+ pub const TTOU = 27;
+ pub const VTALRM = 28;
+ pub const PROF = 29;
+ pub const XCPU = 30;
+ pub const XFSZ = 31;
+ pub const WAITING = 32;
+ pub const LWP = 33;
+ pub const FREEZE = 34;
+ pub const THAW = 35;
+ pub const CANCEL = 36;
+ pub const LOST = 37;
+ pub const XRES = 38;
+ pub const JVM1 = 39;
+ pub const JVM2 = 40;
+ pub const INFO = 41;
+
+ pub const RTMIN = 42;
+ pub const RTMAX = 74;
+
+ pub inline fn IDX(sig: usize) usize {
+ return sig - 1;
+ }
+ pub inline fn WORD(sig: usize) usize {
+ return IDX(sig) >> 5;
+ }
+ pub inline fn BIT(sig: usize) usize {
+ return 1 << (IDX(sig) & 31);
+ }
+ pub inline fn VALID(sig: usize) usize {
+ return sig <= MAXSIG and sig > 0;
+ }
+ },
+ .netbsd => 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 WORDS = 4;
+ pub const MAXSIG = 128;
+
+ pub const BLOCK = 1;
+ pub const UNBLOCK = 2;
+ pub const SETMASK = 3;
+
+ pub const HUP = 1;
+ pub const INT = 2;
+ pub const QUIT = 3;
+ pub const ILL = 4;
+ pub const TRAP = 5;
+ pub const ABRT = 6;
+ pub const IOT = ABRT;
+ pub const EMT = 7;
+ pub const FPE = 8;
+ pub const KILL = 9;
+ pub const BUS = 10;
+ pub const SEGV = 11;
+ pub const SYS = 12;
+ pub const PIPE = 13;
+ pub const ALRM = 14;
+ pub const TERM = 15;
+ pub const URG = 16;
+ pub const STOP = 17;
+ pub const TSTP = 18;
+ pub const CONT = 19;
+ pub const CHLD = 20;
+ pub const TTIN = 21;
+ pub const TTOU = 22;
+ pub const IO = 23;
+ pub const XCPU = 24;
+ pub const XFSZ = 25;
+ pub const VTALRM = 26;
+ pub const PROF = 27;
+ pub const WINCH = 28;
+ pub const INFO = 29;
+ pub const USR1 = 30;
+ pub const USR2 = 31;
+ pub const PWR = 32;
+
+ pub const RTMIN = 33;
+ pub const RTMAX = 63;
+
+ pub inline fn IDX(sig: usize) usize {
+ return sig - 1;
+ }
+ pub inline fn WORD(sig: usize) usize {
+ return IDX(sig) >> 5;
+ }
+ pub inline fn BIT(sig: usize) usize {
+ return 1 << (IDX(sig) & 31);
+ }
+ pub inline fn VALID(sig: usize) usize {
+ return sig <= MAXSIG and sig > 0;
+ }
+ },
+ .dragonfly => 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 BLOCK = 1;
+ pub const UNBLOCK = 2;
+ pub const SETMASK = 3;
+
+ pub const IOT = ABRT;
+ pub const HUP = 1;
+ pub const INT = 2;
+ pub const QUIT = 3;
+ pub const ILL = 4;
+ pub const TRAP = 5;
+ pub const ABRT = 6;
+ pub const EMT = 7;
+ pub const FPE = 8;
+ pub const KILL = 9;
+ pub const BUS = 10;
+ pub const SEGV = 11;
+ pub const SYS = 12;
+ pub const PIPE = 13;
+ pub const ALRM = 14;
+ pub const TERM = 15;
+ pub const URG = 16;
+ pub const STOP = 17;
+ pub const TSTP = 18;
+ pub const CONT = 19;
+ pub const CHLD = 20;
+ pub const TTIN = 21;
+ pub const TTOU = 22;
+ pub const IO = 23;
+ pub const XCPU = 24;
+ pub const XFSZ = 25;
+ pub const VTALRM = 26;
+ pub const PROF = 27;
+ pub const WINCH = 28;
+ pub const INFO = 29;
+ pub const USR1 = 30;
+ pub const USR2 = 31;
+ pub const THR = 32;
+ pub const CKPT = 33;
+ pub const CKPTEXIT = 34;
+
+ pub const WORDS = 4;
+ },
+ .haiku => 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;
+ },
+ .openbsd => 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 CATCH: ?Sigaction.handler_fn = @ptrFromInt(2);
+ 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 TRAP = 5;
+ pub const ABRT = 6;
+ pub const IOT = ABRT;
+ pub const EMT = 7;
+ pub const FPE = 8;
+ pub const KILL = 9;
+ pub const BUS = 10;
+ pub const SEGV = 11;
+ pub const SYS = 12;
+ pub const PIPE = 13;
+ pub const ALRM = 14;
+ pub const TERM = 15;
+ pub const URG = 16;
+ pub const STOP = 17;
+ pub const TSTP = 18;
+ pub const CONT = 19;
+ pub const CHLD = 20;
+ pub const TTIN = 21;
+ pub const TTOU = 22;
+ pub const IO = 23;
+ pub const XCPU = 24;
+ pub const XFSZ = 25;
+ pub const VTALRM = 26;
+ pub const PROF = 27;
+ pub const WINCH = 28;
+ pub const INFO = 29;
+ pub const USR1 = 30;
+ pub const USR2 = 31;
+ pub const PWR = 32;
+
+ pub const BLOCK = 1;
+ pub const UNBLOCK = 2;
+ pub const SETMASK = 3;
+ },
+ else => void,
+};
+
+pub const SIOCGIFINDEX = switch (native_os) {
+ .linux => linux.SIOCGIFINDEX,
+ .emscripten => emscripten.SIOCGIFINDEX,
+ .solaris, .illumos => solaris.SIOCGLIFINDEX,
+ else => void,
+};
+
+pub const STDIN_FILENO = switch (native_os) {
+ .linux => linux.STDIN_FILENO,
+ .emscripten => emscripten.STDIN_FILENO,
+ else => 0,
+};
+pub const STDOUT_FILENO = switch (native_os) {
+ .linux => linux.STDOUT_FILENO,
+ .emscripten => emscripten.STDOUT_FILENO,
+ else => 1,
+};
+pub const STDERR_FILENO = switch (native_os) {
+ .linux => linux.STDERR_FILENO,
+ .emscripten => emscripten.STDERR_FILENO,
+ else => 2,
+};
+
+pub const SYS = switch (native_os) {
+ .linux => linux.SYS,
+ else => void,
+};
+/// Renamed from `sigaction` to `Sigaction` to avoid conflict with function name.
+pub const Sigaction = switch (native_os) {
+ .linux => linux.Sigaction,
+ .emscripten => emscripten.Sigaction,
+ .netbsd, .macos, .ios, .tvos, .watchos, .visionos => 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;
+
+ handler: extern union {
+ handler: ?handler_fn,
+ sigaction: ?sigaction_fn,
+ },
+ mask: sigset_t,
+ flags: c_uint,
+ },
+ .dragonfly, .freebsd, .kfreebsd => 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,
+ },
+ /// see signal options
+ flags: c_uint,
+ /// signal mask to apply
+ mask: sigset_t,
+ },
+ .solaris, .illumos => 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 options
+ flags: c_uint,
+ /// signal handler
+ handler: extern union {
+ handler: ?handler_fn,
+ sigaction: ?sigaction_fn,
+ },
+ /// signal mask to apply
+ mask: sigset_t,
+ },
+ .haiku => 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,
+ },
+ .openbsd => 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,
+ /// signal options
+ flags: c_uint,
+ },
+ else => void,
+};
+pub const T = switch (native_os) {
+ .linux => linux.T,
+ .macos, .ios, .tvos, .watchos, .visionos => struct {
+ pub const IOCGWINSZ = ior(0x40000000, 't', 104, @sizeOf(winsize));
+
+ fn ior(inout: u32, group: usize, num: usize, len: usize) usize {
+ return (inout | ((len & IOCPARM_MASK) << 16) | ((group) << 8) | (num));
+ }
+ },
+ .freebsd, .kfreebsd => struct {
+ pub const IOCEXCL = 0x2000740d;
+ pub const IOCNXCL = 0x2000740e;
+ pub const IOCSCTTY = 0x20007461;
+ pub const IOCGPGRP = 0x40047477;
+ pub const IOCSPGRP = 0x80047476;
+ pub const IOCOUTQ = 0x40047473;
+ pub const IOCSTI = 0x80017472;
+ pub const IOCGWINSZ = 0x40087468;
+ pub const IOCSWINSZ = 0x80087467;
+ pub const IOCMGET = 0x4004746a;
+ pub const IOCMBIS = 0x8004746c;
+ pub const IOCMBIC = 0x8004746b;
+ pub const IOCMSET = 0x8004746d;
+ pub const FIONREAD = 0x4004667f;
+ pub const IOCCONS = 0x80047462;
+ pub const IOCPKT = 0x80047470;
+ pub const FIONBIO = 0x8004667e;
+ pub const IOCNOTTY = 0x20007471;
+ pub const IOCSETD = 0x8004741b;
+ pub const IOCGETD = 0x4004741a;
+ pub const IOCSBRK = 0x2000747b;
+ pub const IOCCBRK = 0x2000747a;
+ pub const IOCGSID = 0x40047463;
+ pub const IOCGPTN = 0x4004740f;
+ pub const IOCSIG = 0x2004745f;
+ },
+ .solaris, .illumos => struct {
+ pub const CGETA = tioc('T', 1);
+ pub const CSETA = tioc('T', 2);
+ pub const CSETAW = tioc('T', 3);
+ pub const CSETAF = tioc('T', 4);
+ pub const CSBRK = tioc('T', 5);
+ pub const CXONC = tioc('T', 6);
+ pub const CFLSH = tioc('T', 7);
+ pub const IOCGWINSZ = tioc('T', 104);
+ pub const IOCSWINSZ = tioc('T', 103);
+ // Softcarrier ioctls
+ pub const IOCGSOFTCAR = tioc('T', 105);
+ pub const IOCSSOFTCAR = tioc('T', 106);
+ // termios ioctls
+ pub const CGETS = tioc('T', 13);
+ pub const CSETS = tioc('T', 14);
+ pub const CSANOW = tioc('T', 14);
+ pub const CSETSW = tioc('T', 15);
+ pub const CSADRAIN = tioc('T', 15);
+ pub const CSETSF = tioc('T', 16);
+ pub const IOCSETLD = tioc('T', 123);
+ pub const IOCGETLD = tioc('T', 124);
+ // NTP PPS ioctls
+ pub const IOCGPPS = tioc('T', 125);
+ pub const IOCSPPS = tioc('T', 126);
+ pub const IOCGPPSEV = tioc('T', 127);
+
+ pub const IOCGETD = tioc('t', 0);
+ pub const IOCSETD = tioc('t', 1);
+ pub const IOCHPCL = tioc('t', 2);
+ pub const IOCGETP = tioc('t', 8);
+ pub const IOCSETP = tioc('t', 9);
+ pub const IOCSETN = tioc('t', 10);
+ pub const IOCEXCL = tioc('t', 13);
+ pub const IOCNXCL = tioc('t', 14);
+ pub const IOCFLUSH = tioc('t', 16);
+ pub const IOCSETC = tioc('t', 17);
+ pub const IOCGETC = tioc('t', 18);
+ /// bis local mode bits
+ pub const IOCLBIS = tioc('t', 127);
+ /// bic local mode bits
+ pub const IOCLBIC = tioc('t', 126);
+ /// set entire local mode word
+ pub const IOCLSET = tioc('t', 125);
+ /// get local modes
+ pub const IOCLGET = tioc('t', 124);
+ /// set break bit
+ pub const IOCSBRK = tioc('t', 123);
+ /// clear break bit
+ pub const IOCCBRK = tioc('t', 122);
+ /// set data terminal ready
+ pub const IOCSDTR = tioc('t', 121);
+ /// clear data terminal ready
+ pub const IOCCDTR = tioc('t', 120);
+ /// set local special chars
+ pub const IOCSLTC = tioc('t', 117);
+ /// get local special chars
+ pub const IOCGLTC = tioc('t', 116);
+ /// driver output queue size
+ pub const IOCOUTQ = tioc('t', 115);
+ /// void tty association
+ pub const IOCNOTTY = tioc('t', 113);
+ /// get a ctty
+ pub const IOCSCTTY = tioc('t', 132);
+ /// stop output, like ^S
+ pub const IOCSTOP = tioc('t', 111);
+ /// start output, like ^Q
+ pub const IOCSTART = tioc('t', 110);
+ /// get pgrp of tty
+ pub const IOCGPGRP = tioc('t', 20);
+ /// set pgrp of tty
+ pub const IOCSPGRP = tioc('t', 21);
+ /// get session id on ctty
+ pub const IOCGSID = tioc('t', 22);
+ /// simulate terminal input
+ pub const IOCSTI = tioc('t', 23);
+ /// set all modem bits
+ pub const IOCMSET = tioc('t', 26);
+ /// bis modem bits
+ pub const IOCMBIS = tioc('t', 27);
+ /// bic modem bits
+ pub const IOCMBIC = tioc('t', 28);
+ /// get all modem bits
+ pub const IOCMGET = tioc('t', 29);
+
+ fn tioc(t: u16, num: u8) u16 {
+ return (t << 8) | num;
+ }
+ },
+ .netbsd => struct {
+ pub const IOCCBRK = 0x2000747a;
+ pub const IOCCDTR = 0x20007478;
+ pub const IOCCONS = 0x80047462;
+ pub const IOCDCDTIMESTAMP = 0x40107458;
+ pub const IOCDRAIN = 0x2000745e;
+ pub const IOCEXCL = 0x2000740d;
+ pub const IOCEXT = 0x80047460;
+ pub const IOCFLAG_CDTRCTS = 0x10;
+ pub const IOCFLAG_CLOCAL = 0x2;
+ pub const IOCFLAG_CRTSCTS = 0x4;
+ pub const IOCFLAG_MDMBUF = 0x8;
+ pub const IOCFLAG_SOFTCAR = 0x1;
+ pub const IOCFLUSH = 0x80047410;
+ pub const IOCGETA = 0x402c7413;
+ pub const IOCGETD = 0x4004741a;
+ pub const IOCGFLAGS = 0x4004745d;
+ pub const IOCGLINED = 0x40207442;
+ pub const IOCGPGRP = 0x40047477;
+ pub const IOCGQSIZE = 0x40047481;
+ pub const IOCGRANTPT = 0x20007447;
+ pub const IOCGSID = 0x40047463;
+ pub const IOCGSIZE = 0x40087468;
+ pub const IOCGWINSZ = 0x40087468;
+ pub const IOCMBIC = 0x8004746b;
+ pub const IOCMBIS = 0x8004746c;
+ pub const IOCMGET = 0x4004746a;
+ pub const IOCMSET = 0x8004746d;
+ pub const IOCM_CAR = 0x40;
+ pub const IOCM_CD = 0x40;
+ pub const IOCM_CTS = 0x20;
+ pub const IOCM_DSR = 0x100;
+ pub const IOCM_DTR = 0x2;
+ pub const IOCM_LE = 0x1;
+ pub const IOCM_RI = 0x80;
+ pub const IOCM_RNG = 0x80;
+ pub const IOCM_RTS = 0x4;
+ pub const IOCM_SR = 0x10;
+ pub const IOCM_ST = 0x8;
+ pub const IOCNOTTY = 0x20007471;
+ pub const IOCNXCL = 0x2000740e;
+ pub const IOCOUTQ = 0x40047473;
+ pub const IOCPKT = 0x80047470;
+ pub const IOCPKT_DATA = 0x0;
+ pub const IOCPKT_DOSTOP = 0x20;
+ pub const IOCPKT_FLUSHREAD = 0x1;
+ pub const IOCPKT_FLUSHWRITE = 0x2;
+ pub const IOCPKT_IOCTL = 0x40;
+ pub const IOCPKT_NOSTOP = 0x10;
+ pub const IOCPKT_START = 0x8;
+ pub const IOCPKT_STOP = 0x4;
+ pub const IOCPTMGET = 0x40287446;
+ pub const IOCPTSNAME = 0x40287448;
+ pub const IOCRCVFRAME = 0x80087445;
+ pub const IOCREMOTE = 0x80047469;
+ pub const IOCSBRK = 0x2000747b;
+ pub const IOCSCTTY = 0x20007461;
+ pub const IOCSDTR = 0x20007479;
+ pub const IOCSETA = 0x802c7414;
+ pub const IOCSETAF = 0x802c7416;
+ pub const IOCSETAW = 0x802c7415;
+ pub const IOCSETD = 0x8004741b;
+ pub const IOCSFLAGS = 0x8004745c;
+ pub const IOCSIG = 0x2000745f;
+ pub const IOCSLINED = 0x80207443;
+ pub const IOCSPGRP = 0x80047476;
+ pub const IOCSQSIZE = 0x80047480;
+ pub const IOCSSIZE = 0x80087467;
+ pub const IOCSTART = 0x2000746e;
+ pub const IOCSTAT = 0x80047465;
+ pub const IOCSTI = 0x80017472;
+ pub const IOCSTOP = 0x2000746f;
+ pub const IOCSWINSZ = 0x80087467;
+ pub const IOCUCNTL = 0x80047466;
+ pub const IOCXMTFRAME = 0x80087444;
+ },
+ .haiku => 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;
+ },
+ .openbsd => struct {
+ pub const IOCCBRK = 0x2000747a;
+ pub const IOCCDTR = 0x20007478;
+ pub const IOCCONS = 0x80047462;
+ pub const IOCDCDTIMESTAMP = 0x40107458;
+ pub const IOCDRAIN = 0x2000745e;
+ pub const IOCEXCL = 0x2000740d;
+ pub const IOCEXT = 0x80047460;
+ pub const IOCFLAG_CDTRCTS = 0x10;
+ pub const IOCFLAG_CLOCAL = 0x2;
+ pub const IOCFLAG_CRTSCTS = 0x4;
+ pub const IOCFLAG_MDMBUF = 0x8;
+ pub const IOCFLAG_SOFTCAR = 0x1;
+ pub const IOCFLUSH = 0x80047410;
+ pub const IOCGETA = 0x402c7413;
+ pub const IOCGETD = 0x4004741a;
+ pub const IOCGFLAGS = 0x4004745d;
+ pub const IOCGLINED = 0x40207442;
+ pub const IOCGPGRP = 0x40047477;
+ pub const IOCGQSIZE = 0x40047481;
+ pub const IOCGRANTPT = 0x20007447;
+ pub const IOCGSID = 0x40047463;
+ pub const IOCGSIZE = 0x40087468;
+ pub const IOCGWINSZ = 0x40087468;
+ pub const IOCMBIC = 0x8004746b;
+ pub const IOCMBIS = 0x8004746c;
+ pub const IOCMGET = 0x4004746a;
+ pub const IOCMSET = 0x8004746d;
+ pub const IOCM_CAR = 0x40;
+ pub const IOCM_CD = 0x40;
+ pub const IOCM_CTS = 0x20;
+ pub const IOCM_DSR = 0x100;
+ pub const IOCM_DTR = 0x2;
+ pub const IOCM_LE = 0x1;
+ pub const IOCM_RI = 0x80;
+ pub const IOCM_RNG = 0x80;
+ pub const IOCM_RTS = 0x4;
+ pub const IOCM_SR = 0x10;
+ pub const IOCM_ST = 0x8;
+ pub const IOCNOTTY = 0x20007471;
+ pub const IOCNXCL = 0x2000740e;
+ pub const IOCOUTQ = 0x40047473;
+ pub const IOCPKT = 0x80047470;
+ pub const IOCPKT_DATA = 0x0;
+ pub const IOCPKT_DOSTOP = 0x20;
+ pub const IOCPKT_FLUSHREAD = 0x1;
+ pub const IOCPKT_FLUSHWRITE = 0x2;
+ pub const IOCPKT_IOCTL = 0x40;
+ pub const IOCPKT_NOSTOP = 0x10;
+ pub const IOCPKT_START = 0x8;
+ pub const IOCPKT_STOP = 0x4;
+ pub const IOCPTMGET = 0x40287446;
+ pub const IOCPTSNAME = 0x40287448;
+ pub const IOCRCVFRAME = 0x80087445;
+ pub const IOCREMOTE = 0x80047469;
+ pub const IOCSBRK = 0x2000747b;
+ pub const IOCSCTTY = 0x20007461;
+ pub const IOCSDTR = 0x20007479;
+ pub const IOCSETA = 0x802c7414;
+ pub const IOCSETAF = 0x802c7416;
+ pub const IOCSETAW = 0x802c7415;
+ pub const IOCSETD = 0x8004741b;
+ pub const IOCSFLAGS = 0x8004745c;
+ pub const IOCSIG = 0x2000745f;
+ pub const IOCSLINED = 0x80207443;
+ pub const IOCSPGRP = 0x80047476;
+ pub const IOCSQSIZE = 0x80047480;
+ pub const IOCSSIZE = 0x80087467;
+ pub const IOCSTART = 0x2000746e;
+ pub const IOCSTAT = 0x80047465;
+ pub const IOCSTI = 0x80017472;
+ pub const IOCSTOP = 0x2000746f;
+ pub const IOCSWINSZ = 0x80087467;
+ pub const IOCUCNTL = 0x80047466;
+ pub const IOCXMTFRAME = 0x80087444;
+ },
+ else => void,
+};
+pub const IOCPARM_MASK = switch (native_os) {
+ .windows => ws2_32.IOCPARM_MASK,
+ .macos, .ios, .tvos, .watchos, .visionos => 0x1fff,
+ else => void,
+};
+pub const TCSA = std.posix.TCSA;
+pub const TFD = switch (native_os) {
+ .linux => linux.TFD,
+ else => void,
+};
+pub const VDSO = switch (native_os) {
+ .linux => linux.VDSO,
+ else => void,
+};
+pub const W = switch (native_os) {
+ .linux => linux.W,
+ .emscripten => emscripten.W,
+ .macos, .ios, .tvos, .watchos, .visionos => struct {
+ /// [XSI] no hang in wait/no child to reap
+ pub const NOHANG = 0x00000001;
+ /// [XSI] notify on stop, untraced child
+ pub const UNTRACED = 0x00000002;
+
+ pub fn EXITSTATUS(x: u32) u8 {
+ return @as(u8, @intCast(x >> 8));
+ }
+ pub fn TERMSIG(x: u32) u32 {
+ return status(x);
+ }
+ pub fn STOPSIG(x: u32) u32 {
+ return x >> 8;
+ }
+ pub fn IFEXITED(x: u32) bool {
+ return status(x) == 0;
+ }
+ pub fn IFSTOPPED(x: u32) bool {
+ return status(x) == stopped and STOPSIG(x) != 0x13;
+ }
+ pub fn IFSIGNALED(x: u32) bool {
+ return status(x) != stopped and status(x) != 0;
+ }
+
+ fn status(x: u32) u32 {
+ return x & 0o177;
+ }
+ const stopped = 0o177;
+ },
+ .freebsd, .kfreebsd => struct {
+ pub const NOHANG = 1;
+ pub const UNTRACED = 2;
+ pub const STOPPED = UNTRACED;
+ pub const CONTINUED = 4;
+ pub const NOWAIT = 8;
+ pub const EXITED = 16;
+ pub const TRAPPED = 32;
+
+ pub fn EXITSTATUS(s: u32) u8 {
+ return @as(u8, @intCast((s & 0xff00) >> 8));
+ }
+ pub fn TERMSIG(s: u32) u32 {
+ return s & 0x7f;
+ }
+ pub fn STOPSIG(s: u32) u32 {
+ return EXITSTATUS(s);
+ }
+ pub fn IFEXITED(s: u32) bool {
+ return TERMSIG(s) == 0;
+ }
+ pub fn IFSTOPPED(s: u32) bool {
+ return @as(u16, @truncate((((s & 0xffff) *% 0x10001) >> 8))) > 0x7f00;
+ }
+ pub fn IFSIGNALED(s: u32) bool {
+ return (s & 0xffff) -% 1 < 0xff;
+ }
+ },
+ .solaris, .illumos => struct {
+ pub const EXITED = 0o001;
+ pub const TRAPPED = 0o002;
+ pub const UNTRACED = 0o004;
+ pub const STOPPED = UNTRACED;
+ pub const CONTINUED = 0o010;
+ pub const NOHANG = 0o100;
+ pub const NOWAIT = 0o200;
+
+ pub fn EXITSTATUS(s: u32) u8 {
+ return @as(u8, @intCast((s >> 8) & 0xff));
+ }
+ pub fn TERMSIG(s: u32) u32 {
+ return s & 0x7f;
+ }
+ pub fn STOPSIG(s: u32) u32 {
+ return EXITSTATUS(s);
+ }
+ pub fn IFEXITED(s: u32) bool {
+ return TERMSIG(s) == 0;
+ }
+
+ pub fn IFCONTINUED(s: u32) bool {
+ return ((s & 0o177777) == 0o177777);
+ }
+
+ pub fn IFSTOPPED(s: u32) bool {
+ return (s & 0x00ff != 0o177) and !(s & 0xff00 != 0);
+ }
+
+ pub fn IFSIGNALED(s: u32) bool {
+ return s & 0x00ff > 0 and s & 0xff00 == 0;
+ }
+ },
+ .netbsd => struct {
+ pub const NOHANG = 0x00000001;
+ pub const UNTRACED = 0x00000002;
+ pub const STOPPED = UNTRACED;
+ pub const CONTINUED = 0x00000010;
+ pub const NOWAIT = 0x00010000;
+ pub const EXITED = 0x00000020;
+ pub const TRAPPED = 0x00000040;
+
+ pub fn EXITSTATUS(s: u32) u8 {
+ return @as(u8, @intCast((s >> 8) & 0xff));
+ }
+ pub fn TERMSIG(s: u32) u32 {
+ return s & 0x7f;
+ }
+ pub fn STOPSIG(s: u32) u32 {
+ return EXITSTATUS(s);
+ }
+ pub fn IFEXITED(s: u32) bool {
+ return TERMSIG(s) == 0;
+ }
+
+ pub fn IFCONTINUED(s: u32) bool {
+ return ((s & 0x7f) == 0xffff);
+ }
+
+ pub fn IFSTOPPED(s: u32) bool {
+ return ((s & 0x7f != 0x7f) and !IFCONTINUED(s));
+ }
+
+ pub fn IFSIGNALED(s: u32) bool {
+ return !IFSTOPPED(s) and !IFCONTINUED(s) and !IFEXITED(s);
+ }
+ },
+ .dragonfly => struct {
+ pub const NOHANG = 0x0001;
+ pub const UNTRACED = 0x0002;
+ pub const CONTINUED = 0x0004;
+ pub const STOPPED = UNTRACED;
+ pub const NOWAIT = 0x0008;
+ pub const EXITED = 0x0010;
+ pub const TRAPPED = 0x0020;
+
+ pub fn EXITSTATUS(s: u32) u8 {
+ return @as(u8, @intCast((s & 0xff00) >> 8));
+ }
+ pub fn TERMSIG(s: u32) u32 {
+ return s & 0x7f;
+ }
+ pub fn STOPSIG(s: u32) u32 {
+ return EXITSTATUS(s);
+ }
+ pub fn IFEXITED(s: u32) bool {
+ return TERMSIG(s) == 0;
+ }
+ pub fn IFSTOPPED(s: u32) bool {
+ return @as(u16, @truncate((((s & 0xffff) *% 0x10001) >> 8))) > 0x7f00;
+ }
+ pub fn IFSIGNALED(s: u32) bool {
+ return (s & 0xffff) -% 1 < 0xff;
+ }
+ },
+ .haiku => 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;
+ }
+ },
+ .openbsd => struct {
+ pub const NOHANG = 1;
+ pub const UNTRACED = 2;
+ pub const CONTINUED = 8;
+
+ pub fn EXITSTATUS(s: u32) u8 {
+ return @as(u8, @intCast((s >> 8) & 0xff));
+ }
+ pub fn TERMSIG(s: u32) u32 {
+ return (s & 0x7f);
+ }
+ pub fn STOPSIG(s: u32) u32 {
+ return EXITSTATUS(s);
+ }
+ pub fn IFEXITED(s: u32) bool {
+ return TERMSIG(s) == 0;
+ }
+
+ pub fn IFCONTINUED(s: u32) bool {
+ return ((s & 0o177777) == 0o177777);
+ }
+
+ pub fn IFSTOPPED(s: u32) bool {
+ return (s & 0xff == 0o177);
+ }
+
+ pub fn IFSIGNALED(s: u32) bool {
+ return (((s) & 0o177) != 0o177) and (((s) & 0o177) != 0);
+ }
+ },
+ else => void,
+};
+pub const clock_t = switch (native_os) {
+ .linux => linux.clock_t,
+ .emscripten => emscripten.clock_t,
+ .macos, .ios, .tvos, .watchos, .visionos => c_ulong,
+ .freebsd, .kfreebsd => isize,
+ .openbsd, .solaris, .illumos => i64,
+ .netbsd => u32,
+ .haiku => i32,
+ else => void,
+};
+pub const cpu_set_t = switch (native_os) {
+ .linux => linux.cpu_set_t,
+ .emscripten => emscripten.cpu_set_t,
+ else => void,
+};
+pub const dl_phdr_info = switch (native_os) {
+ .linux => linux.dl_phdr_info,
+ .emscripten => emscripten.dl_phdr_info,
+ .freebsd, .kfreebsd => extern struct {
+ /// Module relocation base.
+ addr: if (builtin.target.ptrBitWidth() == 32) std.elf.Elf32_Addr else std.elf.Elf64_Addr,
+ /// Module name.
+ name: ?[*:0]const u8,
+ /// Pointer to module's phdr.
+ phdr: [*]std.elf.Phdr,
+ /// Number of entries in phdr.
+ phnum: u16,
+ /// Total number of loads.
+ adds: u64,
+ /// Total number of unloads.
+ subs: u64,
+ tls_modid: usize,
+ tls_data: ?*anyopaque,
+ },
+ .solaris, .illumos => extern struct {
+ addr: std.elf.Addr,
+ name: ?[*:0]const u8,
+ phdr: [*]std.elf.Phdr,
+ phnum: std.elf.Half,
+ /// Incremented when a new object is mapped into the process.
+ adds: u64,
+ /// Incremented when an object is unmapped from the process.
+ subs: u64,
+ },
+ .openbsd, .haiku, .dragonfly, .netbsd => extern struct {
+ addr: usize,
+ name: ?[*:0]const u8,
+ phdr: [*]std.elf.Phdr,
+ phnum: u16,
+ },
+ else => void,
+};
+pub const epoll_event = switch (native_os) {
+ .linux => linux.epoll_event,
+ else => void,
+};
+pub const ifreq = switch (native_os) {
+ .linux => linux.ifreq,
+ .emscripten => emscripten.ifreq,
+ .solaris, .illumos => lifreq,
+ else => void,
+};
+pub const itimerspec = switch (native_os) {
+ .linux => linux.itimerspec,
+ .haiku => extern struct {
+ interval: timespec,
+ value: timespec,
+ },
+ else => void,
+};
+pub const msghdr = switch (native_os) {
+ .linux => linux.msghdr,
+ .openbsd, .emscripten, .dragonfly, .freebsd, .kfreebsd, .netbsd, .haiku, .solaris, .illumos => extern struct {
+ /// optional address
+ name: ?*sockaddr,
+ /// size of address
+ namelen: socklen_t,
+ /// scatter/gather array
+ iov: [*]iovec,
+ /// # elements in iov
+ iovlen: i32,
+ /// ancillary data
+ control: ?*anyopaque,
+ /// ancillary data buffer len
+ controllen: socklen_t,
+ /// flags on received message
+ flags: i32,
+ },
+ else => void,
+};
+pub const msghdr_const = switch (native_os) {
+ .linux => linux.msghdr_const,
+ .openbsd, .emscripten, .dragonfly, .freebsd, .kfreebsd, .netbsd, .haiku, .solaris, .illumos => extern struct {
+ /// optional address
+ name: ?*const sockaddr,
+ /// size of address
+ namelen: socklen_t,
+ /// scatter/gather array
+ iov: [*]const iovec_const,
+ /// # elements in iov
+ iovlen: i32,
+ /// ancillary data
+ control: ?*const anyopaque,
+ /// ancillary data buffer len
+ controllen: socklen_t,
+ /// flags on received message
+ flags: i32,
+ },
+ else => void,
+};
+pub const nfds_t = switch (native_os) {
+ .linux => linux.nfds_t,
+ .emscripten => emscripten.nfds_t,
+ .haiku, .solaris, .illumos, .wasi => usize,
+ .windows => c_ulong,
+ .openbsd, .dragonfly, .netbsd, .freebsd, .kfreebsd, .macos, .ios, .tvos, .watchos, .visionos => u32,
+ else => void,
+};
+pub const perf_event_attr = switch (native_os) {
+ .linux => linux.perf_event_attr,
+ else => void,
+};
+pub const pid_t = switch (native_os) {
+ .linux => linux.pid_t,
+ .emscripten => emscripten.pid_t,
+ .windows => windows.HANDLE,
+ else => i32,
+};
+pub const pollfd = switch (native_os) {
+ .linux => linux.pollfd,
+ .emscripten => emscripten.pollfd,
+ .windows => ws2_32.pollfd,
+ else => extern struct {
+ fd: fd_t,
+ events: i16,
+ revents: i16,
+ },
+};
+pub const rlim_t = switch (native_os) {
+ .linux => linux.rlim_t,
+ .emscripten => emscripten.rlim_t,
+ .openbsd, .netbsd, .solaris, .illumos, .macos, .ios, .tvos, .watchos, .visionos => u64,
+ .haiku, .dragonfly, .freebsd, .kfreebsd => i64,
+ else => void,
+};
+pub const rlimit = switch (native_os) {
+ .linux, .emscripten => linux.rlimit,
+ .windows => void,
+ else => extern struct {
+ /// Soft limit
+ cur: rlim_t,
+ /// Hard limit
+ max: rlim_t,
+ },
+};
+pub const rlimit_resource = switch (native_os) {
+ .linux => linux.rlimit_resource,
+ .emscripten => emscripten.rlimit_resource,
+ .openbsd, .macos, .ios, .tvos, .watchos, .visionos => enum(c_int) {
+ CPU = 0,
+ FSIZE = 1,
+ DATA = 2,
+ STACK = 3,
+ CORE = 4,
+ RSS = 5,
+ MEMLOCK = 6,
+ NPROC = 7,
+ NOFILE = 8,
+ _,
+
+ pub const AS: rlimit_resource = .RSS;
+ },
+ .freebsd, .kfreebsd => enum(c_int) {
+ CPU = 0,
+ FSIZE = 1,
+ DATA = 2,
+ STACK = 3,
+ CORE = 4,
+ RSS = 5,
+ MEMLOCK = 6,
+ NPROC = 7,
+ NOFILE = 8,
+ SBSIZE = 9,
+ VMEM = 10,
+ NPTS = 11,
+ SWAP = 12,
+ KQUEUES = 13,
+ UMTXP = 14,
+ _,
+
+ pub const AS: rlimit_resource = .VMEM;
+ },
+ .solaris, .illumos => enum(c_int) {
+ CPU = 0,
+ FSIZE = 1,
+ DATA = 2,
+ STACK = 3,
+ CORE = 4,
+ NOFILE = 5,
+ VMEM = 6,
+ _,
+
+ pub const AS: rlimit_resource = .VMEM;
+ },
+ .netbsd => enum(c_int) {
+ CPU = 0,
+ FSIZE = 1,
+ DATA = 2,
+ STACK = 3,
+ CORE = 4,
+ RSS = 5,
+ MEMLOCK = 6,
+ NPROC = 7,
+ NOFILE = 8,
+ SBSIZE = 9,
+ VMEM = 10,
+ NTHR = 11,
+ _,
+
+ pub const AS: rlimit_resource = .VMEM;
+ },
+ .dragonfly => enum(c_int) {
+ CPU = 0,
+ FSIZE = 1,
+ DATA = 2,
+ STACK = 3,
+ CORE = 4,
+ RSS = 5,
+ MEMLOCK = 6,
+ NPROC = 7,
+ NOFILE = 8,
+ SBSIZE = 9,
+ VMEM = 10,
+ POSIXLOCKS = 11,
+ _,
+
+ pub const AS: rlimit_resource = .VMEM;
+ },
+ .haiku => enum(i32) {
+ CORE = 0,
+ CPU = 1,
+ DATA = 2,
+ FSIZE = 3,
+ NOFILE = 4,
+ STACK = 5,
+ AS = 6,
+ NOVMON = 7,
+ _,
+ },
+ else => void,
+};
+pub const rusage = switch (native_os) {
+ .linux => linux.rusage,
+ .emscripten => emscripten.rusage,
+ .macos, .ios, .tvos, .watchos, .visionos => extern struct {
+ utime: timeval,
+ stime: timeval,
+ maxrss: isize,
+ ixrss: isize,
+ idrss: isize,
+ isrss: isize,
+ minflt: isize,
+ majflt: isize,
+ nswap: isize,
+ inblock: isize,
+ oublock: isize,
+ msgsnd: isize,
+ msgrcv: isize,
+ nsignals: isize,
+ nvcsw: isize,
+ nivcsw: isize,
+
+ pub const SELF = 0;
+ pub const CHILDREN = -1;
+ },
+ .solaris, .illumos => extern struct {
+ utime: timeval,
+ stime: timeval,
+ maxrss: isize,
+ ixrss: isize,
+ idrss: isize,
+ isrss: isize,
+ minflt: isize,
+ majflt: isize,
+ nswap: isize,
+ inblock: isize,
+ oublock: isize,
+ msgsnd: isize,
+ msgrcv: isize,
+ nsignals: isize,
+ nvcsw: isize,
+ nivcsw: isize,
+
+ pub const SELF = 0;
+ pub const CHILDREN = -1;
+ pub const THREAD = 1;
+ },
+ else => void,
+};
+
+pub const siginfo_t = switch (native_os) {
+ .linux => linux.siginfo_t,
+ .emscripten => emscripten.siginfo_t,
+ .macos, .ios, .tvos, .watchos, .visionos => extern struct {
+ signo: c_int,
+ errno: c_int,
+ code: c_int,
+ pid: pid_t,
+ uid: uid_t,
+ status: c_int,
+ addr: *allowzero anyopaque,
+ value: extern union {
+ int: c_int,
+ ptr: *anyopaque,
+ },
+ si_band: c_long,
+ _pad: [7]c_ulong,
+ },
+ .freebsd, .kfreebsd => extern struct {
+ // Signal number.
+ signo: c_int,
+ // Errno association.
+ errno: c_int,
+ /// Signal code.
+ ///
+ /// Cause of signal, one of the SI_ macros or signal-specific values, i.e.
+ /// one of the FPE_... values for SIGFPE.
+ /// This value is equivalent to the second argument to an old-style FreeBSD
+ /// signal handler.
+ code: c_int,
+ /// Sending process.
+ pid: pid_t,
+ /// Sender's ruid.
+ uid: uid_t,
+ /// Exit value.
+ status: c_int,
+ /// Faulting instruction.
+ addr: *allowzero anyopaque,
+ /// Signal value.
+ value: sigval,
+ reason: extern union {
+ fault: extern struct {
+ /// Machine specific trap code.
+ trapno: c_int,
+ },
+ timer: extern struct {
+ timerid: c_int,
+ overrun: c_int,
+ },
+ mesgq: extern struct {
+ mqd: c_int,
+ },
+ poll: extern struct {
+ /// Band event for SIGPOLL. UNUSED.
+ band: c_long,
+ },
+ spare: extern struct {
+ spare1: c_long,
+ spare2: [7]c_int,
+ },
+ },
+ },
+ .solaris, .illumos => extern struct {
+ signo: c_int,
+ code: c_int,
+ errno: c_int,
+ // 64bit architectures insert 4bytes of padding here, this is done by
+ // correctly aligning the reason field
+ reason: extern union {
+ proc: extern struct {
+ pid: pid_t,
+ pdata: extern union {
+ kill: extern struct {
+ uid: uid_t,
+ value: sigval_t,
+ },
+ cld: extern struct {
+ utime: clock_t,
+ status: c_int,
+ stime: clock_t,
+ },
+ },
+ contract: solaris.ctid_t,
+ zone: solaris.zoneid_t,
+ },
+ fault: extern struct {
+ addr: *allowzero anyopaque,
+ trapno: c_int,
+ pc: ?*anyopaque,
+ },
+ file: extern struct {
+ // fd not currently available for SIGPOLL.
+ fd: c_int,
+ band: c_long,
+ },
+ prof: extern struct {
+ addr: ?*anyopaque,
+ timestamp: timespec,
+ syscall: c_short,
+ sysarg: u8,
+ fault: u8,
+ args: [8]c_long,
+ state: [10]c_int,
+ },
+ rctl: extern struct {
+ entity: i32,
+ },
+ __pad: [256 - 4 * @sizeOf(c_int)]u8,
+ } align(@sizeOf(usize)),
+
+ comptime {
+ assert(@sizeOf(@This()) == 256);
+ assert(@alignOf(@This()) == @sizeOf(usize));
+ }
+ },
+ .netbsd => extern union {
+ pad: [128]u8,
+ info: netbsd._ksiginfo,
+ },
+ .dragonfly => extern struct {
+ signo: c_int,
+ errno: c_int,
+ code: c_int,
+ pid: c_int,
+ uid: uid_t,
+ status: c_int,
+ addr: *allowzero anyopaque,
+ value: sigval,
+ band: c_long,
+ __spare__: [7]c_int,
+ },
+ .haiku => extern struct {
+ signo: i32,
+ code: i32,
+ errno: i32,
+
+ pid: pid_t,
+ uid: uid_t,
+ addr: *allowzero anyopaque,
+ },
+ .openbsd => extern struct {
+ signo: c_int,
+ code: c_int,
+ errno: c_int,
+ data: extern union {
+ proc: extern struct {
+ pid: pid_t,
+ pdata: extern union {
+ kill: extern struct {
+ uid: uid_t,
+ value: sigval,
+ },
+ cld: extern struct {
+ utime: clock_t,
+ stime: clock_t,
+ status: c_int,
+ },
+ },
+ },
+ fault: extern struct {
+ addr: *allowzero anyopaque,
+ trapno: c_int,
+ },
+ __pad: [128 - 3 * @sizeOf(c_int)]u8,
+ },
+
+ comptime {
+ if (@sizeOf(usize) == 4)
+ assert(@sizeOf(@This()) == 128)
+ else
+ // Take into account the padding between errno and data fields.
+ assert(@sizeOf(@This()) == 136);
+ }
+ },
+ else => void,
+};
+pub const sigset_t = switch (native_os) {
+ .linux => linux.sigset_t,
+ .emscripten => emscripten.sigset_t,
+ .openbsd, .macos, .ios, .tvos, .watchos, .visionos => u32,
+ .dragonfly, .netbsd, .solaris, .illumos, .freebsd, .kfreebsd => extern struct {
+ __bits: [SIG.WORDS]u32,
+ },
+ .haiku => u64,
+ else => u0,
+};
+pub const empty_sigset: sigset_t = switch (native_os) {
+ .linux => linux.empty_sigset,
+ .emscripten => emscripten.empty_sigset,
+ .dragonfly, .netbsd, .solaris, .illumos, .freebsd, .kfreebsd => .{ .__bits = [_]u32{0} ** SIG.WORDS },
+ else => 0,
+};
+pub const filled_sigset = switch (native_os) {
+ .linux => linux.filled_sigset,
+ .haiku => ~@as(sigset_t, 0),
+ else => 0,
+};
+pub const sigval = switch (native_os) {
+ .linux => linux.sigval,
+ .openbsd, .dragonfly, .freebsd, .kfreebsd => extern union {
+ int: c_int,
+ ptr: ?*anyopaque,
+ },
+ else => void,
+};
+
+pub const addrinfo = switch (native_os) {
+ .linux, .emscripten => linux.addrinfo,
+ .windows => ws2_32.addrinfo,
+ .freebsd, .kfreebsd, .macos, .ios, .tvos, .watchos, .visionos => extern struct {
+ flags: AI,
+ family: i32,
+ socktype: i32,
+ protocol: i32,
+ addrlen: socklen_t,
+ canonname: ?[*:0]u8,
+ addr: ?*sockaddr,
+ next: ?*addrinfo,
+ },
+ .solaris, .illumos => extern struct {
+ flags: AI,
+ family: i32,
+ socktype: i32,
+ protocol: i32,
+ addrlen: socklen_t,
+ canonname: ?[*:0]u8,
+ addr: ?*sockaddr,
+ next: ?*addrinfo,
+ },
+ .netbsd => extern struct {
+ flags: AI,
+ family: i32,
+ socktype: i32,
+ protocol: i32,
+ addrlen: socklen_t,
+ canonname: ?[*:0]u8,
+ addr: ?*sockaddr,
+ next: ?*addrinfo,
+ },
+ .dragonfly => extern struct {
+ flags: AI,
+ family: i32,
+ socktype: i32,
+ protocol: i32,
+ addrlen: socklen_t,
+ canonname: ?[*:0]u8,
+ addr: ?*sockaddr,
+ next: ?*addrinfo,
+ },
+ .haiku => extern struct {
+ flags: AI,
+ family: i32,
+ socktype: i32,
+ protocol: i32,
+ addrlen: socklen_t,
+ canonname: ?[*:0]u8,
+ addr: ?*sockaddr,
+ next: ?*addrinfo,
+ },
+ .openbsd => extern struct {
+ flags: AI,
+ family: c_int,
+ socktype: c_int,
+ protocol: c_int,
+ addrlen: socklen_t,
+ addr: ?*sockaddr,
+ canonname: ?[*:0]u8,
+ next: ?*addrinfo,
+ },
+ else => void,
+};
+pub const sockaddr = switch (native_os) {
+ .linux, .emscripten => linux.sockaddr,
+ .windows => ws2_32.sockaddr,
+ .macos, .ios, .tvos, .watchos, .visionos => extern struct {
+ len: u8,
+ family: sa_family_t,
+ 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,
+ };
+
+ /// UNIX domain socket
+ pub const un = extern struct {
+ len: u8 = @sizeOf(un),
+ family: sa_family_t = AF.UNIX,
+ path: [104]u8,
+ };
+ },
+ .freebsd, .kfreebsd => 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,
+ };
+ },
+ .solaris, .illumos => extern struct {
+ /// address family
+ family: sa_family_t,
+
+ /// actually longer; address value
+ data: [14]u8,
+
+ pub const SS_MAXSIZE = 256;
+ pub const storage = extern struct {
+ family: sa_family_t align(8),
+ padding: [254]u8 = undefined,
+
+ comptime {
+ assert(@sizeOf(storage) == SS_MAXSIZE);
+ assert(@alignOf(storage) == 8);
+ }
+ };
+
+ 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 },
+ };
+
+ pub const in6 = extern struct {
+ family: sa_family_t = AF.INET6,
+ port: in_port_t,
+ flowinfo: u32,
+ addr: [16]u8,
+ scope_id: u32,
+ __src_id: u32 = 0,
+ };
+
+ /// Definitions for UNIX IPC domain.
+ pub const un = extern struct {
+ family: sa_family_t = AF.UNIX,
+ path: [108]u8,
+ };
+ },
+ .netbsd => 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,
+ };
+
+ /// Definitions for UNIX IPC domain.
+ pub const un = extern struct {
+ /// total sockaddr length
+ len: u8 = @sizeOf(un),
+
+ family: sa_family_t = AF.LOCAL,
+
+ /// path name
+ path: [104]u8,
+ };
+ },
+ .dragonfly => extern struct {
+ len: u8,
+ family: sa_family_t,
+ 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,
+ };
+ },
+ .haiku => 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,
+ };
+ },
+ .openbsd => extern struct {
+ /// total length
+ len: u8,
+ /// address family
+ family: sa_family_t,
+ /// actually longer; address value
+ data: [14]u8,
+
+ pub const SS_MAXSIZE = 256;
+ pub const storage = extern struct {
+ len: u8 align(8),
+ family: sa_family_t,
+ padding: [254]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,
+ };
+
+ /// Definitions for UNIX IPC domain.
+ pub const un = extern struct {
+ /// total sockaddr length
+ len: u8 = @sizeOf(un),
+
+ family: sa_family_t = AF.LOCAL,
+
+ /// path name
+ path: [104]u8,
+ };
+ },
+ else => void,
+};
+pub const socklen_t = switch (native_os) {
+ .linux, .emscripten => linux.socklen_t,
+ .windows => ws2_32.socklen_t,
+ else => u32,
+};
+pub const in_port_t = u16;
+pub const sa_family_t = switch (native_os) {
+ .linux, .emscripten => linux.sa_family_t,
+ .windows => ws2_32.ADDRESS_FAMILY,
+ .openbsd, .haiku, .dragonfly, .netbsd, .freebsd, .kfreebsd, .macos, .ios, .tvos, .watchos, .visionos => u8,
+ .solaris, .illumos => u16,
+ else => void,
+};
+pub const AF = switch (native_os) {
+ .linux, .emscripten => linux.AF,
+ .windows => ws2_32.AF,
+ .macos, .ios, .tvos, .watchos, .visionos => struct {
+ pub const UNSPEC = 0;
+ pub const LOCAL = 1;
+ pub const UNIX = LOCAL;
+ pub const INET = 2;
+ pub const SYS_CONTROL = 2;
+ pub const IMPLINK = 3;
+ pub const PUP = 4;
+ pub const CHAOS = 5;
+ pub const NS = 6;
+ pub const ISO = 7;
+ pub const OSI = ISO;
+ pub const ECMA = 8;
+ pub const DATAKIT = 9;
+ pub const CCITT = 10;
+ pub const SNA = 11;
+ pub const DECnet = 12;
+ pub const DLI = 13;
+ pub const LAT = 14;
+ pub const HYLINK = 15;
+ pub const APPLETALK = 16;
+ pub const ROUTE = 17;
+ pub const LINK = 18;
+ pub const XTP = 19;
+ pub const COIP = 20;
+ pub const CNT = 21;
+ pub const RTIP = 22;
+ pub const IPX = 23;
+ pub const SIP = 24;
+ pub const PIP = 25;
+ pub const ISDN = 28;
+ pub const E164 = ISDN;
+ pub const KEY = 29;
+ pub const INET6 = 30;
+ pub const NATM = 31;
+ pub const SYSTEM = 32;
+ pub const NETBIOS = 33;
+ pub const PPP = 34;
+ pub const MAX = 40;
+ },
+ .freebsd, .kfreebsd => struct {
+ pub const UNSPEC = 0;
+ pub const UNIX = 1;
+ pub const LOCAL = UNIX;
+ pub const FILE = LOCAL;
+ pub const INET = 2;
+ pub const IMPLINK = 3;
+ pub const PUP = 4;
+ pub const CHAOS = 5;
+ pub const NETBIOS = 6;
+ pub const ISO = 7;
+ pub const OSI = ISO;
+ pub const ECMA = 8;
+ pub const DATAKIT = 9;
+ pub const CCITT = 10;
+ pub const SNA = 11;
+ pub const DECnet = 12;
+ pub const DLI = 13;
+ pub const LAT = 14;
+ pub const HYLINK = 15;
+ pub const APPLETALK = 16;
+ pub const ROUTE = 17;
+ pub const LINK = 18;
+ pub const pseudo_XTP = 19;
+ pub const COIP = 20;
+ pub const CNT = 21;
+ pub const pseudo_RTIP = 22;
+ pub const IPX = 23;
+ pub const SIP = 24;
+ pub const pseudo_PIP = 25;
+ pub const ISDN = 26;
+ pub const E164 = ISDN;
+ pub const pseudo_KEY = 27;
+ pub const INET6 = 28;
+ pub const NATM = 29;
+ pub const ATM = 30;
+ pub const pseudo_HDRCMPLT = 31;
+ pub const NETGRAPH = 32;
+ pub const SLOW = 33;
+ pub const SCLUSTER = 34;
+ pub const ARP = 35;
+ pub const BLUETOOTH = 36;
+ pub const IEEE80211 = 37;
+ pub const INET_SDP = 40;
+ pub const INET6_SDP = 42;
+ pub const MAX = 42;
+ },
+ .solaris, .illumos => struct {
+ pub const UNSPEC = 0;
+ pub const UNIX = 1;
+ pub const LOCAL = UNIX;
+ pub const FILE = UNIX;
+ pub const INET = 2;
+ pub const IMPLINK = 3;
+ pub const PUP = 4;
+ pub const CHAOS = 5;
+ pub const NS = 6;
+ pub const NBS = 7;
+ pub const ECMA = 8;
+ pub const DATAKIT = 9;
+ pub const CCITT = 10;
+ pub const SNA = 11;
+ pub const DECnet = 12;
+ pub const DLI = 13;
+ pub const LAT = 14;
+ pub const HYLINK = 15;
+ pub const APPLETALK = 16;
+ pub const NIT = 17;
+ pub const @"802" = 18;
+ pub const OSI = 19;
+ pub const X25 = 20;
+ pub const OSINET = 21;
+ pub const GOSIP = 22;
+ pub const IPX = 23;
+ pub const ROUTE = 24;
+ pub const LINK = 25;
+ pub const INET6 = 26;
+ pub const KEY = 27;
+ pub const NCA = 28;
+ pub const POLICY = 29;
+ pub const INET_OFFLOAD = 30;
+ pub const TRILL = 31;
+ pub const PACKET = 32;
+ pub const LX_NETLINK = 33;
+ pub const MAX = 33;
+ },
+ .netbsd => struct {
+ pub const UNSPEC = 0;
+ pub const LOCAL = 1;
+ pub const UNIX = LOCAL;
+ pub const INET = 2;
+ pub const IMPLINK = 3;
+ pub const PUP = 4;
+ pub const CHAOS = 5;
+ pub const NS = 6;
+ pub const ISO = 7;
+ pub const OSI = ISO;
+ pub const ECMA = 8;
+ pub const DATAKIT = 9;
+ pub const CCITT = 10;
+ pub const SNA = 11;
+ pub const DECnet = 12;
+ pub const DLI = 13;
+ pub const LAT = 14;
+ pub const HYLINK = 15;
+ pub const APPLETALK = 16;
+ pub const OROUTE = 17;
+ pub const LINK = 18;
+ pub const COIP = 20;
+ pub const CNT = 21;
+ pub const IPX = 23;
+ pub const INET6 = 24;
+ pub const ISDN = 26;
+ pub const E164 = ISDN;
+ pub const NATM = 27;
+ pub const ARP = 28;
+ pub const BLUETOOTH = 31;
+ pub const IEEE80211 = 32;
+ pub const MPLS = 33;
+ pub const ROUTE = 34;
+ pub const CAN = 35;
+ pub const ETHER = 36;
+ pub const MAX = 37;
+ },
+ .dragonfly => struct {
+ pub const UNSPEC = 0;
+ pub const OSI = ISO;
+ pub const UNIX = LOCAL;
+ pub const LOCAL = 1;
+ pub const INET = 2;
+ pub const IMPLINK = 3;
+ pub const PUP = 4;
+ pub const CHAOS = 5;
+ pub const NETBIOS = 6;
+ pub const ISO = 7;
+ pub const ECMA = 8;
+ pub const DATAKIT = 9;
+ pub const CCITT = 10;
+ pub const SNA = 11;
+ pub const DLI = 13;
+ pub const LAT = 14;
+ pub const HYLINK = 15;
+ pub const APPLETALK = 16;
+ pub const ROUTE = 17;
+ pub const LINK = 18;
+ pub const COIP = 20;
+ pub const CNT = 21;
+ pub const IPX = 23;
+ pub const SIP = 24;
+ pub const ISDN = 26;
+ pub const INET6 = 28;
+ pub const NATM = 29;
+ pub const ATM = 30;
+ pub const NETGRAPH = 32;
+ pub const BLUETOOTH = 33;
+ pub const MPLS = 34;
+ pub const MAX = 36;
+ },
+ .haiku => 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;
+ },
+ .openbsd => struct {
+ pub const UNSPEC = 0;
+ pub const UNIX = 1;
+ pub const LOCAL = UNIX;
+ pub const INET = 2;
+ pub const APPLETALK = 16;
+ pub const INET6 = 24;
+ pub const KEY = 30;
+ pub const ROUTE = 17;
+ pub const SNA = 11;
+ pub const MPLS = 33;
+ pub const BLUETOOTH = 32;
+ pub const ISDN = 26;
+ pub const MAX = 36;
+ },
+ else => void,
+};
+pub const PF = switch (native_os) {
+ .linux, .emscripten => linux.PF,
+ .macos, .ios, .tvos, .watchos, .visionos => struct {
+ pub const UNSPEC = AF.UNSPEC;
+ pub const LOCAL = AF.LOCAL;
+ pub const UNIX = PF.LOCAL;
+ pub const INET = AF.INET;
+ pub const IMPLINK = AF.IMPLINK;
+ pub const PUP = AF.PUP;
+ pub const CHAOS = AF.CHAOS;
+ pub const NS = AF.NS;
+ pub const ISO = AF.ISO;
+ pub const OSI = AF.ISO;
+ pub const ECMA = AF.ECMA;
+ pub const DATAKIT = AF.DATAKIT;
+ pub const CCITT = AF.CCITT;
+ pub const SNA = AF.SNA;
+ pub const DECnet = AF.DECnet;
+ pub const DLI = AF.DLI;
+ pub const LAT = AF.LAT;
+ pub const HYLINK = AF.HYLINK;
+ pub const APPLETALK = AF.APPLETALK;
+ pub const ROUTE = AF.ROUTE;
+ pub const LINK = AF.LINK;
+ pub const XTP = AF.XTP;
+ pub const COIP = AF.COIP;
+ pub const CNT = AF.CNT;
+ pub const SIP = AF.SIP;
+ pub const IPX = AF.IPX;
+ pub const RTIP = AF.RTIP;
+ pub const PIP = AF.PIP;
+ pub const ISDN = AF.ISDN;
+ pub const KEY = AF.KEY;
+ pub const INET6 = AF.INET6;
+ pub const NATM = AF.NATM;
+ pub const SYSTEM = AF.SYSTEM;
+ pub const NETBIOS = AF.NETBIOS;
+ pub const PPP = AF.PPP;
+ pub const MAX = AF.MAX;
+ },
+ .freebsd, .kfreebsd => struct {
+ pub const UNSPEC = AF.UNSPEC;
+ pub const LOCAL = AF.LOCAL;
+ pub const UNIX = PF.LOCAL;
+ pub const INET = AF.INET;
+ pub const IMPLINK = AF.IMPLINK;
+ pub const PUP = AF.PUP;
+ pub const CHAOS = AF.CHAOS;
+ pub const NETBIOS = AF.NETBIOS;
+ pub const ISO = AF.ISO;
+ pub const OSI = AF.ISO;
+ pub const ECMA = AF.ECMA;
+ pub const DATAKIT = AF.DATAKIT;
+ pub const CCITT = AF.CCITT;
+ pub const DECnet = AF.DECnet;
+ pub const DLI = AF.DLI;
+ pub const LAT = AF.LAT;
+ pub const HYLINK = AF.HYLINK;
+ pub const APPLETALK = AF.APPLETALK;
+ pub const ROUTE = AF.ROUTE;
+ pub const LINK = AF.LINK;
+ pub const XTP = AF.pseudo_XTP;
+ pub const COIP = AF.COIP;
+ pub const CNT = AF.CNT;
+ pub const SIP = AF.SIP;
+ pub const IPX = AF.IPX;
+ pub const RTIP = AF.pseudo_RTIP;
+ pub const PIP = AF.pseudo_PIP;
+ pub const ISDN = AF.ISDN;
+ pub const KEY = AF.pseudo_KEY;
+ pub const INET6 = AF.pseudo_INET6;
+ pub const NATM = AF.NATM;
+ pub const ATM = AF.ATM;
+ pub const NETGRAPH = AF.NETGRAPH;
+ pub const SLOW = AF.SLOW;
+ pub const SCLUSTER = AF.SCLUSTER;
+ pub const ARP = AF.ARP;
+ pub const BLUETOOTH = AF.BLUETOOTH;
+ pub const IEEE80211 = AF.IEEE80211;
+ pub const INET_SDP = AF.INET_SDP;
+ pub const INET6_SDP = AF.INET6_SDP;
+ pub const MAX = AF.MAX;
+ },
+ .solaris, .illumos => struct {
+ pub const UNSPEC = AF.UNSPEC;
+ pub const UNIX = AF.UNIX;
+ pub const LOCAL = UNIX;
+ pub const FILE = UNIX;
+ pub const INET = AF.INET;
+ pub const IMPLINK = AF.IMPLINK;
+ pub const PUP = AF.PUP;
+ pub const CHAOS = AF.CHAOS;
+ pub const NS = AF.NS;
+ pub const NBS = AF.NBS;
+ pub const ECMA = AF.ECMA;
+ pub const DATAKIT = AF.DATAKIT;
+ pub const CCITT = AF.CCITT;
+ pub const SNA = AF.SNA;
+ pub const DECnet = AF.DECnet;
+ pub const DLI = AF.DLI;
+ pub const LAT = AF.LAT;
+ pub const HYLINK = AF.HYLINK;
+ pub const APPLETALK = AF.APPLETALK;
+ pub const NIT = AF.NIT;
+ pub const @"802" = AF.@"802";
+ pub const OSI = AF.OSI;
+ pub const X25 = AF.X25;
+ pub const OSINET = AF.OSINET;
+ pub const GOSIP = AF.GOSIP;
+ pub const IPX = AF.IPX;
+ pub const ROUTE = AF.ROUTE;
+ pub const LINK = AF.LINK;
+ pub const INET6 = AF.INET6;
+ pub const KEY = AF.KEY;
+ pub const NCA = AF.NCA;
+ pub const POLICY = AF.POLICY;
+ pub const TRILL = AF.TRILL;
+ pub const PACKET = AF.PACKET;
+ pub const LX_NETLINK = AF.LX_NETLINK;
+ pub const MAX = AF.MAX;
+ },
+ .netbsd => struct {
+ pub const UNSPEC = AF.UNSPEC;
+ pub const LOCAL = AF.LOCAL;
+ pub const UNIX = PF.LOCAL;
+ pub const INET = AF.INET;
+ pub const IMPLINK = AF.IMPLINK;
+ pub const PUP = AF.PUP;
+ pub const CHAOS = AF.CHAOS;
+ pub const NS = AF.NS;
+ pub const ISO = AF.ISO;
+ pub const OSI = AF.ISO;
+ pub const ECMA = AF.ECMA;
+ pub const DATAKIT = AF.DATAKIT;
+ pub const CCITT = AF.CCITT;
+ pub const SNA = AF.SNA;
+ pub const DECnet = AF.DECnet;
+ pub const DLI = AF.DLI;
+ pub const LAT = AF.LAT;
+ pub const HYLINK = AF.HYLINK;
+ pub const APPLETALK = AF.APPLETALK;
+ pub const OROUTE = AF.OROUTE;
+ pub const LINK = AF.LINK;
+ pub const COIP = AF.COIP;
+ pub const CNT = AF.CNT;
+ pub const INET6 = AF.INET6;
+ pub const IPX = AF.IPX;
+ pub const ISDN = AF.ISDN;
+ pub const E164 = AF.E164;
+ pub const NATM = AF.NATM;
+ pub const ARP = AF.ARP;
+ pub const BLUETOOTH = AF.BLUETOOTH;
+ pub const MPLS = AF.MPLS;
+ pub const ROUTE = AF.ROUTE;
+ pub const CAN = AF.CAN;
+ pub const ETHER = AF.ETHER;
+ pub const MAX = AF.MAX;
+ },
+ .dragonfly => struct {
+ pub const INET6 = AF.INET6;
+ pub const IMPLINK = AF.IMPLINK;
+ pub const ROUTE = AF.ROUTE;
+ pub const ISO = AF.ISO;
+ pub const PIP = AF.pseudo_PIP;
+ pub const CHAOS = AF.CHAOS;
+ pub const DATAKIT = AF.DATAKIT;
+ pub const INET = AF.INET;
+ pub const APPLETALK = AF.APPLETALK;
+ pub const SIP = AF.SIP;
+ pub const OSI = AF.ISO;
+ pub const CNT = AF.CNT;
+ pub const LINK = AF.LINK;
+ pub const HYLINK = AF.HYLINK;
+ pub const MAX = AF.MAX;
+ pub const KEY = AF.pseudo_KEY;
+ pub const PUP = AF.PUP;
+ pub const COIP = AF.COIP;
+ pub const SNA = AF.SNA;
+ pub const LOCAL = AF.LOCAL;
+ pub const NETBIOS = AF.NETBIOS;
+ pub const NATM = AF.NATM;
+ pub const BLUETOOTH = AF.BLUETOOTH;
+ pub const UNSPEC = AF.UNSPEC;
+ pub const NETGRAPH = AF.NETGRAPH;
+ pub const ECMA = AF.ECMA;
+ pub const IPX = AF.IPX;
+ pub const DLI = AF.DLI;
+ pub const ATM = AF.ATM;
+ pub const CCITT = AF.CCITT;
+ pub const ISDN = AF.ISDN;
+ pub const RTIP = AF.pseudo_RTIP;
+ pub const LAT = AF.LAT;
+ pub const UNIX = PF.LOCAL;
+ pub const XTP = AF.pseudo_XTP;
+ pub const DECnet = AF.DECnet;
+ },
+ .haiku => 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;
+ },
+ .openbsd => struct {
+ pub const UNSPEC = AF.UNSPEC;
+ pub const LOCAL = AF.LOCAL;
+ pub const UNIX = AF.UNIX;
+ pub const INET = AF.INET;
+ pub const APPLETALK = AF.APPLETALK;
+ pub const INET6 = AF.INET6;
+ pub const DECnet = AF.DECnet;
+ pub const KEY = AF.KEY;
+ pub const ROUTE = AF.ROUTE;
+ pub const SNA = AF.SNA;
+ pub const MPLS = AF.MPLS;
+ pub const BLUETOOTH = AF.BLUETOOTH;
+ pub const ISDN = AF.ISDN;
+ pub const MAX = AF.MAX;
+ },
+ else => void,
+};
+pub const DT = switch (native_os) {
+ .linux => linux.DT,
+ .netbsd, .freebsd, .kfreebsd, .macos, .ios, .tvos, .watchos, .visionos => struct {
+ pub const UNKNOWN = 0;
+ pub const FIFO = 1;
+ pub const CHR = 2;
+ pub const DIR = 4;
+ pub const BLK = 6;
+ pub const REG = 8;
+ pub const LNK = 10;
+ pub const SOCK = 12;
+ pub const WHT = 14;
+ },
+ .dragonfly => struct {
+ pub const UNKNOWN = 0;
+ pub const FIFO = 1;
+ pub const CHR = 2;
+ pub const DIR = 4;
+ pub const BLK = 6;
+ pub const REG = 8;
+ pub const LNK = 10;
+ pub const SOCK = 12;
+ pub const WHT = 14;
+ pub const DBF = 15;
+ },
+ .openbsd => struct {
+ pub const UNKNOWN = 0;
+ pub const FIFO = 1;
+ pub const CHR = 2;
+ pub const DIR = 4;
+ pub const BLK = 6;
+ pub const REG = 8;
+ pub const LNK = 10;
+ pub const SOCK = 12;
+ pub const WHT = 14; // XXX
+ },
+ else => void,
+};
+pub const MSG = switch (native_os) {
+ .linux => linux.MSG,
+ .emscripten => emscripten.MSG,
+ .windows => ws2_32.MSG,
+ .haiku => struct {
+ pub const OOB = 0x0001;
+ pub const PEEK = 0x0002;
+ pub const DONTROUTE = 0x0004;
+ pub const EOR = 0x0008;
+ pub const TRUNC = 0x0010;
+ pub const CTRUNC = 0x0020;
+ pub const WAITALL = 0x0040;
+ pub const DONTWAIT = 0x0080;
+ pub const BCAST = 0x0100;
+ pub const MCAST = 0x0200;
+ pub const EOF = 0x0400;
+ pub const NOSIGNAL = 0x0800;
+ },
+ else => void,
+};
+pub const SOCK = switch (native_os) {
+ .linux => linux.SOCK,
+ .emscripten => emscripten.SOCK,
+ .windows => ws2_32.SOCK,
+ .macos, .ios, .tvos, .watchos, .visionos => struct {
+ pub const STREAM = 1;
+ pub const DGRAM = 2;
+ pub const RAW = 3;
+ pub const RDM = 4;
+ pub const SEQPACKET = 5;
+ pub const MAXADDRLEN = 255;
+
+ /// Not actually supported by Darwin, but Zig supplies a shim.
+ /// This numerical value is not ABI-stable. It need only not conflict
+ /// with any other `SOCK` bits.
+ pub const CLOEXEC = 1 << 15;
+ /// Not actually supported by Darwin, but Zig supplies a shim.
+ /// This numerical value is not ABI-stable. It need only not conflict
+ /// with any other `SOCK` bits.
+ pub const NONBLOCK = 1 << 16;
+ },
+ .freebsd, .kfreebsd => struct {
+ pub const STREAM = 1;
+ pub const DGRAM = 2;
+ pub const RAW = 3;
+ pub const RDM = 4;
+ pub const SEQPACKET = 5;
+
+ pub const CLOEXEC = 0x10000000;
+ pub const NONBLOCK = 0x20000000;
+ },
+ .solaris, .illumos => struct {
+ /// Datagram.
+ pub const DGRAM = 1;
+ /// STREAM.
+ pub const STREAM = 2;
+ /// Raw-protocol interface.
+ pub const RAW = 4;
+ /// Reliably-delivered message.
+ pub const RDM = 5;
+ /// Sequenced packed stream.
+ pub const SEQPACKET = 6;
+
+ pub const NONBLOCK = 0x100000;
+ pub const NDELAY = 0x200000;
+ pub const CLOEXEC = 0x080000;
+ },
+ .netbsd => struct {
+ pub const STREAM = 1;
+ pub const DGRAM = 2;
+ pub const RAW = 3;
+ pub const RDM = 4;
+ pub const SEQPACKET = 5;
+ pub const CONN_DGRAM = 6;
+ pub const DCCP = CONN_DGRAM;
+
+ pub const CLOEXEC = 0x10000000;
+ pub const NONBLOCK = 0x20000000;
+ pub const NOSIGPIPE = 0x40000000;
+ pub const FLAGS_MASK = 0xf0000000;
+ },
+ .dragonfly => struct {
+ pub const STREAM = 1;
+ pub const DGRAM = 2;
+ pub const RAW = 3;
+ pub const RDM = 4;
+ pub const SEQPACKET = 5;
+ pub const MAXADDRLEN = 255;
+ pub const CLOEXEC = 0x10000000;
+ pub const NONBLOCK = 0x20000000;
+ },
+ .haiku => struct {
+ pub const STREAM = 1;
+ pub const DGRAM = 2;
+ pub const RAW = 3;
+ pub const SEQPACKET = 5;
+ pub const MISC = 255;
+ },
+ .openbsd => struct {
+ pub const STREAM = 1;
+ pub const DGRAM = 2;
+ pub const RAW = 3;
+ pub const RDM = 4;
+ pub const SEQPACKET = 5;
+
+ pub const CLOEXEC = 0x8000;
+ pub const NONBLOCK = 0x4000;
+ },
+ else => void,
+};
+pub const TCP = switch (native_os) {
+ .linux => linux.TCP,
+ .emscripten => emscripten.TCP,
+ .windows => ws2_32.TCP,
+ else => void,
+};
+pub const IPPROTO = switch (native_os) {
+ .linux, .emscripten => linux.IPPROTO,
+ .windows => ws2_32.IPPROTO,
+ .macos, .ios, .tvos, .watchos, .visionos => struct {
+ pub const ICMP = 1;
+ pub const ICMPV6 = 58;
+ pub const TCP = 6;
+ pub const UDP = 17;
+ pub const IP = 0;
+ pub const IPV6 = 41;
+ },
+ .freebsd, .kfreebsd => struct {
+ /// dummy for IP
+ pub const IP = 0;
+ /// control message protocol
+ pub const ICMP = 1;
+ /// tcp
+ pub const TCP = 6;
+ /// user datagram protocol
+ pub const UDP = 17;
+ /// IP6 header
+ pub const IPV6 = 41;
+ /// raw IP packet
+ pub const RAW = 255;
+ /// IP6 hop-by-hop options
+ pub const HOPOPTS = 0;
+ /// group mgmt protocol
+ pub const IGMP = 2;
+ /// gateway^2 (deprecated)
+ pub const GGP = 3;
+ /// IPv4 encapsulation
+ pub const IPV4 = 4;
+ /// for compatibility
+ pub const IPIP = IPV4;
+ /// Stream protocol II
+ pub const ST = 7;
+ /// exterior gateway protocol
+ pub const EGP = 8;
+ /// private interior gateway
+ pub const PIGP = 9;
+ /// BBN RCC Monitoring
+ pub const RCCMON = 10;
+ /// network voice protocol
+ pub const NVPII = 11;
+ /// pup
+ pub const PUP = 12;
+ /// Argus
+ pub const ARGUS = 13;
+ /// EMCON
+ pub const EMCON = 14;
+ /// Cross Net Debugger
+ pub const XNET = 15;
+ /// Chaos
+ pub const CHAOS = 16;
+ /// Multiplexing
+ pub const MUX = 18;
+ /// DCN Measurement Subsystems
+ pub const MEAS = 19;
+ /// Host Monitoring
+ pub const HMP = 20;
+ /// Packet Radio Measurement
+ pub const PRM = 21;
+ /// xns idp
+ pub const IDP = 22;
+ /// Trunk-1
+ pub const TRUNK1 = 23;
+ /// Trunk-2
+ pub const TRUNK2 = 24;
+ /// Leaf-1
+ pub const LEAF1 = 25;
+ /// Leaf-2
+ pub const LEAF2 = 26;
+ /// Reliable Data
+ pub const RDP = 27;
+ /// Reliable Transaction
+ pub const IRTP = 28;
+ /// tp-4 w/ class negotiation
+ pub const TP = 29;
+ /// Bulk Data Transfer
+ pub const BLT = 30;
+ /// Network Services
+ pub const NSP = 31;
+ /// Merit Internodal
+ pub const INP = 32;
+ /// Datagram Congestion Control Protocol
+ pub const DCCP = 33;
+ /// Third Party Connect
+ pub const @"3PC" = 34;
+ /// InterDomain Policy Routing
+ pub const IDPR = 35;
+ /// XTP
+ pub const XTP = 36;
+ /// Datagram Delivery
+ pub const DDP = 37;
+ /// Control Message Transport
+ pub const CMTP = 38;
+ /// TP++ Transport
+ pub const TPXX = 39;
+ /// IL transport protocol
+ pub const IL = 40;
+ /// Source Demand Routing
+ pub const SDRP = 42;
+ /// IP6 routing header
+ pub const ROUTING = 43;
+ /// IP6 fragmentation header
+ pub const FRAGMENT = 44;
+ /// InterDomain Routing
+ pub const IDRP = 45;
+ /// resource reservation
+ pub const RSVP = 46;
+ /// General Routing Encap.
+ pub const GRE = 47;
+ /// Mobile Host Routing
+ pub const MHRP = 48;
+ /// BHA
+ pub const BHA = 49;
+ /// IP6 Encap Sec. Payload
+ pub const ESP = 50;
+ /// IP6 Auth Header
+ pub const AH = 51;
+ /// Integ. Net Layer Security
+ pub const INLSP = 52;
+ /// IP with encryption
+ pub const SWIPE = 53;
+ /// Next Hop Resolution
+ pub const NHRP = 54;
+ /// IP Mobility
+ pub const MOBILE = 55;
+ /// Transport Layer Security
+ pub const TLSP = 56;
+ /// SKIP
+ pub const SKIP = 57;
+ /// ICMP6
+ pub const ICMPV6 = 58;
+ /// IP6 no next header
+ pub const NONE = 59;
+ /// IP6 destination option
+ pub const DSTOPTS = 60;
+ /// any host internal protocol
+ pub const AHIP = 61;
+ /// CFTP
+ pub const CFTP = 62;
+ /// "hello" routing protocol
+ pub const HELLO = 63;
+ /// SATNET/Backroom EXPAK
+ pub const SATEXPAK = 64;
+ /// Kryptolan
+ pub const KRYPTOLAN = 65;
+ /// Remote Virtual Disk
+ pub const RVD = 66;
+ /// Pluribus Packet Core
+ pub const IPPC = 67;
+ /// Any distributed FS
+ pub const ADFS = 68;
+ /// Satnet Monitoring
+ pub const SATMON = 69;
+ /// VISA Protocol
+ pub const VISA = 70;
+ /// Packet Core Utility
+ pub const IPCV = 71;
+ /// Comp. Prot. Net. Executive
+ pub const CPNX = 72;
+ /// Comp. Prot. HeartBeat
+ pub const CPHB = 73;
+ /// Wang Span Network
+ pub const WSN = 74;
+ /// Packet Video Protocol
+ pub const PVP = 75;
+ /// BackRoom SATNET Monitoring
+ pub const BRSATMON = 76;
+ /// Sun net disk proto (temp.)
+ pub const ND = 77;
+ /// WIDEBAND Monitoring
+ pub const WBMON = 78;
+ /// WIDEBAND EXPAK
+ pub const WBEXPAK = 79;
+ /// ISO cnlp
+ pub const EON = 80;
+ /// VMTP
+ pub const VMTP = 81;
+ /// Secure VMTP
+ pub const SVMTP = 82;
+ /// Banyon VINES
+ pub const VINES = 83;
+ /// TTP
+ pub const TTP = 84;
+ /// NSFNET-IGP
+ pub const IGP = 85;
+ /// dissimilar gateway prot.
+ pub const DGP = 86;
+ /// TCF
+ pub const TCF = 87;
+ /// Cisco/GXS IGRP
+ pub const IGRP = 88;
+ /// OSPFIGP
+ pub const OSPFIGP = 89;
+ /// Strite RPC protocol
+ pub const SRPC = 90;
+ /// Locus Address Resoloution
+ pub const LARP = 91;
+ /// Multicast Transport
+ pub const MTP = 92;
+ /// AX.25 Frames
+ pub const AX25 = 93;
+ /// IP encapsulated in IP
+ pub const IPEIP = 94;
+ /// Mobile Int.ing control
+ pub const MICP = 95;
+ /// Semaphore Comm. security
+ pub const SCCSP = 96;
+ /// Ethernet IP encapsulation
+ pub const ETHERIP = 97;
+ /// encapsulation header
+ pub const ENCAP = 98;
+ /// any private encr. scheme
+ pub const APES = 99;
+ /// GMTP
+ pub const GMTP = 100;
+ /// payload compression (IPComp)
+ pub const IPCOMP = 108;
+ /// SCTP
+ pub const SCTP = 132;
+ /// IPv6 Mobility Header
+ pub const MH = 135;
+ /// UDP-Lite
+ pub const UDPLITE = 136;
+ /// IP6 Host Identity Protocol
+ pub const HIP = 139;
+ /// IP6 Shim6 Protocol
+ pub const SHIM6 = 140;
+ /// Protocol Independent Mcast
+ pub const PIM = 103;
+ /// CARP
+ pub const CARP = 112;
+ /// PGM
+ pub const PGM = 113;
+ /// MPLS-in-IP
+ pub const MPLS = 137;
+ /// PFSYNC
+ pub const PFSYNC = 240;
+ /// Reserved
+ pub const RESERVED_253 = 253;
+ /// Reserved
+ pub const RESERVED_254 = 254;
+ },
+ .solaris, .illumos => struct {
+ /// dummy for IP
+ pub const IP = 0;
+ /// Hop by hop header for IPv6
+ pub const HOPOPTS = 0;
+ /// control message protocol
+ pub const ICMP = 1;
+ /// group control protocol
+ pub const IGMP = 2;
+ /// gateway^2 (deprecated)
+ pub const GGP = 3;
+ /// IP in IP encapsulation
+ pub const ENCAP = 4;
+ /// tcp
+ pub const TCP = 6;
+ /// exterior gateway protocol
+ pub const EGP = 8;
+ /// pup
+ pub const PUP = 12;
+ /// user datagram protocol
+ pub const UDP = 17;
+ /// xns idp
+ pub const IDP = 22;
+ /// IPv6 encapsulated in IP
+ pub const IPV6 = 41;
+ /// Routing header for IPv6
+ pub const ROUTING = 43;
+ /// Fragment header for IPv6
+ pub const FRAGMENT = 44;
+ /// rsvp
+ pub const RSVP = 46;
+ /// IPsec Encap. Sec. Payload
+ pub const ESP = 50;
+ /// IPsec Authentication Hdr.
+ pub const AH = 51;
+ /// ICMP for IPv6
+ pub const ICMPV6 = 58;
+ /// No next header for IPv6
+ pub const NONE = 59;
+ /// Destination options
+ pub const DSTOPTS = 60;
+ /// "hello" routing protocol
+ pub const HELLO = 63;
+ /// UNOFFICIAL net disk proto
+ pub const ND = 77;
+ /// ISO clnp
+ pub const EON = 80;
+ /// OSPF
+ pub const OSPF = 89;
+ /// PIM routing protocol
+ pub const PIM = 103;
+ /// Stream Control
+ pub const SCTP = 132;
+ /// raw IP packet
+ pub const RAW = 255;
+ /// Sockets Direct Protocol
+ pub const PROTO_SDP = 257;
+ },
+ .netbsd => struct {
+ /// dummy for IP
+ pub const IP = 0;
+ /// IP6 hop-by-hop options
+ pub const HOPOPTS = 0;
+ /// control message protocol
+ pub const ICMP = 1;
+ /// group mgmt protocol
+ pub const IGMP = 2;
+ /// gateway^2 (deprecated)
+ pub const GGP = 3;
+ /// IP header
+ pub const IPV4 = 4;
+ /// IP inside IP
+ pub const IPIP = 4;
+ /// tcp
+ pub const TCP = 6;
+ /// exterior gateway protocol
+ pub const EGP = 8;
+ /// pup
+ pub const PUP = 12;
+ /// user datagram protocol
+ pub const UDP = 17;
+ /// xns idp
+ pub const IDP = 22;
+ /// tp-4 w/ class negotiation
+ pub const TP = 29;
+ /// DCCP
+ pub const DCCP = 33;
+ /// IP6 header
+ pub const IPV6 = 41;
+ /// IP6 routing header
+ pub const ROUTING = 43;
+ /// IP6 fragmentation header
+ pub const FRAGMENT = 44;
+ /// resource reservation
+ pub const RSVP = 46;
+ /// GRE encaps RFC 1701
+ pub const GRE = 47;
+ /// encap. security payload
+ pub const ESP = 50;
+ /// authentication header
+ pub const AH = 51;
+ /// IP Mobility RFC 2004
+ pub const MOBILE = 55;
+ /// IPv6 ICMP
+ pub const IPV6_ICMP = 58;
+ /// ICMP6
+ pub const ICMPV6 = 58;
+ /// IP6 no next header
+ pub const NONE = 59;
+ /// IP6 destination option
+ pub const DSTOPTS = 60;
+ /// ISO cnlp
+ pub const EON = 80;
+ /// Ethernet-in-IP
+ pub const ETHERIP = 97;
+ /// encapsulation header
+ pub const ENCAP = 98;
+ /// Protocol indep. multicast
+ pub const PIM = 103;
+ /// IP Payload Comp. Protocol
+ pub const IPCOMP = 108;
+ /// VRRP RFC 2338
+ pub const VRRP = 112;
+ /// Common Address Resolution Protocol
+ pub const CARP = 112;
+ /// L2TPv3
+ pub const L2TP = 115;
+ /// SCTP
+ pub const SCTP = 132;
+ /// PFSYNC
+ pub const PFSYNC = 240;
+ /// raw IP packet
+ pub const RAW = 255;
+ },
+ .dragonfly => struct {
+ pub const IP = 0;
+ pub const ICMP = 1;
+ pub const TCP = 6;
+ pub const UDP = 17;
+ pub const IPV6 = 41;
+ pub const RAW = 255;
+ pub const HOPOPTS = 0;
+ pub const IGMP = 2;
+ pub const GGP = 3;
+ pub const IPV4 = 4;
+ pub const IPIP = IPV4;
+ pub const ST = 7;
+ pub const EGP = 8;
+ pub const PIGP = 9;
+ pub const RCCMON = 10;
+ pub const NVPII = 11;
+ pub const PUP = 12;
+ pub const ARGUS = 13;
+ pub const EMCON = 14;
+ pub const XNET = 15;
+ pub const CHAOS = 16;
+ pub const MUX = 18;
+ pub const MEAS = 19;
+ pub const HMP = 20;
+ pub const PRM = 21;
+ pub const IDP = 22;
+ pub const TRUNK1 = 23;
+ pub const TRUNK2 = 24;
+ pub const LEAF1 = 25;
+ pub const LEAF2 = 26;
+ pub const RDP = 27;
+ pub const IRTP = 28;
+ pub const TP = 29;
+ pub const BLT = 30;
+ pub const NSP = 31;
+ pub const INP = 32;
+ pub const SEP = 33;
+ pub const @"3PC" = 34;
+ pub const IDPR = 35;
+ pub const XTP = 36;
+ pub const DDP = 37;
+ pub const CMTP = 38;
+ pub const TPXX = 39;
+ pub const IL = 40;
+ pub const SDRP = 42;
+ pub const ROUTING = 43;
+ pub const FRAGMENT = 44;
+ pub const IDRP = 45;
+ pub const RSVP = 46;
+ pub const GRE = 47;
+ pub const MHRP = 48;
+ pub const BHA = 49;
+ pub const ESP = 50;
+ pub const AH = 51;
+ pub const INLSP = 52;
+ pub const SWIPE = 53;
+ pub const NHRP = 54;
+ pub const MOBILE = 55;
+ pub const TLSP = 56;
+ pub const SKIP = 57;
+ pub const ICMPV6 = 58;
+ pub const NONE = 59;
+ pub const DSTOPTS = 60;
+ pub const AHIP = 61;
+ pub const CFTP = 62;
+ pub const HELLO = 63;
+ pub const SATEXPAK = 64;
+ pub const KRYPTOLAN = 65;
+ pub const RVD = 66;
+ pub const IPPC = 67;
+ pub const ADFS = 68;
+ pub const SATMON = 69;
+ pub const VISA = 70;
+ pub const IPCV = 71;
+ pub const CPNX = 72;
+ pub const CPHB = 73;
+ pub const WSN = 74;
+ pub const PVP = 75;
+ pub const BRSATMON = 76;
+ pub const ND = 77;
+ pub const WBMON = 78;
+ pub const WBEXPAK = 79;
+ pub const EON = 80;
+ pub const VMTP = 81;
+ pub const SVMTP = 82;
+ pub const VINES = 83;
+ pub const TTP = 84;
+ pub const IGP = 85;
+ pub const DGP = 86;
+ pub const TCF = 87;
+ pub const IGRP = 88;
+ pub const OSPFIGP = 89;
+ pub const SRPC = 90;
+ pub const LARP = 91;
+ pub const MTP = 92;
+ pub const AX25 = 93;
+ pub const IPEIP = 94;
+ pub const MICP = 95;
+ pub const SCCSP = 96;
+ pub const ETHERIP = 97;
+ pub const ENCAP = 98;
+ pub const APES = 99;
+ pub const GMTP = 100;
+ pub const IPCOMP = 108;
+ pub const PIM = 103;
+ pub const CARP = 112;
+ pub const PGM = 113;
+ pub const PFSYNC = 240;
+ pub const DIVERT = 254;
+ pub const MAX = 256;
+ pub const DONE = 257;
+ pub const UNKNOWN = 258;
+ },
+ .haiku => 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;
+ },
+ .openbsd => struct {
+ /// dummy for IP
+ pub const IP = 0;
+ /// IP6 hop-by-hop options
+ pub const HOPOPTS = IP;
+ /// control message protocol
+ pub const ICMP = 1;
+ /// group mgmt protocol
+ pub const IGMP = 2;
+ /// gateway^2 (deprecated)
+ pub const GGP = 3;
+ /// IP header
+ pub const IPV4 = IPIP;
+ /// IP inside IP
+ pub const IPIP = 4;
+ /// tcp
+ pub const TCP = 6;
+ /// exterior gateway protocol
+ pub const EGP = 8;
+ /// pup
+ pub const PUP = 12;
+ /// user datagram protocol
+ pub const UDP = 17;
+ /// xns idp
+ pub const IDP = 22;
+ /// tp-4 w/ class negotiation
+ pub const TP = 29;
+ /// IP6 header
+ pub const IPV6 = 41;
+ /// IP6 routing header
+ pub const ROUTING = 43;
+ /// IP6 fragmentation header
+ pub const FRAGMENT = 44;
+ /// resource reservation
+ pub const RSVP = 46;
+ /// GRE encaps RFC 1701
+ pub const GRE = 47;
+ /// encap. security payload
+ pub const ESP = 50;
+ /// authentication header
+ pub const AH = 51;
+ /// IP Mobility RFC 2004
+ pub const MOBILE = 55;
+ /// IPv6 ICMP
+ pub const IPV6_ICMP = 58;
+ /// ICMP6
+ pub const ICMPV6 = 58;
+ /// IP6 no next header
+ pub const NONE = 59;
+ /// IP6 destination option
+ pub const DSTOPTS = 60;
+ /// ISO cnlp
+ pub const EON = 80;
+ /// Ethernet-in-IP
+ pub const ETHERIP = 97;
+ /// encapsulation header
+ pub const ENCAP = 98;
+ /// Protocol indep. multicast
+ pub const PIM = 103;
+ /// IP Payload Comp. Protocol
+ pub const IPCOMP = 108;
+ /// VRRP RFC 2338
+ pub const VRRP = 112;
+ /// Common Address Resolution Protocol
+ pub const CARP = 112;
+ /// PFSYNC
+ pub const PFSYNC = 240;
+ /// raw IP packet
+ pub const RAW = 255;
+ },
+ else => void,
+};
+pub const SOL = switch (native_os) {
+ .linux => linux.SOL,
+ .emscripten => emscripten.SOL,
+ .windows => ws2_32.SOL,
+ .openbsd, .haiku, .dragonfly, .netbsd, .freebsd, .kfreebsd, .macos, .ios, .tvos, .watchos, .visionos => struct {
+ pub const SOCKET = 0xffff;
+ },
+ .solaris, .illumos => struct {
+ pub const SOCKET = 0xffff;
+ pub const ROUTE = 0xfffe;
+ pub const PACKET = 0xfffd;
+ pub const FILTER = 0xfffc;
+ },
+ else => void,
+};
+pub const SO = switch (native_os) {
+ .linux => linux.SO,
+ .emscripten => emscripten.SO,
+ .windows => ws2_32.SO,
+ .macos, .ios, .tvos, .watchos, .visionos => struct {
+ pub const DEBUG = 0x0001;
+ pub const ACCEPTCONN = 0x0002;
+ pub const REUSEADDR = 0x0004;
+ pub const KEEPALIVE = 0x0008;
+ pub const DONTROUTE = 0x0010;
+ pub const BROADCAST = 0x0020;
+ pub const USELOOPBACK = 0x0040;
+ pub const LINGER = 0x1080;
+ pub const OOBINLINE = 0x0100;
+ pub const REUSEPORT = 0x0200;
+ pub const ACCEPTFILTER = 0x1000;
+ pub const SNDBUF = 0x1001;
+ pub const RCVBUF = 0x1002;
+ pub const SNDLOWAT = 0x1003;
+ pub const RCVLOWAT = 0x1004;
+ pub const SNDTIMEO = 0x1005;
+ pub const RCVTIMEO = 0x1006;
+ pub const ERROR = 0x1007;
+ pub const TYPE = 0x1008;
+
+ pub const NREAD = 0x1020;
+ pub const NKE = 0x1021;
+ pub const NOSIGPIPE = 0x1022;
+ pub const NOADDRERR = 0x1023;
+ pub const NWRITE = 0x1024;
+ pub const REUSESHAREUID = 0x1025;
+ },
+ .freebsd, .kfreebsd => struct {
+ pub const DEBUG = 0x00000001;
+ pub const ACCEPTCONN = 0x00000002;
+ pub const REUSEADDR = 0x00000004;
+ pub const KEEPALIVE = 0x00000008;
+ pub const DONTROUTE = 0x00000010;
+ pub const BROADCAST = 0x00000020;
+ pub const USELOOPBACK = 0x00000040;
+ pub const LINGER = 0x00000080;
+ pub const OOBINLINE = 0x00000100;
+ pub const REUSEPORT = 0x00000200;
+ pub const TIMESTAMP = 0x00000400;
+ pub const NOSIGPIPE = 0x00000800;
+ pub const ACCEPTFILTER = 0x00001000;
+ pub const BINTIME = 0x00002000;
+ pub const NO_OFFLOAD = 0x00004000;
+ pub const NO_DDP = 0x00008000;
+ pub const REUSEPORT_LB = 0x00010000;
+
+ pub const SNDBUF = 0x1001;
+ pub const RCVBUF = 0x1002;
+ pub const SNDLOWAT = 0x1003;
+ pub const RCVLOWAT = 0x1004;
+ pub const SNDTIMEO = 0x1005;
+ pub const RCVTIMEO = 0x1006;
+ pub const ERROR = 0x1007;
+ pub const TYPE = 0x1008;
+ pub const LABEL = 0x1009;
+ pub const PEERLABEL = 0x1010;
+ pub const LISTENQLIMIT = 0x1011;
+ pub const LISTENQLEN = 0x1012;
+ pub const LISTENINCQLEN = 0x1013;
+ pub const SETFIB = 0x1014;
+ pub const USER_COOKIE = 0x1015;
+ pub const PROTOCOL = 0x1016;
+ pub const PROTOTYPE = PROTOCOL;
+ pub const TS_CLOCK = 0x1017;
+ pub const MAX_PACING_RATE = 0x1018;
+ pub const DOMAIN = 0x1019;
+ },
+ .solaris, .illumos => struct {
+ pub const DEBUG = 0x0001;
+ pub const ACCEPTCONN = 0x0002;
+ pub const REUSEADDR = 0x0004;
+ pub const KEEPALIVE = 0x0008;
+ pub const DONTROUTE = 0x0010;
+ pub const BROADCAST = 0x0020;
+ pub const USELOOPBACK = 0x0040;
+ pub const LINGER = 0x0080;
+ pub const OOBINLINE = 0x0100;
+ pub const DGRAM_ERRIND = 0x0200;
+ pub const RECVUCRED = 0x0400;
+
+ pub const SNDBUF = 0x1001;
+ pub const RCVBUF = 0x1002;
+ pub const SNDLOWAT = 0x1003;
+ pub const RCVLOWAT = 0x1004;
+ pub const SNDTIMEO = 0x1005;
+ pub const RCVTIMEO = 0x1006;
+ pub const ERROR = 0x1007;
+ pub const TYPE = 0x1008;
+ pub const PROTOTYPE = 0x1009;
+ pub const ANON_MLP = 0x100a;
+ pub const MAC_EXEMPT = 0x100b;
+ pub const DOMAIN = 0x100c;
+ pub const RCVPSH = 0x100d;
+
+ pub const SECATTR = 0x1011;
+ pub const TIMESTAMP = 0x1013;
+ pub const ALLZONES = 0x1014;
+ pub const EXCLBIND = 0x1015;
+ pub const MAC_IMPLICIT = 0x1016;
+ pub const VRRP = 0x1017;
+ },
+ .netbsd => struct {
+ pub const DEBUG = 0x0001;
+ pub const ACCEPTCONN = 0x0002;
+ pub const REUSEADDR = 0x0004;
+ pub const KEEPALIVE = 0x0008;
+ pub const DONTROUTE = 0x0010;
+ pub const BROADCAST = 0x0020;
+ pub const USELOOPBACK = 0x0040;
+ pub const LINGER = 0x0080;
+ pub const OOBINLINE = 0x0100;
+ pub const REUSEPORT = 0x0200;
+ pub const NOSIGPIPE = 0x0800;
+ pub const ACCEPTFILTER = 0x1000;
+ pub const TIMESTAMP = 0x2000;
+ pub const RERROR = 0x4000;
+
+ pub const SNDBUF = 0x1001;
+ pub const RCVBUF = 0x1002;
+ pub const SNDLOWAT = 0x1003;
+ pub const RCVLOWAT = 0x1004;
+ pub const ERROR = 0x1007;
+ pub const TYPE = 0x1008;
+ pub const OVERFLOWED = 0x1009;
+
+ pub const NOHEADER = 0x100a;
+ pub const SNDTIMEO = 0x100b;
+ pub const RCVTIMEO = 0x100c;
+ },
+ .dragonfly => struct {
+ pub const DEBUG = 0x0001;
+ pub const ACCEPTCONN = 0x0002;
+ pub const REUSEADDR = 0x0004;
+ pub const KEEPALIVE = 0x0008;
+ pub const DONTROUTE = 0x0010;
+ pub const BROADCAST = 0x0020;
+ pub const USELOOPBACK = 0x0040;
+ pub const LINGER = 0x0080;
+ pub const OOBINLINE = 0x0100;
+ pub const REUSEPORT = 0x0200;
+ pub const TIMESTAMP = 0x0400;
+ pub const NOSIGPIPE = 0x0800;
+ pub const ACCEPTFILTER = 0x1000;
+ pub const RERROR = 0x2000;
+ pub const PASSCRED = 0x4000;
+
+ pub const SNDBUF = 0x1001;
+ pub const RCVBUF = 0x1002;
+ pub const SNDLOWAT = 0x1003;
+ pub const RCVLOWAT = 0x1004;
+ pub const SNDTIMEO = 0x1005;
+ pub const RCVTIMEO = 0x1006;
+ pub const ERROR = 0x1007;
+ pub const TYPE = 0x1008;
+ pub const SNDSPACE = 0x100a;
+ pub const CPUHINT = 0x1030;
+ },
+ .haiku => 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;
+ },
+ .openbsd => struct {
+ pub const DEBUG = 0x0001;
+ pub const ACCEPTCONN = 0x0002;
+ pub const REUSEADDR = 0x0004;
+ pub const KEEPALIVE = 0x0008;
+ pub const DONTROUTE = 0x0010;
+ pub const BROADCAST = 0x0020;
+ pub const USELOOPBACK = 0x0040;
+ pub const LINGER = 0x0080;
+ pub const OOBINLINE = 0x0100;
+ pub const REUSEPORT = 0x0200;
+ pub const TIMESTAMP = 0x0800;
+ pub const BINDANY = 0x1000;
+ pub const ZEROIZE = 0x2000;
+ pub const SNDBUF = 0x1001;
+ pub const RCVBUF = 0x1002;
+ pub const SNDLOWAT = 0x1003;
+ pub const RCVLOWAT = 0x1004;
+ pub const SNDTIMEO = 0x1005;
+ pub const RCVTIMEO = 0x1006;
+ pub const ERROR = 0x1007;
+ pub const TYPE = 0x1008;
+ pub const NETPROC = 0x1020;
+ pub const RTABLE = 0x1021;
+ pub const PEERCRED = 0x1022;
+ pub const SPLICE = 0x1023;
+ pub const DOMAIN = 0x1024;
+ pub const PROTOCOL = 0x1025;
+ },
+ else => void,
+};
+pub const SOMAXCONN = switch (native_os) {
+ .linux => linux.SOMAXCONN,
+ .windows => ws2_32.SOMAXCONN,
+ .solaris, .illumos => 128,
+ .openbsd => 28,
+ else => void,
+};
+pub const IFNAMESIZE = switch (native_os) {
+ .linux => linux.IFNAMESIZE,
+ .emscripten => emscripten.IFNAMESIZE,
+ .windows => 30,
+ .openbsd, .dragonfly, .netbsd, .freebsd, .kfreebsd, .macos, .ios, .tvos, .watchos, .visionos => 16,
+ .solaris, .illumos => 32,
+ else => void,
+};
+
+pub const stack_t = switch (native_os) {
+ .linux => linux.stack_t,
+ .emscripten => emscripten.stack_t,
+ .freebsd, .kfreebsd => extern struct {
+ /// Signal stack base.
+ sp: *anyopaque,
+ /// Signal stack length.
+ size: usize,
+ /// SS_DISABLE and/or SS_ONSTACK.
+ flags: i32,
+ },
+ else => extern struct {
+ sp: [*]u8,
+ size: isize,
+ flags: i32,
+ },
+};
+pub const time_t = switch (native_os) {
+ .linux => linux.time_t,
+ .emscripten => emscripten.time_t,
+ .haiku, .dragonfly => isize,
+ else => i64,
+};
+pub const suseconds_t = switch (native_os) {
+ .solaris, .illumos => i64,
+ .freebsd, .kfreebsd, .dragonfly => c_long,
+ .netbsd => c_int,
+ .haiku => i32,
+ else => void,
+};
+
+pub const timeval = switch (native_os) {
+ .linux => linux.timeval,
+ .emscripten => emscripten.timeval,
+ .windows => extern struct {
+ sec: c_long,
+ usec: c_long,
+ },
+ .macos, .ios, .tvos, .watchos, .visionos => extern struct {
+ sec: c_long,
+ usec: i32,
+ },
+ .dragonfly, .netbsd, .freebsd, .kfreebsd, .solaris, .illumos => extern struct {
+ /// seconds
+ sec: time_t,
+ /// microseconds
+ usec: suseconds_t,
+ },
+ .openbsd => extern struct {
+ sec: time_t,
+ usec: c_long,
+ },
+ else => void,
+};
+pub const timezone = switch (native_os) {
+ .linux => linux.timezone,
+ .emscripten => emscripten.timezone,
+ .openbsd, .macos, .ios, .tvos, .watchos, .visionos => extern struct {
+ minuteswest: i32,
+ dsttime: i32,
+ },
+ else => void,
+};
+
+pub const ucontext_t = switch (native_os) {
+ .linux => linux.ucontext_t,
+ .emscripten => emscripten.ucontext_t,
+ .macos, .ios, .tvos, .watchos, .visionos => extern struct {
+ onstack: c_int,
+ sigmask: sigset_t,
+ stack: stack_t,
+ link: ?*ucontext_t,
+ mcsize: u64,
+ mcontext: *mcontext_t,
+ __mcontext_data: mcontext_t,
+ },
+ .freebsd, .kfreebsd => extern struct {
+ sigmask: sigset_t,
+ mcontext: mcontext_t,
+ link: ?*ucontext_t,
+ stack: stack_t,
+ flags: c_int,
+ __spare__: [4]c_int,
+ },
+ .solaris, .illumos => extern struct {
+ flags: u64,
+ link: ?*ucontext_t,
+ sigmask: sigset_t,
+ stack: stack_t,
+ mcontext: mcontext_t,
+ brand_data: [3]?*anyopaque,
+ filler: [2]i64,
+ },
+ .netbsd => extern struct {
+ flags: u32,
+ link: ?*ucontext_t,
+ sigmask: sigset_t,
+ stack: stack_t,
+ mcontext: mcontext_t,
+ __pad: [
+ switch (builtin.cpu.arch) {
+ .x86 => 4,
+ .mips, .mipsel, .mips64, .mips64el => 14,
+ .arm, .armeb, .thumb, .thumbeb => 1,
+ .sparc, .sparcel, .sparc64 => if (@sizeOf(usize) == 4) 43 else 8,
+ else => 0,
+ }
+ ]u32,
+ },
+ .dragonfly => extern struct {
+ sigmask: sigset_t,
+ mcontext: mcontext_t,
+ link: ?*ucontext_t,
+ stack: stack_t,
+ cofunc: ?*fn (?*ucontext_t, ?*anyopaque) void,
+ arg: ?*void,
+ _spare: [4]c_int,
+ },
+ .haiku => extern struct {
+ link: ?*ucontext_t,
+ sigmask: sigset_t,
+ stack: stack_t,
+ mcontext: mcontext_t,
+ },
+ .openbsd => openbsd.ucontext_t,
+ else => void,
+};
+pub const mcontext_t = switch (native_os) {
+ .linux => linux.mcontext_t,
+ .emscripten => emscripten.mcontext_t,
+ .macos, .ios, .tvos, .watchos, .visionos => darwin.mcontext_t,
+ .freebsd, .kfreebsd => switch (builtin.cpu.arch) {
+ .x86_64 => extern struct {
+ onstack: u64,
+ rdi: u64,
+ rsi: u64,
+ rdx: u64,
+ rcx: u64,
+ r8: u64,
+ r9: u64,
+ rax: u64,
+ rbx: u64,
+ rbp: u64,
+ r10: u64,
+ r11: u64,
+ r12: u64,
+ r13: u64,
+ r14: u64,
+ r15: u64,
+ trapno: u32,
+ fs: u16,
+ gs: u16,
+ addr: u64,
+ flags: u32,
+ es: u16,
+ ds: u16,
+ err: u64,
+ rip: u64,
+ cs: u64,
+ rflags: u64,
+ rsp: u64,
+ ss: u64,
+ len: u64,
+ fpformat: u64,
+ ownedfp: u64,
+ fpstate: [64]u64 align(16),
+ fsbase: u64,
+ gsbase: u64,
+ xfpustate: u64,
+ xfpustate_len: u64,
+ spare: [4]u64,
+ },
+ .aarch64 => extern struct {
+ gpregs: extern struct {
+ x: [30]u64,
+ lr: u64,
+ sp: u64,
+ elr: u64,
+ spsr: u32,
+ _pad: u32,
+ },
+ fpregs: extern struct {
+ q: [32]u128,
+ sr: u32,
+ cr: u32,
+ flags: u32,
+ _pad: u32,
+ },
+ flags: u32,
+ _pad: u32,
+ _spare: [8]u64,
+ },
+ else => struct {},
+ },
+ .solaris, .illumos => extern struct {
+ gregs: [28]u64,
+ fpregs: solaris.fpregset_t,
+ },
+ .netbsd => switch (builtin.cpu.arch) {
+ .aarch64 => extern struct {
+ gregs: [35]u64,
+ fregs: [528]u8 align(16),
+ spare: [8]u64,
+ },
+ .x86_64 => extern struct {
+ gregs: [26]u64,
+ mc_tlsbase: u64,
+ fpregs: [512]u8 align(8),
+ },
+ else => struct {},
+ },
+ .dragonfly => dragonfly.mcontext_t,
+ .haiku => haiku.mcontext_t,
+ else => void,
+};
+
+pub const user_desc = switch (native_os) {
+ .linux => linux.user_desc,
+ else => void,
+};
+pub const utsname = switch (native_os) {
+ .linux => linux.utsname,
+ .emscripten => emscripten.utsname,
+ .solaris, .illumos => extern struct {
+ sysname: [256:0]u8,
+ nodename: [256:0]u8,
+ release: [256:0]u8,
+ version: [256:0]u8,
+ machine: [256:0]u8,
+ domainname: [256:0]u8,
+ },
+ else => void,
+};
+pub const PR = switch (native_os) {
+ .linux => linux.PR,
+ else => void,
+};
+pub const _errno = switch (native_os) {
+ .linux => switch (native_abi) {
+ .android => private.__errno,
+ else => private.__errno_location,
+ },
+ .emscripten => private.__errno_location,
+ .wasi, .dragonfly => private.errnoFromThreadLocal,
+ .windows => private._errno,
+ .macos, .ios, .tvos, .watchos, .visionos, .freebsd, .kfreebsd => private.__error,
+ .solaris, .illumos => private.___errno,
+ .openbsd, .netbsd => private.__errno,
+ .haiku => haiku._errnop,
+ else => {},
+};
+
+pub const RTLD = switch (native_os) {
+ .linux, .emscripten => packed struct(u32) {
+ LAZY: bool = false,
+ NOW: bool = false,
+ NOLOAD: bool = false,
+ _3: u5 = 0,
+ GLOBAL: bool = false,
+ _9: u3 = 0,
+ NODELETE: bool = false,
+ _: u19 = 0,
+ },
+ .dragonfly, .freebsd, .kfreebsd => packed struct(u32) {
+ LAZY: bool = false,
+ NOW: bool = false,
+ _2: u6 = 0,
+ GLOBAL: bool = false,
+ TRACE: bool = false,
+ _10: u2 = 0,
+ NODELETE: bool = false,
+ NOLOAD: bool = false,
+ _: u18 = 0,
+ },
+ .haiku => packed struct(u32) {
+ NOW: bool = false,
+ GLOBAL: bool = false,
+ _: u30 = 0,
+ },
+ .netbsd => packed struct(u32) {
+ LAZY: bool = false,
+ NOW: bool = false,
+ _2: u6 = 0,
+ GLOBAL: bool = false,
+ LOCAL: bool = false,
+ _10: u2 = 0,
+ NODELETE: bool = false,
+ NOLOAD: bool = false,
+ _: u18 = 0,
+ },
+ .solaris, .illumos => packed struct(u32) {
+ LAZY: bool = false,
+ NOW: bool = false,
+ NOLOAD: bool = false,
+ _3: u5 = 0,
+ GLOBAL: bool = false,
+ PARENT: bool = false,
+ GROUP: bool = false,
+ WORLD: bool = false,
+ NODELETE: bool = false,
+ FIRST: bool = false,
+ _14: u2 = 0,
+ CONFGEN: bool = false,
+ _: u15 = 0,
+ },
+ .openbsd => packed struct(u32) {
+ LAZY: bool = false,
+ NOW: bool = false,
+ _2: u6 = 0,
+ GLOBAL: bool = false,
+ TRACE: bool = false,
+ _: u22 = 0,
+ },
+ .macos, .ios, .tvos, .watchos, .visionos => packed struct(u32) {
+ LAZY: bool = false,
+ NOW: bool = false,
+ LOCAL: bool = false,
+ GLOBAL: bool = false,
+ NOLOAD: bool = false,
+ _5: u2 = 0,
+ NODELETE: bool = false,
+ FIRST: bool = false,
+ _: u23 = 0,
+ },
+ else => void,
+};
+
+pub const dirent = switch (native_os) {
+ .linux, .emscripten => extern struct {
+ ino: c_uint,
+ off: c_uint,
+ reclen: c_ushort,
+ type: u8,
+ name: [256]u8,
+ },
+ .macos, .ios, .tvos, .watchos, .visionos => extern struct {
+ ino: u64,
+ seekoff: u64,
+ reclen: u16,
+ namlen: u16,
+ type: u8,
+ name: [1024]u8,
+ },
+ .freebsd, .kfreebsd => extern struct {
+ /// File number of entry.
+ fileno: ino_t,
+ /// Directory offset of entry.
+ off: off_t,
+ /// Length of this record.
+ reclen: u16,
+ /// File type, one of DT_.
+ type: u8,
+ pad0: u8 = 0,
+ /// Length of the name member.
+ namlen: u16,
+ pad1: u16 = 0,
+ /// Name of entry.
+ name: [255:0]u8,
+ },
+ .solaris, .illumos => extern struct {
+ /// Inode number of entry.
+ ino: ino_t,
+ /// Offset of this entry on disk.
+ off: off_t,
+ /// Length of this record.
+ reclen: u16,
+ /// File name.
+ name: [MAXNAMLEN:0]u8,
+ },
+ .netbsd => extern struct {
+ fileno: ino_t,
+ reclen: u16,
+ namlen: u16,
+ type: u8,
+ name: [MAXNAMLEN:0]u8,
+ },
+ .dragonfly => extern struct {
+ fileno: c_ulong,
+ namlen: u16,
+ type: u8,
+ unused1: u8,
+ unused2: u32,
+ name: [256]u8,
+
+ pub fn reclen(self: dirent) u16 {
+ return (@offsetOf(dirent, "name") + self.namlen + 1 + 7) & ~@as(u16, 7);
+ }
+ },
+ .openbsd => extern struct {
+ fileno: ino_t,
+ off: off_t,
+ reclen: u16,
+ type: u8,
+ namlen: u8,
+ _: u32 align(1) = 0,
+ name: [MAXNAMLEN:0]u8,
+ },
+ else => void,
+};
+pub const MAXNAMLEN = switch (native_os) {
+ .netbsd, .solaris, .illumos => 511,
+ .haiku => NAME_MAX,
+ .openbsd => 255,
+ else => {},
+};
+pub const dirent64 = switch (native_os) {
+ .linux => extern struct {
+ ino: c_ulong,
+ off: c_ulong,
+ reclen: c_ushort,
+ type: u8,
+ name: [256]u8,
+ },
+ else => void,
+};
+
+pub const AI = switch (native_os) {
+ .linux, .emscripten => linux.AI,
+ .dragonfly, .haiku, .freebsd, .kfreebsd => packed struct(u32) {
+ PASSIVE: bool = false,
+ CANONNAME: bool = false,
+ NUMERICHOST: bool = false,
+ NUMERICSERV: bool = false,
+ _4: u4 = 0,
+ ALL: bool = false,
+ V4MAPPED_CFG: bool = false,
+ ADDRCONFIG: bool = false,
+ V4MAPPED: bool = false,
+ _: u20 = 0,
+ },
+ .netbsd => packed struct(u32) {
+ PASSIVE: bool = false,
+ CANONNAME: bool = false,
+ NUMERICHOST: bool = false,
+ NUMERICSERV: bool = false,
+ _4: u6 = 0,
+ ADDRCONFIG: bool = false,
+ _: u21 = 0,
+ },
+ .solaris, .illumos => packed struct(u32) {
+ V4MAPPED: bool = false,
+ ALL: bool = false,
+ ADDRCONFIG: bool = false,
+ PASSIVE: bool = false,
+ CANONNAME: bool = false,
+ NUMERICHOST: bool = false,
+ NUMERICSERV: bool = false,
+ _: u25 = 0,
+ },
+ .openbsd => packed struct(u32) {
+ PASSIVE: bool = false,
+ CANONNAME: bool = false,
+ NUMERICHOST: bool = false,
+ _3: u1 = 0,
+ NUMERICSERV: bool = false,
+ _5: u1 = 0,
+ ADDRCONFIG: bool = false,
+ _: u25 = 0,
+ },
+ .macos, .ios, .tvos, .watchos, .visionos => packed struct(u32) {
+ PASSIVE: bool = false,
+ CANONNAME: bool = false,
+ NUMERICHOST: bool = false,
+ _3: u9 = 0,
+ NUMERICSERV: bool = false,
+ _: u19 = 0,
+ },
+ .windows => ws2_32.AI,
+ else => void,
+};
+
+pub const NI = switch (native_os) {
+ .linux, .emscripten => packed struct(u32) {
+ NUMERICHOST: bool = false,
+ NUMERICSERV: bool = false,
+ NOFQDN: bool = false,
+ NAMEREQD: bool = false,
+ DGRAM: bool = false,
+ _5: u3 = 0,
+ NUMERICSCOPE: bool = false,
+ _: u23 = 0,
+ },
+ .solaris, .illumos => packed struct(u32) {
+ NOFQDN: bool = false,
+ NUMERICHOST: bool = false,
+ NAMEREQD: bool = false,
+ NUMERICSERV: bool = false,
+ DGRAM: bool = false,
+ WITHSCOPEID: bool = false,
+ NUMERICSCOPE: bool = false,
+ _: u25 = 0,
+ },
+ else => void,
+};
+
+pub const EAI = switch (native_os) {
+ .linux, .emscripten => 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,
+
+ _,
+ },
+ .haiku, .dragonfly, .netbsd, .freebsd, .kfreebsd, .macos, .ios, .tvos, .watchos, .visionos => enum(c_int) {
+ /// address family for hostname not supported
+ ADDRFAMILY = 1,
+ /// temporary failure in name resolution
+ AGAIN = 2,
+ /// invalid value for ai_flags
+ BADFLAGS = 3,
+ /// non-recoverable failure in name resolution
+ FAIL = 4,
+ /// ai_family not supported
+ FAMILY = 5,
+ /// memory allocation failure
+ MEMORY = 6,
+ /// no address associated with hostname
+ NODATA = 7,
+ /// hostname nor servname provided, or not known
+ NONAME = 8,
+ /// servname not supported for ai_socktype
+ SERVICE = 9,
+ /// ai_socktype not supported
+ 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,
+ _,
+ },
+ .solaris, .illumos => enum(c_int) {
+ /// 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,
+ /// argument buffer overflow
+ OVERFLOW = 12,
+ /// resolved protocol is unknown
+ PROTOCOL = 13,
+
+ _,
+ },
+ .openbsd => enum(c_int) {
+ /// address family for hostname not supported
+ ADDRFAMILY = -9,
+ /// name could not be resolved at this time
+ AGAIN = -3,
+ /// flags parameter had an invalid value
+ BADFLAGS = -1,
+ /// non-recoverable failure in name resolution
+ FAIL = -4,
+ /// address family not recognized
+ FAMILY = -6,
+ /// memory allocation failure
+ MEMORY = -10,
+ /// no address associated with hostname
+ NODATA = -5,
+ /// name does not resolve
+ NONAME = -2,
+ /// service not recognized for socket type
+ SERVICE = -8,
+ /// intended socket type was not recognized
+ SOCKTYPE = -7,
+ /// system error returned in errno
+ SYSTEM = -11,
+ /// invalid value for hints
+ BADHINTS = -12,
+ /// resolved protocol is unknown
+ PROTOCOL = -13,
+ /// argument buffer overflow
+ OVERFLOW = -14,
+ _,
+ },
+ else => void,
+};
+
+pub const dl_iterate_phdr_callback = *const fn (info: *dl_phdr_info, size: usize, data: ?*anyopaque) callconv(.C) c_int;
+
+pub const Stat = switch (native_os) {
+ .linux => 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.
+ },
+ .emscripten => emscripten.Stat,
+ .wasi => 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(st: wasi.filestat_t) Stat {
+ return .{
+ .dev = st.dev,
+ .ino = st.ino,
+ .mode = switch (st.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 = st.nlink,
+ .size = @intCast(st.size),
+ .atim = timespec.fromTimestamp(st.atim),
+ .mtim = timespec.fromTimestamp(st.mtim),
+ .ctim = timespec.fromTimestamp(st.ctim),
+
+ .uid = 0,
+ .gid = 0,
+ .rdev = 0,
+ .blksize = 0,
+ .blocks = 0,
+ };
}
- };
-}
+ },
+ .macos, .ios, .tvos, .watchos, .visionos => extern struct {
+ dev: i32,
+ mode: u16,
+ nlink: u16,
+ ino: ino_t,
+ uid: uid_t,
+ gid: gid_t,
+ rdev: i32,
+ atimespec: timespec,
+ mtimespec: timespec,
+ ctimespec: timespec,
+ birthtimespec: timespec,
+ size: off_t,
+ blocks: i64,
+ blksize: i32,
+ flags: u32,
+ gen: u32,
+ lspare: i32,
+ qspare: [2]i64,
-pub usingnamespace switch (native_os) {
- .linux => @import("c/linux.zig"),
- .windows => @import("c/windows.zig"),
- .macos, .ios, .tvos, .watchos, .visionos => @import("c/darwin.zig"),
- .freebsd, .kfreebsd => @import("c/freebsd.zig"),
- .netbsd => @import("c/netbsd.zig"),
- .dragonfly => @import("c/dragonfly.zig"),
- .openbsd => @import("c/openbsd.zig"),
- .haiku => @import("c/haiku.zig"),
- .solaris, .illumos => @import("c/solaris.zig"),
- .emscripten => @import("c/emscripten.zig"),
- .wasi => wasi,
- else => struct {},
+ pub fn atime(self: @This()) timespec {
+ return self.atimespec;
+ }
+
+ pub fn mtime(self: @This()) timespec {
+ return self.mtimespec;
+ }
+
+ pub fn ctime(self: @This()) timespec {
+ return self.ctimespec;
+ }
+
+ pub fn birthtime(self: @This()) timespec {
+ return self.birthtimespec;
+ }
+ },
+ .freebsd, .kfreebsd => freebsd.Stat,
+ .solaris, .illumos => extern struct {
+ dev: dev_t,
+ ino: ino_t,
+ mode: mode_t,
+ nlink: nlink_t,
+ uid: uid_t,
+ gid: gid_t,
+ rdev: dev_t,
+ size: off_t,
+ atim: timespec,
+ mtim: timespec,
+ ctim: timespec,
+ blksize: blksize_t,
+ blocks: blkcnt_t,
+ fstype: [16]u8,
+
+ 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;
+ }
+ },
+ .netbsd => extern struct {
+ dev: dev_t,
+ mode: mode_t,
+ ino: ino_t,
+ nlink: nlink_t,
+ uid: uid_t,
+ gid: gid_t,
+ rdev: dev_t,
+ atim: timespec,
+ mtim: timespec,
+ ctim: timespec,
+ birthtim: timespec,
+ size: off_t,
+ blocks: blkcnt_t,
+ blksize: blksize_t,
+ flags: u32,
+ gen: u32,
+ __spare: [2]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;
+ }
+
+ pub fn birthtime(self: @This()) timespec {
+ return self.birthtim;
+ }
+ },
+ .dragonfly => extern struct {
+ ino: ino_t,
+ nlink: c_uint,
+ dev: c_uint,
+ mode: c_ushort,
+ padding1: u16,
+ uid: uid_t,
+ gid: gid_t,
+ rdev: c_uint,
+ atim: timespec,
+ mtim: timespec,
+ ctim: timespec,
+ size: c_ulong,
+ blocks: i64,
+ blksize: u32,
+ flags: u32,
+ gen: u32,
+ lspare: i32,
+ qspare1: i64,
+ qspare2: i64,
+ 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;
+ }
+ },
+ .haiku => 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;
+ }
+ },
+ .openbsd => extern struct {
+ mode: mode_t,
+ dev: dev_t,
+ ino: ino_t,
+ nlink: nlink_t,
+ uid: uid_t,
+ gid: gid_t,
+ rdev: dev_t,
+ atim: timespec,
+ mtim: timespec,
+ ctim: timespec,
+ size: off_t,
+ blocks: blkcnt_t,
+ blksize: blksize_t,
+ flags: u32,
+ gen: u32,
+ birthtim: timespec,
+
+ 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.birthtim;
+ }
+ },
+ else => void,
};
pub const pthread_mutex_t = switch (native_os) {
@@ -73,12 +6649,12 @@ pub const pthread_mutex_t = switch (native_os) {
inner: ?*anyopaque = null,
},
.hermit => extern struct {
- ptr: usize = std.math.maxInt(usize),
+ ptr: usize = maxInt(usize),
},
.netbsd => extern struct {
magic: u32 = 0x33330003,
- errorcheck: c.padded_pthread_spin_t = 0,
- ceiling: c.padded_pthread_spin_t = 0,
+ errorcheck: padded_pthread_spin_t = 0,
+ ceiling: padded_pthread_spin_t = 0,
owner: usize = 0,
waiters: ?*u8 = null,
recursed: u32 = 0,
@@ -106,7 +6682,7 @@ pub const pthread_mutex_t = switch (native_os) {
.emscripten => extern struct {
data: [24]u8 align(4) = [_]u8{0} ** 24,
},
- else => @compileError("target libc does not have pthread_mutex_t"),
+ else => void,
};
pub const pthread_cond_t = switch (native_os) {
@@ -122,11 +6698,11 @@ pub const pthread_cond_t = switch (native_os) {
inner: ?*anyopaque = null,
},
.hermit => extern struct {
- ptr: usize = std.math.maxInt(usize),
+ ptr: usize = maxInt(usize),
},
.netbsd => extern struct {
magic: u32 = 0x55550005,
- lock: c.pthread_spin_t = 0,
+ lock: pthread_spin_t = 0,
waiters_first: ?*u8 = null,
waiters_last: ?*u8 = null,
mutex: ?*pthread_mutex_t = null,
@@ -148,7 +6724,7 @@ pub const pthread_cond_t = switch (native_os) {
.fuchsia, .minix, .emscripten => extern struct {
data: [48]u8 align(@alignOf(usize)) = [_]u8{0} ** 48,
},
- else => @compileError("target libc does not have pthread_cond_t"),
+ else => void,
};
pub const pthread_rwlock_t = switch (native_os) {
@@ -174,7 +6750,7 @@ pub const pthread_rwlock_t = switch (native_os) {
ptr: ?*anyopaque = null,
},
.hermit => extern struct {
- ptr: usize = std.math.maxInt(usize),
+ ptr: usize = maxInt(usize),
},
.netbsd => extern struct {
magic: c_uint = 0x99990009,
@@ -205,7 +6781,185 @@ pub const pthread_rwlock_t = switch (native_os) {
.emscripten => extern struct {
size: [32]u8 align(4) = [_]u8{0} ** 32,
},
- else => @compileError("target libc does not have pthread_rwlock_t"),
+ else => void,
+};
+
+pub const pthread_attr_t = switch (native_os) {
+ .linux, .emscripten, .dragonfly => extern struct {
+ __size: [56]u8,
+ __align: c_long,
+ },
+ .macos, .ios, .tvos, .watchos, .visionos => extern struct {
+ __sig: c_long,
+ __opaque: [56]u8,
+ },
+ .freebsd, .kfreebsd => extern struct {
+ inner: ?*anyopaque = null,
+ },
+ .solaris, .illumos => extern struct {
+ mutexattr: ?*anyopaque = null,
+ },
+ .netbsd => extern struct {
+ magic: u32,
+ flags: i32,
+ private: ?*anyopaque,
+ },
+ .haiku => extern struct {
+ detach_state: i32,
+ sched_priority: i32,
+ stack_size: i32,
+ guard_size: i32,
+ stack_address: ?*anyopaque,
+ },
+ .openbsd => extern struct {
+ inner: ?*anyopaque = null,
+ },
+ else => void,
+};
+
+pub const pthread_key_t = switch (native_os) {
+ .linux, .emscripten => c_uint,
+ .openbsd, .solaris, .illumos => c_int,
+ else => void,
+};
+
+pub const padded_pthread_spin_t = switch (native_os) {
+ .netbsd => switch (builtin.cpu.arch) {
+ .x86, .x86_64 => u32,
+ .sparc, .sparcel, .sparc64 => u32,
+ else => pthread_spin_t,
+ },
+ else => void,
+};
+
+pub const pthread_spin_t = switch (native_os) {
+ .netbsd => switch (builtin.cpu.arch) {
+ .aarch64, .aarch64_be, .aarch64_32 => u8,
+ .mips, .mipsel, .mips64, .mips64el => u32,
+ .powerpc, .powerpc64, .powerpc64le => i32,
+ .x86, .x86_64 => u8,
+ .arm, .armeb, .thumb, .thumbeb => i32,
+ .sparc, .sparcel, .sparc64 => u8,
+ .riscv32, .riscv64 => u32,
+ else => @compileError("undefined pthread_spin_t for this arch"),
+ },
+ else => void,
+};
+
+pub const sem_t = switch (native_os) {
+ .linux, .emscripten => extern struct {
+ __size: [4 * @sizeOf(usize)]u8 align(@alignOf(usize)),
+ },
+ .macos, .ios, .tvos, .watchos, .visionos => c_int,
+ .freebsd, .kfreebsd => extern struct {
+ _magic: u32,
+ _kern: extern struct {
+ _count: u32,
+ _flags: u32,
+ },
+ _padding: u32,
+ },
+ .solaris, .illumos => extern struct {
+ count: u32 = 0,
+ type: u16 = 0,
+ magic: u16 = 0x534d,
+ __pad1: [3]u64 = [_]u64{0} ** 3,
+ __pad2: [2]u64 = [_]u64{0} ** 2,
+ },
+ .openbsd, .netbsd, .dragonfly => ?*opaque {},
+ .haiku => extern struct {
+ type: i32,
+ u: extern union {
+ named_sem_id: i32,
+ unnamed_sem: i32,
+ },
+ padding: [2]i32,
+ },
+ else => void,
+};
+
+/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.
+pub const Kevent = switch (native_os) {
+ .netbsd => extern struct {
+ ident: usize,
+ filter: i32,
+ flags: u32,
+ fflags: u32,
+ data: i64,
+ udata: usize,
+ },
+ .macos, .ios, .tvos, .watchos, .visionos => extern struct {
+ ident: usize,
+ filter: i16,
+ flags: u16,
+ fflags: u32,
+ data: isize,
+ udata: usize,
+
+ // sys/types.h on macos uses #pragma pack(4) so these checks are
+ // to make sure the struct is laid out the same. These values were
+ // produced from C code using the offsetof macro.
+ comptime {
+ assert(@offsetOf(@This(), "ident") == 0);
+ assert(@offsetOf(@This(), "filter") == 8);
+ assert(@offsetOf(@This(), "flags") == 10);
+ assert(@offsetOf(@This(), "fflags") == 12);
+ assert(@offsetOf(@This(), "data") == 16);
+ assert(@offsetOf(@This(), "udata") == 24);
+ }
+ },
+ .freebsd, .kfreebsd => extern struct {
+ /// Identifier for this event.
+ ident: usize,
+ /// Filter for event.
+ filter: i16,
+ /// Action flags for kqueue.
+ flags: u16,
+ /// Filter flag value.
+ fflags: u32,
+ /// Filter data value.
+ data: i64,
+ /// Opaque user data identifier.
+ udata: usize,
+ /// Future extensions.
+ _ext: [4]u64 = [_]u64{0} ** 4,
+ },
+ .dragonfly => extern struct {
+ ident: usize,
+ filter: c_short,
+ flags: c_ushort,
+ fflags: c_uint,
+ data: isize,
+ udata: usize,
+ },
+ .openbsd => extern struct {
+ ident: usize,
+ filter: c_short,
+ flags: u16,
+ fflags: c_uint,
+ data: i64,
+ udata: usize,
+ },
+ else => void,
+};
+
+pub const port_t = switch (native_os) {
+ .solaris, .illumos => c_int,
+ else => void,
+};
+
+pub const port_event = switch (native_os) {
+ .solaris, .illumos => extern struct {
+ events: u32,
+ /// Event source.
+ source: u16,
+ __pad: u16,
+ /// Source-specific object.
+ object: ?*anyopaque,
+ /// User cookie.
+ cookie: ?*anyopaque,
+ },
+ else => void,
};
pub const AT = switch (native_os) {
@@ -287,7 +7041,7 @@ pub const AT = switch (native_os) {
/// Magic value that specify the use of the current working directory
/// to determine the target of relative file paths in the openat() and
/// similar syscalls.
- pub const FDCWD: c.fd_t = @bitCast(@as(u32, 0xffd19553));
+ pub const FDCWD: fd_t = @bitCast(@as(u32, 0xffd19553));
/// Do not follow symbolic links
pub const SYMLINK_NOFOLLOW = 0x1000;
/// Follow symbolic link
@@ -320,10 +7074,10 @@ pub const AT = switch (native_os) {
/// current working directory is the first preopen. This behavior can be
/// overridden with a public function called `wasi_cwd` in the root source
/// file.
- pub const FDCWD: c.fd_t = if (builtin.link_libc) -2 else 3;
+ pub const FDCWD: fd_t = if (builtin.link_libc) -2 else 3;
},
- else => @compileError("target libc does not have AT"),
+ else => void,
};
pub const O = switch (native_os) {
@@ -511,7 +7265,7 @@ pub const O = switch (native_os) {
DIRECTORY: bool = false,
_: u4 = 0,
},
- .freebsd => packed struct(u32) {
+ .freebsd, .kfreebsd => packed struct(u32) {
ACCMODE: std.posix.ACCMODE = .RDONLY,
NONBLOCK: bool = false,
APPEND: bool = false,
@@ -535,7 +7289,7 @@ pub const O = switch (native_os) {
TMPFILE: bool = false,
_: u9 = 0,
},
- else => @compileError("target libc does not have O"),
+ else => void,
};
pub const MAP = switch (native_os) {
@@ -656,7 +7410,7 @@ pub const MAP = switch (native_os) {
SIZEALIGN: bool = false,
_: u13 = 0,
},
- .freebsd => packed struct(u32) {
+ .freebsd, .kfreebsd => packed struct(u32) {
TYPE: enum(u4) {
SHARED = 0x01,
PRIVATE = 0x02,
@@ -674,11 +7428,11 @@ pub const MAP = switch (native_os) {
@"32BIT": bool = false,
_: u12 = 0,
},
- else => @compileError("target libc does not have MAP"),
+ else => void,
};
/// Used by libc to communicate failure. Not actually part of the underlying syscall.
-pub const MAP_FAILED: *anyopaque = @ptrFromInt(std.math.maxInt(usize));
+pub const MAP_FAILED: *anyopaque = @ptrFromInt(maxInt(usize));
pub const cc_t = u8;
@@ -779,7 +7533,7 @@ pub const V = switch (native_os) {
LNEXT,
EOL2,
},
- else => @compileError("target libc does not have cc_t"),
+ else => void,
};
pub const NCCS = switch (native_os) {
@@ -788,7 +7542,7 @@ pub const NCCS = switch (native_os) {
.haiku => 11,
.solaris, .illumos => 19,
.emscripten, .wasi => 32,
- else => @compileError("target libc does not have NCCS"),
+ else => void,
};
pub const termios = switch (native_os) {
@@ -833,12 +7587,12 @@ pub const termios = switch (native_os) {
oflag: tc_oflag_t,
cflag: tc_cflag_t,
lflag: tc_lflag_t,
- line: std.c.cc_t,
+ line: cc_t,
cc: [NCCS]cc_t,
ispeed: speed_t,
ospeed: speed_t,
},
- else => @compileError("target libc does not have termios"),
+ else => void,
};
pub const tc_iflag_t = switch (native_os) {
@@ -948,7 +7702,7 @@ pub const tc_iflag_t = switch (native_os) {
IUTF8: bool = false,
_: u17 = 0,
},
- else => @compileError("target libc does not have tc_iflag_t"),
+ else => void,
};
pub const tc_oflag_t = switch (native_os) {
@@ -1039,7 +7793,7 @@ pub const tc_oflag_t = switch (native_os) {
FFDLY: u1 = 0,
_: u16 = 0,
},
- else => @compileError("target libc does not have tc_oflag_t"),
+ else => void,
};
pub const CSIZE = switch (native_os) {
@@ -1181,7 +7935,7 @@ pub const tc_cflag_t = switch (native_os) {
CLOCAL: bool = false,
_: u20 = 0,
},
- else => @compileError("target libc does not have tc_cflag_t"),
+ else => void,
};
pub const tc_lflag_t = switch (native_os) {
@@ -1307,7 +8061,7 @@ pub const tc_lflag_t = switch (native_os) {
IEXTEN: bool = false,
_: u16 = 0,
},
- else => @compileError("target libc does not have tc_lflag_t"),
+ else => void,
};
pub const speed_t = switch (native_os) {
@@ -1489,11 +8243,543 @@ pub const speed_t = switch (native_os) {
B3500000 = 0o0010016,
B4000000 = 0o0010017,
},
- else => @compileError("target libc does not have speed_t"),
+ else => void,
};
pub const whence_t = if (native_os == .wasi) std.os.wasi.whence_t else c_int;
+pub const sig_atomic_t = c_int;
+
+/// maximum signal number + 1
+pub const NSIG = switch (native_os) {
+ .linux => linux.NSIG,
+ .windows => 23,
+ .haiku => 65,
+ .netbsd, .freebsd, .kfreebsd => 32,
+ .solaris, .illumos => 75,
+ .openbsd => 33,
+ else => {},
+};
+
+pub const MINSIGSTKSZ = switch (native_os) {
+ .macos, .ios, .tvos, .watchos, .visionos => 32768,
+ .freebsd, .kfreebsd => switch (builtin.cpu.arch) {
+ .x86, .x86_64 => 2048,
+ .arm, .aarch64 => 4096,
+ else => @compileError("unsupported arch"),
+ },
+ .solaris, .illumos => 2048,
+ .haiku, .netbsd => 8192,
+ .openbsd => 1 << openbsd.MAX_PAGE_SHIFT,
+ else => {},
+};
+pub const SIGSTKSZ = switch (native_os) {
+ .macos, .ios, .tvos, .watchos, .visionos => 131072,
+ .netbsd, .freebsd, .kfreebsd => MINSIGSTKSZ + 32768,
+ .solaris, .illumos => 8192,
+ .haiku => 16384,
+ .openbsd => MINSIGSTKSZ + (1 << openbsd.MAX_PAGE_SHIFT) * 4,
+ else => {},
+};
+pub const SS = switch (native_os) {
+ .linux => linux.SS,
+ .openbsd, .macos, .ios, .tvos, .watchos, .visionos, .netbsd, .freebsd, .kfreebsd => struct {
+ pub const ONSTACK = 1;
+ pub const DISABLE = 4;
+ },
+ .haiku, .solaris, .illumos => struct {
+ pub const ONSTACK = 0x1;
+ pub const DISABLE = 0x2;
+ },
+ else => void,
+};
+
+pub const EV = switch (native_os) {
+ .macos, .ios, .tvos, .watchos, .visionos => struct {
+ /// add event to kq (implies enable)
+ pub const ADD = 0x0001;
+ /// delete event from kq
+ pub const DELETE = 0x0002;
+ /// enable event
+ pub const ENABLE = 0x0004;
+ /// disable event (not reported)
+ pub const DISABLE = 0x0008;
+ /// only report one occurrence
+ pub const ONESHOT = 0x0010;
+ /// clear event state after reporting
+ pub const CLEAR = 0x0020;
+ /// force immediate event output
+ /// ... with or without ERROR
+ /// ... use KEVENT_FLAG_ERROR_EVENTS
+ /// on syscalls supporting flags
+ pub const RECEIPT = 0x0040;
+ /// disable event after reporting
+ pub const DISPATCH = 0x0080;
+ /// unique kevent per udata value
+ pub const UDATA_SPECIFIC = 0x0100;
+ /// ... in combination with DELETE
+ /// will defer delete until udata-specific
+ /// event enabled. EINPROGRESS will be
+ /// returned to indicate the deferral
+ pub const DISPATCH2 = DISPATCH | UDATA_SPECIFIC;
+ /// report that source has vanished
+ /// ... only valid with DISPATCH2
+ pub const VANISHED = 0x0200;
+ /// reserved by system
+ pub const SYSFLAGS = 0xF000;
+ /// filter-specific flag
+ pub const FLAG0 = 0x1000;
+ /// filter-specific flag
+ pub const FLAG1 = 0x2000;
+ /// EOF detected
+ pub const EOF = 0x8000;
+ /// error, data contains errno
+ pub const ERROR = 0x4000;
+ pub const POLL = FLAG0;
+ pub const OOBAND = FLAG1;
+ },
+ .dragonfly => struct {
+ pub const ADD = 1;
+ pub const DELETE = 2;
+ pub const ENABLE = 4;
+ pub const DISABLE = 8;
+ pub const ONESHOT = 16;
+ pub const CLEAR = 32;
+ pub const RECEIPT = 64;
+ pub const DISPATCH = 128;
+ pub const NODATA = 4096;
+ pub const FLAG1 = 8192;
+ pub const ERROR = 16384;
+ pub const EOF = 32768;
+ pub const SYSFLAGS = 61440;
+ },
+ .netbsd => struct {
+ /// add event to kq (implies enable)
+ pub const ADD = 0x0001;
+ /// delete event from kq
+ pub const DELETE = 0x0002;
+ /// enable event
+ pub const ENABLE = 0x0004;
+ /// disable event (not reported)
+ pub const DISABLE = 0x0008;
+ /// only report one occurrence
+ pub const ONESHOT = 0x0010;
+ /// clear event state after reporting
+ pub const CLEAR = 0x0020;
+ /// force immediate event output
+ /// ... with or without ERROR
+ /// ... use KEVENT_FLAG_ERROR_EVENTS
+ /// on syscalls supporting flags
+ pub const RECEIPT = 0x0040;
+ /// disable event after reporting
+ pub const DISPATCH = 0x0080;
+ },
+ .freebsd => struct {
+ /// add event to kq (implies enable)
+ pub const ADD = 0x0001;
+ /// delete event from kq
+ pub const DELETE = 0x0002;
+ /// enable event
+ pub const ENABLE = 0x0004;
+ /// disable event (not reported)
+ pub const DISABLE = 0x0008;
+ /// only report one occurrence
+ pub const ONESHOT = 0x0010;
+ /// clear event state after reporting
+ pub const CLEAR = 0x0020;
+ /// error, event data contains errno
+ pub const ERROR = 0x4000;
+ /// force immediate event output
+ /// ... with or without ERROR
+ /// ... use KEVENT_FLAG_ERROR_EVENTS
+ /// on syscalls supporting flags
+ pub const RECEIPT = 0x0040;
+ /// disable event after reporting
+ pub const DISPATCH = 0x0080;
+ },
+ .openbsd => struct {
+ pub const ADD = 0x0001;
+ pub const DELETE = 0x0002;
+ pub const ENABLE = 0x0004;
+ pub const DISABLE = 0x0008;
+ pub const ONESHOT = 0x0010;
+ pub const CLEAR = 0x0020;
+ pub const RECEIPT = 0x0040;
+ pub const DISPATCH = 0x0080;
+ pub const FLAG1 = 0x2000;
+ pub const ERROR = 0x4000;
+ pub const EOF = 0x8000;
+ },
+ .haiku => struct {
+ /// add event to kq (implies enable)
+ pub const ADD = 0x0001;
+ /// delete event from kq
+ pub const DELETE = 0x0002;
+ /// enable event
+ pub const ENABLE = 0x0004;
+ /// disable event (not reported)
+ pub const DISABLE = 0x0008;
+ /// only report one occurrence
+ pub const ONESHOT = 0x0010;
+ /// clear event state after reporting
+ pub const CLEAR = 0x0020;
+ /// force immediate event output
+ /// ... with or without ERROR
+ /// ... use KEVENT_FLAG_ERROR_EVENTS
+ /// on syscalls supporting flags
+ pub const RECEIPT = 0x0040;
+ /// disable event after reporting
+ pub const DISPATCH = 0x0080;
+ },
+ else => void,
+};
+
+pub const EVFILT = switch (native_os) {
+ .macos, .ios, .tvos, .watchos, .visionos => struct {
+ pub const READ = -1;
+ pub const WRITE = -2;
+ /// attached to aio requests
+ pub const AIO = -3;
+ /// attached to vnodes
+ pub const VNODE = -4;
+ /// attached to struct proc
+ pub const PROC = -5;
+ /// attached to struct proc
+ pub const SIGNAL = -6;
+ /// timers
+ pub const TIMER = -7;
+ /// Mach portsets
+ pub const MACHPORT = -8;
+ /// Filesystem events
+ pub const FS = -9;
+ /// User events
+ pub const USER = -10;
+ /// Virtual memory events
+ pub const VM = -12;
+ /// Exception events
+ pub const EXCEPT = -15;
+ pub const SYSCOUNT = 17;
+ },
+ .haiku => struct {
+ pub const READ = -1;
+ pub const WRITE = -2;
+ /// attached to aio requests
+ pub const AIO = -3;
+ /// attached to vnodes
+ pub const VNODE = -4;
+ /// attached to struct proc
+ pub const PROC = -5;
+ /// attached to struct proc
+ pub const SIGNAL = -6;
+ /// timers
+ pub const TIMER = -7;
+ /// Process descriptors
+ pub const PROCDESC = -8;
+ /// Filesystem events
+ pub const FS = -9;
+ pub const LIO = -10;
+ /// User events
+ pub const USER = -11;
+ /// Sendfile events
+ pub const SENDFILE = -12;
+ pub const EMPTY = -13;
+ },
+ .dragonfly => struct {
+ pub const FS = -10;
+ pub const USER = -9;
+ pub const EXCEPT = -8;
+ pub const TIMER = -7;
+ pub const SIGNAL = -6;
+ pub const PROC = -5;
+ pub const VNODE = -4;
+ pub const AIO = -3;
+ pub const WRITE = -2;
+ pub const READ = -1;
+ pub const SYSCOUNT = 10;
+ pub const MARKER = 15;
+ },
+ .netbsd => struct {
+ pub const READ = 0;
+ pub const WRITE = 1;
+ /// attached to aio requests
+ pub const AIO = 2;
+ /// attached to vnodes
+ pub const VNODE = 3;
+ /// attached to struct proc
+ pub const PROC = 4;
+ /// attached to struct proc
+ pub const SIGNAL = 5;
+ /// timers
+ pub const TIMER = 6;
+ /// Filesystem events
+ pub const FS = 7;
+ /// User events
+ pub const USER = 1;
+ },
+ .freebsd => struct {
+ pub const READ = -1;
+ pub const WRITE = -2;
+ /// attached to aio requests
+ pub const AIO = -3;
+ /// attached to vnodes
+ pub const VNODE = -4;
+ /// attached to struct proc
+ pub const PROC = -5;
+ /// attached to struct proc
+ pub const SIGNAL = -6;
+ /// timers
+ pub const TIMER = -7;
+ /// Process descriptors
+ pub const PROCDESC = -8;
+ /// Filesystem events
+ pub const FS = -9;
+ pub const LIO = -10;
+ /// User events
+ pub const USER = -11;
+ /// Sendfile events
+ pub const SENDFILE = -12;
+ pub const EMPTY = -13;
+ },
+ .openbsd => struct {
+ pub const READ = -1;
+ pub const WRITE = -2;
+ pub const AIO = -3;
+ pub const VNODE = -4;
+ pub const PROC = -5;
+ pub const SIGNAL = -6;
+ pub const TIMER = -7;
+ pub const EXCEPT = -9;
+ },
+ else => void,
+};
+
+pub const NOTE = switch (native_os) {
+ .macos, .ios, .tvos, .watchos, .visionos => struct {
+ /// On input, TRIGGER causes the event to be triggered for output.
+ pub const TRIGGER = 0x01000000;
+ /// ignore input fflags
+ pub const FFNOP = 0x00000000;
+ /// and fflags
+ pub const FFAND = 0x40000000;
+ /// or fflags
+ pub const FFOR = 0x80000000;
+ /// copy fflags
+ pub const FFCOPY = 0xc0000000;
+ /// mask for operations
+ pub const FFCTRLMASK = 0xc0000000;
+ pub const FFLAGSMASK = 0x00ffffff;
+ /// low water mark
+ pub const LOWAT = 0x00000001;
+ /// OOB data
+ pub const OOB = 0x00000002;
+ /// vnode was removed
+ pub const DELETE = 0x00000001;
+ /// data contents changed
+ pub const WRITE = 0x00000002;
+ /// size increased
+ pub const EXTEND = 0x00000004;
+ /// attributes changed
+ pub const ATTRIB = 0x00000008;
+ /// link count changed
+ pub const LINK = 0x00000010;
+ /// vnode was renamed
+ pub const RENAME = 0x00000020;
+ /// vnode access was revoked
+ pub const REVOKE = 0x00000040;
+ /// No specific vnode event: to test for EVFILT_READ activation
+ pub const NONE = 0x00000080;
+ /// vnode was unlocked by flock(2)
+ pub const FUNLOCK = 0x00000100;
+ /// process exited
+ pub const EXIT = 0x80000000;
+ /// process forked
+ pub const FORK = 0x40000000;
+ /// process exec'd
+ pub const EXEC = 0x20000000;
+ /// shared with EVFILT_SIGNAL
+ pub const SIGNAL = 0x08000000;
+ /// exit status to be returned, valid for child process only
+ pub const EXITSTATUS = 0x04000000;
+ /// provide details on reasons for exit
+ pub const EXIT_DETAIL = 0x02000000;
+ /// mask for signal & exit status
+ pub const PDATAMASK = 0x000fffff;
+ pub const PCTRLMASK = (~PDATAMASK);
+ pub const EXIT_DETAIL_MASK = 0x00070000;
+ pub const EXIT_DECRYPTFAIL = 0x00010000;
+ pub const EXIT_MEMORY = 0x00020000;
+ pub const EXIT_CSERROR = 0x00040000;
+ /// will react on memory pressure
+ pub const VM_PRESSURE = 0x80000000;
+ /// will quit on memory pressure, possibly after cleaning up dirty state
+ pub const VM_PRESSURE_TERMINATE = 0x40000000;
+ /// will quit immediately on memory pressure
+ pub const VM_PRESSURE_SUDDEN_TERMINATE = 0x20000000;
+ /// there was an error
+ pub const VM_ERROR = 0x10000000;
+ /// data is seconds
+ pub const SECONDS = 0x00000001;
+ /// data is microseconds
+ pub const USECONDS = 0x00000002;
+ /// data is nanoseconds
+ pub const NSECONDS = 0x00000004;
+ /// absolute timeout
+ pub const ABSOLUTE = 0x00000008;
+ /// ext[1] holds leeway for power aware timers
+ pub const LEEWAY = 0x00000010;
+ /// system does minimal timer coalescing
+ pub const CRITICAL = 0x00000020;
+ /// system does maximum timer coalescing
+ pub const BACKGROUND = 0x00000040;
+ pub const MACH_CONTINUOUS_TIME = 0x00000080;
+ /// data is mach absolute time units
+ pub const MACHTIME = 0x00000100;
+ },
+ .dragonfly => struct {
+ pub const FFNOP = 0;
+ pub const TRACK = 1;
+ pub const DELETE = 1;
+ pub const LOWAT = 1;
+ pub const TRACKERR = 2;
+ pub const OOB = 2;
+ pub const WRITE = 2;
+ pub const EXTEND = 4;
+ pub const CHILD = 4;
+ pub const ATTRIB = 8;
+ pub const LINK = 16;
+ pub const RENAME = 32;
+ pub const REVOKE = 64;
+ pub const PDATAMASK = 1048575;
+ pub const FFLAGSMASK = 16777215;
+ pub const TRIGGER = 16777216;
+ pub const EXEC = 536870912;
+ pub const FFAND = 1073741824;
+ pub const FORK = 1073741824;
+ pub const EXIT = 2147483648;
+ pub const FFOR = 2147483648;
+ pub const FFCTRLMASK = 3221225472;
+ pub const FFCOPY = 3221225472;
+ pub const PCTRLMASK = 4026531840;
+ },
+ .netbsd => struct {
+ /// On input, TRIGGER causes the event to be triggered for output.
+ pub const TRIGGER = 0x08000000;
+ /// low water mark
+ pub const LOWAT = 0x00000001;
+ /// vnode was removed
+ pub const DELETE = 0x00000001;
+ /// data contents changed
+ pub const WRITE = 0x00000002;
+ /// size increased
+ pub const EXTEND = 0x00000004;
+ /// attributes changed
+ pub const ATTRIB = 0x00000008;
+ /// link count changed
+ pub const LINK = 0x00000010;
+ /// vnode was renamed
+ pub const RENAME = 0x00000020;
+ /// vnode access was revoked
+ pub const REVOKE = 0x00000040;
+ /// process exited
+ pub const EXIT = 0x80000000;
+ /// process forked
+ pub const FORK = 0x40000000;
+ /// process exec'd
+ pub const EXEC = 0x20000000;
+ /// mask for signal & exit status
+ pub const PDATAMASK = 0x000fffff;
+ pub const PCTRLMASK = 0xf0000000;
+ },
+ .freebsd => struct {
+ /// On input, TRIGGER causes the event to be triggered for output.
+ pub const TRIGGER = 0x01000000;
+ /// ignore input fflags
+ pub const FFNOP = 0x00000000;
+ /// and fflags
+ pub const FFAND = 0x40000000;
+ /// or fflags
+ pub const FFOR = 0x80000000;
+ /// copy fflags
+ pub const FFCOPY = 0xc0000000;
+ /// mask for operations
+ pub const FFCTRLMASK = 0xc0000000;
+ pub const FFLAGSMASK = 0x00ffffff;
+ /// low water mark
+ pub const LOWAT = 0x00000001;
+ /// behave like poll()
+ pub const FILE_POLL = 0x00000002;
+ /// vnode was removed
+ pub const DELETE = 0x00000001;
+ /// data contents changed
+ pub const WRITE = 0x00000002;
+ /// size increased
+ pub const EXTEND = 0x00000004;
+ /// attributes changed
+ pub const ATTRIB = 0x00000008;
+ /// link count changed
+ pub const LINK = 0x00000010;
+ /// vnode was renamed
+ pub const RENAME = 0x00000020;
+ /// vnode access was revoked
+ pub const REVOKE = 0x00000040;
+ /// vnode was opened
+ pub const OPEN = 0x00000080;
+ /// file closed, fd did not allow write
+ pub const CLOSE = 0x00000100;
+ /// file closed, fd did allow write
+ pub const CLOSE_WRITE = 0x00000200;
+ /// file was read
+ pub const READ = 0x00000400;
+ /// process exited
+ pub const EXIT = 0x80000000;
+ /// process forked
+ pub const FORK = 0x40000000;
+ /// process exec'd
+ pub const EXEC = 0x20000000;
+ /// mask for signal & exit status
+ pub const PDATAMASK = 0x000fffff;
+ pub const PCTRLMASK = (~PDATAMASK);
+ /// data is seconds
+ pub const SECONDS = 0x00000001;
+ /// data is milliseconds
+ pub const MSECONDS = 0x00000002;
+ /// data is microseconds
+ pub const USECONDS = 0x00000004;
+ /// data is nanoseconds
+ pub const NSECONDS = 0x00000008;
+ /// timeout is absolute
+ pub const ABSTIME = 0x00000010;
+ },
+ .openbsd => struct {
+ // data/hint flags for EVFILT.{READ|WRITE}
+ pub const LOWAT = 0x0001;
+ pub const EOF = 0x0002;
+ // data/hint flags for EVFILT.EXCEPT and EVFILT.{READ|WRITE}
+ pub const OOB = 0x0004;
+ // data/hint flags for EVFILT.VNODE
+ pub const DELETE = 0x0001;
+ pub const WRITE = 0x0002;
+ pub const EXTEND = 0x0004;
+ pub const ATTRIB = 0x0008;
+ pub const LINK = 0x0010;
+ pub const RENAME = 0x0020;
+ pub const REVOKE = 0x0040;
+ pub const TRUNCATE = 0x0080;
+ // data/hint flags for EVFILT.PROC
+ pub const EXIT = 0x80000000;
+ pub const FORK = 0x40000000;
+ pub const EXEC = 0x20000000;
+ pub const PDATAMASK = 0x000fffff;
+ pub const PCTRLMASK = 0xf0000000;
+ pub const TRACK = 0x00000001;
+ pub const TRACKERR = 0x00000002;
+ pub const CHILD = 0x00000004;
+ // data/hint flags for EVFILT.DEVICE
+ pub const CHANGE = 0x00000001;
+ },
+ else => void,
+};
+
// Unix-like systems
pub const DIR = opaque {};
pub extern "c" fn opendir(pathname: [*:0]const u8) ?*DIR;
@@ -1503,10 +8789,15 @@ pub extern "c" fn closedir(dp: *DIR) c_int;
pub extern "c" fn telldir(dp: *DIR) c_long;
pub extern "c" fn seekdir(dp: *DIR, loc: c_long) void;
-pub extern "c" fn sigwait(set: ?*c.sigset_t, sig: ?*c_int) c_int;
+pub extern "c" fn sigwait(set: ?*sigset_t, sig: ?*c_int) c_int;
pub extern "c" fn alarm(seconds: c_uint) c_uint;
+pub const close = switch (native_os) {
+ .macos, .ios, .tvos, .watchos, .visionos => darwin.@"close$NOCANCEL",
+ else => private.close,
+};
+
pub const clock_getres = switch (native_os) {
.netbsd => private.__clock_getres50,
else => private.clock_getres,
@@ -1534,11 +8825,117 @@ pub const fstatat = switch (native_os) {
else => private.fstatat,
};
+pub extern "c" fn getpwnam(name: [*:0]const u8) ?*passwd;
+pub extern "c" fn getpwuid(uid: uid_t) ?*passwd;
+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: O, ...) c_int;
+pub extern "c" fn openat64(fd: c_int, path: [*:0]const u8, oflag: 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 const arc4random_buf = switch (native_os) {
+ .dragonfly, .netbsd, .freebsd, .solaris, .openbsd, .macos, .ios, .tvos, .watchos, .visionos => private.arc4random_buf,
+ else => {},
+};
+pub const getentropy = switch (native_os) {
+ .emscripten => private.getentropy,
+ else => {},
+};
+pub const getrandom = switch (native_os) {
+ .freebsd => private.getrandom,
+ .linux => if (versionCheck(.{ .major = 2, .minor = 25, .patch = 0 })) private.getrandom else {},
+ else => {},
+};
+
+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 timerfd_create(clockid: clockid_t, 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;
+
+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;
+
+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 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 ftruncate64(fd: c_int, length: off_t) c_int;
+pub extern "c" fn fallocate(fd: fd_t, mode: c_int, offset: off_t, len: off_t) c_int;
+pub const sendfile = switch (native_os) {
+ .freebsd, .kfreebsd => freebsd.sendfile,
+ .macos, .ios, .tvos, .watchos, .visionos => darwin.sendfile,
+ .linux => private.sendfile,
+ else => {},
+};
+/// See std.elf for constants for this
+pub extern "c" fn getauxval(__type: c_ulong) c_ulong;
+
+pub extern "c" fn dl_iterate_phdr(callback: dl_iterate_phdr_callback, data: ?*anyopaque) c_int;
+
+pub const sigaltstack = switch (native_os) {
+ .netbsd => private.__sigaltstack14,
+ else => private.sigaltstack,
+};
+
+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: O) c_int;
+
+pub const copy_file_range = switch (native_os) {
+ .linux => private.copy_file_range,
+ .freebsd, .kfreebsd => freebsd.copy_file_range,
+ else => {},
+};
+
+pub extern "c" fn signalfd(fd: fd_t, mask: *const sigset_t, flags: u32) 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 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: u32,
+) c_int;
+
pub const getdirentries = switch (native_os) {
.macos, .ios, .tvos, .watchos, .visionos => private.__getdirentries64,
else => private.getdirentries,
};
+pub const getdents = switch (native_os) {
+ .netbsd => private.__getdents30,
+ else => private.getdents,
+};
+
pub const getrusage = switch (native_os) {
.netbsd => private.__getrusage50,
else => private.getrusage,
@@ -1564,7 +8961,7 @@ pub const readdir = switch (native_os) {
.x86_64 => private.@"readdir$INODE64",
else => private.readdir,
},
- .windows => @compileError("not available"),
+ .windows => {},
else => private.readdir,
};
@@ -1606,6 +9003,33 @@ pub const stat = switch (native_os) {
else => private.stat,
};
+pub const _msize = switch (native_os) {
+ .windows => private._msize,
+ else => {},
+};
+pub const malloc_size = switch (native_os) {
+ .macos, .ios, .tvos, .watchos, .visionos => private.malloc_size,
+ else => {},
+};
+pub const malloc_usable_size = switch (native_os) {
+ .freebsd, .linux => private.malloc_usable_size,
+ else => {},
+};
+pub const posix_memalign = switch (native_os) {
+ .dragonfly, .netbsd, .freebsd, .solaris, .openbsd, .linux, .macos, .ios, .tvos, .watchos, .visionos => private.posix_memalign,
+ else => {},
+};
+
+pub const sf_hdtr = switch (native_os) {
+ .freebsd, .macos, .ios, .tvos, .watchos, .visionos => extern struct {
+ headers: [*]const iovec_const,
+ hdr_cnt: c_int,
+ trailers: [*]const iovec_const,
+ trl_cnt: c_int,
+ },
+ else => void,
+};
+
pub extern "c" var environ: [*:null]?[*:0]u8;
pub extern "c" fn fopen(noalias filename: [*:0]const u8, noalias modes: [*:0]const u8) ?*FILE;
@@ -1617,228 +9041,258 @@ pub extern "c" fn printf(format: [*:0]const u8, ...) c_int;
pub extern "c" fn abort() noreturn;
pub extern "c" fn exit(code: c_int) noreturn;
pub extern "c" fn _exit(code: c_int) noreturn;
-pub extern "c" fn isatty(fd: c.fd_t) c_int;
-pub extern "c" fn close(fd: c.fd_t) c_int;
-pub extern "c" fn lseek(fd: c.fd_t, offset: c.off_t, whence: whence_t) c.off_t;
+pub extern "c" fn isatty(fd: fd_t) c_int;
+pub extern "c" fn lseek(fd: fd_t, offset: off_t, whence: whence_t) off_t;
pub extern "c" fn open(path: [*:0]const u8, oflag: O, ...) c_int;
pub extern "c" fn openat(fd: c_int, path: [*:0]const u8, oflag: O, ...) c_int;
-pub extern "c" fn ftruncate(fd: c_int, length: c.off_t) c_int;
+pub extern "c" fn ftruncate(fd: c_int, length: off_t) c_int;
pub extern "c" fn raise(sig: c_int) c_int;
-pub extern "c" fn read(fd: c.fd_t, buf: [*]u8, nbyte: usize) isize;
+pub extern "c" fn read(fd: fd_t, buf: [*]u8, nbyte: usize) isize;
pub extern "c" fn readv(fd: c_int, iov: [*]const iovec, iovcnt: c_uint) isize;
-pub extern "c" fn pread(fd: c.fd_t, buf: [*]u8, nbyte: usize, offset: c.off_t) isize;
-pub extern "c" fn preadv(fd: c_int, iov: [*]const iovec, iovcnt: c_uint, offset: c.off_t) isize;
+pub extern "c" fn pread(fd: fd_t, buf: [*]u8, nbyte: usize, offset: off_t) isize;
+pub extern "c" fn preadv(fd: c_int, iov: [*]const iovec, iovcnt: c_uint, offset: off_t) isize;
pub extern "c" fn writev(fd: c_int, iov: [*]const iovec_const, iovcnt: c_uint) isize;
-pub extern "c" fn pwritev(fd: c_int, iov: [*]const iovec_const, iovcnt: c_uint, offset: c.off_t) isize;
-pub extern "c" fn write(fd: c.fd_t, buf: [*]const u8, nbyte: usize) isize;
-pub extern "c" fn pwrite(fd: c.fd_t, buf: [*]const u8, nbyte: usize, offset: c.off_t) isize;
-pub extern "c" fn mmap(addr: ?*align(page_size) anyopaque, len: usize, prot: c_uint, flags: MAP, fd: c.fd_t, offset: c.off_t) *anyopaque;
+pub extern "c" fn pwritev(fd: c_int, iov: [*]const iovec_const, iovcnt: c_uint, offset: off_t) isize;
+pub extern "c" fn write(fd: fd_t, buf: [*]const u8, nbyte: usize) isize;
+pub extern "c" fn pwrite(fd: fd_t, buf: [*]const u8, nbyte: usize, offset: off_t) isize;
+pub extern "c" fn mmap(addr: ?*align(page_size) anyopaque, len: usize, prot: c_uint, flags: MAP, fd: fd_t, offset: off_t) *anyopaque;
pub extern "c" fn munmap(addr: *align(page_size) const anyopaque, len: usize) c_int;
pub extern "c" fn mprotect(addr: *align(page_size) anyopaque, len: usize, prot: c_uint) c_int;
pub extern "c" fn link(oldpath: [*:0]const u8, newpath: [*:0]const u8, flags: c_int) c_int;
-pub extern "c" fn linkat(oldfd: c.fd_t, oldpath: [*:0]const u8, newfd: c.fd_t, newpath: [*:0]const u8, flags: c_int) c_int;
+pub extern "c" fn linkat(oldfd: fd_t, oldpath: [*:0]const u8, newfd: fd_t, newpath: [*:0]const u8, flags: c_int) c_int;
pub extern "c" fn unlink(path: [*:0]const u8) c_int;
-pub extern "c" fn unlinkat(dirfd: c.fd_t, path: [*:0]const u8, flags: c_uint) c_int;
+pub extern "c" fn unlinkat(dirfd: fd_t, path: [*:0]const u8, flags: c_uint) c_int;
pub extern "c" fn getcwd(buf: [*]u8, size: usize) ?[*]u8;
-pub extern "c" fn waitpid(pid: c.pid_t, status: ?*c_int, options: c_int) c.pid_t;
-pub extern "c" fn wait4(pid: c.pid_t, status: ?*c_int, options: c_int, ru: ?*c.rusage) c.pid_t;
-pub extern "c" fn fork() c_int;
+pub extern "c" fn waitpid(pid: pid_t, status: ?*c_int, options: c_int) pid_t;
+pub extern "c" fn wait4(pid: pid_t, status: ?*c_int, options: c_int, ru: ?*rusage) pid_t;
+pub const fork = switch (native_os) {
+ .dragonfly,
+ .freebsd,
+ .ios,
+ .kfreebsd,
+ .linux,
+ .macos,
+ .netbsd,
+ .openbsd,
+ .solaris,
+ .illumos,
+ .tvos,
+ .watchos,
+ .visionos,
+ .haiku,
+ => private.fork,
+ else => {},
+};
pub extern "c" fn access(path: [*:0]const u8, mode: c_uint) c_int;
-pub extern "c" fn faccessat(dirfd: c.fd_t, path: [*:0]const u8, mode: c_uint, flags: c_uint) c_int;
-pub extern "c" fn pipe(fds: *[2]c.fd_t) c_int;
+pub extern "c" fn faccessat(dirfd: fd_t, path: [*:0]const u8, mode: c_uint, flags: c_uint) c_int;
+pub extern "c" fn pipe(fds: *[2]fd_t) c_int;
pub extern "c" fn mkdir(path: [*:0]const u8, mode: c_uint) c_int;
-pub extern "c" fn mkdirat(dirfd: c.fd_t, path: [*:0]const u8, mode: u32) c_int;
+pub extern "c" fn mkdirat(dirfd: fd_t, path: [*:0]const u8, mode: u32) c_int;
pub extern "c" fn symlink(existing: [*:0]const u8, new: [*:0]const u8) c_int;
-pub extern "c" fn symlinkat(oldpath: [*:0]const u8, newdirfd: c.fd_t, newpath: [*:0]const u8) c_int;
+pub extern "c" fn symlinkat(oldpath: [*:0]const u8, newdirfd: fd_t, newpath: [*:0]const u8) c_int;
pub extern "c" fn rename(old: [*:0]const u8, new: [*:0]const u8) c_int;
-pub extern "c" fn renameat(olddirfd: c.fd_t, old: [*:0]const u8, newdirfd: c.fd_t, new: [*:0]const u8) c_int;
+pub extern "c" fn renameat(olddirfd: fd_t, old: [*:0]const u8, newdirfd: fd_t, new: [*:0]const u8) c_int;
pub extern "c" fn chdir(path: [*:0]const u8) c_int;
-pub extern "c" fn fchdir(fd: c.fd_t) c_int;
+pub extern "c" fn fchdir(fd: fd_t) c_int;
pub extern "c" fn execve(path: [*:0]const u8, argv: [*:null]const ?[*:0]const u8, envp: [*:null]const ?[*:0]const u8) c_int;
-pub extern "c" fn dup(fd: c.fd_t) c_int;
-pub extern "c" fn dup2(old_fd: c.fd_t, new_fd: c.fd_t) c_int;
+pub extern "c" fn dup(fd: fd_t) c_int;
+pub extern "c" fn dup2(old_fd: fd_t, new_fd: fd_t) c_int;
+pub extern "c" fn dup3(old: c_int, new: c_int, flags: c_uint) c_int;
pub extern "c" fn readlink(noalias path: [*:0]const u8, noalias buf: [*]u8, bufsize: usize) isize;
-pub extern "c" fn readlinkat(dirfd: c.fd_t, noalias path: [*:0]const u8, noalias buf: [*]u8, bufsize: usize) isize;
-pub extern "c" fn chmod(path: [*:0]const u8, mode: c.mode_t) c_int;
-pub extern "c" fn fchmod(fd: c.fd_t, mode: c.mode_t) c_int;
-pub extern "c" fn fchmodat(fd: c.fd_t, path: [*:0]const u8, mode: c.mode_t, flags: c_uint) c_int;
-pub extern "c" fn fchown(fd: c.fd_t, owner: c.uid_t, group: c.gid_t) c_int;
-pub extern "c" fn umask(mode: c.mode_t) c.mode_t;
+pub extern "c" fn readlinkat(dirfd: fd_t, noalias path: [*:0]const u8, noalias buf: [*]u8, bufsize: usize) isize;
+pub extern "c" fn chmod(path: [*:0]const u8, mode: mode_t) c_int;
+pub extern "c" fn fchmod(fd: fd_t, mode: mode_t) c_int;
+pub extern "c" fn fchmodat(fd: fd_t, path: [*:0]const u8, mode: mode_t, flags: c_uint) c_int;
+pub extern "c" fn fchown(fd: fd_t, owner: uid_t, group: gid_t) c_int;
+pub extern "c" fn umask(mode: mode_t) mode_t;
pub extern "c" fn rmdir(path: [*:0]const u8) c_int;
pub extern "c" fn getenv(name: [*:0]const u8) ?[*:0]u8;
pub extern "c" fn sysctl(name: [*]const c_int, namelen: c_uint, oldp: ?*anyopaque, oldlenp: ?*usize, newp: ?*anyopaque, newlen: usize) c_int;
pub extern "c" fn sysctlbyname(name: [*:0]const u8, oldp: ?*anyopaque, oldlenp: ?*usize, newp: ?*anyopaque, newlen: usize) c_int;
pub extern "c" fn sysctlnametomib(name: [*:0]const u8, mibp: ?*c_int, sizep: ?*usize) c_int;
-pub extern "c" fn tcgetattr(fd: c.fd_t, termios_p: *c.termios) c_int;
-pub extern "c" fn tcsetattr(fd: c.fd_t, optional_action: c.TCSA, termios_p: *const c.termios) c_int;
-pub extern "c" fn fcntl(fd: c.fd_t, cmd: c_int, ...) c_int;
-pub extern "c" fn flock(fd: c.fd_t, operation: c_int) c_int;
-pub extern "c" fn ioctl(fd: c.fd_t, request: c_int, ...) c_int;
-pub extern "c" fn uname(buf: *c.utsname) c_int;
+pub extern "c" fn tcgetattr(fd: fd_t, termios_p: *termios) c_int;
+pub extern "c" fn tcsetattr(fd: fd_t, optional_action: TCSA, termios_p: *const termios) c_int;
+pub extern "c" fn fcntl(fd: fd_t, cmd: c_int, ...) c_int;
+pub extern "c" fn flock(fd: fd_t, operation: c_int) c_int;
+pub extern "c" fn ioctl(fd: fd_t, request: c_int, ...) c_int;
+pub extern "c" fn uname(buf: *utsname) c_int;
pub extern "c" fn gethostname(name: [*]u8, len: usize) c_int;
-pub extern "c" fn shutdown(socket: c.fd_t, how: c_int) c_int;
-pub extern "c" fn bind(socket: c.fd_t, address: ?*const c.sockaddr, address_len: c.socklen_t) c_int;
-pub extern "c" fn socketpair(domain: c_uint, sock_type: c_uint, protocol: c_uint, sv: *[2]c.fd_t) c_int;
-pub extern "c" fn listen(sockfd: c.fd_t, backlog: c_uint) c_int;
-pub extern "c" fn getsockname(sockfd: c.fd_t, noalias addr: *c.sockaddr, noalias addrlen: *c.socklen_t) c_int;
-pub extern "c" fn getpeername(sockfd: c.fd_t, noalias addr: *c.sockaddr, noalias addrlen: *c.socklen_t) c_int;
-pub extern "c" fn connect(sockfd: c.fd_t, sock_addr: *const c.sockaddr, addrlen: c.socklen_t) c_int;
-pub extern "c" fn accept(sockfd: c.fd_t, noalias addr: ?*c.sockaddr, noalias addrlen: ?*c.socklen_t) c_int;
-pub extern "c" fn accept4(sockfd: c.fd_t, noalias addr: ?*c.sockaddr, noalias addrlen: ?*c.socklen_t, flags: c_uint) c_int;
-pub extern "c" fn getsockopt(sockfd: c.fd_t, level: i32, optname: u32, noalias optval: ?*anyopaque, noalias optlen: *c.socklen_t) c_int;
-pub extern "c" fn setsockopt(sockfd: c.fd_t, level: i32, optname: u32, optval: ?*const anyopaque, optlen: c.socklen_t) c_int;
-pub extern "c" fn send(sockfd: c.fd_t, buf: *const anyopaque, len: usize, flags: u32) isize;
+pub extern "c" fn shutdown(socket: fd_t, how: c_int) c_int;
+pub extern "c" fn bind(socket: fd_t, address: ?*const sockaddr, address_len: socklen_t) c_int;
+pub extern "c" fn socketpair(domain: c_uint, sock_type: c_uint, protocol: c_uint, sv: *[2]fd_t) c_int;
+pub extern "c" fn listen(sockfd: fd_t, backlog: c_uint) c_int;
+pub extern "c" fn getsockname(sockfd: fd_t, noalias addr: *sockaddr, noalias addrlen: *socklen_t) c_int;
+pub extern "c" fn getpeername(sockfd: fd_t, noalias addr: *sockaddr, noalias addrlen: *socklen_t) c_int;
+pub extern "c" fn connect(sockfd: fd_t, sock_addr: *const sockaddr, addrlen: socklen_t) c_int;
+pub extern "c" fn accept(sockfd: fd_t, noalias addr: ?*sockaddr, noalias addrlen: ?*socklen_t) c_int;
+pub extern "c" fn accept4(sockfd: fd_t, noalias addr: ?*sockaddr, noalias addrlen: ?*socklen_t, flags: c_uint) c_int;
+pub extern "c" fn getsockopt(sockfd: fd_t, level: i32, optname: u32, noalias optval: ?*anyopaque, noalias optlen: *socklen_t) c_int;
+pub extern "c" fn setsockopt(sockfd: fd_t, level: i32, optname: u32, optval: ?*const anyopaque, optlen: socklen_t) c_int;
+pub extern "c" fn send(sockfd: fd_t, buf: *const anyopaque, len: usize, flags: u32) isize;
pub extern "c" fn sendto(
- sockfd: c.fd_t,
+ sockfd: fd_t,
buf: *const anyopaque,
len: usize,
flags: u32,
- dest_addr: ?*const c.sockaddr,
- addrlen: c.socklen_t,
+ dest_addr: ?*const sockaddr,
+ addrlen: socklen_t,
) isize;
-pub extern "c" fn sendmsg(sockfd: c.fd_t, msg: *const c.msghdr_const, flags: u32) isize;
+pub extern "c" fn sendmsg(sockfd: fd_t, msg: *const msghdr_const, flags: u32) isize;
pub extern "c" fn recv(
- sockfd: c.fd_t,
+ sockfd: fd_t,
arg1: ?*anyopaque,
arg2: usize,
arg3: c_int,
) if (native_os == .windows) c_int else isize;
pub extern "c" fn recvfrom(
- sockfd: c.fd_t,
+ sockfd: fd_t,
noalias buf: *anyopaque,
len: usize,
flags: u32,
- noalias src_addr: ?*c.sockaddr,
- noalias addrlen: ?*c.socklen_t,
+ noalias src_addr: ?*sockaddr,
+ noalias addrlen: ?*socklen_t,
) if (native_os == .windows) c_int else isize;
-pub extern "c" fn recvmsg(sockfd: c.fd_t, msg: *c.msghdr, flags: u32) isize;
+pub extern "c" fn recvmsg(sockfd: fd_t, msg: *msghdr, flags: u32) isize;
-pub extern "c" fn kill(pid: c.pid_t, sig: c_int) c_int;
+pub extern "c" fn kill(pid: pid_t, sig: c_int) c_int;
-pub extern "c" fn setuid(uid: c.uid_t) c_int;
-pub extern "c" fn setgid(gid: c.gid_t) c_int;
-pub extern "c" fn seteuid(euid: c.uid_t) c_int;
-pub extern "c" fn setegid(egid: c.gid_t) c_int;
-pub extern "c" fn setreuid(ruid: c.uid_t, euid: c.uid_t) c_int;
-pub extern "c" fn setregid(rgid: c.gid_t, egid: c.gid_t) c_int;
-pub extern "c" fn setresuid(ruid: c.uid_t, euid: c.uid_t, suid: c.uid_t) c_int;
-pub extern "c" fn setresgid(rgid: c.gid_t, egid: c.gid_t, sgid: c.gid_t) c_int;
+pub extern "c" fn setuid(uid: uid_t) c_int;
+pub extern "c" fn setgid(gid: gid_t) c_int;
+pub extern "c" fn seteuid(euid: uid_t) c_int;
+pub extern "c" fn setegid(egid: gid_t) c_int;
+pub extern "c" fn setreuid(ruid: uid_t, euid: uid_t) c_int;
+pub extern "c" fn setregid(rgid: gid_t, egid: gid_t) c_int;
+pub extern "c" fn setresuid(ruid: uid_t, euid: uid_t, suid: uid_t) c_int;
+pub extern "c" fn setresgid(rgid: gid_t, egid: gid_t, sgid: gid_t) c_int;
pub extern "c" fn malloc(usize) ?*anyopaque;
pub extern "c" fn realloc(?*anyopaque, usize) ?*anyopaque;
pub extern "c" fn free(?*anyopaque) void;
-pub extern "c" fn futimes(fd: c.fd_t, times: *[2]c.timeval) c_int;
-pub extern "c" fn utimes(path: [*:0]const u8, times: *[2]c.timeval) c_int;
+pub extern "c" fn futimes(fd: fd_t, times: *[2]timeval) c_int;
+pub extern "c" fn utimes(path: [*:0]const u8, times: *[2]timeval) c_int;
-pub extern "c" fn utimensat(dirfd: c.fd_t, pathname: [*:0]const u8, times: *[2]c.timespec, flags: u32) c_int;
-pub extern "c" fn futimens(fd: c.fd_t, times: *const [2]c.timespec) c_int;
+pub extern "c" fn utimensat(dirfd: fd_t, pathname: [*:0]const u8, times: *[2]timespec, flags: u32) c_int;
+pub extern "c" fn futimens(fd: fd_t, times: *const [2]timespec) c_int;
pub extern "c" fn pthread_create(
noalias newthread: *pthread_t,
- noalias attr: ?*const c.pthread_attr_t,
+ noalias attr: ?*const pthread_attr_t,
start_routine: *const fn (?*anyopaque) callconv(.C) ?*anyopaque,
noalias arg: ?*anyopaque,
-) c.E;
-pub extern "c" fn pthread_attr_init(attr: *c.pthread_attr_t) c.E;
-pub extern "c" fn pthread_attr_setstack(attr: *c.pthread_attr_t, stackaddr: *anyopaque, stacksize: usize) c.E;
-pub extern "c" fn pthread_attr_setstacksize(attr: *c.pthread_attr_t, stacksize: usize) c.E;
-pub extern "c" fn pthread_attr_setguardsize(attr: *c.pthread_attr_t, guardsize: usize) c.E;
-pub extern "c" fn pthread_attr_destroy(attr: *c.pthread_attr_t) c.E;
+) E;
+pub extern "c" fn pthread_attr_init(attr: *pthread_attr_t) E;
+pub extern "c" fn pthread_attr_setstack(attr: *pthread_attr_t, stackaddr: *anyopaque, stacksize: usize) E;
+pub extern "c" fn pthread_attr_setstacksize(attr: *pthread_attr_t, stacksize: usize) E;
+pub extern "c" fn pthread_attr_setguardsize(attr: *pthread_attr_t, guardsize: usize) E;
+pub extern "c" fn pthread_attr_destroy(attr: *pthread_attr_t) E;
pub extern "c" fn pthread_self() pthread_t;
-pub extern "c" fn pthread_join(thread: pthread_t, arg_return: ?*?*anyopaque) c.E;
-pub extern "c" fn pthread_detach(thread: pthread_t) c.E;
+pub extern "c" fn pthread_join(thread: pthread_t, arg_return: ?*?*anyopaque) E;
+pub extern "c" fn pthread_detach(thread: pthread_t) E;
pub extern "c" fn pthread_atfork(
prepare: ?*const fn () callconv(.C) void,
parent: ?*const fn () callconv(.C) void,
child: ?*const fn () callconv(.C) void,
) c_int;
pub extern "c" fn pthread_key_create(
- key: *c.pthread_key_t,
+ key: *pthread_key_t,
destructor: ?*const fn (value: *anyopaque) callconv(.C) void,
-) c.E;
-pub extern "c" fn pthread_key_delete(key: c.pthread_key_t) c.E;
-pub extern "c" fn pthread_getspecific(key: c.pthread_key_t) ?*anyopaque;
-pub extern "c" fn pthread_setspecific(key: c.pthread_key_t, value: ?*anyopaque) c_int;
-pub extern "c" fn pthread_sigmask(how: c_int, set: *const c.sigset_t, oldset: *c.sigset_t) c_int;
-pub extern "c" fn sem_init(sem: *c.sem_t, pshared: c_int, value: c_uint) c_int;
-pub extern "c" fn sem_destroy(sem: *c.sem_t) c_int;
-pub extern "c" fn sem_open(name: [*:0]const u8, flag: c_int, mode: c.mode_t, value: c_uint) *c.sem_t;
-pub extern "c" fn sem_close(sem: *c.sem_t) c_int;
-pub extern "c" fn sem_post(sem: *c.sem_t) c_int;
-pub extern "c" fn sem_wait(sem: *c.sem_t) c_int;
-pub extern "c" fn sem_trywait(sem: *c.sem_t) c_int;
-pub extern "c" fn sem_timedwait(sem: *c.sem_t, abs_timeout: *const c.timespec) c_int;
-pub extern "c" fn sem_getvalue(sem: *c.sem_t, sval: *c_int) c_int;
-
-pub extern "c" fn shm_open(name: [*:0]const u8, flag: c_int, mode: c.mode_t) c_int;
+) E;
+pub extern "c" fn pthread_key_delete(key: pthread_key_t) E;
+pub extern "c" fn pthread_getspecific(key: pthread_key_t) ?*anyopaque;
+pub extern "c" fn pthread_setspecific(key: pthread_key_t, value: ?*anyopaque) c_int;
+pub extern "c" fn pthread_sigmask(how: c_int, set: *const sigset_t, oldset: *sigset_t) c_int;
+pub const pthread_setname_np = switch (native_os) {
+ .macos, .ios, .tvos, .watchos, .visionos => darwin.pthread_setname_np,
+ .solaris, .illumos => solaris.pthread_setname_np,
+ .netbsd => netbsd.pthread_setname_np,
+ else => private.pthread_setname_np,
+};
+
+pub extern "c" fn pthread_getname_np(thread: pthread_t, name: [*:0]u8, len: usize) c_int;
+pub const pthread_threadid_np = switch (native_os) {
+ .macos, .ios, .tvos, .watchos, .visionos => private.pthread_threadid_np,
+ else => {},
+};
+
+pub extern "c" fn sem_init(sem: *sem_t, pshared: c_int, value: c_uint) c_int;
+pub extern "c" fn sem_destroy(sem: *sem_t) c_int;
+pub extern "c" fn sem_open(name: [*:0]const u8, flag: c_int, mode: mode_t, value: c_uint) *sem_t;
+pub extern "c" fn sem_close(sem: *sem_t) c_int;
+pub extern "c" fn sem_post(sem: *sem_t) c_int;
+pub extern "c" fn sem_wait(sem: *sem_t) c_int;
+pub extern "c" fn sem_trywait(sem: *sem_t) c_int;
+pub extern "c" fn sem_timedwait(sem: *sem_t, abs_timeout: *const timespec) c_int;
+pub extern "c" fn sem_getvalue(sem: *sem_t, sval: *c_int) c_int;
+
+pub extern "c" fn shm_open(name: [*:0]const u8, flag: c_int, mode: mode_t) c_int;
pub extern "c" fn shm_unlink(name: [*:0]const u8) c_int;
pub extern "c" fn kqueue() c_int;
pub extern "c" fn kevent(
kq: c_int,
- changelist: [*]const c.Kevent,
+ changelist: [*]const Kevent,
nchanges: c_int,
- eventlist: [*]c.Kevent,
+ eventlist: [*]Kevent,
nevents: c_int,
- timeout: ?*const c.timespec,
+ timeout: ?*const timespec,
) c_int;
-pub extern "c" fn port_create() c.port_t;
+pub extern "c" fn port_create() port_t;
pub extern "c" fn port_associate(
- port: c.port_t,
+ port: port_t,
source: u32,
object: usize,
events: u32,
user_var: ?*anyopaque,
) c_int;
-pub extern "c" fn port_dissociate(port: c.port_t, source: u32, object: usize) c_int;
-pub extern "c" fn port_send(port: c.port_t, events: u32, user_var: ?*anyopaque) c_int;
+pub extern "c" fn port_dissociate(port: port_t, source: u32, object: usize) c_int;
+pub extern "c" fn port_send(port: port_t, events: u32, user_var: ?*anyopaque) c_int;
pub extern "c" fn port_sendn(
- ports: [*]c.port_t,
+ ports: [*]port_t,
errors: []u32,
num_ports: u32,
events: u32,
user_var: ?*anyopaque,
) c_int;
-pub extern "c" fn port_get(port: c.port_t, event: *c.port_event, timeout: ?*c.timespec) c_int;
+pub extern "c" fn port_get(port: port_t, event: *port_event, timeout: ?*timespec) c_int;
pub extern "c" fn port_getn(
- port: c.port_t,
- event_list: []c.port_event,
+ port: port_t,
+ event_list: []port_event,
max_events: u32,
events_retrieved: *u32,
- timeout: ?*c.timespec,
+ timeout: ?*timespec,
) c_int;
-pub extern "c" fn port_alert(port: c.port_t, flags: u32, events: u32, user_var: ?*anyopaque) c_int;
+pub extern "c" fn port_alert(port: port_t, flags: u32, events: u32, user_var: ?*anyopaque) c_int;
pub extern "c" fn getaddrinfo(
noalias node: ?[*:0]const u8,
noalias service: ?[*:0]const u8,
- noalias hints: ?*const c.addrinfo,
+ noalias hints: ?*const addrinfo,
/// On Linux, `res` will not be modified on error and `freeaddrinfo` will
/// potentially crash if you pass it an undefined pointer
- noalias res: *?*c.addrinfo,
-) c.EAI;
+ noalias res: *?*addrinfo,
+) EAI;
-pub extern "c" fn freeaddrinfo(res: *c.addrinfo) void;
+pub extern "c" fn freeaddrinfo(res: *addrinfo) void;
pub extern "c" fn getnameinfo(
- noalias addr: *const c.sockaddr,
- addrlen: c.socklen_t,
+ noalias addr: *const sockaddr,
+ addrlen: socklen_t,
noalias host: [*]u8,
- hostlen: c.socklen_t,
+ hostlen: socklen_t,
noalias serv: [*]u8,
- servlen: c.socklen_t,
+ servlen: socklen_t,
flags: u32,
-) c.EAI;
+) EAI;
-pub extern "c" fn gai_strerror(errcode: c.EAI) [*:0]const u8;
+pub extern "c" fn gai_strerror(errcode: EAI) [*:0]const u8;
-pub extern "c" fn poll(fds: [*]c.pollfd, nfds: c.nfds_t, timeout: c_int) c_int;
-pub extern "c" fn ppoll(fds: [*]c.pollfd, nfds: c.nfds_t, timeout: ?*const c.timespec, sigmask: ?*const c.sigset_t) c_int;
+pub extern "c" fn poll(fds: [*]pollfd, nfds: nfds_t, timeout: c_int) c_int;
+pub extern "c" fn ppoll(fds: [*]pollfd, nfds: nfds_t, timeout: ?*const timespec, sigmask: ?*const sigset_t) c_int;
pub extern "c" fn dn_expand(
msg: [*:0]const u8,
@@ -1849,29 +9303,29 @@ pub extern "c" fn dn_expand(
) c_int;
pub const PTHREAD_MUTEX_INITIALIZER = pthread_mutex_t{};
-pub extern "c" fn pthread_mutex_lock(mutex: *pthread_mutex_t) c.E;
-pub extern "c" fn pthread_mutex_unlock(mutex: *pthread_mutex_t) c.E;
-pub extern "c" fn pthread_mutex_trylock(mutex: *pthread_mutex_t) c.E;
-pub extern "c" fn pthread_mutex_destroy(mutex: *pthread_mutex_t) c.E;
+pub extern "c" fn pthread_mutex_lock(mutex: *pthread_mutex_t) E;
+pub extern "c" fn pthread_mutex_unlock(mutex: *pthread_mutex_t) E;
+pub extern "c" fn pthread_mutex_trylock(mutex: *pthread_mutex_t) E;
+pub extern "c" fn pthread_mutex_destroy(mutex: *pthread_mutex_t) E;
pub const PTHREAD_COND_INITIALIZER = pthread_cond_t{};
-pub extern "c" fn pthread_cond_wait(noalias cond: *pthread_cond_t, noalias mutex: *pthread_mutex_t) c.E;
-pub extern "c" fn pthread_cond_timedwait(noalias cond: *pthread_cond_t, noalias mutex: *pthread_mutex_t, noalias abstime: *const c.timespec) c.E;
-pub extern "c" fn pthread_cond_signal(cond: *pthread_cond_t) c.E;
-pub extern "c" fn pthread_cond_broadcast(cond: *pthread_cond_t) c.E;
-pub extern "c" fn pthread_cond_destroy(cond: *pthread_cond_t) c.E;
-
-pub extern "c" fn pthread_rwlock_destroy(rwl: *c.pthread_rwlock_t) callconv(.C) c.E;
-pub extern "c" fn pthread_rwlock_rdlock(rwl: *c.pthread_rwlock_t) callconv(.C) c.E;
-pub extern "c" fn pthread_rwlock_wrlock(rwl: *c.pthread_rwlock_t) callconv(.C) c.E;
-pub extern "c" fn pthread_rwlock_tryrdlock(rwl: *c.pthread_rwlock_t) callconv(.C) c.E;
-pub extern "c" fn pthread_rwlock_trywrlock(rwl: *c.pthread_rwlock_t) callconv(.C) c.E;
-pub extern "c" fn pthread_rwlock_unlock(rwl: *c.pthread_rwlock_t) callconv(.C) c.E;
+pub extern "c" fn pthread_cond_wait(noalias cond: *pthread_cond_t, noalias mutex: *pthread_mutex_t) E;
+pub extern "c" fn pthread_cond_timedwait(noalias cond: *pthread_cond_t, noalias mutex: *pthread_mutex_t, noalias abstime: *const timespec) E;
+pub extern "c" fn pthread_cond_signal(cond: *pthread_cond_t) E;
+pub extern "c" fn pthread_cond_broadcast(cond: *pthread_cond_t) E;
+pub extern "c" fn pthread_cond_destroy(cond: *pthread_cond_t) E;
+
+pub extern "c" fn pthread_rwlock_destroy(rwl: *pthread_rwlock_t) callconv(.C) E;
+pub extern "c" fn pthread_rwlock_rdlock(rwl: *pthread_rwlock_t) callconv(.C) E;
+pub extern "c" fn pthread_rwlock_wrlock(rwl: *pthread_rwlock_t) callconv(.C) E;
+pub extern "c" fn pthread_rwlock_tryrdlock(rwl: *pthread_rwlock_t) callconv(.C) E;
+pub extern "c" fn pthread_rwlock_trywrlock(rwl: *pthread_rwlock_t) callconv(.C) E;
+pub extern "c" fn pthread_rwlock_unlock(rwl: *pthread_rwlock_t) callconv(.C) E;
pub const pthread_t = *opaque {};
pub const FILE = opaque {};
-pub extern "c" fn dlopen(path: [*:0]const u8, mode: c_int) ?*anyopaque;
+pub extern "c" fn dlopen(path: [*:0]const u8, mode: RTLD) ?*anyopaque;
pub extern "c" fn dlclose(handle: *anyopaque) c_int;
pub extern "c" fn dlsym(handle: ?*anyopaque, symbol: [*:0]const u8) ?*anyopaque;
pub extern "c" fn dlerror() ?[*:0]u8;
@@ -1883,8 +9337,8 @@ pub extern "c" fn fdatasync(fd: c_int) c_int;
pub extern "c" fn prctl(option: c_int, ...) c_int;
-pub extern "c" fn getrlimit(resource: c.rlimit_resource, rlim: *c.rlimit) c_int;
-pub extern "c" fn setrlimit(resource: c.rlimit_resource, rlim: *const c.rlimit) c_int;
+pub extern "c" fn getrlimit(resource: rlimit_resource, rlim: *rlimit) c_int;
+pub extern "c" fn setrlimit(resource: rlimit_resource, rlim: *const rlimit) c_int;
pub extern "c" fn fmemopen(noalias buf: ?*anyopaque, size: usize, noalias mode: [*:0]const u8) ?*FILE;
@@ -1895,6 +9349,8 @@ pub extern "c" fn setlogmask(maskpri: c_int) c_int;
pub extern "c" fn if_nametoindex([*:0]const u8) c_int;
+pub extern "c" fn getpid() pid_t;
+
/// These are implementation defined but share identical values in at least musl and glibc:
/// - https://git.musl-libc.org/cgit/musl/tree/include/locale.h?id=ab31e9d6a0fa7c5c408856c89df2dfb12c344039#n18
/// - https://sourceware.org/git/?p=glibc.git;a=blob;f=locale/bits/locale.h;h=0fcbb66114be5fef0577dc9047256eb508c45919;hb=c90cfce849d010474e8cccf3e5bff49a2c8b141f#l26
@@ -1918,13 +9374,11 @@ pub const LC = enum(c_int) {
pub extern "c" fn setlocale(category: LC, locale: ?[*:0]const u8) ?[*:0]const u8;
pub const getcontext = if (builtin.target.isAndroid())
- @compileError("android bionic libc does not implement getcontext")
+{} // android bionic libc does not implement getcontext
else if (native_os == .linux and builtin.target.isMusl())
linux.getcontext
else
- struct {
- extern fn getcontext(ucp: *std.posix.ucontext_t) c_int;
- }.getcontext;
+ private.getcontext;
pub const max_align_t = if (native_abi == .msvc)
f64
@@ -1936,49 +9390,334 @@ else
b: c_longdouble,
};
+pub extern "c" fn pthread_getthreadid_np() c_int;
+pub extern "c" fn pthread_set_name_np(thread: pthread_t, name: [*:0]const u8) void;
+pub extern "c" fn pthread_get_name_np(thread: pthread_t, name: [*:0]u8, len: usize) void;
+
+pub const AF_SUN = solaris.AF_SUN;
+pub const AT_SUN = solaris.AT_SUN;
+pub const FILE_EVENT = solaris.FILE_EVENT;
+pub const GETCONTEXT = solaris.GETCONTEXT;
+pub const GETUSTACK = solaris.GETUSTACK;
+pub const PORT_ALERT = solaris.PORT_ALERT;
+pub const PORT_SOURCE = solaris.PORT_SOURCE;
+pub const POSIX_FADV = solaris.POSIX_FADV;
+pub const SCM = solaris.SCM;
+pub const SETCONTEXT = solaris.SETCONTEXT;
+pub const SETUSTACK = solaris.GETUSTACK;
+pub const SFD = solaris.SFD;
+pub const _SC = solaris._SC;
+pub const cmsghdr = solaris.cmsghdr;
+pub const ctid_t = solaris.ctid_t;
+pub const file_obj = solaris.file_obj;
+pub const fpregset_t = solaris.fpregset_t;
+pub const id_t = solaris.id_t;
+pub const lif_ifinfo_req = solaris.lif_ifinfo_req;
+pub const lif_nd_req = solaris.lif_nd_req;
+pub const lifreq = solaris.lifreq;
+pub const major_t = solaris.major_t;
+pub const minor_t = solaris.minor_t;
+pub const poolid_t = solaris.poolid_t;
+pub const port_notify = solaris.port_notify;
+pub const priority = solaris.priority;
+pub const procfs = solaris.procfs;
+pub const projid_t = solaris.projid_t;
+pub const signalfd_siginfo = solaris.signalfd_siginfo;
+pub const sysconf = solaris.sysconf;
+pub const taskid_t = solaris.taskid_t;
+pub const zoneid_t = solaris.zoneid_t;
+
+pub const DirEnt = haiku.DirEnt;
+pub const _get_next_area_info = haiku._get_next_area_info;
+pub const _get_next_image_info = haiku._get_next_image_info;
+pub const _get_team_info = haiku._get_team_info;
+pub const _kern_get_current_team = haiku._kern_get_current_team;
+pub const _kern_open_dir = haiku._kern_open_dir;
+pub const _kern_read_dir = haiku._kern_read_dir;
+pub const _kern_read_stat = haiku._kern_read_stat;
+pub const _kern_rewind_dir = haiku._kern_rewind_dir;
+pub const area_id = haiku.area_id;
+pub const area_info = haiku.area_info;
+pub const directory_which = haiku.directory_which;
+pub const find_directory = haiku.find_directory;
+pub const find_thread = haiku.find_thread;
+pub const get_system_info = haiku.get_system_info;
+pub const image_info = haiku.image_info;
+pub const port_id = haiku.port_id;
+pub const sem_id = haiku.sem_id;
+pub const status_t = haiku.status_t;
+pub const system_info = haiku.system_info;
+pub const team_id = haiku.team_id;
+pub const team_info = haiku.team_info;
+pub const thread_id = haiku.thread_id;
+pub const vregs = haiku.vregs;
+
+pub const AUTH = openbsd.AUTH;
+pub const BI = openbsd.BI;
+pub const FUTEX = openbsd.FUTEX;
+pub const HW = openbsd.HW;
+pub const PTHREAD_STACK_MIN = openbsd.PTHREAD_STACK_MIN;
+pub const TCFLUSH = openbsd.TCFLUSH;
+pub const TCIO = openbsd.TCIO;
+pub const auth_approval = openbsd.auth_approval;
+pub const auth_call = openbsd.auth_call;
+pub const auth_cat = openbsd.auth_cat;
+pub const auth_challenge = openbsd.auth_challenge;
+pub const auth_check_change = openbsd.auth_check_change;
+pub const auth_check_expire = openbsd.auth_check_expire;
+pub const auth_checknologin = openbsd.auth_checknologin;
+pub const auth_clean = openbsd.auth_clean;
+pub const auth_close = openbsd.auth_close;
+pub const auth_clrenv = openbsd.auth_clrenv;
+pub const auth_clroption = openbsd.auth_clroption;
+pub const auth_clroptions = openbsd.auth_clroptions;
+pub const auth_getitem = openbsd.auth_getitem;
+pub const auth_getpwd = openbsd.auth_getpwd;
+pub const auth_getstate = openbsd.auth_getstate;
+pub const auth_getvalue = openbsd.auth_getvalue;
+pub const auth_item_t = openbsd.auth_item_t;
+pub const auth_mkvalue = openbsd.auth_mkvalue;
+pub const auth_open = openbsd.auth_open;
+pub const auth_session_t = openbsd.auth_session_t;
+pub const auth_setdata = openbsd.auth_setdata;
+pub const auth_setenv = openbsd.auth_setenv;
+pub const auth_setitem = openbsd.auth_setitem;
+pub const auth_setoption = openbsd.auth_setoption;
+pub const auth_setpwd = openbsd.auth_setpwd;
+pub const auth_setstate = openbsd.auth_setstate;
+pub const auth_userchallenge = openbsd.auth_userchallenge;
+pub const auth_usercheck = openbsd.auth_usercheck;
+pub const auth_userokay = openbsd.auth_userokay;
+pub const auth_userresponse = openbsd.auth_userresponse;
+pub const auth_verify = openbsd.auth_verify;
+pub const bcrypt = openbsd.bcrypt;
+pub const bcrypt_checkpass = openbsd.bcrypt_checkpass;
+pub const bcrypt_gensalt = openbsd.bcrypt_gensalt;
+pub const bcrypt_newhash = openbsd.bcrypt_newhash;
+pub const endpwent = openbsd.endpwent;
+pub const futex = openbsd.futex;
+pub const getpwent = openbsd.getpwent;
+pub const getpwnam_r = openbsd.getpwnam_r;
+pub const getpwnam_shadow = openbsd.getpwnam_shadow;
+pub const getpwuid_r = openbsd.getpwuid_r;
+pub const getpwuid_shadow = openbsd.getpwuid_shadow;
+pub const getthrid = openbsd.getthrid;
+pub const login_cap_t = openbsd.login_cap_t;
+pub const login_close = openbsd.login_close;
+pub const login_getcapbool = openbsd.login_getcapbool;
+pub const login_getcapnum = openbsd.login_getcapnum;
+pub const login_getcapsize = openbsd.login_getcapsize;
+pub const login_getcapstr = openbsd.login_getcapstr;
+pub const login_getcaptime = openbsd.login_getcaptime;
+pub const login_getclass = openbsd.login_getclass;
+pub const login_getstyle = openbsd.login_getstyle;
+pub const pledge = openbsd.pledge;
+pub const pthread_spinlock_t = openbsd.pthread_spinlock_t;
+pub const pw_dup = openbsd.pw_dup;
+pub const setclasscontext = openbsd.setclasscontext;
+pub const setpassent = openbsd.setpassent;
+pub const setpwent = openbsd.setpwent;
+pub const setusercontext = openbsd.setusercontext;
+pub const uid_from_user = openbsd.uid_from_user;
+pub const unveil = openbsd.unveil;
+pub const user_from_uid = openbsd.user_from_uid;
+
+pub const CAP_RIGHTS_VERSION = freebsd.CAP_RIGHTS_VERSION;
+pub const KINFO_FILE_SIZE = freebsd.KINFO_FILE_SIZE;
+pub const MFD = freebsd.MFD;
+pub const UMTX_ABSTIME = freebsd.UMTX_ABSTIME;
+pub const UMTX_OP = freebsd.UMTX_OP;
+pub const _umtx_op = freebsd._umtx_op;
+pub const _umtx_time = freebsd._umtx_time;
+pub const cap_rights = freebsd.cap_rights;
+pub const fflags_t = freebsd.fflags_t;
+pub const fsblkcnt_t = freebsd.fsblkcnt_t;
+pub const fsfilcnt_t = freebsd.fsfilcnt_t;
+pub const kinfo_file = freebsd.kinfo_file;
+pub const kinfo_getfile = freebsd.kinfo_getfile;
+
+pub const COPYFILE = darwin.COPYFILE;
+pub const CPUFAMILY = darwin.CPUFAMILY;
+pub const DB_RECORDTYPE = darwin.DB_RECORDTYPE;
+pub const EXC = darwin.EXC;
+pub const EXCEPTION = darwin.EXCEPTION;
+pub const NSVersionOfRunTimeLibrary = darwin.NSVersionOfRunTimeLibrary;
+pub const OPEN_MAX = darwin.OPEN_MAX;
+pub const THREAD_STATE_NONE = darwin.THREAD_STATE_NONE;
+pub const UL = darwin.UL;
+pub const _NSGetExecutablePath = darwin._NSGetExecutablePath;
+pub const __getdirentries64 = darwin.__getdirentries64;
+pub const __ulock_wait = darwin.__ulock_wait;
+pub const __ulock_wait2 = darwin.__ulock_wait2;
+pub const __ulock_wake = darwin.__ulock_wake;
+pub const _dyld_get_image_header = darwin._dyld_get_image_header;
+pub const _dyld_get_image_name = darwin._dyld_get_image_name;
+pub const _dyld_get_image_vmaddr_slide = darwin._dyld_get_image_vmaddr_slide;
+pub const _dyld_image_count = darwin._dyld_image_count;
+pub const _host_page_size = darwin._host_page_size;
+pub const clock_get_time = darwin.clock_get_time;
+pub const dispatch_release = darwin.dispatch_release;
+pub const dispatch_semaphore_create = darwin.dispatch_semaphore_create;
+pub const dispatch_semaphore_signal = darwin.dispatch_semaphore_signal;
+pub const dispatch_semaphore_wait = darwin.dispatch_semaphore_wait;
+pub const dispatch_time = darwin.dispatch_time;
+pub const fcopyfile = darwin.fcopyfile;
+pub const kevent64 = darwin.kevent64;
+pub const mach_absolute_time = darwin.mach_absolute_time;
+pub const mach_continuous_time = darwin.mach_continuous_time;
+pub const mach_hdr = darwin.mach_hdr;
+pub const mach_host_self = darwin.mach_host_self;
+pub const mach_msg = darwin.mach_msg;
+pub const mach_port_allocate = darwin.mach_port_allocate;
+pub const mach_port_deallocate = darwin.mach_port_deallocate;
+pub const mach_port_insert_right = darwin.mach_port_insert_right;
+pub const mach_port_t = darwin.mach_port_t;
+pub const mach_task_self = darwin.mach_task_self;
+pub const mach_timebase_info = darwin.mach_timebase_info;
+pub const mach_vm_protect = darwin.mach_vm_protect;
+pub const mach_vm_read = darwin.mach_vm_read;
+pub const mach_vm_region = darwin.mach_vm_region;
+pub const mach_vm_region_recurse = darwin.mach_vm_region_recurse;
+pub const mach_vm_write = darwin.mach_vm_write;
+pub const os_log_create = darwin.os_log_create;
+pub const os_log_type_enabled = darwin.os_log_type_enabled;
+pub const os_signpost_enabled = darwin.os_signpost_enabled;
+pub const os_signpost_id_generate = darwin.os_signpost_id_generate;
+pub const os_signpost_id_make_with_pointer = darwin.os_signpost_id_make_with_pointer;
+pub const os_signpost_interval_begin = darwin.os_signpost_interval_begin;
+pub const os_signpost_interval_end = darwin.os_signpost_interval_end;
+pub const os_unfair_lock = darwin.os_unfair_lock;
+pub const os_unfair_lock_assert_not_owner = darwin.os_unfair_lock_assert_not_owner;
+pub const os_unfair_lock_assert_owner = darwin.os_unfair_lock_assert_owner;
+pub const os_unfair_lock_lock = darwin.os_unfair_lock_lock;
+pub const os_unfair_lock_trylock = darwin.os_unfair_lock_trylock;
+pub const os_unfair_lock_unlock = darwin.os_unfair_lock_unlock;
+pub const pid_for_task = darwin.pid_for_task;
+pub const posix_spawn = darwin.posix_spawn;
+pub const posix_spawn_file_actions_addchdir_np = darwin.posix_spawn_file_actions_addchdir_np;
+pub const posix_spawn_file_actions_addclose = darwin.posix_spawn_file_actions_addclose;
+pub const posix_spawn_file_actions_adddup2 = darwin.posix_spawn_file_actions_adddup2;
+pub const posix_spawn_file_actions_addfchdir_np = darwin.posix_spawn_file_actions_addfchdir_np;
+pub const posix_spawn_file_actions_addinherit_np = darwin.posix_spawn_file_actions_addinherit_np;
+pub const posix_spawn_file_actions_addopen = darwin.posix_spawn_file_actions_addopen;
+pub const posix_spawn_file_actions_destroy = darwin.posix_spawn_file_actions_destroy;
+pub const posix_spawn_file_actions_init = darwin.posix_spawn_file_actions_init;
+pub const posix_spawnattr_destroy = darwin.posix_spawnattr_destroy;
+pub const posix_spawnattr_getflags = darwin.posix_spawnattr_getflags;
+pub const posix_spawnattr_init = darwin.posix_spawnattr_init;
+pub const posix_spawnattr_setflags = darwin.posix_spawnattr_setflags;
+pub const posix_spawnp = darwin.posix_spawnp;
+pub const pthread_attr_get_qos_class_np = darwin.pthread_attr_get_qos_class_np;
+pub const pthread_attr_set_qos_class_np = darwin.pthread_attr_set_qos_class_np;
+pub const pthread_get_qos_class_np = darwin.pthread_get_qos_class_np;
+pub const pthread_set_qos_class_self_np = darwin.pthread_set_qos_class_self_np;
+pub const ptrace = darwin.ptrace;
+pub const sigaddset = darwin.sigaddset;
+pub const task_for_pid = darwin.task_for_pid;
+pub const task_get_exception_ports = darwin.task_get_exception_ports;
+pub const task_info = darwin.task_info;
+pub const task_resume = darwin.task_resume;
+pub const task_set_exception_ports = darwin.task_set_exception_ports;
+pub const task_suspend = darwin.task_suspend;
+pub const task_threads = darwin.task_threads;
+pub const thread_get_state = darwin.thread_get_state;
+pub const thread_info = darwin.thread_info;
+pub const thread_resume = darwin.thread_resume;
+pub const thread_set_state = darwin.thread_set_state;
+pub const vm_deallocate = darwin.vm_deallocate;
+pub const vm_machine_attribute = darwin.vm_machine_attribute;
+pub const vm_prot_t = darwin.vm_prot_t;
+
+pub const _ksiginfo = netbsd._ksiginfo;
+pub const _lwp_self = netbsd._lwp_self;
+pub const lwpid_t = netbsd.lwpid_t;
+
+/// External definitions shared by two or more operating systems.
const private = struct {
- extern "c" fn clock_getres(clk_id: c_int, tp: *c.timespec) c_int;
- extern "c" fn clock_gettime(clk_id: c_int, tp: *c.timespec) c_int;
- extern "c" fn fstat(fd: c.fd_t, buf: *c.Stat) c_int;
- extern "c" fn fstatat(dirfd: c.fd_t, path: [*:0]const u8, buf: *c.Stat, flag: u32) c_int;
- extern "c" fn getdirentries(fd: c.fd_t, buf_ptr: [*]u8, nbytes: usize, basep: *i64) isize;
- extern "c" fn getrusage(who: c_int, usage: *c.rusage) c_int;
- extern "c" fn gettimeofday(noalias tv: ?*c.timeval, noalias tz: ?*c.timezone) c_int;
+ extern "c" fn close(fd: fd_t) c_int;
+ extern "c" fn clock_getres(clk_id: clockid_t, tp: *timespec) c_int;
+ extern "c" fn clock_gettime(clk_id: clockid_t, tp: *timespec) c_int;
+ 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;
+ extern "c" fn fork() c_int;
+ extern "c" fn fstat(fd: fd_t, buf: *Stat) c_int;
+ extern "c" fn fstatat(dirfd: fd_t, path: [*:0]const u8, buf: *Stat, flag: u32) c_int;
+ extern "c" fn getdirentries(fd: fd_t, buf_ptr: [*]u8, nbytes: usize, basep: *i64) isize;
+ extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) switch (native_os) {
+ .freebsd, .kfreebsd => isize,
+ .solaris, .illumos => usize,
+ else => c_int,
+ };
+ extern "c" fn getrusage(who: c_int, usage: *rusage) c_int;
+ extern "c" fn gettimeofday(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int;
extern "c" fn msync(addr: *align(page_size) const anyopaque, len: usize, flags: c_int) c_int;
- extern "c" fn nanosleep(rqtp: *const c.timespec, rmtp: ?*c.timespec) c_int;
- extern "c" fn readdir(dir: *c.DIR) ?*c.dirent;
+ extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int;
+ extern "c" fn readdir(dir: *DIR) ?*dirent;
extern "c" fn realpath(noalias file_name: [*:0]const u8, noalias resolved_name: [*]u8) ?[*:0]u8;
extern "c" fn sched_yield() c_int;
- extern "c" fn sigaction(sig: c_int, noalias act: ?*const c.Sigaction, noalias oact: ?*c.Sigaction) c_int;
- extern "c" fn sigfillset(set: ?*c.sigset_t) void;
- extern "c" fn sigprocmask(how: c_int, noalias set: ?*const c.sigset_t, noalias oset: ?*c.sigset_t) c_int;
+ extern "c" fn sendfile(out_fd: fd_t, in_fd: fd_t, offset: ?*off_t, count: usize) isize;
+ extern "c" fn sigaction(sig: c_int, noalias act: ?*const Sigaction, noalias oact: ?*Sigaction) c_int;
+ extern "c" fn sigfillset(set: ?*sigset_t) void;
+ extern "c" fn sigprocmask(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*sigset_t) c_int;
extern "c" fn socket(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int;
- extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *c.Stat) c_int;
+ extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *Stat) c_int;
+ extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int;
+
+ extern "c" fn pthread_setname_np(thread: pthread_t, name: [*:0]const u8) c_int;
+ extern "c" fn getcontext(ucp: *ucontext_t) c_int;
+
+ extern "c" fn getrandom(buf_ptr: [*]u8, buf_len: usize, flags: c_uint) isize;
+ extern "c" fn getentropy(buffer: [*]u8, size: usize) c_int;
+ extern "c" fn arc4random_buf(buf: [*]u8, len: usize) void;
+
+ extern "c" fn _msize(memblock: ?*anyopaque) usize;
+ extern "c" fn malloc_size(?*const anyopaque) usize;
+ extern "c" fn malloc_usable_size(?*const anyopaque) usize;
+ extern "c" fn posix_memalign(memptr: *?*anyopaque, alignment: usize, size: usize) c_int;
/// macos modernized symbols.
/// x86_64 links to $INODE64 suffix for 64-bit support.
/// Note these are not necessary on aarch64.
- extern "c" fn @"fstat$INODE64"(fd: c.fd_t, buf: *c.Stat) c_int;
- extern "c" fn @"fstatat$INODE64"(dirfd: c.fd_t, path: [*:0]const u8, buf: *c.Stat, flag: u32) c_int;
- extern "c" fn @"readdir$INODE64"(dir: *c.DIR) ?*c.dirent;
- extern "c" fn @"stat$INODE64"(noalias path: [*:0]const u8, noalias buf: *c.Stat) c_int;
+ extern "c" fn @"fstat$INODE64"(fd: fd_t, buf: *Stat) c_int;
+ extern "c" fn @"fstatat$INODE64"(dirfd: fd_t, path: [*:0]const u8, buf: *Stat, flag: u32) c_int;
+ extern "c" fn @"readdir$INODE64"(dir: *DIR) ?*dirent;
+ extern "c" fn @"stat$INODE64"(noalias path: [*:0]const u8, noalias buf: *Stat) c_int;
/// macos modernized symbols.
extern "c" fn @"realpath$DARWIN_EXTSN"(noalias file_name: [*:0]const u8, noalias resolved_name: [*]u8) ?[*:0]u8;
- extern "c" fn __getdirentries64(fd: c.fd_t, buf_ptr: [*]u8, buf_len: usize, basep: *i64) isize;
+ extern "c" fn __getdirentries64(fd: fd_t, buf_ptr: [*]u8, buf_len: usize, basep: *i64) isize;
+
+ extern "c" fn pthread_threadid_np(thread: ?pthread_t, thread_id: *u64) c_int;
/// netbsd modernized symbols.
- extern "c" fn __clock_getres50(clk_id: c_int, tp: *c.timespec) c_int;
- extern "c" fn __clock_gettime50(clk_id: c_int, tp: *c.timespec) c_int;
- extern "c" fn __fstat50(fd: c.fd_t, buf: *c.Stat) c_int;
- extern "c" fn __getrusage50(who: c_int, usage: *c.rusage) c_int;
- extern "c" fn __gettimeofday50(noalias tv: ?*c.timeval, noalias tz: ?*c.timezone) c_int;
+ extern "c" fn __clock_getres50(clk_id: clockid_t, tp: *timespec) c_int;
+ extern "c" fn __clock_gettime50(clk_id: clockid_t, tp: *timespec) c_int;
+ extern "c" fn __fstat50(fd: fd_t, buf: *Stat) c_int;
+ extern "c" fn __getrusage50(who: c_int, usage: *rusage) c_int;
+ extern "c" fn __gettimeofday50(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int;
extern "c" fn __libc_thr_yield() c_int;
extern "c" fn __msync13(addr: *align(std.mem.page_size) const anyopaque, len: usize, flags: c_int) c_int;
- extern "c" fn __nanosleep50(rqtp: *const c.timespec, rmtp: ?*c.timespec) c_int;
- extern "c" fn __sigaction14(sig: c_int, noalias act: ?*const c.Sigaction, noalias oact: ?*c.Sigaction) c_int;
- extern "c" fn __sigfillset14(set: ?*c.sigset_t) void;
- extern "c" fn __sigprocmask14(how: c_int, noalias set: ?*const c.sigset_t, noalias oset: ?*c.sigset_t) c_int;
+ extern "c" fn __nanosleep50(rqtp: *const timespec, rmtp: ?*timespec) c_int;
+ extern "c" fn __sigaction14(sig: c_int, noalias act: ?*const Sigaction, noalias oact: ?*Sigaction) c_int;
+ extern "c" fn __sigfillset14(set: ?*sigset_t) void;
+ extern "c" fn __sigprocmask14(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*sigset_t) c_int;
extern "c" fn __socket30(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int;
- extern "c" fn __stat50(path: [*:0]const u8, buf: *c.Stat) c_int;
+ extern "c" fn __stat50(path: [*:0]const u8, buf: *Stat) c_int;
+ extern "c" fn __getdents30(fd: c_int, buf_ptr: [*]u8, nbytes: usize) c_int;
+ extern "c" fn __sigaltstack14(ss: ?*stack_t, old_ss: ?*stack_t) c_int;
+
+ // Don't forget to add another clown when an OS picks yet another unique
+ // symbol name for errno location!
+ // ๐คก๐คก๐คก๐คก๐คก๐คก
+
+ extern "c" fn ___errno() *c_int;
+ extern "c" fn __errno() *c_int;
+ extern "c" fn __errno_location() *c_int;
+ extern "c" fn __error() *c_int;
+ extern "c" fn _errno() *c_int;
+
+ extern threadlocal var errno: c_int;
+
+ fn errnoFromThreadLocal() *c_int {
+ return &errno;
+ }
};
lib/std/debug.zig
@@ -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;
lib/std/dynamic_library.zig
@@ -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;
},
};
lib/std/elf.zig
@@ -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.
///
lib/std/heap.zig
@@ -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)));
lib/std/net.zig
@@ -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),
lib/std/os.zig
@@ -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;
lib/std/posix.zig
@@ -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,
lib/std/process.zig
@@ -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.
lib/std/Progress.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;
lib/std/time.zig
@@ -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));
}
};
CMakeLists.txt
@@ -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