From 5a69eba90b5b961ceb723d816ce8401582980477 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Tue, 15 Nov 2005 03:02:51 +0000 Subject: revert linuxthreads to pre rev 11377 (i.e. before the massive attempt to import glibc updates) while keeping the few bugfixes ... idea is to keep both old and new linuxthreads around so we can hack on the new version while delivering the old stable version to end users --- libpthread/linuxthreads/attr.c | 367 +++----------------------- libpthread/linuxthreads/cancel.c | 23 +- libpthread/linuxthreads/condvar.c | 103 +------- libpthread/linuxthreads/descr.h | 313 ---------------------- libpthread/linuxthreads/events.c | 10 +- libpthread/linuxthreads/internals.h | 287 ++++++++++++++++---- libpthread/linuxthreads/join.c | 4 +- libpthread/linuxthreads/manager.c | 130 ++------- libpthread/linuxthreads/mutex.c | 8 - libpthread/linuxthreads/oldsemaphore.c | 12 +- libpthread/linuxthreads/pt-machine.c | 11 +- libpthread/linuxthreads/pthread.c | 255 +++++++----------- libpthread/linuxthreads/rwlock.c | 239 +++-------------- libpthread/linuxthreads/signals.c | 70 +++-- libpthread/linuxthreads/specific.c | 192 +++++++------- libpthread/linuxthreads/spinlock.h | 2 +- libpthread/linuxthreads/sysdeps/i386/useldt.h | 15 +- libpthread/linuxthreads/wrapsyscall.c | 220 +++++++++++++++ 18 files changed, 792 insertions(+), 1469 deletions(-) delete mode 100644 libpthread/linuxthreads/descr.h create mode 100644 libpthread/linuxthreads/wrapsyscall.c diff --git a/libpthread/linuxthreads/attr.c b/libpthread/linuxthreads/attr.c index c84da0d30..4432a04d1 100644 --- a/libpthread/linuxthreads/attr.c +++ b/libpthread/linuxthreads/attr.c @@ -12,50 +12,27 @@ /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ /* GNU Library General Public License for more details. */ -/* Handling of thread attributes */ - -/* mods for uClibc */ -#define __getpagesize getpagesize +/* changed for uClibc */ #define __sched_get_priority_min sched_get_priority_min #define __sched_get_priority_max sched_get_priority_max -#define __sched_getscheduler sched_getscheduler -#define __sched_getparam sched_getparam -#include -#define __USE_GNU +/* Handling of thread attributes */ + #include -#include -#include -#include -#include #include #include #include -#include #include "pthread.h" #include "internals.h" -/* glibc uses strong aliases, we wont bother */ -#undef strong_alias -#define strong_alias(sym, alias) -#define __pthread_attr_destroy pthread_attr_destroy -#define __pthread_attr_setdetachstate pthread_attr_setdetachstate -#define __pthread_attr_getdetachstate pthread_attr_getdetachstate -#define __pthread_attr_setschedparam pthread_attr_setschedparam -#define __pthread_attr_getschedparam pthread_attr_getschedparam -#define __pthread_attr_setschedpolicy pthread_attr_setschedpolicy -#define __pthread_attr_getschedpolicy pthread_attr_getschedpolicy -#define __pthread_attr_setinheritsched pthread_attr_setinheritsched -#define __pthread_attr_getinheritsched pthread_attr_getinheritsched -#define __pthread_attr_setscope pthread_attr_setscope -#define __pthread_attr_getscope pthread_attr_getscope +extern int __getpagesize(void); /* NOTE: With uClibc I don't think we need this versioning stuff. * Therefore, define the function pthread_attr_init() here using * a strong symbol. */ -#define __pthread_attr_init_2_1 pthread_attr_init -int __pthread_attr_init_2_1(pthread_attr_t *attr) +//int __pthread_attr_init_2_1(pthread_attr_t *attr) +int pthread_attr_init(pthread_attr_t *attr) { size_t ps = __getpagesize (); @@ -64,11 +41,7 @@ int __pthread_attr_init_2_1(pthread_attr_t *attr) attr->__schedparam.sched_priority = 0; attr->__inheritsched = PTHREAD_EXPLICIT_SCHED; attr->__scope = PTHREAD_SCOPE_SYSTEM; -#ifdef NEED_SEPARATE_REGISTER_STACK - attr->__guardsize = ps + ps; -#else attr->__guardsize = ps; -#endif attr->__stackaddr = NULL; attr->__stackaddr_set = 0; attr->__stacksize = STACK_SIZE - ps; @@ -76,11 +49,10 @@ int __pthread_attr_init_2_1(pthread_attr_t *attr) } /* uClibc: leave out this for now. */ -#if 0 -versioned_symbol (libpthread, __pthread_attr_init_2_1, pthread_attr_init, - GLIBC_2_1); +#if DO_PTHREAD_VERSIONING_WITH_UCLIBC +#if defined __HAVE_ELF__ && defined __PIC__ && defined DO_VERSIONING +default_symbol_version (__pthread_attr_init_2_1, pthread_attr_init, GLIBC_2.1); -#if SHLIB_COMPAT(libpthread, GLIBC_2_0, GLIBC_2_1) int __pthread_attr_init_2_0(pthread_attr_t *attr) { attr->__detachstate = PTHREAD_CREATE_JOINABLE; @@ -90,18 +62,18 @@ int __pthread_attr_init_2_0(pthread_attr_t *attr) attr->__scope = PTHREAD_SCOPE_SYSTEM; return 0; } -compat_symbol (libpthread, __pthread_attr_init_2_0, pthread_attr_init, - GLIBC_2_0); -#endif +symbol_version (__pthread_attr_init_2_0, pthread_attr_init, GLIBC_2.0); +#else +strong_alias (__pthread_attr_init_2_1, pthread_attr_init) #endif +#endif /* DO_PTHREAD_VERSIONING_WITH_UCLIBC */ -int __pthread_attr_destroy(pthread_attr_t *attr) +int pthread_attr_destroy(pthread_attr_t *attr) { return 0; } -strong_alias (__pthread_attr_destroy, pthread_attr_destroy); -int __pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate) +int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate) { if (detachstate < PTHREAD_CREATE_JOINABLE || detachstate > PTHREAD_CREATE_DETACHED) @@ -109,17 +81,15 @@ int __pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate) attr->__detachstate = detachstate; return 0; } -strong_alias (__pthread_attr_setdetachstate, pthread_attr_setdetachstate); -int __pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate) +int pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate) { *detachstate = attr->__detachstate; return 0; } -strong_alias (__pthread_attr_getdetachstate, pthread_attr_getdetachstate); -int __pthread_attr_setschedparam(pthread_attr_t *attr, - const struct sched_param *param) +int pthread_attr_setschedparam(pthread_attr_t *attr, + const struct sched_param *param) { int max_prio = __sched_get_priority_max(attr->__schedpolicy); int min_prio = __sched_get_priority_min(attr->__schedpolicy); @@ -129,49 +99,43 @@ int __pthread_attr_setschedparam(pthread_attr_t *attr, memcpy (&attr->__schedparam, param, sizeof (struct sched_param)); return 0; } -strong_alias (__pthread_attr_setschedparam, pthread_attr_setschedparam); -int __pthread_attr_getschedparam(const pthread_attr_t *attr, - struct sched_param *param) +int pthread_attr_getschedparam(const pthread_attr_t *attr, + struct sched_param *param) { memcpy (param, &attr->__schedparam, sizeof (struct sched_param)); return 0; } -strong_alias (__pthread_attr_getschedparam, pthread_attr_getschedparam); -int __pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy) +int pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy) { if (policy != SCHED_OTHER && policy != SCHED_FIFO && policy != SCHED_RR) return EINVAL; attr->__schedpolicy = policy; return 0; } -strong_alias (__pthread_attr_setschedpolicy, pthread_attr_setschedpolicy); -int __pthread_attr_getschedpolicy(const pthread_attr_t *attr, int *policy) +int pthread_attr_getschedpolicy(const pthread_attr_t *attr, int *policy) { *policy = attr->__schedpolicy; return 0; } -strong_alias (__pthread_attr_getschedpolicy, pthread_attr_getschedpolicy); -int __pthread_attr_setinheritsched(pthread_attr_t *attr, int inherit) +int pthread_attr_setinheritsched(pthread_attr_t *attr, int inherit) { if (inherit != PTHREAD_INHERIT_SCHED && inherit != PTHREAD_EXPLICIT_SCHED) return EINVAL; attr->__inheritsched = inherit; return 0; } -strong_alias (__pthread_attr_setinheritsched, pthread_attr_setinheritsched); -int __pthread_attr_getinheritsched(const pthread_attr_t *attr, int *inherit) +int pthread_attr_getinheritsched(const pthread_attr_t *attr, int *inherit) { *inherit = attr->__inheritsched; return 0; } -strong_alias (__pthread_attr_getinheritsched, pthread_attr_getinheritsched); -int __pthread_attr_setscope(pthread_attr_t *attr, int scope) +int pthread_attr_setscope(pthread_attr_t *attr, int scope) { switch (scope) { case PTHREAD_SCOPE_SYSTEM: @@ -183,17 +147,20 @@ int __pthread_attr_setscope(pthread_attr_t *attr, int scope) return EINVAL; } } -strong_alias (__pthread_attr_setscope, pthread_attr_setscope); -int __pthread_attr_getscope(const pthread_attr_t *attr, int *scope) +int pthread_attr_getscope(const pthread_attr_t *attr, int *scope) { *scope = attr->__scope; return 0; } -strong_alias (__pthread_attr_getscope, pthread_attr_getscope); int __pthread_attr_setguardsize(pthread_attr_t *attr, size_t guardsize) { + size_t ps = __getpagesize (); + + /* First round up the guard size. */ + guardsize = roundup (guardsize, ps); + /* The guard size must not be larger than the stack itself */ if (guardsize >= attr->__stacksize) return EINVAL; @@ -218,9 +185,6 @@ int __pthread_attr_setstackaddr(pthread_attr_t *attr, void *stackaddr) } weak_alias (__pthread_attr_setstackaddr, pthread_attr_setstackaddr) -link_warning (pthread_attr_setstackaddr, - "the use of `pthread_attr_setstackaddr' is deprecated, use `pthread_attr_setstack'") - int __pthread_attr_getstackaddr(const pthread_attr_t *attr, void **stackaddr) { /* XXX This function has a stupid definition. The standard specifies @@ -231,27 +195,8 @@ int __pthread_attr_getstackaddr(const pthread_attr_t *attr, void **stackaddr) } weak_alias (__pthread_attr_getstackaddr, pthread_attr_getstackaddr) -link_warning (pthread_attr_getstackaddr, - "the use of `pthread_attr_getstackaddr' is deprecated, use `pthread_attr_getstack'") - - int __pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize) { -#ifdef FLOATING_STACKS - /* We have to check against the maximum allowed stack size. This is no - problem if the manager is already started and we determined it. If - this hasn't happened, we have to find the limit outself. */ - if (__pthread_max_stacksize == 0) - __pthread_init_max_stacksize (); - - if (stacksize > __pthread_max_stacksize) - return EINVAL; -#else - /* We have a fixed size limit. */ - if (stacksize > STACK_SIZE) - return EINVAL; -#endif - /* We don't accept value smaller than PTHREAD_STACK_MIN. */ if (stacksize < PTHREAD_STACK_MIN) return EINVAL; @@ -259,45 +204,7 @@ int __pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize) attr->__stacksize = stacksize; return 0; } - -/* Don't bother with this version stuff in uClibc */ -#if 1 /*PTHREAD_STACK_MIN == 16384*/ weak_alias (__pthread_attr_setstacksize, pthread_attr_setstacksize) -#else -versioned_symbol (libpthread, __pthread_attr_setstacksize, - pthread_attr_setstacksize, GLIBC_2_3_3); - -# if SHLIB_COMPAT(libpthread, GLIBC_2_1, GLIBC_2_3_3) - -int __old_pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize) -{ -# ifdef FLOATING_STACKS - /* We have to check against the maximum allowed stack size. This is no - problem if the manager is already started and we determined it. If - this hasn't happened, we have to find the limit outself. */ - if (__pthread_max_stacksize == 0) - __pthread_init_max_stacksize (); - - if (stacksize > __pthread_max_stacksize) - return EINVAL; -# else - /* We have a fixed size limit. */ - if (stacksize > STACK_SIZE) - return EINVAL; -# endif - - /* We don't accept value smaller than old PTHREAD_STACK_MIN. */ - if (stacksize < 16384) - return EINVAL; - - attr->__stacksize = stacksize; - return 0; -} -compat_symbol (libpthread, __old_pthread_attr_setstacksize, - pthread_attr_setstacksize, GLIBC_2_1); -# endif -#endif - int __pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stacksize) { @@ -305,215 +212,3 @@ int __pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stacksize) return 0; } weak_alias (__pthread_attr_getstacksize, pthread_attr_getstacksize) - -int __pthread_attr_setstack (pthread_attr_t *attr, void *stackaddr, - size_t stacksize) -{ - int err; - - if ((((uintptr_t) stackaddr) - & (__alignof__ (struct _pthread_descr_struct) - 1)) != 0) - err = EINVAL; - else - err = __pthread_attr_setstacksize (attr, stacksize); - if (err == 0) - { -#ifndef _STACK_GROWS_UP - attr->__stackaddr = (char *) stackaddr + stacksize; -#else - attr->__stackaddr = stackaddr; -#endif - attr->__stackaddr_set = 1; - } - - return err; -} - -/* Don't bother with this version stuff in uClibc */ -#if 1 /*PTHREAD_STACK_MIN == 16384*/ -weak_alias (__pthread_attr_setstack, pthread_attr_setstack) -#else -versioned_symbol (libpthread, __pthread_attr_setstack, pthread_attr_setstack, - GLIBC_2_3_3); -# if SHLIB_COMPAT(libpthread, GLIBC_2_2, GLIBC_2_3_3) -int __old_pthread_attr_setstack (pthread_attr_t *attr, void *stackaddr, - size_t stacksize) -{ - int err; - - if ((((uintptr_t) stackaddr) - & (__alignof__ (struct _pthread_descr_struct) - 1)) != 0) - err = EINVAL; - else - err = __old_pthread_attr_setstacksize (attr, stacksize); - if (err == 0) - { -# ifndef _STACK_GROWS_UP - attr->__stackaddr = (char *) stackaddr + stacksize; -# else - attr->__stackaddr = stackaddr; -# endif - attr->__stackaddr_set = 1; - } - - return err; -} - -compat_symbol (libpthread, __old_pthread_attr_setstack, pthread_attr_setstack, - GLIBC_2_2); - -# endif -#endif - -int __pthread_attr_getstack (const pthread_attr_t *attr, void **stackaddr, - size_t *stacksize) -{ - /* XXX This function has a stupid definition. The standard specifies - no error value but what is if no stack address was set? We simply - return the value we have in the member. */ -#ifndef _STACK_GROWS_UP - *stackaddr = (char *) attr->__stackaddr - attr->__stacksize; -#else - *stackaddr = attr->__stackaddr; -#endif - *stacksize = attr->__stacksize; - return 0; -} -weak_alias (__pthread_attr_getstack, pthread_attr_getstack) - -/* can't fully support this just yet */ -#if 0 -int pthread_getattr_np (pthread_t thread, pthread_attr_t *attr) -{ - pthread_handle handle = thread_handle (thread); - pthread_descr descr; - int ret = 0; - - if (handle == NULL) - return ENOENT; - - descr = handle->h_descr; - - attr->__detachstate = (descr->p_detached - ? PTHREAD_CREATE_DETACHED - : PTHREAD_CREATE_JOINABLE); - - attr->__schedpolicy = __sched_getscheduler (descr->p_pid); - if (attr->__schedpolicy == -1) - return errno; - - if (__sched_getparam (descr->p_pid, - (struct sched_param *) &attr->__schedparam) != 0) - return errno; - - attr->__inheritsched = descr->p_inheritsched; - attr->__scope = PTHREAD_SCOPE_SYSTEM; - -#ifdef _STACK_GROWS_DOWN -# ifdef USE_TLS - attr->__stacksize = descr->p_stackaddr - (char *)descr->p_guardaddr - - descr->p_guardsize; -# else - attr->__stacksize = (char *)(descr + 1) - (char *)descr->p_guardaddr - - descr->p_guardsize; -# endif -#else -# ifdef USE_TLS - attr->__stacksize = (char *)descr->p_guardaddr - descr->p_stackaddr; -# else - attr->__stacksize = (char *)descr->p_guardaddr - (char *)descr; -# endif -#endif - attr->__guardsize = descr->p_guardsize; - attr->__stackaddr_set = descr->p_userstack; -#ifdef NEED_SEPARATE_REGISTER_STACK - if (descr->p_userstack == 0) - attr->__stacksize *= 2; - /* XXX This is awkward. The guard pages are in the middle of the - two stacks. We must count the guard size in the stack size since - otherwise the range of the stack area cannot be computed. */ - attr->__stacksize += attr->__guardsize; -#endif -#ifdef USE_TLS - attr->__stackaddr = descr->p_stackaddr; -#else -# ifndef _STACK_GROWS_UP - attr->__stackaddr = (char *)(descr + 1); -# else - attr->__stackaddr = (char *)descr; -# endif -#endif - -#ifdef USE_TLS - if (attr->__stackaddr == NULL) -#else - if (descr == &__pthread_initial_thread) -#endif - { - /* Stack size limit. */ - struct rlimit rl; - - /* The safest way to get the top of the stack is to read - /proc/self/maps and locate the line into which - __libc_stack_end falls. */ - FILE *fp = fopen ("/proc/self/maps", "rc"); - if (fp == NULL) - ret = errno; - /* We need the limit of the stack in any case. */ - else if (getrlimit (RLIMIT_STACK, &rl) != 0) - ret = errno; - else - { - /* We need no locking. */ - __fsetlocking (fp, FSETLOCKING_BYCALLER); - - /* Until we found an entry (which should always be the case) - mark the result as a failure. */ - ret = ENOENT; - - char *line = NULL; - size_t linelen = 0; - uintptr_t last_to = 0; - - while (! feof_unlocked (fp)) - { - if (__getdelim (&line, &linelen, '\n', fp) <= 0) - break; - - uintptr_t from; - uintptr_t to; - if (sscanf (line, "%" SCNxPTR "-%" SCNxPTR, &from, &to) != 2) - continue; - if (from <= (uintptr_t) __libc_stack_end - && (uintptr_t) __libc_stack_end < to) - { - /* Found the entry. Now we have the info we need. */ - attr->__stacksize = rl.rlim_cur; -#ifdef _STACK_GROWS_UP - /* Don't check to enforce a limit on the __stacksize */ - attr->__stackaddr = (void *) from; -#else - attr->__stackaddr = (void *) to; - - /* The limit might be too high. */ - if ((size_t) attr->__stacksize - > (size_t) attr->__stackaddr - last_to) - attr->__stacksize = (size_t) attr->__stackaddr - last_to; -#endif - - /* We succeed and no need to look further. */ - ret = 0; - break; - } - last_to = to; - } - - fclose (fp); - free (line); - } - } - - return 0; - -} -#endif diff --git a/libpthread/linuxthreads/cancel.c b/libpthread/linuxthreads/cancel.c index dbba7eef4..1356348a7 100644 --- a/libpthread/linuxthreads/cancel.c +++ b/libpthread/linuxthreads/cancel.c @@ -26,14 +26,6 @@ extern void __rpc_thread_destroy(void); #endif -#ifdef _STACK_GROWS_DOWN -# define FRAME_LEFT(frame, other) ((char *) frame >= (char *) other) -#elif _STACK_GROWS_UP -# define FRAME_LEFT(frame, other) ((char *) frame <= (char *) other) -#else -# error "Define either _STACK_GROWS_DOWN or _STACK_GROWS_UP" -#endif - int pthread_setcancelstate(int state, int * oldstate) { @@ -70,31 +62,28 @@ int pthread_cancel(pthread_t thread) int dorestart = 0; pthread_descr th; pthread_extricate_if *pextricate; - int already_canceled; __pthread_lock(&handle->h_lock, NULL); - if (nonexisting_handle(handle, thread)) { + if (invalid_handle(handle, thread)) { __pthread_unlock(&handle->h_lock); return ESRCH; } th = handle->h_descr; - already_canceled = th->p_canceled; - th->p_canceled = 1; - - if (th->p_cancelstate == PTHREAD_CANCEL_DISABLE || already_canceled) { + if (th->p_canceled) { __pthread_unlock(&handle->h_lock); return 0; } pextricate = th->p_extricate; + th->p_canceled = 1; pid = th->p_pid; /* If the thread has registered an extrication interface, then invoke the interface. If it returns 1, then we succeeded in dequeuing the thread from whatever waiting object it was enqueued - with. In that case, it is our responsibility to wake it up. + with. In that case, it is our responsibility to wake it up. And also to set the p_woken_by_cancel flag so the woken thread can tell that it was woken by cancellation. */ @@ -136,8 +125,6 @@ void _pthread_cleanup_push(struct _pthread_cleanup_buffer * buffer, buffer->__routine = routine; buffer->__arg = arg; buffer->__prev = THREAD_GETMEM(self, p_cleanup); - if (buffer->__prev != NULL && FRAME_LEFT (buffer, buffer->__prev)) - buffer->__prev = NULL; THREAD_SETMEM(self, p_cleanup, buffer); } @@ -157,8 +144,6 @@ void _pthread_cleanup_push_defer(struct _pthread_cleanup_buffer * buffer, buffer->__arg = arg; buffer->__canceltype = THREAD_GETMEM(self, p_canceltype); buffer->__prev = THREAD_GETMEM(self, p_cleanup); - if (buffer->__prev != NULL && FRAME_LEFT (buffer, buffer->__prev)) - buffer->__prev = NULL; THREAD_SETMEM(self, p_canceltype, PTHREAD_CANCEL_DEFERRED); THREAD_SETMEM(self, p_cleanup, buffer); } diff --git a/libpthread/linuxthreads/condvar.c b/libpthread/linuxthreads/condvar.c index b051afd4c..f9c46a331 100644 --- a/libpthread/linuxthreads/condvar.c +++ b/libpthread/linuxthreads/condvar.c @@ -25,52 +25,19 @@ #include "queue.h" #include "restart.h" -/* glibc uses strong aliases, we wont bother */ -#undef strong_alias -#define strong_alias(sym, alias) -#define __pthread_cond_init pthread_cond_init -#define __pthread_cond_destroy pthread_cond_destroy -#define __pthread_cond_wait pthread_cond_wait -#define __pthread_cond_timedwait pthread_cond_timedwait -#define __pthread_cond_signal pthread_cond_signal -#define __pthread_cond_broadcast pthread_cond_broadcast -#define __pthread_condattr_init pthread_condattr_init -#define __pthread_condattr_destroy pthread_condattr_destroy - - -int __pthread_cond_init(pthread_cond_t *cond, - const pthread_condattr_t *cond_attr) +int pthread_cond_init(pthread_cond_t *cond, + const pthread_condattr_t *cond_attr) { __pthread_init_lock(&cond->__c_lock); cond->__c_waiting = NULL; return 0; } -/* Don't bother with this version stuff in uClibc */ -#if 0 -versioned_symbol (libpthread, __pthread_cond_init, pthread_cond_init, - GLIBC_2_3_2); -#if SHLIB_COMPAT(libpthread, GLIBC_2_0, GLIBC_2_3_2) -strong_alias (__pthread_cond_init, __old_pthread_cond_init) -compat_symbol (libpthread, __old_pthread_cond_init, pthread_cond_init, - GLIBC_2_0); -#endif -#endif - -int __pthread_cond_destroy(pthread_cond_t *cond) + +int pthread_cond_destroy(pthread_cond_t *cond) { if (cond->__c_waiting != NULL) return EBUSY; return 0; } -/* Don't bother with this version stuff in uClibc */ -#if 0 -versioned_symbol (libpthread, __pthread_cond_destroy, pthread_cond_destroy, - GLIBC_2_3_2); -#if SHLIB_COMPAT(libpthread, GLIBC_2_0, GLIBC_2_3_2) -strong_alias (__pthread_cond_destroy, __old_pthread_cond_destroy) -compat_symbol (libpthread, __old_pthread_cond_destroy, pthread_cond_destroy, - GLIBC_2_0); -#endif -#endif /* Function called by pthread_cancel to remove the thread from waiting on a condition variable queue. */ @@ -88,7 +55,7 @@ static int cond_extricate_func(void *obj, pthread_descr th) return did_remove; } -int __pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex) +int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex) { volatile pthread_descr self = thread_self(); pthread_extricate_if extr; @@ -165,16 +132,6 @@ int __pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex) pthread_mutex_lock(mutex); return 0; } -/* Don't bother with this version stuff in uClibc */ -#if 0 -versioned_symbol (libpthread, __pthread_cond_wait, pthread_cond_wait, - GLIBC_2_3_2); -#if SHLIB_COMPAT(libpthread, GLIBC_2_0, GLIBC_2_3_2) -strong_alias (__pthread_cond_wait, __old_pthread_cond_wait) -compat_symbol (libpthread, __old_pthread_cond_wait, pthread_cond_wait, - GLIBC_2_0); -#endif -#endif static int pthread_cond_timedwait_relative(pthread_cond_t *cond, @@ -270,24 +227,14 @@ pthread_cond_timedwait_relative(pthread_cond_t *cond, return 0; } -int __pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, - const struct timespec * abstime) +int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, + const struct timespec * abstime) { /* Indirect call through pointer! */ return pthread_cond_timedwait_relative(cond, mutex, abstime); } -/* Don't bother with this version stuff in uClibc */ -#if 0 -versioned_symbol (libpthread, __pthread_cond_timedwait, pthread_cond_timedwait, - GLIBC_2_3_2); -#if SHLIB_COMPAT(libpthread, GLIBC_2_0, GLIBC_2_3_2) -strong_alias (__pthread_cond_timedwait, __old_pthread_cond_timedwait) -compat_symbol (libpthread, __old_pthread_cond_timedwait, - pthread_cond_timedwait, GLIBC_2_0); -#endif -#endif - -int __pthread_cond_signal(pthread_cond_t *cond) + +int pthread_cond_signal(pthread_cond_t *cond) { pthread_descr th; @@ -301,18 +248,8 @@ int __pthread_cond_signal(pthread_cond_t *cond) } return 0; } -/* Don't bother with this version stuff in uClibc */ -#if 0 -versioned_symbol (libpthread, __pthread_cond_signal, pthread_cond_signal, - GLIBC_2_3_2); -#if SHLIB_COMPAT(libpthread, GLIBC_2_0, GLIBC_2_3_2) -strong_alias (__pthread_cond_signal, __old_pthread_cond_signal) -compat_symbol (libpthread, __old_pthread_cond_signal, pthread_cond_signal, - GLIBC_2_0); -#endif -#endif - -int __pthread_cond_broadcast(pthread_cond_t *cond) + +int pthread_cond_broadcast(pthread_cond_t *cond) { pthread_descr tosignal, th; @@ -329,28 +266,16 @@ int __pthread_cond_broadcast(pthread_cond_t *cond) } return 0; } -/* Don't bother with this version stuff in uClibc */ -#if 0 -versioned_symbol (libpthread, __pthread_cond_broadcast, pthread_cond_broadcast, - GLIBC_2_3_2); -#if SHLIB_COMPAT(libpthread, GLIBC_2_0, GLIBC_2_3_2) -strong_alias (__pthread_cond_broadcast, __old_pthread_cond_broadcast) -compat_symbol (libpthread, __old_pthread_cond_broadcast, - pthread_cond_broadcast, GLIBC_2_0); -#endif -#endif - -int __pthread_condattr_init(pthread_condattr_t *attr) + +int pthread_condattr_init(pthread_condattr_t *attr) { return 0; } -strong_alias (__pthread_condattr_init, pthread_condattr_init) -int __pthread_condattr_destroy(pthread_condattr_t *attr) +int pthread_condattr_destroy(pthread_condattr_t *attr) { return 0; } -strong_alias (__pthread_condattr_destroy, pthread_condattr_destroy) int pthread_condattr_getpshared (const pthread_condattr_t *attr, int *pshared) { diff --git a/libpthread/linuxthreads/descr.h b/libpthread/linuxthreads/descr.h deleted file mode 100644 index fb5fa350e..000000000 --- a/libpthread/linuxthreads/descr.h +++ /dev/null @@ -1,313 +0,0 @@ -/* Linuxthreads - a simple clone()-based implementation of Posix */ -/* threads for Linux. */ -/* Copyright (C) 1996 Xavier Leroy (Xavier.Leroy@inria.fr) */ -/* */ -/* This program is free software; you can redistribute it and/or */ -/* modify it under the terms of the GNU Library General Public License */ -/* as published by the Free Software Foundation; either version 2 */ -/* of the License, or (at your option) any later version. */ -/* */ -/* This program is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ -/* GNU Library General Public License for more details. */ - -#ifndef _DESCR_H -#define _DESCR_H 1 - -#include -#include -#include -#include -#include -#include -#include - -#if 1 -# include -#else -/* Fast thread-specific data internal to libc. */ -enum __libc_tsd_key_t { _LIBC_TSD_KEY_MALLOC = 0, - _LIBC_TSD_KEY_DL_ERROR, - _LIBC_TSD_KEY_RPC_VARS, - _LIBC_TSD_KEY_LOCALE, - _LIBC_TSD_KEY_CTYPE_B, - _LIBC_TSD_KEY_CTYPE_TOLOWER, - _LIBC_TSD_KEY_CTYPE_TOUPPER, - _LIBC_TSD_KEY_N }; -#endif - -/* The type of thread descriptors */ -typedef struct _pthread_descr_struct *pthread_descr; - - -/* Some more includes. */ -#include -#include "../linuxthreads_db/thread_dbP.h" - - -/* Arguments passed to thread creation routine */ -struct pthread_start_args { - void *(*start_routine)(void *); /* function to run */ - void *arg; /* its argument */ - sigset_t mask; /* initial signal mask for thread */ - int schedpolicy; /* initial scheduling policy (if any) */ - struct sched_param schedparam; /* initial scheduling parameters (if any) */ -}; - - -/* Callback interface for removing the thread from waiting on an - object if it is cancelled while waiting or about to wait. - This hold a pointer to the object, and a pointer to a function - which ``extricates'' the thread from its enqueued state. - The function takes two arguments: pointer to the wait object, - and a pointer to the thread. It returns 1 if an extrication - actually occured, and hence the thread must also be signalled. - It returns 0 if the thread had already been extricated. */ -typedef struct _pthread_extricate_struct { - void *pu_object; - int (*pu_extricate_func)(void *, pthread_descr); -} pthread_extricate_if; - - -/* Atomic counter made possible by compare_and_swap */ -struct pthread_atomic { - long p_count; - int p_spinlock; -}; - - -/* Context info for read write locks. The pthread_rwlock_info structure - is information about a lock that has been read-locked by the thread - in whose list this structure appears. The pthread_rwlock_context - is embedded in the thread context and contains a pointer to the - head of the list of lock info structures, as well as a count of - read locks that are untracked, because no info structure could be - allocated for them. */ -struct _pthread_rwlock_t; -typedef struct _pthread_rwlock_info { - struct _pthread_rwlock_info *pr_next; - struct _pthread_rwlock_t *pr_lock; - int pr_lock_count; -} pthread_readlock_info; - - -/* We keep thread specific data in a special data structure, a two-level - array. The top-level array contains pointers to dynamically allocated - arrays of a certain number of data pointers. So we can implement a - sparse array. Each dynamic second-level array has - PTHREAD_KEY_2NDLEVEL_SIZE - entries. This value shouldn't be too large. */ -#define PTHREAD_KEY_2NDLEVEL_SIZE 32 - -/* We need to address PTHREAD_KEYS_MAX key with PTHREAD_KEY_2NDLEVEL_SIZE - keys in each subarray. */ -#define PTHREAD_KEY_1STLEVEL_SIZE \ - ((PTHREAD_KEYS_MAX + PTHREAD_KEY_2NDLEVEL_SIZE - 1) \ - / PTHREAD_KEY_2NDLEVEL_SIZE) - - -union dtv; - -struct _pthread_descr_struct -{ -#if !defined USE_TLS || !TLS_DTV_AT_TP - /* This overlaps tcbhead_t (see tls.h), as used for TLS without threads. */ - union - { - struct - { - void *tcb; /* Pointer to the TCB. This is not always - the address of this thread descriptor. */ - union dtv *dtvp; - pthread_descr self; /* Pointer to this structure */ - int multiple_threads; -# ifdef NEED_DL_SYSINFO - uintptr_t sysinfo; -# endif - } data; - void *__padding[16]; - } p_header; -# define p_multiple_threads p_header.data.multiple_threads -#elif TLS_MULTIPLE_THREADS_IN_TCB - int p_multiple_threads; -#endif - - pthread_descr p_nextlive, p_prevlive; - /* Double chaining of active threads */ - pthread_descr p_nextwaiting; /* Next element in the queue holding the thr */ - pthread_descr p_nextlock; /* can be on a queue and waiting on a lock */ - pthread_t p_tid; /* Thread identifier */ - int p_pid; /* PID of Unix process */ - int p_priority; /* Thread priority (== 0 if not realtime) */ - struct _pthread_fastlock * p_lock; /* Spinlock for synchronized accesses */ - int p_signal; /* last signal received */ - sigjmp_buf * p_signal_jmp; /* where to siglongjmp on a signal or NULL */ - sigjmp_buf * p_cancel_jmp; /* where to siglongjmp on a cancel or NULL */ - char p_terminated; /* true if terminated e.g. by pthread_exit */ - char p_detached; /* true if detached */ - char p_exited; /* true if the assoc. process terminated */ - void * p_retval; /* placeholder for return value */ - int p_retcode; /* placeholder for return code */ - pthread_descr p_joining; /* thread joining on that thread or NULL */ - struct _pthread_cleanup_buffer * p_cleanup; /* cleanup functions */ - char p_cancelstate; /* cancellation state */ - char p_canceltype; /* cancellation type (deferred/async) */ - char p_canceled; /* cancellation request pending */ - char * p_in_sighandler; /* stack address of sighandler, or NULL */ - char p_sigwaiting; /* true if a sigwait() is in progress */ - struct pthread_start_args p_start_args; /* arguments for thread creation */ - void ** p_specific[PTHREAD_KEY_1STLEVEL_SIZE]; /* thread-specific data */ -#if !(USE_TLS && HAVE___THREAD) - void * p_libc_specific[_LIBC_TSD_KEY_N]; /* thread-specific data for libc */ - int * p_errnop; /* pointer to used errno variable */ - int p_errno; /* error returned by last system call */ - int * p_h_errnop; /* pointer to used h_errno variable */ - int p_h_errno; /* error returned by last netdb function */ -#endif - int p_userstack; /* nonzero if the user provided the stack */ - void *p_guardaddr; /* address of guard area or NULL */ - size_t p_guardsize; /* size of guard area */ - pthread_descr p_self; /* Pointer to this structure */ - int p_nr; /* Index of descriptor in __pthread_handles */ - int p_report_events; /* Nonzero if events must be reported. */ - td_eventbuf_t p_eventbuf; /* Data for event. */ - struct pthread_atomic p_resume_count; /* number of times restart() was - called on thread */ - char p_woken_by_cancel; /* cancellation performed wakeup */ - char p_condvar_avail; /* flag if conditional variable became avail */ - char p_sem_avail; /* flag if semaphore became available */ - pthread_extricate_if *p_extricate; /* See above */ - pthread_readlock_info *p_readlock_list; /* List of readlock info structs */ - pthread_readlock_info *p_readlock_free; /* Free list of structs */ - int p_untracked_readlock_count; /* Readlocks not tracked by list */ - int p_inheritsched; /* copied from the thread attribute */ -#if HP_TIMING_AVAIL - hp_timing_t p_cpuclock_offset; /* Initial CPU clock for thread. */ -#endif -#ifdef USE_TLS - char *p_stackaddr; /* Stack address. */ -#endif - size_t p_alloca_cutoff; /* Maximum size which should be allocated - using alloca() instead of malloc(). */ - /* New elements must be added at the end. */ -#ifdef __UCLIBC_HAS_XLOCALE__ - __locale_t locale; /* thread-specific locale from uselocale() only! */ -#endif /* __UCLIBC_HAS_XLOCALE__ */ -} __attribute__ ((aligned(32))); /* We need to align the structure so that - doubles are aligned properly. This is 8 - bytes on MIPS and 16 bytes on MIPS64. - 32 bytes might give better cache - utilization. */ - - - -/* Limit between the stack of the initial thread (above) and the - stacks of other threads (below). Aligned on a STACK_SIZE boundary. - Initially 0, meaning that the current thread is (by definition) - the initial thread. */ - -/* For non-MMU systems also remember to stack top of the initial thread. - * This is adapted when other stacks are malloc'ed since we don't know - * the bounds a-priori. -StS */ - -extern char *__pthread_initial_thread_bos; -#ifndef __ARCH_HAS_MMU__ -extern char *__pthread_initial_thread_tos; -#define NOMMU_INITIAL_THREAD_BOUNDS(tos,bos) \ - if ((tos)>=__pthread_initial_thread_bos \ - && (bos)<__pthread_initial_thread_tos) \ - __pthread_initial_thread_bos = (tos)+1 -#else -#define NOMMU_INITIAL_THREAD_BOUNDS(tos,bos) /* empty */ -#endif /* __ARCH_HAS_MMU__ */ - -/* Descriptor of the initial thread */ - -extern struct _pthread_descr_struct __pthread_initial_thread; - -/* Limits of the thread manager stack. */ - -extern char *__pthread_manager_thread_bos; -extern char *__pthread_manager_thread_tos; - -/* Descriptor of the manager thread */ - -extern struct _pthread_descr_struct __pthread_manager_thread; -extern pthread_descr __pthread_manager_threadp attribute_hidden; - -/* Indicate whether at least one thread has a user-defined stack (if 1), - or all threads have stacks supplied by LinuxThreads (if 0). */ - -extern int __pthread_nonstandard_stacks; - -/* The max size of the thread stack segments. If the default - THREAD_SELF implementation is used, this must be a power of two and - a multiple of PAGE_SIZE. */ -#ifndef STACK_SIZE -#ifdef __ARCH_HAS_MMU__ -#define STACK_SIZE (2 * 1024 * 1024) -#else -#define STACK_SIZE (4 * __pagesize) -#endif -#endif - -/* Get some notion of the current stack. Need not be exactly the top - of the stack, just something somewhere in the current frame. */ -#ifndef CURRENT_STACK_FRAME -#define CURRENT_STACK_FRAME ({ char __csf; &__csf; }) -#endif - -/* Recover thread descriptor for the current thread */ - -extern pthread_descr __pthread_find_self (void) __attribute__ ((pure)); - -static inline pthread_descr thread_self (void) __attribute__ ((pure)); -static inline pthread_descr thread_self (void) -{ -#ifdef THREAD_SELF - return THREAD_SELF; -#else - char *sp = CURRENT_STACK_FRAME; -#ifdef __ARCH_HAS_MMU__ - if (sp >= __pthread_initial_thread_bos) - return &__pthread_initial_thread; - else if (sp >= __pthread_manager_thread_bos - && sp < __pthread_manager_thread_tos) - return &__pthread_manager_thread; - else if (__pthread_nonstandard_stacks) - return __pthread_find_self(); - else -#ifdef _STACK_GROWS_DOWN - return (pthread_descr)(((unsigned long)sp | (STACK_SIZE-1))+1) - 1; -#else - return (pthread_descr)((unsigned long)sp &~ (STACK_SIZE-1)); -#endif -#else /* !__ARCH_HAS_MMU__ */ - /* For non-MMU we need to be more careful about the initial thread stack. - * We refine the initial thread stack bounds dynamically as we allocate - * the other stack frame such that it doesn't overlap with them. Then - * we can be sure to pick the right thread according to the current SP */ - - /* Since we allow other stack frames to be above or below, we need to - * treat this case special. When pthread_initialize() wasn't called yet, - * only the initial thread is there. */ - if (__pthread_initial_thread_bos == NULL) { - return &__pthread_initial_thread; - } - else if (sp >= __pthread_initial_thread_bos - && sp < __pthread_initial_thread_tos) { - return &__pthread_initial_thread; - } - else if (sp >= __pthread_manager_thread_bos - && sp < __pthread_manager_thread_tos) { - return &__pthread_manager_thread; - } - else { - return __pthread_find_self(); - } -#endif /* __ARCH_HAS_MMU__ */ -#endif -} - -#endif /* descr.h */ diff --git a/libpthread/linuxthreads/events.c b/libpthread/linuxthreads/events.c index b4ca3846e..a4bf1f898 100644 --- a/libpthread/linuxthreads/events.c +++ b/libpthread/linuxthreads/events.c @@ -1,18 +1,18 @@ /* Event functions used while debugging. - Copyright (C) 1999, 2000 Free Software Foundation, Inc. + Copyright (C) 1999 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation; either version 2.1 of the + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. The GNU C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. + Library General Public License for more details. - You should have received a copy of the GNU Lesser General Public + You should have received a copy of the GNU Library General Public License along with the GNU C Library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ diff --git a/libpthread/linuxthreads/internals.h b/libpthread/linuxthreads/internals.h index 98dcf4db2..50a4d2d59 100644 --- a/libpthread/linuxthreads/internals.h +++ b/libpthread/linuxthreads/internals.h @@ -13,28 +13,24 @@ /* GNU Library General Public License for more details. */ #ifndef _INTERNALS_H -#define _INTERNALS_H 1 +#define _INTERNALS_H 1 /* Internal data structures */ /* Includes */ -#include #include /* for _LIBC_TSD_KEY_N */ #include #include #include #include -#include #include #include "pt-machine.h" -#include -#include #include "semaphore.h" +#include "../linuxthreads_db/thread_dbP.h" #ifdef __UCLIBC_HAS_XLOCALE__ #include #endif /* __UCLIBC_HAS_XLOCALE__ */ -#include "descr.h" /* Use a funky version in a probably vein attempt at preventing gdb * from dlopen()'ing glibc's libthread_db library... */ @@ -55,14 +51,30 @@ # define THREAD_SETMEM_NC(descr, member, value) descr->member = (value) #endif -#if !defined NOT_IN_libc && defined FLOATING_STACKS -# define LIBC_THREAD_GETMEM(descr, member) THREAD_GETMEM (descr, member) -# define LIBC_THREAD_SETMEM(descr, member, value) \ - THREAD_SETMEM (descr, member, value) -#else -# define LIBC_THREAD_GETMEM(descr, member) descr->member -# define LIBC_THREAD_SETMEM(descr, member, value) descr->member = (value) -#endif +/* Arguments passed to thread creation routine */ + +struct pthread_start_args { + void * (*start_routine)(void *); /* function to run */ + void * arg; /* its argument */ + sigset_t mask; /* initial signal mask for thread */ + int schedpolicy; /* initial scheduling policy (if any) */ + struct sched_param schedparam; /* initial scheduling parameters (if any) */ +}; + + +/* We keep thread specific data in a special data structure, a two-level + array. The top-level array contains pointers to dynamically allocated + arrays of a certain number of data pointers. So we can implement a + sparse array. Each dynamic second-level array has + PTHREAD_KEY_2NDLEVEL_SIZE + entries. This value shouldn't be too large. */ +#define PTHREAD_KEY_2NDLEVEL_SIZE 32 + +/* We need to address PTHREAD_KEYS_MAX key with PTHREAD_KEY_2NDLEVEL_SIZE + keys in each subarray. */ +#define PTHREAD_KEY_1STLEVEL_SIZE \ + ((PTHREAD_KEYS_MAX + PTHREAD_KEY_2NDLEVEL_SIZE - 1) \ + / PTHREAD_KEY_2NDLEVEL_SIZE) typedef void (*destr_function)(void *); @@ -72,9 +84,105 @@ struct pthread_key_struct { }; -#define PTHREAD_START_ARGS_INITIALIZER(fct) \ - { (void *(*) (void *)) fct, NULL, {{0, }}, 0, { 0 } } +#define PTHREAD_START_ARGS_INITIALIZER { NULL, NULL, {{0, }}, 0, { 0 } } + +/* The type of thread descriptors */ + +typedef struct _pthread_descr_struct * pthread_descr; + +/* Callback interface for removing the thread from waiting on an + object if it is cancelled while waiting or about to wait. + This hold a pointer to the object, and a pointer to a function + which ``extricates'' the thread from its enqueued state. + The function takes two arguments: pointer to the wait object, + and a pointer to the thread. It returns 1 if an extrication + actually occured, and hence the thread must also be signalled. + It returns 0 if the thread had already been extricated. */ + +typedef struct _pthread_extricate_struct { + void *pu_object; + int (*pu_extricate_func)(void *, pthread_descr); +} pthread_extricate_if; + +/* Atomic counter made possible by compare_and_swap */ + +struct pthread_atomic { + long p_count; + int p_spinlock; +}; +/* Context info for read write locks. The pthread_rwlock_info structure + is information about a lock that has been read-locked by the thread + in whose list this structure appears. The pthread_rwlock_context + is embedded in the thread context and contains a pointer to the + head of the list of lock info structures, as well as a count of + read locks that are untracked, because no info structure could be + allocated for them. */ + +struct _pthread_rwlock_t; + +typedef struct _pthread_rwlock_info { + struct _pthread_rwlock_info *pr_next; + struct _pthread_rwlock_t *pr_lock; + int pr_lock_count; +} pthread_readlock_info; + +struct _pthread_descr_struct { + pthread_descr p_nextlive, p_prevlive; + /* Double chaining of active threads */ + pthread_descr p_nextwaiting; /* Next element in the queue holding the thr */ + pthread_descr p_nextlock; /* can be on a queue and waiting on a lock */ + pthread_t p_tid; /* Thread identifier */ + int p_pid; /* PID of Unix process */ + int p_priority; /* Thread priority (== 0 if not realtime) */ + struct _pthread_fastlock * p_lock; /* Spinlock for synchronized accesses */ + int p_signal; /* last signal received */ + sigjmp_buf * p_signal_jmp; /* where to siglongjmp on a signal or NULL */ + sigjmp_buf * p_cancel_jmp; /* where to siglongjmp on a cancel or NULL */ + char p_terminated; /* true if terminated e.g. by pthread_exit */ + char p_detached; /* true if detached */ + char p_exited; /* true if the assoc. process terminated */ + void * p_retval; /* placeholder for return value */ + int p_retcode; /* placeholder for return code */ + pthread_descr p_joining; /* thread joining on that thread or NULL */ + struct _pthread_cleanup_buffer * p_cleanup; /* cleanup functions */ + char p_cancelstate; /* cancellation state */ + char p_canceltype; /* cancellation type (deferred/async) */ + char p_canceled; /* cancellation request pending */ + int * p_errnop; /* pointer to used errno variable */ + int p_errno; /* error returned by last system call */ + int * p_h_errnop; /* pointer to used h_errno variable */ + int p_h_errno; /* error returned by last netdb function */ + char * p_in_sighandler; /* stack address of sighandler, or NULL */ + char p_sigwaiting; /* true if a sigwait() is in progress */ + struct pthread_start_args p_start_args; /* arguments for thread creation */ + void ** p_specific[PTHREAD_KEY_1STLEVEL_SIZE]; /* thread-specific data */ + void * p_libc_specific[_LIBC_TSD_KEY_N]; /* thread-specific data for libc */ + int p_userstack; /* nonzero if the user provided the stack */ + void *p_guardaddr; /* address of guard area or NULL */ + size_t p_guardsize; /* size of guard area */ + pthread_descr p_self; /* Pointer to this structure */ + int p_nr; /* Index of descriptor in __pthread_handles */ + int p_report_events; /* Nonzero if events must be reported. */ + td_eventbuf_t p_eventbuf; /* Data for event. */ + struct pthread_atomic p_resume_count; /* number of times restart() was + called on thread */ + char p_woken_by_cancel; /* cancellation performed wakeup */ + char p_condvar_avail; /* flag if conditional variable became avail */ + char p_sem_avail; /* flag if semaphore became available */ + pthread_extricate_if *p_extricate; /* See above */ + pthread_readlock_info *p_readlock_list; /* List of readlock info structs */ + pthread_readlock_info *p_readlock_free; /* Free list of structs */ + int p_untracked_readlock_count; /* Readlocks not tracked by list */ + /* New elements must be added at the end. */ +#ifdef __UCLIBC_HAS_XLOCALE__ + __locale_t locale; /* thread-specific locale from uselocale() only! */ +#endif /* __UCLIBC_HAS_XLOCALE__ */ +} __attribute__ ((aligned(32))); /* We need to align the structure so that + doubles are aligned properly. This is 8 + bytes on MIPS and 16 bytes on MIPS64. + 32 bytes might give better cache + utilization. */ /* The type of thread handles. */ @@ -92,7 +200,7 @@ struct pthread_request { pthread_descr req_thread; /* Thread doing the request */ enum { /* Request kind */ REQ_CREATE, REQ_FREE, REQ_PROCESS_EXIT, REQ_MAIN_THREAD_EXIT, - REQ_POST, REQ_DEBUG, REQ_KICK, REQ_FOR_EACH_THREAD + REQ_POST, REQ_DEBUG, REQ_KICK } req_kind; union { /* Arguments for request */ struct { /* For REQ_CREATE: */ @@ -108,24 +216,10 @@ struct pthread_request { int code; /* exit status */ } exit; void * post; /* For REQ_POST: the semaphore */ - struct { /* For REQ_FOR_EACH_THREAD: callback */ - void (*fn)(void *, pthread_descr); - void *arg; - } for_each; } req_args; }; - -typedef void (*arch_sighandler_t) (int, SIGCONTEXT); -union sighandler -{ - arch_sighandler_t old; - void (*rt) (int, struct siginfo *, struct ucontext *); -}; -extern union sighandler __sighandler[NSIG]; - - /* Signals used for suspend/restart and for cancellation notification. */ extern int __pthread_sig_restart; @@ -141,10 +235,44 @@ extern int __pthread_sig_debug; extern struct pthread_handle_struct __pthread_handles[PTHREAD_THREADS_MAX]; +/* Descriptor of the initial thread */ + +extern struct _pthread_descr_struct __pthread_initial_thread; + +/* Descriptor of the manager thread */ + +extern struct _pthread_descr_struct __pthread_manager_thread; + /* Descriptor of the main thread */ extern pthread_descr __pthread_main_thread; +/* Limit between the stack of the initial thread (above) and the + stacks of other threads (below). Aligned on a STACK_SIZE boundary. + Initially 0, meaning that the current thread is (by definition) + the initial thread. */ + +/* For non-MMU systems also remember to stack top of the initial thread. + * This is adapted when other stacks are malloc'ed since we don't know + * the bounds a-priori. -StS */ + +extern char *__pthread_initial_thread_bos; +#ifndef __ARCH_HAS_MMU__ +extern char *__pthread_initial_thread_tos; +#define NOMMU_INITIAL_THREAD_BOUNDS(tos,bos) \ + if ((tos)>=__pthread_initial_thread_bos \ + && (bos)<__pthread_initial_thread_tos) \ + __pthread_initial_thread_bos = (tos)+1 +#else +#define NOMMU_INITIAL_THREAD_BOUNDS(tos,bos) /* empty */ +#endif /* __ARCH_HAS_MMU__ */ + + +/* Indicate whether at least one thread has a user-defined stack (if 1), + or all threads have stacks supplied by LinuxThreads (if 0). */ + +extern int __pthread_nonstandard_stacks; + /* File descriptor for sending requests to the thread manager. Initially -1, meaning that __pthread_initialize_manager must be called. */ @@ -154,10 +282,10 @@ extern int __pthread_manager_request; extern int __pthread_manager_reader; -#ifdef FLOATING_STACKS -/* Maximum stack size. */ -extern size_t __pthread_max_stacksize; -#endif +/* Limits of the thread manager stack. */ + +extern char *__pthread_manager_thread_bos; +extern char *__pthread_manager_thread_tos; /* Pending request for a process-wide exit */ @@ -173,9 +301,6 @@ extern volatile td_thr_events_t __pthread_threads_events; /* Pointer to descriptor of thread with last event. */ extern volatile pthread_descr __pthread_last_event; -/* Flag which tells whether we are executing on SMP kernel. */ -extern int __pthread_smp_kernel; - /* Return the handle corresponding to a thread id */ static inline pthread_handle thread_handle(pthread_t id) @@ -186,28 +311,29 @@ static inline pthread_handle thread_handle(pthread_t id) /* Validate a thread handle. Must have acquired h->h_spinlock before. */ static inline int invalid_handle(pthread_handle h, pthread_t id) -{ - return h->h_descr == NULL || h->h_descr->p_tid != id || h->h_descr->p_terminated; -} - -static inline int nonexisting_handle(pthread_handle h, pthread_t id) { return h->h_descr == NULL || h->h_descr->p_tid != id; } /* Fill in defaults left unspecified by pt-machine.h. */ -/* We round up a value with page size. */ -#ifndef page_roundup -#define page_roundup(v,p) ((((size_t) (v)) + (p) - 1) & ~((p) - 1)) -#endif - /* The page size we can get from the system. This should likely not be changed by the machine file but, you never know. */ extern size_t __pagesize; #include #ifndef PAGE_SIZE -#define PAGE_SIZE (sysconf (_SC_PAGE_SIZE)) +#define PAGE_SIZE (sysconf (_SC_PAGESIZE)) +#endif + +/* The max size of the thread stack segments. If the default + THREAD_SELF implementation is used, this must be a power of two and + a multiple of PAGE_SIZE. */ +#ifndef STACK_SIZE +#ifdef __ARCH_HAS_MMU__ +#define STACK_SIZE (2 * 1024 * 1024) +#else +#define STACK_SIZE (4 * __pagesize) +#endif #endif /* The initial size of the thread stack. Must be a multiple of PAGE_SIZE. */ @@ -228,12 +354,17 @@ extern size_t __pagesize; #define THREAD_STACK_START_ADDRESS __pthread_initial_thread_bos #endif +/* Get some notion of the current stack. Need not be exactly the top + of the stack, just something somewhere in the current frame. */ +#ifndef CURRENT_STACK_FRAME +#define CURRENT_STACK_FRAME ({ char __csf; &__csf; }) +#endif + /* If MEMORY_BARRIER isn't defined in pt-machine.h, assume the architecture doesn't need a memory barrier instruction (e.g. Intel x86). Still we need the compiler to respect the barrier and emit all outstanding operations which modify memory. Some architectures distinguish between full, read and write barriers. */ - #ifndef MEMORY_BARRIER #define MEMORY_BARRIER() asm ("" : : : "memory") #endif @@ -244,6 +375,54 @@ extern size_t __pagesize; #define WRITE_MEMORY_BARRIER() MEMORY_BARRIER() #endif +/* Recover thread descriptor for the current thread */ + +extern pthread_descr __pthread_find_self (void) __attribute__ ((const)); + +static inline pthread_descr thread_self (void) __attribute__ ((const)); +static inline pthread_descr thread_self (void) +{ +#ifdef THREAD_SELF + return THREAD_SELF; +#else + char *sp = CURRENT_STACK_FRAME; +#ifdef __ARCH_HAS_MMU__ + if (sp >= __pthread_initial_thread_bos) + return &__pthread_initial_thread; + else if (sp >= __pthread_manager_thread_bos + && sp < __pthread_manager_thread_tos) + return &__pthread_manager_thread; + else if (__pthread_nonstandard_stacks) + return __pthread_find_self(); + else + return (pthread_descr)(((unsigned long)sp | (STACK_SIZE-1))+1) - 1; +#else + /* For non-MMU we need to be more careful about the initial thread stack. + * We refine the initial thread stack bounds dynamically as we allocate + * the other stack frame such that it doesn't overlap with them. Then + * we can be sure to pick the right thread according to the current SP */ + + /* Since we allow other stack frames to be above or below, we need to + * treat this case special. When pthread_initialize() wasn't called yet, + * only the initial thread is there. */ + if (__pthread_initial_thread_bos == NULL) { + return &__pthread_initial_thread; + } + else if (sp >= __pthread_initial_thread_bos + && sp < __pthread_initial_thread_tos) { + return &__pthread_initial_thread; + } + else if (sp >= __pthread_manager_thread_bos + && sp < __pthread_manager_thread_tos) { + return &__pthread_manager_thread; + } + else { + return __pthread_find_self(); + } +#endif /* __ARCH_HAS_MMU__ */ +#endif +} + /* Max number of times we must spin on a spinlock calling sched_yield(). After MAX_SPIN_COUNT iterations, we put the calling thread to sleep. */ @@ -251,13 +430,6 @@ extern size_t __pagesize; #define MAX_SPIN_COUNT 50 #endif -/* Max number of times the spinlock in the adaptive mutex implementation - spins actively on SMP systems. */ - -#ifndef MAX_ADAPTIVE_SPIN_COUNT -#define MAX_ADAPTIVE_SPIN_COUNT 100 -#endif - /* Duration of sleep (in nanoseconds) when we can't acquire a spinlock after MAX_SPIN_COUNT iterations of sched_yield(). With the 2.0 and 2.1 kernels, this MUST BE > 2ms. @@ -283,7 +455,6 @@ extern size_t __pagesize; void __pthread_destroy_specifics(void); void __pthread_perform_cleanup(void); -void __pthread_init_max_stacksize (void); int __pthread_initialize_manager(void); void __pthread_message(char * fmt, ...); int __pthread_manager(void *reqfd); diff --git a/libpthread/linuxthreads/join.c b/libpthread/linuxthreads/join.c index 83761e199..5aeec6a20 100644 --- a/libpthread/linuxthreads/join.c +++ b/libpthread/linuxthreads/join.c @@ -124,7 +124,7 @@ int pthread_join(pthread_t thread_id, void ** thread_return) extr.pu_extricate_func = join_extricate_func; __pthread_lock(&handle->h_lock, self); - if (nonexisting_handle(handle, thread_id)) { + if (invalid_handle(handle, thread_id)) { __pthread_unlock(&handle->h_lock); return ESRCH; } @@ -190,7 +190,7 @@ int pthread_detach(pthread_t thread_id) pthread_descr th; __pthread_lock(&handle->h_lock, NULL); - if (nonexisting_handle(handle, thread_id)) { + if (invalid_handle(handle, thread_id)) { __pthread_unlock(&handle->h_lock); return ESRCH; } diff --git a/libpthread/linuxthreads/manager.c b/libpthread/linuxthreads/manager.c index d2e3d5c22..204344aef 100644 --- a/libpthread/linuxthreads/manager.c +++ b/libpthread/linuxthreads/manager.c @@ -14,12 +14,9 @@ /* The "thread manager" thread: manages creation and termination of threads */ -/* mods for uClibc */ +/* mods for uClibc: getpwd and getpagesize are the syscalls */ #define __getpid getpid #define __getpagesize getpagesize -#define __sched_get_priority_max sched_get_priority_max -#define __sched_getscheduler sched_getscheduler -#define __sched_getparam sched_getparam #include #define __USE_GNU @@ -84,13 +81,8 @@ volatile pthread_descr __pthread_last_event; static inline pthread_descr thread_segment(int seg) { -# ifdef _STACK_GROWS_UP - return (pthread_descr)(THREAD_STACK_START_ADDRESS + (seg - 1) * STACK_SIZE) - + 1; -# else return (pthread_descr)(THREAD_STACK_START_ADDRESS - (seg - 1) * STACK_SIZE) - 1; -# endif } /* Flag set in signal handler to record child termination */ @@ -115,18 +107,13 @@ static int pthread_handle_create(pthread_t *thread, const pthread_attr_t *attr, int report_events, td_thr_events_t *event_maskp); static void pthread_handle_free(pthread_t th_id); -static void pthread_handle_exit(pthread_descr issuing_thread, int exitcode) - __attribute__ ((noreturn)); +static void pthread_handle_exit(pthread_descr issuing_thread, int exitcode); static void pthread_reap_children(void); static void pthread_kill_all_threads(int sig, int main_thread_also); -static void pthread_for_each_thread(void *arg, - void (*fn)(void *, pthread_descr)); /* The server thread managing requests for thread creation and termination */ -int -__attribute__ ((noreturn)) -__pthread_manager(void *arg) +int __pthread_manager(void *arg) { int reqfd = (int) (long int) arg; #ifdef USE_SELECT @@ -157,7 +144,7 @@ __pthread_manager(void *arg) sigdelset(&manager_mask, __pthread_sig_cancel); /* for thread termination */ sigdelset(&manager_mask, SIGTRAP); /* for debugging purposes */ if (__pthread_threads_debug && __pthread_sig_debug > 0) - sigdelset(&manager_mask, __pthread_sig_debug); + sigdelset(&manager_mask, __pthread_sig_debug); sigprocmask(SIG_SETMASK, &manager_mask, NULL); /* Raise our priority to match that of main thread */ __pthread_manager_adjust_prio(__pthread_main_thread->p_priority); @@ -253,21 +240,14 @@ __pthread_manager(void *arg) PDEBUG("got REQ_DEBUG\n"); /* Make gdb aware of new thread and gdb will restart the new thread when it is ready to handle the new thread. */ - if (__pthread_threads_debug && __pthread_sig_debug > 0) - { - PDEBUG("about to call raise(__pthread_sig_debug)\n"); + if (__pthread_threads_debug && __pthread_sig_debug > 0) { + PDEBUG("about to call raise(__pthread_sig_debug)\n"); raise(__pthread_sig_debug); } - break; case REQ_KICK: /* This is just a prod to get the manager to reap some threads right away, avoiding a potential delay at shutdown. */ break; - case REQ_FOR_EACH_THREAD: - pthread_for_each_thread(request.req_args.for_each.arg, - request.req_args.for_each.fn); - restart(request.req_thread); - break; } } } @@ -289,7 +269,6 @@ int __pthread_manager_event(void *arg) } /* Process creation */ - static int __attribute__ ((noreturn)) pthread_start_thread(void *arg) @@ -297,16 +276,9 @@ pthread_start_thread(void *arg) pthread_descr self = (pthread_descr) arg; struct pthread_request request; void * outcome; -#if HP_TIMING_AVAIL - hp_timing_t tmpclock; -#endif /* Initialize special thread_self processing, if any. */ #ifdef INIT_THREAD_SELF INIT_THREAD_SELF(self, self->p_nr); -#endif -#if HP_TIMING_AVAIL - HP_TIMING_NOW (tmpclock); - THREAD_SETMEM (self, p_cpuclock_offset, tmpclock); #endif PDEBUG("\n"); /* Make sure our pid field is initialized, just in case we get there @@ -381,39 +353,12 @@ static int pthread_allocate_stack(const pthread_attr_t *attr, if (attr != NULL && attr->__stackaddr_set) { -#ifdef _STACK_GROWS_UP /* The user provided a stack. */ -# ifdef USE_TLS - /* This value is not needed. */ - new_thread = (pthread_descr) attr->__stackaddr; - new_thread_bottom = (char *) new_thread; -# else - new_thread = (pthread_descr) attr->__stackaddr; - new_thread_bottom = (char *) (new_thread + 1); -# endif - guardaddr = attr->__stackaddr + attr->__stacksize; - guardsize = 0; -#else - /* The user provided a stack. For now we interpret the supplied - address as 1 + the highest addr. in the stack segment. If a - separate register stack is needed, we place it at the low end - of the segment, relying on the associated stacksize to - determine the low end of the segment. This differs from many - (but not all) other pthreads implementations. The intent is - that on machines with a single stack growing toward higher - addresses, stackaddr would be the lowest address in the stack - segment, so that it is consistently close to the initial sp - value. */ -# ifdef USE_TLS - new_thread = (pthread_descr) attr->__stackaddr; -# else new_thread = (pthread_descr) ((long)(attr->__stackaddr) & -sizeof(void *)) - 1; -# endif new_thread_bottom = (char *) attr->__stackaddr - attr->__stacksize; guardaddr = NULL; guardsize = 0; -#endif __pthread_nonstandard_stacks = 1; } else @@ -538,7 +483,7 @@ static int pthread_handle_create(pthread_t *thread, const pthread_attr_t *attr, /* First check whether we have to change the policy and if yes, whether we can do this. Normally this should be done by examining the - return value of the __sched_setscheduler call in pthread_start_thread + return value of the sched_setscheduler call in pthread_start_thread but this is hard to implement. FIXME */ if (attr != NULL && attr->__schedpolicy != SCHED_OTHER && geteuid () != 0) return EPERM; @@ -591,8 +536,8 @@ static int pthread_handle_create(pthread_t *thread, const pthread_attr_t *attr, sizeof (struct sched_param)); break; case PTHREAD_INHERIT_SCHED: - new_thread->p_start_args.schedpolicy = __sched_getscheduler(father_pid); - __sched_getparam(father_pid, &new_thread->p_start_args.schedparam); + new_thread->p_start_args.schedpolicy = sched_getscheduler(father_pid); + sched_getparam(father_pid, &new_thread->p_start_args.schedparam); break; } new_thread->p_priority = @@ -633,36 +578,17 @@ static int pthread_handle_create(pthread_t *thread, const pthread_attr_t *attr, __pthread_lock(new_thread->p_lock, NULL); /* We have to report this event. */ -#ifdef NEED_SEPARATE_REGISTER_STACK - /* Perhaps this version should be used on all platforms. But - this requires that __clone2 be uniformly supported - everywhere. - - And th