suspendable_thread_delegate_mac.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 "base/base_export.h"
  8. #include "base/profiler/module_cache.h"
  9. #include "base/profiler/native_unwinder_mac.h"
  10. #include "base/profiler/sampling_profiler_thread_token.h"
  11. #include "base/profiler/suspendable_thread_delegate.h"
  12. #include "base/threading/platform_thread.h"
  13. namespace base {
  14. // Platform- and thread-specific implementation in support of stack sampling on
  15. // Mac.
  16. class BASE_EXPORT SuspendableThreadDelegateMac
  17. : public SuspendableThreadDelegate {
  18. public:
  19. class ScopedSuspendThread
  20. : public SuspendableThreadDelegate::ScopedSuspendThread {
  21. public:
  22. explicit ScopedSuspendThread(mach_port_t thread_port);
  23. ~ScopedSuspendThread() override;
  24. ScopedSuspendThread(const ScopedSuspendThread&) = delete;
  25. ScopedSuspendThread& operator=(const ScopedSuspendThread&) = delete;
  26. bool WasSuccessful() const override;
  27. private:
  28. mach_port_t thread_port_;
  29. };
  30. SuspendableThreadDelegateMac(SamplingProfilerThreadToken thread_token);
  31. ~SuspendableThreadDelegateMac() override;
  32. SuspendableThreadDelegateMac(const SuspendableThreadDelegateMac&) = delete;
  33. SuspendableThreadDelegateMac& operator=(const SuspendableThreadDelegateMac&) =
  34. delete;
  35. // SuspendableThreadDelegate
  36. std::unique_ptr<SuspendableThreadDelegate::ScopedSuspendThread>
  37. CreateScopedSuspendThread() override;
  38. bool GetThreadContext(RegisterContext* thread_context) override;
  39. PlatformThreadId GetThreadId() const override;
  40. uintptr_t GetStackBaseAddress() const override;
  41. bool CanCopyStack(uintptr_t stack_pointer) override;
  42. std::vector<uintptr_t*> GetRegistersToRewrite(
  43. RegisterContext* thread_context) override;
  44. private:
  45. // Weak reference: Mach port for thread being profiled.
  46. const mach_port_t thread_port_;
  47. // The stack base address corresponding to |thread_port_|.
  48. const uintptr_t thread_stack_base_address_;
  49. };
  50. } // namespace base
  51. #endif // BASE_PROFILER_SUSPENDABLE_THREAD_DELEGATE_MAC_H_