Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions compiler-rt/lib/rtsan/rtsan_assertions.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ void ExpectNotRealtime(Context &context, const DiagnosticsInfo &info,
if (context.InRealtimeContext() && !context.IsBypassed()) {
ScopedBypass sb{context};

if ((info.type == DiagnosticsInfoType::InterceptedCall &&
IsInterceptorSuppressed(info.func_name)) ||
(info.type == DiagnosticsInfoType::BlockingCall &&
IsBlockingFnSuppressed(info.func_name)))
return;

__sanitizer::BufferedStackTrace stack;

// We use the unwind_on_fatal flag here because of precedent with other
Expand Down
2 changes: 2 additions & 0 deletions compiler-rt/lib/rtsan/rtsan_checks.inc
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@
// SummaryKind should be a string literal.

RTSAN_CHECK(CallStackContains, "call-stack-contains")
RTSAN_CHECK(InterceptedFnName, "intercepted-fn-name")
RTSAN_CHECK(BlockingFnName, "blocking-fn-name")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any feedback on the names?

22 changes: 22 additions & 0 deletions compiler-rt/lib/rtsan/rtsan_suppressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,25 @@ bool __rtsan::IsStackTraceSuppressed(const StackTrace &stack) {
}
return false;
}

static bool IsFunctionSuppressed(const char *interceptor_name,
const char *flag_name) {
if (suppression_ctx == nullptr)
return false;

if (!suppression_ctx->HasSuppressionType(flag_name))
return false;

Suppression *s;
return suppression_ctx->Match(interceptor_name, flag_name, &s);
}

bool __rtsan::IsInterceptorSuppressed(const char *interceptor_name) {
return IsFunctionSuppressed(
interceptor_name, ConvertTypeToFlagName(ErrorType::InterceptedFnName));
}

bool __rtsan::IsBlockingFnSuppressed(const char *blocking_fn_name) {
return IsFunctionSuppressed(blocking_fn_name,
ConvertTypeToFlagName(ErrorType::BlockingFnName));
}
2 changes: 2 additions & 0 deletions compiler-rt/lib/rtsan/rtsan_suppressions.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ namespace __rtsan {

void InitializeSuppressions();
bool IsStackTraceSuppressed(const __sanitizer::StackTrace &stack);
bool IsInterceptorSuppressed(const char *interceptor_name);
bool IsBlockingFnSuppressed(const char *blocking_fn_name);

} // namespace __rtsan
18 changes: 13 additions & 5 deletions compiler-rt/test/rtsan/stack_suppressions.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// RUN: %clangxx -fsanitize=realtime %s -o %t
// RUN: %env_rtsan_opts=halt_on_error=false %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NOSUPPRESSIONS
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this check here to make sure that these would actually cause errors before suppressing them

// RUN: %env_rtsan_opts=suppressions='%s.supp' not %run %t 2>&1 | FileCheck %s
// UNSUPPORTED: ios

Expand All @@ -22,13 +23,14 @@ void VectorViolations() {
v.reserve(10);
}

void BlockFunc() [[clang::blocking]] { usleep(1); }
void BlockFunc() [[clang::blocking]] { /* do something blocking */
}

void *process() [[clang::nonblocking]] {
void *ptr = MallocViolation();
VectorViolations();
BlockFunc();
free(ptr);
void *ptr = MallocViolation(); // Suppressed call-stack-contains
VectorViolations(); // Suppressed call-stack-contains with regex
BlockFunc(); // Suppressed blocking-fn-name
free(ptr); // Suppressed intercepted-fn-name

// This is the one that should abort the program
// Everything else is suppressed
Expand All @@ -51,3 +53,9 @@ int main() {
// CHECK-NOT: vector
// CHECK-NOT: free
// CHECK-NOT: BlockFunc

// CHECK-NOSUPPRESSIONS: malloc
// CHECK-NOSUPPRESSIONS: vector
// CHECK-NOSUPPRESSIONS: free
// CHECK-NOSUPPRESSIONS: BlockFunc
// CHECK-NOSUPPRESSIONS: usleep
6 changes: 4 additions & 2 deletions compiler-rt/test/rtsan/stack_suppressions.cpp.supp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
call-stack-contains:MallocViolation
call-stack-contains:std::*vector
call-stack-contains:free
call-stack-contains:BlockFunc

intercepted-fn-name:free

blocking-fn-name:BlockFunc
Loading