suspendable_thread_delegate_mac.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright 2019 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef BASE_PROFILER_SUSPENDABLE_THREAD_DELEGATE_MAC_H_
  5. #define BASE_PROFILER_SUSPENDABLE_THREAD_DELEGATE_MAC_H_
  6. #include <mach/mach.h>
  7. #include <memory>
  8. #include <vector>
  9. #include "base/base_export.h"
  10. #include "base/profiler/module_cache.h"
  11. #include "base/profiler/sampling_profiler_thread_token.h"
  12. #include "base/profiler/suspendable_thread_delegate.h"
  13. #include "base/threading/platform_thread.h"
  14. namespace base {
  15. // Platform- and thread-specific implementation in support of stack sampling on
  16. // Mac (X86_64) and iOS (X86_64 and ARM64).
  17. class BASE_EXPORT SuspendableThreadDelegateMac
  18. : public SuspendableThreadDelegate {
  19. public:
  20. class ScopedSuspendThread
  21. : public SuspendableThreadDelegate::ScopedSuspendThread {
  22. public:
  23. explicit ScopedSuspendThread(mach_port_t thread_port);
  24. ~ScopedSuspendThread() override;
  25. ScopedSuspendThread(const ScopedSuspendThread&) = delete;
  26. ScopedSuspendThread& operator=(const ScopedSuspendThread&) = delete;
  27. bool WasSuccessful() const override;
  28. private:
  29. mach_port_t thread_port_;
  30. };
  31. SuspendableThreadDelegateMac(SamplingProfilerThreadToken thread_token);
  32. ~SuspendableThreadDelegateMac() override;
  33. SuspendableThreadDelegateMac(const SuspendableThreadDelegateMac&) = delete;
  34. SuspendableThreadDelegateMac& operator=(const SuspendableThreadDelegateMac&) =
  35. delete;
  36. // SuspendableThreadDelegate
  37. std::unique_ptr<SuspendableThreadDelegate::ScopedSuspendThread>
  38. CreateScopedSuspendThread() override;
  39. bool GetThreadContext(RegisterContext* thread_context) override;
  40. PlatformThreadId GetThreadId() const override;
  41. uintptr_t GetStackBaseAddress() const override;
  42. bool CanCopyStack(uintptr_t stack_pointer) override;
  43. std::vector<uintptr_t*> GetRegistersToRewrite(
  44. RegisterContext* thread_context) override;
  45. private:
  46. // Weak reference: Mach port for thread being profiled.
  47. const mach_port_t thread_port_;
  48. // The stack base address corresponding to |thread_port_|.
  49. const uintptr_t thread_stack_base_address_;
  50. };
  51. } // namespace base
  52. #endif // BASE_PROFILER_SUSPENDABLE_THREAD_DELEGATE_MAC_H_