From f2e4b8cfe7870c7ea30790de5a1cd5e61c8db917 Mon Sep 17 00:00:00 2001 From: Adeel Mujahid <3840695+am11@users.noreply.github.com> Date: Tue, 30 Jun 2026 04:49:29 +0300 Subject: [PATCH 1/7] Preserve throw kind across GetThread --- src/coreclr/nativeaot/Runtime/riscv64/ExceptionHandling.S | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/coreclr/nativeaot/Runtime/riscv64/ExceptionHandling.S b/src/coreclr/nativeaot/Runtime/riscv64/ExceptionHandling.S index 210355fb28ef91..5a46bffeb738f8 100644 --- a/src/coreclr/nativeaot/Runtime/riscv64/ExceptionHandling.S +++ b/src/coreclr/nativeaot/Runtime/riscv64/ExceptionHandling.S @@ -245,14 +245,16 @@ .endm .macro GetThreadA2 - addi sp, sp, -16 + addi sp, sp, -32 sd a0, 0(sp) sd a1, 8(sp) + sd a4, 16(sp) call C_FUNC(RhpGetThread) mv a2, a0 ld a0, 0(sp) ld a1, 8(sp) - addi sp, sp, 16 + ld a4, 16(sp) + addi sp, sp, 32 .endm #define rsp_offsetof_ExInfo 0 From cfcede890bed90c8ed871610b4c834e4ba792e02 Mon Sep 17 00:00:00 2001 From: Adeel Mujahid <3840695+am11@users.noreply.github.com> Date: Tue, 30 Jun 2026 04:50:45 +0300 Subject: [PATCH 2/7] . --- .../nativeaot/Runtime/loongarch64/ExceptionHandling.S | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/coreclr/nativeaot/Runtime/loongarch64/ExceptionHandling.S b/src/coreclr/nativeaot/Runtime/loongarch64/ExceptionHandling.S index 469dd8d03aea93..d6307df6430342 100644 --- a/src/coreclr/nativeaot/Runtime/loongarch64/ExceptionHandling.S +++ b/src/coreclr/nativeaot/Runtime/loongarch64/ExceptionHandling.S @@ -212,14 +212,16 @@ .endm .macro GetThreadA2 - addi.d $sp, $sp, -16 + addi.d $sp, $sp, -32 st.d $a0, $sp, 0 st.d $a1, $sp, 8 + st.d $a4, $sp, 16 bl C_FUNC(RhpGetThread) ori $a2, $a0, 0 ld.d $a0, $sp, 0 ld.d $a1, $sp, 8 - addi.d $sp, $sp, 16 + ld.d $a4, $sp, 16 + addi.d $sp, $sp, 32 .endm #define rsp_offsetof_ExInfo 0 From 768fc83e6e17eeea607886c18428163664a51200 Mon Sep 17 00:00:00 2001 From: Adeel Mujahid <3840695+am11@users.noreply.github.com> Date: Tue, 30 Jun 2026 14:37:17 +0300 Subject: [PATCH 3/7] Revert LA64 asm Co-authored-by: Adeel Mujahid <3840695+am11@users.noreply.github.com> --- .../nativeaot/Runtime/loongarch64/ExceptionHandling.S | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/coreclr/nativeaot/Runtime/loongarch64/ExceptionHandling.S b/src/coreclr/nativeaot/Runtime/loongarch64/ExceptionHandling.S index d6307df6430342..469dd8d03aea93 100644 --- a/src/coreclr/nativeaot/Runtime/loongarch64/ExceptionHandling.S +++ b/src/coreclr/nativeaot/Runtime/loongarch64/ExceptionHandling.S @@ -212,16 +212,14 @@ .endm .macro GetThreadA2 - addi.d $sp, $sp, -32 + addi.d $sp, $sp, -16 st.d $a0, $sp, 0 st.d $a1, $sp, 8 - st.d $a4, $sp, 16 bl C_FUNC(RhpGetThread) ori $a2, $a0, 0 ld.d $a0, $sp, 0 ld.d $a1, $sp, 8 - ld.d $a4, $sp, 16 - addi.d $sp, $sp, 32 + addi.d $sp, $sp, 16 .endm #define rsp_offsetof_ExInfo 0 From a4fa0df050a928749393b90126c69fe97a7b3250 Mon Sep 17 00:00:00 2001 From: Adeel Mujahid <3840695+am11@users.noreply.github.com> Date: Tue, 30 Jun 2026 18:23:31 +0300 Subject: [PATCH 4/7] Address CR feedback --- .../nativeaot/Runtime/riscv64/ExceptionHandling.S | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/coreclr/nativeaot/Runtime/riscv64/ExceptionHandling.S b/src/coreclr/nativeaot/Runtime/riscv64/ExceptionHandling.S index 5a46bffeb738f8..8cbe1b6a276982 100644 --- a/src/coreclr/nativeaot/Runtime/riscv64/ExceptionHandling.S +++ b/src/coreclr/nativeaot/Runtime/riscv64/ExceptionHandling.S @@ -245,16 +245,14 @@ .endm .macro GetThreadA2 - addi sp, sp, -32 + addi sp, sp, -16 sd a0, 0(sp) sd a1, 8(sp) - sd a4, 16(sp) call C_FUNC(RhpGetThread) mv a2, a0 ld a0, 0(sp) ld a1, 8(sp) - ld a4, 16(sp) - addi sp, sp, 32 + addi sp, sp, 16 .endm #define rsp_offsetof_ExInfo 0 @@ -340,6 +338,7 @@ NESTED_ENTRY RhpThrowImpl, _TEXT, NoHandler ALLOC_THROW_FRAME SOFTWARE_EXCEPTION + mv s1, a4 // Save ExKind GetThreadA2 @@ -383,7 +382,7 @@ LOCAL_LABEL(NotHijacked): sb a3, OFFSETOF__ExInfo__m_passNumber(a1) // pExInfo->m_passNumber = 1 addiw a3, zero, -1 sw a3, OFFSETOF__ExInfo__m_idxCurClause(a1) // pExInfo->m_idxCurClause = MaxTryRegionIdx - sb a4, OFFSETOF__ExInfo__m_kind(a1) // pExInfo->m_kind = ExKind (from a4) + sb s1, OFFSETOF__ExInfo__m_kind(a1) // pExInfo->m_kind = ExKind // Link the ExInfo into the thread's ExInfo chain ld a3, OFFSETOF__Thread__m_pExInfoStackHead(a2) From 4ba6c4b7c22714c5692306ead356aa313e17a1d6 Mon Sep 17 00:00:00 2001 From: Adeel Mujahid <3840695+am11@users.noreply.github.com> Date: Tue, 30 Jun 2026 18:24:19 +0300 Subject: [PATCH 5/7] . --- src/coreclr/nativeaot/Runtime/arm64/ExceptionHandling.S | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/coreclr/nativeaot/Runtime/arm64/ExceptionHandling.S b/src/coreclr/nativeaot/Runtime/arm64/ExceptionHandling.S index aa8ac5e79069c3..dbec0bd8ac998e 100644 --- a/src/coreclr/nativeaot/Runtime/arm64/ExceptionHandling.S +++ b/src/coreclr/nativeaot/Runtime/arm64/ExceptionHandling.S @@ -287,6 +287,7 @@ NESTED_ENTRY RhpThrowImpl, _TEXT, NoHandler ALLOC_THROW_FRAME SOFTWARE_EXCEPTION + mov x19, x4 // Save ExKind GetThreadX2 @@ -340,7 +341,7 @@ LOCAL_LABEL(NotHijacked): strb w3, [x1, #OFFSETOF__ExInfo__m_passNumber] // pExInfo->m_passNumber = 1 mov w3, #0xFFFFFFFF str w3, [x1, #OFFSETOF__ExInfo__m_idxCurClause] // pExInfo->m_idxCurClause = MaxTryRegionIdx - strb w4, [x1, #OFFSETOF__ExInfo__m_kind] // pExInfo->m_kind = ExKind (from w4) + strb w19, [x1, #OFFSETOF__ExInfo__m_kind] // pExInfo->m_kind = ExKind // link the ExInfo into the thread's ExInfo chain ldr x3, [x2, #OFFSETOF__Thread__m_pExInfoStackHead] From a69bfb852e66e2e82c4740ffdf79a918123a55ad Mon Sep 17 00:00:00 2001 From: Adeel Mujahid <3840695+am11@users.noreply.github.com> Date: Tue, 30 Jun 2026 18:24:42 +0300 Subject: [PATCH 6/7] . --- src/coreclr/nativeaot/Runtime/loongarch64/ExceptionHandling.S | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/coreclr/nativeaot/Runtime/loongarch64/ExceptionHandling.S b/src/coreclr/nativeaot/Runtime/loongarch64/ExceptionHandling.S index 469dd8d03aea93..8cc46fbcc1d904 100644 --- a/src/coreclr/nativeaot/Runtime/loongarch64/ExceptionHandling.S +++ b/src/coreclr/nativeaot/Runtime/loongarch64/ExceptionHandling.S @@ -303,6 +303,7 @@ NESTED_ENTRY RhpThrowImpl, _TEXT, NoHandler ALLOC_THROW_FRAME SOFTWARE_EXCEPTION + ori $r23, $a4, 0 // Save ExKind GetThreadA2 @@ -355,7 +356,7 @@ LOCAL_LABEL(NotHijacked): st.b $a3, $a1, OFFSETOF__ExInfo__m_passNumber // pExInfo->m_passNumber = 1 addi.w $a3, $zero, -1 st.w $a3, $a1, OFFSETOF__ExInfo__m_idxCurClause // pExInfo->m_idxCurClause = MaxTryRegionIdx - st.b $a4, $a1, OFFSETOF__ExInfo__m_kind // pExInfo->m_kind = ExKind (from a4) + st.b $r23, $a1, OFFSETOF__ExInfo__m_kind // pExInfo->m_kind = ExKind // link the ExInfo into the thread's ExInfo chain ld.d $a3, $a2, OFFSETOF__Thread__m_pExInfoStackHead From 3951c91ce1c9045e2b9602f8d3bd40fd08742179 Mon Sep 17 00:00:00 2001 From: Adeel Mujahid <3840695+am11@users.noreply.github.com> Date: Tue, 30 Jun 2026 23:47:28 +0300 Subject: [PATCH 7/7] Apply the same fix to x64 --- src/coreclr/nativeaot/Runtime/amd64/ExceptionHandling.S | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/coreclr/nativeaot/Runtime/amd64/ExceptionHandling.S b/src/coreclr/nativeaot/Runtime/amd64/ExceptionHandling.S index 8be19fcc8086ca..adadd8ea2123d2 100644 --- a/src/coreclr/nativeaot/Runtime/amd64/ExceptionHandling.S +++ b/src/coreclr/nativeaot/Runtime/amd64/ExceptionHandling.S @@ -143,6 +143,7 @@ NESTED_ENTRY RhpThrowImpl, _TEXT, NoHandler END_PROLOGUE mov rbx, rdi + mov r12, r8 // Save ExKind INLINE_GETTHREAD mov rdi, rbx @@ -161,7 +162,7 @@ NESTED_ENTRY RhpThrowImpl, _TEXT, NoHandler mov [rsi + OFFSETOF__ExInfo__m_exception], rdx // init the exception object to null mov byte ptr [rsi + OFFSETOF__ExInfo__m_passNumber], 1 // init to the first pass mov dword ptr [rsi + OFFSETOF__ExInfo__m_idxCurClause], 0xFFFFFFFF - mov byte ptr [rsi + OFFSETOF__ExInfo__m_kind], r8b // ExKind (from r8b) + mov byte ptr [rsi + OFFSETOF__ExInfo__m_kind], r12b // ExKind // link the ExInfo into the thread's ExInfo chain mov rdx, [rax + OFFSETOF__Thread__m_pExInfoStackHead]