pkgsrc-WIP-changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

coreclr-git: Fix signal to C++ exception translation on NetBSD



Module Name:	pkgsrc-wip
Committed By:	Kamil Rytarowski <n54%gmx.com@localhost>
Pushed By:	kamil
Date:		Mon Apr 11 22:36:26 2016 +0200
Changeset:	07031f78931c818281752b0abcf472f04e2b701d

Modified Files:
	coreclr-git/distinfo
Added Files:
	coreclr-git/patches/patch-src_pal_src_CMakeLists.txt
	coreclr-git/patches/patch-src_pal_src_arch_i386_hardwareexceptionhelper.S
	coreclr-git/patches/patch-src_pal_src_exception_seh.cpp

Log Message:
coreclr-git: Fix signal to C++ exception translation on NetBSD

Backport:

From 4cb93fa5c6bc3aede0207262b58d2169bcbe2c31 Mon Sep 17 00:00:00 2001
From: Jan Vorlicek <janvorli%microsoft.com@localhost>
Date: Mon, 11 Apr 2016 14:21:01 +0200
Subject: [PATCH] Experimental change to hardware exception handling

---
 src/pal/src/CMakeLists.txt                      |  4 +++
 src/pal/src/arch/i386/hardwareexceptionhelper.S | 46 +++++++++++++++++++++++++
 src/pal/src/exception/seh.cpp                   | 20 ++++++++++-
 3 files changed, 69 insertions(+), 1 deletion(-)
 create mode 100644 src/pal/src/arch/i386/hardwareexceptionhelper.S

https://github.com/janvorli/coreclr/commit/4cb93fa5c6bc3aede0207262b58d2169bcbe2c31.patch

To see a diff of this commit:
https://wip.pkgsrc.org/cgi-bin/gitweb.cgi?p=pkgsrc-wip.git;a=commitdiff;h=07031f78931c818281752b0abcf472f04e2b701d

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

diffstat:
 coreclr-git/distinfo                               |  3 ++
 .../patches/patch-src_pal_src_CMakeLists.txt       | 15 +++++++
 ...src_pal_src_arch_i386_hardwareexceptionhelper.S | 52 ++++++++++++++++++++++
 .../patches/patch-src_pal_src_exception_seh.cpp    | 38 ++++++++++++++++
 4 files changed, 108 insertions(+)

diffs:
diff --git a/coreclr-git/distinfo b/coreclr-git/distinfo
index 9f43b91..756dc7f 100644
--- a/coreclr-git/distinfo
+++ b/coreclr-git/distinfo
@@ -1,9 +1,12 @@
 $NetBSD$
 
 SHA1 (patch-src_pal_inc_pal.h) = 7d3ef148af8b1b24067ba4cb5efc12581ebc6881
+SHA1 (patch-src_pal_src_CMakeLists.txt) = 5266c31034534c7ffd4e770c8c5c4712d3743f71
+SHA1 (patch-src_pal_src_arch_i386_hardwareexceptionhelper.S) = c488647e71f0d0c9169451a6954b1ff1f933a22f
 SHA1 (patch-src_pal_src_cruntime_printf.cpp) = 8a86c57e1fe3953d158e1860f04bd19d7df1fe08
 SHA1 (patch-src_pal_src_cruntime_printfcpp.cpp) = 4d1ba5fea45402259c67428506f39d9c3128ecbd
 SHA1 (patch-src_pal_src_cruntime_silent__printf.cpp) = 0922321ad05a90cc3b87b1e2663ff4d0b2e4717e
+SHA1 (patch-src_pal_src_exception_seh.cpp) = 15ebe8a14270ca7e904e0dd27492584dda473c58
 SHA1 (patch-src_pal_src_safecrt_output.inl) = ceb1951e8a7e0839fa1c0f5d07fd6c4087afd5df
 SHA1 (patch-src_pal_src_safecrt_safecrt__output__l.c) = 5a17a2525ab434336cfef369980562d1ecdcd953
 SHA1 (patch-src_pal_tests_palsuite_exception__handling_pal__sxs_test1_exceptionsxs.cpp) = de21ff04dc42fc3a8c3df4b74f0adaeb19488ff0
