authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2019-05-28 15:22:19+02:00
committergravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2019-05-28 15:22:19+02:00
logbcdbd8d1697725992cb08eb1c3c59bd63fda6dc7
treef70669bd50dbc98cde112ef14ac18078a56412ae
parentd1b6f29d225bbedd0afb97fce64f5d042df4d9c6

Add sigaltstack syscall


9 files changed, 84 insertions(+), 0 deletions(-)

std/c/freebsd.zig+4
......@@ -1,4 +1,8 @@
1const std = @import("../std.zig");
2use std.c;
3
14extern "c" fn __error() *c_int;
25pub const _errno = __error;
36
47pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) usize;
8pub 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;
2525
2626pub const dl_iterate_phdr_callback = extern fn (info: *dl_phdr_info, size: usize, data: ?*c_void) c_int;
2727pub extern "c" fn dl_iterate_phdr(callback: dl_iterate_phdr_callback, data: ?*c_void) c_int;
28
29pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int;
std/c/netbsd.zig+4
......@@ -1,4 +1,8 @@
1const std = @import("../std.zig");
2use std.c;
3
14extern "c" fn __errno() *c_int;
25pub const _errno = __errno;
36
47pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) usize;
8pub 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;
10781078
10791079/// Must be equal largest errno
10801080pub const ELAST = 106;
1081
1082pub const SIGSTKSZ = 131072;
1083pub const MINSIGSTKSZ = 32768;
1084
1085pub const SS_ONSTACK = 1;
1086pub const SS_DISABLE = 4;
1087
1088pub 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
835835pub const EOWNERDEAD = 96; // Previous owner died
836836
837837pub const ELAST = 96; // Must be equal largest errno
838
839pub const MINSIGSTKSZ = switch (builtin.arch) {
840 .i386, .x86_64 => 2048,
841 .arm, .aarch64 => 4096,
842 else => @compileError("MINSIGSTKSZ not defined for this architecture"),
843};
844pub const SIGSTKSZ = MINSIGSTKSZ + 32768;
845
846pub const SS_ONSTACK = 1;
847pub const SS_DISABLE = 4;
848
849pub 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 {
929929//#define CPU_COUNT(set) CPU_COUNT_S(sizeof(cpu_set_t),set)
930930//#define CPU_ZERO(set) CPU_ZERO_S(sizeof(cpu_set_t),set)
931931//#define CPU_EQUAL(s1,s2) CPU_EQUAL_S(sizeof(cpu_set_t),s1,s2)
932
933pub const MINSIGSTKSZ = switch (builtin.arch) {
934 .i386, .x86_64, .arm => 2048,
935 .aarch64 => 5120,
936 else => @compileError("MINSIGSTKSZ not defined for this architecture"),
937};
938pub 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
944pub const SS_ONSTACK = 1;
945pub const SS_DISABLE = 2;
946pub const SS_AUTODISARM = 1 << 31;
947
948pub 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
723723pub const EPROTO = 96; // Protocol error
724724
725725pub const ELAST = 96; // Must equal largest errno
726
727pub const MINSIGSTKSZ = 8192;
728pub const SIGSTKSZ = MINSIGSTKSZ + 32768;
729
730pub const SS_ONSTACK = 1;
731pub const SS_DISABLE = 4;
732
733pub 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 {
818818 return syscall2(SYS_capset, @ptrToInt(hdrp), @ptrToInt(datap));
819819}
820820
821pub fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) usize {
822 return syscall2(SYS_sigaltstack, @ptrToInt(ss), @ptrToInt(old_ss));
823}
824
821825// XXX: This should be weak
822826extern const __ehdr_start: elf.Ehdr = undefined;
823827
std/os/linux/test.zig+9
......@@ -83,3 +83,12 @@ test "dl_iterate_phdr" {
8383 expect(linux.dl_iterate_phdr(usize, iter_fn, &counter) != 0);
8484 expect(counter != 0);
8585}
86
87test "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}