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