Wed May 8 12:06:14 CEST 2002 Paolo Molaro <lupus@ximian.com>
[mono.git] / mono / metadata / icall.c
index 2ee2601e9394566b22bbaa94e72a256592d7e9d6..cd140f804176b67c6eedcfe0519218d6f6c7a103 100644 (file)
@@ -4,6 +4,7 @@
  * Authors:
  *   Dietmar Maurer (dietmar@ximian.com)
  *   Paolo Molaro (lupus@ximian.com)
+ *      Patrik Torstensson (patrik.torstensson@labs2.com)
  *
  * (C) 2001 Ximian, Inc.
  */
 #include <mono/metadata/tokentype.h>
 #include <mono/metadata/unicode.h>
 #include <mono/metadata/appdomain.h>
+#include <mono/metadata/gc.h>
 #include <mono/metadata/rand.h>
 #include <mono/metadata/sysmath.h>
 #include <mono/metadata/debug-symfile.h>
+#include <mono/metadata/string-icalls.h>
 #include <mono/io-layer/io-layer.h>
+
+#if defined (PLATFORM_WIN32)
+#include <windows.h>
+#endif
 #include "decimal.h"
 
+static MonoString *
+mono_double_ToStringImpl (double value)
+{
+       /* FIXME: Handle formats, etc. */
+       const gchar *retVal;
+       retVal = g_strdup_printf ("%f", value);
+       return mono_string_new (mono_domain_get (), retVal);
+}
 
 static MonoObject *
 ves_icall_System_Array_GetValueImpl (MonoObject *this, guint32 pos)
@@ -73,10 +88,18 @@ ves_icall_System_Array_GetValue (MonoObject *this, MonoObject *idxs)
        ac = (MonoClass *)ao->obj.vtable->klass;
 
        g_assert (ic->rank == 1);
-       if (io->bounds [0].length != ac->rank)
+       if (io->bounds != NULL || io->max_length !=  ac->rank)
                mono_raise_exception (mono_get_exception_argument (NULL, NULL));
 
        ind = (guint32 *)io->vector;
+
+       if (ao->bounds == NULL) {
+               if (*ind < 0 || *ind >= ao->max_length)
+                       mono_raise_exception (mono_get_exception_index_out_of_range ());
+
+               return ves_icall_System_Array_GetValueImpl (this, *ind);
+       }
+       
        for (i = 0; i < ac->rank; i++)
                if ((ind [i] < ao->bounds [i].lower_bound) ||
                    (ind [i] >= ao->bounds [i].length + ao->bounds [i].lower_bound))
@@ -365,10 +388,19 @@ ves_icall_System_Array_SetValue (MonoArray *this, MonoObject *value,
        ac = this->obj.vtable->klass;
 
        g_assert (ic->rank == 1);
-       if (idxs->bounds [0].length != ac->rank)
+       if (idxs->bounds != NULL || idxs->max_length != ac->rank)
                mono_raise_exception (mono_get_exception_argument (NULL, NULL));
 
        ind = (guint32 *)idxs->vector;
+
+       if (this->bounds == NULL) {
+               if (*ind < 0 || *ind >= this->max_length)
+                       mono_raise_exception (mono_get_exception_index_out_of_range ());
+
+               ves_icall_System_Array_SetValueImpl (this, value, *ind);
+               return;
+       }
+       
        for (i = 0; i < ac->rank; i++)
                if ((ind [i] < this->bounds [i].lower_bound) ||
                    (ind [i] >= this->bounds [i].length + this->bounds [i].lower_bound))
@@ -428,6 +460,10 @@ ves_icall_System_Array_GetLength (MonoArray *this, gint32 dimension)
        gint32 rank = ((MonoObject *)this)->vtable->klass->rank;
        if ((dimension < 0) || (dimension >= rank))
                mono_raise_exception (mono_get_exception_index_out_of_range ());
+       
+       if (this->bounds == NULL)
+               return this->max_length;
+       
        return this->bounds [dimension].length;
 }
 
@@ -437,6 +473,10 @@ ves_icall_System_Array_GetLowerBound (MonoArray *this, gint32 dimension)
        gint32 rank = ((MonoObject *)this)->vtable->klass->rank;
        if ((dimension < 0) || (dimension >= rank))
                mono_raise_exception (mono_get_exception_index_out_of_range ());
+       
+       if (this->bounds == NULL)
+               return 0;
+       
        return this->bounds [dimension].lower_bound;
 }
 
