Date: Thu, 29 May 2003 18:14:06 -0700 (PDT) From: Peter Wemm <peter@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 32083 for review Message-ID: <200305300114.h4U1E6hR083673@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=32083 Change 32083 by peter@peter_daintree on 2003/05/29 18:13:15 IFC @32081 Affected files ... .. //depot/projects/hammer/lib/libpthread/Makefile#7 integrate .. //depot/projects/hammer/lib/libpthread/pthread.map#1 branch .. //depot/projects/hammer/lib/libpthread/support/Makefile.inc#1 branch .. //depot/projects/hammer/lib/libpthread/support/thr_support.c#1 branch .. //depot/projects/hammer/lib/libpthread/sys/Makefile.inc#4 integrate .. //depot/projects/hammer/lib/libpthread/thread/Makefile.inc#5 integrate .. //depot/projects/hammer/lib/libpthread/thread/thr_cond.c#8 integrate .. //depot/projects/hammer/lib/libpthread/thread/thr_exit.c#5 integrate .. //depot/projects/hammer/lib/libpthread/thread/thr_init.c#8 integrate .. //depot/projects/hammer/lib/libpthread/thread/thr_mutex.c#5 integrate .. //depot/projects/hammer/lib/libpthread/thread/thr_private.h#10 integrate .. //depot/projects/hammer/lib/libpthread/thread/thr_rtld.c#1 branch .. //depot/projects/hammer/lib/libpthread/thread/thr_rwlock.c#4 integrate .. //depot/projects/hammer/lib/libpthread/thread/thr_sigprocmask.c#2 integrate .. //depot/projects/hammer/libexec/rtld-elf/Makefile#4 integrate .. //depot/projects/hammer/libexec/rtld-elf/alpha/rtld_machdep.h#3 integrate .. //depot/projects/hammer/libexec/rtld-elf/alpha/rtld_start.S#2 integrate .. //depot/projects/hammer/libexec/rtld-elf/amd64/rtld_machdep.h#5 integrate .. //depot/projects/hammer/libexec/rtld-elf/i386/lockdflt.c#2 integrate .. //depot/projects/hammer/libexec/rtld-elf/i386/rtld_machdep.h#3 integrate .. //depot/projects/hammer/libexec/rtld-elf/ia64/reloc.c#5 integrate .. //depot/projects/hammer/libexec/rtld-elf/ia64/rtld_machdep.h#3 integrate .. //depot/projects/hammer/libexec/rtld-elf/ia64/rtld_start.S#2 integrate .. //depot/projects/hammer/libexec/rtld-elf/libmap.c#5 integrate .. //depot/projects/hammer/libexec/rtld-elf/powerpc/reloc.c#3 integrate .. //depot/projects/hammer/libexec/rtld-elf/powerpc/rtld_machdep.h#2 integrate .. //depot/projects/hammer/libexec/rtld-elf/powerpc/rtld_start.S#2 integrate .. //depot/projects/hammer/libexec/rtld-elf/rtld.c#8 integrate .. //depot/projects/hammer/libexec/rtld-elf/rtld.h#3 integrate .. //depot/projects/hammer/libexec/rtld-elf/rtld_lock.c#1 branch .. //depot/projects/hammer/libexec/rtld-elf/rtld_lock.h#1 branch .. //depot/projects/hammer/libexec/rtld-elf/sparc64/reloc.c#6 integrate .. //depot/projects/hammer/libexec/rtld-elf/sparc64/rtld_machdep.h#4 integrate .. //depot/projects/hammer/libexec/rtld-elf/sparc64/rtld_start.S#3 integrate .. //depot/projects/hammer/sys/amd64/amd64/amd64-gdbstub.c#3 integrate .. //depot/projects/hammer/sys/amd64/amd64/db_interface.c#7 integrate .. //depot/projects/hammer/sys/amd64/amd64/db_trace.c#6 integrate .. //depot/projects/hammer/sys/amd64/amd64/support.S#9 integrate .. //depot/projects/hammer/sys/amd64/include/db_machdep.h#7 integrate .. //depot/projects/hammer/sys/conf/Makefile.amd64#12 integrate .. //depot/projects/hammer/sys/conf/files.amd64#17 integrate .. //depot/projects/hammer/sys/conf/kern.mk#12 integrate .. //depot/projects/hammer/sys/dev/usb/ugen.c#5 integrate .. //depot/projects/hammer/sys/security/mac_biba/mac_biba.c#12 integrate .. //depot/projects/hammer/sys/security/mac_mls/mac_mls.c#12 integrate Differences ... ==== //depot/projects/hammer/lib/libpthread/Makefile#7 (text+ko) ==== @@ -1,4 +1,4 @@ -# $FreeBSD: src/lib/libpthread/Makefile,v 1.41 2003/04/25 01:31:56 deischen Exp $ +# $FreeBSD: src/lib/libpthread/Makefile,v 1.42 2003/05/30 00:21:51 kan Exp $ # # All library objects contain FreeBSD revision strings by default; they may be # excluded as a space-saving measure. To produce a library that does @@ -14,12 +14,16 @@ -I${.CURDIR}/../../include CFLAGS+=-I${.CURDIR}/arch/${MACHINE_ARCH}/include CFLAGS+=-I${.CURDIR}/sys +CFLAGS+=-I${.CURDIR}/../../libexec/rtld-elf +CFLAGS+=-fno-builtin # Uncomment this if you want libpthread to contain debug information for # thread locking. CFLAGS+=-D_LOCK_DEBUG #CFLAGS+= -g +LDADD+= -Wl,--version-script=${.CURDIR}/pthread.map + # enable extra internal consistancy checks CFLAGS+=-D_PTHREADS_INVARIANTS -Wall @@ -28,5 +32,6 @@ .include "${.CURDIR}/thread/Makefile.inc" .include "${.CURDIR}/sys/Makefile.inc" +.include "${.CURDIR}/support/Makefile.inc" .include <bsd.lib.mk> ==== //depot/projects/hammer/lib/libpthread/sys/Makefile.inc#4 (text+ko) ==== @@ -1,6 +1,7 @@ -# $FreeBSD: src/lib/libpthread/sys/Makefile.inc,v 1.13 2003/04/18 05:02:39 deischen Exp $ +# $FreeBSD: src/lib/libpthread/sys/Makefile.inc,v 1.14 2003/05/30 00:21:52 kan Exp $ .PATH: ${.CURDIR}/sys ${.CURDIR}/arch/${MACHINE_ARCH}/${MACHINE_ARCH} SRCS+= thr_error.c _atomic_lock.S ksd.c thr_enter_uts.S thr_getcontext.S \ thr_switch.S lock.c + ==== //depot/projects/hammer/lib/libpthread/thread/Makefile.inc#5 (text+ko) ==== @@ -1,4 +1,4 @@ -# $FreeBSD: src/lib/libpthread/thread/Makefile.inc,v 1.40 2003/04/22 20:29:16 deischen Exp $ +# $FreeBSD: src/lib/libpthread/thread/Makefile.inc,v 1.41 2003/05/30 00:21:52 kan Exp $ # thr sources .PATH: ${.CURDIR}/thread @@ -71,6 +71,7 @@ thr_read.c \ thr_readv.c \ thr_resume_np.c \ + thr_rtld.c \ thr_rwlock.c \ thr_rwlockattr.c \ thr_select.c \ ==== //depot/projects/hammer/lib/libpthread/thread/thr_cond.c#8 (text+ko) ==== @@ -29,7 +29,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/lib/libpthread/thread/thr_cond.c,v 1.42 2003/05/24 02:29:25 deischen Exp $ + * $FreeBSD: src/lib/libpthread/thread/thr_cond.c,v 1.43 2003/05/30 00:21:52 kan Exp $ */ #include <stdlib.h> #include <errno.h> @@ -355,6 +355,8 @@ return (rval); } +__strong_reference(_pthread_cond_wait, _thr_cond_wait); + int __pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex) { @@ -632,6 +634,8 @@ return (rval); } +__strong_reference(_pthread_cond_signal, _thr_cond_signal); + int _pthread_cond_broadcast(pthread_cond_t * cond) { @@ -673,7 +677,7 @@ /* There are no more waiting threads: */ (*cond)->c_mutex = NULL; break; - + /* Trap invalid condition variable types: */ default: /* Return an invalid argument error: */ @@ -689,6 +693,8 @@ return (rval); } +__strong_reference(_pthread_cond_broadcast, _thr_cond_broadcast); + void _cond_wait_backout(struct pthread *curthread) { ==== //depot/projects/hammer/lib/libpthread/thread/thr_exit.c#5 (text+ko) ==== @@ -29,7 +29,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/lib/libpthread/thread/thr_exit.c,v 1.32 2003/05/16 19:58:29 deischen Exp $ + * $FreeBSD: src/lib/libpthread/thread/thr_exit.c,v 1.33 2003/05/30 00:21:52 kan Exp $ */ #include <errno.h> #include <unistd.h> @@ -47,16 +47,12 @@ void _thr_exit(char *fname, int lineno, char *msg) { - char s[256]; - /* Prepare an error message string: */ - snprintf(s, sizeof(s), + /* Write an error message to the standard error file descriptor: */ + _thread_printf(2, "Fatal error '%s' at line %d in file %s (errno = %d)\n", msg, lineno, fname, errno); - /* Write the string to the standard error file descriptor: */ - __sys_write(2, s, strlen(s)); - abort(); } ==== //depot/projects/hammer/lib/libpthread/thread/thr_init.c#8 (text+ko) ==== @@ -30,7 +30,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/lib/libpthread/thread/thr_init.c,v 1.53 2003/05/29 17:10:45 deischen Exp $ + * $FreeBSD: src/lib/libpthread/thread/thr_init.c,v 1.54 2003/05/30 00:21:52 kan Exp $ */ /* Allocate space for global thread variables here: */ @@ -304,6 +304,8 @@ _thr_initial->kse->k_curthread = _thr_initial; _thr_initial->kse->k_flags |= KF_INITIALIZED; _kse_initial->k_curthread = _thr_initial; + + _thr_rtld_init(); } /* ==== //depot/projects/hammer/lib/libpthread/thread/thr_mutex.c#5 (text+ko) ==== @@ -29,7 +29,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/lib/libpthread/thread/thr_mutex.c,v 1.35 2003/05/16 19:58:29 deischen Exp $ + * $FreeBSD: src/lib/libpthread/thread/thr_mutex.c,v 1.36 2003/05/30 00:21:52 kan Exp $ */ #include <stdlib.h> #include <errno.h> @@ -718,6 +718,8 @@ return (ret); } +__strong_reference(__pthread_mutex_lock, _thr_mutex_lock); + int _pthread_mutex_lock(pthread_mutex_t *m) { @@ -748,6 +750,8 @@ return (mutex_unlock_common(m, /* add reference */ 0)); } +__strong_reference(_pthread_mutex_unlock, _thr_mutex_unlock); + int _mutex_cv_unlock(pthread_mutex_t *m) { ==== //depot/projects/hammer/lib/libpthread/thread/thr_private.h#10 (text+ko) ==== @@ -31,7 +31,7 @@ * * Private thread definitions for the uthread kernel. * - * $FreeBSD: src/lib/libpthread/thread/thr_private.h,v 1.88 2003/05/29 17:10:45 deischen Exp $ + * $FreeBSD: src/lib/libpthread/thread/thr_private.h,v 1.89 2003/05/30 00:21:52 kan Exp $ */ #ifndef _THR_PRIVATE_H @@ -794,6 +794,11 @@ struct pthread_specific_elem *specific; int specific_data_count; + /* + * Current locks bitmap for rtld. + */ + int rtld_bits; + /* Cleanup handlers Link List */ struct pthread_cleanup *cleanup; char *fname; /* Ptr to source file name */ @@ -1084,6 +1089,8 @@ int _pthread_mutexattr_destroy(pthread_mutexattr_t *); int _pthread_mutexattr_settype(pthread_mutexattr_t *, int); int _pthread_once(pthread_once_t *, void (*) (void)); +int _pthread_rwlock_init(pthread_rwlock_t *, const pthread_rwlockattr_t *); +int _pthread_rwlock_destroy (pthread_rwlock_t *); struct pthread *_pthread_self(void); int _pthread_setspecific(pthread_key_t, const void *); struct pthread *_thr_alloc(struct pthread *); @@ -1128,6 +1135,19 @@ int _thr_setconcurrency(int new_level); int _thr_setmaxconcurrency(void); +/* + * Aliases for _pthread functions. Should be called instead of + * originals if PLT replocation is unwanted at runtme. + */ +int _thr_cond_broadcast(pthread_cond_t *); +int _thr_cond_signal(pthread_cond_t *); +int _thr_cond_wait(pthread_cond_t *, pthread_mutex_t *); +int _thr_mutex_lock(pthread_mutex_t *); +int _thr_mutex_unlock(pthread_mutex_t *); +int _thr_rwlock_rdlock (pthread_rwlock_t *); +int _thr_rwlock_wrlock (pthread_rwlock_t *); +int _thr_rwlock_unlock (pthread_rwlock_t *); + /* XXX - Stuff that goes away when my sources get more up to date. */ /* #include <sys/kse.h> */ #ifdef SYS_KSE_H ==== //depot/projects/hammer/lib/libpthread/thread/thr_rwlock.c#4 (text+ko) ==== @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/lib/libpthread/thread/thr_rwlock.c,v 1.11 2003/04/18 05:04:16 deischen Exp $ + * $FreeBSD: src/lib/libpthread/thread/thr_rwlock.c,v 1.12 2003/05/30 00:21:52 kan Exp $ */ #include <errno.h> @@ -46,7 +46,6 @@ __weak_reference(_pthread_rwlock_unlock, pthread_rwlock_unlock); __weak_reference(_pthread_rwlock_wrlock, pthread_rwlock_wrlock); - /* * Prototypes */ @@ -158,16 +157,16 @@ } /* grab the monitor lock */ - if ((ret = _pthread_mutex_lock(&prwlock->lock)) != 0) + if ((ret = _thr_mutex_lock(&prwlock->lock)) != 0) return (ret); /* give writers priority over readers */ while (prwlock->blocked_writers || prwlock->state < 0) { - ret = _pthread_cond_wait(&prwlock->read_signal, &prwlock->lock); + ret = _thr_cond_wait(&prwlock->read_signal, &prwlock->lock); if (ret != 0) { /* can't do a whole lot if this fails */ - _pthread_mutex_unlock(&prwlock->lock); + _thr_mutex_unlock(&prwlock->lock); return (ret); } } @@ -184,11 +183,13 @@ * lock. Decrementing 'state' is no good because we probably * don't have the monitor lock. */ - _pthread_mutex_unlock(&prwlock->lock); + _thr_mutex_unlock(&prwlock->lock); return (ret); } +__strong_reference(_pthread_rwlock_rdlock, _thr_rwlock_rdlock); + int _pthread_rwlock_tryrdlock (pthread_rwlock_t *rwlock) { @@ -276,28 +277,30 @@ return (EINVAL); /* grab the monitor lock */ - if ((ret = _pthread_mutex_lock(&prwlock->lock)) != 0) + if ((ret = _thr_mutex_lock(&prwlock->lock)) != 0) return (ret); if (prwlock->state > 0) { if (--prwlock->state == 0 && prwlock->blocked_writers) - ret = _pthread_cond_signal(&prwlock->write_signal); + ret = _thr_cond_signal(&prwlock->write_signal); } else if (prwlock->state < 0) { prwlock->state = 0; if (prwlock->blocked_writers) - ret = _pthread_cond_signal(&prwlock->write_signal); + ret = _thr_cond_signal(&prwlock->write_signal); else - ret = _pthread_cond_broadcast(&prwlock->read_signal); + ret = _thr_cond_broadcast(&prwlock->read_signal); } else ret = EINVAL; /* see the comment on this in pthread_rwlock_rdlock */ - _pthread_mutex_unlock(&prwlock->lock); + _thr_mutex_unlock(&prwlock->lock); return (ret); } +__strong_reference(_pthread_rwlock_unlock, _thr_rwlock_unlock); + int _pthread_rwlock_wrlock (pthread_rwlock_t *rwlock) { @@ -318,17 +321,17 @@ } /* grab the monitor lock */ - if ((ret = _pthread_mutex_lock(&prwlock->lock)) != 0) + if ((ret = _thr_mutex_lock(&prwlock->lock)) != 0) return (ret); while (prwlock->state != 0) { ++prwlock->blocked_writers; - ret = _pthread_cond_wait(&prwlock->write_signal, &prwlock->lock); + ret = _thr_cond_wait(&prwlock->write_signal, &prwlock->lock); if (ret != 0) { --prwlock->blocked_writers; - _pthread_mutex_unlock(&prwlock->lock); + _thr_mutex_unlock(&prwlock->lock); return (ret); } @@ -339,7 +342,9 @@ prwlock->state = -1; /* see the comment on this in pthread_rwlock_rdlock */ - _pthread_mutex_unlock(&prwlock->lock); + _thr_mutex_unlock(&prwlock->lock); return (ret); } + +__strong_reference(_pthread_rwlock_wrlock, _thr_rwlock_wrlock); ==== //depot/projects/hammer/lib/libpthread/thread/thr_sigprocmask.c#2 (text+ko) ==== @@ -29,7 +29,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/lib/libpthread/thread/thr_sigprocmask.c,v 1.13 2002/09/16 08:45:36 mini Exp $ + * $FreeBSD: src/lib/libpthread/thread/thr_sigprocmask.c,v 1.14 2003/05/30 00:09:22 deischen Exp $ */ #include <sys/param.h> #include <sys/types.h> @@ -44,5 +44,8 @@ int _sigprocmask(int how, const sigset_t *set, sigset_t *oset) { - return (pthread_sigmask(how, set, oset)); + if (_kse_isthreaded() != 0) + return (pthread_sigmask(how, set, oset)); + else + return (__sys_sigprocmask(how, set, oset)); } ==== //depot/projects/hammer/libexec/rtld-elf/Makefile#4 (text+ko) ==== @@ -1,10 +1,11 @@ -# $FreeBSD: src/libexec/rtld-elf/Makefile,v 1.18 2003/04/07 16:21:25 mdodd Exp $ +# $FreeBSD: src/libexec/rtld-elf/Makefile,v 1.19 2003/05/29 22:58:22 kan Exp $ PROG= ld-elf.so.1 -SRCS= rtld_start.S rtld.c lockdflt.c map_object.c malloc.c \ +SRCS= rtld_start.S rtld.c rtld_lock.c map_object.c malloc.c \ xmalloc.c debug.c reloc.c MAN= rtld.1 -CFLAGS+= -Wall -DFREEBSD_ELF -I${.CURDIR}/${MACHINE_ARCH} -I${.CURDIR} +CFLAGS+= -Wall -DFREEBSD_ELF -DIN_RTLD +CFLAGS+= -I${.CURDIR}/${MACHINE_ARCH} -I${.CURDIR} LDFLAGS+= -nostdlib -e .rtld_start INSTALLFLAGS= -fschg -C -b MLINKS= rtld.1 ld-elf.so.1.1 \ ==== //depot/projects/hammer/libexec/rtld-elf/alpha/rtld_machdep.h#3 (text+ko) ==== @@ -23,12 +23,24 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/libexec/rtld-elf/alpha/rtld_machdep.h,v 1.8 2002/11/18 22:08:49 tmm Exp $ + * $FreeBSD: src/libexec/rtld-elf/alpha/rtld_machdep.h,v 1.9 2003/05/29 22:58:24 kan Exp $ */ #ifndef RTLD_MACHDEP_H #define RTLD_MACHDEP_H 1 +#include <sys/types.h> +#include <machine/atomic.h> + +/* + * This value of CACHE_LINE_SIZE is conservative. The actual size + * is 32 on the 21064, 21064A, 21066, 21066A, and 21164. It is 64 + * on the 21264. Compaq recommends sequestering each lock in its own + * 128-byte block to allow for future implementations with larger + * cache lines. + */ +#define CACHE_LINE_SIZE 128 + struct Struct_Obj_Entry; /* Return the address of the .dynamic section in the dynamic linker. */ @@ -48,10 +60,4 @@ /* Lazy binding entry point, called via PLT. */ void _rtld_bind_start_old(void); -/* Atomic operations. */ -int cmp0_and_store_int(volatile int *, int); -void atomic_add_int(volatile int *, int); -void atomic_incr_int(volatile int *); -void atomic_decr_int(volatile int *); - #endif ==== //depot/projects/hammer/libexec/rtld-elf/alpha/rtld_start.S#2 (text+ko) ==== @@ -1,4 +1,4 @@ -/* $FreeBSD: src/libexec/rtld-elf/alpha/rtld_start.S,v 1.5 2002/02/18 02:24:10 peter Exp $ */ +/* $FreeBSD: src/libexec/rtld-elf/alpha/rtld_start.S,v 1.6 2003/05/29 22:58:24 kan Exp $ */ /* From: NetBSD: rtld_start.S,v 1.1 1996/12/16 20:38:09 cgd Exp */ /* @@ -209,52 +209,3 @@ END(_rtld_bind_start_old) -/* - * int cmp0_and_store_int(volatile int *p, int newval); - * - * If an int holds 0, store newval into it; else do nothing. Returns - * the previous value. - */ -LEAF(cmp0_and_store_int, 2) -1: mov a1, t0 - ldl_l v0, 0(a0) - bne v0, 3f - stl_c t0, 0(a0) - beq t0, 2f - mb - RET -2: br 1b -3: RET -END(cmp0_and_store_int) - -LEAF(atomic_add_int, 2) -0: ldl_l t0, 0(a0) - addq t0, a1, t0 - stl_c t0, 0(a0) - beq t0, 1f - mb - RET -1: br 0b -END(atomic_add_int) - -/* Atomically increment an int. */ -LEAF(atomic_incr_int, 1) -0: ldl_l t0, 0(a0) - addq t0, 1, t0 - stl_c t0, 0(a0) - beq t0, 1f - mb - RET -1: br 0b -END(atomic_incr_int) - -/* Atomically decrement an int. */ -LEAF(atomic_decr_int, 1) -0: ldl_l t0, 0(a0) - subq t0, 1, t0 - stl_c t0, 0(a0) - beq t0, 1f - mb - RET -1: br 0b -END(atomic_decr_int) ==== //depot/projects/hammer/libexec/rtld-elf/amd64/rtld_machdep.h#5 (text+ko) ==== @@ -23,12 +23,17 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/libexec/rtld-elf/amd64/rtld_machdep.h,v 1.8 2002/11/18 22:08:49 tmm Exp $ + * $FreeBSD: src/libexec/rtld-elf/amd64/rtld_machdep.h,v 1.9 2003/05/29 22:58:24 kan Exp $ */ #ifndef RTLD_MACHDEP_H #define RTLD_MACHDEP_H 1 +#include <sys/types.h> +#include <machine/atomic.h> + +#define CACHE_LINE_SIZE 32 + struct Struct_Obj_Entry; /* Return the address of the .dynamic section in the dynamic linker. */ @@ -53,25 +58,4 @@ #define call_initfini_pointer(obj, target) \ (((InitFunc)(target))()) -static inline void -atomic_decr_int(volatile int *p) -{ - __asm __volatile ("lock; decl %0" : "+m"(*p) : : "cc"); -} - -static inline void -atomic_incr_int(volatile int *p) -{ - __asm __volatile ("lock; incl %0" : "+m"(*p) : : "cc"); -} - -static inline void -atomic_add_int(volatile int *p, int val) -{ - __asm __volatile ("lock; addl %1, %0" - : "+m"(*p) - : "ri"(val) - : "cc"); -} - #endif ==== //depot/projects/hammer/libexec/rtld-elf/i386/lockdflt.c#2 (text+ko) ==== @@ -22,7 +22,7 @@ * (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: src/libexec/rtld-elf/i386/lockdflt.c,v 1.8 2002/07/06 20:25:55 jdp Exp $ + * $FreeBSD: src/libexec/rtld-elf/i386/lockdflt.c,v 1.9 2003/05/29 22:58:25 kan Exp $ */ /* @@ -50,24 +50,7 @@ #include <setjmp.h> #include <signal.h> -#include <stdlib.h> -#include <time.h> - -#include "debug.h" -#include "rtld.h" - -#define CACHE_LINE_SIZE 32 - -#define WAFLAG 0x1 /* A writer holds the lock */ -#define RC_INCR 0x2 /* Adjusts count of readers desiring lock */ - -typedef struct Struct_Lock { - volatile int lock; - void *base; -} Lock; -static sigset_t fullsigmask, oldsigmask; - static inline int cmpxchgl(int old, int new, volatile int *m) { @@ -93,44 +76,6 @@ return result; } -static void * -lock_create(void *context) -{ - void *base; - char *p; - uintptr_t r; - Lock *l; - - /* - * Arrange for the lock to occupy its own cache line. First, we - * optimistically allocate just a cache line, hoping that malloc - * will give us a well-aligned block of memory. If that doesn't - * work, we allocate a larger block and take a well-aligned cache - * line from it. - */ - base = xmalloc(CACHE_LINE_SIZE); - p = (char *)base; - if ((uintptr_t)p % CACHE_LINE_SIZE != 0) { - free(base); - base = xmalloc(2 * CACHE_LINE_SIZE); - p = (char *)base; - if ((r = (uintptr_t)p % CACHE_LINE_SIZE) != 0) - p += CACHE_LINE_SIZE - r; - } - l = (Lock *)p; - l->base = base; - l->lock = 0; - return l; -} - -static void -lock_destroy(void *lock) -{ - Lock *l = (Lock *)lock; - - free(l->base); -} - /* * Crude exclusive locks for the 80386, which does not support the * cmpxchg instruction. @@ -162,51 +107,6 @@ } /* - * Better reader/writer locks for the 80486 and later CPUs. - */ -static void -rlock_acquire(void *lock) -{ - Lock *l = (Lock *)lock; - - atomic_add_int(&l->lock, RC_INCR); - while (l->lock & WAFLAG) - ; /* Spin */ -} - -static void -wlock_acquire(void *lock) -{ - Lock *l = (Lock *)lock; - sigset_t tmp_oldsigmask; - - for ( ; ; ) { - sigprocmask(SIG_BLOCK, &fullsigmask, &tmp_oldsigmask); - if (cmpxchgl(0, WAFLAG, &l->lock) == 0) - break; - sigprocmask(SIG_SETMASK, &tmp_oldsigmask, NULL); - } - oldsigmask = tmp_oldsigmask; -} - -static void -rlock_release(void *lock) -{ - Lock *l = (Lock *)lock; - - atomic_add_int(&l->lock, -RC_INCR); -} - -static void -wlock_release(void *lock) -{ - Lock *l = (Lock *)lock; - - atomic_add_int(&l->lock, -WAFLAG); - sigprocmask(SIG_SETMASK, &oldsigmask, NULL); -} - -/* * Code to determine at runtime whether the CPU supports the cmpxchg * instruction. This instruction allows us to use locks that are more * efficient, but it didn't exist on the 80386. @@ -242,35 +142,3 @@ return result; } -void -lockdflt_init(LockInfo *li) -{ - li->context = NULL; - li->context_destroy = NULL; - li->lock_create = lock_create; - li->lock_destroy = lock_destroy; - if (cpu_supports_cmpxchg()) { - /* Use fast locks that require an 80486 or later. */ - li->rlock_acquire = rlock_acquire; - li->wlock_acquire = wlock_acquire; - li->rlock_release = rlock_release; - li->wlock_release = wlock_release; - } else { - /* It's a cruddy old 80386. */ - li->rlock_acquire = li->wlock_acquire = lock80386_acquire; - li->rlock_release = li->wlock_release = lock80386_release; - } - /* - * Construct a mask to block all signals except traps which might - * conceivably be generated within the dynamic linker itself. - */ - sigfillset(&fullsigmask); - sigdelset(&fullsigmask, SIGILL); - sigdelset(&fullsigmask, SIGTRAP); - sigdelset(&fullsigmask, SIGABRT); - sigdelset(&fullsigmask, SIGEMT); - sigdelset(&fullsigmask, SIGFPE); - sigdelset(&fullsigmask, SIGBUS); - sigdelset(&fullsigmask, SIGSEGV); - sigdelset(&fullsigmask, SIGSYS); -} ==== //depot/projects/hammer/libexec/rtld-elf/i386/rtld_machdep.h#3 (text+ko) ==== @@ -23,12 +23,17 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/libexec/rtld-elf/i386/rtld_machdep.h,v 1.8 2002/11/18 22:08:49 tmm Exp $ + * $FreeBSD: src/libexec/rtld-elf/i386/rtld_machdep.h,v 1.9 2003/05/29 22:58:25 kan Exp $ */ #ifndef RTLD_MACHDEP_H #define RTLD_MACHDEP_H 1 +#include <sys/types.h> +#include <machine/atomic.h> + +#define CACHE_LINE_SIZE 32 + struct Struct_Obj_Entry; /* Return the address of the .dynamic section in the dynamic linker. */ @@ -53,25 +58,4 @@ #define call_initfini_pointer(obj, target) \ (((InitFunc)(target))()) -static inline void -atomic_decr_int(volatile int *p) -{ - __asm __volatile ("lock; decl %0" : "+m"(*p) : : "cc"); -} - -static inline void -atomic_incr_int(volatile int *p) -{ - __asm __volatile ("lock; incl %0" : "+m"(*p) : : "cc"); -} - -static inline void -atomic_add_int(volatile int *p, int val) -{ - __asm __volatile ("lock; addl %1, %0" - : "+m"(*p) - : "ri"(val) - : "cc"); -} - #endif ==== //depot/projects/hammer/libexec/rtld-elf/ia64/reloc.c#5 (text+ko) ==== @@ -22,7 +22,7 @@ * (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: src/libexec/rtld-elf/ia64/reloc.c,v 1.12 2003/03/19 21:38:27 arun Exp $ + * $FreeBSD: src/libexec/rtld-elf/ia64/reloc.c,v 1.13 2003/05/29 22:58:25 kan Exp $ */ /* @@ -122,8 +122,8 @@ } /* - * This assertion is necessary to guarantee function pointer - * uniqueness + * This assertion is necessary to guarantee function pointer + * uniqueness */ assert(fptrs != NULL); @@ -136,12 +136,12 @@ struct fptr **fptrs; size_t fbytes; - fptrs = obj->priv; + fptrs = obj->priv; if (fptrs == NULL) return; fbytes = obj->nchains * sizeof(struct fptr *); - if (mapped) + if (mapped) munmap(fptrs, fbytes); else free(fptrs); @@ -186,7 +186,7 @@ /* * We have to make sure that all @fptr references to * the same function are identical so that code can - * compare function pointers. + * compare function pointers. */ const Elf_Sym *def; const Obj_Entry *defobj; @@ -313,8 +313,8 @@ if (cache) munmap(cache, bytes); - /* - * Release temporarily mapped fptrs if relocating + /* + * Release temporarily mapped fptrs if relocating * rtld object itself. A new table will be created * in make_function_pointer using malloc when needed. */ ==== //depot/projects/hammer/libexec/rtld-elf/ia64/rtld_machdep.h#3 (text+ko) ==== @@ -23,12 +23,17 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/libexec/rtld-elf/ia64/rtld_machdep.h,v 1.3 2002/11/18 22:08:50 tmm Exp $ + * $FreeBSD: src/libexec/rtld-elf/ia64/rtld_machdep.h,v 1.4 2003/05/29 22:58:25 kan Exp $ */ #ifndef RTLD_MACHDEP_H #define RTLD_MACHDEP_H 1 +#include <sys/types.h> +#include <machine/atomic.h> + +#define CACHE_LINE_SIZE 128 + /* * Macros for cracking ia64 function pointers. */ @@ -50,10 +55,4 @@ void *make_function_pointer(const Elf_Sym *, const struct Struct_Obj_Entry *); void call_initfini_pointer(const struct Struct_Obj_Entry *, Elf_Addr); -/* Atomic operations. */ -int cmp0_and_store_int(volatile int *, int); -void atomic_add_int(volatile int *, int); -void atomic_incr_int(volatile int *); -void atomic_decr_int(volatile int *); - #endif ==== //depot/projects/hammer/libexec/rtld-elf/ia64/rtld_start.S#2 (text+ko) ==== @@ -1,4 +1,4 @@ -/* $FreeBSD: src/libexec/rtld-elf/ia64/rtld_start.S,v 1.2 2001/10/29 10:05:32 peter Exp $ */ +/* $FreeBSD: src/libexec/rtld-elf/ia64/rtld_start.S,v 1.3 2003/05/29 22:58:25 kan Exp $ */ /* From: NetBSD: rtld_start.S,v 1.1 1996/12/16 20:38:09 cgd Exp */ /* @@ -50,7 +50,7 @@ ;; sub out0=r14,r15 // out0 is image base address br.call.sptk.many rp=_rtld_reloc // fixup image - + add sp=-16,sp // 16 bytes for us, 16 for _rtld ;; mov out0=in0 @@ -60,7 +60,7 @@ br.call.sptk.many rp=_rtld // r8=_rtld(sp, &exit_proc, &obj_main) add r16=16,sp // address for exit proc - ;; + ;; ld8 r15=[r16] // read exit proc add sp=16,sp // readjust stack mov b7=r8 // address of real _start @@ -106,12 +106,12 @@ stf.spill [r17]=f10,32 stf.spill [r18]=f11,32 mov out0=r16 // Obj_Entry for caller - ;; + ;; } { .mmi stf.spill [r17]=f12,32 stf.spill [r18]=f13,32 shladd out1=r15,3,out1 // rela offset = 24 * index - ;; + ;; } { .mmb stf.spill [r17]=f14,32 stf.spill [r18]=f15,32 @@ -125,21 +125,21 @@ ld8 r1=[r8] // target gp mov ar.pfs=loc0 // clean up mov rp=loc1 -} { .mmi +} { .mmi ldf.fill f8=[r17],32 // restore float arguments ldf.fill f9=[r18],32 mov r8=loc2 // restore structure pointer - ;; + ;; } { .mmi ldf.fill f10=[r17],32 ldf.fill f11=[r18],32 mov r9=loc3 - ;; + ;; } { .mmi ldf.fill f12=[r17],32 ldf.fill f13=[r18],32 mov r10=loc4 - ;; + ;; } { .mmi ldf.fill f14=[r17],32 ldf.fill f15=[r18],32 @@ -157,69 +157,15 @@ } END(_rtld_bind_start) -/* - * int cmp0_and_store_int(volatile int *p, int newval); - * - * If an int holds 0, store newval into it; else do nothing. Returns - * the previous value. - */ -ENTRY(cmp0_and_store_int, 2) - mov ar.ccv=0 >>> TRUNCATED FOR MAIL (1000 lines) <<<
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200305300114.h4U1E6hR083673>