[runtime] Move some mono_error_raise_exception () calls to icalls from utility functi...
[mono.git] / mono / metadata / icall.c
index ba18aac5ac1dc12273a31838da77f1d752ee9b99..82d2c58996f37486b8f9cc672dfb4240ad32197a 100644 (file)
@@ -108,8 +108,16 @@ extern MonoString* ves_icall_System_Environment_GetOSVersionString (void);
 
 ICALL_EXPORT MonoReflectionAssembly* ves_icall_System_Reflection_Assembly_GetCallingAssembly (void);
 
+/* Lazy class loading functions */
+static GENERATE_GET_CLASS_WITH_CACHE (system_version, System, Version)
+static GENERATE_GET_CLASS_WITH_CACHE (assembly_name, System.Reflection, AssemblyName)
+static GENERATE_GET_CLASS_WITH_CACHE (constructor_info, System.Reflection, ConstructorInfo)
+static GENERATE_GET_CLASS_WITH_CACHE (property_info, System.Reflection, PropertyInfo)
+static GENERATE_GET_CLASS_WITH_CACHE (event_info, System.Reflection, EventInfo)
+static GENERATE_GET_CLASS_WITH_CACHE (module, System.Reflection, Module)
+
 static MonoArray*
-type_array_from_modifiers (MonoImage *image, MonoType *type, int optional);
+type_array_from_modifiers (MonoImage *image, MonoType *type, int optional, MonoError *error);
 
 static inline MonoBoolean
 is_generic_parameter (MonoType *type)
@@ -118,10 +126,12 @@ is_generic_parameter (MonoType *type)
 }
 
 static void
-mono_class_init_or_throw (MonoClass *klass)
+mono_class_init_checked (MonoClass *klass, MonoError *error)
 {
+       mono_error_init (error);
+
        if (!mono_class_init (klass))
-               mono_raise_exception (mono_class_get_exception_for_failure (klass));
+               mono_error_set_exception_instance (error, mono_class_get_exception_for_failure (klass));
 }
 
 ICALL_EXPORT MonoObject *
@@ -540,7 +550,8 @@ ves_icall_System_Array_CreateInstanceImpl (MonoReflectionType *type, MonoArray *
        }
 
        klass = mono_class_from_mono_type (type->type);
-       mono_class_init_or_throw (klass);
+       mono_class_init_checked (klass, &error);
+       mono_error_raise_exception (&error);
 
        if (bounds && (mono_array_length (bounds) == 1) && (mono_array_get (bounds, gint32, 0) != 0))
                /* vectors are not the same as one dimensional arrays with no-zero bounds */
@@ -590,7 +601,8 @@ ves_icall_System_Array_CreateInstanceImpl64 (MonoReflectionType *type, MonoArray
        }
 
        klass = mono_class_from_mono_type (type->type);
-       mono_class_init_or_throw (klass);
+       mono_class_init_checked (klass, &error);
+       mono_error_raise_exception (&error);
 
        if (bounds && (mono_array_length (bounds) == 1) && (mono_array_get (bounds, gint64, 0) != 0))
                /* vectors are not the same as one dimensional arrays with no-zero bounds */
@@ -885,6 +897,7 @@ ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetObjectValue (MonoObj
 ICALL_EXPORT void
 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_RunClassConstructor (MonoType *handle)
 {
+       MonoError error;
        MonoClass *klass;
        MonoVTable *vtable;
 
@@ -896,10 +909,15 @@ ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_RunClassConstructor (Mo
        if (klass->generic_container)
                return;
 
-       vtable = mono_class_vtable_full (mono_domain_get (), klass, TRUE);
+       vtable = mono_class_vtable_full (mono_domain_get (), klass, &error);
+       if (!is_ok (&error)) {
+               mono_error_set_pending_exception (&error);
+               return;
+       }
 
        /* This will call the type constructor */
-       mono_runtime_class_init (vtable);
+       if (!mono_runtime_class_init_full (vtable, &error))
+               mono_error_set_pending_exception (&error);
 }
 
 ICALL_EXPORT void
@@ -915,7 +933,13 @@ ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_RunModuleConstructor (M
                        return;
                }
                /*It's fine to raise the exception here*/
-               mono_runtime_class_init (mono_class_vtable_full (mono_domain_get (), module_klass, TRUE));
+               MonoVTable * vtable = mono_class_vtable_full (mono_domain_get (), module_klass, &error);
+               if (!is_ok (&error)) {
+                       mono_error_set_pending_exception (&error);
+                       return;
+               }
+               if (!mono_runtime_class_init_full (vtable, &error))
+                       mono_error_set_pending_exception (&error);
        }
 }
 
@@ -1143,7 +1167,7 @@ ves_icall_System_Object_GetType (MonoObject *obj)
 }
 
 ICALL_EXPORT void
