]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Remove pthread_object_size.h and associated hardwired constants.
authorJulian Seward <jseward@acm.org>
Fri, 30 Nov 2007 08:30:29 +0000 (08:30 +0000)
committerJulian Seward <jseward@acm.org>
Fri, 30 Nov 2007 08:30:29 +0000 (08:30 +0000)
(Bart Van Assche)

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@7252

14 files changed:
exp-drd/TODO.txt
exp-drd/drd_clientreq.c
exp-drd/drd_clientreq.h
exp-drd/drd_cond.c
exp-drd/drd_cond.h
exp-drd/drd_main.c
exp-drd/drd_mutex.c
exp-drd/drd_mutex.h
exp-drd/drd_preloaded.c
exp-drd/drd_thread.c
exp-drd/drd_track.h
exp-drd/priv_drd_clientreq.h [new file with mode: 0644]
exp-drd/pthread_object_size.h [deleted file]
exp-drd/tests/Makefile.am

index 02a135c3fc580d37eafefe5de0cb7b29091257a5..cbe891f33d627d0fbc4c3f3a32e63824cec40bb2 100644 (file)
@@ -19,7 +19,6 @@ Data-race detection algorithm
   AMD64).
 - Change s_threadinfo[] from an array into an OSet or VgHashTable, in order to
   make ThreadId <> DrdThreadId <> pthread_t conversions faster.
-- Write a configure test that figures out sizeof(pthread_mutex_t) etc.
 - [AMD64] Find out why removing 'write(1, "", 0)' in drd_preloaded.c triggers
   a crash on AMD64. Is this a drd or a VEX bug ?
 - Reintroduce the const keyword in the function declarations of the OSet
index 194d31f241712817e27d71aa8f3570555442908e..d77c741deee65fa698880e64c0bc120e7f72515c 100644 (file)
@@ -4,7 +4,7 @@
 #include "drd_suppression.h"      // drd_start_suppression()
 #include "drd_thread.h"
 #include "drd_track.h"
-#include "pthread_object_size.h"
+#include "priv_drd_clientreq.h"
 #include "pub_core_tooliface.h"   // VG_TRACK()
 #include "pub_tool_basics.h"      // Bool
 #include "pub_tool_libcassert.h"
@@ -20,24 +20,26 @@ static void drd_spin_init_or_unlock(const Addr spinlock, const SizeT size)
    struct mutex_info* mutex_p = mutex_get(spinlock);
    if (mutex_p)
    {
-      mutex_unlock(spinlock);
+      mutex_unlock(spinlock, mutex_type_spinlock);
    }
    else
    {
-      mutex_init(spinlock, size);
+      mutex_init(spinlock, size, mutex_type_spinlock);
    }
 }
 
-static void drd_pre_cond_wait(const Addr cond, const Addr mutex)
+static void drd_pre_cond_wait(const Addr cond, const SizeT cond_size,
+                              const Addr mutex)
 {
-   mutex_unlock(mutex);
-   cond_pre_wait(cond, mutex);
+   mutex_unlock(mutex, mutex_type_mutex);
+   cond_pre_wait(cond, cond_size, mutex);
 }
 
-static void drd_post_cond_wait(const Addr cond, const Addr mutex)
+static void drd_post_cond_wait(const Addr cond, const Addr mutex,
+                               const SizeT size)
 {
    cond_post_wait(cond);
-   mutex_lock(mutex, PTHREAD_MUTEX_SIZE);
+   mutex_lock(mutex, size, mutex_type_mutex);
 }
 
 static void drd_pre_cond_signal(const Addr cond)
@@ -105,7 +107,7 @@ static Bool drd_handle_client_request(ThreadId tid, UWord* arg, UWord* ret)
       break;
 
    case VG_USERREQ__PRE_MUTEX_INIT:
-      drd_pre_mutex_init(arg[1], arg[2]);
+      drd_pre_mutex_init(arg[1], arg[2], arg[3]);
       break;
 
    case VG_USERREQ__POST_MUTEX_DESTROY:
@@ -113,15 +115,15 @@ static Bool drd_handle_client_request(ThreadId tid, UWord* arg, UWord* ret)
       break;
 
    case VG_USERREQ__PRE_PTHREAD_MUTEX_LOCK:
-      drd_pre_mutex_lock(thread_get_running_tid(), arg[1], arg[2]);
+      drd_pre_mutex_lock(thread_get_running_tid(), arg[1], arg[2], arg[3]);
       break;
 
    case VG_USERREQ__POST_PTHREAD_MUTEX_LOCK:
-      drd_post_mutex_lock(thread_get_running_tid(), arg[1], arg[2]);
+      drd_post_mutex_lock(thread_get_running_tid(), arg[1], arg[2], arg[3]);
       break;
 
    case VG_USERREQ__PRE_PTHREAD_MUTEX_UNLOCK:
