Title: [155226] trunk/Source/WebCore
Revision
155226
Author
[email protected]
Date
2013-09-06 16:46:01 -0700 (Fri, 06 Sep 2013)

Log Message

[Windows] StructuredExceptionHandlerSuppressor Causes Bad Interactions with Support Libraries
https://bugs.webkit.org/show_bug.cgi?id=120901

Reviewed by Anders Carlsson.

Change from old "crash on any exception" implementation to a new version that leaves normal
exception handling infrastructure in place for use by support libraries. We check exceptions
and decide whether to abort or not based on the failure type.

* WebCore.vcxproj/WebCore.vcxproj: Add new implementation files.
* WebCore.vcxproj/WebCore.vcxproj.filters: Ditto.
* platform/graphics/ca/win/LayerChangesFlusher.cpp:
(WebCore::LayerChangesFlusher::hookCallback): Allocate handler struct on stack.
* platform/win/StructuredExceptionHandlerSuppressor.cpp: Added.
(exceptionShouldTerminateProgram): New.
(exceptionHandler): New.
(WebCore::StructuredExceptionHandlerSuppressor::StructuredExceptionHandlerSuppressor): Moved
from header, and updated to add our new exception handler.
(WebCore::StructuredExceptionHandlerSuppressor::~StructuredExceptionHandlerSuppressor): Moved
from header.
* platform/win/StructuredExceptionHandlerSuppressor.h: Move implementation of constructor and
destructor from header file.
* platform/win/makesafeseh.asm: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (155225 => 155226)


--- trunk/Source/WebCore/ChangeLog	2013-09-06 23:38:29 UTC (rev 155225)
+++ trunk/Source/WebCore/ChangeLog	2013-09-06 23:46:01 UTC (rev 155226)
@@ -1,3 +1,29 @@
+2013-09-06  Brent Fulgham  <[email protected]>
+
+        [Windows] StructuredExceptionHandlerSuppressor Causes Bad Interactions with Support Libraries
+        https://bugs.webkit.org/show_bug.cgi?id=120901
+
+        Reviewed by Anders Carlsson.
+
+        Change from old "crash on any exception" implementation to a new version that leaves normal
+        exception handling infrastructure in place for use by support libraries. We check exceptions
+        and decide whether to abort or not based on the failure type.
+
+        * WebCore.vcxproj/WebCore.vcxproj: Add new implementation files.
+        * WebCore.vcxproj/WebCore.vcxproj.filters: Ditto.
+        * platform/graphics/ca/win/LayerChangesFlusher.cpp:
+        (WebCore::LayerChangesFlusher::hookCallback): Allocate handler struct on stack.
+        * platform/win/StructuredExceptionHandlerSuppressor.cpp: Added.
+        (exceptionShouldTerminateProgram): New.
+        (exceptionHandler): New.
+        (WebCore::StructuredExceptionHandlerSuppressor::StructuredExceptionHandlerSuppressor): Moved
+        from header, and updated to add our new exception handler.
+        (WebCore::StructuredExceptionHandlerSuppressor::~StructuredExceptionHandlerSuppressor): Moved
+        from header.
+        * platform/win/StructuredExceptionHandlerSuppressor.h: Move implementation of constructor and
+        destructor from header file.
+        * platform/win/makesafeseh.asm: Added.
+
 2013-09-06  Vivek Galatage  <[email protected]>
 
         Refactor XMLDocumentParser to defer creation of XMLErrors until error occurs

Modified: trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj (155225 => 155226)


--- trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj	2013-09-06 23:38:29 UTC (rev 155225)
+++ trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj	2013-09-06 23:46:01 UTC (rev 155226)
@@ -7508,6 +7508,7 @@
     <ClCompile Include="..\platform\win\SharedBufferWin.cpp" />
     <ClCompile Include="..\platform\win\SharedTimerWin.cpp" />
     <ClCompile Include="..\platform\win\SoundWin.cpp" />
+    <ClCompile Include="..\platform\win\StructuredExceptionHandlerSuppressor.cpp" />
     <ClCompile Include="..\platform\win\SystemInfo.cpp" />
     <ClCompile Include="..\platform\win\TemporaryLinkStubs.cpp" />
     <ClCompile Include="..\platform\win\WCDataObject.cpp">
@@ -21430,6 +21431,14 @@
     <None Include="WebCorePreBuild.cmd" />
   </ItemGroup>
   <ItemGroup>
