diff options
author | Philip Guenther <guenther@cvs.openbsd.org> | 2013-02-15 22:01:25 +0000 |
---|---|---|
committer | Philip Guenther <guenther@cvs.openbsd.org> | 2013-02-15 22:01:25 +0000 |
commit | 79bcd4dfe34962b8fd02ab9e6d6c1785f5d4ce1c (patch) | |
tree | 41a199e0a5e656f4c29c5bfc20d3f3bcac5d6895 /lib/librthread | |
parent | bbd4da32cb626e4d201c5da8818c72e4aa5eeb36 (diff) |
Revert previous diff: sparc and sparc64 don't set the TCB to NULL in exec, yet,
and vax doesn't support symbols that are both weak and undefined (yet?).
sparc issue diagnosed by kettenis@, vax problem found by todd@
Diffstat (limited to 'lib/librthread')
-rw-r--r-- | lib/librthread/rthread.c | 49 | ||||
-rw-r--r-- | lib/librthread/tcb.h | 17 |
2 files changed, 19 insertions, 47 deletions
diff --git a/lib/librthread/rthread.c b/lib/librthread/rthread.c index bbf68d521b2..5952375d128 100644 --- a/lib/librthread/rthread.c +++ b/lib/librthread/rthread.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rthread.c,v 1.67 2013/02/14 03:38:15 guenther Exp $ */ +/* $OpenBSD: rthread.c,v 1.68 2013/02/15 22:01:24 guenther Exp $ */ /* * Copyright (c) 2004,2005 Ted Unangst <tedu@openbsd.org> * All Rights Reserved. @@ -47,9 +47,6 @@ #include "rthread.h" #include "tcb.h" -#pragma weak _dl_allocate_tls -#pragma weak _dl_free_tls - static int concurrency_level; /* not used */ int _threads_ready; @@ -103,20 +100,11 @@ _spinunlock(_spinlock_lock_t *lock) void _rthread_initlib(void) __attribute__((constructor)); void _rthread_initlib(void) { - struct thread_control_block *tcb = __get_tcb(); - - /* - * A newer ld.so may provide a TCB allocation for us. - * If not, use a static allocation - */ - if (tcb == NULL) { - tcb = &_initial_thread_tcb; - tcb->tcb_dtv = 0; - TCB_SET(tcb); - } + struct thread_control_block *tcb = &_initial_thread_tcb; /* use libc's errno for the main thread */ TCB_INIT(tcb, &_initial_thread, ___errno()); + TCB_SET(tcb); } int * @@ -272,30 +260,6 @@ pthread_self(void) return (TCB_THREAD()); } -static inline struct thread_control_block * -allocate_tcb(void) -{ - struct thread_control_block *tcb; - - if (&_dl_allocate_tls != 0) - tcb = _dl_allocate_tls(NULL); - else { - tcb = malloc(sizeof(*tcb)); - tcb->tcb_dtv = 0; - } - return (tcb); -} - -static inline void -free_tcb(struct thread_control_block *tcb) -{ - if (&_dl_free_tls != 0) - _dl_free_tls(tcb); - else - free(tcb); -} - - static void _rthread_reaper(void) { @@ -311,7 +275,8 @@ restart: _rthread_debug(3, "rthread reaping %p stack %p\n", (void *)thread, (void *)thread->stack); _rthread_free_stack(thread->stack); - free_tcb(thread->arg); + _rtld_free_tls(thread->arg, + sizeof(struct thread_control_block), sizeof(void *)); free(thread); goto restart; } @@ -452,7 +417,7 @@ pthread_create(pthread_t *threadp, const pthread_attr_t *attr, goto fail1; } - tcb = allocate_tcb(); + tcb = _rtld_allocate_tls(NULL, sizeof(*tcb), sizeof(void *)); if (tcb == NULL) { rc = errno; goto fail2; @@ -481,7 +446,7 @@ pthread_create(pthread_t *threadp, const pthread_attr_t *attr, _spinlock(&_thread_lock); LIST_REMOVE(thread, threads); _spinunlock(&_thread_lock); - free_tcb(tcb); + _rtld_free_tls(tcb, sizeof(*tcb), sizeof(void *)); fail2: _rthread_free_stack(thread->stack); fail1: diff --git a/lib/librthread/tcb.h b/lib/librthread/tcb.h index 2139d21d6db..12c5ec8fa63 100644 --- a/lib/librthread/tcb.h +++ b/lib/librthread/tcb.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tcb.h,v 1.5 2013/02/14 03:38:15 guenther Exp $ */ +/* $OpenBSD: tcb.h,v 1.6 2013/02/15 22:01:24 guenther Exp $ */ /* * Copyright (c) 2011 Philip Guenther <guenther@openbsd.org> * @@ -85,6 +85,7 @@ struct thread_control_block { __ERRNOPTR(TCB_THREAD()) #define TCB_INIT(tcb, thread, errnoptr) \ do { \ + (tcb)->tcb_dtv = 0; \ (tcb)->tcb_thread = (thread); \ __ERRNOPTR(thread) = (errnoptr); \ } while (0) @@ -112,6 +113,7 @@ struct thread_control_block { #define TCB_INIT(tcb, thread, errnoptr) \ do { \ (tcb)->__tcb_self = (tcb); \ + (tcb)->tcb_dtv = 0; \ (tcb)->tcb_thread = (thread); \ (tcb)->__tcb_errno = (errnoptr); \ } while (0) @@ -127,11 +129,16 @@ struct thread_control_block { #define TCB_SET(tcb) __set_tcb(tcb) #endif +#if 0 +void *_rtld_allocate_tls(void *, size_t, size_t); +void _rtld_free_tls(void *, size_t, size_t); +#else /* - * Functions that will eventually be provided by ld.so for allocating - * and freeing TCBs + * XXX Until we have these in ld.so and support __thread, just use + * malloc/free. The main thread's TCB cannot be allocated or freed with these. */ -void *_dl_allocate_tls(void *); -void _dl_free_tls(void *); +#define _rtld_allocate_tls(old, size, align) malloc(size) +#define _rtld_free_tls(old, size, align) free(old) +#endif #endif /* _TCB_H_ */ |