drd_pthread_intercepts.c revision 292c1e20f3db3170c185b94b0f3cecbac06d6a04
10a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
20a8c90248264a8b26970b4473770bcc3df8515fJosh Gao/*--------------------------------------------------------------------*/
30a8c90248264a8b26970b4473770bcc3df8515fJosh Gao/*--- Client-space code for drd.          drd_pthread_intercepts.c ---*/
40a8c90248264a8b26970b4473770bcc3df8515fJosh Gao/*--------------------------------------------------------------------*/
50a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
60a8c90248264a8b26970b4473770bcc3df8515fJosh Gao/*
70a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  This file is part of drd, a data race detector.
80a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
90a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  Copyright (C) 2006-2008 Bart Van Assche
100a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  bart.vanassche@gmail.com
110a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
120a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  This program is free software; you can redistribute it and/or
130a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  modify it under the terms of the GNU General Public License as
140a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  published by the Free Software Foundation; either version 2 of the
150a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  License, or (at your option) any later version.
160a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
170a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  This program is distributed in the hope that it will be useful, but
180a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  WITHOUT ANY WARRANTY; without even the implied warranty of
190a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
200a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  General Public License for more details.
210a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
220a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  You should have received a copy of the GNU General Public License
230a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  along with this program; if not, write to the Free Software
240a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
250a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  02111-1307, USA.
260a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
270a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  The GNU General Public License is contained in the file COPYING.
280a8c90248264a8b26970b4473770bcc3df8515fJosh Gao*/
290a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
300a8c90248264a8b26970b4473770bcc3df8515fJosh Gao/* ---------------------------------------------------------------------
310a8c90248264a8b26970b4473770bcc3df8515fJosh Gao   ALL THE CODE IN THIS FILE RUNS ON THE SIMULATED CPU.
320a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
330a8c90248264a8b26970b4473770bcc3df8515fJosh Gao   These functions are not called directly - they're the targets of code
340a8c90248264a8b26970b4473770bcc3df8515fJosh Gao   redirection or load notifications (see pub_core_redir.h for info).
350a8c90248264a8b26970b4473770bcc3df8515fJosh Gao   They're named weirdly so that the intercept code can find them when the
360a8c90248264a8b26970b4473770bcc3df8515fJosh Gao   shared object is initially loaded.
370a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
380a8c90248264a8b26970b4473770bcc3df8515fJosh Gao   Note that this filename has the "drd_" prefix because it can appear
390a8c90248264a8b26970b4473770bcc3df8515fJosh Gao   in stack traces, and the "drd_" makes it a little clearer that it
400a8c90248264a8b26970b4473770bcc3df8515fJosh Gao   originates from Valgrind.
410a8c90248264a8b26970b4473770bcc3df8515fJosh Gao   ------------------------------------------------------------------ */
420a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
430a8c90248264a8b26970b4473770bcc3df8515fJosh Gao// Make sure pthread_spinlock_t is available when compiling with older glibc
440a8c90248264a8b26970b4473770bcc3df8515fJosh Gao// versions (2.3 or before).
450a8c90248264a8b26970b4473770bcc3df8515fJosh Gao#ifndef _GNU_SOURCE
460a8c90248264a8b26970b4473770bcc3df8515fJosh Gao#define _GNU_SOURCE
470a8c90248264a8b26970b4473770bcc3df8515fJosh Gao#endif
480a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
490a8c90248264a8b26970b4473770bcc3df8515fJosh Gao#include <assert.h>
500a8c90248264a8b26970b4473770bcc3df8515fJosh Gao#include <inttypes.h>       // uintptr_t
510a8c90248264a8b26970b4473770bcc3df8515fJosh Gao#include <pthread.h>
520a8c90248264a8b26970b4473770bcc3df8515fJosh Gao#include <semaphore.h>
530a8c90248264a8b26970b4473770bcc3df8515fJosh Gao#include <stdio.h>
540a8c90248264a8b26970b4473770bcc3df8515fJosh Gao#include <stdlib.h>
550a8c90248264a8b26970b4473770bcc3df8515fJosh Gao#include <unistd.h>         // confstr()
560a8c90248264a8b26970b4473770bcc3df8515fJosh Gao#include "config.h"
570a8c90248264a8b26970b4473770bcc3df8515fJosh Gao#include "drd_basics.h"
580a8c90248264a8b26970b4473770bcc3df8515fJosh Gao#include "drd_clientreq.h"
590a8c90248264a8b26970b4473770bcc3df8515fJosh Gao#include "pub_tool_redir.h"
600a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
610a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
620a8c90248264a8b26970b4473770bcc3df8515fJosh Gao// Defines.
630a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
640a8c90248264a8b26970b4473770bcc3df8515fJosh Gao#define PTH_FUNC(ret_ty, f, args...)                            \
650a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  ret_ty VG_WRAP_FUNCTION_ZZ(libpthreadZdsoZd0,f)(args);        \
660a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  ret_ty VG_WRAP_FUNCTION_ZZ(libpthreadZdsoZd0,f)(args)
670a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
680a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
690a8c90248264a8b26970b4473770bcc3df8515fJosh Gao/* Local data structures. */
700a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
710a8c90248264a8b26970b4473770bcc3df8515fJosh Gaotypedef struct
720a8c90248264a8b26970b4473770bcc3df8515fJosh Gao{
730a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  void* (*start)(void*);
740a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  void* arg;
750a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   detachstate;
760a8c90248264a8b26970b4473770bcc3df8515fJosh Gao#if 0
770a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  pthread_mutex_t mutex;
780a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  pthread_cond_t  cond;
790a8c90248264a8b26970b4473770bcc3df8515fJosh Gao#else
800a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int wrapper_started;
810a8c90248264a8b26970b4473770bcc3df8515fJosh Gao#endif
820a8c90248264a8b26970b4473770bcc3df8515fJosh Gao} VgPosixThreadArgs;
830a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
840a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
850a8c90248264a8b26970b4473770bcc3df8515fJosh Gao/* Function declarations. */
860a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
870a8c90248264a8b26970b4473770bcc3df8515fJosh Gaostatic void init(void) __attribute__((constructor));
880a8c90248264a8b26970b4473770bcc3df8515fJosh Gaostatic void check_threading_library(void);
890a8c90248264a8b26970b4473770bcc3df8515fJosh Gaostatic void vg_set_main_thread_state(void);
900a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
910a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
920a8c90248264a8b26970b4473770bcc3df8515fJosh Gao/* Function definitions. */
930a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
940a8c90248264a8b26970b4473770bcc3df8515fJosh Gao/** Shared library initialization function: the _init() function is called
950a8c90248264a8b26970b4473770bcc3df8515fJosh Gao *  after dlopen() has loaded the shared library. This function must not
960a8c90248264a8b26970b4473770bcc3df8515fJosh Gao *  be declared static.
970a8c90248264a8b26970b4473770bcc3df8515fJosh Gao */
980a8c90248264a8b26970b4473770bcc3df8515fJosh Gaostatic void init(void)
990a8c90248264a8b26970b4473770bcc3df8515fJosh Gao{
1000a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  check_threading_library();
1010a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  vg_set_main_thread_state();
1020a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  /* glibc up to and including version 2.8 triggers conflicting accesses   */
1030a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  /* on stdout and stderr when sending output to one of these streams from */
1040a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  /* more than one thread. Suppress data race reports on these objects.    */
1050a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  DRD_IGNORE_VAR(*stdout);
1060a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  DRD_IGNORE_VAR(*stderr);
1070a8c90248264a8b26970b4473770bcc3df8515fJosh Gao#if defined(HAVE_LIBC_FILE_LOCK)
1080a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  DRD_IGNORE_VAR(*(pthread_mutex_t*)(stdout->_lock));
1090a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  DRD_IGNORE_VAR(*(pthread_mutex_t*)(stderr->_lock));
1100a8c90248264a8b26970b4473770bcc3df8515fJosh Gao#endif
1110a8c90248264a8b26970b4473770bcc3df8515fJosh Gao}
1120a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
1130a8c90248264a8b26970b4473770bcc3df8515fJosh Gaostatic MutexT pthread_to_drd_mutex_type(const int kind)
1140a8c90248264a8b26970b4473770bcc3df8515fJosh Gao{
1150a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  switch (kind)
1160a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  {
1170a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    /* PTHREAD_MUTEX_RECURSIVE_NP */
1180a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  case PTHREAD_MUTEX_RECURSIVE:
1190a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    return mutex_type_recursive_mutex;
1200a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    /* PTHREAD_MUTEX_ERRORCHECK_NP */
1210a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  case PTHREAD_MUTEX_ERRORCHECK:
1220a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    return mutex_type_errorcheck_mutex;
1230a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    /* PTHREAD_MUTEX_TIMED_NP */
1240a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    /* PTHREAD_MUTEX_NORMAL */
1250a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  case PTHREAD_MUTEX_DEFAULT:
1260a8c90248264a8b26970b4473770bcc3df8515fJosh Gao#if defined(HAVE_PTHREAD_MUTEX_ADAPTIVE_NP)
1270a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  case PTHREAD_MUTEX_ADAPTIVE_NP:
1280a8c90248264a8b26970b4473770bcc3df8515fJosh Gao#endif
1290a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    return mutex_type_default_mutex;
1300a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  }
1310a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  return mutex_type_invalid_mutex;
1320a8c90248264a8b26970b4473770bcc3df8515fJosh Gao}
1330a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
1340a8c90248264a8b26970b4473770bcc3df8515fJosh Gao/** @note The function mutex_type() has been declared inline in order
1350a8c90248264a8b26970b4473770bcc3df8515fJosh Gao *  to avoid that it shows up in call stacks.
1360a8c90248264a8b26970b4473770bcc3df8515fJosh Gao */
1370a8c90248264a8b26970b4473770bcc3df8515fJosh Gaostatic __inline__ MutexT mutex_type(pthread_mutex_t* mutex)
1380a8c90248264a8b26970b4473770bcc3df8515fJosh Gao{
1390a8c90248264a8b26970b4473770bcc3df8515fJosh Gao#if defined(HAVE_PTHREAD_MUTEX_T__M_KIND)
1400a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  /* LinuxThreads. */
1410a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  const int kind = mutex->__m_kind;
1420a8c90248264a8b26970b4473770bcc3df8515fJosh Gao#elif defined(HAVE_PTHREAD_MUTEX_T__DATA__KIND)
1430a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  /* NPTL. */
1440a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  const int kind = mutex->__data.__kind;
1450a8c90248264a8b26970b4473770bcc3df8515fJosh Gao#else
1460a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  /* Another POSIX threads implementation. Regression tests will fail. */
1470a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  const int kind = PTHREAD_MUTEX_DEFAULT;
1480a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  fprintf(stderr,
1490a8c90248264a8b26970b4473770bcc3df8515fJosh Gao          "Did not recognize your POSIX threads implementation. Giving up.\n");
1500a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  assert(0);
1510a8c90248264a8b26970b4473770bcc3df8515fJosh Gao#endif
1520a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  return pthread_to_drd_mutex_type(kind);
1530a8c90248264a8b26970b4473770bcc3df8515fJosh Gao}
1540a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
1550a8c90248264a8b26970b4473770bcc3df8515fJosh Gaostatic void vg_start_suppression(const void* const p, size_t const size)
1560a8c90248264a8b26970b4473770bcc3df8515fJosh Gao{
1570a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int res;
1580a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__DRD_START_SUPPRESSION,
1590a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             p, size, 0, 0, 0);
1600a8c90248264a8b26970b4473770bcc3df8515fJosh Gao}
1610a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
1620a8c90248264a8b26970b4473770bcc3df8515fJosh Gaostatic void vg_set_joinable(const pthread_t tid, const int joinable)
1630a8c90248264a8b26970b4473770bcc3df8515fJosh Gao{
1640a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int res;
1650a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  assert(joinable == 0 || joinable == 1);
1660a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__SET_JOINABLE,
1670a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             tid, joinable, 0, 0, 0);
1680a8c90248264a8b26970b4473770bcc3df8515fJosh Gao}
1690a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
1700a8c90248264a8b26970b4473770bcc3df8515fJosh Gaostatic void* DRD_(thread_wrapper)(void* arg)
1710a8c90248264a8b26970b4473770bcc3df8515fJosh Gao{
1720a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int res;
1730a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
1740a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__DRD_SUPPRESS_CURRENT_STACK,
1750a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             0, 0, 0, 0, 0);
1760a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
1770a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  {
1780a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    VgPosixThreadArgs* const arg_ptr = (VgPosixThreadArgs*)arg;
1790a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    VgPosixThreadArgs const arg_copy = *arg_ptr;
1800a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    void* result;
1810a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
1820a8c90248264a8b26970b4473770bcc3df8515fJosh Gao#if 0
1830a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    pthread_mutex_lock(arg_ptr->mutex);
1840a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    pthread_cond_signal(arg_ptr->cond);
1850a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    pthread_mutex_unlock(arg_ptr->mutex);
1860a8c90248264a8b26970b4473770bcc3df8515fJosh Gao#else
1870a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    arg_ptr->wrapper_started = 1;
1880a8c90248264a8b26970b4473770bcc3df8515fJosh Gao#endif
1890a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
1900a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__SET_PTHREADID,
1910a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                               pthread_self(), 0, 0, 0, 0);
1920a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    vg_set_joinable(pthread_self(),
1930a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                    arg_copy.detachstate == PTHREAD_CREATE_JOINABLE);
1940a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    result = (arg_copy.start)(arg_copy.arg);
1950a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    return result;
1960a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  }
1970a8c90248264a8b26970b4473770bcc3df8515fJosh Gao}
1980a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
1990a8c90248264a8b26970b4473770bcc3df8515fJosh Gao/** Return 1 if LinuxThread has been detected, and 0 otherwise. */
2000a8c90248264a8b26970b4473770bcc3df8515fJosh Gaostatic int detected_linuxthreads(void)
2010a8c90248264a8b26970b4473770bcc3df8515fJosh Gao{
2020a8c90248264a8b26970b4473770bcc3df8515fJosh Gao#if defined(linux)
2030a8c90248264a8b26970b4473770bcc3df8515fJosh Gao#if defined(_CS_GNU_LIBPTHREAD_VERSION)
2040a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  /* Linux with a recent glibc. */
2050a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  char buffer[256];
2060a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  unsigned len;
2070a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  len = confstr(_CS_GNU_LIBPTHREAD_VERSION, buffer, sizeof(buffer));
2080a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  assert(len <= sizeof(buffer));
2090a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  return len > 0 && buffer[0] == 'l';
2100a8c90248264a8b26970b4473770bcc3df8515fJosh Gao#else
2110a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  /* Linux without _CS_GNU_LIBPTHREAD_VERSION: most likely LinuxThreads. */
2120a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  return 1;
2130a8c90248264a8b26970b4473770bcc3df8515fJosh Gao#endif
2140a8c90248264a8b26970b4473770bcc3df8515fJosh Gao#else
2150a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  /* Another OS than Linux, hence no LinuxThreads. */
2160a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  return 0;
2170a8c90248264a8b26970b4473770bcc3df8515fJosh Gao#endif
2180a8c90248264a8b26970b4473770bcc3df8515fJosh Gao}
2190a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
2200a8c90248264a8b26970b4473770bcc3df8515fJosh Gao/** Stop and print an error message in case a non-supported threading
2210a8c90248264a8b26970b4473770bcc3df8515fJosh Gao *  library (LinuxThreads) has been detected.
2220a8c90248264a8b26970b4473770bcc3df8515fJosh Gao */
2230a8c90248264a8b26970b4473770bcc3df8515fJosh Gaostatic void check_threading_library(void)
2240a8c90248264a8b26970b4473770bcc3df8515fJosh Gao{
2250a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  if (detected_linuxthreads())
2260a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  {
2270a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    if (getenv("LD_ASSUME_KERNEL"))
2280a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    {
2290a8c90248264a8b26970b4473770bcc3df8515fJosh Gao      fprintf(stderr,
2300a8c90248264a8b26970b4473770bcc3df8515fJosh Gao              "Detected the LinuxThreads threading library. Sorry, but DRD only supports\n"
2310a8c90248264a8b26970b4473770bcc3df8515fJosh Gao              "the newer NPTL (Native POSIX Threads Library). Please try to rerun DRD\n"
2320a8c90248264a8b26970b4473770bcc3df8515fJosh Gao              "after having unset the environment variable LD_ASSUME_KERNEL. Giving up.\n"
2330a8c90248264a8b26970b4473770bcc3df8515fJosh Gao              );
2340a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    }
2350a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    else
2360a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    {
2370a8c90248264a8b26970b4473770bcc3df8515fJosh Gao      fprintf(stderr,
2380a8c90248264a8b26970b4473770bcc3df8515fJosh Gao              "Detected the LinuxThreads threading library. Sorry, but DRD only supports\n"
2390a8c90248264a8b26970b4473770bcc3df8515fJosh Gao              "the newer NPTL (Native POSIX Threads Library). Please try to rerun DRD\n"
2400a8c90248264a8b26970b4473770bcc3df8515fJosh Gao              "after having upgraded to a newer version of your Linux distribution.\n"
2410a8c90248264a8b26970b4473770bcc3df8515fJosh Gao              "Giving up.\n"
2420a8c90248264a8b26970b4473770bcc3df8515fJosh Gao              );
2430a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    }
2440a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    abort();
2450a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  }
2460a8c90248264a8b26970b4473770bcc3df8515fJosh Gao}
2470a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
2480a8c90248264a8b26970b4473770bcc3df8515fJosh Gaostatic void vg_set_main_thread_state(void)
2490a8c90248264a8b26970b4473770bcc3df8515fJosh Gao{
2500a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int res;
2510a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
2520a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__DRD_SUPPRESS_CURRENT_STACK,
2530a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             0, 0, 0, 0, 0);
2540a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
2550a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  // Make sure that DRD knows about the main thread's POSIX thread ID.
2560a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__SET_PTHREADID,
2570a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             pthread_self(), 0, 0, 0, 0);
2580a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
2590a8c90248264a8b26970b4473770bcc3df8515fJosh Gao}
2600a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
2610a8c90248264a8b26970b4473770bcc3df8515fJosh Gao// pthread_create
2620a8c90248264a8b26970b4473770bcc3df8515fJosh GaoPTH_FUNC(int, pthreadZucreateZa, // pthread_create*
2630a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         pthread_t *thread, const pthread_attr_t *attr,
2640a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         void *(*start) (void *), void *arg)
2650a8c90248264a8b26970b4473770bcc3df8515fJosh Gao{
2660a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int    res;
2670a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int    ret;
2680a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  OrigFn fn;
2690a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VgPosixThreadArgs vgargs;
2700a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
2710a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_GET_ORIG_FN(fn);
2720a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
2730a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  vg_start_suppression(&vgargs.wrapper_started,
2740a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                       sizeof(vgargs.wrapper_started));
2750a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  vgargs.start = start;
2760a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  vgargs.arg   = arg;
2770a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  vgargs.wrapper_started = 0;
2780a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  vgargs.detachstate = PTHREAD_CREATE_JOINABLE;
2790a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  if (attr)
2800a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  {
2810a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    if (pthread_attr_getdetachstate(attr, &vgargs.detachstate) != 0)
2820a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    {
2830a8c90248264a8b26970b4473770bcc3df8515fJosh Gao      assert(0);
2840a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    }
2850a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  }
2860a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  assert(vgargs.detachstate == PTHREAD_CREATE_JOINABLE
2870a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         || vgargs.detachstate == PTHREAD_CREATE_DETACHED);
2880a8c90248264a8b26970b4473770bcc3df8515fJosh Gao#if 0
2890a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  pthread_mutex_init(&vgargs.mutex, 0);
2900a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  pthread_cond_init(&vgargs.cond, 0);
2910a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  pthread_mutex_lock(&vgargs.mutex);
2920a8c90248264a8b26970b4473770bcc3df8515fJosh Gao#endif
2930a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  /* Suppress NPTL-specific conflicts between creator and created thread. */
2940a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__DRD_STOP_RECORDING,
2950a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             0, 0, 0, 0, 0);
2960a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  CALL_FN_W_WWWW(ret, fn, thread, attr, DRD_(thread_wrapper), &vgargs);
2970a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__DRD_START_RECORDING,
2980a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             0, 0, 0, 0, 0);
2990a8c90248264a8b26970b4473770bcc3df8515fJosh Gao#if 0
3000a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  pthread_cond_wait(&vgargs.cond, &vgargs.mutex);
3010a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  pthread_mutex_unlock(&vgargs.mutex);
3020a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  pthread_cond_destroy(&vgargs.cond);
3030a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  pthread_mutex_destroy(&vgargs.mutex);
3040a8c90248264a8b26970b4473770bcc3df8515fJosh Gao#else
3050a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  // Yes, you see it correctly, busy waiting ... The problem is that
3060a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  // POSIX threads functions cannot be called here -- the functions defined
3070a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  // in this file (drd_intercepts.c) would be called instead of those in
3080a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  // libpthread.so. This loop is necessary because vgargs is allocated on the
3090a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  // stack, and the created thread reads it.
3100a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  if (ret == 0)
3110a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  {
3120a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    while (! vgargs.wrapper_started)
3130a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    {
3140a8c90248264a8b26970b4473770bcc3df8515fJosh Gao      sched_yield();
3150a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    }
3160a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  }
3170a8c90248264a8b26970b4473770bcc3df8515fJosh Gao#endif
3180a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  return ret;
3190a8c90248264a8b26970b4473770bcc3df8515fJosh Gao}
3200a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
3210a8c90248264a8b26970b4473770bcc3df8515fJosh Gao// pthread_join
3220a8c90248264a8b26970b4473770bcc3df8515fJosh GaoPTH_FUNC(int, pthreadZujoin, // pthread_join
3230a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         pthread_t pt_joinee, void **thread_return)
3240a8c90248264a8b26970b4473770bcc3df8515fJosh Gao{
3250a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int      ret;
3260a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int      res;
3270a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  OrigFn   fn;
3280a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
3290a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_GET_ORIG_FN(fn);
3300a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  CALL_FN_W_WW(ret, fn, pt_joinee, thread_return);
3310a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  if (ret == 0)
3320a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  {
3330a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_THREAD_JOIN,
3340a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                               pt_joinee, 0, 0, 0, 0);
3350a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  }
3360a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  return ret;
3370a8c90248264a8b26970b4473770bcc3df8515fJosh Gao}
3380a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
3390a8c90248264a8b26970b4473770bcc3df8515fJosh Gao// pthread_detach
3400a8c90248264a8b26970b4473770bcc3df8515fJosh GaoPTH_FUNC(int, pthreadZudetach, pthread_t pt_thread)
3410a8c90248264a8b26970b4473770bcc3df8515fJosh Gao{
3420a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int ret;
3430a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  OrigFn fn;
3440a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_GET_ORIG_FN(fn);
3450a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  {
3460a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    CALL_FN_W_W(ret, fn, pt_thread);
3470a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    if (ret == 0)
3480a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    {
3490a8c90248264a8b26970b4473770bcc3df8515fJosh Gao      vg_set_joinable(pt_thread, 0);
3500a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    }
3510a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  }
3520a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  return ret;
3530a8c90248264a8b26970b4473770bcc3df8515fJosh Gao}
3540a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
3550a8c90248264a8b26970b4473770bcc3df8515fJosh Gao// pthread_cancel
3560a8c90248264a8b26970b4473770bcc3df8515fJosh GaoPTH_FUNC(int, pthreadZucancel, pthread_t pt_thread)
3570a8c90248264a8b26970b4473770bcc3df8515fJosh Gao{
3580a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int res;
3590a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int ret;
3600a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  OrigFn fn;
3610a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_GET_ORIG_FN(fn);
3620a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_THREAD_CANCEL,
3630a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             pt_thread, 0, 0, 0, 0);
3640a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  CALL_FN_W_W(ret, fn, pt_thread);
3650a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_THREAD_CANCEL,
3660a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             pt_thread, ret==0, 0, 0, 0);
3670a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  return ret;
3680a8c90248264a8b26970b4473770bcc3df8515fJosh Gao}
3690a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
3700a8c90248264a8b26970b4473770bcc3df8515fJosh Gao// pthread_mutex_init
3710a8c90248264a8b26970b4473770bcc3df8515fJosh GaoPTH_FUNC(int, pthreadZumutexZuinit,
3720a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         pthread_mutex_t *mutex,
3730a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         const pthread_mutexattr_t* attr)
3740a8c90248264a8b26970b4473770bcc3df8515fJosh Gao{
3750a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int ret;
3760a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int res;
3770a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  OrigFn fn;
3780a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int mt;
3790a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_GET_ORIG_FN(fn);
3800a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  mt = PTHREAD_MUTEX_DEFAULT;
3810a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  if (attr)
3820a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    pthread_mutexattr_gettype(attr, &mt);
3830a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_MUTEX_INIT,
3840a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             mutex, pthread_to_drd_mutex_type(mt), 0, 0, 0);
3850a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  CALL_FN_W_WW(ret, fn, mutex, attr);
3860a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_MUTEX_INIT,
3870a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             mutex, 0, 0, 0, 0);
3880a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  return ret;
3890a8c90248264a8b26970b4473770bcc3df8515fJosh Gao}
3900a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
3910a8c90248264a8b26970b4473770bcc3df8515fJosh Gao// pthread_mutex_destroy
3920a8c90248264a8b26970b4473770bcc3df8515fJosh GaoPTH_FUNC(int, pthreadZumutexZudestroy,
3930a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         pthread_mutex_t *mutex)
3940a8c90248264a8b26970b4473770bcc3df8515fJosh Gao{
3950a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int ret;
3960a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int res;
3970a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  OrigFn fn;
3980a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_GET_ORIG_FN(fn);
3990a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_MUTEX_DESTROY,
4000a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             mutex, 0, 0, 0, 0);
4010a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  CALL_FN_W_W(ret, fn, mutex);
4020a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_MUTEX_DESTROY,
4030a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             mutex, mutex_type(mutex), 0, 0, 0);
4040a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  return ret;
4050a8c90248264a8b26970b4473770bcc3df8515fJosh Gao}
4060a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
4070a8c90248264a8b26970b4473770bcc3df8515fJosh Gao// pthread_mutex_lock
4080a8c90248264a8b26970b4473770bcc3df8515fJosh GaoPTH_FUNC(int, pthreadZumutexZulock, // pthread_mutex_lock
4090a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         pthread_mutex_t *mutex)
4100a8c90248264a8b26970b4473770bcc3df8515fJosh Gao{
4110a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   ret;
4120a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   res;
4130a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  OrigFn fn;
4140a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_GET_ORIG_FN(fn);
4150a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__PRE_MUTEX_LOCK,
4160a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             mutex, mutex_type(mutex), 0, 0, 0);
4170a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  CALL_FN_W_W(ret, fn, mutex);
4180a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__POST_MUTEX_LOCK,
4190a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             mutex, ret == 0, 0, 0, 0);
4200a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  return ret;
4210a8c90248264a8b26970b4473770bcc3df8515fJosh Gao}
4220a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
4230a8c90248264a8b26970b4473770bcc3df8515fJosh Gao// pthread_mutex_trylock
4240a8c90248264a8b26970b4473770bcc3df8515fJosh GaoPTH_FUNC(int, pthreadZumutexZutrylock, // pthread_mutex_trylock
4250a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         pthread_mutex_t *mutex)
4260a8c90248264a8b26970b4473770bcc3df8515fJosh Gao{
4270a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   ret;
4280a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   res;
4290a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  OrigFn fn;
4300a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_GET_ORIG_FN(fn);
4310a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__PRE_MUTEX_LOCK,
4320a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             mutex, mutex_type(mutex), 1, 0, 0);
4330a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  CALL_FN_W_W(ret, fn, mutex);
4340a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_MUTEX_LOCK,
4350a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             mutex, ret == 0, 0, 0, 0);
4360a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  return ret;
4370a8c90248264a8b26970b4473770bcc3df8515fJosh Gao}
4380a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
4390a8c90248264a8b26970b4473770bcc3df8515fJosh Gao// pthread_mutex_timedlock
4400a8c90248264a8b26970b4473770bcc3df8515fJosh GaoPTH_FUNC(int, pthreadZumutexZutimedlock, // pthread_mutex_timedlock
4410a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         pthread_mutex_t *mutex,
4420a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         const struct timespec *abs_timeout)
4430a8c90248264a8b26970b4473770bcc3df8515fJosh Gao{
4440a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   ret;
4450a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   res;
4460a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  OrigFn fn;
4470a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_GET_ORIG_FN(fn);
4480a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__PRE_MUTEX_LOCK,
4490a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             mutex, mutex_type(mutex), 0, 0, 0);
4500a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  CALL_FN_W_WW(ret, fn, mutex, abs_timeout);
4510a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_MUTEX_LOCK,
4520a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             mutex, ret == 0, 0, 0, 0);
4530a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  return ret;
4540a8c90248264a8b26970b4473770bcc3df8515fJosh Gao}
4550a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
4560a8c90248264a8b26970b4473770bcc3df8515fJosh Gao// pthread_mutex_unlock
4570a8c90248264a8b26970b4473770bcc3df8515fJosh GaoPTH_FUNC(int, pthreadZumutexZuunlock, // pthread_mutex_unlock
4580a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         pthread_mutex_t *mutex)
4590a8c90248264a8b26970b4473770bcc3df8515fJosh Gao{
4600a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int ret;
4610a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   res;
4620a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  OrigFn fn;
4630a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_GET_ORIG_FN(fn);
4640a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1,
4650a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             VG_USERREQ__PRE_MUTEX_UNLOCK,
4660a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             mutex, mutex_type(mutex), 0, 0, 0);
4670a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  CALL_FN_W_W(ret, fn, mutex);
4680a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1,
4690a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             VG_USERREQ__POST_MUTEX_UNLOCK,
4700a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             mutex, 0, 0, 0, 0);
4710a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  return ret;
4720a8c90248264a8b26970b4473770bcc3df8515fJosh Gao}
4730a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
4740a8c90248264a8b26970b4473770bcc3df8515fJosh Gao// pthread_cond_init
4750a8c90248264a8b26970b4473770bcc3df8515fJosh GaoPTH_FUNC(int, pthreadZucondZuinitZa, // pthread_cond_init*
4760a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         pthread_cond_t* cond,
4770a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         const pthread_condattr_t* attr)
4780a8c90248264a8b26970b4473770bcc3df8515fJosh Gao{
4790a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int ret;
4800a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int res;
4810a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  OrigFn fn;
4820a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_GET_ORIG_FN(fn);
4830a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_COND_INIT,
4840a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             cond, 0, 0, 0, 0);
4850a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  CALL_FN_W_WW(ret, fn, cond, attr);
4860a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_COND_INIT,
4870a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             cond, 0, 0, 0, 0);
4880a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  return ret;
4890a8c90248264a8b26970b4473770bcc3df8515fJosh Gao}
4900a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
4910a8c90248264a8b26970b4473770bcc3df8515fJosh Gao// pthread_cond_destroy
4920a8c90248264a8b26970b4473770bcc3df8515fJosh GaoPTH_FUNC(int, pthreadZucondZudestroyZa, // pthread_cond_destroy*
4930a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         pthread_cond_t* cond)
4940a8c90248264a8b26970b4473770bcc3df8515fJosh Gao{
4950a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int ret;
4960a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int res;
4970a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  OrigFn fn;
4980a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_GET_ORIG_FN(fn);
4990a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_COND_DESTROY,
5000a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             cond, 0, 0, 0, 0);
5010a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  CALL_FN_W_W(ret, fn, cond);
5020a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_COND_DESTROY,
5030a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             cond, 0, 0, 0, 0);
5040a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  return ret;
5050a8c90248264a8b26970b4473770bcc3df8515fJosh Gao}
5060a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
5070a8c90248264a8b26970b4473770bcc3df8515fJosh Gao// pthread_cond_wait
5080a8c90248264a8b26970b4473770bcc3df8515fJosh GaoPTH_FUNC(int, pthreadZucondZuwaitZa, // pthread_cond_wait*
5090a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         pthread_cond_t *cond,
5100a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         pthread_mutex_t *mutex)
5110a8c90248264a8b26970b4473770bcc3df8515fJosh Gao{
5120a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   ret;
5130a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   res;
5140a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  OrigFn fn;
5150a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_GET_ORIG_FN(fn);
5160a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_COND_WAIT,
5170a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             cond, mutex, mutex_type(mutex), 0, 0);
5180a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  CALL_FN_W_WW(ret, fn, cond, mutex);
5190a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_COND_WAIT,
5200a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             cond, mutex, 1, 0, 0);
5210a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  return ret;
5220a8c90248264a8b26970b4473770bcc3df8515fJosh Gao}
5230a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
5240a8c90248264a8b26970b4473770bcc3df8515fJosh Gao// pthread_cond_timedwait
5250a8c90248264a8b26970b4473770bcc3df8515fJosh GaoPTH_FUNC(int, pthreadZucondZutimedwaitZa, // pthread_cond_timedwait*
5260a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         pthread_cond_t *cond,
5270a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         pthread_mutex_t *mutex,
5280a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         const struct timespec* abstime)
5290a8c90248264a8b26970b4473770bcc3df8515fJosh Gao{
5300a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   ret;
5310a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   res;
5320a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  OrigFn fn;
5330a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_GET_ORIG_FN(fn);
5340a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_COND_WAIT,
5350a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             cond, mutex, mutex_type(mutex), 0, 0);
5360a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  CALL_FN_W_WWW(ret, fn, cond, mutex, abstime);
5370a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_COND_WAIT,
5380a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             cond, mutex, 1, 0, 0);
5390a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  return ret;
5400a8c90248264a8b26970b4473770bcc3df8515fJosh Gao}
5410a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
5420a8c90248264a8b26970b4473770bcc3df8515fJosh Gao// pthread_cond_signal
5430a8c90248264a8b26970b4473770bcc3df8515fJosh GaoPTH_FUNC(int, pthreadZucondZusignalZa, // pthread_cond_signal*
5440a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         pthread_cond_t* cond)
5450a8c90248264a8b26970b4473770bcc3df8515fJosh Gao{
5460a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   ret;
5470a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   res;
5480a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  OrigFn fn;
5490a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_GET_ORIG_FN(fn);
5500a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_COND_SIGNAL,
5510a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             cond, 0, 0, 0, 0);
5520a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  CALL_FN_W_W(ret, fn, cond);
5530a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_COND_SIGNAL,
5540a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             cond, 0, 0, 0, 0);
5550a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  return ret;
5560a8c90248264a8b26970b4473770bcc3df8515fJosh Gao}
5570a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
5580a8c90248264a8b26970b4473770bcc3df8515fJosh Gao// pthread_cond_broadcast
5590a8c90248264a8b26970b4473770bcc3df8515fJosh GaoPTH_FUNC(int, pthreadZucondZubroadcastZa, // pthread_cond_broadcast*
5600a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         pthread_cond_t* cond)
5610a8c90248264a8b26970b4473770bcc3df8515fJosh Gao{
5620a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   ret;
5630a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   res;
5640a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  OrigFn fn;
5650a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_GET_ORIG_FN(fn);
5660a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_COND_BROADCAST,
5670a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             cond, 0, 0, 0, 0);
5680a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  CALL_FN_W_W(ret, fn, cond);
5690a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_COND_BROADCAST,
5700a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             cond, 0, 0, 0, 0);
5710a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  return ret;
5720a8c90248264a8b26970b4473770bcc3df8515fJosh Gao}
5730a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
5740a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
5750a8c90248264a8b26970b4473770bcc3df8515fJosh Gao// pthread_spin_init
5760a8c90248264a8b26970b4473770bcc3df8515fJosh GaoPTH_FUNC(int, pthreadZuspinZuinit, // pthread_spin_init
5770a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         pthread_spinlock_t *spinlock,
5780a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         int pshared)
5790a8c90248264a8b26970b4473770bcc3df8515fJosh Gao{
5800a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int ret;
5810a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int res;
5820a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  OrigFn fn;
5830a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_GET_ORIG_FN(fn);
5840a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_SPIN_INIT_OR_UNLOCK,
5850a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             spinlock, 0, 0, 0, 0);
5860a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  CALL_FN_W_WW(ret, fn, spinlock, pshared);
5870a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_SPIN_INIT_OR_UNLOCK,
5880a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             spinlock, 0, 0, 0, 0);
5890a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  return ret;
5900a8c90248264a8b26970b4473770bcc3df8515fJosh Gao}
5910a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
5920a8c90248264a8b26970b4473770bcc3df8515fJosh Gao// pthread_spin_destroy
5930a8c90248264a8b26970b4473770bcc3df8515fJosh GaoPTH_FUNC(int, pthreadZuspinZudestroy, // pthread_spin_destroy
5940a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         pthread_spinlock_t *spinlock)
5950a8c90248264a8b26970b4473770bcc3df8515fJosh Gao{
5960a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int ret;
5970a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int res;
5980a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  OrigFn fn;
5990a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_GET_ORIG_FN(fn);
6000a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_MUTEX_DESTROY,
6010a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             spinlock, 0, 0, 0, 0);
6020a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  CALL_FN_W_W(ret, fn, spinlock);
6030a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_MUTEX_DESTROY,
6040a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             spinlock, mutex_type_spinlock, 0, 0, 0);
6050a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  return ret;
6060a8c90248264a8b26970b4473770bcc3df8515fJosh Gao}
6070a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
6080a8c90248264a8b26970b4473770bcc3df8515fJosh Gao// pthread_spin_lock
6090a8c90248264a8b26970b4473770bcc3df8515fJosh GaoPTH_FUNC(int, pthreadZuspinZulock, // pthread_spin_lock
6100a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         pthread_spinlock_t *spinlock)
6110a8c90248264a8b26970b4473770bcc3df8515fJosh Gao{
6120a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   ret;
6130a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   res;
6140a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  OrigFn fn;
6150a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_GET_ORIG_FN(fn);
6160a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__PRE_MUTEX_LOCK,
6170a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             spinlock, mutex_type_spinlock, 0, 0, 0);
6180a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  CALL_FN_W_W(ret, fn, spinlock);
6190a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_MUTEX_LOCK,
6200a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             spinlock, ret == 0, 0, 0, 0);
6210a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  return ret;
6220a8c90248264a8b26970b4473770bcc3df8515fJosh Gao}
6230a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
6240a8c90248264a8b26970b4473770bcc3df8515fJosh Gao// pthread_spin_trylock
6250a8c90248264a8b26970b4473770bcc3df8515fJosh GaoPTH_FUNC(int, pthreadZuspinZutrylock, // pthread_spin_trylock
6260a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         pthread_spinlock_t *spinlock)
6270a8c90248264a8b26970b4473770bcc3df8515fJosh Gao{
6280a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   ret;
6290a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   res;
6300a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  OrigFn fn;
6310a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_GET_ORIG_FN(fn);
6320a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__PRE_MUTEX_LOCK,
6330a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             spinlock, mutex_type_spinlock, 0, 0, 0);
6340a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  CALL_FN_W_W(ret, fn, spinlock);
6350a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_MUTEX_LOCK,
6360a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             spinlock, ret == 0, 0, 0, 0);
6370a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  return ret;
6380a8c90248264a8b26970b4473770bcc3df8515fJosh Gao}
6390a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
6400a8c90248264a8b26970b4473770bcc3df8515fJosh Gao// pthread_spin_unlock
6410a8c90248264a8b26970b4473770bcc3df8515fJosh GaoPTH_FUNC(int, pthreadZuspinZuunlock, // pthread_spin_unlock
6420a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         pthread_spinlock_t *spinlock)
6430a8c90248264a8b26970b4473770bcc3df8515fJosh Gao{
6440a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   ret;
6450a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   res;
6460a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  OrigFn fn;
6470a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_GET_ORIG_FN(fn);
6480a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_SPIN_INIT_OR_UNLOCK,
6490a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             spinlock, mutex_type_spinlock, 0, 0, 0);
6500a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  CALL_FN_W_W(ret, fn, spinlock);
6510a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_SPIN_INIT_OR_UNLOCK,
6520a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             spinlock, 0, 0, 0, 0);
6530a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  return ret;
6540a8c90248264a8b26970b4473770bcc3df8515fJosh Gao}
6550a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
6560a8c90248264a8b26970b4473770bcc3df8515fJosh Gao// pthread_barrier_init
6570a8c90248264a8b26970b4473770bcc3df8515fJosh GaoPTH_FUNC(int, pthreadZubarrierZuinit, // pthread_barrier_init
6580a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         pthread_barrier_t* barrier,
6590a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         const pthread_barrierattr_t* attr,
6600a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         unsigned count)
6610a8c90248264a8b26970b4473770bcc3df8515fJosh Gao{
6620a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   ret;
6630a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   res;
6640a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  OrigFn fn;
6650a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_GET_ORIG_FN(fn);
6660a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_BARRIER_INIT,
6670a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             barrier, pthread_barrier, count, 0, 0);
6680a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  CALL_FN_W_WWW(ret, fn, barrier, attr, count);
6690a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_BARRIER_INIT,
6700a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             barrier, pthread_barrier, 0, 0, 0);
6710a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  return ret;
6720a8c90248264a8b26970b4473770bcc3df8515fJosh Gao}
6730a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
6740a8c90248264a8b26970b4473770bcc3df8515fJosh Gao// pthread_barrier_destroy
6750a8c90248264a8b26970b4473770bcc3df8515fJosh GaoPTH_FUNC(int, pthreadZubarrierZudestroy, // pthread_barrier_destroy
6760a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         pthread_barrier_t* barrier)
6770a8c90248264a8b26970b4473770bcc3df8515fJosh Gao{
6780a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   ret;
6790a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   res;
6800a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  OrigFn fn;
6810a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_GET_ORIG_FN(fn);
6820a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_BARRIER_DESTROY,
6830a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             barrier, pthread_barrier, 0, 0, 0);
6840a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  CALL_FN_W_W(ret, fn, barrier);
6850a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_BARRIER_DESTROY,
6860a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             barrier, pthread_barrier, 0, 0, 0);
6870a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  return ret;
6880a8c90248264a8b26970b4473770bcc3df8515fJosh Gao}
6890a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
6900a8c90248264a8b26970b4473770bcc3df8515fJosh Gao// pthread_barrier_wait
6910a8c90248264a8b26970b4473770bcc3df8515fJosh GaoPTH_FUNC(int, pthreadZubarrierZuwait, // pthread_barrier_wait
6920a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         pthread_barrier_t* barrier)
6930a8c90248264a8b26970b4473770bcc3df8515fJosh Gao{
6940a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   ret;
6950a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   res;
6960a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  OrigFn fn;
6970a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_GET_ORIG_FN(fn);
6980a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_BARRIER_WAIT,
6990a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             barrier, pthread_barrier, 0, 0, 0);
7000a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  CALL_FN_W_W(ret, fn, barrier);
7010a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_BARRIER_WAIT,
7020a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             barrier, pthread_barrier,
7030a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             ret == 0 || ret == PTHREAD_BARRIER_SERIAL_THREAD,
7040a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             0, 0);
7050a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  return ret;
7060a8c90248264a8b26970b4473770bcc3df8515fJosh Gao}
7070a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
7080a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
7090a8c90248264a8b26970b4473770bcc3df8515fJosh Gao// sem_init
7100a8c90248264a8b26970b4473770bcc3df8515fJosh GaoPTH_FUNC(int, semZuinitZa, // sem_init*
7110a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         sem_t *sem,
7120a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         int pshared,
7130a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         unsigned int value)
7140a8c90248264a8b26970b4473770bcc3df8515fJosh Gao{
7150a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   ret;
7160a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   res;
7170a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  OrigFn fn;
7180a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_GET_ORIG_FN(fn);
7190a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_SEM_INIT,
7200a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             sem, pshared, value, 0, 0);
7210a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  CALL_FN_W_WWW(ret, fn, sem, pshared, value);
7220a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_SEM_INIT,
7230a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             sem, 0, 0, 0, 0);
7240a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  return ret;
7250a8c90248264a8b26970b4473770bcc3df8515fJosh Gao}
7260a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
7270a8c90248264a8b26970b4473770bcc3df8515fJosh Gao// sem_destroy
7280a8c90248264a8b26970b4473770bcc3df8515fJosh GaoPTH_FUNC(int, semZudestroyZa, // sem_destroy*
7290a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         sem_t *sem)
7300a8c90248264a8b26970b4473770bcc3df8515fJosh Gao{
7310a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   ret;
7320a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   res;
7330a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  OrigFn fn;
7340a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_GET_ORIG_FN(fn);
7350a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_SEM_DESTROY,
7360a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             sem, 0, 0, 0, 0);
7370a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  CALL_FN_W_W(ret, fn, sem);
7380a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_SEM_DESTROY,
7390a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             sem, 0, 0, 0, 0);
7400a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  return ret;
7410a8c90248264a8b26970b4473770bcc3df8515fJosh Gao}
7420a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
7430a8c90248264a8b26970b4473770bcc3df8515fJosh Gao// sem_wait
7440a8c90248264a8b26970b4473770bcc3df8515fJosh GaoPTH_FUNC(int, semZuwaitZa, // sem_wait*
7450a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         sem_t *sem)
7460a8c90248264a8b26970b4473770bcc3df8515fJosh Gao{
7470a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   ret;
7480a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   res;
7490a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  OrigFn fn;
7500a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_GET_ORIG_FN(fn);
7510a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_SEM_WAIT,
7520a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             sem, 0, 0, 0, 0);
7530a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  CALL_FN_W_W(ret, fn, sem);
7540a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_SEM_WAIT,
7550a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             sem, ret == 0, 0, 0, 0);
7560a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  return ret;
7570a8c90248264a8b26970b4473770bcc3df8515fJosh Gao}
7580a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
7590a8c90248264a8b26970b4473770bcc3df8515fJosh Gao// sem_trywait
7600a8c90248264a8b26970b4473770bcc3df8515fJosh GaoPTH_FUNC(int, semZutrywaitZa, // sem_trywait*
7610a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         sem_t *sem)
7620a8c90248264a8b26970b4473770bcc3df8515fJosh Gao{
7630a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   ret;
7640a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   res;
7650a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  OrigFn fn;
7660a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_GET_ORIG_FN(fn);
7670a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_SEM_WAIT,
7680a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             sem, 0, 0, 0, 0);
7690a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  CALL_FN_W_W(ret, fn, sem);
7700a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_SEM_WAIT,
7710a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             sem, ret == 0, 0, 0, 0);
7720a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  return ret;
7730a8c90248264a8b26970b4473770bcc3df8515fJosh Gao}
7740a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
7750a8c90248264a8b26970b4473770bcc3df8515fJosh Gao// sem_timedwait
7760a8c90248264a8b26970b4473770bcc3df8515fJosh GaoPTH_FUNC(int, semZutimedwait, // sem_timedwait
7770a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         sem_t *sem, const struct timespec *abs_timeout)
7780a8c90248264a8b26970b4473770bcc3df8515fJosh Gao{
7790a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   ret;
7800a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   res;
7810a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  OrigFn fn;
7820a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_GET_ORIG_FN(fn);
7830a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_SEM_WAIT,
7840a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             sem, 0, 0, 0, 0);
7850a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  CALL_FN_W_WW(ret, fn, sem, abs_timeout);
7860a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_SEM_WAIT,
7870a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             sem, ret == 0, 0, 0, 0);
7880a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  return ret;
7890a8c90248264a8b26970b4473770bcc3df8515fJosh Gao}
7900a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
7910a8c90248264a8b26970b4473770bcc3df8515fJosh Gao// sem_post
7920a8c90248264a8b26970b4473770bcc3df8515fJosh GaoPTH_FUNC(int, semZupostZa, // sem_post*
7930a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         sem_t *sem)
7940a8c90248264a8b26970b4473770bcc3df8515fJosh Gao{
7950a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   ret;
7960a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   res;
7970a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  OrigFn fn;
7980a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_GET_ORIG_FN(fn);
7990a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_SEM_POST,
8000a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             sem, 0, 0, 0, 0);
8010a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  CALL_FN_W_W(ret, fn, sem);
8020a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_SEM_POST,
8030a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             sem, ret == 0, 0, 0, 0);
8040a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  return ret;
8050a8c90248264a8b26970b4473770bcc3df8515fJosh Gao}
8060a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
8070a8c90248264a8b26970b4473770bcc3df8515fJosh Gao// pthread_rwlock_init
8080a8c90248264a8b26970b4473770bcc3df8515fJosh GaoPTH_FUNC(int,
8090a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         pthreadZurwlockZuinitZa, // pthread_rwlock_init*
8100a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         pthread_rwlock_t* rwlock,
8110a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         const pthread_rwlockattr_t* attr)
8120a8c90248264a8b26970b4473770bcc3df8515fJosh Gao{
8130a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   ret;
8140a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   res;
8150a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  OrigFn fn;
8160a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_GET_ORIG_FN(fn);
8170a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_RWLOCK_INIT,
8180a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             rwlock, 0, 0, 0, 0);
8190a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  CALL_FN_W_WW(ret, fn, rwlock, attr);
8200a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  return ret;
8210a8c90248264a8b26970b4473770bcc3df8515fJosh Gao}
8220a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
8230a8c90248264a8b26970b4473770bcc3df8515fJosh Gao// pthread_rwlock_destroy
8240a8c90248264a8b26970b4473770bcc3df8515fJosh GaoPTH_FUNC(int,
8250a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         pthreadZurwlockZudestroyZa, // pthread_rwlock_destroy*
8260a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         pthread_rwlock_t* rwlock)
8270a8c90248264a8b26970b4473770bcc3df8515fJosh Gao{
8280a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   ret;
8290a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   res;
8300a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  OrigFn fn;
8310a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_GET_ORIG_FN(fn);
8320a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  CALL_FN_W_W(ret, fn, rwlock);
8330a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_RWLOCK_DESTROY,
8340a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             rwlock, 0, 0, 0, 0);
8350a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  return ret;
8360a8c90248264a8b26970b4473770bcc3df8515fJosh Gao}
8370a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
8380a8c90248264a8b26970b4473770bcc3df8515fJosh Gao// pthread_rwlock_rdlock
8390a8c90248264a8b26970b4473770bcc3df8515fJosh GaoPTH_FUNC(int,
8400a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         pthreadZurwlockZurdlockZa, // pthread_rwlock_rdlock*
8410a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         pthread_rwlock_t* rwlock)
8420a8c90248264a8b26970b4473770bcc3df8515fJosh Gao{
8430a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   ret;
8440a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   res;
8450a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  OrigFn fn;
8460a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_GET_ORIG_FN(fn);
8470a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_RWLOCK_RDLOCK,
8480a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             rwlock, 0, 0, 0, 0);
8490a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  CALL_FN_W_W(ret, fn, rwlock);
8500a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_RWLOCK_RDLOCK,
8510a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             rwlock, ret == 0, 0, 0, 0);
8520a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  return ret;
8530a8c90248264a8b26970b4473770bcc3df8515fJosh Gao}
8540a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
8550a8c90248264a8b26970b4473770bcc3df8515fJosh Gao// pthread_rwlock_wrlock
8560a8c90248264a8b26970b4473770bcc3df8515fJosh GaoPTH_FUNC(int,
8570a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         pthreadZurwlockZuwrlockZa, // pthread_rwlock_wrlock*
8580a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         pthread_rwlock_t* rwlock)
8590a8c90248264a8b26970b4473770bcc3df8515fJosh Gao{
8600a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   ret;
8610a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   res;
8620a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  OrigFn fn;
8630a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_GET_ORIG_FN(fn);
8640a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_RWLOCK_WRLOCK,
8650a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             rwlock, 0, 0, 0, 0);
8660a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  CALL_FN_W_W(ret, fn, rwlock);
8670a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_RWLOCK_WRLOCK,
8680a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             rwlock, ret == 0, 0, 0, 0);
8690a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  return ret;
8700a8c90248264a8b26970b4473770bcc3df8515fJosh Gao}
8710a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
8720a8c90248264a8b26970b4473770bcc3df8515fJosh Gao// pthread_rwlock_timedrdlock
8730a8c90248264a8b26970b4473770bcc3df8515fJosh GaoPTH_FUNC(int,
8740a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         pthreadZurwlockZutimedrdlockZa, // pthread_rwlock_timedrdlock*
8750a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         pthread_rwlock_t* rwlock)
8760a8c90248264a8b26970b4473770bcc3df8515fJosh Gao{
8770a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   ret;
8780a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   res;
8790a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  OrigFn fn;
8800a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_GET_ORIG_FN(fn);
8810a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_RWLOCK_RDLOCK,
8820a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             rwlock, 0, 0, 0, 0);
8830a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  CALL_FN_W_W(ret, fn, rwlock);
8840a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_RWLOCK_RDLOCK,
8850a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             rwlock, ret == 0, 0, 0, 0);
8860a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  return ret;
8870a8c90248264a8b26970b4473770bcc3df8515fJosh Gao}
8880a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
8890a8c90248264a8b26970b4473770bcc3df8515fJosh Gao// pthread_rwlock_timedwrlock
8900a8c90248264a8b26970b4473770bcc3df8515fJosh GaoPTH_FUNC(int,
8910a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         pthreadZurwlockZutimedwrlockZa, // pthread_rwlock_timedwrlock*
8920a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         pthread_rwlock_t* rwlock)
8930a8c90248264a8b26970b4473770bcc3df8515fJosh Gao{
8940a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   ret;
8950a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   res;
8960a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  OrigFn fn;
8970a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_GET_ORIG_FN(fn);
8980a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_RWLOCK_WRLOCK,
8990a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             rwlock, 0, 0, 0, 0);
9000a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  CALL_FN_W_W(ret, fn, rwlock);
9010a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_RWLOCK_WRLOCK,
9020a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             rwlock, ret == 0, 0, 0, 0);
9030a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  return ret;
9040a8c90248264a8b26970b4473770bcc3df8515fJosh Gao}
9050a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
9060a8c90248264a8b26970b4473770bcc3df8515fJosh Gao// pthread_rwlock_tryrdlock
9070a8c90248264a8b26970b4473770bcc3df8515fJosh GaoPTH_FUNC(int,
9080a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         pthreadZurwlockZutryrdlockZa, // pthread_rwlock_tryrdlock*
9090a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         pthread_rwlock_t* rwlock)
9100a8c90248264a8b26970b4473770bcc3df8515fJosh Gao{
9110a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   ret;
9120a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   res;
9130a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  OrigFn fn;
9140a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_GET_ORIG_FN(fn);
9150a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_RWLOCK_RDLOCK,
9160a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             rwlock, 0, 0, 0, 0);
9170a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  CALL_FN_W_W(ret, fn, rwlock);
9180a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_RWLOCK_RDLOCK,
9190a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             rwlock, ret == 0, 0, 0, 0);
9200a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  return ret;
9210a8c90248264a8b26970b4473770bcc3df8515fJosh Gao}
9220a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
9230a8c90248264a8b26970b4473770bcc3df8515fJosh Gao// pthread_rwlock_trywrlock
9240a8c90248264a8b26970b4473770bcc3df8515fJosh GaoPTH_FUNC(int,
9250a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         pthreadZurwlockZutrywrlockZa, // pthread_rwlock_trywrlock*
9260a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         pthread_rwlock_t* rwlock)
9270a8c90248264a8b26970b4473770bcc3df8515fJosh Gao{
9280a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   ret;
9290a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   res;
9300a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  OrigFn fn;
9310a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_GET_ORIG_FN(fn);
9320a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_RWLOCK_WRLOCK,
9330a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             rwlock, 0, 0, 0, 0);
9340a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  CALL_FN_W_W(ret, fn, rwlock);
9350a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_RWLOCK_WRLOCK,
9360a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             rwlock, ret == 0, 0, 0, 0);
9370a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  return ret;
9380a8c90248264a8b26970b4473770bcc3df8515fJosh Gao}
9390a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
9400a8c90248264a8b26970b4473770bcc3df8515fJosh Gao// pthread_rwlock_unlock
9410a8c90248264a8b26970b4473770bcc3df8515fJosh GaoPTH_FUNC(int,
9420a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         pthreadZurwlockZuunlockZa, // pthread_rwlock_unlock*
9430a8c90248264a8b26970b4473770bcc3df8515fJosh Gao         pthread_rwlock_t* rwlock)
9440a8c90248264a8b26970b4473770bcc3df8515fJosh Gao{
9450a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   ret;
9460a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  int   res;
9470a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  OrigFn fn;
9480a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_GET_ORIG_FN(fn);
9490a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_RWLOCK_UNLOCK,
9500a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             rwlock, 0, 0, 0, 0);
9510a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  CALL_FN_W_W(ret, fn, rwlock);
9520a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_RWLOCK_UNLOCK,
9530a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             rwlock, ret == 0, 0, 0, 0);
9540a8c90248264a8b26970b4473770bcc3df8515fJosh Gao  return ret;
9550a8c90248264a8b26970b4473770bcc3df8515fJosh Gao}
9560a8c90248264a8b26970b4473770bcc3df8515fJosh Gao