Merge pull request #3100 from lambdageek/dev/monoerror-exns
[mono.git] / mono / mini / jit-icalls.c
index b4f33c0b489a282b71a1cd2cc67d9ed0d024200d..8651aa25ec497c574a6d492e6ae6e9b324be8e14 100644 (file)
@@ -19,6 +19,7 @@
 
 #include "jit-icalls.h"
 #include <mono/utils/mono-error-internals.h>
+#include <mono/metadata/exception-internals.h>
 #include <mono/metadata/threads-types.h>
 #include <mono/metadata/reflection-internals.h>
 
@@ -1189,13 +1190,21 @@ mono_create_corlib_exception_0 (guint32 token)
 MonoException *
 mono_create_corlib_exception_1 (guint32 token, MonoString *arg)
 {
-       return mono_exception_from_token_two_strings (mono_defaults.corlib, token, arg, NULL);
+       MonoError error;
+       MonoException *ret = mono_exception_from_token_two_strings_checked (
+               mono_defaults.corlib, token, arg, NULL, &error);
+       mono_error_set_pending_exception (&error);
+       return ret;
 }
 
 MonoException *
 mono_create_corlib_exception_2 (guint32 token, MonoString *arg1, MonoString *arg2)
 {
-       return mono_exception_from_token_two_strings (mono_defaults.corlib, token, arg1, arg2);
+       MonoError error;
+       MonoException *ret = mono_exception_from_token_two_strings_checked (
+               mono_defaults.corlib, token, arg1, arg2, &error);
+       mono_error_set_pending_exception (&error);
+       return ret;
 }
 
 MonoObject*
@@ -1487,15 +1496,15 @@ mono_fill_method_rgctx (MonoMethodRuntimeGenericContext *mrgctx, int index)
  * out parameter.
  */
 static gpointer
-resolve_iface_call (MonoObject *this_obj, int imt_slot, MonoMethod *imt_method, gpointer *out_arg, gboolean caller_gsharedvt)
+resolve_iface_call (MonoObject *this_obj, int imt_slot, MonoMethod *imt_method, gpointer *out_arg, gboolean caller_gsharedvt, MonoError *error)
 {
-       MonoError error;
        MonoVTable *vt;
        gpointer *imt, *vtable_slot;
        MonoMethod *impl_method, *generic_virtual = NULL, *variant_iface = NULL;
        gpointer addr, compiled_method, aot_addr;
        gboolean need_rgctx_tramp = FALSE, need_unbox_tramp = FALSE;
 
+       mono_error_init (error);
        if (!this_obj)
                /* The caller will handle it */
                return NULL;
@@ -1503,11 +1512,12 @@ resolve_iface_call (MonoObject *this_obj, int imt_slot, MonoMethod *imt_method,
        vt = this_obj->vtable;
        imt = (gpointer*)vt - MONO_IMT_SIZE;
 
-       vtable_slot = mini_resolve_imt_method (vt, imt + imt_slot, imt_method, &impl_method, &aot_addr, &need_rgctx_tramp, &variant_iface);
+       vtable_slot = mini_resolve_imt_method (vt, imt + imt_slot, imt_method, &impl_method, &aot_addr, &need_rgctx_tramp, &variant_iface, error);
+       return_val_if_nok (error, NULL);
 
        // FIXME: This can throw exceptions
-       addr = compiled_method = mono_compile_method_checked (impl_method, &error);
-       mono_error_assert_ok (&error);
+       addr = compiled_method = mono_compile_method_checked (impl_method, error);
+       mono_error_assert_ok (error);
        g_assert (addr);
 
        if (imt_method->is_inflated && ((MonoMethodInflated*)imt_method)->context.method_inst)
@@ -1537,7 +1547,13 @@ resolve_iface_call (MonoObject *this_obj, int imt_slot, MonoMethod *imt_method,
 gpointer
 mono_resolve_iface_call_gsharedvt (MonoObject *this_obj, int imt_slot, MonoMethod *imt_method, gpointer *out_arg)
 {
-       return resolve_iface_call (this_obj, imt_slot, imt_method, out_arg, TRUE);
+       MonoError error;
+       gpointer res = resolve_iface_call (this_obj, imt_slot, imt_method, out_arg, TRUE, &error);
+       if (!is_ok (&error)) {
+               MonoException *ex = mono_error_convert_to_exception (&error);
+               mono_llvm_throw_exception ((MonoObject*)ex);
+       }
+       return res;
 }
 
 static gboolean
@@ -1726,7 +1742,11 @@ mono_resolve_generic_virtual_iface_call (MonoVTable *vt, int imt_slot, MonoMetho
 
        imt = (gpointer*)vt - MONO_IMT_SIZE;
 
-       mini_resolve_imt_method (vt, imt + imt_slot, generic_virtual, &m, &aot_addr, &need_rgctx_tramp, &variant_iface);
+       mini_resolve_imt_method (vt, imt + imt_slot, generic_virtual, &m, &aot_addr, &need_rgctx_tramp, &variant_iface, &error);
+       if (!is_ok (&error)) {
+               MonoException *ex = mono_error_convert_to_exception (&error);
+               mono_llvm_throw_exception ((MonoObject*)ex);
+       }
 
        if (vt->klass->valuetype)
                need_unbox_tramp = TRUE;