diff options
author | monojenkins <jo.shields+jenkins@xamarin.com> | 2016-01-27 07:45:23 +0300 |
---|---|---|
committer | monojenkins <jo.shields+jenkins@xamarin.com> | 2016-01-27 07:45:23 +0300 |
commit | eb4fdbd81805d026bb5aeee1568d52b9c6ba8ae7 (patch) | |
tree | b8af164aaa0b742bb4867041452b0225afe5374d | |
parent | df3efdc1319779690ef44818a1fa4a63df55bd53 (diff) | |
parent | 2cd2f4a184ff8c8b375324df85659086a7d457bf (diff) |
Merge pull request #2486 from ludovic-henry/monoerror-mono_type_get_object
[runtime] Use MonoError for mono_type_get_object
-rw-r--r-- | mono/metadata/cominterop.c | 10 | ||||
-rw-r--r-- | mono/metadata/icall.c | 300 | ||||
-rw-r--r-- | mono/metadata/object.c | 32 | ||||
-rw-r--r-- | mono/metadata/reflection-internals.h | 3 | ||||
-rw-r--r-- | mono/metadata/reflection.c | 140 | ||||
-rw-r--r-- | mono/metadata/remoting.c | 9 | ||||
-rw-r--r-- | mono/mini/debugger-agent.c | 6 | ||||
-rw-r--r-- | mono/mini/method-to-ir.c | 7 | ||||
-rw-r--r-- | mono/mini/mini-generic-sharing.c | 10 | ||||
-rw-r--r-- | mono/mini/mini-runtime.c | 6 |
10 files changed, 424 insertions, 99 deletions
diff --git a/mono/metadata/cominterop.c b/mono/metadata/cominterop.c index 0035e44f1f9..162e7436406 100644 --- a/mono/metadata/cominterop.c +++ b/mono/metadata/cominterop.c @@ -35,6 +35,8 @@ #include "mono/utils/mono-counters.h" #include "mono/utils/strenc.h" #include "mono/utils/atomic.h" +#include "mono/utils/mono-error.h" +#include "mono/utils/mono-error-internals.h" #include <string.h> #include <errno.h> @@ -520,11 +522,17 @@ cominterop_get_hresult_for_exception (MonoException* exc) static MonoReflectionType * cominterop_type_from_handle (MonoType *handle) { + MonoError error; + MonoReflectionType *ret; MonoDomain *domain = mono_domain_get (); MonoClass *klass = mono_class_from_mono_type (handle); mono_class_init (klass); - return mono_type_get_object (domain, handle); + + ret = mono_type_get_object_checked (domain, handle, &error); + mono_error_raise_exception (&error); /* FIXME don't raise here */ + + return ret; } void diff --git a/mono/metadata/icall.c b/mono/metadata/icall.c index 8bfbdb3c1a5..bc417107966 100644 --- a/mono/metadata/icall.c +++ b/mono/metadata/icall.c @@ -1125,12 +1125,18 @@ ves_icall_System_ValueType_Equals (MonoObject *this_obj, MonoObject *that, MonoA ICALL_EXPORT MonoReflectionType * ves_icall_System_Object_GetType (MonoObject *obj) { + MonoError error; + MonoReflectionType *ret; #ifndef DISABLE_REMOTING if (obj->vtable->klass == mono_defaults.transparent_proxy_class) - return mono_type_get_object (mono_object_domain (obj), &((MonoTransparentProxy*)obj)->remote_class->proxy_class->byval_arg); + ret = mono_type_get_object_checked (mono_object_domain (obj), &((MonoTransparentProxy*)obj)->remote_class->proxy_class->byval_arg, &error); else #endif - return mono_type_get_object (mono_object_domain (obj), &obj->vtable->klass->byval_arg); + ret = mono_type_get_object_checked (mono_object_domain (obj), &obj->vtable->klass->byval_arg, &error); + + mono_error_raise_exception (&error); + + return ret; } ICALL_EXPORT void @@ -1256,6 +1262,8 @@ get_caller_no_reflection (MonoMethod *m, gint32 no, gint32 ilo, gboolean managed static MonoReflectionType * type_from_parsed_name (MonoTypeNameParse *info, MonoBoolean ignoreCase) { + MonoError error; + MonoReflectionType *ret; MonoMethod *m, *dest; MonoType *type = NULL; @@ -1309,7 +1317,10 @@ type_from_parsed_name (MonoTypeNameParse *info, MonoBoolean ignoreCase) if (!type) return NULL; - return mono_type_get_object (mono_domain_get (), type); + ret = mono_type_get_object_checked (mono_domain_get (), type, &error); + mono_error_raise_exception (&error); /* FIXME don't raise here */ + + return ret; } #ifdef UNUSED @@ -1384,9 +1395,14 @@ ves_icall_type_from_name (MonoString *name, ICALL_EXPORT MonoReflectionType* ves_icall_type_from_handle (MonoType *handle) { + MonoError error; + MonoReflectionType *ret; MonoDomain *domain = mono_domain_get (); - return mono_type_get_object (domain, handle); + ret = mono_type_get_object_checked (domain, handle, &error); + mono_error_raise_exception (&error); + + return ret; } /* System.TypeCode */ @@ -1644,6 +1660,7 @@ ICALL_EXPORT void ves_icall_get_method_info (MonoMethod *method, MonoMethodInfo *info) { MonoError error; + MonoReflectionType *rt; MonoDomain *domain = mono_domain_get (); MonoMethodSignature* sig; @@ -1651,9 +1668,16 @@ ves_icall_get_method_info (MonoMethod *method, MonoMethodInfo *info) if (!mono_error_ok (&error)) mono_error_raise_exception (&error); + rt = mono_type_get_object_checked (domain, &method->klass->byval_arg, &error); + mono_error_raise_exception (&error); + + MONO_STRUCT_SETREF (info, parent, rt); + + rt = mono_type_get_object_checked (domain, sig->ret, &error); + mono_error_raise_exception (&error); + + MONO_STRUCT_SETREF (info, ret, rt); - MONO_STRUCT_SETREF (info, parent, mono_type_get_object (domain, &method->klass->byval_arg)); - MONO_STRUCT_SETREF (info, ret, mono_type_get_object (domain, sig->ret)); info->attrs = method->flags; info->implattrs = method->iflags; if (sig->call_convention == MONO_CALL_DEFAULT) @@ -1711,11 +1735,17 @@ ves_icall_MonoField_GetFieldOffset (MonoReflectionField *field) ICALL_EXPORT MonoReflectionType* ves_icall_MonoField_GetParentType (MonoReflectionField *field, MonoBoolean declaring) { + MonoError error; + MonoReflectionType *ret; MonoClass *parent; parent = declaring? field->field->parent: field->klass; - return mono_type_get_object (mono_object_domain (field), &parent->byval_arg); + ret = mono_type_get_object_checked (mono_object_domain (field), &parent->byval_arg, &error); + mono_error_raise_exception (&error); + + return ret; + } ICALL_EXPORT MonoObject * @@ -1938,11 +1968,16 @@ ICALL_EXPORT MonoReflectionType* ves_icall_MonoField_ResolveType (MonoReflectionField *ref_field) { MonoError error; - MonoClassField *field = ref_field->field; - MonoType *type = mono_field_get_type_checked (field, &error); - if (!mono_error_ok (&error)) - mono_error_raise_exception (&error); - return mono_type_get_object (mono_object_domain (ref_field), type); + MonoReflectionType *ret; + MonoType *type; + + type = mono_field_get_type_checked (ref_field->field, &error); + mono_error_raise_exception (&error); + + ret = mono_type_get_object_checked (mono_object_domain (ref_field), type, &error); + mono_error_raise_exception (&error); + + return ret; } /* From MonoProperty.cs */ @@ -1958,13 +1993,23 @@ typedef enum { ICALL_EXPORT void ves_icall_get_property_info (const MonoReflectionProperty *property, MonoPropertyInfo *info, PInfo req_info) { + MonoError error; + MonoReflectionType *rt; MonoDomain *domain = mono_object_domain (property); const MonoProperty *pproperty = property->property; - if ((req_info & PInfo_ReflectedType) != 0) - MONO_STRUCT_SETREF (info, parent, mono_type_get_object (domain, &property->klass->byval_arg)); - if ((req_info & PInfo_DeclaringType) != 0) - MONO_STRUCT_SETREF (info, declaring_type, mono_type_get_object (domain, &pproperty->parent->byval_arg)); + if ((req_info & PInfo_ReflectedType) != 0) { + rt = mono_type_get_object_checked (domain, &property->klass->byval_arg, &error); + mono_error_raise_exception (&error); + + MONO_STRUCT_SETREF (info, parent, rt); + } + if ((req_info & PInfo_DeclaringType) != 0) { + rt = mono_type_get_object_checked (domain, &pproperty->parent->byval_arg, &error); + mono_error_raise_exception (&error); + + MONO_STRUCT_SETREF (info, declaring_type, rt); + } if ((req_info & PInfo_Name) != 0) MONO_STRUCT_SETREF (info, name, mono_string_new (domain, pproperty->name)); @@ -1989,10 +2034,19 @@ ves_icall_get_property_info (const MonoReflectionProperty *property, MonoPropert ICALL_EXPORT void ves_icall_get_event_info (MonoReflectionMonoEvent *event, MonoEventInfo *info) { + MonoError error; + MonoReflectionType *rt; MonoDomain *domain = mono_object_domain (event); - MONO_STRUCT_SETREF (info, reflected_type, mono_type_get_object (domain, &event->klass->byval_arg)); - MONO_STRUCT_SETREF (info, declaring_type, mono_type_get_object (domain, &event->event->parent->byval_arg)); + rt = mono_type_get_object_checked (domain, &event->klass->byval_arg, &error); + mono_error_raise_exception (&error); + + MONO_STRUCT_SETREF (info, reflected_type, rt); + + rt = mono_type_get_object_checked (domain, &event->event->parent->byval_arg, &error); + mono_error_raise_exception (&error); + + MONO_STRUCT_SETREF (info, declaring_type, rt); MONO_STRUCT_SETREF (info, name, mono_string_new (domain, event->event->name)); info->attrs = event->event->attrs; @@ -2044,6 +2098,7 @@ typedef struct { static void fill_iface_array (gpointer key, gpointer value, gpointer user_data) { + MonoReflectionType *rt; FillIfaceArrayData *data = (FillIfaceArrayData *)user_data; MonoClass *ic = (MonoClass *)key; MonoType *ret = &ic->byval_arg, *inflated = NULL; @@ -2057,7 +2112,11 @@ fill_iface_array (gpointer key, gpointer value, gpointer user_data) return; } - mono_array_setref (data->iface_array, data->next_idx++, mono_type_get_object (data->domain, ret)); + rt = mono_type_get_object_checked (data->domain, ret, data->error); + if (!mono_error_ok (data->error)) + return; + + mono_array_setref (data->iface_array, data->next_idx++, rt); if (inflated) mono_metadata_free_type (inflated); @@ -2175,10 +2234,16 @@ ves_icall_Type_GetPacking (MonoReflectionType *type, guint32 *packing, guint32 * ICALL_EXPORT MonoReflectionType* ves_icall_MonoType_GetElementType (MonoReflectionType *type) { + MonoError error; + MonoReflectionType *ret; MonoClass *klass; - if (!type->type->byref && type->type->type == MONO_TYPE_SZARRAY) - return mono_type_get_object (mono_object_domain (type), &type->type->data.klass->byval_arg); + if (!type->type->byref && type->type->type == MONO_TYPE_SZARRAY) { + ret = mono_type_get_object_checked (mono_object_domain (type), &type->type->data.klass->byval_arg, &error); + mono_error_raise_exception (&error); + + return ret; + } klass = mono_class_from_mono_type (type->type); mono_class_init_or_throw (klass); @@ -2186,23 +2251,36 @@ ves_icall_MonoType_GetElementType (MonoReflectionType *type) // GetElementType should only return a type for: // Array Pointer PassedByRef if (type->type->byref) - return mono_type_get_object (mono_object_domain (type), &klass->byval_arg); + ret = mono_type_get_object_checked (mono_object_domain (type), &klass->byval_arg, &error); else if (klass->element_class && MONO_CLASS_IS_ARRAY (klass)) - return mono_type_get_object (mono_object_domain (type), &klass->element_class->byval_arg); + ret = mono_type_get_object_checked (mono_object_domain (type), &klass->element_class->byval_arg, &error); else if (klass->element_class && type->type->type == MONO_TYPE_PTR) - return mono_type_get_object (mono_object_domain (type), &klass->element_class->byval_arg); + ret = mono_type_get_object_checked (mono_object_domain (type), &klass->element_class->byval_arg, &error); else return NULL; + + mono_error_raise_exception (&error); + + return ret; } ICALL_EXPORT MonoReflectionType* ves_icall_get_type_parent (MonoReflectionType *type) { + MonoError error; + MonoReflectionType *ret; + if (type->type->byref) return NULL; MonoClass *klass = mono_class_from_mono_type (type->type); - return klass->parent ? mono_type_get_object (mono_object_domain (type), &klass->parent->byval_arg): NULL; + if (!klass->parent) + return NULL; + + ret = mono_type_get_object_checked (mono_object_domain (type), &klass->parent->byval_arg, &error); + mono_error_raise_exception (&error); + + return ret; } ICALL_EXPORT MonoBoolean @@ -2250,6 +2328,8 @@ ves_icall_MonoType_get_Assembly (MonoReflectionType *type) ICALL_EXPORT MonoReflectionType* ves_icall_MonoType_get_DeclaringType (MonoReflectionType *type) { + MonoError error; + MonoReflectionType *ret; MonoDomain *domain = mono_domain_get (); MonoClass *klass; @@ -2265,7 +2345,13 @@ ves_icall_MonoType_get_DeclaringType (MonoReflectionType *type) klass = mono_class_from_mono_type (type->type)->nested_in; } - return klass ? mono_type_get_object (domain, &klass->byval_arg) : NULL; + if (!klass) + return NULL; + + ret = mono_type_get_object_checked (domain, &klass->byval_arg, &error); + mono_error_raise_exception (&error); + + return ret; } ICALL_EXPORT MonoString* @@ -2327,6 +2413,8 @@ create_type_array (MonoDomain *domain, MonoBoolean runtimeTypeArray, int count) ICALL_EXPORT MonoArray* ves_icall_MonoType_GetGenericArguments (MonoReflectionType *type, MonoBoolean runtimeTypeArray) { + MonoError error; + MonoReflectionType *rt; MonoArray *res; MonoClass *klass, *pklass; MonoDomain *domain = mono_object_domain (type); @@ -2339,13 +2427,21 @@ ves_icall_MonoType_GetGenericArguments (MonoReflectionType *type, MonoBoolean ru res = create_type_array (domain, runtimeTypeArray, container->type_argc); for (i = 0; i < container->type_argc; ++i) { pklass = mono_class_from_generic_parameter_internal (mono_generic_container_get_param (container, i)); - mono_array_setref (res, i, mono_type_get_object (domain, &pklass->byval_arg)); + + rt = mono_type_get_object_checked (domain, &pklass->byval_arg, &error); + mono_error_raise_exception (&error); + + mono_array_setref (res, i, rt); } } else if (klass->generic_class) { MonoGenericInst *inst = klass->generic_class->context.class_inst; res = create_type_array (domain, runtimeTypeArray, inst->type_argc); - for (i = 0; i < inst->type_argc; ++i) - mono_array_setref (res, i, mono_type_get_object (domain, inst->type_argv [i])); + for (i = 0; i < inst->type_argc; ++i) { + rt = mono_type_get_object_checked (domain, inst->type_argv [i], &error); + mono_error_raise_exception (&error); + + mono_array_setref (res, i, rt); + } } else { res = NULL; } @@ -2370,6 +2466,8 @@ ves_icall_Type_get_IsGenericTypeDefinition (MonoReflectionType *type) ICALL_EXPORT MonoReflectionType* ves_icall_Type_GetGenericTypeDefinition_impl (MonoReflectionType *type) { + MonoError error; + MonoReflectionType *ret; MonoClass *klass; if (type->type->byref) @@ -2388,8 +2486,12 @@ ves_icall_Type_GetGenericTypeDefinition_impl (MonoReflectionType *type) if (generic_class->wastypebuilder && tb) return (MonoReflectionType *)tb; - else - return mono_type_get_object (mono_object_domain (type), &generic_class->byval_arg); + else { + ret = mono_type_get_object_checked (mono_object_domain (type), &generic_class->byval_arg, &error); + mono_error_raise_exception (&error); + + return ret; + } } return NULL; } @@ -2397,6 +2499,8 @@ ves_icall_Type_GetGenericTypeDefinition_impl (MonoReflectionType *type) ICALL_EXPORT MonoReflectionType* ves_icall_Type_MakeGenericType (MonoReflectionType *type, MonoArray *type_array) { + MonoError error; + MonoReflectionType *ret; MonoClass *klass; MonoType *geninst, **types; int i, count; @@ -2425,7 +2529,10 @@ ves_icall_Type_MakeGenericType (MonoReflectionType *type, MonoArray *type_array) return NULL; } - return mono_type_get_object (mono_object_domain (type), geninst); + ret = mono_type_get_object_checked (mono_object_domain (type), geninst, &error); + mono_error_raise_exception (&error); + + return ret; } ICALL_EXPORT gboolean @@ -2465,6 +2572,8 @@ ves_icall_Type_GetGenericParameterAttributes (MonoReflectionType *type) ICALL_EXPORT MonoArray * ves_icall_Type_GetGenericParameterConstraints (MonoReflectionType *type) { + MonoError error; + MonoReflectionType *rt; MonoGenericParamInfo *param_info; MonoDomain *domain; MonoClass **ptr; @@ -2479,8 +2588,12 @@ ves_icall_Type_GetGenericParameterConstraints (MonoReflectionType *type) ; res = mono_array_new (domain, mono_defaults.monotype_class, count); - for (i = 0; i < count; i++) - mono_array_setref (res, i, mono_type_get_object (domain, ¶m_info->constraints [i]->byval_arg)); + for (i = 0; i < count; i++) { + rt = mono_type_get_object_checked (domain, ¶m_info->constraints [i]->byval_arg, &error); + mono_error_raise_exception (&error); + + mono_array_setref (res, i, rt); + } return res; @@ -2666,6 +2779,8 @@ ves_icall_MonoMethod_get_IsGenericMethodDefinition (MonoReflectionMethod *method ICALL_EXPORT MonoArray* ves_icall_MonoMethod_GetGenericArguments (MonoReflectionMethod *method) { + MonoError error; + MonoReflectionType *rt; MonoArray *res; MonoDomain *domain; int count, i; @@ -2679,8 +2794,12 @@ ves_icall_MonoMethod_GetGenericArguments (MonoReflectionMethod *method) count = inst->type_argc; res = mono_array_new (domain, mono_defaults.systemtype_class, count); - for (i = 0; i < count; i++) - mono_array_setref (res, i, mono_type_get_object (domain, inst->type_argv [i])); + for (i = 0; i < count; i++) { + rt = mono_type_get_object_checked (domain, inst->type_argv [i], &error); + mono_error_raise_exception (&error); + + mono_array_setref (res, i, rt); + } return res; } @@ -2693,8 +2812,11 @@ ves_icall_MonoMethod_GetGenericArguments (MonoReflectionMethod *method) MonoGenericContainer *container = mono_method_get_generic_container (method->method); MonoGenericParam *param = mono_generic_container_get_param (container, i); MonoClass *pklass = mono_class_from_generic_parameter_internal (param); - mono_array_setref (res, i, - mono_type_get_object (domain, &pklass->byval_arg)); + + rt = mono_type_get_object_checked (domain, &pklass->byval_arg, &error); + mono_error_raise_exception (&error); + + mono_array_setref (res, i, rt); } return res; @@ -3073,6 +3195,8 @@ ves_icall_System_Enum_get_value (MonoObject *eobj) ICALL_EXPORT MonoReflectionType * ves_icall_System_Enum_get_underlying_type (MonoReflectionType *type) { + MonoError error; + MonoReflectionType *ret; MonoType *etype; MonoClass *klass; @@ -3085,7 +3209,10 @@ ves_icall_System_Enum_get_underlying_type (MonoReflectionType *type) return NULL; } - return mono_type_get_object (mono_object_domain (type), etype); + ret = mono_type_get_object_checked (mono_object_domain (type), etype, &error); + mono_error_raise_exception (&error); + + return ret; } ICALL_EXPORT int @@ -3904,10 +4031,11 @@ loader_error: ICALL_EXPORT MonoArray* ves_icall_Type_GetNestedTypes (MonoReflectionType *type, MonoString *name, guint32 bflags) { + MonoError error; + MonoReflectionType *rt; MonoDomain *domain; MonoClass *klass; MonoArray *res; - MonoObject *member; int i, match; MonoClass *nested; gpointer iter; @@ -3955,8 +4083,10 @@ ves_icall_Type_GetNestedTypes (MonoReflectionType *type, MonoString *name, guint continue; } - member = (MonoObject*)mono_type_get_object (domain, &nested->byval_arg); - mono_ptr_array_append (tmp_array, member); + rt = mono_type_get_object_checked (domain, &nested->byval_arg, &error); + mono_error_raise_exception (&error); + + mono_ptr_array_append (tmp_array, (MonoObject*) rt); } res = mono_array_new_cached (domain, mono_defaults.monotype_class, mono_ptr_array_size (tmp_array)); @@ -3975,6 +4105,8 @@ ves_icall_Type_GetNestedTypes (MonoReflectionType *type, MonoString *name, guint ICALL_EXPORT MonoReflectionType* ves_icall_System_Reflection_Assembly_InternalGetType (MonoReflectionAssembly *assembly, MonoReflectionModule *module, MonoString *name, MonoBoolean throwOnError, MonoBoolean ignoreCase) { + MonoError error; + MonoReflectionType *ret; gchar *str; MonoType *type = NULL; MonoTypeNameParse info; @@ -4080,7 +4212,10 @@ ves_icall_System_Reflection_Assembly_InternalGetType (MonoReflectionAssembly *as } /* g_print ("got it\n"); */ - return mono_type_get_object (mono_object_domain (assembly), type); + ret = mono_type_get_object_checked (mono_object_domain (assembly), type, &error); + mono_error_raise_exception (&error); + + return ret; } static gboolean @@ -4979,6 +5114,8 @@ mono_module_type_is_visible (MonoTableInfo *tdef, MonoImage *image, int type) static MonoArray* mono_module_get_types (MonoDomain *domain, MonoImage *image, MonoArray **exceptions, MonoBoolean exportedOnly) { + MonoError error; + MonoReflectionType *rt; MonoArray *res; MonoClass *klass; MonoTableInfo *tdef = &image->tables [MONO_TABLE_TYPEDEF]; @@ -4999,12 +5136,15 @@ mono_module_get_types (MonoDomain *domain, MonoImage *image, MonoArray **excepti count = 0; for (i = 1; i < tdef->rows; ++i) { if (!exportedOnly || mono_module_type_is_visible (tdef, image, i + 1)) { - MonoError error; klass = mono_class_get_checked (image, (i + 1) | MONO_TOKEN_TYPE_DEF, &error); mono_loader_assert_no_error (); /* Plug any leaks */ + g_assert (mono_error_ok (&error)); if (klass) { - mono_array_setref (res, count, mono_type_get_object (domain, &klass->byval_arg)); + rt = mono_type_get_object_checked (domain, &klass->byval_arg, &error); + mono_error_raise_exception (&error); /* FIXME don't raise here */ + + mono_array_setref (res, count, rt); } else { MonoException *ex = mono_error_convert_to_exception (&error); mono_array_setref (*exceptions, count, ex); @@ -5154,6 +5294,7 @@ ICALL_EXPORT MonoReflectionType* ves_icall_System_Reflection_Module_GetGlobalType (MonoReflectionModule *module) { MonoError error; + MonoReflectionType *ret; MonoDomain *domain = mono_object_domain (module); MonoClass *klass; @@ -5165,7 +5306,11 @@ ves_icall_System_Reflection_Module_GetGlobalType (MonoReflectionModule *module) klass = mono_class_get_checked (module->image, 1 | MONO_TOKEN_TYPE_DEF, &error); mono_error_raise_exception (&error); - return mono_type_get_object (domain, &klass->byval_arg); + + ret = mono_type_get_object_checked (domain, &klass->byval_arg, &error); + mono_error_raise_exception (&error); + + return ret; } ICALL_EXPORT void @@ -5441,6 +5586,8 @@ ves_icall_System_Reflection_Module_ResolveFieldToken (MonoImage *image, guint32 ICALL_EXPORT MonoObject* ves_icall_System_Reflection_Module_ResolveMemberToken (MonoImage *image, guint32 token, MonoArray *type_args, MonoArray *method_args, MonoResolveTokenError *error) { + MonoError merror; + MonoObject *ret; int table = mono_metadata_token_table (token); *error = ResolveTokenError_Other; @@ -5450,8 +5597,12 @@ ves_icall_System_Reflection_Module_ResolveMemberToken (MonoImage *image, guint32 case MONO_TABLE_TYPEREF: case MONO_TABLE_TYPESPEC: { MonoType *t = ves_icall_System_Reflection_Module_ResolveTypeToken (image, token, type_args, method_args, error); - if (t) - return (MonoObject*)mono_type_get_object (mono_domain_get (), t); + if (t) { + ret = (MonoObject*) mono_type_get_object_checked (mono_domain_get (), t, &merror); + mono_error_raise_exception (&merror); + + return ret; + } else return NULL; } @@ -5529,6 +5680,8 @@ ves_icall_System_Reflection_Module_ResolveSignature (MonoImage *image, guint32 t ICALL_EXPORT MonoReflectionType* ves_icall_ModuleBuilder_create_modified_type (MonoReflectionTypeBuilder *tb, MonoString *smodifiers) { + MonoError error; + MonoReflectionType *ret; MonoClass *klass; int isbyref = 0, rank; char *str = mono_string_to_utf8 (smodifiers); @@ -5546,9 +5699,13 @@ ves_icall_ModuleBuilder_create_modified_type (MonoReflectionTypeBuilder *tb, Mon } isbyref = 1; p++; + g_free (str); - return mono_type_get_object (mono_object_domain (tb), &klass->this_arg); - break; + + ret = mono_type_get_object_checked (mono_object_domain (tb), &klass->this_arg, &error); + mono_error_raise_exception (&error); + + return ret; case '*': klass = mono_ptr_class_get (&klass->byval_arg); mono_class_init (klass); @@ -5580,8 +5737,13 @@ ves_icall_ModuleBuilder_create_modified_type (MonoReflectionTypeBuilder *tb, Mon break; } } + g_free (str); - return mono_type_get_object (mono_object_domain (tb), &klass->byval_arg); + + ret = mono_type_get_object_checked (mono_object_domain (tb), &klass->byval_arg, &error); + mono_error_raise_exception (&error); + + return ret; } ICALL_EXPORT MonoBoolean @@ -5613,6 +5775,8 @@ check_for_invalid_type (MonoClass *klass) ICALL_EXPORT MonoReflectionType * ves_icall_Type_make_array_type (MonoReflectionType *type, int rank) { + MonoError error; + MonoReflectionType *ret; MonoClass *klass, *aklass; klass = mono_class_from_mono_type (type->type); @@ -5623,24 +5787,34 @@ ves_icall_Type_make_array_type (MonoReflectionType *type, int rank) else aklass = mono_bounded_array_class_get (klass, rank, TRUE); - return mono_type_get_object (mono_object_domain (type), &aklass->byval_arg); + ret = mono_type_get_object_checked (mono_object_domain (type), &aklass->byval_arg, &error); + mono_error_raise_exception (&error); + + return ret; } ICALL_EXPORT MonoReflectionType * ves_icall_Type_make_byref_type (MonoReflectionType *type) { + MonoError error; + MonoReflectionType *ret; MonoClass *klass; klass = mono_class_from_mono_type (type->type); mono_class_init_or_throw (klass); check_for_invalid_type (klass); - return mono_type_get_object (mono_object_domain (type), &klass->this_arg); + ret = mono_type_get_object_checked (mono_object_domain (type), &klass->this_arg, &error); + mono_error_raise_exception (&error); + + return ret; } ICALL_EXPORT MonoReflectionType * ves_icall_Type_MakePointerType (MonoReflectionType *type) { + MonoError error; + MonoReflectionType *ret; MonoClass *klass, *pklass; klass = mono_class_from_mono_type (type->type); @@ -5649,7 +5823,10 @@ ves_icall_Type_MakePointerType (MonoReflectionType *type) pklass = mono_ptr_class_get (type->type); - return mono_type_get_object (mono_object_domain (type), &pklass->byval_arg); + ret = mono_type_get_object_checked (mono_object_domain (type), &pklass->byval_arg, &error); + mono_error_raise_exception (&error); + + return ret; } ICALL_EXPORT MonoObject * @@ -5832,7 +6009,11 @@ ves_icall_Remoting_RealProxy_GetTransparentProxy (MonoObject *this_obj, MonoStri ICALL_EXPORT MonoReflectionType * ves_icall_Remoting_RealProxy_InternalGetProxyType (MonoTransparentProxy *tp) { - return mono_type_get_object (mono_object_domain (tp), &tp->remote_class->proxy_class->byval_arg); + MonoError error; + MonoReflectionType *ret = mono_type_get_object_checked (mono_object_domain (tp), &tp->remote_class->proxy_class->byval_arg, &error); + mono_error_raise_exception (&error); + + return ret; } #endif @@ -7037,6 +7218,8 @@ ves_icall_System_NumberFormatter_GetFormatterTables (guint64 const **mantissas, static MonoArray* type_array_from_modifiers (MonoImage *image, MonoType *type, int optional) { + MonoError error; + MonoReflectionType *rt; MonoArray *res; int i, count = 0; for (i = 0; i < type->num_mods; ++i) { @@ -7049,10 +7232,13 @@ type_array_from_modifiers (MonoImage *image, MonoType *type, int optional) count = 0; for (i = 0; i < type->num_mods; ++i) { if ((optional && !type->modifiers [i].required) || (!optional && type->modifiers [i].required)) { - MonoError error; MonoClass *klass = mono_class_get_checked (image, type->modifiers [i].token, &error); mono_error_raise_exception (&error); /* this is safe, no cleanup needed on callers */ - mono_array_setref (res, count, mono_type_get_object (mono_domain_get (), &klass->byval_arg)); + + rt = mono_type_get_object_checked (mono_domain_get (), &klass->byval_arg, &error); + mono_error_raise_exception (&error); + + mono_array_setref (res, count, rt); count++; } } diff --git a/mono/metadata/object.c b/mono/metadata/object.c index ffae02f394e..bd31aaa2a8b 100644 --- a/mono/metadata/object.c +++ b/mono/metadata/object.c @@ -38,6 +38,7 @@ #include "mono/metadata/mono-debug-debugger.h" #include <mono/metadata/gc-internals.h> #include <mono/metadata/verify-internals.h> +#include <mono/metadata/reflection-internals.h> #include <mono/utils/strenc.h> #include <mono/utils/mono-counters.h> #include <mono/utils/mono-error-internals.h> @@ -1928,6 +1929,7 @@ mono_class_create_runtime_vtable (MonoDomain *domain, MonoClass *klass, gboolean { MONO_REQ_GC_UNSAFE_MODE; + MonoError error; MonoVTable *vt; MonoClassRuntimeInfo *runtime_info, *old_info; MonoClassField *field; @@ -2174,7 +2176,9 @@ mono_class_create_runtime_vtable (MonoDomain *domain, MonoClass *klass, gboolean /* Special case System.MonoType to avoid infinite recursion */ if (klass != mono_defaults.monotype_class) { /*FIXME check for OOM*/ - vt->type = mono_type_get_object (domain, &klass->byval_arg); + vt->type = mono_type_get_object_checked (domain, &klass->byval_arg, &error); + mono_error_raise_exception (&error); /* FIXME don't raise here */ + if (mono_object_get_class ((MonoObject *)vt->type) != mono_defaults.monotype_class) /* This is unregistered in unregister_vtable_reflection_type() in @@ -2228,7 +2232,9 @@ mono_class_create_runtime_vtable (MonoDomain *domain, MonoClass *klass, gboolean if (klass == mono_defaults.monotype_class) { /*FIXME check for OOM*/ - vt->type = mono_type_get_object (domain, &klass->byval_arg); + vt->type = mono_type_get_object_checked (domain, &klass->byval_arg, &error); + mono_error_raise_exception (&error); /* FIXME don't raise here */ + if (mono_object_get_class ((MonoObject *)vt->type) != mono_defaults.monotype_class) /* This is unregistered in unregister_vtable_reflection_type() in @@ -3214,6 +3220,7 @@ mono_field_get_value_object (MonoDomain *domain, MonoClassField *field, MonoObje { MONO_REQ_GC_UNSAFE_MODE; + MonoError error; MonoObject *o; MonoClass *klass; MonoVTable *vtable = NULL; @@ -3222,7 +3229,6 @@ mono_field_get_value_object (MonoDomain *domain, MonoClassField *field, MonoObje gboolean is_ref = FALSE; gboolean is_literal = FALSE; gboolean is_ptr = FALSE; - MonoError error; MonoType *type = mono_field_get_type_checked (field, &error); if (!mono_error_ok (&error)) @@ -3314,7 +3320,8 @@ mono_field_get_value_object (MonoDomain *domain, MonoClassField *field, MonoObje /* MONO_TYPE_PTR is passed by value to runtime_invoke () */ args [0] = ptr ? *ptr : NULL; - args [1] = mono_type_get_object (mono_domain_get (), type); + args [1] = mono_type_get_object_checked (mono_domain_get (), type, &error); + mono_error_raise_exception (&error); /* FIXME don't raise here */ return mono_runtime_invoke (m, NULL, args, NULL); } @@ -3901,6 +3908,7 @@ make_transparent_proxy (MonoObject *obj, gboolean *failure, MonoObject **exc) static MonoMethod *get_proxy_method; + MonoError error; MonoDomain *domain = mono_domain_get (); MonoRealProxy *real_proxy; MonoReflectionType *reflection_type; @@ -3912,7 +3920,8 @@ make_transparent_proxy (MonoObject *obj, gboolean *failure, MonoObject **exc) g_assert (mono_class_is_marshalbyref (obj->vtable->klass)); real_proxy = (MonoRealProxy*) mono_object_new (domain, mono_defaults.real_proxy_class); - reflection_type = mono_type_get_object (domain, &obj->vtable->klass->byval_arg); + reflection_type = mono_type_get_object_checked (domain, &obj->vtable->klass->byval_arg, &error); + mono_error_raise_exception (&error); /* FIXME don't raise here */ MONO_OBJECT_SETREF (real_proxy, class_to_proxy, reflection_type); MONO_OBJECT_SETREF (real_proxy, unwrapped_server, obj); @@ -4300,6 +4309,7 @@ mono_runtime_invoke_array (MonoMethod *method, void *obj, MonoArray *params, { MONO_REQ_GC_UNSAFE_MODE; + MonoError error; MonoMethodSignature *sig = mono_method_signature (method); gpointer *pa = NULL; MonoObject *res; @@ -4451,7 +4461,9 @@ mono_runtime_invoke_array (MonoMethod *method, void *obj, MonoArray *params, g_assert (res->vtable->klass == mono_defaults.int_class); box_args [0] = ((MonoIntPtr*)res)->m_value; - box_args [1] = mono_type_get_object (mono_domain_get (), sig->ret); + box_args [1] = mono_type_get_object_checked (mono_domain_get (), sig->ret, &error); + mono_error_raise_exception (&error); /* FIXME don't raise here */ + res = mono_runtime_invoke (box_method, NULL, box_args, &box_exc); g_assert (!box_exc); } @@ -4577,7 +4589,9 @@ mono_object_new_specific_checked (MonoVTable *vtable, MonoError *error) vtable->domain->create_proxy_for_type_method = im; } - pa [0] = mono_type_get_object (mono_domain_get (), &vtable->klass->byval_arg); + pa [0] = mono_type_get_object_checked (mono_domain_get (), &vtable->klass->byval_arg, error); + if (!mono_error_ok (error)) + return NULL; o = mono_runtime_invoke (im, NULL, pa, NULL); if (o != NULL) return o; @@ -5546,6 +5560,7 @@ mono_object_isinst_mbyref (MonoObject *obj, MonoClass *klass) { MONO_REQ_GC_UNSAFE_MODE; + MonoError error; MonoVTable *vt; if (!obj) @@ -5586,7 +5601,8 @@ mono_object_isinst_mbyref (MonoObject *obj, MonoClass *klass) im = mono_object_get_virtual_method (rp, im); g_assert (im); - pa [0] = mono_type_get_object (domain, &klass->byval_arg); + pa [0] = mono_type_get_object_checked (domain, &klass->byval_arg, &error); + mono_error_raise_exception (&error); /* FIXME don't raise here */ pa [1] = obj; res = mono_runtime_invoke (im, rp, pa, NULL); diff --git a/mono/metadata/reflection-internals.h b/mono/metadata/reflection-internals.h index 54eee9f0c73..144d1130fc1 100644 --- a/mono/metadata/reflection-internals.h +++ b/mono/metadata/reflection-internals.h @@ -17,4 +17,7 @@ mono_identifier_unescape_type_name_chars (char* identifier); MonoImage * mono_find_dynamic_image_owner (void *ptr); +MonoReflectionType* +mono_type_get_object_checked (MonoDomain *domain, MonoType *type, MonoError *error); + #endif /* __MONO_METADATA_REFLECTION_INTERNALS_H__ */ diff --git a/mono/metadata/reflection.c b/mono/metadata/reflection.c index 4bba73e3620..96316adef5b 100644 --- a/mono/metadata/reflection.c +++ b/mono/metadata/reflection.c @@ -1674,12 +1674,14 @@ reflection_methodbuilder_from_ctor_builder (ReflectionMethodBuilder *rmb, MonoRe { MONO_REQ_GC_UNSAFE_MODE; + MonoError error; const char *name = mb->attrs & METHOD_ATTRIBUTE_STATIC ? ".cctor": ".ctor"; memset (rmb, 0, sizeof (ReflectionMethodBuilder)); rmb->ilgen = mb->ilgen; - rmb->rtype = mono_type_get_object (mono_domain_get (), &mono_defaults.void_class->byval_arg); + rmb->rtype = mono_type_get_object_checked (mono_domain_get (), &mono_defaults.void_class->byval_arg, &error); + mono_error_raise_exception (&error); /* FIXME don't raise here */ rmb->parameters = mb->parameters; rmb->generic_params = NULL; rmb->generic_container = NULL; @@ -6691,9 +6693,22 @@ MonoReflectionType* mono_type_get_object (MonoDomain *domain, MonoType *type) { MonoError error; + MonoReflectionType *ret = mono_type_get_object_checked (domain, type, &error); + mono_error_raise_exception (&error); + + return ret; +} + +MonoReflectionType* +mono_type_get_object_checked (MonoDomain *domain, MonoType *type, MonoError *error) +{ MonoType *norm_type; MonoReflectionType *res; - MonoClass *klass = mono_class_from_mono_type (type); + MonoClass *klass; + + mono_error_init (error); + + klass = mono_class_from_mono_type (type); /*we must avoid using @type as it might have come * from a mono_metadata_type_dup and the caller @@ -6739,7 +6754,9 @@ mono_type_get_object (MonoDomain *domain, MonoType *type) */ norm_type = mono_type_normalize (type); if (norm_type != type) { - res = mono_type_get_object (domain, norm_type); + res = mono_type_get_object_checked (domain, norm_type, error); + if (!mono_error_ok (error)) + return NULL; mono_g_hash_table_insert (domain->type_hash, type, res); mono_domain_unlock (domain); mono_loader_unlock (); @@ -6785,8 +6802,10 @@ mono_type_get_object (MonoDomain *domain, MonoType *type) } } /* This is stored in vtables/JITted code so it has to be pinned */ - res = (MonoReflectionType *)mono_object_new_pinned (domain, mono_defaults.monotype_class, &error); - mono_error_raise_exception (&error); + res = (MonoReflectionType *)mono_object_new_pinned (domain, mono_defaults.monotype_class, error); + if (!mono_error_ok (error)) + return NULL; + res->type = type; mono_g_hash_table_insert (domain->type_hash, type, res); @@ -6817,6 +6836,8 @@ mono_method_get_object (MonoDomain *domain, MonoMethod *method, MonoClass *refcl static MonoClass *System_Reflection_MonoCMethod = NULL; static MonoClass *System_Reflection_MonoGenericMethod = NULL; static MonoClass *System_Reflection_MonoGenericCMethod = NULL; + MonoError error; + MonoReflectionType *rt; MonoClass *klass; MonoReflectionMethod *ret; @@ -6837,8 +6858,14 @@ mono_method_get_object (MonoDomain *domain, MonoMethod *method, MonoClass *refcl } gret = (MonoReflectionGenericMethod*)mono_object_new (domain, klass); gret->method.method = method; + MONO_OBJECT_SETREF (gret, method.name, mono_string_new (domain, method->name)); - MONO_OBJECT_SETREF (gret, method.reftype, mono_type_get_object (domain, &refclass->byval_arg)); + + rt = mono_type_get_object_checked (domain, &refclass->byval_arg, &error); + mono_error_raise_exception (&error); /* FIXME don't raise here */ + + MONO_OBJECT_SETREF (gret, method.reftype, rt); + CACHE_OBJECT (MonoReflectionMethod *, method, (MonoReflectionMethod*)gret, refclass); } @@ -6858,7 +6885,12 @@ mono_method_get_object (MonoDomain *domain, MonoMethod *method, MonoClass *refcl } ret = (MonoReflectionMethod*)mono_object_new (domain, klass); ret->method = method; - MONO_OBJECT_SETREF (ret, reftype, mono_type_get_object (domain, &refclass->byval_arg)); + + rt = mono_type_get_object_checked (domain, &refclass->byval_arg, &error); + mono_error_raise_exception (&error); /* FIXME don't raise here */; + + MONO_OBJECT_SETREF (ret, reftype, rt); + CACHE_OBJECT (MonoReflectionMethod *, method, ret, refclass); } @@ -6899,6 +6931,8 @@ mono_method_clear_object (MonoDomain *domain, MonoMethod *method) MonoReflectionField* mono_field_get_object (MonoDomain *domain, MonoClass *klass, MonoClassField *field) { + MonoError error; + MonoReflectionType *rt; MonoReflectionField *res; static MonoClass *monofield_klass; @@ -6912,10 +6946,18 @@ mono_field_get_object (MonoDomain *domain, MonoClass *klass, MonoClassField *fie if (is_field_on_inst (field)) { res->attrs = get_field_on_inst_generic_type (field)->attrs; - MONO_OBJECT_SETREF (res, type, mono_type_get_object (domain, field->type)); + + rt = mono_type_get_object_checked (domain, field->type, &error); + mono_error_raise_exception (&error); /* FIXME don't raise here */ + + MONO_OBJECT_SETREF (res, type, rt); } else { - if (field->type) - MONO_OBJECT_SETREF (res, type, mono_type_get_object (domain, field->type)); + if (field->type) { + rt = mono_type_get_object_checked (domain, field->type, &error); + mono_error_raise_exception (&error); /* FIXME don't raise here */ + + MONO_OBJECT_SETREF (res, type, rt); + } res->attrs = mono_field_get_flags (field); } CACHE_OBJECT (MonoReflectionField *, field, res, klass); @@ -7040,6 +7082,7 @@ mono_param_get_objects_internal (MonoDomain *domain, MonoMethod *method, MonoCla MonoMarshalSpec **mspecs; MonoMethodSignature *sig; MonoVTable *pinfo_vtable; + MonoReflectionType *rt; int i; if (!System_Reflection_ParameterInfo_array) { @@ -7088,9 +7131,16 @@ mono_param_get_objects_internal (MonoDomain *domain, MonoMethod *method, MonoCla for (i = 0; i < sig->param_count; ++i) { param = (MonoReflectionParameter *) mono_object_new_specific_checked (pinfo_vtable, &error); mono_error_raise_exception (&error); /* FIXME don't raise here */ - MONO_OBJECT_SETREF (param, ClassImpl, mono_type_get_object (domain, sig->params [i])); + + rt = mono_type_get_object_checked (domain, sig->params [i], &error); + mono_error_raise_exception (&error); /* FIXME don't raise here */ + + MONO_OBJECT_SETREF (param, ClassImpl, rt); + MONO_OBJECT_SETREF (param, MemberImpl, (MonoObject*)member); + MONO_OBJECT_SETREF (param, NameImpl, mono_string_new (domain, names [i])); + param->PositionImpl = i; param->AttrsImpl = sig->params [i]->attrs; @@ -7171,9 +7221,11 @@ mono_method_body_get_object (MonoDomain *domain, MonoMethod *method) static MonoClass *System_Reflection_MethodBody = NULL; static MonoClass *System_Reflection_LocalVariableInfo = NULL; static MonoClass *System_Reflection_ExceptionHandlingClause = NULL; + MonoError error; MonoReflectionMethodBody *ret; MonoMethodHeader *header; MonoImage *image; + MonoReflectionType *rt; guint32 method_rva, local_var_sig_token; char *ptr; unsigned char format, flags; @@ -7236,7 +7288,12 @@ mono_method_body_get_object (MonoDomain *domain, MonoMethod *method) MONO_OBJECT_SETREF (ret, locals, mono_array_new_cached (domain, System_Reflection_LocalVariableInfo, header->num_locals)); for (i = 0; i < header->num_locals; ++i) { MonoReflectionLocalVariableInfo *info = (MonoReflectionLocalVariableInfo*)mono_object_new (domain, System_Reflection_LocalVariableInfo); - MONO_OBJECT_SETREF (info, local_type, mono_type_get_object (domain, header->locals [i])); + + rt = mono_type_get_object_checked (domain, header->locals [i], &error); + mono_error_raise_exception (&error); /* FIXME don't raise here */ + + MONO_OBJECT_SETREF (info, local_type, rt); + info->is_pinned = header->locals [i]->pinned; info->local_index = i; mono_array_setref (ret->locals, i, info); @@ -7255,8 +7312,12 @@ mono_method_body_get_object (MonoDomain *domain, MonoMethod *method) info->handler_length = clause->handler_len; if (clause->flags == MONO_EXCEPTION_CLAUSE_FILTER) info->filter_offset = clause->data.filter_offset; - else if (clause->data.catch_class) - MONO_OBJECT_SETREF (info, catch_type, mono_type_get_object (mono_domain_get (), &clause->data.catch_class->byval_arg)); + else if (clause->data.catch_class) { + rt = mono_type_get_object_checked (mono_domain_get (), &clause->data.catch_class->byval_arg, &error); + mono_error_raise_exception (&error); /* FIXME don't raise here */ + + MONO_OBJECT_SETREF (info, catch_type, rt); + } mono_array_setref (ret->clauses, i, info); } @@ -7830,6 +7891,7 @@ _mono_reflection_get_type_from_info (MonoTypeNameParse *info, MonoImage *image, static MonoType* mono_reflection_get_type_internal (MonoImage *rootimage, MonoImage* image, MonoTypeNameParse *info, gboolean ignorecase) { + MonoError error; MonoClass *klass; GList *mod; int modval; @@ -7926,7 +7988,8 @@ mono_reflection_get_type_internal (MonoImage *rootimage, MonoImage* image, MonoT } } - the_type = mono_type_get_object (mono_domain_get (), &klass->byval_arg); + the_type = mono_type_get_object_checked (mono_domain_get (), &klass->byval_arg, &error); + mono_error_raise_exception (&error); /* FIXME don't raise here */ instance = mono_reflection_bind_generic_parameters ( the_type, info->type_arguments->len, type_args); @@ -8298,6 +8361,7 @@ handle_enum: *end = p + slen; return mono_string_new_len (mono_domain_get (), p, slen); case MONO_TYPE_CLASS: { + MonoReflectionType *rt; char *n; MonoType *t; if (*p == (char)0xFF) { @@ -8317,7 +8381,12 @@ handle_type: } g_free (n); *end = p + slen; - return mono_type_get_object (mono_domain_get (), t); + + rt = mono_type_get_object_checked (mono_domain_get (), t, error); + if (!mono_error_ok (error)) + return NULL; + + return rt; } case MONO_TYPE_OBJECT: { char subt = *p++; @@ -8469,6 +8538,7 @@ create_cattr_typed_arg (MonoType *t, MonoObject *val) { static MonoClass *klass; static MonoMethod *ctor; + MonoError error; MonoObject *retval; void *params [2], *unboxed; @@ -8477,7 +8547,9 @@ create_cattr_typed_arg (MonoType *t, MonoObject *val) if (!ctor) ctor = mono_class_get_method_from_name (klass, ".ctor", 2); - params [0] = mono_type_get_object (mono_domain_get (), t); + params [0] = mono_type_get_object_checked (mono_domain_get (), t, &error); + mono_error_raise_exception (&error); /* FIXME don't raise here */ + params [1] = val; retval = mono_object_new (mono_domain_get (), klass); unboxed = mono_object_unbox (retval); @@ -9732,7 +9804,7 @@ mono_reflection_register_with_runtime (MonoReflectionType *type) klass = mono_class_from_mono_type (res); - mono_loader_lock (); /*same locking as mono_type_get_object*/ + mono_loader_lock (); /*same locking as mono_type_get_object_checked */ mono_domain_lock (domain); if (!image_is_dynamic (klass->image)) { @@ -10588,6 +10660,8 @@ mono_reflection_marshal_as_attribute_from_marshal_spec (MonoDomain *domain, Mono MonoMarshalSpec *spec) { static MonoClass *System_Reflection_Emit_MarshalAsAttribute; + MonoError error; + MonoReflectionType *rt; MonoReflectionMarshalAsAttribute *minfo; MonoType *mtype; @@ -10616,8 +10690,12 @@ mono_reflection_marshal_as_attribute_from_marshal_spec (MonoDomain *domain, Mono case MONO_NATIVE_CUSTOM: if (spec->data.custom_data.custom_name) { mtype = mono_reflection_type_from_name (spec->data.custom_data.custom_name, klass->image); - if (mtype) - MONO_OBJECT_SETREF (minfo, marshal_type_ref, mono_type_get_object (domain, mtype)); + if (mtype) { + rt = mono_type_get_object_checked (domain, mtype, &error); + mono_error_raise_exception (&error); /* FIXME don't raise here */ + + MONO_OBJECT_SETREF (minfo, marshal_type_ref, rt); + } MONO_OBJECT_SETREF (minfo, marshal_type, mono_string_new (domain, spec->data.custom_data.custom_name)); } @@ -11863,7 +11941,11 @@ mono_reflection_create_runtime_class (MonoReflectionTypeBuilder *tb) if (klass->wastypebuilder) { mono_domain_unlock (domain); mono_loader_unlock (); - return mono_type_get_object (mono_object_domain (tb), &klass->byval_arg); + + res = mono_type_get_object_checked (mono_object_domain (tb), &klass->byval_arg, &error); + mono_error_raise_exception (&error); /* FIXME don't raise here */ + + return res; } /* * Fields to set in klass: @@ -11887,7 +11969,11 @@ mono_reflection_create_runtime_class (MonoReflectionTypeBuilder *tb) klass->wastypebuilder = TRUE; mono_loader_unlock (); mono_domain_unlock (domain); - return mono_type_get_object (mono_object_domain (tb), &klass->byval_arg); + + res = mono_type_get_object_checked (mono_object_domain (tb), &klass->byval_arg, &error); + mono_error_raise_exception (&error); /* FIXME don't raise here */ + + return res; } } #endif @@ -11954,7 +12040,9 @@ mono_reflection_create_runtime_class (MonoReflectionTypeBuilder *tb) mono_raise_exception (mono_get_exception_type_load (tb->name, NULL)); } - res = mono_type_get_object (mono_object_domain (tb), &klass->byval_arg); + res = mono_type_get_object_checked (mono_object_domain (tb), &klass->byval_arg, &error); + mono_error_raise_exception (&error); /* FIXME don't raise here */ + g_assert (res != (MonoReflectionType*)tb); return res; @@ -13195,6 +13283,7 @@ mono_declsec_get_assembly_action (MonoAssembly *assembly, guint32 action, MonoDe gboolean mono_reflection_call_is_assignable_to (MonoClass *klass, MonoClass *oklass) { + MonoError error; MonoObject *res, *exc; void *params [1]; static MonoClass *System_Reflection_Emit_TypeBuilder = NULL; @@ -13210,13 +13299,14 @@ mono_reflection_call_is_assignable_to (MonoClass *klass, MonoClass *oklass) } /* - * The result of mono_type_get_object () might be a System.MonoType but we + * The result of mono_type_get_object_checked () might be a System.MonoType but we * need a TypeBuilder so use mono_class_get_ref_info (klass). */ g_assert (mono_class_get_ref_info (klass)); g_assert (!strcmp (((MonoObject*)(mono_class_get_ref_info (klass)))->vtable->klass->name, "TypeBuilder")); - params [0] = mono_type_get_object (mono_domain_get (), &oklass->byval_arg); + params [0] = mono_type_get_object_checked (mono_domain_get (), &oklass->byval_arg, &error); + mono_error_raise_exception (&error); /* FIXME don't raise here */ res = mono_runtime_invoke (method, (MonoObject*)(mono_class_get_ref_info (klass)), params, &exc); if (exc) diff --git a/mono/metadata/remoting.c b/mono/metadata/remoting.c index cbe8b3add94..8ca8ae62fdb 100644 --- a/mono/metadata/remoting.c +++ b/mono/metadata/remoting.c @@ -16,6 +16,7 @@ #include "mono/metadata/tabledefs.h" #include "mono/metadata/exception.h" #include "mono/metadata/debug-helpers.h" +#include "mono/metadata/reflection-internals.h" typedef enum { MONO_MARSHAL_NONE, /* No marshalling needed */ @@ -199,11 +200,17 @@ mono_remoting_marshal_init (void) static MonoReflectionType * type_from_handle (MonoType *handle) { + MonoError error; + MonoReflectionType *ret; MonoDomain *domain = mono_domain_get (); MonoClass *klass = mono_class_from_mono_type (handle); mono_class_init (klass); - return mono_type_get_object (domain, handle); + + ret = mono_type_get_object_checked (domain, handle, &error); + mono_error_raise_exception (&error); /* FIXME don't raise here */ + + return ret; } #ifndef DISABLE_JIT diff --git a/mono/mini/debugger-agent.c b/mono/mini/debugger-agent.c index 7340ac302cf..62598bbb405 100644 --- a/mono/mini/debugger-agent.c +++ b/mono/mini/debugger-agent.c @@ -62,6 +62,7 @@ #include <mono/metadata/assembly.h> #include <mono/metadata/runtime.h> #include <mono/metadata/verify-internals.h> +#include <mono/metadata/reflection-internals.h> #include <mono/utils/mono-coop-mutex.h> #include <mono/utils/mono-coop-semaphore.h> #include <mono/utils/mono-error-internals.h> @@ -7858,6 +7859,7 @@ collect_interfaces (MonoClass *klass, GHashTable *ifaces, MonoError *error) static ErrorCode type_commands_internal (int command, MonoClass *klass, MonoDomain *domain, guint8 *p, guint8 *end, Buffer *buf) { + MonoError error; MonoClass *nested; MonoType *type; gpointer iter; @@ -8162,7 +8164,8 @@ type_commands_internal (int command, MonoClass *klass, MonoDomain *domain, guint break; } case CMD_TYPE_GET_OBJECT: { - MonoObject *o = (MonoObject*)mono_type_get_object (domain, &klass->byval_arg); + MonoObject *o = (MonoObject*)mono_type_get_object_checked (domain, &klass->byval_arg, &error); + mono_error_raise_exception (&error); /* FIXME don't raise here */ buffer_add_objid (buf, o); break; } @@ -8221,7 +8224,6 @@ type_commands_internal (int command, MonoClass *klass, MonoDomain *domain, guint case CMD_TYPE_GET_INTERFACES: { MonoClass *parent; GHashTable *iface_hash = g_hash_table_new (NULL, NULL); - MonoError error; MonoClass *tclass, *iface; GHashTableIter iter; diff --git a/mono/mini/method-to-ir.c b/mono/mini/method-to-ir.c index 4c0a925becf..a202b20cf38 100644 --- a/mono/mini/method-to-ir.c +++ b/mono/mini/method-to-ir.c @@ -60,6 +60,7 @@ #include <mono/utils/mono-compiler.h> #include <mono/utils/mono-memory-model.h> #include <mono/metadata/mono-basic-block.h> +#include <mono/metadata/reflection-internals.h> #include "trace.h" @@ -12255,7 +12256,11 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b EMIT_NEW_TYPE_FROM_HANDLE_CONST (cfg, ins, image, n, generic_context); } } else { - EMIT_NEW_PCONST (cfg, ins, mono_type_get_object (cfg->domain, (MonoType *)handle)); + MonoError error; + MonoReflectionType *rt = mono_type_get_object_checked (cfg->domain, (MonoType *)handle, &error); + mono_error_raise_exception (&error); /* FIXME don't raise here */ + + EMIT_NEW_PCONST (cfg, ins, rt); } ins->type = STACK_OBJ; ins->klass = cmethod->klass; diff --git a/mono/mini/mini-generic-sharing.c b/mono/mini/mini-generic-sharing.c index a4963295fcb..94312a18f43 100644 --- a/mono/mini/mini-generic-sharing.c +++ b/mono/mini/mini-generic-sharing.c @@ -12,6 +12,7 @@ #include <mono/metadata/class.h> #include <mono/metadata/method-builder.h> +#include <mono/metadata/reflection-internals.h> #include <mono/utils/mono-counters.h> #include "mini.h" @@ -1468,6 +1469,7 @@ static gpointer instantiate_info (MonoDomain *domain, MonoRuntimeGenericContextInfoTemplate *oti, MonoGenericContext *context, MonoClass *klass) { + MonoError error; gpointer data; gboolean temporary; @@ -1516,8 +1518,12 @@ instantiate_info (MonoDomain *domain, MonoRuntimeGenericContextInfoTemplate *oti } case MONO_RGCTX_INFO_TYPE: return data; - case MONO_RGCTX_INFO_REFLECTION_TYPE: - return mono_type_get_object (domain, (MonoType *)data); + case MONO_RGCTX_INFO_REFLECTION_TYPE: { + MonoReflectionType *ret = mono_type_get_object_checked (domain, (MonoType *)data, &error); + mono_error_raise_exception (&error); /* FIXME don't raise here */ + + return ret; + } case MONO_RGCTX_INFO_METHOD: return data; case MONO_RGCTX_INFO_GENERIC_METHOD_CODE: { diff --git a/mono/mini/mini-runtime.c b/mono/mini/mini-runtime.c index a16063cb2d2..514dbbeefaf 100644 --- a/mono/mini/mini-runtime.c +++ b/mono/mini/mini-runtime.c @@ -47,6 +47,7 @@ #include <mono/metadata/mempool-internals.h> #include <mono/metadata/attach.h> #include <mono/metadata/runtime.h> +#include <mono/metadata/reflection-internals.h> #include <mono/utils/mono-math.h> #include <mono/utils/mono-compiler.h> #include <mono/utils/mono-counters.h> @@ -1566,8 +1567,9 @@ mono_resolve_patch_target (MonoMethod *method, MonoDomain *domain, guint8 *code, mono_class_init (handle_class); mono_class_init (mono_class_from_mono_type ((MonoType *)handle)); - target = - mono_type_get_object (domain, (MonoType *)handle); + target = mono_type_get_object_checked (domain, (MonoType *)handle, &error); + mono_error_raise_exception (&error); + break; } case MONO_PATCH_INFO_LDTOKEN: { |