]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/compiler-rt/lib/scudo/scudo_tls_linux.inc
Merge llvm, clang, lld, lldb, compiler-rt and libc++ r302418, and update
[FreeBSD/FreeBSD.git] / contrib / compiler-rt / lib / scudo / scudo_tls_linux.inc
1 //===-- scudo_tls_linux.inc -------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 ///
10 /// Scudo thread local structure fastpath functions implementation for platforms
11 /// supporting thread_local.
12 ///
13 //===----------------------------------------------------------------------===//
14
15 #ifndef SCUDO_TLS_LINUX_H_
16 #define SCUDO_TLS_LINUX_H_
17
18 #ifndef SCUDO_TLS_H_
19 # error "This file must be included inside scudo_tls.h."
20 #endif  // SCUDO_TLS_H_
21
22 #if SANITIZER_LINUX && !SANITIZER_ANDROID
23
24 enum ThreadState : u8 {
25   ThreadNotInitialized = 0,
26   ThreadInitialized,
27   ThreadTornDown,
28 };
29 __attribute__((tls_model("initial-exec")))
30 extern THREADLOCAL ThreadState ScudoThreadState;
31 __attribute__((tls_model("initial-exec")))
32 extern THREADLOCAL ScudoThreadContext ThreadLocalContext;
33
34 ALWAYS_INLINE void initThreadMaybe() {
35   if (LIKELY(ScudoThreadState != ThreadNotInitialized))
36     return;
37   initThread();
38 }
39
40 ALWAYS_INLINE ScudoThreadContext *getThreadContextAndLock() {
41   if (UNLIKELY(ScudoThreadState == ThreadTornDown))
42     return nullptr;
43   return &ThreadLocalContext;
44 }
45
46 #endif  // SANITIZER_LINUX && !SANITIZER_ANDROID
47
48 #endif  // SCUDO_TLS_LINUX_H_