Skip to content

Commit 3fa70e6

Browse files
davidtrevelyancjappl
authored andcommitted
Update comment and TU-local function style
1 parent d1397bd commit 3fa70e6

File tree

3 files changed

+29
-51
lines changed

3 files changed

+29
-51
lines changed

compiler-rt/lib/radsan/radsan.h

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,37 +14,27 @@
1414

1515
extern "C" {
1616

17-
/** Initialise radsan interceptors.
18-
19-
A call to this method is added to the preinit array on Linux systems.
20-
*/
17+
// Initialise radsan interceptors.
18+
// A call to this method is added to the preinit array on Linux systems.
2119
SANITIZER_INTERFACE_ATTRIBUTE void __radsan_init();
2220

23-
/** Enter real-time context.
24-
25-
When in a real-time context, RADSan interceptors will error if realtime
26-
violations are detected. Calls to this method are injected at the code
27-
generation stage when RADSan is enabled.
28-
*/
21+
// Enter real-time context.
22+
// When in a real-time context, RADSan interceptors will error if realtime
23+
// violations are detected. Calls to this method are injected at the code
24+
// generation stage when RADSan is enabled.
2925
SANITIZER_INTERFACE_ATTRIBUTE void __radsan_realtime_enter();
3026

31-
/** Exit the real-time context.
32-
33-
When not in a real-time context, RADSan interceptors will simply forward
34-
intercepted method calls to the real methods.
35-
*/
27+
// Exit the real-time context.
28+
// When not in a real-time context, RADSan interceptors will simply forward
29+
// intercepted method calls to the real methods.
3630
SANITIZER_INTERFACE_ATTRIBUTE void __radsan_realtime_exit();
3731

38-
/** Disable all RADSan error reporting.
39-
40-
Injected into the code if "nosanitize(realtime)" is on a function.
41-
*/
32+
// Disable all RADSan error reporting.
33+
// Injected into the code if "nosanitize(realtime)" is on a function.
4234
SANITIZER_INTERFACE_ATTRIBUTE void __radsan_off();
4335

44-
/** Re-enable all RADSan error reporting.
45-
46-
The counterpart to `__radsan_off`.
47-
*/
36+
// Re-enable all RADSan error reporting.
37+
// The counterpart to `__radsan_off`.
4838
SANITIZER_INTERFACE_ATTRIBUTE void __radsan_on();
4939

5040
} // extern "C"

compiler-rt/lib/radsan/radsan_context.cpp

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,24 @@
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;
2824
static 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

6962
namespace __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

compiler-rt/lib/radsan/radsan_stack.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ using namespace __sanitizer;
1717

1818
// We must define our own implementation of this method for our runtime.
1919
// This one is just copied from UBSan.
20-
2120
namespace __sanitizer {
2221
void BufferedStackTrace::UnwindImpl(uptr pc, uptr bp, void *context,
2322
bool request_fast, u32 max_depth) {
@@ -29,16 +28,14 @@ void BufferedStackTrace::UnwindImpl(uptr pc, uptr bp, void *context,
2928
}
3029
} // namespace __sanitizer
3130

32-
namespace __radsan {
33-
void SetGlobalStackTraceFormat() {
31+
static void SetGlobalStackTraceFormat() {
3432
SetCommonFlagsDefaults();
3533
CommonFlags cf;
3634
cf.CopyFrom(*common_flags());
3735
cf.stack_trace_format = "DEFAULT";
3836
cf.external_symbolizer_path = GetEnv("RADSAN_SYMBOLIZER_PATH");
3937
OverrideCommonFlags(cf);
4038
}
41-
} // namespace __radsan
4239

4340
using namespace __radsan;
4441
void __radsan::PrintStackTrace() {

0 commit comments

Comments
 (0)