mirror of
https://github.com/fluencelabs/musl
synced 2025-06-02 17:41:37 +00:00
fix race condition in rsyscall handler
the problem: there is a (single-instruction) race condition window between a thread flagging itself dead and decrementing itself from the thread count. if it receives the rsyscall signal at this exact moment, the rsyscall caller will never succeed in signalling enough flags to succeed, and will deadlock forever. in previous versions of musl, the about-to-terminate thread masked all signals prior to decrementing the thread count, but this cost a whole syscall just to account for extremely rare races. the solution is a huge hack: rather than blocking in the signal handler if the thread is dead, modify the signal mask of the saved context and return in order to prevent further signal handling by the dead thread. this allows the dead thread to continue decrementing the thread count (if it had not yet done so) and exiting, even while the live part of the program blocks for rsyscall.
This commit is contained in:
parent
c9b2d8016f
commit
1ad049b7b6
@ -85,7 +85,7 @@ static void rsyscall_handler(int sig, siginfo_t *si, void *ctx)
|
||||
/* Threads which have already decremented themselves from the
|
||||
* thread count must not increment rs.cnt or otherwise act. */
|
||||
if (self->dead) {
|
||||
__wait(&rs.hold, 0, 1, 1);
|
||||
sigaddset(&((ucontext_t *)ctx)->uc_sigmask, SIGSYSCALL);
|
||||
return;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user