Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 24 Jan 2000 23:04:52 -0800 (PST)
From:      John Polstra <jdp@polstra.com>
To:        current@freebsd.org
Subject:   Need testers for libc_r patch
Message-ID:  <XFMail.000124230452.jdp@polstra.com>

index | next in thread | raw e-mail

[-- Attachment #1 --]
The attached patch makes libc_r use the recently added hooks in the
dynamic linker to provide locking so that the dynamic linker is
thread-safe.  I have tested it in a simple program and I believe it
works OK.  If any of you have a -current system with a non-trivial
libc_r application, I would appreciate it if you'd give this patch a
try and let me know whether you see any problems with it.  You can
apply the patch by getting into "src/lib/libc_r" and typing "patch
-IEp < libc_r.patch"

Also, if anybody can point me to programs in the ports collection
that use libc_r and aren't too hard to set up and run, that would be
helpful too.

Thanks,
John
---
  John Polstra                                               jdp@polstra.com
  John D. Polstra & Co., Inc.                        Seattle, Washington USA
  "Disappointment is a good sign of basic intelligence."  -- Chögyam Trungpa


[-- Attachment #2 --]
Index: uthread/Makefile.inc
===================================================================
RCS file: /home/ncvs/src/lib/libc_r/uthread/Makefile.inc,v
retrieving revision 1.22
diff -u -r1.22 Makefile.inc
--- uthread/Makefile.inc	2000/01/20 07:54:48	1.22
+++ uthread/Makefile.inc	2000/01/25 06:40:15
@@ -33,6 +33,7 @@
 	uthread_connect.c \
 	uthread_create.c \
 	uthread_detach.c \
+	uthread_dllock.c \
 	uthread_dup.c \
 	uthread_dup2.c \
 	uthread_equal.c \
Index: uthread/pthread_private.h
===================================================================
RCS file: /home/ncvs/src/lib/libc_r/uthread/pthread_private.h,v
retrieving revision 1.36
diff -u -r1.36 pthread_private.h
--- uthread/pthread_private.h	2000/01/20 21:53:58	1.36
+++ uthread/pthread_private.h	2000/01/25 06:55:22
@@ -1036,6 +1036,7 @@
 void    _thread_fd_unlock_owned(pthread_t);
 void    *_thread_cleanup(pthread_t);
 void    _thread_cleanupspecific(void);
+void    _thread_dllockinit(void);
 void    _thread_dump_info(void);
 void    _thread_init(void);
 void    _thread_kern_sched(ucontext_t *);
Index: uthread/uthread_dllock.c
===================================================================
RCS file: uthread_dllock.c
diff -N uthread_dllock.c
--- /dev/null	Mon Jan 24 21:55:53 2000
+++ uthread_dllock.c	Mon Jan 24 22:44:21 2000
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2000 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.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *	This product includes software developed by John Birrell.
+ * 4. Neither the name of the author nor the names of any co-contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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$
+ */
+
+#include <dlfcn.h>
+#include <stdlib.h>
+#ifdef _THREAD_SAFE
+#include <pthread.h>
+#include "pthread_private.h"
+
+static void *
+lock_create(void *ctx)
+{
+	pthread_rwlock_t *lock;
+
+	if ((lock = malloc(sizeof(pthread_rwlock_t))) == NULL)
+		PANIC("Cannot allocate rwlock for dynamic linker");
+	if (pthread_rwlock_init(lock, NULL) != 0)
+		PANIC("Cannot initialize rwlock for dynamic linker");
+	return lock;
+}
+
+static void
+rlock_acquire(void *lock)
+{
+	if (pthread_rwlock_rdlock((pthread_rwlock_t *)lock) != 0)
+		PANIC("Cannot lock dynamic linker rwlock for reading");
+}
+
+static void
+wlock_acquire(void *lock)
+{
+	if (pthread_rwlock_wrlock((pthread_rwlock_t *)lock) != 0)
+		PANIC("Cannot lock dynamic linker rwlock for writing");
+}
+
+static void
+lock_release(void *lock)
+{
+	if (pthread_rwlock_unlock((pthread_rwlock_t *)lock) != 0)
+		PANIC("Cannot unlock dynamic linker rwlock");
+}
+
+static void
+lock_destroy(void *lock)
+{
+	if (pthread_rwlock_destroy((pthread_rwlock_t *)lock) != 0)
+		PANIC("Cannot destroy dynamic linker rwlock");
+	free(lock);
+}
+
+void
+_thread_dllockinit(void)
+{
+	dllockinit(NULL, lock_create, rlock_acquire, wlock_acquire,
+	    lock_release, lock_destroy, NULL);
+}
+#endif
Index: uthread/uthread_init.c
===================================================================
RCS file: /home/ncvs/src/lib/libc_r/uthread/uthread_init.c,v
retrieving revision 1.23
diff -u -r1.23 uthread_init.c
--- uthread/uthread_init.c	2000/01/19 07:04:47	1.23
+++ uthread/uthread_init.c	2000/01/25 06:36:21
@@ -360,6 +360,9 @@
 	    pthread_cond_init(&_gc_cond,NULL) != 0)
 		PANIC("Failed to initialise garbage collector mutex or condvar");
 
+	/* Set up the locking to make the dynamic linker thread-safe. */
+	_thread_dllockinit();
+
 	gettimeofday(&kern_inc_prio_time, NULL);
 
 	return;
help

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?XFMail.000124230452.jdp>