sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1 | |
sewardj | 439d45e | 2002-05-03 20:43:10 +0000 | [diff] [blame] | 2 | /*--------------------------------------------------------------------*/ |
| 3 | /*--- A replacement for the standard libpthread.so. ---*/ |
| 4 | /*--- vg_libpthread.c ---*/ |
| 5 | /*--------------------------------------------------------------------*/ |
| 6 | |
| 7 | /* |
| 8 | This file is part of Valgrind, an x86 protected-mode emulator |
| 9 | designed for debugging and profiling binaries on x86-Unixes. |
| 10 | |
| 11 | Copyright (C) 2000-2002 Julian Seward |
| 12 | jseward@acm.org |
| 13 | |
| 14 | This program is free software; you can redistribute it and/or |
| 15 | modify it under the terms of the GNU General Public License as |
| 16 | published by the Free Software Foundation; either version 2 of the |
| 17 | License, or (at your option) any later version. |
| 18 | |
| 19 | This program is distributed in the hope that it will be useful, but |
| 20 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 22 | General Public License for more details. |
| 23 | |
| 24 | You should have received a copy of the GNU General Public License |
| 25 | along with this program; if not, write to the Free Software |
| 26 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 27 | 02111-1307, USA. |
| 28 | |
| 29 | The GNU General Public License is contained in the file LICENSE. |
| 30 | */ |
| 31 | |
| 32 | /* ALL THIS CODE RUNS ON THE SIMULATED CPU. |
| 33 | |
| 34 | This is a replacement for the standard libpthread.so. It is loaded |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 35 | as part of the client's image (if required) and directs pthread |
| 36 | calls through to Valgrind's request mechanism. |
| 37 | |
| 38 | A couple of caveats. |
| 39 | |
| 40 | 1. Since it's a binary-compatible replacement for an existing library, |
| 41 | we must take care to used exactly the same data layouts, etc, as |
| 42 | the standard pthread.so does. |
| 43 | |
| 44 | 2. Since this runs as part of the client, there are no specific |
| 45 | restrictions on what headers etc we can include, so long as |
| 46 | this libpthread.so does not end up having dependencies on .so's |
| 47 | which the real one doesn't. |
| 48 | |
| 49 | Later ... it appears we cannot call file-related stuff in libc here, |
| 50 | perhaps fair enough. Be careful what you call from here. Even exit() |
| 51 | doesn't work (gives infinite recursion and then stack overflow); hence |
| 52 | myexit(). Also fprintf doesn't seem safe. |
| 53 | */ |
| 54 | |
| 55 | #include "valgrind.h" /* For the request-passing mechanism */ |
| 56 | #include "vg_include.h" /* For the VG_USERREQ__* constants */ |
| 57 | |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 58 | #include <unistd.h> |
| 59 | #include <string.h> |
sewardj | 2a1dcce | 2002-04-22 12:45:25 +0000 | [diff] [blame] | 60 | #ifdef GLIBC_2_1 |
| 61 | #include <sys/time.h> |
| 62 | #endif |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 63 | |
| 64 | /* --------------------------------------------------------------------- |
| 65 | Helpers. We have to be pretty self-sufficient. |
| 66 | ------------------------------------------------------------------ */ |
| 67 | |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 68 | /* Number of times any given error message is printed. */ |
| 69 | #define N_MOANS 3 |
| 70 | |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 71 | /* Extract from Valgrind the value of VG_(clo_trace_pthread_level). |
| 72 | Returns 0 (none) if not running on Valgrind. */ |
| 73 | static |
| 74 | int get_pt_trace_level ( void ) |
| 75 | { |
| 76 | int res; |
| 77 | VALGRIND_MAGIC_SEQUENCE(res, 0 /* default */, |
| 78 | VG_USERREQ__GET_PTHREAD_TRACE_LEVEL, |
| 79 | 0, 0, 0, 0); |
| 80 | return res; |
| 81 | } |
| 82 | |
| 83 | |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 84 | static |
| 85 | void myexit ( int arg ) |
| 86 | { |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 87 | int __res; |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 88 | __asm__ volatile ("movl %%ecx, %%ebx ; int $0x80" |
| 89 | : "=a" (__res) |
| 90 | : "0" (__NR_exit), |
| 91 | "c" (arg) ); |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 92 | /* We don't bother to mention the fact that this asm trashes %ebx, |
| 93 | since it won't return. If you ever do let it return ... fix |
| 94 | this! */ |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | |
sewardj | 68b2dd9 | 2002-05-10 21:03:56 +0000 | [diff] [blame] | 98 | /* We need this guy -- it's in valgrind.so. */ |
| 99 | extern void VG_(startup) ( void ); |
| 100 | |
| 101 | |
| 102 | /* Just start up Valgrind if it's not already going. VG_(startup)() |
| 103 | detects and ignores second and subsequent calls. */ |
sewardj | 604ec3c | 2002-04-18 22:38:41 +0000 | [diff] [blame] | 104 | static __inline__ |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 105 | void ensure_valgrind ( char* caller ) |
| 106 | { |
sewardj | 68b2dd9 | 2002-05-10 21:03:56 +0000 | [diff] [blame] | 107 | VG_(startup)(); |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 108 | } |
| 109 | |
sewardj | bea1caa | 2002-05-10 23:20:58 +0000 | [diff] [blame] | 110 | /* While we're at it ... hook our own startup function into this |
| 111 | game. */ |
| 112 | __asm__ ( |
| 113 | ".section .init\n" |
| 114 | "\tcall vgPlain_startup" |
| 115 | ); |
| 116 | |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 117 | |
| 118 | static |
sewardj | 3b5d886 | 2002-04-20 13:53:23 +0000 | [diff] [blame] | 119 | __attribute__((noreturn)) |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 120 | void barf ( char* str ) |
| 121 | { |
| 122 | char buf[100]; |
| 123 | buf[0] = 0; |
sewardj | 439d45e | 2002-05-03 20:43:10 +0000 | [diff] [blame] | 124 | strcat(buf, "\nvalgrind's libpthread.so: "); |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 125 | strcat(buf, str); |
| 126 | strcat(buf, "\n\n"); |
| 127 | write(2, buf, strlen(buf)); |
| 128 | myexit(1); |
sewardj | 3b5d886 | 2002-04-20 13:53:23 +0000 | [diff] [blame] | 129 | /* We have to persuade gcc into believing this doesn't return. */ |
| 130 | while (1) { }; |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | |
sewardj | 2a3d28c | 2002-04-14 13:27:00 +0000 | [diff] [blame] | 134 | static void ignored ( char* msg ) |
| 135 | { |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 136 | if (get_pt_trace_level() >= 0) { |
sewardj | 439d45e | 2002-05-03 20:43:10 +0000 | [diff] [blame] | 137 | char* ig = "valgrind's libpthread.so: IGNORED call to: "; |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 138 | write(2, ig, strlen(ig)); |
| 139 | write(2, msg, strlen(msg)); |
| 140 | ig = "\n"; |
| 141 | write(2, ig, strlen(ig)); |
| 142 | } |
sewardj | 2a3d28c | 2002-04-14 13:27:00 +0000 | [diff] [blame] | 143 | } |
| 144 | |
sewardj | 30671ff | 2002-04-21 00:13:57 +0000 | [diff] [blame] | 145 | static void kludged ( char* msg ) |
| 146 | { |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 147 | if (get_pt_trace_level() >= 0) { |
sewardj | 439d45e | 2002-05-03 20:43:10 +0000 | [diff] [blame] | 148 | char* ig = "valgrind's libpthread.so: KLUDGED call to: "; |
| 149 | write(2, ig, strlen(ig)); |
| 150 | write(2, msg, strlen(msg)); |
| 151 | ig = "\n"; |
| 152 | write(2, ig, strlen(ig)); |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | static void not_inside ( char* msg ) |
| 157 | { |
sewardj | 68b2dd9 | 2002-05-10 21:03:56 +0000 | [diff] [blame] | 158 | VG_(startup)(); |
sewardj | 30671ff | 2002-04-21 00:13:57 +0000 | [diff] [blame] | 159 | } |
| 160 | |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 161 | void vgPlain_unimp ( char* what ) |
| 162 | { |
sewardj | 439d45e | 2002-05-03 20:43:10 +0000 | [diff] [blame] | 163 | char* ig = "valgrind's libpthread.so: UNIMPLEMENTED FUNCTION: "; |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 164 | write(2, ig, strlen(ig)); |
| 165 | write(2, what, strlen(what)); |
| 166 | ig = "\n"; |
| 167 | write(2, ig, strlen(ig)); |
| 168 | barf("Please report this bug to me at: jseward@acm.org"); |
| 169 | } |
| 170 | |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 171 | |
| 172 | /* --------------------------------------------------------------------- |
| 173 | Pass pthread_ calls to Valgrind's request mechanism. |
| 174 | ------------------------------------------------------------------ */ |
| 175 | |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 176 | #include <pthread.h> |
| 177 | #include <stdio.h> |
| 178 | #include <errno.h> |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 179 | #include <assert.h> |
| 180 | #include <sys/time.h> /* gettimeofday */ |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 181 | |
| 182 | /* --------------------------------------------------- |
| 183 | THREAD ATTRIBUTES |
| 184 | ------------------------------------------------ */ |
| 185 | |
sewardj | 6af4b5d | 2002-04-16 04:40:49 +0000 | [diff] [blame] | 186 | int pthread_attr_init(pthread_attr_t *attr) |
| 187 | { |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 188 | static int moans = N_MOANS; |
| 189 | if (moans-- > 0) |
| 190 | ignored("pthread_attr_init"); |
sewardj | 6af4b5d | 2002-04-16 04:40:49 +0000 | [diff] [blame] | 191 | return 0; |
| 192 | } |
| 193 | |
| 194 | int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate) |
| 195 | { |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 196 | static int moans = N_MOANS; |
| 197 | if (moans-- > 0) |
| 198 | ignored("pthread_attr_setdetachstate"); |
sewardj | 6af4b5d | 2002-04-16 04:40:49 +0000 | [diff] [blame] | 199 | return 0; |
| 200 | } |
| 201 | |
sewardj | 30671ff | 2002-04-21 00:13:57 +0000 | [diff] [blame] | 202 | int pthread_attr_setinheritsched(pthread_attr_t *attr, int inherit) |
| 203 | { |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 204 | static int moans = N_MOANS; |
| 205 | if (moans-- > 0) |
| 206 | ignored("pthread_attr_setinheritsched"); |
sewardj | 30671ff | 2002-04-21 00:13:57 +0000 | [diff] [blame] | 207 | return 0; |
| 208 | } |
sewardj | 6af4b5d | 2002-04-16 04:40:49 +0000 | [diff] [blame] | 209 | |
sewardj | 0286dd5 | 2002-05-16 20:51:15 +0000 | [diff] [blame] | 210 | __attribute__((weak)) |
| 211 | int pthread_attr_setstacksize (pthread_attr_t *__attr, |
| 212 | size_t __stacksize) |
| 213 | { |
sewardj | a18e210 | 2002-05-18 10:43:22 +0000 | [diff] [blame] | 214 | size_t limit; |
sewardj | 0286dd5 | 2002-05-16 20:51:15 +0000 | [diff] [blame] | 215 | ensure_valgrind("pthread_attr_setstacksize"); |
sewardj | a18e210 | 2002-05-18 10:43:22 +0000 | [diff] [blame] | 216 | limit = VG_PTHREAD_STACK_SIZE - VG_AR_CLIENT_STACKBASE_REDZONE_SZB |
| 217 | - 1000; /* paranoia */ |
| 218 | if (__stacksize < limit) |
sewardj | 0286dd5 | 2002-05-16 20:51:15 +0000 | [diff] [blame] | 219 | return 0; |
| 220 | barf("pthread_attr_setstacksize: " |
| 221 | "requested size >= VG_PTHREAD_STACK_SIZE\n " |
| 222 | "edit vg_include.h and rebuild."); |
| 223 | } |
| 224 | |
| 225 | |
sewardj | 30671ff | 2002-04-21 00:13:57 +0000 | [diff] [blame] | 226 | /* This is completely bogus. */ |
| 227 | int pthread_attr_getschedparam(const pthread_attr_t *attr, |
| 228 | struct sched_param *param) |
| 229 | { |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 230 | static int moans = N_MOANS; |
| 231 | if (moans-- > 0) |
| 232 | kludged("pthread_attr_getschedparam"); |
sewardj | 72d5848 | 2002-04-24 02:20:20 +0000 | [diff] [blame] | 233 | # ifdef GLIBC_2_1 |
| 234 | if (param) param->sched_priority = 0; /* who knows */ |
| 235 | # else |
sewardj | 30671ff | 2002-04-21 00:13:57 +0000 | [diff] [blame] | 236 | if (param) param->__sched_priority = 0; /* who knows */ |
sewardj | 72d5848 | 2002-04-24 02:20:20 +0000 | [diff] [blame] | 237 | # endif |
sewardj | 30671ff | 2002-04-21 00:13:57 +0000 | [diff] [blame] | 238 | return 0; |
| 239 | } |
| 240 | |
| 241 | int pthread_attr_setschedparam(pthread_attr_t *attr, |
| 242 | const struct sched_param *param) |
| 243 | { |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 244 | static int moans = N_MOANS; |
| 245 | if (moans-- > 0) |
| 246 | ignored("pthread_attr_setschedparam"); |
sewardj | 30671ff | 2002-04-21 00:13:57 +0000 | [diff] [blame] | 247 | return 0; |
| 248 | } |
| 249 | |
| 250 | int pthread_attr_destroy(pthread_attr_t *attr) |
| 251 | { |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 252 | static int moans = N_MOANS; |
| 253 | if (moans-- > 0) |
| 254 | ignored("pthread_attr_destroy"); |
sewardj | 30671ff | 2002-04-21 00:13:57 +0000 | [diff] [blame] | 255 | return 0; |
| 256 | } |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 257 | |
| 258 | /* --------------------------------------------------- |
| 259 | THREADs |
| 260 | ------------------------------------------------ */ |
| 261 | |
sewardj | 6072c36 | 2002-04-19 14:40:57 +0000 | [diff] [blame] | 262 | int pthread_equal(pthread_t thread1, pthread_t thread2) |
| 263 | { |
| 264 | return thread1 == thread2 ? 1 : 0; |
| 265 | } |
| 266 | |
| 267 | |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 268 | int |
| 269 | pthread_create (pthread_t *__restrict __thread, |
| 270 | __const pthread_attr_t *__restrict __attr, |
| 271 | void *(*__start_routine) (void *), |
| 272 | void *__restrict __arg) |
| 273 | { |
| 274 | int res; |
| 275 | ensure_valgrind("pthread_create"); |
| 276 | VALGRIND_MAGIC_SEQUENCE(res, 0 /* default */, |
| 277 | VG_USERREQ__PTHREAD_CREATE, |
| 278 | __thread, __attr, __start_routine, __arg); |
| 279 | return res; |
| 280 | } |
| 281 | |
| 282 | |
| 283 | |
| 284 | int |
| 285 | pthread_join (pthread_t __th, void **__thread_return) |
| 286 | { |
| 287 | int res; |
| 288 | ensure_valgrind("pthread_join"); |
| 289 | VALGRIND_MAGIC_SEQUENCE(res, 0 /* default */, |
| 290 | VG_USERREQ__PTHREAD_JOIN, |
| 291 | __th, __thread_return, 0, 0); |
| 292 | return res; |
| 293 | } |
| 294 | |
| 295 | |
sewardj | 3b5d886 | 2002-04-20 13:53:23 +0000 | [diff] [blame] | 296 | void pthread_exit(void *retval) |
| 297 | { |
| 298 | int res; |
| 299 | ensure_valgrind("pthread_exit"); |
| 300 | VALGRIND_MAGIC_SEQUENCE(res, 0 /* default */, |
| 301 | VG_USERREQ__PTHREAD_EXIT, |
| 302 | retval, 0, 0, 0); |
| 303 | /* Doesn't return! */ |
| 304 | /* However, we have to fool gcc into knowing that. */ |
| 305 | barf("pthread_exit: still alive after request?!"); |
| 306 | } |
| 307 | |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 308 | |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 309 | pthread_t pthread_self(void) |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 310 | { |
| 311 | int tid; |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 312 | ensure_valgrind("pthread_self"); |
sewardj | 439d45e | 2002-05-03 20:43:10 +0000 | [diff] [blame] | 313 | VALGRIND_MAGIC_SEQUENCE(tid, 1 /* default */, |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 314 | VG_USERREQ__PTHREAD_GET_THREADID, |
| 315 | 0, 0, 0, 0); |
sewardj | 439d45e | 2002-05-03 20:43:10 +0000 | [diff] [blame] | 316 | if (tid < 1 || tid >= VG_N_THREADS) |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 317 | barf("pthread_self: invalid ThreadId"); |
| 318 | return tid; |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 322 | int pthread_detach(pthread_t th) |
| 323 | { |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 324 | static int moans = N_MOANS; |
| 325 | if (moans-- > 0) |
| 326 | ignored("pthread_detach"); |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 327 | return 0; |
| 328 | } |
| 329 | |
| 330 | |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 331 | /* --------------------------------------------------- |
| 332 | MUTEX ATTRIBUTES |
| 333 | ------------------------------------------------ */ |
| 334 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 335 | int __pthread_mutexattr_init(pthread_mutexattr_t *attr) |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 336 | { |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 337 | attr->__mutexkind = PTHREAD_MUTEX_ERRORCHECK_NP; |
sewardj | 8937c81 | 2002-04-12 20:12:20 +0000 | [diff] [blame] | 338 | return 0; |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 339 | } |
| 340 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 341 | int __pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type) |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 342 | { |
| 343 | switch (type) { |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 344 | # ifndef GLIBC_2_1 |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 345 | case PTHREAD_MUTEX_TIMED_NP: |
sewardj | 2a1dcce | 2002-04-22 12:45:25 +0000 | [diff] [blame] | 346 | case PTHREAD_MUTEX_ADAPTIVE_NP: |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 347 | # endif |
sewardj | a1679dd | 2002-05-10 22:31:40 +0000 | [diff] [blame] | 348 | # ifdef GLIBC_2_1 |
sewardj | 68b2dd9 | 2002-05-10 21:03:56 +0000 | [diff] [blame] | 349 | case PTHREAD_MUTEX_FAST_NP: |
sewardj | a1679dd | 2002-05-10 22:31:40 +0000 | [diff] [blame] | 350 | # endif |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 351 | case PTHREAD_MUTEX_RECURSIVE_NP: |
| 352 | case PTHREAD_MUTEX_ERRORCHECK_NP: |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 353 | attr->__mutexkind = type; |
| 354 | return 0; |
| 355 | default: |
| 356 | return EINVAL; |
| 357 | } |
| 358 | } |
| 359 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 360 | int __pthread_mutexattr_destroy(pthread_mutexattr_t *attr) |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 361 | { |
| 362 | return 0; |
| 363 | } |
| 364 | |
| 365 | |
| 366 | /* --------------------------------------------------- |
| 367 | MUTEXes |
| 368 | ------------------------------------------------ */ |
| 369 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 370 | int __pthread_mutex_init(pthread_mutex_t *mutex, |
| 371 | const pthread_mutexattr_t *mutexattr) |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 372 | { |
sewardj | 604ec3c | 2002-04-18 22:38:41 +0000 | [diff] [blame] | 373 | mutex->__m_count = 0; |
| 374 | mutex->__m_owner = (_pthread_descr)VG_INVALID_THREADID; |
| 375 | mutex->__m_kind = PTHREAD_MUTEX_ERRORCHECK_NP; |
| 376 | if (mutexattr) |
| 377 | mutex->__m_kind = mutexattr->__mutexkind; |
| 378 | return 0; |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 379 | } |
| 380 | |
sewardj | 439d45e | 2002-05-03 20:43:10 +0000 | [diff] [blame] | 381 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 382 | int __pthread_mutex_lock(pthread_mutex_t *mutex) |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 383 | { |
| 384 | int res; |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 385 | static int moans = N_MOANS; |
sewardj | 439d45e | 2002-05-03 20:43:10 +0000 | [diff] [blame] | 386 | if (RUNNING_ON_VALGRIND) { |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 387 | VALGRIND_MAGIC_SEQUENCE(res, 0 /* default */, |
| 388 | VG_USERREQ__PTHREAD_MUTEX_LOCK, |
| 389 | mutex, 0, 0, 0); |
| 390 | return res; |
sewardj | 439d45e | 2002-05-03 20:43:10 +0000 | [diff] [blame] | 391 | } else { |
| 392 | if (moans-- > 0) |
| 393 | not_inside("pthread_mutex_lock"); |
| 394 | return 0; /* success */ |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 395 | } |
| 396 | } |
| 397 | |
sewardj | 439d45e | 2002-05-03 20:43:10 +0000 | [diff] [blame] | 398 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 399 | int __pthread_mutex_trylock(pthread_mutex_t *mutex) |
sewardj | 30671ff | 2002-04-21 00:13:57 +0000 | [diff] [blame] | 400 | { |
| 401 | int res; |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 402 | static int moans = N_MOANS; |
sewardj | 439d45e | 2002-05-03 20:43:10 +0000 | [diff] [blame] | 403 | if (RUNNING_ON_VALGRIND) { |
sewardj | 30671ff | 2002-04-21 00:13:57 +0000 | [diff] [blame] | 404 | VALGRIND_MAGIC_SEQUENCE(res, 0 /* default */, |
| 405 | VG_USERREQ__PTHREAD_MUTEX_TRYLOCK, |
| 406 | mutex, 0, 0, 0); |
| 407 | return res; |
sewardj | 439d45e | 2002-05-03 20:43:10 +0000 | [diff] [blame] | 408 | } else { |
| 409 | if (moans-- > 0) |
| 410 | not_inside("pthread_mutex_trylock"); |
| 411 | return 0; |
sewardj | 30671ff | 2002-04-21 00:13:57 +0000 | [diff] [blame] | 412 | } |
| 413 | } |
| 414 | |
sewardj | 439d45e | 2002-05-03 20:43:10 +0000 | [diff] [blame] | 415 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 416 | int __pthread_mutex_unlock(pthread_mutex_t *mutex) |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 417 | { |
| 418 | int res; |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 419 | static int moans = N_MOANS; |
sewardj | 439d45e | 2002-05-03 20:43:10 +0000 | [diff] [blame] | 420 | if (RUNNING_ON_VALGRIND) { |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 421 | VALGRIND_MAGIC_SEQUENCE(res, 0 /* default */, |
| 422 | VG_USERREQ__PTHREAD_MUTEX_UNLOCK, |
| 423 | mutex, 0, 0, 0); |
| 424 | return res; |
sewardj | 439d45e | 2002-05-03 20:43:10 +0000 | [diff] [blame] | 425 | } else { |
| 426 | if (moans-- > 0) |
| 427 | not_inside("pthread_mutex_unlock"); |
| 428 | return 0; |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 429 | } |
| 430 | } |
| 431 | |
sewardj | 439d45e | 2002-05-03 20:43:10 +0000 | [diff] [blame] | 432 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 433 | int __pthread_mutex_destroy(pthread_mutex_t *mutex) |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 434 | { |
sewardj | 604ec3c | 2002-04-18 22:38:41 +0000 | [diff] [blame] | 435 | /* Valgrind doesn't hold any resources on behalf of the mutex, so no |
| 436 | need to involve it. */ |
| 437 | if (mutex->__m_count > 0) |
| 438 | return EBUSY; |
sewardj | 6072c36 | 2002-04-19 14:40:57 +0000 | [diff] [blame] | 439 | mutex->__m_count = 0; |
| 440 | mutex->__m_owner = (_pthread_descr)VG_INVALID_THREADID; |
| 441 | mutex->__m_kind = PTHREAD_MUTEX_ERRORCHECK_NP; |
sewardj | 604ec3c | 2002-04-18 22:38:41 +0000 | [diff] [blame] | 442 | return 0; |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 446 | /* --------------------------------------------------- |
sewardj | 6072c36 | 2002-04-19 14:40:57 +0000 | [diff] [blame] | 447 | CONDITION VARIABLES |
| 448 | ------------------------------------------------ */ |
| 449 | |
| 450 | /* LinuxThreads supports no attributes for conditions. Hence ... */ |
| 451 | |
| 452 | int pthread_condattr_init(pthread_condattr_t *attr) |
| 453 | { |
| 454 | return 0; |
| 455 | } |
| 456 | |
sewardj | 0738a59 | 2002-04-20 13:59:33 +0000 | [diff] [blame] | 457 | int pthread_condattr_destroy(pthread_condattr_t *attr) |
| 458 | { |
| 459 | return 0; |
| 460 | } |
sewardj | 6072c36 | 2002-04-19 14:40:57 +0000 | [diff] [blame] | 461 | |
| 462 | int pthread_cond_init( pthread_cond_t *cond, |
| 463 | const pthread_condattr_t *cond_attr) |
| 464 | { |
| 465 | cond->__c_waiting = (_pthread_descr)VG_INVALID_THREADID; |
| 466 | return 0; |
| 467 | } |
| 468 | |
sewardj | f854f47 | 2002-04-21 12:19:41 +0000 | [diff] [blame] | 469 | int pthread_cond_destroy(pthread_cond_t *cond) |
| 470 | { |
| 471 | /* should check that no threads are waiting on this CV */ |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 472 | static int moans = N_MOANS; |
| 473 | if (moans-- > 0) |
| 474 | kludged("pthread_cond_destroy"); |
sewardj | f854f47 | 2002-04-21 12:19:41 +0000 | [diff] [blame] | 475 | return 0; |
| 476 | } |
sewardj | 6072c36 | 2002-04-19 14:40:57 +0000 | [diff] [blame] | 477 | |
| 478 | /* --------------------------------------------------- |
| 479 | SCHEDULING |
| 480 | ------------------------------------------------ */ |
| 481 | |
| 482 | /* This is completely bogus. */ |
| 483 | int pthread_getschedparam(pthread_t target_thread, |
| 484 | int *policy, |
| 485 | struct sched_param *param) |
| 486 | { |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 487 | static int moans = N_MOANS; |
| 488 | if (moans-- > 0) |
| 489 | kludged("pthread_getschedparam"); |
sewardj | 6072c36 | 2002-04-19 14:40:57 +0000 | [diff] [blame] | 490 | if (policy) *policy = SCHED_OTHER; |
sewardj | 2a1dcce | 2002-04-22 12:45:25 +0000 | [diff] [blame] | 491 | # ifdef GLIBC_2_1 |
| 492 | if (param) param->sched_priority = 0; /* who knows */ |
| 493 | # else |
sewardj | 6072c36 | 2002-04-19 14:40:57 +0000 | [diff] [blame] | 494 | if (param) param->__sched_priority = 0; /* who knows */ |
sewardj | 2a1dcce | 2002-04-22 12:45:25 +0000 | [diff] [blame] | 495 | # endif |
sewardj | 6072c36 | 2002-04-19 14:40:57 +0000 | [diff] [blame] | 496 | return 0; |
| 497 | } |
| 498 | |
| 499 | int pthread_setschedparam(pthread_t target_thread, |
| 500 | int policy, |
| 501 | const struct sched_param *param) |
| 502 | { |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 503 | static int moans = N_MOANS; |
| 504 | if (moans-- > 0) |
| 505 | ignored("pthread_setschedparam"); |
sewardj | 6072c36 | 2002-04-19 14:40:57 +0000 | [diff] [blame] | 506 | return 0; |
| 507 | } |
| 508 | |
sewardj | 3b5d886 | 2002-04-20 13:53:23 +0000 | [diff] [blame] | 509 | int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex) |
| 510 | { |
| 511 | int res; |
| 512 | ensure_valgrind("pthread_cond_wait"); |
| 513 | VALGRIND_MAGIC_SEQUENCE(res, 0 /* default */, |
| 514 | VG_USERREQ__PTHREAD_COND_WAIT, |
| 515 | cond, mutex, 0, 0); |
| 516 | return res; |
| 517 | } |
| 518 | |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 519 | int pthread_cond_timedwait ( pthread_cond_t *cond, |
| 520 | pthread_mutex_t *mutex, |
| 521 | const struct timespec *abstime ) |
| 522 | { |
| 523 | int res; |
| 524 | unsigned int ms_now, ms_end; |
| 525 | struct timeval timeval_now; |
| 526 | unsigned long long int ull_ms_now_after_1970; |
| 527 | unsigned long long int ull_ms_end_after_1970; |
| 528 | |
| 529 | ensure_valgrind("pthread_cond_timedwait"); |
| 530 | VALGRIND_MAGIC_SEQUENCE(ms_now, 0xFFFFFFFF /* default */, |
| 531 | VG_USERREQ__READ_MILLISECOND_TIMER, |
| 532 | 0, 0, 0, 0); |
| 533 | assert(ms_now != 0xFFFFFFFF); |
| 534 | res = gettimeofday(&timeval_now, NULL); |
| 535 | assert(res == 0); |
| 536 | |
| 537 | ull_ms_now_after_1970 |
| 538 | = 1000ULL * ((unsigned long long int)(timeval_now.tv_sec)) |
| 539 | + ((unsigned long long int)(timeval_now.tv_usec / 1000000)); |
| 540 | ull_ms_end_after_1970 |
| 541 | = 1000ULL * ((unsigned long long int)(abstime->tv_sec)) |
| 542 | + ((unsigned long long int)(abstime->tv_nsec / 1000000)); |
| 543 | assert(ull_ms_end_after_1970 >= ull_ms_now_after_1970); |
| 544 | ms_end |
| 545 | = ms_now + (unsigned int)(ull_ms_end_after_1970 - ull_ms_now_after_1970); |
| 546 | VALGRIND_MAGIC_SEQUENCE(res, 0 /* default */, |
| 547 | VG_USERREQ__PTHREAD_COND_TIMEDWAIT, |
| 548 | cond, mutex, ms_end, 0); |
| 549 | return res; |
| 550 | } |
| 551 | |
| 552 | |
sewardj | 3b5d886 | 2002-04-20 13:53:23 +0000 | [diff] [blame] | 553 | int pthread_cond_signal(pthread_cond_t *cond) |
| 554 | { |
| 555 | int res; |
| 556 | ensure_valgrind("pthread_cond_signal"); |
| 557 | VALGRIND_MAGIC_SEQUENCE(res, 0 /* default */, |
| 558 | VG_USERREQ__PTHREAD_COND_SIGNAL, |
| 559 | cond, 0, 0, 0); |
| 560 | return res; |
| 561 | } |
| 562 | |
| 563 | int pthread_cond_broadcast(pthread_cond_t *cond) |
| 564 | { |
| 565 | int res; |
| 566 | ensure_valgrind("pthread_cond_broadcast"); |
| 567 | VALGRIND_MAGIC_SEQUENCE(res, 0 /* default */, |
| 568 | VG_USERREQ__PTHREAD_COND_BROADCAST, |
| 569 | cond, 0, 0, 0); |
| 570 | return res; |
| 571 | } |
| 572 | |
sewardj | 6072c36 | 2002-04-19 14:40:57 +0000 | [diff] [blame] | 573 | |
| 574 | /* --------------------------------------------------- |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 575 | CANCELLATION |
| 576 | ------------------------------------------------ */ |
| 577 | |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 578 | int pthread_setcancelstate(int state, int *oldstate) |
| 579 | { |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 580 | static int moans = N_MOANS; |
| 581 | if (moans-- > 0) |
| 582 | ignored("pthread_setcancelstate"); |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 583 | return 0; |
| 584 | } |
| 585 | |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 586 | int pthread_setcanceltype(int type, int *oldtype) |
| 587 | { |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 588 | static int moans = N_MOANS; |
| 589 | if (moans-- > 0) |
| 590 | ignored("pthread_setcanceltype"); |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 591 | return 0; |
| 592 | } |
| 593 | |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 594 | int pthread_cancel(pthread_t thread) |
| 595 | { |
| 596 | int res; |
| 597 | ensure_valgrind("pthread_cancel"); |
| 598 | VALGRIND_MAGIC_SEQUENCE(res, 0 /* default */, |
| 599 | VG_USERREQ__PTHREAD_CANCEL, |
| 600 | thread, 0, 0, 0); |
| 601 | return res; |
| 602 | } |
| 603 | |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 604 | void pthread_testcancel(void) |
| 605 | { |
| 606 | } |
| 607 | |
| 608 | /*-------------------*/ |
| 609 | static pthread_mutex_t massacre_mx = PTHREAD_MUTEX_INITIALIZER; |
| 610 | |
| 611 | void __pthread_kill_other_threads_np ( void ) |
| 612 | { |
| 613 | int i, res, me; |
sewardj | 68b2dd9 | 2002-05-10 21:03:56 +0000 | [diff] [blame] | 614 | __pthread_mutex_lock(&massacre_mx); |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 615 | me = pthread_self(); |
| 616 | for (i = 1; i < VG_N_THREADS; i++) { |
| 617 | if (i == me) continue; |
| 618 | res = pthread_cancel(i); |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 619 | if (0 && res == 0) |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 620 | printf("----------- NUKED %d\n", i); |
| 621 | } |
sewardj | 68b2dd9 | 2002-05-10 21:03:56 +0000 | [diff] [blame] | 622 | __pthread_mutex_unlock(&massacre_mx); |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 623 | } |
| 624 | |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 625 | |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 626 | /* --------------------------------------------------- |
sewardj | b48e500 | 2002-05-13 00:16:03 +0000 | [diff] [blame] | 627 | SIGNALS |
| 628 | ------------------------------------------------ */ |
| 629 | |
| 630 | #include <signal.h> |
| 631 | |
| 632 | int pthread_sigmask(int how, const sigset_t *newmask, |
| 633 | sigset_t *oldmask) |
| 634 | { |
| 635 | int res; |
| 636 | |
| 637 | /* A bit subtle, because the scheduler expects newmask and oldmask |
| 638 | to be vki_sigset_t* rather than sigset_t*, and the two are |
| 639 | different. Fortunately the first 64 bits of a sigset_t are |
| 640 | exactly a vki_sigset_t, so we just pass the pointers through |
| 641 | unmodified. Haaaack! |
| 642 | |
| 643 | Also mash the how value so that the SIG_ constants from glibc |
sewardj | 018f762 | 2002-05-15 21:13:39 +0000 | [diff] [blame] | 644 | constants to VKI_ constants, so that the former do not have to |
| 645 | be included into vg_scheduler.c. */ |
sewardj | b48e500 | 2002-05-13 00:16:03 +0000 | [diff] [blame] | 646 | |
| 647 | ensure_valgrind("pthread_sigmask"); |
| 648 | |
| 649 | switch (how) { |
sewardj | 018f762 | 2002-05-15 21:13:39 +0000 | [diff] [blame] | 650 | case SIG_SETMASK: how = VKI_SIG_SETMASK; break; |
| 651 | case SIG_BLOCK: how = VKI_SIG_BLOCK; break; |
| 652 | case SIG_UNBLOCK: how = VKI_SIG_UNBLOCK; break; |
sewardj | b48e500 | 2002-05-13 00:16:03 +0000 | [diff] [blame] | 653 | default: return EINVAL; |
| 654 | } |
| 655 | |
| 656 | /* Crude check */ |
| 657 | if (newmask == NULL) |
| 658 | return EFAULT; |
| 659 | |
| 660 | VALGRIND_MAGIC_SEQUENCE(res, 0 /* default */, |
| 661 | VG_USERREQ__PTHREAD_SIGMASK, |
| 662 | how, newmask, oldmask, 0); |
| 663 | |
| 664 | /* The scheduler tells us of any memory violations. */ |
| 665 | return res == 0 ? 0 : EFAULT; |
| 666 | } |
| 667 | |
| 668 | |
| 669 | int sigwait ( const sigset_t* set, int* sig ) |
| 670 | { |
| 671 | int res; |
| 672 | ensure_valgrind("sigwait"); |
| 673 | /* As with pthread_sigmask we deliberately confuse sigset_t with |
| 674 | vki_ksigset_t. */ |
| 675 | VALGRIND_MAGIC_SEQUENCE(res, 0 /* default */, |
| 676 | VG_USERREQ__SIGWAIT, |
| 677 | set, sig, 0, 0); |
| 678 | return res; |
| 679 | } |
| 680 | |
| 681 | |
sewardj | 018f762 | 2002-05-15 21:13:39 +0000 | [diff] [blame] | 682 | int pthread_kill(pthread_t thread, int signo) |
| 683 | { |
| 684 | int res; |
| 685 | ensure_valgrind("pthread_kill"); |
| 686 | VALGRIND_MAGIC_SEQUENCE(res, 0 /* default */, |
| 687 | VG_USERREQ__PTHREAD_KILL, |
| 688 | thread, signo, 0, 0); |
| 689 | return res; |
| 690 | } |
| 691 | |
| 692 | |
sewardj | 3665ded | 2002-05-16 16:57:25 +0000 | [diff] [blame] | 693 | /* Copied verbatim from Linuxthreads */ |
| 694 | /* Redefine raise() to send signal to calling thread only, |
| 695 | as per POSIX 1003.1c */ |
| 696 | int raise (int sig) |
| 697 | { |
| 698 | int retcode = pthread_kill(pthread_self(), sig); |
| 699 | if (retcode == 0) |
| 700 | return 0; |
| 701 | else { |
| 702 | errno = retcode; |
| 703 | return -1; |
| 704 | } |
| 705 | } |
| 706 | |
| 707 | |
sewardj | b48e500 | 2002-05-13 00:16:03 +0000 | [diff] [blame] | 708 | /* --------------------------------------------------- |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 709 | THREAD-SPECIFICs |
| 710 | ------------------------------------------------ */ |
sewardj | 5e5fa51 | 2002-04-14 13:13:05 +0000 | [diff] [blame] | 711 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 712 | int __pthread_key_create(pthread_key_t *key, |
| 713 | void (*destr_function) (void *)) |
sewardj | 5e5fa51 | 2002-04-14 13:13:05 +0000 | [diff] [blame] | 714 | { |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 715 | int res; |
| 716 | ensure_valgrind("pthread_key_create"); |
| 717 | VALGRIND_MAGIC_SEQUENCE(res, 0 /* default */, |
| 718 | VG_USERREQ__PTHREAD_KEY_CREATE, |
| 719 | key, destr_function, 0, 0); |
| 720 | return res; |
sewardj | 5e5fa51 | 2002-04-14 13:13:05 +0000 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | int pthread_key_delete(pthread_key_t key) |
| 724 | { |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 725 | static int moans = N_MOANS; |
| 726 | if (moans-- > 0) |
| 727 | ignored("pthread_key_delete"); |
sewardj | 5e5fa51 | 2002-04-14 13:13:05 +0000 | [diff] [blame] | 728 | return 0; |
| 729 | } |
| 730 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 731 | int __pthread_setspecific(pthread_key_t key, const void *pointer) |
sewardj | 5e5fa51 | 2002-04-14 13:13:05 +0000 | [diff] [blame] | 732 | { |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 733 | int res; |
| 734 | ensure_valgrind("pthread_setspecific"); |
| 735 | VALGRIND_MAGIC_SEQUENCE(res, 0 /* default */, |
| 736 | VG_USERREQ__PTHREAD_SETSPECIFIC, |
| 737 | key, pointer, 0, 0); |
| 738 | return res; |
sewardj | 5e5fa51 | 2002-04-14 13:13:05 +0000 | [diff] [blame] | 739 | } |
| 740 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 741 | void * __pthread_getspecific(pthread_key_t key) |
sewardj | 5e5fa51 | 2002-04-14 13:13:05 +0000 | [diff] [blame] | 742 | { |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 743 | int res; |
| 744 | ensure_valgrind("pthread_getspecific"); |
| 745 | VALGRIND_MAGIC_SEQUENCE(res, 0 /* default */, |
| 746 | VG_USERREQ__PTHREAD_GETSPECIFIC, |
| 747 | key, 0 , 0, 0); |
| 748 | return (void*)res; |
sewardj | 5e5fa51 | 2002-04-14 13:13:05 +0000 | [diff] [blame] | 749 | } |
| 750 | |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 751 | |
| 752 | /* --------------------------------------------------- |
sewardj | 89d3d85 | 2002-04-24 19:21:39 +0000 | [diff] [blame] | 753 | ONCEry |
| 754 | ------------------------------------------------ */ |
| 755 | |
| 756 | static pthread_mutex_t once_masterlock = PTHREAD_MUTEX_INITIALIZER; |
| 757 | |
| 758 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 759 | int __pthread_once ( pthread_once_t *once_control, |
| 760 | void (*init_routine) (void) ) |
sewardj | 89d3d85 | 2002-04-24 19:21:39 +0000 | [diff] [blame] | 761 | { |
| 762 | int res; |
| 763 | ensure_valgrind("pthread_once"); |
| 764 | |
sewardj | 68b2dd9 | 2002-05-10 21:03:56 +0000 | [diff] [blame] | 765 | res = __pthread_mutex_lock(&once_masterlock); |
sewardj | 89d3d85 | 2002-04-24 19:21:39 +0000 | [diff] [blame] | 766 | |
sewardj | 68b2dd9 | 2002-05-10 21:03:56 +0000 | [diff] [blame] | 767 | if (res != 0) { |
| 768 | printf("res = %d\n",res); |
sewardj | 89d3d85 | 2002-04-24 19:21:39 +0000 | [diff] [blame] | 769 | barf("pthread_once: Looks like your program's " |
| 770 | "init routine calls back to pthread_once() ?!"); |
sewardj | 68b2dd9 | 2002-05-10 21:03:56 +0000 | [diff] [blame] | 771 | } |
sewardj | 89d3d85 | 2002-04-24 19:21:39 +0000 | [diff] [blame] | 772 | |
| 773 | if (*once_control == 0) { |
| 774 | *once_control = 1; |
| 775 | init_routine(); |
| 776 | } |
| 777 | |
sewardj | 68b2dd9 | 2002-05-10 21:03:56 +0000 | [diff] [blame] | 778 | __pthread_mutex_unlock(&once_masterlock); |
sewardj | 89d3d85 | 2002-04-24 19:21:39 +0000 | [diff] [blame] | 779 | |
| 780 | return 0; |
| 781 | } |
| 782 | |
| 783 | |
| 784 | /* --------------------------------------------------- |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 785 | MISC |
| 786 | ------------------------------------------------ */ |
| 787 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 788 | int __pthread_atfork ( void (*prepare)(void), |
| 789 | void (*parent)(void), |
| 790 | void (*child)(void) ) |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 791 | { |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 792 | static int moans = N_MOANS; |
| 793 | if (moans-- > 0) |
| 794 | ignored("pthread_atfork"); |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 795 | return 0; |
| 796 | } |
| 797 | |
| 798 | |
sewardj | bb99078 | 2002-05-08 02:01:14 +0000 | [diff] [blame] | 799 | __attribute__((weak)) |
| 800 | void __pthread_initialize ( void ) |
| 801 | { |
sewardj | bea1caa | 2002-05-10 23:20:58 +0000 | [diff] [blame] | 802 | ensure_valgrind("__pthread_initialize"); |
sewardj | bb99078 | 2002-05-08 02:01:14 +0000 | [diff] [blame] | 803 | } |
| 804 | |
| 805 | |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 806 | /* --------------------------------------------------- |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 807 | LIBRARY-PRIVATE THREAD SPECIFIC STATE |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 808 | ------------------------------------------------ */ |
| 809 | |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 810 | #include <resolv.h> |
| 811 | static int thread_specific_errno[VG_N_THREADS]; |
| 812 | static int thread_specific_h_errno[VG_N_THREADS]; |
| 813 | static struct __res_state |
| 814 | thread_specific_res_state[VG_N_THREADS]; |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 815 | |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 816 | int* __errno_location ( void ) |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 817 | { |
| 818 | int tid; |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 819 | /* ensure_valgrind("__errno_location"); */ |
| 820 | VALGRIND_MAGIC_SEQUENCE(tid, 1 /* default */, |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 821 | VG_USERREQ__PTHREAD_GET_THREADID, |
| 822 | 0, 0, 0, 0); |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 823 | /* 'cos I'm paranoid ... */ |
sewardj | 439d45e | 2002-05-03 20:43:10 +0000 | [diff] [blame] | 824 | if (tid < 1 || tid >= VG_N_THREADS) |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 825 | barf("__errno_location: invalid ThreadId"); |
| 826 | return & thread_specific_errno[tid]; |
| 827 | } |
| 828 | |
| 829 | int* __h_errno_location ( void ) |
| 830 | { |
| 831 | int tid; |
| 832 | /* ensure_valgrind("__h_errno_location"); */ |
| 833 | VALGRIND_MAGIC_SEQUENCE(tid, 1 /* default */, |
| 834 | VG_USERREQ__PTHREAD_GET_THREADID, |
| 835 | 0, 0, 0, 0); |
| 836 | /* 'cos I'm paranoid ... */ |
sewardj | 439d45e | 2002-05-03 20:43:10 +0000 | [diff] [blame] | 837 | if (tid < 1 || tid >= VG_N_THREADS) |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 838 | barf("__h_errno_location: invalid ThreadId"); |
| 839 | return & thread_specific_h_errno[tid]; |
| 840 | } |
| 841 | |
| 842 | struct __res_state* __res_state ( void ) |
| 843 | { |
| 844 | int tid; |
| 845 | /* ensure_valgrind("__res_state"); */ |
| 846 | VALGRIND_MAGIC_SEQUENCE(tid, 1 /* default */, |
| 847 | VG_USERREQ__PTHREAD_GET_THREADID, |
| 848 | 0, 0, 0, 0); |
| 849 | /* 'cos I'm paranoid ... */ |
sewardj | 439d45e | 2002-05-03 20:43:10 +0000 | [diff] [blame] | 850 | if (tid < 1 || tid >= VG_N_THREADS) |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 851 | barf("__res_state: invalid ThreadId"); |
| 852 | return & thread_specific_res_state[tid]; |
sewardj | f8f819e | 2002-04-17 23:21:37 +0000 | [diff] [blame] | 853 | } |
| 854 | |
| 855 | |
sewardj | 5716dbb | 2002-04-26 03:28:18 +0000 | [diff] [blame] | 856 | /* --------------------------------------------------- |
| 857 | LIBC-PRIVATE SPECIFIC DATA |
| 858 | ------------------------------------------------ */ |
| 859 | |
| 860 | /* Relies on assumption that initial private data is NULL. This |
| 861 | should be fixed somehow. */ |
| 862 | |
| 863 | /* The allowable keys (indices) (all 2 of them). |
| 864 | From sysdeps/pthread/bits/libc-tsd.h |
| 865 | */ |
sewardj | 70adeb2 | 2002-04-27 01:35:38 +0000 | [diff] [blame] | 866 | #define N_LIBC_TSD_EXTRA_KEYS 1 |
| 867 | |
sewardj | 5716dbb | 2002-04-26 03:28:18 +0000 | [diff] [blame] | 868 | enum __libc_tsd_key_t { _LIBC_TSD_KEY_MALLOC = 0, |
| 869 | _LIBC_TSD_KEY_DL_ERROR, |
| 870 | _LIBC_TSD_KEY_N }; |
| 871 | |
| 872 | /* Auto-initialising subsystem. libc_specifics_inited is set |
| 873 | after initialisation. libc_specifics_inited_mx guards it. */ |
| 874 | static int libc_specifics_inited = 0; |
| 875 | static pthread_mutex_t libc_specifics_inited_mx = PTHREAD_MUTEX_INITIALIZER; |
| 876 | |
| 877 | /* These are the keys we must initialise the first time. */ |
sewardj | 70adeb2 | 2002-04-27 01:35:38 +0000 | [diff] [blame] | 878 | static pthread_key_t libc_specifics_keys[_LIBC_TSD_KEY_N |
| 879 | + N_LIBC_TSD_EXTRA_KEYS]; |
sewardj | 5716dbb | 2002-04-26 03:28:18 +0000 | [diff] [blame] | 880 | |
| 881 | /* Initialise the keys, if they are not already initialise. */ |
| 882 | static |
| 883 | void init_libc_tsd_keys ( void ) |
| 884 | { |
| 885 | int res, i; |
| 886 | pthread_key_t k; |
| 887 | |
| 888 | res = pthread_mutex_lock(&libc_specifics_inited_mx); |
| 889 | if (res != 0) barf("init_libc_tsd_keys: lock"); |
| 890 | |
| 891 | if (libc_specifics_inited == 0) { |
| 892 | /* printf("INIT libc specifics\n"); */ |
| 893 | libc_specifics_inited = 1; |
sewardj | 70adeb2 | 2002-04-27 01:35:38 +0000 | [diff] [blame] | 894 | 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] | 895 | res = pthread_key_create(&k, NULL); |
| 896 | if (res != 0) barf("init_libc_tsd_keys: create"); |
| 897 | libc_specifics_keys[i] = k; |
| 898 | } |
| 899 | } |
| 900 | |
| 901 | res = pthread_mutex_unlock(&libc_specifics_inited_mx); |
| 902 | if (res != 0) barf("init_libc_tsd_keys: unlock"); |
| 903 | } |
| 904 | |
| 905 | |
| 906 | static int |
| 907 | libc_internal_tsd_set ( enum __libc_tsd_key_t key, |
| 908 | const void * pointer ) |
| 909 | { |
sewardj | 70adeb2 | 2002-04-27 01:35:38 +0000 | [diff] [blame] | 910 | int res; |
| 911 | static int moans = N_MOANS; |
sewardj | 5716dbb | 2002-04-26 03:28:18 +0000 | [diff] [blame] | 912 | /* printf("SET SET SET key %d ptr %p\n", key, pointer); */ |
sewardj | 70adeb2 | 2002-04-27 01:35:38 +0000 | [diff] [blame] | 913 | if (key < _LIBC_TSD_KEY_MALLOC |
| 914 | || key >= _LIBC_TSD_KEY_N + N_LIBC_TSD_EXTRA_KEYS) |
sewardj | 5716dbb | 2002-04-26 03:28:18 +0000 | [diff] [blame] | 915 | barf("libc_internal_tsd_set: invalid key"); |
sewardj | 70adeb2 | 2002-04-27 01:35:38 +0000 | [diff] [blame] | 916 | if (key >= _LIBC_TSD_KEY_N && moans-- > 0) |
| 917 | fprintf(stderr, |
sewardj | 439d45e | 2002-05-03 20:43:10 +0000 | [diff] [blame] | 918 | "valgrind's libpthread.so: libc_internal_tsd_set: " |
| 919 | "dubious key %d\n", key); |
sewardj | 5716dbb | 2002-04-26 03:28:18 +0000 | [diff] [blame] | 920 | init_libc_tsd_keys(); |
| 921 | res = pthread_setspecific(libc_specifics_keys[key], pointer); |
| 922 | if (res != 0) barf("libc_internal_tsd_set: setspecific failed"); |
| 923 | return 0; |
| 924 | } |
| 925 | |
| 926 | static void * |
| 927 | libc_internal_tsd_get ( enum __libc_tsd_key_t key ) |
| 928 | { |
sewardj | 70adeb2 | 2002-04-27 01:35:38 +0000 | [diff] [blame] | 929 | void* v; |
| 930 | static int moans = N_MOANS; |
sewardj | 5716dbb | 2002-04-26 03:28:18 +0000 | [diff] [blame] | 931 | /* printf("GET GET GET key %d\n", key); */ |
sewardj | 70adeb2 | 2002-04-27 01:35:38 +0000 | [diff] [blame] | 932 | if (key < _LIBC_TSD_KEY_MALLOC |
| 933 | || key >= _LIBC_TSD_KEY_N + N_LIBC_TSD_EXTRA_KEYS) |
sewardj | 5716dbb | 2002-04-26 03:28:18 +0000 | [diff] [blame] | 934 | barf("libc_internal_tsd_get: invalid key"); |
sewardj | 70adeb2 | 2002-04-27 01:35:38 +0000 | [diff] [blame] | 935 | if (key >= _LIBC_TSD_KEY_N && moans-- > 0) |
| 936 | fprintf(stderr, |
sewardj | 439d45e | 2002-05-03 20:43:10 +0000 | [diff] [blame] | 937 | "valgrind's libpthread.so: libc_internal_tsd_get: " |
| 938 | "dubious key %d\n", key); |
sewardj | 5716dbb | 2002-04-26 03:28:18 +0000 | [diff] [blame] | 939 | init_libc_tsd_keys(); |
| 940 | v = pthread_getspecific(libc_specifics_keys[key]); |
| 941 | /* if (v == NULL) barf("libc_internal_tsd_set: getspecific failed"); */ |
| 942 | return v; |
| 943 | } |
| 944 | |
| 945 | |
| 946 | |
| 947 | |
sewardj | 70adeb2 | 2002-04-27 01:35:38 +0000 | [diff] [blame] | 948 | int (*__libc_internal_tsd_set) |
| 949 | (enum __libc_tsd_key_t key, const void * pointer) |
| 950 | = libc_internal_tsd_set; |
sewardj | 5716dbb | 2002-04-26 03:28:18 +0000 | [diff] [blame] | 951 | |
sewardj | 70adeb2 | 2002-04-27 01:35:38 +0000 | [diff] [blame] | 952 | void* (*__libc_internal_tsd_get) |
| 953 | (enum __libc_tsd_key_t key) |
| 954 | = libc_internal_tsd_get; |
sewardj | 5716dbb | 2002-04-26 03:28:18 +0000 | [diff] [blame] | 955 | |
| 956 | |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 957 | /* --------------------------------------------------------------------- |
| 958 | These are here (I think) because they are deemed cancellation |
| 959 | points by POSIX. For the moment we'll simply pass the call along |
| 960 | to the corresponding thread-unaware (?) libc routine. |
| 961 | ------------------------------------------------------------------ */ |
| 962 | |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 963 | #include <stdlib.h> |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 964 | #include <sys/types.h> |
| 965 | #include <sys/socket.h> |
| 966 | |
sewardj | d529a44 | 2002-05-04 19:49:21 +0000 | [diff] [blame] | 967 | #ifdef GLIBC_2_1 |
| 968 | extern |
| 969 | int __sigaction |
| 970 | (int signum, |
| 971 | const struct sigaction *act, |
| 972 | struct sigaction *oldact); |
| 973 | #else |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 974 | extern |
| 975 | int __libc_sigaction |
| 976 | (int signum, |
| 977 | const struct sigaction *act, |
| 978 | struct sigaction *oldact); |
sewardj | d529a44 | 2002-05-04 19:49:21 +0000 | [diff] [blame] | 979 | #endif |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 980 | int sigaction(int signum, |
| 981 | const struct sigaction *act, |
| 982 | struct sigaction *oldact) |
| 983 | { |
sewardj | 2a1dcce | 2002-04-22 12:45:25 +0000 | [diff] [blame] | 984 | # ifdef GLIBC_2_1 |
| 985 | return __sigaction(signum, act, oldact); |
| 986 | # else |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 987 | return __libc_sigaction(signum, act, oldact); |
sewardj | 2a1dcce | 2002-04-22 12:45:25 +0000 | [diff] [blame] | 988 | # endif |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 989 | } |
| 990 | |
| 991 | |
| 992 | extern |
| 993 | int __libc_connect(int sockfd, |
| 994 | const struct sockaddr *serv_addr, |
| 995 | socklen_t addrlen); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 996 | __attribute__((weak)) |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 997 | int connect(int sockfd, |
| 998 | const struct sockaddr *serv_addr, |
| 999 | socklen_t addrlen) |
| 1000 | { |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 1001 | return __libc_connect(sockfd, serv_addr, addrlen); |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1002 | } |
| 1003 | |
| 1004 | |
| 1005 | extern |
| 1006 | int __libc_fcntl(int fd, int cmd, long arg); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1007 | __attribute__((weak)) |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1008 | int fcntl(int fd, int cmd, long arg) |
| 1009 | { |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 1010 | return __libc_fcntl(fd, cmd, arg); |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1011 | } |
| 1012 | |
| 1013 | |
| 1014 | extern |
| 1015 | ssize_t __libc_write(int fd, const void *buf, size_t count); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1016 | __attribute__((weak)) |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1017 | ssize_t write(int fd, const void *buf, size_t count) |
| 1018 | { |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 1019 | return __libc_write(fd, buf, count); |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1020 | } |
| 1021 | |
| 1022 | |
| 1023 | extern |
| 1024 | ssize_t __libc_read(int fd, void *buf, size_t count); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1025 | __attribute__((weak)) |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1026 | ssize_t read(int fd, void *buf, size_t count) |
| 1027 | { |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 1028 | return __libc_read(fd, buf, count); |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1029 | } |
| 1030 | |
sewardj | be32e45 | 2002-04-24 20:29:58 +0000 | [diff] [blame] | 1031 | |
| 1032 | extern |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 1033 | int __libc_open64(const char *pathname, int flags, mode_t mode); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1034 | __attribute__((weak)) |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 1035 | int open64(const char *pathname, int flags, mode_t mode) |
sewardj | be32e45 | 2002-04-24 20:29:58 +0000 | [diff] [blame] | 1036 | { |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 1037 | return __libc_open64(pathname, flags, mode); |
sewardj | be32e45 | 2002-04-24 20:29:58 +0000 | [diff] [blame] | 1038 | } |
| 1039 | |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1040 | |
| 1041 | extern |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 1042 | int __libc_open(const char *pathname, int flags, mode_t mode); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1043 | __attribute__((weak)) |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 1044 | int open(const char *pathname, int flags, mode_t mode) |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1045 | { |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 1046 | return __libc_open(pathname, flags, mode); |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1047 | } |
| 1048 | |
| 1049 | |
| 1050 | extern |
| 1051 | int __libc_close(int fd); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1052 | __attribute__((weak)) |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1053 | int close(int fd) |
| 1054 | { |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 1055 | return __libc_close(fd); |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1056 | } |
| 1057 | |
| 1058 | |
| 1059 | extern |
| 1060 | int __libc_accept(int s, struct sockaddr *addr, socklen_t *addrlen); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1061 | __attribute__((weak)) |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1062 | int accept(int s, struct sockaddr *addr, socklen_t *addrlen) |
| 1063 | { |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 1064 | return __libc_accept(s, addr, addrlen); |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1065 | } |
| 1066 | |
| 1067 | |
| 1068 | extern |
| 1069 | pid_t __libc_fork(void); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1070 | pid_t __fork(void) |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1071 | { |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 1072 | return __libc_fork(); |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1073 | } |
| 1074 | |
| 1075 | |
| 1076 | extern |
| 1077 | pid_t __libc_waitpid(pid_t pid, int *status, int options); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1078 | __attribute__((weak)) |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1079 | pid_t waitpid(pid_t pid, int *status, int options) |
| 1080 | { |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 1081 | return __libc_waitpid(pid, status, options); |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1082 | } |
| 1083 | |
| 1084 | |
| 1085 | extern |
| 1086 | int __libc_nanosleep(const struct timespec *req, struct timespec *rem); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1087 | __attribute__((weak)) |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1088 | int nanosleep(const struct timespec *req, struct timespec *rem) |
| 1089 | { |
| 1090 | return __libc_nanosleep(req, rem); |
| 1091 | } |
| 1092 | |
sewardj | be32e45 | 2002-04-24 20:29:58 +0000 | [diff] [blame] | 1093 | |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1094 | extern |
| 1095 | int __libc_fsync(int fd); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1096 | __attribute__((weak)) |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1097 | int fsync(int fd) |
| 1098 | { |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 1099 | return __libc_fsync(fd); |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1100 | } |
| 1101 | |
sewardj | be32e45 | 2002-04-24 20:29:58 +0000 | [diff] [blame] | 1102 | |
sewardj | 70c7536 | 2002-04-13 04:18:32 +0000 | [diff] [blame] | 1103 | extern |
| 1104 | off_t __libc_lseek(int fildes, off_t offset, int whence); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1105 | __attribute__((weak)) |
sewardj | 70c7536 | 2002-04-13 04:18:32 +0000 | [diff] [blame] | 1106 | off_t lseek(int fildes, off_t offset, int whence) |
| 1107 | { |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 1108 | return __libc_lseek(fildes, offset, whence); |
sewardj | 70c7536 | 2002-04-13 04:18:32 +0000 | [diff] [blame] | 1109 | } |
| 1110 | |
sewardj | be32e45 | 2002-04-24 20:29:58 +0000 | [diff] [blame] | 1111 | |
| 1112 | extern |
| 1113 | __off64_t __libc_lseek64(int fildes, __off64_t offset, int whence); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1114 | __attribute__((weak)) |
sewardj | be32e45 | 2002-04-24 20:29:58 +0000 | [diff] [blame] | 1115 | __off64_t lseek64(int fildes, __off64_t offset, int whence) |
| 1116 | { |
| 1117 | return __libc_lseek64(fildes, offset, whence); |
| 1118 | } |
| 1119 | |
| 1120 | |
sewardj | 726c412 | 2002-05-16 23:39:10 +0000 | [diff] [blame] | 1121 | extern |
| 1122 | ssize_t __libc_pread64 (int __fd, void *__buf, size_t __nbytes, |
| 1123 | __off64_t __offset); |
| 1124 | ssize_t __pread64 (int __fd, void *__buf, size_t __nbytes, |
| 1125 | __off64_t __offset) |
| 1126 | { |
| 1127 | return __libc_pread64(__fd, __buf, __nbytes, __offset); |
| 1128 | } |
| 1129 | |
| 1130 | |
sewardj | a18e210 | 2002-05-18 10:43:22 +0000 | [diff] [blame] | 1131 | extern |
| 1132 | ssize_t __libc_pwrite64 (int __fd, const void *__buf, size_t __nbytes, |
| 1133 | __off64_t __offset); |
| 1134 | ssize_t __pwrite64 (int __fd, const void *__buf, size_t __nbytes, |
| 1135 | __off64_t __offset) |
| 1136 | { |
| 1137 | return __libc_pwrite64(__fd, __buf, __nbytes, __offset); |
| 1138 | } |
| 1139 | |
sewardj | 726c412 | 2002-05-16 23:39:10 +0000 | [diff] [blame] | 1140 | |
sewardj | 39b93b1 | 2002-05-18 10:56:27 +0000 | [diff] [blame] | 1141 | extern |
| 1142 | ssize_t __libc_pwrite(int fd, const void *buf, size_t count, off_t offset); |
| 1143 | __attribute__((weak)) |
| 1144 | ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset) |
| 1145 | { |
| 1146 | return __libc_pwrite(fd, buf, count, offset); |
| 1147 | } |
| 1148 | |
| 1149 | |
| 1150 | extern |
| 1151 | ssize_t __libc_pread(int fd, void *buf, size_t count, off_t offset); |
| 1152 | __attribute__((weak)) |
| 1153 | ssize_t pread(int fd, void *buf, size_t count, off_t offset) |
| 1154 | { |
| 1155 | return __libc_pread(fd, buf, count, offset); |
| 1156 | } |
| 1157 | |
| 1158 | |
sewardj | 6af4b5d | 2002-04-16 04:40:49 +0000 | [diff] [blame] | 1159 | extern |
| 1160 | void __libc_longjmp(jmp_buf env, int val) __attribute((noreturn)); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1161 | /* not weak: __attribute__((weak)) */ |
sewardj | 6af4b5d | 2002-04-16 04:40:49 +0000 | [diff] [blame] | 1162 | void longjmp(jmp_buf env, int val) |
| 1163 | { |
| 1164 | __libc_longjmp(env, val); |
| 1165 | } |
| 1166 | |
sewardj | be32e45 | 2002-04-24 20:29:58 +0000 | [diff] [blame] | 1167 | |
sewardj | 6af4b5d | 2002-04-16 04:40:49 +0000 | [diff] [blame] | 1168 | extern |
| 1169 | int __libc_send(int s, const void *msg, size_t len, int flags); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1170 | __attribute__((weak)) |
sewardj | 6af4b5d | 2002-04-16 04:40:49 +0000 | [diff] [blame] | 1171 | int send(int s, const void *msg, size_t len, int flags) |
| 1172 | { |
| 1173 | return __libc_send(s, msg, len, flags); |
| 1174 | } |
| 1175 | |
sewardj | be32e45 | 2002-04-24 20:29:58 +0000 | [diff] [blame] | 1176 | |
sewardj | 1e8cdc9 | 2002-04-18 11:37:52 +0000 | [diff] [blame] | 1177 | extern |
| 1178 | int __libc_recv(int s, void *buf, size_t len, int flags); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1179 | __attribute__((weak)) |
sewardj | 1e8cdc9 | 2002-04-18 11:37:52 +0000 | [diff] [blame] | 1180 | int recv(int s, void *buf, size_t len, int flags) |
| 1181 | { |
| 1182 | return __libc_recv(s, buf, len, flags); |
| 1183 | } |
| 1184 | |
sewardj | be32e45 | 2002-04-24 20:29:58 +0000 | [diff] [blame] | 1185 | |
sewardj | 3665ded | 2002-05-16 16:57:25 +0000 | [diff] [blame] | 1186 | extern |
| 1187 | int __libc_sendmsg(int s, const struct msghdr *msg, int flags); |
| 1188 | __attribute__((weak)) |
| 1189 | int sendmsg(int s, const struct msghdr *msg, int flags) |
| 1190 | { |
| 1191 | return __libc_sendmsg(s, msg, flags); |
| 1192 | } |
| 1193 | |
| 1194 | |
sewardj | 796d6a2 | 2002-04-24 02:28:34 +0000 | [diff] [blame] | 1195 | extern |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 1196 | int __libc_recvfrom(int s, void *buf, size_t len, int flags, |
| 1197 | struct sockaddr *from, socklen_t *fromlen); |
| 1198 | __attribute__((weak)) |
| 1199 | int recvfrom(int s, void *buf, size_t len, int flags, |
| 1200 | struct sockaddr *from, socklen_t *fromlen) |
| 1201 | { |
| 1202 | return __libc_recvfrom(s, buf, len, flags, from, fromlen); |
| 1203 | } |
| 1204 | |
| 1205 | |
| 1206 | extern |
sewardj | 796d6a2 | 2002-04-24 02:28:34 +0000 | [diff] [blame] | 1207 | int __libc_sendto(int s, const void *msg, size_t len, int flags, |
| 1208 | const struct sockaddr *to, socklen_t tolen); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1209 | __attribute__((weak)) |
sewardj | 796d6a2 | 2002-04-24 02:28:34 +0000 | [diff] [blame] | 1210 | int sendto(int s, const void *msg, size_t len, int flags, |
| 1211 | const struct sockaddr *to, socklen_t tolen) |
| 1212 | { |
| 1213 | return __libc_sendto(s, msg, len, flags, to, tolen); |
| 1214 | } |
| 1215 | |
sewardj | be32e45 | 2002-04-24 20:29:58 +0000 | [diff] [blame] | 1216 | |
sewardj | 369b170 | 2002-04-24 13:28:15 +0000 | [diff] [blame] | 1217 | extern |
| 1218 | int __libc_system(const char* str); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1219 | __attribute__((weak)) |
sewardj | 369b170 | 2002-04-24 13:28:15 +0000 | [diff] [blame] | 1220 | int system(const char* str) |
| 1221 | { |
| 1222 | return __libc_system(str); |
| 1223 | } |
| 1224 | |
sewardj | be32e45 | 2002-04-24 20:29:58 +0000 | [diff] [blame] | 1225 | |
sewardj | ab0b1c3 | 2002-04-24 19:26:47 +0000 | [diff] [blame] | 1226 | extern |
| 1227 | pid_t __libc_wait(int *status); |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1228 | __attribute__((weak)) |
sewardj | ab0b1c3 | 2002-04-24 19:26:47 +0000 | [diff] [blame] | 1229 | pid_t wait(int *status) |
| 1230 | { |
| 1231 | return __libc_wait(status); |
| 1232 | } |
| 1233 | |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 1234 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1235 | |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 1236 | /* --------------------------------------------------------------------- |
| 1237 | Nonblocking implementations of select() and poll(). This stuff will |
| 1238 | surely rot your mind. |
| 1239 | ------------------------------------------------------------------ */ |
sewardj | e663cb9 | 2002-04-12 10:26:32 +0000 | [diff] [blame] | 1240 | |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1241 | /*--------------------------------------------------*/ |
| 1242 | |
| 1243 | #include "vg_kerneliface.h" |
| 1244 | |
| 1245 | static |
| 1246 | __inline__ |
| 1247 | int is_kerror ( int res ) |
| 1248 | { |
| 1249 | if (res >= -4095 && res <= -1) |
| 1250 | return 1; |
| 1251 | else |
| 1252 | return 0; |
| 1253 | } |
| 1254 | |
| 1255 | |
| 1256 | static |
| 1257 | int my_do_syscall1 ( int syscallno, int arg1 ) |
| 1258 | { |
| 1259 | int __res; |
| 1260 | __asm__ volatile ("pushl %%ebx; movl %%edx,%%ebx ; int $0x80 ; popl %%ebx" |
| 1261 | : "=a" (__res) |
| 1262 | : "0" (syscallno), |
| 1263 | "d" (arg1) ); |
| 1264 | return __res; |
| 1265 | } |
| 1266 | |
| 1267 | static |
| 1268 | int my_do_syscall2 ( int syscallno, |
sewardj | f854f47 | 2002-04-21 12:19:41 +0000 | [diff] [blame] | 1269 | int arg1, int arg2 ) |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1270 | { |
| 1271 | int __res; |
| 1272 | __asm__ volatile ("pushl %%ebx; movl %%edx,%%ebx ; int $0x80 ; popl %%ebx" |
| 1273 | : "=a" (__res) |
| 1274 | : "0" (syscallno), |
| 1275 | "d" (arg1), |
| 1276 | "c" (arg2) ); |
| 1277 | return __res; |
| 1278 | } |
| 1279 | |
| 1280 | static |
sewardj | f854f47 | 2002-04-21 12:19:41 +0000 | [diff] [blame] | 1281 | int my_do_syscall3 ( int syscallno, |
| 1282 | int arg1, int arg2, int arg3 ) |
| 1283 | { |
| 1284 | int __res; |
| 1285 | __asm__ volatile ("pushl %%ebx; movl %%esi,%%ebx ; int $0x80 ; popl %%ebx" |
| 1286 | : "=a" (__res) |
| 1287 | : "0" (syscallno), |
| 1288 | "S" (arg1), |
| 1289 | "c" (arg2), |
| 1290 | "d" (arg3) ); |
| 1291 | return __res; |
| 1292 | } |
| 1293 | |
| 1294 | static |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1295 | int do_syscall_select( int n, |
| 1296 | vki_fd_set* readfds, |
| 1297 | vki_fd_set* writefds, |
| 1298 | vki_fd_set* exceptfds, |
| 1299 | struct vki_timeval * timeout ) |
| 1300 | { |
| 1301 | int res; |
| 1302 | int args[5]; |
| 1303 | args[0] = n; |
| 1304 | args[1] = (int)readfds; |
| 1305 | args[2] = (int)writefds; |
| 1306 | args[3] = (int)exceptfds; |
| 1307 | args[4] = (int)timeout; |
| 1308 | res = my_do_syscall1(__NR_select, (int)(&(args[0])) ); |
sewardj | 02535bc | 2002-04-21 01:08:26 +0000 | [diff] [blame] | 1309 | return res; |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1310 | } |
| 1311 | |
| 1312 | |
| 1313 | /* This is a wrapper round select(), which makes it thread-safe, |
| 1314 | meaning that only this thread will block, rather than the entire |
| 1315 | process. This wrapper in turn depends on nanosleep() not to block |
| 1316 | the entire process, but I think (hope? suspect?) that POSIX |
| 1317 | pthreads guarantees that to be the case. |
| 1318 | |
| 1319 | Basic idea is: modify the timeout parameter to select so that it |
| 1320 | returns immediately. Poll like this until select returns non-zero, |
| 1321 | indicating something interesting happened, or until our time is up. |
| 1322 | Space out the polls with nanosleeps of say 20 milliseconds, which |
| 1323 | is required to be nonblocking; this allows other threads to run. |
sewardj | 02535bc | 2002-04-21 01:08:26 +0000 | [diff] [blame] | 1324 | |
| 1325 | Assumes: |
| 1326 | * (checked via assert) types fd_set and vki_fd_set are identical. |
| 1327 | * (checked via assert) types timeval and vki_timeval are identical. |
| 1328 | * (unchecked) libc error numbers (EINTR etc) are the negation of the |
| 1329 | kernel's error numbers (VKI_EINTR etc). |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1330 | */ |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1331 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1332 | /* __attribute__((weak)) */ |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1333 | int select ( int n, |
| 1334 | fd_set *rfds, |
| 1335 | fd_set *wfds, |
| 1336 | fd_set *xfds, |
| 1337 | struct timeval *timeout ) |
| 1338 | { |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 1339 | unsigned int ms_now, ms_end; |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1340 | int res; |
| 1341 | fd_set rfds_copy; |
| 1342 | fd_set wfds_copy; |
| 1343 | fd_set xfds_copy; |
| 1344 | struct vki_timeval t_now; |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1345 | struct vki_timeval zero_timeout; |
| 1346 | struct vki_timespec nanosleep_interval; |
| 1347 | |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 1348 | /* gcc's complains about ms_end being used uninitialised -- classic |
| 1349 | case it can't understand, where ms_end is both defined and used |
| 1350 | only if timeout != NULL. Hence ... */ |
| 1351 | ms_end = 0; |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1352 | |
| 1353 | /* We assume that the kernel and libc data layouts are identical |
| 1354 | for the following types. These asserts provide a crude |
| 1355 | check. */ |
| 1356 | if (sizeof(fd_set) != sizeof(vki_fd_set) |
| 1357 | || sizeof(struct timeval) != sizeof(struct vki_timeval)) |
| 1358 | barf("valgrind's hacky non-blocking select(): data sizes error"); |
| 1359 | |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 1360 | /* Detect the current time and simultaneously find out if we are |
| 1361 | running on Valgrind. */ |
| 1362 | VALGRIND_MAGIC_SEQUENCE(ms_now, 0xFFFFFFFF /* default */, |
| 1363 | VG_USERREQ__READ_MILLISECOND_TIMER, |
| 1364 | 0, 0, 0, 0); |
| 1365 | |
| 1366 | /* If a zero timeout specified, this call is harmless. Also go |
| 1367 | this route if we're not running on Valgrind, for whatever |
| 1368 | reason. */ |
| 1369 | if ( (timeout && timeout->tv_sec == 0 && timeout->tv_usec == 0) |
| 1370 | || (ms_now == 0xFFFFFFFF) ) { |
sewardj | 02535bc | 2002-04-21 01:08:26 +0000 | [diff] [blame] | 1371 | res = do_syscall_select( n, (vki_fd_set*)rfds, |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1372 | (vki_fd_set*)wfds, |
| 1373 | (vki_fd_set*)xfds, |
| 1374 | (struct vki_timeval*)timeout); |
sewardj | 02535bc | 2002-04-21 01:08:26 +0000 | [diff] [blame] | 1375 | if (is_kerror(res)) { |
| 1376 | * (__errno_location()) = -res; |
| 1377 | return -1; |
| 1378 | } else { |
| 1379 | return res; |
| 1380 | } |
| 1381 | } |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1382 | |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 1383 | /* If a timeout was specified, set ms_end to be the end millisecond |
| 1384 | counter [wallclock] time. */ |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1385 | if (timeout) { |
| 1386 | res = my_do_syscall2(__NR_gettimeofday, (int)&t_now, (int)NULL); |
| 1387 | assert(res == 0); |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 1388 | ms_end = ms_now; |
| 1389 | ms_end += (timeout->tv_usec / 1000); |
| 1390 | ms_end += (timeout->tv_sec * 1000); |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1391 | /* Stay sane ... */ |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 1392 | assert (ms_end >= ms_now); |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1393 | } |
| 1394 | |
| 1395 | /* fprintf(stderr, "MY_SELECT: before loop\n"); */ |
| 1396 | |
| 1397 | /* Either timeout == NULL, meaning wait indefinitely, or timeout != |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 1398 | NULL, in which case ms_end holds the end time. */ |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1399 | while (1) { |
| 1400 | if (timeout) { |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 1401 | VALGRIND_MAGIC_SEQUENCE(ms_now, 0xFFFFFFFF /* default */, |
| 1402 | VG_USERREQ__READ_MILLISECOND_TIMER, |
| 1403 | 0, 0, 0, 0); |
| 1404 | assert(ms_now != 0xFFFFFFFF); |
| 1405 | if (ms_now >= ms_end) { |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1406 | /* timeout; nothing interesting happened. */ |
| 1407 | if (rfds) FD_ZERO(rfds); |
| 1408 | if (wfds) FD_ZERO(wfds); |
| 1409 | if (xfds) FD_ZERO(xfds); |
| 1410 | return 0; |
| 1411 | } |
| 1412 | } |
| 1413 | |
| 1414 | /* These could be trashed each time round the loop, so restore |
| 1415 | them each time. */ |
| 1416 | if (rfds) rfds_copy = *rfds; |
| 1417 | if (wfds) wfds_copy = *wfds; |
| 1418 | if (xfds) xfds_copy = *xfds; |
| 1419 | |
| 1420 | zero_timeout.tv_sec = zero_timeout.tv_usec = 0; |
| 1421 | |
| 1422 | res = do_syscall_select( n, |
| 1423 | rfds ? (vki_fd_set*)(&rfds_copy) : NULL, |
| 1424 | wfds ? (vki_fd_set*)(&wfds_copy) : NULL, |
| 1425 | xfds ? (vki_fd_set*)(&xfds_copy) : NULL, |
| 1426 | & zero_timeout ); |
sewardj | 02535bc | 2002-04-21 01:08:26 +0000 | [diff] [blame] | 1427 | if (is_kerror(res)) { |
| 1428 | /* Some kind of error (including EINTR). Set errno and |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1429 | return. The sets are unspecified in this case. */ |
sewardj | 02535bc | 2002-04-21 01:08:26 +0000 | [diff] [blame] | 1430 | * (__errno_location()) = -res; |
| 1431 | return -1; |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1432 | } |
| 1433 | if (res > 0) { |
| 1434 | /* one or more fds is ready. Copy out resulting sets and |
| 1435 | return. */ |
| 1436 | if (rfds) *rfds = rfds_copy; |
| 1437 | if (wfds) *wfds = wfds_copy; |
| 1438 | if (xfds) *xfds = xfds_copy; |
| 1439 | return res; |
| 1440 | } |
| 1441 | /* fprintf(stderr, "MY_SELECT: nanosleep\n"); */ |
| 1442 | /* nanosleep and go round again */ |
sewardj | 02535bc | 2002-04-21 01:08:26 +0000 | [diff] [blame] | 1443 | nanosleep_interval.tv_sec = 0; |
sewardj | 956cc1b | 2002-04-25 01:33:50 +0000 | [diff] [blame] | 1444 | nanosleep_interval.tv_nsec = 50 * 1000 * 1000; /* 50 milliseconds */ |
sewardj | f854f47 | 2002-04-21 12:19:41 +0000 | [diff] [blame] | 1445 | /* It's critical here that valgrind's nanosleep implementation |
| 1446 | is nonblocking. */ |
| 1447 | (void)my_do_syscall2(__NR_nanosleep, |
| 1448 | (int)(&nanosleep_interval), (int)NULL); |
| 1449 | } |
| 1450 | } |
| 1451 | |
| 1452 | |
| 1453 | |
| 1454 | |
| 1455 | #include <sys/poll.h> |
| 1456 | |
sewardj | 72d5848 | 2002-04-24 02:20:20 +0000 | [diff] [blame] | 1457 | #ifdef GLIBC_2_1 |
| 1458 | typedef unsigned long int nfds_t; |
| 1459 | #endif |
| 1460 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1461 | /* __attribute__((weak)) */ |
sewardj | f854f47 | 2002-04-21 12:19:41 +0000 | [diff] [blame] | 1462 | int poll (struct pollfd *__fds, nfds_t __nfds, int __timeout) |
| 1463 | { |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 1464 | unsigned int ms_now, ms_end; |
sewardj | f854f47 | 2002-04-21 12:19:41 +0000 | [diff] [blame] | 1465 | int res, i; |
sewardj | f854f47 | 2002-04-21 12:19:41 +0000 | [diff] [blame] | 1466 | struct vki_timespec nanosleep_interval; |
| 1467 | |
| 1468 | ensure_valgrind("poll"); |
| 1469 | |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 1470 | /* Detect the current time and simultaneously find out if we are |
| 1471 | running on Valgrind. */ |
| 1472 | VALGRIND_MAGIC_SEQUENCE(ms_now, 0xFFFFFFFF /* default */, |
| 1473 | VG_USERREQ__READ_MILLISECOND_TIMER, |
| 1474 | 0, 0, 0, 0); |
| 1475 | |
sewardj | f854f47 | 2002-04-21 12:19:41 +0000 | [diff] [blame] | 1476 | if (/* CHECK SIZES FOR struct pollfd */ |
| 1477 | sizeof(struct timeval) != sizeof(struct vki_timeval)) |
| 1478 | barf("valgrind's hacky non-blocking poll(): data sizes error"); |
| 1479 | |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 1480 | /* dummy initialisation to keep gcc -Wall happy */ |
| 1481 | ms_end = 0; |
| 1482 | |
| 1483 | /* If a zero timeout specified, this call is harmless. Also do |
| 1484 | this if not running on Valgrind. */ |
| 1485 | if (__timeout == 0 || ms_now == 0xFFFFFFFF) { |
sewardj | f854f47 | 2002-04-21 12:19:41 +0000 | [diff] [blame] | 1486 | res = my_do_syscall3(__NR_poll, (int)__fds, __nfds, __timeout); |
| 1487 | if (is_kerror(res)) { |
| 1488 | * (__errno_location()) = -res; |
| 1489 | return -1; |
| 1490 | } else { |
| 1491 | return res; |
| 1492 | } |
| 1493 | } |
| 1494 | |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 1495 | /* If a timeout was specified, set ms_end to be the end wallclock |
| 1496 | time. Easy considering that __timeout is in milliseconds. */ |
sewardj | f854f47 | 2002-04-21 12:19:41 +0000 | [diff] [blame] | 1497 | if (__timeout > 0) { |
sewardj | 650ac00 | 2002-04-29 12:20:34 +0000 | [diff] [blame] | 1498 | ms_end = ms_now + (unsigned int)__timeout; |
sewardj | f854f47 | 2002-04-21 12:19:41 +0000 | [diff] [blame] | 1499 | } |
| 1500 | |
| 1501 | /* fprintf(stderr, "MY_POLL: before loop\n"); */ |
| 1502 | |
| 1503 | /* Either timeout < 0, meaning wait indefinitely, or timeout > 0, |
| 1504 | in which case t_end holds the end time. */ |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 1505 | assert(__timeout != 0); |
| 1506 | |
sewardj | f854f47 | 2002-04-21 12:19:41 +0000 | [diff] [blame] | 1507 | while (1) { |
sewardj | f854f47 | 2002-04-21 12:19:41 +0000 | [diff] [blame] | 1508 | if (__timeout > 0) { |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 1509 | VALGRIND_MAGIC_SEQUENCE(ms_now, 0xFFFFFFFF /* default */, |
| 1510 | VG_USERREQ__READ_MILLISECOND_TIMER, |
| 1511 | 0, 0, 0, 0); |
| 1512 | assert(ms_now != 0xFFFFFFFF); |
| 1513 | if (ms_now >= ms_end) { |
sewardj | f854f47 | 2002-04-21 12:19:41 +0000 | [diff] [blame] | 1514 | /* timeout; nothing interesting happened. */ |
| 1515 | for (i = 0; i < __nfds; i++) |
| 1516 | __fds[i].revents = 0; |
| 1517 | return 0; |
| 1518 | } |
| 1519 | } |
| 1520 | |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 1521 | /* Do a return-immediately poll. */ |
sewardj | f854f47 | 2002-04-21 12:19:41 +0000 | [diff] [blame] | 1522 | res = my_do_syscall3(__NR_poll, (int)__fds, __nfds, 0 ); |
| 1523 | if (is_kerror(res)) { |
| 1524 | /* Some kind of error. Set errno and return. */ |
| 1525 | * (__errno_location()) = -res; |
| 1526 | return -1; |
| 1527 | } |
| 1528 | if (res > 0) { |
| 1529 | /* One or more fds is ready. Return now. */ |
| 1530 | return res; |
| 1531 | } |
| 1532 | /* fprintf(stderr, "MY_POLL: nanosleep\n"); */ |
| 1533 | /* nanosleep and go round again */ |
| 1534 | nanosleep_interval.tv_sec = 0; |
sewardj | 956cc1b | 2002-04-25 01:33:50 +0000 | [diff] [blame] | 1535 | nanosleep_interval.tv_nsec = 51 * 1000 * 1000; /* 51 milliseconds */ |
sewardj | 08a4c3f | 2002-04-13 03:45:44 +0000 | [diff] [blame] | 1536 | /* It's critical here that valgrind's nanosleep implementation |
| 1537 | is nonblocking. */ |
| 1538 | (void)my_do_syscall2(__NR_nanosleep, |
| 1539 | (int)(&nanosleep_interval), (int)NULL); |
| 1540 | } |
| 1541 | } |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 1542 | |
| 1543 | |
| 1544 | /* --------------------------------------------------------------------- |
sewardj | 8f253ff | 2002-05-19 00:13:34 +0000 | [diff] [blame] | 1545 | Hacky implementation of semaphores. |
| 1546 | ------------------------------------------------------------------ */ |
| 1547 | |
| 1548 | #include <semaphore.h> |
| 1549 | |
| 1550 | /* This is a terrible way to do the remapping. Plan is to import an |
| 1551 | AVL tree at some point. */ |
| 1552 | #define VG_N_SEMAPHORES 50 |
| 1553 | |
| 1554 | typedef |
| 1555 | struct { |
| 1556 | pthread_mutex_t se_mx; |
| 1557 | pthread_cond_t se_cv; |
| 1558 | int count; |
| 1559 | } |
| 1560 | vg_sem_t; |
| 1561 | |
| 1562 | static pthread_mutex_t se_remap_mx = PTHREAD_MUTEX_INITIALIZER; |
| 1563 | |
| 1564 | static int se_remap_used = 0; |
| 1565 | static sem_t* se_remap_orig[VG_N_SEMAPHORES]; |
| 1566 | static vg_sem_t se_remap_new[VG_N_SEMAPHORES]; |
| 1567 | |
| 1568 | static vg_sem_t* se_remap ( sem_t* orig ) |
| 1569 | { |
| 1570 | int res, i; |
| 1571 | res = __pthread_mutex_lock(&se_remap_mx); |
| 1572 | assert(res == 0); |
| 1573 | |
| 1574 | for (i = 0; i < se_remap_used; i++) { |
| 1575 | if (se_remap_orig[i] == orig) |
| 1576 | break; |
| 1577 | } |
| 1578 | if (i == se_remap_used) { |
| 1579 | if (se_remap_used == VG_N_SEMAPHORES) { |
| 1580 | res = pthread_mutex_unlock(&se_remap_mx); |
| 1581 | assert(res == 0); |
| 1582 | barf("N_SEMAPHORES is too low. Increase and recompile."); |
| 1583 | } |
| 1584 | se_remap_used++; |
| 1585 | se_remap_orig[i] = orig; |
| 1586 | /* printf("allocated semaphore %d\n", i); */ |
| 1587 | } |
| 1588 | res = __pthread_mutex_unlock(&se_remap_mx); |
| 1589 | assert(res == 0); |
| 1590 | return &se_remap_new[i]; |
| 1591 | } |
| 1592 | |
| 1593 | |
| 1594 | int sem_init(sem_t *sem, int pshared, unsigned int value) |
| 1595 | { |
| 1596 | int res; |
| 1597 | vg_sem_t* vg_sem; |
| 1598 | ensure_valgrind("sem_init"); |
| 1599 | if (pshared != 0) { |
| 1600 | errno = ENOSYS; |
| 1601 | return -1; |
| 1602 | } |
| 1603 | vg_sem = se_remap(sem); |
| 1604 | res = pthread_mutex_init(&vg_sem->se_mx, NULL); |
| 1605 | assert(res == 0); |
| 1606 | res = pthread_cond_init(&vg_sem->se_cv, NULL); |
| 1607 | assert(res == 0); |
| 1608 | vg_sem->count = value; |
| 1609 | return 0; |
| 1610 | } |
| 1611 | |
| 1612 | |
| 1613 | int sem_wait ( sem_t* sem ) |
| 1614 | { |
| 1615 | int res; |
| 1616 | vg_sem_t* vg_sem; |
| 1617 | ensure_valgrind("sem_wait"); |
| 1618 | vg_sem = se_remap(sem); |
| 1619 | res = __pthread_mutex_lock(&vg_sem->se_mx); |
| 1620 | assert(res == 0); |
| 1621 | while (vg_sem->count == 0) { |
| 1622 | res = pthread_cond_wait(&vg_sem->se_cv, &vg_sem->se_mx); |
| 1623 | assert(res == 0); |
| 1624 | } |
| 1625 | vg_sem->count--; |
| 1626 | res = __pthread_mutex_unlock(&vg_sem->se_mx); |
| 1627 | assert(res == 0); |
| 1628 | return 0; |
| 1629 | } |
| 1630 | |
| 1631 | int sem_post ( sem_t* sem ) |
| 1632 | { |
| 1633 | int res; |
| 1634 | vg_sem_t* vg_sem; |
| 1635 | ensure_valgrind("sem_post"); |
| 1636 | vg_sem = se_remap(sem); |
| 1637 | res = __pthread_mutex_lock(&vg_sem->se_mx); |
| 1638 | assert(res == 0); |
| 1639 | if (vg_sem->count == 0) { |
| 1640 | vg_sem->count++; |
| 1641 | res = pthread_cond_broadcast(&vg_sem->se_cv); |
| 1642 | assert(res == 0); |
| 1643 | } else { |
| 1644 | vg_sem->count++; |
| 1645 | } |
| 1646 | res = __pthread_mutex_unlock(&vg_sem->se_mx); |
| 1647 | assert(res == 0); |
| 1648 | return 0; |
| 1649 | } |
| 1650 | |
| 1651 | |
| 1652 | int sem_trywait ( sem_t* sem ) |
| 1653 | { |
| 1654 | int ret, res; |
| 1655 | vg_sem_t* vg_sem; |
| 1656 | ensure_valgrind("sem_trywait"); |
| 1657 | vg_sem = se_remap(sem); |
| 1658 | res = __pthread_mutex_lock(&vg_sem->se_mx); |
| 1659 | assert(res == 0); |
| 1660 | if (vg_sem->count > 0) { |
| 1661 | vg_sem->count--; |
| 1662 | ret = 0; |
| 1663 | } else { |
| 1664 | ret = -1; |
| 1665 | errno = EAGAIN; |
| 1666 | } |
| 1667 | res = __pthread_mutex_unlock(&vg_sem->se_mx); |
| 1668 | assert(res == 0); |
| 1669 | return ret; |
| 1670 | } |
| 1671 | |
| 1672 | |
| 1673 | int sem_getvalue(sem_t* sem, int * sval) |
| 1674 | { |
| 1675 | vg_sem_t* vg_sem; |
| 1676 | ensure_valgrind("sem_trywait"); |
| 1677 | vg_sem = se_remap(sem); |
| 1678 | *sval = vg_sem->count; |
| 1679 | return 0; |
| 1680 | } |
| 1681 | |
| 1682 | |
| 1683 | int sem_destroy(sem_t * sem) |
| 1684 | { |
| 1685 | kludged("sem_destroy"); |
| 1686 | /* if someone waiting on this semaphore, errno = EBUSY, return -1 */ |
| 1687 | return 0; |
| 1688 | } |
| 1689 | |
| 1690 | |
| 1691 | /* --------------------------------------------------------------------- |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 1692 | B'stard. |
| 1693 | ------------------------------------------------------------------ */ |
| 1694 | |
| 1695 | # define strong_alias(name, aliasname) \ |
| 1696 | extern __typeof (name) aliasname __attribute__ ((alias (#name))); |
| 1697 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1698 | # define weak_alias(name, aliasname) \ |
| 1699 | extern __typeof (name) aliasname __attribute__ ((weak, alias (#name))); |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 1700 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1701 | strong_alias(__pthread_mutex_lock, pthread_mutex_lock) |
| 1702 | strong_alias(__pthread_mutex_trylock, pthread_mutex_trylock) |
| 1703 | strong_alias(__pthread_mutex_unlock, pthread_mutex_unlock) |
| 1704 | strong_alias(__pthread_mutexattr_init, pthread_mutexattr_init) |
| 1705 | weak_alias(__pthread_mutexattr_settype, pthread_mutexattr_settype) |
| 1706 | strong_alias(__pthread_mutex_init, pthread_mutex_init) |
| 1707 | strong_alias(__pthread_mutexattr_destroy, pthread_mutexattr_destroy) |
| 1708 | strong_alias(__pthread_mutex_destroy, pthread_mutex_destroy) |
| 1709 | strong_alias(__pthread_once, pthread_once) |
| 1710 | strong_alias(__pthread_atfork, pthread_atfork) |
| 1711 | strong_alias(__pthread_key_create, pthread_key_create) |
| 1712 | strong_alias(__pthread_getspecific, pthread_getspecific) |
| 1713 | strong_alias(__pthread_setspecific, pthread_setspecific) |
| 1714 | |
sewardj | d529a44 | 2002-05-04 19:49:21 +0000 | [diff] [blame] | 1715 | #ifndef GLIBC_2_1 |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 1716 | strong_alias(sigaction, __sigaction) |
sewardj | d529a44 | 2002-05-04 19:49:21 +0000 | [diff] [blame] | 1717 | #endif |
| 1718 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1719 | strong_alias(close, __close) |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 1720 | strong_alias(fcntl, __fcntl) |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1721 | strong_alias(lseek, __lseek) |
| 1722 | strong_alias(open, __open) |
| 1723 | strong_alias(open64, __open64) |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1724 | strong_alias(read, __read) |
| 1725 | strong_alias(wait, __wait) |
| 1726 | strong_alias(write, __write) |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 1727 | strong_alias(connect, __connect) |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1728 | strong_alias(send, __send) |
| 1729 | |
sewardj | 726c412 | 2002-05-16 23:39:10 +0000 | [diff] [blame] | 1730 | weak_alias (__pread64, pread64) |
sewardj | a18e210 | 2002-05-18 10:43:22 +0000 | [diff] [blame] | 1731 | weak_alias (__pwrite64, pwrite64) |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1732 | weak_alias(__fork, fork) |
sewardj | 7f6456d | 2002-05-21 00:51:21 +0000 | [diff] [blame] | 1733 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1734 | |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 1735 | |
| 1736 | /*--------------------------------------------------*/ |
| 1737 | |
sewardj | 5716dbb | 2002-04-26 03:28:18 +0000 | [diff] [blame] | 1738 | int |
| 1739 | pthread_rwlock_rdlock (void* /* pthread_rwlock_t* */ rwlock) |
| 1740 | { |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 1741 | static int moans = N_MOANS; |
| 1742 | if (moans-- > 0) |
| 1743 | kludged("pthread_rwlock_rdlock"); |
sewardj | 5716dbb | 2002-04-26 03:28:18 +0000 | [diff] [blame] | 1744 | return 0; |
| 1745 | } |
| 1746 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1747 | weak_alias(pthread_rwlock_rdlock, __pthread_rwlock_rdlock) |
sewardj | 5716dbb | 2002-04-26 03:28:18 +0000 | [diff] [blame] | 1748 | |
| 1749 | |
| 1750 | int |
| 1751 | pthread_rwlock_unlock (void* /* pthread_rwlock_t* */ rwlock) |
| 1752 | { |
sewardj | 436e058 | 2002-04-26 14:31:40 +0000 | [diff] [blame] | 1753 | static int moans = N_MOANS; |
| 1754 | if (moans-- > 0) |
| 1755 | kludged("pthread_rwlock_unlock"); |
sewardj | 5716dbb | 2002-04-26 03:28:18 +0000 | [diff] [blame] | 1756 | return 0; |
| 1757 | } |
| 1758 | |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1759 | weak_alias(pthread_rwlock_unlock, __pthread_rwlock_unlock) |
sewardj | 5716dbb | 2002-04-26 03:28:18 +0000 | [diff] [blame] | 1760 | |
| 1761 | |
sewardj | 060b04f | 2002-04-26 21:01:13 +0000 | [diff] [blame] | 1762 | int |
| 1763 | pthread_rwlock_wrlock (void* /* pthread_rwlock_t* */ rwlock) |
| 1764 | { |
| 1765 | static int moans = N_MOANS; |
| 1766 | if (moans-- > 0) |
| 1767 | kludged("pthread_rwlock_wrlock"); |
| 1768 | return 0; |
| 1769 | } |
| 1770 | |
sewardj | 262b029 | 2002-05-01 00:03:16 +0000 | [diff] [blame] | 1771 | weak_alias(pthread_rwlock_wrlock, __pthread_rwlock_wrlock) |
sewardj | 060b04f | 2002-04-26 21:01:13 +0000 | [diff] [blame] | 1772 | |
| 1773 | |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 1774 | /* I've no idea what these are, but they get called quite a lot. |
| 1775 | Anybody know? */ |
| 1776 | |
| 1777 | #undef _IO_flockfile |
| 1778 | void _IO_flockfile ( _IO_FILE * file ) |
| 1779 | { |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 1780 | pthread_mutex_lock(file->_lock); |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 1781 | } |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1782 | weak_alias(_IO_flockfile, flockfile); |
| 1783 | |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 1784 | |
| 1785 | #undef _IO_funlockfile |
| 1786 | void _IO_funlockfile ( _IO_FILE * file ) |
| 1787 | { |
sewardj | 853f55d | 2002-04-26 00:27:53 +0000 | [diff] [blame] | 1788 | pthread_mutex_unlock(file->_lock); |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 1789 | } |
sewardj | 5905fae | 2002-04-26 13:25:00 +0000 | [diff] [blame] | 1790 | weak_alias(_IO_funlockfile, funlockfile); |
| 1791 | |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 1792 | |
| 1793 | void _pthread_cleanup_push_defer ( void ) |
| 1794 | { |
sewardj | 439d45e | 2002-05-03 20:43:10 +0000 | [diff] [blame] | 1795 | static int moans = N_MOANS; |
| 1796 | if (moans-- > 0) |
| 1797 | ignored("_pthread_cleanup_push_defer"); |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 1798 | } |
| 1799 | |
| 1800 | void _pthread_cleanup_pop_restore ( void ) |
| 1801 | { |
sewardj | 439d45e | 2002-05-03 20:43:10 +0000 | [diff] [blame] | 1802 | static int moans = N_MOANS; |
| 1803 | if (moans-- > 0) |
| 1804 | ignored("_pthread_cleanup_pop_restore"); |
sewardj | 3b13f0e | 2002-04-25 20:17:29 +0000 | [diff] [blame] | 1805 | } |
sewardj | d4f2c71 | 2002-04-30 10:20:10 +0000 | [diff] [blame] | 1806 | |
sewardj | 60e3842 | 2002-05-08 14:08:22 +0000 | [diff] [blame] | 1807 | /*--------*/ |
| 1808 | void _pthread_cleanup_push (struct _pthread_cleanup_buffer *__buffer, |
| 1809 | void (*__routine) (void *), |
| 1810 | void *__arg) |
| 1811 | { |
| 1812 | static int moans = N_MOANS; |
| 1813 | if (moans-- > 0) |
| 1814 | ignored("_pthread_cleanup_push"); |
| 1815 | } |
| 1816 | |
| 1817 | void _pthread_cleanup_pop (struct _pthread_cleanup_buffer *__buffer, |
| 1818 | int __execute) |
| 1819 | { |
| 1820 | static int moans = N_MOANS; |
| 1821 | if (moans-- > 0) { |
| 1822 | if (__execute) |
| 1823 | ignored("_pthread_cleanup_pop-EXECUTE"); |
| 1824 | else |
| 1825 | ignored("_pthread_cleanup_pop-NO-EXECUTE"); |
| 1826 | } |
| 1827 | } |
| 1828 | |
sewardj | d4f2c71 | 2002-04-30 10:20:10 +0000 | [diff] [blame] | 1829 | |
| 1830 | /* This doesn't seem to be needed to simulate libpthread.so's external |
| 1831 | interface, but many people complain about its absence. */ |
| 1832 | |
| 1833 | strong_alias(__pthread_mutexattr_settype, __pthread_mutexattr_setkind_np) |
| 1834 | weak_alias(__pthread_mutexattr_setkind_np, pthread_mutexattr_setkind_np) |
sewardj | 439d45e | 2002-05-03 20:43:10 +0000 | [diff] [blame] | 1835 | |
| 1836 | |
| 1837 | /*--------------------------------------------------------------------*/ |
| 1838 | /*--- end vg_libpthread.c ---*/ |
| 1839 | /*--------------------------------------------------------------------*/ |