• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 = nullptr);
25 
26   // Sets the start of the stack.
27   void SetStackStart(const void* stack_start);
28 
29   // Returns true if |slot| is part of the stack and false otherwise.
30   bool IsOnStack(void* slot) const;
31 
32   // Word-aligned iteration of the stack. Callee-saved registers are pushed to
33   // the stack before iterating pointers. Slot values are passed on to
34   // `visitor`.
35   void IteratePointers(StackVisitor* visitor) const;
36 
37   // Word-aligned iteration of the stack, starting at `stack_end`. Slot values
38   // are passed on to `visitor`. This is intended to be used with verifiers that
39   // only visit a subset of the stack of IteratePointers().
40   //
41   // **Ignores:**
42   // - Callee-saved registers.
43   // - SafeStack.
44   void IteratePointersUnsafe(StackVisitor* visitor, uintptr_t stack_end) const;
45 
46   // Returns the start of the stack.
stack_start()47   const void* stack_start() const { return stack_start_; }
48 
49   // Get the current stack pointer for the stack, on which local variables are
50   // stored. In case the safe-stack is enabled (-fsanitize=safe-stack), this
51   // will return the stack pointer for the unsafe-stack. Otherwise, the function
52   // returns the stack pointer for the native stack.
53   static const void* GetCurrentStackPointerForLocalVariables();
54 
55  private:
56   const void* stack_start_;
57 };
58 
59 }  // namespace base
60 }  // namespace heap
61 
62 #endif  // V8_HEAP_BASE_STACK_H_
63