@@ -449,7 +489,7 @@ ves_icall_System_Array_FastCopy (MonoArray *source, int source_idx, MonoArray* d
 
        g_assert (dest_idx + length <= mono_array_length (dest));
        g_assert (source_idx + length <= mono_array_length (source));
-       memcpy (dest_addr, source_addr, element_size * length);
+       memmove (dest_addr, source_addr, element_size * length);
 }
 
 static void
@@ -459,8 +499,11 @@ ves_icall_InitializeArray (MonoArray *array, MonoClassField *field_handle)
        guint32 size = mono_array_element_size (klass);
        int i;
 
-       for (i = 0; i < klass->rank; ++i) 
-               size *= array->bounds [i].length;
+       if (array->bounds == NULL)
+               size *= array->max_length;
+       else
+               for (i = 0; i < klass->rank; ++i) 
+                       size *= array->bounds [i].length;
 
        memcpy (mono_array_addr (array, char, 0), field_handle->data, size);
 
@@ -524,7 +567,7 @@ ves_icall_System_ValueType_GetHashCode (MonoObject *this)
 
        size = this->vtable->klass->instance_size - sizeof (MonoObject);
 
-       p = (char *)this + sizeof (MonoObject);
+       p = (const char *)this + sizeof (MonoObject);
 
        for (i = 0; i < size; i++) {
                h = (h << 5) - h + *p;
@@ -534,6 +577,25 @@ ves_icall_System_ValueType_GetHashCode (MonoObject *this)
        return h;
 }
 
+static MonoBoolean
+ves_icall_System_ValueType_Equals (MonoObject *this, MonoObject *that)
+{
+       gint32 size;
+       const char *p, *s;
+
+       MONO_CHECK_ARG_NULL (that);
+
+       if (this->vtable != that->vtable)
+               return FALSE;
+
+       size = this->vtable->klass->instance_size - sizeof (MonoObject);
+
+       p = (const char *)this + sizeof (MonoObject);
+       s = (const char *)that + sizeof (MonoObject);
+
+       return memcmp (p, s, size)? FALSE: TRUE;
+}
+
 static MonoReflectionType *
 ves_icall_System_Object_GetType (MonoObject *obj)
 {
@@ -554,38 +616,44 @@ ves_icall_AssemblyBuilder_getToken (MonoReflectionAssemblyBuilder *assb, MonoObj
 }
 
 static gint32
-ves_icall_get_data_chunk (MonoReflectionAssemblyBuilder *assb, gint32 offset, MonoArray *buf)
+ves_icall_AssemblyBuilder_getPEHeader (MonoReflectionAssemblyBuilder *assb, MonoArray *buf, gint32 *data_size)
 {
-       int count;
+       int count, hsize;
+       MonoDynamicAssembly *ass = assb->dynamic_assembly;
 
-       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 - 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;
-       }
+       hsize = mono_image_get_header (assb, (char*)buf->vector, mono_array_length (buf));
+       if (hsize < 0)
+               return hsize;
+       count = ass->code.index + ass->meta_size;
+       count += 512 - 1;
+       count &= ~(512 - 1);
+       *data_size = count;
+
+       return hsize;
+}
+
+static gint32
+ves_icall_AssemblyBuilder_getDataChunk (MonoReflectionAssemblyBuilder *assb, MonoArray *buf)
+{
+       int count, real_data;
+       MonoDynamicAssembly *ass = assb->dynamic_assembly;
+       char *p = mono_array_addr (buf, char, 0);
        
-       return 0;
+       count = real_data = ass->code.index + ass->meta_size;
+       count += 512 - 1;
+       count &= ~(512 - 1);
+       if (count > mono_array_length (buf))
+               return -1;
+       count -= real_data;
+       
+       memcpy (p, ass->code.data, ass->code.index);
+       p += ass->code.index;
+       memcpy (p, ass->assembly.image->raw_metadata, ass->meta_size);
+       p += ass->meta_size;
+       /* null-pad section */
+       memset (p, 0, count);
+
+       return real_data + count;
 }
 
 static MonoReflectionType*
@@ -700,7 +768,6 @@ ves_icall_get_method_info (MonoMethod *method, MonoMethodInfo *info)
 
        info->parent = mono_type_get_object (domain, &method->klass->byval_arg);
        info->ret = mono_type_get_object (domain, method->signature->ret);
-       info->name = mono_string_new (domain, method->name);
        info->attrs = method->flags;
        info->implattrs = method->iflags;
 }
@@ -809,6 +876,18 @@ ves_icall_Type_GetInterfaces (MonoReflectionType* type)
        return intf;
 }
 
