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 "base/base_export.h" 12 #include "base/threading/platform_thread.h" 13 #include "third_party/abseil-cpp/absl/types/optional.h" 14 15 namespace base { 16 17 // Returns the base address of the stack for the given thread. (The address of 18 // the start of the stack, the highest addressable byte, where the frame of the 19 // first function on the thread is.) 20 // 21 // |id| and |pthread_id| must refer to the same thread. 22 // 23 // On Linux & ChromeOS, if the sandbox has been engaged, this may crash if 24 // |id| and |pthread_id| refer to any thread except the current one. 25 // 26 // May return nullopt on Android if the thread's memory range is not found in 27 // /proc/self/maps. 28 BASE_EXPORT absl::optional<uintptr_t> GetThreadStackBaseAddress( 29 PlatformThreadId id, 30 pthread_t pthread_id); 31 32 } // namespace base 33 34 #endif // BASE_PROFILER_STACK_BASE_ADDRESS_POSIX_H_ 35