zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit aa832d6a6dbde8a0753d6aa59cc8199b009ea260 (tree)
parent cc65eaf0a982066a8655632c04db11f7c0c5d0ad
Author: Misaki Kasumi <misakikasumi@outlook.com>
Date:   Wed,  2 Apr 2025 18:36:40 +0800

std.os.linux: block all signals in raise

Diffstat:
Mlib/std/posix.zig | 10++++++++++
1 file changed, 10 insertions(+), 0 deletions(-)

diff --git a/lib/std/posix.zig b/lib/std/posix.zig @@ -720,9 +720,19 @@ pub fn raise(sig: u8) RaiseError!void { } if (native_os == .linux) { + // https://git.musl-libc.org/cgit/musl/commit/?id=0bed7e0acfd34e3fb63ca0e4d99b7592571355a9 + // + // Unlike musl, libc-less Zig std does not have any internal signals for implementation purposes, so we + // need to block all signals on the assumption that any of them could potentially fork() in a handler. + var set: sigset_t = undefined; + sigprocmask(SIG.BLOCK, &linux.all_mask, &set); + const tid = linux.gettid(); const rc = linux.tkill(tid, sig); + // restore signal mask + sigprocmask(SIG.SETMASK, &set, null); + switch (errno(rc)) { .SUCCESS => return, else => |err| return unexpectedErrno(err),