forward.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /* Copyright (C) 2002, 2003 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 <features.h>
  17. #include <stdlib.h>
  18. #include <dlfcn.h>
  19. /* psm: keep this before internals.h */
  20. #if 0
  21. vda: here is why:
  22. headers contain libc_hidden_proto(foo).
  23. In libpthread/linuxthreads.old/sysdeps/pthread/bits/libc-lock.h
  24. adding libc_hidden_proto(foo) just before weak_extern (__pthread_initialize)
  25. will not warn:
  26. /* libc_hidden_proto(foo) */
  27. weak_extern (__pthread_initialize)
  28. /* libc_hidden_proto(foo) */
  29. but adding after will! Which is extremely strange -
  30. weak_extern expands into just "#pragma weak __pthread_initialize".
  31. TODO: determine whether it is a gcc bug or what
  32. (see gcc.gnu.org/PR36282).
  33. For now, just include all headers before internals.h
  34. (they are again included in internals.h - maybe remove them there later)
  35. #endif
  36. #include <string.h>
  37. #include <limits.h>
  38. #include <setjmp.h>
  39. #include <signal.h>
  40. #include <unistd.h>
  41. #include <sys/types.h>
  42. #include <sys/wait.h>
  43. #include <sys/time.h>
  44. #include "internals.h"
  45. /* Pointers to the libc functions. */
  46. struct pthread_functions __libc_pthread_functions attribute_hidden;
  47. # define FORWARD2(name, rettype, decl, params, defaction) \
  48. rettype \
  49. name decl \
  50. { \
  51. if (__libc_pthread_functions.ptr_##name == NULL) \
  52. defaction; \
  53. \
  54. return __libc_pthread_functions.ptr_##name params; \
  55. }
  56. # define FORWARD(name, decl, params, defretval) \
  57. FORWARD2 (name, int, decl, params, return defretval)
  58. FORWARD (pthread_attr_destroy, (pthread_attr_t *attr), (attr), 0)
  59. FORWARD (pthread_attr_init, (pthread_attr_t *attr), (attr), 0)
  60. FORWARD (pthread_attr_getdetachstate,
  61. (const pthread_attr_t *attr, int *detachstate), (attr, detachstate),
  62. 0)
  63. FORWARD (pthread_attr_setdetachstate, (pthread_attr_t *attr, int detachstate),
  64. (attr, detachstate), 0)
  65. FORWARD (pthread_attr_getinheritsched,
  66. (const pthread_attr_t *attr, int *inherit), (attr, inherit), 0)
  67. FORWARD (pthread_attr_setinheritsched, (pthread_attr_t *attr, int inherit),
  68. (attr, inherit), 0)
  69. FORWARD (pthread_attr_getschedparam,
  70. (const pthread_attr_t *attr, struct sched_param *param),
  71. (attr, param), 0)
  72. FORWARD (pthread_attr_setschedparam,
  73. (pthread_attr_t *attr, const struct sched_param *param),
  74. (attr, param), 0)
  75. FORWARD (pthread_attr_getschedpolicy,
  76. (const pthread_attr_t *attr, int *policy), (attr, policy), 0)
  77. FORWARD (pthread_attr_setschedpolicy, (pthread_attr_t *attr, int policy),
  78. (attr, policy), 0)
  79. FORWARD (pthread_attr_getscope,
  80. (const pthread_attr_t *attr, int *scope), (attr, scope), 0)
  81. FORWARD (pthread_attr_setscope, (pthread_attr_t *attr, int scope),
  82. (attr, scope), 0)
  83. FORWARD (pthread_condattr_destroy, (pthread_condattr_t *attr), (attr), 0)
  84. FORWARD (pthread_condattr_init, (pthread_condattr_t *attr), (attr), 0)
  85. FORWARD (pthread_cond_broadcast, (pthread_cond_t *cond), (cond), 0)
  86. FORWARD (pthread_cond_destroy, (pthread_cond_t *cond), (cond), 0)
  87. FORWARD (pthread_cond_init,
  88. (pthread_cond_t *cond, const pthread_condattr_t *cond_attr),
  89. (cond, cond_attr), 0)
  90. FORWARD (pthread_cond_signal, (pthread_cond_t *cond), (cond), 0)
  91. FORWARD (pthread_cond_wait, (pthread_cond_t *cond, pthread_mutex_t *mutex),
  92. (cond, mutex), 0)
  93. FORWARD (pthread_cond_timedwait,
  94. (pthread_cond_t *cond, pthread_mutex_t *mutex,
  95. const struct timespec *abstime), (cond, mutex, abstime), 0)
  96. FORWARD (pthread_equal, (pthread_t thread1, pthread_t thread2),
  97. (thread1, thread2), 1)
  98. /* Use an alias to avoid warning, as pthread_exit is declared noreturn. */
  99. FORWARD2 (__pthread_exit, void, (void *retval), (retval), exit (EXIT_SUCCESS))
  100. strong_alias (__pthread_exit, pthread_exit)
  101. FORWARD (pthread_getschedparam,
  102. (pthread_t target_thread, int *policy, struct sched_param *param),
  103. (target_thread, policy, param), 0)
  104. FORWARD (pthread_setschedparam,
  105. (pthread_t target_thread, int policy,
  106. const struct sched_param *param), (target_thread, policy, param), 0)
  107. FORWARD (pthread_mutex_destroy, (pthread_mutex_t *mutex), (mutex), 0)
  108. FORWARD (pthread_mutex_init,
  109. (pthread_mutex_t *mutex, const pthread_mutexattr_t *mutexattr),
  110. (mutex, mutexattr), 0)
  111. strong_alias(pthread_mutex_init, __pthread_mutex_init)
  112. FORWARD (pthread_mutex_lock, (pthread_mutex_t *mutex), (mutex), 0)
  113. strong_alias(pthread_mutex_lock, __pthread_mutex_lock)
  114. FORWARD (pthread_mutex_trylock, (pthread_mutex_t *mutex), (mutex), 0)
  115. strong_alias(pthread_mutex_trylock, __pthread_mutex_trylock)
  116. FORWARD (pthread_mutex_unlock, (pthread_mutex_t *mutex), (mutex), 0)
  117. strong_alias(pthread_mutex_unlock, __pthread_mutex_unlock)
  118. FORWARD2 (pthread_self, pthread_t, (void), (), return 0)
  119. FORWARD (pthread_setcancelstate, (int state, int *oldstate), (state, oldstate),
  120. 0)
  121. FORWARD (pthread_setcanceltype, (int type, int *oldtype), (type, oldtype), 0)
  122. FORWARD2 (_pthread_cleanup_push, void, (struct _pthread_cleanup_buffer * buffer, void (*routine)(void *), void * arg), (buffer, routine, arg), return)
  123. FORWARD2 (_pthread_cleanup_push_defer, void, (struct _pthread_cleanup_buffer * buffer, void (*routine)(void *), void * arg), (buffer, routine, arg), return)
  124. libc_hidden_def(_pthread_cleanup_push_defer)
  125. FORWARD2 (_pthread_cleanup_pop, void, (struct _pthread_cleanup_buffer * buffer, int execute), (buffer, execute), return)
  126. FORWARD2 (_pthread_cleanup_pop_restore, void, (struct _pthread_cleanup_buffer * buffer, int execute), (buffer, execute), return)
  127. libc_hidden_def(_pthread_cleanup_pop_restore)