-      drd_pre_mutex_unlock(thread_get_running_tid(), arg[1]);
+      drd_pre_mutex_unlock(thread_get_running_tid(), arg[1], arg[3]);
       break;
 
    case VG_USERREQ__SPIN_INIT_OR_UNLOCK:
@@ -133,15 +135,16 @@ static Bool drd_handle_client_request(ThreadId tid, UWord* arg, UWord* ret)
       break;
 
    case VG_USERREQ__PRE_PTHREAD_COND_DESTROY:
-      drd_pre_cond_destroy(arg[1], arg[2]);
+      drd_pre_cond_destroy(arg[1]);
       break;
 
    case VG_USERREQ__PRE_PTHREAD_COND_WAIT:
-      drd_pre_cond_wait(arg[1], arg[2]);
+      drd_pre_cond_wait(arg[1]/*cond*/, arg[2]/*cond_size*/, arg[3]/*mutex*/);
       break;
 
    case VG_USERREQ__POST_PTHREAD_COND_WAIT:
-      drd_post_cond_wait(arg[1], arg[2]);
+      drd_post_cond_wait(arg[1]/*cond*/, arg[3]/*mutex*/,
+                         arg[4]/*mutex_size*/);
       break;
 
    case VG_USERREQ__PRE_PTHREAD_COND_SIGNAL:
index 57baee09189af3793766a9648c973ea66163b6c6..e07f008488ab7c7f6bb67a347422d17c515db104 100644 (file)
@@ -54,16 +54,16 @@ enum {
 
   /* To notify the core of a pthread_mutex_init call */
   VG_USERREQ__PRE_MUTEX_INIT,
-  /* args: Addr, SizeT */
+  /* args: Addr, MutexT */
   /* To notify the core of a pthread_mutex_destroy call */
   VG_USERREQ__POST_MUTEX_DESTROY,
-  /* args: Addr, SizeT */
+  /* args: Addr, SizeT, MutexT */
   /* To notify the core of pthread_mutex_lock calls */
   VG_USERREQ__PRE_PTHREAD_MUTEX_LOCK,
-  /* args: Addr, SizeT */
+  /* args: Addr, SizeT, MutexT */
   /* To notify the core of pthread_mutex_lock calls */
   VG_USERREQ__POST_PTHREAD_MUTEX_LOCK,
-  /* args: Addr, SizeT */
+  /* args: Addr, SizeT, MutexT */
   /* To notify the core of pthread_mutex_unlock calls */
   VG_USERREQ__PRE_PTHREAD_MUTEX_UNLOCK,
   /* args: Addr */
@@ -73,14 +73,14 @@ enum {
 
   /* To notify the core of a pthread_cond_init call */
   VG_USERREQ__POST_PTHREAD_COND_INIT,
-  /* args: Addr, SizeT */
+  /* args: Addr */
   /* To notify the core of a pthread_cond_destroy call */
   VG_USERREQ__PRE_PTHREAD_COND_DESTROY,
-  /* args: Addr, SizeT */
+  /* args: Addr cond, SizeT cond_size, Addr mutex, SizeT mutex_size */
   VG_USERREQ__PRE_PTHREAD_COND_WAIT,
-  /* args: Addr cond, Addr mutex */
+  /* args: Addr cond, SizeT cond_size, Addr mutex, SizeT mutex_size */
   VG_USERREQ__POST_PTHREAD_COND_WAIT,
-  /* args: Addr cond, Addr mutex */
+  /* args: Addr cond, SizeT cond_size, Addr mutex, SizeT mutex_size */
   VG_USERREQ__PRE_PTHREAD_COND_SIGNAL,
   /* args: Addr cond */
   VG_USERREQ__PRE_PTHREAD_COND_BROADCAST,
@@ -88,7 +88,11 @@ enum {
 
 };
 
-void drd_clientreq_init(void);
+typedef enum
+{
+   mutex_type_mutex = 1,
+   mutex_type_spinlock = 2,
+} MutexT;
 
 
 #endif //  __DRD_CLIENTREQ_H
index 0323fa0c4daeb73ed4645622e5b2d684495ff4b7..83db465b63be98dc58e845808988d38beb3dff97 100644 (file)
@@ -27,7 +27,6 @@
 #include "drd_error.h"
 #include "drd_mutex.h"
 #include "drd_suppression.h"
-#include "pthread_object_size.h"
 #include "pub_tool_errormgr.h"    // VG_(maybe_record_error)()
 #include "pub_tool_libcassert.h"  // tl_assert()
 #include "pub_tool_libcprint.h"   // VG_(printf)()
@@ -46,29 +45,37 @@ void cond_set_trace(const Bool trace_cond)
 }
 
 static
-void cond_initialize(struct cond_info* const p, const Addr cond)
+void cond_initialize(struct cond_info* const p, const Addr cond,
+                     const SizeT size)
 {
   tl_assert(cond != 0);
 
   p->cond         = cond;
+  p->size         = size;
   p->waiter_count = 0;
   p->mutex        = 0;
 }
 
-static struct cond_info* cond_get_or_allocate(const Addr cond)
+static struct cond_info*
+cond_get_or_allocate(const Addr cond, const SizeT size)
 {
   int i;
   for (i = 0; i < sizeof(s_cond)/sizeof(s_cond[0]); i++)
+  {
     if (s_cond[i].cond == cond)
+    {
+      tl_assert(s_cond[i].size == size);
       return &s_cond[i];
+    }
+  }
   for (i = 0; i < sizeof(s_cond)/sizeof(s_cond[0]); i++)
   {
     if (s_cond[i].cond == 0)
     {
-      cond_initialize(&s_cond[i], cond);
+      cond_initialize(&s_cond[i], cond, size);
       /* TO DO: replace the constant below by a symbolic constant referring */
       /* to sizeof(pthread_cond_t).                                        */
-      drd_start_suppression(cond, cond + PTHREAD_COND_SIZE, "cond");
+      drd_start_suppression(cond, cond + size, "cond");
       return &s_cond[i];
     }
   }
@@ -76,7 +83,7 @@ static struct cond_info* cond_get_or_allocate(const Addr cond)
   return 0;
 }
 
-void cond_init(const Addr cond)
+void cond_init(const Addr cond, const SizeT size)
 {
   if (s_trace_cond)
   {
@@ -85,7 +92,8 @@ void cond_init(const Addr cond)
                                VG_(clo_backtrace_size));
   }
   tl_assert(cond_get(cond) == 0);
-  cond_get_or_allocate(cond);
+  tl_assert(size > 0);
+  cond_get_or_allocate(cond, size);
 }
 
 void cond_destroy(struct cond_info* const p)
