Home | History | Annotate | Line # | Download | only in thread-stub
thread-stub.c revision 1.4
      1 /*	$NetBSD: thread-stub.c,v 1.4 2003/01/19 20:46:12 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	__libc_mutexattr_catchall_stub(mutexattr_t *);
     82 int	__libc_mutexattr_settype_stub(mutexattr_t *, int);
     83 
     84 __weak_alias(__libc_mutexattr_init,__libc_mutexattr_catchall_stub)
     85 __weak_alias(__libc_mutexattr_destroy,__libc_mutexattr_catchall_stub)
     86 __weak_alias(__libc_mutexattr_settype,__libc_mutexattr_settype_stub)
     87 
     88 int
     89 __libc_mutex_init_stub(mutex_t *m, const mutexattr_t *a)
     90 {
     91 	/* LINTED deliberate lack of effect */
     92 	(void)m;
     93 	/* LINTED deliberate lack of effect */
     94 	(void)a;
     95 
     96 	CHECK_NOT_THREADED();
     97 
     98 	return (0);
     99 }
    100 
    101 int
    102 __libc_mutex_catchall_stub(mutex_t *m)
    103 {
    104 	/* LINTED deliberate lack of effect */
    105 	(void)m;
    106 
    107 	CHECK_NOT_THREADED();
    108 
    109 	return (0);
    110 }
    111 
    112 int
    113 __libc_mutexattr_settype_stub(mutexattr_t *ma, int type)
    114 {
    115 	/* LINTED deliberate lack of effect */
    116 	(void)ma;
    117 	/* LINTED deliberate lack of effect */
    118 	(void)type;
    119 
    120 	return (0);
    121 }
    122 
    123 int
    124 __libc_mutexattr_catchall_stub(mutexattr_t *ma)
    125 {
    126 	/* LINTED deliberate lack of effect */
    127 	(void)ma;
    128 
    129 	CHECK_NOT_THREADED();
    130 
    131 	return (0);
    132 }
    133 
    134 /* condition variables */
    135 
    136 int	__libc_cond_init_stub(cond_t *, const condattr_t *);
    137 int	__libc_cond_wait_stub(cond_t *, mutex_t *);
    138 int	__libc_cond_timedwait_stub(cond_t *, mutex_t *,
    139 				   const struct timespec *);
    140 int	__libc_cond_catchall_stub(cond_t *);
    141 
    142 __weak_alias(__libc_cond_init,__libc_cond_init_stub)
    143 __weak_alias(__libc_cond_signal,__libc_cond_catchall_stub)
    144 __weak_alias(__libc_cond_broadcast,__libc_cond_catchall_stub)
    145 __weak_alias(__libc_cond_wait,__libc_cond_wait_stub)
    146 __weak_alias(__libc_cond_timedwait,__libc_cond_timedwait_stub)
    147 __weak_alias(__libc_cond_destroy,__libc_cond_catchall_stub)
    148 
    149 int
    150 __libc_cond_init_stub(cond_t *c, const condattr_t *a)
    151 {
    152 	/* LINTED deliberate lack of effect */
    153 	(void)c;
    154 	/* LINTED deliberate lack of effect */
    155 	(void)a;
    156 
    157 	CHECK_NOT_THREADED();
    158 
    159 	return (0);
    160 }
    161 
    162 int
    163 __libc_cond_wait_stub(cond_t *c, mutex_t *m)
    164 {
    165 	/* LINTED deliberate lack of effect */
    166 	(void)c;
    167 	/* LINTED deliberate lack of effect */
    168 	(void)m;
    169 
    170 	CHECK_NOT_THREADED();
    171 
    172 	return (0);
    173 }
    174 
    175 int
    176 __libc_cond_timedwait_stub(cond_t *c, mutex_t *m, const struct timespec *t)
    177 {
    178 	/* LINTED deliberate lack of effect */
    179 	(void)c;
    180 	/* LINTED deliberate lack of effect */
    181 	(void)m;
    182 	/* LINTED deliberate lack of effect */
    183 	(void)t;
    184 
    185 	CHECK_NOT_THREADED();
    186 
    187 	return (0);
    188 }
    189 
    190 int
    191 __libc_cond_catchall_stub(cond_t *c)
    192 {
    193 	/* LINTED deliberate lack of effect */
    194 	(void)c;
    195 
    196 	CHECK_NOT_THREADED();
    197 
    198 	return (0);
    199 }
    200 
    201 
    202 /* read-write locks */
    203 
    204 int	__libc_rwlock_init_stub(rwlock_t *, rwlockattr_t *);
    205 int	__libc_rwlock_catchall_stub(rwlock_t *);
    206 
    207 __weak_alias(__libc_rwlock_init,__libc_rwlock_init_stub)
    208 __weak_alias(__libc_rwlock_rdlock,__libc_rwlock_catchall_stub)
    209 __weak_alias(__libc_rwlock_wrlock,__libc_rwlock_catchall_stub)
    210 __weak_alias(__libc_rwlock_tryrdlock,__libc_rwlock_catchall_stub)
    211 __weak_alias(__libc_rwlock_trywrlock,__libc_rwlock_catchall_stub)
    212 __weak_alias(__libc_rwlock_unlock,__libc_rwlock_catchall_stub)
    213 __weak_alias(__libc_rwlock_destroy,__libc_rwlock_catchall_stub)
    214 
    215 int
    216 __libc_rwlock_init_stub(rwlock_t *l, rwlockattr_t *a)
    217 {
    218 	/* LINTED deliberate lack of effect */
    219 	(void)l;
    220 	/* LINTED deliberate lack of effect */
    221 	(void)a;
    222 
    223 	CHECK_NOT_THREADED();
    224 
    225 	return (0);
    226 }
    227 
    228 int
    229 __libc_rwlock_catchall_stub(rwlock_t *l)
    230 {
    231 	/* LINTED deliberate lack of effect */
    232 	(void)l;
    233 
    234 	CHECK_NOT_THREADED();
    235 
    236 	return (0);
    237 }
    238 
    239 
    240 /* thread-specific data */
    241 
    242 int	__libc_thr_keycreate_stub(thread_key_t *, void (*)(void *));
    243 int	__libc_thr_setspecific_stub(thread_key_t, const void *);
    244 void	*__libc_thr_getspecific_stub(thread_key_t);
    245 int	__libc_thr_keydelete_stub(thread_key_t);
    246 
    247 __weak_alias(__libc_thr_keycreate,__libc_thr_keycreate_stub)
    248 __weak_alias(__libc_thr_setspecific,__libc_thr_setspecific_stub)
    249 __weak_alias(__libc_thr_getspecific,__libc_thr_getspecific_stub)
    250 __weak_alias(__libc_thr_keydelete,__libc_thr_keydelete_stub)
    251 
    252 int
    253 __libc_thr_keycreate_stub(thread_key_t *k, void (*d)(void *))
    254 {
    255 	/* LINTED deliberate lack of effect */
    256 	(void)k;
    257 	/* LINTED deliberate lack of effect */
    258 	(void)d;
    259 
    260 	CHECK_NOT_THREADED();
    261 
    262 	return (0);
    263 }
    264 
    265 int
    266 __libc_thr_setspecific_stub(thread_key_t k, const void *v)
    267 {
    268 	/* LINTED deliberate lack of effect */
    269 	(void)k;
    270 	/* LINTED deliberate lack of effect */
    271 	(void)v;
    272 
    273 	DIE();
    274 
    275 	return (0);
    276 }
    277 
    278 void *
    279 __libc_thr_getspecific_stub(thread_key_t k)
    280 {
    281 	/* LINTED deliberate lack of effect */
    282 	(void)k;
    283 
    284 	DIE();
    285 
    286 	return (NULL);
    287 }
    288 
    289 int
    290 __libc_thr_keydelete_stub(thread_key_t k)
    291 {
    292 	/* LINTED deliberate lack of effect */
    293 	(void)k;
    294 
    295 	CHECK_NOT_THREADED();
    296 
    297 	return (0);
    298 }
    299 
    300 
    301 /* misc. */
    302 
    303 int	__libc_thr_once_stub(once_t *, void (*)(void));
    304 int	__libc_thr_sigsetmask_stub(int, const sigset_t *, sigset_t *);
    305 thr_t	__libc_thr_self_stub(void);
    306 int	*__libc_thr_errno_stub(void);
    307 
    308 __weak_alias(__libc_thr_once,__libc_thr_once_stub)
    309 __weak_alias(__libc_thr_sigsetmask,__libc_thr_sigsetmask_stub)
    310 __weak_alias(__libc_thr_self,__libc_thr_self_stub)
    311 __weak_alias(__libc_thr_errno,__libc_thr_errno_stub)
    312 
    313 int
    314 __libc_thr_once_stub(once_t *o, void (*r)(void))
    315 {
    316 
    317 	/* XXX Knowledge of libpthread types. */
    318 
    319 	if (o->pto_done == 0) {
    320 		(*r)();
    321 		o->pto_done = 1;
    322 	}
    323 
    324 	return (0);
    325 }
    326 
    327 int
    328 __libc_thr_sigsetmask_stub(int h, const sigset_t *s, sigset_t *o)
    329 {
    330 	/* LINTED deliberate lack of effect */
    331 	(void)h;
    332 	/* LINTED deliberate lack of effect */
    333 	(void)s;
    334 	/* LINTED deliberate lack of effect */
    335 	(void)o;
    336 
    337 	CHECK_NOT_THREADED();
    338 
    339 	/* XXX just use sigmask(2)?  abort? */
    340 
    341 	return (0);
    342 }
    343 
    344 thr_t
    345 __libc_thr_self_stub(void)
    346 {
    347 
    348 	DIE();
    349 
    350 	return (NULL);
    351 }
    352 
    353 int *
    354 __libc_thr_errno_stub(void)
    355 {
    356 
    357 	DIE();
    358 
    359 	return (NULL);
    360 }
    361 
    362 #endif /* _REENTRANT */
    363