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