msan_thread.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //===-- msan_thread.h -------------------------------------------*- 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. // This file is a part of MemorySanitizer.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #ifndef MSAN_THREAD_H
  13. #define MSAN_THREAD_H
  14. #include "msan_allocator.h"
  15. #include "sanitizer_common/sanitizer_common.h"
  16. #include "sanitizer_common/sanitizer_posix.h"
  17. namespace __msan {
  18. class MsanThread {
  19. public:
  20. static MsanThread *Create(thread_callback_t start_routine, void *arg);
  21. static void TSDDtor(void *tsd);
  22. void Destroy();
  23. void Init(); // Should be called from the thread itself.
  24. thread_return_t ThreadStart();
  25. uptr stack_top();
  26. uptr stack_bottom();
  27. uptr tls_begin() { return tls_begin_; }
  28. uptr tls_end() { return tls_end_; }
  29. bool IsMainThread() { return start_routine_ == nullptr; }
  30. bool AddrIsInStack(uptr addr);
  31. bool InSignalHandler() { return in_signal_handler_; }
  32. void EnterSignalHandler() { in_signal_handler_++; }
  33. void LeaveSignalHandler() { in_signal_handler_--; }
  34. void StartSwitchFiber(uptr bottom, uptr size);
  35. void FinishSwitchFiber(uptr *bottom_old, uptr *size_old);
  36. MsanThreadLocalMallocStorage &malloc_storage() { return malloc_storage_; }
  37. int destructor_iterations_;
  38. __sanitizer_sigset_t starting_sigset_;
  39. private:
  40. // NOTE: There is no MsanThread constructor. It is allocated
  41. // via mmap() and *must* be valid in zero-initialized state.
  42. void SetThreadStackAndTls();
  43. void ClearShadowForThreadStackAndTLS();
  44. struct StackBounds {
  45. uptr bottom;
  46. uptr top;
  47. };
  48. StackBounds GetStackBounds() const;
  49. thread_callback_t start_routine_;
  50. void *arg_;
  51. bool stack_switching_;
  52. StackBounds stack_;
  53. StackBounds next_stack_;
  54. uptr tls_begin_;
  55. uptr tls_end_;
  56. unsigned in_signal_handler_;
  57. MsanThreadLocalMallocStorage malloc_storage_;
  58. };
  59. MsanThread *GetCurrentThread();
  60. void SetCurrentThread(MsanThread *t);
  61. } // namespace __msan
  62. #endif // MSAN_THREAD_H