1 /* 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 33 static 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 60 MACRO(PTHREAD_PRIO_INHERIT); 61 MACRO(PTHREAD_PRIO_NONE); 62 #if !defined(__BIONIC__) 63 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*)); 119 FUNCTION(pthread_cond_destroy, int (*f)(pthread_cond_t*)); 120 FUNCTION(pthread_cond_init, int (*f)(pthread_cond_t*, const pthread_condattr_t*)); 121 FUNCTION(pthread_cond_signal, int (*f)(pthread_cond_t*)); 122 FUNCTION(pthread_cond_timedwait, int (*f)(pthread_cond_t*, pthread_mutex_t*, const struct timespec*)); 123 FUNCTION(pthread_cond_wait, int (*f)(pthread_cond_t*, pthread_mutex_t*)); 124 FUNCTION(pthread_condattr_destroy, int (*f)(pthread_condattr_t*)); 125 FUNCTION(pthread_condattr_getclock, int (*f)(const pthread_condattr_t*, clockid_t*)); 126 FUNCTION(pthread_condattr_getpshared, int (*f)(const pthread_condattr_t*, int*)); 127 FUNCTION(pthread_condattr_init, int (*f)(pthread_condattr_t*)); 128 FUNCTION(pthread_condattr_setclock, int (*f)(pthread_condattr_t*, clockid_t)); 129 FUNCTION(pthread_condattr_setpshared, int (*f)(pthread_condattr_t*, int)); 130 FUNCTION(pthread_create, int (*f)(pthread_t*, const pthread_attr_t*, void* (*)(void*), void*)); 131 FUNCTION(pthread_detach, int (*f)(pthread_t)); 132 FUNCTION(pthread_equal, int (*f)(pthread_t, pthread_t)); 133 FUNCTION(pthread_exit, void (*f)(void*)); 134 #if !defined(__BIONIC__) // Marked obsolescent. 135 FUNCTION(pthread_getconcurrency, int (*f)(void)); 136 #endif 137 FUNCTION(pthread_getcpuclockid, int (*f)(pthread_t, clockid_t*)); 138 FUNCTION(pthread_getschedparam, int (*f)(pthread_t, int*, struct sched_param*)); 139 FUNCTION(pthread_getspecific, void* (*f)(pthread_key_t)); 140 FUNCTION(pthread_join, int (*f)(pthread_t, void**)); 141 FUNCTION(pthread_key_create, int (*f)(pthread_key_t*, void (*)(void*))); 142 FUNCTION(pthread_key_delete, int (*f)(pthread_key_t)); 143 #if !defined(__BIONIC__) // No robust mutexes on Android. 144 FUNCTION(pthread_mutex_consistent, int (*f)(pthread_mutex_t*)); 145 #endif 146 FUNCTION(pthread_mutex_destroy, int (*f)(pthread_mutex_t*)); 147 #if !defined(__BIONIC__) // No robust mutexes on Android. 148 FUNCTION(pthread_mutex_getprioceiling, int (*f)(const pthread_mutex_t*, int*)); 149 #endif 150 FUNCTION(pthread_mutex_init, int (*f)(pthread_mutex_t*, const pthread_mutexattr_t*)); 151 FUNCTION(pthread_mutex_lock, int (*f)(pthread_mutex_t*)); 152 #if !defined(__BIONIC__) // No robust mutexes on Android. 153 FUNCTION(pthread_mutex_setprioceiling, int (*f)(pthread_mutex_t*, int, int*)); 154 #endif 155 FUNCTION(pthread_mutex_timedlock, int (*f)(pthread_mutex_t*, const struct timespec*)); 156 FUNCTION(pthread_mutex_trylock, int (*f)(pthread_mutex_t*)); 157 FUNCTION(pthread_mutex_unlock, int (*f)(pthread_mutex_t*)); 158 FUNCTION(pthread_mutexattr_destroy, int (*f)(pthread_mutexattr_t*)); 159 #if !defined(__BIONIC__) // No robust mutexes on Android. 160 FUNCTION(pthread_mutexattr_getprioceiling, int (*f)(const pthread_mutexattr_t*, int*)); 161 #endif 162 FUNCTION(pthread_mutexattr_getprotocol, int (*f)(const pthread_mutexattr_t*, int*)); 163 FUNCTION(pthread_mutexattr_getpshared, int (*f)(const pthread_mutexattr_t*, int*)); 164 #if !defined(__BIONIC__) // No robust mutexes on Android. 165 FUNCTION(pthread_mutexattr_getrobust, int (*f)(const pthread_mutexattr_t*, int*)); 166 #endif 167 FUNCTION(pthread_mutexattr_gettype, int (*f)(const pthread_mutexattr_t*, int*)); 168 FUNCTION(pthread_mutexattr_init, int (*f)(pthread_mutexattr_t*)); 169 #if !defined(__BIONIC__) // No robust mutexes on Android. 170 FUNCTION(pthread_mutexattr_setprioceiling, int (*f)(pthread_mutexattr_t*, int)); 171 #endif 172 FUNCTION(pthread_mutexattr_setprotocol, int (*f)(pthread_mutexattr_t*, int)); 173 FUNCTION(pthread_mutexattr_setpshared, int (*f)(pthread_mutexattr_t*, int)); 174 #if !defined(__BIONIC__) // No robust mutexes on Android. 175 FUNCTION(pthread_mutexattr_setrobust, int (*f)(pthread_mutexattr_t*, int)); 176 #endif 177 FUNCTION(pthread_mutexattr_settype, int (*f)(pthread_mutexattr_t*, int)); 178 FUNCTION(pthread_once, int (*f)(pthread_once_t*, void (*)(void))); 179 FUNCTION(pthread_rwlock_destroy, int (*f)(pthread_rwlock_t*)); 180 FUNCTION(pthread_rwlock_init, int (*f)(pthread_rwlock_t*, const pthread_rwlockattr_t*)); 181 FUNCTION(pthread_rwlock_rdlock, int (*f)(pthread_rwlock_t*)); 182 FUNCTION(pthread_rwlock_timedrdlock, int (*f)(pthread_rwlock_t*, const struct timespec*)); 183 FUNCTION(pthread_rwlock_timedwrlock, int (*f)(pthread_rwlock_t*, const struct timespec*)); 184 FUNCTION(pthread_rwlock_tryrdlock, int (*f)(pthread_rwlock_t*)); 185 FUNCTION(pthread_rwlock_trywrlock, int (*f)(pthread_rwlock_t*)); 186 FUNCTION(pthread_rwlock_unlock, int (*f)(pthread_rwlock_t*)); 187 FUNCTION(pthread_rwlock_wrlock, int (*f)(pthread_rwlock_t*)); 188 FUNCTION(pthread_rwlockattr_destroy, int (*f)(pthread_rwlockattr_t*)); 189 FUNCTION(pthread_rwlockattr_getpshared, int (*f)(const pthread_rwlockattr_t*, int*)); 190 FUNCTION(pthread_rwlockattr_init, int (*f)(pthread_rwlockattr_t*)); 191 FUNCTION(pthread_rwlockattr_setpshared, int (*f)(pthread_rwlockattr_t*, int)); 192 FUNCTION(pthread_self, pthread_t (*f)(void)); 193 #if !defined(__BIONIC__) // No thread cancellation on Android. 194 FUNCTION(pthread_setcancelstate, int (*f)(int, int*)); 195 FUNCTION(pthread_setcanceltype, int (*f)(int, int*)); 196 #endif 197 #if !defined(__BIONIC__) // Marked obsolescent. 198 FUNCTION(pthread_setconcurrency, int (*f)(int)); 199 #endif 200 FUNCTION(pthread_setschedparam, int (*f)(pthread_t, int, const struct sched_param*)); 201 FUNCTION(pthread_setschedprio, int (*f)(pthread_t, int)); 202 FUNCTION(pthread_setspecific, int (*f)(pthread_key_t, const void*)); 203 FUNCTION(pthread_spin_destroy, int (*f)(pthread_spinlock_t*)); 204 FUNCTION(pthread_spin_init, int (*f)(pthread_spinlock_t*, int)); 205 FUNCTION(pthread_spin_lock, int (*f)(pthread_spinlock_t*)); 206 FUNCTION(pthread_spin_trylock, int (*f)(pthread_spinlock_t*)); 207 FUNCTION(pthread_spin_unlock, int (*f)(pthread_spinlock_t*)); 208 #if !defined(__BIONIC__) // No thread cancellation on Android. 209 FUNCTION(pthread_testcancel, void (*f)(void)); 210 #endif 211 212 #if !defined(pthread_cleanup_pop) 213 #error pthread_cleanup_pop 214 #endif 215 #if !defined(pthread_cleanup_push) 216 #error pthread_cleanup_push 217 #endif 218 } 219 220 // POSIX: "Inclusion of the <pthread.h> header shall make symbols defined in the 221 // headers <sched.h> and <time.h> visible." 222 223 #define DO_NOT_INCLUDE_SCHED_H 224 #include "sched_h.c" 225 #define DO_NOT_INCLUDE_TIME_H 226 #include "time_h.c" 227