Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib - Allow libpthread to be dlopened again, by providing li...
details: https://anonhg.NetBSD.org/src/rev/e6591ea54cc0
branches: trunk
changeset: 785582:e6591ea54cc0
user: christos <christos%NetBSD.org@localhost>
date: Thu Mar 21 16:49:11 2013 +0000
description:
- Allow libpthread to be dlopened again, by providing libc stubs to libpthread.
- Fail if the dlopened libpthread does pthread_create(). From manu@
- Discussed at length in the mailing lists; approved by core@
- This was chosen as the least intrusive patch that will provide
the necessary functionality.
XXX: pullup to 6
diffstat:
lib/libc/include/reentrant.h | 52 ++++++++++++++++++++++++++++++-
lib/libc/thread-stub/thread-stub.c | 62 ++++++++++++++++--------------------
lib/libpthread/Makefile | 9 ++--
lib/libpthread/pthread.c | 33 ++++++++++++++++++-
lib/libpthread/pthread_cancelstub.c | 8 ++-
lib/libpthread/pthread_cond.c | 21 ++++++++++-
lib/libpthread/pthread_int.h | 4 +-
lib/libpthread/pthread_misc.c | 9 +++-
lib/libpthread/pthread_mutex.c | 28 ++++++++++++++-
lib/libpthread/pthread_once.c | 8 +++-
lib/libpthread/pthread_rwlock.c | 25 ++++++++++++--
lib/libpthread/pthread_specific.c | 25 ++++++++++----
lib/libpthread/pthread_tsd.c | 14 ++++++-
13 files changed, 227 insertions(+), 71 deletions(-)
diffs (truncated from 924 to 300 lines):
diff -r 160f39d33f71 -r e6591ea54cc0 lib/libc/include/reentrant.h
--- a/lib/libc/include/reentrant.h Thu Mar 21 15:16:43 2013 +0000
+++ b/lib/libc/include/reentrant.h Thu Mar 21 16:49:11 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: reentrant.h,v 1.15 2012/06/03 21:27:30 joerg Exp $ */
+/* $NetBSD: reentrant.h,v 1.16 2013/03/21 16:49:11 christos Exp $ */
/*-
* Copyright (c) 1997, 1998, 2003 The NetBSD Foundation, Inc.
@@ -221,6 +221,56 @@
#define thr_enabled() (__isthreaded)
#define thr_setcancelstate(n, o) __libc_thr_setcancelstate((n),(o))
#define thr_curcpu() __libc_thr_curcpu()
+
+#else /* __LIBC_THREAD_STUBS */
+
+__BEGIN_DECLS
+void __libc_thr_init_stub(void);
+
+int __libc_mutex_init_stub(mutex_t *, const mutexattr_t *);
+int __libc_mutex_lock_stub(mutex_t *);
+int __libc_mutex_trylock_stub(mutex_t *);
+int __libc_mutex_unlock_stub(mutex_t *);
+int __libc_mutex_destroy_stub(mutex_t *);
+
+int __libc_mutexattr_init_stub(mutexattr_t *);
+int __libc_mutexattr_destroy_stub(mutexattr_t *);
+int __libc_mutexattr_settype_stub(mutexattr_t *, int);
+
+int __libc_cond_init_stub(cond_t *, const condattr_t *);
+int __libc_cond_signal_stub(cond_t *);
+int __libc_cond_broadcast_stub(cond_t *);
+int __libc_cond_wait_stub(cond_t *, mutex_t *);
+int __libc_cond_timedwait_stub(cond_t *, mutex_t *,
+ const struct timespec *);
+int __libc_cond_destroy_stub(cond_t *);
+
+int __libc_rwlock_init_stub(rwlock_t *, const rwlockattr_t *);
+int __libc_rwlock_rdlock_stub(rwlock_t *);
+int __libc_rwlock_wrlock_stub(rwlock_t *);
+int __libc_rwlock_tryrdlock_stub(rwlock_t *);
+int __libc_rwlock_trywrlock_stub(rwlock_t *);
+int __libc_rwlock_unlock_stub(rwlock_t *);
+int __libc_rwlock_destroy_stub(rwlock_t *);
+
+int __libc_thr_keycreate_stub(thread_key_t *, void (*)(void *));
+int __libc_thr_setspecific_stub(thread_key_t, const void *);
+void *__libc_thr_getspecific_stub(thread_key_t);
+int __libc_thr_keydelete_stub(thread_key_t);
+
+int __libc_thr_once_stub(once_t *, void (*)(void));
+int __libc_thr_sigsetmask_stub(int, const sigset_t *, sigset_t *);
+thr_t __libc_thr_self_stub(void);
+int __libc_thr_yield_stub(void);
+int __libc_thr_create_stub(thr_t *, const thrattr_t *,
+ void *(*)(void *), void *);
+void __libc_thr_exit_stub(void *);
+int *__libc_thr_errno_stub(void);
+int __libc_thr_setcancelstate_stub(int, int *);
+int __libc_thr_equal_stub(pthread_t, pthread_t);
+unsigned int __libc_thr_curcpu_stub(void);
+__END_DECLS
+
#endif /* __LIBC_THREAD_STUBS */
#define FLOCKFILE(fp) __flockfile_internal(fp, 1)
diff -r 160f39d33f71 -r e6591ea54cc0 lib/libc/thread-stub/thread-stub.c
--- a/lib/libc/thread-stub/thread-stub.c Thu Mar 21 15:16:43 2013 +0000
+++ b/lib/libc/thread-stub/thread-stub.c Thu Mar 21 16:49:11 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: thread-stub.c,v 1.22 2011/09/16 16:05:59 joerg Exp $ */
+/* $NetBSD: thread-stub.c,v 1.23 2013/03/21 16:49:11 christos Exp $ */
/*-
* Copyright (c) 2003, 2009 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: thread-stub.c,v 1.22 2011/09/16 16:05:59 joerg Exp $");
+__RCSID("$NetBSD: thread-stub.c,v 1.23 2013/03/21 16:49:11 christos Exp $");
#endif /* LIBC_SCCS and not lint */
/*
@@ -69,9 +69,6 @@
/* libpthread init */
-void __libc_thr_init(void);
-void __libc_thr_init_stub(void);
-
__weak_alias(__libc_thr_init,__libc_thr_init_stub)
void
@@ -83,8 +80,7 @@
/* mutexes */
-int __libc_mutex_init_stub(mutex_t *, const mutexattr_t *);
-int __libc_mutex_catchall_stub(mutex_t *);
+int __libc_mutex_catchall_stub(mutex_t *);
__weak_alias(__libc_mutex_init,__libc_mutex_init_stub)
__weak_alias(__libc_mutex_lock,__libc_mutex_catchall_stub)
@@ -92,13 +88,20 @@
__weak_alias(__libc_mutex_unlock,__libc_mutex_catchall_stub)
__weak_alias(__libc_mutex_destroy,__libc_mutex_catchall_stub)
-int __libc_mutexattr_catchall_stub(mutexattr_t *);
-int __libc_mutexattr_settype_stub(mutexattr_t *, int);
+__strong_alias(__libc_mutex_lock_stub,__libc_mutex_catchall_stub)
+__strong_alias(__libc_mutex_trylock_stub,__libc_mutex_catchall_stub)
+__strong_alias(__libc_mutex_unlock_stub,__libc_mutex_catchall_stub)
+__strong_alias(__libc_mutex_destroy_stub,__libc_mutex_catchall_stub)
+
+int __libc_mutexattr_catchall_stub(mutexattr_t *);
__weak_alias(__libc_mutexattr_init,__libc_mutexattr_catchall_stub)
__weak_alias(__libc_mutexattr_destroy,__libc_mutexattr_catchall_stub)
__weak_alias(__libc_mutexattr_settype,__libc_mutexattr_settype_stub)
+__strong_alias(__libc_mutexattr_init_stub,__libc_mutexattr_catchall_stub)
+__strong_alias(__libc_mutexattr_destroy_stub,__libc_mutexattr_catchall_stub)
+
int
__libc_mutex_init_stub(mutex_t *m, const mutexattr_t *a)
{
@@ -147,11 +150,7 @@
/* condition variables */
-int __libc_cond_init_stub(cond_t *, const condattr_t *);
-int __libc_cond_wait_stub(cond_t *, mutex_t *);
-int __libc_cond_timedwait_stub(cond_t *, mutex_t *,
- const struct timespec *);
-int __libc_cond_catchall_stub(cond_t *);
+int __libc_cond_catchall_stub(cond_t *);
__weak_alias(__libc_cond_init,__libc_cond_init_stub)
__weak_alias(__libc_cond_signal,__libc_cond_catchall_stub)
@@ -160,6 +159,11 @@
__weak_alias(__libc_cond_timedwait,__libc_cond_timedwait_stub)
__weak_alias(__libc_cond_destroy,__libc_cond_catchall_stub)
+__strong_alias(__libc_cond_signal_stub,__libc_cond_catchall_stub)
+__strong_alias(__libc_cond_broadcast_stub,__libc_cond_catchall_stub)
+__strong_alias(__libc_cond_wait_stub,__libc_cond_catchall_stub)
+__strong_alias(__libc_cond_destroy_stub,__libc_cond_catchall_stub)
+
int
__libc_cond_init_stub(cond_t *c, const condattr_t *a)
{
@@ -215,8 +219,7 @@
/* read-write locks */
-int __libc_rwlock_init_stub(rwlock_t *, rwlockattr_t *);
-int __libc_rwlock_catchall_stub(rwlock_t *);
+int __libc_rwlock_catchall_stub(rwlock_t *);
__weak_alias(__libc_rwlock_init,__libc_rwlock_init_stub)
__weak_alias(__libc_rwlock_rdlock,__libc_rwlock_catchall_stub)
@@ -226,8 +229,16 @@
__weak_alias(__libc_rwlock_unlock,__libc_rwlock_catchall_stub)
__weak_alias(__libc_rwlock_destroy,__libc_rwlock_catchall_stub)
+__strong_alias(__libc_rwlock_rdlock_stub,__libc_rwlock_catchall_stub)
+__strong_alias(__libc_rwlock_wrlock_stub,__libc_rwlock_catchall_stub)
+__strong_alias(__libc_rwlock_tryrdlock_stub,__libc_rwlock_catchall_stub)
+__strong_alias(__libc_rwlock_trywrlock_stub,__libc_rwlock_catchall_stub)
+__strong_alias(__libc_rwlock_unlock_stub,__libc_rwlock_catchall_stub)
+__strong_alias(__libc_rwlock_destroy_stub,__libc_rwlock_catchall_stub)
+
+
int
-__libc_rwlock_init_stub(rwlock_t *l, rwlockattr_t *a)
+__libc_rwlock_init_stub(rwlock_t *l, const rwlockattr_t *a)
{
/* LINTED deliberate lack of effect */
(void)l;
@@ -265,11 +276,6 @@
} __libc_tsd[TSD_KEYS_MAX];
static int __libc_tsd_nextkey;
-int __libc_thr_keycreate_stub(thread_key_t *, void (*)(void *));
-int __libc_thr_setspecific_stub(thread_key_t, const void *);
-void *__libc_thr_getspecific_stub(thread_key_t);
-int __libc_thr_keydelete_stub(thread_key_t);
-
__weak_alias(__libc_thr_keycreate,__libc_thr_keycreate_stub)
__weak_alias(__libc_thr_setspecific,__libc_thr_setspecific_stub)
__weak_alias(__libc_thr_getspecific,__libc_thr_getspecific_stub)
@@ -337,18 +343,6 @@
/* misc. */
-int __libc_thr_once_stub(once_t *, void (*)(void));
-int __libc_thr_sigsetmask_stub(int, const sigset_t *, sigset_t *);
-thr_t __libc_thr_self_stub(void);
-int __libc_thr_yield_stub(void);
-int __libc_thr_create_stub(thr_t *, const thrattr_t *,
- void *(*)(void *), void *);
-__dead void __libc_thr_exit_stub(void *);
-int *__libc_thr_errno_stub(void);
-int __libc_thr_setcancelstate_stub(int, int *);
-int __libc_thr_equal_stub(pthread_t, pthread_t);
-unsigned int __libc_thr_curcpu_stub(void);
-
__weak_alias(__libc_thr_once,__libc_thr_once_stub)
__weak_alias(__libc_thr_sigsetmask,__libc_thr_sigsetmask_stub)
__weak_alias(__libc_thr_self,__libc_thr_self_stub)
diff -r 160f39d33f71 -r e6591ea54cc0 lib/libpthread/Makefile
--- a/lib/libpthread/Makefile Thu Mar 21 15:16:43 2013 +0000
+++ b/lib/libpthread/Makefile Thu Mar 21 16:49:11 2013 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.79 2013/02/25 17:04:46 apb Exp $
+# $NetBSD: Makefile,v 1.80 2013/03/21 16:49:11 christos Exp $
#
WARNS?= 5
@@ -25,16 +25,15 @@
ARCHDIR= ${.CURDIR}/arch/${ARCHSUBDIR}
.PATH: ${ARCHDIR}
-CPPFLAGS+= -I${ARCHDIR} -I${.CURDIR} -I${.OBJDIR} -D_LIBC
-CPPFLAGS+= -D__LIBPTHREAD_SOURCE__
+CPPFLAGS+= -I${ARCHDIR} -I${.CURDIR} -I${.OBJDIR} -D_LIBC -D_REENTRANT
+CPPFLAGS+= -I${.CURDIR}/../libc/include
+CPPFLAGS+= -D__LIBPTHREAD_SOURCE__ -D__LIBC_THREAD_STUBS
# XXX: This crappy poke at libc's internals needs to be fixed.
CPPFLAGS+=-I${NETBSDSRCDIR}/sys -I${.CURDIR}/../libc
LIB= pthread
-LDFLAGS+= -Wl,-znodlopen
-
#
# NOTE: When you create a new file for libpthread, make sure that pthread.c
# gets a reference to a symbol in that file. Otherwise, Unix's stupid static
diff -r 160f39d33f71 -r e6591ea54cc0 lib/libpthread/pthread.c
--- a/lib/libpthread/pthread.c Thu Mar 21 15:16:43 2013 +0000
+++ b/lib/libpthread/pthread.c Thu Mar 21 16:49:11 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pthread.c,v 1.142 2013/01/01 18:42:39 dsl Exp $ */
+/* $NetBSD: pthread.c,v 1.143 2013/03/21 16:49:11 christos Exp $ */
/*-
* Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: pthread.c,v 1.142 2013/01/01 18:42:39 dsl Exp $");
+__RCSID("$NetBSD: pthread.c,v 1.143 2013/03/21 16:49:11 christos Exp $");
#define __EXPOSE_STACK 1
@@ -59,6 +59,7 @@
#include "pthread.h"
#include "pthread_int.h"
+#include "reentrant.h"
pthread_rwlock_t pthread__alltree_lock = PTHREAD_RWLOCK_INITIALIZER;
static rb_tree_t pthread__alltree;
@@ -84,6 +85,7 @@
void pthread__init(void);
int pthread__started;
+int __uselibcstub = 1;
pthread_mutex_t pthread__deadqueue_lock = PTHREAD_MUTEX_INITIALIZER;
pthread_queue_t pthread__deadqueue;
pthread_queue_t pthread__allqueue;
@@ -162,6 +164,8 @@
int i;
extern int __isthreaded;
+ __uselibcstub = 0;
+
pthread__pagesize = (size_t)sysconf(_SC_PAGESIZE);
pthread__concurrency = (int)sysconf(_SC_NPROCESSORS_CONF);
@@ -387,6 +391,12 @@
void *private_area;
int ret;
+ if (__predict_false(__uselibcstub)) {
+ pthread__errorfunc(__FILE__, __LINE__, __func__,
+ "pthread_create() requires linking with -lpthread");
+ return __libc_thr_create_stub(thread, attr, startfunc, arg);
+ }
+
/*
* It's okay to check this without a lock because there can
* only be one thread before it becomes true.
@@ -601,6 +611,11 @@
struct pt_clean_t *cleanup;
char *name;
Home |
Main Index |
Thread Index |
Old Index