| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 The Chromium 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 StackFrameDepth_h | |
| 6 #define StackFrameDepth_h | |
| 7 | |
| 8 #include "platform/PlatformExport.h" | |
| 9 #include "wtf/Assertions.h" | |
| 10 #include <stdint.h> | |
| 11 | |
| 12 namespace blink { | |
| 13 | |
| 14 // StackFrameDepth keeps track of current call stack frame depth. | |
| 15 // Use isSafeToRecurse() to query if there is a room in current | |
| 16 // call stack for more recursive call. | |
| 17 class PLATFORM_EXPORT StackFrameDepth final { | |
| 18 public: | |
| 19 inline bool isSafeToRecurse() | |
| 20 { | |
| 21 ASSERT(m_stackFrameLimit); | |
| 22 | |
| 23 // Below comparison assumes callstack to glow downward, | |
| 24 // which is true for all ABI Blink currently supports. | |
| 25 return currentStackFrame() > m_stackFrameLimit; | |
| 26 } | |
| 27 | |
| 28 static uintptr_t currentStackFrame(const char* dummy = nullptr) | |
| 29 { | |
| 30 #if COMPILER(GCC) | |
| 31 return reinterpret_cast<uintptr_t>(__builtin_frame_address(0)); | |
| 32 #elif COMPILER(MSVC) | |
| 33 return reinterpret_cast<uintptr_t>(&dummy) - sizeof(void*); | |
| 34 #else | |
| 35 #error "Stack frame pointer estimation not supported on this platform." | |
| 36 return 0; | |
| 37 #endif | |
| 38 } | |
| 39 | |
| 40 void configureLimit(); | |
| 41 | |
| 42 private: | |
| 43 // The maximum depth of eager, unrolled trace() calls that is | |
| 44 // considered safe and allowed. | |
| 45 static const int kSafeStackFrameSize = 32 * 1024; | |
| 46 | |
| 47 uintptr_t m_stackFrameLimit; | |
| 48 }; | |
| 49 | |
| 50 } // namespace blink | |
| 51 | |
| 52 #endif // StackFrameDepth_h | |
| OLD | NEW |