Merge pull request #1909 from esdrubal/reflection
[mono.git] / mono / metadata / icall.c
index fead58e0269a3dddd302f5aa03137477c4185cf1..6ab999ba126cb69b9da05f76c2ad1ba78591dc3a 100644 (file)
@@ -37,7 +37,8 @@
 #include <mono/metadata/object.h>
 #include <mono/metadata/threads.h>
 #include <mono/metadata/threads-types.h>
-#include <mono/metadata/threadpool.h>
+#include <mono/metadata/threadpool-ms.h>
+#include <mono/metadata/threadpool-ms-io.h>
 #include <mono/metadata/monitor.h>
 #include <mono/metadata/reflection.h>
 #include <mono/metadata/assembly.h>
@@ -64,7 +65,6 @@
 #include <mono/metadata/profiler-private.h>
 #include <mono/metadata/locales.h>
 #include <mono/metadata/filewatcher.h>
-#include <mono/metadata/char-conversions.h>
 #include <mono/metadata/security.h>
 #include <mono/metadata/mono-config.h>
 #include <mono/metadata/cil-coff.h>
@@ -79,7 +79,6 @@
 #include <mono/metadata/file-mmap.h>
 #include <mono/metadata/seq-points-data.h>
 #include <mono/io-layer/io-layer.h>
-#include <mono/utils/strtod.h>
 #include <mono/utils/monobitset.h>
 #include <mono/utils/mono-time.h>
 #include <mono/utils/mono-proclib.h>
@@ -97,6 +96,7 @@
 #include <shlobj.h>
 #endif
 #include "decimal-ms.h"
+#include "number-ms.h"
 
 extern MonoString* ves_icall_System_Environment_GetOSVersionString (void);
 
@@ -118,28 +118,6 @@ mono_class_init_or_throw (MonoClass *klass)
                mono_raise_exception (mono_class_get_exception_for_failure (klass));
 }
 
-/*
- * We expect a pointer to a char, not a string
- */
-ICALL_EXPORT gboolean
-mono_double_ParseImpl (char *ptr, double *result)
-{
-       gchar *endptr = NULL;
-       *result = 0.0;
-
-       if (*ptr){
-               /* mono_strtod () is not thread-safe */
-               mono_mutex_lock (&mono_strtod_mutex);
-               *result = mono_strtod (ptr, &endptr);
-               mono_mutex_unlock (&mono_strtod_mutex);
-       }
-
-       if (!*ptr || (endptr && *endptr))
-               return FALSE;
-       
-       return TRUE;
-}
-
 ICALL_EXPORT MonoObject *
 ves_icall_System_Array_GetValueImpl (MonoObject *this, guint32 pos)
 {
@@ -292,6 +270,8 @@ ves_icall_System_Array_SetValueImpl (MonoArray *this, MonoObject *value, guint32
                        INVALID_CAST;
                }
                break;
+       default:
+               break;
        }
 
        if (!ec->valuetype) {
@@ -1181,6 +1161,18 @@ ves_icall_ModuleBuilder_RegisterToken (MonoReflectionModuleBuilder *mb, MonoObje
        mono_image_register_token (mb->dynamic_image, token, obj);
 }
 
+ICALL_EXPORT MonoObject*
+ves_icall_ModuleBuilder_GetRegisteredToken (MonoReflectionModuleBuilder *mb, guint32 token)
+{
+       gpointer obj;
+
+       mono_loader_lock ();
+       obj = mono_g_hash_table_lookup (mb->dynamic_image->tokens, GUINT_TO_POINTER (token));
+       mono_loader_unlock ();
+
+       return obj;
+}
+
 static gboolean
 get_caller (MonoMethod *m, gint32 no, gint32 ilo, gboolean managed, gpointer data)
 {
@@ -1364,15 +1356,6 @@ ves_icall_type_from_handle (MonoType *handle)
        return mono_type_get_object (domain, handle);
 }
 
-ICALL_EXPORT MonoBoolean
-ves_icall_System_Type_EqualsInternal (MonoReflectionType *type, MonoReflectionType *c)
-{
-       if (c && type->type && c->type)
-               return mono_metadata_type_equal (type->type, c->type);
-       else
-               return (type == c) ? TRUE : FALSE;
-}
-
 /* System.TypeCode */
 typedef enum {
        TYPECODE_EMPTY,
@@ -1477,40 +1460,6 @@ handle_enum:
        return 0;
 }
 
-ICALL_EXPORT guint32
-ves_icall_type_is_subtype_of (MonoReflectionType *type, MonoReflectionType *c, MonoBoolean check_interfaces)
-{
-       MonoDomain *domain; 
-       MonoClass *klass;
-       MonoClass *klassc;
-
-       g_assert (type != NULL);
-       
-       domain = ((MonoObject *)type)->vtable->domain;
-
-       if (!c) /* FIXME: dont know what do do here */
-               return 0;
-
-       klass = mono_class_from_mono_type (type->type);
-       klassc = mono_class_from_mono_type (c->type);
-
-       /* Interface check requires a more complex setup so we
-        * only do for them. Otherwise we simply avoid mono_class_init.
-        */
-       if (check_interfaces) {
-               mono_class_init_or_throw (klass);
-               mono_class_init_or_throw (klassc);
-       } else if (!klass->supertypes || !klassc->supertypes) {
-               mono_class_setup_supertypes (klass);
-               mono_class_setup_supertypes (klassc);
-       }
-
-       if (type->type->byref)
-               return klassc == mono_defaults.object_class;
-
-       return mono_class_is_subclass_of (klass, klassc, check_interfaces);
-}
-
 static gboolean
 mono_type_is_primitive (MonoType *type)
 {
@@ -1531,14 +1480,11 @@ mono_type_get_underlying_type_ignore_byref (MonoType *type)
 ICALL_EXPORT guint32
 ves_icall_type_is_assignable_from (MonoReflectionType *type, MonoReflectionType *c)
 {
-       MonoDomain *domain; 
        MonoClass *klass;
        MonoClass *klassc;
 
        g_assert (type != NULL);
        
-       domain = ((MonoObject *)type)->vtable->domain;
-
        klass = mono_class_from_mono_type (type->type);
        klassc = mono_class_from_mono_type (c->type);
 
@@ -1849,6 +1795,27 @@ ves_icall_MonoField_SetValueInternal (MonoReflectionField *field, MonoObject *ob
        }
 }
 
+ICALL_EXPORT void
+ves_icall_System_RuntimeFieldHandle_SetValueDirect (MonoReflectionField *field, MonoReflectionType *field_type, MonoTypedRef *obj, MonoObject *value, MonoReflectionType *context_type)
+{
+       MonoClassField *f;
+
+       g_assert (field);
+       g_assert (obj);
+       g_assert (value);
+
+       f = field->field;
+       if (!MONO_TYPE_ISSTRUCT (&f->parent->byval_arg)) {
+               mono_set_pending_exception (mono_get_exception_not_implemented (NULL));
+               return;
+       }
+
+       if (MONO_TYPE_IS_REFERENCE (f->type))
+               mono_copy_value (f->type, (guint8*)obj->value + f->offset - sizeof (MonoObject), value, FALSE);
+       else
+               mono_copy_value (f->type, (guint8*)obj->value + f->offset - sizeof (MonoObject), mono_object_unbox (value), FALSE);
+}
+
 ICALL_EXPORT MonoObject *
 ves_icall_MonoField_GetRawConstantValue (MonoReflectionField *this)
 {      
@@ -2069,6 +2036,14 @@ fill_iface_array (gpointer key, gpointer value, gpointer user_data)
                mono_metadata_free_type (inflated);
 }
 
+static guint
+get_interfaces_hash (gconstpointer v1)
+{
+       MonoClass *k = (MonoClass*)v1;
+
+       return k->type_token;
+}
+
 ICALL_EXPORT MonoArray*
 ves_icall_Type_GetInterfaces (MonoReflectionType* type)
 {
@@ -2078,7 +2053,7 @@ ves_icall_Type_GetInterfaces (MonoReflectionType* type)
        FillIfaceArrayData data = { 0 };
        int len;
 
-       GHashTable *iface_hash = g_hash_table_new (NULL, NULL);
+       GHashTable *iface_hash = g_hash_table_new (get_interfaces_hash, NULL);
 
        if (class->generic_class && class->generic_class->context.class_inst->is_open) {
                data.context = mono_class_get_context (class);
@@ -2314,31 +2289,38 @@ ves_icall_MonoType_GetArrayRank (MonoReflectionType *type)
        return class->rank;
 }
 
+static MonoArray*
+create_type_array (MonoDomain *domain, MonoBoolean runtimeTypeArray, int count)
+{
+       MonoArray *res;
+       res = mono_array_new (domain, runtimeTypeArray ? mono_defaults.runtimetype_class : mono_defaults.systemtype_class, count);
+       return res;
+}
+
 ICALL_EXPORT MonoArray*
-ves_icall_MonoType_GetGenericArguments (MonoReflectionType *type)
+ves_icall_MonoType_GetGenericArguments (MonoReflectionType *type, MonoBoolean runtimeTypeArray)
 {
        MonoArray *res;
        MonoClass *klass, *pklass;
        MonoDomain *domain = mono_object_domain (type);
-       MonoVTable *array_vtable = mono_class_vtable_full (domain, mono_array_class_get_cached (mono_defaults.systemtype_class, 1), TRUE);
        int i;
 
        klass = mono_class_from_mono_type (type->type);
 
        if (klass->generic_container) {
                MonoGenericContainer *container = klass->generic_container;
-               res = mono_array_new_specific (array_vtable, container->type_argc);
+               res = create_type_array (domain, runtimeTypeArray, container->type_argc);
                for (i = 0; i < container->type_argc; ++i) {
                        pklass = mono_class_from_generic_parameter (mono_generic_container_get_param (container, i), klass->image, FALSE);
                        mono_array_setref (res, i, mono_type_get_object (domain, &pklass->byval_arg));
                }
        } else if (klass->generic_class) {
                MonoGenericInst *inst = klass->generic_class->context.class_inst;
-               res = mono_array_new_specific (array_vtable, inst->type_argc);
+               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]));
        } else {
-               res = mono_array_new_specific (array_vtable, 0);
+               res = NULL;
        }
        return res;
 }
