1fe6060f1SDimitry Andric //===-- sanitizer_thread_safety.h -------------------------------*- C++ -*-===// 2fe6060f1SDimitry Andric // 3fe6060f1SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4fe6060f1SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5fe6060f1SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6fe6060f1SDimitry Andric // 7fe6060f1SDimitry Andric //===----------------------------------------------------------------------===// 8fe6060f1SDimitry Andric // 9fe6060f1SDimitry Andric // This file is shared between sanitizer tools. 10fe6060f1SDimitry Andric // 11fe6060f1SDimitry Andric // Wrappers around thread safety annotations. 12fe6060f1SDimitry Andric // https://clang.llvm.org/docs/ThreadSafetyAnalysis.html 13fe6060f1SDimitry Andric //===----------------------------------------------------------------------===// 14fe6060f1SDimitry Andric 15fe6060f1SDimitry Andric #ifndef SANITIZER_THREAD_SAFETY_H 16fe6060f1SDimitry Andric #define SANITIZER_THREAD_SAFETY_H 17fe6060f1SDimitry Andric 18fe6060f1SDimitry Andric #if defined(__clang__) 19*04eeddc0SDimitry Andric # define SANITIZER_THREAD_ANNOTATION(x) __attribute__((x)) 20fe6060f1SDimitry Andric #else 21*04eeddc0SDimitry Andric # define SANITIZER_THREAD_ANNOTATION(x) 22fe6060f1SDimitry Andric #endif 23fe6060f1SDimitry Andric 24*04eeddc0SDimitry Andric #define SANITIZER_MUTEX SANITIZER_THREAD_ANNOTATION(capability("mutex")) 25*04eeddc0SDimitry Andric #define SANITIZER_SCOPED_LOCK SANITIZER_THREAD_ANNOTATION(scoped_lockable) 26*04eeddc0SDimitry Andric #define SANITIZER_GUARDED_BY(x) SANITIZER_THREAD_ANNOTATION(guarded_by(x)) 27*04eeddc0SDimitry Andric #define SANITIZER_PT_GUARDED_BY(x) SANITIZER_THREAD_ANNOTATION(pt_guarded_by(x)) 28*04eeddc0SDimitry Andric #define SANITIZER_REQUIRES(...) \ 29*04eeddc0SDimitry Andric SANITIZER_THREAD_ANNOTATION(requires_capability(__VA_ARGS__)) 30*04eeddc0SDimitry Andric #define SANITIZER_REQUIRES_SHARED(...) \ 31*04eeddc0SDimitry Andric SANITIZER_THREAD_ANNOTATION(requires_shared_capability(__VA_ARGS__)) 32*04eeddc0SDimitry Andric #define SANITIZER_ACQUIRE(...) \ 33*04eeddc0SDimitry Andric SANITIZER_THREAD_ANNOTATION(acquire_capability(__VA_ARGS__)) 34*04eeddc0SDimitry Andric #define SANITIZER_ACQUIRE_SHARED(...) \ 35*04eeddc0SDimitry Andric SANITIZER_THREAD_ANNOTATION(acquire_shared_capability(__VA_ARGS__)) 36*04eeddc0SDimitry Andric #define SANITIZER_TRY_ACQUIRE(...) \ 37*04eeddc0SDimitry Andric SANITIZER_THREAD_ANNOTATION(try_acquire_capability(__VA_ARGS__)) 38*04eeddc0SDimitry Andric #define SANITIZER_RELEASE(...) \ 39*04eeddc0SDimitry Andric SANITIZER_THREAD_ANNOTATION(release_capability(__VA_ARGS__)) 40*04eeddc0SDimitry Andric #define SANITIZER_RELEASE_SHARED(...) \ 41*04eeddc0SDimitry Andric SANITIZER_THREAD_ANNOTATION(release_shared_capability(__VA_ARGS__)) 42*04eeddc0SDimitry Andric #define SANITIZER_EXCLUDES(...) \ 43*04eeddc0SDimitry Andric SANITIZER_THREAD_ANNOTATION(locks_excluded(__VA_ARGS__)) 44*04eeddc0SDimitry Andric #define SANITIZER_CHECK_LOCKED(...) \ 45*04eeddc0SDimitry Andric SANITIZER_THREAD_ANNOTATION(assert_capability(__VA_ARGS__)) 46*04eeddc0SDimitry Andric #define SANITIZER_NO_THREAD_SAFETY_ANALYSIS \ 47*04eeddc0SDimitry Andric SANITIZER_THREAD_ANNOTATION(no_thread_safety_analysis) 48fe6060f1SDimitry Andric 49fe6060f1SDimitry Andric #endif 50