Skip to content

Commit b5dc1aa

Browse files
committed
[rtsan] Introduce blocking-fn-name and intercepted-fn-name suppressions
1 parent 4468d58 commit b5dc1aa

File tree

6 files changed

+49
-7
lines changed

6 files changed

+49
-7
lines changed

compiler-rt/lib/rtsan/rtsan_assertions.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ void ExpectNotRealtime(Context &context, const DiagnosticsInfo &info,
2828
if (context.InRealtimeContext() && !context.IsBypassed()) {
2929
ScopedBypass sb{context};
3030

31+
if ((info.type == DiagnosticsInfoType::InterceptedCall &&
32+
IsInterceptorSuppressed(info.func_name)) ||
33+
(info.type == DiagnosticsInfoType::BlockingCall &&
34+
IsBlockingFnSuppressed(info.func_name)))
35+
return;
36+
3137
__sanitizer::BufferedStackTrace stack;
3238

3339
// We use the unwind_on_fatal flag here because of precedent with other

compiler-rt/lib/rtsan/rtsan_checks.inc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@
1717
// SummaryKind should be a string literal.
1818

1919
RTSAN_CHECK(CallStackContains, "call-stack-contains")
20+
RTSAN_CHECK(InterceptedFnName, "intercepted-fn-name")
21+
RTSAN_CHECK(BlockingFnName, "blocking-fn-name")

compiler-rt/lib/rtsan/rtsan_suppressions.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,25 @@ bool __rtsan::IsStackTraceSuppressed(const StackTrace &stack) {
9292
}
9393
return false;
9494
}
95+
96+
static bool IsFunctionSuppressed(const char *interceptor_name,
97+
const char *flag_name) {
98+
if (suppression_ctx == nullptr)
99+
return false;
100+
101+
if (!suppression_ctx->HasSuppressionType(flag_name))
102+
return false;
103+
104+
Suppression *s;
105+
return suppression_ctx->Match(interceptor_name, flag_name, &s);
106+
}
107+
108+
bool __rtsan::IsInterceptorSuppressed(const char *interceptor_name) {
109+
return IsFunctionSuppressed(
110+
interceptor_name, ConvertTypeToFlagName(ErrorType::InterceptedFnName));
111+
}
112+
113+
bool __rtsan::IsBlockingFnSuppressed(const char *blocking_fn_name) {
114+
return IsFunctionSuppressed(blocking_fn_name,
115+
ConvertTypeToFlagName(ErrorType::BlockingFnName));
116+
}

compiler-rt/lib/rtsan/rtsan_suppressions.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,7 @@ namespace __rtsan {
1818

1919
void InitializeSuppressions();
2020
bool IsStackTraceSuppressed(const __sanitizer::StackTrace &stack);
21+
bool IsInterceptorSuppressed(const char *interceptor_name);
22+
bool IsBlockingFnSuppressed(const char *blocking_fn_name);
2123

2224
} // namespace __rtsan

compiler-rt/test/rtsan/stack_suppressions.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %clangxx -fsanitize=realtime %s -o %t
2+
// RUN: %env_rtsan_opts=halt_on_error=false %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NOSUPPRESSIONS
23
// RUN: %env_rtsan_opts=suppressions='%s.supp' not %run %t 2>&1 | FileCheck %s
34
// UNSUPPORTED: ios
45

@@ -22,13 +23,14 @@ void VectorViolations() {
2223
v.reserve(10);
2324
}
2425

25-
void BlockFunc() [[clang::blocking]] { usleep(1); }
26+
void BlockFunc() [[clang::blocking]] { /* do something blocking */
27+
}
2628

2729
void *process() [[clang::nonblocking]] {
28-
void *ptr = MallocViolation();
29-
VectorViolations();
30-
BlockFunc();
31-
free(ptr);
30+
void *ptr = MallocViolation(); // Suppressed call-stack-contains
31+
VectorViolations(); // Suppressed call-stack-contains with regex
32+
BlockFunc(); // Suppressed blocking-fn-name
33+
free(ptr); // Suppressed intercepted-fn-name
3234

3335
// This is the one that should abort the program
3436
// Everything else is suppressed
@@ -51,3 +53,9 @@ int main() {
5153
// CHECK-NOT: vector
5254
// CHECK-NOT: free
5355
// CHECK-NOT: BlockFunc
56+
57+
// CHECK-NOSUPPRESSIONS: malloc
58+
// CHECK-NOSUPPRESSIONS: vector
59+
// CHECK-NOSUPPRESSIONS: free
60+
// CHECK-NOSUPPRESSIONS: BlockFunc
61+
// CHECK-NOSUPPRESSIONS: usleep
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
call-stack-contains:MallocViolation
22
call-stack-contains:std::*vector
3-
call-stack-contains:free
4-
call-stack-contains:BlockFunc
3+
4+
intercepted-fn-name:free
5+
6+
blocking-fn-name:BlockFunc

0 commit comments

Comments
 (0)