@@ -2419,19 +2401,6 @@ ves_icall_Type_MakeGenericType (MonoReflectionType *type, MonoArray *type_array)
        return mono_type_get_object (mono_object_domain (type), geninst);
 }
 
-ICALL_EXPORT gboolean
-ves_icall_Type_get_IsGenericInstance (MonoReflectionType *type)
-{
-       MonoClass *klass;
-
-       if (type->type->byref)
-               return FALSE;
-
-       klass = mono_class_from_mono_type (type->type);
-
-       return klass->generic_class != NULL;
-}
-
 ICALL_EXPORT gboolean
 ves_icall_Type_get_IsGenericType (MonoReflectionType *type)
 {
@@ -2532,8 +2501,6 @@ ves_icall_MonoType_GetCorrespondingInflatedMethod (MonoReflectionType *type,
         return NULL;
 }
 
-
-
 ICALL_EXPORT MonoReflectionMethod *
 ves_icall_MonoType_get_DeclaringMethod (MonoReflectionType *ref_type)
 {
@@ -2552,14 +2519,26 @@ ves_icall_MonoType_get_DeclaringMethod (MonoReflectionType *ref_type)
        return mono_method_get_object (mono_object_domain (ref_type), method, method->klass);
 }
 
-ICALL_EXPORT MonoReflectionDllImportAttribute*
-ves_icall_MonoMethod_GetDllImportAttribute (MonoMethod *method)
+ICALL_EXPORT MonoBoolean
+ves_icall_System_RuntimeType_IsTypeExportedToWindowsRuntime (void)
+{
+       mono_set_pending_exception (mono_get_exception_not_implemented (NULL));
+       return FALSE;
+}
+
+ICALL_EXPORT MonoBoolean
+ves_icall_System_RuntimeType_IsWindowsRuntimeObjectType (void)
+{
+       mono_set_pending_exception (mono_get_exception_not_implemented (NULL));
+       return FALSE;
+}
+
+ICALL_EXPORT void
+ves_icall_MonoMethod_GetPInvoke (MonoReflectionMethod *method, int* flags, MonoString** entry_point, MonoString** dll_name)
 {
-       static MonoClass *DllImportAttributeClass = NULL;
        MonoDomain *domain = mono_domain_get ();
-       MonoReflectionDllImportAttribute *attr;
-       MonoImage *image = method->klass->image;
-       MonoMethodPInvoke *piinfo = (MonoMethodPInvoke *)method;
+       MonoImage *image = method->method->klass->image;
+       MonoMethodPInvoke *piinfo = (MonoMethodPInvoke *)method->method;
        MonoTableInfo *tables = image->tables;
        MonoTableInfo *im = &tables [MONO_TABLE_IMPLMAP];
        MonoTableInfo *mr = &tables [MONO_TABLE_MODULEREF];
@@ -2567,22 +2546,10 @@ ves_icall_MonoMethod_GetDllImportAttribute (MonoMethod *method)
        guint32 scope_token;
        const char *import = NULL;
        const char *scope = NULL;
-       guint32 flags;
-
-       if (!(method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL))
-               return NULL;
 
-       if (!DllImportAttributeClass) {
-               DllImportAttributeClass = 
-                       mono_class_from_name (mono_defaults.corlib,
-                                                                 "System.Runtime.InteropServices", "DllImportAttribute");
-               g_assert (DllImportAttributeClass);
-       }
-                                                                                                               
-       if (image_is_dynamic (method->klass->image)) {
+       if (image_is_dynamic (image)) {
                MonoReflectionMethodAux *method_aux = 
-                       g_hash_table_lookup (
-                                                                         ((MonoDynamicImage*)method->klass->image)->method_aux_hash, method);
+                       g_hash_table_lookup (((MonoDynamicImage*)image)->method_aux_hash, method->method);
                if (method_aux) {
                        import = method_aux->dllentry;
                        scope = method_aux->dll;
@@ -2590,7 +2557,7 @@ ves_icall_MonoMethod_GetDllImportAttribute (MonoMethod *method)
 
                if (!import || !scope) {
                        mono_set_pending_exception (mono_get_exception_argument ("method", "System.Reflection.Emit method with invalid pinvoke information"));
-                       return NULL;
+                       return;
                }
        }
        else {
@@ -2603,23 +2570,10 @@ ves_icall_MonoMethod_GetDllImportAttribute (MonoMethod *method)
                        scope = mono_metadata_string_heap (image, scope_token);
                }
        }
-       flags = piinfo->piflags;
        
-       attr = (MonoReflectionDllImportAttribute*)mono_object_new (domain, DllImportAttributeClass);
-
-       MONO_OBJECT_SETREF (attr, dll, mono_string_new (domain, scope));
-       MONO_OBJECT_SETREF (attr, entry_point, mono_string_new (domain, import));
-       attr->call_conv = (flags & 0x700) >> 8;
-       attr->charset = ((flags & 0x6) >> 1) + 1;
-       if (attr->charset == 1)
-               attr->charset = 2;
-       attr->exact_spelling = (flags & 0x1) != 0;
-       attr->set_last_error = (flags & 0x40) != 0;
-       attr->best_fit_mapping = (flags & 0x30) == 0x10;
-       attr->throw_on_unmappable = (flags & 0x3000) == 0x1000;
-       attr->preserve_sig = FALSE;
-
-       return attr;
+       *flags = piinfo->piflags;
+       *entry_point = mono_string_new (domain, import);
+       *dll_name = mono_string_new (domain, scope);
 }
 
 ICALL_EXPORT MonoReflectionMethod *
@@ -2817,15 +2771,19 @@ ves_icall_InternalInvoke (MonoReflectionMethod *method, MonoObject *this, MonoAr
 
                if (m->klass->rank == pcount) {
                        /* Only lengths provided. */
-                       lower_bounds = NULL;
+                       return (MonoObject*)mono_array_new_full (mono_object_domain (params), m->klass, lengths, NULL);
                } else {
                        g_assert (pcount == (m->klass->rank * 2));
-                       /* lower bounds are first. */
-                       lower_bounds = (intptr_t*)lengths;
-                       lengths += m->klass->rank;
-               }
+                       /* The arguments are lower-bound-length pairs */
+                       lower_bounds = g_alloca (sizeof (intptr_t) * pcount);
+
+                       for (i = 0; i < pcount / 2; ++i) {
+                               lower_bounds [i] = *(int32_t*) ((char*)mono_array_get (params, gpointer, (i * 2)) + sizeof (MonoObject));
+                               lengths [i] = *(int32_t*) ((char*)mono_array_get (params, gpointer, (i * 2) + 1) + sizeof (MonoObject));
+                       }
 
-               return (MonoObject*)mono_array_new_full (mono_object_domain (params), m->klass, lengths, lower_bounds);
+                       return (MonoObject*)mono_array_new_full (mono_object_domain (params), m->klass, lengths, lower_bounds);
+               }
        }
        return mono_runtime_invoke_array (m, obj, params, NULL);
 }
