Path: blob/main/contrib/llvm-project/compiler-rt/lib/rtsan/rtsan_suppressions.cpp
213766 views
//===--- rtsan_suppressions.cpp - Realtime Sanitizer ------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file is a part of the RTSan runtime, providing support for suppressions9//10//===----------------------------------------------------------------------===//1112#include "rtsan/rtsan_suppressions.h"1314#include "rtsan/rtsan_flags.h"1516#include "sanitizer_common/sanitizer_common.h"17#include "sanitizer_common/sanitizer_internal_defs.h"18#include "sanitizer_common/sanitizer_suppressions.h"19#include "sanitizer_common/sanitizer_symbolizer.h"2021#include <new>2223using namespace __sanitizer;24using namespace __rtsan;2526namespace {27enum class ErrorType {28#define RTSAN_CHECK(Name, FSanitizeFlagName) Name,29#include "rtsan_checks.inc"30#undef RTSAN_CHECK31};32} // namespace3334alignas(64) static char suppression_placeholder[sizeof(SuppressionContext)];35static SuppressionContext *suppression_ctx = nullptr;3637static const char *kSuppressionTypes[] = {38#define RTSAN_CHECK(Name, FSanitizeFlagName) FSanitizeFlagName,39#include "rtsan_checks.inc"40#undef RTSAN_CHECK41};4243static const char *ConvertTypeToFlagName(ErrorType Type) {44switch (Type) {45#define RTSAN_CHECK(Name, FSanitizeFlagName) \46case ErrorType::Name: \47return FSanitizeFlagName;48#include "rtsan_checks.inc"49#undef RTSAN_CHECK50}51UNREACHABLE("unknown ErrorType!");52}5354void __rtsan::InitializeSuppressions() {55CHECK_EQ(nullptr, suppression_ctx);5657// We will use suppression_ctx == nullptr as an early out58if (!flags().ContainsSuppresionFile())59return;6061suppression_ctx = new (suppression_placeholder)62SuppressionContext(kSuppressionTypes, ARRAY_SIZE(kSuppressionTypes));63suppression_ctx->ParseFromFile(flags().suppressions);64}6566bool __rtsan::IsStackTraceSuppressed(const StackTrace &stack) {67if (suppression_ctx == nullptr)68return false;6970const char *call_stack_flag =71ConvertTypeToFlagName(ErrorType::CallStackContains);72if (!suppression_ctx->HasSuppressionType(call_stack_flag))73return false;7475Symbolizer *symbolizer = Symbolizer::GetOrInit();76for (uptr i = 0; i < stack.size && stack.trace[i]; i++) {77const uptr addr = stack.trace[i];7879SymbolizedStackHolder symbolized_stack(symbolizer->SymbolizePC(addr));80const SymbolizedStack *frames = symbolized_stack.get();81CHECK(frames);82for (const SymbolizedStack *cur = frames; cur; cur = cur->next) {83const char *function_name = cur->info.function;84if (!function_name)85continue;8687Suppression *s;88if (suppression_ctx->Match(function_name, call_stack_flag, &s))89return true;90}91}92return false;93}9495bool __rtsan::IsFunctionSuppressed(const char *function_name) {96if (suppression_ctx == nullptr)97return false;9899const char *flag_name = ConvertTypeToFlagName(ErrorType::FunctionNameMatches);100101if (!suppression_ctx->HasSuppressionType(flag_name))102return false;103104Suppression *s;105return suppression_ctx->Match(function_name, flag_name, &s);106}107108109