|
From: <sv...@va...> - 2013-03-24 20:10:36
|
philippe 2013-03-24 20:10:23 +0000 (Sun, 24 Mar 2013)
New Revision: 13332
Log:
fix 307082 HG false positive: pthread_cond_destroy: destruction of unknown cond var
Added files:
trunk/helgrind/tests/cond_init_destroy.c
trunk/helgrind/tests/cond_init_destroy.stderr.exp
trunk/helgrind/tests/cond_init_destroy.vgtest
Modified files:
trunk/NEWS
trunk/helgrind/helgrind.h
trunk/helgrind/hg_intercepts.c
trunk/helgrind/hg_main.c
trunk/helgrind/tests/Makefile.am
Modified: trunk/helgrind/hg_main.c (+23 -0)
===================================================================
--- trunk/helgrind/hg_main.c 2013-03-22 11:49:46 +00:00 (rev 13331)
+++ trunk/helgrind/hg_main.c 2013-03-24 20:10:23 +00:00 (rev 13332)
@@ -2377,6 +2377,22 @@
cvi->nWaiters--;
}
+static void evh__HG_PTHREAD_COND_INIT_POST ( ThreadId tid,
+ void* cond, void* cond_attr )
+{
+ CVInfo* cvi;
+
+ if (SHOW_EVENTS >= 1)
+ VG_(printf)("evh__HG_PTHREAD_COND_INIT_POST"
+ "(ctid=%d, cond=%p, cond_attr=%p)\n",
+ (Int)tid, (void*)cond, (void*) cond_attr );
+
+ cvi = map_cond_to_CVInfo_lookup_or_alloc( cond );
+ tl_assert (cvi);
+ tl_assert (cvi->so);
+}
+
+
static void evh__HG_PTHREAD_COND_DESTROY_PRE ( ThreadId tid,
void* cond )
{
@@ -4842,6 +4858,13 @@
break;
}
+ /* Thread successfully completed pthread_cond_init:
+ cond=arg[1], cond_attr=arg[2] */
+ case _VG_USERREQ__HG_PTHREAD_COND_INIT_POST:
+ evh__HG_PTHREAD_COND_INIT_POST( tid,
+ (void*)args[1], (void*)args[2] );
+ break;
+
/* cond=arg[1] */
case _VG_USERREQ__HG_PTHREAD_COND_DESTROY_PRE:
evh__HG_PTHREAD_COND_DESTROY_PRE( tid, (void*)args[1] );
Added: trunk/helgrind/tests/cond_init_destroy.c (+8 -0)
===================================================================
--- trunk/helgrind/tests/cond_init_destroy.c 2013-03-22 11:49:46 +00:00 (rev 13331)
+++ trunk/helgrind/tests/cond_init_destroy.c 2013-03-24 20:10:23 +00:00 (rev 13332)
@@ -0,0 +1,8 @@
+#include <pthread.h>
+int main(int argc, char *argv[])
+{
+ pthread_cond_t c;
+ pthread_cond_init(& c, NULL);
+ pthread_cond_destroy(& c);
+ return 0;
+}
Added: trunk/helgrind/tests/cond_init_destroy.stderr.exp (+3 -0)
===================================================================
--- trunk/helgrind/tests/cond_init_destroy.stderr.exp 2013-03-22 11:49:46 +00:00 (rev 13331)
+++ trunk/helgrind/tests/cond_init_destroy.stderr.exp 2013-03-24 20:10:23 +00:00 (rev 13332)
@@ -0,0 +1,3 @@
+
+
+ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
Modified: trunk/helgrind/hg_intercepts.c (+50 -3)
===================================================================
--- trunk/helgrind/hg_intercepts.c 2013-03-22 11:49:46 +00:00 (rev 13331)
+++ trunk/helgrind/hg_intercepts.c 2013-03-24 20:10:23 +00:00 (rev 13332)
@@ -631,10 +631,8 @@
/* Handled: pthread_cond_wait pthread_cond_timedwait
pthread_cond_signal pthread_cond_broadcast
+ pthread_cond_init
pthread_cond_destroy
-
- Unhandled: pthread_cond_init
- -- is this important?
*/
//-----------------------------------------------------------
@@ -917,7 +915,56 @@
# error "Unsupported OS"
#endif
+// glibc: pthread_cond_init@GLIBC_2.0
+// glibc: pthread_cond_init@GLIBC_2.2.5
+// glibc: pthread_cond_init@@GLIBC_2.3.2
+// darwin: pthread_cond_init
+// Easy way out: Handling of attr could have been messier.
+// It turns out that pthread_cond_init under linux ignores
+// all information in cond_attr, so do we.
+// FIXME: MacOS X?
+__attribute__((noinline))
+static int pthread_cond_init_WRK(pthread_cond_t* cond, pthread_condattr_t *cond_attr)
+{
+ int ret;
+ OrigFn fn;
+ VALGRIND_GET_ORIG_FN(fn);
+ if (TRACE_PTH_FNS) {
+ fprintf(stderr, "<< pthread_cond_init %p", cond);
+ fflush(stderr);
+ }
+
+ CALL_FN_W_WW(ret, fn, cond, cond_attr);
+
+ if (ret == 0) {
+ DO_CREQ_v_WW(_VG_USERREQ__HG_PTHREAD_COND_INIT_POST,
+ pthread_cond_t*,cond, pthread_condattr_t*, cond_attr);
+ } else {
+ DO_PthAPIerror( "pthread_cond_init", ret );
+ }
+
+ if (TRACE_PTH_FNS) {
+ fprintf(stderr, " coinit -> %d >>\n", ret);
+ }
+
+ return ret;
+}
+#if defined(VGO_linux)
+ PTH_FUNC(int, pthreadZucondZuinitZAZa, // pthread_cond_init@*
+ pthread_cond_t* cond, pthread_condattr_t* cond_attr) {
+ return pthread_cond_init_WRK(cond, cond_attr);
+ }
+#elif defined(VGO_darwin)
+ PTH_FUNC(int, pthreadZucondZuinit, // pthread_cond_init
+ pthread_cond_t* cond, pthread_condattr_t * cond_attr) {
+ return pthread_cond_init_WRK(cond, cond_attr);
+ }
+#else
+# error "Unsupported OS"
+#endif
+
+
//-----------------------------------------------------------
// glibc: pthread_cond_destroy@@GLIBC_2.3.2
// glibc: pthread_cond_destroy@GLIBC_2.2.5
Added: trunk/helgrind/tests/cond_init_destroy.vgtest (+1 -0)
===================================================================
--- trunk/helgrind/tests/cond_init_destroy.vgtest 2013-03-22 11:49:46 +00:00 (rev 13331)
+++ trunk/helgrind/tests/cond_init_destroy.vgtest 2013-03-24 20:10:23 +00:00 (rev 13332)
@@ -0,0 +1 @@
+prog: cond_init_destroy
Modified: trunk/helgrind/tests/Makefile.am (+2 -0)
===================================================================
--- trunk/helgrind/tests/Makefile.am 2013-03-22 11:49:46 +00:00 (rev 13331)
+++ trunk/helgrind/tests/Makefile.am 2013-03-24 20:10:23 +00:00 (rev 13332)
@@ -12,6 +12,7 @@
annotate_rwlock.stderr.exp \
annotate_smart_pointer.vgtest annotate_smart_pointer.stdout.exp \
annotate_smart_pointer.stderr.exp \
+ cond_init_destroy.vgtest cond_init_destroy.stderr.exp \
cond_timedwait_invalid.vgtest cond_timedwait_invalid.stdout.exp \
cond_timedwait_invalid.stderr.exp \
bar_bad.vgtest bar_bad.stdout.exp bar_bad.stderr.exp \
@@ -101,6 +102,7 @@
# should be conditionally compiled like tc20_verifywrap is.
check_PROGRAMS = \
annotate_hbefore \
+ cond_init_destroy \
cond_timedwait_invalid \
free_is_write \
hg01_all_ok \
Modified: trunk/helgrind/helgrind.h (+2 -1)
===================================================================
--- trunk/helgrind/helgrind.h 2013-03-22 11:49:46 +00:00 (rev 13331)
+++ trunk/helgrind/helgrind.h 2013-03-24 20:10:23 +00:00 (rev 13332)
@@ -115,7 +115,8 @@
_VG_USERREQ__HG_ARANGE_MAKE_UNTRACKED, /* Addr a, ulong len */
_VG_USERREQ__HG_ARANGE_MAKE_TRACKED, /* Addr a, ulong len */
_VG_USERREQ__HG_PTHREAD_BARRIER_RESIZE_PRE, /* pth_bar_t*, ulong */
- _VG_USERREQ__HG_CLEAN_MEMORY_HEAPBLOCK /* Addr start_of_block */
+ _VG_USERREQ__HG_CLEAN_MEMORY_HEAPBLOCK, /* Addr start_of_block */
+ _VG_USERREQ__HG_PTHREAD_COND_INIT_POST /* pth_cond_t*, pth_cond_attr_t*/
} Vg_TCheckClientRequest;
Modified: trunk/NEWS (+1 -0)
===================================================================
--- trunk/NEWS 2013-03-22 11:49:46 +00:00 (rev 13331)
+++ trunk/NEWS 2013-03-24 20:10:23 +00:00 (rev 13332)
@@ -95,6 +95,7 @@
307038 DWARF2 CFI reader: unhandled DW_OP_ opcode 0x8 (DW_OP_const1u et al)
FIXED r13010
+307082 [390] HG false positive: pthread_cond_destroy: destruction of unknown cond var
307101 sys_capget second argument can be NULL
FIXED r13021
|