@@ -2968,17 +2926,16 @@ read_enum_value (const char *mem, int type)
                return *(gint8*)mem;
        case MONO_TYPE_CHAR:
        case MONO_TYPE_U2:
-               return *(guint16*)mem;
+               return read16 (mem);
        case MONO_TYPE_I2:
-               return *(gint16*)mem;
+               return (gint16) read16 (mem);
        case MONO_TYPE_U4:
-               return *(guint32*)mem;
+               return read32 (mem);
        case MONO_TYPE_I4:
-               return *(gint32*)mem;
+               return (gint32) read32 (mem);
        case MONO_TYPE_U8:
-               return *(guint64*)mem;
        case MONO_TYPE_I8:
-               return *(gint64*)mem;
+               return read64 (mem);
        default:
                g_assert_not_reached ();
        }
@@ -3135,6 +3092,8 @@ ves_icall_System_Enum_compare_value_to (MonoObject *this, MonoObject *other)
                        COMPARE_ENUM_VALUES (guint64);
                case MONO_TYPE_I8:
                        COMPARE_ENUM_VALUES (gint64);
+               default:
+                       break;
        }
 #undef COMPARE_ENUM_VALUES
        /* indicates that the enum was of an unsupported unerlying type */
@@ -3179,7 +3138,7 @@ ves_icall_System_Enum_GetEnumValuesAndNames (MonoReflectionType *type, MonoArray
 {
        MonoDomain *domain = mono_object_domain (type); 
        MonoClass *enumc = mono_class_from_mono_type (type->type);
-       guint j = 0, nvalues, crow;
+       guint j = 0, nvalues;
        gpointer iter;
        MonoClassField *field;
        int base_type;
@@ -3199,11 +3158,9 @@ ves_icall_System_Enum_GetEnumValuesAndNames (MonoReflectionType *type, MonoArray
        *names = mono_array_new (domain, mono_defaults.string_class, nvalues);
        *values = mono_array_new (domain, mono_defaults.uint64_class, nvalues);
 
-       crow = -1;
        iter = NULL;
        while ((field = mono_class_get_fields (enumc, &iter))) {
                const char *p;
-               int len;
                MonoTypeEnum def_type;
 
                if (!(field->type->attrs & FIELD_ATTRIBUTE_STATIC))
@@ -3215,7 +3172,7 @@ ves_icall_System_Enum_GetEnumValuesAndNames (MonoReflectionType *type, MonoArray
                mono_array_setref (*names, j, mono_string_new (domain, mono_field_get_name (field)));
 
                p = mono_class_get_field_default_value (field, &def_type);
-               len = mono_metadata_decode_blob_size (p, &p);
+               /* len = */ mono_metadata_decode_blob_size (p, &p);
 
                field_value = read_enum_value (p, base_type);
                mono_array_set (*values, guint64, j, field_value);
@@ -3249,82 +3206,8 @@ enum {
        BFLAGS_OptionalParamBinding = 0x40000
 };
 
-ICALL_EXPORT MonoReflectionField *
-ves_icall_Type_GetField (MonoReflectionType *type, MonoString *name, guint32 bflags)
-{
-       MonoDomain *domain; 
-       MonoClass *startklass, *klass;
-       int match;
-       MonoClassField *field;
-       gpointer iter;
-       char *utf8_name;
-       int (*compare_func) (const char *s1, const char *s2) = NULL;
-       domain = ((MonoObject *)type)->vtable->domain;
-       klass = startklass = mono_class_from_mono_type (type->type);
-
-       if (!name) {
-               mono_set_pending_exception (mono_get_exception_argument_null ("name"));
-               return NULL;
-       }
-       if (type->type->byref)
-               return NULL;
-
-       compare_func = (bflags & BFLAGS_IgnoreCase) ? mono_utf8_strcasecmp : strcmp;
-
-handle_parent:
-       if (klass->exception_type != MONO_EXCEPTION_NONE) {
-               mono_set_pending_exception (mono_class_get_exception_for_failure (klass));
-               return NULL;
-       }
-
-       iter = NULL;
-       while ((field = mono_class_get_fields_lazy (klass, &iter))) {
-               guint32 flags = mono_field_get_flags (field);
-               match = 0;
-
-               if (mono_field_is_deleted_with_flags (field, flags))
-                       continue;
-               if ((flags & FIELD_ATTRIBUTE_FIELD_ACCESS_MASK) == FIELD_ATTRIBUTE_PUBLIC) {
-                       if (bflags & BFLAGS_Public)
-                               match++;
-               } else if ((klass == startklass) || (flags & FIELD_ATTRIBUTE_FIELD_ACCESS_MASK) != FIELD_ATTRIBUTE_PRIVATE) {
-                       if (bflags & BFLAGS_NonPublic) {
-                               match++;
-                       }
-               }
-               if (!match)
-                       continue;
-               match = 0;
-               if (flags & FIELD_ATTRIBUTE_STATIC) {
-                       if (bflags & BFLAGS_Static)
-                               if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
-                                       match++;
-               } else {
-                       if (bflags & BFLAGS_Instance)
-                               match++;
-               }
-
-               if (!match)
-                       continue;
-               
-               utf8_name = mono_string_to_utf8 (name);
-
-               if (compare_func (mono_field_get_name (field), utf8_name)) {
-                       g_free (utf8_name);
-                       continue;
-               }
-               g_free (utf8_name);
-               
-               return mono_field_get_object (domain, klass, field);
-       }
-       if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
-               goto handle_parent;
-
-       return NULL;
-}
-
 ICALL_EXPORT MonoArray*
-ves_icall_Type_GetFields_internal (MonoReflectionType *type, guint32 bflags, MonoReflectionType *reftype)
+ves_icall_Type_GetFields_internal (MonoReflectionType *type, MonoString *name, guint32 bflags, MonoReflectionType *reftype)
 {
        MonoDomain *domain; 
        MonoClass *startklass, *klass, *refklass;
@@ -3332,12 +3215,15 @@ ves_icall_Type_GetFields_internal (MonoReflectionType *type, guint32 bflags, Mon
        MonoObject *member;
        int i, match;
        gpointer iter;
+       char *utf8_name = NULL;
+       int (*compare_func) (const char *s1, const char *s2) = NULL;    
        MonoClassField *field;
        MonoPtrArray tmp_array;
 
        domain = ((MonoObject *)type)->vtable->domain;
        if (type->type->byref)
                return mono_array_new (domain, mono_defaults.field_info_class, 0);
+
        klass = startklass = mono_class_from_mono_type (type->type);
        refklass = mono_class_from_mono_type (reftype->type);
 
@@ -3378,6 +3264,17 @@ handle_parent:
 
                if (!match)
                        continue;
+
+               if (name != NULL) {
+                       if (utf8_name == NULL) {
+                               utf8_name = mono_string_to_utf8 (name);
+                               compare_func = (bflags & BFLAGS_IgnoreCase) ? mono_utf8_strcasecmp : strcmp;
+                       }
+
+                       if (compare_func (mono_field_get_name (field), utf8_name))
+                               continue;
+               }
+
                member = (MonoObject*)mono_field_get_object (domain, refklass, field);
                mono_ptr_array_append (tmp_array, member);
        }
@@ -3391,6 +3288,9 @@ handle_parent:
 
        mono_ptr_array_destroy (tmp_array);
 
+       if (utf8_name != NULL)
+               g_free (utf8_name);
+
        return res;
 }
 
@@ -3416,7 +3316,7 @@ mono_class_get_methods_by_name (MonoClass *klass, const char *name, guint32 bfla
        MonoClass *startklass;
        MonoMethod *method;
        gpointer iter;
-       int len, match, nslots;
+       int match, nslots;
        /*FIXME, use MonoBitSet*/
        guint32 method_slots_default [8];
        guint32 *method_slots = NULL;
@@ -3426,7 +3326,6 @@ mono_class_get_methods_by_name (MonoClass *klass, const char *name, guint32 bfla
        startklass = klass;
        *ex = NULL;
 
-       len = 0;
        if (name != NULL)
                compare_func = (ignore_case) ? mono_utf8_strcasecmp : strcmp;
 
@@ -3794,77 +3693,6 @@ loader_error:
        return NULL;
 }
 
-ICALL_EXPORT MonoReflectionEvent *
-ves_icall_MonoType_GetEvent (MonoReflectionType *type, MonoString *name, guint32 bflags)
-{
-       MonoDomain *domain;
-       MonoClass *klass, *startklass;
-       gpointer iter;
-       MonoEvent *event;
-       MonoMethod *method;
-       gchar *event_name;
-       int (*compare_func) (const char *s1, const char *s2);
-
-       event_name = mono_string_to_utf8 (name);
-       if (type->type->byref)
-               return NULL;
-       klass = startklass = mono_class_from_mono_type (type->type);
-       domain = mono_object_domain (type);
-
-       mono_class_init_or_throw (klass);
-
-       compare_func = (bflags & BFLAGS_IgnoreCase) ? mono_utf8_strcasecmp : strcmp;
-handle_parent: 
-       if (klass->exception_type != MONO_EXCEPTION_NONE) {
-               mono_set_pending_exception (mono_class_get_exception_for_failure (klass));
-               return NULL;
-       }
-
-       iter = NULL;
-       while ((event = mono_class_get_events (klass, &iter))) {
-               if (compare_func (event->name, event_name))
-                       continue;
-
-               method = event->add;
-               if (!method)
-                       method = event->remove;
-               if (!method)
-                       method = event->raise;
-               if (method) {
-                       if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
-                               if (!(bflags & BFLAGS_Public))
-                                       continue;
-                       } else {
-                               if (!(bflags & BFLAGS_NonPublic))
-                                       continue;
-                               if ((klass != startklass) && (method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PRIVATE)
-                                       continue;
-                       }
-
-                       if (method->flags & METHOD_ATTRIBUTE_STATIC) {
-                               if (!(bflags & BFLAGS_Static))
-                                       continue;
-                               if (!(bflags & BFLAGS_FlattenHierarchy) && (klass != startklass))
-                                       continue;
-                       } else {
-                               if (!(bflags & BFLAGS_Instance))
-                                       continue;
-                       }
-               } else 
-                       if (!(bflags & BFLAGS_NonPublic))
-                               continue;
-               
-               g_free (event_name);
-               return mono_event_get_object (domain, startklass, event);
-       }
-
-       if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
-               goto handle_parent;
-
-       g_free (event_name);
-       return NULL;
-}
-
 static guint
 event_hash (gconstpointer data)
 {
@@ -3881,7 +3709,7 @@ event_equal (MonoEvent *event1, MonoEvent *event2)
 }
 
 ICALL_EXPORT MonoArray*
-ves_icall_Type_GetEvents_internal (MonoReflectionType *type, guint32 bflags, MonoReflectionType *reftype)
+ves_icall_Type_GetEvents_internal (MonoReflectionType *type, MonoString *name, guint32 bflags, MonoReflectionType *reftype)
 {
        MonoException *ex;
        MonoDomain *domain; 
@@ -3892,6 +3720,8 @@ ves_icall_Type_GetEvents_internal (MonoReflectionType *type, guint32 bflags, Mon
        MonoEvent *event;
        int i, match;
        gpointer iter;
+       char *utf8_name = NULL;
+       int (*compare_func) (const char *s1, const char *s2) = NULL;    
        GHashTable *events = NULL;
        MonoPtrArray tmp_array;
 
@@ -3952,6 +3782,16 @@ handle_parent:
                if (!match)
                        continue;
 
+               if (name != NULL) {
+                       if (utf8_name == NULL) {
+                               utf8_name = mono_string_to_utf8 (name);
+                               compare_func = (bflags & BFLAGS_IgnoreCase) ? mono_utf8_strcasecmp : strcmp;
+                       }
+
+                       if (compare_func (event->name, utf8_name))
+                               continue;
+               }               
+
                if (g_hash_table_lookup (events, event))
                        continue;
 
@@ -3971,6 +3811,9 @@ handle_parent:
 
        mono_ptr_array_destroy (tmp_array);
 
+       if (utf8_name != NULL)
+               g_free (utf8_name);
+
        return res;
 
 loader_error:
@@ -3985,70 +3828,8 @@ loader_error:
        return NULL;
 }
 
-ICALL_EXPORT MonoReflectionType *
-ves_icall_Type_GetNestedType (MonoReflectionType *type, MonoString *name, guint32 bflags)
-{
-       MonoDomain *domain; 
-       MonoClass *klass;
-       MonoClass *nested;
-       char *str;
-       gpointer iter;
-       
-       if (name == NULL) {
-               mono_set_pending_exception (mono_get_exception_argument_null ("name"));
-               return NULL;
-       }
-       
-       domain = ((MonoObject *)type)->vtable->domain;
-       if (type->type->byref)
-               return NULL;
-       klass = mono_class_from_mono_type (type->type);
-
-       str = mono_string_to_utf8 (name);
-
- handle_parent:
-       if (klass->exception_type != MONO_EXCEPTION_NONE) {
-               mono_set_pending_exception (mono_class_get_exception_for_failure (klass));
-               return NULL;
-       }
-
-       /*
-        * If a nested type is generic, return its generic type definition.
-        * Note that this means that the return value is essentially a
-        * nested type of the generic type definition of @klass.
-        *
-        * A note in MSDN claims that a generic type definition can have
-        * nested types that aren't generic.  In any case, the container of that
-        * nested type would be the generic type definition.
-        */
-       if (klass->generic_class)
-               klass = klass->generic_class->container_class;
-
-       iter = NULL;
-       while ((nested = mono_class_get_nested_types (klass, &iter))) {
-               int match = 0;
-               if ((nested->flags & TYPE_ATTRIBUTE_VISIBILITY_MASK) == TYPE_ATTRIBUTE_NESTED_PUBLIC) {
-                       if (bflags & BFLAGS_Public)
-                               match++;
-               } else {
-                       if (bflags & BFLAGS_NonPublic)
-                               match++;
-               }
-               if (!match)
-                       continue;
-               if (strcmp (nested->name, str) == 0){
-                       g_free (str);
-                       return mono_type_get_object (domain, &nested->byval_arg);
-               }
-       }
-       if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
-               goto handle_parent;
-       g_free (str);
-       return NULL;
-}
-
 ICALL_EXPORT MonoArray*
-ves_icall_Type_GetNestedTypes (MonoReflectionType *type, guint32 bflags)
+ves_icall_Type_GetNestedTypes (MonoReflectionType *type, MonoString *name, guint32 bflags)
 {
        MonoDomain *domain; 
        MonoClass *klass;
@@ -4057,6 +3838,7 @@ ves_icall_Type_GetNestedTypes (MonoReflectionType *type, guint32 bflags)
        int i, match;
        MonoClass *nested;
        gpointer iter;
+       char *str = NULL;
        MonoPtrArray tmp_array;
 
        domain = ((MonoObject *)type)->vtable->domain;
@@ -4089,6 +3871,15 @@ ves_icall_Type_GetNestedTypes (MonoReflectionType *type, guint32 bflags)
                }
                if (!match)
                        continue;
+
+               if (name != NULL) {
+                       if (str == NULL)
+                               str = mono_string_to_utf8 (name);
+
+                       if (strcmp (nested->name, str))
+                               continue;
+               }
+
                member = (MonoObject*)mono_type_get_object (domain, &nested->byval_arg);
                mono_ptr_array_append (tmp_array, member);
        }
@@ -4100,6 +3891,9 @@ ves_icall_Type_GetNestedTypes (MonoReflectionType *type, guint32 bflags)
 
        mono_ptr_array_destroy (tmp_array);
 
+       if (!str)
+               g_free (str);
+
        return res;
 }
 
@@ -4201,10 +3995,6 @@ ves_icall_System_Reflection_Assembly_InternalGetType (MonoReflectionAssembly *as
        if (type->type == MONO_TYPE_CLASS) {
                MonoClass *klass = mono_type_get_class (type);
 
-               if (mono_security_enabled () && !klass->exception_type)
-                       /* Some security problems are detected during generic vtable construction */
-                       mono_class_setup_vtable (klass);
-
                /* need to report exceptions ? */
                if (throwOnError && klass->exception_type) {
                        /* report SecurityException (or others) that occured when loading the assembly */
@@ -4212,8 +4002,6 @@ ves_icall_System_Reflection_Assembly_InternalGetType (MonoReflectionAssembly *as
                        mono_loader_clear_error ();
                        mono_set_pending_exception (exc);
                        return NULL;
-               } else if (mono_security_enabled () && klass->exception_type == MONO_EXCEPTION_SECURITY_INHERITANCEDEMAND) {
-                       return NULL;
                }
        }
 
@@ -4791,12 +4579,6 @@ ves_icall_System_Reflection_MethodBase_GetMethodFromHandleInternalType (MonoMeth
        return mono_method_get_object (mono_domain_get (), method, klass);
 }
 
-ICALL_EXPORT MonoReflectionMethod*
-ves_icall_System_Reflection_MethodBase_GetMethodFromHandleInternal (MonoMethod *method)
-{
-       return mono_method_get_object (mono_domain_get (), method, NULL);
-}
-
 ICALL_EXPORT MonoReflectionMethodBody*
 ves_icall_System_Reflection_MethodBase_GetMethodBodyInternal (MonoMethod *method)
 {
@@ -4879,6 +4661,20 @@ vell_icall_MonoType_get_core_clr_security_level (MonoReflectionType *this)
        return mono_security_core_clr_class_level (klass);
 }
 
+ICALL_EXPORT int
+ves_icall_MonoField_get_core_clr_security_level (MonoReflectionField *this)
+{
+       MonoClassField *field = this->field;
+       return mono_security_core_clr_field_level (field, TRUE);
+}
+
+ICALL_EXPORT int
+ves_icall_MonoMethod_get_core_clr_security_level (MonoReflectionMethod *this)
+{
+       MonoMethod *method = this->method;
+       return mono_security_core_clr_method_level (method, TRUE);
+}
+
 static void
 fill_reflection_assembly_name (MonoDomain *domain, MonoReflectionAssemblyName *aname, MonoAssemblyName *name, const char *absolute, gboolean by_default_version, gboolean default_publickey, gboolean default_token)
 {
@@ -5126,7 +4922,7 @@ mono_module_get_types (MonoDomain *domain, MonoImage *image, MonoArray **excepti
                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);
-                       g_assert (!mono_loader_get_last_error ()); /* Plug any leaks */
+                       mono_loader_assert_no_error (); /* Plug any leaks */
                        
                        if (klass) {
                                mono_array_setref (res, count, mono_type_get_object (domain, &klass->byval_arg));
@@ -5812,265 +5608,17 @@ ves_icall_System_Delegate_CreateDelegate_internal (MonoReflectionType *type, Mon
        return delegate;
 }
 
-ICALL_EXPORT void
-ves_icall_System_Delegate_SetMulticastInvoke (MonoDelegate *this)
+ICALL_EXPORT MonoMulticastDelegate *
+ves_icall_System_Delegate_AllocDelegateLike_internal (MonoDelegate *delegate)
 {
-       /* Reset the invoke impl to the default one */
-       this->invoke_impl = mono_runtime_create_delegate_trampoline (this->object.vtable->klass);
-}
+       MonoMulticastDelegate *ret;
 
-/*
- * Magic number to convert a time which is relative to
- * Jan 1, 1970 into a value which is relative to Jan 1, 0001.
- */
-#define        EPOCH_ADJUST    ((guint64)62135596800LL)
+       g_assert (mono_class_has_parent (mono_object_class (delegate), mono_defaults.multicastdelegate_class));
 
-/*
- * Magic number to convert FILETIME base Jan 1, 1601 to DateTime - base Jan, 1, 0001
- */
-#define FILETIME_ADJUST ((guint64)504911232000000000LL)
-
-#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)
-{
-#define IS_LEAP(y) ((y % 4) == 0 && ((y % 100) != 0 || (y % 400) == 0))
-       static int days_in_month[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
-       static int leap_days_in_month[] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
-       /* from the calendar FAQ */
-       int a = (14 - date->wMonth) / 12;
-       int y = date->wYear - a;
-       int m = date->wMonth + 12 * a - 2;
-       int d = (1 + y + y/4 - y/100 + y/400 + (31*m)/12) % 7;
+       ret = (MonoMulticastDelegate*) mono_object_new (mono_object_domain (delegate), mono_object_class (delegate));
+       ret->delegate.invoke_impl = mono_runtime_create_delegate_trampoline (mono_object_class (delegate));
 
-       /* d is now the day of the week for the first of the month (0 == Sunday) */
-
-       int day_of_week = date->wDayOfWeek;
-
-       /* set day_in_month to the first day in the month which falls on day_of_week */    
-       int day_in_month = 1 + (day_of_week - d);
-       if (day_in_month <= 0)
-               day_in_month += 7;
-
-       /* wDay is 1 for first weekday in month, 2 for 2nd ... 5 means last - so work that out allowing for days in the month */
-       date->wDay = day_in_month + (date->wDay - 1) * 7;
-       if (date->wDay > (IS_LEAP(date->wYear) ? leap_days_in_month[date->wMonth - 1] : days_in_month[date->wMonth - 1]))
-               date->wDay -= 7;
-}
-#endif
-
-#ifndef HOST_WIN32
-/*
- * Return's the offset from GMT of a local time.
- * 
- *  tm is a local time
- *  t  is the same local time as seconds.
- */
-static int 
-gmt_offset(struct tm *tm, time_t t)
-{
-#if defined (HAVE_TM_GMTOFF)
-       return tm->tm_gmtoff;
-#else
-       struct tm g;
-       time_t t2;
-       g = *gmtime(&t);
-       g.tm_isdst = tm->tm_isdst;
-       t2 = mktime(&g);
-       return (int)difftime(t, t2);
-#endif
-}
-#endif
-/*
- * This is heavily based on zdump.c from glibc 2.2.
- *
- *  * data[0]:  start of daylight saving time (in DateTime ticks).
- *  * data[1]:  end of daylight saving time (in DateTime ticks).
- *  * data[2]:  utcoffset (in TimeSpan ticks).
- *  * data[3]:  additional offset when daylight saving (in TimeSpan ticks).
- *  * name[0]:  name of this timezone when not daylight saving.
- *  * name[1]:  name of this timezone when daylight saving.
- *
- *  FIXME: This only works with "standard" Unix dates (years between 1900 and 2100) while
- *         the class library allows years between 1 and 9999.
- *
- *  Returns true on success and zero on failure.
- */
-ICALL_EXPORT guint32
-ves_icall_System_CurrentSystemTimeZone_GetTimeZoneData (guint32 year, MonoArray **data, MonoArray **names)
-{
-#ifndef HOST_WIN32
-       MonoDomain *domain = mono_domain_get ();
-       struct tm start, tt;
-       time_t t;
-
-       long int gmtoff, gmtoff_after, gmtoff_st, gmtoff_ds;
-       int day, transitioned;
-       char tzone [64];
-
-       gmtoff_st = gmtoff_ds = transitioned = 0;
-
-       MONO_CHECK_ARG_NULL (data, 0);
-       MONO_CHECK_ARG_NULL (names, 0);
-
-       mono_gc_wbarrier_generic_store (data, (MonoObject*) mono_array_new (domain, mono_defaults.int64_class, 4));
-       mono_gc_wbarrier_generic_store (names, (MonoObject*) mono_array_new (domain, mono_defaults.string_class, 2));
-
-       /* 
-        * no info is better than crashing: we'll need our own tz data
-        * to make this work properly, anyway. The range is probably
-        * reduced to 1970 .. 2037 because that is what mktime is
-        * guaranteed to support (we get into an infinite loop
-        * otherwise).
-        */
-
-       memset (&start, 0, sizeof (start));
-
-       start.tm_mday = 1;
-       start.tm_year = year-1900;
-
-       t = mktime (&start);
-
-       if ((year < 1970) || (year > 2037) || (t == -1)) {
-               t = time (NULL);
-               tt = *localtime (&t);
-               strftime (tzone, sizeof (tzone), "%Z", &tt);
-               mono_array_setref ((*names), 0, mono_string_new (domain, tzone));
-               mono_array_setref ((*names), 1, mono_string_new (domain, tzone));
-               return 1;
-       }
-
-       gmtoff = gmt_offset (&start, t);
-
-       /* For each day of the year, calculate the tm_gmtoff. */
-       for (day = 0; day < 365 && transitioned < 2; day++) {
-
-               t += 3600*24;
-               tt = *localtime (&t);
-
-        gmtoff_after = gmt_offset(&tt, t);
-
-               /* Daylight saving starts or ends here. */
-               if (gmtoff_after != gmtoff) {
-                       struct tm tt1;
-                       time_t t1;
-
-                       /* Try to find the exact hour when daylight saving starts/ends. */
-                       t1 = t;
-                       do {
-                               t1 -= 3600;
-                               tt1 = *localtime (&t1);
-                       } while (gmt_offset (&tt1, t1) != gmtoff);
-
-                       /* Try to find the exact minute when daylight saving starts/ends. */
-                       do {
-                               t1 += 60;
-                               tt1 = *localtime (&t1);
-                       } while (gmt_offset (&tt1, t1) == gmtoff);
-                       t1+=gmtoff;
-                       strftime (tzone, sizeof (tzone), "%Z", &tt);
-                       
-                       /* Write data, if we're already in daylight saving, we're done. */
-                       if (tt.tm_isdst) {
-                               mono_array_setref ((*names), 1, mono_string_new (domain, tzone));
-                               mono_array_set ((*data), gint64, 0, ((gint64)t1 + EPOCH_ADJUST) * 10000000L);
-                               if (gmtoff_ds == 0) {
-                                       gmtoff_st = gmtoff;
-                                       gmtoff_ds = gmtoff_after;
-                               }
-                               transitioned++;
-                       } else {
-                               time_t te;
-                               te = mktime (&tt);
-                               
-                               mono_array_setref ((*names), 0, mono_string_new (domain, tzone));
-                               mono_array_set ((*data), gint64, 1, ((gint64)t1 + EPOCH_ADJUST) * 10000000L);
-                               if (gmtoff_ds == 0) {
-                                       gmtoff_st = gmtoff_after;
-                                       gmtoff_ds = gmtoff;
-                               }
-                               transitioned++;
-                       }
-
-                       /* This is only set once when we enter daylight saving. */
-                       if (tt1.tm_isdst) {
-                               mono_array_set ((*data), gint64, 2, (gint64)gmtoff_st * 10000000L);
-                               mono_array_set ((*data), gint64, 3, (gint64)(gmtoff_ds - gmtoff_st) * 10000000L);
-                       }
-                       gmtoff = gmt_offset (&tt, t);
-               }
-       }
-
-       if (transitioned < 2) {
-               strftime (tzone, sizeof (tzone), "%Z", &tt);
-               mono_array_setref ((*names), 0, mono_string_new (domain, tzone));
-               mono_array_setref ((*names), 1, mono_string_new (domain, tzone));
-               mono_array_set ((*data), gint64, 0, 0);
-               mono_array_set ((*data), gint64, 1, 0);
-               mono_array_set ((*data), gint64, 2, (gint64) gmtoff * 10000000L);
-               mono_array_set ((*data), gint64, 3, 0);
-       }
-
-       return 1;
-#else
-       MonoDomain *domain = mono_domain_get ();
-       TIME_ZONE_INFORMATION tz_info;
-       FILETIME ft;
-       int i;
-       int err, tz_id;
-
-       tz_id = GetTimeZoneInformation (&tz_info);
-       if (tz_id == TIME_ZONE_ID_INVALID)
-               return 0;
-
-       MONO_CHECK_ARG_NULL (data, 0);
-       MONO_CHECK_ARG_NULL (names, 0);
-
-       mono_gc_wbarrier_generic_store (data, mono_array_new (domain, mono_defaults.int64_class, 4));
-       mono_gc_wbarrier_generic_store (names, mono_array_new (domain, mono_defaults.string_class, 2));
-
-       for (i = 0; i < 32; ++i)
-               if (!tz_info.DaylightName [i])
-                       break;
-       mono_array_setref ((*names), 1, mono_string_new_utf16 (domain, tz_info.DaylightName, i));
-       for (i = 0; i < 32; ++i)
-               if (!tz_info.StandardName [i])
-                       break;
-       mono_array_setref ((*names), 0, mono_string_new_utf16 (domain, tz_info.StandardName, i));
-
-       if ((year <= 1601) || (year > 30827)) {
-               /*
-                * According to MSDN, the MS time functions can't handle dates outside
-                * this interval.
-                */
-               return 1;
-       }
-
-       /* even if the timezone has no daylight savings it may have Bias (e.g. GMT+13 it seems) */
-       if (tz_id != TIME_ZONE_ID_UNKNOWN) {
-               tz_info.StandardDate.wYear = year;
-               convert_to_absolute_date(&tz_info.StandardDate);
-               err = SystemTimeToFileTime (&tz_info.StandardDate, &ft);
-               //g_assert(err);
-               if (err == 0)
-                       return 0;
-               
-               mono_array_set ((*data), gint64, 1, FILETIME_ADJUST + (((guint64)ft.dwHighDateTime<<32) | ft.dwLowDateTime));
-               tz_info.DaylightDate.wYear = year;
-               convert_to_absolute_date(&tz_info.DaylightDate);
-               err = SystemTimeToFileTime (&tz_info.DaylightDate, &ft);
-               //g_assert(err);
-               if (err == 0)
-                       return 0;
-               
-               mono_array_set ((*data), gint64, 0, FILETIME_ADJUST + (((guint64)ft.dwHighDateTime<<32) | ft.dwLowDateTime));
-       }
-       mono_array_set ((*data), gint64, 2, (tz_info.Bias + tz_info.StandardBias) * -600000000LL);
-       mono_array_set ((*data), gint64, 3, (tz_info.DaylightBias - tz_info.StandardBias) * -600000000LL);
-
-       return 1;
-#endif
+       return ret;
 }
 
 /* System.Buffer */
@@ -6654,6 +6202,12 @@ ves_icall_System_Environment_BroadcastSettingChange (void)
 #endif
 }
 
+ICALL_EXPORT gint32
+ves_icall_System_Runtime_Versioning_VersioningHelper_GetRuntimeId (void)
+{
+       return 9;
+}
+
 ICALL_EXPORT void
 ves_icall_MonoMethodMessage_InitMessage (MonoMethodMessage *this, 
                                         MonoReflectionMethod *method,
@@ -6851,12 +6405,12 @@ get_bundled_app_config (void)
        MonoDomain *domain;
        MonoString *file;
        gchar *config_file_name, *config_file_path;
-       gsize len;
+       gsize len, config_file_path_length, config_ext_length;
        gchar *module;
 
        domain = mono_domain_get ();
        file = domain->setup->configuration_file;
-       if (!file)
+       if (!file || file->length == 0)
                return NULL;
 
        // Retrieve config file and remove the extension
@@ -6864,7 +6418,13 @@ get_bundled_app_config (void)
        config_file_path = mono_portability_find_file (config_file_name, TRUE);
        if (!config_file_path)
                config_file_path = config_file_name;
-       len = strlen (config_file_path) - strlen (".config");
+
+       config_file_path_length = strlen (config_file_path);
+       config_ext_length = strlen (".config");
+       if (config_file_path_length <= config_ext_length)
+               return NULL;
+
+       len = config_file_path_length - config_ext_length;
        module = g_malloc0 (len + 1);
        memcpy (module, config_file_path, len);
        // Get the config file from the module name
@@ -7173,25 +6733,56 @@ mono_ArgIterator_IntGetNextArgType (MonoArgIterator *iter)
 }
 
 ICALL_EXPORT MonoObject*
-mono_TypedReference_ToObject (MonoTypedRef tref)
+mono_TypedReference_ToObject (MonoTypedRef* tref)
 {
-       if (MONO_TYPE_IS_REFERENCE (tref.type)) {
-               MonoObject** objp = tref.value;
+       if (MONO_TYPE_IS_REFERENCE (tref->type)) {
+               MonoObject** objp = tref->value;
                return *objp;
        }
 
-       return mono_value_box (mono_domain_get (), tref.klass, tref.value);
+       return mono_value_box (mono_domain_get (), tref->klass, tref->value);
 }
 
-ICALL_EXPORT MonoObject*
-mono_TypedReference_ToObjectInternal (MonoType *type, gpointer value, MonoClass *klass)
+ICALL_EXPORT MonoTypedRef
+mono_TypedReference_MakeTypedReferenceInternal (MonoObject *target, MonoArray *fields)
 {
-       if (MONO_TYPE_IS_REFERENCE (type)) {
-               MonoObject** objp = value;
-               return *objp;
+       MonoTypedRef res;
+       MonoReflectionField *f;
+       MonoClass *klass;
+       MonoType *ftype = NULL;
+       guint8 *p = NULL;
+       int i;
+
+       memset (&res, 0, sizeof (res));
+
+       g_assert (fields);
+       g_assert (mono_array_length (fields) > 0);
+
+       klass = target->vtable->klass;
+
+       for (i = 0; i < mono_array_length (fields); ++i) {
+               f = mono_array_get (fields, MonoReflectionField*, i);
+               if (f == NULL) {
+                       mono_set_pending_exception (mono_get_exception_argument_null ("field"));
+                       return res;
+               }
+               if (f->field->parent != klass) {
+                       mono_set_pending_exception (mono_get_exception_argument ("field", ""));
+                       return res;
+               }
+               if (i == 0)
+                       p = (guint8*)target + f->field->offset;
+               else
+                       p += f->field->offset - sizeof (MonoObject);
+               klass = mono_class_from_mono_type (f->field->type);
+               ftype = f->field->type;
        }
 
-       return mono_value_box (mono_domain_get (), klass, value);
+       res.type = ftype;
+       res.klass = mono_class_from_mono_type (ftype);
+       res.value = p;
+
+       return res;
 }
 
 static void
@@ -7244,20 +6835,6 @@ ves_icall_System_NumberFormatter_GetFormatterTables (guint64 const **mantissas,
        *decHexDigits = Formatter_DecHexDigits;
 }
 
-/* These parameters are "readonly" in corlib/System/Globalization/TextInfo.cs */
-ICALL_EXPORT void
-ves_icall_System_Globalization_TextInfo_GetDataTablePointersLite (
-                                           guint16 const **to_lower_data_low,
-                                           guint16 const **to_lower_data_high,
-                                           guint16 const **to_upper_data_low,
-                                           guint16 const **to_upper_data_high)
-{
-       *to_lower_data_low = ToLowerDataLow;
-       *to_lower_data_high = ToLowerDataHigh;
-       *to_upper_data_low = ToUpperDataLow;
-       *to_upper_data_high = ToUpperDataHigh;
-}
-
 /*
  * We return NULL for no modifiers so the corlib code can return Type.EmptyTypes
  * and avoid useless allocations.
@@ -7472,12 +7049,12 @@ ves_icall_System_ComponentModel_Win32Exception_W32ErrorMessage (guint32 code)
 }
 
 ICALL_EXPORT int
-ves_icall_System_StackFrame_GetILOffsetFromFile (MonoString *path, int methodToken, int nativeOffset)
+ves_icall_System_StackFrame_GetILOffsetFromFile (MonoString *path, guint32 method_token, guint32 method_index, int native_offset)
 {
        guint32 il_offset;
        char *path_str = mono_string_to_utf8 (path);
 
-       if (!seq_point_data_get_il_offset (path_str, methodToken, nativeOffset, &il_offset))
+       if (!mono_seq_point_data_get_il_offset (path_str, method_token, method_index, native_offset, &il_offset))
                il_offset = -1;
 
        g_free (path_str);