Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: third_party/WebKit/Source/platform/heap/StackFrameDepth.cpp

Issue 2304023003: StackFrameDepth should be managed per ThreadHeap (Closed)
Patch Set: revert to PS1 Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 = kMinimumStackLimit;
22
23 // NEVER_INLINE ensures that |dummy| array on configureLimit() is not optimized away, 21 // NEVER_INLINE ensures that |dummy| array on configureLimit() is not optimized away,
24 // and the stack frame base register is adjusted |kSafeStackFrameSize|. 22 // and the stack frame base register is adjusted |kSafeStackFrameSize|.
25 NEVER_INLINE static uintptr_t currentStackFrameBaseOnCallee(const char* dummy) 23 NEVER_INLINE static uintptr_t currentStackFrameBaseOnCallee(const char* dummy)
26 { 24 {
27 s_avoidOptimization = dummy; 25 s_avoidOptimization = dummy;
28 return StackFrameDepth::currentStackFrame(); 26 return StackFrameDepth::currentStackFrame();
29 } 27 }
30 28
31 uintptr_t StackFrameDepth::getFallbackStackLimit() 29 uintptr_t StackFrameDepth::getFallbackStackLimit()
32 { 30 {
33 // Allocate an |kSafeStackFrameSize|-sized object on stack and query 31 // Allocate an |kSafeStackFrameSize|-sized object on stack and query
34 // stack frame base after it. 32 // stack frame base after it.
35 char dummy[kSafeStackFrameSize]; 33 char dummy[kSafeStackFrameSize];
36 34
37 // Check that the stack frame can be used. 35 // Check that the stack frame can be used.
38 dummy[sizeof(dummy) - 1] = 0; 36 dummy[sizeof(dummy) - 1] = 0;
39 return currentStackFrameBaseOnCallee(dummy); 37 return currentStackFrameBaseOnCallee(dummy);
40 } 38 }
41 39
42 void StackFrameDepth::enableStackLimit() 40 void StackFrameDepth::enableStackLimit()
43 { 41 {
44 // All supported platforms will currently return a non-zero estimate, 42 // All supported platforms will currently return a non-zero estimate,
45 // except if ASan is enabled. 43 // except if ASan is enabled.
46 size_t stackSize = getUnderestimatedStackSize(); 44 size_t stackSize = getUnderestimatedStackSize();
47 if (!stackSize) { 45 if (!stackSize) {
48 s_stackFrameLimit = getFallbackStackLimit(); 46 m_stackFrameLimit = getFallbackStackLimit();
49 return; 47 return;
50 } 48 }
51 49
52 static const int kStackRoomSize = 1024; 50 static const int kStackRoomSize = 1024;
53 51
54 Address stackBase = reinterpret_cast<Address>(getStackStart()); 52 Address stackBase = reinterpret_cast<Address>(getStackStart());
55 RELEASE_ASSERT(stackSize > static_cast<const size_t>(kStackRoomSize)); 53 RELEASE_ASSERT(stackSize > static_cast<const size_t>(kStackRoomSize));
56 size_t stackRoom = stackSize - kStackRoomSize; 54 size_t stackRoom = stackSize - kStackRoomSize;
57 RELEASE_ASSERT(stackBase > reinterpret_cast<Address>(stackRoom)); 55 RELEASE_ASSERT(stackBase > reinterpret_cast<Address>(stackRoom));
58 s_stackFrameLimit = reinterpret_cast<uintptr_t>(stackBase - stackRoom); 56 m_stackFrameLimit = reinterpret_cast<uintptr_t>(stackBase - stackRoom);
59 57
60 // If current stack use is already exceeding estimated limit, mark as disabl ed. 58 // If current stack use is already exceeding estimated limit, mark as disabl ed.
61 if (!isSafeToRecurse()) 59 if (!isSafeToRecurse())
62 disableStackLimit(); 60 disableStackLimit();
63 } 61 }
64 62
65 size_t StackFrameDepth::getUnderestimatedStackSize() 63 size_t StackFrameDepth::getUnderestimatedStackSize()
66 { 64 {
67 // FIXME: ASAN bot uses a fake stack as a thread stack frame, 65 // FIXME: ASAN bot uses a fake stack as a thread stack frame,
68 // and its size is different from the value which APIs tells us. 66 // and its size is different from the value which APIs tells us.
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 return reinterpret_cast<void*>(__readgsqword(offsetof(NT_TIB64, StackBase))) ; 173 return reinterpret_cast<void*>(__readgsqword(offsetof(NT_TIB64, StackBase))) ;
176 #else 174 #else
177 return reinterpret_cast<void*>(__readfsdword(offsetof(NT_TIB, StackBase))); 175 return reinterpret_cast<void*>(__readfsdword(offsetof(NT_TIB, StackBase)));
178 #endif 176 #endif
179 #else 177 #else
180 #error Unsupported getStackStart on this platform. 178 #error Unsupported getStackStart on this platform.
181 #endif 179 #endif
182 } 180 }
183 181
184 } // namespace blink 182 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/heap/StackFrameDepth.h ('k') | third_party/WebKit/Source/platform/heap/TraceTraits.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698