Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 05e3582

Browse files
authored
Port to 3.1 - Fix handling thread abort in HelperMethodFrame (#28029)
The thread abort during func eval from a managed debugger on Linux and macOS was sometimes causing the debuggee to exit with unhandled c++ PAL_SEHException. The reason is that the thread abort detection that is done in the HELPER_METHOD_FRAME_BEGIN and ...END macros was done outside of the INSTALL_MANAGED_EXCEPTION_DISPATCHER / UNINSTALL_MANAGED_EXCEPTION_DISPATCHER region and so the exception thrown when thread abort request is detected there was not being caught and translated into a call to DispatchManagedException. Since the caller frame was a managed function frame, the C++ exception handling didn't know how to unwind it and so it declared the exception being unhandled. This fix moves the check for the thread abort out of the HelperMethodFrame::Push/Pop into a new method and calls that explicitly from the HELPER_METHOD_* macros inside the INSTALL_MANAGED_EXCEPTION_DISPATCHER / UNINSTALL_MANAGED_EXCEPTION_DISPATCHER region. That way, the thread abort exception is properly handled. # Customer impact .NET Core apps randomly terminate with unhandled c++ PAL_SEHException when a customer debugs an app under managed debuggers (VS Code, 3rd party debuggers) and tries to view a property value. # Regression? No, this problem has been present since .NET Core 1.0 # Testing CoreCLR pri 1 tests and .NET Core debugger tests. # Risk
1 parent 83c2d68 commit 05e3582

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/vm/fcall.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -567,19 +567,21 @@ LPVOID __FCThrowArgument(LPVOID me, enum RuntimeExceptionKind reKind, LPCWSTR ar
567567
FORLAZYMACHSTATE_DEBUG_OK_TO_RETURN_END; \
568568
INDEBUG(__helperframe.SetAddrOfHaveCheckedRestoreState(&__haveCheckedRestoreState)); \
569569
DEBUG_ASSURE_NO_RETURN_BEGIN(HELPER_METHOD_FRAME); \
570-
INCONTRACT(FCallGCCanTrigger::Enter()); \
571-
__helperframe.Push(); \
572-
MAKE_CURRENT_THREAD_AVAILABLE_EX(__helperframe.GetThread()); \
570+
INCONTRACT(FCallGCCanTrigger::Enter());
573571

574572
#define HELPER_METHOD_FRAME_BEGIN_EX(ret, helperFrame, gcpoll, allowGC) \
575573
HELPER_METHOD_FRAME_BEGIN_EX_BODY(ret, helperFrame, gcpoll, allowGC) \
576574
/* <TODO>TODO TURN THIS ON!!! </TODO> */ \
577575
/* gcpoll; */ \
578576
INSTALL_MANAGED_EXCEPTION_DISPATCHER; \
577+
__helperframe.Push(); \
578+
MAKE_CURRENT_THREAD_AVAILABLE_EX(__helperframe.GetThread()); \
579579
INSTALL_UNWIND_AND_CONTINUE_HANDLER_FOR_HMF(&__helperframe);
580580

581581
#define HELPER_METHOD_FRAME_BEGIN_EX_NOTHROW(ret, helperFrame, gcpoll, allowGC, probeFailExpr) \
582582
HELPER_METHOD_FRAME_BEGIN_EX_BODY(ret, helperFrame, gcpoll, allowGC) \
583+
__helperframe.Push(); \
584+
MAKE_CURRENT_THREAD_AVAILABLE_EX(__helperframe.GetThread()); \
583585
/* <TODO>TODO TURN THIS ON!!! </TODO> */ \
584586
/* gcpoll; */
585587

@@ -596,7 +598,6 @@ LPVOID __FCThrowArgument(LPVOID me, enum RuntimeExceptionKind reKind, LPCWSTR ar
596598
#define HELPER_METHOD_FRAME_END_EX_BODY(gcpoll,allowGC) \
597599
/* <TODO>TODO TURN THIS ON!!! </TODO> */ \
598600
/* gcpoll; */ \
599-
__helperframe.Pop(); \
600601
DEBUG_ASSURE_NO_RETURN_END(HELPER_METHOD_FRAME); \
601602
INCONTRACT(FCallGCCanTrigger::Leave(__FUNCTION__, __FILE__, __LINE__)); \
602603
FORLAZYMACHSTATE(alwaysZero = \
@@ -607,10 +608,12 @@ LPVOID __FCThrowArgument(LPVOID me, enum RuntimeExceptionKind reKind, LPCWSTR ar
607608

608609
#define HELPER_METHOD_FRAME_END_EX(gcpoll,allowGC) \
609610
UNINSTALL_UNWIND_AND_CONTINUE_HANDLER; \
611+
__helperframe.Pop(); \
610612
UNINSTALL_MANAGED_EXCEPTION_DISPATCHER; \
611613
HELPER_METHOD_FRAME_END_EX_BODY(gcpoll,allowGC);
612614

613615
#define HELPER_METHOD_FRAME_END_EX_NOTHROW(gcpoll,allowGC) \
616+
__helperframe.Pop(); \
614617
HELPER_METHOD_FRAME_END_EX_BODY(gcpoll,allowGC);
615618

616619
#define HELPER_METHOD_FRAME_BEGIN_ATTRIB(attribs) \

0 commit comments

Comments
 (0)