+static MonoReflectionType*
+ves_icall_MonoType_GetElementType (MonoReflectionType *type)
+{
+       MonoClass *class = mono_class_from_mono_type (type->type);
+       if (class->enumtype && class->enum_basetype) /* types that are modifierd typebuilkders may not have enum_basetype set */
+               return mono_type_get_object (mono_object_domain (type), class->enum_basetype);
+       else if (class->element_class)
+               return mono_type_get_object (mono_object_domain (type), &class->element_class->byval_arg);
+       else
+               return NULL;
+}
+
 static void
 ves_icall_get_type_info (MonoType *type, MonoTypeInfo *info)
 {
@@ -836,48 +915,7 @@ ves_icall_get_type_info (MonoType *type, MonoTypeInfo *info)
 static MonoObject *
 ves_icall_InternalInvoke (MonoReflectionMethod *method, MonoObject *this, MonoArray *params) 
 {
-       MonoMethodSignature *sig = method->method->signature;
-       gpointer *pa;
-       int i;
-
-       pa = alloca (sizeof (gpointer) * params->bounds->length);
-
-       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:
-               case MONO_TYPE_OBJECT:
-                       pa [i] = (char *)(((gpointer *)params->vector)[i]);
-                       break;
-               default:
-                       g_error ("type 0x%x not handled in ves_icall_InternalInvoke", 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);
+       return mono_runtime_invoke_array (method->method, this, params);
 }
 
 static MonoObject *
@@ -952,14 +990,14 @@ ves_icall_InternalExecute (MonoReflectionMethod *method, MonoObject *this, MonoA
                }
        }
 
