1/* Copyright (C) 2002-2020 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 <https://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_getschedpolicy,
60 (const pthread_attr_t *attr, int *policy), (attr, policy), 0)
61FORWARD (pthread_attr_setschedpolicy, (pthread_attr_t *attr, int policy),
62 (attr, policy), 0)
63
64FORWARD (pthread_attr_getscope,
65 (const pthread_attr_t *attr, int *scope), (attr, scope), 0)
66FORWARD (pthread_attr_setscope, (pthread_attr_t *attr, int scope),
67 (attr, scope), 0)
68
69
70FORWARD (pthread_condattr_destroy, (pthread_condattr_t *attr), (attr), 0)
71FORWARD (pthread_condattr_init, (pthread_condattr_t *attr), (attr), 0)
72
73#if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_3_2)
74FORWARD2 (__pthread_cond_broadcast_2_0, int attribute_compat_text_section,
75 (pthread_cond_2_0_t *cond), (cond), return 0)
76compat_symbol (libc, __pthread_cond_broadcast_2_0, pthread_cond_broadcast,
77 GLIBC_2_0);
78#endif
79FORWARD (__pthread_cond_broadcast, (pthread_cond_t *cond), (cond), 0)
80versioned_symbol (libc, __pthread_cond_broadcast, pthread_cond_broadcast,
81 GLIBC_2_3_2);
82
83#if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_3_2)
84FORWARD2 (__pthread_cond_destroy_2_0, int attribute_compat_text_section,
85 (pthread_cond_2_0_t *cond), (cond), return 0)
86compat_symbol (libc, __pthread_cond_destroy_2_0, pthread_cond_destroy,
87 GLIBC_2_0);
88#endif
89FORWARD (__pthread_cond_destroy, (pthread_cond_t *cond), (cond), 0)
90versioned_symbol (libc, __pthread_cond_destroy, pthread_cond_destroy,
91 GLIBC_2_3_2);
92
93#if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_3_2)
94FORWARD2 (__pthread_cond_init_2_0, int attribute_compat_text_section,
95 (pthread_cond_2_0_t *cond, const pthread_condattr_t *cond_attr),
96 (cond, cond_attr), return 0)
97compat_symbol (libc, __pthread_cond_init_2_0, pthread_cond_init, GLIBC_2_0);
98#endif
99FORWARD (__pthread_cond_init,
100 (pthread_cond_t *cond, const pthread_condattr_t *cond_attr),
101 (cond, cond_attr), 0)
102versioned_symbol (libc, __pthread_cond_init, pthread_cond_init, GLIBC_2_3_2);
103
104#if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_3_2)
105FORWARD2 (__pthread_cond_signal_2_0, int attribute_compat_text_section,
106 (pthread_cond_2_0_t *cond), (cond), return 0)
107compat_symbol (libc, __pthread_cond_signal_2_0, pthread_cond_signal,
108 GLIBC_2_0);
109#endif
110FORWARD (__pthread_cond_signal, (pthread_cond_t *cond), (cond), 0)
111versioned_symbol (libc, __pthread_cond_signal, pthread_cond_signal,
112 GLIBC_2_3_2);
113
114#if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_3_2)
115FORWARD2 (__pthread_cond_wait_2_0, int attribute_compat_text_section,
116 (pthread_cond_2_0_t *cond, pthread_mutex_t *mutex), (cond, mutex),
117 return 0)
118compat_symbol (libc, __pthread_cond_wait_2_0, pthread_cond_wait,
119 GLIBC_2_0);
120#endif
121FORWARD (__pthread_cond_wait, (pthread_cond_t *cond, pthread_mutex_t *mutex),
122 (cond, mutex), 0)
123versioned_symbol (libc, __pthread_cond_wait, pthread_cond_wait,
124 GLIBC_2_3_2);
125
126#if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_3_2)
127FORWARD2 (__pthread_cond_timedwait_2_0, int attribute_compat_text_section,
128 (pthread_cond_2_0_t *cond, pthread_mutex_t *mutex,
129 const struct timespec *abstime), (cond, mutex, abstime),
130 return 0)
131compat_symbol (libc, __pthread_cond_timedwait_2_0, pthread_cond_timedwait,
132 GLIBC_2_0);
133#endif
134FORWARD (__pthread_cond_timedwait,
135 (pthread_cond_t *cond, pthread_mutex_t *mutex,
136 const struct timespec *abstime), (cond, mutex, abstime), 0)
137versioned_symbol (libc, __pthread_cond_timedwait, pthread_cond_timedwait,
138 GLIBC_2_3_2);
139
140
141FORWARD_NORETURN (__pthread_exit, void, (void *retval), (retval),
142 exit (EXIT_SUCCESS))
143strong_alias (__pthread_exit, pthread_exit);
144
145
146FORWARD (pthread_getschedparam,
147 (pthread_t target_thread, int *policy, struct sched_param *param),
148 (target_thread, policy, param), 0)
149FORWARD (pthread_setschedparam,
150 (pthread_t target_thread, int policy,
151 const struct sched_param *param), (target_thread, policy, param), 0)
152
153
154FORWARD (pthread_mutex_destroy, (pthread_mutex_t *mutex), (mutex), 0)
155
156FORWARD (pthread_mutex_init,
157 (pthread_mutex_t *mutex, const pthread_mutexattr_t *mutexattr),
158 (mutex, mutexattr), 0)
159
160FORWARD (pthread_mutex_lock, (pthread_mutex_t *mutex), (mutex), 0)
161
162FORWARD (pthread_mutex_unlock, (pthread_mutex_t *mutex), (mutex), 0)
163
164FORWARD (__pthread_setcancelstate, (int state, int *oldstate),
165 (state, oldstate), 0)
166strong_alias (__pthread_setcancelstate, pthread_setcancelstate)
167
168FORWARD (pthread_setcanceltype, (int type, int *oldtype), (type, oldtype), 0)
169
170FORWARD_NORETURN (__pthread_unwind,
171 void attribute_hidden __attribute ((noreturn))
172 __cleanup_fct_attribute attribute_compat_text_section,
173 (__pthread_unwind_buf_t *buf), (buf),
174 __safe_fatal ())
175