suspendable_thread_delegate_win.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 <memory>
  8. #include <vector>
  9. #include "base/base_export.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. #include "base/win/scoped_handle.h"
  14. namespace base {
  15. // Platform- and thread-specific implementation in support of stack sampling on
  16. // Windows.
  17. class BASE_EXPORT SuspendableThreadDelegateWin
  18. : public SuspendableThreadDelegate {
  19. public:
  20. class ScopedSuspendThread
  21. : public SuspendableThreadDelegate::ScopedSuspendThread {
  22. public:
  23. explicit ScopedSuspendThread(HANDLE thread_handle);
  24. ScopedSuspendThread(const ScopedSuspendThread&) = delete;
  25. ScopedSuspendThread& operator=(const ScopedSuspendThread&) = delete;
  26. ~ScopedSuspendThread() override;
  27. bool WasSuccessful() const override;
  28. private:
  29. HANDLE thread_handle_;
  30. bool was_successful_;
  31. };
  32. explicit SuspendableThreadDelegateWin(
  33. SamplingProfilerThreadToken thread_token);
  34. ~SuspendableThreadDelegateWin() override;
  35. SuspendableThreadDelegateWin(const SuspendableThreadDelegateWin&) = delete;
  36. SuspendableThreadDelegateWin& operator=(const SuspendableThreadDelegateWin&) =
  37. delete;
  38. // SuspendableThreadDelegate
  39. std::unique_ptr<SuspendableThreadDelegate::ScopedSuspendThread>
  40. CreateScopedSuspendThread() override;
  41. bool GetThreadContext(CONTEXT* thread_context) override;
  42. PlatformThreadId GetThreadId() const override;
  43. uintptr_t GetStackBaseAddress() const override;
  44. bool CanCopyStack(uintptr_t stack_pointer) override;
  45. std::vector<uintptr_t*> GetRegistersToRewrite(
  46. CONTEXT* thread_context) override;
  47. private:
  48. const PlatformThreadId thread_id_;
  49. win::ScopedHandle thread_handle_;
  50. const uintptr_t thread_stack_base_address_;
  51. };
  52. } // namespace base
  53. #endif // BASE_PROFILER_SUSPENDABLE_THREAD_DELEGATE_WIN_H_