sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1 | |
| 2 | /*--------------------------------------------------------------------*/ |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 3 | /*--- Client-space code for drd. drd_intercepts.c ---*/ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 4 | /*--------------------------------------------------------------------*/ |
| 5 | |
| 6 | /* |
| 7 | This file is part of drd, a data race detector. |
| 8 | |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 9 | Copyright (C) 2006-2008 Bart Van Assche |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 10 | bart.vanassche@gmail.com |
| 11 | |
| 12 | This program is free software; you can redistribute it and/or |
| 13 | modify it under the terms of the GNU General Public License as |
| 14 | published by the Free Software Foundation; either version 2 of the |
| 15 | License, or (at your option) any later version. |
| 16 | |
| 17 | This program is distributed in the hope that it will be useful, but |
| 18 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 20 | General Public License for more details. |
| 21 | |
| 22 | You should have received a copy of the GNU General Public License |
| 23 | along with this program; if not, write to the Free Software |
| 24 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 25 | 02111-1307, USA. |
| 26 | |
| 27 | The GNU General Public License is contained in the file COPYING. |
| 28 | */ |
| 29 | |
| 30 | /* --------------------------------------------------------------------- |
| 31 | ALL THE CODE IN THIS FILE RUNS ON THE SIMULATED CPU. |
| 32 | |
| 33 | These functions are not called directly - they're the targets of code |
| 34 | redirection or load notifications (see pub_core_redir.h for info). |
| 35 | They're named weirdly so that the intercept code can find them when the |
| 36 | shared object is initially loaded. |
| 37 | |
| 38 | Note that this filename has the "drd_" prefix because it can appear |
| 39 | in stack traces, and the "drd_" makes it a little clearer that it |
| 40 | originates from Valgrind. |
| 41 | ------------------------------------------------------------------ */ |
| 42 | |
| 43 | // Make sure pthread_spinlock_t is available on glibc 2.3.2 systems. |
| 44 | #ifndef _GNU_SOURCE |
| 45 | #define _GNU_SOURCE |
| 46 | #endif |
| 47 | |
| 48 | #include <assert.h> |
| 49 | #include <inttypes.h> // uintptr_t |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 50 | #include <pthread.h> |
| 51 | #include <semaphore.h> |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 52 | #include <stdio.h> |
| 53 | #include <unistd.h> |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 54 | #include "drd_clientreq.h" |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 55 | #include "pub_tool_redir.h" |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 56 | |
| 57 | |
| 58 | // Defines. |
| 59 | |
| 60 | #define PTH_FUNC(ret_ty, f, args...) \ |
| 61 | ret_ty VG_WRAP_FUNCTION_ZZ(libpthreadZdsoZd0,f)(args); \ |
| 62 | ret_ty VG_WRAP_FUNCTION_ZZ(libpthreadZdsoZd0,f)(args) |
| 63 | |
| 64 | |
| 65 | // Local data structures. |
| 66 | |
| 67 | typedef struct |
| 68 | { |
| 69 | void* (*start)(void*); |
| 70 | void* arg; |
| 71 | int detachstate; |
| 72 | #if 0 |
| 73 | pthread_mutex_t mutex; |
| 74 | pthread_cond_t cond; |
| 75 | #else |
| 76 | int wrapper_started; |
| 77 | #endif |
| 78 | } VgPosixThreadArgs; |
| 79 | |
| 80 | |
| 81 | // Local variables. |
| 82 | |
| 83 | static int vg_main_thread_state_is_set = 0; |
| 84 | |
| 85 | |
| 86 | // Function definitions. |
| 87 | |
bart | 5357fcb | 2008-02-27 15:46:00 +0000 | [diff] [blame] | 88 | static MutexT pthread_to_drd_mutex_type(const int kind) |
| 89 | { |
| 90 | switch (kind) |
| 91 | { |
| 92 | /* PTHREAD_MUTEX_RECURSIVE_NP */ |
| 93 | case PTHREAD_MUTEX_RECURSIVE: |
| 94 | return mutex_type_recursive_mutex; |
| 95 | /* PTHREAD_MUTEX_ERRORCHECK_NP */ |
| 96 | case PTHREAD_MUTEX_ERRORCHECK: |
| 97 | return mutex_type_errorcheck_mutex; |
| 98 | /* PTHREAD_MUTEX_TIMED_NP */ |
| 99 | /* PTHREAD_MUTEX_NORMAL */ |
| 100 | case PTHREAD_MUTEX_DEFAULT: |
| 101 | case PTHREAD_MUTEX_ADAPTIVE_NP: |
| 102 | return mutex_type_default_mutex; |
| 103 | #if 0 |
| 104 | case -1: |
| 105 | printf("Warning: changed mutex type from -1 into %d\n", |
| 106 | mutex_type_default_mutex); |
| 107 | return mutex_type_default_mutex; |
| 108 | #endif |
| 109 | } |
| 110 | #if 0 |
| 111 | printf("mutex->__data.__kind = %d\n", kind); |
| 112 | assert(0); |
| 113 | #endif |
| 114 | return mutex_type_default_mutex; |
| 115 | } |
| 116 | |
| 117 | static MutexT mutex_type(pthread_mutex_t* mutex) |
| 118 | { |
| 119 | return pthread_to_drd_mutex_type(mutex->__data.__kind); |
| 120 | } |
| 121 | |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 122 | static void vg_start_suppression(const void* const p, size_t const size) |
| 123 | { |
| 124 | int res; |
| 125 | VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__DRD_START_SUPPRESSION, |
| 126 | p, size, 0, 0, 0); |
| 127 | } |
| 128 | |
| 129 | #if 0 |
| 130 | static void vg_finish_suppression(const void* const p, size_t const size) |
| 131 | { |
| 132 | int res; |
| 133 | VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__DRD_FINISH_SUPPRESSION, |
| 134 | p, size, 0, 0, 0); |
| 135 | } |
| 136 | #endif |
| 137 | |
| 138 | static void vg_start_recording(void) |
| 139 | { |
| 140 | int res; |
| 141 | VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__DRD_START_RECORDING, |
| 142 | pthread_self(), 0, 0, 0, 0); |
| 143 | } |
| 144 | |
| 145 | static void vg_stop_recording(void) |
| 146 | { |
| 147 | int res; |
| 148 | VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__DRD_STOP_RECORDING, |
| 149 | pthread_self(), 0, 0, 0, 0); |
| 150 | } |
| 151 | |
| 152 | static void vg_set_joinable(const pthread_t tid, const int joinable) |
| 153 | { |
| 154 | int res; |
| 155 | assert(joinable == 0 || joinable == 1); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 156 | VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__SET_JOINABLE, |
| 157 | tid, joinable, 0, 0, 0); |
| 158 | } |
| 159 | |
| 160 | static void* vg_thread_wrapper(void* arg) |
| 161 | { |
| 162 | int res; |
| 163 | VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__DRD_SUPPRESS_CURRENT_STACK, |
| 164 | 0, 0, 0, 0, 0); |
| 165 | |
| 166 | { |
| 167 | VgPosixThreadArgs* const arg_ptr = (VgPosixThreadArgs*)arg; |
| 168 | VgPosixThreadArgs const arg_copy = *arg_ptr; |
| 169 | void* result; |
| 170 | |
| 171 | #if 0 |
| 172 | pthread_mutex_lock(arg_ptr->mutex); |
| 173 | pthread_cond_signal(arg_ptr->cond); |
| 174 | pthread_mutex_unlock(arg_ptr->mutex); |
| 175 | #else |
| 176 | arg_ptr->wrapper_started = 1; |
| 177 | #endif |
| 178 | |
| 179 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__SET_PTHREADID, |
| 180 | pthread_self(), 0, 0, 0, 0); |
| 181 | vg_set_joinable(pthread_self(), |
| 182 | arg_copy.detachstate == PTHREAD_CREATE_JOINABLE); |
| 183 | result = (arg_copy.start)(arg_copy.arg); |
| 184 | return result; |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | static void vg_set_main_thread_state(void) |
| 189 | { |
| 190 | int res; |
| 191 | |
| 192 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__DRD_SUPPRESS_CURRENT_STACK, |
| 193 | 0, 0, 0, 0, 0); |
| 194 | |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 195 | // Make sure that DRD knows about the main thread's POSIX thread ID. |
| 196 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__SET_PTHREADID, |
| 197 | pthread_self(), 0, 0, 0, 0); |
| 198 | |
| 199 | } |
| 200 | |
| 201 | // pthread_create |
sewardj | 347eeba | 2008-01-21 14:19:07 +0000 | [diff] [blame] | 202 | PTH_FUNC(int, pthreadZucreateZa, // pthread_create* |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 203 | pthread_t *thread, const pthread_attr_t *attr, |
| 204 | void *(*start) (void *), void *arg) |
| 205 | { |
| 206 | int ret; |
| 207 | OrigFn fn; |
| 208 | VgPosixThreadArgs vgargs; |
| 209 | |
| 210 | VALGRIND_GET_ORIG_FN(fn); |
| 211 | |
| 212 | if (vg_main_thread_state_is_set == 0) |
| 213 | { |
| 214 | vg_set_main_thread_state(); |
| 215 | vg_main_thread_state_is_set = 1; |
| 216 | } |
| 217 | vg_start_suppression(&vgargs.wrapper_started, |
| 218 | sizeof(vgargs.wrapper_started)); |
| 219 | vgargs.start = start; |
| 220 | vgargs.arg = arg; |
| 221 | vgargs.wrapper_started = 0; |
| 222 | vgargs.detachstate = PTHREAD_CREATE_JOINABLE; |
| 223 | if (attr) |
| 224 | { |
| 225 | if (pthread_attr_getdetachstate(attr, &vgargs.detachstate) != 0) |
| 226 | { |
| 227 | assert(0); |
| 228 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 229 | } |
| 230 | assert(vgargs.detachstate == PTHREAD_CREATE_JOINABLE |
| 231 | || vgargs.detachstate == PTHREAD_CREATE_DETACHED); |
| 232 | #if 0 |
| 233 | pthread_mutex_init(&vgargs.mutex, 0); |
| 234 | pthread_cond_init(&vgargs.cond, 0); |
| 235 | pthread_mutex_lock(&vgargs.mutex); |
| 236 | #endif |
| 237 | vg_stop_recording(); |
| 238 | CALL_FN_W_WWWW(ret, fn, thread, attr, vg_thread_wrapper, &vgargs); |
| 239 | vg_start_recording(); |
| 240 | #if 0 |
| 241 | pthread_cond_wait(&vgargs.cond, &vgargs.mutex); |
| 242 | pthread_mutex_unlock(&vgargs.mutex); |
| 243 | pthread_cond_destroy(&vgargs.cond); |
| 244 | pthread_mutex_destroy(&vgargs.mutex); |
| 245 | #else |
| 246 | // Yes, you see it correctly, busy waiting ... The problem is that |
| 247 | // POSIX threads functions cannot be called here -- the functions defined |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 248 | // in this file (drd_intercepts.c) would be called instead of those in |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 249 | // libpthread.so. This loop is necessary because vgargs is allocated on the |
| 250 | // stack, and the created thread reads it. |
sewardj | e0744f0 | 2007-12-01 02:09:50 +0000 | [diff] [blame] | 251 | if (ret == 0) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 252 | { |
sewardj | e0744f0 | 2007-12-01 02:09:50 +0000 | [diff] [blame] | 253 | while (! vgargs.wrapper_started) |
| 254 | { |
| 255 | sched_yield(); |
| 256 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 257 | } |
| 258 | #endif |
| 259 | return ret; |
| 260 | } |
| 261 | |
| 262 | // pthread_join |
| 263 | PTH_FUNC(int, pthreadZujoin, // pthread_join |
| 264 | pthread_t pt_joinee, void **thread_return) |
| 265 | { |
| 266 | int ret; |
| 267 | int res; |
| 268 | OrigFn fn; |
| 269 | |
| 270 | VALGRIND_GET_ORIG_FN(fn); |
| 271 | CALL_FN_W_WW(ret, fn, pt_joinee, thread_return); |
| 272 | if (ret == 0) |
| 273 | { |
| 274 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_THREAD_JOIN, |
| 275 | pt_joinee, 0, 0, 0, 0); |
| 276 | } |
| 277 | return ret; |
| 278 | } |
| 279 | |
| 280 | // pthread_detach |
| 281 | PTH_FUNC(int, pthreadZudetach, pthread_t pt_thread) |
| 282 | { |
| 283 | int ret; |
| 284 | OrigFn fn; |
| 285 | VALGRIND_GET_ORIG_FN(fn); |
| 286 | { |
| 287 | CALL_FN_W_W(ret, fn, pt_thread); |
| 288 | if (ret == 0) |
| 289 | { |
| 290 | vg_set_joinable(pt_thread, 0); |
| 291 | } |
| 292 | } |
| 293 | return ret; |
| 294 | } |
| 295 | |
| 296 | // pthread_mutex_init |
| 297 | PTH_FUNC(int, pthreadZumutexZuinit, |
| 298 | pthread_mutex_t *mutex, |
| 299 | const pthread_mutexattr_t* attr) |
| 300 | { |
| 301 | int ret; |
| 302 | int res; |
| 303 | OrigFn fn; |
bart | 5357fcb | 2008-02-27 15:46:00 +0000 | [diff] [blame] | 304 | int mt = PTHREAD_MUTEX_DEFAULT; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 305 | VALGRIND_GET_ORIG_FN(fn); |
bart | 5357fcb | 2008-02-27 15:46:00 +0000 | [diff] [blame] | 306 | if (attr) |
| 307 | pthread_mutexattr_gettype(attr, &mt); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 308 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_MUTEX_INIT, |
bart | 5357fcb | 2008-02-27 15:46:00 +0000 | [diff] [blame] | 309 | mutex, sizeof(*mutex), |
| 310 | pthread_to_drd_mutex_type(mt), 0, 0); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 311 | CALL_FN_W_WW(ret, fn, mutex, attr); |
| 312 | return ret; |
| 313 | } |
| 314 | |
| 315 | // pthread_mutex_destroy |
| 316 | PTH_FUNC(int, pthreadZumutexZudestroy, |
| 317 | pthread_mutex_t *mutex) |
| 318 | { |
| 319 | int ret; |
| 320 | int res; |
| 321 | OrigFn fn; |
| 322 | VALGRIND_GET_ORIG_FN(fn); |
| 323 | CALL_FN_W_W(ret, fn, mutex); |
| 324 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_MUTEX_DESTROY, |
bart | 5357fcb | 2008-02-27 15:46:00 +0000 | [diff] [blame] | 325 | mutex, mutex_type(mutex), 0, 0, 0); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 326 | return ret; |
| 327 | } |
| 328 | |
| 329 | // pthread_mutex_lock |
| 330 | PTH_FUNC(int, pthreadZumutexZulock, // pthread_mutex_lock |
| 331 | pthread_mutex_t *mutex) |
| 332 | { |
| 333 | int ret; |
| 334 | int res; |
| 335 | OrigFn fn; |
| 336 | VALGRIND_GET_ORIG_FN(fn); |
| 337 | VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__PRE_PTHREAD_MUTEX_LOCK, |
bart | 5357fcb | 2008-02-27 15:46:00 +0000 | [diff] [blame] | 338 | mutex, sizeof(*mutex), mutex_type(mutex), 0, 0); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 339 | #if 1 |
| 340 | // The only purpose of the system call below is to make drd work on AMD64 |
| 341 | // systems. Without this system call, clients crash (SIGSEGV) in |
| 342 | // std::locale::locale(). |
| 343 | write(1, "", 0); |
| 344 | #endif |
| 345 | CALL_FN_W_W(ret, fn, mutex); |
| 346 | if (ret == 0) |
| 347 | VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__POST_PTHREAD_MUTEX_LOCK, |
bart | 5357fcb | 2008-02-27 15:46:00 +0000 | [diff] [blame] | 348 | mutex, sizeof(*mutex), mutex_type(mutex), 0, 0); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 349 | return ret; |
| 350 | } |
| 351 | |
| 352 | // pthread_mutex_trylock |
| 353 | PTH_FUNC(int, pthreadZumutexZutrylock, // pthread_mutex_trylock |
| 354 | pthread_mutex_t *mutex) |
| 355 | { |
| 356 | int ret; |
| 357 | int res; |
| 358 | OrigFn fn; |
| 359 | VALGRIND_GET_ORIG_FN(fn); |
| 360 | CALL_FN_W_W(ret, fn, mutex); |
| 361 | if (ret == 0) |
| 362 | { |
| 363 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_PTHREAD_MUTEX_LOCK, |
bart | 5357fcb | 2008-02-27 15:46:00 +0000 | [diff] [blame] | 364 | mutex, sizeof(*mutex), mutex_type(mutex), 0, 0); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 365 | } |
| 366 | return ret; |
| 367 | } |
| 368 | |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 369 | // pthread_mutex_timedlock |
| 370 | PTH_FUNC(int, pthreadZumutexZutimedlock, // pthread_mutex_timedlock |
| 371 | pthread_mutex_t *mutex, |
| 372 | const struct timespec *abs_timeout) |
| 373 | { |
| 374 | int ret; |
| 375 | int res; |
| 376 | OrigFn fn; |
| 377 | VALGRIND_GET_ORIG_FN(fn); |
| 378 | CALL_FN_W_WW(ret, fn, mutex, abs_timeout); |
| 379 | if (ret == 0) |
| 380 | { |
| 381 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_PTHREAD_MUTEX_LOCK, |
bart | 5357fcb | 2008-02-27 15:46:00 +0000 | [diff] [blame] | 382 | mutex, sizeof(*mutex), mutex_type(mutex), 0, 0); |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 383 | } |
| 384 | return ret; |
| 385 | } |
| 386 | |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 387 | // pthread_mutex_unlock |
| 388 | PTH_FUNC(int, pthreadZumutexZuunlock, // pthread_mutex_unlock |
| 389 | pthread_mutex_t *mutex) |
| 390 | { |
| 391 | int ret; |
| 392 | int res; |
| 393 | OrigFn fn; |
| 394 | VALGRIND_GET_ORIG_FN(fn); |
| 395 | VALGRIND_DO_CLIENT_REQUEST(res, -1, |
| 396 | VG_USERREQ__PRE_PTHREAD_MUTEX_UNLOCK, |
bart | 5357fcb | 2008-02-27 15:46:00 +0000 | [diff] [blame] | 397 | mutex, sizeof(*mutex), mutex_type(mutex), 0, 0); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 398 | CALL_FN_W_W(ret, fn, mutex); |
| 399 | return ret; |
| 400 | } |
| 401 | |
| 402 | // pthread_cond_init |
sewardj | 347eeba | 2008-01-21 14:19:07 +0000 | [diff] [blame] | 403 | PTH_FUNC(int, pthreadZucondZuinitZa, // pthread_cond_init* |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 404 | pthread_cond_t* cond, |
| 405 | const pthread_condattr_t* attr) |
| 406 | { |
| 407 | int ret; |
| 408 | int res; |
| 409 | OrigFn fn; |
| 410 | VALGRIND_GET_ORIG_FN(fn); |
| 411 | CALL_FN_W_WW(ret, fn, cond, attr); |
| 412 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_PTHREAD_COND_INIT, |
| 413 | cond, sizeof(*cond), 0, 0, 0); |
| 414 | return ret; |
| 415 | } |
| 416 | |
| 417 | // pthread_cond_destroy |
sewardj | 347eeba | 2008-01-21 14:19:07 +0000 | [diff] [blame] | 418 | PTH_FUNC(int, pthreadZucondZudestroyZa, // pthread_cond_destroy* |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 419 | pthread_cond_t* cond) |
| 420 | { |
| 421 | int ret; |
| 422 | int res; |
| 423 | OrigFn fn; |
| 424 | VALGRIND_GET_ORIG_FN(fn); |
| 425 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_PTHREAD_COND_DESTROY, |
sewardj | 721ad7b | 2007-11-30 08:30:29 +0000 | [diff] [blame] | 426 | cond, 0, 0, 0, 0); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 427 | CALL_FN_W_W(ret, fn, cond); |
| 428 | return ret; |
| 429 | } |
| 430 | |
| 431 | // pthread_cond_wait |
sewardj | 347eeba | 2008-01-21 14:19:07 +0000 | [diff] [blame] | 432 | PTH_FUNC(int, pthreadZucondZuwaitZa, // pthread_cond_wait* |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 433 | pthread_cond_t *cond, |
| 434 | pthread_mutex_t *mutex) |
| 435 | { |
| 436 | int ret; |
| 437 | int res; |
| 438 | OrigFn fn; |
| 439 | VALGRIND_GET_ORIG_FN(fn); |
| 440 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_PTHREAD_COND_WAIT, |
bart | 5357fcb | 2008-02-27 15:46:00 +0000 | [diff] [blame] | 441 | cond, sizeof(*cond), mutex, mutex_type(mutex), 0); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 442 | CALL_FN_W_WW(ret, fn, cond, mutex); |
| 443 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_PTHREAD_COND_WAIT, |
bart | 5357fcb | 2008-02-27 15:46:00 +0000 | [diff] [blame] | 444 | cond, mutex, sizeof(*mutex), mutex_type(mutex), 0); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 445 | return ret; |
| 446 | } |
| 447 | |
| 448 | // pthread_cond_timedwait |
sewardj | 347eeba | 2008-01-21 14:19:07 +0000 | [diff] [blame] | 449 | PTH_FUNC(int, pthreadZucondZutimedwaitZa, // pthread_cond_timedwait* |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 450 | pthread_cond_t *cond, |
| 451 | pthread_mutex_t *mutex, |
| 452 | const struct timespec* abstime) |
| 453 | { |
| 454 | int ret; |
| 455 | int res; |
| 456 | OrigFn fn; |
| 457 | VALGRIND_GET_ORIG_FN(fn); |
| 458 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_PTHREAD_COND_WAIT, |
bart | 5357fcb | 2008-02-27 15:46:00 +0000 | [diff] [blame] | 459 | cond, sizeof(*cond), mutex, mutex_type(mutex), 0); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 460 | CALL_FN_W_WWW(ret, fn, cond, mutex, abstime); |
| 461 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_PTHREAD_COND_WAIT, |
bart | 5357fcb | 2008-02-27 15:46:00 +0000 | [diff] [blame] | 462 | cond, mutex, sizeof(*mutex), mutex_type(mutex), 0); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 463 | return ret; |
| 464 | } |
| 465 | |
| 466 | // pthread_cond_signal |
sewardj | 347eeba | 2008-01-21 14:19:07 +0000 | [diff] [blame] | 467 | PTH_FUNC(int, pthreadZucondZusignalZa, // pthread_cond_signal* |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 468 | pthread_cond_t* cond) |
| 469 | { |
| 470 | int ret; |
| 471 | int res; |
| 472 | OrigFn fn; |
| 473 | VALGRIND_GET_ORIG_FN(fn); |
| 474 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_PTHREAD_COND_SIGNAL, |
| 475 | cond, 0, 0, 0, 0); |
| 476 | CALL_FN_W_W(ret, fn, cond); |
| 477 | return ret; |
| 478 | } |
| 479 | |
| 480 | // pthread_cond_broadcast |
sewardj | 347eeba | 2008-01-21 14:19:07 +0000 | [diff] [blame] | 481 | PTH_FUNC(int, pthreadZucondZubroadcastZa, // pthread_cond_broadcast* |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 482 | pthread_cond_t* cond) |
| 483 | { |
| 484 | int ret; |
| 485 | int res; |
| 486 | OrigFn fn; |
| 487 | VALGRIND_GET_ORIG_FN(fn); |
| 488 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_PTHREAD_COND_BROADCAST, |
| 489 | cond, 0, 0, 0, 0); |
| 490 | CALL_FN_W_W(ret, fn, cond); |
| 491 | return ret; |
| 492 | } |
| 493 | |
| 494 | |
| 495 | // pthread_spin_init |
| 496 | PTH_FUNC(int, pthreadZuspinZuinit, // pthread_spin_init |
| 497 | pthread_spinlock_t *spinlock, |
| 498 | int pshared) |
| 499 | { |
| 500 | int ret; |
| 501 | int res; |
| 502 | OrigFn fn; |
| 503 | VALGRIND_GET_ORIG_FN(fn); |
| 504 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__SPIN_INIT_OR_UNLOCK, |
sewardj | 721ad7b | 2007-11-30 08:30:29 +0000 | [diff] [blame] | 505 | spinlock, sizeof(*spinlock), |
| 506 | mutex_type_spinlock, 0, 0); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 507 | CALL_FN_W_WW(ret, fn, spinlock, pshared); |
| 508 | return ret; |
| 509 | } |
| 510 | |
| 511 | // pthread_spin_destroy |
| 512 | PTH_FUNC(int, pthreadZuspinZudestroy, // pthread_spin_destroy |
| 513 | pthread_spinlock_t *spinlock) |
| 514 | { |
| 515 | int ret; |
| 516 | int res; |
| 517 | OrigFn fn; |
| 518 | VALGRIND_GET_ORIG_FN(fn); |
| 519 | CALL_FN_W_W(ret, fn, spinlock); |
| 520 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_MUTEX_DESTROY, |
sewardj | 721ad7b | 2007-11-30 08:30:29 +0000 | [diff] [blame] | 521 | spinlock, mutex_type_spinlock, 0, 0, 0); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 522 | return ret; |
| 523 | } |
| 524 | |
| 525 | // pthread_spin_lock |
| 526 | PTH_FUNC(int, pthreadZuspinZulock, // pthread_spin_lock |
| 527 | pthread_spinlock_t *spinlock) |
| 528 | { |
| 529 | int ret; |
| 530 | int res; |
| 531 | OrigFn fn; |
| 532 | VALGRIND_GET_ORIG_FN(fn); |
| 533 | CALL_FN_W_W(ret, fn, spinlock); |
| 534 | if (ret == 0) |
| 535 | { |
| 536 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_PTHREAD_MUTEX_LOCK, |
sewardj | 721ad7b | 2007-11-30 08:30:29 +0000 | [diff] [blame] | 537 | spinlock, sizeof(*spinlock), |
| 538 | mutex_type_spinlock, 0, 0); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 539 | } |
| 540 | return ret; |
| 541 | } |
| 542 | |
| 543 | // pthread_spin_trylock |
| 544 | PTH_FUNC(int, pthreadZuspinZutrylock, // pthread_spin_trylock |
| 545 | pthread_spinlock_t *spinlock) |
| 546 | { |
| 547 | int ret; |
| 548 | int res; |
| 549 | OrigFn fn; |
| 550 | VALGRIND_GET_ORIG_FN(fn); |
| 551 | CALL_FN_W_W(ret, fn, spinlock); |
| 552 | if (ret == 0) |
| 553 | { |
| 554 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_PTHREAD_MUTEX_LOCK, |
sewardj | 721ad7b | 2007-11-30 08:30:29 +0000 | [diff] [blame] | 555 | spinlock, sizeof(*spinlock), |
| 556 | mutex_type_spinlock, 0, 0); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 557 | } |
| 558 | return ret; |
| 559 | } |
| 560 | |
| 561 | // pthread_spin_unlock |
| 562 | PTH_FUNC(int, pthreadZuspinZuunlock, // pthread_spin_unlock |
| 563 | pthread_spinlock_t *spinlock) |
| 564 | { |
| 565 | int ret; |
| 566 | int res; |
| 567 | OrigFn fn; |
| 568 | VALGRIND_GET_ORIG_FN(fn); |
| 569 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__SPIN_INIT_OR_UNLOCK, |
sewardj | 721ad7b | 2007-11-30 08:30:29 +0000 | [diff] [blame] | 570 | spinlock, sizeof(*spinlock), |
| 571 | mutex_type_spinlock, 0, 0); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 572 | CALL_FN_W_W(ret, fn, spinlock); |
| 573 | return ret; |
| 574 | } |
| 575 | |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 576 | // pthread_barrier_init |
| 577 | PTH_FUNC(int, pthreadZubarrierZuinit, // pthread_barrier_init |
| 578 | pthread_barrier_t* barrier, |
| 579 | const pthread_barrierattr_t* attr, |
| 580 | unsigned count) |
| 581 | { |
| 582 | int ret; |
| 583 | int res; |
| 584 | OrigFn fn; |
| 585 | VALGRIND_GET_ORIG_FN(fn); |
| 586 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__BARRIER_INIT, |
| 587 | barrier, sizeof(*barrier), |
| 588 | count, 0, 0); |
| 589 | CALL_FN_W_WWW(ret, fn, barrier, attr, count); |
| 590 | return ret; |
| 591 | } |
| 592 | |
| 593 | // pthread_barrier_destroy |
| 594 | PTH_FUNC(int, pthreadZubarrierZudestroy, // pthread_barrier_destroy |
| 595 | pthread_barrier_t* barrier) |
| 596 | { |
| 597 | int ret; |
| 598 | int res; |
| 599 | OrigFn fn; |
| 600 | VALGRIND_GET_ORIG_FN(fn); |
| 601 | CALL_FN_W_W(ret, fn, barrier); |
| 602 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__BARRIER_DESTROY, |
| 603 | barrier, 0, 0, 0, 0); |
| 604 | return ret; |
| 605 | } |
| 606 | |
| 607 | // pthread_barrier_wait |
| 608 | PTH_FUNC(int, pthreadZubarrierZuwait, // pthread_barrier_wait |
| 609 | pthread_barrier_t* barrier) |
| 610 | { |
| 611 | int ret; |
| 612 | int res; |
| 613 | OrigFn fn; |
| 614 | VALGRIND_GET_ORIG_FN(fn); |
| 615 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_BARRIER_WAIT, |
| 616 | barrier, 0, 0, 0, 0); |
| 617 | CALL_FN_W_W(ret, fn, barrier); |
| 618 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_BARRIER_WAIT, |
| 619 | barrier, |
| 620 | ret == 0 || ret == PTHREAD_BARRIER_SERIAL_THREAD, |
| 621 | 0, 0, 0); |
| 622 | return ret; |
| 623 | } |
| 624 | |
| 625 | |
| 626 | // From glibc 2.0 linuxthreads/sysdeps/pthread/cmpxchg/semaphorebits.h |
| 627 | typedef struct { long int sem_status; } sem_t_glibc_2_0; |
| 628 | |
| 629 | // sem_init |
| 630 | PTH_FUNC(int, sem_initZAGLIBCZu2Zd0, // sem_init@GLIBC_2.0 |
| 631 | sem_t_glibc_2_0 *sem, |
| 632 | int pshared, |
| 633 | unsigned int value) |
| 634 | { |
| 635 | int ret; |
| 636 | int res; |
| 637 | OrigFn fn; |
| 638 | VALGRIND_GET_ORIG_FN(fn); |
| 639 | CALL_FN_W_WWW(ret, fn, sem, pshared, value); |
| 640 | if (ret == 0) |
| 641 | { |
| 642 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__SEM_INIT, |
| 643 | sem, sizeof(*sem), |
| 644 | pshared, value, 0); |
| 645 | } |
| 646 | return ret; |
| 647 | } |
| 648 | |
| 649 | PTH_FUNC(int, sem_initZa, // sem_init* |
| 650 | sem_t *sem, |
| 651 | int pshared, |
| 652 | unsigned int value) |
| 653 | { |
| 654 | int ret; |
| 655 | int res; |
| 656 | OrigFn fn; |
| 657 | VALGRIND_GET_ORIG_FN(fn); |
| 658 | CALL_FN_W_WWW(ret, fn, sem, pshared, value); |
| 659 | if (ret == 0) |
| 660 | { |
| 661 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__SEM_INIT, |
| 662 | sem, sizeof(*sem), |
| 663 | pshared, value, 0); |
| 664 | } |
| 665 | return ret; |
| 666 | } |
| 667 | |
| 668 | // sem_destroy |
| 669 | PTH_FUNC(int, sem_destroyZAGLIBCZu2Zd0, // sem_destroy@GLIBC_2.0 |
| 670 | sem_t_glibc_2_0 *sem) |
| 671 | { |
| 672 | int ret; |
| 673 | int res; |
| 674 | OrigFn fn; |
| 675 | VALGRIND_GET_ORIG_FN(fn); |
| 676 | CALL_FN_W_W(ret, fn, sem); |
| 677 | if (ret == 0) |
| 678 | { |
| 679 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__SEM_DESTROY, |
| 680 | sem, 0, 0, 0, 0); |
| 681 | } |
| 682 | return ret; |
| 683 | } |
| 684 | |
| 685 | PTH_FUNC(int, sem_destroyZa, // sem_destroy* |
| 686 | sem_t *sem) |
| 687 | { |
| 688 | int ret; |
| 689 | int res; |
| 690 | OrigFn fn; |
| 691 | VALGRIND_GET_ORIG_FN(fn); |
| 692 | CALL_FN_W_W(ret, fn, sem); |
| 693 | if (ret == 0) |
| 694 | { |
| 695 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__SEM_DESTROY, |
| 696 | sem, 0, 0, 0, 0); |
| 697 | } |
| 698 | return ret; |
| 699 | } |
| 700 | |
| 701 | // sem_wait |
| 702 | PTH_FUNC(int, sem_waitZAGLIBCZu2Zd0, // sem_wait@GLIBC_2.0 |
| 703 | sem_t_glibc_2_0 *sem) |
| 704 | { |
| 705 | int ret; |
| 706 | int res; |
| 707 | OrigFn fn; |
| 708 | VALGRIND_GET_ORIG_FN(fn); |
| 709 | CALL_FN_W_W(ret, fn, sem); |
| 710 | if (ret == 0) |
| 711 | { |
| 712 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_SEM_WAIT, |
| 713 | sem, sizeof(*sem), 0, 0, 0); |
| 714 | } |
| 715 | return ret; |
| 716 | } |
| 717 | |
| 718 | PTH_FUNC(int, sem_waitZa, // sem_wait* |
| 719 | sem_t *sem) |
| 720 | { |
| 721 | int ret; |
| 722 | int res; |
| 723 | OrigFn fn; |
| 724 | VALGRIND_GET_ORIG_FN(fn); |
| 725 | CALL_FN_W_W(ret, fn, sem); |
| 726 | if (ret == 0) |
| 727 | { |
| 728 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_SEM_WAIT, |
| 729 | sem, sizeof(*sem), 0, 0, 0); |
| 730 | } |
| 731 | return ret; |
| 732 | } |
| 733 | |
| 734 | // sem_trywait |
| 735 | PTH_FUNC(int, sem_trywaitZAGLIBCZu2Zd0, // sem_trywait@GLIBC_2.0 |
| 736 | sem_t_glibc_2_0 *sem) |
| 737 | { |
| 738 | int ret; |
| 739 | int res; |
| 740 | OrigFn fn; |
| 741 | VALGRIND_GET_ORIG_FN(fn); |
| 742 | CALL_FN_W_W(ret, fn, sem); |
| 743 | if (ret == 0) |
| 744 | { |
| 745 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_SEM_WAIT, |
| 746 | sem, sizeof(*sem), 0, 0, 0); |
| 747 | } |
| 748 | return ret; |
| 749 | } |
| 750 | |
| 751 | PTH_FUNC(int, sem_trywaitZa, // sem_trywait* |
| 752 | sem_t *sem) |
| 753 | { |
| 754 | int ret; |
| 755 | int res; |
| 756 | OrigFn fn; |
| 757 | VALGRIND_GET_ORIG_FN(fn); |
| 758 | CALL_FN_W_W(ret, fn, sem); |
| 759 | if (ret == 0) |
| 760 | { |
| 761 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_SEM_WAIT, |
| 762 | sem, sizeof(*sem), 0, 0, 0); |
| 763 | } |
| 764 | return ret; |
| 765 | } |
| 766 | |
| 767 | // sem_timedwait |
| 768 | PTH_FUNC(int, sem_timedwait, // sem_timedwait |
| 769 | sem_t *sem, const struct timespec *abs_timeout) |
| 770 | { |
| 771 | int ret; |
| 772 | int res; |
| 773 | OrigFn fn; |
| 774 | VALGRIND_GET_ORIG_FN(fn); |
| 775 | CALL_FN_W_WW(ret, fn, sem, abs_timeout); |
| 776 | if (ret == 0) |
| 777 | { |
| 778 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_SEM_WAIT, |
| 779 | sem, sizeof(*sem), 0, 0, 0); |
| 780 | } |
| 781 | return ret; |
| 782 | } |
| 783 | |
| 784 | // sem_post |
| 785 | PTH_FUNC(int, sem_postZAGLIBCZu2Zd0, // sem_post@GLIBC_2.0 |
| 786 | sem_t_glibc_2_0 *sem) |
| 787 | { |
| 788 | int ret; |
| 789 | int res; |
| 790 | OrigFn fn; |
| 791 | VALGRIND_GET_ORIG_FN(fn); |
| 792 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_SEM_POST, |
| 793 | sem, sizeof(*sem), 0, 0, 0); |
| 794 | CALL_FN_W_W(ret, fn, sem); |
sewardj | c0be925 | 2008-02-11 11:00:51 +0000 | [diff] [blame] | 795 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_SEM_POST, |
| 796 | sem, sizeof(*sem), ret == 0, 0, 0); |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 797 | return ret; |
| 798 | } |
| 799 | |
| 800 | PTH_FUNC(int, sem_postZa, // sem_post* |
| 801 | sem_t *sem) |
| 802 | { |
| 803 | int ret; |
| 804 | int res; |
| 805 | OrigFn fn; |
| 806 | VALGRIND_GET_ORIG_FN(fn); |
| 807 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_SEM_POST, |
| 808 | sem, sizeof(*sem), 0, 0, 0); |
| 809 | CALL_FN_W_W(ret, fn, sem); |
sewardj | e3b57aa | 2008-01-18 07:42:01 +0000 | [diff] [blame] | 810 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_SEM_POST, |
| 811 | sem, sizeof(*sem), ret == 0, 0, 0); |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 812 | return ret; |
| 813 | } |
| 814 | |
| 815 | /* |
| 816 | pthread_rwlock_destroy |
| 817 | pthread_rwlock_init |
| 818 | pthread_rwlock_rdlock |
| 819 | pthread_rwlock_timedrdlock |
| 820 | pthread_rwlock_timedwrlock |
| 821 | pthread_rwlock_tryrdlock |
| 822 | pthread_rwlock_trywrlock |
| 823 | pthread_rwlock_unlock |
| 824 | pthread_rwlock_wrlock |
| 825 | pthread_rwlockattr_destroy |
| 826 | pthread_rwlockattr_getkind_np |
| 827 | pthread_rwlockattr_getpshared |
| 828 | pthread_rwlockattr_init |
| 829 | pthread_rwlockattr_setkind_np |
| 830 | pthread_rwlockattr_setpshared |
| 831 | */ |
| 832 | |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 833 | /* |
| 834 | * Local variables: |
| 835 | * c-basic-offset: 3 |
| 836 | * End: |
| 837 | */ |