mirror of
https://git.musl-libc.org/git/musl
synced 2025-01-21 21:52:04 +03:00
fix async thread cancellation stack alignment
if async cancellation is enabled and acted upon, the stack pointer is
not necessarily pointing to a __syscall_cp_asm stack frame. the
contents of the stack being wrong don't really matter, but if the
stack pointer is not suitably aligned, the procedure call ABI is
violated when calling back into C code via __cancel, and pthread_exit,
cancellation cleanup handlers, TSD destructors, etc. may malfunction
or crash.
for the async cancel case, just call __cancel directly like we did
prior to commit 102f6a01e2
. restore the
signal mask prior to doing this since the cancellation handler runs
with all signals blocked.
This commit is contained in:
parent
8f9259450a
commit
ad5dcd398b
@ -56,7 +56,12 @@ static void cancel_handler(int sig, siginfo_t *si, void *ctx)
|
||||
|
||||
_sigaddset(&uc->uc_sigmask, SIGCANCEL);
|
||||
|
||||
if (self->cancelasync || pc >= (uintptr_t)__cp_begin && pc < (uintptr_t)__cp_end) {
|
||||
if (self->cancelasync) {
|
||||
pthread_sigmask(SIG_SETMASK, &uc->uc_sigmask, 0);
|
||||
__cancel();
|
||||
}
|
||||
|
||||
if (pc >= (uintptr_t)__cp_begin && pc < (uintptr_t)__cp_end) {
|
||||
uc->uc_mcontext.MC_PC = (uintptr_t)__cp_cancel;
|
||||
#ifdef CANCEL_GOT
|
||||
uc->uc_mcontext.MC_GOT = CANCEL_GOT;
|
||||
|
Loading…
Reference in New Issue
Block a user