Skip to content
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
8 changes: 5 additions & 3 deletions src/coreclr/inc/readytorun.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
// src/coreclr/nativeaot/Runtime/inc/ModuleHeaders.h
// If you update this, ensure you run `git grep MINIMUM_READYTORUN_MAJOR_VERSION`
// and handle pending work.
#define READYTORUN_MAJOR_VERSION 33
#define READYTORUN_MINOR_VERSION 0x0001
#define READYTORUN_MAJOR_VERSION 34
#define READYTORUN_MINOR_VERSION 0x0000

#define MINIMUM_READYTORUN_MAJOR_VERSION 33
#define MINIMUM_READYTORUN_MAJOR_VERSION 34

// R2R Version 2.1 adds the InliningInfo section
// R2R Version 2.2 adds the ProfileDataInfo section
Expand Down Expand Up @@ -86,6 +86,8 @@
// GCRefMaps, moves VASIG_COOKIE from 5 to 7, and prefixes map-bearing import
// signatures with their GCRefMaps.
// R2R Version 33.1 adds READYTORUN_HELPER_WasmProfSamplepoint (used on WebAssembly)
// R2R Version 34 changes the ABI for funclets on ARM64 to match AMD64: funclets save only LR, and the
// runtime preserves the callee-saved registers around the funclets that it calls

struct READYTORUN_CORE_HEADER
{
Expand Down
8 changes: 1 addition & 7 deletions src/coreclr/jit/codegen.h
Original file line number Diff line number Diff line change
Expand Up @@ -521,12 +521,7 @@ class CodeGen final : public CodeGenInterface
// same.
struct FuncletFrameInfoDsc
{
regMaskTP fiSaveRegs; // Set of callee-saved registers saved in the funclet prolog (includes LR)
int fiSP_to_FPLR_save_delta; // FP/LR register save offset from SP (positive)
int fiSP_to_CalleeSave_delta; // First callee-saved register slot offset from SP (positive)
int fiFrameType; // Funclet frame types are numbered. See genFuncletProlog() for details.
int fiSpDelta1; // Stack pointer delta 1 (negative)
int fiSpDelta2; // Stack pointer delta 2 (negative)
unsigned fiOutgoingArgSpace; // Outgoing argument space allocated below the saved LR, aligned to 16
Comment thread
jkotas marked this conversation as resolved.
Resolved
};

FuncletFrameInfoDsc genFuncletInfo;
Expand Down Expand Up @@ -666,7 +661,6 @@ class CodeGen final : public CodeGenInterface
virtual void SetSaveFpLrWithAllCalleeSavedRegisters(bool value);
virtual bool IsSaveFpLrWithAllCalleeSavedRegisters() const;
bool genSaveFpLrWithAllCalleeSavedRegisters;
bool genForceFuncletFrameType5;
bool genReverseAndPairCalleeSavedRegisters;
#endif // TARGET_ARM64

Expand Down
640 changes: 28 additions & 612 deletions src/coreclr/jit/codegenarm64.cpp

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion src/coreclr/jit/codegencommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,6 @@ CodeGen::CodeGen(Compiler* theCompiler)

#ifdef TARGET_ARM64
genSaveFpLrWithAllCalleeSavedRegisters = false;
genForceFuncletFrameType5 = false;
genReverseAndPairCalleeSavedRegisters = false;
#endif // TARGET_ARM64
}
Expand Down
2 changes: 0 additions & 2 deletions src/coreclr/jit/jitconfigvalues.h
Original file line number Diff line number Diff line change
Expand Up @@ -904,8 +904,6 @@ CONFIG_STRING(JitRawHexCodeFile, "JitRawHexCodeFile")
// 1: disable frames that save FP/LR registers with the callee-saved registers (at the top of the frame)
// 2: force all frames to use the frame types that save FP/LR registers with the callee-saved registers (at the top
// of the frame)
// 3: force all frames to use the frame types that save FP/LR registers with the callee-saved registers (at the top
// of the frame) and also force using the large funclet frame variation (frame 5) if possible.
CONFIG_INTEGER(JitSaveFpLrWithCalleeSavedRegisters, "JitSaveFpLrWithCalleeSavedRegisters", 0)

