llvm-project
102 строки · 3.6 Кб
1//===-- asan_suppressions.cpp ---------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file is a part of AddressSanitizer, an address sanity checker.
10//
11// Issue suppression and suppression-related functions.
12//===----------------------------------------------------------------------===//
13
14#include "asan_suppressions.h"15
16#include "asan_stack.h"17#include "sanitizer_common/sanitizer_placement_new.h"18#include "sanitizer_common/sanitizer_suppressions.h"19#include "sanitizer_common/sanitizer_symbolizer.h"20
21namespace __asan {22
23ALIGNED(64) static char suppression_placeholder[sizeof(SuppressionContext)];24static SuppressionContext *suppression_ctx = nullptr;25static const char kInterceptorName[] = "interceptor_name";26static const char kInterceptorViaFunction[] = "interceptor_via_fun";27static const char kInterceptorViaLibrary[] = "interceptor_via_lib";28static const char kODRViolation[] = "odr_violation";29static const char *kSuppressionTypes[] = {30kInterceptorName, kInterceptorViaFunction, kInterceptorViaLibrary,31kODRViolation};32
33SANITIZER_INTERFACE_WEAK_DEF(const char *, __asan_default_suppressions, void) {34return "";35}
36
37void InitializeSuppressions() {38CHECK_EQ(nullptr, suppression_ctx);39suppression_ctx = new (suppression_placeholder)40SuppressionContext(kSuppressionTypes, ARRAY_SIZE(kSuppressionTypes));41suppression_ctx->ParseFromFile(flags()->suppressions);42suppression_ctx->Parse(__asan_default_suppressions());43}
44
45bool IsInterceptorSuppressed(const char *interceptor_name) {46CHECK(suppression_ctx);47Suppression *s;48// Match "interceptor_name" suppressions.49return suppression_ctx->Match(interceptor_name, kInterceptorName, &s);50}
51
52bool HaveStackTraceBasedSuppressions() {53CHECK(suppression_ctx);54return suppression_ctx->HasSuppressionType(kInterceptorViaFunction) ||55suppression_ctx->HasSuppressionType(kInterceptorViaLibrary);56}
57
58bool IsODRViolationSuppressed(const char *global_var_name) {59CHECK(suppression_ctx);60Suppression *s;61// Match "odr_violation" suppressions.62return suppression_ctx->Match(global_var_name, kODRViolation, &s);63}
64
65bool IsStackTraceSuppressed(const StackTrace *stack) {66if (!HaveStackTraceBasedSuppressions())67return false;68
69CHECK(suppression_ctx);70Symbolizer *symbolizer = Symbolizer::GetOrInit();71Suppression *s;72for (uptr i = 0; i < stack->size && stack->trace[i]; i++) {73uptr addr = stack->trace[i];74
75if (suppression_ctx->HasSuppressionType(kInterceptorViaLibrary)) {76// Match "interceptor_via_lib" suppressions.77if (const char *module_name = symbolizer->GetModuleNameForPc(addr))78if (suppression_ctx->Match(module_name, kInterceptorViaLibrary, &s))79return true;80}81
82if (suppression_ctx->HasSuppressionType(kInterceptorViaFunction)) {83SymbolizedStackHolder symbolized_stack(symbolizer->SymbolizePC(addr));84const SymbolizedStack *frames = symbolized_stack.get();85CHECK(frames);86for (const SymbolizedStack *cur = frames; cur; cur = cur->next) {87const char *function_name = cur->info.function;88if (!function_name) {89continue;90}91// Match "interceptor_via_fun" suppressions.92if (suppression_ctx->Match(function_name, kInterceptorViaFunction,93&s)) {94return true;95}96}97}98}99return false;100}
101
102} // namespace __asan103