scudo_tsd_exclusive.inc 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. //===-- scudo_tsd_exclusive.inc ---------------------------------*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. ///
  9. /// Scudo exclusive TSD fastpath functions implementation.
  10. ///
  11. //===----------------------------------------------------------------------===//
  12. #ifndef SCUDO_TSD_H_
  13. #error "This file must be included inside scudo_tsd.h."
  14. #endif // SCUDO_TSD_H_
  15. #if SCUDO_TSD_EXCLUSIVE
  16. enum ThreadState : u8 {
  17. ThreadNotInitialized = 0,
  18. ThreadInitialized,
  19. ThreadTornDown,
  20. };
  21. __attribute__((
  22. tls_model("initial-exec"))) extern THREADLOCAL ThreadState ScudoThreadState;
  23. __attribute__((tls_model("initial-exec"))) extern THREADLOCAL ScudoTSD TSD;
  24. extern ScudoTSD FallbackTSD;
  25. ALWAYS_INLINE void initThreadMaybe(bool MinimalInit = false) {
  26. if (LIKELY(ScudoThreadState != ThreadNotInitialized))
  27. return;
  28. initThread(MinimalInit);
  29. }
  30. ALWAYS_INLINE ScudoTSD *
  31. getTSDAndLock(bool *UnlockRequired) SANITIZER_NO_THREAD_SAFETY_ANALYSIS {
  32. if (UNLIKELY(ScudoThreadState != ThreadInitialized)) {
  33. FallbackTSD.lock();
  34. *UnlockRequired = true;
  35. return &FallbackTSD;
  36. }
  37. *UnlockRequired = false;
  38. return &TSD;
  39. }
  40. #endif // SCUDO_TSD_EXCLUSIVE