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