From: Bart Van Assche Date: Sat, 6 Jun 2009 19:22:26 +0000 (+0000) Subject: Merged trunk revisions 10261, 10262, 10265, 10266 and 10269. X-Git-Tag: svn/VALGRIND_3_4_1~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=32174b67427b5e134aeacab517b0b3f5e3a87789;p=thirdparty%2Fvalgrind.git Merged trunk revisions 10261, 10262, 10265, 10266 and 10269. git-svn-id: svn://svn.valgrind.org/valgrind/branches/VALGRIND_3_4_BRANCH@10270 --- diff --git a/drd/drd_barrier.c b/drd/drd_barrier.c index 0dd53d3418..a8568cafc9 100644 --- a/drd/drd_barrier.c +++ b/drd/drd_barrier.c @@ -388,6 +388,10 @@ void barrier_post_wait(const DrdThreadId tid, const Addr barrier, VG_(OSetGen_Insert)(p->oset, q); tl_assert(VG_(OSetGen_Lookup)(p->oset, &word_tid) == q); } + + thread_new_segment(tid); + s_barrier_segment_creation_count++; + VG_(OSetGen_ResetIter)(p->oset); for ( ; (r = VG_(OSetGen_Next)(p->oset)) != 0; ) { @@ -398,9 +402,6 @@ void barrier_post_wait(const DrdThreadId tid, const Addr barrier, } } - thread_new_segment(tid); - s_barrier_segment_creation_count++; - if (--p->post_waiters_left <= 0) { p->post_iteration = 1 - p->post_iteration; diff --git a/drd/drd_gomp_intercepts.c b/drd/drd_gomp_intercepts.c index 4922b49c16..7072325d6c 100644 --- a/drd/drd_gomp_intercepts.c +++ b/drd/drd_gomp_intercepts.c @@ -59,6 +59,8 @@ typedef void* gomp_barrier_t; // Function definitions. +#if 0 + GOMP_FUNC(void, gompZubarrierZuinit, // gomp_barrier_init gomp_barrier_t* barrier, unsigned count) { @@ -115,3 +117,5 @@ GOMP_FUNC(void, gompZubarrierZuwait, // gomp_barrier_wait VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_BARRIER_WAIT, barrier, gomp_barrier, 1, 0, 0); } + +#endif diff --git a/drd/drd_main.c b/drd/drd_main.c index 0dc981cc10..bdd6a94cea 100644 --- a/drd/drd_main.c +++ b/drd/drd_main.c @@ -646,9 +646,10 @@ void drd_post_thread_join(DrdThreadId drd_joiner, DrdThreadId drd_joinee) { tl_assert(IsValidDrdThreadId(drd_joiner)); tl_assert(IsValidDrdThreadId(drd_joinee)); - thread_new_segment(drd_joinee); - thread_combine_vc(drd_joiner, drd_joinee); + thread_new_segment(drd_joiner); + thread_combine_vc(drd_joiner, drd_joinee); + thread_new_segment(drd_joinee); if (s_drd_trace_fork_join) { diff --git a/drd/drd_mutex.c b/drd/drd_mutex.c index fc3b8af14a..09275b8b10 100644 --- a/drd/drd_mutex.c +++ b/drd/drd_mutex.c @@ -301,13 +301,14 @@ void mutex_post_lock(const Addr mutex, const Bool took_lock, { const DrdThreadId last_owner = p->owner; + thread_new_segment(drd_tid); + s_mutex_segment_creation_count++; + if (last_owner != drd_tid && last_owner != DRD_INVALID_THREADID) { tl_assert(p->last_locked_segment); thread_combine_vc2(drd_tid, &p->last_locked_segment->vc); } - thread_new_segment(drd_tid); - s_mutex_segment_creation_count++; p->owner = drd_tid; p->acquiry_time_ms = VG_(read_millisecond_timer)(); diff --git a/drd/drd_rwlock.c b/drd/drd_rwlock.c index 20800a4466..cb9200e9e9 100644 --- a/drd/drd_rwlock.c +++ b/drd/drd_rwlock.c @@ -368,10 +368,10 @@ void rwlock_post_rdlock(const Addr rwlock, const Bool took_lock) q = lookup_or_insert_node(p->thread_info, drd_tid); if (++q->reader_nesting_count == 1) { - rwlock_combine_other_vc(p, drd_tid, False); q->last_lock_was_writer_lock = False; thread_new_segment(drd_tid); s_rwlock_segment_creation_count++; + rwlock_combine_other_vc(p, drd_tid, False); p->acquiry_time_ms = VG_(read_millisecond_timer)(); p->acquired_at = VG_(record_ExeContext)(VG_(get_running_tid)(), 0); @@ -446,9 +446,9 @@ void rwlock_post_wrlock(const Addr rwlock, const Bool took_lock) q->writer_nesting_count++; q->last_lock_was_writer_lock = True; tl_assert(q->writer_nesting_count == 1); - rwlock_combine_other_vc(p, drd_tid, True); thread_new_segment(drd_tid); s_rwlock_segment_creation_count++; + rwlock_combine_other_vc(p, drd_tid, True); p->acquiry_time_ms = VG_(read_millisecond_timer)(); p->acquired_at = VG_(record_ExeContext)(VG_(get_running_tid)(), 0); } diff --git a/drd/drd_semaphore.c b/drd/drd_semaphore.c index e5c867ce85..c2878ef7f7 100644 --- a/drd/drd_semaphore.c +++ b/drd/drd_semaphore.c @@ -227,9 +227,17 @@ void semaphore_pre_wait(const Addr semaphore) p = semaphore_get_or_allocate(semaphore); tl_assert(p); - tl_assert((int)p->waiters >= 0); p->waiters++; - tl_assert(p->waiters > 0); + + if ((int)p->waiters <= 0) + { + SemaphoreErrInfo sei = { semaphore }; + VG_(maybe_record_error)(VG_(get_running_tid)(), + SemaphoreErr, + VG_(get_IP)(VG_(get_running_tid)()), + "Invalid semaphore", + &sei); + } } /** Called after sem_wait() finished. @@ -253,12 +261,21 @@ void semaphore_post_wait(const DrdThreadId tid, const Addr semaphore, p ? p->value : 0, p ? p->value - 1 : 0); } - tl_assert(p); - tl_assert(p->waiters > 0); - p->waiters--; - tl_assert((int)p->waiters >= 0); - tl_assert((int)p->value >= 0); - if (p->value == 0) + + if (p) + { + p->waiters--; + p->value--; + } + + /* + * Note: if another thread destroyed and reinitialized a semaphore while + * the current thread was waiting in sem_wait, p->waiters may have been + * set to zero by semaphore_initialize() after + * semaphore_pre_wait() has finished before + * semaphore_post_wait() has been called. + */ + if (p == NULL || (int)p->value < 0 || (int)p->waiters < 0) { SemaphoreErrInfo sei = { semaphore }; VG_(maybe_record_error)(VG_(get_running_tid)(), @@ -268,8 +285,7 @@ void semaphore_post_wait(const DrdThreadId tid, const Addr semaphore, &sei); return; } - p->value--; - tl_assert((int)p->value >= 0); + if (p->waits_to_skip > 0) p->waits_to_skip--; else @@ -278,14 +294,15 @@ void semaphore_post_wait(const DrdThreadId tid, const Addr semaphore, tl_assert(sg); if (sg) { + thread_new_segment(tid); + s_semaphore_segment_creation_count++; + if (p->last_sem_post_tid != tid && p->last_sem_post_tid != DRD_INVALID_THREADID) { thread_combine_vc2(tid, &sg->vc); } sg_put(sg); - thread_new_segment(tid); - s_semaphore_segment_creation_count++; } } } @@ -310,11 +327,11 @@ void semaphore_pre_post(const DrdThreadId tid, const Addr semaphore) } p->last_sem_post_tid = tid; - thread_new_segment(tid); sg = 0; thread_get_latest_segment(&sg, tid); tl_assert(sg); segment_push(p, sg); + thread_new_segment(tid); s_semaphore_segment_creation_count++; } diff --git a/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.3 b/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.3 index 1c36ddf96b..c6dbd79687 100644 --- a/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.3 +++ b/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.3 @@ -134,11 +134,11 @@ Invalid semaphore: semaphore 0x........ semaphore 0x........ was first observed at: at 0x........: sem_init* (drd_pthread_intercepts.c:?) by 0x........: main (tc20_verifywrap.c:228) -[1/1] semaphore_post 0x........ value 0 -> 1 +[1/1] semaphore_post 0x........ value 4294967295 -> 0 FIXME: can't figure out how to verify wrap of sem_post -[1/1] semaphore_destroy 0x........ value 1 +[1/1] semaphore_destroy 0x........ value 0 ------------ dealloc of mem holding locks ------------ diff --git a/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.3-b b/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.3-b index 7fb1fe8e1d..06b5bb794b 100644 --- a/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.3-b +++ b/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.3-b @@ -148,11 +148,11 @@ Invalid semaphore: semaphore 0x........ semaphore 0x........ was first observed at: at 0x........: sem_init* (drd_pthread_intercepts.c:?) by 0x........: main (tc20_verifywrap.c:228) -[1/1] semaphore_post 0x........ value 0 -> 1 +[1/1] semaphore_post 0x........ value 4294967295 -> 0 FIXME: can't figure out how to verify wrap of sem_post -[1/1] semaphore_destroy 0x........ value 1 +[1/1] semaphore_destroy 0x........ value 0 ------------ dealloc of mem holding locks ------------ diff --git a/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.5 b/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.5 index aff9624e44..b94d930bc9 100644 --- a/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.5 +++ b/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.5 @@ -133,11 +133,11 @@ Invalid semaphore: semaphore 0x........ semaphore 0x........ was first observed at: at 0x........: sem_init* (drd_pthread_intercepts.c:?) by 0x........: main (tc20_verifywrap.c:228) -[1/1] semaphore_post 0x........ value 0 -> 1 +[1/1] semaphore_post 0x........ value 4294967295 -> 0 FIXME: can't figure out how to verify wrap of sem_post -[1/1] semaphore_destroy 0x........ value 1 +[1/1] semaphore_destroy 0x........ value 0 ------------ dealloc of mem holding locks ------------ diff --git a/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.5-ppc b/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.5-ppc index a7360fc1ad..69eade2418 100644 --- a/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.5-ppc +++ b/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.5-ppc @@ -133,11 +133,11 @@ Invalid semaphore: semaphore 0x........ semaphore 0x........ was first observed at: at 0x........: sem_init* (drd_pthread_intercepts.c:?) by 0x........: main (tc20_verifywrap.c:228) -[1/1] semaphore_post 0x........ value 0 -> 1 +[1/1] semaphore_post 0x........ value 4294967295 -> 0 FIXME: can't figure out how to verify wrap of sem_post -[1/1] semaphore_destroy 0x........ value 1 +[1/1] semaphore_destroy 0x........ value 0 ------------ dealloc of mem holding locks ------------ diff --git a/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.8 b/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.8 index 939ae4106f..c86fb1ad23 100644 --- a/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.8 +++ b/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.8 @@ -126,11 +126,11 @@ Invalid semaphore: semaphore 0x........ semaphore 0x........ was first observed at: at 0x........: sem_init* (drd_pthread_intercepts.c:?) by 0x........: main (tc20_verifywrap.c:228) -[1/1] semaphore_post 0x........ value 0 -> 1 +[1/1] semaphore_post 0x........ value 4294967295 -> 0 FIXME: can't figure out how to verify wrap of sem_post -[1/1] semaphore_destroy 0x........ value 1 +[1/1] semaphore_destroy 0x........ value 0 ------------ dealloc of mem holding locks ------------ diff --git a/glibc-2.X-drd.supp b/glibc-2.X-drd.supp index 30437f531e..7b171ace94 100644 --- a/glibc-2.X-drd.supp +++ b/glibc-2.X-drd.supp @@ -262,7 +262,6 @@ gomp drd:ConflictingAccess obj:/usr/lib*/libgomp.so* - obj:/usr/lib*/libgomp.so* } { libX11-XCreateFontSet