sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1 | |
| 2 | /* This is a replacement for the standard libpthread.so. It is loaded |
| 3 | as part of the client's image (if required) and directs pthread |
| 4 | calls through to Valgrind's request mechanism. |
| 5 | |
| 6 | A couple of caveats. |
| 7 | |
| 8 | 1. Since it's a binary-compatible replacement for an existing library, |
| 9 | we must take care to used exactly the same data layouts, etc, as |
| 10 | the standard pthread.so does. |
| 11 | |
| 12 | 2. Since this runs as part of the client, there are no specific |
| 13 | restrictions on what headers etc we can include, so long as |
| 14 | this libpthread.so does not end up having dependencies on .so's |
| 15 | which the real one doesn't. |
| 16 | |
| 17 | Later ... it appears we cannot call file-related stuff in libc here, |
| 18 | perhaps fair enough. Be careful what you call from here. Even exit() |
| 19 | doesn't work (gives infinite recursion and then stack overflow); hence |
| 20 | myexit(). Also fprintf doesn't seem safe. |
| 21 | */ |
| 22 | |
| 23 | #include "valgrind.h" /* For the request-passing mechanism */ |
| 24 | #include "vg_include.h" /* For the VG_USERREQ__* constants */ |
| 25 | |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 26 | #include <unistd.h> |
| 27 | #include <string.h> |
sewardj | 2a1dcce | 2002-04-22 12:45:25 +0000 | [diff] [blame] | 28 | #ifdef GLIBC_2_1 |
| 29 | #include <sys/time.h> |
| 30 | #endif |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 31 | |
| 32 | /* --------------------------------------------------------------------- |
| 33 | Helpers. We have to be pretty self-sufficient. |
| 34 | ------------------------------------------------------------------ */ |
| 35 | |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 36 | /* Number of times any given error message is printed. */ |
| 37 | #define N_MOANS 3 |
| 38 | |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 39 | /* Extract from Valgrind the value of VG_(clo_trace_pthread_level). |
| 40 | Returns 0 (none) if not running on Valgrind. */ |
| 41 | static |
| 42 | int get_pt_trace_level ( void ) |
| 43 | { |
| 44 | int res; |
| 45 | VALGRIND_MAGIC_SEQUENCE(res, 0 /* default */, |
| 46 | VG_USERREQ__GET_PTHREAD_TRACE_LEVEL, |
| 47 | 0, 0, 0, 0); |
| 48 | return res; |
| 49 | } |
| 50 | |
| 51 | |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 52 | static |
| 53 | void myexit ( int arg ) |
| 54 | { |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 55 | int __res; |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 56 | __asm__ volatile ("movl %%ecx, %%ebx ; int $0x80" |
| 57 | : "=a" (__res) |
| 58 | : "0" (__NR_exit), |
| 59 | "c" (arg) ); |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 60 | /* We don't bother to mention the fact that this asm trashes %ebx, |
| 61 | since it won't return. If you ever do let it return ... fix |
| 62 | this! */ |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | |
| 66 | /* Give up without using printf etc, since they seem to give |
| 67 | segfaults. */ |
sewardj | 604ec3c | 2002-04-18 22:38:41 +0000 | [diff] [blame] | 68 | static __inline__ |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 69 | void ensure_valgrind ( char* caller ) |
| 70 | { |
| 71 | char* str; |
| 72 | int is_valgrind = RUNNING_ON_VALGRIND; |
| 73 | if (!is_valgrind) { |
| 74 | str = "\nvalgrind-ed process: vg_libpthread.so: " |
| 75 | "pthread call when\n"; |
| 76 | write(2, str, strlen(str)); |
| 77 | str = "not running on valgrind; aborting! " |
| 78 | "This is probably a bug in\n"; |
| 79 | write(2, str, strlen(str)); |
| 80 | str = "valgrind. Please report it to me at: " |
| 81 | "jseward@acm.org. Thanks.\n"; |
| 82 | write(2, str, strlen(str)); |
| 83 | str = "unexpectedly called function is: "; |
| 84 | write(2, str, strlen(str)); |
| 85 | write(2, caller, strlen(caller)); |
| 86 | str = "\n\n"; |
| 87 | write(2, str, strlen(str)); |
| 88 | myexit(1); |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | |
| 93 | static |
sewardj | 3b5d886 | 2002-04-20 13:53:23 +0000 | [diff] [blame] | 94 | __attribute__((noreturn)) |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 95 | void barf ( char* str ) |
| 96 | { |
| 97 | char buf[100]; |
| 98 | buf[0] = 0; |
| 99 | strcat(buf, "\nvg_libpthread.so: "); |
| 100 | strcat(buf, str); |
| 101 | strcat(buf, "\n\n"); |
| 102 | write(2, buf, strlen(buf)); |
| 103 | myexit(1); |
sewardj | 3b5d886 | 2002-04-20 13:53:23 +0000 | [diff] [blame] | 104 | /* We have to persuade gcc into believing this doesn't return. */ |
| 105 | while (1) { }; |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | |
sewardj | 2a3d28c | 2002-04-14 13:27:00 +0000 | [diff] [blame] | 109 | static void ignored ( char* msg ) |
| 110 | { |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 111 | if (get_pt_trace_level() >= 0) { |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 112 | char* ig = "vg_libpthread.so: IGNORED call to: "; |
| 113 | write(2, ig, strlen(ig)); |
| 114 | write(2, msg, strlen(msg)); |
| 115 | ig = "\n"; |
| 116 | write(2, ig, strlen(ig)); |
| 117 | } |
sewardj | 2a3d28c | 2002-04-14 13:27:00 +0000 | [diff] [blame] | 118 | } |
| 119 | |
sewardj | 30671ff | 2002-04-21 00:13:57 +0000 | [diff] [blame] | 120 | static void kludged ( char* msg ) |
| 121 | { |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 122 | if (get_pt_trace_level() >= 0) { |
sewardj | 30671ff | 2002-04-21 00:13:57 +0000 | [diff] [blame] | 123 | char* ig = "vg_libpthread.so: KLUDGED call to: "; |
| 124 | write(2, ig, strlen(ig)); |
| 125 | write(2, msg, strlen(msg)); |
| 126 | ig = "\n"; |
| 127 | write(2, ig, strlen(ig)); |
| 128 | } |
| 129 | } |
| 130 | |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 131 | void vgPlain_unimp ( char* what ) |
| 132 | { |
| 133 | char* ig = "vg_libpthread.so: UNIMPLEMENTED FUNCTION: "; |
| 134 | write(2, ig, strlen(ig)); |
| 135 | write(2, what, strlen(what)); |
| 136 | ig = "\n"; |
| 137 | write(2, ig, strlen(ig)); |
| 138 | barf("Please report this bug to me at: jseward@acm.org"); |
| 139 | } |
| 140 | |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 141 | |
| 142 | /* --------------------------------------------------------------------- |
| 143 | Pass pthread_ calls to Valgrind's request mechanism. |
| 144 | ------------------------------------------------------------------ */ |
| 145 | |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 146 | #include <pthread.h> |
| 147 | #include <stdio.h> |
| 148 | #include <errno.h> |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 149 | #include <assert.h> |
| 150 | #include <sys/time.h> /* gettimeofday */ |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 151 | |
| 152 | /* --------------------------------------------------- |
| 153 | THREAD ATTRIBUTES |
| 154 | ------------------------------------------------ */ |
| 155 | |
sewardj | 6af4b5d | 2002-04-16 04:40:49 +0000 | [diff] [blame] | 156 | int pthread_attr_init(pthread_attr_t *attr) |
| 157 | { |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 158 | static int moans = N_MOANS; |
| 159 | if (moans-- > 0) |
| 160 | ignored("pthread_attr_init"); |
sewardj | 6af4b5d | 2002-04-16 04:40:49 +0000 | [diff] [blame] | 161 | return 0; |
| 162 | } |
| 163 | |
| 164 | int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate) |
| 165 | { |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 166 | static int moans = N_MOANS; |
| 167 | if (moans-- > 0) |
| 168 | ignored("pthread_attr_setdetachstate"); |
sewardj | 6af4b5d | 2002-04-16 04:40:49 +0000 | [diff] [blame] | 169 | return 0; |
| 170 | } |
| 171 | |
sewardj | 30671ff | 2002-04-21 00:13:57 +0000 | [diff] [blame] | 172 | int pthread_attr_setinheritsched(pthread_attr_t *attr, int inherit) |
| 173 | { |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 174 | static int moans = N_MOANS; |
| 175 | if (moans-- > 0) |
| 176 | ignored("pthread_attr_setinheritsched"); |
sewardj | 30671ff | 2002-04-21 00:13:57 +0000 | [diff] [blame] | 177 | return 0; |
| 178 | } |
sewardj | 6af4b5d | 2002-04-16 04:40:49 +0000 | [diff] [blame] | 179 | |
sewardj | 30671ff | 2002-04-21 00:13:57 +0000 | [diff] [blame] | 180 | /* This is completely bogus. */ |
| 181 | int pthread_attr_getschedparam(const pthread_attr_t *attr, |
| 182 | struct sched_param *param) |
| 183 | { |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 184 | static int moans = N_MOANS; |
| 185 | if (moans-- > 0) |
| 186 | kludged("pthread_attr_getschedparam"); |
sewardj | 72d5848 | 2002-04-24 02:20:20 +0000 | [diff] [blame] | 187 | # ifdef GLIBC_2_1 |
| 188 | if (param) param->sched_priority = 0; /* who knows */ |
| 189 | # else |
sewardj | 30671ff | 2002-04-21 00:13:57 +0000 | [diff] [blame] | 190 | if (param) param->__sched_priority = 0; /* who knows */ |
sewardj | 72d5848 | 2002-04-24 02:20:20 +0000 | [diff] [blame] | 191 | # endif |
sewardj | 30671ff | 2002-04-21 00:13:57 +0000 | [diff] [blame] | 192 | return 0; |
| 193 | } |
| 194 | |
| 195 | int pthread_attr_setschedparam(pthread_attr_t *attr, |
| 196 | const struct sched_param *param) |
| 197 | { |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 198 | static int moans = N_MOANS; |
| 199 | if (moans-- > 0) |
| 200 | ignored("pthread_attr_setschedparam"); |
sewardj | 30671ff | 2002-04-21 00:13:57 +0000 | [diff] [blame] | 201 | return 0; |
| 202 | } |
| 203 | |
| 204 | int pthread_attr_destroy(pthread_attr_t *attr) |
| 205 | { |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 206 | static int moans = N_MOANS; |
| 207 | if (moans-- > 0) |
| 208 | ignored("pthread_attr_destroy"); |
sewardj | 30671ff | 2002-04-21 00:13:57 +0000 | [diff] [blame] | 209 | return 0; |
| 210 | } |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 211 | |
| 212 | /* --------------------------------------------------- |
| 213 | THREADs |
| 214 | ------------------------------------------------ */ |
| 215 | |
sewardj | 6072c36 | 2002-04-19 14:40:57 +0000 | [diff] [blame] | 216 | int pthread_equal(pthread_t thread1, pthread_t thread2) |
| 217 | { |
| 218 | return thread1 == thread2 ? 1 : 0; |
| 219 | } |
| 220 | |
| 221 | |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 222 | int |
| 223 | pthread_create (pthread_t *__restrict __thread, |
| 224 | __const pthread_attr_t *__restrict __attr, |
| 225 | void *(*__start_routine) (void *), |
| 226 | void *__restrict __arg) |
| 227 | { |
| 228 | int res; |
| 229 | ensure_valgrind("pthread_create"); |
| 230 | VALGRIND_MAGIC_SEQUENCE(res, 0 /* default */, |
| 231 | VG_USERREQ__PTHREAD_CREATE, |
| 232 | __thread, __attr, __start_routine, __arg); |
| 233 | return res; |
| 234 | } |
| 235 | |
| 236 | |
| 237 | |
| 238 | int |
| 239 | pthread_join (pthread_t __th, void **__thread_return) |
| 240 | { |
| 241 | int res; |
| 242 | ensure_valgrind("pthread_join"); |
| 243 | VALGRIND_MAGIC_SEQUENCE(res, 0 /* default */, |
| 244 | VG_USERREQ__PTHREAD_JOIN, |
| 245 | __th, __thread_return, 0, 0); |
| 246 | return res; |
| 247 | } |
| 248 | |
| 249 | |
sewardj | 3b5d886 | 2002-04-20 13:53:23 +0000 | [diff] [blame] | 250 | void pthread_exit(void *retval) |
| 251 | { |
| 252 | int res; |
| 253 | ensure_valgrind("pthread_exit"); |
| 254 | VALGRIND_MAGIC_SEQUENCE(res, 0 /* default */, |
| 255 | VG_USERREQ__PTHREAD_EXIT, |
| 256 | retval, 0, 0, 0); |
| 257 | /* Doesn't return! */ |
| 258 | /* However, we have to fool gcc into knowing that. */ |
| 259 | barf("pthread_exit: still alive after request?!"); |
| 260 | } |
| 261 | |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 262 | |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 263 | pthread_t pthread_self(void) |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 264 | { |
| 265 | int tid; |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 266 | ensure_valgrind("pthread_self"); |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 267 | VALGRIND_MAGIC_SEQUENCE(tid, 0 /* default */, |
| 268 | VG_USERREQ__PTHREAD_GET_THREADID, |
| 269 | 0, 0, 0, 0); |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 270 | if (tid < 0 || tid >= VG_N_THREADS) |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 271 | barf("pthread_self: invalid ThreadId"); |
| 272 | return tid; |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 276 | int pthread_detach(pthread_t th) |
| 277 | { |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 278 | static int moans = N_MOANS; |
| 279 | if (moans-- > 0) |
| 280 | ignored("pthread_detach"); |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 281 | return 0; |
| 282 | } |
| 283 | |
| 284 | |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 285 | /* --------------------------------------------------- |
| 286 | MUTEX ATTRIBUTES |
| 287 | ------------------------------------------------ */ |
| 288 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 289 | int __pthread_mutexattr_init(pthread_mutexattr_t *attr) |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 290 | { |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 291 | attr->__mutexkind = PTHREAD_MUTEX_ERRORCHECK_NP; |
sewardj | 8937c81 | 2002-04-12 20:12:20 +0000 | [diff] [blame] | 292 | return 0; |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 293 | } |
| 294 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 295 | int __pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type) |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 296 | { |
| 297 | switch (type) { |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 298 | # ifndef GLIBC_2_1 |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 299 | case PTHREAD_MUTEX_TIMED_NP: |
sewardj | 2a1dcce | 2002-04-22 12:45:25 +0000 | [diff] [blame] | 300 | case PTHREAD_MUTEX_ADAPTIVE_NP: |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 301 | # endif |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 302 | case PTHREAD_MUTEX_RECURSIVE_NP: |
| 303 | case PTHREAD_MUTEX_ERRORCHECK_NP: |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 304 | attr->__mutexkind = type; |
| 305 | return 0; |
| 306 | default: |
| 307 | return EINVAL; |
| 308 | } |
| 309 | } |
| 310 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 311 | int __pthread_mutexattr_destroy(pthread_mutexattr_t *attr) |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 312 | { |
| 313 | return 0; |
| 314 | } |
| 315 | |
| 316 | |
| 317 | /* --------------------------------------------------- |
| 318 | MUTEXes |
| 319 | ------------------------------------------------ */ |
| 320 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 321 | int __pthread_mutex_init(pthread_mutex_t *mutex, |
| 322 | const pthread_mutexattr_t *mutexattr) |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 323 | { |
sewardj | 604ec3c | 2002-04-18 22:38:41 +0000 | [diff] [blame] | 324 | mutex->__m_count = 0; |
| 325 | mutex->__m_owner = (_pthread_descr)VG_INVALID_THREADID; |
| 326 | mutex->__m_kind = PTHREAD_MUTEX_ERRORCHECK_NP; |
| 327 | if (mutexattr) |
| 328 | mutex->__m_kind = mutexattr->__mutexkind; |
| 329 | return 0; |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 330 | } |
| 331 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 332 | int __pthread_mutex_lock(pthread_mutex_t *mutex) |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 333 | { |
| 334 | int res; |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 335 | static int moans = N_MOANS; |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 336 | if (!(RUNNING_ON_VALGRIND) && moans-- > 0) { |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 337 | char* str = "pthread_mutex_lock-NOT-INSIDE-VALGRIND\n"; |
| 338 | write(2, str, strlen(str)); |
| 339 | return 0; |
| 340 | } else { |
| 341 | VALGRIND_MAGIC_SEQUENCE(res, 0 /* default */, |
| 342 | VG_USERREQ__PTHREAD_MUTEX_LOCK, |
| 343 | mutex, 0, 0, 0); |
| 344 | return res; |
| 345 | } |
| 346 | } |
| 347 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 348 | int __pthread_mutex_trylock(pthread_mutex_t *mutex) |
sewardj | 30671ff | 2002-04-21 00:13:57 +0000 | [diff] [blame] | 349 | { |
| 350 | int res; |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 351 | static int moans = N_MOANS; |
sewardj | 30671ff | 2002-04-21 00:13:57 +0000 | [diff] [blame] | 352 | if (!(RUNNING_ON_VALGRIND) && moans-- > 0) { |
| 353 | char* str = "pthread_mutex_trylock-NOT-INSIDE-VALGRIND\n"; |
| 354 | write(2, str, strlen(str)); |
| 355 | return 0; |
| 356 | } else { |
| 357 | VALGRIND_MAGIC_SEQUENCE(res, 0 /* default */, |
| 358 | VG_USERREQ__PTHREAD_MUTEX_TRYLOCK, |
| 359 | mutex, 0, 0, 0); |
| 360 | return res; |
| 361 | } |
| 362 | } |
| 363 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 364 | int __pthread_mutex_unlock(pthread_mutex_t *mutex) |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 365 | { |
| 366 | int res; |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 367 | static int moans = N_MOANS; |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 368 | if (!(RUNNING_ON_VALGRIND) && moans-- > 0) { |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 369 | char* str = "pthread_mutex_unlock-NOT-INSIDE-VALGRIND\n"; |
| 370 | write(2, str, strlen(str)); |
| 371 | return 0; |
| 372 | } else { |
| 373 | VALGRIND_MAGIC_SEQUENCE(res, 0 /* default */, |
| 374 | VG_USERREQ__PTHREAD_MUTEX_UNLOCK, |
| 375 | mutex, 0, 0, 0); |
| 376 | return res; |
| 377 | } |
| 378 | } |
| 379 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 380 | int __pthread_mutex_destroy(pthread_mutex_t *mutex) |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 381 | { |
sewardj | 604ec3c | 2002-04-18 22:38:41 +0000 | [diff] [blame] | 382 | /* Valgrind doesn't hold any resources on behalf of the mutex, so no |
| 383 | need to involve it. */ |
| 384 | if (mutex->__m_count > 0) |
| 385 | return EBUSY; |
sewardj | 6072c36 | 2002-04-19 14:40:57 +0000 | [diff] [blame] | 386 | mutex->__m_count = 0; |
| 387 | mutex->__m_owner = (_pthread_descr)VG_INVALID_THREADID; |
| 388 | mutex->__m_kind = PTHREAD_MUTEX_ERRORCHECK_NP; |
sewardj | 604ec3c | 2002-04-18 22:38:41 +0000 | [diff] [blame] | 389 | return 0; |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 393 | /* --------------------------------------------------- |
sewardj | 6072c36 | 2002-04-19 14:40:57 +0000 | [diff] [blame] | 394 | CONDITION VARIABLES |
| 395 | ------------------------------------------------ */ |
| 396 | |
| 397 | /* LinuxThreads supports no attributes for conditions. Hence ... */ |
| 398 | |
| 399 | int pthread_condattr_init(pthread_condattr_t *attr) |
| 400 | { |
| 401 | return 0; |
| 402 | } |
| 403 | |
sewardj | 0738a59 | 2002-04-20 13:59:33 +0000 | [diff] [blame] | 404 | int pthread_condattr_destroy(pthread_condattr_t *attr) |
| 405 | { |
| 406 | return 0; |
| 407 | } |
sewardj | 6072c36 | 2002-04-19 14:40:57 +0000 | [diff] [blame] | 408 | |
| 409 | int pthread_cond_init( pthread_cond_t *cond, |
| 410 | const pthread_condattr_t *cond_attr) |
| 411 | { |
| 412 | cond->__c_waiting = (_pthread_descr)VG_INVALID_THREADID; |
| 413 | return 0; |
| 414 | } |
| 415 | |
sewardj | f854f47 | 2002-04-21 12:19:41 +0000 | [diff] [blame] | 416 | int pthread_cond_destroy(pthread_cond_t *cond) |
| 417 | { |
| 418 | /* should check that no threads are waiting on this CV */ |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 419 | static int moans = N_MOANS; |
| 420 | if (moans-- > 0) |
| 421 | kludged("pthread_cond_destroy"); |
sewardj | f854f47 | 2002-04-21 12:19:41 +0000 | [diff] [blame] | 422 | return 0; |
| 423 | } |
sewardj | 6072c36 | 2002-04-19 14:40:57 +0000 | [diff] [blame] | 424 | |
| 425 | /* --------------------------------------------------- |
| 426 | SCHEDULING |
| 427 | ------------------------------------------------ */ |
| 428 | |
| 429 | /* This is completely bogus. */ |
| 430 | int pthread_getschedparam(pthread_t target_thread, |
| 431 | int *policy, |
| 432 | struct sched_param *param) |
| 433 | { |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 434 | static int moans = N_MOANS; |
| 435 | if (moans-- > 0) |
| 436 | kludged("pthread_getschedparam"); |
sewardj | 6072c36 | 2002-04-19 14:40:57 +0000 | [diff] [blame] | 437 | if (policy) *policy = SCHED_OTHER; |
sewardj | 2a1dcce | 2002-04-22 12:45:25 +0000 | [diff] [blame] | 438 | # ifdef GLIBC_2_1 |
| 439 | if (param) param->sched_priority = 0; /* who knows */ |
| 440 | # else |
sewardj | 6072c36 | 2002-04-19 14:40:57 +0000 | [diff] [blame] | 441 | if (param) param->__sched_priority = 0; /* who knows */ |
sewardj | 2a1dcce | 2002-04-22 12:45:25 +0000 | [diff] [blame] | 442 | # endif |
sewardj | 6072c36 | 2002-04-19 14:40:57 +0000 | [diff] [blame] | 443 | return 0; |
| 444 | } |
| 445 | |
| 446 | int pthread_setschedparam(pthread_t target_thread, |
| 447 | int policy, |
| 448 | const struct sched_param *param) |
| 449 | { |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 450 | static int moans = N_MOANS; |
| 451 | if (moans-- > 0) |
| 452 | ignored("pthread_setschedparam"); |
sewardj | 6072c36 | 2002-04-19 14:40:57 +0000 | [diff] [blame] | 453 | return 0; |
| 454 | } |
| 455 | |
sewardj | 3b5d886 | 2002-04-20 13:53:23 +0000 | [diff] [blame] | 456 | int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex) |
| 457 | { |
| 458 | int res; |
| 459 | ensure_valgrind("pthread_cond_wait"); |
| 460 | VALGRIND_MAGIC_SEQUENCE(res, 0 /* default */, |
| 461 | VG_USERREQ__PTHREAD_COND_WAIT, |
| 462 | cond, mutex, 0, 0); |
| 463 | return res; |
| 464 | } |
| 465 | |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 466 | int pthread_cond_timedwait ( pthread_cond_t *cond, |
| 467 | pthread_mutex_t *mutex, |
| 468 | const struct timespec *abstime ) |
| 469 | { |
| 470 | int res; |
| 471 | unsigned int ms_now, ms_end; |
| 472 | struct timeval timeval_now; |
| 473 | unsigned long long int ull_ms_now_after_1970; |
| 474 | unsigned long long int ull_ms_end_after_1970; |
| 475 | |
| 476 | ensure_valgrind("pthread_cond_timedwait"); |
| 477 | VALGRIND_MAGIC_SEQUENCE(ms_now, 0xFFFFFFFF /* default */, |
| 478 | VG_USERREQ__READ_MILLISECOND_TIMER, |
| 479 | 0, 0, 0, 0); |
| 480 | assert(ms_now != 0xFFFFFFFF); |
| 481 | res = gettimeofday(&timeval_now, NULL); |
| 482 | assert(res == 0); |
| 483 | |
| 484 | ull_ms_now_after_1970 |
| 485 | = 1000ULL * ((unsigned long long int)(timeval_now.tv_sec)) |
| 486 | + ((unsigned long long int)(timeval_now.tv_usec / 1000000)); |
| 487 | ull_ms_end_after_1970 |
| 488 | = 1000ULL * ((unsigned long long int)(abstime->tv_sec)) |
| 489 | + ((unsigned long long int)(abstime->tv_nsec / 1000000)); |
| 490 | assert(ull_ms_end_after_1970 >= ull_ms_now_after_1970); |
| 491 | ms_end |
| 492 | = ms_now + (unsigned int)(ull_ms_end_after_1970 - ull_ms_now_after_1970); |
| 493 | VALGRIND_MAGIC_SEQUENCE(res, 0 /* default */, |
| 494 | VG_USERREQ__PTHREAD_COND_TIMEDWAIT, |
| 495 | cond, mutex, ms_end, 0); |
| 496 | return res; |
| 497 | } |
| 498 | |
| 499 | |
sewardj | 3b5d886 | 2002-04-20 13:53:23 +0000 | [diff] [blame] | 500 | int pthread_cond_signal(pthread_cond_t *cond) |
| 501 | { |
| 502 | int res; |
| 503 | ensure_valgrind("pthread_cond_signal"); |
| 504 | VALGRIND_MAGIC_SEQUENCE(res, 0 /* default */, |
| 505 | VG_USERREQ__PTHREAD_COND_SIGNAL, |
| 506 | cond, 0, 0, 0); |
| 507 | return res; |
| 508 | } |
| 509 | |
| 510 | int pthread_cond_broadcast(pthread_cond_t *cond) |
| 511 | { |
| 512 | int res; |
| 513 | ensure_valgrind("pthread_cond_broadcast"); |
| 514 | VALGRIND_MAGIC_SEQUENCE(res, 0 /* default */, |
| 515 | VG_USERREQ__PTHREAD_COND_BROADCAST, |
| 516 | cond, 0, 0, 0); |
| 517 | return res; |
| 518 | } |
| 519 | |
sewardj | 6072c36 | 2002-04-19 14:40:57 +0000 | [diff] [blame] | 520 | |
| 521 | /* --------------------------------------------------- |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 522 | CANCELLATION |
| 523 | ------------------------------------------------ */ |
| 524 | |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 525 | int pthread_setcancelstate(int state, int *oldstate) |
| 526 | { |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 527 | static int moans = N_MOANS; |
| 528 | if (moans-- > 0) |
| 529 | ignored("pthread_setcancelstate"); |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 530 | return 0; |
| 531 | } |
| 532 | |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 533 | int pthread_setcanceltype(int type, int *oldtype) |
| 534 | { |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 535 | static int moans = N_MOANS; |
| 536 | if (moans-- > 0) |
| 537 | ignored("pthread_setcanceltype"); |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 538 | return 0; |
| 539 | } |
| 540 | |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 541 | int pthread_cancel(pthread_t thread) |
| 542 | { |
| 543 | int res; |
| 544 | ensure_valgrind("pthread_cancel"); |
| 545 | VALGRIND_MAGIC_SEQUENCE(res, 0 /* default */, |
| 546 | VG_USERREQ__PTHREAD_CANCEL, |
| 547 | thread, 0, 0, 0); |
| 548 | return res; |
| 549 | } |
| 550 | |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 551 | void pthread_testcancel(void) |
| 552 | { |
| 553 | } |
| 554 | |
| 555 | /*-------------------*/ |
| 556 | static pthread_mutex_t massacre_mx = PTHREAD_MUTEX_INITIALIZER; |
| 557 | |
| 558 | void __pthread_kill_other_threads_np ( void ) |
| 559 | { |
| 560 | int i, res, me; |
| 561 | pthread_mutex_lock(&massacre_mx); |
| 562 | me = pthread_self(); |
| 563 | for (i = 1; i < VG_N_THREADS; i++) { |
| 564 | if (i == me) continue; |
| 565 | res = pthread_cancel(i); |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 566 | if (0 && res == 0) |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 567 | printf("----------- NUKED %d\n", i); |
| 568 | } |
| 569 | pthread_mutex_unlock(&massacre_mx); |
| 570 | } |
| 571 | |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 572 | |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 573 | /* --------------------------------------------------- |
| 574 | THREAD-SPECIFICs |
| 575 | ------------------------------------------------ */ |
sewardj | 5e5fa51 | 2002-04-14 13:13:05 +0000 | [diff] [blame] | 576 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 577 | int __pthread_key_create(pthread_key_t *key, |
| 578 | void (*destr_function) (void *)) |
sewardj | 5e5fa51 | 2002-04-14 13:13:05 +0000 | [diff] [blame] | 579 | { |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 580 | int res; |
| 581 | ensure_valgrind("pthread_key_create"); |
| 582 | VALGRIND_MAGIC_SEQUENCE(res, 0 /* default */, |
| 583 | VG_USERREQ__PTHREAD_KEY_CREATE, |
| 584 | key, destr_function, 0, 0); |
| 585 | return res; |
sewardj | 5e5fa51 | 2002-04-14 13:13:05 +0000 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | int pthread_key_delete(pthread_key_t key) |
| 589 | { |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 590 | static int moans = N_MOANS; |
| 591 | if (moans-- > 0) |
| 592 | ignored("pthread_key_delete"); |
sewardj | 5e5fa51 | 2002-04-14 13:13:05 +0000 | [diff] [blame] | 593 | return 0; |
| 594 | } |
| 595 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 596 | int __pthread_setspecific(pthread_key_t key, const void *pointer) |
sewardj | 5e5fa51 | 2002-04-14 13:13:05 +0000 | [diff] [blame] | 597 | { |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 598 | int res; |
| 599 | ensure_valgrind("pthread_setspecific"); |
| 600 | VALGRIND_MAGIC_SEQUENCE(res, 0 /* default */, |
| 601 | VG_USERREQ__PTHREAD_SETSPECIFIC, |
| 602 | key, pointer, 0, 0); |
| 603 | return res; |
sewardj | 5e5fa51 | 2002-04-14 13:13:05 +0000 | [diff] [blame] | 604 | } |
| 605 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 606 | void * __pthread_getspecific(pthread_key_t key) |
sewardj | 5e5fa51 | 2002-04-14 13:13:05 +0000 | [diff] [blame] | 607 | { |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 608 | int res; |
| 609 | ensure_valgrind("pthread_getspecific"); |
| 610 | VALGRIND_MAGIC_SEQUENCE(res, 0 /* default */, |
| 611 | VG_USERREQ__PTHREAD_GETSPECIFIC, |
| 612 | key, 0 , 0, 0); |
| 613 | return (void*)res; |
sewardj | 5e5fa51 | 2002-04-14 13:13:05 +0000 | [diff] [blame] | 614 | } |
| 615 | |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 616 | |
| 617 | /* --------------------------------------------------- |
sewardj | 89d3d85 | 2002-04-24 19:21:39 +0000 | [diff] [blame] | 618 | ONCEry |
| 619 | ------------------------------------------------ */ |
| 620 | |
| 621 | static pthread_mutex_t once_masterlock = PTHREAD_MUTEX_INITIALIZER; |
| 622 | |
| 623 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 624 | int __pthread_once ( pthread_once_t *once_control, |
| 625 | void (*init_routine) (void) ) |
sewardj | 89d3d85 | 2002-04-24 19:21:39 +0000 | [diff] [blame] | 626 | { |
| 627 | int res; |
| 628 | ensure_valgrind("pthread_once"); |
| 629 | |
| 630 | res = pthread_mutex_lock(&once_masterlock); |
| 631 | |
| 632 | if (res != 0) |
| 633 | barf("pthread_once: Looks like your program's " |
| 634 | "init routine calls back to pthread_once() ?!"); |
| 635 | |
| 636 | if (*once_control == 0) { |
| 637 | *once_control = 1; |
| 638 | init_routine(); |
| 639 | } |
| 640 | |
| 641 | pthread_mutex_unlock(&once_masterlock); |
| 642 | |
| 643 | return 0; |
| 644 | } |
| 645 | |
| 646 | |
| 647 | /* --------------------------------------------------- |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 648 | MISC |
| 649 | ------------------------------------------------ */ |
| 650 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 651 | int __pthread_atfork ( void (*prepare)(void), |
| 652 | void (*parent)(void), |
| 653 | void (*child)(void) ) |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 654 | { |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 655 | static int moans = N_MOANS; |
| 656 | if (moans-- > 0) |
| 657 | ignored("pthread_atfork"); |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 658 | return 0; |
| 659 | } |
| 660 | |
| 661 | |
| 662 | /* --------------------------------------------------- |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 663 | LIBRARY-PRIVATE THREAD SPECIFIC STATE |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 664 | ------------------------------------------------ */ |
| 665 | |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 666 | #include <resolv.h> |
| 667 | static int thread_specific_errno[VG_N_THREADS]; |
| 668 | static int thread_specific_h_errno[VG_N_THREADS]; |
| 669 | static struct __res_state |
| 670 | thread_specific_res_state[VG_N_THREADS]; |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 671 | |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 672 | int* __errno_location ( void ) |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 673 | { |
| 674 | int tid; |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 675 | /* ensure_valgrind("__errno_location"); */ |
| 676 | VALGRIND_MAGIC_SEQUENCE(tid, 1 /* default */, |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 677 | VG_USERREQ__PTHREAD_GET_THREADID, |
| 678 | 0, 0, 0, 0); |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 679 | /* 'cos I'm paranoid ... */ |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 680 | if (tid < 0 || tid >= VG_N_THREADS) |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 681 | barf("__errno_location: invalid ThreadId"); |
| 682 | return & thread_specific_errno[tid]; |
| 683 | } |
| 684 | |
| 685 | int* __h_errno_location ( void ) |
| 686 | { |
| 687 | int tid; |
| 688 | /* ensure_valgrind("__h_errno_location"); */ |
| 689 | VALGRIND_MAGIC_SEQUENCE(tid, 1 /* default */, |
| 690 | VG_USERREQ__PTHREAD_GET_THREADID, |
| 691 | 0, 0, 0, 0); |
| 692 | /* 'cos I'm paranoid ... */ |
| 693 | if (tid < 0 || tid >= VG_N_THREADS) |
| 694 | barf("__h_errno_location: invalid ThreadId"); |
| 695 | return & thread_specific_h_errno[tid]; |
| 696 | } |
| 697 | |
| 698 | struct __res_state* __res_state ( void ) |
| 699 | { |
| 700 | int tid; |
| 701 | /* ensure_valgrind("__res_state"); */ |
| 702 | VALGRIND_MAGIC_SEQUENCE(tid, 1 /* default */, |
| 703 | VG_USERREQ__PTHREAD_GET_THREADID, |
| 704 | 0, 0, 0, 0); |
| 705 | /* 'cos I'm paranoid ... */ |
| 706 | if (tid < 0 || tid >= VG_N_THREADS) |
| 707 | barf("__res_state: invalid ThreadId"); |
| 708 | return & thread_specific_res_state[tid]; |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | |
sewardj | 5716dbb | 2002-04-26 03:28:18 +0000 | [diff] [blame] | 712 | /* --------------------------------------------------- |
| 713 | LIBC-PRIVATE SPECIFIC DATA |
| 714 | ------------------------------------------------ */ |
| 715 | |
| 716 | /* Relies on assumption that initial private data is NULL. This |
| 717 | should be fixed somehow. */ |
| 718 | |
| 719 | /* The allowable keys (indices) (all 2 of them). |
| 720 | From sysdeps/pthread/bits/libc-tsd.h |
| 721 | */ |
sewardj | 70adeb2 | 2002-04-27 01:35:38 +0000 | [diff] [blame] | 722 | #define N_LIBC_TSD_EXTRA_KEYS 1 |
| 723 | |
sewardj | 5716dbb | 2002-04-26 03:28:18 +0000 | [diff] [blame] | 724 | enum __libc_tsd_key_t { _LIBC_TSD_KEY_MALLOC = 0, |
| 725 | _LIBC_TSD_KEY_DL_ERROR, |
| 726 | _LIBC_TSD_KEY_N }; |
| 727 | |
| 728 | /* Auto-initialising subsystem. libc_specifics_inited is set |
| 729 | after initialisation. libc_specifics_inited_mx guards it. */ |
| 730 | static int libc_specifics_inited = 0; |
| 731 | static pthread_mutex_t libc_specifics_inited_mx = PTHREAD_MUTEX_INITIALIZER; |
| 732 | |
| 733 | /* These are the keys we must initialise the first time. */ |
sewardj | 70adeb2 | 2002-04-27 01:35:38 +0000 | [diff] [blame] | 734 | static pthread_key_t libc_specifics_keys[_LIBC_TSD_KEY_N |
| 735 | + N_LIBC_TSD_EXTRA_KEYS]; |
sewardj | 5716dbb | 2002-04-26 03:28:18 +0000 | [diff] [blame] | 736 | |
| 737 | /* Initialise the keys, if they are not already initialise. */ |
| 738 | static |
| 739 | void init_libc_tsd_keys ( void ) |
| 740 | { |
| 741 | int res, i; |
| 742 | pthread_key_t k; |
| 743 | |
| 744 | res = pthread_mutex_lock(&libc_specifics_inited_mx); |
| 745 | if (res != 0) barf("init_libc_tsd_keys: lock"); |
| 746 | |
| 747 | if (libc_specifics_inited == 0) { |
| 748 | /* printf("INIT libc specifics\n"); */ |
| 749 | libc_specifics_inited = 1; |
sewardj | 70adeb2 | 2002-04-27 01:35:38 +0000 | [diff] [blame] | 750 | for (i = 0; i < _LIBC_TSD_KEY_N + N_LIBC_TSD_EXTRA_KEYS; i++) { |
sewardj | 5716dbb | 2002-04-26 03:28:18 +0000 | [diff] [blame] | 751 | res = pthread_key_create(&k, NULL); |
| 752 | if (res != 0) barf("init_libc_tsd_keys: create"); |
| 753 | libc_specifics_keys[i] = k; |
| 754 | } |
| 755 | } |
| 756 | |
| 757 | res = pthread_mutex_unlock(&libc_specifics_inited_mx); |
| 758 | if (res != 0) barf("init_libc_tsd_keys: unlock"); |
| 759 | } |
| 760 | |
| 761 | |
| 762 | static int |
| 763 | libc_internal_tsd_set ( enum __libc_tsd_key_t key, |
| 764 | const void * pointer ) |
| 765 | { |
sewardj | 70adeb2 | 2002-04-27 01:35:38 +0000 | [diff] [blame] | 766 | int res; |
| 767 | static int moans = N_MOANS; |
sewardj | 5716dbb | 2002-04-26 03:28:18 +0000 | [diff] [blame] | 768 | /* printf("SET SET SET key %d ptr %p\n", key, pointer); */ |
sewardj | 70adeb2 | 2002-04-27 01:35:38 +0000 | [diff] [blame] | 769 | if (key < _LIBC_TSD_KEY_MALLOC |
| 770 | || key >= _LIBC_TSD_KEY_N + N_LIBC_TSD_EXTRA_KEYS) |
sewardj | 5716dbb | 2002-04-26 03:28:18 +0000 | [diff] [blame] | 771 | barf("libc_internal_tsd_set: invalid key"); |
sewardj | 70adeb2 | 2002-04-27 01:35:38 +0000 | [diff] [blame] | 772 | if (key >= _LIBC_TSD_KEY_N && moans-- > 0) |
| 773 | fprintf(stderr, |
| 774 | "vg_libpthread.so: libc_internal_tsd_set: dubious key %d\n", key); |
sewardj | 5716dbb | 2002-04-26 03:28:18 +0000 | [diff] [blame] | 775 | init_libc_tsd_keys(); |
| 776 | res = pthread_setspecific(libc_specifics_keys[key], pointer); |
| 777 | if (res != 0) barf("libc_internal_tsd_set: setspecific failed"); |
| 778 | return 0; |
| 779 | } |
| 780 | |
| 781 | static void * |
| 782 | libc_internal_tsd_get ( enum __libc_tsd_key_t key ) |
| 783 | { |
sewardj | 70adeb2 | 2002-04-27 01:35:38 +0000 | [diff] [blame] | 784 | void* v; |
| 785 | static int moans = N_MOANS; |
sewardj | 5716dbb | 2002-04-26 03:28:18 +0000 | [diff] [blame] | 786 | /* printf("GET GET GET key %d\n", key); */ |
sewardj | 70adeb2 | 2002-04-27 01:35:38 +0000 | [diff] [blame] | 787 | if (key < _LIBC_TSD_KEY_MALLOC |
| 788 | || key >= _LIBC_TSD_KEY_N + N_LIBC_TSD_EXTRA_KEYS) |
sewardj | 5716dbb | 2002-04-26 03:28:18 +0000 | [diff] [blame] | 789 | barf("libc_internal_tsd_get: invalid key"); |
sewardj | 70adeb2 | 2002-04-27 01:35:38 +0000 | [diff] [blame] | 790 | if (key >= _LIBC_TSD_KEY_N && moans-- > 0) |
| 791 | fprintf(stderr, |
| 792 | "vg_libpthread.so: libc_internal_tsd_get: dubious key %d\n", key); |
sewardj | 5716dbb | 2002-04-26 03:28:18 +0000 | [diff] [blame] | 793 | init_libc_tsd_keys(); |
| 794 | v = pthread_getspecific(libc_specifics_keys[key]); |
| 795 | /* if (v == NULL) barf("libc_internal_tsd_set: getspecific failed"); */ |
| 796 | return v; |
| 797 | } |
| 798 | |
| 799 | |
| 800 | |
| 801 | |
sewardj | 70adeb2 | 2002-04-27 01:35:38 +0000 | [diff] [blame] | 802 | int (*__libc_internal_tsd_set) |
| 803 | (enum __libc_tsd_key_t key, const void * pointer) |
| 804 | = libc_internal_tsd_set; |
sewardj | 5716dbb | 2002-04-26 03:28:18 +0000 | [diff] [blame] | 805 | |
sewardj | 70adeb2 | 2002-04-27 01:35:38 +0000 | [diff] [blame] | 806 | void* (*__libc_internal_tsd_get) |
| 807 | (enum __libc_tsd_key_t key) |
| 808 | = libc_internal_tsd_get; |
sewardj | 5716dbb | 2002-04-26 03:28:18 +0000 | [diff] [blame] | 809 | |
| 810 | |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 811 | /* --------------------------------------------------------------------- |
| 812 | These are here (I think) because they are deemed cancellation |
| 813 | points by POSIX. For the moment we'll simply pass the call along |
| 814 | to the corresponding thread-unaware (?) libc routine. |
| 815 | ------------------------------------------------------------------ */ |
| 816 | |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 817 | #include <stdlib.h> |
| 818 | #include <signal.h> |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 819 | #include <sys/types.h> |
| 820 | #include <sys/socket.h> |
| 821 | |
| 822 | extern |
| 823 | int __libc_sigaction |
| 824 | (int signum, |
| 825 | const struct sigaction *act, |
| 826 | struct sigaction *oldact); |
| 827 | int sigaction(int signum, |
| 828 | const struct sigaction *act, |
| 829 | struct sigaction *oldact) |
| 830 | { |
sewardj | 2a1dcce | 2002-04-22 12:45:25 +0000 | [diff] [blame] | 831 | # ifdef GLIBC_2_1 |
| 832 | return __sigaction(signum, act, oldact); |
| 833 | # else |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 834 | return __libc_sigaction(signum, act, oldact); |
sewardj | 2a1dcce | 2002-04-22 12:45:25 +0000 | [diff] [blame] | 835 | # endif |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 836 | } |
| 837 | |
| 838 | |
| 839 | extern |
| 840 | int __libc_connect(int sockfd, |
| 841 | const struct sockaddr *serv_addr, |
| 842 | socklen_t addrlen); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 843 | __attribute__((weak)) |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 844 | int connect(int sockfd, |
| 845 | const struct sockaddr *serv_addr, |
| 846 | socklen_t addrlen) |
| 847 | { |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 848 | return __libc_connect(sockfd, serv_addr, addrlen); |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 849 | } |
| 850 | |
| 851 | |
| 852 | extern |
| 853 | int __libc_fcntl(int fd, int cmd, long arg); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 854 | __attribute__((weak)) |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 855 | int fcntl(int fd, int cmd, long arg) |
| 856 | { |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 857 | return __libc_fcntl(fd, cmd, arg); |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | |
| 861 | extern |
| 862 | ssize_t __libc_write(int fd, const void *buf, size_t count); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 863 | __attribute__((weak)) |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 864 | ssize_t write(int fd, const void *buf, size_t count) |
| 865 | { |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 866 | return __libc_write(fd, buf, count); |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 867 | } |
| 868 | |
| 869 | |
| 870 | extern |
| 871 | ssize_t __libc_read(int fd, void *buf, size_t count); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 872 | __attribute__((weak)) |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 873 | ssize_t read(int fd, void *buf, size_t count) |
| 874 | { |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 875 | return __libc_read(fd, buf, count); |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 876 | } |
| 877 | |
sewardj | be32e45 | 2002-04-24 20:29:58 +0000 | [diff] [blame] | 878 | |
| 879 | extern |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 880 | int __libc_open64(const char *pathname, int flags, mode_t mode); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 881 | __attribute__((weak)) |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 882 | int open64(const char *pathname, int flags, mode_t mode) |
sewardj | be32e45 | 2002-04-24 20:29:58 +0000 | [diff] [blame] | 883 | { |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 884 | return __libc_open64(pathname, flags, mode); |
sewardj | be32e45 | 2002-04-24 20:29:58 +0000 | [diff] [blame] | 885 | } |
| 886 | |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 887 | |
| 888 | extern |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 889 | int __libc_open(const char *pathname, int flags, mode_t mode); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 890 | __attribute__((weak)) |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 891 | int open(const char *pathname, int flags, mode_t mode) |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 892 | { |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 893 | return __libc_open(pathname, flags, mode); |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 894 | } |
| 895 | |
| 896 | |
| 897 | extern |
| 898 | int __libc_close(int fd); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 899 | __attribute__((weak)) |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 900 | int close(int fd) |
| 901 | { |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 902 | return __libc_close(fd); |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 903 | } |
| 904 | |
| 905 | |
| 906 | extern |
| 907 | int __libc_accept(int s, struct sockaddr *addr, socklen_t *addrlen); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 908 | __attribute__((weak)) |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 909 | int accept(int s, struct sockaddr *addr, socklen_t *addrlen) |
| 910 | { |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 911 | return __libc_accept(s, addr, addrlen); |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 912 | } |
| 913 | |
| 914 | |
| 915 | extern |
| 916 | pid_t __libc_fork(void); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 917 | pid_t __fork(void) |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 918 | { |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 919 | return __libc_fork(); |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 920 | } |
| 921 | |
| 922 | |
| 923 | extern |
| 924 | pid_t __libc_waitpid(pid_t pid, int *status, int options); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 925 | __attribute__((weak)) |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 926 | pid_t waitpid(pid_t pid, int *status, int options) |
| 927 | { |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 928 | return __libc_waitpid(pid, status, options); |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 929 | } |
| 930 | |
| 931 | |
| 932 | extern |
| 933 | int __libc_nanosleep(const struct timespec *req, struct timespec *rem); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 934 | __attribute__((weak)) |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 935 | int nanosleep(const struct timespec *req, struct timespec *rem) |
| 936 | { |
| 937 | return __libc_nanosleep(req, rem); |
| 938 | } |
| 939 | |
sewardj | be32e45 | 2002-04-24 20:29:58 +0000 | [diff] [blame] | 940 | |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 941 | extern |
| 942 | int __libc_fsync(int fd); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 943 | __attribute__((weak)) |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 944 | int fsync(int fd) |
| 945 | { |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 946 | return __libc_fsync(fd); |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 947 | } |
| 948 | |
sewardj | be32e45 | 2002-04-24 20:29:58 +0000 | [diff] [blame] | 949 | |
sewardj | 70c7536 | 2002-04-13 04:18:32 +0000 | [diff] [blame] | 950 | extern |
| 951 | off_t __libc_lseek(int fildes, off_t offset, int whence); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 952 | __attribute__((weak)) |
sewardj | 70c7536 | 2002-04-13 04:18:32 +0000 | [diff] [blame] | 953 | off_t lseek(int fildes, off_t offset, int whence) |
| 954 | { |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 955 | return __libc_lseek(fildes, offset, whence); |
sewardj | 70c7536 | 2002-04-13 04:18:32 +0000 | [diff] [blame] | 956 | } |
| 957 | |
sewardj | be32e45 | 2002-04-24 20:29:58 +0000 | [diff] [blame] | 958 | |
| 959 | extern |
| 960 | __off64_t __libc_lseek64(int fildes, __off64_t offset, int whence); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 961 | __attribute__((weak)) |
sewardj | be32e45 | 2002-04-24 20:29:58 +0000 | [diff] [blame] | 962 | __off64_t lseek64(int fildes, __off64_t offset, int whence) |
| 963 | { |
| 964 | return __libc_lseek64(fildes, offset, whence); |
| 965 | } |
| 966 | |
| 967 | |
sewardj | 6af4b5d | 2002-04-16 04:40:49 +0000 | [diff] [blame] | 968 | extern |
| 969 | void __libc_longjmp(jmp_buf env, int val) __attribute((noreturn)); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 970 | /* not weak: __attribute__((weak)) */ |
sewardj | 6af4b5d | 2002-04-16 04:40:49 +0000 | [diff] [blame] | 971 | void longjmp(jmp_buf env, int val) |
| 972 | { |
| 973 | __libc_longjmp(env, val); |
| 974 | } |
| 975 | |
sewardj | be32e45 | 2002-04-24 20:29:58 +0000 | [diff] [blame] | 976 | |
sewardj | 6af4b5d | 2002-04-16 04:40:49 +0000 | [diff] [blame] | 977 | extern |
| 978 | int __libc_send(int s, const void *msg, size_t len, int flags); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 979 | __attribute__((weak)) |
sewardj | 6af4b5d | 2002-04-16 04:40:49 +0000 | [diff] [blame] | 980 | int send(int s, const void *msg, size_t len, int flags) |
| 981 | { |
| 982 | return __libc_send(s, msg, len, flags); |
| 983 | } |
| 984 | |
sewardj | be32e45 | 2002-04-24 20:29:58 +0000 | [diff] [blame] | 985 | |
sewardj | 1e8cdc9 | 2002-04-18 11:37:52 +0000 | [diff] [blame] | 986 | extern |
| 987 | int __libc_recv(int s, void *buf, size_t len, int flags); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 988 | __attribute__((weak)) |
sewardj | 1e8cdc9 | 2002-04-18 11:37:52 +0000 | [diff] [blame] | 989 | int recv(int s, void *buf, size_t len, int flags) |
| 990 | { |
| 991 | return __libc_recv(s, buf, len, flags); |
| 992 | } |
| 993 | |
sewardj | be32e45 | 2002-04-24 20:29:58 +0000 | [diff] [blame] | 994 | |
sewardj | 796d6a2 | 2002-04-24 02:28:34 +0000 | [diff] [blame] | 995 | extern |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 996 | int __libc_recvfrom(int s, void *buf, size_t len, int flags, |
| 997 | struct sockaddr *from, socklen_t *fromlen); |
| 998 | __attribute__((weak)) |
| 999 | int recvfrom(int s, void *buf, size_t len, int flags, |
| 1000 | struct sockaddr *from, socklen_t *fromlen) |
| 1001 | { |
| 1002 | return __libc_recvfrom(s, buf, len, flags, from, fromlen); |
| 1003 | } |
| 1004 | |
| 1005 | |
| 1006 | extern |
sewardj | 796d6a2 | 2002-04-24 02:28:34 +0000 | [diff] [blame] | 1007 | int __libc_sendto(int s, const void *msg, size_t len, int flags, |
| 1008 | const struct sockaddr *to, socklen_t tolen); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1009 | __attribute__((weak)) |
sewardj | 796d6a2 | 2002-04-24 02:28:34 +0000 | [diff] [blame] | 1010 | int sendto(int s, const void *msg, size_t len, int flags, |
| 1011 | const struct sockaddr *to, socklen_t tolen) |
| 1012 | { |
| 1013 | return __libc_sendto(s, msg, len, flags, to, tolen); |
| 1014 | } |
| 1015 | |
sewardj | be32e45 | 2002-04-24 20:29:58 +0000 | [diff] [blame] | 1016 | |
sewardj | 369b170 | 2002-04-24 13:28:15 +0000 | [diff] [blame] | 1017 | extern |
| 1018 | int __libc_system(const char* str); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1019 | __attribute__((weak)) |
sewardj | 369b170 | 2002-04-24 13:28:15 +0000 | [diff] [blame] | 1020 | int system(const char* str) |
| 1021 | { |
| 1022 | return __libc_system(str); |
| 1023 | } |
| 1024 | |
sewardj | be32e45 | 2002-04-24 20:29:58 +0000 | [diff] [blame] | 1025 | |
sewardj | ab0b1c3 | 2002-04-24 19:26:47 +0000 | [diff] [blame] | 1026 | extern |
| 1027 | pid_t __libc_wait(int *status); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1028 | __attribute__((weak)) |
sewardj | ab0b1c3 | 2002-04-24 19:26:47 +0000 | [diff] [blame] | 1029 | pid_t wait(int *status) |
| 1030 | { |
| 1031 | return __libc_wait(status); |
| 1032 | } |
| 1033 | |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 1034 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1035 | |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 1036 | /* --------------------------------------------------------------------- |
| 1037 | Nonblocking implementations of select() and poll(). This stuff will |
| 1038 | surely rot your mind. |
| 1039 | ------------------------------------------------------------------ */ |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1040 | |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1041 | /*--------------------------------------------------*/ |
| 1042 | |
| 1043 | #include "vg_kerneliface.h" |
| 1044 | |
| 1045 | static |
| 1046 | __inline__ |
| 1047 | int is_kerror ( int res ) |
| 1048 | { |
| 1049 | if (res >= -4095 && res <= -1) |
| 1050 | return 1; |
| 1051 | else |
| 1052 | return 0; |
| 1053 | } |
| 1054 | |
| 1055 | |
| 1056 | static |
| 1057 | int my_do_syscall1 ( int syscallno, int arg1 ) |
| 1058 | { |
| 1059 | int __res; |
| 1060 | __asm__ volatile ("pushl %%ebx; movl %%edx,%%ebx ; int $0x80 ; popl %%ebx" |
| 1061 | : "=a" (__res) |
| 1062 | : "0" (syscallno), |
| 1063 | "d" (arg1) ); |
| 1064 | return __res; |
| 1065 | } |
| 1066 | |
| 1067 | static |
| 1068 | int my_do_syscall2 ( int syscallno, |
sewardj | f854f47 | 2002-04-21 12:19:41 +0000 | [diff] [blame] | 1069 | int arg1, int arg2 ) |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1070 | { |
| 1071 | int __res; |
| 1072 | __asm__ volatile ("pushl %%ebx; movl %%edx,%%ebx ; int $0x80 ; popl %%ebx" |
| 1073 | : "=a" (__res) |
| 1074 | : "0" (syscallno), |
| 1075 | "d" (arg1), |
| 1076 | "c" (arg2) ); |
| 1077 | return __res; |
| 1078 | } |
| 1079 | |
| 1080 | static |
sewardj | f854f47 | 2002-04-21 12:19:41 +0000 | [diff] [blame] | 1081 | int my_do_syscall3 ( int syscallno, |
| 1082 | int arg1, int arg2, int arg3 ) |
| 1083 | { |
| 1084 | int __res; |
| 1085 | __asm__ volatile ("pushl %%ebx; movl %%esi,%%ebx ; int $0x80 ; popl %%ebx" |
| 1086 | : "=a" (__res) |
| 1087 | : "0" (syscallno), |
| 1088 | "S" (arg1), |
| 1089 | "c" (arg2), |
| 1090 | "d" (arg3) ); |
| 1091 | return __res; |
| 1092 | } |
| 1093 | |
| 1094 | static |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1095 | int do_syscall_select( int n, |
| 1096 | vki_fd_set* readfds, |
| 1097 | vki_fd_set* writefds, |
| 1098 | vki_fd_set* exceptfds, |
| 1099 | struct vki_timeval * timeout ) |
| 1100 | { |
| 1101 | int res; |
| 1102 | int args[5]; |
| 1103 | args[0] = n; |
| 1104 | args[1] = (int)readfds; |
| 1105 | args[2] = (int)writefds; |
| 1106 | args[3] = (int)exceptfds; |
| 1107 | args[4] = (int)timeout; |
| 1108 | res = my_do_syscall1(__NR_select, (int)(&(args[0])) ); |
sewardj | 02535bc | 2002-04-21 01:08:26 +0000 | [diff] [blame] | 1109 | return res; |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1110 | } |
| 1111 | |
| 1112 | |
| 1113 | /* This is a wrapper round select(), which makes it thread-safe, |
| 1114 | meaning that only this thread will block, rather than the entire |
| 1115 | process. This wrapper in turn depends on nanosleep() not to block |
| 1116 | the entire process, but I think (hope? suspect?) that POSIX |
| 1117 | pthreads guarantees that to be the case. |
| 1118 | |
| 1119 | Basic idea is: modify the timeout parameter to select so that it |
| 1120 | returns immediately. Poll like this until select returns non-zero, |
| 1121 | indicating something interesting happened, or until our time is up. |
| 1122 | Space out the polls with nanosleeps of say 20 milliseconds, which |
| 1123 | is required to be nonblocking; this allows other threads to run. |
sewardj | 02535bc | 2002-04-21 01:08:26 +0000 | [diff] [blame] | 1124 | |
| 1125 | Assumes: |
| 1126 | * (checked via assert) types fd_set and vki_fd_set are identical. |
| 1127 | * (checked via assert) types timeval and vki_timeval are identical. |
| 1128 | * (unchecked) libc error numbers (EINTR etc) are the negation of the |
| 1129 | kernel's error numbers (VKI_EINTR etc). |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1130 | */ |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1131 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1132 | /* __attribute__((weak)) */ |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1133 | int select ( int n, |
| 1134 | fd_set *rfds, |
| 1135 | fd_set *wfds, |
| 1136 | fd_set *xfds, |
| 1137 | struct timeval *timeout ) |
| 1138 | { |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 1139 | unsigned int ms_now, ms_end; |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1140 | int res; |
| 1141 | fd_set rfds_copy; |
| 1142 | fd_set wfds_copy; |
| 1143 | fd_set xfds_copy; |
| 1144 | struct vki_timeval t_now; |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1145 | struct vki_timeval zero_timeout; |
| 1146 | struct vki_timespec nanosleep_interval; |
| 1147 | |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 1148 | /* gcc's complains about ms_end being used uninitialised -- classic |
| 1149 | case it can't understand, where ms_end is both defined and used |
| 1150 | only if timeout != NULL. Hence ... */ |
| 1151 | ms_end = 0; |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1152 | |
| 1153 | /* We assume that the kernel and libc data layouts are identical |
| 1154 | for the following types. These asserts provide a crude |
| 1155 | check. */ |
| 1156 | if (sizeof(fd_set) != sizeof(vki_fd_set) |
| 1157 | || sizeof(struct timeval) != sizeof(struct vki_timeval)) |
| 1158 | barf("valgrind's hacky non-blocking select(): data sizes error"); |
| 1159 | |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 1160 | /* Detect the current time and simultaneously find out if we are |
| 1161 | running on Valgrind. */ |
| 1162 | VALGRIND_MAGIC_SEQUENCE(ms_now, 0xFFFFFFFF /* default */, |
| 1163 | VG_USERREQ__READ_MILLISECOND_TIMER, |
| 1164 | 0, 0, 0, 0); |
| 1165 | |
| 1166 | /* If a zero timeout specified, this call is harmless. Also go |
| 1167 | this route if we're not running on Valgrind, for whatever |
| 1168 | reason. */ |
| 1169 | if ( (timeout && timeout->tv_sec == 0 && timeout->tv_usec == 0) |
| 1170 | || (ms_now == 0xFFFFFFFF) ) { |
sewardj | 02535bc | 2002-04-21 01:08:26 +0000 | [diff] [blame] | 1171 | res = do_syscall_select( n, (vki_fd_set*)rfds, |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1172 | (vki_fd_set*)wfds, |
| 1173 | (vki_fd_set*)xfds, |
| 1174 | (struct vki_timeval*)timeout); |
sewardj | 02535bc | 2002-04-21 01:08:26 +0000 | [diff] [blame] | 1175 | if (is_kerror(res)) { |
| 1176 | * (__errno_location()) = -res; |
| 1177 | return -1; |
| 1178 | } else { |
| 1179 | return res; |
| 1180 | } |
| 1181 | } |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1182 | |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 1183 | /* If a timeout was specified, set ms_end to be the end millisecond |
| 1184 | counter [wallclock] time. */ |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1185 | if (timeout) { |
| 1186 | res = my_do_syscall2(__NR_gettimeofday, (int)&t_now, (int)NULL); |
| 1187 | assert(res == 0); |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 1188 | ms_end = ms_now; |
| 1189 | ms_end += (timeout->tv_usec / 1000); |
| 1190 | ms_end += (timeout->tv_sec * 1000); |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1191 | /* Stay sane ... */ |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 1192 | assert (ms_end >= ms_now); |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1193 | } |
| 1194 | |
| 1195 | /* fprintf(stderr, "MY_SELECT: before loop\n"); */ |
| 1196 | |
| 1197 | /* Either timeout == NULL, meaning wait indefinitely, or timeout != |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 1198 | NULL, in which case ms_end holds the end time. */ |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1199 | while (1) { |
| 1200 | if (timeout) { |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 1201 | VALGRIND_MAGIC_SEQUENCE(ms_now, 0xFFFFFFFF /* default */, |
| 1202 | VG_USERREQ__READ_MILLISECOND_TIMER, |
| 1203 | 0, 0, 0, 0); |
| 1204 | assert(ms_now != 0xFFFFFFFF); |
| 1205 | if (ms_now >= ms_end) { |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1206 | /* timeout; nothing interesting happened. */ |
| 1207 | if (rfds) FD_ZERO(rfds); |
| 1208 | if (wfds) FD_ZERO(wfds); |
| 1209 | if (xfds) FD_ZERO(xfds); |
| 1210 | return 0; |
| 1211 | } |
| 1212 | } |
| 1213 | |
| 1214 | /* These could be trashed each time round the loop, so restore |
| 1215 | them each time. */ |
| 1216 | if (rfds) rfds_copy = *rfds; |
| 1217 | if (wfds) wfds_copy = *wfds; |
| 1218 | if (xfds) xfds_copy = *xfds; |
| 1219 | |
| 1220 | zero_timeout.tv_sec = zero_timeout.tv_usec = 0; |
| 1221 | |
| 1222 | res = do_syscall_select( n, |
| 1223 | rfds ? (vki_fd_set*)(&rfds_copy) : NULL, |
| 1224 | wfds ? (vki_fd_set*)(&wfds_copy) : NULL, |
| 1225 | xfds ? (vki_fd_set*)(&xfds_copy) : NULL, |
| 1226 | & zero_timeout ); |
sewardj | 02535bc | 2002-04-21 01:08:26 +0000 | [diff] [blame] | 1227 | if (is_kerror(res)) { |
| 1228 | /* Some kind of error (including EINTR). Set errno and |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1229 | return. The sets are unspecified in this case. */ |
sewardj | 02535bc | 2002-04-21 01:08:26 +0000 | [diff] [blame] | 1230 | * (__errno_location()) = -res; |
| 1231 | return -1; |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1232 | } |
| 1233 | if (res > 0) { |
| 1234 | /* one or more fds is ready. Copy out resulting sets and |
| 1235 | return. */ |
| 1236 | if (rfds) *rfds = rfds_copy; |
| 1237 | if (wfds) *wfds = wfds_copy; |
| 1238 | if (xfds) *xfds = xfds_copy; |
| 1239 | return res; |
| 1240 | } |
| 1241 | /* fprintf(stderr, "MY_SELECT: nanosleep\n"); */ |
| 1242 | /* nanosleep and go round again */ |
sewardj | 02535bc | 2002-04-21 01:08:26 +0000 | [diff] [blame] | 1243 | nanosleep_interval.tv_sec = 0; |
sewardj | 956cc1b | 2002-04-25 01:33:50 +0000 | [diff] [blame] | 1244 | nanosleep_interval.tv_nsec = 50 * 1000 * 1000; /* 50 milliseconds */ |
sewardj | f854f47 | 2002-04-21 12:19:41 +0000 | [diff] [blame] | 1245 | /* It's critical here that valgrind's nanosleep implementation |
| 1246 | is nonblocking. */ |
| 1247 | (void)my_do_syscall2(__NR_nanosleep, |
| 1248 | (int)(&nanosleep_interval), (int)NULL); |
| 1249 | } |
| 1250 | } |
| 1251 | |
| 1252 | |
| 1253 | |
| 1254 | |
| 1255 | #include <sys/poll.h> |
| 1256 | |
sewardj | 72d5848 | 2002-04-24 02:20:20 +0000 | [diff] [blame] | 1257 | #ifdef GLIBC_2_1 |
| 1258 | typedef unsigned long int nfds_t; |
| 1259 | #endif |
| 1260 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1261 | /* __attribute__((weak)) */ |
sewardj | f854f47 | 2002-04-21 12:19:41 +0000 | [diff] [blame] | 1262 | int poll (struct pollfd *__fds, nfds_t __nfds, int __timeout) |
| 1263 | { |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 1264 | unsigned int ms_now, ms_end; |
sewardj | f854f47 | 2002-04-21 12:19:41 +0000 | [diff] [blame] | 1265 | int res, i; |
sewardj | f854f47 | 2002-04-21 12:19:41 +0000 | [diff] [blame] | 1266 | struct vki_timespec nanosleep_interval; |
| 1267 | |
| 1268 | ensure_valgrind("poll"); |
| 1269 | |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 1270 | /* Detect the current time and simultaneously find out if we are |
| 1271 | running on Valgrind. */ |
| 1272 | VALGRIND_MAGIC_SEQUENCE(ms_now, 0xFFFFFFFF /* default */, |
| 1273 | VG_USERREQ__READ_MILLISECOND_TIMER, |
| 1274 | 0, 0, 0, 0); |
| 1275 | |
sewardj | f854f47 | 2002-04-21 12:19:41 +0000 | [diff] [blame] | 1276 | if (/* CHECK SIZES FOR struct pollfd */ |
| 1277 | sizeof(struct timeval) != sizeof(struct vki_timeval)) |
| 1278 | barf("valgrind's hacky non-blocking poll(): data sizes error"); |
| 1279 | |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 1280 | /* dummy initialisation to keep gcc -Wall happy */ |
| 1281 | ms_end = 0; |
| 1282 | |
| 1283 | /* If a zero timeout specified, this call is harmless. Also do |
| 1284 | this if not running on Valgrind. */ |
| 1285 | if (__timeout == 0 || ms_now == 0xFFFFFFFF) { |
sewardj | f854f47 | 2002-04-21 12:19:41 +0000 | [diff] [blame] | 1286 | res = my_do_syscall3(__NR_poll, (int)__fds, __nfds, __timeout); |
| 1287 | if (is_kerror(res)) { |
| 1288 | * (__errno_location()) = -res; |
| 1289 | return -1; |
| 1290 | } else { |
| 1291 | return res; |
| 1292 | } |
| 1293 | } |
| 1294 | |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 1295 | /* If a timeout was specified, set ms_end to be the end wallclock |
| 1296 | time. Easy considering that __timeout is in milliseconds. */ |
sewardj | f854f47 | 2002-04-21 12:19:41 +0000 | [diff] [blame] | 1297 | if (__timeout > 0) { |
sewardj | 650ac00 | 2002-04-29 12:20:34 +0000 | [diff] [blame^] | 1298 | ms_end = ms_now + (unsigned int)__timeout; |
sewardj | f854f47 | 2002-04-21 12:19:41 +0000 | [diff] [blame] | 1299 | } |
| 1300 | |
| 1301 | /* fprintf(stderr, "MY_POLL: before loop\n"); */ |
| 1302 | |
| 1303 | /* Either timeout < 0, meaning wait indefinitely, or timeout > 0, |
| 1304 | in which case t_end holds the end time. */ |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 1305 | assert(__timeout != 0); |
| 1306 | |
sewardj | f854f47 | 2002-04-21 12:19:41 +0000 | [diff] [blame] | 1307 | while (1) { |
sewardj | f854f47 | 2002-04-21 12:19:41 +0000 | [diff] [blame] | 1308 | if (__timeout > 0) { |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 1309 | VALGRIND_MAGIC_SEQUENCE(ms_now, 0xFFFFFFFF /* default */, |
| 1310 | VG_USERREQ__READ_MILLISECOND_TIMER, |
| 1311 | 0, 0, 0, 0); |
| 1312 | assert(ms_now != 0xFFFFFFFF); |
| 1313 | if (ms_now >= ms_end) { |
sewardj | f854f47 | 2002-04-21 12:19:41 +0000 | [diff] [blame] | 1314 | /* timeout; nothing interesting happened. */ |
| 1315 | for (i = 0; i < __nfds; i++) |
| 1316 | __fds[i].revents = 0; |
| 1317 | return 0; |
| 1318 | } |
| 1319 | } |
| 1320 | |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 1321 | /* Do a return-immediately poll. */ |
sewardj | f854f47 | 2002-04-21 12:19:41 +0000 | [diff] [blame] | 1322 | res = my_do_syscall3(__NR_poll, (int)__fds, __nfds, 0 ); |
| 1323 | if (is_kerror(res)) { |
| 1324 | /* Some kind of error. Set errno and return. */ |
| 1325 | * (__errno_location()) = -res; |
| 1326 | return -1; |
| 1327 | } |
| 1328 | if (res > 0) { |
| 1329 | /* One or more fds is ready. Return now. */ |
| 1330 | return res; |
| 1331 | } |
| 1332 | /* fprintf(stderr, "MY_POLL: nanosleep\n"); */ |
| 1333 | /* nanosleep and go round again */ |
| 1334 | nanosleep_interval.tv_sec = 0; |
sewardj | 956cc1b | 2002-04-25 01:33:50 +0000 | [diff] [blame] | 1335 | nanosleep_interval.tv_nsec = 51 * 1000 * 1000; /* 51 milliseconds */ |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1336 | /* It's critical here that valgrind's nanosleep implementation |
| 1337 | is nonblocking. */ |
| 1338 | (void)my_do_syscall2(__NR_nanosleep, |
| 1339 | (int)(&nanosleep_interval), (int)NULL); |
| 1340 | } |
| 1341 | } |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 1342 | |
| 1343 | |
| 1344 | /* --------------------------------------------------------------------- |
| 1345 | B'stard. |
| 1346 | ------------------------------------------------------------------ */ |
| 1347 | |
| 1348 | # define strong_alias(name, aliasname) \ |
| 1349 | extern __typeof (name) aliasname __attribute__ ((alias (#name))); |
| 1350 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1351 | # define weak_alias(name, aliasname) \ |
| 1352 | extern __typeof (name) aliasname __attribute__ ((weak, alias (#name))); |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 1353 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1354 | #if 1 |
| 1355 | strong_alias(__pthread_mutex_lock, pthread_mutex_lock) |
| 1356 | strong_alias(__pthread_mutex_trylock, pthread_mutex_trylock) |
| 1357 | strong_alias(__pthread_mutex_unlock, pthread_mutex_unlock) |
| 1358 | strong_alias(__pthread_mutexattr_init, pthread_mutexattr_init) |
| 1359 | weak_alias(__pthread_mutexattr_settype, pthread_mutexattr_settype) |
| 1360 | strong_alias(__pthread_mutex_init, pthread_mutex_init) |
| 1361 | strong_alias(__pthread_mutexattr_destroy, pthread_mutexattr_destroy) |
| 1362 | strong_alias(__pthread_mutex_destroy, pthread_mutex_destroy) |
| 1363 | strong_alias(__pthread_once, pthread_once) |
| 1364 | strong_alias(__pthread_atfork, pthread_atfork) |
| 1365 | strong_alias(__pthread_key_create, pthread_key_create) |
| 1366 | strong_alias(__pthread_getspecific, pthread_getspecific) |
| 1367 | strong_alias(__pthread_setspecific, pthread_setspecific) |
| 1368 | |
| 1369 | //strong_alias(__sigaction, sigaction) |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 1370 | strong_alias(sigaction, __sigaction) |
| 1371 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1372 | strong_alias(close, __close) |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 1373 | strong_alias(fcntl, __fcntl) |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1374 | strong_alias(lseek, __lseek) |
| 1375 | strong_alias(open, __open) |
| 1376 | strong_alias(open64, __open64) |
| 1377 | //strong_alias(pread64, __pread64) |
| 1378 | //strong_alias(pwrite64, __pwrite64) |
| 1379 | strong_alias(read, __read) |
| 1380 | strong_alias(wait, __wait) |
| 1381 | strong_alias(write, __write) |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 1382 | strong_alias(connect, __connect) |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1383 | strong_alias(send, __send) |
| 1384 | |
| 1385 | weak_alias(__fork, fork) |
| 1386 | //weak_alias(__vfork, vfork) |
| 1387 | |
| 1388 | #endif |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 1389 | |
| 1390 | /*--------------------------------------------------*/ |
| 1391 | |
sewardj | 5716dbb | 2002-04-26 03:28:18 +0000 | [diff] [blame] | 1392 | int |
| 1393 | pthread_rwlock_rdlock (void* /* pthread_rwlock_t* */ rwlock) |
| 1394 | { |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 1395 | static int moans = N_MOANS; |
| 1396 | if (moans-- > 0) |
| 1397 | kludged("pthread_rwlock_rdlock"); |
sewardj | 5716dbb | 2002-04-26 03:28:18 +0000 | [diff] [blame] | 1398 | return 0; |
| 1399 | } |
| 1400 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1401 | weak_alias(pthread_rwlock_rdlock, __pthread_rwlock_rdlock) |
sewardj | 5716dbb | 2002-04-26 03:28:18 +0000 | [diff] [blame] | 1402 | |
| 1403 | |
| 1404 | int |
| 1405 | pthread_rwlock_unlock (void* /* pthread_rwlock_t* */ rwlock) |
| 1406 | { |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 1407 | static int moans = N_MOANS; |
| 1408 | if (moans-- > 0) |
| 1409 | kludged("pthread_rwlock_unlock"); |
sewardj | 5716dbb | 2002-04-26 03:28:18 +0000 | [diff] [blame] | 1410 | return 0; |
| 1411 | } |
| 1412 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1413 | weak_alias(pthread_rwlock_unlock, __pthread_rwlock_unlock) |
sewardj | 5716dbb | 2002-04-26 03:28:18 +0000 | [diff] [blame] | 1414 | |
| 1415 | |
sewardj | 060b04f | 2002-04-26 21:01:13 +0000 | [diff] [blame] | 1416 | int |
| 1417 | pthread_rwlock_wrlock (void* /* pthread_rwlock_t* */ rwlock) |
| 1418 | { |
| 1419 | static int moans = N_MOANS; |
| 1420 | if (moans-- > 0) |
| 1421 | kludged("pthread_rwlock_wrlock"); |
| 1422 | return 0; |
| 1423 | } |
| 1424 | |
| 1425 | weak_alias(pthread_rwlock_wrlock, __pthread_wrlock_unlock) |
| 1426 | |
| 1427 | |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 1428 | /* I've no idea what these are, but they get called quite a lot. |
| 1429 | Anybody know? */ |
| 1430 | |
| 1431 | #undef _IO_flockfile |
| 1432 | void _IO_flockfile ( _IO_FILE * file ) |
| 1433 | { |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 1434 | //char* str = "_IO_flockfile\n"; |
| 1435 | //write(2, str, strlen(str)); |
| 1436 | pthread_mutex_lock(file->_lock); |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 1437 | // barf("_IO_flockfile"); |
| 1438 | } |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1439 | weak_alias(_IO_flockfile, flockfile); |
| 1440 | |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 1441 | |
| 1442 | #undef _IO_funlockfile |
| 1443 | void _IO_funlockfile ( _IO_FILE * file ) |
| 1444 | { |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 1445 | //char* str = "_IO_funlockfile\n"; |
| 1446 | //write(2, str, strlen(str)); |
| 1447 | pthread_mutex_unlock(file->_lock); |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 1448 | // barf("_IO_funlockfile"); |
| 1449 | } |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1450 | weak_alias(_IO_funlockfile, funlockfile); |
| 1451 | |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 1452 | |
| 1453 | void _pthread_cleanup_push_defer ( void ) |
| 1454 | { |
| 1455 | // char* str = "_pthread_cleanup_push_defer\n"; |
| 1456 | // write(2, str, strlen(str)); |
| 1457 | } |
| 1458 | |
| 1459 | void _pthread_cleanup_pop_restore ( void ) |
| 1460 | { |
| 1461 | // char* str = "_pthread_cleanup_pop_restore\n"; |
| 1462 | // write(2, str, strlen(str)); |
| 1463 | } |