mips clone: don't free stack space used to copy arg
[musl] / src / thread / pthread_create.c
index 87bf816..48290d3 100644 (file)
@@ -43,19 +43,16 @@ void pthread_exit(void *result)
        __syscall(SYS_exit, 0);
 }
 
-void __do_cleanup_push(struct __ptcb *cb, void (*f)(void *), void *x)
+void __do_cleanup_push(struct __ptcb *cb)
 {
        struct pthread *self = pthread_self();
-       cb->__f = f;
-       cb->__x = x;
        cb->__next = self->cancelbuf;
        self->cancelbuf = cb;
 }
 
-void __do_cleanup_pop(struct __ptcb *cb, int run)
+void __do_cleanup_pop(struct __ptcb *cb)
 {
        __pthread_self()->cancelbuf = cb->__next;
-       if (run) cb->__f(cb->__x);
 }
 
 static int start(void *p)
@@ -98,20 +95,23 @@ int pthread_create(pthread_t *res, const pthread_attr_t *attr, void *(*entry)(vo
                init_file_lock(__stdin_used);
                init_file_lock(__stdout_used);
                init_file_lock(__stderr_used);
-               __syscall(SYS_rt_sigprocmask, SIG_UNBLOCK, SIGPT_SET, 0, 8);
                libc.threaded = 1;
        }
 
-       if (attr) {
-               guard = ROUND(attr->_a_guardsize + DEFAULT_GUARD_SIZE);
-               size = guard + ROUND(attr->_a_stacksize + DEFAULT_STACK_SIZE);
+       if (attr && attr->_a_stackaddr) {
+               map = 0;
+               tsd = (void *)(attr->_a_stackaddr-__pthread_tsd_size & -16);
+       } else {
+               if (attr) {
+                       guard = ROUND(attr->_a_guardsize + DEFAULT_GUARD_SIZE);
+                       size = guard + ROUND(attr->_a_stacksize + DEFAULT_STACK_SIZE);
+               }
+               size += __pthread_tsd_size;
+               map = mmap(0, size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0);
+               if (map == MAP_FAILED) return EAGAIN;
+               if (guard) mprotect(map, guard, PROT_NONE);
+               tsd = map + size - __pthread_tsd_size;
        }
-       size += __pthread_tsd_size;
-       map = mmap(0, size, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_ANON, -1, 0);
-       if (map == MAP_FAILED) return EAGAIN;
-       if (guard) mprotect(map, guard, PROT_NONE);
-
-       tsd = map + size - __pthread_tsd_size;
        new = (void *)(tsd - sizeof *new - PAGE_SIZE%sizeof *new);
        new->map_base = map;
        new->map_size = size;
@@ -123,6 +123,7 @@ int pthread_create(pthread_t *res, const pthread_attr_t *attr, void *(*entry)(vo
        new->tsd = (void *)tsd;
        if (attr) new->detached = attr->_a_detach;
        new->unblock_cancel = self->cancel;
+       new->canary = self->canary ^ (uintptr_t)&new;
        stack = (void *)new;
 
        __synccall_lock();