@@ -100,7 +108,7 @@ void cond_destroy(struct cond_info* const p)
   // TO DO: print a proper error message if waiter_count != 0.
   tl_assert(p->waiter_count == 0);
 
-  drd_finish_suppression(p->cond, p->cond + PTHREAD_COND_SIZE);
+  drd_finish_suppression(p->cond, p->cond + p->size);
 
   p->cond         = 0;
   p->waiter_count = 0;
@@ -116,11 +124,11 @@ struct cond_info* cond_get(const Addr cond)
   return 0;
 }
 
-int cond_pre_wait(const Addr cond, const Addr mutex)
+int cond_pre_wait(const Addr cond, const SizeT cond_size, const Addr mutex)
 {
   struct cond_info* p;
 
-  p = cond_get_or_allocate(cond);
+  p = cond_get_or_allocate(cond, cond_size);
   if (p->waiter_count == 0)
   {
     p->mutex = mutex;
@@ -194,7 +202,7 @@ void cond_stop_using_mem(const Addr a1, const Addr a2)
   {
     if (a1 <= s_cond[i].cond && s_cond[i].cond < a2)
     {
-      tl_assert(s_cond[i].cond + PTHREAD_COND_SIZE <= a2);
+      tl_assert(s_cond[i].cond + s_cond[i].size <= a2);
       cond_destroy(&s_cond[i]);
     }
   }
index 2a3b94570b98b392a01c8ae7155cf0b50c47c15a..9912c83c31464ee36f0c37f4dd0727c8604ecdf5 100644 (file)
 
 struct cond_info
 {
-  Addr cond;  // Pointer to client condition variable.
-  int  waiter_count;
-  Addr mutex; // Client mutex specified in pthread_cond_wait() call, and null
+  Addr  cond;  // Pointer to client condition variable.
+  SizeT size;  // sizeof(pthread_cond_t)
+  int   waiter_count;
+  Addr  mutex; // Client mutex specified in pthread_cond_wait() call, and null
               // if no client threads are currently waiting on this cond.var.
 };
 
 void cond_set_trace(const Bool trace_cond);
-void cond_init(const Addr cond);
+void cond_init(const Addr cond, const SizeT size);
 void cond_destroy(struct cond_info* const p);
 struct cond_info* cond_get(Addr const mutex);
-int cond_pre_wait(const Addr cond, const Addr mutex);
+int cond_pre_wait(const Addr cond, const SizeT cond_size, const Addr mutex);
 int cond_post_wait(const Addr cond);
 void cond_pre_signal(Addr const cond);
 void cond_pre_broadcast(Addr const cond);
index 7ddb900c8c9e2e826e2b72a3662ce683f38bd95a..900b08369e7ccaeed92c06e2e352ec7959e356cf 100644 (file)
@@ -34,7 +34,7 @@
 #include "drd_thread.h"
 #include "drd_track.h"
 #include "drd_vc.h"
-#include "pthread_object_size.h"
+#include "priv_drd_clientreq.h"
 #include "pub_core_mallocfree.h"
 #include "pub_core_options.h"
 #include "pub_tool_vki.h"
@@ -469,12 +469,12 @@ static void drd_thread_finished(ThreadId tid)
    thread_finished(drd_tid);
 }
 
-void drd_pre_mutex_init(Addr mutex, SizeT size)
+void drd_pre_mutex_init(Addr mutex, SizeT size, MutexT mutex_type)
 {
-   mutex_init(mutex, size);
+   mutex_init(mutex, size, mutex_type);
 }
 
-void drd_post_mutex_destroy(Addr mutex, SizeT size)
+void drd_post_mutex_destroy(Addr mutex, MutexT mutex_type)
 {
    struct mutex_info* p;
 
@@ -490,29 +490,32 @@ void drd_post_mutex_destroy(Addr mutex, SizeT size)
 
 void drd_pre_mutex_lock(const DrdThreadId drd_tid,
                         const Addr mutex,
-                        const SizeT size)
+                        const SizeT size,
+                        const MutexT mutex_type)
 {
    if (mutex_get(mutex) == 0)
    {
-      mutex_init(mutex, size);
+      mutex_init(mutex, size, mutex_type);
    }
 }
 
 void drd_post_mutex_lock(const DrdThreadId drd_tid,
                          const Addr mutex,
-                         const SizeT size)
+                         const SizeT size,
+                         const MutexT mutex_type)
 {
-   mutex_lock(mutex, size);
+   mutex_lock(mutex, size, mutex_type);
 }
 
