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 | |
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')
-rw-r--r-- | lib/libc/Symbols.list | 2 | ||||
-rw-r--r-- | lib/libc/hidden/pthread.h | 4 | ||||
-rw-r--r-- | lib/libc/include/thread_private.h | 10 | ||||
-rw-r--r-- | lib/libc/shlib_version | 4 | ||||
-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 |
8 files changed, 21 insertions, 110 deletions
diff --git a/lib/libc/Symbols.list b/lib/libc/Symbols.list index 52e223ac98d..d6346040a78 100644 --- a/lib/libc/Symbols.list +++ b/lib/libc/Symbols.list @@ -1671,8 +1671,6 @@ _spinlock _spinlocktry _spinunlock _thread_atfork -_thread_cleanup_pop -_thread_cleanup_push _thread_dofork _thread_set_callbacks pthread_atfork diff --git a/lib/libc/hidden/pthread.h b/lib/libc/hidden/pthread.h index 5991bc4cfee..e16712dfbb1 100644 --- a/lib/libc/hidden/pthread.h +++ b/lib/libc/hidden/pthread.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pthread.h,v 1.3 2017/10/28 21:23:14 guenther Exp $ */ +/* $OpenBSD: pthread.h,v 1.4 2017/11/04 22:53:57 jca Exp $ */ /* * Copyright (c) 2015 Philip Guenther <guenther@openbsd.org> * @@ -20,8 +20,6 @@ #include_next <pthread.h> -PROTO_NORMAL(_thread_cleanup_pop); -PROTO_NORMAL(_thread_cleanup_push); PROTO_STD_DEPRECATED(pthread_atfork); PROTO_STD_DEPRECATED(pthread_cond_broadcast); PROTO_STD_DEPRECATED(pthread_cond_destroy); diff --git a/lib/libc/include/thread_private.h b/lib/libc/include/thread_private.h index 6c695ee5ee8..fd530d7dff1 100644 --- a/lib/libc/include/thread_private.h +++ b/lib/libc/include/thread_private.h @@ -1,4 +1,4 @@ -/* $OpenBSD: thread_private.h,v 1.31 2017/10/28 21:23:14 guenther Exp $ */ +/* $OpenBSD: thread_private.h,v 1.32 2017/11/04 22:53:57 jca Exp $ */ /* PUBLIC DOMAIN: No Rights Reserved. Marco S Hyman <marc@snafu.org> */ @@ -344,6 +344,12 @@ struct rthread_storage { void *data; }; +struct rthread_cleanup_fn { + void (*fn)(void *); + void *arg; + struct rthread_cleanup_fn *next; +}; + struct tib; struct stack; struct pthread { @@ -361,7 +367,7 @@ struct pthread { pthread_cond_t blocking_cond; struct pthread_attr attr; struct rthread_storage *local_storage; - struct __thread_cleanup *cleanup_fns; + struct rthread_cleanup_fn *cleanup_fns; /* cancel received in a delayed cancel block? */ int delayed_cancel; diff --git a/lib/libc/shlib_version b/lib/libc/shlib_version index 9dcf58fd5f6..7fe672d9c92 100644 --- a/lib/libc/shlib_version +++ b/lib/libc/shlib_version @@ -1,4 +1,4 @@ -major=91 -minor=1 +major=92 +minor=0 # note: If changes were made to include/thread_private.h or if system # calls were added/changed then librthread/shlib_version also be updated. 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); |