From 8dc97a5e7ca62b98aba02883724fd58a91f9a32e Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sun, 1 Mar 2015 20:23:52 +0100 Subject: Forward lockfile calls from libc to dynamically loaded libpthread * forward.c: (__libc_pthread_functions_init): Add variable (FORWARD2): Use __libc_pthread_functions_init instead of testing __libc_pthread_functions.ptr_##name value. (FORWARD_NORETURN): Add macro. (pthread_exit): Use FORWARD_NORETURN instead of FORWARD2. * libc_pthread_init.c (__libc_pthread_init): Set __libc_pthread_functions_init to 1. * pthread/pthread-functions.h (__pthread_once, __pthread_rwlock_rdlock, __pthread_rwlock_wrlock, __pthread_rwlock_unlock, __pthread_key_create, __pthread_getspecific, __pthread_setspecific, _cthreads_flockfile, _cthreads_funlockfile, _cthreads_ftrylockfile): Add prototypes. (pthread_functions): Add ptr_pthread_once, ptr_pthread_rwlock_rdlock, ptr_pthread_rwlock_wrlock, ptr_pthread_rwlock_unlock, ptr_pthread_key_create, ptr_pthread_getspecific, ptr_pthread_setspecific, ptr__IO_flockfile, ptr__IO_funlockfile, ptr__IO_ftrylockfile. (__libc_pthread_functions_init): Add variable declaration. (PTHFCT_CALL): Add macro. * pthread/pt-initialize.c (pthread_functions): Initialize ptr_pthread_once, ptr_pthread_rwlock_rdlock, ptr_pthread_rwlock_wrlock, pthread_rwlock_unlock, ptr_ptr_pthread_key_create, pthread_getspecific, ptr_pthread_setspecific, ptr_ptr__IO_flockfile, _IO_funlockfile, ptr__IO_ftrylockfile. * sysdeps/generic/pt-once.c (pthread_once): Rename to __pthread_once (pthread_once): Add strong alias. * sysdeps/generic/pt-rwlock-rdlock.c (pthread_rwlock_rdlock): Rename to __pthread_rwlock_rdlock (pthread_rwlock_rdlock): Add strong alias. * sysdeps/generic/pt-rwlock-wrlock.c (pthread_rwlock_wrlock): Rename to __pthread_rwlock_wrlock (pthread_rwlock_wrlock): Add strong alias. * sysdeps/generic/pt-rwlock-unlock.c (pthread_rwlock_unlock): Rename to __pthread_rwlock_unlock (pthread_rwlock_unlock): Add strong alias. * sysdeps/generic/pt-getspecific.c (pthread_getspecific): Rename to __pthread_getspecific (pthread_getspecific): Add strong alias. * sysdeps/generic/pt-setspecific.c (pthread_setspecific): Rename to __pthread_setspecific (pthread_setspecific): Add strong alias. * sysdeps/pthread/flockfile.c: Add file. * sysdeps/pthread/ftrylockfile.c: Add file. * sysdeps/pthread/funlockfile.c: Add file. --- forward.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'forward.c') diff --git a/forward.c b/forward.c index 9e940fb..994106e 100644 --- a/forward.c +++ b/forward.c @@ -25,16 +25,28 @@ /* Pointers to the libc functions. */ struct pthread_functions __libc_pthread_functions attribute_hidden; +int __libc_pthread_functions_init attribute_hidden; # define FORWARD2(name, rettype, decl, params, defaction) \ rettype \ name decl \ { \ - if (__libc_pthread_functions.ptr_##name == NULL) \ + if (!__libc_pthread_functions_init) \ defaction; \ \ - return __libc_pthread_functions.ptr_##name params; \ + return PTHFCT_CALL (ptr_##name, params); \ +} + +/* Same as FORWARD2, only without return. */ +# define FORWARD_NORETURN(name, rettype, decl, params, defaction) \ +rettype \ +name decl \ +{ \ + if (!__libc_pthread_functions_init) \ + defaction; \ + \ + PTHFCT_CALL (ptr_##name, params); \ } # define FORWARD(name, decl, params, defretval) \ @@ -94,7 +106,7 @@ FORWARD (pthread_equal, (pthread_t thread1, pthread_t thread2), /* Use an alias to avoid warning, as pthread_exit is declared noreturn. */ -FORWARD2 (pthread_exit, void, (void *retval), (retval), exit (EXIT_SUCCESS)) +FORWARD_NORETURN (pthread_exit, void, (void *retval), (retval), exit (EXIT_SUCCESS)) FORWARD (pthread_getschedparam, -- cgit v1.2.3