lsan_thread.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //=-- lsan_thread.h -------------------------------------------------------===//
  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. // This file is a part of LeakSanitizer.
  10. // Thread registry for standalone LSan.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LSAN_THREAD_H
  14. #define LSAN_THREAD_H
  15. #include "sanitizer_common/sanitizer_thread_arg_retval.h"
  16. #include "sanitizer_common/sanitizer_thread_registry.h"
  17. namespace __lsan {
  18. class ThreadContextLsanBase : public ThreadContextBase {
  19. public:
  20. explicit ThreadContextLsanBase(int tid);
  21. void OnStarted(void *arg) override;
  22. void OnFinished() override;
  23. uptr stack_begin() { return stack_begin_; }
  24. uptr stack_end() { return stack_end_; }
  25. uptr cache_begin() { return cache_begin_; }
  26. uptr cache_end() { return cache_end_; }
  27. // The argument is passed on to the subclass's OnStarted member function.
  28. static void ThreadStart(u32 tid, tid_t os_id, ThreadType thread_type,
  29. void *onstarted_arg);
  30. protected:
  31. ~ThreadContextLsanBase() {}
  32. uptr stack_begin_ = 0;
  33. uptr stack_end_ = 0;
  34. uptr cache_begin_ = 0;
  35. uptr cache_end_ = 0;
  36. };
  37. // This subclass of ThreadContextLsanBase is declared in an OS-specific header.
  38. class ThreadContext;
  39. void InitializeThreads();
  40. void InitializeMainThread();
  41. ThreadRegistry *GetLsanThreadRegistryLocked();
  42. ThreadArgRetval &GetThreadArgRetval();
  43. u32 ThreadCreate(u32 tid, bool detached, void *arg = nullptr);
  44. void ThreadFinish();
  45. ThreadContextLsanBase *GetCurrentThread();
  46. inline u32 GetCurrentThreadId() {
  47. ThreadContextLsanBase *ctx = GetCurrentThread();
  48. return ctx ? ctx->tid : kInvalidTid;
  49. }
  50. void SetCurrentThread(ThreadContextLsanBase *tctx);
  51. void EnsureMainThreadIDIsCorrect();
  52. } // namespace __lsan
  53. #endif // LSAN_THREAD_H