5 * Dietmar Maurer (dietmar@ximian.com)
6 * Paolo Molaro (lupus@ximian.com)
7 * Patrik Torstensson (patrik.torstensson@labs2.com)
9 * (C) 2001 Ximian, Inc.
18 #if defined (PLATFORM_WIN32)
22 #include <mono/metadata/object.h>
23 #include <mono/metadata/threads.h>
24 #include <mono/metadata/monitor.h>
25 #include <mono/metadata/reflection.h>
26 #include <mono/metadata/assembly.h>
27 #include <mono/metadata/tabledefs.h>
28 #include <mono/metadata/exception.h>
29 #include <mono/metadata/file-io.h>
30 #include <mono/metadata/socket-io.h>
31 #include <mono/metadata/mono-endian.h>
32 #include <mono/metadata/tokentype.h>
33 #include <mono/metadata/unicode.h>
34 #include <mono/metadata/appdomain.h>
35 #include <mono/metadata/marshal.h>
36 #include <mono/metadata/gc-internal.h>
37 #include <mono/metadata/rand.h>
38 #include <mono/metadata/sysmath.h>
39 #include <mono/metadata/string-icalls.h>
40 #include <mono/metadata/mono-debug-debugger.h>
41 #include <mono/metadata/process.h>
42 #include <mono/metadata/environment.h>
43 #include <mono/metadata/profiler-private.h>
44 #include <mono/metadata/locales.h>
45 #include <mono/io-layer/io-layer.h>
46 #include <mono/utils/strtod.h>
47 #include <mono/utils/monobitset.h>
49 #if defined (PLATFORM_WIN32)
54 static MonoReflectionAssembly* ves_icall_System_Reflection_Assembly_GetCallingAssembly (void);
58 * We expect a pointer to a char, not a string
61 mono_double_ParseImpl (char *ptr)
69 result = bsd_strtod (ptr, &endptr);
71 if (!*ptr || (endptr && *endptr))
72 mono_raise_exception (mono_exception_from_name (mono_defaults.corlib,
80 ves_icall_System_Double_AssertEndianity (double *value)
84 MONO_DOUBLE_ASSERT_ENDIANITY (value);
88 ves_icall_System_Array_GetValueImpl (MonoObject *this, guint32 pos)
97 ao = (MonoArray *)this;
98 ac = (MonoClass *)ao->obj.vtable->klass;
100 esize = mono_array_element_size (ac);
101 ea = (gpointer*)((char*)ao->vector + (pos * esize));
103 if (ac->element_class->valuetype)
104 return mono_value_box (this->vtable->domain, ac->element_class, ea);
110 ves_icall_System_Array_GetValue (MonoObject *this, MonoObject *idxs)
118 MONO_CHECK_ARG_NULL (idxs);
120 io = (MonoArray *)idxs;
121 ic = (MonoClass *)io->obj.vtable->klass;
123 ao = (MonoArray *)this;
124 ac = (MonoClass *)ao->obj.vtable->klass;
126 g_assert (ic->rank == 1);
127 if (io->bounds != NULL || io->max_length != ac->rank)
128 mono_raise_exception (mono_get_exception_argument (NULL, NULL));
130 ind = (guint32 *)io->vector;
132 if (ao->bounds == NULL) {
133 if (*ind < 0 || *ind >= ao->max_length)
134 mono_raise_exception (mono_get_exception_index_out_of_range ());
136 return ves_icall_System_Array_GetValueImpl (this, *ind);
139 for (i = 0; i < ac->rank; i++)
140 if ((ind [i] < ao->bounds [i].lower_bound) ||
141 (ind [i] >= ao->bounds [i].length + ao->bounds [i].lower_bound))
142 mono_raise_exception (mono_get_exception_index_out_of_range ());
144 pos = ind [0] - ao->bounds [0].lower_bound;
145 for (i = 1; i < ac->rank; i++)
146 pos = pos*ao->bounds [i].length + ind [i] -
147 ao->bounds [i].lower_bound;
149 return ves_icall_System_Array_GetValueImpl (this, pos);
153 ves_icall_System_Array_SetValueImpl (MonoArray *this, MonoObject *value, guint32 pos)
155 MonoClass *ac, *vc, *ec;
166 vc = value->vtable->klass;
170 ac = this->obj.vtable->klass;
171 ec = ac->element_class;
173 esize = mono_array_element_size (ac);
174 ea = (gpointer*)((char*)this->vector + (pos * esize));
175 va = (gpointer*)((char*)value + sizeof (MonoObject));
178 memset (ea, 0, esize);
182 #define NO_WIDENING_CONVERSION G_STMT_START{\
183 mono_raise_exception (mono_get_exception_argument ( \
184 "value", "not a widening conversion")); \
187 #define CHECK_WIDENING_CONVERSION(extra) G_STMT_START{\
188 if (esize < vsize + (extra)) \
189 mono_raise_exception (mono_get_exception_argument ( \
190 "value", "not a widening conversion")); \
193 #define INVALID_CAST G_STMT_START{\
194 mono_raise_exception (mono_get_exception_invalid_cast ()); \
197 /* Check element (destination) type. */
198 switch (ec->byval_arg.type) {
199 case MONO_TYPE_STRING:
200 switch (vc->byval_arg.type) {
201 case MONO_TYPE_STRING:
207 case MONO_TYPE_BOOLEAN:
208 switch (vc->byval_arg.type) {
209 case MONO_TYPE_BOOLEAN:
222 NO_WIDENING_CONVERSION;
229 if (!ec->valuetype) {
230 if (!mono_object_isinst (value, ec))
232 *ea = (gpointer)value;
236 if (mono_object_isinst (value, ec)) {
237 memcpy (ea, (char *)value + sizeof (MonoObject), esize);
244 vsize = mono_class_instance_size (vc) - sizeof (MonoObject);
247 g_message (G_STRLOC ": %d (%d) <= %d (%d)",
248 ec->byval_arg.type, esize,
249 vc->byval_arg.type, vsize);
252 #define ASSIGN_UNSIGNED(etype) G_STMT_START{\
253 switch (vc->byval_arg.type) { \
258 case MONO_TYPE_CHAR: \
259 CHECK_WIDENING_CONVERSION(0); \
260 *(etype *) ea = (etype) u64; \
262 /* You can't assign a signed value to an unsigned array. */ \
267 /* You can't assign a floating point number to an integer array. */ \
270 NO_WIDENING_CONVERSION; \
274 #define ASSIGN_SIGNED(etype) G_STMT_START{\
275 switch (vc->byval_arg.type) { \
280 CHECK_WIDENING_CONVERSION(0); \
281 *(etype *) ea = (etype) i64; \
283 /* You can assign an unsigned value to a signed array if the array's */ \
284 /* element size is larger than the value size. */ \
289 case MONO_TYPE_CHAR: \
290 CHECK_WIDENING_CONVERSION(1); \
291 *(etype *) ea = (etype) u64; \
293 /* You can't assign a floating point number to an integer array. */ \
296 NO_WIDENING_CONVERSION; \
300 #define ASSIGN_REAL(etype) G_STMT_START{\
301 switch (vc->byval_arg.type) { \
304 CHECK_WIDENING_CONVERSION(0); \
305 *(etype *) ea = (etype) r64; \
307 /* All integer values fit into a floating point array, so we don't */ \
308 /* need to CHECK_WIDENING_CONVERSION here. */ \
313 *(etype *) ea = (etype) i64; \
319 case MONO_TYPE_CHAR: \
320 *(etype *) ea = (etype) u64; \
325 switch (vc->byval_arg.type) {
327 u64 = *(guint8 *) va;
330 u64 = *(guint16 *) va;
333 u64 = *(guint32 *) va;
336 u64 = *(guint64 *) va;
342 i64 = *(gint16 *) va;
345 i64 = *(gint32 *) va;
348 i64 = *(gint64 *) va;
351 r64 = *(gfloat *) va;
354 r64 = *(gdouble *) va;
357 u64 = *(guint16 *) va;
359 case MONO_TYPE_BOOLEAN:
360 /* Boolean is only compatible with itself. */
361 switch (ec->byval_arg.type) {
373 NO_WIDENING_CONVERSION;
380 /* If we can't do a direct copy, let's try a widening conversion. */
381 switch (ec->byval_arg.type) {
383 ASSIGN_UNSIGNED (guint16);
385 ASSIGN_UNSIGNED (guint8);
387 ASSIGN_UNSIGNED (guint16);
389 ASSIGN_UNSIGNED (guint32);
391 ASSIGN_UNSIGNED (guint64);
393 ASSIGN_SIGNED (gint8);
395 ASSIGN_SIGNED (gint16);
397 ASSIGN_SIGNED (gint32);
399 ASSIGN_SIGNED (gint64);
401 ASSIGN_REAL (gfloat);
403 ASSIGN_REAL (gdouble);
407 /* Not reached, INVALID_CAST does not return. Just to avoid a compiler warning ... */
411 #undef NO_WIDENING_CONVERSION
412 #undef CHECK_WIDENING_CONVERSION
413 #undef ASSIGN_UNSIGNED
419 ves_icall_System_Array_SetValue (MonoArray *this, MonoObject *value,
427 MONO_CHECK_ARG_NULL (idxs);
429 ic = idxs->obj.vtable->klass;
430 ac = this->obj.vtable->klass;
432 g_assert (ic->rank == 1);
433 if (idxs->bounds != NULL || idxs->max_length != ac->rank)
434 mono_raise_exception (mono_get_exception_argument (NULL, NULL));
436 ind = (guint32 *)idxs->vector;
438 if (this->bounds == NULL) {
439 if (*ind < 0 || *ind >= this->max_length)
440 mono_raise_exception (mono_get_exception_index_out_of_range ());
442 ves_icall_System_Array_SetValueImpl (this, value, *ind);
446 for (i = 0; i < ac->rank; i++)
447 if ((ind [i] < this->bounds [i].lower_bound) ||
448 (ind [i] >= this->bounds [i].length + this->bounds [i].lower_bound))
449 mono_raise_exception (mono_get_exception_index_out_of_range ());
451 pos = ind [0] - this->bounds [0].lower_bound;
452 for (i = 1; i < ac->rank; i++)
453 pos = pos * this->bounds [i].length + ind [i] -
454 this->bounds [i].lower_bound;
456 ves_icall_System_Array_SetValueImpl (this, value, pos);
460 ves_icall_System_Array_CreateInstanceImpl (MonoReflectionType *type, MonoArray *lengths, MonoArray *bounds)
468 MONO_CHECK_ARG_NULL (type);
469 MONO_CHECK_ARG_NULL (lengths);
471 MONO_CHECK_ARG (lengths, mono_array_length (lengths) > 0);
473 MONO_CHECK_ARG (bounds, mono_array_length (lengths) == mono_array_length (bounds));
475 for (i = 0; i < mono_array_length (lengths); i++)
476 if (mono_array_get (lengths, gint32, i) < 0)
477 mono_raise_exception (mono_get_exception_argument_out_of_range (NULL));
479 aklass = mono_array_class_get (mono_class_from_mono_type (type->type), mono_array_length (lengths));
481 sizes = alloca (aklass->rank * sizeof(guint32) * 2);
482 for (i = 0; i < aklass->rank; ++i) {
483 sizes [i] = mono_array_get (lengths, gint32, i);
485 sizes [i + aklass->rank] = mono_array_get (bounds, gint32, i);
487 sizes [i + aklass->rank] = 0;
490 array = mono_array_new_full (mono_object_domain (type), aklass, sizes, sizes + aklass->rank);
496 ves_icall_System_Array_GetRank (MonoObject *this)
500 return this->vtable->klass->rank;
504 ves_icall_System_Array_GetLength (MonoArray *this, gint32 dimension)
506 gint32 rank = ((MonoObject *)this)->vtable->klass->rank;
510 if ((dimension < 0) || (dimension >= rank))
511 mono_raise_exception (mono_get_exception_index_out_of_range ());
513 if (this->bounds == NULL)
514 return this->max_length;
516 return this->bounds [dimension].length;
520 ves_icall_System_Array_GetLowerBound (MonoArray *this, gint32 dimension)
522 gint32 rank = ((MonoObject *)this)->vtable->klass->rank;
526 if ((dimension < 0) || (dimension >= rank))
527 mono_raise_exception (mono_get_exception_index_out_of_range ());
529 if (this->bounds == NULL)
532 return this->bounds [dimension].lower_bound;
536 ves_icall_System_Array_FastCopy (MonoArray *source, int source_idx, MonoArray* dest, int dest_idx, int length)
541 MonoClass *src_class;
542 MonoClass *dest_class;
547 if (source->obj.vtable->klass->rank != dest->obj.vtable->klass->rank)
550 if (source->bounds || dest->bounds)
553 if ((dest_idx + length > mono_array_length (dest)) ||
554 (source_idx + length > mono_array_length (source)))
557 element_size = mono_array_element_size (source->obj.vtable->klass);
558 dest_addr = mono_array_addr_with_size (dest, element_size, dest_idx);
559 source_addr = mono_array_addr_with_size (source, element_size, source_idx);
561 src_class = source->obj.vtable->klass->element_class;
562 dest_class = dest->obj.vtable->klass->element_class;
565 * Handle common cases.
568 /* Case1: object[] -> valuetype[] (ArrayList::ToArray) */
569 if (src_class == mono_defaults.object_class && dest_class->valuetype) {
570 for (i = source_idx; i < source_idx + length; ++i) {
571 MonoObject *elem = mono_array_get (source, MonoObject*, i);
572 if (elem && !mono_object_isinst (elem, dest_class))
576 element_size = mono_array_element_size (dest->obj.vtable->klass);
577 for (i = 0; i < length; ++i) {
578 MonoObject *elem = mono_array_get (source, MonoObject*, source_idx + i);
579 void *addr = mono_array_addr_with_size (dest, element_size, dest_idx + i);
581 memset (addr, 0, element_size);
583 memcpy (addr, (char *)elem + sizeof (MonoObject), element_size);
588 if (src_class != dest_class) {
589 if (dest_class->valuetype || dest_class->enumtype || src_class->valuetype || src_class->enumtype)
592 if (mono_class_is_subclass_of (src_class, dest_class, FALSE))
594 /* Case2: object[] -> reftype[] (ArrayList::ToArray) */
595 else if (mono_class_is_subclass_of (dest_class, src_class, FALSE))
596 for (i = source_idx; i < source_idx + length; ++i) {
597 MonoObject *elem = mono_array_get (source, MonoObject*, i);
598 if (elem && !mono_object_isinst (elem, dest_class))
605 memmove (dest_addr, source_addr, element_size * length);
611 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_InitializeArray (MonoArray *array, MonoClassField *field_handle)
613 MonoClass *klass = array->obj.vtable->klass;
614 guint32 size = mono_array_element_size (klass);
619 if (array->bounds == NULL)
620 size *= array->max_length;
622 for (i = 0; i < klass->rank; ++i)
623 size *= array->bounds [i].length;
625 memcpy (mono_array_addr (array, char, 0), field_handle->data, size);
627 #if G_BYTE_ORDER != G_LITTLE_ENDIAN
631 guint ## n *data = (guint ## n *) mono_array_addr (array, char, 0); \
633 for (i = 0; i < size; i += n/8, data++) { \
634 tmp = read ## n (data); \
639 /* printf ("Initialize array with elements of %s type\n", klass->element_class->name); */
641 switch (klass->element_class->byval_arg.type) {
661 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetOffsetToStringData (void)
665 return offsetof (MonoString, chars);
669 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetObjectValue (MonoObject *obj)
673 if ((obj == NULL) || (! (obj->vtable->klass->valuetype)))
676 return mono_object_clone (obj);
680 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_RunClassConstructor (MonoType *handle)
686 MONO_CHECK_ARG_NULL (handle);
688 klass = mono_class_from_mono_type (handle);
689 MONO_CHECK_ARG (handle, klass);
691 /* This will call the type constructor */
692 if (! (klass->flags & TYPE_ATTRIBUTE_INTERFACE))
693 mono_runtime_class_init (mono_class_vtable (mono_domain_get (), klass));
697 ves_icall_System_Object_MemberwiseClone (MonoObject *this)
701 return mono_object_clone (this);
705 #define MONO_OBJECT_ALIGNMENT_SHIFT 3
707 #define MONO_OBJECT_ALIGNMENT_SHIFT 2
711 * Return hashcode based on object address. This function will need to be
712 * smarter in the presence of a moving garbage collector, which will cache
713 * the address hash before relocating the object.
715 * Wang's address-based hash function:
716 * http://www.concentric.net/~Ttwang/tech/addrhash.htm
719 ves_icall_System_Object_GetHashCode (MonoObject *this)
721 register guint32 key;
725 key = (GPOINTER_TO_UINT (this) >> MONO_OBJECT_ALIGNMENT_SHIFT) * 2654435761u;
727 return key & 0x7fffffff;
731 ves_icall_System_ValueType_InternalGetHashCode (MonoObject *this, MonoArray **fields)
735 MonoObject **values = NULL;
742 klass = this->vtable->klass;
744 if (klass->field.count == 0)
745 return ves_icall_System_Object_GetHashCode (this);
748 * Compute the starting value of the hashcode for fields of primitive
749 * types, and return the remaining fields in an array to the managed side.
750 * This way, we can avoid costly reflection operations in managed code.
752 for (i = 0; i < klass->field.count; ++i) {
753 MonoClassField *field = &klass->fields [i];
754 if (field->type->attrs & FIELD_ATTRIBUTE_STATIC)
756 /* FIXME: Add more types */
757 switch (field->type->type) {
759 result ^= *(gint32*)((guint8*)this + field->offset);
761 case MONO_TYPE_STRING: {
763 s = *(MonoString**)((guint8*)this + field->offset);
765 result ^= ves_icall_System_String_GetHashCode (s);
770 values = alloca (klass->field.count * sizeof (MonoObject*));
771 o = mono_field_get_value_object (mono_object_domain (this), field, this);
772 values [count++] = o;
777 *fields = mono_array_new (mono_domain_get (), mono_defaults.object_class, count);
778 memcpy (mono_array_addr (*fields, MonoObject*, 0), values, count * sizeof (MonoObject*));
786 ves_icall_System_ValueType_Equals (MonoObject *this, MonoObject *that, MonoArray **fields)
790 MonoObject **values = NULL;
796 MONO_CHECK_ARG_NULL (that);
798 if (this->vtable != that->vtable)
801 klass = this->vtable->klass;
804 * Do the comparison for fields of primitive type and return a result if
805 * possible. Otherwise, return the remaining fields in an array to the
806 * managed side. This way, we can avoid costly reflection operations in
810 for (i = 0; i < klass->field.count; ++i) {
811 MonoClassField *field = &klass->fields [i];
812 if (field->type->attrs & FIELD_ATTRIBUTE_STATIC)
814 /* FIXME: Add more types */
815 switch (field->type->type) {
817 if (*(gint32*)((guint8*)this + field->offset) != *(gint32*)((guint8*)that + field->offset))
820 case MONO_TYPE_STRING: {
822 guint32 s1len, s2len;
823 s1 = *(MonoString**)((guint8*)this + field->offset);
824 s2 = *(MonoString**)((guint8*)that + field->offset);
827 if ((s1 == NULL) || (s2 == NULL))
829 s1len = mono_string_length (s1);
830 s2len = mono_string_length (s2);
834 if (memcmp (mono_string_chars (s1), mono_string_chars (s2), s1len * sizeof (gunichar2)) != 0)
840 values = alloca (klass->field.count * 2 * sizeof (MonoObject*));
841 o = mono_field_get_value_object (mono_object_domain (this), field, this);
842 values [count++] = o;
843 o = mono_field_get_value_object (mono_object_domain (this), field, that);
844 values [count++] = o;
849 *fields = mono_array_new (mono_domain_get (), mono_defaults.object_class, count);
850 memcpy (mono_array_addr (*fields, MonoObject*, 0), values, count * sizeof (MonoObject*));
858 static MonoReflectionType *
859 ves_icall_System_Object_GetType (MonoObject *obj)
863 return mono_type_get_object (mono_object_domain (obj), &obj->vtable->klass->byval_arg);
867 mono_type_type_from_obj (MonoReflectionType *mtype, MonoObject *obj)
871 mtype->type = &obj->vtable->klass->byval_arg;
872 g_assert (mtype->type->type);
876 ves_icall_ModuleBuilder_getToken (MonoReflectionModuleBuilder *mb, MonoObject *obj)
880 return mono_image_create_token (mb->dynamic_image, obj);
884 ves_icall_ModuleBuilder_getDataChunk (MonoReflectionModuleBuilder *mb, MonoArray *buf, gint32 offset)
887 MonoDynamicImage *image = mb->dynamic_image;
888 char *p = mono_array_addr (buf, char, 0);
892 mono_image_create_pefile (mb);
894 if (offset >= image->pefile.index)
896 count = mono_array_length (buf);
897 count = MIN (count, image->pefile.index - offset);
899 memcpy (p, image->pefile.data + offset, count);
905 ves_icall_ModuleBuilder_build_metadata (MonoReflectionModuleBuilder *mb)
909 mono_image_build_metadata (mb);
912 static MonoReflectionType*
913 ves_icall_type_from_name (MonoString *name,
914 MonoBoolean throwOnError,
915 MonoBoolean ignoreCase)
918 MonoType *type = NULL;
919 MonoAssembly *assembly;
920 MonoTypeNameParse info;
924 str = mono_string_to_utf8 (name);
925 if (!mono_reflection_parse_type (str, &info)) {
927 g_list_free (info.modifiers);
928 g_list_free (info.nested);
929 if (throwOnError) /* uhm: this is a parse error, though... */
930 mono_raise_exception (mono_get_exception_type_load (name));
935 if (info.assembly.name) {
936 assembly = mono_assembly_load (&info.assembly, NULL, NULL);
938 MonoReflectionAssembly *refass;
940 refass = ves_icall_System_Reflection_Assembly_GetCallingAssembly ();
941 assembly = refass->assembly;
945 type = mono_reflection_get_type (assembly->image, &info, ignoreCase);
947 if (!info.assembly.name && !type) /* try mscorlib */
948 type = mono_reflection_get_type (NULL, &info, ignoreCase);
951 g_list_free (info.modifiers);
952 g_list_free (info.nested);
955 mono_raise_exception (mono_get_exception_type_load (name));
960 return mono_type_get_object (mono_domain_get (), type);
963 static MonoReflectionType*
964 ves_icall_type_from_handle (MonoType *handle)
966 MonoDomain *domain = mono_domain_get ();
967 MonoClass *klass = mono_class_from_mono_type (handle);
971 mono_class_init (klass);
972 return mono_type_get_object (domain, handle);
976 ves_icall_type_Equals (MonoReflectionType *type, MonoReflectionType *c)
980 if (type->type && c->type)
981 return mono_metadata_type_equal (type->type, c->type);
982 g_print ("type equals\n");
986 /* System.TypeCode */
1005 TYPECODE_STRING = 18
1009 ves_icall_type_GetTypeCode (MonoReflectionType *type)
1011 int t = type->type->type;
1013 MONO_ARCH_SAVE_REGS;
1017 case MONO_TYPE_VOID:
1018 return TYPECODE_OBJECT;
1019 case MONO_TYPE_BOOLEAN:
1020 return TYPECODE_BOOLEAN;
1022 return TYPECODE_BYTE;
1024 return TYPECODE_SBYTE;
1026 return TYPECODE_UINT16;
1028 return TYPECODE_INT16;
1029 case MONO_TYPE_CHAR:
1030 return TYPECODE_CHAR;
1034 return TYPECODE_OBJECT;
1036 return TYPECODE_UINT32;
1038 return TYPECODE_INT32;
1040 return TYPECODE_UINT64;
1042 return TYPECODE_INT64;
1044 return TYPECODE_SINGLE;
1046 return TYPECODE_DOUBLE;
1047 case MONO_TYPE_VALUETYPE:
1048 if (type->type->data.klass->enumtype) {
1049 t = type->type->data.klass->enum_basetype->type;
1052 MonoClass *k = type->type->data.klass;
1053 if (strcmp (k->name_space, "System") == 0) {
1054 if (strcmp (k->name, "Decimal") == 0)
1055 return TYPECODE_DECIMAL;
1056 else if (strcmp (k->name, "DateTime") == 0)
1057 return TYPECODE_DATETIME;
1060 return TYPECODE_OBJECT;
1061 case MONO_TYPE_STRING:
1062 return TYPECODE_STRING;
1063 case MONO_TYPE_SZARRAY:
1064 case MONO_TYPE_ARRAY:
1065 case MONO_TYPE_OBJECT:
1066 return TYPECODE_OBJECT;
1067 case MONO_TYPE_CLASS:
1069 MonoClass *k = type->type->data.klass;
1070 if (strcmp (k->name_space, "System") == 0) {
1071 if (strcmp (k->name, "DBNull") == 0)
1072 return TYPECODE_DBNULL;
1075 return TYPECODE_OBJECT;
1077 g_error ("type 0x%02x not handled in GetTypeCode()", t);
1083 ves_icall_type_is_subtype_of (MonoReflectionType *type, MonoReflectionType *c, MonoBoolean check_interfaces)
1089 MONO_ARCH_SAVE_REGS;
1091 g_assert (type != NULL);
1093 domain = ((MonoObject *)type)->vtable->domain;
1095 if (!c) /* FIXME: dont know what do do here */
1098 klass = mono_class_from_mono_type (type->type);
1099 klassc = mono_class_from_mono_type (c->type);
1101 return mono_class_is_subclass_of (klass, klassc, check_interfaces);
1105 ves_icall_type_is_assignable_from (MonoReflectionType *type, MonoReflectionType *c)
1111 MONO_ARCH_SAVE_REGS;
1113 g_assert (type != NULL);
1115 domain = ((MonoObject *)type)->vtable->domain;
1117 klass = mono_class_from_mono_type (type->type);
1118 klassc = mono_class_from_mono_type (c->type);
1120 return mono_class_is_assignable_from (klass, klassc);
1124 ves_icall_get_attributes (MonoReflectionType *type)
1126 MonoClass *klass = mono_class_from_mono_type (type->type);
1128 MONO_ARCH_SAVE_REGS;
1130 return klass->flags;
1133 static MonoReflectionField*
1134 ves_icall_System_Reflection_FieldInfo_internal_from_handle (MonoClassField *handle)
1136 MONO_ARCH_SAVE_REGS;
1140 return mono_field_get_object (mono_domain_get (), handle->parent, handle);
1144 ves_icall_get_method_info (MonoMethod *method, MonoMethodInfo *info)
1146 MonoDomain *domain = mono_domain_get ();
1148 MONO_ARCH_SAVE_REGS;
1150 info->parent = mono_type_get_object (domain, &method->klass->byval_arg);
1151 info->ret = mono_type_get_object (domain, method->signature->ret);
1152 info->attrs = method->flags;
1153 info->implattrs = method->iflags;
1154 if (method->signature->call_convention == MONO_CALL_DEFAULT)
1157 if (method->signature->call_convention == MONO_CALL_VARARG)
1161 info->callconv |= (method->signature->hasthis << 5) | (method->signature->explicit_this << 6);
1165 ves_icall_get_parameter_info (MonoMethod *method)
1167 MonoDomain *domain = mono_domain_get ();
1169 MONO_ARCH_SAVE_REGS;
1171 return mono_param_get_objects (domain, method);
1174 static MonoReflectionType*
1175 ves_icall_MonoField_GetParentType (MonoReflectionField *field, MonoBoolean declaring)
1178 MONO_ARCH_SAVE_REGS;
1180 parent = declaring? field->field->parent: field->klass;
1182 return mono_type_get_object (mono_object_domain (field), &parent->byval_arg);
1186 ves_icall_MonoField_GetValueInternal (MonoReflectionField *field, MonoObject *obj)
1189 MonoClassField *cf = field->field;
1192 MonoDomain *domain = mono_object_domain (field);
1194 gboolean is_static = FALSE;
1195 gboolean is_ref = FALSE;
1197 MONO_ARCH_SAVE_REGS;
1199 mono_class_init (field->klass);
1201 switch (cf->type->type) {
1202 case MONO_TYPE_STRING:
1203 case MONO_TYPE_OBJECT:
1204 case MONO_TYPE_CLASS:
1205 case MONO_TYPE_ARRAY:
1206 case MONO_TYPE_SZARRAY:
1211 case MONO_TYPE_BOOLEAN:
1214 case MONO_TYPE_CHAR:
1223 case MONO_TYPE_VALUETYPE:
1224 is_ref = cf->type->byref;
1227 g_error ("type 0x%x not handled in "
1228 "ves_icall_Monofield_GetValue", cf->type->type);
1232 if (cf->type->attrs & FIELD_ATTRIBUTE_STATIC) {
1234 vtable = mono_class_vtable (domain, field->klass);
1235 if (!vtable->initialized)
1236 mono_runtime_class_init (vtable);
1241 mono_field_static_get_value (vtable, cf, &o);
1243 mono_field_get_value (obj, cf, &o);
1248 /* boxed value type */
1249 klass = mono_class_from_mono_type (cf->type);
1250 o = mono_object_new (domain, klass);
1251 v = ((gchar *) o) + sizeof (MonoObject);
1253 mono_field_static_get_value (vtable, cf, v);
1255 mono_field_get_value (obj, cf, v);
1262 ves_icall_FieldInfo_SetValueInternal (MonoReflectionField *field, MonoObject *obj, MonoObject *value)
1264 MonoClassField *cf = field->field;
1267 MONO_ARCH_SAVE_REGS;
1269 v = (gchar *) value;
1270 if (!cf->type->byref) {
1271 switch (cf->type->type) {
1274 case MONO_TYPE_BOOLEAN:
1277 case MONO_TYPE_CHAR:
1286 case MONO_TYPE_VALUETYPE:
1287 v += sizeof (MonoObject);
1289 case MONO_TYPE_STRING:
1290 case MONO_TYPE_OBJECT:
1291 case MONO_TYPE_CLASS:
1292 case MONO_TYPE_ARRAY:
1293 case MONO_TYPE_SZARRAY:
1297 g_error ("type 0x%x not handled in "
1298 "ves_icall_FieldInfo_SetValueInternal", cf->type->type);
1303 if (cf->type->attrs & FIELD_ATTRIBUTE_STATIC) {
1304 MonoVTable *vtable = mono_class_vtable (mono_object_domain (field), field->klass);
1305 if (!vtable->initialized)
1306 mono_runtime_class_init (vtable);
1307 mono_field_static_set_value (vtable, cf, v);
1309 mono_field_set_value (obj, cf, v);
1314 ves_icall_get_property_info (MonoReflectionProperty *property, MonoPropertyInfo *info)
1316 MonoDomain *domain = mono_object_domain (property);
1318 MONO_ARCH_SAVE_REGS;
1320 info->parent = mono_type_get_object (domain, &property->klass->byval_arg);
1321 info->name = mono_string_new (domain, property->property->name);
1322 info->attrs = property->property->attrs;
1323 info->get = property->property->get ? mono_method_get_object (domain, property->property->get, NULL): NULL;
1324 info->set = property->property->set ? mono_method_get_object (domain, property->property->set, NULL): NULL;
1326 * There may be other methods defined for properties, though, it seems they are not exposed
1327 * in the reflection API
1332 ves_icall_get_event_info (MonoReflectionEvent *event, MonoEventInfo *info)
1334 MonoDomain *domain = mono_object_domain (event);
1336 MONO_ARCH_SAVE_REGS;
1338 info->parent = mono_type_get_object (domain, &event->klass->byval_arg);
1339 info->name = mono_string_new (domain, event->event->name);
1340 info->attrs = event->event->attrs;
1341 info->add_method = event->event->add ? mono_method_get_object (domain, event->event->add, NULL): NULL;
1342 info->remove_method = event->event->remove ? mono_method_get_object (domain, event->event->remove, NULL): NULL;
1343 info->raise_method = event->event->raise ? mono_method_get_object (domain, event->event->raise, NULL): NULL;
1347 ves_icall_Type_GetInterfaces (MonoReflectionType* type)
1349 MonoDomain *domain = mono_object_domain (type);
1352 MonoClass *class = mono_class_from_mono_type (type->type);
1354 MonoBitSet *slots = mono_bitset_new (class->max_interface_id + 1, 0);
1356 MONO_ARCH_SAVE_REGS;
1359 /* GetInterfaces() returns an empty array in MS.NET (this may be a bug) */
1360 return mono_array_new (domain, mono_defaults.monotype_class, 0);
1364 for (parent = class; parent; parent = parent->parent) {
1365 for (i = 0; i < parent->interface_count; ++i) {
1366 if (mono_bitset_test (slots, parent->interfaces [i]->interface_id))
1369 mono_bitset_set (slots, parent->interfaces [i]->interface_id);
1374 intf = mono_array_new (domain, mono_defaults.monotype_class, ninterf);
1376 for (parent = class; parent; parent = parent->parent) {
1377 for (i = 0; i < parent->interface_count; ++i) {
1378 if (!mono_bitset_test (slots, parent->interfaces [i]->interface_id))
1381 mono_bitset_clear (slots, parent->interfaces [i]->interface_id);
1382 mono_array_set (intf, gpointer, ninterf,
1383 mono_type_get_object (domain, &parent->interfaces [i]->byval_arg));
1388 mono_bitset_free (slots);
1393 ves_icall_Type_GetInterfaceMapData (MonoReflectionType *type, MonoReflectionType *iface, MonoArray **targets, MonoArray **methods)
1395 MonoClass *class = mono_class_from_mono_type (type->type);
1396 MonoClass *iclass = mono_class_from_mono_type (iface->type);
1397 MonoReflectionMethod *member;
1398 int i, len, ioffset;
1401 MONO_ARCH_SAVE_REGS;
1403 /* type doesn't implement iface: the exception is thrown in managed code */
1404 if ((iclass->interface_id > class->max_interface_id) || !class->interface_offsets [iclass->interface_id])
1407 len = iclass->method.count;
1408 ioffset = class->interface_offsets [iclass->interface_id];
1409 domain = mono_object_domain (type);
1410 *targets = mono_array_new (domain, mono_defaults.method_info_class, len);
1411 *methods = mono_array_new (domain, mono_defaults.method_info_class, len);
1412 for (i = 0; i < len; ++i) {
1413 member = mono_method_get_object (domain, iclass->methods [i], iclass);
1414 mono_array_set (*methods, gpointer, i, member);
1415 member = mono_method_get_object (domain, class->vtable [i + ioffset], class);
1416 mono_array_set (*targets, gpointer, i, member);
1420 static MonoReflectionType*
1421 ves_icall_MonoType_GetElementType (MonoReflectionType *type)
1423 MonoClass *class = mono_class_from_mono_type (type->type);
1425 MONO_ARCH_SAVE_REGS;
1427 if (type->type->byref)
1428 return mono_type_get_object (mono_object_domain (type), &class->byval_arg);
1429 if (class->enumtype && class->enum_basetype) /* types that are modifierd typebuilkders may not have enum_basetype set */
1430 return mono_type_get_object (mono_object_domain (type), class->enum_basetype);
1431 else if (class->element_class)
1432 return mono_type_get_object (mono_object_domain (type), &class->element_class->byval_arg);
1437 static MonoReflectionType*
1438 ves_icall_get_type_parent (MonoReflectionType *type)
1440 MonoClass *class = mono_class_from_mono_type (type->type);
1442 MONO_ARCH_SAVE_REGS;
1444 return class->parent ? mono_type_get_object (mono_object_domain (type), &class->parent->byval_arg): NULL;
1448 ves_icall_type_ispointer (MonoReflectionType *type)
1450 MONO_ARCH_SAVE_REGS;
1452 return type->type->type == MONO_TYPE_PTR;
1456 ves_icall_type_isprimitive (MonoReflectionType *type)
1458 MONO_ARCH_SAVE_REGS;
1460 return (!type->type->byref && (type->type->type >= MONO_TYPE_BOOLEAN) && (type->type->type <= MONO_TYPE_R8));
1464 ves_icall_type_isbyref (MonoReflectionType *type)
1466 MONO_ARCH_SAVE_REGS;
1468 return type->type->byref;
1471 static MonoReflectionModule*
1472 ves_icall_MonoType_get_Module (MonoReflectionType *type)
1474 MonoClass *class = mono_class_from_mono_type (type->type);
1476 MONO_ARCH_SAVE_REGS;
1478 return mono_module_get_object (mono_object_domain (type), class->image);
1482 ves_icall_get_type_info (MonoType *type, MonoTypeInfo *info)
1484 MonoDomain *domain = mono_domain_get ();
1485 MonoClass *class = mono_class_from_mono_type (type);
1487 MONO_ARCH_SAVE_REGS;
1489 info->nested_in = class->nested_in ? mono_type_get_object (domain, &class->nested_in->byval_arg): NULL;
1490 info->name = mono_string_new (domain, class->name);
1491 info->name_space = mono_string_new (domain, class->name_space);
1492 info->rank = class->rank;
1493 info->assembly = mono_assembly_get_object (domain, class->image->assembly);
1494 if (class->enumtype && class->enum_basetype) /* types that are modifierd typebuilkders may not have enum_basetype set */
1495 info->etype = mono_type_get_object (domain, class->enum_basetype);
1496 else if (class->element_class)
1497 info->etype = mono_type_get_object (domain, &class->element_class->byval_arg);
1501 info->isprimitive = (!type->byref && (type->type >= MONO_TYPE_BOOLEAN) && (type->type <= MONO_TYPE_R8));
1505 ves_icall_Type_GetGenericArguments (MonoReflectionType *type)
1508 MonoClass *klass, *pklass;
1510 MONO_ARCH_SAVE_REGS;
1512 klass = mono_class_from_mono_type (type->type);
1514 if (type->type->byref) {
1515 res = mono_array_new (mono_object_domain (type), mono_defaults.monotype_class, 0);
1516 } else if (klass->gen_params) {
1517 res = mono_array_new (mono_object_domain (type), mono_defaults.monotype_class, klass->num_gen_params);
1518 for (i = 0; i < klass->num_gen_params; ++i) {
1519 pklass = mono_class_from_generic_parameter (&klass->gen_params [i], klass->image, FALSE);
1520 mono_array_set (res, gpointer, i, mono_type_get_object (mono_object_domain (type), &pklass->byval_arg));
1522 } else if (klass->generic_inst) {
1523 MonoGenericInst *inst = klass->generic_inst->data.generic_inst;
1524 res = mono_array_new (mono_object_domain (type), mono_defaults.monotype_class, inst->type_argc);
1525 for (i = 0; i < inst->type_argc; ++i) {
1526 mono_array_set (res, gpointer, i, mono_type_get_object (mono_object_domain (type), inst->type_argv [i]));
1529 res = mono_array_new (mono_object_domain (type), mono_defaults.monotype_class, 0);
1535 ves_icall_Type_get_IsGenericTypeDefinition (MonoReflectionType *type)
1538 MONO_ARCH_SAVE_REGS;
1540 if (type->type->byref)
1542 klass = mono_class_from_mono_type (type->type);
1544 return klass->gen_params != NULL;
1547 static MonoReflectionType*
1548 ves_icall_Type_GetGenericTypeDefinition_impl (MonoReflectionType *type)
1551 MONO_ARCH_SAVE_REGS;
1553 if (type->type->byref)
1555 klass = mono_class_from_mono_type (type->type);
1556 if (klass->gen_params) {
1557 return type; /* check this one */
1559 if (klass->generic_inst) {
1560 MonoType *generic_type = klass->generic_inst->data.generic_inst->generic_type;
1561 MonoClass *generic_class = mono_class_from_mono_type (generic_type);
1563 if (generic_class->wastypebuilder && generic_class->reflection_info)
1564 return generic_class->reflection_info;
1566 return mono_type_get_object (mono_object_domain (type), generic_type);
1571 static MonoReflectionGenericInst*
1572 ves_icall_Type_BindGenericParameters (MonoReflectionType *type, MonoArray *types)
1574 MONO_ARCH_SAVE_REGS;
1576 if (type->type->byref)
1579 return mono_reflection_bind_generic_parameters (type, types);
1583 ves_icall_Type_get_IsGenericInstance (MonoReflectionType *type)
1586 MONO_ARCH_SAVE_REGS;
1588 if (type->type->byref)
1590 klass = mono_class_from_mono_type (type->type);
1591 return klass->generic_inst != NULL;
1595 ves_icall_Type_GetGenericParameterPosition (MonoReflectionType *type)
1597 MONO_ARCH_SAVE_REGS;
1599 if (type->type->byref)
1601 if (type->type->type == MONO_TYPE_VAR || type->type->type == MONO_TYPE_MVAR)
1602 return type->type->data.generic_param->num;
1607 ves_icall_MonoType_get_HasGenericArguments (MonoReflectionType *type)
1610 MONO_ARCH_SAVE_REGS;
1612 if (type->type->byref)
1614 klass = mono_class_from_mono_type (type->type);
1615 if (klass->gen_params || klass->generic_inst)
1621 ves_icall_MonoType_get_IsGenericParameter (MonoReflectionType *type)
1623 MONO_ARCH_SAVE_REGS;
1625 if (type->type->byref)
1627 if (type->type->type == MONO_TYPE_VAR || type->type->type == MONO_TYPE_MVAR)
1633 ves_icall_TypeBuilder_get_IsGenericParameter (MonoReflectionTypeBuilder *tb)
1635 MONO_ARCH_SAVE_REGS;
1637 if (tb->type.type->byref)
1639 if (tb->type.type->type == MONO_TYPE_VAR || tb->type.type->type == MONO_TYPE_MVAR)
1644 static MonoReflectionType*
1645 ves_icall_TypeBuilder_define_generic_parameter (MonoReflectionTypeBuilder *tb, MonoReflectionGenericParam *gparam)
1649 MONO_ARCH_SAVE_REGS;
1651 index = mono_array_length (tb->generic_params) - 1;
1652 return mono_reflection_define_generic_parameter (tb, NULL, index, gparam);
1655 static MonoReflectionType*
1656 ves_icall_MethodBuilder_define_generic_parameter (MonoReflectionMethodBuilder *mb, MonoReflectionGenericParam *gparam)
1660 MONO_ARCH_SAVE_REGS;
1662 index = mono_array_length (mb->generic_params) - 1;
1663 return mono_reflection_define_generic_parameter (NULL, mb, index, gparam);
1666 static MonoReflectionMethod *
1667 ves_icall_MonoType_get_DeclaringMethod (MonoReflectionType *type)
1672 MONO_ARCH_SAVE_REGS;
1674 if (type->type->byref)
1677 method = type->type->data.generic_param->method;
1681 klass = mono_class_from_mono_type (type->type);
1682 return mono_method_get_object (mono_object_domain (type), method, klass);
1686 ves_icall_MethodInfo_get_IsGenericMethodDefinition (MonoReflectionMethod *method)
1688 MonoMethodNormal *mn;
1689 MONO_ARCH_SAVE_REGS;
1691 if ((method->method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) ||
1692 (method->method->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL))
1695 mn = (MonoMethodNormal *) method->method;
1696 return mn->header->gen_params != NULL;
1700 ves_icall_MonoMethod_GetGenericArguments (MonoReflectionMethod *method)
1702 MonoMethodNormal *mn;
1705 MONO_ARCH_SAVE_REGS;
1707 if ((method->method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) ||
1708 (method->method->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL))
1709 return mono_array_new (mono_object_domain (method), mono_defaults.monotype_class, 0);
1711 mn = (MonoMethodNormal *) method->method;
1712 count = method->method->signature->generic_param_count;
1713 res = mono_array_new (mono_object_domain (method), mono_defaults.monotype_class, count);
1715 for (i = 0; i < count; i++) {
1716 MonoGenericParam *param = &mn->header->gen_params [i];
1717 MonoClass *pklass = mono_class_from_generic_parameter (param, method->method->klass->image, TRUE);
1718 mono_array_set (res, gpointer, i, mono_type_get_object (mono_object_domain (method), &pklass->byval_arg));
1725 ves_icall_InternalInvoke (MonoReflectionMethod *method, MonoObject *this, MonoArray *params)
1728 * Invoke from reflection is supposed to always be a virtual call (the API
1729 * is stupid), mono_runtime_invoke_*() calls the provided method, allowing
1730 * greater flexibility.
1732 MonoMethod *m = method->method;
1735 MONO_ARCH_SAVE_REGS;
1738 if (!mono_object_isinst (this, m->klass))
1739 mono_raise_exception (mono_exception_from_name (mono_defaults.corlib, "System.Reflection", "TargetException"));
1740 m = mono_object_get_virtual_method (this, m);
1741 } else if (!(m->flags & METHOD_ATTRIBUTE_STATIC) && strcmp (m->name, ".ctor") && !m->wrapper_type)
1742 mono_raise_exception (mono_exception_from_name (mono_defaults.corlib, "System.Reflection", "TargetException"));
1744 pcount = params? mono_array_length (params): 0;
1745 if (pcount != m->signature->param_count)
1746 mono_raise_exception (mono_exception_from_name (mono_defaults.corlib, "System.Reflection", "TargetParameterCountException"));
1748 if (m->klass->rank && !strcmp (m->name, ".ctor")) {
1751 guint32 *lower_bounds;
1752 pcount = mono_array_length (params);
1753 lengths = alloca (sizeof (guint32) * pcount);
1754 for (i = 0; i < pcount; ++i)
1755 lengths [i] = *(gint32*) ((char*)mono_array_get (params, gpointer, i) + sizeof (MonoObject));
1757 if (m->klass->rank == pcount) {
1758 /* Only lengths provided. */
1759 lower_bounds = NULL;
1761 g_assert (pcount == (m->klass->rank * 2));
1762 /* lower bounds are first. */
1763 lower_bounds = lengths;
1764 lengths += m->klass->rank;
1767 return (MonoObject*)mono_array_new_full (mono_object_domain (params), m->klass, lengths, lower_bounds);
1769 return mono_runtime_invoke_array (m, this, params, NULL);
1773 ves_icall_InternalExecute (MonoReflectionMethod *method, MonoObject *this, MonoArray *params, MonoArray **outArgs)
1775 MonoDomain *domain = mono_object_domain (method);
1776 MonoMethod *m = method->method;
1777 MonoMethodSignature *sig = m->signature;
1778 MonoArray *out_args;
1780 int i, j, outarg_count = 0;
1782 MONO_ARCH_SAVE_REGS;
1784 if (m->klass == mono_defaults.object_class) {
1786 if (!strcmp (m->name, "FieldGetter")) {
1787 MonoClass *k = this->vtable->klass;
1788 MonoString *name = mono_array_get (params, MonoString *, 1);
1791 str = mono_string_to_utf8 (name);
1793 for (i = 0; i < k->field.count; i++) {
1794 if (!strcmp (k->fields [i].name, str)) {
1795 MonoClass *field_klass = mono_class_from_mono_type (k->fields [i].type);
1796 if (field_klass->valuetype)
1797 result = mono_value_box (domain, field_klass,
1798 (char *)this + k->fields [i].offset);
1800 result = *((gpointer *)((char *)this + k->fields [i].offset));
1803 out_args = mono_array_new (domain, mono_defaults.object_class, 1);
1804 *outArgs = out_args;
1805 mono_array_set (out_args, gpointer, 0, result);
1812 g_assert_not_reached ();
1814 } else if (!strcmp (m->name, "FieldSetter")) {
1815 MonoClass *k = this->vtable->klass;
1816 MonoString *name = mono_array_get (params, MonoString *, 1);
1820 str = mono_string_to_utf8 (name);
1822 for (i = 0; i < k->field.count; i++) {
1823 if (!strcmp (k->fields [i].name, str)) {
1824 MonoClass *field_klass = mono_class_from_mono_type (k->fields [i].type);
1825 MonoObject *val = mono_array_get (params, gpointer, 2);
1827 if (field_klass->valuetype) {
1828 size = mono_type_size (k->fields [i].type, &align);
1829 memcpy ((char *)this + k->fields [i].offset,
1830 ((char *)val) + sizeof (MonoObject), size);
1832 *(MonoObject**)((char *)this + k->fields [i].offset) = val;
1834 out_args = mono_array_new (domain, mono_defaults.object_class, 0);
1835 *outArgs = out_args;
1843 g_assert_not_reached ();
1848 for (i = 0; i < mono_array_length (params); i++) {
1849 if (sig->params [i]->byref)
1853 out_args = mono_array_new (domain, mono_defaults.object_class, outarg_count);
1855 /* fixme: handle constructors? */
1856 if (!strcmp (method->method->name, ".ctor"))
1857 g_assert_not_reached ();
1859 result = mono_runtime_invoke_array (method->method, this, params, NULL);
1861 for (i = 0, j = 0; i < mono_array_length (params); i++) {
1862 if (sig->params [i]->byref) {
1864 arg = mono_array_get (params, gpointer, i);
1865 mono_array_set (out_args, gpointer, j, arg);
1870 *outArgs = out_args;
1876 ves_icall_System_Enum_ToObject (MonoReflectionType *type, MonoObject *obj)
1879 MonoClass *enumc, *objc;
1883 MONO_ARCH_SAVE_REGS;
1885 MONO_CHECK_ARG_NULL (type);
1886 MONO_CHECK_ARG_NULL (obj);
1888 domain = mono_object_domain (type);
1889 enumc = mono_class_from_mono_type (type->type);
1890 objc = obj->vtable->klass;
1892 MONO_CHECK_ARG (obj, enumc->enumtype == TRUE);
1893 MONO_CHECK_ARG (obj, (objc->enumtype) || (objc->byval_arg.type >= MONO_TYPE_I1 &&
1894 objc->byval_arg.type <= MONO_TYPE_U8));
1896 s1 = mono_class_value_size (enumc, NULL);
1897 s2 = mono_class_value_size (objc, NULL);
1899 res = mono_object_new (domain, enumc);
1901 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
1902 memcpy ((char *)res + sizeof (MonoObject), (char *)obj + sizeof (MonoObject), MIN (s1, s2));
1904 memcpy ((char *)res + sizeof (MonoObject) + (s1 > s2 ? s1 - s2 : 0),
1905 (char *)obj + sizeof (MonoObject) + (s2 > s1 ? s2 - s1 : 0),
1912 ves_icall_System_Enum_get_value (MonoObject *this)
1920 MONO_ARCH_SAVE_REGS;
1925 g_assert (this->vtable->klass->enumtype);
1927 enumc = mono_class_from_mono_type (this->vtable->klass->enum_basetype);
1928 res = mono_object_new (mono_object_domain (this), enumc);
1929 dst = (char *)res + sizeof (MonoObject);
1930 src = (char *)this + sizeof (MonoObject);
1931 size = mono_class_value_size (enumc, NULL);
1933 memcpy (dst, src, size);
1939 ves_icall_get_enum_info (MonoReflectionType *type, MonoEnumInfo *info)
1941 MonoDomain *domain = mono_object_domain (type);
1942 MonoClass *enumc = mono_class_from_mono_type (type->type);
1943 guint i, j, nvalues, crow;
1944 MonoClassField *field;
1946 MONO_ARCH_SAVE_REGS;
1948 info->utype = mono_type_get_object (domain, enumc->enum_basetype);
1949 nvalues = enumc->field.count - 1;
1950 info->names = mono_array_new (domain, mono_defaults.string_class, nvalues);
1951 info->values = mono_array_new (domain, enumc, nvalues);
1953 for (i = 0, j = 0; i < enumc->field.count; ++i) {
1954 field = &enumc->fields [i];
1955 if (strcmp ("value__", field->name) == 0)
1957 mono_array_set (info->names, gpointer, j, mono_string_new (domain, field->name));
1959 crow = mono_metadata_get_constant_index (enumc->image, MONO_TOKEN_FIELD_DEF | (i+enumc->field.first+1));
1960 crow = mono_metadata_decode_row_col (&enumc->image->tables [MONO_TABLE_CONSTANT], crow-1, MONO_CONSTANT_VALUE);
1961 /* 1 is the length of the blob */
1962 field->data = 1 + mono_metadata_blob_heap (enumc->image, crow);
1964 switch (enumc->enum_basetype->type) {
1967 mono_array_set (info->values, gchar, j, *field->data);
1969 case MONO_TYPE_CHAR:
1972 mono_array_set (info->values, gint16, j, read16 (field->data));
1976 mono_array_set (info->values, gint32, j, read32 (field->data));
1980 mono_array_set (info->values, gint64, j, read64 (field->data));
1983 g_error ("Implement type 0x%02x in get_enum_info", enumc->enum_basetype->type);
1990 BFLAGS_IgnoreCase = 1,
1991 BFLAGS_DeclaredOnly = 2,
1992 BFLAGS_Instance = 4,
1994 BFLAGS_Public = 0x10,
1995 BFLAGS_NonPublic = 0x20,
1996 BFLAGS_InvokeMethod = 0x100,
1997 BFLAGS_CreateInstance = 0x200,
1998 BFLAGS_GetField = 0x400,
1999 BFLAGS_SetField = 0x800,
2000 BFLAGS_GetProperty = 0x1000,
2001 BFLAGS_SetProperty = 0x2000,
2002 BFLAGS_ExactBinding = 0x10000,
2003 BFLAGS_SuppressChangeType = 0x20000,
2004 BFLAGS_OptionalParamBinding = 0x40000
2007 static MonoReflectionField *
2008 ves_icall_Type_GetField (MonoReflectionType *type, MonoString *name, guint32 bflags)
2011 MonoClass *startklass, *klass;
2013 MonoClassField *field;
2015 domain = ((MonoObject *)type)->vtable->domain;
2016 klass = startklass = mono_class_from_mono_type (type->type);
2018 MONO_ARCH_SAVE_REGS;
2021 mono_raise_exception (mono_get_exception_argument_null ("name"));
2024 for (i = 0; i < klass->field.count; ++i) {
2026 field = &klass->fields [i];
2027 if ((field->type->attrs & FIELD_ATTRIBUTE_FIELD_ACCESS_MASK) == FIELD_ATTRIBUTE_PUBLIC) {
2028 if (bflags & BFLAGS_Public)
2031 if (bflags & BFLAGS_NonPublic)
2037 if (field->type->attrs & FIELD_ATTRIBUTE_STATIC) {
2038 if (bflags & BFLAGS_Static)
2041 if (bflags & BFLAGS_Instance)
2048 utf8_name = mono_string_to_utf8 (name);
2050 if (strcmp (field->name, utf8_name)) {
2056 return mono_field_get_object (domain, klass, field);
2058 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
2065 ves_icall_Type_GetFields (MonoReflectionType *type, guint32 bflags)
2068 GSList *l = NULL, *tmp;
2069 MonoClass *startklass, *klass;
2073 MonoClassField *field;
2075 MONO_ARCH_SAVE_REGS;
2077 domain = ((MonoObject *)type)->vtable->domain;
2078 klass = startklass = mono_class_from_mono_type (type->type);
2081 for (i = 0; i < klass->field.count; ++i) {
2083 field = &klass->fields [i];
2084 if ((field->type->attrs & FIELD_ATTRIBUTE_FIELD_ACCESS_MASK) == FIELD_ATTRIBUTE_PUBLIC) {
2085 if (bflags & BFLAGS_Public)
2088 if (bflags & BFLAGS_NonPublic)
2094 if (field->type->attrs & FIELD_ATTRIBUTE_STATIC) {
2095 if (bflags & BFLAGS_Static)
2098 if (bflags & BFLAGS_Instance)
2104 member = (MonoObject*)mono_field_get_object (domain, klass, field);
2105 l = g_slist_prepend (l, member);
2107 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
2109 len = g_slist_length (l);
2110 res = mono_array_new (domain, mono_defaults.field_info_class, len);
2112 tmp = l = g_slist_reverse (l);
2113 for (; tmp; tmp = tmp->next, ++i)
2114 mono_array_set (res, gpointer, i, tmp->data);
2120 ves_icall_Type_GetMethods (MonoReflectionType *type, guint32 bflags)
2123 GSList *l = NULL, *tmp;
2124 MonoClass *startklass, *klass;
2129 GHashTable *method_slots = g_hash_table_new (NULL, NULL);
2131 MONO_ARCH_SAVE_REGS;
2133 domain = ((MonoObject *)type)->vtable->domain;
2134 klass = startklass = mono_class_from_mono_type (type->type);
2138 for (i = 0; i < klass->method.count; ++i) {
2140 method = klass->methods [i];
2141 if (strcmp (method->name, ".ctor") == 0 || strcmp (method->name, ".cctor") == 0)
2143 if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
2144 if (bflags & BFLAGS_Public)
2147 if (bflags & BFLAGS_NonPublic)
2153 if (method->flags & METHOD_ATTRIBUTE_STATIC) {
2154 if (bflags & BFLAGS_Static)
2157 if (bflags & BFLAGS_Instance)
2164 if (g_hash_table_lookup (method_slots, GUINT_TO_POINTER (method->slot)))
2166 g_hash_table_insert (method_slots, GUINT_TO_POINTER (method->slot), method);
2167 member = (MonoObject*)mono_method_get_object (domain, method, startklass);
2169 l = g_slist_prepend (l, member);
2172 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
2174 res = mono_array_new (domain, mono_defaults.method_info_class, len);
2177 tmp = l = g_slist_reverse (l);
2179 for (; tmp; tmp = tmp->next, ++i)
2180 mono_array_set (res, gpointer, i, tmp->data);
2182 g_hash_table_destroy (method_slots);
2187 ves_icall_Type_GetConstructors (MonoReflectionType *type, guint32 bflags)
2190 GSList *l = NULL, *tmp;
2191 static MonoClass *System_Reflection_ConstructorInfo;
2192 MonoClass *startklass, *klass;
2198 MONO_ARCH_SAVE_REGS;
2200 domain = ((MonoObject *)type)->vtable->domain;
2201 klass = startklass = mono_class_from_mono_type (type->type);
2203 for (i = 0; i < klass->method.count; ++i) {
2205 method = klass->methods [i];
2206 if (strcmp (method->name, ".ctor") && strcmp (method->name, ".cctor"))
2208 if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
2209 if (bflags & BFLAGS_Public)
2212 if (bflags & BFLAGS_NonPublic)
2218 if (method->flags & METHOD_ATTRIBUTE_STATIC) {
2219 if (bflags & BFLAGS_Static)
2222 if (bflags & BFLAGS_Instance)
2228 member = (MonoObject*)mono_method_get_object (domain, method, startklass);
2230 l = g_slist_prepend (l, member);
2232 len = g_slist_length (l);
2233 if (!System_Reflection_ConstructorInfo)
2234 System_Reflection_ConstructorInfo = mono_class_from_name (
2235 mono_defaults.corlib, "System.Reflection", "ConstructorInfo");
2236 res = mono_array_new (domain, System_Reflection_ConstructorInfo, len);
2238 tmp = l = g_slist_reverse (l);
2239 for (; tmp; tmp = tmp->next, ++i)
2240 mono_array_set (res, gpointer, i, tmp->data);
2246 ves_icall_Type_GetProperties (MonoReflectionType *type, guint32 bflags)
2249 GSList *l = NULL, *tmp;
2250 static MonoClass *System_Reflection_PropertyInfo;
2251 MonoClass *startklass, *klass;
2257 GHashTable *method_slots = g_hash_table_new (NULL, NULL);
2259 MONO_ARCH_SAVE_REGS;
2261 domain = ((MonoObject *)type)->vtable->domain;
2262 klass = startklass = mono_class_from_mono_type (type->type);
2265 for (i = 0; i < klass->property.count; ++i) {
2266 prop = &klass->properties [i];
2271 if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
2272 if (bflags & BFLAGS_Public)
2275 if (bflags & BFLAGS_NonPublic)
2281 if (method->flags & METHOD_ATTRIBUTE_STATIC) {
2282 if (bflags & BFLAGS_Static)
2285 if (bflags & BFLAGS_Instance)
2293 if (g_hash_table_lookup (method_slots, GUINT_TO_POINTER (method->slot)))
2295 g_hash_table_insert (method_slots, GUINT_TO_POINTER (method->slot), prop);
2297 l = g_slist_prepend (l, mono_property_get_object (domain, klass, prop));
2300 if ((!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent)))
2302 if (!System_Reflection_PropertyInfo)
2303 System_Reflection_PropertyInfo = mono_class_from_name (
2304 mono_defaults.corlib, "System.Reflection", "PropertyInfo");
2305 res = mono_array_new (domain, System_Reflection_PropertyInfo, len);
2308 tmp = l = g_slist_reverse (l);
2310 for (; tmp; tmp = tmp->next, ++i)
2311 mono_array_set (res, gpointer, i, tmp->data);
2313 g_hash_table_destroy (method_slots);
2317 static MonoReflectionEvent *
2318 ves_icall_MonoType_GetEvent (MonoReflectionType *type, MonoString *name, guint32 bflags)
2327 MONO_ARCH_SAVE_REGS;
2329 event_name = mono_string_to_utf8 (name);
2330 klass = mono_class_from_mono_type (type->type);
2331 domain = mono_object_domain (type);
2334 for (i = 0; i < klass->event.count; i++) {
2335 event = &klass->events [i];
2336 if (strcmp (event->name, event_name))
2339 method = event->add;
2341 method = event->remove;
2343 if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
2344 if (!(bflags & BFLAGS_Public))
2347 if (!(bflags & BFLAGS_NonPublic))
2351 g_free (event_name);
2352 return mono_event_get_object (domain, klass, event);
2355 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
2358 g_free (event_name);
2363 ves_icall_Type_GetEvents (MonoReflectionType *type, guint32 bflags)
2366 GSList *l = NULL, *tmp;
2367 static MonoClass *System_Reflection_EventInfo;
2368 MonoClass *startklass, *klass;
2374 MONO_ARCH_SAVE_REGS;
2376 domain = ((MonoObject *)type)->vtable->domain;
2377 klass = startklass = mono_class_from_mono_type (type->type);
2380 for (i = 0; i < klass->event.count; ++i) {
2381 event = &klass->events [i];
2383 method = event->add;
2385 method = event->remove;
2386 if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
2387 if (bflags & BFLAGS_Public)
2390 if (bflags & BFLAGS_NonPublic)
2396 if (method->flags & METHOD_ATTRIBUTE_STATIC) {
2397 if (bflags & BFLAGS_Static)
2400 if (bflags & BFLAGS_Instance)
2407 l = g_slist_prepend (l, mono_event_get_object (domain, klass, event));
2409 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
2411 len = g_slist_length (l);
2412 if (!System_Reflection_EventInfo)
2413 System_Reflection_EventInfo = mono_class_from_name (
2414 mono_defaults.corlib, "System.Reflection", "EventInfo");
2415 res = mono_array_new (domain, System_Reflection_EventInfo, len);
2418 tmp = l = g_slist_reverse (l);
2420 for (; tmp; tmp = tmp->next, ++i)
2421 mono_array_set (res, gpointer, i, tmp->data);
2426 static MonoReflectionType *
2427 ves_icall_Type_GetNestedType (MonoReflectionType *type, MonoString *name, guint32 bflags)
2430 MonoClass *startklass, *klass;
2435 MONO_ARCH_SAVE_REGS;
2437 domain = ((MonoObject *)type)->vtable->domain;
2438 klass = startklass = mono_class_from_mono_type (type->type);
2439 str = mono_string_to_utf8 (name);
2442 for (tmpn = klass->nested_classes; tmpn; tmpn = tmpn->next) {
2444 nested = tmpn->data;
2445 if ((nested->flags & TYPE_ATTRIBUTE_VISIBILITY_MASK) == TYPE_ATTRIBUTE_NESTED_PUBLIC) {
2446 if (bflags & BFLAGS_Public)
2449 if (bflags & BFLAGS_NonPublic)
2454 if (strcmp (nested->name, str) == 0){
2456 return mono_type_get_object (domain, &nested->byval_arg);
2459 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
2466 ves_icall_Type_GetNestedTypes (MonoReflectionType *type, guint32 bflags)
2469 GSList *l = NULL, *tmp;
2471 MonoClass *startklass, *klass;
2477 MONO_ARCH_SAVE_REGS;
2479 domain = ((MonoObject *)type)->vtable->domain;
2480 klass = startklass = mono_class_from_mono_type (type->type);
2482 for (tmpn = klass->nested_classes; tmpn; tmpn = tmpn->next) {
2484 nested = tmpn->data;
2485 if ((nested->flags & TYPE_ATTRIBUTE_VISIBILITY_MASK) == TYPE_ATTRIBUTE_NESTED_PUBLIC) {
2486 if (bflags & BFLAGS_Public)
2489 if (bflags & BFLAGS_NonPublic)
2494 member = (MonoObject*)mono_type_get_object (domain, &nested->byval_arg);
2495 l = g_slist_prepend (l, member);
2497 len = g_slist_length (l);
2498 res = mono_array_new (domain, mono_defaults.monotype_class, len);
2500 tmp = l = g_slist_reverse (l);
2501 for (; tmp; tmp = tmp->next, ++i)
2502 mono_array_set (res, gpointer, i, tmp->data);
2507 static MonoReflectionType*
2508 ves_icall_System_Reflection_Assembly_InternalGetType (MonoReflectionAssembly *assembly, MonoReflectionModule *module, MonoString *name, MonoBoolean throwOnError, MonoBoolean ignoreCase)
2512 MonoTypeNameParse info;
2514 MONO_ARCH_SAVE_REGS;
2516 str = mono_string_to_utf8 (name);
2517 /*g_print ("requested type %s in %s\n", str, assembly->assembly->aname.name);*/
2518 if (!mono_reflection_parse_type (str, &info)) {
2520 g_list_free (info.modifiers);
2521 g_list_free (info.nested);
2522 if (throwOnError) /* uhm: this is a parse error, though... */
2523 mono_raise_exception (mono_get_exception_type_load (name));
2524 /*g_print ("failed parse\n");*/
2528 if (module != NULL) {
2530 type = mono_reflection_get_type (module->image, &info, ignoreCase);
2535 if (assembly->assembly->dynamic) {
2536 /* Enumerate all modules */
2537 MonoReflectionAssemblyBuilder *abuilder = (MonoReflectionAssemblyBuilder*)assembly;
2540 if (!abuilder->modules)
2543 for (i = 0; i < mono_array_length (abuilder->modules); ++i) {
2544 MonoReflectionModuleBuilder *mb = mono_array_get (abuilder->modules, MonoReflectionModuleBuilder*, i);
2545 type = mono_reflection_get_type (&mb->dynamic_image->image, &info, ignoreCase);
2552 type = mono_reflection_get_type (assembly->assembly->image, &info, ignoreCase);
2554 g_list_free (info.modifiers);
2555 g_list_free (info.nested);
2558 mono_raise_exception (mono_get_exception_type_load (name));
2559 /* g_print ("failed find\n"); */
2562 /* g_print ("got it\n"); */
2563 return mono_type_get_object (mono_object_domain (assembly), type);
2568 ves_icall_System_Reflection_Assembly_get_code_base (MonoReflectionAssembly *assembly)
2570 MonoDomain *domain = mono_object_domain (assembly);
2571 MonoAssembly *mass = assembly->assembly;
2576 MONO_ARCH_SAVE_REGS;
2578 absolute = g_build_filename (mass->basedir, mass->image->module_name, NULL);
2579 uri = g_filename_to_uri (absolute, NULL, NULL);
2580 res = mono_string_new (domain, uri);
2587 ves_icall_System_Reflection_Assembly_get_location (MonoReflectionAssembly *assembly)
2589 MonoDomain *domain = mono_object_domain (assembly);
2591 char *name = g_build_filename (
2592 assembly->assembly->basedir,
2593 assembly->assembly->image->module_name, NULL);
2595 MONO_ARCH_SAVE_REGS;
2597 res = mono_string_new (domain, name);
2603 ves_icall_System_Reflection_Assembly_InternalImageRuntimeVersion (MonoReflectionAssembly *assembly)
2605 MonoDomain *domain = mono_object_domain (assembly);
2607 MONO_ARCH_SAVE_REGS;
2609 return mono_string_new (domain, assembly->assembly->image->version);
2612 static MonoReflectionMethod*
2613 ves_icall_System_Reflection_Assembly_get_EntryPoint (MonoReflectionAssembly *assembly)
2615 guint32 token = mono_image_get_entry_point (assembly->assembly->image);
2617 MONO_ARCH_SAVE_REGS;
2621 return mono_method_get_object (mono_object_domain (assembly), mono_get_method (assembly->assembly->image, token, NULL), NULL);
2625 ves_icall_System_Reflection_Assembly_GetManifestResourceNames (MonoReflectionAssembly *assembly)
2627 MonoTableInfo *table = &assembly->assembly->image->tables [MONO_TABLE_MANIFESTRESOURCE];
2628 MonoArray *result = mono_array_new (mono_object_domain (assembly), mono_defaults.string_class, table->rows);
2632 MONO_ARCH_SAVE_REGS;
2634 for (i = 0; i < table->rows; ++i) {
2635 val = mono_metadata_string_heap (assembly->assembly->image, mono_metadata_decode_row_col (table, i, MONO_MANIFEST_NAME));
2636 mono_array_set (result, gpointer, i, mono_string_new (mono_object_domain (assembly), val));
2642 ves_icall_System_Reflection_Assembly_GetReferencedAssemblies (MonoReflectionAssembly *assembly)
2644 static MonoClass *System_Reflection_AssemblyName;
2647 MonoDomain *domain = mono_object_domain (assembly);
2650 MONO_ARCH_SAVE_REGS;
2652 if (!System_Reflection_AssemblyName)
2653 System_Reflection_AssemblyName = mono_class_from_name (
2654 mono_defaults.corlib, "System.Reflection", "AssemblyName");
2656 for (ptr = assembly->assembly->image->references; ptr && *ptr; ptr++)
2659 result = mono_array_new (mono_object_domain (assembly), System_Reflection_AssemblyName, count);
2661 for (i = 0; i < count; i++) {
2662 MonoAssembly *assem = assembly->assembly->image->references [i];
2663 MonoReflectionAssemblyName *aname;
2664 char *codebase, *absolute;
2666 aname = (MonoReflectionAssemblyName *) mono_object_new (
2667 domain, System_Reflection_AssemblyName);
2669 if (strcmp (assem->aname.name, "corlib") == 0)
2670 aname->name = mono_string_new (domain, "mscorlib");
2672 aname->name = mono_string_new (domain, assem->aname.name);
2673 aname->major = assem->aname.major;
2675 absolute = g_build_filename (assem->basedir, assem->image->module_name, NULL);
2676 codebase = g_filename_to_uri (absolute, NULL, NULL);
2677 aname->codebase = mono_string_new (domain, codebase);
2680 mono_array_set (result, gpointer, i, aname);
2691 foreach_namespace (const char* key, gconstpointer val, NameSpaceInfo *info)
2693 MonoString *name = mono_string_new (mono_object_domain (info->res), key);
2695 mono_array_set (info->res, gpointer, info->idx, name);
2700 ves_icall_System_Reflection_Assembly_GetNamespaces (MonoReflectionAssembly *assembly)
2702 MonoImage *img = assembly->assembly->image;
2706 MonoTableInfo *t = &img->tables [MONO_TABLE_EXPORTEDTYPE];
2709 MONO_ARCH_SAVE_REGS;
2711 n = g_hash_table_size (img->name_cache);
2712 res = mono_array_new (mono_object_domain (assembly), mono_defaults.string_class, n);
2715 g_hash_table_foreach (img->name_cache, (GHFunc)foreach_namespace, &info);
2717 /* Add namespaces from the EXPORTEDTYPES table as well */
2720 GPtrArray *nspaces = g_ptr_array_new ();
2721 for (i = 0; i < t->rows; ++i) {
2722 const char *nspace = mono_metadata_string_heap (img, mono_metadata_decode_row_col (t, i, MONO_EXP_TYPE_NAMESPACE));
2723 if (!g_hash_table_lookup (img->name_cache, nspace)) {
2724 g_ptr_array_add (nspaces, (char*)nspace);
2727 if (nspaces->len > 0) {
2728 res2 = mono_array_new (mono_object_domain (assembly), mono_defaults.string_class, n + nspaces->len);
2729 memcpy (mono_array_addr (res2, MonoString*, 0),
2730 mono_array_addr (res, MonoString*, 0),
2731 n * sizeof (MonoString*));
2732 for (i = 0; i < nspaces->len; ++i)
2733 mono_array_set (res2, MonoString*, n + i,
2734 mono_string_new (mono_object_domain (assembly),
2735 g_ptr_array_index (nspaces, i)));
2738 g_ptr_array_free (nspaces, TRUE);
2744 /* move this in some file in mono/util/ */
2746 g_concat_dir_and_file (const char *dir, const char *file)
2748 g_return_val_if_fail (dir != NULL, NULL);
2749 g_return_val_if_fail (file != NULL, NULL);
2752 * If the directory name doesn't have a / on the end, we need
2753 * to add one so we get a proper path to the file
2755 if (dir [strlen(dir) - 1] != G_DIR_SEPARATOR)
2756 return g_strconcat (dir, G_DIR_SEPARATOR_S, file, NULL);
2758 return g_strconcat (dir, file, NULL);
2762 ves_icall_System_Reflection_Assembly_GetManifestResourceInternal (MonoReflectionAssembly *assembly, MonoString *name, gint32 *size)
2764 char *n = mono_string_to_utf8 (name);
2765 MonoTableInfo *table = &assembly->assembly->image->tables [MONO_TABLE_MANIFESTRESOURCE];
2767 guint32 cols [MONO_MANIFEST_SIZE];
2770 MONO_ARCH_SAVE_REGS;
2772 for (i = 0; i < table->rows; ++i) {
2773 mono_metadata_decode_row (table, i, cols, MONO_MANIFEST_SIZE);
2774 val = mono_metadata_string_heap (assembly->assembly->image, cols [MONO_MANIFEST_NAME]);
2775 if (strcmp (val, n) == 0)
2779 if (i == table->rows)
2782 if (cols [MONO_MANIFEST_IMPLEMENTATION]) {
2784 * this code should only be called after obtaining the
2785 * ResourceInfo and handling the other cases.
2787 g_assert_not_reached ();
2791 return (void*)mono_image_get_resource (assembly->assembly->image, cols [MONO_MANIFEST_OFFSET], size);
2795 ves_icall_System_Reflection_Assembly_GetManifestResourceInfoInternal (MonoReflectionAssembly *assembly, MonoString *name, MonoManifestResourceInfo *info)
2797 MonoTableInfo *table = &assembly->assembly->image->tables [MONO_TABLE_MANIFESTRESOURCE];
2799 guint32 cols [MONO_MANIFEST_SIZE];
2800 guint32 file_cols [MONO_FILE_SIZE];
2804 MONO_ARCH_SAVE_REGS;
2806 n = mono_string_to_utf8 (name);
2807 for (i = 0; i < table->rows; ++i) {
2808 mono_metadata_decode_row (table, i, cols, MONO_MANIFEST_SIZE);
2809 val = mono_metadata_string_heap (assembly->assembly->image, cols [MONO_MANIFEST_NAME]);
2810 if (strcmp (val, n) == 0)
2814 if (i == table->rows)
2817 if (!cols [MONO_MANIFEST_IMPLEMENTATION]) {
2818 info->location = RESOURCE_LOCATION_EMBEDDED | RESOURCE_LOCATION_IN_MANIFEST;
2821 switch (cols [MONO_MANIFEST_IMPLEMENTATION] & IMPLEMENTATION_MASK) {
2822 case IMPLEMENTATION_FILE:
2823 i = cols [MONO_MANIFEST_IMPLEMENTATION] >> IMPLEMENTATION_BITS;
2824 table = &assembly->assembly->image->tables [MONO_TABLE_FILE];
2825 mono_metadata_decode_row (table, i - 1, file_cols, MONO_FILE_SIZE);
2826 val = mono_metadata_string_heap (assembly->assembly->image, file_cols [MONO_FILE_NAME]);
2827 info->filename = mono_string_new (mono_object_domain (assembly), val);
2828 if (file_cols [MONO_FILE_FLAGS] && FILE_CONTAINS_NO_METADATA)
2831 info->location = RESOURCE_LOCATION_EMBEDDED;
2834 case IMPLEMENTATION_ASSEMBLYREF:
2835 i = cols [MONO_MANIFEST_IMPLEMENTATION] >> IMPLEMENTATION_BITS;
2836 info->assembly = mono_assembly_get_object (mono_domain_get (), assembly->assembly->image->references [i - 1]);
2838 // Obtain info recursively
2839 ves_icall_System_Reflection_Assembly_GetManifestResourceInfoInternal (info->assembly, name, info);
2840 info->location |= RESOURCE_LOCATION_ANOTHER_ASSEMBLY;
2843 case IMPLEMENTATION_EXP_TYPE:
2844 g_assert_not_reached ();
2853 ves_icall_System_Reflection_Assembly_GetFilesInternal (MonoReflectionAssembly *assembly, MonoString *name)
2855 MonoTableInfo *table = &assembly->assembly->image->tables [MONO_TABLE_FILE];
2856 MonoArray *result = NULL;
2861 MONO_ARCH_SAVE_REGS;
2863 /* check hash if needed */
2865 n = mono_string_to_utf8 (name);
2866 for (i = 0; i < table->rows; ++i) {
2867 val = mono_metadata_string_heap (assembly->assembly->image, mono_metadata_decode_row_col (table, i, MONO_FILE_NAME));
2868 if (strcmp (val, n) == 0) {
2871 n = g_concat_dir_and_file (assembly->assembly->basedir, val);
2872 fn = mono_string_new (mono_object_domain (assembly), n);
2874 return (MonoObject*)fn;
2881 for (i = 0; i < table->rows; ++i) {
2882 result = mono_array_new (mono_object_domain (assembly), mono_defaults.string_class, table->rows);
2883 val = mono_metadata_string_heap (assembly->assembly->image, mono_metadata_decode_row_col (table, i, MONO_FILE_NAME));
2884 n = g_concat_dir_and_file (assembly->assembly->basedir, val);
2885 mono_array_set (result, gpointer, i, mono_string_new (mono_object_domain (assembly), n));
2888 return (MonoObject*)result;
2892 ves_icall_System_Reflection_Assembly_GetModulesInternal (MonoReflectionAssembly *assembly)
2894 MonoDomain *domain = mono_domain_get();
2897 int i, module_count = 0, file_count = 0;
2898 MonoImage **modules = assembly->assembly->image->modules;
2899 MonoTableInfo *table;
2902 while (modules[module_count])
2906 table = &assembly->assembly->image->tables [MONO_TABLE_FILE];
2907 file_count = table->rows;
2909 g_assert( assembly->assembly->image != NULL);
2912 klass = mono_class_from_name ( mono_defaults.corlib, "System.Reflection", "Module");
2913 res = mono_array_new (domain, klass, module_count + file_count);
2915 mono_array_set (res, gpointer, 0, mono_module_get_object (domain, assembly->assembly->image));
2916 for ( i = 1; i < module_count; ++i )
2917 mono_array_set (res, gpointer, i, mono_module_get_object (domain, modules[i]));
2919 for (i = 0; i < table->rows; ++i)
2920 mono_array_set (res, gpointer, module_count + i, mono_module_file_get_object (domain, assembly->assembly->image, i));
2925 static MonoReflectionMethod*
2926 ves_icall_GetCurrentMethod (void)
2928 MonoMethod *m = mono_method_get_last_managed ();
2930 MONO_ARCH_SAVE_REGS;
2932 return mono_method_get_object (mono_domain_get (), m, NULL);
2935 static MonoReflectionAssembly*
2936 ves_icall_System_Reflection_Assembly_GetExecutingAssembly (void)
2938 MonoMethod *m = mono_method_get_last_managed ();
2940 MONO_ARCH_SAVE_REGS;
2942 return mono_assembly_get_object (mono_domain_get (), m->klass->image->assembly);
2947 get_caller (MonoMethod *m, gint32 no, gint32 ilo, gboolean managed, gpointer data)
2949 MonoMethod **dest = data;
2951 /* skip unmanaged frames */
2966 static MonoReflectionAssembly*
2967 ves_icall_System_Reflection_Assembly_GetEntryAssembly (void)
2969 MonoDomain* domain = mono_domain_get ();
2971 MONO_ARCH_SAVE_REGS;
2973 if (!domain->entry_assembly)
2974 domain = mono_root_domain;
2976 return mono_assembly_get_object (domain, domain->entry_assembly);
2980 static MonoReflectionAssembly*
2981 ves_icall_System_Reflection_Assembly_GetCallingAssembly (void)
2983 MonoMethod *m = mono_method_get_last_managed ();
2984 MonoMethod *dest = m;
2986 MONO_ARCH_SAVE_REGS;
2988 mono_stack_walk (get_caller, &dest);
2991 return mono_assembly_get_object (mono_domain_get (), dest->klass->image->assembly);
2995 ves_icall_System_MonoType_getFullName (MonoReflectionType *object)
2997 MonoDomain *domain = mono_object_domain (object);
3001 MONO_ARCH_SAVE_REGS;
3003 name = mono_type_get_name (object->type);
3004 res = mono_string_new (domain, name);
3011 fill_reflection_assembly_name (MonoDomain *domain, MonoReflectionAssemblyName *aname, MonoAssemblyName *name, const char *absolute)
3013 static MonoMethod *create_culture = NULL;
3016 const char *pkey_ptr;
3019 MONO_ARCH_SAVE_REGS;
3021 if (strcmp (name->name, "corlib") == 0)
3022 aname->name = mono_string_new (domain, "mscorlib");
3024 aname->name = mono_string_new (domain, name->name);
3026 aname->major = name->major;
3027 aname->minor = name->minor;
3028 aname->build = name->build;
3029 aname->revision = name->revision;
3030 aname->hashalg = name->hash_alg;
3032 codebase = g_filename_to_uri (absolute, NULL, NULL);
3034 aname->codebase = mono_string_new (domain, codebase);
3038 if (!create_culture) {
3039 MonoMethodDesc *desc = mono_method_desc_new ("System.Globalization.CultureInfo:CreateSpecificCulture(string)", TRUE);
3040 create_culture = mono_method_desc_search_in_image (desc, mono_defaults.corlib);
3041 g_assert (create_culture);
3042 mono_method_desc_free (desc);
3045 args [0] = mono_string_new (domain, name->culture);
3046 aname->cultureInfo =
3047 mono_runtime_invoke (create_culture, NULL, args, NULL);
3049 if (name->public_key) {
3050 pkey_ptr = name->public_key;
3051 pkey_len = mono_metadata_decode_blob_size (pkey_ptr, &pkey_ptr);
3053 aname->publicKey = mono_array_new (domain, mono_defaults.byte_class, pkey_len);
3054 memcpy (mono_array_addr (aname->publicKey, guint8, 0), pkey_ptr, pkey_len);
3059 ves_icall_System_Reflection_Assembly_FillName (MonoReflectionAssembly *assembly, MonoReflectionAssemblyName *aname)
3063 MONO_ARCH_SAVE_REGS;
3065 absolute = g_build_filename (assembly->assembly->basedir, assembly->assembly->image->module_name, NULL);
3067 fill_reflection_assembly_name (mono_object_domain (assembly), aname,
3068 &assembly->assembly->aname, absolute);
3074 ves_icall_System_Reflection_Assembly_InternalGetAssemblyName (MonoString *fname, MonoReflectionAssemblyName *aname)
3077 MonoImageOpenStatus status = MONO_IMAGE_OK;
3080 MonoAssemblyName name;
3082 MONO_ARCH_SAVE_REGS;
3084 filename = mono_string_to_utf8 (fname);
3086 image = mono_image_open (filename, &status);
3092 exc = mono_get_exception_file_not_found (fname);
3093 mono_raise_exception (exc);
3096 res = mono_assembly_fill_assembly_name (image, &name);
3098 mono_image_close (image);
3100 mono_raise_exception (mono_get_exception_argument ("assemblyFile", "The file does not contain a manifest"));
3103 fill_reflection_assembly_name (mono_domain_get (), aname, &name, filename);
3106 mono_image_close (image);
3110 mono_module_get_types (MonoDomain *domain, MonoImage *image,
3111 MonoBoolean exportedOnly)
3115 MonoTableInfo *tdef = &image->tables [MONO_TABLE_TYPEDEF];
3117 guint32 attrs, visibility;
3119 /* we start the count from 1 because we skip the special type <Module> */
3122 for (i = 1; i < tdef->rows; ++i) {
3123 attrs = mono_metadata_decode_row_col (tdef, i, MONO_TYPEDEF_FLAGS);
3124 visibility = attrs & TYPE_ATTRIBUTE_VISIBILITY_MASK;
3125 if (visibility == TYPE_ATTRIBUTE_PUBLIC || visibility == TYPE_ATTRIBUTE_NESTED_PUBLIC)
3129 count = tdef->rows - 1;
3131 res = mono_array_new (domain, mono_defaults.monotype_class, count);
3133 for (i = 1; i < tdef->rows; ++i) {
3134 attrs = mono_metadata_decode_row_col (tdef, i, MONO_TYPEDEF_FLAGS);
3135 visibility = attrs & TYPE_ATTRIBUTE_VISIBILITY_MASK;
3136 if (!exportedOnly || (visibility == TYPE_ATTRIBUTE_PUBLIC || visibility == TYPE_ATTRIBUTE_NESTED_PUBLIC)) {
3137 klass = mono_class_get (image, (i + 1) | MONO_TOKEN_TYPE_DEF);
3138 mono_array_set (res, gpointer, count, mono_type_get_object (domain, &klass->byval_arg));
3147 ves_icall_System_Reflection_Assembly_GetTypes (MonoReflectionAssembly *assembly, MonoBoolean exportedOnly)
3150 MonoImage *image = assembly->assembly->image;
3151 MonoTableInfo *table = &image->tables [MONO_TABLE_FILE];
3155 MONO_ARCH_SAVE_REGS;
3157 domain = mono_object_domain (assembly);
3158 res = mono_module_get_types (domain, image, exportedOnly);
3160 /* Append data from all modules in the assembly */
3161 for (i = 0; i < table->rows; ++i) {
3162 if (!(mono_metadata_decode_row_col (table, i, MONO_FILE_FLAGS) & FILE_CONTAINS_NO_METADATA)) {
3163 MonoImage *loaded_image = mono_assembly_load_module (image->assembly, i + 1);
3165 MonoArray *res2 = mono_module_get_types (domain, loaded_image, exportedOnly);
3166 /* Append the new types to the end of the array */
3167 if (mono_array_length (res2) > 0) {
3171 len1 = mono_array_length (res);
3172 len2 = mono_array_length (res2);
3173 res3 = mono_array_new (domain, mono_defaults.monotype_class, len1 + len2);
3174 memcpy (mono_array_addr (res3, MonoReflectionType*, 0),
3175 mono_array_addr (res, MonoReflectionType*, 0),
3176 len1 * sizeof (MonoReflectionType*));
3177 memcpy (mono_array_addr (res3, MonoReflectionType*, len1),
3178 mono_array_addr (res2, MonoReflectionType*, 0),
3179 len2 * sizeof (MonoReflectionType*));
3189 static MonoReflectionType*
3190 ves_icall_System_Reflection_Module_GetGlobalType (MonoReflectionModule *module)
3192 MonoDomain *domain = mono_object_domain (module);
3195 MONO_ARCH_SAVE_REGS;
3197 g_assert (module->image);
3198 klass = mono_class_get (module->image, 1 | MONO_TOKEN_TYPE_DEF);
3199 return mono_type_get_object (domain, &klass->byval_arg);
3203 ves_icall_System_Reflection_Module_GetGuidInternal (MonoReflectionModule *module)
3205 MonoDomain *domain = mono_object_domain (module);
3207 MONO_ARCH_SAVE_REGS;
3209 g_assert (module->image);
3210 return mono_string_new (domain, module->image->guid);
3214 ves_icall_System_Reflection_Module_InternalGetTypes (MonoReflectionModule *module)
3216 MONO_ARCH_SAVE_REGS;
3219 return mono_array_new (mono_object_domain (module), mono_defaults.monotype_class, 0);
3221 return mono_module_get_types (mono_object_domain (module), module->image, FALSE);
3224 static MonoReflectionType*
3225 ves_icall_ModuleBuilder_create_modified_type (MonoReflectionTypeBuilder *tb, MonoString *smodifiers)
3228 int isbyref = 0, rank;
3229 char *str = mono_string_to_utf8 (smodifiers);
3232 MONO_ARCH_SAVE_REGS;
3234 klass = mono_class_from_mono_type (tb->type.type);
3236 /* logic taken from mono_reflection_parse_type(): keep in sync */
3240 if (isbyref) { /* only one level allowed by the spec */
3247 return mono_type_get_object (mono_object_domain (tb), &klass->this_arg);
3250 klass = mono_ptr_class_get (&klass->byval_arg);
3251 mono_class_init (klass);
3262 else if (*p != '*') { /* '*' means unknown lower bound */
3273 klass = mono_array_class_get (klass, rank);
3274 mono_class_init (klass);
3281 return mono_type_get_object (mono_object_domain (tb), &klass->byval_arg);
3285 ves_icall_Type_IsArrayImpl (MonoReflectionType *t)
3290 MONO_ARCH_SAVE_REGS;
3293 res = !type->byref && (type->type == MONO_TYPE_ARRAY || type->type == MONO_TYPE_SZARRAY);
3299 ves_icall_System_Delegate_CreateDelegate_internal (MonoReflectionType *type, MonoObject *target,
3300 MonoReflectionMethod *info)
3302 MonoClass *delegate_class = mono_class_from_mono_type (type->type);
3303 MonoObject *delegate;
3306 MONO_ARCH_SAVE_REGS;
3308 mono_assert (delegate_class->parent == mono_defaults.multicastdelegate_class);
3310 delegate = mono_object_new (mono_object_domain (type), delegate_class);
3312 func = mono_compile_method (info->method);
3314 mono_delegate_ctor (delegate, target, func);
3320 * Magic number to convert a time which is relative to
3321 * Jan 1, 1970 into a value which is relative to Jan 1, 0001.
3323 #define EPOCH_ADJUST ((guint64)62135596800L)
3326 * Magic number to convert FILETIME base Jan 1, 1601 to DateTime - base Jan, 1, 0001
3328 #define FILETIME_ADJUST ((guint64)504911232000000000LL)
3331 * This returns Now in UTC
3334 ves_icall_System_DateTime_GetNow (void)
3336 #ifdef PLATFORM_WIN32
3341 SystemTimeToFileTime (&st, &ft);
3342 return (gint64) FILETIME_ADJUST + ((((gint64)ft.dwHighDateTime)<<32) | ft.dwLowDateTime);
3344 /* FIXME: put this in io-layer and call it GetLocalTime */
3348 MONO_ARCH_SAVE_REGS;
3350 if (gettimeofday (&tv, NULL) == 0) {
3351 res = (((gint64)tv.tv_sec + EPOCH_ADJUST)* 1000000 + tv.tv_usec)*10;
3354 /* fixme: raise exception */
3359 #ifdef PLATFORM_WIN32
3360 /* convert a SYSTEMTIME which is of the form "last thursday in october" to a real date */
3362 convert_to_absolute_date(SYSTEMTIME *date)
3364 #define IS_LEAP(y) ((y % 4) == 0 && ((y % 100) != 0 || (y % 400) == 0))
3365 static int days_in_month[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
3366 static int leap_days_in_month[] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
3367 /* from the calendar FAQ */
3368 int a = (14 - date->wMonth) / 12;
3369 int y = date->wYear - a;
3370 int m = date->wMonth + 12 * a - 2;
3371 int d = (1 + y + y/4 - y/100 + y/400 + (31*m)/12) % 7;
3373 /* d is now the day of the week for the first of the month (0 == Sunday) */
3375 int day_of_week = date->wDayOfWeek;
3377 /* set day_in_month to the first day in the month which falls on day_of_week */
3378 int day_in_month = 1 + (day_of_week - d);
3379 if (day_in_month <= 0)
3382 /* wDay is 1 for first weekday in month, 2 for 2nd ... 5 means last - so work that out allowing for days in the month */
3383 date->wDay = day_in_month + (date->wDay - 1) * 7;
3384 if (date->wDay > (IS_LEAP(date->wYear) ? leap_days_in_month[date->wMonth - 1] : days_in_month[date->wMonth - 1]))
3389 #ifndef PLATFORM_WIN32
3391 * Return's the offset from GMT of a local time.
3393 * tm is a local time
3394 * t is the same local time as seconds.
3397 gmt_offset(struct tm *tm, time_t t)
3399 #if defined (HAVE_TM_GMTOFF)
3400 return tm->tm_gmtoff;
3405 g.tm_isdst = tm->tm_isdst;
3407 return (int)difftime(t, t2);
3412 * This is heavily based on zdump.c from glibc 2.2.
3414 * * data[0]: start of daylight saving time (in DateTime ticks).
3415 * * data[1]: end of daylight saving time (in DateTime ticks).
3416 * * data[2]: utcoffset (in TimeSpan ticks).
3417 * * data[3]: additional offset when daylight saving (in TimeSpan ticks).
3418 * * name[0]: name of this timezone when not daylight saving.
3419 * * name[1]: name of this timezone when daylight saving.
3421 * FIXME: This only works with "standard" Unix dates (years between 1900 and 2100) while
3422 * the class library allows years between 1 and 9999.
3424 * Returns true on success and zero on failure.
3427 ves_icall_System_CurrentTimeZone_GetTimeZoneData (guint32 year, MonoArray **data, MonoArray **names)
3429 #ifndef PLATFORM_WIN32
3430 MonoDomain *domain = mono_domain_get ();
3431 struct tm start, tt;
3435 int is_daylight = 0, day;
3438 MONO_ARCH_SAVE_REGS;
3440 MONO_CHECK_ARG_NULL (data);
3441 MONO_CHECK_ARG_NULL (names);
3443 (*data) = mono_array_new (domain, mono_defaults.int64_class, 4);
3444 (*names) = mono_array_new (domain, mono_defaults.string_class, 2);
3447 * no info is better than crashing: we'll need our own tz data to make
3448 * this work properly, anyway. The range is reduced to 1970 .. 2037 because
3449 * that is what mktime is guaranteed to support (we get into an infinite loop
3452 if ((year < 1970) || (year > 2037)) {
3454 tt = *localtime (&t);
3455 strftime (tzone, sizeof (tzone), "%Z", &tt);
3456 mono_array_set ((*names), gpointer, 0, mono_string_new (domain, tzone));
3457 mono_array_set ((*names), gpointer, 1, mono_string_new (domain, tzone));
3461 memset (&start, 0, sizeof (start));
3464 start.tm_year = year-1900;
3466 t = mktime (&start);
3467 gmtoff = gmt_offset (&start, t);
3469 /* For each day of the year, calculate the tm_gmtoff. */
3470 for (day = 0; day < 365; day++) {
3473 tt = *localtime (&t);
3475 /* Daylight saving starts or ends here. */
3476 if (gmt_offset (&tt, t) != gmtoff) {
3480 /* Try to find the exact hour when daylight saving starts/ends. */
3484 tt1 = *localtime (&t1);
3485 } while (gmt_offset (&tt1, t1) != gmtoff);
3487 /* Try to find the exact minute when daylight saving starts/ends. */
3490 tt1 = *localtime (&t1);
3491 } while (gmt_offset (&tt1, t1) == gmtoff);
3493 strftime (tzone, sizeof (tzone), "%Z", &tt);
3495 /* Write data, if we're already in daylight saving, we're done. */
3497 mono_array_set ((*names), gpointer, 0, mono_string_new (domain, tzone));
3498 mono_array_set ((*data), gint64, 1, ((gint64)t1 + EPOCH_ADJUST) * 10000000L);
3501 mono_array_set ((*names), gpointer, 1, mono_string_new (domain, tzone));
3502 mono_array_set ((*data), gint64, 0, ((gint64)t1 + EPOCH_ADJUST) * 10000000L);
3506 /* This is only set once when we enter daylight saving. */
3507 mono_array_set ((*data), gint64, 2, (gint64)gmtoff * 10000000L);
3508 mono_array_set ((*data), gint64, 3, (gint64)(gmt_offset (&tt, t) - gmtoff) * 10000000L);
3510 gmtoff = gmt_offset (&tt, t);
3515 strftime (tzone, sizeof (tzone), "%Z", &tt);
3516 mono_array_set ((*names), gpointer, 0, mono_string_new (domain, tzone));
3517 mono_array_set ((*names), gpointer, 1, mono_string_new (domain, tzone));
3518 mono_array_set ((*data), gint64, 0, 0);
3519 mono_array_set ((*data), gint64, 1, 0);
3520 mono_array_set ((*data), gint64, 2, (gint64) gmtoff * 10000000L);
3521 mono_array_set ((*data), gint64, 3, 0);
3526 MonoDomain *domain = mono_domain_get ();
3527 TIME_ZONE_INFORMATION tz_info;
3532 tz_id = GetTimeZoneInformation (&tz_info);
3533 if (tz_id == TIME_ZONE_ID_INVALID)
3536 MONO_CHECK_ARG_NULL (data);
3537 MONO_CHECK_ARG_NULL (names);
3539 (*data) = mono_array_new (domain, mono_defaults.int64_class, 4);
3540 (*names) = mono_array_new (domain, mono_defaults.string_class, 2);
3542 for (i = 0; i < 32; ++i)
3543 if (!tz_info.DaylightName [i])
3545 mono_array_set ((*names), gpointer, 1, mono_string_new_utf16 (domain, tz_info.DaylightName, i));
3546 for (i = 0; i < 32; ++i)
3547 if (!tz_info.StandardName [i])
3549 mono_array_set ((*names), gpointer, 0, mono_string_new_utf16 (domain, tz_info.StandardName, i));
3551 if ((year <= 1601) || (year > 30827)) {
3553 * According to MSDN, the MS time functions can't handle dates outside
3559 /* even if the timezone has no daylight savings it may have Bias (e.g. GMT+13 it seems) */
3560 if (tz_id != TIME_ZONE_ID_UNKNOWN) {
3561 tz_info.StandardDate.wYear = year;
3562 convert_to_absolute_date(&tz_info.StandardDate);
3563 err = SystemTimeToFileTime (&tz_info.StandardDate, &ft);
3565 mono_array_set ((*data), gint64, 1, FILETIME_ADJUST + (((guint64)ft.dwHighDateTime<<32) | ft.dwLowDateTime));
3566 tz_info.DaylightDate.wYear = year;
3567 convert_to_absolute_date(&tz_info.DaylightDate);
3568 err = SystemTimeToFileTime (&tz_info.DaylightDate, &ft);
3570 mono_array_set ((*data), gint64, 0, FILETIME_ADJUST + (((guint64)ft.dwHighDateTime<<32) | ft.dwLowDateTime));
3572 mono_array_set ((*data), gint64, 2, (tz_info.Bias + tz_info.StandardBias) * -600000000LL);
3573 mono_array_set ((*data), gint64, 3, (tz_info.DaylightBias - tz_info.StandardBias) * -600000000LL);
3580 ves_icall_System_Object_obj_address (MonoObject *this)
3582 MONO_ARCH_SAVE_REGS;
3590 ves_icall_System_Buffer_ByteLengthInternal (MonoArray *array)
3597 MONO_ARCH_SAVE_REGS;
3599 klass = array->obj.vtable->klass;
3600 etype = klass->element_class->byval_arg.type;
3601 if (etype < MONO_TYPE_BOOLEAN || etype > MONO_TYPE_R8)
3604 if (array->bounds == NULL)
3605 length = array->max_length;
3608 for (i = 0; i < klass->rank; ++ i)
3609 length *= array->bounds [i].length;
3612 esize = mono_array_element_size (klass);
3613 return length * esize;
3617 ves_icall_System_Buffer_GetByteInternal (MonoArray *array, gint32 idx)
3619 MONO_ARCH_SAVE_REGS;
3621 return mono_array_get (array, gint8, idx);
3625 ves_icall_System_Buffer_SetByteInternal (MonoArray *array, gint32 idx, gint8 value)
3627 MONO_ARCH_SAVE_REGS;
3629 mono_array_set (array, gint8, idx, value);
3633 ves_icall_System_Buffer_BlockCopyInternal (MonoArray *src, gint32 src_offset, MonoArray *dest, gint32 dest_offset, gint32 count)
3635 char *src_buf, *dest_buf;
3637 MONO_ARCH_SAVE_REGS;
3639 src_buf = (gint8 *)src->vector + src_offset;
3640 dest_buf = (gint8 *)dest->vector + dest_offset;
3642 memcpy (dest_buf, src_buf, count);
3646 ves_icall_Remoting_RealProxy_GetTransparentProxy (MonoObject *this)
3648 MonoDomain *domain = mono_object_domain (this);
3650 MonoRealProxy *rp = ((MonoRealProxy *)this);
3654 MONO_ARCH_SAVE_REGS;
3656 res = mono_object_new (domain, mono_defaults.transparent_proxy_class);
3658 ((MonoTransparentProxy *)res)->rp = rp;
3659 type = ((MonoReflectionType *)rp->class_to_proxy)->type;
3660 klass = mono_class_from_mono_type (type);
3662 if (klass->flags & TYPE_ATTRIBUTE_INTERFACE)
3663 ((MonoTransparentProxy *)res)->klass = mono_defaults.marshalbyrefobject_class;
3665 ((MonoTransparentProxy *)res)->klass = klass;
3667 res->vtable = mono_class_proxy_vtable (domain, klass);
3672 /* System.Environment */
3675 ves_icall_System_Environment_get_MachineName (void)
3677 #if defined (PLATFORM_WIN32)
3682 len = MAX_COMPUTERNAME_LENGTH + 1;
3683 buf = g_new (gunichar2, len);
3686 if (GetComputerName (buf, (PDWORD) &len))
3687 result = mono_string_new_utf16 (mono_domain_get (), buf, len);
3696 MONO_ARCH_SAVE_REGS;
3699 buf = g_new (gchar, len);
3702 if (gethostname (buf, len) == 0)
3703 result = mono_string_new (mono_domain_get (), buf);
3711 ves_icall_System_Environment_get_Platform (void)
3713 MONO_ARCH_SAVE_REGS;
3715 #if defined (PLATFORM_WIN32)
3725 ves_icall_System_Environment_get_NewLine (void)
3727 MONO_ARCH_SAVE_REGS;
3729 #if defined (PLATFORM_WIN32)
3730 return mono_string_new (mono_domain_get (), "\r\n");
3732 return mono_string_new (mono_domain_get (), "\n");
3737 ves_icall_System_Environment_GetEnvironmentVariable (MonoString *name)
3742 MONO_ARCH_SAVE_REGS;
3747 utf8_name = mono_string_to_utf8 (name); /* FIXME: this should be ascii */
3748 value = g_getenv (utf8_name);
3754 return mono_string_new (mono_domain_get (), value);
3758 * There is no standard way to get at environ.
3766 ves_icall_System_Environment_GetEnvironmentVariableNames (void)
3774 MONO_ARCH_SAVE_REGS;
3777 for (e = environ; *e != 0; ++ e)
3780 domain = mono_domain_get ();
3781 names = mono_array_new (domain, mono_defaults.string_class, n);
3784 for (e = environ; *e != 0; ++ e) {
3785 parts = g_strsplit (*e, "=", 2);
3787 str = mono_string_new (domain, *parts);
3788 mono_array_set (names, MonoString *, n, str);
3800 * Returns the number of milliseconds elapsed since the system started.
3803 ves_icall_System_Environment_get_TickCount (void)
3805 #if defined (PLATFORM_WIN32)
3806 return GetTickCount();
3812 MONO_ARCH_SAVE_REGS;
3814 res = (gint32) gettimeofday (&tv, &tz);
3817 res = (gint32) ((tv.tv_sec & 0xFFFFF) * 1000 + (tv.tv_usec / 1000));
3824 ves_icall_System_Environment_Exit (int result)
3826 MONO_ARCH_SAVE_REGS;
3828 mono_runtime_quit ();
3830 /* we may need to do some cleanup here... */
3835 ves_icall_System_Text_Encoding_InternalCodePage (void)
3839 MONO_ARCH_SAVE_REGS;
3841 g_get_charset (&cset);
3842 /* g_print ("charset: %s\n", cset); */
3843 /* handle some common aliases */
3846 if (strcmp (cset, "ANSI_X3.4-1968") == 0)
3850 return mono_string_new (mono_domain_get (), cset);
3854 ves_icall_MonoMethodMessage_InitMessage (MonoMethodMessage *this,
3855 MonoReflectionMethod *method,
3856 MonoArray *out_args)
3858 MONO_ARCH_SAVE_REGS;
3860 mono_message_init (mono_object_domain (this), this, method, out_args);
3864 ves_icall_IsTransparentProxy (MonoObject *proxy)
3866 MONO_ARCH_SAVE_REGS;
3871 if (proxy->vtable->klass == mono_defaults.transparent_proxy_class)
3878 ves_icall_System_Runtime_Activation_ActivationServices_EnableProxyActivation (MonoReflectionType *type, MonoBoolean enable)
3883 MONO_ARCH_SAVE_REGS;
3885 klass = mono_class_from_mono_type (type->type);
3886 vtable = mono_class_vtable (mono_domain_get (), klass);
3888 if (enable) vtable->remote = 1;
3889 else vtable->remote = 0;
3893 ves_icall_System_Runtime_Activation_ActivationServices_AllocateUninitializedClassInstance (MonoReflectionType *type)
3898 MONO_ARCH_SAVE_REGS;
3900 domain = mono_object_domain (type);
3901 klass = mono_class_from_mono_type (type->type);
3903 if (klass->rank >= 1) {
3904 g_assert (klass->rank == 1);
3905 return (MonoObject *) mono_array_new (domain, klass->element_class, 0);
3907 // Bypass remoting object creation check
3908 return mono_object_new_alloc_specific (mono_class_vtable (domain, klass));
3913 ves_icall_System_IO_get_temp_path (void)
3915 MONO_ARCH_SAVE_REGS;
3917 return mono_string_new (mono_domain_get (), g_get_tmp_dir ());
3921 ves_icall_RuntimeMethod_GetFunctionPointer (MonoMethod *method)
3923 MONO_ARCH_SAVE_REGS;
3925 return mono_compile_method (method);
3928 char const * mono_cfg_dir = "";
3931 mono_install_get_config_dir (void)
3933 #ifdef PLATFORM_WIN32
3937 mono_cfg_dir = getenv ("MONO_CFG_DIR");
3939 if (!mono_cfg_dir) {
3940 #ifndef PLATFORM_WIN32
3941 mono_cfg_dir = MONO_CFG_DIR;
3943 mono_cfg_dir = g_strdup (MONO_CFG_DIR);
3944 for (i = strlen (mono_cfg_dir) - 1; i >= 0; i--) {
3945 if (mono_cfg_dir [i] == '/')
3946 ((char*) mono_cfg_dir) [i] = '\\';
3954 ves_icall_System_Configuration_DefaultConfig_get_machine_config_path (void)
3959 MONO_ARCH_SAVE_REGS;
3961 path = g_build_path (G_DIR_SEPARATOR_S, mono_cfg_dir, "mono", "machine.config", NULL);
3963 #if defined (PLATFORM_WIN32)
3964 /* Avoid mixing '/' and '\\' */
3967 for (i = strlen (path) - 1; i >= 0; i--)
3968 if (path [i] == '/')
3972 mcpath = mono_string_new (mono_domain_get (), path);
3979 ves_icall_System_Web_Util_ICalls_get_machine_install_dir (void)
3984 MONO_ARCH_SAVE_REGS;
3986 path = g_path_get_dirname (mono_cfg_dir);
3988 #if defined (PLATFORM_WIN32)
3989 /* Avoid mixing '/' and '\\' */
3992 for (i = strlen (path) - 1; i >= 0; i--)
3993 if (path [i] == '/')
3997 ipath = mono_string_new (mono_domain_get (), path);
4004 ves_icall_System_Diagnostics_DefaultTraceListener_WriteWindowsDebugString (MonoString *message)
4006 #if defined (PLATFORM_WIN32)
4007 static void (*output_debug) (gchar *);
4008 static gboolean tried_loading = FALSE;
4010 MONO_ARCH_SAVE_REGS;
4012 if (!tried_loading && output_debug == NULL) {
4015 tried_loading = TRUE;
4016 k32 = g_module_open ("kernel32", G_MODULE_BIND_LAZY);
4018 gchar *error = g_strdup (g_module_error ());
4019 g_warning ("Failed to load kernel32.dll: %s\n", error);
4024 g_module_symbol (k32, "OutputDebugStringW", (gpointer *) &output_debug);
4025 if (!output_debug) {
4026 gchar *error = g_strdup (g_module_error ());
4027 g_warning ("Failed to load OutputDebugStringW: %s\n", error);
4033 if (output_debug == NULL)
4036 output_debug (mono_string_chars (message));
4038 g_warning ("WriteWindowsDebugString called and PLATFORM_WIN32 not defined!\n");
4042 /* Only used for value types */
4044 ves_icall_System_Activator_CreateInstanceInternal (MonoReflectionType *type)
4049 MONO_ARCH_SAVE_REGS;
4051 domain = mono_object_domain (type);
4052 klass = mono_class_from_mono_type (type->type);
4054 return mono_object_new (domain, klass);
4057 static MonoReflectionMethod *
4058 ves_icall_MonoMethod_get_base_definition (MonoReflectionMethod *m)
4061 MonoMethod *method = m->method;
4062 MonoMethod *result = NULL;
4064 MONO_ARCH_SAVE_REGS;
4066 if (!(method->flags & METHOD_ATTRIBUTE_VIRTUAL) ||
4067 method->klass->flags & TYPE_ATTRIBUTE_INTERFACE ||
4068 method->flags & METHOD_ATTRIBUTE_NEW_SLOT)
4071 if (method->klass == NULL || (klass = method->klass->parent) == NULL)
4074 while (result == NULL && klass != NULL && (klass->vtable_size > method->slot))
4076 result = klass->vtable [method->slot];
4077 if (result == NULL) {
4078 /* It is an abstract method */
4080 for (i=0; i<klass->method.count; i++) {
4081 if (klass->methods [i]->slot == method->slot) {
4082 result = klass->methods [i];
4087 klass = klass->parent;
4093 return mono_method_get_object (mono_domain_get (), result, NULL);
4097 mono_ArgIterator_Setup (MonoArgIterator *iter, char* argsp, char* start)
4099 MONO_ARCH_SAVE_REGS;
4101 iter->sig = *(MonoMethodSignature**)argsp;
4103 g_assert (iter->sig->sentinelpos <= iter->sig->param_count);
4104 g_assert (iter->sig->call_convention == MONO_CALL_VARARG);
4107 /* FIXME: it's not documented what start is exactly... */
4108 iter->args = start? start: argsp + sizeof (gpointer);
4109 iter->num_args = iter->sig->param_count - iter->sig->sentinelpos;
4111 // g_print ("sig %p, param_count: %d, sent: %d\n", iter->sig, iter->sig->param_count, iter->sig->sentinelpos);
4115 mono_ArgIterator_IntGetNextArg (MonoArgIterator *iter)
4117 gint i, align, arg_size;
4119 MONO_ARCH_SAVE_REGS;
4121 i = iter->sig->sentinelpos + iter->next_arg;
4123 g_assert (i < iter->sig->param_count);
4125 res.type = iter->sig->params [i];
4126 res.klass = mono_class_from_mono_type (res.type);
4127 /* FIXME: endianess issue... */
4128 res.value = iter->args;
4129 arg_size = mono_type_stack_size (res.type, &align);
4130 iter->args = (char*)iter->args + arg_size;
4133 //g_print ("returning arg %d, type 0x%02x of size %d at %p\n", i, res.type->type, arg_size, res.value);
4139 mono_ArgIterator_IntGetNextArgT (MonoArgIterator *iter, MonoType *type)
4141 gint i, align, arg_size;
4143 MONO_ARCH_SAVE_REGS;
4145 i = iter->sig->sentinelpos + iter->next_arg;
4147 g_assert (i < iter->sig->param_count);
4149 while (i < iter->sig->param_count) {
4150 if (!mono_metadata_type_equal (type, iter->sig->params [i]))
4152 res.type = iter->sig->params [i];
4153 res.klass = mono_class_from_mono_type (res.type);
4154 /* FIXME: endianess issue... */
4155 res.value = iter->args;
4156 arg_size = mono_type_stack_size (res.type, &align);
4157 iter->args = (char*)iter->args + arg_size;
4159 //g_print ("returning arg %d, type 0x%02x of size %d at %p\n", i, res.type->type, arg_size, res.value);
4162 //g_print ("arg type 0x%02x not found\n", res.type->type);
4171 mono_ArgIterator_IntGetNextArgType (MonoArgIterator *iter)
4174 MONO_ARCH_SAVE_REGS;
4176 i = iter->sig->sentinelpos + iter->next_arg;
4178 g_assert (i < iter->sig->param_count);
4180 return iter->sig->params [i];
4184 mono_TypedReference_ToObject (MonoTypedRef tref)
4186 MONO_ARCH_SAVE_REGS;
4188 if (MONO_TYPE_IS_REFERENCE (tref.type)) {
4189 MonoObject** objp = tref.value;
4193 return mono_value_box (mono_domain_get (), tref.klass, tref.value);
4197 prelink_method (MonoMethod *method)
4199 if (!(method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL))
4201 mono_lookup_pinvoke_call (method);
4202 /* create the wrapper, too? */
4206 ves_icall_System_Runtime_InteropServices_Marshal_Prelink (MonoReflectionMethod *method)
4208 MONO_ARCH_SAVE_REGS;
4209 prelink_method (method->method);
4213 ves_icall_System_Runtime_InteropServices_Marshal_PrelinkAll (MonoReflectionType *type)
4215 MonoClass *klass = mono_class_from_mono_type (type->type);
4217 MONO_ARCH_SAVE_REGS;
4219 mono_class_init (klass);
4220 for (i = 0; i < klass->method.count; ++i)
4221 prelink_method (klass->methods [i]);
4226 static gconstpointer icall_map [] = {
4230 "System.Array::GetValue", ves_icall_System_Array_GetValue,
4231 "System.Array::SetValue", ves_icall_System_Array_SetValue,
4232 "System.Array::GetValueImpl", ves_icall_System_Array_GetValueImpl,
4233 "System.Array::SetValueImpl", ves_icall_System_Array_SetValueImpl,
4234 "System.Array::GetRank", ves_icall_System_Array_GetRank,
4235 "System.Array::GetLength", ves_icall_System_Array_GetLength,
4236 "System.Array::GetLowerBound", ves_icall_System_Array_GetLowerBound,
4237 "System.Array::CreateInstanceImpl", ves_icall_System_Array_CreateInstanceImpl,
4238 "System.Array::FastCopy", ves_icall_System_Array_FastCopy,
4239 "System.Array::Clone", mono_array_clone,
4242 * System.ArgIterator
4244 "System.ArgIterator::Setup", mono_ArgIterator_Setup,
4245 "System.ArgIterator::IntGetNextArg()", mono_ArgIterator_IntGetNextArg,
4246 "System.ArgIterator::IntGetNextArg(intptr)", mono_ArgIterator_IntGetNextArgT,
4247 "System.ArgIterator::IntGetNextArgType", mono_ArgIterator_IntGetNextArgType,
4250 * System.TypedReference
4252 "System.TypedReference::ToObject", mono_TypedReference_ToObject,
4257 "System.Object::MemberwiseClone", ves_icall_System_Object_MemberwiseClone,
4258 "System.Object::GetType", ves_icall_System_Object_GetType,
4259 "System.Object::InternalGetHashCode", ves_icall_System_Object_GetHashCode,
4260 "System.Object::obj_address", ves_icall_System_Object_obj_address,
4265 "System.ValueType::InternalGetHashCode", ves_icall_System_ValueType_InternalGetHashCode,
4266 "System.ValueType::InternalEquals", ves_icall_System_ValueType_Equals,
4272 "System.String::.ctor(char*)", ves_icall_System_String_ctor_charp,
4273 "System.String::.ctor(char*,int,int)", ves_icall_System_String_ctor_charp_int_int,
4274 "System.String::.ctor(sbyte*)", ves_icall_System_String_ctor_sbytep,
4275 "System.String::.ctor(sbyte*,int,int)", ves_icall_System_String_ctor_sbytep_int_int,
4276 "System.String::.ctor(sbyte*,int,int,System.Text.Encoding)", ves_icall_System_String_ctor_encoding,
4277 "System.String::.ctor(char[])", ves_icall_System_String_ctor_chara,
4278 "System.String::.ctor(char[],int,int)", ves_icall_System_String_ctor_chara_int_int,
4279 "System.String::.ctor(char,int)", ves_icall_System_String_ctor_char_int,
4280 "System.String::InternalJoin", ves_icall_System_String_InternalJoin,
4281 "System.String::InternalInsert", ves_icall_System_String_InternalInsert,
4282 "System.String::InternalReplace(char,char)", ves_icall_System_String_InternalReplace_Char,
4283 "System.String::InternalRemove", ves_icall_System_String_InternalRemove,
4284 "System.String::InternalCopyTo", ves_icall_System_String_InternalCopyTo,
4285 "System.String::InternalSplit", ves_icall_System_String_InternalSplit,
4286 "System.String::InternalTrim", ves_icall_System_String_InternalTrim,
4287 "System.String::InternalIndexOfAny", ves_icall_System_String_InternalIndexOfAny,
4288 "System.String::InternalLastIndexOfAny", ves_icall_System_String_InternalLastIndexOfAny,
4289 "System.String::InternalPad", ves_icall_System_String_InternalPad,
4290 "System.String::InternalAllocateStr", ves_icall_System_String_InternalAllocateStr,
4291 "System.String::InternalStrcpy(string,int,string)", ves_icall_System_String_InternalStrcpy_Str,
4292 "System.String::InternalStrcpy(string,int,string,int,int)", ves_icall_System_String_InternalStrcpy_StrN,
4293 "System.String::InternalIntern", ves_icall_System_String_InternalIntern,
4294 "System.String::InternalIsInterned", ves_icall_System_String_InternalIsInterned,
4295 "System.String::GetHashCode", ves_icall_System_String_GetHashCode,
4296 "System.String::get_Chars", ves_icall_System_String_get_Chars,
4301 "System.AppDomain::createDomain", ves_icall_System_AppDomain_createDomain,
4302 "System.AppDomain::getCurDomain", ves_icall_System_AppDomain_getCurDomain,
4303 "System.AppDomain::GetData", ves_icall_System_AppDomain_GetData,
4304 "System.AppDomain::SetData", ves_icall_System_AppDomain_SetData,
4305 "System.AppDomain::getSetup", ves_icall_System_AppDomain_getSetup,
4306 "System.AppDomain::getFriendlyName", ves_icall_System_AppDomain_getFriendlyName,
4307 "System.AppDomain::GetAssemblies", ves_icall_System_AppDomain_GetAssemblies,
4308 "System.AppDomain::LoadAssembly", ves_icall_System_AppDomain_LoadAssembly,
4309 "System.AppDomain::LoadAssemblyRaw", ves_icall_System_AppDomain_LoadAssemblyRaw,
4310 "System.AppDomain::InternalIsFinalizingForUnload", ves_icall_System_AppDomain_InternalIsFinalizingForUnload,
4311 "System.AppDomain::InternalUnload", ves_icall_System_AppDomain_InternalUnload,
4312 "System.AppDomain::ExecuteAssembly", ves_icall_System_AppDomain_ExecuteAssembly,
4313 "System.AppDomain::InternalSetDomain", ves_icall_System_AppDomain_InternalSetDomain,
4314 "System.AppDomain::InternalSetDomainByID", ves_icall_System_AppDomain_InternalSetDomainByID,
4315 "System.AppDomain::InternalPushDomainRef", ves_icall_System_AppDomain_InternalPushDomainRef,
4316 "System.AppDomain::InternalPushDomainRefByID", ves_icall_System_AppDomain_InternalPushDomainRefByID,
4317 "System.AppDomain::InternalPopDomainRef", ves_icall_System_AppDomain_InternalPopDomainRef,
4318 "System.AppDomain::InternalSetContext", ves_icall_System_AppDomain_InternalSetContext,
4319 "System.AppDomain::InternalGetContext", ves_icall_System_AppDomain_InternalGetContext,
4320 "System.AppDomain::InternalGetDefaultContext", ves_icall_System_AppDomain_InternalGetDefaultContext,
4321 "System.AppDomain::InternalGetProcessGuid", ves_icall_System_AppDomain_InternalGetProcessGuid,
4324 * System.AppDomainSetup
4326 "System.AppDomainSetup::InitAppDomainSetup", ves_icall_System_AppDomainSetup_InitAppDomainSetup,
4331 "System.Double::ParseImpl", mono_double_ParseImpl,
4332 "System.Double::AssertEndianity", ves_icall_System_Double_AssertEndianity,
4337 "System.Decimal::decimal2UInt64", mono_decimal2UInt64,
4338 "System.Decimal::decimal2Int64", mono_decimal2Int64,
4339 "System.Decimal::double2decimal", mono_double2decimal, /* FIXME: wrong signature. */
4340 "System.Decimal::decimalIncr", mono_decimalIncr,
4341 "System.Decimal::decimalSetExponent", mono_decimalSetExponent,
4342 "System.Decimal::decimal2double", mono_decimal2double,
4343 "System.Decimal::decimalFloorAndTrunc", mono_decimalFloorAndTrunc,
4344 "System.Decimal::decimalRound", mono_decimalRound,
4345 "System.Decimal::decimalMult", mono_decimalMult,
4346 "System.Decimal::decimalDiv", mono_decimalDiv,
4347 "System.Decimal::decimalIntDiv", mono_decimalIntDiv,
4348 "System.Decimal::decimalCompare", mono_decimalCompare,
4349 "System.Decimal::string2decimal", mono_string2decimal,
4350 "System.Decimal::decimal2string", mono_decimal2string,
4355 "System.Reflection.Emit.ModuleBuilder::getUSIndex", mono_image_insert_string,
4356 "System.Reflection.Emit.ModuleBuilder::getToken", ves_icall_ModuleBuilder_getToken,
4357 "System.Reflection.Emit.ModuleBuilder::create_modified_type", ves_icall_ModuleBuilder_create_modified_type,
4358 "System.Reflection.Emit.ModuleBuilder::basic_init", mono_image_module_basic_init,
4359 "System.Reflection.Emit.ModuleBuilder::build_metadata", ves_icall_ModuleBuilder_build_metadata,
4360 "System.Reflection.Emit.ModuleBuilder::getDataChunk", ves_icall_ModuleBuilder_getDataChunk,
4365 "System.Reflection.Emit.AssemblyBuilder::basic_init", mono_image_basic_init,
4370 "System.Reflection.MonoMethodInfo::get_method_info", ves_icall_get_method_info,
4371 "System.Reflection.MonoMethodInfo::get_parameter_info", ves_icall_get_parameter_info,
4372 "System.Reflection.MonoPropertyInfo::get_property_info", ves_icall_get_property_info,
4373 "System.Reflection.MonoEventInfo::get_event_info", ves_icall_get_event_info,
4374 "System.Reflection.MonoMethod::InternalInvoke", ves_icall_InternalInvoke,
4375 "System.Reflection.MonoCMethod::InternalInvoke", ves_icall_InternalInvoke,
4376 "System.Reflection.MethodBase::GetCurrentMethod", ves_icall_GetCurrentMethod,
4377 "System.MonoCustomAttrs::GetCustomAttributes", mono_reflection_get_custom_attrs,
4378 "System.Reflection.Emit.CustomAttributeBuilder::GetBlob", mono_reflection_get_custom_attrs_blob,
4379 "System.Reflection.MonoField::GetParentType", ves_icall_MonoField_GetParentType,
4380 "System.Reflection.MonoField::GetValueInternal", ves_icall_MonoField_GetValueInternal,
4381 "System.Reflection.MonoField::SetValueInternal", ves_icall_FieldInfo_SetValueInternal,
4382 "System.Reflection.Emit.SignatureHelper::get_signature_local", mono_reflection_sighelper_get_signature_local,
4383 "System.Reflection.Emit.SignatureHelper::get_signature_field", mono_reflection_sighelper_get_signature_field,
4385 "System.RuntimeMethodHandle::GetFunctionPointer", ves_icall_RuntimeMethod_GetFunctionPointer,
4386 "System.Reflection.MonoMethod::get_base_definition", ves_icall_MonoMethod_get_base_definition,
4390 "System.MonoEnumInfo::get_enum_info", ves_icall_get_enum_info,
4391 "System.Enum::get_value", ves_icall_System_Enum_get_value,
4392 "System.Enum::ToObject", ves_icall_System_Enum_ToObject,
4397 "System.Reflection.Emit.TypeBuilder::setup_internal_class", mono_reflection_setup_internal_class,
4398 "System.Reflection.Emit.TypeBuilder::create_internal_class", mono_reflection_create_internal_class,
4399 "System.Reflection.Emit.TypeBuilder::create_runtime_class", mono_reflection_create_runtime_class,
4400 "System.Reflection.Emit.TypeBuilder::setup_generic_class", mono_reflection_setup_generic_class,
4405 "System.Reflection.Emit.DynamicMethod::create_dynamic_method", mono_reflection_create_dynamic_method,
4408 * TypeBuilder generics icalls.
4410 "System.Reflection.Emit.TypeBuilder::get_IsGenericParameter", ves_icall_TypeBuilder_get_IsGenericParameter,
4411 "System.Reflection.Emit.TypeBuilder::define_generic_parameter", ves_icall_TypeBuilder_define_generic_parameter,
4414 * MethodBuilder generic icalls.
4416 "System.Reflection.Emit.MethodBuilder::define_generic_parameter", ves_icall_MethodBuilder_define_generic_parameter,
4419 * MonoGenericInst generic icalls.
4421 "System.Reflection.MonoGenericInst::inflate_method", mono_reflection_inflate_method_or_ctor,
4422 "System.Reflection.MonoGenericInst::inflate_ctor", mono_reflection_inflate_method_or_ctor,
4423 "System.Reflection.MonoGenericInst::inflate_field", mono_reflection_inflate_field,
4428 "System.Type::internal_from_name", ves_icall_type_from_name,
4429 "System.Type::internal_from_handle", ves_icall_type_from_handle,
4430 "System.MonoType::get_attributes", ves_icall_get_attributes,
4431 "System.Type::type_is_subtype_of", ves_icall_type_is_subtype_of,
4432 "System.Type::type_is_assignable_from", ves_icall_type_is_assignable_from,
4433 "System.Type::Equals", ves_icall_type_Equals,
4434 "System.Type::GetTypeCode", ves_icall_type_GetTypeCode,
4435 "System.Type::GetInterfaceMapData", ves_icall_Type_GetInterfaceMapData,
4436 "System.Type::IsArrayImpl", ves_icall_Type_IsArrayImpl,
4438 /* Type generics icalls */
4439 "System.Type::GetGenericArguments", ves_icall_Type_GetGenericArguments,
4440 "System.Type::GetGenericParameterPosition", ves_icall_Type_GetGenericParameterPosition,
4441 "System.Type::get_IsGenericTypeDefinition", ves_icall_Type_get_IsGenericTypeDefinition,
4442 "System.Type::GetGenericTypeDefinition_impl", ves_icall_Type_GetGenericTypeDefinition_impl,
4443 "System.Type::BindGenericParameters", ves_icall_Type_BindGenericParameters,
4444 "System.Type::get_IsGenericInstance", ves_icall_Type_get_IsGenericInstance,
4446 "System.MonoType::get_HasGenericArguments", ves_icall_MonoType_get_HasGenericArguments,
4447 "System.MonoType::get_IsGenericParameter", ves_icall_MonoType_get_IsGenericParameter,
4448 "System.MonoType::get_DeclaringMethod", ves_icall_MonoType_get_DeclaringMethod,
4450 /* Method generics icalls */
4451 "System.Reflection.MethodInfo::get_IsGenericMethodDefinition", ves_icall_MethodInfo_get_IsGenericMethodDefinition,
4452 "System.Reflection.MethodInfo::BindGenericParameters", mono_reflection_bind_generic_method_parameters,
4453 "System.Reflection.MonoMethod::GetGenericArguments", ves_icall_MonoMethod_GetGenericArguments,
4457 * System.Reflection.FieldInfo
4459 "System.Reflection.FieldInfo::internal_from_handle", ves_icall_System_Reflection_FieldInfo_internal_from_handle,
4462 * System.Runtime.CompilerServices.RuntimeHelpers
4464 "System.Runtime.CompilerServices.RuntimeHelpers::InitializeArray", ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_InitializeArray,
4465 "System.Runtime.CompilerServices.RuntimeHelpers::GetOffsetToStringData", ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetOffsetToStringData,
4466 "System.Runtime.CompilerServices.RuntimeHelpers::GetObjectValue", ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetObjectValue,
4467 "System.Runtime.CompilerServices.RuntimeHelpers::RunClassConstructor", ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_RunClassConstructor,
4472 "System.Threading.Thread::Abort_internal(object)", ves_icall_System_Threading_Thread_Abort,
4473 "System.Threading.Thread::ResetAbort_internal()", ves_icall_System_Threading_Thread_ResetAbort,
4474 "System.Threading.Thread::Thread_internal", ves_icall_System_Threading_Thread_Thread_internal,
4475 "System.Threading.Thread::Thread_free_internal", ves_icall_System_Threading_Thread_Thread_free_internal,
4476 "System.Threading.Thread::Start_internal", ves_icall_System_Threading_Thread_Start_internal,
4477 "System.Threading.Thread::Sleep_internal", ves_icall_System_Threading_Thread_Sleep_internal,
4478 "System.Threading.Thread::CurrentThread_internal", mono_thread_current,
4479 "System.Threading.Thread::Join_internal", ves_icall_System_Threading_Thread_Join_internal,
4480 "System.Threading.Thread::SlotHash_lookup", ves_icall_System_Threading_Thread_SlotHash_lookup,
4481 "System.Threading.Thread::SlotHash_store", ves_icall_System_Threading_Thread_SlotHash_store,
4482 "System.Threading.Thread::GetDomainID", ves_icall_System_Threading_Thread_GetDomainID,
4483 "System.Threading.Monitor::Monitor_exit", ves_icall_System_Threading_Monitor_Monitor_exit,
4484 "System.Threading.Monitor::Monitor_test_owner", ves_icall_System_Threading_Monitor_Monitor_test_owner,
4485 "System.Threading.Monitor::Monitor_test_synchronised", ves_icall_System_Threading_Monitor_Monitor_test_synchronised,
4486 "System.Threading.Monitor::Monitor_pulse", ves_icall_System_Threading_Monitor_Monitor_pulse,
4487 "System.Threading.Monitor::Monitor_pulse_all", ves_icall_System_Threading_Monitor_Monitor_pulse_all,
4488 "System.Threading.Monitor::Monitor_try_enter", ves_icall_System_Threading_Monitor_Monitor_try_enter,
4489 "System.Threading.Monitor::Monitor_wait", ves_icall_System_Threading_Monitor_Monitor_wait,
4490 "System.Threading.Mutex::CreateMutex_internal", ves_icall_System_Threading_Mutex_CreateMutex_internal,
4491 "System.Threading.Mutex::ReleaseMutex_internal", ves_icall_System_Threading_Mutex_ReleaseMutex_internal,
4492 "System.Threading.NativeEventCalls::CreateEvent_internal", ves_icall_System_Threading_Events_CreateEvent_internal,
4493 "System.Threading.NativeEventCalls::SetEvent_internal", ves_icall_System_Threading_Events_SetEvent_internal,
4494 "System.Threading.NativeEventCalls::ResetEvent_internal", ves_icall_System_Threading_Events_ResetEvent_internal,
4495 "System.Threading.NativeEventCalls::CloseEvent_internal", ves_icall_System_Threading_Events_CloseEvent_internal,
4496 "System.Threading.ThreadPool::GetAvailableThreads", ves_icall_System_Threading_ThreadPool_GetAvailableThreads,
4497 "System.Threading.ThreadPool::GetMaxThreads", ves_icall_System_Threading_ThreadPool_GetMaxThreads,
4498 "System.Threading.Thread::VolatileRead(byte&)", ves_icall_System_Threading_Thread_VolatileRead1,
4499 "System.Threading.Thread::VolatileRead(double&)", ves_icall_System_Threading_Thread_VolatileRead8,
4500 "System.Threading.Thread::VolatileRead(short&)", ves_icall_System_Threading_Thread_VolatileRead2,
4501 "System.Threading.Thread::VolatileRead(int&)", ves_icall_System_Threading_Thread_VolatileRead4,
4502 "System.Threading.Thread::VolatileRead(long&)", ves_icall_System_Threading_Thread_VolatileRead8,
4503 "System.Threading.Thread::VolatileRead(IntPtr&)", ves_icall_System_Threading_Thread_VolatileReadIntPtr,
4504 "System.Threading.Thread::VolatileRead(object&)", ves_icall_System_Threading_Thread_VolatileReadIntPtr,
4505 "System.Threading.Thread::VolatileRead(sbyte&)", ves_icall_System_Threading_Thread_VolatileRead1,
4506 "System.Threading.Thread::VolatileRead(float&)", ves_icall_System_Threading_Thread_VolatileRead4,
4507 "System.Threading.Thread::VolatileRead(ushort&)", ves_icall_System_Threading_Thread_VolatileRead2,
4508 "System.Threading.Thread::VolatileRead(uint&)", ves_icall_System_Threading_Thread_VolatileRead2,
4509 "System.Threading.Thread::VolatileRead(ulong&)", ves_icall_System_Threading_Thread_VolatileRead8,
4510 "System.Threading.Thread::VolatileRead(UIntPtr&)", ves_icall_System_Threading_Thread_VolatileReadIntPtr,
4511 "System.Threading.Thread::VolatileWrite(byte&,byte)", ves_icall_System_Threading_Thread_VolatileWrite1,
4512 "System.Threading.Thread::VolatileWrite(double&,double)", ves_icall_System_Threading_Thread_VolatileWrite8,
4513 "System.Threading.Thread::VolatileWrite(short&,short)", ves_icall_System_Threading_Thread_VolatileWrite2,
4514 "System.Threading.Thread::VolatileWrite(int&,int)", ves_icall_System_Threading_Thread_VolatileWrite4,
4515 "System.Threading.Thread::VolatileWrite(long&,long)", ves_icall_System_Threading_Thread_VolatileWrite8,
4516 "System.Threading.Thread::VolatileWrite(IntPtr&,IntPtr)", ves_icall_System_Threading_Thread_VolatileWriteIntPtr,
4517 "System.Threading.Thread::VolatileWrite(object&,object)", ves_icall_System_Threading_Thread_VolatileWriteIntPtr,
4518 "System.Threading.Thread::VolatileWrite(sbyte&,sbyte)", ves_icall_System_Threading_Thread_VolatileWrite1,
4519 "System.Threading.Thread::VolatileWrite(float&,float)", ves_icall_System_Threading_Thread_VolatileWrite4,
4520 "System.Threading.Thread::VolatileWrite(ushort&,ushort)", ves_icall_System_Threading_Thread_VolatileWrite2,
4521 "System.Threading.Thread::VolatileWrite(uint&,uint)", ves_icall_System_Threading_Thread_VolatileWrite2,
4522 "System.Threading.Thread::VolatileWrite(ulong&,ulong)", ves_icall_System_Threading_Thread_VolatileWrite8,
4523 "System.Threading.Thread::VolatileWrite(UIntPtr&,UIntPtr)", ves_icall_System_Threading_Thread_VolatileWriteIntPtr,
4526 * System.Threading.WaitHandle
4528 "System.Threading.WaitHandle::WaitAll_internal", ves_icall_System_Threading_WaitHandle_WaitAll_internal,
4529 "System.Threading.WaitHandle::WaitAny_internal", ves_icall_System_Threading_WaitHandle_WaitAny_internal,
4530 "System.Threading.WaitHandle::WaitOne_internal", ves_icall_System_Threading_WaitHandle_WaitOne_internal,
4533 * System.Runtime.InteropServices.Marshal
4535 "System.Runtime.InteropServices.Marshal::ReadIntPtr", ves_icall_System_Runtime_InteropServices_Marshal_ReadIntPtr,
4536 "System.Runtime.InteropServices.Marshal::ReadByte", ves_icall_System_Runtime_InteropServices_Marshal_ReadByte,
4537 "System.Runtime.InteropServices.Marshal::ReadInt16", ves_icall_System_Runtime_InteropServices_Marshal_ReadInt16,
4538 "System.Runtime.InteropServices.Marshal::ReadInt32", ves_icall_System_Runtime_InteropServices_Marshal_ReadInt32,
4539 "System.Runtime.InteropServices.Marshal::ReadInt64", ves_icall_System_Runtime_InteropServices_Marshal_ReadInt64,
4540 "System.Runtime.InteropServices.Marshal::WriteIntPtr", ves_icall_System_Runtime_InteropServices_Marshal_WriteIntPtr,
4541 "System.Runtime.InteropServices.Marshal::WriteByte", ves_icall_System_Runtime_InteropServices_Marshal_WriteByte,
4542 "System.Runtime.InteropServices.Marshal::WriteInt16", ves_icall_System_Runtime_InteropServices_Marshal_WriteInt16,
4543 "System.Runtime.InteropServices.Marshal::WriteInt32", ves_icall_System_Runtime_InteropServices_Marshal_WriteInt32,
4544 "System.Runtime.InteropServices.Marshal::WriteInt64", ves_icall_System_Runtime_InteropServices_Marshal_WriteInt64,
4546 "System.Runtime.InteropServices.Marshal::PtrToStringAnsi(intptr)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi,
4547 "System.Runtime.InteropServices.Marshal::PtrToStringAnsi(intptr,int)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi_len,
4548 "System.Runtime.InteropServices.Marshal::PtrToStringAuto(intptr)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi,
4549 "System.Runtime.InteropServices.Marshal::PtrToStringAuto(intptr,int)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi_len,
4550 "System.Runtime.InteropServices.Marshal::PtrToStringUni(intptr)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringUni,
4551 "System.Runtime.InteropServices.Marshal::PtrToStringUni(intptr,int)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringUni_len,
4552 "System.Runtime.InteropServices.Marshal::PtrToStringBSTR", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringBSTR,
4554 "System.Runtime.InteropServices.Marshal::GetLastWin32Error", ves_icall_System_Runtime_InteropServices_Marshal_GetLastWin32Error,
4555 "System.Runtime.InteropServices.Marshal::AllocHGlobal", mono_marshal_alloc,
4556 "System.Runtime.InteropServices.Marshal::FreeHGlobal", mono_marshal_free,
4557 "System.Runtime.InteropServices.Marshal::ReAllocHGlobal", mono_marshal_realloc,
4558 "System.Runtime.InteropServices.Marshal::copy_to_unmanaged", ves_icall_System_Runtime_InteropServices_Marshal_copy_to_unmanaged,
4559 "System.Runtime.InteropServices.Marshal::copy_from_unmanaged", ves_icall_System_Runtime_InteropServices_Marshal_copy_from_unmanaged,
4560 "System.Runtime.InteropServices.Marshal::SizeOf", ves_icall_System_Runtime_InteropServices_Marshal_SizeOf,
4561 "System.Runtime.InteropServices.Marshal::StructureToPtr", ves_icall_System_Runtime_InteropServices_Marshal_StructureToPtr,
4562 "System.Runtime.InteropServices.Marshal::PtrToStructure(intptr,object)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStructure,
4563 "System.Runtime.InteropServices.Marshal::PtrToStructure(intptr,System.Type)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStructure_type,
4564 "System.Runtime.InteropServices.Marshal::OffsetOf", ves_icall_System_Runtime_InteropServices_Marshal_OffsetOf,
4565 "System.Runtime.InteropServices.Marshal::StringToHGlobalAnsi", ves_icall_System_Runtime_InteropServices_Marshal_StringToHGlobalAnsi,
4566 "System.Runtime.InteropServices.Marshal::StringToHGlobalAuto", ves_icall_System_Runtime_InteropServices_Marshal_StringToHGlobalAnsi,
4567 "System.Runtime.InteropServices.Marshal::StringToHGlobalUni", ves_icall_System_Runtime_InteropServices_Marshal_StringToHGlobalUni,
4568 "System.Runtime.InteropServices.Marshal::DestroyStructure", ves_icall_System_Runtime_InteropServices_Marshal_DestroyStructure,
4569 "System.Runtime.InteropServices.Marshal::Prelink", ves_icall_System_Runtime_InteropServices_Marshal_Prelink,
4570 "System.Runtime.InteropServices.Marshal::PrelinkAll", ves_icall_System_Runtime_InteropServices_Marshal_PrelinkAll,
4573 "System.Reflection.Assembly::LoadFrom", ves_icall_System_Reflection_Assembly_LoadFrom,
4574 "System.Reflection.Assembly::InternalGetType", ves_icall_System_Reflection_Assembly_InternalGetType,
4575 "System.Reflection.Assembly::GetTypes", ves_icall_System_Reflection_Assembly_GetTypes,
4576 "System.Reflection.Assembly::FillName", ves_icall_System_Reflection_Assembly_FillName,
4577 "System.Reflection.Assembly::InternalGetAssemblyName", ves_icall_System_Reflection_Assembly_InternalGetAssemblyName,
4578 "System.Reflection.Assembly::get_code_base", ves_icall_System_Reflection_Assembly_get_code_base,
4579 "System.Reflection.Assembly::get_location", ves_icall_System_Reflection_Assembly_get_location,
4580 "System.Reflection.Assembly::InternalImageRuntimeVersion", ves_icall_System_Reflection_Assembly_InternalImageRuntimeVersion,
4581 "System.Reflection.Assembly::GetExecutingAssembly", ves_icall_System_Reflection_Assembly_GetExecutingAssembly,
4582 "System.Reflection.Assembly::GetEntryAssembly", ves_icall_System_Reflection_Assembly_GetEntryAssembly,
4583 "System.Reflection.Assembly::GetCallingAssembly", ves_icall_System_Reflection_Assembly_GetCallingAssembly,
4584 "System.Reflection.Assembly::get_EntryPoint", ves_icall_System_Reflection_Assembly_get_EntryPoint,
4585 "System.Reflection.Assembly::GetManifestResourceNames", ves_icall_System_Reflection_Assembly_GetManifestResourceNames,
4586 "System.Reflection.Assembly::GetManifestResourceInternal", ves_icall_System_Reflection_Assembly_GetManifestResourceInternal,
4587 "System.Reflection.Assembly::GetManifestResourceInfoInternal", ves_icall_System_Reflection_Assembly_GetManifestResourceInfoInternal,
4588 "System.Reflection.Assembly::GetFilesInternal", ves_icall_System_Reflection_Assembly_GetFilesInternal,
4589 "System.Reflection.Assembly::GetReferencedAssemblies", ves_icall_System_Reflection_Assembly_GetReferencedAssemblies,
4590 "System.Reflection.Assembly::GetNamespaces", ves_icall_System_Reflection_Assembly_GetNamespaces,
4591 "System.Reflection.Assembly::GetModulesInternal", ves_icall_System_Reflection_Assembly_GetModulesInternal,
4594 * System.Reflection.Module
4596 "System.Reflection.Module::GetGlobalType", ves_icall_System_Reflection_Module_GetGlobalType,
4597 "System.Reflection.Module::GetGuidInternal", ves_icall_System_Reflection_Module_GetGuidInternal,
4598 "System.Reflection.Module::InternalGetTypes", ves_icall_System_Reflection_Module_InternalGetTypes,
4603 "System.MonoType::getFullName", ves_icall_System_MonoType_getFullName,
4604 "System.MonoType::type_from_obj", mono_type_type_from_obj,
4605 "System.MonoType::GetElementType", ves_icall_MonoType_GetElementType,
4606 "System.MonoType::get_type_info", ves_icall_get_type_info,
4607 "System.MonoType::get_BaseType", ves_icall_get_type_parent,
4608 "System.MonoType::get_Module", ves_icall_MonoType_get_Module,
4609 "System.MonoType::IsPointerImpl", ves_icall_type_ispointer,
4610 "System.MonoType::IsPrimitiveImpl", ves_icall_type_isprimitive,
4611 "System.MonoType::IsByRefImpl", ves_icall_type_isbyref,
4612 "System.MonoType::GetField", ves_icall_Type_GetField,
4613 "System.MonoType::GetFields", ves_icall_Type_GetFields,
4614 "System.MonoType::GetMethods", ves_icall_Type_GetMethods,
4615 "System.MonoType::GetConstructors", ves_icall_Type_GetConstructors,
4616 "System.MonoType::GetProperties", ves_icall_Type_GetProperties,
4617 "System.MonoType::GetEvents", ves_icall_Type_GetEvents,
4618 "System.MonoType::InternalGetEvent", ves_icall_MonoType_GetEvent,
4619 "System.MonoType::GetInterfaces", ves_icall_Type_GetInterfaces,
4620 "System.MonoType::GetNestedTypes", ves_icall_Type_GetNestedTypes,
4621 "System.MonoType::GetNestedType", ves_icall_Type_GetNestedType,
4624 * System.Net.Sockets I/O Services
4626 "System.Net.Sockets.Socket::Socket_internal", ves_icall_System_Net_Sockets_Socket_Socket_internal,
4627 "System.Net.Sockets.Socket::Close_internal", ves_icall_System_Net_Sockets_Socket_Close_internal,
4628 "System.Net.Sockets.SocketException::WSAGetLastError_internal", ves_icall_System_Net_Sockets_SocketException_WSAGetLastError_internal,
4629 "System.Net.Sockets.Socket::Available_internal", ves_icall_System_Net_Sockets_Socket_Available_internal,
4630 "System.Net.Sockets.Socket::Blocking_internal", ves_icall_System_Net_Sockets_Socket_Blocking_internal,
4631 "System.Net.Sockets.Socket::Accept_internal", ves_icall_System_Net_Sockets_Socket_Accept_internal,
4632 "System.Net.Sockets.Socket::Listen_internal", ves_icall_System_Net_Sockets_Socket_Listen_internal,
4633 "System.Net.Sockets.Socket::LocalEndPoint_internal", ves_icall_System_Net_Sockets_Socket_LocalEndPoint_internal,
4634 "System.Net.Sockets.Socket::RemoteEndPoint_internal", ves_icall_System_Net_Sockets_Socket_RemoteEndPoint_internal,
4635 "System.Net.Sockets.Socket::Bind_internal", ves_icall_System_Net_Sockets_Socket_Bind_internal,
4636 "System.Net.Sockets.Socket::Connect_internal", ves_icall_System_Net_Sockets_Socket_Connect_internal,
4637 "System.Net.Sockets.Socket::Receive_internal", ves_icall_System_Net_Sockets_Socket_Receive_internal,
4638 "System.Net.Sockets.Socket::RecvFrom_internal", ves_icall_System_Net_Sockets_Socket_RecvFrom_internal,
4639 "System.Net.Sockets.Socket::Send_internal", ves_icall_System_Net_Sockets_Socket_Send_internal,
4640 "System.Net.Sockets.Socket::SendTo_internal", ves_icall_System_Net_Sockets_Socket_SendTo_internal,
4641 "System.Net.Sockets.Socket::Select_internal", ves_icall_System_Net_Sockets_Socket_Select_internal,
4642 "System.Net.Sockets.Socket::Shutdown_internal", ves_icall_System_Net_Sockets_Socket_Shutdown_internal,
4643 "System.Net.Sockets.Socket::GetSocketOption_obj_internal", ves_icall_System_Net_Sockets_Socket_GetSocketOption_obj_internal,
4644 "System.Net.Sockets.Socket::GetSocketOption_arr_internal", ves_icall_System_Net_Sockets_Socket_GetSocketOption_arr_internal,
4645 "System.Net.Sockets.Socket::SetSocketOption_internal", ves_icall_System_Net_Sockets_Socket_SetSocketOption_internal,
4646 "System.Net.Dns::GetHostByName_internal(string,string&,string[]&,string[]&)", ves_icall_System_Net_Dns_GetHostByName_internal,
4647 "System.Net.Dns::GetHostByAddr_internal(string,string&,string[]&,string[]&)", ves_icall_System_Net_Dns_GetHostByAddr_internal,
4648 "System.Net.Dns::GetHostName_internal(string&)", ves_icall_System_Net_Dns_GetHostName_internal,
4653 "System.Char::GetNumericValue", ves_icall_System_Char_GetNumericValue,
4654 "System.Char::GetUnicodeCategory", ves_icall_System_Char_GetUnicodeCategory,
4655 "System.Char::IsControl", ves_icall_System_Char_IsControl,
4656 "System.Char::IsDigit", ves_icall_System_Char_IsDigit,
4657 "System.Char::IsLetter", ves_icall_System_Char_IsLetter,
4658 "System.Char::IsLower", ves_icall_System_Char_IsLower,
4659 "System.Char::IsUpper", ves_icall_System_Char_IsUpper,
4660 "System.Char::IsNumber", ves_icall_System_Char_IsNumber,
4661 "System.Char::IsPunctuation", ves_icall_System_Char_IsPunctuation,
4662 "System.Char::IsSeparator", ves_icall_System_Char_IsSeparator,
4663 "System.Char::IsSurrogate", ves_icall_System_Char_IsSurrogate,
4664 "System.Char::IsSymbol", ves_icall_System_Char_IsSymbol,
4665 "System.Char::IsWhiteSpace", ves_icall_System_Char_IsWhiteSpace,
4666 "System.Char::ToLower", ves_icall_System_Char_ToLower,
4667 "System.Char::ToUpper", ves_icall_System_Char_ToUpper,
4670 * System.Text.Encoding
4672 "System.Text.Encoding::InternalCodePage", ves_icall_System_Text_Encoding_InternalCodePage,
4674 "System.DateTime::GetNow", ves_icall_System_DateTime_GetNow,
4675 "System.CurrentTimeZone::GetTimeZoneData", ves_icall_System_CurrentTimeZone_GetTimeZoneData,
4680 "System.GC::InternalCollect", ves_icall_System_GC_InternalCollect,
4681 "System.GC::GetTotalMemory", ves_icall_System_GC_GetTotalMemory,
4682 "System.GC::KeepAlive", ves_icall_System_GC_KeepAlive,
4683 "System.GC::ReRegisterForFinalize", ves_icall_System_GC_ReRegisterForFinalize,
4684 "System.GC::SuppressFinalize", ves_icall_System_GC_SuppressFinalize,
4685 "System.GC::WaitForPendingFinalizers", ves_icall_System_GC_WaitForPendingFinalizers,
4686 "System.Runtime.InteropServices.GCHandle::GetTarget", ves_icall_System_GCHandle_GetTarget,
4687 "System.Runtime.InteropServices.GCHandle::GetTargetHandle", ves_icall_System_GCHandle_GetTargetHandle,
4688 "System.Runtime.InteropServices.GCHandle::FreeHandle", ves_icall_System_GCHandle_FreeHandle,
4689 "System.Runtime.InteropServices.GCHandle::GetAddrOfPinnedObject", ves_icall_System_GCHandle_GetAddrOfPinnedObject,
4692 * System.Security.Cryptography calls
4695 "System.Security.Cryptography.RNGCryptoServiceProvider::InternalGetBytes", ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_InternalGetBytes,
4696 "System.Security.Cryptography.RNGCryptoServiceProvider::InternalGetNonZeroBytes", ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_InternalGetNonZeroBytes,
4701 "System.Buffer::ByteLengthInternal", ves_icall_System_Buffer_ByteLengthInternal,
4702 "System.Buffer::GetByteInternal", ves_icall_System_Buffer_GetByteInternal,
4703 "System.Buffer::SetByteInternal", ves_icall_System_Buffer_SetByteInternal,
4704 "System.Buffer::BlockCopyInternal", ves_icall_System_Buffer_BlockCopyInternal,
4709 "System.IO.MonoIO::CreateDirectory(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_CreateDirectory,
4710 "System.IO.MonoIO::RemoveDirectory(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_RemoveDirectory,
4711 "System.IO.MonoIO::FindFirstFile(string,System.IO.MonoIOStat&,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_FindFirstFile,
4712 "System.IO.MonoIO::FindNextFile(intptr,System.IO.MonoIOStat&,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_FindNextFile,
4713 "System.IO.MonoIO::FindClose(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_FindClose,
4714 "System.IO.MonoIO::GetCurrentDirectory(System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetCurrentDirectory,
4715 "System.IO.MonoIO::SetCurrentDirectory(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_SetCurrentDirectory,
4716 "System.IO.MonoIO::MoveFile(string,string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_MoveFile,
4717 "System.IO.MonoIO::CopyFile(string,string,bool,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_CopyFile,
4718 "System.IO.MonoIO::DeleteFile(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_DeleteFile,
4719 "System.IO.MonoIO::GetFileAttributes(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetFileAttributes,
4720 "System.IO.MonoIO::SetFileAttributes(string,System.IO.FileAttributes,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_SetFileAttributes,
4721 "System.IO.MonoIO::GetFileType(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetFileType,
4722 "System.IO.MonoIO::GetFileStat(string,System.IO.MonoIOStat&,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetFileStat,
4723 "System.IO.MonoIO::Open(string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Open,
4724 "System.IO.MonoIO::Close(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Close,
4725 "System.IO.MonoIO::Read(intptr,byte[],int,int,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Read,
4726 "System.IO.MonoIO::Write(intptr,byte[],int,int,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Write,
4727 "System.IO.MonoIO::Seek(intptr,long,System.IO.SeekOrigin,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Seek,
4728 "System.IO.MonoIO::GetLength(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetLength,
4729 "System.IO.MonoIO::SetLength(intptr,long,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_SetLength,
4730 "System.IO.MonoIO::SetFileTime(intptr,long,long,long,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_SetFileTime,
4731 "System.IO.MonoIO::Flush(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Flush,
4732 "System.IO.MonoIO::get_ConsoleOutput", ves_icall_System_IO_MonoIO_get_ConsoleOutput,
4733 "System.IO.MonoIO::get_ConsoleInput", ves_icall_System_IO_MonoIO_get_ConsoleInput,
4734 "System.IO.MonoIO::get_ConsoleError", ves_icall_System_IO_MonoIO_get_ConsoleError,
4735 "System.IO.MonoIO::CreatePipe(intptr&,intptr&)", ves_icall_System_IO_MonoIO_CreatePipe,
4736 "System.IO.MonoIO::get_VolumeSeparatorChar", ves_icall_System_IO_MonoIO_get_VolumeSeparatorChar,
4737 "System.IO.MonoIO::get_DirectorySeparatorChar", ves_icall_System_IO_MonoIO_get_DirectorySeparatorChar,
4738 "System.IO.MonoIO::get_AltDirectorySeparatorChar", ves_icall_System_IO_MonoIO_get_AltDirectorySeparatorChar,
4739 "System.IO.MonoIO::get_PathSeparator", ves_icall_System_IO_MonoIO_get_PathSeparator,
4740 "System.IO.MonoIO::get_InvalidPathChars", ves_icall_System_IO_MonoIO_get_InvalidPathChars,
4741 "System.IO.MonoIO::GetTempPath(string&)", ves_icall_System_IO_MonoIO_GetTempPath,
4746 "System.Math::Floor", ves_icall_System_Math_Floor,
4747 "System.Math::Round", ves_icall_System_Math_Round,
4748 "System.Math::Round2", ves_icall_System_Math_Round2,
4749 "System.Math::Sin", ves_icall_System_Math_Sin,
4750 "System.Math::Cos", ves_icall_System_Math_Cos,
4751 "System.Math::Tan", ves_icall_System_Math_Tan,
4752 "System.Math::Sinh", ves_icall_System_Math_Sinh,
4753 "System.Math::Cosh", ves_icall_System_Math_Cosh,
4754 "System.Math::Tanh", ves_icall_System_Math_Tanh,
4755 "System.Math::Acos", ves_icall_System_Math_Acos,
4756 "System.Math::Asin", ves_icall_System_Math_Asin,
4757 "System.Math::Atan", ves_icall_System_Math_Atan,
4758 "System.Math::Atan2", ves_icall_System_Math_Atan2,
4759 "System.Math::Exp", ves_icall_System_Math_Exp,
4760 "System.Math::Log", ves_icall_System_Math_Log,
4761 "System.Math::Log10", ves_icall_System_Math_Log10,
4762 "System.Math::Pow", ves_icall_System_Math_Pow,
4763 "System.Math::Sqrt", ves_icall_System_Math_Sqrt,
4766 * System.Environment
4768 "System.Environment::get_MachineName", ves_icall_System_Environment_get_MachineName,
4769 "System.Environment::get_NewLine", ves_icall_System_Environment_get_NewLine,
4770 "System.Environment::GetEnvironmentVariable", ves_icall_System_Environment_GetEnvironmentVariable,
4771 "System.Environment::GetEnvironmentVariableNames", ves_icall_System_Environment_GetEnvironmentVariableNames,
4772 "System.Environment::GetCommandLineArgs", mono_runtime_get_main_args,
4773 "System.Environment::get_TickCount", ves_icall_System_Environment_get_TickCount,
4774 "System.Environment::Exit", ves_icall_System_Environment_Exit,
4775 "System.Environment::get_Platform", ves_icall_System_Environment_get_Platform,
4776 "System.Environment::get_ExitCode", mono_environment_exitcode_get,
4777 "System.Environment::set_ExitCode", mono_environment_exitcode_set,
4778 "System.Environment::GetMachineConfigPath", ves_icall_System_Configuration_DefaultConfig_get_machine_config_path,
4781 * System.Runtime.Remoting
4783 "System.Runtime.Remoting.RemotingServices::InternalExecute",
4784 ves_icall_InternalExecute,
4785 "System.Runtime.Remoting.RemotingServices::IsTransparentProxy",
4786 ves_icall_IsTransparentProxy,
4789 * System.Runtime.Remoting.Activation
4791 "System.Runtime.Remoting.Activation.ActivationServices::AllocateUninitializedClassInstance",
4792 ves_icall_System_Runtime_Activation_ActivationServices_AllocateUninitializedClassInstance,
4793 "System.Runtime.Remoting.Activation.ActivationServices::EnableProxyActivation",
4794 ves_icall_System_Runtime_Activation_ActivationServices_EnableProxyActivation,
4797 * System.Runtime.Remoting.Messaging
4799 "System.Runtime.Remoting.Messaging.MonoMethodMessage::InitMessage",
4800 ves_icall_MonoMethodMessage_InitMessage,
4803 * System.Runtime.Remoting.Proxies
4805 "System.Runtime.Remoting.Proxies.RealProxy::InternalGetTransparentProxy",
4806 ves_icall_Remoting_RealProxy_GetTransparentProxy,
4809 * System.Threading.Interlocked
4811 "System.Threading.Interlocked::Increment(int&)", ves_icall_System_Threading_Interlocked_Increment_Int,
4812 "System.Threading.Interlocked::Increment(long&)", ves_icall_System_Threading_Interlocked_Increment_Long,
4813 "System.Threading.Interlocked::Decrement(int&)", ves_icall_System_Threading_Interlocked_Decrement_Int,
4814 "System.Threading.Interlocked::Decrement(long&)", ves_icall_System_Threading_Interlocked_Decrement_Long,
4815 "System.Threading.Interlocked::CompareExchange(int&,int,int)", ves_icall_System_Threading_Interlocked_CompareExchange_Int,
4816 "System.Threading.Interlocked::CompareExchange(object&,object,object)", ves_icall_System_Threading_Interlocked_CompareExchange_Object,
4817 "System.Threading.Interlocked::CompareExchange(single&,single,single)", ves_icall_System_Threading_Interlocked_CompareExchange_Single,
4818 "System.Threading.Interlocked::Exchange(int&,int)", ves_icall_System_Threading_Interlocked_Exchange_Int,
4819 "System.Threading.Interlocked::Exchange(object&,object)", ves_icall_System_Threading_Interlocked_Exchange_Object,
4820 "System.Threading.Interlocked::Exchange(single&,single)", ves_icall_System_Threading_Interlocked_Exchange_Single,
4821 "System.Threading.Thread::current_lcid()", ves_icall_System_Threading_Thread_current_lcid,
4824 * System.Diagnostics.Process
4826 "System.Diagnostics.Process::GetProcess_internal(int)", ves_icall_System_Diagnostics_Process_GetProcess_internal,
4827 "System.Diagnostics.Process::GetProcesses_internal()", ves_icall_System_Diagnostics_Process_GetProcesses_internal,
4828 "System.Diagnostics.Process::GetPid_internal()", ves_icall_System_Diagnostics_Process_GetPid_internal,
4829 "System.Diagnostics.Process::Process_free_internal(intptr)", ves_icall_System_Diagnostics_Process_Process_free_internal,
4830 "System.Diagnostics.Process::GetModules_internal()", ves_icall_System_Diagnostics_Process_GetModules_internal,
4831 "System.Diagnostics.Process::Start_internal(string,string,intptr,intptr,intptr,System.Diagnostics.Process/ProcInfo&)", ves_icall_System_Diagnostics_Process_Start_internal,
4832 "System.Diagnostics.Process::WaitForExit_internal(intptr,int)", ves_icall_System_Diagnostics_Process_WaitForExit_internal,
4833 "System.Diagnostics.Process::ExitTime_internal(intptr)", ves_icall_System_Diagnostics_Process_ExitTime_internal,
4834 "System.Diagnostics.Process::StartTime_internal(intptr)", ves_icall_System_Diagnostics_Process_StartTime_internal,
4835 "System.Diagnostics.Process::ExitCode_internal(intptr)", ves_icall_System_Diagnostics_Process_ExitCode_internal,
4836 "System.Diagnostics.Process::ProcessName_internal(intptr)", ves_icall_System_Diagnostics_Process_ProcessName_internal,
4837 "System.Diagnostics.Process::GetWorkingSet_internal(intptr,int&,int&)", ves_icall_System_Diagnostics_Process_GetWorkingSet_internal,
4838 "System.Diagnostics.Process::SetWorkingSet_internal(intptr,int,int,bool)", ves_icall_System_Diagnostics_Process_SetWorkingSet_internal,
4839 "System.Diagnostics.FileVersionInfo::GetVersionInfo_internal(string)", ves_icall_System_Diagnostics_FileVersionInfo_GetVersionInfo_internal,
4844 "System.Delegate::CreateDelegate_internal", ves_icall_System_Delegate_CreateDelegate_internal,
4849 "System.IO.Path::get_temp_path", ves_icall_System_IO_get_temp_path,
4852 * Private icalls for the Mono Debugger
4854 "System.Reflection.Assembly::MonoDebugger_GetMethod",
4855 ves_icall_MonoDebugger_GetMethod,
4857 "System.Reflection.Assembly::MonoDebugger_GetMethodToken",
4858 ves_icall_MonoDebugger_GetMethodToken,
4860 "System.Reflection.Assembly::MonoDebugger_GetLocalTypeFromSignature",
4861 ves_icall_MonoDebugger_GetLocalTypeFromSignature,
4863 "System.Reflection.Assembly::MonoDebugger_GetType",
4864 ves_icall_MonoDebugger_GetType,
4867 * System.Configuration
4869 "System.Configuration.DefaultConfig::get_machine_config_path",
4870 ves_icall_System_Configuration_DefaultConfig_get_machine_config_path,
4873 * System.Diagnostics.DefaultTraceListener
4875 "System.Diagnostics.DefaultTraceListener::WriteWindowsDebugString",
4876 ves_icall_System_Diagnostics_DefaultTraceListener_WriteWindowsDebugString,
4880 "System.Activator::CreateInstanceInternal",
4881 ves_icall_System_Activator_CreateInstanceInternal,
4886 "System.Web.Util.ICalls::GetMachineConfigPath",
4887 ves_icall_System_Configuration_DefaultConfig_get_machine_config_path,
4889 "System.Web.Util.ICalls::GetMachineInstallDirectory",
4890 ves_icall_System_Web_Util_ICalls_get_machine_install_dir,
4893 * System.Globalization
4895 "System.Globalization.CultureInfo::construct_internal_locale(string)", ves_icall_System_Globalization_CultureInfo_construct_internal_locale,
4896 "System.Globalization.CultureInfo::construct_compareinfo(object,string)", ves_icall_System_Globalization_CultureInfo_construct_compareinfo,
4897 "System.Globalization.CompareInfo::internal_compare(string,string,System.Globalization.CompareOptions)", ves_icall_System_Globalization_CompareInfo_internal_compare,
4898 "System.Globalization.CompareInfo::free_internal_collator()", ves_icall_System_Globalization_CompareInfo_free_internal_collator,
4899 "System.Globalization.CompareInfo::assign_sortkey(object,string,System.Globalization.CompareOptions)", ves_icall_System_Globalization_CompareInfo_assign_sortkey,
4900 "System.Globalization.CompareInfo::internal_index(string,int,int,string,System.Globalization.CompareOptions,bool)", ves_icall_System_Globalization_CompareInfo_internal_index,
4901 "System.String::InternalReplace(string,string,System.Globalization.CompareInfo)", ves_icall_System_String_InternalReplace_Str_Comp,
4902 "System.String::InternalToLower(System.Globalization.CultureInfo)", ves_icall_System_String_InternalToLower_Comp,
4903 "System.String::InternalToUpper(System.Globalization.CultureInfo)", ves_icall_System_String_InternalToUpper_Comp,
4906 * add other internal calls here
4909 /* These will be deleted after the next release */
4910 "System.String::InternalEquals", ves_icall_System_String_InternalEquals,
4911 "System.String::InternalIndexOf(char,int,int)", ves_icall_System_String_InternalIndexOf_Char,
4912 "System.String::InternalIndexOf(string,int,int)", ves_icall_System_String_InternalIndexOf_Str,
4913 "System.String::InternalLastIndexOf(char,int,int)", ves_icall_System_String_InternalLastIndexOf_Char,
4914 "System.String::InternalLastIndexOf(string,int,int)", ves_icall_System_String_InternalLastIndexOf_Str,
4915 "System.String::InternalCompare(string,int,string,int,int,int)", ves_icall_System_String_InternalCompareStr_N,
4916 "System.String::InternalReplace(string,string)", ves_icall_System_String_InternalReplace_Str,
4917 "System.String::InternalToLower()", ves_icall_System_String_InternalToLower,
4918 "System.String::InternalToUpper()", ves_icall_System_String_InternalToUpper,
4924 mono_init_icall (void)
4929 while ((name = icall_map [i])) {
4930 mono_add_internal_call (name, icall_map [i+1]);