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 | |
bart | 5e85d26 | 2008-03-01 10:49:37 +0000 | [diff] [blame] | 43 | // Make sure pthread_spinlock_t is available when compiling with older glibc |
| 44 | // versions (2.3 or before). |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 45 | #ifndef _GNU_SOURCE |
| 46 | #define _GNU_SOURCE |
| 47 | #endif |
| 48 | |
| 49 | #include <assert.h> |
| 50 | #include <inttypes.h> // uintptr_t |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 51 | #include <pthread.h> |
| 52 | #include <semaphore.h> |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 53 | #include <stdio.h> |
bart | 0d06300 | 2008-03-01 07:25:13 +0000 | [diff] [blame] | 54 | #include <stdlib.h> |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 55 | #include <unistd.h> |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 56 | #include "drd_clientreq.h" |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 57 | #include "pub_tool_redir.h" |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 58 | |
| 59 | |
| 60 | // Defines. |
| 61 | |
| 62 | #define PTH_FUNC(ret_ty, f, args...) \ |
| 63 | ret_ty VG_WRAP_FUNCTION_ZZ(libpthreadZdsoZd0,f)(args); \ |
| 64 | ret_ty VG_WRAP_FUNCTION_ZZ(libpthreadZdsoZd0,f)(args) |
| 65 | |
| 66 | |
| 67 | // Local data structures. |
| 68 | |
| 69 | typedef struct |
| 70 | { |
| 71 | void* (*start)(void*); |
| 72 | void* arg; |
| 73 | int detachstate; |
| 74 | #if 0 |
| 75 | pthread_mutex_t mutex; |
| 76 | pthread_cond_t cond; |
| 77 | #else |
| 78 | int wrapper_started; |
| 79 | #endif |
| 80 | } VgPosixThreadArgs; |
| 81 | |
| 82 | |
| 83 | // Local variables. |
| 84 | |
| 85 | static int vg_main_thread_state_is_set = 0; |
bart | 0d06300 | 2008-03-01 07:25:13 +0000 | [diff] [blame] | 86 | static pid_t vg_main_thread_pid; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 87 | |
| 88 | |
| 89 | // Function definitions. |
| 90 | |
bart | 5357fcb | 2008-02-27 15:46:00 +0000 | [diff] [blame] | 91 | static MutexT pthread_to_drd_mutex_type(const int kind) |
| 92 | { |
| 93 | switch (kind) |
| 94 | { |
| 95 | /* PTHREAD_MUTEX_RECURSIVE_NP */ |
| 96 | case PTHREAD_MUTEX_RECURSIVE: |
| 97 | return mutex_type_recursive_mutex; |
| 98 | /* PTHREAD_MUTEX_ERRORCHECK_NP */ |
| 99 | case PTHREAD_MUTEX_ERRORCHECK: |
| 100 | return mutex_type_errorcheck_mutex; |
| 101 | /* PTHREAD_MUTEX_TIMED_NP */ |
| 102 | /* PTHREAD_MUTEX_NORMAL */ |
| 103 | case PTHREAD_MUTEX_DEFAULT: |
| 104 | case PTHREAD_MUTEX_ADAPTIVE_NP: |
| 105 | return mutex_type_default_mutex; |
bart | 5357fcb | 2008-02-27 15:46:00 +0000 | [diff] [blame] | 106 | } |
bart | 635cb16 | 2008-02-28 08:30:43 +0000 | [diff] [blame] | 107 | return mutex_type_invalid_mutex; |
bart | 5357fcb | 2008-02-27 15:46:00 +0000 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | static MutexT mutex_type(pthread_mutex_t* mutex) |
| 111 | { |
bart | c9463c4 | 2008-02-28 07:36:04 +0000 | [diff] [blame] | 112 | #if defined(_PTHREAD_DESCR_DEFINED) |
| 113 | // Linuxthreads. |
| 114 | const int kind = mutex->__m_kind; |
| 115 | #elif defined(__SIZEOF_PTHREAD_MUTEX_T) |
| 116 | // NPTL. |
| 117 | const int kind = mutex->__data.__kind; |
| 118 | #else |
| 119 | // Another POSIX threads implementation. Regression tests will fail. |
| 120 | const int kind = PTHREAD_MUTEX_DEFAULT; |
| 121 | #endif |
| 122 | return pthread_to_drd_mutex_type(kind); |
bart | 5357fcb | 2008-02-27 15:46:00 +0000 | [diff] [blame] | 123 | } |
| 124 | |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 125 | static void vg_start_suppression(const void* const p, size_t const size) |
| 126 | { |
| 127 | int res; |
| 128 | VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__DRD_START_SUPPRESSION, |
bart | 5e85d26 | 2008-03-01 10:49:37 +0000 | [diff] [blame] | 129 | p, (char*)p + size, 0, 0, 0); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | static void vg_set_joinable(const pthread_t tid, const int joinable) |
| 133 | { |
| 134 | int res; |
| 135 | assert(joinable == 0 || joinable == 1); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 136 | VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__SET_JOINABLE, |
| 137 | tid, joinable, 0, 0, 0); |
| 138 | } |
| 139 | |
| 140 | static void* vg_thread_wrapper(void* arg) |
| 141 | { |
| 142 | int res; |
bart | 0d06300 | 2008-03-01 07:25:13 +0000 | [diff] [blame] | 143 | |
| 144 | if (getpid() != vg_main_thread_pid) |
| 145 | { |
bart | 777f7fe | 2008-03-02 17:43:18 +0000 | [diff] [blame] | 146 | if (getenv("LD_ASSUME_KERNEL")) |
| 147 | { |
| 148 | fprintf(stderr, |
| 149 | "Detected the LinuxThreads threading library. Sorry, but DRD only supports\n" |
| 150 | "the newer NPTL (Native POSIX Threads Library). Please try to rerun DRD\n" |
| 151 | "after having unset the environment variable LD_ASSUME_KERNEL. Giving up.\n" |
| 152 | ); |
| 153 | } |
| 154 | else |
| 155 | { |
| 156 | fprintf(stderr, |
| 157 | "Detected the LinuxThreads threading library. Sorry, but DRD only supports\n" |
| 158 | "the newer NPTL (Native POSIX Threads Library). Please try to rerun DRD\n" |
| 159 | "after having upgraded to a newer version of your Linux distribution.\n" |
| 160 | "Giving up.\n" |
| 161 | ); |
| 162 | } |
bart | 0d06300 | 2008-03-01 07:25:13 +0000 | [diff] [blame] | 163 | abort(); |
| 164 | } |
| 165 | |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 166 | VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__DRD_SUPPRESS_CURRENT_STACK, |
| 167 | 0, 0, 0, 0, 0); |
| 168 | |
| 169 | { |
| 170 | VgPosixThreadArgs* const arg_ptr = (VgPosixThreadArgs*)arg; |
| 171 | VgPosixThreadArgs const arg_copy = *arg_ptr; |
| 172 | void* result; |
| 173 | |
| 174 | #if 0 |
| 175 | pthread_mutex_lock(arg_ptr->mutex); |
| 176 | pthread_cond_signal(arg_ptr->cond); |
| 177 | pthread_mutex_unlock(arg_ptr->mutex); |
| 178 | #else |
| 179 | arg_ptr->wrapper_started = 1; |
| 180 | #endif |
| 181 | |
| 182 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__SET_PTHREADID, |
| 183 | pthread_self(), 0, 0, 0, 0); |
| 184 | vg_set_joinable(pthread_self(), |
| 185 | arg_copy.detachstate == PTHREAD_CREATE_JOINABLE); |
| 186 | result = (arg_copy.start)(arg_copy.arg); |
| 187 | return result; |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | static void vg_set_main_thread_state(void) |
| 192 | { |
| 193 | int res; |
| 194 | |
bart | 0d06300 | 2008-03-01 07:25:13 +0000 | [diff] [blame] | 195 | vg_main_thread_pid = getpid(); |
| 196 | |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 197 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__DRD_SUPPRESS_CURRENT_STACK, |
| 198 | 0, 0, 0, 0, 0); |
| 199 | |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 200 | // Make sure that DRD knows about the main thread's POSIX thread ID. |
| 201 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__SET_PTHREADID, |
| 202 | pthread_self(), 0, 0, 0, 0); |
| 203 | |
| 204 | } |
| 205 | |
| 206 | // pthread_create |
sewardj | 347eeba | 2008-01-21 14:19:07 +0000 | [diff] [blame] | 207 | PTH_FUNC(int, pthreadZucreateZa, // pthread_create* |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 208 | pthread_t *thread, const pthread_attr_t *attr, |
| 209 | void *(*start) (void *), void *arg) |
| 210 | { |
| 211 | int ret; |
| 212 | OrigFn fn; |
| 213 | VgPosixThreadArgs vgargs; |
| 214 | |
| 215 | VALGRIND_GET_ORIG_FN(fn); |
| 216 | |
| 217 | if (vg_main_thread_state_is_set == 0) |
| 218 | { |
| 219 | vg_set_main_thread_state(); |
| 220 | vg_main_thread_state_is_set = 1; |
| 221 | } |
| 222 | vg_start_suppression(&vgargs.wrapper_started, |
| 223 | sizeof(vgargs.wrapper_started)); |
| 224 | vgargs.start = start; |
| 225 | vgargs.arg = arg; |
| 226 | vgargs.wrapper_started = 0; |
| 227 | vgargs.detachstate = PTHREAD_CREATE_JOINABLE; |
| 228 | if (attr) |
| 229 | { |
| 230 | if (pthread_attr_getdetachstate(attr, &vgargs.detachstate) != 0) |
| 231 | { |
| 232 | assert(0); |
| 233 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 234 | } |
| 235 | assert(vgargs.detachstate == PTHREAD_CREATE_JOINABLE |
| 236 | || vgargs.detachstate == PTHREAD_CREATE_DETACHED); |
| 237 | #if 0 |
| 238 | pthread_mutex_init(&vgargs.mutex, 0); |
| 239 | pthread_cond_init(&vgargs.cond, 0); |
| 240 | pthread_mutex_lock(&vgargs.mutex); |
| 241 | #endif |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 242 | CALL_FN_W_WWWW(ret, fn, thread, attr, vg_thread_wrapper, &vgargs); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 243 | #if 0 |
| 244 | pthread_cond_wait(&vgargs.cond, &vgargs.mutex); |
| 245 | pthread_mutex_unlock(&vgargs.mutex); |
| 246 | pthread_cond_destroy(&vgargs.cond); |
| 247 | pthread_mutex_destroy(&vgargs.mutex); |
| 248 | #else |
| 249 | // Yes, you see it correctly, busy waiting ... The problem is that |
| 250 | // POSIX threads functions cannot be called here -- the functions defined |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 251 | // in this file (drd_intercepts.c) would be called instead of those in |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 252 | // libpthread.so. This loop is necessary because vgargs is allocated on the |
| 253 | // stack, and the created thread reads it. |
sewardj | e0744f0 | 2007-12-01 02:09:50 +0000 | [diff] [blame] | 254 | if (ret == 0) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 255 | { |
sewardj | e0744f0 | 2007-12-01 02:09:50 +0000 | [diff] [blame] | 256 | while (! vgargs.wrapper_started) |
| 257 | { |
| 258 | sched_yield(); |
| 259 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 260 | } |
| 261 | #endif |
| 262 | return ret; |
| 263 | } |
| 264 | |
| 265 | // pthread_join |
| 266 | PTH_FUNC(int, pthreadZujoin, // pthread_join |
| 267 | pthread_t pt_joinee, void **thread_return) |
| 268 | { |
| 269 | int ret; |
| 270 | int res; |
| 271 | OrigFn fn; |
| 272 | |
| 273 | VALGRIND_GET_ORIG_FN(fn); |
| 274 | CALL_FN_W_WW(ret, fn, pt_joinee, thread_return); |
| 275 | if (ret == 0) |
| 276 | { |
| 277 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_THREAD_JOIN, |
| 278 | pt_joinee, 0, 0, 0, 0); |
| 279 | } |
| 280 | return ret; |
| 281 | } |
| 282 | |
| 283 | // pthread_detach |
| 284 | PTH_FUNC(int, pthreadZudetach, pthread_t pt_thread) |
| 285 | { |
| 286 | int ret; |
| 287 | OrigFn fn; |
| 288 | VALGRIND_GET_ORIG_FN(fn); |
| 289 | { |
| 290 | CALL_FN_W_W(ret, fn, pt_thread); |
| 291 | if (ret == 0) |
| 292 | { |
| 293 | vg_set_joinable(pt_thread, 0); |
| 294 | } |
| 295 | } |
| 296 | return ret; |
| 297 | } |
| 298 | |
| 299 | // pthread_mutex_init |
| 300 | PTH_FUNC(int, pthreadZumutexZuinit, |
| 301 | pthread_mutex_t *mutex, |
| 302 | const pthread_mutexattr_t* attr) |
| 303 | { |
| 304 | int ret; |
| 305 | int res; |
| 306 | OrigFn fn; |
bart | 5357fcb | 2008-02-27 15:46:00 +0000 | [diff] [blame] | 307 | int mt = PTHREAD_MUTEX_DEFAULT; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 308 | VALGRIND_GET_ORIG_FN(fn); |
bart | 5357fcb | 2008-02-27 15:46:00 +0000 | [diff] [blame] | 309 | if (attr) |
| 310 | pthread_mutexattr_gettype(attr, &mt); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 311 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_MUTEX_INIT, |
bart | 5357fcb | 2008-02-27 15:46:00 +0000 | [diff] [blame] | 312 | mutex, sizeof(*mutex), |
| 313 | pthread_to_drd_mutex_type(mt), 0, 0); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 314 | CALL_FN_W_WW(ret, fn, mutex, attr); |
| 315 | return ret; |
| 316 | } |
| 317 | |
| 318 | // pthread_mutex_destroy |
| 319 | PTH_FUNC(int, pthreadZumutexZudestroy, |
| 320 | pthread_mutex_t *mutex) |
| 321 | { |
| 322 | int ret; |
| 323 | int res; |
| 324 | OrigFn fn; |
| 325 | VALGRIND_GET_ORIG_FN(fn); |
| 326 | CALL_FN_W_W(ret, fn, mutex); |
| 327 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_MUTEX_DESTROY, |
bart | 5357fcb | 2008-02-27 15:46:00 +0000 | [diff] [blame] | 328 | mutex, mutex_type(mutex), 0, 0, 0); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 329 | return ret; |
| 330 | } |
| 331 | |
| 332 | // pthread_mutex_lock |
| 333 | PTH_FUNC(int, pthreadZumutexZulock, // pthread_mutex_lock |
| 334 | pthread_mutex_t *mutex) |
| 335 | { |
| 336 | int ret; |
| 337 | int res; |
| 338 | OrigFn fn; |
| 339 | VALGRIND_GET_ORIG_FN(fn); |
| 340 | VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__PRE_PTHREAD_MUTEX_LOCK, |
bart | 5357fcb | 2008-02-27 15:46:00 +0000 | [diff] [blame] | 341 | mutex, sizeof(*mutex), mutex_type(mutex), 0, 0); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 342 | CALL_FN_W_W(ret, fn, mutex); |
bart | 3b1ee45 | 2008-02-29 19:28:15 +0000 | [diff] [blame] | 343 | VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__POST_PTHREAD_MUTEX_LOCK, |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 344 | mutex, ret == 0, 0, 0, 0); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 345 | return ret; |
| 346 | } |
| 347 | |
| 348 | // pthread_mutex_trylock |
| 349 | PTH_FUNC(int, pthreadZumutexZutrylock, // pthread_mutex_trylock |
| 350 | pthread_mutex_t *mutex) |
| 351 | { |
| 352 | int ret; |
| 353 | int res; |
| 354 | OrigFn fn; |
| 355 | VALGRIND_GET_ORIG_FN(fn); |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 356 | VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__PRE_PTHREAD_MUTEX_LOCK, |
| 357 | mutex, sizeof(*mutex), mutex_type(mutex), 0, 0); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 358 | CALL_FN_W_W(ret, fn, mutex); |
bart | 3b1ee45 | 2008-02-29 19:28:15 +0000 | [diff] [blame] | 359 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_PTHREAD_MUTEX_LOCK, |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 360 | mutex, ret == 0, 0, 0, 0); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 361 | return ret; |
| 362 | } |
| 363 | |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 364 | // pthread_mutex_timedlock |
| 365 | PTH_FUNC(int, pthreadZumutexZutimedlock, // pthread_mutex_timedlock |
| 366 | pthread_mutex_t *mutex, |
| 367 | const struct timespec *abs_timeout) |
| 368 | { |
| 369 | int ret; |
| 370 | int res; |
| 371 | OrigFn fn; |
| 372 | VALGRIND_GET_ORIG_FN(fn); |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 373 | VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__PRE_PTHREAD_MUTEX_LOCK, |
| 374 | mutex, sizeof(*mutex), mutex_type(mutex), 0, 0); |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 375 | CALL_FN_W_WW(ret, fn, mutex, abs_timeout); |
bart | 3b1ee45 | 2008-02-29 19:28:15 +0000 | [diff] [blame] | 376 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_PTHREAD_MUTEX_LOCK, |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 377 | mutex, ret == 0, 0, 0, 0); |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 378 | return ret; |
| 379 | } |
| 380 | |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 381 | // pthread_mutex_unlock |
| 382 | PTH_FUNC(int, pthreadZumutexZuunlock, // pthread_mutex_unlock |
| 383 | pthread_mutex_t *mutex) |
| 384 | { |
| 385 | int ret; |
| 386 | int res; |
| 387 | OrigFn fn; |
| 388 | VALGRIND_GET_ORIG_FN(fn); |
| 389 | VALGRIND_DO_CLIENT_REQUEST(res, -1, |
| 390 | VG_USERREQ__PRE_PTHREAD_MUTEX_UNLOCK, |
bart | 5357fcb | 2008-02-27 15:46:00 +0000 | [diff] [blame] | 391 | mutex, sizeof(*mutex), mutex_type(mutex), 0, 0); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 392 | CALL_FN_W_W(ret, fn, mutex); |
| 393 | return ret; |
| 394 | } |
| 395 | |
| 396 | // pthread_cond_init |
sewardj | 347eeba | 2008-01-21 14:19:07 +0000 | [diff] [blame] | 397 | PTH_FUNC(int, pthreadZucondZuinitZa, // pthread_cond_init* |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 398 | pthread_cond_t* cond, |
| 399 | const pthread_condattr_t* attr) |
| 400 | { |
| 401 | int ret; |
| 402 | int res; |
| 403 | OrigFn fn; |
| 404 | VALGRIND_GET_ORIG_FN(fn); |
bart | 72b751c | 2008-03-01 13:44:24 +0000 | [diff] [blame] | 405 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_PTHREAD_COND_INIT, |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 406 | cond, sizeof(*cond), 0, 0, 0); |
bart | 72b751c | 2008-03-01 13:44:24 +0000 | [diff] [blame] | 407 | CALL_FN_W_WW(ret, fn, cond, attr); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 408 | return ret; |
| 409 | } |
| 410 | |
| 411 | // pthread_cond_destroy |
sewardj | 347eeba | 2008-01-21 14:19:07 +0000 | [diff] [blame] | 412 | PTH_FUNC(int, pthreadZucondZudestroyZa, // pthread_cond_destroy* |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 413 | pthread_cond_t* cond) |
| 414 | { |
| 415 | int ret; |
| 416 | int res; |
| 417 | OrigFn fn; |
| 418 | VALGRIND_GET_ORIG_FN(fn); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 419 | CALL_FN_W_W(ret, fn, cond); |
bart | 72b751c | 2008-03-01 13:44:24 +0000 | [diff] [blame] | 420 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_PTHREAD_COND_DESTROY, |
| 421 | cond, 0, 0, 0, 0); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 422 | return ret; |
| 423 | } |
| 424 | |
| 425 | // pthread_cond_wait |
sewardj | 347eeba | 2008-01-21 14:19:07 +0000 | [diff] [blame] | 426 | PTH_FUNC(int, pthreadZucondZuwaitZa, // pthread_cond_wait* |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 427 | pthread_cond_t *cond, |
| 428 | pthread_mutex_t *mutex) |
| 429 | { |
| 430 | int ret; |
| 431 | int res; |
| 432 | OrigFn fn; |
| 433 | VALGRIND_GET_ORIG_FN(fn); |
| 434 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_PTHREAD_COND_WAIT, |
bart | 3b1ee45 | 2008-02-29 19:28:15 +0000 | [diff] [blame] | 435 | cond, sizeof(*cond), mutex, mutex_type(mutex), |
| 436 | 0); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 437 | CALL_FN_W_WW(ret, fn, cond, mutex); |
| 438 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_PTHREAD_COND_WAIT, |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 439 | cond, mutex, ret == 0, 0, 0); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 440 | return ret; |
| 441 | } |
| 442 | |
| 443 | // pthread_cond_timedwait |
sewardj | 347eeba | 2008-01-21 14:19:07 +0000 | [diff] [blame] | 444 | PTH_FUNC(int, pthreadZucondZutimedwaitZa, // pthread_cond_timedwait* |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 445 | pthread_cond_t *cond, |
| 446 | pthread_mutex_t *mutex, |
| 447 | const struct timespec* abstime) |
| 448 | { |
| 449 | int ret; |
| 450 | int res; |
| 451 | OrigFn fn; |
| 452 | VALGRIND_GET_ORIG_FN(fn); |
| 453 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_PTHREAD_COND_WAIT, |
bart | 3b1ee45 | 2008-02-29 19:28:15 +0000 | [diff] [blame] | 454 | cond, sizeof(*cond), mutex, mutex_type(mutex), |
| 455 | 0); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 456 | CALL_FN_W_WWW(ret, fn, cond, mutex, abstime); |
| 457 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_PTHREAD_COND_WAIT, |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 458 | cond, mutex, ret == 0, 0, 0); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 459 | return ret; |
| 460 | } |
| 461 | |
| 462 | // pthread_cond_signal |
sewardj | 347eeba | 2008-01-21 14:19:07 +0000 | [diff] [blame] | 463 | PTH_FUNC(int, pthreadZucondZusignalZa, // pthread_cond_signal* |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 464 | pthread_cond_t* cond) |
| 465 | { |
| 466 | int ret; |
| 467 | int res; |
| 468 | OrigFn fn; |
| 469 | VALGRIND_GET_ORIG_FN(fn); |
| 470 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_PTHREAD_COND_SIGNAL, |
| 471 | cond, 0, 0, 0, 0); |
| 472 | CALL_FN_W_W(ret, fn, cond); |
| 473 | return ret; |
| 474 | } |
| 475 | |
| 476 | // pthread_cond_broadcast |
sewardj | 347eeba | 2008-01-21 14:19:07 +0000 | [diff] [blame] | 477 | PTH_FUNC(int, pthreadZucondZubroadcastZa, // pthread_cond_broadcast* |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 478 | pthread_cond_t* cond) |
| 479 | { |
| 480 | int ret; |
| 481 | int res; |
| 482 | OrigFn fn; |
| 483 | VALGRIND_GET_ORIG_FN(fn); |
| 484 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_PTHREAD_COND_BROADCAST, |
| 485 | cond, 0, 0, 0, 0); |
| 486 | CALL_FN_W_W(ret, fn, cond); |
| 487 | return ret; |
| 488 | } |
| 489 | |
| 490 | |
| 491 | // pthread_spin_init |
| 492 | PTH_FUNC(int, pthreadZuspinZuinit, // pthread_spin_init |
| 493 | pthread_spinlock_t *spinlock, |
| 494 | int pshared) |
| 495 | { |
| 496 | int ret; |
| 497 | int res; |
| 498 | OrigFn fn; |
| 499 | VALGRIND_GET_ORIG_FN(fn); |
| 500 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__SPIN_INIT_OR_UNLOCK, |
sewardj | 721ad7b | 2007-11-30 08:30:29 +0000 | [diff] [blame] | 501 | spinlock, sizeof(*spinlock), |
| 502 | mutex_type_spinlock, 0, 0); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 503 | CALL_FN_W_WW(ret, fn, spinlock, pshared); |
| 504 | return ret; |
| 505 | } |
| 506 | |
| 507 | // pthread_spin_destroy |
| 508 | PTH_FUNC(int, pthreadZuspinZudestroy, // pthread_spin_destroy |
| 509 | pthread_spinlock_t *spinlock) |
| 510 | { |
| 511 | int ret; |
| 512 | int res; |
| 513 | OrigFn fn; |
| 514 | VALGRIND_GET_ORIG_FN(fn); |
| 515 | CALL_FN_W_W(ret, fn, spinlock); |
| 516 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_MUTEX_DESTROY, |
sewardj | 721ad7b | 2007-11-30 08:30:29 +0000 | [diff] [blame] | 517 | spinlock, mutex_type_spinlock, 0, 0, 0); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 518 | return ret; |
| 519 | } |
| 520 | |
| 521 | // pthread_spin_lock |
| 522 | PTH_FUNC(int, pthreadZuspinZulock, // pthread_spin_lock |
| 523 | pthread_spinlock_t *spinlock) |
| 524 | { |
| 525 | int ret; |
| 526 | int res; |
| 527 | OrigFn fn; |
| 528 | VALGRIND_GET_ORIG_FN(fn); |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 529 | VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__PRE_PTHREAD_MUTEX_LOCK, |
| 530 | spinlock, sizeof(*spinlock), mutex_type_spinlock, |
| 531 | 0, 0); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 532 | CALL_FN_W_W(ret, fn, spinlock); |
bart | 3b1ee45 | 2008-02-29 19:28:15 +0000 | [diff] [blame] | 533 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_PTHREAD_MUTEX_LOCK, |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 534 | spinlock, ret == 0, 0, 0, 0); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 535 | return ret; |
| 536 | } |
| 537 | |
| 538 | // pthread_spin_trylock |
| 539 | PTH_FUNC(int, pthreadZuspinZutrylock, // pthread_spin_trylock |
| 540 | pthread_spinlock_t *spinlock) |
| 541 | { |
| 542 | int ret; |
| 543 | int res; |
| 544 | OrigFn fn; |
| 545 | VALGRIND_GET_ORIG_FN(fn); |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 546 | VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__PRE_PTHREAD_MUTEX_LOCK, |
| 547 | spinlock, sizeof(*spinlock), mutex_type_spinlock, |
| 548 | 0, 0); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 549 | CALL_FN_W_W(ret, fn, spinlock); |
bart | 3b1ee45 | 2008-02-29 19:28:15 +0000 | [diff] [blame] | 550 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_PTHREAD_MUTEX_LOCK, |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 551 | spinlock, ret == 0, 0, 0, 0); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 552 | return ret; |
| 553 | } |
| 554 | |
| 555 | // pthread_spin_unlock |
| 556 | PTH_FUNC(int, pthreadZuspinZuunlock, // pthread_spin_unlock |
| 557 | pthread_spinlock_t *spinlock) |
| 558 | { |
| 559 | int ret; |
| 560 | int res; |
| 561 | OrigFn fn; |
| 562 | VALGRIND_GET_ORIG_FN(fn); |
| 563 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__SPIN_INIT_OR_UNLOCK, |
sewardj | 721ad7b | 2007-11-30 08:30:29 +0000 | [diff] [blame] | 564 | spinlock, sizeof(*spinlock), |
| 565 | mutex_type_spinlock, 0, 0); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 566 | CALL_FN_W_W(ret, fn, spinlock); |
| 567 | return ret; |
| 568 | } |
| 569 | |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 570 | // pthread_barrier_init |
| 571 | PTH_FUNC(int, pthreadZubarrierZuinit, // pthread_barrier_init |
| 572 | pthread_barrier_t* barrier, |
| 573 | const pthread_barrierattr_t* attr, |
| 574 | unsigned count) |
| 575 | { |
| 576 | int ret; |
| 577 | int res; |
| 578 | OrigFn fn; |
| 579 | VALGRIND_GET_ORIG_FN(fn); |
| 580 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__BARRIER_INIT, |
| 581 | barrier, sizeof(*barrier), |
| 582 | count, 0, 0); |
| 583 | CALL_FN_W_WWW(ret, fn, barrier, attr, count); |
| 584 | return ret; |
| 585 | } |
| 586 | |
| 587 | // pthread_barrier_destroy |
| 588 | PTH_FUNC(int, pthreadZubarrierZudestroy, // pthread_barrier_destroy |
| 589 | pthread_barrier_t* barrier) |
| 590 | { |
| 591 | int ret; |
| 592 | int res; |
| 593 | OrigFn fn; |
| 594 | VALGRIND_GET_ORIG_FN(fn); |
| 595 | CALL_FN_W_W(ret, fn, barrier); |
| 596 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__BARRIER_DESTROY, |
| 597 | barrier, 0, 0, 0, 0); |
| 598 | return ret; |
| 599 | } |
| 600 | |
| 601 | // pthread_barrier_wait |
| 602 | PTH_FUNC(int, pthreadZubarrierZuwait, // pthread_barrier_wait |
| 603 | pthread_barrier_t* barrier) |
| 604 | { |
| 605 | int ret; |
| 606 | int res; |
| 607 | OrigFn fn; |
| 608 | VALGRIND_GET_ORIG_FN(fn); |
| 609 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_BARRIER_WAIT, |
| 610 | barrier, 0, 0, 0, 0); |
| 611 | CALL_FN_W_W(ret, fn, barrier); |
| 612 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_BARRIER_WAIT, |
| 613 | barrier, |
| 614 | ret == 0 || ret == PTHREAD_BARRIER_SERIAL_THREAD, |
| 615 | 0, 0, 0); |
| 616 | return ret; |
| 617 | } |
| 618 | |
| 619 | |
| 620 | // From glibc 2.0 linuxthreads/sysdeps/pthread/cmpxchg/semaphorebits.h |
| 621 | typedef struct { long int sem_status; } sem_t_glibc_2_0; |
| 622 | |
| 623 | // sem_init |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 624 | PTH_FUNC(int, semZuinitZAGLIBCZu2Zd0, // sem_init@GLIBC_2.0 |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 625 | sem_t_glibc_2_0 *sem, |
| 626 | int pshared, |
| 627 | unsigned int value) |
| 628 | { |
| 629 | int ret; |
| 630 | int res; |
| 631 | OrigFn fn; |
| 632 | VALGRIND_GET_ORIG_FN(fn); |
| 633 | CALL_FN_W_WWW(ret, fn, sem, pshared, value); |
| 634 | if (ret == 0) |
| 635 | { |
| 636 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__SEM_INIT, |
| 637 | sem, sizeof(*sem), |
| 638 | pshared, value, 0); |
| 639 | } |
| 640 | return ret; |
| 641 | } |
| 642 | |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 643 | PTH_FUNC(int, semZuinitZa, // sem_init* |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 644 | sem_t *sem, |
| 645 | int pshared, |
| 646 | unsigned int value) |
| 647 | { |
| 648 | int ret; |
| 649 | int res; |
| 650 | OrigFn fn; |
| 651 | VALGRIND_GET_ORIG_FN(fn); |
| 652 | CALL_FN_W_WWW(ret, fn, sem, pshared, value); |
| 653 | if (ret == 0) |
| 654 | { |
| 655 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__SEM_INIT, |
| 656 | sem, sizeof(*sem), |
| 657 | pshared, value, 0); |
| 658 | } |
| 659 | return ret; |
| 660 | } |
| 661 | |
| 662 | // sem_destroy |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 663 | PTH_FUNC(int, semZudestroyZAGLIBCZu2Zd0, // sem_destroy@GLIBC_2.0 |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 664 | sem_t_glibc_2_0 *sem) |
| 665 | { |
| 666 | int ret; |
| 667 | int res; |
| 668 | OrigFn fn; |
| 669 | VALGRIND_GET_ORIG_FN(fn); |
| 670 | CALL_FN_W_W(ret, fn, sem); |
| 671 | if (ret == 0) |
| 672 | { |
| 673 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__SEM_DESTROY, |
| 674 | sem, 0, 0, 0, 0); |
| 675 | } |
| 676 | return ret; |
| 677 | } |
| 678 | |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 679 | PTH_FUNC(int, semZudestroyZa, // sem_destroy* |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 680 | sem_t *sem) |
| 681 | { |
| 682 | int ret; |
| 683 | int res; |
| 684 | OrigFn fn; |
| 685 | VALGRIND_GET_ORIG_FN(fn); |
| 686 | CALL_FN_W_W(ret, fn, sem); |
| 687 | if (ret == 0) |
| 688 | { |
| 689 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__SEM_DESTROY, |
| 690 | sem, 0, 0, 0, 0); |
| 691 | } |
| 692 | return ret; |
| 693 | } |
| 694 | |
| 695 | // sem_wait |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 696 | PTH_FUNC(int, semZuwaitZAGLIBCZu2Zd0, // sem_wait@GLIBC_2.0 |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 697 | sem_t_glibc_2_0 *sem) |
| 698 | { |
| 699 | int ret; |
| 700 | int res; |
| 701 | OrigFn fn; |
| 702 | VALGRIND_GET_ORIG_FN(fn); |
bart | 28230a3 | 2008-02-29 17:27:03 +0000 | [diff] [blame] | 703 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_SEM_WAIT, |
| 704 | sem, 0, 0, 0, 0); |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 705 | CALL_FN_W_W(ret, fn, sem); |
bart | 28230a3 | 2008-02-29 17:27:03 +0000 | [diff] [blame] | 706 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_SEM_WAIT, |
| 707 | sem, ret == 0, 0, 0, 0); |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 708 | return ret; |
| 709 | } |
| 710 | |
bart | 28230a3 | 2008-02-29 17:27:03 +0000 | [diff] [blame] | 711 | // sem_wait |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 712 | PTH_FUNC(int, semZuwaitZa, // sem_wait* |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 713 | sem_t *sem) |
| 714 | { |
| 715 | int ret; |
| 716 | int res; |
| 717 | OrigFn fn; |
| 718 | VALGRIND_GET_ORIG_FN(fn); |
bart | 28230a3 | 2008-02-29 17:27:03 +0000 | [diff] [blame] | 719 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_SEM_WAIT, |
| 720 | sem, 0, 0, 0, 0); |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 721 | CALL_FN_W_W(ret, fn, sem); |
bart | 28230a3 | 2008-02-29 17:27:03 +0000 | [diff] [blame] | 722 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_SEM_WAIT, |
| 723 | sem, ret == 0, 0, 0, 0); |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 724 | return ret; |
| 725 | } |
| 726 | |
| 727 | // sem_trywait |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 728 | PTH_FUNC(int, semZutrywaitZAGLIBCZu2Zd0, // sem_trywait@GLIBC_2.0 |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 729 | sem_t_glibc_2_0 *sem) |
| 730 | { |
| 731 | int ret; |
| 732 | int res; |
| 733 | OrigFn fn; |
| 734 | VALGRIND_GET_ORIG_FN(fn); |
bart | 28230a3 | 2008-02-29 17:27:03 +0000 | [diff] [blame] | 735 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_SEM_WAIT, |
| 736 | sem, 0, 0, 0, 0); |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 737 | CALL_FN_W_W(ret, fn, sem); |
bart | 28230a3 | 2008-02-29 17:27:03 +0000 | [diff] [blame] | 738 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_SEM_WAIT, |
| 739 | sem, ret == 0, 0, 0, 0); |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 740 | return ret; |
| 741 | } |
| 742 | |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 743 | PTH_FUNC(int, semZutrywaitZa, // sem_trywait* |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 744 | sem_t *sem) |
| 745 | { |
| 746 | int ret; |
| 747 | int res; |
| 748 | OrigFn fn; |
| 749 | VALGRIND_GET_ORIG_FN(fn); |
bart | 28230a3 | 2008-02-29 17:27:03 +0000 | [diff] [blame] | 750 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_SEM_WAIT, |
| 751 | sem, 0, 0, 0, 0); |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 752 | CALL_FN_W_W(ret, fn, sem); |
bart | 28230a3 | 2008-02-29 17:27:03 +0000 | [diff] [blame] | 753 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_SEM_WAIT, |
| 754 | sem, ret == 0, 0, 0, 0); |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 755 | return ret; |
| 756 | } |
| 757 | |
| 758 | // sem_timedwait |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 759 | PTH_FUNC(int, semZutimedwait, // sem_timedwait |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 760 | sem_t *sem, const struct timespec *abs_timeout) |
| 761 | { |
| 762 | int ret; |
| 763 | int res; |
| 764 | OrigFn fn; |
| 765 | VALGRIND_GET_ORIG_FN(fn); |
bart | 28230a3 | 2008-02-29 17:27:03 +0000 | [diff] [blame] | 766 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_SEM_WAIT, |
| 767 | sem, 0, 0, 0, 0); |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 768 | CALL_FN_W_WW(ret, fn, sem, abs_timeout); |
bart | 28230a3 | 2008-02-29 17:27:03 +0000 | [diff] [blame] | 769 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_SEM_WAIT, |
| 770 | sem, ret == 0, 0, 0, 0); |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 771 | return ret; |
| 772 | } |
| 773 | |
| 774 | // sem_post |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 775 | PTH_FUNC(int, semZupostZAGLIBCZu2Zd0, // sem_post@GLIBC_2.0 |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 776 | sem_t_glibc_2_0 *sem) |
| 777 | { |
| 778 | int ret; |
| 779 | int res; |
| 780 | OrigFn fn; |
| 781 | VALGRIND_GET_ORIG_FN(fn); |
| 782 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_SEM_POST, |
| 783 | sem, sizeof(*sem), 0, 0, 0); |
| 784 | CALL_FN_W_W(ret, fn, sem); |
sewardj | c0be925 | 2008-02-11 11:00:51 +0000 | [diff] [blame] | 785 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_SEM_POST, |
| 786 | sem, sizeof(*sem), ret == 0, 0, 0); |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 787 | return ret; |
| 788 | } |
| 789 | |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 790 | // sem_post |
| 791 | PTH_FUNC(int, semZupostZa, // sem_post* |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 792 | sem_t *sem) |
| 793 | { |
| 794 | int ret; |
| 795 | int res; |
| 796 | OrigFn fn; |
| 797 | VALGRIND_GET_ORIG_FN(fn); |
| 798 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_SEM_POST, |
| 799 | sem, sizeof(*sem), 0, 0, 0); |
| 800 | CALL_FN_W_W(ret, fn, sem); |
sewardj | e3b57aa | 2008-01-18 07:42:01 +0000 | [diff] [blame] | 801 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_SEM_POST, |
| 802 | sem, sizeof(*sem), ret == 0, 0, 0); |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 803 | return ret; |
| 804 | } |
| 805 | |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 806 | // pthread_rwlock_init |
| 807 | PTH_FUNC(int, |
| 808 | pthreadZurwlockZuinitZa, // pthread_rwlock_init* |
| 809 | pthread_rwlock_t* rwlock, |
| 810 | const pthread_rwlockattr_t* attr) |
| 811 | { |
| 812 | int ret; |
| 813 | int res; |
| 814 | OrigFn fn; |
| 815 | VALGRIND_GET_ORIG_FN(fn); |
| 816 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_RWLOCK_INIT, |
| 817 | rwlock, sizeof(*rwlock), 0, 0, 0); |
| 818 | CALL_FN_W_WW(ret, fn, rwlock, attr); |
| 819 | return ret; |
| 820 | } |
| 821 | |
| 822 | // pthread_rwlock_destroy |
| 823 | PTH_FUNC(int, |
| 824 | pthreadZurwlockZudestroyZa, // pthread_rwlock_destroy* |
| 825 | pthread_rwlock_t* rwlock) |
| 826 | { |
| 827 | int ret; |
| 828 | int res; |
| 829 | OrigFn fn; |
| 830 | VALGRIND_GET_ORIG_FN(fn); |
| 831 | CALL_FN_W_W(ret, fn, rwlock); |
| 832 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_RWLOCK_DESTROY, |
| 833 | rwlock, 0, 0, 0, 0); |
| 834 | return ret; |
| 835 | } |
| 836 | |
| 837 | // pthread_rwlock_rdlock |
| 838 | PTH_FUNC(int, |
| 839 | pthreadZurwlockZurdlockZa, // pthread_rwlock_rdlock* |
| 840 | pthread_rwlock_t* rwlock) |
| 841 | { |
| 842 | int ret; |
| 843 | int res; |
| 844 | OrigFn fn; |
| 845 | VALGRIND_GET_ORIG_FN(fn); |
| 846 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_RWLOCK_RDLOCK, |
| 847 | rwlock, sizeof(*rwlock), 0, 0, 0); |
| 848 | CALL_FN_W_W(ret, fn, rwlock); |
| 849 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_RWLOCK_RDLOCK, |
| 850 | rwlock, ret == 0, 0, 0, 0); |
| 851 | return ret; |
| 852 | } |
| 853 | |
| 854 | // pthread_rwlock_wrlock |
| 855 | PTH_FUNC(int, |
| 856 | pthreadZurwlockZuwrlockZa, // pthread_rwlock_wrlock* |
| 857 | pthread_rwlock_t* rwlock) |
| 858 | { |
| 859 | int ret; |
| 860 | int res; |
| 861 | OrigFn fn; |
| 862 | VALGRIND_GET_ORIG_FN(fn); |
| 863 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_RWLOCK_WRLOCK, |
| 864 | rwlock, sizeof(*rwlock), 0, 0, 0); |
| 865 | CALL_FN_W_W(ret, fn, rwlock); |
| 866 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_RWLOCK_WRLOCK, |
| 867 | rwlock, ret == 0, 0, 0, 0); |
| 868 | return ret; |
| 869 | } |
| 870 | |
| 871 | // pthread_rwlock_timedrdlock |
| 872 | PTH_FUNC(int, |
| 873 | pthreadZurwlockZutimedrdlockZa, // pthread_rwlock_timedrdlock* |
| 874 | pthread_rwlock_t* rwlock) |
| 875 | { |
| 876 | int ret; |
| 877 | int res; |
| 878 | OrigFn fn; |
| 879 | VALGRIND_GET_ORIG_FN(fn); |
| 880 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_RWLOCK_RDLOCK, |
| 881 | rwlock, sizeof(*rwlock), 0, 0, 0); |
| 882 | CALL_FN_W_W(ret, fn, rwlock); |
| 883 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_RWLOCK_RDLOCK, |
| 884 | rwlock, ret == 0, 0, 0, 0); |
| 885 | return ret; |
| 886 | } |
| 887 | |
| 888 | // pthread_rwlock_timedwrlock |
| 889 | PTH_FUNC(int, |
| 890 | pthreadZurwlockZutimedwrlockZa, // pthread_rwlock_timedwrlock* |
| 891 | pthread_rwlock_t* rwlock) |
| 892 | { |
| 893 | int ret; |
| 894 | int res; |
| 895 | OrigFn fn; |
| 896 | VALGRIND_GET_ORIG_FN(fn); |
| 897 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_RWLOCK_WRLOCK, |
| 898 | rwlock, sizeof(*rwlock), 0, 0, 0); |
| 899 | CALL_FN_W_W(ret, fn, rwlock); |
| 900 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_RWLOCK_WRLOCK, |
| 901 | rwlock, ret == 0, 0, 0, 0); |
| 902 | return ret; |
| 903 | } |
| 904 | |
| 905 | // pthread_rwlock_tryrdlock |
| 906 | PTH_FUNC(int, |
| 907 | pthreadZurwlockZutryrdlockZa, // pthread_rwlock_tryrdlock* |
| 908 | pthread_rwlock_t* rwlock) |
| 909 | { |
| 910 | int ret; |
| 911 | int res; |
| 912 | OrigFn fn; |
| 913 | VALGRIND_GET_ORIG_FN(fn); |
| 914 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_RWLOCK_RDLOCK, |
| 915 | rwlock, sizeof(*rwlock), 0, 0, 0); |
| 916 | CALL_FN_W_W(ret, fn, rwlock); |
| 917 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_RWLOCK_RDLOCK, |
| 918 | rwlock, ret == 0, 0, 0, 0); |
| 919 | return ret; |
| 920 | } |
| 921 | |
| 922 | // pthread_rwlock_trywrlock |
| 923 | PTH_FUNC(int, |
| 924 | pthreadZurwlockZutrywrlockZa, // pthread_rwlock_trywrlock* |
| 925 | pthread_rwlock_t* rwlock) |
| 926 | { |
| 927 | int ret; |
| 928 | int res; |
| 929 | OrigFn fn; |
| 930 | VALGRIND_GET_ORIG_FN(fn); |
| 931 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_RWLOCK_WRLOCK, |
| 932 | rwlock, sizeof(*rwlock), 0, 0, 0); |
| 933 | CALL_FN_W_W(ret, fn, rwlock); |
| 934 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_RWLOCK_WRLOCK, |
| 935 | rwlock, ret == 0, 0, 0, 0); |
| 936 | return ret; |
| 937 | } |
| 938 | |
| 939 | // pthread_rwlock_unlock |
| 940 | PTH_FUNC(int, |
| 941 | pthreadZurwlockZuunlockZa, // pthread_rwlock_unlock* |
| 942 | pthread_rwlock_t* rwlock) |
| 943 | { |
| 944 | int ret; |
| 945 | int res; |
| 946 | OrigFn fn; |
| 947 | VALGRIND_GET_ORIG_FN(fn); |
| 948 | CALL_FN_W_W(ret, fn, rwlock); |
bart | 777f7fe | 2008-03-02 17:43:18 +0000 | [diff] [blame] | 949 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_RWLOCK_UNLOCK, |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 950 | rwlock, ret == 0, 0, 0, 0); |
| 951 | return ret; |
| 952 | } |
| 953 | |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 954 | |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 955 | /* |
| 956 | * Local variables: |
| 957 | * c-basic-offset: 3 |
| 958 | * End: |
| 959 | */ |