diff options
author | Jeremie Courreges-Anglas <jca@cvs.openbsd.org> | 2017-11-04 22:53:58 +0000 |
---|---|---|
committer | Jeremie Courreges-Anglas <jca@cvs.openbsd.org> | 2017-11-04 22:53:58 +0000 |
commit | d9fa4bd9a3fc4cca904ffcf8f640020d6e0538be (patch) | |
tree | ca254e2971b46758ba17bb858ace8a0e4258346c /lib/libc/thread | |
parent | f62b8a875ce265c1684cc9af05545b04e3b21b9a (diff) |
Revert recent changes to unbreak ports/net/samba
While it is not clear (to me) why that ports ends up with corrupted
shared libs, reverting those changes fixes the issue and should allow us
to close p2k17 more smoothly.
Discussed with a bunch, ok ajacoutot@ guenther@
Diffstat (limited to 'lib/libc/thread')
-rw-r--r-- | lib/libc/thread/Makefile.inc | 3 | ||||
-rw-r--r-- | lib/libc/thread/rthread.c | 12 | ||||
-rw-r--r-- | lib/libc/thread/rthread_cleanup.c | 84 | ||||
-rw-r--r-- | lib/libc/thread/rthread_once.c | 12 |
4 files changed, 10 insertions, 101 deletions
diff --git a/lib/libc/thread/Makefile.inc b/lib/libc/thread/Makefile.inc index 9eb1622f883..075a9b8da17 100644 --- a/lib/libc/thread/Makefile.inc +++ b/lib/libc/thread/Makefile.inc @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.inc,v 1.12 2017/10/28 21:23:14 guenther Exp $ +# $OpenBSD: Makefile.inc,v 1.13 2017/11/04 22:53:57 jca Exp $ .PATH: ${LIBCSRCDIR}/thread @@ -6,7 +6,6 @@ SRCS+= callbacks.c atfork.c # threads infrastructure SRCS+= rthread.c \ - rthread_cleanup.c \ rthread_condattr.c \ rthread_debug.c \ rthread_file.c \ diff --git a/lib/libc/thread/rthread.c b/lib/libc/thread/rthread.c index a92d3a20328..66405cf477a 100644 --- a/lib/libc/thread/rthread.c +++ b/lib/libc/thread/rthread.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rthread.c,v 1.5 2017/10/28 21:23:14 guenther Exp $ */ +/* $OpenBSD: rthread.c,v 1.6 2017/11/04 22:53:57 jca Exp $ */ /* * Copyright (c) 2004,2005 Ted Unangst <tedu@openbsd.org> * All Rights Reserved. @@ -112,7 +112,7 @@ DEF_STRONG(pthread_self); void pthread_exit(void *retval) { - struct __thread_cleanup *clfn; + struct rthread_cleanup_fn *clfn; struct tib *tib; pthread_t thread = pthread_self(); @@ -131,8 +131,12 @@ pthread_exit(void *retval) thread->retval = retval; - while ((clfn = thread->cleanup_fns) != NULL) - _thread_cleanup_pop(1, clfn); + for (clfn = thread->cleanup_fns; clfn; ) { + struct rthread_cleanup_fn *oclfn = clfn; + clfn = clfn->next; + oclfn->fn(oclfn->arg); + free(oclfn); + } _rthread_tls_destructors(thread); if (_thread_cb.tc_thread_release != NULL) diff --git a/lib/libc/thread/rthread_cleanup.c b/lib/libc/thread/rthread_cleanup.c index 4accd64494d..e69de29bb2d 100644 --- a/lib/libc/thread/rthread_cleanup.c +++ b/lib/libc/thread/rthread_cleanup.c @@ -1,84 +0,0 @@ -/* $OpenBSD: rthread_cleanup.c,v 1.1 2017/10/28 21:23:14 guenther Exp $ */ -/* - * Copyright (c) 2017 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 - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include <string.h> -#include <stdint.h> -#include <stdlib.h> -#include <syslog.h> - -#include "thread_private.h" - -/* If this is static then clang will optimize it away */ -uintptr_t cleanup_cookie[4] __dso_hidden - __attribute__((section(".openbsd.randomdata"))); - -void -_thread_cleanup_push(void (*fn)(void *), void *arg, - struct __thread_cleanup *tc) -{ - pthread_t self = pthread_self(); - - tc->__tc_magic = cleanup_cookie[0]; - tc->__tc_next = cleanup_cookie[1] ^ (uintptr_t)self->cleanup_fns; - tc->__tc_fn = cleanup_cookie[2] ^ (uintptr_t)fn; - tc->__tc_arg = cleanup_cookie[3] ^ (uintptr_t)arg; - self->cleanup_fns = tc; -} -DEF_STRONG(_thread_cleanup_push); - -static const char bad_magic[] = ": corrupted buffer in pthread_cleanup_pop"; -static const char bad_pop[] = ": non-LIFO pthread_cleanup_pop"; - -void -_thread_cleanup_pop(int execute, struct __thread_cleanup *tc) -{ - pthread_t self = pthread_self(); - - if (__predict_false(tc->__tc_magic != cleanup_cookie[0] || - tc != self->cleanup_fns)) { - char buf[1024]; - const char *msg; - size_t msgsiz; - - /* <10> is LOG_CRIT */ - strlcpy(buf, "<10>", sizeof buf); - - /* Make sure progname does not fill the whole buffer */ - if (tc->__tc_magic != cleanup_cookie[0]) { - msgsiz = sizeof bad_magic; - msg = bad_magic; - } else { - msgsiz = sizeof bad_pop; - msg = bad_pop; - } - strlcat(buf, __progname, sizeof(buf) - msgsiz); - strlcat(buf, msg, sizeof buf); - - sendsyslog(buf, strlen(buf), LOG_CONS); - abort(); - } - - self->cleanup_fns = (void *)(cleanup_cookie[1] ^ tc->__tc_next); - if (execute) { - void (*fn)(void *), *arg; - - fn = (void *)(cleanup_cookie[2] ^ tc->__tc_fn); - arg = (void *)(cleanup_cookie[3] ^ tc->__tc_arg); - fn(arg); - } -} -DEF_STRONG(_thread_cleanup_pop); diff --git a/lib/libc/thread/rthread_once.c b/lib/libc/thread/rthread_once.c index 014532e56c4..a9b6749d75f 100644 --- a/lib/libc/thread/rthread_once.c +++ b/lib/libc/thread/rthread_once.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rthread_once.c,v 1.2 2017/10/28 21:25:24 guenther Exp $ */ +/* $OpenBSD: rthread_once.c,v 1.3 2017/11/04 22:53:57 jca Exp $ */ /* * Copyright (c) 2004,2005 Ted Unangst <tedu@openbsd.org> * All Rights Reserved. @@ -17,23 +17,13 @@ */ #include <pthread.h> -#include <stdlib.h> - -static void -mutex_unlock(void *arg) -{ - if (pthread_mutex_unlock(arg)) - abort(); -} int pthread_once(pthread_once_t *once_control, void (*init_routine)(void)) { pthread_mutex_lock(&once_control->mutex); if (once_control->state == PTHREAD_NEEDS_INIT) { - pthread_cleanup_push(mutex_unlock, &once_control->mutex); init_routine(); - pthread_cleanup_pop(0); once_control->state = PTHREAD_DONE_INIT; } pthread_mutex_unlock(&once_control->mutex); |