1/* Copyright (C) 2002-2021 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
59#if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_3_2)
60FORWARD2 (__pthread_cond_broadcast_2_0, int attribute_compat_text_section,
61 (pthread_cond_2_0_t *cond), (cond), return 0)
62compat_symbol (libc, __pthread_cond_broadcast_2_0, pthread_cond_broadcast,
63 GLIBC_2_0);
64#endif
65FORWARD (__pthread_cond_broadcast, (pthread_cond_t *cond), (cond), 0)
66versioned_symbol (libc, __pthread_cond_broadcast, pthread_cond_broadcast,
67 GLIBC_2_3_2);
68
69#if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_3_2)
70FORWARD2 (__pthread_cond_signal_2_0, int attribute_compat_text_section,
71 (pthread_cond_2_0_t *cond), (cond), return 0)
72compat_symbol (libc, __pthread_cond_signal_2_0, pthread_cond_signal,
73 GLIBC_2_0);
74#endif
75FORWARD (__pthread_cond_signal, (pthread_cond_t *cond), (cond), 0)
76versioned_symbol (libc, __pthread_cond_signal, pthread_cond_signal,
77 GLIBC_2_3_2);
78
79#if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_3_2)
80FORWARD2 (__pthread_cond_wait_2_0, int attribute_compat_text_section,
81 (pthread_cond_2_0_t *cond, pthread_mutex_t *mutex), (cond, mutex),
82 return 0)
83compat_symbol (libc, __pthread_cond_wait_2_0, pthread_cond_wait,
84 GLIBC_2_0);
85#endif
86FORWARD (__pthread_cond_wait, (pthread_cond_t *cond, pthread_mutex_t *mutex),
87 (cond, mutex), 0)
88versioned_symbol (libc, __pthread_cond_wait, pthread_cond_wait,
89 GLIBC_2_3_2);
90
91#if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_3_2)
92FORWARD2 (__pthread_cond_timedwait_2_0, int attribute_compat_text_section,
93 (pthread_cond_2_0_t *cond, pthread_mutex_t *mutex,
94 const struct timespec *abstime), (cond, mutex, abstime),
95 return 0)
96compat_symbol (libc, __pthread_cond_timedwait_2_0, pthread_cond_timedwait,
97 GLIBC_2_0);
98#endif
99FORWARD (__pthread_cond_timedwait,
100 (pthread_cond_t *cond, pthread_mutex_t *mutex,
101 const struct timespec *abstime), (cond, mutex, abstime), 0)
102versioned_symbol (libc, __pthread_cond_timedwait, pthread_cond_timedwait,
103 GLIBC_2_3_2);
104
105
106FORWARD_NORETURN (__pthread_exit, void, (void *retval), (retval),
107 exit (EXIT_SUCCESS))
108strong_alias (__pthread_exit, pthread_exit);
109
110
111FORWARD (pthread_mutex_destroy, (pthread_mutex_t *mutex), (mutex), 0)
112
113FORWARD (pthread_mutex_init,
114 (pthread_mutex_t *mutex, const pthread_mutexattr_t *mutexattr),
115 (mutex, mutexattr), 0)
116
117FORWARD (pthread_mutex_lock, (pthread_mutex_t *mutex), (mutex), 0)
118
119FORWARD (pthread_mutex_unlock, (pthread_mutex_t *mutex), (mutex), 0)
120
121FORWARD (__pthread_setcancelstate, (int state, int *oldstate),
122 (state, oldstate), 0)
123strong_alias (__pthread_setcancelstate, pthread_setcancelstate)
124
125FORWARD (pthread_setcanceltype, (int type, int *oldtype), (type, oldtype), 0)
126
127FORWARD_NORETURN (__pthread_unwind,
128 void attribute_hidden __attribute ((noreturn))
129 __cleanup_fct_attribute attribute_compat_text_section,
130 (__pthread_unwind_buf_t *buf), (buf),
131 __safe_fatal ())
132