xref: /dflybsd-src/lib/libc/gen/_pthread_stubs.c (revision b792147d2d9a225bb5c9a0d9ab69d4dbf010979e)
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: src/lib/libc/gen/_pthread_stubs.c,v 1.5 2001/06/11 23:18:22 iedowse Exp $
27  * $DragonFly: src/lib/libc/gen/_pthread_stubs.c,v 1.4 2005/05/09 12:43:40 davidxu Exp $
28  */
29 
30 #include <sys/cdefs.h>
31 #include <stdlib.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 
43 #define WR(f, n)			\
44     __weak_reference(f, _ ## n);	\
45     __weak_reference(f, n)
46 
47 
48 WR(stub_zero, pthread_atfork);
49 WR(stub_zero, pthread_attr_destroy);
50 WR(stub_zero, pthread_attr_get_np);
51 WR(stub_zero, pthread_attr_getdetachstate);
52 WR(stub_zero, pthread_attr_getinheritsched);
53 WR(stub_zero, pthread_attr_getschedparam);
54 WR(stub_zero, pthread_attr_getschedpolicy);
55 WR(stub_zero, pthread_attr_getscope);
56 WR(stub_zero, pthread_attr_getstack);
57 WR(stub_zero, pthread_attr_getstackaddr);
58 WR(stub_zero, pthread_attr_getstacksize);
59 WR(stub_zero, pthread_attr_init);
60 WR(stub_zero, pthread_attr_setcreatesuspend_np);
61 WR(stub_zero, pthread_attr_setdetachstate);
62 WR(stub_zero, pthread_attr_setinheritsched);
63 WR(stub_zero, pthread_attr_setschedparam);
64 WR(stub_zero, pthread_attr_setschedpolicy);
65 WR(stub_zero, pthread_attr_setscope);
66 WR(stub_zero, pthread_attr_setstack);
67 WR(stub_zero, pthread_attr_setstackaddr);
68 WR(stub_zero, pthread_attr_setstacksize);
69 WR(stub_zero, pthread_cancel);
70 WR(stub_zero, pthread_cleanup_pop);
71 WR(stub_zero, pthread_cleanup_push);
72 WR(stub_zero, pthread_cond_broadcast);
73 WR(stub_zero, pthread_cond_destroy);
74 WR(stub_zero, pthread_cond_init);
75 WR(stub_zero, pthread_cond_signal);
76 WR(stub_zero, pthread_cond_timedwait);
77 WR(stub_zero, pthread_cond_wait);
78 WR(stub_zero, pthread_condattr_destroy);
79 WR(stub_zero, pthread_condattr_init);
80 WR(stub_zero, pthread_detach);
81 WR(stub_true, pthread_equal);
82 WR(stub_exit, pthread_exit);
83 WR(stub_zero, pthread_getconcurrency);
84 WR(stub_zero, pthread_getprio);
85 WR(stub_zero, pthread_getschedparam);
86 WR(stub_null, pthread_getspecific);
87 WR(stub_zero, pthread_join);
88 WR(stub_zero, pthread_key_create);
89 WR(stub_zero, pthread_key_delete);
90 WR(stub_zero, pthread_kill);
91 WR(stub_main, pthread_main_np);
92 WR(stub_zero, pthread_multi_np);
93 WR(stub_zero, pthread_mutex_destroy);
94 WR(stub_zero, pthread_mutex_getprioceiling);
95 WR(stub_zero, pthread_mutex_init);
96 WR(stub_zero, pthread_mutex_lock);
97 WR(stub_zero, pthread_mutex_setprioceiling);
98 WR(stub_zero, pthread_mutex_trylock);
99 WR(stub_zero, pthread_mutex_unlock);
100 WR(stub_zero, pthread_mutexattr_destroy);
101 WR(stub_zero, pthread_mutexattr_getkind_np);
102 WR(stub_zero, pthread_mutexattr_getprioceiling);
103 WR(stub_zero, pthread_mutexattr_getprotocol);
104 WR(stub_zero, pthread_mutexattr_getpshared);
105 WR(stub_zero, pthread_mutexattr_gettype);
106 WR(stub_zero, pthread_mutexattr_init);
107 WR(stub_zero, pthread_mutexattr_setkind_np);
108 WR(stub_zero, pthread_mutexattr_setprioceiling);
109 WR(stub_zero, pthread_mutexattr_setprotocol);
110 WR(stub_zero, pthread_mutexattr_setpshared);
111 WR(stub_zero, pthread_mutexattr_settype);
112 WR(stub_zero, pthread_once);
113 WR(stub_zero, pthread_resume_all_np);
114 WR(stub_zero, pthread_resume_np);
115 WR(stub_zero, pthread_rwlock_destroy);
116 WR(stub_zero, pthread_rwlock_init);
117 WR(stub_zero, pthread_rwlock_rdlock);
118 WR(stub_zero, pthread_rwlock_tryrdlock);
119 WR(stub_zero, pthread_rwlock_trywrlock);
120 WR(stub_zero, pthread_rwlock_unlock);
121 WR(stub_zero, pthread_rwlock_wrlock);
122 WR(stub_zero, pthread_rwlockattr_destroy);
123 WR(stub_zero, pthread_rwlockattr_getpshared);
124 WR(stub_zero, pthread_rwlockattr_init);
125 WR(stub_zero, pthread_rwlockattr_setpshared);
126 WR(stub_self, pthread_self);
127 WR(stub_zero, pthread_set_name_np);
128 WR(stub_zero, pthread_setcancelstate);
129 WR(stub_zero, pthread_setcanceltype);
130 WR(stub_zero, pthread_setconcurrency);
131 WR(stub_zero, pthread_setprio);
132 WR(stub_zero, pthread_setschedparam);
133 WR(stub_zero, pthread_setspecific);
134 WR(stub_zero, pthread_sigmask);
135 WR(stub_zero, pthread_single_np);
136 WR(stub_zero, pthread_suspend_all_np);
137 WR(stub_zero, pthread_suspend_np);
138 WR(stub_zero, pthread_switch_add_np);
139 WR(stub_zero, pthread_switch_delete_np);
140 WR(stub_zero, pthread_testcancel);
141 WR(stub_zero, pthread_yield);
142 WR(stub_zero, sched_yield);
143 WR(stub_zero, sem_close);
144 WR(stub_zero, sem_destroy);
145 WR(stub_zero, sem_getvalue);
146 WR(stub_zero, sem_init);
147 WR(stub_zero, sem_open);
148 WR(stub_zero, sem_post);
149 WR(stub_zero, sem_trywait);
150 WR(stub_zero, sem_unlink);
151 WR(stub_zero, sem_wait);
152 
153 
154 static int __used
155 stub_zero(void)
156 {
157 	return (0);
158 }
159 
160 static void * __used
161 stub_null(void)
162 {
163 	return (NULL);
164 }
165 
166 static void * __used
167 stub_self(void)
168 {
169 	static struct {} main_thread;
170 
171 	return (&main_thread);
172 }
173 
174 static int __used
175 stub_main(void)
176 {
177 	return (-1);
178 }
179 
180 static int __used
181 stub_true(void)
182 {
183 	return (1);
184 }
185 
186 static void __used
187 stub_exit(void)
188 {
189 	exit(0);
190 }
191