1 // Copyright 2021 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_ALLOCATOR_PARTITION_ALLOCATOR_STARSCAN_STACK_STACK_H_ 6 #define BASE_ALLOCATOR_PARTITION_ALLOCATOR_STARSCAN_STACK_STACK_H_ 7 8 #include <cstdint> 9 10 #include "base/allocator/partition_allocator/partition_alloc_base/compiler_specific.h" 11 #include "base/allocator/partition_allocator/partition_alloc_base/component_export.h" 12 13 namespace partition_alloc::internal { 14 15 // Returns the current stack pointer. 16 // TODO(bikineev,1202644): Remove this once base/stack_util.h lands. 17 PA_NOINLINE PA_COMPONENT_EXPORT(PARTITION_ALLOC) uintptr_t* GetStackPointer(); 18 // Returns the top of the stack using system API. 19 PA_COMPONENT_EXPORT(PARTITION_ALLOC) void* GetStackTop(); 20 21 // Interface for stack visitation. 22 class StackVisitor { 23 public: 24 virtual void VisitStack(uintptr_t* stack_ptr, uintptr_t* stack_top) = 0; 25 }; 26 27 // Abstraction over the stack. Supports handling of: 28 // - native stack; 29 // - SafeStack: https://releases.llvm.org/10.0.0/tools/clang/docs/SafeStack.html PA_COMPONENT_EXPORT(PARTITION_ALLOC)30class PA_COMPONENT_EXPORT(PARTITION_ALLOC) Stack final { 31 public: 32 // Sets start of the stack. 33 explicit Stack(void* stack_top); 34 35 // Word-aligned iteration of the stack. Flushes callee saved registers and 36 // passes the range of the stack on to |visitor|. 37 void IteratePointers(StackVisitor* visitor) const; 38 39 // Returns the top of the stack. 40 void* stack_top() const { return stack_top_; } 41 42 private: 43 void* stack_top_; 44 }; 45 46 } // namespace partition_alloc::internal 47 48 #endif // BASE_ALLOCATOR_PARTITION_ALLOCATOR_STARSCAN_STACK_STACK_H_ 49