| author | |
| committer | |
| log | 399e026cc00af430df66d3d4b77a12fd775973cd |
| tree | 1d39ac9f12c3b0f752317a936f990eb902555da2 |
| parent | bcdbd8d1697725992cb08eb1c3c59bd63fda6dc7 |
4 files changed, 38 insertions(+), 9 deletions(-)
std/os.zig+23| ... | ... | @@ -2433,6 +2433,29 @@ pub fn unexpectedErrno(err: usize) UnexpectedError { |
| 2433 | 2433 | return error.Unexpected; |
| 2434 | 2434 | } |
| 2435 | 2435 | |
| 2436 | pub const SigaltstackError = error{ | |
| 2437 | /// The supplied stack size was less than MINSIGSTKSZ. | |
| 2438 | SizeTooSmall, | |
| 2439 | ||
| 2440 | /// Attempted to change the signal stack while it was active. | |
| 2441 | PermissionDenied, | |
| 2442 | Unexpected, | |
| 2443 | }; | |
| 2444 | ||
| 2445 | pub fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) SigaltstackError!void { | |
| 2446 | if (windows.is_the_target or uefi.is_the_target or wasi.is_the_target) | |
| 2447 | @compileError("std.os.sigaltstack not available for this target"); | |
| 2448 | ||
| 2449 | switch (errno(system.sigaltstack(ss, old_ss))) { | |
| 2450 | 0 => return, | |
| 2451 | EFAULT => unreachable, | |
| 2452 | EINVAL => unreachable, | |
| 2453 | ENOMEM => return error.SizeTooSmall, | |
| 2454 | EPERM => return error.PermissionDenied, | |
| 2455 | else => |err| return unexpectedErrno(err), | |
| 2456 | } | |
| 2457 | } | |
| 2458 | ||
| 2436 | 2459 | test "" { |
| 2437 | 2460 | _ = @import("os/darwin.zig"); |
| 2438 | 2461 | _ = @import("os/freebsd.zig"); |
std/os/linux/test.zig-9| ... | ... | @@ -83,12 +83,3 @@ 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 | } |
std/os/test.zig+11| ... | ... | @@ -149,3 +149,14 @@ test "realpath" { |
| 149 | 149 | var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; |
| 150 | 150 | testing.expectError(error.FileNotFound, fs.realpath("definitely_bogus_does_not_exist1234", &buf)); |
| 151 | 151 | } |
| 152 | ||
| 153 | test "sigaltstack" { | |
| 154 | if (builtin.os == .windows or builtin.os == .wasi) return error.SkipZigTest; | |
| 155 | ||
| 156 | var st: os.stack_t = undefined; | |
| 157 | try os.sigaltstack(null, &st); | |
| 158 | // Setting a stack size less than MINSIGSTKSZ returns ENOMEM | |
| 159 | st.ss_flags = 0; | |
| 160 | st.ss_size = 1; | |
| 161 | testing.expectError(error.SizeTooSmall, os.sigaltstack(&st, null)); | |
| 162 | } |
std/os/uefi.zig+4| ... | ... | @@ -1,2 +1,6 @@ |
| 1 | 1 | // TODO this is where the extern declarations go. For example, see |
| 2 | 2 | // inc/efilib.h in gnu-efi-code |
| 3 | ||
| 4 | const builtin = @import("builtin"); | |
| 5 | ||
| 6 | pub const is_the_target = builtin.os == .uefi; |