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