]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Added support for recognizing invalid mutexes.
authorBart Van Assche <bvanassche@acm.org>
Thu, 28 Feb 2008 08:30:43 +0000 (08:30 +0000)
committerBart Van Assche <bvanassche@acm.org>
Thu, 28 Feb 2008 08:30:43 +0000 (08:30 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@7497

exp-drd/drd_clientreq.h
exp-drd/drd_intercepts.c
exp-drd/drd_mutex.c
exp-drd/tests/tc09_bad_unlock.stderr.exp
exp-drd/tests/tc20_verifywrap.stderr.exp

index bb701e298346c8550155b387686204c672ed0628..b0357130c62d4112ce9ff42528ea04b8fd6219b6 100644 (file)
@@ -119,6 +119,7 @@ enum {
 
 typedef enum
 {
+   mutex_type_invalid_mutex    = 0,
    mutex_type_recursive_mutex  = 1,
    mutex_type_errorcheck_mutex = 2,
    mutex_type_default_mutex    = 3,
index 5ed7a5bc8529698f0637f84d1b6af66b7d6bdcf7..07900de4d5e78a7a67f9cc18b6905a59a98e6e20 100644 (file)
@@ -100,18 +100,8 @@ static MutexT pthread_to_drd_mutex_type(const int kind)
    case PTHREAD_MUTEX_DEFAULT:
    case PTHREAD_MUTEX_ADAPTIVE_NP:
       return mutex_type_default_mutex;
-#if 0
-   case -1:
-      printf("Warning: changed mutex type from -1 into %d\n",
-             mutex_type_default_mutex);
-      return mutex_type_default_mutex;
-#endif
    }
-#if 0
-   printf("mutex->__data.__kind = %d\n", kind);
-   assert(0);
-#endif
-   return mutex_type_default_mutex;
+   return mutex_type_invalid_mutex;
 }
 
 static MutexT mutex_type(pthread_mutex_t* mutex)
index 491d047cc7a53dcbac6cc8809030ed4b62b41628..e45c6a692a900ed2c133e2e11257a31473a5266d 100644 (file)
@@ -251,12 +251,15 @@ struct mutex_info* mutex_get(const Addr mutex)
  */
 void mutex_pre_lock(const Addr mutex, const SizeT size, MutexT mutex_type)
 {
-  struct mutex_info* p = mutex_get(mutex);
+  struct mutex_info* p;
+
+  p = mutex_get(mutex);
   if (p == 0)
   {
     mutex_init(mutex, size, mutex_type);
     p = mutex_get(mutex);
   }
+
   tl_assert(p);
 
   if (p->owner == thread_get_running_tid()
@@ -295,6 +298,16 @@ int mutex_post_lock(const Addr mutex, const SizeT size, MutexT mutex_type)
                  p ? p->owner : VG_INVALID_THREADID);
   }
 
+  if (mutex_type == mutex_type_invalid_mutex)
+  {
+    GenericErrInfo GEI;
+    VG_(maybe_record_error)(VG_(get_running_tid)(),
+                            GenericErr,
+                            VG_(get_IP)(VG_(get_running_tid)()),
+                            "Invalid mutex",
+                            &GEI);
+  }
+
   if (p == 0)
   {
      GenericErrInfo GEI;
@@ -368,6 +381,16 @@ int mutex_unlock(const Addr mutex, const MutexT mutex_type)
                  p->owner);
   }
 
+  if (mutex_type == mutex_type_invalid_mutex)
+  {
+    GenericErrInfo GEI;
+    VG_(maybe_record_error)(VG_(get_running_tid)(),
+                            GenericErr,
+                            VG_(get_IP)(VG_(get_running_tid)()),
+                            "Invalid mutex",
+                            &GEI);
+  }
+
   if (p == 0)
   {
      GenericErrInfo GEI;
@@ -448,6 +471,8 @@ const char* mutex_type_name(const MutexT mt)
 {
   switch (mt)
   {
+  case mutex_type_invalid_mutex:
+    return "invalid mutex";
   case mutex_type_recursive_mutex:
     return "recursive mutex";
   case mutex_type_errorcheck_mutex:
index a16e24c7cb3251bcbf03a27e2a33bf5361f9bd60..40b301ccc5841356fe6a2d4cb13df93a37ea80da 100644 (file)
@@ -13,6 +13,11 @@ Mutex not unlocked by owner thread: address 0x........, recursion count 1, owner
    by 0x........: clone (in /...libc...)
 
 Thread 1:
+Invalid mutex
+   at 0x........: pthread_mutex_unlock (drd_intercepts.c:?)
+   by 0x........: nearly_main (tc09_bad_unlock.c:41)
+   by 0x........: main (tc09_bad_unlock.c:49)
+
 Not a mutex
    at 0x........: pthread_mutex_unlock (drd_intercepts.c:?)
    by 0x........: nearly_main (tc09_bad_unlock.c:41)
@@ -32,9 +37,14 @@ Mutex not unlocked by owner thread: address 0x........, recursion count 1, owner
    by 0x........: clone (in /...libc...)
 
 Thread 1:
+Invalid mutex
+   at 0x........: pthread_mutex_unlock (drd_intercepts.c:?)
+   by 0x........: nearly_main (tc09_bad_unlock.c:41)
+   by 0x........: main (tc09_bad_unlock.c:50)
+
 Not a mutex
    at 0x........: pthread_mutex_unlock (drd_intercepts.c:?)
    by 0x........: nearly_main (tc09_bad_unlock.c:41)
    by 0x........: main (tc09_bad_unlock.c:50)
 
-ERROR SUMMARY: 6 errors from 6 contexts (suppressed: 0 from 0)
+ERROR SUMMARY: 8 errors from 8 contexts (suppressed: 0 from 0)
index a5d09792876b2f6c88cae33a982d7e55d6ce7ea0..ccc5f40439205da662ca916e301326235f3fa71e 100644 (file)
@@ -24,6 +24,10 @@ Destroying locked mutex: address 0x........, recursion count 1, owner 1.
    at 0x........: pthread_mutex_destroy (drd_intercepts.c:?)
    by 0x........: main (tc20_verifywrap.c:102)
 
+Invalid mutex
+   at 0x........: pthread_mutex_unlock (drd_intercepts.c:?)
+   by 0x........: main (tc20_verifywrap.c:125)
+
 Mutex not locked: address 0x........, recursion count 0, owner 0.
    at 0x........: pthread_mutex_unlock (drd_intercepts.c:?)
    by 0x........: main (tc20_verifywrap.c:125)
@@ -67,4 +71,4 @@ FIXME: can't figure out how to verify wrap of sem_post
 Destroying locked mutex: address 0x........, recursion count 1, owner 1.
    at 0x........: main (tc20_verifywrap.c:261)
 
-ERROR SUMMARY: 6 errors from 6 contexts (suppressed: 0 from 0)
+ERROR SUMMARY: 7 errors from 7 contexts (suppressed: 0 from 0)