-
Notifications
You must be signed in to change notification settings - Fork 0
DEMO: [rtsan] Support suppressions list #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,16 +14,48 @@ | |
|
|
||
| #include "rtsan/rtsan.h" | ||
| #include "rtsan/rtsan_context.h" | ||
| #include "rtsan/rtsan_diagnostics.h" | ||
| #include "rtsan/rtsan_suppressions.h" | ||
|
|
||
| #include "sanitizer_common/sanitizer_stacktrace.h" | ||
|
|
||
| namespace __rtsan { | ||
|
|
||
| class ScopedBypass { | ||
| public: | ||
| [[nodiscard]] explicit ScopedBypass(Context &context) : context_(context) { | ||
| context_.BypassPush(); | ||
| } | ||
|
|
||
| ~ScopedBypass() { context_.BypassPop(); } | ||
|
|
||
| private: | ||
| Context &context_; | ||
| }; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we go this direction, I will split this into it's own review, likely putting this in rtsan_context.h There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we do without this and use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, I'm not sure if we have access to that construct here, but I'll investigate There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The answer is that no compiler-rt libs include these headers, except in tests. If you do a grep such as: This shows up blank for all interface files. Based on this (for better or worse) we are left with re-implementing anything in our "top level header" down here in the depths of the impl. We can theorize how to improve this (perhaps for us and all sanitizers), but I'm going to keep this as is for now |
||
|
|
||
| template <typename OnViolationAction> | ||
| void ExpectNotRealtime(Context &context, OnViolationAction &&OnViolation) { | ||
| void ExpectNotRealtime(Context &context, const DiagnosticsInfo &info, | ||
| OnViolationAction &&OnViolation) { | ||
| using namespace __sanitizer; | ||
|
|
||
| CHECK(__rtsan_is_initialized()); | ||
| if (context.InRealtimeContext() && !context.IsBypassed()) { | ||
| context.BypassPush(); | ||
| OnViolation(); | ||
| context.BypassPop(); | ||
| ScopedBypass scoped_bypass{context}; | ||
|
|
||
| if (IsInterceptorSuppressed(info.func_name)) | ||
| return; | ||
|
|
||
| BufferedStackTrace stack; | ||
|
|
||
| // We use the unwind_on_fatal flag here because of precedent with other | ||
| // sanitizers, this action is not necessarily fatal if halt_on_error=false | ||
| stack.Unwind(info.pc, info.bp, nullptr, | ||
| common_flags()->fast_unwind_on_fatal); | ||
|
|
||
| if (IsStackTraceSuppressed(stack)) | ||
| return; | ||
|
|
||
| OnViolation(stack, info); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| //===-- rtsan_checks.inc ----------------------------------------*- C++ -*-===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // List of checks handled by RTSan runtime. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| #ifndef RTSAN_CHECK | ||
| #error "Define RTSAN_CHECK prior to including this file!" | ||
| #endif | ||
|
|
||
| // RTSAN_CHECK(Name, SummaryKind) | ||
| // SummaryKind should be a string literal. | ||
|
|
||
| RTSAN_CHECK(FunctionCall, "function-call") | ||
| RTSAN_CHECK(Interceptor, "interceptor") | ||
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| //===--- rtsan_suppressions.cpp - Realtime Sanitizer ------------*- C++ -*-===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This file is a part of the RTSan runtime, providing support for suppressions | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "rtsan/rtsan_suppressions.h" | ||
|
|
||
| #include "rtsan/rtsan_flags.h" | ||
|
|
||
| #include "sanitizer_common/sanitizer_common.h" | ||
| #include "sanitizer_common/sanitizer_internal_defs.h" | ||
| #include "sanitizer_common/sanitizer_suppressions.h" | ||
| #include "sanitizer_common/sanitizer_symbolizer.h" | ||
|
|
||
| #include <new> | ||
|
|
||
| using namespace __sanitizer; | ||
| using namespace __rtsan; | ||
|
|
||
| namespace { | ||
| enum class ErrorType { | ||
| #define RTSAN_CHECK(Name, FSanitizeFlagName) Name, | ||
| #include "rtsan_checks.inc" | ||
| #undef RTSAN_CHECK | ||
| }; | ||
| } // namespace | ||
|
|
||
| alignas(64) static char suppression_placeholder[sizeof(SuppressionContext)]; | ||
| static SuppressionContext *suppression_ctx = nullptr; | ||
| static const char *kSuppressionTypes[] = { | ||
| #define RTSAN_CHECK(Name, FSanitizeFlagName) FSanitizeFlagName, | ||
| #include "rtsan_checks.inc" | ||
| #undef RTSAN_CHECK | ||
| }; | ||
|
|
||
| static const char *ConvertTypeToFlagName(ErrorType Type) { | ||
| switch (Type) { | ||
| #define RTSAN_CHECK(Name, FSanitizeFlagName) \ | ||
| case ErrorType::Name: \ | ||
| return FSanitizeFlagName; | ||
| #include "rtsan_checks.inc" | ||
| #undef RTSAN_CHECK | ||
| } | ||
| UNREACHABLE("unknown ErrorType!"); | ||
| } | ||
|
|
||
| void __rtsan::InitializeSuppressions() { | ||
| CHECK_EQ(nullptr, suppression_ctx); | ||
|
|
||
| suppression_ctx = new (suppression_placeholder) | ||
| SuppressionContext(kSuppressionTypes, ARRAY_SIZE(kSuppressionTypes)); | ||
| suppression_ctx->ParseFromFile(flags().suppressions); | ||
| } | ||
|
|
||
| bool __rtsan::IsStackTraceSuppressed(const StackTrace &stack) { | ||
| CHECK(suppression_ctx); | ||
|
|
||
| const char *function_call_type = | ||
| ConvertTypeToFlagName(ErrorType::FunctionCall); | ||
| if (!suppression_ctx->HasSuppressionType(function_call_type)) | ||
| return false; | ||
|
|
||
| Symbolizer *symbolizer = Symbolizer::GetOrInit(); | ||
| Suppression *s; | ||
|
|
||
| for (uptr i = 0; i < stack.size && stack.trace[i]; i++) { | ||
| uptr addr = stack.trace[i]; | ||
|
|
||
| if (suppression_ctx->HasSuppressionType(function_call_type)) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like there's quite a lot of code here that looks very similar to what's in asan's suppression implementation. Do you think it's worth abstracting anything in common into shared utility functions, or are they different enough to warrant their own implementations? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea. I would recommend investigating this in a follow up review. I don't want to abstract too soon and muddy up this change in isolation. This could be a good refactor follow-on. |
||
| SymbolizedStackHolder symbolized_stack(symbolizer->SymbolizePC(addr)); | ||
| const SymbolizedStack *frames = symbolized_stack.get(); | ||
| CHECK(frames); | ||
| for (const SymbolizedStack *cur = frames; cur; cur = cur->next) { | ||
| const char *function_name = cur->info.function; | ||
| if (!function_name) | ||
| continue; | ||
|
|
||
| if (suppression_ctx->Match(function_name, function_call_type, &s)) | ||
| return true; | ||
| } | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| bool __rtsan::IsInterceptorSuppressed(const char *interceptor_name) { | ||
| CHECK(suppression_ctx); | ||
|
|
||
| const char *interceptor = ConvertTypeToFlagName(ErrorType::Interceptor); | ||
| if (!suppression_ctx->HasSuppressionType(interceptor)) | ||
| return false; | ||
|
|
||
| Suppression *s; | ||
| return suppression_ctx->Match(interceptor_name, interceptor, &s); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| //===--- rtsan_suppressions.h - Realtime Sanitizer --------------*- C++ -*-===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This file is a part of the RTSan runtime, providing support for suppressions | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "sanitizer_common/sanitizer_common.h" | ||
| #include "sanitizer_common/sanitizer_stacktrace.h" | ||
|
|
||
| namespace __rtsan { | ||
|
|
||
| void InitializeSuppressions(); | ||
| bool IsStackTraceSuppressed(const __sanitizer::StackTrace &stack); | ||
| bool IsInterceptorSuppressed(const char *interceptor_name); | ||
|
|
||
| } // namespace __rtsan |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that now, when a violation occurs, ExpectNotRealtime passes in the stack and diagnostics info for more processing.
This function is probably best shown with whitespace turned off, I mostly just extracted things out of the lambda