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..9b0250672e57e430d17e90063542d69bcf56df8d 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; |
|
haraken
2015/02/10 12:15:09
Shall we make this a static variable of StackFrame
kouhei (in TOK)
2015/02/10 12:35:38
static const int +1
peria
2015/02/12 02:31:58
Done.
|
| static const char* s_avoidOptimization = nullptr; |
| // NEVER_INLINE ensures that |dummy| array on configureLimit() is not optimized away, |
| @@ -29,21 +30,49 @@ NEVER_INLINE static uintptr_t currentStackFrameBaseOnCallee(const char* dummy) |
| void StackFrameDepth::configureLimit() |
| { |
| - // Allocate a large object in stack and query stack frame pointer after it. |
| + size_t stackSize = getUnderestimatedStackSize(); |
| + if (stackSize) { |
| + size_t stackBase = reinterpret_cast<size_t>(getStackStart()); |
| + m_stackFrameLimit = stackBase - stackSize + kStackRoomSize; |
| + return; |
| + } |
| + |
| + // Fallback version |
| + // Allocate a 32KB object on stack and query stack frame base after it. |
| char dummy[kSafeStackFrameSize]; |
| m_stackFrameLimit = currentStackFrameBaseOnCallee(dummy); |
| // Assert that the stack frame can be used. |
| - dummy[sizeof(dummy) - 1] = 0; |
| + dummy[0] = 0; |
|
haraken
2015/02/10 12:15:09
What is this change for?
kouhei (in TOK)
2015/02/10 12:35:38
To check if the top of the stack is actually writa
peria
2015/02/12 02:31:58
will do in another CL.
|
| } |
| 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. |
| + // We cannot get the stack size on the main thread in these platforms, because |
|
haraken
2015/02/10 12:15:09
Update the comment like:
// pthread_getattr_np()
peria
2015/02/12 02:31:58
Done.
|
| + // pthread_getattr_np() can fail. |
| + // In this case, this method returns 0 and the caller must handle it. |
| + |
| + 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 +86,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 |
| } |