-void drd_pre_mutex_unlock(const DrdThreadId drd_tid, Addr mutex)
+void drd_pre_mutex_unlock(const DrdThreadId drd_tid,
+                          const Addr mutex,
+                          const MutexT mutex_type)
 {
-   mutex_unlock(mutex);
+   mutex_unlock(mutex, mutex_type);
 }
 
 void drd_post_cond_init(Addr cond, SizeT s)
 {
-   tl_assert(s == PTHREAD_COND_SIZE);
    if (cond_get(cond))
    {
       CondErrInfo cei = { .cond = cond };
@@ -522,14 +525,13 @@ void drd_post_cond_init(Addr cond, SizeT s)
                               "initialized twice",
                               &cei);
    }
-   cond_init(cond);
+   cond_init(cond, s);
 }
 
-void drd_pre_cond_destroy(Addr cond, SizeT s)
+void drd_pre_cond_destroy(Addr cond)
 {
    struct cond_info* cond_p;
 
-   tl_assert(s == PTHREAD_COND_SIZE);
    cond_p = cond_get(cond);
    if (cond_p)
    {
index 25b4ef13b59c57a6117383082f443f36b5b2587a..304f36531a839171e4d5310d1ea1d5309ed06834 100644 (file)
@@ -26,7 +26,7 @@
 #include "drd_error.h"
 #include "drd_mutex.h"
 #include "drd_suppression.h"
-#include "pthread_object_size.h"
+#include "priv_drd_clientreq.h"
 #include "pub_tool_errormgr.h"    // VG_(maybe_record_error)()
 #include "pub_tool_libcassert.h"  // tl_assert()
 #include "pub_tool_libcprint.h"   // VG_(printf)()
@@ -40,6 +40,7 @@ struct mutex_info
 {
   Addr        mutex;           // Pointer to client mutex.
   SizeT       size;            // Size in bytes of client-side object.
+  MutexT      mutex_type;      // pthread_mutex_t or pthread_spinlock_t.
   int         recursion_count; // 0 if free, >= 1 if locked.
   DrdThreadId owner;           // owner if locked, last owner if free.
   VectorClock vc;              // vector clock associated with last unlock.
@@ -64,30 +65,47 @@ void mutex_set_trace(const Bool trace_mutex)
 static
 void mutex_initialize(struct mutex_info* const p,
                       const Addr mutex,
-                      const SizeT size)
+                      const SizeT size,
+                      const MutexT mutex_type)
 {
   tl_assert(mutex != 0);
   tl_assert(size > 0);
+  tl_assert(mutex_type == mutex_type_mutex
+            || mutex_type == mutex_type_spinlock);
 
   p->mutex           = mutex;
   p->size            = size;
+  p->mutex_type      = mutex_type;
   p->recursion_count = 0;
   p->owner           = DRD_INVALID_THREADID;
   vc_init(&p->vc, 0, 0);
 }
 
 static
-struct mutex_info* mutex_get_or_allocate(const Addr mutex, const SizeT size)
+struct mutex_info*
+mutex_get_or_allocate(const Addr mutex,
+                      const SizeT size,
+                      const MutexT mutex_type)
 {
   int i;
+
+  tl_assert(mutex_type == mutex_type_mutex
+            || mutex_type == mutex_type_spinlock);
+
   for (i = 0; i < sizeof(s_mutex)/sizeof(s_mutex[0]); i++)
+  {
     if (s_mutex[i].mutex == mutex)
+    {
+      tl_assert(s_mutex[i].mutex_type == mutex_type);
+      tl_assert(s_mutex[i].size == size);
       return &s_mutex[i];
+    }
+  }
   for (i = 0; i < sizeof(s_mutex)/sizeof(s_mutex[0]); i++)
   {
     if (s_mutex[i].mutex == 0)
     {
-      mutex_initialize(&s_mutex[i], mutex, size);
+      mutex_initialize(&s_mutex[i], mutex, size, mutex_type);
       drd_start_suppression(mutex, mutex + size,
                             mutex_get_typename(&s_mutex[i]));
       return &s_mutex[i];
@@ -97,12 +115,15 @@ struct mutex_info* mutex_get_or_allocate(const Addr mutex, const SizeT size)
   return 0;
 }
 
-struct mutex_info* mutex_init(const Addr mutex, const SizeT size)
+struct mutex_info*
+mutex_init(const Addr mutex, const SizeT size, const MutexT mutex_type)
 {
   struct mutex_info* mutex_p;
 
   tl_assert(mutex_get(mutex) == 0);
-  mutex_p = mutex_get_or_allocate(mutex, size);
+  tl_assert(mutex_type == mutex_type_mutex
+            || mutex_type == mutex_type_spinlock);
+  mutex_p = mutex_get_or_allocate(mutex, size, mutex_type);
 
   if (s_trace_mutex)
   {
@@ -151,10 +172,10 @@ struct mutex_info* mutex_get(const Addr mutex)
  * Note: this function must be called after pthread_mutex_lock() has been
  * called, or a race condition is triggered !
  */
-int mutex_lock(const Addr mutex, const SizeT size)
+int mutex_lock(const Addr mutex, const SizeT size, MutexT mutex_type)
 {
   const DrdThreadId drd_tid = VgThreadIdToDrdThreadId(VG_(get_running_tid)());
-  struct mutex_info* const p = mutex_get_or_allocate(mutex, size);
+  struct mutex_info* const p = mutex_get_or_allocate(mutex, size, mutex_type);
   const DrdThreadId last_owner = p->owner;
 
   if (s_trace_mutex)
@@ -170,7 +191,12 @@ int mutex_lock(const Addr mutex, const SizeT size)
                  p ? p->owner : VG_INVALID_THREADID);
   }
 
-  if (p->recursion_count >= 1 && p->size == PTHREAD_SPINLOCK_SIZE)
+  tl_assert(mutex_type == mutex_type_mutex
+            || mutex_type == mutex_type_spinlock);
+  tl_assert(p->mutex_type == mutex_type);
+  tl_assert(p->size == size);
+
+  if (p->recursion_count >= 1 && mutex_type == mutex_type_spinlock)
   {
     // TO DO: tell the user in a more friendly way that it is not allowed to
     // lock spinlocks recursively.
@@ -211,7 +237,7 @@ int mutex_lock(const Addr mutex, const SizeT size)
  * @param tid ThreadId of the thread calling pthread_mutex_unlock().
  * @param vc Pointer to the current vector clock of thread tid.
  */
-int mutex_unlock(const Addr mutex)
+int mutex_unlock(const Addr mutex, const MutexT mutex_type)
 {
   const DrdThreadId drd_tid = VgThreadIdToDrdThreadId(VG_(get_running_tid)());
   const ThreadId vg_tid = DrdThreadIdToVgThreadId(drd_tid);
@@ -230,7 +256,11 @@ int mutex_unlock(const Addr mutex)
   }
 
   tl_assert(p);
+  tl_assert(p->mutex_type == mutex_type);
   tl_assert(p->owner != DRD_INVALID_THREADID);
+  tl_assert(mutex_type == mutex_type_mutex
+            || mutex_type == mutex_type_spinlock);
+
   if (p->owner != drd_tid)
   {
     MutexErrInfo MEI = { p->mutex, p->recursion_count, p->owner };
@@ -257,11 +287,12 @@ int mutex_unlock(const Addr mutex)
 const char* mutex_get_typename(struct mutex_info* const p)
 {
   tl_assert(p);
-  switch (p->size)
+
+  switch (p->mutex_type)
   {
-  case PTHREAD_MUTEX_SIZE:
+  case mutex_type_mutex:
     return "mutex";
-  case PTHREAD_SPINLOCK_SIZE:
+  case mutex_type_spinlock:
     return "spinlock";
   default:
     tl_assert(0);
index 03d2994b03ccb8f35308d7520d72389034eb01e3..180c7e1744e67cd9c780a89a7a149c86e5d136b3 100644 (file)
 #define __MUTEX_H
 
 
-#include "pub_tool_basics.h"      // Addr, SizeT
-#include "drd_vc.h"
+#include "drd_clientreq.h"        // MutexT
 #include "drd_thread.h"           // DrdThreadId
+#include "drd_vc.h"
+#include "pub_tool_basics.h"      // Addr, SizeT
 
 
 struct mutex_info;
 
 
 void mutex_set_trace(const Bool trace_mutex);
-struct mutex_info* mutex_init(const Addr mutex, const SizeT size);
+struct mutex_info* mutex_init(const Addr mutex, const SizeT size,
+                              const MutexT mutex_type);
 void mutex_destroy(struct mutex_info* const p);
 struct mutex_info* mutex_get(const Addr mutex);
-int mutex_lock(const Addr mutex, const SizeT size);
-int mutex_unlock(const Addr mutex);
+int mutex_lock(const Addr mutex, const SizeT size, const MutexT mutex_type);
+int mutex_unlock(const Addr mutex, const MutexT mutex_type);
 const char* mutex_get_typename(struct mutex_info* const p);
 Bool mutex_is_locked_by(const Addr mutex, const DrdThreadId tid);
 const VectorClock* mutex_get_last_vc(const Addr mutex);
index 8c9028845cb1ceaa18f2a2953fdda861dbd1860f..0a0b30035b403f017d2b5972b31a111a2cb1fce5 100644 (file)
@@ -56,7 +56,6 @@
 #include "pub_core_debuginfo.h"  // Needed for pub_core_redir.h
 #include "pub_core_redir.h"      // For VG_NOTIFY_ON_LOAD
 #include "pub_tool_threadstate.h"// VG_N_THREADS
-#include "pthread_object_size.h" // PTHREAD_MUTEX_SIZE etc.
 
 
 // Defines.
@@ -165,10 +164,6 @@ static void vg_set_main_thread_state(void)
    VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__DRD_SUPPRESS_CURRENT_STACK,
                               0, 0, 0, 0, 0);
 
-   // Sanity checks.
-   assert(sizeof(pthread_mutex_t)    == PTHREAD_MUTEX_SIZE);
-   assert(sizeof(pthread_spinlock_t) == PTHREAD_SPINLOCK_SIZE);
-
    // Make sure that DRD knows about the main thread's POSIX thread ID.
    VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__SET_PTHREADID,
                               pthread_self(), 0, 0, 0, 0);
@@ -281,7 +276,7 @@ PTH_FUNC(int, pthreadZumutexZuinit,
    OrigFn fn;
    VALGRIND_GET_ORIG_FN(fn);
    VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_MUTEX_INIT,
-                              mutex, sizeof(*mutex), 0, 0, 0);
+                              mutex, sizeof(*mutex), mutex_type_mutex, 0, 0);
    CALL_FN_W_WW(ret, fn, mutex, attr);
    return ret;
 }
@@ -296,7 +291,7 @@ PTH_FUNC(int, pthreadZumutexZudestroy,
    VALGRIND_GET_ORIG_FN(fn);
    CALL_FN_W_W(ret, fn, mutex);
    VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_MUTEX_DESTROY,
-                              mutex, sizeof(*mutex), 0, 0, 0);
+                              mutex, mutex_type_mutex, 0, 0, 0);
    return ret;
 }
 
@@ -309,7 +304,7 @@ PTH_FUNC(int, pthreadZumutexZulock, // pthread_mutex_lock
    OrigFn fn;
    VALGRIND_GET_ORIG_FN(fn);
    VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__PRE_PTHREAD_MUTEX_LOCK,
-                              mutex, sizeof(*mutex), 0, 0, 0);
+                              mutex, sizeof(*mutex), mutex_type_mutex, 0, 0);
 #if 1
    // The only purpose of the system call below is to make drd work on AMD64
    // systems. Without this system call, clients crash (SIGSEGV) in
@@ -319,7 +314,7 @@ PTH_FUNC(int, pthreadZumutexZulock, // pthread_mutex_lock
    CALL_FN_W_W(ret, fn, mutex);
    if (ret == 0)
       VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__POST_PTHREAD_MUTEX_LOCK,
-                                 mutex, sizeof(*mutex), 0, 0, 0);
+                                mutex, sizeof(*mutex), mutex_type_mutex, 0, 0);
    return ret;
 }
 