// Experimental support for vector length agnostic implementation of Vector<T>
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/lclvars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5719,7 +5719,7 @@ void Compiler::lvaAssignVirtualFrameOffsetsToLocals()
{
codeGen->SetSaveFpLrWithAllCalleeSavedRegisters(false); // Disable using new frames
}
else if ((opts.compJitSaveFpLrWithCalleeSavedRegisters == 2) || (opts.compJitSaveFpLrWithCalleeSavedRegisters == 3))
else if (opts.compJitSaveFpLrWithCalleeSavedRegisters == 2)
{
codeGen->SetSaveFpLrWithAllCalleeSavedRegisters(true); // Force using new frames
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -942,14 +942,9 @@ private static void DispatchEx(scoped ref StackFrameIterator frameIter, ref ExIn
#if FEATURE_OBJCMARSHAL
if (pReversePInvokePropagationCallback != IntPtr.Zero)
{
#if TARGET_AMD64
InternalCalls.RhpPopExInfo(ref exInfo, frameIter.SP);
InternalCalls.RhpCallPropagateExceptionCallback(
pReversePInvokePropagationContext, pReversePInvokePropagationCallback, frameIter.RegisterSet, frameIter.PreviousTransitionFrame);
#else
InternalCalls.RhpCallPropagateExceptionCallback(
pReversePInvokePropagationContext, pReversePInvokePropagationCallback, frameIter.RegisterSet, ref exInfo, frameIter.PreviousTransitionFrame);
#endif
// the helper should jump to propagation handler and not return
Debug.Fail("unreachable");
FallbackFailFast(RhFailFastReason.InternalError, null);
Expand All @@ -962,7 +957,7 @@ private static void DispatchEx(scoped ref StackFrameIterator frameIter, ref ExIn
//
// ------------------------------------------------
exInfo._idxCurClause = catchingTryRegionIdx;
#if TARGET_AMD64
#if TARGET_AMD64 || TARGET_ARM64
UIntPtr funcletCallerSP;
byte* pResumeIP = InternalCalls.CallEHFunclet(
exceptionObj, pCatchHandler, frameIter.RegisterSet, &funcletCallerSP);
Expand Down Expand Up @@ -1106,7 +1101,7 @@ private static bool FindFirstPassHandler(object exception, uint idxStart,
#if NATIVEAOT
try
{
#if TARGET_AMD64
#if TARGET_AMD64 || TARGET_ARM64
UIntPtr funcletCallerSP;
shouldInvokeHandler =
InternalCalls.CallEHFilterFunclet(exception, frameIter.RegisterSet, pFilterFunclet, &funcletCallerSP) != 0;
Expand Down Expand Up @@ -1259,7 +1254,7 @@ private static void InvokeSecondPass(ref ExInfo exInfo, uint idxStart, uint idxL

byte* pFinallyHandler = ehClause._handlerAddress;
exInfo._idxCurClause = curIdx;
#if TARGET_AMD64
#if TARGET_AMD64 || TARGET_ARM64
UIntPtr funcletCallerSP;
InternalCalls.CallEHFunclet(null, pFinallyHandler, exInfo._frameIter.RegisterSet, &funcletCallerSP);
#else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ internal static class InternalCalls
// Miscellaneous helpers.
//

#if TARGET_AMD64
#if TARGET_AMD64 || TARGET_ARM64
[RuntimeImport(RuntimeLibrary, "CallEHFunclet")]
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern unsafe byte* CallEHFunclet(
Expand Down Expand Up @@ -181,13 +181,8 @@ internal static extern unsafe bool RhpCallFilterFunclet(
#if FEATURE_OBJCMARSHAL
[RuntimeImport(RuntimeLibrary, "RhpCallPropagateExceptionCallback")]
[MethodImpl(MethodImplOptions.InternalCall)]
#if TARGET_AMD64
internal static extern unsafe IntPtr RhpCallPropagateExceptionCallback(
IntPtr callbackContext, IntPtr callback, void* pvRegDisplay, IntPtr pPreviousTransitionFrame);
#else
internal static extern unsafe IntPtr RhpCallPropagateExceptionCallback(
IntPtr callbackContext, IntPtr callback, void* pvRegDisplay, ref EH.ExInfo exInfo, IntPtr pPreviousTransitionFrame);
#endif
#endif // FEATURE_OBJCMARSHAL

[RuntimeImport(RuntimeLibrary, "RhpFallbackFailFast")]
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/nativeaot/Runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -323,11 +323,11 @@ if(NOT FEATURE_PORTABLE_HELPERS)
endif()
endif()

if (CLR_CMAKE_TARGET_ARCH_AMD64)
if (CLR_CMAKE_TARGET_ARCH_AMD64 OR CLR_CMAKE_TARGET_ARCH_ARM64)
list(APPEND RUNTIME_SOURCES_ARCH_ASM
${RUNTIME_DIR}/${ARCH_SOURCES_DIR}/EHHelpers.${ASM_SUFFIX}
)
endif (CLR_CMAKE_TARGET_ARCH_AMD64)
endif (CLR_CMAKE_TARGET_ARCH_AMD64 OR CLR_CMAKE_TARGET_ARCH_ARM64)

# Add architecture specific folder for looking up headers.
convert_to_absolute_path(ARCH_SOURCES_DIR ${ARCH_SOURCES_DIR})
Expand Down
30 changes: 15 additions & 15 deletions src/coreclr/nativeaot/Runtime/StackFrameIterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ EXTERN_C CODE_LOCATION ReturnFromUniversalTransitionTailCall;
EXTERN_C CODE_LOCATION ReturnFromUniversalTransitionGuardedTailCall;
#endif

#if defined(TARGET_AMD64)
#if defined(TARGET_AMD64) || defined(TARGET_ARM64)
EXTERN_C CODE_LOCATION CallEHFunclet2;
EXTERN_C CODE_LOCATION CallEHFilterFunclet2;
#else
Expand Down Expand Up @@ -1086,7 +1086,7 @@ void StackFrameIterator::UnwindFuncletInvokeThunk()
#else // FEATURE_PORTABLE_HELPERS
PTR_uintptr_t SP;

#if defined(TARGET_AMD64)
#if defined(TARGET_AMD64) || defined(TARGET_ARM64)
bool isFilterInvoke = EQUALS_RETURN_ADDRESS(m_ControlPC, CallEHFilterFunclet2);
#else
bool isFilterInvoke = EQUALS_RETURN_ADDRESS(m_ControlPC, RhpCallFilterFunclet2);
Expand Down Expand Up @@ -1220,21 +1220,10 @@ void StackFrameIterator::UnwindFuncletInvokeThunk()
m_RegDisplay.pR11 = SP++;

#elif defined(TARGET_ARM64)
PTR_uint64_t d = (PTR_uint64_t)(m_RegDisplay.SP);

for (int i = 0; i < 8; i++)
{
m_RegDisplay.D[i] = *d++;
}

SP = (PTR_uintptr_t)d;
SP = (PTR_uintptr_t)(m_RegDisplay.SP);

if (!isFilterInvoke)
{
// RhpCallCatchFunclet puts a couple of extra things on the stack that aren't put there by the other two
// thunks, but we don't need to know what they are here, so we just skip them.
SP += EQUALS_RETURN_ADDRESS(m_ControlPC, RhpCallCatchFunclet2) ? 6 : 4;

// Save the preserved regs portion of the REGDISPLAY across the unwind through the C# EH dispatch code.
m_funcletPtrs.pX19 = m_RegDisplay.pX19;
m_funcletPtrs.pX20 = m_RegDisplay.pX20;
Expand Down Expand Up @@ -1264,6 +1253,17 @@ void StackFrameIterator::UnwindFuncletInvokeThunk()
m_RegDisplay.pX27 = SP++;
m_RegDisplay.pX28 = SP++;

PTR_uint64_t d = (PTR_uint64_t)SP;

for (int i = 0; i < 8; i++)
{
m_RegDisplay.D[i] = *d++;
}

SP = (PTR_uintptr_t)d;

SP += 2; // 2 locals

#elif defined(TARGET_LOONGARCH64)
PTR_uint64_t f = (PTR_uint64_t)(m_RegDisplay.SP);

Expand Down Expand Up @@ -2392,7 +2392,7 @@ StackFrameIterator::ReturnAddressCategory StackFrameIterator::CategorizeUnadjust
return InThrowSiteThunk;
}

#if defined(TARGET_AMD64)
#if defined(TARGET_AMD64) || defined(TARGET_ARM64)
if (EQUALS_RETURN_ADDRESS(returnAddress, CallEHFunclet2))
{
return InFuncletInvokeThunk;
Expand Down
115 changes: 32 additions & 83 deletions src/coreclr/nativeaot/Runtime/amd64/ExceptionHandling.S
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

.intel_syntax noprefix
#include <AsmOffsets.inc> // generated by the build from AsmOffsets.cpp
#include <unixasmmacros.inc>
#include "AsmMacros_Shared.h"

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
Expand Down Expand Up @@ -255,39 +254,6 @@ ALTERNATE_ENTRY RhpRethrow2

NESTED_END RhpRethrow, _TEXT

//
// Prologue of all funclet calling helpers (RhpCallXXXXFunclet)
//
.macro FUNCLET_CALL_PROLOGUE localsCount, alignStack

push_nonvol_reg r15 // save preserved regs for OS stackwalker
push_nonvol_reg r14 // ...
push_nonvol_reg r13 // ...
push_nonvol_reg r12 // ...
push_nonvol_reg rbx // ...
push_nonvol_reg rbp // ...

stack_alloc_size = \localsCount * 8 + \alignStack * 8

alloc_stack stack_alloc_size

END_PROLOGUE
.endm

//
// Epilogue of all funclet calling helpers (RhpCallXXXXFunclet)
//
.macro FUNCLET_CALL_EPILOGUE
free_stack stack_alloc_size

pop_nonvol_reg rbp
pop_nonvol_reg rbx
pop_nonvol_reg r12
pop_nonvol_reg r13
pop_nonvol_reg r14
pop_nonvol_reg r15
.endm

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// void FASTCALL RhpResumeAfterCatch(REGDISPLAY* pRegDisplay, void* pResumeIP)
Expand Down Expand Up @@ -322,18 +288,12 @@ NESTED_ENTRY RhpResumeAfterCatch, _TEXT, NoHandler
mov rax, r13 // rax <- resume IP
mov rcx, rbx // rcx <- REGDISPLAY*

mov rsi, [rcx + OFFSETOF__REGDISPLAY__pRbx]
mov rbx, [rsi]
mov rsi, [rcx + OFFSETOF__REGDISPLAY__pRbp]
mov rbp, [rsi]
mov rsi, [rcx + OFFSETOF__REGDISPLAY__pR12]
mov r12, [rsi]
mov rsi, [rcx + OFFSETOF__REGDISPLAY__pR13]
mov r13, [rsi]
mov rsi, [rcx + OFFSETOF__REGDISPLAY__pR14]
mov r14, [rsi]
mov rsi, [rcx + OFFSETOF__REGDISPLAY__pR15]
mov r15, [rsi]
LOAD_FUNCLET_REGISTER(rcx, Rbx, rsi)
LOAD_FUNCLET_REGISTER(rcx, Rbp, rsi)
LOAD_FUNCLET_REGISTER(rcx, R12, rsi)
LOAD_FUNCLET_REGISTER(rcx, R13, rsi)
LOAD_FUNCLET_REGISTER(rcx, R14, rsi)
LOAD_FUNCLET_REGISTER(rcx, R15, rsi)

// reset RSP and jump to the continuation address
mov rsp, rdx // reset the SP
Expand Down Expand Up @@ -362,53 +322,42 @@ NESTED_END RhpResumeAfterCatch, _TEXT
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
NESTED_ENTRY RhpCallPropagateExceptionCallback, _TEXT, NoHandler

// We could use a simpler prolog, as we don't have to be unwindable by StackFrameIterator::UnwindFuncletInvokeThunk()
FUNCLET_CALL_PROLOGUE 4, 1

locThread = 0
locArg0 = 0x08
locArg1 = 0x10
locArg3 = 0x18
alloc_stack 8 // align the stack for the calls below
END_PROLOGUE

mov [rsp + locArg0], rdi // save arguments for later
mov [rsp + locArg1], rsi
mov [rsp + locArg3], rcx
// The preserved registers are reloaded from the REGDISPLAY before calling the callback, so they can be used here.
mov rbx, rdi // rbx <- callback context
mov r12, rsi // r12 <- callback
mov r13, rdx // r13 <- REGDISPLAY*
mov r14, rcx // r14 <- pPreviousTransitionFrame

mov rbx, rdx
INLINE_GETTHREAD
mov rdx, rbx

mov [rsp + locThread], rax // save Thread* for later
mov r15, rax // r15 <- Thread*

// Clear the DoNotTriggerGc state before calling out to the propagation callback.
lock and dword ptr [rax + OFFSETOF__Thread__m_ThreadStateFlags], ~TSF_DoNotTriggerGc

mov rax, [rdx + OFFSETOF__REGDISPLAY__pRbx]
mov rbx, [rax]
mov rax, [rdx + OFFSETOF__REGDISPLAY__pRbp]
mov rbp, [rax]
mov rax, [rdx + OFFSETOF__REGDISPLAY__pR12]
mov r12, [rax]
mov rax, [rdx + OFFSETOF__REGDISPLAY__pR13]
mov r13, [rax]
mov rax, [rdx + OFFSETOF__REGDISPLAY__pR14]
mov r14, [rax]
mov rax, [rdx + OFFSETOF__REGDISPLAY__pR15]
mov r15, [rax]

mov rsi, [rsp + locThread] // rsi <- Thread*
lock and dword ptr [r15 + OFFSETOF__Thread__m_ThreadStateFlags], ~TSF_DoNotTriggerGc

// We must unhijack the thread at this point because the section of stack where the hijack is applied
// may go dead. If it does, then the next time we try to unhijack the thread, it will corrupt the stack.
INLINE_THREAD_UNHIJACK rsi, rdi, rcx // Thread in rsi, trashes rdi and rcx
INLINE_THREAD_UNHIJACK r15, rdi, rcx // Thread in r15, trashes rdi and rcx

mov rdi, rbx // rdi <- callback context
mov rax, r12 // rax <- callback
mov rdx, r13 // rdx <- REGDISPLAY*
mov r8, r14 // r8 <- pPreviousTransitionFrame
mov r9, r15 // r9 <- Thread*

LOAD_FUNCLET_REGISTER(rdx, Rbx, rcx)
LOAD_FUNCLET_REGISTER(rdx, Rbp, rcx)
LOAD_FUNCLET_REGISTER(rdx, R12, rcx)
LOAD_FUNCLET_REGISTER(rdx, R13, rcx)
LOAD_FUNCLET_REGISTER(rdx, R14, rcx)
LOAD_FUNCLET_REGISTER(rdx, R15, rcx)

// Switch to preemptive mode.
mov r8, [rsp + locArg3]
mov [rsi + OFFSETOF__Thread__m_pTransitionFrame], r8
mov [r9 + OFFSETOF__Thread__m_pTransitionFrame], r8

// reset RSP and RDI and jump to the propagation callback
mov rdi, [rsp + locArg0] // rdi <- callback context
mov rax, [rsp + locArg1] // rax <- callback
// reset RSP and jump to the propagation callback
mov rsp, [rdx + OFFSETOF__REGDISPLAY__SP] // reset the SP
// Don't restore the stack pointer to exact same context. Leave the
// return IP on the stack to let the unwinder work if the callback throws
Expand Down
Loading
Loading