From: Julian Seward Date: Mon, 11 Feb 2008 11:00:51 +0000 (+0000) Subject: Fix race condition in sem_post() wrapper (Bart Van Assche). X-Git-Tag: svn/VALGRIND_3_4_0~1074 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1bb74c0cc0a4afc954906af758457020ef136b7f;p=thirdparty%2Fvalgrind.git Fix race condition in sem_post() wrapper (Bart Van Assche). git-svn-id: svn://svn.valgrind.org/valgrind/trunk@7395 --- diff --git a/exp-drd/drd_intercepts.c b/exp-drd/drd_intercepts.c index 0bd716334c..cb585cda4c 100644 --- a/exp-drd/drd_intercepts.c +++ b/exp-drd/drd_intercepts.c @@ -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; } diff --git a/exp-drd/drd_main.c b/exp-drd/drd_main.c index b70151cd7a..c42f0ffbc8 100644 --- a/exp-drd/drd_main.c +++ b/exp-drd/drd_main.c @@ -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) diff --git a/exp-drd/drd_semaphore.c b/exp-drd/drd_semaphore.c index 89242a52e5..ef28e71b7c 100644 --- a/exp-drd/drd_semaphore.c +++ b/exp-drd/drd_semaphore.c @@ -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)