@@ -335,7 +330,7 @@ PTH_FUNC(int, pthreadZumutexZutrylock, // pthread_mutex_trylock
    if (ret == 0)
    {
       VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_PTHREAD_MUTEX_LOCK,
-                                 mutex, sizeof(*mutex), 0, 0, 0);
+                                mutex, sizeof(*mutex), mutex_type_mutex, 0, 0);
    }
    return ret;
 }
@@ -350,7 +345,7 @@ PTH_FUNC(int, pthreadZumutexZuunlock, // pthread_mutex_unlock
    VALGRIND_GET_ORIG_FN(fn);
    VALGRIND_DO_CLIENT_REQUEST(res, -1,
                               VG_USERREQ__PRE_PTHREAD_MUTEX_UNLOCK,
-                              mutex, sizeof(*mutex), 0, 0, 0);
+                              mutex, sizeof(*mutex), mutex_type_mutex, 0, 0);
    CALL_FN_W_W(ret, fn, mutex);
    return ret;
 }
@@ -379,7 +374,7 @@ PTH_FUNC(int, pthreadZucondZudestroyZAZa, // pthread_cond_destroy@*
    OrigFn fn;
    VALGRIND_GET_ORIG_FN(fn);
    VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_PTHREAD_COND_DESTROY,
-                              cond, sizeof(*cond), 0, 0, 0);
+                              cond, 0, 0, 0, 0);
    CALL_FN_W_W(ret, fn, cond);
    return ret;
 }
