forward.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /* Copyright (C) 2002, 2003, 2004 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, write to the Free
  14. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA. */
  16. #include <dlfcn.h>
  17. #include <pthreadP.h>
  18. #include <signal.h>
  19. #include <stdlib.h>
  20. #include <shlib-compat.h>
  21. #include <atomic.h>
  22. #include <sysdep.h>
  23. /* Pointers to the libc functions. */
  24. struct pthread_functions __libc_pthread_functions attribute_hidden;
  25. #define FORWARD2(name, rettype, decl, params, defaction) \
  26. rettype \
  27. name decl \
  28. { \
  29. if (__libc_pthread_functions.ptr_##name == NULL) \
  30. defaction; \
  31. \
  32. return __libc_pthread_functions.ptr_##name params; \
  33. }
  34. #define FORWARD(name, decl, params, defretval) \
  35. FORWARD2 (name, int, decl, params, return defretval)
  36. FORWARD (pthread_attr_destroy, (pthread_attr_t *attr), (attr), 0)
  37. #if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_1)
  38. FORWARD (__pthread_attr_init_2_0, (pthread_attr_t *attr), (attr), 0)
  39. compat_symbol (libc, __pthread_attr_init_2_0, pthread_attr_init, GLIBC_2_0);
  40. #endif
  41. FORWARD (__pthread_attr_init_2_1, (pthread_attr_t *attr), (attr), 0)
  42. versioned_symbol (libc, __pthread_attr_init_2_1, pthread_attr_init, GLIBC_2_1);
  43. FORWARD (pthread_attr_getdetachstate,
  44. (const pthread_attr_t *attr, int *detachstate), (attr, detachstate),
  45. 0)
  46. FORWARD (pthread_attr_setdetachstate, (pthread_attr_t *attr, int detachstate),
  47. (attr, detachstate), 0)
  48. FORWARD (pthread_attr_getinheritsched,
  49. (const pthread_attr_t *attr, int *inherit), (attr, inherit), 0)
  50. FORWARD (pthread_attr_setinheritsched, (pthread_attr_t *attr, int inherit),
  51. (attr, inherit), 0)
  52. FORWARD (pthread_attr_getschedparam,
  53. (const pthread_attr_t *attr, struct sched_param *param),
  54. (attr, param), 0)
  55. FORWARD (pthread_attr_setschedparam,
  56. (pthread_attr_t *attr, const struct sched_param *param),
  57. (attr, param), 0)
  58. FORWARD (pthread_attr_getschedpolicy,
  59. (const pthread_attr_t *attr, int *policy), (attr, policy), 0)
  60. FORWARD (pthread_attr_setschedpolicy, (pthread_attr_t *attr, int policy),
  61. (attr, policy), 0)
  62. FORWARD (pthread_attr_getscope,
  63. (const pthread_attr_t *attr, int *scope), (attr, scope), 0)
  64. FORWARD (pthread_attr_setscope, (pthread_attr_t *attr, int scope),
  65. (attr, scope), 0)
  66. FORWARD (pthread_condattr_destroy, (pthread_condattr_t *attr), (attr), 0)
  67. FORWARD (pthread_condattr_init, (pthread_condattr_t *attr), (attr), 0)
  68. #if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_3_2)
  69. FORWARD2 (__pthread_cond_broadcast_2_0, int attribute_compat_text_section,
  70. (pthread_cond_2_0_t *cond), (cond), return 0)
  71. compat_symbol (libc, __pthread_cond_broadcast_2_0, pthread_cond_broadcast,
  72. GLIBC_2_0);
  73. #endif
  74. FORWARD (__pthread_cond_broadcast, (pthread_cond_t *cond), (cond), 0)
  75. versioned_symbol (libc, __pthread_cond_broadcast, pthread_cond_broadcast,
  76. GLIBC_2_3_2);
  77. #if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_3_2)
  78. FORWARD2 (__pthread_cond_destroy_2_0, int attribute_compat_text_section,
  79. (pthread_cond_2_0_t *cond), (cond), return 0)
  80. compat_symbol (libc, __pthread_cond_destroy_2_0, pthread_cond_destroy,
  81. GLIBC_2_0);
  82. #endif
  83. FORWARD (__pthread_cond_destroy, (pthread_cond_t *cond), (cond), 0)
  84. versioned_symbol (libc, __pthread_cond_destroy, pthread_cond_destroy,
  85. GLIBC_2_3_2);
  86. #if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_3_2)
  87. FORWARD2 (__pthread_cond_init_2_0, int attribute_compat_text_section,
  88. (pthread_cond_2_0_t *cond, const pthread_condattr_t *cond_attr),
  89. (cond, cond_attr), return 0)
  90. compat_symbol (libc, __pthread_cond_init_2_0, pthread_cond_init, GLIBC_2_0);
  91. #endif
  92. FORWARD (__pthread_cond_init,
  93. (pthread_cond_t *cond, const pthread_condattr_t *cond_attr),
  94. (cond, cond_attr), 0)
  95. versioned_symbol (libc, __pthread_cond_init, pthread_cond_init, GLIBC_2_3_2);
  96. #if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_3_2)
  97. FORWARD2 (__pthread_cond_signal_2_0, int attribute_compat_text_section,
  98. (pthread_cond_2_0_t *cond), (cond), return 0)
  99. compat_symbol (libc, __pthread_cond_signal_2_0, pthread_cond_signal,
  100. GLIBC_2_0);
  101. #endif
  102. FORWARD (__pthread_cond_signal, (pthread_cond_t *cond), (cond), 0)
  103. versioned_symbol (libc, __pthread_cond_signal, pthread_cond_signal,
  104. GLIBC_2_3_2);
  105. #if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_3_2)
  106. FORWARD2 (__pthread_cond_wait_2_0, int attribute_compat_text_section,
  107. (pthread_cond_2_0_t *cond, pthread_mutex_t *mutex), (cond, mutex),
  108. return 0)
  109. compat_symbol (libc, __pthread_cond_wait_2_0, pthread_cond_wait,
  110. GLIBC_2_0);
  111. #endif
  112. FORWARD (__pthread_cond_wait, (pthread_cond_t *cond, pthread_mutex_t *mutex),
  113. (cond, mutex), 0)
  114. versioned_symbol (libc, __pthread_cond_wait, pthread_cond_wait,
  115. GLIBC_2_3_2);
  116. #if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_3_2)
  117. FORWARD2 (__pthread_cond_timedwait_2_0, int attribute_compat_text_section,
  118. (pthread_cond_2_0_t *cond, pthread_mutex_t *mutex,
  119. const struct timespec *abstime), (cond, mutex, abstime),
  120. return 0)
  121. compat_symbol (libc, __pthread_cond_timedwait_2_0, pthread_cond_timedwait,
  122. GLIBC_2_0);
  123. #endif
  124. FORWARD (__pthread_cond_timedwait,
  125. (pthread_cond_t *cond, pthread_mutex_t *mutex,
  126. const struct timespec *abstime), (cond, mutex, abstime), 0)
  127. versioned_symbol (libc, __pthread_cond_timedwait, pthread_cond_timedwait,
  128. GLIBC_2_3_2);
  129. FORWARD (pthread_equal, (pthread_t thread1, pthread_t thread2),
  130. (thread1, thread2), 1)
  131. /* Use an alias to avoid warning, as pthread_exit is declared noreturn. */
  132. FORWARD2 (__pthread_exit, void, (void *retval), (retval), exit (EXIT_SUCCESS))
  133. strong_alias (__pthread_exit, pthread_exit);
  134. FORWARD (pthread_getschedparam,
  135. (pthread_t target_thread, int *policy, struct sched_param *param),
  136. (target_thread, policy, param), 0)
  137. FORWARD (pthread_setschedparam,
  138. (pthread_t target_thread, int policy,
  139. const struct sched_param *param), (target_thread, policy, param), 0)
  140. FORWARD (pthread_mutex_destroy, (pthread_mutex_t *mutex), (mutex), 0)
  141. FORWARD (pthread_mutex_init,
  142. (pthread_mutex_t *mutex, const pthread_mutexattr_t *mutexattr),
  143. (mutex, mutexattr), 0)
  144. FORWARD (pthread_mutex_lock, (pthread_mutex_t *mutex), (mutex), 0)
  145. FORWARD (pthread_mutex_unlock, (pthread_mutex_t *mutex), (mutex), 0)
  146. FORWARD2 (pthread_self, pthread_t, (void), (), return 0)
  147. FORWARD (pthread_setcancelstate, (int state, int *oldstate), (state, oldstate),
  148. 0)
  149. FORWARD (pthread_setcanceltype, (int type, int *oldtype), (type, oldtype), 0)
  150. #define return /* value is void */
  151. FORWARD2(__pthread_unwind,
  152. void attribute_hidden __attribute ((noreturn)) __cleanup_fct_attribute
  153. attribute_compat_text_section,
  154. (__pthread_unwind_buf_t *buf), (buf), {
  155. /* We cannot call abort() here. */
  156. INTERNAL_SYSCALL_DECL (err);
  157. INTERNAL_SYSCALL (kill, err, 1, SIGKILL);
  158. })
  159. #undef return