1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
#include "sanitizers.h"
#include "thread.h"
using namespace NSan;
#if defined(_tsan_enabled_)
#if defined(__clang_major__) && (__clang_major__ >= 9)
extern "C" { // sanitizers API
#if defined(_tsan_enabled_)
void* __tsan_create_fiber(unsigned flags);
void __tsan_set_fiber_name(void* fiber, const char* name);
#endif
} // sanitizers API
#else
namespace {
void* __tsan_create_fiber(unsigned) {
return nullptr;
}
void __tsan_set_fiber_name(void*, const char*) {
}
} // namespace
#endif
#endif
TFiberContext::TFiberContext() noexcept
: Token_(nullptr)
, IsMainFiber_(true)
#if defined(_tsan_enabled_)
, CurrentTSanFiberContext_(__tsan_get_current_fiber())
#endif
{
TCurrentThreadLimits sl;
(void)Token_;
Stack_ = sl.StackBegin;
Len_ = sl.StackLength;
#if defined(_tsan_enabled_)
static constexpr char MainFiberName[] = "main_fiber";
__tsan_set_fiber_name(CurrentTSanFiberContext_, MainFiberName);
#endif
}
TFiberContext::TFiberContext(const void* stack, size_t len, const char* contName) noexcept
: Token_(nullptr)
, Stack_(stack)
, Len_(len)
, IsMainFiber_(false)
#if defined(_tsan_enabled_)
, CurrentTSanFiberContext_(__tsan_create_fiber(/*flags =*/0))
#endif
{
(void)contName;
#if defined(_tsan_enabled_)
__tsan_set_fiber_name(CurrentTSanFiberContext_, contName);
#endif
}
#if defined(_tsan_enabled_)
extern "C" {
// This function should not be directly exposed in headers
// due to signature variations among contrib headers.
void AnnotateBenignRaceSized(const char* file, int line,
const volatile void* address,
size_t size,
const char* description);
}
void NSan::AnnotateBenignRaceSized(const char* file, int line,
const volatile void* address,
size_t size,
const char* description) noexcept {
::AnnotateBenignRaceSized(file, line, address, size, description);
}
#endif
|