2009-12-09 Rodrigo Kumpera <rkumpera@novell.com>
[mono.git] / mono / metadata / icall.c
index a8d28707c5ec9d914fe2b5a43c80f024548d5e75..20e4ebb4ff0c51a7bf6899d5350010f065f15166 100644 (file)
@@ -24,7 +24,7 @@
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
-#if defined (PLATFORM_WIN32)
+#if defined (HOST_WIN32)
 #include <stdlib.h>
 #endif
 
 #include <mono/utils/monobitset.h>
 #include <mono/utils/mono-time.h>
 #include <mono/utils/mono-proclib.h>
+#include <mono/utils/mono-string.h>
+#include <mono/utils/mono-error-internals.h>
 
-#if defined (PLATFORM_WIN32)
+#if defined (HOST_WIN32)
 #include <windows.h>
 #include <shlobj.h>
 #endif
@@ -719,6 +721,7 @@ ves_icall_System_Array_FastCopy (MonoArray *source, int source_idx, MonoArray* d
        if (source->bounds || dest->bounds)
                return FALSE;
 
+       /* there's no integer overflow since mono_array_length returns an unsigned integer */
        if ((dest_idx + length > mono_array_length (dest)) ||
                (source_idx + length > mono_array_length (source)))
                return FALSE;
@@ -829,9 +832,11 @@ ves_icall_System_Array_SetGenericValueImpl (MonoObject *this, guint32 pos, gpoin
                mono_gc_wbarrier_generic_store (ea, *(gpointer*)value);
        } else {
                g_assert (ec->inited);
+               g_assert (esize == mono_class_value_size (ec, NULL));
                if (ec->has_references)
                        mono_gc_wbarrier_value_copy (ea, value, 1, ec);
-               memcpy (ea, value, esize);
+               else
+                       memcpy (ea, value, esize);
        }
 }
 
@@ -941,16 +946,17 @@ static void
 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_RunClassConstructor (MonoType *handle)
 {
        MonoClass *klass;
-
-       MONO_ARCH_SAVE_REGS;
+       MonoVTable *vtable;
 
        MONO_CHECK_ARG_NULL (handle);
 
        klass = mono_class_from_mono_type (handle);
        MONO_CHECK_ARG (handle, klass);
 
+       vtable = mono_class_vtable_full (mono_domain_get (), klass, TRUE);
+
        /* This will call the type constructor */
-       mono_runtime_class_init (mono_class_vtable (mono_domain_get (), klass));
+       mono_runtime_class_init (vtable);
 }
 
 static void
@@ -961,7 +967,8 @@ ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_RunModuleConstructor (M
        mono_image_check_for_module_cctor (image);
        if (image->has_module_cctor) {
                MonoClass *module_klass = mono_class_get (image, MONO_TOKEN_TYPE_DEF | 1);
-               mono_runtime_class_init (mono_class_vtable (mono_domain_get (), module_klass));
+               /*It's fine to raise the exception here*/
+               mono_runtime_class_init (mono_class_vtable_full (mono_domain_get (), module_klass, TRUE));
        }
 }
 
@@ -1617,16 +1624,6 @@ ves_icall_System_Reflection_FieldInfo_internal_from_handle_type (MonoClassField
        return mono_field_get_object (mono_domain_get (), klass, handle);
 }
 
