summaryrefslogtreecommitdiff
path: root/lib/libpthread
diff options
context:
space:
mode:
authorMarco S Hyman <marc@cvs.openbsd.org>2003-05-13 16:49:33 +0000
committerMarco S Hyman <marc@cvs.openbsd.org>2003-05-13 16:49:33 +0000
commit09633e9f98f50e906a012742b2b61b29ecdd406c (patch)
tree3dd0d8798f873c9bd2088b18c73c04fa48a2be31 /lib/libpthread
parent936f1e7e34e563b3e201da211745dcc817c0f3b8 (diff)
Add support for blocking thread switches during dlopen and other
non-thread-safe dl functions. Only enabled for ELF architectures at this time as needed dlxxx support has not yet been added to the a.out run time loader. 'doesn't break xmms at least' tedu@. Tested by others with no comment
Diffstat (limited to 'lib/libpthread')
-rw-r--r--lib/libpthread/uthread/pthread_private.h3
-rw-r--r--lib/libpthread/uthread/uthread_init.c10
-rw-r--r--lib/libpthread/uthread/uthread_kern.c18
3 files changed, 27 insertions, 4 deletions
diff --git a/lib/libpthread/uthread/pthread_private.h b/lib/libpthread/uthread/pthread_private.h
index 4a244e89075..f5950ee9367 100644
--- a/lib/libpthread/uthread/pthread_private.h
+++ b/lib/libpthread/uthread/pthread_private.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: pthread_private.h,v 1.45 2003/02/14 03:58:42 marc Exp $ */
+/* $OpenBSD: pthread_private.h,v 1.46 2003/05/13 16:49:32 marc Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
@@ -1095,6 +1095,7 @@ void _thread_clear_pending(int, pthread_t);
void _thread_dump_data(const void *, int);
void _thread_dump_info(void);
void _thread_init(void);
+void _thread_kern_lock(int);
void _thread_kern_sched(struct sigcontext *);
void _thread_kern_sched_state(enum pthread_state, const char *, int);
void _thread_kern_sched_state_unlock(enum pthread_state, spinlock_t *,
diff --git a/lib/libpthread/uthread/uthread_init.c b/lib/libpthread/uthread/uthread_init.c
index 1be9ce7ca3a..a226a09b912 100644
--- a/lib/libpthread/uthread/uthread_init.c
+++ b/lib/libpthread/uthread/uthread_init.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_init.c,v 1.28 2003/02/04 22:14:27 marc Exp $ */
+/* $OpenBSD: uthread_init.c,v 1.29 2003/05/13 16:49:32 marc Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -50,6 +50,7 @@
#include <sys/user.h>
#include <sys/wait.h>
+#include <dlfcn.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
@@ -361,7 +362,12 @@ _thread_init(void)
/* Initialise the garbage collector mutex and condition variable. */
if (pthread_mutex_init(&_gc_mutex,NULL) != 0 ||
pthread_cond_init(&_gc_cond,NULL) != 0)
- PANIC("Failed to initialise garbage collector mutex or condvar");
+ PANIC("Failed to initialise garbage collector mutex or cond");
+
+#if defined(__ELF__)
+ /* Register with dlctl for thread safe dlopen */
+ dlctl(NULL, DL_SETTHREADLCK, _thread_kern_lock);
+#endif
_thread_autoinit_dummy_decl = 0;
}
#endif
diff --git a/lib/libpthread/uthread/uthread_kern.c b/lib/libpthread/uthread/uthread_kern.c
index 5a9e7ccc3c3..ef9d87957b0 100644
--- a/lib/libpthread/uthread/uthread_kern.c
+++ b/lib/libpthread/uthread/uthread_kern.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_kern.c,v 1.26 2003/01/31 04:46:17 marc Exp $ */
+/* $OpenBSD: uthread_kern.c,v 1.27 2003/05/13 16:49:32 marc Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -940,6 +940,22 @@ _thread_kern_set_timeout(const struct timespec * timeout)
}
}
+/*
+ * Function registered with dlctl to lock/unlock the kernel for
+ * threade safe dlopen calls.
+ * which == 0: defer signals (stops scheduler)
+ * which != 0: undefer signals and process any queued sigs
+ */
+void
+_thread_kern_lock(int which)
+{
+ if (which == 0)
+ _thread_kern_sig_defer();
+ else
+ _thread_kern_sig_undefer();
+}
+
+
void
_thread_kern_sig_defer(void)
{