From 189f8b7c1e243b63b25637a5e68c54d5e34f7b2c Mon Sep 17 00:00:00 2001 From: Jay Krell Date: Mon, 29 Jul 2019 16:39:44 -0700 Subject: [PATCH] HANDLE_FUNCTION_RETURN_VAL must not use handles in current frame (mono/mono#15873) Commit migrated from https://github.com/mono/mono/commit/929e3135bb12c55f6976763f43dda1371465d1fa --- src/mono/mono/metadata/cominterop.c | 11 +++++++---- src/mono/mono/metadata/custom-attrs.c | 5 +++-- src/mono/mono/metadata/dynamic-image.c | 2 +- src/mono/mono/metadata/handle.h | 2 ++ src/mono/mono/metadata/object.c | 5 +++-- src/mono/mono/metadata/sre-save.c | 2 +- src/mono/mono/metadata/sre.c | 11 +++++------ src/mono/mono/metadata/threadpool.c | 2 +- src/mono/mono/metadata/threads.c | 2 +- 9 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/mono/mono/metadata/cominterop.c b/src/mono/mono/metadata/cominterop.c index 84131ee..4ef0685 100644 --- a/src/mono/mono/metadata/cominterop.c +++ b/src/mono/mono/metadata/cominterop.c @@ -355,7 +355,8 @@ cominterop_object_is_rcw (MonoObject *obj_raw) HANDLE_FUNCTION_ENTER (); MONO_HANDLE_DCL (MonoObject, obj); MonoRealProxyHandle real_proxy; - HANDLE_FUNCTION_RETURN_VAL (cominterop_object_is_rcw_handle (obj, &real_proxy)); + gboolean const result = cominterop_object_is_rcw_handle (obj, &real_proxy); + HANDLE_FUNCTION_RETURN_VAL (result); } static int @@ -2187,7 +2188,7 @@ cominterop_get_ccw (MonoObject* object_raw, MonoClass* itf) HANDLE_FUNCTION_ENTER (); ERROR_DECL (error); MONO_HANDLE_DCL (MonoObject, object); - gpointer ccw_entry = cominterop_get_ccw_checked (object, itf, error); + gpointer const ccw_entry = cominterop_get_ccw_checked (object, itf, error); mono_error_set_pending_exception (error); HANDLE_FUNCTION_RETURN_VAL (ccw_entry); } @@ -2277,7 +2278,8 @@ mono_marshal_free_ccw (MonoObject* object_raw) HANDLE_FUNCTION_ENTER (); MONO_HANDLE_DCL (MonoObject, object); - HANDLE_FUNCTION_RETURN_VAL (mono_marshal_free_ccw_handle (object)); + gboolean const result = mono_marshal_free_ccw_handle (object); + HANDLE_FUNCTION_RETURN_VAL (result); } /** @@ -3697,7 +3699,8 @@ mono_cominterop_get_com_interface (MonoObject *object_raw, MonoClass *ic, MonoEr { HANDLE_FUNCTION_ENTER (); MONO_HANDLE_DCL (MonoObject, object); - HANDLE_FUNCTION_RETURN_VAL (mono_cominterop_get_com_interface_internal (FALSE, object, ic, error)); + void* const result = mono_cominterop_get_com_interface_internal (FALSE, object, ic, error); + HANDLE_FUNCTION_RETURN_VAL (result); } static void* diff --git a/src/mono/mono/metadata/custom-attrs.c b/src/mono/mono/metadata/custom-attrs.c index c773ca7..8e61307 100644 --- a/src/mono/mono/metadata/custom-attrs.c +++ b/src/mono/mono/metadata/custom-attrs.c @@ -724,7 +724,8 @@ MonoCustomAttrInfo* mono_custom_attrs_from_builders (MonoImage *alloc_img, MonoImage *image, MonoArray* cattrs) { HANDLE_FUNCTION_ENTER (); - HANDLE_FUNCTION_RETURN_VAL (mono_custom_attrs_from_builders_handle (alloc_img, image, MONO_HANDLE_NEW (MonoArray, cattrs))); + MonoCustomAttrInfo* const result = mono_custom_attrs_from_builders_handle (alloc_img, image, MONO_HANDLE_NEW (MonoArray, cattrs)); + HANDLE_FUNCTION_RETURN_VAL (result); } static void @@ -2045,7 +2046,7 @@ mono_reflection_get_custom_attrs_info (MonoObject *obj_raw) HANDLE_FUNCTION_ENTER (); ERROR_DECL (error); MONO_HANDLE_DCL (MonoObject, obj); - MonoCustomAttrInfo *result = mono_reflection_get_custom_attrs_info_checked (obj, error); + MonoCustomAttrInfo * const result = mono_reflection_get_custom_attrs_info_checked (obj, error); mono_error_assert_ok (error); HANDLE_FUNCTION_RETURN_VAL (result); } diff --git a/src/mono/mono/metadata/dynamic-image.c b/src/mono/mono/metadata/dynamic-image.c index 451ba99..9ba6ca6 100644 --- a/src/mono/mono/metadata/dynamic-image.c +++ b/src/mono/mono/metadata/dynamic-image.c @@ -263,7 +263,7 @@ mono_reflection_lookup_dynamic_token (MonoImage *image, guint32 token, gboolean if (!handle_class) handle_class = &klass; - gpointer result = mono_reflection_resolve_object_handle (image, obj, handle_class, context, error); + gpointer const result = mono_reflection_resolve_object_handle (image, obj, handle_class, context, error); HANDLE_FUNCTION_RETURN_VAL (result); } #else /* DISABLE_REFLECTION_EMIT */ diff --git a/src/mono/mono/metadata/handle.h b/src/mono/mono/metadata/handle.h index 7b72082..8fbe79a 100644 --- a/src/mono/mono/metadata/handle.h +++ b/src/mono/mono/metadata/handle.h @@ -217,6 +217,8 @@ Icall macros MONO_RESTORE_WARNING // Return a non-pointer or non-managed pointer, e.g. gboolean. +// VAL should be a local variable or at least not use handles in the current frame. +// i.e. it is "val", not "expr". #define HANDLE_FUNCTION_RETURN_VAL(VAL) \ CLEAR_ICALL_FRAME; \ return (VAL); \ diff --git a/src/mono/mono/metadata/object.c b/src/mono/mono/metadata/object.c index 42e78ad..f959d67 100644 --- a/src/mono/mono/metadata/object.c +++ b/src/mono/mono/metadata/object.c @@ -161,7 +161,8 @@ mono_runtime_object_init_checked (MonoObject *this_obj_raw, MonoError *error) { HANDLE_FUNCTION_ENTER (); MONO_HANDLE_DCL (MonoObject, this_obj); - HANDLE_FUNCTION_RETURN_VAL (mono_runtime_object_init_handle (this_obj, error)); + gboolean const result = mono_runtime_object_init_handle (this_obj, error); + HANDLE_FUNCTION_RETURN_VAL (result); } /* The pseudo algorithm for type initialization from the spec @@ -8509,7 +8510,7 @@ get_native_backtrace (MonoException *exc_raw) { HANDLE_FUNCTION_ENTER (); MONO_HANDLE_DCL(MonoException, exc); - char * trace = mono_exception_handle_get_native_backtrace (exc); + char * const trace = mono_exception_handle_get_native_backtrace (exc); HANDLE_FUNCTION_RETURN_VAL (trace); } diff --git a/src/mono/mono/metadata/sre-save.c b/src/mono/mono/metadata/sre-save.c index 5ae49ab..0af60e5 100644 --- a/src/mono/mono/metadata/sre-save.c +++ b/src/mono/mono/metadata/sre-save.c @@ -186,7 +186,7 @@ image_create_token_raw (MonoDynamicImage *assembly, MonoObject* obj_raw, gboole HANDLE_FUNCTION_ENTER (); /* FIXME callers of image_create_token_raw should use handles */ error_init (error); MONO_HANDLE_DCL (MonoObject, obj); - guint32 result = mono_image_create_token (assembly, obj, create_methodspec, register_token, error); + guint32 const result = mono_image_create_token (assembly, obj, create_methodspec, register_token, error); HANDLE_FUNCTION_RETURN_VAL (result); } diff --git a/src/mono/mono/metadata/sre.c b/src/mono/mono/metadata/sre.c index 36f5964..2b48867 100644 --- a/src/mono/mono/metadata/sre.c +++ b/src/mono/mono/metadata/sre.c @@ -100,10 +100,9 @@ string_to_utf8_image_raw (MonoImage *image, MonoString *s_raw, MonoError *error) { /* FIXME all callers to string_to_utf8_image_raw should use handles */ HANDLE_FUNCTION_ENTER (); - char* result = NULL; error_init (error); MONO_HANDLE_DCL (MonoString, s); - result = mono_string_to_utf8_image (image, s, error); + char* const result = mono_string_to_utf8_image (image, s, error); HANDLE_FUNCTION_RETURN_VAL (result); } @@ -1668,7 +1667,7 @@ mono_reflection_type_get_handle (MonoReflectionType* ref_raw, MonoError *error) HANDLE_FUNCTION_ENTER (); error_init (error); MONO_HANDLE_DCL (MonoReflectionType, ref); - MonoType *result = mono_reflection_type_handle_mono_type (ref, error); + MonoType * const result = mono_reflection_type_handle_mono_type (ref, error); HANDLE_FUNCTION_RETURN_VAL (result); } @@ -1776,7 +1775,7 @@ mono_type_array_get_and_resolve_raw (MonoArray* array_raw, int idx, MonoError *e HANDLE_FUNCTION_ENTER(); /* FIXME callers of mono_type_array_get_and_resolve_raw should use handles */ error_init (error); MONO_HANDLE_DCL (MonoArray, array); - MonoType *result = mono_type_array_get_and_resolve (array, idx, error); + MonoType * const result = mono_type_array_get_and_resolve (array, idx, error); HANDLE_FUNCTION_RETURN_VAL (result); } @@ -1919,7 +1918,7 @@ static MonoMethodSignature* ctor_builder_to_signature_raw (MonoImage *image, MonoReflectionCtorBuilder* ctor_raw, MonoError *error) { HANDLE_FUNCTION_ENTER(); MONO_HANDLE_DCL (MonoReflectionCtorBuilder, ctor); - MonoMethodSignature *sig = ctor_builder_to_signature (image, ctor, error); + MonoMethodSignature * const sig = ctor_builder_to_signature (image, ctor, error); HANDLE_FUNCTION_RETURN_VAL (sig); } /** @@ -3260,7 +3259,7 @@ methodbuilder_to_mono_method_raw (MonoClass *klass, MonoReflectionMethodBuilder* HANDLE_FUNCTION_ENTER (); /* FIXME change callers of methodbuilder_to_mono_method_raw to use handles */ error_init (error); MONO_HANDLE_DCL (MonoReflectionMethodBuilder, mb); - MonoMethod *result = methodbuilder_to_mono_method (klass, mb, error); + MonoMethod * const result = methodbuilder_to_mono_method (klass, mb, error); HANDLE_FUNCTION_RETURN_VAL (result); } diff --git a/src/mono/mono/metadata/threadpool.c b/src/mono/mono/metadata/threadpool.c index ff0b588..12b0d5c 100644 --- a/src/mono/mono/metadata/threadpool.c +++ b/src/mono/mono/metadata/threadpool.c @@ -281,7 +281,7 @@ try_invoke_perform_wait_callback (MonoObject** exc, MonoError *error) { HANDLE_FUNCTION_ENTER (); error_init (error); - MonoObject *res = mono_runtime_try_invoke (mono_defaults.threadpool_perform_wait_callback_method, NULL, NULL, exc, error); + MonoObject * const res = mono_runtime_try_invoke (mono_defaults.threadpool_perform_wait_callback_method, NULL, NULL, exc, error); HANDLE_FUNCTION_RETURN_VAL (res); } diff --git a/src/mono/mono/metadata/threads.c b/src/mono/mono/metadata/threads.c index af4d7c4..2c03359 100644 --- a/src/mono/mono/metadata/threads.c +++ b/src/mono/mono/metadata/threads.c @@ -5092,7 +5092,7 @@ mono_thread_execute_interruption_ptr (void) { HANDLE_FUNCTION_ENTER (); MonoExceptionHandle exc = MONO_HANDLE_NEW (MonoException, NULL); - MonoException *exc_raw = mono_thread_execute_interruption (&exc) ? MONO_HANDLE_RAW (exc) : NULL; + MonoException * const exc_raw = mono_thread_execute_interruption (&exc) ? MONO_HANDLE_RAW (exc) : NULL; HANDLE_FUNCTION_RETURN_VAL (exc_raw); } -- 2.7.4