blob: 3713aff8e6afc7d4d3ed4b36ce23eca97569a6f3 [file] [log] [blame]
Elliott Hughes21b56eb2017-10-20 17:57:17 -07001/*
2 * Copyright (C) 2017 The Android Open Source Project
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 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the
13 * distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29#include <pthread.h>
30
31#include "header_checks.h"
32
33static void pthread_h() {
34 MACRO(PTHREAD_BARRIER_SERIAL_THREAD);
35
36#if !defined(__BIONIC__) // No thread cancellation on Android.
37 MACRO(PTHREAD_CANCEL_ASYNCHRONOUS);
38 MACRO(PTHREAD_CANCEL_ENABLE);
39 MACRO(PTHREAD_CANCEL_DEFERRED);
40 MACRO(PTHREAD_CANCEL_DISABLE);
41 MACRO(PTHREAD_CANCELED);
42#endif
43
44 MACRO(PTHREAD_CREATE_DETACHED);
45 MACRO(PTHREAD_CREATE_JOINABLE);
46 MACRO(PTHREAD_EXPLICIT_SCHED);
47 MACRO(PTHREAD_INHERIT_SCHED);
48 MACRO(PTHREAD_MUTEX_DEFAULT);
49 MACRO(PTHREAD_MUTEX_ERRORCHECK);
50 MACRO(PTHREAD_MUTEX_NORMAL);
51 MACRO(PTHREAD_MUTEX_RECURSIVE);
52
53#if !defined(__BIONIC__) // No robust mutexes on Android.
54 MACRO(PTHREAD_MUTEX_ROBUST);
55 MACRO(PTHREAD_MUTEX_STALLED);
56#endif
57
58 MACRO(PTHREAD_ONCE_INIT);
59
Elliott Hughes21b56eb2017-10-20 17:57:17 -070060 MACRO(PTHREAD_PRIO_INHERIT);
61 MACRO(PTHREAD_PRIO_NONE);
Elliott Hughes13550b82018-01-25 22:50:09 -080062#if !defined(__BIONIC__)
Elliott Hughes21b56eb2017-10-20 17:57:17 -070063 MACRO(PTHREAD_PRIO_PROTECT);
64#endif
65
66 MACRO(PTHREAD_PROCESS_SHARED);
67 MACRO(PTHREAD_PROCESS_PRIVATE);
68 MACRO(PTHREAD_SCOPE_PROCESS);
69 MACRO(PTHREAD_SCOPE_SYSTEM);
70
71 pthread_cond_t c0 = PTHREAD_COND_INITIALIZER;
72 pthread_mutex_t m0 = PTHREAD_MUTEX_INITIALIZER;
73 pthread_rwlock_t rw0 = PTHREAD_RWLOCK_INITIALIZER;
74
75 TYPE(pthread_attr_t);
76 TYPE(pthread_barrier_t);
77 TYPE(pthread_barrierattr_t);
78 TYPE(pthread_cond_t);
79 TYPE(pthread_condattr_t);
80 TYPE(pthread_key_t);
81 TYPE(pthread_mutex_t);
82 TYPE(pthread_mutexattr_t);
83 TYPE(pthread_once_t);
84 TYPE(pthread_rwlock_t);
85 TYPE(pthread_rwlockattr_t);
86 TYPE(pthread_spinlock_t);
87 TYPE(pthread_t);
88
89 FUNCTION(pthread_atfork, int (*f)(void (*)(void), void (*)(void), void (*)(void)));
90 FUNCTION(pthread_attr_destroy, int (*f)(pthread_attr_t*));
91 FUNCTION(pthread_attr_getdetachstate, int (*f)(const pthread_attr_t*, int*));
92 FUNCTION(pthread_attr_getguardsize, int (*f)(const pthread_attr_t*, size_t*));
93 FUNCTION(pthread_attr_getinheritsched, int (*f)(const pthread_attr_t*, int*));
94 FUNCTION(pthread_attr_getschedparam, int (*f)(const pthread_attr_t*, struct sched_param*));
95 FUNCTION(pthread_attr_getschedpolicy, int (*f)(const pthread_attr_t*, int*));
96 FUNCTION(pthread_attr_getscope, int (*f)(const pthread_attr_t*, int*));
97 FUNCTION(pthread_attr_getstack, int (*f)(const pthread_attr_t*, void**, size_t*));
98 FUNCTION(pthread_attr_getstacksize, int (*f)(const pthread_attr_t*, size_t*));
99 FUNCTION(pthread_attr_init, int (*f)(pthread_attr_t*));
100 FUNCTION(pthread_attr_setdetachstate, int (*f)(pthread_attr_t*, int));
101 FUNCTION(pthread_attr_setguardsize, int (*f)(pthread_attr_t*, size_t));
102 FUNCTION(pthread_attr_setinheritsched, int (*f)(pthread_attr_t*, int));
103 FUNCTION(pthread_attr_setschedparam, int (*f)(pthread_attr_t*, const struct sched_param*));
104 FUNCTION(pthread_attr_setschedpolicy, int (*f)(pthread_attr_t*, int));
105 FUNCTION(pthread_attr_setscope, int (*f)(pthread_attr_t*, int));
106 FUNCTION(pthread_attr_setstack, int (*f)(pthread_attr_t*, void*, size_t));
107 FUNCTION(pthread_attr_setstacksize, int (*f)(pthread_attr_t*, size_t));
108 FUNCTION(pthread_barrier_destroy, int (*f)(pthread_barrier_t*));
109 FUNCTION(pthread_barrier_init, int (*f)(pthread_barrier_t*, const pthread_barrierattr_t*, unsigned));
110 FUNCTION(pthread_barrier_wait, int (*f)(pthread_barrier_t*));
111 FUNCTION(pthread_barrierattr_destroy, int (*f)(pthread_barrierattr_t*));
112 FUNCTION(pthread_barrierattr_getpshared, int (*f)(const pthread_barrierattr_t*, int*));
113 FUNCTION(pthread_barrierattr_init, int (*f)(pthread_barrierattr_t*));
114 FUNCTION(pthread_barrierattr_setpshared, int (*f)(pthread_barrierattr_t*, int));
115#if !defined(__BIONIC__) // No thread cancellation on Android.
116 FUNCTION(pthread_cancel, int (*f)(pthread_t));
117#endif
118 FUNCTION(pthread_cond_broadcast, int (*f)(pthread_cond_t*));
Elliott Hughesf4d57ac2025-01-28 14:22:12 -0800119#if !defined(__GLIBC__) // Our glibc is too old.
120 FUNCTION(pthread_cond_clockwait, int (*f)(pthread_cond_t*, pthread_mutex_t*, clockid_t, const struct timespec*));
121#endif
Elliott Hughes21b56eb2017-10-20 17:57:17 -0700122 FUNCTION(pthread_cond_destroy, int (*f)(pthread_cond_t*));
123 FUNCTION(pthread_cond_init, int (*f)(pthread_cond_t*, const pthread_condattr_t*));
124 FUNCTION(pthread_cond_signal, int (*f)(pthread_cond_t*));
125 FUNCTION(pthread_cond_timedwait, int (*f)(pthread_cond_t*, pthread_mutex_t*, const struct timespec*));
126 FUNCTION(pthread_cond_wait, int (*f)(pthread_cond_t*, pthread_mutex_t*));
127 FUNCTION(pthread_condattr_destroy, int (*f)(pthread_condattr_t*));
128 FUNCTION(pthread_condattr_getclock, int (*f)(const pthread_condattr_t*, clockid_t*));
129 FUNCTION(pthread_condattr_getpshared, int (*f)(const pthread_condattr_t*, int*));
130 FUNCTION(pthread_condattr_init, int (*f)(pthread_condattr_t*));
131 FUNCTION(pthread_condattr_setclock, int (*f)(pthread_condattr_t*, clockid_t));
132 FUNCTION(pthread_condattr_setpshared, int (*f)(pthread_condattr_t*, int));
133 FUNCTION(pthread_create, int (*f)(pthread_t*, const pthread_attr_t*, void* (*)(void*), void*));
134 FUNCTION(pthread_detach, int (*f)(pthread_t));
135 FUNCTION(pthread_equal, int (*f)(pthread_t, pthread_t));
136 FUNCTION(pthread_exit, void (*f)(void*));
137#if !defined(__BIONIC__) // Marked obsolescent.
138 FUNCTION(pthread_getconcurrency, int (*f)(void));
139#endif
140 FUNCTION(pthread_getcpuclockid, int (*f)(pthread_t, clockid_t*));
141 FUNCTION(pthread_getschedparam, int (*f)(pthread_t, int*, struct sched_param*));
142 FUNCTION(pthread_getspecific, void* (*f)(pthread_key_t));
143 FUNCTION(pthread_join, int (*f)(pthread_t, void**));
144 FUNCTION(pthread_key_create, int (*f)(pthread_key_t*, void (*)(void*)));
145 FUNCTION(pthread_key_delete, int (*f)(pthread_key_t));
Elliott Hughesf4d57ac2025-01-28 14:22:12 -0800146#if !defined(__GLIBC__) // Our glibc is too old.
147 FUNCTION(pthread_mutex_clocklock, int (*f)(pthread_mutex_t*, clockid_t, const struct timespec*));
148#endif
Elliott Hughes21b56eb2017-10-20 17:57:17 -0700149#if !defined(__BIONIC__) // No robust mutexes on Android.
150 FUNCTION(pthread_mutex_consistent, int (*f)(pthread_mutex_t*));
151#endif
152 FUNCTION(pthread_mutex_destroy, int (*f)(pthread_mutex_t*));
153#if !defined(__BIONIC__) // No robust mutexes on Android.
154 FUNCTION(pthread_mutex_getprioceiling, int (*f)(const pthread_mutex_t*, int*));
155#endif
156 FUNCTION(pthread_mutex_init, int (*f)(pthread_mutex_t*, const pthread_mutexattr_t*));
157 FUNCTION(pthread_mutex_lock, int (*f)(pthread_mutex_t*));
158#if !defined(__BIONIC__) // No robust mutexes on Android.
159 FUNCTION(pthread_mutex_setprioceiling, int (*f)(pthread_mutex_t*, int, int*));
160#endif
161 FUNCTION(pthread_mutex_timedlock, int (*f)(pthread_mutex_t*, const struct timespec*));
162 FUNCTION(pthread_mutex_trylock, int (*f)(pthread_mutex_t*));
163 FUNCTION(pthread_mutex_unlock, int (*f)(pthread_mutex_t*));
164 FUNCTION(pthread_mutexattr_destroy, int (*f)(pthread_mutexattr_t*));
165#if !defined(__BIONIC__) // No robust mutexes on Android.
166 FUNCTION(pthread_mutexattr_getprioceiling, int (*f)(const pthread_mutexattr_t*, int*));
Elliott Hughes21b56eb2017-10-20 17:57:17 -0700167#endif
Elliott Hughes13550b82018-01-25 22:50:09 -0800168 FUNCTION(pthread_mutexattr_getprotocol, int (*f)(const pthread_mutexattr_t*, int*));
Elliott Hughes21b56eb2017-10-20 17:57:17 -0700169 FUNCTION(pthread_mutexattr_getpshared, int (*f)(const pthread_mutexattr_t*, int*));
170#if !defined(__BIONIC__) // No robust mutexes on Android.
171 FUNCTION(pthread_mutexattr_getrobust, int (*f)(const pthread_mutexattr_t*, int*));
172#endif
173 FUNCTION(pthread_mutexattr_gettype, int (*f)(const pthread_mutexattr_t*, int*));
174 FUNCTION(pthread_mutexattr_init, int (*f)(pthread_mutexattr_t*));
175#if !defined(__BIONIC__) // No robust mutexes on Android.
176 FUNCTION(pthread_mutexattr_setprioceiling, int (*f)(pthread_mutexattr_t*, int));
Elliott Hughes21b56eb2017-10-20 17:57:17 -0700177#endif
Elliott Hughes13550b82018-01-25 22:50:09 -0800178 FUNCTION(pthread_mutexattr_setprotocol, int (*f)(pthread_mutexattr_t*, int));
Elliott Hughes21b56eb2017-10-20 17:57:17 -0700179 FUNCTION(pthread_mutexattr_setpshared, int (*f)(pthread_mutexattr_t*, int));
180#if !defined(__BIONIC__) // No robust mutexes on Android.
181 FUNCTION(pthread_mutexattr_setrobust, int (*f)(pthread_mutexattr_t*, int));
182#endif
183 FUNCTION(pthread_mutexattr_settype, int (*f)(pthread_mutexattr_t*, int));
184 FUNCTION(pthread_once, int (*f)(pthread_once_t*, void (*)(void)));
Elliott Hughesf4d57ac2025-01-28 14:22:12 -0800185#if !defined(__GLIBC__) // Our glibc is too old.
186 FUNCTION(pthread_rwlock_clockrdlock, int (*f)(pthread_rwlock_t*, clockid_t, const struct timespec*));
187 FUNCTION(pthread_rwlock_clockwrlock, int (*f)(pthread_rwlock_t*, clockid_t, const struct timespec*));
188#endif
Elliott Hughes21b56eb2017-10-20 17:57:17 -0700189 FUNCTION(pthread_rwlock_destroy, int (*f)(pthread_rwlock_t*));
190 FUNCTION(pthread_rwlock_init, int (*f)(pthread_rwlock_t*, const pthread_rwlockattr_t*));
191 FUNCTION(pthread_rwlock_rdlock, int (*f)(pthread_rwlock_t*));
192 FUNCTION(pthread_rwlock_timedrdlock, int (*f)(pthread_rwlock_t*, const struct timespec*));
193 FUNCTION(pthread_rwlock_timedwrlock, int (*f)(pthread_rwlock_t*, const struct timespec*));
194 FUNCTION(pthread_rwlock_tryrdlock, int (*f)(pthread_rwlock_t*));
195 FUNCTION(pthread_rwlock_trywrlock, int (*f)(pthread_rwlock_t*));
196 FUNCTION(pthread_rwlock_unlock, int (*f)(pthread_rwlock_t*));
197 FUNCTION(pthread_rwlock_wrlock, int (*f)(pthread_rwlock_t*));
198 FUNCTION(pthread_rwlockattr_destroy, int (*f)(pthread_rwlockattr_t*));
199 FUNCTION(pthread_rwlockattr_getpshared, int (*f)(const pthread_rwlockattr_t*, int*));
200 FUNCTION(pthread_rwlockattr_init, int (*f)(pthread_rwlockattr_t*));
201 FUNCTION(pthread_rwlockattr_setpshared, int (*f)(pthread_rwlockattr_t*, int));
202 FUNCTION(pthread_self, pthread_t (*f)(void));
203#if !defined(__BIONIC__) // No thread cancellation on Android.
204 FUNCTION(pthread_setcancelstate, int (*f)(int, int*));
205 FUNCTION(pthread_setcanceltype, int (*f)(int, int*));
206#endif
207#if !defined(__BIONIC__) // Marked obsolescent.
208 FUNCTION(pthread_setconcurrency, int (*f)(int));
209#endif
210 FUNCTION(pthread_setschedparam, int (*f)(pthread_t, int, const struct sched_param*));
211 FUNCTION(pthread_setschedprio, int (*f)(pthread_t, int));
212 FUNCTION(pthread_setspecific, int (*f)(pthread_key_t, const void*));
213 FUNCTION(pthread_spin_destroy, int (*f)(pthread_spinlock_t*));
214 FUNCTION(pthread_spin_init, int (*f)(pthread_spinlock_t*, int));
215 FUNCTION(pthread_spin_lock, int (*f)(pthread_spinlock_t*));
216 FUNCTION(pthread_spin_trylock, int (*f)(pthread_spinlock_t*));
217 FUNCTION(pthread_spin_unlock, int (*f)(pthread_spinlock_t*));
218#if !defined(__BIONIC__) // No thread cancellation on Android.
219 FUNCTION(pthread_testcancel, void (*f)(void));
220#endif
221
222#if !defined(pthread_cleanup_pop)
223#error pthread_cleanup_pop
224#endif
225#if !defined(pthread_cleanup_push)
226#error pthread_cleanup_push
227#endif
228}
229
230// POSIX: "Inclusion of the <pthread.h> header shall make symbols defined in the
231// headers <sched.h> and <time.h> visible."
232
233#define DO_NOT_INCLUDE_SCHED_H
234#include "sched_h.c"
235#define DO_NOT_INCLUDE_TIME_H
236#include "time_h.c"