lsan_thread.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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_registry.h"
  16. namespace __lsan {
  17. class ThreadContextLsanBase : public ThreadContextBase {
  18. public:
  19. explicit ThreadContextLsanBase(int tid);
  20. void OnFinished() override;
  21. uptr stack_begin() { return stack_begin_; }
  22. uptr stack_end() { return stack_end_; }
  23. uptr cache_begin() { return cache_begin_; }
  24. uptr cache_end() { return cache_end_; }
  25. // The argument is passed on to the subclass's OnStarted member function.
  26. static void ThreadStart(u32 tid, tid_t os_id, ThreadType thread_type,
  27. void *onstarted_arg);
  28. protected:
  29. ~ThreadContextLsanBase() {}
  30. uptr stack_begin_ = 0;
  31. uptr stack_end_ = 0;
  32. uptr cache_begin_ = 0;
  33. uptr cache_end_ = 0;
  34. };
  35. // This subclass of ThreadContextLsanBase is declared in an OS-specific header.
  36. class ThreadContext;
  37. void InitializeThreadRegistry();
  38. void InitializeMainThread();
  39. u32 ThreadCreate(u32 tid, uptr uid, bool detached, void *arg = nullptr);
  40. void ThreadFinish();
  41. void ThreadDetach(u32 tid);
  42. void ThreadJoin(u32 tid);
  43. u32 ThreadTid(uptr uid);
  44. u32 GetCurrentThread();
  45. void SetCurrentThread(u32 tid);
  46. ThreadContext *CurrentThreadContext();
  47. void EnsureMainThreadIDIsCorrect();
  48. } // namespace __lsan
  49. #endif // LSAN_THREAD_H