1 //===-- scudo_tsd_shared.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 shared TSD fastpath functions implementation.
12 //===----------------------------------------------------------------------===//
15 # error "This file must be included inside scudo_tsd.h."
16 #endif // SCUDO_TSD_H_
18 #if !SCUDO_TSD_EXCLUSIVE
20 extern pthread_key_t PThreadKey;
22 #if SANITIZER_LINUX && !SANITIZER_ANDROID
23 __attribute__((tls_model("initial-exec")))
24 extern THREADLOCAL ScudoTSD *CurrentTSD;
27 ALWAYS_INLINE ScudoTSD* getCurrentTSD() {
29 return reinterpret_cast<ScudoTSD *>(*get_android_tls_ptr());
33 return reinterpret_cast<ScudoTSD *>(pthread_getspecific(PThreadKey));
34 #endif // SANITIZER_ANDROID
37 ALWAYS_INLINE void initThreadMaybe(bool MinimalInit = false) {
38 if (LIKELY(getCurrentTSD()))
40 initThread(MinimalInit);
43 ScudoTSD *getTSDAndLockSlow(ScudoTSD *TSD);
45 ALWAYS_INLINE ScudoTSD *getTSDAndLock(bool *UnlockRequired) {
46 ScudoTSD *TSD = getCurrentTSD();
47 DCHECK(TSD && "No TSD associated with the current thread!");
48 *UnlockRequired = true;
49 // Try to lock the currently associated context.
52 // If it failed, go the slow path.
53 return getTSDAndLockSlow(TSD);
56 #endif // !SCUDO_TSD_EXCLUSIVE