1//===-- scudo_tsd_exclusive.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 exclusive TSD fastpath functions implementation. 11/// 12//===----------------------------------------------------------------------===// 13 14#ifndef SCUDO_TSD_H_ 15# error "This file must be included inside scudo_tsd.h." 16#endif // SCUDO_TSD_H_ 17 18#if SCUDO_TSD_EXCLUSIVE 19 20enum ThreadState : u8 { 21 ThreadNotInitialized = 0, 22 ThreadInitialized, 23 ThreadTornDown, 24}; 25__attribute__((tls_model("initial-exec"))) 26extern THREADLOCAL ThreadState ScudoThreadState; 27__attribute__((tls_model("initial-exec"))) 28extern THREADLOCAL ScudoTSD TSD; 29 30extern ScudoTSD FallbackTSD; 31 32ALWAYS_INLINE void initThreadMaybe(bool MinimalInit = false) { 33 if (LIKELY(ScudoThreadState != ThreadNotInitialized)) 34 return; 35 initThread(MinimalInit); 36} 37 38ALWAYS_INLINE ScudoTSD *getTSDAndLock(bool *UnlockRequired) { 39 if (UNLIKELY(ScudoThreadState != ThreadInitialized)) { 40 FallbackTSD.lock(); 41 *UnlockRequired = true; 42 return &FallbackTSD; 43 } 44 *UnlockRequired = false; 45 return &TSD; 46} 47 48#endif // SCUDO_TSD_EXCLUSIVE 49