1 //===-- sanitizer_common_libcdep.cc ---------------------------------------===//
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
6 //===----------------------------------------------------------------------===//
8 // This file is shared between AddressSanitizer and ThreadSanitizer
10 //===----------------------------------------------------------------------===//
12 #include "sanitizer_common.h"
13 #include "sanitizer_flags.h"
14 #include "sanitizer_stacktrace.h"
15 #include "sanitizer_symbolizer.h"
17 namespace __sanitizer
{
20 MaybeOpenReportFile();
21 return internal_isatty(report_fd
) != 0;
24 bool PrintsToTtyCached() {
25 // FIXME: Add proper Windows support to AnsiColorDecorator and re-enable color
26 // printing on Windows.
27 if (SANITIZER_WINDOWS
)
30 static int cached
= 0;
31 static bool prints_to_tty
;
32 if (!cached
) { // Not thread-safe.
33 prints_to_tty
= PrintsToTty();
39 bool ColorizeReports() {
40 const char *flag
= common_flags()->color
;
41 return internal_strcmp(flag
, "always") == 0 ||
42 (internal_strcmp(flag
, "auto") == 0 && PrintsToTtyCached());
45 static void (*sandboxing_callback
)();
46 void SetSandboxingCallback(void (*f
)()) {
47 sandboxing_callback
= f
;
50 void ReportErrorSummary(const char *error_type
, StackTrace
*stack
) {
51 if (!common_flags()->print_summary
)
55 if (stack
->size
> 0 && Symbolizer::GetOrInit()->CanReturnFileLineInfo()) {
56 // Currently, we include the first stack frame into the report summary.
57 // Maybe sometimes we need to choose another frame (e.g. skip memcpy/etc).
58 uptr pc
= StackTrace::GetPreviousInstructionPc(stack
->trace
[0]);
59 Symbolizer::GetOrInit()->SymbolizePC(pc
, &ai
, 1);
62 ReportErrorSummary(error_type
, ai
.file
, ai
.line
, ai
.function
);
65 } // namespace __sanitizer
68 __sanitizer_sandbox_on_notify(__sanitizer_sandbox_arguments
*args
) {
69 PrepareForSandboxing(args
);
70 if (sandboxing_callback
)
71 sandboxing_callback();