5 * Dietmar Maurer (dietmar@ximian.com)
6 * Paolo Molaro (lupus@ximian.com)
7 * Patrik Torstensson (patrik.torstensson@labs2.com)
9 * (C) 2001 Ximian, Inc.
19 #if defined (PLATFORM_WIN32)
23 #include <mono/metadata/object.h>
24 #include <mono/metadata/threads.h>
25 #include <mono/metadata/threadpool.h>
26 #include <mono/metadata/monitor.h>
27 #include <mono/metadata/reflection.h>
28 #include <mono/metadata/assembly.h>
29 #include <mono/metadata/tabledefs.h>
30 #include <mono/metadata/exception.h>
31 #include <mono/metadata/file-io.h>
32 #include <mono/metadata/socket-io.h>
33 #include <mono/metadata/mono-endian.h>
34 #include <mono/metadata/tokentype.h>
35 #include <mono/metadata/unicode.h>
36 #include <mono/metadata/appdomain.h>
37 #include <mono/metadata/marshal.h>
38 #include <mono/metadata/gc-internal.h>
39 #include <mono/metadata/rand.h>
40 #include <mono/metadata/sysmath.h>
41 #include <mono/metadata/string-icalls.h>
42 #include <mono/metadata/mono-debug-debugger.h>
43 #include <mono/metadata/process.h>
44 #include <mono/metadata/environment.h>
45 #include <mono/metadata/profiler-private.h>
46 #include <mono/metadata/locales.h>
47 #include <mono/metadata/filewatcher.h>
48 #include <mono/metadata/char-conversions.h>
49 #include <mono/metadata/security.h>
50 #include <mono/metadata/mono-config.h>
51 #include <mono/io-layer/io-layer.h>
52 #include <mono/utils/strtod.h>
53 #include <mono/utils/monobitset.h>
55 #if defined (PLATFORM_WIN32)
61 static MonoReflectionAssembly* ves_icall_System_Reflection_Assembly_GetCallingAssembly (void);
65 * We expect a pointer to a char, not a string
68 mono_double_ParseImpl (char *ptr)
76 result = bsd_strtod (ptr, &endptr);
78 if (!*ptr || (endptr && *endptr))
79 mono_raise_exception (mono_exception_from_name (mono_defaults.corlib,
87 ves_icall_System_Double_AssertEndianity (double *value)
91 MONO_DOUBLE_ASSERT_ENDIANITY (value);
95 ves_icall_System_Array_GetValueImpl (MonoObject *this, guint32 pos)
104 ao = (MonoArray *)this;
105 ac = (MonoClass *)ao->obj.vtable->klass;
107 esize = mono_array_element_size (ac);
108 ea = (gpointer*)((char*)ao->vector + (pos * esize));
110 if (ac->element_class->valuetype)
111 return mono_value_box (this->vtable->domain, ac->element_class, ea);
117 ves_icall_System_Array_GetValue (MonoObject *this, MonoObject *idxs)
125 MONO_CHECK_ARG_NULL (idxs);
127 io = (MonoArray *)idxs;
128 ic = (MonoClass *)io->obj.vtable->klass;
130 ao = (MonoArray *)this;
131 ac = (MonoClass *)ao->obj.vtable->klass;
133 g_assert (ic->rank == 1);
134 if (io->bounds != NULL || io->max_length != ac->rank)
135 mono_raise_exception (mono_get_exception_argument (NULL, NULL));
137 ind = (guint32 *)io->vector;
139 if (ao->bounds == NULL) {
140 if (*ind < 0 || *ind >= ao->max_length)
141 mono_raise_exception (mono_get_exception_index_out_of_range ());
143 return ves_icall_System_Array_GetValueImpl (this, *ind);
146 for (i = 0; i < ac->rank; i++)
147 if ((ind [i] < ao->bounds [i].lower_bound) ||
148 (ind [i] >= ao->bounds [i].length + ao->bounds [i].lower_bound))
149 mono_raise_exception (mono_get_exception_index_out_of_range ());
151 pos = ind [0] - ao->bounds [0].lower_bound;
152 for (i = 1; i < ac->rank; i++)
153 pos = pos*ao->bounds [i].length + ind [i] -
154 ao->bounds [i].lower_bound;
156 return ves_icall_System_Array_GetValueImpl (this, pos);
160 ves_icall_System_Array_SetValueImpl (MonoArray *this, MonoObject *value, guint32 pos)
162 MonoClass *ac, *vc, *ec;
173 vc = value->vtable->klass;
177 ac = this->obj.vtable->klass;
178 ec = ac->element_class;
180 esize = mono_array_element_size (ac);
181 ea = (gpointer*)((char*)this->vector + (pos * esize));
182 va = (gpointer*)((char*)value + sizeof (MonoObject));
185 memset (ea, 0, esize);
189 #define NO_WIDENING_CONVERSION G_STMT_START{\
190 mono_raise_exception (mono_get_exception_argument ( \
191 "value", "not a widening conversion")); \
194 #define CHECK_WIDENING_CONVERSION(extra) G_STMT_START{\
195 if (esize < vsize + (extra)) \
196 mono_raise_exception (mono_get_exception_argument ( \
197 "value", "not a widening conversion")); \
200 #define INVALID_CAST G_STMT_START{\
201 mono_raise_exception (mono_get_exception_invalid_cast ()); \
204 /* Check element (destination) type. */
205 switch (ec->byval_arg.type) {
206 case MONO_TYPE_STRING:
207 switch (vc->byval_arg.type) {
208 case MONO_TYPE_STRING:
214 case MONO_TYPE_BOOLEAN:
215 switch (vc->byval_arg.type) {
216 case MONO_TYPE_BOOLEAN:
229 NO_WIDENING_CONVERSION;
236 if (!ec->valuetype) {
237 if (!mono_object_isinst (value, ec))
239 *ea = (gpointer)value;
243 if (mono_object_isinst (value, ec)) {
244 memcpy (ea, (char *)value + sizeof (MonoObject), esize);
251 vsize = mono_class_instance_size (vc) - sizeof (MonoObject);
254 g_message (G_STRLOC ": %d (%d) <= %d (%d)",
255 ec->byval_arg.type, esize,
256 vc->byval_arg.type, vsize);
259 #define ASSIGN_UNSIGNED(etype) G_STMT_START{\
260 switch (vc->byval_arg.type) { \
265 case MONO_TYPE_CHAR: \
266 CHECK_WIDENING_CONVERSION(0); \
267 *(etype *) ea = (etype) u64; \
269 /* You can't assign a signed value to an unsigned array. */ \
274 /* You can't assign a floating point number to an integer array. */ \
277 NO_WIDENING_CONVERSION; \
281 #define ASSIGN_SIGNED(etype) G_STMT_START{\
282 switch (vc->byval_arg.type) { \
287 CHECK_WIDENING_CONVERSION(0); \
288 *(etype *) ea = (etype) i64; \
290 /* You can assign an unsigned value to a signed array if the array's */ \
291 /* element size is larger than the value size. */ \
296 case MONO_TYPE_CHAR: \
297 CHECK_WIDENING_CONVERSION(1); \
298 *(etype *) ea = (etype) u64; \
300 /* You can't assign a floating point number to an integer array. */ \
303 NO_WIDENING_CONVERSION; \
307 #define ASSIGN_REAL(etype) G_STMT_START{\
308 switch (vc->byval_arg.type) { \
311 CHECK_WIDENING_CONVERSION(0); \
312 *(etype *) ea = (etype) r64; \
314 /* All integer values fit into a floating point array, so we don't */ \
315 /* need to CHECK_WIDENING_CONVERSION here. */ \
320 *(etype *) ea = (etype) i64; \
326 case MONO_TYPE_CHAR: \
327 *(etype *) ea = (etype) u64; \
332 switch (vc->byval_arg.type) {
334 u64 = *(guint8 *) va;
337 u64 = *(guint16 *) va;
340 u64 = *(guint32 *) va;
343 u64 = *(guint64 *) va;
349 i64 = *(gint16 *) va;
352 i64 = *(gint32 *) va;
355 i64 = *(gint64 *) va;
358 r64 = *(gfloat *) va;
361 r64 = *(gdouble *) va;
364 u64 = *(guint16 *) va;
366 case MONO_TYPE_BOOLEAN:
367 /* Boolean is only compatible with itself. */
368 switch (ec->byval_arg.type) {
380 NO_WIDENING_CONVERSION;
387 /* If we can't do a direct copy, let's try a widening conversion. */
388 switch (ec->byval_arg.type) {
390 ASSIGN_UNSIGNED (guint16);
392 ASSIGN_UNSIGNED (guint8);
394 ASSIGN_UNSIGNED (guint16);
396 ASSIGN_UNSIGNED (guint32);
398 ASSIGN_UNSIGNED (guint64);
400 ASSIGN_SIGNED (gint8);
402 ASSIGN_SIGNED (gint16);
404 ASSIGN_SIGNED (gint32);
406 ASSIGN_SIGNED (gint64);
408 ASSIGN_REAL (gfloat);
410 ASSIGN_REAL (gdouble);
414 /* Not reached, INVALID_CAST does not return. Just to avoid a compiler warning ... */
418 #undef NO_WIDENING_CONVERSION
419 #undef CHECK_WIDENING_CONVERSION
420 #undef ASSIGN_UNSIGNED
426 ves_icall_System_Array_SetValue (MonoArray *this, MonoObject *value,
434 MONO_CHECK_ARG_NULL (idxs);
436 ic = idxs->obj.vtable->klass;
437 ac = this->obj.vtable->klass;
439 g_assert (ic->rank == 1);
440 if (idxs->bounds != NULL || idxs->max_length != ac->rank)
441 mono_raise_exception (mono_get_exception_argument (NULL, NULL));
443 ind = (guint32 *)idxs->vector;
445 if (this->bounds == NULL) {
446 if (*ind < 0 || *ind >= this->max_length)
447 mono_raise_exception (mono_get_exception_index_out_of_range ());
449 ves_icall_System_Array_SetValueImpl (this, value, *ind);
453 for (i = 0; i < ac->rank; i++)
454 if ((ind [i] < this->bounds [i].lower_bound) ||
455 (ind [i] >= this->bounds [i].length + this->bounds [i].lower_bound))
456 mono_raise_exception (mono_get_exception_index_out_of_range ());
458 pos = ind [0] - this->bounds [0].lower_bound;
459 for (i = 1; i < ac->rank; i++)
460 pos = pos * this->bounds [i].length + ind [i] -
461 this->bounds [i].lower_bound;
463 ves_icall_System_Array_SetValueImpl (this, value, pos);
467 ves_icall_System_Array_CreateInstanceImpl (MonoReflectionType *type, MonoArray *lengths, MonoArray *bounds)
472 gboolean bounded = FALSE;
476 MONO_CHECK_ARG_NULL (type);
477 MONO_CHECK_ARG_NULL (lengths);
479 MONO_CHECK_ARG (lengths, mono_array_length (lengths) > 0);
481 MONO_CHECK_ARG (bounds, mono_array_length (lengths) == mono_array_length (bounds));
483 for (i = 0; i < mono_array_length (lengths); i++)
484 if (mono_array_get (lengths, gint32, i) < 0)
485 mono_raise_exception (mono_get_exception_argument_out_of_range (NULL));
487 if (bounds && (mono_array_length (bounds) == 1) && (mono_array_get (bounds, gint32, 0) != 0))
488 /* vectors are not the same as one dimensional arrays with no-zero bounds */
493 aklass = mono_bounded_array_class_get (mono_class_from_mono_type (type->type), mono_array_length (lengths), bounded);
495 sizes = alloca (aklass->rank * sizeof(guint32) * 2);
496 for (i = 0; i < aklass->rank; ++i) {
497 sizes [i] = mono_array_get (lengths, gint32, i);
499 sizes [i + aklass->rank] = mono_array_get (bounds, gint32, i);
501 sizes [i + aklass->rank] = 0;
504 array = mono_array_new_full (mono_object_domain (type), aklass, sizes, sizes + aklass->rank);
510 ves_icall_System_Array_GetRank (MonoObject *this)
514 return this->vtable->klass->rank;
518 ves_icall_System_Array_GetLength (MonoArray *this, gint32 dimension)
520 gint32 rank = ((MonoObject *)this)->vtable->klass->rank;
524 if ((dimension < 0) || (dimension >= rank))
525 mono_raise_exception (mono_get_exception_index_out_of_range ());
527 if (this->bounds == NULL)
528 return this->max_length;
530 return this->bounds [dimension].length;
534 ves_icall_System_Array_GetLowerBound (MonoArray *this, gint32 dimension)
536 gint32 rank = ((MonoObject *)this)->vtable->klass->rank;
540 if ((dimension < 0) || (dimension >= rank))
541 mono_raise_exception (mono_get_exception_index_out_of_range ());
543 if (this->bounds == NULL)
546 return this->bounds [dimension].lower_bound;
550 ves_icall_System_Array_FastCopy (MonoArray *source, int source_idx, MonoArray* dest, int dest_idx, int length)
555 MonoClass *src_class;
556 MonoClass *dest_class;
561 if (source->obj.vtable->klass->rank != dest->obj.vtable->klass->rank)
564 if (source->bounds || dest->bounds)
567 if ((dest_idx + length > mono_array_length (dest)) ||
568 (source_idx + length > mono_array_length (source)))
571 element_size = mono_array_element_size (source->obj.vtable->klass);
572 dest_addr = mono_array_addr_with_size (dest, element_size, dest_idx);
573 source_addr = mono_array_addr_with_size (source, element_size, source_idx);
575 src_class = source->obj.vtable->klass->element_class;
576 dest_class = dest->obj.vtable->klass->element_class;
579 * Handle common cases.
582 /* Case1: object[] -> valuetype[] (ArrayList::ToArray) */
583 if (src_class == mono_defaults.object_class && dest_class->valuetype) {
584 for (i = source_idx; i < source_idx + length; ++i) {
585 MonoObject *elem = mono_array_get (source, MonoObject*, i);
586 if (elem && !mono_object_isinst (elem, dest_class))
590 element_size = mono_array_element_size (dest->obj.vtable->klass);
591 for (i = 0; i < length; ++i) {
592 MonoObject *elem = mono_array_get (source, MonoObject*, source_idx + i);
593 void *addr = mono_array_addr_with_size (dest, element_size, dest_idx + i);
595 memset (addr, 0, element_size);
597 memcpy (addr, (char *)elem + sizeof (MonoObject), element_size);
602 if (src_class != dest_class) {
603 if (dest_class->valuetype || dest_class->enumtype || src_class->valuetype || src_class->enumtype)
606 if (mono_class_is_subclass_of (src_class, dest_class, FALSE))
608 /* Case2: object[] -> reftype[] (ArrayList::ToArray) */
609 else if (mono_class_is_subclass_of (dest_class, src_class, FALSE))
610 for (i = source_idx; i < source_idx + length; ++i) {
611 MonoObject *elem = mono_array_get (source, MonoObject*, i);
612 if (elem && !mono_object_isinst (elem, dest_class))
619 memmove (dest_addr, source_addr, element_size * length);
625 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_InitializeArray (MonoArray *array, MonoClassField *field_handle)
627 MonoClass *klass = array->obj.vtable->klass;
628 guint32 size = mono_array_element_size (klass);
633 if (array->bounds == NULL)
634 size *= array->max_length;
636 for (i = 0; i < klass->rank; ++i)
637 size *= array->bounds [i].length;
639 memcpy (mono_array_addr (array, char, 0), field_handle->data, size);
641 #if G_BYTE_ORDER != G_LITTLE_ENDIAN
645 guint ## n *data = (guint ## n *) mono_array_addr (array, char, 0); \
647 for (i = 0; i < size; i += n/8, data++) { \
648 tmp = read ## n (data); \
653 /* printf ("Initialize array with elements of %s type\n", klass->element_class->name); */
655 switch (klass->element_class->byval_arg.type) {
675 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetOffsetToStringData (void)
679 return offsetof (MonoString, chars);
683 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetObjectValue (MonoObject *obj)
687 if ((obj == NULL) || (! (obj->vtable->klass->valuetype)))
690 return mono_object_clone (obj);
694 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_RunClassConstructor (MonoType *handle)
700 MONO_CHECK_ARG_NULL (handle);
702 klass = mono_class_from_mono_type (handle);
703 MONO_CHECK_ARG (handle, klass);
705 /* This will call the type constructor */
706 if (! (klass->flags & TYPE_ATTRIBUTE_INTERFACE))
707 mono_runtime_class_init (mono_class_vtable (mono_domain_get (), klass));
711 ves_icall_System_Object_MemberwiseClone (MonoObject *this)
715 return mono_object_clone (this);
719 #define MONO_OBJECT_ALIGNMENT_SHIFT 3
721 #define MONO_OBJECT_ALIGNMENT_SHIFT 2
725 * Return hashcode based on object address. This function will need to be
726 * smarter in the presence of a moving garbage collector, which will cache
727 * the address hash before relocating the object.
729 * Wang's address-based hash function:
730 * http://www.concentric.net/~Ttwang/tech/addrhash.htm
733 ves_icall_System_Object_GetHashCode (MonoObject *this)
735 register guint32 key;
739 key = (GPOINTER_TO_UINT (this) >> MONO_OBJECT_ALIGNMENT_SHIFT) * 2654435761u;
741 return key & 0x7fffffff;
745 ves_icall_System_ValueType_InternalGetHashCode (MonoObject *this, MonoArray **fields)
749 MonoObject **values = NULL;
756 klass = this->vtable->klass;
758 if (klass->field.count == 0)
759 return ves_icall_System_Object_GetHashCode (this);
762 * Compute the starting value of the hashcode for fields of primitive
763 * types, and return the remaining fields in an array to the managed side.
764 * This way, we can avoid costly reflection operations in managed code.
766 for (i = 0; i < klass->field.count; ++i) {
767 MonoClassField *field = &klass->fields [i];
768 if (field->type->attrs & FIELD_ATTRIBUTE_STATIC)
770 if (mono_field_is_deleted (field))
772 /* FIXME: Add more types */
773 switch (field->type->type) {
775 result ^= *(gint32*)((guint8*)this + field->offset);
777 case MONO_TYPE_STRING: {
779 s = *(MonoString**)((guint8*)this + field->offset);
781 result ^= ves_icall_System_String_GetHashCode (s);
786 values = alloca (klass->field.count * sizeof (MonoObject*));
787 o = mono_field_get_value_object (mono_object_domain (this), field, this);
788 values [count++] = o;
793 *fields = mono_array_new (mono_domain_get (), mono_defaults.object_class, count);
794 memcpy (mono_array_addr (*fields, MonoObject*, 0), values, count * sizeof (MonoObject*));
802 ves_icall_System_ValueType_Equals (MonoObject *this, MonoObject *that, MonoArray **fields)
806 MonoObject **values = NULL;
812 MONO_CHECK_ARG_NULL (that);
814 if (this->vtable != that->vtable)
817 klass = this->vtable->klass;
820 * Do the comparison for fields of primitive type and return a result if
821 * possible. Otherwise, return the remaining fields in an array to the
822 * managed side. This way, we can avoid costly reflection operations in
826 for (i = 0; i < klass->field.count; ++i) {
827 MonoClassField *field = &klass->fields [i];
828 if (field->type->attrs & FIELD_ATTRIBUTE_STATIC)
830 if (mono_field_is_deleted (field))
832 /* FIXME: Add more types */
833 switch (field->type->type) {
835 if (*(gint32*)((guint8*)this + field->offset) != *(gint32*)((guint8*)that + field->offset))
838 case MONO_TYPE_STRING: {
840 guint32 s1len, s2len;
841 s1 = *(MonoString**)((guint8*)this + field->offset);
842 s2 = *(MonoString**)((guint8*)that + field->offset);
845 if ((s1 == NULL) || (s2 == NULL))
847 s1len = mono_string_length (s1);
848 s2len = mono_string_length (s2);
852 if (memcmp (mono_string_chars (s1), mono_string_chars (s2), s1len * sizeof (gunichar2)) != 0)
858 values = alloca (klass->field.count * 2 * sizeof (MonoObject*));
859 o = mono_field_get_value_object (mono_object_domain (this), field, this);
860 values [count++] = o;
861 o = mono_field_get_value_object (mono_object_domain (this), field, that);
862 values [count++] = o;
867 *fields = mono_array_new (mono_domain_get (), mono_defaults.object_class, count);
868 memcpy (mono_array_addr (*fields, MonoObject*, 0), values, count * sizeof (MonoObject*));
876 static MonoReflectionType *
877 ves_icall_System_Object_GetType (MonoObject *obj)
881 if (obj->vtable->klass != mono_defaults.transparent_proxy_class)
882 return mono_type_get_object (mono_object_domain (obj), &obj->vtable->klass->byval_arg);
884 return mono_type_get_object (mono_object_domain (obj), &((MonoTransparentProxy*)obj)->remote_class->proxy_class->byval_arg);
888 mono_type_type_from_obj (MonoReflectionType *mtype, MonoObject *obj)
892 mtype->type = &obj->vtable->klass->byval_arg;
893 g_assert (mtype->type->type);
897 ves_icall_ModuleBuilder_getToken (MonoReflectionModuleBuilder *mb, MonoObject *obj)
901 return mono_image_create_token (mb->dynamic_image, obj);
905 ves_icall_ModuleBuilder_getDataChunk (MonoReflectionModuleBuilder *mb, MonoArray *buf, gint32 offset)
908 MonoDynamicImage *image = mb->dynamic_image;
909 char *p = mono_array_addr (buf, char, 0);
913 mono_image_create_pefile (mb);
915 if (offset >= image->pefile.index)
917 count = mono_array_length (buf);
918 count = MIN (count, image->pefile.index - offset);
920 memcpy (p, image->pefile.data + offset, count);
926 ves_icall_ModuleBuilder_build_metadata (MonoReflectionModuleBuilder *mb)
930 mono_image_build_metadata (mb);
933 static MonoReflectionType *
934 type_from_name (const char *str, MonoBoolean ignoreCase)
936 MonoType *type = NULL;
937 MonoAssembly *assembly;
938 MonoTypeNameParse info;
942 if (!mono_reflection_parse_type (str, &info)) {
943 g_list_free (info.modifiers);
944 g_list_free (info.nested);
948 if (info.assembly.name) {
949 assembly = mono_assembly_load (&info.assembly, NULL, NULL);
951 MonoReflectionAssembly *refass;
953 refass = ves_icall_System_Reflection_Assembly_GetCallingAssembly ();
954 assembly = refass->assembly;
958 type = mono_reflection_get_type (assembly->image, &info, ignoreCase);
960 if (!info.assembly.name && !type) /* try mscorlib */
961 type = mono_reflection_get_type (NULL, &info, ignoreCase);
963 g_list_free (info.modifiers);
964 g_list_free (info.nested);
968 return mono_type_get_object (mono_domain_get (), type);
972 mono_type_get (const char *str)
974 char *copy = g_strdup (str);
975 MonoReflectionType *type = type_from_name (copy, FALSE);
981 static MonoReflectionType*
982 ves_icall_type_from_name (MonoString *name,
983 MonoBoolean throwOnError,
984 MonoBoolean ignoreCase)
986 char *str = mono_string_to_utf8 (name);
987 MonoReflectionType *type;
989 type = type_from_name (str, ignoreCase);
993 mono_raise_exception (mono_get_exception_type_load (name));
1000 static MonoReflectionType*
1001 ves_icall_type_from_handle (MonoType *handle)
1003 MonoDomain *domain = mono_domain_get ();
1004 MonoClass *klass = mono_class_from_mono_type (handle);
1006 MONO_ARCH_SAVE_REGS;
1008 mono_class_init (klass);
1009 return mono_type_get_object (domain, handle);
1013 ves_icall_type_Equals (MonoReflectionType *type, MonoReflectionType *c)
1015 MONO_ARCH_SAVE_REGS;
1017 if (type->type && c->type)
1018 return mono_metadata_type_equal (type->type, c->type);
1019 g_print ("type equals\n");
1023 /* System.TypeCode */
1042 TYPECODE_STRING = 18
1046 ves_icall_type_GetTypeCode (MonoReflectionType *type)
1048 int t = type->type->type;
1050 MONO_ARCH_SAVE_REGS;
1054 case MONO_TYPE_VOID:
1055 return TYPECODE_OBJECT;
1056 case MONO_TYPE_BOOLEAN:
1057 return TYPECODE_BOOLEAN;
1059 return TYPECODE_BYTE;
1061 return TYPECODE_SBYTE;
1063 return TYPECODE_UINT16;
1065 return TYPECODE_INT16;
1066 case MONO_TYPE_CHAR:
1067 return TYPECODE_CHAR;
1071 return TYPECODE_OBJECT;
1073 return TYPECODE_UINT32;
1075 return TYPECODE_INT32;
1077 return TYPECODE_UINT64;
1079 return TYPECODE_INT64;
1081 return TYPECODE_SINGLE;
1083 return TYPECODE_DOUBLE;
1084 case MONO_TYPE_VALUETYPE:
1085 if (type->type->data.klass->enumtype) {
1086 t = type->type->data.klass->enum_basetype->type;
1089 MonoClass *k = type->type->data.klass;
1090 if (strcmp (k->name_space, "System") == 0) {
1091 if (strcmp (k->name, "Decimal") == 0)
1092 return TYPECODE_DECIMAL;
1093 else if (strcmp (k->name, "DateTime") == 0)
1094 return TYPECODE_DATETIME;
1097 return TYPECODE_OBJECT;
1098 case MONO_TYPE_STRING:
1099 return TYPECODE_STRING;
1100 case MONO_TYPE_SZARRAY:
1101 case MONO_TYPE_ARRAY:
1102 case MONO_TYPE_OBJECT:
1104 case MONO_TYPE_MVAR:
1105 return TYPECODE_OBJECT;
1106 case MONO_TYPE_CLASS:
1108 MonoClass *k = type->type->data.klass;
1109 if (strcmp (k->name_space, "System") == 0) {
1110 if (strcmp (k->name, "DBNull") == 0)
1111 return TYPECODE_DBNULL;
1114 return TYPECODE_OBJECT;
1115 case MONO_TYPE_GENERICINST:
1116 return TYPECODE_OBJECT;
1118 g_error ("type 0x%02x not handled in GetTypeCode()", t);
1124 ves_icall_type_is_subtype_of (MonoReflectionType *type, MonoReflectionType *c, MonoBoolean check_interfaces)
1130 MONO_ARCH_SAVE_REGS;
1132 g_assert (type != NULL);
1134 domain = ((MonoObject *)type)->vtable->domain;
1136 if (!c) /* FIXME: dont know what do do here */
1139 klass = mono_class_from_mono_type (type->type);
1140 klassc = mono_class_from_mono_type (c->type);
1142 return mono_class_is_subclass_of (klass, klassc, check_interfaces);
1146 ves_icall_type_is_assignable_from (MonoReflectionType *type, MonoReflectionType *c)
1152 MONO_ARCH_SAVE_REGS;
1154 g_assert (type != NULL);
1156 domain = ((MonoObject *)type)->vtable->domain;
1158 klass = mono_class_from_mono_type (type->type);
1159 klassc = mono_class_from_mono_type (c->type);
1161 return mono_class_is_assignable_from (klass, klassc);
1165 ves_icall_type_IsInstanceOfType (MonoReflectionType *type, MonoObject *obj)
1167 MonoClass *klass = mono_class_from_mono_type (type->type);
1168 return mono_object_isinst (obj, klass) != NULL;
1172 ves_icall_get_attributes (MonoReflectionType *type)
1174 MonoClass *klass = mono_class_from_mono_type (type->type);
1176 MONO_ARCH_SAVE_REGS;
1178 return klass->flags;
1181 static MonoReflectionField*
1182 ves_icall_System_Reflection_FieldInfo_internal_from_handle (MonoClassField *handle)
1184 MONO_ARCH_SAVE_REGS;
1188 return mono_field_get_object (mono_domain_get (), handle->parent, handle);
1192 ves_icall_get_method_info (MonoMethod *method, MonoMethodInfo *info)
1194 MonoDomain *domain = mono_domain_get ();
1196 MONO_ARCH_SAVE_REGS;
1198 info->parent = mono_type_get_object (domain, &method->klass->byval_arg);
1199 info->ret = mono_type_get_object (domain, method->signature->ret);
1200 info->attrs = method->flags;
1201 info->implattrs = method->iflags;
1202 if (method->signature->call_convention == MONO_CALL_DEFAULT)
1205 if (method->signature->call_convention == MONO_CALL_VARARG)
1209 info->callconv |= (method->signature->hasthis << 5) | (method->signature->explicit_this << 6);
1213 ves_icall_get_parameter_info (MonoMethod *method)
1215 MonoDomain *domain = mono_domain_get ();
1217 MONO_ARCH_SAVE_REGS;
1219 return mono_param_get_objects (domain, method);
1222 static MonoReflectionType*
1223 ves_icall_MonoField_GetParentType (MonoReflectionField *field, MonoBoolean declaring)
1226 MONO_ARCH_SAVE_REGS;
1228 parent = declaring? field->field->parent: field->klass;
1230 return mono_type_get_object (mono_object_domain (field), &parent->byval_arg);
1234 ves_icall_MonoField_GetValueInternal (MonoReflectionField *field, MonoObject *obj)
1237 MonoClassField *cf = field->field;
1240 MonoDomain *domain = mono_object_domain (field);
1242 gboolean is_static = FALSE;
1243 gboolean is_ref = FALSE;
1245 MONO_ARCH_SAVE_REGS;
1247 mono_class_init (field->klass);
1249 switch (cf->type->type) {
1250 case MONO_TYPE_STRING:
1251 case MONO_TYPE_OBJECT:
1252 case MONO_TYPE_CLASS:
1253 case MONO_TYPE_ARRAY:
1254 case MONO_TYPE_SZARRAY:
1259 case MONO_TYPE_BOOLEAN:
1262 case MONO_TYPE_CHAR:
1271 case MONO_TYPE_VALUETYPE:
1272 is_ref = cf->type->byref;
1275 g_error ("type 0x%x not handled in "
1276 "ves_icall_Monofield_GetValue", cf->type->type);
1281 if (cf->type->attrs & FIELD_ATTRIBUTE_STATIC) {
1283 vtable = mono_class_vtable (domain, field->klass);
1284 if (!vtable->initialized && !(cf->type->attrs & FIELD_ATTRIBUTE_LITERAL))
1285 mono_runtime_class_init (vtable);
1290 mono_field_static_get_value (vtable, cf, &o);
1292 mono_field_get_value (obj, cf, &o);
1297 /* boxed value type */
1298 klass = mono_class_from_mono_type (cf->type);
1299 o = mono_object_new (domain, klass);
1300 v = ((gchar *) o) + sizeof (MonoObject);
1302 mono_field_static_get_value (vtable, cf, v);
1304 mono_field_get_value (obj, cf, v);
1311 ves_icall_FieldInfo_SetValueInternal (MonoReflectionField *field, MonoObject *obj, MonoObject *value)
1313 MonoClassField *cf = field->field;
1316 MONO_ARCH_SAVE_REGS;
1318 v = (gchar *) value;
1319 if (!cf->type->byref) {
1320 switch (cf->type->type) {
1323 case MONO_TYPE_BOOLEAN:
1326 case MONO_TYPE_CHAR:
1335 case MONO_TYPE_VALUETYPE:
1336 v += sizeof (MonoObject);
1338 case MONO_TYPE_STRING:
1339 case MONO_TYPE_OBJECT:
1340 case MONO_TYPE_CLASS:
1341 case MONO_TYPE_ARRAY:
1342 case MONO_TYPE_SZARRAY:
1346 g_error ("type 0x%x not handled in "
1347 "ves_icall_FieldInfo_SetValueInternal", cf->type->type);
1352 if (cf->type->attrs & FIELD_ATTRIBUTE_STATIC) {
1353 MonoVTable *vtable = mono_class_vtable (mono_object_domain (field), field->klass);
1354 if (!vtable->initialized)
1355 mono_runtime_class_init (vtable);
1356 mono_field_static_set_value (vtable, cf, v);
1358 mono_field_set_value (obj, cf, v);
1362 /* From MonoProperty.cs */
1364 PInfo_Attributes = 1,
1365 PInfo_GetMethod = 1 << 1,
1366 PInfo_SetMethod = 1 << 2,
1367 PInfo_ReflectedType = 1 << 3,
1368 PInfo_DeclaringType = 1 << 4,
1373 ves_icall_get_property_info (MonoReflectionProperty *property, MonoPropertyInfo *info, PInfo req_info)
1375 MonoDomain *domain = mono_object_domain (property);
1377 MONO_ARCH_SAVE_REGS;
1379 if ((req_info & PInfo_ReflectedType) != 0)
1380 info->parent = mono_type_get_object (domain, &property->klass->byval_arg);
1381 else if ((req_info & PInfo_DeclaringType) != 0)
1382 info->parent = mono_type_get_object (domain, &property->property->parent->byval_arg);
1384 if ((req_info & PInfo_Name) != 0)
1385 info->name = mono_string_new (domain, property->property->name);
1387 if ((req_info & PInfo_Attributes) != 0)
1388 info->attrs = property->property->attrs;
1390 if ((req_info & PInfo_GetMethod) != 0)
1391 info->get = property->property->get ?
1392 mono_method_get_object (domain, property->property->get, NULL): NULL;
1394 if ((req_info & PInfo_SetMethod) != 0)
1395 info->set = property->property->set ?
1396 mono_method_get_object (domain, property->property->set, NULL): NULL;
1398 * There may be other methods defined for properties, though, it seems they are not exposed
1399 * in the reflection API
1404 ves_icall_get_event_info (MonoReflectionEvent *event, MonoEventInfo *info)
1406 MonoDomain *domain = mono_object_domain (event);
1408 MONO_ARCH_SAVE_REGS;
1410 info->declaring_type = mono_type_get_object (domain, &event->klass->byval_arg);
1411 info->reflected_type = mono_type_get_object (domain, &event->event->parent->byval_arg);
1413 info->name = mono_string_new (domain, event->event->name);
1414 info->attrs = event->event->attrs;
1415 info->add_method = event->event->add ? mono_method_get_object (domain, event->event->add, NULL): NULL;
1416 info->remove_method = event->event->remove ? mono_method_get_object (domain, event->event->remove, NULL): NULL;
1417 info->raise_method = event->event->raise ? mono_method_get_object (domain, event->event->raise, NULL): NULL;
1421 ves_icall_Type_GetInterfaces (MonoReflectionType* type)
1423 MonoDomain *domain = mono_object_domain (type);
1426 MonoClass *class = mono_class_from_mono_type (type->type);
1428 MonoBitSet *slots = mono_bitset_new (class->max_interface_id + 1, 0);
1430 MONO_ARCH_SAVE_REGS;
1433 /* GetInterfaces() returns an empty array in MS.NET (this may be a bug) */
1434 mono_bitset_free (slots);
1435 return mono_array_new (domain, mono_defaults.monotype_class, 0);
1439 for (parent = class; parent; parent = parent->parent) {
1440 for (i = 0; i < parent->interface_count; ++i) {
1441 if (mono_bitset_test (slots, parent->interfaces [i]->interface_id))
1444 mono_bitset_set (slots, parent->interfaces [i]->interface_id);
1449 intf = mono_array_new (domain, mono_defaults.monotype_class, ninterf);
1451 for (parent = class; parent; parent = parent->parent) {
1452 for (i = 0; i < parent->interface_count; ++i) {
1453 if (!mono_bitset_test (slots, parent->interfaces [i]->interface_id))
1456 mono_bitset_clear (slots, parent->interfaces [i]->interface_id);
1457 mono_array_set (intf, gpointer, ninterf,
1458 mono_type_get_object (domain, &parent->interfaces [i]->byval_arg));
1463 mono_bitset_free (slots);
1468 ves_icall_Type_GetInterfaceMapData (MonoReflectionType *type, MonoReflectionType *iface, MonoArray **targets, MonoArray **methods)
1470 MonoClass *class = mono_class_from_mono_type (type->type);
1471 MonoClass *iclass = mono_class_from_mono_type (iface->type);
1472 MonoReflectionMethod *member;
1473 int i, len, ioffset;
1476 MONO_ARCH_SAVE_REGS;
1478 /* type doesn't implement iface: the exception is thrown in managed code */
1479 if ((iclass->interface_id > class->max_interface_id) || !class->interface_offsets [iclass->interface_id])
1482 len = iclass->method.count;
1483 ioffset = class->interface_offsets [iclass->interface_id];
1484 domain = mono_object_domain (type);
1485 *targets = mono_array_new (domain, mono_defaults.method_info_class, len);
1486 *methods = mono_array_new (domain, mono_defaults.method_info_class, len);
1487 for (i = 0; i < len; ++i) {
1488 member = mono_method_get_object (domain, iclass->methods [i], iclass);
1489 mono_array_set (*methods, gpointer, i, member);
1490 member = mono_method_get_object (domain, class->vtable [i + ioffset], class);
1491 mono_array_set (*targets, gpointer, i, member);
1495 static MonoReflectionType*
1496 ves_icall_MonoType_GetElementType (MonoReflectionType *type)
1498 MonoClass *class = mono_class_from_mono_type (type->type);
1500 MONO_ARCH_SAVE_REGS;
1502 if (type->type->byref)
1503 return mono_type_get_object (mono_object_domain (type), &class->byval_arg);
1504 if (class->enumtype && class->enum_basetype) /* types that are modifierd typebuilkders may not have enum_basetype set */
1505 return mono_type_get_object (mono_object_domain (type), class->enum_basetype);
1506 else if (class->element_class)
1507 return mono_type_get_object (mono_object_domain (type), &class->element_class->byval_arg);
1512 static MonoReflectionType*
1513 ves_icall_get_type_parent (MonoReflectionType *type)
1515 MonoClass *class = mono_class_from_mono_type (type->type);
1517 MONO_ARCH_SAVE_REGS;
1519 return class->parent ? mono_type_get_object (mono_object_domain (type), &class->parent->byval_arg): NULL;
1523 ves_icall_type_ispointer (MonoReflectionType *type)
1525 MONO_ARCH_SAVE_REGS;
1527 return type->type->type == MONO_TYPE_PTR;
1531 ves_icall_type_isprimitive (MonoReflectionType *type)
1533 MONO_ARCH_SAVE_REGS;
1535 return (!type->type->byref && (type->type->type >= MONO_TYPE_BOOLEAN) && (type->type->type <= MONO_TYPE_R8));
1539 ves_icall_type_isbyref (MonoReflectionType *type)
1541 MONO_ARCH_SAVE_REGS;
1543 return type->type->byref;
1546 static MonoReflectionModule*
1547 ves_icall_MonoType_get_Module (MonoReflectionType *type)
1549 MonoClass *class = mono_class_from_mono_type (type->type);
1551 MONO_ARCH_SAVE_REGS;
1553 return mono_module_get_object (mono_object_domain (type), class->image);
1556 static MonoReflectionAssembly*
1557 ves_icall_MonoType_get_Assembly (MonoReflectionType *type)
1559 MonoDomain *domain = mono_domain_get ();
1560 MonoClass *class = mono_class_from_mono_type (type->type);
1562 MONO_ARCH_SAVE_REGS;
1564 return mono_assembly_get_object (domain, class->image->assembly);
1567 static MonoReflectionType*
1568 ves_icall_MonoType_get_DeclaringType (MonoReflectionType *type)
1570 MonoDomain *domain = mono_domain_get ();
1571 MonoClass *class = mono_class_from_mono_type (type->type);
1573 MONO_ARCH_SAVE_REGS;
1575 return class->nested_in ? mono_type_get_object (domain, &class->nested_in->byval_arg) : NULL;
1578 static MonoReflectionType*
1579 ves_icall_MonoType_get_UnderlyingSystemType (MonoReflectionType *type)
1581 MonoDomain *domain = mono_domain_get ();
1582 MonoClass *class = mono_class_from_mono_type (type->type);
1584 MONO_ARCH_SAVE_REGS;
1586 if (class->enumtype && class->enum_basetype) /* types that are modified typebuilders may not have enum_basetype set */
1587 return mono_type_get_object (domain, class->enum_basetype);
1588 else if (class->element_class)
1589 return mono_type_get_object (domain, &class->element_class->byval_arg);
1595 ves_icall_MonoType_get_Name (MonoReflectionType *type)
1597 MonoDomain *domain = mono_domain_get ();
1598 MonoClass *class = mono_class_from_mono_type (type->type);
1600 MONO_ARCH_SAVE_REGS;
1602 return mono_string_new (domain, class->name);
1606 ves_icall_MonoType_get_Namespace (MonoReflectionType *type)
1608 MonoDomain *domain = mono_domain_get ();
1609 MonoClass *class = mono_class_from_mono_type (type->type);
1611 MONO_ARCH_SAVE_REGS;
1613 while (class->nested_in)
1614 class = class->nested_in;
1616 return mono_string_new (domain, class->name_space);
1620 ves_icall_MonoType_GetArrayRank (MonoReflectionType *type)
1622 MonoClass *class = mono_class_from_mono_type (type->type);
1624 MONO_ARCH_SAVE_REGS;
1630 ves_icall_MonoType_GetGenericArguments (MonoReflectionType *type)
1633 MonoClass *klass, *pklass;
1635 MONO_ARCH_SAVE_REGS;
1637 klass = mono_class_from_mono_type (type->type);
1639 if (type->type->byref) {
1640 res = mono_array_new (mono_object_domain (type), mono_defaults.monotype_class, 0);
1641 } else if (klass->gen_params) {
1642 res = mono_array_new (mono_object_domain (type), mono_defaults.monotype_class, klass->num_gen_params);
1643 for (i = 0; i < klass->num_gen_params; ++i) {
1644 pklass = mono_class_from_generic_parameter (&klass->gen_params [i], klass->image, FALSE);
1645 mono_array_set (res, gpointer, i, mono_type_get_object (mono_object_domain (type), &pklass->byval_arg));
1647 } else if (klass->generic_inst) {
1648 MonoGenericInst *inst = klass->generic_inst;
1649 res = mono_array_new (mono_object_domain (type), mono_defaults.monotype_class, inst->type_argc);
1650 for (i = 0; i < inst->type_argc; ++i) {
1651 mono_array_set (res, gpointer, i, mono_type_get_object (mono_object_domain (type), inst->type_argv [i]));
1654 res = mono_array_new (mono_object_domain (type), mono_defaults.monotype_class, 0);
1660 ves_icall_Type_get_IsGenericTypeDefinition (MonoReflectionType *type)
1663 MONO_ARCH_SAVE_REGS;
1665 if (type->type->byref)
1667 klass = mono_class_from_mono_type (type->type);
1669 return klass->gen_params != NULL;
1672 static MonoReflectionType*
1673 ves_icall_Type_GetGenericTypeDefinition_impl (MonoReflectionType *type)
1676 MONO_ARCH_SAVE_REGS;
1678 if (type->type->byref)
1680 klass = mono_class_from_mono_type (type->type);
1681 if (klass->gen_params) {
1682 return type; /* check this one */
1684 if (klass->generic_inst) {
1685 MonoType *generic_type = klass->generic_inst->generic_type;
1686 MonoClass *generic_class = mono_class_from_mono_type (generic_type);
1688 if (generic_class->wastypebuilder && generic_class->reflection_info)
1689 return generic_class->reflection_info;
1691 return mono_type_get_object (mono_object_domain (type), generic_type);
1696 static MonoReflectionType*
1697 ves_icall_Type_BindGenericParameters (MonoReflectionType *type, MonoArray *type_array)
1699 MonoType *geninst, **types;
1702 MONO_ARCH_SAVE_REGS;
1704 if (type->type->byref)
1707 count = mono_array_length (type_array);
1708 types = g_new0 (MonoType *, count);
1710 for (i = 0; i < count; i++) {
1711 MonoReflectionType *t = mono_array_get (type_array, gpointer, i);
1712 types [i] = t->type;
1715 geninst = mono_reflection_bind_generic_parameters (type, count, types);
1717 return mono_type_get_object (mono_object_domain (type), geninst);
1721 ves_icall_Type_get_IsGenericInstance (MonoReflectionType *type)
1724 MONO_ARCH_SAVE_REGS;
1726 if (type->type->byref)
1728 klass = mono_class_from_mono_type (type->type);
1729 return klass->generic_inst != NULL;
1733 ves_icall_Type_GetGenericParameterPosition (MonoReflectionType *type)
1735 MONO_ARCH_SAVE_REGS;
1737 if (type->type->byref)
1739 if (type->type->type == MONO_TYPE_VAR || type->type->type == MONO_TYPE_MVAR)
1740 return type->type->data.generic_param->num;
1745 ves_icall_MonoType_get_HasGenericArguments (MonoReflectionType *type)
1748 MONO_ARCH_SAVE_REGS;
1750 if (type->type->byref)
1752 klass = mono_class_from_mono_type (type->type);
1753 if (klass->gen_params || klass->generic_inst)
1759 ves_icall_MonoType_get_IsGenericParameter (MonoReflectionType *type)
1761 MONO_ARCH_SAVE_REGS;
1763 if (type->type->byref)
1765 if (type->type->type == MONO_TYPE_VAR || type->type->type == MONO_TYPE_MVAR)
1771 ves_icall_TypeBuilder_get_IsGenericParameter (MonoReflectionTypeBuilder *tb)
1773 MONO_ARCH_SAVE_REGS;
1775 if (tb->type.type->byref)
1777 if (tb->type.type->type == MONO_TYPE_VAR || tb->type.type->type == MONO_TYPE_MVAR)
1782 static MonoReflectionType*
1783 ves_icall_MonoGenericInst_GetParentType (MonoReflectionGenericInst *type)
1785 MonoGenericInst *ginst;
1788 MONO_ARCH_SAVE_REGS;
1790 ginst = type->type.type->data.generic_inst;
1791 if (!ginst || !ginst->parent || (ginst->parent->type != MONO_TYPE_GENERICINST))
1794 klass = mono_class_from_mono_type (ginst->parent);
1795 if (!klass->generic_inst && !klass->gen_params)
1798 return mono_type_get_object (mono_object_domain (type), ginst->parent);
1802 ves_icall_MonoGenericInst_GetInterfaces (MonoReflectionGenericInst *type)
1804 static MonoClass *System_Reflection_MonoGenericInst;
1805 MonoGenericInst *ginst;
1811 MONO_ARCH_SAVE_REGS;
1813 if (!System_Reflection_MonoGenericInst) {
1814 System_Reflection_MonoGenericInst = mono_class_from_name (
1815 mono_defaults.corlib, "System.Reflection", "MonoGenericInst");
1816 g_assert (System_Reflection_MonoGenericInst);
1819 domain = mono_object_domain (type);
1821 ginst = type->type.type->data.generic_inst;
1822 if (!ginst || !ginst->ifaces)
1823 return mono_array_new (domain, System_Reflection_MonoGenericInst, 0);
1825 klass = mono_class_from_mono_type (ginst->generic_type);
1827 res = mono_array_new (domain, System_Reflection_MonoGenericInst, ginst->count_ifaces);
1829 for (i = 0; i < ginst->count_ifaces; i++) {
1830 MonoReflectionType *iface = mono_type_get_object (domain, ginst->ifaces [i]);
1832 mono_array_set (res, gpointer, i, iface);
1839 ves_icall_MonoGenericInst_GetMethods (MonoReflectionGenericInst *type,
1840 MonoReflectionType *reflected_type)
1842 MonoGenericInst *ginst;
1843 MonoDynamicGenericInst *dginst;
1845 MonoClass *refclass;
1849 MONO_ARCH_SAVE_REGS;
1851 ginst = type->type.type->data.generic_inst;
1852 g_assert ((dginst = ginst->dynamic_info) != NULL);
1854 refclass = mono_class_from_mono_type (reflected_type->type);
1856 domain = mono_object_domain (type);
1857 res = mono_array_new (domain, mono_defaults.method_info_class, dginst->count_methods);
1859 for (i = 0; i < dginst->count_methods; i++)
1860 mono_array_set (res, gpointer, i,
1861 mono_method_get_object (domain, dginst->methods [i], refclass));
1867 ves_icall_MonoGenericInst_GetConstructors (MonoReflectionGenericInst *type,
1868 MonoReflectionType *reflected_type)
1870 static MonoClass *System_Reflection_ConstructorInfo;
1871 MonoGenericInst *ginst;
1872 MonoDynamicGenericInst *dginst;
1874 MonoClass *refclass;
1878 MONO_ARCH_SAVE_REGS;
1880 if (!System_Reflection_ConstructorInfo)
1881 System_Reflection_ConstructorInfo = mono_class_from_name (
1882 mono_defaults.corlib, "System.Reflection", "ConstructorInfo");
1884 ginst = type->type.type->data.generic_inst;
1885 g_assert ((dginst = ginst->dynamic_info) != NULL);
1887 refclass = mono_class_from_mono_type (reflected_type->type);
1889 domain = mono_object_domain (type);
1890 res = mono_array_new (domain, System_Reflection_ConstructorInfo, dginst->count_ctors);
1892 for (i = 0; i < dginst->count_ctors; i++)
1893 mono_array_set (res, gpointer, i,
1894 mono_method_get_object (domain, dginst->ctors [i], refclass));
1900 ves_icall_MonoGenericInst_GetFields (MonoReflectionGenericInst *type,
1901 MonoReflectionType *reflected_type)
1903 MonoGenericInst *ginst;
1904 MonoDynamicGenericInst *dginst;
1906 MonoClass *refclass;
1910 MONO_ARCH_SAVE_REGS;
1912 ginst = type->type.type->data.generic_inst;
1913 g_assert ((dginst = ginst->dynamic_info) != NULL);
1915 refclass = mono_class_from_mono_type (reflected_type->type);
1917 domain = mono_object_domain (type);
1918 res = mono_array_new (domain, mono_defaults.field_info_class, dginst->count_fields);
1920 for (i = 0; i < dginst->count_fields; i++)
1921 mono_array_set (res, gpointer, i,
1922 mono_field_get_object (domain, refclass, &dginst->fields [i]));
1928 ves_icall_MonoGenericInst_GetProperties (MonoReflectionGenericInst *type,
1929 MonoReflectionType *reflected_type)
1931 static MonoClass *System_Reflection_PropertyInfo;
1932 MonoGenericInst *ginst;
1933 MonoDynamicGenericInst *dginst;
1935 MonoClass *refclass;
1939 MONO_ARCH_SAVE_REGS;
1941 if (!System_Reflection_PropertyInfo)
1942 System_Reflection_PropertyInfo = mono_class_from_name (
1943 mono_defaults.corlib, "System.Reflection", "PropertyInfo");
1945 ginst = type->type.type->data.generic_inst;
1946 g_assert ((dginst = ginst->dynamic_info) != NULL);
1948 refclass = mono_class_from_mono_type (reflected_type->type);
1950 domain = mono_object_domain (type);
1951 res = mono_array_new (domain, System_Reflection_PropertyInfo, dginst->count_properties);
1953 for (i = 0; i < dginst->count_properties; i++)
1954 mono_array_set (res, gpointer, i,
1955 mono_property_get_object (domain, refclass, &dginst->properties [i]));
1961 ves_icall_MonoGenericInst_GetEvents (MonoReflectionGenericInst *type,
1962 MonoReflectionType *reflected_type)
1964 static MonoClass *System_Reflection_EventInfo;
1965 MonoGenericInst *ginst;
1966 MonoDynamicGenericInst *dginst;
1968 MonoClass *refclass;
1972 MONO_ARCH_SAVE_REGS;
1974 if (!System_Reflection_EventInfo)
1975 System_Reflection_EventInfo = mono_class_from_name (
1976 mono_defaults.corlib, "System.Reflection", "EventInfo");
1978 ginst = type->type.type->data.generic_inst;
1979 g_assert ((dginst = ginst->dynamic_info) != NULL);
1981 refclass = mono_class_from_mono_type (reflected_type->type);
1983 domain = mono_object_domain (type);
1984 res = mono_array_new (domain, System_Reflection_EventInfo, dginst->count_events);
1986 for (i = 0; i < dginst->count_events; i++)
1987 mono_array_set (res, gpointer, i,
1988 mono_event_get_object (domain, refclass, &dginst->events [i]));
1993 static MonoReflectionMethod *
1994 ves_icall_MonoType_get_DeclaringMethod (MonoReflectionType *type)
1999 MONO_ARCH_SAVE_REGS;
2001 if (type->type->byref)
2004 method = type->type->data.generic_param->method;
2008 klass = mono_class_from_mono_type (type->type);
2009 return mono_method_get_object (mono_object_domain (type), method, klass);
2012 static MonoReflectionMethod *
2013 ves_icall_MonoMethod_GetGenericMethodDefinition (MonoReflectionMethod *method)
2015 MonoMethodInflated *imethod;
2017 MONO_ARCH_SAVE_REGS;
2019 if (!method->method->signature->is_inflated) {
2020 if (method->method->signature->generic_param_count)
2026 imethod = (MonoMethodInflated *) method->method;
2027 if (imethod->context->gmethod && imethod->context->gmethod->reflection_info)
2028 return imethod->context->gmethod->reflection_info;
2030 return mono_method_get_object (
2031 mono_object_domain (method), imethod->declaring, NULL);
2035 ves_icall_MonoMethod_get_HasGenericParameters (MonoReflectionMethod *method)
2037 MONO_ARCH_SAVE_REGS;
2039 if ((method->method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) ||
2040 (method->method->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL))
2043 return method->method->signature->generic_param_count != 0;
2047 ves_icall_MonoMethod_get_Mono_IsInflatedMethod (MonoReflectionMethod *method)
2049 MONO_ARCH_SAVE_REGS;
2051 if ((method->method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) ||
2052 (method->method->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL))
2055 return method->method->signature->is_inflated;
2059 ves_icall_MonoMethod_get_IsGenericMethodDefinition (MonoReflectionMethod *method)
2061 MONO_ARCH_SAVE_REGS;
2063 if ((method->method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) ||
2064 (method->method->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL))
2067 return method->method->signature->generic_param_count != 0;
2071 ves_icall_MonoMethod_GetGenericArguments (MonoReflectionMethod *method)
2075 MonoMethodNormal *mn;
2077 MONO_ARCH_SAVE_REGS;
2079 domain = mono_object_domain (method);
2081 if ((method->method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) ||
2082 (method->method->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL))
2083 return mono_array_new (domain, mono_defaults.monotype_class, 0);
2085 if (method->method->signature->is_inflated) {
2086 MonoMethodInflated *imethod = (MonoMethodInflated *) method->method;
2087 MonoGenericMethod *gmethod = imethod->context->gmethod;
2090 count = gmethod->mtype_argc;
2091 res = mono_array_new (domain, mono_defaults.monotype_class, count);
2093 for (i = 0; i < count; i++) {
2094 MonoType *t = gmethod->mtype_argv [i];
2096 res, gpointer, i, mono_type_get_object (domain, t));
2103 mn = (MonoMethodNormal *) method->method;
2104 count = method->method->signature->generic_param_count;
2105 res = mono_array_new (domain, mono_defaults.monotype_class, count);
2107 for (i = 0; i < count; i++) {
2108 MonoGenericParam *param = &mn->header->gen_params [i];
2109 MonoClass *pklass = mono_class_from_generic_parameter (
2110 param, method->method->klass->image, TRUE);
2111 mono_array_set (res, gpointer, i,
2112 mono_type_get_object (domain, &pklass->byval_arg));
2119 ves_icall_InternalInvoke (MonoReflectionMethod *method, MonoObject *this, MonoArray *params)
2122 * Invoke from reflection is supposed to always be a virtual call (the API
2123 * is stupid), mono_runtime_invoke_*() calls the provided method, allowing
2124 * greater flexibility.
2126 MonoMethod *m = method->method;
2129 MONO_ARCH_SAVE_REGS;
2132 if (!mono_object_isinst (this, m->klass))
2133 mono_raise_exception (mono_exception_from_name (mono_defaults.corlib, "System.Reflection", "TargetException"));
2134 m = mono_object_get_virtual_method (this, m);
2135 } else if (!(m->flags & METHOD_ATTRIBUTE_STATIC) && strcmp (m->name, ".ctor") && !m->wrapper_type)
2136 mono_raise_exception (mono_exception_from_name (mono_defaults.corlib, "System.Reflection", "TargetException"));
2138 pcount = params? mono_array_length (params): 0;
2139 if (pcount != m->signature->param_count)
2140 mono_raise_exception (mono_exception_from_name (mono_defaults.corlib, "System.Reflection", "TargetParameterCountException"));
2142 if (m->klass->rank && !strcmp (m->name, ".ctor")) {
2145 guint32 *lower_bounds;
2146 pcount = mono_array_length (params);
2147 lengths = alloca (sizeof (guint32) * pcount);
2148 for (i = 0; i < pcount; ++i)
2149 lengths [i] = *(gint32*) ((char*)mono_array_get (params, gpointer, i) + sizeof (MonoObject));
2151 if (m->klass->rank == pcount) {
2152 /* Only lengths provided. */
2153 lower_bounds = NULL;
2155 g_assert (pcount == (m->klass->rank * 2));
2156 /* lower bounds are first. */
2157 lower_bounds = lengths;
2158 lengths += m->klass->rank;
2161 return (MonoObject*)mono_array_new_full (mono_object_domain (params), m->klass, lengths, lower_bounds);
2163 return mono_runtime_invoke_array (m, this, params, NULL);
2167 ves_icall_InternalExecute (MonoReflectionMethod *method, MonoObject *this, MonoArray *params, MonoArray **outArgs)
2169 MonoDomain *domain = mono_object_domain (method);
2170 MonoMethod *m = method->method;
2171 MonoMethodSignature *sig = m->signature;
2172 MonoArray *out_args;
2174 int i, j, outarg_count = 0;
2176 MONO_ARCH_SAVE_REGS;
2178 if (m->klass == mono_defaults.object_class) {
2180 if (!strcmp (m->name, "FieldGetter")) {
2181 MonoClass *k = this->vtable->klass;
2182 MonoString *name = mono_array_get (params, MonoString *, 1);
2185 str = mono_string_to_utf8 (name);
2187 for (i = 0; i < k->field.count; i++) {
2188 if (!strcmp (k->fields [i].name, str)) {
2189 MonoClass *field_klass = mono_class_from_mono_type (k->fields [i].type);
2190 if (field_klass->valuetype)
2191 result = mono_value_box (domain, field_klass,
2192 (char *)this + k->fields [i].offset);
2194 result = *((gpointer *)((char *)this + k->fields [i].offset));
2197 out_args = mono_array_new (domain, mono_defaults.object_class, 1);
2198 *outArgs = out_args;
2199 mono_array_set (out_args, gpointer, 0, result);
2206 g_assert_not_reached ();
2208 } else if (!strcmp (m->name, "FieldSetter")) {
2209 MonoClass *k = this->vtable->klass;
2210 MonoString *name = mono_array_get (params, MonoString *, 1);
2214 str = mono_string_to_utf8 (name);
2216 for (i = 0; i < k->field.count; i++) {
2217 if (!strcmp (k->fields [i].name, str)) {
2218 MonoClass *field_klass = mono_class_from_mono_type (k->fields [i].type);
2219 MonoObject *val = mono_array_get (params, gpointer, 2);
2221 if (field_klass->valuetype) {
2222 size = mono_type_size (k->fields [i].type, &align);
2223 memcpy ((char *)this + k->fields [i].offset,
2224 ((char *)val) + sizeof (MonoObject), size);
2226 *(MonoObject**)((char *)this + k->fields [i].offset) = val;
2228 out_args = mono_array_new (domain, mono_defaults.object_class, 0);
2229 *outArgs = out_args;
2237 g_assert_not_reached ();
2242 for (i = 0; i < mono_array_length (params); i++) {
2243 if (sig->params [i]->byref)
2247 out_args = mono_array_new (domain, mono_defaults.object_class, outarg_count);
2249 /* fixme: handle constructors? */
2250 if (!strcmp (method->method->name, ".ctor"))
2251 g_assert_not_reached ();
2253 result = mono_runtime_invoke_array (method->method, this, params, NULL);
2255 for (i = 0, j = 0; i < mono_array_length (params); i++) {
2256 if (sig->params [i]->byref) {
2258 arg = mono_array_get (params, gpointer, i);
2259 mono_array_set (out_args, gpointer, j, arg);
2264 *outArgs = out_args;
2270 ves_icall_System_Enum_ToObject (MonoReflectionType *type, MonoObject *obj)
2273 MonoClass *enumc, *objc;
2277 MONO_ARCH_SAVE_REGS;
2279 MONO_CHECK_ARG_NULL (type);
2280 MONO_CHECK_ARG_NULL (obj);
2282 domain = mono_object_domain (type);
2283 enumc = mono_class_from_mono_type (type->type);
2284 objc = obj->vtable->klass;
2286 MONO_CHECK_ARG (obj, enumc->enumtype == TRUE);
2287 MONO_CHECK_ARG (obj, (objc->enumtype) || (objc->byval_arg.type >= MONO_TYPE_I1 &&
2288 objc->byval_arg.type <= MONO_TYPE_U8));
2290 s1 = mono_class_value_size (enumc, NULL);
2291 s2 = mono_class_value_size (objc, NULL);
2293 res = mono_object_new (domain, enumc);
2295 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
2296 memcpy ((char *)res + sizeof (MonoObject), (char *)obj + sizeof (MonoObject), MIN (s1, s2));
2298 memcpy ((char *)res + sizeof (MonoObject) + (s1 > s2 ? s1 - s2 : 0),
2299 (char *)obj + sizeof (MonoObject) + (s2 > s1 ? s2 - s1 : 0),
2306 ves_icall_System_Enum_get_value (MonoObject *this)
2314 MONO_ARCH_SAVE_REGS;
2319 g_assert (this->vtable->klass->enumtype);
2321 enumc = mono_class_from_mono_type (this->vtable->klass->enum_basetype);
2322 res = mono_object_new (mono_object_domain (this), enumc);
2323 dst = (char *)res + sizeof (MonoObject);
2324 src = (char *)this + sizeof (MonoObject);
2325 size = mono_class_value_size (enumc, NULL);
2327 memcpy (dst, src, size);
2333 ves_icall_get_enum_info (MonoReflectionType *type, MonoEnumInfo *info)
2335 MonoDomain *domain = mono_object_domain (type);
2336 MonoClass *enumc = mono_class_from_mono_type (type->type);
2337 guint i, j, nvalues, crow;
2338 MonoClassField *field;
2340 MONO_ARCH_SAVE_REGS;
2342 info->utype = mono_type_get_object (domain, enumc->enum_basetype);
2343 nvalues = enumc->field.count - 1;
2344 info->names = mono_array_new (domain, mono_defaults.string_class, nvalues);
2345 info->values = mono_array_new (domain, enumc, nvalues);
2348 for (i = 0, j = 0; i < enumc->field.count; ++i) {
2352 field = &enumc->fields [i];
2353 if (strcmp ("value__", field->name) == 0)
2355 if (mono_field_is_deleted (field))
2357 mono_array_set (info->names, gpointer, j, mono_string_new (domain, field->name));
2358 if (!field->def_value) {
2359 field->def_value = g_new0 (MonoConstant, 1);
2360 crow = mono_metadata_get_constant_index (enumc->image, MONO_TOKEN_FIELD_DEF | (i+enumc->field.first+1), crow + 1);
2361 field->def_value->type = mono_metadata_decode_row_col (&enumc->image->tables [MONO_TABLE_CONSTANT], crow-1, MONO_CONSTANT_TYPE);
2362 crow = mono_metadata_decode_row_col (&enumc->image->tables [MONO_TABLE_CONSTANT], crow-1, MONO_CONSTANT_VALUE);
2363 field->def_value->value = (gpointer)mono_metadata_blob_heap (enumc->image, crow);
2366 p = field->def_value->value;
2367 len = mono_metadata_decode_blob_size (p, &p);
2368 switch (enumc->enum_basetype->type) {
2371 mono_array_set (info->values, gchar, j, *p);
2373 case MONO_TYPE_CHAR:
2376 mono_array_set (info->values, gint16, j, read16 (p));
2380 mono_array_set (info->values, gint32, j, read32 (p));
2384 mono_array_set (info->values, gint64, j, read64 (p));
2387 g_error ("Implement type 0x%02x in get_enum_info", enumc->enum_basetype->type);
2394 BFLAGS_IgnoreCase = 1,
2395 BFLAGS_DeclaredOnly = 2,
2396 BFLAGS_Instance = 4,
2398 BFLAGS_Public = 0x10,
2399 BFLAGS_NonPublic = 0x20,
2400 BFLAGS_FlattenHierarchy = 0x40,
2401 BFLAGS_InvokeMethod = 0x100,
2402 BFLAGS_CreateInstance = 0x200,
2403 BFLAGS_GetField = 0x400,
2404 BFLAGS_SetField = 0x800,
2405 BFLAGS_GetProperty = 0x1000,
2406 BFLAGS_SetProperty = 0x2000,
2407 BFLAGS_ExactBinding = 0x10000,
2408 BFLAGS_SuppressChangeType = 0x20000,
2409 BFLAGS_OptionalParamBinding = 0x40000
2412 static MonoReflectionField *
2413 ves_icall_Type_GetField (MonoReflectionType *type, MonoString *name, guint32 bflags)
2416 MonoClass *startklass, *klass;
2418 MonoClassField *field;
2420 domain = ((MonoObject *)type)->vtable->domain;
2421 klass = startklass = mono_class_from_mono_type (type->type);
2423 MONO_ARCH_SAVE_REGS;
2426 mono_raise_exception (mono_get_exception_argument_null ("name"));
2429 for (i = 0; i < klass->field.count; ++i) {
2431 field = &klass->fields [i];
2432 if (mono_field_is_deleted (field))
2434 if ((field->type->attrs & FIELD_ATTRIBUTE_FIELD_ACCESS_MASK) == FIELD_ATTRIBUTE_PUBLIC) {
2435 if (bflags & BFLAGS_Public)
2438 if (bflags & BFLAGS_NonPublic)
2444 if (field->type->attrs & FIELD_ATTRIBUTE_STATIC) {
2445 if (bflags & BFLAGS_Static)
2446 if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
2449 if (bflags & BFLAGS_Instance)
2456 utf8_name = mono_string_to_utf8 (name);
2458 if (strcmp (field->name, utf8_name)) {
2464 return mono_field_get_object (domain, startklass, field);
2466 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
2473 ves_icall_Type_GetFields_internal (MonoReflectionType *type, guint32 bflags, MonoReflectionType *reftype)
2476 GSList *l = NULL, *tmp;
2477 MonoClass *startklass, *klass, *refklass;
2481 MonoClassField *field;
2483 MONO_ARCH_SAVE_REGS;
2485 domain = ((MonoObject *)type)->vtable->domain;
2486 klass = startklass = mono_class_from_mono_type (type->type);
2487 refklass = mono_class_from_mono_type (reftype->type);
2490 for (i = 0; i < klass->field.count; ++i) {
2492 field = &klass->fields [i];
2493 if (mono_field_is_deleted (field))
2495 if ((field->type->attrs & FIELD_ATTRIBUTE_FIELD_ACCESS_MASK) == FIELD_ATTRIBUTE_PUBLIC) {
2496 if (bflags & BFLAGS_Public)
2499 if (bflags & BFLAGS_NonPublic)
2505 if (field->type->attrs & FIELD_ATTRIBUTE_STATIC) {
2506 if (bflags & BFLAGS_Static)
2507 if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
2510 if (bflags & BFLAGS_Instance)
2516 member = (MonoObject*)mono_field_get_object (domain, refklass, field);
2517 l = g_slist_prepend (l, member);
2519 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
2521 len = g_slist_length (l);
2522 res = mono_array_new (domain, mono_defaults.field_info_class, len);
2524 tmp = l = g_slist_reverse (l);
2525 for (; tmp; tmp = tmp->next, ++i)
2526 mono_array_set (res, gpointer, i, tmp->data);
2532 ves_icall_Type_GetMethodsByName (MonoReflectionType *type, MonoString *name, guint32 bflags, MonoBoolean ignore_case, MonoReflectionType *reftype)
2535 GSList *l = NULL, *tmp;
2536 MonoClass *startklass, *klass, *refklass;
2541 GHashTable *method_slots = g_hash_table_new (NULL, NULL);
2542 gchar *mname = NULL;
2543 int (*compare_func) (const char *s1, const char *s2) = NULL;
2545 MONO_ARCH_SAVE_REGS;
2547 domain = ((MonoObject *)type)->vtable->domain;
2548 klass = startklass = mono_class_from_mono_type (type->type);
2549 refklass = mono_class_from_mono_type (reftype->type);
2552 mname = mono_string_to_utf8 (name);
2553 compare_func = (ignore_case) ? g_strcasecmp : strcmp;
2557 for (i = 0; i < klass->method.count; ++i) {
2559 method = klass->methods [i];
2560 if (strcmp (method->name, ".ctor") == 0 || strcmp (method->name, ".cctor") == 0)
2562 if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
2563 if (bflags & BFLAGS_Public)
2566 if (bflags & BFLAGS_NonPublic)
2572 if (method->flags & METHOD_ATTRIBUTE_STATIC) {
2573 if (bflags & BFLAGS_Static)
2574 if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
2577 if (bflags & BFLAGS_Instance)
2585 if (compare_func (mname, method->name))
2590 if (method->slot != -1) {
2591 if (g_hash_table_lookup (method_slots, GUINT_TO_POINTER (method->slot)))
2593 g_hash_table_insert (method_slots, GUINT_TO_POINTER (method->slot), method);
2596 member = (MonoObject*)mono_method_get_object (domain, method, refklass);
2598 l = g_slist_prepend (l, member);
2601 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
2605 res = mono_array_new (domain, mono_defaults.method_info_class, len);
2608 tmp = l = g_slist_reverse (l);
2610 for (; tmp; tmp = tmp->next, ++i)
2611 mono_array_set (res, gpointer, i, tmp->data);
2613 g_hash_table_destroy (method_slots);
2618 ves_icall_Type_GetConstructors_internal (MonoReflectionType *type, guint32 bflags, MonoReflectionType *reftype)
2621 GSList *l = NULL, *tmp;
2622 static MonoClass *System_Reflection_ConstructorInfo;
2623 MonoClass *startklass, *klass, *refklass;
2629 MONO_ARCH_SAVE_REGS;
2631 domain = ((MonoObject *)type)->vtable->domain;
2632 klass = startklass = mono_class_from_mono_type (type->type);
2633 refklass = mono_class_from_mono_type (reftype->type);
2635 for (i = 0; i < klass->method.count; ++i) {
2637 method = klass->methods [i];
2638 if (strcmp (method->name, ".ctor") && strcmp (method->name, ".cctor"))
2640 if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
2641 if (bflags & BFLAGS_Public)
2644 if (bflags & BFLAGS_NonPublic)
2650 if (method->flags & METHOD_ATTRIBUTE_STATIC) {
2651 if (bflags & BFLAGS_Static)
2652 if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
2655 if (bflags & BFLAGS_Instance)
2661 member = (MonoObject*)mono_method_get_object (domain, method, refklass);
2663 l = g_slist_prepend (l, member);
2665 len = g_slist_length (l);
2666 if (!System_Reflection_ConstructorInfo)
2667 System_Reflection_ConstructorInfo = mono_class_from_name (
2668 mono_defaults.corlib, "System.Reflection", "ConstructorInfo");
2669 res = mono_array_new (domain, System_Reflection_ConstructorInfo, len);
2671 tmp = l = g_slist_reverse (l);
2672 for (; tmp; tmp = tmp->next, ++i)
2673 mono_array_set (res, gpointer, i, tmp->data);
2679 ves_icall_Type_GetPropertiesByName (MonoReflectionType *type, MonoString *name, guint32 bflags, MonoBoolean ignore_case, MonoReflectionType *reftype)
2682 GSList *l = NULL, *tmp;
2683 static MonoClass *System_Reflection_PropertyInfo;
2684 MonoClass *startklass, *klass;
2690 GHashTable *method_slots = g_hash_table_new (NULL, NULL);
2691 gchar *propname = NULL;
2692 int (*compare_func) (const char *s1, const char *s2) = NULL;
2694 MONO_ARCH_SAVE_REGS;
2696 domain = ((MonoObject *)type)->vtable->domain;
2697 klass = startklass = mono_class_from_mono_type (type->type);
2699 propname = mono_string_to_utf8 (name);
2700 compare_func = (ignore_case) ? g_strcasecmp : strcmp;
2704 for (i = 0; i < klass->property.count; ++i) {
2705 prop = &klass->properties [i];
2710 if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
2711 if (bflags & BFLAGS_Public)
2714 if (bflags & BFLAGS_NonPublic)
2720 if (method->flags & METHOD_ATTRIBUTE_STATIC) {
2721 if (bflags & BFLAGS_Static)
2722 if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
2725 if (bflags & BFLAGS_Instance)
2734 if (compare_func (propname, prop->name))
2738 if (prop->get && prop->get->slot != -1) {
2739 if (g_hash_table_lookup (method_slots, GUINT_TO_POINTER (prop->get->slot)))
2741 g_hash_table_insert (method_slots, GUINT_TO_POINTER (prop->get->slot), prop);
2743 if (prop->set && prop->set->slot != -1) {
2744 if (g_hash_table_lookup (method_slots, GUINT_TO_POINTER (prop->set->slot)))
2746 g_hash_table_insert (method_slots, GUINT_TO_POINTER (prop->set->slot), prop);
2749 l = g_slist_prepend (l, mono_property_get_object (domain, startklass, prop));
2752 if ((!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent)))
2756 if (!System_Reflection_PropertyInfo)
2757 System_Reflection_PropertyInfo = mono_class_from_name (
2758 mono_defaults.corlib, "System.Reflection", "PropertyInfo");
2759 res = mono_array_new (domain, System_Reflection_PropertyInfo, len);
2762 tmp = l = g_slist_reverse (l);
2764 for (; tmp; tmp = tmp->next, ++i)
2765 mono_array_set (res, gpointer, i, tmp->data);
2767 g_hash_table_destroy (method_slots);
2771 static MonoReflectionEvent *
2772 ves_icall_MonoType_GetEvent (MonoReflectionType *type, MonoString *name, guint32 bflags)
2775 MonoClass *klass, *startklass;
2781 MONO_ARCH_SAVE_REGS;
2783 event_name = mono_string_to_utf8 (name);
2784 klass = startklass = mono_class_from_mono_type (type->type);
2785 domain = mono_object_domain (type);
2788 for (i = 0; i < klass->event.count; i++) {
2789 event = &klass->events [i];
2790 if (strcmp (event->name, event_name))
2793 method = event->add;
2795 method = event->remove;
2797 if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
2798 if (!(bflags & BFLAGS_Public))
2801 if (!(bflags & BFLAGS_NonPublic))
2805 g_free (event_name);
2806 return mono_event_get_object (domain, startklass, event);
2809 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
2812 g_free (event_name);
2817 ves_icall_Type_GetEvents_internal (MonoReflectionType *type, guint32 bflags, MonoReflectionType *reftype)
2820 GSList *l = NULL, *tmp;
2821 static MonoClass *System_Reflection_EventInfo;
2822 MonoClass *startklass, *klass;
2828 MONO_ARCH_SAVE_REGS;
2830 domain = ((MonoObject *)type)->vtable->domain;
2831 klass = startklass = mono_class_from_mono_type (type->type);
2834 for (i = 0; i < klass->event.count; ++i) {
2835 event = &klass->events [i];
2837 method = event->add;
2839 method = event->remove;
2841 method = event->raise;
2842 if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
2843 if (bflags & BFLAGS_Public)
2846 if (bflags & BFLAGS_NonPublic)
2852 if (method->flags & METHOD_ATTRIBUTE_STATIC) {
2853 if (bflags & BFLAGS_Static)
2854 if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
2857 if (bflags & BFLAGS_Instance)
2864 l = g_slist_prepend (l, mono_event_get_object (domain, klass, event));
2866 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
2868 len = g_slist_length (l);
2869 if (!System_Reflection_EventInfo)
2870 System_Reflection_EventInfo = mono_class_from_name (
2871 mono_defaults.corlib, "System.Reflection", "EventInfo");
2872 res = mono_array_new (domain, System_Reflection_EventInfo, len);
2875 tmp = l = g_slist_reverse (l);
2877 for (; tmp; tmp = tmp->next, ++i)
2878 mono_array_set (res, gpointer, i, tmp->data);
2883 static MonoReflectionType *
2884 ves_icall_Type_GetNestedType (MonoReflectionType *type, MonoString *name, guint32 bflags)
2887 MonoClass *startklass, *klass;
2892 MONO_ARCH_SAVE_REGS;
2894 domain = ((MonoObject *)type)->vtable->domain;
2895 klass = startklass = mono_class_from_mono_type (type->type);
2896 str = mono_string_to_utf8 (name);
2899 for (tmpn = klass->nested_classes; tmpn; tmpn = tmpn->next) {
2901 nested = tmpn->data;
2902 if ((nested->flags & TYPE_ATTRIBUTE_VISIBILITY_MASK) == TYPE_ATTRIBUTE_NESTED_PUBLIC) {
2903 if (bflags & BFLAGS_Public)
2906 if (bflags & BFLAGS_NonPublic)
2911 if (strcmp (nested->name, str) == 0){
2913 return mono_type_get_object (domain, &nested->byval_arg);
2916 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
2923 ves_icall_Type_GetNestedTypes (MonoReflectionType *type, guint32 bflags)
2926 GSList *l = NULL, *tmp;
2928 MonoClass *startklass, *klass;
2934 MONO_ARCH_SAVE_REGS;
2936 domain = ((MonoObject *)type)->vtable->domain;
2937 klass = startklass = mono_class_from_mono_type (type->type);
2939 for (tmpn = klass->nested_classes; tmpn; tmpn = tmpn->next) {
2941 nested = tmpn->data;
2942 if ((nested->flags & TYPE_ATTRIBUTE_VISIBILITY_MASK) == TYPE_ATTRIBUTE_NESTED_PUBLIC) {
2943 if (bflags & BFLAGS_Public)
2946 if (bflags & BFLAGS_NonPublic)
2951 member = (MonoObject*)mono_type_get_object (domain, &nested->byval_arg);
2952 l = g_slist_prepend (l, member);
2954 len = g_slist_length (l);
2955 res = mono_array_new (domain, mono_defaults.monotype_class, len);
2957 tmp = l = g_slist_reverse (l);
2958 for (; tmp; tmp = tmp->next, ++i)
2959 mono_array_set (res, gpointer, i, tmp->data);
2964 static MonoReflectionType*
2965 ves_icall_System_Reflection_Assembly_InternalGetType (MonoReflectionAssembly *assembly, MonoReflectionModule *module, MonoString *name, MonoBoolean throwOnError, MonoBoolean ignoreCase)
2968 MonoType *type = NULL;
2969 MonoTypeNameParse info;
2971 MONO_ARCH_SAVE_REGS;
2973 str = mono_string_to_utf8 (name);
2974 /*g_print ("requested type %s in %s\n", str, assembly->assembly->aname.name);*/
2975 if (!mono_reflection_parse_type (str, &info)) {
2977 g_list_free (info.modifiers);
2978 g_list_free (info.nested);
2979 if (throwOnError) /* uhm: this is a parse error, though... */
2980 mono_raise_exception (mono_get_exception_type_load (name));
2981 /*g_print ("failed parse\n");*/
2985 if (module != NULL) {
2987 type = mono_reflection_get_type (module->image, &info, ignoreCase);
2992 if (assembly->assembly->dynamic) {
2993 /* Enumerate all modules */
2994 MonoReflectionAssemblyBuilder *abuilder = (MonoReflectionAssemblyBuilder*)assembly;
2998 if (abuilder->modules) {
2999 for (i = 0; i < mono_array_length (abuilder->modules); ++i) {
3000 MonoReflectionModuleBuilder *mb = mono_array_get (abuilder->modules, MonoReflectionModuleBuilder*, i);
3001 type = mono_reflection_get_type (&mb->dynamic_image->image, &info, ignoreCase);
3007 if (!type && abuilder->loaded_modules) {
3008 for (i = 0; i < mono_array_length (abuilder->loaded_modules); ++i) {
3009 MonoReflectionModule *mod = mono_array_get (abuilder->loaded_modules, MonoReflectionModule*, i);
3010 type = mono_reflection_get_type (mod->image, &info, ignoreCase);
3017 type = mono_reflection_get_type (assembly->assembly->image, &info, ignoreCase);
3019 g_list_free (info.modifiers);
3020 g_list_free (info.nested);
3023 mono_raise_exception (mono_get_exception_type_load (name));
3024 /* g_print ("failed find\n"); */
3027 /* g_print ("got it\n"); */
3028 return mono_type_get_object (mono_object_domain (assembly), type);
3033 ves_icall_System_Reflection_Assembly_get_code_base (MonoReflectionAssembly *assembly)
3035 MonoDomain *domain = mono_object_domain (assembly);
3036 MonoAssembly *mass = assembly->assembly;
3041 MONO_ARCH_SAVE_REGS;
3043 absolute = g_build_filename (mass->basedir, mass->image->module_name, NULL);
3044 uri = g_filename_to_uri (absolute, NULL, NULL);
3045 res = mono_string_new (domain, uri);
3052 ves_icall_System_Reflection_Assembly_get_global_assembly_cache (MonoReflectionAssembly *assembly)
3054 MonoAssembly *mass = assembly->assembly;
3056 MONO_ARCH_SAVE_REGS;
3058 return mass->in_gac;
3061 static MonoReflectionAssembly*
3062 ves_icall_System_Reflection_Assembly_load_with_partial_name (MonoString *mname, MonoObject *evidence)
3066 MonoImageOpenStatus status;
3068 MONO_ARCH_SAVE_REGS;
3070 name = mono_string_to_utf8 (mname);
3071 res = mono_assembly_load_with_partial_name (name, &status);
3077 return mono_assembly_get_object (mono_domain_get (), res);
3081 ves_icall_System_Reflection_Assembly_get_location (MonoReflectionAssembly *assembly)
3083 MonoDomain *domain = mono_object_domain (assembly);
3085 char *name = g_build_filename (
3086 assembly->assembly->basedir,
3087 assembly->assembly->image->module_name, NULL);
3089 MONO_ARCH_SAVE_REGS;
3091 res = mono_string_new (domain, name);
3097 ves_icall_System_Reflection_Assembly_InternalImageRuntimeVersion (MonoReflectionAssembly *assembly)
3099 MonoDomain *domain = mono_object_domain (assembly);
3101 MONO_ARCH_SAVE_REGS;
3103 return mono_string_new (domain, assembly->assembly->image->version);
3106 static MonoReflectionMethod*
3107 ves_icall_System_Reflection_Assembly_get_EntryPoint (MonoReflectionAssembly *assembly)
3109 guint32 token = mono_image_get_entry_point (assembly->assembly->image);
3111 MONO_ARCH_SAVE_REGS;
3115 return mono_method_get_object (mono_object_domain (assembly), mono_get_method (assembly->assembly->image, token, NULL), NULL);
3119 ves_icall_System_Reflection_Assembly_GetManifestResourceNames (MonoReflectionAssembly *assembly)
3121 MonoTableInfo *table = &assembly->assembly->image->tables [MONO_TABLE_MANIFESTRESOURCE];
3122 MonoArray *result = mono_array_new (mono_object_domain (assembly), mono_defaults.string_class, table->rows);
3126 MONO_ARCH_SAVE_REGS;
3128 for (i = 0; i < table->rows; ++i) {
3129 val = mono_metadata_string_heap (assembly->assembly->image, mono_metadata_decode_row_col (table, i, MONO_MANIFEST_NAME));
3130 mono_array_set (result, gpointer, i, mono_string_new (mono_object_domain (assembly), val));
3136 ves_icall_System_Reflection_Assembly_GetReferencedAssemblies (MonoReflectionAssembly *assembly)
3138 static MonoClass *System_Reflection_AssemblyName;
3141 MonoDomain *domain = mono_object_domain (assembly);
3144 MONO_ARCH_SAVE_REGS;
3146 if (!System_Reflection_AssemblyName)
3147 System_Reflection_AssemblyName = mono_class_from_name (
3148 mono_defaults.corlib, "System.Reflection", "AssemblyName");
3150 for (ptr = assembly->assembly->image->references; ptr && *ptr; ptr++)
3153 result = mono_array_new (mono_object_domain (assembly), System_Reflection_AssemblyName, count);
3155 for (i = 0; i < count; i++) {
3156 MonoAssembly *assem = assembly->assembly->image->references [i];
3157 MonoReflectionAssemblyName *aname;
3158 char *codebase, *absolute;
3160 aname = (MonoReflectionAssemblyName *) mono_object_new (
3161 domain, System_Reflection_AssemblyName);
3163 aname->name = mono_string_new (domain, assem->aname.name);
3165 aname->major = assem->aname.major;
3166 aname->minor = assem->aname.minor;
3167 aname->build = assem->aname.build;
3168 aname->revision = assem->aname.revision;
3170 absolute = g_build_filename (assem->basedir, assem->image->module_name, NULL);
3171 codebase = g_filename_to_uri (absolute, NULL, NULL);
3172 aname->codebase = mono_string_new (domain, codebase);
3175 mono_array_set (result, gpointer, i, aname);
3186 foreach_namespace (const char* key, gconstpointer val, NameSpaceInfo *info)
3188 MonoString *name = mono_string_new (mono_object_domain (info->res), key);
3190 mono_array_set (info->res, gpointer, info->idx, name);
3195 ves_icall_System_Reflection_Assembly_GetNamespaces (MonoReflectionAssembly *assembly)
3197 MonoImage *img = assembly->assembly->image;
3201 MonoTableInfo *t = &img->tables [MONO_TABLE_EXPORTEDTYPE];
3204 MONO_ARCH_SAVE_REGS;
3206 n = g_hash_table_size (img->name_cache);
3207 res = mono_array_new (mono_object_domain (assembly), mono_defaults.string_class, n);
3210 g_hash_table_foreach (img->name_cache, (GHFunc)foreach_namespace, &info);
3212 /* Add namespaces from the EXPORTEDTYPES table as well */
3215 GPtrArray *nspaces = g_ptr_array_new ();
3216 for (i = 0; i < t->rows; ++i) {
3217 const char *nspace = mono_metadata_string_heap (img, mono_metadata_decode_row_col (t, i, MONO_EXP_TYPE_NAMESPACE));
3218 if (!g_hash_table_lookup (img->name_cache, nspace)) {
3219 g_ptr_array_add (nspaces, (char*)nspace);
3222 if (nspaces->len > 0) {
3223 res2 = mono_array_new (mono_object_domain (assembly), mono_defaults.string_class, n + nspaces->len);
3224 memcpy (mono_array_addr (res2, MonoString*, 0),
3225 mono_array_addr (res, MonoString*, 0),
3226 n * sizeof (MonoString*));
3227 for (i = 0; i < nspaces->len; ++i)
3228 mono_array_set (res2, MonoString*, n + i,
3229 mono_string_new (mono_object_domain (assembly),
3230 g_ptr_array_index (nspaces, i)));
3233 g_ptr_array_free (nspaces, TRUE);
3239 /* move this in some file in mono/util/ */
3241 g_concat_dir_and_file (const char *dir, const char *file)
3243 g_return_val_if_fail (dir != NULL, NULL);
3244 g_return_val_if_fail (file != NULL, NULL);
3247 * If the directory name doesn't have a / on the end, we need
3248 * to add one so we get a proper path to the file
3250 if (dir [strlen(dir) - 1] != G_DIR_SEPARATOR)
3251 return g_strconcat (dir, G_DIR_SEPARATOR_S, file, NULL);
3253 return g_strconcat (dir, file, NULL);
3257 ves_icall_System_Reflection_Assembly_GetManifestResourceInternal (MonoReflectionAssembly *assembly, MonoString *name, gint32 *size, MonoReflectionModule **ref_module)
3259 char *n = mono_string_to_utf8 (name);
3260 MonoTableInfo *table = &assembly->assembly->image->tables [MONO_TABLE_MANIFESTRESOURCE];
3262 guint32 cols [MONO_MANIFEST_SIZE];
3263 guint32 impl, file_idx;
3267 MONO_ARCH_SAVE_REGS;
3269 for (i = 0; i < table->rows; ++i) {
3270 mono_metadata_decode_row (table, i, cols, MONO_MANIFEST_SIZE);
3271 val = mono_metadata_string_heap (assembly->assembly->image, cols [MONO_MANIFEST_NAME]);
3272 if (strcmp (val, n) == 0)
3276 if (i == table->rows)
3279 impl = cols [MONO_MANIFEST_IMPLEMENTATION];
3282 * this code should only be called after obtaining the
3283 * ResourceInfo and handling the other cases.
3285 g_assert ((impl & IMPLEMENTATION_MASK) == IMPLEMENTATION_FILE);
3286 file_idx = impl >> IMPLEMENTATION_BITS;
3288 module = mono_image_load_file_for_image (assembly->assembly->image, file_idx);
3293 module = assembly->assembly->image;
3295 *ref_module = mono_module_get_object (mono_domain_get (), module);
3297 return (void*)mono_image_get_resource (module, cols [MONO_MANIFEST_OFFSET], size);
3301 ves_icall_System_Reflection_Assembly_GetManifestResourceInfoInternal (MonoReflectionAssembly *assembly, MonoString *name, MonoManifestResourceInfo *info)
3303 MonoTableInfo *table = &assembly->assembly->image->tables [MONO_TABLE_MANIFESTRESOURCE];
3305 guint32 cols [MONO_MANIFEST_SIZE];
3306 guint32 file_cols [MONO_FILE_SIZE];
3310 MONO_ARCH_SAVE_REGS;
3312 n = mono_string_to_utf8 (name);
3313 for (i = 0; i < table->rows; ++i) {
3314 mono_metadata_decode_row (table, i, cols, MONO_MANIFEST_SIZE);
3315 val = mono_metadata_string_heap (assembly->assembly->image, cols [MONO_MANIFEST_NAME]);
3316 if (strcmp (val, n) == 0)
3320 if (i == table->rows)
3323 if (!cols [MONO_MANIFEST_IMPLEMENTATION]) {
3324 info->location = RESOURCE_LOCATION_EMBEDDED | RESOURCE_LOCATION_IN_MANIFEST;
3327 switch (cols [MONO_MANIFEST_IMPLEMENTATION] & IMPLEMENTATION_MASK) {
3328 case IMPLEMENTATION_FILE:
3329 i = cols [MONO_MANIFEST_IMPLEMENTATION] >> IMPLEMENTATION_BITS;
3330 table = &assembly->assembly->image->tables [MONO_TABLE_FILE];
3331 mono_metadata_decode_row (table, i - 1, file_cols, MONO_FILE_SIZE);
3332 val = mono_metadata_string_heap (assembly->assembly->image, file_cols [MONO_FILE_NAME]);
3333 info->filename = mono_string_new (mono_object_domain (assembly), val);
3334 if (file_cols [MONO_FILE_FLAGS] && FILE_CONTAINS_NO_METADATA)
3337 info->location = RESOURCE_LOCATION_EMBEDDED;
3340 case IMPLEMENTATION_ASSEMBLYREF:
3341 i = cols [MONO_MANIFEST_IMPLEMENTATION] >> IMPLEMENTATION_BITS;
3342 info->assembly = mono_assembly_get_object (mono_domain_get (), assembly->assembly->image->references [i - 1]);
3344 /* Obtain info recursively */
3345 ves_icall_System_Reflection_Assembly_GetManifestResourceInfoInternal (info->assembly, name, info);
3346 info->location |= RESOURCE_LOCATION_ANOTHER_ASSEMBLY;
3349 case IMPLEMENTATION_EXP_TYPE:
3350 g_assert_not_reached ();
3359 ves_icall_System_Reflection_Assembly_GetFilesInternal (MonoReflectionAssembly *assembly, MonoString *name)
3361 MonoTableInfo *table = &assembly->assembly->image->tables [MONO_TABLE_FILE];
3362 MonoArray *result = NULL;
3367 MONO_ARCH_SAVE_REGS;
3369 /* check hash if needed */
3371 n = mono_string_to_utf8 (name);
3372 for (i = 0; i < table->rows; ++i) {
3373 val = mono_metadata_string_heap (assembly->assembly->image, mono_metadata_decode_row_col (table, i, MONO_FILE_NAME));
3374 if (strcmp (val, n) == 0) {
3377 n = g_concat_dir_and_file (assembly->assembly->basedir, val);
3378 fn = mono_string_new (mono_object_domain (assembly), n);
3380 return (MonoObject*)fn;
3387 for (i = 0; i < table->rows; ++i) {
3388 result = mono_array_new (mono_object_domain (assembly), mono_defaults.string_class, table->rows);
3389 val = mono_metadata_string_heap (assembly->assembly->image, mono_metadata_decode_row_col (table, i, MONO_FILE_NAME));
3390 n = g_concat_dir_and_file (assembly->assembly->basedir, val);
3391 mono_array_set (result, gpointer, i, mono_string_new (mono_object_domain (assembly), n));
3394 return (MonoObject*)result;
3398 ves_icall_System_Reflection_Assembly_GetModulesInternal (MonoReflectionAssembly *assembly)
3400 MonoDomain *domain = mono_domain_get();
3403 int i, module_count = 0, file_count = 0;
3404 MonoImage **modules = assembly->assembly->image->modules;
3405 MonoTableInfo *table;
3408 while (modules[module_count])
3412 table = &assembly->assembly->image->tables [MONO_TABLE_FILE];
3413 file_count = table->rows;
3415 g_assert( assembly->assembly->image != NULL);
3418 klass = mono_class_from_name ( mono_defaults.corlib, "System.Reflection", "Module");
3419 res = mono_array_new (domain, klass, module_count + file_count);
3421 mono_array_set (res, gpointer, 0, mono_module_get_object (domain, assembly->assembly->image));
3422 for ( i = 1; i < module_count; ++i )
3423 mono_array_set (res, gpointer, i, mono_module_get_object (domain, modules[i]));
3425 for (i = 0; i < table->rows; ++i)
3426 mono_array_set (res, gpointer, module_count + i, mono_module_file_get_object (domain, assembly->assembly->image, i));
3431 static MonoReflectionMethod*
3432 ves_icall_GetCurrentMethod (void)
3434 MonoMethod *m = mono_method_get_last_managed ();
3436 MONO_ARCH_SAVE_REGS;
3438 return mono_method_get_object (mono_domain_get (), m, NULL);
3441 static MonoReflectionAssembly*
3442 ves_icall_System_Reflection_Assembly_GetExecutingAssembly (void)
3444 MonoMethod *m = mono_method_get_last_managed ();
3446 MONO_ARCH_SAVE_REGS;
3448 return mono_assembly_get_object (mono_domain_get (), m->klass->image->assembly);
3453 get_caller (MonoMethod *m, gint32 no, gint32 ilo, gboolean managed, gpointer data)
3455 MonoMethod **dest = data;
3457 /* skip unmanaged frames */
3472 static MonoReflectionAssembly*
3473 ves_icall_System_Reflection_Assembly_GetEntryAssembly (void)
3475 MonoDomain* domain = mono_domain_get ();
3477 MONO_ARCH_SAVE_REGS;
3479 if (!domain->entry_assembly)
3480 domain = mono_root_domain;
3482 return mono_assembly_get_object (domain, domain->entry_assembly);
3486 static MonoReflectionAssembly*
3487 ves_icall_System_Reflection_Assembly_GetCallingAssembly (void)
3489 MonoMethod *m = mono_method_get_last_managed ();
3490 MonoMethod *dest = m;
3492 MONO_ARCH_SAVE_REGS;
3494 mono_stack_walk (get_caller, &dest);
3497 return mono_assembly_get_object (mono_domain_get (), dest->klass->image->assembly);
3501 ves_icall_System_MonoType_getFullName (MonoReflectionType *object)
3503 MonoDomain *domain = mono_object_domain (object);
3507 MONO_ARCH_SAVE_REGS;
3509 name = mono_type_get_name (object->type);
3510 res = mono_string_new (domain, name);
3517 fill_reflection_assembly_name (MonoDomain *domain, MonoReflectionAssemblyName *aname, MonoAssemblyName *name, const char *absolute)
3519 static MonoMethod *create_culture = NULL;
3522 const char *pkey_ptr;
3525 MONO_ARCH_SAVE_REGS;
3527 aname->name = mono_string_new (domain, name->name);
3528 aname->major = name->major;
3529 aname->minor = name->minor;
3530 aname->build = name->build;
3531 aname->revision = name->revision;
3532 aname->hashalg = name->hash_alg;
3534 codebase = g_filename_to_uri (absolute, NULL, NULL);
3536 aname->codebase = mono_string_new (domain, codebase);
3540 if (!create_culture) {
3541 MonoMethodDesc *desc = mono_method_desc_new ("System.Globalization.CultureInfo:CreateSpecificCulture(string)", TRUE);
3542 create_culture = mono_method_desc_search_in_image (desc, mono_defaults.corlib);
3543 g_assert (create_culture);
3544 mono_method_desc_free (desc);
3547 args [0] = mono_string_new (domain, name->culture);
3548 aname->cultureInfo =
3549 mono_runtime_invoke (create_culture, NULL, args, NULL);
3551 if (name->public_key) {
3552 pkey_ptr = name->public_key;
3553 pkey_len = mono_metadata_decode_blob_size (pkey_ptr, &pkey_ptr);
3555 aname->publicKey = mono_array_new (domain, mono_defaults.byte_class, pkey_len);
3556 memcpy (mono_array_addr (aname->publicKey, guint8, 0), pkey_ptr, pkey_len);
3561 ves_icall_System_Reflection_Assembly_FillName (MonoReflectionAssembly *assembly, MonoReflectionAssemblyName *aname)
3565 MONO_ARCH_SAVE_REGS;
3567 absolute = g_build_filename (assembly->assembly->basedir, assembly->assembly->image->module_name, NULL);
3569 fill_reflection_assembly_name (mono_object_domain (assembly), aname,
3570 &assembly->assembly->aname, absolute);
3576 ves_icall_System_Reflection_Assembly_InternalGetAssemblyName (MonoString *fname, MonoReflectionAssemblyName *aname)
3579 MonoImageOpenStatus status = MONO_IMAGE_OK;
3582 MonoAssemblyName name;
3584 MONO_ARCH_SAVE_REGS;
3586 filename = mono_string_to_utf8 (fname);
3588 image = mono_image_open (filename, &status);
3594 exc = mono_get_exception_file_not_found (fname);
3595 mono_raise_exception (exc);
3598 res = mono_assembly_fill_assembly_name (image, &name);
3600 mono_image_close (image);
3602 mono_raise_exception (mono_get_exception_argument ("assemblyFile", "The file does not contain a manifest"));
3605 fill_reflection_assembly_name (mono_domain_get (), aname, &name, filename);
3608 mono_image_close (image);
3612 mono_module_get_types (MonoDomain *domain, MonoImage *image,
3613 MonoBoolean exportedOnly)
3617 MonoTableInfo *tdef = &image->tables [MONO_TABLE_TYPEDEF];
3619 guint32 attrs, visibility;
3621 /* we start the count from 1 because we skip the special type <Module> */
3624 for (i = 1; i < tdef->rows; ++i) {
3625 attrs = mono_metadata_decode_row_col (tdef, i, MONO_TYPEDEF_FLAGS);
3626 visibility = attrs & TYPE_ATTRIBUTE_VISIBILITY_MASK;
3627 if (visibility == TYPE_ATTRIBUTE_PUBLIC || visibility == TYPE_ATTRIBUTE_NESTED_PUBLIC)
3631 count = tdef->rows - 1;
3633 res = mono_array_new (domain, mono_defaults.monotype_class, count);
3635 for (i = 1; i < tdef->rows; ++i) {
3636 attrs = mono_metadata_decode_row_col (tdef, i, MONO_TYPEDEF_FLAGS);
3637 visibility = attrs & TYPE_ATTRIBUTE_VISIBILITY_MASK;
3638 if (!exportedOnly || (visibility == TYPE_ATTRIBUTE_PUBLIC || visibility == TYPE_ATTRIBUTE_NESTED_PUBLIC)) {
3639 klass = mono_class_get (image, (i + 1) | MONO_TOKEN_TYPE_DEF);
3640 mono_array_set (res, gpointer, count, mono_type_get_object (domain, &klass->byval_arg));
3649 ves_icall_System_Reflection_Assembly_GetTypes (MonoReflectionAssembly *assembly, MonoBoolean exportedOnly)
3652 MonoImage *image = assembly->assembly->image;
3653 MonoTableInfo *table = &image->tables [MONO_TABLE_FILE];
3657 MONO_ARCH_SAVE_REGS;
3659 domain = mono_object_domain (assembly);
3660 res = mono_module_get_types (domain, image, exportedOnly);
3662 /* Append data from all modules in the assembly */
3663 for (i = 0; i < table->rows; ++i) {
3664 if (!(mono_metadata_decode_row_col (table, i, MONO_FILE_FLAGS) & FILE_CONTAINS_NO_METADATA)) {
3665 MonoImage *loaded_image = mono_assembly_load_module (image->assembly, i + 1);
3667 MonoArray *res2 = mono_module_get_types (domain, loaded_image, exportedOnly);
3668 /* Append the new types to the end of the array */
3669 if (mono_array_length (res2) > 0) {
3673 len1 = mono_array_length (res);
3674 len2 = mono_array_length (res2);
3675 res3 = mono_array_new (domain, mono_defaults.monotype_class, len1 + len2);
3676 memcpy (mono_array_addr (res3, MonoReflectionType*, 0),
3677 mono_array_addr (res, MonoReflectionType*, 0),
3678 len1 * sizeof (MonoReflectionType*));
3679 memcpy (mono_array_addr (res3, MonoReflectionType*, len1),
3680 mono_array_addr (res2, MonoReflectionType*, 0),
3681 len2 * sizeof (MonoReflectionType*));
3691 static MonoReflectionType*
3692 ves_icall_System_Reflection_Module_GetGlobalType (MonoReflectionModule *module)
3694 MonoDomain *domain = mono_object_domain (module);
3697 MONO_ARCH_SAVE_REGS;
3699 g_assert (module->image);
3700 klass = mono_class_get (module->image, 1 | MONO_TOKEN_TYPE_DEF);
3701 return mono_type_get_object (domain, &klass->byval_arg);
3705 ves_icall_System_Reflection_Module_Close (MonoReflectionModule *module)
3708 mono_image_close (module->image);
3712 ves_icall_System_Reflection_Module_GetGuidInternal (MonoReflectionModule *module)
3714 MonoDomain *domain = mono_object_domain (module);
3716 MONO_ARCH_SAVE_REGS;
3718 g_assert (module->image);
3719 return mono_string_new (domain, module->image->guid);
3723 ves_icall_System_Reflection_Module_InternalGetTypes (MonoReflectionModule *module)
3725 MONO_ARCH_SAVE_REGS;
3728 return mono_array_new (mono_object_domain (module), mono_defaults.monotype_class, 0);
3730 return mono_module_get_types (mono_object_domain (module), module->image, FALSE);
3733 static MonoReflectionType*
3734 ves_icall_ModuleBuilder_create_modified_type (MonoReflectionTypeBuilder *tb, MonoString *smodifiers)
3737 int isbyref = 0, rank;
3738 char *str = mono_string_to_utf8 (smodifiers);
3741 MONO_ARCH_SAVE_REGS;
3743 klass = mono_class_from_mono_type (tb->type.type);
3745 /* logic taken from mono_reflection_parse_type(): keep in sync */
3749 if (isbyref) { /* only one level allowed by the spec */
3756 return mono_type_get_object (mono_object_domain (tb), &klass->this_arg);
3759 klass = mono_ptr_class_get (&klass->byval_arg);
3760 mono_class_init (klass);
3771 else if (*p != '*') { /* '*' means unknown lower bound */
3782 klass = mono_array_class_get (klass, rank);
3783 mono_class_init (klass);
3790 return mono_type_get_object (mono_object_domain (tb), &klass->byval_arg);
3794 ves_icall_Type_IsArrayImpl (MonoReflectionType *t)
3799 MONO_ARCH_SAVE_REGS;
3802 res = !type->byref && (type->type == MONO_TYPE_ARRAY || type->type == MONO_TYPE_SZARRAY);
3807 static MonoReflectionType *
3808 ves_icall_Type_make_array_type (MonoReflectionType *type, int rank)
3810 MonoClass *klass, *aklass;
3812 MONO_ARCH_SAVE_REGS;
3814 klass = mono_class_from_mono_type (type->type);
3815 aklass = mono_array_class_get (klass, rank);
3817 return mono_type_get_object (mono_object_domain (type), &aklass->byval_arg);
3820 static MonoReflectionType *
3821 ves_icall_Type_make_byref_type (MonoReflectionType *type)
3825 MONO_ARCH_SAVE_REGS;
3827 klass = mono_class_from_mono_type (type->type);
3829 return mono_type_get_object (mono_object_domain (type), &klass->this_arg);
3833 ves_icall_System_Delegate_CreateDelegate_internal (MonoReflectionType *type, MonoObject *target,
3834 MonoReflectionMethod *info)
3836 MonoClass *delegate_class = mono_class_from_mono_type (type->type);
3837 MonoObject *delegate;
3840 MONO_ARCH_SAVE_REGS;
3842 mono_assert (delegate_class->parent == mono_defaults.multicastdelegate_class);
3844 delegate = mono_object_new (mono_object_domain (type), delegate_class);
3846 func = mono_compile_method (info->method);
3848 mono_delegate_ctor (delegate, target, func);
3854 * Magic number to convert a time which is relative to
3855 * Jan 1, 1970 into a value which is relative to Jan 1, 0001.
3857 #define EPOCH_ADJUST ((guint64)62135596800LL)
3860 * Magic number to convert FILETIME base Jan 1, 1601 to DateTime - base Jan, 1, 0001
3862 #define FILETIME_ADJUST ((guint64)504911232000000000LL)
3865 * This returns Now in UTC
3868 ves_icall_System_DateTime_GetNow (void)
3870 #ifdef PLATFORM_WIN32
3874 GetSystemTime (&st);
3875 SystemTimeToFileTime (&st, &ft);
3876 return (gint64) FILETIME_ADJUST + ((((gint64)ft.dwHighDateTime)<<32) | ft.dwLowDateTime);
3878 /* FIXME: put this in io-layer and call it GetLocalTime */
3882 MONO_ARCH_SAVE_REGS;
3884 if (gettimeofday (&tv, NULL) == 0) {
3885 res = (((gint64)tv.tv_sec + EPOCH_ADJUST)* 1000000 + tv.tv_usec)*10;
3888 /* fixme: raise exception */
3893 #ifdef PLATFORM_WIN32
3894 /* convert a SYSTEMTIME which is of the form "last thursday in october" to a real date */
3896 convert_to_absolute_date(SYSTEMTIME *date)
3898 #define IS_LEAP(y) ((y % 4) == 0 && ((y % 100) != 0 || (y % 400) == 0))
3899 static int days_in_month[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
3900 static int leap_days_in_month[] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
3901 /* from the calendar FAQ */
3902 int a = (14 - date->wMonth) / 12;
3903 int y = date->wYear - a;
3904 int m = date->wMonth + 12 * a - 2;
3905 int d = (1 + y + y/4 - y/100 + y/400 + (31*m)/12) % 7;
3907 /* d is now the day of the week for the first of the month (0 == Sunday) */
3909 int day_of_week = date->wDayOfWeek;
3911 /* set day_in_month to the first day in the month which falls on day_of_week */
3912 int day_in_month = 1 + (day_of_week - d);
3913 if (day_in_month <= 0)
3916 /* wDay is 1 for first weekday in month, 2 for 2nd ... 5 means last - so work that out allowing for days in the month */
3917 date->wDay = day_in_month + (date->wDay - 1) * 7;
3918 if (date->wDay > (IS_LEAP(date->wYear) ? leap_days_in_month[date->wMonth - 1] : days_in_month[date->wMonth - 1]))
3923 #ifndef PLATFORM_WIN32
3925 * Return's the offset from GMT of a local time.
3927 * tm is a local time
3928 * t is the same local time as seconds.
3931 gmt_offset(struct tm *tm, time_t t)
3933 #if defined (HAVE_TM_GMTOFF)
3934 return tm->tm_gmtoff;
3939 g.tm_isdst = tm->tm_isdst;
3941 return (int)difftime(t, t2);
3946 * This is heavily based on zdump.c from glibc 2.2.
3948 * * data[0]: start of daylight saving time (in DateTime ticks).
3949 * * data[1]: end of daylight saving time (in DateTime ticks).
3950 * * data[2]: utcoffset (in TimeSpan ticks).
3951 * * data[3]: additional offset when daylight saving (in TimeSpan ticks).
3952 * * name[0]: name of this timezone when not daylight saving.
3953 * * name[1]: name of this timezone when daylight saving.
3955 * FIXME: This only works with "standard" Unix dates (years between 1900 and 2100) while
3956 * the class library allows years between 1 and 9999.
3958 * Returns true on success and zero on failure.
3961 ves_icall_System_CurrentTimeZone_GetTimeZoneData (guint32 year, MonoArray **data, MonoArray **names)
3963 #ifndef PLATFORM_WIN32
3964 MonoDomain *domain = mono_domain_get ();
3965 struct tm start, tt;
3969 int is_daylight = 0, day;
3972 MONO_ARCH_SAVE_REGS;
3974 MONO_CHECK_ARG_NULL (data);
3975 MONO_CHECK_ARG_NULL (names);
3977 (*data) = mono_array_new (domain, mono_defaults.int64_class, 4);
3978 (*names) = mono_array_new (domain, mono_defaults.string_class, 2);
3981 * no info is better than crashing: we'll need our own tz data to make
3982 * this work properly, anyway. The range is reduced to 1970 .. 2037 because
3983 * that is what mktime is guaranteed to support (we get into an infinite loop
3986 if ((year < 1970) || (year > 2037)) {
3988 tt = *localtime (&t);
3989 strftime (tzone, sizeof (tzone), "%Z", &tt);
3990 mono_array_set ((*names), gpointer, 0, mono_string_new (domain, tzone));
3991 mono_array_set ((*names), gpointer, 1, mono_string_new (domain, tzone));
3995 memset (&start, 0, sizeof (start));
3998 start.tm_year = year-1900;
4000 t = mktime (&start);
4001 gmtoff = gmt_offset (&start, t);
4003 /* For each day of the year, calculate the tm_gmtoff. */
4004 for (day = 0; day < 365; day++) {
4007 tt = *localtime (&t);
4009 /* Daylight saving starts or ends here. */
4010 if (gmt_offset (&tt, t) != gmtoff) {
4014 /* Try to find the exact hour when daylight saving starts/ends. */
4018 tt1 = *localtime (&t1);
4019 } while (gmt_offset (&tt1, t1) != gmtoff);
4021 /* Try to find the exact minute when daylight saving starts/ends. */
4024 tt1 = *localtime (&t1);
4025 } while (gmt_offset (&tt1, t1) == gmtoff);
4027 strftime (tzone, sizeof (tzone), "%Z", &tt);
4029 /* Write data, if we're already in daylight saving, we're done. */
4031 mono_array_set ((*names), gpointer, 0, mono_string_new (domain, tzone));
4032 mono_array_set ((*data), gint64, 1, ((gint64)t1 + EPOCH_ADJUST) * 10000000L);
4035 mono_array_set ((*names), gpointer, 1, mono_string_new (domain, tzone));
4036 mono_array_set ((*data), gint64, 0, ((gint64)t1 + EPOCH_ADJUST) * 10000000L);
4040 /* This is only set once when we enter daylight saving. */
4041 mono_array_set ((*data), gint64, 2, (gint64)gmtoff * 10000000L);
4042 mono_array_set ((*data), gint64, 3, (gint64)(gmt_offset (&tt, t) - gmtoff) * 10000000L);
4044 gmtoff = gmt_offset (&tt, t);
4049 strftime (tzone, sizeof (tzone), "%Z", &tt);
4050 mono_array_set ((*names), gpointer, 0, mono_string_new (domain, tzone));
4051 mono_array_set ((*names), gpointer, 1, mono_string_new (domain, tzone));
4052 mono_array_set ((*data), gint64, 0, 0);
4053 mono_array_set ((*data), gint64, 1, 0);
4054 mono_array_set ((*data), gint64, 2, (gint64) gmtoff * 10000000L);
4055 mono_array_set ((*data), gint64, 3, 0);
4060 MonoDomain *domain = mono_domain_get ();
4061 TIME_ZONE_INFORMATION tz_info;
4066 tz_id = GetTimeZoneInformation (&tz_info);
4067 if (tz_id == TIME_ZONE_ID_INVALID)
4070 MONO_CHECK_ARG_NULL (data);
4071 MONO_CHECK_ARG_NULL (names);
4073 (*data) = mono_array_new (domain, mono_defaults.int64_class, 4);
4074 (*names) = mono_array_new (domain, mono_defaults.string_class, 2);
4076 for (i = 0; i < 32; ++i)
4077 if (!tz_info.DaylightName [i])
4079 mono_array_set ((*names), gpointer, 1, mono_string_new_utf16 (domain, tz_info.DaylightName, i));
4080 for (i = 0; i < 32; ++i)
4081 if (!tz_info.StandardName [i])
4083 mono_array_set ((*names), gpointer, 0, mono_string_new_utf16 (domain, tz_info.StandardName, i));
4085 if ((year <= 1601) || (year > 30827)) {
4087 * According to MSDN, the MS time functions can't handle dates outside
4093 /* even if the timezone has no daylight savings it may have Bias (e.g. GMT+13 it seems) */
4094 if (tz_id != TIME_ZONE_ID_UNKNOWN) {
4095 tz_info.StandardDate.wYear = year;
4096 convert_to_absolute_date(&tz_info.StandardDate);
4097 err = SystemTimeToFileTime (&tz_info.StandardDate, &ft);
4099 mono_array_set ((*data), gint64, 1, FILETIME_ADJUST + (((guint64)ft.dwHighDateTime<<32) | ft.dwLowDateTime));
4100 tz_info.DaylightDate.wYear = year;
4101 convert_to_absolute_date(&tz_info.DaylightDate);
4102 err = SystemTimeToFileTime (&tz_info.DaylightDate, &ft);
4104 mono_array_set ((*data), gint64, 0, FILETIME_ADJUST + (((guint64)ft.dwHighDateTime<<32) | ft.dwLowDateTime));
4106 mono_array_set ((*data), gint64, 2, (tz_info.Bias + tz_info.StandardBias) * -600000000LL);
4107 mono_array_set ((*data), gint64, 3, (tz_info.DaylightBias - tz_info.StandardBias) * -600000000LL);
4114 ves_icall_System_Object_obj_address (MonoObject *this)
4116 MONO_ARCH_SAVE_REGS;
4123 static inline gint32
4124 mono_array_get_byte_length (MonoArray *array)
4130 klass = array->obj.vtable->klass;
4132 if (array->bounds == NULL)
4133 length = array->max_length;
4136 for (i = 0; i < klass->rank; ++ i)
4137 length *= array->bounds [i].length;
4140 switch (klass->element_class->byval_arg.type) {
4143 case MONO_TYPE_BOOLEAN:
4147 case MONO_TYPE_CHAR:
4155 return length * sizeof (gpointer);
4166 ves_icall_System_Buffer_ByteLengthInternal (MonoArray *array)
4168 MONO_ARCH_SAVE_REGS;
4170 return mono_array_get_byte_length (array);
4174 ves_icall_System_Buffer_GetByteInternal (MonoArray *array, gint32 idx)
4176 MONO_ARCH_SAVE_REGS;
4178 return mono_array_get (array, gint8, idx);
4182 ves_icall_System_Buffer_SetByteInternal (MonoArray *array, gint32 idx, gint8 value)
4184 MONO_ARCH_SAVE_REGS;
4186 mono_array_set (array, gint8, idx, value);
4190 ves_icall_System_Buffer_BlockCopyInternal (MonoArray *src, gint32 src_offset, MonoArray *dest, gint32 dest_offset, gint32 count)
4192 char *src_buf, *dest_buf;
4194 MONO_ARCH_SAVE_REGS;
4196 /* watch out for integer overflow */
4197 if ((src_offset > mono_array_get_byte_length (src) - count) || (dest_offset > mono_array_get_byte_length (dest) - count))
4200 src_buf = (gint8 *)src->vector + src_offset;
4201 dest_buf = (gint8 *)dest->vector + dest_offset;
4203 memcpy (dest_buf, src_buf, count);
4209 ves_icall_Remoting_RealProxy_GetTransparentProxy (MonoObject *this, MonoString *class_name)
4211 MonoDomain *domain = mono_object_domain (this);
4213 MonoRealProxy *rp = ((MonoRealProxy *)this);
4214 MonoTransparentProxy *tp;
4218 MONO_ARCH_SAVE_REGS;
4220 res = mono_object_new (domain, mono_defaults.transparent_proxy_class);
4221 tp = (MonoTransparentProxy*) res;
4224 type = ((MonoReflectionType *)rp->class_to_proxy)->type;
4225 klass = mono_class_from_mono_type (type);
4227 tp->custom_type_info = (mono_object_isinst (this, mono_defaults.iremotingtypeinfo_class) != NULL);
4228 tp->remote_class = mono_remote_class (domain, class_name, klass);
4229 res->vtable = tp->remote_class->vtable;
4234 static MonoReflectionType *
4235 ves_icall_Remoting_RealProxy_InternalGetProxyType (MonoTransparentProxy *tp)
4237 return mono_type_get_object (mono_object_domain (tp), &tp->remote_class->proxy_class->byval_arg);
4240 /* System.Environment */
4243 ves_icall_System_Environment_get_MachineName (void)
4245 #if defined (PLATFORM_WIN32)
4250 len = MAX_COMPUTERNAME_LENGTH + 1;
4251 buf = g_new (gunichar2, len);
4254 if (GetComputerName (buf, (PDWORD) &len))
4255 result = mono_string_new_utf16 (mono_domain_get (), buf, len);
4264 MONO_ARCH_SAVE_REGS;
4267 buf = g_new (gchar, len);
4270 if (gethostname (buf, len) == 0)
4271 result = mono_string_new (mono_domain_get (), buf);
4279 ves_icall_System_Environment_get_Platform (void)
4281 MONO_ARCH_SAVE_REGS;
4283 #if defined (PLATFORM_WIN32)
4293 ves_icall_System_Environment_get_NewLine (void)
4295 MONO_ARCH_SAVE_REGS;
4297 #if defined (PLATFORM_WIN32)
4298 return mono_string_new (mono_domain_get (), "\r\n");
4300 return mono_string_new (mono_domain_get (), "\n");
4305 ves_icall_System_Environment_GetEnvironmentVariable (MonoString *name)
4310 MONO_ARCH_SAVE_REGS;
4315 utf8_name = mono_string_to_utf8 (name); /* FIXME: this should be ascii */
4316 value = g_getenv (utf8_name);
4322 return mono_string_new (mono_domain_get (), value);
4326 * There is no standard way to get at environ.
4334 ves_icall_System_Environment_GetEnvironmentVariableNames (void)
4342 MONO_ARCH_SAVE_REGS;
4345 for (e = environ; *e != 0; ++ e)
4348 domain = mono_domain_get ();
4349 names = mono_array_new (domain, mono_defaults.string_class, n);
4352 for (e = environ; *e != 0; ++ e) {
4353 parts = g_strsplit (*e, "=", 2);
4355 str = mono_string_new (domain, *parts);
4356 mono_array_set (names, MonoString *, n, str);
4368 * Returns the number of milliseconds elapsed since the system started.
4371 ves_icall_System_Environment_get_TickCount (void)
4373 #if defined (PLATFORM_WIN32)
4374 return GetTickCount();
4380 MONO_ARCH_SAVE_REGS;
4382 res = (gint32) gettimeofday (&tv, &tz);
4385 res = (gint32) ((tv.tv_sec & 0xFFFFF) * 1000 + (tv.tv_usec / 1000));
4392 ves_icall_System_Environment_Exit (int result)
4394 MONO_ARCH_SAVE_REGS;
4396 mono_runtime_quit ();
4398 /* we may need to do some cleanup here... */
4403 ves_icall_System_Environment_GetGacPath (void)
4405 return mono_string_new (mono_domain_get (), mono_assembly_getrootdir ());
4409 ves_icall_System_Environment_GetWindowsFolderPath (int folder)
4411 #if defined (PLATFORM_WIN32)
4412 #ifndef CSIDL_FLAG_CREATE
4413 #define CSIDL_FLAG_CREATE 0x8000
4416 WCHAR path [MAX_PATH];
4417 /* Create directory if no existing */
4418 if (SUCCEEDED (SHGetFolderPathW (NULL, folder | CSIDL_FLAG_CREATE, NULL, 0, path))) {
4422 return mono_string_new_utf16 (mono_domain_get (), path, len);
4425 g_warning ("ves_icall_System_Environment_GetWindowsFolderPath should only be called on Windows!");
4427 return mono_string_new (mono_domain_get (), "");
4431 ves_icall_System_Environment_GetLogicalDrives (void)
4433 gunichar2 buf [128], *ptr, *dname;
4435 gint initial_size = 127, size = 128;
4438 MonoString *drivestr;
4439 MonoDomain *domain = mono_domain_get ();
4441 MONO_ARCH_SAVE_REGS;
4446 while (size > initial_size) {
4447 size = GetLogicalDriveStrings (initial_size, ptr);
4448 if (size > initial_size) {
4451 ptr = g_malloc0 ((size + 1) * sizeof (gunichar2));
4452 initial_size = size;
4466 result = mono_array_new (domain, mono_defaults.string_class, ndrives);
4469 u8 = g_utf16_to_utf8 (dname, -1, NULL, NULL, NULL);
4470 drivestr = mono_string_new (domain, u8);
4472 mono_array_set (result, gpointer, ndrives++, drivestr);
4482 static const char *encodings [] = {
4484 "ascii", "us_ascii", "us", "ansi_x3.4_1968",
4485 "ansi_x3.4_1986", "cp367", "csascii", "ibm367",
4486 "iso_ir_6", "iso646_us", "iso_646.irv:1991",
4488 "utf_7", "csunicode11utf7", "unicode_1_1_utf_7",
4489 "unicode_2_0_utf_7", "x_unicode_1_1_utf_7",
4490 "x_unicode_2_0_utf_7",
4492 "utf_8", "unicode_1_1_utf_8", "unicode_2_0_utf_8",
4493 "x_unicode_1_1_utf_8", "x_unicode_2_0_utf_8",
4495 "utf_16", "UTF_16LE", "ucs_2", "unicode",
4498 "unicodefffe", "utf_16be",
4505 * Returns the internal codepage, if the value of "int_code_page" is
4506 * 1 at entry, and we can not compute a suitable code page number,
4507 * returns the code page as a string
4510 ves_icall_System_Text_Encoding_InternalCodePage (gint32 *int_code_page)
4514 char *codepage = NULL;
4516 int want_name = *int_code_page;
4519 *int_code_page = -1;
4520 MONO_ARCH_SAVE_REGS;
4522 g_get_charset (&cset);
4523 p = codepage = strdup (cset);
4524 for (p = codepage; *p; p++){
4525 if (isascii (*p) && isalpha (*p))
4530 /* g_print ("charset: %s\n", cset); */
4532 /* handle some common aliases */
4535 for (i = 0; p != 0; ){
4538 p = encodings [++i];
4541 if (strcmp (p, codepage) == 0){
4542 *int_code_page = code;
4545 p = encodings [++i];
4548 if (strstr (codepage, "utf_8") != NULL)
4549 *int_code_page |= 0x10000000;
4552 if (want_name && *int_code_page == -1)
4553 return mono_string_new (mono_domain_get (), cset);
4559 ves_icall_System_Environment_get_HasShutdownStarted (void)
4561 if (mono_runtime_is_shutting_down ())
4564 if (mono_domain_is_unloading (mono_domain_get ()))
4571 ves_icall_MonoMethodMessage_InitMessage (MonoMethodMessage *this,
4572 MonoReflectionMethod *method,
4573 MonoArray *out_args)
4575 MONO_ARCH_SAVE_REGS;
4577 mono_message_init (mono_object_domain (this), this, method, out_args);
4581 ves_icall_IsTransparentProxy (MonoObject *proxy)
4583 MONO_ARCH_SAVE_REGS;
4588 if (proxy->vtable->klass == mono_defaults.transparent_proxy_class)
4595 ves_icall_System_Runtime_Activation_ActivationServices_EnableProxyActivation (MonoReflectionType *type, MonoBoolean enable)
4600 MONO_ARCH_SAVE_REGS;
4602 klass = mono_class_from_mono_type (type->type);
4603 vtable = mono_class_vtable (mono_domain_get (), klass);
4605 if (enable) vtable->remote = 1;
4606 else vtable->remote = 0;
4610 ves_icall_System_Runtime_Activation_ActivationServices_AllocateUninitializedClassInstance (MonoReflectionType *type)
4615 MONO_ARCH_SAVE_REGS;
4617 domain = mono_object_domain (type);
4618 klass = mono_class_from_mono_type (type->type);
4620 if (klass->rank >= 1) {
4621 g_assert (klass->rank == 1);
4622 return (MonoObject *) mono_array_new (domain, klass->element_class, 0);
4624 /* Bypass remoting object creation check */
4625 return mono_object_new_alloc_specific (mono_class_vtable (domain, klass));
4630 ves_icall_System_IO_get_temp_path (void)
4632 MONO_ARCH_SAVE_REGS;
4634 return mono_string_new (mono_domain_get (), g_get_tmp_dir ());
4638 ves_icall_RuntimeMethod_GetFunctionPointer (MonoMethod *method)
4640 MONO_ARCH_SAVE_REGS;
4642 return mono_compile_method (method);
4646 ves_icall_System_Configuration_DefaultConfig_get_machine_config_path (void)
4651 MONO_ARCH_SAVE_REGS;
4653 path = g_build_path (G_DIR_SEPARATOR_S, mono_get_config_dir (), "mono", "machine.config", NULL);
4655 #if defined (PLATFORM_WIN32)
4656 /* Avoid mixing '/' and '\\' */
4659 for (i = strlen (path) - 1; i >= 0; i--)
4660 if (path [i] == '/')
4664 mcpath = mono_string_new (mono_domain_get (), path);
4671 ves_icall_System_Web_Util_ICalls_get_machine_install_dir (void)
4676 MONO_ARCH_SAVE_REGS;
4678 path = g_path_get_dirname (mono_get_config_dir ());
4680 #if defined (PLATFORM_WIN32)
4681 /* Avoid mixing '/' and '\\' */
4684 for (i = strlen (path) - 1; i >= 0; i--)
4685 if (path [i] == '/')
4689 ipath = mono_string_new (mono_domain_get (), path);
4696 ves_icall_System_Diagnostics_DefaultTraceListener_WriteWindowsDebugString (MonoString *message)
4698 #if defined (PLATFORM_WIN32)
4699 static void (*output_debug) (gchar *);
4700 static gboolean tried_loading = FALSE;
4702 MONO_ARCH_SAVE_REGS;
4704 if (!tried_loading && output_debug == NULL) {
4707 tried_loading = TRUE;
4708 k32 = g_module_open ("kernel32", G_MODULE_BIND_LAZY);
4710 gchar *error = g_strdup (g_module_error ());
4711 g_warning ("Failed to load kernel32.dll: %s\n", error);
4716 g_module_symbol (k32, "OutputDebugStringW", (gpointer *) &output_debug);
4717 if (!output_debug) {
4718 gchar *error = g_strdup (g_module_error ());
4719 g_warning ("Failed to load OutputDebugStringW: %s\n", error);
4725 if (output_debug == NULL)
4728 output_debug (mono_string_chars (message));
4730 g_warning ("WriteWindowsDebugString called and PLATFORM_WIN32 not defined!\n");
4734 /* Only used for value types */
4736 ves_icall_System_Activator_CreateInstanceInternal (MonoReflectionType *type)
4741 MONO_ARCH_SAVE_REGS;
4743 domain = mono_object_domain (type);
4744 klass = mono_class_from_mono_type (type->type);
4746 return mono_object_new (domain, klass);
4749 static MonoReflectionMethod *
4750 ves_icall_MonoMethod_get_base_definition (MonoReflectionMethod *m)
4753 MonoMethod *method = m->method;
4754 MonoMethod *result = NULL;
4756 MONO_ARCH_SAVE_REGS;
4758 if (!(method->flags & METHOD_ATTRIBUTE_VIRTUAL) ||
4759 MONO_CLASS_IS_INTERFACE (method->klass) ||
4760 method->flags & METHOD_ATTRIBUTE_NEW_SLOT)
4763 if (method->klass == NULL || (klass = method->klass->parent) == NULL)
4766 if (klass->generic_inst)
4767 klass = mono_class_from_mono_type (klass->generic_inst->generic_type);
4769 while (result == NULL && klass != NULL && (klass->vtable_size > method->slot))
4771 result = klass->vtable [method->slot];
4772 if (result == NULL) {
4773 /* It is an abstract method */
4775 for (i=0; i<klass->method.count; i++) {
4776 if (klass->methods [i]->slot == method->slot) {
4777 result = klass->methods [i];
4782 klass = klass->parent;
4788 return mono_method_get_object (mono_domain_get (), result, NULL);
4792 mono_ArgIterator_Setup (MonoArgIterator *iter, char* argsp, char* start)
4794 MONO_ARCH_SAVE_REGS;
4796 iter->sig = *(MonoMethodSignature**)argsp;
4798 g_assert (iter->sig->sentinelpos <= iter->sig->param_count);
4799 g_assert (iter->sig->call_convention == MONO_CALL_VARARG);
4802 /* FIXME: it's not documented what start is exactly... */
4803 iter->args = start? start: argsp + sizeof (gpointer);
4804 iter->num_args = iter->sig->param_count - iter->sig->sentinelpos;
4806 /* g_print ("sig %p, param_count: %d, sent: %d\n", iter->sig, iter->sig->param_count, iter->sig->sentinelpos); */
4810 mono_ArgIterator_IntGetNextArg (MonoArgIterator *iter)
4812 gint i, align, arg_size;
4814 MONO_ARCH_SAVE_REGS;
4816 i = iter->sig->sentinelpos + iter->next_arg;
4818 g_assert (i < iter->sig->param_count);
4820 res.type = iter->sig->params [i];
4821 res.klass = mono_class_from_mono_type (res.type);
4822 /* FIXME: endianess issue... */
4823 res.value = iter->args;
4824 arg_size = mono_type_stack_size (res.type, &align);
4825 iter->args = (char*)iter->args + arg_size;
4828 //g_print ("returning arg %d, type 0x%02x of size %d at %p\n", i, res.type->type, arg_size, res.value);
4834 mono_ArgIterator_IntGetNextArgT (MonoArgIterator *iter, MonoType *type)
4836 gint i, align, arg_size;
4838 MONO_ARCH_SAVE_REGS;
4840 i = iter->sig->sentinelpos + iter->next_arg;
4842 g_assert (i < iter->sig->param_count);
4844 while (i < iter->sig->param_count) {
4845 if (!mono_metadata_type_equal (type, iter->sig->params [i]))
4847 res.type = iter->sig->params [i];
4848 res.klass = mono_class_from_mono_type (res.type);
4849 /* FIXME: endianess issue... */
4850 res.value = iter->args;
4851 arg_size = mono_type_stack_size (res.type, &align);
4852 iter->args = (char*)iter->args + arg_size;
4854 //g_print ("returning arg %d, type 0x%02x of size %d at %p\n", i, res.type->type, arg_size, res.value);
4857 //g_print ("arg type 0x%02x not found\n", res.type->type);
4866 mono_ArgIterator_IntGetNextArgType (MonoArgIterator *iter)
4869 MONO_ARCH_SAVE_REGS;
4871 i = iter->sig->sentinelpos + iter->next_arg;
4873 g_assert (i < iter->sig->param_count);
4875 return iter->sig->params [i];
4879 mono_TypedReference_ToObject (MonoTypedRef tref)
4881 MONO_ARCH_SAVE_REGS;
4883 if (MONO_TYPE_IS_REFERENCE (tref.type)) {
4884 MonoObject** objp = tref.value;
4888 return mono_value_box (mono_domain_get (), tref.klass, tref.value);
4892 prelink_method (MonoMethod *method)
4894 const char *exc_class, *exc_arg;
4895 if (!(method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL))
4897 mono_lookup_pinvoke_call (method, &exc_class, &exc_arg);
4899 mono_raise_exception(
4900 mono_exception_from_name_msg (mono_defaults.corlib, "System", exc_class, exc_arg ) );
4902 /* create the wrapper, too? */
4906 ves_icall_System_Runtime_InteropServices_Marshal_Prelink (MonoReflectionMethod *method)
4908 MONO_ARCH_SAVE_REGS;
4909 prelink_method (method->method);
4913 ves_icall_System_Runtime_InteropServices_Marshal_PrelinkAll (MonoReflectionType *type)
4915 MonoClass *klass = mono_class_from_mono_type (type->type);
4917 MONO_ARCH_SAVE_REGS;
4919 mono_class_init (klass);
4920 for (i = 0; i < klass->method.count; ++i)
4921 prelink_method (klass->methods [i]);
4925 ves_icall_System_Char_GetDataTablePointers (guint8 **category_data, guint8 **numeric_data,
4926 gdouble **numeric_data_values, guint16 **to_lower_data_low,
4927 guint16 **to_lower_data_high, guint16 **to_upper_data_low,
4928 guint16 **to_upper_data_high)
4930 *category_data = CategoryData;
4931 *numeric_data = NumericData;
4932 *numeric_data_values = NumericDataValues;
4933 *to_lower_data_low = ToLowerDataLow;
4934 *to_lower_data_high = ToLowerDataHigh;
4935 *to_upper_data_low = ToUpperDataLow;
4936 *to_upper_data_high = ToUpperDataHigh;
4947 const IcallEntry *icalls;
4951 static const IcallEntry activator_icalls [] = {
4952 {"CreateInstanceInternal", ves_icall_System_Activator_CreateInstanceInternal}
4954 static const IcallEntry appdomain_icalls [] = {
4955 {"ExecuteAssembly", ves_icall_System_AppDomain_ExecuteAssembly},
4956 {"GetAssemblies", ves_icall_System_AppDomain_GetAssemblies},
4957 {"GetData", ves_icall_System_AppDomain_GetData},
4958 {"InternalGetContext", ves_icall_System_AppDomain_InternalGetContext},
4959 {"InternalGetDefaultContext", ves_icall_System_AppDomain_InternalGetDefaultContext},
4960 {"InternalGetProcessGuid", ves_icall_System_AppDomain_InternalGetProcessGuid},
4961 {"InternalIsFinalizingForUnload", ves_icall_System_AppDomain_InternalIsFinalizingForUnload},
4962 {"InternalPopDomainRef", ves_icall_System_AppDomain_InternalPopDomainRef},
4963 {"InternalPushDomainRef", ves_icall_System_AppDomain_InternalPushDomainRef},
4964 {"InternalPushDomainRefByID", ves_icall_System_AppDomain_InternalPushDomainRefByID},
4965 {"InternalSetContext", ves_icall_System_AppDomain_InternalSetContext},
4966 {"InternalSetDomain", ves_icall_System_AppDomain_InternalSetDomain},
4967 {"InternalSetDomainByID", ves_icall_System_AppDomain_InternalSetDomainByID},
4968 {"InternalUnload", ves_icall_System_AppDomain_InternalUnload},
4969 {"LoadAssembly", ves_icall_System_AppDomain_LoadAssembly},
4970 {"LoadAssemblyRaw", ves_icall_System_AppDomain_LoadAssemblyRaw},
4971 {"SetData", ves_icall_System_AppDomain_SetData},
4972 {"createDomain", ves_icall_System_AppDomain_createDomain},
4973 {"getCurDomain", ves_icall_System_AppDomain_getCurDomain},
4974 {"getFriendlyName", ves_icall_System_AppDomain_getFriendlyName},
4975 {"getSetup", ves_icall_System_AppDomain_getSetup}
4978 static const IcallEntry argiterator_icalls [] = {
4979 {"IntGetNextArg()", mono_ArgIterator_IntGetNextArg},
4980 {"IntGetNextArg(intptr)", mono_ArgIterator_IntGetNextArgT},
4981 {"IntGetNextArgType", mono_ArgIterator_IntGetNextArgType},
4982 {"Setup", mono_ArgIterator_Setup}
4985 static const IcallEntry array_icalls [] = {
4986 {"Clone", mono_array_clone},
4987 {"CreateInstanceImpl", ves_icall_System_Array_CreateInstanceImpl},
4988 {"FastCopy", ves_icall_System_Array_FastCopy},
4989 {"GetLength", ves_icall_System_Array_GetLength},
4990 {"GetLowerBound", ves_icall_System_Array_GetLowerBound},
4991 {"GetRank", ves_icall_System_Array_GetRank},
4992 {"GetValue", ves_icall_System_Array_GetValue},
4993 {"GetValueImpl", ves_icall_System_Array_GetValueImpl},
4994 {"SetValue", ves_icall_System_Array_SetValue},
4995 {"SetValueImpl", ves_icall_System_Array_SetValueImpl}
4998 static const IcallEntry buffer_icalls [] = {
4999 {"BlockCopyInternal", ves_icall_System_Buffer_BlockCopyInternal},
5000 {"ByteLengthInternal", ves_icall_System_Buffer_ByteLengthInternal},
5001 {"GetByteInternal", ves_icall_System_Buffer_GetByteInternal},
5002 {"SetByteInternal", ves_icall_System_Buffer_SetByteInternal}
5005 static const IcallEntry char_icalls [] = {
5006 {"GetDataTablePointers", ves_icall_System_Char_GetDataTablePointers},
5007 {"InternalToLower(char,System.Globalization.CultureInfo)", ves_icall_System_Char_InternalToLower_Comp},
5008 {"InternalToUpper(char,System.Globalization.CultureInfo)", ves_icall_System_Char_InternalToUpper_Comp}
5011 static const IcallEntry defaultconf_icalls [] = {
5012 {"get_machine_config_path", ves_icall_System_Configuration_DefaultConfig_get_machine_config_path}
5015 static const IcallEntry timezone_icalls [] = {
5016 {"GetTimeZoneData", ves_icall_System_CurrentTimeZone_GetTimeZoneData}
5019 static const IcallEntry datetime_icalls [] = {
5020 {"GetNow", ves_icall_System_DateTime_GetNow}
5023 static const IcallEntry decimal_icalls [] = {
5024 {"decimal2Int64", mono_decimal2Int64},
5025 {"decimal2UInt64", mono_decimal2UInt64},
5026 {"decimal2double", mono_decimal2double},
5027 {"decimal2string", mono_decimal2string},
5028 {"decimalCompare", mono_decimalCompare},
5029 {"decimalDiv", mono_decimalDiv},
5030 {"decimalFloorAndTrunc", mono_decimalFloorAndTrunc},
5031 {"decimalIncr", mono_decimalIncr},
5032 {"decimalIntDiv", mono_decimalIntDiv},
5033 {"decimalMult", mono_decimalMult},
5034 {"decimalRound", mono_decimalRound},
5035 {"decimalSetExponent", mono_decimalSetExponent},
5036 {"double2decimal", mono_double2decimal}, /* FIXME: wrong signature. */
5037 {"string2decimal", mono_string2decimal}
5040 static const IcallEntry delegate_icalls [] = {
5041 {"CreateDelegate_internal", ves_icall_System_Delegate_CreateDelegate_internal}
5044 static const IcallEntry tracelist_icalls [] = {
5045 {"WriteWindowsDebugString", ves_icall_System_Diagnostics_DefaultTraceListener_WriteWindowsDebugString}
5048 static const IcallEntry fileversion_icalls [] = {
5049 {"GetVersionInfo_internal(string)", ves_icall_System_Diagnostics_FileVersionInfo_GetVersionInfo_internal}
5052 static const IcallEntry process_icalls [] = {
5053 {"ExitCode_internal(intptr)", ves_icall_System_Diagnostics_Process_ExitCode_internal},
5054 {"ExitTime_internal(intptr)", ves_icall_System_Diagnostics_Process_ExitTime_internal},
5055 {"GetModules_internal()", ves_icall_System_Diagnostics_Process_GetModules_internal},
5056 {"GetPid_internal()", ves_icall_System_Diagnostics_Process_GetPid_internal},
5057 {"GetProcess_internal(int)", ves_icall_System_Diagnostics_Process_GetProcess_internal},
5058 {"GetProcesses_internal()", ves_icall_System_Diagnostics_Process_GetProcesses_internal},
5059 {"GetWorkingSet_internal(intptr,int&,int&)", ves_icall_System_Diagnostics_Process_GetWorkingSet_internal},
5060 {"Kill_internal", ves_icall_System_Diagnostics_Process_Kill_internal},
5061 {"ProcessName_internal(intptr)", ves_icall_System_Diagnostics_Process_ProcessName_internal},
5062 {"Process_free_internal(intptr)", ves_icall_System_Diagnostics_Process_Process_free_internal},
5063 {"SetWorkingSet_internal(intptr,int,int,bool)", ves_icall_System_Diagnostics_Process_SetWorkingSet_internal},
5064 {"StartTime_internal(intptr)", ves_icall_System_Diagnostics_Process_StartTime_internal},
5065 {"Start_internal(string,string,string,intptr,intptr,intptr,System.Diagnostics.Process/ProcInfo&)", ves_icall_System_Diagnostics_Process_Start_internal},
5066 {"WaitForExit_internal(intptr,int)", ves_icall_System_Diagnostics_Process_WaitForExit_internal}
5069 static const IcallEntry double_icalls [] = {
5070 {"AssertEndianity", ves_icall_System_Double_AssertEndianity},
5071 {"ParseImpl", mono_double_ParseImpl}
5074 static const IcallEntry enum_icalls [] = {
5075 {"ToObject", ves_icall_System_Enum_ToObject},
5076 {"get_value", ves_icall_System_Enum_get_value}
5079 static const IcallEntry environment_icalls [] = {
5080 {"Exit", ves_icall_System_Environment_Exit},
5081 {"GetCommandLineArgs", mono_runtime_get_main_args},
5082 {"GetEnvironmentVariable", ves_icall_System_Environment_GetEnvironmentVariable},
5083 {"GetEnvironmentVariableNames", ves_icall_System_Environment_GetEnvironmentVariableNames},
5084 {"GetLogicalDrivesInternal", ves_icall_System_Environment_GetLogicalDrives },
5085 {"GetMachineConfigPath", ves_icall_System_Configuration_DefaultConfig_get_machine_config_path},
5086 {"GetOSVersionString", ves_icall_System_Environment_GetOSVersionString},
5087 {"GetWindowsFolderPath", ves_icall_System_Environment_GetWindowsFolderPath},
5088 {"get_ExitCode", mono_environment_exitcode_get},
5089 {"get_HasShutdownStarted", ves_icall_System_Environment_get_HasShutdownStarted},
5090 {"get_MachineName", ves_icall_System_Environment_get_MachineName},
5091 {"get_NewLine", ves_icall_System_Environment_get_NewLine},
5092 {"get_Platform", ves_icall_System_Environment_get_Platform},
5093 {"get_TickCount", ves_icall_System_Environment_get_TickCount},
5094 {"get_UserName", ves_icall_System_Environment_get_UserName},
5095 {"internalGetGacPath", ves_icall_System_Environment_GetGacPath},
5096 {"set_ExitCode", mono_environment_exitcode_set}
5099 static const IcallEntry cultureinfo_icalls [] = {
5100 {"construct_compareinfo(object,string)", ves_icall_System_Globalization_CompareInfo_construct_compareinfo},
5101 {"construct_datetime_format", ves_icall_System_Globalization_CultureInfo_construct_datetime_format},
5102 {"construct_internal_locale(string)", ves_icall_System_Globalization_CultureInfo_construct_internal_locale},
5103 {"construct_internal_locale_from_current_locale", ves_icall_System_Globalization_CultureInfo_construct_internal_locale_from_current_locale},
5104 {"construct_internal_locale_from_lcid", ves_icall_System_Globalization_CultureInfo_construct_internal_locale_from_lcid},
5105 {"construct_internal_locale_from_name", ves_icall_System_Globalization_CultureInfo_construct_internal_locale_from_name},
5106 {"construct_internal_locale_from_specific_name", ves_icall_System_Globalization_CultureInfo_construct_internal_locale_from_specific_name},
5107 {"construct_number_format", ves_icall_System_Globalization_CultureInfo_construct_number_format},
5108 {"internal_get_cultures", ves_icall_System_Globalization_CultureInfo_internal_get_cultures},
5109 {"internal_is_lcid_neutral", ves_icall_System_Globalization_CultureInfo_internal_is_lcid_neutral}
5112 static const IcallEntry compareinfo_icalls [] = {
5113 {"assign_sortkey(object,string,System.Globalization.CompareOptions)", ves_icall_System_Globalization_CompareInfo_assign_sortkey},
5114 {"construct_compareinfo(string)", ves_icall_System_Globalization_CompareInfo_construct_compareinfo},
5115 {"free_internal_collator()", ves_icall_System_Globalization_CompareInfo_free_internal_collator},
5116 {"internal_compare(string,int,int,string,int,int,System.Globalization.CompareOptions)", ves_icall_System_Globalization_CompareInfo_internal_compare},
5117 {"internal_index(string,int,int,char,System.Globalization.CompareOptions,bool)", ves_icall_System_Globalization_CompareInfo_internal_index_char},
5118 {"internal_index(string,int,int,string,System.Globalization.CompareOptions,bool)", ves_icall_System_Globalization_CompareInfo_internal_index}
5121 static const IcallEntry gc_icalls [] = {
5122 {"GetTotalMemory", ves_icall_System_GC_GetTotalMemory},
5123 {"InternalCollect", ves_icall_System_GC_InternalCollect},
5124 {"KeepAlive", ves_icall_System_GC_KeepAlive},
5125 {"ReRegisterForFinalize", ves_icall_System_GC_ReRegisterForFinalize},
5126 {"SuppressFinalize", ves_icall_System_GC_SuppressFinalize},
5127 {"WaitForPendingFinalizers", ves_icall_System_GC_WaitForPendingFinalizers}
5130 static const IcallEntry famwatcher_icalls [] = {
5131 {"InternalFAMNextEvent", ves_icall_System_IO_FAMW_InternalFAMNextEvent}
5134 static const IcallEntry filewatcher_icalls [] = {
5135 {"InternalCloseDirectory", ves_icall_System_IO_FSW_CloseDirectory},
5136 {"InternalOpenDirectory", ves_icall_System_IO_FSW_OpenDirectory},
5137 {"InternalReadDirectoryChanges", ves_icall_System_IO_FSW_ReadDirectoryChanges},
5138 {"InternalSupportsFSW", ves_icall_System_IO_FSW_SupportsFSW}
5141 static const IcallEntry path_icalls [] = {
5142 {"get_temp_path", ves_icall_System_IO_get_temp_path}
5145 static const IcallEntry monoio_icalls [] = {
5146 {"BeginRead", ves_icall_System_IO_MonoIO_BeginRead },
5147 {"BeginWrite", ves_icall_System_IO_MonoIO_BeginWrite },
5148 {"Close(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Close},
5149 {"CopyFile(string,string,bool,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_CopyFile},
5150 {"CreateDirectory(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_CreateDirectory},
5151 {"CreatePipe(intptr&,intptr&)", ves_icall_System_IO_MonoIO_CreatePipe},
5152 {"DeleteFile(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_DeleteFile},
5153 {"FindClose(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_FindClose},
5154 {"FindFirstFile(string,System.IO.MonoIOStat&,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_FindFirstFile},
5155 {"FindNextFile(intptr,System.IO.MonoIOStat&,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_FindNextFile},
5156 {"Flush(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Flush},
5157 {"GetCurrentDirectory(System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetCurrentDirectory},
5158 {"GetFileAttributes(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetFileAttributes},
5159 {"GetFileStat(string,System.IO.MonoIOStat&,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetFileStat},
5160 {"GetFileType(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetFileType},
5161 {"GetLength(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetLength},
5162 {"GetSupportsAsync", ves_icall_System_IO_MonoIO_GetSupportsAsync},
5163 {"GetTempPath(string&)", ves_icall_System_IO_MonoIO_GetTempPath},
5164 {"Lock(intptr,long,long,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Lock},
5165 {"MoveFile(string,string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_MoveFile},
5166 {"Open(string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare,bool,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Open},
5167 {"Read(intptr,byte[],int,int,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Read},
5168 {"RemoveDirectory(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_RemoveDirectory},
5169 {"Seek(intptr,long,System.IO.SeekOrigin,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Seek},
5170 {"SetCurrentDirectory(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_SetCurrentDirectory},
5171 {"SetFileAttributes(string,System.IO.FileAttributes,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_SetFileAttributes},
5172 {"SetFileTime(intptr,long,long,long,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_SetFileTime},
5173 {"SetLength(intptr,long,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_SetLength},
5174 {"Unlock(intptr,long,long,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Unlock},
5175 {"Write(intptr,byte[],int,int,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Write},
5176 {"get_AltDirectorySeparatorChar", ves_icall_System_IO_MonoIO_get_AltDirectorySeparatorChar},
5177 {"get_ConsoleError", ves_icall_System_IO_MonoIO_get_ConsoleError},
5178 {"get_ConsoleInput", ves_icall_System_IO_MonoIO_get_ConsoleInput},
5179 {"get_ConsoleOutput", ves_icall_System_IO_MonoIO_get_ConsoleOutput},
5180 {"get_DirectorySeparatorChar", ves_icall_System_IO_MonoIO_get_DirectorySeparatorChar},
5181 {"get_InvalidPathChars", ves_icall_System_IO_MonoIO_get_InvalidPathChars},
5182 {"get_PathSeparator", ves_icall_System_IO_MonoIO_get_PathSeparator},
5183 {"get_VolumeSeparatorChar", ves_icall_System_IO_MonoIO_get_VolumeSeparatorChar}
5186 static const IcallEntry math_icalls [] = {
5187 {"Acos", ves_icall_System_Math_Acos},
5188 {"Asin", ves_icall_System_Math_Asin},
5189 {"Atan", ves_icall_System_Math_Atan},
5190 {"Atan2", ves_icall_System_Math_Atan2},
5191 {"Cos", ves_icall_System_Math_Cos},
5192 {"Cosh", ves_icall_System_Math_Cosh},
5193 {"Exp", ves_icall_System_Math_Exp},
5194 {"Floor", ves_icall_System_Math_Floor},
5195 {"Log", ves_icall_System_Math_Log},
5196 {"Log10", ves_icall_System_Math_Log10},
5197 {"Pow", ves_icall_System_Math_Pow},
5198 {"Round", ves_icall_System_Math_Round},
5199 {"Round2", ves_icall_System_Math_Round2},
5200 {"Sin", ves_icall_System_Math_Sin},
5201 {"Sinh", ves_icall_System_Math_Sinh},
5202 {"Sqrt", ves_icall_System_Math_Sqrt},
5203 {"Tan", ves_icall_System_Math_Tan},
5204 {"Tanh", ves_icall_System_Math_Tanh}
5207 static const IcallEntry customattrs_icalls [] = {
5208 {"GetCustomAttributes", mono_reflection_get_custom_attrs}
5211 static const IcallEntry enuminfo_icalls [] = {
5212 {"get_enum_info", ves_icall_get_enum_info}
5215 static const IcallEntry fieldinfo_icalls [] = {
5216 {"internal_from_handle", ves_icall_System_Reflection_FieldInfo_internal_from_handle}
5219 static const IcallEntry monotype_icalls [] = {
5220 {"GetArrayRank", ves_icall_MonoType_GetArrayRank},
5221 {"GetConstructors", ves_icall_Type_GetConstructors_internal},
5222 {"GetConstructors_internal", ves_icall_Type_GetConstructors_internal},
5223 {"GetElementType", ves_icall_MonoType_GetElementType},
5224 {"GetEvents_internal", ves_icall_Type_GetEvents_internal},
5225 {"GetField", ves_icall_Type_GetField},
5226 {"GetFields_internal", ves_icall_Type_GetFields_internal},
5227 {"GetGenericArguments", ves_icall_MonoType_GetGenericArguments},
5228 {"GetInterfaces", ves_icall_Type_GetInterfaces},
5229 {"GetMethodsByName", ves_icall_Type_GetMethodsByName},
5230 {"GetNestedType", ves_icall_Type_GetNestedType},
5231 {"GetNestedTypes", ves_icall_Type_GetNestedTypes},
5232 {"GetPropertiesByName", ves_icall_Type_GetPropertiesByName},
5233 {"InternalGetEvent", ves_icall_MonoType_GetEvent},
5234 {"IsByRefImpl", ves_icall_type_isbyref},
5235 {"IsPointerImpl", ves_icall_type_ispointer},
5236 {"IsPrimitiveImpl", ves_icall_type_isprimitive},
5237 {"getFullName", ves_icall_System_MonoType_getFullName},
5238 {"get_Assembly", ves_icall_MonoType_get_Assembly},
5239 {"get_BaseType", ves_icall_get_type_parent},
5240 {"get_DeclaringMethod", ves_icall_MonoType_get_DeclaringMethod},
5241 {"get_DeclaringType", ves_icall_MonoType_get_DeclaringType},
5242 {"get_HasGenericArguments", ves_icall_MonoType_get_HasGenericArguments},
5243 {"get_IsGenericParameter", ves_icall_MonoType_get_IsGenericParameter},
5244 {"get_Module", ves_icall_MonoType_get_Module},
5245 {"get_Name", ves_icall_MonoType_get_Name},
5246 {"get_Namespace", ves_icall_MonoType_get_Namespace},
5247 {"get_UnderlyingSystemType", ves_icall_MonoType_get_UnderlyingSystemType},
5248 {"get_attributes", ves_icall_get_attributes},
5249 {"type_from_obj", mono_type_type_from_obj}
5252 static const IcallEntry assembly_icalls [] = {
5253 {"FillName", ves_icall_System_Reflection_Assembly_FillName},
5254 {"GetCallingAssembly", ves_icall_System_Reflection_Assembly_GetCallingAssembly},
5255 {"GetEntryAssembly", ves_icall_System_Reflection_Assembly_GetEntryAssembly},
5256 {"GetExecutingAssembly", ves_icall_System_Reflection_Assembly_GetExecutingAssembly},
5257 {"GetFilesInternal", ves_icall_System_Reflection_Assembly_GetFilesInternal},
5258 {"GetManifestResourceInfoInternal", ves_icall_System_Reflection_Assembly_GetManifestResourceInfoInternal},
5259 {"GetManifestResourceInternal", ves_icall_System_Reflection_Assembly_GetManifestResourceInternal},
5260 {"GetManifestResourceNames", ves_icall_System_Reflection_Assembly_GetManifestResourceNames},
5261 {"GetModulesInternal", ves_icall_System_Reflection_Assembly_GetModulesInternal},
5262 {"GetNamespaces", ves_icall_System_Reflection_Assembly_GetNamespaces},
5263 {"GetReferencedAssemblies", ves_icall_System_Reflection_Assembly_GetReferencedAssemblies},
5264 {"GetTypes", ves_icall_System_Reflection_Assembly_GetTypes},
5265 {"InternalGetAssemblyName", ves_icall_System_Reflection_Assembly_InternalGetAssemblyName},
5266 {"InternalGetType", ves_icall_System_Reflection_Assembly_InternalGetType},
5267 {"InternalImageRuntimeVersion", ves_icall_System_Reflection_Assembly_InternalImageRuntimeVersion},
5268 {"LoadFrom", ves_icall_System_Reflection_Assembly_LoadFrom},
5270 * Private icalls for the Mono Debugger
5272 {"MonoDebugger_GetLocalTypeFromSignature", ves_icall_MonoDebugger_GetLocalTypeFromSignature},
5273 {"MonoDebugger_GetMethod", ves_icall_MonoDebugger_GetMethod},
5274 {"MonoDebugger_GetMethodToken", ves_icall_MonoDebugger_GetMethodToken},
5275 {"MonoDebugger_GetType", ves_icall_MonoDebugger_GetType},
5276 /* normal icalls again */
5277 {"get_EntryPoint", ves_icall_System_Reflection_Assembly_get_EntryPoint},
5278 {"get_code_base", ves_icall_System_Reflection_Assembly_get_code_base},
5279 {"get_global_assembly_cache", ves_icall_System_Reflection_Assembly_get_global_assembly_cache},
5280 {"get_location", ves_icall_System_Reflection_Assembly_get_location},
5281 {"load_with_partial_name", ves_icall_System_Reflection_Assembly_load_with_partial_name}
5284 static const IcallEntry methodbase_icalls [] = {
5285 {"GetCurrentMethod", ves_icall_GetCurrentMethod}
5288 static const IcallEntry module_icalls [] = {
5289 {"Close", ves_icall_System_Reflection_Module_Close},
5290 {"GetGlobalType", ves_icall_System_Reflection_Module_GetGlobalType},
5291 {"GetGuidInternal", ves_icall_System_Reflection_Module_GetGuidInternal},
5292 {"InternalGetTypes", ves_icall_System_Reflection_Module_InternalGetTypes}
5295 static const IcallEntry monocmethod_icalls [] = {
5296 {"GetGenericMethodDefinition_impl", ves_icall_MonoMethod_GetGenericMethodDefinition},
5297 {"InternalInvoke", ves_icall_InternalInvoke},
5298 {"get_Mono_IsInflatedMethod", ves_icall_MonoMethod_get_Mono_IsInflatedMethod}
5301 static const IcallEntry monoeventinfo_icalls [] = {
5302 {"get_event_info", ves_icall_get_event_info}
5305 static const IcallEntry monofield_icalls [] = {
5306 {"GetParentType", ves_icall_MonoField_GetParentType},
5307 {"GetValueInternal", ves_icall_MonoField_GetValueInternal},
5308 {"SetValueInternal", ves_icall_FieldInfo_SetValueInternal}
5311 static const IcallEntry monogenericinst_icalls [] = {
5312 {"GetConstructors_internal", ves_icall_MonoGenericInst_GetConstructors},
5313 {"GetEvents_internal", ves_icall_MonoGenericInst_GetEvents},
5314 {"GetFields_internal", ves_icall_MonoGenericInst_GetFields},
5315 {"GetInterfaces_internal", ves_icall_MonoGenericInst_GetInterfaces},
5316 {"GetMethods_internal", ves_icall_MonoGenericInst_GetMethods},
5317 {"GetParentType", ves_icall_MonoGenericInst_GetParentType},
5318 {"GetProperties_internal", ves_icall_MonoGenericInst_GetProperties},
5319 {"initialize", mono_reflection_generic_inst_initialize}
5322 static const IcallEntry generictypeparambuilder_icalls [] = {
5323 {"initialize", mono_reflection_initialize_generic_parameter}
5326 static const IcallEntry monomethod_icalls [] = {
5327 {"BindGenericParameters", mono_reflection_bind_generic_method_parameters},
5328 {"GetGenericArguments", ves_icall_MonoMethod_GetGenericArguments},
5329 {"GetGenericMethodDefinition_impl", ves_icall_MonoMethod_GetGenericMethodDefinition},
5330 {"InternalInvoke", ves_icall_InternalInvoke},
5331 {"get_HasGenericParameters", ves_icall_MonoMethod_get_HasGenericParameters},
5332 {"get_IsGenericMethodDefinition", ves_icall_MonoMethod_get_IsGenericMethodDefinition},
5333 {"get_Mono_IsInflatedMethod", ves_icall_MonoMethod_get_Mono_IsInflatedMethod},
5334 {"get_base_definition", ves_icall_MonoMethod_get_base_definition}
5337 static const IcallEntry monomethodinfo_icalls [] = {
5338 {"get_method_info", ves_icall_get_method_info},
5339 {"get_parameter_info", ves_icall_get_parameter_info}
5342 static const IcallEntry monopropertyinfo_icalls [] = {
5343 {"get_property_info", ves_icall_get_property_info}
5346 static const IcallEntry dns_icalls [] = {
5347 {"GetHostByAddr_internal(string,string&,string[]&,string[]&)", ves_icall_System_Net_Dns_GetHostByAddr_internal},
5348 {"GetHostByName_internal(string,string&,string[]&,string[]&)", ves_icall_System_Net_Dns_GetHostByName_internal},
5349 {"GetHostName_internal(string&)", ves_icall_System_Net_Dns_GetHostName_internal}
5352 static const IcallEntry socket_icalls [] = {
5353 {"Accept_internal(intptr,int&)", ves_icall_System_Net_Sockets_Socket_Accept_internal},
5354 {"AsyncReceiveInternal", ves_icall_System_Net_Sockets_Socket_AsyncReceive},
5355 {"AsyncSendInternal", ves_icall_System_Net_Sockets_Socket_AsyncSend},
5356 {"Available_internal(intptr,int&)", ves_icall_System_Net_Sockets_Socket_Available_internal},
5357 {"Bind_internal(intptr,System.Net.SocketAddress,int&)", ves_icall_System_Net_Sockets_Socket_Bind_internal},
5358 {"Blocking_internal(intptr,bool,int&)", ves_icall_System_Net_Sockets_Socket_Blocking_internal},
5359 {"Close_internal(intptr,int&)", ves_icall_System_Net_Sockets_Socket_Close_internal},
5360 {"Connect_internal(intptr,System.Net.SocketAddress,int&)", ves_icall_System_Net_Sockets_Socket_Connect_internal},
5361 {"GetSocketOption_arr_internal(intptr,System.Net.Sockets.SocketOptionLevel,System.Net.Sockets.SocketOptionName,byte[]&,int&)", ves_icall_System_Net_Sockets_Socket_GetSocketOption_arr_internal},
5362 {"GetSocketOption_obj_internal(intptr,System.Net.Sockets.SocketOptionLevel,System.Net.Sockets.SocketOptionName,object&,int&)", ves_icall_System_Net_Sockets_Socket_GetSocketOption_obj_internal},
5363 {"GetSupportsAsync", ves_icall_System_IO_MonoIO_GetSupportsAsync},
5364 {"Listen_internal(intptr,int,int&)", ves_icall_System_Net_Sockets_Socket_Listen_internal},
5365 {"LocalEndPoint_internal(intptr,int&)", ves_icall_System_Net_Sockets_Socket_LocalEndPoint_internal},
5366 {"Poll_internal", ves_icall_System_Net_Sockets_Socket_Poll_internal},
5367 {"Receive_internal(intptr,byte[],int,int,System.Net.Sockets.SocketFlags,int&)", ves_icall_System_Net_Sockets_Socket_Receive_internal},
5368 {"RecvFrom_internal(intptr,byte[],int,int,System.Net.Sockets.SocketFlags,System.Net.SocketAddress&,int&)", ves_icall_System_Net_Sockets_Socket_RecvFrom_internal},
5369 {"RemoteEndPoint_internal(intptr,int&)", ves_icall_System_Net_Sockets_Socket_RemoteEndPoint_internal},
5370 {"Select_internal(System.Net.Sockets.Socket[]&,System.Net.Sockets.Socket[]&,System.Net.Sockets.Socket[]&,int,int&)", ves_icall_System_Net_Sockets_Socket_Select_internal},
5371 {"SendTo_internal(intptr,byte[],int,int,System.Net.Sockets.SocketFlags,System.Net.SocketAddress,int&)", ves_icall_System_Net_Sockets_Socket_SendTo_internal},
5372 {"Send_internal(intptr,byte[],int,int,System.Net.Sockets.SocketFlags,int&)", ves_icall_System_Net_Sockets_Socket_Send_internal},
5373 {"SetSocketOption_internal(intptr,System.Net.Sockets.SocketOptionLevel,System.Net.Sockets.SocketOptionName,object,byte[],int,int&)", ves_icall_System_Net_Sockets_Socket_SetSocketOption_internal},
5374 {"Shutdown_internal(intptr,System.Net.Sockets.SocketShutdown,int&)", ves_icall_System_Net_Sockets_Socket_Shutdown_internal},
5375 {"Socket_internal(System.Net.Sockets.AddressFamily,System.Net.Sockets.SocketType,System.Net.Sockets.ProtocolType,int&)", ves_icall_System_Net_Sockets_Socket_Socket_internal},
5376 {"WSAIoctl(intptr,int,byte[],byte[],int&)", ves_icall_System_Net_Sockets_Socket_WSAIoctl}
5379 static const IcallEntry socketex_icalls [] = {
5380 {"WSAGetLastError_internal", ves_icall_System_Net_Sockets_SocketException_WSAGetLastError_internal}
5383 static const IcallEntry object_icalls [] = {
5384 {"GetType", ves_icall_System_Object_GetType},
5385 {"InternalGetHashCode", ves_icall_System_Object_GetHashCode},
5386 {"MemberwiseClone", ves_icall_System_Object_MemberwiseClone},
5387 {"obj_address", ves_icall_System_Object_obj_address}
5390 static const IcallEntry assemblybuilder_icalls[] = {
5391 {"InternalAddModule", mono_image_load_module},
5392 {"basic_init", mono_image_basic_init}
5395 static const IcallEntry customattrbuilder_icalls [] = {
5396 {"GetBlob", mono_reflection_get_custom_attrs_blob}
5399 static const IcallEntry dynamicmethod_icalls [] = {
5400 {"create_dynamic_method", mono_reflection_create_dynamic_method}
5403 static const IcallEntry methodbuilder_icalls [] = {
5404 {"BindGenericParameters", mono_reflection_bind_generic_method_parameters}
5407 static const IcallEntry modulebuilder_icalls [] = {
5408 {"basic_init", mono_image_module_basic_init},
5409 {"build_metadata", ves_icall_ModuleBuilder_build_metadata},
5410 {"create_modified_type", ves_icall_ModuleBuilder_create_modified_type},
5411 {"getDataChunk", ves_icall_ModuleBuilder_getDataChunk},
5412 {"getToken", ves_icall_ModuleBuilder_getToken},
5413 {"getUSIndex", mono_image_insert_string}
5416 static const IcallEntry signaturehelper_icalls [] = {
5417 {"get_signature_field", mono_reflection_sighelper_get_signature_field},
5418 {"get_signature_local", mono_reflection_sighelper_get_signature_local}
5421 static const IcallEntry typebuilder_icalls [] = {
5422 {"create_internal_class", mono_reflection_create_internal_class},
5423 {"create_runtime_class", mono_reflection_create_runtime_class},
5424 {"get_IsGenericParameter", ves_icall_TypeBuilder_get_IsGenericParameter},
5425 {"get_event_info", mono_reflection_event_builder_get_event_info},
5426 {"setup_generic_class", mono_reflection_setup_generic_class},
5427 {"setup_internal_class", mono_reflection_setup_internal_class}
5430 static const IcallEntry runtimehelpers_icalls [] = {
5431 {"GetObjectValue", ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetObjectValue},
5432 {"GetOffsetToStringData", ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetOffsetToStringData},
5433 {"InitializeArray", ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_InitializeArray},
5434 {"RunClassConstructor", ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_RunClassConstructor}
5437 static const IcallEntry gchandle_icalls [] = {
5438 {"FreeHandle", ves_icall_System_GCHandle_FreeHandle},
5439 {"GetAddrOfPinnedObject", ves_icall_System_GCHandle_GetAddrOfPinnedObject},
5440 {"GetTarget", ves_icall_System_GCHandle_GetTarget},
5441 {"GetTargetHandle", ves_icall_System_GCHandle_GetTargetHandle}
5444 static const IcallEntry marshal_icalls [] = {
5445 {"AllocCoTaskMem", ves_icall_System_Runtime_InteropServices_Marshal_AllocCoTaskMem},
5446 {"AllocHGlobal", mono_marshal_alloc},
5447 {"DestroyStructure", ves_icall_System_Runtime_InteropServices_Marshal_DestroyStructure},
5448 {"FreeCoTaskMem", ves_icall_System_Runtime_InteropServices_Marshal_FreeCoTaskMem},
5449 {"FreeHGlobal", mono_marshal_free},
5450 {"GetLastWin32Error", ves_icall_System_Runtime_InteropServices_Marshal_GetLastWin32Error},
5451 {"OffsetOf", ves_icall_System_Runtime_InteropServices_Marshal_OffsetOf},
5452 {"Prelink", ves_icall_System_Runtime_InteropServices_Marshal_Prelink},
5453 {"PrelinkAll", ves_icall_System_Runtime_InteropServices_Marshal_PrelinkAll},
5454 {"PtrToStringAnsi(intptr)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi},
5455 {"PtrToStringAnsi(intptr,int)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi_len},
5456 {"PtrToStringAuto(intptr)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi},
5457 {"PtrToStringAuto(intptr,int)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi_len},
5458 {"PtrToStringBSTR", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringBSTR},
5459 {"PtrToStringUni(intptr)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringUni},
5460 {"PtrToStringUni(intptr,int)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringUni_len},
5461 {"PtrToStructure(intptr,System.Type)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStructure_type},
5462 {"PtrToStructure(intptr,object)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStructure},
5463 {"ReAllocHGlobal", mono_marshal_realloc},
5464 {"ReadByte", ves_icall_System_Runtime_InteropServices_Marshal_ReadByte},
5465 {"ReadInt16", ves_icall_System_Runtime_InteropServices_Marshal_ReadInt16},
5466 {"ReadInt32", ves_icall_System_Runtime_InteropServices_Marshal_ReadInt32},
5467 {"ReadInt64", ves_icall_System_Runtime_InteropServices_Marshal_ReadInt64},
5468 {"ReadIntPtr", ves_icall_System_Runtime_InteropServices_Marshal_ReadIntPtr},
5469 {"SizeOf", ves_icall_System_Runtime_InteropServices_Marshal_SizeOf},
5470 {"StringToHGlobalAnsi", ves_icall_System_Runtime_InteropServices_Marshal_StringToHGlobalAnsi},
5471 {"StringToHGlobalAuto", ves_icall_System_Runtime_InteropServices_Marshal_StringToHGlobalAnsi},
5472 {"StringToHGlobalUni", ves_icall_System_Runtime_InteropServices_Marshal_StringToHGlobalUni},
5473 {"StructureToPtr", ves_icall_System_Runtime_InteropServices_Marshal_StructureToPtr},
5474 {"UnsafeAddrOfPinnedArrayElement", ves_icall_System_Runtime_InteropServices_Marshal_UnsafeAddrOfPinnedArrayElement},
5475 {"WriteByte", ves_icall_System_Runtime_InteropServices_Marshal_WriteByte},
5476 {"WriteInt16", ves_icall_System_Runtime_InteropServices_Marshal_WriteInt16},
5477 {"WriteInt32", ves_icall_System_Runtime_InteropServices_Marshal_WriteInt32},
5478 {"WriteInt64", ves_icall_System_Runtime_InteropServices_Marshal_WriteInt64},
5479 {"WriteIntPtr", ves_icall_System_Runtime_InteropServices_Marshal_WriteIntPtr},
5480 {"copy_from_unmanaged", ves_icall_System_Runtime_InteropServices_Marshal_copy_from_unmanaged},
5481 {"copy_to_unmanaged", ves_icall_System_Runtime_InteropServices_Marshal_copy_to_unmanaged}
5484 static const IcallEntry activationservices_icalls [] = {
5485 {"AllocateUninitializedClassInstance", ves_icall_System_Runtime_Activation_ActivationServices_AllocateUninitializedClassInstance},
5486 {"EnableProxyActivation", ves_icall_System_Runtime_Activation_ActivationServices_EnableProxyActivation}
5489 static const IcallEntry monomethodmessage_icalls [] = {
5490 {"InitMessage", ves_icall_MonoMethodMessage_InitMessage}
5493 static const IcallEntry realproxy_icalls [] = {
5494 {"InternalGetProxyType", ves_icall_Remoting_RealProxy_InternalGetProxyType},
5495 {"InternalGetTransparentProxy", ves_icall_Remoting_RealProxy_GetTransparentProxy}
5498 static const IcallEntry remotingservices_icalls [] = {
5499 {"InternalExecute", ves_icall_InternalExecute},
5500 {"IsTransparentProxy", ves_icall_IsTransparentProxy}
5503 static const IcallEntry rng_icalls [] = {
5504 {"RngClose", ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngClose},
5505 {"RngGetBytes", ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngGetBytes},
5506 {"RngInitialize", ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngInitialize}
5509 static const IcallEntry methodhandle_icalls [] = {
5510 {"GetFunctionPointer", ves_icall_RuntimeMethod_GetFunctionPointer}
5513 static const IcallEntry string_icalls [] = {
5514 {".ctor(char*)", ves_icall_System_String_ctor_charp},
5515 {".ctor(char*,int,int)", ves_icall_System_String_ctor_charp_int_int},
5516 {".ctor(char,int)", ves_icall_System_String_ctor_char_int},
5517 {".ctor(char[])", ves_icall_System_String_ctor_chara},
5518 {".ctor(char[],int,int)", ves_icall_System_String_ctor_chara_int_int},
5519 {".ctor(sbyte*)", ves_icall_System_String_ctor_sbytep},
5520 {".ctor(sbyte*,int,int)", ves_icall_System_String_ctor_sbytep_int_int},
5521 {".ctor(sbyte*,int,int,System.Text.Encoding)", ves_icall_System_String_ctor_encoding},
5522 {"GetHashCode", ves_icall_System_String_GetHashCode},
5523 {"InternalAllocateStr", ves_icall_System_String_InternalAllocateStr},
5524 {"InternalCharCopy", ves_icall_System_String_InternalCharCopy},
5525 {"InternalCopyTo", ves_icall_System_String_InternalCopyTo},
5526 {"InternalIndexOfAny", ves_icall_System_String_InternalIndexOfAny},
5527 {"InternalInsert", ves_icall_System_String_InternalInsert},
5528 {"InternalIntern", ves_icall_System_String_InternalIntern},
5529 {"InternalIsInterned", ves_icall_System_String_InternalIsInterned},
5530 {"InternalJoin", ves_icall_System_String_InternalJoin},
5531 {"InternalLastIndexOfAny", ves_icall_System_String_InternalLastIndexOfAny},
5532 {"InternalPad", ves_icall_System_String_InternalPad},
5533 {"InternalRemove", ves_icall_System_String_InternalRemove},
5534 {"InternalReplace(char,char)", ves_icall_System_String_InternalReplace_Char},
5535 {"InternalReplace(string,string,System.Globalization.CompareInfo)", ves_icall_System_String_InternalReplace_Str_Comp},
5536 {"InternalSplit", ves_icall_System_String_InternalSplit},
5537 {"InternalStrcpy(string,int,char[])", ves_icall_System_String_InternalStrcpy_Chars},
5538 {"InternalStrcpy(string,int,char[],int,int)", ves_icall_System_String_InternalStrcpy_CharsN},
5539 {"InternalStrcpy(string,int,string)", ves_icall_System_String_InternalStrcpy_Str},
5540 {"InternalStrcpy(string,int,string,int,int)", ves_icall_System_String_InternalStrcpy_StrN},
5541 {"InternalToLower(System.Globalization.CultureInfo)", ves_icall_System_String_InternalToLower_Comp},
5542 {"InternalToUpper(System.Globalization.CultureInfo)", ves_icall_System_String_InternalToUpper_Comp},
5543 {"InternalTrim", ves_icall_System_String_InternalTrim},
5544 {"get_Chars", ves_icall_System_String_get_Chars}
5547 static const IcallEntry encoding_icalls [] = {
5548 {"InternalCodePage", ves_icall_System_Text_Encoding_InternalCodePage}
5551 static const IcallEntry monitor_icalls [] = {
5552 {"Monitor_exit", ves_icall_System_Threading_Monitor_Monitor_exit},
5553 {"Monitor_pulse", ves_icall_System_Threading_Monitor_Monitor_pulse},
5554 {"Monitor_pulse_all", ves_icall_System_Threading_Monitor_Monitor_pulse_all},
5555 {"Monitor_test_owner", ves_icall_System_Threading_Monitor_Monitor_test_owner},
5556 {"Monitor_test_synchronised", ves_icall_System_Threading_Monitor_Monitor_test_synchronised},
5557 {"Monitor_try_enter", ves_icall_System_Threading_Monitor_Monitor_try_enter},
5558 {"Monitor_wait", ves_icall_System_Threading_Monitor_Monitor_wait}
5561 static const IcallEntry interlocked_icalls [] = {
5562 {"CompareExchange(int&,int,int)", ves_icall_System_Threading_Interlocked_CompareExchange_Int},
5563 {"CompareExchange(object&,object,object)", ves_icall_System_Threading_Interlocked_CompareExchange_Object},
5564 {"CompareExchange(single&,single,single)", ves_icall_System_Threading_Interlocked_CompareExchange_Single},
5565 {"Decrement(int&)", ves_icall_System_Threading_Interlocked_Decrement_Int},
5566 {"Decrement(long&)", ves_icall_System_Threading_Interlocked_Decrement_Long},
5567 {"Exchange(int&,int)", ves_icall_System_Threading_Interlocked_Exchange_Int},
5568 {"Exchange(object&,object)", ves_icall_System_Threading_Interlocked_Exchange_Object},
5569 {"Exchange(single&,single)", ves_icall_System_Threading_Interlocked_Exchange_Single},
5570 {"Increment(int&)", ves_icall_System_Threading_Interlocked_Increment_Int},
5571 {"Increment(long&)", ves_icall_System_Threading_Interlocked_Increment_Long}
5574 static const IcallEntry mutex_icalls [] = {
5575 {"CreateMutex_internal", ves_icall_System_Threading_Mutex_CreateMutex_internal},
5576 {"ReleaseMutex_internal", ves_icall_System_Threading_Mutex_ReleaseMutex_internal}
5579 static const IcallEntry nativeevents_icalls [] = {
5580 {"CloseEvent_internal", ves_icall_System_Threading_Events_CloseEvent_internal},
5581 {"CreateEvent_internal", ves_icall_System_Threading_Events_CreateEvent_internal},
5582 {"ResetEvent_internal", ves_icall_System_Threading_Events_ResetEvent_internal},
5583 {"SetEvent_internal", ves_icall_System_Threading_Events_SetEvent_internal}
5586 static const IcallEntry thread_icalls [] = {
5587 {"Abort_internal(object)", ves_icall_System_Threading_Thread_Abort},
5588 {"CurrentThread_internal", mono_thread_current},
5589 {"GetDomainID", ves_icall_System_Threading_Thread_GetDomainID},
5590 {"GetName_internal", ves_icall_System_Threading_Thread_GetName_internal},
5591 {"Join_internal", ves_icall_System_Threading_Thread_Join_internal},
5592 {"ResetAbort_internal()", ves_icall_System_Threading_Thread_ResetAbort},
5593 {"Resume_internal()", ves_icall_System_Threading_Thread_Resume},
5594 {"SetName_internal", ves_icall_System_Threading_Thread_SetName_internal},
5595 {"Sleep_internal", ves_icall_System_Threading_Thread_Sleep_internal},
5596 {"SlotHash_lookup", ves_icall_System_Threading_Thread_SlotHash_lookup},
5597 {"SlotHash_store", ves_icall_System_Threading_Thread_SlotHash_store},
5598 {"Start_internal", ves_icall_System_Threading_Thread_Start_internal},
5599 {"Suspend_internal", ves_icall_System_Threading_Thread_Suspend},
5600 {"Thread_free_internal", ves_icall_System_Threading_Thread_Thread_free_internal},
5601 {"Thread_internal", ves_icall_System_Threading_Thread_Thread_internal},
5602 {"VolatileRead(IntPtr&)", ves_icall_System_Threading_Thread_VolatileReadIntPtr},
5603 {"VolatileRead(UIntPtr&)", ves_icall_System_Threading_Thread_VolatileReadIntPtr},
5604 {"VolatileRead(byte&)", ves_icall_System_Threading_Thread_VolatileRead1},
5605 {"VolatileRead(double&)", ves_icall_System_Threading_Thread_VolatileRead8},
5606 {"VolatileRead(float&)", ves_icall_System_Threading_Thread_VolatileRead4},
5607 {"VolatileRead(int&)", ves_icall_System_Threading_Thread_VolatileRead4},
5608 {"VolatileRead(long&)", ves_icall_System_Threading_Thread_VolatileRead8},
5609 {"VolatileRead(object&)", ves_icall_System_Threading_Thread_VolatileReadIntPtr},
5610 {"VolatileRead(sbyte&)", ves_icall_System_Threading_Thread_VolatileRead1},
5611 {"VolatileRead(short&)", ves_icall_System_Threading_Thread_VolatileRead2},
5612 {"VolatileRead(uint&)", ves_icall_System_Threading_Thread_VolatileRead2},
5613 {"VolatileRead(ulong&)", ves_icall_System_Threading_Thread_VolatileRead8},
5614 {"VolatileRead(ushort&)", ves_icall_System_Threading_Thread_VolatileRead2},
5615 {"VolatileWrite(IntPtr&,IntPtr)", ves_icall_System_Threading_Thread_VolatileWriteIntPtr},
5616 {"VolatileWrite(UIntPtr&,UIntPtr)", ves_icall_System_Threading_Thread_VolatileWriteIntPtr},
5617 {"VolatileWrite(byte&,byte)", ves_icall_System_Threading_Thread_VolatileWrite1},
5618 {"VolatileWrite(double&,double)", ves_icall_System_Threading_Thread_VolatileWrite8},
5619 {"VolatileWrite(float&,float)", ves_icall_System_Threading_Thread_VolatileWrite4},
5620 {"VolatileWrite(int&,int)", ves_icall_System_Threading_Thread_VolatileWrite4},
5621 {"VolatileWrite(long&,long)", ves_icall_System_Threading_Thread_VolatileWrite8},
5622 {"VolatileWrite(object&,object)", ves_icall_System_Threading_Thread_VolatileWriteIntPtr},
5623 {"VolatileWrite(sbyte&,sbyte)", ves_icall_System_Threading_Thread_VolatileWrite1},
5624 {"VolatileWrite(short&,short)", ves_icall_System_Threading_Thread_VolatileWrite2},
5625 {"VolatileWrite(uint&,uint)", ves_icall_System_Threading_Thread_VolatileWrite2},
5626 {"VolatileWrite(ulong&,ulong)", ves_icall_System_Threading_Thread_VolatileWrite8},
5627 {"VolatileWrite(ushort&,ushort)", ves_icall_System_Threading_Thread_VolatileWrite2},
5628 {"current_lcid()", ves_icall_System_Threading_Thread_current_lcid}
5631 static const IcallEntry threadpool_icalls [] = {
5632 {"BindHandleInternal", ves_icall_System_Threading_ThreadPool_BindHandle},
5633 {"GetAvailableThreads", ves_icall_System_Threading_ThreadPool_GetAvailableThreads},
5634 {"GetMaxThreads", ves_icall_System_Threading_ThreadPool_GetMaxThreads},
5635 {"GetMinThreads", ves_icall_System_Threading_ThreadPool_GetMinThreads},
5636 {"SetMinThreads", ves_icall_System_Threading_ThreadPool_SetMinThreads}
5639 static const IcallEntry waithandle_icalls [] = {
5640 {"WaitAll_internal", ves_icall_System_Threading_WaitHandle_WaitAll_internal},
5641 {"WaitAny_internal", ves_icall_System_Threading_WaitHandle_WaitAny_internal},
5642 {"WaitOne_internal", ves_icall_System_Threading_WaitHandle_WaitOne_internal}
5645 static const IcallEntry type_icalls [] = {
5646 {"BindGenericParameters", ves_icall_Type_BindGenericParameters},
5647 {"Equals", ves_icall_type_Equals},
5648 {"GetGenericParameterPosition", ves_icall_Type_GetGenericParameterPosition},
5649 {"GetGenericTypeDefinition_impl", ves_icall_Type_GetGenericTypeDefinition_impl},
5650 {"GetInterfaceMapData", ves_icall_Type_GetInterfaceMapData},
5651 {"GetTypeCode", ves_icall_type_GetTypeCode},
5652 {"IsArrayImpl", ves_icall_Type_IsArrayImpl},
5653 {"IsInstanceOfType", ves_icall_type_IsInstanceOfType},
5654 {"get_IsGenericInstance", ves_icall_Type_get_IsGenericInstance},
5655 {"get_IsGenericTypeDefinition", ves_icall_Type_get_IsGenericTypeDefinition},
5656 {"internal_from_handle", ves_icall_type_from_handle},
5657 {"internal_from_name", ves_icall_type_from_name},
5658 {"make_array_type", ves_icall_Type_make_array_type},
5659 {"make_byref_type", ves_icall_Type_make_byref_type},
5660 {"type_is_assignable_from", ves_icall_type_is_assignable_from},
5661 {"type_is_subtype_of", ves_icall_type_is_subtype_of}
5664 static const IcallEntry typedref_icalls [] = {
5665 {"ToObject", mono_TypedReference_ToObject}
5668 static const IcallEntry valuetype_icalls [] = {
5669 {"InternalEquals", ves_icall_System_ValueType_Equals},
5670 {"InternalGetHashCode", ves_icall_System_ValueType_InternalGetHashCode}
5673 static const IcallEntry web_icalls [] = {
5674 {"GetMachineConfigPath", ves_icall_System_Configuration_DefaultConfig_get_machine_config_path},
5675 {"GetMachineInstallDirectory", ves_icall_System_Web_Util_ICalls_get_machine_install_dir}
5678 static const IcallEntry identity_icalls [] = {
5679 {"GetCurrentToken", ves_icall_System_Security_Principal_WindowsIdentity_GetCurrentToken},
5680 {"GetTokenName", ves_icall_System_Security_Principal_WindowsIdentity_GetTokenName},
5681 {"GetUserToken", ves_icall_System_Security_Principal_WindowsIdentity_GetUserToken},
5682 {"_GetRoles", ves_icall_System_Security_Principal_WindowsIdentity_GetRoles}
5685 static const IcallEntry impersonation_icalls [] = {
5686 {"CloseToken", ves_icall_System_Security_Principal_WindowsImpersonationContext_CloseToken},
5687 {"DuplicateToken", ves_icall_System_Security_Principal_WindowsImpersonationContext_DuplicateToken},
5688 {"RevertToSelf", ves_icall_System_Security_Principal_WindowsImpersonationContext_RevertToSelf},
5689 {"SetCurrentToken", ves_icall_System_Security_Principal_WindowsImpersonationContext_SetCurrentToken}
5692 static const IcallEntry principal_icalls [] = {
5693 {"IsMemberOfGroupId", ves_icall_System_Security_Principal_WindowsPrincipal_IsMemberOfGroupId},
5694 {"IsMemberOfGroupName", ves_icall_System_Security_Principal_WindowsPrincipal_IsMemberOfGroupName}
5697 static const IcallEntry keypair_icalls [] = {
5698 {"_CanSecure", ves_icall_Mono_Security_Cryptography_KeyPairPersistence_CanSecure},
5699 {"_IsMachineProtected", ves_icall_Mono_Security_Cryptography_KeyPairPersistence_IsMachineProtected},
5700 {"_IsUserProtected", ves_icall_Mono_Security_Cryptography_KeyPairPersistence_IsUserProtected},
5701 {"_ProtectMachine", ves_icall_Mono_Security_Cryptography_KeyPairPersistence_ProtectMachine},
5702 {"_ProtectUser", ves_icall_Mono_Security_Cryptography_KeyPairPersistence_ProtectUser}
5706 static const IcallEntry array_icalls [] = {
5711 /* keep the entries all sorted */
5712 static const IcallMap icall_entries [] = {
5713 {"Mono.Security.Cryptography.KeyPairPersistence", keypair_icalls, G_N_ELEMENTS (keypair_icalls)},
5714 {"System.Activator", activator_icalls, G_N_ELEMENTS (activator_icalls)},
5715 {"System.AppDomain", appdomain_icalls, G_N_ELEMENTS (appdomain_icalls)},
5716 {"System.ArgIterator", argiterator_icalls, G_N_ELEMENTS (argiterator_icalls)},
5717 {"System.Array", array_icalls, G_N_ELEMENTS (array_icalls)},
5718 {"System.Buffer", buffer_icalls, G_N_ELEMENTS (buffer_icalls)},
5719 {"System.Char", char_icalls, G_N_ELEMENTS (char_icalls)},
5720 {"System.Configuration.DefaultConfig", defaultconf_icalls, G_N_ELEMENTS (defaultconf_icalls)},
5721 {"System.CurrentTimeZone", timezone_icalls, G_N_ELEMENTS (timezone_icalls)},
5722 {"System.DateTime", datetime_icalls, G_N_ELEMENTS (datetime_icalls)},
5723 {"System.Decimal", decimal_icalls, G_N_ELEMENTS (decimal_icalls)},
5724 {"System.Delegate", delegate_icalls, G_N_ELEMENTS (delegate_icalls)},
5725 {"System.Diagnostics.DefaultTraceListener", tracelist_icalls, G_N_ELEMENTS (tracelist_icalls)},
5726 {"System.Diagnostics.FileVersionInfo", fileversion_icalls, G_N_ELEMENTS (fileversion_icalls)},
5727 {"System.Diagnostics.Process", process_icalls, G_N_ELEMENTS (process_icalls)},
5728 {"System.Double", double_icalls, G_N_ELEMENTS (double_icalls)},
5729 {"System.Enum", enum_icalls, G_N_ELEMENTS (enum_icalls)},
5730 {"System.Environment", environment_icalls, G_N_ELEMENTS (environment_icalls)},
5731 {"System.GC", gc_icalls, G_N_ELEMENTS (gc_icalls)},
5732 {"System.Globalization.CompareInfo", compareinfo_icalls, G_N_ELEMENTS (compareinfo_icalls)},
5733 {"System.Globalization.CultureInfo", cultureinfo_icalls, G_N_ELEMENTS (cultureinfo_icalls)},
5734 {"System.IO.FAMWatcher", famwatcher_icalls, G_N_ELEMENTS (famwatcher_icalls)},
5735 {"System.IO.FileSystemWatcher", filewatcher_icalls, G_N_ELEMENTS (filewatcher_icalls)},
5736 {"System.IO.MonoIO", monoio_icalls, G_N_ELEMENTS (monoio_icalls)},
5737 {"System.IO.Path", path_icalls, G_N_ELEMENTS (path_icalls)},
5738 {"System.Math", math_icalls, G_N_ELEMENTS (math_icalls)},
5739 {"System.MonoCustomAttrs", customattrs_icalls, G_N_ELEMENTS (customattrs_icalls)},
5740 {"System.MonoEnumInfo", enuminfo_icalls, G_N_ELEMENTS (enuminfo_icalls)},
5741 {"System.MonoType", monotype_icalls, G_N_ELEMENTS (monotype_icalls)},
5742 {"System.Net.Dns", dns_icalls, G_N_ELEMENTS (dns_icalls)},
5743 {"System.Net.Sockets.Socket", socket_icalls, G_N_ELEMENTS (socket_icalls)},
5744 {"System.Net.Sockets.SocketException", socketex_icalls, G_N_ELEMENTS (socketex_icalls)},
5745 {"System.Object", object_icalls, G_N_ELEMENTS (object_icalls)},
5746 {"System.Reflection.Assembly", assembly_icalls, G_N_ELEMENTS (assembly_icalls)},
5747 {"System.Reflection.Emit.AssemblyBuilder", assemblybuilder_icalls, G_N_ELEMENTS (assemblybuilder_icalls)},
5748 {"System.Reflection.Emit.CustomAttributeBuilder", customattrbuilder_icalls, G_N_ELEMENTS (customattrbuilder_icalls)},
5749 {"System.Reflection.Emit.DynamicMethod", dynamicmethod_icalls, G_N_ELEMENTS (dynamicmethod_icalls)},
5750 {"System.Reflection.Emit.GenericTypeParameterBuilder", generictypeparambuilder_icalls, G_N_ELEMENTS (generictypeparambuilder_icalls)},
5751 {"System.Reflection.Emit.MethodBuilder", methodbuilder_icalls, G_N_ELEMENTS (methodbuilder_icalls)},
5752 {"System.Reflection.Emit.ModuleBuilder", modulebuilder_icalls, G_N_ELEMENTS (modulebuilder_icalls)},
5753 {"System.Reflection.Emit.SignatureHelper", signaturehelper_icalls, G_N_ELEMENTS (signaturehelper_icalls)},
5754 {"System.Reflection.Emit.TypeBuilder", typebuilder_icalls, G_N_ELEMENTS (typebuilder_icalls)},
5755 {"System.Reflection.FieldInfo", fieldinfo_icalls, G_N_ELEMENTS (fieldinfo_icalls)},
5756 {"System.Reflection.MethodBase", methodbase_icalls, G_N_ELEMENTS (methodbase_icalls)},
5757 {"System.Reflection.Module", module_icalls, G_N_ELEMENTS (module_icalls)},
5758 {"System.Reflection.MonoCMethod", monocmethod_icalls, G_N_ELEMENTS (monocmethod_icalls)},
5759 {"System.Reflection.MonoEventInfo", monoeventinfo_icalls, G_N_ELEMENTS (monoeventinfo_icalls)},
5760 {"System.Reflection.MonoField", monofield_icalls, G_N_ELEMENTS (monofield_icalls)},
5761 {"System.Reflection.MonoGenericInst", monogenericinst_icalls, G_N_ELEMENTS (monogenericinst_icalls)},
5762 {"System.Reflection.MonoMethod", monomethod_icalls, G_N_ELEMENTS (monomethod_icalls)},
5763 {"System.Reflection.MonoMethodInfo", monomethodinfo_icalls, G_N_ELEMENTS (monomethodinfo_icalls)},
5764 {"System.Reflection.MonoPropertyInfo", monopropertyinfo_icalls, G_N_ELEMENTS (monopropertyinfo_icalls)},
5765 {"System.Runtime.CompilerServices.RuntimeHelpers", runtimehelpers_icalls, G_N_ELEMENTS (runtimehelpers_icalls)},
5766 {"System.Runtime.InteropServices.GCHandle", gchandle_icalls, G_N_ELEMENTS (gchandle_icalls)},
5767 {"System.Runtime.InteropServices.Marshal", marshal_icalls, G_N_ELEMENTS (marshal_icalls)},
5768 {"System.Runtime.Remoting.Activation.ActivationServices", activationservices_icalls, G_N_ELEMENTS (activationservices_icalls)},
5769 {"System.Runtime.Remoting.Messaging.MonoMethodMessage", monomethodmessage_icalls, G_N_ELEMENTS (monomethodmessage_icalls)},
5770 {"System.Runtime.Remoting.Proxies.RealProxy", realproxy_icalls, G_N_ELEMENTS (realproxy_icalls)},
5771 {"System.Runtime.Remoting.RemotingServices", remotingservices_icalls, G_N_ELEMENTS (remotingservices_icalls)},
5772 {"System.RuntimeMethodHandle", methodhandle_icalls, G_N_ELEMENTS (methodhandle_icalls)},
5773 {"System.Security.Cryptography.RNGCryptoServiceProvider", rng_icalls, G_N_ELEMENTS (rng_icalls)},
5774 {"System.Security.Principal.WindowsIdentity", identity_icalls, G_N_ELEMENTS (identity_icalls)},
5775 {"System.Security.Principal.WindowsImpersonationContext", impersonation_icalls, G_N_ELEMENTS (impersonation_icalls)},
5776 {"System.Security.Principal.WindowsPrincipal", principal_icalls, G_N_ELEMENTS (principal_icalls)},
5777 {"System.String", string_icalls, G_N_ELEMENTS (string_icalls)},
5778 {"System.Text.Encoding", encoding_icalls, G_N_ELEMENTS (encoding_icalls)},
5779 {"System.Threading.Interlocked", interlocked_icalls, G_N_ELEMENTS (interlocked_icalls)},
5780 {"System.Threading.Monitor", monitor_icalls, G_N_ELEMENTS (monitor_icalls)},
5781 {"System.Threading.Mutex", mutex_icalls, G_N_ELEMENTS (mutex_icalls)},
5782 {"System.Threading.NativeEventCalls", nativeevents_icalls, G_N_ELEMENTS (nativeevents_icalls)},
5783 {"System.Threading.Thread", thread_icalls, G_N_ELEMENTS (thread_icalls)},
5784 {"System.Threading.ThreadPool", threadpool_icalls, G_N_ELEMENTS (threadpool_icalls)},
5785 {"System.Threading.WaitHandle", waithandle_icalls, G_N_ELEMENTS (waithandle_icalls)},
5786 {"System.Type", type_icalls, G_N_ELEMENTS (type_icalls)},
5787 {"System.TypedReference", typedref_icalls, G_N_ELEMENTS (typedref_icalls)},
5788 {"System.ValueType", valuetype_icalls, G_N_ELEMENTS (valuetype_icalls)},
5789 {"System.Web.Util.ICalls", web_icalls, G_N_ELEMENTS (web_icalls)}
5792 static GHashTable *icall_hash = NULL;
5795 mono_init_icall (void)
5799 /* check that tables are sorted: disable in release */
5802 const IcallMap *imap;
5803 const IcallEntry *ientry;
5804 const char *prev_class = NULL;
5805 const char *prev_method;
5807 for (i = 0; i < G_N_ELEMENTS (icall_entries); ++i) {
5808 imap = &icall_entries [i];
5810 if (prev_class && strcmp (prev_class, imap->klass) >= 0)
5811 g_print ("class %s should come before class %s\n", imap->klass, prev_class);
5812 prev_class = imap->klass;
5813 for (j = 0; j < imap->size; ++j) {
5814 ientry = &imap->icalls [j];
5815 if (prev_method && strcmp (prev_method, ientry->method) >= 0)
5816 g_print ("method %s should come before method %s\n", ientry->method, prev_method);
5817 prev_method = ientry->method;
5822 icall_hash = g_hash_table_new (g_str_hash , g_str_equal);
5826 mono_add_internal_call (const char *name, gconstpointer method)
5828 mono_loader_lock ();
5830 g_hash_table_insert (icall_hash, g_strdup (name), (gpointer) method);
5832 mono_loader_unlock ();
5836 compare_class_imap (const void *key, const void *elem)
5838 const IcallMap* imap = (const IcallMap*)elem;
5839 return strcmp (key, imap->klass);
5842 static const IcallMap*
5843 find_class_icalls (const char *name)
5845 return (const IcallMap*) bsearch (name, icall_entries, G_N_ELEMENTS (icall_entries), sizeof (IcallMap), compare_class_imap);
5849 compare_method_imap (const void *key, const void *elem)
5851 const IcallEntry* ientry = (const IcallEntry*)elem;
5852 return strcmp (key, ientry->method);
5856 find_method_icall (const IcallMap *imap, const char *name)
5858 const IcallEntry *ientry = (const IcallEntry*) bsearch (name, imap->icalls, imap->size, sizeof (IcallEntry), compare_method_imap);
5860 return (void*)ientry->func;
5865 * we should probably export this as an helper (handle nested types).
5866 * Returns the number of chars written in buf.
5869 concat_class_name (char *buf, int bufsize, MonoClass *klass)
5871 int nspacelen, cnamelen;
5872 nspacelen = strlen (klass->name_space);
5873 cnamelen = strlen (klass->name);
5874 if (nspacelen + cnamelen + 2 > bufsize)
5877 memcpy (buf, klass->name_space, nspacelen);
5878 buf [nspacelen ++] = '.';
5880 memcpy (buf + nspacelen, klass->name, cnamelen);
5881 buf [nspacelen + cnamelen] = 0;
5882 return nspacelen + cnamelen;
5886 mono_lookup_internal_call (MonoMethod *method)
5891 int typelen = 0, mlen, siglen;
5893 const IcallMap *imap;
5895 g_assert (method != NULL);
5897 typelen = concat_class_name (mname, sizeof (mname), method->klass);
5901 imap = find_class_icalls (mname);
5903 mname [typelen] = ':';
5904 mname [typelen + 1] = ':';
5906 mlen = strlen (method->name);
5907 memcpy (mname + typelen + 2, method->name, mlen);
5908 sigstart = mname + typelen + 2 + mlen;
5911 tmpsig = mono_signature_get_desc (method->signature, TRUE);
5912 siglen = strlen (tmpsig);
5913 if (typelen + mlen + siglen + 6 > sizeof (mname))
5916 memcpy (sigstart + 1, tmpsig, siglen);
5917 sigstart [siglen + 1] = ')';
5918 sigstart [siglen + 2] = 0;
5921 mono_loader_lock ();
5923 res = g_hash_table_lookup (icall_hash, mname);
5925 mono_loader_unlock ();
5928 /* try without signature */
5930 res = g_hash_table_lookup (icall_hash, mname);
5932 mono_loader_unlock ();
5936 /* it wasn't found in the static call tables */
5938 mono_loader_unlock ();
5941 res = find_method_icall (imap, sigstart - mlen);
5943 mono_loader_unlock ();
5946 /* try _with_ signature */
5948 res = find_method_icall (imap, sigstart - mlen);
5950 mono_loader_unlock ();
5954 g_warning ("cant resolve internal call to \"%s\" (tested without signature also)", mname);
5955 g_print ("\nYour mono runtime and class libraries are out of sync.\n");
5956 g_print ("The out of sync library is: %s\n", method->klass->image->name);
5957 g_print ("\nWhen you update one from cvs you need to update, compile and install\nthe other too.\n");
5958 g_print ("Do not report this as a bug unless you're sure you have updated correctly:\nyou probably have a broken mono install.\n");
5959 g_print ("If you see other errors or faults after this message they are probably related\n");
5960 g_print ("and you need to fix your mono install first.\n");
5962 mono_loader_unlock ();