| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "platform/heap/StackFrameDepth.h" | 5 #include "platform/heap/StackFrameDepth.h" |
| 6 | 6 |
| 7 #include "public/platform/Platform.h" | 7 #include "public/platform/Platform.h" |
| 8 | 8 |
| 9 #if OS(WIN) | 9 #if OS(WIN) |
| 10 #include <stddef.h> | 10 #include <stddef.h> |
| 11 #include <windows.h> | 11 #include <windows.h> |
| 12 #include <winnt.h> | 12 #include <winnt.h> |
| 13 #elif defined(__GLIBC__) | 13 #elif defined(__GLIBC__) |
| 14 extern "C" void* __libc_stack_end; // NOLINT | 14 extern "C" void* __libc_stack_end; // NOLINT |
| 15 #endif | 15 #endif |
| 16 | 16 |
| 17 namespace blink { | 17 namespace blink { |
| 18 | 18 |
| 19 static const char* s_avoidOptimization = nullptr; | 19 static const char* s_avoidOptimization = nullptr; |
| 20 | 20 |
| 21 uintptr_t StackFrameDepth::s_stackFrameLimit = 0; | 21 uintptr_t StackFrameDepth::s_stackFrameLimit = 0; |
| 22 #if ENABLE(ASSERT) | 22 #if ENABLE(ASSERT) |
| 23 bool StackFrameDepth::s_isEnabled = false; | 23 bool StackFrameDepth::s_isEnabled = false; |
| 24 bool StackFrameDepth::s_isUsingFallbackStackSize = false; |
| 24 #endif | 25 #endif |
| 25 | 26 |
| 26 // NEVER_INLINE ensures that |dummy| array on configureLimit() is not optimized
away, | 27 // NEVER_INLINE ensures that |dummy| array on configureLimit() is not optimized
away, |
| 27 // and the stack frame base register is adjusted |kSafeStackFrameSize|. | 28 // and the stack frame base register is adjusted |kSafeStackFrameSize|. |
| 28 NEVER_INLINE static uintptr_t currentStackFrameBaseOnCallee(const char* dummy) | 29 NEVER_INLINE static uintptr_t currentStackFrameBaseOnCallee(const char* dummy) |
| 29 { | 30 { |
| 30 s_avoidOptimization = dummy; | 31 s_avoidOptimization = dummy; |
| 31 return StackFrameDepth::currentStackFrame(); | 32 return StackFrameDepth::currentStackFrame(); |
| 32 } | 33 } |
| 33 | 34 |
| 34 void StackFrameDepth::enableStackLimit() | 35 void StackFrameDepth::enableStackLimit() |
| 35 { | 36 { |
| 36 #if ENABLE(ASSERT) | 37 #if ENABLE(ASSERT) |
| 37 s_isEnabled = true; | 38 s_isEnabled = true; |
| 39 s_isUsingFallbackStackSize = false; |
| 38 #endif | 40 #endif |
| 39 | 41 |
| 40 static const int kStackRoomSize = 1024; | 42 static const int kStackRoomSize = 1024; |
| 41 | 43 |
| 42 size_t stackSize = getUnderestimatedStackSize(); | 44 size_t stackSize = getUnderestimatedStackSize(); |
| 43 if (stackSize) { | 45 if (stackSize) { |
| 44 Address stackBase = reinterpret_cast<Address>(getStackStart()); | 46 Address stackBase = reinterpret_cast<Address>(getStackStart()); |
| 45 RELEASE_ASSERT(stackSize > static_cast<const size_t>(kStackRoomSize)); | 47 RELEASE_ASSERT(stackSize > static_cast<const size_t>(kStackRoomSize)); |
| 46 size_t stackRoom = stackSize - kStackRoomSize; | 48 size_t stackRoom = stackSize - kStackRoomSize; |
| 47 RELEASE_ASSERT(stackBase > reinterpret_cast<Address>(stackRoom)); | 49 RELEASE_ASSERT(stackBase > reinterpret_cast<Address>(stackRoom)); |
| 48 s_stackFrameLimit = reinterpret_cast<uintptr_t>(stackBase - stackRoom); | 50 s_stackFrameLimit = reinterpret_cast<uintptr_t>(stackBase - stackRoom); |
| 49 return; | 51 return; |
| 50 } | 52 } |
| 51 | 53 |
| 52 // Fallback version | 54 // Fallback version |
| 53 // Allocate a 32KB object on stack and query stack frame base after it. | 55 // Allocate a 32KB object on stack and query stack frame base after it. |
| 54 char dummy[kSafeStackFrameSize]; | 56 char dummy[kSafeStackFrameSize]; |
| 55 s_stackFrameLimit = currentStackFrameBaseOnCallee(dummy); | 57 s_stackFrameLimit = currentStackFrameBaseOnCallee(dummy); |
| 56 | 58 |
| 57 // Assert that the stack frame can be used. | 59 // Assert that the stack frame can be used. |
| 58 dummy[sizeof(dummy) - 1] = 0; | 60 dummy[sizeof(dummy) - 1] = 0; |
| 61 #if ENABLE(ASSERT) |
| 62 // Use a larger stack limit for what's acceptable if the platform |
| 63 // thread ends up using the fallback size to decide if switching to |
| 64 // lazy marking is in order. |
| 65 s_isUsingFallbackStackSize = true; |
| 66 #endif |
| 59 } | 67 } |
| 60 | 68 |
| 61 size_t StackFrameDepth::getUnderestimatedStackSize() | 69 size_t StackFrameDepth::getUnderestimatedStackSize() |
| 62 { | 70 { |
| 63 // FIXME: ASAN bot uses a fake stack as a thread stack frame, | 71 // FIXME: ASAN bot uses a fake stack as a thread stack frame, |
| 64 // and its size is different from the value which APIs tells us. | 72 // and its size is different from the value which APIs tells us. |
| 65 #if defined(ADDRESS_SANITIZER) | 73 #if defined(ADDRESS_SANITIZER) |
| 66 return 0; | 74 return 0; |
| 67 #endif | 75 #endif |
| 68 | 76 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 return reinterpret_cast<void*>(__readgsqword(offsetof(NT_TIB64, StackBase)))
; | 174 return reinterpret_cast<void*>(__readgsqword(offsetof(NT_TIB64, StackBase)))
; |
| 167 #else | 175 #else |
| 168 return reinterpret_cast<void*>(__readfsdword(offsetof(NT_TIB, StackBase))); | 176 return reinterpret_cast<void*>(__readfsdword(offsetof(NT_TIB, StackBase))); |
| 169 #endif | 177 #endif |
| 170 #else | 178 #else |
| 171 #error Unsupported getStackStart on this platform. | 179 #error Unsupported getStackStart on this platform. |
| 172 #endif | 180 #endif |
| 173 } | 181 } |
| 174 | 182 |
| 175 } // namespace blink | 183 } // namespace blink |
| OLD | NEW |