Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/pal/src/exception/seh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,8 @@ CatchHardwareExceptionHolder::~CatchHardwareExceptionHolder()

bool CatchHardwareExceptionHolder::IsEnabled()
{
CPalThread *pThread = InternalGetCurrentThread();
return pThread->IsHardwareExceptionsEnabled();
CPalThread *pThread = GetCurrentPalThread();
return pThread ? pThread->IsHardwareExceptionsEnabled() : false;
}

/*++
Expand Down
38 changes: 26 additions & 12 deletions src/pal/src/exception/signal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,23 +477,37 @@ static void sigsegv_handler(int code, siginfo_t *siginfo, void *context)

// Establish a return point in case the common_signal_handler returns

volatile bool contextInitialization = true;
if (GetCurrentPalThread())
{
volatile bool contextInitialization = true;

SignalHandlerWorkerReturnPoint returnPoint;
RtlCaptureContext(&returnPoint.context);
void *ptr = alloca(sizeof(SignalHandlerWorkerReturnPoint) + alignof(SignalHandlerWorkerReturnPoint) - 1);
SignalHandlerWorkerReturnPoint *pReturnPoint = (SignalHandlerWorkerReturnPoint *)ALIGN_UP(ptr, alignof(SignalHandlerWorkerReturnPoint));
RtlCaptureContext(&pReturnPoint->context);

// When the signal handler worker completes, it uses setcontext to return to this point
// When the signal handler worker completes, it uses setcontext to return to this point

if (contextInitialization)
{
contextInitialization = false;
ExecuteHandlerOnOriginalStack(code, siginfo, context, &returnPoint);
_ASSERTE(FALSE); // The ExecuteHandlerOnOriginalStack should never return
if (contextInitialization)
{
contextInitialization = false;
ExecuteHandlerOnOriginalStack(code, siginfo, context, pReturnPoint);
_ASSERTE(FALSE); // The ExecuteHandlerOnOriginalStack should never return
}

if (pReturnPoint->returnFromHandler)
{
return;
}
}

if (returnPoint.returnFromHandler)
else
{
return;
// If thread isn't created by coreclr and has alternate signal stack GetCurrentPalThread() will return NULL too.
// But since in this case we don't handle hardware exceptions (IsSafeToHandleHardwareException returns false)
// we can call common_signal_handler on the alternate stack.
if (common_signal_handler(code, siginfo, context, 2, (size_t)0, (size_t)siginfo->si_addr))
{
return;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/vm/threads.inl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#ifndef __llvm__
EXTERN_C __declspec(thread) ThreadLocalInfo gCurrentThreadInfo;
#else // !__llvm__
EXTERN_C __thread ThreadLocalInfo gCurrentThreadInfo;
EXTERN_C __thread ThreadLocalInfo gCurrentThreadInfo __attribute__ ((tls_model("initial-exec")));
#endif // !__llvm__

EXTERN_C inline Thread* STDCALL GetThread()
Expand Down