]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/compiler-rt/lib/asan/asan_suppressions.cc
Update compiler-rt to trunk r228651. This enables using Address
[FreeBSD/FreeBSD.git] / contrib / compiler-rt / lib / asan / asan_suppressions.cc
1 //===-- asan_suppressions.cc ----------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file is a part of AddressSanitizer, an address sanity checker.
11 //
12 // Issue suppression and suppression-related functions.
13 //===----------------------------------------------------------------------===//
14
15 #include "asan_suppressions.h"
16
17 #include "asan_stack.h"
18 #include "sanitizer_common/sanitizer_suppressions.h"
19 #include "sanitizer_common/sanitizer_symbolizer.h"
20
21 namespace __asan {
22
23 static bool suppressions_inited = false;
24
25 void InitializeSuppressions() {
26   CHECK(!suppressions_inited);
27   SuppressionContext::InitIfNecessary();
28   suppressions_inited = true;
29 }
30
31 bool IsInterceptorSuppressed(const char *interceptor_name) {
32   CHECK(suppressions_inited);
33   SuppressionContext *ctx = SuppressionContext::Get();
34   Suppression *s;
35   // Match "interceptor_name" suppressions.
36   return ctx->Match(interceptor_name, SuppressionInterceptorName, &s);
37 }
38
39 bool HaveStackTraceBasedSuppressions() {
40   CHECK(suppressions_inited);
41   SuppressionContext *ctx = SuppressionContext::Get();
42   return ctx->HasSuppressionType(SuppressionInterceptorViaFunction) ||
43          ctx->HasSuppressionType(SuppressionInterceptorViaLibrary);
44 }
45
46 bool IsStackTraceSuppressed(const StackTrace *stack) {
47   CHECK(suppressions_inited);
48   if (!HaveStackTraceBasedSuppressions())
49     return false;
50
51   SuppressionContext *ctx = SuppressionContext::Get();
52   Symbolizer *symbolizer = Symbolizer::GetOrInit();
53   Suppression *s;
54   for (uptr i = 0; i < stack->size && stack->trace[i]; i++) {
55     uptr addr = stack->trace[i];
56
57     if (ctx->HasSuppressionType(SuppressionInterceptorViaLibrary)) {
58       const char *module_name;
59       uptr module_offset;
60       // Match "interceptor_via_lib" suppressions.
61       if (symbolizer->GetModuleNameAndOffsetForPC(addr, &module_name,
62                                                   &module_offset) &&
63           ctx->Match(module_name, SuppressionInterceptorViaLibrary, &s)) {
64         return true;
65       }
66     }
67
68     if (ctx->HasSuppressionType(SuppressionInterceptorViaFunction)) {
69       SymbolizedStack *frames = symbolizer->SymbolizePC(addr);
70       for (SymbolizedStack *cur = frames; cur; cur = cur->next) {
71         const char *function_name = cur->info.function;
72         if (!function_name) {
73           continue;
74         }
75         // Match "interceptor_via_fun" suppressions.
76         if (ctx->Match(function_name, SuppressionInterceptorViaFunction, &s)) {
77           frames->ClearAll();
78           return true;
79         }
80       }
81       frames->ClearAll();
82     }
83   }
84   return false;
85 }
86
87 } // namespace __asan