+    <MASM Include="..\platform\win\makesafeseh.asm">
+      <AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='DebugSuffix|Win32'">/safeseh %(AdditionalOptions)</AdditionalOptions>
+      <AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Debug_WinCairo|Win32'">/safeseh %(AdditionalOptions)</AdditionalOptions>
+      <AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">/safeseh %(AdditionalOptions)</AdditionalOptions>
+      <AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Production|Win32'">/safeseh %(AdditionalOptions)</AdditionalOptions>
+      <AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Release_WinCairo|Win32'">/safeseh %(AdditionalOptions)</AdditionalOptions>
+      <AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">/safeseh %(AdditionalOptions)</AdditionalOptions>
+    </MASM>
     <MASM Include="..\plugins\win\PaintHooks.asm">
       <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
       <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug_WinCairo|Win32'">true</ExcludedFromBuild>
@@ -21443,4 +21452,4 @@
   <ImportGroup Label="ExtensionTargets">
     <Import Project="$(VCTargetsPath)\BuildCustomizations\masm.targets" />
   </ImportGroup>
-</Project>
+</Project>
\ No newline at end of file

Modified: trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters (155225 => 155226)


--- trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters	2013-09-06 23:38:29 UTC (rev 155225)
+++ trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters	2013-09-06 23:46:01 UTC (rev 155226)
@@ -7099,6 +7099,10 @@
     <ClCompile Include="..\bindings\js\WebCoreTypedArrayController.cpp">
       <Filter>bindings\js</Filter>
     </ClCompile>
+    <ClCompile Include="..\rendering\RenderBlockFlow.cpp" />
+    <ClCompile Include="..\platform\win\StructuredExceptionHandlerSuppressor.cpp">
+      <Filter>platform\win</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\Modules\filesystem\AsyncFileWriter.h">
@@ -14885,9 +14889,6 @@
     <ClInclude Include="..\css\CSSFilterImageValue.h">
       <Filter>css</Filter>
     </ClInclude>
-    <ClInclude Include="$(ConfigurationBuildDir)\obj$(PlatformArchitecture)\$(ProjectName)\DerivedSources\HTMLElementTypeChecks.h">
-      <Filter>DerivedSources</Filter>
-    </ClInclude>
     <ClInclude Include="..\dom\InlineStyleSheetOwner.h">
       <Filter>dom</Filter>
     </ClInclude>
@@ -14903,12 +14904,11 @@
     <ClInclude Include="..\style\StyleResolveForDocument.h">
       <Filter>css</Filter>
     </ClInclude>
-    <ClInclude Include="$(ConfigurationBuildDir)\obj$(PlatformArchitecture)\$(ProjectName)\DerivedSources\SVGElementTypeChecks.h">
-      <Filter>DerivedSources</Filter>
-    </ClInclude>
     <ClInclude Include="..\dom\TextNodeTraversal.h">
       <Filter>dom</Filter>
     </ClInclude>
+    <ClInclude Include="$(ConfigurationBuildDir)\obj$(PlatformArchitecture)\$(ProjectName)\DerivedSources\HTMLElementTypeHelpers.h" />
+    <ClInclude Include="$(ConfigurationBuildDir)\obj$(PlatformArchitecture)\$(ProjectName)\DerivedSources\SVGElementTypeHelpers.h" />
   </ItemGroup>
   <ItemGroup>
     <None Include="..\css\CSSGrammar.y.in">
@@ -15877,5 +15877,8 @@
     <MASM Include="..\plugins\win\PaintHooks.asm">
       <Filter>plugins\win</Filter>
     </MASM>
+    <MASM Include="..\platform\win\makesafeseh.asm">
+      <Filter>platform\win</Filter>
+    </MASM>
   </ItemGroup>
-</Project>
+</Project>
\ No newline at end of file

Modified: trunk/Source/WebCore/platform/graphics/ca/win/LayerChangesFlusher.cpp (155225 => 155226)


--- trunk/Source/WebCore/platform/graphics/ca/win/LayerChangesFlusher.cpp	2013-09-06 23:38:29 UTC (rev 155225)
+++ trunk/Source/WebCore/platform/graphics/ca/win/LayerChangesFlusher.cpp	2013-09-06 23:46:01 UTC (rev 155226)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011 Apple Inc. All rights reserved.
+ * Copyright (C) 2011, 2013 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -74,7 +74,8 @@
 {
     // Supress the exception handler Windows puts around all hook calls so we can 
     // crash for debugging purposes if an exception is hit. 
-    StructuredExceptionHandlerSuppressor supressor; 
+    ExceptionRegistration registrationStruct; // Note: must be stack allocated.
+    StructuredExceptionHandlerSuppressor supressor(registrationStruct);
     return shared().hookFired(code, wParam, lParam);
 }
 

Added: trunk/Source/WebCore/platform/win/StructuredExceptionHandlerSuppressor.cpp (0 => 155226)


