]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Fix race condition in sem_post() wrapper (Bart Van Assche).
authorJulian Seward <jseward@acm.org>
Mon, 11 Feb 2008 11:00:51 +0000 (11:00 +0000)
committerJulian Seward <jseward@acm.org>
Mon, 11 Feb 2008 11:00:51 +0000 (11:00 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@7395

exp-drd/drd_intercepts.c
exp-drd/drd_main.c
exp-drd/drd_semaphore.c

index 0bd716334ccd493c9baee8be2c72366dae50f7c8..cb585cda4c33c98067d6eaa9e62ea4683a032e3b 100644 (file)
@@ -754,12 +754,8 @@ PTH_FUNC(int, sem_postZAGLIBCZu2Zd0, // sem_post@GLIBC_2.0
    VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_SEM_POST,
                               sem, sizeof(*sem), 0, 0, 0);
    CALL_FN_W_W(ret, fn, sem);
-   assert(ret == 0);
-   if (ret == 0)
-   {
-      VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_SEM_POST,
-                                 sem, sizeof(*sem), 0, 0, 0);
-   }
+   VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_SEM_POST,
+                              sem, sizeof(*sem), ret == 0, 0, 0);
    return ret;
 }
 
index b70151cd7acecc6ea9be13585e81858c46a83f49..c42f0ffbc8932fefbe9df509bc2abd6fecda736e 100644 (file)
@@ -91,7 +91,13 @@ static Bool drd_process_cmd_line_option(Char* arg)
       return False;
 
    if (trace_address)
+   {
       drd_trace_address = VG_(strtoll16)(trace_address, 0);
+#if 0
+      VG_(message)(Vg_DebugMsg, "Tracing address %s <> 0x%x\n",
+                   trace_address, drd_trace_address);
+#endif
+   }
    if (trace_barrier)
       barrier_set_trace(trace_barrier);
    if (trace_cond)
index 89242a52e5889a1cb537ee6ca64cea7432fd09e6..ef28e71b7c94dfa791c9b1002472145754abb837 100644 (file)
@@ -156,6 +156,8 @@ void semaphore_pre_post(const DrdThreadId tid, const Addr semaphore,
   if (p->value == 1)
   {
     p->last_sem_post_tid = tid;
+    thread_new_segment(tid);
+    vc_copy(&p->vc, thread_get_vc(tid));
   }
 }
 
@@ -163,14 +165,12 @@ void semaphore_pre_post(const DrdThreadId tid, const Addr semaphore,
 void semaphore_post_post(const DrdThreadId tid, const Addr semaphore,
                          const SizeT size, const Bool waited)
 {
-  if (waited)
-  {
-    struct semaphore_info* p;
-
-    p = semaphore_get_or_allocate(semaphore, size);
-    thread_new_segment(tid);
-    vc_copy(&p->vc, thread_get_vc(tid));
-  }
+  /* Note: it is hard to implement the sem_post() wrapper correctly if */
+  /* sem_post() can return an error code. The reason is that this would */
+  /* require to detect whether sem_post() will fail before sem_post is */
+  /* called -- p->vc may only be modified if the sem_post() call will */
+  /* succeed. */
+  tl_assert(waited);
 }
 
 void semaphore_thread_delete(const DrdThreadId threadid)