2013-05-18 00:17:19 +08:00
|
|
|
//===-- sanitizer_common_libcdep.cc ---------------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file is shared between AddressSanitizer and ThreadSanitizer
|
|
|
|
// run-time libraries.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "sanitizer_common.h"
|
2015-11-21 02:42:01 +08:00
|
|
|
|
2016-09-15 06:00:58 +08:00
|
|
|
#include "sanitizer_allocator_interface.h"
|
2017-07-22 09:46:40 +08:00
|
|
|
#include "sanitizer_file.h"
|
2014-02-26 17:06:59 +08:00
|
|
|
#include "sanitizer_flags.h"
|
2017-09-13 14:24:59 +08:00
|
|
|
#include "sanitizer_procmaps.h"
|
|
|
|
#include "sanitizer_report_decorator.h"
|
2014-12-17 03:13:01 +08:00
|
|
|
#include "sanitizer_stackdepot.h"
|
2014-09-11 06:45:09 +08:00
|
|
|
#include "sanitizer_stacktrace.h"
|
|
|
|
#include "sanitizer_symbolizer.h"
|
2013-05-18 00:17:19 +08:00
|
|
|
|
2015-04-09 01:08:24 +08:00
|
|
|
#if SANITIZER_POSIX
|
|
|
|
#include "sanitizer_posix.h"
|
|
|
|
#endif
|
|
|
|
|
2013-05-18 00:17:19 +08:00
|
|
|
namespace __sanitizer {
|
|
|
|
|
2017-08-02 05:28:39 +08:00
|
|
|
#if !SANITIZER_FUCHSIA
|
|
|
|
|
2015-04-09 01:42:57 +08:00
|
|
|
bool ReportFile::SupportsColors() {
|
2014-12-12 02:30:25 +08:00
|
|
|
SpinMutexLock l(mu);
|
|
|
|
ReopenIfNecessary();
|
2015-04-09 01:42:57 +08:00
|
|
|
return SupportsColoredOutput(fd);
|
2013-05-18 00:17:19 +08:00
|
|
|
}
|
|
|
|
|
2017-08-02 05:28:39 +08:00
|
|
|
static INLINE bool ReportSupportsColors() {
|
|
|
|
return report_file.SupportsColors();
|
|
|
|
}
|
|
|
|
|
|
|
|
#else // SANITIZER_FUCHSIA
|
|
|
|
|
|
|
|
// Fuchsia's logs always go through post-processing that handles colorization.
|
|
|
|
static INLINE bool ReportSupportsColors() { return true; }
|
|
|
|
|
|
|
|
#endif // !SANITIZER_FUCHSIA
|
|
|
|
|
2014-12-12 02:30:25 +08:00
|
|
|
bool ColorizeReports() {
|
2013-09-03 21:31:03 +08:00
|
|
|
// FIXME: Add proper Windows support to AnsiColorDecorator and re-enable color
|
|
|
|
// printing on Windows.
|
|
|
|
if (SANITIZER_WINDOWS)
|
2014-12-12 02:30:25 +08:00
|
|
|
return false;
|
2014-02-26 17:06:59 +08:00
|
|
|
|
|
|
|
const char *flag = common_flags()->color;
|
|
|
|
return internal_strcmp(flag, "always") == 0 ||
|
2017-08-02 05:28:39 +08:00
|
|
|
(internal_strcmp(flag, "auto") == 0 && ReportSupportsColors());
|
2014-02-26 17:06:59 +08:00
|
|
|
}
|
2014-05-27 20:37:52 +08:00
|
|
|
|
|
|
|
static void (*sandboxing_callback)();
|
|
|
|
void SetSandboxingCallback(void (*f)()) {
|
|
|
|
sandboxing_callback = f;
|
|
|
|
}
|
|
|
|
|
2017-04-15 02:24:35 +08:00
|
|
|
void ReportErrorSummary(const char *error_type, const StackTrace *stack,
|
|
|
|
const char *alt_tool_name) {
|
Reapply: [asan] On OS X, log reports to syslog and os_trace
When ASan currently detects a bug, by default it will only print out the text
of the report to stderr. This patch changes this behavior and writes the full
text of the report to syslog before we terminate the process. It also calls
os_trace (Activity Tracing available on OS X and iOS) with a message saying
that the report is available in syslog. This is useful, because this message
will be shown in the crash log.
For this to work, the patch makes sure we store the full report into
error_message_buffer unconditionally, and it also strips out ANSI escape
sequences from the report (they are used when producing colored reports).
I've initially tried to log to syslog during printing, which is done on Android
right now. The advantage is that if we crash during error reporting or the
produced error does not go through ScopedInErrorReport, we would still get a
(partial) message in the syslog. However, that solution is very problematic on
OS X. One issue is that the logging routine uses GCD, which may spawn a new
thread on its behalf. In many cases, the reporting logic locks threadRegistry,
which leads to deadlocks.
Reviewed at http://reviews.llvm.org/D13452
(In addition, add sanitizer_common_libcdep.cc to buildgo.sh to avoid
build failures on Linux.)
llvm-svn: 253688
2015-11-21 02:41:44 +08:00
|
|
|
#if !SANITIZER_GO
|
2014-09-11 06:45:09 +08:00
|
|
|
if (!common_flags()->print_summary)
|
|
|
|
return;
|
2015-03-18 07:46:06 +08:00
|
|
|
if (stack->size == 0) {
|
|
|
|
ReportErrorSummary(error_type);
|
2015-02-27 10:29:25 +08:00
|
|
|
return;
|
2015-03-18 07:46:06 +08:00
|
|
|
}
|
2015-02-27 10:29:25 +08:00
|
|
|
// Currently, we include the first stack frame into the report summary.
|
|
|
|
// Maybe sometimes we need to choose another frame (e.g. skip memcpy/etc).
|
|
|
|
uptr pc = StackTrace::GetPreviousInstructionPc(stack->trace[0]);
|
|
|
|
SymbolizedStack *frame = Symbolizer::GetOrInit()->SymbolizePC(pc);
|
2017-04-15 02:24:35 +08:00
|
|
|
ReportErrorSummary(error_type, frame->info, alt_tool_name);
|
2015-02-27 10:29:25 +08:00
|
|
|
frame->ClearAll();
|
Reapply: [asan] On OS X, log reports to syslog and os_trace
When ASan currently detects a bug, by default it will only print out the text
of the report to stderr. This patch changes this behavior and writes the full
text of the report to syslog before we terminate the process. It also calls
os_trace (Activity Tracing available on OS X and iOS) with a message saying
that the report is available in syslog. This is useful, because this message
will be shown in the crash log.
For this to work, the patch makes sure we store the full report into
error_message_buffer unconditionally, and it also strips out ANSI escape
sequences from the report (they are used when producing colored reports).
I've initially tried to log to syslog during printing, which is done on Android
right now. The advantage is that if we crash during error reporting or the
produced error does not go through ScopedInErrorReport, we would still get a
(partial) message in the syslog. However, that solution is very problematic on
OS X. One issue is that the logging routine uses GCD, which may spawn a new
thread on its behalf. In many cases, the reporting logic locks threadRegistry,
which leads to deadlocks.
Reviewed at http://reviews.llvm.org/D13452
(In addition, add sanitizer_common_libcdep.cc to buildgo.sh to avoid
build failures on Linux.)
llvm-svn: 253688
2015-11-21 02:41:44 +08:00
|
|
|
#endif
|
2014-09-11 06:45:09 +08:00
|
|
|
}
|
|
|
|
|
2015-01-07 07:53:32 +08:00
|
|
|
static void (*SoftRssLimitExceededCallback)(bool exceeded);
|
|
|
|
void SetSoftRssLimitExceededCallback(void (*Callback)(bool exceeded)) {
|
|
|
|
CHECK_EQ(SoftRssLimitExceededCallback, nullptr);
|
|
|
|
SoftRssLimitExceededCallback = Callback;
|
|
|
|
}
|
|
|
|
|
2016-10-28 22:16:13 +08:00
|
|
|
#if SANITIZER_LINUX && !SANITIZER_GO
|
2014-12-17 03:13:01 +08:00
|
|
|
void BackgroundThread(void *arg) {
|
|
|
|
uptr hard_rss_limit_mb = common_flags()->hard_rss_limit_mb;
|
2015-01-07 07:53:32 +08:00
|
|
|
uptr soft_rss_limit_mb = common_flags()->soft_rss_limit_mb;
|
2016-09-15 06:00:58 +08:00
|
|
|
bool heap_profile = common_flags()->heap_profile;
|
2014-12-17 03:13:01 +08:00
|
|
|
uptr prev_reported_rss = 0;
|
|
|
|
uptr prev_reported_stack_depot_size = 0;
|
2015-01-07 07:53:32 +08:00
|
|
|
bool reached_soft_rss_limit = false;
|
2016-09-15 06:00:58 +08:00
|
|
|
uptr rss_during_last_reported_profile = 0;
|
2014-12-17 03:13:01 +08:00
|
|
|
while (true) {
|
|
|
|
SleepForMillis(100);
|
|
|
|
uptr current_rss_mb = GetRSS() >> 20;
|
2015-01-20 21:21:20 +08:00
|
|
|
if (Verbosity()) {
|
2014-12-17 03:13:01 +08:00
|
|
|
// If RSS has grown 10% since last time, print some information.
|
|
|
|
if (prev_reported_rss * 11 / 10 < current_rss_mb) {
|
|
|
|
Printf("%s: RSS: %zdMb\n", SanitizerToolName, current_rss_mb);
|
|
|
|
prev_reported_rss = current_rss_mb;
|
|
|
|
}
|
|
|
|
// If stack depot has grown 10% since last time, print it too.
|
|
|
|
StackDepotStats *stack_depot_stats = StackDepotGetStats();
|
|
|
|
if (prev_reported_stack_depot_size * 11 / 10 <
|
|
|
|
stack_depot_stats->allocated) {
|
|
|
|
Printf("%s: StackDepot: %zd ids; %zdM allocated\n",
|
|
|
|
SanitizerToolName,
|
|
|
|
stack_depot_stats->n_uniq_ids,
|
|
|
|
stack_depot_stats->allocated >> 20);
|
|
|
|
prev_reported_stack_depot_size = stack_depot_stats->allocated;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Check RSS against the limit.
|
|
|
|
if (hard_rss_limit_mb && hard_rss_limit_mb < current_rss_mb) {
|
|
|
|
Report("%s: hard rss limit exhausted (%zdMb vs %zdMb)\n",
|
|
|
|
SanitizerToolName, hard_rss_limit_mb, current_rss_mb);
|
|
|
|
DumpProcessMap();
|
|
|
|
Die();
|
|
|
|
}
|
2015-01-07 07:53:32 +08:00
|
|
|
if (soft_rss_limit_mb) {
|
|
|
|
if (soft_rss_limit_mb < current_rss_mb && !reached_soft_rss_limit) {
|
|
|
|
reached_soft_rss_limit = true;
|
|
|
|
Report("%s: soft rss limit exhausted (%zdMb vs %zdMb)\n",
|
|
|
|
SanitizerToolName, soft_rss_limit_mb, current_rss_mb);
|
|
|
|
if (SoftRssLimitExceededCallback)
|
|
|
|
SoftRssLimitExceededCallback(true);
|
|
|
|
} else if (soft_rss_limit_mb >= current_rss_mb &&
|
|
|
|
reached_soft_rss_limit) {
|
|
|
|
reached_soft_rss_limit = false;
|
|
|
|
if (SoftRssLimitExceededCallback)
|
|
|
|
SoftRssLimitExceededCallback(false);
|
|
|
|
}
|
|
|
|
}
|
2016-09-15 10:11:07 +08:00
|
|
|
if (heap_profile &&
|
2016-09-15 06:00:58 +08:00
|
|
|
current_rss_mb > rss_during_last_reported_profile * 1.1) {
|
|
|
|
Printf("\n\nHEAP PROFILE at RSS %zdMb\n", current_rss_mb);
|
2017-03-16 07:27:14 +08:00
|
|
|
__sanitizer_print_memory_profile(90, 20);
|
2016-09-15 06:00:58 +08:00
|
|
|
rss_during_last_reported_profile = current_rss_mb;
|
|
|
|
}
|
2014-12-17 03:13:01 +08:00
|
|
|
}
|
|
|
|
}
|
2016-10-28 22:16:13 +08:00
|
|
|
#endif
|
2014-12-17 03:13:01 +08:00
|
|
|
|
2017-09-20 01:00:22 +08:00
|
|
|
#if !SANITIZER_FUCHSIA && !SANITIZER_GO
|
2017-09-18 15:36:32 +08:00
|
|
|
void StartReportDeadlySignal() {
|
|
|
|
// Write the first message using fd=2, just in case.
|
|
|
|
// It may actually fail to write in case stderr is closed.
|
|
|
|
CatastrophicErrorWrite(SanitizerToolName, internal_strlen(SanitizerToolName));
|
|
|
|
static const char kDeadlySignal[] = ":DEADLYSIGNAL\n";
|
|
|
|
CatastrophicErrorWrite(kDeadlySignal, sizeof(kDeadlySignal) - 1);
|
|
|
|
}
|
|
|
|
|
2017-09-15 06:44:03 +08:00
|
|
|
static void MaybeReportNonExecRegion(uptr pc) {
|
2017-09-13 14:24:59 +08:00
|
|
|
#if SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD
|
|
|
|
MemoryMappingLayout proc_maps(/*cache_enabled*/ true);
|
|
|
|
MemoryMappedSegment segment;
|
|
|
|
while (proc_maps.Next(&segment)) {
|
|
|
|
if (pc >= segment.start && pc < segment.end && !segment.IsExecutable())
|
|
|
|
Report("Hint: PC is at a non-executable region. Maybe a wild jump?\n");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PrintMemoryByte(InternalScopedString *str, const char *before,
|
|
|
|
u8 byte) {
|
|
|
|
SanitizerCommonDecorator d;
|
|
|
|
str->append("%s%s%x%x%s ", before, d.MemoryByte(), byte >> 4, byte & 15,
|
|
|
|
d.Default());
|
|
|
|
}
|
|
|
|
|
2017-09-15 06:44:03 +08:00
|
|
|
static void MaybeDumpInstructionBytes(uptr pc) {
|
2017-09-13 14:24:59 +08:00
|
|
|
if (!common_flags()->dump_instruction_bytes || (pc < GetPageSizeCached()))
|
|
|
|
return;
|
|
|
|
InternalScopedString str(1024);
|
|
|
|
str.append("First 16 instruction bytes at pc: ");
|
|
|
|
if (IsAccessibleMemoryRange(pc, 16)) {
|
|
|
|
for (int i = 0; i < 16; ++i) {
|
|
|
|
PrintMemoryByte(&str, "", ((u8 *)pc)[i]);
|
|
|
|
}
|
|
|
|
str.append("\n");
|
|
|
|
} else {
|
|
|
|
str.append("unaccessible\n");
|
|
|
|
}
|
|
|
|
Report("%s", str.data());
|
|
|
|
}
|
|
|
|
|
2017-09-15 06:44:03 +08:00
|
|
|
static void MaybeDumpRegisters(void *context) {
|
2017-09-13 14:24:59 +08:00
|
|
|
if (!common_flags()->dump_registers) return;
|
|
|
|
SignalContext::DumpAllRegisters(context);
|
|
|
|
}
|
2017-09-15 06:44:03 +08:00
|
|
|
|
|
|
|
static void ReportStackOverflowImpl(const SignalContext &sig, u32 tid,
|
|
|
|
UnwindSignalStackCallbackType unwind,
|
|
|
|
const void *unwind_context) {
|
|
|
|
SanitizerCommonDecorator d;
|
|
|
|
Printf("%s", d.Warning());
|
|
|
|
static const char kDescription[] = "stack-overflow";
|
|
|
|
Report("ERROR: %s: %s on address %p (pc %p bp %p sp %p T%d)\n",
|
|
|
|
SanitizerToolName, kDescription, (void *)sig.addr, (void *)sig.pc,
|
|
|
|
(void *)sig.bp, (void *)sig.sp, tid);
|
|
|
|
Printf("%s", d.Default());
|
|
|
|
InternalScopedBuffer<BufferedStackTrace> stack_buffer(1);
|
|
|
|
BufferedStackTrace *stack = stack_buffer.data();
|
|
|
|
stack->Reset();
|
|
|
|
unwind(sig, unwind_context, stack);
|
|
|
|
stack->Print();
|
|
|
|
ReportErrorSummary(kDescription, stack);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ReportDeadlySignalImpl(const SignalContext &sig, u32 tid,
|
|
|
|
UnwindSignalStackCallbackType unwind,
|
|
|
|
const void *unwind_context) {
|
|
|
|
SanitizerCommonDecorator d;
|
|
|
|
Printf("%s", d.Warning());
|
|
|
|
const char *description = sig.Describe();
|
|
|
|
Report("ERROR: %s: %s on unknown address %p (pc %p bp %p sp %p T%d)\n",
|
|
|
|
SanitizerToolName, description, (void *)sig.addr, (void *)sig.pc,
|
|
|
|
(void *)sig.bp, (void *)sig.sp, tid);
|
|
|
|
Printf("%s", d.Default());
|
|
|
|
if (sig.pc < GetPageSizeCached())
|
|
|
|
Report("Hint: pc points to the zero page.\n");
|
|
|
|
if (sig.is_memory_access) {
|
|
|
|
const char *access_type =
|
|
|
|
sig.write_flag == SignalContext::WRITE
|
|
|
|
? "WRITE"
|
|
|
|
: (sig.write_flag == SignalContext::READ ? "READ" : "UNKNOWN");
|
|
|
|
Report("The signal is caused by a %s memory access.\n", access_type);
|
|
|
|
if (sig.addr < GetPageSizeCached())
|
|
|
|
Report("Hint: address points to the zero page.\n");
|
|
|
|
}
|
|
|
|
MaybeReportNonExecRegion(sig.pc);
|
|
|
|
InternalScopedBuffer<BufferedStackTrace> stack_buffer(1);
|
|
|
|
BufferedStackTrace *stack = stack_buffer.data();
|
|
|
|
stack->Reset();
|
|
|
|
unwind(sig, unwind_context, stack);
|
|
|
|
stack->Print();
|
|
|
|
MaybeDumpInstructionBytes(sig.pc);
|
|
|
|
MaybeDumpRegisters(sig.context);
|
|
|
|
Printf("%s can not provide additional info.\n", SanitizerToolName);
|
|
|
|
ReportErrorSummary(description, stack);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ReportDeadlySignal(const SignalContext &sig, u32 tid,
|
|
|
|
UnwindSignalStackCallbackType unwind,
|
|
|
|
const void *unwind_context) {
|
|
|
|
if (sig.IsStackOverflow())
|
|
|
|
ReportStackOverflowImpl(sig, tid, unwind, unwind_context);
|
|
|
|
else
|
|
|
|
ReportDeadlySignalImpl(sig, tid, unwind, unwind_context);
|
|
|
|
}
|
2017-09-23 06:57:48 +08:00
|
|
|
|
|
|
|
void HandleDeadlySignal(void *siginfo, void *context, u32 tid,
|
|
|
|
UnwindSignalStackCallbackType unwind,
|
|
|
|
const void *unwind_context) {
|
|
|
|
StartReportDeadlySignal();
|
|
|
|
ScopedErrorReportLock rl;
|
|
|
|
SignalContext sig(siginfo, context);
|
|
|
|
ReportDeadlySignal(sig, tid, unwind, unwind_context);
|
|
|
|
Report("ABORTING\n");
|
|
|
|
Die();
|
|
|
|
}
|
|
|
|
|
2017-09-20 01:00:22 +08:00
|
|
|
#endif // !SANITIZER_FUCHSIA && !SANITIZER_GO
|
2017-09-13 14:24:59 +08:00
|
|
|
|
2015-11-21 02:42:01 +08:00
|
|
|
void WriteToSyslog(const char *msg) {
|
|
|
|
InternalScopedString msg_copy(kErrorMessageBufferSize);
|
|
|
|
msg_copy.append("%s", msg);
|
|
|
|
char *p = msg_copy.data();
|
Reapply: [asan] On OS X, log reports to syslog and os_trace
When ASan currently detects a bug, by default it will only print out the text
of the report to stderr. This patch changes this behavior and writes the full
text of the report to syslog before we terminate the process. It also calls
os_trace (Activity Tracing available on OS X and iOS) with a message saying
that the report is available in syslog. This is useful, because this message
will be shown in the crash log.
For this to work, the patch makes sure we store the full report into
error_message_buffer unconditionally, and it also strips out ANSI escape
sequences from the report (they are used when producing colored reports).
I've initially tried to log to syslog during printing, which is done on Android
right now. The advantage is that if we crash during error reporting or the
produced error does not go through ScopedInErrorReport, we would still get a
(partial) message in the syslog. However, that solution is very problematic on
OS X. One issue is that the logging routine uses GCD, which may spawn a new
thread on its behalf. In many cases, the reporting logic locks threadRegistry,
which leads to deadlocks.
Reviewed at http://reviews.llvm.org/D13452
(In addition, add sanitizer_common_libcdep.cc to buildgo.sh to avoid
build failures on Linux.)
llvm-svn: 253688
2015-11-21 02:41:44 +08:00
|
|
|
char *q;
|
|
|
|
|
|
|
|
// Print one line at a time.
|
|
|
|
// syslog, at least on Android, has an implicit message length limit.
|
|
|
|
do {
|
|
|
|
q = internal_strchr(p, '\n');
|
|
|
|
if (q)
|
|
|
|
*q = '\0';
|
|
|
|
WriteOneLineToSyslog(p);
|
|
|
|
if (q)
|
|
|
|
p = q + 1;
|
|
|
|
} while (q);
|
|
|
|
}
|
|
|
|
|
2014-12-17 03:13:01 +08:00
|
|
|
void MaybeStartBackgroudThread() {
|
Reapply: [asan] On OS X, log reports to syslog and os_trace
When ASan currently detects a bug, by default it will only print out the text
of the report to stderr. This patch changes this behavior and writes the full
text of the report to syslog before we terminate the process. It also calls
os_trace (Activity Tracing available on OS X and iOS) with a message saying
that the report is available in syslog. This is useful, because this message
will be shown in the crash log.
For this to work, the patch makes sure we store the full report into
error_message_buffer unconditionally, and it also strips out ANSI escape
sequences from the report (they are used when producing colored reports).
I've initially tried to log to syslog during printing, which is done on Android
right now. The advantage is that if we crash during error reporting or the
produced error does not go through ScopedInErrorReport, we would still get a
(partial) message in the syslog. However, that solution is very problematic on
OS X. One issue is that the logging routine uses GCD, which may spawn a new
thread on its behalf. In many cases, the reporting logic locks threadRegistry,
which leads to deadlocks.
Reviewed at http://reviews.llvm.org/D13452
(In addition, add sanitizer_common_libcdep.cc to buildgo.sh to avoid
build failures on Linux.)
llvm-svn: 253688
2015-11-21 02:41:44 +08:00
|
|
|
#if SANITIZER_LINUX && \
|
|
|
|
!SANITIZER_GO // Need to implement/test on other platforms.
|
2015-01-07 07:53:32 +08:00
|
|
|
// Start the background thread if one of the rss limits is given.
|
|
|
|
if (!common_flags()->hard_rss_limit_mb &&
|
2016-08-27 07:58:42 +08:00
|
|
|
!common_flags()->soft_rss_limit_mb &&
|
2016-09-15 06:00:58 +08:00
|
|
|
!common_flags()->heap_profile) return;
|
2015-02-18 05:57:42 +08:00
|
|
|
if (!&real_pthread_create) return; // Can't spawn the thread anyway.
|
2014-12-17 03:13:01 +08:00
|
|
|
internal_start_thread(BackgroundThread, nullptr);
|
2015-04-02 22:48:08 +08:00
|
|
|
#endif
|
2014-12-17 03:13:01 +08:00
|
|
|
}
|
|
|
|
|
2017-09-23 06:36:21 +08:00
|
|
|
static atomic_uintptr_t reporting_thread = {0};
|
2017-11-10 10:07:11 +08:00
|
|
|
static StaticSpinMutex CommonSanitizerReportMutex;
|
2017-09-23 06:36:11 +08:00
|
|
|
|
2017-09-23 06:36:21 +08:00
|
|
|
ScopedErrorReportLock::ScopedErrorReportLock() {
|
|
|
|
uptr current = GetThreadSelf();
|
2017-09-23 06:36:11 +08:00
|
|
|
for (;;) {
|
2017-09-23 06:36:21 +08:00
|
|
|
uptr expected = 0;
|
|
|
|
if (atomic_compare_exchange_strong(&reporting_thread, &expected, current,
|
|
|
|
memory_order_relaxed)) {
|
|
|
|
// We've claimed reporting_thread so proceed.
|
2017-09-23 06:36:11 +08:00
|
|
|
CommonSanitizerReportMutex.Lock();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-23 06:36:21 +08:00
|
|
|
if (expected == current) {
|
2017-09-23 06:36:11 +08:00
|
|
|
// 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();
|
2017-09-23 06:36:21 +08:00
|
|
|
atomic_store_relaxed(&reporting_thread, 0);
|
2017-09-23 06:36:11 +08:00
|
|
|
}
|
|
|
|
|
2017-09-23 10:47:21 +08:00
|
|
|
void ScopedErrorReportLock::CheckLocked() {
|
|
|
|
CommonSanitizerReportMutex.CheckLocked();
|
|
|
|
}
|
|
|
|
|
2013-05-18 00:17:19 +08:00
|
|
|
} // namespace __sanitizer
|
2014-05-27 20:37:52 +08:00
|
|
|
|
2017-02-01 04:23:14 +08:00
|
|
|
SANITIZER_INTERFACE_WEAK_DEF(void, __sanitizer_sandbox_on_notify,
|
|
|
|
__sanitizer_sandbox_arguments *args) {
|
2016-09-16 05:02:18 +08:00
|
|
|
__sanitizer::PrepareForSandboxing(args);
|
|
|
|
if (__sanitizer::sandboxing_callback)
|
|
|
|
__sanitizer::sandboxing_callback();
|
2014-05-27 20:37:52 +08:00
|
|
|
}
|