forward.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /* Copyright (C) 2002, 2003, 2004, 2007 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 <atomic.h>
  20. #include <sysdep.h>
  21. /* Pointers to the libc functions. */
  22. struct pthread_functions __libc_pthread_functions attribute_hidden;
  23. int __libc_pthread_functions_init attribute_hidden;
  24. #define FORWARD2(name, rettype, decl, params, defaction) \
  25. rettype \
  26. name decl \
  27. { \
  28. if (!__libc_pthread_functions_init) { \
  29. defaction; \
  30. } else { \
  31. return PTHFCT_CALL (ptr_##name, params); \
  32. } \
  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. FORWARD (__pthread_attr_init_2_1, (pthread_attr_t *attr), (attr), 0)
  38. weak_alias(__pthread_attr_init_2_1, pthread_attr_init)
  39. FORWARD (pthread_attr_getdetachstate,
  40. (const pthread_attr_t *attr, int *detachstate), (attr, detachstate),
  41. 0)
  42. FORWARD (pthread_attr_setdetachstate, (pthread_attr_t *attr, int detachstate),
  43. (attr, detachstate), 0)
  44. FORWARD (pthread_attr_getinheritsched,
  45. (const pthread_attr_t *attr, int *inherit), (attr, inherit), 0)
  46. FORWARD (pthread_attr_setinheritsched, (pthread_attr_t *attr, int inherit),
  47. (attr, inherit), 0)
  48. FORWARD (pthread_attr_getschedparam,
  49. (const pthread_attr_t *attr, struct sched_param *param),
  50. (attr, param), 0)
  51. FORWARD (pthread_attr_setschedparam,
  52. (pthread_attr_t *attr, const struct sched_param *param),
  53. (attr, param), 0)
  54. FORWARD (pthread_attr_getschedpolicy,
  55. (const pthread_attr_t *attr, int *policy), (attr, policy), 0)
  56. FORWARD (pthread_attr_setschedpolicy, (pthread_attr_t *attr, int policy),
  57. (attr, policy), 0)
  58. FORWARD (pthread_attr_getscope,
  59. (const pthread_attr_t *attr, int *scope), (attr, scope), 0)
  60. FORWARD (pthread_attr_setscope, (pthread_attr_t *attr, int scope),
  61. (attr, scope), 0)
  62. FORWARD (pthread_condattr_destroy, (pthread_condattr_t *attr), (attr), 0)
  63. FORWARD (pthread_condattr_init, (pthread_condattr_t *attr), (attr), 0)
  64. FORWARD (__pthread_cond_broadcast, (pthread_cond_t *cond), (cond), 0)
  65. weak_alias(__pthread_cond_broadcast, pthread_cond_broadcast)
  66. FORWARD (__pthread_cond_destroy, (pthread_cond_t *cond), (cond), 0)
  67. weak_alias(__pthread_cond_destroy, pthread_cond_destroy)
  68. FORWARD (__pthread_cond_init,
  69. (pthread_cond_t *cond, const pthread_condattr_t *cond_attr),
  70. (cond, cond_attr), 0)
  71. weak_alias(__pthread_cond_init, pthread_cond_init)
  72. FORWARD (__pthread_cond_signal, (pthread_cond_t *cond), (cond), 0)
  73. weak_alias(__pthread_cond_signal, pthread_cond_signal)
  74. FORWARD (__pthread_cond_wait, (pthread_cond_t *cond, pthread_mutex_t *mutex),
  75. (cond, mutex), 0)
  76. weak_alias(__pthread_cond_wait, pthread_cond_wait)
  77. FORWARD (__pthread_cond_timedwait,
  78. (pthread_cond_t *cond, pthread_mutex_t *mutex,
  79. const struct timespec *abstime), (cond, mutex, abstime), 0)
  80. weak_alias(__pthread_cond_timedwait, pthread_cond_timedwait)
  81. FORWARD (pthread_equal, (pthread_t thread1, pthread_t thread2),
  82. (thread1, thread2), 1)
  83. /* Use an alias to avoid warning, as pthread_exit is declared noreturn. */
  84. FORWARD2 (__pthread_exit, void, (void *retval), (retval), exit (EXIT_SUCCESS))
  85. strong_alias (__pthread_exit, pthread_exit);
  86. FORWARD (pthread_getschedparam,
  87. (pthread_t target_thread, int *policy, struct sched_param *param),
  88. (target_thread, policy, param), 0)
  89. FORWARD (pthread_setschedparam,
  90. (pthread_t target_thread, int policy,
  91. const struct sched_param *param), (target_thread, policy, param), 0)
  92. FORWARD (pthread_mutex_destroy, (pthread_mutex_t *mutex), (mutex), 0)
  93. FORWARD (pthread_mutex_init,
  94. (pthread_mutex_t *mutex, const pthread_mutexattr_t *mutexattr),
  95. (mutex, mutexattr), 0)
  96. FORWARD (pthread_mutex_lock, (pthread_mutex_t *mutex), (mutex), 0)
  97. weak_alias (pthread_mutex_lock, __pthread_mutex_lock)
  98. FORWARD (pthread_mutex_unlock, (pthread_mutex_t *mutex), (mutex), 0)
  99. weak_alias (pthread_mutex_unlock, __pthread_mutex_unlock)
  100. FORWARD2 (pthread_self, pthread_t, (void), (), return 0)
  101. FORWARD (pthread_setcancelstate, (int state, int *oldstate), (state, oldstate),
  102. 0)
  103. FORWARD (pthread_setcanceltype, (int type, int *oldtype), (type, oldtype), 0)
  104. #define return /* value is void */
  105. FORWARD2(_pthread_cleanup_push_defer,
  106. void, (struct _pthread_cleanup_buffer *buffer, void (*routine)(void *), void *arg),
  107. (buffer, routine, arg),
  108. { buffer->__routine = routine; buffer->__arg = arg; });
  109. FORWARD2(_pthread_cleanup_pop_restore,
  110. void, (struct _pthread_cleanup_buffer *buffer, int execute),
  111. (buffer, execute),
  112. if (execute) { buffer->__routine(buffer->__arg); });
  113. FORWARD2(__pthread_unwind,
  114. void attribute_hidden __attribute ((noreturn)) __cleanup_fct_attribute,
  115. (__pthread_unwind_buf_t *buf), (buf), {
  116. /* We cannot call abort() here. */
  117. INTERNAL_SYSCALL_DECL (err);
  118. INTERNAL_SYSCALL (kill, err, 1, SIGKILL);
  119. #if __GNUC_PREREQ(4, 5)
  120. __builtin_unreachable();
  121. #else
  122. while(1);
  123. #endif
  124. })
  125. #undef return