forward.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /* Copyright (C) 2002-2019 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #include <dlfcn.h>
  16. #include <pthreadP.h>
  17. #include <signal.h>
  18. #include <stdlib.h>
  19. #include <shlib-compat.h>
  20. #include <atomic.h>
  21. #include <safe-fatal.h>
  22. /* Pointers to the libc functions. */
  23. struct pthread_functions __libc_pthread_functions attribute_hidden;
  24. int __libc_pthread_functions_init attribute_hidden;
  25. #define FORWARD2(name, rettype, decl, params, defaction) \
  26. rettype \
  27. name decl \
  28. { \
  29. if (!__libc_pthread_functions_init) \
  30. defaction; \
  31. \
  32. return PTHFCT_CALL (ptr_##name, params); \
  33. }
  34. /* Same as FORWARD2, only without return. */
  35. #define FORWARD_NORETURN(name, rettype, decl, params, defaction) \
  36. rettype \
  37. name decl \
  38. { \
  39. if (!__libc_pthread_functions_init) \
  40. defaction; \
  41. \
  42. PTHFCT_CALL (ptr_##name, params); \
  43. }
  44. #define FORWARD(name, decl, params, defretval) \
  45. FORWARD2 (name, int, decl, params, return defretval)
  46. FORWARD (pthread_attr_destroy, (pthread_attr_t *attr), (attr), 0)
  47. #if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_1)
  48. FORWARD (__pthread_attr_init_2_0, (pthread_attr_t *attr), (attr), 0)
  49. compat_symbol (libc, __pthread_attr_init_2_0, pthread_attr_init, GLIBC_2_0);
  50. #endif
  51. FORWARD (__pthread_attr_init_2_1, (pthread_attr_t *attr), (attr), 0)
  52. versioned_symbol (libc, __pthread_attr_init_2_1, pthread_attr_init, GLIBC_2_1);
  53. FORWARD (pthread_attr_getdetachstate,
  54. (const pthread_attr_t *attr, int *detachstate), (attr, detachstate),
  55. 0)
  56. FORWARD (pthread_attr_setdetachstate, (pthread_attr_t *attr, int detachstate),
  57. (attr, detachstate), 0)
  58. FORWARD (pthread_attr_getinheritsched,
  59. (const pthread_attr_t *attr, int *inherit), (attr, inherit), 0)
  60. FORWARD (pthread_attr_setinheritsched, (pthread_attr_t *attr, int inherit),
  61. (attr, inherit), 0)
  62. FORWARD (pthread_attr_getschedparam,
  63. (const pthread_attr_t *attr, struct sched_param *param),
  64. (attr, param), 0)
  65. FORWARD (pthread_attr_setschedparam,
  66. (pthread_attr_t *attr, const struct sched_param *param),
  67. (attr, param), 0)
  68. FORWARD (pthread_attr_getschedpolicy,
  69. (const pthread_attr_t *attr, int *policy), (attr, policy), 0)
  70. FORWARD (pthread_attr_setschedpolicy, (pthread_attr_t *attr, int policy),
  71. (attr, policy), 0)
  72. FORWARD (pthread_attr_getscope,
  73. (const pthread_attr_t *attr, int *scope), (attr, scope), 0)
  74. FORWARD (pthread_attr_setscope, (pthread_attr_t *attr, int scope),
  75. (attr, scope), 0)
  76. FORWARD (pthread_condattr_destroy, (pthread_condattr_t *attr), (attr), 0)
  77. FORWARD (pthread_condattr_init, (pthread_condattr_t *attr), (attr), 0)
  78. #if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_3_2)
  79. FORWARD2 (__pthread_cond_broadcast_2_0, int attribute_compat_text_section,
  80. (pthread_cond_2_0_t *cond), (cond), return 0)
  81. compat_symbol (libc, __pthread_cond_broadcast_2_0, pthread_cond_broadcast,
  82. GLIBC_2_0);
  83. #endif
  84. FORWARD (__pthread_cond_broadcast, (pthread_cond_t *cond), (cond), 0)
  85. versioned_symbol (libc, __pthread_cond_broadcast, pthread_cond_broadcast,
  86. GLIBC_2_3_2);
  87. #if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_3_2)
  88. FORWARD2 (__pthread_cond_destroy_2_0, int attribute_compat_text_section,
  89. (pthread_cond_2_0_t *cond), (cond), return 0)
  90. compat_symbol (libc, __pthread_cond_destroy_2_0, pthread_cond_destroy,
  91. GLIBC_2_0);
  92. #endif
  93. FORWARD (__pthread_cond_destroy, (pthread_cond_t *cond), (cond), 0)
  94. versioned_symbol (libc, __pthread_cond_destroy, pthread_cond_destroy,
  95. GLIBC_2_3_2);
  96. #if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_3_2)
  97. FORWARD2 (__pthread_cond_init_2_0, int attribute_compat_text_section,
  98. (pthread_cond_2_0_t *cond, const pthread_condattr_t *cond_attr),
  99. (cond, cond_attr), return 0)
  100. compat_symbol (libc, __pthread_cond_init_2_0, pthread_cond_init, GLIBC_2_0);
  101. #endif
  102. FORWARD (__pthread_cond_init,
  103. (pthread_cond_t *cond, const pthread_condattr_t *cond_attr),
  104. (cond, cond_attr), 0)
  105. versioned_symbol (libc, __pthread_cond_init, pthread_cond_init, GLIBC_2_3_2);
  106. #if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_3_2)
  107. FORWARD2 (__pthread_cond_signal_2_0, int attribute_compat_text_section,
  108. (pthread_cond_2_0_t *cond), (cond), return 0)
  109. compat_symbol (libc, __pthread_cond_signal_2_0, pthread_cond_signal,
  110. GLIBC_2_0);
  111. #endif
  112. FORWARD (__pthread_cond_signal, (pthread_cond_t *cond), (cond), 0)
  113. versioned_symbol (libc, __pthread_cond_signal, pthread_cond_signal,
  114. GLIBC_2_3_2);
  115. #if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_3_2)
  116. FORWARD2 (__pthread_cond_wait_2_0, int attribute_compat_text_section,
  117. (pthread_cond_2_0_t *cond, pthread_mutex_t *mutex), (cond, mutex),
  118. return 0)
  119. compat_symbol (libc, __pthread_cond_wait_2_0, pthread_cond_wait,
  120. GLIBC_2_0);
  121. #endif
  122. FORWARD (__pthread_cond_wait, (pthread_cond_t *cond, pthread_mutex_t *mutex),
  123. (cond, mutex), 0)
  124. versioned_symbol (libc, __pthread_cond_wait, pthread_cond_wait,
  125. GLIBC_2_3_2);
  126. #if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_3_2)
  127. FORWARD2 (__pthread_cond_timedwait_2_0, int attribute_compat_text_section,
  128. (pthread_cond_2_0_t *cond, pthread_mutex_t *mutex,
  129. const struct timespec *abstime), (cond, mutex, abstime),
  130. return 0)
  131. compat_symbol (libc, __pthread_cond_timedwait_2_0, pthread_cond_timedwait,
  132. GLIBC_2_0);
  133. #endif
  134. FORWARD (__pthread_cond_timedwait,
  135. (pthread_cond_t *cond, pthread_mutex_t *mutex,
  136. const struct timespec *abstime), (cond, mutex, abstime), 0)
  137. versioned_symbol (libc, __pthread_cond_timedwait, pthread_cond_timedwait,
  138. GLIBC_2_3_2);
  139. FORWARD (pthread_equal, (pthread_t thread1, pthread_t thread2),
  140. (thread1, thread2), 1)
  141. FORWARD_NORETURN (__pthread_exit, void, (void *retval), (retval),
  142. exit (EXIT_SUCCESS))
  143. strong_alias (__pthread_exit, pthread_exit);
  144. FORWARD (pthread_getschedparam,
  145. (pthread_t target_thread, int *policy, struct sched_param *param),
  146. (target_thread, policy, param), 0)
  147. FORWARD (pthread_setschedparam,
  148. (pthread_t target_thread, int policy,
  149. const struct sched_param *param), (target_thread, policy, param), 0)
  150. FORWARD (pthread_mutex_destroy, (pthread_mutex_t *mutex), (mutex), 0)
  151. FORWARD (pthread_mutex_init,
  152. (pthread_mutex_t *mutex, const pthread_mutexattr_t *mutexattr),
  153. (mutex, mutexattr), 0)
  154. FORWARD (pthread_mutex_lock, (pthread_mutex_t *mutex), (mutex), 0)
  155. FORWARD (pthread_mutex_unlock, (pthread_mutex_t *mutex), (mutex), 0)
  156. FORWARD (__pthread_setcancelstate, (int state, int *oldstate),
  157. (state, oldstate), 0)
  158. strong_alias (__pthread_setcancelstate, pthread_setcancelstate)
  159. FORWARD (pthread_setcanceltype, (int type, int *oldtype), (type, oldtype), 0)
  160. FORWARD_NORETURN (__pthread_unwind,
  161. void attribute_hidden __attribute ((noreturn))
  162. __cleanup_fct_attribute attribute_compat_text_section,
  163. (__pthread_unwind_buf_t *buf), (buf),
  164. __safe_fatal ())