diff --git a/lib/std/Thread.zig b/lib/std/Thread.zig index 126338e77f0a82eae15042c49a20c3155d677faf..1c361506b72e3eb1a8c6125642b68ba1e6fba51a 100644 --- a/lib/std/Thread.zig +++ b/lib/std/Thread.zig @@ -1224,6 +1224,10 @@ const LinuxThreadImpl = struct { /// Ported over from musl libc's pthread detached implementation: /// https://github.com/ifduyue/musl/search?q=__unmapself fn freeAndExit(self: *ThreadCompletion) noreturn { + // If a signal were delivered between SYS_munmap and SYS_exit, any installed signal + // handler would immediately segfault due to the stack being unmapped. To avoid this, + // we need to mask all signals before entering the inline asm. + posix.sigprocmask(std.posix.SIG.BLOCK, &std.os.linux.sigfillset(), null); switch (target.cpu.arch) { .x86 => asm volatile ( \\ movl $91, %%eax # SYS_munmap