-mono_type_type_from_obj (MonoReflectionType *mtype, MonoObject *obj)
+ves_icall_MonoType_type_from_obj (MonoReflectionType *mtype, MonoObject *obj)
 {
        mtype->type = &obj->vtable->klass->byval_arg;
        g_assert (mtype->type->type);
@@ -1334,9 +1358,9 @@ type_from_parsed_name (MonoTypeNameParse *info, MonoBoolean ignoreCase, MonoErro
 }
 
 ICALL_EXPORT MonoReflectionType*
-ves_icall_type_from_name (MonoString *name,
-                         MonoBoolean throwOnError,
-                         MonoBoolean ignoreCase)
+ves_icall_System_Type_internal_from_name (MonoString *name,
+                                                                                 MonoBoolean throwOnError,
+                                                                                 MonoBoolean ignoreCase)
 {
        MonoError error;
        char *str = mono_string_to_utf8 (name);
@@ -1387,7 +1411,7 @@ ves_icall_type_from_name (MonoString *name,
 
 
 ICALL_EXPORT MonoReflectionType*
-ves_icall_type_from_handle (MonoType *handle)
+ves_icall_System_Type_internal_from_handle (MonoType *handle)
 {
        MonoError error;
        MonoReflectionType *ret;
@@ -1521,7 +1545,7 @@ mono_type_get_underlying_type_ignore_byref (MonoType *type)
 }
 
 ICALL_EXPORT guint32
-ves_icall_type_is_assignable_from (MonoReflectionType *type, MonoReflectionType *c)
+ves_icall_RuntimeTypeHandle_type_is_assignable_from (MonoReflectionType *type, MonoReflectionType *c)
 {
        MonoClass *klass;
        MonoClass *klassc;
@@ -1560,15 +1584,17 @@ ves_icall_type_is_assignable_from (MonoReflectionType *type, MonoReflectionType
 }
 
 ICALL_EXPORT guint32
-ves_icall_type_IsInstanceOfType (MonoReflectionType *type, MonoObject *obj)
+ves_icall_RuntimeTypeHandle_IsInstanceOfType (MonoReflectionType *type, MonoObject *obj)
 {
+       MonoError error;
        MonoClass *klass = mono_class_from_mono_type (type->type);
-       mono_class_init_or_throw (klass);
+       mono_class_init_checked (klass, &error);
+       mono_error_raise_exception (&error);
        return mono_object_isinst (obj, klass) != NULL;
 }
 
 ICALL_EXPORT guint32
-ves_icall_get_attributes (MonoReflectionType *type)
+ves_icall_RuntimeTypeHandle_GetAttributes (MonoReflectionType *type)
 {
        MonoClass *klass = mono_class_from_mono_type (type->type);
        return klass->flags;
@@ -1648,12 +1674,16 @@ ves_icall_System_Reflection_FieldInfo_GetTypeModifiers (MonoReflectionField *fie
 {
        MonoError error;
        MonoType *type = mono_field_get_type_checked (field->field, &error);
+       MonoArray *res;
+
        if (!mono_error_ok (&error)) {
                mono_error_set_pending_exception (&error);
                return NULL;
        }
 
-       return type_array_from_modifiers (field->field->parent->image, type, optional);
+       res = type_array_from_modifiers (field->field->parent->image, type, optional, &error);
+       mono_error_raise_exception (&error);
+       return res;
 }
 
 ICALL_EXPORT int
@@ -1875,9 +1905,17 @@ ves_icall_MonoField_SetValueInternal (MonoReflectionField *field, MonoObject *ob
        }
 
        if (type->attrs & FIELD_ATTRIBUTE_STATIC) {
-               MonoVTable *vtable = mono_class_vtable_full (mono_object_domain (field), cf->parent, TRUE);
-               if (!vtable->initialized)
-                       mono_runtime_class_init (vtable);
+               MonoVTable *vtable = mono_class_vtable_full (mono_object_domain (field), cf->parent, &error);
+               if (!is_ok (&error)) {
+                       mono_error_set_pending_exception (&error);
+                       return;
+               }
+               if (!vtable->initialized) {
+                       if (!mono_runtime_class_init_full (vtable, &error)) {
+                               mono_error_set_pending_exception (&error);
+                               return;
+                       }
+               }
                mono_field_static_set_value (vtable, cf, v);
        } else {
                mono_field_set_value (obj, cf, v);
@@ -2029,7 +2067,7 @@ typedef enum {
 } PInfo;
 
 ICALL_EXPORT void
-ves_icall_get_property_info (const MonoReflectionProperty *property, MonoPropertyInfo *info, PInfo req_info)
+ves_icall_MonoPropertyInfo_get_property_info (const MonoReflectionProperty *property, MonoPropertyInfo *info, PInfo req_info)
 {
        MonoError error;
        MonoReflectionType *rt;
@@ -2087,7 +2125,7 @@ ves_icall_get_property_info (const MonoReflectionProperty *property, MonoPropert
 }
 
 ICALL_EXPORT void
-ves_icall_get_event_info (MonoReflectionMonoEvent *event, MonoEventInfo *info)
+ves_icall_MonoEventInfo_get_event_info (MonoReflectionMonoEvent *event, MonoEventInfo *info)
 {
        MonoError error;
        MonoReflectionType *rt;
@@ -2276,8 +2314,10 @@ ves_icall_Type_GetInterfaceMapData (MonoReflectionType *type, MonoReflectionType
        MonoDomain *domain;
        MonoError error;
 
-       mono_class_init_or_throw (klass);
-       mono_class_init_or_throw (iclass);
+       mono_class_init_checked (klass, &error);
+       mono_error_raise_exception (&error);
+       mono_class_init_checked (iclass, &error);
+       mono_error_raise_exception (&error);
 
        mono_class_setup_vtable (klass);
 
@@ -2305,8 +2345,11 @@ ves_icall_Type_GetInterfaceMapData (MonoReflectionType *type, MonoReflectionType
 ICALL_EXPORT void
 ves_icall_Type_GetPacking (MonoReflectionType *type, guint32 *packing, guint32 *size)
 {
+       MonoError error;
        MonoClass *klass = mono_class_from_mono_type (type->type);
-       mono_class_init_or_throw (klass);
+
+       mono_class_init_checked (klass, &error);
+       mono_error_raise_exception (&error);
 
        if (image_is_dynamic (klass->image)) {
                MonoReflectionTypeBuilder *tb = (MonoReflectionTypeBuilder*)type;
@@ -2318,7 +2361,7 @@ ves_icall_Type_GetPacking (MonoReflectionType *type, guint32 *packing, guint32 *
 }
 
 ICALL_EXPORT MonoReflectionType*
-ves_icall_MonoType_GetElementType (MonoReflectionType *type)
+ves_icall_RuntimeTypeHandle_GetElementType (MonoReflectionType *type)
 {
        MonoError error;
        MonoReflectionType *ret;
@@ -2332,7 +2375,8 @@ ves_icall_MonoType_GetElementType (MonoReflectionType *type)
        }
 
        klass = mono_class_from_mono_type (type->type);
-       mono_class_init_or_throw (klass);
+       mono_class_init_checked (klass, &error);
+       mono_error_raise_exception (&error);
 
        // GetElementType should only return a type for:
        // Array Pointer PassedByRef
@@ -2351,7 +2395,7 @@ ves_icall_MonoType_GetElementType (MonoReflectionType *type)
 }
 
 ICALL_EXPORT MonoReflectionType*
-ves_icall_get_type_parent (MonoReflectionType *type)
+ves_icall_RuntimeTypeHandle_GetBaseType (MonoReflectionType *type)
 {
        MonoError error;
        MonoReflectionType *ret;
@@ -2370,34 +2414,42 @@ ves_icall_get_type_parent (MonoReflectionType *type)
 }
 
 ICALL_EXPORT MonoBoolean
-ves_icall_type_ispointer (MonoReflectionType *type)
+ves_icall_RuntimeTypeHandle_IsPointer (MonoReflectionType *type)
 {
        return type->type->type == MONO_TYPE_PTR;
 }
 
 ICALL_EXPORT MonoBoolean
-ves_icall_type_isprimitive (MonoReflectionType *type)
+ves_icall_RuntimeTypeHandle_IsPrimitive (MonoReflectionType *type)
 {
        return (!type->type->byref && (((type->type->type >= MONO_TYPE_BOOLEAN) && (type->type->type <= MONO_TYPE_R8)) || (type->type->type == MONO_TYPE_I) || (type->type->type == MONO_TYPE_U)));
 }
 
 ICALL_EXPORT MonoBoolean
-ves_icall_type_isbyref (MonoReflectionType *type)
+ves_icall_RuntimeTypeHandle_IsByRef (MonoReflectionType *type)
 {
        return type->type->byref;
 }
 
 ICALL_EXPORT MonoBoolean
-ves_icall_type_iscomobject (MonoReflectionType *type)
+ves_icall_RuntimeTypeHandle_IsComObject (MonoReflectionType *type)
 {
+       MonoError error;
        MonoClass *klass = mono_class_from_mono_type (type->type);
-       mono_class_init_or_throw (klass);
+       mono_class_init_checked (klass, &error);
+       mono_error_raise_exception (&error);
 
        return mono_class_is_com_object (klass);
 }
 
+ICALL_EXPORT guint32
+ves_icall_RuntimeTypeHandle_GetMetadataToken (MonoReflectionType *obj)
+{
+       return mono_reflection_get_token ((MonoObject*)obj);
+}
+
 ICALL_EXPORT MonoReflectionModule*
-ves_icall_MonoType_get_Module (MonoReflectionType *type)
+ves_icall_RuntimeTypeHandle_GetModule (MonoReflectionType *type)
 {
        MonoError error;
        MonoReflectionModule *result = NULL;
@@ -2409,7 +2461,7 @@ ves_icall_MonoType_get_Module (MonoReflectionType *type)
 }
 
 ICALL_EXPORT MonoReflectionAssembly*
-ves_icall_MonoType_get_Assembly (MonoReflectionType *type)
+ves_icall_RuntimeTypeHandle_GetAssembly (MonoReflectionType *type)
 {
        MonoError error;
        MonoDomain *domain = mono_domain_get (); 
@@ -2483,7 +2535,7 @@ ves_icall_MonoType_get_Namespace (MonoReflectionType *type)
 }
 
 ICALL_EXPORT gint32
-ves_icall_MonoType_GetArrayRank (MonoReflectionType *type)
+ves_icall_RuntimeTypeHandle_GetArrayRank (MonoReflectionType *type)
 {
        MonoClass *klass;
 
@@ -2544,7 +2596,7 @@ ves_icall_MonoType_GetGenericArguments (MonoReflectionType *type, MonoBoolean ru
 }
 
 ICALL_EXPORT gboolean
-ves_icall_Type_get_IsGenericTypeDefinition (MonoReflectionType *type)
+ves_icall_RuntimeTypeHandle_IsGenericTypeDefinition (MonoReflectionType *type)
 {
        MonoClass *klass;
 
@@ -2559,7 +2611,7 @@ ves_icall_Type_get_IsGenericTypeDefinition (MonoReflectionType *type)
 }
 
 ICALL_EXPORT MonoReflectionType*
-ves_icall_Type_GetGenericTypeDefinition_impl (MonoReflectionType *type)
+ves_icall_RuntimeTypeHandle_GetGenericTypeDefinition_impl (MonoReflectionType *type)
 {
        MonoError error;
        MonoReflectionType *ret;
@@ -2601,7 +2653,8 @@ ves_icall_Type_MakeGenericType (MonoReflectionType *type, MonoArray *type_array)
        int i, count;
 
        g_assert (IS_MONOTYPE (type));
-       mono_class_init_or_throw (mono_class_from_mono_type (type->type));
+       mono_class_init_checked (mono_class_from_mono_type (type->type), &error);
+       mono_error_raise_exception (&error);
 
        count = mono_array_length (type_array);
        types = g_new0 (MonoType *, count);
@@ -2631,7 +2684,7 @@ ves_icall_Type_MakeGenericType (MonoReflectionType *type, MonoArray *type_array)
 }
 
 ICALL_EXPORT gboolean
-ves_icall_Type_get_IsGenericType (MonoReflectionType *type)
+ves_icall_RuntimeTypeHandle_HasInstantiation (MonoReflectionType *type)
 {
        MonoClass *klass;
 
@@ -2695,7 +2748,7 @@ ves_icall_Type_GetGenericParameterConstraints (MonoReflectionType *type)
 }
 
 ICALL_EXPORT MonoBoolean
-ves_icall_MonoType_get_IsGenericParameter (MonoReflectionType *type)
+ves_icall_RuntimeTypeHandle_IsGenericVariable (MonoReflectionType *type)
 {
        return is_generic_parameter (type->type);
 }
@@ -2727,7 +2780,8 @@ ves_icall_MonoType_GetCorrespondingInflatedMethod (MonoReflectionType *type,
        domain = ((MonoObject *)type)->vtable->domain;
 
        klass = mono_class_from_mono_type (type->type);
-       mono_class_init_or_throw (klass);
+       mono_class_init_checked (klass, &error);
+       mono_error_raise_exception (&error);
 
        iter = NULL;
        while ((method = mono_class_get_methods (klass, &iter))) {
@@ -2954,7 +3008,8 @@ ves_icall_InternalInvoke (MonoReflectionMethod *method, MonoObject *this_arg, Mo
                mono_security_core_clr_ensure_reflection_access_method (m);
 
        if (!(m->flags & METHOD_ATTRIBUTE_STATIC)) {
-               if (!mono_class_vtable_full (mono_object_domain (method), m->klass, FALSE)) {
+               if (!mono_class_vtable_full (mono_object_domain (method), m->klass, &error)) {
+                       mono_error_cleanup (&error); /* FIXME does this make sense? */
                        mono_gc_wbarrier_generic_store (exc, (MonoObject*) mono_class_get_exception_for_failure (m->klass));
                        return NULL;
                }
@@ -3268,7 +3323,8 @@ ves_icall_System_Enum_ToObject (MonoReflectionType *enumType, guint64 value)
        domain = mono_object_domain (enumType); 
        enumc = mono_class_from_mono_type (enumType->type);
 
-       mono_class_init_or_throw (enumc);
+       mono_class_init_checked (enumc, &error);
+       mono_error_raise_exception (&error);
 
        etype = mono_class_enum_basetype (enumc);
 
@@ -3327,7 +3383,8 @@ ves_icall_System_Enum_get_underlying_type (MonoReflectionType *type)
        MonoClass *klass;
 
        klass = mono_class_from_mono_type (type->type);
-       mono_class_init_or_throw (klass);
+       mono_class_init_checked (klass, &error);
+       mono_error_raise_exception (&error);
 
        etype = mono_class_enum_basetype (klass);
        if (!etype) {
@@ -3429,6 +3486,7 @@ ves_icall_System_Enum_get_hashcode (MonoObject *eobj)
 ICALL_EXPORT MonoBoolean
 ves_icall_System_Enum_GetEnumValuesAndNames (MonoReflectionType *type, MonoArray **values, MonoArray **names)
 {
+       MonoError error;
        MonoDomain *domain = mono_object_domain (type); 
        MonoClass *enumc = mono_class_from_mono_type (type->type);
        guint j = 0, nvalues;
@@ -3438,7 +3496,8 @@ ves_icall_System_Enum_GetEnumValuesAndNames (MonoReflectionType *type, MonoArray
        guint64 field_value, previous_value = 0;
        gboolean sorted = TRUE;
 
-       mono_class_init_or_throw (enumc);
+       mono_class_init_checked (enumc, &error);
+       mono_error_raise_exception (&error);
 
        if (!enumc->enumtype) {
                mono_set_pending_exception (mono_get_exception_argument ("enumType", "Type provided must be an Enum."));
@@ -3524,7 +3583,7 @@ ves_icall_Type_GetFields_internal (MonoReflectionType *type, MonoString *name, g
        mono_ptr_array_init (tmp_array, 2, MONO_ROOT_SOURCE_REFLECTION, "temporary reflection fields list");
        
 handle_parent: 
-       if (klass->exception_type != MONO_EXCEPTION_NONE) {
+       if (mono_class_has_failure (klass)) {
                mono_ptr_array_destroy (tmp_array);
                mono_set_pending_exception (mono_class_get_exception_for_failure (klass));
                return NULL;
@@ -3641,7 +3700,7 @@ mono_class_get_methods_by_name (MonoClass *klass, const char *name, guint32 bfla
 
        mono_class_setup_methods (klass);
        mono_class_setup_vtable (klass);
-       if (klass->exception_type != MONO_EXCEPTION_NONE || mono_loader_get_last_error ())
+       if (mono_class_has_failure (klass) || mono_loader_get_last_error ())
                goto loader_error;
 
        if (is_generic_parameter (&klass->byval_arg))
@@ -3657,7 +3716,7 @@ mono_class_get_methods_by_name (MonoClass *klass, const char *name, guint32 bfla
 handle_parent:
        mono_class_setup_methods (klass);
        mono_class_setup_vtable (klass);
-       if (klass->exception_type != MONO_EXCEPTION_NONE || mono_loader_get_last_error ())
+       if (mono_class_has_failure (klass) || mono_loader_get_last_error ())
                goto loader_error;              
 
        iter = NULL;
@@ -3714,7 +3773,7 @@ loader_error:
                g_free (method_slots);
        g_ptr_array_free (array, TRUE);
 
-       if (klass->exception_type != MONO_EXCEPTION_NONE) {
+       if (mono_class_has_failure (klass)) {
                *ex = mono_class_get_exception_for_failure (klass);
        } else {
                *ex = mono_loader_error_prepare_exception (mono_loader_get_last_error ());
@@ -3748,7 +3807,11 @@ ves_icall_Type_GetMethodsByName (MonoReflectionType *type, MonoString *name, gui
        klass = mono_class_from_mono_type (type->type);
        refklass = mono_class_from_mono_type (reftype->type);
        domain = ((MonoObject *)type)->vtable->domain;
-       array_vtable = mono_class_vtable_full (domain, MethodInfo_array, TRUE);
+       array_vtable = mono_class_vtable_full (domain, MethodInfo_array, &error);
+       if (!is_ok (&error)) {
+               mono_error_set_pending_exception (&error);
+               return NULL;
+       }
        if (type->type->byref) {
                res = mono_array_new_specific_checked (array_vtable, 0, &error);
                mono_error_set_pending_exception (&error);
@@ -3791,7 +3854,6 @@ ICALL_EXPORT MonoArray*
 ves_icall_Type_GetConstructors_internal (MonoReflectionType *type, guint32 bflags, MonoReflectionType *reftype)
 {
        MonoDomain *domain; 
-       static MonoClass *System_Reflection_ConstructorInfo;
        MonoClass *startklass, *klass, *refklass;
        MonoArray *res;
        MonoMethod *method;
@@ -3809,12 +3871,8 @@ ves_icall_Type_GetConstructors_internal (MonoReflectionType *type, guint32 bflag
        klass = startklass = mono_class_from_mono_type (type->type);
        refklass = mono_class_from_mono_type (reftype->type);
 
-       if (!System_Reflection_ConstructorInfo)
-               System_Reflection_ConstructorInfo = mono_class_from_name (
-                       mono_defaults.corlib, "System.Reflection", "ConstructorInfo");
-
        mono_class_setup_methods (klass);
-       if (klass->exception_type != MONO_EXCEPTION_NONE) {
+       if (mono_class_has_failure (klass)) {
                mono_set_pending_exception (mono_class_get_exception_for_failure (klass));
                return NULL;
        }
@@ -3854,7 +3912,7 @@ ves_icall_Type_GetConstructors_internal (MonoReflectionType *type, guint32 bflag
                mono_ptr_array_append (tmp_array, member);
        }
 
-       res = mono_array_new_cached (domain, System_Reflection_ConstructorInfo, mono_ptr_array_size (tmp_array));
+       res = mono_array_new_cached (domain, mono_class_get_constructor_info_class (), mono_ptr_array_size (tmp_array));
 
        for (i = 0; i < mono_ptr_array_size (tmp_array); ++i)
                mono_array_setref (res, i, mono_ptr_array_get (tmp_array, i));
@@ -3927,7 +3985,6 @@ ves_icall_Type_GetPropertiesByName (MonoReflectionType *type, MonoString *name,
 {
        MonoError error;
        MonoDomain *domain; 
-       static MonoClass *System_Reflection_PropertyInfo;
        MonoClass *startklass, *klass;
        MonoArray *res;
        MonoMethod *method;
@@ -3944,13 +4001,9 @@ ves_icall_Type_GetPropertiesByName (MonoReflectionType *type, MonoString *name,
        
        mono_ptr_array_init (tmp_array, 8, MONO_ROOT_SOURCE_REFLECTION, "temporary reflection properties list"); /*This the average for ASP.NET types*/
 
-       if (!System_Reflection_PropertyInfo)
-               System_Reflection_PropertyInfo = mono_class_from_name (
-                       mono_defaults.corlib, "System.Reflection", "PropertyInfo");
-
        domain = ((MonoObject *)type)->vtable->domain;
        if (type->type->byref)
-               return mono_array_new_cached (domain, System_Reflection_PropertyInfo, 0);
+               return mono_array_new_cached (domain, mono_class_get_property_info_class (), 0);
        klass = startklass = mono_class_from_mono_type (type->type);
 
        if (name != NULL) {
@@ -3962,7 +4015,7 @@ ves_icall_Type_GetPropertiesByName (MonoReflectionType *type, MonoString *name,
 handle_parent:
        mono_class_setup_methods (klass);
        mono_class_setup_vtable (klass);
-       if (klass->exception_type != MONO_EXCEPTION_NONE || mono_loader_get_last_error ())
+       if (mono_class_has_failure (klass) || mono_loader_get_last_error ())
                goto loader_error;
 
        iter = NULL;
@@ -4022,7 +4075,7 @@ handle_parent:
        g_hash_table_destroy (properties);
        g_free (propname);
 
-       res = mono_array_new_cached (domain, System_Reflection_PropertyInfo, mono_ptr_array_size (tmp_array));
+       res = mono_array_new_cached (domain, mono_class_get_property_info_class (), mono_ptr_array_size (tmp_array));
        for (i = 0; i < mono_ptr_array_size (tmp_array); ++i)
                mono_array_setref (res, i, mono_ptr_array_get (tmp_array, i));
 
@@ -4033,7 +4086,7 @@ handle_parent:
 
 
 loader_error:
-       if (klass->exception_type != MONO_EXCEPTION_NONE) {
+       if (mono_class_has_failure (klass)) {
                mono_error_set_exception_instance (&error, mono_class_get_exception_for_failure (klass));
        } else {
                mono_error_set_from_loader_error (&error);
@@ -4072,7 +4125,6 @@ ves_icall_Type_GetEvents_internal (MonoReflectionType *type, MonoString *name, g
 {
        MonoError error;
        MonoDomain *domain; 
-       static MonoClass *System_Reflection_EventInfo;
        MonoClass *startklass, *klass;
        MonoArray *res;
        MonoMethod *method;
@@ -4088,20 +4140,16 @@ ves_icall_Type_GetEvents_internal (MonoReflectionType *type, MonoString *name, g
        
        mono_ptr_array_init (tmp_array, 4, MONO_ROOT_SOURCE_REFLECTION, "temporary reflection events list");
 
-       if (!System_Reflection_EventInfo)
-               System_Reflection_EventInfo = mono_class_from_name (
-                       mono_defaults.corlib, "System.Reflection", "EventInfo");
-
        domain = mono_object_domain (type);
        if (type->type->byref)
-               return mono_array_new_cached (domain, System_Reflection_EventInfo, 0);
+               return mono_array_new_cached (domain, mono_class_get_event_info_class (), 0);
        klass = startklass = mono_class_from_mono_type (type->type);
 
        events = g_hash_table_new (event_hash, (GEqualFunc)event_equal);
 handle_parent:
        mono_class_setup_methods (klass);
        mono_class_setup_vtable (klass);
-       if (klass->exception_type != MONO_EXCEPTION_NONE || mono_loader_get_last_error ())
+       if (mono_class_has_failure (klass) || mono_loader_get_last_error ())
                goto loader_error;
 
        iter = NULL;
@@ -4169,7 +4217,7 @@ handle_parent:
 
        g_hash_table_destroy (events);
 
-       res = mono_array_new_cached (domain, System_Reflection_EventInfo, mono_ptr_array_size (tmp_array));
+       res = mono_array_new_cached (domain, mono_class_get_event_info_class (), mono_ptr_array_size (tmp_array));
 
        for (i = 0; i < mono_ptr_array_size (tmp_array); ++i)
                mono_array_setref (res, i, mono_ptr_array_get (tmp_array, i));
@@ -4182,7 +4230,7 @@ handle_parent:
        return res;
 
 loader_error:
-       if (klass->exception_type != MONO_EXCEPTION_NONE) {
+       if (mono_class_has_failure (klass)) {
                mono_error_set_exception_instance (&error, mono_class_get_exception_for_failure (klass));
        } else {
                mono_error_set_from_loader_error (&error);
@@ -4376,7 +4424,7 @@ ves_icall_System_Reflection_Assembly_InternalGetType (MonoReflectionAssembly *as
                MonoClass *klass = mono_type_get_class (type);
 
                /* need to report exceptions ? */
-               if (throwOnError && klass->exception_type) {
+               if (throwOnError && mono_class_has_failure (klass)) {
                        /* report SecurityException (or others) that occured when loading the assembly */
                        MonoException *exc = mono_class_get_exception_for_failure (klass);
                        mono_loader_clear_error ();
@@ -4578,21 +4626,16 @@ ves_icall_System_Reflection_Assembly_GetManifestResourceNames (MonoReflectionAss
 static MonoObject*
 create_version (MonoDomain *domain, guint32 major, guint32 minor, guint32 build, guint32 revision, MonoError *error)
 {
-       static MonoClass *System_Version = NULL;
        static MonoMethod *create_version = NULL;
        MonoObject *result;
        gpointer args [4];
 
        mono_error_init (error);
        
-       if (!System_Version) {
-               System_Version = mono_class_from_name (mono_defaults.corlib, "System", "Version");
-               g_assert (System_Version);
-       }
 
        if (!create_version) {
                MonoMethodDesc *desc = mono_method_desc_new (":.ctor(int,int,int,int)", FALSE);
-               create_version = mono_method_desc_search_in_class (desc, System_Version);
+               create_version = mono_method_desc_search_in_class (desc, mono_class_get_system_version_class ());
                g_assert (create_version);
                mono_method_desc_free (desc);
        }
@@ -4601,7 +4644,7 @@ create_version (MonoDomain *domain, guint32 major, guint32 minor, guint32 build,
        args [1] = &minor;
        args [2] = &build;
        args [3] = &revision;
-       result = mono_object_new_checked (domain, System_Version, error);
+       result = mono_object_new_checked (domain, mono_class_get_system_version_class (), error);
        return_val_if_nok (error, NULL);
 
        mono_runtime_invoke_checked (create_version, result, args, error);
@@ -4613,7 +4656,6 @@ create_version (MonoDomain *domain, guint32 major, guint32 minor, guint32 build,
 ICALL_EXPORT MonoArray*
 ves_icall_System_Reflection_Assembly_GetReferencedAssemblies (MonoReflectionAssembly *assembly) 
 {
-       static MonoClass *System_Reflection_AssemblyName;
        MonoError error;
        MonoArray *result;
        MonoDomain *domain = mono_object_domain (assembly);
@@ -4623,14 +4665,10 @@ ves_icall_System_Reflection_Assembly_GetReferencedAssemblies (MonoReflectionAsse
        MonoTableInfo *t;
        MonoObject *o;
 
-       if (!System_Reflection_AssemblyName)
-               System_Reflection_AssemblyName = mono_class_from_name (
-                       mono_defaults.corlib, "System.Reflection", "AssemblyName");
-
        t = &assembly->assembly->image->tables [MONO_TABLE_ASSEMBLYREF];
        count = t->rows;
 
-       result = mono_array_new (domain, System_Reflection_AssemblyName, count);
+       result = mono_array_new (domain, mono_class_get_assembly_name_class (), count);
 
        if (count > 0 && !create_culture) {
                MonoMethodDesc *desc = mono_method_desc_new (
@@ -4648,7 +4686,7 @@ ves_icall_System_Reflection_Assembly_GetReferencedAssemblies (MonoReflectionAsse
                mono_metadata_decode_row (t, i, cols, MONO_ASSEMBLYREF_SIZE);
 
                aname = (MonoReflectionAssemblyName *) mono_object_new_checked (
-                       domain, System_Reflection_AssemblyName, &error);
+                       domain, mono_class_get_assembly_name_class (), &error);
                mono_error_raise_exception (&error);
 
                MONO_OBJECT_SETREF (aname, name, mono_string_new (domain, mono_metadata_string_heap (image, cols [MONO_ASSEMBLYREF_NAME])));
@@ -4913,7 +4951,7 @@ ves_icall_System_Reflection_Assembly_GetModulesInternal (MonoReflectionAssembly
                if (modules [i])
                        real_module_count ++;
 
-       klass = mono_class_from_name (mono_defaults.corlib, "System.Reflection", "Module");
+       klass = mono_class_get_module_class ();
        res = mono_array_new (domain, klass, 1 + real_module_count + file_count);
 
        MonoReflectionModule *image_obj = mono_module_get_object_checked (domain, image, &error);
@@ -4995,7 +5033,7 @@ mono_method_get_equivalent_method (MonoMethod *method, MonoClass *klass)
        }
 
        mono_class_setup_methods (method->klass);
-       if (method->klass->exception_type)
+       if (mono_class_has_failure (method->klass))
                return NULL;
        for (i = 0; i < method->klass->method.count; ++i) {
                if (method->klass->methods [i] == method) {
@@ -5004,7 +5042,7 @@ mono_method_get_equivalent_method (MonoMethod *method, MonoClass *klass)
                }       
        }
        mono_class_setup_methods (klass);
-       if (klass->exception_type)
+       if (mono_class_has_failure (klass))
                return NULL;
        g_assert (offset >= 0 && offset < klass->method.count);
        return klass->methods [offset];
@@ -5128,8 +5166,11 @@ ves_icall_System_MonoType_getFullName (MonoReflectionType *object, gboolean full
 ICALL_EXPORT int
 vell_icall_MonoType_get_core_clr_security_level (MonoReflectionType *rfield)
 {
+       MonoError error;
        MonoClass *klass = mono_class_from_mono_type (rfield->type);
-       mono_class_init_or_throw (klass);
+
+       mono_class_init_checked (klass, &error);
+       mono_error_raise_exception (&error);
        return mono_security_core_clr_class_level (klass);
 }
 
@@ -5495,7 +5536,7 @@ ves_icall_System_Reflection_Assembly_GetTypes (MonoReflectionAssembly *assembly,
 
                if (t) {
                        klass = mono_type_get_class (t->type);
-                       if ((klass != NULL) && klass->exception_type) {
+                       if ((klass != NULL) && mono_class_has_failure (klass)) {
                                /* keep the class in the list */
                                list = g_list_append (list, klass);
                                /* and replace Type with NULL */
@@ -6052,7 +6093,7 @@ ves_icall_ModuleBuilder_create_modified_type (MonoReflectionTypeBuilder *tb, Mon
 }
 
 ICALL_EXPORT MonoBoolean
-ves_icall_Type_IsArrayImpl (MonoReflectionType *t)
+ves_icall_RuntimeTypeHandle_IsArray (MonoReflectionType *t)
 {
        MonoType *type;
        MonoBoolean res;
@@ -6064,17 +6105,20 @@ ves_icall_Type_IsArrayImpl (MonoReflectionType *t)
 }
 
 static void
-check_for_invalid_type (MonoClass *klass)
+check_for_invalid_type (MonoClass *klass, MonoError *error)
 {
        char *name;
        MonoString *str;
+
+       mono_error_init (error);
+
        if (klass->byval_arg.type != MONO_TYPE_TYPEDBYREF)
                return;
 
        name = mono_type_get_full_name (klass);
        str =  mono_string_new (mono_domain_get (), name);
        g_free (name);
-       mono_raise_exception ((MonoException*)mono_get_exception_type_load (str, NULL));
+       mono_error_set_exception_instance (error, mono_get_exception_type_load (str, NULL));
 
 }
 ICALL_EXPORT MonoReflectionType *
@@ -6085,7 +6129,8 @@ ves_icall_Type_make_array_type (MonoReflectionType *type, int rank)
        MonoClass *klass, *aklass;
 
        klass = mono_class_from_mono_type (type->type);
-       check_for_invalid_type (klass);
+       check_for_invalid_type (klass, &error);
+       mono_error_raise_exception (&error);
 
        if (rank == 0) //single dimentional array
                aklass = mono_array_class_get (klass, 1);
@@ -6106,8 +6151,10 @@ ves_icall_Type_make_byref_type (MonoReflectionType *type)
        MonoClass *klass;
 
        klass = mono_class_from_mono_type (type->type);
-       mono_class_init_or_throw (klass);
-       check_for_invalid_type (klass);
+       mono_class_init_checked (klass, &error);
+       mono_error_raise_exception (&error);
+       check_for_invalid_type (klass, &error);
+       mono_error_raise_exception (&error);
 
        ret = mono_type_get_object_checked (mono_object_domain (type), &klass->this_arg, &error);
        mono_error_raise_exception (&error);
@@ -6123,8 +6170,10 @@ ves_icall_Type_MakePointerType (MonoReflectionType *type)
        MonoClass *klass, *pklass;
 
        klass = mono_class_from_mono_type (type->type);
-       mono_class_init_or_throw (klass);
-       check_for_invalid_type (klass);
+       mono_class_init_checked (klass, &error);
+       mono_error_raise_exception (&error);
+       check_for_invalid_type (klass, &error);
+       mono_error_raise_exception (&error);
 
        pklass = mono_ptr_class_get (type->type);
 
@@ -6144,7 +6193,8 @@ ves_icall_System_Delegate_CreateDelegate_internal (MonoReflectionType *type, Mon
        gpointer func;
        MonoMethod *method = info->method;
 
-       mono_class_init_or_throw (delegate_class);
+       mono_class_init_checked (delegate_class, &error);
+       mono_error_raise_exception (&error);
 
        mono_assert (delegate_class->parent == mono_defaults.multicastdelegate_class);
 
@@ -6311,7 +6361,7 @@ ves_icall_Remoting_RealProxy_GetTransparentProxy (MonoObject *this_obj, MonoStri
 
        // mono_remote_class_vtable cannot handle errors well, so force any loading error to occur early
        mono_class_setup_vtable (klass);
-       if (klass->exception_type) {
+       if (mono_class_has_failure (klass)) {
                mono_set_pending_exception (mono_class_get_exception_for_failure (klass));
                return NULL;
        }
@@ -6888,7 +6938,8 @@ ves_icall_Remoting_RemotingServices_GetVirtualMethod (
 
        method = rmethod->method;
        klass = mono_class_from_mono_type (rtype->type);
-       mono_class_init_or_throw (klass);
+       mono_class_init_checked (klass, &error);
+       mono_error_raise_exception (&error);
 
        if (MONO_CLASS_IS_INTERFACE (klass))
                return NULL;
@@ -6931,11 +6982,16 @@ ves_icall_Remoting_RemotingServices_GetVirtualMethod (
 ICALL_EXPORT void
 ves_icall_System_Runtime_Activation_ActivationServices_EnableProxyActivation (MonoReflectionType *type, MonoBoolean enable)
 {
+       MonoError error;
        MonoClass *klass;
        MonoVTable* vtable;
 
        klass = mono_class_from_mono_type (type->type);
-       vtable = mono_class_vtable_full (mono_domain_get (), klass, TRUE);
+       vtable = mono_class_vtable_full (mono_domain_get (), klass, &error);
+       if (!is_ok (&error)) {
+               mono_error_set_pending_exception (&error);
+               return;
+       }
 
        mono_vtable_set_is_remote (vtable, enable);
 }
@@ -6960,7 +7016,8 @@ ves_icall_System_Runtime_Activation_ActivationServices_AllocateUninitializedClas
        
        domain = mono_object_domain (type);
        klass = mono_class_from_mono_type (type->type);
-       mono_class_init_or_throw (klass);
+       mono_class_init_checked (klass, &error);
+       mono_error_raise_exception (&error);
 
        if (MONO_CLASS_IS_INTERFACE (klass) || (klass->flags & TYPE_ATTRIBUTE_ABSTRACT)) {
                mono_set_pending_exception (mono_get_exception_argument ("type", "Type cannot be instantiated"));
@@ -6971,8 +7028,13 @@ ves_icall_System_Runtime_Activation_ActivationServices_AllocateUninitializedClas
                g_assert (klass->rank == 1);
                return (MonoObject *) mono_array_new (domain, klass->element_class, 0);
        } else {
+               MonoVTable *vtable = mono_class_vtable_full (domain, klass, &error);
+               if (!is_ok (&error)) {
+                       mono_error_set_pending_exception (&error);
+                       return NULL;
+               }
                /* Bypass remoting object creation check */
-               ret = mono_object_new_alloc_specific_checked (mono_class_vtable_full (domain, klass, TRUE), &error);
+               ret = mono_object_new_alloc_specific_checked (vtable, &error);
                mono_error_set_pending_exception (&error);
 
                return ret;
@@ -7022,7 +7084,7 @@ ves_icall_System_IO_DriveInfo_GetDriveType (MonoString *root_path_name)
 #endif
 
 ICALL_EXPORT gpointer
-ves_icall_RuntimeMethod_GetFunctionPointer (MonoMethod *method)
+ves_icall_RuntimeMethodHandle_GetFunctionPointer (MonoMethod *method)
 {
        return mono_compile_method (method);
 }
@@ -7198,7 +7260,8 @@ ves_icall_System_Activator_CreateInstanceInternal (MonoReflectionType *type)
        
        domain = mono_object_domain (type);
        klass = mono_class_from_mono_type (type->type);
-       mono_class_init_or_throw (klass);
+       mono_class_init_checked (klass, &error);
+       mono_error_raise_exception (&error);
 
        if (mono_class_is_nullable (klass))
                /* No arguments -> null */
@@ -7509,15 +7572,18 @@ mono_TypedReference_MakeTypedReferenceInternal (MonoObject *target, MonoArray *f
 }
 
 static void
-prelink_method (MonoMethod *method)
+prelink_method (MonoMethod *method, MonoError *error)
 {
        const char *exc_class, *exc_arg;
+
+       mono_error_init (error);
        if (!(method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL))
                return;
        mono_lookup_pinvoke_call (method, &exc_class, &exc_arg);
        if (exc_class) {
-               mono_raise_exception( 
-                       mono_exception_from_name_msg (mono_defaults.corlib, "System", exc_class, exc_arg ) );
+               mono_error_set_exception_instance (error,
+                       mono_exception_from_name_msg (mono_defaults.corlib, "System", exc_class, exc_arg));
+               return;
        }
        /* create the wrapper, too? */
 }
@@ -7525,20 +7591,27 @@ prelink_method (MonoMethod *method)
 ICALL_EXPORT void
 ves_icall_System_Runtime_InteropServices_Marshal_Prelink (MonoReflectionMethod *method)
 {
-       prelink_method (method->method);
+       MonoError error;
+
+       prelink_method (method->method, &error);
+       mono_error_raise_exception (&error);
 }
 
 ICALL_EXPORT void
 ves_icall_System_Runtime_InteropServices_Marshal_PrelinkAll (MonoReflectionType *type)
 {
+       MonoError error;
        MonoClass *klass = mono_class_from_mono_type (type->type);
        MonoMethod* m;
        gpointer iter = NULL;
 
-       mono_class_init_or_throw (klass);
+       mono_class_init_checked (klass, &error);
+       mono_error_raise_exception (&error);
 
-       while ((m = mono_class_get_methods (klass, &iter)))
-               prelink_method (m);
+       while ((m = mono_class_get_methods (klass, &iter))) {
+               prelink_method (m, &error);
+               mono_error_raise_exception (&error);
+       }
 }
 
 /* These parameters are "readonly" in corlib/System/NumberFormatter.cs */
@@ -7561,16 +7634,15 @@ ves_icall_System_NumberFormatter_GetFormatterTables (guint64 const **mantissas,
 /*
  * We return NULL for no modifiers so the corlib code can return Type.EmptyTypes
  * and avoid useless allocations.
- * 
- * MAY THROW
  */
 static MonoArray*
-type_array_from_modifiers (MonoImage *image, MonoType *type, int optional)
+type_array_from_modifiers (MonoImage *image, MonoType *type, int optional, MonoError *error)
 {
-       MonoError error;
        MonoReflectionType *rt;
        MonoArray *res;
        int i, count = 0;
+
+       mono_error_init (error);
        for (i = 0; i < type->num_mods; ++i) {
                if ((optional && !type->modifiers [i].required) || (!optional && type->modifiers [i].required))
                        count++;
@@ -7581,11 +7653,11 @@ 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)) {
-                       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 */ 
+                       MonoClass *klass = mono_class_get_checked (image, type->modifiers [i].token, error);
+                       return_val_if_nok (error, NULL);
 
-                       rt = mono_type_get_object_checked (mono_domain_get (), &klass->byval_arg, &error);
-                       mono_error_raise_exception (&error);
+                       rt = mono_type_get_object_checked (mono_domain_get (), &klass->byval_arg, error);
+                       return_val_if_nok (error, NULL);
 
                        mono_array_setref (res, count, rt);
                        count++;
@@ -7595,14 +7667,16 @@ type_array_from_modifiers (MonoImage *image, MonoType *type, int optional)
 }
 
 ICALL_EXPORT MonoArray*
-param_info_get_type_modifiers (MonoReflectionParameter *param, MonoBoolean optional)
+ves_icall_ParameterInfo_GetTypeModifiers (MonoReflectionParameter *param, MonoBoolean optional)
 {
+       MonoError error;
        MonoType *type = param->ClassImpl->type;
        MonoClass *member_class = mono_object_class (param->MemberImpl);
        MonoMethod *method = NULL;
        MonoImage *image;
        int pos;
        MonoMethodSignature *sig;
+       MonoArray *res;
 
        if (mono_class_is_reflection_method_or_constructor (member_class)) {
                MonoReflectionMethod *rmethod = (MonoReflectionMethod*)param->MemberImpl;
@@ -7630,7 +7704,9 @@ param_info_get_type_modifiers (MonoReflectionParameter *param, MonoBoolean optio
        else
                type = sig->params [pos];
 
-       return type_array_from_modifiers (image, type, optional);
+       res = type_array_from_modifiers (image, type, optional, &error);
+       mono_error_raise_exception (&error);
+       return res;
 }
 
 static MonoType*
@@ -7648,14 +7724,18 @@ get_property_type (MonoProperty *prop)
 }
 
 ICALL_EXPORT MonoArray*
-property_info_get_type_modifiers (MonoReflectionProperty *property, MonoBoolean optional)
+ves_icall_MonoPropertyInfo_GetTypeModifiers (MonoReflectionProperty *property, MonoBoolean optional)
 {
+       MonoError error;
        MonoType *type = get_property_type (property->property);
        MonoImage *image = property->klass->image;
+       MonoArray *res;
 
        if (!type)
                return NULL;
-       return type_array_from_modifiers (image, type, optional);
+       res = type_array_from_modifiers (image, type, optional, &error);
+       mono_error_raise_exception (&error);
+       return res;
 }
 
 /*
@@ -7709,13 +7789,19 @@ property_info_get_default_value (MonoReflectionProperty *property)
 ICALL_EXPORT MonoBoolean
 custom_attrs_defined_internal (MonoObject *obj, MonoReflectionType *attr_type)
 {
+       MonoError error;
        MonoClass *attr_class = mono_class_from_mono_type (attr_type->type);
        MonoCustomAttrInfo *cinfo;
        gboolean found;
 
-       mono_class_init_or_throw (attr_class);
+       mono_class_init_checked (attr_class, &error);
+       mono_error_raise_exception (&error);
 
-       cinfo = mono_reflection_get_custom_attrs_info (obj);
+       cinfo = mono_reflection_get_custom_attrs_info_checked (obj, &error);
+       if (!is_ok (&error)) {
+               mono_error_set_pending_exception (&error);
+               return FALSE;
+       }
        if (!cinfo)
                return FALSE;
        found = mono_custom_attrs_has_attr (cinfo, attr_class);
@@ -7731,8 +7817,10 @@ custom_attrs_get_by_type (MonoObject *obj, MonoReflectionType *attr_type)
        MonoArray *res;
        MonoError error;
 
-       if (attr_class)
-               mono_class_init_or_throw (attr_class);
+       if (attr_class) {
+               mono_class_init_checked (attr_class, &error);
+               mono_error_raise_exception (&error);
+       }
 
        res = mono_reflection_get_custom_attrs_by_type (obj, attr_class, &error);
        if (!mono_error_ok (&error)) {
@@ -7806,6 +7894,76 @@ ves_icall_System_StackFrame_GetILOffsetFromFile (MonoString *path, guint32 metho
        return il_offset;
 }
 
+ICALL_EXPORT gpointer
+ves_icall_Microsoft_Win32_NativeMethods_GetCurrentProcess (void)
+{
+       return GetCurrentProcess ();
+}
+
+ICALL_EXPORT MonoBoolean
+ves_icall_Microsoft_Win32_NativeMethods_GetExitCodeProcess (gpointer handle, gint32 *exitcode)
+{
+       return GetExitCodeProcess (handle, (guint32*) exitcode);
+}
+
+ICALL_EXPORT MonoBoolean
+ves_icall_Microsoft_Win32_NativeMethods_CloseProcess (gpointer handle)
+{
+#if defined(TARGET_WIN32) || defined(HOST_WIN32)
+       return CloseHandle (handle);
+#else
+       return CloseProcess (handle);
+#endif
+}
+
+ICALL_EXPORT MonoBoolean
+ves_icall_Microsoft_Win32_NativeMethods_TerminateProcess (gpointer handle, gint32 exitcode)
+{
+       return TerminateProcess (handle, exitcode);
+}
+
+ICALL_EXPORT gint32
+ves_icall_Microsoft_Win32_NativeMethods_WaitForInputIdle (gpointer handle, gint32 milliseconds)
+{
+       return WaitForInputIdle (handle, milliseconds);
+}
+
+ICALL_EXPORT MonoBoolean
+ves_icall_Microsoft_Win32_NativeMethods_GetProcessWorkingSetSize (gpointer handle, gsize *min, gsize *max)
+{
+       return GetProcessWorkingSetSize (handle, min, max);
+}
+
+ICALL_EXPORT MonoBoolean
+ves_icall_Microsoft_Win32_NativeMethods_SetProcessWorkingSetSize (gpointer handle, gsize min, gsize max)
+{
+       return SetProcessWorkingSetSize (handle, min, max);
+}
+
+ICALL_EXPORT MonoBoolean
+ves_icall_Microsoft_Win32_NativeMethods_GetProcessTimes (gpointer handle, gint64 *creationtime, gint64 *exittime, gint64 *kerneltime, gint64 *usertime)
+{
+       return GetProcessTimes (handle, (LPFILETIME) creationtime, (LPFILETIME) exittime, (LPFILETIME) kerneltime, (LPFILETIME) usertime);
+}
+
+ICALL_EXPORT gint32
+ves_icall_Microsoft_Win32_NativeMethods_GetCurrentProcessId (void)
+{
+       return mono_process_current_pid ();
+}
+
+ICALL_EXPORT gint32
+ves_icall_Microsoft_Win32_NativeMethods_GetPriorityClass (gpointer handle)
+{
+       return GetPriorityClass (handle);
+}
+
+ICALL_EXPORT MonoBoolean
+ves_icall_Microsoft_Win32_NativeMethods_SetPriorityClass (gpointer handle, gint32 priorityClass)
+{
+       return SetPriorityClass (handle, priorityClass);
+}
+
 #ifndef DISABLE_ICALL_TABLES
 
 #define ICALL_TYPE(id,name,first)