--- trunk/Source/WebCore/platform/win/StructuredExceptionHandlerSuppressor.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/win/StructuredExceptionHandlerSuppressor.cpp	2013-09-06 23:46:01 UTC (rev 155226)
@@ -0,0 +1,134 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#include "config.h"
+
+#include "StructuredExceptionHandlerSuppressor.h"
+
+extern "C" int __stdcall exceptionHandlerThunk(); // Defined in makesafeseh.asm
+
+static bool exceptionShouldTerminateProgram(int code)
+{
+    switch (code) {
+#ifndef NDEBUG
+    case EXCEPTION_DATATYPE_MISALIGNMENT:
+    case EXCEPTION_FLT_DENORMAL_OPERAND:
+    case EXCEPTION_FLT_DIVIDE_BY_ZERO:
+    case EXCEPTION_FLT_INEXACT_RESULT:
+    case EXCEPTION_FLT_INVALID_OPERATION:
+    case EXCEPTION_FLT_OVERFLOW:
+    case EXCEPTION_FLT_STACK_CHECK:
+    case EXCEPTION_FLT_UNDERFLOW:
+#endif
+    case EXCEPTION_ACCESS_VIOLATION:
+    case EXCEPTION_ARRAY_BOUNDS_EXCEEDED:
+    case EXCEPTION_INT_DIVIDE_BY_ZERO:
+    case EXCEPTION_INT_OVERFLOW:
+    case EXCEPTION_PRIV_INSTRUCTION:
+    case EXCEPTION_IN_PAGE_ERROR:
+    case EXCEPTION_ILLEGAL_INSTRUCTION:
+    case EXCEPTION_NONCONTINUABLE_EXCEPTION:
+    case EXCEPTION_STACK_OVERFLOW:
+    case EXCEPTION_INVALID_DISPOSITION:
+    case EXCEPTION_GUARD_PAGE:
+    case EXCEPTION_INVALID_HANDLE:
+        return true;
+    };
+
+    return false;
+}
+
+extern "C" EXCEPTION_DISPOSITION __stdcall exceptionHandler(struct _EXCEPTION_RECORD* exceptionRecord, void* /*establisherFrame*/, struct _CONTEXT* /*contextRecord*/, void* /*dispatcherContext*/)
+{
+    if (exceptionShouldTerminateProgram(exceptionRecord->ExceptionCode))
+        abort();
+
+    return ExceptionContinueSearch;
+}
+
+namespace WebCore {
+
+#pragma warning(push)
+#pragma warning(disable: 4733) // Disable "not registered as safe handler" warning
+
+StructuredExceptionHandlerSuppressor::StructuredExceptionHandlerSuppressor(ExceptionRegistration& exceptionRegistration)
+{
+    // Note: Windows requires that the EXCEPTION_REGISTRATION block (modeled here as our
+    // ExceptionRegistration struct) be stack allocated. Therefore we instantiated it prior
+    // to building this object so that Windows can still find it in stack memory when it
+    // attempts to use the handler.
+
+    // Windows puts an __try/__except block around some calls, such as hooks.
+    // The exception handler then ignores system exceptions like invalid addresses
+    // and null pointers. This class can be used to remove this block and prevent
+    // it from catching the exception. Typically this will cause the exception to crash 
+    // which is often desirable to allow crashlogs to be recorded for debugging purposed.
+    // While this class is in scope we replace the Windows exception handler with a custom
+    // handler that indicates exceptions that should not be handled.
+    //
+    // See http://www.microsoft.com/msj/0197/Exception/Exception.aspx,
+    //     http://www.microsoft.com/msj/archive/S2CE.aspx
+    //     http://www.hexblog.com/wp-content/uploads/2012/06/Recon-2012-Skochinsky-Compiler-Internals.pdf
+    //     http://www.codeproject.com/Articles/2126/How-a-C-compiler-implements-exception-handling
+
+    // Windows doesn't like assigning to member variables, so we need to get the value into
+    // a local variable and store it afterwards.
+    void* registration;
+
+    // Note: The FS register on Windows always holds the Thread Information Block.
+    // FS:[0] points to the structured exception handling chain (a chain of
+    // EXCEPTION_REGISTRATION structs).
+    //
+    // struct EXCEPTION_REGISTRATION
+    // {
+    //     DWORD next;
+    //     DWORD handler;
+    // };
+    //
+    // The first four bytes of FS:[0] point to the 'Next' member in the chain. Grab it so we can restore it later.
+    __asm mov eax, FS:[0]
+    __asm mov [registration], eax
+
+    exceptionRegistration.prev = (ExceptionRegistration*)registration;
+    exceptionRegistration.handler = (void*)exceptionHandlerThunk;
+
+    void* erStructMem = &exceptionRegistration;
+
+    __asm mov eax, erStructMem
+    __asm mov FS:[0], eax
+
+    m_savedExceptionRegistration = registration;
+}
+
+StructuredExceptionHandlerSuppressor::~StructuredExceptionHandlerSuppressor()
+{
+    // Restore the exception handler
+    __asm mov eax, [m_savedExceptionRegistration]
+    __asm mov FS:[0], eax
+}
+
+#pragma warning(pop)
+
+}

