diff --git a/src/coreclr/pal/src/exception/machexception.cpp b/src/coreclr/pal/src/exception/machexception.cpp index 0449be77458df3..e5aebdf652c6a5 100644 --- a/src/coreclr/pal/src/exception/machexception.cpp +++ b/src/coreclr/pal/src/exception/machexception.cpp @@ -376,8 +376,6 @@ void PAL_DispatchException(PCONTEXT pContext, PEXCEPTION_RECORD pExRecord, MachE *contextRecord = *pContext; *exceptionRecord = *pExRecord; - g_hardware_exception_context_locvar_offset = (int)((char*)&contextRecord - (char*)__builtin_frame_address(0)); - contextRecord->ContextFlags |= CONTEXT_EXCEPTION_ACTIVE; bool continueExecution; diff --git a/src/coreclr/pal/src/exception/seh-unwind.cpp b/src/coreclr/pal/src/exception/seh-unwind.cpp index b79552c6a51edc..4b149f941b5dc9 100644 --- a/src/coreclr/pal/src/exception/seh-unwind.cpp +++ b/src/coreclr/pal/src/exception/seh-unwind.cpp @@ -496,9 +496,7 @@ void GetContextPointers(unw_cursor_t *cursor, unw_context_t *unwContext, KNONVOL #ifndef HOST_WINDOWS -// Frame pointer relative offset of a local containing a pointer to the windows style context of a location -// where a hardware exception occured. -int g_hardware_exception_context_locvar_offset = 0; +extern int g_common_signal_handler_context_locvar_offset; BOOL PAL_VirtualUnwind(CONTEXT *context, KNONVOLATILE_CONTEXT_POINTERS *contextPointers) { @@ -508,17 +506,19 @@ BOOL PAL_VirtualUnwind(CONTEXT *context, KNONVOLATILE_CONTEXT_POINTERS *contextP DWORD64 curPc = CONTEXTGetPC(context); - // Check if the PC is the return address from the SEHProcessException. - // If that's the case, extract its local variable containing a pointer to the windows style context of the hardware +#ifndef __APPLE__ + // Check if the PC is the return address from the SEHProcessException in the common_signal_handler. + // If that's the case, extract its local variable containing the windows style context of the hardware // exception and return that. This skips the hardware signal handler trampoline that the libunwind - // cannot cross on some systems. On macOS, it skips a similar trampoline we create in HijackFaultingThread. + // cannot cross on some systems. if ((void*)curPc == g_SEHProcessExceptionReturnAddress) { - CONTEXT* exceptionContext = *(CONTEXT**)(CONTEXTGetFP(context) + g_hardware_exception_context_locvar_offset); - memcpy_s(context, sizeof(CONTEXT), exceptionContext, sizeof(CONTEXT)); + CONTEXT* signalContext = (CONTEXT*)(CONTEXTGetFP(context) + g_common_signal_handler_context_locvar_offset); + memcpy_s(context, sizeof(CONTEXT), signalContext, sizeof(CONTEXT)); return TRUE; } +#endif if ((context->ContextFlags & CONTEXT_EXCEPTION_ACTIVE) != 0) { diff --git a/src/coreclr/pal/src/exception/signal.cpp b/src/coreclr/pal/src/exception/signal.cpp index 1aa6dd730ec9da..521150530fa33e 100644 --- a/src/coreclr/pal/src/exception/signal.cpp +++ b/src/coreclr/pal/src/exception/signal.cpp @@ -116,6 +116,10 @@ struct sigaction g_previous_sigabrt; #if !HAVE_MACH_EXCEPTIONS +// Offset of the local variable containing pointer to windows style context in the common_signal_handler function. +// This offset is relative to the frame pointer. +int g_common_signal_handler_context_locvar_offset = 0; + // TOP of special stack for handling stack overflow volatile void* g_stackOverflowHandlerStack = NULL; @@ -935,12 +939,11 @@ static bool common_signal_handler(int code, siginfo_t *siginfo, void *sigcontext #if !HAVE_MACH_EXCEPTIONS sigset_t signal_set; CONTEXT signalContextRecord; - CONTEXT* signalContextRecordPtr = &signalContextRecord; EXCEPTION_RECORD exceptionRecord; native_context_t *ucontext; ucontext = (native_context_t *)sigcontext; - g_hardware_exception_context_locvar_offset = (int)((char*)&signalContextRecordPtr - (char*)__builtin_frame_address(0)); + g_common_signal_handler_context_locvar_offset = (int)((char*)&signalContextRecord - (char*)__builtin_frame_address(0)); if (code == (SIGSEGV | StackOverflowFlag)) { diff --git a/src/coreclr/pal/src/include/pal/seh.hpp b/src/coreclr/pal/src/include/pal/seh.hpp index 327fe0d7fb03e2..6ad89df0fdd650 100644 --- a/src/coreclr/pal/src/include/pal/seh.hpp +++ b/src/coreclr/pal/src/include/pal/seh.hpp @@ -145,10 +145,5 @@ CorUnix::PAL_ERROR SEHDisable(CorUnix::CPalThread *pthrCurrent); } -// Offset of the local variable containing pointer to windows style context in the common_signal_handler / PAL_DispatchException function. -// This offset is relative to the frame pointer. -extern int g_hardware_exception_context_locvar_offset; - - #endif /* _PAL_SEH_HPP_ */ diff --git a/src/tests/Regressions/coreclr/GitHub_62058/test62058.cs b/src/tests/Regressions/coreclr/GitHub_62058/test62058.cs deleted file mode 100644 index 3744007d9e45ac..00000000000000 --- a/src/tests/Regressions/coreclr/GitHub_62058/test62058.cs +++ /dev/null @@ -1,60 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; - -public class Program -{ - private interface IFoo - { - bool IsValid { get; } - } - - private class Foo : IFoo - { - public bool IsValid { get; set; } - } - - public static int Main(string[] args) - { - bool warmup = new Foo().IsValid; - CatchIgnore(() => - CatchRethrow(() => - { - IFoo[] foos = {new Foo(), null}; - foreach (var foo in foos) - { - bool check = foo.IsValid; - } - })); - - return 100; - } - - public static void CatchRethrow(Action action) - { - try - { - action.Invoke(); - } - catch (Exception e) - { - Console.Out.WriteLine("catch"); - Console.Out.Flush(); - throw new Exception("catch", e); // throw; doesn't work either - } - } - - public static void CatchIgnore(Action action) - { - try - { - action.Invoke(); - } - catch (Exception) - { - Console.Out.WriteLine("ignore"); - Console.Out.Flush(); - } - } -} diff --git a/src/tests/Regressions/coreclr/GitHub_62058/test62058.csproj b/src/tests/Regressions/coreclr/GitHub_62058/test62058.csproj deleted file mode 100644 index 0fce5a0556f40e..00000000000000 --- a/src/tests/Regressions/coreclr/GitHub_62058/test62058.csproj +++ /dev/null @@ -1,9 +0,0 @@ - - - Exe - 1 - - - - -