Commit df6d452
authored
Block signals when freeing the stack for a detached thread (#126)
When a detached thread exits, it frees its own stack, creating a window
between the time when the stack is freed and the thread exits. If a
signal is delivered to the thread in that window, it will attempt to
run on the freed stack.
To avoid this hazard, use `rustix::runtime::sigprocmask` to block
all signals on the thread before freeing the stack. This causes all
process-directed signals to be delivered to a different thread in
the process.
A slight infelicity is that thread-directed symbols directed at the
detached thread that arrive during this time will be silently ignored.
However, since such signals would already be racing with the thread exit,
so there's no guarantee they won't be delivered after the exit and
therefore to a different thread that reuses the tid. So this problem is
arguably unobservable.
Fixes #125.1 parent 076876f commit df6d452
1 file changed
Lines changed: 10 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
| 31 | + | |
30 | 32 | | |
31 | 33 | | |
32 | 34 | | |
| |||
713 | 715 | | |
714 | 716 | | |
715 | 717 | | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
716 | 726 | | |
717 | 727 | | |
718 | 728 | | |
| |||
0 commit comments