forward.c 7.3 KB

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