20
20
#include < stdio.h>
21
21
#include < stdlib.h>
22
22
23
- using namespace __sanitizer ;
24
-
25
- namespace detail {
26
-
27
- static pthread_key_t key;
23
+ static pthread_key_t context_key;
28
24
static pthread_once_t key_once = PTHREAD_ONCE_INIT;
29
- void internalFree (void *ptr) { __sanitizer::InternalFree (ptr); }
30
25
31
- using __radsan::Context;
26
+ static void internalFree ( void *ptr) { __sanitizer::InternalFree (ptr); }
32
27
33
- Context &GetContextForThisThreadImpl () {
34
- auto make_tls_key = []() {
35
- CHECK_EQ (pthread_key_create (&detail::key, detail:: internalFree), 0 );
28
+ static __radsan:: Context &GetContextForThisThreadImpl () {
29
+ auto make_thread_local_context_key = []() {
30
+ CHECK_EQ (pthread_key_create (&context_key, internalFree), 0 );
36
31
};
37
32
38
- pthread_once (&detail:: key_once, make_tls_key );
39
- Context *current_thread_context =
40
- static_cast <Context *>(pthread_getspecific (detail::key ));
33
+ pthread_once (&key_once, make_thread_local_context_key );
34
+ __radsan:: Context *current_thread_context =
35
+ static_cast <__radsan:: Context *>(pthread_getspecific (context_key ));
41
36
if (current_thread_context == nullptr ) {
42
- current_thread_context =
43
- static_cast <Context *>( InternalAlloc (sizeof (Context)));
44
- new (current_thread_context) Context ();
45
- pthread_setspecific (detail::key , current_thread_context);
37
+ current_thread_context = static_cast <__radsan::Context *>(
38
+ __sanitizer:: InternalAlloc (sizeof (__radsan:: Context)));
39
+ new (current_thread_context) __radsan:: Context ();
40
+ pthread_setspecific (context_key , current_thread_context);
46
41
}
47
42
48
43
return *current_thread_context;
@@ -62,9 +57,7 @@ Context &GetContextForThisThreadImpl() {
62
57
Until then, and to keep the first PRs small, only the exit mode
63
58
is available.
64
59
*/
65
- void InvokeViolationDetectedAction () { exit (EXIT_FAILURE); }
66
-
67
- } // namespace detail
60
+ static void InvokeViolationDetectedAction () { exit (EXIT_FAILURE); }
68
61
69
62
namespace __radsan {
70
63
@@ -82,7 +75,7 @@ void Context::ExpectNotRealtime(const char *intercepted_function_name) {
82
75
if (InRealtimeContext () && !IsBypassed ()) {
83
76
BypassPush ();
84
77
PrintDiagnostics (intercepted_function_name);
85
- detail:: InvokeViolationDetectedAction ();
78
+ InvokeViolationDetectedAction ();
86
79
BypassPop ();
87
80
}
88
81
}
@@ -99,8 +92,6 @@ void Context::PrintDiagnostics(const char *intercepted_function_name) {
99
92
__radsan::PrintStackTrace ();
100
93
}
101
94
102
- Context &GetContextForThisThread () {
103
- return detail::GetContextForThisThreadImpl ();
104
- }
95
+ Context &GetContextForThisThread () { return GetContextForThisThreadImpl (); }
105
96
106
97
} // namespace __radsan
0 commit comments