lsan_thread.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. ThreadRegistry *GetLsanThreadRegistryLocked();
  40. u32 ThreadCreate(u32 tid, bool detached, void *arg = nullptr);
  41. void ThreadFinish();
  42. u32 GetCurrentThread();
  43. void SetCurrentThread(u32 tid);
  44. ThreadContext *CurrentThreadContext();
  45. void EnsureMainThreadIDIsCorrect();
  46. } // namespace __lsan
  47. #endif // LSAN_THREAD_H