X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fthread%2Fpthread_cancel.c;h=a21c386697c3e399c6c86e18d6be56c77a05d284;hb=8a8fdf6398b85c99dffb237e47fa577e2ddc9e77;hp=1b71aa423399220f70a0a35066af8b04d8d0339a;hpb=102f6a01e249ce4495f1119ae6d963a2a4a53ce5;p=musl diff --git a/src/thread/pthread_cancel.c b/src/thread/pthread_cancel.c index 1b71aa42..a21c3866 100644 --- a/src/thread/pthread_cancel.c +++ b/src/thread/pthread_cancel.c @@ -1,7 +1,12 @@ +#define _GNU_SOURCE +#include #include "pthread_impl.h" #include "syscall.h" #include "libc.h" +__attribute__((__visibility__("hidden"))) +long __cancel(), __syscall_cp_asm(), __syscall_cp_c(); + long __cancel() { pthread_t self = __pthread_self(); @@ -11,12 +16,6 @@ long __cancel() return -ECANCELED; } -/* If __syscall_cp_asm has adjusted the stack pointer, it must provide a - * definition of __cp_cancel to undo those adjustments and call __cancel. - * Otherwise, __cancel provides a definition for __cp_cancel. */ - -weak_alias(__cancel, __cp_cancel); - long __syscall_cp_asm(volatile void *, syscall_arg_t, syscall_arg_t, syscall_arg_t, syscall_arg_t, syscall_arg_t, syscall_arg_t, syscall_arg_t); @@ -29,7 +28,7 @@ long __syscall_cp_c(syscall_arg_t nr, long r; int st; - if (!libc.has_thread_pointer || (st=(self=__pthread_self())->canceldisable) + if ((st=(self=__pthread_self())->canceldisable) && (st==PTHREAD_CANCEL_DISABLE || nr==SYS_close)) return __syscall(nr, u, v, w, x, y, z); @@ -46,20 +45,22 @@ static void _sigaddset(sigset_t *set, int sig) set->__bits[s/8/sizeof *set->__bits] |= 1UL<<(s&8*sizeof *set->__bits-1); } +__attribute__((__visibility__("hidden"))) +extern const char __cp_begin[1], __cp_end[1], __cp_cancel[1]; + static void cancel_handler(int sig, siginfo_t *si, void *ctx) { pthread_t self = __pthread_self(); ucontext_t *uc = ctx; - const char *ip = ((char **)&uc->uc_mcontext)[CANCEL_REG_IP]; - extern const char __cp_begin[1], __cp_end[1]; + uintptr_t pc = uc->uc_mcontext.MC_PC; a_barrier(); if (!self->cancel || self->canceldisable == PTHREAD_CANCEL_DISABLE) return; _sigaddset(&uc->uc_sigmask, SIGCANCEL); - if (self->cancelasync || ip >= __cp_begin && ip < __cp_end) { - ((char **)&uc->uc_mcontext)[CANCEL_REG_IP] = (char *)__cp_cancel; + if (self->cancelasync || pc >= (uintptr_t)__cp_begin && pc < (uintptr_t)__cp_end) { + uc->uc_mcontext.MC_PC = (uintptr_t)__cp_cancel; return; } @@ -68,7 +69,6 @@ static void cancel_handler(int sig, siginfo_t *si, void *ctx) void __testcancel() { - if (!libc.has_thread_pointer) return; pthread_t self = __pthread_self(); if (self->cancel && !self->canceldisable) __cancel(); @@ -80,7 +80,7 @@ static void init_cancellation() .sa_flags = SA_SIGINFO | SA_RESTART, .sa_sigaction = cancel_handler }; - sigfillset(&sa.sa_mask); + memset(&sa.sa_mask, -1, _NSIG/8); __libc_sigaction(SIGCANCEL, &sa, 0); }