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 
5 #ifndef BASE_PROFILER_THREAD_DELEGATE_POSIX_H_
6 #define BASE_PROFILER_THREAD_DELEGATE_POSIX_H_
7 
8 #include <memory>
9 
10 #include "base/base_export.h"
11 #include "base/profiler/sampling_profiler_thread_token.h"
12 #include "base/profiler/thread_delegate.h"
13 #include "base/threading/platform_thread.h"
14 
15 namespace base {
16 
17 // Platform- and thread-specific implementation in support of stack sampling on
18 // POSIX.
19 class BASE_EXPORT ThreadDelegatePosix : public ThreadDelegate {
20  public:
21   static std::unique_ptr<ThreadDelegatePosix> Create(
22       SamplingProfilerThreadToken thread_token);
23 
24   ~ThreadDelegatePosix() override;
25 
26   ThreadDelegatePosix(const ThreadDelegatePosix&) = delete;
27   ThreadDelegatePosix& operator=(const ThreadDelegatePosix&) = delete;
28 
29   // ThreadDelegate
30   PlatformThreadId GetThreadId() const override;
31   uintptr_t GetStackBaseAddress() const override;
32   std::vector<uintptr_t*> GetRegistersToRewrite(
33       RegisterContext* thread_context) override;
34 
35  private:
36   ThreadDelegatePosix(PlatformThreadId id, uintptr_t base_address);
37 
38   const PlatformThreadId thread_id_;
39   const uintptr_t thread_stack_base_address_;
40 };
41 
42 }  // namespace base
43 
44 #endif  // BASE_PROFILER_THREAD_DELEGATE_POSIX_H_
45