thread-stub.c revision 1.3 1 /* $NetBSD: thread-stub.c,v 1.3 2003/01/19 19:48:45 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 <signal.h>
52 #include <unistd.h>
53
54 extern int __isthreaded;
55
56 #define DIE() (void)kill(getpid(), SIGABRT)
57
58 #define CHECK_NOT_THREADED_ALWAYS() \
59 do { \
60 if (__isthreaded) \
61 DIE(); \
62 } while (/*CONSTCOND*/0)
63
64 #if 1
65 #define CHECK_NOT_THREADED() CHECK_NOT_THREADED_ALWAYS()
66 #else
67 #define CHECK_NOT_THREADED() /* nothing */
68 #endif
69
70 /* mutexes */
71
72 int __libc_mutex_init_stub(mutex_t *, const mutexattr_t *);
73 int __libc_mutex_catchall_stub(mutex_t *);
74
75 __weak_alias(__libc_mutex_init,__libc_mutex_init_stub)
76 __weak_alias(__libc_mutex_lock,__libc_mutex_catchall_stub)
77 __weak_alias(__libc_mutex_trylock,__libc_mutex_catchall_stub)
78 __weak_alias(__libc_mutex_unlock,__libc_mutex_catchall_stub)
79 __weak_alias(__libc_mutex_destroy,__libc_mutex_catchall_stub)
80
81 int
82 __libc_mutex_init_stub(mutex_t *m, const mutexattr_t *a)
83 {
84 /* LINTED deliberate lack of effect */
85 (void)m;
86 /* LINTED deliberate lack of effect */
87 (void)a;
88
89 CHECK_NOT_THREADED();
90
91 return (0);
92 }
93
94 int
95 __libc_mutex_catchall_stub(mutex_t *m)
96 {
97 /* LINTED deliberate lack of effect */
98 (void)m;
99
100 CHECK_NOT_THREADED();
101
102 return (0);
103 }
104
105
106 /* condition variables */
107
108 int __libc_cond_init_stub(cond_t *, const condattr_t *);
109 int __libc_cond_wait_stub(cond_t *, mutex_t *);
110 int __libc_cond_timedwait_stub(cond_t *, mutex_t *,
111 const struct timespec *);
112 int __libc_cond_catchall_stub(cond_t *);
113
114 __weak_alias(__libc_cond_init,__libc_cond_init_stub)
115 __weak_alias(__libc_cond_signal,__libc_cond_catchall_stub)
116 __weak_alias(__libc_cond_broadcast,__libc_cond_catchall_stub)
117 __weak_alias(__libc_cond_wait,__libc_cond_wait_stub)
118 __weak_alias(__libc_cond_timedwait,__libc_cond_timedwait_stub)
119 __weak_alias(__libc_cond_destroy,__libc_cond_catchall_stub)
120
121 int
122 __libc_cond_init_stub(cond_t *c, const condattr_t *a)
123 {
124 /* LINTED deliberate lack of effect */
125 (void)c;
126 /* LINTED deliberate lack of effect */
127 (void)a;
128
129 CHECK_NOT_THREADED();
130
131 return (0);
132 }
133
134 int
135 __libc_cond_wait_stub(cond_t *c, mutex_t *m)
136 {
137 /* LINTED deliberate lack of effect */
138 (void)c;
139 /* LINTED deliberate lack of effect */
140 (void)m;
141
142 CHECK_NOT_THREADED();
143
144 return (0);
145 }
146
147 int
148 __libc_cond_timedwait_stub(cond_t *c, mutex_t *m, const struct timespec *t)
149 {
150 /* LINTED deliberate lack of effect */
151 (void)c;
152 /* LINTED deliberate lack of effect */
153 (void)m;
154 /* LINTED deliberate lack of effect */
155 (void)t;
156
157 CHECK_NOT_THREADED();
158
159 return (0);
160 }
161
162 int
163 __libc_cond_catchall_stub(cond_t *c)
164 {
165 /* LINTED deliberate lack of effect */
166 (void)c;
167
168 CHECK_NOT_THREADED();
169
170 return (0);
171 }
172
173
174 /* read-write locks */
175
176 int __libc_rwlock_init_stub(rwlock_t *, rwlockattr_t *);
177 int __libc_rwlock_catchall_stub(rwlock_t *);
178
179 __weak_alias(__libc_rwlock_init,__libc_rwlock_init_stub)
180 __weak_alias(__libc_rwlock_rdlock,__libc_rwlock_catchall_stub)
181 __weak_alias(__libc_rwlock_wrlock,__libc_rwlock_catchall_stub)
182 __weak_alias(__libc_rwlock_tryrdlock,__libc_rwlock_catchall_stub)
183 __weak_alias(__libc_rwlock_trywrlock,__libc_rwlock_catchall_stub)
184 __weak_alias(__libc_rwlock_unlock,__libc_rwlock_catchall_stub)
185 __weak_alias(__libc_rwlock_destroy,__libc_rwlock_catchall_stub)
186
187 int
188 __libc_rwlock_init_stub(rwlock_t *l, rwlockattr_t *a)
189 {
190 /* LINTED deliberate lack of effect */
191 (void)l;
192 /* LINTED deliberate lack of effect */
193 (void)a;
194
195 CHECK_NOT_THREADED();
196
197 return (0);
198 }
199
200 int
201 __libc_rwlock_catchall_stub(rwlock_t *l)
202 {
203 /* LINTED deliberate lack of effect */
204 (void)l;
205
206 CHECK_NOT_THREADED();
207
208 return (0);
209 }
210
211
212 /* thread-specific data */
213
214 int __libc_thr_keycreate_stub(thread_key_t *, void (*)(void *));
215 int __libc_thr_setspecific_stub(thread_key_t, const void *);
216 void *__libc_thr_getspecific_stub(thread_key_t);
217 int __libc_thr_keydelete_stub(thread_key_t);
218
219 __weak_alias(__libc_thr_keycreate,__libc_thr_keycreate_stub)
220 __weak_alias(__libc_thr_setspecific,__libc_thr_setspecific_stub)
221 __weak_alias(__libc_thr_getspecific,__libc_thr_getspecific_stub)
222 __weak_alias(__libc_thr_keydelete,__libc_thr_keydelete_stub)
223
224 int
225 __libc_thr_keycreate_stub(thread_key_t *k, void (*d)(void *))
226 {
227 /* LINTED deliberate lack of effect */
228 (void)k;
229 /* LINTED deliberate lack of effect */
230 (void)d;
231
232 CHECK_NOT_THREADED();
233
234 return (0);
235 }
236
237 int
238 __libc_thr_setspecific_stub(thread_key_t k, const void *v)
239 {
240 /* LINTED deliberate lack of effect */
241 (void)k;
242 /* LINTED deliberate lack of effect */
243 (void)v;
244
245 DIE();
246
247 return (0);
248 }
249
250 void *
251 __libc_thr_getspecific_stub(thread_key_t k)
252 {
253 /* LINTED deliberate lack of effect */
254 (void)k;
255
256 DIE();
257
258 return (NULL);
259 }
260
261 int
262 __libc_thr_keydelete_stub(thread_key_t k)
263 {
264 /* LINTED deliberate lack of effect */
265 (void)k;
266
267 CHECK_NOT_THREADED();
268
269 return (0);
270 }
271
272
273 /* misc. */
274
275 int __libc_thr_once_stub(once_t *, void (*)(void));
276 int __libc_thr_sigsetmask_stub(int, const sigset_t *, sigset_t *);
277 thr_t __libc_thr_self_stub(void);
278 int *__libc_thr_errno_stub(void);
279
280 __weak_alias(__libc_thr_once,__libc_thr_once_stub)
281 __weak_alias(__libc_thr_sigsetmask,__libc_thr_sigsetmask_stub)
282 __weak_alias(__libc_thr_self,__libc_thr_self_stub)
283 __weak_alias(__libc_thr_errno,__libc_thr_errno_stub)
284
285 int
286 __libc_thr_once_stub(once_t *o, void (*r)(void))
287 {
288
289 /* XXX Knowledge of libpthread types. */
290
291 if (o->pto_done == 0) {
292 (*r)();
293 o->pto_done = 1;
294 }
295
296 return (0);
297 }
298
299 int
300 __libc_thr_sigsetmask_stub(int h, const sigset_t *s, sigset_t *o)
301 {
302 /* LINTED deliberate lack of effect */
303 (void)h;
304 /* LINTED deliberate lack of effect */
305 (void)s;
306 /* LINTED deliberate lack of effect */
307 (void)o;
308
309 CHECK_NOT_THREADED();
310
311 /* XXX just use sigmask(2)? abort? */
312
313 return (0);
314 }
315
316 thr_t
317 __libc_thr_self_stub(void)
318 {
319
320 DIE();
321
322 return (NULL);
323 }
324
325 int *
326 __libc_thr_errno_stub(void)
327 {
328
329 DIE();
330
331 return (NULL);
332 }
333
334 #endif /* _REENTRANT */
335