diff --git a/helgrind/hg_errors.c b/helgrind/hg_errors.c index 6bc9482cc..6076f475d 100644 --- a/helgrind/hg_errors.c +++ b/helgrind/hg_errors.c @@ -341,7 +341,7 @@ UInt HG_(update_extra) ( Error* err ) Thread* threadp; tl_assert(wherep); tl_assert(thrp); - threadp = libhb_get_Thr_opaque( thrp ); + threadp = libhb_get_Thr_hgthread( thrp ); tl_assert(threadp); xe->XE.Race.h2_ct_accEC = wherep; xe->XE.Race.h2_ct = threadp; diff --git a/helgrind/hg_lock_n_thread.h b/helgrind/hg_lock_n_thread.h index 78948fe11..e109b551e 100644 --- a/helgrind/hg_lock_n_thread.h +++ b/helgrind/hg_lock_n_thread.h @@ -83,8 +83,8 @@ typedef /* ADMIN */ struct _Thread* admin; UInt magic; - Thr* hbthr; - ThreadId coretid; + Thr* hbthr; /* which in turn points back here .. */ + ThreadId coretid; /* .. via its hgthread field */ /* USEFUL */ WordSetID locksetA; /* WordSet of Lock* currently held by thread */ WordSetID locksetW; /* subset of locksetA held in w-mode */ diff --git a/helgrind/hg_main.c b/helgrind/hg_main.c index e2e4a981c..1b17f6f9e 100644 --- a/helgrind/hg_main.c +++ b/helgrind/hg_main.c @@ -590,8 +590,8 @@ static void initialise_data_structures ( Thr* hbthr_root ) thr = mk_Thread(hbthr_root); thr->coretid = 1; /* FIXME: hardwires an assumption about the identity of the root thread. */ - tl_assert( libhb_get_Thr_opaque(hbthr_root) == NULL ); - libhb_set_Thr_opaque(hbthr_root, thr); + tl_assert( libhb_get_Thr_hgthread(hbthr_root) == NULL ); + libhb_set_Thr_hgthread(hbthr_root, thr); /* and bind it in the thread-map table. */ tl_assert(HG_(is_sane_ThreadId)(thr->coretid)); @@ -1620,15 +1620,15 @@ void evh__pre_thread_ll_create ( ThreadId parent, ThreadId child ) hbthr_p = thr_p->hbthr; tl_assert(hbthr_p != NULL); - tl_assert( libhb_get_Thr_opaque(hbthr_p) == thr_p ); + tl_assert( libhb_get_Thr_hgthread(hbthr_p) == thr_p ); hbthr_c = libhb_create ( hbthr_p ); /* Create a new thread record for the child. */ /* a Thread for the new thread ... */ thr_c = mk_Thread( hbthr_c ); - tl_assert( libhb_get_Thr_opaque(hbthr_c) == NULL ); - libhb_set_Thr_opaque(hbthr_c, thr_c); + tl_assert( libhb_get_Thr_hgthread(hbthr_c) == NULL ); + libhb_set_Thr_hgthread(hbthr_c, thr_c); /* and bind it in the thread-map table */ map_threads[child] = thr_c; @@ -1765,8 +1765,8 @@ void evh__HG_PTHREAD_JOIN_POST ( ThreadId stay_tid, Thread* quit_thr ) hbthr_s = thr_s->hbthr; hbthr_q = thr_q->hbthr; tl_assert(hbthr_s != hbthr_q); - tl_assert( libhb_get_Thr_opaque(hbthr_s) == thr_s ); - tl_assert( libhb_get_Thr_opaque(hbthr_q) == thr_q ); + tl_assert( libhb_get_Thr_hgthread(hbthr_s) == thr_s ); + tl_assert( libhb_get_Thr_hgthread(hbthr_q) == thr_q ); /* Allocate a temporary synchronisation object and use it to send an imaginary message from the quitter to the stayer, the purpose @@ -4838,7 +4838,7 @@ void for_libhb__get_stacktrace ( Thr* hbt, Addr* frames, UWord nRequest ) ThreadId tid; UWord nActual; tl_assert(hbt); - thr = libhb_get_Thr_opaque( hbt ); + thr = libhb_get_Thr_hgthread( hbt ); tl_assert(thr); tid = map_threads_maybe_reverse_lookup_SLOW(thr); nActual = (UWord)VG_(get_StackTrace)( tid, frames, (UInt)nRequest, @@ -4855,7 +4855,7 @@ ExeContext* for_libhb__get_EC ( Thr* hbt ) ThreadId tid; ExeContext* ec; tl_assert(hbt); - thr = libhb_get_Thr_opaque( hbt ); + thr = libhb_get_Thr_hgthread( hbt ); tl_assert(thr); tid = map_threads_maybe_reverse_lookup_SLOW(thr); /* this will assert if tid is invalid */ diff --git a/helgrind/libhb.h b/helgrind/libhb.h index 8d88de639..39711b52e 100644 --- a/helgrind/libhb.h +++ b/helgrind/libhb.h @@ -129,10 +129,10 @@ void libhb_srange_new ( Thr*, Addr, SizeT ); void libhb_srange_noaccess ( Thr*, Addr, SizeT ); /* IS IGNORED */ void libhb_srange_untrack ( Thr*, Addr, SizeT ); -/* For the convenience of callers, we offer to store one void* item in - a Thr, which we ignore, but the caller can get or set any time. */ -void* libhb_get_Thr_opaque ( Thr* ); -void libhb_set_Thr_opaque ( Thr*, void* ); +/* Get and set the hgthread (pointer to corresponding Thread + structure). */ +void* libhb_get_Thr_hgthread ( Thr* ); +void libhb_set_Thr_hgthread ( Thr*, void* ); /* Low level copy of shadow state from [src,src+len) to [dst,dst+len). Overlapping moves are checked for and asserted against. */ diff --git a/helgrind/libhb_core.c b/helgrind/libhb_core.c index 2e878ebf4..05fda56a3 100644 --- a/helgrind/libhb_core.c +++ b/helgrind/libhb_core.c @@ -3060,8 +3060,11 @@ struct _Thr { race. */ Filter* filter; - /* opaque (to us) data we hold on behalf of the library's user. */ - void* opaque; + /* A pointer back to the top level Thread structure. There is a + 1-1 mapping between Thread and Thr structures -- each Thr points + at its corresponding Thread, and vice versa. Really, Thr and + Thread should be merged into a single structure. */ + Thread* hgthread; /* The ULongs (scalar Kws) in this accumulate in strictly increasing order, without duplicates. This is important because @@ -4359,7 +4362,8 @@ static void record_race_info ( Thr* acc_thr, Thread* hist1_conf_thr = NULL; tl_assert(acc_thr); - tl_assert(acc_thr->opaque); + tl_assert(acc_thr->hgthread); + tl_assert(acc_thr->hgthread->hbthr == acc_thr); tl_assert(HG_(clo_history_level) >= 0 && HG_(clo_history_level) <= 2); if (HG_(clo_history_level) == 1) { @@ -4443,11 +4447,11 @@ static void record_race_info ( Thr* acc_thr, // seg_start could be NULL iff this is the first stack in the thread //if (seg_start) VG_(pp_ExeContext)(seg_start); //if (seg_end) VG_(pp_ExeContext)(seg_end); - hist1_conf_thr = confThr->opaque; + hist1_conf_thr = confThr->hgthread; } } - HG_(record_error_Race)( acc_thr->opaque, acc_addr, + HG_(record_error_Race)( acc_thr->hgthread, acc_addr, szB, isWrite, hist1_conf_thr, hist1_seg_start, hist1_seg_end ); } @@ -5976,14 +5980,14 @@ void libhb_srange_untrack ( Thr* thr, Addr a, SizeT szB ) if (0 && TRACEME(a,szB)) trace(thr,a,szB,"untrack-after "); } -void* libhb_get_Thr_opaque ( Thr* thr ) { +void* libhb_get_Thr_hgthread ( Thr* thr ) { tl_assert(thr); - return thr->opaque; + return thr->hgthread; } -void libhb_set_Thr_opaque ( Thr* thr, void* v ) { +void libhb_set_Thr_hgthread ( Thr* thr, void* v ) { tl_assert(thr); - thr->opaque = v; + thr->hgthread = v; } void libhb_copy_shadow_state ( Thr* thr, Addr src, Addr dst, SizeT len )