| author | |
| committer | |
| log | 070ace4b22810116f7816eeccbc1ce600be5b2a2 |
| tree | 28a88e7a1aa8567d3549c4a92548ec9e11dd23cf |
| parent | a5af78c376fc41424b81ea83766b38a0a1d17870 |
Fix some more libc definitions.4 files changed, 160 insertions(+), 42 deletions(-)
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 |
| 10 | pub extern "c" fn dl_iterate_phdr(callback: dl_iterate_phdr_callback, data: ?*c_void) c_int; | 10 | pub extern "c" fn dl_iterate_phdr(callback: dl_iterate_phdr_callback, data: ?*c_void) c_int; |
| 11 | 11 | ||
| 12 | pub extern "c" fn __fstat50(fd: fd_t, buf: *Stat) c_int; | 12 | pub extern "c" fn __fstat50(fd: fd_t, buf: *Stat) c_int; |
| 13 | pub extern "c" fn __stat50(path: [*:0]const u8, buf: *Stat) c_int; | ||
| 13 | pub extern "c" fn __clock_gettime50(clk_id: c_int, tp: *timespec) c_int; | 14 | pub extern "c" fn __clock_gettime50(clk_id: c_int, tp: *timespec) c_int; |
| 14 | pub extern "c" fn __clock_getres50(clk_id: c_int, tp: *timespec) c_int; | 15 | pub extern "c" fn __clock_getres50(clk_id: c_int, tp: *timespec) c_int; |
| 15 | pub extern "c" fn __getdents30(fd: c_int, buf_ptr: [*]u8, nbytes: usize) c_int; | 16 | pub extern "c" fn __getdents30(fd: c_int, buf_ptr: [*]u8, nbytes: usize) c_int; |
| 16 | pub extern "c" fn __sigaltstack14(ss: ?*stack_t, old_ss: ?*stack_t) c_int; | 17 | pub extern "c" fn __sigaltstack14(ss: ?*stack_t, old_ss: ?*stack_t) c_int; |
| 18 | pub extern "c" fn __nanosleep50(rqtp: *const timespec, rmtp: ?*timespec) c_int; | ||
| 19 | pub extern "c" fn __sigaction14(sig: c_int, noalias act: *const Sigaction, noalias oact: ?*Sigaction) c_int; | ||
| 20 | pub extern "c" fn __sigprocmask14(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*sigset_t) c_int; | ||
| 21 | pub extern "c" fn __socket30(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int; | ||
| 22 | pub extern "c" fn __gettimeofday50(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int; | ||
| 23 | pub extern "c" fn __getrusage50(who: c_int, usage: *rusage) c_int; | ||
| 24 | // instead of sched_yield | ||
| 25 | pub extern "c" fn __libc_thr_yield() c_int; | ||
| 17 | 26 | ||
| 18 | pub const pthread_mutex_t = extern struct { | 27 | pub 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 | |||
| 27 | pub const pthread_cond_t = extern struct { | 37 | pub 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 | }; |
| 35 | const pthread_spin_t = if (builtin.arch == .arm or .arch == .powerpc) c_int else u8; | 45 | |
| 36 | const padded_spin_t = switch (builtin.arch) { | 46 | const 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 | |||
| 57 | const padded_pthread_spin_t = switch (builtin.arch) { | ||
| 58 | .i386, .x86_64 => u32, | ||
| 59 | .sparc, .sparcel, .sparcv9 => u32, | ||
| 60 | else => pthread_spin_t, | ||
| 39 | }; | 61 | }; |
| 40 | 62 | ||
| 41 | pub const pthread_attr_t = extern struct { | 63 | pub 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 | } |
| 1667 | 1667 | ||
| 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. |
| 1669 | pub const have_segfault_handling_support = builtin.os.tag == .linux or builtin.os.tag == .windows; | 1669 | pub const have_segfault_handling_support = switch (builtin.os.tag) { |
| 1670 | .linux, .netbsd => true, | ||
| 1671 | .windows => true, | ||
| 1672 | else => false, | ||
| 1673 | }; | ||
| 1670 | pub const enable_segfault_handler: bool = if (@hasDecl(root, "enable_segfault_handler")) | 1674 | pub const enable_segfault_handler: bool = if (@hasDecl(root, "enable_segfault_handler")) |
| 1671 | root.enable_segfault_handler | 1675 | root.enable_segfault_handler |
| 1672 | else | 1676 | else |
| ... | @@ -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 | } |
| 1720 | 1724 | ||
| 1721 | fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: *const c_void) callconv(.C) noreturn { | 1725 | fn 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 crash | 1726 | // 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 repeated | 1727 | // 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(); |
| 1726 | 1730 | ||
| 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/bits/linux.zig+2-2| ... | @@ -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 |
| 813 | pub const k_sigaction = if (is_mips) | 813 | pub 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 | } |
| 820 | else | 820 | else |
| 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, |
lib/std/os/bits/netbsd.zig+114-26| ... | @@ -1,12 +1,22 @@ | ... | @@ -1,12 +1,22 @@ |
| 1 | const std = @import("../../std.zig"); | 1 | const std = @import("../../std.zig"); |
| 2 | const builtin = std.builtin; | ||
| 2 | const maxInt = std.math.maxInt; | 3 | const maxInt = std.math.maxInt; |
| 3 | 4 | ||
| 5 | pub const blkcnt_t = i64; | ||
| 6 | pub const blksize_t = i32; | ||
| 7 | pub const clock_t = u32; | ||
| 8 | pub const dev_t = u64; | ||
| 4 | pub const fd_t = i32; | 9 | pub const fd_t = i32; |
| 5 | pub const pid_t = i32; | 10 | pub const gid_t = u32; |
| 6 | pub const mode_t = u32; | ||
| 7 | pub const ino_t = u64; | 11 | pub const ino_t = u64; |
| 12 | pub const mode_t = u32; | ||
| 13 | pub const nlink_t = u32; | ||
| 8 | pub const off_t = i64; | 14 | pub const off_t = i64; |
| 15 | pub const pid_t = i32; | ||
| 9 | pub const socklen_t = u32; | 16 | pub const socklen_t = u32; |
| 17 | pub const time_t = i64; | ||
| 18 | pub const uid_t = u32; | ||
| 19 | pub const lwpid_t = i32; | ||
| 10 | 20 | ||
| 11 | /// Renamed from `kevent` to `Kevent` to avoid conflict with function name. | 21 | /// Renamed from `kevent` to `Kevent` to avoid conflict with function name. |
| 12 | pub const Kevent = extern struct { | 22 | pub 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 use | 147 | /// in C, macros are used to hide the differences. Here we use |
| 138 | /// methods to accomplish this. | 148 | /// methods to accomplish this. |
| 139 | pub const Stat = extern struct { | 149 | pub 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, |
| 144 | 154 | 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 | }; |
| 178 | 185 | ||
| 186 | pub const MAXNAMLEN = 511; | ||
| 187 | |||
| 179 | pub const dirent = extern struct { | 188 | pub 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, |
| 185 | 194 | ||
| 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 { |
| 685 | 694 | ||
| 686 | const NSIG = 32; | 695 | const NSIG = 32; |
| 687 | 696 | ||
| 688 | pub const SIG_ERR = @intToPtr(extern fn (i32) void, maxInt(usize)); | 697 | pub const SIG_ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize)); |
| 689 | pub const SIG_DFL = @intToPtr(extern fn (i32) void, 0); | 698 | pub const SIG_DFL = @intToPtr(?Sigaction.sigaction_fn, 0); |
| 690 | pub const SIG_IGN = @intToPtr(extern fn (i32) void, 1); | 699 | pub const SIG_IGN = @intToPtr(?Sigaction.sigaction_fn, 1); |
| 691 | 700 | ||
| 692 | /// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. | 701 | /// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. |
| 693 | pub const Sigaction = extern struct { | 702 | pub const Sigaction = extern struct { |
| 703 | pub const sigaction_fn = fn (i32, *siginfo_t, ?*c_void) callconv(.C) void; | ||
| 694 | /// signal handler | 704 | /// 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 | }; | ||
| 699 | 711 | ||
| 700 | /// see signal options | 712 | pub const sigval_t = extern union { |
| 701 | sa_flags: u32, | 713 | int: i32, |
| 714 | ptr: ?*c_void, | ||
| 715 | }; | ||
| 702 | 716 | ||
| 703 | /// signal mask to apply | 717 | pub const siginfo_t = extern union { |
| 704 | sa_mask: sigset_t, | 718 | pad: [128]u8, |
| 719 | info: _ksiginfo, | ||
| 720 | }; | ||
| 721 | |||
| 722 | pub 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 | }; |
| 706 | 766 | ||
| 707 | pub const _SIG_WORDS = 4; | 767 | pub 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 | }; |
| 726 | 786 | ||
| 787 | pub const empty_sigset = sigset_t{ .__bits = [_]u32{0} ** _SIG_WORDS }; | ||
| 788 | |||
| 789 | // XXX x86_64 specific | ||
| 790 | pub const mcontext_t = extern struct { | ||
| 791 | gregs: [26]u64, | ||
| 792 | mc_tlsbase: u64, | ||
| 793 | fpregs: [512]u8 align(8), | ||
| 794 | }; | ||
| 795 | |||
| 796 | pub const REG_RBP = 12; | ||
| 797 | pub const REG_RIP = 21; | ||
| 798 | pub const REG_RSP = 24; | ||
| 799 | |||
| 800 | pub 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 | |||
| 727 | pub const EPERM = 1; // Operation not permitted | 815 | pub const EPERM = 1; // Operation not permitted |
| 728 | pub const ENOENT = 2; // No such file or directory | 816 | pub const ENOENT = 2; // No such file or directory |
| 729 | pub const ESRCH = 3; // No such process | 817 | pub const ESRCH = 3; // No such process |