Modified: trunk/Source/WebCore/platform/win/StructuredExceptionHandlerSuppressor.h (155225 => 155226)


--- trunk/Source/WebCore/platform/win/StructuredExceptionHandlerSuppressor.h	2013-09-06 23:38:29 UTC (rev 155225)
+++ trunk/Source/WebCore/platform/win/StructuredExceptionHandlerSuppressor.h	2013-09-06 23:46:01 UTC (rev 155226)
@@ -26,51 +26,28 @@
 #ifndef StructuredExceptionHandlerSuppressor_h
 #define StructuredExceptionHandlerSuppressor_h
 
+#include <excpt.h>
+#include <wtf/Noncopyable.h>
+
+extern "C" EXCEPTION_DISPOSITION __stdcall exceptionHandler(struct _EXCEPTION_RECORD* exceptionRecord, void* establisherFrame, struct _CONTEXT* contextRecord, void* dispatcherContext);
+
 namespace WebCore {
 
-#pragma warning(push)
-#pragma warning(disable: 4733) // Disable "not registered as safe handler" warning
+struct ExceptionRegistration {
+    ExceptionRegistration* prev;
+    void* handler;
+};
 
 class StructuredExceptionHandlerSuppressor {
     WTF_MAKE_NONCOPYABLE(StructuredExceptionHandlerSuppressor);
 public:
-    StructuredExceptionHandlerSuppressor()
-    {
-        // Windows puts an __try/__except block around some calls, such as hooks.
-        // The exception handler then ignores system exceptions like invalid addresses
-        // and null pointers. This class can be used to remove this block and prevent
-        // it from catching the exception. Typically this will cause the exception to crash 
-        // which is often desirable to allow crashlogs to be recorded for debugging purposed.
-        // While this class is in scope we replace the Windows exception handler with 0xffffffff, 
-        // which indicates that the exception should not be handled.
-        //
-        // See http://www.microsoft.com/msj/0197/Exception/Exception.aspx
+    StructuredExceptionHandlerSuppressor(ExceptionRegistration&);
+    ~StructuredExceptionHandlerSuppressor();
 
-        // Windows doesn't like assigning to member variables, so we need to get the value into
-        // a local variable and store it afterwards.
-        void* registration;
-
-        __asm mov eax, FS:[0]
-        __asm mov [registration], eax
-        __asm mov eax, 0xffffffff
-        __asm mov FS:[0], eax
-
-        m_savedExceptionRegistration = registration;
-    }
-
-    ~StructuredExceptionHandlerSuppressor()
-    {
-        // Restore the exception handler
-        __asm mov eax, [m_savedExceptionRegistration]
-        __asm mov FS:[0], eax
-    }
-
 private:
     void* m_savedExceptionRegistration;
 };
 
-#pragma warning(pop)
-
 } // namespace WebCore
 
 #endif // StructuredExceptionHandlerSuppressor_h

Added: trunk/Source/WebCore/platform/win/makesafeseh.asm (0 => 155226)


--- trunk/Source/WebCore/platform/win/makesafeseh.asm	                        (rev 0)
+++ trunk/Source/WebCore/platform/win/makesafeseh.asm	2013-09-06 23:46:01 UTC (rev 155226)
@@ -0,0 +1,45 @@
+;/*
+; * Copyright (C) 2013 Apple, Inc. All rights reserved
+; *
+; * Redistribution and use in source and binary forms, with or without
+; * modification, are permitted provided that the following conditions
+; * are met:
+; * 1. Redistributions of source code must retain the above copyright
+; *    notice, this list of conditions and the following disclaimer.
+; * 2. Redistributions in binary form must reproduce the above copyright
+; *    notice, this list of conditions and the following disclaimer in the
+; *    documentation and/or other materials provided with the distribution.
+; *
+; * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+; * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+; * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+; * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+; * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+; * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+; * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+; * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+; * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+; * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+; * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+; */
+
+; Tell Windows to trust our error handler. This must be done within an assembly
+; module. We cannot do it on-the-fly in our C++ code.
+;
+; Note also (confirmed by Raymond Chen) that we must use this assembly thunk
+; to call our custom exception handler. (See http://jpassing.com/2008/05/20/fun-with-low-level-seh/)
+
+.386
+.model FLAT, STDCALL
+
+EXTERN exceptionHandler@16 : near   ; Defined in StructuredExceptionHandlerSupressor.cpp
+
+exceptionHandlerThunk proto
+.safeseh exceptionHandlerThunk
+
+.code
+exceptionHandlerThunk proc
+    jmp exceptionHandler@16
+exceptionHandlerThunk endp
+
+END
\ No newline at end of file
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to