sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1 | /*--------------------------------------------------------------------*/ |
bart | 227c659 | 2009-02-14 12:12:57 +0000 | [diff] [blame] | 2 | /*--- Client-space code for DRD. drd_pthread_intercepts.c ---*/ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 3 | /*--------------------------------------------------------------------*/ |
| 4 | |
| 5 | /* |
bart | 86562bd | 2009-02-16 19:43:56 +0000 | [diff] [blame] | 6 | This file is part of DRD, a thread error detector. |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 7 | |
sewardj | 03f8d3f | 2012-08-05 15:46:46 +0000 | [diff] [blame] | 8 | Copyright (C) 2006-2012 Bart Van Assche <bvanassche@acm.org>. |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 9 | |
| 10 | This program is free software; you can redistribute it and/or |
| 11 | modify it under the terms of the GNU General Public License as |
| 12 | published by the Free Software Foundation; either version 2 of the |
| 13 | License, or (at your option) any later version. |
| 14 | |
| 15 | This program is distributed in the hope that it will be useful, but |
| 16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18 | General Public License for more details. |
| 19 | |
| 20 | You should have received a copy of the GNU General Public License |
| 21 | along with this program; if not, write to the Free Software |
| 22 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 23 | 02111-1307, USA. |
| 24 | |
| 25 | The GNU General Public License is contained in the file COPYING. |
| 26 | */ |
| 27 | |
| 28 | /* --------------------------------------------------------------------- |
bart | 31b983d | 2010-02-21 14:52:59 +0000 | [diff] [blame] | 29 | ALL THE CODE IN THIS FILE RUNS ON THE SIMULATED CPU. |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 30 | |
| 31 | These functions are not called directly - they're the targets of code |
| 32 | redirection or load notifications (see pub_core_redir.h for info). |
| 33 | They're named weirdly so that the intercept code can find them when the |
| 34 | shared object is initially loaded. |
| 35 | |
| 36 | Note that this filename has the "drd_" prefix because it can appear |
| 37 | in stack traces, and the "drd_" makes it a little clearer that it |
| 38 | originates from Valgrind. |
| 39 | ------------------------------------------------------------------ */ |
| 40 | |
bart | 227c659 | 2009-02-14 12:12:57 +0000 | [diff] [blame] | 41 | /* |
bart | a764b37 | 2009-02-15 10:40:44 +0000 | [diff] [blame] | 42 | * Define _GNU_SOURCE to make sure that pthread_spinlock_t is available when |
| 43 | * compiling with older glibc versions (2.3 or before). |
| 44 | */ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 45 | #ifndef _GNU_SOURCE |
| 46 | #define _GNU_SOURCE |
| 47 | #endif |
| 48 | |
bart | 227c659 | 2009-02-14 12:12:57 +0000 | [diff] [blame] | 49 | #include <assert.h> /* assert() */ |
bart | d1a5cd6 | 2011-07-28 15:04:08 +0000 | [diff] [blame] | 50 | #include <errno.h> |
bart | 227c659 | 2009-02-14 12:12:57 +0000 | [diff] [blame] | 51 | #include <pthread.h> /* pthread_mutex_t */ |
| 52 | #include <semaphore.h> /* sem_t */ |
bart | 33f76c1 | 2010-09-19 11:14:31 +0000 | [diff] [blame] | 53 | #include <stdint.h> /* uintptr_t */ |
bart | 227c659 | 2009-02-14 12:12:57 +0000 | [diff] [blame] | 54 | #include <stdio.h> /* fprintf() */ |
| 55 | #include <stdlib.h> /* malloc(), free() */ |
| 56 | #include <unistd.h> /* confstr() */ |
bart | 818f17e | 2011-09-17 06:24:49 +0000 | [diff] [blame] | 57 | #include "config.h" /* HAVE_PTHREAD_MUTEX_ADAPTIVE_NP etc. */ |
| 58 | #ifdef HAVE_USABLE_LINUX_FUTEX_H |
bart | 651f56b | 2011-07-26 19:30:28 +0000 | [diff] [blame] | 59 | #include <asm/unistd.h> /* __NR_futex */ |
| 60 | #include <linux/futex.h> /* FUTEX_WAIT */ |
bart | d1a5cd6 | 2011-07-28 15:04:08 +0000 | [diff] [blame] | 61 | #ifndef FUTEX_PRIVATE_FLAG |
| 62 | #define FUTEX_PRIVATE_FLAG 0 |
| 63 | #endif |
bart | 651f56b | 2011-07-26 19:30:28 +0000 | [diff] [blame] | 64 | #endif |
bart | 227c659 | 2009-02-14 12:12:57 +0000 | [diff] [blame] | 65 | #include "drd_basics.h" /* DRD_() */ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 66 | #include "drd_clientreq.h" |
bart | 227c659 | 2009-02-14 12:12:57 +0000 | [diff] [blame] | 67 | #include "pub_tool_redir.h" /* VG_WRAP_FUNCTION_ZZ() */ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 68 | |
| 69 | |
bart | a0b7222 | 2009-03-12 18:39:31 +0000 | [diff] [blame] | 70 | /* |
bart | 8239742 | 2011-03-08 17:53:45 +0000 | [diff] [blame] | 71 | * Notes regarding thread creation: |
| 72 | * - sg_init() runs on the context of the created thread and copies the vector |
| 73 | * clock of the creator thread. This only works reliably if the creator |
| 74 | * thread waits until this copy has been performed. |
| 75 | * - DRD_(thread_compute_minimum_vc)() does not take the vector clocks into |
| 76 | * account that are involved in thread creation and for which the |
| 77 | * corresponding thread has not yet been created. So not waiting until the |
| 78 | * created thread has been started would make it possible that segments get |
| 79 | * discarded that should not yet be discarded. Or: some data races are not |
| 80 | * detected. |
bart | a0b7222 | 2009-03-12 18:39:31 +0000 | [diff] [blame] | 81 | */ |
bart | a0b7222 | 2009-03-12 18:39:31 +0000 | [diff] [blame] | 82 | |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 83 | /** |
| 84 | * Macro for generating a Valgrind interception function. |
| 85 | * @param[in] ret_ty Return type of the function to be generated. |
| 86 | * @param[in] zf Z-encoded name of the interception function. |
| 87 | * @param[in] implf Name of the function that implements the intercept. |
| 88 | * @param[in] arg_decl Argument declaration list enclosed in parentheses. |
| 89 | * @param[in] argl Argument list enclosed in parentheses. |
| 90 | */ |
bart | 377d23f | 2011-03-05 14:51:24 +0000 | [diff] [blame] | 91 | #ifdef VGO_darwin |
| 92 | static int never_true; |
| 93 | #define PTH_FUNC(ret_ty, zf, implf, argl_decl, argl) \ |
| 94 | ret_ty VG_WRAP_FUNCTION_ZZ(VG_Z_LIBPTHREAD_SONAME,zf) argl_decl; \ |
| 95 | ret_ty VG_WRAP_FUNCTION_ZZ(VG_Z_LIBPTHREAD_SONAME,zf) argl_decl \ |
| 96 | { \ |
| 97 | ret_ty pth_func_result = implf argl; \ |
| 98 | /* Apparently inserting a function call in wrapper functions */ \ |
| 99 | /* is sufficient to avoid misaligned stack errors. */ \ |
| 100 | if (never_true) \ |
| 101 | fflush(stdout); \ |
| 102 | return pth_func_result; \ |
| 103 | } |
| 104 | #else |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 105 | #define PTH_FUNC(ret_ty, zf, implf, argl_decl, argl) \ |
| 106 | ret_ty VG_WRAP_FUNCTION_ZZ(VG_Z_LIBPTHREAD_SONAME,zf) argl_decl; \ |
| 107 | ret_ty VG_WRAP_FUNCTION_ZZ(VG_Z_LIBPTHREAD_SONAME,zf) argl_decl \ |
| 108 | { return implf argl; } |
bart | 377d23f | 2011-03-05 14:51:24 +0000 | [diff] [blame] | 109 | #endif |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 110 | |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 111 | /** |
| 112 | * Macro for generating three Valgrind interception functions: one with the |
| 113 | * Z-encoded name zf, one with ZAZa ("@*") appended to the name zf and one |
| 114 | * with ZDZa ("$*") appended to the name zf. The second generated interception |
| 115 | * function will intercept versioned symbols on Linux, and the third will |
| 116 | * intercept versioned symbols on Darwin. |
| 117 | */ |
| 118 | #define PTH_FUNCS(ret_ty, zf, implf, argl_decl, argl) \ |
| 119 | PTH_FUNC(ret_ty, zf, implf, argl_decl, argl); \ |
| 120 | PTH_FUNC(ret_ty, zf ## ZAZa, implf, argl_decl, argl); \ |
| 121 | PTH_FUNC(ret_ty, zf ## ZDZa, implf, argl_decl, argl); |
| 122 | |
| 123 | /* |
bart | b2260b8 | 2011-02-13 07:55:36 +0000 | [diff] [blame] | 124 | * Not inlining one of the intercept functions will cause the regression |
| 125 | * tests to fail because this would cause an additional stackfram to appear |
| 126 | * in the output. The __always_inline macro guarantees that inlining will |
| 127 | * happen, even when compiling with optimization disabled. |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 128 | */ |
| 129 | #undef __always_inline /* since already defined in <cdefs.h> */ |
bart | 4f66a77 | 2009-07-31 17:59:28 +0000 | [diff] [blame] | 130 | #if __GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ >= 2 |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 131 | #define __always_inline __inline__ __attribute__((always_inline)) |
| 132 | #else |
| 133 | #define __always_inline __inline__ |
| 134 | #endif |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 135 | |
bart | 6f07b25 | 2008-04-04 16:45:20 +0000 | [diff] [blame] | 136 | /* Local data structures. */ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 137 | |
bart | 651f56b | 2011-07-26 19:30:28 +0000 | [diff] [blame] | 138 | typedef struct { |
bart | e528697 | 2012-01-19 19:52:15 +0000 | [diff] [blame] | 139 | pthread_mutex_t mutex; |
| 140 | int counter; |
bart | ce1d688 | 2012-01-23 17:01:58 +0000 | [diff] [blame] | 141 | int waiters; |
bart | 651f56b | 2011-07-26 19:30:28 +0000 | [diff] [blame] | 142 | } DrdSema; |
| 143 | |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 144 | typedef struct |
| 145 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 146 | void* (*start)(void*); |
| 147 | void* arg; |
| 148 | int detachstate; |
bart | e57a9e2 | 2012-01-24 08:30:32 +0000 | [diff] [blame] | 149 | DrdSema* wrapper_started; |
bart | a764b37 | 2009-02-15 10:40:44 +0000 | [diff] [blame] | 150 | } DrdPosixThreadArgs; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 151 | |
| 152 | |
bart | 227c659 | 2009-02-14 12:12:57 +0000 | [diff] [blame] | 153 | /* Local function declarations. */ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 154 | |
bart | 227c659 | 2009-02-14 12:12:57 +0000 | [diff] [blame] | 155 | static void DRD_(init)(void) __attribute__((constructor)); |
| 156 | static void DRD_(check_threading_library)(void); |
| 157 | static void DRD_(set_main_thread_state)(void); |
bart | 651f56b | 2011-07-26 19:30:28 +0000 | [diff] [blame] | 158 | static void DRD_(sema_init)(DrdSema* sema); |
| 159 | static void DRD_(sema_destroy)(DrdSema* sema); |
| 160 | static void DRD_(sema_down)(DrdSema* sema); |
| 161 | static void DRD_(sema_up)(DrdSema* sema); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 162 | |
| 163 | |
bart | 6f07b25 | 2008-04-04 16:45:20 +0000 | [diff] [blame] | 164 | /* Function definitions. */ |
| 165 | |
bart | 227c659 | 2009-02-14 12:12:57 +0000 | [diff] [blame] | 166 | /** |
| 167 | * Shared library initialization function. The function init() is called after |
| 168 | * dlopen() has loaded the shared library with DRD client intercepts because |
| 169 | * the constructor attribute was specified in the declaration of this function. |
| 170 | * Note: do specify the -nostdlib option to gcc when linking this code into a |
| 171 | * shared library because doing so would cancel the effect of the constructor |
| 172 | * attribute ! Using the gcc option -nodefaultlibs is fine because this last |
| 173 | * option preserves the shared library initialization code that calls |
| 174 | * constructor and destructor functions. |
bart | 6f07b25 | 2008-04-04 16:45:20 +0000 | [diff] [blame] | 175 | */ |
bart | 227c659 | 2009-02-14 12:12:57 +0000 | [diff] [blame] | 176 | static void DRD_(init)(void) |
bart | 6f07b25 | 2008-04-04 16:45:20 +0000 | [diff] [blame] | 177 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 178 | DRD_(check_threading_library)(); |
| 179 | DRD_(set_main_thread_state)(); |
bart | 6f07b25 | 2008-04-04 16:45:20 +0000 | [diff] [blame] | 180 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 181 | |
bart | 651f56b | 2011-07-26 19:30:28 +0000 | [diff] [blame] | 182 | static void DRD_(sema_init)(DrdSema* sema) |
| 183 | { |
| 184 | DRD_IGNORE_VAR(sema->counter); |
bart | e528697 | 2012-01-19 19:52:15 +0000 | [diff] [blame] | 185 | pthread_mutex_init(&sema->mutex, NULL); |
bart | 651f56b | 2011-07-26 19:30:28 +0000 | [diff] [blame] | 186 | sema->counter = 0; |
bart | ce1d688 | 2012-01-23 17:01:58 +0000 | [diff] [blame] | 187 | sema->waiters = 0; |
bart | 651f56b | 2011-07-26 19:30:28 +0000 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | static void DRD_(sema_destroy)(DrdSema* sema) |
| 191 | { |
bart | e528697 | 2012-01-19 19:52:15 +0000 | [diff] [blame] | 192 | pthread_mutex_destroy(&sema->mutex); |
bart | 651f56b | 2011-07-26 19:30:28 +0000 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | static void DRD_(sema_down)(DrdSema* sema) |
| 196 | { |
bart | d1a5cd6 | 2011-07-28 15:04:08 +0000 | [diff] [blame] | 197 | int res = ENOSYS; |
| 198 | |
bart | e528697 | 2012-01-19 19:52:15 +0000 | [diff] [blame] | 199 | pthread_mutex_lock(&sema->mutex); |
bart | ce1d688 | 2012-01-23 17:01:58 +0000 | [diff] [blame] | 200 | if (sema->counter == 0) { |
| 201 | sema->waiters++; |
| 202 | while (sema->counter == 0) { |
| 203 | pthread_mutex_unlock(&sema->mutex); |
bart | 818f17e | 2011-09-17 06:24:49 +0000 | [diff] [blame] | 204 | #ifdef HAVE_USABLE_LINUX_FUTEX_H |
bart | ce1d688 | 2012-01-23 17:01:58 +0000 | [diff] [blame] | 205 | if (syscall(__NR_futex, (UWord)&sema->counter, |
| 206 | FUTEX_WAIT | FUTEX_PRIVATE_FLAG, 0) == 0) |
| 207 | res = 0; |
| 208 | else |
| 209 | res = errno; |
bart | 651f56b | 2011-07-26 19:30:28 +0000 | [diff] [blame] | 210 | #endif |
bart | ce1d688 | 2012-01-23 17:01:58 +0000 | [diff] [blame] | 211 | /* |
| 212 | * Invoke sched_yield() on non-Linux systems, if the futex syscall has |
| 213 | * not been invoked or if this code has been built on a Linux system |
| 214 | * where __NR_futex is defined and is run on a Linux system that does |
| 215 | * not support the futex syscall. |
| 216 | */ |
| 217 | if (res != 0 && res != EWOULDBLOCK) |
| 218 | sched_yield(); |
| 219 | pthread_mutex_lock(&sema->mutex); |
| 220 | } |
| 221 | sema->waiters--; |
bart | 651f56b | 2011-07-26 19:30:28 +0000 | [diff] [blame] | 222 | } |
| 223 | sema->counter--; |
bart | e528697 | 2012-01-19 19:52:15 +0000 | [diff] [blame] | 224 | pthread_mutex_unlock(&sema->mutex); |
bart | 651f56b | 2011-07-26 19:30:28 +0000 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | static void DRD_(sema_up)(DrdSema* sema) |
| 228 | { |
bart | e528697 | 2012-01-19 19:52:15 +0000 | [diff] [blame] | 229 | pthread_mutex_lock(&sema->mutex); |
bart | 651f56b | 2011-07-26 19:30:28 +0000 | [diff] [blame] | 230 | sema->counter++; |
bart | 818f17e | 2011-09-17 06:24:49 +0000 | [diff] [blame] | 231 | #ifdef HAVE_USABLE_LINUX_FUTEX_H |
bart | ce1d688 | 2012-01-23 17:01:58 +0000 | [diff] [blame] | 232 | if (sema->waiters > 0) |
| 233 | syscall(__NR_futex, (UWord)&sema->counter, |
| 234 | FUTEX_WAKE | FUTEX_PRIVATE_FLAG, 1); |
bart | 651f56b | 2011-07-26 19:30:28 +0000 | [diff] [blame] | 235 | #endif |
bart | e528697 | 2012-01-19 19:52:15 +0000 | [diff] [blame] | 236 | pthread_mutex_unlock(&sema->mutex); |
bart | 651f56b | 2011-07-26 19:30:28 +0000 | [diff] [blame] | 237 | } |
| 238 | |
bart | 227c659 | 2009-02-14 12:12:57 +0000 | [diff] [blame] | 239 | /** |
| 240 | * POSIX threads and DRD each have their own mutex type identification. |
| 241 | * Convert POSIX threads' mutex type to DRD's mutex type. In the code below |
| 242 | * if-statements are used to test the value of 'kind' instead of a switch |
| 243 | * statement because some of the PTHREAD_MUTEX_ macro's may have the same |
| 244 | * value. |
| 245 | */ |
| 246 | static MutexT DRD_(pthread_to_drd_mutex_type)(const int kind) |
bart | 5357fcb | 2008-02-27 15:46:00 +0000 | [diff] [blame] | 247 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 248 | if (kind == PTHREAD_MUTEX_RECURSIVE) |
| 249 | return mutex_type_recursive_mutex; |
| 250 | else if (kind == PTHREAD_MUTEX_ERRORCHECK) |
| 251 | return mutex_type_errorcheck_mutex; |
| 252 | else if (kind == PTHREAD_MUTEX_NORMAL) |
| 253 | return mutex_type_default_mutex; |
| 254 | else if (kind == PTHREAD_MUTEX_DEFAULT) |
| 255 | return mutex_type_default_mutex; |
bart | 227c659 | 2009-02-14 12:12:57 +0000 | [diff] [blame] | 256 | #if defined(HAVE_PTHREAD_MUTEX_ADAPTIVE_NP) |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 257 | else if (kind == PTHREAD_MUTEX_ADAPTIVE_NP) |
| 258 | return mutex_type_default_mutex; |
bart | 227c659 | 2009-02-14 12:12:57 +0000 | [diff] [blame] | 259 | #endif |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 260 | else |
| 261 | { |
| 262 | return mutex_type_invalid_mutex; |
| 263 | } |
bart | 5357fcb | 2008-02-27 15:46:00 +0000 | [diff] [blame] | 264 | } |
| 265 | |
bart | 33f76c1 | 2010-09-19 11:14:31 +0000 | [diff] [blame] | 266 | #define IS_ALIGNED(p) (((uintptr_t)(p) & (sizeof(*(p)) - 1)) == 0) |
| 267 | |
bart | 227c659 | 2009-02-14 12:12:57 +0000 | [diff] [blame] | 268 | /** |
| 269 | * Read the mutex type stored in the client memory used for the mutex |
| 270 | * implementation. |
| 271 | * |
| 272 | * @note This function depends on the implementation of the POSIX threads |
| 273 | * library -- the POSIX standard does not define the name of the member in |
| 274 | * which the mutex type is stored. |
| 275 | * @note The function mutex_type() has been declared inline in order |
| 276 | * to avoid that it shows up in call stacks (drd/tests/...exp* files). |
bart | 489de21 | 2009-03-13 17:32:52 +0000 | [diff] [blame] | 277 | * @note glibc stores the mutex type in the lowest two bits, and uses the |
| 278 | * higher bits for flags like PTHREAD_MUTEXATTR_FLAG_ROBUST and |
| 279 | * PTHREAD_MUTEXATTR_FLAG_PSHARED. |
bart | 2bc9c10 | 2008-09-27 12:40:57 +0000 | [diff] [blame] | 280 | */ |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 281 | static __always_inline MutexT DRD_(mutex_type)(pthread_mutex_t* mutex) |
bart | 5357fcb | 2008-02-27 15:46:00 +0000 | [diff] [blame] | 282 | { |
bart | 5e389f1 | 2008-04-05 12:53:15 +0000 | [diff] [blame] | 283 | #if defined(HAVE_PTHREAD_MUTEX_T__M_KIND) |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 284 | /* glibc + LinuxThreads. */ |
bart | 33f76c1 | 2010-09-19 11:14:31 +0000 | [diff] [blame] | 285 | if (IS_ALIGNED(&mutex->__m_kind)) |
| 286 | { |
| 287 | const int kind = mutex->__m_kind & 3; |
| 288 | return DRD_(pthread_to_drd_mutex_type)(kind); |
| 289 | } |
bart | 5e389f1 | 2008-04-05 12:53:15 +0000 | [diff] [blame] | 290 | #elif defined(HAVE_PTHREAD_MUTEX_T__DATA__KIND) |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 291 | /* glibc + NPTL. */ |
bart | 33f76c1 | 2010-09-19 11:14:31 +0000 | [diff] [blame] | 292 | if (IS_ALIGNED(&mutex->__data.__kind)) |
| 293 | { |
| 294 | const int kind = mutex->__data.__kind & 3; |
| 295 | return DRD_(pthread_to_drd_mutex_type)(kind); |
| 296 | } |
bart | adb7a20 | 2009-07-21 12:39:25 +0000 | [diff] [blame] | 297 | #else |
| 298 | /* |
| 299 | * Another POSIX threads implementation. The mutex type won't be printed |
| 300 | * when enabling --trace-mutex=yes. |
| 301 | */ |
bart | adb7a20 | 2009-07-21 12:39:25 +0000 | [diff] [blame] | 302 | #endif |
bart | 33f76c1 | 2010-09-19 11:14:31 +0000 | [diff] [blame] | 303 | return mutex_type_unknown; |
bart | 5357fcb | 2008-02-27 15:46:00 +0000 | [diff] [blame] | 304 | } |
| 305 | |
bart | 227c659 | 2009-02-14 12:12:57 +0000 | [diff] [blame] | 306 | /** |
| 307 | * Tell DRD whether 'tid' is a joinable thread or a detached thread. |
| 308 | */ |
| 309 | static void DRD_(set_joinable)(const pthread_t tid, const int joinable) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 310 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 311 | assert(joinable == 0 || joinable == 1); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 312 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__SET_JOINABLE, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 313 | tid, joinable, 0, 0, 0); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 314 | } |
| 315 | |
bart | dd75cdf | 2009-07-24 08:20:10 +0000 | [diff] [blame] | 316 | /** Tell DRD that the calling thread is about to enter pthread_create(). */ |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 317 | static __always_inline void DRD_(entering_pthread_create)(void) |
bart | dd75cdf | 2009-07-24 08:20:10 +0000 | [diff] [blame] | 318 | { |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 319 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__ENTERING_PTHREAD_CREATE, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 320 | 0, 0, 0, 0, 0); |
bart | dd75cdf | 2009-07-24 08:20:10 +0000 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | /** Tell DRD that the calling thread has left pthread_create(). */ |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 324 | static __always_inline void DRD_(left_pthread_create)(void) |
bart | dd75cdf | 2009-07-24 08:20:10 +0000 | [diff] [blame] | 325 | { |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 326 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__LEFT_PTHREAD_CREATE, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 327 | 0, 0, 0, 0, 0); |
bart | dd75cdf | 2009-07-24 08:20:10 +0000 | [diff] [blame] | 328 | } |
| 329 | |
bart | 227c659 | 2009-02-14 12:12:57 +0000 | [diff] [blame] | 330 | /** |
bart | dd75cdf | 2009-07-24 08:20:10 +0000 | [diff] [blame] | 331 | * Entry point for newly created threads. This function is called from the |
| 332 | * thread created by pthread_create(). |
bart | 227c659 | 2009-02-14 12:12:57 +0000 | [diff] [blame] | 333 | */ |
bart | 292c1e2 | 2009-02-14 11:54:42 +0000 | [diff] [blame] | 334 | static void* DRD_(thread_wrapper)(void* arg) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 335 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 336 | DrdPosixThreadArgs* arg_ptr; |
| 337 | DrdPosixThreadArgs arg_copy; |
bart | 0d06300 | 2008-03-01 07:25:13 +0000 | [diff] [blame] | 338 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 339 | arg_ptr = (DrdPosixThreadArgs*)arg; |
| 340 | arg_copy = *arg_ptr; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 341 | |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 342 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__SET_PTHREADID, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 343 | pthread_self(), 0, 0, 0, 0); |
bart | 227c659 | 2009-02-14 12:12:57 +0000 | [diff] [blame] | 344 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 345 | DRD_(set_joinable)(pthread_self(), |
| 346 | arg_copy.detachstate == PTHREAD_CREATE_JOINABLE); |
bart | 227c659 | 2009-02-14 12:12:57 +0000 | [diff] [blame] | 347 | |
bart | 8244b86 | 2011-03-08 18:34:44 +0000 | [diff] [blame] | 348 | /* |
| 349 | * Only set 'wrapper_started' after VG_USERREQ__SET_PTHREADID and |
| 350 | * DRD_(set_joinable)() have been invoked to avoid a race with |
| 351 | * a pthread_detach() invocation for this thread from another thread. |
| 352 | */ |
bart | e57a9e2 | 2012-01-24 08:30:32 +0000 | [diff] [blame] | 353 | DRD_(sema_up)(arg_copy.wrapper_started); |
bart | 8244b86 | 2011-03-08 18:34:44 +0000 | [diff] [blame] | 354 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 355 | return (arg_copy.start)(arg_copy.arg); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 356 | } |
| 357 | |
bart | 227c659 | 2009-02-14 12:12:57 +0000 | [diff] [blame] | 358 | /** |
bart | d2c5eae | 2009-02-21 15:27:04 +0000 | [diff] [blame] | 359 | * Return 1 if the LinuxThreads implementation of POSIX Threads has been |
| 360 | * detected, and 0 otherwise. |
| 361 | * |
| 362 | * @see For more information about the confstr() function, see also |
bart | 227c659 | 2009-02-14 12:12:57 +0000 | [diff] [blame] | 363 | * http://www.opengroup.org/onlinepubs/009695399/functions/confstr.html |
| 364 | */ |
| 365 | static int DRD_(detected_linuxthreads)(void) |
bart | 4501d5c | 2008-03-04 18:36:23 +0000 | [diff] [blame] | 366 | { |
| 367 | #if defined(linux) |
| 368 | #if defined(_CS_GNU_LIBPTHREAD_VERSION) |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 369 | /* Linux with a recent glibc. */ |
| 370 | char buffer[256]; |
| 371 | unsigned len; |
| 372 | len = confstr(_CS_GNU_LIBPTHREAD_VERSION, buffer, sizeof(buffer)); |
| 373 | assert(len <= sizeof(buffer)); |
| 374 | return len > 0 && buffer[0] == 'l'; |
bart | 4501d5c | 2008-03-04 18:36:23 +0000 | [diff] [blame] | 375 | #else |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 376 | /* Linux without _CS_GNU_LIBPTHREAD_VERSION: most likely LinuxThreads. */ |
| 377 | return 1; |
bart | 4501d5c | 2008-03-04 18:36:23 +0000 | [diff] [blame] | 378 | #endif |
| 379 | #else |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 380 | /* Another OS than Linux, hence no LinuxThreads. */ |
| 381 | return 0; |
bart | 4501d5c | 2008-03-04 18:36:23 +0000 | [diff] [blame] | 382 | #endif |
| 383 | } |
| 384 | |
bart | 227c659 | 2009-02-14 12:12:57 +0000 | [diff] [blame] | 385 | /** |
| 386 | * Stop and print an error message in case a non-supported threading |
| 387 | * library implementation (LinuxThreads) has been detected. |
bart | 6f07b25 | 2008-04-04 16:45:20 +0000 | [diff] [blame] | 388 | */ |
bart | 227c659 | 2009-02-14 12:12:57 +0000 | [diff] [blame] | 389 | static void DRD_(check_threading_library)(void) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 390 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 391 | if (DRD_(detected_linuxthreads)()) |
| 392 | { |
| 393 | if (getenv("LD_ASSUME_KERNEL")) |
| 394 | { |
| 395 | fprintf(stderr, |
bart | 227c659 | 2009-02-14 12:12:57 +0000 | [diff] [blame] | 396 | "Detected the LinuxThreads threading library. Sorry, but DRD only supports\n" |
| 397 | "the newer NPTL (Native POSIX Threads Library). Please try to rerun DRD\n" |
| 398 | "after having unset the environment variable LD_ASSUME_KERNEL. Giving up.\n" |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 399 | ); |
| 400 | } |
| 401 | else |
| 402 | { |
| 403 | fprintf(stderr, |
bart | 227c659 | 2009-02-14 12:12:57 +0000 | [diff] [blame] | 404 | "Detected the LinuxThreads threading library. Sorry, but DRD only supports\n" |
| 405 | "the newer NPTL (Native POSIX Threads Library). Please try to rerun DRD\n" |
| 406 | "after having upgraded to a newer version of your Linux distribution.\n" |
| 407 | "Giving up.\n" |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 408 | ); |
| 409 | } |
| 410 | abort(); |
| 411 | } |
bart | 6f07b25 | 2008-04-04 16:45:20 +0000 | [diff] [blame] | 412 | } |
| 413 | |
bart | 227c659 | 2009-02-14 12:12:57 +0000 | [diff] [blame] | 414 | /** |
| 415 | * The main thread is the only thread not created by pthread_create(). |
| 416 | * Update DRD's state information about the main thread. |
| 417 | */ |
| 418 | static void DRD_(set_main_thread_state)(void) |
bart | 6f07b25 | 2008-04-04 16:45:20 +0000 | [diff] [blame] | 419 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 420 | // Make sure that DRD knows about the main thread's POSIX thread ID. |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 421 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__SET_PTHREADID, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 422 | pthread_self(), 0, 0, 0, 0); |
bart | 850f199 | 2010-05-29 18:43:21 +0000 | [diff] [blame] | 423 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 424 | |
bart | c39d109 | 2009-04-22 18:59:50 +0000 | [diff] [blame] | 425 | /* |
bart | dd75cdf | 2009-07-24 08:20:10 +0000 | [diff] [blame] | 426 | * Note: as of today there exist three different versions of pthread_create |
| 427 | * in Linux: |
bart | c39d109 | 2009-04-22 18:59:50 +0000 | [diff] [blame] | 428 | * - pthread_create@GLIBC_2.0 |
| 429 | * - pthread_create@@GLIBC_2.1 |
| 430 | * - pthread_create@@GLIBC_2.2.5 |
| 431 | * As an example, in libpthread-2.3.4 both pthread_create@GLIBC_2.0 and |
| 432 | * pthread_create@@GLIBC_2.1 are defined, while in libpthread-2.9 all three |
| 433 | * versions have been implemented. In any glibc version where more than one |
| 434 | * pthread_create function has been implemented, older versions call the |
| 435 | * newer versions. Or: the pthread_create* wrapper defined below can be |
| 436 | * called recursively. Any code in this wrapper should take this in account. |
| 437 | * As an example, it is not safe to invoke the DRD_STOP_RECORDING |
| 438 | * / DRD_START_RECORDING client requests from the pthread_create wrapper. |
| 439 | * See also the implementation of pthread_create@GLIBC_2.0 in |
| 440 | * glibc-2.9/nptl/pthread_create.c. |
| 441 | */ |
| 442 | |
bart | b2260b8 | 2011-02-13 07:55:36 +0000 | [diff] [blame] | 443 | static __always_inline |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 444 | int pthread_create_intercept(pthread_t* thread, const pthread_attr_t* attr, |
| 445 | void* (*start)(void*), void* arg) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 446 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 447 | int ret; |
| 448 | OrigFn fn; |
bart | e57a9e2 | 2012-01-24 08:30:32 +0000 | [diff] [blame] | 449 | DrdSema wrapper_started; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 450 | DrdPosixThreadArgs thread_args; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 451 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 452 | VALGRIND_GET_ORIG_FN(fn); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 453 | |
bart | e57a9e2 | 2012-01-24 08:30:32 +0000 | [diff] [blame] | 454 | DRD_(sema_init)(&wrapper_started); |
bart | b957ab8 | 2011-03-12 11:01:06 +0000 | [diff] [blame] | 455 | thread_args.start = start; |
| 456 | thread_args.arg = arg; |
bart | e57a9e2 | 2012-01-24 08:30:32 +0000 | [diff] [blame] | 457 | thread_args.wrapper_started = &wrapper_started; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 458 | /* |
| 459 | * Find out whether the thread will be started as a joinable thread |
| 460 | * or as a detached thread. If no thread attributes have been specified, |
| 461 | * this means that the new thread will be started as a joinable thread. |
| 462 | */ |
bart | b957ab8 | 2011-03-12 11:01:06 +0000 | [diff] [blame] | 463 | thread_args.detachstate = PTHREAD_CREATE_JOINABLE; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 464 | if (attr) |
| 465 | { |
bart | b957ab8 | 2011-03-12 11:01:06 +0000 | [diff] [blame] | 466 | if (pthread_attr_getdetachstate(attr, &thread_args.detachstate) != 0) |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 467 | assert(0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 468 | } |
bart | b957ab8 | 2011-03-12 11:01:06 +0000 | [diff] [blame] | 469 | assert(thread_args.detachstate == PTHREAD_CREATE_JOINABLE |
| 470 | || thread_args.detachstate == PTHREAD_CREATE_DETACHED); |
bart | dd75cdf | 2009-07-24 08:20:10 +0000 | [diff] [blame] | 471 | |
| 472 | DRD_(entering_pthread_create)(); |
bart | b957ab8 | 2011-03-12 11:01:06 +0000 | [diff] [blame] | 473 | CALL_FN_W_WWWW(ret, fn, thread, attr, DRD_(thread_wrapper), &thread_args); |
bart | dd75cdf | 2009-07-24 08:20:10 +0000 | [diff] [blame] | 474 | DRD_(left_pthread_create)(); |
bart | 227c659 | 2009-02-14 12:12:57 +0000 | [diff] [blame] | 475 | |
bart | e57a9e2 | 2012-01-24 08:30:32 +0000 | [diff] [blame] | 476 | if (ret == 0) { |
bart | e476e92 | 2011-03-08 18:32:36 +0000 | [diff] [blame] | 477 | /* Wait until the thread wrapper started. */ |
bart | e57a9e2 | 2012-01-24 08:30:32 +0000 | [diff] [blame] | 478 | DRD_(sema_down)(&wrapper_started); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 479 | } |
bart | 227c659 | 2009-02-14 12:12:57 +0000 | [diff] [blame] | 480 | |
bart | e57a9e2 | 2012-01-24 08:30:32 +0000 | [diff] [blame] | 481 | DRD_(sema_destroy)(&wrapper_started); |
bart | 651f56b | 2011-07-26 19:30:28 +0000 | [diff] [blame] | 482 | |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 483 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_START_NEW_SEGMENT, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 484 | pthread_self(), 0, 0, 0, 0); |
bart | a0b7222 | 2009-03-12 18:39:31 +0000 | [diff] [blame] | 485 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 486 | return ret; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 487 | } |
| 488 | |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 489 | PTH_FUNCS(int, pthreadZucreate, pthread_create_intercept, |
| 490 | (pthread_t *thread, const pthread_attr_t *attr, |
| 491 | void *(*start) (void *), void *arg), |
| 492 | (thread, attr, start, arg)); |
| 493 | |
bart | b2260b8 | 2011-02-13 07:55:36 +0000 | [diff] [blame] | 494 | static __always_inline |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 495 | int pthread_join_intercept(pthread_t pt_joinee, void **thread_return) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 496 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 497 | int ret; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 498 | OrigFn fn; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 499 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 500 | VALGRIND_GET_ORIG_FN(fn); |
bart | 5cbd26e | 2011-08-24 15:02:21 +0000 | [diff] [blame] | 501 | /* |
| 502 | * Avoid that the sys_futex(td->tid) call invoked by the NPTL pthread_join() |
| 503 | * implementation triggers a (false positive) race report. |
| 504 | */ |
| 505 | ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN(); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 506 | CALL_FN_W_WW(ret, fn, pt_joinee, thread_return); |
| 507 | if (ret == 0) |
| 508 | { |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 509 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__POST_THREAD_JOIN, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 510 | pt_joinee, 0, 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 511 | } |
bart | 5cbd26e | 2011-08-24 15:02:21 +0000 | [diff] [blame] | 512 | ANNOTATE_IGNORE_READS_AND_WRITES_END(); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 513 | return ret; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 514 | } |
| 515 | |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 516 | PTH_FUNCS(int, pthreadZujoin, pthread_join_intercept, |
| 517 | (pthread_t pt_joinee, void **thread_return), |
| 518 | (pt_joinee, thread_return)); |
| 519 | |
bart | b2260b8 | 2011-02-13 07:55:36 +0000 | [diff] [blame] | 520 | static __always_inline |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 521 | int pthread_detach_intercept(pthread_t pt_thread) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 522 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 523 | int ret; |
| 524 | OrigFn fn; |
bart | 5668d4e | 2011-03-09 17:53:28 +0000 | [diff] [blame] | 525 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 526 | VALGRIND_GET_ORIG_FN(fn); |
bart | 5668d4e | 2011-03-09 17:53:28 +0000 | [diff] [blame] | 527 | CALL_FN_W_W(ret, fn, pt_thread); |
| 528 | DRD_(set_joinable)(pt_thread, 0); |
| 529 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 530 | return ret; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 531 | } |
| 532 | |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 533 | PTH_FUNCS(int, pthreadZudetach, pthread_detach_intercept, |
| 534 | (pthread_t thread), (thread)); |
| 535 | |
| 536 | // NOTE: be careful to intercept only pthread_cancel() and not |
| 537 | // pthread_cancel_init() on Linux. |
| 538 | |
bart | b2260b8 | 2011-02-13 07:55:36 +0000 | [diff] [blame] | 539 | static __always_inline |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 540 | int pthread_cancel_intercept(pthread_t pt_thread) |
bart | 2bc9c10 | 2008-09-27 12:40:57 +0000 | [diff] [blame] | 541 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 542 | int ret; |
| 543 | OrigFn fn; |
| 544 | VALGRIND_GET_ORIG_FN(fn); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 545 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PRE_THREAD_CANCEL, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 546 | pt_thread, 0, 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 547 | CALL_FN_W_W(ret, fn, pt_thread); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 548 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__POST_THREAD_CANCEL, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 549 | pt_thread, ret==0, 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 550 | return ret; |
bart | 2bc9c10 | 2008-09-27 12:40:57 +0000 | [diff] [blame] | 551 | } |
| 552 | |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 553 | PTH_FUNCS(int, pthreadZucancel, pthread_cancel_intercept, |
| 554 | (pthread_t thread), (thread)) |
| 555 | |
bart | b2260b8 | 2011-02-13 07:55:36 +0000 | [diff] [blame] | 556 | static __always_inline |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 557 | int pthread_once_intercept(pthread_once_t *once_control, |
| 558 | void (*init_routine)(void)) |
bart | 93a0274 | 2009-07-26 15:55:48 +0000 | [diff] [blame] | 559 | { |
| 560 | int ret; |
| 561 | OrigFn fn; |
| 562 | VALGRIND_GET_ORIG_FN(fn); |
| 563 | /* |
| 564 | * Ignore any data races triggered by the implementation of pthread_once(). |
| 565 | * Necessary for Darwin. This is not necessary for Linux but doesn't have |
| 566 | * any known adverse effects. |
| 567 | */ |
bart | 554953f | 2009-07-26 16:21:00 +0000 | [diff] [blame] | 568 | DRD_IGNORE_VAR(*once_control); |
bart | 6d956dc | 2011-07-28 09:54:37 +0000 | [diff] [blame] | 569 | ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN(); |
bart | 93a0274 | 2009-07-26 15:55:48 +0000 | [diff] [blame] | 570 | CALL_FN_W_WW(ret, fn, once_control, init_routine); |
bart | 6d956dc | 2011-07-28 09:54:37 +0000 | [diff] [blame] | 571 | ANNOTATE_IGNORE_READS_AND_WRITES_END(); |
bart | 554953f | 2009-07-26 16:21:00 +0000 | [diff] [blame] | 572 | DRD_STOP_IGNORING_VAR(*once_control); |
bart | 93a0274 | 2009-07-26 15:55:48 +0000 | [diff] [blame] | 573 | return ret; |
| 574 | } |
| 575 | |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 576 | PTH_FUNCS(int, pthreadZuonce, pthread_once_intercept, |
| 577 | (pthread_once_t *once_control, void (*init_routine)(void)), |
| 578 | (once_control, init_routine)); |
| 579 | |
bart | b2260b8 | 2011-02-13 07:55:36 +0000 | [diff] [blame] | 580 | static __always_inline |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 581 | int pthread_mutex_init_intercept(pthread_mutex_t *mutex, |
| 582 | const pthread_mutexattr_t* attr) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 583 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 584 | int ret; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 585 | OrigFn fn; |
| 586 | int mt; |
| 587 | VALGRIND_GET_ORIG_FN(fn); |
| 588 | mt = PTHREAD_MUTEX_DEFAULT; |
| 589 | if (attr) |
| 590 | pthread_mutexattr_gettype(attr, &mt); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 591 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PRE_MUTEX_INIT, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 592 | mutex, DRD_(pthread_to_drd_mutex_type)(mt), |
| 593 | 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 594 | CALL_FN_W_WW(ret, fn, mutex, attr); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 595 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__POST_MUTEX_INIT, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 596 | mutex, 0, 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 597 | return ret; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 598 | } |
| 599 | |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 600 | PTH_FUNCS(int, pthreadZumutexZuinit, pthread_mutex_init_intercept, |
| 601 | (pthread_mutex_t *mutex, const pthread_mutexattr_t* attr), |
| 602 | (mutex, attr)); |
| 603 | |
bart | b2260b8 | 2011-02-13 07:55:36 +0000 | [diff] [blame] | 604 | static __always_inline |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 605 | int pthread_mutex_destroy_intercept(pthread_mutex_t* mutex) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 606 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 607 | int ret; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 608 | OrigFn fn; |
| 609 | VALGRIND_GET_ORIG_FN(fn); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 610 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PRE_MUTEX_DESTROY, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 611 | mutex, 0, 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 612 | CALL_FN_W_W(ret, fn, mutex); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 613 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__POST_MUTEX_DESTROY, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 614 | mutex, DRD_(mutex_type)(mutex), 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 615 | return ret; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 616 | } |
| 617 | |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 618 | PTH_FUNCS(int, pthreadZumutexZudestroy, pthread_mutex_destroy_intercept, |
| 619 | (pthread_mutex_t *mutex), (mutex)); |
| 620 | |
bart | b2260b8 | 2011-02-13 07:55:36 +0000 | [diff] [blame] | 621 | static __always_inline |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 622 | int pthread_mutex_lock_intercept(pthread_mutex_t* mutex) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 623 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 624 | int ret; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 625 | OrigFn fn; |
| 626 | VALGRIND_GET_ORIG_FN(fn); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 627 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PRE_MUTEX_LOCK, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 628 | mutex, DRD_(mutex_type)(mutex), 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 629 | CALL_FN_W_W(ret, fn, mutex); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 630 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__POST_MUTEX_LOCK, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 631 | mutex, ret == 0, 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 632 | return ret; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 633 | } |
| 634 | |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 635 | PTH_FUNCS(int, pthreadZumutexZulock, pthread_mutex_lock_intercept, |
| 636 | (pthread_mutex_t *mutex), (mutex)); |
| 637 | |
bart | b2260b8 | 2011-02-13 07:55:36 +0000 | [diff] [blame] | 638 | static __always_inline |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 639 | int pthread_mutex_trylock_intercept(pthread_mutex_t* mutex) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 640 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 641 | int ret; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 642 | OrigFn fn; |
| 643 | VALGRIND_GET_ORIG_FN(fn); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 644 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PRE_MUTEX_LOCK, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 645 | mutex, DRD_(mutex_type)(mutex), 1, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 646 | CALL_FN_W_W(ret, fn, mutex); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 647 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__POST_MUTEX_LOCK, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 648 | mutex, ret == 0, 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 649 | return ret; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 650 | } |
| 651 | |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 652 | PTH_FUNCS(int, pthreadZumutexZutrylock, pthread_mutex_trylock_intercept, |
| 653 | (pthread_mutex_t *mutex), (mutex)); |
| 654 | |
bart | b2260b8 | 2011-02-13 07:55:36 +0000 | [diff] [blame] | 655 | static __always_inline |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 656 | int pthread_mutex_timedlock_intercept(pthread_mutex_t *mutex, |
| 657 | const struct timespec *abs_timeout) |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 658 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 659 | int ret; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 660 | OrigFn fn; |
| 661 | VALGRIND_GET_ORIG_FN(fn); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 662 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PRE_MUTEX_LOCK, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 663 | mutex, DRD_(mutex_type)(mutex), 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 664 | CALL_FN_W_WW(ret, fn, mutex, abs_timeout); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 665 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__POST_MUTEX_LOCK, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 666 | mutex, ret == 0, 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 667 | return ret; |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 668 | } |
| 669 | |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 670 | PTH_FUNCS(int, pthreadZumutexZutimedlock, pthread_mutex_timedlock_intercept, |
| 671 | (pthread_mutex_t *mutex, const struct timespec *abs_timeout), |
| 672 | (mutex, abs_timeout)); |
| 673 | |
bart | b2260b8 | 2011-02-13 07:55:36 +0000 | [diff] [blame] | 674 | static __always_inline |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 675 | int pthread_mutex_unlock_intercept(pthread_mutex_t *mutex) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 676 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 677 | int ret; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 678 | OrigFn fn; |
| 679 | VALGRIND_GET_ORIG_FN(fn); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 680 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PRE_MUTEX_UNLOCK, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 681 | mutex, DRD_(mutex_type)(mutex), 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 682 | CALL_FN_W_W(ret, fn, mutex); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 683 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__POST_MUTEX_UNLOCK, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 684 | mutex, 0, 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 685 | return ret; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 686 | } |
| 687 | |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 688 | PTH_FUNCS(int, pthreadZumutexZuunlock, pthread_mutex_unlock_intercept, |
| 689 | (pthread_mutex_t *mutex), (mutex)); |
| 690 | |
bart | b2260b8 | 2011-02-13 07:55:36 +0000 | [diff] [blame] | 691 | static __always_inline |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 692 | int pthread_cond_init_intercept(pthread_cond_t* cond, |
| 693 | const pthread_condattr_t* attr) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 694 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 695 | int ret; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 696 | OrigFn fn; |
| 697 | VALGRIND_GET_ORIG_FN(fn); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 698 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PRE_COND_INIT, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 699 | cond, 0, 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 700 | CALL_FN_W_WW(ret, fn, cond, attr); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 701 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__POST_COND_INIT, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 702 | cond, 0, 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 703 | return ret; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 704 | } |
| 705 | |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 706 | PTH_FUNCS(int, pthreadZucondZuinit, pthread_cond_init_intercept, |
| 707 | (pthread_cond_t* cond, const pthread_condattr_t* attr), |
| 708 | (cond, attr)); |
| 709 | |
bart | b2260b8 | 2011-02-13 07:55:36 +0000 | [diff] [blame] | 710 | static __always_inline |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 711 | int pthread_cond_destroy_intercept(pthread_cond_t* cond) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 712 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 713 | int ret; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 714 | OrigFn fn; |
| 715 | VALGRIND_GET_ORIG_FN(fn); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 716 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PRE_COND_DESTROY, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 717 | cond, 0, 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 718 | CALL_FN_W_W(ret, fn, cond); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 719 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__POST_COND_DESTROY, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 720 | cond, 0, 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 721 | return ret; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 722 | } |
| 723 | |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 724 | PTH_FUNCS(int, pthreadZucondZudestroy, pthread_cond_destroy_intercept, |
| 725 | (pthread_cond_t* cond), (cond)); |
| 726 | |
bart | b2260b8 | 2011-02-13 07:55:36 +0000 | [diff] [blame] | 727 | static __always_inline |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 728 | int pthread_cond_wait_intercept(pthread_cond_t *cond, pthread_mutex_t *mutex) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 729 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 730 | int ret; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 731 | OrigFn fn; |
| 732 | VALGRIND_GET_ORIG_FN(fn); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 733 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PRE_COND_WAIT, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 734 | cond, mutex, DRD_(mutex_type)(mutex), 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 735 | CALL_FN_W_WW(ret, fn, cond, mutex); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 736 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__POST_COND_WAIT, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 737 | cond, mutex, 1, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 738 | return ret; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 739 | } |
| 740 | |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 741 | PTH_FUNCS(int, pthreadZucondZuwait, pthread_cond_wait_intercept, |
| 742 | (pthread_cond_t *cond, pthread_mutex_t *mutex), |
| 743 | (cond, mutex)); |
| 744 | |
bart | b2260b8 | 2011-02-13 07:55:36 +0000 | [diff] [blame] | 745 | static __always_inline |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 746 | int pthread_cond_timedwait_intercept(pthread_cond_t *cond, |
| 747 | pthread_mutex_t *mutex, |
| 748 | const struct timespec* abstime) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 749 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 750 | int ret; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 751 | OrigFn fn; |
| 752 | VALGRIND_GET_ORIG_FN(fn); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 753 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PRE_COND_WAIT, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 754 | cond, mutex, DRD_(mutex_type)(mutex), 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 755 | CALL_FN_W_WWW(ret, fn, cond, mutex, abstime); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 756 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__POST_COND_WAIT, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 757 | cond, mutex, 1, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 758 | return ret; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 759 | } |
| 760 | |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 761 | PTH_FUNCS(int, pthreadZucondZutimedwait, pthread_cond_timedwait_intercept, |
| 762 | (pthread_cond_t *cond, pthread_mutex_t *mutex, |
| 763 | const struct timespec* abstime), |
| 764 | (cond, mutex, abstime)); |
| 765 | |
bart | e8cbb40 | 2009-07-22 19:17:05 +0000 | [diff] [blame] | 766 | // NOTE: be careful to intercept only pthread_cond_signal() and not Darwin's |
| 767 | // pthread_cond_signal_thread_np(). The former accepts one argument; the latter |
| 768 | // two. Intercepting all pthread_cond_signal* functions will cause only one |
| 769 | // argument to be passed to pthread_cond_signal_np() and hence will cause this |
| 770 | // last function to crash. |
| 771 | |
bart | b2260b8 | 2011-02-13 07:55:36 +0000 | [diff] [blame] | 772 | static __always_inline |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 773 | int pthread_cond_signal_intercept(pthread_cond_t* cond) |
bart | e8cbb40 | 2009-07-22 19:17:05 +0000 | [diff] [blame] | 774 | { |
| 775 | int ret; |
bart | e8cbb40 | 2009-07-22 19:17:05 +0000 | [diff] [blame] | 776 | OrigFn fn; |
| 777 | VALGRIND_GET_ORIG_FN(fn); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 778 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PRE_COND_SIGNAL, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 779 | cond, 0, 0, 0, 0); |
bart | e8cbb40 | 2009-07-22 19:17:05 +0000 | [diff] [blame] | 780 | CALL_FN_W_W(ret, fn, cond); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 781 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__POST_COND_SIGNAL, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 782 | cond, 0, 0, 0, 0); |
bart | e8cbb40 | 2009-07-22 19:17:05 +0000 | [diff] [blame] | 783 | return ret; |
| 784 | } |
| 785 | |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 786 | PTH_FUNCS(int, pthreadZucondZusignal, pthread_cond_signal_intercept, |
| 787 | (pthread_cond_t* cond), (cond)); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 788 | |
bart | b2260b8 | 2011-02-13 07:55:36 +0000 | [diff] [blame] | 789 | static __always_inline |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 790 | int pthread_cond_broadcast_intercept(pthread_cond_t* cond) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 791 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 792 | int ret; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 793 | OrigFn fn; |
| 794 | VALGRIND_GET_ORIG_FN(fn); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 795 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PRE_COND_BROADCAST, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 796 | cond, 0, 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 797 | CALL_FN_W_W(ret, fn, cond); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 798 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__POST_COND_BROADCAST, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 799 | cond, 0, 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 800 | return ret; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 801 | } |
| 802 | |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 803 | PTH_FUNCS(int, pthreadZucondZubroadcast, pthread_cond_broadcast_intercept, |
| 804 | (pthread_cond_t* cond), (cond)); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 805 | |
njn | f76d27a | 2009-05-28 01:53:07 +0000 | [diff] [blame] | 806 | #if defined(HAVE_PTHREAD_SPIN_LOCK) |
bart | b2260b8 | 2011-02-13 07:55:36 +0000 | [diff] [blame] | 807 | static __always_inline |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 808 | int pthread_spin_init_intercept(pthread_spinlock_t *spinlock, int pshared) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 809 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 810 | int ret; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 811 | OrigFn fn; |
| 812 | VALGRIND_GET_ORIG_FN(fn); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 813 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PRE_SPIN_INIT_OR_UNLOCK, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 814 | spinlock, 0, 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 815 | CALL_FN_W_WW(ret, fn, spinlock, pshared); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 816 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__POST_SPIN_INIT_OR_UNLOCK, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 817 | spinlock, 0, 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 818 | return ret; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 819 | } |
| 820 | |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 821 | PTH_FUNCS(int, pthreadZuspinZuinit, pthread_spin_init_intercept, |
| 822 | (pthread_spinlock_t *spinlock, int pshared), (spinlock, pshared)); |
| 823 | |
bart | b2260b8 | 2011-02-13 07:55:36 +0000 | [diff] [blame] | 824 | static __always_inline |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 825 | int pthread_spin_destroy_intercept(pthread_spinlock_t *spinlock) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 826 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 827 | int ret; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 828 | OrigFn fn; |
| 829 | VALGRIND_GET_ORIG_FN(fn); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 830 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PRE_MUTEX_DESTROY, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 831 | spinlock, 0, 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 832 | CALL_FN_W_W(ret, fn, spinlock); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 833 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__POST_MUTEX_DESTROY, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 834 | spinlock, mutex_type_spinlock, 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 835 | return ret; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 836 | } |
| 837 | |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 838 | PTH_FUNCS(int, pthreadZuspinZudestroy, pthread_spin_destroy_intercept, |
| 839 | (pthread_spinlock_t *spinlock), (spinlock)); |
| 840 | |
bart | b2260b8 | 2011-02-13 07:55:36 +0000 | [diff] [blame] | 841 | static __always_inline |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 842 | int pthread_spin_lock_intercept(pthread_spinlock_t *spinlock) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 843 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 844 | int ret; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 845 | OrigFn fn; |
| 846 | VALGRIND_GET_ORIG_FN(fn); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 847 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PRE_MUTEX_LOCK, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 848 | spinlock, mutex_type_spinlock, 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 849 | CALL_FN_W_W(ret, fn, spinlock); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 850 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__POST_MUTEX_LOCK, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 851 | spinlock, ret == 0, 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 852 | return ret; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 853 | } |
| 854 | |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 855 | PTH_FUNCS(int, pthreadZuspinZulock, pthread_spin_lock_intercept, |
| 856 | (pthread_spinlock_t *spinlock), (spinlock)); |
| 857 | |
bart | b2260b8 | 2011-02-13 07:55:36 +0000 | [diff] [blame] | 858 | static __always_inline |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 859 | int pthread_spin_trylock_intercept(pthread_spinlock_t *spinlock) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 860 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 861 | int ret; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 862 | OrigFn fn; |
| 863 | VALGRIND_GET_ORIG_FN(fn); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 864 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PRE_MUTEX_LOCK, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 865 | spinlock, mutex_type_spinlock, 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 866 | CALL_FN_W_W(ret, fn, spinlock); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 867 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__POST_MUTEX_LOCK, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 868 | spinlock, ret == 0, 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 869 | return ret; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 870 | } |
| 871 | |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 872 | PTH_FUNCS(int, pthreadZuspinZutrylock, pthread_spin_trylock_intercept, |
| 873 | (pthread_spinlock_t *spinlock), (spinlock)); |
| 874 | |
bart | b2260b8 | 2011-02-13 07:55:36 +0000 | [diff] [blame] | 875 | static __always_inline |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 876 | int pthread_spin_unlock_intercept(pthread_spinlock_t *spinlock) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 877 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 878 | int ret; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 879 | OrigFn fn; |
| 880 | VALGRIND_GET_ORIG_FN(fn); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 881 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PRE_SPIN_INIT_OR_UNLOCK, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 882 | spinlock, mutex_type_spinlock, 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 883 | CALL_FN_W_W(ret, fn, spinlock); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 884 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__POST_SPIN_INIT_OR_UNLOCK, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 885 | spinlock, 0, 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 886 | return ret; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 887 | } |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 888 | |
| 889 | PTH_FUNCS(int, pthreadZuspinZuunlock, pthread_spin_unlock_intercept, |
| 890 | (pthread_spinlock_t *spinlock), (spinlock)); |
njn | f76d27a | 2009-05-28 01:53:07 +0000 | [diff] [blame] | 891 | #endif // HAVE_PTHREAD_SPIN_LOCK |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 892 | |
njn | f76d27a | 2009-05-28 01:53:07 +0000 | [diff] [blame] | 893 | |
| 894 | #if defined(HAVE_PTHREAD_BARRIER_INIT) |
bart | b2260b8 | 2011-02-13 07:55:36 +0000 | [diff] [blame] | 895 | static __always_inline |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 896 | int pthread_barrier_init_intercept(pthread_barrier_t* barrier, |
| 897 | const pthread_barrierattr_t* attr, |
| 898 | unsigned count) |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 899 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 900 | int ret; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 901 | OrigFn fn; |
| 902 | VALGRIND_GET_ORIG_FN(fn); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 903 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PRE_BARRIER_INIT, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 904 | barrier, pthread_barrier, count, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 905 | CALL_FN_W_WWW(ret, fn, barrier, attr, count); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 906 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__POST_BARRIER_INIT, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 907 | barrier, pthread_barrier, 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 908 | return ret; |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 909 | } |
| 910 | |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 911 | PTH_FUNCS(int, pthreadZubarrierZuinit, pthread_barrier_init_intercept, |
| 912 | (pthread_barrier_t* barrier, const pthread_barrierattr_t* attr, |
| 913 | unsigned count), (barrier, attr, count)); |
| 914 | |
bart | b2260b8 | 2011-02-13 07:55:36 +0000 | [diff] [blame] | 915 | static __always_inline |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 916 | int pthread_barrier_destroy_intercept(pthread_barrier_t* barrier) |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 917 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 918 | int ret; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 919 | OrigFn fn; |
| 920 | VALGRIND_GET_ORIG_FN(fn); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 921 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PRE_BARRIER_DESTROY, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 922 | barrier, pthread_barrier, 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 923 | CALL_FN_W_W(ret, fn, barrier); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 924 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__POST_BARRIER_DESTROY, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 925 | barrier, pthread_barrier, 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 926 | return ret; |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 927 | } |
| 928 | |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 929 | PTH_FUNCS(int, pthreadZubarrierZudestroy, pthread_barrier_destroy_intercept, |
| 930 | (pthread_barrier_t* barrier), (barrier)); |
| 931 | |
bart | b2260b8 | 2011-02-13 07:55:36 +0000 | [diff] [blame] | 932 | static __always_inline |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 933 | int pthread_barrier_wait_intercept(pthread_barrier_t* barrier) |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 934 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 935 | int ret; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 936 | OrigFn fn; |
| 937 | VALGRIND_GET_ORIG_FN(fn); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 938 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PRE_BARRIER_WAIT, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 939 | barrier, pthread_barrier, 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 940 | CALL_FN_W_W(ret, fn, barrier); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 941 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__POST_BARRIER_WAIT, |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 942 | barrier, pthread_barrier, |
| 943 | ret == 0 || ret == PTHREAD_BARRIER_SERIAL_THREAD, |
| 944 | ret == PTHREAD_BARRIER_SERIAL_THREAD, 0); |
| 945 | return ret; |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 946 | } |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 947 | |
| 948 | PTH_FUNCS(int, pthreadZubarrierZuwait, pthread_barrier_wait_intercept, |
| 949 | (pthread_barrier_t* barrier), (barrier)); |
njn | f76d27a | 2009-05-28 01:53:07 +0000 | [diff] [blame] | 950 | #endif // HAVE_PTHREAD_BARRIER_INIT |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 951 | |
| 952 | |
bart | b2260b8 | 2011-02-13 07:55:36 +0000 | [diff] [blame] | 953 | static __always_inline |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 954 | int sem_init_intercept(sem_t *sem, int pshared, unsigned int value) |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 955 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 956 | int ret; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 957 | OrigFn fn; |
| 958 | VALGRIND_GET_ORIG_FN(fn); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 959 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PRE_SEM_INIT, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 960 | sem, pshared, value, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 961 | CALL_FN_W_WWW(ret, fn, sem, pshared, value); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 962 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__POST_SEM_INIT, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 963 | sem, 0, 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 964 | return ret; |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 965 | } |
| 966 | |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 967 | PTH_FUNCS(int, semZuinit, sem_init_intercept, |
| 968 | (sem_t *sem, int pshared, unsigned int value), (sem, pshared, value)); |
| 969 | |
bart | b2260b8 | 2011-02-13 07:55:36 +0000 | [diff] [blame] | 970 | static __always_inline |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 971 | int sem_destroy_intercept(sem_t *sem) |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 972 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 973 | int ret; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 974 | OrigFn fn; |
| 975 | VALGRIND_GET_ORIG_FN(fn); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 976 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PRE_SEM_DESTROY, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 977 | sem, 0, 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 978 | CALL_FN_W_W(ret, fn, sem); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 979 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__POST_SEM_DESTROY, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 980 | sem, 0, 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 981 | return ret; |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 982 | } |
| 983 | |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 984 | PTH_FUNCS(int, semZudestroy, sem_destroy_intercept, (sem_t *sem), (sem)); |
| 985 | |
bart | b2260b8 | 2011-02-13 07:55:36 +0000 | [diff] [blame] | 986 | static __always_inline |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 987 | sem_t* sem_open_intercept(const char *name, int oflag, mode_t mode, |
| 988 | unsigned int value) |
bart | 25f9f54 | 2009-07-23 16:31:39 +0000 | [diff] [blame] | 989 | { |
| 990 | sem_t *ret; |
bart | 25f9f54 | 2009-07-23 16:31:39 +0000 | [diff] [blame] | 991 | OrigFn fn; |
| 992 | VALGRIND_GET_ORIG_FN(fn); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 993 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PRE_SEM_OPEN, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 994 | name, oflag, mode, value, 0); |
bart | 25f9f54 | 2009-07-23 16:31:39 +0000 | [diff] [blame] | 995 | CALL_FN_W_WWWW(ret, fn, name, oflag, mode, value); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 996 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__POST_SEM_OPEN, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 997 | ret != SEM_FAILED ? ret : 0, |
| 998 | name, oflag, mode, value); |
bart | 25f9f54 | 2009-07-23 16:31:39 +0000 | [diff] [blame] | 999 | return ret; |
| 1000 | } |
| 1001 | |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 1002 | PTH_FUNCS(sem_t *, semZuopen, sem_open_intercept, |
| 1003 | (const char *name, int oflag, mode_t mode, unsigned int value), |
| 1004 | (name, oflag, mode, value)); |
| 1005 | |
bart | b2260b8 | 2011-02-13 07:55:36 +0000 | [diff] [blame] | 1006 | static __always_inline int sem_close_intercept(sem_t *sem) |
bart | 25f9f54 | 2009-07-23 16:31:39 +0000 | [diff] [blame] | 1007 | { |
| 1008 | int ret; |
bart | 25f9f54 | 2009-07-23 16:31:39 +0000 | [diff] [blame] | 1009 | OrigFn fn; |
| 1010 | VALGRIND_GET_ORIG_FN(fn); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 1011 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PRE_SEM_CLOSE, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 1012 | sem, 0, 0, 0, 0); |
bart | 25f9f54 | 2009-07-23 16:31:39 +0000 | [diff] [blame] | 1013 | CALL_FN_W_W(ret, fn, sem); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 1014 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__POST_SEM_CLOSE, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 1015 | sem, 0, 0, 0, 0); |
bart | 25f9f54 | 2009-07-23 16:31:39 +0000 | [diff] [blame] | 1016 | return ret; |
| 1017 | } |
| 1018 | |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 1019 | PTH_FUNCS(int, semZuclose, sem_close_intercept, (sem_t *sem), (sem)); |
| 1020 | |
bart | b2260b8 | 2011-02-13 07:55:36 +0000 | [diff] [blame] | 1021 | static __always_inline int sem_wait_intercept(sem_t *sem) |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 1022 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1023 | int ret; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1024 | OrigFn fn; |
| 1025 | VALGRIND_GET_ORIG_FN(fn); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 1026 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PRE_SEM_WAIT, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 1027 | sem, 0, 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1028 | CALL_FN_W_W(ret, fn, sem); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 1029 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__POST_SEM_WAIT, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 1030 | sem, ret == 0, 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1031 | return ret; |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 1032 | } |
| 1033 | |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 1034 | PTH_FUNCS(int, semZuwait, sem_wait_intercept, (sem_t *sem), (sem)); |
| 1035 | |
bart | b2260b8 | 2011-02-13 07:55:36 +0000 | [diff] [blame] | 1036 | static __always_inline int sem_trywait_intercept(sem_t *sem) |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 1037 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1038 | int ret; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1039 | OrigFn fn; |
| 1040 | VALGRIND_GET_ORIG_FN(fn); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 1041 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PRE_SEM_WAIT, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 1042 | sem, 0, 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1043 | CALL_FN_W_W(ret, fn, sem); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 1044 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__POST_SEM_WAIT, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 1045 | sem, ret == 0, 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1046 | return ret; |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 1047 | } |
| 1048 | |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 1049 | PTH_FUNCS(int, semZutrywait, sem_trywait_intercept, (sem_t *sem), (sem)); |
| 1050 | |
bart | b2260b8 | 2011-02-13 07:55:36 +0000 | [diff] [blame] | 1051 | static __always_inline |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 1052 | int sem_timedwait_intercept(sem_t *sem, const struct timespec *abs_timeout) |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 1053 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1054 | int ret; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1055 | OrigFn fn; |
| 1056 | VALGRIND_GET_ORIG_FN(fn); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 1057 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PRE_SEM_WAIT, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 1058 | sem, 0, 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1059 | CALL_FN_W_WW(ret, fn, sem, abs_timeout); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 1060 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__POST_SEM_WAIT, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 1061 | sem, ret == 0, 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1062 | return ret; |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 1063 | } |
| 1064 | |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 1065 | PTH_FUNCS(int, semZutimedwait, sem_timedwait_intercept, |
| 1066 | (sem_t *sem, const struct timespec *abs_timeout), |
| 1067 | (sem, abs_timeout)); |
| 1068 | |
bart | b2260b8 | 2011-02-13 07:55:36 +0000 | [diff] [blame] | 1069 | static __always_inline int sem_post_intercept(sem_t *sem) |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 1070 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1071 | int ret; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1072 | OrigFn fn; |
| 1073 | VALGRIND_GET_ORIG_FN(fn); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 1074 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PRE_SEM_POST, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 1075 | sem, 0, 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1076 | CALL_FN_W_W(ret, fn, sem); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 1077 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__POST_SEM_POST, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 1078 | sem, ret == 0, 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1079 | return ret; |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 1080 | } |
| 1081 | |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 1082 | PTH_FUNCS(int, semZupost, sem_post_intercept, (sem_t *sem), (sem)); |
| 1083 | |
sewardj | 0c09bf0 | 2011-07-11 22:11:58 +0000 | [diff] [blame] | 1084 | /* Android's pthread.h doesn't say anything about rwlocks, hence these |
| 1085 | functions have to be conditionally compiled. */ |
| 1086 | #if defined(HAVE_PTHREAD_RWLOCK_T) |
| 1087 | |
bart | b2260b8 | 2011-02-13 07:55:36 +0000 | [diff] [blame] | 1088 | static __always_inline |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 1089 | int pthread_rwlock_init_intercept(pthread_rwlock_t* rwlock, |
| 1090 | const pthread_rwlockattr_t* attr) |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 1091 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1092 | int ret; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1093 | OrigFn fn; |
| 1094 | VALGRIND_GET_ORIG_FN(fn); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 1095 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PRE_RWLOCK_INIT, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 1096 | rwlock, 0, 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1097 | CALL_FN_W_WW(ret, fn, rwlock, attr); |
| 1098 | return ret; |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 1099 | } |
| 1100 | |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 1101 | PTH_FUNCS(int, |
| 1102 | pthreadZurwlockZuinit, pthread_rwlock_init_intercept, |
| 1103 | (pthread_rwlock_t* rwlock, const pthread_rwlockattr_t* attr), |
| 1104 | (rwlock, attr)); |
| 1105 | |
bart | b2260b8 | 2011-02-13 07:55:36 +0000 | [diff] [blame] | 1106 | static __always_inline |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 1107 | int pthread_rwlock_destroy_intercept(pthread_rwlock_t* rwlock) |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 1108 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1109 | int ret; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1110 | OrigFn fn; |
| 1111 | VALGRIND_GET_ORIG_FN(fn); |
| 1112 | CALL_FN_W_W(ret, fn, rwlock); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 1113 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__POST_RWLOCK_DESTROY, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 1114 | rwlock, 0, 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1115 | return ret; |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 1116 | } |
| 1117 | |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 1118 | PTH_FUNCS(int, |
| 1119 | pthreadZurwlockZudestroy, pthread_rwlock_destroy_intercept, |
| 1120 | (pthread_rwlock_t* rwlock), (rwlock)); |
| 1121 | |
bart | b2260b8 | 2011-02-13 07:55:36 +0000 | [diff] [blame] | 1122 | static __always_inline |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 1123 | int pthread_rwlock_rdlock_intercept(pthread_rwlock_t* rwlock) |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 1124 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1125 | int ret; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1126 | OrigFn fn; |
| 1127 | VALGRIND_GET_ORIG_FN(fn); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 1128 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PRE_RWLOCK_RDLOCK, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 1129 | rwlock, 0, 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1130 | CALL_FN_W_W(ret, fn, rwlock); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 1131 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__POST_RWLOCK_RDLOCK, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 1132 | rwlock, ret == 0, 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1133 | return ret; |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 1134 | } |
| 1135 | |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 1136 | PTH_FUNCS(int, |
| 1137 | pthreadZurwlockZurdlock, pthread_rwlock_rdlock_intercept, |
| 1138 | (pthread_rwlock_t* rwlock), (rwlock)); |
| 1139 | |
bart | b2260b8 | 2011-02-13 07:55:36 +0000 | [diff] [blame] | 1140 | static __always_inline |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 1141 | int pthread_rwlock_wrlock_intercept(pthread_rwlock_t* rwlock) |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 1142 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1143 | int ret; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1144 | OrigFn fn; |
| 1145 | VALGRIND_GET_ORIG_FN(fn); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 1146 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PRE_RWLOCK_WRLOCK, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 1147 | rwlock, 0, 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1148 | CALL_FN_W_W(ret, fn, rwlock); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 1149 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__POST_RWLOCK_WRLOCK, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 1150 | rwlock, ret == 0, 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1151 | return ret; |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 1152 | } |
| 1153 | |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 1154 | PTH_FUNCS(int, |
| 1155 | pthreadZurwlockZuwrlock, pthread_rwlock_wrlock_intercept, |
| 1156 | (pthread_rwlock_t* rwlock), (rwlock)); |
| 1157 | |
bart | b2260b8 | 2011-02-13 07:55:36 +0000 | [diff] [blame] | 1158 | static __always_inline |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 1159 | int pthread_rwlock_timedrdlock_intercept(pthread_rwlock_t* rwlock) |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 1160 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1161 | int ret; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1162 | OrigFn fn; |
| 1163 | VALGRIND_GET_ORIG_FN(fn); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 1164 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PRE_RWLOCK_RDLOCK, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 1165 | rwlock, 0, 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1166 | CALL_FN_W_W(ret, fn, rwlock); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 1167 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__POST_RWLOCK_RDLOCK, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 1168 | rwlock, ret == 0, 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1169 | return ret; |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 1170 | } |
| 1171 | |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 1172 | PTH_FUNCS(int, |
| 1173 | pthreadZurwlockZutimedrdlock, pthread_rwlock_timedrdlock_intercept, |
| 1174 | (pthread_rwlock_t* rwlock), (rwlock)); |
| 1175 | |
bart | b2260b8 | 2011-02-13 07:55:36 +0000 | [diff] [blame] | 1176 | static __always_inline |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 1177 | int pthread_rwlock_timedwrlock_intercept(pthread_rwlock_t* rwlock) |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 1178 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1179 | int ret; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1180 | OrigFn fn; |
| 1181 | VALGRIND_GET_ORIG_FN(fn); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 1182 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PRE_RWLOCK_WRLOCK, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 1183 | rwlock, 0, 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1184 | CALL_FN_W_W(ret, fn, rwlock); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 1185 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__POST_RWLOCK_WRLOCK, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 1186 | rwlock, ret == 0, 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1187 | return ret; |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 1188 | } |
| 1189 | |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 1190 | PTH_FUNCS(int, |
| 1191 | pthreadZurwlockZutimedwrlock, pthread_rwlock_timedwrlock_intercept, |
| 1192 | (pthread_rwlock_t* rwlock), (rwlock)); |
| 1193 | |
bart | b2260b8 | 2011-02-13 07:55:36 +0000 | [diff] [blame] | 1194 | static __always_inline |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 1195 | int pthread_rwlock_tryrdlock_intercept(pthread_rwlock_t* rwlock) |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 1196 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1197 | int ret; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1198 | OrigFn fn; |
| 1199 | VALGRIND_GET_ORIG_FN(fn); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 1200 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PRE_RWLOCK_RDLOCK, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 1201 | rwlock, 0, 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1202 | CALL_FN_W_W(ret, fn, rwlock); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 1203 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__POST_RWLOCK_RDLOCK, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 1204 | rwlock, ret == 0, 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1205 | return ret; |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 1206 | } |
| 1207 | |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 1208 | PTH_FUNCS(int, |
| 1209 | pthreadZurwlockZutryrdlock, pthread_rwlock_tryrdlock_intercept, |
| 1210 | (pthread_rwlock_t* rwlock), (rwlock)); |
| 1211 | |
bart | b2260b8 | 2011-02-13 07:55:36 +0000 | [diff] [blame] | 1212 | static __always_inline |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 1213 | int pthread_rwlock_trywrlock_intercept(pthread_rwlock_t* rwlock) |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 1214 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1215 | int ret; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1216 | OrigFn fn; |
| 1217 | VALGRIND_GET_ORIG_FN(fn); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 1218 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PRE_RWLOCK_WRLOCK, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 1219 | rwlock, 0, 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1220 | CALL_FN_W_W(ret, fn, rwlock); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 1221 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__POST_RWLOCK_WRLOCK, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 1222 | rwlock, ret == 0, 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1223 | return ret; |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 1224 | } |
| 1225 | |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 1226 | PTH_FUNCS(int, |
| 1227 | pthreadZurwlockZutrywrlock, pthread_rwlock_trywrlock_intercept, |
| 1228 | (pthread_rwlock_t* rwlock), (rwlock)); |
| 1229 | |
bart | b2260b8 | 2011-02-13 07:55:36 +0000 | [diff] [blame] | 1230 | static __always_inline |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 1231 | int pthread_rwlock_unlock_intercept(pthread_rwlock_t* rwlock) |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 1232 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1233 | int ret; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1234 | OrigFn fn; |
| 1235 | VALGRIND_GET_ORIG_FN(fn); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 1236 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PRE_RWLOCK_UNLOCK, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 1237 | rwlock, 0, 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1238 | CALL_FN_W_W(ret, fn, rwlock); |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 1239 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__POST_RWLOCK_UNLOCK, |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 1240 | rwlock, ret == 0, 0, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1241 | return ret; |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 1242 | } |
bart | 791a0c6 | 2009-07-31 17:31:44 +0000 | [diff] [blame] | 1243 | |
| 1244 | PTH_FUNCS(int, |
| 1245 | pthreadZurwlockZuunlock, pthread_rwlock_unlock_intercept, |
| 1246 | (pthread_rwlock_t* rwlock), (rwlock)); |
sewardj | 0c09bf0 | 2011-07-11 22:11:58 +0000 | [diff] [blame] | 1247 | |
| 1248 | #endif /* defined(HAVE_PTHREAD_RWLOCK_T) */ |