xref: /freebsd/contrib/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_thread_safety.h (revision 04eeddc0aa8e0a417a16eaf9d7d095207f4a8623)
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 
15 #ifndef SANITIZER_THREAD_SAFETY_H
16 #define SANITIZER_THREAD_SAFETY_H
17 
18 #if defined(__clang__)
19 #  define SANITIZER_THREAD_ANNOTATION(x) __attribute__((x))
20 #else
21 #  define SANITIZER_THREAD_ANNOTATION(x)
22 #endif
23 
24 #define SANITIZER_MUTEX SANITIZER_THREAD_ANNOTATION(capability("mutex"))
25 #define SANITIZER_SCOPED_LOCK SANITIZER_THREAD_ANNOTATION(scoped_lockable)
26 #define SANITIZER_GUARDED_BY(x) SANITIZER_THREAD_ANNOTATION(guarded_by(x))
27 #define SANITIZER_PT_GUARDED_BY(x) SANITIZER_THREAD_ANNOTATION(pt_guarded_by(x))
28 #define SANITIZER_REQUIRES(...) \
29   SANITIZER_THREAD_ANNOTATION(requires_capability(__VA_ARGS__))
30 #define SANITIZER_REQUIRES_SHARED(...) \
31   SANITIZER_THREAD_ANNOTATION(requires_shared_capability(__VA_ARGS__))
32 #define SANITIZER_ACQUIRE(...) \
33   SANITIZER_THREAD_ANNOTATION(acquire_capability(__VA_ARGS__))
34 #define SANITIZER_ACQUIRE_SHARED(...) \
35   SANITIZER_THREAD_ANNOTATION(acquire_shared_capability(__VA_ARGS__))
36 #define SANITIZER_TRY_ACQUIRE(...) \
37   SANITIZER_THREAD_ANNOTATION(try_acquire_capability(__VA_ARGS__))
38 #define SANITIZER_RELEASE(...) \
39   SANITIZER_THREAD_ANNOTATION(release_capability(__VA_ARGS__))
40 #define SANITIZER_RELEASE_SHARED(...) \
41   SANITIZER_THREAD_ANNOTATION(release_shared_capability(__VA_ARGS__))
42 #define SANITIZER_EXCLUDES(...) \
43   SANITIZER_THREAD_ANNOTATION(locks_excluded(__VA_ARGS__))
44 #define SANITIZER_CHECK_LOCKED(...) \
45   SANITIZER_THREAD_ANNOTATION(assert_capability(__VA_ARGS__))
46 #define SANITIZER_NO_THREAD_SAFETY_ANALYSIS \
47   SANITIZER_THREAD_ANNOTATION(no_thread_safety_analysis)
48 
49 #endif
50