xref: /aosp_15_r20/external/cronet/base/profiler/stack_base_address_posix.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2022 The Chromium Authors
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_STACK_BASE_ADDRESS_POSIX_H_
6 #define BASE_PROFILER_STACK_BASE_ADDRESS_POSIX_H_
7 
8 #include <pthread.h>
9 #include <stdint.h>
10 
11 #include <optional>
12 
13 #include "base/base_export.h"
14 #include "base/threading/platform_thread.h"
15 
16 namespace base {
17 
18 // Returns the base address of the stack for the given thread. (The address of
19 // the start of the stack, the highest addressable byte, where the frame of the
20 // first function on the thread is.)
21 //
22 // |id| and |pthread_id| must refer to the same thread.
23 //
24 // On Linux & ChromeOS, if the sandbox has been engaged, this may crash if
25 // |id| and |pthread_id| refer to any thread except the current one.
26 //
27 // May return nullopt on Android if the thread's memory range is not found in
28 // /proc/self/maps.
29 BASE_EXPORT std::optional<uintptr_t> GetThreadStackBaseAddress(
30     PlatformThreadId id,
31     pthread_t pthread_id);
32 
33 }  // namespace base
34 
35 #endif  // BASE_PROFILER_STACK_BASE_ADDRESS_POSIX_H_
36