Browse Source

linux: build lib/common/exceptions

Disable SEH usage on Unix. Existing SEH usage can be rewritten or disabled.
Makes cross platform easier.
Jianchun Xu 10 years ago
parent
commit
5bed2e15c5

+ 1 - 0
CMakeLists.txt

@@ -86,6 +86,7 @@ if(CLR_CMAKE_PLATFORM_UNIX)
         -Wno-ignored-pragmas
         -Wno-invalid-token-paste
         -Wno-format
+        -Wno-invalid-noreturn
     )
 endif(CLR_CMAKE_PLATFORM_UNIX)
 

+ 1 - 0
lib/common/CMakeLists.txt

@@ -6,4 +6,5 @@ add_subdirectory (codex)
 add_subdirectory (common)
 add_subdirectory (core)
 add_subdirectory (DataStructures)
+add_subdirectory (Exceptions)
 add_subdirectory (Memory)

+ 5 - 1
lib/common/CommonDefines.h

@@ -115,7 +115,7 @@
 #define ENABLE_NATIVE_CODEGEN 0
 #define ENABLE_PROFILE_INFO 0
 #define ENABLE_BACKGROUND_PARSING 0                 // Disable background parsing in this mode
-                                                    // We need to decouple the Jobs infrastructure out of 
+                                                    // We need to decouple the Jobs infrastructure out of
                                                     // Backend to make background parsing work with JIT disabled
 #define DYNAMIC_INTERPRETER_THUNK 0
 #define DISABLE_DYNAMIC_PROFILE_DEFER_PARSE
@@ -439,6 +439,10 @@
 #endif
 #endif
 
+#ifndef _WIN32
+#define DISABLE_SEH 1
+#endif
+
 //----------------------------------------------------------------------------------------------------
 // Dependent flags
 //  - flags values that are dependent on other flags

+ 10 - 0
lib/common/Exceptions/CMakeLists.txt

