From 3deda15e21ea3a8138d5b628f2649bbbfe7fa910 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 24 Aug 2021 13:43:41 -0700 Subject: std.os reorganization, avoiding `usingnamespace` The main purpose of this branch is to explore avoiding the `usingnamespace` feature of the zig language, specifically with regards to `std.os` and related functionality. If this experiment is successful, it will provide a data point on whether or not it would be practical to entirely remove `usingnamespace` from the language. In this commit, `usingnamespace` has been completely eliminated from the Linux x86_64 compilation path, aside from io_uring. The behavior tests pass, however that's as far as this branch goes. It is very breaking, and a lot more work is needed before it could be considered mergeable. I wanted to put a pull requset up early so that zig programmers have time to provide feedback. This is progress towards closing #6600 since it clarifies where the actual "owner" of each declaration is, and reduces the number of different ways to import the same declarations. One of the main organizational strategies used here is to do namespacing with real namespaces (e.g. structs) rather than by having declarations share a common prefix (the C strategy). It's no coincidence that `usingnamespace` has similar semantics to `#include` and becomes much less necessary when using proper namespaces. --- lib/std/debug.zig | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'lib/std/debug.zig') diff --git a/lib/std/debug.zig b/lib/std/debug.zig index 4b715f2b14..540586a38f 100644 --- a/lib/std/debug.zig +++ b/lib/std/debug.zig @@ -948,8 +948,8 @@ fn mapWholeFile(file: File) ![]align(mem.page_size) const u8 { const mapped_mem = try os.mmap( null, file_len, - os.PROT_READ, - os.MAP_SHARED, + os.PROT.READ, + os.MAP.SHARED, file.handle, 0, ); @@ -1498,12 +1498,12 @@ pub fn attachSegfaultHandler() void { var act = os.Sigaction{ .handler = .{ .sigaction = handleSegfaultLinux }, .mask = os.empty_sigset, - .flags = (os.SA_SIGINFO | os.SA_RESTART | os.SA_RESETHAND), + .flags = (os.SA.SIGINFO | os.SA.RESTART | os.SA.RESETHAND), }; - os.sigaction(os.SIGSEGV, &act, null); - os.sigaction(os.SIGILL, &act, null); - os.sigaction(os.SIGBUS, &act, null); + os.sigaction(os.SIG.SEGV, &act, null); + os.sigaction(os.SIG.ILL, &act, null); + os.sigaction(os.SIG.BUS, &act, null); } fn resetSegfaultHandler() void { @@ -1515,13 +1515,13 @@ fn resetSegfaultHandler() void { return; } var act = os.Sigaction{ - .handler = .{ .sigaction = os.SIG_DFL }, + .handler = .{ .sigaction = os.SIG.DFL }, .mask = os.empty_sigset, .flags = 0, }; - os.sigaction(os.SIGSEGV, &act, null); - os.sigaction(os.SIGILL, &act, null); - os.sigaction(os.SIGBUS, &act, null); + os.sigaction(os.SIG.SEGV, &act, null); + os.sigaction(os.SIG.ILL, &act, null); + os.sigaction(os.SIG.BUS, &act, null); } fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const c_void) callconv(.C) noreturn { @@ -1542,9 +1542,9 @@ fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const c_v nosuspend { const stderr = io.getStdErr().writer(); _ = switch (sig) { - os.SIGSEGV => stderr.print("Segmentation fault at address 0x{x}\n", .{addr}), - os.SIGILL => stderr.print("Illegal instruction at address 0x{x}\n", .{addr}), - os.SIGBUS => stderr.print("Bus error at address 0x{x}\n", .{addr}), + os.SIG.SEGV => stderr.print("Segmentation fault at address 0x{x}\n", .{addr}), + os.SIG.ILL => stderr.print("Illegal instruction at address 0x{x}\n", .{addr}), + os.SIG.BUS => stderr.print("Bus error at address 0x{x}\n", .{addr}), else => unreachable, } catch os.abort(); } @@ -1552,20 +1552,20 @@ fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const c_v switch (native_arch) { .i386 => { const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr)); - const ip = @intCast(usize, ctx.mcontext.gregs[os.REG_EIP]); - const bp = @intCast(usize, ctx.mcontext.gregs[os.REG_EBP]); + const ip = @intCast(usize, ctx.mcontext.gregs[os.REG.EIP]); + const bp = @intCast(usize, ctx.mcontext.gregs[os.REG.EBP]); dumpStackTraceFromBase(bp, ip); }, .x86_64 => { const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr)); const ip = switch (native_os) { - .linux, .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG_RIP]), + .linux, .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG.RIP]), .freebsd => @intCast(usize, ctx.mcontext.rip), .openbsd => @intCast(usize, ctx.sc_rip), else => unreachable, }; const bp = switch (native_os) { - .linux, .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG_RBP]), + .linux, .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG.RBP]), .openbsd => @intCast(usize, ctx.sc_rbp), .freebsd => @intCast(usize, ctx.mcontext.rbp), else => unreachable, -- cgit v1.2.3 From c05a20fc8c36742dab8792d15e79716da1a55759 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sat, 28 Aug 2021 15:34:17 -0700 Subject: std: reorganization that allows new usingnamespace semantics The proposal #9629 is now accepted, usingnamespace stays but no longer puts identifiers in scope. --- CMakeLists.txt | 1 - lib/std/builtin.zig | 2 +- lib/std/c.zig | 498 +++++++++++-------------- lib/std/c/darwin.zig | 284 ++++++--------- lib/std/c/dragonfly.zig | 59 +-- lib/std/c/freebsd.zig | 263 +++++++------- lib/std/c/generic.zig | 23 -- lib/std/c/haiku.zig | 195 +++++----- lib/std/c/hermit.zig | 5 +- lib/std/c/linux.zig | 1 + lib/std/c/netbsd.zig | 265 +++++++------- lib/std/c/openbsd.zig | 62 ++-- lib/std/c/wasi.zig | 24 +- lib/std/c/windows.zig | 86 +++-- lib/std/crypto/25519/curve25519.zig | 4 +- lib/std/debug.zig | 4 +- lib/std/dwarf.zig | 338 +++++++++++++---- lib/std/dwarf/AT.zig | 198 ++++++++++ lib/std/dwarf/OP.zig | 195 ++++++++++ lib/std/dwarf/TAG.zig | 108 ++++++ lib/std/dwarf_bits.zig | 699 ------------------------------------ lib/std/event/rwlock.zig | 1 + lib/std/fmt.zig | 2 +- lib/std/fs.zig | 90 ++--- lib/std/fs/wasi.zig | 6 +- lib/std/hash_map.zig | 8 +- lib/std/heap.zig | 8 +- lib/std/io/c_writer.zig | 1 + lib/std/json.zig | 2 +- lib/std/math/big/int.zig | 3 +- lib/std/os.zig | 40 ++- lib/std/os/linux.zig | 68 ++-- lib/std/os/linux/arm-eabi.zig | 48 +-- lib/std/os/linux/arm64.zig | 48 +-- lib/std/os/linux/io_uring.zig | 6 +- lib/std/os/linux/mips.zig | 48 +-- lib/std/os/linux/powerpc.zig | 48 +-- lib/std/os/linux/powerpc64.zig | 48 +-- lib/std/os/linux/riscv64.zig | 42 +-- lib/std/os/linux/sparc64.zig | 42 +-- lib/std/os/linux/thumb.zig | 3 + lib/std/os/wasi.zig | 189 +++++----- lib/std/os/windows.zig | 17 +- lib/std/os/windows/gdi32.zig | 2 + lib/std/os/windows/kernel32.zig | 20 ++ lib/std/os/windows/ntdll.zig | 1 + lib/std/os/windows/psapi.zig | 43 +++ lib/std/os/windows/user32.zig | 26 +- lib/std/os/windows/ws2_32.zig | 10 + lib/std/time.zig | 2 - lib/std/zig.zig | 1 - 51 files changed, 2115 insertions(+), 2072 deletions(-) delete mode 100644 lib/std/c/generic.zig create mode 100644 lib/std/dwarf/AT.zig create mode 100644 lib/std/dwarf/OP.zig create mode 100644 lib/std/dwarf/TAG.zig delete mode 100644 lib/std/dwarf_bits.zig (limited to 'lib/std/debug.zig') diff --git a/CMakeLists.txt b/CMakeLists.txt index 7227b04862..0f68c2c649 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -431,7 +431,6 @@ set(ZIG_STAGE2_SOURCES "${CMAKE_SOURCE_DIR}/lib/std/os/linux/io_uring.zig" "${CMAKE_SOURCE_DIR}/lib/std/os/linux/x86_64.zig" "${CMAKE_SOURCE_DIR}/lib/std/os/windows.zig" - "${CMAKE_SOURCE_DIR}/lib/std/os/windows/bits.zig" "${CMAKE_SOURCE_DIR}/lib/std/os/windows/ntstatus.zig" "${CMAKE_SOURCE_DIR}/lib/std/os/windows/win32error.zig" "${CMAKE_SOURCE_DIR}/lib/std/Progress.zig" diff --git a/lib/std/builtin.zig b/lib/std/builtin.zig index bb35d61375..7f6c40c6f5 100644 --- a/lib/std/builtin.zig +++ b/lib/std/builtin.zig @@ -27,7 +27,7 @@ pub const code_model = builtin.code_model; /// used rather than `explicit_subsystem`. /// On non-Windows targets, this is `null`. pub const subsystem: ?std.Target.SubSystem = blk: { - if (@hasDecl(builtin, "explicit_subsystem")) break :blk explicit_subsystem; + if (@hasDecl(builtin, "explicit_subsystem")) break :blk builtin.explicit_subsystem; switch (os.tag) { .windows => { if (is_test) { diff --git a/lib/std/c.zig b/lib/std/c.zig index 11ed75581a..9770af5f5f 100644 --- a/lib/std/c.zig +++ b/lib/std/c.zig @@ -1,181 +1,17 @@ const std = @import("std"); const builtin = std.builtin; +const c = @This(); const page_size = std.mem.page_size; const iovec = std.os.iovec; const iovec_const = std.os.iovec_const; -pub const tokenizer = @import("c/tokenizer.zig"); -pub const Token = tokenizer.Token; -pub const Tokenizer = tokenizer.Tokenizer; - test { _ = tokenizer; } -const generic = @import("c/generic.zig"); -const system = switch (builtin.os.tag) { - .linux => @import("c/linux.zig"), - .windows => @import("c/windows.zig"), - .macos, .ios, .tvos, .watchos => @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"), - .hermit => @import("c/hermit.zig"), - .solaris => @import("c/solaris.zig"), - .fuchsia => @import("c/fuchsia.zig"), - .minix => @import("c/minix.zig"), - .emscripten => @import("c/emscripten.zig"), - .wasi => @import("c/wasi.zig"), - else => struct {}, -}; - -pub const _errno = system._errno; -pub const copy_file_range = system.copy_file_range; -pub const fallocate64 = system.fallocate64; -pub const fopen64 = system.fopen64; -pub const fstat64 = system.fstat64; -pub const fstatat64 = system.fstatat64; -pub const ftruncate64 = system.ftruncate64; -pub const getrlimit64 = system.getrlimit64; -pub const lseek64 = system.lseek64; -pub const mmap64 = system.mmap64; -pub const open64 = system.open64; -pub const openat64 = system.openat64; -pub const pread64 = system.pread64; -pub const preadv64 = system.preadv64; -pub const pwrite64 = system.pwrite64; -pub const pwritev64 = system.pwritev64; -pub const sendfile64 = system.sendfile64; -pub const setrlimit64 = system.setrlimit64; - -pub const AF = system.AF; -pub const AI = system.AI; -pub const AT = system.AT; -pub const CLOCK = system.CLOCK; -pub const CPU_COUNT = system.CPU_COUNT; -pub const E = system.E; -pub const EAI = system.EAI; -pub const F = system.F; -pub const FD_CLOEXEC = system.FD_CLOEXEC; -pub const F_OK = system.F_OK; -pub const HOST_NAME_MAX = system.HOST_NAME_MAX; -pub const IFNAMESIZE = system.IFNAMESIZE; -pub const IOV_MAX = system.IOV_MAX; -pub const IPPROTO = system.IPPROTO; -pub const LOCK = system.LOCK; -pub const MADV = system.MADV; -pub const MAP = system.MAP; -pub const NAME_MAX = system.NAME_MAX; -pub const NI = system.NI; -pub const O = system.O; -pub const PATH_MAX = system.PATH_MAX; -pub const POLL = system.POLL; -pub const PROT = system.PROT; -pub const REG = system.REG; -pub const RLIM = system.RLIM; -pub const RTLD = system.RTLD; -pub const R_OK = system.R_OK; -pub const S = system.S; -pub const SA = system.SA; -pub const SEEK = system.SEEK; -pub const SHUT = system.SHUT; -pub const SIG = system.SIG; -pub const SIOCGIFINDEX = system.SIOCGIFINDEX; -pub const SO = system.SO; -pub const SOCK = system.SOCK; -pub const SOL = system.SOL; -pub const STDERR_FILENO = system.STDERR_FILENO; -pub const STDIN_FILENO = system.STDIN_FILENO; -pub const STDOUT_FILENO = system.STDOUT_FILENO; -pub const Sigaction = system.Sigaction; -pub const Stat = system.Stat; -pub const W = system.W; -pub const W_OK = system.W_OK; -pub const X_OK = system.X_OK; -pub const addrinfo = system.addrinfo; -pub const cpu_set_t = system.cpu_set_t; -pub const dl_iterate_phdr = system.dl_iterate_phdr; -pub const dl_iterate_phdr_callback = system.dl_iterate_phdr_callback; -pub const dl_phdr_info = system.dl_phdr_info; -pub const empty_sigset = system.empty_sigset; -pub const epoll_create1 = system.epoll_create1; -pub const epoll_ctl = system.epoll_ctl; -pub const epoll_pwait = system.epoll_pwait; -pub const epoll_wait = system.epoll_wait; -pub const eventfd = system.eventfd; -pub const fallocate = system.fallocate; -pub const fd_t = system.fd_t; -pub const getauxval = system.getauxval; -pub const getdents = system.getdents; -pub const getrandom = system.getrandom; -pub const gid_t = system.gid_t; -pub const ifreq = system.ifreq; -pub const ino_t = system.ino_t; -pub const inotify_add_watch = system.inotify_add_watch; -pub const inotify_init1 = system.inotify_init1; -pub const inotify_rm_watch = system.inotify_rm_watch; -pub const madvise = system.madvise; -pub const malloc_usable_size = system.malloc_usable_size; -pub const memfd_create = system.memfd_create; -pub const mode_t = system.mode_t; -pub const nfds_t = system.nfds_t; -pub const off_t = system.off_t; -pub const pid_t = system.pid_t; -pub const pipe2 = system.pipe2; -pub const pollfd = system.pollfd; -pub const posix_memalign = system.posix_memalign; -pub const prlimit = system.prlimit; -pub const pthread_attr_t = system.pthread_attr_t; -pub const pthread_cond_t = system.pthread_cond_t; -pub const pthread_getname_np = system.pthread_getname_np; -pub const pthread_mutex_t = system.pthread_mutex_t; -pub const pthread_rwlock_t = system.pthread_rwlock_t; -pub const pthread_setname_np = system.pthread_setname_np; -pub const rlim_t = system.rlim_t; -pub const rlimit = system.rlimit; -pub const rlimit_resource = system.rlimit_resource; -pub const sched_getaffinity = system.sched_getaffinity; -pub const sem_t = system.sem_t; -pub const sendfile = system.sendfile; -pub const sigaltstack = system.sigaltstack; -pub const siginfo_t = system.siginfo_t; -pub const signalfd = system.signalfd; -pub const sigset_t = system.sigset_t; -pub const sockaddr = system.sockaddr; -pub const socklen_t = system.socklen_t; -pub const stack_t = system.stack_t; -pub const timespec = system.timespec; -pub const timeval = system.timeval; -pub const ucontext_t = system.ucontext_t; -pub const uid_t = system.uid_t; -pub const utsname = system.utsname; - -pub const alarm = if (@hasDecl(system, "alarm")) system.alarm else generic.alarm; -pub const clock_getres = if (@hasDecl(system, "clock_getres")) system.clock_getres else generic.clock_getres; -pub const clock_gettime = if (@hasDecl(system, "clock_gettime")) system.clock_gettime else generic.clock_gettime; -pub const fstat = if (@hasDecl(system, "fstat")) system.fstat else generic.fstat; -pub const fstatat = if (@hasDecl(system, "fstatat")) system.fstatat else generic.fstatat; -pub const getrusage = if (@hasDecl(system, "getrusage")) system.getrusage else generic.getrusage; -pub const gettimeofday = if (@hasDecl(system, "gettimeofday")) system.gettimeofday else generic.gettimeofday; -pub const nanosleep = if (@hasDecl(system, "nanosleep")) system.nanosleep else generic.nanosleep; -pub const realpath = if (@hasDecl(system, "realpath")) system.realpath else generic.realpath; -pub const sched_yield = if (@hasDecl(system, "sched_yield")) system.sched_yield else generic.sched_yield; -pub const sigaction = if (@hasDecl(system, "sigaction")) system.sigaction else generic.sigaction; -pub const sigfillset = if (@hasDecl(system, "sigfillset")) system.sigfillset else generic.sigfillset; -pub const sigprocmask = if (@hasDecl(system, "sigprocmask")) system.sigprocmask else generic.sigprocmask; -pub const sigwait = if (@hasDecl(system, "sigwait")) system.sigwait else generic.sigwait; -pub const socket = if (@hasDecl(system, "socket")) system.socket else generic.socket; -pub const stat = if (@hasDecl(system, "stat")) system.stat else generic.stat; - -pub fn getErrno(rc: anytype) E { - if (rc == -1) { - return @intToEnum(E, _errno().*); - } else { - return .SUCCESS; - } -} +pub const tokenizer = @import("c/tokenizer.zig"); +pub const Token = tokenizer.Token; +pub const Tokenizer = tokenizer.Tokenizer; /// The return type is `type` to force comptime function call execution. /// TODO: https://github.com/ziglang/zig/issues/425 @@ -203,6 +39,94 @@ pub fn versionCheck(glibc_version: builtin.Version) type { }; } +pub usingnamespace switch (builtin.os.tag) { + .linux => @import("c/linux.zig"), + .windows => @import("c/windows.zig"), + .macos, .ios, .tvos, .watchos => @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"), + .hermit => @import("c/hermit.zig"), + .solaris => @import("c/solaris.zig"), + .fuchsia => @import("c/fuchsia.zig"), + .minix => @import("c/minix.zig"), + .emscripten => @import("c/emscripten.zig"), + .wasi => @import("c/wasi.zig"), + else => struct {}, +}; + +pub usingnamespace switch (builtin.os.tag) { + .netbsd => struct {}, + .macos, .ios, .watchos, .tvos => struct { + // XXX: close -> close$NOCANCEL + // XXX: getdirentries -> _getdirentries64 + pub extern "c" fn clock_getres(clk_id: c_int, tp: *c.timespec) c_int; + pub extern "c" fn clock_gettime(clk_id: c_int, tp: *c.timespec) c_int; + pub extern "c" fn getrusage(who: c_int, usage: *c.rusage) c_int; + pub extern "c" fn gettimeofday(noalias tv: ?*c.timeval, noalias tz: ?*c.timezone) c_int; + pub extern "c" fn nanosleep(rqtp: *const c.timespec, rmtp: ?*c.timespec) c_int; + pub extern "c" fn sched_yield() c_int; + pub extern "c" fn sigaction(sig: c_int, noalias act: ?*const c.Sigaction, noalias oact: ?*c.Sigaction) c_int; + pub extern "c" fn sigprocmask(how: c_int, noalias set: ?*const c.sigset_t, noalias oset: ?*c.sigset_t) c_int; + pub extern "c" fn socket(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int; + pub extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *c.Stat) c_int; + pub extern "c" fn sigfillset(set: ?*c.sigset_t) void; + pub extern "c" fn alarm(seconds: c_uint) c_uint; + pub extern "c" fn sigwait(set: ?*c.sigset_t, sig: ?*c_int) c_int; + }, + .windows => struct { + // 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: *c.timespec) c_int; + pub extern "c" fn clock_gettime(clk_id: c_int, tp: *c.timespec) c_int; + pub extern "c" fn fstat(fd: c.fd_t, buf: *c.Stat) c_int; + pub extern "c" fn getrusage(who: c_int, usage: *c.rusage) c_int; + pub extern "c" fn gettimeofday(noalias tv: ?*c.timeval, noalias tz: ?*c.timezone) c_int; + pub extern "c" fn nanosleep(rqtp: *const c.timespec, rmtp: ?*c.timespec) c_int; + pub extern "c" fn sched_yield() c_int; + pub extern "c" fn sigaction(sig: c_int, noalias act: ?*const c.Sigaction, noalias oact: ?*c.Sigaction) c_int; + pub extern "c" fn sigprocmask(how: c_int, noalias set: ?*const c.sigset_t, noalias oset: ?*c.sigset_t) c_int; + pub extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *c.Stat) c_int; + pub extern "c" fn sigfillset(set: ?*c.sigset_t) void; + pub extern "c" fn alarm(seconds: c_uint) c_uint; + pub extern "c" fn sigwait(set: ?*c.sigset_t, sig: ?*c_int) c_int; + }, + else => struct { + pub extern "c" fn clock_getres(clk_id: c_int, tp: *c.timespec) c_int; + pub extern "c" fn clock_gettime(clk_id: c_int, tp: *c.timespec) c_int; + pub extern "c" fn fstat(fd: c.fd_t, buf: *c.Stat) c_int; + pub extern "c" fn getrusage(who: c_int, usage: *c.rusage) c_int; + pub extern "c" fn gettimeofday(noalias tv: ?*c.timeval, noalias tz: ?*c.timezone) c_int; + pub extern "c" fn nanosleep(rqtp: *const c.timespec, rmtp: ?*c.timespec) c_int; + pub extern "c" fn sched_yield() c_int; + pub extern "c" fn sigaction(sig: c_int, noalias act: ?*const c.Sigaction, noalias oact: ?*c.Sigaction) c_int; + pub extern "c" fn sigprocmask(how: c_int, noalias set: ?*const c.sigset_t, noalias oset: ?*c.sigset_t) c_int; + pub extern "c" fn socket(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int; + pub extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *c.Stat) c_int; + pub extern "c" fn sigfillset(set: ?*c.sigset_t) void; + pub extern "c" fn alarm(seconds: c_uint) c_uint; + pub extern "c" fn sigwait(set: ?*c.sigset_t, sig: ?*c_int) c_int; + }, +}; + +pub usingnamespace switch (builtin.os.tag) { + .macos, .ios, .watchos, .tvos => struct {}, + else => struct { + pub extern "c" fn realpath(noalias file_name: [*:0]const u8, noalias resolved_name: [*]u8) ?[*:0]u8; + pub extern "c" fn fstatat(dirfd: c.fd_t, path: [*:0]const u8, stat_buf: *c.Stat, flags: u32) c_int; + }, +}; + +pub fn getErrno(rc: anytype) c.E { + if (rc == -1) { + return @intToEnum(c.E, c._errno().*); + } else { + return .SUCCESS; + } +} + pub extern "c" var environ: [*:null]?[*:0]u8; pub extern "c" fn fopen(noalias filename: [*:0]const u8, noalias modes: [*:0]const u8) ?*FILE; @@ -214,175 +138,175 @@ 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: fd_t) c_int; -pub extern "c" fn close(fd: fd_t) c_int; -pub extern "c" fn lseek(fd: fd_t, offset: off_t, whence: c_int) off_t; +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: c_int) c.off_t; pub extern "c" fn open(path: [*:0]const u8, oflag: c_uint, ...) c_int; pub extern "c" fn openat(fd: c_int, path: [*:0]const u8, oflag: c_uint, ...) c_int; -pub extern "c" fn ftruncate(fd: c_int, length: off_t) c_int; +pub extern "c" fn ftruncate(fd: c_int, length: c.off_t) c_int; pub extern "c" fn raise(sig: c_int) c_int; -pub extern "c" fn read(fd: fd_t, buf: [*]u8, nbyte: usize) isize; +pub extern "c" fn read(fd: c.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: 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 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 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: 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) c_void, len: usize, prot: c_uint, flags: c_uint, fd: fd_t, offset: off_t) *c_void; +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) c_void, len: usize, prot: c_uint, flags: c_uint, fd: c.fd_t, offset: c.off_t) *c_void; pub extern "c" fn munmap(addr: *align(page_size) const c_void, len: usize) c_int; pub extern "c" fn mprotect(addr: *align(page_size) c_void, 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: fd_t, oldpath: [*:0]const u8, newfd: fd_t, 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 unlink(path: [*:0]const u8) c_int; -pub extern "c" fn unlinkat(dirfd: fd_t, path: [*:0]const u8, flags: c_uint) c_int; +pub extern "c" fn unlinkat(dirfd: c.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: pid_t, stat_loc: ?*c_int, options: c_int) pid_t; +pub extern "c" fn waitpid(pid: c.pid_t, stat_loc: ?*c_int, options: c_int) c.pid_t; pub extern "c" fn fork() c_int; pub extern "c" fn access(path: [*:0]const u8, mode: c_uint) 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 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 mkdir(path: [*:0]const u8, mode: c_uint) c_int; -pub extern "c" fn mkdirat(dirfd: fd_t, path: [*:0]const u8, mode: u32) c_int; +pub extern "c" fn mkdirat(dirfd: c.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: fd_t, newpath: [*: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 rename(old: [*:0]const u8, 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 renameat(olddirfd: c.fd_t, old: [*:0]const u8, newdirfd: c.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: fd_t) c_int; +pub extern "c" fn fchdir(fd: c.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: fd_t) c_int; -pub extern "c" fn dup2(old_fd: fd_t, new_fd: fd_t) 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 readlink(noalias path: [*:0]const u8, noalias buf: [*]u8, bufsize: usize) isize; -pub extern "c" fn readlinkat(dirfd: fd_t, 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 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: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int; pub extern "c" fn sysctlbyname(name: [*:0]const u8, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, 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: 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 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 gethostname(name: [*]u8, len: usize) c_int; -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: u32, optname: u32, noalias optval: ?*c_void, noalias optlen: *socklen_t) c_int; -pub extern "c" fn setsockopt(sockfd: fd_t, level: u32, optname: u32, optval: ?*const c_void, optlen: socklen_t) c_int; -pub extern "c" fn send(sockfd: fd_t, buf: *const c_void, len: usize, flags: u32) isize; +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: u32, optname: u32, noalias optval: ?*c_void, noalias optlen: *c.socklen_t) c_int; +pub extern "c" fn setsockopt(sockfd: c.fd_t, level: u32, optname: u32, optval: ?*const c_void, optlen: c.socklen_t) c_int; +pub extern "c" fn send(sockfd: c.fd_t, buf: *const c_void, len: usize, flags: u32) isize; pub extern "c" fn sendto( - sockfd: fd_t, + sockfd: c.fd_t, buf: *const c_void, len: usize, flags: u32, - dest_addr: ?*const sockaddr, - addrlen: socklen_t, + dest_addr: ?*const c.sockaddr, + addrlen: c.socklen_t, ) isize; -pub extern "c" fn sendmsg(sockfd: fd_t, msg: *const std.x.os.Socket.Message, flags: c_int) isize; +pub extern "c" fn sendmsg(sockfd: c.fd_t, msg: *const std.x.os.Socket.Message, flags: c_int) isize; -pub extern "c" fn recv(sockfd: fd_t, arg1: ?*c_void, arg2: usize, arg3: c_int) isize; +pub extern "c" fn recv(sockfd: c.fd_t, arg1: ?*c_void, arg2: usize, arg3: c_int) isize; pub extern "c" fn recvfrom( - sockfd: fd_t, + sockfd: c.fd_t, noalias buf: *c_void, len: usize, flags: u32, - noalias src_addr: ?*sockaddr, - noalias addrlen: ?*socklen_t, + noalias src_addr: ?*c.sockaddr, + noalias addrlen: ?*c.socklen_t, ) isize; -pub extern "c" fn recvmsg(sockfd: fd_t, msg: *std.x.os.Socket.Message, flags: c_int) isize; +pub extern "c" fn recvmsg(sockfd: c.fd_t, msg: *std.x.os.Socket.Message, flags: c_int) isize; -pub extern "c" fn kill(pid: pid_t, sig: c_int) c_int; -pub extern "c" fn getdirentries(fd: fd_t, buf_ptr: [*]u8, nbytes: usize, basep: *i64) isize; +pub extern "c" fn kill(pid: c.pid_t, sig: c_int) c_int; +pub extern "c" fn getdirentries(fd: c.fd_t, buf_ptr: [*]u8, nbytes: usize, basep: *i64) isize; -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 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 malloc(usize) ?*c_void; pub extern "c" fn realloc(?*c_void, usize) ?*c_void; pub extern "c" fn free(?*c_void) void; -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 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 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 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 pthread_create(noalias newthread: *pthread_t, noalias attr: ?*const pthread_attr_t, start_routine: fn (?*c_void) callconv(.C) ?*c_void, noalias arg: ?*c_void) 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: *c_void, 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_create(noalias newthread: *pthread_t, noalias attr: ?*const c.pthread_attr_t, start_routine: fn (?*c_void) callconv(.C) ?*c_void, noalias arg: ?*c_void) 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: *c_void, 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; pub extern "c" fn pthread_self() pthread_t; -pub extern "c" fn pthread_join(thread: pthread_t, arg_return: ?*?*c_void) E; -pub extern "c" fn pthread_detach(thread: pthread_t) E; +pub extern "c" fn pthread_join(thread: pthread_t, arg_return: ?*?*c_void) c.E; +pub extern "c" fn pthread_detach(thread: pthread_t) c.E; pub extern "c" fn pthread_atfork( prepare: ?fn () callconv(.C) void, parent: ?fn () callconv(.C) void, child: ?fn () callconv(.C) void, ) c_int; -pub extern "c" fn pthread_key_create(key: *pthread_key_t, destructor: ?fn (value: *c_void) callconv(.C) void) E; -pub extern "c" fn pthread_key_delete(key: pthread_key_t) E; -pub extern "c" fn pthread_getspecific(key: pthread_key_t) ?*c_void; -pub extern "c" fn pthread_setspecific(key: pthread_key_t, value: ?*c_void) c_int; -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_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 pthread_key_create(key: *c.pthread_key_t, destructor: ?fn (value: *c_void) 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) ?*c_void; +pub extern "c" fn pthread_setspecific(key: c.pthread_key_t, value: ?*c_void) 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_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 kqueue() c_int; pub extern "c" fn kevent( kq: c_int, - changelist: [*]const Kevent, + changelist: [*]const c.Kevent, nchanges: c_int, - eventlist: [*]Kevent, + eventlist: [*]c.Kevent, nevents: c_int, - timeout: ?*const timespec, + timeout: ?*const c.timespec, ) c_int; pub extern "c" fn getaddrinfo( noalias node: ?[*:0]const u8, noalias service: ?[*:0]const u8, - noalias hints: ?*const addrinfo, - noalias res: **addrinfo, -) EAI; + noalias hints: ?*const c.addrinfo, + noalias res: **c.addrinfo, +) c.EAI; -pub extern "c" fn freeaddrinfo(res: *addrinfo) void; +pub extern "c" fn freeaddrinfo(res: *c.addrinfo) void; pub extern "c" fn getnameinfo( - noalias addr: *const sockaddr, - addrlen: socklen_t, + noalias addr: *const c.sockaddr, + addrlen: c.socklen_t, noalias host: [*]u8, - hostlen: socklen_t, + hostlen: c.socklen_t, noalias serv: [*]u8, - servlen: socklen_t, + servlen: c.socklen_t, flags: u32, -) EAI; +) c.EAI; -pub extern "c" fn gai_strerror(errcode: EAI) [*:0]const u8; +pub extern "c" fn gai_strerror(errcode: c.EAI) [*:0]const u8; -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 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 dn_expand( msg: [*:0]const u8, @@ -392,25 +316,25 @@ pub extern "c" fn dn_expand( length: c_int, ) c_int; -pub const PTHREAD_MUTEX_INITIALIZER = pthread_mutex_t{}; -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) 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_MUTEX_INITIALIZER = c.pthread_mutex_t{}; +pub extern "c" fn pthread_mutex_lock(mutex: *c.pthread_mutex_t) c.E; +pub extern "c" fn pthread_mutex_unlock(mutex: *c.pthread_mutex_t) c.E; +pub extern "c" fn pthread_mutex_trylock(mutex: *c.pthread_mutex_t) c.E; +pub extern "c" fn pthread_mutex_destroy(mutex: *c.pthread_mutex_t) c.E; + +pub const PTHREAD_COND_INITIALIZER = c.pthread_cond_t{}; +pub extern "c" fn pthread_cond_wait(noalias cond: *c.pthread_cond_t, noalias mutex: *c.pthread_mutex_t) c.E; +pub extern "c" fn pthread_cond_timedwait(noalias cond: *c.pthread_cond_t, noalias mutex: *c.pthread_mutex_t, noalias abstime: *const c.timespec) c.E; +pub extern "c" fn pthread_cond_signal(cond: *c.pthread_cond_t) c.E; +pub extern "c" fn pthread_cond_broadcast(cond: *c.pthread_cond_t) c.E; +pub extern "c" fn pthread_cond_destroy(cond: *c.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 const pthread_t = *opaque {}; pub const FILE = opaque {}; @@ -426,8 +350,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: rlimit_resource, rlim: *rlimit) c_int; -pub extern "c" fn setrlimit(resource: rlimit_resource, rlim: *const rlimit) 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 fmemopen(noalias buf: ?*c_void, size: usize, noalias mode: [*:0]const u8) ?*FILE; diff --git a/lib/std/c/darwin.zig b/lib/std/c/darwin.zig index a79c318fb5..75e0d32f49 100644 --- a/lib/std/c/darwin.zig +++ b/lib/std/c/darwin.zig @@ -4,6 +4,7 @@ const builtin = @import("builtin"); const macho = std.macho; const native_arch = builtin.target.cpu.arch; const maxInt = std.math.maxInt; +const iovec_const = std.os.iovec_const; extern "c" fn __error() *c_int; pub extern "c" fn NSVersionOfRunTimeLibrary(library_name: [*:0]const u8) u32; @@ -84,8 +85,6 @@ pub const _errno = __error; 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 extern "c" fn host_get_clock_service(host: host_t, clock_id: clock_id_t, clock_serv: ?[*]clock_serv_t) kern_return_t; -pub extern "c" fn mach_port_deallocate(task: ipc_space_t, name: mach_port_name_t) kern_return_t; pub const sf_hdtr = extern struct { headers: [*]const iovec_const, @@ -1550,19 +1549,17 @@ pub fn S_IWHT(m: u32) bool { pub const HOST_NAME_MAX = 72; -pub const AT_FDCWD = -2; - -/// Use effective ids in access check -pub const AT_EACCESS = 0x0010; - -/// Act on the symlink itself not the target -pub const AT_SYMLINK_NOFOLLOW = 0x0020; - -/// Act on target of symlink -pub const AT_SYMLINK_FOLLOW = 0x0040; - -/// Path refers to directory -pub const AT_REMOVEDIR = 0x0080; +pub const AT = struct { + pub const FDCWD = -2; + /// Use effective ids in access check + pub const EACCESS = 0x0010; + /// Act on the symlink itself not the target + pub const SYMLINK_NOFOLLOW = 0x0020; + /// Act on target of symlink + pub const SYMLINK_FOLLOW = 0x0040; + /// Path refers to directory + pub const REMOVEDIR = 0x0080; +}; pub const addrinfo = extern struct { flags: i32, @@ -1590,164 +1587,117 @@ pub const RTLD = struct { pub const MAIN_ONLY = @intToPtr(*c_void, @bitCast(usize, @as(isize, -5))); }; -/// duplicate file descriptor -pub const F_DUPFD = 0; - -/// get file descriptor flags -pub const F_GETFD = 1; - -/// set file descriptor flags -pub const F_SETFD = 2; - -/// get file status flags -pub const F_GETFL = 3; - -/// set file status flags -pub const F_SETFL = 4; - -/// get SIGIO/SIGURG proc/pgrp -pub const F_GETOWN = 5; - -/// set SIGIO/SIGURG proc/pgrp -pub const F_SETOWN = 6; - -/// get record locking information -pub const F_GETLK = 7; - -/// set record locking information -pub const F_SETLK = 8; - -/// F_SETLK; wait if blocked -pub const F_SETLKW = 9; - -/// F_SETLK; wait if blocked, return on timeout -pub const F_SETLKWTIMEOUT = 10; -pub const F_FLUSH_DATA = 40; - -/// Used for regression test -pub const F_CHKCLEAN = 41; - -/// Preallocate storage -pub const F_PREALLOCATE = 42; - -/// Truncate a file without zeroing space -pub const F_SETSIZE = 43; - -/// Issue an advisory read async with no copy to user -pub const F_RDADVISE = 44; - -/// turn read ahead off/on for this fd -pub const F_RDAHEAD = 45; - -/// turn data caching off/on for this fd -pub const F_NOCACHE = 48; - -/// file offset to device offset -pub const F_LOG2PHYS = 49; - -/// return the full path of the fd -pub const F_GETPATH = 50; - -/// fsync + ask the drive to flush to the media -pub const F_FULLFSYNC = 51; - -/// find which component (if any) is a package -pub const F_PATHPKG_CHECK = 52; - -/// "freeze" all fs operations -pub const F_FREEZE_FS = 53; - -/// "thaw" all fs operations -pub const F_THAW_FS = 54; - -/// turn data caching off/on (globally) for this file -pub const F_GLOBAL_NOCACHE = 55; - -/// add detached signatures -pub const F_ADDSIGS = 59; - -/// add signature from same file (used by dyld for shared libs) -pub const F_ADDFILESIGS = 61; - -/// used in conjunction with F_NOCACHE to indicate that DIRECT, synchonous writes -/// should not be used (i.e. its ok to temporaily create cached pages) -pub const F_NODIRECT = 62; - -///Get the protection class of a file from the EA, returns int -pub const F_GETPROTECTIONCLASS = 63; - -///Set the protection class of a file for the EA, requires int -pub const F_SETPROTECTIONCLASS = 64; - -///file offset to device offset, extended -pub const F_LOG2PHYS_EXT = 65; - -///get record locking information, per-process -pub const F_GETLKPID = 66; - -///Mark the file as being the backing store for another filesystem -pub const F_SETBACKINGSTORE = 70; - -///return the full path of the FD, but error in specific mtmd circumstances -pub const F_GETPATH_MTMINFO = 71; - -///Returns the code directory, with associated hashes, to the caller -pub const F_GETCODEDIR = 72; - -///No SIGPIPE generated on EPIPE -pub const F_SETNOSIGPIPE = 73; - -///Status of SIGPIPE for this fd -pub const F_GETNOSIGPIPE = 74; - -///For some cases, we need to rewrap the key for AKS/MKB -pub const F_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 F_SINGLE_WRITER = 76; - -///Get the protection version number for this filesystem -pub const F_GETPROTECTIONLEVEL = 77; - -///Add detached code signatures (used by dyld for shared libs) -pub const F_FINDSIGS = 78; - -///Add signature from same file, only if it is signed by Apple (used by dyld for simulator) -pub const F_ADDFILESIGS_FOR_DYLD_SIM = 83; - -///fsync + issue barrier to drive -pub const F_BARRIERFSYNC = 85; - -///Add signature from same file, return end offset in structure on success -pub const F_ADDFILESIGS_RETURN = 97; - -///Check if Library Validation allows this Mach-O file to be mapped into the calling process -pub const F_CHECK_LV = 98; - -///Deallocate a range of the file -pub const F_PUNCHHOLE = 99; - -///Trim an active file -pub const F_TRIM_ACTIVE_FILE = 100; +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, synchonous writes + /// should not be used (i.e. its ok to temporaily 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; -///mark the dup with FD_CLOEXEC -pub const F_DUPFD_CLOEXEC = 67; - ///close-on-exec flag pub const FD_CLOEXEC = 1; -/// shared or read lock -pub const F_RDLCK = 1; - -/// unlock -pub const F_UNLCK = 2; - -/// exclusive or write lock -pub const F_WRLCK = 3; - pub const LOCK = struct { pub const SH = 1; pub const EX = 2; diff --git a/lib/std/c/dragonfly.zig b/lib/std/c/dragonfly.zig index 929ddfc443..427a08262d 100644 --- a/lib/std/c/dragonfly.zig +++ b/lib/std/c/dragonfly.zig @@ -1,5 +1,6 @@ const std = @import("../std.zig"); const maxInt = std.math.maxInt; +const iovec = std.os.iovec; extern "c" threadlocal var errno: c_int; pub fn _errno() *c_int { @@ -353,18 +354,39 @@ pub const SEEK_END = 2; pub const SEEK_DATA = 3; pub const SEEK_HOLE = 4; -pub const F_ULOCK = 0; -pub const F_LOCK = 1; -pub const F_TLOCK = 2; -pub const F_TEST = 3; +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 FD_CLOEXEC = 1; -pub const AT_FDCWD = -328243; -pub const AT_SYMLINK_NOFOLLOW = 1; -pub const AT_REMOVEDIR = 2; -pub const AT_EACCESS = 4; -pub const AT_SYMLINK_FOLLOW = 8; +pub const AT = struct { + pub const FDCWD = -328243; + pub const SYMLINK_NOFOLLOW = 1; + pub const REMOVEDIR = 2; + pub const EACCESS = 4; + pub const SYMLINK_FOLLOW = 8; +}; pub fn WEXITSTATUS(s: u32) u8 { return @intCast(u8, (s & 0xff00) >> 8); @@ -715,7 +737,7 @@ pub const PF = struct { pub const ISDN = AF.ISDN; pub const RTIP = AF.pseudo_RTIP; pub const LAT = AF.LAT; - pub const UNIX = PF_LOCAL; + pub const UNIX = PF.LOCAL; pub const XTP = AF.pseudo_XTP; pub const DECnet = AF.DECnet; }; @@ -868,23 +890,6 @@ pub const MADV = struct { pub const SETMAP = 11; }; -pub const F_DUPFD = 0; -pub const F_GETFD = 1; -pub const F_RDLCK = 1; -pub const F_SETFD = 2; -pub const F_UNLCK = 2; -pub const F_WRLCK = 3; -pub const F_GETFL = 3; -pub const F_SETFL = 4; -pub const F_GETOWN = 5; -pub const F_SETOWN = 6; -pub const F_GETLK = 7; -pub const F_SETLK = 8; -pub const F_SETLKW = 9; -pub const F_DUP2FD = 10; -pub const F_DUPFD_CLOEXEC = 17; -pub const F_DUP2FD_CLOEXEC = 18; - pub const LOCK = struct { pub const SH = 1; pub const EX = 2; diff --git a/lib/std/c/freebsd.zig b/lib/std/c/freebsd.zig index 0ad05d41d0..5c9cf82b09 100644 --- a/lib/std/c/freebsd.zig +++ b/lib/std/c/freebsd.zig @@ -1,5 +1,8 @@ const std = @import("../std.zig"); +const builtin = @import("builtin"); const maxInt = std.math.maxInt; +const iovec = std.os.iovec; +const iovec_const = std.os.iovec_const; extern "c" fn __error() *c_int; pub const _errno = __error; @@ -400,60 +403,100 @@ pub const MAP = struct { pub const @"32BIT" = 0x00080000; }; -pub const WNOHANG = 1; -pub const WUNTRACED = 2; -pub const WSTOPPED = WUNTRACED; -pub const WCONTINUED = 4; -pub const WNOWAIT = 8; -pub const WEXITED = 16; -pub const WTRAPPED = 32; - -pub const SA_ONSTACK = 0x0001; -pub const SA_RESTART = 0x0002; -pub const SA_RESETHAND = 0x0004; -pub const SA_NOCLDSTOP = 0x0008; -pub const SA_NODEFER = 0x0010; -pub const SA_NOCLDWAIT = 0x0020; -pub const SA_SIGINFO = 0x0040; - -pub const SIGHUP = 1; -pub const SIGINT = 2; -pub const SIGQUIT = 3; -pub const SIGILL = 4; -pub const SIGTRAP = 5; -pub const SIGABRT = 6; -pub const SIGIOT = SIGABRT; -pub const SIGEMT = 7; -pub const SIGFPE = 8; -pub const SIGKILL = 9; -pub const SIGBUS = 10; -pub const SIGSEGV = 11; -pub const SIGSYS = 12; -pub const SIGPIPE = 13; -pub const SIGALRM = 14; -pub const SIGTERM = 15; -pub const SIGURG = 16; -pub const SIGSTOP = 17; -pub const SIGTSTP = 18; -pub const SIGCONT = 19; -pub const SIGCHLD = 20; -pub const SIGTTIN = 21; -pub const SIGTTOU = 22; -pub const SIGIO = 23; -pub const SIGXCPU = 24; -pub const SIGXFSZ = 25; -pub const SIGVTALRM = 26; -pub const SIGPROF = 27; -pub const SIGWINCH = 28; -pub const SIGINFO = 29; -pub const SIGUSR1 = 30; -pub const SIGUSR2 = 31; -pub const SIGTHR = 32; -pub const SIGLWP = SIGTHR; -pub const SIGLIBRT = 33; - -pub const SIGRTMIN = 65; -pub const SIGRTMAX = 126; +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 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 = @intToPtr(?Sigaction.sigaction_fn, 0); + pub const IGN = @intToPtr(?Sigaction.sigaction_fn, 1); + pub const ERR = @intToPtr(?Sigaction.sigaction_fn, 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; + } +}; +pub const sigval = extern union { + int: c_int, + ptr: ?*c_void, +}; + +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 @@ -489,22 +532,29 @@ pub const O_PATH = 0o10000000; pub const O_TMPFILE = 0o20200000; pub const O_NDELAY = O_NONBLOCK; -pub const F_DUPFD = 0; -pub const F_GETFD = 1; -pub const F_SETFD = 2; -pub const F_GETFL = 3; -pub const F_SETFL = 4; +pub const F = 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 F_GETOWN = 5; -pub const F_SETOWN = 6; + pub const GETLK = 11; + pub const SETLK = 12; + pub const SETLKW = 13; -pub const F_GETLK = 11; -pub const F_SETLK = 12; -pub const F_SETLKW = 13; + pub const RDLCK = 1; + pub const WRLCK = 3; + pub const UNLCK = 2; -pub const F_RDLCK = 1; -pub const F_WRLCK = 3; -pub const F_UNLCK = 2; + pub const SETOWN_EX = 15; + pub const GETOWN_EX = 16; + + pub const GETOWNER_UIDS = 17; +}; pub const LOCK = struct { pub const SH = 1; @@ -513,21 +563,12 @@ pub const LOCK = struct { pub const NB = 4; }; -pub const F_SETOWN_EX = 15; -pub const F_GETOWN_EX = 16; - -pub const F_GETOWNER_UIDS = 17; - pub const FD_CLOEXEC = 1; pub const SEEK_SET = 0; pub const SEEK_CUR = 1; pub const SEEK_END = 2; -pub const SIG_BLOCK = 1; -pub const SIG_UNBLOCK = 2; -pub const SIG_SETMASK = 3; - pub const SOCK = struct { pub const STREAM = 1; pub const DGRAM = 2; @@ -890,10 +931,6 @@ pub const winsize = extern struct { const NSIG = 32; -pub const SIG_DFL = @intToPtr(?Sigaction.sigaction_fn, 0); -pub const SIG_IGN = @intToPtr(?Sigaction.sigaction_fn, 1); -pub const SIG_ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize)); - /// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. pub const Sigaction = extern struct { pub const handler_fn = fn (c_int) callconv(.C) void; @@ -942,34 +979,7 @@ pub const siginfo_t = extern struct { }, }; -pub const sigval = extern union { - int: c_int, - ptr: ?*c_void, -}; - -pub const _SIG_WORDS = 4; -pub const _SIG_MAXSIG = 128; - -pub inline fn _SIG_IDX(sig: usize) usize { - return sig - 1; -} -pub inline fn _SIG_WORD(sig: usize) usize { - return_SIG_IDX(sig) >> 5; -} -pub inline fn _SIG_BIT(sig: usize) usize { - return 1 << (_SIG_IDX(sig) & 31); -} -pub inline fn _SIG_VALID(sig: usize) usize { - return sig <= _SIG_MAXSIG and sig > 0; -} - -pub const sigset_t = extern struct { - __bits: [_SIG_WORDS]u32, -}; - -pub const empty_sigset = sigset_t{ .__bits = [_]u32{0} ** _SIG_WORDS }; - -const arch_bits = switch (builtin.cpu.arch) { +pub usingnamespace switch (builtin.cpu.arch) { .x86_64 => struct { pub const ucontext_t = extern struct { sigmask: sigset_t, @@ -1015,8 +1025,6 @@ const arch_bits = switch (builtin.cpu.arch) { }, else => struct {}, }; -pub const ucontext_t = arch_bits.ucontext_t; -pub const mcontext_t = arch_bits.mcontext_t; pub const E = enum(u16) { /// No error occurred. @@ -1224,22 +1232,22 @@ pub fn S_IWHT(m: u32) bool { pub const HOST_NAME_MAX = 255; -/// 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 AT_FDCWD = -100; - -/// Check access using effective user and group ID -pub const AT_EACCESS = 0x0100; - -/// Do not follow symbolic links -pub const AT_SYMLINK_NOFOLLOW = 0x0200; - -/// Follow symbolic link -pub const AT_SYMLINK_FOLLOW = 0x0400; - -/// Remove directory instead of file -pub const AT_REMOVEDIR = 0x0800; +pub const AT = struct { + /// 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 = -100; + /// Check access using effective user and group ID + pub const EACCESS = 0x0100; + /// Do not follow symbolic links + pub const SYMLINK_NOFOLLOW = 0x0200; + /// Follow symbolic link + pub const SYMLINK_FOLLOW = 0x0400; + /// Remove directory instead of file + pub const REMOVEDIR = 0x0800; + /// Fail if not under dirfd + pub const BENEATH = 0x1000; +}; pub const addrinfo = extern struct { flags: i32, @@ -1252,9 +1260,6 @@ pub const addrinfo = extern struct { next: ?*addrinfo, }; -/// Fail if not under dirfd -pub const AT_BENEATH = 0x1000; - pub const IPPROTO = struct { /// dummy for IP pub const IP = 0; diff --git a/lib/std/c/generic.zig b/lib/std/c/generic.zig deleted file mode 100644 index 6580eee520..0000000000 --- a/lib/std/c/generic.zig +++ /dev/null @@ -1,23 +0,0 @@ -const std = @import("../std.zig"); -const Stat = std.c.Stat; -const timespec = std.c.timespec; -const Sigaction = std.c.Sigaction; -const sigset_t = std.c.sigset_t; -const rusage = std.c.rusage; - -pub extern "c" fn realpath(noalias file_name: [*:0]const u8, noalias resolved_name: [*]u8) ?[*:0]u8; -pub extern "c" fn fstatat(dirfd: fd_t, path: [*:0]const u8, stat_buf: *Stat, flags: u32) c_int; -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 fstat(fd: fd_t, buf: *Stat) 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 socket(domain: c_uint, sock_type: c_uint, protocol: c_uint) 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; diff --git a/lib/std/c/haiku.zig b/lib/std/c/haiku.zig index caa78dd864..b5aa325908 100644 --- a/lib/std/c/haiku.zig +++ b/lib/std/c/haiku.zig @@ -1,5 +1,8 @@ const std = @import("../std.zig"); +const builtin = @import("builtin"); const maxInt = std.math.maxInt; +const iovec = std.os.iovec; +const iovec_const = std.os.iovec_const; extern "c" fn _errnop() *c_int; @@ -421,43 +424,64 @@ pub const SA_NOMASK = SA_NODEFER; pub const SA_STACK = SA_ONSTACK; pub const SA_ONESHOT = SA_RESETHAND; -pub const SIGHUP = 1; -pub const SIGINT = 2; -pub const SIGQUIT = 3; -pub const SIGILL = 4; -pub const SIGCHLD = 5; -pub const SIGABRT = 6; -pub const SIGIOT = SIGABRT; -pub const SIGPIPE = 7; -pub const SIGFPE = 8; -pub const SIGKILL = 9; -pub const SIGSTOP = 10; -pub const SIGSEGV = 11; -pub const SIGCONT = 12; -pub const SIGTSTP = 13; -pub const SIGALRM = 14; -pub const SIGTERM = 15; -pub const SIGTTIN = 16; -pub const SIGTTOU = 17; -pub const SIGUSR1 = 18; -pub const SIGUSR2 = 19; -pub const SIGWINCH = 20; -pub const SIGKILLTHR = 21; -pub const SIGTRAP = 22; -pub const SIGPOLL = 23; -pub const SIGPROF = 24; -pub const SIGSYS = 25; -pub const SIGURG = 26; -pub const SIGVTALRM = 27; -pub const SIGXCPU = 28; -pub const SIGXFSZ = 29; -pub const SIGBUS = 30; -pub const SIGRESERVED1 = 31; -pub const SIGRESERVED2 = 32; - -// TODO: check -pub const SIGRTMIN = 65; -pub const SIGRTMAX = 126; +pub const SIG = struct { + 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; + + // TODO: check + pub const RTMIN = 65; + pub const RTMAX = 126; + + pub const BLOCK = 1; + pub const UNBLOCK = 2; + pub const SETMASK = 3; + + 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; + } +}; // access function pub const F_OK = 0; // test for existence of file @@ -493,22 +517,29 @@ pub const O_PATH = 0o10000000; pub const O_TMPFILE = 0o20200000; pub const O_NDELAY = O_NONBLOCK; -pub const F_DUPFD = 0; -pub const F_GETFD = 1; -pub const F_SETFD = 2; -pub const F_GETFL = 3; -pub const F_SETFL = 4; +pub const F = 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 F_GETOWN = 5; -pub const F_SETOWN = 6; + pub const GETLK = 11; + pub const SETLK = 12; + pub const SETLKW = 13; -pub const F_GETLK = 11; -pub const F_SETLK = 12; -pub const F_SETLKW = 13; + pub const RDLCK = 1; + pub const WRLCK = 3; + pub const UNLCK = 2; -pub const F_RDLCK = 1; -pub const F_WRLCK = 3; -pub const F_UNLCK = 2; + pub const SETOWN_EX = 15; + pub const GETOWN_EX = 16; + + pub const GETOWNER_UIDS = 17; +}; pub const LOCK = struct { pub const SH = 1; @@ -517,21 +548,12 @@ pub const LOCK = struct { pub const NB = 4; }; -pub const F_SETOWN_EX = 15; -pub const F_GETOWN_EX = 16; - -pub const F_GETOWNER_UIDS = 17; - pub const FD_CLOEXEC = 1; pub const SEEK_SET = 0; pub const SEEK_CUR = 1; pub const SEEK_END = 2; -pub const SIG_BLOCK = 1; -pub const SIG_UNBLOCK = 2; -pub const SIG_SETMASK = 3; - pub const SOCK = struct { pub const STREAM = 1; pub const DGRAM = 2; @@ -615,7 +637,7 @@ pub const PF = struct { pub const SIP = AF.SIP; pub const IPX = AF.IPX; pub const RTIP = AF.pseudo_RTIP; - pub const PIP = psuedo_AF.PIP; + pub const PIP = AF.pseudo_PIP; pub const ISDN = AF.ISDN; pub const KEY = AF.pseudo_KEY; pub const INET6 = AF.pseudo_INET6; @@ -816,7 +838,6 @@ pub const Sigaction = extern struct { /// signal handler __sigaction_u: extern union { __sa_handler: fn (i32) callconv(.C) void, - __sa_sigaction: fn (i32, *__siginfo, usize) callconv(.C) void, }, /// see signal options @@ -826,23 +847,8 @@ pub const Sigaction = extern struct { sa_mask: sigset_t, }; -pub const _SIG_WORDS = 4; -pub const _SIG_MAXSIG = 128; -pub inline fn _SIG_IDX(sig: usize) usize { - return sig - 1; -} -pub inline fn _SIG_WORD(sig: usize) usize { - return_SIG_IDX(sig) >> 5; -} -pub inline fn _SIG_BIT(sig: usize) usize { - return 1 << (_SIG_IDX(sig) & 31); -} -pub inline fn _SIG_VALID(sig: usize) usize { - return sig <= _SIG_MAXSIG and sig > 0; -} - pub const sigset_t = extern struct { - __bits: [_SIG_WORDS]u32, + __bits: [SIG.WORDS]u32, }; pub const E = enum(i32) { @@ -1047,22 +1053,22 @@ pub fn S_IWHT(m: u32) bool { pub const HOST_NAME_MAX = 255; -/// 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 AT_FDCWD = -100; - -/// Check access using effective user and group ID -pub const AT_EACCESS = 0x0100; - -/// Do not follow symbolic links -pub const AT_SYMLINK_NOFOLLOW = 0x0200; - -/// Follow symbolic link -pub const AT_SYMLINK_FOLLOW = 0x0400; - -/// Remove directory instead of file -pub const AT_REMOVEDIR = 0x0800; +pub const AT = struct { + /// 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 = -100; + /// Check access using effective user and group ID + pub const EACCESS = 0x0100; + /// Do not follow symbolic links + pub const SYMLINK_NOFOLLOW = 0x0200; + /// Follow symbolic link + pub const SYMLINK_FOLLOW = 0x0400; + /// Remove directory instead of file + pub const REMOVEDIR = 0x0800; + /// Fail if not under dirfd + pub const BENEATH = 0x1000; +}; pub const addrinfo = extern struct { flags: i32, @@ -1075,9 +1081,6 @@ pub const addrinfo = extern struct { next: ?*addrinfo, }; -/// Fail if not under dirfd -pub const AT_BENEATH = 0x1000; - pub const IPPROTO = struct { /// dummy for IP pub const IP = 0; diff --git a/lib/std/c/hermit.zig b/lib/std/c/hermit.zig index ae13840e16..879346ba13 100644 --- a/lib/std/c/hermit.zig +++ b/lib/std/c/hermit.zig @@ -1,3 +1,6 @@ +const std = @import("std"); +const maxInt = std.math.maxInt; + pub const pthread_mutex_t = extern struct { inner: usize = ~@as(usize, 0), }; @@ -5,5 +8,5 @@ pub const pthread_cond_t = extern struct { inner: usize = ~@as(usize, 0), }; pub const pthread_rwlock_t = extern struct { - ptr: usize = std.math.maxInt(usize), + ptr: usize = maxInt(usize), }; diff --git a/lib/std/c/linux.zig b/lib/std/c/linux.zig index 0043ca39af..00b88ecb02 100644 --- a/lib/std/c/linux.zig +++ b/lib/std/c/linux.zig @@ -6,6 +6,7 @@ const native_arch = builtin.cpu.arch; const linux = std.os.linux; const iovec = std.os.iovec; const iovec_const = std.os.iovec_const; +const FILE = std.c.FILE; pub const AF = linux.AF; pub const ARCH = linux.ARCH; diff --git a/lib/std/c/netbsd.zig b/lib/std/c/netbsd.zig index cd9eaee19c..c5bc633e01 100644 --- a/lib/std/c/netbsd.zig +++ b/lib/std/c/netbsd.zig @@ -1,6 +1,10 @@ const std = @import("../std.zig"); const builtin = @import("builtin"); const maxInt = std.math.maxInt; +const iovec = std.os.iovec; +const iovec_const = std.os.iovec_const; +const timezone = std.c.timezone; +const rusage = std.c.rusage; extern "c" fn __errno() *c_int; pub const _errno = __errno; @@ -12,56 +16,81 @@ pub extern "c" fn _lwp_self() lwpid_t; pub extern "c" fn pipe2(fds: *[2]fd_t, flags: u32) c_int; pub extern "c" fn arc4random_buf(buf: [*]u8, len: usize) void; + pub extern "c" fn __fstat50(fd: fd_t, buf: *Stat) c_int; +pub const fstat = __fstat50; + pub extern "c" fn __stat50(path: [*:0]const u8, buf: *Stat) c_int; +pub const stat = __stat50; + pub extern "c" fn __clock_gettime50(clk_id: c_int, tp: *timespec) c_int; +pub const clock_gettime = __clock_gettime50; + pub extern "c" fn __clock_getres50(clk_id: c_int, tp: *timespec) c_int; +pub const clock_getres = __clock_getres50; + 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 __nanosleep50(rqtp: *const timespec, rmtp: ?*timespec) c_int; +pub const nanosleep = __nanosleep50; + pub extern "c" fn __sigaction14(sig: c_int, noalias act: ?*const Sigaction, noalias oact: ?*Sigaction) c_int; +pub const sigaction = __sigaction14; + pub extern "c" fn __sigprocmask14(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*sigset_t) c_int; +pub const sigprocmask = __sigaction14; + pub extern "c" fn __socket30(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int; +pub const socket = __socket30; + pub extern "c" fn __gettimeofday50(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int; +pub const gettimeofday = __gettimeofday50; + pub extern "c" fn __getrusage50(who: c_int, usage: *rusage) c_int; -// libc aliases this as sched_yield +pub const getrusage = __getrusage50; + pub extern "c" fn __libc_thr_yield() c_int; +pub const sched_yield = __libc_thr_yield; pub extern "c" fn posix_memalign(memptr: *?*c_void, alignment: usize, size: usize) c_int; pub const pthread_mutex_t = extern struct { - ptm_magic: u32 = 0x33330003, - ptm_errorcheck: padded_pthread_spin_t = 0, - ptm_ceiling: padded_pthread_spin_t = 0, - ptm_owner: usize = 0, - ptm_waiters: ?*u8 = null, - ptm_recursed: u32 = 0, - ptm_spare2: ?*c_void = null, + magic: u32 = 0x33330003, + errorcheck: padded_pthread_spin_t = 0, + ceiling: padded_pthread_spin_t = 0, + owner: usize = 0, + waiters: ?*u8 = null, + recursed: u32 = 0, + spare2: ?*c_void = null, }; pub const pthread_cond_t = extern struct { - ptc_magic: u32 = 0x55550005, - ptc_lock: pthread_spin_t = 0, - ptc_waiters_first: ?*u8 = null, - ptc_waiters_last: ?*u8 = null, - ptc_mutex: ?*pthread_mutex_t = null, - ptc_private: ?*c_void = null, + magic: u32 = 0x55550005, + lock: pthread_spin_t = 0, + waiters_first: ?*u8 = null, + waiters_last: ?*u8 = null, + mutex: ?*pthread_mutex_t = null, + private: ?*c_void = null, }; pub const pthread_rwlock_t = extern struct { - ptr_magic: c_uint = 0x99990009, - ptr_interlock: switch (builtin.cpu.arch) { + magic: c_uint = 0x99990009, + interlock: switch (builtin.cpu.arch) { .aarch64, .sparc, .x86_64, .i386 => u8, .arm, .powerpc => c_int, else => unreachable, } = 0, - ptr_rblocked_first: ?*u8 = null, - ptr_rblocked_last: ?*u8 = null, - ptr_wblocked_first: ?*u8 = null, - ptr_wblocked_last: ?*u8 = null, - ptr_nreaders: c_uint = 0, - ptr_owner: std.c.pthread_t = null, - ptr_private: ?*c_void = null, + rblocked_first: ?*u8 = null, + rblocked_last: ?*u8 = null, + wblocked_first: ?*u8 = null, + wblocked_last: ?*u8 = null, + nreaders: c_uint = 0, + owner: std.c.pthread_t = null, + private: ?*c_void = null, }; const pthread_spin_t = switch (builtin.cpu.arch) { @@ -92,20 +121,6 @@ pub const sem_t = ?*opaque {}; pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8, arg: ?*c_void) E; pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) E; -pub const clock_getres = __clock_getres50; -pub const clock_gettime = __clock_gettime50; -pub const fstat = __fstat50; -pub const getdents = __getdents30; -pub const getrusage = __getrusage50; -pub const gettimeofday = __gettimeofday50; -pub const nanosleep = __nanosleep50; -pub const sched_yield = __libc_thr_yield; -pub const sigaction = __sigaction14; -pub const sigaltstack = __sigaltstack14; -pub const sigprocmask = __sigprocmask14; -pub const socket = __socket30; -pub const stat = __stat50; - pub const blkcnt_t = i64; pub const blksize_t = i32; pub const clock_t = u32; @@ -568,43 +583,6 @@ pub const SA_NODEFER = 0x0010; pub const SA_NOCLDWAIT = 0x0020; pub const SA_SIGINFO = 0x0040; -pub const SIGHUP = 1; -pub const SIGINT = 2; -pub const SIGQUIT = 3; -pub const SIGILL = 4; -pub const SIGTRAP = 5; -pub const SIGABRT = 6; -pub const SIGIOT = SIGABRT; -pub const SIGEMT = 7; -pub const SIGFPE = 8; -pub const SIGKILL = 9; -pub const SIGBUS = 10; -pub const SIGSEGV = 11; -pub const SIGSYS = 12; -pub const SIGPIPE = 13; -pub const SIGALRM = 14; -pub const SIGTERM = 15; -pub const SIGURG = 16; -pub const SIGSTOP = 17; -pub const SIGTSTP = 18; -pub const SIGCONT = 19; -pub const SIGCHLD = 20; -pub const SIGTTIN = 21; -pub const SIGTTOU = 22; -pub const SIGIO = 23; -pub const SIGXCPU = 24; -pub const SIGXFSZ = 25; -pub const SIGVTALRM = 26; -pub const SIGPROF = 27; -pub const SIGWINCH = 28; -pub const SIGINFO = 29; -pub const SIGUSR1 = 30; -pub const SIGUSR2 = 31; -pub const SIGPWR = 32; - -pub const SIGRTMIN = 33; -pub const SIGRTMAX = 63; - // access function pub const F_OK = 0; // test for existence of file pub const X_OK = 1; // test for execute or search permission @@ -677,22 +655,24 @@ pub const O_CLOEXEC = 0x00400000; /// skip search permission checks pub const O_SEARCH = 0x00800000; -pub const F_DUPFD = 0; -pub const F_GETFD = 1; -pub const F_SETFD = 2; -pub const F_GETFL = 3; -pub const F_SETFL = 4; +pub const F = struct { + pub const DUPFD = 0; + pub const GETFD = 1; + pub const SETFD = 2; + pub const GETFL = 3; + pub const SETFL = 4; -pub const F_GETOWN = 5; -pub const F_SETOWN = 6; + pub const GETOWN = 5; + pub const SETOWN = 6; -pub const F_GETLK = 7; -pub const F_SETLK = 8; -pub const F_SETLKW = 9; + pub const GETLK = 7; + pub const SETLK = 8; + pub const SETLKW = 9; -pub const F_RDLCK = 1; -pub const F_WRLCK = 3; -pub const F_UNLCK = 2; + pub const RDLCK = 1; + pub const WRLCK = 3; + pub const UNLCK = 2; +}; pub const LOCK = struct { pub const SH = 1; @@ -918,9 +898,64 @@ pub const winsize = extern struct { const NSIG = 32; -pub const SIG_DFL = @intToPtr(?Sigaction.sigaction_fn, 0); -pub const SIG_IGN = @intToPtr(?Sigaction.sigaction_fn, 1); -pub const SIG_ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize)); +pub const SIG = struct { + pub const DFL = @intToPtr(?Sigaction.sigaction_fn, 0); + pub const IGN = @intToPtr(?Sigaction.sigaction_fn, 1); + pub const ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize)); + + pub const WORDS = 4; + pub const MAXSIG = 128; + + 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 { @@ -993,27 +1028,11 @@ pub const _ksiginfo = extern struct { } align(@sizeOf(usize)), }; -pub const _SIG_WORDS = 4; -pub const _SIG_MAXSIG = 128; - -pub inline fn _SIG_IDX(sig: usize) usize { - return sig - 1; -} -pub inline fn _SIG_WORD(sig: usize) usize { - return_SIG_IDX(sig) >> 5; -} -pub inline fn _SIG_BIT(sig: usize) usize { - return 1 << (_SIG_IDX(sig) & 31); -} -pub inline fn _SIG_VALID(sig: usize) usize { - return sig <= _SIG_MAXSIG and sig > 0; -} - pub const sigset_t = extern struct { - __bits: [_SIG_WORDS]u32, + __bits: [SIG.WORDS]u32, }; -pub const empty_sigset = sigset_t{ .__bits = [_]u32{0} ** _SIG_WORDS }; +pub const empty_sigset = sigset_t{ .__bits = [_]u32{0} ** SIG.WORDS }; // XXX x86_64 specific pub const mcontext_t = extern struct { @@ -1253,22 +1272,20 @@ pub fn S_IWHT(m: u32) bool { return m & S_IFMT == S_IFWHT; } -/// 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 AT_FDCWD = -100; - -/// Check access using effective user and group ID -pub const AT_EACCESS = 0x0100; - -/// Do not follow symbolic links -pub const AT_SYMLINK_NOFOLLOW = 0x0200; - -/// Follow symbolic link -pub const AT_SYMLINK_FOLLOW = 0x0400; - -/// Remove directory instead of file -pub const AT_REMOVEDIR = 0x0800; +pub const AT = struct { + /// 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 = -100; + /// Check access using effective user and group ID + pub const EACCESS = 0x0100; + /// Do not follow symbolic links + pub const SYMLINK_NOFOLLOW = 0x0200; + /// Follow symbolic link + pub const SYMLINK_FOLLOW = 0x0400; + /// Remove directory instead of file + pub const REMOVEDIR = 0x0800; +}; pub const HOST_NAME_MAX = 255; diff --git a/lib/std/c/openbsd.zig b/lib/std/c/openbsd.zig index 9795a6064d..cd7632df3c 100644 --- a/lib/std/c/openbsd.zig +++ b/lib/std/c/openbsd.zig @@ -1,6 +1,8 @@ const std = @import("../std.zig"); const maxInt = std.math.maxInt; const builtin = @import("builtin"); +const iovec = std.os.iovec; +const iovec_const = std.os.iovec_const; extern "c" fn __errno() *c_int; pub const _errno = __errno; @@ -466,22 +468,24 @@ pub const O_DIRECTORY = 0x20000; /// set close on exec pub const O_CLOEXEC = 0x10000; -pub const F_DUPFD = 0; -pub const F_GETFD = 1; -pub const F_SETFD = 2; -pub const F_GETFL = 3; -pub const F_SETFL = 4; +pub const F = struct { + pub const DUPFD = 0; + pub const GETFD = 1; + pub const SETFD = 2; + pub const GETFL = 3; + pub const SETFL = 4; -pub const F_GETOWN = 5; -pub const F_SETOWN = 6; + pub const GETOWN = 5; + pub const SETOWN = 6; -pub const F_GETLK = 7; -pub const F_SETLK = 8; -pub const F_SETLKW = 9; + pub const GETLK = 7; + pub const SETLK = 8; + pub const SETLKW = 9; -pub const F_RDLCK = 1; -pub const F_UNLCK = 2; -pub const F_WRLCK = 3; + pub const RDLCK = 1; + pub const UNLCK = 2; + pub const WRLCK = 3; +}; pub const LOCK = struct { pub const SH = 0x01; @@ -840,7 +844,7 @@ const arch_bits = switch (builtin.cpu.arch) { sc_rsp: c_long, sc_ss: c_long, - sc_fpstate: fxsave64, + sc_fpstate: arch_bits.fxsave64, __sc_unused: c_int, sc_mask: c_int, sc_cookie: c_long, @@ -1063,22 +1067,20 @@ pub fn S_ISSOCK(m: u32) bool { return m & S_IFMT == S_IFSOCK; } -/// 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 AT_FDCWD = -100; - -/// Check access using effective user and group ID -pub const AT_EACCESS = 0x01; - -/// Do not follow symbolic links -pub const AT_SYMLINK_NOFOLLOW = 0x02; - -/// Follow symbolic link -pub const AT_SYMLINK_FOLLOW = 0x04; - -/// Remove directory instead of file -pub const AT_REMOVEDIR = 0x08; +pub const AT = struct { + /// 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 = -100; + /// Check access using effective user and group ID + pub const EACCESS = 0x01; + /// Do not follow symbolic links + pub const SYMLINK_NOFOLLOW = 0x02; + /// Follow symbolic link + pub const SYMLINK_FOLLOW = 0x04; + /// Remove directory instead of file + pub const REMOVEDIR = 0x08; +}; pub const HOST_NAME_MAX = 255; diff --git a/lib/std/c/wasi.zig b/lib/std/c/wasi.zig index 686965d42a..95eafd7fad 100644 --- a/lib/std/c/wasi.zig +++ b/lib/std/c/wasi.zig @@ -1,3 +1,7 @@ +const std = @import("../std.zig"); +const wasi = std.os.wasi; +const FDFLAG = wasi.FDFLAG; + extern threadlocal var errno: c_int; pub fn _errno() *c_int { @@ -9,6 +13,10 @@ 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.ino_t; +pub const mode_t = wasi.mode_t; +pub const time_t = wasi.time_t; +pub const timespec = wasi.timespec; pub const Stat = extern struct { dev: i32, @@ -57,22 +65,28 @@ pub const Stat = extern struct { /// https://github.com/WebAssembly/wasi-libc/blob/main/expected/wasm32-wasi/predefined-macros.txt pub const O = struct { pub const ACCMODE = (EXEC | RDWR | SEARCH); - pub const APPEND = FDFLAG_APPEND; + pub const APPEND = FDFLAG.APPEND; pub const CLOEXEC = (0); pub const CREAT = ((1 << 0) << 12); // = __WASI_OFLAGS_CREAT << 12 pub const DIRECTORY = ((1 << 1) << 12); // = __WASI_OFLAGS_DIRECTORY << 12 - pub const DSYNC = FDFLAG_DSYNC; + pub const DSYNC = FDFLAG.DSYNC; pub const EXCL = ((1 << 2) << 12); // = __WASI_OFLAGS_EXCL << 12 pub const EXEC = (0x02000000); pub const NOCTTY = (0); pub const NOFOLLOW = (0x01000000); - pub const NONBLOCK = (1 << FDFLAG_NONBLOCK); + pub const NONBLOCK = (1 << FDFLAG.NONBLOCK); pub const RDONLY = (0x04000000); pub const RDWR = (RDONLY | WRONLY); - pub const RSYNC = (1 << FDFLAG_RSYNC); + pub const RSYNC = (1 << FDFLAG.RSYNC); pub const SEARCH = (0x08000000); - pub const SYNC = (1 << FDFLAG_SYNC); + pub const SYNC = (1 << FDFLAG.SYNC); pub const TRUNC = ((1 << 3) << 12); // = __WASI_OFLAGS_TRUNC << 12 pub const TTY_INIT = (0); pub const WRONLY = (0x10000000); }; + +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; +}; diff --git a/lib/std/c/windows.zig b/lib/std/c/windows.zig index 4e9a9f2676..3a5b033022 100644 --- a/lib/std/c/windows.zig +++ b/lib/std/c/windows.zig @@ -1,7 +1,6 @@ //! 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; @@ -43,56 +42,51 @@ pub const timeval = extern struct { 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 - -/// interrupt -pub const SIGINT = 2; - -/// illegal instruction - invalid function image -pub const SIGILL = 4; - -/// floating point exception -pub const SIGFPE = 8; - -/// segment violation -pub const SIGSEGV = 11; - -/// Software termination signal from kill -pub const SIGTERM = 15; - -/// Ctrl-Break sequence -pub const SIGBREAK = 21; - -/// abnormal termination triggered by abort call -pub const SIGABRT = 22; - -/// SIGABRT compatible with other platforms, same as SIGABRT -pub const SIGABRT_COMPAT = 6; - -// Signal action codes - -/// default signal action -pub const SIG_DFL = 0; - -/// ignore signal -pub const SIG_IGN = 1; - -/// return current value -pub const SIG_GET = 2; - -/// signal gets error -pub const SIG_SGE = 3; - -/// acknowledge -pub const SIG_ACK = 4; - -/// Signal error value (returned by signal call on error) -pub const SIG_ERR = -1; +/// 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_SET = 0; pub const SEEK_CUR = 1; diff --git a/lib/std/crypto/25519/curve25519.zig b/lib/std/crypto/25519/curve25519.zig index 44a19362e4..20b0dccaa0 100644 --- a/lib/std/crypto/25519/curve25519.zig +++ b/lib/std/crypto/25519/curve25519.zig @@ -40,9 +40,7 @@ pub const Curve25519 = struct { } /// Multiply a point by the cofactor - pub fn clearCofactor(p: Edwards25519) Edwards25519 { - return p.dbl().dbl().dbl(); - } + pub const clearCofactor = @compileError("TODO what was this function supposed to do? it didn't compile successfully"); fn ladder(p: Curve25519, s: [32]u8, comptime bits: usize) IdentityElementError!Curve25519 { var x1 = p.x; diff --git a/lib/std/debug.zig b/lib/std/debug.zig index 540586a38f..8402f42e6d 100644 --- a/lib/std/debug.zig +++ b/lib/std/debug.zig @@ -1341,7 +1341,7 @@ pub const ModuleDebugInfo = switch (native_os) { if (o_file_di.findCompileUnit(relocated_address_o)) |compile_unit| { return SymbolInfo{ .symbol_name = o_file_di.getSymbolName(relocated_address_o) orelse "???", - .compile_unit_name = compile_unit.die.getAttrString(&o_file_di, DW.AT_name) catch |err| switch (err) { + .compile_unit_name = compile_unit.die.getAttrString(&o_file_di, DW.AT.name) catch |err| switch (err) { error.MissingDebugInfo, error.InvalidDebugInfo => "???", else => return err, }, @@ -1438,7 +1438,7 @@ fn getSymbolFromDwarf(address: u64, di: *DW.DwarfInfo) !SymbolInfo { if (nosuspend di.findCompileUnit(address)) |compile_unit| { return SymbolInfo{ .symbol_name = nosuspend di.getSymbolName(address) orelse "???", - .compile_unit_name = compile_unit.die.getAttrString(di, DW.AT_name) catch |err| switch (err) { + .compile_unit_name = compile_unit.die.getAttrString(di, DW.AT.name) catch |err| switch (err) { error.MissingDebugInfo, error.InvalidDebugInfo => "???", else => return err, }, diff --git a/lib/std/dwarf.zig b/lib/std/dwarf.zig index 3a294c2dd3..8f14f88e2e 100644 --- a/lib/std/dwarf.zig +++ b/lib/std/dwarf.zig @@ -9,7 +9,223 @@ const leb = @import("leb128.zig"); const ArrayList = std.ArrayList; -pub usingnamespace @import("dwarf_bits.zig"); +pub const TAG = @import("dwarf/TAG.zig"); +pub const AT = @import("dwarf/AT.zig"); +pub const OP = @import("dwarf/OP.zig"); + +pub const FORM = struct { + pub const addr = 0x01; + pub const block2 = 0x03; + pub const block4 = 0x04; + pub const data2 = 0x05; + pub const data4 = 0x06; + pub const data8 = 0x07; + pub const string = 0x08; + pub const block = 0x09; + pub const block1 = 0x0a; + pub const data1 = 0x0b; + pub const flag = 0x0c; + pub const sdata = 0x0d; + pub const strp = 0x0e; + pub const udata = 0x0f; + pub const ref_addr = 0x10; + pub const ref1 = 0x11; + pub const ref2 = 0x12; + pub const ref4 = 0x13; + pub const ref8 = 0x14; + pub const ref_udata = 0x15; + pub const indirect = 0x16; + pub const sec_offset = 0x17; + pub const exprloc = 0x18; + pub const flag_present = 0x19; + pub const ref_sig8 = 0x20; + + // Extensions for Fission. See http://gcc.gnu.org/wiki/DebugFission. + pub const GNU_addr_index = 0x1f01; + pub const GNU_str_index = 0x1f02; + + // Extensions for DWZ multifile. + // See http://www.dwarfstd.org/ShowIssue.php?issue=120604.1&type=open . + pub const GNU_ref_alt = 0x1f20; + pub const GNU_strp_alt = 0x1f21; +}; + +pub const ATE = struct { + pub const @"void" = 0x0; + pub const address = 0x1; + pub const boolean = 0x2; + pub const complex_float = 0x3; + pub const float = 0x4; + pub const signed = 0x5; + pub const signed_char = 0x6; + pub const unsigned = 0x7; + pub const unsigned_char = 0x8; + + // DWARF 3. + pub const imaginary_float = 0x9; + pub const packed_decimal = 0xa; + pub const numeric_string = 0xb; + pub const edited = 0xc; + pub const signed_fixed = 0xd; + pub const unsigned_fixed = 0xe; + pub const decimal_float = 0xf; + + // DWARF 4. + pub const UTF = 0x10; + + pub const lo_user = 0x80; + pub const hi_user = 0xff; + + // HP extensions. + pub const HP_float80 = 0x80; // Floating-point (80 bit). + pub const HP_complex_float80 = 0x81; // Complex floating-point (80 bit). + pub const HP_float128 = 0x82; // Floating-point (128 bit). + pub const HP_complex_float128 = 0x83; // Complex fp (128 bit). + pub const HP_floathpintel = 0x84; // Floating-point (82 bit IA64). + pub const HP_imaginary_float80 = 0x85; + pub const HP_imaginary_float128 = 0x86; + pub const HP_VAX_float = 0x88; // F or G floating. + pub const HP_VAX_float_d = 0x89; // D floating. + pub const HP_packed_decimal = 0x8a; // Cobol. + pub const HP_zoned_decimal = 0x8b; // Cobol. + pub const HP_edited = 0x8c; // Cobol. + pub const HP_signed_fixed = 0x8d; // Cobol. + pub const HP_unsigned_fixed = 0x8e; // Cobol. + pub const HP_VAX_complex_float = 0x8f; // F or G floating complex. + pub const HP_VAX_complex_float_d = 0x90; // D floating complex. +}; + +pub const CFA = struct { + pub const advance_loc = 0x40; + pub const offset = 0x80; + pub const restore = 0xc0; + pub const nop = 0x00; + pub const set_loc = 0x01; + pub const advance_loc1 = 0x02; + pub const advance_loc2 = 0x03; + pub const advance_loc4 = 0x04; + pub const offset_extended = 0x05; + pub const restore_extended = 0x06; + pub const @"undefined" = 0x07; + pub const same_value = 0x08; + pub const register = 0x09; + pub const remember_state = 0x0a; + pub const restore_state = 0x0b; + pub const def_cfa = 0x0c; + pub const def_cfa_register = 0x0d; + pub const def_cfa_offset = 0x0e; + + // DWARF 3. + pub const def_cfa_expression = 0x0f; + pub const expression = 0x10; + pub const offset_extended_sf = 0x11; + pub const def_cfa_sf = 0x12; + pub const def_cfa_offset_sf = 0x13; + pub const val_offset = 0x14; + pub const val_offset_sf = 0x15; + pub const val_expression = 0x16; + + pub const lo_user = 0x1c; + pub const hi_user = 0x3f; + + // SGI/MIPS specific. + pub const MIPS_advance_loc8 = 0x1d; + + // GNU extensions. + pub const GNU_window_save = 0x2d; + pub const GNU_args_size = 0x2e; + pub const GNU_negative_offset_extended = 0x2f; +}; + +pub const CHILDREN = struct { + pub const no = 0x00; + pub const yes = 0x01; +}; + +pub const LNS = struct { + pub const extended_op = 0x00; + pub const copy = 0x01; + pub const advance_pc = 0x02; + pub const advance_line = 0x03; + pub const set_file = 0x04; + pub const set_column = 0x05; + pub const negate_stmt = 0x06; + pub const set_basic_block = 0x07; + pub const const_add_pc = 0x08; + pub const fixed_advance_pc = 0x09; + pub const set_prologue_end = 0x0a; + pub const set_epilogue_begin = 0x0b; + pub const set_isa = 0x0c; +}; + +pub const LNE = struct { + pub const end_sequence = 0x01; + pub const set_address = 0x02; + pub const define_file = 0x03; + pub const set_discriminator = 0x04; + pub const lo_user = 0x80; + pub const hi_user = 0xff; +}; + +pub const LANG = struct { + pub const C89 = 0x0001; + pub const C = 0x0002; + pub const Ada83 = 0x0003; + pub const C_plus_plus = 0x0004; + pub const Cobol74 = 0x0005; + pub const Cobol85 = 0x0006; + pub const Fortran77 = 0x0007; + pub const Fortran90 = 0x0008; + pub const Pascal83 = 0x0009; + pub const Modula2 = 0x000a; + pub const Java = 0x000b; + pub const C99 = 0x000c; + pub const Ada95 = 0x000d; + pub const Fortran95 = 0x000e; + pub const PLI = 0x000f; + pub const ObjC = 0x0010; + pub const ObjC_plus_plus = 0x0011; + pub const UPC = 0x0012; + pub const D = 0x0013; + pub const Python = 0x0014; + pub const Go = 0x0016; + pub const C_plus_plus_11 = 0x001a; + pub const Rust = 0x001c; + pub const C11 = 0x001d; + pub const C_plus_plus_14 = 0x0021; + pub const Fortran03 = 0x0022; + pub const Fortran08 = 0x0023; + pub const lo_user = 0x8000; + pub const hi_user = 0xffff; + pub const Mips_Assembler = 0x8001; + pub const Upc = 0x8765; + pub const HP_Bliss = 0x8003; + pub const HP_Basic91 = 0x8004; + pub const HP_Pascal91 = 0x8005; + pub const HP_IMacro = 0x8006; + pub const HP_Assembler = 0x8007; +}; + +pub const UT = struct { + pub const compile = 0x01; + pub const @"type" = 0x02; + pub const partial = 0x03; + pub const skeleton = 0x04; + pub const split_compile = 0x05; + pub const split_type = 0x06; + pub const lo_user = 0x80; + pub const hi_user = 0xff; +}; + +pub const LNCT = struct { + pub const path = 0x1; + pub const directory_index = 0x2; + pub const timestamp = 0x3; + pub const size = 0x4; + pub const MD5 = 0x5; + pub const lo_user = 0x2000; + pub const hi_user = 0x3fff; +}; const PcRange = struct { start: u64, @@ -322,43 +538,43 @@ fn parseFormValueRef(allocator: *mem.Allocator, in_stream: anytype, endian: buil // TODO the nosuspends here are workarounds fn parseFormValue(allocator: *mem.Allocator, in_stream: anytype, form_id: u64, endian: builtin.Endian, is_64: bool) anyerror!FormValue { return switch (form_id) { - FORM_addr => FormValue{ .Address = try readAddress(in_stream, endian, @sizeOf(usize) == 8) }, - FORM_block1 => parseFormValueBlock(allocator, in_stream, endian, 1), - FORM_block2 => parseFormValueBlock(allocator, in_stream, endian, 2), - FORM_block4 => parseFormValueBlock(allocator, in_stream, endian, 4), - FORM_block => { + FORM.addr => FormValue{ .Address = try readAddress(in_stream, endian, @sizeOf(usize) == 8) }, + FORM.block1 => parseFormValueBlock(allocator, in_stream, endian, 1), + FORM.block2 => parseFormValueBlock(allocator, in_stream, endian, 2), + FORM.block4 => parseFormValueBlock(allocator, in_stream, endian, 4), + FORM.block => { const block_len = try nosuspend leb.readULEB128(usize, in_stream); return parseFormValueBlockLen(allocator, in_stream, block_len); }, - FORM_data1 => parseFormValueConstant(allocator, in_stream, false, endian, 1), - FORM_data2 => parseFormValueConstant(allocator, in_stream, false, endian, 2), - FORM_data4 => parseFormValueConstant(allocator, in_stream, false, endian, 4), - FORM_data8 => parseFormValueConstant(allocator, in_stream, false, endian, 8), - FORM_udata, FORM_sdata => { - const signed = form_id == FORM_sdata; + FORM.data1 => parseFormValueConstant(allocator, in_stream, false, endian, 1), + FORM.data2 => parseFormValueConstant(allocator, in_stream, false, endian, 2), + FORM.data4 => parseFormValueConstant(allocator, in_stream, false, endian, 4), + FORM.data8 => parseFormValueConstant(allocator, in_stream, false, endian, 8), + FORM.udata, FORM.sdata => { + const signed = form_id == FORM.sdata; return parseFormValueConstant(allocator, in_stream, signed, endian, -1); }, - FORM_exprloc => { + FORM.exprloc => { const size = try nosuspend leb.readULEB128(usize, in_stream); const buf = try readAllocBytes(allocator, in_stream, size); return FormValue{ .ExprLoc = buf }; }, - FORM_flag => FormValue{ .Flag = (try nosuspend in_stream.readByte()) != 0 }, - FORM_flag_present => FormValue{ .Flag = true }, - FORM_sec_offset => FormValue{ .SecOffset = try readAddress(in_stream, endian, is_64) }, - - FORM_ref1 => parseFormValueRef(allocator, in_stream, endian, 1), - FORM_ref2 => parseFormValueRef(allocator, in_stream, endian, 2), - FORM_ref4 => parseFormValueRef(allocator, in_stream, endian, 4), - FORM_ref8 => parseFormValueRef(allocator, in_stream, endian, 8), - FORM_ref_udata => parseFormValueRef(allocator, in_stream, endian, -1), - - FORM_ref_addr => FormValue{ .RefAddr = try readAddress(in_stream, endian, is_64) }, - FORM_ref_sig8 => FormValue{ .Ref = try nosuspend in_stream.readInt(u64, endian) }, - - FORM_string => FormValue{ .String = try in_stream.readUntilDelimiterAlloc(allocator, 0, math.maxInt(usize)) }, - FORM_strp => FormValue{ .StrPtr = try readAddress(in_stream, endian, is_64) }, - FORM_indirect => { + FORM.flag => FormValue{ .Flag = (try nosuspend in_stream.readByte()) != 0 }, + FORM.flag_present => FormValue{ .Flag = true }, + FORM.sec_offset => FormValue{ .SecOffset = try readAddress(in_stream, endian, is_64) }, + + FORM.ref1 => parseFormValueRef(allocator, in_stream, endian, 1), + FORM.ref2 => parseFormValueRef(allocator, in_stream, endian, 2), + FORM.ref4 => parseFormValueRef(allocator, in_stream, endian, 4), + FORM.ref8 => parseFormValueRef(allocator, in_stream, endian, 8), + FORM.ref_udata => parseFormValueRef(allocator, in_stream, endian, -1), + + FORM.ref_addr => FormValue{ .RefAddr = try readAddress(in_stream, endian, is_64) }, + FORM.ref_sig8 => FormValue{ .Ref = try nosuspend in_stream.readInt(u64, endian) }, + + FORM.string => FormValue{ .String = try in_stream.readUntilDelimiterAlloc(allocator, 0, math.maxInt(usize)) }, + FORM.strp => FormValue{ .StrPtr = try readAddress(in_stream, endian, is_64) }, + FORM.indirect => { const child_form_id = try nosuspend leb.readULEB128(u64, in_stream); const F = @TypeOf(async parseFormValue(allocator, in_stream, child_form_id, endian, is_64)); var frame = try allocator.create(F); @@ -441,24 +657,24 @@ pub const DwarfInfo = struct { const after_die_offset = try seekable.getPos(); switch (die_obj.tag_id) { - TAG_subprogram, TAG_inlined_subroutine, TAG_subroutine, TAG_entry_point => { + TAG.subprogram, TAG.inlined_subroutine, TAG.subroutine, TAG.entry_point => { const fn_name = x: { var depth: i32 = 3; var this_die_obj = die_obj; // Prenvent endless loops while (depth > 0) : (depth -= 1) { - if (this_die_obj.getAttr(AT_name)) |_| { - const name = try this_die_obj.getAttrString(di, AT_name); + if (this_die_obj.getAttr(AT.name)) |_| { + const name = try this_die_obj.getAttrString(di, AT.name); break :x name; - } else if (this_die_obj.getAttr(AT_abstract_origin)) |_| { + } else if (this_die_obj.getAttr(AT.abstract_origin)) |_| { // Follow the DIE it points to and repeat - const ref_offset = try this_die_obj.getAttrRef(AT_abstract_origin); + const ref_offset = try this_die_obj.getAttrRef(AT.abstract_origin); if (ref_offset > next_offset) return error.InvalidDebugInfo; try seekable.seekTo(this_unit_offset + ref_offset); this_die_obj = (try di.parseDie(in, abbrev_table, is_64)) orelse return error.InvalidDebugInfo; - } else if (this_die_obj.getAttr(AT_specification)) |_| { + } else if (this_die_obj.getAttr(AT.specification)) |_| { // Follow the DIE it points to and repeat - const ref_offset = try this_die_obj.getAttrRef(AT_specification); + const ref_offset = try this_die_obj.getAttrRef(AT.specification); if (ref_offset > next_offset) return error.InvalidDebugInfo; try seekable.seekTo(this_unit_offset + ref_offset); this_die_obj = (try di.parseDie(in, abbrev_table, is_64)) orelse return error.InvalidDebugInfo; @@ -471,8 +687,8 @@ pub const DwarfInfo = struct { }; const pc_range = x: { - if (die_obj.getAttrAddr(AT_low_pc)) |low_pc| { - if (die_obj.getAttr(AT_high_pc)) |high_pc_value| { + if (die_obj.getAttrAddr(AT.low_pc)) |low_pc| { + if (die_obj.getAttr(AT.high_pc)) |high_pc_value| { const pc_end = switch (high_pc_value.*) { FormValue.Address => |value| value, FormValue.Const => |value| b: { @@ -539,11 +755,11 @@ pub const DwarfInfo = struct { const compile_unit_die = try di.allocator().create(Die); compile_unit_die.* = (try di.parseDie(in, abbrev_table, is_64)) orelse return error.InvalidDebugInfo; - if (compile_unit_die.tag_id != TAG_compile_unit) return error.InvalidDebugInfo; + if (compile_unit_die.tag_id != TAG.compile_unit) return error.InvalidDebugInfo; const pc_range = x: { - if (compile_unit_die.getAttrAddr(AT_low_pc)) |low_pc| { - if (compile_unit_die.getAttr(AT_high_pc)) |high_pc_value| { + if (compile_unit_die.getAttrAddr(AT.low_pc)) |low_pc| { + if (compile_unit_die.getAttr(AT.high_pc)) |high_pc_value| { const pc_end = switch (high_pc_value.*) { FormValue.Address => |value| value, FormValue.Const => |value| b: { @@ -582,16 +798,16 @@ pub const DwarfInfo = struct { if (target_address >= range.start and target_address < range.end) return compile_unit; } if (di.debug_ranges) |debug_ranges| { - if (compile_unit.die.getAttrSecOffset(AT_ranges)) |ranges_offset| { + if (compile_unit.die.getAttrSecOffset(AT.ranges)) |ranges_offset| { var stream = io.fixedBufferStream(debug_ranges); const in = &stream.reader(); const seekable = &stream.seekableStream(); // All the addresses in the list are relative to the value - // specified by DW_AT_low_pc or to some other value encoded + // specified by DW_AT.low_pc or to some other value encoded // in the list itself. // If no starting value is specified use zero. - var base_address = compile_unit.die.getAttrAddr(AT_low_pc) catch |err| switch (err) { + var base_address = compile_unit.die.getAttrAddr(AT.low_pc) catch |err| switch (err) { error.MissingDebugInfo => 0, else => return err, }; @@ -651,7 +867,7 @@ pub const DwarfInfo = struct { try result.append(AbbrevTableEntry{ .abbrev_code = abbrev_code, .tag_id = try leb.readULEB128(u64, in), - .has_children = (try in.readByte()) == CHILDREN_yes, + .has_children = (try in.readByte()) == CHILDREN.yes, .attrs = ArrayList(AbbrevAttr).init(di.allocator()), }); const attrs = &result.items[result.items.len - 1].attrs; @@ -693,8 +909,8 @@ pub const DwarfInfo = struct { const in = &stream.reader(); const seekable = &stream.seekableStream(); - const compile_unit_cwd = try compile_unit.die.getAttrString(di, AT_comp_dir); - const line_info_offset = try compile_unit.die.getAttrSecOffset(AT_stmt_list); + const compile_unit_cwd = try compile_unit.die.getAttrString(di, AT.comp_dir); + const line_info_offset = try compile_unit.die.getAttrSecOffset(AT.stmt_list); try seekable.seekTo(line_info_offset); @@ -769,21 +985,21 @@ pub const DwarfInfo = struct { while ((try seekable.getPos()) < next_unit_pos) { const opcode = try in.readByte(); - if (opcode == LNS_extended_op) { + if (opcode == LNS.extended_op) { const op_size = try leb.readULEB128(u64, in); if (op_size < 1) return error.InvalidDebugInfo; var sub_op = try in.readByte(); switch (sub_op) { - LNE_end_sequence => { + LNE.end_sequence => { prog.end_sequence = true; if (try prog.checkLineMatch()) |info| return info; prog.reset(); }, - LNE_set_address => { + LNE.set_address => { const addr = try in.readInt(usize, di.endian); prog.address = addr; }, - LNE_define_file => { + LNE.define_file => { const file_name = try in.readUntilDelimiterAlloc(di.allocator(), 0, math.maxInt(usize)); const dir_index = try leb.readULEB128(usize, in); const mtime = try leb.readULEB128(usize, in); @@ -811,41 +1027,41 @@ pub const DwarfInfo = struct { prog.basic_block = false; } else { switch (opcode) { - LNS_copy => { + LNS.copy => { if (try prog.checkLineMatch()) |info| return info; prog.basic_block = false; }, - LNS_advance_pc => { + LNS.advance_pc => { const arg = try leb.readULEB128(usize, in); prog.address += arg * minimum_instruction_length; }, - LNS_advance_line => { + LNS.advance_line => { const arg = try leb.readILEB128(i64, in); prog.line += arg; }, - LNS_set_file => { + LNS.set_file => { const arg = try leb.readULEB128(usize, in); prog.file = arg; }, - LNS_set_column => { + LNS.set_column => { const arg = try leb.readULEB128(u64, in); prog.column = arg; }, - LNS_negate_stmt => { + LNS.negate_stmt => { prog.is_stmt = !prog.is_stmt; }, - LNS_set_basic_block => { + LNS.set_basic_block => { prog.basic_block = true; }, - LNS_const_add_pc => { + LNS.const_add_pc => { const inc_addr = minimum_instruction_length * ((255 - opcode_base) / line_range); prog.address += inc_addr; }, - LNS_fixed_advance_pc => { + LNS.fixed_advance_pc => { const arg = try in.readInt(u16, di.endian); prog.address += arg; }, - LNS_set_prologue_end => {}, + LNS.set_prologue_end => {}, else => { if (opcode - 1 >= standard_opcode_lengths.len) return error.InvalidDebugInfo; const len_bytes = standard_opcode_lengths[opcode - 1]; diff --git a/lib/std/dwarf/AT.zig b/lib/std/dwarf/AT.zig new file mode 100644 index 0000000000..a4d03ad3d3 --- /dev/null +++ b/lib/std/dwarf/AT.zig @@ -0,0 +1,198 @@ +pub const sibling = 0x01; +pub const location = 0x02; +pub const name = 0x03; +pub const ordering = 0x09; +pub const subscr_data = 0x0a; +pub const byte_size = 0x0b; +pub const bit_offset = 0x0c; +pub const bit_size = 0x0d; +pub const element_list = 0x0f; +pub const stmt_list = 0x10; +pub const low_pc = 0x11; +pub const high_pc = 0x12; +pub const language = 0x13; +pub const member = 0x14; +pub const discr = 0x15; +pub const discr_value = 0x16; +pub const visibility = 0x17; +pub const import = 0x18; +pub const string_length = 0x19; +pub const common_reference = 0x1a; +pub const comp_dir = 0x1b; +pub const const_value = 0x1c; +pub const containing_type = 0x1d; +pub const default_value = 0x1e; +pub const @"inline" = 0x20; +pub const is_optional = 0x21; +pub const lower_bound = 0x22; +pub const producer = 0x25; +pub const prototyped = 0x27; +pub const return_addr = 0x2a; +pub const start_scope = 0x2c; +pub const bit_stride = 0x2e; +pub const upper_bound = 0x2f; +pub const abstract_origin = 0x31; +pub const accessibility = 0x32; +pub const address_class = 0x33; +pub const artificial = 0x34; +pub const base_types = 0x35; +pub const calling_convention = 0x36; +pub const count = 0x37; +pub const data_member_location = 0x38; +pub const decl_column = 0x39; +pub const decl_file = 0x3a; +pub const decl_line = 0x3b; +pub const declaration = 0x3c; +pub const discr_list = 0x3d; +pub const encoding = 0x3e; +pub const external = 0x3f; +pub const frame_base = 0x40; +pub const friend = 0x41; +pub const identifier_case = 0x42; +pub const macro_info = 0x43; +pub const namelist_items = 0x44; +pub const priority = 0x45; +pub const segment = 0x46; +pub const specification = 0x47; +pub const static_link = 0x48; +pub const @"type" = 0x49; +pub const use_location = 0x4a; +pub const variable_parameter = 0x4b; +pub const virtuality = 0x4c; +pub const vtable_elem_location = 0x4d; + +// DWARF 3 values. +pub const allocated = 0x4e; +pub const associated = 0x4f; +pub const data_location = 0x50; +pub const byte_stride = 0x51; +pub const entry_pc = 0x52; +pub const use_UTF8 = 0x53; +pub const extension = 0x54; +pub const ranges = 0x55; +pub const trampoline = 0x56; +pub const call_column = 0x57; +pub const call_file = 0x58; +pub const call_line = 0x59; +pub const description = 0x5a; +pub const binary_scale = 0x5b; +pub const decimal_scale = 0x5c; +pub const small = 0x5d; +pub const decimal_sign = 0x5e; +pub const digit_count = 0x5f; +pub const picture_string = 0x60; +pub const mutable = 0x61; +pub const threads_scaled = 0x62; +pub const explicit = 0x63; +pub const object_pointer = 0x64; +pub const endianity = 0x65; +pub const elemental = 0x66; +pub const pure = 0x67; +pub const recursive = 0x68; + +// DWARF 4. +pub const signature = 0x69; +pub const main_subprogram = 0x6a; +pub const data_bit_offset = 0x6b; +pub const const_expr = 0x6c; +pub const enum_class = 0x6d; +pub const linkage_name = 0x6e; + +// DWARF 5 +pub const alignment = 0x88; + +pub const lo_user = 0x2000; // Implementation-defined range start. +pub const hi_user = 0x3fff; // Implementation-defined range end. + +// SGI/MIPS extensions. +pub const MIPS_fde = 0x2001; +pub const MIPS_loop_begin = 0x2002; +pub const MIPS_tail_loop_begin = 0x2003; +pub const MIPS_epilog_begin = 0x2004; +pub const MIPS_loop_unroll_factor = 0x2005; +pub const MIPS_software_pipeline_depth = 0x2006; +pub const MIPS_linkage_name = 0x2007; +pub const MIPS_stride = 0x2008; +pub const MIPS_abstract_name = 0x2009; +pub const MIPS_clone_origin = 0x200a; +pub const MIPS_has_inlines = 0x200b; + +// HP extensions. +pub const HP_block_index = 0x2000; +pub const HP_unmodifiable = 0x2001; // Same as AT.MIPS_fde. +pub const HP_prologue = 0x2005; // Same as AT.MIPS_loop_unroll. +pub const HP_epilogue = 0x2008; // Same as AT.MIPS_stride. +pub const HP_actuals_stmt_list = 0x2010; +pub const HP_proc_per_section = 0x2011; +pub const HP_raw_data_ptr = 0x2012; +pub const HP_pass_by_reference = 0x2013; +pub const HP_opt_level = 0x2014; +pub const HP_prof_version_id = 0x2015; +pub const HP_opt_flags = 0x2016; +pub const HP_cold_region_low_pc = 0x2017; +pub const HP_cold_region_high_pc = 0x2018; +pub const HP_all_variables_modifiable = 0x2019; +pub const HP_linkage_name = 0x201a; +pub const HP_prof_flags = 0x201b; // In comp unit of procs_info for -g. +pub const HP_unit_name = 0x201f; +pub const HP_unit_size = 0x2020; +pub const HP_widened_byte_size = 0x2021; +pub const HP_definition_points = 0x2022; +pub const HP_default_location = 0x2023; +pub const HP_is_result_param = 0x2029; + +// GNU extensions. +pub const sf_names = 0x2101; +pub const src_info = 0x2102; +pub const mac_info = 0x2103; +pub const src_coords = 0x2104; +pub const body_begin = 0x2105; +pub const body_end = 0x2106; +pub const GNU_vector = 0x2107; +// Thread-safety annotations. +// See http://gcc.gnu.org/wiki/ThreadSafetyAnnotation . +pub const GNU_guarded_by = 0x2108; +pub const GNU_pt_guarded_by = 0x2109; +pub const GNU_guarded = 0x210a; +pub const GNU_pt_guarded = 0x210b; +pub const GNU_locks_excluded = 0x210c; +pub const GNU_exclusive_locks_required = 0x210d; +pub const GNU_shared_locks_required = 0x210e; +// One-definition rule violation detection. +// See http://gcc.gnu.org/wiki/DwarfSeparateTypeInfo . +pub const GNU_odr_signature = 0x210f; +// Template template argument name. +// See http://gcc.gnu.org/wiki/TemplateParmsDwarf . +pub const GNU_template_name = 0x2110; +// The GNU call site extension. +// See http://www.dwarfstd.org/ShowIssue.php?issue=100909.2&type=open . +pub const GNU_call_site_value = 0x2111; +pub const GNU_call_site_data_value = 0x2112; +pub const GNU_call_site_target = 0x2113; +pub const GNU_call_site_target_clobbered = 0x2114; +pub const GNU_tail_call = 0x2115; +pub const GNU_all_tail_call_sites = 0x2116; +pub const GNU_all_call_sites = 0x2117; +pub const GNU_all_source_call_sites = 0x2118; +// Section offset into .debug_macro section. +pub const GNU_macros = 0x2119; +// Extensions for Fission. See http://gcc.gnu.org/wiki/DebugFission. +pub const GNU_dwo_name = 0x2130; +pub const GNU_dwo_id = 0x2131; +pub const GNU_ranges_base = 0x2132; +pub const GNU_addr_base = 0x2133; +pub const GNU_pubnames = 0x2134; +pub const GNU_pubtypes = 0x2135; +// VMS extensions. +pub const VMS_rtnbeg_pd_address = 0x2201; +// GNAT extensions. +// GNAT descriptive type. +// See http://gcc.gnu.org/wiki/DW_AT_GNAT_descriptive_type . +pub const use_GNAT_descriptive_type = 0x2301; +pub const GNAT_descriptive_type = 0x2302; +// UPC extension. +pub const upc_threads_scaled = 0x3210; +// PGI (STMicroelectronics) extensions. +pub const PGI_lbase = 0x3a00; +pub const PGI_soffset = 0x3a01; +pub const PGI_lstride = 0x3a02; diff --git a/lib/std/dwarf/OP.zig b/lib/std/dwarf/OP.zig new file mode 100644 index 0000000000..92e13e8158 --- /dev/null +++ b/lib/std/dwarf/OP.zig @@ -0,0 +1,195 @@ +pub const addr = 0x03; +pub const deref = 0x06; +pub const const1u = 0x08; +pub const const1s = 0x09; +pub const const2u = 0x0a; +pub const const2s = 0x0b; +pub const const4u = 0x0c; +pub const const4s = 0x0d; +pub const const8u = 0x0e; +pub const const8s = 0x0f; +pub const constu = 0x10; +pub const consts = 0x11; +pub const dup = 0x12; +pub const drop = 0x13; +pub const over = 0x14; +pub const pick = 0x15; +pub const swap = 0x16; +pub const rot = 0x17; +pub const xderef = 0x18; +pub const abs = 0x19; +pub const @"and" = 0x1a; +pub const div = 0x1b; +pub const minus = 0x1c; +pub const mod = 0x1d; +pub const mul = 0x1e; +pub const neg = 0x1f; +pub const not = 0x20; +pub const @"or" = 0x21; +pub const plus = 0x22; +pub const plus_uconst = 0x23; +pub const shl = 0x24; +pub const shr = 0x25; +pub const shra = 0x26; +pub const xor = 0x27; +pub const bra = 0x28; +pub const eq = 0x29; +pub const ge = 0x2a; +pub const gt = 0x2b; +pub const le = 0x2c; +pub const lt = 0x2d; +pub const ne = 0x2e; +pub const skip = 0x2f; +pub const lit0 = 0x30; +pub const lit1 = 0x31; +pub const lit2 = 0x32; +pub const lit3 = 0x33; +pub const lit4 = 0x34; +pub const lit5 = 0x35; +pub const lit6 = 0x36; +pub const lit7 = 0x37; +pub const lit8 = 0x38; +pub const lit9 = 0x39; +pub const lit10 = 0x3a; +pub const lit11 = 0x3b; +pub const lit12 = 0x3c; +pub const lit13 = 0x3d; +pub const lit14 = 0x3e; +pub const lit15 = 0x3f; +pub const lit16 = 0x40; +pub const lit17 = 0x41; +pub const lit18 = 0x42; +pub const lit19 = 0x43; +pub const lit20 = 0x44; +pub const lit21 = 0x45; +pub const lit22 = 0x46; +pub const lit23 = 0x47; +pub const lit24 = 0x48; +pub const lit25 = 0x49; +pub const lit26 = 0x4a; +pub const lit27 = 0x4b; +pub const lit28 = 0x4c; +pub const lit29 = 0x4d; +pub const lit30 = 0x4e; +pub const lit31 = 0x4f; +pub const reg0 = 0x50; +pub const reg1 = 0x51; +pub const reg2 = 0x52; +pub const reg3 = 0x53; +pub const reg4 = 0x54; +pub const reg5 = 0x55; +pub const reg6 = 0x56; +pub const reg7 = 0x57; +pub const reg8 = 0x58; +pub const reg9 = 0x59; +pub const reg10 = 0x5a; +pub const reg11 = 0x5b; +pub const reg12 = 0x5c; +pub const reg13 = 0x5d; +pub const reg14 = 0x5e; +pub const reg15 = 0x5f; +pub const reg16 = 0x60; +pub const reg17 = 0x61; +pub const reg18 = 0x62; +pub const reg19 = 0x63; +pub const reg20 = 0x64; +pub const reg21 = 0x65; +pub const reg22 = 0x66; +pub const reg23 = 0x67; +pub const reg24 = 0x68; +pub const reg25 = 0x69; +pub const reg26 = 0x6a; +pub const reg27 = 0x6b; +pub const reg28 = 0x6c; +pub const reg29 = 0x6d; +pub const reg30 = 0x6e; +pub const reg31 = 0x6f; +pub const breg0 = 0x70; +pub const breg1 = 0x71; +pub const breg2 = 0x72; +pub const breg3 = 0x73; +pub const breg4 = 0x74; +pub const breg5 = 0x75; +pub const breg6 = 0x76; +pub const breg7 = 0x77; +pub const breg8 = 0x78; +pub const breg9 = 0x79; +pub const breg10 = 0x7a; +pub const breg11 = 0x7b; +pub const breg12 = 0x7c; +pub const breg13 = 0x7d; +pub const breg14 = 0x7e; +pub const breg15 = 0x7f; +pub const breg16 = 0x80; +pub const breg17 = 0x81; +pub const breg18 = 0x82; +pub const breg19 = 0x83; +pub const breg20 = 0x84; +pub const breg21 = 0x85; +pub const breg22 = 0x86; +pub const breg23 = 0x87; +pub const breg24 = 0x88; +pub const breg25 = 0x89; +pub const breg26 = 0x8a; +pub const breg27 = 0x8b; +pub const breg28 = 0x8c; +pub const breg29 = 0x8d; +pub const breg30 = 0x8e; +pub const breg31 = 0x8f; +pub const regx = 0x90; +pub const fbreg = 0x91; +pub const bregx = 0x92; +pub const piece = 0x93; +pub const deref_size = 0x94; +pub const xderef_size = 0x95; +pub const nop = 0x96; + +// DWARF 3 extensions. +pub const push_object_address = 0x97; +pub const call2 = 0x98; +pub const call4 = 0x99; +pub const call_ref = 0x9a; +pub const form_tls_address = 0x9b; +pub const call_frame_cfa = 0x9c; +pub const bit_piece = 0x9d; + +// DWARF 4 extensions. +pub const implicit_value = 0x9e; +pub const stack_value = 0x9f; + +pub const lo_user = 0xe0; // Implementation-defined range start. +pub const hi_user = 0xff; // Implementation-defined range end. + +// GNU extensions. +pub const GNU_push_tls_address = 0xe0; +// The following is for marking variables that are uninitialized. +pub const GNU_uninit = 0xf0; +pub const GNU_encoded_addr = 0xf1; +// The GNU implicit pointer extension. +// See http://www.dwarfstd.org/ShowIssue.php?issue=100831.1&type=open . +pub const GNU_implicit_pointer = 0xf2; +// The GNU entry value extension. +// See http://www.dwarfstd.org/ShowIssue.php?issue=100909.1&type=open . +pub const GNU_entry_value = 0xf3; +// The GNU typed stack extension. +// See http://www.dwarfstd.org/doc/040408.1.html . +pub const GNU_const_type = 0xf4; +pub const GNU_regval_type = 0xf5; +pub const GNU_deref_type = 0xf6; +pub const GNU_convert = 0xf7; +pub const GNU_reinterpret = 0xf9; +// The GNU parameter ref extension. +pub const GNU_parameter_ref = 0xfa; +// Extension for Fission. See http://gcc.gnu.org/wiki/DebugFission. +pub const GNU_addr_index = 0xfb; +pub const GNU_const_index = 0xfc; +// HP extensions. +pub const HP_unknown = 0xe0; // Ouch, the same as GNU_push_tls_address. +pub const HP_is_value = 0xe1; +pub const HP_fltconst4 = 0xe2; +pub const HP_fltconst8 = 0xe3; +pub const HP_mod_range = 0xe4; +pub const HP_unmod_range = 0xe5; +pub const HP_tls = 0xe6; +// PGI (STMicroelectronics) extensions. +pub const PGI_omp_thread_num = 0xf8; diff --git a/lib/std/dwarf/TAG.zig b/lib/std/dwarf/TAG.zig new file mode 100644 index 0000000000..a6434cf3ec --- /dev/null +++ b/lib/std/dwarf/TAG.zig @@ -0,0 +1,108 @@ +pub const padding = 0x00; +pub const array_type = 0x01; +pub const class_type = 0x02; +pub const entry_point = 0x03; +pub const enumeration_type = 0x04; +pub const formal_parameter = 0x05; +pub const imported_declaration = 0x08; +pub const label = 0x0a; +pub const lexical_block = 0x0b; +pub const member = 0x0d; +pub const pointer_type = 0x0f; +pub const reference_type = 0x10; +pub const compile_unit = 0x11; +pub const string_type = 0x12; +pub const structure_type = 0x13; +pub const subroutine = 0x14; +pub const subroutine_type = 0x15; +pub const typedef = 0x16; +pub const union_type = 0x17; +pub const unspecified_parameters = 0x18; +pub const variant = 0x19; +pub const common_block = 0x1a; +pub const common_inclusion = 0x1b; +pub const inheritance = 0x1c; +pub const inlined_subroutine = 0x1d; +pub const module = 0x1e; +pub const ptr_to_member_type = 0x1f; +pub const set_type = 0x20; +pub const subrange_type = 0x21; +pub const with_stmt = 0x22; +pub const access_declaration = 0x23; +pub const base_type = 0x24; +pub const catch_block = 0x25; +pub const const_type = 0x26; +pub const constant = 0x27; +pub const enumerator = 0x28; +pub const file_type = 0x29; +pub const friend = 0x2a; +pub const namelist = 0x2b; +pub const namelist_item = 0x2c; +pub const packed_type = 0x2d; +pub const subprogram = 0x2e; +pub const template_type_param = 0x2f; +pub const template_value_param = 0x30; +pub const thrown_type = 0x31; +pub const try_block = 0x32; +pub const variant_part = 0x33; +pub const variable = 0x34; +pub const volatile_type = 0x35; + +// DWARF 3 +pub const dwarf_procedure = 0x36; +pub const restrict_type = 0x37; +pub const interface_type = 0x38; +pub const namespace = 0x39; +pub const imported_module = 0x3a; +pub const unspecified_type = 0x3b; +pub const partial_unit = 0x3c; +pub const imported_unit = 0x3d; +pub const condition = 0x3f; +pub const shared_type = 0x40; + +// DWARF 4 +pub const type_unit = 0x41; +pub const rvalue_reference_type = 0x42; +pub const template_alias = 0x43; + +pub const lo_user = 0x4080; +pub const hi_user = 0xffff; + +// SGI/MIPS Extensions. +pub const MIPS_loop = 0x4081; + +// HP extensions. See: ftp://ftp.hp.com/pub/lang/tools/WDB/wdb-4.0.tar.gz . +pub const HP_array_descriptor = 0x4090; +pub const HP_Bliss_field = 0x4091; +pub const HP_Bliss_field_set = 0x4092; + +// GNU extensions. +pub const format_label = 0x4101; // For FORTRAN 77 and Fortran 90. +pub const function_template = 0x4102; // For C++. +pub const class_template = 0x4103; //For C++. +pub const GNU_BINCL = 0x4104; +pub const GNU_EINCL = 0x4105; + +// Template template parameter. +// See http://gcc.gnu.org/wiki/TemplateParmsDwarf . +pub const GNU_template_template_param = 0x4106; + +// Template parameter pack extension = specified at +// http://wiki.dwarfstd.org/index.php?title=C%2B%2B0x:_Variadic_templates +// The values of these two TAGS are in the DW_TAG_GNU_* space until the tags +// are properly part of DWARF 5. +pub const GNU_template_parameter_pack = 0x4107; +pub const GNU_formal_parameter_pack = 0x4108; +// The GNU call site extension = specified at +// http://www.dwarfstd.org/ShowIssue.php?issue=100909.2&type=open . +// The values of these two TAGS are in the DW_TAG_GNU_* space until the tags +// are properly part of DWARF 5. +pub const GNU_call_site = 0x4109; +pub const GNU_call_site_parameter = 0x410a; +// Extensions for UPC. See: http://dwarfstd.org/doc/DWARF4.pdf. +pub const upc_shared_type = 0x8765; +pub const upc_strict_type = 0x8766; +pub const upc_relaxed_type = 0x8767; +// PGI (STMicroelectronics; extensions. No documentation available. +pub const PGI_kanji_type = 0xA000; +pub const PGI_interface_block = 0xA020; diff --git a/lib/std/dwarf_bits.zig b/lib/std/dwarf_bits.zig deleted file mode 100644 index a40fa8a277..0000000000 --- a/lib/std/dwarf_bits.zig +++ /dev/null @@ -1,699 +0,0 @@ -pub const TAG_padding = 0x00; -pub const TAG_array_type = 0x01; -pub const TAG_class_type = 0x02; -pub const TAG_entry_point = 0x03; -pub const TAG_enumeration_type = 0x04; -pub const TAG_formal_parameter = 0x05; -pub const TAG_imported_declaration = 0x08; -pub const TAG_label = 0x0a; -pub const TAG_lexical_block = 0x0b; -pub const TAG_member = 0x0d; -pub const TAG_pointer_type = 0x0f; -pub const TAG_reference_type = 0x10; -pub const TAG_compile_unit = 0x11; -pub const TAG_string_type = 0x12; -pub const TAG_structure_type = 0x13; -pub const TAG_subroutine = 0x14; -pub const TAG_subroutine_type = 0x15; -pub const TAG_typedef = 0x16; -pub const TAG_union_type = 0x17; -pub const TAG_unspecified_parameters = 0x18; -pub const TAG_variant = 0x19; -pub const TAG_common_block = 0x1a; -pub const TAG_common_inclusion = 0x1b; -pub const TAG_inheritance = 0x1c; -pub const TAG_inlined_subroutine = 0x1d; -pub const TAG_module = 0x1e; -pub const TAG_ptr_to_member_type = 0x1f; -pub const TAG_set_type = 0x20; -pub const TAG_subrange_type = 0x21; -pub const TAG_with_stmt = 0x22; -pub const TAG_access_declaration = 0x23; -pub const TAG_base_type = 0x24; -pub const TAG_catch_block = 0x25; -pub const TAG_const_type = 0x26; -pub const TAG_constant = 0x27; -pub const TAG_enumerator = 0x28; -pub const TAG_file_type = 0x29; -pub const TAG_friend = 0x2a; -pub const TAG_namelist = 0x2b; -pub const TAG_namelist_item = 0x2c; -pub const TAG_packed_type = 0x2d; -pub const TAG_subprogram = 0x2e; -pub const TAG_template_type_param = 0x2f; -pub const TAG_template_value_param = 0x30; -pub const TAG_thrown_type = 0x31; -pub const TAG_try_block = 0x32; -pub const TAG_variant_part = 0x33; -pub const TAG_variable = 0x34; -pub const TAG_volatile_type = 0x35; - -// DWARF 3 -pub const TAG_dwarf_procedure = 0x36; -pub const TAG_restrict_type = 0x37; -pub const TAG_interface_type = 0x38; -pub const TAG_namespace = 0x39; -pub const TAG_imported_module = 0x3a; -pub const TAG_unspecified_type = 0x3b; -pub const TAG_partial_unit = 0x3c; -pub const TAG_imported_unit = 0x3d; -pub const TAG_condition = 0x3f; -pub const TAG_shared_type = 0x40; - -// DWARF 4 -pub const TAG_type_unit = 0x41; -pub const TAG_rvalue_reference_type = 0x42; -pub const TAG_template_alias = 0x43; - -pub const TAG_lo_user = 0x4080; -pub const TAG_hi_user = 0xffff; - -// SGI/MIPS Extensions. -pub const TAG_MIPS_loop = 0x4081; - -// HP extensions. See: ftp://ftp.hp.com/pub/lang/tools/WDB/wdb-4.0.tar.gz . -pub const TAG_HP_array_descriptor = 0x4090; -pub const TAG_HP_Bliss_field = 0x4091; -pub const TAG_HP_Bliss_field_set = 0x4092; - -// GNU extensions. -pub const TAG_format_label = 0x4101; // For FORTRAN 77 and Fortran 90. -pub const TAG_function_template = 0x4102; // For C++. -pub const TAG_class_template = 0x4103; //For C++. -pub const TAG_GNU_BINCL = 0x4104; -pub const TAG_GNU_EINCL = 0x4105; - -// Template template parameter. -// See http://gcc.gnu.org/wiki/TemplateParmsDwarf . -pub const TAG_GNU_template_template_param = 0x4106; - -// Template parameter pack extension = specified at -// http://wiki.dwarfstd.org/index.php?title=C%2B%2B0x:_Variadic_templates -// The values of these two TAGS are in the DW_TAG_GNU_* space until the tags -// are properly part of DWARF 5. -pub const TAG_GNU_template_parameter_pack = 0x4107; -pub const TAG_GNU_formal_parameter_pack = 0x4108; -// The GNU call site extension = specified at -// http://www.dwarfstd.org/ShowIssue.php?issue=100909.2&type=open . -// The values of these two TAGS are in the DW_TAG_GNU_* space until the tags -// are properly part of DWARF 5. -pub const TAG_GNU_call_site = 0x4109; -pub const TAG_GNU_call_site_parameter = 0x410a; -// Extensions for UPC. See: http://dwarfstd.org/doc/DWARF4.pdf. -pub const TAG_upc_shared_type = 0x8765; -pub const TAG_upc_strict_type = 0x8766; -pub const TAG_upc_relaxed_type = 0x8767; -// PGI (STMicroelectronics; extensions. No documentation available. -pub const TAG_PGI_kanji_type = 0xA000; -pub const TAG_PGI_interface_block = 0xA020; - -pub const FORM_addr = 0x01; -pub const FORM_block2 = 0x03; -pub const FORM_block4 = 0x04; -pub const FORM_data2 = 0x05; -pub const FORM_data4 = 0x06; -pub const FORM_data8 = 0x07; -pub const FORM_string = 0x08; -pub const FORM_block = 0x09; -pub const FORM_block1 = 0x0a; -pub const FORM_data1 = 0x0b; -pub const FORM_flag = 0x0c; -pub const FORM_sdata = 0x0d; -pub const FORM_strp = 0x0e; -pub const FORM_udata = 0x0f; -pub const FORM_ref_addr = 0x10; -pub const FORM_ref1 = 0x11; -pub const FORM_ref2 = 0x12; -pub const FORM_ref4 = 0x13; -pub const FORM_ref8 = 0x14; -pub const FORM_ref_udata = 0x15; -pub const FORM_indirect = 0x16; -pub const FORM_sec_offset = 0x17; -pub const FORM_exprloc = 0x18; -pub const FORM_flag_present = 0x19; -pub const FORM_ref_sig8 = 0x20; - -// Extensions for Fission. See http://gcc.gnu.org/wiki/DebugFission. -pub const FORM_GNU_addr_index = 0x1f01; -pub const FORM_GNU_str_index = 0x1f02; - -// Extensions for DWZ multifile. -// See http://www.dwarfstd.org/ShowIssue.php?issue=120604.1&type=open . -pub const FORM_GNU_ref_alt = 0x1f20; -pub const FORM_GNU_strp_alt = 0x1f21; - -pub const AT_sibling = 0x01; -pub const AT_location = 0x02; -pub const AT_name = 0x03; -pub const AT_ordering = 0x09; -pub const AT_subscr_data = 0x0a; -pub const AT_byte_size = 0x0b; -pub const AT_bit_offset = 0x0c; -pub const AT_bit_size = 0x0d; -pub const AT_element_list = 0x0f; -pub const AT_stmt_list = 0x10; -pub const AT_low_pc = 0x11; -pub const AT_high_pc = 0x12; -pub const AT_language = 0x13; -pub const AT_member = 0x14; -pub const AT_discr = 0x15; -pub const AT_discr_value = 0x16; -pub const AT_visibility = 0x17; -pub const AT_import = 0x18; -pub const AT_string_length = 0x19; -pub const AT_common_reference = 0x1a; -pub const AT_comp_dir = 0x1b; -pub const AT_const_value = 0x1c; -pub const AT_containing_type = 0x1d; -pub const AT_default_value = 0x1e; -pub const AT_inline = 0x20; -pub const AT_is_optional = 0x21; -pub const AT_lower_bound = 0x22; -pub const AT_producer = 0x25; -pub const AT_prototyped = 0x27; -pub const AT_return_addr = 0x2a; -pub const AT_start_scope = 0x2c; -pub const AT_bit_stride = 0x2e; -pub const AT_upper_bound = 0x2f; -pub const AT_abstract_origin = 0x31; -pub const AT_accessibility = 0x32; -pub const AT_address_class = 0x33; -pub const AT_artificial = 0x34; -pub const AT_base_types = 0x35; -pub const AT_calling_convention = 0x36; -pub const AT_count = 0x37; -pub const AT_data_member_location = 0x38; -pub const AT_decl_column = 0x39; -pub const AT_decl_file = 0x3a; -pub const AT_decl_line = 0x3b; -pub const AT_declaration = 0x3c; -pub const AT_discr_list = 0x3d; -pub const AT_encoding = 0x3e; -pub const AT_external = 0x3f; -pub const AT_frame_base = 0x40; -pub const AT_friend = 0x41; -pub const AT_identifier_case = 0x42; -pub const AT_macro_info = 0x43; -pub const AT_namelist_items = 0x44; -pub const AT_priority = 0x45; -pub const AT_segment = 0x46; -pub const AT_specification = 0x47; -pub const AT_static_link = 0x48; -pub const AT_type = 0x49; -pub const AT_use_location = 0x4a; -pub const AT_variable_parameter = 0x4b; -pub const AT_virtuality = 0x4c; -pub const AT_vtable_elem_location = 0x4d; - -// DWARF 3 values. -pub const AT_allocated = 0x4e; -pub const AT_associated = 0x4f; -pub const AT_data_location = 0x50; -pub const AT_byte_stride = 0x51; -pub const AT_entry_pc = 0x52; -pub const AT_use_UTF8 = 0x53; -pub const AT_extension = 0x54; -pub const AT_ranges = 0x55; -pub const AT_trampoline = 0x56; -pub const AT_call_column = 0x57; -pub const AT_call_file = 0x58; -pub const AT_call_line = 0x59; -pub const AT_description = 0x5a; -pub const AT_binary_scale = 0x5b; -pub const AT_decimal_scale = 0x5c; -pub const AT_small = 0x5d; -pub const AT_decimal_sign = 0x5e; -pub const AT_digit_count = 0x5f; -pub const AT_picture_string = 0x60; -pub const AT_mutable = 0x61; -pub const AT_threads_scaled = 0x62; -pub const AT_explicit = 0x63; -pub const AT_object_pointer = 0x64; -pub const AT_endianity = 0x65; -pub const AT_elemental = 0x66; -pub const AT_pure = 0x67; -pub const AT_recursive = 0x68; - -// DWARF 4. -pub const AT_signature = 0x69; -pub const AT_main_subprogram = 0x6a; -pub const AT_data_bit_offset = 0x6b; -pub const AT_const_expr = 0x6c; -pub const AT_enum_class = 0x6d; -pub const AT_linkage_name = 0x6e; - -// DWARF 5 -pub const AT_alignment = 0x88; - -pub const AT_lo_user = 0x2000; // Implementation-defined range start. -pub const AT_hi_user = 0x3fff; // Implementation-defined range end. - -// SGI/MIPS extensions. -pub const AT_MIPS_fde = 0x2001; -pub const AT_MIPS_loop_begin = 0x2002; -pub const AT_MIPS_tail_loop_begin = 0x2003; -pub const AT_MIPS_epilog_begin = 0x2004; -pub const AT_MIPS_loop_unroll_factor = 0x2005; -pub const AT_MIPS_software_pipeline_depth = 0x2006; -pub const AT_MIPS_linkage_name = 0x2007; -pub const AT_MIPS_stride = 0x2008; -pub const AT_MIPS_abstract_name = 0x2009; -pub const AT_MIPS_clone_origin = 0x200a; -pub const AT_MIPS_has_inlines = 0x200b; - -// HP extensions. -pub const AT_HP_block_index = 0x2000; -pub const AT_HP_unmodifiable = 0x2001; // Same as AT_MIPS_fde. -pub const AT_HP_prologue = 0x2005; // Same as AT_MIPS_loop_unroll. -pub const AT_HP_epilogue = 0x2008; // Same as AT_MIPS_stride. -pub const AT_HP_actuals_stmt_list = 0x2010; -pub const AT_HP_proc_per_section = 0x2011; -pub const AT_HP_raw_data_ptr = 0x2012; -pub const AT_HP_pass_by_reference = 0x2013; -pub const AT_HP_opt_level = 0x2014; -pub const AT_HP_prof_version_id = 0x2015; -pub const AT_HP_opt_flags = 0x2016; -pub const AT_HP_cold_region_low_pc = 0x2017; -pub const AT_HP_cold_region_high_pc = 0x2018; -pub const AT_HP_all_variables_modifiable = 0x2019; -pub const AT_HP_linkage_name = 0x201a; -pub const AT_HP_prof_flags = 0x201b; // In comp unit of procs_info for -g. -pub const AT_HP_unit_name = 0x201f; -pub const AT_HP_unit_size = 0x2020; -pub const AT_HP_widened_byte_size = 0x2021; -pub const AT_HP_definition_points = 0x2022; -pub const AT_HP_default_location = 0x2023; -pub const AT_HP_is_result_param = 0x2029; - -// GNU extensions. -pub const AT_sf_names = 0x2101; -pub const AT_src_info = 0x2102; -pub const AT_mac_info = 0x2103; -pub const AT_src_coords = 0x2104; -pub const AT_body_begin = 0x2105; -pub const AT_body_end = 0x2106; -pub const AT_GNU_vector = 0x2107; -// Thread-safety annotations. -// See http://gcc.gnu.org/wiki/ThreadSafetyAnnotation . -pub const AT_GNU_guarded_by = 0x2108; -pub const AT_GNU_pt_guarded_by = 0x2109; -pub const AT_GNU_guarded = 0x210a; -pub const AT_GNU_pt_guarded = 0x210b; -pub const AT_GNU_locks_excluded = 0x210c; -pub const AT_GNU_exclusive_locks_required = 0x210d; -pub const AT_GNU_shared_locks_required = 0x210e; -// One-definition rule violation detection. -// See http://gcc.gnu.org/wiki/DwarfSeparateTypeInfo . -pub const AT_GNU_odr_signature = 0x210f; -// Template template argument name. -// See http://gcc.gnu.org/wiki/TemplateParmsDwarf . -pub const AT_GNU_template_name = 0x2110; -// The GNU call site extension. -// See http://www.dwarfstd.org/ShowIssue.php?issue=100909.2&type=open . -pub const AT_GNU_call_site_value = 0x2111; -pub const AT_GNU_call_site_data_value = 0x2112; -pub const AT_GNU_call_site_target = 0x2113; -pub const AT_GNU_call_site_target_clobbered = 0x2114; -pub const AT_GNU_tail_call = 0x2115; -pub const AT_GNU_all_tail_call_sites = 0x2116; -pub const AT_GNU_all_call_sites = 0x2117; -pub const AT_GNU_all_source_call_sites = 0x2118; -// Section offset into .debug_macro section. -pub const AT_GNU_macros = 0x2119; -// Extensions for Fission. See http://gcc.gnu.org/wiki/DebugFission. -pub const AT_GNU_dwo_name = 0x2130; -pub const AT_GNU_dwo_id = 0x2131; -pub const AT_GNU_ranges_base = 0x2132; -pub const AT_GNU_addr_base = 0x2133; -pub const AT_GNU_pubnames = 0x2134; -pub const AT_GNU_pubtypes = 0x2135; -// VMS extensions. -pub const AT_VMS_rtnbeg_pd_address = 0x2201; -// GNAT extensions. -// GNAT descriptive type. -// See http://gcc.gnu.org/wiki/DW_AT_GNAT_descriptive_type . -pub const AT_use_GNAT_descriptive_type = 0x2301; -pub const AT_GNAT_descriptive_type = 0x2302; -// UPC extension. -pub const AT_upc_threads_scaled = 0x3210; -// PGI (STMicroelectronics) extensions. -pub const AT_PGI_lbase = 0x3a00; -pub const AT_PGI_soffset = 0x3a01; -pub const AT_PGI_lstride = 0x3a02; - -pub const OP_addr = 0x03; -pub const OP_deref = 0x06; -pub const OP_const1u = 0x08; -pub const OP_const1s = 0x09; -pub const OP_const2u = 0x0a; -pub const OP_const2s = 0x0b; -pub const OP_const4u = 0x0c; -pub const OP_const4s = 0x0d; -pub const OP_const8u = 0x0e; -pub const OP_const8s = 0x0f; -pub const OP_constu = 0x10; -pub const OP_consts = 0x11; -pub const OP_dup = 0x12; -pub const OP_drop = 0x13; -pub const OP_over = 0x14; -pub const OP_pick = 0x15; -pub const OP_swap = 0x16; -pub const OP_rot = 0x17; -pub const OP_xderef = 0x18; -pub const OP_abs = 0x19; -pub const OP_and = 0x1a; -pub const OP_div = 0x1b; -pub const OP_minus = 0x1c; -pub const OP_mod = 0x1d; -pub const OP_mul = 0x1e; -pub const OP_neg = 0x1f; -pub const OP_not = 0x20; -pub const OP_or = 0x21; -pub const OP_plus = 0x22; -pub const OP_plus_uconst = 0x23; -pub const OP_shl = 0x24; -pub const OP_shr = 0x25; -pub const OP_shra = 0x26; -pub const OP_xor = 0x27; -pub const OP_bra = 0x28; -pub const OP_eq = 0x29; -pub const OP_ge = 0x2a; -pub const OP_gt = 0x2b; -pub const OP_le = 0x2c; -pub const OP_lt = 0x2d; -pub const OP_ne = 0x2e; -pub const OP_skip = 0x2f; -pub const OP_lit0 = 0x30; -pub const OP_lit1 = 0x31; -pub const OP_lit2 = 0x32; -pub const OP_lit3 = 0x33; -pub const OP_lit4 = 0x34; -pub const OP_lit5 = 0x35; -pub const OP_lit6 = 0x36; -pub const OP_lit7 = 0x37; -pub const OP_lit8 = 0x38; -pub const OP_lit9 = 0x39; -pub const OP_lit10 = 0x3a; -pub const OP_lit11 = 0x3b; -pub const OP_lit12 = 0x3c; -pub const OP_lit13 = 0x3d; -pub const OP_lit14 = 0x3e; -pub const OP_lit15 = 0x3f; -pub const OP_lit16 = 0x40; -pub const OP_lit17 = 0x41; -pub const OP_lit18 = 0x42; -pub const OP_lit19 = 0x43; -pub const OP_lit20 = 0x44; -pub const OP_lit21 = 0x45; -pub const OP_lit22 = 0x46; -pub const OP_lit23 = 0x47; -pub const OP_lit24 = 0x48; -pub const OP_lit25 = 0x49; -pub const OP_lit26 = 0x4a; -pub const OP_lit27 = 0x4b; -pub const OP_lit28 = 0x4c; -pub const OP_lit29 = 0x4d; -pub const OP_lit30 = 0x4e; -pub const OP_lit31 = 0x4f; -pub const OP_reg0 = 0x50; -pub const OP_reg1 = 0x51; -pub const OP_reg2 = 0x52; -pub const OP_reg3 = 0x53; -pub const OP_reg4 = 0x54; -pub const OP_reg5 = 0x55; -pub const OP_reg6 = 0x56; -pub const OP_reg7 = 0x57; -pub const OP_reg8 = 0x58; -pub const OP_reg9 = 0x59; -pub const OP_reg10 = 0x5a; -pub const OP_reg11 = 0x5b; -pub const OP_reg12 = 0x5c; -pub const OP_reg13 = 0x5d; -pub const OP_reg14 = 0x5e; -pub const OP_reg15 = 0x5f; -pub const OP_reg16 = 0x60; -pub const OP_reg17 = 0x61; -pub const OP_reg18 = 0x62; -pub const OP_reg19 = 0x63; -pub const OP_reg20 = 0x64; -pub const OP_reg21 = 0x65; -pub const OP_reg22 = 0x66; -pub const OP_reg23 = 0x67; -pub const OP_reg24 = 0x68; -pub const OP_reg25 = 0x69; -pub const OP_reg26 = 0x6a; -pub const OP_reg27 = 0x6b; -pub const OP_reg28 = 0x6c; -pub const OP_reg29 = 0x6d; -pub const OP_reg30 = 0x6e; -pub const OP_reg31 = 0x6f; -pub const OP_breg0 = 0x70; -pub const OP_breg1 = 0x71; -pub const OP_breg2 = 0x72; -pub const OP_breg3 = 0x73; -pub const OP_breg4 = 0x74; -pub const OP_breg5 = 0x75; -pub const OP_breg6 = 0x76; -pub const OP_breg7 = 0x77; -pub const OP_breg8 = 0x78; -pub const OP_breg9 = 0x79; -pub const OP_breg10 = 0x7a; -pub const OP_breg11 = 0x7b; -pub const OP_breg12 = 0x7c; -pub const OP_breg13 = 0x7d; -pub const OP_breg14 = 0x7e; -pub const OP_breg15 = 0x7f; -pub const OP_breg16 = 0x80; -pub const OP_breg17 = 0x81; -pub const OP_breg18 = 0x82; -pub const OP_breg19 = 0x83; -pub const OP_breg20 = 0x84; -pub const OP_breg21 = 0x85; -pub const OP_breg22 = 0x86; -pub const OP_breg23 = 0x87; -pub const OP_breg24 = 0x88; -pub const OP_breg25 = 0x89; -pub const OP_breg26 = 0x8a; -pub const OP_breg27 = 0x8b; -pub const OP_breg28 = 0x8c; -pub const OP_breg29 = 0x8d; -pub const OP_breg30 = 0x8e; -pub const OP_breg31 = 0x8f; -pub const OP_regx = 0x90; -pub const OP_fbreg = 0x91; -pub const OP_bregx = 0x92; -pub const OP_piece = 0x93; -pub const OP_deref_size = 0x94; -pub const OP_xderef_size = 0x95; -pub const OP_nop = 0x96; - -// DWARF 3 extensions. -pub const OP_push_object_address = 0x97; -pub const OP_call2 = 0x98; -pub const OP_call4 = 0x99; -pub const OP_call_ref = 0x9a; -pub const OP_form_tls_address = 0x9b; -pub const OP_call_frame_cfa = 0x9c; -pub const OP_bit_piece = 0x9d; - -// DWARF 4 extensions. -pub const OP_implicit_value = 0x9e; -pub const OP_stack_value = 0x9f; - -pub const OP_lo_user = 0xe0; // Implementation-defined range start. -pub const OP_hi_user = 0xff; // Implementation-defined range end. - -// GNU extensions. -pub const OP_GNU_push_tls_address = 0xe0; -// The following is for marking variables that are uninitialized. -pub const OP_GNU_uninit = 0xf0; -pub const OP_GNU_encoded_addr = 0xf1; -// The GNU implicit pointer extension. -// See http://www.dwarfstd.org/ShowIssue.php?issue=100831.1&type=open . -pub const OP_GNU_implicit_pointer = 0xf2; -// The GNU entry value extension. -// See http://www.dwarfstd.org/ShowIssue.php?issue=100909.1&type=open . -pub const OP_GNU_entry_value = 0xf3; -// The GNU typed stack extension. -// See http://www.dwarfstd.org/doc/040408.1.html . -pub const OP_GNU_const_type = 0xf4; -pub const OP_GNU_regval_type = 0xf5; -pub const OP_GNU_deref_type = 0xf6; -pub const OP_GNU_convert = 0xf7; -pub const OP_GNU_reinterpret = 0xf9; -// The GNU parameter ref extension. -pub const OP_GNU_parameter_ref = 0xfa; -// Extension for Fission. See http://gcc.gnu.org/wiki/DebugFission. -pub const OP_GNU_addr_index = 0xfb; -pub const OP_GNU_const_index = 0xfc; -// HP extensions. -pub const OP_HP_unknown = 0xe0; // Ouch, the same as GNU_push_tls_address. -pub const OP_HP_is_value = 0xe1; -pub const OP_HP_fltconst4 = 0xe2; -pub const OP_HP_fltconst8 = 0xe3; -pub const OP_HP_mod_range = 0xe4; -pub const OP_HP_unmod_range = 0xe5; -pub const OP_HP_tls = 0xe6; -// PGI (STMicroelectronics) extensions. -pub const OP_PGI_omp_thread_num = 0xf8; - -pub const ATE_void = 0x0; -pub const ATE_address = 0x1; -pub const ATE_boolean = 0x2; -pub const ATE_complex_float = 0x3; -pub const ATE_float = 0x4; -pub const ATE_signed = 0x5; -pub const ATE_signed_char = 0x6; -pub const ATE_unsigned = 0x7; -pub const ATE_unsigned_char = 0x8; - -// DWARF 3. -pub const ATE_imaginary_float = 0x9; -pub const ATE_packed_decimal = 0xa; -pub const ATE_numeric_string = 0xb; -pub const ATE_edited = 0xc; -pub const ATE_signed_fixed = 0xd; -pub const ATE_unsigned_fixed = 0xe; -pub const ATE_decimal_float = 0xf; - -// DWARF 4. -pub const ATE_UTF = 0x10; - -pub const ATE_lo_user = 0x80; -pub const ATE_hi_user = 0xff; - -// HP extensions. -pub const ATE_HP_float80 = 0x80; // Floating-point (80 bit). -pub const ATE_HP_complex_float80 = 0x81; // Complex floating-point (80 bit). -pub const ATE_HP_float128 = 0x82; // Floating-point (128 bit). -pub const ATE_HP_complex_float128 = 0x83; // Complex fp (128 bit). -pub const ATE_HP_floathpintel = 0x84; // Floating-point (82 bit IA64). -pub const ATE_HP_imaginary_float80 = 0x85; -pub const ATE_HP_imaginary_float128 = 0x86; -pub const ATE_HP_VAX_float = 0x88; // F or G floating. -pub const ATE_HP_VAX_float_d = 0x89; // D floating. -pub const ATE_HP_packed_decimal = 0x8a; // Cobol. -pub const ATE_HP_zoned_decimal = 0x8b; // Cobol. -pub const ATE_HP_edited = 0x8c; // Cobol. -pub const ATE_HP_signed_fixed = 0x8d; // Cobol. -pub const ATE_HP_unsigned_fixed = 0x8e; // Cobol. -pub const ATE_HP_VAX_complex_float = 0x8f; // F or G floating complex. -pub const ATE_HP_VAX_complex_float_d = 0x90; // D floating complex. - -pub const CFA_advance_loc = 0x40; -pub const CFA_offset = 0x80; -pub const CFA_restore = 0xc0; -pub const CFA_nop = 0x00; -pub const CFA_set_loc = 0x01; -pub const CFA_advance_loc1 = 0x02; -pub const CFA_advance_loc2 = 0x03; -pub const CFA_advance_loc4 = 0x04; -pub const CFA_offset_extended = 0x05; -pub const CFA_restore_extended = 0x06; -pub const CFA_undefined = 0x07; -pub const CFA_same_value = 0x08; -pub const CFA_register = 0x09; -pub const CFA_remember_state = 0x0a; -pub const CFA_restore_state = 0x0b; -pub const CFA_def_cfa = 0x0c; -pub const CFA_def_cfa_register = 0x0d; -pub const CFA_def_cfa_offset = 0x0e; - -// DWARF 3. -pub const CFA_def_cfa_expression = 0x0f; -pub const CFA_expression = 0x10; -pub const CFA_offset_extended_sf = 0x11; -pub const CFA_def_cfa_sf = 0x12; -pub const CFA_def_cfa_offset_sf = 0x13; -pub const CFA_val_offset = 0x14; -pub const CFA_val_offset_sf = 0x15; -pub const CFA_val_expression = 0x16; - -pub const CFA_lo_user = 0x1c; -pub const CFA_hi_user = 0x3f; - -// SGI/MIPS specific. -pub const CFA_MIPS_advance_loc8 = 0x1d; - -// GNU extensions. -pub const CFA_GNU_window_save = 0x2d; -pub const CFA_GNU_args_size = 0x2e; -pub const CFA_GNU_negative_offset_extended = 0x2f; - -pub const CHILDREN_no = 0x00; -pub const CHILDREN_yes = 0x01; - -pub const LNS_extended_op = 0x00; -pub const LNS_copy = 0x01; -pub const LNS_advance_pc = 0x02; -pub const LNS_advance_line = 0x03; -pub const LNS_set_file = 0x04; -pub const LNS_set_column = 0x05; -pub const LNS_negate_stmt = 0x06; -pub const LNS_set_basic_block = 0x07; -pub const LNS_const_add_pc = 0x08; -pub const LNS_fixed_advance_pc = 0x09; -pub const LNS_set_prologue_end = 0x0a; -pub const LNS_set_epilogue_begin = 0x0b; -pub const LNS_set_isa = 0x0c; - -pub const LNE_end_sequence = 0x01; -pub const LNE_set_address = 0x02; -pub const LNE_define_file = 0x03; -pub const LNE_set_discriminator = 0x04; -pub const LNE_lo_user = 0x80; -pub const LNE_hi_user = 0xff; - -pub const LANG_C89 = 0x0001; -pub const LANG_C = 0x0002; -pub const LANG_Ada83 = 0x0003; -pub const LANG_C_plus_plus = 0x0004; -pub const LANG_Cobol74 = 0x0005; -pub const LANG_Cobol85 = 0x0006; -pub const LANG_Fortran77 = 0x0007; -pub const LANG_Fortran90 = 0x0008; -pub const LANG_Pascal83 = 0x0009; -pub const LANG_Modula2 = 0x000a; -pub const LANG_Java = 0x000b; -pub const LANG_C99 = 0x000c; -pub const LANG_Ada95 = 0x000d; -pub const LANG_Fortran95 = 0x000e; -pub const LANG_PLI = 0x000f; -pub const LANG_ObjC = 0x0010; -pub const LANG_ObjC_plus_plus = 0x0011; -pub const LANG_UPC = 0x0012; -pub const LANG_D = 0x0013; -pub const LANG_Python = 0x0014; -pub const LANG_Go = 0x0016; -pub const LANG_C_plus_plus_11 = 0x001a; -pub const LANG_Rust = 0x001c; -pub const LANG_C11 = 0x001d; -pub const LANG_C_plus_plus_14 = 0x0021; -pub const LANG_Fortran03 = 0x0022; -pub const LANG_Fortran08 = 0x0023; -pub const LANG_lo_user = 0x8000; -pub const LANG_hi_user = 0xffff; -pub const LANG_Mips_Assembler = 0x8001; -pub const LANG_Upc = 0x8765; -pub const LANG_HP_Bliss = 0x8003; -pub const LANG_HP_Basic91 = 0x8004; -pub const LANG_HP_Pascal91 = 0x8005; -pub const LANG_HP_IMacro = 0x8006; -pub const LANG_HP_Assembler = 0x8007; - -pub const UT_compile = 0x01; -pub const UT_type = 0x02; -pub const UT_partial = 0x03; -pub const UT_skeleton = 0x04; -pub const UT_split_compile = 0x05; -pub const UT_split_type = 0x06; -pub const UT_lo_user = 0x80; -pub const UT_hi_user = 0xff; - -pub const LNCT_path = 0x1; -pub const LNCT_directory_index = 0x2; -pub const LNCT_timestamp = 0x3; -pub const LNCT_size = 0x4; -pub const LNCT_MD5 = 0x5; -pub const LNCT_lo_user = 0x2000; -pub const LNCT_hi_user = 0x3fff; diff --git a/lib/std/event/rwlock.zig b/lib/std/event/rwlock.zig index 43d41b860e..951f305cff 100644 --- a/lib/std/event/rwlock.zig +++ b/lib/std/event/rwlock.zig @@ -4,6 +4,7 @@ const assert = std.debug.assert; const testing = std.testing; const mem = std.mem; const Loop = std.event.Loop; +const Allocator = std.mem.Allocator; /// Thread-safe async/await lock. /// Functions which are waiting for the lock are suspended, and diff --git a/lib/std/fmt.zig b/lib/std/fmt.zig index 52bc25af00..563a67bc89 100644 --- a/lib/std/fmt.zig +++ b/lib/std/fmt.zig @@ -902,7 +902,7 @@ pub fn formatText( } else if (comptime std.mem.eql(u8, fmt, "Z")) { @compileError("specifier 'Z' has been deprecated, wrap your argument in std.zig.fmtEscapes instead"); } else { - @compileError("Unsupported format string '" ++ fmt ++ "' for type '" ++ @typeName(@TypeOf(value)) ++ "'"); + @compileError("Unsupported format string '" ++ fmt ++ "' when formatting text"); } } diff --git a/lib/std/fs.zig b/lib/std/fs.zig index 0f577436be..1f063bb88a 100644 --- a/lib/std/fs.zig +++ b/lib/std/fs.zig @@ -880,20 +880,20 @@ pub const Dir = struct { var fdflags: w.fdflags_t = 0x0; var base: w.rights_t = 0x0; if (flags.read) { - base |= w.RIGHT_FD_READ | w.RIGHT_FD_TELL | w.RIGHT_FD_SEEK | w.RIGHT_FD_FILESTAT_GET; + base |= w.RIGHT.FD_READ | w.RIGHT.FD_TELL | w.RIGHT.FD_SEEK | w.RIGHT.FD_FILESTAT_GET; } if (flags.write) { - fdflags |= w.FDFLAG_APPEND; - base |= w.RIGHT_FD_WRITE | - w.RIGHT_FD_TELL | - w.RIGHT_FD_SEEK | - w.RIGHT_FD_DATASYNC | - w.RIGHT_FD_FDSTAT_SET_FLAGS | - w.RIGHT_FD_SYNC | - w.RIGHT_FD_ALLOCATE | - w.RIGHT_FD_ADVISE | - w.RIGHT_FD_FILESTAT_SET_TIMES | - w.RIGHT_FD_FILESTAT_SET_SIZE; + fdflags |= w.FDFLAG.APPEND; + base |= w.RIGHT.FD_WRITE | + w.RIGHT.FD_TELL | + w.RIGHT.FD_SEEK | + w.RIGHT.FD_DATASYNC | + w.RIGHT.FD_FDSTAT_SET_FLAGS | + w.RIGHT.FD_SYNC | + w.RIGHT.FD_ALLOCATE | + w.RIGHT.FD_ADVISE | + w.RIGHT.FD_FILESTAT_SET_TIMES | + w.RIGHT.FD_FILESTAT_SET_SIZE; } const fd = try os.openatWasi(self.fd, sub_path, 0x0, 0x0, fdflags, base, 0x0); return File{ .handle = fd }; @@ -958,14 +958,14 @@ pub const Dir = struct { } if (has_flock_open_flags and flags.lock_nonblocking) { - var fl_flags = os.fcntl(fd, os.F_GETFL, 0) catch |err| switch (err) { + var fl_flags = os.fcntl(fd, os.F.GETFL, 0) catch |err| switch (err) { error.FileBusy => unreachable, error.Locked => unreachable, error.PermissionDenied => unreachable, else => |e| return e, }; fl_flags &= ~@as(usize, os.O.NONBLOCK); - _ = os.fcntl(fd, os.F_SETFL, fl_flags) catch |err| switch (err) { + _ = os.fcntl(fd, os.F.SETFL, fl_flags) catch |err| switch (err) { error.FileBusy => unreachable, error.Locked => unreachable, error.PermissionDenied => unreachable, @@ -1040,19 +1040,19 @@ pub const Dir = struct { pub fn createFileWasi(self: Dir, sub_path: []const u8, flags: File.CreateFlags) File.OpenError!File { const w = os.wasi; var oflags = w.O.CREAT; - var base: w.rights_t = w.RIGHT_FD_WRITE | - w.RIGHT_FD_DATASYNC | - w.RIGHT_FD_SEEK | - w.RIGHT_FD_TELL | - w.RIGHT_FD_FDSTAT_SET_FLAGS | - w.RIGHT_FD_SYNC | - w.RIGHT_FD_ALLOCATE | - w.RIGHT_FD_ADVISE | - w.RIGHT_FD_FILESTAT_SET_TIMES | - w.RIGHT_FD_FILESTAT_SET_SIZE | - w.RIGHT_FD_FILESTAT_GET; + var base: w.rights_t = w.RIGHT.FD_WRITE | + w.RIGHT.FD_DATASYNC | + w.RIGHT.FD_SEEK | + w.RIGHT.FD_TELL | + w.RIGHT.FD_FDSTAT_SET_FLAGS | + w.RIGHT.FD_SYNC | + w.RIGHT.FD_ALLOCATE | + w.RIGHT.FD_ADVISE | + w.RIGHT.FD_FILESTAT_SET_TIMES | + w.RIGHT.FD_FILESTAT_SET_SIZE | + w.RIGHT.FD_FILESTAT_GET; if (flags.read) { - base |= w.RIGHT_FD_READ; + base |= w.RIGHT.FD_READ; } if (flags.truncate) { oflags |= w.O.TRUNC; @@ -1112,14 +1112,14 @@ pub const Dir = struct { } if (has_flock_open_flags and flags.lock_nonblocking) { - var fl_flags = os.fcntl(fd, os.F_GETFL, 0) catch |err| switch (err) { + var fl_flags = os.fcntl(fd, os.F.GETFL, 0) catch |err| switch (err) { error.FileBusy => unreachable, error.Locked => unreachable, error.PermissionDenied => unreachable, else => |e| return e, }; fl_flags &= ~@as(usize, os.O.NONBLOCK); - _ = os.fcntl(fd, os.F_SETFL, fl_flags) catch |err| switch (err) { + _ = os.fcntl(fd, os.F.SETFL, fl_flags) catch |err| switch (err) { error.FileBusy => unreachable, error.Locked => unreachable, error.PermissionDenied => unreachable, @@ -1402,27 +1402,27 @@ pub const Dir = struct { /// Same as `openDir` except only WASI. pub fn openDirWasi(self: Dir, sub_path: []const u8, args: OpenDirOptions) OpenError!Dir { const w = os.wasi; - var base: w.rights_t = w.RIGHT_FD_FILESTAT_GET | w.RIGHT_FD_FDSTAT_SET_FLAGS | w.RIGHT_FD_FILESTAT_SET_TIMES; + var base: w.rights_t = w.RIGHT.FD_FILESTAT_GET | w.RIGHT.FD_FDSTAT_SET_FLAGS | w.RIGHT.FD_FILESTAT_SET_TIMES; if (args.access_sub_paths) { - base |= w.RIGHT_FD_READDIR | - w.RIGHT_PATH_CREATE_DIRECTORY | - w.RIGHT_PATH_CREATE_FILE | - w.RIGHT_PATH_LINK_SOURCE | - w.RIGHT_PATH_LINK_TARGET | - w.RIGHT_PATH_OPEN | - w.RIGHT_PATH_READLINK | - w.RIGHT_PATH_RENAME_SOURCE | - w.RIGHT_PATH_RENAME_TARGET | - w.RIGHT_PATH_FILESTAT_GET | - w.RIGHT_PATH_FILESTAT_SET_SIZE | - w.RIGHT_PATH_FILESTAT_SET_TIMES | - w.RIGHT_PATH_SYMLINK | - w.RIGHT_PATH_REMOVE_DIRECTORY | - w.RIGHT_PATH_UNLINK_FILE; + base |= w.RIGHT.FD_READDIR | + w.RIGHT.PATH_CREATE_DIRECTORY | + w.RIGHT.PATH_CREATE_FILE | + w.RIGHT.PATH_LINK_SOURCE | + w.RIGHT.PATH_LINK_TARGET | + w.RIGHT.PATH_OPEN | + w.RIGHT.PATH_READLINK | + w.RIGHT.PATH_RENAME_SOURCE | + w.RIGHT.PATH_RENAME_TARGET | + w.RIGHT.PATH_FILESTAT_GET | + w.RIGHT.PATH_FILESTAT_SET_SIZE | + w.RIGHT.PATH_FILESTAT_SET_TIMES | + w.RIGHT.PATH_SYMLINK | + w.RIGHT.PATH_REMOVE_DIRECTORY | + w.RIGHT.PATH_UNLINK_FILE; } const symlink_flags: w.lookupflags_t = if (args.no_follow) 0x0 else w.LOOKUP_SYMLINK_FOLLOW; // TODO do we really need all the rights here? - const inheriting: w.rights_t = w.RIGHT_ALL ^ w.RIGHT_SOCK_SHUTDOWN; + const inheriting: w.rights_t = w.RIGHT.ALL ^ w.RIGHT.SOCK_SHUTDOWN; const result = os.openatWasi(self.fd, sub_path, symlink_flags, w.O.DIRECTORY, 0x0, base, inheriting); const fd = result catch |err| switch (err) { diff --git a/lib/std/fs/wasi.zig b/lib/std/fs/wasi.zig index ed901c37d3..5ace21ecd7 100644 --- a/lib/std/fs/wasi.zig +++ b/lib/std/fs/wasi.zig @@ -4,6 +4,8 @@ const mem = std.mem; const math = std.math; const Allocator = mem.Allocator; const wasi = std.os.wasi; +const fd_t = wasi.fd_t; +const prestat_t = wasi.prestat_t; /// Type-tag of WASI preopen. /// @@ -114,7 +116,7 @@ pub const PreopenList = struct { while (true) { var buf: prestat_t = undefined; - switch (fd_prestat_get(fd, &buf)) { + switch (wasi.fd_prestat_get(fd, &buf)) { .SUCCESS => {}, .OPNOTSUPP => { // not a preopen, so keep going @@ -130,7 +132,7 @@ pub const PreopenList = struct { const preopen_len = buf.u.dir.pr_name_len; const path_buf = try self.buffer.allocator.alloc(u8, preopen_len); mem.set(u8, path_buf, 0); - switch (fd_prestat_dir_name(fd, path_buf.ptr, preopen_len)) { + switch (wasi.fd_prestat_dir_name(fd, path_buf.ptr, preopen_len)) { .SUCCESS => {}, else => |err| return os.unexpectedErrno(err), } diff --git a/lib/std/hash_map.zig b/lib/std/hash_map.zig index 06071f0a0b..765add1e68 100644 --- a/lib/std/hash_map.zig +++ b/lib/std/hash_map.zig @@ -622,8 +622,12 @@ pub fn HashMap( return other.promoteContext(self.allocator, new_ctx); } - /// Creates a copy of this map, using a specified allocator and context - pub fn cloneWithAllocatorAndContext(new_allocator: *Allocator, new_ctx: anytype) !HashMap(K, V, @TypeOf(new_ctx), max_load_percentage) { + /// Creates a copy of this map, using a specified allocator and context. + pub fn cloneWithAllocatorAndContext( + self: Self, + new_allocator: *Allocator, + new_ctx: anytype, + ) !HashMap(K, V, @TypeOf(new_ctx), max_load_percentage) { var other = try self.unmanaged.cloneContext(new_allocator, new_ctx); return other.promoteContext(new_allocator, new_ctx); } diff --git a/lib/std/heap.zig b/lib/std/heap.zig index 55c7b4ee70..e6e7af4626 100644 --- a/lib/std/heap.zig +++ b/lib/std/heap.zig @@ -88,12 +88,12 @@ const CAllocator = struct { fn alignedAllocSize(ptr: [*]u8) usize { if (supports_posix_memalign) { - return malloc_size(ptr); + return CAllocator.malloc_size(ptr); } const unaligned_ptr = getHeader(ptr).*; const delta = @ptrToInt(ptr) - @ptrToInt(unaligned_ptr); - return malloc_size(unaligned_ptr) - delta; + return CAllocator.malloc_size(unaligned_ptr) - delta; } fn alloc( @@ -113,7 +113,7 @@ const CAllocator = struct { return ptr[0..len]; } const full_len = init: { - if (supports_malloc_size) { + if (CAllocator.supports_malloc_size) { const s = alignedAllocSize(ptr); assert(s >= len); break :init s; @@ -141,7 +141,7 @@ const CAllocator = struct { if (new_len <= buf.len) { return mem.alignAllocLen(buf.len, new_len, len_align); } - if (supports_malloc_size) { + if (CAllocator.supports_malloc_size) { const full_len = alignedAllocSize(buf.ptr); if (new_len <= full_len) { return mem.alignAllocLen(full_len, new_len, len_align); diff --git a/lib/std/io/c_writer.zig b/lib/std/io/c_writer.zig index 758df71165..07a719b0c2 100644 --- a/lib/std/io/c_writer.zig +++ b/lib/std/io/c_writer.zig @@ -2,6 +2,7 @@ const std = @import("../std.zig"); const builtin = std.builtin; const io = std.io; const testing = std.testing; +const os = std.os; pub const CWriter = io.Writer(*std.c.FILE, std.fs.File.WriteError, cWriterWrite); diff --git a/lib/std/json.zig b/lib/std/json.zig index ce9ed9af7d..d3da57d18b 100644 --- a/lib/std/json.zig +++ b/lib/std/json.zig @@ -1405,7 +1405,7 @@ fn parsedEqual(a: anytype, b: @TypeOf(a)) bool { if (a == null or b == null) return false; return parsedEqual(a.?, b.?); }, - .Union => { + .Union => |info| { if (info.tag_type) |UnionTag| { const tag_a = std.meta.activeTag(a); const tag_b = std.meta.activeTag(b); diff --git a/lib/std/math/big/int.zig b/lib/std/math/big/int.zig index e289520e57..9efd4d5752 100644 --- a/lib/std/math/big/int.zig +++ b/lib/std/math/big/int.zig @@ -672,10 +672,9 @@ pub const Mutable = struct { /// /// `limbs_buffer` is used for temporary storage during the operation. pub fn gcdNoAlias(rma: *Mutable, x: Const, y: Const, limbs_buffer: *std.ArrayList(Limb)) !void { - _ = limbs_buffer; assert(rma.limbs.ptr != x.limbs.ptr); // illegal aliasing assert(rma.limbs.ptr != y.limbs.ptr); // illegal aliasing - return gcdLehmer(rma, x, y, allocator); + return gcdLehmer(rma, x, y, limbs_buffer); } fn gcdLehmer(result: *Mutable, xa: Const, ya: Const, limbs_buffer: *std.ArrayList(Limb)) !void { diff --git a/lib/std/os.zig b/lib/std/os.zig index c8350fb1d8..c688eedec8 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -78,6 +78,7 @@ pub const HOST_NAME_MAX = system.HOST_NAME_MAX; pub const IFNAMESIZE = system.IFNAMESIZE; pub const IOV_MAX = system.IOV_MAX; pub const IPPROTO = system.IPPROTO; +pub const Kevent = system.Kevent; pub const LOCK = system.LOCK; pub const MADV = system.MADV; pub const MAP = system.MAP; @@ -89,8 +90,10 @@ pub const O = system.O; pub const PATH_MAX = system.PATH_MAX; pub const POLL = system.POLL; pub const POSIX_FADV = system.POSIX_FADV; +pub const PR = system.PR; pub const PROT = system.PROT; pub const REG = system.REG; +pub const RIGHT = system.RIGHT; pub const RLIM = system.RLIM; pub const RR = system.RR; pub const R_OK = system.R_OK; @@ -110,6 +113,7 @@ pub const STDOUT_FILENO = system.STDOUT_FILENO; pub const SYS = system.SYS; pub const Sigaction = system.Sigaction; pub const Stat = system.Stat; +pub const TCSA = system.TCSA; pub const VDSO = system.VDSO; pub const W = system.W; pub const W_OK = system.W_OK; @@ -123,9 +127,12 @@ 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 fd_t = system.fd_t; +pub const fdflags_t = system.fdflags_t; +pub const fdstat_t = system.fdstat_t; pub const gid_t = system.gid_t; pub const ifreq = system.ifreq; pub const ino_t = system.ino_t; +pub const lookupflags_t = system.lookupflags_t; pub const mcontext_t = system.mcontext_t; pub const mode_t = system.mode_t; pub const msghdr = system.msghdr; @@ -133,19 +140,24 @@ pub const msghdr_const = system.msghdr_const; pub const nfds_t = system.nfds_t; pub const nlink_t = system.nlink_t; pub const off_t = system.off_t; +pub const oflags_t = system.oflags_t; pub const pid_t = system.pid_t; pub const pollfd = system.pollfd; +pub const rights_t = system.rights_t; pub const rlim_t = system.rlim_t; pub const rlimit = system.rlimit; pub const rlimit_resource = system.rlimit_resource; +pub const rusage = system.rusage; pub const sa_family_t = system.sa_family_t; pub const siginfo_t = system.siginfo_t; pub const sigset_t = system.sigset_t; pub const sockaddr = system.sockaddr; pub const socklen_t = system.socklen_t; pub const stack_t = system.stack_t; +pub const termios = system.termios; pub const time_t = system.time_t; pub const timespec = system.timespec; +pub const timestamp_t = system.timestamp_t; pub const timeval = system.timeval; pub const timezone = system.timezone; pub const ucontext_t = system.ucontext_t; @@ -2770,8 +2782,8 @@ pub fn isatty(handle: fd_t) bool { } // A tty is a character device that we can't seek or tell on. - if (statbuf.fs_filetype != FILETYPE_CHARACTER_DEVICE or - (statbuf.fs_rights_base & (RIGHT_FD_SEEK | RIGHT_FD_TELL)) != 0) + if (statbuf.fs_filetype != .CHARACTER_DEVICE or + (statbuf.fs_rights_base & (RIGHT.FD_SEEK | RIGHT.FD_TELL)) != 0) { // errno = ENOTTY; return false; @@ -3933,7 +3945,7 @@ pub const AccessError = error{ } || UnexpectedError; /// check user's permissions for a file -/// TODO currently this assumes `mode` is `F_OK` on Windows. +/// TODO currently this assumes `mode` is `F.OK` on Windows. pub fn access(path: []const u8, mode: u32) AccessError!void { if (builtin.os.tag == .windows) { const path_w = try windows.sliceToPrefixedFileW(path); @@ -4104,10 +4116,10 @@ pub fn pipe2(flags: u32) PipeError![2]fd_t { return fds; // O.CLOEXEC is special, it's a file descriptor flag and must be set using - // F_SETFD. + // F.SETFD. if (flags & O.CLOEXEC != 0) { for (fds) |fd| { - switch (errno(system.fcntl(fd, F_SETFD, @as(u32, FD_CLOEXEC)))) { + switch (errno(system.fcntl(fd, F.SETFD, @as(u32, FD_CLOEXEC)))) { .SUCCESS => {}, .INVAL => unreachable, // Invalid flags .BADF => unreachable, // Always a race condition @@ -4117,10 +4129,10 @@ pub fn pipe2(flags: u32) PipeError![2]fd_t { } const new_flags = flags & ~@as(u32, O.CLOEXEC); - // Set every other flag affecting the file status using F_SETFL. + // Set every other flag affecting the file status using F.SETFL. if (new_flags != 0) { for (fds) |fd| { - switch (errno(system.fcntl(fd, F_SETFL, new_flags))) { + switch (errno(system.fcntl(fd, F.SETFL, new_flags))) { .SUCCESS => {}, .INVAL => unreachable, // Invalid flags .BADF => unreachable, // Always a race condition @@ -4425,14 +4437,14 @@ fn setSockFlags(sock: socket_t, flags: u32) !void { if (builtin.os.tag == .windows) { // TODO: Find out if this is supported for sockets } else { - var fd_flags = fcntl(sock, F_GETFD, 0) catch |err| switch (err) { + var fd_flags = fcntl(sock, F.GETFD, 0) catch |err| switch (err) { error.FileBusy => unreachable, error.Locked => unreachable, error.PermissionDenied => unreachable, else => |e| return e, }; fd_flags |= FD_CLOEXEC; - _ = fcntl(sock, F_SETFD, fd_flags) catch |err| switch (err) { + _ = fcntl(sock, F.SETFD, fd_flags) catch |err| switch (err) { error.FileBusy => unreachable, error.Locked => unreachable, error.PermissionDenied => unreachable, @@ -4453,14 +4465,14 @@ fn setSockFlags(sock: socket_t, flags: u32) !void { } } } else { - var fl_flags = fcntl(sock, F_GETFL, 0) catch |err| switch (err) { + var fl_flags = fcntl(sock, F.GETFL, 0) catch |err| switch (err) { error.FileBusy => unreachable, error.Locked => unreachable, error.PermissionDenied => unreachable, else => |e| return e, }; fl_flags |= O.NONBLOCK; - _ = fcntl(sock, F_SETFL, fl_flags) catch |err| switch (err) { + _ = fcntl(sock, F.SETFL, fl_flags) catch |err| switch (err) { error.FileBusy => unreachable, error.Locked => unreachable, error.PermissionDenied => unreachable, @@ -4625,14 +4637,14 @@ pub fn getFdPath(fd: fd_t, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 { return out_buffer[0..end_index]; }, .macos, .ios, .watchos, .tvos => { - // On macOS, we can use F_GETPATH fcntl command to query the OS for + // On macOS, we can use F.GETPATH fcntl command to query the OS for // the path to the file descriptor. @memset(out_buffer, 0, MAX_PATH_BYTES); - switch (errno(system.fcntl(fd, F_GETPATH, out_buffer))) { + switch (errno(system.fcntl(fd, F.GETPATH, out_buffer))) { .SUCCESS => {}, .BADF => return error.FileNotFound, // TODO man pages for fcntl on macOS don't really tell you what - // errno values to expect when command is F_GETPATH... + // errno values to expect when command is F.GETPATH... else => |err| return unexpectedErrno(err), } const len = mem.indexOfScalar(u8, out_buffer[0..], @as(u8, 0)) orelse MAX_PATH_BYTES; diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig index 6c8dd85e64..ecfded4193 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -50,8 +50,12 @@ pub const syscall3 = syscall_bits.syscall3; pub const syscall4 = syscall_bits.syscall4; pub const syscall5 = syscall_bits.syscall5; pub const syscall6 = syscall_bits.syscall6; +pub const syscall7 = syscall_bits.syscall7; pub const restore = syscall_bits.restore; pub const restore_rt = syscall_bits.restore_rt; +pub const socketcall = syscall_bits.socketcall; +pub const syscall_pipe = syscall_bits.syscall_pipe; +pub const syscall_fork = syscall_bits.syscall_fork; pub const clone = arch_bits.clone; pub const ARCH = arch_bits.ARCH; @@ -181,7 +185,7 @@ pub fn dup2(old: i32, new: i32) usize { } else { if (old == new) { if (std.debug.runtime_safety) { - const rc = syscall2(.fcntl, @bitCast(usize, @as(isize, old)), F_GETFD); + const rc = syscall2(.fcntl, @bitCast(usize, @as(isize, old)), F.GETFD); if (@bitCast(isize, rc) < 0) return rc; } return @intCast(usize, old); @@ -217,7 +221,7 @@ pub fn fork() usize { } else if (@hasField(SYS, "fork")) { return syscall0(.fork); } else { - return syscall2(.clone, SIGCHLD, 0); + return syscall2(.clone, SIG.CHLD, 0); } } @@ -821,7 +825,7 @@ var vdso_clock_gettime = @ptrCast(?*const c_void, init_vdso_clock_gettime); const vdso_clock_gettime_ty = fn (i32, *timespec) callconv(.C) usize; pub fn clock_gettime(clk_id: i32, tp: *timespec) usize { - if (@hasDecl(@This(), "VDSO_CGT_SYM")) { + if (@hasDecl(VDSO, "CGT_SYM")) { const ptr = @atomicLoad(?*const c_void, &vdso_clock_gettime, .Unordered); if (ptr) |fn_ptr| { const f = @ptrCast(vdso_clock_gettime_ty, fn_ptr); @@ -836,7 +840,7 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) usize { } fn init_vdso_clock_gettime(clk: i32, ts: *timespec) callconv(.C) usize { - const ptr = @intToPtr(?*const c_void, vdso.lookup(VDSO_CGT_VER, VDSO_CGT_SYM)); + const ptr = @intToPtr(?*const c_void, 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 @atomicStore(?*const c_void, &vdso_clock_gettime, ptr, .Monotonic); @@ -1070,42 +1074,42 @@ pub fn sigismember(set: *const sigset_t, sig: u6) bool { pub fn getsockname(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize { if (native_arch == .i386) { - return socketcall(SC_getsockname, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len) }); + return socketcall(SC.getsockname, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len) }); } return syscall3(.getsockname, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len)); } pub fn getpeername(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize { if (native_arch == .i386) { - return socketcall(SC_getpeername, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len) }); + return socketcall(SC.getpeername, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len) }); } return syscall3(.getpeername, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len)); } pub fn socket(domain: u32, socket_type: u32, protocol: u32) usize { if (native_arch == .i386) { - return socketcall(SC_socket, &[3]usize{ domain, socket_type, protocol }); + return socketcall(SC.socket, &[3]usize{ domain, socket_type, protocol }); } return syscall3(.socket, domain, socket_type, protocol); } pub fn setsockopt(fd: i32, level: u32, optname: u32, optval: [*]const u8, optlen: socklen_t) usize { if (native_arch == .i386) { - return socketcall(SC_setsockopt, &[5]usize{ @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @intCast(usize, optlen) }); + return socketcall(SC.setsockopt, &[5]usize{ @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @intCast(usize, optlen) }); } return syscall5(.setsockopt, @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @intCast(usize, optlen)); } pub fn getsockopt(fd: i32, level: u32, optname: u32, noalias optval: [*]u8, noalias optlen: *socklen_t) usize { if (native_arch == .i386) { - return socketcall(SC_getsockopt, &[5]usize{ @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @ptrToInt(optlen) }); + return socketcall(SC.getsockopt, &[5]usize{ @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @ptrToInt(optlen) }); } return syscall5(.getsockopt, @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @ptrToInt(optlen)); } pub fn sendmsg(fd: i32, msg: *const std.x.os.Socket.Message, flags: c_int) usize { if (native_arch == .i386) { - return socketcall(SC_sendmsg, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), @bitCast(usize, @as(isize, flags)) }); + return socketcall(SC.sendmsg, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), @bitCast(usize, @as(isize, flags)) }); } return syscall3(.sendmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), @bitCast(usize, @as(isize, flags))); } @@ -1152,49 +1156,49 @@ pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize pub fn connect(fd: i32, addr: *const c_void, len: socklen_t) usize { if (native_arch == .i386) { - return socketcall(SC_connect, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), len }); + return socketcall(SC.connect, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), len }); } return syscall3(.connect, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), len); } pub fn recvmsg(fd: i32, msg: *std.x.os.Socket.Message, flags: c_int) usize { if (native_arch == .i386) { - return socketcall(SC_recvmsg, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), @bitCast(usize, @as(isize, flags)) }); + return socketcall(SC.recvmsg, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), @bitCast(usize, @as(isize, flags)) }); } return syscall3(.recvmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), @bitCast(usize, @as(isize, flags))); } pub fn recvfrom(fd: i32, noalias buf: [*]u8, len: usize, flags: u32, noalias addr: ?*sockaddr, noalias alen: ?*socklen_t) usize { if (native_arch == .i386) { - return socketcall(SC_recvfrom, &[6]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen) }); + return socketcall(SC.recvfrom, &[6]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen) }); } return syscall6(.recvfrom, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen)); } pub fn shutdown(fd: i32, how: i32) usize { if (native_arch == .i386) { - return socketcall(SC_shutdown, &[2]usize{ @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, how)) }); + return socketcall(SC.shutdown, &[2]usize{ @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, how)) }); } return syscall2(.shutdown, @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, how))); } pub fn bind(fd: i32, addr: *const sockaddr, len: socklen_t) usize { if (native_arch == .i386) { - return socketcall(SC_bind, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @intCast(usize, len) }); + return socketcall(SC.bind, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @intCast(usize, len) }); } return syscall3(.bind, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @intCast(usize, len)); } pub fn listen(fd: i32, backlog: u32) usize { if (native_arch == .i386) { - return socketcall(SC_listen, &[2]usize{ @bitCast(usize, @as(isize, fd)), backlog }); + return socketcall(SC.listen, &[2]usize{ @bitCast(usize, @as(isize, fd)), backlog }); } return syscall2(.listen, @bitCast(usize, @as(isize, fd)), backlog); } pub fn sendto(fd: i32, buf: [*]const u8, len: usize, flags: u32, addr: ?*const sockaddr, alen: socklen_t) usize { if (native_arch == .i386) { - return socketcall(SC_sendto, &[6]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @intCast(usize, alen) }); + return socketcall(SC.sendto, &[6]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @intCast(usize, alen) }); } return syscall6(.sendto, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @intCast(usize, alen)); } @@ -1221,21 +1225,21 @@ pub fn sendfile(outfd: i32, infd: i32, offset: ?*i64, count: usize) usize { pub fn socketpair(domain: i32, socket_type: i32, protocol: i32, fd: [2]i32) usize { if (native_arch == .i386) { - return socketcall(SC_socketpair, &[4]usize{ @intCast(usize, domain), @intCast(usize, socket_type), @intCast(usize, protocol), @ptrToInt(&fd[0]) }); + return socketcall(SC.socketpair, &[4]usize{ @intCast(usize, domain), @intCast(usize, socket_type), @intCast(usize, protocol), @ptrToInt(&fd[0]) }); } return syscall4(.socketpair, @intCast(usize, domain), @intCast(usize, socket_type), @intCast(usize, protocol), @ptrToInt(&fd[0])); } pub fn accept(fd: i32, noalias addr: ?*sockaddr, noalias len: ?*socklen_t) usize { if (native_arch == .i386) { - return socketcall(SC_accept, &[4]usize{ fd, addr, len, 0 }); + return socketcall(SC.accept, &[4]usize{ fd, addr, len, 0 }); } return accept4(fd, addr, len, 0); } pub fn accept4(fd: i32, noalias addr: ?*sockaddr, noalias len: ?*socklen_t, flags: u32) usize { if (native_arch == .i386) { - return socketcall(SC_accept4, &[4]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len), flags }); + return socketcall(SC.accept4, &[4]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len), flags }); } return syscall4(.accept4, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len), flags); } @@ -1435,11 +1439,11 @@ pub fn getrusage(who: i32, usage: *rusage) usize { } pub fn tcgetattr(fd: fd_t, termios_p: *termios) usize { - return syscall3(.ioctl, @bitCast(usize, @as(isize, fd)), TCGETS, @ptrToInt(termios_p)); + return syscall3(.ioctl, @bitCast(usize, @as(isize, fd)), T.CGETS, @ptrToInt(termios_p)); } pub fn tcsetattr(fd: fd_t, optional_action: TCSA, termios_p: *const termios) usize { - return syscall3(.ioctl, @bitCast(usize, @as(isize, fd)), TCSETS + @enumToInt(optional_action), @ptrToInt(termios_p)); + return syscall3(.ioctl, @bitCast(usize, @as(isize, fd)), T.CSETS + @enumToInt(optional_action), @ptrToInt(termios_p)); } pub fn ioctl(fd: fd_t, request: u32, arg: usize) usize { @@ -1900,7 +1904,7 @@ pub const SIG = if (is_mips) struct { pub const IOT = ABRT; pub const CLD = CHLD; pub const PWR = LOST; - pub const IO = POLL; + pub const IO = SIG.POLL; pub const ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize)); pub const DFL = @intToPtr(?Sigaction.sigaction_fn, 0); @@ -1996,8 +2000,8 @@ pub const SOCK = struct { pub const PF = struct { pub const UNSPEC = 0; pub const LOCAL = 1; - pub const UNIX = PF_LOCAL; - pub const FILE = PF_LOCAL; + pub const UNIX = LOCAL; + pub const FILE = LOCAL; pub const INET = 2; pub const AX25 = 3; pub const IPX = 4; @@ -2013,7 +2017,7 @@ pub const PF = struct { pub const SECURITY = 14; pub const KEY = 15; pub const NETLINK = 16; - pub const ROUTE = PF_NETLINK; + pub const ROUTE = PF.NETLINK; pub const PACKET = 17; pub const ASH = 18; pub const ECONET = 19; @@ -2357,7 +2361,7 @@ pub const IP = struct { pub const PASSSEC = 18; pub const TRANSPARENT = 19; pub const ORIGDSTADDR = 20; - pub const RECVORIGDSTADDR = IP_ORIGDSTADDR; + pub const RECVORIGDSTADDR = IP.ORIGDSTADDR; pub const MINTTL = 21; pub const NODEFRAG = 22; pub const CHECKSUM = 23; @@ -2376,7 +2380,7 @@ pub const IP = struct { pub const MULTICAST_ALL = 49; pub const UNICAST_IF = 50; - pub const RECVRETOPTS = IP_RETOPTS; + pub const RECVRETOPTS = IP.RETOPTS; pub const PMTUDISC_DONT = 0; pub const PMTUDISC_WANT = 1; @@ -2418,7 +2422,7 @@ pub const IPV6 = struct { pub const JOIN_ANYCAST = 27; pub const LEAVE_ANYCAST = 28; - // IPV6_MTU_DISCOVER values + // IPV6.MTU_DISCOVER values pub const PMTUDISC_DONT = 0; pub const PMTUDISC_WANT = 1; pub const PMTUDISC_DO = 2; @@ -2470,7 +2474,7 @@ pub const IPV6 = struct { pub const MINHOPCOUNT = 73; pub const ORIGDSTADDR = 74; - pub const RECVORIGDSTADDR = IPV6_ORIGDSTADDR; + pub const RECVORIGDSTADDR = IPV6.ORIGDSTADDR; pub const TRANSPARENT = 75; pub const UNICAST_IF = 76; pub const RECVFRAGSIZE = 77; @@ -3924,8 +3928,8 @@ pub const V = switch (native_arch) { pub const DISCARD = 13; pub const WERASE = 14; pub const LNEXT = 15; - pub const MIN = VEOF; - pub const TIME = VEOL; + pub const MIN = EOF; + pub const TIME = EOL; }, .mips, .mipsel, .mips64, .mips64el => struct { pub const INTR = 0; diff --git a/lib/std/os/linux/arm-eabi.zig b/lib/std/os/linux/arm-eabi.zig index 87567d5e89..8f472b87f5 100644 --- a/lib/std/os/linux/arm-eabi.zig +++ b/lib/std/os/linux/arm-eabi.zig @@ -551,29 +551,31 @@ pub const O_PATH = 0o10000000; pub const O_TMPFILE = 0o20040000; pub const O_NDELAY = O_NONBLOCK; -pub const F_DUPFD = 0; -pub const F_GETFD = 1; -pub const F_SETFD = 2; -pub const F_GETFL = 3; -pub const F_SETFL = 4; - -pub const F_SETOWN = 8; -pub const F_GETOWN = 9; -pub const F_SETSIG = 10; -pub const F_GETSIG = 11; - -pub const F_GETLK = 12; -pub const F_SETLK = 13; -pub const F_SETLKW = 14; - -pub const F_RDLCK = 0; -pub const F_WRLCK = 1; -pub const F_UNLCK = 2; - -pub const F_SETOWN_EX = 15; -pub const F_GETOWN_EX = 16; - -pub const F_GETOWNER_UIDS = 17; +pub const F = struct { + pub const DUPFD = 0; + pub const GETFD = 1; + pub const SETFD = 2; + pub const GETFL = 3; + pub const SETFL = 4; + + pub const SETOWN = 8; + pub const GETOWN = 9; + pub const SETSIG = 10; + pub const GETSIG = 11; + + pub const GETLK = 12; + pub const SETLK = 13; + pub const SETLKW = 14; + + pub const RDLCK = 0; + pub const WRLCK = 1; + pub const UNLCK = 2; + + pub const SETOWN_EX = 15; + pub const GETOWN_EX = 16; + + pub const GETOWNER_UIDS = 17; +}; pub const LOCK = struct { pub const SH = 1; diff --git a/lib/std/os/linux/arm64.zig b/lib/std/os/linux/arm64.zig index 7a7dd997fd..1c3033a226 100644 --- a/lib/std/os/linux/arm64.zig +++ b/lib/std/os/linux/arm64.zig @@ -430,24 +430,31 @@ pub const O_PATH = 0o10000000; pub const O_TMPFILE = 0o20040000; pub const O_NDELAY = O_NONBLOCK; -pub const F_DUPFD = 0; -pub const F_GETFD = 1; -pub const F_SETFD = 2; -pub const F_GETFL = 3; -pub const F_SETFL = 4; - -pub const F_SETOWN = 8; -pub const F_GETOWN = 9; -pub const F_SETSIG = 10; -pub const F_GETSIG = 11; - -pub const F_GETLK = 5; -pub const F_SETLK = 6; -pub const F_SETLKW = 7; - -pub const F_RDLCK = 0; -pub const F_WRLCK = 1; -pub const F_UNLCK = 2; +pub const F = struct { + pub const DUPFD = 0; + pub const GETFD = 1; + pub const SETFD = 2; + pub const GETFL = 3; + pub const SETFL = 4; + + pub const SETOWN = 8; + pub const GETOWN = 9; + pub const SETSIG = 10; + pub const GETSIG = 11; + + pub const GETLK = 5; + pub const SETLK = 6; + pub const SETLKW = 7; + + pub const RDLCK = 0; + pub const WRLCK = 1; + pub const UNLCK = 2; + + pub const SETOWN_EX = 15; + pub const GETOWN_EX = 16; + + pub const GETOWNER_UIDS = 17; +}; pub const LOCK = struct { pub const SH = 1; @@ -456,11 +463,6 @@ pub const LOCK = struct { pub const NB = 4; }; -pub const F_SETOWN_EX = 15; -pub const F_GETOWN_EX = 16; - -pub const F_GETOWNER_UIDS = 17; - pub const MAP = struct { /// stack-like segment pub const GROWSDOWN = 0x0100; diff --git a/lib/std/os/linux/io_uring.zig b/lib/std/os/linux/io_uring.zig index 0e02b67d2c..bba9786a90 100644 --- a/lib/std/os/linux/io_uring.zig +++ b/lib/std/os/linux/io_uring.zig @@ -1297,12 +1297,12 @@ test "openat" { const flags: u32 = os.O_CLOEXEC | os.O_RDWR | os.O_CREAT; const mode: os.mode_t = 0o666; - const sqe_openat = try ring.openat(0x33333333, linux.AT_FDCWD, path, flags, mode); + const sqe_openat = try ring.openat(0x33333333, linux.AT.FDCWD, path, flags, mode); try testing.expectEqual(io_uring_sqe{ .opcode = .OPENAT, .flags = 0, .ioprio = 0, - .fd = linux.AT_FDCWD, + .fd = linux.AT.FDCWD, .off = 0, .addr = @ptrToInt(path), .len = mode, @@ -1318,7 +1318,7 @@ test "openat" { const cqe_openat = try ring.copy_cqe(); try testing.expectEqual(@as(u64, 0x33333333), cqe_openat.user_data); if (cqe_openat.err() == .INVAL) return error.SkipZigTest; - // AT_FDCWD is not fully supported before kernel 5.6: + // AT.FDCWD is not fully supported before kernel 5.6: // See https://lore.kernel.org/io-uring/20200207155039.12819-1-axboe@kernel.dk/T/ // We use IORING_FEAT_RW_CUR_POS to know if we are pre-5.6 since that feature was added in 5.6. if (cqe_openat.err() == .BADF and (ring.features & linux.IORING_FEAT_RW_CUR_POS) == 0) { diff --git a/lib/std/os/linux/mips.zig b/lib/std/os/linux/mips.zig index a69e186079..cc8334cf49 100644 --- a/lib/std/os/linux/mips.zig +++ b/lib/std/os/linux/mips.zig @@ -649,24 +649,31 @@ pub const O_PATH = 0o010000000; pub const O_TMPFILE = 0o020200000; pub const O_NDELAY = O_NONBLOCK; -pub const F_DUPFD = 0; -pub const F_GETFD = 1; -pub const F_SETFD = 2; -pub const F_GETFL = 3; -pub const F_SETFL = 4; - -pub const F_SETOWN = 24; -pub const F_GETOWN = 23; -pub const F_SETSIG = 10; -pub const F_GETSIG = 11; - -pub const F_GETLK = 33; -pub const F_SETLK = 34; -pub const F_SETLKW = 35; - -pub const F_RDLCK = 0; -pub const F_WRLCK = 1; -pub const F_UNLCK = 2; +pub const F = struct { + pub const DUPFD = 0; + pub const GETFD = 1; + pub const SETFD = 2; + pub const GETFL = 3; + pub const SETFL = 4; + + pub const SETOWN = 24; + pub const GETOWN = 23; + pub const SETSIG = 10; + pub const GETSIG = 11; + + pub const GETLK = 33; + pub const SETLK = 34; + pub const SETLKW = 35; + + pub const RDLCK = 0; + pub const WRLCK = 1; + pub const UNLCK = 2; + + pub const SETOWN_EX = 15; + pub const GETOWN_EX = 16; + + pub const GETOWNER_UIDS = 17; +}; pub const LOCK = struct { pub const SH = 1; @@ -675,11 +682,6 @@ pub const LOCK = struct { pub const NB = 4; }; -pub const F_SETOWN_EX = 15; -pub const F_GETOWN_EX = 16; - -pub const F_GETOWNER_UIDS = 17; - pub const MMAP2_UNIT = 4096; pub const MAP = struct { diff --git a/lib/std/os/linux/powerpc.zig b/lib/std/os/linux/powerpc.zig index 7fbdb7ea78..51c85d1472 100644 --- a/lib/std/os/linux/powerpc.zig +++ b/lib/std/os/linux/powerpc.zig @@ -581,29 +581,31 @@ pub const O_PATH = 0o10000000; pub const O_TMPFILE = 0o20040000; pub const O_NDELAY = O_NONBLOCK; -pub const F_DUPFD = 0; -pub const F_GETFD = 1; -pub const F_SETFD = 2; -pub const F_GETFL = 3; -pub const F_SETFL = 4; - -pub const F_SETOWN = 8; -pub const F_GETOWN = 9; -pub const F_SETSIG = 10; -pub const F_GETSIG = 11; - -pub const F_GETLK = 12; -pub const F_SETLK = 13; -pub const F_SETLKW = 14; - -pub const F_SETOWN_EX = 15; -pub const F_GETOWN_EX = 16; - -pub const F_GETOWNER_UIDS = 17; - -pub const F_RDLCK = 0; -pub const F_WRLCK = 1; -pub const F_UNLCK = 2; +pub const F = struct { + pub const DUPFD = 0; + pub const GETFD = 1; + pub const SETFD = 2; + pub const GETFL = 3; + pub const SETFL = 4; + + pub const SETOWN = 8; + pub const GETOWN = 9; + pub const SETSIG = 10; + pub const GETSIG = 11; + + pub const GETLK = 12; + pub const SETLK = 13; + pub const SETLKW = 14; + + pub const SETOWN_EX = 15; + pub const GETOWN_EX = 16; + + pub const GETOWNER_UIDS = 17; + + pub const RDLCK = 0; + pub const WRLCK = 1; + pub const UNLCK = 2; +}; pub const LOCK = struct { pub const SH = 1; diff --git a/lib/std/os/linux/powerpc64.zig b/lib/std/os/linux/powerpc64.zig index 175a2afff0..366ddbffa8 100644 --- a/lib/std/os/linux/powerpc64.zig +++ b/lib/std/os/linux/powerpc64.zig @@ -556,24 +556,31 @@ pub const O_PATH = 0o10000000; pub const O_TMPFILE = 0o20200000; pub const O_NDELAY = O_NONBLOCK; -pub const F_DUPFD = 0; -pub const F_GETFD = 1; -pub const F_SETFD = 2; -pub const F_GETFL = 3; -pub const F_SETFL = 4; - -pub const F_SETOWN = 8; -pub const F_GETOWN = 9; -pub const F_SETSIG = 10; -pub const F_GETSIG = 11; - -pub const F_GETLK = 5; -pub const F_SETLK = 6; -pub const F_SETLKW = 7; - -pub const F_RDLCK = 0; -pub const F_WRLCK = 1; -pub const F_UNLCK = 2; +pub const F = struct { + pub const DUPFD = 0; + pub const GETFD = 1; + pub const SETFD = 2; + pub const GETFL = 3; + pub const SETFL = 4; + + pub const SETOWN = 8; + pub const GETOWN = 9; + pub const SETSIG = 10; + pub const GETSIG = 11; + + pub const GETLK = 5; + pub const SETLK = 6; + pub const SETLKW = 7; + + pub const RDLCK = 0; + pub const WRLCK = 1; + pub const UNLCK = 2; + + pub const SETOWN_EX = 15; + pub const GETOWN_EX = 16; + + pub const GETOWNER_UIDS = 17; +}; pub const LOCK = struct { pub const SH = 1; @@ -582,11 +589,6 @@ pub const LOCK = struct { pub const NB = 4; }; -pub const F_SETOWN_EX = 15; -pub const F_GETOWN_EX = 16; - -pub const F_GETOWNER_UIDS = 17; - pub const MAP = struct { /// stack-like segment pub const GROWSDOWN = 0x0100; diff --git a/lib/std/os/linux/riscv64.zig b/lib/std/os/linux/riscv64.zig index a50dcd69b9..0dd947506a 100644 --- a/lib/std/os/linux/riscv64.zig +++ b/lib/std/os/linux/riscv64.zig @@ -427,22 +427,29 @@ pub const O_PATH = 0o10000000; pub const O_TMPFILE = 0o20200000; pub const O_NDELAY = O_NONBLOCK; -pub const F_DUPFD = 0; -pub const F_GETFD = 1; -pub const F_SETFD = 2; -pub const F_GETFL = 3; -pub const F_SETFL = 4; -pub const F_GETLK = 5; -pub const F_SETLK = 6; -pub const F_SETLKW = 7; -pub const F_SETOWN = 8; -pub const F_GETOWN = 9; -pub const F_SETSIG = 10; -pub const F_GETSIG = 11; +pub const F = struct { + pub const DUPFD = 0; + pub const GETFD = 1; + pub const SETFD = 2; + pub const GETFL = 3; + pub const SETFL = 4; + pub const GETLK = 5; + pub const SETLK = 6; + pub const SETLKW = 7; + pub const SETOWN = 8; + pub const GETOWN = 9; + pub const SETSIG = 10; + pub const GETSIG = 11; -pub const F_RDLCK = 0; -pub const F_WRLCK = 1; -pub const F_UNLCK = 2; + pub const RDLCK = 0; + pub const WRLCK = 1; + pub const UNLCK = 2; + + pub const SETOWN_EX = 15; + pub const GETOWN_EX = 16; + + pub const GETOWNER_UIDS = 17; +}; pub const LOCK = struct { pub const SH = 1; @@ -451,11 +458,6 @@ pub const LOCK = struct { pub const NB = 4; }; -pub const F_SETOWN_EX = 15; -pub const F_GETOWN_EX = 16; - -pub const F_GETOWNER_UIDS = 17; - pub const blksize_t = i32; pub const nlink_t = u32; pub const time_t = isize; diff --git a/lib/std/os/linux/sparc64.zig b/lib/std/os/linux/sparc64.zig index f87b861ee2..fd34b34ae4 100644 --- a/lib/std/os/linux/sparc64.zig +++ b/lib/std/os/linux/sparc64.zig @@ -591,26 +591,28 @@ pub const O_PATH = 0x1000000; pub const O_TMPFILE = 0x2010000; pub const O_NDELAY = O_NONBLOCK | 0x4; -pub const F_DUPFD = 0; -pub const F_GETFD = 1; -pub const F_SETFD = 2; -pub const F_GETFL = 3; -pub const F_SETFL = 4; - -pub const F_SETOWN = 5; -pub const F_GETOWN = 6; -pub const F_GETLK = 7; -pub const F_SETLK = 8; -pub const F_SETLKW = 9; - -pub const F_RDLCK = 1; -pub const F_WRLCK = 2; -pub const F_UNLCK = 3; - -pub const F_SETOWN_EX = 15; -pub const F_GETOWN_EX = 16; - -pub const F_GETOWNER_UIDS = 17; +pub const F = struct { + pub const DUPFD = 0; + pub const GETFD = 1; + pub const SETFD = 2; + pub const GETFL = 3; + pub const SETFL = 4; + + pub const SETOWN = 5; + pub const GETOWN = 6; + pub const GETLK = 7; + pub const SETLK = 8; + pub const SETLKW = 9; + + pub const RDLCK = 1; + pub const WRLCK = 2; + pub const UNLCK = 3; + + pub const SETOWN_EX = 15; + pub const GETOWN_EX = 16; + + pub const GETOWNER_UIDS = 17; +}; pub const LOCK = struct { pub const SH = 1; diff --git a/lib/std/os/linux/thumb.zig b/lib/std/os/linux/thumb.zig index 3d38ca85b9..6ac51afb78 100644 --- a/lib/std/os/linux/thumb.zig +++ b/lib/std/os/linux/thumb.zig @@ -3,6 +3,9 @@ //! reserved for the frame pointer. //! Save and restore r7 around the syscall without touching the stack pointer not //! to break the frame chain. +const std = @import("../../std.zig"); +const linux = std.os.linux; +const SYS = linux.SYS; pub fn syscall0(number: SYS) usize { @setRuntimeSafety(false); diff --git a/lib/std/os/wasi.zig b/lib/std/os/wasi.zig index 635d4e390f..07f56a1913 100644 --- a/lib/std/os/wasi.zig +++ b/lib/std/os/wasi.zig @@ -149,8 +149,10 @@ pub const Stat = struct { pub const IOV_MAX = 1024; -pub const AT_REMOVEDIR: u32 = 0x4; -pub const AT_FDCWD: fd_t = -2; +pub const AT = struct { + pub const REMOVEDIR: u32 = 0x4; + pub const FDCWD: fd_t = -2; +}; // As defined in the wasi_snapshot_preview1 spec file: // https://github.com/WebAssembly/WASI/blob/master/phases/snapshot/witx/typenames.witx @@ -293,11 +295,13 @@ pub const exitcode_t = u32; pub const fd_t = u32; pub const fdflags_t = u16; -pub const FDFLAG_APPEND: fdflags_t = 0x0001; -pub const FDFLAG_DSYNC: fdflags_t = 0x0002; -pub const FDFLAG_NONBLOCK: fdflags_t = 0x0004; -pub const FDFLAG_RSYNC: fdflags_t = 0x0008; -pub const FDFLAG_SYNC: fdflags_t = 0x0010; +pub const FDFLAG = struct { + pub const APPEND: fdflags_t = 0x0001; + pub const DSYNC: fdflags_t = 0x0002; + pub const NONBLOCK: fdflags_t = 0x0004; + pub const RSYNC: fdflags_t = 0x0008; + pub const SYNC: fdflags_t = 0x0010; +}; pub const fdstat_t = extern struct { fs_filetype: filetype_t, @@ -333,15 +337,17 @@ pub const filestat_t = extern struct { } }; -pub const filetype_t = u8; -pub const FILETYPE_UNKNOWN: filetype_t = 0; -pub const FILETYPE_BLOCK_DEVICE: filetype_t = 1; -pub const FILETYPE_CHARACTER_DEVICE: filetype_t = 2; -pub const FILETYPE_DIRECTORY: filetype_t = 3; -pub const FILETYPE_REGULAR_FILE: filetype_t = 4; -pub const FILETYPE_SOCKET_DGRAM: filetype_t = 5; -pub const FILETYPE_SOCKET_STREAM: filetype_t = 6; -pub const FILETYPE_SYMBOLIC_LINK: filetype_t = 7; +pub const filetype_t = enum(u8) { + UNKNOWN, + BLOCK_DEVICE, + CHARACTER_DEVICE, + DIRECTORY, + REGULAR_FILE, + SOCKET_DGRAM, + SOCKET_STREAM, + SYMBOLIC_LINK, + _, +}; pub const fstflags_t = u16; pub const FILESTAT_SET_ATIM: fstflags_t = 0x0001; @@ -392,64 +398,66 @@ pub const SOCK = struct { }; pub const rights_t = u64; -pub const RIGHT_FD_DATASYNC: rights_t = 0x0000000000000001; -pub const RIGHT_FD_READ: rights_t = 0x0000000000000002; -pub const RIGHT_FD_SEEK: rights_t = 0x0000000000000004; -pub const RIGHT_FD_FDSTAT_SET_FLAGS: rights_t = 0x0000000000000008; -pub const RIGHT_FD_SYNC: rights_t = 0x0000000000000010; -pub const RIGHT_FD_TELL: rights_t = 0x0000000000000020; -pub const RIGHT_FD_WRITE: rights_t = 0x0000000000000040; -pub const RIGHT_FD_ADVISE: rights_t = 0x0000000000000080; -pub const RIGHT_FD_ALLOCATE: rights_t = 0x0000000000000100; -pub const RIGHT_PATH_CREATE_DIRECTORY: rights_t = 0x0000000000000200; -pub const RIGHT_PATH_CREATE_FILE: rights_t = 0x0000000000000400; -pub const RIGHT_PATH_LINK_SOURCE: rights_t = 0x0000000000000800; -pub const RIGHT_PATH_LINK_TARGET: rights_t = 0x0000000000001000; -pub const RIGHT_PATH_OPEN: rights_t = 0x0000000000002000; -pub const RIGHT_FD_READDIR: rights_t = 0x0000000000004000; -pub const RIGHT_PATH_READLINK: rights_t = 0x0000000000008000; -pub const RIGHT_PATH_RENAME_SOURCE: rights_t = 0x0000000000010000; -pub const RIGHT_PATH_RENAME_TARGET: rights_t = 0x0000000000020000; -pub const RIGHT_PATH_FILESTAT_GET: rights_t = 0x0000000000040000; -pub const RIGHT_PATH_FILESTAT_SET_SIZE: rights_t = 0x0000000000080000; -pub const RIGHT_PATH_FILESTAT_SET_TIMES: rights_t = 0x0000000000100000; -pub const RIGHT_FD_FILESTAT_GET: rights_t = 0x0000000000200000; -pub const RIGHT_FD_FILESTAT_SET_SIZE: rights_t = 0x0000000000400000; -pub const RIGHT_FD_FILESTAT_SET_TIMES: rights_t = 0x0000000000800000; -pub const RIGHT_PATH_SYMLINK: rights_t = 0x0000000001000000; -pub const RIGHT_PATH_REMOVE_DIRECTORY: rights_t = 0x0000000002000000; -pub const RIGHT_PATH_UNLINK_FILE: rights_t = 0x0000000004000000; -pub const RIGHT_POLL_FD_READWRITE: rights_t = 0x0000000008000000; -pub const RIGHT_SOCK_SHUTDOWN: rights_t = 0x0000000010000000; -pub const RIGHT_ALL: rights_t = RIGHT_FD_DATASYNC | - RIGHT_FD_READ | - RIGHT_FD_SEEK | - RIGHT_FD_FDSTAT_SET_FLAGS | - RIGHT_FD_SYNC | - RIGHT_FD_TELL | - RIGHT_FD_WRITE | - RIGHT_FD_ADVISE | - RIGHT_FD_ALLOCATE | - RIGHT_PATH_CREATE_DIRECTORY | - RIGHT_PATH_CREATE_FILE | - RIGHT_PATH_LINK_SOURCE | - RIGHT_PATH_LINK_TARGET | - RIGHT_PATH_OPEN | - RIGHT_FD_READDIR | - RIGHT_PATH_READLINK | - RIGHT_PATH_RENAME_SOURCE | - RIGHT_PATH_RENAME_TARGET | - RIGHT_PATH_FILESTAT_GET | - RIGHT_PATH_FILESTAT_SET_SIZE | - RIGHT_PATH_FILESTAT_SET_TIMES | - RIGHT_FD_FILESTAT_GET | - RIGHT_FD_FILESTAT_SET_SIZE | - RIGHT_FD_FILESTAT_SET_TIMES | - RIGHT_PATH_SYMLINK | - RIGHT_PATH_REMOVE_DIRECTORY | - RIGHT_PATH_UNLINK_FILE | - RIGHT_POLL_FD_READWRITE | - RIGHT_SOCK_SHUTDOWN; +pub const RIGHT = struct { + pub const FD_DATASYNC: rights_t = 0x0000000000000001; + pub const FD_READ: rights_t = 0x0000000000000002; + pub const FD_SEEK: rights_t = 0x0000000000000004; + pub const FD_FDSTAT_SET_FLAGS: rights_t = 0x0000000000000008; + pub const FD_SYNC: rights_t = 0x0000000000000010; + pub const FD_TELL: rights_t = 0x0000000000000020; + pub const FD_WRITE: rights_t = 0x0000000000000040; + pub const FD_ADVISE: rights_t = 0x0000000000000080; + pub const FD_ALLOCATE: rights_t = 0x0000000000000100; + pub const PATH_CREATE_DIRECTORY: rights_t = 0x0000000000000200; + pub const PATH_CREATE_FILE: rights_t = 0x0000000000000400; + pub const PATH_LINK_SOURCE: rights_t = 0x0000000000000800; + pub const PATH_LINK_TARGET: rights_t = 0x0000000000001000; + pub const PATH_OPEN: rights_t = 0x0000000000002000; + pub const FD_READDIR: rights_t = 0x0000000000004000; + pub const PATH_READLINK: rights_t = 0x0000000000008000; + pub const PATH_RENAME_SOURCE: rights_t = 0x0000000000010000; + pub const PATH_RENAME_TARGET: rights_t = 0x0000000000020000; + pub const PATH_FILESTAT_GET: rights_t = 0x0000000000040000; + pub const PATH_FILESTAT_SET_SIZE: rights_t = 0x0000000000080000; + pub const PATH_FILESTAT_SET_TIMES: rights_t = 0x0000000000100000; + pub const FD_FILESTAT_GET: rights_t = 0x0000000000200000; + pub const FD_FILESTAT_SET_SIZE: rights_t = 0x0000000000400000; + pub const FD_FILESTAT_SET_TIMES: rights_t = 0x0000000000800000; + pub const PATH_SYMLINK: rights_t = 0x0000000001000000; + pub const PATH_REMOVE_DIRECTORY: rights_t = 0x0000000002000000; + pub const PATH_UNLINK_FILE: rights_t = 0x0000000004000000; + pub const POLL_FD_READWRITE: rights_t = 0x0000000008000000; + pub const SOCK_SHUTDOWN: rights_t = 0x0000000010000000; + pub const ALL: rights_t = FD_DATASYNC | + FD_READ | + FD_SEEK | + FD_FDSTAT_SET_FLAGS | + FD_SYNC | + FD_TELL | + FD_WRITE | + FD_ADVISE | + FD_ALLOCATE | + PATH_CREATE_DIRECTORY | + PATH_CREATE_FILE | + PATH_LINK_SOURCE | + PATH_LINK_TARGET | + PATH_OPEN | + FD_READDIR | + PATH_READLINK | + PATH_RENAME_SOURCE | + PATH_RENAME_TARGET | + PATH_FILESTAT_GET | + PATH_FILESTAT_SET_SIZE | + PATH_FILESTAT_SET_TIMES | + FD_FILESTAT_GET | + FD_FILESTAT_SET_SIZE | + FD_FILESTAT_SET_TIMES | + PATH_SYMLINK | + PATH_REMOVE_DIRECTORY | + PATH_UNLINK_FILE | + POLL_FD_READWRITE | + SOCK_SHUTDOWN; +}; pub const sdflags_t = u8; pub const SHUT_RD: sdflags_t = 0x01; @@ -524,25 +532,20 @@ pub const timestamp_t = u64; pub const userdata_t = u64; -pub const whence_t = u8; -pub const WHENCE_SET: whence_t = 0; -pub const WHENCE_CUR: whence_t = 1; -pub const WHENCE_END: whence_t = 2; - -pub const S_IEXEC = S_IXUSR; -pub const S_IFBLK = 0x6000; -pub const S_IFCHR = 0x2000; -pub const S_IFDIR = 0x4000; -pub const S_IFIFO = 0xc000; -pub const S_IFLNK = 0xa000; -pub const S_IFMT = S_IFBLK | S_IFCHR | S_IFDIR | S_IFIFO | S_IFLNK | S_IFREG | S_IFSOCK; -pub const S_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 S_IFSOCK = 0x1; - -pub const SEEK_SET = WHENCE_SET; -pub const SEEK_CUR = WHENCE_CUR; -pub const SEEK_END = WHENCE_END; +pub const whence_t = enum(u8) { SET, CUR, END }; + +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 LOCK = struct { pub const SH = 0x1; diff --git a/lib/std/os/windows.zig b/lib/std/os/windows.zig index cf77b2b156..9fe4329ccc 100644 --- a/lib/std/os/windows.zig +++ b/lib/std/os/windows.zig @@ -2971,7 +2971,7 @@ pub const EXCEPTION_RECORD = extern struct { ExceptionInformation: [15]usize, }; -const arch_bits = switch (native_arch) { +pub usingnamespace switch (native_arch) { .i386 => struct { pub const FLOATING_SAVE_AREA = extern struct { ControlWord: DWORD, @@ -3037,8 +3037,8 @@ const arch_bits = switch (native_arch) { Reserved3: WORD, MxCsr: DWORD, MxCsr_Mask: DWORD, - FloatRegisters: [8]arch_bits.M128A, - XmmRegisters: [16]arch_bits.M128A, + FloatRegisters: [8]M128A, + XmmRegisters: [16]M128A, Reserved4: [96]BYTE, }; @@ -3082,8 +3082,8 @@ const arch_bits = switch (native_arch) { R15: DWORD64, Rip: DWORD64, DUMMYUNIONNAME: extern union { - FltSave: arch_bits.XMM_SAVE_AREA32, - FloatSave: arch_bits.XMM_SAVE_AREA32, + FltSave: XMM_SAVE_AREA32, + FloatSave: XMM_SAVE_AREA32, DUMMYSTRUCTNAME: extern struct { Header: [2]M128A, Legacy: [8]M128A, @@ -3189,15 +3189,10 @@ const arch_bits = switch (native_arch) { }, else => struct {}, }; -pub const M128A = arch_bits.M128A; -pub const XMM_SAVE_AREA32 = arch_bits.XMM_SAVE_AREA32; -pub const CONTEXT = arch_bits.CONTEXT; -pub const FLOATING_SAVE_AREA = arch_bits.FLOATING_SAVE_AREA; -pub const NEON128 = arch_bits.NEON128; pub const EXCEPTION_POINTERS = extern struct { ExceptionRecord: *EXCEPTION_RECORD, - ContextRecord: *CONTEXT, + ContextRecord: *@This().CONTEXT, }; pub const VECTORED_EXCEPTION_HANDLER = fn (ExceptionInfo: *EXCEPTION_POINTERS) callconv(WINAPI) c_long; diff --git a/lib/std/os/windows/gdi32.zig b/lib/std/os/windows/gdi32.zig index 5865fc8b1b..f7860c2ca1 100644 --- a/lib/std/os/windows/gdi32.zig +++ b/lib/std/os/windows/gdi32.zig @@ -5,6 +5,8 @@ const DWORD = windows.DWORD; const WINAPI = windows.WINAPI; const HDC = windows.HDC; const HGLRC = windows.HGLRC; +const WORD = windows.WORD; +const BYTE = windows.BYTE; pub const PIXELFORMATDESCRIPTOR = extern struct { nSize: WORD = @sizeOf(PIXELFORMATDESCRIPTOR), diff --git a/lib/std/os/windows/kernel32.zig b/lib/std/os/windows/kernel32.zig index 0a6145ed12..89a00ed892 100644 --- a/lib/std/os/windows/kernel32.zig +++ b/lib/std/os/windows/kernel32.zig @@ -36,6 +36,26 @@ const HLOCAL = windows.HLOCAL; const FILETIME = windows.FILETIME; const STARTUPINFOW = windows.STARTUPINFOW; const PROCESS_INFORMATION = windows.PROCESS_INFORMATION; +const OVERLAPPED_ENTRY = windows.OVERLAPPED_ENTRY; +const LPHEAP_SUMMARY = windows.LPHEAP_SUMMARY; +const ULONG_PTR = windows.ULONG_PTR; +const FILE_NOTIFY_INFORMATION = windows.FILE_NOTIFY_INFORMATION; +const HANDLER_ROUTINE = windows.HANDLER_ROUTINE; +const ULONG = windows.ULONG; +const PVOID = windows.PVOID; +const LPSTR = windows.LPSTR; +const PENUM_PAGE_FILE_CALLBACKA = windows.PENUM_PAGE_FILE_CALLBACKA; +const PENUM_PAGE_FILE_CALLBACKW = windows.PENUM_PAGE_FILE_CALLBACKW; +const INIT_ONCE = windows.INIT_ONCE; +const CRITICAL_SECTION = windows.CRITICAL_SECTION; +const WIN32_FIND_DATAW = windows.WIN32_FIND_DATAW; +const CHAR = windows.CHAR; +const BY_HANDLE_FILE_INFORMATION = windows.BY_HANDLE_FILE_INFORMATION; +const SYSTEM_INFO = windows.SYSTEM_INFO; +const LPOVERLAPPED_COMPLETION_ROUTINE = windows.LPOVERLAPPED_COMPLETION_ROUTINE; +const UCHAR = windows.UCHAR; +const FARPROC = windows.FARPROC; +const INIT_ONCE_FN = windows.INIT_ONCE_FN; pub extern "kernel32" fn AddVectoredExceptionHandler(First: c_ulong, Handler: ?VECTORED_EXCEPTION_HANDLER) callconv(WINAPI) ?*c_void; pub extern "kernel32" fn RemoveVectoredExceptionHandler(Handle: HANDLE) callconv(WINAPI) c_ulong; diff --git a/lib/std/os/windows/ntdll.zig b/lib/std/os/windows/ntdll.zig index 8da8a36249..228cf09ead 100644 --- a/lib/std/os/windows/ntdll.zig +++ b/lib/std/os/windows/ntdll.zig @@ -21,6 +21,7 @@ const UNICODE_STRING = windows.UNICODE_STRING; const RTL_OSVERSIONINFOW = windows.RTL_OSVERSIONINFOW; const FILE_BASIC_INFORMATION = windows.FILE_BASIC_INFORMATION; const SIZE_T = windows.SIZE_T; +const CURDIR = windows.CURDIR; pub extern "NtDll" fn RtlGetVersion( lpVersionInformation: *RTL_OSVERSIONINFOW, diff --git a/lib/std/os/windows/psapi.zig b/lib/std/os/windows/psapi.zig index 513b802b0c..0ef7429232 100644 --- a/lib/std/os/windows/psapi.zig +++ b/lib/std/os/windows/psapi.zig @@ -2,6 +2,49 @@ const std = @import("../../std.zig"); const windows = std.os.windows; const WINAPI = windows.WINAPI; const DWORD = windows.DWORD; +const HANDLE = windows.HANDLE; +const PENUM_PAGE_FILE_CALLBACKW = windows.PENUM_PAGE_FILE_CALLBACKW; +const HMODULE = windows.HMODULE; +const BOOL = windows.BOOL; +const BOOLEAN = windows.BOOLEAN; +const CONDITION_VARIABLE = windows.CONDITION_VARIABLE; +const CONSOLE_SCREEN_BUFFER_INFO = windows.CONSOLE_SCREEN_BUFFER_INFO; +const COORD = windows.COORD; +const FILE_INFO_BY_HANDLE_CLASS = windows.FILE_INFO_BY_HANDLE_CLASS; +const HRESULT = windows.HRESULT; +const LARGE_INTEGER = windows.LARGE_INTEGER; +const LPCWSTR = windows.LPCWSTR; +const LPTHREAD_START_ROUTINE = windows.LPTHREAD_START_ROUTINE; +const LPVOID = windows.LPVOID; +const LPWSTR = windows.LPWSTR; +const MODULEINFO = windows.MODULEINFO; +const OVERLAPPED = windows.OVERLAPPED; +const PERFORMANCE_INFORMATION = windows.PERFORMANCE_INFORMATION; +const PROCESS_MEMORY_COUNTERS = windows.PROCESS_MEMORY_COUNTERS; +const PSAPI_WS_WATCH_INFORMATION = windows.PSAPI_WS_WATCH_INFORMATION; +const PSAPI_WS_WATCH_INFORMATION_EX = windows.PSAPI_WS_WATCH_INFORMATION_EX; +const SECURITY_ATTRIBUTES = windows.SECURITY_ATTRIBUTES; +const SIZE_T = windows.SIZE_T; +const SRWLOCK = windows.SRWLOCK; +const UINT = windows.UINT; +const VECTORED_EXCEPTION_HANDLER = windows.VECTORED_EXCEPTION_HANDLER; +const WCHAR = windows.WCHAR; +const WORD = windows.WORD; +const Win32Error = windows.Win32Error; +const va_list = windows.va_list; +const HLOCAL = windows.HLOCAL; +const FILETIME = windows.FILETIME; +const STARTUPINFOW = windows.STARTUPINFOW; +const PROCESS_INFORMATION = windows.PROCESS_INFORMATION; +const OVERLAPPED_ENTRY = windows.OVERLAPPED_ENTRY; +const LPHEAP_SUMMARY = windows.LPHEAP_SUMMARY; +const ULONG_PTR = windows.ULONG_PTR; +const FILE_NOTIFY_INFORMATION = windows.FILE_NOTIFY_INFORMATION; +const HANDLER_ROUTINE = windows.HANDLER_ROUTINE; +const ULONG = windows.ULONG; +const PVOID = windows.PVOID; +const LPSTR = windows.LPSTR; +const PENUM_PAGE_FILE_CALLBACKA = windows.PENUM_PAGE_FILE_CALLBACKA; pub extern "psapi" fn EmptyWorkingSet(hProcess: HANDLE) callconv(WINAPI) BOOL; pub extern "psapi" fn EnumDeviceDrivers(lpImageBase: [*]LPVOID, cb: DWORD, lpcbNeeded: *DWORD) callconv(WINAPI) BOOL; diff --git a/lib/std/os/windows/user32.zig b/lib/std/os/windows/user32.zig index 077c1de8ee..5224b9f0cb 100644 --- a/lib/std/os/windows/user32.zig +++ b/lib/std/os/windows/user32.zig @@ -1,9 +1,31 @@ const std = @import("../../std.zig"); const assert = std.debug.assert; + const windows = std.os.windows; -const unexpectedError = windows.unexpectedError; const GetLastError = windows.kernel32.GetLastError; const SetLastError = windows.kernel32.SetLastError; +const unexpectedError = windows.unexpectedError; +const HWND = windows.HWND; +const UINT = windows.UINT; +const HDC = windows.HDC; +const LONG = windows.LONG; +const LONG_PTR = windows.LONG_PTR; +const WINAPI = windows.WINAPI; +const RECT = windows.RECT; +const DWORD = windows.DWORD; +const BOOL = windows.BOOL; +const TRUE = windows.TRUE; +const HMENU = windows.HMENU; +const HINSTANCE = windows.HINSTANCE; +const LPVOID = windows.LPVOID; +const ATOM = windows.ATOM; +const WPARAM = windows.WPARAM; +const LRESULT = windows.LRESULT; +const HICON = windows.HICON; +const LPARAM = windows.LPARAM; +const POINT = windows.POINT; +const HCURSOR = windows.HCURSOR; +const HBRUSH = windows.HBRUSH; fn selectSymbol(comptime function_static: anytype, function_dynamic: @TypeOf(function_static), comptime os: std.Target.Os.WindowsVersion) @TypeOf(function_static) { comptime { @@ -1316,7 +1338,7 @@ pub fn showWindow(hWnd: HWND, nCmdShow: i32) bool { pub extern "user32" fn UpdateWindow(hWnd: HWND) callconv(WINAPI) BOOL; pub fn updateWindow(hWnd: HWND) !void { - if (ShowWindow(hWnd, nCmdShow) == 0) { + if (UpdateWindow(hWnd) == 0) { switch (GetLastError()) { .INVALID_WINDOW_HANDLE => unreachable, .INVALID_PARAMETER => unreachable, diff --git a/lib/std/os/windows/ws2_32.zig b/lib/std/os/windows/ws2_32.zig index 1ee8732227..247ae20deb 100644 --- a/lib/std/os/windows/ws2_32.zig +++ b/lib/std/os/windows/ws2_32.zig @@ -8,6 +8,16 @@ const DWORD = windows.DWORD; const GUID = windows.GUID; const USHORT = windows.USHORT; const WCHAR = windows.WCHAR; +const BOOL = windows.BOOL; +const HANDLE = windows.HANDLE; +const timeval = windows.timeval; +const HWND = windows.HWND; +const INT = windows.INT; +const SHORT = windows.SHORT; +const CHAR = windows.CHAR; +const ULONG = windows.ULONG; +const LPARAM = windows.LPARAM; +const FARPROC = windows.FARPROC; pub const SOCKET = *opaque {}; pub const INVALID_SOCKET = @intToPtr(SOCKET, ~@as(usize, 0)); diff --git a/lib/std/time.zig b/lib/std/time.zig index 0690fc8a7d..eb398f1a4a 100644 --- a/lib/std/time.zig +++ b/lib/std/time.zig @@ -200,8 +200,6 @@ pub const Timer = struct { .frequency = {}, }; } - - return self; } /// Reads the timer value since start or the last reset in nanoseconds diff --git a/lib/std/zig.zig b/lib/std/zig.zig index 85ad4d2c81..9573bfcd48 100644 --- a/lib/std/zig.zig +++ b/lib/std/zig.zig @@ -157,7 +157,6 @@ pub fn binNameAlloc(allocator: *std.mem.Allocator, options: BinNameOptions) erro } }, } - return std.fmt.allocPrint(allocator, "{s}{s}{s}", .{ target.libPrefix(), root_name, suffix }); }, .Obj => return std.fmt.allocPrint(allocator, "{s}.o", .{root_name}), }, -- cgit v1.2.3 From cca57042df374305390b5b0000be75ba6d24fb63 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 30 Aug 2021 22:02:34 -0700 Subject: std: fix regressions from this branch Also move some usingnamespace test cases from compare_output to behavior. --- lib/std/c.zig | 36 +- lib/std/c/darwin.zig | 468 ++++++++++----------- lib/std/c/dragonfly.zig | 227 +++++----- lib/std/c/freebsd.zig | 228 +++++----- lib/std/c/haiku.zig | 288 +++++++------ lib/std/c/linux.zig | 6 +- lib/std/c/netbsd.zig | 383 ++++++++--------- lib/std/c/openbsd.zig | 440 ++++++++++--------- lib/std/c/wasi.zig | 5 + lib/std/debug.zig | 2 +- lib/std/event/loop.zig | 2 +- lib/std/fs.zig | 50 +-- lib/std/fs/file.zig | 16 +- lib/std/fs/watch.zig | 2 +- lib/std/os.zig | 17 +- lib/std/os/linux.zig | 82 ++-- lib/std/os/linux/arm-eabi.zig | 101 ++--- lib/std/os/linux/arm64.zig | 51 +-- lib/std/os/linux/i386.zig | 34 -- lib/std/os/linux/io_uring.zig | 14 +- lib/std/os/linux/mips.zig | 50 +-- lib/std/os/linux/powerpc.zig | 51 +-- lib/std/os/linux/powerpc64.zig | 50 +-- lib/std/os/linux/riscv64.zig | 43 +- lib/std/os/linux/sparc64.zig | 51 +-- lib/std/os/linux/x86_64.zig | 32 -- lib/std/os/test.zig | 4 +- lib/std/os/wasi.zig | 2 + lib/std/os/windows.zig | 2 +- lib/std/special/ssp.zig | 4 +- lib/std/start.zig | 2 +- lib/std/x/net/tcp.zig | 6 +- lib/std/x/os/net.zig | 5 +- test/behavior/usingnamespace/a.zig | 7 + test/behavior/usingnamespace/b.zig | 3 + test/behavior/usingnamespace/bar.zig | 8 + test/behavior/usingnamespace/foo.zig | 14 + .../behavior/usingnamespace/import_segregation.zig | 11 + test/behavior/usingnamespace/other.zig | 4 + test/behavior/usingnamespace_stage1.zig | 19 + test/cases.zig | 14 +- test/cli.zig | 7 - test/compare_output.zig | 105 ----- test/standalone/brace_expansion/main.zig | 2 +- 44 files changed, 1406 insertions(+), 1542 deletions(-) create mode 100644 test/behavior/usingnamespace/a.zig create mode 100644 test/behavior/usingnamespace/b.zig create mode 100644 test/behavior/usingnamespace/bar.zig create mode 100644 test/behavior/usingnamespace/foo.zig create mode 100644 test/behavior/usingnamespace/import_segregation.zig create mode 100644 test/behavior/usingnamespace/other.zig (limited to 'lib/std/debug.zig') diff --git a/lib/std/c.zig b/lib/std/c.zig index 9770af5f5f..5e88b1a7d3 100644 --- a/lib/std/c.zig +++ b/lib/std/c.zig @@ -58,41 +58,7 @@ pub usingnamespace switch (builtin.os.tag) { }; pub usingnamespace switch (builtin.os.tag) { - .netbsd => struct {}, - .macos, .ios, .watchos, .tvos => struct { - // XXX: close -> close$NOCANCEL - // XXX: getdirentries -> _getdirentries64 - pub extern "c" fn clock_getres(clk_id: c_int, tp: *c.timespec) c_int; - pub extern "c" fn clock_gettime(clk_id: c_int, tp: *c.timespec) c_int; - pub extern "c" fn getrusage(who: c_int, usage: *c.rusage) c_int; - pub extern "c" fn gettimeofday(noalias tv: ?*c.timeval, noalias tz: ?*c.timezone) c_int; - pub extern "c" fn nanosleep(rqtp: *const c.timespec, rmtp: ?*c.timespec) c_int; - pub extern "c" fn sched_yield() c_int; - pub extern "c" fn sigaction(sig: c_int, noalias act: ?*const c.Sigaction, noalias oact: ?*c.Sigaction) c_int; - pub extern "c" fn sigprocmask(how: c_int, noalias set: ?*const c.sigset_t, noalias oset: ?*c.sigset_t) c_int; - pub extern "c" fn socket(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int; - pub extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *c.Stat) c_int; - pub extern "c" fn sigfillset(set: ?*c.sigset_t) void; - pub extern "c" fn alarm(seconds: c_uint) c_uint; - pub extern "c" fn sigwait(set: ?*c.sigset_t, sig: ?*c_int) c_int; - }, - .windows => struct { - // 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: *c.timespec) c_int; - pub extern "c" fn clock_gettime(clk_id: c_int, tp: *c.timespec) c_int; - pub extern "c" fn fstat(fd: c.fd_t, buf: *c.Stat) c_int; - pub extern "c" fn getrusage(who: c_int, usage: *c.rusage) c_int; - pub extern "c" fn gettimeofday(noalias tv: ?*c.timeval, noalias tz: ?*c.timezone) c_int; - pub extern "c" fn nanosleep(rqtp: *const c.timespec, rmtp: ?*c.timespec) c_int; - pub extern "c" fn sched_yield() c_int; - pub extern "c" fn sigaction(sig: c_int, noalias act: ?*const c.Sigaction, noalias oact: ?*c.Sigaction) c_int; - pub extern "c" fn sigprocmask(how: c_int, noalias set: ?*const c.sigset_t, noalias oset: ?*c.sigset_t) c_int; - pub extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *c.Stat) c_int; - pub extern "c" fn sigfillset(set: ?*c.sigset_t) void; - pub extern "c" fn alarm(seconds: c_uint) c_uint; - pub extern "c" fn sigwait(set: ?*c.sigset_t, sig: ?*c_int) c_int; - }, + .netbsd, .macos, .ios, .watchos, .tvos, .windows => struct {}, else => struct { pub extern "c" fn clock_getres(clk_id: c_int, tp: *c.timespec) c_int; pub extern "c" fn clock_gettime(clk_id: c_int, tp: *c.timespec) c_int; diff --git a/lib/std/c/darwin.zig b/lib/std/c/darwin.zig index 75e0d32f49..a658138a96 100644 --- a/lib/std/c/darwin.zig +++ b/lib/std/c/darwin.zig @@ -395,10 +395,85 @@ pub const timespec = extern struct { pub const sigset_t = u32; pub const empty_sigset: sigset_t = 0; -pub const SIG_ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize)); -pub const SIG_DFL = @intToPtr(?Sigaction.sigaction_fn, 0); -pub const SIG_IGN = @intToPtr(?Sigaction.sigaction_fn, 1); -pub const SIG_HOLD = @intToPtr(?Sigaction.sigaction_fn, 5); +pub const SIG = struct { + pub const ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize)); + pub const DFL = @intToPtr(?Sigaction.sigaction_fn, 0); + pub const IGN = @intToPtr(?Sigaction.sigaction_fn, 1); + pub const HOLD = @intToPtr(?Sigaction.sigaction_fn, 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, @@ -507,17 +582,16 @@ pub const STDIN_FILENO = 0; pub const STDOUT_FILENO = 1; pub const STDERR_FILENO = 2; -/// [MC2] no permissions -pub const PROT_NONE = 0x00; - -/// [MC2] pages can be read -pub const PROT_READ = 0x01; - -/// [MC2] pages can be written -pub const PROT_WRITE = 0x02; - -/// [MC2] pages can be executed -pub const PROT_EXEC = 0x04; +pub const PROT = struct { + /// [MC2] no permissions + pub const NONE = 0x00; + /// [MC2] pages can be read + pub const READ = 0x01; + /// [MC2] pages can be written + pub const WRITE = 0x02; + /// [MC2] pages can be executed + pub const EXEC = 0x04; +}; pub const MAP = struct { /// allocated from memory, swap space @@ -551,10 +625,10 @@ pub const SA_ONSTACK = 0x0001; /// restart system on signal return pub const SA_RESTART = 0x0002; -/// reset to SIG_DFL when taking signal +/// reset to SIG.DFL when taking signal pub const SA_RESETHAND = 0x0004; -/// do not generate SIGCHLD on child stop +/// do not generate SIG.CHLD on child stop pub const SA_NOCLDSTOP = 0x0008; /// don't mask the signal we're delivering @@ -572,66 +646,53 @@ pub const SA_USERTRAMP = 0x0100; /// signal handler with SA_SIGINFO args with 64bit regs information pub const SA_64REGSET = 0x0200; -pub const O_PATH = 0x0000; - pub const F_OK = 0; pub const X_OK = 1; pub const W_OK = 2; pub const R_OK = 4; -/// open for reading only -pub const O_RDONLY = 0x0000; - -/// open for writing only -pub const O_WRONLY = 0x0001; - -/// open for reading and writing -pub const O_RDWR = 0x0002; - -/// do not block on open or for data to become available -pub const O_NONBLOCK = 0x0004; - -/// append on each write -pub const O_APPEND = 0x0008; - -/// create file if it does not exist -pub const O_CREAT = 0x0200; - -/// truncate size to 0 -pub const O_TRUNC = 0x0400; - -/// error if O_CREAT and the file exists -pub const O_EXCL = 0x0800; - -/// atomically obtain a shared lock -pub const O_SHLOCK = 0x0010; - -/// atomically obtain an exclusive lock -pub const O_EXLOCK = 0x0020; - -/// do not follow symlinks -pub const O_NOFOLLOW = 0x0100; - -/// allow open of symlinks -pub const O_SYMLINK = 0x200000; - -/// descriptor requested for event notifications only -pub const O_EVTONLY = 0x8000; - -/// mark as close-on-exec -pub const O_CLOEXEC = 0x1000000; - -pub const O_ACCMODE = 3; -pub const O_ALERT = 536870912; -pub const O_ASYNC = 64; -pub const O_DIRECTORY = 1048576; -pub const O_DP_GETRAWENCRYPTED = 1; -pub const O_DP_GETRAWUNENCRYPTED = 2; -pub const O_DSYNC = 4194304; -pub const O_FSYNC = O_SYNC; -pub const O_NOCTTY = 131072; -pub const O_POPUP = 2147483648; -pub const O_SYNC = 128; +pub const O = struct { + pub const PATH = 0x0000; + /// open for reading only + pub const RDONLY = 0x0000; + /// open for writing only + pub const WRONLY = 0x0001; + /// open for reading and writing + pub const RDWR = 0x0002; + /// do not block on open or for data to become available + pub const NONBLOCK = 0x0004; + /// append on each write + pub const APPEND = 0x0008; + /// create file if it does not exist + pub const CREAT = 0x0200; + /// truncate size to 0 + pub const TRUNC = 0x0400; + /// error if CREAT and the file exists + pub const EXCL = 0x0800; + /// atomically obtain a shared lock + pub const SHLOCK = 0x0010; + /// atomically obtain an exclusive lock + pub const EXLOCK = 0x0020; + /// do not follow symlinks + pub const NOFOLLOW = 0x0100; + /// allow open of symlinks + pub const SYMLINK = 0x200000; + /// descriptor requested for event notifications only + pub const EVTONLY = 0x8000; + /// mark as close-on-exec + pub const CLOEXEC = 0x1000000; + pub const ACCMODE = 3; + pub const ALERT = 536870912; + pub const ASYNC = 64; + pub const DIRECTORY = 1048576; + pub const DP_GETRAWENCRYPTED = 1; + pub const DP_GETRAWUNENCRYPTED = 2; + pub const DSYNC = 4194304; + pub const FSYNC = SYNC; + pub const NOCTTY = 131072; + pub const POPUP = 2147483648; + pub const SYNC = 128; +}; pub const SEEK_SET = 0x0; pub const SEEK_CUR = 0x1; @@ -647,114 +708,6 @@ pub const DT_LNK = 10; pub const DT_SOCK = 12; pub const DT_WHT = 14; -/// block specified signal set -pub const SIG_BLOCK = 1; - -/// unblock specified signal set -pub const SIG_UNBLOCK = 2; - -/// set specified signal set -pub const SIG_SETMASK = 3; - -/// hangup -pub const SIGHUP = 1; - -/// interrupt -pub const SIGINT = 2; - -/// quit -pub const SIGQUIT = 3; - -/// illegal instruction (not reset when caught) -pub const SIGILL = 4; - -/// trace trap (not reset when caught) -pub const SIGTRAP = 5; - -/// abort() -pub const SIGABRT = 6; - -/// pollable event ([XSR] generated, not supported) -pub const SIGPOLL = 7; - -/// compatibility -pub const SIGIOT = SIGABRT; - -/// EMT instruction -pub const SIGEMT = 7; - -/// floating point exception -pub const SIGFPE = 8; - -/// kill (cannot be caught or ignored) -pub const SIGKILL = 9; - -/// bus error -pub const SIGBUS = 10; - -/// segmentation violation -pub const SIGSEGV = 11; - -/// bad argument to system call -pub const SIGSYS = 12; - -/// write on a pipe with no one to read it -pub const SIGPIPE = 13; - -/// alarm clock -pub const SIGALRM = 14; - -/// software termination signal from kill -pub const SIGTERM = 15; - -/// urgent condition on IO channel -pub const SIGURG = 16; - -/// sendable stop signal not from tty -pub const SIGSTOP = 17; - -/// stop signal from tty -pub const SIGTSTP = 18; - -/// continue a stopped process -pub const SIGCONT = 19; - -/// to parent on child stop or exit -pub const SIGCHLD = 20; - -/// to readers pgrp upon background tty read -pub const SIGTTIN = 21; - -/// like TTIN for output if (tp->t_local<OSTOP) -pub const SIGTTOU = 22; - -/// input/output possible signal -pub const SIGIO = 23; - -/// exceeded CPU time limit -pub const SIGXCPU = 24; - -/// exceeded file size limit -pub const SIGXFSZ = 25; - -/// virtual time alarm -pub const SIGVTALRM = 26; - -/// profiling time alarm -pub const SIGPROF = 27; - -/// window size changes -pub const SIGWINCH = 28; - -/// information request -pub const SIGINFO = 29; - -/// user defined signal 1 -pub const SIGUSR1 = 30; - -/// user defined signal 2 -pub const SIGUSR2 = 31; - /// no flag value pub const KEVENT_FLAG_NONE = 0x000; @@ -1116,28 +1069,31 @@ pub const SO = struct { pub const REUSESHAREUID = 0x1025; }; -fn wstatus(x: u32) u32 { - return x & 0o177; -} -const wstopped = 0o177; -pub fn WEXITSTATUS(x: u32) u8 { - return @intCast(u8, x >> 8); -} -pub fn WTERMSIG(x: u32) u32 { - return wstatus(x); -} -pub fn WSTOPSIG(x: u32) u32 { - return x >> 8; -} -pub fn WIFEXITED(x: u32) bool { - return wstatus(x) == 0; -} -pub fn WIFSTOPPED(x: u32) bool { - return wstatus(x) == wstopped and WSTOPSIG(x) != 0x13; -} -pub fn WIFSIGNALED(x: u32) bool { - return wstatus(x) != wstopped and wstatus(x) != 0; -} +pub const W = struct { + pub fn EXITSTATUS(x: u32) u8 { + return @intCast(u8, 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; +}; pub const E = enum(u16) { /// No error occurred. @@ -1488,64 +1444,66 @@ pub const stack_t = extern struct { ss_flags: i32, }; -pub const S_IFMT = 0o170000; - -pub const S_IFIFO = 0o010000; -pub const S_IFCHR = 0o020000; -pub const S_IFDIR = 0o040000; -pub const S_IFBLK = 0o060000; -pub const S_IFREG = 0o100000; -pub const S_IFLNK = 0o120000; -pub const S_IFSOCK = 0o140000; -pub const S_IFWHT = 0o160000; - -pub const S_ISUID = 0o4000; -pub const S_ISGID = 0o2000; -pub const S_ISVTX = 0o1000; -pub const S_IRWXU = 0o700; -pub const S_IRUSR = 0o400; -pub const S_IWUSR = 0o200; -pub const S_IXUSR = 0o100; -pub const S_IRWXG = 0o070; -pub const S_IRGRP = 0o040; -pub const S_IWGRP = 0o020; -pub const S_IXGRP = 0o010; -pub const S_IRWXO = 0o007; -pub const S_IROTH = 0o004; -pub const S_IWOTH = 0o002; -pub const S_IXOTH = 0o001; - -pub fn S_ISFIFO(m: u32) bool { - return m & S_IFMT == S_IFIFO; -} +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 S_ISCHR(m: u32) bool { - return m & S_IFMT == S_IFCHR; -} + pub fn ISCHR(m: u32) bool { + return m & IFMT == IFCHR; + } -pub fn S_ISDIR(m: u32) bool { - return m & S_IFMT == S_IFDIR; -} + pub fn ISDIR(m: u32) bool { + return m & IFMT == IFDIR; + } -pub fn S_ISBLK(m: u32) bool { - return m & S_IFMT == S_IFBLK; -} + pub fn ISBLK(m: u32) bool { + return m & IFMT == IFBLK; + } -pub fn S_ISREG(m: u32) bool { - return m & S_IFMT == S_IFREG; -} + pub fn ISREG(m: u32) bool { + return m & IFMT == IFREG; + } -pub fn S_ISLNK(m: u32) bool { - return m & S_IFMT == S_IFLNK; -} + pub fn ISLNK(m: u32) bool { + return m & IFMT == IFLNK; + } -pub fn S_ISSOCK(m: u32) bool { - return m & S_IFMT == S_IFSOCK; -} + pub fn ISSOCK(m: u32) bool { + return m & IFMT == IFSOCK; + } -pub fn S_IWHT(m: u32) bool { - return m & S_IFMT == S_IFWHT; -} + pub fn IWHT(m: u32) bool { + return m & IFMT == IFWHT; + } +}; pub const HOST_NAME_MAX = 72; @@ -1981,7 +1939,9 @@ pub const winsize = extern struct { ws_ypixel: u16, }; -pub const TIOCGWINSZ = ior(0x40000000, 't', 104, @sizeOf(winsize)); +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 { diff --git a/lib/std/c/dragonfly.zig b/lib/std/c/dragonfly.zig index 427a08262d..921116b4f6 100644 --- a/lib/std/c/dragonfly.zig +++ b/lib/std/c/dragonfly.zig @@ -33,10 +33,6 @@ pub const pthread_attr_t = extern struct { // copied from freebsd pub const sem_t = ?*opaque {}; -pub fn S_ISCHR(m: u32) bool { - return m & S_IFMT == S_IFCHR; -} - // See: // - https://gitweb.dragonflybsd.org/dragonfly.git/blob/HEAD:/include/unistd.h // - https://gitweb.dragonflybsd.org/dragonfly.git/blob/HEAD:/sys/sys/types.h @@ -157,10 +153,12 @@ pub const STDIN_FILENO = 0; pub const STDOUT_FILENO = 1; pub const STDERR_FILENO = 2; -pub const PROT_NONE = 0; -pub const PROT_READ = 1; -pub const PROT_WRITE = 2; -pub const PROT_EXEC = 4; +pub const PROT = struct { + pub const NONE = 0; + pub const READ = 1; + pub const WRITE = 2; + pub const EXEC = 4; +}; pub const MAP = struct { pub const FILE = 0; @@ -321,32 +319,34 @@ 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 O_RDONLY = 0; -pub const O_NDELAY = O_NONBLOCK; -pub const O_WRONLY = 1; -pub const O_RDWR = 2; -pub const O_ACCMODE = 3; -pub const O_NONBLOCK = 4; -pub const O_APPEND = 8; -pub const O_SHLOCK = 16; -pub const O_EXLOCK = 32; -pub const O_ASYNC = 64; -pub const O_FSYNC = 128; -pub const O_SYNC = 128; -pub const O_NOFOLLOW = 256; -pub const O_CREAT = 512; -pub const O_TRUNC = 1024; -pub const O_EXCL = 2048; -pub const O_NOCTTY = 32768; -pub const O_DIRECT = 65536; -pub const O_CLOEXEC = 131072; -pub const O_FBLOCKING = 262144; -pub const O_FNONBLOCKING = 524288; -pub const O_FAPPEND = 1048576; -pub const O_FOFFSET = 2097152; -pub const O_FSYNCWRITE = 4194304; -pub const O_FASYNCWRITE = 8388608; -pub const O_DIRECTORY = 134217728; +pub const O = struct { + pub const RDONLY = 0; + pub const NDELAY = NONBLOCK; + pub const WRONLY = 1; + pub const RDWR = 2; + pub const ACCMODE = 3; + pub const NONBLOCK = 4; + pub const APPEND = 8; + pub const SHLOCK = 16; + pub const EXLOCK = 32; + pub const ASYNC = 64; + pub const FSYNC = 128; + pub const SYNC = 128; + pub const NOFOLLOW = 256; + pub const CREAT = 512; + pub const TRUNC = 1024; + pub const EXCL = 2048; + pub const NOCTTY = 32768; + pub const DIRECT = 65536; + pub const CLOEXEC = 131072; + pub const FBLOCKING = 262144; + pub const FNONBLOCKING = 524288; + pub const FAPPEND = 1048576; + pub const FOFFSET = 2097152; + pub const FSYNCWRITE = 4194304; + pub const FASYNCWRITE = 8388608; + pub const DIRECTORY = 134217728; +}; pub const SEEK_SET = 0; pub const SEEK_CUR = 1; @@ -540,81 +540,90 @@ pub const stack_t = extern struct { ss_flags: i32, }; -pub const S_IREAD = S_IRUSR; -pub const S_IEXEC = S_IXUSR; -pub const S_IWRITE = S_IWUSR; -pub const S_IXOTH = 1; -pub const S_IWOTH = 2; -pub const S_IROTH = 4; -pub const S_IRWXO = 7; -pub const S_IXGRP = 8; -pub const S_IWGRP = 16; -pub const S_IRGRP = 32; -pub const S_IRWXG = 56; -pub const S_IXUSR = 64; -pub const S_IWUSR = 128; -pub const S_IRUSR = 256; -pub const S_IRWXU = 448; -pub const S_ISTXT = 512; -pub const S_BLKSIZE = 512; -pub const S_ISVTX = 512; -pub const S_ISGID = 1024; -pub const S_ISUID = 2048; -pub const S_IFIFO = 4096; -pub const S_IFCHR = 8192; -pub const S_IFDIR = 16384; -pub const S_IFBLK = 24576; -pub const S_IFREG = 32768; -pub const S_IFDB = 36864; -pub const S_IFLNK = 40960; -pub const S_IFSOCK = 49152; -pub const S_IFWHT = 57344; -pub const S_IFMT = 61440; - -pub const SIG_DFL = @intToPtr(?Sigaction.sigaction_fn, 0); -pub const SIG_IGN = @intToPtr(?Sigaction.sigaction_fn, 1); -pub const SIG_ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize)); -pub const BADSIG = SIG_ERR; - -pub const SIG_BLOCK = 1; -pub const SIG_UNBLOCK = 2; -pub const SIG_SETMASK = 3; - -pub const SIGIOT = SIGABRT; -pub const SIGHUP = 1; -pub const SIGINT = 2; -pub const SIGQUIT = 3; -pub const SIGILL = 4; -pub const SIGTRAP = 5; -pub const SIGABRT = 6; -pub const SIGEMT = 7; -pub const SIGFPE = 8; -pub const SIGKILL = 9; -pub const SIGBUS = 10; -pub const SIGSEGV = 11; -pub const SIGSYS = 12; -pub const SIGPIPE = 13; -pub const SIGALRM = 14; -pub const SIGTERM = 15; -pub const SIGURG = 16; -pub const SIGSTOP = 17; -pub const SIGTSTP = 18; -pub const SIGCONT = 19; -pub const SIGCHLD = 20; -pub const SIGTTIN = 21; -pub const SIGTTOU = 22; -pub const SIGIO = 23; -pub const SIGXCPU = 24; -pub const SIGXFSZ = 25; -pub const SIGVTALRM = 26; -pub const SIGPROF = 27; -pub const SIGWINCH = 28; -pub const SIGINFO = 29; -pub const SIGUSR1 = 30; -pub const SIGUSR2 = 31; -pub const SIGTHR = 32; -pub const SIGCKPT = 33; -pub const SIGCKPTEXIT = 34; +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 = @intToPtr(?Sigaction.sigaction_fn, 0); + pub const IGN = @intToPtr(?Sigaction.sigaction_fn, 1); + pub const ERR = @intToPtr(?Sigaction.sigaction_fn, 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, diff --git a/lib/std/c/freebsd.zig b/lib/std/c/freebsd.zig index 5c9cf82b09..3e5fbf25fe 100644 --- a/lib/std/c/freebsd.zig +++ b/lib/std/c/freebsd.zig @@ -363,10 +363,12 @@ pub const STDIN_FILENO = 0; pub const STDOUT_FILENO = 1; pub const STDERR_FILENO = 2; -pub const PROT_NONE = 0; -pub const PROT_READ = 1; -pub const PROT_WRITE = 2; -pub const PROT_EXEC = 4; +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; @@ -504,33 +506,35 @@ 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 O_RDONLY = 0x0000; -pub const O_WRONLY = 0x0001; -pub const O_RDWR = 0x0002; -pub const O_ACCMODE = 0x0003; - -pub const O_SHLOCK = 0x0010; -pub const O_EXLOCK = 0x0020; - -pub const O_CREAT = 0x0200; -pub const O_EXCL = 0x0800; -pub const O_NOCTTY = 0x8000; -pub const O_TRUNC = 0x0400; -pub const O_APPEND = 0x0008; -pub const O_NONBLOCK = 0x0004; -pub const O_DSYNC = 0o10000; -pub const O_SYNC = 0x0080; -pub const O_RSYNC = 0o4010000; -pub const O_DIRECTORY = 0x20000; -pub const O_NOFOLLOW = 0x0100; -pub const O_CLOEXEC = 0x00100000; - -pub const O_ASYNC = 0x0040; -pub const O_DIRECT = 0x00010000; -pub const O_NOATIME = 0o1000000; -pub const O_PATH = 0o10000000; -pub const O_TMPFILE = 0o20200000; -pub const O_NDELAY = O_NONBLOCK; +pub const O = struct { + pub const RDONLY = 0x0000; + pub const WRONLY = 0x0001; + pub const RDWR = 0x0002; + pub const ACCMODE = 0x0003; + + pub const SHLOCK = 0x0010; + pub const EXLOCK = 0x0020; + + pub const CREAT = 0x0200; + pub const EXCL = 0x0800; + pub const NOCTTY = 0x8000; + pub const TRUNC = 0x0400; + pub const APPEND = 0x0008; + pub const NONBLOCK = 0x0004; + pub const DSYNC = 0o10000; + pub const SYNC = 0x0080; + pub const RSYNC = 0o4010000; + pub const DIRECTORY = 0x20000; + pub const NOFOLLOW = 0x0100; + pub const CLOEXEC = 0x00100000; + + pub const ASYNC = 0x0040; + pub const DIRECT = 0x00010000; + pub const NOATIME = 0o1000000; + pub const PATH = 0o10000000; + pub const TMPFILE = 0o20200000; + pub const NDELAY = NONBLOCK; +}; pub const F = struct { pub const DUPFD = 0; @@ -877,31 +881,33 @@ pub const NOTE_NSECONDS = 0x00000008; /// timeout is absolute pub const NOTE_ABSTIME = 0x00000010; -pub const TIOCEXCL = 0x2000740d; -pub const TIOCNXCL = 0x2000740e; -pub const TIOCSCTTY = 0x20007461; -pub const TIOCGPGRP = 0x40047477; -pub const TIOCSPGRP = 0x80047476; -pub const TIOCOUTQ = 0x40047473; -pub const TIOCSTI = 0x80017472; -pub const TIOCGWINSZ = 0x40087468; -pub const TIOCSWINSZ = 0x80087467; -pub const TIOCMGET = 0x4004746a; -pub const TIOCMBIS = 0x8004746c; -pub const TIOCMBIC = 0x8004746b; -pub const TIOCMSET = 0x8004746d; -pub const FIONREAD = 0x4004667f; -pub const TIOCCONS = 0x80047462; -pub const TIOCPKT = 0x80047470; -pub const FIONBIO = 0x8004667e; -pub const TIOCNOTTY = 0x20007471; -pub const TIOCSETD = 0x8004741b; -pub const TIOCGETD = 0x4004741a; -pub const TIOCSBRK = 0x2000747b; -pub const TIOCCBRK = 0x2000747a; -pub const TIOCGSID = 0x40047463; -pub const TIOCGPTN = 0x4004740f; -pub const TIOCSIG = 0x2004745f; +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 fn WEXITSTATUS(s: u32) u8 { return @intCast(u8, (s & 0xff00) >> 8); @@ -1166,69 +1172,71 @@ pub const SS_ONSTACK = 1; pub const SS_DISABLE = 4; pub const stack_t = extern struct { - ss_sp: [*]u8, - ss_size: isize, - ss_flags: i32, + sp: [*]u8, + size: isize, + flags: i32, }; -pub const S_IFMT = 0o170000; - -pub const S_IFIFO = 0o010000; -pub const S_IFCHR = 0o020000; -pub const S_IFDIR = 0o040000; -pub const S_IFBLK = 0o060000; -pub const S_IFREG = 0o100000; -pub const S_IFLNK = 0o120000; -pub const S_IFSOCK = 0o140000; -pub const S_IFWHT = 0o160000; - -pub const S_ISUID = 0o4000; -pub const S_ISGID = 0o2000; -pub const S_ISVTX = 0o1000; -pub const S_IRWXU = 0o700; -pub const S_IRUSR = 0o400; -pub const S_IWUSR = 0o200; -pub const S_IXUSR = 0o100; -pub const S_IRWXG = 0o070; -pub const S_IRGRP = 0o040; -pub const S_IWGRP = 0o020; -pub const S_IXGRP = 0o010; -pub const S_IRWXO = 0o007; -pub const S_IROTH = 0o004; -pub const S_IWOTH = 0o002; -pub const S_IXOTH = 0o001; - -pub fn S_ISFIFO(m: u32) bool { - return m & S_IFMT == S_IFIFO; -} +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 S_ISCHR(m: u32) bool { - return m & S_IFMT == S_IFCHR; -} + pub fn ISCHR(m: u32) bool { + return m & IFMT == IFCHR; + } -pub fn S_ISDIR(m: u32) bool { - return m & S_IFMT == S_IFDIR; -} + pub fn ISDIR(m: u32) bool { + return m & IFMT == IFDIR; + } -pub fn S_ISBLK(m: u32) bool { - return m & S_IFMT == S_IFBLK; -} + pub fn ISBLK(m: u32) bool { + return m & IFMT == IFBLK; + } -pub fn S_ISREG(m: u32) bool { - return m & S_IFMT == S_IFREG; -} + pub fn ISREG(m: u32) bool { + return m & IFMT == IFREG; + } -pub fn S_ISLNK(m: u32) bool { - return m & S_IFMT == S_IFLNK; -} + pub fn ISLNK(m: u32) bool { + return m & IFMT == IFLNK; + } -pub fn S_ISSOCK(m: u32) bool { - return m & S_IFMT == S_IFSOCK; -} + pub fn ISSOCK(m: u32) bool { + return m & IFMT == IFSOCK; + } -pub fn S_IWHT(m: u32) bool { - return m & S_IFMT == S_IFWHT; -} + pub fn IWHT(m: u32) bool { + return m & IFMT == IFWHT; + } +}; pub const HOST_NAME_MAX = 255; diff --git a/lib/std/c/haiku.zig b/lib/std/c/haiku.zig index b5aa325908..e759ab10a4 100644 --- a/lib/std/c/haiku.zig +++ b/lib/std/c/haiku.zig @@ -377,10 +377,12 @@ pub const STDIN_FILENO = 0; pub const STDOUT_FILENO = 1; pub const STDERR_FILENO = 2; -pub const PROT_NONE = 0; -pub const PROT_READ = 1; -pub const PROT_WRITE = 2; -pub const PROT_EXEC = 4; +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 MONOTONIC = 0; @@ -425,6 +427,10 @@ pub const SA_STACK = SA_ONSTACK; pub const SA_ONESHOT = SA_RESETHAND; pub const SIG = struct { + pub const ERR = @intToPtr(fn (i32) callconv(.C) void, maxInt(usize)); + pub const DFL = @intToPtr(fn (i32) callconv(.C) void, 0); + pub const IGN = @intToPtr(fn (i32) callconv(.C) void, 1); + pub const HUP = 1; pub const INT = 2; pub const QUIT = 3; @@ -489,33 +495,35 @@ 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 O_RDONLY = 0x0000; -pub const O_WRONLY = 0x0001; -pub const O_RDWR = 0x0002; -pub const O_ACCMODE = 0x0003; - -pub const O_SHLOCK = 0x0010; -pub const O_EXLOCK = 0x0020; - -pub const O_CREAT = 0x0200; -pub const O_EXCL = 0x0800; -pub const O_NOCTTY = 0x8000; -pub const O_TRUNC = 0x0400; -pub const O_APPEND = 0x0008; -pub const O_NONBLOCK = 0x0004; -pub const O_DSYNC = 0o10000; -pub const O_SYNC = 0x0080; -pub const O_RSYNC = 0o4010000; -pub const O_DIRECTORY = 0x20000; -pub const O_NOFOLLOW = 0x0100; -pub const O_CLOEXEC = 0x00100000; - -pub const O_ASYNC = 0x0040; -pub const O_DIRECT = 0x00010000; -pub const O_NOATIME = 0o1000000; -pub const O_PATH = 0o10000000; -pub const O_TMPFILE = 0o20200000; -pub const O_NDELAY = O_NONBLOCK; +pub const O = struct { + pub const RDONLY = 0x0000; + pub const WRONLY = 0x0001; + pub const RDWR = 0x0002; + pub const ACCMODE = 0x0003; + + pub const SHLOCK = 0x0010; + pub const EXLOCK = 0x0020; + + pub const CREAT = 0x0200; + pub const EXCL = 0x0800; + pub const NOCTTY = 0x8000; + pub const TRUNC = 0x0400; + pub const APPEND = 0x0008; + pub const NONBLOCK = 0x0004; + pub const DSYNC = 0o10000; + pub const SYNC = 0x0080; + pub const RSYNC = 0o4010000; + pub const DIRECTORY = 0x20000; + pub const NOFOLLOW = 0x0100; + pub const CLOEXEC = 0x00100000; + + pub const ASYNC = 0x0040; + pub const DIRECT = 0x00010000; + pub const NOATIME = 0o1000000; + pub const PATH = 0o10000000; + pub const TMPFILE = 0o20200000; + pub const NDELAY = NONBLOCK; +}; pub const F = struct { pub const DUPFD = 0; @@ -773,52 +781,56 @@ pub const EVFILT_SENDFILE = -12; pub const EVFILT_EMPTY = -13; -pub const TCGETA = 0x8000; -pub const TCSETA = 0x8001; -pub const TCSETAW = 0x8004; -pub const TCSETAF = 0x8003; -pub const TCSBRK = 08005; -pub const TCXONC = 0x8007; -pub const TCFLSH = 0x8006; - -pub const TIOCSCTTY = 0x8017; -pub const TIOCGPGRP = 0x8015; -pub const TIOCSPGRP = 0x8016; -pub const TIOCGWINSZ = 0x8012; -pub const TIOCSWINSZ = 0x8013; -pub const TIOCMGET = 0x8018; -pub const TIOCMBIS = 0x8022; -pub const TIOCMBIC = 0x8023; -pub const TIOCMSET = 0x8019; -pub const FIONREAD = 0xbe000001; -pub const FIONBIO = 0xbe000000; -pub const TIOCSBRK = 0x8020; -pub const TIOCCBRK = 0x8021; -pub const TIOCGSID = 0x8024; - -pub fn WEXITSTATUS(s: u32) u8 { - return @intCast(u8, s & 0xff); -} - -pub fn WTERMSIG(s: u32) u32 { - return (s >> 8) & 0xff; -} - -pub fn WSTOPSIG(s: u32) u32 { - return WEXITSTATUS(s); -} - -pub fn WIFEXITED(s: u32) bool { - return WTERMSIG(s) == 0; -} - -pub fn WIFSTOPPED(s: u32) bool { - return ((s >> 16) & 0xff) != 0; -} - -pub fn WIFSIGNALED(s: u32) bool { - return ((s >> 8) & 0xff) != 0; -} +pub const T = struct { + pub const CGETA = 0x8000; + pub const CSETA = 0x8001; + pub const CSETAW = 0x8004; + pub const CSETAF = 0x8003; + pub const CSBRK = 08005; + pub const CXONC = 0x8007; + pub const CFLSH = 0x8006; + + pub const IOCSCTTY = 0x8017; + pub const IOCGPGRP = 0x8015; + pub const IOCSPGRP = 0x8016; + pub const IOCGWINSZ = 0x8012; + pub const IOCSWINSZ = 0x8013; + pub const IOCMGET = 0x8018; + pub const IOCMBIS = 0x8022; + pub const IOCMBIC = 0x8023; + pub const IOCMSET = 0x8019; + pub const FIONREAD = 0xbe000001; + pub const FIONBIO = 0xbe000000; + pub const IOCSBRK = 0x8020; + pub const IOCCBRK = 0x8021; + pub const IOCGSID = 0x8024; +}; + +pub const W = struct { + pub fn EXITSTATUS(s: u32) u8 { + return @intCast(u8, s & 0xff); + } + + pub fn TERMSIG(s: u32) u32 { + return (s >> 8) & 0xff; + } + + 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 ((s >> 16) & 0xff) != 0; + } + + pub fn IFSIGNALED(s: u32) bool { + return ((s >> 8) & 0xff) != 0; + } +}; pub const winsize = extern struct { ws_row: u16, @@ -829,10 +841,6 @@ pub const winsize = extern struct { const NSIG = 32; -pub const SIG_ERR = @intToPtr(fn (i32) callconv(.C) void, maxInt(usize)); -pub const SIG_DFL = @intToPtr(fn (i32) callconv(.C) void, 0); -pub const SIG_IGN = @intToPtr(fn (i32) callconv(.C) void, 1); - /// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. pub const Sigaction = extern struct { /// signal handler @@ -992,64 +1000,66 @@ pub const stack_t = extern struct { ss_flags: i32, }; -pub const S_IFMT = 0o170000; - -pub const S_IFIFO = 0o010000; -pub const S_IFCHR = 0o020000; -pub const S_IFDIR = 0o040000; -pub const S_IFBLK = 0o060000; -pub const S_IFREG = 0o100000; -pub const S_IFLNK = 0o120000; -pub const S_IFSOCK = 0o140000; -pub const S_IFWHT = 0o160000; - -pub const S_ISUID = 0o4000; -pub const S_ISGID = 0o2000; -pub const S_ISVTX = 0o1000; -pub const S_IRWXU = 0o700; -pub const S_IRUSR = 0o400; -pub const S_IWUSR = 0o200; -pub const S_IXUSR = 0o100; -pub const S_IRWXG = 0o070; -pub const S_IRGRP = 0o040; -pub const S_IWGRP = 0o020; -pub const S_IXGRP = 0o010; -pub const S_IRWXO = 0o007; -pub const S_IROTH = 0o004; -pub const S_IWOTH = 0o002; -pub const S_IXOTH = 0o001; - -pub fn S_ISFIFO(m: u32) bool { - return m & S_IFMT == S_IFIFO; -} - -pub fn S_ISCHR(m: u32) bool { - return m & S_IFMT == S_IFCHR; -} - -pub fn S_ISDIR(m: u32) bool { - return m & S_IFMT == S_IFDIR; -} - -pub fn S_ISBLK(m: u32) bool { - return m & S_IFMT == S_IFBLK; -} - -pub fn S_ISREG(m: u32) bool { - return m & S_IFMT == S_IFREG; -} - -pub fn S_ISLNK(m: u32) bool { - return m & S_IFMT == S_IFLNK; -} - -pub fn S_ISSOCK(m: u32) bool { - return m & S_IFMT == S_IFSOCK; -} - -pub fn S_IWHT(m: u32) bool { - return m & S_IFMT == S_IFWHT; -} +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; diff --git a/lib/std/c/linux.zig b/lib/std/c/linux.zig index 00b88ecb02..5ffdc37689 100644 --- a/lib/std/c/linux.zig +++ b/lib/std/c/linux.zig @@ -25,7 +25,11 @@ pub const IOV_MAX = linux.IOV_MAX; pub const IPPROTO = linux.IPPROTO; pub const LOCK = linux.LOCK; pub const MADV = linux.MADV; -pub const MAP = linux.MAP; +pub const MAP = struct { + pub usingnamespace linux.MAP; + /// Only used by libc to communicate failure. + pub const FAILED = @intToPtr(*c_void, maxInt(usize)); +}; pub const MMAP2_UNIT = linux.MMAP2_UNIT; pub const NAME_MAX = linux.NAME_MAX; pub const O = linux.O; diff --git a/lib/std/c/netbsd.zig b/lib/std/c/netbsd.zig index c5bc633e01..cf066f3f47 100644 --- a/lib/std/c/netbsd.zig +++ b/lib/std/c/netbsd.zig @@ -534,10 +534,12 @@ pub const STDIN_FILENO = 0; pub const STDOUT_FILENO = 1; pub const STDERR_FILENO = 2; -pub const PROT_NONE = 0; -pub const PROT_READ = 1; -pub const PROT_WRITE = 2; -pub const PROT_EXEC = 4; +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; @@ -589,71 +591,52 @@ 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 -/// open for reading only -pub const O_RDONLY = 0x00000000; - -/// open for writing only -pub const O_WRONLY = 0x00000001; - -/// open for reading and writing -pub const O_RDWR = 0x00000002; - -/// mask for above modes -pub const O_ACCMODE = 0x00000003; - -/// no delay -pub const O_NONBLOCK = 0x00000004; - -/// set append mode -pub const O_APPEND = 0x00000008; - -/// open with shared file lock -pub const O_SHLOCK = 0x00000010; - -/// open with exclusive file lock -pub const O_EXLOCK = 0x00000020; - -/// signal pgrp when data ready -pub const O_ASYNC = 0x00000040; - -/// synchronous writes -pub const O_SYNC = 0x00000080; - -/// don't follow symlinks on the last -pub const O_NOFOLLOW = 0x00000100; - -/// create if nonexistent -pub const O_CREAT = 0x00000200; - -/// truncate to zero length -pub const O_TRUNC = 0x00000400; - -/// error if already exists -pub const O_EXCL = 0x00000800; - -/// don't assign controlling terminal -pub const O_NOCTTY = 0x00008000; - -/// write: I/O data completion -pub const O_DSYNC = 0x00010000; - -/// read: I/O completion as for write -pub const O_RSYNC = 0x00020000; - -/// use alternate i/o semantics -pub const O_ALT_IO = 0x00040000; - -/// direct I/O hint -pub const O_DIRECT = 0x00080000; - -/// fail if not a directory -pub const O_DIRECTORY = 0x00200000; - -/// set close on exec -pub const O_CLOEXEC = 0x00400000; - -/// skip search permission checks -pub const O_SEARCH = 0x00800000; +pub const O = struct { + /// open for reading only + pub const RDONLY = 0x00000000; + /// open for writing only + pub const WRONLY = 0x00000001; + /// open for reading and writing + pub const RDWR = 0x00000002; + /// mask for above modes + pub const ACCMODE = 0x00000003; + /// no delay + pub const NONBLOCK = 0x00000004; + /// set append mode + pub const APPEND = 0x00000008; + /// open with shared file lock + pub const SHLOCK = 0x00000010; + /// open with exclusive file lock + pub const EXLOCK = 0x00000020; + /// signal pgrp when data ready + pub const ASYNC = 0x00000040; + /// synchronous writes + pub const SYNC = 0x00000080; + /// don't follow symlinks on the last + pub const NOFOLLOW = 0x00000100; + /// create if nonexistent + pub const CREAT = 0x00000200; + /// truncate to zero length + pub const TRUNC = 0x00000400; + /// error if already exists + pub const EXCL = 0x00000800; + /// don't assign controlling terminal + pub const NOCTTY = 0x00008000; + /// write: I/O data completion + pub const DSYNC = 0x00010000; + /// read: I/O completion as for write + pub const RSYNC = 0x00020000; + /// use alternate i/o semantics + pub const ALT_IO = 0x00040000; + /// direct I/O hint + pub const DIRECT = 0x00080000; + /// fail if not a directory + pub const DIRECTORY = 0x00200000; + /// set close on exec + pub const CLOEXEC = 0x00400000; + /// skip search permission checks + pub const SEARCH = 0x00800000; +}; pub const F = struct { pub const DUPFD = 0; @@ -687,10 +670,6 @@ pub const SEEK_SET = 0; pub const SEEK_CUR = 1; pub const SEEK_END = 2; -pub const SIG_BLOCK = 1; -pub const SIG_UNBLOCK = 2; -pub const SIG_SETMASK = 3; - pub const DT_UNKNOWN = 0; pub const DT_FIFO = 1; pub const DT_CHR = 2; @@ -789,80 +768,82 @@ pub const NOTE_EXEC = 0x20000000; pub const NOTE_PDATAMASK = 0x000fffff; pub const NOTE_PCTRLMASK = 0xf0000000; -pub const TIOCCBRK = 0x2000747a; -pub const TIOCCDTR = 0x20007478; -pub const TIOCCONS = 0x80047462; -pub const TIOCDCDTIMESTAMP = 0x40107458; -pub const TIOCDRAIN = 0x2000745e; -pub const TIOCEXCL = 0x2000740d; -pub const TIOCEXT = 0x80047460; -pub const TIOCFLAG_CDTRCTS = 0x10; -pub const TIOCFLAG_CLOCAL = 0x2; -pub const TIOCFLAG_CRTSCTS = 0x4; -pub const TIOCFLAG_MDMBUF = 0x8; -pub const TIOCFLAG_SOFTCAR = 0x1; -pub const TIOCFLUSH = 0x80047410; -pub const TIOCGETA = 0x402c7413; -pub const TIOCGETD = 0x4004741a; -pub const TIOCGFLAGS = 0x4004745d; -pub const TIOCGLINED = 0x40207442; -pub const TIOCGPGRP = 0x40047477; -pub const TIOCGQSIZE = 0x40047481; -pub const TIOCGRANTPT = 0x20007447; -pub const TIOCGSID = 0x40047463; -pub const TIOCGSIZE = 0x40087468; -pub const TIOCGWINSZ = 0x40087468; -pub const TIOCMBIC = 0x8004746b; -pub const TIOCMBIS = 0x8004746c; -pub const TIOCMGET = 0x4004746a; -pub const TIOCMSET = 0x8004746d; -pub const TIOCM_CAR = 0x40; -pub const TIOCM_CD = 0x40; -pub const TIOCM_CTS = 0x20; -pub const TIOCM_DSR = 0x100; -pub const TIOCM_DTR = 0x2; -pub const TIOCM_LE = 0x1; -pub const TIOCM_RI = 0x80; -pub const TIOCM_RNG = 0x80; -pub const TIOCM_RTS = 0x4; -pub const TIOCM_SR = 0x10; -pub const TIOCM_ST = 0x8; -pub const TIOCNOTTY = 0x20007471; -pub const TIOCNXCL = 0x2000740e; -pub const TIOCOUTQ = 0x40047473; -pub const TIOCPKT = 0x80047470; -pub const TIOCPKT_DATA = 0x0; -pub const TIOCPKT_DOSTOP = 0x20; -pub const TIOCPKT_FLUSHREAD = 0x1; -pub const TIOCPKT_FLUSHWRITE = 0x2; -pub const TIOCPKT_IOCTL = 0x40; -pub const TIOCPKT_NOSTOP = 0x10; -pub const TIOCPKT_START = 0x8; -pub const TIOCPKT_STOP = 0x4; -pub const TIOCPTMGET = 0x40287446; -pub const TIOCPTSNAME = 0x40287448; -pub const TIOCRCVFRAME = 0x80087445; -pub const TIOCREMOTE = 0x80047469; -pub const TIOCSBRK = 0x2000747b; -pub const TIOCSCTTY = 0x20007461; -pub const TIOCSDTR = 0x20007479; -pub const TIOCSETA = 0x802c7414; -pub const TIOCSETAF = 0x802c7416; -pub const TIOCSETAW = 0x802c7415; -pub const TIOCSETD = 0x8004741b; -pub const TIOCSFLAGS = 0x8004745c; -pub const TIOCSIG = 0x2000745f; -pub const TIOCSLINED = 0x80207443; -pub const TIOCSPGRP = 0x80047476; -pub const TIOCSQSIZE = 0x80047480; -pub const TIOCSSIZE = 0x80087467; -pub const TIOCSTART = 0x2000746e; -pub const TIOCSTAT = 0x80047465; -pub const TIOCSTI = 0x80017472; -pub const TIOCSTOP = 0x2000746f; -pub const TIOCSWINSZ = 0x80087467; -pub const TIOCUCNTL = 0x80047466; -pub const TIOCXMTFRAME = 0x80087444; +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 fn WEXITSTATUS(s: u32) u8 { return @intCast(u8, (s >> 8) & 0xff); @@ -906,6 +887,10 @@ pub const SIG = struct { 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; @@ -1213,64 +1198,66 @@ pub const stack_t = extern struct { ss_flags: i32, }; -pub const S_IFMT = 0o170000; - -pub const S_IFIFO = 0o010000; -pub const S_IFCHR = 0o020000; -pub const S_IFDIR = 0o040000; -pub const S_IFBLK = 0o060000; -pub const S_IFREG = 0o100000; -pub const S_IFLNK = 0o120000; -pub const S_IFSOCK = 0o140000; -pub const S_IFWHT = 0o160000; - -pub const S_ISUID = 0o4000; -pub const S_ISGID = 0o2000; -pub const S_ISVTX = 0o1000; -pub const S_IRWXU = 0o700; -pub const S_IRUSR = 0o400; -pub const S_IWUSR = 0o200; -pub const S_IXUSR = 0o100; -pub const S_IRWXG = 0o070; -pub const S_IRGRP = 0o040; -pub const S_IWGRP = 0o020; -pub const S_IXGRP = 0o010; -pub const S_IRWXO = 0o007; -pub const S_IROTH = 0o004; -pub const S_IWOTH = 0o002; -pub const S_IXOTH = 0o001; - -pub fn S_ISFIFO(m: u32) bool { - return m & S_IFMT == S_IFIFO; -} +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 S_ISCHR(m: u32) bool { - return m & S_IFMT == S_IFCHR; -} + pub fn ISCHR(m: u32) bool { + return m & IFMT == IFCHR; + } -pub fn S_ISDIR(m: u32) bool { - return m & S_IFMT == S_IFDIR; -} + pub fn ISDIR(m: u32) bool { + return m & IFMT == IFDIR; + } -pub fn S_ISBLK(m: u32) bool { - return m & S_IFMT == S_IFBLK; -} + pub fn ISBLK(m: u32) bool { + return m & IFMT == IFBLK; + } -pub fn S_ISREG(m: u32) bool { - return m & S_IFMT == S_IFREG; -} + pub fn ISREG(m: u32) bool { + return m & IFMT == IFREG; + } -pub fn S_ISLNK(m: u32) bool { - return m & S_IFMT == S_IFLNK; -} + pub fn ISLNK(m: u32) bool { + return m & IFMT == IFLNK; + } -pub fn S_ISSOCK(m: u32) bool { - return m & S_IFMT == S_IFSOCK; -} + pub fn ISSOCK(m: u32) bool { + return m & IFMT == IFSOCK; + } -pub fn S_IWHT(m: u32) bool { - return m & S_IFMT == S_IFWHT; -} + pub fn IWHT(m: u32) bool { + return m & IFMT == IFWHT; + } +}; pub const AT = struct { /// Magic value that specify the use of the current working directory diff --git a/lib/std/c/openbsd.zig b/lib/std/c/openbsd.zig index cd7632df3c..83a32d52e3 100644 --- a/lib/std/c/openbsd.zig +++ b/lib/std/c/openbsd.zig @@ -330,10 +330,12 @@ pub const STDIN_FILENO = 0; pub const STDOUT_FILENO = 1; pub const STDERR_FILENO = 2; -pub const PROT_NONE = 0; -pub const PROT_READ = 1; -pub const PROT_WRITE = 2; -pub const PROT_EXEC = 4; +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; @@ -371,102 +373,52 @@ pub const SA_NODEFER = 0x0010; pub const SA_NOCLDWAIT = 0x0020; pub const SA_SIGINFO = 0x0040; -pub const SIGHUP = 1; -pub const SIGINT = 2; -pub const SIGQUIT = 3; -pub const SIGILL = 4; -pub const SIGTRAP = 5; -pub const SIGABRT = 6; -pub const SIGIOT = SIGABRT; -pub const SIGEMT = 7; -pub const SIGFPE = 8; -pub const SIGKILL = 9; -pub const SIGBUS = 10; -pub const SIGSEGV = 11; -pub const SIGSYS = 12; -pub const SIGPIPE = 13; -pub const SIGALRM = 14; -pub const SIGTERM = 15; -pub const SIGURG = 16; -pub const SIGSTOP = 17; -pub const SIGTSTP = 18; -pub const SIGCONT = 19; -pub const SIGCHLD = 20; -pub const SIGTTIN = 21; -pub const SIGTTOU = 22; -pub const SIGIO = 23; -pub const SIGXCPU = 24; -pub const SIGXFSZ = 25; -pub const SIGVTALRM = 26; -pub const SIGPROF = 27; -pub const SIGWINCH = 28; -pub const SIGINFO = 29; -pub const SIGUSR1 = 30; -pub const SIGUSR2 = 31; -pub const SIGPWR = 32; - // 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 -/// open for reading only -pub const O_RDONLY = 0x00000000; - -/// open for writing only -pub const O_WRONLY = 0x00000001; - -/// open for reading and writing -pub const O_RDWR = 0x00000002; - -/// mask for above modes -pub const O_ACCMODE = 0x00000003; - -/// no delay -pub const O_NONBLOCK = 0x00000004; - -/// set append mode -pub const O_APPEND = 0x00000008; - -/// open with shared file lock -pub const O_SHLOCK = 0x00000010; - -/// open with exclusive file lock -pub const O_EXLOCK = 0x00000020; - -/// signal pgrp when data ready -pub const O_ASYNC = 0x00000040; - -/// synchronous writes -pub const O_SYNC = 0x00000080; - -/// don't follow symlinks on the last -pub const O_NOFOLLOW = 0x00000100; - -/// create if nonexistent -pub const O_CREAT = 0x00000200; - -/// truncate to zero length -pub const O_TRUNC = 0x00000400; - -/// error if already exists -pub const O_EXCL = 0x00000800; - -/// don't assign controlling terminal -pub const O_NOCTTY = 0x00008000; - -/// write: I/O data completion -pub const O_DSYNC = O_SYNC; - -/// read: I/O completion as for write -pub const O_RSYNC = O_SYNC; - -/// fail if not a directory -pub const O_DIRECTORY = 0x20000; - -/// set close on exec -pub const O_CLOEXEC = 0x10000; +pub const O = struct { + /// open for reading only + pub const RDONLY = 0x00000000; + /// open for writing only + pub const WRONLY = 0x00000001; + /// open for reading and writing + pub const RDWR = 0x00000002; + /// mask for above modes + pub const ACCMODE = 0x00000003; + /// no delay + pub const NONBLOCK = 0x00000004; + /// set append mode + pub const APPEND = 0x00000008; + /// open with shared file lock + pub const SHLOCK = 0x00000010; + /// open with exclusive file lock + pub const EXLOCK = 0x00000020; + /// signal pgrp when data ready + pub const ASYNC = 0x00000040; + /// synchronous writes + pub const SYNC = 0x00000080; + /// don't follow symlinks on the last + pub const NOFOLLOW = 0x00000100; + /// create if nonexistent + pub const CREAT = 0x00000200; + /// truncate to zero length + pub const TRUNC = 0x00000400; + /// error if already exists + pub const EXCL = 0x00000800; + /// don't assign controlling terminal + pub const NOCTTY = 0x00008000; + /// write: I/O data completion + pub const DSYNC = SYNC; + /// read: I/O completion as for write + pub const RSYNC = SYNC; + /// fail if not a directory + pub const DIRECTORY = 0x20000; + /// set close on exec + pub const CLOEXEC = 0x10000; +}; pub const F = struct { pub const DUPFD = 0; @@ -500,10 +452,6 @@ pub const SEEK_SET = 0; pub const SEEK_CUR = 1; pub const SEEK_END = 2; -pub const SIG_BLOCK = 1; -pub const SIG_UNBLOCK = 2; -pub const SIG_SETMASK = 3; - pub const SOCK = struct { pub const STREAM = 1; pub const DGRAM = 2; @@ -643,80 +591,82 @@ pub const NOTE_CHILD = 0x00000004; // data/hint flags for EVFILT_DEVICE pub const NOTE_CHANGE = 0x00000001; -pub const TIOCCBRK = 0x2000747a; -pub const TIOCCDTR = 0x20007478; -pub const TIOCCONS = 0x80047462; -pub const TIOCDCDTIMESTAMP = 0x40107458; -pub const TIOCDRAIN = 0x2000745e; -pub const TIOCEXCL = 0x2000740d; -pub const TIOCEXT = 0x80047460; -pub const TIOCFLAG_CDTRCTS = 0x10; -pub const TIOCFLAG_CLOCAL = 0x2; -pub const TIOCFLAG_CRTSCTS = 0x4; -pub const TIOCFLAG_MDMBUF = 0x8; -pub const TIOCFLAG_SOFTCAR = 0x1; -pub const TIOCFLUSH = 0x80047410; -pub const TIOCGETA = 0x402c7413; -pub const TIOCGETD = 0x4004741a; -pub const TIOCGFLAGS = 0x4004745d; -pub const TIOCGLINED = 0x40207442; -pub const TIOCGPGRP = 0x40047477; -pub const TIOCGQSIZE = 0x40047481; -pub const TIOCGRANTPT = 0x20007447; -pub const TIOCGSID = 0x40047463; -pub const TIOCGSIZE = 0x40087468; -pub const TIOCGWINSZ = 0x40087468; -pub const TIOCMBIC = 0x8004746b; -pub const TIOCMBIS = 0x8004746c; -pub const TIOCMGET = 0x4004746a; -pub const TIOCMSET = 0x8004746d; -pub const TIOCM_CAR = 0x40; -pub const TIOCM_CD = 0x40; -pub const TIOCM_CTS = 0x20; -pub const TIOCM_DSR = 0x100; -pub const TIOCM_DTR = 0x2; -pub const TIOCM_LE = 0x1; -pub const TIOCM_RI = 0x80; -pub const TIOCM_RNG = 0x80; -pub const TIOCM_RTS = 0x4; -pub const TIOCM_SR = 0x10; -pub const TIOCM_ST = 0x8; -pub const TIOCNOTTY = 0x20007471; -pub const TIOCNXCL = 0x2000740e; -pub const TIOCOUTQ = 0x40047473; -pub const TIOCPKT = 0x80047470; -pub const TIOCPKT_DATA = 0x0; -pub const TIOCPKT_DOSTOP = 0x20; -pub const TIOCPKT_FLUSHREAD = 0x1; -pub const TIOCPKT_FLUSHWRITE = 0x2; -pub const TIOCPKT_IOCTL = 0x40; -pub const TIOCPKT_NOSTOP = 0x10; -pub const TIOCPKT_START = 0x8; -pub const TIOCPKT_STOP = 0x4; -pub const TIOCPTMGET = 0x40287446; -pub const TIOCPTSNAME = 0x40287448; -pub const TIOCRCVFRAME = 0x80087445; -pub const TIOCREMOTE = 0x80047469; -pub const TIOCSBRK = 0x2000747b; -pub const TIOCSCTTY = 0x20007461; -pub const TIOCSDTR = 0x20007479; -pub const TIOCSETA = 0x802c7414; -pub const TIOCSETAF = 0x802c7416; -pub const TIOCSETAW = 0x802c7415; -pub const TIOCSETD = 0x8004741b; -pub const TIOCSFLAGS = 0x8004745c; -pub const TIOCSIG = 0x2000745f; -pub const TIOCSLINED = 0x80207443; -pub const TIOCSPGRP = 0x80047476; -pub const TIOCSQSIZE = 0x80047480; -pub const TIOCSSIZE = 0x80087467; -pub const TIOCSTART = 0x2000746e; -pub const TIOCSTAT = 0x80047465; -pub const TIOCSTI = 0x80017472; -pub const TIOCSTOP = 0x2000746f; -pub const TIOCSWINSZ = 0x80087467; -pub const TIOCUCNTL = 0x80047466; -pub const TIOCXMTFRAME = 0x80087444; +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 fn WEXITSTATUS(s: u32) u8 { return @intCast(u8, (s >> 8) & 0xff); @@ -752,11 +702,51 @@ pub const winsize = extern struct { const NSIG = 33; -pub const SIG_DFL = @intToPtr(?Sigaction.sigaction_fn, 0); -pub const SIG_IGN = @intToPtr(?Sigaction.sigaction_fn, 1); -pub const SIG_ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize)); -pub const SIG_CATCH = @intToPtr(?Sigaction.sigaction_fn, 2); -pub const SIG_HOLD = @intToPtr(?Sigaction.sigaction_fn, 3); +pub const SIG = struct { + pub const DFL = @intToPtr(?Sigaction.sigaction_fn, 0); + pub const IGN = @intToPtr(?Sigaction.sigaction_fn, 1); + pub const ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize)); + pub const CATCH = @intToPtr(?Sigaction.sigaction_fn, 2); + pub const HOLD = @intToPtr(?Sigaction.sigaction_fn, 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 { @@ -1013,59 +1003,61 @@ pub const stack_t = extern struct { ss_flags: c_int, }; -pub const S_IFMT = 0o170000; - -pub const S_IFIFO = 0o010000; -pub const S_IFCHR = 0o020000; -pub const S_IFDIR = 0o040000; -pub const S_IFBLK = 0o060000; -pub const S_IFREG = 0o100000; -pub const S_IFLNK = 0o120000; -pub const S_IFSOCK = 0o140000; - -pub const S_ISUID = 0o4000; -pub const S_ISGID = 0o2000; -pub const S_ISVTX = 0o1000; -pub const S_IRWXU = 0o700; -pub const S_IRUSR = 0o400; -pub const S_IWUSR = 0o200; -pub const S_IXUSR = 0o100; -pub const S_IRWXG = 0o070; -pub const S_IRGRP = 0o040; -pub const S_IWGRP = 0o020; -pub const S_IXGRP = 0o010; -pub const S_IRWXO = 0o007; -pub const S_IROTH = 0o004; -pub const S_IWOTH = 0o002; -pub const S_IXOTH = 0o001; - -pub fn S_ISFIFO(m: u32) bool { - return m & S_IFMT == S_IFIFO; -} +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 S_ISCHR(m: u32) bool { - return m & S_IFMT == S_IFCHR; -} + pub fn ISCHR(m: u32) bool { + return m & IFMT == IFCHR; + } -pub fn S_ISDIR(m: u32) bool { - return m & S_IFMT == S_IFDIR; -} + pub fn ISDIR(m: u32) bool { + return m & IFMT == IFDIR; + } -pub fn S_ISBLK(m: u32) bool { - return m & S_IFMT == S_IFBLK; -} + pub fn ISBLK(m: u32) bool { + return m & IFMT == IFBLK; + } -pub fn S_ISREG(m: u32) bool { - return m & S_IFMT == S_IFREG; -} + pub fn ISREG(m: u32) bool { + return m & IFMT == IFREG; + } -pub fn S_ISLNK(m: u32) bool { - return m & S_IFMT == S_IFLNK; -} + pub fn ISLNK(m: u32) bool { + return m & IFMT == IFLNK; + } -pub fn S_ISSOCK(m: u32) bool { - return m & S_IFMT == S_IFSOCK; -} + pub fn ISSOCK(m: u32) bool { + return m & IFMT == IFSOCK; + } +}; pub const AT = struct { /// Magic value that specify the use of the current working directory diff --git a/lib/std/c/wasi.zig b/lib/std/c/wasi.zig index 95eafd7fad..497f1213c8 100644 --- a/lib/std/c/wasi.zig +++ b/lib/std/c/wasi.zig @@ -17,6 +17,11 @@ pub const ino_t = wasi.ino_t; pub const mode_t = wasi.mode_t; pub const time_t = wasi.time_t; pub const timespec = wasi.timespec; +pub const STDERR_FILENO = wasi.STDERR_FILENO; +pub const STDIN_FILENO = wasi.STDIN_FILENO; +pub const STDOUT_FILENO = wasi.STDOUT_FILENO; +pub const E = wasi.E; +pub const CLOCK = wasi.CLOCK; pub const Stat = extern struct { dev: i32, diff --git a/lib/std/debug.zig b/lib/std/debug.zig index 8402f42e6d..8517703566 100644 --- a/lib/std/debug.zig +++ b/lib/std/debug.zig @@ -1470,7 +1470,7 @@ fn getDebugInfoAllocator() *mem.Allocator { pub const have_segfault_handling_support = switch (native_os) { .linux, .netbsd => true, .windows => true, - .freebsd, .openbsd => @hasDecl(os, "ucontext_t"), + .freebsd, .openbsd => @hasDecl(os.system, "ucontext_t"), else => false, }; pub const enable_segfault_handler: bool = if (@hasDecl(root, "enable_segfault_handler")) diff --git a/lib/std/event/loop.zig b/lib/std/event/loop.zig index ef19728ec9..21211c9af0 100644 --- a/lib/std/event/loop.zig +++ b/lib/std/event/loop.zig @@ -904,7 +904,7 @@ pub const Loop = struct { addr_size: *os.socklen_t, /// The following values can be bitwise ORed in flags to obtain different behavior: /// * `SOCK.CLOEXEC` - Set the close-on-exec (`FD_CLOEXEC`) flag on the new file descriptor. See the - /// description of the `O_CLOEXEC` flag in `open` for reasons why this may be useful. + /// description of the `O.CLOEXEC` flag in `open` for reasons why this may be useful. flags: u32, ) os.AcceptError!os.socket_t { while (true) { diff --git a/lib/std/fs.zig b/lib/std/fs.zig index 1f063bb88a..5c795e658f 100644 --- a/lib/std/fs.zig +++ b/lib/std/fs.zig @@ -479,15 +479,15 @@ pub const Dir = struct { &stat_info, 0, ); - const statmode = stat_info.mode & os.S_IFMT; + const statmode = stat_info.mode & os.S.IFMT; const entry_kind = switch (statmode) { - os.S_IFDIR => Entry.Kind.Directory, - os.S_IFBLK => Entry.Kind.BlockDevice, - os.S_IFCHR => Entry.Kind.CharacterDevice, - os.S_IFLNK => Entry.Kind.SymLink, - os.S_IFREG => Entry.Kind.File, - os.S_IFIFO => Entry.Kind.NamedPipe, + os.S.IFDIR => Entry.Kind.Directory, + os.S.IFBLK => Entry.Kind.BlockDevice, + os.S.IFCHR => Entry.Kind.CharacterDevice, + os.S.IFLNK => Entry.Kind.SymLink, + os.S.IFREG => Entry.Kind.File, + os.S.IFIFO => Entry.Kind.NamedPipe, else => Entry.Kind.Unknown, }; @@ -678,12 +678,12 @@ pub const Dir = struct { } const entry_kind = switch (entry.d_type) { - w.FILETYPE_BLOCK_DEVICE => Entry.Kind.BlockDevice, - w.FILETYPE_CHARACTER_DEVICE => Entry.Kind.CharacterDevice, - w.FILETYPE_DIRECTORY => Entry.Kind.Directory, - w.FILETYPE_SYMBOLIC_LINK => Entry.Kind.SymLink, - w.FILETYPE_REGULAR_FILE => Entry.Kind.File, - w.FILETYPE_SOCKET_STREAM, wasi.FILETYPE_SOCKET_DGRAM => Entry.Kind.UnixDomainSocket, + .BLOCK_DEVICE => Entry.Kind.BlockDevice, + .CHARACTER_DEVICE => Entry.Kind.CharacterDevice, + .DIRECTORY => Entry.Kind.Directory, + .SYMBOLIC_LINK => Entry.Kind.SymLink, + .REGULAR_FILE => Entry.Kind.File, + .SOCKET_STREAM, .SOCKET_DGRAM => Entry.Kind.UnixDomainSocket, else => Entry.Kind.Unknown, }; return Entry{ @@ -909,11 +909,11 @@ pub const Dir = struct { } var os_flags: u32 = os.O.CLOEXEC; - // Use the O_ locking flags if the os supports them to acquire the lock + // Use the O locking flags if the os supports them to acquire the lock // atomically. const has_flock_open_flags = @hasDecl(os.O, "EXLOCK"); if (has_flock_open_flags) { - // Note that the O_NONBLOCK flag is removed after the openat() call + // Note that the O.NONBLOCK flag is removed after the openat() call // is successful. const nonblocking_lock_flag: u32 = if (flags.lock_nonblocking) os.O.NONBLOCK @@ -1071,10 +1071,10 @@ pub const Dir = struct { return self.createFileW(path_w.span(), flags); } - // Use the O_ locking flags if the os supports them to acquire the lock + // Use the O locking flags if the os supports them to acquire the lock // atomically. const has_flock_open_flags = @hasDecl(os.O, "EXLOCK"); - // Note that the O_NONBLOCK flag is removed after the openat() call + // Note that the O.NONBLOCK flag is removed after the openat() call // is successful. const nonblocking_lock_flag: u32 = if (has_flock_open_flags and flags.lock_nonblocking) os.O.NONBLOCK @@ -1427,9 +1427,9 @@ pub const Dir = struct { const result = os.openatWasi(self.fd, sub_path, symlink_flags, w.O.DIRECTORY, 0x0, base, inheriting); const fd = result catch |err| switch (err) { error.FileTooBig => unreachable, // can't happen for directories - error.IsDir => unreachable, // we're providing O_DIRECTORY - error.NoSpaceLeft => unreachable, // not providing O_CREAT - error.PathAlreadyExists => unreachable, // not providing O_CREAT + error.IsDir => unreachable, // we're providing O.DIRECTORY + error.NoSpaceLeft => unreachable, // not providing O.CREAT + error.PathAlreadyExists => unreachable, // not providing O.CREAT error.FileLocksNotSupported => unreachable, // locking folders is not supported error.WouldBlock => unreachable, // can't happen for directories else => |e| return e, @@ -1463,7 +1463,7 @@ pub const Dir = struct { return self.openDirAccessMaskW(sub_path_w, flags, args.no_follow); } - /// `flags` must contain `os.O_DIRECTORY`. + /// `flags` must contain `os.O.DIRECTORY`. fn openDirFlagsZ(self: Dir, sub_path_c: [*:0]const u8, flags: u32) OpenError!Dir { const result = if (need_async_thread) std.event.Loop.instance.?.openatZ(self.fd, sub_path_c, flags, 0) @@ -1471,9 +1471,9 @@ pub const Dir = struct { os.openatZ(self.fd, sub_path_c, flags, 0); const fd = result catch |err| switch (err) { error.FileTooBig => unreachable, // can't happen for directories - error.IsDir => unreachable, // we're providing O_DIRECTORY - error.NoSpaceLeft => unreachable, // not providing O_CREAT - error.PathAlreadyExists => unreachable, // not providing O_CREAT + error.IsDir => unreachable, // we're providing O.DIRECTORY + error.NoSpaceLeft => unreachable, // not providing O.CREAT + error.PathAlreadyExists => unreachable, // not providing O.CREAT error.FileLocksNotSupported => unreachable, // locking folders is not supported error.WouldBlock => unreachable, // can't happen for directories else => |e| return e, @@ -1559,7 +1559,7 @@ pub const Dir = struct { .macos, .ios, .freebsd, .netbsd, .dragonfly, .openbsd => { // Don't follow symlinks to match unlinkat (which acts on symlinks rather than follows them) const fstat = os.fstatatZ(self.fd, sub_path_c, os.AT.SYMLINK_NOFOLLOW) catch return e; - const is_dir = fstat.mode & os.S_IFMT == os.S_IFDIR; + const is_dir = fstat.mode & os.S.IFMT == os.S.IFDIR; return if (is_dir) error.IsDir else e; }, else => return e, diff --git a/lib/std/fs/file.zig b/lib/std/fs/file.zig index e37fa1d655..d08b743919 100644 --- a/lib/std/fs/file.zig +++ b/lib/std/fs/file.zig @@ -106,7 +106,7 @@ pub const File = struct { /// and `false` means `error.WouldBlock` is handled by the event loop. lock_nonblocking: bool = false, - /// Setting this to `.blocking` prevents `O_NONBLOCK` from being passed even + /// Setting this to `.blocking` prevents `O.NONBLOCK` from being passed even /// if `std.io.is_async`. It allows the use of `nosuspend` when calling functions /// related to opening the file, reading, writing, and locking. intended_io_mode: io.ModeOverride = io.default_mode, @@ -167,7 +167,7 @@ pub const File = struct { /// be created with. mode: Mode = default_mode, - /// Setting this to `.blocking` prevents `O_NONBLOCK` from being passed even + /// Setting this to `.blocking` prevents `O.NONBLOCK` from being passed even /// if `std.io.is_async`. It allows the use of `nosuspend` when calling functions /// related to opening the file, reading, writing, and locking. intended_io_mode: io.ModeOverride = io.default_mode, @@ -325,12 +325,12 @@ pub const File = struct { .size = @bitCast(u64, st.size), .mode = st.mode, .kind = if (builtin.os.tag == .wasi and !builtin.link_libc) switch (st.filetype) { - os.FILETYPE_BLOCK_DEVICE => Kind.BlockDevice, - os.FILETYPE_CHARACTER_DEVICE => Kind.CharacterDevice, - os.FILETYPE_DIRECTORY => Kind.Directory, - os.FILETYPE_SYMBOLIC_LINK => Kind.SymLink, - os.FILETYPE_REGULAR_FILE => Kind.File, - os.FILETYPE_SOCKET_STREAM, os.FILETYPE_SOCKET_DGRAM => Kind.UnixDomainSocket, + .BLOCK_DEVICE => Kind.BlockDevice, + .CHARACTER_DEVICE => Kind.CharacterDevice, + .DIRECTORY => Kind.Directory, + .SYMBOLIC_LINK => Kind.SymLink, + .REGULAR_FILE => Kind.File, + .SOCKET_STREAM, .SOCKET_DGRAM => Kind.UnixDomainSocket, else => Kind.Unknown, } else switch (st.mode & os.S.IFMT) { os.S.IFBLK => Kind.BlockDevice, diff --git a/lib/std/fs/watch.zig b/lib/std/fs/watch.zig index 7777793b29..117843bf95 100644 --- a/lib/std/fs/watch.zig +++ b/lib/std/fs/watch.zig @@ -250,7 +250,7 @@ pub fn Watch(comptime V: type) type { }; // @TODO Can I close this fd and get an error from bsdWaitKev? - const flags = if (comptime std.Target.current.isDarwin()) os.O_SYMLINK | os.O_EVTONLY else 0; + const flags = if (comptime std.Target.current.isDarwin()) os.O.SYMLINK | os.O.EVTONLY else 0; const fd = try os.open(realpath, flags, 0); gop.value_ptr.putter_frame = async self.kqPutEvents(fd, gop.key_ptr.*, gop.value_ptr.*); return null; diff --git a/lib/std/os.zig b/lib/std/os.zig index c688eedec8..1de4bac644 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -72,7 +72,6 @@ pub const E = system.E; pub const Elf_Symndx = system.Elf_Symndx; pub const F = system.F; pub const FD_CLOEXEC = system.FD_CLOEXEC; -pub const F_OK = system.F_OK; pub const Flock = system.Flock; pub const HOST_NAME_MAX = system.HOST_NAME_MAX; pub const IFNAMESIZE = system.IFNAMESIZE; @@ -96,7 +95,6 @@ pub const REG = system.REG; pub const RIGHT = system.RIGHT; pub const RLIM = system.RLIM; pub const RR = system.RR; -pub const R_OK = system.R_OK; pub const S = system.S; pub const SA = system.SA; pub const SC = system.SC; @@ -116,8 +114,6 @@ pub const Stat = system.Stat; pub const TCSA = system.TCSA; pub const VDSO = system.VDSO; pub const W = system.W; -pub const W_OK = system.W_OK; -pub const X_OK = system.X_OK; pub const addrinfo = system.addrinfo; pub const blkcnt_t = system.blkcnt_t; pub const blksize_t = system.blksize_t; @@ -165,6 +161,11 @@ pub const uid_t = system.uid_t; pub const user_desc = system.user_desc; pub const utsname = system.utsname; +pub const F_OK = system.F_OK; +pub const R_OK = system.R_OK; +pub const W_OK = system.W_OK; +pub const X_OK = system.X_OK; + pub const iovec = extern struct { iov_base: [*]u8, iov_len: usize, @@ -4237,7 +4238,7 @@ pub fn lseek_SET(fd: fd_t, offset: u64) SeekError!void { } if (builtin.os.tag == .wasi and !builtin.link_libc) { var new_offset: wasi.filesize_t = undefined; - switch (wasi.fd_seek(fd, @bitCast(wasi.filedelta_t, offset), wasi.WHENCE_SET, &new_offset)) { + switch (wasi.fd_seek(fd, @bitCast(wasi.filedelta_t, offset), .SET, &new_offset)) { .SUCCESS => return, .BADF => unreachable, // always a race condition .INVAL => return error.Unseekable, @@ -4285,7 +4286,7 @@ pub fn lseek_CUR(fd: fd_t, offset: i64) SeekError!void { } if (builtin.os.tag == .wasi and !builtin.link_libc) { var new_offset: wasi.filesize_t = undefined; - switch (wasi.fd_seek(fd, offset, wasi.WHENCE_CUR, &new_offset)) { + switch (wasi.fd_seek(fd, offset, .CUR, &new_offset)) { .SUCCESS => return, .BADF => unreachable, // always a race condition .INVAL => return error.Unseekable, @@ -4332,7 +4333,7 @@ pub fn lseek_END(fd: fd_t, offset: i64) SeekError!void { } if (builtin.os.tag == .wasi and !builtin.link_libc) { var new_offset: wasi.filesize_t = undefined; - switch (wasi.fd_seek(fd, offset, wasi.WHENCE_END, &new_offset)) { + switch (wasi.fd_seek(fd, offset, .END, &new_offset)) { .SUCCESS => return, .BADF => unreachable, // always a race condition .INVAL => return error.Unseekable, @@ -4379,7 +4380,7 @@ pub fn lseek_CUR_get(fd: fd_t) SeekError!u64 { } if (builtin.os.tag == .wasi and !builtin.link_libc) { var new_offset: wasi.filesize_t = undefined; - switch (wasi.fd_seek(fd, 0, wasi.WHENCE_CUR, &new_offset)) { + switch (wasi.fd_seek(fd, 0, .CUR, &new_offset)) { .SUCCESS => return new_offset, .BADF => unreachable, // always a race condition .INVAL => return error.Unseekable, diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig index ecfded4193..33d640a958 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -57,24 +57,23 @@ pub const socketcall = syscall_bits.socketcall; pub const syscall_pipe = syscall_bits.syscall_pipe; pub const syscall_fork = syscall_bits.syscall_fork; -pub const clone = arch_bits.clone; pub const ARCH = arch_bits.ARCH; pub const Elf_Symndx = arch_bits.Elf_Symndx; pub const F = arch_bits.F; pub const Flock = arch_bits.Flock; +pub const HWCAP = arch_bits.HWCAP; pub const LOCK = arch_bits.LOCK; -pub const MAP = arch_bits.MAP; pub const MMAP2_UNIT = arch_bits.MMAP2_UNIT; -pub const O = arch_bits.O; pub const REG = arch_bits.REG; pub const SC = arch_bits.SC; pub const SYS = arch_bits.SYS; +pub const Stat = arch_bits.Stat; pub const VDSO = arch_bits.VDSO; pub const blkcnt_t = arch_bits.blkcnt_t; pub const blksize_t = arch_bits.blksize_t; +pub const clone = arch_bits.clone; pub const dev_t = arch_bits.dev_t; pub const ino_t = arch_bits.ino_t; -pub const Stat = arch_bits.Stat; pub const mcontext_t = arch_bits.mcontext_t; pub const mode_t = arch_bits.mode_t; pub const msghdr = arch_bits.msghdr; @@ -92,29 +91,46 @@ pub const tls = @import("linux/tls.zig"); pub const pie = @import("linux/start_pie.zig"); pub const BPF = @import("linux/bpf.zig"); -const io_uring = @import("linux/io_uring.zig"); -pub const IO_Uring = io_uring.IO_Uring; -pub const SubmissionQueue = io_uring.SubmissionQueue; -pub const CompletionQueue = io_uring.CompletionQueue; -pub const io_uring_prep_nop = io_uring.io_uring_prep_nop; -pub const io_uring_prep_fsync = io_uring.io_uring_prep_fsync; -pub const io_uring_prep_rw = io_uring.io_uring_prep_rw; -pub const io_uring_prep_read = io_uring.io_uring_prep_read; -pub const io_uring_prep_write = io_uring.io_uring_prep_write; -pub const io_uring_prep_readv = io_uring.io_uring_prep_readv; -pub const io_uring_prep_writev = io_uring.io_uring_prep_writev; -pub const io_uring_prep_accept = io_uring.io_uring_prep_accept; -pub const io_uring_prep_connect = io_uring.io_uring_prep_connect; -pub const io_uring_prep_epoll_ctl = io_uring.io_uring_prep_epoll_ctl; -pub const io_uring_prep_recv = io_uring.io_uring_prep_recv; -pub const io_uring_prep_send = io_uring.io_uring_prep_send; -pub const io_uring_prep_openat = io_uring.io_uring_prep_openat; -pub const io_uring_prep_close = io_uring.io_uring_prep_close; -pub const io_uring_prep_timeout = io_uring.io_uring_prep_timeout; -pub const io_uring_prep_timeout_remove = io_uring.io_uring_prep_timeout_remove; -pub const io_uring_prep_poll_add = io_uring.io_uring_prep_poll_add; -pub const io_uring_prep_poll_remove = io_uring.io_uring_prep_poll_remove; -pub const io_uring_prep_fallocate = io_uring.io_uring_prep_fallocate; +pub const MAP = struct { + pub usingnamespace arch_bits.MAP; + + /// Share changes + pub const SHARED = 0x01; + /// Changes are private + pub const PRIVATE = 0x02; + /// share + validate extension flags + pub const SHARED_VALIDATE = 0x03; + /// Mask for type of mapping + pub const TYPE = 0x0f; + /// Interpret addr exactly + pub const FIXED = 0x10; + /// don't use a file + pub const ANONYMOUS = 0x20; + /// populate (prefault) pagetables + pub const POPULATE = 0x8000; + /// do not block on IO + pub const NONBLOCK = 0x10000; + /// give out an address that is best suited for process/thread stacks + pub const STACK = 0x20000; + /// create a huge page mapping + pub const HUGETLB = 0x40000; + /// perform synchronous page faults for the mapping + pub const SYNC = 0x80000; + /// FIXED which doesn't unmap underlying mapping + pub const FIXED_NOREPLACE = 0x100000; + /// For anonymous mmap, memory could be uninitialized + pub const UNINITIALIZED = 0x4000000; +}; + +pub const O = struct { + pub usingnamespace arch_bits.O; + + pub const RDONLY = 0o0; + pub const WRONLY = 0o1; + pub const RDWR = 0o2; +}; + +pub usingnamespace @import("linux/io_uring.zig"); /// Set by startup code, used by `getauxval`. pub var elf_aux_maybe: ?[*]std.elf.Auxv = null; @@ -1725,26 +1741,20 @@ pub const FUTEX = struct { 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; - /// page may be used for atomic ops pub const SEM = switch (native_arch) { // TODO: also xtensa .mips, .mipsel, .mips64, .mips64el => 0x10, else => 0x8, }; - /// mprotect flag: extend change to start of growsdown vma pub const GROWSDOWN = 0x01000000; - /// mprotect flag: extend change to end of growsup vma pub const GROWSUP = 0x02000000; }; @@ -1960,16 +1970,16 @@ pub const RWF = struct { /// high priority request, poll if possible pub const HIPRI: kernel_rwf = 0x00000001; - /// per-IO O_DSYNC + /// per-IO O.DSYNC pub const DSYNC: kernel_rwf = 0x00000002; - /// per-IO O_SYNC + /// per-IO O.SYNC pub const SYNC: kernel_rwf = 0x00000004; /// per-IO, return -EAGAIN if operation would block pub const NOWAIT: kernel_rwf = 0x00000008; - /// per-IO O_APPEND + /// per-IO O.APPEND pub const APPEND: kernel_rwf = 0x00000010; }; diff --git a/lib/std/os/linux/arm-eabi.zig b/lib/std/os/linux/arm-eabi.zig index 700761fe35..7727e2ff2f 100644 --- a/lib/std/os/linux/arm-eabi.zig +++ b/lib/std/os/linux/arm-eabi.zig @@ -532,26 +532,28 @@ pub const SYS = enum(usize) { pub const MMAP2_UNIT = 4096; -pub const O_CREAT = 0o100; -pub const O_EXCL = 0o200; -pub const O_NOCTTY = 0o400; -pub const O_TRUNC = 0o1000; -pub const O_APPEND = 0o2000; -pub const O_NONBLOCK = 0o4000; -pub const O_DSYNC = 0o10000; -pub const O_SYNC = 0o4010000; -pub const O_RSYNC = 0o4010000; -pub const O_DIRECTORY = 0o40000; -pub const O_NOFOLLOW = 0o100000; -pub const O_CLOEXEC = 0o2000000; - -pub const O_ASYNC = 0o20000; -pub const O_DIRECT = 0o200000; -pub const O_LARGEFILE = 0o400000; -pub const O_NOATIME = 0o1000000; -pub const O_PATH = 0o10000000; -pub const O_TMPFILE = 0o20040000; -pub const O_NDELAY = O_NONBLOCK; +pub const O = struct { + pub const CREAT = 0o100; + pub const EXCL = 0o200; + pub const NOCTTY = 0o400; + pub const TRUNC = 0o1000; + pub const APPEND = 0o2000; + pub const NONBLOCK = 0o4000; + pub const DSYNC = 0o10000; + pub const SYNC = 0o4010000; + pub const RSYNC = 0o4010000; + pub const DIRECTORY = 0o40000; + pub const NOFOLLOW = 0o100000; + pub const CLOEXEC = 0o2000000; + + pub const ASYNC = 0o20000; + pub const DIRECT = 0o200000; + pub const LARGEFILE = 0o400000; + pub const NOATIME = 0o1000000; + pub const PATH = 0o10000000; + pub const TMPFILE = 0o20040000; + pub const NDELAY = NONBLOCK; +}; pub const F = struct { pub const DUPFD = 0; @@ -597,35 +599,38 @@ pub const MAP = struct { pub const LOCKED = 0x2000; /// don't check for reservations pub const NORESERVE = 0x4000; - /// Only used by libc to communicate failure. - pub const FAILED = @intToPtr(*c_void, maxInt(usize)); }; -pub const VDSO_CGT_SYM = "__vdso_clock_gettime"; -pub const VDSO_CGT_VER = "LINUX_2.6"; - -pub const HWCAP_SWP = 1 << 0; -pub const HWCAP_HALF = 1 << 1; -pub const HWCAP_THUMB = 1 << 2; -pub const HWCAP_26BIT = 1 << 3; -pub const HWCAP_FAST_MULT = 1 << 4; -pub const HWCAP_FPA = 1 << 5; -pub const HWCAP_VFP = 1 << 6; -pub const HWCAP_EDSP = 1 << 7; -pub const HWCAP_JAVA = 1 << 8; -pub const HWCAP_IWMMXT = 1 << 9; -pub const HWCAP_CRUNCH = 1 << 10; -pub const HWCAP_THUMBEE = 1 << 11; -pub const HWCAP_NEON = 1 << 12; -pub const HWCAP_VFPv3 = 1 << 13; -pub const HWCAP_VFPv3D16 = 1 << 14; -pub const HWCAP_TLS = 1 << 15; -pub const HWCAP_VFPv4 = 1 << 16; -pub const HWCAP_IDIVA = 1 << 17; -pub const HWCAP_IDIVT = 1 << 18; -pub const HWCAP_VFPD32 = 1 << 19; -pub const HWCAP_IDIV = HWCAP_IDIVA | HWCAP_IDIVT; -pub const HWCAP_LPAE = 1 << 20; -pub const HWCAP_EVTSTRM = 1 << 21; + +pub const VDSO = struct { + pub const CGT_SYM = "__vdso_clock_gettime"; + pub const CGT_VER = "LINUX_2.6"; +}; + +pub const HWCAP = struct { + pub const SWP = 1 << 0; + pub const HALF = 1 << 1; + pub const THUMB = 1 << 2; + pub const @"26BIT" = 1 << 3; + pub const FAST_MULT = 1 << 4; + pub const FPA = 1 << 5; + pub const VFP = 1 << 6; + pub const EDSP = 1 << 7; + pub const JAVA = 1 << 8; + pub const IWMMXT = 1 << 9; + pub const CRUNCH = 1 << 10; + pub const THUMBEE = 1 << 11; + pub const NEON = 1 << 12; + pub const VFPv3 = 1 << 13; + pub const VFPv3D16 = 1 << 14; + pub const TLS = 1 << 15; + pub const VFPv4 = 1 << 16; + pub const IDIVA = 1 << 17; + pub const IDIVT = 1 << 18; + pub const VFPD32 = 1 << 19; + pub const IDIV = IDIVA | IDIVT; + pub const LPAE = 1 << 20; + pub const EVTSTRM = 1 << 21; +}; pub const Flock = extern struct { l_type: i16, diff --git a/lib/std/os/linux/arm64.zig b/lib/std/os/linux/arm64.zig index 13321f4595..7f0c2c12c5 100644 --- a/lib/std/os/linux/arm64.zig +++ b/lib/std/os/linux/arm64.zig @@ -410,26 +410,28 @@ pub const SYS = enum(usize) { _, }; -pub const O_CREAT = 0o100; -pub const O_EXCL = 0o200; -pub const O_NOCTTY = 0o400; -pub const O_TRUNC = 0o1000; -pub const O_APPEND = 0o2000; -pub const O_NONBLOCK = 0o4000; -pub const O_DSYNC = 0o10000; -pub const O_SYNC = 0o4010000; -pub const O_RSYNC = 0o4010000; -pub const O_DIRECTORY = 0o40000; -pub const O_NOFOLLOW = 0o100000; -pub const O_CLOEXEC = 0o2000000; - -pub const O_ASYNC = 0o20000; -pub const O_DIRECT = 0o200000; -pub const O_LARGEFILE = 0o400000; -pub const O_NOATIME = 0o1000000; -pub const O_PATH = 0o10000000; -pub const O_TMPFILE = 0o20040000; -pub const O_NDELAY = O_NONBLOCK; +pub const O = struct { + pub const CREAT = 0o100; + pub const EXCL = 0o200; + pub const NOCTTY = 0o400; + pub const TRUNC = 0o1000; + pub const APPEND = 0o2000; + pub const NONBLOCK = 0o4000; + pub const DSYNC = 0o10000; + pub const SYNC = 0o4010000; + pub const RSYNC = 0o4010000; + pub const DIRECTORY = 0o40000; + pub const NOFOLLOW = 0o100000; + pub const CLOEXEC = 0o2000000; + + pub const ASYNC = 0o20000; + pub const DIRECT = 0o200000; + pub const LARGEFILE = 0o400000; + pub const NOATIME = 0o1000000; + pub const PATH = 0o10000000; + pub const TMPFILE = 0o20040000; + pub const NDELAY = NONBLOCK; +}; pub const F = struct { pub const DUPFD = 0; @@ -475,11 +477,12 @@ pub const MAP = struct { pub const LOCKED = 0x2000; /// don't check for reservations pub const NORESERVE = 0x4000; - /// Only used by libc to communicate failure. - pub const FAILED = @intToPtr(*c_void, maxInt(usize)); }; -pub const VDSO_CGT_SYM = "__kernel_clock_gettime"; -pub const VDSO_CGT_VER = "LINUX_2.6.39"; + +pub const VDSO = struct { + pub const CGT_SYM = "__kernel_clock_gettime"; + pub const CGT_VER = "LINUX_2.6.39"; +}; pub const Flock = extern struct { l_type: i16, diff --git a/lib/std/os/linux/i386.zig b/lib/std/os/linux/i386.zig index 8efe21a8e4..eaa803768d 100644 --- a/lib/std/os/linux/i386.zig +++ b/lib/std/os/linux/i386.zig @@ -572,10 +572,6 @@ pub const SYS = enum(usize) { }; pub const O = struct { - pub const RDONLY = 0o0; - pub const WRONLY = 0o1; - pub const RDWR = 0o2; - pub const CREAT = 0o100; pub const EXCL = 0o200; pub const NOCTTY = 0o400; @@ -628,42 +624,12 @@ pub const LOCK = struct { }; pub const MAP = struct { - /// Share changes - pub const SHARED = 0x01; - /// Changes are private - pub const PRIVATE = 0x02; - /// share + validate extension flags - pub const SHARED_VALIDATE = 0x03; - /// Mask for type of mapping - pub const TYPE = 0x0f; - /// Interpret addr exactly - pub const FIXED = 0x10; - /// don't use a file - pub const ANONYMOUS = 0x20; - /// populate (prefault) pagetables - pub const POPULATE = 0x8000; - /// do not block on IO - pub const NONBLOCK = 0x10000; - /// give out an address that is best suited for process/thread stacks - pub const STACK = 0x20000; - /// create a huge page mapping - pub const HUGETLB = 0x40000; - /// perform synchronous page faults for the mapping - pub const SYNC = 0x80000; - /// FIXED which doesn't unmap underlying mapping - pub const FIXED_NOREPLACE = 0x100000; - /// For anonymous mmap, memory could be uninitialized - pub const UNINITIALIZED = 0x4000000; - pub const NORESERVE = 0x4000; pub const GROWSDOWN = 0x0100; pub const DENYWRITE = 0x0800; pub const EXECUTABLE = 0x1000; pub const LOCKED = 0x2000; pub const @"32BIT" = 0x40; - - /// Only used by libc to communicate failure. - pub const FAILED = @intToPtr(*c_void, maxInt(usize)); }; pub const MMAP2_UNIT = 4096; diff --git a/lib/std/os/linux/io_uring.zig b/lib/std/os/linux/io_uring.zig index bba9786a90..716137f43b 100644 --- a/lib/std/os/linux/io_uring.zig +++ b/lib/std/os/linux/io_uring.zig @@ -539,7 +539,7 @@ pub const IO_Uring = struct { pub fn timeout( self: *IO_Uring, user_data: u64, - ts: *const os.__kernel_timespec, + ts: *const os.linux.timespec, count: u32, flags: u32, ) !*io_uring_sqe { @@ -979,7 +979,7 @@ pub fn io_uring_prep_close(sqe: *io_uring_sqe, fd: os.fd_t) void { pub fn io_uring_prep_timeout( sqe: *io_uring_sqe, - ts: *const os.__kernel_timespec, + ts: *const os.linux.timespec, count: u32, flags: u32, ) void { @@ -1136,7 +1136,7 @@ test "readv" { }; defer ring.deinit(); - const fd = try os.openZ("/dev/zero", os.O_RDONLY | os.O_CLOEXEC, 0); + const fd = try os.openZ("/dev/zero", os.O.RDONLY | os.O.CLOEXEC, 0); defer os.close(fd); // Linux Kernel 5.4 supports IORING_REGISTER_FILES but not sparse fd sets (i.e. an fd of -1). @@ -1295,7 +1295,7 @@ test "openat" { const path = "test_io_uring_openat"; defer std.fs.cwd().deleteFile(path) catch {}; - const flags: u32 = os.O_CLOEXEC | os.O_RDWR | os.O_CREAT; + const flags: u32 = os.O.CLOEXEC | os.O.RDWR | os.O.CREAT; const mode: os.mode_t = 0o666; const sqe_openat = try ring.openat(0x33333333, linux.AT.FDCWD, path, flags, mode); try testing.expectEqual(io_uring_sqe{ @@ -1450,7 +1450,7 @@ test "timeout (after a relative time)" { const ms = 10; const margin = 5; - const ts = os.__kernel_timespec{ .tv_sec = 0, .tv_nsec = ms * 1000000 }; + const ts = os.linux.timespec{ .tv_sec = 0, .tv_nsec = ms * 1000000 }; const started = std.time.milliTimestamp(); const sqe = try ring.timeout(0x55555555, &ts, 0, 0); @@ -1479,7 +1479,7 @@ test "timeout (after a number of completions)" { }; defer ring.deinit(); - const ts = os.__kernel_timespec{ .tv_sec = 3, .tv_nsec = 0 }; + const ts = os.linux.timespec{ .tv_sec = 3, .tv_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); @@ -1512,7 +1512,7 @@ test "timeout_remove" { }; defer ring.deinit(); - const ts = os.__kernel_timespec{ .tv_sec = 3, .tv_nsec = 0 }; + const ts = os.linux.timespec{ .tv_sec = 3, .tv_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); diff --git a/lib/std/os/linux/mips.zig b/lib/std/os/linux/mips.zig index f4bdef609d..427a1aa6c6 100644 --- a/lib/std/os/linux/mips.zig +++ b/lib/std/os/linux/mips.zig @@ -629,26 +629,28 @@ pub const SYS = enum(usize) { _, }; -pub const O_CREAT = 0o0400; -pub const O_EXCL = 0o02000; -pub const O_NOCTTY = 0o04000; -pub const O_TRUNC = 0o01000; -pub const O_APPEND = 0o0010; -pub const O_NONBLOCK = 0o0200; -pub const O_DSYNC = 0o0020; -pub const O_SYNC = 0o040020; -pub const O_RSYNC = 0o040020; -pub const O_DIRECTORY = 0o0200000; -pub const O_NOFOLLOW = 0o0400000; -pub const O_CLOEXEC = 0o02000000; - -pub const O_ASYNC = 0o010000; -pub const O_DIRECT = 0o0100000; -pub const O_LARGEFILE = 0o020000; -pub const O_NOATIME = 0o01000000; -pub const O_PATH = 0o010000000; -pub const O_TMPFILE = 0o020200000; -pub const O_NDELAY = O_NONBLOCK; +pub const O = struct { + pub const CREAT = 0o0400; + pub const EXCL = 0o02000; + pub const NOCTTY = 0o04000; + pub const TRUNC = 0o01000; + pub const APPEND = 0o0010; + pub const NONBLOCK = 0o0200; + pub const DSYNC = 0o0020; + pub const SYNC = 0o040020; + pub const RSYNC = 0o040020; + pub const DIRECTORY = 0o0200000; + pub const NOFOLLOW = 0o0400000; + pub const CLOEXEC = 0o02000000; + + pub const ASYNC = 0o010000; + pub const DIRECT = 0o0100000; + pub const LARGEFILE = 0o020000; + pub const NOATIME = 0o01000000; + pub const PATH = 0o010000000; + pub const TMPFILE = 0o020200000; + pub const NDELAY = NONBLOCK; +}; pub const F = struct { pub const DUPFD = 0; @@ -692,8 +694,6 @@ pub const MAP = struct { pub const EXECUTABLE = 0x4000; pub const LOCKED = 0x8000; pub const @"32BIT" = 0x40; - /// Only used by libc to communicate failure. - pub const FAILED = @intToPtr(*c_void, maxInt(usize)); }; pub const SO = struct { @@ -726,8 +726,10 @@ pub const SO = struct { pub const RCVBUFFORCE = 33; }; -pub const VDSO_CGT_SYM = "__kernel_clock_gettime"; -pub const VDSO_CGT_VER = "LINUX_2.6.39"; +pub const VDSO = struct { + pub const CGT_SYM = "__kernel_clock_gettime"; + pub const CGT_VER = "LINUX_2.6.39"; +}; pub const Flock = extern struct { l_type: i16, diff --git a/lib/std/os/linux/powerpc.zig b/lib/std/os/linux/powerpc.zig index e0c1d32390..e2473055d6 100644 --- a/lib/std/os/linux/powerpc.zig +++ b/lib/std/os/linux/powerpc.zig @@ -562,26 +562,28 @@ pub const SYS = enum(usize) { process_madvise = 440, }; -pub const O_CREAT = 0o100; -pub const O_EXCL = 0o200; -pub const O_NOCTTY = 0o400; -pub const O_TRUNC = 0o1000; -pub const O_APPEND = 0o2000; -pub const O_NONBLOCK = 0o4000; -pub const O_DSYNC = 0o10000; -pub const O_SYNC = 0o4010000; -pub const O_RSYNC = 0o4010000; -pub const O_DIRECTORY = 0o40000; -pub const O_NOFOLLOW = 0o100000; -pub const O_CLOEXEC = 0o2000000; - -pub const O_ASYNC = 0o20000; -pub const O_DIRECT = 0o400000; -pub const O_LARGEFILE = 0o200000; -pub const O_NOATIME = 0o1000000; -pub const O_PATH = 0o10000000; -pub const O_TMPFILE = 0o20040000; -pub const O_NDELAY = O_NONBLOCK; +pub const O = struct { + pub const CREAT = 0o100; + pub const EXCL = 0o200; + pub const NOCTTY = 0o400; + pub const TRUNC = 0o1000; + pub const APPEND = 0o2000; + pub const NONBLOCK = 0o4000; + pub const DSYNC = 0o10000; + pub const SYNC = 0o4010000; + pub const RSYNC = 0o4010000; + pub const DIRECTORY = 0o40000; + pub const NOFOLLOW = 0o100000; + pub const CLOEXEC = 0o2000000; + + pub const ASYNC = 0o20000; + pub const DIRECT = 0o400000; + pub const LARGEFILE = 0o200000; + pub const NOATIME = 0o1000000; + pub const PATH = 0o10000000; + pub const TMPFILE = 0o20040000; + pub const NDELAY = NONBLOCK; +}; pub const F = struct { pub const DUPFD = 0; @@ -627,11 +629,12 @@ pub const MAP = struct { pub const LOCKED = 0x0080; /// don't check for reservations pub const NORESERVE = 0x0040; - /// Only used by libc to communicate failure. - pub const FAILED = @intToPtr(*c_void, maxInt(usize)); }; -pub const VDSO_CGT_SYM = "__kernel_clock_gettime"; -pub const VDSO_CGT_VER = "LINUX_2.6.15"; + +pub const VDSO = struct { + pub const CGT_SYM = "__kernel_clock_gettime"; + pub const CGT_VER = "LINUX_2.6.15"; +}; pub const Flock = extern struct { l_type: i16, diff --git a/lib/std/os/linux/powerpc64.zig b/lib/std/os/linux/powerpc64.zig index 62586eb0f7..63c4e6a2d9 100644 --- a/lib/std/os/linux/powerpc64.zig +++ b/lib/std/os/linux/powerpc64.zig @@ -537,26 +537,28 @@ pub const SYS = enum(usize) { _, }; -pub const O_CREAT = 0o100; -pub const O_EXCL = 0o200; -pub const O_NOCTTY = 0o400; -pub const O_TRUNC = 0o1000; -pub const O_APPEND = 0o2000; -pub const O_NONBLOCK = 0o4000; -pub const O_DSYNC = 0o10000; -pub const O_SYNC = 0o4010000; -pub const O_RSYNC = 0o4010000; -pub const O_DIRECTORY = 0o40000; -pub const O_NOFOLLOW = 0o100000; -pub const O_CLOEXEC = 0o2000000; - -pub const O_ASYNC = 0o20000; -pub const O_DIRECT = 0o400000; -pub const O_LARGEFILE = 0o200000; -pub const O_NOATIME = 0o1000000; -pub const O_PATH = 0o10000000; -pub const O_TMPFILE = 0o20200000; -pub const O_NDELAY = O_NONBLOCK; +pub const O = struct { + pub const CREAT = 0o100; + pub const EXCL = 0o200; + pub const NOCTTY = 0o400; + pub const TRUNC = 0o1000; + pub const APPEND = 0o2000; + pub const NONBLOCK = 0o4000; + pub const DSYNC = 0o10000; + pub const SYNC = 0o4010000; + pub const RSYNC = 0o4010000; + pub const DIRECTORY = 0o40000; + pub const NOFOLLOW = 0o100000; + pub const CLOEXEC = 0o2000000; + + pub const ASYNC = 0o20000; + pub const DIRECT = 0o400000; + pub const LARGEFILE = 0o200000; + pub const NOATIME = 0o1000000; + pub const PATH = 0o10000000; + pub const TMPFILE = 0o20200000; + pub const NDELAY = NONBLOCK; +}; pub const F = struct { pub const DUPFD = 0; @@ -602,12 +604,12 @@ pub const MAP = struct { pub const LOCKED = 0x0080; /// don't check for reservations pub const NORESERVE = 0x0040; - /// Only used by libc to communicate failure. - pub const FAILED = @intToPtr(*c_void, maxInt(usize)); }; -pub const VDSO_CGT_SYM = "__kernel_clock_gettime"; -pub const VDSO_CGT_VER = "LINUX_2.6.15"; +pub const VDSO = struct { + pub const CGT_SYM = "__kernel_clock_gettime"; + pub const CGT_VER = "LINUX_2.6.15"; +}; pub const Flock = extern struct { l_type: i16, diff --git a/lib/std/os/linux/riscv64.zig b/lib/std/os/linux/riscv64.zig index 0dd947506a..424e6bc3de 100644 --- a/lib/std/os/linux/riscv64.zig +++ b/lib/std/os/linux/riscv64.zig @@ -406,26 +406,28 @@ pub const SYS = enum(usize) { _, }; -pub const O_CREAT = 0o100; -pub const O_EXCL = 0o200; -pub const O_NOCTTY = 0o400; -pub const O_TRUNC = 0o1000; -pub const O_APPEND = 0o2000; -pub const O_NONBLOCK = 0o4000; -pub const O_DSYNC = 0o10000; -pub const O_SYNC = 0o4010000; -pub const O_RSYNC = 0o4010000; -pub const O_DIRECTORY = 0o200000; -pub const O_NOFOLLOW = 0o400000; -pub const O_CLOEXEC = 0o2000000; +pub const O = struct { + pub const CREAT = 0o100; + pub const EXCL = 0o200; + pub const NOCTTY = 0o400; + pub const TRUNC = 0o1000; + pub const APPEND = 0o2000; + pub const NONBLOCK = 0o4000; + pub const DSYNC = 0o10000; + pub const SYNC = 0o4010000; + pub const RSYNC = 0o4010000; + pub const DIRECTORY = 0o200000; + pub const NOFOLLOW = 0o400000; + pub const CLOEXEC = 0o2000000; -pub const O_ASYNC = 0o20000; -pub const O_DIRECT = 0o40000; -pub const O_LARGEFILE = 0o100000; -pub const O_NOATIME = 0o1000000; -pub const O_PATH = 0o10000000; -pub const O_TMPFILE = 0o20200000; -pub const O_NDELAY = O_NONBLOCK; + pub const ASYNC = 0o20000; + pub const DIRECT = 0o40000; + pub const LARGEFILE = 0o100000; + pub const NOATIME = 0o1000000; + pub const PATH = 0o10000000; + pub const TMPFILE = 0o20200000; + pub const NDELAY = NONBLOCK; +}; pub const F = struct { pub const DUPFD = 0; @@ -518,3 +520,6 @@ pub const Stat = extern struct { }; pub const Elf_Symndx = u32; + +pub const VDSO = struct {}; +pub const MAP = struct {}; diff --git a/lib/std/os/linux/sparc64.zig b/lib/std/os/linux/sparc64.zig index aa50b8364b..e3e32b659b 100644 --- a/lib/std/os/linux/sparc64.zig +++ b/lib/std/os/linux/sparc64.zig @@ -571,26 +571,28 @@ pub const SYS = enum(usize) { _, }; -pub const O_CREAT = 0x200; -pub const O_EXCL = 0x800; -pub const O_NOCTTY = 0x8000; -pub const O_TRUNC = 0x400; -pub const O_APPEND = 0x8; -pub const O_NONBLOCK = 0x4000; -pub const O_SYNC = 0x802000; -pub const O_DSYNC = 0x2000; -pub const O_RSYNC = O_SYNC; -pub const O_DIRECTORY = 0x10000; -pub const O_NOFOLLOW = 0x20000; -pub const O_CLOEXEC = 0x400000; - -pub const O_ASYNC = 0x40; -pub const O_DIRECT = 0x100000; -pub const O_LARGEFILE = 0; -pub const O_NOATIME = 0x200000; -pub const O_PATH = 0x1000000; -pub const O_TMPFILE = 0x2010000; -pub const O_NDELAY = O_NONBLOCK | 0x4; +pub const O = struct { + pub const CREAT = 0x200; + pub const EXCL = 0x800; + pub const NOCTTY = 0x8000; + pub const TRUNC = 0x400; + pub const APPEND = 0x8; + pub const NONBLOCK = 0x4000; + pub const SYNC = 0x802000; + pub const DSYNC = 0x2000; + pub const RSYNC = SYNC; + pub const DIRECTORY = 0x10000; + pub const NOFOLLOW = 0x20000; + pub const CLOEXEC = 0x400000; + + pub const ASYNC = 0x40; + pub const DIRECT = 0x100000; + pub const LARGEFILE = 0; + pub const NOATIME = 0x200000; + pub const PATH = 0x1000000; + pub const TMPFILE = 0x2010000; + pub const NDELAY = NONBLOCK | 0x4; +}; pub const F = struct { pub const DUPFD = 0; @@ -633,11 +635,12 @@ pub const MAP = struct { pub const LOCKED = 0x0100; /// don't check for reservations pub const NORESERVE = 0x0040; - /// Only used by libc to communicate failure. - pub const FAILED = @intToPtr(*c_void, maxInt(usize)); }; -pub const VDSO_CGT_SYM = "__vdso_clock_gettime"; -pub const VDSO_CGT_VER = "LINUX_2.6"; + +pub const VDSO = struct { + pub const CGT_SYM = "__vdso_clock_gettime"; + pub const CGT_VER = "LINUX_2.6"; +}; pub const Flock = extern struct { l_type: i16, diff --git a/lib/std/os/linux/x86_64.zig b/lib/std/os/linux/x86_64.zig index 3f4106aa35..1a50fb14c6 100644 --- a/lib/std/os/linux/x86_64.zig +++ b/lib/std/os/linux/x86_64.zig @@ -476,10 +476,6 @@ pub const SYS = enum(usize) { }; pub const O = struct { - pub const RDONLY = 0o0; - pub const WRONLY = 0o1; - pub const RDWR = 0o2; - pub const CREAT = 0o100; pub const EXCL = 0o200; pub const NOCTTY = 0o400; @@ -526,32 +522,6 @@ pub const F = struct { }; pub const MAP = struct { - /// Share changes - pub const SHARED = 0x01; - /// Changes are private - pub const PRIVATE = 0x02; - /// share + validate extension flags - pub const SHARED_VALIDATE = 0x03; - /// Mask for type of mapping - pub const TYPE = 0x0f; - /// Interpret addr exactly - pub const FIXED = 0x10; - /// don't use a file - pub const ANONYMOUS = 0x20; - /// populate (prefault) pagetables - pub const POPULATE = 0x8000; - /// do not block on IO - pub const NONBLOCK = 0x10000; - /// give out an address that is best suited for process/thread stacks - pub const STACK = 0x20000; - /// create a huge page mapping - pub const HUGETLB = 0x40000; - /// perform synchronous page faults for the mapping - pub const SYNC = 0x80000; - /// FIXED which doesn't unmap underlying mapping - pub const FIXED_NOREPLACE = 0x100000; - /// For anonymous mmap, memory could be uninitialized - pub const UNINITIALIZED = 0x4000000; /// only give out 32bit addresses pub const @"32BIT" = 0x40; /// stack-like segment @@ -564,8 +534,6 @@ pub const MAP = struct { pub const LOCKED = 0x2000; /// don't check for reservations pub const NORESERVE = 0x4000; - /// Only used by libc to communicate failure. - pub const FAILED = @intToPtr(*c_void, maxInt(usize)); }; pub const VDSO = struct { diff --git a/lib/std/os/test.zig b/lib/std/os/test.zig index 3face414ad..21a02a8c8f 100644 --- a/lib/std/os/test.zig +++ b/lib/std/os/test.zig @@ -401,7 +401,7 @@ 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(os, "dl_phdr_info")) os.dl_phdr_info else c_void; +const dl_phdr_info = if (@hasDecl(os.system, "dl_phdr_info")) os.dl_phdr_info else c_void; const IterFnError = error{ MissingPtLoadSegment, @@ -676,7 +676,7 @@ test "fsync" { } test "getrlimit and setrlimit" { - if (native_os == .windows) { + if (!@hasDecl(os.system, "rlimit")) { return error.SkipZigTest; } diff --git a/lib/std/os/wasi.zig b/lib/std/os/wasi.zig index 07f56a1913..7cd0206402 100644 --- a/lib/std/os/wasi.zig +++ b/lib/std/os/wasi.zig @@ -337,6 +337,7 @@ pub const filestat_t = extern struct { } }; +/// Also known as `FILETYPE`. pub const filetype_t = enum(u8) { UNKNOWN, BLOCK_DEVICE, @@ -532,6 +533,7 @@ pub const timestamp_t = u64; pub const userdata_t = u64; +/// Also known as `WHENCE`. pub const whence_t = enum(u8) { SET, CUR, END }; pub const S = struct { diff --git a/lib/std/os/windows.zig b/lib/std/os/windows.zig index 9fe4329ccc..3b1394202f 100644 --- a/lib/std/os/windows.zig +++ b/lib/std/os/windows.zig @@ -3192,7 +3192,7 @@ pub usingnamespace switch (native_arch) { pub const EXCEPTION_POINTERS = extern struct { ExceptionRecord: *EXCEPTION_RECORD, - ContextRecord: *@This().CONTEXT, + ContextRecord: *std.os.windows.CONTEXT, }; pub const VECTORED_EXCEPTION_HANDLER = fn (ExceptionInfo: *EXCEPTION_POINTERS) callconv(WINAPI) c_long; diff --git a/lib/std/special/ssp.zig b/lib/std/special/ssp.zig index 7bc5cef813..94a6676838 100644 --- a/lib/std/special/ssp.zig +++ b/lib/std/special/ssp.zig @@ -25,9 +25,7 @@ pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn _ = msg; _ = error_return_trace; @setCold(true); - if (@hasDecl(std.os, "abort")) - std.os.abort(); - while (true) {} + std.os.abort(); } export fn __stack_chk_fail() callconv(.C) noreturn { diff --git a/lib/std/start.zig b/lib/std/start.zig index f16a5aba1e..ac592e26ed 100644 --- a/lib/std/start.zig +++ b/lib/std/start.zig @@ -345,7 +345,7 @@ fn posixCallMainAndExit() noreturn { // FIXME: Elide the check for targets >= ARMv7 when the target feature API // becomes less verbose (and more usable). if (comptime native_arch.isARM()) { - if (at_hwcap & std.os.linux.HWCAP_TLS == 0) { + if (at_hwcap & std.os.linux.HWCAP.TLS == 0) { // FIXME: Make __aeabi_read_tp call the kernel helper kuser_get_tls // For the time being use a simple abort instead of a @panic call to // keep the binary bloat under control. diff --git a/lib/std/x/net/tcp.zig b/lib/std/x/net/tcp.zig index 740c2d434a..4fbd07e00c 100644 --- a/lib/std/x/net/tcp.zig +++ b/lib/std/x/net/tcp.zig @@ -193,7 +193,7 @@ pub const Client = struct { /// Disable Nagle's algorithm on a TCP socket. It returns `error.UnsupportedSocketOption` if /// the host does not support sockets disabling Nagle's algorithm. pub fn setNoDelay(self: Client, enabled: bool) !void { - if (comptime @hasDecl(os, "TCP_NODELAY")) { + if (@hasDecl(os.TCP, "NODELAY")) { const bytes = mem.asBytes(&@as(usize, @boolToInt(enabled))); return self.socket.setOption(os.IPPROTO.TCP, os.TCP_NODELAY, bytes); } @@ -203,7 +203,7 @@ pub const Client = struct { /// Enables TCP Quick ACK on a TCP socket to immediately send rather than delay ACKs when necessary. It returns /// `error.UnsupportedSocketOption` if the host does not support TCP Quick ACK. pub fn setQuickACK(self: Client, enabled: bool) !void { - if (comptime @hasDecl(os, "TCP_QUICKACK")) { + if (@hasDecl(os.TCP, "QUICKACK")) { return self.socket.setOption(os.IPPROTO.TCP, os.TCP_QUICKACK, mem.asBytes(&@as(u32, @boolToInt(enabled)))); } return error.UnsupportedSocketOption; @@ -304,7 +304,7 @@ pub const Listener = struct { /// Enables TCP Fast Open (RFC 7413) on a TCP socket. It returns `error.UnsupportedSocketOption` if the host does not /// support TCP Fast Open. pub fn setFastOpen(self: Listener, enabled: bool) !void { - if (comptime @hasDecl(os, "TCP_FASTOPEN")) { + if (@hasDecl(os.TCP, "FASTOPEN")) { return self.socket.setOption(os.IPPROTO.TCP, os.TCP_FASTOPEN, mem.asBytes(&@as(u32, @boolToInt(enabled)))); } return error.UnsupportedSocketOption; diff --git a/lib/std/x/os/net.zig b/lib/std/x/os/net.zig index 6a5b12dab6..08ecede3e5 100644 --- a/lib/std/x/os/net.zig +++ b/lib/std/x/os/net.zig @@ -6,12 +6,13 @@ const mem = std.mem; const math = std.math; const testing = std.testing; const native_os = std.Target.current.os; +const have_ifnamesize = @hasDecl(os.system, "IFNAMESIZE"); /// Resolves a network interface name into a scope/zone ID. It returns /// an error if either resolution fails, or if the interface name is /// too long. pub fn resolveScopeID(name: []const u8) !u32 { - if (@hasDecl(os, "IFNAMESIZE")) { + if (have_ifnamesize) { if (name.len >= os.IFNAMESIZE - 1) return error.NameTooLong; if (native_os.tag == .windows) { @@ -556,7 +557,7 @@ test "ipv6: parse & format" { } test "ipv6: parse & format addresses with scope ids" { - if (!@hasDecl(os, "IFNAMESIZE")) return error.SkipZigTest; + if (!have_ifnamesize) return error.SkipZigTest; const inputs = [_][]const u8{ "FF01::FB%lo", diff --git a/test/behavior/usingnamespace/a.zig b/test/behavior/usingnamespace/a.zig new file mode 100644 index 0000000000..21d4278e15 --- /dev/null +++ b/test/behavior/usingnamespace/a.zig @@ -0,0 +1,7 @@ +usingnamespace @import("b.zig"); + +pub const a_text = "OK\n"; + +pub fn ok() bool { + return @import("std").mem.eql(u8, @This().b_text, "OK\n"); +} diff --git a/test/behavior/usingnamespace/b.zig b/test/behavior/usingnamespace/b.zig new file mode 100644 index 0000000000..08dafa3c50 --- /dev/null +++ b/test/behavior/usingnamespace/b.zig @@ -0,0 +1,3 @@ +usingnamespace @import("a.zig"); + +pub const b_text = @This().a_text; diff --git a/test/behavior/usingnamespace/bar.zig b/test/behavior/usingnamespace/bar.zig new file mode 100644 index 0000000000..faa3f27dbe --- /dev/null +++ b/test/behavior/usingnamespace/bar.zig @@ -0,0 +1,8 @@ +usingnamespace @import("other.zig"); + +pub var saw_bar_function = false; +pub fn bar_function() void { + if (@This().foo_function()) { + saw_bar_function = true; + } +} diff --git a/test/behavior/usingnamespace/foo.zig b/test/behavior/usingnamespace/foo.zig new file mode 100644 index 0000000000..6b2b14e51c --- /dev/null +++ b/test/behavior/usingnamespace/foo.zig @@ -0,0 +1,14 @@ +// purposefully conflicting function with main source file +// but it's private so it should be OK +fn privateFunction() bool { + return false; +} + +pub fn printText() bool { + return privateFunction(); +} + +pub var saw_foo_function = false; +pub fn foo_function() void { + saw_foo_function = true; +} diff --git a/test/behavior/usingnamespace/import_segregation.zig b/test/behavior/usingnamespace/import_segregation.zig new file mode 100644 index 0000000000..a509189be3 --- /dev/null +++ b/test/behavior/usingnamespace/import_segregation.zig @@ -0,0 +1,11 @@ +const expect = @import("std").testing.expect; + +usingnamespace @import("foo.zig"); +usingnamespace @import("bar.zig"); + +test "no clobbering happened" { + @This().foo_function(); + @This().bar_function(); + try expect(@This().saw_foo_function); + try expect(@This().saw_bar_function); +} diff --git a/test/behavior/usingnamespace/other.zig b/test/behavior/usingnamespace/other.zig new file mode 100644 index 0000000000..02e0f39e90 --- /dev/null +++ b/test/behavior/usingnamespace/other.zig @@ -0,0 +1,4 @@ +pub fn foo_function() bool { + // this one conflicts with the one from foo + return true; +} diff --git a/test/behavior/usingnamespace_stage1.zig b/test/behavior/usingnamespace_stage1.zig index 30babc5381..142df21549 100644 --- a/test/behavior/usingnamespace_stage1.zig +++ b/test/behavior/usingnamespace_stage1.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const expect = std.testing.expect; fn Foo(comptime T: type) type { return struct { @@ -20,3 +21,21 @@ usingnamespace struct { test "usingnamespace does not redeclare an imported variable" { comptime try std.testing.expect(@This().foo == 42); } + +usingnamespace @import("usingnamespace/foo.zig"); +test "usingnamespace omits mixing in private functions" { + try expect(@This().privateFunction()); + try expect(!@This().printText()); +} +fn privateFunction() bool { + return true; +} + +test { + _ = @import("usingnamespace/import_segregation.zig"); +} + +usingnamespace @import("usingnamespace/a.zig"); +test "two files usingnamespace import each other" { + try expect(@This().ok()); +} diff --git a/test/cases.zig b/test/cases.zig index 2f3884de1e..64fe39e07b 100644 --- a/test/cases.zig +++ b/test/cases.zig @@ -1073,37 +1073,37 @@ pub fn addCases(ctx: *TestContext) !void { case.addError( \\pub fn main() void { \\ var i = 0; - \\ for (n) |_, i| { + \\ for ("n") |_, i| { \\ } \\} , &[_][]const u8{ - ":3:17: error: redeclaration of local variable 'i'", + ":3:19: error: redeclaration of local variable 'i'", ":2:9: note: previous declaration here", }); case.addError( \\pub fn main() void { \\ var i = 0; - \\ for (n) |i| { + \\ for ("n") |i| { \\ } \\} , &[_][]const u8{ - ":3:14: error: redeclaration of local variable 'i'", + ":3:16: error: redeclaration of local variable 'i'", ":2:9: note: previous declaration here", }); case.addError( \\pub fn main() void { \\ var i = 0; - \\ while (n) |i| { + \\ while ("n") |i| { \\ } \\} , &[_][]const u8{ - ":3:16: error: redeclaration of local variable 'i'", + ":3:18: error: redeclaration of local variable 'i'", ":2:9: note: previous declaration here", }); case.addError( \\pub fn main() void { \\ var i = 0; - \\ while (n) |bruh| { + \\ while ("n") |bruh| { \\ _ = bruh; \\ } else |i| { \\ diff --git a/test/cli.zig b/test/cli.zig index e3a00fe735..59fb7095af 100644 --- a/test/cli.zig +++ b/test/cli.zig @@ -45,13 +45,6 @@ pub fn main() !void { } } -fn unwrapArg(arg: UnwrapArgError![]u8) UnwrapArgError![]u8 { - return arg catch |err| { - warn("Unable to parse command line: {}\n", .{err}); - return err; - }; -} - fn printCmd(cwd: []const u8, argv: []const []const u8) void { std.debug.warn("cd {s} && ", .{cwd}); for (argv) |arg| { diff --git a/test/compare_output.zig b/test/compare_output.zig index c3da3cc4a5..7ff428fb33 100644 --- a/test/compare_output.zig +++ b/test/compare_output.zig @@ -17,111 +17,6 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { \\} , "Hello, world!" ++ std.cstr.line_sep); - cases.addCase(x: { - var tc = cases.create("multiple files with private function", - \\usingnamespace @import("std").io; - \\usingnamespace @import("foo.zig"); - \\ - \\pub fn main() void { - \\ privateFunction(); - \\ const stdout = getStdOut().writer(); - \\ stdout.print("OK 2\n", .{}) catch unreachable; - \\} - \\ - \\fn privateFunction() void { - \\ printText(); - \\} - , "OK 1\nOK 2\n"); - - tc.addSourceFile("foo.zig", - \\usingnamespace @import("std").io; - \\ - \\// purposefully conflicting function with main.zig - \\// but it's private so it should be OK - \\fn privateFunction() void { - \\ const stdout = getStdOut().writer(); - \\ stdout.print("OK 1\n", .{}) catch unreachable; - \\} - \\ - \\pub fn printText() void { - \\ privateFunction(); - \\} - ); - - break :x tc; - }); - - cases.addCase(x: { - var tc = cases.create("import segregation", - \\usingnamespace @import("foo.zig"); - \\usingnamespace @import("bar.zig"); - \\ - \\pub fn main() void { - \\ foo_function(); - \\ bar_function(); - \\} - , "OK\nOK\n"); - - tc.addSourceFile("foo.zig", - \\usingnamespace @import("std").io; - \\pub fn foo_function() void { - \\ const stdout = getStdOut().writer(); - \\ stdout.print("OK\n", .{}) catch unreachable; - \\} - ); - - tc.addSourceFile("bar.zig", - \\usingnamespace @import("other.zig"); - \\usingnamespace @import("std").io; - \\ - \\pub fn bar_function() void { - \\ if (foo_function()) { - \\ const stdout = getStdOut().writer(); - \\ stdout.print("OK\n", .{}) catch unreachable; - \\ } - \\} - ); - - tc.addSourceFile("other.zig", - \\pub fn foo_function() bool { - \\ // this one conflicts with the one from foo - \\ return true; - \\} - ); - - break :x tc; - }); - - cases.addCase(x: { - var tc = cases.create("two files usingnamespace import each other", - \\usingnamespace @import("a.zig"); - \\ - \\pub fn main() void { - \\ ok(); - \\} - , "OK\n"); - - tc.addSourceFile("a.zig", - \\usingnamespace @import("b.zig"); - \\const io = @import("std").io; - \\ - \\pub const a_text = "OK\n"; - \\ - \\pub fn ok() void { - \\ const stdout = io.getStdOut().writer(); - \\ stdout.print(b_text, .{}) catch unreachable; - \\} - ); - - tc.addSourceFile("b.zig", - \\usingnamespace @import("a.zig"); - \\ - \\pub const b_text = a_text; - ); - - break :x tc; - }); - cases.add("hello world without libc", \\const io = @import("std").io; \\ diff --git a/test/standalone/brace_expansion/main.zig b/test/standalone/brace_expansion/main.zig index 990c2b1660..35fe6e5c6a 100644 --- a/test/standalone/brace_expansion/main.zig +++ b/test/standalone/brace_expansion/main.zig @@ -234,7 +234,7 @@ pub fn main() !void { var result_buf = ArrayList(u8).init(global_allocator); defer result_buf.deinit(); - try expandString(stdin_buf.items, &result_buf); + try expandString(stdin.items, &result_buf); try stdout_file.write(result_buf.items); } -- cgit v1.2.3