| author | |
| committer | |
| log | bcdbd8d1697725992cb08eb1c3c59bd63fda6dc7 |
| tree | f70669bd50dbc98cde112ef14ac18078a56412ae |
| parent | d1b6f29d225bbedd0afb97fce64f5d042df4d9c6 |
9 files changed, 84 insertions(+), 0 deletions(-)
std/c/freebsd.zig+4| ... | ... | @@ -1,4 +1,8 @@ |
| 1 | const std = @import("../std.zig"); | |
| 2 | use std.c; | |
| 3 | ||
| 1 | 4 | extern "c" fn __error() *c_int; |
| 2 | 5 | pub const _errno = __error; |
| 3 | 6 | |
| 4 | 7 | pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) usize; |
| 8 | pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int; |
std/c/linux.zig+2| ... | ... | @@ -25,3 +25,5 @@ pub extern "c" fn getauxval(__type: c_ulong) c_ulong; |
| 25 | 25 | |
| 26 | 26 | pub const dl_iterate_phdr_callback = extern fn (info: *dl_phdr_info, size: usize, data: ?*c_void) c_int; |
| 27 | 27 | pub extern "c" fn dl_iterate_phdr(callback: dl_iterate_phdr_callback, data: ?*c_void) c_int; |
| 28 | ||
| 29 | pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int; |
std/c/netbsd.zig+4| ... | ... | @@ -1,4 +1,8 @@ |
| 1 | const std = @import("../std.zig"); | |
| 2 | use std.c; | |
| 3 | ||
| 1 | 4 | extern "c" fn __errno() *c_int; |
| 2 | 5 | pub const _errno = __errno; |
| 3 | 6 | |
| 4 | 7 | pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) usize; |
| 8 | pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int; |
std/os/bits/darwin.zig+12| ... | ... | @@ -1078,3 +1078,15 @@ pub const EQFULL = 106; |
| 1078 | 1078 | |
| 1079 | 1079 | /// Must be equal largest errno |
| 1080 | 1080 | pub const ELAST = 106; |
| 1081 | ||
| 1082 | pub const SIGSTKSZ = 131072; | |
| 1083 | pub const MINSIGSTKSZ = 32768; | |
| 1084 | ||
| 1085 | pub const SS_ONSTACK = 1; | |
| 1086 | pub const SS_DISABLE = 4; | |
| 1087 | ||
| 1088 | pub const stack_t = extern struct { | |
| 1089 | ss_sp: [*]u8, | |
| 1090 | ss_size: isize, | |
| 1091 | ss_flags: i32, | |
| 1092 | }; |
std/os/bits/freebsd.zig+16| ... | ... | @@ -835,3 +835,19 @@ pub const ENOTRECOVERABLE = 95; // State not recoverable |
| 835 | 835 | pub const EOWNERDEAD = 96; // Previous owner died |
| 836 | 836 | |
| 837 | 837 | pub const ELAST = 96; // Must be equal largest errno |
| 838 | ||
| 839 | pub const MINSIGSTKSZ = switch (builtin.arch) { | |
| 840 | .i386, .x86_64 => 2048, | |
| 841 | .arm, .aarch64 => 4096, | |
| 842 | else => @compileError("MINSIGSTKSZ not defined for this architecture"), | |
| 843 | }; | |
| 844 | pub const SIGSTKSZ = MINSIGSTKSZ + 32768; | |
| 845 | ||
| 846 | pub const SS_ONSTACK = 1; | |
| 847 | pub const SS_DISABLE = 4; | |
| 848 | ||
| 849 | pub const stack_t = extern struct { | |
| 850 | ss_sp: [*]u8, | |
| 851 | ss_size: isize, | |
| 852 | ss_flags: i32, | |
| 853 | }; |
std/os/bits/linux.zig+21| ... | ... | @@ -929,3 +929,24 @@ pub fn CPU_COUNT(set: cpu_set_t) cpu_count_t { |
| 929 | 929 | //#define CPU_COUNT(set) CPU_COUNT_S(sizeof(cpu_set_t),set) |
| 930 | 930 | //#define CPU_ZERO(set) CPU_ZERO_S(sizeof(cpu_set_t),set) |
| 931 | 931 | //#define CPU_EQUAL(s1,s2) CPU_EQUAL_S(sizeof(cpu_set_t),s1,s2) |
| 932 | ||
| 933 | pub const MINSIGSTKSZ = switch (builtin.arch) { | |
| 934 | .i386, .x86_64, .arm => 2048, | |
| 935 | .aarch64 => 5120, | |
| 936 | else => @compileError("MINSIGSTKSZ not defined for this architecture"), | |
| 937 | }; | |
| 938 | pub const SIGSTKSZ = switch (builtin.arch) { | |
| 939 | .i386, .x86_64, .arm => 8192, | |
| 940 | .aarch64 => 16384, | |
| 941 | else => @compileError("SIGSTKSZ not defined for this architecture"), | |
| 942 | }; | |
| 943 | ||
| 944 | pub const SS_ONSTACK = 1; | |
| 945 | pub const SS_DISABLE = 2; | |
| 946 | pub const SS_AUTODISARM = 1 << 31; | |
| 947 | ||
| 948 | pub const stack_t = extern struct { | |
| 949 | ss_sp: [*]u8, | |
| 950 | ss_flags: i32, | |
| 951 | ss_size: isize, | |
| 952 | }; |
std/os/bits/netbsd.zig+12| ... | ... | @@ -723,3 +723,15 @@ pub const ENOLINK = 95; // Link has been severed |
| 723 | 723 | pub const EPROTO = 96; // Protocol error |
| 724 | 724 | |
| 725 | 725 | pub const ELAST = 96; // Must equal largest errno |
| 726 | ||
| 727 | pub const MINSIGSTKSZ = 8192; | |
| 728 | pub const SIGSTKSZ = MINSIGSTKSZ + 32768; | |
| 729 | ||
| 730 | pub const SS_ONSTACK = 1; | |
| 731 | pub const SS_DISABLE = 4; | |
| 732 | ||
| 733 | pub const stack_t = extern struct { | |
| 734 | ss_sp: [*]u8, | |
| 735 | ss_size: isize, | |
| 736 | ss_flags: i32, | |
| 737 | }; |
std/os/linux.zig+4| ... | ... | @@ -818,6 +818,10 @@ pub fn capset(hdrp: *cap_user_header_t, datap: *const cap_user_data_t) usize { |
| 818 | 818 | return syscall2(SYS_capset, @ptrToInt(hdrp), @ptrToInt(datap)); |
| 819 | 819 | } |
| 820 | 820 | |
| 821 | pub fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) usize { | |
| 822 | return syscall2(SYS_sigaltstack, @ptrToInt(ss), @ptrToInt(old_ss)); | |
| 823 | } | |
| 824 | ||
| 821 | 825 | // XXX: This should be weak |
| 822 | 826 | extern const __ehdr_start: elf.Ehdr = undefined; |
| 823 | 827 |
std/os/linux/test.zig+9| ... | ... | @@ -83,3 +83,12 @@ test "dl_iterate_phdr" { |
| 83 | 83 | expect(linux.dl_iterate_phdr(usize, iter_fn, &counter) != 0); |
| 84 | 84 | expect(counter != 0); |
| 85 | 85 | } |
| 86 | ||
| 87 | test "sigaltstack" { | |
| 88 | var st: linux.stack_t = undefined; | |
| 89 | expect(linux.sigaltstack(null, &st) == 0); | |
| 90 | // Setting a stack size less than MINSIGSTKSZ returns ENOMEM | |
| 91 | st.ss_flags = 0; | |
| 92 | st.ss_size = 1; | |
| 93 | expect(linux.getErrno(linux.sigaltstack(&st, null)) == linux.ENOMEM); | |
| 94 | } |