Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LoongArch64, RISC-V] Fix handling ThreadAbortException at the end of catch for LoongArch64 and RISC-V. #91531

Merged
merged 6 commits into from
Sep 7, 2023
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
18 changes: 17 additions & 1 deletion src/coreclr/pal/inc/unixasmmacrosloongarch64.inc
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ __RedirectionFuncName SETS "|?RedirectedHandledJITCaseFor":CC:"$reason":CC:"@Thr

// Stack alignment. This check is necessary as this function can be
// entered before complete execution of the prolog of another function.
andi $t4, $fp, 15
andi $t4, $fp, 0xf
sub.d $sp, $sp, $t4


Expand Down Expand Up @@ -482,3 +482,19 @@ $__RedirectionStubEndFuncName
EMIT_BREAKPOINT
#endif
.endm

//-----------------------------------------------------------------------------
// Macro used to check (in debug builds only) whether the stack is 16-bytes aligned (a requirement before calling
// out into C++/OS code). Invoke this directly after your prolog (if the stack frame size is fixed) or directly
// before a call (if you have a frame pointer and a dynamic stack). A breakpoint will be invoked if the stack
// is misaligned.
//
.macro CHECK_STACK_ALIGNMENT

#ifdef _DEBUG
andi $t4, $sp, 0xf
beq $t4, $r0, 0f
EMIT_BREAKPOINT
0:
#endif
.endm
16 changes: 16 additions & 0 deletions src/coreclr/pal/inc/unixasmmacrosriscv64.inc
Original file line number Diff line number Diff line change
Expand Up @@ -323,3 +323,19 @@ C_FUNC(\Name\()_End):
// TODO RISCV NYI
sw ra, 0(zero)
.endm

//-----------------------------------------------------------------------------
// Macro used to check (in debug builds only) whether the stack is 16-bytes aligned (a requirement before calling
// out into C++/OS code). Invoke this directly after your prolog (if the stack frame size is fixed) or directly
// before a call (if you have a frame pointer and a dynamic stack). A breakpoint will be invoked if the stack
// is misaligned.
//
.macro CHECK_STACK_ALIGNMENT

