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 * $FreeBSD$ 27 */ 28 29 #include <signal.h> 30 #include <pthread.h> 31 #include <pthread_np.h> 32 33 /* 34 * Weak symbols: All libc internal usage of these functions should 35 * use the weak symbol versions (_pthread_XXX). If libpthread is 36 * linked, it will override these functions with (non-weak) routines. 37 * The _pthread_XXX functions are provided solely for internal libc 38 * usage to avoid unwanted cancellation points and to differentiate 39 * between application locks and libc locks (threads holding the 40 * latter can't be allowed to exit/terminate). 41 */ 42 __weak_reference(_pthread_cond_init_stub, _pthread_cond_init); 43 __weak_reference(_pthread_cond_signal_stub, _pthread_cond_signal); 44 __weak_reference(_pthread_cond_wait_stub, _pthread_cond_wait); 45 __weak_reference(_pthread_getspecific_stub, _pthread_getspecific); 46 __weak_reference(_pthread_key_create_stub, _pthread_key_create); 47 __weak_reference(_pthread_key_delete_stub, _pthread_key_delete); 48 __weak_reference(_pthread_main_np_stub, _pthread_main_np); 49 __weak_reference(_pthread_mutex_destroy_stub, _pthread_mutex_destroy); 50 __weak_reference(_pthread_mutex_init_stub, _pthread_mutex_init); 51 __weak_reference(_pthread_mutex_lock_stub, _pthread_mutex_lock); 52 __weak_reference(_pthread_mutex_trylock_stub, _pthread_mutex_trylock); 53 __weak_reference(_pthread_mutex_unlock_stub, _pthread_mutex_unlock); 54 __weak_reference(_pthread_mutexattr_init_stub, _pthread_mutexattr_init); 55 __weak_reference(_pthread_mutexattr_destroy_stub, _pthread_mutexattr_destroy); 56 __weak_reference(_pthread_mutexattr_settype_stub, _pthread_mutexattr_settype); 57 __weak_reference(_pthread_once_stub, _pthread_once); 58 __weak_reference(_pthread_self_stub, _pthread_self); 59 __weak_reference(_pthread_rwlock_init_stub, _pthread_rwlock_init); 60 __weak_reference(_pthread_rwlock_rdlock_stub, _pthread_rwlock_rdlock); 61 __weak_reference(_pthread_rwlock_tryrdlock_stub, _pthread_rwlock_tryrdlock); 62 __weak_reference(_pthread_rwlock_trywrlock_stub, _pthread_rwlock_trywrloc); 63 __weak_reference(_pthread_rwlock_unlock_stub, _pthread_rwlock_unlock); 64 __weak_reference(_pthread_rwlock_wrlock_stub, _pthread_rwlock_wrlock); 65 __weak_reference(_pthread_setspecific_stub, _pthread_setspecific); 66 __weak_reference(_pthread_sigmask_stub, _pthread_sigmask); 67 68 /* Define a null pthread structure just to satisfy _pthread_self. */ 69 struct pthread { 70 }; 71 72 static struct pthread main_thread; 73 74 int 75 _pthread_cond_init_stub(pthread_cond_t *cond, 76 const pthread_condattr_t *cond_attr) 77 { 78 return (0); 79 } 80 81 int 82 _pthread_cond_signal_stub(pthread_cond_t *cond) 83 { 84 return (0); 85 } 86 87 int 88 _pthread_cond_wait_stub(pthread_cond_t *cond, pthread_mutex_t *mutex) 89 { 90 return (0); 91 } 92 93 void * 94 _pthread_getspecific_stub(pthread_key_t key) 95 { 96 return (NULL); 97 } 98 99 int 100 _pthread_key_create_stub(pthread_key_t *key, void (*destructor) (void *)) 101 { 102 return (0); 103 } 104 105 int 106 _pthread_key_delete_stub(pthread_key_t key) 107 { 108 return (0); 109 } 110 111 int 112 _pthread_main_np_stub() 113 { 114 return (-1); 115 } 116 117 int 118 _pthread_mutex_destroy_stub(pthread_mutex_t *mattr) 119 { 120 return (0); 121 } 122 123 int 124 _pthread_mutex_init_stub(pthread_mutex_t *mutex, const pthread_mutexattr_t *mattr) 125 { 126 return (0); 127 } 128 129 int 130 _pthread_mutex_lock_stub(pthread_mutex_t *mutex) 131 { 132 return (0); 133 } 134 135 int 136 _pthread_mutex_trylock_stub(pthread_mutex_t *mutex) 137 { 138 return (0); 139 } 140 141 int 142 _pthread_mutex_unlock_stub(pthread_mutex_t *mutex) 143 { 144 return (0); 145 } 146 147 int 148 _pthread_mutexattr_init_stub(pthread_mutexattr_t *mattr) 149 { 150 return (0); 151 } 152 153 int 154 _pthread_mutexattr_destroy_stub(pthread_mutexattr_t *mattr) 155 { 156 return (0); 157 } 158 159 int 160 _pthread_mutexattr_settype_stub(pthread_mutexattr_t *mattr, int type) 161 { 162 return (0); 163 } 164 165 int 166 _pthread_once_stub(pthread_once_t *once_control, void (*init_routine) (void)) 167 { 168 return (0); 169 } 170 171 int 172 _pthread_rwlock_init_stub(pthread_rwlock_t *rwlock, 173 const pthread_rwlockattr_t *attr) 174 { 175 return (0); 176 } 177 178 int 179 _pthread_rwlock_destroy_stub(pthread_rwlock_t *rwlock) 180 { 181 return (0); 182 } 183 184 int 185 _pthread_rwlock_rdlock_stub(pthread_rwlock_t *rwlock) 186 { 187 return (0); 188 } 189 190 int 191 _pthread_rwlock_tryrdlock_stub(pthread_rwlock_t *rwlock) 192 { 193 return (0); 194 } 195 196 int 197 _pthread_rwlock_trywrlock_stub(pthread_rwlock_t *rwlock) 198 { 199 return (0); 200 } 201 202 int 203 _pthread_rwlock_unlock_stub(pthread_rwlock_t *rwlock) 204 { 205 return (0); 206 } 207 208 int 209 _pthread_rwlock_wrlock_stub(pthread_rwlock_t *rwlock) 210 { 211 return (0); 212 } 213 214 pthread_t 215 _pthread_self_stub(void) 216 { 217 return (&main_thread); 218 } 219 220 int 221 _pthread_setspecific_stub(pthread_key_t key, const void *value) 222 { 223 return (0); 224 } 225 226 int 227 _pthread_sigmask_stub(int how, const sigset_t *set, sigset_t *oset) 228 { 229 return (0); 230 } 231