Skip to content

Commit 48356a1

Browse files
committed
Revert "Fix exception propagation over HW exception frame on macOS arm64 (dotnet#63482)"
This reverts commit 897694f.
1 parent c6ceca8 commit 48356a1

File tree

6 files changed

+13
-86
lines changed

6 files changed

+13
-86
lines changed

src/coreclr/pal/src/exception/machexception.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,6 @@ void PAL_DispatchException(PCONTEXT pContext, PEXCEPTION_RECORD pExRecord, MachE
376376
*contextRecord = *pContext;
377377
*exceptionRecord = *pExRecord;
378378

379-
g_hardware_exception_context_locvar_offset = (int)((char*)&contextRecord - (char*)__builtin_frame_address(0));
380-
381379
contextRecord->ContextFlags |= CONTEXT_EXCEPTION_ACTIVE;
382380
bool continueExecution;
383381

src/coreclr/pal/src/exception/seh-unwind.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -496,9 +496,7 @@ void GetContextPointers(unw_cursor_t *cursor, unw_context_t *unwContext, KNONVOL
496496

497497
#ifndef HOST_WINDOWS
498498

499-
// Frame pointer relative offset of a local containing a pointer to the windows style context of a location
500-
// where a hardware exception occured.
501-
int g_hardware_exception_context_locvar_offset = 0;
499+
extern int g_common_signal_handler_context_locvar_offset;
502500

503501
BOOL PAL_VirtualUnwind(CONTEXT *context, KNONVOLATILE_CONTEXT_POINTERS *contextPointers)
504502
{
@@ -508,17 +506,19 @@ BOOL PAL_VirtualUnwind(CONTEXT *context, KNONVOLATILE_CONTEXT_POINTERS *contextP
508506

509507
DWORD64 curPc = CONTEXTGetPC(context);
510508

511-
// Check if the PC is the return address from the SEHProcessException.
512-
// If that's the case, extract its local variable containing a pointer to the windows style context of the hardware
509+
#ifndef __APPLE__
510+
// Check if the PC is the return address from the SEHProcessException in the common_signal_handler.
511+
// If that's the case, extract its local variable containing the windows style context of the hardware
513512
// exception and return that. This skips the hardware signal handler trampoline that the libunwind
514-
// cannot cross on some systems. On macOS, it skips a similar trampoline we create in HijackFaultingThread.
513+
// cannot cross on some systems.
515514
if ((void*)curPc == g_SEHProcessExceptionReturnAddress)
516515
{
517-
CONTEXT* exceptionContext = *(CONTEXT**)(CONTEXTGetFP(context) + g_hardware_exception_context_locvar_offset);
518-
memcpy_s(context, sizeof(CONTEXT), exceptionContext, sizeof(CONTEXT));
516+
CONTEXT* signalContext = (CONTEXT*)(CONTEXTGetFP(context) + g_common_signal_handler_context_locvar_offset);
517+
memcpy_s(context, sizeof(CONTEXT), signalContext, sizeof(CONTEXT));
519518

520519
return TRUE;
521520
}
521+
#endif
522522

523523
if ((context->ContextFlags & CONTEXT_EXCEPTION_ACTIVE) != 0)
524524
{

src/coreclr/pal/src/exception/signal.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ struct sigaction g_previous_sigabrt;
116116

117117
#if !HAVE_MACH_EXCEPTIONS
118118

119+
// Offset of the local variable containing pointer to windows style context in the common_signal_handler function.
120+
// This offset is relative to the frame pointer.
121+
int g_common_signal_handler_context_locvar_offset = 0;
122+
119123
// TOP of special stack for handling stack overflow
120124
volatile void* g_stackOverflowHandlerStack = NULL;
121125

@@ -935,12 +939,11 @@ static bool common_signal_handler(int code, siginfo_t *siginfo, void *sigcontext
935939
#if !HAVE_MACH_EXCEPTIONS
936940
sigset_t signal_set;
937941
CONTEXT signalContextRecord;
938-
CONTEXT* signalContextRecordPtr = &signalContextRecord;
939942
EXCEPTION_RECORD exceptionRecord;
940943
native_context_t *ucontext;
941944

942945
ucontext = (native_context_t *)sigcontext;
943-
g_hardware_exception_context_locvar_offset = (int)((char*)&signalContextRecordPtr - (char*)__builtin_frame_address(0));
946+
g_common_signal_handler_context_locvar_offset = (int)((char*)&signalContextRecord - (char*)__builtin_frame_address(0));
944947

945948
if (code == (SIGSEGV | StackOverflowFlag))
946949
{

src/coreclr/pal/src/include/pal/seh.hpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,5 @@ CorUnix::PAL_ERROR SEHDisable(CorUnix::CPalThread *pthrCurrent);
145145

146146
}
147147

148-
// Offset of the local variable containing pointer to windows style context in the common_signal_handler / PAL_DispatchException function.
149-
// This offset is relative to the frame pointer.
150-
extern int g_hardware_exception_context_locvar_offset;
151-
152-
153148
#endif /* _PAL_SEH_HPP_ */
154149

src/tests/Regressions/coreclr/GitHub_62058/test62058.cs

Lines changed: 0 additions & 60 deletions
This file was deleted.

src/tests/Regressions/coreclr/GitHub_62058/test62058.csproj

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)