From 40b6c3c5dc5c8ed22543d93442a8c56b881b3778 Mon Sep 17 00:00:00 2001 From: Joerg Sonnenberger Date: Thu, 28 Apr 2005 18:16:47 +0000 Subject: [PATCH] Add support for TLS. --- lib/libc_r/uthread/pthread_private.h | 5 ++++- lib/libc_r/uthread/uthread_create.c | 3 ++- lib/libc_r/uthread/uthread_fork.c | 3 ++- lib/libc_r/uthread/uthread_gc.c | 3 ++- lib/libc_r/uthread/uthread_init.c | 3 ++- lib/libc_r/uthread/uthread_kern.c | 3 ++- 6 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/libc_r/uthread/pthread_private.h b/lib/libc_r/uthread/pthread_private.h index 11f86899d3..2b031394ef 100644 --- a/lib/libc_r/uthread/pthread_private.h +++ b/lib/libc_r/uthread/pthread_private.h @@ -32,7 +32,7 @@ * Private thread definitions for the uthread kernel. * * $FreeBSD: src/lib/libc_r/uthread/pthread_private.h,v 1.36.2.21 2002/10/22 14:44:02 fjoe Exp $ - * $DragonFly: src/lib/libc_r/uthread/pthread_private.h,v 1.5 2005/03/13 15:10:03 swildner Exp $ + * $DragonFly: src/lib/libc_r/uthread/pthread_private.h,v 1.6 2005/04/28 18:16:47 joerg Exp $ */ #ifndef _PTHREAD_PRIVATE_H @@ -61,6 +61,8 @@ #include #include +#include + /* * Define machine dependent macros to get and set the stack pointer * from the supported contexts. Also define a macro to set the return @@ -613,6 +615,7 @@ struct pthread { u_int32_t magic; char *name; u_int64_t uniqueid; /* for gdb */ + struct tls_tcb *tcb; /* * Lock for accesses to this thread structure. diff --git a/lib/libc_r/uthread/uthread_create.c b/lib/libc_r/uthread/uthread_create.c index 942f2ca9bb..d1c453a37a 100644 --- a/lib/libc_r/uthread/uthread_create.c +++ b/lib/libc_r/uthread/uthread_create.c @@ -30,7 +30,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc_r/uthread/uthread_create.c,v 1.24.2.6 2003/01/08 05:04:26 fjoe Exp $ - * $DragonFly: src/lib/libc_r/uthread/uthread_create.c,v 1.2 2003/06/17 04:26:48 dillon Exp $ + * $DragonFly: src/lib/libc_r/uthread/uthread_create.c,v 1.3 2005/04/28 18:16:47 joerg Exp $ */ #include #include @@ -166,6 +166,7 @@ _pthread_create(pthread_t *thread, const pthread_attr_t *attr, } else { /* Initialise the thread structure: */ memset(new_thread, 0, sizeof(struct pthread)); + new_thread->tcb = _rtld_allocate_tls(NULL); new_thread->slice_usec = -1; new_thread->stack = stack; new_thread->start_routine = start_routine; diff --git a/lib/libc_r/uthread/uthread_fork.c b/lib/libc_r/uthread/uthread_fork.c index 9ef342e2df..4550d1ad16 100644 --- a/lib/libc_r/uthread/uthread_fork.c +++ b/lib/libc_r/uthread/uthread_fork.c @@ -30,7 +30,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc_r/uthread/uthread_fork.c,v 1.19.2.7 2002/10/22 14:44:03 fjoe Exp $ - * $DragonFly: src/lib/libc_r/uthread/uthread_fork.c,v 1.2 2003/06/17 04:26:48 dillon Exp $ + * $DragonFly: src/lib/libc_r/uthread/uthread_fork.c,v 1.3 2005/04/28 18:16:47 joerg Exp $ */ #include #include @@ -161,6 +161,7 @@ _fork(void) if (pthread_save->poll_data.fds != NULL) free(pthread_save->poll_data.fds); + _rtld_free_tls(pthread_save->tcb); free(pthread_save); } } diff --git a/lib/libc_r/uthread/uthread_gc.c b/lib/libc_r/uthread/uthread_gc.c index cfe40ef080..aff0e45ecf 100644 --- a/lib/libc_r/uthread/uthread_gc.c +++ b/lib/libc_r/uthread/uthread_gc.c @@ -30,7 +30,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc_r/uthread/uthread_gc.c,v 1.11.2.5 2002/10/22 14:44:03 fjoe Exp $ - * $DragonFly: src/lib/libc_r/uthread/uthread_gc.c,v 1.2 2003/06/17 04:26:48 dillon Exp $ + * $DragonFly: src/lib/libc_r/uthread/uthread_gc.c,v 1.3 2005/04/28 18:16:47 joerg Exp $ * * Garbage collector thread. Frees memory allocated for dead threads. * @@ -248,6 +248,7 @@ _thread_gc(pthread_addr_t arg) /* Free the thread name string. */ free(pthread_cln->name); } + _rtld_free_tls(pthread_cln->tcb); /* * Free the memory allocated for the thread * structure. diff --git a/lib/libc_r/uthread/uthread_init.c b/lib/libc_r/uthread/uthread_init.c index 91f5774046..a3ea2284d4 100644 --- a/lib/libc_r/uthread/uthread_init.c +++ b/lib/libc_r/uthread/uthread_init.c @@ -30,7 +30,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc_r/uthread/uthread_init.c,v 1.23.2.11 2003/02/24 23:27:32 das Exp $ - * $DragonFly: src/lib/libc_r/uthread/uthread_init.c,v 1.4 2005/03/13 15:10:03 swildner Exp $ + * $DragonFly: src/lib/libc_r/uthread/uthread_init.c,v 1.5 2005/04/28 18:16:47 joerg Exp $ */ /* Allocate space for global thread variables here: */ @@ -263,6 +263,7 @@ _thread_init(void) -1, 0) == MAP_FAILED) PANIC("Cannot allocate red zone for initial thread"); + _thread_initial->tcb = tls_get_tcb(); /* Set the main thread stack pointer. */ _thread_initial->stack = _usrstack - PTHREAD_STACK_INITIAL; diff --git a/lib/libc_r/uthread/uthread_kern.c b/lib/libc_r/uthread/uthread_kern.c index a3bffd4502..770e9ef052 100644 --- a/lib/libc_r/uthread/uthread_kern.c +++ b/lib/libc_r/uthread/uthread_kern.c @@ -30,7 +30,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc_r/uthread/uthread_kern.c,v 1.28.2.13 2002/10/22 14:44:03 fjoe Exp $ - * $DragonFly: src/lib/libc_r/uthread/uthread_kern.c,v 1.2 2003/06/17 04:26:48 dillon Exp $ + * $DragonFly: src/lib/libc_r/uthread/uthread_kern.c,v 1.3 2005/04/28 18:16:47 joerg Exp $ * */ #include @@ -1141,4 +1141,5 @@ void _set_curthread(struct pthread *newthread) { _thread_run = newthread; + tls_set_tcb(newthread->tcb); } -- 2.41.0