* attr.c (pthread_getattr_np): Don't take thread descriptor size
	into account if USE_TLS.
	* manager.c (pthread_handle_create): Free TLS data structures if call
	failed.  Pass correct stack to clone if USE_TLS.
	* sysdeps/i386/pt-machine.h: Handle multiple inclusion.
	* sysdeps/i386/i686/pt-machine.h: Likewise.
	* sysdeps/i386/tls.h: Unconditionally include <pt-machine.h>.
This commit is contained in:
Ulrich Drepper 2002-02-24 04:57:56 +00:00
parent 6370466d5a
commit b6a0a99693
6 changed files with 61 additions and 8 deletions

View File

@ -1,5 +1,13 @@
2002-02-23 Ulrich Drepper <drepper@redhat.com>
* attr.c (pthread_getattr_np): Don't take thread descriptor size
into account if USE_TLS.
* manager.c (pthread_handle_create): Free TLS data structures if call
failed. Pass correct stack to clone if USE_TLS.
* sysdeps/i386/pt-machine.h: Handle multiple inclusion.
* sysdeps/i386/i686/pt-machine.h: Likewise.
* sysdeps/i386/tls.h: Unconditionally include <pt-machine.h>.
* descr.h (struct _pthread_descr_struct): Update p_header for TLS.
Add p_stackaddr element #if USE_TLS.
* internals.c: Include <tls.h>.

View File

@ -283,10 +283,19 @@ int pthread_getattr_np (pthread_t thread, pthread_attr_t *attr)
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;
@ -298,10 +307,14 @@ int pthread_getattr_np (pthread_t thread, pthread_attr_t *attr)
otherwise the range of the stack area cannot be computed. */
attr->__stacksize += attr->__guardsize;
#endif
#ifndef _STACK_GROWS_UP
attr->__stackaddr = (char *)(descr + 1);
#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
return 0;

View File

@ -593,6 +593,9 @@ static int pthread_handle_create(pthread_t *thread, const pthread_attr_t *attr,
new_thread = _dl_allocate_tls ();
if (new_thread == NULL)
return EAGAIN;
#else
/* Prevent warnings. */
new_thread = NULL;
#endif
/* First check whether we have to change the policy and if yes, whether
@ -605,7 +608,12 @@ static int pthread_handle_create(pthread_t *thread, const pthread_attr_t *attr,
for (sseg = 2; ; sseg++)
{
if (sseg >= PTHREAD_THREADS_MAX)
return EAGAIN;
{
#ifdef USE_TLS
_dl_deallocate_tls (new_thread);
#endif
return EAGAIN;
}
if (__pthread_handles[sseg].h_descr != NULL)
continue;
if (pthread_allocate_stack(attr, thread_segment(sseg),
@ -741,15 +749,15 @@ static int pthread_handle_create(pthread_t *thread, const pthread_attr_t *attr,
#ifdef NEED_SEPARATE_REGISTER_STACK
pid = __clone2(pthread_start_thread,
(void **)new_thread_bottom,
(char *)new_thread - new_thread_bottom,
(char *)stack_addr - new_thread_bottom,
CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND |
__pthread_sig_cancel, new_thread);
#elif _STACK_GROWS_UP
pid = __clone(pthread_start_thread, (void **) new_thread_bottom,
pid = __clone(pthread_start_thread, (void *) new_thread_bottom,
CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND |
__pthread_sig_cancel, new_thread);
#else
pid = __clone(pthread_start_thread, (void **) new_thread,
pid = __clone(pthread_start_thread, stack_addr,
CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND |
__pthread_sig_cancel, new_thread);
#endif /* !NEED_SEPARATE_REGISTER_STACK */
@ -766,13 +774,25 @@ static int pthread_handle_create(pthread_t *thread, const pthread_attr_t *attr,
munmap((caddr_t)new_thread_bottom,
2 * stacksize + new_thread->p_guardsize);
#elif _STACK_GROWS_UP
# ifdef USE_TLS
size_t stacksize = guardaddr - stack_addr;
munmap(stack_addr, stacksize + guardsize);
# else
size_t stacksize = guardaddr - (char *)new_thread;
munmap(new_thread, stacksize + guardsize);
# endif
#else
# ifdef USE_TLS
size_t stacksize = stack_addr - new_thread_bottom;
# else
size_t stacksize = (char *)(new_thread+1) - new_thread_bottom;
# endif
munmap(new_thread_bottom - guardsize, guardsize + stacksize);
#endif
}
#ifdef USE_TLS
_dl_deallocate_tls (new_thread);
#endif
__pthread_handles[sseg].h_descr = NULL;
__pthread_handles[sseg].h_bottom = NULL;
__pthread_handles_num--;

View File

@ -1,6 +1,6 @@
/* Machine-dependent pthreads configuration and inline functions.
i686 version.
Copyright (C) 1996, 1997, 1998, 2000, 2001 Free Software Foundation, Inc.
Copyright (C) 1996-2001, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Richard Henderson <rth@tamu.edu>.
@ -19,6 +19,9 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#ifndef _PT_MACHINE_H
#define _PT_MACHINE_H 1
#ifndef PT_EI
# define PT_EI extern inline
#endif
@ -67,3 +70,5 @@ __compare_and_swap (long int *p, long int oldval, long int newval)
/* The P4 and above really want some help to prevent overheating. */
#define BUSY_WAIT_NOP __asm__ ("rep; nop")
#endif /* pt-machine.h */

View File

@ -1,6 +1,6 @@
/* Machine-dependent pthreads configuration and inline functions.
i386 version.
Copyright (C) 1996,1997,1998,1999,2000,2001 Free Software Foundation, Inc.
Copyright (C) 1996-2001, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Richard Henderson <rth@tamu.edu>.
@ -19,6 +19,9 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#ifndef _PT_MACHINE_H
#define _PT_MACHINE_H 1
#ifndef PT_EI
# define PT_EI extern inline
#endif
@ -96,3 +99,5 @@ compare_and_swap_is_available (void)
Otherwise, it's a 486 or above and it has cmpxchg. */
return changed != 0;
}
#endif /* pt-machine.h */

View File

@ -22,6 +22,8 @@
#include <stddef.h>
#include <pt-machine.h>
/* Type for the dtv. */
typedef union dtv
{