| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights
reserved. | 2 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights
reserved. |
| 3 * Copyright (C) 2007 Eric Seidel <eric@webkit.org> | 3 * Copyright (C) 2007 Eric Seidel <eric@webkit.org> |
| 4 * | 4 * |
| 5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
| 6 * modify it under the terms of the GNU Lesser General Public | 6 * modify it under the terms of the GNU Lesser General Public |
| 7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
| 8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
| 9 * | 9 * |
| 10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 | 53 |
| 54 #endif | 54 #endif |
| 55 | 55 |
| 56 namespace WTF { | 56 namespace WTF { |
| 57 | 57 |
| 58 // Bug 26276 - Need a mechanism to determine stack extent | 58 // Bug 26276 - Need a mechanism to determine stack extent |
| 59 // | 59 // |
| 60 // These platforms should now be working correctly: | 60 // These platforms should now be working correctly: |
| 61 // DARWIN, QNX, UNIX | 61 // DARWIN, QNX, UNIX |
| 62 // These platforms are not: | 62 // These platforms are not: |
| 63 // WINDOWS, SOLARIS, OPENBSD, WINCE | 63 // WINDOWS, SOLARIS, OPENBSD |
| 64 // | 64 // |
| 65 // FIXME: remove this! - this code unsafely guesses at stack sizes! | 65 // FIXME: remove this! - this code unsafely guesses at stack sizes! |
| 66 #if OS(WINDOWS) || OS(SOLARIS) || OS(OPENBSD) | 66 #if OS(WINDOWS) || OS(SOLARIS) || OS(OPENBSD) |
| 67 // Based on the current limit used by the JSC parser, guess the stack size. | 67 // Based on the current limit used by the JSC parser, guess the stack size. |
| 68 static const ptrdiff_t estimatedStackSize = 128 * sizeof(void*) * 1024; | 68 static const ptrdiff_t estimatedStackSize = 128 * sizeof(void*) * 1024; |
| 69 // This method assumes the stack is growing downwards. | 69 // This method assumes the stack is growing downwards. |
| 70 static void* estimateStackBound(void* origin) | 70 static void* estimateStackBound(void* origin) |
| 71 { | 71 { |
| 72 return static_cast<char*>(origin) - estimatedStackSize; | 72 return static_cast<char*>(origin) - estimatedStackSize; |
| 73 } | 73 } |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 pthread_getattr_np(thread, &sattr); | 146 pthread_getattr_np(thread, &sattr); |
| 147 #endif | 147 #endif |
| 148 int rc = pthread_attr_getstack(&sattr, &stackBase, &stackSize); | 148 int rc = pthread_attr_getstack(&sattr, &stackBase, &stackSize); |
| 149 (void)rc; // FIXME: Deal with error code somehow? Seems fatal. | 149 (void)rc; // FIXME: Deal with error code somehow? Seems fatal. |
| 150 ASSERT(stackBase); | 150 ASSERT(stackBase); |
| 151 pthread_attr_destroy(&sattr); | 151 pthread_attr_destroy(&sattr); |
| 152 m_bound = stackBase; | 152 m_bound = stackBase; |
| 153 m_origin = static_cast<char*>(stackBase) + stackSize; | 153 m_origin = static_cast<char*>(stackBase) + stackSize; |
| 154 } | 154 } |
| 155 | 155 |
| 156 #elif OS(WINCE) | |
| 157 | |
| 158 static bool detectGrowingDownward(void* previousFrame) | |
| 159 { | |
| 160 // Find the address of this stack frame by taking the address of a local var
iable. | |
| 161 int thisFrame; | |
| 162 return previousFrame > &thisFrame; | |
| 163 } | |
| 164 | |
| 165 static inline bool isPageWritable(void* page) | |
| 166 { | |
| 167 MEMORY_BASIC_INFORMATION memoryInformation; | |
| 168 DWORD result = VirtualQuery(page, &memoryInformation, sizeof(memoryInformati
on)); | |
| 169 | |
| 170 // return false on error, including ptr outside memory | |
| 171 if (result != sizeof(memoryInformation)) | |
| 172 return false; | |
| 173 | |
| 174 DWORD protect = memoryInformation.Protect & ~(PAGE_GUARD | PAGE_NOCACHE); | |
| 175 return protect == PAGE_READWRITE | |
| 176 || protect == PAGE_WRITECOPY | |
| 177 || protect == PAGE_EXECUTE_READWRITE | |
| 178 || protect == PAGE_EXECUTE_WRITECOPY; | |
| 179 } | |
| 180 | |
| 181 static inline void* getLowerStackBound(char* currentPage, DWORD pageSize) | |
| 182 { | |
| 183 while (currentPage > 0) { | |
| 184 // check for underflow | |
| 185 if (currentPage >= reinterpret_cast<char*>(pageSize)) | |
| 186 currentPage -= pageSize; | |
| 187 else | |
| 188 currentPage = 0; | |
| 189 | |
| 190 if (!isPageWritable(currentPage)) | |
| 191 return currentPage + pageSize; | |
| 192 } | |
| 193 | |
| 194 return 0; | |
| 195 } | |
| 196 | |
| 197 static inline void* getUpperStackBound(char* currentPage, DWORD pageSize) | |
| 198 { | |
| 199 do { | |
| 200 // guaranteed to complete because isPageWritable returns false at end of
memory | |
| 201 currentPage += pageSize; | |
| 202 } while (isPageWritable(currentPage)); | |
| 203 | |
| 204 return currentPage - pageSize; | |
| 205 } | |
| 206 | |
| 207 void StackBounds::initialize() | |
| 208 { | |
| 209 // find the address of this stack frame by taking the address of a local var
iable | |
| 210 void* thisFrame = &thisFrame; | |
| 211 bool isGrowingDownward = detectGrowingDownward(thisFrame); | |
| 212 | |
| 213 SYSTEM_INFO systemInfo; | |
| 214 GetSystemInfo(&systemInfo); | |
| 215 DWORD pageSize = systemInfo.dwPageSize; | |
| 216 | |
| 217 // scan all of memory starting from this frame, and return the last writeabl
e page found | |
| 218 char* currentPage = reinterpret_cast<char*>(reinterpret_cast<DWORD>(thisFram
e) & ~(pageSize - 1)); | |
| 219 void* lowerStackBound = getLowerStackBound(currentPage, pageSize); | |
| 220 void* upperStackBound = getUpperStackBound(currentPage, pageSize); | |
| 221 | |
| 222 m_origin = isGrowingDownward ? upperStackBound : lowerStackBound; | |
| 223 m_bound = isGrowingDownward ? lowerStackBound : upperStackBound; | |
| 224 } | |
| 225 | |
| 226 #elif OS(WINDOWS) | 156 #elif OS(WINDOWS) |
| 227 | 157 |
| 228 void StackBounds::initialize() | 158 void StackBounds::initialize() |
| 229 { | 159 { |
| 230 #if CPU(X86) && COMPILER(MSVC) | 160 #if CPU(X86) && COMPILER(MSVC) |
| 231 // offset 0x18 from the FS segment register gives a pointer to | 161 // offset 0x18 from the FS segment register gives a pointer to |
| 232 // the thread information block for the current thread | 162 // the thread information block for the current thread |
| 233 NT_TIB* pTib; | 163 NT_TIB* pTib; |
| 234 __asm { | 164 __asm { |
| 235 MOV EAX, FS:[18h] | 165 MOV EAX, FS:[18h] |
| (...skipping 16 matching lines...) Expand all Loading... |
| 252 #endif | 182 #endif |
| 253 // Looks like we should be able to get pTib->StackLimit | 183 // Looks like we should be able to get pTib->StackLimit |
| 254 m_bound = estimateStackBound(m_origin); | 184 m_bound = estimateStackBound(m_origin); |
| 255 } | 185 } |
| 256 | 186 |
| 257 #else | 187 #else |
| 258 #error Need a way to get the stack bounds on this platform | 188 #error Need a way to get the stack bounds on this platform |
| 259 #endif | 189 #endif |
| 260 | 190 |
| 261 } // namespace WTF | 191 } // namespace WTF |
| OLD | NEW |