thread-stub.c revision 1.5 1 /* $NetBSD: thread-stub.c,v 1.5 2003/01/19 21:58:23 thorpej Exp $ */
2
3 /*-
4 * Copyright (c) 2003 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 /*
40 * Stubs for thread operations, for use when threads are not used by
41 * the application. See "reentrant.h" for details.
42 */
43
44 #ifdef _REENTRANT
45
46 #define __LIBC_THREAD_STUBS
47
48 #include "namespace.h"
49 #include "reentrant.h"
50
51 #include <errno.h>
52 #include <signal.h>
53 #include <unistd.h>
54
55 extern int __isthreaded;
56
57 #define DIE() (void)kill(getpid(), SIGABRT)
58
59 #define CHECK_NOT_THREADED_ALWAYS() \
60 do { \
61 if (__isthreaded) \
62 DIE(); \
63 } while (/*CONSTCOND*/0)
64
65 #if 1
66 #define CHECK_NOT_THREADED() CHECK_NOT_THREADED_ALWAYS()
67 #else
68 #define CHECK_NOT_THREADED() /* nothing */
69 #endif
70
71 /* mutexes */
72
73 int __libc_mutex_init_stub(mutex_t *, const mutexattr_t *);
74 int __libc_mutex_catchall_stub(mutex_t *);
75
76 __weak_alias(__libc_mutex_init,__libc_mutex_init_stub)
77 __weak_alias(__libc_mutex_lock,__libc_mutex_catchall_stub)
78 __weak_alias(__libc_mutex_trylock,__libc_mutex_catchall_stub)
79 __weak_alias(__libc_mutex_unlock,__libc_mutex_catchall_stub)
80 __weak_alias(__libc_mutex_destroy,__libc_mutex_catchall_stub)
81
82 int __libc_mutexattr_catchall_stub(mutexattr_t *);
83 int __libc_mutexattr_settype_stub(mutexattr_t *, int);
84
85 __weak_alias(__libc_mutexattr_init,__libc_mutexattr_catchall_stub)
86 __weak_alias(__libc_mutexattr_destroy,__libc_mutexattr_catchall_stub)
87 __weak_alias(__libc_mutexattr_settype,__libc_mutexattr_settype_stub)
88
89 int
90 __libc_mutex_init_stub(mutex_t *m, const mutexattr_t *a)
91 {
92 /* LINTED deliberate lack of effect */
93 (void)m;
94 /* LINTED deliberate lack of effect */
95 (void)a;
96
97 CHECK_NOT_THREADED();
98
99 return (0);
100 }
101
102 int
103 __libc_mutex_catchall_stub(mutex_t *m)
104 {
105 /* LINTED deliberate lack of effect */
106 (void)m;
107
108 CHECK_NOT_THREADED();
109
110 return (0);
111 }
112
113 int
114 __libc_mutexattr_settype_stub(mutexattr_t *ma, int type)
115 {
116 /* LINTED deliberate lack of effect */
117 (void)ma;
118 /* LINTED deliberate lack of effect */
119 (void)type;
120
121 return (0);
122 }
123
124 int
125 __libc_mutexattr_catchall_stub(mutexattr_t *ma)
126 {
127 /* LINTED deliberate lack of effect */
128 (void)ma;
129
130 CHECK_NOT_THREADED();
131
132 return (0);
133 }
134
135 /* condition variables */
136
137 int __libc_cond_init_stub(cond_t *, const condattr_t *);
138 int __libc_cond_wait_stub(cond_t *, mutex_t *);
139 int __libc_cond_timedwait_stub(cond_t *, mutex_t *,
140 const struct timespec *);
141 int __libc_cond_catchall_stub(cond_t *);
142
143 __weak_alias(__libc_cond_init,__libc_cond_init_stub)
144 __weak_alias(__libc_cond_signal,__libc_cond_catchall_stub)
145 __weak_alias(__libc_cond_broadcast,__libc_cond_catchall_stub)
146 __weak_alias(__libc_cond_wait,__libc_cond_wait_stub)
147 __weak_alias(__libc_cond_timedwait,__libc_cond_timedwait_stub)
148 __weak_alias(__libc_cond_destroy,__libc_cond_catchall_stub)
149
150 int
151 __libc_cond_init_stub(cond_t *c, const condattr_t *a)
152 {
153 /* LINTED deliberate lack of effect */
154 (void)c;
155 /* LINTED deliberate lack of effect */
156 (void)a;
157
158 CHECK_NOT_THREADED();
159
160 return (0);
161 }
162
163 int
164 __libc_cond_wait_stub(cond_t *c, mutex_t *m)
165 {
166 /* LINTED deliberate lack of effect */
167 (void)c;
168 /* LINTED deliberate lack of effect */
169 (void)m;
170
171 CHECK_NOT_THREADED();
172
173 return (0);
174 }
175
176 int
177 __libc_cond_timedwait_stub(cond_t *c, mutex_t *m, const struct timespec *t)
178 {
179 /* LINTED deliberate lack of effect */
180 (void)c;
181 /* LINTED deliberate lack of effect */
182 (void)m;
183 /* LINTED deliberate lack of effect */
184 (void)t;
185
186 CHECK_NOT_THREADED();
187
188 return (0);
189 }
190
191 int
192 __libc_cond_catchall_stub(cond_t *c)
193 {
194 /* LINTED deliberate lack of effect */
195 (void)c;
196
197 CHECK_NOT_THREADED();
198
199 return (0);
200 }
201
202
203 /* read-write locks */
204
205 int __libc_rwlock_init_stub(rwlock_t *, rwlockattr_t *);
206 int __libc_rwlock_catchall_stub(rwlock_t *);
207
208 __weak_alias(__libc_rwlock_init,__libc_rwlock_init_stub)
209 __weak_alias(__libc_rwlock_rdlock,__libc_rwlock_catchall_stub)
210 __weak_alias(__libc_rwlock_wrlock,__libc_rwlock_catchall_stub)
211 __weak_alias(__libc_rwlock_tryrdlock,__libc_rwlock_catchall_stub)
212 __weak_alias(__libc_rwlock_trywrlock,__libc_rwlock_catchall_stub)
213 __weak_alias(__libc_rwlock_unlock,__libc_rwlock_catchall_stub)
214 __weak_alias(__libc_rwlock_destroy,__libc_rwlock_catchall_stub)
215
216 int
217 __libc_rwlock_init_stub(rwlock_t *l, rwlockattr_t *a)
218 {
219 /* LINTED deliberate lack of effect */
220 (void)l;
221 /* LINTED deliberate lack of effect */
222 (void)a;
223
224 CHECK_NOT_THREADED();
225
226 return (0);
227 }
228
229 int
230 __libc_rwlock_catchall_stub(rwlock_t *l)
231 {
232 /* LINTED deliberate lack of effect */
233 (void)l;
234
235 CHECK_NOT_THREADED();
236
237 return (0);
238 }
239
240
241 /* thread-specific data */
242
243 int __libc_thr_keycreate_stub(thread_key_t *, void (*)(void *));
244 int __libc_thr_setspecific_stub(thread_key_t, const void *);
245 void *__libc_thr_getspecific_stub(thread_key_t);
246 int __libc_thr_keydelete_stub(thread_key_t);
247
248 __weak_alias(__libc_thr_keycreate,__libc_thr_keycreate_stub)
249 __weak_alias(__libc_thr_setspecific,__libc_thr_setspecific_stub)
250 __weak_alias(__libc_thr_getspecific,__libc_thr_getspecific_stub)
251 __weak_alias(__libc_thr_keydelete,__libc_thr_keydelete_stub)
252
253 int
254 __libc_thr_keycreate_stub(thread_key_t *k, void (*d)(void *))
255 {
256 /* LINTED deliberate lack of effect */
257 (void)k;
258 /* LINTED deliberate lack of effect */
259 (void)d;
260
261 CHECK_NOT_THREADED();
262
263 return (0);
264 }
265
266 int
267 __libc_thr_setspecific_stub(thread_key_t k, const void *v)
268 {
269 /* LINTED deliberate lack of effect */
270 (void)k;
271 /* LINTED deliberate lack of effect */
272 (void)v;
273
274 DIE();
275
276 return (0);
277 }
278
279 void *
280 __libc_thr_getspecific_stub(thread_key_t k)
281 {
282 /* LINTED deliberate lack of effect */
283 (void)k;
284
285 DIE();
286
287 return (NULL);
288 }
289
290 int
291 __libc_thr_keydelete_stub(thread_key_t k)
292 {
293 /* LINTED deliberate lack of effect */
294 (void)k;
295
296 CHECK_NOT_THREADED();
297
298 return (0);
299 }
300
301
302 /* misc. */
303
304 int __libc_thr_once_stub(once_t *, void (*)(void));
305 int __libc_thr_sigsetmask_stub(int, const sigset_t *, sigset_t *);
306 thr_t __libc_thr_self_stub(void);
307 void __libc_thr_yield_stub(void);
308 int __libc_thr_create_stub(thr_t *, const thrattr_t *,
309 void *(*)(void *), void *);
310 void __libc_thr_exit_stub(void *);
311 int *__libc_thr_errno_stub(void);
312
313 __weak_alias(__libc_thr_once,__libc_thr_once_stub)
314 __weak_alias(__libc_thr_sigsetmask,__libc_thr_sigsetmask_stub)
315 __weak_alias(__libc_thr_self,__libc_thr_self_stub)
316 __weak_alias(__libc_thr_yield,__libc_thr_yield_stub)
317 __weak_alias(__libc_thr_create,__libc_thr_create_stub)
318 __weak_alias(__libc_thr_exit,__libc_thr_exit_stub)
319 __weak_alias(__libc_thr_errno,__libc_thr_errno_stub)
320
321
322 int
323 __libc_thr_once_stub(once_t *o, void (*r)(void))
324 {
325
326 /* XXX Knowledge of libpthread types. */
327
328 if (o->pto_done == 0) {
329 (*r)();
330 o->pto_done = 1;
331 }
332
333 return (0);
334 }
335
336 int
337 __libc_thr_sigsetmask_stub(int h, const sigset_t *s, sigset_t *o)
338 {
339 /* LINTED deliberate lack of effect */
340 (void)h;
341 /* LINTED deliberate lack of effect */
342 (void)s;
343 /* LINTED deliberate lack of effect */
344 (void)o;
345
346 CHECK_NOT_THREADED();
347
348 /* XXX just use sigmask(2)? abort? */
349
350 return (0);
351 }
352
353 thr_t
354 __libc_thr_self_stub(void)
355 {
356
357 return (NULL);
358 }
359
360 void
361 __libc_thr_yield_stub(void)
362 {
363
364 /* Nothing to do. */
365 }
366
367 int
368 __libc_thr_create_stub(thr_t *tp, const thrattr_t *ta,
369 void *(*f)(void *), void *a)
370 {
371 /* LINTED deliberate lack of effect */
372 (void)tp;
373 /* LINTED deliberate lack of effect */
374 (void)ta;
375 /* LINTED deliberate lack of effect */
376 (void)f;
377 /* LINTED deliberate lack of effect */
378 (void)a;
379
380 DIE();
381
382 return (EOPNOTSUPP);
383 }
384
385 void
386 __libc_thr_exit_stub(void *v)
387 {
388 /* LINTED deliberate lack of effect */
389 (void)v;
390
391 exit(0);
392 }
393
394 int *
395 __libc_thr_errno_stub(void)
396 {
397
398 DIE();
399
400 return (NULL);
401 }
402
403 #endif /* _REENTRANT */
404