1 // Copyright 2020 the V8 project 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 V8_HEAP_BASE_STACK_H_ 6 #define V8_HEAP_BASE_STACK_H_ 7 8 #include "src/base/macros.h" 9 10 namespace heap { 11 namespace base { 12 13 class StackVisitor { 14 public: 15 virtual void VisitPointer(const void* address) = 0; 16 }; 17 18 // Abstraction over the stack. Supports handling of: 19 // - native stack; 20 // - ASAN/MSAN; 21 // - SafeStack: https://releases.llvm.org/10.0.0/tools/clang/docs/SafeStack.html 22 class V8_EXPORT_PRIVATE Stack final { 23 public: 24 explicit Stack(const void* stack_start); 25 26 // Returns true if |slot| is part of the stack and false otherwise. 27 bool IsOnStack(void* slot) const; 28 29 // Word-aligned iteration of the stack. Slot values are passed on to 30 // |visitor|. 31 void IteratePointers(StackVisitor* visitor) const; 32 33 // Returns the start of the stack. stack_start()34 const void* stack_start() const { return stack_start_; } 35 36 private: 37 const void* stack_start_; 38 }; 39 40 } // namespace base 41 } // namespace heap 42 43 #endif // V8_HEAP_BASE_STACK_H_ 44