blob: f64ab1c535756e1f3541eb372518b77cc9508489 [file] [log] [blame]
sewardjaf44c822007-11-25 14:01:38 +00001
2/*--------------------------------------------------------------------*/
sewardj85642922008-01-14 11:54:56 +00003/*--- Client-space code for drd. drd_intercepts.c ---*/
sewardjaf44c822007-11-25 14:01:38 +00004/*--------------------------------------------------------------------*/
5
6/*
7 This file is part of drd, a data race detector.
8
sewardj85642922008-01-14 11:54:56 +00009 Copyright (C) 2006-2008 Bart Van Assche
sewardjaf44c822007-11-25 14:01:38 +000010 bart.vanassche@gmail.com
11
12 This program is free software; you can redistribute it and/or
13 modify it under the terms of the GNU General Public License as
14 published by the Free Software Foundation; either version 2 of the
15 License, or (at your option) any later version.
16
17 This program is distributed in the hope that it will be useful, but
18 WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
25 02111-1307, USA.
26
27 The GNU General Public License is contained in the file COPYING.
28*/
29
30/* ---------------------------------------------------------------------
31 ALL THE CODE IN THIS FILE RUNS ON THE SIMULATED CPU.
32
33 These functions are not called directly - they're the targets of code
34 redirection or load notifications (see pub_core_redir.h for info).
35 They're named weirdly so that the intercept code can find them when the
36 shared object is initially loaded.
37
38 Note that this filename has the "drd_" prefix because it can appear
39 in stack traces, and the "drd_" makes it a little clearer that it
40 originates from Valgrind.
41 ------------------------------------------------------------------ */
42
bart5e85d262008-03-01 10:49:37 +000043// Make sure pthread_spinlock_t is available when compiling with older glibc
44// versions (2.3 or before).
sewardjaf44c822007-11-25 14:01:38 +000045#ifndef _GNU_SOURCE
46#define _GNU_SOURCE
47#endif
48
49#include <assert.h>
bart4501d5c2008-03-04 18:36:23 +000050#include <inttypes.h> // uintptr_t
sewardj85642922008-01-14 11:54:56 +000051#include <pthread.h>
52#include <semaphore.h>
sewardjaf44c822007-11-25 14:01:38 +000053#include <stdio.h>
bart0d063002008-03-01 07:25:13 +000054#include <stdlib.h>
bart4501d5c2008-03-04 18:36:23 +000055#include <unistd.h> // confstr()
bart5e389f12008-04-05 12:53:15 +000056#include "config.h"
sewardjaf44c822007-11-25 14:01:38 +000057#include "drd_clientreq.h"
sewardj85642922008-01-14 11:54:56 +000058#include "pub_tool_redir.h"
sewardjaf44c822007-11-25 14:01:38 +000059
60
61// Defines.
62
bart3772a982008-03-15 08:11:03 +000063#define PTH_FUNC(ret_ty, f, args...) \
64 ret_ty VG_WRAP_FUNCTION_ZZ(libpthreadZdsoZd0,f)(args); \
65 ret_ty VG_WRAP_FUNCTION_ZZ(libpthreadZdsoZd0,f)(args)
sewardjaf44c822007-11-25 14:01:38 +000066
67
bart6f07b252008-04-04 16:45:20 +000068/* Local data structures. */
sewardjaf44c822007-11-25 14:01:38 +000069
70typedef struct
71{
bart3772a982008-03-15 08:11:03 +000072 void* (*start)(void*);
73 void* arg;
74 int detachstate;
sewardjaf44c822007-11-25 14:01:38 +000075#if 0
bart3772a982008-03-15 08:11:03 +000076 pthread_mutex_t mutex;
77 pthread_cond_t cond;
sewardjaf44c822007-11-25 14:01:38 +000078#else
bart3772a982008-03-15 08:11:03 +000079 int wrapper_started;
sewardjaf44c822007-11-25 14:01:38 +000080#endif
81} VgPosixThreadArgs;
82
83
bart6f07b252008-04-04 16:45:20 +000084/* Function declarations. */
sewardjaf44c822007-11-25 14:01:38 +000085
bart44ceea22008-04-16 18:19:45 +000086static void init(void) __attribute__((constructor));
bart6f07b252008-04-04 16:45:20 +000087static void check_threading_library(void);
88static void vg_set_main_thread_state(void);
sewardjaf44c822007-11-25 14:01:38 +000089
90
bart6f07b252008-04-04 16:45:20 +000091/* Function definitions. */
92
93/** Shared library initialization function: the _init() function is called
94 * after dlopen() has loaded the shared library. This function must not
95 * be declared static.
96 */
bart44ceea22008-04-16 18:19:45 +000097static void init(void)
bart6f07b252008-04-04 16:45:20 +000098{
99 check_threading_library();
bart25d30032008-04-06 07:51:24 +0000100 /* glibc up to and including version 2.7 triggers conflicting accesses */
101 /* on stdout and stderr when sending output to one of these streams from */
102 /* more than one thread. Suppress data race reports on these objects. */
103 DRD_IGNORE_VAR(*stdout);
104 DRD_IGNORE_VAR(*stderr);
bart6f07b252008-04-04 16:45:20 +0000105}
sewardjaf44c822007-11-25 14:01:38 +0000106
bart1fb17552008-05-02 18:53:33 +0000107int VG_WRAP_FUNCTION_ZZ(Za,main)(int argc, char** argv, char** envp);
108int VG_WRAP_FUNCTION_ZZ(Za,main)(int argc, char** argv, char** envp)
109{
110 int ret;
111 OrigFn fn;
112 VALGRIND_GET_ORIG_FN(fn);
113 vg_set_main_thread_state();
114 CALL_FN_W_WWW(ret, fn, argc, argv, envp);
115 return ret;
116}
117
bart5357fcb2008-02-27 15:46:00 +0000118static MutexT pthread_to_drd_mutex_type(const int kind)
119{
bart3772a982008-03-15 08:11:03 +0000120 switch (kind)
121 {
122 /* PTHREAD_MUTEX_RECURSIVE_NP */
123 case PTHREAD_MUTEX_RECURSIVE:
124 return mutex_type_recursive_mutex;
125 /* PTHREAD_MUTEX_ERRORCHECK_NP */
126 case PTHREAD_MUTEX_ERRORCHECK:
127 return mutex_type_errorcheck_mutex;
128 /* PTHREAD_MUTEX_TIMED_NP */
129 /* PTHREAD_MUTEX_NORMAL */
130 case PTHREAD_MUTEX_DEFAULT:
sewardj7cf4e6b2008-05-01 20:24:26 +0000131# if !defined(VGP_ppc32_aix5) && !defined(VGP_ppc64_aix5)
bart3772a982008-03-15 08:11:03 +0000132 case PTHREAD_MUTEX_ADAPTIVE_NP:
sewardj7cf4e6b2008-05-01 20:24:26 +0000133# endif
bart3772a982008-03-15 08:11:03 +0000134 return mutex_type_default_mutex;
135 }
136 return mutex_type_invalid_mutex;
bart5357fcb2008-02-27 15:46:00 +0000137}
138
139static MutexT mutex_type(pthread_mutex_t* mutex)
140{
bart5e389f12008-04-05 12:53:15 +0000141#if defined(HAVE_PTHREAD_MUTEX_T__M_KIND)
142 /* LinuxThreads. */
bart3772a982008-03-15 08:11:03 +0000143 const int kind = mutex->__m_kind;
bart5e389f12008-04-05 12:53:15 +0000144#elif defined(HAVE_PTHREAD_MUTEX_T__DATA__KIND)
145 /* NPTL. */
bart3772a982008-03-15 08:11:03 +0000146 const int kind = mutex->__data.__kind;
bartc9463c42008-02-28 07:36:04 +0000147#else
bart5e389f12008-04-05 12:53:15 +0000148 /* Another POSIX threads implementation. Regression tests will fail. */
bart3772a982008-03-15 08:11:03 +0000149 const int kind = PTHREAD_MUTEX_DEFAULT;
bart5e389f12008-04-05 12:53:15 +0000150 fprintf(stderr,
151 "Did not recognize your POSIX threads implementation. Giving up.\n");
152 assert(0);
bartc9463c42008-02-28 07:36:04 +0000153#endif
bart3772a982008-03-15 08:11:03 +0000154 return pthread_to_drd_mutex_type(kind);
bart5357fcb2008-02-27 15:46:00 +0000155}
156
sewardjaf44c822007-11-25 14:01:38 +0000157static void vg_start_suppression(const void* const p, size_t const size)
158{
bart3772a982008-03-15 08:11:03 +0000159 int res;
160 VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__DRD_START_SUPPRESSION,
bartf5bb46a2008-03-29 13:18:02 +0000161 p, size, 0, 0, 0);
sewardjaf44c822007-11-25 14:01:38 +0000162}
163
164static void vg_set_joinable(const pthread_t tid, const int joinable)
165{
bart3772a982008-03-15 08:11:03 +0000166 int res;
167 assert(joinable == 0 || joinable == 1);
168 VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__SET_JOINABLE,
169 tid, joinable, 0, 0, 0);
sewardjaf44c822007-11-25 14:01:38 +0000170}
171
172static void* vg_thread_wrapper(void* arg)
173{
bart3772a982008-03-15 08:11:03 +0000174 int res;
bart0d063002008-03-01 07:25:13 +0000175
bart3772a982008-03-15 08:11:03 +0000176 VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__DRD_SUPPRESS_CURRENT_STACK,
177 0, 0, 0, 0, 0);
sewardjaf44c822007-11-25 14:01:38 +0000178
bart3772a982008-03-15 08:11:03 +0000179 {
180 VgPosixThreadArgs* const arg_ptr = (VgPosixThreadArgs*)arg;
181 VgPosixThreadArgs const arg_copy = *arg_ptr;
182 void* result;
sewardjaf44c822007-11-25 14:01:38 +0000183
184#if 0
bart3772a982008-03-15 08:11:03 +0000185 pthread_mutex_lock(arg_ptr->mutex);
186 pthread_cond_signal(arg_ptr->cond);
187 pthread_mutex_unlock(arg_ptr->mutex);
sewardjaf44c822007-11-25 14:01:38 +0000188#else
bart3772a982008-03-15 08:11:03 +0000189 arg_ptr->wrapper_started = 1;
sewardjaf44c822007-11-25 14:01:38 +0000190#endif
191
bart3772a982008-03-15 08:11:03 +0000192 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__SET_PTHREADID,
193 pthread_self(), 0, 0, 0, 0);
194 vg_set_joinable(pthread_self(),
195 arg_copy.detachstate == PTHREAD_CREATE_JOINABLE);
196 result = (arg_copy.start)(arg_copy.arg);
197 return result;
198 }
sewardjaf44c822007-11-25 14:01:38 +0000199}
200
bart6f07b252008-04-04 16:45:20 +0000201/** Return 1 if LinuxThread has been detected, and 0 otherwise. */
bart4501d5c2008-03-04 18:36:23 +0000202static int detected_linuxthreads(void)
203{
204#if defined(linux)
205#if defined(_CS_GNU_LIBPTHREAD_VERSION)
bart3772a982008-03-15 08:11:03 +0000206 /* Linux with a recent glibc. */
207 char buffer[256];
208 unsigned len;
209 len = confstr(_CS_GNU_LIBPTHREAD_VERSION, buffer, sizeof(buffer));
210 assert(len <= sizeof(buffer));
211 return len > 0 && buffer[0] == 'l';
bart4501d5c2008-03-04 18:36:23 +0000212#else
bart3772a982008-03-15 08:11:03 +0000213 /* Linux without _CS_GNU_LIBPTHREAD_VERSION: most likely LinuxThreads. */
214 return 1;
bart4501d5c2008-03-04 18:36:23 +0000215#endif
216#else
bart3772a982008-03-15 08:11:03 +0000217 /* Another OS than Linux, hence no LinuxThreads. */
218 return 0;
bart4501d5c2008-03-04 18:36:23 +0000219#endif
220}
221
bart6f07b252008-04-04 16:45:20 +0000222/** Stop and print an error message in case a non-supported threading
223 * library (LinuxThreads) has been detected.
224 */
225static void check_threading_library(void)
sewardjaf44c822007-11-25 14:01:38 +0000226{
bart3772a982008-03-15 08:11:03 +0000227 if (detected_linuxthreads())
228 {
229 if (getenv("LD_ASSUME_KERNEL"))
230 {
231 fprintf(stderr,
232 "Detected the LinuxThreads threading library. Sorry, but DRD only supports\n"
233 "the newer NPTL (Native POSIX Threads Library). Please try to rerun DRD\n"
234 "after having unset the environment variable LD_ASSUME_KERNEL. Giving up.\n"
235 );
236 }
237 else
238 {
239 fprintf(stderr,
240 "Detected the LinuxThreads threading library. Sorry, but DRD only supports\n"
241 "the newer NPTL (Native POSIX Threads Library). Please try to rerun DRD\n"
242 "after having upgraded to a newer version of your Linux distribution.\n"
243 "Giving up.\n"
244 );
245 }
246 abort();
247 }
bart6f07b252008-04-04 16:45:20 +0000248}
249
250static void vg_set_main_thread_state(void)
251{
252 int res;
bart0d063002008-03-01 07:25:13 +0000253
bart3772a982008-03-15 08:11:03 +0000254 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__DRD_SUPPRESS_CURRENT_STACK,
255 0, 0, 0, 0, 0);
sewardjaf44c822007-11-25 14:01:38 +0000256
bart3772a982008-03-15 08:11:03 +0000257 // Make sure that DRD knows about the main thread's POSIX thread ID.
258 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__SET_PTHREADID,
259 pthread_self(), 0, 0, 0, 0);
sewardjaf44c822007-11-25 14:01:38 +0000260
261}
262
263// pthread_create
sewardj347eeba2008-01-21 14:19:07 +0000264PTH_FUNC(int, pthreadZucreateZa, // pthread_create*
bart3772a982008-03-15 08:11:03 +0000265 pthread_t *thread, const pthread_attr_t *attr,
266 void *(*start) (void *), void *arg)
sewardjaf44c822007-11-25 14:01:38 +0000267{
bartbf3a60c2008-04-04 19:10:21 +0000268 int res;
bart3772a982008-03-15 08:11:03 +0000269 int ret;
270 OrigFn fn;
271 VgPosixThreadArgs vgargs;
sewardjaf44c822007-11-25 14:01:38 +0000272
bart3772a982008-03-15 08:11:03 +0000273 VALGRIND_GET_ORIG_FN(fn);
sewardjaf44c822007-11-25 14:01:38 +0000274
bart3772a982008-03-15 08:11:03 +0000275 vg_start_suppression(&vgargs.wrapper_started,
276 sizeof(vgargs.wrapper_started));
277 vgargs.start = start;
278 vgargs.arg = arg;
279 vgargs.wrapper_started = 0;
280 vgargs.detachstate = PTHREAD_CREATE_JOINABLE;
281 if (attr)
282 {
283 if (pthread_attr_getdetachstate(attr, &vgargs.detachstate) != 0)
284 {
285 assert(0);
286 }
287 }
288 assert(vgargs.detachstate == PTHREAD_CREATE_JOINABLE
289 || vgargs.detachstate == PTHREAD_CREATE_DETACHED);
sewardjaf44c822007-11-25 14:01:38 +0000290#if 0
bart3772a982008-03-15 08:11:03 +0000291 pthread_mutex_init(&vgargs.mutex, 0);
292 pthread_cond_init(&vgargs.cond, 0);
293 pthread_mutex_lock(&vgargs.mutex);
sewardjaf44c822007-11-25 14:01:38 +0000294#endif
bartbf3a60c2008-04-04 19:10:21 +0000295 /* Suppress NPTL-specific conflicts between creator and created thread. */
296 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__DRD_STOP_RECORDING,
297 0, 0, 0, 0, 0);
bart3772a982008-03-15 08:11:03 +0000298 CALL_FN_W_WWWW(ret, fn, thread, attr, vg_thread_wrapper, &vgargs);
bartbf3a60c2008-04-04 19:10:21 +0000299 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__DRD_START_RECORDING,
300 0, 0, 0, 0, 0);
sewardjaf44c822007-11-25 14:01:38 +0000301#if 0
bart3772a982008-03-15 08:11:03 +0000302 pthread_cond_wait(&vgargs.cond, &vgargs.mutex);
303 pthread_mutex_unlock(&vgargs.mutex);
304 pthread_cond_destroy(&vgargs.cond);
305 pthread_mutex_destroy(&vgargs.mutex);
sewardjaf44c822007-11-25 14:01:38 +0000306#else
bart3772a982008-03-15 08:11:03 +0000307 // Yes, you see it correctly, busy waiting ... The problem is that
308 // POSIX threads functions cannot be called here -- the functions defined
309 // in this file (drd_intercepts.c) would be called instead of those in
310 // libpthread.so. This loop is necessary because vgargs is allocated on the
311 // stack, and the created thread reads it.
312 if (ret == 0)
313 {
314 while (! vgargs.wrapper_started)
315 {
316 sched_yield();
317 }
318 }
sewardjaf44c822007-11-25 14:01:38 +0000319#endif
bart3772a982008-03-15 08:11:03 +0000320 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000321}
322
323// pthread_join
324PTH_FUNC(int, pthreadZujoin, // pthread_join
bart3772a982008-03-15 08:11:03 +0000325 pthread_t pt_joinee, void **thread_return)
sewardjaf44c822007-11-25 14:01:38 +0000326{
bart3772a982008-03-15 08:11:03 +0000327 int ret;
328 int res;
329 OrigFn fn;
sewardjaf44c822007-11-25 14:01:38 +0000330
bart3772a982008-03-15 08:11:03 +0000331 VALGRIND_GET_ORIG_FN(fn);
332 CALL_FN_W_WW(ret, fn, pt_joinee, thread_return);
333 if (ret == 0)
334 {
335 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_THREAD_JOIN,
336 pt_joinee, 0, 0, 0, 0);
337 }
338 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000339}
340
341// pthread_detach
342PTH_FUNC(int, pthreadZudetach, pthread_t pt_thread)
343{
bart3772a982008-03-15 08:11:03 +0000344 int ret;
345 OrigFn fn;
346 VALGRIND_GET_ORIG_FN(fn);
347 {
348 CALL_FN_W_W(ret, fn, pt_thread);
349 if (ret == 0)
350 {
351 vg_set_joinable(pt_thread, 0);
352 }
353 }
354 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000355}
356
357// pthread_mutex_init
358PTH_FUNC(int, pthreadZumutexZuinit,
bart3772a982008-03-15 08:11:03 +0000359 pthread_mutex_t *mutex,
360 const pthread_mutexattr_t* attr)
sewardjaf44c822007-11-25 14:01:38 +0000361{
bart3772a982008-03-15 08:11:03 +0000362 int ret;
363 int res;
364 OrigFn fn;
365 int mt;
366 VALGRIND_GET_ORIG_FN(fn);
367 mt = PTHREAD_MUTEX_DEFAULT;
368 if (attr)
369 pthread_mutexattr_gettype(attr, &mt);
370 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_MUTEX_INIT,
371 mutex, pthread_to_drd_mutex_type(mt), 0, 0, 0);
372 CALL_FN_W_WW(ret, fn, mutex, attr);
373 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_MUTEX_INIT,
374 mutex, 0, 0, 0, 0);
375 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000376}
377
378// pthread_mutex_destroy
379PTH_FUNC(int, pthreadZumutexZudestroy,
bart3772a982008-03-15 08:11:03 +0000380 pthread_mutex_t *mutex)
sewardjaf44c822007-11-25 14:01:38 +0000381{
bart3772a982008-03-15 08:11:03 +0000382 int ret;
383 int res;
384 OrigFn fn;
385 VALGRIND_GET_ORIG_FN(fn);
386 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_MUTEX_DESTROY,
387 mutex, 0, 0, 0, 0);
388 CALL_FN_W_W(ret, fn, mutex);
389 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_MUTEX_DESTROY,
390 mutex, mutex_type(mutex), 0, 0, 0);
391 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000392}
393
394// pthread_mutex_lock
395PTH_FUNC(int, pthreadZumutexZulock, // pthread_mutex_lock
bart3772a982008-03-15 08:11:03 +0000396 pthread_mutex_t *mutex)
sewardjaf44c822007-11-25 14:01:38 +0000397{
bart3772a982008-03-15 08:11:03 +0000398 int ret;
399 int res;
400 OrigFn fn;
401 VALGRIND_GET_ORIG_FN(fn);
402 VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__PRE_MUTEX_LOCK,
403 mutex, mutex_type(mutex), 0, 0, 0);
404 CALL_FN_W_W(ret, fn, mutex);
405 VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__POST_MUTEX_LOCK,
406 mutex, ret == 0, 0, 0, 0);
407 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000408}
409
410// pthread_mutex_trylock
411PTH_FUNC(int, pthreadZumutexZutrylock, // pthread_mutex_trylock
bart3772a982008-03-15 08:11:03 +0000412 pthread_mutex_t *mutex)
sewardjaf44c822007-11-25 14:01:38 +0000413{
bart3772a982008-03-15 08:11:03 +0000414 int ret;
415 int res;
416 OrigFn fn;
417 VALGRIND_GET_ORIG_FN(fn);
418 VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__PRE_MUTEX_LOCK,
bart2e3a3c12008-03-24 08:33:47 +0000419 mutex, mutex_type(mutex), 1, 0, 0);
bart3772a982008-03-15 08:11:03 +0000420 CALL_FN_W_W(ret, fn, mutex);
421 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_MUTEX_LOCK,
422 mutex, ret == 0, 0, 0, 0);
423 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000424}
425
sewardj85642922008-01-14 11:54:56 +0000426// pthread_mutex_timedlock
427PTH_FUNC(int, pthreadZumutexZutimedlock, // pthread_mutex_timedlock
bart3772a982008-03-15 08:11:03 +0000428 pthread_mutex_t *mutex,
429 const struct timespec *abs_timeout)
sewardj85642922008-01-14 11:54:56 +0000430{
bart3772a982008-03-15 08:11:03 +0000431 int ret;
432 int res;
433 OrigFn fn;
434 VALGRIND_GET_ORIG_FN(fn);
435 VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__PRE_MUTEX_LOCK,
436 mutex, mutex_type(mutex), 0, 0, 0);
437 CALL_FN_W_WW(ret, fn, mutex, abs_timeout);
438 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_MUTEX_LOCK,
439 mutex, ret == 0, 0, 0, 0);
440 return ret;
sewardj85642922008-01-14 11:54:56 +0000441}
442
sewardjaf44c822007-11-25 14:01:38 +0000443// pthread_mutex_unlock
444PTH_FUNC(int, pthreadZumutexZuunlock, // pthread_mutex_unlock
bart3772a982008-03-15 08:11:03 +0000445 pthread_mutex_t *mutex)
sewardjaf44c822007-11-25 14:01:38 +0000446{
bart3772a982008-03-15 08:11:03 +0000447 int ret;
448 int res;
449 OrigFn fn;
450 VALGRIND_GET_ORIG_FN(fn);
451 VALGRIND_DO_CLIENT_REQUEST(res, -1,
452 VG_USERREQ__PRE_MUTEX_UNLOCK,
453 mutex, mutex_type(mutex), 0, 0, 0);
454 CALL_FN_W_W(ret, fn, mutex);
455 VALGRIND_DO_CLIENT_REQUEST(res, -1,
456 VG_USERREQ__POST_MUTEX_UNLOCK,
457 mutex, 0, 0, 0, 0);
458 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000459}
460
461// pthread_cond_init
sewardj347eeba2008-01-21 14:19:07 +0000462PTH_FUNC(int, pthreadZucondZuinitZa, // pthread_cond_init*
bart3772a982008-03-15 08:11:03 +0000463 pthread_cond_t* cond,
464 const pthread_condattr_t* attr)
sewardjaf44c822007-11-25 14:01:38 +0000465{
bart3772a982008-03-15 08:11:03 +0000466 int ret;
467 int res;
468 OrigFn fn;
469 VALGRIND_GET_ORIG_FN(fn);
470 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_COND_INIT,
471 cond, 0, 0, 0, 0);
472 CALL_FN_W_WW(ret, fn, cond, attr);
473 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000474}
475
476// pthread_cond_destroy
sewardj347eeba2008-01-21 14:19:07 +0000477PTH_FUNC(int, pthreadZucondZudestroyZa, // pthread_cond_destroy*
bart3772a982008-03-15 08:11:03 +0000478 pthread_cond_t* cond)
sewardjaf44c822007-11-25 14:01:38 +0000479{
bart3772a982008-03-15 08:11:03 +0000480 int ret;
481 int res;
482 OrigFn fn;
483 VALGRIND_GET_ORIG_FN(fn);
484 CALL_FN_W_W(ret, fn, cond);
485 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_COND_DESTROY,
486 cond, 0, 0, 0, 0);
487 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000488}
489
490// pthread_cond_wait
sewardj347eeba2008-01-21 14:19:07 +0000491PTH_FUNC(int, pthreadZucondZuwaitZa, // pthread_cond_wait*
bart3772a982008-03-15 08:11:03 +0000492 pthread_cond_t *cond,
493 pthread_mutex_t *mutex)
sewardjaf44c822007-11-25 14:01:38 +0000494{
bart3772a982008-03-15 08:11:03 +0000495 int ret;
496 int res;
497 OrigFn fn;
498 VALGRIND_GET_ORIG_FN(fn);
499 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_COND_WAIT,
500 cond, mutex, mutex_type(mutex), 0, 0);
501 CALL_FN_W_WW(ret, fn, cond, mutex);
502 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_COND_WAIT,
bart1b7a8302008-03-30 08:39:51 +0000503 cond, mutex, 1, 0, 0);
bart3772a982008-03-15 08:11:03 +0000504 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000505}
506
507// pthread_cond_timedwait
sewardj347eeba2008-01-21 14:19:07 +0000508PTH_FUNC(int, pthreadZucondZutimedwaitZa, // pthread_cond_timedwait*
bart3772a982008-03-15 08:11:03 +0000509 pthread_cond_t *cond,
510 pthread_mutex_t *mutex,
511 const struct timespec* abstime)
sewardjaf44c822007-11-25 14:01:38 +0000512{
bart3772a982008-03-15 08:11:03 +0000513 int ret;
514 int res;
515 OrigFn fn;
516 VALGRIND_GET_ORIG_FN(fn);
517 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_COND_WAIT,
518 cond, mutex, mutex_type(mutex), 0, 0);
519 CALL_FN_W_WWW(ret, fn, cond, mutex, abstime);
520 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_COND_WAIT,
bart1b7a8302008-03-30 08:39:51 +0000521 cond, mutex, 1, 0, 0);
bart3772a982008-03-15 08:11:03 +0000522 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000523}
524
525// pthread_cond_signal
sewardj347eeba2008-01-21 14:19:07 +0000526PTH_FUNC(int, pthreadZucondZusignalZa, // pthread_cond_signal*
bart3772a982008-03-15 08:11:03 +0000527 pthread_cond_t* cond)
sewardjaf44c822007-11-25 14:01:38 +0000528{
bart3772a982008-03-15 08:11:03 +0000529 int ret;
530 int res;
531 OrigFn fn;
532 VALGRIND_GET_ORIG_FN(fn);
533 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_COND_SIGNAL,
534 cond, 0, 0, 0, 0);
535 CALL_FN_W_W(ret, fn, cond);
536 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000537}
538
539// pthread_cond_broadcast
sewardj347eeba2008-01-21 14:19:07 +0000540PTH_FUNC(int, pthreadZucondZubroadcastZa, // pthread_cond_broadcast*
bart3772a982008-03-15 08:11:03 +0000541 pthread_cond_t* cond)
sewardjaf44c822007-11-25 14:01:38 +0000542{
bart3772a982008-03-15 08:11:03 +0000543 int ret;
544 int res;
545 OrigFn fn;
546 VALGRIND_GET_ORIG_FN(fn);
547 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_COND_BROADCAST,
548 cond, 0, 0, 0, 0);
549 CALL_FN_W_W(ret, fn, cond);
550 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000551}
552
553
554// pthread_spin_init
555PTH_FUNC(int, pthreadZuspinZuinit, // pthread_spin_init
bart3772a982008-03-15 08:11:03 +0000556 pthread_spinlock_t *spinlock,
557 int pshared)
sewardjaf44c822007-11-25 14:01:38 +0000558{
bart3772a982008-03-15 08:11:03 +0000559 int ret;
560 int res;
561 OrigFn fn;
562 VALGRIND_GET_ORIG_FN(fn);
563 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__SPIN_INIT_OR_UNLOCK,
564 spinlock, mutex_type_spinlock, 0, 0, 0);
565 CALL_FN_W_WW(ret, fn, spinlock, pshared);
566 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000567}
568
569// pthread_spin_destroy
570PTH_FUNC(int, pthreadZuspinZudestroy, // pthread_spin_destroy
bart3772a982008-03-15 08:11:03 +0000571 pthread_spinlock_t *spinlock)
sewardjaf44c822007-11-25 14:01:38 +0000572{
bart3772a982008-03-15 08:11:03 +0000573 int ret;
574 int res;
575 OrigFn fn;
576 VALGRIND_GET_ORIG_FN(fn);
577 CALL_FN_W_W(ret, fn, spinlock);
578 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_MUTEX_DESTROY,
579 spinlock, mutex_type_spinlock, 0, 0, 0);
580 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000581}
582
583// pthread_spin_lock
584PTH_FUNC(int, pthreadZuspinZulock, // pthread_spin_lock
bart3772a982008-03-15 08:11:03 +0000585 pthread_spinlock_t *spinlock)
sewardjaf44c822007-11-25 14:01:38 +0000586{
bart3772a982008-03-15 08:11:03 +0000587 int ret;
588 int res;
589 OrigFn fn;
590 VALGRIND_GET_ORIG_FN(fn);
591 VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__PRE_MUTEX_LOCK,
592 spinlock, mutex_type_spinlock, 0, 0, 0);
593 CALL_FN_W_W(ret, fn, spinlock);
594 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_MUTEX_LOCK,
595 spinlock, ret == 0, 0, 0, 0);
596 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000597}
598
599// pthread_spin_trylock
600PTH_FUNC(int, pthreadZuspinZutrylock, // pthread_spin_trylock
bart3772a982008-03-15 08:11:03 +0000601 pthread_spinlock_t *spinlock)
sewardjaf44c822007-11-25 14:01:38 +0000602{
bart3772a982008-03-15 08:11:03 +0000603 int ret;
604 int res;
605 OrigFn fn;
606 VALGRIND_GET_ORIG_FN(fn);
607 VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__PRE_MUTEX_LOCK,
608 spinlock, mutex_type_spinlock, 0, 0, 0);
609 CALL_FN_W_W(ret, fn, spinlock);
610 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_MUTEX_LOCK,
611 spinlock, ret == 0, 0, 0, 0);
612 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000613}
614
615// pthread_spin_unlock
616PTH_FUNC(int, pthreadZuspinZuunlock, // pthread_spin_unlock
bart3772a982008-03-15 08:11:03 +0000617 pthread_spinlock_t *spinlock)
sewardjaf44c822007-11-25 14:01:38 +0000618{
bart3772a982008-03-15 08:11:03 +0000619 int ret;
620 int res;
621 OrigFn fn;
622 VALGRIND_GET_ORIG_FN(fn);
623 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__SPIN_INIT_OR_UNLOCK,
624 spinlock, mutex_type_spinlock, 0, 0, 0);
625 CALL_FN_W_W(ret, fn, spinlock);
626 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000627}
628
sewardj85642922008-01-14 11:54:56 +0000629// pthread_barrier_init
630PTH_FUNC(int, pthreadZubarrierZuinit, // pthread_barrier_init
bart3772a982008-03-15 08:11:03 +0000631 pthread_barrier_t* barrier,
632 const pthread_barrierattr_t* attr,
633 unsigned count)
sewardj85642922008-01-14 11:54:56 +0000634{
bart3772a982008-03-15 08:11:03 +0000635 int ret;
636 int res;
637 OrigFn fn;
638 VALGRIND_GET_ORIG_FN(fn);
639 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_BARRIER_INIT,
640 barrier, pthread_barrier, count, 0, 0);
641 CALL_FN_W_WWW(ret, fn, barrier, attr, count);
642 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_BARRIER_INIT,
643 barrier, pthread_barrier, 0, 0, 0);
644 return ret;
sewardj85642922008-01-14 11:54:56 +0000645}
646
647// pthread_barrier_destroy
648PTH_FUNC(int, pthreadZubarrierZudestroy, // pthread_barrier_destroy
bart3772a982008-03-15 08:11:03 +0000649 pthread_barrier_t* barrier)
sewardj85642922008-01-14 11:54:56 +0000650{
bart3772a982008-03-15 08:11:03 +0000651 int ret;
652 int res;
653 OrigFn fn;
654 VALGRIND_GET_ORIG_FN(fn);
655 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_BARRIER_DESTROY,
656 barrier, pthread_barrier, 0, 0, 0);
657 CALL_FN_W_W(ret, fn, barrier);
658 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_BARRIER_DESTROY,
659 barrier, pthread_barrier, 0, 0, 0);
660 return ret;
sewardj85642922008-01-14 11:54:56 +0000661}
662
663// pthread_barrier_wait
664PTH_FUNC(int, pthreadZubarrierZuwait, // pthread_barrier_wait
bart3772a982008-03-15 08:11:03 +0000665 pthread_barrier_t* barrier)
sewardj85642922008-01-14 11:54:56 +0000666{
bart3772a982008-03-15 08:11:03 +0000667 int ret;
668 int res;
669 OrigFn fn;
670 VALGRIND_GET_ORIG_FN(fn);
671 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_BARRIER_WAIT,
672 barrier, pthread_barrier, 0, 0, 0);
673 CALL_FN_W_W(ret, fn, barrier);
674 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_BARRIER_WAIT,
675 barrier, pthread_barrier,
676 ret == 0 || ret == PTHREAD_BARRIER_SERIAL_THREAD,
677 0, 0);
678 return ret;
sewardj85642922008-01-14 11:54:56 +0000679}
680
681
sewardj85642922008-01-14 11:54:56 +0000682// sem_init
bart368ec982008-03-11 20:39:01 +0000683PTH_FUNC(int, semZuinitZa, // sem_init*
bart3772a982008-03-15 08:11:03 +0000684 sem_t *sem,
685 int pshared,
686 unsigned int value)
sewardj85642922008-01-14 11:54:56 +0000687{
bart3772a982008-03-15 08:11:03 +0000688 int ret;
689 int res;
690 OrigFn fn;
691 VALGRIND_GET_ORIG_FN(fn);
692 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_SEM_INIT,
693 sem, pshared, value, 0, 0);
694 CALL_FN_W_WWW(ret, fn, sem, pshared, value);
695 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_SEM_INIT,
696 sem, 0, 0, 0, 0);
697 return ret;
sewardj85642922008-01-14 11:54:56 +0000698}
699
700// sem_destroy
bart00344642008-03-01 15:27:41 +0000701PTH_FUNC(int, semZudestroyZa, // sem_destroy*
bart3772a982008-03-15 08:11:03 +0000702 sem_t *sem)
sewardj85642922008-01-14 11:54:56 +0000703{
bart3772a982008-03-15 08:11:03 +0000704 int ret;
705 int res;
706 OrigFn fn;
707 VALGRIND_GET_ORIG_FN(fn);
708 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_SEM_DESTROY,
709 sem, 0, 0, 0, 0);
710 CALL_FN_W_W(ret, fn, sem);
711 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_SEM_DESTROY,
712 sem, 0, 0, 0, 0);
713 return ret;
sewardj85642922008-01-14 11:54:56 +0000714}
715
716// sem_wait
bart368ec982008-03-11 20:39:01 +0000717PTH_FUNC(int, semZuwaitZa, // sem_wait*
bart3772a982008-03-15 08:11:03 +0000718 sem_t *sem)
sewardj85642922008-01-14 11:54:56 +0000719{
bart3772a982008-03-15 08:11:03 +0000720 int ret;
721 int res;
722 OrigFn fn;
723 VALGRIND_GET_ORIG_FN(fn);
724 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_SEM_WAIT,
725 sem, 0, 0, 0, 0);
726 CALL_FN_W_W(ret, fn, sem);
727 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_SEM_WAIT,
728 sem, ret == 0, 0, 0, 0);
729 return ret;
sewardj85642922008-01-14 11:54:56 +0000730}
731
732// sem_trywait
bart00344642008-03-01 15:27:41 +0000733PTH_FUNC(int, semZutrywaitZa, // sem_trywait*
bart3772a982008-03-15 08:11:03 +0000734 sem_t *sem)
sewardj85642922008-01-14 11:54:56 +0000735{
bart3772a982008-03-15 08:11:03 +0000736 int ret;
737 int res;
738 OrigFn fn;
739 VALGRIND_GET_ORIG_FN(fn);
740 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_SEM_WAIT,
741 sem, 0, 0, 0, 0);
742 CALL_FN_W_W(ret, fn, sem);
743 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_SEM_WAIT,
744 sem, ret == 0, 0, 0, 0);
745 return ret;
sewardj85642922008-01-14 11:54:56 +0000746}
747
748// sem_timedwait
bart00344642008-03-01 15:27:41 +0000749PTH_FUNC(int, semZutimedwait, // sem_timedwait
bart3772a982008-03-15 08:11:03 +0000750 sem_t *sem, const struct timespec *abs_timeout)
sewardj85642922008-01-14 11:54:56 +0000751{
bart3772a982008-03-15 08:11:03 +0000752 int ret;
753 int res;
754 OrigFn fn;
755 VALGRIND_GET_ORIG_FN(fn);
756 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_SEM_WAIT,
757 sem, 0, 0, 0, 0);
758 CALL_FN_W_WW(ret, fn, sem, abs_timeout);
759 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_SEM_WAIT,
760 sem, ret == 0, 0, 0, 0);
761 return ret;
sewardj85642922008-01-14 11:54:56 +0000762}
763
764// sem_post
bart368ec982008-03-11 20:39:01 +0000765PTH_FUNC(int, semZupostZa, // sem_post*
bart3772a982008-03-15 08:11:03 +0000766 sem_t *sem)
sewardj85642922008-01-14 11:54:56 +0000767{
bart3772a982008-03-15 08:11:03 +0000768 int ret;
769 int res;
770 OrigFn fn;
771 VALGRIND_GET_ORIG_FN(fn);
772 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_SEM_POST,
773 sem, 0, 0, 0, 0);
774 CALL_FN_W_W(ret, fn, sem);
775 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_SEM_POST,
776 sem, ret == 0, 0, 0, 0);
777 return ret;
sewardj85642922008-01-14 11:54:56 +0000778}
779
bart00344642008-03-01 15:27:41 +0000780// pthread_rwlock_init
781PTH_FUNC(int,
782 pthreadZurwlockZuinitZa, // pthread_rwlock_init*
783 pthread_rwlock_t* rwlock,
784 const pthread_rwlockattr_t* attr)
785{
bart3772a982008-03-15 08:11:03 +0000786 int ret;
787 int res;
788 OrigFn fn;
789 VALGRIND_GET_ORIG_FN(fn);
790 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_RWLOCK_INIT,
791 rwlock, 0, 0, 0, 0);
792 CALL_FN_W_WW(ret, fn, rwlock, attr);
793 return ret;
bart00344642008-03-01 15:27:41 +0000794}
795
796// pthread_rwlock_destroy
797PTH_FUNC(int,
798 pthreadZurwlockZudestroyZa, // pthread_rwlock_destroy*
799 pthread_rwlock_t* rwlock)
800{
bart3772a982008-03-15 08:11:03 +0000801 int ret;
802 int res;
803 OrigFn fn;
804 VALGRIND_GET_ORIG_FN(fn);
805 CALL_FN_W_W(ret, fn, rwlock);
806 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_RWLOCK_DESTROY,
807 rwlock, 0, 0, 0, 0);
808 return ret;
bart00344642008-03-01 15:27:41 +0000809}
810
811// pthread_rwlock_rdlock
812PTH_FUNC(int,
813 pthreadZurwlockZurdlockZa, // pthread_rwlock_rdlock*
814 pthread_rwlock_t* rwlock)
815{
bart3772a982008-03-15 08:11:03 +0000816 int ret;
817 int res;
818 OrigFn fn;
819 VALGRIND_GET_ORIG_FN(fn);
820 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_RWLOCK_RDLOCK,
821 rwlock, 0, 0, 0, 0);
822 CALL_FN_W_W(ret, fn, rwlock);
823 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_RWLOCK_RDLOCK,
824 rwlock, ret == 0, 0, 0, 0);
825 return ret;
bart00344642008-03-01 15:27:41 +0000826}
827
828// pthread_rwlock_wrlock
829PTH_FUNC(int,
830 pthreadZurwlockZuwrlockZa, // pthread_rwlock_wrlock*
831 pthread_rwlock_t* rwlock)
832{
bart3772a982008-03-15 08:11:03 +0000833 int ret;
834 int res;
835 OrigFn fn;
836 VALGRIND_GET_ORIG_FN(fn);
837 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_RWLOCK_WRLOCK,
838 rwlock, 0, 0, 0, 0);
839 CALL_FN_W_W(ret, fn, rwlock);
840 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_RWLOCK_WRLOCK,
841 rwlock, ret == 0, 0, 0, 0);
842 return ret;
bart00344642008-03-01 15:27:41 +0000843}
844
845// pthread_rwlock_timedrdlock
846PTH_FUNC(int,
847 pthreadZurwlockZutimedrdlockZa, // pthread_rwlock_timedrdlock*
848 pthread_rwlock_t* rwlock)
849{
bart3772a982008-03-15 08:11:03 +0000850 int ret;
851 int res;
852 OrigFn fn;
853 VALGRIND_GET_ORIG_FN(fn);
854 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_RWLOCK_RDLOCK,
855 rwlock, 0, 0, 0, 0);
856 CALL_FN_W_W(ret, fn, rwlock);
857 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_RWLOCK_RDLOCK,
858 rwlock, ret == 0, 0, 0, 0);
859 return ret;
bart00344642008-03-01 15:27:41 +0000860}
861
862// pthread_rwlock_timedwrlock
863PTH_FUNC(int,
864 pthreadZurwlockZutimedwrlockZa, // pthread_rwlock_timedwrlock*
865 pthread_rwlock_t* rwlock)
866{
bart3772a982008-03-15 08:11:03 +0000867 int ret;
868 int res;
869 OrigFn fn;
870 VALGRIND_GET_ORIG_FN(fn);
871 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_RWLOCK_WRLOCK,
872 rwlock, 0, 0, 0, 0);
873 CALL_FN_W_W(ret, fn, rwlock);
874 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_RWLOCK_WRLOCK,
875 rwlock, ret == 0, 0, 0, 0);
876 return ret;
bart00344642008-03-01 15:27:41 +0000877}
878
879// pthread_rwlock_tryrdlock
880PTH_FUNC(int,
881 pthreadZurwlockZutryrdlockZa, // pthread_rwlock_tryrdlock*
882 pthread_rwlock_t* rwlock)
883{
bart3772a982008-03-15 08:11:03 +0000884 int ret;
885 int res;
886 OrigFn fn;
887 VALGRIND_GET_ORIG_FN(fn);
888 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_RWLOCK_RDLOCK,
889 rwlock, 0, 0, 0, 0);
890 CALL_FN_W_W(ret, fn, rwlock);
891 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_RWLOCK_RDLOCK,
892 rwlock, ret == 0, 0, 0, 0);
893 return ret;
bart00344642008-03-01 15:27:41 +0000894}
895
896// pthread_rwlock_trywrlock
897PTH_FUNC(int,
898 pthreadZurwlockZutrywrlockZa, // pthread_rwlock_trywrlock*
899 pthread_rwlock_t* rwlock)
900{
bart3772a982008-03-15 08:11:03 +0000901 int ret;
902 int res;
903 OrigFn fn;
904 VALGRIND_GET_ORIG_FN(fn);
905 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_RWLOCK_WRLOCK,
906 rwlock, 0, 0, 0, 0);
907 CALL_FN_W_W(ret, fn, rwlock);
908 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_RWLOCK_WRLOCK,
909 rwlock, ret == 0, 0, 0, 0);
910 return ret;
bart00344642008-03-01 15:27:41 +0000911}
912
913// pthread_rwlock_unlock
914PTH_FUNC(int,
915 pthreadZurwlockZuunlockZa, // pthread_rwlock_unlock*
916 pthread_rwlock_t* rwlock)
917{
bart3772a982008-03-15 08:11:03 +0000918 int ret;
919 int res;
920 OrigFn fn;
921 VALGRIND_GET_ORIG_FN(fn);
922 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_RWLOCK_UNLOCK,
923 rwlock, 0, 0, 0, 0);
924 CALL_FN_W_W(ret, fn, rwlock);
925 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_RWLOCK_UNLOCK,
926 rwlock, ret == 0, 0, 0, 0);
927 return ret;
bart00344642008-03-01 15:27:41 +0000928}