sanitizer_thread_safety.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. //===-- sanitizer_thread_safety.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. // This file is shared between sanitizer tools.
  10. //
  11. // Wrappers around thread safety annotations.
  12. // https://clang.llvm.org/docs/ThreadSafetyAnalysis.html
  13. //===----------------------------------------------------------------------===//
  14. #ifndef SANITIZER_THREAD_SAFETY_H
  15. #define SANITIZER_THREAD_SAFETY_H
  16. #if defined(__clang__)
  17. # define SANITIZER_THREAD_ANNOTATION(x) __attribute__((x))
  18. #else
  19. # define SANITIZER_THREAD_ANNOTATION(x)
  20. #endif
  21. #define SANITIZER_MUTEX SANITIZER_THREAD_ANNOTATION(capability("mutex"))
  22. #define SANITIZER_SCOPED_LOCK SANITIZER_THREAD_ANNOTATION(scoped_lockable)
  23. #define SANITIZER_GUARDED_BY(x) SANITIZER_THREAD_ANNOTATION(guarded_by(x))
  24. #define SANITIZER_PT_GUARDED_BY(x) SANITIZER_THREAD_ANNOTATION(pt_guarded_by(x))
  25. #define SANITIZER_REQUIRES(...) \
  26. SANITIZER_THREAD_ANNOTATION(requires_capability(__VA_ARGS__))
  27. #define SANITIZER_REQUIRES_SHARED(...) \
  28. SANITIZER_THREAD_ANNOTATION(requires_shared_capability(__VA_ARGS__))
  29. #define SANITIZER_ACQUIRE(...) \
  30. SANITIZER_THREAD_ANNOTATION(acquire_capability(__VA_ARGS__))
  31. #define SANITIZER_ACQUIRE_SHARED(...) \
  32. SANITIZER_THREAD_ANNOTATION(acquire_shared_capability(__VA_ARGS__))
  33. #define SANITIZER_TRY_ACQUIRE(...) \
  34. SANITIZER_THREAD_ANNOTATION(try_acquire_capability(__VA_ARGS__))
  35. #define SANITIZER_RELEASE(...) \
  36. SANITIZER_THREAD_ANNOTATION(release_capability(__VA_ARGS__))
  37. #define SANITIZER_RELEASE_SHARED(...) \
  38. SANITIZER_THREAD_ANNOTATION(release_shared_capability(__VA_ARGS__))
  39. #define SANITIZER_EXCLUDES(...) \
  40. SANITIZER_THREAD_ANNOTATION(locks_excluded(__VA_ARGS__))
  41. #define SANITIZER_CHECK_LOCKED(...) \
  42. SANITIZER_THREAD_ANNOTATION(assert_capability(__VA_ARGS__))
  43. #define SANITIZER_NO_THREAD_SAFETY_ANALYSIS \
  44. SANITIZER_THREAD_ANNOTATION(no_thread_safety_analysis)
  45. #endif