Index: Source/platform/heap/ThreadState.cpp |
diff --git a/Source/platform/heap/ThreadState.cpp b/Source/platform/heap/ThreadState.cpp |
index 0f9ad60c7a86af4e5bbdbb5d69f936234ae0bcf6..78f5fb927742f93eeaa91a5e23b8c6111d14a561 100644 |
--- a/Source/platform/heap/ThreadState.cpp |
+++ b/Source/platform/heap/ThreadState.cpp |
@@ -110,11 +110,37 @@ static void* getStackStart() |
#endif |
} |
+static size_t getStackSize() |
+{ |
+#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. |
+ // It is OK to return 0 because ThreadState::current() doesn't use |
+ // the stack size in these platforms. |
+ return 0; |
+#elif OS(MACOSX) |
+ return pthread_get_stacksize_np(pthread_self()); |
+#elif OS(WIN) && COMPILER(MSVC) |
+ // On Windows stack limits for the current thread are available in |
+ // the thread information block (TIB). Its fields can be accessed through |
+ // FS segment register on x86 and GS segment register on x86_64. |
+#ifdef _WIN64 |
+ return __readgsqword(offsetof(NT_TIB64, StackBase)) - __readgsqword(offsetof(NT_TIB64, StackLimit)); |
sof
2014/10/12 08:09:23
Does this account for stack usage&sizes exceeding
haraken
2014/10/12 08:45:49
I don't know if the StackLimit grows up dynamicall
sof
2014/10/12 11:39:16
Yes, if the initial commit is 1M, then calling cur
|
+#else |
+ return __readfsdword(offsetof(NT_TIB, StackBase)) - __readfsdword(offsetof(NT_TIB, StackLimit)); |
+#endif |
+#else |
+#error Unsupported getStackSize on this platform. |
+#endif |
+} |
+ |
// The maximum number of WrapperPersistentRegions to keep around in the |
// m_pooledWrapperPersistentRegions pool. |
static const size_t MaxPooledWrapperPersistentRegionCount = 2; |
WTF::ThreadSpecific<ThreadState*>* ThreadState::s_threadSpecific = 0; |
+intptr_t ThreadState::s_mainThreadStackStart = 0; |
+intptr_t ThreadState::s_mainThreadStackSize = 0; |
uint8_t ThreadState::s_mainThreadStateStorage[sizeof(ThreadState)]; |
SafePointBarrier* ThreadState::s_safePointBarrier = 0; |
bool ThreadState::s_inGC = false; |
@@ -325,6 +351,11 @@ ThreadState::ThreadState() |
ASSERT(!**s_threadSpecific); |
**s_threadSpecific = this; |
+ if (isMainThread()) { |
+ s_mainThreadStackStart = reinterpret_cast<intptr_t>(m_startOfStack); |
+ s_mainThreadStackSize = getStackSize(); |
+ } |
+ |
InitializeHeaps<NumberOfHeaps>::init(m_heaps, this); |
m_weakCallbackStack = new CallbackStack(); |