summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2011-10-30 20:10:37 +0100
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2011-10-30 20:10:37 +0100
commit916e61485d5434e0b4052832ca331cf0eb315538 (patch)
treec747e26d7149265ecf07489d7a740a76e6a0138a
parent532f60cb8ebdb47af86a4dbe7b551c5b5835f763 (diff)
parent221b60d8f0cf39511d26e275b3a0e26a4bdc4f15 (diff)
Merge branch 'libpthread' into libpthread-moved
-rw-r--r--libpthread/Makefile3
-rw-r--r--libpthread/TODO3
-rw-r--r--libpthread/include/pthread/pthread.h7
-rw-r--r--libpthread/include/pthread/pthreadtypes.h13
-rw-r--r--libpthread/pthread/pt-create.c11
-rw-r--r--libpthread/pthread/pt-exit.c8
-rw-r--r--libpthread/pthread/pt-internal.h29
-rw-r--r--libpthread/sysdeps/generic/bits/condition-attr.h4
-rw-r--r--libpthread/sysdeps/generic/pt-attr-getschedparam.c1
-rw-r--r--libpthread/sysdeps/mach/hurd/ia32/pt-machdep.c39
-rw-r--r--libpthread/sysdeps/mach/hurd/ia32/pt-setup.c11
-rw-r--r--libpthread/sysdeps/mach/hurd/pt-docancel.c6
-rw-r--r--libpthread/sysdeps/mach/hurd/pt-sysdep.h12
-rw-r--r--libpthread/tests/test-1.c1
-rw-r--r--libpthread/tests/test-16.c2
-rw-r--r--libpthread/tests/test-6.c1
-rw-r--r--libpthread/tests/test-7.c1
17 files changed, 113 insertions, 39 deletions
diff --git a/libpthread/Makefile b/libpthread/Makefile
index 2b895e88..a1801f5c 100644
--- a/libpthread/Makefile
+++ b/libpthread/Makefile
@@ -1,6 +1,6 @@
#
# Copyright (C) 1994, 1995, 1996, 1997, 2000, 2002, 2004, 2005, 2006, 2007,
-# 2008 Free Software Foundation, Inc.
+# 2008, 2011 Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
@@ -182,6 +182,7 @@ installhdrsubdir := .
include ../Makeconf
CPPFLAGS += \
+ -DENABLE_TLS \
$(addprefix -I, $(SYSDEP_PATH)) \
-imacros $(srcdir)/include/libc-symbols.h \
-imacros $(srcdir)/not-in-libc.h
diff --git a/libpthread/TODO b/libpthread/TODO
index 45b4cdc2..d7e54da6 100644
--- a/libpthread/TODO
+++ b/libpthread/TODO
@@ -140,6 +140,9 @@
Use them consistently and correctly and start by reading
http://sources.redhat.com/ml/libc-alpha/2002-08/msg00278.html.
+** TLS
+ Support for TLS is only implemented for Mach/Hurd (x86).
+
* L4 Specific Issues
** Stack
*** Size
diff --git a/libpthread/include/pthread/pthread.h b/libpthread/include/pthread/pthread.h
index e6b92495..4dbcb0cb 100644
--- a/libpthread/include/pthread/pthread.h
+++ b/libpthread/include/pthread/pthread.h
@@ -48,6 +48,7 @@
#endif
#include <sched.h>
+#include <time.h>
__BEGIN_DECLS
@@ -377,11 +378,11 @@ extern int pthread_condattr_destroy (pthread_condattr_t *attr);
#ifdef __USE_XOPEN2K
/* Return the value of the clock attribute in *ATTR in *CLOCK_ID. */
extern int pthread_condattr_getclock (const pthread_condattr_t *__restrict attr,
- clockid_t *__restrict clock_id);
+ __clockid_t *__restrict clock_id);
/* Set the value of the clock attribute in *ATTR to CLOCK_ID. */
extern int pthread_condattr_setclock (pthread_condattr_t *attr,
- clockid_t clock_id);
+ __clockid_t clock_id);
#endif
@@ -718,7 +719,7 @@ extern int pthread_kill (pthread_t thread, int signo);
#ifdef __USE_XOPEN2K
/* Return the thread cpu clock. */
-extern int pthread_getcpuclockid (pthread_t thread, clockid_t *clock);
+extern int pthread_getcpuclockid (pthread_t thread, __clockid_t *clock);
#endif
diff --git a/libpthread/include/pthread/pthreadtypes.h b/libpthread/include/pthread/pthreadtypes.h
index 471e08ed..33bd0099 100644
--- a/libpthread/include/pthread/pthreadtypes.h
+++ b/libpthread/include/pthread/pthreadtypes.h
@@ -25,18 +25,7 @@
#include <features.h>
-#define __need_clockid_t
-#include <time.h>
-
-/* If we are in a mode where clockid_t is not automatically defined
- and another header has already included <time.h> then defining
- __need_clockid_t was not enough. */
-#ifndef __clockid_t_defined
-# define __clockid_t_defined 1
-# include <bits/types.h>
-/* Clock ID used in clock and timer functions. */
-typedef __clockid_t clockid_t;
-#endif
+#include <bits/types.h>
__BEGIN_DECLS
diff --git a/libpthread/pthread/pt-create.c b/libpthread/pthread/pt-create.c
index 8f62b78e..346c6979 100644
--- a/libpthread/pthread/pt-create.c
+++ b/libpthread/pthread/pt-create.c
@@ -129,6 +129,13 @@ __pthread_create_internal (struct __pthread **thread,
if (err)
goto failed_thread_alloc;
+#ifdef ENABLE_TLS
+ pthread->tcb = _dl_allocate_tls (NULL);
+ if (!pthread->tcb)
+ goto failed_thread_tls_alloc;
+ pthread->tcb->tcb = pthread->tcb;
+#endif /* ENABLE_TLS */
+
/* And initialize the rest of the machine context. This may include
additional machine- and system-specific initializations that
prove convenient. */
@@ -194,6 +201,10 @@ __pthread_create_internal (struct __pthread **thread,
failed_sigstate:
__pthread_sigstate_destroy (pthread);
failed_setup:
+#ifdef ENABLE_TLS
+ _dl_deallocate_tls (pthread->tcb, 1);
+ failed_thread_tls_alloc:
+#endif /* ENABLE_TLS */
__pthread_thread_dealloc (pthread);
__pthread_thread_halt (pthread);
failed_thread_alloc:
diff --git a/libpthread/pthread/pt-exit.c b/libpthread/pthread/pt-exit.c
index 5fe0ba86..c01efda0 100644
--- a/libpthread/pthread/pt-exit.c
+++ b/libpthread/pthread/pt-exit.c
@@ -1,5 +1,5 @@
/* Thread termination.
- Copyright (C) 2000, 2002, 2005 Free Software Foundation, Inc.
+ Copyright (C) 2000, 2002, 2005, 2007, 2011 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
@@ -35,7 +35,6 @@ pthread_exit (void *status)
struct __pthread *self = _pthread_self ();
struct __pthread_cancelation_handler **handlers;
int oldstate;
- int need_dealloc;
/* Run any cancelation handlers. According to POSIX, the
cancellation cleanup handlers should be called with cancellation
@@ -70,6 +69,11 @@ pthread_exit (void *status)
if (self->cancel_state == PTHREAD_CANCEL_ENABLE && self->cancel_pending)
status = PTHREAD_CANCELED;
+#ifdef ENABLE_TLS
+ if (self->tcb)
+ _dl_deallocate_tls (self->tcb, 1);
+#endif /* ENABLE_TLS */
+
switch (self->state)
{
default:
diff --git a/libpthread/pthread/pt-internal.h b/libpthread/pthread/pt-internal.h
index cb441d09..3f69d2dd 100644
--- a/libpthread/pthread/pt-internal.h
+++ b/libpthread/pthread/pt-internal.h
@@ -1,5 +1,5 @@
/* Internal defenitions for pthreads library.
- Copyright (C) 2000, 2005, 2006, 2008 Free Software Foundation, Inc.
+ Copyright (C) 2000, 2005, 2006, 2007, 2008 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
@@ -54,6 +54,16 @@ enum pthread_state
# define PTHREAD_SYSDEP_MEMBERS
#endif
+#ifdef ENABLE_TLS
+/* Type of the TCB. */
+typedef struct
+{
+ void *tcb; /* Points to this structure. */
+ void *dtv; /* Vector of pointers to TLS data. */
+ thread_t self; /* This thread's control port. */
+} tcbhead_t;
+#endif /* ENABLE_TLS */
+
/* This structure describes a POSIX thread. */
struct __pthread
{
@@ -89,6 +99,10 @@ struct __pthread
PTHREAD_SYSDEP_MEMBERS
+#ifdef ENABLE_TLS
+ tcbhead_t *tcb;
+#endif /* ENABLE_TLS */
+
struct __pthread *next, **prevp;
};
@@ -287,4 +301,17 @@ const struct __pthread_rwlockattr __pthread_default_rwlockattr;
/* Default condition attributes. */
const struct __pthread_condattr __pthread_default_condattr;
+
+#ifdef ENABLE_TLS
+
+/* From glibc. */
+
+/* Dynamic linker TLS allocation. */
+extern void *_dl_allocate_tls(void *);
+
+/* Dynamic linker TLS deallocation. */
+extern void _dl_deallocate_tls(void *, int);
+
+#endif /* ENABLE_TLS */
+
#endif /* pt-internal.h */
diff --git a/libpthread/sysdeps/generic/bits/condition-attr.h b/libpthread/sysdeps/generic/bits/condition-attr.h
index a1311286..4cd4e8c4 100644
--- a/libpthread/sysdeps/generic/bits/condition-attr.h
+++ b/libpthread/sysdeps/generic/bits/condition-attr.h
@@ -20,7 +20,7 @@
#ifndef _BITS_CONDITION_ATTR_H
#define _BITS_CONDITION_ATTR_H 1
-#include <time.h>
+#include <bits/types.h>
enum __pthread_process_shared;
@@ -28,7 +28,7 @@ enum __pthread_process_shared;
struct __pthread_condattr
{
enum __pthread_process_shared pshared;
- clockid_t clock;
+ __clockid_t clock;
};
#endif /* bits/condition.h */
diff --git a/libpthread/sysdeps/generic/pt-attr-getschedparam.c b/libpthread/sysdeps/generic/pt-attr-getschedparam.c
index 6c3f15be..190cf9d0 100644
--- a/libpthread/sysdeps/generic/pt-attr-getschedparam.c
+++ b/libpthread/sysdeps/generic/pt-attr-getschedparam.c
@@ -19,6 +19,7 @@
#include <pthread.h>
#include <sched.h>
+#include <string.h>
#include <pt-internal.h>
diff --git a/libpthread/sysdeps/mach/hurd/ia32/pt-machdep.c b/libpthread/sysdeps/mach/hurd/ia32/pt-machdep.c
index face46c5..f3c8cf50 100644
--- a/libpthread/sysdeps/mach/hurd/ia32/pt-machdep.c
+++ b/libpthread/sysdeps/mach/hurd/ia32/pt-machdep.c
@@ -1,5 +1,5 @@
/* Machine dependent pthreads code. Hurd/i386 version.
- Copyright (C) 2000,02 Free Software Foundation, Inc.
+ Copyright (C) 2000, 2002, 2007 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
@@ -21,12 +21,28 @@
#include <mach.h>
#include <mach/i386/thread_status.h>
+#include <mach/i386/mach_i386.h>
+#include <mach/mig_errors.h>
#include <mach/thread_status.h>
+#define HURD_TLS_DESC_DECL(desc, tcb) \
+ struct descriptor desc = \
+ { /* low word: */ \
+ 0xffff /* limit 0..15 */ \
+ | (((unsigned int) (tcb)) << 16) /* base 0..15 */ \
+ , /* high word: */ \
+ ((((unsigned int) (tcb)) >> 16) & 0xff) /* base 16..23 */ \
+ | ((0x12 | 0x60 | 0x80) << 8) /* access = ACC_DATA_W|ACC_PL_U|ACC_P */ \
+ | (0xf << 16) /* limit 16..19 */ \
+ | ((4 | 8) << 20) /* granularity = SZ_32|SZ_G */ \
+ | (((unsigned int) (tcb)) & 0xff000000) /* base 24..31 */ \
+ }
+
int
-__thread_set_pcsp (thread_t thread,
+__thread_set_pcsptp (thread_t thread,
int set_ip, void *ip,
- int set_sp, void *sp)
+ int set_sp, void *sp,
+ int set_tp, void *tp)
{
error_t err;
struct i386_thread_state state;
@@ -34,7 +50,7 @@ __thread_set_pcsp (thread_t thread,
state_count = i386_THREAD_STATE_COUNT;
- err = __thread_get_state (thread, i386_THREAD_STATE,
+ err = __thread_get_state (thread, i386_REGS_SEGS_STATE,
(thread_state_t) &state, &state_count);
if (err)
return err;
@@ -43,8 +59,21 @@ __thread_set_pcsp (thread_t thread,
state.uesp = (unsigned int) sp;
if (set_ip)
state.eip = (unsigned int) ip;
+ if (set_tp) {
+ HURD_TLS_DESC_DECL(desc, tp);
+ int sel;
+
+ asm ("mov %%gs, %w0" : "=q" (sel) : "0" (0));
+ if (__builtin_expect (sel, 0x48) & 4) /* LDT selector */
+ err = __i386_set_ldt (thread, sel, &desc, 1);
+ else
+ err = __i386_set_gdt (thread, &sel, desc);
+ if (err)
+ return err;
+ state.gs = sel;
+ }
- err = __thread_set_state (thread, i386_THREAD_STATE,
+ err = __thread_set_state (thread, i386_REGS_SEGS_STATE,
(thread_state_t) &state,
i386_THREAD_STATE_COUNT);
if (err)
diff --git a/libpthread/sysdeps/mach/hurd/ia32/pt-setup.c b/libpthread/sysdeps/mach/hurd/ia32/pt-setup.c
index ba438d6a..5420dc8e 100644
--- a/libpthread/sysdeps/mach/hurd/ia32/pt-setup.c
+++ b/libpthread/sysdeps/mach/hurd/ia32/pt-setup.c
@@ -1,5 +1,5 @@
/* Setup thread stack. Hurd/i386 version.
- Copyright (C) 2000, 2002, 2005, 2008 Free Software Foundation, Inc.
+ Copyright (C) 2000, 2002, 2005, 2007, 2008 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
@@ -64,7 +64,7 @@ stack_setup (struct __pthread *thread,
{
/* And then the call frame. */
top -= 2;
- top = (uintptr_t) top & ~0xf;
+ top = (uintptr_t *) ((uintptr_t) top & ~0xf);
top[1] = (uintptr_t) arg; /* Argument to START_ROUTINE. */
top[0] = (uintptr_t) start_routine;
*--top = 0; /* Fake return address. */
@@ -91,12 +91,15 @@ __pthread_setup (struct __pthread *thread,
thread->mcontext.pc = entry_point;
thread->mcontext.sp = stack_setup (thread, start_routine, arg);
+ thread->tcb->self = thread->kernel_thread;
+
ktid = __mach_thread_self ();
if (thread->kernel_thread != ktid)
{
- err = __thread_set_pcsp (thread->kernel_thread,
+ err = __thread_set_pcsptp (thread->kernel_thread,
1, thread->mcontext.pc,
- 1, thread->mcontext.sp);
+ 1, thread->mcontext.sp,
+ 1, thread->tcb);
assert_perror (err);
}
__mach_port_deallocate (__mach_task_self (), ktid);
diff --git a/libpthread/sysdeps/mach/hurd/pt-docancel.c b/libpthread/sysdeps/mach/hurd/pt-docancel.c
index b81a5c70..105c6fda 100644
--- a/libpthread/sysdeps/mach/hurd/pt-docancel.c
+++ b/libpthread/sysdeps/mach/hurd/pt-docancel.c
@@ -1,5 +1,5 @@
/* Cancel a thread.
- Copyright (C) 2002, 2008 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2007, 2008 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
@@ -52,8 +52,8 @@ __pthread_do_cancel (struct __pthread *p)
err = __thread_abort (p->kernel_thread);
assert_perror (err);
- err = __thread_set_pcsp (p->kernel_thread,
- 1, (void *) call_exit, 0, 0);
+ err = __thread_set_pcsptp (p->kernel_thread,
+ 1, (void *) call_exit, 0, 0, 0, 0);
assert_perror (err);
err = __thread_resume (p->kernel_thread);
diff --git a/libpthread/sysdeps/mach/hurd/pt-sysdep.h b/libpthread/sysdeps/mach/hurd/pt-sysdep.h
index f14a1366..13e235d9 100644
--- a/libpthread/sysdeps/mach/hurd/pt-sysdep.h
+++ b/libpthread/sysdeps/mach/hurd/pt-sysdep.h
@@ -1,5 +1,5 @@
/* Internal defenitions for pthreads library.
- Copyright (C) 2000, 2002, 2008 Free Software Foundation, Inc.
+ Copyright (C) 2000, 2002, 2007, 2008 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
@@ -60,11 +60,13 @@ __pthread_stack_dealloc (void *stackaddr, size_t stacksize)
__vm_deallocate (__mach_task_self (), (vm_offset_t) stackaddr, stacksize);
}
-/* Change thread THREAD's program counter to PC if SET_PC is true and
- its stack pointer to SP if SET_IP is true. */
-extern int __thread_set_pcsp (thread_t thread,
+/* Change thread THREAD's program counter to PC if SET_PC is true,
+ its stack pointer to SP if SET_IP is true, and its thread pointer
+ to TP if SET_TP is true. */
+extern int __thread_set_pcsptp (thread_t thread,
int set_pc, void *pc,
- int set_sp, void *sp);
+ int set_sp, void *sp,
+ int set_tp, void *tp);
#endif /* pt-sysdep.h */
diff --git a/libpthread/tests/test-1.c b/libpthread/tests/test-1.c
index 318fd6e9..6ec1afb3 100644
--- a/libpthread/tests/test-1.c
+++ b/libpthread/tests/test-1.c
@@ -1,6 +1,7 @@
#define _GNU_SOURCE
#include <pthread.h>
+#include <assert.h>
#include <unistd.h>
#include <error.h>
#include <errno.h>
diff --git a/libpthread/tests/test-16.c b/libpthread/tests/test-16.c
index b6a52d01..3660f5f7 100644
--- a/libpthread/tests/test-16.c
+++ b/libpthread/tests/test-16.c
@@ -33,7 +33,7 @@ test (void *arg)
}
static void
-handler (int sig, siginfo_t *info, void *context)
+handler (int sig)
{
assert (pthread_equal (pthread_self (), testthread));
printf ("handler: %d\n", pthread_self ());
diff --git a/libpthread/tests/test-6.c b/libpthread/tests/test-6.c
index 98aa8ba7..edf2919e 100644
--- a/libpthread/tests/test-6.c
+++ b/libpthread/tests/test-6.c
@@ -3,6 +3,7 @@
#include <pthread.h>
#include <stdio.h>
#include <error.h>
+#include <assert.h>
#include <errno.h>
#define THREADS 500
diff --git a/libpthread/tests/test-7.c b/libpthread/tests/test-7.c
index bd97acfa..8159be34 100644
--- a/libpthread/tests/test-7.c
+++ b/libpthread/tests/test-7.c
@@ -1,6 +1,7 @@
#define _GNU_SOURCE
#include <pthread.h>
+#include <assert.h>
#include <stdio.h>
#include <error.h>
#include <errno.h>