This commit was manufactured by cvs2svn to create branch 'mono-1-0'.
[mono.git] / mono / metadata / icall.c
index e0cec38ca53de2bc66be0c1c99ad8c6a0f038db5..7e76bf279d4e6c2d0bb1b30e0aa728ef2eff92d5 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <mono/metadata/object.h>
 #include <mono/metadata/threads.h>
+#include <mono/metadata/threads-types.h>
 #include <mono/metadata/threadpool.h>
 #include <mono/metadata/monitor.h>
 #include <mono/metadata/reflection.h>
@@ -33,7 +34,9 @@
 #include <mono/metadata/mono-endian.h>
 #include <mono/metadata/tokentype.h>
 #include <mono/metadata/unicode.h>
-#include <mono/metadata/appdomain.h>
+#include <mono/metadata/domain-internals.h>
+#include <mono/metadata/metadata-internals.h>
+#include <mono/metadata/class-internals.h>
 #include <mono/metadata/marshal.h>
 #include <mono/metadata/gc-internal.h>
 #include <mono/metadata/rand.h>
@@ -901,6 +904,17 @@ ves_icall_ModuleBuilder_getToken (MonoReflectionModuleBuilder *mb, MonoObject *o
        return mono_image_create_token (mb->dynamic_image, obj);
 }
 
+static gint32
+ves_icall_ModuleBuilder_getMethodToken (MonoReflectionModuleBuilder *mb,
+                                       MonoReflectionMethod *method,
+                                       MonoArray *opt_param_types)
+{
+       MONO_ARCH_SAVE_REGS;
+
+       return mono_image_create_method_token (
+               mb->dynamic_image, (MonoObject *) method, opt_param_types);
+}
+
 static gint32
 ves_icall_ModuleBuilder_getDataChunk (MonoReflectionModuleBuilder *mb, MonoArray *buf, gint32 offset)
 {
@@ -930,26 +944,18 @@ ves_icall_ModuleBuilder_build_metadata (MonoReflectionModuleBuilder *mb)
        mono_image_build_metadata (mb);
 }
 
-static MonoReflectionType*
-ves_icall_type_from_name (MonoString *name,
-                         MonoBoolean throwOnError,
-                         MonoBoolean ignoreCase)
+static MonoReflectionType *
+type_from_name (const char *str, MonoBoolean ignoreCase)
 {
-       gchar *str;
        MonoType *type = NULL;
        MonoAssembly *assembly;
        MonoTypeNameParse info;
 
        MONO_ARCH_SAVE_REGS;
 
-       str = mono_string_to_utf8 (name);
        if (!mono_reflection_parse_type (str, &info)) {
-               g_free (str);
                g_list_free (info.modifiers);
                g_list_free (info.nested);
-               if (throwOnError) /* uhm: this is a parse error, though... */
-                       mono_raise_exception (mono_get_exception_type_load (name));
-
                return NULL;
        }
 
@@ -968,19 +974,43 @@ ves_icall_type_from_name (MonoString *name,
        if (!info.assembly.name && !type) /* try mscorlib */
                type = mono_reflection_get_type (NULL, &info, ignoreCase);
 
-       g_free (str);
        g_list_free (info.modifiers);
        g_list_free (info.nested);
-       if (!type) {
-               if (throwOnError)
-                       mono_raise_exception (mono_get_exception_type_load (name));
-
+       if (!type) 
                return NULL;
-       }
 
        return mono_type_get_object (mono_domain_get (), type);
 }
 
+MonoReflectionType *
+mono_type_get (const char *str)
+{
+       char *copy = g_strdup (str);
+       MonoReflectionType *type = type_from_name (copy, FALSE);
+
+       g_free (copy);
+       return type;
+}
+
+static MonoReflectionType*
+ves_icall_type_from_name (MonoString *name,
+                         MonoBoolean throwOnError,
+                         MonoBoolean ignoreCase)
+{
+       char *str = mono_string_to_utf8 (name);
+       MonoReflectionType *type;
+
+       type = type_from_name (str, ignoreCase);
+       g_free (str);
+       if (type == NULL){
+               if (throwOnError)
+                       mono_raise_exception (mono_get_exception_type_load (name));
+       }
+       
+       return type;
+}
+
+
 static MonoReflectionType*
 ves_icall_type_from_handle (MonoType *handle)
 {
@@ -1185,11 +1215,12 @@ ves_icall_get_method_info (MonoMethod *method, MonoMethodInfo *info)
        info->implattrs = method->iflags;
        if (method->signature->call_convention == MONO_CALL_DEFAULT)
                info->callconv = 1;
-       else
+       else {
                if (method->signature->call_convention == MONO_CALL_VARARG)
                        info->callconv = 2;
                else
                        info->callconv = 0;
+       }
        info->callconv |= (method->signature->hasthis << 5) | (method->signature->explicit_this << 6); 
 }
 
@@ -1343,6 +1374,17 @@ ves_icall_FieldInfo_SetValueInternal (MonoReflectionField *field, MonoObject *ob
        }
 }
 
