blob: 6e1e6d8dfa94bba45a88f6a4542e9b23ca993567 [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
bart6f07b252008-04-04 16:45:20 +000086void _init(void);
87static 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 */
97void _init(void)
98{
99 check_threading_library();
100 vg_set_main_thread_state();
bart25d30032008-04-06 07:51:24 +0000101 /* glibc up to and including version 2.7 triggers conflicting accesses */
102 /* on stdout and stderr when sending output to one of these streams from */
103 /* more than one thread. Suppress data race reports on these objects. */
104 DRD_IGNORE_VAR(*stdout);
105 DRD_IGNORE_VAR(*stderr);
bart6f07b252008-04-04 16:45:20 +0000106}
sewardjaf44c822007-11-25 14:01:38 +0000107
bart5357fcb2008-02-27 15:46:00 +0000108static MutexT pthread_to_drd_mutex_type(const int kind)
109{
bart3772a982008-03-15 08:11:03 +0000110 switch (kind)
111 {
112 /* PTHREAD_MUTEX_RECURSIVE_NP */
113 case PTHREAD_MUTEX_RECURSIVE:
114 return mutex_type_recursive_mutex;
115 /* PTHREAD_MUTEX_ERRORCHECK_NP */
116 case PTHREAD_MUTEX_ERRORCHECK:
117 return mutex_type_errorcheck_mutex;
118 /* PTHREAD_MUTEX_TIMED_NP */
119 /* PTHREAD_MUTEX_NORMAL */
120 case PTHREAD_MUTEX_DEFAULT:
121 case PTHREAD_MUTEX_ADAPTIVE_NP:
122 return mutex_type_default_mutex;
123 }
124 return mutex_type_invalid_mutex;
bart5357fcb2008-02-27 15:46:00 +0000125}
126
127static MutexT mutex_type(pthread_mutex_t* mutex)
128{
bart5e389f12008-04-05 12:53:15 +0000129#if defined(HAVE_PTHREAD_MUTEX_T__M_KIND)
130 /* LinuxThreads. */
bart3772a982008-03-15 08:11:03 +0000131 const int kind = mutex->__m_kind;
bart5e389f12008-04-05 12:53:15 +0000132#elif defined(HAVE_PTHREAD_MUTEX_T__DATA__KIND)
133 /* NPTL. */
bart3772a982008-03-15 08:11:03 +0000134 const int kind = mutex->__data.__kind;
bartc9463c42008-02-28 07:36:04 +0000135#else
bart5e389f12008-04-05 12:53:15 +0000136 /* Another POSIX threads implementation. Regression tests will fail. */
bart3772a982008-03-15 08:11:03 +0000137 const int kind = PTHREAD_MUTEX_DEFAULT;
bart5e389f12008-04-05 12:53:15 +0000138 fprintf(stderr,
139 "Did not recognize your POSIX threads implementation. Giving up.\n");
140 assert(0);
bartc9463c42008-02-28 07:36:04 +0000141#endif
bart3772a982008-03-15 08:11:03 +0000142 return pthread_to_drd_mutex_type(kind);
bart5357fcb2008-02-27 15:46:00 +0000143}
144
sewardjaf44c822007-11-25 14:01:38 +0000145static void vg_start_suppression(const void* const p, size_t const size)
146{
bart3772a982008-03-15 08:11:03 +0000147 int res;
148 VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__DRD_START_SUPPRESSION,
bartf5bb46a2008-03-29 13:18:02 +0000149 p, size, 0, 0, 0);
sewardjaf44c822007-11-25 14:01:38 +0000150}
151
152static void vg_set_joinable(const pthread_t tid, const int joinable)
153{
bart3772a982008-03-15 08:11:03 +0000154 int res;
155 assert(joinable == 0 || joinable == 1);
156 VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__SET_JOINABLE,
157 tid, joinable, 0, 0, 0);
sewardjaf44c822007-11-25 14:01:38 +0000158}
159
160static void* vg_thread_wrapper(void* arg)
161{
bart3772a982008-03-15 08:11:03 +0000162 int res;
bart0d063002008-03-01 07:25:13 +0000163
bart3772a982008-03-15 08:11:03 +0000164 VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__DRD_SUPPRESS_CURRENT_STACK,
165 0, 0, 0, 0, 0);
sewardjaf44c822007-11-25 14:01:38 +0000166
bart3772a982008-03-15 08:11:03 +0000167 {
168 VgPosixThreadArgs* const arg_ptr = (VgPosixThreadArgs*)arg;
169 VgPosixThreadArgs const arg_copy = *arg_ptr;
170 void* result;
sewardjaf44c822007-11-25 14:01:38 +0000171
172#if 0
bart3772a982008-03-15 08:11:03 +0000173 pthread_mutex_lock(arg_ptr->mutex);
174 pthread_cond_signal(arg_ptr->cond);
175 pthread_mutex_unlock(arg_ptr->mutex);
sewardjaf44c822007-11-25 14:01:38 +0000176#else
bart3772a982008-03-15 08:11:03 +0000177 arg_ptr->wrapper_started = 1;
sewardjaf44c822007-11-25 14:01:38 +0000178#endif
179
bart3772a982008-03-15 08:11:03 +0000180 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__SET_PTHREADID,
181 pthread_self(), 0, 0, 0, 0);
182 vg_set_joinable(pthread_self(),
183 arg_copy.detachstate == PTHREAD_CREATE_JOINABLE);
184 result = (arg_copy.start)(arg_copy.arg);
185 return result;
186 }
sewardjaf44c822007-11-25 14:01:38 +0000187}
188
bart6f07b252008-04-04 16:45:20 +0000189/** Return 1 if LinuxThread has been detected, and 0 otherwise. */
bart4501d5c2008-03-04 18:36:23 +0000190static int detected_linuxthreads(void)
191{
192#if defined(linux)
193#if defined(_CS_GNU_LIBPTHREAD_VERSION)
bart3772a982008-03-15 08:11:03 +0000194 /* Linux with a recent glibc. */
195 char buffer[256];
196 unsigned len;
197 len = confstr(_CS_GNU_LIBPTHREAD_VERSION, buffer, sizeof(buffer));
198 assert(len <= sizeof(buffer));
199 return len > 0 && buffer[0] == 'l';
bart4501d5c2008-03-04 18:36:23 +0000200#else
bart3772a982008-03-15 08:11:03 +0000201 /* Linux without _CS_GNU_LIBPTHREAD_VERSION: most likely LinuxThreads. */
202 return 1;
bart4501d5c2008-03-04 18:36:23 +0000203#endif
204#else
bart3772a982008-03-15 08:11:03 +0000205 /* Another OS than Linux, hence no LinuxThreads. */
206 return 0;
bart4501d5c2008-03-04 18:36:23 +0000207#endif
208}
209
bart6f07b252008-04-04 16:45:20 +0000210/** Stop and print an error message in case a non-supported threading
211 * library (LinuxThreads) has been detected.
212 */
213static void check_threading_library(void)
sewardjaf44c822007-11-25 14:01:38 +0000214{
bart3772a982008-03-15 08:11:03 +0000215 if (detected_linuxthreads())
216 {
217 if (getenv("LD_ASSUME_KERNEL"))
218 {
219 fprintf(stderr,
220 "Detected the LinuxThreads threading library. Sorry, but DRD only supports\n"
221 "the newer NPTL (Native POSIX Threads Library). Please try to rerun DRD\n"
222 "after having unset the environment variable LD_ASSUME_KERNEL. Giving up.\n"
223 );
224 }
225 else
226 {
227 fprintf(stderr,
228 "Detected the LinuxThreads threading library. Sorry, but DRD only supports\n"
229 "the newer NPTL (Native POSIX Threads Library). Please try to rerun DRD\n"
230 "after having upgraded to a newer version of your Linux distribution.\n"
231 "Giving up.\n"
232 );
233 }
234 abort();
235 }
bart6f07b252008-04-04 16:45:20 +0000236}
237
238static void vg_set_main_thread_state(void)
239{
240 int res;
bart0d063002008-03-01 07:25:13 +0000241
bart3772a982008-03-15 08:11:03 +0000242 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__DRD_SUPPRESS_CURRENT_STACK,
243 0, 0, 0, 0, 0);
sewardjaf44c822007-11-25 14:01:38 +0000244
bart3772a982008-03-15 08:11:03 +0000245 // Make sure that DRD knows about the main thread's POSIX thread ID.
246 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__SET_PTHREADID,
247 pthread_self(), 0, 0, 0, 0);
sewardjaf44c822007-11-25 14:01:38 +0000248
249}
250
251// pthread_create
sewardj347eeba2008-01-21 14:19:07 +0000252PTH_FUNC(int, pthreadZucreateZa, // pthread_create*
bart3772a982008-03-15 08:11:03 +0000253 pthread_t *thread, const pthread_attr_t *attr,
254 void *(*start) (void *), void *arg)
sewardjaf44c822007-11-25 14:01:38 +0000255{
bartbf3a60c2008-04-04 19:10:21 +0000256 int res;
bart3772a982008-03-15 08:11:03 +0000257 int ret;
258 OrigFn fn;
259 VgPosixThreadArgs vgargs;
sewardjaf44c822007-11-25 14:01:38 +0000260
bart3772a982008-03-15 08:11:03 +0000261 VALGRIND_GET_ORIG_FN(fn);
sewardjaf44c822007-11-25 14:01:38 +0000262
bart3772a982008-03-15 08:11:03 +0000263 vg_start_suppression(&vgargs.wrapper_started,
264 sizeof(vgargs.wrapper_started));
265 vgargs.start = start;
266 vgargs.arg = arg;
267 vgargs.wrapper_started = 0;
268 vgargs.detachstate = PTHREAD_CREATE_JOINABLE;
269 if (attr)
270 {
271 if (pthread_attr_getdetachstate(attr, &vgargs.detachstate) != 0)
272 {
273 assert(0);
274 }
275 }
276 assert(vgargs.detachstate == PTHREAD_CREATE_JOINABLE
277 || vgargs.detachstate == PTHREAD_CREATE_DETACHED);
sewardjaf44c822007-11-25 14:01:38 +0000278#if 0
bart3772a982008-03-15 08:11:03 +0000279 pthread_mutex_init(&vgargs.mutex, 0);
280 pthread_cond_init(&vgargs.cond, 0);
281 pthread_mutex_lock(&vgargs.mutex);
sewardjaf44c822007-11-25 14:01:38 +0000282#endif
bartbf3a60c2008-04-04 19:10:21 +0000283 /* Suppress NPTL-specific conflicts between creator and created thread. */
284 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__DRD_STOP_RECORDING,
285 0, 0, 0, 0, 0);
bart3772a982008-03-15 08:11:03 +0000286 CALL_FN_W_WWWW(ret, fn, thread, attr, vg_thread_wrapper, &vgargs);
bartbf3a60c2008-04-04 19:10:21 +0000287 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__DRD_START_RECORDING,
288 0, 0, 0, 0, 0);
sewardjaf44c822007-11-25 14:01:38 +0000289#if 0
bart3772a982008-03-15 08:11:03 +0000290 pthread_cond_wait(&vgargs.cond, &vgargs.mutex);
291 pthread_mutex_unlock(&vgargs.mutex);
292 pthread_cond_destroy(&vgargs.cond);
293 pthread_mutex_destroy(&vgargs.mutex);
sewardjaf44c822007-11-25 14:01:38 +0000294#else
bart3772a982008-03-15 08:11:03 +0000295 // Yes, you see it correctly, busy waiting ... The problem is that
296 // POSIX threads functions cannot be called here -- the functions defined
297 // in this file (drd_intercepts.c) would be called instead of those in
298 // libpthread.so. This loop is necessary because vgargs is allocated on the
299 // stack, and the created thread reads it.
300 if (ret == 0)
301 {
302 while (! vgargs.wrapper_started)
303 {
304 sched_yield();
305 }
306 }
sewardjaf44c822007-11-25 14:01:38 +0000307#endif
bart3772a982008-03-15 08:11:03 +0000308 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000309}
310
311// pthread_join
312PTH_FUNC(int, pthreadZujoin, // pthread_join
bart3772a982008-03-15 08:11:03 +0000313 pthread_t pt_joinee, void **thread_return)
sewardjaf44c822007-11-25 14:01:38 +0000314{
bart3772a982008-03-15 08:11:03 +0000315 int ret;
316 int res;
317 OrigFn fn;
sewardjaf44c822007-11-25 14:01:38 +0000318
bart3772a982008-03-15 08:11:03 +0000319 VALGRIND_GET_ORIG_FN(fn);
320 CALL_FN_W_WW(ret, fn, pt_joinee, thread_return);
321 if (ret == 0)
322 {
323 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_THREAD_JOIN,
324 pt_joinee, 0, 0, 0, 0);
325 }
326 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000327}
328
329// pthread_detach
330PTH_FUNC(int, pthreadZudetach, pthread_t pt_thread)
331{
bart3772a982008-03-15 08:11:03 +0000332 int ret;
333 OrigFn fn;
334 VALGRIND_GET_ORIG_FN(fn);
335 {
336 CALL_FN_W_W(ret, fn, pt_thread);
337 if (ret == 0)
338 {
339 vg_set_joinable(pt_thread, 0);
340 }
341 }
342 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000343}
344
345// pthread_mutex_init
346PTH_FUNC(int, pthreadZumutexZuinit,
bart3772a982008-03-15 08:11:03 +0000347 pthread_mutex_t *mutex,
348 const pthread_mutexattr_t* attr)
sewardjaf44c822007-11-25 14:01:38 +0000349{
bart3772a982008-03-15 08:11:03 +0000350 int ret;
351 int res;
352 OrigFn fn;
353 int mt;
354 VALGRIND_GET_ORIG_FN(fn);
355 mt = PTHREAD_MUTEX_DEFAULT;
356 if (attr)
357 pthread_mutexattr_gettype(attr, &mt);
358 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_MUTEX_INIT,
359 mutex, pthread_to_drd_mutex_type(mt), 0, 0, 0);
360 CALL_FN_W_WW(ret, fn, mutex, attr);
361 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_MUTEX_INIT,
362 mutex, 0, 0, 0, 0);
363 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000364}
365
366// pthread_mutex_destroy
367PTH_FUNC(int, pthreadZumutexZudestroy,
bart3772a982008-03-15 08:11:03 +0000368 pthread_mutex_t *mutex)
sewardjaf44c822007-11-25 14:01:38 +0000369{
bart3772a982008-03-15 08:11:03 +0000370 int ret;
371 int res;
372 OrigFn fn;
373 VALGRIND_GET_ORIG_FN(fn);
374 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_MUTEX_DESTROY,
375 mutex, 0, 0, 0, 0);
376 CALL_FN_W_W(ret, fn, mutex);
377 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_MUTEX_DESTROY,
378 mutex, mutex_type(mutex), 0, 0, 0);
379 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000380}
381
382// pthread_mutex_lock
383PTH_FUNC(int, pthreadZumutexZulock, // pthread_mutex_lock
bart3772a982008-03-15 08:11:03 +0000384 pthread_mutex_t *mutex)
sewardjaf44c822007-11-25 14:01:38 +0000385{
bart3772a982008-03-15 08:11:03 +0000386 int ret;
387 int res;
388 OrigFn fn;
389 VALGRIND_GET_ORIG_FN(fn);
390 VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__PRE_MUTEX_LOCK,
391 mutex, mutex_type(mutex), 0, 0, 0);
392 CALL_FN_W_W(ret, fn, mutex);
393 VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__POST_MUTEX_LOCK,
394 mutex, ret == 0, 0, 0, 0);
395 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000396}
397
398// pthread_mutex_trylock
399PTH_FUNC(int, pthreadZumutexZutrylock, // pthread_mutex_trylock
bart3772a982008-03-15 08:11:03 +0000400 pthread_mutex_t *mutex)
sewardjaf44c822007-11-25 14:01:38 +0000401{
bart3772a982008-03-15 08:11:03 +0000402 int ret;
403 int res;
404 OrigFn fn;
405 VALGRIND_GET_ORIG_FN(fn);
406 VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__PRE_MUTEX_LOCK,
bart2e3a3c12008-03-24 08:33:47 +0000407 mutex, mutex_type(mutex), 1, 0, 0);
bart3772a982008-03-15 08:11:03 +0000408 CALL_FN_W_W(ret, fn, mutex);
409 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_MUTEX_LOCK,
410 mutex, ret == 0, 0, 0, 0);
411 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000412}
413
sewardj85642922008-01-14 11:54:56 +0000414// pthread_mutex_timedlock
415PTH_FUNC(int, pthreadZumutexZutimedlock, // pthread_mutex_timedlock
bart3772a982008-03-15 08:11:03 +0000416 pthread_mutex_t *mutex,
417 const struct timespec *abs_timeout)
sewardj85642922008-01-14 11:54:56 +0000418{
bart3772a982008-03-15 08:11:03 +0000419 int ret;
420 int res;
421 OrigFn fn;
422 VALGRIND_GET_ORIG_FN(fn);
423 VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__PRE_MUTEX_LOCK,
424 mutex, mutex_type(mutex), 0, 0, 0);
425 CALL_FN_W_WW(ret, fn, mutex, abs_timeout);
426 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_MUTEX_LOCK,
427 mutex, ret == 0, 0, 0, 0);
428 return ret;
sewardj85642922008-01-14 11:54:56 +0000429}
430
sewardjaf44c822007-11-25 14:01:38 +0000431// pthread_mutex_unlock
432PTH_FUNC(int, pthreadZumutexZuunlock, // pthread_mutex_unlock
bart3772a982008-03-15 08:11:03 +0000433 pthread_mutex_t *mutex)
sewardjaf44c822007-11-25 14:01:38 +0000434{
bart3772a982008-03-15 08:11:03 +0000435 int ret;
436 int res;
437 OrigFn fn;
438 VALGRIND_GET_ORIG_FN(fn);
439 VALGRIND_DO_CLIENT_REQUEST(res, -1,
440 VG_USERREQ__PRE_MUTEX_UNLOCK,
441 mutex, mutex_type(mutex), 0, 0, 0);
442 CALL_FN_W_W(ret, fn, mutex);
443 VALGRIND_DO_CLIENT_REQUEST(res, -1,
444 VG_USERREQ__POST_MUTEX_UNLOCK,
445 mutex, 0, 0, 0, 0);
446 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000447}
448
449// pthread_cond_init
sewardj347eeba2008-01-21 14:19:07 +0000450PTH_FUNC(int, pthreadZucondZuinitZa, // pthread_cond_init*
bart3772a982008-03-15 08:11:03 +0000451 pthread_cond_t* cond,
452 const pthread_condattr_t* attr)
sewardjaf44c822007-11-25 14:01:38 +0000453{
bart3772a982008-03-15 08:11:03 +0000454 int ret;
455 int res;
456 OrigFn fn;
457 VALGRIND_GET_ORIG_FN(fn);
458 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_COND_INIT,
459 cond, 0, 0, 0, 0);
460 CALL_FN_W_WW(ret, fn, cond, attr);
461 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000462}
463
464// pthread_cond_destroy
sewardj347eeba2008-01-21 14:19:07 +0000465PTH_FUNC(int, pthreadZucondZudestroyZa, // pthread_cond_destroy*
bart3772a982008-03-15 08:11:03 +0000466 pthread_cond_t* cond)
sewardjaf44c822007-11-25 14:01:38 +0000467{
bart3772a982008-03-15 08:11:03 +0000468 int ret;
469 int res;
470 OrigFn fn;
471 VALGRIND_GET_ORIG_FN(fn);
472 CALL_FN_W_W(ret, fn, cond);
473 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_COND_DESTROY,
474 cond, 0, 0, 0, 0);
475 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000476}
477
478// pthread_cond_wait
sewardj347eeba2008-01-21 14:19:07 +0000479PTH_FUNC(int, pthreadZucondZuwaitZa, // pthread_cond_wait*
bart3772a982008-03-15 08:11:03 +0000480 pthread_cond_t *cond,
481 pthread_mutex_t *mutex)
sewardjaf44c822007-11-25 14:01:38 +0000482{
bart3772a982008-03-15 08:11:03 +0000483 int ret;
484 int res;
485 OrigFn fn;
486 VALGRIND_GET_ORIG_FN(fn);
487 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_COND_WAIT,
488 cond, mutex, mutex_type(mutex), 0, 0);
489 CALL_FN_W_WW(ret, fn, cond, mutex);
490 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_COND_WAIT,
bart1b7a8302008-03-30 08:39:51 +0000491 cond, mutex, 1, 0, 0);
bart3772a982008-03-15 08:11:03 +0000492 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000493}
494
495// pthread_cond_timedwait
sewardj347eeba2008-01-21 14:19:07 +0000496PTH_FUNC(int, pthreadZucondZutimedwaitZa, // pthread_cond_timedwait*
bart3772a982008-03-15 08:11:03 +0000497 pthread_cond_t *cond,
498 pthread_mutex_t *mutex,
499 const struct timespec* abstime)
sewardjaf44c822007-11-25 14:01:38 +0000500{
bart3772a982008-03-15 08:11:03 +0000501 int ret;
502 int res;
503 OrigFn fn;
504 VALGRIND_GET_ORIG_FN(fn);
505 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_COND_WAIT,
506 cond, mutex, mutex_type(mutex), 0, 0);
507 CALL_FN_W_WWW(ret, fn, cond, mutex, abstime);
508 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_COND_WAIT,
bart1b7a8302008-03-30 08:39:51 +0000509 cond, mutex, 1, 0, 0);
bart3772a982008-03-15 08:11:03 +0000510 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000511}
512
513// pthread_cond_signal
sewardj347eeba2008-01-21 14:19:07 +0000514PTH_FUNC(int, pthreadZucondZusignalZa, // pthread_cond_signal*
bart3772a982008-03-15 08:11:03 +0000515 pthread_cond_t* cond)
sewardjaf44c822007-11-25 14:01:38 +0000516{
bart3772a982008-03-15 08:11:03 +0000517 int ret;
518 int res;
519 OrigFn fn;
520 VALGRIND_GET_ORIG_FN(fn);
521 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_COND_SIGNAL,
522 cond, 0, 0, 0, 0);
523 CALL_FN_W_W(ret, fn, cond);
524 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000525}
526
527// pthread_cond_broadcast
sewardj347eeba2008-01-21 14:19:07 +0000528PTH_FUNC(int, pthreadZucondZubroadcastZa, // pthread_cond_broadcast*
bart3772a982008-03-15 08:11:03 +0000529 pthread_cond_t* cond)
sewardjaf44c822007-11-25 14:01:38 +0000530{
bart3772a982008-03-15 08:11:03 +0000531 int ret;
532 int res;
533 OrigFn fn;
534 VALGRIND_GET_ORIG_FN(fn);
535 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_COND_BROADCAST,
536 cond, 0, 0, 0, 0);
537 CALL_FN_W_W(ret, fn, cond);
538 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000539}
540
541
542// pthread_spin_init
543PTH_FUNC(int, pthreadZuspinZuinit, // pthread_spin_init
bart3772a982008-03-15 08:11:03 +0000544 pthread_spinlock_t *spinlock,
545 int pshared)
sewardjaf44c822007-11-25 14:01:38 +0000546{
bart3772a982008-03-15 08:11:03 +0000547 int ret;
548 int res;
549 OrigFn fn;
550 VALGRIND_GET_ORIG_FN(fn);
551 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__SPIN_INIT_OR_UNLOCK,
552 spinlock, mutex_type_spinlock, 0, 0, 0);
553 CALL_FN_W_WW(ret, fn, spinlock, pshared);
554 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000555}
556
557// pthread_spin_destroy
558PTH_FUNC(int, pthreadZuspinZudestroy, // pthread_spin_destroy
bart3772a982008-03-15 08:11:03 +0000559 pthread_spinlock_t *spinlock)
sewardjaf44c822007-11-25 14:01:38 +0000560{
bart3772a982008-03-15 08:11:03 +0000561 int ret;
562 int res;
563 OrigFn fn;
564 VALGRIND_GET_ORIG_FN(fn);
565 CALL_FN_W_W(ret, fn, spinlock);
566 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_MUTEX_DESTROY,
567 spinlock, mutex_type_spinlock, 0, 0, 0);
568 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000569}
570
571// pthread_spin_lock
572PTH_FUNC(int, pthreadZuspinZulock, // pthread_spin_lock
bart3772a982008-03-15 08:11:03 +0000573 pthread_spinlock_t *spinlock)
sewardjaf44c822007-11-25 14:01:38 +0000574{
bart3772a982008-03-15 08:11:03 +0000575 int ret;
576 int res;
577 OrigFn fn;
578 VALGRIND_GET_ORIG_FN(fn);
579 VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__PRE_MUTEX_LOCK,
580 spinlock, mutex_type_spinlock, 0, 0, 0);
581 CALL_FN_W_W(ret, fn, spinlock);
582 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_MUTEX_LOCK,
583 spinlock, ret == 0, 0, 0, 0);
584 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000585}
586
587// pthread_spin_trylock
588PTH_FUNC(int, pthreadZuspinZutrylock, // pthread_spin_trylock
bart3772a982008-03-15 08:11:03 +0000589 pthread_spinlock_t *spinlock)
sewardjaf44c822007-11-25 14:01:38 +0000590{
bart3772a982008-03-15 08:11:03 +0000591 int ret;
592 int res;
593 OrigFn fn;
594 VALGRIND_GET_ORIG_FN(fn);
595 VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__PRE_MUTEX_LOCK,
596 spinlock, mutex_type_spinlock, 0, 0, 0);
597 CALL_FN_W_W(ret, fn, spinlock);
598 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_MUTEX_LOCK,
599 spinlock, ret == 0, 0, 0, 0);
600 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000601}
602
603// pthread_spin_unlock
604PTH_FUNC(int, pthreadZuspinZuunlock, // pthread_spin_unlock
bart3772a982008-03-15 08:11:03 +0000605 pthread_spinlock_t *spinlock)
sewardjaf44c822007-11-25 14:01:38 +0000606{
bart3772a982008-03-15 08:11:03 +0000607 int ret;
608 int res;
609 OrigFn fn;
610 VALGRIND_GET_ORIG_FN(fn);
611 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__SPIN_INIT_OR_UNLOCK,
612 spinlock, mutex_type_spinlock, 0, 0, 0);
613 CALL_FN_W_W(ret, fn, spinlock);
614 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000615}
616
sewardj85642922008-01-14 11:54:56 +0000617// pthread_barrier_init
618PTH_FUNC(int, pthreadZubarrierZuinit, // pthread_barrier_init
bart3772a982008-03-15 08:11:03 +0000619 pthread_barrier_t* barrier,
620 const pthread_barrierattr_t* attr,
621 unsigned count)
sewardj85642922008-01-14 11:54:56 +0000622{
bart3772a982008-03-15 08:11:03 +0000623 int ret;
624 int res;
625 OrigFn fn;
626 VALGRIND_GET_ORIG_FN(fn);
627 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_BARRIER_INIT,
628 barrier, pthread_barrier, count, 0, 0);
629 CALL_FN_W_WWW(ret, fn, barrier, attr, count);
630 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_BARRIER_INIT,
631 barrier, pthread_barrier, 0, 0, 0);
632 return ret;
sewardj85642922008-01-14 11:54:56 +0000633}
634
635// pthread_barrier_destroy
636PTH_FUNC(int, pthreadZubarrierZudestroy, // pthread_barrier_destroy
bart3772a982008-03-15 08:11:03 +0000637 pthread_barrier_t* barrier)
sewardj85642922008-01-14 11:54:56 +0000638{
bart3772a982008-03-15 08:11:03 +0000639 int ret;
640 int res;
641 OrigFn fn;
642 VALGRIND_GET_ORIG_FN(fn);
643 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_BARRIER_DESTROY,
644 barrier, pthread_barrier, 0, 0, 0);
645 CALL_FN_W_W(ret, fn, barrier);
646 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_BARRIER_DESTROY,
647 barrier, pthread_barrier, 0, 0, 0);
648 return ret;
sewardj85642922008-01-14 11:54:56 +0000649}
650
651// pthread_barrier_wait
652PTH_FUNC(int, pthreadZubarrierZuwait, // pthread_barrier_wait
bart3772a982008-03-15 08:11:03 +0000653 pthread_barrier_t* barrier)
sewardj85642922008-01-14 11:54:56 +0000654{
bart3772a982008-03-15 08:11:03 +0000655 int ret;
656 int res;
657 OrigFn fn;
658 VALGRIND_GET_ORIG_FN(fn);
659 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_BARRIER_WAIT,
660 barrier, pthread_barrier, 0, 0, 0);
661 CALL_FN_W_W(ret, fn, barrier);
662 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_BARRIER_WAIT,
663 barrier, pthread_barrier,
664 ret == 0 || ret == PTHREAD_BARRIER_SERIAL_THREAD,
665 0, 0);
666 return ret;
sewardj85642922008-01-14 11:54:56 +0000667}
668
669
sewardj85642922008-01-14 11:54:56 +0000670// sem_init
bart368ec982008-03-11 20:39:01 +0000671PTH_FUNC(int, semZuinitZa, // sem_init*
bart3772a982008-03-15 08:11:03 +0000672 sem_t *sem,
673 int pshared,
674 unsigned int value)
sewardj85642922008-01-14 11:54:56 +0000675{
bart3772a982008-03-15 08:11:03 +0000676 int ret;
677 int res;
678 OrigFn fn;
679 VALGRIND_GET_ORIG_FN(fn);
680 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_SEM_INIT,
681 sem, pshared, value, 0, 0);
682 CALL_FN_W_WWW(ret, fn, sem, pshared, value);
683 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_SEM_INIT,
684 sem, 0, 0, 0, 0);
685 return ret;
sewardj85642922008-01-14 11:54:56 +0000686}
687
688// sem_destroy
bart00344642008-03-01 15:27:41 +0000689PTH_FUNC(int, semZudestroyZa, // sem_destroy*
bart3772a982008-03-15 08:11:03 +0000690 sem_t *sem)
sewardj85642922008-01-14 11:54:56 +0000691{
bart3772a982008-03-15 08:11:03 +0000692 int ret;
693 int res;
694 OrigFn fn;
695 VALGRIND_GET_ORIG_FN(fn);
696 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_SEM_DESTROY,
697 sem, 0, 0, 0, 0);
698 CALL_FN_W_W(ret, fn, sem);
699 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_SEM_DESTROY,
700 sem, 0, 0, 0, 0);
701 return ret;
sewardj85642922008-01-14 11:54:56 +0000702}
703
704// sem_wait
bart368ec982008-03-11 20:39:01 +0000705PTH_FUNC(int, semZuwaitZa, // sem_wait*
bart3772a982008-03-15 08:11:03 +0000706 sem_t *sem)
sewardj85642922008-01-14 11:54:56 +0000707{
bart3772a982008-03-15 08:11:03 +0000708 int ret;
709 int res;
710 OrigFn fn;
711 VALGRIND_GET_ORIG_FN(fn);
712 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_SEM_WAIT,
713 sem, 0, 0, 0, 0);
714 CALL_FN_W_W(ret, fn, sem);
715 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_SEM_WAIT,
716 sem, ret == 0, 0, 0, 0);
717 return ret;
sewardj85642922008-01-14 11:54:56 +0000718}
719
720// sem_trywait
bart00344642008-03-01 15:27:41 +0000721PTH_FUNC(int, semZutrywaitZa, // sem_trywait*
bart3772a982008-03-15 08:11:03 +0000722 sem_t *sem)
sewardj85642922008-01-14 11:54:56 +0000723{
bart3772a982008-03-15 08:11:03 +0000724 int ret;
725 int res;
726 OrigFn fn;
727 VALGRIND_GET_ORIG_FN(fn);
728 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_SEM_WAIT,
729 sem, 0, 0, 0, 0);
730 CALL_FN_W_W(ret, fn, sem);
731 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_SEM_WAIT,
732 sem, ret == 0, 0, 0, 0);
733 return ret;
sewardj85642922008-01-14 11:54:56 +0000734}
735
736// sem_timedwait
bart00344642008-03-01 15:27:41 +0000737PTH_FUNC(int, semZutimedwait, // sem_timedwait
bart3772a982008-03-15 08:11:03 +0000738 sem_t *sem, const struct timespec *abs_timeout)
sewardj85642922008-01-14 11:54:56 +0000739{
bart3772a982008-03-15 08:11:03 +0000740 int ret;
741 int res;
742 OrigFn fn;
743 VALGRIND_GET_ORIG_FN(fn);
744 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_SEM_WAIT,
745 sem, 0, 0, 0, 0);
746 CALL_FN_W_WW(ret, fn, sem, abs_timeout);
747 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_SEM_WAIT,
748 sem, ret == 0, 0, 0, 0);
749 return ret;
sewardj85642922008-01-14 11:54:56 +0000750}
751
752// sem_post
bart368ec982008-03-11 20:39:01 +0000753PTH_FUNC(int, semZupostZa, // sem_post*
bart3772a982008-03-15 08:11:03 +0000754 sem_t *sem)
sewardj85642922008-01-14 11:54:56 +0000755{
bart3772a982008-03-15 08:11:03 +0000756 int ret;
757 int res;
758 OrigFn fn;
759 VALGRIND_GET_ORIG_FN(fn);
760 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_SEM_POST,
761 sem, 0, 0, 0, 0);
762 CALL_FN_W_W(ret, fn, sem);
763 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_SEM_POST,
764 sem, ret == 0, 0, 0, 0);
765 return ret;
sewardj85642922008-01-14 11:54:56 +0000766}
767
bart00344642008-03-01 15:27:41 +0000768// pthread_rwlock_init
769PTH_FUNC(int,
770 pthreadZurwlockZuinitZa, // pthread_rwlock_init*
771 pthread_rwlock_t* rwlock,
772 const pthread_rwlockattr_t* attr)
773{
bart3772a982008-03-15 08:11:03 +0000774 int ret;
775 int res;
776 OrigFn fn;
777 VALGRIND_GET_ORIG_FN(fn);
778 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_RWLOCK_INIT,
779 rwlock, 0, 0, 0, 0);
780 CALL_FN_W_WW(ret, fn, rwlock, attr);
781 return ret;
bart00344642008-03-01 15:27:41 +0000782}
783
784// pthread_rwlock_destroy
785PTH_FUNC(int,
786 pthreadZurwlockZudestroyZa, // pthread_rwlock_destroy*
787 pthread_rwlock_t* rwlock)
788{
bart3772a982008-03-15 08:11:03 +0000789 int ret;
790 int res;
791 OrigFn fn;
792 VALGRIND_GET_ORIG_FN(fn);
793 CALL_FN_W_W(ret, fn, rwlock);
794 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_RWLOCK_DESTROY,
795 rwlock, 0, 0, 0, 0);
796 return ret;
bart00344642008-03-01 15:27:41 +0000797}
798
799// pthread_rwlock_rdlock
800PTH_FUNC(int,
801 pthreadZurwlockZurdlockZa, // pthread_rwlock_rdlock*
802 pthread_rwlock_t* rwlock)
803{
bart3772a982008-03-15 08:11:03 +0000804 int ret;
805 int res;
806 OrigFn fn;
807 VALGRIND_GET_ORIG_FN(fn);
808 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_RWLOCK_RDLOCK,
809 rwlock, 0, 0, 0, 0);
810 CALL_FN_W_W(ret, fn, rwlock);
811 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_RWLOCK_RDLOCK,
812 rwlock, ret == 0, 0, 0, 0);
813 return ret;
bart00344642008-03-01 15:27:41 +0000814}
815
816// pthread_rwlock_wrlock
817PTH_FUNC(int,
818 pthreadZurwlockZuwrlockZa, // pthread_rwlock_wrlock*
819 pthread_rwlock_t* rwlock)
820{
bart3772a982008-03-15 08:11:03 +0000821 int ret;
822 int res;
823 OrigFn fn;
824 VALGRIND_GET_ORIG_FN(fn);
825 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_RWLOCK_WRLOCK,
826 rwlock, 0, 0, 0, 0);
827 CALL_FN_W_W(ret, fn, rwlock);
828 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_RWLOCK_WRLOCK,
829 rwlock, ret == 0, 0, 0, 0);
830 return ret;
bart00344642008-03-01 15:27:41 +0000831}
832
833// pthread_rwlock_timedrdlock
834PTH_FUNC(int,
835 pthreadZurwlockZutimedrdlockZa, // pthread_rwlock_timedrdlock*
836 pthread_rwlock_t* rwlock)
837{
bart3772a982008-03-15 08:11:03 +0000838 int ret;
839 int res;
840 OrigFn fn;
841 VALGRIND_GET_ORIG_FN(fn);
842 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_RWLOCK_RDLOCK,
843 rwlock, 0, 0, 0, 0);
844 CALL_FN_W_W(ret, fn, rwlock);
845 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_RWLOCK_RDLOCK,
846 rwlock, ret == 0, 0, 0, 0);
847 return ret;
bart00344642008-03-01 15:27:41 +0000848}
849
850// pthread_rwlock_timedwrlock
851PTH_FUNC(int,
852 pthreadZurwlockZutimedwrlockZa, // pthread_rwlock_timedwrlock*
853 pthread_rwlock_t* rwlock)
854{
bart3772a982008-03-15 08:11:03 +0000855 int ret;
856 int res;
857 OrigFn fn;
858 VALGRIND_GET_ORIG_FN(fn);
859 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_RWLOCK_WRLOCK,
860 rwlock, 0, 0, 0, 0);
861 CALL_FN_W_W(ret, fn, rwlock);
862 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_RWLOCK_WRLOCK,
863 rwlock, ret == 0, 0, 0, 0);
864 return ret;
bart00344642008-03-01 15:27:41 +0000865}
866
867// pthread_rwlock_tryrdlock
868PTH_FUNC(int,
869 pthreadZurwlockZutryrdlockZa, // pthread_rwlock_tryrdlock*
870 pthread_rwlock_t* rwlock)
871{
bart3772a982008-03-15 08:11:03 +0000872 int ret;
873 int res;
874 OrigFn fn;
875 VALGRIND_GET_ORIG_FN(fn);
876 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_RWLOCK_RDLOCK,
877 rwlock, 0, 0, 0, 0);
878 CALL_FN_W_W(ret, fn, rwlock);
879 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_RWLOCK_RDLOCK,
880 rwlock, ret == 0, 0, 0, 0);
881 return ret;
bart00344642008-03-01 15:27:41 +0000882}
883
884// pthread_rwlock_trywrlock
885PTH_FUNC(int,
886 pthreadZurwlockZutrywrlockZa, // pthread_rwlock_trywrlock*
887 pthread_rwlock_t* rwlock)
888{
bart3772a982008-03-15 08:11:03 +0000889 int ret;
890 int res;
891 OrigFn fn;
892 VALGRIND_GET_ORIG_FN(fn);
893 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_RWLOCK_WRLOCK,
894 rwlock, 0, 0, 0, 0);
895 CALL_FN_W_W(ret, fn, rwlock);
896 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_RWLOCK_WRLOCK,
897 rwlock, ret == 0, 0, 0, 0);
898 return ret;
bart00344642008-03-01 15:27:41 +0000899}
900
901// pthread_rwlock_unlock
902PTH_FUNC(int,
903 pthreadZurwlockZuunlockZa, // pthread_rwlock_unlock*
904 pthread_rwlock_t* rwlock)
905{
bart3772a982008-03-15 08:11:03 +0000906 int ret;
907 int res;
908 OrigFn fn;
909 VALGRIND_GET_ORIG_FN(fn);
910 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_RWLOCK_UNLOCK,
911 rwlock, 0, 0, 0, 0);
912 CALL_FN_W_W(ret, fn, rwlock);
913 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_RWLOCK_UNLOCK,
914 rwlock, ret == 0, 0, 0, 0);
915 return ret;
bart00344642008-03-01 15:27:41 +0000916}