summaryrefslogtreecommitdiffstats
path: root/libexec/rtld-elf/alpha/lockdflt.c
diff options
context:
space:
mode:
authorjdp <jdp@FreeBSD.org>1999-12-27 04:44:04 +0000
committerjdp <jdp@FreeBSD.org>1999-12-27 04:44:04 +0000
commit52ec4df9e85a6ae74cd9f5cf905ae35c0c1a6670 (patch)
treee4e05bba4c3de19150902d099920062a8bdb21ab /libexec/rtld-elf/alpha/lockdflt.c
parentefacb21bbc4c5e4ae5ef661233ee6249ee8a0e7f (diff)
downloadFreeBSD-src-52ec4df9e85a6ae74cd9f5cf905ae35c0c1a6670.zip
FreeBSD-src-52ec4df9e85a6ae74cd9f5cf905ae35c0c1a6670.tar.gz
Add a new function dllockinit() for registering thread locking
functions to be used by the dynamic linker. This can be called by threads packages at start-up time. I will add the call to libc_r soon. Also add a default locking method that is used up until dllockinit() is called. The default method works by blocking SIGVTALRM, SIGPROF, and SIGALRM in critical sections. It is based on the observation that most user-space threads packages implement thread preemption with one of these signals (usually SIGVTALRM). The dynamic linker has never been reentrant, but it became less reentrant in revision 1.34 of "src/libexec/rtld-elf/rtld.c". Starting with that revision, multiple threads each doing lazy binding could interfere with each other. The usual symptom was that a symbol was falsely reported as undefined at start-up time. It was rare but not unseen. This commit fixes it.
Diffstat (limited to 'libexec/rtld-elf/alpha/lockdflt.c')
-rw-r--r--libexec/rtld-elf/alpha/lockdflt.c94
1 files changed, 94 insertions, 0 deletions
diff --git a/libexec/rtld-elf/alpha/lockdflt.c b/libexec/rtld-elf/alpha/lockdflt.c
new file mode 100644
index 0000000..6f278c3
--- /dev/null
+++ b/libexec/rtld-elf/alpha/lockdflt.c
@@ -0,0 +1,94 @@
+/*-
+ * Copyright 1999 John D. Polstra.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+/*
+ * Default thread locking implementation for the dynamic linker. It
+ * is used until the client registers a different implementation with
+ * dllockinit(). The default implementation does mutual exclusion
+ * by blocking the SIGVTALRM, SIGPROF, and SIGALRM signals. This is
+ * based on the observation that most userland thread packages use one
+ * of these signals to support preemption.
+ */
+
+#include <dlfcn.h>
+#include <signal.h>
+#include <stdlib.h>
+
+#include "debug.h"
+#include "rtld.h"
+
+typedef struct Struct_LockDflt {
+ sigset_t lock_mask;
+ sigset_t old_mask;
+ int depth;
+} LockDflt;
+
+void
+lockdflt_acquire(void *lock)
+{
+ LockDflt *l = (LockDflt *)lock;
+ sigprocmask(SIG_BLOCK, &l->lock_mask, &l->old_mask);
+ assert(l->depth == 0);
+ l->depth++;
+}
+
+void *
+lockdflt_create(void *context)
+{
+ LockDflt *l;
+
+ l = NEW(LockDflt);
+ l->depth = 0;
+ sigemptyset(&l->lock_mask);
+ sigaddset(&l->lock_mask, SIGVTALRM);
+ sigaddset(&l->lock_mask, SIGPROF);
+ sigaddset(&l->lock_mask, SIGALRM);
+ return l;
+}
+
+void
+lockdflt_destroy(void *lock)
+{
+ LockDflt *l = (LockDflt *)lock;
+ free(l);
+}
+
+void
+lockdflt_release(void *lock)
+{
+ LockDflt *l = (LockDflt *)lock;
+ assert(l->depth == 1);
+ l->depth--;
+ sigprocmask(SIG_SETMASK, &l->old_mask, NULL);
+}
+
+void
+lockdflt_init(void)
+{
+ dllockinit(NULL, lockdflt_create, lockdflt_acquire, lockdflt_acquire,
+ lockdflt_release, lockdflt_destroy, NULL);
+}
OpenPOWER on IntegriCloud