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