1 //===-- thread_annotations.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 #ifndef SCUDO_THREAD_ANNOTATIONS_ 10 #define SCUDO_THREAD_ANNOTATIONS_ 11 12 // Enable thread safety attributes only with clang. 13 // The attributes can be safely ignored when compiling with other compilers. 14 #if defined(__clang__) 15 #define THREAD_ANNOTATION_ATTRIBUTE_(x) __attribute__((x)) 16 #else 17 #define THREAD_ANNOTATION_ATTRIBUTE_(x) // no-op 18 #endif 19 20 #define CAPABILITY(x) THREAD_ANNOTATION_ATTRIBUTE_(capability(x)) 21 22 #define SCOPED_CAPABILITY THREAD_ANNOTATION_ATTRIBUTE_(scoped_lockable) 23 24 #define GUARDED_BY(x) THREAD_ANNOTATION_ATTRIBUTE_(guarded_by(x)) 25 26 #define PT_GUARDED_BY(x) THREAD_ANNOTATION_ATTRIBUTE_(pt_guarded_by(x)) 27 28 #define ACQUIRED_BEFORE(...) \ 29 THREAD_ANNOTATION_ATTRIBUTE_(acquired_before(__VA_ARGS__)) 30 31 #define ACQUIRED_AFTER(...) \ 32 THREAD_ANNOTATION_ATTRIBUTE_(acquired_after(__VA_ARGS__)) 33 34 #define REQUIRES(...) \ 35 THREAD_ANNOTATION_ATTRIBUTE_(requires_capability(__VA_ARGS__)) 36 37 #define REQUIRES_SHARED(...) \ 38 THREAD_ANNOTATION_ATTRIBUTE_(requires_shared_capability(__VA_ARGS__)) 39 40 #define ACQUIRE(...) \ 41 THREAD_ANNOTATION_ATTRIBUTE_(acquire_capability(__VA_ARGS__)) 42 43 #define ACQUIRE_SHARED(...) \ 44 THREAD_ANNOTATION_ATTRIBUTE_(acquire_shared_capability(__VA_ARGS__)) 45 46 #define RELEASE(...) \ 47 THREAD_ANNOTATION_ATTRIBUTE_(release_capability(__VA_ARGS__)) 48 49 #define RELEASE_SHARED(...) \ 50 THREAD_ANNOTATION_ATTRIBUTE_(release_shared_capability(__VA_ARGS__)) 51 52 #define TRY_ACQUIRE(...) \ 53 THREAD_ANNOTATION_ATTRIBUTE_(try_acquire_capability(__VA_ARGS__)) 54 55 #define TRY_ACQUIRE_SHARED(...) \ 56 THREAD_ANNOTATION_ATTRIBUTE_(try_acquire_shared_capability(__VA_ARGS__)) 57 58 #define EXCLUDES(...) THREAD_ANNOTATION_ATTRIBUTE_(locks_excluded(__VA_ARGS__)) 59 60 #define ASSERT_CAPABILITY(x) THREAD_ANNOTATION_ATTRIBUTE_(assert_capability(x)) 61 62 #define ASSERT_SHARED_CAPABILITY(x) \ 63 THREAD_ANNOTATION_ATTRIBUTE_(assert_shared_capability(x)) 64 65 #define RETURN_CAPABILITY(x) THREAD_ANNOTATION_ATTRIBUTE_(lock_returned(x)) 66 67 #define NO_THREAD_SAFETY_ANALYSIS \ 68 THREAD_ANNOTATION_ATTRIBUTE_(no_thread_safety_analysis) 69 70 #endif // SCUDO_THREAD_ANNOTATIONS_ 71