2020#include < stdio.h>
2121#include < stdlib.h>
2222
23- using namespace __sanitizer ;
24-
25- namespace detail {
26-
27- static pthread_key_t key;
23+ static pthread_key_t context_key;
2824static pthread_once_t key_once = PTHREAD_ONCE_INIT;
29- void internalFree (void *ptr) { __sanitizer::InternalFree (ptr); }
3025
31- using __radsan::Context;
26+ static void internalFree ( void *ptr) { __sanitizer::InternalFree (ptr); }
3227
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 );
3631 };
3732
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 ));
4136 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);
4641 }
4742
4843 return *current_thread_context;
@@ -62,9 +57,7 @@ Context &GetContextForThisThreadImpl() {
6257 Until then, and to keep the first PRs small, only the exit mode
6358 is available.
6459*/
65- void InvokeViolationDetectedAction () { exit (EXIT_FAILURE); }
66-
67- } // namespace detail
60+ static void InvokeViolationDetectedAction () { exit (EXIT_FAILURE); }
6861
6962namespace __radsan {
7063
@@ -82,7 +75,7 @@ void Context::ExpectNotRealtime(const char *intercepted_function_name) {
8275 if (InRealtimeContext () && !IsBypassed ()) {
8376 BypassPush ();
8477 PrintDiagnostics (intercepted_function_name);
85- detail:: InvokeViolationDetectedAction ();
78+ InvokeViolationDetectedAction ();
8679 BypassPop ();
8780 }
8881}
@@ -99,8 +92,6 @@ void Context::PrintDiagnostics(const char *intercepted_function_name) {
9992 __radsan::PrintStackTrace ();
10093}
10194
102- Context &GetContextForThisThread () {
103- return detail::GetContextForThisThreadImpl ();
104- }
95+ Context &GetContextForThisThread () { return GetContextForThisThreadImpl (); }
10596
10697} // namespace __radsan
0 commit comments