xref: /freebsd/lib/libc/gen/_pthread_stubs.c (revision 42c159fe388a3765f69860c84183700af37aca8a)
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_getspecific_stub,	_pthread_getspecific);
47 __weak_reference(_pthread_key_create_stub,	_pthread_key_create);
48 __weak_reference(_pthread_key_delete_stub,	_pthread_key_delete);
49 __weak_reference(_pthread_main_np_stub,		_pthread_main_np);
50 __weak_reference(_pthread_mutex_destroy_stub,	_pthread_mutex_destroy);
51 __weak_reference(_pthread_mutex_init_stub,	_pthread_mutex_init);
52 __weak_reference(_pthread_mutex_lock_stub,	_pthread_mutex_lock);
53 __weak_reference(_pthread_mutex_trylock_stub,	_pthread_mutex_trylock);
54 __weak_reference(_pthread_mutex_unlock_stub,	_pthread_mutex_unlock);
55 __weak_reference(_pthread_mutexattr_init_stub,	_pthread_mutexattr_init);
56 __weak_reference(_pthread_mutexattr_destroy_stub, _pthread_mutexattr_destroy);
57 __weak_reference(_pthread_mutexattr_settype_stub, _pthread_mutexattr_settype);
58 __weak_reference(_pthread_once_stub,		_pthread_once);
59 __weak_reference(_pthread_self_stub,		_pthread_self);
60 __weak_reference(_pthread_rwlock_init_stub,	_pthread_rwlock_init);
61 __weak_reference(_pthread_rwlock_rdlock_stub,	_pthread_rwlock_rdlock);
62 __weak_reference(_pthread_rwlock_tryrdlock_stub, _pthread_rwlock_tryrdlock);
63 __weak_reference(_pthread_rwlock_trywrlock_stub, _pthread_rwlock_trywrloc);
64 __weak_reference(_pthread_rwlock_unlock_stub,	_pthread_rwlock_unlock);
65 __weak_reference(_pthread_rwlock_wrlock_stub,	_pthread_rwlock_wrlock);
66 __weak_reference(_pthread_setspecific_stub,	_pthread_setspecific);
67 __weak_reference(_pthread_sigmask_stub,		_pthread_sigmask);
68 
69 /* Define a null pthread structure just to satisfy _pthread_self. */
70 struct pthread {
71 };
72 
73 static struct pthread	main_thread;
74 
75 int
76 _pthread_cond_init_stub(pthread_cond_t *cond,
77     const pthread_condattr_t *cond_attr)
78 {
79 	return (0);
80 }
81 
82 int
83 _pthread_cond_signal_stub(pthread_cond_t *cond)
84 {
85 	return (0);
86 }
87 
88 int
89 _pthread_cond_wait_stub(pthread_cond_t *cond, pthread_mutex_t *mutex)
90 {
91 	return (0);
92 }
93 
94 void *
95 _pthread_getspecific_stub(pthread_key_t key)
96 {
97 	return (NULL);
98 }
99 
100 int
101 _pthread_key_create_stub(pthread_key_t *key, void (*destructor) (void *))
102 {
103 	return (0);
104 }
105 
106 int
107 _pthread_key_delete_stub(pthread_key_t key)
108 {
109 	return (0);
110 }
111 
112 int
113 _pthread_main_np_stub()
114 {
115 	return (-1);
116 }
117 
118 int
119 _pthread_mutex_destroy_stub(pthread_mutex_t *mattr)
120 {
121 	return (0);
122 }
123 
124 int
125 _pthread_mutex_init_stub(pthread_mutex_t *mutex, const pthread_mutexattr_t *mattr)
126 {
127 	return (0);
128 }
129 
130 int
131 _pthread_mutex_lock_stub(pthread_mutex_t *mutex)
132 {
133 	return (0);
134 }
135 
136 int
137 _pthread_mutex_trylock_stub(pthread_mutex_t *mutex)
138 {
139 	return (0);
140 }
141 
142 int
143 _pthread_mutex_unlock_stub(pthread_mutex_t *mutex)
144 {
145 	return (0);
146 }
147 
148 int
149 _pthread_mutexattr_init_stub(pthread_mutexattr_t *mattr)
150 {
151 	return (0);
152 }
153 
154 int
155 _pthread_mutexattr_destroy_stub(pthread_mutexattr_t *mattr)
156 {
157 	return (0);
158 }
159 
160 int
161 _pthread_mutexattr_settype_stub(pthread_mutexattr_t *mattr, int type)
162 {
163 	return (0);
164 }
165 
166 int
167 _pthread_once_stub(pthread_once_t *once_control, void (*init_routine) (void))
168 {
169 	return (0);
170 }
171 
172 int
173 _pthread_rwlock_init_stub(pthread_rwlock_t *rwlock,
174     const pthread_rwlockattr_t *attr)
175 {
176 	return (0);
177 }
178 
179 int
180 _pthread_rwlock_destroy_stub(pthread_rwlock_t *rwlock)
181 {
182 	return (0);
183 }
184 
185 int
186 _pthread_rwlock_rdlock_stub(pthread_rwlock_t *rwlock)
187 {
188 	return (0);
189 }
190 
191 int
192 _pthread_rwlock_tryrdlock_stub(pthread_rwlock_t *rwlock)
193 {
194 	return (0);
195 }
196 
197 int
198 _pthread_rwlock_trywrlock_stub(pthread_rwlock_t *rwlock)
199 {
200 	return (0);
201 }
202 
203 int
204 _pthread_rwlock_unlock_stub(pthread_rwlock_t *rwlock)
205 {
206 	return (0);
207 }
208 
209 int
210 _pthread_rwlock_wrlock_stub(pthread_rwlock_t *rwlock)
211 {
212 	return (0);
213 }
214 
215 pthread_t
216 _pthread_self_stub(void)
217 {
218 	return (&main_thread);
219 }
220 
221 int
222 _pthread_setspecific_stub(pthread_key_t key, const void *value)
223 {
224 	return (0);
225 }
226 
227 int
228 _pthread_sigmask_stub(int how, const sigset_t *set, sigset_t *oset)
229 {
230 	return (0);
231 }
232