diff --git a/coreclr-git/patches/patch-src_pal_src_CMakeLists.txt b/coreclr-git/patches/patch-src_pal_src_CMakeLists.txt
new file mode 100644
index 0000000..54d680c
--- /dev/null
+++ b/coreclr-git/patches/patch-src_pal_src_CMakeLists.txt
@@ -0,0 +1,15 @@
+$NetBSD$
+
+--- src/pal/src/CMakeLists.txt.orig	2016-04-08 23:29:23.000000000 +0000
++++ src/pal/src/CMakeLists.txt
+@@ -45,6 +45,10 @@ if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
+     exception/machexception.cpp
+     exception/machmessage.cpp
+   )
++else(CMAKE_SYSTEM_NAME STREQUAL Darwin)
++  set(PLATFORM_SOURCES
++    arch/i386/hardwareexceptionhelper.S
++  )
+ endif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
+ 
+ add_definitions(-DPLATFORM_UNIX=1)
diff --git a/coreclr-git/patches/patch-src_pal_src_arch_i386_hardwareexceptionhelper.S b/coreclr-git/patches/patch-src_pal_src_arch_i386_hardwareexceptionhelper.S
new file mode 100644
index 0000000..389df2f
--- /dev/null
+++ b/coreclr-git/patches/patch-src_pal_src_arch_i386_hardwareexceptionhelper.S
@@ -0,0 +1,52 @@
+$NetBSD$
+
+--- src/pal/src/arch/i386/hardwareexceptionhelper.S.orig	2016-04-11 19:51:21.962403601 +0000
++++ src/pal/src/arch/i386/hardwareexceptionhelper.S
+@@ -0,0 +1,46 @@
++// Licensed to the .NET Foundation under one or more agreements.
++// The .NET Foundation licenses this file to you under the MIT license.
++// See the LICENSE file in the project root for more information.
++
++.intel_syntax noprefix
++#include "unixasmmacros.inc"
++#include "asmconstants.h"
++
++//////////////////////////////////////////////////////////////////////////
++//
++// This function initiates unwinding of native frames during the unwinding of a managed 
++// exception. The managed exception can be propagated over several managed / native ranges 
++// until it is finally handled by a managed handler or leaves the stack unhandled and
++// aborts the current process.
++// It creates a stack frame right below the target frame, restores all callee saved registers
++// from the passed in context and finally sets the RSP to that frame and sets the return
++// address to the target frame's RIP.
++//
++// EXTERN_C void ThrowHardwareExceptionFromContext(CONTEXT* context, PAL_SEHException* ex);
++LEAF_ENTRY ThrowHardwareExceptionFromContext, _TEXT
++        // Save the RBP to the stack so that the unwind can work at the instruction after
++        // loading the RBP from the context, but before loading the RSP from the context.
++        push_nonvol_reg rbp
++        mov     r12, [rdi + CONTEXT_R12]
++        mov     r13, [rdi + CONTEXT_R13]
++        mov     r14, [rdi + CONTEXT_R14]
++        mov     r15, [rdi + CONTEXT_R15]
++        mov     rbx, [rdi + CONTEXT_Rbx]
++        mov     rbp, [rdi + CONTEXT_Rbp]
++        mov     rsp, [rdi + CONTEXT_Rsp]
++        // The RSP was set to the target frame's value, so the current function's
++        // CFA is now right at the RSP.
++        .cfi_def_cfa_offset 0
++
++        // Indicate that now that we have moved the RSP to the target address, 
++        // the RBP is no longer saved in the current stack frame. 
++        .cfi_restore rbp
++
++        mov     rax, [rdi + CONTEXT_Rip]
++
++        // Store return address to the stack
++        push_register rax
++        // The PAL_SEHException pointer
++        mov     rdi, rsi 
++        jmp     EXTERNAL_C_FUNC(ThrowHardwareExceptionHelper)
++LEAF_END ThrowHardwareExceptionFromContext, _TEXT
+\ No newline at end of file
diff --git a/coreclr-git/patches/patch-src_pal_src_exception_seh.cpp b/coreclr-git/patches/patch-src_pal_src_exception_seh.cpp
new file mode 100644
index 0000000..a101955
--- /dev/null
+++ b/coreclr-git/patches/patch-src_pal_src_exception_seh.cpp
@@ -0,0 +1,38 @@
+$NetBSD$
+
+--- src/pal/src/exception/seh.cpp.orig	2016-04-08 23:29:23.000000000 +0000
++++ src/pal/src/exception/seh.cpp
+@@ -149,6 +149,21 @@ PAL_SetGetGcMarkerExceptionCode(
+     g_getGcMarkerExceptionCode = getGcMarkerExceptionCode;
+ }
+ 
++EXTERN_C void ThrowHardwareExceptionFromContext(CONTEXT* context, PAL_SEHException* ex);
++
++//---------------------------------------------------------------------------------------
++//
++// Helper function to throw the passed in exception.
++// It is called from the assembler function StartUnwindingNativeFrames 
++// Arguments:
++//
++//      ex - the exception to throw.
++//
++extern "C"
++void ThrowHardwareExceptionHelper(PAL_SEHException* ex)
++{
++    throw *ex;
++}
+ /*++
+ Function:
+     SEHProcessException
+@@ -175,7 +190,10 @@ SEHProcessException(PEXCEPTION_POINTERS 
+ 
+         if (CatchHardwareExceptionHolder::IsEnabled())
+         {
+-            throw exception;
++            static __thread BYTE threadLocalExceptionStorage[sizeof(PAL_SEHException)];
++            PAL_SEHException* ex = new (threadLocalExceptionStorage) PAL_SEHException(exception);
++            ThrowHardwareExceptionFromContext(&ex->ContextRecord, ex);
++            //throw exception;
+         }
+     }
+ 


Home | Main Index | Thread Index | Old Index