Changeset 151810 in webkit
- Timestamp:
- Jun 20, 2013 4:36:28 PM (11 years ago)
- Location:
- trunk/Source/WTF
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r151800 r151810 1 2013-06-20 Mark Lam <mark.lam@apple.com> 2 3 [Windows] Undoing r150621 to roll r150600 back in as the jsc test 4 failures have been fixed in r151808. 5 https://bugs.webkit.org/show_bug.cgi?id=116661. 6 7 Reviewed by Brent Fulgham. 8 9 * wtf/StackBounds.cpp: 10 (WTF::StackBounds::initialize): 11 1 12 2013-06-20 Mikhail Pozdnyakov <mikhail.pozdnyakov@intel.com> 2 13 -
trunk/Source/WTF/wtf/StackBounds.cpp
r150786 r151810 55 55 56 56 namespace WTF { 57 58 // Bug 26276 - Need a mechanism to determine stack extent59 //60 // These platforms should now be working correctly:61 // DARWIN, OPENBSD, QNX, SOLARIS, UNIX62 // These platforms are not:63 // WINDOWS, WINCE64 //65 // FIXME: remove this! - this code unsafely guesses at stack sizes!66 #if OS(WINDOWS)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 #endif75 57 76 58 #if OS(DARWIN) … … 168 150 } 169 151 170 #elif OS(WINCE) 171 172 static bool detectGrowingDownward(void* previousFrame) 173 { 174 // Find the address of this stack frame by taking the address of a local variable. 175 int thisFrame; 176 return previousFrame > &thisFrame; 177 } 178 179 static inline bool isPageWritable(void* page) 180 { 181 MEMORY_BASIC_INFORMATION memoryInformation; 182 DWORD result = VirtualQuery(page, &memoryInformation, sizeof(memoryInformation)); 183 184 // return false on error, including ptr outside memory 185 if (result != sizeof(memoryInformation)) 186 return false; 187 188 DWORD protect = memoryInformation.Protect & ~(PAGE_GUARD | PAGE_NOCACHE); 189 return protect == PAGE_READWRITE 190 || protect == PAGE_WRITECOPY 191 || protect == PAGE_EXECUTE_READWRITE 192 || protect == PAGE_EXECUTE_WRITECOPY; 193 } 194 195 static inline void* getLowerStackBound(char* currentPage, DWORD pageSize) 196 { 197 while (currentPage > 0) { 198 // check for underflow 199 if (currentPage >= reinterpret_cast<char*>(pageSize)) 200 currentPage -= pageSize; 201 else 202 currentPage = 0; 203 204 if (!isPageWritable(currentPage)) 205 return currentPage + pageSize; 206 } 207 208 return 0; 209 } 210 211 static inline void* getUpperStackBound(char* currentPage, DWORD pageSize) 212 { 213 do { 214 // guaranteed to complete because isPageWritable returns false at end of memory 215 currentPage += pageSize; 216 } while (isPageWritable(currentPage)); 217 218 return currentPage - pageSize; 219 } 152 #elif OS(WINDOWS) 220 153 221 154 void StackBounds::initialize() 222 155 { 223 // find the address of this stack frame by taking the address of a local variable224 void* thisFrame = &thisFrame;225 bool isGrowingDownward = detectGrowingDownward(thisFrame);226 227 156 SYSTEM_INFO systemInfo; 228 157 GetSystemInfo(&systemInfo); 229 158 DWORD pageSize = systemInfo.dwPageSize; 230 159 231 // scan all of memory starting from this frame, and return the last writeable page found 232 char* currentPage = reinterpret_cast<char*>(reinterpret_cast<DWORD>(thisFrame) & ~(pageSize - 1)); 233 void* lowerStackBound = getLowerStackBound(currentPage, pageSize); 234 void* upperStackBound = getUpperStackBound(currentPage, pageSize); 160 MEMORY_BASIC_INFORMATION stackOrigin; 161 VirtualQuery(&stackOrigin, &stackOrigin, sizeof(stackOrigin)); 162 // stackOrigin.AllocationBase points to the reserved stack memory base address. 235 163 236 m_origin = isGrowingDownward ? upperStackBound : lowerStackBound; 237 m_bound = isGrowingDownward ? lowerStackBound : upperStackBound; 238 } 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)); 239 168 240 #elif OS(WINDOWS) 169 m_bound = static_cast<char*>(m_origin) - stackMemory.RegionSize + pageSize; 170 #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. 241 174 242 void StackBounds::initialize() 243 { 244 #if CPU(X86) && COMPILER(MSVC) 245 // offset 0x18 from the FS segment register gives a pointer to 246 // the thread information block for the current thread 247 NT_TIB* pTib; 248 __asm { 249 MOV EAX, FS:[18h] 250 MOV pTib, EAX 251 } 252 m_origin = static_cast<void*>(pTib->StackBase); 253 #elif CPU(X86) && COMPILER(GCC) 254 // offset 0x18 from the FS segment register gives a pointer to 255 // the thread information block for the current thread 256 NT_TIB* pTib; 257 asm ( "movl %%fs:0x18, %0\n" 258 : "=r" (pTib) 259 ); 260 m_origin = static_cast<void*>(pTib->StackBase); 261 #elif CPU(X86_64) 262 PNT_TIB64 pTib = reinterpret_cast<PNT_TIB64>(NtCurrentTeb()); 263 m_origin = reinterpret_cast<void*>(pTib->StackBase); 264 #else 265 #error Need a way to get the stack bounds on this platform (Windows) 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; 266 191 #endif 267 // Looks like we should be able to get pTib->StackLimit268 m_bound = estimateStackBound(m_origin);269 192 } 270 193
Note: See TracChangeset
for help on using the changeset viewer.