-       for (i = 0; i < params->bounds->length; i++) {
+       for (i = 0; i < mono_array_length (params); 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++) {
+       for (i = 0, j = 0; i < mono_array_length (params); i++) {
                if (sig->params [i]->byref) {
                        gpointer arg;
                        arg = mono_array_get (params, gpointer, i);
@@ -972,7 +1010,7 @@ ves_icall_InternalExecute (MonoReflectionMethod *method, MonoObject *this, MonoA
        if (!strcmp (method->method->name, ".ctor"))
                g_assert_not_reached ();
 
-       result = ves_icall_InternalInvoke (method, this, params);
+       result = mono_runtime_invoke_array (method->method, this, params);
 
        *outArgs = out_args;
 
@@ -1260,11 +1298,11 @@ ves_icall_Type_GetMethods (MonoReflectionType *type, guint32 bflags)
        MonoMethod *method;
        MonoObject *member;
        int i, len, match;
-
+               
        domain = ((MonoObject *)type)->vtable->domain;
        klass = startklass = mono_class_from_mono_type (type->type);
 
-handle_parent: 
+handle_parent:
        for (i = 0; i < klass->method.count; ++i) {
                match = 0;
                method = klass->methods [i];
@@ -1307,6 +1345,7 @@ handle_parent:
        for (; tmp; tmp = tmp->next, ++i)
                mono_array_set (res, gpointer, i, tmp->data);
        g_slist_free (l);
+
        return res;
 }
 
@@ -1385,7 +1424,7 @@ ves_icall_Type_GetProperties (MonoReflectionType *type, guint32 bflags)
        domain = ((MonoObject *)type)->vtable->domain;
        klass = startklass = mono_class_from_mono_type (type->type);
 
-handle_parent: 
+handle_parent:
        for (i = 0; i < klass->property.count; ++i) {
                prop = &klass->properties [i];
                match = 0;
@@ -1490,6 +1529,46 @@ handle_parent:
        return res;
 }
 
+static MonoArray*
+ves_icall_Type_GetNestedTypes (MonoReflectionType *type, guint32 bflags)
+{
+       MonoDomain *domain; 
+       GSList *l = NULL, *tmp;
+       GList *tmpn;
+       MonoClass *startklass, *klass;
+       MonoArray *res;
+       MonoObject *member;
+       int i, len, match;
+       MonoClass *nested;
+
+       domain = ((MonoObject *)type)->vtable->domain;
+       klass = startklass = mono_class_from_mono_type (type->type);
+
+       for (tmpn = klass->nested_classes; tmpn; tmpn = tmpn->next) {
+               match = 0;
+               nested = tmpn->data;
+               if ((nested->flags & TYPE_ATTRIBUTE_VISIBILITY_MASK) == TYPE_ATTRIBUTE_NESTED_PUBLIC) {
+                       if (bflags & BFLAGS_Public)
+                               match++;
+               } else {
+                       if (bflags & BFLAGS_NonPublic)
+                               match++;
+               }
+               if (!match)
+                       continue;
+               member = (MonoObject*)mono_type_get_object (domain, &nested->byval_arg);
+               l = g_slist_prepend (l, member);
+       }
+       len = g_slist_length (l);
+       res = mono_array_new (domain, mono_defaults.monotype_class, len);
+       i = 0;
+       tmp = g_slist_reverse (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)
 {
@@ -1524,6 +1603,7 @@ ves_icall_System_Reflection_Assembly_GetType (MonoReflectionAssembly *assembly,
                g_list_free (info.modifiers);
                if (throwOnError) /* uhm: this is a parse error, though... */
                        mono_raise_exception (mono_get_exception_type_load ());
+               /*g_print ("failed parse\n");*/
                return NULL;
        }
 
@@ -1533,9 +1613,10 @@ ves_icall_System_Reflection_Assembly_GetType (MonoReflectionAssembly *assembly,
        if (!type) {
                if (throwOnError)
                        mono_raise_exception (mono_get_exception_type_load ());
+               /* g_print ("failed find\n"); */
                return NULL;
        }
-       /*g_print ("got it\n");*/
+       /* g_print ("got it\n"); */
        return mono_type_get_object (domain, type);
 
 }
@@ -1567,6 +1648,18 @@ ves_icall_System_MonoType_getFullName (MonoReflectionType *object)
        return res;
 }
 
+static void
+ves_icall_System_Reflection_Assembly_FillName (MonoReflectionAssembly *assembly, MonoReflectionAssemblyName *aname)
+{
+       MonoAssemblyName *name = &assembly->assembly->aname;
+
+       if (strcmp (name->name, "corlib") == 0)
+               aname->name = mono_string_new (mono_object_domain (assembly), "mscorlib");
+       else
+               aname->name = mono_string_new (mono_object_domain (assembly), name->name);
+       aname->major = name->major;
+}
+
 static MonoArray*
 ves_icall_System_Reflection_Assembly_GetTypes (MonoReflectionAssembly *assembly, MonoBoolean exportedOnly)
 {
@@ -1617,10 +1710,13 @@ ves_icall_ModuleBuilder_create_modified_type (MonoReflectionTypeBuilder *tb, Mon
        while (*p) {
                switch (*p) {
                case '&':
-                       if (isbyref) /* only one level allowed by the spec */
+                       if (isbyref) { /* only one level allowed by the spec */
+                               g_free (str);
                                return NULL;
+                       }
                        isbyref = 1;
                        p++;
+                       g_free (str);
                        return mono_type_get_object (mono_domain_get (), &klass->this_arg);
                        break;
                case '*':
@@ -1636,12 +1732,16 @@ ves_icall_ModuleBuilder_create_modified_type (MonoReflectionTypeBuilder *tb, Mon
                                        break;
                                if (*p == ',')
                                        rank++;
-                               else if (*p != '*') /* '*' means unknown lower bound */
+                               else if (*p != '*') { /* '*' means unknown lower bound */
+                                       g_free (str);
                                        return NULL;
+                               }
                                ++p;
                        }
-                       if (*p != ']')
+                       if (*p != ']') {
+                               g_free (str);
                                return NULL;
+                       }
                        p++;
                        klass = mono_array_class_get (&klass->byval_arg, rank);
                        mono_class_init (klass);
@@ -1663,7 +1763,14 @@ ves_icall_ModuleBuilder_create_modified_type (MonoReflectionTypeBuilder *tb, Mon
 static gint64
 ves_icall_System_DateTime_GetNow (void)
 {
-#ifndef PLATFORM_WIN32
+#ifdef PLATFORM_WIN32
+       SYSTEMTIME st;
+       FILETIME ft;
+       
+       GetLocalTime (&st);
+       SystemTimeToFileTime (&st, &ft);
+       return (gint64)504911232000000000L + (((gint64)ft.dwHighDateTime)<<32) | ft.dwLowDateTime;
+#else
        /* FIXME: put this in io-layer and call it GetLocalTime */
        struct timeval tv;
        gint64 res;
@@ -1672,10 +1779,9 @@ ves_icall_System_DateTime_GetNow (void)
                res = (((gint64)tv.tv_sec + EPOCH_ADJUST)* 1000000 + tv.tv_usec)*10;
                return res;
        }
-
        /* fixme: raise exception */
-#endif
        return 0;
+#endif
 }
 
 /*
@@ -1710,8 +1816,16 @@ ves_icall_System_CurrentTimeZone_GetTimeZoneData (guint32 year, MonoArray **data
        start.tm_year = year-1900;
 
        t = mktime (&start);
-       gmtoff = start.tm_gmtoff;
-
+#if defined (HAVE_TIMEZONE)
+#define gmt_offset(x) (-1 * (((timezone / 60 / 60) - daylight) * 100))
+#elif defined (HAVE_TM_GMTOFF)
+#define gmt_offset(x) x.tm_gmtoff
+#else
+#error Neither HAVE_TIMEZONE nor HAVE_TM_GMTOFF defined. Rerun autoheader, autoconf, etc.
+#endif
+       
+       gmtoff = gmt_offset (start);
+       
        MONO_CHECK_ARG_NULL (data);
        MONO_CHECK_ARG_NULL (names);
 
@@ -1725,7 +1839,8 @@ ves_icall_System_CurrentTimeZone_GetTimeZoneData (guint32 year, MonoArray **data
                tt = *localtime (&t);
 
                /* Daylight saving starts or ends here. */
-               if (tt.tm_gmtoff != gmtoff) {
+               if (gmt_offset (tt) != gmtoff) {
+                       char tzone[10];
                        struct tm tt1;
                        time_t t1;
 
@@ -1734,36 +1849,69 @@ ves_icall_System_CurrentTimeZone_GetTimeZoneData (guint32 year, MonoArray **data
                        do {
                                t1 -= 3600;
                                tt1 = *localtime (&t1);
-                       } while (tt1.tm_gmtoff != gmtoff);
+                       } while (gmt_offset (tt1) != gmtoff);
 
                        /* Try to find the exact minute when daylight saving starts/ends. */
                        do {
                                t1 += 60;
                                tt1 = *localtime (&t1);
-                       } while (tt1.tm_gmtoff == gmtoff);
-
+                       } while (gmt_offset (tt1) == gmtoff);
+                       
+                       strftime (tzone, 10, "%Z", &tt);
+                       
                        /* Write data, if we're already in daylight saving, we're done. */
                        if (is_daylight) {
-                               mono_array_set ((*names), gpointer, 0, mono_string_new (domain, tt.tm_zone));
+                               mono_array_set ((*names), gpointer, 0, mono_string_new (domain, tzone));
                                mono_array_set ((*data), gint64, 1, ((gint64)t1 + EPOCH_ADJUST) * 10000000L);
                                return 1;
                        } else {
-                               mono_array_set ((*names), gpointer, 1, mono_string_new (domain, tt.tm_zone));
+                               mono_array_set ((*names), gpointer, 1, mono_string_new (domain, tzone));
                                mono_array_set ((*data), gint64, 0, ((gint64)t1 + EPOCH_ADJUST) * 10000000L);
                                is_daylight = 1;
                        }
 
                        /* This is only set once when we enter daylight saving. */
                        mono_array_set ((*data), gint64, 2, (gint64)gmtoff * 10000000L);
-                       mono_array_set ((*data), gint64, 3, (gint64)(tt.tm_gmtoff - gmtoff) * 10000000L);
+                       mono_array_set ((*data), gint64, 3, (gint64)(gmt_offset (tt) - gmtoff) * 10000000L);
 
-                       gmtoff = tt.tm_gmtoff;
+                       gmtoff = gmt_offset (tt);
                }
 
-               gmtoff = tt.tm_gmtoff;
+               gmtoff = gmt_offset (tt);
        }
+       return 1;
+#else
+       MonoDomain *domain = mono_domain_get ();
+       TIME_ZONE_INFORMATION tz_info;
+       FILETIME ft;
+       int i;
+
+       GetTimeZoneInformation (&tz_info);
+
+       MONO_CHECK_ARG_NULL (data);
+       MONO_CHECK_ARG_NULL (names);
+
+       (*data) = mono_array_new (domain, mono_defaults.int64_class, 4);
+       (*names) = mono_array_new (domain, mono_defaults.string_class, 2);
+
+       for (i = 0; i < 32; ++i)
+               if (!tz_info.DaylightName [i])
+                       break;
+       mono_array_set ((*names), gpointer, 1, mono_string_new_utf16 (domain, tz_info.DaylightName, i));
+       for (i = 0; i < 32; ++i)
+               if (!tz_info.StandardName [i])
+                       break;
+       mono_array_set ((*names), gpointer, 0, mono_string_new_utf16 (domain, tz_info.StandardName, i));
+
+       SystemTimeToFileTime (&tz_info.StandardDate, &ft);
+       mono_array_set ((*data), gint64, 1, ((guint64)ft.dwHighDateTime<<32) | ft.dwLowDateTime);
+       SystemTimeToFileTime (&tz_info.DaylightDate, &ft);
+       mono_array_set ((*data), gint64, 0, ((guint64)ft.dwHighDateTime<<32) | ft.dwLowDateTime);
+       mono_array_set ((*data), gint64, 3, tz_info.Bias + tz_info.StandardBias);
+       mono_array_set ((*data), gint64, 2, tz_info.Bias + tz_info.DaylightBias);
+
+       return 1;
 #endif
-       return 0;
 }
 
 static gpointer
@@ -1785,9 +1933,13 @@ ves_icall_System_Buffer_ByteLengthInternal (MonoArray *array) {
        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;
+       if (array->bounds == NULL)
+               length = array->max_length;
+       else {
+               length = 0;
+               for (i = 0; i < klass->rank; ++ i)
+                       length += array->bounds [i].length;
+       }
 
        esize = mono_array_element_size (klass);
        return length * esize;
@@ -1828,6 +1980,8 @@ ves_icall_Remoting_RealProxy_GetTransparentProxy (MonoObject *this)
        type = ((MonoReflectionType *)rp->class_to_proxy)->type;
        klass = mono_class_from_mono_type (type);
 
+       ((MonoTransparentProxy *)res)->klass = klass;
+
        res->vtable = mono_class_proxy_vtable (domain, klass);
 
        return res;
@@ -1898,6 +2052,11 @@ ves_icall_System_Environment_GetEnvironmentVariable (MonoString *name)
        return mono_string_new (mono_domain_get (), value);
 }
 
+/*
+ * There is no standard way to get at environ.
+ */
+extern char **environ;
+
 static MonoArray *
 ves_icall_System_Environment_GetEnvironmentVariableNames (void)
 {
@@ -1930,58 +2089,11 @@ ves_icall_System_Environment_GetEnvironmentVariableNames (void)
        return names;
 }
 
-static MonoString *
-ves_icall_System_Environment_GetCommandLine (void)
-{
-       return NULL;    /* FIXME */
-}
-
-
-void
-mono_message_init (MonoDomain *domain,
-                  MonoMethodMessage *this, 
-                  MonoReflectionMethod *method,
-                  MonoArray *out_args)
+static void
+ves_icall_System_Environment_Exit (int result)
 {
-       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);
-       }
+       /* we may need to do some cleanup here... */
+       exit (result);
 }
 
 static void
@@ -2006,6 +2118,7 @@ ves_icall_IsTransparentProxy (MonoObject *proxy)
        return 0;
 }
 
+
 /* icall map */
 
 static gconstpointer icall_map [] = {
@@ -2035,12 +2148,46 @@ static gconstpointer icall_map [] = {
         * System.ValueType
         */
        "System.ValueType::GetHashCode", ves_icall_System_ValueType_GetHashCode,
+       "System.ValueType::Equals", ves_icall_System_ValueType_Equals,
 
        /*
         * System.String
         */
-       "System.String::_IsInterned", mono_string_is_interned,
-       "System.String::_Intern", mono_string_intern,
+       
+       "System.String::.ctor(char*)", ves_icall_System_String_ctor_charp,
+       "System.String::.ctor(char*,uint,uint)", ves_icall_System_String_ctor_charp_int_int,
+       "System.String::.ctor(sbyte*)", ves_icall_System_String_ctor_sbytep,
+       "System.String::.ctor(sbyte*,uint,uint)", ves_icall_System_String_ctor_sbytep_int_int,
+       "System.String::.ctor(sbyte*,uint,uint,System.Text.Encoding)", ves_icall_System_String_ctor_encoding,
+       "System.String::.ctor(char[])", ves_icall_System_String_ctor_chara,
+       "System.String::.ctor(char[],uint,uint)", ves_icall_System_String_ctor_chara_int_int,
+       "System.String::.ctor(char,uint)", ves_icall_System_String_ctor_char_int,
+       "System.String::InternalEquals", ves_icall_System_String_InternalEquals,
+       "System.String::InternalJoin", ves_icall_System_String_InternalJoin,
+       "System.String::InternalInsert", ves_icall_System_String_InternalInsert,
+       "System.String::InternalReplace(char,char)", ves_icall_System_String_InternalReplace_Char,
+       "System.String::InternalReplace(string,string)", ves_icall_System_String_InternalReplace_Str,
+       "System.String::InternalRemove", ves_icall_System_String_InternalRemove,
+       "System.String::InternalCopyTo", ves_icall_System_String_InternalCopyTo,
+       "System.String::InternalSplit", ves_icall_System_String_InternalSplit,
+       "System.String::InternalTrim", ves_icall_System_String_InternalTrim,
+       "System.String::InternalIndexOf(char,uint,uint)", ves_icall_System_String_InternalIndexOf_Char,
+       "System.String::InternalIndexOf(string,uint,uint)", ves_icall_System_String_InternalIndexOf_Str,
+       "System.String::InternalIndexOfAny", ves_icall_System_String_InternalIndexOfAny,
+       "System.String::InternalLastIndexOf(char,uint,uint)", ves_icall_System_String_InternalLastIndexOf_Char,
+       "System.String::InternalLastIndexOf(string,uint,uint)", ves_icall_System_String_InternalLastIndexOf_Str,
+       "System.String::InternalLastIndexOfAny", ves_icall_System_String_InternalLastIndexOfAny,
+       "System.String::InternalPad", ves_icall_System_String_InternalPad,
+       "System.String::InternalToLower", ves_icall_System_String_InternalToLower,
+       "System.String::InternalToUpper", ves_icall_System_String_InternalToUpper,
+       "System.String::InternalAllocateStr", ves_icall_System_String_InternalAllocateStr,
+       "System.String::InternalStrcpy(string,uint,string)", ves_icall_System_String_InternalStrcpy_Str,
+       "System.String::InternalStrcpy(string,uint,string,uint,uint)", ves_icall_System_String_InternalStrcpy_StrN,
+       "System.String::InternalIntern", ves_icall_System_String_InternalIntern,
+       "System.String::InternalIsInterned", ves_icall_System_String_InternalIsInterned,
+       "System.String::InternalCompare(string,uint,string,uint,uint,bool)", ves_icall_System_String_InternalCompareStr_N,
+       "System.String::GetHashCode", ves_icall_System_String_GetHashCode,
+       "System.String::get_Chars", ves_icall_System_String_get_Chars,
 
        /*
         * System.AppDomain
@@ -2061,6 +2208,11 @@ static gconstpointer icall_map [] = {
         */
        "System.AppDomainSetup::InitAppDomainSetup", ves_icall_System_AppDomainSetup_InitAppDomainSetup,
 
+       /*
+        * System.Double
+        */
+       "System.Double::ToStringImpl", mono_double_ToStringImpl,
+
        /*
         * System.Decimal
         */
@@ -2087,7 +2239,8 @@ static gconstpointer icall_map [] = {
        /*
         * AssemblyBuilder
         */
-       "System.Reflection.Emit.AssemblyBuilder::getDataChunk", ves_icall_get_data_chunk,
+       "System.Reflection.Emit.AssemblyBuilder::getDataChunk", ves_icall_AssemblyBuilder_getDataChunk,
+       "System.Reflection.Emit.AssemblyBuilder::getPEHeader", ves_icall_AssemblyBuilder_getPEHeader,
        "System.Reflection.Emit.AssemblyBuilder::getUSIndex", mono_image_insert_string,
        "System.Reflection.Emit.AssemblyBuilder::getToken", ves_icall_AssemblyBuilder_getToken,
        "System.Reflection.Emit.AssemblyBuilder::basic_init", mono_image_basic_init,
@@ -2145,9 +2298,11 @@ static gconstpointer icall_map [] = {
         * System.Threading
         */
        "System.Threading.Thread::Thread_internal", ves_icall_System_Threading_Thread_Thread_internal,
+       "System.Threading.Thread::Thread_free_internal", ves_icall_System_Threading_Thread_Thread_free_internal,
        "System.Threading.Thread::Start_internal", ves_icall_System_Threading_Thread_Start_internal,
        "System.Threading.Thread::Sleep_internal", ves_icall_System_Threading_Thread_Sleep_internal,
        "System.Threading.Thread::CurrentThread_internal", ves_icall_System_Threading_Thread_CurrentThread_internal,
+       "System.Threading.Thread::CurrentThreadDomain_internal", ves_icall_System_Threading_Thread_CurrentThreadDomain_internal,
        "System.Threading.Thread::Join_internal", ves_icall_System_Threading_Thread_Join_internal,
        "System.Threading.Thread::SlotHash_lookup", ves_icall_System_Threading_Thread_SlotHash_lookup,
        "System.Threading.Thread::SlotHash_store", ves_icall_System_Threading_Thread_SlotHash_store,
@@ -2175,8 +2330,10 @@ static gconstpointer icall_map [] = {
        "System.Runtime.InteropServices.Marshal::PtrToStringAuto", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAuto,
        "System.Runtime.InteropServices.Marshal::GetLastWin32Error", ves_icall_System_Runtime_InteropServices_Marshal_GetLastWin32Error,
 
+       "System.Reflection.Assembly::LoadFrom", ves_icall_System_Reflection_Assembly_LoadFrom,
        "System.Reflection.Assembly::GetType", ves_icall_System_Reflection_Assembly_GetType,
        "System.Reflection.Assembly::GetTypes", ves_icall_System_Reflection_Assembly_GetTypes,
+       "System.Reflection.Assembly::FillName", ves_icall_System_Reflection_Assembly_FillName,
        "System.Reflection.Assembly::get_code_base", ves_icall_System_Reflection_Assembly_get_code_base,
 
        /*
@@ -2184,6 +2341,7 @@ static gconstpointer icall_map [] = {
         */
        "System.MonoType::getFullName", ves_icall_System_MonoType_getFullName,
        "System.MonoType::type_from_obj", mono_type_type_from_obj,
+       "System.MonoType::GetElementType", ves_icall_MonoType_GetElementType,
        "System.MonoType::get_type_info", ves_icall_get_type_info,
        "System.MonoType::GetFields", ves_icall_Type_GetFields,
        "System.MonoType::GetMethods", ves_icall_Type_GetMethods,
@@ -2191,6 +2349,7 @@ static gconstpointer icall_map [] = {
        "System.MonoType::GetProperties", ves_icall_Type_GetProperties,
        "System.MonoType::GetEvents", ves_icall_Type_GetEvents,
        "System.MonoType::GetInterfaces", ves_icall_Type_GetInterfaces,
+       "System.MonoType::GetNestedTypes", ves_icall_Type_GetNestedTypes,
 
        /*
         * System.Net.Sockets I/O Services
@@ -2248,12 +2407,22 @@ static gconstpointer icall_map [] = {
        "System.DateTime::GetNow", ves_icall_System_DateTime_GetNow,
        "System.CurrentTimeZone::GetTimeZoneData", ves_icall_System_CurrentTimeZone_GetTimeZoneData,
 
+       /*
+        * System.GC
+        */
+       "System.GC::InternalCollect", ves_icall_System_GC_InternalCollect,
+       "System.GC::GetTotalMemory", ves_icall_System_GC_GetTotalMemory,
+       "System.GC::KeepAlive", ves_icall_System_GC_KeepAlive,
+       "System.GC::ReRegisterForFinalize", ves_icall_System_GC_ReRegisterForFinalize,
+       "System.GC::SuppressFinalize", ves_icall_System_GC_SuppressFinalize,
+       "System.GC::WaitForPendingFinalizers", ves_icall_System_GC_WaitForPendingFinalizers,
+
        /*
         * System.Security.Cryptography calls
         */
 
         "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.Security.Cryptography.RNGCryptoServiceProvider::GetNonZeroBytes", ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_GetNonZeroBytes,
        
        /*
         * System.Buffer
@@ -2302,20 +2471,20 @@ static gconstpointer icall_map [] = {
         * 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.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
@@ -2324,7 +2493,8 @@ static gconstpointer icall_map [] = {
        "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,
+       "System.Environment::GetCommandLineArgs", mono_runtime_get_main_args,
+       "System.Environment::Exit", ves_icall_System_Environment_Exit,
 
        /*
         * Mono.CSharp.Debugger
@@ -2357,6 +2527,20 @@ static gconstpointer icall_map [] = {
        "System.Runtime.Remoting.Proxies.RealProxy::GetTransparentProxy", 
        ves_icall_Remoting_RealProxy_GetTransparentProxy,
 
+       /*
+        * System.Threading.Interlocked
+        */
+       "System.Threading.Interlocked::Increment(uint&)", ves_icall_System_Threading_Interlocked_Increment_Int,
+       "System.Threading.Interlocked::Increment(long&)", ves_icall_System_Threading_Interlocked_Increment_Long,
+       "System.Threading.Interlocked::Decrement(uint&)", ves_icall_System_Threading_Interlocked_Decrement_Int,
+       "System.Threading.Interlocked::Decrement(long&)", ves_icall_System_Threading_Interlocked_Decrement_Long,
+       "System.Threading.Interlocked::CompareExchange(uint&,uint,uint)", ves_icall_System_Threading_Interlocked_CompareExchange_Int,
+       "System.Threading.Interlocked::CompareExchange(object&,object,object)", ves_icall_System_Threading_Interlocked_CompareExchange_Object,
+       "System.Threading.Interlocked::CompareExchange(single&,single,single)", ves_icall_System_Threading_Interlocked_CompareExchange_Single,
+       "System.Threading.Interlocked::Exchange(uint&,uint)", ves_icall_System_Threading_Interlocked_Exchange_Int,
+       "System.Threading.Interlocked::Exchange(object&,object)", ves_icall_System_Threading_Interlocked_Exchange_Object,
+       "System.Threading.Interlocked::Exchange(single&,single)", ves_icall_System_Threading_Interlocked_Exchange_Single,
+
        /*
         * add other internal calls here
         */