jit: Add checking for dereference of void *
[official-gcc.git] / libsanitizer / sanitizer_common / sanitizer_common_libcdep.cc
blobb5251444f0fa6f4ed070f57b34278a7408f4b87f
1 //===-- sanitizer_common_libcdep.cc ---------------------------------------===//
2 //
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
5 //
6 //===----------------------------------------------------------------------===//
7 //
8 // This file is shared between AddressSanitizer and ThreadSanitizer
9 // run-time libraries.
10 //===----------------------------------------------------------------------===//
12 #include "sanitizer_common.h"
13 #include "sanitizer_flags.h"
14 #include "sanitizer_stacktrace.h"
15 #include "sanitizer_symbolizer.h"
17 namespace __sanitizer {
19 bool PrintsToTty() {
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)
28 return 0;
30 static int cached = 0;
31 static bool prints_to_tty;
32 if (!cached) { // Not thread-safe.
33 prints_to_tty = PrintsToTty();
34 cached = 1;
36 return prints_to_tty;
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)
52 return;
53 AddressInfo ai;
54 #if !SANITIZER_GO
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);
61 #endif
62 ReportErrorSummary(error_type, ai.file, ai.line, ai.function);
65 } // namespace __sanitizer
67 void NOINLINE
68 __sanitizer_sandbox_on_notify(__sanitizer_sandbox_arguments *args) {
69 PrepareForSandboxing(args);
70 if (sandboxing_callback)
71 sandboxing_callback();