1 //===-- asan_suppressions.cc ----------------------------------------------===//
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
6 //===----------------------------------------------------------------------===//
8 // This file is a part of AddressSanitizer, an address sanity checker.
10 // Issue suppression and suppression-related functions.
11 //===----------------------------------------------------------------------===//
13 #include "asan_suppressions.h"
15 #include "asan_stack.h"
16 #include "sanitizer_common/sanitizer_placement_new.h"
17 #include "sanitizer_common/sanitizer_suppressions.h"
18 #include "sanitizer_common/sanitizer_symbolizer.h"
22 ALIGNED(64) static char suppression_placeholder
[sizeof(SuppressionContext
)];
23 static SuppressionContext
*suppression_ctx
= nullptr;
24 static const char kInterceptorName
[] = "interceptor_name";
25 static const char kInterceptorViaFunction
[] = "interceptor_via_fun";
26 static const char kInterceptorViaLibrary
[] = "interceptor_via_lib";
27 static const char kODRViolation
[] = "odr_violation";
28 static const char *kSuppressionTypes
[] = {
29 kInterceptorName
, kInterceptorViaFunction
, kInterceptorViaLibrary
,
32 SANITIZER_INTERFACE_WEAK_DEF(const char *, __asan_default_suppressions
, void) {
36 void InitializeSuppressions() {
37 CHECK_EQ(nullptr, suppression_ctx
);
38 suppression_ctx
= new (suppression_placeholder
) // NOLINT
39 SuppressionContext(kSuppressionTypes
, ARRAY_SIZE(kSuppressionTypes
));
40 suppression_ctx
->ParseFromFile(flags()->suppressions
);
41 if (&__asan_default_suppressions
)
42 suppression_ctx
->Parse(__asan_default_suppressions());
45 bool IsInterceptorSuppressed(const char *interceptor_name
) {
46 CHECK(suppression_ctx
);
48 // Match "interceptor_name" suppressions.
49 return suppression_ctx
->Match(interceptor_name
, kInterceptorName
, &s
);
52 bool HaveStackTraceBasedSuppressions() {
53 CHECK(suppression_ctx
);
54 return suppression_ctx
->HasSuppressionType(kInterceptorViaFunction
) ||
55 suppression_ctx
->HasSuppressionType(kInterceptorViaLibrary
);
58 bool IsODRViolationSuppressed(const char *global_var_name
) {
59 CHECK(suppression_ctx
);
61 // Match "odr_violation" suppressions.
62 return suppression_ctx
->Match(global_var_name
, kODRViolation
, &s
);
65 bool IsStackTraceSuppressed(const StackTrace
*stack
) {
66 if (!HaveStackTraceBasedSuppressions())
69 CHECK(suppression_ctx
);
70 Symbolizer
*symbolizer
= Symbolizer::GetOrInit();
72 for (uptr i
= 0; i
< stack
->size
&& stack
->trace
[i
]; i
++) {
73 uptr addr
= stack
->trace
[i
];
75 if (suppression_ctx
->HasSuppressionType(kInterceptorViaLibrary
)) {
76 // Match "interceptor_via_lib" suppressions.
77 if (const char *module_name
= symbolizer
->GetModuleNameForPc(addr
))
78 if (suppression_ctx
->Match(module_name
, kInterceptorViaLibrary
, &s
))
82 if (suppression_ctx
->HasSuppressionType(kInterceptorViaFunction
)) {
83 SymbolizedStack
*frames
= symbolizer
->SymbolizePC(addr
);
85 for (SymbolizedStack
*cur
= frames
; cur
; cur
= cur
->next
) {
86 const char *function_name
= cur
->info
.function
;
90 // Match "interceptor_via_fun" suppressions.
91 if (suppression_ctx
->Match(function_name
, kInterceptorViaFunction
,
103 } // namespace __asan