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