Changeset 150621 in webkit
- Timestamp:
- May 23, 2013 6:33:04 PM (11 years ago)
- Location:
- trunk/Source/WTF
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r150603 r150621 1 2013-05-23 Brent Fulgham <bfulgham@apple.com> 2 3 [Windows] Rolling back r150600 as it breaks the VS2010 builds. 4 5 * wtf/StackBounds.cpp: Rollback. 6 1 7 2013-05-23 Patrick Gansterer <paroga@webkit.org> 2 8 -
trunk/Source/WTF/wtf/StackBounds.cpp
r150603 r150621 55 55 56 56 namespace WTF { 57 58 // Bug 26276 - Need a mechanism to determine stack extent 59 // 60 // These platforms should now be working correctly: 61 // DARWIN, QNX, UNIX 62 // These platforms are not: 63 // WINDOWS, SOLARIS, OPENBSD, WINCE 64 // 65 // FIXME: remove this! - this code unsafely guesses at stack sizes! 66 #if OS(WINDOWS) || OS(SOLARIS) || OS(OPENBSD) 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; 69 // This method assumes the stack is growing downwards. 70 static void* estimateStackBound(void* origin) 71 { 72 return static_cast<char*>(origin) - estimatedStackSize; 73 } 74 #endif 57 75 58 76 #if OS(DARWIN) … … 107 125 thr_stksegment(&s); 108 126 m_origin = s.ss_sp; 109 m_bound = static_cast<char*>(m_origin) - s.ss_size;127 m_bound = estimateStackBound(m_origin); 110 128 } 111 129 … … 118 136 pthread_stackseg_np(thread, &stack); 119 137 m_origin = stack.ss_sp; 120 #if CPU(HPPA) 121 m_bound = static_cast<char*>(m_origin) + stack.ss_size; 122 #else 123 m_bound = static_cast<char*>(m_origin) - stack.ss_size; 124 #endif 138 m_bound = estimateStackBound(m_origin); 125 139 } 126 140 … … 150 164 } 151 165 152 #elif OS(WINDOWS) 153 154 void StackBounds::initialize() 155 { 166 #elif OS(WINCE) 167 168 static bool detectGrowingDownward(void* previousFrame) 169 { 170 // Find the address of this stack frame by taking the address of a local variable. 171 int thisFrame; 172 return previousFrame > &thisFrame; 173 } 174 175 static inline bool isPageWritable(void* page) 176 { 177 MEMORY_BASIC_INFORMATION memoryInformation; 178 DWORD result = VirtualQuery(page, &memoryInformation, sizeof(memoryInformation)); 179 180 // return false on error, including ptr outside memory 181 if (result != sizeof(memoryInformation)) 182 return false; 183 184 DWORD protect = memoryInformation.Protect & ~(PAGE_GUARD | PAGE_NOCACHE); 185 return protect == PAGE_READWRITE 186 || protect == PAGE_WRITECOPY 187 || protect == PAGE_EXECUTE_READWRITE 188 || protect == PAGE_EXECUTE_WRITECOPY; 189 } 190 191 static inline void* getLowerStackBound(char* currentPage, DWORD pageSize) 192 { 193 while (currentPage > 0) { 194 // check for underflow 195 if (currentPage >= reinterpret_cast<char*>(pageSize)) 196 currentPage -= pageSize; 197 else 198 currentPage = 0; 199 200 if (!isPageWritable(currentPage)) 201 return currentPage + pageSize; 202 } 203 204 return 0; 205 } 206 207 static inline void* getUpperStackBound(char* currentPage, DWORD pageSize) 208 { 209 do { 210 // guaranteed to complete because isPageWritable returns false at end of memory 211 currentPage += pageSize; 212 } while (isPageWritable(currentPage)); 213 214 return currentPage - pageSize; 215 } 216 217 void StackBounds::initialize() 218 { 219 // find the address of this stack frame by taking the address of a local variable 220 void* thisFrame = &thisFrame; 221 bool isGrowingDownward = detectGrowingDownward(thisFrame); 222 156 223 SYSTEM_INFO systemInfo; 157 224 GetSystemInfo(&systemInfo); 158 225 DWORD pageSize = systemInfo.dwPageSize; 159 226 160 MEMORY_BASIC_INFORMATION stackOrigin; 161 VirtualQuery(&stackOrigin, &stackOrigin, sizeof(stackOrigin)); 162 // stackOrigin.AllocationBase points to the reserved stack memory base address. 163 164 m_origin = static_cast<char*>(stackOrigin.BaseAddress) + stackOrigin.RegionSize; 165 #if OS(WINCE) 166 MEMORY_BASIC_INFORMATION stackMemory; 167 VirtualQuery(m_origin, &stackMemory, sizeof(stackMemory)); 168 169 m_bound = static_cast<char*>(m_origin) - stackMemory.RegionSize + pageSize; 227 // scan all of memory starting from this frame, and return the last writeable page found 228 char* currentPage = reinterpret_cast<char*>(reinterpret_cast<DWORD>(thisFrame) & ~(pageSize - 1)); 229 void* lowerStackBound = getLowerStackBound(currentPage, pageSize); 230 void* upperStackBound = getUpperStackBound(currentPage, pageSize); 231 232 m_origin = isGrowingDownward ? upperStackBound : lowerStackBound; 233 m_bound = isGrowingDownward ? lowerStackBound : upperStackBound; 234 } 235 236 #elif OS(WINDOWS) 237 238 void StackBounds::initialize() 239 { 240 #if CPU(X86) && COMPILER(MSVC) 241 // offset 0x18 from the FS segment register gives a pointer to 242 // the thread information block for the current thread 243 NT_TIB* pTib; 244 __asm { 245 MOV EAX, FS:[18h] 246 MOV pTib, EAX 247 } 248 m_origin = static_cast<void*>(pTib->StackBase); 249 #elif CPU(X86) && COMPILER(GCC) 250 // offset 0x18 from the FS segment register gives a pointer to 251 // the thread information block for the current thread 252 NT_TIB* pTib; 253 asm ( "movl %%fs:0x18, %0\n" 254 : "=r" (pTib) 255 ); 256 m_origin = static_cast<void*>(pTib->StackBase); 257 #elif CPU(X86_64) 258 PNT_TIB64 pTib = reinterpret_cast<PNT_TIB64>(NtCurrentTeb()); 259 m_origin = reinterpret_cast<void*>(pTib->StackBase); 170 260 #else 171 // The stack on Windows consists out of three parts (reserved memory, a guard page and initially committed memory), 172 // which need to me queried seperately to get the full size of the stack. 173 // See http://msdn.microsoft.com/en-us/library/ms686774%28VS.85%29.aspx for more information. 174 175 MEMORY_BASIC_INFORMATION reservedMemory; 176 VirtualQuery(stackOrigin.AllocationBase, &reservedMemory, sizeof(reservedMemory)); 177 ASSERT(reservedMemory.State == MEM_RESERVE); 178 // reservedMemory.BaseAddress and reservedMemory.RegionSize describe reserved (uncommitted) portion of the stack. 179 180 MEMORY_BASIC_INFORMATION guardPage; 181 VirtualQuery(static_cast<char*>(reservedMemory.BaseAddress) + reservedMemory.RegionSize, &guardPage, sizeof(guardPage)); 182 ASSERT(guardPage.Protect & PAGE_GUARD); 183 // guardPage.BaseAddress and guardPage.RegionSize describe the guard page. 184 185 MEMORY_BASIC_INFORMATION committedMemory; 186 VirtualQuery(static_cast<char*>(guardPage.BaseAddress) + guardPage.RegionSize, &committedMemory, sizeof(committedMemory)); 187 ASSERT(committedMemory.State == MEM_COMMIT); 188 // committedMemory.BaseAddress, committedMemory.RegionSize describe the committed (i.e. accessed) portion of the stack. 189 190 m_bound = static_cast<char*>(m_origin) - (reservedMemory.RegionSize - guardPage.RegionSize + committedMemory.RegionSize) + pageSize; 191 #endif 261 #error Need a way to get the stack bounds on this platform (Windows) 262 #endif 263 // Looks like we should be able to get pTib->StackLimit 264 m_bound = estimateStackBound(m_origin); 192 265 } 193 266
Note: See TracChangeset
for help on using the changeset viewer.