@@ -394,10 +389,10 @@ PTH_FUNC(int, pthreadZucondZuwaitZAZa, // pthread_cond_wait@*
    OrigFn fn;
    VALGRIND_GET_ORIG_FN(fn);
    VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_PTHREAD_COND_WAIT,
-                              cond, mutex, 0, 0, 0);
+                              cond, sizeof(*cond), mutex, sizeof(*mutex), 0);
    CALL_FN_W_WW(ret, fn, cond, mutex);
    VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_PTHREAD_COND_WAIT,
-                              cond, mutex, 0, 0, 0);
+                              cond, sizeof(*cond), mutex, sizeof(*mutex), 0);
    return ret;
 }
 
@@ -412,10 +407,10 @@ PTH_FUNC(int, pthreadZucondZutimedwaitZAZa, // pthread_cond_timedwait@*
    OrigFn fn;
    VALGRIND_GET_ORIG_FN(fn);
    VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_PTHREAD_COND_WAIT,
-                              cond, mutex, 0, 0, 0);
+                              cond, sizeof(*cond), mutex, sizeof(*mutex), 0);
    CALL_FN_W_WWW(ret, fn, cond, mutex, abstime);
    VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_PTHREAD_COND_WAIT,
-                              cond, mutex, 0, 0, 0);
+                              cond, sizeof(*cond), mutex, sizeof(*mutex), 0);
    return ret;
 }
 