#ifdef _DEBUG
andi t4, sp, 0xf
beq t4, zero, 0f
EMIT_BREAKPOINT
0:
#endif
.endm
2 changes: 1 addition & 1 deletion src/coreclr/vm/exceptionhandling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ UINT_PTR ExceptionTracker::FinishSecondPass(
{
CopyOSContext(pThread->m_OSContext, pContextRecord);
SetIP(pThread->m_OSContext, (PCODE)uResumePC);
#if defined(TARGET_UNIX) && !(defined(TARGET_AMD64) || defined(TARGET_ARM64) || defined(TARGET_ARM))
#if defined(TARGET_UNIX) && defined(TARGET_X86)
uAbortAddr = NULL;
#else
uAbortAddr = (UINT_PTR)COMPlusCheckForAbort(uResumePC);
Expand Down
40 changes: 40 additions & 0 deletions src/coreclr/vm/loongarch64/asmhelpers.S
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,46 @@ LEAF_ENTRY JIT_GetSharedGCStaticBase_SingleAppDomain, _TEXT
bl JIT_GetSharedGCStaticBase_Helper
LEAF_END JIT_GetSharedGCStaticBase_SingleAppDomain, _TEXT

// Make sure the `FaultingExceptionFrame_StackAlloc` is 16-byte aligned.
#define FaultingExceptionFrame_StackAlloc (SIZEOF__GSCookie + SIZEOF__FaultingExceptionFrame + 0x8)
#define FaultingExceptionFrame_FrameOffset SIZEOF__GSCookie

.macro GenerateRedirectedStubWithFrame stub, target

//
// This is the primary function to which execution will be redirected to.
//
NESTED_ENTRY \stub, _TEXT, NoHandler

//
// IN: ra: original IP before redirect
//

PROLOG_SAVE_REG_PAIR_INDEXED 22, 1, 16

// alloc stack for FaultingExceptionFrame.
addi.d $sp, $sp, -FaultingExceptionFrame_StackAlloc

// stack must be 16 bytes aligned
CHECK_STACK_ALIGNMENT

// Save pointer to FEF for GetFrameFromRedirectedStubStackFrame
addi.d $a0, $sp, FaultingExceptionFrame_FrameOffset

// Prepare to initialize to NULL
st.d $r0, $a0, 0 // Initialize vtbl (it is not strictly necessary)
st.d $r0, $a0, FaultingExceptionFrame__m_fFilterExecuted // Initialize BOOL for personality routine

bl C_FUNC(\target)
// Target should not return.
EMIT_BREAKPOINT

NESTED_END \stub, _TEXT

.endm

GenerateRedirectedStubWithFrame RedirectForThreadAbort, ThrowControlForThread

// ------------------------------------------------------------------
// ResolveWorkerChainLookupAsmStub
//
Expand Down
6 changes: 0 additions & 6 deletions src/coreclr/vm/loongarch64/stubs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -952,12 +952,6 @@ PTR_CONTEXT GetCONTEXTFromRedirectedStubStackFrame(T_CONTEXT * pContext)
return *ppContext;
}

void RedirectForThreadAbort()
{
// ThreadAbort is not supported in .net core
throw "NYI";
}

#if !defined(DACCESS_COMPILE)
FaultingExceptionFrame *GetFrameFromRedirectedStubStackFrame (DISPATCHER_CONTEXT *pDispatcherContext)
{
Expand Down
8 changes: 0 additions & 8 deletions src/coreclr/vm/loongarch64/unixstubs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,3 @@
// The .NET Foundation licenses this file to you under the MIT license.

#include "common.h"

extern "C"
{
void RedirectForThrowControl()
{
PORTABILITY_ASSERT("Implement for PAL");
}
};
40 changes: 40 additions & 0 deletions src/coreclr/vm/riscv64/asmhelpers.S
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,46 @@ LOCAL_LABEL(JIT_GetSharedGCStaticBase_SingleAppDomain_CallHelper):
call JIT_GetSharedGCStaticBase_Helper
LEAF_END JIT_GetSharedGCStaticBase_SingleAppDomain, _TEXT

// Make sure the `FaultingExceptionFrame_StackAlloc` is 16-byte aligned.
#define FaultingExceptionFrame_StackAlloc (SIZEOF__GSCookie + SIZEOF__FaultingExceptionFrame + 0x8)
#define FaultingExceptionFrame_FrameOffset SIZEOF__GSCookie

.macro GenerateRedirectedStubWithFrame stub, target

//
// This is the primary function to which execution will be redirected to.
//
NESTED_ENTRY \stub, _TEXT, NoHandler

//
// IN: ra: original IP before redirect
//

PROLOG_SAVE_REG_PAIR_INDEXED fp, ra, 16

// alloc stack for FaultingExceptionFrame.
addi sp, sp, -FaultingExceptionFrame_StackAlloc

// stack must be 16 bytes aligned
CHECK_STACK_ALIGNMENT
jkotas marked this conversation as resolved.
Show resolved Hide resolved

// Save pointer to FEF for GetFrameFromRedirectedStubStackFrame
addi a0, sp, FaultingExceptionFrame_FrameOffset

// Prepare to initialize to NULL
sd zero, 0(a0) // Initialize vtbl (it is not strictly necessary)
sd zero, FaultingExceptionFrame__m_fFilterExecuted(a0) // Initialize BOOL for personality routine

call C_FUNC(\target)
// Target should not return.
EMIT_BREAKPOINT

NESTED_END \stub, _TEXT

.endm

GenerateRedirectedStubWithFrame RedirectForThreadAbort, ThrowControlForThread

// ------------------------------------------------------------------
// ResolveWorkerChainLookupAsmStub
//
Expand Down
6 changes: 0 additions & 6 deletions src/coreclr/vm/riscv64/stubs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -849,12 +849,6 @@ PTR_CONTEXT GetCONTEXTFromRedirectedStubStackFrame(T_CONTEXT * pContext)
return *ppContext;
}

void RedirectForThreadAbort()
{
// ThreadAbort is not supported in .net core
throw "NYI";
}

#if !defined(DACCESS_COMPILE)
FaultingExceptionFrame *GetFrameFromRedirectedStubStackFrame (DISPATCHER_CONTEXT *pDispatcherContext)
{
Expand Down
8 changes: 0 additions & 8 deletions src/coreclr/vm/riscv64/unixstubs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,3 @@
// The .NET Foundation licenses this file to you under the MIT license.

#include "common.h"

extern "C"
{
void RedirectForThrowControl()
{
PORTABILITY_ASSERT("Implement for PAL");
}
};
Loading