-static MonoReflectionField*
-ves_icall_System_Reflection_FieldInfo_internal_from_handle (MonoClassField *handle)
-{
-       MONO_ARCH_SAVE_REGS;
-
-       g_assert (handle);
-
-       return mono_field_get_object (mono_domain_get (), handle->parent, handle);
-}
-
 static MonoArray*
 ves_icall_System_Reflection_FieldInfo_GetTypeModifiers (MonoReflectionField *field, MonoBoolean optional)
 {
@@ -1798,7 +1795,7 @@ ves_icall_MonoField_GetValueInternal (MonoReflectionField *field, MonoObject *ob
 
        vtable = NULL;
        if (is_static) {
-               vtable = mono_class_vtable (domain, cf->parent);
+               vtable = mono_class_vtable_full (domain, cf->parent, TRUE);
                if (!vtable->initialized && !(cf->type->attrs & FIELD_ATTRIBUTE_LITERAL))
                        mono_runtime_class_init (vtable);
        }
@@ -1913,7 +1910,7 @@ ves_icall_MonoField_SetValueInternal (MonoReflectionField *field, MonoObject *ob
        }
 
        if (cf->type->attrs & FIELD_ATTRIBUTE_STATIC) {
-               MonoVTable *vtable = mono_class_vtable (mono_object_domain (field), cf->parent);
+               MonoVTable *vtable = mono_class_vtable_full (mono_object_domain (field), cf->parent, TRUE);
                if (!vtable->initialized)
                        mono_runtime_class_init (vtable);
                mono_field_static_set_value (vtable, cf, v);
@@ -2147,7 +2144,6 @@ ves_icall_Type_GetInterfaceMapData (MonoReflectionType *type, MonoReflectionType
        mono_gc_wbarrier_generic_store (targets, (MonoObject*) mono_array_new (domain, mono_defaults.method_info_class, len));
        mono_gc_wbarrier_generic_store (methods, (MonoObject*) mono_array_new (domain, mono_defaults.method_info_class, len));
        iter = NULL;
-       iter = NULL;
        while ((method = mono_class_get_methods (iclass, &iter))) {
                member = mono_method_get_object (domain, method, iclass);
                mono_array_setref (*methods, i, member);
@@ -2351,7 +2347,7 @@ ves_icall_MonoType_GetGenericArguments (MonoReflectionType *type)
        MonoArray *res;
        MonoClass *klass, *pklass;
        MonoDomain *domain = mono_object_domain (type);
-       MonoVTable *array_vtable = mono_class_vtable (domain, mono_array_class_get_cached (mono_defaults.systemtype_class, 1));
+       MonoVTable *array_vtable = mono_class_vtable_full (domain, mono_array_class_get_cached (mono_defaults.systemtype_class, 1), TRUE);
        int i;
        MONO_ARCH_SAVE_REGS;
 
@@ -2539,174 +2535,6 @@ ves_icall_EnumBuilder_setup_enum_type (MonoReflectionType *enumtype,
        enumtype->type = t->type;
 }
 
-static MonoReflectionType*
-ves_icall_MonoGenericClass_GetParentType (MonoReflectionGenericClass *type)
-{
-       MonoDynamicGenericClass *gclass;
-       MonoReflectionType *parent = NULL, *res;
-       MonoDomain *domain;
-       MonoType *inflated;
-       MonoClass *klass;
-
-
-       MONO_ARCH_SAVE_REGS;
-
-       g_assert (type->type.type->data.generic_class->is_dynamic);
-       gclass = (MonoDynamicGenericClass *) type->type.type->data.generic_class;
-
-       domain = mono_object_domain (type);
-       klass = mono_class_from_mono_type (type->generic_type->type.type);
-
-       if (!klass->generic_class && !klass->generic_container)
-               return NULL;
-
-       parent = monotype_cast (type->generic_type->parent);
-
-       if (!parent || (parent->type->type != MONO_TYPE_GENERICINST))
-               return NULL;
-
-       inflated = mono_class_inflate_generic_type (
-               parent->type, mono_generic_class_get_context ((MonoGenericClass *) gclass));
-
-       res = mono_type_get_object (domain, inflated);
-       mono_metadata_free_type (inflated);
-       return res;
-}
-
-static MonoArray*
-ves_icall_MonoGenericClass_GetInterfaces (MonoReflectionGenericClass *type)
-{
-       static MonoClass *System_Reflection_MonoGenericClass;
-       MonoGenericClass *gclass;
-       MonoReflectionTypeBuilder *tb = NULL;
-       MonoClass *klass = NULL;
-       MonoDomain *domain;
-       MonoArray *res;
-       int icount, i;
-
-       MONO_ARCH_SAVE_REGS;
-
-       if (!System_Reflection_MonoGenericClass) {
-               System_Reflection_MonoGenericClass = mono_class_from_name (
-                       mono_defaults.corlib, "System.Reflection", "MonoGenericClass");
-               g_assert (System_Reflection_MonoGenericClass);
-       }
-
-       domain = mono_object_domain (type);
-
-       gclass = type->type.type->data.generic_class;
-       g_assert (gclass->is_dynamic);
-
-       tb = type->generic_type;
-       icount = tb->interfaces ? mono_array_length (tb->interfaces) : 0;
-
-       res = mono_array_new (domain, System_Reflection_MonoGenericClass, icount);
-
-       for (i = 0; i < icount; i++) {
-               MonoReflectionType *iface;
-               MonoType *it;
-
-               if (tb) {
-                       iface = mono_array_get (tb->interfaces, MonoReflectionType *, i);
-                       it = iface->type;
-               } else
-                       it = &klass->interfaces [i]->byval_arg;
-
-               it = mono_class_inflate_generic_type (it, mono_generic_class_get_context (gclass));
-
-               iface = mono_type_get_object (domain, it);
-               mono_array_setref (res, i, iface);
-               mono_metadata_free_type (it);
-       }
-
-       return res;
-}
-
-static MonoReflectionMethod*
-ves_icall_MonoGenericClass_GetCorrespondingInflatedMethod (MonoReflectionGenericClass *type, 
-                                                           MonoReflectionMethod* generic)
-{
-       MonoGenericClass *gclass;
-       MonoDynamicGenericClass *dgclass;
-       MonoDomain *domain;
-       int i;
-
-       MONO_ARCH_SAVE_REGS;
-
-       gclass = type->type.type->data.generic_class;
-       g_assert (gclass->is_dynamic);
-
-       dgclass = (MonoDynamicGenericClass *) gclass;
-
-       domain = mono_object_domain (type);
-
-       for (i = 0; i < dgclass->count_methods; i++)
-               if (generic->method->token == dgclass->methods [i]->token)
-                        return mono_method_get_object (domain, dgclass->methods [i], NULL);
-
-       return NULL;
-}
-
-static MonoReflectionMethod*
-ves_icall_MonoGenericClass_GetCorrespondingInflatedConstructor (MonoReflectionGenericClass *type, 
-                                                                MonoReflectionMethod* generic)
-{
-       MonoGenericClass *gclass;
-       MonoDynamicGenericClass *dgclass;
-       MonoDomain *domain;
-       int i;
-
-       MONO_ARCH_SAVE_REGS;
-
-       gclass = type->type.type->data.generic_class;
-       g_assert (gclass->is_dynamic);
-
-       dgclass = (MonoDynamicGenericClass *) gclass;
-
-       domain = mono_object_domain (type);
-
-       for (i = 0; i < dgclass->count_ctors; i++)
-               if (generic->method->token == dgclass->ctors [i]->token)
-                        return mono_method_get_object (domain, dgclass->ctors [i], NULL);
-
-       return NULL;
-}
-
-
-static MonoReflectionField*
-ves_icall_MonoGenericClass_GetCorrespondingInflatedField (MonoReflectionGenericClass *type, 
-                                                          MonoString* generic_name)
-{
-       MonoGenericClass *gclass;
-       MonoDynamicGenericClass *dgclass;
-       MonoDomain *domain;
-        MonoClass *refclass;
-       char *utf8_name = mono_string_to_utf8 (generic_name);
-       int i;
-
-       MONO_ARCH_SAVE_REGS;
-
-       gclass = type->type.type->data.generic_class;
-       g_assert (gclass->is_dynamic);
-
-       dgclass = (MonoDynamicGenericClass *) gclass;
-
-       refclass = mono_class_from_mono_type (type->type.type);
-
-       domain = mono_object_domain (type);
-
-       for (i = 0; i < dgclass->count_fields; i++)
-               if (strcmp (utf8_name, mono_field_get_name (&dgclass->fields [i])) == 0) {
-                       g_free (utf8_name);
-                        return mono_field_get_object (domain, refclass, &dgclass->fields [i]);
-               }
-       
-       g_free (utf8_name);
-
-       return NULL;
-}
-
-
 static MonoReflectionMethod*
 ves_icall_MonoType_GetCorrespondingInflatedMethod (MonoReflectionType *type, 
                                                    MonoReflectionMethod* generic)
@@ -2731,177 +2559,7 @@ ves_icall_MonoType_GetCorrespondingInflatedMethod (MonoReflectionType *type,
         return NULL;
 }
 
-static MonoArray*
-ves_icall_MonoGenericClass_GetMethods (MonoReflectionGenericClass *type,
-                                      MonoReflectionType *reflected_type)
-{
-       MonoGenericClass *gclass;
-       MonoDynamicGenericClass *dgclass;
-       MonoDomain *domain;
-       MonoClass *refclass;
-       MonoArray *res;
-       int i;
-
-       MONO_ARCH_SAVE_REGS;
-
-       gclass = type->type.type->data.generic_class;
-       g_assert (gclass->is_dynamic);
-       dgclass = (MonoDynamicGenericClass *) gclass;
-
-       refclass = mono_class_from_mono_type (reflected_type->type);
-
-       domain = mono_object_domain (type);
-       res = mono_array_new (domain, mono_defaults.method_info_class, dgclass->count_methods);
-
-       for (i = 0; i < dgclass->count_methods; i++)
-               mono_array_setref (res, i, mono_method_get_object (domain, dgclass->methods [i], refclass));
-
-       return res;
-}
-
-static MonoArray*
-ves_icall_MonoGenericClass_GetConstructors (MonoReflectionGenericClass *type,
-                                           MonoReflectionType *reflected_type)
-{
-       static MonoClass *System_Reflection_ConstructorInfo;
-       MonoGenericClass *gclass;
-       MonoDynamicGenericClass *dgclass;
-       MonoDomain *domain;
-       MonoClass *refclass;
-       MonoArray *res;
-       int i;
-
-       MONO_ARCH_SAVE_REGS;
-
-       if (!System_Reflection_ConstructorInfo)
-               System_Reflection_ConstructorInfo = mono_class_from_name (
-                       mono_defaults.corlib, "System.Reflection", "ConstructorInfo");
-
-       gclass = type->type.type->data.generic_class;
-       g_assert (gclass->is_dynamic);
-       dgclass = (MonoDynamicGenericClass *) gclass;
-
-       refclass = mono_class_from_mono_type (reflected_type->type);
-
-       domain = mono_object_domain (type);
-       res = mono_array_new_cached (domain, System_Reflection_ConstructorInfo, dgclass->count_ctors);
-
-       for (i = 0; i < dgclass->count_ctors; i++)
-               mono_array_setref (res, i, mono_method_get_object (domain, dgclass->ctors [i], refclass));
-
-       return res;
-}
-
-static MonoArray*
-ves_icall_MonoGenericClass_GetFields (MonoReflectionGenericClass *type,
-                                     MonoReflectionType *reflected_type)
-{
-       MonoGenericClass *gclass;
-       MonoDynamicGenericClass *dgclass;
-       MonoDomain *domain;
-       MonoClass *refclass;
-       MonoArray *res;
-       int i;
-
-       MONO_ARCH_SAVE_REGS;
-
-       gclass = type->type.type->data.generic_class;
-       g_assert (gclass->is_dynamic);
-       dgclass = (MonoDynamicGenericClass *) gclass;
 
-       refclass = mono_class_from_mono_type (reflected_type->type);
-
-       domain = mono_object_domain (type);
-       res = mono_array_new (domain, mono_defaults.field_info_class, dgclass->count_fields);
-
-       for (i = 0; i < dgclass->count_fields; i++)
-               mono_array_setref (res, i, mono_field_get_object (domain, refclass, &dgclass->fields [i]));
-
-       return res;
-}
-
-static MonoArray*
-ves_icall_MonoGenericClass_GetProperties (MonoReflectionGenericClass *type,
-                                         MonoReflectionType *reflected_type)
-{
-       static MonoClass *System_Reflection_PropertyInfo;
-       MonoGenericClass *gclass;
-       MonoDynamicGenericClass *dgclass;
-       MonoDomain *domain;
-       MonoClass *refclass;
-       MonoArray *res;
-       int i;
-
-       MONO_ARCH_SAVE_REGS;
-
-       if (!System_Reflection_PropertyInfo)
-               System_Reflection_PropertyInfo = mono_class_from_name (
-                       mono_defaults.corlib, "System.Reflection", "PropertyInfo");
-
-       gclass = type->type.type->data.generic_class;
-       g_assert (gclass->is_dynamic);
-       dgclass = (MonoDynamicGenericClass *) gclass;
-
-       refclass = mono_class_from_mono_type (reflected_type->type);
-
-       domain = mono_object_domain (type);
-       res = mono_array_new (domain, System_Reflection_PropertyInfo, dgclass->count_properties);
-
-       for (i = 0; i < dgclass->count_properties; i++)
-               mono_array_setref (res, i, mono_property_get_object (domain, refclass, &dgclass->properties [i]));
-
-       return res;
-}
-
-static MonoArray*
-ves_icall_MonoGenericClass_GetEvents (MonoReflectionGenericClass *type,
-                                     MonoReflectionType *reflected_type)
-{
-       static MonoClass *System_Reflection_EventInfo;
-       MonoGenericClass *gclass;
-       MonoDynamicGenericClass *dgclass;
-       MonoDomain *domain;
-       MonoClass *refclass;
-       MonoArray *res;
-       int i;
-
-       MONO_ARCH_SAVE_REGS;
-
-       if (!System_Reflection_EventInfo)
-               System_Reflection_EventInfo = mono_class_from_name (
-                       mono_defaults.corlib, "System.Reflection", "EventInfo");
-
-       gclass = type->type.type->data.generic_class;
-       g_assert (gclass->is_dynamic);
-       dgclass = (MonoDynamicGenericClass *) gclass;
-
-       refclass = mono_class_from_mono_type (reflected_type->type);
-
-       domain = mono_object_domain (type);
-       res = mono_array_new (domain, System_Reflection_EventInfo, dgclass->count_events);
-
-       for (i = 0; i < dgclass->count_events; i++)
-               mono_array_setref (res, i, mono_event_get_object (domain, refclass, &dgclass->events [i]));
-
-       return res;
-}
-
-static MonoReflectionType*
-ves_icall_MonoGenericClass_InflateType (MonoReflectionGenericClass *type,
-                                     MonoReflectionType *target)
-{
-       MonoType *res_type;
-       MonoClass *gklass;
-       MonoReflectionType *res;
-
-       MONO_ARCH_SAVE_REGS;
-
-       gklass = mono_class_from_mono_type (type->type.type);
-       res_type = mono_class_inflate_generic_type (mono_reflection_type_get_handle (target), mono_class_get_context (gklass));
-       res = mono_type_get_object (mono_object_domain (type), res_type);
-       mono_metadata_free_type (res_type);
-       return res;
-}
 
 static MonoReflectionMethod *
 ves_icall_MonoType_get_DeclaringMethod (MonoReflectionType *ref_type)
@@ -2938,7 +2596,7 @@ ves_icall_MonoMethod_GetDllImportAttribute (MonoMethod *method)
        const char *scope = NULL;
        guint32 flags;
 
-       if (!method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL)
+       if (!(method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL))
                return NULL;
 
        if (!DllImportAttributeClass) {
@@ -2956,6 +2614,11 @@ ves_icall_MonoMethod_GetDllImportAttribute (MonoMethod *method)
                        import = method_aux->dllentry;
                        scope = method_aux->dll;
                }
+
+               if (!import || !scope) {
+                       mono_raise_exception (mono_get_exception_argument ("method", "System.Reflection.Emit method with invalid pinvoke information"));
+                       return NULL;
+               }
        }
        else {
                if (piinfo->implmap_idx) {
@@ -3238,11 +2901,8 @@ ves_icall_InternalExecute (MonoReflectionMethod *method, MonoObject *this, MonoA
 
                                        if (field_klass->valuetype) {
                                                size = mono_type_size (field->type, &align);
-#ifdef HAVE_SGEN_GC
+                                               g_assert (size == mono_class_value_size (field_klass, NULL));
                                                mono_gc_wbarrier_value_copy ((char *)this + field->offset, (char*)val + sizeof (MonoObject), 1, field_klass);
-#endif
-                                               memcpy ((char *)this + field->offset, 
-                                                       ((char *)val) + sizeof (MonoObject), size);
                                        } else {
                                                mono_gc_wbarrier_set_field (this, (char*)this + field->offset, val);
                                        }
@@ -3594,7 +3254,7 @@ ves_icall_Type_GetField (MonoReflectionType *type, MonoString *name, guint32 bfl
        if (type->type->byref)
                return NULL;
 
-       compare_func = (bflags & BFLAGS_IgnoreCase) ? g_strcasecmp : strcmp;
+       compare_func = (bflags & BFLAGS_IgnoreCase) ? mono_utf8_strcasecmp : strcmp;
 
 handle_parent:
        if (klass->exception_type != MONO_EXCEPTION_NONE)
@@ -3744,12 +3404,13 @@ ves_icall_Type_GetMethodsByName (MonoReflectionType *type, MonoString *name, gui
        int i, len, match, nslots;
        /*FIXME, use MonoBitSet*/
        guint32 method_slots_default [8];
-       guint32 *method_slots;
+       guint32 *method_slots = NULL;
        gchar *mname = NULL;
        int (*compare_func) (const char *s1, const char *s2) = NULL;
        MonoVTable *array_vtable;
+       MonoException *ex;
        MonoPtrArray tmp_array;
-               
+
        MONO_ARCH_SAVE_REGS;
 
        mono_ptr_array_init (tmp_array, 4);
@@ -3761,7 +3422,7 @@ ves_icall_Type_GetMethodsByName (MonoReflectionType *type, MonoString *name, gui
        }
 
        domain = ((MonoObject *)type)->vtable->domain;
-       array_vtable = mono_class_vtable (domain, MethodInfo_array);
+       array_vtable = mono_class_vtable_full (domain, MethodInfo_array, TRUE);
        if (type->type->byref)
                return mono_array_new_specific (array_vtable, 0);
        klass = startklass = mono_class_from_mono_type (type->type);
@@ -3769,15 +3430,17 @@ ves_icall_Type_GetMethodsByName (MonoReflectionType *type, MonoString *name, gui
        len = 0;
        if (name != NULL) {
                mname = mono_string_to_utf8 (name);
-               compare_func = (ignore_case) ? g_strcasecmp : strcmp;
+               compare_func = (ignore_case) ? mono_utf8_strcasecmp : strcmp;
        }
 
        /* An optimization for calls made from Delegate:CreateDelegate () */
        if (klass->delegate && mname && !strcmp (mname, "Invoke") && (bflags == (BFLAGS_Public | BFLAGS_Static | BFLAGS_Instance))) {
                method = mono_get_delegate_invoke (klass);
+               if (mono_loader_get_last_error ())
+                       goto loader_error;
 
                member = (MonoObject*)mono_method_get_object (domain, method, refklass);
-               
+
                res = mono_array_new_specific (array_vtable, 1);
                mono_array_setref (res, 0, member);
                g_free (mname);
@@ -3785,6 +3448,8 @@ ves_icall_Type_GetMethodsByName (MonoReflectionType *type, MonoString *name, gui
        }
 
        mono_class_setup_vtable (klass);
+       if (klass->exception_type != MONO_EXCEPTION_NONE || mono_loader_get_last_error ())
+               goto loader_error;
 
        if (is_generic_parameter (type->type))
                nslots = mono_class_get_vtable_size (klass->parent);
@@ -3798,8 +3463,8 @@ ves_icall_Type_GetMethodsByName (MonoReflectionType *type, MonoString *name, gui
        }
 handle_parent:
        mono_class_setup_vtable (klass);
-       if (klass->exception_type != MONO_EXCEPTION_NONE)
-               mono_raise_exception (mono_class_get_exception_for_failure (klass));
+       if (klass->exception_type != MONO_EXCEPTION_NONE || mono_loader_get_last_error ())
+               goto loader_error;              
 
        iter = NULL;
        while ((method = mono_class_get_methods (klass, &iter))) {
@@ -3859,6 +3524,20 @@ handle_parent:
 
        mono_ptr_array_destroy (tmp_array);
        return res;
+
+loader_error:
+       g_free (mname);
+       if (method_slots != method_slots_default)
+               g_free (method_slots);
+       mono_ptr_array_destroy (tmp_array);
+       if (klass->exception_type != MONO_EXCEPTION_NONE) {
+               ex = mono_class_get_exception_for_failure (klass);
+       } else {
+               ex = mono_loader_error_prepare_exception (mono_loader_get_last_error ());
+               mono_loader_clear_error ();
+       }
+       mono_raise_exception (ex);
+       return NULL;
 }
 
 static MonoArray*
@@ -3994,7 +3673,7 @@ ves_icall_Type_GetPropertiesByName (MonoReflectionType *type, MonoString *name,
        klass = startklass = mono_class_from_mono_type (type->type);
        if (name != NULL) {
                propname = mono_string_to_utf8 (name);
-               compare_func = (ignore_case) ? g_strcasecmp : strcmp;
+               compare_func = (ignore_case) ? mono_utf8_strcasecmp : strcmp;
        }
 
        mono_class_setup_vtable (klass);
@@ -4502,7 +4181,7 @@ ves_icall_System_Reflection_Assembly_get_code_base (MonoReflectionAssembly *asse
 
        replace_shadow_path (domain, dirname, &absolute);
        g_free (dirname);
-#if PLATFORM_WIN32
+#if HOST_WIN32
        {
                gint i;
                for (i = strlen (absolute) - 1; i >= 0; i--)
@@ -4514,7 +4193,7 @@ ves_icall_System_Reflection_Assembly_get_code_base (MonoReflectionAssembly *asse
                uri = g_filename_to_uri (absolute, NULL, NULL);
        } else {
                const char *prepend = "file://";
-#if PLATFORM_WIN32
+#if HOST_WIN32
                if (*absolute == '/' && *(absolute + 1) == '/') {
                        prepend = "file:";
                } else {
@@ -5023,7 +4702,8 @@ ves_icall_GetCurrentMethod (void)
 {
        MonoMethod *m = mono_method_get_last_managed ();
 
-       MONO_ARCH_SAVE_REGS;
+       while (m->is_inflated)
+               m = ((MonoMethodInflated*)m)->declaring;
 
        return mono_method_get_object (mono_domain_get (), m, NULL);
 }
@@ -5190,7 +4870,7 @@ fill_reflection_assembly_name (MonoDomain *domain, MonoReflectionAssemblyName *a
 
                codebase = g_strdup (absolute);
 
-#if PLATFORM_WIN32
+#if HOST_WIN32
                {
                        gint i;
                        for (i = strlen (codebase) - 1; i >= 0; i--)
@@ -5601,7 +5281,7 @@ ves_icall_System_Reflection_Module_GetGuidInternal (MonoReflectionModule *module
 static gpointer
 ves_icall_System_Reflection_Module_GetHINSTANCE (MonoReflectionModule *module)
 {
-#ifdef PLATFORM_WIN32
+#ifdef HOST_WIN32
        if (module->image && module->image->is_module_handle)
                return module->image->raw_data;
 #endif
@@ -6083,7 +5763,7 @@ ves_icall_System_Delegate_SetMulticastInvoke (MonoDelegate *this)
  */
 #define FILETIME_ADJUST ((guint64)504911232000000000LL)
 
-#ifdef PLATFORM_WIN32
+#ifdef HOST_WIN32
 /* convert a SYSTEMTIME which is of the form "last thursday in october" to a real date */
 static void
 convert_to_absolute_date(SYSTEMTIME *date)
@@ -6113,7 +5793,7 @@ convert_to_absolute_date(SYSTEMTIME *date)
 }
 #endif
 
-#ifndef PLATFORM_WIN32
+#ifndef HOST_WIN32
 /*
  * Return's the offset from GMT of a local time.
  * 
@@ -6153,7 +5833,7 @@ gmt_offset(struct tm *tm, time_t t)
 static guint32
 ves_icall_System_CurrentSystemTimeZone_GetTimeZoneData (guint32 year, MonoArray **data, MonoArray **names)
 {
-#ifndef PLATFORM_WIN32
+#ifndef HOST_WIN32
        MonoDomain *domain = mono_domain_get ();
        struct tm start, tt;
        time_t t;
@@ -6457,7 +6137,7 @@ ves_icall_System_Environment_get_UserName (void)
 static MonoString *
 ves_icall_System_Environment_get_MachineName (void)
 {
-#if defined (PLATFORM_WIN32)
+#if defined (HOST_WIN32)
        gunichar2 *buf;
        guint32 len;
        MonoString *result;
@@ -6489,7 +6169,7 @@ ves_icall_System_Environment_get_MachineName (void)
 static int
 ves_icall_System_Environment_get_Platform (void)
 {
-#if defined (PLATFORM_WIN32)
+#if defined (TARGET_WIN32)
        /* Win32NT */
        return 2;
 #elif defined(__MACH__)
@@ -6517,7 +6197,7 @@ ves_icall_System_Environment_get_NewLine (void)
 {
        MONO_ARCH_SAVE_REGS;
 
-#if defined (PLATFORM_WIN32)
+#if defined (HOST_WIN32)
        return mono_string_new (mono_domain_get (), "\r\n");
 #else
        return mono_string_new (mono_domain_get (), "\n");
@@ -6556,7 +6236,7 @@ ves_icall_System_Environment_GetEnvironmentVariable (MonoString *name)
  * arm-apple-darwin9.  We'll manually define the symbol on Apple as it does
  * in fact exist on all implementations (so far) 
  */
-gchar ***_NSGetEnviron();
+gchar ***_NSGetEnviron(void);
 #define environ (*_NSGetEnviron())
 #else
 extern
@@ -6568,7 +6248,7 @@ char **environ;
 static MonoArray *
 ves_icall_System_Environment_GetEnvironmentVariableNames (void)
 {
-#ifdef PLATFORM_WIN32
+#ifdef HOST_WIN32
        MonoArray *names;
        MonoDomain *domain;
        MonoString *str;
@@ -6660,7 +6340,9 @@ ves_icall_System_Environment_GetEnvironmentVariableNames (void)
 static void
 ves_icall_System_Environment_InternalSetEnvironmentVariable (MonoString *name, MonoString *value)
 {
-#ifdef PLATFORM_WIN32
+       MonoError error;
+#ifdef HOST_WIN32
+
        gunichar2 *utf16_name, *utf16_value;
 #else
        gchar *utf8_name, *utf8_value;
@@ -6668,7 +6350,7 @@ ves_icall_System_Environment_InternalSetEnvironmentVariable (MonoString *name, M
 
        MONO_ARCH_SAVE_REGS;
        
-#ifdef PLATFORM_WIN32
+#ifdef HOST_WIN32
        utf16_name = mono_string_to_utf16 (name);
        if ((value == NULL) || (mono_string_length (value) == 0) || (mono_string_chars (value)[0] == 0)) {
                SetEnvironmentVariable (utf16_name, NULL);
@@ -6691,7 +6373,11 @@ ves_icall_System_Environment_InternalSetEnvironmentVariable (MonoString *name, M
                return;
        }
 
-       utf8_value = mono_string_to_utf8 (value);
+       utf8_value = mono_string_to_utf8_checked (value, &error);
+       if (!mono_error_ok (&error)) {
+               g_free (utf8_name);
+               mono_error_raise_exception (&error);
+       }
        g_setenv (utf8_name, utf8_value, TRUE);
 
        g_free (utf8_name);
@@ -6726,7 +6412,7 @@ ves_icall_System_Environment_GetGacPath (void)
 static MonoString*
 ves_icall_System_Environment_GetWindowsFolderPath (int folder)
 {
-#if defined (PLATFORM_WIN32)
+#if defined (HOST_WIN32)
        #ifndef CSIDL_FLAG_CREATE
                #define CSIDL_FLAG_CREATE       0x8000
        #endif
@@ -6899,7 +6585,7 @@ ves_icall_System_Environment_get_HasShutdownStarted (void)
 static void
 ves_icall_System_Environment_BroadcastSettingChange (void)
 {
-#ifdef PLATFORM_WIN32
+#ifdef HOST_WIN32
        SendMessageTimeout (HWND_BROADCAST, WM_SETTINGCHANGE, NULL, L"Environment", SMTO_ABORTIFHUNG, 2000, 0);
 #endif
 }
@@ -6986,7 +6672,7 @@ ves_icall_System_Runtime_Activation_ActivationServices_EnableProxyActivation (Mo
        MONO_ARCH_SAVE_REGS;
 
        klass = mono_class_from_mono_type (type->type);
-       vtable = mono_class_vtable (mono_domain_get (), klass);
+       vtable = mono_class_vtable_full (mono_domain_get (), klass, TRUE);
 
        if (enable) vtable->remote = 1;
        else vtable->remote = 0;
@@ -7008,7 +6694,7 @@ ves_icall_System_Runtime_Activation_ActivationServices_AllocateUninitializedClas
                return (MonoObject *) mono_array_new (domain, klass->element_class, 0);
        } else {
                /* Bypass remoting object creation check */
-               return mono_object_new_alloc_specific (mono_class_vtable (domain, klass));
+               return mono_object_new_alloc_specific (mono_class_vtable_full (domain, klass, TRUE));
        }
 }
 
@@ -7078,7 +6764,7 @@ ves_icall_System_Configuration_DefaultConfig_get_machine_config_path (void)
 
        path = g_build_path (G_DIR_SEPARATOR_S, mono_get_config_dir (), "mono", mono_get_runtime_info ()->framework_version, "machine.config", NULL);
 
-#if defined (PLATFORM_WIN32)
+#if defined (HOST_WIN32)
        /* Avoid mixing '/' and '\\' */
        {
                gint i;
@@ -7118,7 +6804,7 @@ ves_icall_System_Web_Util_ICalls_get_machine_install_dir (void)
 
        path = g_path_get_dirname (mono_get_config_dir ());
 
-#if defined (PLATFORM_WIN32)
+#if defined (HOST_WIN32)
        /* Avoid mixing '/' and '\\' */
        {
                gint i;
@@ -7164,16 +6850,16 @@ ves_icall_get_resources_ptr (MonoReflectionAssembly *assembly, gpointer *result,
 static MonoBoolean
 ves_icall_System_Diagnostics_Debugger_IsAttached_internal (void)
 {
-       return mono_debug_using_mono_debugger ();
+       return mono_debug_using_mono_debugger () || mono_is_debugger_attached ();
 }
 
 static void
 ves_icall_System_Diagnostics_DefaultTraceListener_WriteWindowsDebugString (MonoString *message)
 {
-#if defined (PLATFORM_WIN32)
+#if defined (HOST_WIN32)
        OutputDebugString (mono_string_chars (message));
 #else
-       g_warning ("WriteWindowsDebugString called and PLATFORM_WIN32 not defined!\n");
+       g_warning ("WriteWindowsDebugString called and HOST_WIN32 not defined!\n");
 #endif
 }
 
@@ -7197,7 +6883,7 @@ ves_icall_System_Activator_CreateInstanceInternal (MonoReflectionType *type)
 }
 
 static MonoReflectionMethod *
-ves_icall_MonoMethod_get_base_definition (MonoReflectionMethod *m)
+ves_icall_MonoMethod_get_base_method (MonoReflectionMethod *m, gboolean definition)
 {
        MonoClass *klass, *parent;
        MonoMethod *method = m->method;
@@ -7217,13 +6903,19 @@ ves_icall_MonoMethod_get_base_definition (MonoReflectionMethod *m)
        if (klass->generic_class)
                klass = klass->generic_class->container_class;
 
-       /* At the end of the loop, klass points to the eldest class that has this virtual function slot. */
-       for (parent = klass->parent; parent != NULL; parent = parent->parent) {
-               mono_class_setup_vtable (parent);
-               if (parent->vtable_size <= method->slot)
-                       break;
-               klass = parent;
-       }               
+       if (definition) {
+               /* At the end of the loop, klass points to the eldest class that has this virtual function slot. */
+               for (parent = klass->parent; parent != NULL; parent = parent->parent) {
+                       mono_class_setup_vtable (parent);
+                       if (parent->vtable_size <= method->slot)
+                               break;
+                       klass = parent;
+               }
+       } else {
+               klass = klass->parent;
+               if (!klass)
+                       return m;
+       }
 
        if (klass == method->klass)
                return m;
@@ -7268,16 +6960,6 @@ mono_ArgIterator_Setup (MonoArgIterator *iter, char* argsp, char* start)
                iter->args = start;
        } else {
                iter->args = argsp + sizeof (gpointer);
-#ifndef MONO_ARCH_REGPARMS
-               {
-               guint32 i, arg_size;
-               gint32 align;
-               for (i = 0; i < iter->sig->sentinelpos; ++i) {
-                       arg_size = mono_type_stack_size (iter->sig->params [i], &align);
-                       iter->args = (char*)iter->args + arg_size;
-               }
-               }
-#endif
        }
        iter->num_args = iter->sig->param_count - iter->sig->sentinelpos;
 
@@ -7560,17 +7242,15 @@ custom_attrs_get_by_type (MonoObject *obj, MonoReflectionType *attr_type)
        }
 }
 
-static MonoBoolean
-GCHandle_CheckCurrentDomain (guint32 gchandle)
-{
-       return mono_gchandle_is_in_domain (gchandle, mono_domain_get ());
-}
-
 static MonoString*
 ves_icall_Mono_Runtime_GetDisplayName (void)
 {
-       static const char display_name_str [] = "Mono " VERSION;
-       MonoString *display_name = mono_string_new (mono_domain_get (), display_name_str);
+       char *info;
+       MonoString *display_name;
+
+       info = mono_get_runtime_callbacks ()->get_runtime_build_info ();
+       display_name = mono_string_new (mono_domain_get (), info);
+       g_free (info);
        return display_name;
 }
 
@@ -8144,7 +7824,7 @@ mono_create_icall_signature (const char *sigstr)
        res = mono_metadata_signature_alloc (mono_defaults.corlib, len - 1);
        res->pinvoke = 1;
 
-#ifdef PLATFORM_WIN32
+#ifdef HOST_WIN32
        /* 
         * Under windows, the default pinvoke calling convention is STDCALL but
         * we need CDECL.