Chromium Code Reviews| Index: Source/platform/heap/StackFrameDepth.cpp |
| diff --git a/Source/platform/heap/StackFrameDepth.cpp b/Source/platform/heap/StackFrameDepth.cpp |
| index 2d7985a1d3bf9fd1d72f07cb50a8673e3ff6c5eb..76790d4fe65f8c425ab55ff215eb7e9678aca07f 100644 |
| --- a/Source/platform/heap/StackFrameDepth.cpp |
| +++ b/Source/platform/heap/StackFrameDepth.cpp |
| @@ -17,6 +17,7 @@ extern "C" void* __libc_stack_end; // NOLINT |
| namespace blink { |
| +const int StackFrameDepth::kStackRoomSize = 1024; |
| static const char* s_avoidOptimization = nullptr; |
| // NEVER_INLINE ensures that |dummy| array on configureLimit() is not optimized away, |
| @@ -29,6 +30,13 @@ NEVER_INLINE static uintptr_t currentStackFrameBaseOnCallee(const char* dummy) |
| void StackFrameDepth::configureLimit() |
|
haraken
2015/02/10 08:53:22
Can we avoid calling getUnderestimatedStackSize()
peria
2015/02/10 12:05:29
The instance of StackFrameDepth is globally unique
|
| { |
| + size_t stackSize = getUnderestimatedStackSize(); |
|
haraken
2015/02/10 08:53:22
Note: You can add RELEASE_ASSERT(stackSize >= 128
peria
2015/02/10 12:05:28
Acknowledged.
haraken
2015/02/10 12:15:09
Would you try this before landing this CL? We migh
peria
2015/02/12 02:31:58
Trying in https://codereview.chromium.org/91888300
|
| + if (stackSize) { |
| + m_stackFrameLimit = reinterpret_cast<uintptr_t>(getStackStart()) - stackSize + kStackRoomSize; |
| + return; |
| + } |
| + |
| + // Fallback version |
| // Allocate a large object in stack and query stack frame pointer after it. |
| char dummy[kSafeStackFrameSize]; |
| m_stackFrameLimit = currentStackFrameBaseOnCallee(dummy); |
| @@ -40,10 +48,26 @@ void StackFrameDepth::configureLimit() |
| size_t StackFrameDepth::getUnderestimatedStackSize() |
| { |
| #if defined(__GLIBC__) || OS(ANDROID) || OS(FREEBSD) |
| - // We cannot get the stack size in these platforms because |
| - // pthread_getattr_np() can fail for the main thread. |
| - // This is OK because ThreadState::current() doesn't use the stack size |
| - // in these platforms. |
|
haraken
2015/02/10 08:53:22
Update this comment instead of removing.
peria
2015/02/10 12:05:28
Done.
|
| + pthread_attr_t attr; |
| + int error; |
| +#if OS(FREEBSD) |
| + pthread_attr_init(&attr); |
| + error = pthread_attr_get_np(pthread_self(), &attr); |
| +#else |
| + error = pthread_getattr_np(pthread_self(), &attr); |
| +#endif |
| + if (!error) { |
| + void* base; |
| + size_t size; |
| + error = pthread_attr_getstack(&attr, &base, &size); |
| + RELEASE_ASSERT(!error); |
| + pthread_attr_destroy(&attr); |
| + return size; |
| + } |
| +#if OS(FREEBSD) |
| + pthread_attr_destroy(&attr); |
| +#endif |
| + |
| return 0; |
| #elif OS(MACOSX) |
| return pthread_get_stacksize_np(pthread_self()); |
| @@ -57,6 +81,7 @@ size_t StackFrameDepth::getUnderestimatedStackSize() |
| return __readfsdword(offsetof(NT_TIB, StackBase)) - __readfsdword(offsetof(NT_TIB, StackLimit)); |
| #endif |
| #else |
| +#error "Stack frame size estimation not supported on this platform." |
| return 0; |
| #endif |
| } |