summaryrefslogtreecommitdiff
path: root/src/thread/pthread_cancel.c
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2015-11-02 12:39:28 -0500
committerRich Felker <dalias@aerifal.cx>2015-11-02 12:41:49 -0500
commitcb1bf2f321b45a06447133b3db00621b7300c456 (patch)
tree50518595b1f221270ec0a209b5252c85d4ba140c /src/thread/pthread_cancel.c
parentfead7e3fc04729b4cc8a5feec4a172b389395212 (diff)
downloadmusl-cb1bf2f321b45a06447133b3db00621b7300c456.tar.gz
properly access mcontext_t program counter in cancellation handler
using the actual mcontext_t definition rather than an overlaid pointer array both improves correctness/readability and eliminates some ugly hacks for archs with 64-bit registers bit 32-bit program counter. also fix UB due to comparison of pointers not in a common array object.
Diffstat (limited to 'src/thread/pthread_cancel.c')
-rw-r--r--src/thread/pthread_cancel.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/thread/pthread_cancel.c b/src/thread/pthread_cancel.c
index 0151a1ae..6eaf72c4 100644
--- a/src/thread/pthread_cancel.c
+++ b/src/thread/pthread_cancel.c
@@ -1,3 +1,4 @@
+#define _GNU_SOURCE
#include <string.h>
#include "pthread_impl.h"
#include "syscall.h"
@@ -61,15 +62,15 @@ 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];
+ 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;
}