suspendable_thread_delegate_win.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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_WIN_H_
  5. #define BASE_PROFILER_SUSPENDABLE_THREAD_DELEGATE_WIN_H_
  6. #include <windows.h>
  7. #include "base/base_export.h"
  8. #include "base/profiler/sampling_profiler_thread_token.h"
  9. #include "base/profiler/suspendable_thread_delegate.h"
  10. #include "base/threading/platform_thread.h"
  11. #include "base/win/scoped_handle.h"
  12. namespace base {
  13. // Platform- and thread-specific implementation in support of stack sampling on
  14. // Windows.
  15. class BASE_EXPORT SuspendableThreadDelegateWin
  16. : public SuspendableThreadDelegate {
  17. public:
  18. class ScopedSuspendThread
  19. : public SuspendableThreadDelegate::ScopedSuspendThread {
  20. public:
  21. explicit ScopedSuspendThread(HANDLE thread_handle);
  22. ~ScopedSuspendThread() override;
  23. bool WasSuccessful() const override;
  24. private:
  25. HANDLE thread_handle_;
  26. bool was_successful_;
  27. DISALLOW_COPY_AND_ASSIGN(ScopedSuspendThread);
  28. };
  29. explicit SuspendableThreadDelegateWin(
  30. SamplingProfilerThreadToken thread_token);
  31. ~SuspendableThreadDelegateWin() override;
  32. SuspendableThreadDelegateWin(const SuspendableThreadDelegateWin&) = delete;
  33. SuspendableThreadDelegateWin& operator=(const SuspendableThreadDelegateWin&) =
  34. delete;
  35. // SuspendableThreadDelegate
  36. std::unique_ptr<SuspendableThreadDelegate::ScopedSuspendThread>
  37. CreateScopedSuspendThread() override;
  38. bool GetThreadContext(CONTEXT* 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. CONTEXT* thread_context) override;
  44. private:
  45. const PlatformThreadId thread_id_;
  46. win::ScopedHandle thread_handle_;
  47. const uintptr_t thread_stack_base_address_;
  48. };
  49. } // namespace base
  50. #endif // BASE_PROFILER_SUSPENDABLE_THREAD_DELEGATE_WIN_H_