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

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

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