e1086920e65927e13bdf725bb97fe0bd243b491a
[mono.git] / mono / metadata / icall.c
1 /*
2  * icall.c:
3  *
4  * Authors:
5  *   Dietmar Maurer (dietmar@ximian.com)
6  *   Paolo Molaro (lupus@ximian.com)
7  *       Patrik Torstensson (patrik.torstensson@labs2.com)
8  *
9  * (C) 2001 Ximian, Inc.
10  */
11
12 #include <config.h>
13 #include <glib.h>
14 #include <stdarg.h>
15 #include <string.h>
16 #include <sys/time.h>
17 #include <unistd.h>
18 #if defined (PLATFORM_WIN32)
19 #include <stdlib.h>
20 #endif
21
22 #include <mono/metadata/object.h>
23 #include <mono/metadata/threads.h>
24 #include <mono/metadata/reflection.h>
25 #include <mono/metadata/assembly.h>
26 #include <mono/metadata/tabledefs.h>
27 #include <mono/metadata/exception.h>
28 #include <mono/metadata/file-io.h>
29 #include <mono/metadata/socket-io.h>
30 #include <mono/metadata/mono-endian.h>
31 #include <mono/metadata/tokentype.h>
32 #include <mono/metadata/unicode.h>
33 #include <mono/metadata/appdomain.h>
34 #include <mono/metadata/rand.h>
35 #include <mono/metadata/sysmath.h>
36 #include <mono/metadata/debug-symfile.h>
37 #include <mono/io-layer/io-layer.h>
38 #include "decimal.h"
39
40 static MonoString *
41 mono_double_ToStringImpl (double value)
42 {
43         /* FIXME: Handle formats, etc. */
44         const gchar *retVal;
45         retVal = g_strdup_printf ("%f", value);
46         return mono_string_new (mono_domain_get (), retVal);
47 }
48
49 static MonoObject *
50 ves_icall_System_Array_GetValueImpl (MonoObject *this, guint32 pos)
51 {
52         MonoClass *ac;
53         MonoArray *ao;
54         gint32 esize;
55         gpointer *ea;
56
57         ao = (MonoArray *)this;
58         ac = (MonoClass *)ao->obj.vtable->klass;
59
60         esize = mono_array_element_size (ac);
61         ea = (gpointer*)((char*)ao->vector + (pos * esize));
62
63         if (ac->element_class->valuetype)
64                 return mono_value_box (this->vtable->domain, ac->element_class, ea);
65         else
66                 return *ea;
67 }
68
69 static MonoObject *
70 ves_icall_System_Array_GetValue (MonoObject *this, MonoObject *idxs)
71 {
72         MonoClass *ac, *ic;
73         MonoArray *ao, *io;
74         gint32 i, pos, *ind;
75
76         MONO_CHECK_ARG_NULL (idxs);
77
78         io = (MonoArray *)idxs;
79         ic = (MonoClass *)io->obj.vtable->klass;
80         
81         ao = (MonoArray *)this;
82         ac = (MonoClass *)ao->obj.vtable->klass;
83
84         g_assert (ic->rank == 1);
85         if (io->bounds [0].length != ac->rank)
86                 mono_raise_exception (mono_get_exception_argument (NULL, NULL));
87
88         ind = (guint32 *)io->vector;
89         for (i = 0; i < ac->rank; i++)
90                 if ((ind [i] < ao->bounds [i].lower_bound) ||
91                     (ind [i] >= ao->bounds [i].length + ao->bounds [i].lower_bound))
92                         mono_raise_exception (mono_get_exception_index_out_of_range ());
93
94         pos = ind [0] - ao->bounds [0].lower_bound;
95         for (i = 1; i < ac->rank; i++)
96                 pos = pos*ao->bounds [i].length + ind [i] - 
97                         ao->bounds [i].lower_bound;
98
99         return ves_icall_System_Array_GetValueImpl (this, pos);
100 }
101
102 static void
103 ves_icall_System_Array_SetValueImpl (MonoArray *this, MonoObject *value, guint32 pos)
104 {
105         MonoClass *ac, *vc, *ec;
106         gint32 esize, vsize;
107         gpointer *ea, *va;
108
109         guint64 u64;
110         gint64 i64;
111         gdouble r64;
112
113         if (value)
114                 vc = value->vtable->klass;
115         else
116                 vc = NULL;
117
118         ac = this->obj.vtable->klass;
119         ec = ac->element_class;
120
121         esize = mono_array_element_size (ac);
122         ea = (gpointer*)((char*)this->vector + (pos * esize));
123         va = (gpointer*)((char*)value + sizeof (MonoObject));
124
125         if (!value) {
126                 memset (ea, 0,  esize);
127                 return;
128         }
129
130 #define NO_WIDENING_CONVERSION G_STMT_START{\
131         mono_raise_exception (mono_get_exception_argument ( \
132                 "value", "not a widening conversion")); \
133 }G_STMT_END
134
135 #define CHECK_WIDENING_CONVERSION(extra) G_STMT_START{\
136         if (esize < vsize + ## extra) \
137                 mono_raise_exception (mono_get_exception_argument ( \
138                         "value", "not a widening conversion")); \
139 }G_STMT_END
140
141 #define INVALID_CAST G_STMT_START{\
142         mono_raise_exception (mono_get_exception_invalid_cast ()); \
143 }G_STMT_END
144
145         /* Check element (destination) type. */
146         switch (ec->byval_arg.type) {
147         case MONO_TYPE_STRING:
148                 switch (vc->byval_arg.type) {
149                 case MONO_TYPE_STRING:
150                         break;
151                 default:
152                         INVALID_CAST;
153                 }
154                 break;
155         case MONO_TYPE_BOOLEAN:
156                 switch (vc->byval_arg.type) {
157                 case MONO_TYPE_BOOLEAN:
158                         break;
159                 case MONO_TYPE_CHAR:
160                 case MONO_TYPE_U1:
161                 case MONO_TYPE_U2:
162                 case MONO_TYPE_U4:
163                 case MONO_TYPE_U8:
164                 case MONO_TYPE_I1:
165                 case MONO_TYPE_I2:
166                 case MONO_TYPE_I4:
167                 case MONO_TYPE_I8:
168                 case MONO_TYPE_R4:
169                 case MONO_TYPE_R8:
170                         NO_WIDENING_CONVERSION;
171                 default:
172                         INVALID_CAST;
173                 }
174                 break;
175         }
176
177         if (!ec->valuetype) {
178                 *ea = (gpointer)value;
179                 return;
180         }
181
182         if (mono_object_isinst (value, ec)) {
183                 memcpy (ea, (char *)value + sizeof (MonoObject), esize);
184                 return;
185         }
186
187         if (!vc->valuetype)
188                 INVALID_CAST;
189
190         vsize = mono_class_instance_size (vc) - sizeof (MonoObject);
191
192 #if 0
193         g_message (G_STRLOC ": %d (%d) <= %d (%d)",
194                    ec->byval_arg.type, esize,
195                    vc->byval_arg.type, vsize);
196 #endif
197
198 #define ASSIGN_UNSIGNED(etype) G_STMT_START{\
199         switch (vc->byval_arg.type) { \
200         case MONO_TYPE_U1: \
201         case MONO_TYPE_U2: \
202         case MONO_TYPE_U4: \
203         case MONO_TYPE_U8: \
204         case MONO_TYPE_CHAR: \
205                 CHECK_WIDENING_CONVERSION(0); \
206                 *(## etype *) ea = (## etype) u64; \
207                 return; \
208         /* You can't assign a signed value to an unsigned array. */ \
209         case MONO_TYPE_I1: \
210         case MONO_TYPE_I2: \
211         case MONO_TYPE_I4: \
212         case MONO_TYPE_I8: \
213         /* You can't assign a floating point number to an integer array. */ \
214         case MONO_TYPE_R4: \
215         case MONO_TYPE_R8: \
216                 NO_WIDENING_CONVERSION; \
217         } \
218 }G_STMT_END
219
220 #define ASSIGN_SIGNED(etype) G_STMT_START{\
221         switch (vc->byval_arg.type) { \
222         case MONO_TYPE_I1: \
223         case MONO_TYPE_I2: \
224         case MONO_TYPE_I4: \
225         case MONO_TYPE_I8: \
226                 CHECK_WIDENING_CONVERSION(0); \
227                 *(## etype *) ea = (## etype) i64; \
228                 return; \
229         /* You can assign an unsigned value to a signed array if the array's */ \
230         /* element size is larger than the value size. */ \
231         case MONO_TYPE_U1: \
232         case MONO_TYPE_U2: \
233         case MONO_TYPE_U4: \
234         case MONO_TYPE_U8: \
235         case MONO_TYPE_CHAR: \
236                 CHECK_WIDENING_CONVERSION(1); \
237                 *(## etype *) ea = (## etype) u64; \
238                 return; \
239         /* You can't assign a floating point number to an integer array. */ \
240         case MONO_TYPE_R4: \
241         case MONO_TYPE_R8: \
242                 NO_WIDENING_CONVERSION; \
243         } \
244 }G_STMT_END
245
246 #define ASSIGN_REAL(etype) G_STMT_START{\
247         switch (vc->byval_arg.type) { \
248         case MONO_TYPE_R4: \
249         case MONO_TYPE_R8: \
250                 CHECK_WIDENING_CONVERSION(0); \
251                 *(## etype *) ea = (## etype) r64; \
252                 return; \
253         /* All integer values fit into a floating point array, so we don't */ \
254         /* need to CHECK_WIDENING_CONVERSION here. */ \
255         case MONO_TYPE_I1: \
256         case MONO_TYPE_I2: \
257         case MONO_TYPE_I4: \
258         case MONO_TYPE_I8: \
259                 *(## etype *) ea = (## etype) i64; \
260                 return; \
261         case MONO_TYPE_U1: \
262         case MONO_TYPE_U2: \
263         case MONO_TYPE_U4: \
264         case MONO_TYPE_U8: \
265         case MONO_TYPE_CHAR: \
266                 *(## etype *) ea = (## etype) u64; \
267                 return; \
268         } \
269 }G_STMT_END
270
271         switch (vc->byval_arg.type) {
272         case MONO_TYPE_U1:
273                 u64 = *(guint8 *) va;
274                 break;
275         case MONO_TYPE_U2:
276                 u64 = *(guint16 *) va;
277                 break;
278         case MONO_TYPE_U4:
279                 u64 = *(guint32 *) va;
280                 break;
281         case MONO_TYPE_U8:
282                 u64 = *(guint64 *) va;
283                 break;
284         case MONO_TYPE_I1:
285                 i64 = *(gint8 *) va;
286                 break;
287         case MONO_TYPE_I2:
288                 i64 = *(gint16 *) va;
289                 break;
290         case MONO_TYPE_I4:
291                 i64 = *(gint32 *) va;
292                 break;
293         case MONO_TYPE_I8:
294                 i64 = *(gint64 *) va;
295                 break;
296         case MONO_TYPE_R4:
297                 r64 = *(gfloat *) va;
298                 break;
299         case MONO_TYPE_R8:
300                 r64 = *(gdouble *) va;
301                 break;
302         case MONO_TYPE_CHAR:
303                 u64 = *(guint16 *) va;
304                 break;
305         case MONO_TYPE_BOOLEAN:
306                 /* Boolean is only compatible with itself. */
307                 switch (ec->byval_arg.type) {
308                 case MONO_TYPE_CHAR:
309                 case MONO_TYPE_U1:
310                 case MONO_TYPE_U2:
311                 case MONO_TYPE_U4:
312                 case MONO_TYPE_U8:
313                 case MONO_TYPE_I1:
314                 case MONO_TYPE_I2:
315                 case MONO_TYPE_I4:
316                 case MONO_TYPE_I8:
317                 case MONO_TYPE_R4:
318                 case MONO_TYPE_R8:
319                         NO_WIDENING_CONVERSION;
320                 default:
321                         INVALID_CAST;
322                 }
323                 break;
324         }
325
326         /* If we can't do a direct copy, let's try a widening conversion. */
327         switch (ec->byval_arg.type) {
328         case MONO_TYPE_CHAR:
329                 ASSIGN_UNSIGNED (guint16);
330         case MONO_TYPE_U1:
331                 ASSIGN_UNSIGNED (guint8);
332         case MONO_TYPE_U2:
333                 ASSIGN_UNSIGNED (guint16);
334         case MONO_TYPE_U4:
335                 ASSIGN_UNSIGNED (guint32);
336         case MONO_TYPE_U8:
337                 ASSIGN_UNSIGNED (guint64);
338         case MONO_TYPE_I1:
339                 ASSIGN_SIGNED (gint8);
340         case MONO_TYPE_I2:
341                 ASSIGN_SIGNED (gint16);
342         case MONO_TYPE_I4:
343                 ASSIGN_SIGNED (gint32);
344         case MONO_TYPE_I8:
345                 ASSIGN_SIGNED (gint64);
346         case MONO_TYPE_R4:
347                 ASSIGN_REAL (gfloat);
348         case MONO_TYPE_R8:
349                 ASSIGN_REAL (gdouble);
350         }
351
352         INVALID_CAST;
353         /* Not reached, INVALID_CAST does not return. Just to avoid a compiler warning ... */
354         return;
355
356 #undef INVALID_CAST
357 #undef NO_WIDENING_CONVERSION
358 #undef CHECK_WIDENING_CONVERSION
359 #undef ASSIGN_UNSIGNED
360 #undef ASSIGN_SIGNED
361 #undef ASSIGN_REAL
362 }
363
364 static void 
365 ves_icall_System_Array_SetValue (MonoArray *this, MonoObject *value,
366                                  MonoArray *idxs)
367 {
368         MonoClass *ac, *ic;
369         gint32 i, pos, *ind;
370
371         MONO_CHECK_ARG_NULL (idxs);
372
373         ic = idxs->obj.vtable->klass;
374         ac = this->obj.vtable->klass;
375
376         g_assert (ic->rank == 1);
377         if (idxs->bounds [0].length != ac->rank)
378                 mono_raise_exception (mono_get_exception_argument (NULL, NULL));
379
380         ind = (guint32 *)idxs->vector;
381         for (i = 0; i < ac->rank; i++)
382                 if ((ind [i] < this->bounds [i].lower_bound) ||
383                     (ind [i] >= this->bounds [i].length + this->bounds [i].lower_bound))
384                         mono_raise_exception (mono_get_exception_index_out_of_range ());
385
386         pos = ind [0] - this->bounds [0].lower_bound;
387         for (i = 1; i < ac->rank; i++)
388                 pos = pos * this->bounds [i].length + ind [i] - 
389                         this->bounds [i].lower_bound;
390
391         ves_icall_System_Array_SetValueImpl (this, value, pos);
392 }
393
394 static MonoArray *
395 ves_icall_System_Array_CreateInstanceImpl (MonoReflectionType *type, MonoArray *lengths, MonoArray *bounds)
396 {
397         MonoClass *aklass;
398         MonoArray *array;
399         gint32 *sizes, i;
400
401         MONO_CHECK_ARG_NULL (type);
402         MONO_CHECK_ARG_NULL (lengths);
403
404         MONO_CHECK_ARG (lengths, mono_array_length (lengths) > 0);
405         if (bounds)
406                 MONO_CHECK_ARG (bounds, mono_array_length (lengths) == mono_array_length (bounds));
407
408         for (i = 0; i < mono_array_length (lengths); i++)
409                 if (mono_array_get (lengths, gint32, i) < 0)
410                         mono_raise_exception (mono_get_exception_argument_out_of_range (NULL));
411
412         aklass = mono_array_class_get (type->type, mono_array_length (lengths));
413
414         sizes = alloca (aklass->rank * sizeof(guint32) * 2);
415         for (i = 0; i < aklass->rank; ++i) {
416                 sizes [i] = mono_array_get (lengths, gint32, i);
417                 if (bounds)
418                         sizes [i + aklass->rank] = mono_array_get (bounds, gint32, i);
419                 else
420                         sizes [i + aklass->rank] = 0;
421         }
422
423         array = mono_array_new_full (mono_domain_get (), aklass, sizes, sizes + aklass->rank);
424
425         return array;
426 }
427
428 static gint32 
429 ves_icall_System_Array_GetRank (MonoObject *this)
430 {
431         return this->vtable->klass->rank;
432 }
433
434 static gint32
435 ves_icall_System_Array_GetLength (MonoArray *this, gint32 dimension)
436 {
437         gint32 rank = ((MonoObject *)this)->vtable->klass->rank;
438         if ((dimension < 0) || (dimension >= rank))
439                 mono_raise_exception (mono_get_exception_index_out_of_range ());
440         return this->bounds [dimension].length;
441 }
442
443 static gint32
444 ves_icall_System_Array_GetLowerBound (MonoArray *this, gint32 dimension)
445 {
446         gint32 rank = ((MonoObject *)this)->vtable->klass->rank;
447         if ((dimension < 0) || (dimension >= rank))
448                 mono_raise_exception (mono_get_exception_index_out_of_range ());
449         return this->bounds [dimension].lower_bound;
450 }
451
452 static void
453 ves_icall_System_Array_FastCopy (MonoArray *source, int source_idx, MonoArray* dest, int dest_idx, int length)
454 {
455         int element_size = mono_array_element_size (source->obj.vtable->klass);
456         void * dest_addr = mono_array_addr_with_size (dest, element_size, dest_idx);
457         void * source_addr = mono_array_addr_with_size (source, element_size, source_idx);
458
459         g_assert (dest_idx + length <= mono_array_length (dest));
460         g_assert (source_idx + length <= mono_array_length (source));
461         memmove (dest_addr, source_addr, element_size * length);
462 }
463
464 static void
465 ves_icall_InitializeArray (MonoArray *array, MonoClassField *field_handle)
466 {
467         MonoClass *klass = array->obj.vtable->klass;
468         guint32 size = mono_array_element_size (klass);
469         int i;
470
471         for (i = 0; i < klass->rank; ++i) 
472                 size *= array->bounds [i].length;
473
474         memcpy (mono_array_addr (array, char, 0), field_handle->data, size);
475
476 #if G_BYTE_ORDER != G_LITTLE_ENDIAN
477 #define SWAP(n) {\
478         gint i; \
479         guint ## n tmp; \
480         guint ## n *data = (guint ## n *) mono_array_addr (array, char, 0); \
481 \
482         for (i = 0; i < size; i += n/8, data++) { \
483                 tmp = read ## n (data); \
484                 *data = tmp; \
485         } \
486 }
487
488         printf ("Initialize array with elements of %s type\n", klass->element_class->name);
489
490         switch (klass->element_class->byval_arg.type) {
491         case MONO_TYPE_CHAR:
492         case MONO_TYPE_I2:
493         case MONO_TYPE_U2:
494                 SWAP (16);
495                 break;
496         case MONO_TYPE_I4:
497         case MONO_TYPE_U4:
498                 SWAP (32);
499                 break;
500         case MONO_TYPE_I8:
501         case MONO_TYPE_U8:
502                 SWAP (64);
503                 break;
504         }
505                  
506 #endif
507 }
508
509 static MonoObject *
510 ves_icall_System_Object_MemberwiseClone (MonoObject *this)
511 {
512         return mono_object_clone (this);
513 }
514
515 static gint32
516 ves_icall_System_Object_GetHashCode (MonoObject *this)
517 {
518         return *((gint32 *)this - 1);
519 }
520
521 /*
522  * A hash function for value types. I have no idea if this is a good hash 
523  * function (its similar to g_str_hash).
524  */
525 static gint32
526 ves_icall_System_ValueType_GetHashCode (MonoObject *this)
527 {
528         gint32 i, size;
529         const char *p;
530         guint h;
531
532         MONO_CHECK_ARG_NULL (this);
533
534         size = this->vtable->klass->instance_size - sizeof (MonoObject);
535
536         p = (const char *)this + sizeof (MonoObject);
537
538         for (i = 0; i < size; i++) {
539                 h = (h << 5) - h + *p;
540                 p++;
541         }
542
543         return h;
544 }
545
546 static MonoBoolean
547 ves_icall_System_ValueType_Equals (MonoObject *this, MonoObject *that)
548 {
549         gint32 size;
550         const char *p, *s;
551
552         MONO_CHECK_ARG_NULL (that);
553
554         if (this->vtable != that->vtable)
555                 return FALSE;
556
557         size = this->vtable->klass->instance_size - sizeof (MonoObject);
558
559         p = (const char *)this + sizeof (MonoObject);
560         s = (const char *)that + sizeof (MonoObject);
561
562         return memcmp (p, s, size)? FALSE: TRUE;
563 }
564
565 static MonoReflectionType *
566 ves_icall_System_Object_GetType (MonoObject *obj)
567 {
568         return mono_type_get_object (mono_domain_get (), &obj->vtable->klass->byval_arg);
569 }
570
571 static void
572 mono_type_type_from_obj (MonoReflectionType *mtype, MonoObject *obj)
573 {
574         mtype->type = &obj->vtable->klass->byval_arg;
575         g_assert (mtype->type->type);
576 }
577
578 static gint32
579 ves_icall_AssemblyBuilder_getToken (MonoReflectionAssemblyBuilder *assb, MonoObject *obj)
580 {
581         return mono_image_create_token (assb->dynamic_assembly, obj);
582 }
583
584 static gint32
585 ves_icall_AssemblyBuilder_getPEHeader (MonoReflectionAssemblyBuilder *assb, MonoArray *buf, gint32 *data_size)
586 {
587         int count, hsize;
588         MonoDynamicAssembly *ass = assb->dynamic_assembly;
589
590         hsize = mono_image_get_header (assb, (char*)buf->vector, buf->bounds->length);
591         if (hsize < 0)
592                 return hsize;
593         count = ass->code.index + ass->meta_size;
594         count += 512 - 1;
595         count &= ~(512 - 1);
596         *data_size = count;
597
598         return hsize;
599 }
600
601 static gint32
602 ves_icall_AssemblyBuilder_getDataChunk (MonoReflectionAssemblyBuilder *assb, MonoArray *buf)
603 {
604         int count, real_data;
605         MonoDynamicAssembly *ass = assb->dynamic_assembly;
606         char *p = mono_array_addr (buf, char, 0);
607         
608         count = real_data = ass->code.index + ass->meta_size;
609         count += 512 - 1;
610         count &= ~(512 - 1);
611         if (count > mono_array_length (buf))
612                 return -1;
613         count -= real_data;
614         
615         memcpy (p, ass->code.data, ass->code.index);
616         p += ass->code.index;
617         memcpy (p, ass->assembly.image->raw_metadata, ass->meta_size);
618         p += ass->meta_size;
619         /* null-pad section */
620         memset (p, 0, count);
621
622         return real_data + count;
623 }
624
625 static MonoReflectionType*
626 ves_icall_type_from_name (MonoString *name)
627 {
628         MonoDomain *domain = mono_domain_get (); 
629         MonoType *type;
630         MonoImage *image;
631         MonoTypeNameParse info;
632         gchar *str;
633         
634         str = mono_string_to_utf8 (name);
635         /*g_print ("requested type %s\n", str);*/
636         if (!mono_reflection_parse_type (str, &info)) {
637                 g_free (str);
638                 g_list_free (info.modifiers);
639                 return NULL;
640         }
641
642         if (info.assembly) {
643                 image = mono_image_loaded (info.assembly);
644                 /* do we need to load if it's not already loaded? */
645                 if (!image) {
646                         g_free (str);
647                         g_list_free (info.modifiers);
648                         return NULL;
649                 }
650         } else
651                 image = mono_defaults.corlib;
652
653         type = mono_reflection_get_type (image, &info, FALSE);
654         g_free (str);
655         g_list_free (info.modifiers);
656         if (!type)
657                 return NULL;
658         /*g_print ("got it\n");*/
659         return mono_type_get_object (domain, type);
660 }
661
662 static MonoReflectionType*
663 ves_icall_type_from_handle (MonoType *handle)
664 {
665         MonoDomain *domain = mono_domain_get (); 
666         MonoClass *klass = mono_class_from_mono_type (handle);
667
668         mono_class_init (klass);
669         return mono_type_get_object (domain, handle);
670 }
671
672 static guint32
673 ves_icall_type_Equals (MonoReflectionType *type, MonoReflectionType *c)
674 {
675         if (type->type && c->type)
676                 return mono_metadata_type_equal (type->type, c->type);
677         g_print ("type equals\n");
678         return 0;
679 }
680
681 static guint32
682 ves_icall_type_is_subtype_of (MonoReflectionType *type, MonoReflectionType *c, MonoBoolean check_interfaces)
683 {
684         MonoDomain *domain; 
685         MonoClass *klass;
686         MonoClass *klassc;
687
688         g_assert (type != NULL);
689         
690         domain = ((MonoObject *)type)->vtable->domain;
691
692         if (!c) /* FIXME: dont know what do do here */
693                 return 0;
694
695         klass = mono_class_from_mono_type (type->type);
696         klassc = mono_class_from_mono_type (c->type);
697
698         /* cut&paste from mono_object_isinst (): keep in sync */
699         if (check_interfaces && (klassc->flags & TYPE_ATTRIBUTE_INTERFACE) && !(klass->flags & TYPE_ATTRIBUTE_INTERFACE)) {
700                 MonoVTable *klass_vt = mono_class_vtable (domain, klass);
701                 if ((klassc->interface_id <= klass->max_interface_id) &&
702                     klass_vt->interface_offsets [klassc->interface_id])
703                         return 1;
704         } else if (check_interfaces && (klassc->flags & TYPE_ATTRIBUTE_INTERFACE) && (klass->flags & TYPE_ATTRIBUTE_INTERFACE)) {
705                 int i;
706
707                 for (i = 0; i < klass->interface_count; i ++) {
708                         MonoClass *ic =  klass->interfaces [i];
709                         if (ic == klassc)
710                                 return 1;
711                 }
712         } else {
713                 /*
714                  * klass->baseval is 0 for interfaces 
715                  */
716                 if (klass->baseval && ((klass->baseval - klassc->baseval) <= klassc->diffval))
717                         return 1;
718         }
719         return 0;
720 }
721
722 static guint32
723 ves_icall_get_attributes (MonoReflectionType *type)
724 {
725         MonoClass *klass = mono_class_from_mono_type (type->type);
726
727         return klass->flags;
728 }
729
730 static MonoString*
731 ves_icall_MonoMethod_get_Name (MonoReflectionMethod *method)
732 {
733         return mono_string_new (mono_object_domain (method), method->method->name);
734 }
735
736 static void
737 ves_icall_get_method_info (MonoMethod *method, MonoMethodInfo *info)
738 {
739         MonoDomain *domain = mono_domain_get (); 
740
741         info->parent = mono_type_get_object (domain, &method->klass->byval_arg);
742         info->ret = mono_type_get_object (domain, method->signature->ret);
743         info->name = mono_string_new (domain, method->name);
744         info->attrs = method->flags;
745         info->implattrs = method->iflags;
746 }
747
748 static MonoArray*
749 ves_icall_get_parameter_info (MonoMethod *method)
750 {
751         MonoDomain *domain = mono_domain_get (); 
752         MonoArray *res;
753         static MonoClass *System_Reflection_ParameterInfo;
754         MonoReflectionParameter** args;
755         int i;
756
757         args = mono_param_get_objects (domain, method);
758         if (!System_Reflection_ParameterInfo)
759                 System_Reflection_ParameterInfo = mono_class_from_name (
760                         mono_defaults.corlib, "System.Reflection", "ParameterInfo");
761         res = mono_array_new (domain, System_Reflection_ParameterInfo, method->signature->param_count);
762         for (i = 0; i < method->signature->param_count; ++i) {
763                 mono_array_set (res, gpointer, i, args [i]);
764         }
765         return res;
766 }
767
768 static void
769 ves_icall_get_field_info (MonoReflectionField *field, MonoFieldInfo *info)
770 {
771         MonoDomain *domain = mono_domain_get (); 
772
773         info->parent = mono_type_get_object (domain, &field->klass->byval_arg);
774         info->type = mono_type_get_object (domain, field->field->type);
775         info->name = mono_string_new (domain, field->field->name);
776         info->attrs = field->field->type->attrs;
777 }
778
779 static MonoObject *
780 ves_icall_MonoField_GetValue (MonoReflectionField *field, MonoObject *obj) {
781         MonoObject *res;
782         MonoClass *klass;
783         MonoType *ftype = field->field->type;
784         int type = ftype->type;
785         char *p, *r;
786         guint32 align;
787
788         mono_class_init (field->klass);
789         if (ftype->attrs & FIELD_ATTRIBUTE_STATIC) {
790                 MonoVTable *vtable;
791                 vtable = mono_class_vtable (mono_domain_get (), field->klass);
792                 p = (char*)(vtable->data) + field->field->offset;
793         } else {
794                 p = (char*)obj + field->field->offset;
795         }
796
797         switch (type) {
798         case MONO_TYPE_OBJECT:
799         case MONO_TYPE_STRING:
800         case MONO_TYPE_SZARRAY:
801         case MONO_TYPE_ARRAY:
802                 return *(MonoObject**)p;
803         }
804         klass = mono_class_from_mono_type (ftype);
805         res = mono_object_new (mono_domain_get (), klass);
806         r = (char*)res + sizeof (MonoObject);
807         memcpy (r, p, mono_class_value_size (klass, &align));
808
809         return res;
810 }
811
812 static void
813 ves_icall_get_property_info (MonoReflectionProperty *property, MonoPropertyInfo *info)
814 {
815         MonoDomain *domain = mono_domain_get (); 
816
817         info->parent = mono_type_get_object (domain, &property->klass->byval_arg);
818         info->name = mono_string_new (domain, property->property->name);
819         info->attrs = property->property->attrs;
820         info->get = property->property->get ? mono_method_get_object (domain, property->property->get): NULL;
821         info->set = property->property->set ? mono_method_get_object (domain, property->property->set): NULL;
822         /* 
823          * There may be other methods defined for properties, though, it seems they are not exposed 
824          * in the reflection API 
825          */
826 }
827
828 static MonoArray*
829 ves_icall_Type_GetInterfaces (MonoReflectionType* type)
830 {
831         MonoDomain *domain = mono_domain_get (); 
832         MonoArray *intf;
833         int ninterf, i;
834         MonoClass *class = mono_class_from_mono_type (type->type);
835         MonoClass *parent;
836
837         ninterf = 0;
838         for (parent = class; parent; parent = parent->parent) {
839                 ninterf += parent->interface_count;
840         }
841         intf = mono_array_new (domain, mono_defaults.monotype_class, ninterf);
842         ninterf = 0;
843         for (parent = class; parent; parent = parent->parent) {
844                 for (i = 0; i < parent->interface_count; ++i) {
845                         mono_array_set (intf, gpointer, ninterf, mono_type_get_object (domain, &parent->interfaces [i]->byval_arg));
846                         ++ninterf;
847                 }
848         }
849         return intf;
850 }
851
852 static void
853 ves_icall_get_type_info (MonoType *type, MonoTypeInfo *info)
854 {
855         MonoDomain *domain = mono_domain_get (); 
856         MonoClass *class = mono_class_from_mono_type (type);
857
858         info->parent = class->parent ? mono_type_get_object (domain, &class->parent->byval_arg): NULL;
859         info->name = mono_string_new (domain, class->name);
860         info->name_space = mono_string_new (domain, class->name_space);
861         info->attrs = class->flags;
862         info->rank = class->rank;
863         info->assembly = mono_assembly_get_object (domain, class->image->assembly);
864         if (class->enumtype && class->enum_basetype) /* types that are modifierd typebuilkders may not have enum_basetype set */
865                 info->etype = mono_type_get_object (domain, class->enum_basetype);
866         else if (class->element_class)
867                 info->etype = mono_type_get_object (domain, &class->element_class->byval_arg);
868         else
869                 info->etype = NULL;
870
871         info->isbyref = type->byref;
872         info->ispointer = type->type == MONO_TYPE_PTR;
873         info->isprimitive = (type->type >= MONO_TYPE_BOOLEAN) && (type->type <= MONO_TYPE_R8);
874 }
875
876 static MonoObject *
877 ves_icall_InternalInvoke (MonoReflectionMethod *method, MonoObject *this, MonoArray *params) 
878 {
879         return mono_runtime_invoke_array (method->method, this, params);
880 }
881
882 static MonoObject *
883 ves_icall_InternalExecute (MonoReflectionMethod *method, MonoObject *this, MonoArray *params, MonoArray **outArgs) 
884 {
885         MonoDomain *domain = mono_domain_get (); 
886         MonoMethod *m = method->method;
887         MonoMethodSignature *sig = m->signature;
888         MonoArray *out_args;
889         MonoObject *result;
890         int i, j, outarg_count = 0;
891
892         if (m->klass == mono_defaults.object_class) {
893
894                 if (!strcmp (m->name, "FieldGetter")) {
895                         MonoClass *k = this->vtable->klass;
896                         MonoString *name = mono_array_get (params, MonoString *, 1);
897                         char *str;
898
899                         str = mono_string_to_utf8 (name);
900                 
901                         for (i = 0; i < k->field.count; i++) {
902                                 if (!strcmp (k->fields [i].name, str)) {
903                                         MonoClass *field_klass =  mono_class_from_mono_type (k->fields [i].type);
904                                         if (field_klass->valuetype)
905                                                 result = mono_value_box (domain, field_klass,
906                                                                          (char *)this + k->fields [i].offset);
907                                         else 
908                                                 result = *((gpointer *)((char *)this + k->fields [i].offset));
909                                 
910                                         g_assert (result);
911                                         out_args = mono_array_new (domain, mono_defaults.object_class, 1);
912                                         *outArgs = out_args;
913                                         mono_array_set (out_args, gpointer, 0, result);
914                                         g_free (str);
915                                         return NULL;
916                                 }
917                         }
918
919                         g_free (str);
920                         g_assert_not_reached ();
921
922                 } else if (!strcmp (m->name, "FieldSetter")) {
923                         MonoClass *k = this->vtable->klass;
924                         MonoString *name = mono_array_get (params, MonoString *, 1);
925                         int size, align;
926                         char *str;
927
928                         str = mono_string_to_utf8 (name);
929                 
930                         for (i = 0; i < k->field.count; i++) {
931                                 if (!strcmp (k->fields [i].name, str)) {
932                                         MonoClass *field_klass =  mono_class_from_mono_type (k->fields [i].type);
933                                         MonoObject *val = mono_array_get (params, gpointer, 2);
934
935                                         if (field_klass->valuetype) {
936                                                 size = mono_type_size (k->fields [i].type, &align);
937                                                 memcpy ((char *)this + k->fields [i].offset, 
938                                                         ((char *)val) + sizeof (MonoObject), size);
939                                         } else 
940                                                 *((gpointer *)this + k->fields [i].offset) = val;
941                                 
942                                         g_assert (result);
943                                         g_free (str);
944                                         return NULL;
945                                 }
946                         }
947
948                         g_free (str);
949                         g_assert_not_reached ();
950
951                 }
952         }
953
954         for (i = 0; i < params->bounds->length; i++) {
955                 if (sig->params [i]->byref) 
956                         outarg_count++;
957         }
958
959         out_args = mono_array_new (domain, mono_defaults.object_class, outarg_count);
960         
961         for (i = 0, j = 0; i < params->bounds->length; i++) {
962                 if (sig->params [i]->byref) {
963                         gpointer arg;
964                         arg = mono_array_get (params, gpointer, i);
965                         mono_array_set (out_args, gpointer, j, arg);
966                         j++;
967                 }
968         }
969
970         /* fixme: handle constructors? */
971         if (!strcmp (method->method->name, ".ctor"))
972                 g_assert_not_reached ();
973
974         result = mono_runtime_invoke_array (method->method, this, params);
975
976         *outArgs = out_args;
977
978         return result;
979 }
980
981 static MonoObject *
982 ves_icall_System_Enum_ToObject (MonoReflectionType *type, MonoObject *obj)
983 {
984         MonoDomain *domain = mono_domain_get (); 
985         MonoClass *enumc, *objc;
986         gint32 s1, s2;
987         MonoObject *res;
988         
989         MONO_CHECK_ARG_NULL (type);
990         MONO_CHECK_ARG_NULL (obj);
991
992         enumc = mono_class_from_mono_type (type->type);
993         objc = obj->vtable->klass;
994
995         MONO_CHECK_ARG (obj, enumc->enumtype == TRUE);
996         MONO_CHECK_ARG (obj, (objc->enumtype) || (objc->byval_arg.type >= MONO_TYPE_I1 &&
997                                                   objc->byval_arg.type <= MONO_TYPE_U8));
998         
999         s1 = mono_class_value_size (enumc, NULL);
1000         s2 = mono_class_value_size (objc, NULL);
1001
1002         res = mono_object_new (domain, enumc);
1003
1004 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
1005         memcpy ((char *)res + sizeof (MonoObject), (char *)obj + sizeof (MonoObject), MIN (s1, s2));
1006 #else
1007         memcpy ((char *)res + sizeof (MonoObject) + (s1 > s2 ? s1 - s2 : 0),
1008                 (char *)obj + sizeof (MonoObject) + (s2 > s1 ? s2 - s1 : 0),
1009                 MIN (s1, s2));
1010 #endif
1011         return res;
1012 }
1013
1014 static MonoObject *
1015 ves_icall_System_Enum_get_value (MonoObject *this)
1016 {
1017         MonoDomain *domain = mono_domain_get (); 
1018         MonoObject *res;
1019         MonoClass *enumc;
1020         gpointer dst;
1021         gpointer src;
1022         int size;
1023
1024         if (!this)
1025                 return NULL;
1026
1027         g_assert (this->vtable->klass->enumtype);
1028         
1029         enumc = mono_class_from_mono_type (this->vtable->klass->enum_basetype);
1030         res = mono_object_new (domain, enumc);
1031         dst = (char *)res + sizeof (MonoObject);
1032         src = (char *)this + sizeof (MonoObject);
1033         size = mono_class_value_size (enumc, NULL);
1034
1035         memcpy (dst, src, size);
1036
1037         return res;
1038 }
1039
1040 static void
1041 ves_icall_get_enum_info (MonoReflectionType *type, MonoEnumInfo *info)
1042 {
1043         MonoDomain *domain = mono_domain_get (); 
1044         MonoClass *enumc = mono_class_from_mono_type (type->type);
1045         guint i, j, nvalues, crow;
1046         MonoClassField *field;
1047         
1048         info->utype = mono_type_get_object (domain, enumc->enum_basetype);
1049         nvalues = enumc->field.count - 1;
1050         info->names = mono_array_new (domain, mono_defaults.string_class, nvalues);
1051         info->values = mono_array_new (domain, enumc, nvalues);
1052         
1053         for (i = 0, j = 0; i < enumc->field.count; ++i) {
1054                 field = &enumc->fields [i];
1055                 if (strcmp ("value__", field->name) == 0)
1056                         continue;
1057                 mono_array_set (info->names, gpointer, j, mono_string_new (domain, field->name));
1058                 if (!field->data) {
1059                         crow = mono_metadata_get_constant_index (enumc->image, MONO_TOKEN_FIELD_DEF | (i+enumc->field.first+1));
1060                         crow = mono_metadata_decode_row_col (&enumc->image->tables [MONO_TABLE_CONSTANT], crow-1, MONO_CONSTANT_VALUE);
1061                         /* 1 is the length of the blob */
1062                         field->data = 1 + mono_metadata_blob_heap (enumc->image, crow);
1063                 }
1064                 switch (enumc->enum_basetype->type) {
1065                 case MONO_TYPE_U1:
1066                 case MONO_TYPE_I1:
1067                         mono_array_set (info->values, gchar, j, *field->data);
1068                         break;
1069                 case MONO_TYPE_CHAR:
1070                 case MONO_TYPE_U2:
1071                 case MONO_TYPE_I2:
1072                         mono_array_set (info->values, gint16, j, read16 (field->data));
1073                         break;
1074                 case MONO_TYPE_U4:
1075                 case MONO_TYPE_I4:
1076                         mono_array_set (info->values, gint32, j, read32 (field->data));
1077                         break;
1078                 case MONO_TYPE_U8:
1079                 case MONO_TYPE_I8:
1080                         mono_array_set (info->values, gint64, j, read64 (field->data));
1081                         break;
1082                 default:
1083                         g_error ("Implement type 0x%02x in get_enum_info", enumc->enum_basetype->type);
1084                 }
1085                 ++j;
1086         }
1087 }
1088
1089 static MonoMethod*
1090 search_method (MonoReflectionType *type, const char *name, guint32 flags, MonoArray *args)
1091 {
1092         MonoClass *klass, *start_class;
1093         MonoMethod *m;
1094         MonoReflectionType *paramt;
1095         int i, j;
1096
1097         start_class = klass = mono_class_from_mono_type (type->type);
1098         while (klass) {
1099                 for (i = 0; i < klass->method.count; ++i) {
1100                         m = klass->methods [i];
1101                         if (!((m->flags & flags) == flags))
1102                                 continue;
1103                         if (strcmp(m->name, name))
1104                                 continue;
1105                         if (m->signature->param_count != mono_array_length (args))
1106                                 continue;
1107                         for (j = 0; j < m->signature->param_count; ++j) {
1108                                 paramt = mono_array_get (args, MonoReflectionType*, j);
1109                                 if (!mono_metadata_type_equal (paramt->type, m->signature->params [j]))
1110                                         break;
1111                         }
1112                         if (j == m->signature->param_count)
1113                                 return m;
1114                 }
1115                 klass = klass->parent;
1116         }
1117         g_print ("Method %s.%s::%s (%d) not found\n", start_class->name_space, start_class->name, name, mono_array_length (args));
1118         return NULL;
1119 }
1120
1121 static MonoReflectionMethod*
1122 ves_icall_get_constructor (MonoReflectionType *type, MonoArray *args)
1123 {
1124         MonoDomain *domain = mono_domain_get (); 
1125         MonoMethod *m;
1126
1127         m = search_method (type, ".ctor", METHOD_ATTRIBUTE_RT_SPECIAL_NAME, args);
1128         if (m)
1129                 return mono_method_get_object (domain, m);
1130         return NULL;
1131 }
1132
1133 static MonoReflectionMethod*
1134 ves_icall_get_method (MonoReflectionType *type, MonoString *name, MonoArray *args)
1135 {
1136         MonoDomain *domain = mono_domain_get (); 
1137         MonoMethod *m;
1138         char *n = mono_string_to_utf8 (name);
1139
1140         m = search_method (type, n, 0, args);
1141         g_free (n);
1142         if (m)
1143                 return mono_method_get_object (domain, m);
1144         return NULL;
1145 }
1146
1147 static MonoProperty*
1148 search_property (MonoClass *klass, char* name, MonoArray *args) {
1149         int i;
1150         MonoProperty *p;
1151
1152         /* FIXME: handle args */
1153         for (i = 0; i < klass->property.count; ++i) {
1154                 p = &klass->properties [i];
1155                 if (strcmp (p->name, name) == 0)
1156                         return p;
1157         }
1158         return NULL;
1159 }
1160
1161 static MonoReflectionProperty*
1162 ves_icall_get_property (MonoReflectionType *type, MonoString *name, MonoArray *args)
1163 {
1164         MonoDomain *domain = mono_domain_get (); 
1165         MonoProperty *p;
1166         MonoClass *class = mono_class_from_mono_type (type->type);
1167         char *n = mono_string_to_utf8 (name);
1168
1169         p = search_property (class, n, args);
1170         g_free (n);
1171         if (p)
1172                 return mono_property_get_object (domain, class, p);
1173         return NULL;
1174 }
1175
1176 enum {
1177         BFLAGS_IgnoreCase = 1,
1178         BFLAGS_DeclaredOnly = 2,
1179         BFLAGS_Instance = 4,
1180         BFLAGS_Static = 8,
1181         BFLAGS_Public = 0x10,
1182         BFLAGS_NonPublic = 0x20,
1183         BFLAGS_InvokeMethod = 0x100,
1184         BFLAGS_CreateInstance = 0x200,
1185         BFLAGS_GetField = 0x400,
1186         BFLAGS_SetField = 0x800,
1187         BFLAGS_GetProperty = 0x1000,
1188         BFLAGS_SetProperty = 0x2000,
1189         BFLAGS_ExactBinding = 0x10000,
1190         BFLAGS_SuppressChangeType = 0x20000,
1191         BFLAGS_OptionalParamBinding = 0x40000
1192 };
1193
1194 static MonoArray*
1195 ves_icall_Type_GetFields (MonoReflectionType *type, guint32 bflags)
1196 {
1197         MonoDomain *domain; 
1198         GSList *l = NULL, *tmp;
1199         static MonoClass *System_Reflection_FieldInfo;
1200         MonoClass *startklass, *klass;
1201         MonoArray *res;
1202         MonoObject *member;
1203         int i, len, match;
1204         MonoClassField *field;
1205
1206         domain = ((MonoObject *)type)->vtable->domain;
1207         klass = startklass = mono_class_from_mono_type (type->type);
1208
1209 handle_parent:  
1210         for (i = 0; i < klass->field.count; ++i) {
1211                 match = 0;
1212                 field = &klass->fields [i];
1213                 if ((field->type->attrs & FIELD_ATTRIBUTE_FIELD_ACCESS_MASK) == FIELD_ATTRIBUTE_PUBLIC) {
1214                         if (bflags & BFLAGS_Public)
1215                                 match++;
1216                 } else {
1217                         if (bflags & BFLAGS_NonPublic)
1218                                 match++;
1219                 }
1220                 if (!match)
1221                         continue;
1222                 match = 0;
1223                 if (field->type->attrs & FIELD_ATTRIBUTE_STATIC) {
1224                         if (bflags & BFLAGS_Static)
1225                                 match++;
1226                 } else {
1227                         if (bflags & BFLAGS_Instance)
1228                                 match++;
1229                 }
1230
1231                 if (!match)
1232                         continue;
1233                 member = (MonoObject*)mono_field_get_object (domain, klass, field);
1234                 l = g_slist_prepend (l, member);
1235         }
1236         if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
1237                 goto handle_parent;
1238         len = g_slist_length (l);
1239         if (!System_Reflection_FieldInfo)
1240                 System_Reflection_FieldInfo = mono_class_from_name (
1241                         mono_defaults.corlib, "System.Reflection", "FieldInfo");
1242         res = mono_array_new (domain, System_Reflection_FieldInfo, len);
1243         i = 0;
1244         tmp = g_slist_reverse (l);
1245         for (; tmp; tmp = tmp->next, ++i)
1246                 mono_array_set (res, gpointer, i, tmp->data);
1247         g_slist_free (l);
1248         return res;
1249 }
1250
1251 static MonoArray*
1252 ves_icall_Type_GetMethods (MonoReflectionType *type, guint32 bflags)
1253 {
1254         MonoDomain *domain; 
1255         GSList *l = NULL, *tmp;
1256         static MonoClass *System_Reflection_MethodInfo;
1257         MonoClass *startklass, *klass;
1258         MonoArray *res;
1259         MonoMethod *method;
1260         MonoObject *member;
1261         int i, len, match;
1262
1263         domain = ((MonoObject *)type)->vtable->domain;
1264         klass = startklass = mono_class_from_mono_type (type->type);
1265
1266 handle_parent:
1267         for (i = 0; i < klass->method.count; ++i) {
1268                 match = 0;
1269                 method = klass->methods [i];
1270                 if (strcmp (method->name, ".ctor") == 0 || strcmp (method->name, ".cctor") == 0)
1271                         continue;
1272                 if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
1273                         if (bflags & BFLAGS_Public)
1274                                 match++;
1275                 } else {
1276                         if (bflags & BFLAGS_NonPublic)
1277                                 match++;
1278                 }
1279                 if (!match)
1280                         continue;
1281                 match = 0;
1282                 if (method->flags & METHOD_ATTRIBUTE_STATIC) {
1283                         if (bflags & BFLAGS_Static)
1284                                 match++;
1285                 } else {
1286                         if (bflags & BFLAGS_Instance)
1287                                 match++;
1288                 }
1289
1290                 if (!match)
1291                         continue;
1292                 match = 0;
1293                 member = (MonoObject*)mono_method_get_object (domain, method);
1294                         
1295                 l = g_slist_prepend (l, member);
1296         }
1297         if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
1298                 goto handle_parent;
1299         len = g_slist_length (l);
1300         if (!System_Reflection_MethodInfo)
1301                 System_Reflection_MethodInfo = mono_class_from_name (
1302                         mono_defaults.corlib, "System.Reflection", "MethodInfo");
1303         res = mono_array_new (domain, System_Reflection_MethodInfo, len);
1304         i = 0;
1305         tmp = l;
1306         for (; tmp; tmp = tmp->next, ++i)
1307                 mono_array_set (res, gpointer, i, tmp->data);
1308         g_slist_free (l);
1309         return res;
1310 }
1311
1312 static MonoArray*
1313 ves_icall_Type_GetConstructors (MonoReflectionType *type, guint32 bflags)
1314 {
1315         MonoDomain *domain; 
1316         GSList *l = NULL, *tmp;
1317         static MonoClass *System_Reflection_ConstructorInfo;
1318         MonoClass *startklass, *klass;
1319         MonoArray *res;
1320         MonoMethod *method;
1321         MonoObject *member;
1322         int i, len, match;
1323
1324         domain = ((MonoObject *)type)->vtable->domain;
1325         klass = startklass = mono_class_from_mono_type (type->type);
1326
1327 handle_parent:  
1328         for (i = 0; i < klass->method.count; ++i) {
1329                 match = 0;
1330                 method = klass->methods [i];
1331                 if (strcmp (method->name, ".ctor") && strcmp (method->name, ".cctor"))
1332                         continue;
1333                 if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
1334                         if (bflags & BFLAGS_Public)
1335                                 match++;
1336                 } else {
1337                         if (bflags & BFLAGS_NonPublic)
1338                                 match++;
1339                 }
1340                 if (!match)
1341                         continue;
1342                 match = 0;
1343                 if (method->flags & METHOD_ATTRIBUTE_STATIC) {
1344                         if (bflags & BFLAGS_Static)
1345                                 match++;
1346                 } else {
1347                         if (bflags & BFLAGS_Instance)
1348                                 match++;
1349                 }
1350
1351                 if (!match)
1352                         continue;
1353                 member = (MonoObject*)mono_method_get_object (domain, method);
1354                         
1355                 l = g_slist_prepend (l, member);
1356         }
1357         if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
1358                 goto handle_parent;
1359         len = g_slist_length (l);
1360         if (!System_Reflection_ConstructorInfo)
1361                 System_Reflection_ConstructorInfo = mono_class_from_name (
1362                         mono_defaults.corlib, "System.Reflection", "ConstructorInfo");
1363         res = mono_array_new (domain, System_Reflection_ConstructorInfo, len);
1364         i = 0;
1365         tmp = l;
1366         for (; tmp; tmp = tmp->next, ++i)
1367                 mono_array_set (res, gpointer, i, tmp->data);
1368         g_slist_free (l);
1369         return res;
1370 }
1371
1372 static MonoArray*
1373 ves_icall_Type_GetProperties (MonoReflectionType *type, guint32 bflags)
1374 {
1375         MonoDomain *domain; 
1376         GSList *l = NULL, *tmp;
1377         static MonoClass *System_Reflection_PropertyInfo;
1378         MonoClass *startklass, *klass;
1379         MonoArray *res;
1380         MonoMethod *method;
1381         MonoProperty *prop;
1382         int i, len, match;
1383
1384         domain = ((MonoObject *)type)->vtable->domain;
1385         klass = startklass = mono_class_from_mono_type (type->type);
1386
1387 handle_parent:
1388         for (i = 0; i < klass->property.count; ++i) {
1389                 prop = &klass->properties [i];
1390                 match = 0;
1391                 method = prop->get;
1392                 if (!method)
1393                         method = prop->set;
1394                 if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
1395                         if (bflags & BFLAGS_Public)
1396                                 match++;
1397                 } else {
1398                         if (bflags & BFLAGS_NonPublic)
1399                                 match++;
1400                 }
1401                 if (!match)
1402                         continue;
1403                 match = 0;
1404                 if (method->flags & METHOD_ATTRIBUTE_STATIC) {
1405                         if (bflags & BFLAGS_Static)
1406                                 match++;
1407                 } else {
1408                         if (bflags & BFLAGS_Instance)
1409                                 match++;
1410                 }
1411
1412                 if (!match)
1413                         continue;
1414                 match = 0;
1415                 l = g_slist_prepend (l, mono_property_get_object (domain, klass, prop));
1416         }
1417         if (!l && (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent)))
1418                 goto handle_parent;
1419         len = g_slist_length (l);
1420         if (!System_Reflection_PropertyInfo)
1421                 System_Reflection_PropertyInfo = mono_class_from_name (
1422                         mono_defaults.corlib, "System.Reflection", "PropertyInfo");
1423         res = mono_array_new (domain, System_Reflection_PropertyInfo, len);
1424         i = 0;
1425         tmp = l;
1426         for (; tmp; tmp = tmp->next, ++i)
1427                 mono_array_set (res, gpointer, i, tmp->data);
1428         g_slist_free (l);
1429         return res;
1430 }
1431
1432 static MonoArray*
1433 ves_icall_Type_GetEvents (MonoReflectionType *type, guint32 bflags)
1434 {
1435         MonoDomain *domain; 
1436         GSList *l = NULL, *tmp;
1437         static MonoClass *System_Reflection_EventInfo;
1438         MonoClass *startklass, *klass;
1439         MonoArray *res;
1440         MonoMethod *method;
1441         MonoEvent *event;
1442         int i, len, match;
1443
1444         domain = ((MonoObject *)type)->vtable->domain;
1445         klass = startklass = mono_class_from_mono_type (type->type);
1446
1447 handle_parent:  
1448         for (i = 0; i < klass->event.count; ++i) {
1449                 event = &klass->events [i];
1450                 match = 0;
1451                 method = event->add;
1452                 if (!method)
1453                         method = event->remove;
1454                 if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
1455                         if (bflags & BFLAGS_Public)
1456                                 match++;
1457                 } else {
1458                         if (bflags & BFLAGS_NonPublic)
1459                                 match++;
1460                 }
1461                 if (!match)
1462                         continue;
1463                 match = 0;
1464                 if (method->flags & METHOD_ATTRIBUTE_STATIC) {
1465                         if (bflags & BFLAGS_Static)
1466                                 match++;
1467                 } else {
1468                         if (bflags & BFLAGS_Instance)
1469                                 match++;
1470                 }
1471
1472                 if (!match)
1473                         continue;
1474                 match = 0;
1475                 l = g_slist_prepend (l, mono_event_get_object (domain, klass, event));
1476         }
1477         if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
1478                 goto handle_parent;
1479         len = g_slist_length (l);
1480         if (!System_Reflection_EventInfo)
1481                 System_Reflection_EventInfo = mono_class_from_name (
1482                         mono_defaults.corlib, "System.Reflection", "EventInfo");
1483         res = mono_array_new (domain, System_Reflection_EventInfo, len);
1484         i = 0;
1485         tmp = l;
1486         for (; tmp; tmp = tmp->next, ++i)
1487                 mono_array_set (res, gpointer, i, tmp->data);
1488         g_slist_free (l);
1489         return res;
1490 }
1491
1492 static MonoArray*
1493 ves_icall_Type_GetNestedTypes (MonoReflectionType *type, guint32 bflags)
1494 {
1495         MonoDomain *domain; 
1496         GSList *l = NULL, *tmp;
1497         GList *tmpn;
1498         MonoClass *startklass, *klass;
1499         MonoArray *res;
1500         MonoObject *member;
1501         int i, len, match;
1502         MonoClass *nested;
1503
1504         domain = ((MonoObject *)type)->vtable->domain;
1505         klass = startklass = mono_class_from_mono_type (type->type);
1506
1507         for (tmpn = klass->nested_classes; tmpn; tmpn = tmpn->next) {
1508                 match = 0;
1509                 nested = tmpn->data;
1510                 if ((nested->flags & TYPE_ATTRIBUTE_VISIBILITY_MASK) == TYPE_ATTRIBUTE_NESTED_PUBLIC) {
1511                         if (bflags & BFLAGS_Public)
1512                                 match++;
1513                 } else {
1514                         if (bflags & BFLAGS_NonPublic)
1515                                 match++;
1516                 }
1517                 if (!match)
1518                         continue;
1519                 member = (MonoObject*)mono_type_get_object (domain, &nested->byval_arg);
1520                 l = g_slist_prepend (l, member);
1521         }
1522         len = g_slist_length (l);
1523         res = mono_array_new (domain, mono_defaults.monotype_class, len);
1524         i = 0;
1525         tmp = g_slist_reverse (l);
1526         for (; tmp; tmp = tmp->next, ++i)
1527                 mono_array_set (res, gpointer, i, tmp->data);
1528         g_slist_free (l);
1529         return res;
1530 }
1531
1532 static gpointer
1533 ves_icall_System_Runtime_InteropServices_Marshal_ReadIntPtr (gpointer ptr)
1534 {
1535         return (gpointer)(*(int *)ptr);
1536 }
1537
1538 static MonoString*
1539 ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAuto (gpointer ptr)
1540 {
1541         MonoDomain *domain = mono_domain_get (); 
1542
1543         return mono_string_new (domain, (char *)ptr);
1544 }
1545
1546 static guint32 ves_icall_System_Runtime_InteropServices_Marshal_GetLastWin32Error(void)
1547 {
1548         return(GetLastError());
1549 }
1550
1551 static MonoReflectionType*
1552 ves_icall_System_Reflection_Assembly_GetType (MonoReflectionAssembly *assembly, MonoString *name, MonoBoolean throwOnError, MonoBoolean ignoreCase)
1553 {
1554         MonoDomain *domain = mono_domain_get (); 
1555         gchar *str;
1556         MonoType *type;
1557         MonoTypeNameParse info;
1558
1559         str = mono_string_to_utf8 (name);
1560         /*g_print ("requested type %s in %s\n", str, assembly->assembly->name);*/
1561         if (!mono_reflection_parse_type (str, &info)) {
1562                 g_free (str);
1563                 g_list_free (info.modifiers);
1564                 if (throwOnError) /* uhm: this is a parse error, though... */
1565                         mono_raise_exception (mono_get_exception_type_load ());
1566                 return NULL;
1567         }
1568
1569         type = mono_reflection_get_type (assembly->assembly->image, &info, ignoreCase);
1570         g_free (str);
1571         g_list_free (info.modifiers);
1572         if (!type) {
1573                 if (throwOnError)
1574                         mono_raise_exception (mono_get_exception_type_load ());
1575                 return NULL;
1576         }
1577         /*g_print ("got it\n");*/
1578         return mono_type_get_object (domain, type);
1579
1580 }
1581
1582 static MonoString *
1583 ves_icall_System_Reflection_Assembly_get_code_base (MonoReflectionAssembly *assembly)
1584 {
1585         MonoDomain *domain = mono_domain_get (); 
1586         MonoString *res;
1587         char *name = g_strconcat (
1588                 "file://", assembly->assembly->image->name, NULL);
1589         
1590         res = mono_string_new (domain, name);
1591         g_free (name);
1592         return res;
1593 }
1594
1595 static MonoString *
1596 ves_icall_System_MonoType_getFullName (MonoReflectionType *object)
1597 {
1598         MonoDomain *domain = mono_domain_get (); 
1599         MonoString *res;
1600         gchar *name;
1601
1602         name = mono_type_get_name (object->type);
1603         res = mono_string_new (domain, name);
1604         g_free (name);
1605
1606         return res;
1607 }
1608
1609 static MonoArray*
1610 ves_icall_System_Reflection_Assembly_GetTypes (MonoReflectionAssembly *assembly, MonoBoolean exportedOnly)
1611 {
1612         MonoDomain *domain = mono_domain_get (); 
1613         MonoArray *res;
1614         MonoClass *klass;
1615         MonoTableInfo *tdef = &assembly->assembly->image->tables [MONO_TABLE_TYPEDEF];
1616         int i, count;
1617         guint32 attrs, visibility;
1618
1619         if (exportedOnly) {
1620                 count = 0;
1621                 for (i = 0; i < tdef->rows; ++i) {
1622                         attrs = mono_metadata_decode_row_col (tdef, i, MONO_TYPEDEF_FLAGS);
1623                         visibility = attrs & TYPE_ATTRIBUTE_VISIBILITY_MASK;
1624                         if (visibility == TYPE_ATTRIBUTE_PUBLIC || visibility == TYPE_ATTRIBUTE_NESTED_PUBLIC)
1625                                 count++;
1626                 }
1627         } else {
1628                 count = tdef->rows;
1629         }
1630         res = mono_array_new (domain, mono_defaults.monotype_class, count);
1631         count = 0;
1632         for (i = 0; i < tdef->rows; ++i) {
1633                 attrs = mono_metadata_decode_row_col (tdef, i, MONO_TYPEDEF_FLAGS);
1634                 visibility = attrs & TYPE_ATTRIBUTE_VISIBILITY_MASK;
1635                 if (!exportedOnly || (visibility == TYPE_ATTRIBUTE_PUBLIC || visibility == TYPE_ATTRIBUTE_NESTED_PUBLIC)) {
1636                         klass = mono_class_get (assembly->assembly->image, (i + 1) | MONO_TOKEN_TYPE_DEF);
1637                         mono_array_set (res, gpointer, count, mono_type_get_object (domain, &klass->byval_arg));
1638                         count++;
1639                 }
1640         }
1641         
1642         return res;
1643 }
1644
1645 static MonoReflectionType*
1646 ves_icall_ModuleBuilder_create_modified_type (MonoReflectionTypeBuilder *tb, MonoString *smodifiers)
1647 {
1648         MonoClass *klass;
1649         int isbyref = 0, rank;
1650         char *str = mono_string_to_utf8 (smodifiers);
1651         char *p;
1652
1653         klass = mono_class_from_mono_type (tb->type.type);
1654         p = str;
1655         /* logic taken from mono_reflection_parse_type(): keep in sync */
1656         while (*p) {
1657                 switch (*p) {
1658                 case '&':
1659                         if (isbyref) /* only one level allowed by the spec */
1660                                 return NULL;
1661                         isbyref = 1;
1662                         p++;
1663                         return mono_type_get_object (mono_domain_get (), &klass->this_arg);
1664                         break;
1665                 case '*':
1666                         klass = mono_ptr_class_get (&klass->byval_arg);
1667                         mono_class_init (klass);
1668                         p++;
1669                         break;
1670                 case '[':
1671                         rank = 1;
1672                         p++;
1673                         while (*p) {
1674                                 if (*p == ']')
1675                                         break;
1676                                 if (*p == ',')
1677                                         rank++;
1678                                 else if (*p != '*') /* '*' means unknown lower bound */
1679                                         return NULL;
1680                                 ++p;
1681                         }
1682                         if (*p != ']')
1683                                 return NULL;
1684                         p++;
1685                         klass = mono_array_class_get (&klass->byval_arg, rank);
1686                         mono_class_init (klass);
1687                         break;
1688                 default:
1689                         break;
1690                 }
1691         }
1692         g_free (str);
1693         return mono_type_get_object (mono_domain_get (), &klass->byval_arg);
1694 }
1695
1696 /*
1697  * Magic number to convert a time which is relative to
1698  * Jan 1, 1970 into a value which is relative to Jan 1, 0001.
1699  */
1700 #define EPOCH_ADJUST    ((gint64)62135596800L)
1701
1702 static gint64
1703 ves_icall_System_DateTime_GetNow (void)
1704 {
1705 #ifndef PLATFORM_WIN32
1706         /* FIXME: put this in io-layer and call it GetLocalTime */
1707         struct timeval tv;
1708         gint64 res;
1709
1710         if (gettimeofday (&tv, NULL) == 0) {
1711                 res = (((gint64)tv.tv_sec + EPOCH_ADJUST)* 1000000 + tv.tv_usec)*10;
1712                 return res;
1713         }
1714
1715         /* fixme: raise exception */
1716 #endif
1717         return 0;
1718 }
1719
1720 /*
1721  * This is heavily based on zdump.c from glibc 2.2.
1722  *
1723  *  * data[0]:  start of daylight saving time (in DateTime ticks).
1724  *  * data[1]:  end of daylight saving time (in DateTime ticks).
1725  *  * data[2]:  utcoffset (in TimeSpan ticks).
1726  *  * data[3]:  additional offset when daylight saving (in TimeSpan ticks).
1727  *  * name[0]:  name of this timezone when not daylight saving.
1728  *  * name[1]:  name of this timezone when daylight saving.
1729  *
1730  *  FIXME: This only works with "standard" Unix dates (years between 1900 and 2100) while
1731  *         the class library allows years between 1 and 9999.
1732  *
1733  *  Returns true on success and zero on failure.
1734  */
1735 static guint32
1736 ves_icall_System_CurrentTimeZone_GetTimeZoneData (guint32 year, MonoArray **data, MonoArray **names)
1737 {
1738 #ifndef PLATFORM_WIN32
1739         MonoDomain *domain = mono_domain_get ();
1740         struct tm start, tt;
1741         time_t t;
1742
1743         long int gmtoff;
1744         int is_daylight = 0, day;
1745
1746         memset (&start, 0, sizeof (start));
1747
1748         start.tm_mday = 1;
1749         start.tm_year = year-1900;
1750
1751         t = mktime (&start);
1752         gmtoff = start.tm_gmtoff;
1753
1754         MONO_CHECK_ARG_NULL (data);
1755         MONO_CHECK_ARG_NULL (names);
1756
1757         (*data) = mono_array_new (domain, mono_defaults.int64_class, 4);
1758         (*names) = mono_array_new (domain, mono_defaults.string_class, 2);
1759
1760         /* For each day of the year, calculate the tm_gmtoff. */
1761         for (day = 0; day < 365; day++) {
1762
1763                 t += 3600*24;
1764                 tt = *localtime (&t);
1765
1766                 /* Daylight saving starts or ends here. */
1767                 if (tt.tm_gmtoff != gmtoff) {
1768                         struct tm tt1;
1769                         time_t t1;
1770
1771                         /* Try to find the exact hour when daylight saving starts/ends. */
1772                         t1 = t;
1773                         do {
1774                                 t1 -= 3600;
1775                                 tt1 = *localtime (&t1);
1776                         } while (tt1.tm_gmtoff != gmtoff);
1777
1778                         /* Try to find the exact minute when daylight saving starts/ends. */
1779                         do {
1780                                 t1 += 60;
1781                                 tt1 = *localtime (&t1);
1782                         } while (tt1.tm_gmtoff == gmtoff);
1783
1784                         /* Write data, if we're already in daylight saving, we're done. */
1785                         if (is_daylight) {
1786                                 mono_array_set ((*names), gpointer, 0, mono_string_new (domain, tt.tm_zone));
1787                                 mono_array_set ((*data), gint64, 1, ((gint64)t1 + EPOCH_ADJUST) * 10000000L);
1788                                 return 1;
1789                         } else {
1790                                 mono_array_set ((*names), gpointer, 1, mono_string_new (domain, tt.tm_zone));
1791                                 mono_array_set ((*data), gint64, 0, ((gint64)t1 + EPOCH_ADJUST) * 10000000L);
1792                                 is_daylight = 1;
1793                         }
1794
1795                         /* This is only set once when we enter daylight saving. */
1796                         mono_array_set ((*data), gint64, 2, (gint64)gmtoff * 10000000L);
1797                         mono_array_set ((*data), gint64, 3, (gint64)(tt.tm_gmtoff - gmtoff) * 10000000L);
1798
1799                         gmtoff = tt.tm_gmtoff;
1800                 }
1801
1802                 gmtoff = tt.tm_gmtoff;
1803         }
1804         return 1;
1805 #endif
1806         /* FIXME: This is a reminder to implement this icall on windows */
1807         return 0;
1808 }
1809
1810 static gpointer
1811 ves_icall_System_Object_obj_address (MonoObject *this) {
1812         return this;
1813 }
1814
1815 /* System.Buffer */
1816
1817 static gint32 
1818 ves_icall_System_Buffer_ByteLengthInternal (MonoArray *array) {
1819         MonoClass *klass;
1820         MonoTypeEnum etype;
1821         int length, esize;
1822         int i;
1823
1824         klass = array->obj.vtable->klass;
1825         etype = klass->element_class->byval_arg.type;
1826         if (etype < MONO_TYPE_BOOLEAN || etype > MONO_TYPE_R8)
1827                 return -1;
1828
1829         length = 0;
1830         for (i = 0; i < klass->rank; ++ i)
1831                 length += array->bounds [i].length;
1832
1833         esize = mono_array_element_size (klass);
1834         return length * esize;
1835 }
1836
1837 static gint8 
1838 ves_icall_System_Buffer_GetByteInternal (MonoArray *array, gint32 idx) {
1839         return mono_array_get (array, gint8, idx);
1840 }
1841
1842 static void 
1843 ves_icall_System_Buffer_SetByteInternal (MonoArray *array, gint32 idx, gint8 value) {
1844         mono_array_set (array, gint8, idx, value);
1845 }
1846
1847 static void 
1848 ves_icall_System_Buffer_BlockCopyInternal (MonoArray *src, gint32 src_offset, MonoArray *dest, gint32 dest_offset, gint32 count) {
1849         char *src_buf, *dest_buf;
1850
1851         src_buf = (gint8 *)src->vector + src_offset;
1852         dest_buf = (gint8 *)dest->vector + dest_offset;
1853
1854         memcpy (dest_buf, src_buf, count);
1855 }
1856
1857 static MonoObject *
1858 ves_icall_Remoting_RealProxy_GetTransparentProxy (MonoObject *this)
1859 {
1860         MonoDomain *domain = mono_domain_get (); 
1861         MonoObject *res;
1862         MonoRealProxy *rp = ((MonoRealProxy *)this);
1863         MonoType *type;
1864         MonoClass *klass;
1865
1866         res = mono_object_new (domain, mono_defaults.transparent_proxy_class);
1867         
1868         ((MonoTransparentProxy *)res)->rp = rp;
1869         type = ((MonoReflectionType *)rp->class_to_proxy)->type;
1870         klass = mono_class_from_mono_type (type);
1871
1872         res->vtable = mono_class_proxy_vtable (domain, klass);
1873
1874         return res;
1875 }
1876
1877 /* System.Environment */
1878
1879 static MonoString *
1880 ves_icall_System_Environment_get_MachineName (void)
1881 {
1882 #if defined (PLATFORM_WIN32)
1883         gunichar2 *buf;
1884         guint32 len;
1885         MonoString *result;
1886
1887         len = MAX_COMPUTERNAME_LENGTH + 1;
1888         buf = g_new (gunichar2, len);
1889
1890         result = NULL;
1891         if (GetComputerName (buf, &len))
1892                 result = mono_string_new_utf16 (mono_domain_get (), buf, len);
1893
1894         g_free (buf);
1895         return result;
1896 #else
1897         gchar *buf;
1898         int len;
1899         MonoString *result;
1900
1901         len = 256;
1902         buf = g_new (gchar, len);
1903
1904         result = NULL;
1905         if (gethostname (buf, len) != 0)
1906                 result = mono_string_new (mono_domain_get (), buf);
1907         
1908         g_free (buf);
1909         return result;
1910 #endif
1911 }
1912
1913 static MonoString *
1914 ves_icall_System_Environment_get_NewLine (void)
1915 {
1916 #if defined (PLATFORM_WIN32)
1917         return mono_string_new (mono_domain_get (), "\r\n");
1918 #else
1919         return mono_string_new (mono_domain_get (), "\n");
1920 #endif
1921 }
1922
1923 static MonoString *
1924 ves_icall_System_Environment_GetEnvironmentVariable (MonoString *name)
1925 {
1926         const gchar *value;
1927         gchar *utf8_name;
1928
1929         if (name == NULL)
1930                 return NULL;
1931
1932         utf8_name = mono_string_to_utf8 (name); /* FIXME: this should be ascii */
1933         value = g_getenv (utf8_name);
1934         g_free (utf8_name);
1935
1936         if (value == 0)
1937                 return NULL;
1938         
1939         return mono_string_new (mono_domain_get (), value);
1940 }
1941
1942 /*
1943  * There is no standard way to get at environ.
1944  */
1945 extern char **environ;
1946
1947 static MonoArray *
1948 ves_icall_System_Environment_GetEnvironmentVariableNames (void)
1949 {
1950         MonoArray *names;
1951         MonoDomain *domain;
1952         MonoString *str;
1953         gchar **e, **parts;
1954         int n;
1955
1956         n = 0;
1957         for (e = environ; *e != 0; ++ e)
1958                 ++ n;
1959
1960         domain = mono_domain_get ();
1961         names = mono_array_new (domain, mono_defaults.string_class, n);
1962
1963         n = 0;
1964         for (e = environ; *e != 0; ++ e) {
1965                 parts = g_strsplit (*e, "=", 2);
1966                 if (*parts != 0) {
1967                         str = mono_string_new (domain, *parts);
1968                         mono_array_set (names, MonoString *, n, str);
1969                 }
1970
1971                 g_strfreev (parts);
1972
1973                 ++ n;
1974         }
1975
1976         return names;
1977 }
1978
1979 static MonoString *
1980 ves_icall_System_Environment_GetCommandLine (void)
1981 {
1982         return NULL;    /* FIXME */
1983 }
1984
1985 static void
1986 ves_icall_MonoMethodMessage_InitMessage (MonoMethodMessage *this, 
1987                                          MonoReflectionMethod *method,
1988                                          MonoArray *out_args)
1989 {
1990         MonoDomain *domain = mono_domain_get ();
1991         
1992         mono_message_init (domain, this, method, out_args);
1993 }
1994
1995 static MonoBoolean
1996 ves_icall_IsTransparentProxy (MonoObject *proxy)
1997 {
1998         if (!proxy)
1999                 return 0;
2000
2001         if (proxy->vtable->klass == mono_defaults.transparent_proxy_class)
2002                 return 1;
2003
2004         return 0;
2005 }
2006
2007 static gint32
2008 ves_icall_System_String_InternalIndexOfAny (MonoString *str, MonoArray *chars, gint32 start, gint32 count)
2009 {
2010         int i, j;
2011         gunichar2 *data = mono_string_chars (str);
2012
2013         for (i = start; i < start + count; ++i) {
2014                 for (j = 0; j < mono_array_length (chars); ++j) {
2015                         if (data [i] == mono_array_get (chars, guint16, j))
2016                                 return i;
2017                 }
2018         }
2019         return -1;
2020 }
2021
2022 static gint32
2023 ves_icall_System_String_GetHashCode (MonoString *str)
2024 {
2025         int i, h = 0;
2026         gunichar2 *data = mono_string_chars (str);
2027
2028         for (i = 0; i < mono_string_length (str); ++i)
2029                 h = (h << 5) - h + data [i];
2030         return h;
2031 }
2032
2033 /* icall map */
2034
2035 static gconstpointer icall_map [] = {
2036         /*
2037          * System.Array
2038          */
2039         "System.Array::GetValue",         ves_icall_System_Array_GetValue,
2040         "System.Array::SetValue",         ves_icall_System_Array_SetValue,
2041         "System.Array::GetValueImpl",     ves_icall_System_Array_GetValueImpl,
2042         "System.Array::SetValueImpl",     ves_icall_System_Array_SetValueImpl,
2043         "System.Array::GetRank",          ves_icall_System_Array_GetRank,
2044         "System.Array::GetLength",        ves_icall_System_Array_GetLength,
2045         "System.Array::GetLowerBound",    ves_icall_System_Array_GetLowerBound,
2046         "System.Array::CreateInstanceImpl",   ves_icall_System_Array_CreateInstanceImpl,
2047         "System.Array::FastCopy",         ves_icall_System_Array_FastCopy,
2048         "System.Array::Clone",            mono_array_clone,
2049
2050         /*
2051          * System.Object
2052          */
2053         "System.Object::MemberwiseClone", ves_icall_System_Object_MemberwiseClone,
2054         "System.Object::GetType", ves_icall_System_Object_GetType,
2055         "System.Object::GetHashCode", ves_icall_System_Object_GetHashCode,
2056         "System.Object::obj_address", ves_icall_System_Object_obj_address,
2057
2058         /*
2059          * System.ValueType
2060          */
2061         "System.ValueType::GetHashCode", ves_icall_System_ValueType_GetHashCode,
2062         "System.ValueType::Equals", ves_icall_System_ValueType_Equals,
2063
2064         /*
2065          * System.String
2066          */
2067         "System.String::_IsInterned", mono_string_is_interned,
2068         "System.String::_Intern", mono_string_intern,
2069         "System.String::InternalIndexOfAny", ves_icall_System_String_InternalIndexOfAny,
2070         "System.String::GetHashCode", ves_icall_System_String_GetHashCode,
2071
2072         /*
2073          * System.AppDomain
2074          */
2075         "System.AppDomain::createDomain", ves_icall_System_AppDomain_createDomain,
2076         "System.AppDomain::getCurDomain", ves_icall_System_AppDomain_getCurDomain,
2077         "System.AppDomain::GetData", ves_icall_System_AppDomain_GetData,
2078         "System.AppDomain::SetData", ves_icall_System_AppDomain_SetData,
2079         "System.AppDomain::getSetup", ves_icall_System_AppDomain_getSetup,
2080         "System.AppDomain::getFriendlyName", ves_icall_System_AppDomain_getFriendlyName,
2081         "System.AppDomain::GetAssemblies", ves_icall_System_AppDomain_GetAssemblies,
2082         "System.AppDomain::LoadAssembly", ves_icall_System_AppDomain_LoadAssembly,
2083         "System.AppDomain::Unload", ves_icall_System_AppDomain_Unload,
2084         "System.AppDomain::ExecuteAssembly", ves_icall_System_AppDomain_ExecuteAssembly,
2085
2086         /*
2087          * System.AppDomainSetup
2088          */
2089         "System.AppDomainSetup::InitAppDomainSetup", ves_icall_System_AppDomainSetup_InitAppDomainSetup,
2090
2091         /*
2092          * System.Double
2093          */
2094         "System.Double::ToStringImpl", mono_double_ToStringImpl,
2095
2096         /*
2097          * System.Decimal
2098          */
2099         "System.Decimal::decimal2UInt64", mono_decimal2UInt64,
2100         "System.Decimal::decimal2Int64", mono_decimal2Int64,
2101         "System.Decimal::double2decimal", mono_double2decimal, /* FIXME: wrong signature. */
2102         "System.Decimal::decimalIncr", mono_decimalIncr,
2103         "System.Decimal::decimalSetExponent", mono_decimalSetExponent,
2104         "System.Decimal::decimal2double", mono_decimal2double,
2105         "System.Decimal::decimalFloorAndTrunc", mono_decimalFloorAndTrunc,
2106         "System.Decimal::decimalRound", mono_decimalRound,
2107         "System.Decimal::decimalMult", mono_decimalMult,
2108         "System.Decimal::decimalDiv", mono_decimalDiv,
2109         "System.Decimal::decimalIntDiv", mono_decimalIntDiv,
2110         "System.Decimal::decimalCompare", mono_decimalCompare,
2111         "System.Decimal::string2decimal", mono_string2decimal,
2112         "System.Decimal::decimal2string", mono_decimal2string,
2113
2114         /*
2115          * ModuleBuilder
2116          */
2117         "System.Reflection.Emit.ModuleBuilder::create_modified_type", ves_icall_ModuleBuilder_create_modified_type,
2118         
2119         /*
2120          * AssemblyBuilder
2121          */
2122         "System.Reflection.Emit.AssemblyBuilder::getDataChunk", ves_icall_AssemblyBuilder_getDataChunk,
2123         "System.Reflection.Emit.AssemblyBuilder::getPEHeader", ves_icall_AssemblyBuilder_getPEHeader,
2124         "System.Reflection.Emit.AssemblyBuilder::getUSIndex", mono_image_insert_string,
2125         "System.Reflection.Emit.AssemblyBuilder::getToken", ves_icall_AssemblyBuilder_getToken,
2126         "System.Reflection.Emit.AssemblyBuilder::basic_init", mono_image_basic_init,
2127
2128         /*
2129          * Reflection stuff.
2130          */
2131         "System.Reflection.MonoMethodInfo::get_method_info", ves_icall_get_method_info,
2132         "System.Reflection.MonoMethodInfo::get_parameter_info", ves_icall_get_parameter_info,
2133         "System.Reflection.MonoFieldInfo::get_field_info", ves_icall_get_field_info,
2134         "System.Reflection.MonoPropertyInfo::get_property_info", ves_icall_get_property_info,
2135         "System.Reflection.MonoMethod::InternalInvoke", ves_icall_InternalInvoke,
2136         "System.Reflection.MonoMethod::get_Name", ves_icall_MonoMethod_get_Name,
2137         "System.Reflection.MonoCMethod::InternalInvoke", ves_icall_InternalInvoke,
2138         "System.MonoCustomAttrs::GetCustomAttributes", mono_reflection_get_custom_attrs,
2139         "System.Reflection.Emit.CustomAttributeBuilder::GetBlob", mono_reflection_get_custom_attrs_blob,
2140         "System.Reflection.MonoField::GetValue", ves_icall_MonoField_GetValue,
2141         "System.Reflection.Emit.SignatureHelper::get_signature_local", mono_reflection_sighelper_get_signature_local,
2142         "System.Reflection.Emit.SignatureHelper::get_signature_field", mono_reflection_sighelper_get_signature_field,
2143
2144         
2145         /* System.Enum */
2146
2147         "System.MonoEnumInfo::get_enum_info", ves_icall_get_enum_info,
2148         "System.Enum::get_value", ves_icall_System_Enum_get_value,
2149         "System.Enum::ToObject", ves_icall_System_Enum_ToObject,
2150
2151         /*
2152          * TypeBuilder
2153          */
2154         "System.Reflection.Emit.TypeBuilder::setup_internal_class", mono_reflection_setup_internal_class,
2155
2156         
2157         /*
2158          * MethodBuilder
2159          */
2160         
2161         /*
2162          * System.Type
2163          */
2164         "System.Type::internal_from_name", ves_icall_type_from_name,
2165         "System.Type::internal_from_handle", ves_icall_type_from_handle,
2166         "System.Type::get_constructor", ves_icall_get_constructor,
2167         "System.Type::get_property", ves_icall_get_property,
2168         "System.Type::get_method", ves_icall_get_method,
2169         "System.MonoType::get_attributes", ves_icall_get_attributes,
2170         "System.Type::type_is_subtype_of", ves_icall_type_is_subtype_of,
2171         "System.Type::Equals", ves_icall_type_Equals,
2172
2173         /*
2174          * System.Runtime.CompilerServices.RuntimeHelpers
2175          */
2176         "System.Runtime.CompilerServices.RuntimeHelpers::InitializeArray", ves_icall_InitializeArray,
2177         
2178         /*
2179          * System.Threading
2180          */
2181         "System.Threading.Thread::Thread_internal", ves_icall_System_Threading_Thread_Thread_internal,
2182         "System.Threading.Thread::Start_internal", ves_icall_System_Threading_Thread_Start_internal,
2183         "System.Threading.Thread::Sleep_internal", ves_icall_System_Threading_Thread_Sleep_internal,
2184         "System.Threading.Thread::CurrentThread_internal", ves_icall_System_Threading_Thread_CurrentThread_internal,
2185         "System.Threading.Thread::CurrentThreadDomain_internal", ves_icall_System_Threading_Thread_CurrentThreadDomain_internal,
2186         "System.Threading.Thread::Join_internal", ves_icall_System_Threading_Thread_Join_internal,
2187         "System.Threading.Thread::SlotHash_lookup", ves_icall_System_Threading_Thread_SlotHash_lookup,
2188         "System.Threading.Thread::SlotHash_store", ves_icall_System_Threading_Thread_SlotHash_store,
2189         "System.Threading.Monitor::Monitor_exit", ves_icall_System_Threading_Monitor_Monitor_exit,
2190         "System.Threading.Monitor::Monitor_test_owner", ves_icall_System_Threading_Monitor_Monitor_test_owner,
2191         "System.Threading.Monitor::Monitor_test_synchronised", ves_icall_System_Threading_Monitor_Monitor_test_synchronised,
2192         "System.Threading.Monitor::Monitor_pulse", ves_icall_System_Threading_Monitor_Monitor_pulse,
2193         "System.Threading.Monitor::Monitor_pulse_all", ves_icall_System_Threading_Monitor_Monitor_pulse_all,
2194         "System.Threading.Monitor::Monitor_try_enter", ves_icall_System_Threading_Monitor_Monitor_try_enter,
2195         "System.Threading.Monitor::Monitor_wait", ves_icall_System_Threading_Monitor_Monitor_wait,
2196         "System.Threading.Mutex::CreateMutex_internal", ves_icall_System_Threading_Mutex_CreateMutex_internal,
2197         "System.Threading.Mutex::ReleaseMutex_internal", ves_icall_System_Threading_Mutex_ReleaseMutex_internal,
2198         "System.Threading.NativeEventCalls::CreateEvent_internal", ves_icall_System_Threading_Events_CreateEvent_internal,
2199         "System.Threading.NativeEventCalls::SetEvent_internal",    ves_icall_System_Threading_Events_SetEvent_internal,
2200         "System.Threading.NativeEventCalls::ResetEvent_internal",  ves_icall_System_Threading_Events_ResetEvent_internal,
2201
2202         /*
2203          * System.Threading.WaitHandle
2204          */
2205         "System.Threading.WaitHandle::WaitAll_internal", ves_icall_System_Threading_WaitHandle_WaitAll_internal,
2206         "System.Threading.WaitHandle::WaitAny_internal", ves_icall_System_Threading_WaitHandle_WaitAny_internal,
2207         "System.Threading.WaitHandle::WaitOne_internal", ves_icall_System_Threading_WaitHandle_WaitOne_internal,
2208
2209         "System.Runtime.InteropServices.Marshal::ReadIntPtr", ves_icall_System_Runtime_InteropServices_Marshal_ReadIntPtr,
2210         "System.Runtime.InteropServices.Marshal::PtrToStringAuto", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAuto,
2211         "System.Runtime.InteropServices.Marshal::GetLastWin32Error", ves_icall_System_Runtime_InteropServices_Marshal_GetLastWin32Error,
2212
2213         "System.Reflection.Assembly::GetType", ves_icall_System_Reflection_Assembly_GetType,
2214         "System.Reflection.Assembly::GetTypes", ves_icall_System_Reflection_Assembly_GetTypes,
2215         "System.Reflection.Assembly::get_code_base", ves_icall_System_Reflection_Assembly_get_code_base,
2216
2217         /*
2218          * System.MonoType.
2219          */
2220         "System.MonoType::getFullName", ves_icall_System_MonoType_getFullName,
2221         "System.MonoType::type_from_obj", mono_type_type_from_obj,
2222         "System.MonoType::get_type_info", ves_icall_get_type_info,
2223         "System.MonoType::GetFields", ves_icall_Type_GetFields,
2224         "System.MonoType::GetMethods", ves_icall_Type_GetMethods,
2225         "System.MonoType::GetConstructors", ves_icall_Type_GetConstructors,
2226         "System.MonoType::GetProperties", ves_icall_Type_GetProperties,
2227         "System.MonoType::GetEvents", ves_icall_Type_GetEvents,
2228         "System.MonoType::GetInterfaces", ves_icall_Type_GetInterfaces,
2229         "System.MonoType::GetNestedTypes", ves_icall_Type_GetNestedTypes,
2230
2231         /*
2232          * System.Net.Sockets I/O Services
2233          */
2234         "System.Net.Sockets.Socket::Socket_internal", ves_icall_System_Net_Sockets_Socket_Socket_internal,
2235         "System.Net.Sockets.Socket::Close_internal", ves_icall_System_Net_Sockets_Socket_Close_internal,
2236         "System.Net.Sockets.SocketException::WSAGetLastError_internal", ves_icall_System_Net_Sockets_SocketException_WSAGetLastError_internal,
2237         "System.Net.Sockets.Socket::Available_internal", ves_icall_System_Net_Sockets_Socket_Available_internal,
2238         "System.Net.Sockets.Socket::Blocking_internal", ves_icall_System_Net_Sockets_Socket_Blocking_internal,
2239         "System.Net.Sockets.Socket::Accept_internal", ves_icall_System_Net_Sockets_Socket_Accept_internal,
2240         "System.Net.Sockets.Socket::Listen_internal", ves_icall_System_Net_Sockets_Socket_Listen_internal,
2241         "System.Net.Sockets.Socket::LocalEndPoint_internal", ves_icall_System_Net_Sockets_Socket_LocalEndPoint_internal,
2242         "System.Net.Sockets.Socket::RemoteEndPoint_internal", ves_icall_System_Net_Sockets_Socket_RemoteEndPoint_internal,
2243         "System.Net.Sockets.Socket::Bind_internal", ves_icall_System_Net_Sockets_Socket_Bind_internal,
2244         "System.Net.Sockets.Socket::Connect_internal", ves_icall_System_Net_Sockets_Socket_Connect_internal,
2245         "System.Net.Sockets.Socket::Receive_internal", ves_icall_System_Net_Sockets_Socket_Receive_internal,
2246         "System.Net.Sockets.Socket::RecvFrom_internal", ves_icall_System_Net_Sockets_Socket_RecvFrom_internal,
2247         "System.Net.Sockets.Socket::Send_internal", ves_icall_System_Net_Sockets_Socket_Send_internal,
2248         "System.Net.Sockets.Socket::SendTo_internal", ves_icall_System_Net_Sockets_Socket_SendTo_internal,
2249         "System.Net.Sockets.Socket::Select_internal", ves_icall_System_Net_Sockets_Socket_Select_internal,
2250         "System.Net.Sockets.Socket::Shutdown_internal", ves_icall_System_Net_Sockets_Socket_Shutdown_internal,
2251         "System.Net.Sockets.Socket::GetSocketOption_obj_internal", ves_icall_System_Net_Sockets_Socket_GetSocketOption_obj_internal,
2252         "System.Net.Sockets.Socket::GetSocketOption_arr_internal", ves_icall_System_Net_Sockets_Socket_GetSocketOption_arr_internal,
2253         "System.Net.Sockets.Socket::SetSocketOption_internal", ves_icall_System_Net_Sockets_Socket_SetSocketOption_internal,
2254         "System.Net.Dns::GetHostByName_internal", ves_icall_System_Net_Dns_GetHostByName_internal,
2255         "System.Net.Dns::GetHostByAddr_internal", ves_icall_System_Net_Dns_GetHostByAddr_internal,
2256
2257         /*
2258          * System.Char
2259          */
2260         "System.Char::GetNumericValue", ves_icall_System_Char_GetNumericValue,
2261         "System.Char::GetUnicodeCategory", ves_icall_System_Char_GetUnicodeCategory,
2262         "System.Char::IsControl", ves_icall_System_Char_IsControl,
2263         "System.Char::IsDigit", ves_icall_System_Char_IsDigit,
2264         "System.Char::IsLetter", ves_icall_System_Char_IsLetter,
2265         "System.Char::IsLower", ves_icall_System_Char_IsLower,
2266         "System.Char::IsUpper", ves_icall_System_Char_IsUpper,
2267         "System.Char::IsNumber", ves_icall_System_Char_IsNumber,
2268         "System.Char::IsPunctuation", ves_icall_System_Char_IsPunctuation,
2269         "System.Char::IsSeparator", ves_icall_System_Char_IsSeparator,
2270         "System.Char::IsSurrogate", ves_icall_System_Char_IsSurrogate,
2271         "System.Char::IsSymbol", ves_icall_System_Char_IsSymbol,
2272         "System.Char::IsWhiteSpace", ves_icall_System_Char_IsWhiteSpace,
2273         "System.Char::ToLower", ves_icall_System_Char_ToLower,
2274         "System.Char::ToUpper", ves_icall_System_Char_ToUpper,
2275
2276         "System.Text.Encoding::IConvNewEncoder", ves_icall_iconv_new_encoder,
2277         "System.Text.Encoding::IConvNewDecoder", ves_icall_iconv_new_decoder,
2278         "System.Text.Encoding::IConvReset", ves_icall_iconv_reset,
2279         "System.Text.Encoding::IConvGetByteCount", ves_icall_iconv_get_byte_count,
2280         "System.Text.Encoding::IConvGetBytes", ves_icall_iconv_get_bytes,
2281         "System.Text.Encoding::IConvGetCharCount", ves_icall_iconv_get_char_count,
2282         "System.Text.Encoding::IConvGetChars", ves_icall_iconv_get_chars,
2283
2284         "System.DateTime::GetNow", ves_icall_System_DateTime_GetNow,
2285         "System.CurrentTimeZone::GetTimeZoneData", ves_icall_System_CurrentTimeZone_GetTimeZoneData,
2286
2287         /*
2288          * System.Security.Cryptography calls
2289          */
2290
2291          "System.Security.Cryptography.RNGCryptoServiceProvider::GetBytes", ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_GetBytes,
2292          "System.Security.Cryptography.RNG_CryptoServiceProvider::GetNonZeroBytes", ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_GetNonZeroBytes,
2293         
2294         /*
2295          * System.Buffer
2296          */
2297         "System.Buffer::ByteLengthInternal", ves_icall_System_Buffer_ByteLengthInternal,
2298         "System.Buffer::GetByteInternal", ves_icall_System_Buffer_GetByteInternal,
2299         "System.Buffer::SetByteInternal", ves_icall_System_Buffer_SetByteInternal,
2300         "System.Buffer::BlockCopyInternal", ves_icall_System_Buffer_BlockCopyInternal,
2301
2302         /*
2303          * System.IO.MonoIO
2304          */
2305         "System.IO.MonoIO::GetLastError", ves_icall_System_IO_MonoIO_GetLastError,
2306         "System.IO.MonoIO::CreateDirectory", ves_icall_System_IO_MonoIO_CreateDirectory,
2307         "System.IO.MonoIO::RemoveDirectory", ves_icall_System_IO_MonoIO_RemoveDirectory,
2308         "System.IO.MonoIO::FindFirstFile", ves_icall_System_IO_MonoIO_FindFirstFile,
2309         "System.IO.MonoIO::FindNextFile", ves_icall_System_IO_MonoIO_FindNextFile,
2310         "System.IO.MonoIO::FindClose", ves_icall_System_IO_MonoIO_FindClose,
2311         "System.IO.MonoIO::GetCurrentDirectory", ves_icall_System_IO_MonoIO_GetCurrentDirectory,
2312         "System.IO.MonoIO::SetCurrentDirectory", ves_icall_System_IO_MonoIO_SetCurrentDirectory,
2313         "System.IO.MonoIO::MoveFile", ves_icall_System_IO_MonoIO_MoveFile,
2314         "System.IO.MonoIO::CopyFile", ves_icall_System_IO_MonoIO_CopyFile,
2315         "System.IO.MonoIO::DeleteFile", ves_icall_System_IO_MonoIO_DeleteFile,
2316         "System.IO.MonoIO::GetFileAttributes", ves_icall_System_IO_MonoIO_GetFileAttributes,
2317         "System.IO.MonoIO::SetFileAttributes", ves_icall_System_IO_MonoIO_SetFileAttributes,
2318         "System.IO.MonoIO::GetFileStat", ves_icall_System_IO_MonoIO_GetFileStat,
2319         "System.IO.MonoIO::Open", ves_icall_System_IO_MonoIO_Open,
2320         "System.IO.MonoIO::Close", ves_icall_System_IO_MonoIO_Close,
2321         "System.IO.MonoIO::Read", ves_icall_System_IO_MonoIO_Read,
2322         "System.IO.MonoIO::Write", ves_icall_System_IO_MonoIO_Write,
2323         "System.IO.MonoIO::Seek", ves_icall_System_IO_MonoIO_Seek,
2324         "System.IO.MonoIO::GetLength", ves_icall_System_IO_MonoIO_GetLength,
2325         "System.IO.MonoIO::SetLength", ves_icall_System_IO_MonoIO_SetLength,
2326         "System.IO.MonoIO::SetFileTime", ves_icall_System_IO_MonoIO_SetFileTime,
2327         "System.IO.MonoIO::Flush", ves_icall_System_IO_MonoIO_Flush,
2328         "System.IO.MonoIO::get_ConsoleOutput", ves_icall_System_IO_MonoIO_get_ConsoleOutput,
2329         "System.IO.MonoIO::get_ConsoleInput", ves_icall_System_IO_MonoIO_get_ConsoleInput,
2330         "System.IO.MonoIO::get_ConsoleError", ves_icall_System_IO_MonoIO_get_ConsoleError,
2331         "System.IO.MonoIO::get_VolumeSeparatorChar", ves_icall_System_IO_MonoIO_get_VolumeSeparatorChar,
2332         "System.IO.MonoIO::get_DirectorySeparatorChar", ves_icall_System_IO_MonoIO_get_DirectorySeparatorChar,
2333         "System.IO.MonoIO::get_AltDirectorySeparatorChar", ves_icall_System_IO_MonoIO_get_AltDirectorySeparatorChar,
2334         "System.IO.MonoIO::get_PathSeparator", ves_icall_System_IO_MonoIO_get_PathSeparator,
2335         "System.IO.MonoIO::get_InvalidPathChars", ves_icall_System_IO_MonoIO_get_InvalidPathChars,
2336
2337         /*
2338          * System.Math
2339          */
2340         "System.Math::Sin", ves_icall_System_Math_Sin,
2341         "System.Math::Cos", ves_icall_System_Math_Cos,
2342         "System.Math::Tan", ves_icall_System_Math_Tan,
2343         "System.Math::Sinh", ves_icall_System_Math_Sinh,
2344         "System.Math::Cosh", ves_icall_System_Math_Cosh,
2345         "System.Math::Tanh", ves_icall_System_Math_Tanh,
2346         "System.Math::Acos", ves_icall_System_Math_Acos,
2347         "System.Math::Asin", ves_icall_System_Math_Asin,
2348         "System.Math::Atan", ves_icall_System_Math_Atan,
2349         "System.Math::Atan2", ves_icall_System_Math_Atan2,
2350         "System.Math::Exp", ves_icall_System_Math_Exp,
2351         "System.Math::Log", ves_icall_System_Math_Log,
2352         "System.Math::Log10", ves_icall_System_Math_Log10,
2353         "System.Math::Pow", ves_icall_System_Math_Pow,
2354         "System.Math::Sqrt", ves_icall_System_Math_Sqrt,
2355
2356         /*
2357          * System.Environment
2358          */
2359         "System.Environment::get_MachineName", ves_icall_System_Environment_get_MachineName,
2360         "System.Environment::get_NewLine", ves_icall_System_Environment_get_NewLine,
2361         "System.Environment::GetEnvironmentVariable", ves_icall_System_Environment_GetEnvironmentVariable,
2362         "System.Environment::GetEnvironmentVariableNames", ves_icall_System_Environment_GetEnvironmentVariableNames,
2363         "System.Environment::GetCommandLine", ves_icall_System_Environment_GetCommandLine,
2364
2365         /*
2366          * Mono.CSharp.Debugger
2367          */
2368         "Mono.CSharp.Debugger.MonoSymbolWriter::get_local_type_from_sig", 
2369         ves_icall_Debugger_MonoSymbolWriter_get_local_type_from_sig,
2370         "Mono.CSharp.Debugger.MonoSymbolWriter::get_method", 
2371         ves_icall_Debugger_MonoSymbolWriter_method_from_token,
2372         "Mono.CSharp.Debugger.DwarfFileWriter::get_type_token", 
2373         ves_icall_Debugger_DwarfFileWriter_get_type_token,
2374
2375
2376         /*
2377          * System.Runtime.Remoting
2378          */     
2379         "System.Runtime.Remoting.RemotingServices::InternalExecute",
2380         ves_icall_InternalExecute,
2381         "System.Runtime.Remoting.RemotingServices::IsTransparentProxy",
2382         ves_icall_IsTransparentProxy,
2383
2384         /*
2385          * System.Runtime.Remoting.Messaging
2386          */     
2387         "System.Runtime.Remoting.Messaging.MonoMethodMessage::InitMessage",
2388         ves_icall_MonoMethodMessage_InitMessage,
2389         
2390         /*
2391          * System.Runtime.Remoting.Proxies
2392          */     
2393         "System.Runtime.Remoting.Proxies.RealProxy::GetTransparentProxy", 
2394         ves_icall_Remoting_RealProxy_GetTransparentProxy,
2395
2396         /*
2397          * add other internal calls here
2398          */
2399         NULL, NULL
2400 };
2401
2402 void
2403 mono_init_icall (void)
2404 {
2405         const char *name;
2406         int i = 0;
2407
2408         while ((name = icall_map [i])) {
2409                 mono_add_internal_call (name, icall_map [i+1]);
2410                 i += 2;
2411         }
2412        
2413 }
2414
2415