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