On Wed Oct 19 12:08:10 2022 +0000, Rémi Bernon wrote:
We could maybe arrange the syscall unwind information so that `pthread_exit` would skip the PE frames, but `pthread_exit` on normal thread exit is only one side of the problem. The other side is when exception happen in unix code, in which case we jump back to user code while leaving pthread cleanup handlers in place. If that happened, and even if everything else runs fine, calling pthread_exit on thread exit becomes dangerous. To address that scenario we would have to partially unwind the stacks when returning to user mode, and call any pushed handler. This isn't possible with the C cleanup handlers ABI, which are only registered to some internal pthread structures. It would be possible if the code was in C++, where the handlers are registered as unwinding personality functions.
For the record, we discussed a bit more about that and it ends up that a C code compiled with `-fexceptions` also registers its pthread cleanup handlers into the personality routines.
It would then eventually be possible to partially unwind stacks, and correctly execute and unregister the pthread handlers using standard stack unwinding logic (through libunwind or other), were we building everything with `-fexceptions`.
There would still be potential issues when interacting with third-party C libraries built without that flag.