authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-04-01 10:24:54-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2020-04-01 10:24:54-04:00
loge8a1e2a1d8f2903d5951339f7d3e0dbdfc85704c
tree41f671fd9924644bb3e3f1bcd771822087a527d0
parent0628c2e2bae0a847dee4863521d9e6f4d9383e83
parent5047cd3d782c51474216eda92ea457315bc4f8b5
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #4894 from LemonBoy/netbsd-p2

More NetBSD bits

6 files changed, 215 insertions(+), 84 deletions(-)

lib/std/c.zig+45-12
...@@ -73,7 +73,6 @@ pub extern "c" fn abort() noreturn;...@@ -73,7 +73,6 @@ pub extern "c" fn abort() noreturn;
73pub extern "c" fn exit(code: c_int) noreturn;73pub extern "c" fn exit(code: c_int) noreturn;
74pub extern "c" fn isatty(fd: fd_t) c_int;74pub extern "c" fn isatty(fd: fd_t) c_int;
75pub extern "c" fn close(fd: fd_t) c_int;75pub extern "c" fn close(fd: fd_t) c_int;
76pub extern "c" fn fstat(fd: fd_t, buf: *Stat) c_int;
77pub extern "c" fn fstatat(dirfd: fd_t, path: [*:0]const u8, stat_buf: *Stat, flags: u32) c_int;76pub extern "c" fn fstatat(dirfd: fd_t, path: [*:0]const u8, stat_buf: *Stat, flags: u32) c_int;
78pub extern "c" fn lseek(fd: fd_t, offset: off_t, whence: c_int) off_t;77pub extern "c" fn lseek(fd: fd_t, offset: off_t, whence: c_int) off_t;
79pub extern "c" fn open(path: [*:0]const u8, oflag: c_uint, ...) c_int;78pub extern "c" fn open(path: [*:0]const u8, oflag: c_uint, ...) c_int;
...@@ -86,7 +85,6 @@ pub extern "c" fn pread(fd: fd_t, buf: [*]u8, nbyte: usize, offset: u64) isize;...@@ -86,7 +85,6 @@ pub extern "c" fn pread(fd: fd_t, buf: [*]u8, nbyte: usize, offset: u64) isize;
86pub extern "c" fn preadv(fd: c_int, iov: [*]const iovec, iovcnt: c_uint, offset: u64) isize;85pub extern "c" fn preadv(fd: c_int, iov: [*]const iovec, iovcnt: c_uint, offset: u64) isize;
87pub extern "c" fn writev(fd: c_int, iov: [*]const iovec_const, iovcnt: c_uint) isize;86pub extern "c" fn writev(fd: c_int, iov: [*]const iovec_const, iovcnt: c_uint) isize;
88pub extern "c" fn pwritev(fd: c_int, iov: [*]const iovec_const, iovcnt: c_uint, offset: u64) isize;87pub extern "c" fn pwritev(fd: c_int, iov: [*]const iovec_const, iovcnt: c_uint, offset: u64) isize;
89pub extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *Stat) c_int;
90pub extern "c" fn write(fd: fd_t, buf: [*]const u8, nbyte: usize) isize;88pub extern "c" fn write(fd: fd_t, buf: [*]const u8, nbyte: usize) isize;
91pub extern "c" fn pwrite(fd: fd_t, buf: [*]const u8, nbyte: usize, offset: u64) isize;89pub extern "c" fn pwrite(fd: fd_t, buf: [*]const u8, nbyte: usize, offset: u64) isize;
92pub extern "c" fn mmap(addr: ?*align(page_size) c_void, len: usize, prot: c_uint, flags: c_uint, fd: fd_t, offset: u64) *c_void;90pub extern "c" fn mmap(addr: ?*align(page_size) c_void, len: usize, prot: c_uint, flags: c_uint, fd: fd_t, offset: u64) *c_void;
...@@ -114,15 +112,10 @@ pub extern "c" fn dup2(old_fd: fd_t, new_fd: fd_t) c_int;...@@ -114,15 +112,10 @@ pub extern "c" fn dup2(old_fd: fd_t, new_fd: fd_t) c_int;
114pub extern "c" fn readlink(noalias path: [*:0]const u8, noalias buf: [*]u8, bufsize: usize) isize;112pub extern "c" fn readlink(noalias path: [*:0]const u8, noalias buf: [*]u8, bufsize: usize) isize;
115pub extern "c" fn readlinkat(dirfd: fd_t, noalias path: [*:0]const u8, noalias buf: [*]u8, bufsize: usize) isize;113pub extern "c" fn readlinkat(dirfd: fd_t, noalias path: [*:0]const u8, noalias buf: [*]u8, bufsize: usize) isize;
116pub extern "c" fn realpath(noalias file_name: [*:0]const u8, noalias resolved_name: [*]u8) ?[*:0]u8;114pub extern "c" fn realpath(noalias file_name: [*:0]const u8, noalias resolved_name: [*]u8) ?[*:0]u8;
117pub extern "c" fn sigprocmask(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*sigset_t) c_int;
118pub extern "c" fn gettimeofday(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int;
119pub extern "c" fn sigaction(sig: c_int, noalias act: *const Sigaction, noalias oact: ?*Sigaction) c_int;
120pub extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int;
121pub extern "c" fn setreuid(ruid: c_uint, euid: c_uint) c_int;115pub extern "c" fn setreuid(ruid: c_uint, euid: c_uint) c_int;
122pub extern "c" fn setregid(rgid: c_uint, egid: c_uint) c_int;116pub extern "c" fn setregid(rgid: c_uint, egid: c_uint) c_int;
123pub extern "c" fn rmdir(path: [*:0]const u8) c_int;117pub extern "c" fn rmdir(path: [*:0]const u8) c_int;
124pub extern "c" fn getenv(name: [*:0]const u8) ?[*:0]u8;118pub extern "c" fn getenv(name: [*:0]const u8) ?[*:0]u8;
125pub extern "c" fn getrusage(who: c_int, usage: *rusage) c_int;
126pub extern "c" fn sysctl(name: [*]const c_int, namelen: c_uint, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int;119pub extern "c" fn sysctl(name: [*]const c_int, namelen: c_uint, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int;
127pub extern "c" fn sysctlbyname(name: [*:0]const u8, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int;120pub extern "c" fn sysctlbyname(name: [*:0]const u8, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int;
128pub extern "c" fn sysctlnametomib(name: [*:0]const u8, mibp: ?*c_int, sizep: ?*usize) c_int;121pub extern "c" fn sysctlnametomib(name: [*:0]const u8, mibp: ?*c_int, sizep: ?*usize) c_int;
...@@ -133,7 +126,6 @@ pub extern "c" fn uname(buf: *utsname) c_int;...@@ -133,7 +126,6 @@ pub extern "c" fn uname(buf: *utsname) c_int;
133126
134pub extern "c" fn gethostname(name: [*]u8, len: usize) c_int;127pub extern "c" fn gethostname(name: [*]u8, len: usize) c_int;
135pub extern "c" fn bind(socket: fd_t, address: ?*const sockaddr, address_len: socklen_t) c_int;128pub extern "c" fn bind(socket: fd_t, address: ?*const sockaddr, address_len: socklen_t) c_int;
136pub extern "c" fn socket(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int;
137pub extern "c" fn socketpair(domain: c_uint, sock_type: c_uint, protocol: c_uint, sv: *[2]fd_t) c_int;129pub extern "c" fn socketpair(domain: c_uint, sock_type: c_uint, protocol: c_uint, sv: *[2]fd_t) c_int;
138pub extern "c" fn listen(sockfd: fd_t, backlog: c_uint) c_int;130pub extern "c" fn listen(sockfd: fd_t, backlog: c_uint) c_int;
139pub extern "c" fn getsockname(sockfd: fd_t, noalias addr: *sockaddr, noalias addrlen: *socklen_t) c_int;131pub extern "c" fn getsockname(sockfd: fd_t, noalias addr: *sockaddr, noalias addrlen: *socklen_t) c_int;
...@@ -161,12 +153,55 @@ pub extern fn recvfrom(...@@ -161,12 +153,55 @@ pub extern fn recvfrom(
161 noalias addrlen: ?*socklen_t,153 noalias addrlen: ?*socklen_t,
162) isize;154) isize;
163155
156pub usingnamespace switch (builtin.os.tag) {
157 .netbsd => struct {
158 pub const clock_getres = __clock_getres50;
159 pub const clock_gettime = __clock_gettime50;
160 pub const fstat = __fstat50;
161 pub const getdents = __getdents30;
162 pub const getrusage = __getrusage50;
163 pub const gettimeofday = __gettimeofday50;
164 pub const nanosleep = __nanosleep50;
165 pub const sched_yield = __libc_thr_yield;
166 pub const sigaction = __sigaction14;
167 pub const sigaltstack = __sigaltstack14;
168 pub const sigprocmask = __sigprocmask14;
169 pub const stat = __stat50;
170 },
171 .macosx, .ios, .watchos, .tvos => struct {
172 // XXX: close -> close$NOCANCEL
173 // XXX: getdirentries -> _getdirentries64
174 pub extern "c" fn clock_getres(clk_id: c_int, tp: *timespec) c_int;
175 pub extern "c" fn clock_gettime(clk_id: c_int, tp: *timespec) c_int;
176 pub const fstat = @"fstat$INODE64";
177 pub extern "c" fn getrusage(who: c_int, usage: *rusage) c_int;
178 pub extern "c" fn gettimeofday(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int;
179 pub extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int;
180 pub extern "c" fn sched_yield() c_int;
181 pub extern "c" fn sigaction(sig: c_int, noalias act: *const Sigaction, noalias oact: ?*Sigaction) c_int;
182 pub extern "c" fn sigprocmask(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*sigset_t) c_int;
183 pub extern "c" fn socket(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int;
184 pub extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *Stat) c_int;
185 },
186 else => struct {
187 pub extern "c" fn clock_getres(clk_id: c_int, tp: *timespec) c_int;
188 pub extern "c" fn clock_gettime(clk_id: c_int, tp: *timespec) c_int;
189 pub extern "c" fn fstat(fd: fd_t, buf: *Stat) c_int;
190 pub extern "c" fn getrusage(who: c_int, usage: *rusage) c_int;
191 pub extern "c" fn gettimeofday(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int;
192 pub extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int;
193 pub extern "c" fn sched_yield() c_int;
194 pub extern "c" fn sigaction(sig: c_int, noalias act: *const Sigaction, noalias oact: ?*Sigaction) c_int;
195 pub extern "c" fn sigprocmask(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*sigset_t) c_int;
196 pub extern "c" fn socket(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int;
197 pub extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *Stat) c_int;
198 },
199};
200
164pub extern "c" fn kill(pid: pid_t, sig: c_int) c_int;201pub extern "c" fn kill(pid: pid_t, sig: c_int) c_int;
165pub extern "c" fn getdirentries(fd: fd_t, buf_ptr: [*]u8, nbytes: usize, basep: *i64) isize;202pub extern "c" fn getdirentries(fd: fd_t, buf_ptr: [*]u8, nbytes: usize, basep: *i64) isize;
166pub extern "c" fn setgid(ruid: c_uint, euid: c_uint) c_int;203pub extern "c" fn setgid(ruid: c_uint, euid: c_uint) c_int;
167pub extern "c" fn setuid(uid: c_uint) c_int;204pub extern "c" fn setuid(uid: c_uint) c_int;
168pub extern "c" fn clock_gettime(clk_id: c_int, tp: *timespec) c_int;
169pub extern "c" fn clock_getres(clk_id: c_int, tp: *timespec) c_int;
170205
171pub extern "c" fn aligned_alloc(alignment: usize, size: usize) ?*c_void;206pub extern "c" fn aligned_alloc(alignment: usize, size: usize) ?*c_void;
172pub extern "c" fn malloc(usize) ?*c_void;207pub extern "c" fn malloc(usize) ?*c_void;
...@@ -229,8 +264,6 @@ pub extern "c" fn dn_expand(...@@ -229,8 +264,6 @@ pub extern "c" fn dn_expand(
229 length: c_int,264 length: c_int,
230) c_int;265) c_int;
231266
232pub extern "c" fn sched_yield() c_int;
233
234pub const PTHREAD_MUTEX_INITIALIZER = pthread_mutex_t{};267pub const PTHREAD_MUTEX_INITIALIZER = pthread_mutex_t{};
235pub extern "c" fn pthread_mutex_lock(mutex: *pthread_mutex_t) c_int;268pub extern "c" fn pthread_mutex_lock(mutex: *pthread_mutex_t) c_int;
236pub extern "c" fn pthread_mutex_unlock(mutex: *pthread_mutex_t) c_int;269pub extern "c" fn pthread_mutex_unlock(mutex: *pthread_mutex_t) c_int;
lib/std/c/netbsd.zig+33-11
...@@ -10,36 +10,58 @@ pub const dl_iterate_phdr_callback = extern fn (info: *dl_phdr_info, size: usize...@@ -10,36 +10,58 @@ pub const dl_iterate_phdr_callback = extern fn (info: *dl_phdr_info, size: usize
10pub extern "c" fn dl_iterate_phdr(callback: dl_iterate_phdr_callback, data: ?*c_void) c_int;10pub extern "c" fn dl_iterate_phdr(callback: dl_iterate_phdr_callback, data: ?*c_void) c_int;
1111
12pub extern "c" fn __fstat50(fd: fd_t, buf: *Stat) c_int;12pub extern "c" fn __fstat50(fd: fd_t, buf: *Stat) c_int;
13pub extern "c" fn __stat50(path: [*:0]const u8, buf: *Stat) c_int;
13pub extern "c" fn __clock_gettime50(clk_id: c_int, tp: *timespec) c_int;14pub extern "c" fn __clock_gettime50(clk_id: c_int, tp: *timespec) c_int;
14pub extern "c" fn __clock_getres50(clk_id: c_int, tp: *timespec) c_int;15pub extern "c" fn __clock_getres50(clk_id: c_int, tp: *timespec) c_int;
15pub extern "c" fn __getdents30(fd: c_int, buf_ptr: [*]u8, nbytes: usize) c_int;16pub extern "c" fn __getdents30(fd: c_int, buf_ptr: [*]u8, nbytes: usize) c_int;
16pub extern "c" fn __sigaltstack14(ss: ?*stack_t, old_ss: ?*stack_t) c_int;17pub extern "c" fn __sigaltstack14(ss: ?*stack_t, old_ss: ?*stack_t) c_int;
18pub extern "c" fn __nanosleep50(rqtp: *const timespec, rmtp: ?*timespec) c_int;
19pub extern "c" fn __sigaction14(sig: c_int, noalias act: *const Sigaction, noalias oact: ?*Sigaction) c_int;
20pub extern "c" fn __sigprocmask14(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*sigset_t) c_int;
21pub extern "c" fn __socket30(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int;
22pub extern "c" fn __gettimeofday50(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int;
23pub extern "c" fn __getrusage50(who: c_int, usage: *rusage) c_int;
24// libc aliases this as sched_yield
25pub extern "c" fn __libc_thr_yield() c_int;
1726
18pub const pthread_mutex_t = extern struct {27pub const pthread_mutex_t = extern struct {
19 ptm_magic: c_uint = 0x33330003,28 ptm_magic: u32 = 0x33330003,
20 ptm_errorcheck: padded_spin_t = 0,29 ptm_errorcheck: padded_pthread_spin_t = 0,
21 ptm_unused: padded_spin_t = 0,30 ptm_ceiling: padded_pthread_spin_t = 0,
22 ptm_owner: usize = 0,31 ptm_owner: usize = 0,
23 ptm_waiters: ?*u8 = null,32 ptm_waiters: ?*u8 = null,
24 ptm_recursed: c_uint = 0,33 ptm_recursed: u32 = 0,
25 ptm_spare2: ?*c_void = null,34 ptm_spare2: ?*c_void = null,
26};35};
36
27pub const pthread_cond_t = extern struct {37pub const pthread_cond_t = extern struct {
28 ptc_magic: c_uint = 0x55550005,38 ptc_magic: u32 = 0x55550005,
29 ptc_lock: pthread_spin_t = 0,39 ptc_lock: pthread_spin_t = 0,
30 ptc_waiters_first: ?*u8 = null,40 ptc_waiters_first: ?*u8 = null,
31 ptc_waiters_last: ?*u8 = null,41 ptc_waiters_last: ?*u8 = null,
32 ptc_mutex: ?*pthread_mutex_t = null,42 ptc_mutex: ?*pthread_mutex_t = null,
33 ptc_private: ?*c_void = null,43 ptc_private: ?*c_void = null,
34};44};
35const pthread_spin_t = if (builtin.arch == .arm or .arch == .powerpc) c_int else u8;45
36const padded_spin_t = switch (builtin.arch) {46const pthread_spin_t = switch (builtin.arch) {
37 .sparc, .sparcel, .sparcv9, .i386, .x86_64, .le64 => u32,47 .aarch64, .aarch64_be, .aarch64_32 => u8,
38 else => spin_t,48 .mips, .mipsel, .mips64, .mips64el => u32,
49 .powerpc, .powerpc64, .powerpc64le => i32,
50 .i386, .x86_64 => u8,
51 .arm, .armeb, .thumb, .thumbeb => i32,
52 .sparc, .sparcel, .sparcv9 => u8,
53 .riscv32, .riscv64 => u32,
54 else => @compileError("undefined pthread_spin_t for this arch"),
55};
56
57const padded_pthread_spin_t = switch (builtin.arch) {
58 .i386, .x86_64 => u32,
59 .sparc, .sparcel, .sparcv9 => u32,
60 else => pthread_spin_t,
39};61};
4062
41pub const pthread_attr_t = extern struct {63pub const pthread_attr_t = extern struct {
42 pta_magic: u32,64 pta_magic: u32,
43 pta_flags: c_int,65 pta_flags: i32,
44 pta_private: *c_void,66 pta_private: ?*c_void,
45};67};
lib/std/debug.zig+11-3
...@@ -1666,7 +1666,11 @@ fn getDebugInfoAllocator() *mem.Allocator {...@@ -1666,7 +1666,11 @@ fn getDebugInfoAllocator() *mem.Allocator {
1666}1666}
16671667
1668/// Whether or not the current target can print useful debug information when a segfault occurs.1668/// Whether or not the current target can print useful debug information when a segfault occurs.
1669pub const have_segfault_handling_support = builtin.os.tag == .linux or builtin.os.tag == .windows;1669pub const have_segfault_handling_support = switch (builtin.os.tag) {
1670 .linux, .netbsd => true,
1671 .windows => true,
1672 else => false,
1673};
1670pub const enable_segfault_handler: bool = if (@hasDecl(root, "enable_segfault_handler"))1674pub const enable_segfault_handler: bool = if (@hasDecl(root, "enable_segfault_handler"))
1671 root.enable_segfault_handler1675 root.enable_segfault_handler
1672else1676else
...@@ -1718,13 +1722,17 @@ fn resetSegfaultHandler() void {...@@ -1718,13 +1722,17 @@ fn resetSegfaultHandler() void {
1718 os.sigaction(os.SIGBUS, &act, null);1722 os.sigaction(os.SIGBUS, &act, null);
1719}1723}
17201724
1721fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: *const c_void) callconv(.C) noreturn {1725fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const c_void) callconv(.C) noreturn {
1722 // Reset to the default handler so that if a segfault happens in this handler it will crash1726 // Reset to the default handler so that if a segfault happens in this handler it will crash
1723 // the process. Also when this handler returns, the original instruction will be repeated1727 // the process. Also when this handler returns, the original instruction will be repeated
1724 // and the resulting segfault will crash the process rather than continually dump stack traces.1728 // and the resulting segfault will crash the process rather than continually dump stack traces.
1725 resetSegfaultHandler();1729 resetSegfaultHandler();
17261730
1727 const addr = @ptrToInt(info.fields.sigfault.addr);1731 const addr = switch (builtin.os.tag) {
1732 .linux => @ptrToInt(info.fields.sigfault.addr),
1733 .netbsd => @ptrToInt(info.info.reason.fault.addr),
1734 else => unreachable,
1735 };
1728 switch (sig) {1736 switch (sig) {
1729 os.SIGSEGV => std.debug.warn("Segmentation fault at address 0x{x}\n", .{addr}),1737 os.SIGSEGV => std.debug.warn("Segmentation fault at address 0x{x}\n", .{addr}),
1730 os.SIGILL => std.debug.warn("Illegal instruction at address 0x{x}\n", .{addr}),1738 os.SIGILL => std.debug.warn("Illegal instruction at address 0x{x}\n", .{addr}),
lib/std/os.zig+4-26
...@@ -2553,14 +2553,7 @@ pub const FStatError = error{...@@ -2553,14 +2553,7 @@ pub const FStatError = error{
2553pub fn fstat(fd: fd_t) FStatError!Stat {2553pub fn fstat(fd: fd_t) FStatError!Stat {
2554 var stat: Stat = undefined;2554 var stat: Stat = undefined;
25552555
2556 const symbol_name = if (comptime std.Target.current.isDarwin())2556 switch (errno(system.fstat(fd, &stat))) {
2557 "fstat$INODE64"
2558 else if (std.Target.current.os.tag == .netbsd)
2559 "__fstat50"
2560 else
2561 "fstat";
2562
2563 switch (errno(@field(system, symbol_name)(fd, &stat))) {
2564 0 => return stat,2557 0 => return stat,
2565 EINVAL => unreachable,2558 EINVAL => unreachable,
2566 EBADF => unreachable, // Always a race condition.2559 EBADF => unreachable, // Always a race condition.
...@@ -3427,12 +3420,7 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) ClockGetTimeError!void {...@@ -3427,12 +3420,7 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) ClockGetTimeError!void {
3427 return;3420 return;
3428 }3421 }
34293422
3430 const symbol_name = if (std.Target.current.os.tag == .netbsd)3423 switch (errno(system.clock_gettime(clk_id, tp))) {
3431 "__clock_gettime50"
3432 else
3433 "clock_gettime";
3434
3435 switch (errno(@field(system, symbol_name)(clk_id, tp))) {
3436 0 => return,3424 0 => return,
3437 EFAULT => unreachable,3425 EFAULT => unreachable,
3438 EINVAL => return error.UnsupportedClock,3426 EINVAL => return error.UnsupportedClock,
...@@ -3454,12 +3442,7 @@ pub fn clock_getres(clk_id: i32, res: *timespec) ClockGetTimeError!void {...@@ -3454,12 +3442,7 @@ pub fn clock_getres(clk_id: i32, res: *timespec) ClockGetTimeError!void {
3454 return;3442 return;
3455 }3443 }
34563444
3457 const symbol_name = if (std.Target.current.os.tag == .netbsd)3445 switch (errno(system.clock_getres(clk_id, res))) {
3458 "__clock_getres50"
3459 else
3460 "clock_getres";
3461
3462 switch (errno(@field(system, symbol_name)(clk_id, res))) {
3463 0 => return,3446 0 => return,
3464 EFAULT => unreachable,3447 EFAULT => unreachable,
3465 EINVAL => return error.UnsupportedClock,3448 EINVAL => return error.UnsupportedClock,
...@@ -3525,12 +3508,7 @@ pub const SigaltstackError = error{...@@ -3525,12 +3508,7 @@ pub const SigaltstackError = error{
3525} || UnexpectedError;3508} || UnexpectedError;
35263509
3527pub fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) SigaltstackError!void {3510pub fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) SigaltstackError!void {
3528 const symbol_name = if (std.Target.current.os.tag == .netbsd)3511 switch (errno(system.sigaltstack(ss, old_ss))) {
3529 "__sigaltstack14"
3530 else
3531 "sigaltstack";
3532
3533 switch (errno(@field(system, symbol_name)(ss, old_ss))) {
3534 0 => return,3512 0 => return,
3535 EFAULT => unreachable,3513 EFAULT => unreachable,
3536 EINVAL => unreachable,3514 EINVAL => unreachable,
lib/std/os/bits/linux.zig+8-6
...@@ -813,13 +813,13 @@ pub const app_mask: sigset_t = [2]u32{ 0xfffffffc, 0x7fffffff } ++ [_]u32{0xffff...@@ -813,13 +813,13 @@ pub const app_mask: sigset_t = [2]u32{ 0xfffffffc, 0x7fffffff } ++ [_]u32{0xffff
813pub const k_sigaction = if (is_mips)813pub const k_sigaction = if (is_mips)
814 extern struct {814 extern struct {
815 flags: usize,815 flags: usize,
816 sigaction: ?extern fn (i32, *siginfo_t, *c_void) void,816 sigaction: ?extern fn (i32, *siginfo_t, ?*c_void) void,
817 mask: [4]u32,817 mask: [4]u32,
818 restorer: extern fn () void,818 restorer: extern fn () void,
819 }819 }
820else820else
821 extern struct {821 extern struct {
822 sigaction: ?extern fn (i32, *siginfo_t, *c_void) void,822 sigaction: ?extern fn (i32, *siginfo_t, ?*c_void) void,
823 flags: usize,823 flags: usize,
824 restorer: extern fn () void,824 restorer: extern fn () void,
825 mask: [2]u32,825 mask: [2]u32,
...@@ -827,15 +827,17 @@ else...@@ -827,15 +827,17 @@ else
827827
828/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.828/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
829pub const Sigaction = extern struct {829pub const Sigaction = extern struct {
830 sigaction: ?extern fn (i32, *siginfo_t, *c_void) void,830 pub const sigaction_fn = fn (i32, *siginfo_t, ?*c_void) callconv(.C) void;
831 sigaction: ?sigaction_fn,
831 mask: sigset_t,832 mask: sigset_t,
832 flags: u32,833 flags: u32,
833 restorer: ?extern fn () void = null,834 restorer: ?extern fn () void = null,
834};835};
835836
836pub const SIG_ERR = @intToPtr(extern fn (i32, *siginfo_t, *c_void) void, maxInt(usize));837pub const SIG_ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize));
837pub const SIG_DFL = @intToPtr(?extern fn (i32, *siginfo_t, *c_void) void, 0);838pub const SIG_DFL = @intToPtr(?Sigaction.sigaction_fn, 0);
838pub const SIG_IGN = @intToPtr(extern fn (i32, *siginfo_t, *c_void) void, 1);839pub const SIG_IGN = @intToPtr(?Sigaction.sigaction_fn, 1);
840
839pub const empty_sigset = [_]u32{0} ** sigset_t.len;841pub const empty_sigset = [_]u32{0} ** sigset_t.len;
840842
841pub const in_port_t = u16;843pub const in_port_t = u16;
lib/std/os/bits/netbsd.zig+114-26
...@@ -1,12 +1,22 @@...@@ -1,12 +1,22 @@
1const std = @import("../../std.zig");1const std = @import("../../std.zig");
2const builtin = std.builtin;
2const maxInt = std.math.maxInt;3const maxInt = std.math.maxInt;
34
5pub const blkcnt_t = i64;
6pub const blksize_t = i32;
7pub const clock_t = u32;
8pub const dev_t = u64;
4pub const fd_t = i32;9pub const fd_t = i32;
5pub const pid_t = i32;10pub const gid_t = u32;
6pub const mode_t = u32;
7pub const ino_t = u64;11pub const ino_t = u64;
12pub const mode_t = u32;
13pub const nlink_t = u32;
8pub const off_t = i64;14pub const off_t = i64;
15pub const pid_t = i32;
9pub const socklen_t = u32;16pub const socklen_t = u32;
17pub const time_t = i64;
18pub const uid_t = u32;
19pub const lwpid_t = i32;
1020
11/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.21/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.
12pub const Kevent = extern struct {22pub const Kevent = extern struct {
...@@ -137,23 +147,20 @@ pub const msghdr_const = extern struct {...@@ -137,23 +147,20 @@ pub const msghdr_const = extern struct {
137/// in C, macros are used to hide the differences. Here we use147/// in C, macros are used to hide the differences. Here we use
138/// methods to accomplish this.148/// methods to accomplish this.
139pub const Stat = extern struct {149pub const Stat = extern struct {
140 dev: u64,150 dev: dev_t,
141 mode: u32,151 mode: mode_t,
142 ino: ino_t,152 ino: ino_t,
143 nlink: usize,153 nlink: nlink_t,
144154 uid: uid_t,
145 uid: u32,155 gid: gid_t,
146 gid: u32,156 rdev: dev_t,
147 rdev: u64,
148
149 atim: timespec,157 atim: timespec,
150 mtim: timespec,158 mtim: timespec,
151 ctim: timespec,159 ctim: timespec,
152 birthtim: timespec,160 birthtim: timespec,
153
154 size: off_t,161 size: off_t,
155 blocks: i64,162 blocks: blkcnt_t,
156 blksize: isize,163 blksize: blksize_t,
157 flags: u32,164 flags: u32,
158 gen: u32,165 gen: u32,
159 __spare: [2]u32,166 __spare: [2]u32,
...@@ -176,12 +183,14 @@ pub const timespec = extern struct {...@@ -176,12 +183,14 @@ pub const timespec = extern struct {
176 tv_nsec: isize,183 tv_nsec: isize,
177};184};
178185
186pub const MAXNAMLEN = 511;
187
179pub const dirent = extern struct {188pub const dirent = extern struct {
180 d_fileno: u64,189 d_fileno: ino_t,
181 d_reclen: u16,190 d_reclen: u16,
182 d_namlen: u16,191 d_namlen: u16,
183 d_type: u8,192 d_type: u8,
184 d_name: [512]u8,193 d_name: [MAXNAMLEN:0]u8,
185194
186 pub fn reclen(self: dirent) u16 {195 pub fn reclen(self: dirent) u16 {
187 return self.d_reclen;196 return self.d_reclen;
...@@ -685,23 +694,74 @@ pub const winsize = extern struct {...@@ -685,23 +694,74 @@ pub const winsize = extern struct {
685694
686const NSIG = 32;695const NSIG = 32;
687696
688pub const SIG_ERR = @intToPtr(extern fn (i32) void, maxInt(usize));697pub const SIG_ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize));
689pub const SIG_DFL = @intToPtr(extern fn (i32) void, 0);698pub const SIG_DFL = @intToPtr(?Sigaction.sigaction_fn, 0);
690pub const SIG_IGN = @intToPtr(extern fn (i32) void, 1);699pub const SIG_IGN = @intToPtr(?Sigaction.sigaction_fn, 1);
691700
692/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.701/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
693pub const Sigaction = extern struct {702pub const Sigaction = extern struct {
703 pub const sigaction_fn = fn (i32, *siginfo_t, ?*c_void) callconv(.C) void;
694 /// signal handler704 /// signal handler
695 __sigaction_u: extern union {705 sigaction: ?sigaction_fn,
696 __sa_handler: extern fn (i32) void,706 /// signal mask to apply
697 __sa_sigaction: extern fn (i32, *__siginfo, usize) void,707 mask: sigset_t,
698 },708 /// signal options
709 flags: u32,
710};
699711
700 /// see signal options712pub const sigval_t = extern union {
701 sa_flags: u32,713 int: i32,
714 ptr: ?*c_void,
715};
702716
703 /// signal mask to apply717pub const siginfo_t = extern union {
704 sa_mask: sigset_t,718 pad: [128]u8,
719 info: _ksiginfo,
720};
721
722pub const _ksiginfo = extern struct {
723 signo: i32,
724 code: i32,
725 errno: i32,
726 // 64bit architectures insert 4bytes of padding here, this is done by
727 // correctly aligning the reason field
728 reason: extern union {
729 rt: extern struct {
730 pid: pid_t,
731 uid: uid_t,
732 value: sigval_t,
733 },
734 child: extern struct {
735 pid: pid_t,
736 uid: uid_t,
737 status: i32,
738 utime: clock_t,
739 stime: clock_t,
740 },
741 fault: extern struct {
742 addr: ?*c_void,
743 trap: i32,
744 trap2: i32,
745 trap3: i32,
746 },
747 poll: extern struct {
748 band: i32,
749 fd: i32,
750 },
751 syscall: extern struct {
752 sysnum: i32,
753 retval: [2]i32,
754 @"error": i32,
755 args: [8]u64,
756 },
757 ptrace_state: extern struct {
758 pe_report_event: i32,
759 option: extern union {
760 pe_other_pid: pid_t,
761 pe_lwp: lwpid_t,
762 },
763 },
764 } align(@sizeOf(usize)),
705};765};
706766
707pub const _SIG_WORDS = 4;767pub const _SIG_WORDS = 4;
...@@ -724,6 +784,34 @@ pub const sigset_t = extern struct {...@@ -724,6 +784,34 @@ pub const sigset_t = extern struct {
724 __bits: [_SIG_WORDS]u32,784 __bits: [_SIG_WORDS]u32,
725};785};
726786
787pub const empty_sigset = sigset_t{ .__bits = [_]u32{0} ** _SIG_WORDS };
788
789// XXX x86_64 specific
790pub const mcontext_t = extern struct {
791 gregs: [26]u64,
792 mc_tlsbase: u64,
793 fpregs: [512]u8 align(8),
794};
795
796pub const REG_RBP = 12;
797pub const REG_RIP = 21;
798pub const REG_RSP = 24;
799
800pub const ucontext_t = extern struct {
801 flags: u32,
802 link: ?*ucontext_t,
803 sigmask: sigset_t,
804 stack: stack_t,
805 mcontext: mcontext_t,
806 __pad: [switch (builtin.arch) {
807 .i386 => 4,
808 .mips, .mipsel, .mips64, .mips64el => 14,
809 .arm, .armeb, .thumb, .thumbeb => 1,
810 .sparc, .sparcel, .sparcv9 => if (@sizeOf(usize) == 4) 43 else 8,
811 else => 0,
812 }]u32,
813};
814
727pub const EPERM = 1; // Operation not permitted815pub const EPERM = 1; // Operation not permitted
728pub const ENOENT = 2; // No such file or directory816pub const ENOENT = 2; // No such file or directory
729pub const ESRCH = 3; // No such process817pub const ESRCH = 3; // No such process