@@ -0,0 +1,10 @@
+add_library (Chakra.Common.Exceptions
+  # CommonExceptionsPch.cpp
+  ExceptionCheck.cpp
+  ExceptionBase.cpp
+  reporterror.cpp
+  Throw.cpp
+)
+
+target_include_directories (
+  Chakra.Common.Exceptions PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

+ 1 - 1
lib/common/Exceptions/CommonExceptionsPch.h

@@ -6,5 +6,5 @@
 
 #include "CommonBasic.h"
 
-#include "Exceptions\ExceptionBase.h"
+#include "Exceptions/ExceptionBase.h"
 

+ 21 - 48
lib/common/Exceptions/Throw.cpp

@@ -2,7 +2,6 @@
 // Copyright (C) Microsoft. All rights reserved.
 // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
 //-------------------------------------------------------------------------------------------------------
-#pragma once
 
 #include "CommonExceptionsPch.h"
 // === C Runtime Header Files ===
@@ -20,37 +19,41 @@
 // Header files required before including ConfigFlagsTable.h
 
 #include "EnumHelp.h"
-#include "Common\MathUtil.h"
-#include "Core\AllocSizeMath.h"
-#include "Core\FaultInjection.h"
+#include "common/MathUtil.h"
+#include "core/AllocSizeMath.h"
+#include "core/FaultInjection.h"
 
-#include "core\BasePtr.h"
-#include "core\AutoFILE.h"
-#include "core\Output.h"
+#include "core/BasePtr.h"
+#include "core/AutoFILE.h"
+#include "core/Output.h"
 
 // Memory Management
-namespace Memory {}
+namespace Memory {
+    class ArenaAllocator;
+}
 using namespace Memory;
-#include "Memory\Allocator.h"
-#include "Memory\HeapAllocator.h"
+#include "Memory/Allocator.h"
+#include "Memory/HeapAllocator.h"
 
 // Data structure
-#include "DataStructures\Comparer.h"
-#include "DataStructures\SizePolicy.h"
-#include "DataStructures\SList.h"
-#include "DataStructures\KeyValuePair.h"
-#include "DataStructures\BaseDictionary.h"
-#include "core\ConfigFlagsTable.h"
-
-#include "core\StackBackTrace.h"
+#include "DataStructures/comparer.h"
+#include "DataStructures/SizePolicy.h"
+#include "DataStructures/SList.h"
+#include "DataStructures/KeyValuePair.h"
+#include "DataStructures/DefaultContainerLockPolicy.h"
+#include "DataStructures/BaseDictionary.h"
+#include "core/ConfigFlagsTable.h"
 
+#include "core/StackBackTrace.h"
 
 
+#ifdef GENERATE_DUMP
 // dbghelp.h is not clean with warning 4091
 #pragma warning(push)
 #pragma warning(disable: 4091) /* warning C4091: 'typedef ': ignored on left of '' when no variable is declared */
 #include <dbghelp.h>
 #pragma warning(pop)
+#endif // GENERATE_DUMP
 
 extern "C"{
     BOOLEAN IsMessageBoxWPresent();
@@ -122,36 +125,6 @@ namespace Js {
         throw NotImplementedException();
     }
 
-    // Returns true when the process is either TE.exe or TE.processhost.exe
-    bool Throw::IsTEProcess()
-    {
-        wchar_t fileName[_MAX_PATH];
-        wchar_t moduleName[_MAX_PATH];
-        GetModuleFileName(0, moduleName, _MAX_PATH);
-        errno_t err = _wsplitpath_s(moduleName, nullptr, 0, nullptr, 0, fileName, _MAX_PATH, nullptr, 0);
-
-        return err == 0 && _wcsnicmp(fileName, L"TE", 2) == 0;
-    }
-
-    void Throw::GenerateDumpAndTerminateProcess(PEXCEPTION_POINTERS exceptInfo)
-    {
-        if (!Throw::IsTEProcess()
-#ifdef ENABLE_DEBUG_CONFIG_OPTIONS
-            && !Js::Configuration::Global.flags.IsEnabled(Js::DumpOnCrashFlag)
-#endif
-            )
-        {
-            return;
-        }
-
-#ifdef GENERATE_DUMP
-        Js::Throw::GenerateDump(exceptInfo, Js::Configuration::Global.flags.DumpOnCrash);
-#endif
-
-        // For now let's terminate the process.
-        TerminateProcess(GetCurrentProcess(), (UINT)DBG_TERMINATE_PROCESS);
-    }
-
 #ifdef GENERATE_DUMP
     CriticalSection Throw::csGenereateDump;
     void Throw::GenerateDump(LPCWSTR filePath, bool terminate, bool needLock)

+ 0 - 3
lib/common/Exceptions/Throw.h

@@ -20,9 +20,6 @@ namespace Js {
         static void __declspec(noreturn) FatalInternalError();
         static void __declspec(noreturn) FatalProjectionError();
 
-        static bool IsTEProcess();
-        static void GenerateDumpAndTerminateProcess(PEXCEPTION_POINTERS exceptInfo);
-
         static void CheckAndThrowOutOfMemory(BOOLEAN status);
 #ifdef GENERATE_DUMP
         static bool ReportAssert(__in LPSTR fileName, uint lineNumber, __in LPSTR error, __in LPSTR message);

+ 5 - 0
lib/common/Exceptions/reporterror.cpp

@@ -17,6 +17,10 @@ __inline void ReportFatalException(
     {
         DebugBreak();
     }
+
+#ifdef DISABLE_SEH
+    TerminateProcess(GetCurrentProcess(), (UINT)DBG_TERMINATE_PROCESS);
+#else
     __try
     {
         ULONG_PTR ExceptionInformation[2];
@@ -27,6 +31,7 @@ __inline void ReportFatalException(
     __except(FatalExceptionFilter(GetExceptionInformation()))
     {
     }
+#endif // DISABLE_SEH
 }
 
 // Disable optimization make sure all the frames are still available in Dr. Watson bug reports.

+ 4 - 0
lib/common/Exceptions/reporterror.h

@@ -59,6 +59,8 @@ void LargeHeapBlock_Metadata_Corrupted(
 
 void FromDOM_NoScriptScope_fatal_error();
 
+
+#ifndef DISABLE_SEH
 // RtlReportException is available on Vista and up, but we cannot use it for OOB release.
 // Use UnhandleExceptionFilter to let the default handler handles it.
 __inline LONG FatalExceptionFilter(
@@ -82,6 +84,8 @@ __inline LONG FatalExceptionFilter(
 
     return EXCEPTION_CONTINUE_SEARCH;
 }
+#endif // DISABLE_SEH
+
 
 template<class Fn>
 static STDMETHODIMP DebugApiWrapper(Fn fn)