Title: [151817] trunk/Source/WTF
Revision
151817
Author
[email protected]
Date
2013-06-20 19:49:26 -0700 (Thu, 20 Jun 2013)

Log Message

Refine the StackBounds computation for Windows.
https://bugs.webkit.org/show_bug.cgi?id=117854.

Reviewed by Brent Fulgham.

* wtf/StackBounds.cpp:
(WTF::StackBounds::initialize):

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (151816 => 151817)


--- trunk/Source/WTF/ChangeLog	2013-06-21 02:29:47 UTC (rev 151816)
+++ trunk/Source/WTF/ChangeLog	2013-06-21 02:49:26 UTC (rev 151817)
@@ -1,5 +1,15 @@
 2013-06-20  Mark Lam  <[email protected]>
 
+        Refine the StackBounds computation for Windows.
+        https://bugs.webkit.org/show_bug.cgi?id=117854.
+
+        Reviewed by Brent Fulgham.
+
+        * wtf/StackBounds.cpp:
+        (WTF::StackBounds::initialize):
+
+2013-06-20  Mark Lam  <[email protected]>
+
         [Windows] Undoing r150621 to roll r150600 back in as the jsc test
         failures have been fixed in r151808.
         https://bugs.webkit.org/show_bug.cgi?id=116661.

Modified: trunk/Source/WTF/wtf/StackBounds.cpp (151816 => 151817)


--- trunk/Source/WTF/wtf/StackBounds.cpp	2013-06-21 02:29:47 UTC (rev 151816)
+++ trunk/Source/WTF/wtf/StackBounds.cpp	2013-06-21 02:49:26 UTC (rev 151817)
@@ -153,42 +153,61 @@
 
 void StackBounds::initialize()
 {
-    SYSTEM_INFO systemInfo;
-    GetSystemInfo(&systemInfo);
-    DWORD pageSize = systemInfo.dwPageSize;
-
     MEMORY_BASIC_INFORMATION stackOrigin;
     VirtualQuery(&stackOrigin, &stackOrigin, sizeof(stackOrigin));
     // stackOrigin.AllocationBase points to the reserved stack memory base address.
 
     m_origin = static_cast<char*>(stackOrigin.BaseAddress) + stackOrigin.RegionSize;
 #if OS(WINCE)
+    SYSTEM_INFO systemInfo;
+    GetSystemInfo(&systemInfo);
+    DWORD pageSize = systemInfo.dwPageSize;
+
     MEMORY_BASIC_INFORMATION stackMemory;
     VirtualQuery(m_origin, &stackMemory, sizeof(stackMemory));
 
     m_bound = static_cast<char*>(m_origin) - stackMemory.RegionSize + pageSize;
 #else
-    // The stack on Windows consists out of three parts (reserved memory, a guard page and initially committed memory),
-    // which need to me queried seperately to get the full size of the stack.
+    // The stack on Windows consists out of three parts (uncommitted memory, a guard page and present
+    // committed memory). The 3 regions have different BaseAddresses but all have the same AllocationBase
+    // since they are all from the same VirtualAlloc. The 3 regions are laid out in memory (from high to
+    // low) as follows:
+    //
+    //    High |-------------------|  -----
+    //         | committedMemory   |    ^
+    //         |-------------------|    |
+    //         | guardPage         | reserved memory for the stack
+    //         |-------------------|    |
+    //         | uncommittedMemory |    v
+    //    Low  |-------------------|  ----- <--- stackOrigin.AllocationBase
+    //
     // See http://msdn.microsoft.com/en-us/library/ms686774%28VS.85%29.aspx for more information.
 
-    MEMORY_BASIC_INFORMATION reservedMemory;
-    VirtualQuery(stackOrigin.AllocationBase, &reservedMemory, sizeof(reservedMemory));
-    ASSERT(reservedMemory.State == MEM_RESERVE);
-    // reservedMemory.BaseAddress and reservedMemory.RegionSize describe reserved (uncommitted) portion of the stack.
+    MEMORY_BASIC_INFORMATION uncommittedMemory;
+    VirtualQuery(stackOrigin.AllocationBase, &uncommittedMemory, sizeof(uncommittedMemory));
+    ASSERT(uncommittedMemory.State == MEM_RESERVE);
 
     MEMORY_BASIC_INFORMATION guardPage;
-    VirtualQuery(static_cast<char*>(reservedMemory.BaseAddress) + reservedMemory.RegionSize, &guardPage, sizeof(guardPage));
+    VirtualQuery(static_cast<char*>(uncommittedMemory.BaseAddress) + uncommittedMemory.RegionSize, &guardPage, sizeof(guardPage));
     ASSERT(guardPage.Protect & PAGE_GUARD);
-    // guardPage.BaseAddress and guardPage.RegionSize describe the guard page.
 
+    void* endOfStack = stackOrigin.AllocationBase;
+
+#ifndef NDEBUG
     MEMORY_BASIC_INFORMATION committedMemory;
     VirtualQuery(static_cast<char*>(guardPage.BaseAddress) + guardPage.RegionSize, &committedMemory, sizeof(committedMemory));
     ASSERT(committedMemory.State == MEM_COMMIT);
-    // committedMemory.BaseAddress, committedMemory.RegionSize describe the committed (i.e. accessed) portion of the stack.
 
-    m_bound = static_cast<char*>(m_origin) - (reservedMemory.RegionSize - guardPage.RegionSize + committedMemory.RegionSize) + pageSize;
-#endif
+    void* computedEnd = static_cast<char*>(m_origin) - (uncommittedMemory.RegionSize + guardPage.RegionSize + committedMemory.RegionSize);
+
+    ASSERT(stackOrigin.AllocationBase == uncommittedMemory.AllocationBase);
+    ASSERT(stackOrigin.AllocationBase == guardPage.AllocationBase);
+    ASSERT(stackOrigin.AllocationBase == committedMemory.AllocationBase);
+    ASSERT(stackOrigin.AllocationBase == uncommittedMemory.BaseAddress);
+    ASSERT(endOfStack == computedEnd);
+#endif // NDEBUG
+    m_bound = static_cast<char*>(endOfStack) + guardPage.RegionSize;
+#endif // OS(WINCE)
 }
 
 #else
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to