Merge pull request #505 from roji/shutdown_flow
[mono.git] / mono / metadata / icall.c
index 6da69f7116a5cb99ab10ad67737305085bfbf911..ed34f324fc96e03b17aa06a093c71102e58b846a 100644 (file)
@@ -8,6 +8,7 @@
  *
  * Copyright 2001-2003 Ximian, Inc (http://www.ximian.com)
  * Copyright 2004-2009 Novell, Inc (http://www.novell.com)
+ * Copyright 2011-2012 Xamarin Inc (http://www.xamarin.com).
  */
 
 #include <config.h>
@@ -72,6 +73,7 @@
 #include <mono/metadata/mono-debug.h>
 #include <mono/metadata/mono-ptr-array.h>
 #include <mono/metadata/verify-internals.h>
+#include <mono/metadata/runtime.h>
 #include <mono/io-layer/io-layer.h>
 #include <mono/utils/strtod.h>
 #include <mono/utils/monobitset.h>
@@ -81,6 +83,7 @@
 #include <mono/utils/mono-error-internals.h>
 #include <mono/utils/mono-mmap.h>
 #include <mono/utils/mono-io-portability.h>
+#include <mono/utils/mono-digest.h>
 
 #if defined (HOST_WIN32)
 #include <windows.h>
@@ -90,7 +93,7 @@
 
 extern MonoString* ves_icall_System_Environment_GetOSVersionString (void) MONO_INTERNAL;
 
-static MonoReflectionAssembly* ves_icall_System_Reflection_Assembly_GetCallingAssembly (void);
+ICALL_EXPORT MonoReflectionAssembly* ves_icall_System_Reflection_Assembly_GetCallingAssembly (void);
 
 static MonoArray*
 type_array_from_modifiers (MonoImage *image, MonoType *type, int optional);
@@ -111,7 +114,7 @@ mono_class_init_or_throw (MonoClass *klass)
 /*
  * We expect a pointer to a char, not a string
  */
-static gboolean
+ICALL_EXPORT gboolean
 mono_double_ParseImpl (char *ptr, double *result)
 {
        gchar *endptr = NULL;
@@ -137,7 +140,7 @@ mono_double_ParseImpl (char *ptr, double *result)
        return TRUE;
 }
 
-static MonoObject *
+ICALL_EXPORT MonoObject *
 ves_icall_System_Array_GetValueImpl (MonoObject *this, guint32 pos)
 {
        MonoClass *ac;
@@ -159,7 +162,7 @@ ves_icall_System_Array_GetValueImpl (MonoObject *this, guint32 pos)
                return *ea;
 }
 
-static MonoObject *
+ICALL_EXPORT MonoObject *
 ves_icall_System_Array_GetValue (MonoObject *this, MonoObject *idxs)
 {
        MonoClass *ac, *ic;
@@ -202,7 +205,7 @@ ves_icall_System_Array_GetValue (MonoObject *this, MonoObject *idxs)
        return ves_icall_System_Array_GetValueImpl (this, pos);
 }
 
-static void
+ICALL_EXPORT void
 ves_icall_System_Array_SetValueImpl (MonoArray *this, MonoObject *value, guint32 pos)
 {
        MonoClass *ac, *vc, *ec;
@@ -480,7 +483,7 @@ ves_icall_System_Array_SetValueImpl (MonoArray *this, MonoObject *value, guint32
 #undef ASSIGN_REAL
 }
 
-static void 
+ICALL_EXPORT void 
 ves_icall_System_Array_SetValue (MonoArray *this, MonoObject *value,
                                 MonoArray *idxs)
 {
@@ -521,7 +524,7 @@ ves_icall_System_Array_SetValue (MonoArray *this, MonoObject *value,
        ves_icall_System_Array_SetValueImpl (this, value, pos);
 }
 
-static MonoArray *
+ICALL_EXPORT MonoArray *
 ves_icall_System_Array_CreateInstanceImpl (MonoReflectionType *type, MonoArray *lengths, MonoArray *bounds)
 {
        MonoClass *aklass, *klass;
@@ -557,7 +560,7 @@ ves_icall_System_Array_CreateInstanceImpl (MonoReflectionType *type, MonoArray *
        for (i = 0; i < aklass->rank; ++i) {
                sizes [i] = mono_array_get (lengths, guint32, i);
                if (bounds)
-                       sizes [i + aklass->rank] = mono_array_get (bounds, guint32, i);
+                       sizes [i + aklass->rank] = mono_array_get (bounds, gint32, i);
                else
                        sizes [i + aklass->rank] = 0;
        }
@@ -567,7 +570,7 @@ ves_icall_System_Array_CreateInstanceImpl (MonoReflectionType *type, MonoArray *
        return array;
 }
 
-static MonoArray *
+ICALL_EXPORT MonoArray *
 ves_icall_System_Array_CreateInstanceImpl64 (MonoReflectionType *type, MonoArray *lengths, MonoArray *bounds)
 {
        MonoClass *aklass, *klass;
@@ -614,7 +617,7 @@ ves_icall_System_Array_CreateInstanceImpl64 (MonoReflectionType *type, MonoArray
        return array;
 }
 
-static gint32 
+ICALL_EXPORT gint32 
 ves_icall_System_Array_GetRank (MonoObject *this)
 {
        MONO_ARCH_SAVE_REGS;
@@ -622,7 +625,7 @@ ves_icall_System_Array_GetRank (MonoObject *this)
        return this->vtable->klass->rank;
 }
 
-static gint32
+ICALL_EXPORT gint32
 ves_icall_System_Array_GetLength (MonoArray *this, gint32 dimension)
 {
        gint32 rank = ((MonoObject *)this)->vtable->klass->rank;
@@ -645,7 +648,7 @@ ves_icall_System_Array_GetLength (MonoArray *this, gint32 dimension)
        return length;
 }
 
-static gint64
+ICALL_EXPORT gint64
 ves_icall_System_Array_GetLongLength (MonoArray *this, gint32 dimension)
 {
        gint32 rank = ((MonoObject *)this)->vtable->klass->rank;
@@ -661,7 +664,7 @@ ves_icall_System_Array_GetLongLength (MonoArray *this, gint32 dimension)
        return this->bounds [dimension].length;
 }
 
-static gint32
+ICALL_EXPORT gint32
 ves_icall_System_Array_GetLowerBound (MonoArray *this, gint32 dimension)
 {
        gint32 rank = ((MonoObject *)this)->vtable->klass->rank;
@@ -677,14 +680,14 @@ ves_icall_System_Array_GetLowerBound (MonoArray *this, gint32 dimension)
        return this->bounds [dimension].lower_bound;
 }
 
-static void
+ICALL_EXPORT void
 ves_icall_System_Array_ClearInternal (MonoArray *arr, int idx, int length)
 {
        int sz = mono_array_element_size (mono_object_class (arr));
        mono_gc_bzero (mono_array_addr_with_size (arr, sz, idx), length * sz);
 }
 
-static gboolean
+ICALL_EXPORT gboolean
 ves_icall_System_Array_FastCopy (MonoArray *source, int source_idx, MonoArray* dest, int dest_idx, int length)
 {
        int element_size;
@@ -781,7 +784,7 @@ ves_icall_System_Array_FastCopy (MonoArray *source, int source_idx, MonoArray* d
        return TRUE;
 }
 
-static void
+ICALL_EXPORT void
 ves_icall_System_Array_GetGenericValueImpl (MonoObject *this, guint32 pos, gpointer value)
 {
        MonoClass *ac;
@@ -800,7 +803,7 @@ ves_icall_System_Array_GetGenericValueImpl (MonoObject *this, guint32 pos, gpoin
        mono_gc_memmove (value, ea, esize);
 }
 
-static void
+ICALL_EXPORT void
 ves_icall_System_Array_SetGenericValueImpl (MonoObject *this, guint32 pos, gpointer value)
 {
        MonoClass *ac, *ec;
@@ -830,7 +833,7 @@ ves_icall_System_Array_SetGenericValueImpl (MonoObject *this, guint32 pos, gpoin
        }
 }
 
-static void
+ICALL_EXPORT void
 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_InitializeArray (MonoArray *array, MonoClassField *field_handle)
 {
        MonoClass *klass = array->obj.vtable->klass;
@@ -910,7 +913,7 @@ ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_InitializeArray (MonoAr
 #endif
 }
 
-static gint
+ICALL_EXPORT gint
 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetOffsetToStringData (void)
 {
        MONO_ARCH_SAVE_REGS;
@@ -918,7 +921,7 @@ ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetOffsetToStringData (
        return offsetof (MonoString, chars);
 }
 
-static MonoObject *
+ICALL_EXPORT MonoObject *
 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetObjectValue (MonoObject *obj)
 {
        MONO_ARCH_SAVE_REGS;
@@ -929,7 +932,7 @@ ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetObjectValue (MonoObj
                return mono_object_clone (obj);
 }
 
-static void
+ICALL_EXPORT void
 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_RunClassConstructor (MonoType *handle)
 {
        MonoClass *klass;
@@ -946,7 +949,7 @@ ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_RunClassConstructor (Mo
        mono_runtime_class_init (vtable);
 }
 
-static void
+ICALL_EXPORT void
 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_RunModuleConstructor (MonoImage *image)
 {
        MONO_ARCH_SAVE_REGS;
@@ -959,7 +962,7 @@ ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_RunModuleConstructor (M
        }
 }
 
-static MonoBoolean
+ICALL_EXPORT MonoBoolean
 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_SufficientExecutionStack (void)
 {
        guint8 *stack_addr;
@@ -982,7 +985,7 @@ ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_SufficientExecutionStac
        return TRUE;
 }
 
-static MonoObject *
+ICALL_EXPORT MonoObject *
 ves_icall_System_Object_MemberwiseClone (MonoObject *this)
 {
        MONO_ARCH_SAVE_REGS;
@@ -990,7 +993,7 @@ ves_icall_System_Object_MemberwiseClone (MonoObject *this)
        return mono_object_clone (this);
 }
 
-static gint32
+ICALL_EXPORT gint32
 ves_icall_System_ValueType_InternalGetHashCode (MonoObject *this, MonoArray **fields)
 {
        MonoClass *klass;
@@ -1050,7 +1053,7 @@ ves_icall_System_ValueType_InternalGetHashCode (MonoObject *this, MonoArray **fi
        return result;
 }
 
-static MonoBoolean
+ICALL_EXPORT MonoBoolean
 ves_icall_System_ValueType_Equals (MonoObject *this, MonoObject *that, MonoArray **fields)
 {
        MonoClass *klass;
@@ -1162,18 +1165,20 @@ ves_icall_System_ValueType_Equals (MonoObject *this, MonoObject *that, MonoArray
        }
 }
 
-static MonoReflectionType *
+ICALL_EXPORT MonoReflectionType *
 ves_icall_System_Object_GetType (MonoObject *obj)
 {
        MONO_ARCH_SAVE_REGS;
 
-       if (obj->vtable->klass != mono_defaults.transparent_proxy_class)
-               return mono_type_get_object (mono_object_domain (obj), &obj->vtable->klass->byval_arg);
-       else
+#ifndef DISABLE_REMOTING
+       if (obj->vtable->klass == mono_defaults.transparent_proxy_class)
                return mono_type_get_object (mono_object_domain (obj), &((MonoTransparentProxy*)obj)->remote_class->proxy_class->byval_arg);
+       else
+#endif
+               return mono_type_get_object (mono_object_domain (obj), &obj->vtable->klass->byval_arg);
 }
 
-static void
+ICALL_EXPORT void
 mono_type_type_from_obj (MonoReflectionType *mtype, MonoObject *obj)
 {
        MONO_ARCH_SAVE_REGS;
@@ -1182,7 +1187,7 @@ mono_type_type_from_obj (MonoReflectionType *mtype, MonoObject *obj)
        g_assert (mtype->type->type);
 }
 
-static gint32
+ICALL_EXPORT gint32
 ves_icall_ModuleBuilder_getToken (MonoReflectionModuleBuilder *mb, MonoObject *obj, gboolean create_open_instance)
 {
        MONO_ARCH_SAVE_REGS;
@@ -1192,7 +1197,7 @@ ves_icall_ModuleBuilder_getToken (MonoReflectionModuleBuilder *mb, MonoObject *o
        return mono_image_create_token (mb->dynamic_image, obj, create_open_instance, TRUE);
 }
 
-static gint32
+ICALL_EXPORT gint32
 ves_icall_ModuleBuilder_getMethodToken (MonoReflectionModuleBuilder *mb,
                                        MonoReflectionMethod *method,
                                        MonoArray *opt_param_types)
@@ -1205,7 +1210,7 @@ ves_icall_ModuleBuilder_getMethodToken (MonoReflectionModuleBuilder *mb,
                mb->dynamic_image, (MonoObject *) method, opt_param_types);
 }
 
-static void
+ICALL_EXPORT void
 ves_icall_ModuleBuilder_WriteToFile (MonoReflectionModuleBuilder *mb, HANDLE file)
 {
        MONO_ARCH_SAVE_REGS;
@@ -1213,7 +1218,7 @@ ves_icall_ModuleBuilder_WriteToFile (MonoReflectionModuleBuilder *mb, HANDLE fil
        mono_image_create_pefile (mb, file);
 }
 
-static void
+ICALL_EXPORT void
 ves_icall_ModuleBuilder_build_metadata (MonoReflectionModuleBuilder *mb)
 {
        MONO_ARCH_SAVE_REGS;
@@ -1221,7 +1226,7 @@ ves_icall_ModuleBuilder_build_metadata (MonoReflectionModuleBuilder *mb)
        mono_image_build_metadata (mb);
 }
 
-static void
+ICALL_EXPORT void
 ves_icall_ModuleBuilder_RegisterToken (MonoReflectionModuleBuilder *mb, MonoObject *obj, guint32 token)
 {
        MONO_ARCH_SAVE_REGS;
@@ -1371,7 +1376,7 @@ mono_type_get (const char *str)
 }
 #endif
 
-static MonoReflectionType*
+ICALL_EXPORT MonoReflectionType*
 ves_icall_type_from_name (MonoString *name,
                          MonoBoolean throwOnError,
                          MonoBoolean ignoreCase)
@@ -1396,7 +1401,7 @@ ves_icall_type_from_name (MonoString *name,
 }
 
 
-static MonoReflectionType*
+ICALL_EXPORT MonoReflectionType*
 ves_icall_type_from_handle (MonoType *handle)
 {
        MonoDomain *domain = mono_domain_get (); 
@@ -1406,7 +1411,7 @@ ves_icall_type_from_handle (MonoType *handle)
        return mono_type_get_object (domain, handle);
 }
 
-static MonoBoolean
+ICALL_EXPORT MonoBoolean
 ves_icall_System_Type_EqualsInternal (MonoReflectionType *type, MonoReflectionType *c)
 {
        MONO_ARCH_SAVE_REGS;
@@ -1439,7 +1444,7 @@ typedef enum {
        TYPECODE_STRING = 18
 } TypeCode;
 
-static guint32
+ICALL_EXPORT guint32
 ves_icall_type_GetTypeCodeInternal (MonoReflectionType *type)
 {
        int t = type->type->type;
@@ -1523,7 +1528,7 @@ handle_enum:
        return 0;
 }
 
-static guint32
+ICALL_EXPORT guint32
 ves_icall_type_is_subtype_of (MonoReflectionType *type, MonoReflectionType *c, MonoBoolean check_interfaces)
 {
        MonoDomain *domain; 
@@ -1578,7 +1583,7 @@ mono_type_get_underlying_type_ignore_byref (MonoType *type)
        return type;
 }
 
-static guint32
+ICALL_EXPORT guint32
 ves_icall_type_is_assignable_from (MonoReflectionType *type, MonoReflectionType *c)
 {
        MonoDomain *domain; 
@@ -1625,7 +1630,7 @@ ves_icall_type_is_assignable_from (MonoReflectionType *type, MonoReflectionType
        return mono_class_is_assignable_from (klass, klassc);
 }
 
-static guint32
+ICALL_EXPORT guint32
 ves_icall_type_IsInstanceOfType (MonoReflectionType *type, MonoObject *obj)
 {
        MonoClass *klass = mono_class_from_mono_type (type->type);
@@ -1633,15 +1638,15 @@ ves_icall_type_IsInstanceOfType (MonoReflectionType *type, MonoObject *obj)
        return mono_object_isinst (obj, klass) != NULL;
 }
 
-static guint32
+ICALL_EXPORT guint32
 ves_icall_get_attributes (MonoReflectionType *type)
 {
        MonoClass *klass = mono_class_from_mono_type (type->type);
        return klass->flags;
 }
 
-static MonoReflectionMarshal*
-ves_icall_System_Reflection_FieldInfo_GetUnmanagedMarshal (MonoReflectionField *field)
+ICALL_EXPORT MonoReflectionMarshalAsAttribute*
+ves_icall_System_Reflection_FieldInfo_get_marshal_info (MonoReflectionField *field)
 {
        MonoClass *klass = field->field->parent;
        MonoMarshalType *info;
@@ -1658,14 +1663,14 @@ ves_icall_System_Reflection_FieldInfo_GetUnmanagedMarshal (MonoReflectionField *
                        if (!info->fields [i].mspec)
                                return NULL;
                        else
-                               return mono_reflection_marshal_from_marshal_spec (field->object.vtable->domain, klass, info->fields [i].mspec);
+                               return mono_reflection_marshal_as_attribute_from_marshal_spec (field->object.vtable->domain, klass, info->fields [i].mspec);
                }
        }
 
        return NULL;
 }
 
-static MonoReflectionField*
+ICALL_EXPORT MonoReflectionField*
 ves_icall_System_Reflection_FieldInfo_internal_from_handle_type (MonoClassField *handle, MonoType *type)
 {
        gboolean found = FALSE;
@@ -1695,7 +1700,7 @@ ves_icall_System_Reflection_FieldInfo_internal_from_handle_type (MonoClassField
        return mono_field_get_object (mono_domain_get (), klass, handle);
 }
 
-static MonoArray*
+ICALL_EXPORT MonoArray*
 ves_icall_System_Reflection_FieldInfo_GetTypeModifiers (MonoReflectionField *field, MonoBoolean optional)
 {
        MonoError error;
@@ -1706,13 +1711,13 @@ ves_icall_System_Reflection_FieldInfo_GetTypeModifiers (MonoReflectionField *fie
        return type_array_from_modifiers (field->field->parent->image, type, optional);
 }
 
-static int
+ICALL_EXPORT int
 vell_icall_get_method_attributes (MonoMethod *method)
 {
        return method->flags;
 }
 
-static void
+ICALL_EXPORT void
 ves_icall_get_method_info (MonoMethod *method, MonoMethodInfo *info)
 {
        MonoError error;
@@ -1740,7 +1745,7 @@ ves_icall_get_method_info (MonoMethod *method, MonoMethodInfo *info)
        info->callconv |= (sig->hasthis << 5) | (sig->explicit_this << 6); 
 }
 
-static MonoArray*
+ICALL_EXPORT MonoArray*
 ves_icall_get_parameter_info (MonoMethod *method, MonoReflectionMethod *member)
 {
        MonoDomain *domain = mono_domain_get (); 
@@ -1748,11 +1753,11 @@ ves_icall_get_parameter_info (MonoMethod *method, MonoReflectionMethod *member)
        return mono_param_get_objects_internal (domain, method, member->reftype ? mono_class_from_mono_type (member->reftype->type) : NULL);
 }
 
-static MonoReflectionMarshal*
+ICALL_EXPORT MonoReflectionMarshalAsAttribute*
 ves_icall_System_MonoMethodInfo_get_retval_marshal (MonoMethod *method)
 {
        MonoDomain *domain = mono_domain_get (); 
-       MonoReflectionMarshal* res = NULL;
+       MonoReflectionMarshalAsAttribute* res = NULL;
        MonoMarshalSpec **mspecs;
        int i;
 
@@ -1760,7 +1765,7 @@ ves_icall_System_MonoMethodInfo_get_retval_marshal (MonoMethod *method)
        mono_method_get_marshal_info (method, mspecs);
 
        if (mspecs [0])
-               res = mono_reflection_marshal_from_marshal_spec (domain, method->klass, mspecs [0]);
+               res = mono_reflection_marshal_as_attribute_from_marshal_spec (domain, method->klass, mspecs [0]);
                
        for (i = mono_method_signature (method)->param_count; i >= 0; i--)
                if (mspecs [i])
@@ -1770,7 +1775,7 @@ ves_icall_System_MonoMethodInfo_get_retval_marshal (MonoMethod *method)
        return res;
 }
 
-static gint32
+ICALL_EXPORT gint32
 ves_icall_MonoField_GetFieldOffset (MonoReflectionField *field)
 {
        MonoClass *parent = field->field->parent;
@@ -1780,7 +1785,7 @@ ves_icall_MonoField_GetFieldOffset (MonoReflectionField *field)
        return field->field->offset - sizeof (MonoObject);
 }
 
-static MonoReflectionType*
+ICALL_EXPORT MonoReflectionType*
 ves_icall_MonoField_GetParentType (MonoReflectionField *field, MonoBoolean declaring)
 {
        MonoClass *parent;
@@ -1791,7 +1796,7 @@ ves_icall_MonoField_GetParentType (MonoReflectionField *field, MonoBoolean decla
        return mono_type_get_object (mono_object_domain (field), &parent->byval_arg);
 }
 
-static MonoObject *
+ICALL_EXPORT MonoObject *
 ves_icall_MonoField_GetValueInternal (MonoReflectionField *field, MonoObject *obj)
 {      
        MonoClass *fklass = field->klass;
@@ -1808,7 +1813,7 @@ ves_icall_MonoField_GetValueInternal (MonoReflectionField *field, MonoObject *ob
        return mono_field_get_value_object (domain, cf, obj);
 }
 
-static void
+ICALL_EXPORT void
 ves_icall_MonoField_SetValueInternal (MonoReflectionField *field, MonoObject *obj, MonoObject *value)
 {
        MonoError error;
@@ -1899,7 +1904,7 @@ ves_icall_MonoField_SetValueInternal (MonoReflectionField *field, MonoObject *ob
        }
 }
 
-static MonoObject *
+ICALL_EXPORT MonoObject *
 ves_icall_MonoField_GetRawConstantValue (MonoReflectionField *this)
 {      
        MonoObject *o = NULL;
@@ -1971,7 +1976,7 @@ ves_icall_MonoField_GetRawConstantValue (MonoReflectionField *this)
        return o;
 }
 
-static MonoReflectionType*
+ICALL_EXPORT MonoReflectionType*
 ves_icall_MonoField_ResolveType (MonoReflectionField *ref_field)
 {
        MonoError error;
@@ -1982,7 +1987,7 @@ ves_icall_MonoField_ResolveType (MonoReflectionField *ref_field)
        return mono_type_get_object (mono_object_domain (ref_field), type);
 }
 
-static MonoReflectionType*
+ICALL_EXPORT MonoReflectionType*
 ves_icall_MonoGenericMethod_get_ReflectedType (MonoReflectionGenericMethod *rmethod)
 {
        MonoMethod *method = rmethod->method.method;
@@ -2000,7 +2005,7 @@ typedef enum {
        PInfo_Name = 1 << 5
 } PInfo;
 
-static void
+ICALL_EXPORT void
 ves_icall_get_property_info (MonoReflectionProperty *property, MonoPropertyInfo *info, PInfo req_info)
 {
        MonoDomain *domain = mono_object_domain (property); 
@@ -2031,7 +2036,7 @@ ves_icall_get_property_info (MonoReflectionProperty *property, MonoPropertyInfo
         */
 }
 
-static void
+ICALL_EXPORT void
 ves_icall_get_event_info (MonoReflectionMonoEvent *event, MonoEventInfo *info)
 {
        MonoDomain *domain = mono_object_domain (event); 
@@ -2110,7 +2115,7 @@ fill_iface_array (gpointer key, gpointer value, gpointer user_data)
                mono_metadata_free_type (inflated);
 }
 
-static MonoArray*
+ICALL_EXPORT MonoArray*
 ves_icall_Type_GetInterfaces (MonoReflectionType* type)
 {
        MonoError error;
@@ -2160,7 +2165,7 @@ fail:
        return NULL;
 }
 
-static void
+ICALL_EXPORT void
 ves_icall_Type_GetInterfaceMapData (MonoReflectionType *type, MonoReflectionType *iface, MonoArray **targets, MonoArray **methods)
 {
        gboolean variance_used;
@@ -2197,7 +2202,7 @@ ves_icall_Type_GetInterfaceMapData (MonoReflectionType *type, MonoReflectionType
        }
 }
 
-static void
+ICALL_EXPORT void
 ves_icall_Type_GetPacking (MonoReflectionType *type, guint32 *packing, guint32 *size)
 {
        MonoClass *klass = mono_class_from_mono_type (type->type);
@@ -2212,7 +2217,7 @@ ves_icall_Type_GetPacking (MonoReflectionType *type, guint32 *packing, guint32 *
        }
 }
 
-static MonoReflectionType*
+ICALL_EXPORT MonoReflectionType*
 ves_icall_MonoType_GetElementType (MonoReflectionType *type)
 {
        MonoClass *class;
@@ -2237,14 +2242,14 @@ ves_icall_MonoType_GetElementType (MonoReflectionType *type)
                return NULL;
 }
 
-static MonoReflectionType*
+ICALL_EXPORT MonoReflectionType*
 ves_icall_get_type_parent (MonoReflectionType *type)
 {
        MonoClass *class = mono_class_from_mono_type (type->type);
        return class->parent ? mono_type_get_object (mono_object_domain (type), &class->parent->byval_arg): NULL;
 }
 
-static MonoBoolean
+ICALL_EXPORT MonoBoolean
 ves_icall_type_ispointer (MonoReflectionType *type)
 {
        MONO_ARCH_SAVE_REGS;
@@ -2252,7 +2257,7 @@ ves_icall_type_ispointer (MonoReflectionType *type)
        return type->type->type == MONO_TYPE_PTR;
 }
 
-static MonoBoolean
+ICALL_EXPORT MonoBoolean
 ves_icall_type_isprimitive (MonoReflectionType *type)
 {
        MONO_ARCH_SAVE_REGS;
@@ -2260,7 +2265,7 @@ ves_icall_type_isprimitive (MonoReflectionType *type)
        return (!type->type->byref && (((type->type->type >= MONO_TYPE_BOOLEAN) && (type->type->type <= MONO_TYPE_R8)) || (type->type->type == MONO_TYPE_I) || (type->type->type == MONO_TYPE_U)));
 }
 
-static MonoBoolean
+ICALL_EXPORT MonoBoolean
 ves_icall_type_isbyref (MonoReflectionType *type)
 {
        MONO_ARCH_SAVE_REGS;
@@ -2268,7 +2273,7 @@ ves_icall_type_isbyref (MonoReflectionType *type)
        return type->type->byref;
 }
 
-static MonoBoolean
+ICALL_EXPORT MonoBoolean
 ves_icall_type_iscomobject (MonoReflectionType *type)
 {
        MonoClass *klass = mono_class_from_mono_type (type->type);
@@ -2277,14 +2282,14 @@ ves_icall_type_iscomobject (MonoReflectionType *type)
        return (klass && klass->is_com_object);
 }
 
-static MonoReflectionModule*
+ICALL_EXPORT MonoReflectionModule*
 ves_icall_MonoType_get_Module (MonoReflectionType *type)
 {
        MonoClass *class = mono_class_from_mono_type (type->type);
        return mono_module_get_object (mono_object_domain (type), class->image);
 }
 
-static MonoReflectionAssembly*
+ICALL_EXPORT MonoReflectionAssembly*
 ves_icall_MonoType_get_Assembly (MonoReflectionType *type)
 {
        MonoDomain *domain = mono_domain_get (); 
@@ -2292,7 +2297,7 @@ ves_icall_MonoType_get_Assembly (MonoReflectionType *type)
        return mono_assembly_get_object (domain, class->image->assembly);
 }
 
-static MonoReflectionType*
+ICALL_EXPORT MonoReflectionType*
 ves_icall_MonoType_get_DeclaringType (MonoReflectionType *type)
 {
        MonoDomain *domain = mono_domain_get ();
@@ -2312,7 +2317,7 @@ ves_icall_MonoType_get_DeclaringType (MonoReflectionType *type)
        return class ? mono_type_get_object (domain, &class->byval_arg) : NULL;
 }
 
-static MonoString*
+ICALL_EXPORT MonoString*
 ves_icall_MonoType_get_Name (MonoReflectionType *type)
 {
        MonoDomain *domain = mono_domain_get (); 
@@ -2330,7 +2335,7 @@ ves_icall_MonoType_get_Name (MonoReflectionType *type)
        }
 }
 
-static MonoString*
+ICALL_EXPORT MonoString*
 ves_icall_MonoType_get_Namespace (MonoReflectionType *type)
 {
        MonoDomain *domain = mono_domain_get (); 
@@ -2345,7 +2350,7 @@ ves_icall_MonoType_get_Namespace (MonoReflectionType *type)
                return mono_string_new (domain, class->name_space);
 }
 
-static gint32
+ICALL_EXPORT gint32
 ves_icall_MonoType_GetArrayRank (MonoReflectionType *type)
 {
        MonoClass *class;
@@ -2358,7 +2363,7 @@ ves_icall_MonoType_GetArrayRank (MonoReflectionType *type)
        return class->rank;
 }
 
-static MonoArray*
+ICALL_EXPORT MonoArray*
 ves_icall_MonoType_GetGenericArguments (MonoReflectionType *type)
 {
        MonoArray *res;
@@ -2388,7 +2393,7 @@ ves_icall_MonoType_GetGenericArguments (MonoReflectionType *type)
        return res;
 }
 
-static gboolean
+ICALL_EXPORT gboolean
 ves_icall_Type_get_IsGenericTypeDefinition (MonoReflectionType *type)
 {
        MonoClass *klass;
@@ -2404,7 +2409,7 @@ ves_icall_Type_get_IsGenericTypeDefinition (MonoReflectionType *type)
        return klass->generic_container != NULL;
 }
 
-static MonoReflectionType*
+ICALL_EXPORT MonoReflectionType*
 ves_icall_Type_GetGenericTypeDefinition_impl (MonoReflectionType *type)
 {
        MonoClass *klass;
@@ -2432,7 +2437,7 @@ ves_icall_Type_GetGenericTypeDefinition_impl (MonoReflectionType *type)
        return NULL;
 }
 
-static MonoReflectionType*
+ICALL_EXPORT MonoReflectionType*
 ves_icall_Type_MakeGenericType (MonoReflectionType *type, MonoArray *type_array)
 {
        MonoClass *class;
@@ -2464,7 +2469,7 @@ ves_icall_Type_MakeGenericType (MonoReflectionType *type, MonoArray *type_array)
        return mono_type_get_object (mono_object_domain (type), geninst);
 }
 
-static gboolean
+ICALL_EXPORT gboolean
 ves_icall_Type_get_IsGenericInstance (MonoReflectionType *type)
 {
        MonoClass *klass;
@@ -2478,7 +2483,7 @@ ves_icall_Type_get_IsGenericInstance (MonoReflectionType *type)
        return klass->generic_class != NULL;
 }
 
-static gboolean
+ICALL_EXPORT gboolean
 ves_icall_Type_get_IsGenericType (MonoReflectionType *type)
 {
        MonoClass *klass;
@@ -2494,7 +2499,7 @@ ves_icall_Type_get_IsGenericType (MonoReflectionType *type)
        return klass->generic_class != NULL || klass->generic_container != NULL;
 }
 
-static gint32
+ICALL_EXPORT gint32
 ves_icall_Type_GetGenericParameterPosition (MonoReflectionType *type)
 {
        MONO_ARCH_SAVE_REGS;
@@ -2507,7 +2512,7 @@ ves_icall_Type_GetGenericParameterPosition (MonoReflectionType *type)
        return -1;
 }
 
-static GenericParameterAttributes
+ICALL_EXPORT GenericParameterAttributes
 ves_icall_Type_GetGenericParameterAttributes (MonoReflectionType *type)
 {
        MONO_ARCH_SAVE_REGS;
@@ -2517,7 +2522,7 @@ ves_icall_Type_GetGenericParameterAttributes (MonoReflectionType *type)
        return mono_generic_param_info (type->type->data.generic_param)->flags;
 }
 
-static MonoArray *
+ICALL_EXPORT MonoArray *
 ves_icall_Type_GetGenericParameterConstraints (MonoReflectionType *type)
 {
        MonoGenericParamInfo *param_info;
@@ -2543,28 +2548,28 @@ ves_icall_Type_GetGenericParameterConstraints (MonoReflectionType *type)
        return res;
 }
 
-static MonoBoolean
+ICALL_EXPORT MonoBoolean
 ves_icall_MonoType_get_IsGenericParameter (MonoReflectionType *type)
 {
        MONO_ARCH_SAVE_REGS;
        return is_generic_parameter (type->type);
 }
 
-static MonoBoolean
+ICALL_EXPORT MonoBoolean
 ves_icall_TypeBuilder_get_IsGenericParameter (MonoReflectionTypeBuilder *tb)
 {
        MONO_ARCH_SAVE_REGS;
        return is_generic_parameter (tb->type.type);
 }
 
-static void
+ICALL_EXPORT void
 ves_icall_EnumBuilder_setup_enum_type (MonoReflectionType *enumtype,
                                                                           MonoReflectionType *t)
 {
        enumtype->type = t->type;
 }
 
-static MonoReflectionMethod*
+ICALL_EXPORT MonoReflectionMethod*
 ves_icall_MonoType_GetCorrespondingInflatedMethod (MonoReflectionType *type, 
                                                    MonoReflectionMethod* generic)
 {
@@ -2591,7 +2596,7 @@ ves_icall_MonoType_GetCorrespondingInflatedMethod (MonoReflectionType *type,
 
 
 
-static MonoReflectionMethod *
+ICALL_EXPORT MonoReflectionMethod *
 ves_icall_MonoType_get_DeclaringMethod (MonoReflectionType *ref_type)
 {
        MonoMethod *method;
@@ -2609,7 +2614,7 @@ ves_icall_MonoType_get_DeclaringMethod (MonoReflectionType *ref_type)
        return mono_method_get_object (mono_object_domain (ref_type), method, method->klass);
 }
 
-static MonoReflectionDllImportAttribute*
+ICALL_EXPORT MonoReflectionDllImportAttribute*
 ves_icall_MonoMethod_GetDllImportAttribute (MonoMethod *method)
 {
        static MonoClass *DllImportAttributeClass = NULL;
@@ -2679,7 +2684,7 @@ ves_icall_MonoMethod_GetDllImportAttribute (MonoMethod *method)
        return attr;
 }
 
-static MonoReflectionMethod *
+ICALL_EXPORT MonoReflectionMethod *
 ves_icall_MonoMethod_GetGenericMethodDefinition (MonoReflectionMethod *method)
 {
        MonoMethodInflated *imethod;
@@ -2726,7 +2731,7 @@ ves_icall_MonoMethod_GetGenericMethodDefinition (MonoReflectionMethod *method)
        return mono_method_get_object (mono_object_domain (method), result, NULL);
 }
 
-static gboolean
+ICALL_EXPORT gboolean
 ves_icall_MonoMethod_get_IsGenericMethod (MonoReflectionMethod *method)
 {
        MONO_ARCH_SAVE_REGS;
@@ -2734,7 +2739,7 @@ ves_icall_MonoMethod_get_IsGenericMethod (MonoReflectionMethod *method)
        return mono_method_signature (method->method)->generic_param_count != 0;
 }
 
-static gboolean
+ICALL_EXPORT gboolean
 ves_icall_MonoMethod_get_IsGenericMethodDefinition (MonoReflectionMethod *method)
 {
        MONO_ARCH_SAVE_REGS;
@@ -2742,7 +2747,7 @@ ves_icall_MonoMethod_get_IsGenericMethodDefinition (MonoReflectionMethod *method
        return method->method->is_generic;
 }
 
-static MonoArray*
+ICALL_EXPORT MonoArray*
 ves_icall_MonoMethod_GetGenericArguments (MonoReflectionMethod *method)
 {
        MonoArray *res;
@@ -2781,7 +2786,7 @@ ves_icall_MonoMethod_GetGenericArguments (MonoReflectionMethod *method)
        return res;
 }
 
-static MonoObject *
+ICALL_EXPORT MonoObject *
 ves_icall_InternalInvoke (MonoReflectionMethod *method, MonoObject *this, MonoArray *params, MonoException **exc) 
 {
        /* 
@@ -2790,6 +2795,7 @@ ves_icall_InternalInvoke (MonoReflectionMethod *method, MonoObject *this, MonoAr
         * greater flexibility.
         */
        MonoMethod *m = method->method;
+       MonoMethodSignature *sig = mono_method_signature (m);
        int pcount;
        void *obj = this;
 
@@ -2808,7 +2814,13 @@ ves_icall_InternalInvoke (MonoReflectionMethod *method, MonoObject *this, MonoAr
 
                if (this) {
                        if (!mono_object_isinst (this, m->klass)) {
-                               mono_gc_wbarrier_generic_store (exc, (MonoObject*) mono_exception_from_name_msg (mono_defaults.corlib, "System.Reflection", "TargetException", "Object does not match target type."));
+                               char *this_name = mono_type_get_full_name (mono_object_get_class (this));
+                               char *target_name = mono_type_get_full_name (m->klass);
+                               char *msg = g_strdup_printf ("Object of type '%s' doesn't match target type '%s'", this_name, target_name);
+                               mono_gc_wbarrier_generic_store (exc, (MonoObject*) mono_exception_from_name_msg (mono_defaults.corlib, "System.Reflection", "TargetException", msg));
+                               g_free (msg);
+                               g_free (target_name);
+                               g_free (this_name);
                                return NULL;
                        }
                        m = mono_object_get_virtual_method (this, m);
@@ -2821,8 +2833,13 @@ ves_icall_InternalInvoke (MonoReflectionMethod *method, MonoObject *this, MonoAr
                }
        }
 
+       if (sig->ret->byref) {
+               mono_gc_wbarrier_generic_store (exc, (MonoObject*) mono_exception_from_name_msg (mono_defaults.corlib, "System", "NotSupportedException", "Cannot invoke method returning ByRef type via reflection"));
+               return NULL;
+       }
+
        pcount = params? mono_array_length (params): 0;
-       if (pcount != mono_method_signature (m)->param_count) {
+       if (pcount != sig->param_count) {
                mono_gc_wbarrier_generic_store (exc, (MonoObject*) mono_exception_from_name (mono_defaults.corlib, "System.Reflection", "TargetParameterCountException"));
                return NULL;
        }
@@ -2862,7 +2879,8 @@ ves_icall_InternalInvoke (MonoReflectionMethod *method, MonoObject *this, MonoAr
        return mono_runtime_invoke_array (m, obj, params, NULL);
 }
 
-static MonoObject *
+#ifndef DISABLE_REMOTING
+ICALL_EXPORT MonoObject *
 ves_icall_InternalExecute (MonoReflectionMethod *method, MonoObject *this, MonoArray *params, MonoArray **outArgs) 
 {
        MonoDomain *domain = mono_object_domain (method); 
@@ -2989,6 +3007,7 @@ ves_icall_InternalExecute (MonoReflectionMethod *method, MonoObject *this, MonoA
 
        return result;
 }
+#endif
 
 static guint64
 read_enum_value (char *mem, int type)
@@ -3050,7 +3069,7 @@ write_enum_value (char *mem, int type, guint64 value)
        return;
 }
 
-static MonoObject *
+ICALL_EXPORT MonoObject *
 ves_icall_System_Enum_ToObject (MonoReflectionType *enumType, MonoObject *value)
 {
        MonoDomain *domain; 
@@ -3088,7 +3107,7 @@ ves_icall_System_Enum_ToObject (MonoReflectionType *enumType, MonoObject *value)
        return res;
 }
 
-static MonoObject *
+ICALL_EXPORT MonoObject *
 ves_icall_System_Enum_get_value (MonoObject *this)
 {
        MonoObject *res;
@@ -3115,7 +3134,7 @@ ves_icall_System_Enum_get_value (MonoObject *this)
        return res;
 }
 
-static MonoReflectionType *
+ICALL_EXPORT MonoReflectionType *
 ves_icall_System_Enum_get_underlying_type (MonoReflectionType *type)
 {
        MonoType *etype;
@@ -3134,7 +3153,7 @@ ves_icall_System_Enum_get_underlying_type (MonoReflectionType *type)
        return mono_type_get_object (mono_object_domain (type), etype);
 }
 
-static int
+ICALL_EXPORT int
 ves_icall_System_Enum_compare_value_to (MonoObject *this, MonoObject *other)
 {
        gpointer tdata = (char *)this + sizeof (MonoObject);
@@ -3184,7 +3203,7 @@ ves_icall_System_Enum_compare_value_to (MonoObject *this, MonoObject *other)
        return 0;
 }
 
-static int
+ICALL_EXPORT int
 ves_icall_System_Enum_get_hashcode (MonoObject *this)
 {
        gpointer data = (char *)this + sizeof (MonoObject);
@@ -3217,7 +3236,7 @@ ves_icall_System_Enum_get_hashcode (MonoObject *this)
        return 0;
 }
 
-static void
+ICALL_EXPORT void
 ves_icall_get_enum_info (MonoReflectionType *type, MonoEnumInfo *info)
 {
        MonoDomain *domain = mono_object_domain (type); 
@@ -3296,7 +3315,7 @@ enum {
        BFLAGS_OptionalParamBinding = 0x40000
 };
 
-static MonoReflectionField *
+ICALL_EXPORT MonoReflectionField *
 ves_icall_Type_GetField (MonoReflectionType *type, MonoString *name, guint32 bflags)
 {
        MonoDomain *domain; 
@@ -3366,7 +3385,7 @@ handle_parent:
        return NULL;
 }
 
-static MonoArray*
+ICALL_EXPORT MonoArray*
 ves_icall_Type_GetFields_internal (MonoReflectionType *type, guint32 bflags, MonoReflectionType *reftype)
 {
        MonoDomain *domain; 
@@ -3453,66 +3472,42 @@ method_nonpublic (MonoMethod* method, gboolean start_klass)
        }
 }
 
-static MonoArray*
-ves_icall_Type_GetMethodsByName (MonoReflectionType *type, MonoString *name, guint32 bflags, MonoBoolean ignore_case, MonoReflectionType *reftype)
+GPtrArray*
+mono_class_get_methods_by_name (MonoClass *klass, const char *name, guint32 bflags, gboolean ignore_case, gboolean allow_ctors, MonoException **ex)
 {
-       static MonoClass *MethodInfo_array;
-       MonoDomain *domain; 
-       MonoClass *startklass, *klass, *refklass;
-       MonoArray *res;
+       GPtrArray *array;
+       MonoClass *startklass;
        MonoMethod *method;
        gpointer iter;
-       MonoObject *member;
-       int i, len, match, nslots;
+       int len, match, nslots;
        /*FIXME, use MonoBitSet*/
        guint32 method_slots_default [8];
        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_ptr_array_init (tmp_array, 4);
-
-       if (!MethodInfo_array) {
-               MonoClass *klass = mono_array_class_get (mono_defaults.method_info_class, 1);
-               mono_memory_barrier ();
-               MethodInfo_array = klass;
-       }
-
-       domain = ((MonoObject *)type)->vtable->domain;
-       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);
-       refklass = mono_class_from_mono_type (reftype->type);
+       array = g_ptr_array_new ();
+       startklass = klass;
+       *ex = NULL;
 
        len = 0;
-       if (name != NULL) {
-               mname = mono_string_to_utf8 (name);
+       if (name != NULL)
                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))) {
+       if (klass->delegate && name && !strcmp (name, "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);
-               return res;
+               g_ptr_array_add (array, method);
+               return array;
        }
 
        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))
+       if (is_generic_parameter (&klass->byval_arg))
                nslots = mono_class_get_vtable_size (klass->parent);
        else
                nslots = MONO_CLASS_IS_INTERFACE (klass) ? mono_class_num_methods (klass) : mono_class_get_vtable_size (klass);
@@ -3538,7 +3533,7 @@ handle_parent:
                                method_slots [method->slot >> 5] |= 1 << (method->slot & 0x1f);
                }
 
-               if (method->name [0] == '.' && (strcmp (method->name, ".ctor") == 0 || strcmp (method->name, ".cctor") == 0))
+               if (!allow_ctors && method->name [0] == '.' && (strcmp (method->name, ".ctor") == 0 || strcmp (method->name, ".cctor") == 0))
                        continue;
                if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
                        if (bflags & BFLAGS_Public)
@@ -3562,47 +3557,81 @@ handle_parent:
                        continue;
 
                if (name != NULL) {
-                       if (compare_func (mname, method->name))
+                       if (compare_func (name, method->name))
                                continue;
                }
                
                match = 0;
-               
-               member = (MonoObject*)mono_method_get_object (domain, method, refklass);
-               
-               mono_ptr_array_append (tmp_array, member);
+               g_ptr_array_add (array, method);
        }
        if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
                goto handle_parent;
-
-       g_free (mname);
        if (method_slots != method_slots_default)
                g_free (method_slots);
 
-       res = mono_array_new_specific (array_vtable, mono_ptr_array_size (tmp_array));
-
-       for (i = 0; i < mono_ptr_array_size (tmp_array); ++i)
-               mono_array_setref (res, i, mono_ptr_array_get (tmp_array, i));
-
-       mono_ptr_array_destroy (tmp_array);
-       return res;
+       return array;
 
 loader_error:
-       g_free (mname);
        if (method_slots != method_slots_default)
                g_free (method_slots);
-       mono_ptr_array_destroy (tmp_array);
+       g_ptr_array_free (array, TRUE);
+
        if (klass->exception_type != MONO_EXCEPTION_NONE) {
-               ex = mono_class_get_exception_for_failure (klass);
+               *ex = mono_class_get_exception_for_failure (klass);
        } else {
-               ex = mono_loader_error_prepare_exception (mono_loader_get_last_error ());
+               *ex = mono_loader_error_prepare_exception (mono_loader_get_last_error ());
                mono_loader_clear_error ();
        }
-       mono_raise_exception (ex);
        return NULL;
 }
 
-static MonoArray*
+ICALL_EXPORT MonoArray*
+ves_icall_Type_GetMethodsByName (MonoReflectionType *type, MonoString *name, guint32 bflags, MonoBoolean ignore_case, MonoReflectionType *reftype)
+{
+       static MonoClass *MethodInfo_array;
+       MonoDomain *domain; 
+       MonoArray *res;
+       MonoVTable *array_vtable;
+       MonoException *ex = NULL;
+       const char *mname = NULL;
+       GPtrArray *method_array;
+       MonoClass *klass, *refklass;
+       int i;
+
+       if (!MethodInfo_array) {
+               MonoClass *klass = mono_array_class_get (mono_defaults.method_info_class, 1);
+               mono_memory_barrier ();
+               MethodInfo_array = klass;
+       }
+
+       klass = mono_class_from_mono_type (type->type);
+       refklass = mono_class_from_mono_type (reftype->type);
+       domain = ((MonoObject *)type)->vtable->domain;
+       array_vtable = mono_class_vtable_full (domain, MethodInfo_array, TRUE);
+       if (type->type->byref)
+               return mono_array_new_specific (array_vtable, 0);
+
+       if (name)
+               mname = mono_string_to_utf8 (name);
+
+       method_array = mono_class_get_methods_by_name (klass, mname, bflags, ignore_case, FALSE, &ex);
+       g_free ((char*)mname);
+       if (ex)
+               mono_raise_exception (ex);
+
+       res = mono_array_new_specific (array_vtable, method_array->len);
+
+
+       for (i = 0; i < method_array->len; ++i) {
+               MonoMethod *method = g_ptr_array_index (method_array, i);
+               mono_array_setref (res, i, mono_method_get_object (domain, method, refklass));
+       }
+
+       g_ptr_array_free (method_array, TRUE);
+       return res;
+}
+
+ICALL_EXPORT MonoArray*
 ves_icall_Type_GetConstructors_internal (MonoReflectionType *type, guint32 bflags, MonoReflectionType *reftype)
 {
        MonoDomain *domain; 
@@ -3701,7 +3730,7 @@ property_accessor_nonpublic (MonoMethod* accessor, gboolean start_klass)
        return method_nonpublic (accessor, start_klass);
 }
 
-static MonoArray*
+ICALL_EXPORT MonoArray*
 ves_icall_Type_GetPropertiesByName (MonoReflectionType *type, MonoString *name, guint32 bflags, MonoBoolean ignore_case, MonoReflectionType *reftype)
 {
        MonoException *ex;
@@ -3822,7 +3851,7 @@ loader_error:
        return NULL;
 }
 
-static MonoReflectionEvent *
+ICALL_EXPORT MonoReflectionEvent *
 ves_icall_MonoType_GetEvent (MonoReflectionType *type, MonoString *name, guint32 bflags)
 {
        MonoDomain *domain;
@@ -3893,7 +3922,7 @@ handle_parent:
        return NULL;
 }
 
-static MonoArray*
+ICALL_EXPORT MonoArray*
 ves_icall_Type_GetEvents_internal (MonoReflectionType *type, guint32 bflags, MonoReflectionType *reftype)
 {
        MonoException *ex;
@@ -3990,7 +4019,7 @@ loader_error:
        return NULL;
 }
 
-static MonoReflectionType *
+ICALL_EXPORT MonoReflectionType *
 ves_icall_Type_GetNestedType (MonoReflectionType *type, MonoString *name, guint32 bflags)
 {
        MonoDomain *domain; 
@@ -4050,7 +4079,7 @@ ves_icall_Type_GetNestedType (MonoReflectionType *type, MonoString *name, guint3
        return NULL;
 }
 
-static MonoArray*
+ICALL_EXPORT MonoArray*
 ves_icall_Type_GetNestedTypes (MonoReflectionType *type, guint32 bflags)
 {
        MonoDomain *domain; 
@@ -4108,7 +4137,7 @@ ves_icall_Type_GetNestedTypes (MonoReflectionType *type, guint32 bflags)
        return res;
 }
 
-static MonoReflectionType*
+ICALL_EXPORT MonoReflectionType*
 ves_icall_System_Reflection_Assembly_InternalGetType (MonoReflectionAssembly *assembly, MonoReflectionModule *module, MonoString *name, MonoBoolean throwOnError, MonoBoolean ignoreCase)
 {
        gchar *str;
@@ -4250,7 +4279,7 @@ replace_shadow_path (MonoDomain *domain, gchar *dirname, gchar **filename)
        return FALSE;
 }
 
-static MonoString *
+ICALL_EXPORT MonoString *
 ves_icall_System_Reflection_Assembly_get_code_base (MonoReflectionAssembly *assembly, MonoBoolean escaped)
 {
        MonoDomain *domain = mono_object_domain (assembly); 
@@ -4302,7 +4331,7 @@ ves_icall_System_Reflection_Assembly_get_code_base (MonoReflectionAssembly *asse
        return res;
 }
 
-static MonoBoolean
+ICALL_EXPORT MonoBoolean
 ves_icall_System_Reflection_Assembly_get_global_assembly_cache (MonoReflectionAssembly *assembly)
 {
        MonoAssembly *mass = assembly->assembly;
@@ -4312,7 +4341,7 @@ ves_icall_System_Reflection_Assembly_get_global_assembly_cache (MonoReflectionAs
        return mass->in_gac;
 }
 
-static MonoReflectionAssembly*
+ICALL_EXPORT MonoReflectionAssembly*
 ves_icall_System_Reflection_Assembly_load_with_partial_name (MonoString *mname, MonoObject *evidence)
 {
        gchar *name;
@@ -4331,7 +4360,7 @@ ves_icall_System_Reflection_Assembly_load_with_partial_name (MonoString *mname,
        return mono_assembly_get_object (mono_domain_get (), res);
 }
 
-static MonoString *
+ICALL_EXPORT MonoString *
 ves_icall_System_Reflection_Assembly_get_location (MonoReflectionAssembly *assembly)
 {
        MonoDomain *domain = mono_object_domain (assembly); 
@@ -4344,7 +4373,7 @@ ves_icall_System_Reflection_Assembly_get_location (MonoReflectionAssembly *assem
        return res;
 }
 
-static MonoBoolean
+ICALL_EXPORT MonoBoolean
 ves_icall_System_Reflection_Assembly_get_ReflectionOnly (MonoReflectionAssembly *assembly)
 {
        MONO_ARCH_SAVE_REGS;
@@ -4352,7 +4381,7 @@ ves_icall_System_Reflection_Assembly_get_ReflectionOnly (MonoReflectionAssembly
        return assembly->assembly->ref_only;
 }
 
-static MonoString *
+ICALL_EXPORT MonoString *
 ves_icall_System_Reflection_Assembly_InternalImageRuntimeVersion (MonoReflectionAssembly *assembly)
 {
        MonoDomain *domain = mono_object_domain (assembly); 
@@ -4362,7 +4391,7 @@ ves_icall_System_Reflection_Assembly_InternalImageRuntimeVersion (MonoReflection
        return mono_string_new (domain, assembly->assembly->image->version);
 }
 
-static MonoReflectionMethod*
+ICALL_EXPORT MonoReflectionMethod*
 ves_icall_System_Reflection_Assembly_get_EntryPoint (MonoReflectionAssembly *assembly) 
 {
        guint32 token = mono_image_get_entry_point (assembly->assembly->image);
@@ -4374,13 +4403,13 @@ ves_icall_System_Reflection_Assembly_get_EntryPoint (MonoReflectionAssembly *ass
        return mono_method_get_object (mono_object_domain (assembly), mono_get_method (assembly->assembly->image, token, NULL), NULL);
 }
 
-static MonoReflectionModule*
+ICALL_EXPORT MonoReflectionModule*
 ves_icall_System_Reflection_Assembly_GetManifestModuleInternal (MonoReflectionAssembly *assembly) 
 {
        return mono_module_get_object (mono_object_domain (assembly), assembly->assembly->image);
 }
 
-static MonoArray*
+ICALL_EXPORT MonoArray*
 ves_icall_System_Reflection_Assembly_GetManifestResourceNames (MonoReflectionAssembly *assembly) 
 {
        MonoTableInfo *table = &assembly->assembly->image->tables [MONO_TABLE_MANIFESTRESOURCE];
@@ -4427,7 +4456,7 @@ create_version (MonoDomain *domain, guint32 major, guint32 minor, guint32 build,
        return result;
 }
 
-static MonoArray*
+ICALL_EXPORT MonoArray*
 ves_icall_System_Reflection_Assembly_GetReferencedAssemblies (MonoReflectionAssembly *assembly) 
 {
        static MonoClass *System_Reflection_AssemblyName;
@@ -4510,53 +4539,6 @@ ves_icall_System_Reflection_Assembly_GetReferencedAssemblies (MonoReflectionAsse
        return result;
 }
 
-typedef struct {
-       MonoArray *res;
-       int idx;
-} NameSpaceInfo;
-
-static void
-foreach_namespace (const char* key, gconstpointer val, NameSpaceInfo *info)
-{
-       MonoString *name = mono_string_new (mono_object_domain (info->res), key);
-
-       mono_array_setref (info->res, info->idx, name);
-       info->idx++;
-}
-
-static MonoArray*
-ves_icall_System_Reflection_Assembly_GetNamespaces (MonoReflectionAssembly *assembly) 
-{
-       MonoImage *img = assembly->assembly->image;
-       MonoArray *res;
-       NameSpaceInfo info;
-       int len;
-
-       MONO_ARCH_SAVE_REGS;
-
-       mono_image_lock (img);
-       mono_image_init_name_cache (img);
-
-RETRY_LEN:
-       len = g_hash_table_size (img->name_cache);
-       mono_image_unlock (img);
-
-       /*we can't create objects holding the image lock */
-       res = mono_array_new (mono_object_domain (assembly), mono_defaults.string_class, len);
-
-       mono_image_lock (img);
-       /*len might have changed, create a new array*/
-       if (len != g_hash_table_size (img->name_cache))
-               goto RETRY_LEN;
-
-       info.res = res;
-       info.idx = 0;
-       g_hash_table_foreach (img->name_cache, (GHFunc)foreach_namespace, &info);
-       mono_image_unlock (img);
-
-       return res;
-}
-
 /* move this in some file in mono/util/ */
 static char *
 g_concat_dir_and_file (const char *dir, const char *file)
@@ -4574,7 +4556,7 @@ g_concat_dir_and_file (const char *dir, const char *file)
                return g_strconcat (dir, file, NULL);
 }
 
-static void *
+ICALL_EXPORT void *
 ves_icall_System_Reflection_Assembly_GetManifestResourceInternal (MonoReflectionAssembly *assembly, MonoString *name, gint32 *size, MonoReflectionModule **ref_module) 
 {
        char *n = mono_string_to_utf8 (name);
@@ -4618,7 +4600,7 @@ ves_icall_System_Reflection_Assembly_GetManifestResourceInternal (MonoReflection
        return (void*)mono_image_get_resource (module, cols [MONO_MANIFEST_OFFSET], (guint32*)size);
 }
 
-static gboolean
+ICALL_EXPORT gboolean
 ves_icall_System_Reflection_Assembly_GetManifestResourceInfoInternal (MonoReflectionAssembly *assembly, MonoString *name, MonoManifestResourceInfo *info)
 {
        MonoTableInfo *table = &assembly->assembly->image->tables [MONO_TABLE_MANIFESTRESOURCE];
@@ -4683,7 +4665,7 @@ ves_icall_System_Reflection_Assembly_GetManifestResourceInfoInternal (MonoReflec
        return TRUE;
 }
 
-static MonoObject*
+ICALL_EXPORT MonoObject*
 ves_icall_System_Reflection_Assembly_GetFilesInternal (MonoReflectionAssembly *assembly, MonoString *name, MonoBoolean resource_modules) 
 {
        MonoTableInfo *table = &assembly->assembly->image->tables [MONO_TABLE_FILE];
@@ -4733,7 +4715,7 @@ ves_icall_System_Reflection_Assembly_GetFilesInternal (MonoReflectionAssembly *a
        return (MonoObject*)result;
 }
 
-static MonoArray*
+ICALL_EXPORT MonoArray*
 ves_icall_System_Reflection_Assembly_GetModulesInternal (MonoReflectionAssembly *assembly)
 {
        MonoDomain *domain = mono_domain_get();
@@ -4788,7 +4770,7 @@ ves_icall_System_Reflection_Assembly_GetModulesInternal (MonoReflectionAssembly
        return res;
 }
 
-static MonoReflectionMethod*
+ICALL_EXPORT MonoReflectionMethod*
 ves_icall_GetCurrentMethod (void) 
 {
        MonoMethod *m = mono_method_get_last_managed ();
@@ -4833,7 +4815,7 @@ mono_method_get_equivalent_method (MonoMethod *method, MonoClass *klass)
        return klass->methods [offset];
 }
 
-static MonoReflectionMethod*
+ICALL_EXPORT MonoReflectionMethod*
 ves_icall_System_Reflection_MethodBase_GetMethodFromHandleInternalType (MonoMethod *method, MonoType *type)
 {
        MonoClass *klass;
@@ -4851,19 +4833,19 @@ ves_icall_System_Reflection_MethodBase_GetMethodFromHandleInternalType (MonoMeth
        return mono_method_get_object (mono_domain_get (), method, klass);
 }
 
-static MonoReflectionMethod*
+ICALL_EXPORT MonoReflectionMethod*
 ves_icall_System_Reflection_MethodBase_GetMethodFromHandleInternal (MonoMethod *method)
 {
        return mono_method_get_object (mono_domain_get (), method, NULL);
 }
 
-static MonoReflectionMethodBody*
+ICALL_EXPORT MonoReflectionMethodBody*
 ves_icall_System_Reflection_MethodBase_GetMethodBodyInternal (MonoMethod *method)
 {
        return mono_method_body_get_object (mono_domain_get (), method);
 }
 
-static MonoReflectionAssembly*
+ICALL_EXPORT MonoReflectionAssembly*
 ves_icall_System_Reflection_Assembly_GetExecutingAssembly (void)
 {
        MonoMethod *dest = NULL;
@@ -4875,7 +4857,7 @@ ves_icall_System_Reflection_Assembly_GetExecutingAssembly (void)
 }
 
 
-static MonoReflectionAssembly*
+ICALL_EXPORT MonoReflectionAssembly*
 ves_icall_System_Reflection_Assembly_GetEntryAssembly (void)
 {
        MonoDomain* domain = mono_domain_get ();
@@ -4888,7 +4870,7 @@ ves_icall_System_Reflection_Assembly_GetEntryAssembly (void)
        return mono_assembly_get_object (domain, domain->entry_assembly);
 }
 
-static MonoReflectionAssembly*
+ICALL_EXPORT MonoReflectionAssembly*
 ves_icall_System_Reflection_Assembly_GetCallingAssembly (void)
 {
        MonoMethod *m;
@@ -4905,7 +4887,7 @@ ves_icall_System_Reflection_Assembly_GetCallingAssembly (void)
        return mono_assembly_get_object (mono_domain_get (), dest->klass->image->assembly);
 }
 
-static MonoString *
+ICALL_EXPORT MonoString *
 ves_icall_System_MonoType_getFullName (MonoReflectionType *object, gboolean full_name,
                                       gboolean assembly_qualified)
 {
@@ -4936,7 +4918,7 @@ ves_icall_System_MonoType_getFullName (MonoReflectionType *object, gboolean full
        return res;
 }
 
-static int
+ICALL_EXPORT int
 vell_icall_MonoType_get_core_clr_security_level (MonoReflectionType *this)
 {
        MonoClass *klass = mono_class_from_mono_type (this->type);
@@ -5043,7 +5025,7 @@ fill_reflection_assembly_name (MonoDomain *domain, MonoReflectionAssemblyName *a
        }
 }
 
-static MonoString *
+ICALL_EXPORT MonoString *
 ves_icall_System_Reflection_Assembly_get_fullName (MonoReflectionAssembly *assembly)
 {
        MonoDomain *domain = mono_object_domain (assembly); 
@@ -5058,7 +5040,7 @@ ves_icall_System_Reflection_Assembly_get_fullName (MonoReflectionAssembly *assem
        return res;
 }
 
-static void
+ICALL_EXPORT void
 ves_icall_System_Reflection_Assembly_FillName (MonoReflectionAssembly *assembly, MonoReflectionAssemblyName *aname)
 {
        gchar *absolute;
@@ -5081,7 +5063,7 @@ ves_icall_System_Reflection_Assembly_FillName (MonoReflectionAssembly *assembly,
        g_free (absolute);
 }
 
-static void
+ICALL_EXPORT void
 ves_icall_System_Reflection_Assembly_InternalGetAssemblyName (MonoString *fname, MonoReflectionAssemblyName *aname)
 {
        char *filename;
@@ -5126,7 +5108,7 @@ ves_icall_System_Reflection_Assembly_InternalGetAssemblyName (MonoString *fname,
        mono_image_close (image);
 }
 
-static MonoBoolean
+ICALL_EXPORT MonoBoolean
 ves_icall_System_Reflection_Assembly_LoadPermissions (MonoReflectionAssembly *assembly,
        char **minimum, guint32 *minLength, char **optional, guint32 *optLength, char **refused, guint32 *refLength)
 {
@@ -5205,7 +5187,7 @@ mono_module_get_types (MonoDomain *domain, MonoImage *image, MonoArray **excepti
        return res;
 }
 
-static MonoArray*
+ICALL_EXPORT MonoArray*
 ves_icall_System_Reflection_Assembly_GetTypes (MonoReflectionAssembly *assembly, MonoBoolean exportedOnly)
 {
        MonoArray *res = NULL;
@@ -5313,7 +5295,7 @@ ves_icall_System_Reflection_Assembly_GetTypes (MonoReflectionAssembly *assembly,
        return res;
 }
 
-static gboolean
+ICALL_EXPORT gboolean
 ves_icall_System_Reflection_AssemblyName_ParseName (MonoReflectionAssemblyName *name, MonoString *assname)
 {
        MonoAssemblyName aname;
@@ -5340,7 +5322,7 @@ ves_icall_System_Reflection_AssemblyName_ParseName (MonoReflectionAssemblyName *
        return TRUE;
 }
 
-static MonoReflectionType*
+ICALL_EXPORT MonoReflectionType*
 ves_icall_System_Reflection_Module_GetGlobalType (MonoReflectionModule *module)
 {
        MonoDomain *domain = mono_object_domain (module); 
@@ -5358,14 +5340,14 @@ ves_icall_System_Reflection_Module_GetGlobalType (MonoReflectionModule *module)
        return mono_type_get_object (domain, &klass->byval_arg);
 }
 
-static void
+ICALL_EXPORT void
 ves_icall_System_Reflection_Module_Close (MonoReflectionModule *module)
 {
        /*if (module->image)
                mono_image_close (module->image);*/
 }
 
-static MonoString*
+ICALL_EXPORT MonoString*
 ves_icall_System_Reflection_Module_GetGuidInternal (MonoReflectionModule *module)
 {
        MonoDomain *domain = mono_object_domain (module); 
@@ -5376,7 +5358,7 @@ ves_icall_System_Reflection_Module_GetGuidInternal (MonoReflectionModule *module
        return mono_string_new (domain, module->image->guid);
 }
 
-static gpointer
+ICALL_EXPORT gpointer
 ves_icall_System_Reflection_Module_GetHINSTANCE (MonoReflectionModule *module)
 {
 #ifdef HOST_WIN32
@@ -5387,7 +5369,7 @@ ves_icall_System_Reflection_Module_GetHINSTANCE (MonoReflectionModule *module)
        return (gpointer) (-1);
 }
 
-static void
+ICALL_EXPORT void
 ves_icall_System_Reflection_Module_GetPEKind (MonoImage *image, gint32 *pe_kind, gint32 *machine)
 {
        if (image->dynamic) {
@@ -5401,13 +5383,13 @@ ves_icall_System_Reflection_Module_GetPEKind (MonoImage *image, gint32 *pe_kind,
        }
 }
 
-static gint32
+ICALL_EXPORT gint32
 ves_icall_System_Reflection_Module_GetMDStreamVersion (MonoImage *image)
 {
        return (image->md_version_major << 16) | (image->md_version_minor);
 }
 
-static MonoArray*
+ICALL_EXPORT MonoArray*
 ves_icall_System_Reflection_Module_InternalGetTypes (MonoReflectionModule *module)
 {
        MonoArray *exceptions;
@@ -5463,7 +5445,7 @@ init_generic_context_from_args (MonoGenericContext *context, MonoArray *type_arg
                context->method_inst = NULL;
 }
 
-static MonoType*
+ICALL_EXPORT MonoType*
 ves_icall_System_Reflection_Module_ResolveTypeToken (MonoImage *image, guint32 token, MonoArray *type_args, MonoArray *method_args, MonoResolveTokenError *error)
 {
        MonoClass *klass;
@@ -5508,7 +5490,7 @@ ves_icall_System_Reflection_Module_ResolveTypeToken (MonoImage *image, guint32 t
                return NULL;
 }
 
-static MonoMethod*
+ICALL_EXPORT MonoMethod*
 ves_icall_System_Reflection_Module_ResolveMethodToken (MonoImage *image, guint32 token, MonoArray *type_args, MonoArray *method_args, MonoResolveTokenError *error)
 {
        int table = mono_metadata_token_table (token);
@@ -5556,7 +5538,7 @@ ves_icall_System_Reflection_Module_ResolveMethodToken (MonoImage *image, guint32
        return method;
 }
 
-static MonoString*
+ICALL_EXPORT MonoString*
 ves_icall_System_Reflection_Module_ResolveStringToken (MonoImage *image, guint32 token, MonoResolveTokenError *error)
 {
        int index = mono_metadata_token_index (token);
@@ -5582,7 +5564,7 @@ ves_icall_System_Reflection_Module_ResolveStringToken (MonoImage *image, guint32
        return mono_ldstr (mono_domain_get (), image, index);
 }
 
-static MonoClassField*
+ICALL_EXPORT MonoClassField*
 ves_icall_System_Reflection_Module_ResolveFieldToken (MonoImage *image, guint32 token, MonoArray *type_args, MonoArray *method_args, MonoResolveTokenError *error)
 {
        MonoClass *klass;
@@ -5631,7 +5613,7 @@ ves_icall_System_Reflection_Module_ResolveFieldToken (MonoImage *image, guint32
 }
 
 
-static MonoObject*
+ICALL_EXPORT MonoObject*
 ves_icall_System_Reflection_Module_ResolveMemberToken (MonoImage *image, guint32 token, MonoArray *type_args, MonoArray *method_args, MonoResolveTokenError *error)
 {
        int table = mono_metadata_token_table (token);
@@ -5687,7 +5669,7 @@ ves_icall_System_Reflection_Module_ResolveMemberToken (MonoImage *image, guint32
        return NULL;
 }
 
-static MonoArray*
+ICALL_EXPORT MonoArray*
 ves_icall_System_Reflection_Module_ResolveSignature (MonoImage *image, guint32 token, MonoResolveTokenError *error)
 {
        int table = mono_metadata_token_table (token);
@@ -5719,7 +5701,7 @@ ves_icall_System_Reflection_Module_ResolveSignature (MonoImage *image, guint32 t
        return res;
 }
 
-static MonoReflectionType*
+ICALL_EXPORT MonoReflectionType*
 ves_icall_ModuleBuilder_create_modified_type (MonoReflectionTypeBuilder *tb, MonoString *smodifiers)
 {
        MonoClass *klass;
@@ -5779,7 +5761,7 @@ ves_icall_ModuleBuilder_create_modified_type (MonoReflectionTypeBuilder *tb, Mon
        return mono_type_get_object (mono_object_domain (tb), &klass->byval_arg);
 }
 
-static MonoBoolean
+ICALL_EXPORT MonoBoolean
 ves_icall_Type_IsArrayImpl (MonoReflectionType *t)
 {
        MonoType *type;
@@ -5807,7 +5789,7 @@ check_for_invalid_type (MonoClass *klass)
        mono_raise_exception ((MonoException*)mono_get_exception_type_load (str, NULL));
 
 }
-static MonoReflectionType *
+ICALL_EXPORT MonoReflectionType *
 ves_icall_Type_make_array_type (MonoReflectionType *type, int rank)
 {
        MonoClass *klass, *aklass;
@@ -5825,7 +5807,7 @@ ves_icall_Type_make_array_type (MonoReflectionType *type, int rank)
        return mono_type_get_object (mono_object_domain (type), &aklass->byval_arg);
 }
 
-static MonoReflectionType *
+ICALL_EXPORT MonoReflectionType *
 ves_icall_Type_make_byref_type (MonoReflectionType *type)
 {
        MonoClass *klass;
@@ -5839,7 +5821,7 @@ ves_icall_Type_make_byref_type (MonoReflectionType *type)
        return mono_type_get_object (mono_object_domain (type), &klass->this_arg);
 }
 
-static MonoReflectionType *
+ICALL_EXPORT MonoReflectionType *
 ves_icall_Type_MakePointerType (MonoReflectionType *type)
 {
        MonoClass *klass, *pklass;
@@ -5853,7 +5835,7 @@ ves_icall_Type_MakePointerType (MonoReflectionType *type)
        return mono_type_get_object (mono_object_domain (type), &pklass->byval_arg);
 }
 
-static MonoObject *
+ICALL_EXPORT MonoObject *
 ves_icall_System_Delegate_CreateDelegate_internal (MonoReflectionType *type, MonoObject *target,
                                                   MonoReflectionMethod *info, MonoBoolean throwOnBindFailure)
 {
@@ -5890,7 +5872,7 @@ ves_icall_System_Delegate_CreateDelegate_internal (MonoReflectionType *type, Mon
        return delegate;
 }
 
-static void
+ICALL_EXPORT void
 ves_icall_System_Delegate_SetMulticastInvoke (MonoDelegate *this)
 {
        /* Reset the invoke impl to the default one */
@@ -5975,7 +5957,7 @@ gmt_offset(struct tm *tm, time_t t)
  *
  *  Returns true on success and zero on failure.
  */
-static guint32
+ICALL_EXPORT guint32
 ves_icall_System_CurrentSystemTimeZone_GetTimeZoneData (guint32 year, MonoArray **data, MonoArray **names)
 {
 #ifndef HOST_WIN32
@@ -6053,8 +6035,19 @@ ves_icall_System_CurrentSystemTimeZone_GetTimeZoneData (guint32 year, MonoArray
                                mono_array_set ((*data), gint64, 1, ((gint64)t1 + EPOCH_ADJUST) * 10000000L);
                                return 1;
                        } else {
+                               struct tm end;
+                               time_t te;
+                               
+                               memset (&end, 0, sizeof (end));
+                               end.tm_year = year-1900 + 1;
+                               end.tm_mday = 1;
+                               
+                               te = mktime (&end);
+                               
                                mono_array_setref ((*names), 1, mono_string_new (domain, tzone));
                                mono_array_set ((*data), gint64, 0, ((gint64)t1 + EPOCH_ADJUST) * 10000000L);
+                               mono_array_setref ((*names), 0, mono_string_new (domain, tzone));
+                               mono_array_set ((*data), gint64, 1, ((gint64)te + EPOCH_ADJUST) * 10000000L);
                                is_daylight = 1;
                        }
 
@@ -6137,7 +6130,7 @@ ves_icall_System_CurrentSystemTimeZone_GetTimeZoneData (guint32 year, MonoArray
 #endif
 }
 
-static gpointer
+ICALL_EXPORT gpointer
 ves_icall_System_Object_obj_address (MonoObject *this) 
 {
        MONO_ARCH_SAVE_REGS;
@@ -6189,7 +6182,7 @@ mono_array_get_byte_length (MonoArray *array)
        }
 }
 
-static gint32 
+ICALL_EXPORT gint32 
 ves_icall_System_Buffer_ByteLengthInternal (MonoArray *array) 
 {
        MONO_ARCH_SAVE_REGS;
@@ -6197,7 +6190,7 @@ ves_icall_System_Buffer_ByteLengthInternal (MonoArray *array)
        return mono_array_get_byte_length (array);
 }
 
-static gint8 
+ICALL_EXPORT gint8 
 ves_icall_System_Buffer_GetByteInternal (MonoArray *array, gint32 idx) 
 {
        MONO_ARCH_SAVE_REGS;
@@ -6205,7 +6198,7 @@ ves_icall_System_Buffer_GetByteInternal (MonoArray *array, gint32 idx)
        return mono_array_get (array, gint8, idx);
 }
 
-static void 
+ICALL_EXPORT void 
 ves_icall_System_Buffer_SetByteInternal (MonoArray *array, gint32 idx, gint8 value) 
 {
        MONO_ARCH_SAVE_REGS;
@@ -6213,13 +6206,17 @@ ves_icall_System_Buffer_SetByteInternal (MonoArray *array, gint32 idx, gint8 val
        mono_array_set (array, gint8, idx, value);
 }
 
-static MonoBoolean
+ICALL_EXPORT MonoBoolean
 ves_icall_System_Buffer_BlockCopyInternal (MonoArray *src, gint32 src_offset, MonoArray *dest, gint32 dest_offset, gint32 count) 
 {
        guint8 *src_buf, *dest_buf;
 
        MONO_ARCH_SAVE_REGS;
 
+       /* This is called directly from the class libraries without going through the managed wrapper */
+       MONO_CHECK_ARG_NULL (src);
+       MONO_CHECK_ARG_NULL (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;
@@ -6235,7 +6232,8 @@ ves_icall_System_Buffer_BlockCopyInternal (MonoArray *src, gint32 src_offset, Mo
        return TRUE;
 }
 
-static MonoObject *
+#ifndef DISABLE_REMOTING
+ICALL_EXPORT MonoObject *
 ves_icall_Remoting_RealProxy_GetTransparentProxy (MonoObject *this, MonoString *class_name)
 {
        MonoDomain *domain = mono_object_domain (this); 
@@ -6261,11 +6259,12 @@ ves_icall_Remoting_RealProxy_GetTransparentProxy (MonoObject *this, MonoString *
        return res;
 }
 
-static MonoReflectionType *
+ICALL_EXPORT MonoReflectionType *
 ves_icall_Remoting_RealProxy_InternalGetProxyType (MonoTransparentProxy *tp)
 {
        return mono_type_get_object (mono_object_domain (tp), &tp->remote_class->proxy_class->byval_arg);
 }
+#endif
 
 /* System.Environment */
 
@@ -6279,7 +6278,7 @@ ves_icall_System_Environment_get_UserName (void)
 }
 
 
-static MonoString *
+ICALL_EXPORT MonoString *
 ves_icall_System_Environment_get_MachineName (void)
 {
 #if defined (HOST_WIN32)
@@ -6311,7 +6310,7 @@ ves_icall_System_Environment_get_MachineName (void)
 #endif
 }
 
-static int
+ICALL_EXPORT int
 ves_icall_System_Environment_get_Platform (void)
 {
 #if defined (TARGET_WIN32)
@@ -6333,7 +6332,7 @@ ves_icall_System_Environment_get_Platform (void)
 #endif
 }
 
-static MonoString *
+ICALL_EXPORT MonoString *
 ves_icall_System_Environment_get_NewLine (void)
 {
        MONO_ARCH_SAVE_REGS;
@@ -6345,7 +6344,7 @@ ves_icall_System_Environment_get_NewLine (void)
 #endif
 }
 
-static MonoString *
+ICALL_EXPORT MonoString *
 ves_icall_System_Environment_GetEnvironmentVariable (MonoString *name)
 {
        const gchar *value;
@@ -6386,7 +6385,7 @@ char **environ;
 #endif
 #endif
 
-static MonoArray *
+ICALL_EXPORT MonoArray *
 ves_icall_System_Environment_GetEnvironmentVariableNames (void)
 {
 #ifdef HOST_WIN32
@@ -6478,7 +6477,7 @@ ves_icall_System_Environment_GetEnvironmentVariableNames (void)
 #define g_unsetenv(a) unsetenv(a)
 #endif
 
-static void
+ICALL_EXPORT void
 ves_icall_System_Environment_InternalSetEnvironmentVariable (MonoString *name, MonoString *value)
 {
        MonoError error;
@@ -6526,11 +6525,15 @@ ves_icall_System_Environment_InternalSetEnvironmentVariable (MonoString *name, M
 #endif
 }
 
-static void
+ICALL_EXPORT void
 ves_icall_System_Environment_Exit (int result)
 {
        MONO_ARCH_SAVE_REGS;
 
+#ifndef MONO_CROSS_COMPILE
+       mono_runtime_shutdown ();
+#endif
+
        mono_threads_set_shutting_down ();
 
        mono_runtime_set_shutting_down ();
@@ -6547,13 +6550,13 @@ ves_icall_System_Environment_Exit (int result)
        exit (result);
 }
 
-static MonoString*
+ICALL_EXPORT MonoString*
 ves_icall_System_Environment_GetGacPath (void)
 {
        return mono_string_new (mono_domain_get (), mono_assembly_getrootdir ());
 }
 
-static MonoString*
+ICALL_EXPORT MonoString*
 ves_icall_System_Environment_GetWindowsFolderPath (int folder)
 {
 #if defined (HOST_WIN32)
@@ -6575,7 +6578,7 @@ ves_icall_System_Environment_GetWindowsFolderPath (int folder)
        return mono_string_new (mono_domain_get (), "");
 }
 
-static MonoArray *
+ICALL_EXPORT MonoArray *
 ves_icall_System_Environment_GetLogicalDrives (void)
 {
         gunichar2 buf [256], *ptr, *dname;
@@ -6629,7 +6632,7 @@ ves_icall_System_Environment_GetLogicalDrives (void)
        return result;
 }
 
-static MonoString *
+ICALL_EXPORT MonoString *
 ves_icall_System_IO_DriveInfo_GetDriveFormat (MonoString *path)
 {
        gunichar2 volume_name [MAX_PATH + 1];
@@ -6639,7 +6642,7 @@ ves_icall_System_IO_DriveInfo_GetDriveFormat (MonoString *path)
        return mono_string_from_utf16 (volume_name);
 }
 
-static MonoString *
+ICALL_EXPORT MonoString *
 ves_icall_System_Environment_InternalGetHome (void)
 {
        MONO_ARCH_SAVE_REGS;
@@ -6674,7 +6677,7 @@ static const char *encodings [] = {
  * 1 at entry, and we can not compute a suitable code page number,
  * returns the code page as a string
  */
-static MonoString*
+ICALL_EXPORT MonoString*
 ves_icall_System_Text_Encoding_InternalCodePage (gint32 *int_code_page) 
 {
        const char *cset;
@@ -6724,7 +6727,7 @@ ves_icall_System_Text_Encoding_InternalCodePage (gint32 *int_code_page)
                return NULL;
 }
 
-static MonoBoolean
+ICALL_EXPORT MonoBoolean
 ves_icall_System_Environment_get_HasShutdownStarted (void)
 {
        if (mono_runtime_is_shutting_down ())
@@ -6736,7 +6739,7 @@ ves_icall_System_Environment_get_HasShutdownStarted (void)
        return FALSE;
 }
 
-static void
+ICALL_EXPORT void
 ves_icall_System_Environment_BroadcastSettingChange (void)
 {
 #ifdef HOST_WIN32
@@ -6744,7 +6747,7 @@ ves_icall_System_Environment_BroadcastSettingChange (void)
 #endif
 }
 
-static void
+ICALL_EXPORT void
 ves_icall_MonoMethodMessage_InitMessage (MonoMethodMessage *this, 
                                         MonoReflectionMethod *method,
                                         MonoArray *out_args)
@@ -6754,7 +6757,8 @@ ves_icall_MonoMethodMessage_InitMessage (MonoMethodMessage *this,
        mono_message_init (mono_object_domain (this), this, method, out_args);
 }
 
-static MonoBoolean
+#ifndef DISABLE_REMOTING
+ICALL_EXPORT MonoBoolean
 ves_icall_IsTransparentProxy (MonoObject *proxy)
 {
        MONO_ARCH_SAVE_REGS;
@@ -6768,7 +6772,7 @@ ves_icall_IsTransparentProxy (MonoObject *proxy)
        return 0;
 }
 
-static MonoReflectionMethod *
+ICALL_EXPORT MonoReflectionMethod *
 ves_icall_Remoting_RemotingServices_GetVirtualMethod (
        MonoReflectionType *rtype, MonoReflectionMethod *rmethod)
 {
@@ -6820,7 +6824,7 @@ ves_icall_Remoting_RemotingServices_GetVirtualMethod (
        return mono_method_get_object (mono_domain_get (), res, NULL);
 }
 
-static void
+ICALL_EXPORT void
 ves_icall_System_Runtime_Activation_ActivationServices_EnableProxyActivation (MonoReflectionType *type, MonoBoolean enable)
 {
        MonoClass *klass;
@@ -6834,8 +6838,9 @@ ves_icall_System_Runtime_Activation_ActivationServices_EnableProxyActivation (Mo
        if (enable) vtable->remote = 1;
        else vtable->remote = 0;
 }
+#endif
 
-static MonoObject *
+ICALL_EXPORT MonoObject *
 ves_icall_System_Runtime_Activation_ActivationServices_AllocateUninitializedClassInstance (MonoReflectionType *type)
 {
        MonoClass *klass;
@@ -6859,7 +6864,7 @@ ves_icall_System_Runtime_Activation_ActivationServices_AllocateUninitializedClas
        }
 }
 
-static MonoString *
+ICALL_EXPORT MonoString *
 ves_icall_System_IO_get_temp_path (void)
 {
        MONO_ARCH_SAVE_REGS;
@@ -6868,7 +6873,7 @@ ves_icall_System_IO_get_temp_path (void)
 }
 
 #ifndef PLATFORM_NO_DRIVEINFO
-static MonoBoolean
+ICALL_EXPORT MonoBoolean
 ves_icall_System_IO_DriveInfo_GetDiskFreeSpace (MonoString *path_name, guint64 *free_bytes_avail,
                                                guint64 *total_number_of_bytes, guint64 *total_number_of_free_bytes,
                                                gint32 *error)
@@ -6898,7 +6903,7 @@ ves_icall_System_IO_DriveInfo_GetDiskFreeSpace (MonoString *path_name, guint64 *
        return result;
 }
 
-static guint32
+ICALL_EXPORT guint32
 ves_icall_System_IO_DriveInfo_GetDriveType (MonoString *root_path_name)
 {
        MONO_ARCH_SAVE_REGS;
@@ -6907,7 +6912,7 @@ ves_icall_System_IO_DriveInfo_GetDriveType (MonoString *root_path_name)
 }
 #endif
 
-static gpointer
+ICALL_EXPORT gpointer
 ves_icall_RuntimeMethod_GetFunctionPointer (MonoMethod *method)
 {
        MONO_ARCH_SAVE_REGS;
@@ -6915,7 +6920,7 @@ ves_icall_RuntimeMethod_GetFunctionPointer (MonoMethod *method)
        return mono_compile_method (method);
 }
 
-static MonoString *
+ICALL_EXPORT MonoString *
 ves_icall_System_Configuration_DefaultConfig_get_machine_config_path (void)
 {
        MonoString *mcpath;
@@ -6994,7 +6999,7 @@ get_bundled_machine_config (void)
        return mono_string_new (mono_domain_get (), machine_config);
 }
 
-static MonoString *
+ICALL_EXPORT MonoString *
 ves_icall_System_Web_Util_ICalls_get_machine_install_dir (void)
 {
        MonoString *ipath;
@@ -7019,7 +7024,7 @@ ves_icall_System_Web_Util_ICalls_get_machine_install_dir (void)
        return ipath;
 }
 
-static gboolean
+ICALL_EXPORT gboolean
 ves_icall_get_resources_ptr (MonoReflectionAssembly *assembly, gpointer *result, gint32 *size)
 {
        MonoPEResourceDataEntry *entry;
@@ -7047,13 +7052,13 @@ ves_icall_get_resources_ptr (MonoReflectionAssembly *assembly, gpointer *result,
        return TRUE;
 }
 
-static MonoBoolean
+ICALL_EXPORT MonoBoolean
 ves_icall_System_Diagnostics_Debugger_IsAttached_internal (void)
 {
        return mono_debug_using_mono_debugger () || mono_is_debugger_attached ();
 }
 
-static MonoBoolean
+ICALL_EXPORT MonoBoolean
 ves_icall_System_Diagnostics_Debugger_IsLogging (void)
 {
        if (mono_get_runtime_callbacks ()->debug_log_is_enabled)
@@ -7062,14 +7067,14 @@ ves_icall_System_Diagnostics_Debugger_IsLogging (void)
                return FALSE;
 }
 
-static void
+ICALL_EXPORT void
 ves_icall_System_Diagnostics_Debugger_Log (int level, MonoString *category, MonoString *message)
 {
        if (mono_get_runtime_callbacks ()->debug_log)
                mono_get_runtime_callbacks ()->debug_log (level, category, message);
 }
 
-static void
+ICALL_EXPORT void
 ves_icall_System_Diagnostics_DefaultTraceListener_WriteWindowsDebugString (MonoString *message)
 {
 #if defined (HOST_WIN32)
@@ -7080,7 +7085,7 @@ ves_icall_System_Diagnostics_DefaultTraceListener_WriteWindowsDebugString (MonoS
 }
 
 /* Only used for value types */
-static MonoObject *
+ICALL_EXPORT MonoObject *
 ves_icall_System_Activator_CreateInstanceInternal (MonoReflectionType *type)
 {
        MonoClass *klass;
@@ -7099,7 +7104,7 @@ ves_icall_System_Activator_CreateInstanceInternal (MonoReflectionType *type)
        return mono_object_new (domain, klass);
 }
 
-static MonoReflectionMethod *
+ICALL_EXPORT MonoReflectionMethod *
 ves_icall_MonoMethod_get_base_method (MonoReflectionMethod *m, gboolean definition)
 {
        MonoClass *klass, *parent;
@@ -7165,7 +7170,7 @@ ves_icall_MonoMethod_get_base_method (MonoReflectionMethod *m, gboolean definiti
        return mono_method_get_object (mono_domain_get (), result, NULL);
 }
 
-static MonoString*
+ICALL_EXPORT MonoString*
 ves_icall_MonoMethod_get_name (MonoReflectionMethod *m)
 {
        MonoMethod *method = m->method;
@@ -7174,7 +7179,7 @@ ves_icall_MonoMethod_get_name (MonoReflectionMethod *m)
        return m->name;
 }
 
-static void
+ICALL_EXPORT void
 mono_ArgIterator_Setup (MonoArgIterator *iter, char* argsp, char* start)
 {
        MONO_ARCH_SAVE_REGS;
@@ -7196,7 +7201,7 @@ mono_ArgIterator_Setup (MonoArgIterator *iter, char* argsp, char* start)
        /* g_print ("sig %p, param_count: %d, sent: %d\n", iter->sig, iter->sig->param_count, iter->sig->sentinelpos); */
 }
 
-static MonoTypedRef
+ICALL_EXPORT MonoTypedRef
 mono_ArgIterator_IntGetNextArg (MonoArgIterator *iter)
 {
        guint32 i, arg_size;
@@ -7211,7 +7216,7 @@ mono_ArgIterator_IntGetNextArg (MonoArgIterator *iter)
        res.type = iter->sig->params [i];
        res.klass = mono_class_from_mono_type (res.type);
        arg_size = mono_type_stack_size (res.type, &align);
-#if defined(__arm__)
+#if defined(__arm__) || defined(__mips__)
        iter->args = (guint8*)(((gsize)iter->args + (align) - 1) & ~(align - 1));
 #endif
        res.value = iter->args;
@@ -7230,7 +7235,7 @@ mono_ArgIterator_IntGetNextArg (MonoArgIterator *iter)
        return res;
 }
 
-static MonoTypedRef
+ICALL_EXPORT MonoTypedRef
 mono_ArgIterator_IntGetNextArgT (MonoArgIterator *iter, MonoType *type)
 {
        guint32 i, arg_size;
@@ -7249,7 +7254,7 @@ mono_ArgIterator_IntGetNextArgT (MonoArgIterator *iter, MonoType *type)
                res.klass = mono_class_from_mono_type (res.type);
                /* FIXME: endianess issue... */
                arg_size = mono_type_stack_size (res.type, &align);
-#if defined(__arm__)
+#if defined(__arm__) || defined(__mips__)
                iter->args = (guint8*)(((gsize)iter->args + (align) - 1) & ~(align - 1));
 #endif
                res.value = iter->args;
@@ -7266,7 +7271,7 @@ mono_ArgIterator_IntGetNextArgT (MonoArgIterator *iter, MonoType *type)
        return res;
 }
 
-static MonoType*
+ICALL_EXPORT MonoType*
 mono_ArgIterator_IntGetNextArgType (MonoArgIterator *iter)
 {
        gint i;
@@ -7279,7 +7284,7 @@ mono_ArgIterator_IntGetNextArgType (MonoArgIterator *iter)
        return iter->sig->params [i];
 }
 
-static MonoObject*
+ICALL_EXPORT MonoObject*
 mono_TypedReference_ToObject (MonoTypedRef tref)
 {
        MONO_ARCH_SAVE_REGS;
@@ -7292,7 +7297,7 @@ mono_TypedReference_ToObject (MonoTypedRef tref)
        return mono_value_box (mono_domain_get (), tref.klass, tref.value);
 }
 
-static MonoObject*
+ICALL_EXPORT MonoObject*
 mono_TypedReference_ToObjectInternal (MonoType *type, gpointer value, MonoClass *klass)
 {
        MONO_ARCH_SAVE_REGS;
@@ -7319,14 +7324,14 @@ prelink_method (MonoMethod *method)
        /* create the wrapper, too? */
 }
 
-static void
+ICALL_EXPORT void
 ves_icall_System_Runtime_InteropServices_Marshal_Prelink (MonoReflectionMethod *method)
 {
        MONO_ARCH_SAVE_REGS;
        prelink_method (method->method);
 }
 
-static void
+ICALL_EXPORT void
 ves_icall_System_Runtime_InteropServices_Marshal_PrelinkAll (MonoReflectionType *type)
 {
        MonoClass *klass = mono_class_from_mono_type (type->type);
@@ -7341,7 +7346,7 @@ ves_icall_System_Runtime_InteropServices_Marshal_PrelinkAll (MonoReflectionType
 }
 
 /* These parameters are "readonly" in corlib/System/NumberFormatter.cs */
-static void
+ICALL_EXPORT void
 ves_icall_System_NumberFormatter_GetFormatterTables (guint64 const **mantissas,
                                            gint32 const **exponents,
                                            gunichar2 const **digitLowerTable,
@@ -7357,7 +7362,7 @@ ves_icall_System_NumberFormatter_GetFormatterTables (guint64 const **mantissas,
        *decHexDigits = Formatter_DecHexDigits;
 }
 
-static void
+ICALL_EXPORT void
 get_category_data (int version,
                   guint8 const **category_data,
                   guint16 const **category_astral_index)
@@ -7381,7 +7386,7 @@ get_category_data (int version,
 }
 
 /* These parameters are "readonly" in corlib/System/Char.cs */
-static void
+ICALL_EXPORT void
 ves_icall_System_Char_GetDataTablePointers (int category_data_version,
                                            guint8 const **category_data,
                                            guint16 const **category_astral_index,
@@ -7401,7 +7406,7 @@ ves_icall_System_Char_GetDataTablePointers (int category_data_version,
        *to_upper_data_high = ToUpperDataHigh;
 }
 
-static gint32
+ICALL_EXPORT gint32
 ves_icall_MonoDebugger_GetMethodToken (MonoReflectionMethod *method)
 {
        return method->method->token;
@@ -7434,7 +7439,7 @@ type_array_from_modifiers (MonoImage *image, MonoType *type, int optional)
        return res;
 }
 
-static MonoArray*
+ICALL_EXPORT MonoArray*
 param_info_get_type_modifiers (MonoReflectionParameter *param, MonoBoolean optional)
 {
        MonoType *type = param->ClassImpl->type;
@@ -7486,7 +7491,7 @@ get_property_type (MonoProperty *prop)
        return NULL;
 }
 
-static MonoArray*
+ICALL_EXPORT MonoArray*
 property_info_get_type_modifiers (MonoReflectionProperty *property, MonoBoolean optional)
 {
        MonoType *type = get_property_type (property->property);
@@ -7519,7 +7524,7 @@ mono_type_from_blob_type (MonoType *type, MonoTypeEnum blob_type, MonoType *real
                type->data.klass = mono_class_from_mono_type (real_type);
 }
 
-static MonoObject*
+ICALL_EXPORT MonoObject*
 property_info_get_default_value (MonoReflectionProperty *property)
 {
        MonoType blob_type;
@@ -7543,7 +7548,7 @@ property_info_get_default_value (MonoReflectionProperty *property)
        return o;
 }
 
-static MonoBoolean
+ICALL_EXPORT MonoBoolean
 custom_attrs_defined_internal (MonoObject *obj, MonoReflectionType *attr_type)
 {
        MonoClass *attr_class = mono_class_from_mono_type (attr_type->type);
@@ -7561,7 +7566,7 @@ custom_attrs_defined_internal (MonoObject *obj, MonoReflectionType *attr_type)
        return found;
 }
 
-static MonoArray*
+ICALL_EXPORT MonoArray*
 custom_attrs_get_by_type (MonoObject *obj, MonoReflectionType *attr_type)
 {
        MonoClass *attr_class = attr_type ? mono_class_from_mono_type (attr_type->type) : NULL;
@@ -7584,7 +7589,7 @@ custom_attrs_get_by_type (MonoObject *obj, MonoReflectionType *attr_type)
        }
 }
 
-static MonoString*
+ICALL_EXPORT MonoString*
 ves_icall_Mono_Runtime_GetDisplayName (void)
 {
        char *info;
@@ -7596,7 +7601,7 @@ ves_icall_Mono_Runtime_GetDisplayName (void)
        return display_name;
 }
 
-static MonoString*
+ICALL_EXPORT MonoString*
 ves_icall_System_ComponentModel_Win32Exception_W32ErrorMessage (guint32 code)
 {
        MonoString *message;
@@ -7640,6 +7645,7 @@ base64_to_byte_array (gunichar2 *start, gint ilength, MonoBoolean allowWhitespac
        gint a [4], b [4];
        MonoException *exc;
 
+       int havePadding = 0;
        ignored = 0;
        last = prev_last = 0, prev2_last = 0;
        for (i = 0; i < ilength; i++) {
@@ -7651,7 +7657,13 @@ base64_to_byte_array (gunichar2 *start, gint ilength, MonoBoolean allowWhitespac
                        mono_raise_exception (exc);
                } else if (isspace (c)) {
                        ignored++;
+               } else if (havePadding && c != '=') {
+                       exc = mono_exception_from_name_msg (mono_get_corlib (),
+                               "System", "FormatException",
+                               "Invalid character found.");
+                       mono_raise_exception (exc);
                } else {
+                       if (c == '=') havePadding = 1;
                        prev2_last = prev_last;
                        prev_last = last;
                        last = c;
@@ -7715,7 +7727,7 @@ base64_to_byte_array (gunichar2 *start, gint ilength, MonoBoolean allowWhitespac
        return result;
 }
 
-static MonoArray *
+ICALL_EXPORT MonoArray *
 InternalFromBase64String (MonoString *str, MonoBoolean allowWhitespaceOnly)
 {
        MONO_ARCH_SAVE_REGS;
@@ -7724,7 +7736,7 @@ InternalFromBase64String (MonoString *str, MonoBoolean allowWhitespaceOnly)
                mono_string_length (str), allowWhitespaceOnly);
 }
 
-static MonoArray *
+ICALL_EXPORT MonoArray *
 InternalFromBase64CharArray (MonoArray *input, gint offset, gint length)
 {
        MONO_ARCH_SAVE_REGS;
@@ -7733,6 +7745,8 @@ InternalFromBase64CharArray (MonoArray *input, gint offset, gint length)
                length, FALSE);
 }
 
+#ifndef DISABLE_ICALL_TABLES
+
 #define ICALL_TYPE(id,name,first)
 #define ICALL(id,name,func) Icall_ ## id,
 
@@ -7847,6 +7861,20 @@ icall_functions [] = {
        NULL
 };
 
+#ifdef ENABLE_ICALL_SYMBOL_MAP
+#undef ICALL_TYPE
+#undef ICALL
+#define ICALL_TYPE(id,name,first)
+#define ICALL(id,name,func) #func,
+static const gconstpointer
+icall_symbols [] = {
+#include "metadata/icall-def.h"
+       NULL
+};
+#endif
+
+#endif /* DISABLE_ICALL_TABLES */
+
 static GHashTable *icall_hash = NULL;
 static GHashTable *jit_icall_hash_name = NULL;
 static GHashTable *jit_icall_hash_addr = NULL;
@@ -7854,6 +7882,7 @@ static GHashTable *jit_icall_hash_addr = NULL;
 void
 mono_icall_init (void)
 {
+#ifndef DISABLE_ICALL_TABLES
        int i = 0;
 
        /* check that tables are sorted: disable in release */
@@ -7880,6 +7909,7 @@ mono_icall_init (void)
                        }
                }
        }
+#endif
 
        icall_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
 }
@@ -7902,6 +7932,8 @@ mono_add_internal_call (const char *name, gconstpointer method)
        mono_loader_unlock ();
 }
 
+#ifndef DISABLE_ICALL_TABLES
+
 #ifdef HAVE_ARRAY_ELEM_INIT
 static int
 compare_method_imap (const void *key, const void *elem)
@@ -7935,7 +7967,8 @@ find_class_icalls (const char *name)
        return &icall_type_descs [nameslot - &icall_type_names_idx [0]];
 }
 
-#else
+#else /* HAVE_ARRAY_ELEM_INIT */
+
 static int
 compare_method_imap (const void *key, const void *elem)
 {
@@ -7968,7 +8001,9 @@ find_class_icalls (const char *name)
        return &icall_type_descs [nameslot - icall_type_names];
 }
 
-#endif
+#endif /* HAVE_ARRAY_ELEM_INIT */
+
+#endif /* DISABLE_ICALL_TABLES */
 
 /* 
  * we should probably export this as an helper (handle nested types).
@@ -7991,6 +8026,14 @@ concat_class_name (char *buf, int bufsize, MonoClass *klass)
        return nspacelen + cnamelen;
 }
 
+#ifdef DISABLE_ICALL_TABLES
+static void
+no_icall_table (void)
+{
+       g_assert_not_reached ();
+}
+#endif
+
 gpointer
 mono_lookup_internal_call (MonoMethod *method)
 {
@@ -7999,7 +8042,9 @@ mono_lookup_internal_call (MonoMethod *method)
        char mname [2048];
        int typelen = 0, mlen, siglen;
        gpointer res;
-       const IcallTypeDesc *imap;
+#ifndef DISABLE_ICALL_TABLES
+       const IcallTypeDesc *imap = NULL;
+#endif
 
        g_assert (method != NULL);
 
@@ -8025,7 +8070,9 @@ mono_lookup_internal_call (MonoMethod *method)
                        return NULL;
        }
 
+#ifndef DISABLE_ICALL_TABLES
        imap = find_class_icalls (mname);
+#endif
 
        mname [typelen] = ':';
        mname [typelen + 1] = ':';
@@ -8060,6 +8107,15 @@ mono_lookup_internal_call (MonoMethod *method)
                return res;
        }
 
+#ifdef DISABLE_ICALL_TABLES
+       mono_loader_unlock ();
+       /* Fail only when the result is actually used */
+       /* mono_marshal_get_native_wrapper () depends on this */
+       if (method->klass == mono_defaults.string_class && !strcmp (method->name, ".ctor"))
+               return ves_icall_System_String_ctor_RedirectToCreateString;
+       else
+               return no_icall_table;
+#else
        /* it wasn't found in the static call tables */
        if (!imap) {
                mono_loader_unlock ();
@@ -8089,6 +8145,78 @@ mono_lookup_internal_call (MonoMethod *method)
        mono_loader_unlock ();
 
        return NULL;
+#endif
+}
+
+#ifdef ENABLE_ICALL_SYMBOL_MAP
+static int
+func_cmp (gconstpointer key, gconstpointer p)
+{
+       return (gsize)key - (gsize)*(gsize*)p;
+}
+#endif
+
+/*
+ * mono_lookup_icall_symbol:
+ *
+ *   Given the icall METHOD, returns its C symbol.
+ */
+const char*
+mono_lookup_icall_symbol (MonoMethod *m)
+{
+#ifdef DISABLE_ICALL_TABLES
+       g_assert_not_reached ();
+       return NULL;
+#else
+#ifdef ENABLE_ICALL_SYMBOL_MAP
+       gpointer func;
+       int i;
+       gpointer slot;
+       static gconstpointer *functions_sorted;
+       static const char**symbols_sorted;
+       static gboolean inited;
+
+       if (!inited) {
+               gboolean changed;
+
+               functions_sorted = g_malloc (G_N_ELEMENTS (icall_functions) * sizeof (gpointer));
+               memcpy (functions_sorted, icall_functions, G_N_ELEMENTS (icall_functions) * sizeof (gpointer));
+               symbols_sorted = g_malloc (G_N_ELEMENTS (icall_functions) * sizeof (gpointer));
+               memcpy (symbols_sorted, icall_symbols, G_N_ELEMENTS (icall_functions) * sizeof (gpointer));
+               /* Bubble sort the two arrays */
+               changed = TRUE;
+               while (changed) {
+                       changed = FALSE;
+                       for (i = 0; i < G_N_ELEMENTS (icall_functions) - 1; ++i) {
+                               if (functions_sorted [i] > functions_sorted [i + 1]) {
+                                       gconstpointer tmp;
+
+                                       tmp = functions_sorted [i];
+                                       functions_sorted [i] = functions_sorted [i + 1];
+                                       functions_sorted [i + 1] = tmp;
+                                       tmp = symbols_sorted [i];
+                                       symbols_sorted [i] = symbols_sorted [i + 1];
+                                       symbols_sorted [i + 1] = tmp;
+                                       changed = TRUE;
+                               }
+                       }
+               }
+       }
+
+       func = mono_lookup_internal_call (m);
+       if (!func)
+               return NULL;
+       slot = bsearch (func, functions_sorted, G_N_ELEMENTS (icall_functions), sizeof (gpointer), func_cmp);
+       if (!slot)
+               return NULL;
+       g_assert (slot);
+       return symbols_sorted [(gpointer*)slot - (gpointer*)functions_sorted];
+#else
+       fprintf (stderr, "icall symbol maps not enabled, pass --enable-icall-symbol-map to configure.\n");
+       g_assert_not_reached ();
+       return 0;
+#endif
+#endif
 }
 
 static MonoType*
@@ -8225,6 +8353,25 @@ mono_get_jit_icall_info (void)
        return jit_icall_hash_name;
 }
 
+/*
+ * mono_lookup_jit_icall_symbol:
+ *
+ *   Given the jit icall NAME, returns its C symbol if possible, or NULL.
+ */
+const char*
+mono_lookup_jit_icall_symbol (const char *name)
+{
+       MonoJitICallInfo *info;
+       const char *res = NULL;
+
+       mono_loader_lock ();
+       info = g_hash_table_lookup (jit_icall_hash_name, name);
+       if (info)
+               res = info->c_symbol;
+       mono_loader_unlock ();
+       return res;
+}
+
 void
 mono_register_jit_icall_wrapper (MonoJitICallInfo *info, gconstpointer wrapper)
 {
@@ -8234,7 +8381,7 @@ mono_register_jit_icall_wrapper (MonoJitICallInfo *info, gconstpointer wrapper)
 }
 
 MonoJitICallInfo *
-mono_register_jit_icall (gconstpointer func, const char *name, MonoMethodSignature *sig, gboolean is_save)
+mono_register_jit_icall_full (gconstpointer func, const char *name, MonoMethodSignature *sig, gboolean is_save, const char *c_symbol)
 {
        MonoJitICallInfo *info;
        
@@ -8258,6 +8405,7 @@ mono_register_jit_icall (gconstpointer func, const char *name, MonoMethodSignatu
        info->name = name;
        info->func = func;
        info->sig = sig;
+       info->c_symbol = c_symbol;
 
        if (is_save) {
                info->wrapper = func;
@@ -8271,3 +8419,10 @@ mono_register_jit_icall (gconstpointer func, const char *name, MonoMethodSignatu
        mono_loader_unlock ();
        return info;
 }
+
+MonoJitICallInfo *
+mono_register_jit_icall (gconstpointer func, const char *name, MonoMethodSignature *sig, gboolean is_save)
+{
+       return mono_register_jit_icall_full (func, name, sig, is_save, NULL);
+}
+