From f881f17267506f3ced17259a066a4d95bffb57f0 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sun, 24 Sep 2017 23:09:59 +0200 Subject: Fix symbols exposed in linkspace Libc uses some thread functions, but should not expose the corresponding symbols, so use aliases. * Versions (__cthread_detach, __cthread_fork, __cthread_keycreate, __cthread_getspecific, __cthread_setspecific, __pthread_getattr_np, __pthread_attr_getstack): Add symbols * pthread/cthreads-compat.c (cthread_t, cthread_fn_t, cthread_key_t): Do not define. (cthread_detach): Rename to __cthread_detach. (cthread_detach): Define as weak alias to __cthread_detach. (cthread_fork, cthread_keycreate, cthread_getspecific, cthread_setspecific): Likewise. * pthread/pt-getattr.c (pthread_getattr_np): Likewise. * sysdeps/generic/pt-attr-getstack.c (pthread_attr_getstack): Likewise. * sysdeps/pthread/pthread.h (__cthread_t, __cthread_key_t, __cthread_fn_t, __cthread_fork, __cthread_detach, __cthread_keycreate, __cthread_getspecific, __cthread_setspecific, __pthread_getattr_np, __pthread_attr_getstack): Declare. --- pthread/cthreads-compat.c | 25 +++++++++++++------------ pthread/pt-getattr.c | 3 ++- 2 files changed, 15 insertions(+), 13 deletions(-) (limited to 'pthread') diff --git a/pthread/cthreads-compat.c b/pthread/cthreads-compat.c index 1a0971b..cd845ed 100644 --- a/pthread/cthreads-compat.c +++ b/pthread/cthreads-compat.c @@ -20,23 +20,20 @@ #include #include -typedef void *cthread_t; -typedef void *(*cthread_fn_t) (void *arg); -typedef int cthread_key_t; - -#define CTHREAD_KEY_INVALID (cthread_key_t) -1 +#define CTHREAD_KEY_INVALID (__cthread_key_t) -1 void -cthread_detach (cthread_t thread) +__cthread_detach (__cthread_t thread) { int err; err = pthread_detach ((pthread_t) thread); assert_perror (err); } +weak_alias (__cthread_detach, cthread_detach) -cthread_t -cthread_fork (cthread_fn_t func, void *arg) +__cthread_t +__cthread_fork (__cthread_fn_t func, void *arg) { pthread_t thread; int err; @@ -44,11 +41,12 @@ cthread_fork (cthread_fn_t func, void *arg) err = pthread_create (&thread, NULL, func, arg); assert_perror (err); - return (cthread_t) thread; + return (__cthread_t) thread; } +weak_alias (__cthread_fork, cthread_fork) int -cthread_keycreate (cthread_key_t *key) +__cthread_keycreate (__cthread_key_t *key) { error_t err; @@ -62,16 +60,18 @@ cthread_keycreate (cthread_key_t *key) return err; } +weak_alias (__cthread_keycreate, cthread_keycreate) int -cthread_getspecific (cthread_key_t key, void **val) +__cthread_getspecific (__cthread_key_t key, void **val) { *val = pthread_getspecific (key); return 0; } +weak_alias (__cthread_getspecific, cthread_getspecific) int -cthread_setspecific (cthread_key_t key, void *val) +__cthread_setspecific (__cthread_key_t key, void *val) { error_t err; @@ -84,6 +84,7 @@ cthread_setspecific (cthread_key_t key, void *val) return err; } +weak_alias (__cthread_setspecific, cthread_setspecific) void __mutex_lock_solid (void *lock) diff --git a/pthread/pt-getattr.c b/pthread/pt-getattr.c index 574420a..0b86c66 100644 --- a/pthread/pt-getattr.c +++ b/pthread/pt-getattr.c @@ -27,7 +27,7 @@ already running thread THREAD. It shall be called on an uninitialized ATTR and destroyed with pthread_attr_destroy when no longer needed. */ int -pthread_getattr_np (pthread_t thread, pthread_attr_t *attr) +__pthread_getattr_np (pthread_t thread, pthread_attr_t *attr) { struct __pthread *pthread; @@ -49,3 +49,4 @@ pthread_getattr_np (pthread_t thread, pthread_attr_t *attr) return 0; } +weak_alias (__pthread_getattr_np, pthread_getattr_np) -- cgit v1.2.3 From 8f03a364f803ad878ea3ab226fd2955ed4565495 Mon Sep 17 00:00:00 2001 From: Agustina Arzille Date: Tue, 18 Oct 2016 00:20:45 +0200 Subject: Make pthread_spinlock use gsync * pthread/pt-spin-inlines.c (pthread_spin_lock): Define weak alias for __pthread_spin_lock. * sysdeps/mach/bits/spin-lock-inline.h: Include instead of . (__pthread_spin_trylock, __pthread_spin_unlock): Use __spin_lock_t type instead of __lock. (__pthread_spin_lock): Define as inline only, use __spin_lock and __spin_lock_t type. * sysdeps/mach/bits/spin-lock.h: Do not include (__pthread_spinlock_t): Use volatile int instead of __spin_lock_t. (__PTHREAD_SPIN_LOCK_INITIALIZER): Define to 0. * sysdeps/mach/i386/bits/spin-lock-inline.h: Remove file. * sysdeps/mach/i386/bits/spin-lock.h: Remove file. * sysdeps/posix/pt-spin.c (pthread_spin_lock, __pthread_spin_lock): Remove weak aliases, provided by pt-spin-inlines.c --- pthread/pt-spin-inlines.c | 5 +- sysdeps/mach/bits/spin-lock-inline.h | 14 ++--- sysdeps/mach/bits/spin-lock.h | 7 +-- sysdeps/mach/i386/bits/spin-lock-inline.h | 98 ------------------------------- sysdeps/mach/i386/bits/spin-lock.h | 39 ------------ sysdeps/mach/pt-spin.c | 8 +-- sysdeps/posix/pt-spin.c | 3 - 7 files changed, 12 insertions(+), 162 deletions(-) delete mode 100644 sysdeps/mach/i386/bits/spin-lock-inline.h delete mode 100644 sysdeps/mach/i386/bits/spin-lock.h (limited to 'pthread') diff --git a/pthread/pt-spin-inlines.c b/pthread/pt-spin-inlines.c index cfb21dd..97afb4d 100644 --- a/pthread/pt-spin-inlines.c +++ b/pthread/pt-spin-inlines.c @@ -25,10 +25,9 @@ #include -/* Weak aliases for the spin lock functions. Note that - pthread_spin_lock is left out deliberately. We already provide an - implementation for it in pt-spin.c. */ +/* Weak aliases for the spin lock functions. */ weak_alias (__pthread_spin_destroy, pthread_spin_destroy); weak_alias (__pthread_spin_init, pthread_spin_init); weak_alias (__pthread_spin_trylock, pthread_spin_trylock); +weak_alias (__pthread_spin_lock, pthread_spin_lock); weak_alias (__pthread_spin_unlock, pthread_spin_unlock); diff --git a/sysdeps/mach/bits/spin-lock-inline.h b/sysdeps/mach/bits/spin-lock-inline.h index f9f7c29..98e4b3b 100644 --- a/sysdeps/mach/bits/spin-lock-inline.h +++ b/sysdeps/mach/bits/spin-lock-inline.h @@ -22,7 +22,7 @@ #include #include -#include /* This does all the work. */ +#include /* This does all the work. */ __BEGIN_DECLS @@ -60,17 +60,15 @@ __PT_SPIN_INLINE int __pthread_spin_trylock (__pthread_spinlock_t *__lock); __PT_SPIN_INLINE int __pthread_spin_trylock (__pthread_spinlock_t *__lock) { - return __spin_try_lock (__lock) ? 0 : __EBUSY; + return __spin_try_lock ((__spin_lock_t *) __lock) ? 0 : __EBUSY; } -__extern_inline int __pthread_spin_lock (__pthread_spinlock_t *__lock); -extern int _pthread_spin_lock (__pthread_spinlock_t *__lock); +__PT_SPIN_INLINE int __pthread_spin_lock (__pthread_spinlock_t *__lock); -__extern_inline int +__PT_SPIN_INLINE int __pthread_spin_lock (__pthread_spinlock_t *__lock) { - if (__pthread_spin_trylock (__lock)) - return _pthread_spin_lock (__lock); + __spin_lock ((__spin_lock_t *) __lock); return 0; } @@ -79,7 +77,7 @@ __PT_SPIN_INLINE int __pthread_spin_unlock (__pthread_spinlock_t *__lock); __PT_SPIN_INLINE int __pthread_spin_unlock (__pthread_spinlock_t *__lock) { - __spin_unlock (__lock); + __spin_unlock ((__spin_lock_t *) __lock); return 0; } diff --git a/sysdeps/mach/bits/spin-lock.h b/sysdeps/mach/bits/spin-lock.h index 537dac9..7574b37 100644 --- a/sysdeps/mach/bits/spin-lock.h +++ b/sysdeps/mach/bits/spin-lock.h @@ -21,17 +21,14 @@ #define _BITS_SPIN_LOCK_H 1 #include -#include /* This does all the work. */ __BEGIN_DECLS /* The type of a spin lock object. */ -typedef __spin_lock_t __pthread_spinlock_t; +typedef volatile int __pthread_spinlock_t; /* Initializer for a spin lock object. */ -#ifndef __PTHREAD_SPIN_LOCK_INITIALIZER -#error __PTHREAD_SPIN_LOCK_INITIALIZER undefined: should be defined by . -#endif +#define __PTHREAD_SPIN_LOCK_INITIALIZER 0 __END_DECLS diff --git a/sysdeps/mach/i386/bits/spin-lock-inline.h b/sysdeps/mach/i386/bits/spin-lock-inline.h deleted file mode 100644 index e5ed3de..0000000 --- a/sysdeps/mach/i386/bits/spin-lock-inline.h +++ /dev/null @@ -1,98 +0,0 @@ -/* Machine-specific definitions for spin locks. i386 version. - Copyright (C) 2000, 2005, 2008, 2009 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -/* - * Never include this file directly; use or instead. - */ - -#ifndef _BITS_SPIN_LOCK_INLINE_H -#define _BITS_SPIN_LOCK_INLINE_H 1 - -#include -#include - -__BEGIN_DECLS - -#if defined __USE_EXTERN_INLINES || defined _FORCE_INLINES - -# ifndef __EBUSY -# include -# define __EBUSY EBUSY -# endif - -# ifndef __PT_SPIN_INLINE -# define __PT_SPIN_INLINE __extern_inline -# endif - -__PT_SPIN_INLINE int __pthread_spin_destroy (__pthread_spinlock_t *__lock); - -__PT_SPIN_INLINE int -__pthread_spin_destroy (__pthread_spinlock_t *__lock) -{ - return 0; -} - -__PT_SPIN_INLINE int __pthread_spin_init (__pthread_spinlock_t *__lock, - int __pshared); - -__PT_SPIN_INLINE int -__pthread_spin_init (__pthread_spinlock_t *__lock, int __pshared) -{ - *__lock = __PTHREAD_SPIN_LOCK_INITIALIZER; - return 0; -} - -__PT_SPIN_INLINE int __pthread_spin_trylock (__pthread_spinlock_t *__lock); - -__PT_SPIN_INLINE int -__pthread_spin_trylock (__pthread_spinlock_t *__lock) -{ - int __locked; - __asm__ __volatile ("xchgl %0, %1" - : "=&r" (__locked), "=m" (*__lock) : "0" (1) : "memory"); - return __locked ? __EBUSY : 0; -} - -__extern_inline int __pthread_spin_lock (__pthread_spinlock_t *__lock); -extern int _pthread_spin_lock (__pthread_spinlock_t *__lock); - -__extern_inline int -__pthread_spin_lock (__pthread_spinlock_t *__lock) -{ - if (__pthread_spin_trylock (__lock)) - return _pthread_spin_lock (__lock); - return 0; -} - -__PT_SPIN_INLINE int __pthread_spin_unlock (__pthread_spinlock_t *__lock); - -__PT_SPIN_INLINE int -__pthread_spin_unlock (__pthread_spinlock_t *__lock) -{ - int __unlocked; - __asm__ __volatile ("xchgl %0, %1" - : "=&r" (__unlocked), "=m" (*__lock) : "0" (0) : "memory"); - return 0; -} - -#endif /* Use extern inlines or force inlines. */ - -__END_DECLS - -#endif /* bits/spin-lock.h */ diff --git a/sysdeps/mach/i386/bits/spin-lock.h b/sysdeps/mach/i386/bits/spin-lock.h deleted file mode 100644 index 5ae81e1..0000000 --- a/sysdeps/mach/i386/bits/spin-lock.h +++ /dev/null @@ -1,39 +0,0 @@ -/* Machine-specific definitions for spin locks. i386 version. - Copyright (C) 2000, 2005, 2008, 2009 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -/* - * Never include this file directly; use or instead. - */ - -#ifndef _BITS_SPIN_LOCK_H -#define _BITS_SPIN_LOCK_H 1 - -#include - -__BEGIN_DECLS - -/* The type of a spin lock object. */ -typedef __volatile int __pthread_spinlock_t; - -/* Initializer for a spin lock object. */ -# define __PTHREAD_SPIN_LOCK_INITIALIZER ((__pthread_spinlock_t) 0) - -__END_DECLS - -#endif /* bits/spin-lock.h */ diff --git a/sysdeps/mach/pt-spin.c b/sysdeps/mach/pt-spin.c index d9a2a32..0cf1c49 100644 --- a/sysdeps/mach/pt-spin.c +++ b/sysdeps/mach/pt-spin.c @@ -17,20 +17,16 @@ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include #include /* In glibc. */ -extern void __spin_lock_solid (__pthread_spinlock_t *lock); +extern void __spin_lock_solid (__spin_lock_t *lock); /* Lock the spin lock object LOCK. If the lock is held by another thread spin until it becomes available. */ int -_pthread_spin_lock (__pthread_spinlock_t *lock) +_pthread_spin_lock (__spin_lock_t *lock) { __spin_lock_solid (lock); return 0; } - -weak_alias (_pthread_spin_lock, pthread_spin_lock); -weak_alias (_pthread_spin_lock, __pthread_spin_lock); diff --git a/sysdeps/posix/pt-spin.c b/sysdeps/posix/pt-spin.c index cb809c6..07f8936 100644 --- a/sysdeps/posix/pt-spin.c +++ b/sysdeps/posix/pt-spin.c @@ -49,6 +49,3 @@ _pthread_spin_lock (__pthread_spinlock_t *lock) __sched_yield (); } } - -weak_alias (_pthread_spin_lock, pthread_spin_lock); -weak_alias (_pthread_spin_lock, __pthread_spin_lock); -- cgit v1.2.3