Skip to content

Commit

Permalink
Expose an icall to report unhandled exceptions in mscorlib.
Browse files Browse the repository at this point in the history
  • Loading branch information
TautvydasZilys authored and Josh Peterson committed Apr 19, 2021
1 parent 02c0f70 commit e4495a6
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 4 deletions.
3 changes: 3 additions & 0 deletions mcs/class/referencesource/mscorlib/system/exception.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1138,6 +1138,9 @@ internal Exception FixRemotingException ()

return this;
}

[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal static extern void ReportUnhandledException(Exception exception);
#endif
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,10 +424,17 @@ public override void Post(SendOrPostCallback d, object state)
[MonoPInvokeCallback(typeof(InvocationEntryDelegate))]
private static void InvocationEntry(IntPtr arg)
{
var invocationContextHandle = GCHandle.FromIntPtr(arg);
var invocationContext = (InvocationContext)invocationContextHandle.Target;
invocationContextHandle.Free();
invocationContext.Invoke();
try
{
var invocationContextHandle = GCHandle.FromIntPtr(arg);
var invocationContext = (InvocationContext)invocationContextHandle.Target;
invocationContextHandle.Free();
invocationContext.Invoke();
}
catch (Exception e)
{
Exception.ReportUnhandledException(e);
}
}

[AttributeUsage (AttributeTargets.Method)]
Expand Down
7 changes: 7 additions & 0 deletions mono/metadata/exception.c
Original file line number Diff line number Diff line change
Expand Up @@ -1533,3 +1533,10 @@ mono_error_convert_to_exception_handle (MonoError *error)
return is_ok (error) ? MONO_HANDLE_CAST (MonoException, NULL_HANDLE)
: MONO_HANDLE_NEW (MonoException, mono_error_convert_to_exception (error));
}

void
ves_icall_System_Exception_ReportUnhandledException(MonoObject *exc)
{
mono_unhandled_exception (exc);
mono_invoke_unhandled_exception_hook (exc);
}
3 changes: 3 additions & 0 deletions mono/metadata/exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ typedef void (*MonoUnhandledExceptionFunc) (MonoObject *exc, void *user
MONO_API void mono_install_unhandled_exception_hook (MonoUnhandledExceptionFunc func, void *user_data);
void mono_invoke_unhandled_exception_hook (MonoObject *exc);

void
ves_icall_System_Exception_ReportUnhandledException (MonoObject *exc);

MONO_END_DECLS

#endif /* _MONO_METADATA_EXCEPTION_H_ */
3 changes: 3 additions & 0 deletions mono/metadata/icall-def.h
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,9 @@ HANDLES(GC_7, "_SuppressFinalize", ves_icall_System_GC_SuppressFinalize, void, 1
HANDLES(GC_9, "get_ephemeron_tombstone", ves_icall_System_GC_get_ephemeron_tombstone, MonoObject, 0, ())
HANDLES(GC_8, "register_ephemeron_array", ves_icall_System_GC_register_ephemeron_array, void, 1, (MonoObject))

ICALL_TYPE(EXCEPTION, "System.Exception", EXCEPTION_1)
HANDLES(ICALL(EXCEPTION_1, "ReportUnhandledException", ves_icall_System_Exception_ReportUnhandledException))

ICALL_TYPE(CALDATA, "System.Globalization.CalendarData", CALDATA_1)
HANDLES(CALDATA_1, "fill_calendar_data", ves_icall_System_Globalization_CalendarData_fill_calendar_data, MonoBoolean, 3, (MonoCalendarData, MonoString, gint32))

Expand Down

0 comments on commit e4495a6

Please sign in to comment.