Skip to content

Commit dec6686

Browse files
Delete ThreadAbort support from native AOT (#119173)
dotnet/runtimelab#893 (comment) better 4 years late than never I guess.
1 parent c6566fb commit dec6686

33 files changed

+44
-443
lines changed

src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/ExceptionHandling.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,6 @@ private enum HwExceptionCode : uint
446446
{
447447
STATUS_NATIVEAOT_NULL_REFERENCE = 0x00000000u,
448448
STATUS_NATIVEAOT_UNMANAGED_HELPER_NULL_REFERENCE = 0x00000042u,
449-
STATUS_NATIVEAOT_THREAD_ABORT = 0x00000043u,
450449

451450
STATUS_DATATYPE_MISALIGNMENT = 0x80000002u,
452451
STATUS_ACCESS_VIOLATION = 0xC0000005u,
@@ -586,12 +585,6 @@ public static void RhThrowHwEx(uint exceptionCode, ref ExInfo exInfo)
586585
exceptionId = ExceptionIDs.NullReference;
587586
break;
588587

589-
#if NATIVEAOT
590-
case (uint)HwExceptionCode.STATUS_NATIVEAOT_THREAD_ABORT:
591-
exceptionToThrow = InternalCalls.RhpGetThreadAbortException();
592-
break;
593-
#endif
594-
595588
case (uint)HwExceptionCode.STATUS_DATATYPE_MISALIGNMENT:
596589
exceptionId = ExceptionIDs.DataMisaligned;
597590
break;

src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/InternalCalls.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,6 @@ internal static extern unsafe IntPtr RhpCallPropagateExceptionCallback(
232232
internal static extern unsafe void RhpCopyContextFromExInfo(void* pOSContext, int cbOSContext, EH.PAL_LIMITED_CONTEXT* pPalContext);
233233
#endif
234234

235-
[RuntimeImport(RuntimeLibrary, "RhpGetThreadAbortException")]
236-
[MethodImpl(MethodImplOptions.InternalCall)]
237-
internal static extern Exception RhpGetThreadAbortException();
238-
239235
[RuntimeImport(RuntimeLibrary, "RhCurrentNativeThreadId")]
240236
[MethodImpl(MethodImplOptions.InternalCall)]
241237
internal static extern unsafe IntPtr RhCurrentNativeThreadId();

src/coreclr/nativeaot/Runtime/AsmOffsets.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,8 @@ ASM_OFFSET( 34, 50, Thread, m_pDeferredTransitionFrame)
5555
ASM_OFFSET( 40, 68, Thread, m_ppvHijackedReturnAddressLocation)
5656
ASM_OFFSET( 44, 70, Thread, m_pvHijackedReturnAddress)
5757
ASM_OFFSET( 48, 78, Thread, m_pExInfoStackHead)
58-
ASM_OFFSET( 4c, 80, Thread, m_threadAbortException)
5958
#ifdef TARGET_X86
60-
ASM_OFFSET( 50, FF, Thread, m_uHijackedReturnValueFlags)
59+
ASM_OFFSET( 4c, FF, Thread, m_uHijackedReturnValueFlags)
6160
#endif
6261

6362
ASM_SIZEOF( 14, 20, EHEnum)

src/coreclr/nativeaot/Runtime/StackFrameIterator.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,7 +1107,7 @@ void StackFrameIterator::UnwindFuncletInvokeThunk()
11071107

11081108
if (EQUALS_RETURN_ADDRESS(m_ControlPC, RhpCallCatchFunclet2))
11091109
{
1110-
SP += 3; // 3 locals
1110+
SP += 2 + 1; // 2 locals and stack alignment
11111111
}
11121112
else
11131113
{
@@ -1143,14 +1143,7 @@ void StackFrameIterator::UnwindFuncletInvokeThunk()
11431143
m_funcletPtrs.pRbx = m_RegDisplay.pRbx;
11441144
}
11451145

1146-
if (EQUALS_RETURN_ADDRESS(m_ControlPC, RhpCallCatchFunclet2))
1147-
{
1148-
SP += 2; // 2 locals
1149-
}
1150-
else
1151-
{
1152-
SP++; // 1 local
1153-
}
1146+
SP++; // local / stack alignment
11541147
m_RegDisplay.pRdi = SP++;
11551148
m_RegDisplay.pRsi = SP++;
11561149
m_RegDisplay.pRbx = SP++;

src/coreclr/nativeaot/Runtime/amd64/AsmMacros.inc

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -359,16 +359,11 @@ PTFF_SAVE_ALL_PRESERVED equ 000000F7h ;; NOTE: RBP is not included in this set
359359
PTFF_SAVE_RSP equ 00008000h
360360
PTFF_SAVE_RAX equ 00000100h ;; RAX is saved in hijack handler - in case it contains a GC ref
361361
PTFF_SAVE_ALL_SCRATCH equ 00007F00h
362-
PTFF_THREAD_ABORT equ 00100000h ;; indicates that ThreadAbortException should be thrown when returning from the transition
363-
PTFF_THREAD_HIJACK equ 00200000h ;; indicates that this is a frame for a hijacked call
362+
PTFF_THREAD_HIJACK equ 00100000h ;; indicates that this is a frame for a hijacked call
364363

365364
;; These must match the TrapThreadsFlags enum
366365
TrapThreadsFlags_None equ 0
367-
TrapThreadsFlags_AbortInProgress equ 1
368-
TrapThreadsFlags_TrapThreads equ 2
369-
370-
;; This must match HwExceptionCode.STATUS_NATIVEAOT_THREAD_ABORT
371-
STATUS_NATIVEAOT_THREAD_ABORT equ 43h
366+
TrapThreadsFlags_TrapThreads equ 1
372367

373368
;;
374369
;; CONSTANTS -- SYMBOLS

src/coreclr/nativeaot/Runtime/amd64/ExceptionHandling.asm

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -371,12 +371,11 @@ endm
371371
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
372372
NESTED_ENTRY RhpCallCatchFunclet, _TEXT
373373

374-
FUNCLET_CALL_PROLOGUE 3, 0
374+
FUNCLET_CALL_PROLOGUE 2, 1
375375

376376
;; locals
377377
rsp_offsetof_thread = rsp_offsetof_locals
378378
rsp_offsetof_resume_ip = rsp_offsetof_locals + 8;
379-
rsp_offsetof_is_handling_thread_abort = rsp_offsetof_locals + 16;
380379

381380
mov [rsp + rsp_offsetof_arguments + 0h], rcx ;; save arguments for later
382381
mov [rsp + rsp_offsetof_arguments + 8h], rdx
@@ -386,9 +385,6 @@ NESTED_ENTRY RhpCallCatchFunclet, _TEXT
386385
INLINE_GETTHREAD rax, rbx ;; rax <- Thread*, rbx is trashed
387386
mov [rsp + rsp_offsetof_thread], rax ;; save Thread* for later
388387

389-
cmp rcx, [rax + OFFSETOF__Thread__m_threadAbortException]
390-
setz byte ptr [rsp + rsp_offsetof_is_handling_thread_abort]
391-
392388
;; Clear the DoNotTriggerGc state before calling out to our managed catch funclet.
393389
lock and dword ptr [rax + OFFSETOF__Thread__m_ThreadStateFlags], NOT TSF_DoNotTriggerGc
394390

@@ -508,20 +504,8 @@ endif
508504
xor r9, r9 ;; r9 <- 0
509505
endif
510506

511-
test [RhpTrapThreads], TrapThreadsFlags_AbortInProgress
512-
jz @f
513-
514-
;; test if the exception handled by the catch was the ThreadAbortException
515-
cmp byte ptr [rsp + rsp_offsetof_is_handling_thread_abort], 0
516-
je @f
517-
518-
;; It was the ThreadAbortException, so rethrow it
519-
mov rcx, STATUS_NATIVEAOT_THREAD_ABORT
520-
mov rdx, rax ;; rdx <- continuation address as exception RIP
521-
lea rax, [RhpThrowHwEx] ;; Throw the ThreadAbortException as a special kind of hardware exception
522-
523507
;; reset RSP and jump to RAX
524-
@@: mov rsp, r8 ;; reset the SP to resume SP value
508+
mov rsp, r8 ;; reset the SP to resume SP value
525509

526510
;; if have shadow stack, then we need to reconcile it with the rsp change we have just made. (r11 must contain target SSP)
527511
rdsspq r9 ;; NB, r9 == 0 prior to this

src/coreclr/nativeaot/Runtime/amd64/GcProbe.S

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,16 +124,8 @@ NESTED_ENTRY RhpWaitForGC, _TEXT, NoHandler
124124
mov rdi, [rbx + OFFSETOF__Thread__m_pDeferredTransitionFrame]
125125
call C_FUNC(RhpWaitForGC2)
126126

127-
mov rax, [rbx + OFFSETOF__Thread__m_pDeferredTransitionFrame]
128-
test dword ptr [rax + OFFSETOF__PInvokeTransitionFrame__m_Flags], PTFF_THREAD_ABORT
129-
jnz LOCAL_LABEL(Abort)
130127
POP_PROBE_FRAME
131128
ret
132-
LOCAL_LABEL(Abort):
133-
POP_PROBE_FRAME
134-
mov rcx, STATUS_NATIVEAOT_THREAD_ABORT
135-
pop rdx // return address as exception RIP
136-
jmp C_FUNC(RhpThrowHwEx) // Throw the ThreadAbortException as a special kind of hardware exception
137129

138130
NESTED_END RhpWaitForGC, _TEXT
139131

src/coreclr/nativeaot/Runtime/amd64/GcProbe.asm

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,6 @@ NESTED_ENTRY RhpGcProbeHijack, _TEXT
107107
jmp RhpWaitForGC
108108
NESTED_END RhpGcProbeHijack, _TEXT
109109

110-
EXTERN RhpThrowHwEx : PROC
111-
112110
NESTED_ENTRY RhpWaitForGC, _TEXT
113111
PUSH_PROBE_FRAME rdx, rax, rcx
114112
END_PROLOGUE
@@ -117,16 +115,8 @@ NESTED_ENTRY RhpWaitForGC, _TEXT
117115
mov rcx, [rbx + OFFSETOF__Thread__m_pDeferredTransitionFrame]
118116
call RhpWaitForGC2
119117

120-
mov rax, [rbx + OFFSETOF__Thread__m_pDeferredTransitionFrame]
121-
test dword ptr [rax + OFFSETOF__PInvokeTransitionFrame__m_Flags], PTFF_THREAD_ABORT
122-
jnz Abort
123118
POP_PROBE_FRAME
124119
ret
125-
Abort:
126-
POP_PROBE_FRAME
127-
mov rcx, STATUS_NATIVEAOT_THREAD_ABORT
128-
pop rdx ;; return address as exception RIP
129-
jmp RhpThrowHwEx ;; Throw the ThreadAbortException as a special kind of hardware exception
130120

131121
NESTED_END RhpWaitForGC, _TEXT
132122

src/coreclr/nativeaot/Runtime/arm/GcProbe.S

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,9 @@ NESTED_ENTRY RhpWaitForGC, _TEXT, NoHandler
8888
ldr r0, [r2, #OFFSETOF__Thread__m_pDeferredTransitionFrame]
8989
bl RhpWaitForGC2
9090

91-
ldr r2, [sp, #OFFSETOF__PInvokeTransitionFrame__m_Flags]
92-
tst r2, #PTFF_THREAD_ABORT
93-
bne LOCAL_LABEL(ThrowThreadAbort)
94-
9591
POP_PROBE_FRAME
9692
bx lr
9793

98-
LOCAL_LABEL(ThrowThreadAbort):
99-
POP_PROBE_FRAME
100-
mov r0, #STATUS_NATIVEAOT_THREAD_ABORT
101-
mov r1, lr // return address as exception PC
102-
b C_FUNC(RhpThrowHwEx)
10394
NESTED_END RhpWaitForGC
10495

10596
LEAF_ENTRY RhpGcPoll

src/coreclr/nativeaot/Runtime/arm64/AsmMacros.h

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,14 @@ PTFF_SAVE_ALL_SCRATCH equ 0x3FFFF800 ;; NOTE: X0-X18
5858
PTFF_SAVE_FP equ 0x40000000
5959
PTFF_SAVE_LR equ 0x80000000
6060

61-
PTFF_THREAD_HIJACK_HI equ 0x00000002 // upper 32 bits of the PTFF_THREAD_HIJACK
62-
63-
;; Bit position for the flags above, to be used with tbz / tbnz instructions
64-
PTFF_THREAD_ABORT_BIT equ 32
61+
PTFF_THREAD_HIJACK_HI equ 0x00000001 // upper 32 bits of the PTFF_THREAD_HIJACK
6562

6663
;; These must match the TrapThreadsFlags enum
6764
TrapThreadsFlags_None equ 0
68-
TrapThreadsFlags_AbortInProgress equ 1
69-
TrapThreadsFlags_TrapThreads equ 2
65+
TrapThreadsFlags_TrapThreads equ 1
7066

7167
;; Bit position for the flags above, to be used with tbz / tbnz instructions
72-
TrapThreadsFlags_AbortInProgress_Bit equ 0
73-
TrapThreadsFlags_TrapThreads_Bit equ 1
74-
75-
;; This must match HwExceptionCode.STATUS_NATIVEAOT_THREAD_ABORT
76-
STATUS_NATIVEAOT_THREAD_ABORT equ 0x43
68+
TrapThreadsFlags_TrapThreads_Bit equ 0
7769

7870
;;
7971
;; Rename fields of nested structs

0 commit comments

Comments
 (0)