diff options
| author | LemonBoy <thatlemon@gmail.com> | 2019-05-29 09:43:39 +0200 |
|---|---|---|
| committer | LemonBoy <thatlemon@gmail.com> | 2019-05-29 22:38:14 +0200 |
| commit | 399e026cc00af430df66d3d4b77a12fd775973cd (patch) | |
| tree | 1d39ac9f12c3b0f752317a936f990eb902555da2 | |
| parent | bcdbd8d1697725992cb08eb1c3c59bd63fda6dc7 (diff) | |
| download | zig-399e026cc00af430df66d3d4b77a12fd775973cd.tar.gz zig-399e026cc00af430df66d3d4b77a12fd775973cd.zip | |
Add sigaltstack wrapper in os.zig
| -rw-r--r-- | std/os.zig | 23 | ||||
| -rw-r--r-- | std/os/linux/test.zig | 9 | ||||
| -rw-r--r-- | std/os/test.zig | 11 | ||||
| -rw-r--r-- | std/os/uefi.zig | 4 |
4 files changed, 38 insertions, 9 deletions
diff --git a/std/os.zig b/std/os.zig index be2be92f7d..a7067c8908 100644 --- a/std/os.zig +++ b/std/os.zig @@ -2433,6 +2433,29 @@ pub fn unexpectedErrno(err: usize) UnexpectedError { return error.Unexpected; } +pub const SigaltstackError = error{ + /// The supplied stack size was less than MINSIGSTKSZ. + SizeTooSmall, + + /// Attempted to change the signal stack while it was active. + PermissionDenied, + Unexpected, +}; + +pub fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) SigaltstackError!void { + if (windows.is_the_target or uefi.is_the_target or wasi.is_the_target) + @compileError("std.os.sigaltstack not available for this target"); + + switch (errno(system.sigaltstack(ss, old_ss))) { + 0 => return, + EFAULT => unreachable, + EINVAL => unreachable, + ENOMEM => return error.SizeTooSmall, + EPERM => return error.PermissionDenied, + else => |err| return unexpectedErrno(err), + } +} + test "" { _ = @import("os/darwin.zig"); _ = @import("os/freebsd.zig"); diff --git a/std/os/linux/test.zig b/std/os/linux/test.zig index 063c10257c..c78b071c74 100644 --- a/std/os/linux/test.zig +++ b/std/os/linux/test.zig @@ -83,12 +83,3 @@ test "dl_iterate_phdr" { expect(linux.dl_iterate_phdr(usize, iter_fn, &counter) != 0); expect(counter != 0); } - -test "sigaltstack" { - var st: linux.stack_t = undefined; - expect(linux.sigaltstack(null, &st) == 0); - // Setting a stack size less than MINSIGSTKSZ returns ENOMEM - st.ss_flags = 0; - st.ss_size = 1; - expect(linux.getErrno(linux.sigaltstack(&st, null)) == linux.ENOMEM); -} diff --git a/std/os/test.zig b/std/os/test.zig index d4d662e97f..dfcd25c4bb 100644 --- a/std/os/test.zig +++ b/std/os/test.zig @@ -149,3 +149,14 @@ test "realpath" { var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; testing.expectError(error.FileNotFound, fs.realpath("definitely_bogus_does_not_exist1234", &buf)); } + +test "sigaltstack" { + if (builtin.os == .windows or builtin.os == .wasi) return error.SkipZigTest; + + var st: os.stack_t = undefined; + try os.sigaltstack(null, &st); + // Setting a stack size less than MINSIGSTKSZ returns ENOMEM + st.ss_flags = 0; + st.ss_size = 1; + testing.expectError(error.SizeTooSmall, os.sigaltstack(&st, null)); +} diff --git a/std/os/uefi.zig b/std/os/uefi.zig index 8ed60d9c9b..7102938d70 100644 --- a/std/os/uefi.zig +++ b/std/os/uefi.zig @@ -1,2 +1,6 @@ // TODO this is where the extern declarations go. For example, see // inc/efilib.h in gnu-efi-code + +const builtin = @import("builtin"); + +pub const is_the_target = builtin.os == .uefi; |
