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