@@ -458,7 +453,8 @@ PTH_FUNC(int, pthreadZuspinZuinit, // pthread_spin_init
    OrigFn fn;
    VALGRIND_GET_ORIG_FN(fn);
    VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__SPIN_INIT_OR_UNLOCK,
-                              spinlock, sizeof(*spinlock), 0, 0, 0);
+                              spinlock, sizeof(*spinlock),
+                              mutex_type_spinlock, 0, 0);
    CALL_FN_W_WW(ret, fn, spinlock, pshared);
    return ret;
 }
@@ -473,7 +469,7 @@ PTH_FUNC(int, pthreadZuspinZudestroy, // pthread_spin_destroy
    VALGRIND_GET_ORIG_FN(fn);
    CALL_FN_W_W(ret, fn, spinlock);
    VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_MUTEX_DESTROY,
-                              spinlock, sizeof(*spinlock), 0, 0, 0);
+                              spinlock, mutex_type_spinlock, 0, 0, 0);
    return ret;
 }
 
@@ -489,7 +485,8 @@ PTH_FUNC(int, pthreadZuspinZulock, // pthread_spin_lock
    if (ret == 0)
    {
       VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_PTHREAD_MUTEX_LOCK,
-                                 spinlock, sizeof(*spinlock), 0, 0, 0);
+                                 spinlock, sizeof(*spinlock),
+                                 mutex_type_spinlock, 0, 0);
    }
    return ret;
 }
@@ -506,7 +503,8 @@ PTH_FUNC(int, pthreadZuspinZutrylock, // pthread_spin_trylock
    if (ret == 0)
    {
       VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_PTHREAD_MUTEX_LOCK,
-                                 spinlock, sizeof(*spinlock), 0, 0, 0);
+                                 spinlock, sizeof(*spinlock),
+                                 mutex_type_spinlock, 0, 0);
    }
    return ret;
 }
