diff --git a/src/coreclr/dlls/mscoree/exports.cpp b/src/coreclr/dlls/mscoree/exports.cpp index ca22f3ad324b73..3da6254b0dfb2f 100644 --- a/src/coreclr/dlls/mscoree/exports.cpp +++ b/src/coreclr/dlls/mscoree/exports.cpp @@ -23,6 +23,25 @@ #define ASSERTE_ALL_BUILDS(expr) _ASSERTE_ALL_BUILDS((expr)) +#ifdef TARGET_UNIX +#define NO_HOSTING_API_RETURN_ADDRESS ((void*)ULONG_PTR_MAX) +void* g_hostingApiReturnAddress = NO_HOSTING_API_RETURN_ADDRESS; + +class HostingApiFrameHolder +{ +public: + HostingApiFrameHolder(void* returnAddress) + { + g_hostingApiReturnAddress = returnAddress; + } + + ~HostingApiFrameHolder() + { + g_hostingApiReturnAddress = NO_HOSTING_API_RETURN_ADDRESS; + } +}; +#endif // TARGET_UNIX + // Holder for const wide strings typedef NewArrayHolder ConstWStringHolder; @@ -194,6 +213,7 @@ extern "C" int coreclr_create_delegate(void*, unsigned int, const char*, const c // HRESULT indicating status of the operation. S_OK if the assembly was successfully executed // extern "C" +NOINLINE DLLEXPORT int coreclr_initialize( const char* exePath, @@ -212,6 +232,10 @@ int coreclr_initialize( bool hostPolicyEmbedded = false; PInvokeOverrideFn* pinvokeOverride = nullptr; +#ifdef TARGET_UNIX + HostingApiFrameHolder apiFrameHolder(_ReturnAddress()); +#endif + ConvertConfigPropertiesToUnicode( propertyKeys, propertyValues, @@ -420,6 +444,7 @@ int coreclr_create_delegate( // HRESULT indicating status of the operation. S_OK if the assembly was successfully executed // extern "C" +NOINLINE DLLEXPORT int coreclr_execute_assembly( void* hostHandle, @@ -435,6 +460,10 @@ int coreclr_execute_assembly( } *exitCode = -1; +#ifdef TARGET_UNIX + HostingApiFrameHolder apiFrameHolder(_ReturnAddress()); +#endif + ICLRRuntimeHost4* host = reinterpret_cast(hostHandle); ConstWStringArrayHolder argvW; diff --git a/src/coreclr/vm/exceptionhandling.cpp b/src/coreclr/vm/exceptionhandling.cpp index 9623dee9dfdcfa..441c6a6c6a3715 100644 --- a/src/coreclr/vm/exceptionhandling.cpp +++ b/src/coreclr/vm/exceptionhandling.cpp @@ -4523,6 +4523,8 @@ VOID UnwindManagedExceptionPass2(PAL_SEHException& ex, CONTEXT* unwindStartConte EEPOLICY_HANDLE_FATAL_ERROR(COR_E_EXECUTIONENGINE); } +extern void* g_hostingApiReturnAddress; + //--------------------------------------------------------------------------------------- // // This functions performs dispatching of a managed exception. @@ -4724,7 +4726,8 @@ VOID DECLSPEC_NORETURN UnwindManagedExceptionPass1(PAL_SEHException& ex, CONTEXT STRESS_LOG2(LF_EH, LL_INFO100, "Processing exception at native frame: IP = %p, SP = %p \n", controlPc, sp); - if (controlPc == 0) + // Consider the exception unhandled if the unwinding cannot proceed further or if it went past the coreclr_initialize or coreclr_execute_assembly + if ((controlPc == 0) || (controlPc == (UINT_PTR)g_hostingApiReturnAddress)) { if (!GetThread()->HasThreadStateNC(Thread::TSNC_ProcessedUnhandledException)) { diff --git a/src/coreclr/vm/stackwalk.cpp b/src/coreclr/vm/stackwalk.cpp index 08faf72c69e3dd..6b6d8c10f29daf 100644 --- a/src/coreclr/vm/stackwalk.cpp +++ b/src/coreclr/vm/stackwalk.cpp @@ -709,6 +709,8 @@ PCODE Thread::VirtualUnwindNonLeafCallFrame(T_CONTEXT* pContext, KNONVOLATILE_CO return uControlPc; } +extern void* g_hostingApiReturnAddress; + // static UINT_PTR Thread::VirtualUnwindToFirstManagedCallFrame(T_CONTEXT* pContext) { @@ -751,8 +753,9 @@ UINT_PTR Thread::VirtualUnwindToFirstManagedCallFrame(T_CONTEXT* pContext) uControlPc = GetIP(pContext); - if (uControlPc == 0) + if ((uControlPc == 0) || (uControlPc == (PCODE)g_hostingApiReturnAddress)) { + uControlPc = 0; break; } #endif // !TARGET_UNIX