xref: /freebsd/lib/libc/gen/_pthread_stubs.c (revision a3e8fd0b7f663db7eafff527d5c3ca3bcfa8a537)
1 /*
2  * Copyright (c) 2001 Daniel Eischen <deischen@FreeBSD.org>.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY DANIEL EISCHEN AND CONTRIBUTORS ``AS IS''
15  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  */
26 
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
29 
30 #include <signal.h>
31 #include <pthread.h>
32 #include <pthread_np.h>
33 
34 /*
35  * Weak symbols: All libc internal usage of these functions should
36  * use the weak symbol versions (_pthread_XXX).  If libpthread is
37  * linked, it will override these functions with (non-weak) routines.
38  * The _pthread_XXX functions are provided solely for internal libc
39  * usage to avoid unwanted cancellation points and to differentiate
40  * between application locks and libc locks (threads holding the
41  * latter can't be allowed to exit/terminate).
42  */
43 __weak_reference(_pthread_cond_init_stub,	_pthread_cond_init);
44 __weak_reference(_pthread_cond_signal_stub,	_pthread_cond_signal);
45 __weak_reference(_pthread_cond_wait_stub,	_pthread_cond_wait);
46 __weak_reference(_pthread_cond_destroy_stub,	_pthread_cond_destroy);
47 __weak_reference(_pthread_getspecific_stub,	_pthread_getspecific);
48 __weak_reference(_pthread_key_create_stub,	_pthread_key_create);
49 __weak_reference(_pthread_key_delete_stub,	_pthread_key_delete);
50 __weak_reference(_pthread_main_np_stub,		_pthread_main_np);
51 __weak_reference(_pthread_mutex_destroy_stub,	_pthread_mutex_destroy);
52 __weak_reference(_pthread_mutex_init_stub,	_pthread_mutex_init);
53 __weak_reference(_pthread_mutex_lock_stub,	_pthread_mutex_lock);
54 __weak_reference(_pthread_mutex_trylock_stub,	_pthread_mutex_trylock);
55 __weak_reference(_pthread_mutex_unlock_stub,	_pthread_mutex_unlock);
56 __weak_reference(_pthread_mutexattr_init_stub,	_pthread_mutexattr_init);
57 __weak_reference(_pthread_mutexattr_destroy_stub, _pthread_mutexattr_destroy);
58 __weak_reference(_pthread_mutexattr_settype_stub, _pthread_mutexattr_settype);
59 __weak_reference(_pthread_once_stub,		_pthread_once);
60 __weak_reference(_pthread_self_stub,		_pthread_self);
61 __weak_reference(_pthread_rwlock_init_stub,	_pthread_rwlock_init);
62 __weak_reference(_pthread_rwlock_rdlock_stub,	_pthread_rwlock_rdlock);
63 __weak_reference(_pthread_rwlock_tryrdlock_stub, _pthread_rwlock_tryrdlock);
64 __weak_reference(_pthread_rwlock_trywrlock_stub, _pthread_rwlock_trywrloc);
65 __weak_reference(_pthread_rwlock_unlock_stub,	_pthread_rwlock_unlock);
66 __weak_reference(_pthread_rwlock_wrlock_stub,	_pthread_rwlock_wrlock);
67 __weak_reference(_pthread_setspecific_stub,	_pthread_setspecific);
68 __weak_reference(_pthread_sigmask_stub,		_pthread_sigmask);
69 
70 /* Define a null pthread structure just to satisfy _pthread_self. */
71 struct pthread {
72 };
73 
74 static struct pthread	main_thread;
75 
76 int
77 _pthread_cond_init_stub(pthread_cond_t *cond,
78     const pthread_condattr_t *cond_attr)
79 {
80 	return (0);
81 }
82 
83 int
84 _pthread_cond_signal_stub(pthread_cond_t *cond)
85 {
86 	return (0);
87 }
88 
89 int
90 _pthread_cond_wait_stub(pthread_cond_t *cond, pthread_mutex_t *mutex)
91 {
92 	return (0);
93 }
94 
95 int
96 _pthread_cond_destroy_stub(pthread_cond_t *cond)
97 {
98 	return (0);
99 }
100 
101 void *
102 _pthread_getspecific_stub(pthread_key_t key)
103 {
104 	return (NULL);
105 }
106 
107 int
108 _pthread_key_create_stub(pthread_key_t *key, void (*destructor) (void *))
109 {
110 	return (0);
111 }
112 
113 int
114 _pthread_key_delete_stub(pthread_key_t key)
115 {
116 	return (0);
117 }
118 
119 int
120 _pthread_main_np_stub()
121 {
122 	return (-1);
123 }
124 
125 int
126 _pthread_mutex_destroy_stub(pthread_mutex_t *mattr)
127 {
128 	return (0);
129 }
130 
131 int
132 _pthread_mutex_init_stub(pthread_mutex_t *mutex, const pthread_mutexattr_t *mattr)
133 {
134 	return (0);
135 }
136 
137 int
138 _pthread_mutex_lock_stub(pthread_mutex_t *mutex)
139 {
140 	return (0);
141 }
142 
143 int
144 _pthread_mutex_trylock_stub(pthread_mutex_t *mutex)
145 {
146 	return (0);
147 }
148 
149 int
150 _pthread_mutex_unlock_stub(pthread_mutex_t *mutex)
151 {
152 	return (0);
153 }
154 
155 int
156 _pthread_mutexattr_init_stub(pthread_mutexattr_t *mattr)
157 {
158 	return (0);
159 }
160 
161 int
162 _pthread_mutexattr_destroy_stub(pthread_mutexattr_t *mattr)
163 {
164 	return (0);
165 }
166 
167 int
168 _pthread_mutexattr_settype_stub(pthread_mutexattr_t *mattr, int type)
169 {
170 	return (0);
171 }
172 
173 int
174 _pthread_once_stub(pthread_once_t *once_control, void (*init_routine) (void))
175 {
176 	return (0);
177 }
178 
179 int
180 _pthread_rwlock_init_stub(pthread_rwlock_t *rwlock,
181     const pthread_rwlockattr_t *attr)
182 {
183 	return (0);
184 }
185 
186 int
187 _pthread_rwlock_destroy_stub(pthread_rwlock_t *rwlock)
188 {
189 	return (0);
190 }
191 
192 int
193 _pthread_rwlock_rdlock_stub(pthread_rwlock_t *rwlock)
194 {
195 	return (0);
196 }
197 
198 int
199 _pthread_rwlock_tryrdlock_stub(pthread_rwlock_t *rwlock)
200 {
201 	return (0);
202 }
203 
204 int
205 _pthread_rwlock_trywrlock_stub(pthread_rwlock_t *rwlock)
206 {
207 	return (0);
208 }
209 
210 int
211 _pthread_rwlock_unlock_stub(pthread_rwlock_t *rwlock)
212 {
213 	return (0);
214 }
215 
216 int
217 _pthread_rwlock_wrlock_stub(pthread_rwlock_t *rwlock)
218 {
219 	return (0);
220 }
221 
222 pthread_t
223 _pthread_self_stub(void)
224 {
225 	return (&main_thread);
226 }
227 
228 int
229 _pthread_setspecific_stub(pthread_key_t key, const void *value)
230 {
231 	return (0);
232 }
233 
234 int
235 _pthread_sigmask_stub(int how, const sigset_t *set, sigset_t *oset)
236 {
237 	return (0);
238 }
239