diff options
author | 2016-05-07 19:05:21 +0000 | |
---|---|---|
committer | 2016-05-07 19:05:21 +0000 | |
commit | fe38b55cb0aae270de3f844146814682e8cd345c (patch) | |
tree | 9825cc8aa96314e8e79ea1802ccbc9349772680b /lib/libc/thread | |
parent | Implement ACPI 5.0 GeneralPurposeIo OpRegion support. This basically allows (diff) | |
download | wireguard-openbsd-fe38b55cb0aae270de3f844146814682e8cd345c.tar.xz wireguard-openbsd-fe38b55cb0aae270de3f844146814682e8cd345c.zip |
Use a Thread Information Block in both single and multi-threaded programs.
This stores errno, the cancelation flags, and related bits for each thread
and is allocated by ld.so or libc.a. This is an ABI break from 5.9-stable!
Make libpthread dlopen'able by moving the cancelation wrappers into libc
and doing locking and fork/errno handling via callbacks that libpthread
registers when it first initializes. 'errno' *must* be declared via
<errno.h> now!
Clean up libpthread's symbol exports like libc.
On powerpc, offset the TIB/TCB/TLS data from the register per the ELF spec.
Testing by various, particularly sthen@ and patrick@
ok kettenis@
Diffstat (limited to 'lib/libc/thread')
-rw-r--r-- | lib/libc/thread/Makefile.inc | 4 | ||||
-rw-r--r-- | lib/libc/thread/callbacks.c (renamed from lib/libc/thread/unithread_mutex.c) | 47 | ||||
-rw-r--r-- | lib/libc/thread/unithread_malloc_lock.c | 76 | ||||
-rw-r--r-- | lib/libc/thread/unithread_tag.c | 32 |
4 files changed, 22 insertions, 137 deletions
diff --git a/lib/libc/thread/Makefile.inc b/lib/libc/thread/Makefile.inc index b5d3cb147dc..8c0cecf92d7 100644 --- a/lib/libc/thread/Makefile.inc +++ b/lib/libc/thread/Makefile.inc @@ -1,5 +1,5 @@ -# $OpenBSD: Makefile.inc,v 1.9 2015/04/07 01:27:07 guenther Exp $ +# $OpenBSD: Makefile.inc,v 1.10 2016/05/07 19:05:22 guenther Exp $ .PATH: ${LIBCSRCDIR}/thread -SRCS+= unithread_malloc_lock.c unithread_mutex.c unithread_tag.c atfork.c +SRCS+= callbacks.c atfork.c diff --git a/lib/libc/thread/unithread_mutex.c b/lib/libc/thread/callbacks.c index 44009de7c01..c57a931b08c 100644 --- a/lib/libc/thread/unithread_mutex.c +++ b/lib/libc/thread/callbacks.c @@ -1,7 +1,5 @@ -/* $OpenBSD: unithread_mutex.c,v 1.1 2007/06/05 18:11:48 kurt Exp $ */ - /* - * Copyright (c) 2007 Kurt Miller <kurt@openbsd.org> + * Copyright (c) 2014 Philip Guenther <guenther@openbsd.org> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -16,34 +14,29 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include <sys/types.h> +#include <stdio.h> +#include <signal.h> +#include <string.h> +#include <unistd.h> #include "thread_private.h" -WEAK_PROTOTYPE(_thread_mutex_lock); -WEAK_PROTOTYPE(_thread_mutex_unlock); -WEAK_PROTOTYPE(_thread_mutex_destroy); - -WEAK_ALIAS(_thread_mutex_lock); -WEAK_ALIAS(_thread_mutex_unlock); -WEAK_ALIAS(_thread_mutex_destroy); - -/* ARGSUSED */ void -WEAK_NAME(_thread_mutex_lock)(void **mutex) +_thread_set_callbacks(const struct thread_callbacks *cb, size_t len) { - return; -} + sigset_t allmask, omask; -/* ARGSUSED */ -void -WEAK_NAME(_thread_mutex_unlock)(void **mutex) -{ - return; -} + if (sizeof(*cb) != len) { + fprintf(stderr, "library mismatch: libc expected %z but" + " libpthread gave %z\n", sizeof(*cb), len); + fflush(stderr); + _exit(44); + } -/* ARGSUSED */ -void -WEAK_NAME(_thread_mutex_destroy)(void **mutex) -{ - return; + sigfillset(&allmask); + if (sigprocmask(SIG_BLOCK, &allmask, &omask) == 0) { + /* mprotect RW */ + memcpy(&_thread_cb, cb, sizeof(_thread_cb)); + /* mprotect RO | LOCKPERM | NOUNMAP */ + sigprocmask(SIG_SETMASK, &omask, NULL); + } } diff --git a/lib/libc/thread/unithread_malloc_lock.c b/lib/libc/thread/unithread_malloc_lock.c deleted file mode 100644 index d813bc708f2..00000000000 --- a/lib/libc/thread/unithread_malloc_lock.c +++ /dev/null @@ -1,76 +0,0 @@ -/* $OpenBSD: unithread_malloc_lock.c,v 1.9 2015/04/07 01:27:07 guenther Exp $ */ - -#include <sys/time.h> -#include "thread_private.h" - -WEAK_PROTOTYPE(_thread_malloc_lock); -WEAK_PROTOTYPE(_thread_malloc_unlock); - -WEAK_ALIAS(_thread_malloc_lock); -WEAK_ALIAS(_thread_malloc_unlock); - -WEAK_PROTOTYPE(_thread_atexit_lock); -WEAK_PROTOTYPE(_thread_atexit_unlock); - -WEAK_ALIAS(_thread_atexit_lock); -WEAK_ALIAS(_thread_atexit_unlock); - -WEAK_PROTOTYPE(_thread_atfork_lock); -WEAK_PROTOTYPE(_thread_atfork_unlock); - -WEAK_ALIAS(_thread_atfork_lock); -WEAK_ALIAS(_thread_atfork_unlock); - -WEAK_PROTOTYPE(_thread_arc4_lock); -WEAK_PROTOTYPE(_thread_arc4_unlock); - -WEAK_ALIAS(_thread_arc4_lock); -WEAK_ALIAS(_thread_arc4_unlock); - -void -WEAK_NAME(_thread_malloc_lock)(void) -{ - return; -} - -void -WEAK_NAME(_thread_malloc_unlock)(void) -{ - return; -} - -void -WEAK_NAME(_thread_atexit_lock)(void) -{ - return; -} - -void -WEAK_NAME(_thread_atexit_unlock)(void) -{ - return; -} - -void -WEAK_NAME(_thread_atfork_lock)(void) -{ - return; -} - -void -WEAK_NAME(_thread_atfork_unlock)(void) -{ - return; -} - -void -WEAK_NAME(_thread_arc4_lock)(void) -{ - return; -} - -void -WEAK_NAME(_thread_arc4_unlock)(void) -{ - return; -} diff --git a/lib/libc/thread/unithread_tag.c b/lib/libc/thread/unithread_tag.c deleted file mode 100644 index c7ac928b994..00000000000 --- a/lib/libc/thread/unithread_tag.c +++ /dev/null @@ -1,32 +0,0 @@ -/* $OpenBSD: unithread_tag.c,v 1.1 2004/06/07 21:11:23 marc Exp $ */ - -/* PUBLIC DOMAIN: No Rights Reserved. Marco S Hyman <marc@snafu.org> */ - -#include <sys/time.h> -#include "thread_private.h" - -WEAK_PROTOTYPE(_thread_tag_lock); -WEAK_PROTOTYPE(_thread_tag_unlock); -WEAK_PROTOTYPE(_thread_tag_storage); - -WEAK_ALIAS(_thread_tag_lock); -WEAK_ALIAS(_thread_tag_unlock); -WEAK_ALIAS(_thread_tag_storage); - -void -WEAK_NAME(_thread_tag_lock)(void **tag) -{ - return; -} - -void -WEAK_NAME(_thread_tag_unlock)(void **tag) -{ - return; -} - -void * -WEAK_NAME(_thread_tag_storage)(void **tag, void *init, size_t initsz, void *err) -{ - return init; -} |