sanitizer_suppressions.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //===-- sanitizer_suppressions.h --------------------------------*- C++ -*-===//
  2. //
  3. // This file is distributed under the University of Illinois Open Source
  4. // License. See LICENSE.TXT for details.
  5. //
  6. //===----------------------------------------------------------------------===//
  7. //
  8. // Suppression parsing/matching code shared between TSan and LSan.
  9. //
  10. //===----------------------------------------------------------------------===//
  11. #ifndef SANITIZER_SUPPRESSIONS_H
  12. #define SANITIZER_SUPPRESSIONS_H
  13. #include "sanitizer_common.h"
  14. #include "sanitizer_internal_defs.h"
  15. namespace __sanitizer {
  16. enum SuppressionType {
  17. SuppressionNone,
  18. SuppressionRace,
  19. SuppressionMutex,
  20. SuppressionThread,
  21. SuppressionSignal,
  22. SuppressionLeak,
  23. SuppressionLib,
  24. SuppressionDeadlock,
  25. SuppressionVptrCheck,
  26. SuppressionTypeCount
  27. };
  28. struct Suppression {
  29. SuppressionType type;
  30. char *templ;
  31. unsigned hit_count;
  32. uptr weight;
  33. };
  34. class SuppressionContext {
  35. public:
  36. void Parse(const char *str);
  37. bool Match(const char* str, SuppressionType type, Suppression **s);
  38. uptr SuppressionCount() const;
  39. const Suppression *SuppressionAt(uptr i) const;
  40. void GetMatched(InternalMmapVector<Suppression *> *matched);
  41. // Create a SuppressionContext singleton if it hasn't been created earlier.
  42. // Not thread safe. Must be called early during initialization (but after
  43. // runtime flags are parsed).
  44. static void InitIfNecessary();
  45. // Returns a SuppressionContext singleton.
  46. static SuppressionContext *Get();
  47. private:
  48. SuppressionContext() : suppressions_(1), can_parse_(true) {}
  49. InternalMmapVector<Suppression> suppressions_;
  50. bool can_parse_;
  51. friend class SuppressionContextTest;
  52. };
  53. const char *SuppressionTypeString(SuppressionType t);
  54. bool TemplateMatch(char *templ, const char *str);
  55. } // namespace __sanitizer
  56. #endif // SANITIZER_SUPPRESSIONS_H