1 //===-- sanitizer_suppressions.h --------------------------------*- C++ -*-===//
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 // Suppression parsing/matching code.
10 //
11 //===----------------------------------------------------------------------===//
12 #ifndef SANITIZER_SUPPRESSIONS_H
13 #define SANITIZER_SUPPRESSIONS_H
14 
15 #include "sanitizer_common.h"
16 #include "sanitizer_atomic.h"
17 #include "sanitizer_internal_defs.h"
18 
19 namespace __sanitizer {
20 
21 struct Suppression {
22   Suppression() { internal_memset(this, 0, sizeof(*this)); }
23   const char *type;
24   char *templ;
25   atomic_uint32_t hit_count;
26   uptr weight;
27 };
28 
29 class SuppressionContext {
30  public:
31   // Create new SuppressionContext capable of parsing given suppression types.
32   SuppressionContext(const char *supprression_types[],
33                      int suppression_types_num);
34 
35   void ParseFromFile(const char *filename);
36   void Parse(const char *str);
37 
38   bool Match(const char *str, const char *type, Suppression **s);
39   uptr SuppressionCount() const;
40   bool HasSuppressionType(const char *type) const;
41   const Suppression *SuppressionAt(uptr i) const;
42   void GetMatched(InternalMmapVector<Suppression *> *matched);
43 
44  private:
45   static const int kMaxSuppressionTypes = 64;
46   const char **const suppression_types_;
47   const int suppression_types_num_;
48 
49   InternalMmapVector<Suppression> suppressions_;
50   bool has_suppression_type_[kMaxSuppressionTypes];
51   bool can_parse_;
52 };
53 
54 }  // namespace __sanitizer
55 
56 #endif  // SANITIZER_SUPPRESSIONS_H
57