Date: Sat, 14 Feb 2015 11:47:40 +0000 (UTC) From: Konstantin Belousov <kib@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r278751 - in head/lib: libc/gen libc/include libc/sys libthr/thread Message-ID: <201502141147.t1EBle1t009369@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: kib Date: Sat Feb 14 11:47:40 2015 New Revision: 278751 URL: https://svnweb.freebsd.org/changeset/base/278751 Log: Properly interpose libc spinlocks, was missed in r276630. In particular, stdio locking was affected. Reported and tested by: "Matthew D. Fuller" <fullermd@over-yonder.net> Sponsored by: The FreeBSD Foundation MFC after: 3 days Modified: head/lib/libc/gen/_spinlock_stub.c head/lib/libc/include/libc_private.h head/lib/libc/sys/interposing_table.c head/lib/libthr/thread/thr_private.h head/lib/libthr/thread/thr_spinlock.c head/lib/libthr/thread/thr_syscalls.c Modified: head/lib/libc/gen/_spinlock_stub.c ============================================================================== --- head/lib/libc/gen/_spinlock_stub.c Sat Feb 14 10:56:03 2015 (r278750) +++ head/lib/libc/gen/_spinlock_stub.c Sat Feb 14 11:47:40 2015 (r278751) @@ -33,51 +33,48 @@ __FBSDID("$FreeBSD$"); #include <stdio.h> #include "spinlock.h" +#include "libc_private.h" long _atomic_lock_stub(volatile long *); void _spinlock_stub(spinlock_t *); void _spinunlock_stub(spinlock_t *); void _spinlock_debug_stub(spinlock_t *, char *, int); -/* - * Declare weak definitions in case the application is not linked - * with libpthread. - */ __weak_reference(_atomic_lock_stub, _atomic_lock); -__weak_reference(_spinlock_stub, _spinlock); -__weak_reference(_spinunlock_stub, _spinunlock); -__weak_reference(_spinlock_debug_stub, _spinlock_debug); - -/* - * This function is a stub for the _atomic_lock function in libpthread. - */ + long _atomic_lock_stub(volatile long *lck __unused) { return (0L); } +__weak_reference(_spinlock, _spinlock_debug); +#pragma weak _spinlock +void +_spinlock(spinlock_t *lck) +{ + + ((void (*)(spinlock_t *lck))__libc_interposing[INTERPOS_spinlock]) + (lck); -/* - * This function is a stub for the spinlock function in libpthread. - */ +} + +#pragma weak _spinlock void -_spinlock_stub(spinlock_t *lck __unused) +_spinunlock(spinlock_t *lck) { + + ((void (*)(spinlock_t *lck))__libc_interposing[INTERPOS_spinunlock]) + (lck); + } -/* - * This function is a stub for the spinunlock function in libpthread. - */ void -_spinunlock_stub(spinlock_t *lck __unused) +__libc_spinlock_stub(spinlock_t *lck __unused) { } -/* - * This function is a stub for the debug spinlock function in libpthread. - */ void -_spinlock_debug_stub(spinlock_t *lck __unused, char *fname __unused, int lineno __unused) +__libc_spinunlock_stub(spinlock_t *lck __unused) { } Modified: head/lib/libc/include/libc_private.h ============================================================================== --- head/lib/libc/include/libc_private.h Sat Feb 14 10:56:03 2015 (r278750) +++ head/lib/libc/include/libc_private.h Sat Feb 14 11:47:40 2015 (r278751) @@ -95,6 +95,9 @@ do { \ _SPINUNLOCK(&__stdio_thread_lock); \ } while (0) +void __libc_spinlock_stub(struct _spinlock *); +void __libc_spinunlock_stub(struct _spinlock *); + /* * Indexes into the pthread jump table. * @@ -216,6 +219,8 @@ enum { INTERPOS_write, INTERPOS_writev, INTERPOS__pthread_mutex_init_calloc_cb, + INTERPOS_spinlock, + INTERPOS_spinunlock, INTERPOS_MAX }; Modified: head/lib/libc/sys/interposing_table.c ============================================================================== --- head/lib/libc/sys/interposing_table.c Sat Feb 14 10:56:03 2015 (r278750) +++ head/lib/libc/sys/interposing_table.c Sat Feb 14 11:47:40 2015 (r278751) @@ -73,6 +73,8 @@ interpos_func_t __libc_interposing[INTER SLOT(write, __sys_write), SLOT(writev, __sys_writev), SLOT(_pthread_mutex_init_calloc_cb, _pthread_mutex_init_calloc_cb_stub), + SLOT(spinlock, __libc_spinlock_stub), + SLOT(spinunlock, __libc_spinunlock_stub), }; #undef SLOT Modified: head/lib/libthr/thread/thr_private.h ============================================================================== --- head/lib/libthr/thread/thr_private.h Sat Feb 14 10:56:03 2015 (r278750) +++ head/lib/libthr/thread/thr_private.h Sat Feb 14 11:47:40 2015 (r278751) @@ -928,6 +928,10 @@ int __thr_sigwait(const sigset_t *set, i int __thr_sigwaitinfo(const sigset_t *set, siginfo_t *info); int __thr_swapcontext(ucontext_t *oucp, const ucontext_t *ucp); +struct _spinlock; +void __thr_spinunlock(struct _spinlock *lck); +void __thr_spinlock(struct _spinlock *lck); + struct tcb *_tcb_ctor(struct pthread *, int); void _tcb_dtor(struct tcb *); Modified: head/lib/libthr/thread/thr_spinlock.c ============================================================================== --- head/lib/libthr/thread/thr_spinlock.c Sat Feb 14 10:56:03 2015 (r278750) +++ head/lib/libthr/thread/thr_spinlock.c Sat Feb 14 11:47:40 2015 (r278751) @@ -61,7 +61,7 @@ static void init_spinlock(spinlock_t *lc */ void -_spinunlock(spinlock_t *lck) +__thr_spinunlock(spinlock_t *lck) { struct spinlock_extra *_extra; @@ -70,7 +70,7 @@ _spinunlock(spinlock_t *lck) } void -_spinlock(spinlock_t *lck) +__thr_spinlock(spinlock_t *lck) { struct spinlock_extra *_extra; @@ -84,12 +84,6 @@ _spinlock(spinlock_t *lck) THR_UMUTEX_LOCK(_get_curthread(), &_extra->lock); } -void -_spinlock_debug(spinlock_t *lck, char *fname __unused, int lineno __unused) -{ - _spinlock(lck); -} - static void init_spinlock(spinlock_t *lck) { Modified: head/lib/libthr/thread/thr_syscalls.c ============================================================================== --- head/lib/libthr/thread/thr_syscalls.c Sat Feb 14 10:56:03 2015 (r278750) +++ head/lib/libthr/thread/thr_syscalls.c Sat Feb 14 11:47:40 2015 (r278751) @@ -597,6 +597,8 @@ __thr_interpose_libc(void) SLOT(wait4); SLOT(write); SLOT(writev); + SLOT(spinlock); + SLOT(spinunlock); #undef SLOT *(__libc_interposing_slot( INTERPOS__pthread_mutex_init_calloc_cb)) =
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201502141147.t1EBle1t009369>