Skip to content

Instantly share code, notes, and snippets.

@benesch
Created November 8, 2018 21:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benesch/cb3258a3eb4b573b5a3b7891db000e66 to your computer and use it in GitHub Desktop.
Save benesch/cb3258a3eb4b573b5a3b7891db000e66 to your computer and use it in GitHub Desktop.
diff --git a/lib/tsan/go/tsan_go.cc b/lib/tsan/go/tsan_go.cc
index 71a660683..ba0dd4a08 100644
--- a/lib/tsan/go/tsan_go.cc
+++ b/lib/tsan/go/tsan_go.cc
@@ -231,48 +231,84 @@ void __tsan_proc_destroy(Processor *proc) {
}
void __tsan_acquire(ThreadState *thr, void *addr) {
+ CHECK(!thr->proc()->inuse);
+ thr->proc()->inuse = true;
Acquire(thr, 0, (uptr)addr);
+ CHECK(thr->proc()->inuse);
+ thr->proc()->inuse = false;
}
void __tsan_release(ThreadState *thr, void *addr) {
+ CHECK(!thr->proc()->inuse);
+ thr->proc()->inuse = true;
ReleaseStore(thr, 0, (uptr)addr);
+ CHECK(thr->proc()->inuse);
+ thr->proc()->inuse = false;
}
void __tsan_release_merge(ThreadState *thr, void *addr) {
+ CHECK(!thr->proc()->inuse);
+ thr->proc()->inuse = true;
Release(thr, 0, (uptr)addr);
+ CHECK(thr->proc()->inuse);
+ thr->proc()->inuse = false;
}
void __tsan_finalizer_goroutine(ThreadState *thr) {
+ CHECK(!thr->proc()->inuse);
+ thr->proc()->inuse = true;
AcquireGlobal(thr, 0);
+ CHECK(thr->proc()->inuse);
+ thr->proc()->inuse = false;
}
void __tsan_mutex_before_lock(ThreadState *thr, uptr addr, uptr write) {
+ CHECK(!thr->proc()->inuse);
+ thr->proc()->inuse = true;
if (write)
MutexPreLock(thr, 0, addr);
else
MutexPreReadLock(thr, 0, addr);
+ CHECK(thr->proc()->inuse);
+ thr->proc()->inuse = false;
}
void __tsan_mutex_after_lock(ThreadState *thr, uptr addr, uptr write) {
+ CHECK(!thr->proc()->inuse);
+ thr->proc()->inuse = true;
if (write)
MutexPostLock(thr, 0, addr);
else
MutexPostReadLock(thr, 0, addr);
+ CHECK(thr->proc()->inuse);
+ thr->proc()->inuse = false;
}
void __tsan_mutex_before_unlock(ThreadState *thr, uptr addr, uptr write) {
+ CHECK(!thr->proc()->inuse);
+ thr->proc()->inuse = true;
if (write)
MutexUnlock(thr, 0, addr);
else
MutexReadUnlock(thr, 0, addr);
+ CHECK(thr->proc()->inuse);
+ thr->proc()->inuse = false;
}
void __tsan_go_ignore_sync_begin(ThreadState *thr) {
+ CHECK(!thr->proc()->inuse);
+ thr->proc()->inuse = true;
ThreadIgnoreSyncBegin(thr, 0);
+ CHECK(thr->proc()->inuse);
+ thr->proc()->inuse = false;
}
void __tsan_go_ignore_sync_end(ThreadState *thr) {
+ CHECK(!thr->proc()->inuse);
+ thr->proc()->inuse = true;
ThreadIgnoreSyncEnd(thr, 0);
+ CHECK(thr->proc()->inuse);
+ thr->proc()->inuse = false;
}
void __tsan_report_count(u64 *pn) {
diff --git a/lib/tsan/rtl/tsan_rtl.h b/lib/tsan/rtl/tsan_rtl.h
index 5e2a745c9..130b33609 100644
--- a/lib/tsan/rtl/tsan_rtl.h
+++ b/lib/tsan/rtl/tsan_rtl.h
@@ -356,6 +356,7 @@ struct Processor {
DenseSlabAllocCache sync_cache;
DenseSlabAllocCache clock_cache;
DDPhysicalThread *dd_pt;
+ bool inuse;
};
#if !SANITIZER_GO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment