Restartable sequences in glibc
Restartable sequences in glibc
Posted Feb 1, 2022 1:26 UTC (Tue) by developer122 (guest, #152928)Parent article: Restartable sequences in glibc
Posted Feb 1, 2022 1:51 UTC (Tue)
by compudj (subscriber, #43335)
[Link] (2 responses)
Please keep in mind that this is user-space code, so interrupt handlers don't really make sense in this context. What happens when a signal is delivered on top of a rseq critical section is very much relevant though.
What happens in this case is that the rseq c.s. interrupted by the signal handler will be aborted (it's instruction pointer moved to the abort_ip) so when the signal handler returns, the interrupted thread will continue its execution at the abort ip. It's pretty much as simple as that.
This allows using rseq critical sections within signal handlers as well.
Posted Feb 1, 2022 16:10 UTC (Tue)
by developer122 (guest, #152928)
[Link] (1 responses)
As for how such a situation could ever occur, the article mentions calling code that makes use of restartible sequences, which I suppose could be inlined. So, one bit of restartible code could call a data manipulation library that itself naively tried to create a restartible sequence to protect it's own data structures. Each is trying to protect it's manipulation of it's data structures from access during premption by discarding results that were being worked on if a premption occurred.
The tricky thing here is the matter of cleanup. If something interrupts both sequences by occuring during the nested sequence, then you could restart just the inner sequence but that's wrong because the outer sequence is interrupted and doesn't know it. BUT, if you run just out outer sequence's cleanup code, then the data structures for the inner sequence may be left in an indeterminate state with the changes not being discarded. You can't run both, because only the entry not the exit is defined.
And while we're at it, we're invented the C++ problem of memory cleanup :/
Posted Feb 1, 2022 16:24 UTC (Tue)
by compudj (subscriber, #43335)
[Link]
So I really don't think the scenario you have in mind can realistically happen with the current rseq ABI.
Restartable sequences in glibc
Restartable sequences in glibc
Restartable sequences in glibc