@@ -520,7 +518,8 @@ PTH_FUNC(int, pthreadZuspinZuunlock, // pthread_spin_unlock
    OrigFn fn;
    VALGRIND_GET_ORIG_FN(fn);
    VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__SPIN_INIT_OR_UNLOCK,
-                              spinlock, sizeof(*spinlock), 0, 0, 0);
+                              spinlock, sizeof(*spinlock),
+                              mutex_type_spinlock, 0, 0);
    CALL_FN_W_W(ret, fn, spinlock);
    return ret;
 }
index 72a92dc02bb40576d24294fcbb09417603684edd..38121a2575dc0cce1c80e1ebf961423fb402b729 100644 (file)
@@ -27,7 +27,6 @@
 #include "drd_segment.h"
 #include "drd_suppression.h"
 #include "drd_thread.h"
-#include "pthread_object_size.h"
 #include "pub_core_options.h"     // VG_(clo_backtrace_size)
 #include "pub_tool_basics.h"      // Addr, SizeT
 #include "pub_tool_errormgr.h"    // VG_(unique_error)()
index 8d56222c5424caf38acfc5eea4501fa33f802020..4a8e564f696202f6f0c1585b88d2fb69405d75c6 100644 (file)
@@ -1,8 +1,11 @@
 void drd_post_thread_join(DrdThreadId joiner, DrdThreadId joinee);
-void drd_pre_mutex_init(Addr mutex, SizeT size);
-void drd_post_mutex_destroy(Addr mutex, SizeT size);
-void drd_pre_mutex_lock(DrdThreadId tid, Addr mutex, const SizeT size);
-void drd_post_mutex_lock(DrdThreadId tid, Addr mutex, const SizeT size);
-void drd_pre_mutex_unlock(DrdThreadId tid, Addr mutex);
+void drd_pre_mutex_init(Addr mutex, SizeT size, const MutexT mutex_type);
+void drd_post_mutex_destroy(Addr mutex, const MutexT mutex_type);
+void drd_pre_mutex_lock(DrdThreadId tid, Addr mutex, const SizeT size,
+                        const MutexT mutex_type);
+void drd_post_mutex_lock(DrdThreadId tid, Addr mutex, const SizeT size,
+                         const MutexT mutex_type);
+void drd_pre_mutex_unlock(const DrdThreadId tid, const Addr mutex,
+                          const MutexT mutex_type);
 void drd_post_cond_init(Addr cond, SizeT s);
-void drd_pre_cond_destroy(Addr cond, SizeT s);
+void drd_pre_cond_destroy(Addr cond);
diff --git a/exp-drd/priv_drd_clientreq.h b/exp-drd/priv_drd_clientreq.h
new file mode 100644 (file)
index 0000000..0e63b0e
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+  This file is part of drd, a data race detector.
+
+  Copyright (C) 2006-2007 Bart Van Assche
+  bart.vanassche@gmail.com
+
+  This program is free software; you can redistribute it and/or
+  modify it under the terms of the GNU General Public License as
+  published by the Free Software Foundation; either version 2 of the
+  License, or (at your option) any later version.
+
+  This program is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+  02111-1307, USA.
+
+  The GNU General Public License is contained in the file COPYING.
+*/
+
+#ifndef __PRIV_DRD_CLIENTREQ_H
+#define __PRIV_DRD_CLIENTREQ_H
+
+void drd_clientreq_init(void);
+
+#endif /* __PRIV_DRD_CLIENTREQ_H */
diff --git a/exp-drd/pthread_object_size.h b/exp-drd/pthread_object_size.h
deleted file mode 100644 (file)
index 75b1baa..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-// TO DO: replace the constants below by macro's #define'd during the configure
-// phase.
-
-#if defined(VGP_x86_linux)
-# define PTHREAD_MUTEX_SIZE    24
-# define PTHREAD_COND_SIZE     48
-#elif defined(VGP_amd64_linux)
-# define PTHREAD_MUTEX_SIZE    40
-# define PTHREAD_COND_SIZE     48
-#else
-  /* FIXME: fill these fields in correctly.  32 is arbitrary. */
-# define PTHREAD_MUTEX_SIZE    32
-# define PTHREAD_COND_SIZE     32
-#endif
-#define PTHREAD_SPINLOCK_SIZE  4
index 2959c5665f33fb06d0c1451fec15f48cd9869c31..bc01d0dacadf4f0c709f079831ad78e59039ee22 100644 (file)
@@ -57,4 +57,4 @@ pth_detached_SOURCES  = pth_detached.c
 pth_detached_LDADD    = -lpthread
 
 sigalrm_SOURCES       = sigalrm.c
-sigalrm_LDADD         = -lpthread -lrt
+sigalrm_LDADD         = -lpthread