+static MonoReflectionField*
+ves_icall_MonoField_Mono_GetGenericFieldDefinition (MonoReflectionField *field)
+{
+       MONO_ARCH_SAVE_REGS;
+
+       if (field->field->generic_info && field->field->generic_info->reflection_info)
+               return field->field->generic_info->reflection_info;
+
+       return field;
+}
+
 /* From MonoProperty.cs */
 typedef enum {
        PInfo_Attributes = 1,
@@ -2109,6 +2151,7 @@ ves_icall_InternalInvoke (MonoReflectionMethod *method, MonoObject *this, MonoAr
         */
        MonoMethod *m = method->method;
        int pcount;
+       void *obj = this;
 
        MONO_ARCH_SAVE_REGS;
 
@@ -2116,6 +2159,9 @@ ves_icall_InternalInvoke (MonoReflectionMethod *method, MonoObject *this, MonoAr
                if (!mono_object_isinst (this, m->klass))
                        mono_raise_exception (mono_exception_from_name (mono_defaults.corlib, "System.Reflection", "TargetException"));
                m = mono_object_get_virtual_method (this, m);
+               /* must pass the pointer to the value for valuetype methods */
+               if (m->klass->valuetype)
+                       obj = mono_object_unbox (this);
        } else if (!(m->flags & METHOD_ATTRIBUTE_STATIC) && strcmp (m->name, ".ctor") && !m->wrapper_type)
                mono_raise_exception (mono_exception_from_name (mono_defaults.corlib, "System.Reflection", "TargetException"));
 
@@ -2144,7 +2190,7 @@ ves_icall_InternalInvoke (MonoReflectionMethod *method, MonoObject *this, MonoAr
 
                return (MonoObject*)mono_array_new_full (mono_object_domain (params), m->klass, lengths, lower_bounds);
        }
-       return mono_runtime_invoke_array (m, this, params, NULL);
+       return mono_runtime_invoke_array (m, obj, params, NULL);
 }
 
 static MonoObject *
@@ -2168,23 +2214,27 @@ ves_icall_InternalExecute (MonoReflectionMethod *method, MonoObject *this, MonoA
 
                        str = mono_string_to_utf8 (name);
                
-                       for (i = 0; i < k->field.count; i++) {
-                               if (!strcmp (k->fields [i].name, str)) {
-                                       MonoClass *field_klass =  mono_class_from_mono_type (k->fields [i].type);
-                                       if (field_klass->valuetype)
-                                               result = mono_value_box (domain, field_klass,
-                                                                        (char *)this + k->fields [i].offset);
-                                       else 
-                                               result = *((gpointer *)((char *)this + k->fields [i].offset));
-                               
-                                       g_assert (result);
-                                       out_args = mono_array_new (domain, mono_defaults.object_class, 1);
-                                       *outArgs = out_args;
-                                       mono_array_set (out_args, gpointer, 0, result);
-                                       g_free (str);
-                                       return NULL;
+                       do {
+                               for (i = 0; i < k->field.count; i++) {
+                                       if (!strcmp (k->fields [i].name, str)) {
+                                               MonoClass *field_klass =  mono_class_from_mono_type (k->fields [i].type);
+                                               if (field_klass->valuetype)
+                                                       result = mono_value_box (domain, field_klass,
+                                                                                (char *)this + k->fields [i].offset);
+                                               else 
+                                                       result = *((gpointer *)((char *)this + k->fields [i].offset));
+                                       
+                                               g_assert (result);
+                                               out_args = mono_array_new (domain, mono_defaults.object_class, 1);
+                                               *outArgs = out_args;
+                                               mono_array_set (out_args, gpointer, 0, result);
+                                               g_free (str);
+                                               return NULL;
+                                       }
                                }
-                       }
+                               k = k->parent;
+                       } 
+                       while (k != NULL);
 
                        g_free (str);
                        g_assert_not_reached ();
@@ -2197,25 +2247,29 @@ ves_icall_InternalExecute (MonoReflectionMethod *method, MonoObject *this, MonoA
 
                        str = mono_string_to_utf8 (name);
                
-                       for (i = 0; i < k->field.count; i++) {
-                               if (!strcmp (k->fields [i].name, str)) {
-                                       MonoClass *field_klass =  mono_class_from_mono_type (k->fields [i].type);
-                                       MonoObject *val = mono_array_get (params, gpointer, 2);
-
-                                       if (field_klass->valuetype) {
-                                               size = mono_type_size (k->fields [i].type, &align);
-                                               memcpy ((char *)this + k->fields [i].offset, 
-                                                       ((char *)val) + sizeof (MonoObject), size);
-                                       } else 
-                                               *(MonoObject**)((char *)this + k->fields [i].offset) = val;
-                               
-                                       out_args = mono_array_new (domain, mono_defaults.object_class, 0);
-                                       *outArgs = out_args;
-
-                                       g_free (str);
-                                       return NULL;
+                       do {
+                               for (i = 0; i < k->field.count; i++) {
+                                       if (!strcmp (k->fields [i].name, str)) {
+                                               MonoClass *field_klass =  mono_class_from_mono_type (k->fields [i].type);
+                                               MonoObject *val = mono_array_get (params, gpointer, 2);
+       
+                                               if (field_klass->valuetype) {
+                                                       size = mono_type_size (k->fields [i].type, &align);
+                                                       memcpy ((char *)this + k->fields [i].offset, 
+                                                               ((char *)val) + sizeof (MonoObject), size);
+                                               } else 
+                                                       *(MonoObject**)((char *)this + k->fields [i].offset) = val;
+                                       
+                                               out_args = mono_array_new (domain, mono_defaults.object_class, 0);
+                                               *outArgs = out_args;
+       
+                                               g_free (str);
+                                               return NULL;
+                                       }
                                }
-                       }
+                               k = k->parent;
+                       } 
+                       while (k != NULL);
 
                        g_free (str);
                        g_assert_not_reached ();
@@ -2234,6 +2288,8 @@ ves_icall_InternalExecute (MonoReflectionMethod *method, MonoObject *this, MonoA
        if (!strcmp (method->method->name, ".ctor"))
                g_assert_not_reached ();
 
+       /* This can be called only on MBR objects, so no need to unbox for valuetypes. */
+       g_assert (!method->method->klass->valuetype);
        result = mono_runtime_invoke_array (method->method, this, params, NULL);
 
        for (i = 0, j = 0; i < mono_array_length (params); i++) {
@@ -2777,14 +2833,20 @@ handle_parent:
                method = event->add;
                if (!method)
                        method = event->remove;
-
-               if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
-                       if (!(bflags & BFLAGS_Public))
-                               continue;
-               } else {
+               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;
+                       }
+               }
+               else
                        if (!(bflags & BFLAGS_NonPublic))
                                continue;
-               }
 
                g_free (event_name);
                return mono_event_get_object (domain, startklass, event);
@@ -2821,25 +2883,36 @@ handle_parent:
                method = event->add;
                if (!method)
                        method = event->remove;
-               if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
-                       if (bflags & BFLAGS_Public)
-                               match++;
-               } else {
-                       if (bflags & BFLAGS_NonPublic)
-                               match++;
+               if (!method)
+                       method = event->raise;
+               if (method) {
+                       if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
+                               if (bflags & BFLAGS_Public)
+                                       match++;
+                       } else {
+                               if (bflags & BFLAGS_NonPublic)
+                                       match++;
+                       }
                }
+               else
+                       if (bflags & BFLAGS_NonPublic)
+                               match ++;
                if (!match)
                        continue;
                match = 0;
-               if (method->flags & METHOD_ATTRIBUTE_STATIC) {
-                       if (bflags & BFLAGS_Static)
-                               if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
+               if (method) {
+                       if (method->flags & METHOD_ATTRIBUTE_STATIC) {
+                               if (bflags & BFLAGS_Static)
+                                       if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
+                                               match++;
+                       } else {
+                               if (bflags & BFLAGS_Instance)
                                        match++;
-               } else {
-                       if (bflags & BFLAGS_Instance)
-                               match++;
+                       }
                }
-
+               else
+                       if (bflags & BFLAGS_Instance)
+                               match ++;
                if (!match)
                        continue;
                match = 0;
@@ -3122,6 +3195,7 @@ ves_icall_System_Reflection_Assembly_GetReferencedAssemblies (MonoReflectionAsse
        MonoAssembly **ptr;
        MonoDomain *domain = mono_object_domain (assembly);
        int i, count = 0;
+       static MonoMethod *create_culture = NULL;
 
        MONO_ARCH_SAVE_REGS;
 
@@ -3132,7 +3206,15 @@ ves_icall_System_Reflection_Assembly_GetReferencedAssemblies (MonoReflectionAsse
        for (ptr = assembly->assembly->image->references; ptr && *ptr; ptr++)
                count++;
 
-       result = mono_array_new (mono_object_domain (assembly), System_Reflection_AssemblyName, count);
+       result = mono_array_new (domain, System_Reflection_AssemblyName, count);
+
+       if (count > 0) {
+               MonoMethodDesc *desc = mono_method_desc_new (
+                       "System.Globalization.CultureInfo:CreateSpecificCulture(string)", TRUE);
+               create_culture = mono_method_desc_search_in_image (desc, mono_defaults.corlib);
+               g_assert (create_culture);
+               mono_method_desc_free (desc);
+       }
 
        for (i = 0; i < count; i++) {
                MonoAssembly *assem = assembly->assembly->image->references [i];
@@ -3143,7 +3225,32 @@ ves_icall_System_Reflection_Assembly_GetReferencedAssemblies (MonoReflectionAsse
                        domain, System_Reflection_AssemblyName);
 
                aname->name = mono_string_new (domain, assem->aname.name);
+
                aname->major = assem->aname.major;
+               aname->minor = assem->aname.minor;
+               aname->build = assem->aname.build;
+               aname->revision = assem->aname.revision;
+               aname->revision = assem->aname.revision;
+               aname->hashalg = assem->aname.hash_alg;
+               aname->flags = assem->aname.flags;
+
+               if (create_culture) {
+                       gpointer args [1];
+                       args [0] = mono_string_new (domain, assem->aname.culture);
+                       aname->cultureInfo = mono_runtime_invoke (create_culture, NULL, args, NULL);
+               }
+
+               if (assem->aname.public_key) {
+                       guint32 pkey_len;
+                       const char *pkey_ptr = assem->aname.public_key;
+                       pkey_len = mono_metadata_decode_blob_size (pkey_ptr, &pkey_ptr);
+
+                       aname->publicKey = mono_array_new (domain, mono_defaults.byte_class, pkey_len);
+                       memcpy (mono_array_addr (aname->publicKey, guint8, 0), pkey_ptr, pkey_len);
+               }
+
+               /* public key token isn't copied - the class library will 
+                  automatically generate it from the public key if required */
 
                absolute = g_build_filename (assem->basedir, assem->image->module_name, NULL);
                codebase = g_filename_to_uri (absolute, NULL, NULL);
@@ -3260,8 +3367,8 @@ ves_icall_System_Reflection_Assembly_GetManifestResourceInternal (MonoReflection
                 * this code should only be called after obtaining the 
                 * ResourceInfo and handling the other cases.
                 */
-               g_assert ((impl & IMPLEMENTATION_MASK) == IMPLEMENTATION_FILE);
-               file_idx = impl >> IMPLEMENTATION_BITS;
+               g_assert ((impl & MONO_IMPLEMENTATION_MASK) == MONO_IMPLEMENTATION_FILE);
+               file_idx = impl >> MONO_IMPLEMENTATION_BITS;
 
                module = mono_image_load_file_for_image (assembly->assembly->image, file_idx);
                if (!module)
@@ -3302,9 +3409,9 @@ ves_icall_System_Reflection_Assembly_GetManifestResourceInfoInternal (MonoReflec
                info->location = RESOURCE_LOCATION_EMBEDDED | RESOURCE_LOCATION_IN_MANIFEST;
        }
        else {
-               switch (cols [MONO_MANIFEST_IMPLEMENTATION] & IMPLEMENTATION_MASK) {
-               case IMPLEMENTATION_FILE:
-                       i = cols [MONO_MANIFEST_IMPLEMENTATION] >> IMPLEMENTATION_BITS;
+               switch (cols [MONO_MANIFEST_IMPLEMENTATION] & MONO_IMPLEMENTATION_MASK) {
+               case MONO_IMPLEMENTATION_FILE:
+                       i = cols [MONO_MANIFEST_IMPLEMENTATION] >> MONO_IMPLEMENTATION_BITS;
                        table = &assembly->assembly->image->tables [MONO_TABLE_FILE];
                        mono_metadata_decode_row (table, i - 1, file_cols, MONO_FILE_SIZE);
                        val = mono_metadata_string_heap (assembly->assembly->image, file_cols [MONO_FILE_NAME]);
@@ -3315,16 +3422,16 @@ ves_icall_System_Reflection_Assembly_GetManifestResourceInfoInternal (MonoReflec
                                info->location = RESOURCE_LOCATION_EMBEDDED;
                        break;
 
-               case IMPLEMENTATION_ASSEMBLYREF:
-                       i = cols [MONO_MANIFEST_IMPLEMENTATION] >> IMPLEMENTATION_BITS;
+               case MONO_IMPLEMENTATION_ASSEMBLYREF:
+                       i = cols [MONO_MANIFEST_IMPLEMENTATION] >> MONO_IMPLEMENTATION_BITS;
                        info->assembly = mono_assembly_get_object (mono_domain_get (), assembly->assembly->image->references [i - 1]);
 
-                       // Obtain info recursively
+                       /* Obtain info recursively */
                        ves_icall_System_Reflection_Assembly_GetManifestResourceInfoInternal (info->assembly, name, info);
                        info->location |= RESOURCE_LOCATION_ANOTHER_ASSEMBLY;
                        break;
 
-               case IMPLEMENTATION_EXP_TYPE:
+               case MONO_IMPLEMENTATION_EXP_TYPE:
                        g_assert_not_reached ();
                        break;
                }
@@ -3455,7 +3562,7 @@ ves_icall_System_Reflection_Assembly_GetEntryAssembly (void)
        MONO_ARCH_SAVE_REGS;
 
        if (!domain->entry_assembly)
-               domain = mono_root_domain;
+               domain = mono_get_root_domain ();
 
        return mono_assembly_get_object (domain, domain->entry_assembly);
 }
@@ -3849,7 +3956,7 @@ ves_icall_System_DateTime_GetNow (void)
        SYSTEMTIME st;
        FILETIME ft;
        
-       GetLocalTime (&st);
+       GetSystemTime (&st);
        SystemTimeToFileTime (&st, &ft);
        return (gint64) FILETIME_ADJUST + ((((gint64)ft.dwHighDateTime)<<32) | ft.dwLowDateTime);
 #else
@@ -4171,7 +4278,8 @@ ves_icall_System_Buffer_BlockCopyInternal (MonoArray *src, gint32 src_offset, Mo
 
        MONO_ARCH_SAVE_REGS;
 
-       if ((src_offset + count > mono_array_get_byte_length (src)) || (dest_offset + count > mono_array_get_byte_length (dest)))
+       /* watch out for integer overflow */
+       if ((src_offset > mono_array_get_byte_length (src) - count) || (dest_offset > mono_array_get_byte_length (dest) - count))
                return FALSE;
 
        src_buf = (gint8 *)src->vector + src_offset;
@@ -4386,6 +4494,10 @@ static MonoString*
 ves_icall_System_Environment_GetWindowsFolderPath (int folder)
 {
 #if defined (PLATFORM_WIN32)
+       #ifndef CSIDL_FLAG_CREATE
+               #define CSIDL_FLAG_CREATE       0x8000
+       #endif
+
        WCHAR path [MAX_PATH];
        /* Create directory if no existing */
        if (SUCCEEDED (SHGetFolderPathW (NULL, folder | CSIDL_FLAG_CREATE, NULL, 0, path))) {
@@ -4452,6 +4564,14 @@ ves_icall_System_Environment_GetLogicalDrives (void)
        return result;
 }
 
+static MonoString *
+ves_icall_System_Environment_InternalGetHome (void)
+{
+       MONO_ARCH_SAVE_REGS;
+
+       return mono_string_new (mono_domain_get (), g_get_home_dir ());
+}
+
 static const char *encodings [] = {
        (char *) 1,
                "ascii", "us_ascii", "us", "ansi_x3.4_1968",
@@ -4518,10 +4638,8 @@ ves_icall_System_Text_Encoding_InternalCodePage (gint32 *int_code_page)
                p = encodings [++i];
        }
        
-       if (p - codepage > 5){
-               if (strstr (codepage, "utf_8") != NULL)
-                       *int_code_page |= 0x10000000;
-       }
+       if (strstr (codepage, "utf_8") != NULL)
+               *int_code_page |= 0x10000000;
        free (codepage);
        
        if (want_name && *int_code_page == -1)
@@ -4596,7 +4714,7 @@ ves_icall_System_Runtime_Activation_ActivationServices_AllocateUninitializedClas
                g_assert (klass->rank == 1);
                return (MonoObject *) mono_array_new (domain, klass->element_class, 0);
        } else {
-               // Bypass remoting object creation check
+               /* Bypass remoting object creation check */
                return mono_object_new_alloc_specific (mono_class_vtable (domain, klass));
        }
 }
@@ -4775,10 +4893,19 @@ mono_ArgIterator_Setup (MonoArgIterator *iter, char* argsp, char* start)
 
        iter->next_arg = 0;
        /* FIXME: it's not documented what start is exactly... */
-       iter->args = start? start: argsp + sizeof (gpointer);
+       if (start) {
+               iter->args = start;
+       } else {
+               int i, align, arg_size;
+               iter->args = argsp + sizeof (gpointer);
+               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;
+               }
+       }
        iter->num_args = iter->sig->param_count - iter->sig->sentinelpos;
 
-       // g_print ("sig %p, param_count: %d, sent: %d\n", iter->sig, iter->sig->param_count, iter->sig->sentinelpos);
+       /* g_print ("sig %p, param_count: %d, sent: %d\n", iter->sig, iter->sig->param_count, iter->sig->sentinelpos); */
 }
 
 static MonoTypedRef
@@ -4800,7 +4927,7 @@ mono_ArgIterator_IntGetNextArg (MonoArgIterator *iter)
        iter->args = (char*)iter->args + arg_size;
        iter->next_arg++;
 
-       //g_print ("returning arg %d, type 0x%02x of size %d at %p\n", i, res.type->type, arg_size, res.value);
+       /* g_print ("returning arg %d, type 0x%02x of size %d at %p\n", i, res.type->type, arg_size, res.value); */
 
        return res;
 }
@@ -4826,10 +4953,10 @@ mono_ArgIterator_IntGetNextArgT (MonoArgIterator *iter, MonoType *type)
                arg_size = mono_type_stack_size (res.type, &align);
                iter->args = (char*)iter->args + arg_size;
                iter->next_arg++;
-               //g_print ("returning arg %d, type 0x%02x of size %d at %p\n", i, res.type->type, arg_size, res.value);
+               /* g_print ("returning arg %d, type 0x%02x of size %d at %p\n", i, res.type->type, arg_size, res.value); */
                return res;
        }
-       //g_print ("arg type 0x%02x not found\n", res.type->type);
+       /* g_print ("arg type 0x%02x not found\n", res.type->type); */
 
        res.type = NULL;
        res.value = NULL;
@@ -4950,10 +5077,6 @@ static const IcallEntry appdomain_icalls [] = {
        {"getSetup", ves_icall_System_AppDomain_getSetup}
 };
 
-static const IcallEntry appdomainsetup_icalls [] = {
-       {"InitAppDomainSetup", ves_icall_System_AppDomainSetup_InitAppDomainSetup}
-};
-
 static const IcallEntry argiterator_icalls [] = {
        {"IntGetNextArg()",                  mono_ArgIterator_IntGetNextArg},
        {"IntGetNextArg(intptr)", mono_ArgIterator_IntGetNextArgT},
@@ -5072,6 +5195,7 @@ static const IcallEntry environment_icalls [] = {
        {"get_TickCount", ves_icall_System_Environment_get_TickCount},
        {"get_UserName", ves_icall_System_Environment_get_UserName},
        {"internalGetGacPath", ves_icall_System_Environment_GetGacPath},
+       {"internalGetHome", ves_icall_System_Environment_InternalGetHome},
        {"set_ExitCode", mono_environment_exitcode_set}
 };
 
@@ -5140,6 +5264,7 @@ static const IcallEntry monoio_icalls [] = {
        {"GetLength(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetLength},
        {"GetSupportsAsync", ves_icall_System_IO_MonoIO_GetSupportsAsync},
        {"GetTempPath(string&)", ves_icall_System_IO_MonoIO_GetTempPath},
+       {"Lock(intptr,long,long,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Lock},
        {"MoveFile(string,string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_MoveFile},
        {"Open(string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare,bool,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Open},
        {"Read(intptr,byte[],int,int,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Read},
@@ -5149,6 +5274,7 @@ static const IcallEntry monoio_icalls [] = {
        {"SetFileAttributes(string,System.IO.FileAttributes,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_SetFileAttributes},
        {"SetFileTime(intptr,long,long,long,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_SetFileTime},
        {"SetLength(intptr,long,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_SetLength},
+       {"Unlock(intptr,long,long,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Unlock},
        {"Write(intptr,byte[],int,int,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Write},
        {"get_AltDirectorySeparatorChar", ves_icall_System_IO_MonoIO_get_AltDirectorySeparatorChar},
        {"get_ConsoleError", ves_icall_System_IO_MonoIO_get_ConsoleError},
@@ -5282,6 +5408,7 @@ static const IcallEntry monoeventinfo_icalls [] = {
 static const IcallEntry monofield_icalls [] = {
        {"GetParentType", ves_icall_MonoField_GetParentType},
        {"GetValueInternal", ves_icall_MonoField_GetValueInternal},
+       {"Mono_GetGenericFieldDefinition", ves_icall_MonoField_Mono_GetGenericFieldDefinition},
        {"SetValueInternal", ves_icall_FieldInfo_SetValueInternal}
 };
 
@@ -5386,6 +5513,7 @@ static const IcallEntry modulebuilder_icalls [] = {
        {"build_metadata", ves_icall_ModuleBuilder_build_metadata},
        {"create_modified_type", ves_icall_ModuleBuilder_create_modified_type},
        {"getDataChunk", ves_icall_ModuleBuilder_getDataChunk},
+       {"getMethodToken", ves_icall_ModuleBuilder_getMethodToken},
        {"getToken", ves_icall_ModuleBuilder_getToken},
        {"getUSIndex", mono_image_insert_string}
 };
@@ -5478,8 +5606,9 @@ static const IcallEntry remotingservices_icalls [] = {
 };
 
 static const IcallEntry rng_icalls [] = {
-       {"InternalGetBytes", ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_InternalGetBytes},
-       {"Seed", ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_Seed}
+       {"RngClose", ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngClose},
+       {"RngGetBytes", ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngGetBytes},
+       {"RngInitialize", ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngInitialize}
 };
 
 static const IcallEntry methodhandle_icalls [] = {
@@ -5510,6 +5639,8 @@ static const IcallEntry string_icalls [] = {
        {"InternalReplace(char,char)", ves_icall_System_String_InternalReplace_Char},
        {"InternalReplace(string,string,System.Globalization.CompareInfo)", ves_icall_System_String_InternalReplace_Str_Comp},
        {"InternalSplit", ves_icall_System_String_InternalSplit},
+       {"InternalStrcpy(string,int,char[])", ves_icall_System_String_InternalStrcpy_Chars},
+       {"InternalStrcpy(string,int,char[],int,int)", ves_icall_System_String_InternalStrcpy_CharsN},
        {"InternalStrcpy(string,int,string)", ves_icall_System_String_InternalStrcpy_Str},
        {"InternalStrcpy(string,int,string,int,int)", ves_icall_System_String_InternalStrcpy_StrN},
        {"InternalToLower(System.Globalization.CultureInfo)", ves_icall_System_String_InternalToLower_Comp},
@@ -5546,8 +5677,8 @@ static const IcallEntry interlocked_icalls [] = {
 };
 
 static const IcallEntry mutex_icalls [] = {
-       {"CreateMutex_internal", ves_icall_System_Threading_Mutex_CreateMutex_internal},
-       {"ReleaseMutex_internal", ves_icall_System_Threading_Mutex_ReleaseMutex_internal}
+       {"CreateMutex_internal(bool,string,bool&)", ves_icall_System_Threading_Mutex_CreateMutex_internal},
+       {"ReleaseMutex_internal(intptr)", ves_icall_System_Threading_Mutex_ReleaseMutex_internal}
 };
 
 static const IcallEntry nativeevents_icalls [] = {
@@ -5573,32 +5704,32 @@ static const IcallEntry thread_icalls [] = {
        {"Suspend_internal", ves_icall_System_Threading_Thread_Suspend},
        {"Thread_free_internal", ves_icall_System_Threading_Thread_Thread_free_internal},
        {"Thread_internal", ves_icall_System_Threading_Thread_Thread_internal},
-       {"VolatileRead(IntPtr&)", ves_icall_System_Threading_Thread_VolatileReadIntPtr},
-       {"VolatileRead(UIntPtr&)", ves_icall_System_Threading_Thread_VolatileReadIntPtr},
        {"VolatileRead(byte&)", ves_icall_System_Threading_Thread_VolatileRead1},
        {"VolatileRead(double&)", ves_icall_System_Threading_Thread_VolatileRead8},
-       {"VolatileRead(float&)", ves_icall_System_Threading_Thread_VolatileRead4},
        {"VolatileRead(int&)", ves_icall_System_Threading_Thread_VolatileRead4},
+       {"VolatileRead(int16&)", ves_icall_System_Threading_Thread_VolatileRead2},
+       {"VolatileRead(intptr&)", ves_icall_System_Threading_Thread_VolatileReadIntPtr},
        {"VolatileRead(long&)", ves_icall_System_Threading_Thread_VolatileRead8},
        {"VolatileRead(object&)", ves_icall_System_Threading_Thread_VolatileReadIntPtr},
        {"VolatileRead(sbyte&)", ves_icall_System_Threading_Thread_VolatileRead1},
-       {"VolatileRead(short&)", ves_icall_System_Threading_Thread_VolatileRead2},
+       {"VolatileRead(single&)", ves_icall_System_Threading_Thread_VolatileRead4},
        {"VolatileRead(uint&)", ves_icall_System_Threading_Thread_VolatileRead2},
+       {"VolatileRead(uint16&)", ves_icall_System_Threading_Thread_VolatileRead2},
+       {"VolatileRead(uintptr&)", ves_icall_System_Threading_Thread_VolatileReadIntPtr},
        {"VolatileRead(ulong&)", ves_icall_System_Threading_Thread_VolatileRead8},
-       {"VolatileRead(ushort&)", ves_icall_System_Threading_Thread_VolatileRead2},
-       {"VolatileWrite(IntPtr&,IntPtr)", ves_icall_System_Threading_Thread_VolatileWriteIntPtr},
-       {"VolatileWrite(UIntPtr&,UIntPtr)", ves_icall_System_Threading_Thread_VolatileWriteIntPtr},
        {"VolatileWrite(byte&,byte)", ves_icall_System_Threading_Thread_VolatileWrite1},
        {"VolatileWrite(double&,double)", ves_icall_System_Threading_Thread_VolatileWrite8},
-       {"VolatileWrite(float&,float)", ves_icall_System_Threading_Thread_VolatileWrite4},
        {"VolatileWrite(int&,int)", ves_icall_System_Threading_Thread_VolatileWrite4},
+       {"VolatileWrite(int16&,int16)", ves_icall_System_Threading_Thread_VolatileWrite2},
+       {"VolatileWrite(intptr&,intptr)", ves_icall_System_Threading_Thread_VolatileWriteIntPtr},
        {"VolatileWrite(long&,long)", ves_icall_System_Threading_Thread_VolatileWrite8},
        {"VolatileWrite(object&,object)", ves_icall_System_Threading_Thread_VolatileWriteIntPtr},
        {"VolatileWrite(sbyte&,sbyte)", ves_icall_System_Threading_Thread_VolatileWrite1},
-       {"VolatileWrite(short&,short)", ves_icall_System_Threading_Thread_VolatileWrite2},
+       {"VolatileWrite(single&,single)", ves_icall_System_Threading_Thread_VolatileWrite4},
        {"VolatileWrite(uint&,uint)", ves_icall_System_Threading_Thread_VolatileWrite2},
+       {"VolatileWrite(uint16&,uint16)", ves_icall_System_Threading_Thread_VolatileWrite2},
+       {"VolatileWrite(uintptr&,uintptr)", ves_icall_System_Threading_Thread_VolatileWriteIntPtr},
        {"VolatileWrite(ulong&,ulong)", ves_icall_System_Threading_Thread_VolatileWrite8},
-       {"VolatileWrite(ushort&,ushort)", ves_icall_System_Threading_Thread_VolatileWrite2},
        {"current_lcid()", ves_icall_System_Threading_Thread_current_lcid}
 };
 
@@ -5687,7 +5818,6 @@ static const IcallMap icall_entries [] = {
        {"Mono.Security.Cryptography.KeyPairPersistence", keypair_icalls, G_N_ELEMENTS (keypair_icalls)},
        {"System.Activator", activator_icalls, G_N_ELEMENTS (activator_icalls)},
        {"System.AppDomain", appdomain_icalls, G_N_ELEMENTS (appdomain_icalls)},
-       {"System.AppDomainSetup", appdomainsetup_icalls, G_N_ELEMENTS (appdomainsetup_icalls)},
        {"System.ArgIterator", argiterator_icalls, G_N_ELEMENTS (argiterator_icalls)},
        {"System.Array", array_icalls, G_N_ELEMENTS (array_icalls)},
        {"System.Buffer", buffer_icalls, G_N_ELEMENTS (buffer_icalls)},