fix pthread_exit from cancellation handler
authorRich Felker <dalias@aerifal.cx>
Sun, 17 Apr 2011 21:06:05 +0000 (17:06 -0400)
committerRich Felker <dalias@aerifal.cx>
Sun, 17 Apr 2011 21:06:05 +0000 (17:06 -0400)
cancellation frames were not correctly popped, so this usage would not
only loop, but also reuse discarded and invalid parts of the stack.

src/thread/pthread_create.c

index 8e3a4a26e94484825a0978dba22ff76b93e8b4a3..c6a23955bdd6dde5b12ace70b74130bd2abf1c6d 100644 (file)
@@ -18,12 +18,13 @@ weak_alias(dummy_1, __pthread_tsd_run_dtors);
 
 void __pthread_unwind_next(struct __ptcb *cb)
 {
-       pthread_t self;
+       pthread_t self = pthread_self();
        int n;
 
-       if (cb->__next) longjmp((void *)cb->__next->__jb, 1);
-
-       self = pthread_self();
+       if (cb->__next) {
+               self->cancelbuf = cb->__next->__next;
+               longjmp((void *)cb->__next->__jb, 1);
+       }
 
        LOCK(&self->exitlock);
 
@@ -104,7 +105,6 @@ int pthread_create(pthread_t *res, const pthread_attr_t *attr, void *(*entry)(vo
        new->detached = attr->_a_detach;
        new->attr = *attr;
        new->unblock_cancel = self->cancel;
-       new->result = PTHREAD_CANCELED;
        memcpy(new->tlsdesc, self->tlsdesc, sizeof new->tlsdesc);
        new->tlsdesc[1] = (uintptr_t)new;
        stack = (void *)((uintptr_t)new-1 & ~(uintptr_t)15);