1 //===-- tsan_printf.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 a part of ThreadSanitizer (TSan), a race detector. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #include "sanitizer_common/sanitizer_common.h" 15 #include "sanitizer_common/sanitizer_libc.h" 16 #include "tsan_defs.h" 17 #include "tsan_mman.h" 18 #include "tsan_platform.h" 19 20 #include <stdarg.h> // va_list 21 22 namespace __sanitizer { 23 int VSNPrintf(char *buff, int buff_length, const char *format, va_list args); 24 } // namespace __sanitizer 25 26 namespace __tsan { 27 28 void TsanPrintf(const char *format, ...) { 29 ScopedInRtl in_rtl; 30 const uptr kMaxLen = 16 * 1024; 31 InternalScopedBuffer<char> buffer(kMaxLen); 32 va_list args; 33 va_start(args, format); 34 uptr len = VSNPrintf(buffer.data(), buffer.size(), format, args); 35 va_end(args); 36 internal_write(CTX() ? flags()->log_fileno : 2, 37 buffer.data(), len < buffer.size() ? len : buffer.size() - 1); 38 } 39 40 } // namespace __tsan 41