1 //===-- scudo_tls_linux.inc -------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 /// Scudo thread local structure fastpath functions implementation for platforms
11 /// supporting thread_local.
13 //===----------------------------------------------------------------------===//
15 #ifndef SCUDO_TLS_LINUX_H_
16 #define SCUDO_TLS_LINUX_H_
19 # error "This file must be included inside scudo_tls.h."
20 #endif // SCUDO_TLS_H_
22 #if SANITIZER_LINUX && !SANITIZER_ANDROID
24 enum ThreadState : u8 {
25 ThreadNotInitialized = 0,
29 __attribute__((tls_model("initial-exec")))
30 extern THREADLOCAL ThreadState ScudoThreadState;
31 __attribute__((tls_model("initial-exec")))
32 extern THREADLOCAL ScudoThreadContext ThreadLocalContext;
34 ALWAYS_INLINE void initThreadMaybe() {
35 if (LIKELY(ScudoThreadState != ThreadNotInitialized))
40 ALWAYS_INLINE ScudoThreadContext *getThreadContextAndLock() {
41 if (UNLIKELY(ScudoThreadState == ThreadTornDown))
43 return &ThreadLocalContext;
46 #endif // SANITIZER_LINUX && !SANITIZER_ANDROID
48 #endif // SCUDO_TLS_LINUX_H_