blob: e16845d106a22934dc5410a67d314f935055d16e [file] [log] [blame]
sewardjaf44c822007-11-25 14:01:38 +00001
2/*--------------------------------------------------------------------*/
bart3f4623e2008-07-07 16:53:07 +00003/*--- Client-space code for drd. drd_pthread_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();
bart0baacb32008-05-03 09:00:40 +0000100 vg_set_main_thread_state();
bart280990e2008-10-11 18:29:46 +0000101 /* glibc up to and including version 2.8 triggers conflicting accesses */
bart25d30032008-04-06 07:51:24 +0000102 /* 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);
barte8900ff2008-10-13 19:22:35 +0000106#if defined(HAVE_LIBC_FILE_LOCK)
bart3a979cb2008-10-11 19:04:40 +0000107 DRD_IGNORE_VAR(*(pthread_mutex_t*)(stdout->_lock));
108 DRD_IGNORE_VAR(*(pthread_mutex_t*)(stderr->_lock));
bart280990e2008-10-11 18:29:46 +0000109#endif
bart6f07b252008-04-04 16:45:20 +0000110}
sewardjaf44c822007-11-25 14:01:38 +0000111
bart5357fcb2008-02-27 15:46:00 +0000112static MutexT pthread_to_drd_mutex_type(const int kind)
113{
bart3772a982008-03-15 08:11:03 +0000114 switch (kind)
115 {
116 /* PTHREAD_MUTEX_RECURSIVE_NP */
117 case PTHREAD_MUTEX_RECURSIVE:
118 return mutex_type_recursive_mutex;
119 /* PTHREAD_MUTEX_ERRORCHECK_NP */
120 case PTHREAD_MUTEX_ERRORCHECK:
121 return mutex_type_errorcheck_mutex;
122 /* PTHREAD_MUTEX_TIMED_NP */
123 /* PTHREAD_MUTEX_NORMAL */
124 case PTHREAD_MUTEX_DEFAULT:
bart85569572008-05-03 09:15:25 +0000125#if defined(HAVE_PTHREAD_MUTEX_ADAPTIVE_NP)
bart3772a982008-03-15 08:11:03 +0000126 case PTHREAD_MUTEX_ADAPTIVE_NP:
bart85569572008-05-03 09:15:25 +0000127#endif
bart3772a982008-03-15 08:11:03 +0000128 return mutex_type_default_mutex;
129 }
130 return mutex_type_invalid_mutex;
bart5357fcb2008-02-27 15:46:00 +0000131}
132
bart2bc9c102008-09-27 12:40:57 +0000133/** @note The function mutex_type() has been declared inline in order
134 * to avoid that it shows up in call stacks.
135 */
136static __inline__ MutexT mutex_type(pthread_mutex_t* mutex)
bart5357fcb2008-02-27 15:46:00 +0000137{
bart5e389f12008-04-05 12:53:15 +0000138#if defined(HAVE_PTHREAD_MUTEX_T__M_KIND)
139 /* LinuxThreads. */
bart3772a982008-03-15 08:11:03 +0000140 const int kind = mutex->__m_kind;
bart5e389f12008-04-05 12:53:15 +0000141#elif defined(HAVE_PTHREAD_MUTEX_T__DATA__KIND)
142 /* NPTL. */
bart3772a982008-03-15 08:11:03 +0000143 const int kind = mutex->__data.__kind;
bartc9463c42008-02-28 07:36:04 +0000144#else
bart5e389f12008-04-05 12:53:15 +0000145 /* Another POSIX threads implementation. Regression tests will fail. */
bart3772a982008-03-15 08:11:03 +0000146 const int kind = PTHREAD_MUTEX_DEFAULT;
bart5e389f12008-04-05 12:53:15 +0000147 fprintf(stderr,
148 "Did not recognize your POSIX threads implementation. Giving up.\n");
149 assert(0);
bartc9463c42008-02-28 07:36:04 +0000150#endif
bart3772a982008-03-15 08:11:03 +0000151 return pthread_to_drd_mutex_type(kind);
bart5357fcb2008-02-27 15:46:00 +0000152}
153
sewardjaf44c822007-11-25 14:01:38 +0000154static void vg_start_suppression(const void* const p, size_t const size)
155{
bart3772a982008-03-15 08:11:03 +0000156 int res;
157 VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__DRD_START_SUPPRESSION,
bartf5bb46a2008-03-29 13:18:02 +0000158 p, size, 0, 0, 0);
sewardjaf44c822007-11-25 14:01:38 +0000159}
160
161static void vg_set_joinable(const pthread_t tid, const int joinable)
162{
bart3772a982008-03-15 08:11:03 +0000163 int res;
164 assert(joinable == 0 || joinable == 1);
165 VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__SET_JOINABLE,
166 tid, joinable, 0, 0, 0);
sewardjaf44c822007-11-25 14:01:38 +0000167}
168
169static void* vg_thread_wrapper(void* arg)
170{
bart3772a982008-03-15 08:11:03 +0000171 int res;
bart0d063002008-03-01 07:25:13 +0000172
bart3772a982008-03-15 08:11:03 +0000173 VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__DRD_SUPPRESS_CURRENT_STACK,
174 0, 0, 0, 0, 0);
sewardjaf44c822007-11-25 14:01:38 +0000175
bart3772a982008-03-15 08:11:03 +0000176 {
177 VgPosixThreadArgs* const arg_ptr = (VgPosixThreadArgs*)arg;
178 VgPosixThreadArgs const arg_copy = *arg_ptr;
179 void* result;
sewardjaf44c822007-11-25 14:01:38 +0000180
181#if 0
bart3772a982008-03-15 08:11:03 +0000182 pthread_mutex_lock(arg_ptr->mutex);
183 pthread_cond_signal(arg_ptr->cond);
184 pthread_mutex_unlock(arg_ptr->mutex);
sewardjaf44c822007-11-25 14:01:38 +0000185#else
bart3772a982008-03-15 08:11:03 +0000186 arg_ptr->wrapper_started = 1;
sewardjaf44c822007-11-25 14:01:38 +0000187#endif
188
bart3772a982008-03-15 08:11:03 +0000189 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__SET_PTHREADID,
190 pthread_self(), 0, 0, 0, 0);
191 vg_set_joinable(pthread_self(),
192 arg_copy.detachstate == PTHREAD_CREATE_JOINABLE);
193 result = (arg_copy.start)(arg_copy.arg);
194 return result;
195 }
sewardjaf44c822007-11-25 14:01:38 +0000196}
197
bart6f07b252008-04-04 16:45:20 +0000198/** Return 1 if LinuxThread has been detected, and 0 otherwise. */
bart4501d5c2008-03-04 18:36:23 +0000199static int detected_linuxthreads(void)
200{
201#if defined(linux)
202#if defined(_CS_GNU_LIBPTHREAD_VERSION)
bart3772a982008-03-15 08:11:03 +0000203 /* Linux with a recent glibc. */
204 char buffer[256];
205 unsigned len;
206 len = confstr(_CS_GNU_LIBPTHREAD_VERSION, buffer, sizeof(buffer));
207 assert(len <= sizeof(buffer));
208 return len > 0 && buffer[0] == 'l';
bart4501d5c2008-03-04 18:36:23 +0000209#else
bart3772a982008-03-15 08:11:03 +0000210 /* Linux without _CS_GNU_LIBPTHREAD_VERSION: most likely LinuxThreads. */
211 return 1;
bart4501d5c2008-03-04 18:36:23 +0000212#endif
213#else
bart3772a982008-03-15 08:11:03 +0000214 /* Another OS than Linux, hence no LinuxThreads. */
215 return 0;
bart4501d5c2008-03-04 18:36:23 +0000216#endif
217}
218
bart6f07b252008-04-04 16:45:20 +0000219/** Stop and print an error message in case a non-supported threading
220 * library (LinuxThreads) has been detected.
221 */
222static void check_threading_library(void)
sewardjaf44c822007-11-25 14:01:38 +0000223{
bart3772a982008-03-15 08:11:03 +0000224 if (detected_linuxthreads())
225 {
226 if (getenv("LD_ASSUME_KERNEL"))
227 {
228 fprintf(stderr,
229 "Detected the LinuxThreads threading library. Sorry, but DRD only supports\n"
230 "the newer NPTL (Native POSIX Threads Library). Please try to rerun DRD\n"
231 "after having unset the environment variable LD_ASSUME_KERNEL. Giving up.\n"
232 );
233 }
234 else
235 {
236 fprintf(stderr,
237 "Detected the LinuxThreads threading library. Sorry, but DRD only supports\n"
238 "the newer NPTL (Native POSIX Threads Library). Please try to rerun DRD\n"
239 "after having upgraded to a newer version of your Linux distribution.\n"
240 "Giving up.\n"
241 );
242 }
243 abort();
244 }
bart6f07b252008-04-04 16:45:20 +0000245}
246
247static void vg_set_main_thread_state(void)
248{
249 int res;
bart0d063002008-03-01 07:25:13 +0000250
bart3772a982008-03-15 08:11:03 +0000251 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__DRD_SUPPRESS_CURRENT_STACK,
252 0, 0, 0, 0, 0);
sewardjaf44c822007-11-25 14:01:38 +0000253
bart3772a982008-03-15 08:11:03 +0000254 // Make sure that DRD knows about the main thread's POSIX thread ID.
255 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__SET_PTHREADID,
256 pthread_self(), 0, 0, 0, 0);
sewardjaf44c822007-11-25 14:01:38 +0000257
258}
259
260// pthread_create
sewardj347eeba2008-01-21 14:19:07 +0000261PTH_FUNC(int, pthreadZucreateZa, // pthread_create*
bart3772a982008-03-15 08:11:03 +0000262 pthread_t *thread, const pthread_attr_t *attr,
263 void *(*start) (void *), void *arg)
sewardjaf44c822007-11-25 14:01:38 +0000264{
bartbf3a60c2008-04-04 19:10:21 +0000265 int res;
bart3772a982008-03-15 08:11:03 +0000266 int ret;
267 OrigFn fn;
268 VgPosixThreadArgs vgargs;
sewardjaf44c822007-11-25 14:01:38 +0000269
bart3772a982008-03-15 08:11:03 +0000270 VALGRIND_GET_ORIG_FN(fn);
sewardjaf44c822007-11-25 14:01:38 +0000271
bart3772a982008-03-15 08:11:03 +0000272 vg_start_suppression(&vgargs.wrapper_started,
273 sizeof(vgargs.wrapper_started));
274 vgargs.start = start;
275 vgargs.arg = arg;
276 vgargs.wrapper_started = 0;
277 vgargs.detachstate = PTHREAD_CREATE_JOINABLE;
278 if (attr)
279 {
280 if (pthread_attr_getdetachstate(attr, &vgargs.detachstate) != 0)
281 {
282 assert(0);
283 }
284 }
285 assert(vgargs.detachstate == PTHREAD_CREATE_JOINABLE
286 || vgargs.detachstate == PTHREAD_CREATE_DETACHED);
sewardjaf44c822007-11-25 14:01:38 +0000287#if 0
bart3772a982008-03-15 08:11:03 +0000288 pthread_mutex_init(&vgargs.mutex, 0);
289 pthread_cond_init(&vgargs.cond, 0);
290 pthread_mutex_lock(&vgargs.mutex);
sewardjaf44c822007-11-25 14:01:38 +0000291#endif
bartbf3a60c2008-04-04 19:10:21 +0000292 /* Suppress NPTL-specific conflicts between creator and created thread. */
293 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__DRD_STOP_RECORDING,
294 0, 0, 0, 0, 0);
bart3772a982008-03-15 08:11:03 +0000295 CALL_FN_W_WWWW(ret, fn, thread, attr, vg_thread_wrapper, &vgargs);
bartbf3a60c2008-04-04 19:10:21 +0000296 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__DRD_START_RECORDING,
297 0, 0, 0, 0, 0);
sewardjaf44c822007-11-25 14:01:38 +0000298#if 0
bart3772a982008-03-15 08:11:03 +0000299 pthread_cond_wait(&vgargs.cond, &vgargs.mutex);
300 pthread_mutex_unlock(&vgargs.mutex);
301 pthread_cond_destroy(&vgargs.cond);
302 pthread_mutex_destroy(&vgargs.mutex);
sewardjaf44c822007-11-25 14:01:38 +0000303#else
bart3772a982008-03-15 08:11:03 +0000304 // Yes, you see it correctly, busy waiting ... The problem is that
305 // POSIX threads functions cannot be called here -- the functions defined
306 // in this file (drd_intercepts.c) would be called instead of those in
307 // libpthread.so. This loop is necessary because vgargs is allocated on the
308 // stack, and the created thread reads it.
309 if (ret == 0)
310 {
311 while (! vgargs.wrapper_started)
312 {
313 sched_yield();
314 }
315 }
sewardjaf44c822007-11-25 14:01:38 +0000316#endif
bart3772a982008-03-15 08:11:03 +0000317 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000318}
319
320// pthread_join
321PTH_FUNC(int, pthreadZujoin, // pthread_join
bart3772a982008-03-15 08:11:03 +0000322 pthread_t pt_joinee, void **thread_return)
sewardjaf44c822007-11-25 14:01:38 +0000323{
bart3772a982008-03-15 08:11:03 +0000324 int ret;
325 int res;
326 OrigFn fn;
sewardjaf44c822007-11-25 14:01:38 +0000327
bart3772a982008-03-15 08:11:03 +0000328 VALGRIND_GET_ORIG_FN(fn);
329 CALL_FN_W_WW(ret, fn, pt_joinee, thread_return);
330 if (ret == 0)
331 {
332 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_THREAD_JOIN,
333 pt_joinee, 0, 0, 0, 0);
334 }
335 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000336}
337
338// pthread_detach
339PTH_FUNC(int, pthreadZudetach, pthread_t pt_thread)
340{
bart3772a982008-03-15 08:11:03 +0000341 int ret;
342 OrigFn fn;
343 VALGRIND_GET_ORIG_FN(fn);
344 {
345 CALL_FN_W_W(ret, fn, pt_thread);
346 if (ret == 0)
347 {
348 vg_set_joinable(pt_thread, 0);
349 }
350 }
351 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000352}
353
bart2bc9c102008-09-27 12:40:57 +0000354// pthread_cancel
355PTH_FUNC(int, pthreadZucancel, pthread_t pt_thread)
356{
357 int res;
358 int ret;
359 OrigFn fn;
360 VALGRIND_GET_ORIG_FN(fn);
361 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_THREAD_CANCEL,
362 pt_thread, 0, 0, 0, 0);
363 CALL_FN_W_W(ret, fn, pt_thread);
364 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_THREAD_CANCEL,
365 pt_thread, ret==0, 0, 0, 0);
366 return ret;
367}
368
sewardjaf44c822007-11-25 14:01:38 +0000369// pthread_mutex_init
370PTH_FUNC(int, pthreadZumutexZuinit,
bart3772a982008-03-15 08:11:03 +0000371 pthread_mutex_t *mutex,
372 const pthread_mutexattr_t* attr)
sewardjaf44c822007-11-25 14:01:38 +0000373{
bart3772a982008-03-15 08:11:03 +0000374 int ret;
375 int res;
376 OrigFn fn;
377 int mt;
378 VALGRIND_GET_ORIG_FN(fn);
379 mt = PTHREAD_MUTEX_DEFAULT;
380 if (attr)
381 pthread_mutexattr_gettype(attr, &mt);
382 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_MUTEX_INIT,
383 mutex, pthread_to_drd_mutex_type(mt), 0, 0, 0);
384 CALL_FN_W_WW(ret, fn, mutex, attr);
385 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_MUTEX_INIT,
386 mutex, 0, 0, 0, 0);
387 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000388}
389
390// pthread_mutex_destroy
391PTH_FUNC(int, pthreadZumutexZudestroy,
bart3772a982008-03-15 08:11:03 +0000392 pthread_mutex_t *mutex)
sewardjaf44c822007-11-25 14:01:38 +0000393{
bart3772a982008-03-15 08:11:03 +0000394 int ret;
395 int res;
396 OrigFn fn;
397 VALGRIND_GET_ORIG_FN(fn);
398 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_MUTEX_DESTROY,
399 mutex, 0, 0, 0, 0);
400 CALL_FN_W_W(ret, fn, mutex);
401 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_MUTEX_DESTROY,
402 mutex, mutex_type(mutex), 0, 0, 0);
403 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000404}
405
406// pthread_mutex_lock
407PTH_FUNC(int, pthreadZumutexZulock, // pthread_mutex_lock
bart3772a982008-03-15 08:11:03 +0000408 pthread_mutex_t *mutex)
sewardjaf44c822007-11-25 14:01:38 +0000409{
bart3772a982008-03-15 08:11:03 +0000410 int ret;
411 int res;
412 OrigFn fn;
413 VALGRIND_GET_ORIG_FN(fn);
414 VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__PRE_MUTEX_LOCK,
415 mutex, mutex_type(mutex), 0, 0, 0);
416 CALL_FN_W_W(ret, fn, mutex);
417 VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__POST_MUTEX_LOCK,
418 mutex, ret == 0, 0, 0, 0);
419 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000420}
421
422// pthread_mutex_trylock
423PTH_FUNC(int, pthreadZumutexZutrylock, // pthread_mutex_trylock
bart3772a982008-03-15 08:11:03 +0000424 pthread_mutex_t *mutex)
sewardjaf44c822007-11-25 14:01:38 +0000425{
bart3772a982008-03-15 08:11:03 +0000426 int ret;
427 int res;
428 OrigFn fn;
429 VALGRIND_GET_ORIG_FN(fn);
430 VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__PRE_MUTEX_LOCK,
bart2e3a3c12008-03-24 08:33:47 +0000431 mutex, mutex_type(mutex), 1, 0, 0);
bart3772a982008-03-15 08:11:03 +0000432 CALL_FN_W_W(ret, fn, mutex);
433 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_MUTEX_LOCK,
434 mutex, ret == 0, 0, 0, 0);
435 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000436}
437
sewardj85642922008-01-14 11:54:56 +0000438// pthread_mutex_timedlock
439PTH_FUNC(int, pthreadZumutexZutimedlock, // pthread_mutex_timedlock
bart3772a982008-03-15 08:11:03 +0000440 pthread_mutex_t *mutex,
441 const struct timespec *abs_timeout)
sewardj85642922008-01-14 11:54:56 +0000442{
bart3772a982008-03-15 08:11:03 +0000443 int ret;
444 int res;
445 OrigFn fn;
446 VALGRIND_GET_ORIG_FN(fn);
447 VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__PRE_MUTEX_LOCK,
448 mutex, mutex_type(mutex), 0, 0, 0);
449 CALL_FN_W_WW(ret, fn, mutex, abs_timeout);
450 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_MUTEX_LOCK,
451 mutex, ret == 0, 0, 0, 0);
452 return ret;
sewardj85642922008-01-14 11:54:56 +0000453}
454
sewardjaf44c822007-11-25 14:01:38 +0000455// pthread_mutex_unlock
456PTH_FUNC(int, pthreadZumutexZuunlock, // pthread_mutex_unlock
bart3772a982008-03-15 08:11:03 +0000457 pthread_mutex_t *mutex)
sewardjaf44c822007-11-25 14:01:38 +0000458{
bart3772a982008-03-15 08:11:03 +0000459 int ret;
460 int res;
461 OrigFn fn;
462 VALGRIND_GET_ORIG_FN(fn);
463 VALGRIND_DO_CLIENT_REQUEST(res, -1,
464 VG_USERREQ__PRE_MUTEX_UNLOCK,
465 mutex, mutex_type(mutex), 0, 0, 0);
466 CALL_FN_W_W(ret, fn, mutex);
467 VALGRIND_DO_CLIENT_REQUEST(res, -1,
468 VG_USERREQ__POST_MUTEX_UNLOCK,
469 mutex, 0, 0, 0, 0);
470 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000471}
472
473// pthread_cond_init
sewardj347eeba2008-01-21 14:19:07 +0000474PTH_FUNC(int, pthreadZucondZuinitZa, // pthread_cond_init*
bart3772a982008-03-15 08:11:03 +0000475 pthread_cond_t* cond,
476 const pthread_condattr_t* attr)
sewardjaf44c822007-11-25 14:01:38 +0000477{
bart3772a982008-03-15 08:11:03 +0000478 int ret;
479 int res;
480 OrigFn fn;
481 VALGRIND_GET_ORIG_FN(fn);
482 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_COND_INIT,
483 cond, 0, 0, 0, 0);
484 CALL_FN_W_WW(ret, fn, cond, attr);
bart3f4623e2008-07-07 16:53:07 +0000485 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_COND_INIT,
486 cond, 0, 0, 0, 0);
bart3772a982008-03-15 08:11:03 +0000487 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000488}
489
490// pthread_cond_destroy
sewardj347eeba2008-01-21 14:19:07 +0000491PTH_FUNC(int, pthreadZucondZudestroyZa, // pthread_cond_destroy*
bart3772a982008-03-15 08:11:03 +0000492 pthread_cond_t* cond)
sewardjaf44c822007-11-25 14:01:38 +0000493{
bart3772a982008-03-15 08:11:03 +0000494 int ret;
495 int res;
496 OrigFn fn;
497 VALGRIND_GET_ORIG_FN(fn);
bart3f4623e2008-07-07 16:53:07 +0000498 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_COND_DESTROY,
499 cond, 0, 0, 0, 0);
bart3772a982008-03-15 08:11:03 +0000500 CALL_FN_W_W(ret, fn, cond);
501 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_COND_DESTROY,
502 cond, 0, 0, 0, 0);
503 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000504}
505
506// pthread_cond_wait
sewardj347eeba2008-01-21 14:19:07 +0000507PTH_FUNC(int, pthreadZucondZuwaitZa, // pthread_cond_wait*
bart3772a982008-03-15 08:11:03 +0000508 pthread_cond_t *cond,
509 pthread_mutex_t *mutex)
sewardjaf44c822007-11-25 14:01:38 +0000510{
bart3772a982008-03-15 08:11:03 +0000511 int ret;
512 int res;
513 OrigFn fn;
514 VALGRIND_GET_ORIG_FN(fn);
515 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_COND_WAIT,
516 cond, mutex, mutex_type(mutex), 0, 0);
517 CALL_FN_W_WW(ret, fn, cond, mutex);
518 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_COND_WAIT,
bart1b7a8302008-03-30 08:39:51 +0000519 cond, mutex, 1, 0, 0);
bart3772a982008-03-15 08:11:03 +0000520 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000521}
522
523// pthread_cond_timedwait
sewardj347eeba2008-01-21 14:19:07 +0000524PTH_FUNC(int, pthreadZucondZutimedwaitZa, // pthread_cond_timedwait*
bart3772a982008-03-15 08:11:03 +0000525 pthread_cond_t *cond,
526 pthread_mutex_t *mutex,
527 const struct timespec* abstime)
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_WAIT,
534 cond, mutex, mutex_type(mutex), 0, 0);
535 CALL_FN_W_WWW(ret, fn, cond, mutex, abstime);
536 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_COND_WAIT,
bart1b7a8302008-03-30 08:39:51 +0000537 cond, mutex, 1, 0, 0);
bart3772a982008-03-15 08:11:03 +0000538 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000539}
540
541// pthread_cond_signal
sewardj347eeba2008-01-21 14:19:07 +0000542PTH_FUNC(int, pthreadZucondZusignalZa, // pthread_cond_signal*
bart3772a982008-03-15 08:11:03 +0000543 pthread_cond_t* cond)
sewardjaf44c822007-11-25 14:01:38 +0000544{
bart3772a982008-03-15 08:11:03 +0000545 int ret;
546 int res;
547 OrigFn fn;
548 VALGRIND_GET_ORIG_FN(fn);
549 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_COND_SIGNAL,
550 cond, 0, 0, 0, 0);
551 CALL_FN_W_W(ret, fn, cond);
bart3f4623e2008-07-07 16:53:07 +0000552 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_COND_SIGNAL,
553 cond, 0, 0, 0, 0);
bart3772a982008-03-15 08:11:03 +0000554 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000555}
556
557// pthread_cond_broadcast
sewardj347eeba2008-01-21 14:19:07 +0000558PTH_FUNC(int, pthreadZucondZubroadcastZa, // pthread_cond_broadcast*
bart3772a982008-03-15 08:11:03 +0000559 pthread_cond_t* cond)
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 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_COND_BROADCAST,
566 cond, 0, 0, 0, 0);
567 CALL_FN_W_W(ret, fn, cond);
bart3f4623e2008-07-07 16:53:07 +0000568 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_COND_BROADCAST,
569 cond, 0, 0, 0, 0);
bart3772a982008-03-15 08:11:03 +0000570 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000571}
572
573
574// pthread_spin_init
575PTH_FUNC(int, pthreadZuspinZuinit, // pthread_spin_init
bart3772a982008-03-15 08:11:03 +0000576 pthread_spinlock_t *spinlock,
577 int pshared)
sewardjaf44c822007-11-25 14:01:38 +0000578{
bart3772a982008-03-15 08:11:03 +0000579 int ret;
580 int res;
581 OrigFn fn;
582 VALGRIND_GET_ORIG_FN(fn);
bartf4f05812008-07-07 08:10:56 +0000583 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_SPIN_INIT_OR_UNLOCK,
584 spinlock, 0, 0, 0, 0);
bart3772a982008-03-15 08:11:03 +0000585 CALL_FN_W_WW(ret, fn, spinlock, pshared);
bartf4f05812008-07-07 08:10:56 +0000586 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_SPIN_INIT_OR_UNLOCK,
587 spinlock, 0, 0, 0, 0);
bart3772a982008-03-15 08:11:03 +0000588 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000589}
590
591// pthread_spin_destroy
592PTH_FUNC(int, pthreadZuspinZudestroy, // pthread_spin_destroy
bart3772a982008-03-15 08:11:03 +0000593 pthread_spinlock_t *spinlock)
sewardjaf44c822007-11-25 14:01:38 +0000594{
bart3772a982008-03-15 08:11:03 +0000595 int ret;
596 int res;
597 OrigFn fn;
598 VALGRIND_GET_ORIG_FN(fn);
bartf4f05812008-07-07 08:10:56 +0000599 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_MUTEX_DESTROY,
600 spinlock, 0, 0, 0, 0);
bart3772a982008-03-15 08:11:03 +0000601 CALL_FN_W_W(ret, fn, spinlock);
602 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_MUTEX_DESTROY,
603 spinlock, mutex_type_spinlock, 0, 0, 0);
604 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000605}
606
607// pthread_spin_lock
608PTH_FUNC(int, pthreadZuspinZulock, // pthread_spin_lock
bart3772a982008-03-15 08:11:03 +0000609 pthread_spinlock_t *spinlock)
sewardjaf44c822007-11-25 14:01:38 +0000610{
bart3772a982008-03-15 08:11:03 +0000611 int ret;
612 int res;
613 OrigFn fn;
614 VALGRIND_GET_ORIG_FN(fn);
615 VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__PRE_MUTEX_LOCK,
616 spinlock, mutex_type_spinlock, 0, 0, 0);
617 CALL_FN_W_W(ret, fn, spinlock);
618 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_MUTEX_LOCK,
619 spinlock, ret == 0, 0, 0, 0);
620 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000621}
622
623// pthread_spin_trylock
624PTH_FUNC(int, pthreadZuspinZutrylock, // pthread_spin_trylock
bart3772a982008-03-15 08:11:03 +0000625 pthread_spinlock_t *spinlock)
sewardjaf44c822007-11-25 14:01:38 +0000626{
bart3772a982008-03-15 08:11:03 +0000627 int ret;
628 int res;
629 OrigFn fn;
630 VALGRIND_GET_ORIG_FN(fn);
631 VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__PRE_MUTEX_LOCK,
632 spinlock, mutex_type_spinlock, 0, 0, 0);
633 CALL_FN_W_W(ret, fn, spinlock);
634 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_MUTEX_LOCK,
635 spinlock, ret == 0, 0, 0, 0);
636 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000637}
638
639// pthread_spin_unlock
640PTH_FUNC(int, pthreadZuspinZuunlock, // pthread_spin_unlock
bart3772a982008-03-15 08:11:03 +0000641 pthread_spinlock_t *spinlock)
sewardjaf44c822007-11-25 14:01:38 +0000642{
bart3772a982008-03-15 08:11:03 +0000643 int ret;
644 int res;
645 OrigFn fn;
646 VALGRIND_GET_ORIG_FN(fn);
bartf4f05812008-07-07 08:10:56 +0000647 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_SPIN_INIT_OR_UNLOCK,
bart3772a982008-03-15 08:11:03 +0000648 spinlock, mutex_type_spinlock, 0, 0, 0);
649 CALL_FN_W_W(ret, fn, spinlock);
bartf4f05812008-07-07 08:10:56 +0000650 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_SPIN_INIT_OR_UNLOCK,
651 spinlock, 0, 0, 0, 0);
bart3772a982008-03-15 08:11:03 +0000652 return ret;
sewardjaf44c822007-11-25 14:01:38 +0000653}
654
sewardj85642922008-01-14 11:54:56 +0000655// pthread_barrier_init
656PTH_FUNC(int, pthreadZubarrierZuinit, // pthread_barrier_init
bart3772a982008-03-15 08:11:03 +0000657 pthread_barrier_t* barrier,
658 const pthread_barrierattr_t* attr,
659 unsigned count)
sewardj85642922008-01-14 11:54:56 +0000660{
bart3772a982008-03-15 08:11:03 +0000661 int ret;
662 int res;
663 OrigFn fn;
664 VALGRIND_GET_ORIG_FN(fn);
665 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_BARRIER_INIT,
666 barrier, pthread_barrier, count, 0, 0);
667 CALL_FN_W_WWW(ret, fn, barrier, attr, count);
668 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_BARRIER_INIT,
669 barrier, pthread_barrier, 0, 0, 0);
670 return ret;
sewardj85642922008-01-14 11:54:56 +0000671}
672
673// pthread_barrier_destroy
674PTH_FUNC(int, pthreadZubarrierZudestroy, // pthread_barrier_destroy
bart3772a982008-03-15 08:11:03 +0000675 pthread_barrier_t* barrier)
sewardj85642922008-01-14 11:54:56 +0000676{
bart3772a982008-03-15 08:11:03 +0000677 int ret;
678 int res;
679 OrigFn fn;
680 VALGRIND_GET_ORIG_FN(fn);
681 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_BARRIER_DESTROY,
682 barrier, pthread_barrier, 0, 0, 0);
683 CALL_FN_W_W(ret, fn, barrier);
684 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_BARRIER_DESTROY,
685 barrier, pthread_barrier, 0, 0, 0);
686 return ret;
sewardj85642922008-01-14 11:54:56 +0000687}
688
689// pthread_barrier_wait
690PTH_FUNC(int, pthreadZubarrierZuwait, // pthread_barrier_wait
bart3772a982008-03-15 08:11:03 +0000691 pthread_barrier_t* barrier)
sewardj85642922008-01-14 11:54:56 +0000692{
bart3772a982008-03-15 08:11:03 +0000693 int ret;
694 int res;
695 OrigFn fn;
696 VALGRIND_GET_ORIG_FN(fn);
697 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_BARRIER_WAIT,
698 barrier, pthread_barrier, 0, 0, 0);
699 CALL_FN_W_W(ret, fn, barrier);
700 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_BARRIER_WAIT,
701 barrier, pthread_barrier,
702 ret == 0 || ret == PTHREAD_BARRIER_SERIAL_THREAD,
703 0, 0);
704 return ret;
sewardj85642922008-01-14 11:54:56 +0000705}
706
707
sewardj85642922008-01-14 11:54:56 +0000708// sem_init
bart368ec982008-03-11 20:39:01 +0000709PTH_FUNC(int, semZuinitZa, // sem_init*
bart3772a982008-03-15 08:11:03 +0000710 sem_t *sem,
711 int pshared,
712 unsigned int value)
sewardj85642922008-01-14 11:54:56 +0000713{
bart3772a982008-03-15 08:11:03 +0000714 int ret;
715 int res;
716 OrigFn fn;
717 VALGRIND_GET_ORIG_FN(fn);
718 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_SEM_INIT,
719 sem, pshared, value, 0, 0);
720 CALL_FN_W_WWW(ret, fn, sem, pshared, value);
721 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_SEM_INIT,
722 sem, 0, 0, 0, 0);
723 return ret;
sewardj85642922008-01-14 11:54:56 +0000724}
725
726// sem_destroy
bart00344642008-03-01 15:27:41 +0000727PTH_FUNC(int, semZudestroyZa, // sem_destroy*
bart3772a982008-03-15 08:11:03 +0000728 sem_t *sem)
sewardj85642922008-01-14 11:54:56 +0000729{
bart3772a982008-03-15 08:11:03 +0000730 int ret;
731 int res;
732 OrigFn fn;
733 VALGRIND_GET_ORIG_FN(fn);
734 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_SEM_DESTROY,
735 sem, 0, 0, 0, 0);
736 CALL_FN_W_W(ret, fn, sem);
737 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_SEM_DESTROY,
738 sem, 0, 0, 0, 0);
739 return ret;
sewardj85642922008-01-14 11:54:56 +0000740}
741
742// sem_wait
bart368ec982008-03-11 20:39:01 +0000743PTH_FUNC(int, semZuwaitZa, // sem_wait*
bart3772a982008-03-15 08:11:03 +0000744 sem_t *sem)
sewardj85642922008-01-14 11:54:56 +0000745{
bart3772a982008-03-15 08:11:03 +0000746 int ret;
747 int res;
748 OrigFn fn;
749 VALGRIND_GET_ORIG_FN(fn);
750 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_SEM_WAIT,
751 sem, 0, 0, 0, 0);
752 CALL_FN_W_W(ret, fn, sem);
753 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_SEM_WAIT,
754 sem, ret == 0, 0, 0, 0);
755 return ret;
sewardj85642922008-01-14 11:54:56 +0000756}
757
758// sem_trywait
bart00344642008-03-01 15:27:41 +0000759PTH_FUNC(int, semZutrywaitZa, // sem_trywait*
bart3772a982008-03-15 08:11:03 +0000760 sem_t *sem)
sewardj85642922008-01-14 11:54:56 +0000761{
bart3772a982008-03-15 08:11:03 +0000762 int ret;
763 int res;
764 OrigFn fn;
765 VALGRIND_GET_ORIG_FN(fn);
766 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_SEM_WAIT,
767 sem, 0, 0, 0, 0);
768 CALL_FN_W_W(ret, fn, sem);
769 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_SEM_WAIT,
770 sem, ret == 0, 0, 0, 0);
771 return ret;
sewardj85642922008-01-14 11:54:56 +0000772}
773
774// sem_timedwait
bart00344642008-03-01 15:27:41 +0000775PTH_FUNC(int, semZutimedwait, // sem_timedwait
bart3772a982008-03-15 08:11:03 +0000776 sem_t *sem, const struct timespec *abs_timeout)
sewardj85642922008-01-14 11:54:56 +0000777{
bart3772a982008-03-15 08:11:03 +0000778 int ret;
779 int res;
780 OrigFn fn;
781 VALGRIND_GET_ORIG_FN(fn);
782 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_SEM_WAIT,
783 sem, 0, 0, 0, 0);
784 CALL_FN_W_WW(ret, fn, sem, abs_timeout);
785 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_SEM_WAIT,
786 sem, ret == 0, 0, 0, 0);
787 return ret;
sewardj85642922008-01-14 11:54:56 +0000788}
789
790// sem_post
bart368ec982008-03-11 20:39:01 +0000791PTH_FUNC(int, semZupostZa, // sem_post*
bart3772a982008-03-15 08:11:03 +0000792 sem_t *sem)
sewardj85642922008-01-14 11:54:56 +0000793{
bart3772a982008-03-15 08:11:03 +0000794 int ret;
795 int res;
796 OrigFn fn;
797 VALGRIND_GET_ORIG_FN(fn);
798 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_SEM_POST,
799 sem, 0, 0, 0, 0);
800 CALL_FN_W_W(ret, fn, sem);
801 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_SEM_POST,
802 sem, ret == 0, 0, 0, 0);
803 return ret;
sewardj85642922008-01-14 11:54:56 +0000804}
805
bart00344642008-03-01 15:27:41 +0000806// pthread_rwlock_init
807PTH_FUNC(int,
808 pthreadZurwlockZuinitZa, // pthread_rwlock_init*
809 pthread_rwlock_t* rwlock,
810 const pthread_rwlockattr_t* attr)
811{
bart3772a982008-03-15 08:11:03 +0000812 int ret;
813 int res;
814 OrigFn fn;
815 VALGRIND_GET_ORIG_FN(fn);
816 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_RWLOCK_INIT,
817 rwlock, 0, 0, 0, 0);
818 CALL_FN_W_WW(ret, fn, rwlock, attr);
819 return ret;
bart00344642008-03-01 15:27:41 +0000820}
821
822// pthread_rwlock_destroy
823PTH_FUNC(int,
824 pthreadZurwlockZudestroyZa, // pthread_rwlock_destroy*
825 pthread_rwlock_t* rwlock)
826{
bart3772a982008-03-15 08:11:03 +0000827 int ret;
828 int res;
829 OrigFn fn;
830 VALGRIND_GET_ORIG_FN(fn);
831 CALL_FN_W_W(ret, fn, rwlock);
832 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_RWLOCK_DESTROY,
833 rwlock, 0, 0, 0, 0);
834 return ret;
bart00344642008-03-01 15:27:41 +0000835}
836
837// pthread_rwlock_rdlock
838PTH_FUNC(int,
839 pthreadZurwlockZurdlockZa, // pthread_rwlock_rdlock*
840 pthread_rwlock_t* rwlock)
841{
bart3772a982008-03-15 08:11:03 +0000842 int ret;
843 int res;
844 OrigFn fn;
845 VALGRIND_GET_ORIG_FN(fn);
846 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_RWLOCK_RDLOCK,
847 rwlock, 0, 0, 0, 0);
848 CALL_FN_W_W(ret, fn, rwlock);
849 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_RWLOCK_RDLOCK,
850 rwlock, ret == 0, 0, 0, 0);
851 return ret;
bart00344642008-03-01 15:27:41 +0000852}
853
854// pthread_rwlock_wrlock
855PTH_FUNC(int,
856 pthreadZurwlockZuwrlockZa, // pthread_rwlock_wrlock*
857 pthread_rwlock_t* rwlock)
858{
bart3772a982008-03-15 08:11:03 +0000859 int ret;
860 int res;
861 OrigFn fn;
862 VALGRIND_GET_ORIG_FN(fn);
863 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_RWLOCK_WRLOCK,
864 rwlock, 0, 0, 0, 0);
865 CALL_FN_W_W(ret, fn, rwlock);
866 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_RWLOCK_WRLOCK,
867 rwlock, ret == 0, 0, 0, 0);
868 return ret;
bart00344642008-03-01 15:27:41 +0000869}
870
871// pthread_rwlock_timedrdlock
872PTH_FUNC(int,
873 pthreadZurwlockZutimedrdlockZa, // pthread_rwlock_timedrdlock*
874 pthread_rwlock_t* rwlock)
875{
bart3772a982008-03-15 08:11:03 +0000876 int ret;
877 int res;
878 OrigFn fn;
879 VALGRIND_GET_ORIG_FN(fn);
880 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_RWLOCK_RDLOCK,
881 rwlock, 0, 0, 0, 0);
882 CALL_FN_W_W(ret, fn, rwlock);
883 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_RWLOCK_RDLOCK,
884 rwlock, ret == 0, 0, 0, 0);
885 return ret;
bart00344642008-03-01 15:27:41 +0000886}
887
888// pthread_rwlock_timedwrlock
889PTH_FUNC(int,
890 pthreadZurwlockZutimedwrlockZa, // pthread_rwlock_timedwrlock*
891 pthread_rwlock_t* rwlock)
892{
bart3772a982008-03-15 08:11:03 +0000893 int ret;
894 int res;
895 OrigFn fn;
896 VALGRIND_GET_ORIG_FN(fn);
897 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_RWLOCK_WRLOCK,
898 rwlock, 0, 0, 0, 0);
899 CALL_FN_W_W(ret, fn, rwlock);
900 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_RWLOCK_WRLOCK,
901 rwlock, ret == 0, 0, 0, 0);
902 return ret;
bart00344642008-03-01 15:27:41 +0000903}
904
905// pthread_rwlock_tryrdlock
906PTH_FUNC(int,
907 pthreadZurwlockZutryrdlockZa, // pthread_rwlock_tryrdlock*
908 pthread_rwlock_t* rwlock)
909{
bart3772a982008-03-15 08:11:03 +0000910 int ret;
911 int res;
912 OrigFn fn;
913 VALGRIND_GET_ORIG_FN(fn);
914 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_RWLOCK_RDLOCK,
915 rwlock, 0, 0, 0, 0);
916 CALL_FN_W_W(ret, fn, rwlock);
917 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_RWLOCK_RDLOCK,
918 rwlock, ret == 0, 0, 0, 0);
919 return ret;
bart00344642008-03-01 15:27:41 +0000920}
921
922// pthread_rwlock_trywrlock
923PTH_FUNC(int,
924 pthreadZurwlockZutrywrlockZa, // pthread_rwlock_trywrlock*
925 pthread_rwlock_t* rwlock)
926{
bart3772a982008-03-15 08:11:03 +0000927 int ret;
928 int res;
929 OrigFn fn;
930 VALGRIND_GET_ORIG_FN(fn);
931 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_RWLOCK_WRLOCK,
932 rwlock, 0, 0, 0, 0);
933 CALL_FN_W_W(ret, fn, rwlock);
934 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_RWLOCK_WRLOCK,
935 rwlock, ret == 0, 0, 0, 0);
936 return ret;
bart00344642008-03-01 15:27:41 +0000937}
938
939// pthread_rwlock_unlock
940PTH_FUNC(int,
941 pthreadZurwlockZuunlockZa, // pthread_rwlock_unlock*
942 pthread_rwlock_t* rwlock)
943{
bart3772a982008-03-15 08:11:03 +0000944 int ret;
945 int res;
946 OrigFn fn;
947 VALGRIND_GET_ORIG_FN(fn);
948 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_RWLOCK_UNLOCK,
949 rwlock, 0, 0, 0, 0);
950 CALL_FN_W_W(ret, fn, rwlock);
951 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_RWLOCK_UNLOCK,
952 rwlock, ret == 0, 0, 0, 0);
953 return ret;
bart00344642008-03-01 15:27:41 +0000954}