Fri Mar 29 16:09:54 CET 2002 Paolo Molaro <lupus@ximian.com>
[mono.git] / mono / metadata / icall.c
index aec7134d338dffacf823f0b44b03edb4f1225760..1488817681967e12803924967faf154128d9fc58 100644 (file)
@@ -14,6 +14,9 @@
 #include <string.h>
 #include <sys/time.h>
 #include <unistd.h>
+#if defined (PLATFORM_WIN32)
+#include <stdlib.h>
+#endif
 
 #include <mono/metadata/object.h>
 #include <mono/metadata/threads.h>
@@ -28,6 +31,8 @@
 #include <mono/metadata/unicode.h>
 #include <mono/metadata/appdomain.h>
 #include <mono/metadata/rand.h>
+#include <mono/metadata/sysmath.h>
+#include <mono/metadata/debug-symfile.h>
 #include <mono/io-layer/io-layer.h>
 #include "decimal.h"
 
@@ -355,17 +360,11 @@ ves_icall_System_Array_SetValue (MonoObject *this, MonoObject *value,
                                 MonoObject *idxs)
 {
        MonoArray *ao, *io, *vo;
-       MonoClass *ac, *ic, *vc;
+       MonoClass *ac, *ic;
        gint32 i, pos, *ind;
 
        MONO_CHECK_ARG_NULL (idxs);
 
-       vo = (MonoArray *)value;
-       if (vo)
-               vc = (MonoClass *)vo->obj.vtable->klass;
-       else
-               vc = NULL;
-
        io = (MonoArray *)idxs;
        ic = (MonoClass *)io->obj.vtable->klass;
        
@@ -393,7 +392,6 @@ ves_icall_System_Array_SetValue (MonoObject *this, MonoObject *value,
 static MonoArray *
 ves_icall_System_Array_CreateInstanceImpl (MonoReflectionType *type, MonoArray *lengths, MonoArray *bounds)
 {
-       MonoClass *klass;
        MonoClass *aklass;
        MonoArray *array;
        gint32 *sizes, i;
@@ -409,8 +407,7 @@ ves_icall_System_Array_CreateInstanceImpl (MonoReflectionType *type, MonoArray *
                if (mono_array_get (lengths, gint32, i) < 0)
                        mono_raise_exception (mono_get_exception_argument_out_of_range (NULL));
 
-       klass = mono_class_from_mono_type (type->type);
-       aklass = mono_array_class_get (klass, mono_array_length (lengths));
+       aklass = mono_array_class_get (type->type, mono_array_length (lengths));
 
        sizes = alloca (aklass->rank * sizeof(guint32) * 2);
        for (i = 0; i < aklass->rank; ++i) {
@@ -419,7 +416,6 @@ ves_icall_System_Array_CreateInstanceImpl (MonoReflectionType *type, MonoArray *
                        sizes [i + aklass->rank] = mono_array_get (bounds, gint32, i);
                else
                        sizes [i + aklass->rank] = 0;
-               sizes [i] -= sizes [i + aklass->rank];
        }
 
        array = mono_array_new_full (mono_domain_get (), aklass, sizes, sizes + aklass->rank);
@@ -456,7 +452,7 @@ ves_icall_System_Array_FastCopy (MonoArray *source, int source_idx, MonoArray* d
 {
        int element_size = mono_array_element_size (source->obj.vtable->klass);
        void * dest_addr = mono_array_addr_with_size (dest, element_size, dest_idx);
-       void * source_addr = mono_array_addr_with_size (source, element_size, dest_idx);
+       void * source_addr = mono_array_addr_with_size (source, element_size, source_idx);
 
        memcpy (dest_addr, source_addr, element_size * length);
 }
@@ -512,6 +508,37 @@ ves_icall_System_Object_MemberwiseClone (MonoObject *this)
        return mono_object_clone (this);
 }
 
+static gint32
+ves_icall_System_Object_GetHashCode (MonoObject *this)
+{
+       return *((gint32 *)this - 1);
+}
+
+/*
+ * A hash function for value types. I have no idea if this is a good hash 
+ * function (its similar to g_str_hash).
+ */
+static gint32
+ves_icall_System_ValueType_GetHashCode (MonoObject *this)
+{
+       gint32 i, size;
+       const char *p;
+       guint h;
+
+       MONO_CHECK_ARG_NULL (this);
+
+       size = this->vtable->klass->instance_size - sizeof (MonoObject);
+
+       p = (char *)this + sizeof (MonoObject);
+
+       for (i = 0; i < size; i++) {
+               h = (h << 5) - h + *p;
+               p++;
+       }
+
+       return h;
+}
+
 static MonoReflectionType *
 ves_icall_System_Object_GetType (MonoObject *obj)
 {
@@ -532,24 +559,34 @@ ves_icall_AssemblyBuilder_getToken (MonoReflectionAssemblyBuilder *assb, MonoObj
 }
 
 static gint32
-ves_icall_get_data_chunk (MonoReflectionAssemblyBuilder *assb, gint32 type, MonoArray *buf)
+ves_icall_get_data_chunk (MonoReflectionAssemblyBuilder *assb, gint32 offset, MonoArray *buf)
 {
        int count;
 
-       if (type == 0) { /* get the header */
+       if (offset == 0) { /* get the header */
                count = mono_image_get_header (assb, (char*)buf->vector, buf->bounds->length);
                if (count != -1)
                        return count;
        } else {
                MonoDynamicAssembly *ass = assb->dynamic_assembly;
                char *p = mono_array_addr (buf, char, 0);
+               int chunklen;
+               offset--;
                count = ass->code.index + ass->meta_size;
-               if (count > buf->bounds->length) {
-                       g_print ("assembly data exceed supplied buffer\n");
-                       return 0;
-               }
-               memcpy (p, ass->code.data, ass->code.index);
-               memcpy (p + ass->code.index, ass->assembly.image->raw_metadata, ass->meta_size);
+               if (count - offset > buf->bounds->length) {
+                       count =  buf->bounds->length;
+               } else
+                       count = count - offset;
+               if (offset < ass->code.index) {
+                       chunklen = ass->code.index - offset;
+                       memcpy (p, ass->code.data + offset, chunklen);
+                       offset += chunklen;
+                       p += chunklen;
+                       chunklen = count - chunklen;
+               } else
+                       chunklen = count;
+               offset -= ass->code.index;
+               memcpy (p, ass->assembly.image->raw_metadata + offset, chunklen);
                return count;
        }
        
@@ -560,7 +597,7 @@ static MonoReflectionType*
 ves_icall_type_from_name (MonoString *name)
 {
        MonoDomain *domain = mono_domain_get (); 
-       MonoClass *klass;
+       MonoType *type;
        MonoImage *image;
        MonoTypeNameParse info;
        gchar *str;
@@ -569,6 +606,7 @@ ves_icall_type_from_name (MonoString *name)
        /*g_print ("requested type %s\n", str);*/
        if (!mono_reflection_parse_type (str, &info)) {
                g_free (str);
+               g_list_free (info.modifiers);
                return NULL;
        }
 
@@ -577,46 +615,28 @@ ves_icall_type_from_name (MonoString *name)
                /* do we need to load if it's not already loaded? */
                if (!image) {
                        g_free (str);
+                       g_list_free (info.modifiers);
                        return NULL;
                }
        } else
                image = mono_defaults.corlib;
-       if (info.nest_name) {
-               klass = mono_class_from_name (image, info.nest_name_space, info.nest_name);
-               if (klass) {
-                       GList *nested;
-                       mono_class_init (klass);
-                       nested = klass->nested_classes;
-                       while (nested) {
-                               klass = nested->data;
-                               if (strcmp (klass->name, info.nest_name) == 0 &&
-                                               strcmp (klass->name_space, info.nest_name_space) == 0)
-                                       break;
-                               klass = NULL;
-                       }
-               }
-       } else {
-               klass = mono_class_from_name (image, info.name_space, info.name);
-       }
+
+       type = mono_reflection_get_type (image, &info, FALSE);
        g_free (str);
-       if (!klass)
+       g_list_free (info.modifiers);
+       if (!type)
                return NULL;
-       mono_class_init (klass);
-       if (info.rank)
-               klass = mono_array_class_get (klass, info.rank);
-       
-       if (info.isbyref || info.ispointer) /* hack */
-               return mono_type_get_object (domain, &klass->this_arg);
-       else
-               return mono_type_get_object (domain, &klass->byval_arg);
+       /*g_print ("got it\n");*/
+       return mono_type_get_object (domain, type);
 }
 
 static MonoReflectionType*
 ves_icall_type_from_handle (MonoType *handle)
 {
        MonoDomain *domain = mono_domain_get (); 
+       MonoClass *klass = mono_class_from_mono_type (handle);
 
-       mono_class_init (handle->data.klass);
+       mono_class_init (klass);
        return mono_type_get_object (domain, handle);
 }
 
@@ -806,7 +826,7 @@ ves_icall_get_type_info (MonoType *type, MonoTypeInfo *info)
        info->attrs = class->flags;
        info->rank = class->rank;
        info->assembly = NULL; /* FIXME */
-       if (class->enumtype)
+       if (class->enumtype && class->enum_basetype) /* types that are modifierd typebuilkders may not have enum_basetype set */
                info->etype = mono_type_get_object (domain, class->enum_basetype);
        else if (class->element_class)
                info->etype = mono_type_get_object (domain, &class->element_class->byval_arg);
@@ -818,15 +838,86 @@ ves_icall_get_type_info (MonoType *type, MonoTypeInfo *info)
        info->isprimitive = (type->type >= MONO_TYPE_BOOLEAN) && (type->type <= MONO_TYPE_R8);
 }
 
-static MonoObject*
-ves_icall_InternalInvoke (MonoReflectionMethod *method, MonoObject *this, MonoArray *params) {
-       //MonoMethodSignature *sig = method->method->signature;
+static MonoObject *
+ves_icall_InternalInvoke (MonoReflectionMethod *method, MonoObject *this, MonoArray *params) 
+{
+       MonoMethodSignature *sig = method->method->signature;
+       gpointer *pa;
+       int i;
 
-       /*
-        * Do we need to copy the values so that the called method can't change them?
-        */
+       pa = alloca (sizeof (gpointer) * params->bounds->length);
 
-       return NULL;
+       for (i = 0; i < params->bounds->length; i++) {
+               if (sig->params [i]->byref) {
+                       /* nothing to do */
+               }
+
+               switch (sig->params [i]->type) {
+               case MONO_TYPE_U1:
+               case MONO_TYPE_I1:
+               case MONO_TYPE_BOOLEAN:
+               case MONO_TYPE_U2:
+               case MONO_TYPE_I2:
+               case MONO_TYPE_CHAR:
+               case MONO_TYPE_U:
+               case MONO_TYPE_I:
+               case MONO_TYPE_U4:
+               case MONO_TYPE_I4:
+               case MONO_TYPE_U8:
+               case MONO_TYPE_I8:
+               case MONO_TYPE_VALUETYPE:
+                       pa [i] = (char *)(((gpointer *)params->vector)[i]) + sizeof (MonoObject);
+                       break;
+               case MONO_TYPE_STRING:
+                       pa [i] = (char *)(((gpointer *)params->vector)[i]);
+                       break;
+               default:
+                       g_error ("type 0x%x not handled in invoke", sig->params [i]->type);
+               }
+       }
+
+       if (!strcmp (method->method->name, ".ctor")) {
+               this = mono_object_new (mono_domain_get (), method->method->klass);
+               mono_runtime_invoke (method->method, this, pa);
+               return this;
+       } else
+               return mono_runtime_invoke (method->method, this, pa);
+}
+
+static MonoObject *
+ves_icall_InternalExecute (MonoReflectionMethod *method, MonoObject *this, MonoArray *params, MonoArray **outArgs) 
+{
+       MonoDomain *domain = mono_domain_get (); 
+       MonoMethodSignature *sig = method->method->signature;
+       MonoArray *out_args;
+       MonoObject *result;
+       int i, j, outarg_count = 0;
+
+       for (i = 0; i < params->bounds->length; i++) {
+               if (sig->params [i]->byref) 
+                       outarg_count++;
+       }
+
+       out_args = mono_array_new (domain, mono_defaults.object_class, outarg_count);
+       
+       for (i = 0, j = 0; i < params->bounds->length; i++) {
+               if (sig->params [i]->byref) {
+                       gpointer arg;
+                       arg = mono_array_get (params, gpointer, i);
+                       mono_array_set (out_args, gpointer, j, arg);
+                       j++;
+               }
+       }
+
+       /* fixme: handle constructors? */
+       if (!strcmp (method->method->name, ".ctor"))
+               g_assert_not_reached ();
+
+       result = ves_icall_InternalInvoke (method, this, params);
+
+       *outArgs = out_args;
+
+       return result;
 }
 
 static MonoObject *
@@ -1092,7 +1183,7 @@ handle_parent:
                        mono_defaults.corlib, "System.Reflection", "FieldInfo");
        res = mono_array_new (domain, System_Reflection_FieldInfo, len);
        i = 0;
-       tmp = l;
+       tmp = g_slist_reverse (l);
        for (; tmp; tmp = tmp->next, ++i)
                mono_array_set (res, gpointer, i, tmp->data);
        g_slist_free (l);
@@ -1265,7 +1356,7 @@ handle_parent:
                match = 0;
                l = g_slist_prepend (l, mono_property_get_object (domain, klass, prop));
        }
-       if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
+       if (!l && (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent)))
                goto handle_parent;
        len = g_slist_length (l);
        if (!System_Reflection_PropertyInfo)
@@ -1280,6 +1371,66 @@ handle_parent:
        return res;
 }
 
+static MonoArray*
+ves_icall_Type_GetEvents (MonoReflectionType *type, guint32 bflags)
+{
+       MonoDomain *domain; 
+       GSList *l = NULL, *tmp;
+       static MonoClass *System_Reflection_EventInfo;
+       MonoClass *startklass, *klass;
+       MonoArray *res;
+       MonoMethod *method;
+       MonoEvent *event;
+       int i, len, match;
+
+       domain = ((MonoObject *)type)->vtable->domain;
+       klass = startklass = mono_class_from_mono_type (type->type);
+
+handle_parent: 
+       for (i = 0; i < klass->event.count; ++i) {
+               event = &klass->events [i];
+               match = 0;
+               method = event->add;
+               if (!method)
+                       method = event->remove;
+               if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
+                       if (bflags & BFLAGS_Public)
+                               match++;
+               } else {
+                       if (bflags & BFLAGS_NonPublic)
+                               match++;
+               }
+               if (!match)
+                       continue;
+               match = 0;
+               if (method->flags & METHOD_ATTRIBUTE_STATIC) {
+                       if (bflags & BFLAGS_Static)
+                               match++;
+               } else {
+                       if (bflags & BFLAGS_Instance)
+                               match++;
+               }
+
+               if (!match)
+                       continue;
+               match = 0;
+               l = g_slist_prepend (l, mono_event_get_object (domain, klass, event));
+       }
+       if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
+               goto handle_parent;
+       len = g_slist_length (l);
+       if (!System_Reflection_EventInfo)
+               System_Reflection_EventInfo = mono_class_from_name (
+                       mono_defaults.corlib, "System.Reflection", "EventInfo");
+       res = mono_array_new (domain, System_Reflection_EventInfo, len);
+       i = 0;
+       tmp = l;
+       for (; tmp; tmp = tmp->next, ++i)
+               mono_array_set (res, gpointer, i, tmp->data);
+       g_slist_free (l);
+       return res;
+}
+
 static gpointer
 ves_icall_System_Runtime_InteropServices_Marshal_ReadIntPtr (gpointer ptr)
 {
@@ -1300,66 +1451,34 @@ static guint32 ves_icall_System_Runtime_InteropServices_Marshal_GetLastWin32Erro
 }
 
 static MonoReflectionType*
-ves_icall_System_Reflection_Assembly_GetType (MonoReflectionAssembly *assembly, MonoString *type, MonoBoolean throwOnError, MonoBoolean ignoreCase)
+ves_icall_System_Reflection_Assembly_GetType (MonoReflectionAssembly *assembly, MonoString *name, MonoBoolean throwOnError, MonoBoolean ignoreCase)
 {
        MonoDomain *domain = mono_domain_get (); 
-       /* FIXME : use ignoreCase */
-       gchar *name, *namespace, *str;
-       char *byref, *isarray, *ispointer;
-       guint rank;
-       MonoClass *klass;
+       gchar *str;
+       MonoType *type;
+       MonoTypeNameParse info;
 
-       str = namespace = mono_string_to_utf8 (type);
+       str = mono_string_to_utf8 (name);
        /*g_print ("requested type %s in %s\n", str, assembly->assembly->name);*/
-
-       name = strrchr (str, '.');
-       byref = strrchr (str, '&');
-       ispointer = strrchr (str, '*');
-       if (byref)
-               *byref = 0;
-       if (ispointer)
-               *ispointer = 0;
-       isarray = strrchr (str, '[');
-       if (isarray) {
-               rank = 1;
-               *isarray = 0;
-               while (*isarray) {
-                       if (*isarray == ',')
-                               rank++;
-                       if (*isarray == ']')
-                               break;
-                       ++isarray;
-               }
-       }
-
-       if (name) {
-               *name = 0;
-               ++name;
-       } else {
-               namespace = "";
-               name = str;
+       if (!mono_reflection_parse_type (str, &info)) {
+               g_free (str);
+               g_list_free (info.modifiers);
+               if (throwOnError) /* uhm: this is a parse error, though... */
+                       mono_raise_exception (mono_get_exception_type_load ());
+               return NULL;
        }
 
-       klass = mono_class_from_name (assembly->assembly->image, namespace, name);
+       type = mono_reflection_get_type (assembly->assembly->image, &info, ignoreCase);
        g_free (str);
-       if (!klass) {
+       g_list_free (info.modifiers);
+       if (!type) {
                if (throwOnError)
                        mono_raise_exception (mono_get_exception_type_load ());
                return NULL;
        }
-       if (!klass->inited)
-               mono_class_init (klass);
-
-       if (isarray) {
-               klass = mono_array_class_get (klass, rank);
-               mono_class_init (klass);
-               /*g_print ("got array class %s [%d] (0x%x)\n", klass->element_class->name, klass->rank, klass->this_arg.type);*/
-       }
+       /*g_print ("got it\n");*/
+       return mono_type_get_object (domain, type);
 
-       if (byref || ispointer)
-               return mono_type_get_object (domain, &klass->this_arg);
-       else
-               return mono_type_get_object (domain, &klass->byval_arg);
 }
 
 static MonoString *
@@ -1387,13 +1506,27 @@ ves_icall_System_MonoType_assQualifiedName (MonoReflectionType *object)
        char *append = NULL;
 
        switch (object->type->type) {
+       case MONO_TYPE_ARRAY: {
+               int i, rank = object->type->data.array->rank;
+               char *tmp, *str = g_strdup ("[");
+               klass = mono_class_from_mono_type (object->type->data.array->type);
+               for (i = 1; i < rank; i++) {
+                       tmp = g_strconcat (str, ",", NULL);
+                       g_free (str);
+                       str = tmp;
+               }
+               tmp = g_strconcat (str, "]", NULL);
+               g_free (str);
+               append = tmp;
+               break;
+       }
        case MONO_TYPE_SZARRAY:
-               klass = object->type->data.type->data.klass;
-               append = "[]";
+               klass = mono_class_from_mono_type (object->type->data.type);
+               append = g_strdup ("[]");
                break;
        case MONO_TYPE_PTR:
-               klass = object->type->data.type->data.klass;
-               append = "*";
+               klass = mono_class_from_mono_type (object->type->data.type);
+               append = g_strdup ("*");
                break;
        default:
                klass = object->type->data.klass;
@@ -1405,30 +1538,60 @@ ves_icall_System_MonoType_assQualifiedName (MonoReflectionType *object)
                                   klass->image->assembly_name, NULL);
        res = mono_string_new (domain, fullname);
        g_free (fullname);
+       g_free (append);
 
        return res;
 }
 
 static MonoReflectionType*
-ves_icall_ModuleBuilder_create_modified_type (MonoReflectionType *tb, gint32 arrayrank, MonoBoolean isbyref)
+ves_icall_ModuleBuilder_create_modified_type (MonoReflectionTypeBuilder *tb, MonoString *smodifiers)
 {
        MonoClass *klass;
-
-       klass = mono_class_from_mono_type (tb->type);
-       if (arrayrank)
-               klass = mono_array_class_get (klass, arrayrank);
-       return mono_type_get_object (mono_domain_get (), isbyref? &klass->this_arg: &klass->byval_arg);
-}
-
-static MonoString *
-ves_icall_System_PAL_GetCurrentDirectory (MonoObject *object)
-{
-       MonoDomain *domain = mono_domain_get (); 
-       MonoString *res;
-       gchar *path = g_get_current_dir ();
-       res = mono_string_new (domain, path);
-       g_free (path);
-       return res;
+       int isbyref = 0, rank;
+       char *str = mono_string_to_utf8 (smodifiers);
+       char *p;
+
+       klass = mono_class_from_mono_type (tb->type.type);
+       p = str;
+       /* logic taken from mono_reflection_parse_type(): keep in sync */
+       while (*p) {
+               switch (*p) {
+               case '&':
+                       if (isbyref) /* only one level allowed by the spec */
+                               return NULL;
+                       isbyref = 1;
+                       p++;
+                       return mono_type_get_object (mono_domain_get (), &klass->this_arg);
+                       break;
+               case '*':
+                       klass = mono_ptr_class_get (&klass->byval_arg);
+                       mono_class_init (klass);
+                       p++;
+                       break;
+               case '[':
+                       rank = 1;
+                       p++;
+                       while (*p) {
+                               if (*p == ']')
+                                       break;
+                               if (*p == ',')
+                                       rank++;
+                               else if (*p != '*') /* '*' means unknown lower bound */
+                                       return NULL;
+                               ++p;
+                       }
+                       if (*p != ']')
+                               return NULL;
+                       p++;
+                       klass = mono_array_class_get (&klass->byval_arg, rank);
+                       mono_class_init (klass);
+                       break;
+               default:
+                       break;
+               }
+       }
+       g_free (str);
+       return mono_type_get_object (mono_domain_get (), &klass->byval_arg);
 }
 
 /*
@@ -1539,17 +1702,230 @@ ves_icall_System_CurrentTimeZone_GetTimeZoneData (guint32 year, MonoArray **data
 
                gmtoff = tt.tm_gmtoff;
        }
-
-       return 0;
 #endif
+       return 0;
 }
 
-
 static gpointer
 ves_icall_System_Object_obj_address (MonoObject *this) {
        return this;
 }
 
+/* System.Buffer */
+
+static gint32 
+ves_icall_System_Buffer_ByteLengthInternal (MonoArray *array) {
+       MonoClass *klass;
+       MonoTypeEnum etype;
+       int length, esize;
+       int i;
+
+       klass = array->obj.vtable->klass;
+       etype = klass->element_class->byval_arg.type;
+       if (etype < MONO_TYPE_BOOLEAN || etype > MONO_TYPE_R8)
+               return -1;
+
+       length = 0;
+       for (i = 0; i < klass->rank; ++ i)
+               length += array->bounds [i].length;
+
+       esize = mono_array_element_size (klass);
+       return length * esize;
+}
+
+static gint8 
+ves_icall_System_Buffer_GetByteInternal (MonoArray *array, gint32 index) {
+       return mono_array_get (array, gint8, index);
+}
+
+static void 
+ves_icall_System_Buffer_SetByteInternal (MonoArray *array, gint32 index, gint8 value) {
+       mono_array_set (array, gint8, index, value);
+}
+
+static void 
+ves_icall_System_Buffer_BlockCopyInternal (MonoArray *src, gint32 src_offset, MonoArray *dest, gint32 dest_offset, gint32 count) {
+       char *src_buf, *dest_buf;
+
+       src_buf = (gint8 *)src->vector + src_offset;
+       dest_buf = (gint8 *)dest->vector + dest_offset;
+
+       memcpy (dest_buf, src_buf, count);
+}
+
+static MonoObject *
+ves_icall_Remoting_RealProxy_GetTransparentProxy (MonoObject *this)
+{
+       MonoDomain *domain = mono_domain_get (); 
+       MonoObject *res;
+       MonoRealProxy *rp = ((MonoRealProxy *)this);
+       MonoType *type;
+       MonoClass *klass;
+
+       res = mono_object_new (domain, mono_defaults.transparent_proxy_class);
+       
+       ((MonoTransparentProxy *)res)->rp = this;
+       type = ((MonoReflectionType *)rp->class_to_proxy)->type;
+       klass = mono_class_from_mono_type (type);
+
+       res->vtable = mono_class_proxy_vtable (domain, klass);
+
+       return res;
+}
+
+/* System.Environment */
+
+static MonoString *
+ves_icall_System_Environment_get_MachineName ()
+{
+#if defined (PLATFORM_WIN32)
+       gunichar2 *buf;
+       guint32 len;
+       MonoString *result;
+
+       len = MAX_COMPUTERNAME_LENGTH + 1;
+       buf = g_new (gunichar2, len);
+
+       result = NULL;
+       if (GetComputerName (buf, &len))
+               result = mono_string_new_utf16 (mono_domain_get (), buf, len);
+
+       g_free (buf);
+       return result;
+#else
+       gchar *buf;
+       int len;
+       MonoString *result;
+
+       len = 256;
+       buf = g_new (gchar, len);
+
+       result = NULL;
+       if (gethostname (buf, len) != 0)
+               result = mono_string_new (mono_domain_get (), buf);
+       
+       g_free (buf);
+       return result;
+#endif
+}
+
+static MonoString *
+ves_icall_System_Environment_get_NewLine ()
+{
+#if defined (PLATFORM_WIN32)
+       return mono_string_new (mono_domain_get (), "\r\n");
+#else
+       return mono_string_new (mono_domain_get (), "\n");
+#endif
+}
+
+static MonoString *
+ves_icall_System_Environment_GetEnvironmentVariable (MonoString *name)
+{
+       const gchar *value;
+       gchar *utf8_name;
+
+       if (name == NULL)
+               return NULL;
+
+       utf8_name = mono_string_to_utf8 (name); /* FIXME: this should be ascii */
+       value = g_getenv (utf8_name);
+       g_free (utf8_name);
+
+       if (value == 0)
+               return NULL;
+       
+       return mono_string_new (mono_domain_get (), value);
+}
+
+static MonoArray *
+ves_icall_System_Environment_GetEnvironmentVariableNames ()
+{
+       MonoArray *names;
+       MonoDomain *domain;
+       MonoString *str;
+       gchar **e, **parts;
+       int n;
+
+       n = 0;
+       for (e = environ; *e != 0; ++ e)
+               ++ n;
+
+       domain = mono_domain_get ();
+       names = mono_array_new (domain, mono_defaults.string_class, n);
+
+       n = 0;
+       for (e = environ; *e != 0; ++ e) {
+               parts = g_strsplit (*e, "=", 2);
+               if (*parts != 0) {
+                       str = mono_string_new (domain, *parts);
+                       mono_array_set (names, MonoString *, n, str);
+               }
+
+               g_strfreev (parts);
+
+               ++ n;
+       }
+
+       return names;
+}
+
+static MonoString *
+ves_icall_System_Environment_GetCommandLine ()
+{
+       return NULL;    /* FIXME */
+}
+
+
+void
+ves_icall_MonoMethodMessage_InitMessage (MonoMethodMessage *this, 
+                                        MonoReflectionMethod *method,
+                                        MonoArray *out_args)
+{
+       MonoDomain *domain = mono_domain_get ();
+       MonoMethodSignature *sig = method->method->signature;
+       MonoString *name;
+       int i, j;
+       char **names;
+       guint8 arg_type;
+
+       this->method = method;
+
+       this->args = mono_array_new (domain, mono_defaults.object_class, sig->param_count);
+       this->arg_types = mono_array_new (domain, mono_defaults.byte_class, sig->param_count);
+
+       names = g_new (char *, sig->param_count);
+       mono_method_get_param_names (method->method, (const char **) names);
+       this->names = mono_array_new (domain, mono_defaults.string_class, sig->param_count);
+       
+       for (i = 0; i < sig->param_count; i++) {
+                name = mono_string_new (domain, names [i]);
+                mono_array_set (this->names, gpointer, i, name);       
+       }
+
+       g_free (names);
+       
+       for (i = 0, j = 0; i < sig->param_count; i++) {
+
+               if (sig->params [i]->byref) {
+                       if (out_args) {
+                               gpointer arg = mono_array_get (out_args, gpointer, j);
+                               mono_array_set (this->args, gpointer, i, arg);
+                               j++;
+                       }
+                       arg_type = 2;
+                       if (sig->params [i]->attrs & PARAM_ATTRIBUTE_IN)
+                               arg_type = 1;
+               } else {
+                       arg_type = 1;
+               }
+
+               mono_array_set (this->arg_types, guint8, i, arg_type);
+       }
+}
+
+/* icall map */
+
 static gpointer icall_map [] = {
        /*
         * System.Array
@@ -1570,8 +1946,14 @@ static gpointer icall_map [] = {
         */
        "System.Object::MemberwiseClone", ves_icall_System_Object_MemberwiseClone,
        "System.Object::GetType", ves_icall_System_Object_GetType,
+       "System.Object::GetHashCode", ves_icall_System_Object_GetHashCode,
        "System.Object::obj_address", ves_icall_System_Object_obj_address,
 
+       /*
+        * System.ValueType
+        */
+       "System.ValueType::GetHashCode", ves_icall_System_ValueType_GetHashCode,
+
        /*
         * System.String
         */
@@ -1636,9 +2018,13 @@ static gpointer icall_map [] = {
        "System.Reflection.MonoFieldInfo::get_field_info", ves_icall_get_field_info,
        "System.Reflection.MonoPropertyInfo::get_property_info", ves_icall_get_property_info,
        "System.Reflection.MonoMethod::InternalInvoke", ves_icall_InternalInvoke,
+       "System.Reflection.MonoCMethod::InternalInvoke", ves_icall_InternalInvoke,
        "System.MonoCustomAttrs::GetCustomAttributes", mono_reflection_get_custom_attrs,
        "System.Reflection.Emit.CustomAttributeBuilder::GetBlob", mono_reflection_get_custom_attrs_blob,
        "System.Reflection.MonoField::GetValue", ves_icall_MonoField_GetValue,
+       "System.Reflection.Emit.SignatureHelper::get_signature_local", mono_reflection_sighelper_get_signature_local,
+       "System.Reflection.Emit.SignatureHelper::get_signature_field", mono_reflection_sighelper_get_signature_field,
+
        
        /* System.Enum */
 
@@ -1650,6 +2036,7 @@ static gpointer icall_map [] = {
         * TypeBuilder
         */
        "System.Reflection.Emit.TypeBuilder::setup_internal_class", mono_reflection_setup_internal_class,
+
        
        /*
         * MethodBuilder
@@ -1719,25 +2106,9 @@ static gpointer icall_map [] = {
        "System.MonoType::GetMethods", ves_icall_Type_GetMethods,
        "System.MonoType::GetConstructors", ves_icall_Type_GetConstructors,
        "System.MonoType::GetProperties", ves_icall_Type_GetProperties,
+       "System.MonoType::GetEvents", ves_icall_Type_GetEvents,
        "System.MonoType::GetInterfaces", ves_icall_Type_GetInterfaces,
 
-       "System.PAL.OpSys::GetCurrentDirectory", ves_icall_System_PAL_GetCurrentDirectory,
-
-       /*
-        * System.PAL.OpSys I/O Services
-        */
-       "System.PAL.OpSys::GetStdHandle", ves_icall_System_PAL_OpSys_GetStdHandle,
-       "System.PAL.OpSys::ReadFile", ves_icall_System_PAL_OpSys_ReadFile,
-       "System.PAL.OpSys::WriteFile", ves_icall_System_PAL_OpSys_WriteFile,
-       "System.PAL.OpSys::SetLengthFile", ves_icall_System_PAL_OpSys_SetLengthFile,
-       "System.PAL.OpSys::OpenFile", ves_icall_System_PAL_OpSys_OpenFile,
-       "System.PAL.OpSys::CloseFile", ves_icall_System_PAL_OpSys_CloseFile,
-       "System.PAL.OpSys::SeekFile", ves_icall_System_PAL_OpSys_SeekFile,
-       "System.PAL.OpSys::DeleteFile", ves_icall_System_PAL_OpSys_DeleteFile,
-       "System.PAL.OpSys::ExistsFile", ves_icall_System_PAL_OpSys_ExistsFile,
-       "System.PAL.OpSys::GetFileTime", ves_icall_System_PAL_OpSys_GetFileTime,
-       "System.PAL.OpSys::SetFileTime", ves_icall_System_PAL_OpSys_SetFileTime,
-
        /*
         * System.Net.Sockets I/O Services
         */
@@ -1800,6 +2171,106 @@ static gpointer icall_map [] = {
 
         "System.Security.Cryptography.RNGCryptoServiceProvider::GetBytes", ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_GetBytes,
         "System.Security.Cryptography.RNG_CryptoServiceProvider::GetNonZeroBytes", ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_GetNonZeroBytes,
+       
+       /*
+        * System.Buffer
+        */
+       "System.Buffer::ByteLengthInternal", ves_icall_System_Buffer_ByteLengthInternal,
+       "System.Buffer::GetByteInternal", ves_icall_System_Buffer_GetByteInternal,
+       "System.Buffer::SetByteInternal", ves_icall_System_Buffer_SetByteInternal,
+       "System.Buffer::BlockCopyInternal", ves_icall_System_Buffer_BlockCopyInternal,
+
+       /*
+        * System.IO.MonoIO
+        */
+       "System.IO.MonoIO::GetLastError", ves_icall_System_IO_MonoIO_GetLastError,
+       "System.IO.MonoIO::CreateDirectory", ves_icall_System_IO_MonoIO_CreateDirectory,
+       "System.IO.MonoIO::RemoveDirectory", ves_icall_System_IO_MonoIO_RemoveDirectory,
+       "System.IO.MonoIO::FindFirstFile", ves_icall_System_IO_MonoIO_FindFirstFile,
+       "System.IO.MonoIO::FindNextFile", ves_icall_System_IO_MonoIO_FindNextFile,
+       "System.IO.MonoIO::FindClose", ves_icall_System_IO_MonoIO_FindClose,
+       "System.IO.MonoIO::GetCurrentDirectory", ves_icall_System_IO_MonoIO_GetCurrentDirectory,
+       "System.IO.MonoIO::SetCurrentDirectory", ves_icall_System_IO_MonoIO_SetCurrentDirectory,
+       "System.IO.MonoIO::MoveFile", ves_icall_System_IO_MonoIO_MoveFile,
+       "System.IO.MonoIO::CopyFile", ves_icall_System_IO_MonoIO_CopyFile,
+       "System.IO.MonoIO::DeleteFile", ves_icall_System_IO_MonoIO_DeleteFile,
+       "System.IO.MonoIO::GetFileAttributes", ves_icall_System_IO_MonoIO_GetFileAttributes,
+       "System.IO.MonoIO::SetFileAttributes", ves_icall_System_IO_MonoIO_SetFileAttributes,
+       "System.IO.MonoIO::GetFileStat", ves_icall_System_IO_MonoIO_GetFileStat,
+       "System.IO.MonoIO::Open", ves_icall_System_IO_MonoIO_Open,
+       "System.IO.MonoIO::Close", ves_icall_System_IO_MonoIO_Close,
+       "System.IO.MonoIO::Read", ves_icall_System_IO_MonoIO_Read,
+       "System.IO.MonoIO::Write", ves_icall_System_IO_MonoIO_Write,
+       "System.IO.MonoIO::Seek", ves_icall_System_IO_MonoIO_Seek,
+       "System.IO.MonoIO::GetLength", ves_icall_System_IO_MonoIO_GetLength,
+       "System.IO.MonoIO::SetLength", ves_icall_System_IO_MonoIO_SetLength,
+       "System.IO.MonoIO::SetFileTime", ves_icall_System_IO_MonoIO_SetFileTime,
+       "System.IO.MonoIO::Flush", ves_icall_System_IO_MonoIO_Flush,
+       "System.IO.MonoIO::get_ConsoleOutput", ves_icall_System_IO_MonoIO_get_ConsoleOutput,
+       "System.IO.MonoIO::get_ConsoleInput", ves_icall_System_IO_MonoIO_get_ConsoleInput,
+       "System.IO.MonoIO::get_ConsoleError", ves_icall_System_IO_MonoIO_get_ConsoleError,
+       "System.IO.MonoIO::get_VolumeSeparatorChar", ves_icall_System_IO_MonoIO_get_VolumeSeparatorChar,
+       "System.IO.MonoIO::get_DirectorySeparatorChar", ves_icall_System_IO_MonoIO_get_DirectorySeparatorChar,
+       "System.IO.MonoIO::get_AltDirectorySeparatorChar", ves_icall_System_IO_MonoIO_get_AltDirectorySeparatorChar,
+       "System.IO.MonoIO::get_PathSeparator", ves_icall_System_IO_MonoIO_get_PathSeparator,
+       "System.IO.MonoIO::get_InvalidPathChars", ves_icall_System_IO_MonoIO_get_InvalidPathChars,
+
+       /*
+        * System.Math
+        */
+       "System.Math::Sin", ves_icall_System_Math_Sin,
+        "System.Math::Cos", ves_icall_System_Math_Cos,
+        "System.Math::Tan", ves_icall_System_Math_Tan,
+        "System.Math::Sinh", ves_icall_System_Math_Sinh,
+        "System.Math::Cosh", ves_icall_System_Math_Cosh,
+        "System.Math::Tanh", ves_icall_System_Math_Tanh,
+        "System.Math::Acos", ves_icall_System_Math_Acos,
+        "System.Math::Asin", ves_icall_System_Math_Asin,
+        "System.Math::Atan", ves_icall_System_Math_Atan,
+        "System.Math::Atan2", ves_icall_System_Math_Atan2,
+        "System.Math::Exp", ves_icall_System_Math_Exp,
+        "System.Math::Log", ves_icall_System_Math_Log,
+        "System.Math::Log10", ves_icall_System_Math_Log10,
+        "System.Math::Pow", ves_icall_System_Math_Pow,
+        "System.Math::Sqrt", ves_icall_System_Math_Sqrt,
+
+       /*
+        * System.Environment
+        */
+       "System.Environment::get_MachineName", ves_icall_System_Environment_get_MachineName,
+       "System.Environment::get_NewLine", ves_icall_System_Environment_get_NewLine,
+       "System.Environment::GetEnvironmentVariable", ves_icall_System_Environment_GetEnvironmentVariable,
+       "System.Environment::GetEnvironmentVariableNames", ves_icall_System_Environment_GetEnvironmentVariableNames,
+       "System.Environment::GetCommandLine", ves_icall_System_Environment_GetCommandLine,
+
+       /*
+        * Mono.CSharp.Debugger
+        */
+       "Mono.CSharp.Debugger.MonoSymbolWriter::get_local_type_from_sig", 
+       ves_icall_Debugger_MonoSymbolWriter_get_local_type_from_sig,
+       "Mono.CSharp.Debugger.MonoSymbolWriter::get_method", 
+       ves_icall_Debugger_MonoSymbolWriter_method_from_token,
+       "Mono.CSharp.Debugger.DwarfFileWriter::get_type_token", 
+       ves_icall_Debugger_DwarfFileWriter_get_type_token,
+
+
+       /*
+        * System.Runtime.Remoting
+        */     
+       "System.Runtime.Remoting.RemotingServices::InternalExecute",
+       ves_icall_InternalExecute,
+
+       /*
+        * System.Runtime.Remoting.Messaging
+        */     
+       "System.Runtime.Remoting.Messaging.MonoMethodMessage::InitMessage",
+       ves_icall_MonoMethodMessage_InitMessage,
+       
+       /*
+        * System.Runtime.Remoting.Proxies
+        */     
+       "System.Runtime.Remoting.Proxies.RealProxy::GetTransparentProxy", 
+       ves_icall_Remoting_RealProxy_GetTransparentProxy,
 
        /*
         * add other internal calls here