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 | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 247 | int ret; |
| 248 | OrigFn fn; |
| 249 | VgPosixThreadArgs vgargs; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 250 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 251 | VALGRIND_GET_ORIG_FN(fn); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 252 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 253 | vg_start_suppression(&vgargs.wrapper_started, |
| 254 | sizeof(vgargs.wrapper_started)); |
| 255 | vgargs.start = start; |
| 256 | vgargs.arg = arg; |
| 257 | vgargs.wrapper_started = 0; |
| 258 | vgargs.detachstate = PTHREAD_CREATE_JOINABLE; |
| 259 | if (attr) |
| 260 | { |
| 261 | if (pthread_attr_getdetachstate(attr, &vgargs.detachstate) != 0) |
| 262 | { |
| 263 | assert(0); |
| 264 | } |
| 265 | } |
| 266 | assert(vgargs.detachstate == PTHREAD_CREATE_JOINABLE |
| 267 | || vgargs.detachstate == PTHREAD_CREATE_DETACHED); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 268 | #if 0 |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 269 | pthread_mutex_init(&vgargs.mutex, 0); |
| 270 | pthread_cond_init(&vgargs.cond, 0); |
| 271 | pthread_mutex_lock(&vgargs.mutex); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 272 | #endif |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 273 | CALL_FN_W_WWWW(ret, fn, thread, attr, vg_thread_wrapper, &vgargs); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 274 | #if 0 |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 275 | pthread_cond_wait(&vgargs.cond, &vgargs.mutex); |
| 276 | pthread_mutex_unlock(&vgargs.mutex); |
| 277 | pthread_cond_destroy(&vgargs.cond); |
| 278 | pthread_mutex_destroy(&vgargs.mutex); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 279 | #else |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 280 | // Yes, you see it correctly, busy waiting ... The problem is that |
| 281 | // POSIX threads functions cannot be called here -- the functions defined |
| 282 | // in this file (drd_intercepts.c) would be called instead of those in |
| 283 | // libpthread.so. This loop is necessary because vgargs is allocated on the |
| 284 | // stack, and the created thread reads it. |
| 285 | if (ret == 0) |
| 286 | { |
| 287 | while (! vgargs.wrapper_started) |
| 288 | { |
| 289 | sched_yield(); |
| 290 | } |
| 291 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 292 | #endif |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 293 | return ret; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | // pthread_join |
| 297 | PTH_FUNC(int, pthreadZujoin, // pthread_join |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 298 | pthread_t pt_joinee, void **thread_return) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 299 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 300 | int ret; |
| 301 | int res; |
| 302 | OrigFn fn; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 303 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 304 | VALGRIND_GET_ORIG_FN(fn); |
| 305 | CALL_FN_W_WW(ret, fn, pt_joinee, thread_return); |
| 306 | if (ret == 0) |
| 307 | { |
| 308 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_THREAD_JOIN, |
| 309 | pt_joinee, 0, 0, 0, 0); |
| 310 | } |
| 311 | return ret; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | // pthread_detach |
| 315 | PTH_FUNC(int, pthreadZudetach, pthread_t pt_thread) |
| 316 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 317 | int ret; |
| 318 | OrigFn fn; |
| 319 | VALGRIND_GET_ORIG_FN(fn); |
| 320 | { |
| 321 | CALL_FN_W_W(ret, fn, pt_thread); |
| 322 | if (ret == 0) |
| 323 | { |
| 324 | vg_set_joinable(pt_thread, 0); |
| 325 | } |
| 326 | } |
| 327 | return ret; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | // pthread_mutex_init |
| 331 | PTH_FUNC(int, pthreadZumutexZuinit, |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 332 | pthread_mutex_t *mutex, |
| 333 | const pthread_mutexattr_t* attr) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 334 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 335 | int ret; |
| 336 | int res; |
| 337 | OrigFn fn; |
| 338 | int mt; |
| 339 | VALGRIND_GET_ORIG_FN(fn); |
| 340 | mt = PTHREAD_MUTEX_DEFAULT; |
| 341 | if (attr) |
| 342 | pthread_mutexattr_gettype(attr, &mt); |
| 343 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_MUTEX_INIT, |
| 344 | mutex, pthread_to_drd_mutex_type(mt), 0, 0, 0); |
| 345 | CALL_FN_W_WW(ret, fn, mutex, attr); |
| 346 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_MUTEX_INIT, |
| 347 | mutex, 0, 0, 0, 0); |
| 348 | return ret; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | // pthread_mutex_destroy |
| 352 | PTH_FUNC(int, pthreadZumutexZudestroy, |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 353 | pthread_mutex_t *mutex) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 354 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 355 | int ret; |
| 356 | int res; |
| 357 | OrigFn fn; |
| 358 | VALGRIND_GET_ORIG_FN(fn); |
| 359 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_MUTEX_DESTROY, |
| 360 | mutex, 0, 0, 0, 0); |
| 361 | CALL_FN_W_W(ret, fn, mutex); |
| 362 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_MUTEX_DESTROY, |
| 363 | mutex, mutex_type(mutex), 0, 0, 0); |
| 364 | return ret; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | // pthread_mutex_lock |
| 368 | PTH_FUNC(int, pthreadZumutexZulock, // pthread_mutex_lock |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 369 | pthread_mutex_t *mutex) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 370 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 371 | int ret; |
| 372 | int res; |
| 373 | OrigFn fn; |
| 374 | VALGRIND_GET_ORIG_FN(fn); |
| 375 | VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__PRE_MUTEX_LOCK, |
| 376 | mutex, mutex_type(mutex), 0, 0, 0); |
| 377 | CALL_FN_W_W(ret, fn, mutex); |
| 378 | VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__POST_MUTEX_LOCK, |
| 379 | mutex, ret == 0, 0, 0, 0); |
| 380 | return ret; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | // pthread_mutex_trylock |
| 384 | PTH_FUNC(int, pthreadZumutexZutrylock, // pthread_mutex_trylock |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 385 | pthread_mutex_t *mutex) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 386 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 387 | int ret; |
| 388 | int res; |
| 389 | OrigFn fn; |
| 390 | VALGRIND_GET_ORIG_FN(fn); |
| 391 | VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__PRE_MUTEX_LOCK, |
bart | 2e3a3c1 | 2008-03-24 08:33:47 +0000 | [diff] [blame] | 392 | mutex, mutex_type(mutex), 1, 0, 0); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 393 | CALL_FN_W_W(ret, fn, mutex); |
| 394 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_MUTEX_LOCK, |
| 395 | mutex, ret == 0, 0, 0, 0); |
| 396 | return ret; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 397 | } |
| 398 | |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 399 | // pthread_mutex_timedlock |
| 400 | PTH_FUNC(int, pthreadZumutexZutimedlock, // pthread_mutex_timedlock |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 401 | pthread_mutex_t *mutex, |
| 402 | const struct timespec *abs_timeout) |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 403 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 404 | int ret; |
| 405 | int res; |
| 406 | OrigFn fn; |
| 407 | VALGRIND_GET_ORIG_FN(fn); |
| 408 | VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__PRE_MUTEX_LOCK, |
| 409 | mutex, mutex_type(mutex), 0, 0, 0); |
| 410 | CALL_FN_W_WW(ret, fn, mutex, abs_timeout); |
| 411 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_MUTEX_LOCK, |
| 412 | mutex, ret == 0, 0, 0, 0); |
| 413 | return ret; |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 414 | } |
| 415 | |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 416 | // pthread_mutex_unlock |
| 417 | PTH_FUNC(int, pthreadZumutexZuunlock, // pthread_mutex_unlock |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 418 | pthread_mutex_t *mutex) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 419 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 420 | int ret; |
| 421 | int res; |
| 422 | OrigFn fn; |
| 423 | VALGRIND_GET_ORIG_FN(fn); |
| 424 | VALGRIND_DO_CLIENT_REQUEST(res, -1, |
| 425 | VG_USERREQ__PRE_MUTEX_UNLOCK, |
| 426 | mutex, mutex_type(mutex), 0, 0, 0); |
| 427 | CALL_FN_W_W(ret, fn, mutex); |
| 428 | VALGRIND_DO_CLIENT_REQUEST(res, -1, |
| 429 | VG_USERREQ__POST_MUTEX_UNLOCK, |
| 430 | mutex, 0, 0, 0, 0); |
| 431 | return ret; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | // pthread_cond_init |
sewardj | 347eeba | 2008-01-21 14:19:07 +0000 | [diff] [blame] | 435 | PTH_FUNC(int, pthreadZucondZuinitZa, // pthread_cond_init* |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 436 | pthread_cond_t* cond, |
| 437 | const pthread_condattr_t* attr) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 438 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 439 | int ret; |
| 440 | int res; |
| 441 | OrigFn fn; |
| 442 | VALGRIND_GET_ORIG_FN(fn); |
| 443 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_COND_INIT, |
| 444 | cond, 0, 0, 0, 0); |
| 445 | CALL_FN_W_WW(ret, fn, cond, attr); |
| 446 | return ret; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | // pthread_cond_destroy |
sewardj | 347eeba | 2008-01-21 14:19:07 +0000 | [diff] [blame] | 450 | PTH_FUNC(int, pthreadZucondZudestroyZa, // pthread_cond_destroy* |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 451 | pthread_cond_t* cond) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 452 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 453 | int ret; |
| 454 | int res; |
| 455 | OrigFn fn; |
| 456 | VALGRIND_GET_ORIG_FN(fn); |
| 457 | CALL_FN_W_W(ret, fn, cond); |
| 458 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_COND_DESTROY, |
| 459 | cond, 0, 0, 0, 0); |
| 460 | return ret; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | // pthread_cond_wait |
sewardj | 347eeba | 2008-01-21 14:19:07 +0000 | [diff] [blame] | 464 | PTH_FUNC(int, pthreadZucondZuwaitZa, // pthread_cond_wait* |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 465 | pthread_cond_t *cond, |
| 466 | pthread_mutex_t *mutex) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 467 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 468 | int ret; |
| 469 | int res; |
| 470 | OrigFn fn; |
| 471 | VALGRIND_GET_ORIG_FN(fn); |
| 472 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_COND_WAIT, |
| 473 | cond, mutex, mutex_type(mutex), 0, 0); |
| 474 | CALL_FN_W_WW(ret, fn, cond, mutex); |
| 475 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_COND_WAIT, |
bart | 1b7a830 | 2008-03-30 08:39:51 +0000 | [diff] [blame] | 476 | cond, mutex, 1, 0, 0); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 477 | return ret; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | // pthread_cond_timedwait |
sewardj | 347eeba | 2008-01-21 14:19:07 +0000 | [diff] [blame] | 481 | PTH_FUNC(int, pthreadZucondZutimedwaitZa, // pthread_cond_timedwait* |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 482 | pthread_cond_t *cond, |
| 483 | pthread_mutex_t *mutex, |
| 484 | const struct timespec* abstime) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 485 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 486 | int ret; |
| 487 | int res; |
| 488 | OrigFn fn; |
| 489 | VALGRIND_GET_ORIG_FN(fn); |
| 490 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_COND_WAIT, |
| 491 | cond, mutex, mutex_type(mutex), 0, 0); |
| 492 | CALL_FN_W_WWW(ret, fn, cond, mutex, abstime); |
| 493 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_COND_WAIT, |
bart | 1b7a830 | 2008-03-30 08:39:51 +0000 | [diff] [blame] | 494 | cond, mutex, 1, 0, 0); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 495 | return ret; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | // pthread_cond_signal |
sewardj | 347eeba | 2008-01-21 14:19:07 +0000 | [diff] [blame] | 499 | PTH_FUNC(int, pthreadZucondZusignalZa, // pthread_cond_signal* |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 500 | pthread_cond_t* cond) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 501 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 502 | int ret; |
| 503 | int res; |
| 504 | OrigFn fn; |
| 505 | VALGRIND_GET_ORIG_FN(fn); |
| 506 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_COND_SIGNAL, |
| 507 | cond, 0, 0, 0, 0); |
| 508 | CALL_FN_W_W(ret, fn, cond); |
| 509 | return ret; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | // pthread_cond_broadcast |
sewardj | 347eeba | 2008-01-21 14:19:07 +0000 | [diff] [blame] | 513 | PTH_FUNC(int, pthreadZucondZubroadcastZa, // pthread_cond_broadcast* |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 514 | pthread_cond_t* cond) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 515 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 516 | int ret; |
| 517 | int res; |
| 518 | OrigFn fn; |
| 519 | VALGRIND_GET_ORIG_FN(fn); |
| 520 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_COND_BROADCAST, |
| 521 | cond, 0, 0, 0, 0); |
| 522 | CALL_FN_W_W(ret, fn, cond); |
| 523 | return ret; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | |
| 527 | // pthread_spin_init |
| 528 | PTH_FUNC(int, pthreadZuspinZuinit, // pthread_spin_init |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 529 | pthread_spinlock_t *spinlock, |
| 530 | int pshared) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 531 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 532 | int ret; |
| 533 | int res; |
| 534 | OrigFn fn; |
| 535 | VALGRIND_GET_ORIG_FN(fn); |
| 536 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__SPIN_INIT_OR_UNLOCK, |
| 537 | spinlock, mutex_type_spinlock, 0, 0, 0); |
| 538 | CALL_FN_W_WW(ret, fn, spinlock, pshared); |
| 539 | return ret; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | // pthread_spin_destroy |
| 543 | PTH_FUNC(int, pthreadZuspinZudestroy, // pthread_spin_destroy |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 544 | pthread_spinlock_t *spinlock) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 545 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 546 | int ret; |
| 547 | int res; |
| 548 | OrigFn fn; |
| 549 | VALGRIND_GET_ORIG_FN(fn); |
| 550 | CALL_FN_W_W(ret, fn, spinlock); |
| 551 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_MUTEX_DESTROY, |
| 552 | spinlock, mutex_type_spinlock, 0, 0, 0); |
| 553 | return ret; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | // pthread_spin_lock |
| 557 | PTH_FUNC(int, pthreadZuspinZulock, // pthread_spin_lock |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 558 | pthread_spinlock_t *spinlock) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 559 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 560 | int ret; |
| 561 | int res; |
| 562 | OrigFn fn; |
| 563 | VALGRIND_GET_ORIG_FN(fn); |
| 564 | VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__PRE_MUTEX_LOCK, |
| 565 | spinlock, mutex_type_spinlock, 0, 0, 0); |
| 566 | CALL_FN_W_W(ret, fn, spinlock); |
| 567 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_MUTEX_LOCK, |
| 568 | spinlock, ret == 0, 0, 0, 0); |
| 569 | return ret; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | // pthread_spin_trylock |
| 573 | PTH_FUNC(int, pthreadZuspinZutrylock, // pthread_spin_trylock |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 574 | pthread_spinlock_t *spinlock) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 575 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 576 | int ret; |
| 577 | int res; |
| 578 | OrigFn fn; |
| 579 | VALGRIND_GET_ORIG_FN(fn); |
| 580 | VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__PRE_MUTEX_LOCK, |
| 581 | spinlock, mutex_type_spinlock, 0, 0, 0); |
| 582 | CALL_FN_W_W(ret, fn, spinlock); |
| 583 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_MUTEX_LOCK, |
| 584 | spinlock, ret == 0, 0, 0, 0); |
| 585 | return ret; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | // pthread_spin_unlock |
| 589 | PTH_FUNC(int, pthreadZuspinZuunlock, // pthread_spin_unlock |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 590 | pthread_spinlock_t *spinlock) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 591 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 592 | int ret; |
| 593 | int res; |
| 594 | OrigFn fn; |
| 595 | VALGRIND_GET_ORIG_FN(fn); |
| 596 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__SPIN_INIT_OR_UNLOCK, |
| 597 | spinlock, mutex_type_spinlock, 0, 0, 0); |
| 598 | CALL_FN_W_W(ret, fn, spinlock); |
| 599 | return ret; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 600 | } |
| 601 | |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 602 | // pthread_barrier_init |
| 603 | PTH_FUNC(int, pthreadZubarrierZuinit, // pthread_barrier_init |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 604 | pthread_barrier_t* barrier, |
| 605 | const pthread_barrierattr_t* attr, |
| 606 | unsigned count) |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 607 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 608 | int ret; |
| 609 | int res; |
| 610 | OrigFn fn; |
| 611 | VALGRIND_GET_ORIG_FN(fn); |
| 612 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_BARRIER_INIT, |
| 613 | barrier, pthread_barrier, count, 0, 0); |
| 614 | CALL_FN_W_WWW(ret, fn, barrier, attr, count); |
| 615 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_BARRIER_INIT, |
| 616 | barrier, pthread_barrier, 0, 0, 0); |
| 617 | return ret; |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | // pthread_barrier_destroy |
| 621 | PTH_FUNC(int, pthreadZubarrierZudestroy, // pthread_barrier_destroy |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 622 | pthread_barrier_t* barrier) |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 623 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 624 | int ret; |
| 625 | int res; |
| 626 | OrigFn fn; |
| 627 | VALGRIND_GET_ORIG_FN(fn); |
| 628 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_BARRIER_DESTROY, |
| 629 | barrier, pthread_barrier, 0, 0, 0); |
| 630 | CALL_FN_W_W(ret, fn, barrier); |
| 631 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_BARRIER_DESTROY, |
| 632 | barrier, pthread_barrier, 0, 0, 0); |
| 633 | return ret; |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 634 | } |
| 635 | |
| 636 | // pthread_barrier_wait |
| 637 | PTH_FUNC(int, pthreadZubarrierZuwait, // pthread_barrier_wait |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 638 | pthread_barrier_t* barrier) |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 639 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 640 | int ret; |
| 641 | int res; |
| 642 | OrigFn fn; |
| 643 | VALGRIND_GET_ORIG_FN(fn); |
| 644 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_BARRIER_WAIT, |
| 645 | barrier, pthread_barrier, 0, 0, 0); |
| 646 | CALL_FN_W_W(ret, fn, barrier); |
| 647 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_BARRIER_WAIT, |
| 648 | barrier, pthread_barrier, |
| 649 | ret == 0 || ret == PTHREAD_BARRIER_SERIAL_THREAD, |
| 650 | 0, 0); |
| 651 | return ret; |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 655 | // sem_init |
bart | 368ec98 | 2008-03-11 20:39:01 +0000 | [diff] [blame] | 656 | PTH_FUNC(int, semZuinitZa, // sem_init* |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 657 | sem_t *sem, |
| 658 | int pshared, |
| 659 | unsigned int value) |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 660 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 661 | int ret; |
| 662 | int res; |
| 663 | OrigFn fn; |
| 664 | VALGRIND_GET_ORIG_FN(fn); |
| 665 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_SEM_INIT, |
| 666 | sem, pshared, value, 0, 0); |
| 667 | CALL_FN_W_WWW(ret, fn, sem, pshared, value); |
| 668 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_SEM_INIT, |
| 669 | sem, 0, 0, 0, 0); |
| 670 | return ret; |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | // sem_destroy |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 674 | PTH_FUNC(int, semZudestroyZa, // sem_destroy* |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 675 | sem_t *sem) |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 676 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 677 | int ret; |
| 678 | int res; |
| 679 | OrigFn fn; |
| 680 | VALGRIND_GET_ORIG_FN(fn); |
| 681 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_SEM_DESTROY, |
| 682 | sem, 0, 0, 0, 0); |
| 683 | CALL_FN_W_W(ret, fn, sem); |
| 684 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_SEM_DESTROY, |
| 685 | sem, 0, 0, 0, 0); |
| 686 | return ret; |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | // sem_wait |
bart | 368ec98 | 2008-03-11 20:39:01 +0000 | [diff] [blame] | 690 | PTH_FUNC(int, semZuwaitZa, // sem_wait* |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 691 | sem_t *sem) |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 692 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 693 | int ret; |
| 694 | int res; |
| 695 | OrigFn fn; |
| 696 | VALGRIND_GET_ORIG_FN(fn); |
| 697 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_SEM_WAIT, |
| 698 | sem, 0, 0, 0, 0); |
| 699 | CALL_FN_W_W(ret, fn, sem); |
| 700 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_SEM_WAIT, |
| 701 | sem, ret == 0, 0, 0, 0); |
| 702 | return ret; |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 703 | } |
| 704 | |
| 705 | // sem_trywait |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 706 | PTH_FUNC(int, semZutrywaitZa, // sem_trywait* |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 707 | sem_t *sem) |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 708 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 709 | int ret; |
| 710 | int res; |
| 711 | OrigFn fn; |
| 712 | VALGRIND_GET_ORIG_FN(fn); |
| 713 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_SEM_WAIT, |
| 714 | sem, 0, 0, 0, 0); |
| 715 | CALL_FN_W_W(ret, fn, sem); |
| 716 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_SEM_WAIT, |
| 717 | sem, ret == 0, 0, 0, 0); |
| 718 | return ret; |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | // sem_timedwait |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 722 | PTH_FUNC(int, semZutimedwait, // sem_timedwait |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 723 | sem_t *sem, const struct timespec *abs_timeout) |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 724 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 725 | int ret; |
| 726 | int res; |
| 727 | OrigFn fn; |
| 728 | VALGRIND_GET_ORIG_FN(fn); |
| 729 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_SEM_WAIT, |
| 730 | sem, 0, 0, 0, 0); |
| 731 | CALL_FN_W_WW(ret, fn, sem, abs_timeout); |
| 732 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_SEM_WAIT, |
| 733 | sem, ret == 0, 0, 0, 0); |
| 734 | return ret; |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | // sem_post |
bart | 368ec98 | 2008-03-11 20:39:01 +0000 | [diff] [blame] | 738 | PTH_FUNC(int, semZupostZa, // sem_post* |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 739 | sem_t *sem) |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 740 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 741 | int ret; |
| 742 | int res; |
| 743 | OrigFn fn; |
| 744 | VALGRIND_GET_ORIG_FN(fn); |
| 745 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_SEM_POST, |
| 746 | sem, 0, 0, 0, 0); |
| 747 | CALL_FN_W_W(ret, fn, sem); |
| 748 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_SEM_POST, |
| 749 | sem, ret == 0, 0, 0, 0); |
| 750 | return ret; |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 751 | } |
| 752 | |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 753 | // pthread_rwlock_init |
| 754 | PTH_FUNC(int, |
| 755 | pthreadZurwlockZuinitZa, // pthread_rwlock_init* |
| 756 | pthread_rwlock_t* rwlock, |
| 757 | const pthread_rwlockattr_t* attr) |
| 758 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 759 | int ret; |
| 760 | int res; |
| 761 | OrigFn fn; |
| 762 | VALGRIND_GET_ORIG_FN(fn); |
| 763 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_RWLOCK_INIT, |
| 764 | rwlock, 0, 0, 0, 0); |
| 765 | CALL_FN_W_WW(ret, fn, rwlock, attr); |
| 766 | return ret; |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 767 | } |
| 768 | |
| 769 | // pthread_rwlock_destroy |
| 770 | PTH_FUNC(int, |
| 771 | pthreadZurwlockZudestroyZa, // pthread_rwlock_destroy* |
| 772 | pthread_rwlock_t* rwlock) |
| 773 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 774 | int ret; |
| 775 | int res; |
| 776 | OrigFn fn; |
| 777 | VALGRIND_GET_ORIG_FN(fn); |
| 778 | CALL_FN_W_W(ret, fn, rwlock); |
| 779 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_RWLOCK_DESTROY, |
| 780 | rwlock, 0, 0, 0, 0); |
| 781 | return ret; |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | // pthread_rwlock_rdlock |
| 785 | PTH_FUNC(int, |
| 786 | pthreadZurwlockZurdlockZa, // pthread_rwlock_rdlock* |
| 787 | pthread_rwlock_t* rwlock) |
| 788 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 789 | int ret; |
| 790 | int res; |
| 791 | OrigFn fn; |
| 792 | VALGRIND_GET_ORIG_FN(fn); |
| 793 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_RWLOCK_RDLOCK, |
| 794 | rwlock, 0, 0, 0, 0); |
| 795 | CALL_FN_W_W(ret, fn, rwlock); |
| 796 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_RWLOCK_RDLOCK, |
| 797 | rwlock, ret == 0, 0, 0, 0); |
| 798 | return ret; |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 799 | } |
| 800 | |
| 801 | // pthread_rwlock_wrlock |
| 802 | PTH_FUNC(int, |
| 803 | pthreadZurwlockZuwrlockZa, // pthread_rwlock_wrlock* |
| 804 | pthread_rwlock_t* rwlock) |
| 805 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 806 | int ret; |
| 807 | int res; |
| 808 | OrigFn fn; |
| 809 | VALGRIND_GET_ORIG_FN(fn); |
| 810 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_RWLOCK_WRLOCK, |
| 811 | rwlock, 0, 0, 0, 0); |
| 812 | CALL_FN_W_W(ret, fn, rwlock); |
| 813 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_RWLOCK_WRLOCK, |
| 814 | rwlock, ret == 0, 0, 0, 0); |
| 815 | return ret; |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 816 | } |
| 817 | |
| 818 | // pthread_rwlock_timedrdlock |
| 819 | PTH_FUNC(int, |
| 820 | pthreadZurwlockZutimedrdlockZa, // pthread_rwlock_timedrdlock* |
| 821 | pthread_rwlock_t* rwlock) |
| 822 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 823 | int ret; |
| 824 | int res; |
| 825 | OrigFn fn; |
| 826 | VALGRIND_GET_ORIG_FN(fn); |
| 827 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_RWLOCK_RDLOCK, |
| 828 | rwlock, 0, 0, 0, 0); |
| 829 | CALL_FN_W_W(ret, fn, rwlock); |
| 830 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_RWLOCK_RDLOCK, |
| 831 | rwlock, ret == 0, 0, 0, 0); |
| 832 | return ret; |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 833 | } |
| 834 | |
| 835 | // pthread_rwlock_timedwrlock |
| 836 | PTH_FUNC(int, |
| 837 | pthreadZurwlockZutimedwrlockZa, // pthread_rwlock_timedwrlock* |
| 838 | pthread_rwlock_t* rwlock) |
| 839 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 840 | int ret; |
| 841 | int res; |
| 842 | OrigFn fn; |
| 843 | VALGRIND_GET_ORIG_FN(fn); |
| 844 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_RWLOCK_WRLOCK, |
| 845 | rwlock, 0, 0, 0, 0); |
| 846 | CALL_FN_W_W(ret, fn, rwlock); |
| 847 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_RWLOCK_WRLOCK, |
| 848 | rwlock, ret == 0, 0, 0, 0); |
| 849 | return ret; |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 850 | } |
| 851 | |
| 852 | // pthread_rwlock_tryrdlock |
| 853 | PTH_FUNC(int, |
| 854 | pthreadZurwlockZutryrdlockZa, // pthread_rwlock_tryrdlock* |
| 855 | pthread_rwlock_t* rwlock) |
| 856 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 857 | int ret; |
| 858 | int res; |
| 859 | OrigFn fn; |
| 860 | VALGRIND_GET_ORIG_FN(fn); |
| 861 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_RWLOCK_RDLOCK, |
| 862 | rwlock, 0, 0, 0, 0); |
| 863 | CALL_FN_W_W(ret, fn, rwlock); |
| 864 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_RWLOCK_RDLOCK, |
| 865 | rwlock, ret == 0, 0, 0, 0); |
| 866 | return ret; |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 867 | } |
| 868 | |
| 869 | // pthread_rwlock_trywrlock |
| 870 | PTH_FUNC(int, |
| 871 | pthreadZurwlockZutrywrlockZa, // pthread_rwlock_trywrlock* |
| 872 | pthread_rwlock_t* rwlock) |
| 873 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 874 | int ret; |
| 875 | int res; |
| 876 | OrigFn fn; |
| 877 | VALGRIND_GET_ORIG_FN(fn); |
| 878 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_RWLOCK_WRLOCK, |
| 879 | rwlock, 0, 0, 0, 0); |
| 880 | CALL_FN_W_W(ret, fn, rwlock); |
| 881 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_RWLOCK_WRLOCK, |
| 882 | rwlock, ret == 0, 0, 0, 0); |
| 883 | return ret; |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | // pthread_rwlock_unlock |
| 887 | PTH_FUNC(int, |
| 888 | pthreadZurwlockZuunlockZa, // pthread_rwlock_unlock* |
| 889 | pthread_rwlock_t* rwlock) |
| 890 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 891 | int ret; |
| 892 | int res; |
| 893 | OrigFn fn; |
| 894 | VALGRIND_GET_ORIG_FN(fn); |
| 895 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_RWLOCK_UNLOCK, |
| 896 | rwlock, 0, 0, 0, 0); |
| 897 | CALL_FN_W_W(ret, fn, rwlock); |
| 898 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_RWLOCK_UNLOCK, |
| 899 | rwlock, ret == 0, 0, 0, 0); |
| 900 | return ret; |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 901 | } |