[compiler-rt] r314039 - [sanitizer] Move ScopedErrorReportLock into libcdep version
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 22 15:36:11 PDT 2017
Author: vitalybuka
Date: Fri Sep 22 15:36:11 2017
New Revision: 314039
URL: http://llvm.org/viewvc/llvm-project?rev=314039&view=rev
Log:
[sanitizer] Move ScopedErrorReportLock into libcdep version
Modified:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc?rev=314039&r1=314038&r2=314039&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc Fri Sep 22 15:36:11 2017
@@ -348,43 +348,6 @@ static int InstallMallocFreeHooks(void (
return 0;
}
-static const u32 kUnclaimedTid = 0xfffffe;
-static atomic_uint32_t reporting_thread_tid = {kUnclaimedTid};
-
-ScopedErrorReportLock::ScopedErrorReportLock(u32 current_tid) {
- for (;;) {
- u32 expected_tid = kUnclaimedTid;
- if (current_tid == kUnclaimedTid ||
- atomic_compare_exchange_strong(&reporting_thread_tid, &expected_tid,
- current_tid, memory_order_relaxed)) {
- // We've claimed reporting_thread_tid_ so proceed.
- CommonSanitizerReportMutex.Lock();
- return;
- }
-
- if (expected_tid == current_tid) {
- // This is either asynch signal or nested error during error reporting.
- // Fail simple to avoid deadlocks in Report().
-
- // Can't use Report() here because of potential deadlocks in nested
- // signal handlers.
- CatastrophicErrorWrite(SanitizerToolName,
- internal_strlen(SanitizerToolName));
- static const char msg[] = ": nested bug in the same thread, aborting.\n";
- CatastrophicErrorWrite(msg, sizeof(msg) - 1);
-
- internal__exit(common_flags()->exitcode);
- }
-
- internal_sched_yield();
- }
-}
-
-ScopedErrorReportLock::~ScopedErrorReportLock() {
- CommonSanitizerReportMutex.Unlock();
- atomic_store_relaxed(&reporting_thread_tid, kUnclaimedTid);
-}
-
} // namespace __sanitizer
using namespace __sanitizer; // NOLINT
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc?rev=314039&r1=314038&r2=314039&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc Fri Sep 22 15:36:11 2017
@@ -286,6 +286,43 @@ void MaybeStartBackgroudThread() {
#endif
}
+static const u32 kUnclaimedTid = 0xfffffe;
+static atomic_uint32_t reporting_thread_tid = {kUnclaimedTid};
+
+ScopedErrorReportLock::ScopedErrorReportLock(u32 current_tid) {
+ for (;;) {
+ u32 expected_tid = kUnclaimedTid;
+ if (current_tid == kUnclaimedTid ||
+ atomic_compare_exchange_strong(&reporting_thread_tid, &expected_tid,
+ current_tid, memory_order_relaxed)) {
+ // We've claimed reporting_thread_tid_ so proceed.
+ CommonSanitizerReportMutex.Lock();
+ return;
+ }
+
+ if (expected_tid == current_tid) {
+ // This is either asynch signal or nested error during error reporting.
+ // Fail simple to avoid deadlocks in Report().
+
+ // Can't use Report() here because of potential deadlocks in nested
+ // signal handlers.
+ CatastrophicErrorWrite(SanitizerToolName,
+ internal_strlen(SanitizerToolName));
+ static const char msg[] = ": nested bug in the same thread, aborting.\n";
+ CatastrophicErrorWrite(msg, sizeof(msg) - 1);
+
+ internal__exit(common_flags()->exitcode);
+ }
+
+ internal_sched_yield();
+ }
+}
+
+ScopedErrorReportLock::~ScopedErrorReportLock() {
+ CommonSanitizerReportMutex.Unlock();
+ atomic_store_relaxed(&reporting_thread_tid, kUnclaimedTid);
+}
+
} // namespace __sanitizer
SANITIZER_INTERFACE_WEAK_DEF(void, __sanitizer_sandbox_on_notify,
More information about the llvm-commits
mailing list