diff options
author | joseph <joseph@7b3dc134-2b1b-0410-93df-9e9f96275f8d> | 2010-03-13 18:20:12 +0000 |
---|---|---|
committer | joseph <joseph@7b3dc134-2b1b-0410-93df-9e9f96275f8d> | 2010-03-13 18:20:12 +0000 |
commit | 984124d726e087943f1415337c50a1bff32cfc17 (patch) | |
tree | c6f715c85c46ad0c97af31cff88257aca141d3ac /libc/nptl | |
parent | 3b289e20aa9fa02a85745547a976b824bc66d096 (diff) | |
download | eglibc2-984124d726e087943f1415337c50a1bff32cfc17.tar.gz |
Merge changes between r9801 and r10031 from /fsf/trunk.
git-svn-id: svn://svn.eglibc.org/trunk@10032 7b3dc134-2b1b-0410-93df-9e9f96275f8d
Diffstat (limited to 'libc/nptl')
-rw-r--r-- | libc/nptl/ChangeLog | 25 | ||||
-rw-r--r-- | libc/nptl/allocatestack.c | 22 | ||||
-rw-r--r-- | libc/nptl/pthread_create.c | 36 | ||||
-rw-r--r-- | libc/nptl/sysdeps/pthread/createthread.c | 25 |
4 files changed, 75 insertions, 33 deletions
diff --git a/libc/nptl/ChangeLog b/libc/nptl/ChangeLog index c81eb03b7..f51ad4326 100644 --- a/libc/nptl/ChangeLog +++ b/libc/nptl/ChangeLog @@ -1,3 +1,28 @@ +2010-03-09 Ulrich Drepper <drepper@redhat.com> + + * pthread_create.c (__pthread_create_2_1): If priorities are incorrect + and the call fails wake eventually waiting setxid threads. Don't free + stack here if we try starting a thread. + * sysdeps/pthread/createthread.c (do_clone): Only wake setxid waiter + if the clone call failed. + +2010-03-08 Andreas Schwab <schwab@redhat.com> + + * pthread_create.c (__pthread_create_2_1): Don't set setxid_futex. + * allocatestack.c (get_cached_stack): Set setxid_futex. + (allocate_stack): Likewise. + +2010-03-05 Andreas Schwab <schwab@redhat.com> + Ulrich Drepper <drepper@redhat.com> + + * allocatestack.c (setxid_mark_thread): Delay handling of thread if + it is creating a thread or it is just being created. + * pthread_create.c (start_thread): Wake setxid thread if it is + waiting. + (__pthread_create_2_1): Initialize setxid_futex. + * sysdeps/pthread/createthread.c (do_clone): Wake setxid thread if it + is waiting. + 2010-01-15 Ulrich Drepper <drepper@redhat.com> * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S: diff --git a/libc/nptl/allocatestack.c b/libc/nptl/allocatestack.c index 3c3585fe3..831e98e4c 100644 --- a/libc/nptl/allocatestack.c +++ b/libc/nptl/allocatestack.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2002-2007, 2009 Free Software Foundation, Inc. +/* Copyright (C) 2002-2007, 2009, 2010 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. @@ -213,6 +213,9 @@ get_cached_stack (size_t *sizep, void **memp) return NULL; } + /* Don't allow setxid until cloned. */ + result->setxid_futex = -1; + /* Dequeue the entry. */ stack_list_del (&result->list); @@ -380,7 +383,7 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp, - TLS_TCB_SIZE - adj); #elif TLS_DTV_AT_TP pd = (struct pthread *) (((uintptr_t) attr->stackaddr - - __static_tls_size - adj) + - __static_tls_size - adj) - TLS_PRE_TCB_SIZE); #endif @@ -418,6 +421,9 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp, /* The process ID is also the same as that of the caller. */ pd->pid = THREAD_GETMEM (THREAD_SELF, pid); + /* Don't allow setxid until cloned. */ + pd->setxid_futex = -1; + /* Allocate the DTV for this thread. */ if (_dl_allocate_tls (TLS_TPADJ (pd)) == NULL) { @@ -546,7 +552,7 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp, #ifndef __ASSUME_PRIVATE_FUTEX /* The thread must know when private futexes are supported. */ pd->header.private_futex = THREAD_GETMEM (THREAD_SELF, - header.private_futex); + header.private_futex); #endif #ifdef NEED_DL_SYSINFO @@ -554,6 +560,9 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp, THREAD_SYSINFO(pd) = THREAD_SELF_SYSINFO; #endif + /* Don't allow setxid until cloned. */ + pd->setxid_futex = -1; + /* The process ID is also the same as that of the caller. */ pd->pid = THREAD_GETMEM (THREAD_SELF, pid); @@ -969,6 +978,13 @@ setxid_mark_thread (struct xid_command *cmdp, struct pthread *t) { int ch; + /* Wait until this thread is cloned. */ + if (t->setxid_futex == -1 + && ! atomic_compare_and_exchange_bool_acq (&t->setxid_futex, -2, -1)) + do + lll_futex_wait (&t->setxid_futex, -2, LLL_PRIVATE); + while (t->setxid_futex == -2); + /* Don't let the thread exit before the setxid handler runs. */ t->setxid_futex = 0; diff --git a/libc/nptl/pthread_create.c b/libc/nptl/pthread_create.c index ddf377cdb..649cdae8f 100644 --- a/libc/nptl/pthread_create.c +++ b/libc/nptl/pthread_create.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2002-2007,2008,2009 Free Software Foundation, Inc. +/* Copyright (C) 2002-2007,2008,2009,2010 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. @@ -242,6 +242,10 @@ start_thread (void *arg) __resp = &pd->res; #endif + /* Allow setxid from now onwards. */ + if (__builtin_expect (atomic_exchange_acq (&pd->setxid_futex, 0) == -2, 0)) + lll_futex_wake (&pd->setxid_futex, 1, LLL_PRIVATE); + #ifdef __NR_set_robust_list # ifndef __ASSUME_SET_ROBUST_LIST if (__set_robust_list_avail >= 0) @@ -538,33 +542,23 @@ __pthread_create_2_1 (newthread, attr, start_routine, arg) if (pd->schedparam.sched_priority < minprio || pd->schedparam.sched_priority > maxprio) { - err = EINVAL; - goto errout; + /* Perhaps a thread wants to change the IDs and if waiting + for this stillborn thread. */ + if (__builtin_expect (atomic_exchange_acq (&pd->setxid_futex, 0) + == -2, 0)) + lll_futex_wake (&pd->setxid_futex, 1, LLL_PRIVATE); + + __deallocate_stack (pd); + + return EINVAL; } } /* Pass the descriptor to the caller. */ *newthread = (pthread_t) pd; - /* Remember whether the thread is detached or not. In case of an - error we have to free the stacks of non-detached stillborn - threads. */ - bool is_detached = IS_DETACHED (pd); - /* Start the thread. */ - err = create_thread (pd, iattr, STACK_VARIABLES_ARGS); - if (err != 0) - { - /* Something went wrong. Free the resources. */ - if (!is_detached) - { - errout: - __deallocate_stack (pd); - } - return err; - } - - return 0; + return create_thread (pd, iattr, STACK_VARIABLES_ARGS); } versioned_symbol (libpthread, __pthread_create_2_1, pthread_create, GLIBC_2_1); diff --git a/libc/nptl/sysdeps/pthread/createthread.c b/libc/nptl/sysdeps/pthread/createthread.c index 66fafe805..8d96387a9 100644 --- a/libc/nptl/sysdeps/pthread/createthread.c +++ b/libc/nptl/sysdeps/pthread/createthread.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2002-2007, 2008 Free Software Foundation, Inc. +/* Copyright (C) 2002-2007, 2008, 2010 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. @@ -28,7 +28,7 @@ #include "kernel-features.h" -#define CLONE_SIGNAL (CLONE_SIGHAND | CLONE_THREAD) +#define CLONE_SIGNAL (CLONE_SIGHAND | CLONE_THREAD) /* Unless otherwise specified, the thread "register" is going to be initialized with a pointer to the TCB. */ @@ -72,16 +72,20 @@ do_clone (struct pthread *pd, const struct pthread_attr *attr, that cares whether the thread count is correct. */ atomic_increment (&__nptl_nthreads); - if (ARCH_CLONE (fct, STACK_VARIABLES_ARGS, clone_flags, - pd, &pd->tid, TLS_VALUE, &pd->tid) == -1) + int rc = ARCH_CLONE (fct, STACK_VARIABLES_ARGS, clone_flags, + pd, &pd->tid, TLS_VALUE, &pd->tid); + + if (__builtin_expect (rc == -1, 0)) { atomic_decrement (&__nptl_nthreads); /* Oops, we lied for a second. */ - /* Failed. If the thread is detached, remove the TCB here since - the caller cannot do this. The caller remembered the thread - as detached and cannot reverify that it is not since it must - not access the thread descriptor again. */ - if (IS_DETACHED (pd)) + /* Perhaps a thread wants to change the IDs and if waiting + for this stillborn thread. */ + if (__builtin_expect (atomic_exchange_acq (&pd->setxid_futex, 0) + == -2, 0)) + lll_futex_wake (&pd->setxid_futex, 1, LLL_PRIVATE); + + /* Free the resources. */ __deallocate_stack (pd); /* We have to translate error codes. */ @@ -114,6 +118,9 @@ do_clone (struct pthread *pd, const struct pthread_attr *attr, (void) INTERNAL_SYSCALL (tkill, err2, 2, pd->tid, SIGCANCEL); #endif + /* We do not free the stack here because the canceled thread + itself will do this. */ + return (INTERNAL_SYSCALL_ERROR_P (res, err) ? INTERNAL_SYSCALL_ERRNO (res, err) : 0); |