From: Aleksey Kliger Date: Fri, 13 May 2016 21:35:40 +0000 (-0400) Subject: [runtime] MonoError-ize mono_runtime_delegate_invoke X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=3e0081e924220b9630136e2c1744796ea2bfd00a;p=mono.git [runtime] MonoError-ize mono_runtime_delegate_invoke Mark it external only. Runtime can use mono_runtime_delegate_invoke_checked or mono_runtime_delegate_try_invoke. --- diff --git a/mono/metadata/object-internals.h b/mono/metadata/object-internals.h index 2587d877e64..27085b47f8e 100644 --- a/mono/metadata/object-internals.h +++ b/mono/metadata/object-internals.h @@ -1709,6 +1709,14 @@ mono_runtime_invoke_checked (MonoMethod *method, void *obj, void **params, MonoE void* mono_compile_method_checked (MonoMethod *method, MonoError *error); +MonoObject* +mono_runtime_delegate_try_invoke (MonoObject *delegate, void **params, + MonoObject **exc, MonoError *error); + +MonoObject* +mono_runtime_delegate_invoke_checked (MonoObject *delegate, void **params, + MonoError *error); + MonoArray* mono_runtime_get_main_args_checked (MonoError *error); diff --git a/mono/metadata/object.c b/mono/metadata/object.c index a211180eff4..0fe846451ae 100644 --- a/mono/metadata/object.c +++ b/mono/metadata/object.c @@ -3966,6 +3966,44 @@ mono_runtime_delegate_invoke (MonoObject *delegate, void **params, MonoObject ** MONO_REQ_GC_UNSAFE_MODE; MonoError error; + if (exc) { + MonoObject *result = mono_runtime_delegate_try_invoke (delegate, params, exc, &error); + if (*exc) { + mono_error_cleanup (&error); + return NULL; + } else { + if (!is_ok (&error)) + *exc = (MonoObject*)mono_error_convert_to_exception (&error); + return result; + } + } else { + MonoObject *result = mono_runtime_delegate_invoke_checked (delegate, params, &error); + mono_error_raise_exception (&error); /* FIXME don't raise here */ + return result; + } +} + +/** + * mono_runtime_delegate_try_invoke: + * @delegate: pointer to a delegate object. + * @params: parameters for the delegate. + * @exc: Pointer to the exception result. + * @error: set on error + * + * Invokes the delegate method @delegate with the parameters provided. + * + * You can pass NULL as the exc argument if you don't want to + * catch exceptions, otherwise, *exc will be set to the exception + * thrown, if any. On failure to execute, @error will be set. + * if an exception is thrown, you can't use the + * MonoObject* result from the function. + */ +MonoObject* +mono_runtime_delegate_try_invoke (MonoObject *delegate, void **params, MonoObject **exc, MonoError *error) +{ + MONO_REQ_GC_UNSAFE_MODE; + + mono_error_init (error); MonoMethod *im; MonoClass *klass = delegate->vtable->klass; MonoObject *o; @@ -3975,19 +4013,32 @@ mono_runtime_delegate_invoke (MonoObject *delegate, void **params, MonoObject ** g_error ("Could not lookup delegate invoke method for delegate %s", mono_type_get_full_name (klass)); if (exc) { - o = mono_runtime_try_invoke (im, delegate, params, exc, &error); - if (*exc == NULL && !mono_error_ok (&error)) - *exc = (MonoObject*) mono_error_convert_to_exception (&error); - else - mono_error_cleanup (&error); + o = mono_runtime_try_invoke (im, delegate, params, exc, error); } else { - o = mono_runtime_invoke_checked (im, delegate, params, &error); - mono_error_raise_exception (&error); /* FIXME don't raise here */ + o = mono_runtime_invoke_checked (im, delegate, params, error); } return o; } +/** + * mono_runtime_delegate_invoke_checked: + * @delegate: pointer to a delegate object. + * @params: parameters for the delegate. + * @error: set on error + * + * Invokes the delegate method @delegate with the parameters provided. + * + * On failure @error will be set and you can't use the MonoObject* + * result from the function. + */ +MonoObject* +mono_runtime_delegate_invoke_checked (MonoObject *delegate, void **params, MonoError *error) +{ + mono_error_init (error); + return mono_runtime_delegate_try_invoke (delegate, params, NULL, error); +} + static char **main_args = NULL; static int num_main_args = 0; @@ -4414,7 +4465,13 @@ call_unhandled_exception_delegate (MonoDomain *domain, MonoObject *delegate, Mon pa [0] = domain->domain; pa [1] = create_unhandled_exception_eventargs (exc, &error); mono_error_assert_ok (&error); - mono_runtime_delegate_invoke (delegate, pa, &e); + mono_runtime_delegate_try_invoke (delegate, pa, &e, &error); + if (!is_ok (&error)) { + if (e == NULL) + e = (MonoObject*)mono_error_convert_to_exception (&error); + else + mono_error_cleanup (&error); + } if (domain != current_domain) mono_domain_set_internal_with_options (current_domain, FALSE); @@ -7108,7 +7165,9 @@ ves_icall_System_Runtime_Remoting_Messaging_AsyncResult_Invoke (MonoAsyncResult ac = (MonoAsyncCall*) ares->object_data; if (!ac) { - res = mono_runtime_delegate_invoke (ares->async_delegate, (void**) &ares->async_state, NULL); + res = mono_runtime_delegate_invoke_checked (ares->async_delegate, (void**) &ares->async_state, &error); + if (mono_error_set_pending_exception (&error)) + return NULL; } else { gpointer wait_event = NULL; diff --git a/mono/metadata/object.h b/mono/metadata/object.h index bf23c26c61a..63f48ccca62 100644 --- a/mono/metadata/object.h +++ b/mono/metadata/object.h @@ -254,6 +254,7 @@ mono_get_delegate_begin_invoke (MonoClass *klass); MONO_API MonoMethod * mono_get_delegate_end_invoke (MonoClass *klass); +MONO_RT_EXTERNAL_ONLY MONO_API MonoObject* mono_runtime_delegate_invoke (MonoObject *delegate, void **params, MonoObject **exc); diff --git a/mono/metadata/runtime.c b/mono/metadata/runtime.c index 1c41c797db4..078b4cef997 100644 --- a/mono/metadata/runtime.c +++ b/mono/metadata/runtime.c @@ -57,6 +57,7 @@ mono_runtime_is_shutting_down (void) static void fire_process_exit_event (MonoDomain *domain, gpointer user_data) { + MonoError error; MonoClassField *field; gpointer pa [2]; MonoObject *delegate, *exc; @@ -70,7 +71,8 @@ fire_process_exit_event (MonoDomain *domain, gpointer user_data) pa [0] = domain; pa [1] = NULL; - mono_runtime_delegate_invoke (delegate, pa, &exc); + mono_runtime_delegate_try_invoke (delegate, pa, &exc, &error); + mono_error_cleanup (&error); } static void diff --git a/mono/metadata/threads.c b/mono/metadata/threads.c index 253e9c32c3f..103f48f8b66 100644 --- a/mono/metadata/threads.c +++ b/mono/metadata/threads.c @@ -744,7 +744,8 @@ static guint32 WINAPI start_wrapper_internal(void *data) g_assert (start_delegate != NULL); args [0] = start_arg; /* we may want to handle the exception here. See comment below on unhandled exceptions */ - mono_runtime_delegate_invoke (start_delegate, args, NULL); + mono_runtime_delegate_invoke_checked (start_delegate, args, &error); + mono_error_raise_exception (&error); /* FIXME don't raise here */ } /* If the thread calls ExitThread at all, this remaining code