Home | History | Annotate | Download | only in sanitizer_common
      1 //===-- sanitizer_common_libcdep.cc ---------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 //
     10 // This file is shared between AddressSanitizer and ThreadSanitizer
     11 // run-time libraries.
     12 //===----------------------------------------------------------------------===//
     13 
     14 #include "sanitizer_common.h"
     15 #include "sanitizer_flags.h"
     16 
     17 namespace __sanitizer {
     18 
     19 bool PrintsToTty() {
     20   MaybeOpenReportFile();
     21   return internal_isatty(report_fd) != 0;
     22 }
     23 
     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;
     29 
     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;
     35   }
     36   return prints_to_tty;
     37 }
     38 
     39 bool ColorizeReports() {
     40   const char *flag = common_flags()->color;
     41   return internal_strcmp(flag, "always") == 0 ||
     42          (internal_strcmp(flag, "auto") == 0 && PrintsToTtyCached());
     43 }
     44 
     45 static void (*sandboxing_callback)();
     46 void SetSandboxingCallback(void (*f)()) {
     47   sandboxing_callback = f;
     48 }
     49 
     50 }  // namespace __sanitizer
     51 
     52 void NOINLINE
     53 __sanitizer_sandbox_on_notify(__sanitizer_sandbox_arguments *args) {
     54   PrepareForSandboxing(args);
     55   if (sandboxing_callback)
     56     sandboxing_callback();
     57 }
     58