5 * Dietmar Maurer (dietmar@ximian.com)
6 * Paolo Molaro (lupus@ximian.com)
7 * Patrik Torstensson (patrik.torstensson@labs2.com)
9 * (C) 2001 Ximian, Inc.
18 #if defined (PLATFORM_WIN32)
22 #include <mono/metadata/object.h>
23 #include <mono/metadata/threads.h>
24 #include <mono/metadata/monitor.h>
25 #include <mono/metadata/reflection.h>
26 #include <mono/metadata/assembly.h>
27 #include <mono/metadata/tabledefs.h>
28 #include <mono/metadata/exception.h>
29 #include <mono/metadata/file-io.h>
30 #include <mono/metadata/socket-io.h>
31 #include <mono/metadata/mono-endian.h>
32 #include <mono/metadata/tokentype.h>
33 #include <mono/metadata/unicode.h>
34 #include <mono/metadata/appdomain.h>
35 #include <mono/metadata/marshal.h>
36 #include <mono/metadata/gc-internal.h>
37 #include <mono/metadata/rand.h>
38 #include <mono/metadata/sysmath.h>
39 #include <mono/metadata/string-icalls.h>
40 #include <mono/metadata/mono-debug-debugger.h>
41 #include <mono/metadata/process.h>
42 #include <mono/metadata/environment.h>
43 #include <mono/metadata/profiler-private.h>
44 #include <mono/metadata/locales.h>
45 #include <mono/metadata/filewatcher.h>
46 #include <mono/io-layer/io-layer.h>
47 #include <mono/utils/strtod.h>
48 #include <mono/utils/monobitset.h>
50 #if defined (PLATFORM_WIN32)
55 static MonoReflectionAssembly* ves_icall_System_Reflection_Assembly_GetCallingAssembly (void);
59 * We expect a pointer to a char, not a string
62 mono_double_ParseImpl (char *ptr)
70 result = bsd_strtod (ptr, &endptr);
72 if (!*ptr || (endptr && *endptr))
73 mono_raise_exception (mono_exception_from_name (mono_defaults.corlib,
81 ves_icall_System_Double_AssertEndianity (double *value)
85 MONO_DOUBLE_ASSERT_ENDIANITY (value);
89 ves_icall_System_Array_GetValueImpl (MonoObject *this, guint32 pos)
98 ao = (MonoArray *)this;
99 ac = (MonoClass *)ao->obj.vtable->klass;
101 esize = mono_array_element_size (ac);
102 ea = (gpointer*)((char*)ao->vector + (pos * esize));
104 if (ac->element_class->valuetype)
105 return mono_value_box (this->vtable->domain, ac->element_class, ea);
111 ves_icall_System_Array_GetValue (MonoObject *this, MonoObject *idxs)
119 MONO_CHECK_ARG_NULL (idxs);
121 io = (MonoArray *)idxs;
122 ic = (MonoClass *)io->obj.vtable->klass;
124 ao = (MonoArray *)this;
125 ac = (MonoClass *)ao->obj.vtable->klass;
127 g_assert (ic->rank == 1);
128 if (io->bounds != NULL || io->max_length != ac->rank)
129 mono_raise_exception (mono_get_exception_argument (NULL, NULL));
131 ind = (guint32 *)io->vector;
133 if (ao->bounds == NULL) {
134 if (*ind < 0 || *ind >= ao->max_length)
135 mono_raise_exception (mono_get_exception_index_out_of_range ());
137 return ves_icall_System_Array_GetValueImpl (this, *ind);
140 for (i = 0; i < ac->rank; i++)
141 if ((ind [i] < ao->bounds [i].lower_bound) ||
142 (ind [i] >= ao->bounds [i].length + ao->bounds [i].lower_bound))
143 mono_raise_exception (mono_get_exception_index_out_of_range ());
145 pos = ind [0] - ao->bounds [0].lower_bound;
146 for (i = 1; i < ac->rank; i++)
147 pos = pos*ao->bounds [i].length + ind [i] -
148 ao->bounds [i].lower_bound;
150 return ves_icall_System_Array_GetValueImpl (this, pos);
154 ves_icall_System_Array_SetValueImpl (MonoArray *this, MonoObject *value, guint32 pos)
156 MonoClass *ac, *vc, *ec;
167 vc = value->vtable->klass;
171 ac = this->obj.vtable->klass;
172 ec = ac->element_class;
174 esize = mono_array_element_size (ac);
175 ea = (gpointer*)((char*)this->vector + (pos * esize));
176 va = (gpointer*)((char*)value + sizeof (MonoObject));
179 memset (ea, 0, esize);
183 #define NO_WIDENING_CONVERSION G_STMT_START{\
184 mono_raise_exception (mono_get_exception_argument ( \
185 "value", "not a widening conversion")); \
188 #define CHECK_WIDENING_CONVERSION(extra) G_STMT_START{\
189 if (esize < vsize + (extra)) \
190 mono_raise_exception (mono_get_exception_argument ( \
191 "value", "not a widening conversion")); \
194 #define INVALID_CAST G_STMT_START{\
195 mono_raise_exception (mono_get_exception_invalid_cast ()); \
198 /* Check element (destination) type. */
199 switch (ec->byval_arg.type) {
200 case MONO_TYPE_STRING:
201 switch (vc->byval_arg.type) {
202 case MONO_TYPE_STRING:
208 case MONO_TYPE_BOOLEAN:
209 switch (vc->byval_arg.type) {
210 case MONO_TYPE_BOOLEAN:
223 NO_WIDENING_CONVERSION;
230 if (!ec->valuetype) {
231 if (!mono_object_isinst (value, ec))
233 *ea = (gpointer)value;
237 if (mono_object_isinst (value, ec)) {
238 memcpy (ea, (char *)value + sizeof (MonoObject), esize);
245 vsize = mono_class_instance_size (vc) - sizeof (MonoObject);
248 g_message (G_STRLOC ": %d (%d) <= %d (%d)",
249 ec->byval_arg.type, esize,
250 vc->byval_arg.type, vsize);
253 #define ASSIGN_UNSIGNED(etype) G_STMT_START{\
254 switch (vc->byval_arg.type) { \
259 case MONO_TYPE_CHAR: \
260 CHECK_WIDENING_CONVERSION(0); \
261 *(etype *) ea = (etype) u64; \
263 /* You can't assign a signed value to an unsigned array. */ \
268 /* You can't assign a floating point number to an integer array. */ \
271 NO_WIDENING_CONVERSION; \
275 #define ASSIGN_SIGNED(etype) G_STMT_START{\
276 switch (vc->byval_arg.type) { \
281 CHECK_WIDENING_CONVERSION(0); \
282 *(etype *) ea = (etype) i64; \
284 /* You can assign an unsigned value to a signed array if the array's */ \
285 /* element size is larger than the value size. */ \
290 case MONO_TYPE_CHAR: \
291 CHECK_WIDENING_CONVERSION(1); \
292 *(etype *) ea = (etype) u64; \
294 /* You can't assign a floating point number to an integer array. */ \
297 NO_WIDENING_CONVERSION; \
301 #define ASSIGN_REAL(etype) G_STMT_START{\
302 switch (vc->byval_arg.type) { \
305 CHECK_WIDENING_CONVERSION(0); \
306 *(etype *) ea = (etype) r64; \
308 /* All integer values fit into a floating point array, so we don't */ \
309 /* need to CHECK_WIDENING_CONVERSION here. */ \
314 *(etype *) ea = (etype) i64; \
320 case MONO_TYPE_CHAR: \
321 *(etype *) ea = (etype) u64; \
326 switch (vc->byval_arg.type) {
328 u64 = *(guint8 *) va;
331 u64 = *(guint16 *) va;
334 u64 = *(guint32 *) va;
337 u64 = *(guint64 *) va;
343 i64 = *(gint16 *) va;
346 i64 = *(gint32 *) va;
349 i64 = *(gint64 *) va;
352 r64 = *(gfloat *) va;
355 r64 = *(gdouble *) va;
358 u64 = *(guint16 *) va;
360 case MONO_TYPE_BOOLEAN:
361 /* Boolean is only compatible with itself. */
362 switch (ec->byval_arg.type) {
374 NO_WIDENING_CONVERSION;
381 /* If we can't do a direct copy, let's try a widening conversion. */
382 switch (ec->byval_arg.type) {
384 ASSIGN_UNSIGNED (guint16);
386 ASSIGN_UNSIGNED (guint8);
388 ASSIGN_UNSIGNED (guint16);
390 ASSIGN_UNSIGNED (guint32);
392 ASSIGN_UNSIGNED (guint64);
394 ASSIGN_SIGNED (gint8);
396 ASSIGN_SIGNED (gint16);
398 ASSIGN_SIGNED (gint32);
400 ASSIGN_SIGNED (gint64);
402 ASSIGN_REAL (gfloat);
404 ASSIGN_REAL (gdouble);
408 /* Not reached, INVALID_CAST does not return. Just to avoid a compiler warning ... */
412 #undef NO_WIDENING_CONVERSION
413 #undef CHECK_WIDENING_CONVERSION
414 #undef ASSIGN_UNSIGNED
420 ves_icall_System_Array_SetValue (MonoArray *this, MonoObject *value,
428 MONO_CHECK_ARG_NULL (idxs);
430 ic = idxs->obj.vtable->klass;
431 ac = this->obj.vtable->klass;
433 g_assert (ic->rank == 1);
434 if (idxs->bounds != NULL || idxs->max_length != ac->rank)
435 mono_raise_exception (mono_get_exception_argument (NULL, NULL));
437 ind = (guint32 *)idxs->vector;
439 if (this->bounds == NULL) {
440 if (*ind < 0 || *ind >= this->max_length)
441 mono_raise_exception (mono_get_exception_index_out_of_range ());
443 ves_icall_System_Array_SetValueImpl (this, value, *ind);
447 for (i = 0; i < ac->rank; i++)
448 if ((ind [i] < this->bounds [i].lower_bound) ||
449 (ind [i] >= this->bounds [i].length + this->bounds [i].lower_bound))
450 mono_raise_exception (mono_get_exception_index_out_of_range ());
452 pos = ind [0] - this->bounds [0].lower_bound;
453 for (i = 1; i < ac->rank; i++)
454 pos = pos * this->bounds [i].length + ind [i] -
455 this->bounds [i].lower_bound;
457 ves_icall_System_Array_SetValueImpl (this, value, pos);
461 ves_icall_System_Array_CreateInstanceImpl (MonoReflectionType *type, MonoArray *lengths, MonoArray *bounds)
466 gboolean bounded = FALSE;
470 MONO_CHECK_ARG_NULL (type);
471 MONO_CHECK_ARG_NULL (lengths);
473 MONO_CHECK_ARG (lengths, mono_array_length (lengths) > 0);
475 MONO_CHECK_ARG (bounds, mono_array_length (lengths) == mono_array_length (bounds));
477 for (i = 0; i < mono_array_length (lengths); i++)
478 if (mono_array_get (lengths, gint32, i) < 0)
479 mono_raise_exception (mono_get_exception_argument_out_of_range (NULL));
481 if (bounds && (mono_array_length (bounds) == 1) && (mono_array_get (bounds, gint32, 0) != 0))
482 /* vectors are not the same as one dimensional arrays with no-zero bounds */
487 aklass = mono_bounded_array_class_get (mono_class_from_mono_type (type->type), mono_array_length (lengths), bounded);
489 sizes = alloca (aklass->rank * sizeof(guint32) * 2);
490 for (i = 0; i < aklass->rank; ++i) {
491 sizes [i] = mono_array_get (lengths, gint32, i);
493 sizes [i + aklass->rank] = mono_array_get (bounds, gint32, i);
495 sizes [i + aklass->rank] = 0;
498 array = mono_array_new_full (mono_object_domain (type), aklass, sizes, sizes + aklass->rank);
504 ves_icall_System_Array_GetRank (MonoObject *this)
508 return this->vtable->klass->rank;
512 ves_icall_System_Array_GetLength (MonoArray *this, gint32 dimension)
514 gint32 rank = ((MonoObject *)this)->vtable->klass->rank;
518 if ((dimension < 0) || (dimension >= rank))
519 mono_raise_exception (mono_get_exception_index_out_of_range ());
521 if (this->bounds == NULL)
522 return this->max_length;
524 return this->bounds [dimension].length;
528 ves_icall_System_Array_GetLowerBound (MonoArray *this, gint32 dimension)
530 gint32 rank = ((MonoObject *)this)->vtable->klass->rank;
534 if ((dimension < 0) || (dimension >= rank))
535 mono_raise_exception (mono_get_exception_index_out_of_range ());
537 if (this->bounds == NULL)
540 return this->bounds [dimension].lower_bound;
544 ves_icall_System_Array_FastCopy (MonoArray *source, int source_idx, MonoArray* dest, int dest_idx, int length)
549 MonoClass *src_class;
550 MonoClass *dest_class;
555 if (source->obj.vtable->klass->rank != dest->obj.vtable->klass->rank)
558 if (source->bounds || dest->bounds)
561 if ((dest_idx + length > mono_array_length (dest)) ||
562 (source_idx + length > mono_array_length (source)))
565 element_size = mono_array_element_size (source->obj.vtable->klass);
566 dest_addr = mono_array_addr_with_size (dest, element_size, dest_idx);
567 source_addr = mono_array_addr_with_size (source, element_size, source_idx);
569 src_class = source->obj.vtable->klass->element_class;
570 dest_class = dest->obj.vtable->klass->element_class;
573 * Handle common cases.
576 /* Case1: object[] -> valuetype[] (ArrayList::ToArray) */
577 if (src_class == mono_defaults.object_class && dest_class->valuetype) {
578 for (i = source_idx; i < source_idx + length; ++i) {
579 MonoObject *elem = mono_array_get (source, MonoObject*, i);
580 if (elem && !mono_object_isinst (elem, dest_class))
584 element_size = mono_array_element_size (dest->obj.vtable->klass);
585 for (i = 0; i < length; ++i) {
586 MonoObject *elem = mono_array_get (source, MonoObject*, source_idx + i);
587 void *addr = mono_array_addr_with_size (dest, element_size, dest_idx + i);
589 memset (addr, 0, element_size);
591 memcpy (addr, (char *)elem + sizeof (MonoObject), element_size);
596 if (src_class != dest_class) {
597 if (dest_class->valuetype || dest_class->enumtype || src_class->valuetype || src_class->enumtype)
600 if (mono_class_is_subclass_of (src_class, dest_class, FALSE))
602 /* Case2: object[] -> reftype[] (ArrayList::ToArray) */
603 else if (mono_class_is_subclass_of (dest_class, src_class, FALSE))
604 for (i = source_idx; i < source_idx + length; ++i) {
605 MonoObject *elem = mono_array_get (source, MonoObject*, i);
606 if (elem && !mono_object_isinst (elem, dest_class))
613 memmove (dest_addr, source_addr, element_size * length);
619 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_InitializeArray (MonoArray *array, MonoClassField *field_handle)
621 MonoClass *klass = array->obj.vtable->klass;
622 guint32 size = mono_array_element_size (klass);
627 if (array->bounds == NULL)
628 size *= array->max_length;
630 for (i = 0; i < klass->rank; ++i)
631 size *= array->bounds [i].length;
633 memcpy (mono_array_addr (array, char, 0), field_handle->data, size);
635 #if G_BYTE_ORDER != G_LITTLE_ENDIAN
639 guint ## n *data = (guint ## n *) mono_array_addr (array, char, 0); \
641 for (i = 0; i < size; i += n/8, data++) { \
642 tmp = read ## n (data); \
647 /* printf ("Initialize array with elements of %s type\n", klass->element_class->name); */
649 switch (klass->element_class->byval_arg.type) {
669 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetOffsetToStringData (void)
673 return offsetof (MonoString, chars);
677 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetObjectValue (MonoObject *obj)
681 if ((obj == NULL) || (! (obj->vtable->klass->valuetype)))
684 return mono_object_clone (obj);
688 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_RunClassConstructor (MonoType *handle)
694 MONO_CHECK_ARG_NULL (handle);
696 klass = mono_class_from_mono_type (handle);
697 MONO_CHECK_ARG (handle, klass);
699 /* This will call the type constructor */
700 if (! (klass->flags & TYPE_ATTRIBUTE_INTERFACE))
701 mono_runtime_class_init (mono_class_vtable (mono_domain_get (), klass));
705 ves_icall_System_Object_MemberwiseClone (MonoObject *this)
709 return mono_object_clone (this);
713 #define MONO_OBJECT_ALIGNMENT_SHIFT 3
715 #define MONO_OBJECT_ALIGNMENT_SHIFT 2
719 * Return hashcode based on object address. This function will need to be
720 * smarter in the presence of a moving garbage collector, which will cache
721 * the address hash before relocating the object.
723 * Wang's address-based hash function:
724 * http://www.concentric.net/~Ttwang/tech/addrhash.htm
727 ves_icall_System_Object_GetHashCode (MonoObject *this)
729 register guint32 key;
733 key = (GPOINTER_TO_UINT (this) >> MONO_OBJECT_ALIGNMENT_SHIFT) * 2654435761u;
735 return key & 0x7fffffff;
739 ves_icall_System_ValueType_InternalGetHashCode (MonoObject *this, MonoArray **fields)
743 MonoObject **values = NULL;
750 klass = this->vtable->klass;
752 if (klass->field.count == 0)
753 return ves_icall_System_Object_GetHashCode (this);
756 * Compute the starting value of the hashcode for fields of primitive
757 * types, and return the remaining fields in an array to the managed side.
758 * This way, we can avoid costly reflection operations in managed code.
760 for (i = 0; i < klass->field.count; ++i) {
761 MonoClassField *field = &klass->fields [i];
762 if (field->type->attrs & FIELD_ATTRIBUTE_STATIC)
764 if (mono_field_is_deleted (field))
766 /* FIXME: Add more types */
767 switch (field->type->type) {
769 result ^= *(gint32*)((guint8*)this + field->offset);
771 case MONO_TYPE_STRING: {
773 s = *(MonoString**)((guint8*)this + field->offset);
775 result ^= ves_icall_System_String_GetHashCode (s);
780 values = alloca (klass->field.count * sizeof (MonoObject*));
781 o = mono_field_get_value_object (mono_object_domain (this), field, this);
782 values [count++] = o;
787 *fields = mono_array_new (mono_domain_get (), mono_defaults.object_class, count);
788 memcpy (mono_array_addr (*fields, MonoObject*, 0), values, count * sizeof (MonoObject*));
796 ves_icall_System_ValueType_Equals (MonoObject *this, MonoObject *that, MonoArray **fields)
800 MonoObject **values = NULL;
806 MONO_CHECK_ARG_NULL (that);
808 if (this->vtable != that->vtable)
811 klass = this->vtable->klass;
814 * Do the comparison for fields of primitive type and return a result if
815 * possible. Otherwise, return the remaining fields in an array to the
816 * managed side. This way, we can avoid costly reflection operations in
820 for (i = 0; i < klass->field.count; ++i) {
821 MonoClassField *field = &klass->fields [i];
822 if (field->type->attrs & FIELD_ATTRIBUTE_STATIC)
824 if (mono_field_is_deleted (field))
826 /* FIXME: Add more types */
827 switch (field->type->type) {
829 if (*(gint32*)((guint8*)this + field->offset) != *(gint32*)((guint8*)that + field->offset))
832 case MONO_TYPE_STRING: {
834 guint32 s1len, s2len;
835 s1 = *(MonoString**)((guint8*)this + field->offset);
836 s2 = *(MonoString**)((guint8*)that + field->offset);
839 if ((s1 == NULL) || (s2 == NULL))
841 s1len = mono_string_length (s1);
842 s2len = mono_string_length (s2);
846 if (memcmp (mono_string_chars (s1), mono_string_chars (s2), s1len * sizeof (gunichar2)) != 0)
852 values = alloca (klass->field.count * 2 * sizeof (MonoObject*));
853 o = mono_field_get_value_object (mono_object_domain (this), field, this);
854 values [count++] = o;
855 o = mono_field_get_value_object (mono_object_domain (this), field, that);
856 values [count++] = o;
861 *fields = mono_array_new (mono_domain_get (), mono_defaults.object_class, count);
862 memcpy (mono_array_addr (*fields, MonoObject*, 0), values, count * sizeof (MonoObject*));
870 static MonoReflectionType *
871 ves_icall_System_Object_GetType (MonoObject *obj)
875 return mono_type_get_object (mono_object_domain (obj), &obj->vtable->klass->byval_arg);
879 mono_type_type_from_obj (MonoReflectionType *mtype, MonoObject *obj)
883 mtype->type = &obj->vtable->klass->byval_arg;
884 g_assert (mtype->type->type);
888 ves_icall_ModuleBuilder_getToken (MonoReflectionModuleBuilder *mb, MonoObject *obj)
892 return mono_image_create_token (mb->dynamic_image, obj);
896 ves_icall_ModuleBuilder_getDataChunk (MonoReflectionModuleBuilder *mb, MonoArray *buf, gint32 offset)
899 MonoDynamicImage *image = mb->dynamic_image;
900 char *p = mono_array_addr (buf, char, 0);
904 mono_image_create_pefile (mb);
906 if (offset >= image->pefile.index)
908 count = mono_array_length (buf);
909 count = MIN (count, image->pefile.index - offset);
911 memcpy (p, image->pefile.data + offset, count);
917 ves_icall_ModuleBuilder_build_metadata (MonoReflectionModuleBuilder *mb)
921 mono_image_build_metadata (mb);
924 static MonoReflectionType*
925 ves_icall_type_from_name (MonoString *name,
926 MonoBoolean throwOnError,
927 MonoBoolean ignoreCase)
930 MonoType *type = NULL;
931 MonoAssembly *assembly;
932 MonoTypeNameParse info;
936 str = mono_string_to_utf8 (name);
937 if (!mono_reflection_parse_type (str, &info)) {
939 g_list_free (info.modifiers);
940 g_list_free (info.nested);
941 if (throwOnError) /* uhm: this is a parse error, though... */
942 mono_raise_exception (mono_get_exception_type_load (name));
947 if (info.assembly.name) {
948 assembly = mono_assembly_load (&info.assembly, NULL, NULL);
950 MonoReflectionAssembly *refass;
952 refass = ves_icall_System_Reflection_Assembly_GetCallingAssembly ();
953 assembly = refass->assembly;
957 type = mono_reflection_get_type (assembly->image, &info, ignoreCase);
959 if (!info.assembly.name && !type) /* try mscorlib */
960 type = mono_reflection_get_type (NULL, &info, ignoreCase);
963 g_list_free (info.modifiers);
964 g_list_free (info.nested);
967 mono_raise_exception (mono_get_exception_type_load (name));
972 return mono_type_get_object (mono_domain_get (), type);
975 static MonoReflectionType*
976 ves_icall_type_from_handle (MonoType *handle)
978 MonoDomain *domain = mono_domain_get ();
979 MonoClass *klass = mono_class_from_mono_type (handle);
983 mono_class_init (klass);
984 return mono_type_get_object (domain, handle);
988 ves_icall_type_Equals (MonoReflectionType *type, MonoReflectionType *c)
992 if (type->type && c->type)
993 return mono_metadata_type_equal (type->type, c->type);
994 g_print ("type equals\n");
998 /* System.TypeCode */
1017 TYPECODE_STRING = 18
1021 ves_icall_type_GetTypeCode (MonoReflectionType *type)
1023 int t = type->type->type;
1025 MONO_ARCH_SAVE_REGS;
1029 case MONO_TYPE_VOID:
1030 return TYPECODE_OBJECT;
1031 case MONO_TYPE_BOOLEAN:
1032 return TYPECODE_BOOLEAN;
1034 return TYPECODE_BYTE;
1036 return TYPECODE_SBYTE;
1038 return TYPECODE_UINT16;
1040 return TYPECODE_INT16;
1041 case MONO_TYPE_CHAR:
1042 return TYPECODE_CHAR;
1046 return TYPECODE_OBJECT;
1048 return TYPECODE_UINT32;
1050 return TYPECODE_INT32;
1052 return TYPECODE_UINT64;
1054 return TYPECODE_INT64;
1056 return TYPECODE_SINGLE;
1058 return TYPECODE_DOUBLE;
1059 case MONO_TYPE_VALUETYPE:
1060 if (type->type->data.klass->enumtype) {
1061 t = type->type->data.klass->enum_basetype->type;
1064 MonoClass *k = type->type->data.klass;
1065 if (strcmp (k->name_space, "System") == 0) {
1066 if (strcmp (k->name, "Decimal") == 0)
1067 return TYPECODE_DECIMAL;
1068 else if (strcmp (k->name, "DateTime") == 0)
1069 return TYPECODE_DATETIME;
1072 return TYPECODE_OBJECT;
1073 case MONO_TYPE_STRING:
1074 return TYPECODE_STRING;
1075 case MONO_TYPE_SZARRAY:
1076 case MONO_TYPE_ARRAY:
1077 case MONO_TYPE_OBJECT:
1079 case MONO_TYPE_MVAR:
1080 return TYPECODE_OBJECT;
1081 case MONO_TYPE_CLASS:
1083 MonoClass *k = type->type->data.klass;
1084 if (strcmp (k->name_space, "System") == 0) {
1085 if (strcmp (k->name, "DBNull") == 0)
1086 return TYPECODE_DBNULL;
1089 return TYPECODE_OBJECT;
1091 g_error ("type 0x%02x not handled in GetTypeCode()", t);
1097 ves_icall_type_is_subtype_of (MonoReflectionType *type, MonoReflectionType *c, MonoBoolean check_interfaces)
1103 MONO_ARCH_SAVE_REGS;
1105 g_assert (type != NULL);
1107 domain = ((MonoObject *)type)->vtable->domain;
1109 if (!c) /* FIXME: dont know what do do here */
1112 klass = mono_class_from_mono_type (type->type);
1113 klassc = mono_class_from_mono_type (c->type);
1115 return mono_class_is_subclass_of (klass, klassc, check_interfaces);
1119 ves_icall_type_is_assignable_from (MonoReflectionType *type, MonoReflectionType *c)
1125 MONO_ARCH_SAVE_REGS;
1127 g_assert (type != NULL);
1129 domain = ((MonoObject *)type)->vtable->domain;
1131 klass = mono_class_from_mono_type (type->type);
1132 klassc = mono_class_from_mono_type (c->type);
1134 return mono_class_is_assignable_from (klass, klassc);
1138 ves_icall_type_IsInstanceOfType (MonoReflectionType *type, MonoObject *obj)
1140 MonoClass *klass = mono_class_from_mono_type (type->type);
1141 return mono_object_isinst (obj, klass) != NULL;
1145 ves_icall_get_attributes (MonoReflectionType *type)
1147 MonoClass *klass = mono_class_from_mono_type (type->type);
1149 MONO_ARCH_SAVE_REGS;
1151 return klass->flags;
1154 static MonoReflectionField*
1155 ves_icall_System_Reflection_FieldInfo_internal_from_handle (MonoClassField *handle)
1157 MONO_ARCH_SAVE_REGS;
1161 return mono_field_get_object (mono_domain_get (), handle->parent, handle);
1165 ves_icall_get_method_info (MonoMethod *method, MonoMethodInfo *info)
1167 MonoDomain *domain = mono_domain_get ();
1169 MONO_ARCH_SAVE_REGS;
1171 info->parent = mono_type_get_object (domain, &method->klass->byval_arg);
1172 info->ret = mono_type_get_object (domain, method->signature->ret);
1173 info->attrs = method->flags;
1174 info->implattrs = method->iflags;
1175 if (method->signature->call_convention == MONO_CALL_DEFAULT)
1178 if (method->signature->call_convention == MONO_CALL_VARARG)
1182 info->callconv |= (method->signature->hasthis << 5) | (method->signature->explicit_this << 6);
1186 ves_icall_get_parameter_info (MonoMethod *method)
1188 MonoDomain *domain = mono_domain_get ();
1190 MONO_ARCH_SAVE_REGS;
1192 return mono_param_get_objects (domain, method);
1195 static MonoReflectionType*
1196 ves_icall_MonoField_GetParentType (MonoReflectionField *field, MonoBoolean declaring)
1199 MONO_ARCH_SAVE_REGS;
1201 parent = declaring? field->field->parent: field->klass;
1203 return mono_type_get_object (mono_object_domain (field), &parent->byval_arg);
1207 ves_icall_MonoField_GetValueInternal (MonoReflectionField *field, MonoObject *obj)
1210 MonoClassField *cf = field->field;
1213 MonoDomain *domain = mono_object_domain (field);
1215 gboolean is_static = FALSE;
1216 gboolean is_ref = FALSE;
1218 MONO_ARCH_SAVE_REGS;
1220 mono_class_init (field->klass);
1222 switch (cf->type->type) {
1223 case MONO_TYPE_STRING:
1224 case MONO_TYPE_OBJECT:
1225 case MONO_TYPE_CLASS:
1226 case MONO_TYPE_ARRAY:
1227 case MONO_TYPE_SZARRAY:
1232 case MONO_TYPE_BOOLEAN:
1235 case MONO_TYPE_CHAR:
1244 case MONO_TYPE_VALUETYPE:
1245 is_ref = cf->type->byref;
1248 g_error ("type 0x%x not handled in "
1249 "ves_icall_Monofield_GetValue", cf->type->type);
1254 if (cf->type->attrs & FIELD_ATTRIBUTE_STATIC) {
1256 vtable = mono_class_vtable (domain, field->klass);
1257 if (!vtable->initialized && !(cf->type->attrs & FIELD_ATTRIBUTE_LITERAL))
1258 mono_runtime_class_init (vtable);
1263 mono_field_static_get_value (vtable, cf, &o);
1265 mono_field_get_value (obj, cf, &o);
1270 /* boxed value type */
1271 klass = mono_class_from_mono_type (cf->type);
1272 o = mono_object_new (domain, klass);
1273 v = ((gchar *) o) + sizeof (MonoObject);
1275 mono_field_static_get_value (vtable, cf, v);
1277 mono_field_get_value (obj, cf, v);
1284 ves_icall_FieldInfo_SetValueInternal (MonoReflectionField *field, MonoObject *obj, MonoObject *value)
1286 MonoClassField *cf = field->field;
1289 MONO_ARCH_SAVE_REGS;
1291 v = (gchar *) value;
1292 if (!cf->type->byref) {
1293 switch (cf->type->type) {
1296 case MONO_TYPE_BOOLEAN:
1299 case MONO_TYPE_CHAR:
1308 case MONO_TYPE_VALUETYPE:
1309 v += sizeof (MonoObject);
1311 case MONO_TYPE_STRING:
1312 case MONO_TYPE_OBJECT:
1313 case MONO_TYPE_CLASS:
1314 case MONO_TYPE_ARRAY:
1315 case MONO_TYPE_SZARRAY:
1319 g_error ("type 0x%x not handled in "
1320 "ves_icall_FieldInfo_SetValueInternal", cf->type->type);
1325 if (cf->type->attrs & FIELD_ATTRIBUTE_STATIC) {
1326 MonoVTable *vtable = mono_class_vtable (mono_object_domain (field), field->klass);
1327 if (!vtable->initialized)
1328 mono_runtime_class_init (vtable);
1329 mono_field_static_set_value (vtable, cf, v);
1331 mono_field_set_value (obj, cf, v);
1335 /* From MonoProperty.cs */
1337 PInfo_Attributes = 1,
1338 PInfo_GetMethod = 1 << 1,
1339 PInfo_SetMethod = 1 << 2,
1340 PInfo_ReflectedType = 1 << 3,
1341 PInfo_DeclaringType = 1 << 4,
1346 ves_icall_get_property_info (MonoReflectionProperty *property, MonoPropertyInfo *info, PInfo req_info)
1348 MonoDomain *domain = mono_object_domain (property);
1350 MONO_ARCH_SAVE_REGS;
1352 if ((req_info & PInfo_ReflectedType) != 0 || (req_info & PInfo_DeclaringType) != 0)
1353 info->parent = mono_type_get_object (domain, &property->klass->byval_arg);
1355 if ((req_info & PInfo_Name) != 0)
1356 info->name = mono_string_new (domain, property->property->name);
1358 if ((req_info & PInfo_Attributes) != 0)
1359 info->attrs = property->property->attrs;
1361 if ((req_info & PInfo_GetMethod) != 0)
1362 info->get = property->property->get ?
1363 mono_method_get_object (domain, property->property->get, NULL): NULL;
1365 if ((req_info & PInfo_SetMethod) != 0)
1366 info->set = property->property->set ?
1367 mono_method_get_object (domain, property->property->set, NULL): NULL;
1369 * There may be other methods defined for properties, though, it seems they are not exposed
1370 * in the reflection API
1375 ves_icall_get_event_info (MonoReflectionEvent *event, MonoEventInfo *info)
1377 MonoDomain *domain = mono_object_domain (event);
1379 MONO_ARCH_SAVE_REGS;
1381 info->parent = mono_type_get_object (domain, &event->klass->byval_arg);
1382 info->name = mono_string_new (domain, event->event->name);
1383 info->attrs = event->event->attrs;
1384 info->add_method = event->event->add ? mono_method_get_object (domain, event->event->add, NULL): NULL;
1385 info->remove_method = event->event->remove ? mono_method_get_object (domain, event->event->remove, NULL): NULL;
1386 info->raise_method = event->event->raise ? mono_method_get_object (domain, event->event->raise, NULL): NULL;
1390 ves_icall_Type_GetInterfaces (MonoReflectionType* type)
1392 MonoDomain *domain = mono_object_domain (type);
1395 MonoClass *class = mono_class_from_mono_type (type->type);
1397 MonoBitSet *slots = mono_bitset_new (class->max_interface_id + 1, 0);
1399 MONO_ARCH_SAVE_REGS;
1402 /* GetInterfaces() returns an empty array in MS.NET (this may be a bug) */
1403 mono_bitset_free (slots);
1404 return mono_array_new (domain, mono_defaults.monotype_class, 0);
1408 for (parent = class; parent; parent = parent->parent) {
1409 for (i = 0; i < parent->interface_count; ++i) {
1410 if (mono_bitset_test (slots, parent->interfaces [i]->interface_id))
1413 mono_bitset_set (slots, parent->interfaces [i]->interface_id);
1418 intf = mono_array_new (domain, mono_defaults.monotype_class, ninterf);
1420 for (parent = class; parent; parent = parent->parent) {
1421 for (i = 0; i < parent->interface_count; ++i) {
1422 if (!mono_bitset_test (slots, parent->interfaces [i]->interface_id))
1425 mono_bitset_clear (slots, parent->interfaces [i]->interface_id);
1426 mono_array_set (intf, gpointer, ninterf,
1427 mono_type_get_object (domain, &parent->interfaces [i]->byval_arg));
1432 mono_bitset_free (slots);
1437 ves_icall_Type_GetInterfaceMapData (MonoReflectionType *type, MonoReflectionType *iface, MonoArray **targets, MonoArray **methods)
1439 MonoClass *class = mono_class_from_mono_type (type->type);
1440 MonoClass *iclass = mono_class_from_mono_type (iface->type);
1441 MonoReflectionMethod *member;
1442 int i, len, ioffset;
1445 MONO_ARCH_SAVE_REGS;
1447 /* type doesn't implement iface: the exception is thrown in managed code */
1448 if ((iclass->interface_id > class->max_interface_id) || !class->interface_offsets [iclass->interface_id])
1451 len = iclass->method.count;
1452 ioffset = class->interface_offsets [iclass->interface_id];
1453 domain = mono_object_domain (type);
1454 *targets = mono_array_new (domain, mono_defaults.method_info_class, len);
1455 *methods = mono_array_new (domain, mono_defaults.method_info_class, len);
1456 for (i = 0; i < len; ++i) {
1457 member = mono_method_get_object (domain, iclass->methods [i], iclass);
1458 mono_array_set (*methods, gpointer, i, member);
1459 member = mono_method_get_object (domain, class->vtable [i + ioffset], class);
1460 mono_array_set (*targets, gpointer, i, member);
1464 static MonoReflectionType*
1465 ves_icall_MonoType_GetElementType (MonoReflectionType *type)
1467 MonoClass *class = mono_class_from_mono_type (type->type);
1469 MONO_ARCH_SAVE_REGS;
1471 if (type->type->byref)
1472 return mono_type_get_object (mono_object_domain (type), &class->byval_arg);
1473 if (class->enumtype && class->enum_basetype) /* types that are modifierd typebuilkders may not have enum_basetype set */
1474 return mono_type_get_object (mono_object_domain (type), class->enum_basetype);
1475 else if (class->element_class)
1476 return mono_type_get_object (mono_object_domain (type), &class->element_class->byval_arg);
1481 static MonoReflectionType*
1482 ves_icall_get_type_parent (MonoReflectionType *type)
1484 MonoClass *class = mono_class_from_mono_type (type->type);
1486 MONO_ARCH_SAVE_REGS;
1488 return class->parent ? mono_type_get_object (mono_object_domain (type), &class->parent->byval_arg): NULL;
1492 ves_icall_type_ispointer (MonoReflectionType *type)
1494 MONO_ARCH_SAVE_REGS;
1496 return type->type->type == MONO_TYPE_PTR;
1500 ves_icall_type_isprimitive (MonoReflectionType *type)
1502 MONO_ARCH_SAVE_REGS;
1504 return (!type->type->byref && (type->type->type >= MONO_TYPE_BOOLEAN) && (type->type->type <= MONO_TYPE_R8));
1508 ves_icall_type_isbyref (MonoReflectionType *type)
1510 MONO_ARCH_SAVE_REGS;
1512 return type->type->byref;
1515 static MonoReflectionModule*
1516 ves_icall_MonoType_get_Module (MonoReflectionType *type)
1518 MonoClass *class = mono_class_from_mono_type (type->type);
1520 MONO_ARCH_SAVE_REGS;
1522 return mono_module_get_object (mono_object_domain (type), class->image);
1525 static MonoReflectionAssembly*
1526 ves_icall_MonoType_get_Assembly (MonoReflectionType *type)
1528 MonoDomain *domain = mono_domain_get ();
1529 MonoClass *class = mono_class_from_mono_type (type->type);
1531 MONO_ARCH_SAVE_REGS;
1533 return mono_assembly_get_object (domain, class->image->assembly);
1536 static MonoReflectionType*
1537 ves_icall_MonoType_get_DeclaringType (MonoReflectionType *type)
1539 MonoDomain *domain = mono_domain_get ();
1540 MonoClass *class = mono_class_from_mono_type (type->type);
1542 MONO_ARCH_SAVE_REGS;
1544 return class->nested_in ? mono_type_get_object (domain, &class->nested_in->byval_arg) : NULL;
1547 static MonoReflectionType*
1548 ves_icall_MonoType_get_UnderlyingSystemType (MonoReflectionType *type)
1550 MonoDomain *domain = mono_domain_get ();
1551 MonoClass *class = mono_class_from_mono_type (type->type);
1553 MONO_ARCH_SAVE_REGS;
1555 if (class->enumtype && class->enum_basetype) /* types that are modified typebuilders may not have enum_basetype set */
1556 return mono_type_get_object (domain, class->enum_basetype);
1557 else if (class->element_class)
1558 return mono_type_get_object (domain, &class->element_class->byval_arg);
1564 ves_icall_MonoType_get_Name (MonoReflectionType *type)
1566 MonoDomain *domain = mono_domain_get ();
1567 MonoClass *class = mono_class_from_mono_type (type->type);
1569 MONO_ARCH_SAVE_REGS;
1571 return mono_string_new (domain, class->name);
1575 ves_icall_MonoType_get_Namespace (MonoReflectionType *type)
1577 MonoDomain *domain = mono_domain_get ();
1578 MonoClass *class = mono_class_from_mono_type (type->type);
1580 MONO_ARCH_SAVE_REGS;
1582 while (class->nested_in)
1583 class = class->nested_in;
1585 return mono_string_new (domain, class->name_space);
1589 ves_icall_MonoType_GetArrayRank (MonoReflectionType *type)
1591 MonoClass *class = mono_class_from_mono_type (type->type);
1593 MONO_ARCH_SAVE_REGS;
1599 ves_icall_Type_GetGenericArguments (MonoReflectionType *type)
1602 MonoClass *klass, *pklass;
1604 MONO_ARCH_SAVE_REGS;
1606 klass = mono_class_from_mono_type (type->type);
1608 if (type->type->byref) {
1609 res = mono_array_new (mono_object_domain (type), mono_defaults.monotype_class, 0);
1610 } else if (klass->gen_params) {
1611 res = mono_array_new (mono_object_domain (type), mono_defaults.monotype_class, klass->num_gen_params);
1612 for (i = 0; i < klass->num_gen_params; ++i) {
1613 pklass = mono_class_from_generic_parameter (&klass->gen_params [i], klass->image, FALSE);
1614 mono_array_set (res, gpointer, i, mono_type_get_object (mono_object_domain (type), &pklass->byval_arg));
1616 } else if (klass->generic_inst) {
1617 MonoGenericInst *inst = klass->generic_inst;
1618 res = mono_array_new (mono_object_domain (type), mono_defaults.monotype_class, inst->type_argc);
1619 for (i = 0; i < inst->type_argc; ++i) {
1620 mono_array_set (res, gpointer, i, mono_type_get_object (mono_object_domain (type), inst->type_argv [i]));
1623 res = mono_array_new (mono_object_domain (type), mono_defaults.monotype_class, 0);
1629 ves_icall_Type_get_IsGenericTypeDefinition (MonoReflectionType *type)
1632 MONO_ARCH_SAVE_REGS;
1634 if (type->type->byref)
1636 klass = mono_class_from_mono_type (type->type);
1638 return klass->gen_params != NULL;
1641 static MonoReflectionType*
1642 ves_icall_Type_GetGenericTypeDefinition_impl (MonoReflectionType *type)
1645 MONO_ARCH_SAVE_REGS;
1647 if (type->type->byref)
1649 klass = mono_class_from_mono_type (type->type);
1650 if (klass->gen_params) {
1651 return type; /* check this one */
1653 if (klass->generic_inst) {
1654 MonoType *generic_type = klass->generic_inst->generic_type;
1655 MonoClass *generic_class = mono_class_from_mono_type (generic_type);
1657 if (generic_class->wastypebuilder && generic_class->reflection_info)
1658 return generic_class->reflection_info;
1660 return mono_type_get_object (mono_object_domain (type), generic_type);
1665 static MonoReflectionType*
1666 ves_icall_Type_BindGenericParameters (MonoReflectionType *type, MonoArray *types)
1670 MONO_ARCH_SAVE_REGS;
1672 if (type->type->byref)
1675 geninst = mono_reflection_bind_generic_parameters (type->type, types);
1677 return mono_type_get_object (mono_object_domain (type), geninst);
1681 ves_icall_Type_get_IsGenericInstance (MonoReflectionType *type)
1684 MONO_ARCH_SAVE_REGS;
1686 if (type->type->byref)
1688 klass = mono_class_from_mono_type (type->type);
1689 return klass->generic_inst != NULL;
1693 ves_icall_Type_GetGenericParameterPosition (MonoReflectionType *type)
1695 MONO_ARCH_SAVE_REGS;
1697 if (type->type->byref)
1699 if (type->type->type == MONO_TYPE_VAR || type->type->type == MONO_TYPE_MVAR)
1700 return type->type->data.generic_param->num;
1705 ves_icall_MonoType_get_HasGenericArguments (MonoReflectionType *type)
1708 MONO_ARCH_SAVE_REGS;
1710 if (type->type->byref)
1712 klass = mono_class_from_mono_type (type->type);
1713 if (klass->gen_params || klass->generic_inst)
1719 ves_icall_MonoType_get_IsGenericParameter (MonoReflectionType *type)
1721 MONO_ARCH_SAVE_REGS;
1723 if (type->type->byref)
1725 if (type->type->type == MONO_TYPE_VAR || type->type->type == MONO_TYPE_MVAR)
1731 ves_icall_TypeBuilder_get_IsGenericParameter (MonoReflectionTypeBuilder *tb)
1733 MONO_ARCH_SAVE_REGS;
1735 if (tb->type.type->byref)
1737 if (tb->type.type->type == MONO_TYPE_VAR || tb->type.type->type == MONO_TYPE_MVAR)
1742 static MonoReflectionGenericParam*
1743 ves_icall_TypeBuilder_define_generic_parameter (MonoReflectionTypeBuilder *tb, MonoString *name, int index)
1745 MONO_ARCH_SAVE_REGS;
1747 return mono_reflection_define_generic_parameter (tb, NULL, name, index);
1750 static MonoReflectionGenericParam*
1751 ves_icall_MethodBuilder_define_generic_parameter (MonoReflectionMethodBuilder *mb, MonoString *name, int index)
1753 MONO_ARCH_SAVE_REGS;
1755 return mono_reflection_define_generic_parameter (NULL, mb, name, index);
1758 static MonoReflectionType*
1759 ves_icall_MonoGenericInst_GetParentType (MonoReflectionGenericInst *type)
1761 MonoGenericInst *ginst;
1764 MONO_ARCH_SAVE_REGS;
1766 ginst = type->type.type->data.generic_inst;
1767 if (!ginst || !ginst->parent || (ginst->parent->type != MONO_TYPE_GENERICINST))
1770 klass = mono_class_from_mono_type (ginst->parent);
1771 if (!klass->generic_inst && !klass->gen_params)
1774 return mono_type_get_object (mono_object_domain (type), ginst->parent);
1778 ves_icall_MonoGenericInst_GetInterfaces (MonoReflectionGenericInst *type)
1780 static MonoClass *System_Reflection_MonoGenericInst;
1781 MonoGenericInst *ginst;
1787 MONO_ARCH_SAVE_REGS;
1789 if (!System_Reflection_MonoGenericInst) {
1790 System_Reflection_MonoGenericInst = mono_class_from_name (
1791 mono_defaults.corlib, "System.Reflection", "MonoGenericInst");
1792 g_assert (System_Reflection_MonoGenericInst);
1795 domain = mono_object_domain (type);
1797 ginst = type->type.type->data.generic_inst;
1798 if (!ginst || !ginst->ifaces)
1799 return mono_array_new (domain, System_Reflection_MonoGenericInst, 0);
1801 klass = mono_class_from_mono_type (ginst->generic_type);
1803 res = mono_array_new (domain, System_Reflection_MonoGenericInst, klass->interface_count);
1805 for (i = 0; i < klass->interface_count; i++) {
1806 MonoReflectionType *iface = mono_type_get_object (domain, ginst->ifaces [i]);
1808 mono_array_set (res, gpointer, i, iface);
1815 ves_icall_MonoGenericParam_initialize (MonoReflectionGenericParam *gparam)
1817 MONO_ARCH_SAVE_REGS;
1818 mono_reflection_initialize_generic_parameter (gparam);
1821 static MonoReflectionMethod *
1822 ves_icall_MonoType_get_DeclaringMethod (MonoReflectionType *type)
1827 MONO_ARCH_SAVE_REGS;
1829 if (type->type->byref)
1832 method = type->type->data.generic_param->method;
1836 klass = mono_class_from_mono_type (type->type);
1837 return mono_method_get_object (mono_object_domain (type), method, klass);
1841 ves_icall_MethodInfo_get_IsGenericMethodDefinition (MonoReflectionMethod *method)
1843 MonoMethodNormal *mn;
1844 MONO_ARCH_SAVE_REGS;
1846 if ((method->method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) ||
1847 (method->method->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL))
1850 mn = (MonoMethodNormal *) method->method;
1851 return mn->header->gen_params != NULL;
1855 ves_icall_MonoMethod_GetGenericArguments (MonoReflectionMethod *method)
1857 MonoMethodNormal *mn;
1860 MONO_ARCH_SAVE_REGS;
1862 if ((method->method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) ||
1863 (method->method->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL))
1864 return mono_array_new (mono_object_domain (method), mono_defaults.monotype_class, 0);
1866 mn = (MonoMethodNormal *) method->method;
1867 count = method->method->signature->generic_param_count;
1868 res = mono_array_new (mono_object_domain (method), mono_defaults.monotype_class, count);
1870 for (i = 0; i < count; i++) {
1871 MonoGenericParam *param = &mn->header->gen_params [i];
1872 MonoClass *pklass = mono_class_from_generic_parameter (param, method->method->klass->image, TRUE);
1873 mono_array_set (res, gpointer, i, mono_type_get_object (mono_object_domain (method), &pklass->byval_arg));
1880 ves_icall_InternalInvoke (MonoReflectionMethod *method, MonoObject *this, MonoArray *params)
1883 * Invoke from reflection is supposed to always be a virtual call (the API
1884 * is stupid), mono_runtime_invoke_*() calls the provided method, allowing
1885 * greater flexibility.
1887 MonoMethod *m = method->method;
1890 MONO_ARCH_SAVE_REGS;
1893 if (!mono_object_isinst (this, m->klass))
1894 mono_raise_exception (mono_exception_from_name (mono_defaults.corlib, "System.Reflection", "TargetException"));
1895 m = mono_object_get_virtual_method (this, m);
1896 } else if (!(m->flags & METHOD_ATTRIBUTE_STATIC) && strcmp (m->name, ".ctor") && !m->wrapper_type)
1897 mono_raise_exception (mono_exception_from_name (mono_defaults.corlib, "System.Reflection", "TargetException"));
1899 pcount = params? mono_array_length (params): 0;
1900 if (pcount != m->signature->param_count)
1901 mono_raise_exception (mono_exception_from_name (mono_defaults.corlib, "System.Reflection", "TargetParameterCountException"));
1903 if (m->klass->rank && !strcmp (m->name, ".ctor")) {
1906 guint32 *lower_bounds;
1907 pcount = mono_array_length (params);
1908 lengths = alloca (sizeof (guint32) * pcount);
1909 for (i = 0; i < pcount; ++i)
1910 lengths [i] = *(gint32*) ((char*)mono_array_get (params, gpointer, i) + sizeof (MonoObject));
1912 if (m->klass->rank == pcount) {
1913 /* Only lengths provided. */
1914 lower_bounds = NULL;
1916 g_assert (pcount == (m->klass->rank * 2));
1917 /* lower bounds are first. */
1918 lower_bounds = lengths;
1919 lengths += m->klass->rank;
1922 return (MonoObject*)mono_array_new_full (mono_object_domain (params), m->klass, lengths, lower_bounds);
1924 return mono_runtime_invoke_array (m, this, params, NULL);
1928 ves_icall_InternalExecute (MonoReflectionMethod *method, MonoObject *this, MonoArray *params, MonoArray **outArgs)
1930 MonoDomain *domain = mono_object_domain (method);
1931 MonoMethod *m = method->method;
1932 MonoMethodSignature *sig = m->signature;
1933 MonoArray *out_args;
1935 int i, j, outarg_count = 0;
1937 MONO_ARCH_SAVE_REGS;
1939 if (m->klass == mono_defaults.object_class) {
1941 if (!strcmp (m->name, "FieldGetter")) {
1942 MonoClass *k = this->vtable->klass;
1943 MonoString *name = mono_array_get (params, MonoString *, 1);
1946 str = mono_string_to_utf8 (name);
1948 for (i = 0; i < k->field.count; i++) {
1949 if (!strcmp (k->fields [i].name, str)) {
1950 MonoClass *field_klass = mono_class_from_mono_type (k->fields [i].type);
1951 if (field_klass->valuetype)
1952 result = mono_value_box (domain, field_klass,
1953 (char *)this + k->fields [i].offset);
1955 result = *((gpointer *)((char *)this + k->fields [i].offset));
1958 out_args = mono_array_new (domain, mono_defaults.object_class, 1);
1959 *outArgs = out_args;
1960 mono_array_set (out_args, gpointer, 0, result);
1967 g_assert_not_reached ();
1969 } else if (!strcmp (m->name, "FieldSetter")) {
1970 MonoClass *k = this->vtable->klass;
1971 MonoString *name = mono_array_get (params, MonoString *, 1);
1975 str = mono_string_to_utf8 (name);
1977 for (i = 0; i < k->field.count; i++) {
1978 if (!strcmp (k->fields [i].name, str)) {
1979 MonoClass *field_klass = mono_class_from_mono_type (k->fields [i].type);
1980 MonoObject *val = mono_array_get (params, gpointer, 2);
1982 if (field_klass->valuetype) {
1983 size = mono_type_size (k->fields [i].type, &align);
1984 memcpy ((char *)this + k->fields [i].offset,
1985 ((char *)val) + sizeof (MonoObject), size);
1987 *(MonoObject**)((char *)this + k->fields [i].offset) = val;
1989 out_args = mono_array_new (domain, mono_defaults.object_class, 0);
1990 *outArgs = out_args;
1998 g_assert_not_reached ();
2003 for (i = 0; i < mono_array_length (params); i++) {
2004 if (sig->params [i]->byref)
2008 out_args = mono_array_new (domain, mono_defaults.object_class, outarg_count);
2010 /* fixme: handle constructors? */
2011 if (!strcmp (method->method->name, ".ctor"))
2012 g_assert_not_reached ();
2014 result = mono_runtime_invoke_array (method->method, this, params, NULL);
2016 for (i = 0, j = 0; i < mono_array_length (params); i++) {
2017 if (sig->params [i]->byref) {
2019 arg = mono_array_get (params, gpointer, i);
2020 mono_array_set (out_args, gpointer, j, arg);
2025 *outArgs = out_args;
2031 ves_icall_System_Enum_ToObject (MonoReflectionType *type, MonoObject *obj)
2034 MonoClass *enumc, *objc;
2038 MONO_ARCH_SAVE_REGS;
2040 MONO_CHECK_ARG_NULL (type);
2041 MONO_CHECK_ARG_NULL (obj);
2043 domain = mono_object_domain (type);
2044 enumc = mono_class_from_mono_type (type->type);
2045 objc = obj->vtable->klass;
2047 MONO_CHECK_ARG (obj, enumc->enumtype == TRUE);
2048 MONO_CHECK_ARG (obj, (objc->enumtype) || (objc->byval_arg.type >= MONO_TYPE_I1 &&
2049 objc->byval_arg.type <= MONO_TYPE_U8));
2051 s1 = mono_class_value_size (enumc, NULL);
2052 s2 = mono_class_value_size (objc, NULL);
2054 res = mono_object_new (domain, enumc);
2056 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
2057 memcpy ((char *)res + sizeof (MonoObject), (char *)obj + sizeof (MonoObject), MIN (s1, s2));
2059 memcpy ((char *)res + sizeof (MonoObject) + (s1 > s2 ? s1 - s2 : 0),
2060 (char *)obj + sizeof (MonoObject) + (s2 > s1 ? s2 - s1 : 0),
2067 ves_icall_System_Enum_get_value (MonoObject *this)
2075 MONO_ARCH_SAVE_REGS;
2080 g_assert (this->vtable->klass->enumtype);
2082 enumc = mono_class_from_mono_type (this->vtable->klass->enum_basetype);
2083 res = mono_object_new (mono_object_domain (this), enumc);
2084 dst = (char *)res + sizeof (MonoObject);
2085 src = (char *)this + sizeof (MonoObject);
2086 size = mono_class_value_size (enumc, NULL);
2088 memcpy (dst, src, size);
2094 ves_icall_get_enum_info (MonoReflectionType *type, MonoEnumInfo *info)
2096 MonoDomain *domain = mono_object_domain (type);
2097 MonoClass *enumc = mono_class_from_mono_type (type->type);
2098 guint i, j, nvalues, crow;
2099 MonoClassField *field;
2101 MONO_ARCH_SAVE_REGS;
2103 info->utype = mono_type_get_object (domain, enumc->enum_basetype);
2104 nvalues = enumc->field.count - 1;
2105 info->names = mono_array_new (domain, mono_defaults.string_class, nvalues);
2106 info->values = mono_array_new (domain, enumc, nvalues);
2109 for (i = 0, j = 0; i < enumc->field.count; ++i) {
2113 field = &enumc->fields [i];
2114 if (strcmp ("value__", field->name) == 0)
2116 if (mono_field_is_deleted (field))
2118 mono_array_set (info->names, gpointer, j, mono_string_new (domain, field->name));
2119 if (!field->def_value) {
2120 field->def_value = g_new0 (MonoConstant, 1);
2121 crow = mono_metadata_get_constant_index (enumc->image, MONO_TOKEN_FIELD_DEF | (i+enumc->field.first+1), crow + 1);
2122 field->def_value->type = mono_metadata_decode_row_col (&enumc->image->tables [MONO_TABLE_CONSTANT], crow-1, MONO_CONSTANT_TYPE);
2123 crow = mono_metadata_decode_row_col (&enumc->image->tables [MONO_TABLE_CONSTANT], crow-1, MONO_CONSTANT_VALUE);
2124 field->def_value->value = (gpointer)mono_metadata_blob_heap (enumc->image, crow);
2127 p = field->def_value->value;
2128 len = mono_metadata_decode_blob_size (p, &p);
2129 switch (enumc->enum_basetype->type) {
2132 mono_array_set (info->values, gchar, j, *p);
2134 case MONO_TYPE_CHAR:
2137 mono_array_set (info->values, gint16, j, read16 (p));
2141 mono_array_set (info->values, gint32, j, read32 (p));
2145 mono_array_set (info->values, gint64, j, read64 (p));
2148 g_error ("Implement type 0x%02x in get_enum_info", enumc->enum_basetype->type);
2155 BFLAGS_IgnoreCase = 1,
2156 BFLAGS_DeclaredOnly = 2,
2157 BFLAGS_Instance = 4,
2159 BFLAGS_Public = 0x10,
2160 BFLAGS_NonPublic = 0x20,
2161 BFLAGS_FlattenHierarchy = 0x40,
2162 BFLAGS_InvokeMethod = 0x100,
2163 BFLAGS_CreateInstance = 0x200,
2164 BFLAGS_GetField = 0x400,
2165 BFLAGS_SetField = 0x800,
2166 BFLAGS_GetProperty = 0x1000,
2167 BFLAGS_SetProperty = 0x2000,
2168 BFLAGS_ExactBinding = 0x10000,
2169 BFLAGS_SuppressChangeType = 0x20000,
2170 BFLAGS_OptionalParamBinding = 0x40000
2173 static MonoReflectionField *
2174 ves_icall_Type_GetField (MonoReflectionType *type, MonoString *name, guint32 bflags)
2177 MonoClass *startklass, *klass;
2179 MonoClassField *field;
2181 domain = ((MonoObject *)type)->vtable->domain;
2182 klass = startklass = mono_class_from_mono_type (type->type);
2184 MONO_ARCH_SAVE_REGS;
2187 mono_raise_exception (mono_get_exception_argument_null ("name"));
2190 for (i = 0; i < klass->field.count; ++i) {
2192 field = &klass->fields [i];
2193 if (mono_field_is_deleted (field))
2195 if ((field->type->attrs & FIELD_ATTRIBUTE_FIELD_ACCESS_MASK) == FIELD_ATTRIBUTE_PUBLIC) {
2196 if (bflags & BFLAGS_Public)
2199 if (bflags & BFLAGS_NonPublic)
2205 if (field->type->attrs & FIELD_ATTRIBUTE_STATIC) {
2206 if (bflags & BFLAGS_Static)
2207 if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
2210 if (bflags & BFLAGS_Instance)
2217 utf8_name = mono_string_to_utf8 (name);
2219 if (strcmp (field->name, utf8_name)) {
2225 return mono_field_get_object (domain, klass, field);
2227 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
2234 ves_icall_Type_GetFields (MonoReflectionType *type, guint32 bflags)
2237 GSList *l = NULL, *tmp;
2238 MonoClass *startklass, *klass;
2242 MonoClassField *field;
2244 MONO_ARCH_SAVE_REGS;
2246 domain = ((MonoObject *)type)->vtable->domain;
2247 klass = startklass = mono_class_from_mono_type (type->type);
2250 for (i = 0; i < klass->field.count; ++i) {
2252 field = &klass->fields [i];
2253 if (mono_field_is_deleted (field))
2255 if ((field->type->attrs & FIELD_ATTRIBUTE_FIELD_ACCESS_MASK) == FIELD_ATTRIBUTE_PUBLIC) {
2256 if (bflags & BFLAGS_Public)
2259 if (bflags & BFLAGS_NonPublic)
2265 if (field->type->attrs & FIELD_ATTRIBUTE_STATIC) {
2266 if (bflags & BFLAGS_Static)
2267 if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
2270 if (bflags & BFLAGS_Instance)
2276 member = (MonoObject*)mono_field_get_object (domain, klass, field);
2277 l = g_slist_prepend (l, member);
2279 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
2281 len = g_slist_length (l);
2282 res = mono_array_new (domain, mono_defaults.field_info_class, len);
2284 tmp = l = g_slist_reverse (l);
2285 for (; tmp; tmp = tmp->next, ++i)
2286 mono_array_set (res, gpointer, i, tmp->data);
2292 ves_icall_Type_GetMethodsByName (MonoReflectionType *type, MonoString *name, guint32 bflags, MonoBoolean ignore_case)
2295 GSList *l = NULL, *tmp;
2296 MonoClass *startklass, *klass;
2301 GHashTable *method_slots = g_hash_table_new (NULL, NULL);
2302 gchar *mname = NULL;
2303 int (*compare_func) (const char *s1, const char *s2) = NULL;
2305 MONO_ARCH_SAVE_REGS;
2307 domain = ((MonoObject *)type)->vtable->domain;
2308 klass = startklass = mono_class_from_mono_type (type->type);
2311 mname = mono_string_to_utf8 (name);
2312 compare_func = (ignore_case) ? g_strcasecmp : strcmp;
2316 for (i = 0; i < klass->method.count; ++i) {
2318 method = klass->methods [i];
2319 if (strcmp (method->name, ".ctor") == 0 || strcmp (method->name, ".cctor") == 0)
2321 if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
2322 if (bflags & BFLAGS_Public)
2325 if (bflags & BFLAGS_NonPublic)
2331 if (method->flags & METHOD_ATTRIBUTE_STATIC) {
2332 if (bflags & BFLAGS_Static)
2333 if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
2336 if (bflags & BFLAGS_Instance)
2344 if (compare_func (mname, method->name))
2349 if (g_hash_table_lookup (method_slots, GUINT_TO_POINTER (method->slot)))
2351 g_hash_table_insert (method_slots, GUINT_TO_POINTER (method->slot), method);
2352 member = (MonoObject*)mono_method_get_object (domain, method, startklass);
2354 l = g_slist_prepend (l, member);
2357 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
2361 res = mono_array_new (domain, mono_defaults.method_info_class, len);
2364 tmp = l = g_slist_reverse (l);
2366 for (; tmp; tmp = tmp->next, ++i)
2367 mono_array_set (res, gpointer, i, tmp->data);
2369 g_hash_table_destroy (method_slots);
2374 ves_icall_Type_GetConstructors (MonoReflectionType *type, guint32 bflags)
2377 GSList *l = NULL, *tmp;
2378 static MonoClass *System_Reflection_ConstructorInfo;
2379 MonoClass *startklass, *klass;
2385 MONO_ARCH_SAVE_REGS;
2387 domain = ((MonoObject *)type)->vtable->domain;
2388 klass = startklass = mono_class_from_mono_type (type->type);
2390 for (i = 0; i < klass->method.count; ++i) {
2392 method = klass->methods [i];
2393 if (strcmp (method->name, ".ctor") && strcmp (method->name, ".cctor"))
2395 if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
2396 if (bflags & BFLAGS_Public)
2399 if (bflags & BFLAGS_NonPublic)
2405 if (method->flags & METHOD_ATTRIBUTE_STATIC) {
2406 if (bflags & BFLAGS_Static)
2407 if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
2410 if (bflags & BFLAGS_Instance)
2416 member = (MonoObject*)mono_method_get_object (domain, method, startklass);
2418 l = g_slist_prepend (l, member);
2420 len = g_slist_length (l);
2421 if (!System_Reflection_ConstructorInfo)
2422 System_Reflection_ConstructorInfo = mono_class_from_name (
2423 mono_defaults.corlib, "System.Reflection", "ConstructorInfo");
2424 res = mono_array_new (domain, System_Reflection_ConstructorInfo, len);
2426 tmp = l = g_slist_reverse (l);
2427 for (; tmp; tmp = tmp->next, ++i)
2428 mono_array_set (res, gpointer, i, tmp->data);
2434 ves_icall_Type_GetPropertiesByName (MonoReflectionType *type, MonoString *name, guint32 bflags, MonoBoolean ignore_case)
2437 GSList *l = NULL, *tmp;
2438 static MonoClass *System_Reflection_PropertyInfo;
2439 MonoClass *startklass, *klass;
2445 GHashTable *method_slots = g_hash_table_new (NULL, NULL);
2446 gchar *propname = NULL;
2447 int (*compare_func) (const char *s1, const char *s2) = NULL;
2449 MONO_ARCH_SAVE_REGS;
2451 domain = ((MonoObject *)type)->vtable->domain;
2452 klass = startklass = mono_class_from_mono_type (type->type);
2454 propname = mono_string_to_utf8 (name);
2455 compare_func = (ignore_case) ? g_strcasecmp : strcmp;
2459 for (i = 0; i < klass->property.count; ++i) {
2460 prop = &klass->properties [i];
2465 if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
2466 if (bflags & BFLAGS_Public)
2469 if (bflags & BFLAGS_NonPublic)
2475 if (method->flags & METHOD_ATTRIBUTE_STATIC) {
2476 if (bflags & BFLAGS_Static)
2477 if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
2480 if (bflags & BFLAGS_Instance)
2489 if (compare_func (propname, prop->name))
2493 if (g_hash_table_lookup (method_slots, GUINT_TO_POINTER (method->slot)))
2495 g_hash_table_insert (method_slots, GUINT_TO_POINTER (method->slot), prop);
2497 l = g_slist_prepend (l, mono_property_get_object (domain, klass, prop));
2500 if ((!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent)))
2504 if (!System_Reflection_PropertyInfo)
2505 System_Reflection_PropertyInfo = mono_class_from_name (
2506 mono_defaults.corlib, "System.Reflection", "PropertyInfo");
2507 res = mono_array_new (domain, System_Reflection_PropertyInfo, len);
2510 tmp = l = g_slist_reverse (l);
2512 for (; tmp; tmp = tmp->next, ++i)
2513 mono_array_set (res, gpointer, i, tmp->data);
2515 g_hash_table_destroy (method_slots);
2519 static MonoReflectionEvent *
2520 ves_icall_MonoType_GetEvent (MonoReflectionType *type, MonoString *name, guint32 bflags)
2529 MONO_ARCH_SAVE_REGS;
2531 event_name = mono_string_to_utf8 (name);
2532 klass = mono_class_from_mono_type (type->type);
2533 domain = mono_object_domain (type);
2536 for (i = 0; i < klass->event.count; i++) {
2537 event = &klass->events [i];
2538 if (strcmp (event->name, event_name))
2541 method = event->add;
2543 method = event->remove;
2545 if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
2546 if (!(bflags & BFLAGS_Public))
2549 if (!(bflags & BFLAGS_NonPublic))
2553 g_free (event_name);
2554 return mono_event_get_object (domain, klass, event);
2557 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
2560 g_free (event_name);
2565 ves_icall_Type_GetEvents (MonoReflectionType *type, guint32 bflags)
2568 GSList *l = NULL, *tmp;
2569 static MonoClass *System_Reflection_EventInfo;
2570 MonoClass *startklass, *klass;
2576 MONO_ARCH_SAVE_REGS;
2578 domain = ((MonoObject *)type)->vtable->domain;
2579 klass = startklass = mono_class_from_mono_type (type->type);
2582 for (i = 0; i < klass->event.count; ++i) {
2583 event = &klass->events [i];
2585 method = event->add;
2587 method = event->remove;
2588 if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
2589 if (bflags & BFLAGS_Public)
2592 if (bflags & BFLAGS_NonPublic)
2598 if (method->flags & METHOD_ATTRIBUTE_STATIC) {
2599 if (bflags & BFLAGS_Static)
2600 if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
2603 if (bflags & BFLAGS_Instance)
2610 l = g_slist_prepend (l, mono_event_get_object (domain, klass, event));
2612 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
2614 len = g_slist_length (l);
2615 if (!System_Reflection_EventInfo)
2616 System_Reflection_EventInfo = mono_class_from_name (
2617 mono_defaults.corlib, "System.Reflection", "EventInfo");
2618 res = mono_array_new (domain, System_Reflection_EventInfo, len);
2621 tmp = l = g_slist_reverse (l);
2623 for (; tmp; tmp = tmp->next, ++i)
2624 mono_array_set (res, gpointer, i, tmp->data);
2629 static MonoReflectionType *
2630 ves_icall_Type_GetNestedType (MonoReflectionType *type, MonoString *name, guint32 bflags)
2633 MonoClass *startklass, *klass;
2638 MONO_ARCH_SAVE_REGS;
2640 domain = ((MonoObject *)type)->vtable->domain;
2641 klass = startklass = mono_class_from_mono_type (type->type);
2642 str = mono_string_to_utf8 (name);
2645 for (tmpn = klass->nested_classes; tmpn; tmpn = tmpn->next) {
2647 nested = tmpn->data;
2648 if ((nested->flags & TYPE_ATTRIBUTE_VISIBILITY_MASK) == TYPE_ATTRIBUTE_NESTED_PUBLIC) {
2649 if (bflags & BFLAGS_Public)
2652 if (bflags & BFLAGS_NonPublic)
2657 if (strcmp (nested->name, str) == 0){
2659 return mono_type_get_object (domain, &nested->byval_arg);
2662 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
2669 ves_icall_Type_GetNestedTypes (MonoReflectionType *type, guint32 bflags)
2672 GSList *l = NULL, *tmp;
2674 MonoClass *startklass, *klass;
2680 MONO_ARCH_SAVE_REGS;
2682 domain = ((MonoObject *)type)->vtable->domain;
2683 klass = startklass = mono_class_from_mono_type (type->type);
2685 for (tmpn = klass->nested_classes; tmpn; tmpn = tmpn->next) {
2687 nested = tmpn->data;
2688 if ((nested->flags & TYPE_ATTRIBUTE_VISIBILITY_MASK) == TYPE_ATTRIBUTE_NESTED_PUBLIC) {
2689 if (bflags & BFLAGS_Public)
2692 if (bflags & BFLAGS_NonPublic)
2697 member = (MonoObject*)mono_type_get_object (domain, &nested->byval_arg);
2698 l = g_slist_prepend (l, member);
2700 len = g_slist_length (l);
2701 res = mono_array_new (domain, mono_defaults.monotype_class, len);
2703 tmp = l = g_slist_reverse (l);
2704 for (; tmp; tmp = tmp->next, ++i)
2705 mono_array_set (res, gpointer, i, tmp->data);
2710 static MonoReflectionType*
2711 ves_icall_System_Reflection_Assembly_InternalGetType (MonoReflectionAssembly *assembly, MonoReflectionModule *module, MonoString *name, MonoBoolean throwOnError, MonoBoolean ignoreCase)
2714 MonoType *type = NULL;
2715 MonoTypeNameParse info;
2717 MONO_ARCH_SAVE_REGS;
2719 str = mono_string_to_utf8 (name);
2720 /*g_print ("requested type %s in %s\n", str, assembly->assembly->aname.name);*/
2721 if (!mono_reflection_parse_type (str, &info)) {
2723 g_list_free (info.modifiers);
2724 g_list_free (info.nested);
2725 if (throwOnError) /* uhm: this is a parse error, though... */
2726 mono_raise_exception (mono_get_exception_type_load (name));
2727 /*g_print ("failed parse\n");*/
2731 if (module != NULL) {
2733 type = mono_reflection_get_type (module->image, &info, ignoreCase);
2738 if (assembly->assembly->dynamic) {
2739 /* Enumerate all modules */
2740 MonoReflectionAssemblyBuilder *abuilder = (MonoReflectionAssemblyBuilder*)assembly;
2744 if (abuilder->modules) {
2745 for (i = 0; i < mono_array_length (abuilder->modules); ++i) {
2746 MonoReflectionModuleBuilder *mb = mono_array_get (abuilder->modules, MonoReflectionModuleBuilder*, i);
2747 type = mono_reflection_get_type (&mb->dynamic_image->image, &info, ignoreCase);
2753 if (!type && abuilder->loaded_modules) {
2754 for (i = 0; i < mono_array_length (abuilder->loaded_modules); ++i) {
2755 MonoReflectionModule *mod = mono_array_get (abuilder->loaded_modules, MonoReflectionModule*, i);
2756 type = mono_reflection_get_type (mod->image, &info, ignoreCase);
2763 type = mono_reflection_get_type (assembly->assembly->image, &info, ignoreCase);
2765 g_list_free (info.modifiers);
2766 g_list_free (info.nested);
2769 mono_raise_exception (mono_get_exception_type_load (name));
2770 /* g_print ("failed find\n"); */
2773 /* g_print ("got it\n"); */
2774 return mono_type_get_object (mono_object_domain (assembly), type);
2779 ves_icall_System_Reflection_Assembly_get_code_base (MonoReflectionAssembly *assembly)
2781 MonoDomain *domain = mono_object_domain (assembly);
2782 MonoAssembly *mass = assembly->assembly;
2787 MONO_ARCH_SAVE_REGS;
2789 absolute = g_build_filename (mass->basedir, mass->image->module_name, NULL);
2790 uri = g_filename_to_uri (absolute, NULL, NULL);
2791 res = mono_string_new (domain, uri);
2798 ves_icall_System_Reflection_Assembly_get_location (MonoReflectionAssembly *assembly)
2800 MonoDomain *domain = mono_object_domain (assembly);
2802 char *name = g_build_filename (
2803 assembly->assembly->basedir,
2804 assembly->assembly->image->module_name, NULL);
2806 MONO_ARCH_SAVE_REGS;
2808 res = mono_string_new (domain, name);
2814 ves_icall_System_Reflection_Assembly_InternalImageRuntimeVersion (MonoReflectionAssembly *assembly)
2816 MonoDomain *domain = mono_object_domain (assembly);
2818 MONO_ARCH_SAVE_REGS;
2820 return mono_string_new (domain, assembly->assembly->image->version);
2823 static MonoReflectionMethod*
2824 ves_icall_System_Reflection_Assembly_get_EntryPoint (MonoReflectionAssembly *assembly)
2826 guint32 token = mono_image_get_entry_point (assembly->assembly->image);
2828 MONO_ARCH_SAVE_REGS;
2832 return mono_method_get_object (mono_object_domain (assembly), mono_get_method (assembly->assembly->image, token, NULL), NULL);
2836 ves_icall_System_Reflection_Assembly_GetManifestResourceNames (MonoReflectionAssembly *assembly)
2838 MonoTableInfo *table = &assembly->assembly->image->tables [MONO_TABLE_MANIFESTRESOURCE];
2839 MonoArray *result = mono_array_new (mono_object_domain (assembly), mono_defaults.string_class, table->rows);
2843 MONO_ARCH_SAVE_REGS;
2845 for (i = 0; i < table->rows; ++i) {
2846 val = mono_metadata_string_heap (assembly->assembly->image, mono_metadata_decode_row_col (table, i, MONO_MANIFEST_NAME));
2847 mono_array_set (result, gpointer, i, mono_string_new (mono_object_domain (assembly), val));
2853 ves_icall_System_Reflection_Assembly_GetReferencedAssemblies (MonoReflectionAssembly *assembly)
2855 static MonoClass *System_Reflection_AssemblyName;
2858 MonoDomain *domain = mono_object_domain (assembly);
2861 MONO_ARCH_SAVE_REGS;
2863 if (!System_Reflection_AssemblyName)
2864 System_Reflection_AssemblyName = mono_class_from_name (
2865 mono_defaults.corlib, "System.Reflection", "AssemblyName");
2867 for (ptr = assembly->assembly->image->references; ptr && *ptr; ptr++)
2870 result = mono_array_new (mono_object_domain (assembly), System_Reflection_AssemblyName, count);
2872 for (i = 0; i < count; i++) {
2873 MonoAssembly *assem = assembly->assembly->image->references [i];
2874 MonoReflectionAssemblyName *aname;
2875 char *codebase, *absolute;
2877 aname = (MonoReflectionAssemblyName *) mono_object_new (
2878 domain, System_Reflection_AssemblyName);
2880 if (strcmp (assem->aname.name, "corlib") == 0)
2881 aname->name = mono_string_new (domain, "mscorlib");
2883 aname->name = mono_string_new (domain, assem->aname.name);
2884 aname->major = assem->aname.major;
2886 absolute = g_build_filename (assem->basedir, assem->image->module_name, NULL);
2887 codebase = g_filename_to_uri (absolute, NULL, NULL);
2888 aname->codebase = mono_string_new (domain, codebase);
2891 mono_array_set (result, gpointer, i, aname);
2902 foreach_namespace (const char* key, gconstpointer val, NameSpaceInfo *info)
2904 MonoString *name = mono_string_new (mono_object_domain (info->res), key);
2906 mono_array_set (info->res, gpointer, info->idx, name);
2911 ves_icall_System_Reflection_Assembly_GetNamespaces (MonoReflectionAssembly *assembly)
2913 MonoImage *img = assembly->assembly->image;
2917 MonoTableInfo *t = &img->tables [MONO_TABLE_EXPORTEDTYPE];
2920 MONO_ARCH_SAVE_REGS;
2922 n = g_hash_table_size (img->name_cache);
2923 res = mono_array_new (mono_object_domain (assembly), mono_defaults.string_class, n);
2926 g_hash_table_foreach (img->name_cache, (GHFunc)foreach_namespace, &info);
2928 /* Add namespaces from the EXPORTEDTYPES table as well */
2931 GPtrArray *nspaces = g_ptr_array_new ();
2932 for (i = 0; i < t->rows; ++i) {
2933 const char *nspace = mono_metadata_string_heap (img, mono_metadata_decode_row_col (t, i, MONO_EXP_TYPE_NAMESPACE));
2934 if (!g_hash_table_lookup (img->name_cache, nspace)) {
2935 g_ptr_array_add (nspaces, (char*)nspace);
2938 if (nspaces->len > 0) {
2939 res2 = mono_array_new (mono_object_domain (assembly), mono_defaults.string_class, n + nspaces->len);
2940 memcpy (mono_array_addr (res2, MonoString*, 0),
2941 mono_array_addr (res, MonoString*, 0),
2942 n * sizeof (MonoString*));
2943 for (i = 0; i < nspaces->len; ++i)
2944 mono_array_set (res2, MonoString*, n + i,
2945 mono_string_new (mono_object_domain (assembly),
2946 g_ptr_array_index (nspaces, i)));
2949 g_ptr_array_free (nspaces, TRUE);
2955 /* move this in some file in mono/util/ */
2957 g_concat_dir_and_file (const char *dir, const char *file)
2959 g_return_val_if_fail (dir != NULL, NULL);
2960 g_return_val_if_fail (file != NULL, NULL);
2963 * If the directory name doesn't have a / on the end, we need
2964 * to add one so we get a proper path to the file
2966 if (dir [strlen(dir) - 1] != G_DIR_SEPARATOR)
2967 return g_strconcat (dir, G_DIR_SEPARATOR_S, file, NULL);
2969 return g_strconcat (dir, file, NULL);
2973 ves_icall_System_Reflection_Assembly_GetManifestResourceInternal (MonoReflectionAssembly *assembly, MonoString *name, gint32 *size, MonoReflectionModule **ref_module)
2975 char *n = mono_string_to_utf8 (name);
2976 MonoTableInfo *table = &assembly->assembly->image->tables [MONO_TABLE_MANIFESTRESOURCE];
2978 guint32 cols [MONO_MANIFEST_SIZE];
2979 guint32 impl, file_idx;
2983 MONO_ARCH_SAVE_REGS;
2985 for (i = 0; i < table->rows; ++i) {
2986 mono_metadata_decode_row (table, i, cols, MONO_MANIFEST_SIZE);
2987 val = mono_metadata_string_heap (assembly->assembly->image, cols [MONO_MANIFEST_NAME]);
2988 if (strcmp (val, n) == 0)
2992 if (i == table->rows)
2995 impl = cols [MONO_MANIFEST_IMPLEMENTATION];
2998 * this code should only be called after obtaining the
2999 * ResourceInfo and handling the other cases.
3001 g_assert ((impl & IMPLEMENTATION_MASK) == IMPLEMENTATION_FILE);
3002 file_idx = impl >> IMPLEMENTATION_BITS;
3004 module = mono_image_load_file_for_image (assembly->assembly->image, file_idx);
3009 module = assembly->assembly->image;
3011 *ref_module = mono_module_get_object (mono_domain_get (), module);
3013 return (void*)mono_image_get_resource (module, cols [MONO_MANIFEST_OFFSET], size);
3017 ves_icall_System_Reflection_Assembly_GetManifestResourceInfoInternal (MonoReflectionAssembly *assembly, MonoString *name, MonoManifestResourceInfo *info)
3019 MonoTableInfo *table = &assembly->assembly->image->tables [MONO_TABLE_MANIFESTRESOURCE];
3021 guint32 cols [MONO_MANIFEST_SIZE];
3022 guint32 file_cols [MONO_FILE_SIZE];
3026 MONO_ARCH_SAVE_REGS;
3028 n = mono_string_to_utf8 (name);
3029 for (i = 0; i < table->rows; ++i) {
3030 mono_metadata_decode_row (table, i, cols, MONO_MANIFEST_SIZE);
3031 val = mono_metadata_string_heap (assembly->assembly->image, cols [MONO_MANIFEST_NAME]);
3032 if (strcmp (val, n) == 0)
3036 if (i == table->rows)
3039 if (!cols [MONO_MANIFEST_IMPLEMENTATION]) {
3040 info->location = RESOURCE_LOCATION_EMBEDDED | RESOURCE_LOCATION_IN_MANIFEST;
3043 switch (cols [MONO_MANIFEST_IMPLEMENTATION] & IMPLEMENTATION_MASK) {
3044 case IMPLEMENTATION_FILE:
3045 i = cols [MONO_MANIFEST_IMPLEMENTATION] >> IMPLEMENTATION_BITS;
3046 table = &assembly->assembly->image->tables [MONO_TABLE_FILE];
3047 mono_metadata_decode_row (table, i - 1, file_cols, MONO_FILE_SIZE);
3048 val = mono_metadata_string_heap (assembly->assembly->image, file_cols [MONO_FILE_NAME]);
3049 info->filename = mono_string_new (mono_object_domain (assembly), val);
3050 if (file_cols [MONO_FILE_FLAGS] && FILE_CONTAINS_NO_METADATA)
3053 info->location = RESOURCE_LOCATION_EMBEDDED;
3056 case IMPLEMENTATION_ASSEMBLYREF:
3057 i = cols [MONO_MANIFEST_IMPLEMENTATION] >> IMPLEMENTATION_BITS;
3058 info->assembly = mono_assembly_get_object (mono_domain_get (), assembly->assembly->image->references [i - 1]);
3060 // Obtain info recursively
3061 ves_icall_System_Reflection_Assembly_GetManifestResourceInfoInternal (info->assembly, name, info);
3062 info->location |= RESOURCE_LOCATION_ANOTHER_ASSEMBLY;
3065 case IMPLEMENTATION_EXP_TYPE:
3066 g_assert_not_reached ();
3075 ves_icall_System_Reflection_Assembly_GetFilesInternal (MonoReflectionAssembly *assembly, MonoString *name)
3077 MonoTableInfo *table = &assembly->assembly->image->tables [MONO_TABLE_FILE];
3078 MonoArray *result = NULL;
3083 MONO_ARCH_SAVE_REGS;
3085 /* check hash if needed */
3087 n = mono_string_to_utf8 (name);
3088 for (i = 0; i < table->rows; ++i) {
3089 val = mono_metadata_string_heap (assembly->assembly->image, mono_metadata_decode_row_col (table, i, MONO_FILE_NAME));
3090 if (strcmp (val, n) == 0) {
3093 n = g_concat_dir_and_file (assembly->assembly->basedir, val);
3094 fn = mono_string_new (mono_object_domain (assembly), n);
3096 return (MonoObject*)fn;
3103 for (i = 0; i < table->rows; ++i) {
3104 result = mono_array_new (mono_object_domain (assembly), mono_defaults.string_class, table->rows);
3105 val = mono_metadata_string_heap (assembly->assembly->image, mono_metadata_decode_row_col (table, i, MONO_FILE_NAME));
3106 n = g_concat_dir_and_file (assembly->assembly->basedir, val);
3107 mono_array_set (result, gpointer, i, mono_string_new (mono_object_domain (assembly), n));
3110 return (MonoObject*)result;
3114 ves_icall_System_Reflection_Assembly_GetModulesInternal (MonoReflectionAssembly *assembly)
3116 MonoDomain *domain = mono_domain_get();
3119 int i, module_count = 0, file_count = 0;
3120 MonoImage **modules = assembly->assembly->image->modules;
3121 MonoTableInfo *table;
3124 while (modules[module_count])
3128 table = &assembly->assembly->image->tables [MONO_TABLE_FILE];
3129 file_count = table->rows;
3131 g_assert( assembly->assembly->image != NULL);
3134 klass = mono_class_from_name ( mono_defaults.corlib, "System.Reflection", "Module");
3135 res = mono_array_new (domain, klass, module_count + file_count);
3137 mono_array_set (res, gpointer, 0, mono_module_get_object (domain, assembly->assembly->image));
3138 for ( i = 1; i < module_count; ++i )
3139 mono_array_set (res, gpointer, i, mono_module_get_object (domain, modules[i]));
3141 for (i = 0; i < table->rows; ++i)
3142 mono_array_set (res, gpointer, module_count + i, mono_module_file_get_object (domain, assembly->assembly->image, i));
3147 static MonoReflectionMethod*
3148 ves_icall_GetCurrentMethod (void)
3150 MonoMethod *m = mono_method_get_last_managed ();
3152 MONO_ARCH_SAVE_REGS;
3154 return mono_method_get_object (mono_domain_get (), m, NULL);
3157 static MonoReflectionAssembly*
3158 ves_icall_System_Reflection_Assembly_GetExecutingAssembly (void)
3160 MonoMethod *m = mono_method_get_last_managed ();
3162 MONO_ARCH_SAVE_REGS;
3164 return mono_assembly_get_object (mono_domain_get (), m->klass->image->assembly);
3169 get_caller (MonoMethod *m, gint32 no, gint32 ilo, gboolean managed, gpointer data)
3171 MonoMethod **dest = data;
3173 /* skip unmanaged frames */
3188 static MonoReflectionAssembly*
3189 ves_icall_System_Reflection_Assembly_GetEntryAssembly (void)
3191 MonoDomain* domain = mono_domain_get ();
3193 MONO_ARCH_SAVE_REGS;
3195 if (!domain->entry_assembly)
3196 domain = mono_root_domain;
3198 return mono_assembly_get_object (domain, domain->entry_assembly);
3202 static MonoReflectionAssembly*
3203 ves_icall_System_Reflection_Assembly_GetCallingAssembly (void)
3205 MonoMethod *m = mono_method_get_last_managed ();
3206 MonoMethod *dest = m;
3208 MONO_ARCH_SAVE_REGS;
3210 mono_stack_walk (get_caller, &dest);
3213 return mono_assembly_get_object (mono_domain_get (), dest->klass->image->assembly);
3217 ves_icall_System_MonoType_getFullName (MonoReflectionType *object)
3219 MonoDomain *domain = mono_object_domain (object);
3223 MONO_ARCH_SAVE_REGS;
3225 name = mono_type_get_name (object->type);
3226 res = mono_string_new (domain, name);
3233 fill_reflection_assembly_name (MonoDomain *domain, MonoReflectionAssemblyName *aname, MonoAssemblyName *name, const char *absolute)
3235 static MonoMethod *create_culture = NULL;
3238 const char *pkey_ptr;
3241 MONO_ARCH_SAVE_REGS;
3243 if (strcmp (name->name, "corlib") == 0)
3244 aname->name = mono_string_new (domain, "mscorlib");
3246 aname->name = mono_string_new (domain, name->name);
3248 aname->major = name->major;
3249 aname->minor = name->minor;
3250 aname->build = name->build;
3251 aname->revision = name->revision;
3252 aname->hashalg = name->hash_alg;
3254 codebase = g_filename_to_uri (absolute, NULL, NULL);
3256 aname->codebase = mono_string_new (domain, codebase);
3260 if (!create_culture) {
3261 MonoMethodDesc *desc = mono_method_desc_new ("System.Globalization.CultureInfo:CreateSpecificCulture(string)", TRUE);
3262 create_culture = mono_method_desc_search_in_image (desc, mono_defaults.corlib);
3263 g_assert (create_culture);
3264 mono_method_desc_free (desc);
3267 args [0] = mono_string_new (domain, name->culture);
3268 aname->cultureInfo =
3269 mono_runtime_invoke (create_culture, NULL, args, NULL);
3271 if (name->public_key) {
3272 pkey_ptr = name->public_key;
3273 pkey_len = mono_metadata_decode_blob_size (pkey_ptr, &pkey_ptr);
3275 aname->publicKey = mono_array_new (domain, mono_defaults.byte_class, pkey_len);
3276 memcpy (mono_array_addr (aname->publicKey, guint8, 0), pkey_ptr, pkey_len);
3281 ves_icall_System_Reflection_Assembly_FillName (MonoReflectionAssembly *assembly, MonoReflectionAssemblyName *aname)
3285 MONO_ARCH_SAVE_REGS;
3287 absolute = g_build_filename (assembly->assembly->basedir, assembly->assembly->image->module_name, NULL);
3289 fill_reflection_assembly_name (mono_object_domain (assembly), aname,
3290 &assembly->assembly->aname, absolute);
3296 ves_icall_System_Reflection_Assembly_InternalGetAssemblyName (MonoString *fname, MonoReflectionAssemblyName *aname)
3299 MonoImageOpenStatus status = MONO_IMAGE_OK;
3302 MonoAssemblyName name;
3304 MONO_ARCH_SAVE_REGS;
3306 filename = mono_string_to_utf8 (fname);
3308 image = mono_image_open (filename, &status);
3314 exc = mono_get_exception_file_not_found (fname);
3315 mono_raise_exception (exc);
3318 res = mono_assembly_fill_assembly_name (image, &name);
3320 mono_image_close (image);
3322 mono_raise_exception (mono_get_exception_argument ("assemblyFile", "The file does not contain a manifest"));
3325 fill_reflection_assembly_name (mono_domain_get (), aname, &name, filename);
3328 mono_image_close (image);
3332 mono_module_get_types (MonoDomain *domain, MonoImage *image,
3333 MonoBoolean exportedOnly)
3337 MonoTableInfo *tdef = &image->tables [MONO_TABLE_TYPEDEF];
3339 guint32 attrs, visibility;
3341 /* we start the count from 1 because we skip the special type <Module> */
3344 for (i = 1; i < tdef->rows; ++i) {
3345 attrs = mono_metadata_decode_row_col (tdef, i, MONO_TYPEDEF_FLAGS);
3346 visibility = attrs & TYPE_ATTRIBUTE_VISIBILITY_MASK;
3347 if (visibility == TYPE_ATTRIBUTE_PUBLIC || visibility == TYPE_ATTRIBUTE_NESTED_PUBLIC)
3351 count = tdef->rows - 1;
3353 res = mono_array_new (domain, mono_defaults.monotype_class, count);
3355 for (i = 1; i < tdef->rows; ++i) {
3356 attrs = mono_metadata_decode_row_col (tdef, i, MONO_TYPEDEF_FLAGS);
3357 visibility = attrs & TYPE_ATTRIBUTE_VISIBILITY_MASK;
3358 if (!exportedOnly || (visibility == TYPE_ATTRIBUTE_PUBLIC || visibility == TYPE_ATTRIBUTE_NESTED_PUBLIC)) {
3359 klass = mono_class_get (image, (i + 1) | MONO_TOKEN_TYPE_DEF);
3360 mono_array_set (res, gpointer, count, mono_type_get_object (domain, &klass->byval_arg));
3369 ves_icall_System_Reflection_Assembly_GetTypes (MonoReflectionAssembly *assembly, MonoBoolean exportedOnly)
3372 MonoImage *image = assembly->assembly->image;
3373 MonoTableInfo *table = &image->tables [MONO_TABLE_FILE];
3377 MONO_ARCH_SAVE_REGS;
3379 domain = mono_object_domain (assembly);
3380 res = mono_module_get_types (domain, image, exportedOnly);
3382 /* Append data from all modules in the assembly */
3383 for (i = 0; i < table->rows; ++i) {
3384 if (!(mono_metadata_decode_row_col (table, i, MONO_FILE_FLAGS) & FILE_CONTAINS_NO_METADATA)) {
3385 MonoImage *loaded_image = mono_assembly_load_module (image->assembly, i + 1);
3387 MonoArray *res2 = mono_module_get_types (domain, loaded_image, exportedOnly);
3388 /* Append the new types to the end of the array */
3389 if (mono_array_length (res2) > 0) {
3393 len1 = mono_array_length (res);
3394 len2 = mono_array_length (res2);
3395 res3 = mono_array_new (domain, mono_defaults.monotype_class, len1 + len2);
3396 memcpy (mono_array_addr (res3, MonoReflectionType*, 0),
3397 mono_array_addr (res, MonoReflectionType*, 0),
3398 len1 * sizeof (MonoReflectionType*));
3399 memcpy (mono_array_addr (res3, MonoReflectionType*, len1),
3400 mono_array_addr (res2, MonoReflectionType*, 0),
3401 len2 * sizeof (MonoReflectionType*));
3411 static MonoReflectionType*
3412 ves_icall_System_Reflection_Module_GetGlobalType (MonoReflectionModule *module)
3414 MonoDomain *domain = mono_object_domain (module);
3417 MONO_ARCH_SAVE_REGS;
3419 g_assert (module->image);
3420 klass = mono_class_get (module->image, 1 | MONO_TOKEN_TYPE_DEF);
3421 return mono_type_get_object (domain, &klass->byval_arg);
3425 ves_icall_System_Reflection_Module_Close (MonoReflectionModule *module)
3428 mono_image_close (module->image);
3432 ves_icall_System_Reflection_Module_GetGuidInternal (MonoReflectionModule *module)
3434 MonoDomain *domain = mono_object_domain (module);
3436 MONO_ARCH_SAVE_REGS;
3438 g_assert (module->image);
3439 return mono_string_new (domain, module->image->guid);
3443 ves_icall_System_Reflection_Module_InternalGetTypes (MonoReflectionModule *module)
3445 MONO_ARCH_SAVE_REGS;
3448 return mono_array_new (mono_object_domain (module), mono_defaults.monotype_class, 0);
3450 return mono_module_get_types (mono_object_domain (module), module->image, FALSE);
3453 static MonoReflectionType*
3454 ves_icall_ModuleBuilder_create_modified_type (MonoReflectionTypeBuilder *tb, MonoString *smodifiers)
3457 int isbyref = 0, rank;
3458 char *str = mono_string_to_utf8 (smodifiers);
3461 MONO_ARCH_SAVE_REGS;
3463 klass = mono_class_from_mono_type (tb->type.type);
3465 /* logic taken from mono_reflection_parse_type(): keep in sync */
3469 if (isbyref) { /* only one level allowed by the spec */
3476 return mono_type_get_object (mono_object_domain (tb), &klass->this_arg);
3479 klass = mono_ptr_class_get (&klass->byval_arg);
3480 mono_class_init (klass);
3491 else if (*p != '*') { /* '*' means unknown lower bound */
3502 klass = mono_array_class_get (klass, rank);
3503 mono_class_init (klass);
3510 return mono_type_get_object (mono_object_domain (tb), &klass->byval_arg);
3514 ves_icall_Type_IsArrayImpl (MonoReflectionType *t)
3519 MONO_ARCH_SAVE_REGS;
3522 res = !type->byref && (type->type == MONO_TYPE_ARRAY || type->type == MONO_TYPE_SZARRAY);
3527 static MonoReflectionType *
3528 ves_icall_Type_make_array_type (MonoReflectionType *type, int rank)
3530 MonoClass *klass, *aklass;
3532 MONO_ARCH_SAVE_REGS;
3534 klass = mono_class_from_mono_type (type->type);
3535 aklass = mono_array_class_get (klass, rank);
3537 return mono_type_get_object (mono_object_domain (type), &aklass->byval_arg);
3540 static MonoReflectionType *
3541 ves_icall_Type_make_byref_type (MonoReflectionType *type)
3545 MONO_ARCH_SAVE_REGS;
3547 klass = mono_class_from_mono_type (type->type);
3549 return mono_type_get_object (mono_object_domain (type), &klass->this_arg);
3553 ves_icall_System_Delegate_CreateDelegate_internal (MonoReflectionType *type, MonoObject *target,
3554 MonoReflectionMethod *info)
3556 MonoClass *delegate_class = mono_class_from_mono_type (type->type);
3557 MonoObject *delegate;
3560 MONO_ARCH_SAVE_REGS;
3562 mono_assert (delegate_class->parent == mono_defaults.multicastdelegate_class);
3564 delegate = mono_object_new (mono_object_domain (type), delegate_class);
3566 func = mono_compile_method (info->method);
3568 mono_delegate_ctor (delegate, target, func);
3574 * Magic number to convert a time which is relative to
3575 * Jan 1, 1970 into a value which is relative to Jan 1, 0001.
3577 #define EPOCH_ADJUST ((guint64)62135596800LL)
3580 * Magic number to convert FILETIME base Jan 1, 1601 to DateTime - base Jan, 1, 0001
3582 #define FILETIME_ADJUST ((guint64)504911232000000000LL)
3585 * This returns Now in UTC
3588 ves_icall_System_DateTime_GetNow (void)
3590 #ifdef PLATFORM_WIN32
3595 SystemTimeToFileTime (&st, &ft);
3596 return (gint64) FILETIME_ADJUST + ((((gint64)ft.dwHighDateTime)<<32) | ft.dwLowDateTime);
3598 /* FIXME: put this in io-layer and call it GetLocalTime */
3602 MONO_ARCH_SAVE_REGS;
3604 if (gettimeofday (&tv, NULL) == 0) {
3605 res = (((gint64)tv.tv_sec + EPOCH_ADJUST)* 1000000 + tv.tv_usec)*10;
3608 /* fixme: raise exception */
3613 #ifdef PLATFORM_WIN32
3614 /* convert a SYSTEMTIME which is of the form "last thursday in october" to a real date */
3616 convert_to_absolute_date(SYSTEMTIME *date)
3618 #define IS_LEAP(y) ((y % 4) == 0 && ((y % 100) != 0 || (y % 400) == 0))
3619 static int days_in_month[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
3620 static int leap_days_in_month[] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
3621 /* from the calendar FAQ */
3622 int a = (14 - date->wMonth) / 12;
3623 int y = date->wYear - a;
3624 int m = date->wMonth + 12 * a - 2;
3625 int d = (1 + y + y/4 - y/100 + y/400 + (31*m)/12) % 7;
3627 /* d is now the day of the week for the first of the month (0 == Sunday) */
3629 int day_of_week = date->wDayOfWeek;
3631 /* set day_in_month to the first day in the month which falls on day_of_week */
3632 int day_in_month = 1 + (day_of_week - d);
3633 if (day_in_month <= 0)
3636 /* wDay is 1 for first weekday in month, 2 for 2nd ... 5 means last - so work that out allowing for days in the month */
3637 date->wDay = day_in_month + (date->wDay - 1) * 7;
3638 if (date->wDay > (IS_LEAP(date->wYear) ? leap_days_in_month[date->wMonth - 1] : days_in_month[date->wMonth - 1]))
3643 #ifndef PLATFORM_WIN32
3645 * Return's the offset from GMT of a local time.
3647 * tm is a local time
3648 * t is the same local time as seconds.
3651 gmt_offset(struct tm *tm, time_t t)
3653 #if defined (HAVE_TM_GMTOFF)
3654 return tm->tm_gmtoff;
3659 g.tm_isdst = tm->tm_isdst;
3661 return (int)difftime(t, t2);
3666 * This is heavily based on zdump.c from glibc 2.2.
3668 * * data[0]: start of daylight saving time (in DateTime ticks).
3669 * * data[1]: end of daylight saving time (in DateTime ticks).
3670 * * data[2]: utcoffset (in TimeSpan ticks).
3671 * * data[3]: additional offset when daylight saving (in TimeSpan ticks).
3672 * * name[0]: name of this timezone when not daylight saving.
3673 * * name[1]: name of this timezone when daylight saving.
3675 * FIXME: This only works with "standard" Unix dates (years between 1900 and 2100) while
3676 * the class library allows years between 1 and 9999.
3678 * Returns true on success and zero on failure.
3681 ves_icall_System_CurrentTimeZone_GetTimeZoneData (guint32 year, MonoArray **data, MonoArray **names)
3683 #ifndef PLATFORM_WIN32
3684 MonoDomain *domain = mono_domain_get ();
3685 struct tm start, tt;
3689 int is_daylight = 0, day;
3692 MONO_ARCH_SAVE_REGS;
3694 MONO_CHECK_ARG_NULL (data);
3695 MONO_CHECK_ARG_NULL (names);
3697 (*data) = mono_array_new (domain, mono_defaults.int64_class, 4);
3698 (*names) = mono_array_new (domain, mono_defaults.string_class, 2);
3701 * no info is better than crashing: we'll need our own tz data to make
3702 * this work properly, anyway. The range is reduced to 1970 .. 2037 because
3703 * that is what mktime is guaranteed to support (we get into an infinite loop
3706 if ((year < 1970) || (year > 2037)) {
3708 tt = *localtime (&t);
3709 strftime (tzone, sizeof (tzone), "%Z", &tt);
3710 mono_array_set ((*names), gpointer, 0, mono_string_new (domain, tzone));
3711 mono_array_set ((*names), gpointer, 1, mono_string_new (domain, tzone));
3715 memset (&start, 0, sizeof (start));
3718 start.tm_year = year-1900;
3720 t = mktime (&start);
3721 gmtoff = gmt_offset (&start, t);
3723 /* For each day of the year, calculate the tm_gmtoff. */
3724 for (day = 0; day < 365; day++) {
3727 tt = *localtime (&t);
3729 /* Daylight saving starts or ends here. */
3730 if (gmt_offset (&tt, t) != gmtoff) {
3734 /* Try to find the exact hour when daylight saving starts/ends. */
3738 tt1 = *localtime (&t1);
3739 } while (gmt_offset (&tt1, t1) != gmtoff);
3741 /* Try to find the exact minute when daylight saving starts/ends. */
3744 tt1 = *localtime (&t1);
3745 } while (gmt_offset (&tt1, t1) == gmtoff);
3747 strftime (tzone, sizeof (tzone), "%Z", &tt);
3749 /* Write data, if we're already in daylight saving, we're done. */
3751 mono_array_set ((*names), gpointer, 0, mono_string_new (domain, tzone));
3752 mono_array_set ((*data), gint64, 1, ((gint64)t1 + EPOCH_ADJUST) * 10000000L);
3755 mono_array_set ((*names), gpointer, 1, mono_string_new (domain, tzone));
3756 mono_array_set ((*data), gint64, 0, ((gint64)t1 + EPOCH_ADJUST) * 10000000L);
3760 /* This is only set once when we enter daylight saving. */
3761 mono_array_set ((*data), gint64, 2, (gint64)gmtoff * 10000000L);
3762 mono_array_set ((*data), gint64, 3, (gint64)(gmt_offset (&tt, t) - gmtoff) * 10000000L);
3764 gmtoff = gmt_offset (&tt, t);
3769 strftime (tzone, sizeof (tzone), "%Z", &tt);
3770 mono_array_set ((*names), gpointer, 0, mono_string_new (domain, tzone));
3771 mono_array_set ((*names), gpointer, 1, mono_string_new (domain, tzone));
3772 mono_array_set ((*data), gint64, 0, 0);
3773 mono_array_set ((*data), gint64, 1, 0);
3774 mono_array_set ((*data), gint64, 2, (gint64) gmtoff * 10000000L);
3775 mono_array_set ((*data), gint64, 3, 0);
3780 MonoDomain *domain = mono_domain_get ();
3781 TIME_ZONE_INFORMATION tz_info;
3786 tz_id = GetTimeZoneInformation (&tz_info);
3787 if (tz_id == TIME_ZONE_ID_INVALID)
3790 MONO_CHECK_ARG_NULL (data);
3791 MONO_CHECK_ARG_NULL (names);
3793 (*data) = mono_array_new (domain, mono_defaults.int64_class, 4);
3794 (*names) = mono_array_new (domain, mono_defaults.string_class, 2);
3796 for (i = 0; i < 32; ++i)
3797 if (!tz_info.DaylightName [i])
3799 mono_array_set ((*names), gpointer, 1, mono_string_new_utf16 (domain, tz_info.DaylightName, i));
3800 for (i = 0; i < 32; ++i)
3801 if (!tz_info.StandardName [i])
3803 mono_array_set ((*names), gpointer, 0, mono_string_new_utf16 (domain, tz_info.StandardName, i));
3805 if ((year <= 1601) || (year > 30827)) {
3807 * According to MSDN, the MS time functions can't handle dates outside
3813 /* even if the timezone has no daylight savings it may have Bias (e.g. GMT+13 it seems) */
3814 if (tz_id != TIME_ZONE_ID_UNKNOWN) {
3815 tz_info.StandardDate.wYear = year;
3816 convert_to_absolute_date(&tz_info.StandardDate);
3817 err = SystemTimeToFileTime (&tz_info.StandardDate, &ft);
3819 mono_array_set ((*data), gint64, 1, FILETIME_ADJUST + (((guint64)ft.dwHighDateTime<<32) | ft.dwLowDateTime));
3820 tz_info.DaylightDate.wYear = year;
3821 convert_to_absolute_date(&tz_info.DaylightDate);
3822 err = SystemTimeToFileTime (&tz_info.DaylightDate, &ft);
3824 mono_array_set ((*data), gint64, 0, FILETIME_ADJUST + (((guint64)ft.dwHighDateTime<<32) | ft.dwLowDateTime));
3826 mono_array_set ((*data), gint64, 2, (tz_info.Bias + tz_info.StandardBias) * -600000000LL);
3827 mono_array_set ((*data), gint64, 3, (tz_info.DaylightBias - tz_info.StandardBias) * -600000000LL);
3834 ves_icall_System_Object_obj_address (MonoObject *this)
3836 MONO_ARCH_SAVE_REGS;
3844 ves_icall_System_Buffer_ByteLengthInternal (MonoArray *array)
3851 MONO_ARCH_SAVE_REGS;
3853 klass = array->obj.vtable->klass;
3854 etype = klass->element_class->byval_arg.type;
3855 if (etype < MONO_TYPE_BOOLEAN || etype > MONO_TYPE_R8)
3858 if (array->bounds == NULL)
3859 length = array->max_length;
3862 for (i = 0; i < klass->rank; ++ i)
3863 length *= array->bounds [i].length;
3866 esize = mono_array_element_size (klass);
3867 return length * esize;
3871 ves_icall_System_Buffer_GetByteInternal (MonoArray *array, gint32 idx)
3873 MONO_ARCH_SAVE_REGS;
3875 return mono_array_get (array, gint8, idx);
3879 ves_icall_System_Buffer_SetByteInternal (MonoArray *array, gint32 idx, gint8 value)
3881 MONO_ARCH_SAVE_REGS;
3883 mono_array_set (array, gint8, idx, value);
3887 ves_icall_System_Buffer_BlockCopyInternal (MonoArray *src, gint32 src_offset, MonoArray *dest, gint32 dest_offset, gint32 count)
3889 char *src_buf, *dest_buf;
3891 MONO_ARCH_SAVE_REGS;
3893 src_buf = (gint8 *)src->vector + src_offset;
3894 dest_buf = (gint8 *)dest->vector + dest_offset;
3896 memcpy (dest_buf, src_buf, count);
3900 ves_icall_Remoting_RealProxy_GetTransparentProxy (MonoObject *this)
3902 MonoDomain *domain = mono_object_domain (this);
3904 MonoRealProxy *rp = ((MonoRealProxy *)this);
3905 MonoTransparentProxy *tp;
3909 MONO_ARCH_SAVE_REGS;
3911 res = mono_object_new (domain, mono_defaults.transparent_proxy_class);
3912 tp = (MonoTransparentProxy*) res;
3915 type = ((MonoReflectionType *)rp->class_to_proxy)->type;
3916 klass = mono_class_from_mono_type (type);
3918 if (klass->flags & TYPE_ATTRIBUTE_INTERFACE)
3919 tp->klass = mono_defaults.marshalbyrefobject_class;
3923 tp->custom_type_info = (mono_object_isinst (this, mono_defaults.iremotingtypeinfo_class) != NULL);
3925 res->vtable = mono_class_proxy_vtable (domain, klass);
3930 /* System.Environment */
3933 ves_icall_System_Environment_get_MachineName (void)
3935 #if defined (PLATFORM_WIN32)
3940 len = MAX_COMPUTERNAME_LENGTH + 1;
3941 buf = g_new (gunichar2, len);
3944 if (GetComputerName (buf, (PDWORD) &len))
3945 result = mono_string_new_utf16 (mono_domain_get (), buf, len);
3954 MONO_ARCH_SAVE_REGS;
3957 buf = g_new (gchar, len);
3960 if (gethostname (buf, len) == 0)
3961 result = mono_string_new (mono_domain_get (), buf);
3969 ves_icall_System_Environment_get_Platform (void)
3971 MONO_ARCH_SAVE_REGS;
3973 #if defined (PLATFORM_WIN32)
3983 ves_icall_System_Environment_get_NewLine (void)
3985 MONO_ARCH_SAVE_REGS;
3987 #if defined (PLATFORM_WIN32)
3988 return mono_string_new (mono_domain_get (), "\r\n");
3990 return mono_string_new (mono_domain_get (), "\n");
3995 ves_icall_System_Environment_GetEnvironmentVariable (MonoString *name)
4000 MONO_ARCH_SAVE_REGS;
4005 utf8_name = mono_string_to_utf8 (name); /* FIXME: this should be ascii */
4006 value = g_getenv (utf8_name);
4012 return mono_string_new (mono_domain_get (), value);
4016 * There is no standard way to get at environ.
4024 ves_icall_System_Environment_GetEnvironmentVariableNames (void)
4032 MONO_ARCH_SAVE_REGS;
4035 for (e = environ; *e != 0; ++ e)
4038 domain = mono_domain_get ();
4039 names = mono_array_new (domain, mono_defaults.string_class, n);
4042 for (e = environ; *e != 0; ++ e) {
4043 parts = g_strsplit (*e, "=", 2);
4045 str = mono_string_new (domain, *parts);
4046 mono_array_set (names, MonoString *, n, str);
4058 * Returns the number of milliseconds elapsed since the system started.
4061 ves_icall_System_Environment_get_TickCount (void)
4063 #if defined (PLATFORM_WIN32)
4064 return GetTickCount();
4070 MONO_ARCH_SAVE_REGS;
4072 res = (gint32) gettimeofday (&tv, &tz);
4075 res = (gint32) ((tv.tv_sec & 0xFFFFF) * 1000 + (tv.tv_usec / 1000));
4082 ves_icall_System_Environment_Exit (int result)
4084 MONO_ARCH_SAVE_REGS;
4086 mono_runtime_quit ();
4088 /* we may need to do some cleanup here... */
4093 ves_icall_System_Environment_GetGacPath (void)
4095 return mono_string_new (mono_domain_get (), MONO_ASSEMBLIES);
4099 ves_icall_System_Text_Encoding_InternalCodePage (void)
4103 MONO_ARCH_SAVE_REGS;
4105 g_get_charset (&cset);
4106 /* g_print ("charset: %s\n", cset); */
4107 /* handle some common aliases */
4110 if (strcmp (cset, "ANSI_X3.4-1968") == 0)
4114 return mono_string_new (mono_domain_get (), cset);
4118 ves_icall_System_Environment_get_HasShutdownStarted (void)
4120 if (mono_runtime_is_shutting_down ())
4123 if (mono_domain_is_unloading (mono_domain_get ()))
4130 ves_icall_MonoMethodMessage_InitMessage (MonoMethodMessage *this,
4131 MonoReflectionMethod *method,
4132 MonoArray *out_args)
4134 MONO_ARCH_SAVE_REGS;
4136 mono_message_init (mono_object_domain (this), this, method, out_args);
4140 ves_icall_IsTransparentProxy (MonoObject *proxy)
4142 MONO_ARCH_SAVE_REGS;
4147 if (proxy->vtable->klass == mono_defaults.transparent_proxy_class)
4154 ves_icall_System_Runtime_Activation_ActivationServices_EnableProxyActivation (MonoReflectionType *type, MonoBoolean enable)
4159 MONO_ARCH_SAVE_REGS;
4161 klass = mono_class_from_mono_type (type->type);
4162 vtable = mono_class_vtable (mono_domain_get (), klass);
4164 if (enable) vtable->remote = 1;
4165 else vtable->remote = 0;
4169 ves_icall_System_Runtime_Activation_ActivationServices_AllocateUninitializedClassInstance (MonoReflectionType *type)
4174 MONO_ARCH_SAVE_REGS;
4176 domain = mono_object_domain (type);
4177 klass = mono_class_from_mono_type (type->type);
4179 if (klass->rank >= 1) {
4180 g_assert (klass->rank == 1);
4181 return (MonoObject *) mono_array_new (domain, klass->element_class, 0);
4183 // Bypass remoting object creation check
4184 return mono_object_new_alloc_specific (mono_class_vtable (domain, klass));
4189 ves_icall_System_IO_get_temp_path (void)
4191 MONO_ARCH_SAVE_REGS;
4193 return mono_string_new (mono_domain_get (), g_get_tmp_dir ());
4197 ves_icall_RuntimeMethod_GetFunctionPointer (MonoMethod *method)
4199 MONO_ARCH_SAVE_REGS;
4201 return mono_compile_method (method);
4204 char const * mono_cfg_dir = "";
4207 mono_install_get_config_dir (void)
4209 #ifdef PLATFORM_WIN32
4213 mono_cfg_dir = getenv ("MONO_CFG_DIR");
4215 if (!mono_cfg_dir) {
4216 #ifndef PLATFORM_WIN32
4217 mono_cfg_dir = MONO_CFG_DIR;
4219 mono_cfg_dir = g_strdup (MONO_CFG_DIR);
4220 for (i = strlen (mono_cfg_dir) - 1; i >= 0; i--) {
4221 if (mono_cfg_dir [i] == '/')
4222 ((char*) mono_cfg_dir) [i] = '\\';
4230 ves_icall_System_Configuration_DefaultConfig_get_machine_config_path (void)
4235 MONO_ARCH_SAVE_REGS;
4237 path = g_build_path (G_DIR_SEPARATOR_S, mono_cfg_dir, "mono", "machine.config", NULL);
4239 #if defined (PLATFORM_WIN32)
4240 /* Avoid mixing '/' and '\\' */
4243 for (i = strlen (path) - 1; i >= 0; i--)
4244 if (path [i] == '/')
4248 mcpath = mono_string_new (mono_domain_get (), path);
4255 ves_icall_System_Web_Util_ICalls_get_machine_install_dir (void)
4260 MONO_ARCH_SAVE_REGS;
4262 path = g_path_get_dirname (mono_cfg_dir);
4264 #if defined (PLATFORM_WIN32)
4265 /* Avoid mixing '/' and '\\' */
4268 for (i = strlen (path) - 1; i >= 0; i--)
4269 if (path [i] == '/')
4273 ipath = mono_string_new (mono_domain_get (), path);
4280 ves_icall_System_Diagnostics_DefaultTraceListener_WriteWindowsDebugString (MonoString *message)
4282 #if defined (PLATFORM_WIN32)
4283 static void (*output_debug) (gchar *);
4284 static gboolean tried_loading = FALSE;
4286 MONO_ARCH_SAVE_REGS;
4288 if (!tried_loading && output_debug == NULL) {
4291 tried_loading = TRUE;
4292 k32 = g_module_open ("kernel32", G_MODULE_BIND_LAZY);
4294 gchar *error = g_strdup (g_module_error ());
4295 g_warning ("Failed to load kernel32.dll: %s\n", error);
4300 g_module_symbol (k32, "OutputDebugStringW", (gpointer *) &output_debug);
4301 if (!output_debug) {
4302 gchar *error = g_strdup (g_module_error ());
4303 g_warning ("Failed to load OutputDebugStringW: %s\n", error);
4309 if (output_debug == NULL)
4312 output_debug (mono_string_chars (message));
4314 g_warning ("WriteWindowsDebugString called and PLATFORM_WIN32 not defined!\n");
4318 /* Only used for value types */
4320 ves_icall_System_Activator_CreateInstanceInternal (MonoReflectionType *type)
4325 MONO_ARCH_SAVE_REGS;
4327 domain = mono_object_domain (type);
4328 klass = mono_class_from_mono_type (type->type);
4330 return mono_object_new (domain, klass);
4333 static MonoReflectionMethod *
4334 ves_icall_MonoMethod_get_base_definition (MonoReflectionMethod *m)
4337 MonoMethod *method = m->method;
4338 MonoMethod *result = NULL;
4340 MONO_ARCH_SAVE_REGS;
4342 if (!(method->flags & METHOD_ATTRIBUTE_VIRTUAL) ||
4343 method->klass->flags & TYPE_ATTRIBUTE_INTERFACE ||
4344 method->flags & METHOD_ATTRIBUTE_NEW_SLOT)
4347 if (method->klass == NULL || (klass = method->klass->parent) == NULL)
4350 while (result == NULL && klass != NULL && (klass->vtable_size > method->slot))
4352 result = klass->vtable [method->slot];
4353 if (result == NULL) {
4354 /* It is an abstract method */
4356 for (i=0; i<klass->method.count; i++) {
4357 if (klass->methods [i]->slot == method->slot) {
4358 result = klass->methods [i];
4363 klass = klass->parent;
4369 return mono_method_get_object (mono_domain_get (), result, NULL);
4373 mono_ArgIterator_Setup (MonoArgIterator *iter, char* argsp, char* start)
4375 MONO_ARCH_SAVE_REGS;
4377 iter->sig = *(MonoMethodSignature**)argsp;
4379 g_assert (iter->sig->sentinelpos <= iter->sig->param_count);
4380 g_assert (iter->sig->call_convention == MONO_CALL_VARARG);
4383 /* FIXME: it's not documented what start is exactly... */
4384 iter->args = start? start: argsp + sizeof (gpointer);
4385 iter->num_args = iter->sig->param_count - iter->sig->sentinelpos;
4387 // g_print ("sig %p, param_count: %d, sent: %d\n", iter->sig, iter->sig->param_count, iter->sig->sentinelpos);
4391 mono_ArgIterator_IntGetNextArg (MonoArgIterator *iter)
4393 gint i, align, arg_size;
4395 MONO_ARCH_SAVE_REGS;
4397 i = iter->sig->sentinelpos + iter->next_arg;
4399 g_assert (i < iter->sig->param_count);
4401 res.type = iter->sig->params [i];
4402 res.klass = mono_class_from_mono_type (res.type);
4403 /* FIXME: endianess issue... */
4404 res.value = iter->args;
4405 arg_size = mono_type_stack_size (res.type, &align);
4406 iter->args = (char*)iter->args + arg_size;
4409 //g_print ("returning arg %d, type 0x%02x of size %d at %p\n", i, res.type->type, arg_size, res.value);
4415 mono_ArgIterator_IntGetNextArgT (MonoArgIterator *iter, MonoType *type)
4417 gint i, align, arg_size;
4419 MONO_ARCH_SAVE_REGS;
4421 i = iter->sig->sentinelpos + iter->next_arg;
4423 g_assert (i < iter->sig->param_count);
4425 while (i < iter->sig->param_count) {
4426 if (!mono_metadata_type_equal (type, iter->sig->params [i]))
4428 res.type = iter->sig->params [i];
4429 res.klass = mono_class_from_mono_type (res.type);
4430 /* FIXME: endianess issue... */
4431 res.value = iter->args;
4432 arg_size = mono_type_stack_size (res.type, &align);
4433 iter->args = (char*)iter->args + arg_size;
4435 //g_print ("returning arg %d, type 0x%02x of size %d at %p\n", i, res.type->type, arg_size, res.value);
4438 //g_print ("arg type 0x%02x not found\n", res.type->type);
4447 mono_ArgIterator_IntGetNextArgType (MonoArgIterator *iter)
4450 MONO_ARCH_SAVE_REGS;
4452 i = iter->sig->sentinelpos + iter->next_arg;
4454 g_assert (i < iter->sig->param_count);
4456 return iter->sig->params [i];
4460 mono_TypedReference_ToObject (MonoTypedRef tref)
4462 MONO_ARCH_SAVE_REGS;
4464 if (MONO_TYPE_IS_REFERENCE (tref.type)) {
4465 MonoObject** objp = tref.value;
4469 return mono_value_box (mono_domain_get (), tref.klass, tref.value);
4473 prelink_method (MonoMethod *method)
4475 const char *exc_class, *exc_arg;
4476 if (!(method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL))
4478 mono_lookup_pinvoke_call (method, &exc_class, &exc_arg);
4480 mono_raise_exception(
4481 mono_exception_from_name_msg (mono_defaults.corlib, "System", exc_class, exc_arg ) );
4483 /* create the wrapper, too? */
4487 ves_icall_System_Runtime_InteropServices_Marshal_Prelink (MonoReflectionMethod *method)
4489 MONO_ARCH_SAVE_REGS;
4490 prelink_method (method->method);
4494 ves_icall_System_Runtime_InteropServices_Marshal_PrelinkAll (MonoReflectionType *type)
4496 MonoClass *klass = mono_class_from_mono_type (type->type);
4498 MONO_ARCH_SAVE_REGS;
4500 mono_class_init (klass);
4501 for (i = 0; i < klass->method.count; ++i)
4502 prelink_method (klass->methods [i]);
4513 const IcallEntry *icalls;
4517 static const IcallEntry activator_icalls [] = {
4518 {"CreateInstanceInternal", ves_icall_System_Activator_CreateInstanceInternal}
4520 static const IcallEntry appdomain_icalls [] = {
4521 {"ExecuteAssembly", ves_icall_System_AppDomain_ExecuteAssembly},
4522 {"GetAssemblies", ves_icall_System_AppDomain_GetAssemblies},
4523 {"GetData", ves_icall_System_AppDomain_GetData},
4524 {"InternalGetContext", ves_icall_System_AppDomain_InternalGetContext},
4525 {"InternalGetDefaultContext", ves_icall_System_AppDomain_InternalGetDefaultContext},
4526 {"InternalGetProcessGuid", ves_icall_System_AppDomain_InternalGetProcessGuid},
4527 {"InternalIsFinalizingForUnload", ves_icall_System_AppDomain_InternalIsFinalizingForUnload},
4528 {"InternalPopDomainRef", ves_icall_System_AppDomain_InternalPopDomainRef},
4529 {"InternalPushDomainRef", ves_icall_System_AppDomain_InternalPushDomainRef},
4530 {"InternalPushDomainRefByID", ves_icall_System_AppDomain_InternalPushDomainRefByID},
4531 {"InternalSetContext", ves_icall_System_AppDomain_InternalSetContext},
4532 {"InternalSetDomain", ves_icall_System_AppDomain_InternalSetDomain},
4533 {"InternalSetDomainByID", ves_icall_System_AppDomain_InternalSetDomainByID},
4534 {"InternalUnload", ves_icall_System_AppDomain_InternalUnload},
4535 {"LoadAssembly", ves_icall_System_AppDomain_LoadAssembly},
4536 {"LoadAssemblyRaw", ves_icall_System_AppDomain_LoadAssemblyRaw},
4537 {"SetData", ves_icall_System_AppDomain_SetData},
4538 {"createDomain", ves_icall_System_AppDomain_createDomain},
4539 {"getCurDomain", ves_icall_System_AppDomain_getCurDomain},
4540 {"getFriendlyName", ves_icall_System_AppDomain_getFriendlyName},
4541 {"getSetup", ves_icall_System_AppDomain_getSetup}
4544 static const IcallEntry appdomainsetup_icalls [] = {
4545 {"InitAppDomainSetup", ves_icall_System_AppDomainSetup_InitAppDomainSetup}
4548 static const IcallEntry argiterator_icalls [] = {
4549 {"IntGetNextArg()", mono_ArgIterator_IntGetNextArg},
4550 {"IntGetNextArg(intptr)", mono_ArgIterator_IntGetNextArgT},
4551 {"IntGetNextArgType", mono_ArgIterator_IntGetNextArgType},
4552 {"Setup", mono_ArgIterator_Setup}
4555 static const IcallEntry array_icalls [] = {
4556 {"Clone", mono_array_clone},
4557 {"CreateInstanceImpl", ves_icall_System_Array_CreateInstanceImpl},
4558 {"FastCopy", ves_icall_System_Array_FastCopy},
4559 {"GetLength", ves_icall_System_Array_GetLength},
4560 {"GetLowerBound", ves_icall_System_Array_GetLowerBound},
4561 {"GetRank", ves_icall_System_Array_GetRank},
4562 {"GetValue", ves_icall_System_Array_GetValue},
4563 {"GetValueImpl", ves_icall_System_Array_GetValueImpl},
4564 {"SetValue", ves_icall_System_Array_SetValue},
4565 {"SetValueImpl", ves_icall_System_Array_SetValueImpl}
4568 static const IcallEntry buffer_icalls [] = {
4569 {"BlockCopyInternal", ves_icall_System_Buffer_BlockCopyInternal},
4570 {"ByteLengthInternal", ves_icall_System_Buffer_ByteLengthInternal},
4571 {"GetByteInternal", ves_icall_System_Buffer_GetByteInternal},
4572 {"SetByteInternal", ves_icall_System_Buffer_SetByteInternal}
4575 static const IcallEntry char_icalls [] = {
4576 {"GetNumericValue", ves_icall_System_Char_GetNumericValue},
4577 {"GetUnicodeCategory", ves_icall_System_Char_GetUnicodeCategory},
4578 {"IsControl", ves_icall_System_Char_IsControl},
4579 {"IsDigit", ves_icall_System_Char_IsDigit},
4580 {"IsLetter", ves_icall_System_Char_IsLetter},
4581 {"IsLower", ves_icall_System_Char_IsLower},
4582 {"IsNumber", ves_icall_System_Char_IsNumber},
4583 {"IsPunctuation", ves_icall_System_Char_IsPunctuation},
4584 {"IsSeparator", ves_icall_System_Char_IsSeparator},
4585 {"IsSurrogate", ves_icall_System_Char_IsSurrogate},
4586 {"IsSymbol", ves_icall_System_Char_IsSymbol},
4587 {"IsUpper", ves_icall_System_Char_IsUpper},
4588 {"IsWhiteSpace", ves_icall_System_Char_IsWhiteSpace},
4589 {"ToLower", ves_icall_System_Char_ToLower},
4590 {"ToUpper", ves_icall_System_Char_ToUpper}
4593 static const IcallEntry defaultconf_icalls [] = {
4594 {"get_machine_config_path", ves_icall_System_Configuration_DefaultConfig_get_machine_config_path}
4597 static const IcallEntry timezone_icalls [] = {
4598 {"GetTimeZoneData", ves_icall_System_CurrentTimeZone_GetTimeZoneData}
4601 static const IcallEntry datetime_icalls [] = {
4602 {"GetNow", ves_icall_System_DateTime_GetNow}
4605 static const IcallEntry decimal_icalls [] = {
4606 {"decimal2Int64", mono_decimal2Int64},
4607 {"decimal2UInt64", mono_decimal2UInt64},
4608 {"decimal2double", mono_decimal2double},
4609 {"decimal2string", mono_decimal2string},
4610 {"decimalCompare", mono_decimalCompare},
4611 {"decimalDiv", mono_decimalDiv},
4612 {"decimalFloorAndTrunc", mono_decimalFloorAndTrunc},
4613 {"decimalIncr", mono_decimalIncr},
4614 {"decimalIntDiv", mono_decimalIntDiv},
4615 {"decimalMult", mono_decimalMult},
4616 {"decimalRound", mono_decimalRound},
4617 {"decimalSetExponent", mono_decimalSetExponent},
4618 {"double2decimal", mono_double2decimal}, /* FIXME: wrong signature. */
4619 {"string2decimal", mono_string2decimal}
4622 static const IcallEntry delegate_icalls [] = {
4623 {"CreateDelegate_internal", ves_icall_System_Delegate_CreateDelegate_internal}
4626 static const IcallEntry tracelist_icalls [] = {
4627 {"WriteWindowsDebugString", ves_icall_System_Diagnostics_DefaultTraceListener_WriteWindowsDebugString}
4630 static const IcallEntry fileversion_icalls [] = {
4631 {"GetVersionInfo_internal(string)", ves_icall_System_Diagnostics_FileVersionInfo_GetVersionInfo_internal}
4634 static const IcallEntry process_icalls [] = {
4635 {"ExitCode_internal(intptr)", ves_icall_System_Diagnostics_Process_ExitCode_internal},
4636 {"ExitTime_internal(intptr)", ves_icall_System_Diagnostics_Process_ExitTime_internal},
4637 {"GetModules_internal()", ves_icall_System_Diagnostics_Process_GetModules_internal},
4638 {"GetPid_internal()", ves_icall_System_Diagnostics_Process_GetPid_internal},
4639 {"GetProcess_internal(int)", ves_icall_System_Diagnostics_Process_GetProcess_internal},
4640 {"GetProcesses_internal()", ves_icall_System_Diagnostics_Process_GetProcesses_internal},
4641 {"GetWorkingSet_internal(intptr,int&,int&)", ves_icall_System_Diagnostics_Process_GetWorkingSet_internal},
4642 {"ProcessName_internal(intptr)", ves_icall_System_Diagnostics_Process_ProcessName_internal},
4643 {"Process_free_internal(intptr)", ves_icall_System_Diagnostics_Process_Process_free_internal},
4644 {"SetWorkingSet_internal(intptr,int,int,bool)", ves_icall_System_Diagnostics_Process_SetWorkingSet_internal},
4645 {"StartTime_internal(intptr)", ves_icall_System_Diagnostics_Process_StartTime_internal},
4646 {"Start_internal(string,string,intptr,intptr,intptr,System.Diagnostics.Process/ProcInfo&)", ves_icall_System_Diagnostics_Process_Start_internal},
4647 {"WaitForExit_internal(intptr,int)", ves_icall_System_Diagnostics_Process_WaitForExit_internal}
4650 static const IcallEntry double_icalls [] = {
4651 {"AssertEndianity", ves_icall_System_Double_AssertEndianity},
4652 {"ParseImpl", mono_double_ParseImpl}
4655 static const IcallEntry enum_icalls [] = {
4656 {"ToObject", ves_icall_System_Enum_ToObject},
4657 {"get_value", ves_icall_System_Enum_get_value}
4660 static const IcallEntry environment_icalls [] = {
4661 {"Exit", ves_icall_System_Environment_Exit},
4662 {"GetCommandLineArgs", mono_runtime_get_main_args},
4663 {"GetEnvironmentVariable", ves_icall_System_Environment_GetEnvironmentVariable},
4664 {"GetEnvironmentVariableNames", ves_icall_System_Environment_GetEnvironmentVariableNames},
4665 {"GetMachineConfigPath", ves_icall_System_Configuration_DefaultConfig_get_machine_config_path},
4666 {"get_ExitCode", mono_environment_exitcode_get},
4667 {"get_HasShutdownStarted", ves_icall_System_Environment_get_HasShutdownStarted},
4668 {"get_MachineName", ves_icall_System_Environment_get_MachineName},
4669 {"get_NewLine", ves_icall_System_Environment_get_NewLine},
4670 {"get_Platform", ves_icall_System_Environment_get_Platform},
4671 {"get_TickCount", ves_icall_System_Environment_get_TickCount},
4672 {"internalGetGacPath", ves_icall_System_Environment_GetGacPath},
4673 {"set_ExitCode", mono_environment_exitcode_set}
4676 static const IcallEntry cultureinfo_icalls [] = {
4677 {"construct_compareinfo(object,string)", ves_icall_System_Globalization_CompareInfo_construct_compareinfo},
4678 {"construct_internal_locale(string)", ves_icall_System_Globalization_CultureInfo_construct_internal_locale}
4681 static const IcallEntry compareinfo_icalls [] = {
4682 {"assign_sortkey(object,string,System.Globalization.CompareOptions)", ves_icall_System_Globalization_CompareInfo_assign_sortkey},
4683 {"construct_compareinfo(string)", ves_icall_System_Globalization_CompareInfo_construct_compareinfo},
4684 {"free_internal_collator()", ves_icall_System_Globalization_CompareInfo_free_internal_collator},
4685 {"internal_compare(string,int,int,string,int,int,System.Globalization.CompareOptions)", ves_icall_System_Globalization_CompareInfo_internal_compare},
4686 {"internal_index(string,int,int,char,System.Globalization.CompareOptions,bool)", ves_icall_System_Globalization_CompareInfo_internal_index_char},
4687 {"internal_index(string,int,int,string,System.Globalization.CompareOptions,bool)", ves_icall_System_Globalization_CompareInfo_internal_index}
4690 static const IcallEntry gc_icalls [] = {
4691 {"GetTotalMemory", ves_icall_System_GC_GetTotalMemory},
4692 {"InternalCollect", ves_icall_System_GC_InternalCollect},
4693 {"KeepAlive", ves_icall_System_GC_KeepAlive},
4694 {"ReRegisterForFinalize", ves_icall_System_GC_ReRegisterForFinalize},
4695 {"SuppressFinalize", ves_icall_System_GC_SuppressFinalize},
4696 {"WaitForPendingFinalizers", ves_icall_System_GC_WaitForPendingFinalizers}
4699 static const IcallEntry famwatcher_icalls [] = {
4700 {"InternalFAMNextEvent", ves_icall_System_IO_FAMW_InternalFAMNextEvent}
4703 static const IcallEntry filewatcher_icalls [] = {
4704 {"InternalCloseDirectory", ves_icall_System_IO_FSW_CloseDirectory},
4705 {"InternalOpenDirectory", ves_icall_System_IO_FSW_OpenDirectory},
4706 {"InternalReadDirectoryChanges", ves_icall_System_IO_FSW_ReadDirectoryChanges},
4707 {"InternalSupportsFSW", ves_icall_System_IO_FSW_SupportsFSW}
4710 static const IcallEntry path_icalls [] = {
4711 {"get_temp_path", ves_icall_System_IO_get_temp_path}
4714 static const IcallEntry monoio_icalls [] = {
4715 {"Close(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Close},
4716 {"CopyFile(string,string,bool,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_CopyFile},
4717 {"CreateDirectory(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_CreateDirectory},
4718 {"CreatePipe(intptr&,intptr&)", ves_icall_System_IO_MonoIO_CreatePipe},
4719 {"DeleteFile(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_DeleteFile},
4720 {"FindClose(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_FindClose},
4721 {"FindFirstFile(string,System.IO.MonoIOStat&,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_FindFirstFile},
4722 {"FindNextFile(intptr,System.IO.MonoIOStat&,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_FindNextFile},
4723 {"Flush(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Flush},
4724 {"GetCurrentDirectory(System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetCurrentDirectory},
4725 {"GetFileAttributes(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetFileAttributes},
4726 {"GetFileStat(string,System.IO.MonoIOStat&,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetFileStat},
4727 {"GetFileType(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetFileType},
4728 {"GetLength(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetLength},
4729 {"GetTempPath(string&)", ves_icall_System_IO_MonoIO_GetTempPath},
4730 {"MoveFile(string,string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_MoveFile},
4731 {"Open(string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Open},
4732 {"Read(intptr,byte[],int,int,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Read},
4733 {"RemoveDirectory(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_RemoveDirectory},
4734 {"Seek(intptr,long,System.IO.SeekOrigin,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Seek},
4735 {"SetCurrentDirectory(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_SetCurrentDirectory},
4736 {"SetFileAttributes(string,System.IO.FileAttributes,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_SetFileAttributes},
4737 {"SetFileTime(intptr,long,long,long,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_SetFileTime},
4738 {"SetLength(intptr,long,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_SetLength},
4739 {"Write(intptr,byte[],int,int,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Write},
4740 {"get_AltDirectorySeparatorChar", ves_icall_System_IO_MonoIO_get_AltDirectorySeparatorChar},
4741 {"get_ConsoleError", ves_icall_System_IO_MonoIO_get_ConsoleError},
4742 {"get_ConsoleInput", ves_icall_System_IO_MonoIO_get_ConsoleInput},
4743 {"get_ConsoleOutput", ves_icall_System_IO_MonoIO_get_ConsoleOutput},
4744 {"get_DirectorySeparatorChar", ves_icall_System_IO_MonoIO_get_DirectorySeparatorChar},
4745 {"get_InvalidPathChars", ves_icall_System_IO_MonoIO_get_InvalidPathChars},
4746 {"get_PathSeparator", ves_icall_System_IO_MonoIO_get_PathSeparator},
4747 {"get_VolumeSeparatorChar", ves_icall_System_IO_MonoIO_get_VolumeSeparatorChar}
4750 static const IcallEntry math_icalls [] = {
4751 {"Acos", ves_icall_System_Math_Acos},
4752 {"Asin", ves_icall_System_Math_Asin},
4753 {"Atan", ves_icall_System_Math_Atan},
4754 {"Atan2", ves_icall_System_Math_Atan2},
4755 {"Cos", ves_icall_System_Math_Cos},
4756 {"Cosh", ves_icall_System_Math_Cosh},
4757 {"Exp", ves_icall_System_Math_Exp},
4758 {"Floor", ves_icall_System_Math_Floor},
4759 {"Log", ves_icall_System_Math_Log},
4760 {"Log10", ves_icall_System_Math_Log10},
4761 {"Pow", ves_icall_System_Math_Pow},
4762 {"Round", ves_icall_System_Math_Round},
4763 {"Round2", ves_icall_System_Math_Round2},
4764 {"Sin", ves_icall_System_Math_Sin},
4765 {"Sinh", ves_icall_System_Math_Sinh},
4766 {"Sqrt", ves_icall_System_Math_Sqrt},
4767 {"Tan", ves_icall_System_Math_Tan},
4768 {"Tanh", ves_icall_System_Math_Tanh}
4771 static const IcallEntry customattrs_icalls [] = {
4772 {"GetCustomAttributes", mono_reflection_get_custom_attrs}
4775 static const IcallEntry enuminfo_icalls [] = {
4776 {"get_enum_info", ves_icall_get_enum_info}
4779 static const IcallEntry fieldinfo_icalls [] = {
4780 {"internal_from_handle", ves_icall_System_Reflection_FieldInfo_internal_from_handle}
4783 static const IcallEntry monotype_icalls [] = {
4784 {"GetArrayRank", ves_icall_MonoType_GetArrayRank},
4785 {"GetConstructors", ves_icall_Type_GetConstructors},
4786 {"GetElementType", ves_icall_MonoType_GetElementType},
4787 {"GetEvents", ves_icall_Type_GetEvents},
4788 {"GetField", ves_icall_Type_GetField},
4789 {"GetFields", ves_icall_Type_GetFields},
4790 {"GetInterfaces", ves_icall_Type_GetInterfaces},
4791 {"GetMethodsByName", ves_icall_Type_GetMethodsByName},
4792 {"GetNestedType", ves_icall_Type_GetNestedType},
4793 {"GetNestedTypes", ves_icall_Type_GetNestedTypes},
4794 {"GetPropertiesByName", ves_icall_Type_GetPropertiesByName},
4795 {"InternalGetEvent", ves_icall_MonoType_GetEvent},
4796 {"IsByRefImpl", ves_icall_type_isbyref},
4797 {"IsPointerImpl", ves_icall_type_ispointer},
4798 {"IsPrimitiveImpl", ves_icall_type_isprimitive},
4799 {"getFullName", ves_icall_System_MonoType_getFullName},
4800 {"get_Assembly", ves_icall_MonoType_get_Assembly},
4801 {"get_BaseType", ves_icall_get_type_parent},
4802 {"get_DeclaringMethod", ves_icall_MonoType_get_DeclaringMethod},
4803 {"get_DeclaringType", ves_icall_MonoType_get_DeclaringType},
4804 {"get_HasGenericArguments", ves_icall_MonoType_get_HasGenericArguments},
4805 {"get_IsGenericParameter", ves_icall_MonoType_get_IsGenericParameter},
4806 {"get_Module", ves_icall_MonoType_get_Module},
4807 {"get_Name", ves_icall_MonoType_get_Name},
4808 {"get_Namespace", ves_icall_MonoType_get_Namespace},
4809 {"get_UnderlyingSystemType", ves_icall_MonoType_get_UnderlyingSystemType},
4810 {"get_attributes", ves_icall_get_attributes},
4811 {"type_from_obj", mono_type_type_from_obj}
4814 static const IcallEntry assembly_icalls [] = {
4815 {"FillName", ves_icall_System_Reflection_Assembly_FillName},
4816 {"GetCallingAssembly", ves_icall_System_Reflection_Assembly_GetCallingAssembly},
4817 {"GetEntryAssembly", ves_icall_System_Reflection_Assembly_GetEntryAssembly},
4818 {"GetExecutingAssembly", ves_icall_System_Reflection_Assembly_GetExecutingAssembly},
4819 {"GetFilesInternal", ves_icall_System_Reflection_Assembly_GetFilesInternal},
4820 {"GetManifestResourceInfoInternal", ves_icall_System_Reflection_Assembly_GetManifestResourceInfoInternal},
4821 {"GetManifestResourceInternal", ves_icall_System_Reflection_Assembly_GetManifestResourceInternal},
4822 {"GetManifestResourceNames", ves_icall_System_Reflection_Assembly_GetManifestResourceNames},
4823 {"GetModulesInternal", ves_icall_System_Reflection_Assembly_GetModulesInternal},
4824 {"GetNamespaces", ves_icall_System_Reflection_Assembly_GetNamespaces},
4825 {"GetReferencedAssemblies", ves_icall_System_Reflection_Assembly_GetReferencedAssemblies},
4826 {"GetTypes", ves_icall_System_Reflection_Assembly_GetTypes},
4827 {"InternalGetAssemblyName", ves_icall_System_Reflection_Assembly_InternalGetAssemblyName},
4828 {"InternalGetType", ves_icall_System_Reflection_Assembly_InternalGetType},
4829 {"InternalImageRuntimeVersion", ves_icall_System_Reflection_Assembly_InternalImageRuntimeVersion},
4830 {"LoadFrom", ves_icall_System_Reflection_Assembly_LoadFrom},
4832 * Private icalls for the Mono Debugger
4834 {"MonoDebugger_GetLocalTypeFromSignature", ves_icall_MonoDebugger_GetLocalTypeFromSignature},
4835 {"MonoDebugger_GetMethod", ves_icall_MonoDebugger_GetMethod},
4836 {"MonoDebugger_GetMethodToken", ves_icall_MonoDebugger_GetMethodToken},
4837 {"MonoDebugger_GetType", ves_icall_MonoDebugger_GetType},
4838 /* normal icalls again */
4839 {"get_EntryPoint", ves_icall_System_Reflection_Assembly_get_EntryPoint},
4840 {"get_code_base", ves_icall_System_Reflection_Assembly_get_code_base},
4841 {"get_location", ves_icall_System_Reflection_Assembly_get_location}
4844 static const IcallEntry methodbase_icalls [] = {
4845 {"GetCurrentMethod", ves_icall_GetCurrentMethod}
4848 static const IcallEntry methodinfo_icalls [] = {
4849 {"BindGenericParameters", mono_reflection_bind_generic_method_parameters},
4850 {"get_IsGenericMethodDefinition", ves_icall_MethodInfo_get_IsGenericMethodDefinition}
4853 static const IcallEntry module_icalls [] = {
4854 {"Close", ves_icall_System_Reflection_Module_Close},
4855 {"GetGlobalType", ves_icall_System_Reflection_Module_GetGlobalType},
4856 {"GetGuidInternal", ves_icall_System_Reflection_Module_GetGuidInternal},
4857 {"InternalGetTypes", ves_icall_System_Reflection_Module_InternalGetTypes}
4860 static const IcallEntry monocmethod_icalls [] = {
4861 {"InternalInvoke", ves_icall_InternalInvoke}
4864 static const IcallEntry monoeventinfo_icalls [] = {
4865 {"get_event_info", ves_icall_get_event_info}
4868 static const IcallEntry monofield_icalls [] = {
4869 {"GetParentType", ves_icall_MonoField_GetParentType},
4870 {"GetValueInternal", ves_icall_MonoField_GetValueInternal},
4871 {"SetValueInternal", ves_icall_FieldInfo_SetValueInternal}
4874 static const IcallEntry monogenericinst_icalls [] = {
4875 {"GetInterfaces_internal", ves_icall_MonoGenericInst_GetInterfaces},
4876 {"GetParentType", ves_icall_MonoGenericInst_GetParentType},
4877 {"inflate_ctor", mono_reflection_inflate_method_or_ctor},
4878 {"inflate_field", mono_reflection_inflate_field},
4879 {"inflate_method", mono_reflection_inflate_method_or_ctor}
4882 static const IcallEntry monogenericparam_icalls [] = {
4883 {"initialize", ves_icall_MonoGenericParam_initialize}
4886 static const IcallEntry monomethod_icalls [] = {
4887 {"GetGenericArguments", ves_icall_MonoMethod_GetGenericArguments},
4888 {"InternalInvoke", ves_icall_InternalInvoke},
4889 {"get_base_definition", ves_icall_MonoMethod_get_base_definition}
4892 static const IcallEntry monomethodinfo_icalls [] = {
4893 {"get_method_info", ves_icall_get_method_info},
4894 {"get_parameter_info", ves_icall_get_parameter_info}
4897 static const IcallEntry monopropertyinfo_icalls [] = {
4898 {"get_property_info", ves_icall_get_property_info}
4901 static const IcallEntry dns_icalls [] = {
4902 {"GetHostByAddr_internal(string,string&,string[]&,string[]&)", ves_icall_System_Net_Dns_GetHostByAddr_internal},
4903 {"GetHostByName_internal(string,string&,string[]&,string[]&)", ves_icall_System_Net_Dns_GetHostByName_internal},
4904 {"GetHostName_internal(string&)", ves_icall_System_Net_Dns_GetHostName_internal}
4907 static const IcallEntry socket_icalls [] = {
4908 {"Accept_internal", ves_icall_System_Net_Sockets_Socket_Accept_internal},
4909 {"Available_internal", ves_icall_System_Net_Sockets_Socket_Available_internal},
4910 {"Bind_internal", ves_icall_System_Net_Sockets_Socket_Bind_internal},
4911 {"Blocking_internal", ves_icall_System_Net_Sockets_Socket_Blocking_internal},
4912 {"Close_internal", ves_icall_System_Net_Sockets_Socket_Close_internal},
4913 {"Connect_internal", ves_icall_System_Net_Sockets_Socket_Connect_internal},
4914 {"GetSocketOption_arr_internal", ves_icall_System_Net_Sockets_Socket_GetSocketOption_arr_internal},
4915 {"GetSocketOption_obj_internal", ves_icall_System_Net_Sockets_Socket_GetSocketOption_obj_internal},
4916 {"Listen_internal", ves_icall_System_Net_Sockets_Socket_Listen_internal},
4917 {"LocalEndPoint_internal", ves_icall_System_Net_Sockets_Socket_LocalEndPoint_internal},
4918 {"Receive_internal", ves_icall_System_Net_Sockets_Socket_Receive_internal},
4919 {"RecvFrom_internal", ves_icall_System_Net_Sockets_Socket_RecvFrom_internal},
4920 {"RemoteEndPoint_internal", ves_icall_System_Net_Sockets_Socket_RemoteEndPoint_internal},
4921 {"Select_internal", ves_icall_System_Net_Sockets_Socket_Select_internal},
4922 {"SendTo_internal", ves_icall_System_Net_Sockets_Socket_SendTo_internal},
4923 {"Send_internal", ves_icall_System_Net_Sockets_Socket_Send_internal},
4924 {"SetSocketOption_internal", ves_icall_System_Net_Sockets_Socket_SetSocketOption_internal},
4925 {"Shutdown_internal", ves_icall_System_Net_Sockets_Socket_Shutdown_internal},
4926 {"Socket_internal", ves_icall_System_Net_Sockets_Socket_Socket_internal}
4929 static const IcallEntry socketex_icalls [] = {
4930 {"SocketException::WSAGetLastError_internal", ves_icall_System_Net_Sockets_SocketException_WSAGetLastError_internal}
4933 static const IcallEntry object_icalls [] = {
4934 {"GetType", ves_icall_System_Object_GetType},
4935 {"InternalGetHashCode", ves_icall_System_Object_GetHashCode},
4936 {"MemberwiseClone", ves_icall_System_Object_MemberwiseClone},
4937 {"obj_address", ves_icall_System_Object_obj_address}
4940 static const IcallEntry assemblybuilder_icalls[] = {
4941 {"InternalAddModule", mono_image_load_module},
4942 {"basic_init", mono_image_basic_init}
4945 static const IcallEntry customattrbuilder_icalls [] = {
4946 {"GetBlob", mono_reflection_get_custom_attrs_blob}
4949 static const IcallEntry dynamicmethod_icalls [] = {
4950 {"create_dynamic_method", mono_reflection_create_dynamic_method}
4953 static const IcallEntry methodbuilder_icalls [] = {
4954 {"define_generic_parameter", ves_icall_MethodBuilder_define_generic_parameter}
4957 static const IcallEntry modulebuilder_icalls [] = {
4958 {"basic_init", mono_image_module_basic_init},
4959 {"build_metadata", ves_icall_ModuleBuilder_build_metadata},
4960 {"create_modified_type", ves_icall_ModuleBuilder_create_modified_type},
4961 {"getDataChunk", ves_icall_ModuleBuilder_getDataChunk},
4962 {"getToken", ves_icall_ModuleBuilder_getToken},
4963 {"getUSIndex", mono_image_insert_string}
4966 static const IcallEntry signaturehelper_icalls [] = {
4967 {"get_signature_field", mono_reflection_sighelper_get_signature_field},
4968 {"get_signature_local", mono_reflection_sighelper_get_signature_local}
4971 static const IcallEntry typebuilder_icalls [] = {
4972 {"create_internal_class", mono_reflection_create_internal_class},
4973 {"create_runtime_class", mono_reflection_create_runtime_class},
4974 {"define_generic_parameter", ves_icall_TypeBuilder_define_generic_parameter},
4975 {"get_IsGenericParameter", ves_icall_TypeBuilder_get_IsGenericParameter},
4976 {"setup_generic_class", mono_reflection_setup_generic_class},
4977 {"setup_internal_class", mono_reflection_setup_internal_class}
4980 static const IcallEntry runtimehelpers_icalls [] = {
4981 {"GetObjectValue", ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetObjectValue},
4982 {"GetOffsetToStringData", ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetOffsetToStringData},
4983 {"InitializeArray", ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_InitializeArray},
4984 {"RunClassConstructor", ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_RunClassConstructor}
4987 static const IcallEntry gchandle_icalls [] = {
4988 {"FreeHandle", ves_icall_System_GCHandle_FreeHandle},
4989 {"GetAddrOfPinnedObject", ves_icall_System_GCHandle_GetAddrOfPinnedObject},
4990 {"GetTarget", ves_icall_System_GCHandle_GetTarget},
4991 {"GetTargetHandle", ves_icall_System_GCHandle_GetTargetHandle}
4994 static const IcallEntry marshal_icalls [] = {
4995 {"AllocCoTaskMem", ves_icall_System_Runtime_InteropServices_Marshal_AllocCoTaskMem},
4996 {"AllocHGlobal", mono_marshal_alloc},
4997 {"DestroyStructure", ves_icall_System_Runtime_InteropServices_Marshal_DestroyStructure},
4998 {"FreeCoTaskMem", ves_icall_System_Runtime_InteropServices_Marshal_FreeCoTaskMem},
4999 {"FreeHGlobal", mono_marshal_free},
5000 {"GetLastWin32Error", ves_icall_System_Runtime_InteropServices_Marshal_GetLastWin32Error},
5001 {"OffsetOf", ves_icall_System_Runtime_InteropServices_Marshal_OffsetOf},
5002 {"Prelink", ves_icall_System_Runtime_InteropServices_Marshal_Prelink},
5003 {"PrelinkAll", ves_icall_System_Runtime_InteropServices_Marshal_PrelinkAll},
5004 {"PtrToStringAnsi(intptr)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi},
5005 {"PtrToStringAnsi(intptr,int)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi_len},
5006 {"PtrToStringAuto(intptr)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi},
5007 {"PtrToStringAuto(intptr,int)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi_len},
5008 {"PtrToStringBSTR", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringBSTR},
5009 {"PtrToStringUni(intptr)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringUni},
5010 {"PtrToStringUni(intptr,int)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringUni_len},
5011 {"PtrToStructure(intptr,System.Type)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStructure_type},
5012 {"PtrToStructure(intptr,object)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStructure},
5013 {"ReAllocHGlobal", mono_marshal_realloc},
5014 {"ReadByte", ves_icall_System_Runtime_InteropServices_Marshal_ReadByte},
5015 {"ReadInt16", ves_icall_System_Runtime_InteropServices_Marshal_ReadInt16},
5016 {"ReadInt32", ves_icall_System_Runtime_InteropServices_Marshal_ReadInt32},
5017 {"ReadInt64", ves_icall_System_Runtime_InteropServices_Marshal_ReadInt64},
5018 {"ReadIntPtr", ves_icall_System_Runtime_InteropServices_Marshal_ReadIntPtr},
5019 {"SizeOf", ves_icall_System_Runtime_InteropServices_Marshal_SizeOf},
5020 {"StringToHGlobalAnsi", ves_icall_System_Runtime_InteropServices_Marshal_StringToHGlobalAnsi},
5021 {"StringToHGlobalAuto", ves_icall_System_Runtime_InteropServices_Marshal_StringToHGlobalAnsi},
5022 {"StringToHGlobalUni", ves_icall_System_Runtime_InteropServices_Marshal_StringToHGlobalUni},
5023 {"StructureToPtr", ves_icall_System_Runtime_InteropServices_Marshal_StructureToPtr},
5024 {"WriteByte", ves_icall_System_Runtime_InteropServices_Marshal_WriteByte},
5025 {"WriteInt16", ves_icall_System_Runtime_InteropServices_Marshal_WriteInt16},
5026 {"WriteInt32", ves_icall_System_Runtime_InteropServices_Marshal_WriteInt32},
5027 {"WriteInt64", ves_icall_System_Runtime_InteropServices_Marshal_WriteInt64},
5028 {"WriteIntPtr", ves_icall_System_Runtime_InteropServices_Marshal_WriteIntPtr},
5029 {"copy_from_unmanaged", ves_icall_System_Runtime_InteropServices_Marshal_copy_from_unmanaged},
5030 {"copy_to_unmanaged", ves_icall_System_Runtime_InteropServices_Marshal_copy_to_unmanaged}
5033 static const IcallEntry activationservices_icalls [] = {
5034 {"AllocateUninitializedClassInstance", ves_icall_System_Runtime_Activation_ActivationServices_AllocateUninitializedClassInstance},
5035 {"EnableProxyActivation", ves_icall_System_Runtime_Activation_ActivationServices_EnableProxyActivation}
5038 static const IcallEntry monomethodmessage_icalls [] = {
5039 {"InitMessage", ves_icall_MonoMethodMessage_InitMessage}
5042 static const IcallEntry realproxy_icalls [] = {
5043 {"InternalGetTransparentProxy", ves_icall_Remoting_RealProxy_GetTransparentProxy}
5046 static const IcallEntry remotingservices_icalls [] = {
5047 {"InternalExecute", ves_icall_InternalExecute},
5048 {"IsTransparentProxy", ves_icall_IsTransparentProxy}
5051 static const IcallEntry rng_icalls [] = {
5052 {"InternalGetBytes", ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_InternalGetBytes}
5055 static const IcallEntry methodhandle_icalls [] = {
5056 {"GetFunctionPointer", ves_icall_RuntimeMethod_GetFunctionPointer}
5059 static const IcallEntry string_icalls [] = {
5060 {".ctor(char*)", ves_icall_System_String_ctor_charp},
5061 {".ctor(char*,int,int)", ves_icall_System_String_ctor_charp_int_int},
5062 {".ctor(char,int)", ves_icall_System_String_ctor_char_int},
5063 {".ctor(char[])", ves_icall_System_String_ctor_chara},
5064 {".ctor(char[],int,int)", ves_icall_System_String_ctor_chara_int_int},
5065 {".ctor(sbyte*)", ves_icall_System_String_ctor_sbytep},
5066 {".ctor(sbyte*,int,int)", ves_icall_System_String_ctor_sbytep_int_int},
5067 {".ctor(sbyte*,int,int,System.Text.Encoding)", ves_icall_System_String_ctor_encoding},
5068 {"GetHashCode", ves_icall_System_String_GetHashCode},
5069 {"InternalAllocateStr", ves_icall_System_String_InternalAllocateStr},
5070 {"InternalCompare(string,int,string,int,int,int)", ves_icall_System_String_InternalCompareStr_N},
5071 {"InternalCopyTo", ves_icall_System_String_InternalCopyTo},
5072 {"InternalEquals", ves_icall_System_String_InternalEquals},
5073 {"InternalIndexOf(char,int,int)", ves_icall_System_String_InternalIndexOf_Char},
5074 {"InternalIndexOf(string,int,int)", ves_icall_System_String_InternalIndexOf_Str},
5075 {"InternalIndexOfAny", ves_icall_System_String_InternalIndexOfAny},
5076 {"InternalInsert", ves_icall_System_String_InternalInsert},
5077 {"InternalIntern", ves_icall_System_String_InternalIntern},
5078 {"InternalIsInterned", ves_icall_System_String_InternalIsInterned},
5079 {"InternalJoin", ves_icall_System_String_InternalJoin},
5080 {"InternalLastIndexOf(char,int,int)", ves_icall_System_String_InternalLastIndexOf_Char},
5081 {"InternalLastIndexOf(string,int,int)", ves_icall_System_String_InternalLastIndexOf_Str},
5082 {"InternalLastIndexOfAny", ves_icall_System_String_InternalLastIndexOfAny},
5083 {"InternalPad", ves_icall_System_String_InternalPad},
5084 {"InternalRemove", ves_icall_System_String_InternalRemove},
5085 {"InternalReplace(char,char)", ves_icall_System_String_InternalReplace_Char},
5086 {"InternalReplace(string,string)", ves_icall_System_String_InternalReplace_Str},
5087 {"InternalReplace(string,string,System.Globalization.CompareInfo)", ves_icall_System_String_InternalReplace_Str_Comp},
5088 {"InternalSplit", ves_icall_System_String_InternalSplit},
5089 {"InternalStrcpy(string,int,string)", ves_icall_System_String_InternalStrcpy_Str},
5090 {"InternalStrcpy(string,int,string,int,int)", ves_icall_System_String_InternalStrcpy_StrN},
5091 {"InternalToLower", ves_icall_System_String_InternalToLower},
5092 {"InternalToLower(System.Globalization.CultureInfo)", ves_icall_System_String_InternalToLower_Comp},
5093 {"InternalToUpper", ves_icall_System_String_InternalToUpper},
5094 {"InternalToUpper(System.Globalization.CultureInfo)", ves_icall_System_String_InternalToUpper_Comp},
5095 {"InternalTrim", ves_icall_System_String_InternalTrim},
5096 {"get_Chars", ves_icall_System_String_get_Chars}
5099 static const IcallEntry encoding_icalls [] = {
5100 {"InternalCodePage", ves_icall_System_Text_Encoding_InternalCodePage}
5103 static const IcallEntry monitor_icalls [] = {
5104 {"Monitor_exit", ves_icall_System_Threading_Monitor_Monitor_exit},
5105 {"Monitor_pulse", ves_icall_System_Threading_Monitor_Monitor_pulse},
5106 {"Monitor_pulse_all", ves_icall_System_Threading_Monitor_Monitor_pulse_all},
5107 {"Monitor_test_owner", ves_icall_System_Threading_Monitor_Monitor_test_owner},
5108 {"Monitor_test_synchronised", ves_icall_System_Threading_Monitor_Monitor_test_synchronised},
5109 {"Monitor_try_enter", ves_icall_System_Threading_Monitor_Monitor_try_enter},
5110 {"Monitor_wait", ves_icall_System_Threading_Monitor_Monitor_wait}
5113 static const IcallEntry interlocked_icalls [] = {
5114 {"CompareExchange(int&,int,int)", ves_icall_System_Threading_Interlocked_CompareExchange_Int},
5115 {"CompareExchange(object&,object,object)", ves_icall_System_Threading_Interlocked_CompareExchange_Object},
5116 {"CompareExchange(single&,single,single)", ves_icall_System_Threading_Interlocked_CompareExchange_Single},
5117 {"Decrement(int&)", ves_icall_System_Threading_Interlocked_Decrement_Int},
5118 {"Decrement(long&)", ves_icall_System_Threading_Interlocked_Decrement_Long},
5119 {"Exchange(int&,int)", ves_icall_System_Threading_Interlocked_Exchange_Int},
5120 {"Exchange(object&,object)", ves_icall_System_Threading_Interlocked_Exchange_Object},
5121 {"Exchange(single&,single)", ves_icall_System_Threading_Interlocked_Exchange_Single},
5122 {"Increment(int&)", ves_icall_System_Threading_Interlocked_Increment_Int},
5123 {"Increment(long&)", ves_icall_System_Threading_Interlocked_Increment_Long}
5126 static const IcallEntry mutex_icalls [] = {
5127 {"CreateMutex_internal", ves_icall_System_Threading_Mutex_CreateMutex_internal},
5128 {"ReleaseMutex_internal", ves_icall_System_Threading_Mutex_ReleaseMutex_internal}
5131 static const IcallEntry nativeevents_icalls [] = {
5132 {"CloseEvent_internal", ves_icall_System_Threading_Events_CloseEvent_internal},
5133 {"CreateEvent_internal", ves_icall_System_Threading_Events_CreateEvent_internal},
5134 {"ResetEvent_internal", ves_icall_System_Threading_Events_ResetEvent_internal},
5135 {"SetEvent_internal", ves_icall_System_Threading_Events_SetEvent_internal}
5138 static const IcallEntry thread_icalls [] = {
5139 {"Abort_internal(object)", ves_icall_System_Threading_Thread_Abort},
5140 {"CurrentThread_internal", mono_thread_current},
5141 {"GetDomainID", ves_icall_System_Threading_Thread_GetDomainID},
5142 {"GetName_internal", ves_icall_System_Threading_Thread_GetName_internal},
5143 {"Join_internal", ves_icall_System_Threading_Thread_Join_internal},
5144 {"ResetAbort_internal()", ves_icall_System_Threading_Thread_ResetAbort},
5145 {"SetName_internal", ves_icall_System_Threading_Thread_SetName_internal},
5146 {"Sleep_internal", ves_icall_System_Threading_Thread_Sleep_internal},
5147 {"SlotHash_lookup", ves_icall_System_Threading_Thread_SlotHash_lookup},
5148 {"SlotHash_store", ves_icall_System_Threading_Thread_SlotHash_store},
5149 {"Start_internal", ves_icall_System_Threading_Thread_Start_internal},
5150 {"Thread_free_internal", ves_icall_System_Threading_Thread_Thread_free_internal},
5151 {"Thread_internal", ves_icall_System_Threading_Thread_Thread_internal},
5152 {"VolatileRead(IntPtr&)", ves_icall_System_Threading_Thread_VolatileReadIntPtr},
5153 {"VolatileRead(UIntPtr&)", ves_icall_System_Threading_Thread_VolatileReadIntPtr},
5154 {"VolatileRead(byte&)", ves_icall_System_Threading_Thread_VolatileRead1},
5155 {"VolatileRead(double&)", ves_icall_System_Threading_Thread_VolatileRead8},
5156 {"VolatileRead(float&)", ves_icall_System_Threading_Thread_VolatileRead4},
5157 {"VolatileRead(int&)", ves_icall_System_Threading_Thread_VolatileRead4},
5158 {"VolatileRead(long&)", ves_icall_System_Threading_Thread_VolatileRead8},
5159 {"VolatileRead(object&)", ves_icall_System_Threading_Thread_VolatileReadIntPtr},
5160 {"VolatileRead(sbyte&)", ves_icall_System_Threading_Thread_VolatileRead1},
5161 {"VolatileRead(short&)", ves_icall_System_Threading_Thread_VolatileRead2},
5162 {"VolatileRead(uint&)", ves_icall_System_Threading_Thread_VolatileRead2},
5163 {"VolatileRead(ulong&)", ves_icall_System_Threading_Thread_VolatileRead8},
5164 {"VolatileRead(ushort&)", ves_icall_System_Threading_Thread_VolatileRead2},
5165 {"VolatileWrite(IntPtr&,IntPtr)", ves_icall_System_Threading_Thread_VolatileWriteIntPtr},
5166 {"VolatileWrite(UIntPtr&,UIntPtr)", ves_icall_System_Threading_Thread_VolatileWriteIntPtr},
5167 {"VolatileWrite(byte&,byte)", ves_icall_System_Threading_Thread_VolatileWrite1},
5168 {"VolatileWrite(double&,double)", ves_icall_System_Threading_Thread_VolatileWrite8},
5169 {"VolatileWrite(float&,float)", ves_icall_System_Threading_Thread_VolatileWrite4},
5170 {"VolatileWrite(int&,int)", ves_icall_System_Threading_Thread_VolatileWrite4},
5171 {"VolatileWrite(long&,long)", ves_icall_System_Threading_Thread_VolatileWrite8},
5172 {"VolatileWrite(object&,object)", ves_icall_System_Threading_Thread_VolatileWriteIntPtr},
5173 {"VolatileWrite(sbyte&,sbyte)", ves_icall_System_Threading_Thread_VolatileWrite1},
5174 {"VolatileWrite(short&,short)", ves_icall_System_Threading_Thread_VolatileWrite2},
5175 {"VolatileWrite(uint&,uint)", ves_icall_System_Threading_Thread_VolatileWrite2},
5176 {"VolatileWrite(ulong&,ulong)", ves_icall_System_Threading_Thread_VolatileWrite8},
5177 {"VolatileWrite(ushort&,ushort)", ves_icall_System_Threading_Thread_VolatileWrite2},
5178 {"current_lcid()", ves_icall_System_Threading_Thread_current_lcid}
5181 static const IcallEntry threadpool_icalls [] = {
5182 {"GetAvailableThreads", ves_icall_System_Threading_ThreadPool_GetAvailableThreads},
5183 {"GetMaxThreads", ves_icall_System_Threading_ThreadPool_GetMaxThreads}
5186 static const IcallEntry waithandle_icalls [] = {
5187 {"WaitAll_internal", ves_icall_System_Threading_WaitHandle_WaitAll_internal},
5188 {"WaitAny_internal", ves_icall_System_Threading_WaitHandle_WaitAny_internal},
5189 {"WaitOne_internal", ves_icall_System_Threading_WaitHandle_WaitOne_internal}
5192 static const IcallEntry type_icalls [] = {
5193 {"BindGenericParameters", ves_icall_Type_BindGenericParameters},
5194 {"Equals", ves_icall_type_Equals},
5195 {"GetGenericArguments", ves_icall_Type_GetGenericArguments},
5196 {"GetGenericParameterPosition", ves_icall_Type_GetGenericParameterPosition},
5197 {"GetGenericTypeDefinition_impl", ves_icall_Type_GetGenericTypeDefinition_impl},
5198 {"GetInterfaceMapData", ves_icall_Type_GetInterfaceMapData},
5199 {"GetTypeCode", ves_icall_type_GetTypeCode},
5200 {"IsArrayImpl", ves_icall_Type_IsArrayImpl},
5201 {"IsInstanceOfType", ves_icall_type_IsInstanceOfType},
5202 {"get_IsGenericInstance", ves_icall_Type_get_IsGenericInstance},
5203 {"get_IsGenericTypeDefinition", ves_icall_Type_get_IsGenericTypeDefinition},
5204 {"internal_from_handle", ves_icall_type_from_handle},
5205 {"internal_from_name", ves_icall_type_from_name},
5206 {"make_array_type", ves_icall_Type_make_array_type},
5207 {"make_byref_type", ves_icall_Type_make_byref_type},
5208 {"type_is_assignable_from", ves_icall_type_is_assignable_from},
5209 {"type_is_subtype_of", ves_icall_type_is_subtype_of}
5212 static const IcallEntry typedref_icalls [] = {
5213 {"ToObject", mono_TypedReference_ToObject}
5216 static const IcallEntry valuetype_icalls [] = {
5217 {"InternalEquals", ves_icall_System_ValueType_Equals},
5218 {"InternalGetHashCode", ves_icall_System_ValueType_InternalGetHashCode}
5221 static const IcallEntry web_icalls [] = {
5222 {"GetMachineConfigPath", ves_icall_System_Configuration_DefaultConfig_get_machine_config_path},
5223 {"GetMachineInstallDirectory", ves_icall_System_Web_Util_ICalls_get_machine_install_dir}
5227 static const IcallEntry array_icalls [] = {
5232 /* keep the entries all sorted */
5233 static const IcallMap icall_entries [] = {
5234 {"System.Activation", activator_icalls, G_N_ELEMENTS (activator_icalls)},
5235 {"System.AppDomain", appdomain_icalls, G_N_ELEMENTS (appdomain_icalls)},
5236 {"System.ArgIterator", argiterator_icalls, G_N_ELEMENTS (argiterator_icalls)},
5237 {"System.Array", array_icalls, G_N_ELEMENTS (array_icalls)},
5238 {"System.Buffer", buffer_icalls, G_N_ELEMENTS (buffer_icalls)},
5239 {"System.Char", char_icalls, G_N_ELEMENTS (char_icalls)},
5240 {"System.Configuration.DefaultConfig", defaultconf_icalls, G_N_ELEMENTS (defaultconf_icalls)},
5241 {"System.CurrentTimeZone", timezone_icalls, G_N_ELEMENTS (timezone_icalls)},
5242 {"System.DateTime", datetime_icalls, G_N_ELEMENTS (datetime_icalls)},
5243 {"System.Decimal", decimal_icalls, G_N_ELEMENTS (decimal_icalls)},
5244 {"System.Delegate", delegate_icalls, G_N_ELEMENTS (delegate_icalls)},
5245 {"System.Diagnostic.DefaultTraceListener", tracelist_icalls, G_N_ELEMENTS (tracelist_icalls)},
5246 {"System.Diagnostic.FileVersionInfo", fileversion_icalls, G_N_ELEMENTS (fileversion_icalls)},
5247 {"System.Diagnostic.Process", process_icalls, G_N_ELEMENTS (process_icalls)},
5248 {"System.Double", double_icalls, G_N_ELEMENTS (double_icalls)},
5249 {"System.Enum", enum_icalls, G_N_ELEMENTS (enum_icalls)},
5250 {"System.Environment", environment_icalls, G_N_ELEMENTS (environment_icalls)},
5251 {"System.GC", gc_icalls, G_N_ELEMENTS (gc_icalls)},
5252 {"System.Globalization.CompareInfo", compareinfo_icalls, G_N_ELEMENTS (compareinfo_icalls)},
5253 {"System.Globalization.CultureInfo", cultureinfo_icalls, G_N_ELEMENTS (cultureinfo_icalls)},
5254 {"System.IO.FAMWatcher", famwatcher_icalls, G_N_ELEMENTS (famwatcher_icalls)},
5255 {"System.IO.FileSystemWatcher", filewatcher_icalls, G_N_ELEMENTS (filewatcher_icalls)},
5256 {"System.IO.MonoIO", monoio_icalls, G_N_ELEMENTS (monoio_icalls)},
5257 {"System.IO.Path", path_icalls, G_N_ELEMENTS (path_icalls)},
5258 {"System.Math", math_icalls, G_N_ELEMENTS (math_icalls)},
5259 {"System.MonoCustomAttrs", customattrs_icalls, G_N_ELEMENTS (customattrs_icalls)},
5260 {"System.MonoEnumInfo", enuminfo_icalls, G_N_ELEMENTS (enuminfo_icalls)},
5261 {"System.MonoType", monotype_icalls, G_N_ELEMENTS (monotype_icalls)},
5262 {"System.Net.Dns", dns_icalls, G_N_ELEMENTS (dns_icalls)},
5263 {"System.Net.Sockets.Socket", socket_icalls, G_N_ELEMENTS (socket_icalls)},
5264 {"System.Net.Sockets.SocketException", socketex_icalls, G_N_ELEMENTS (socketex_icalls)},
5265 {"System.Object", object_icalls, G_N_ELEMENTS (object_icalls)},
5266 {"System.Reflection.Assembly", assembly_icalls, G_N_ELEMENTS (assembly_icalls)},
5267 {"System.Reflection.Emit.AssemblyBuilder", assemblybuilder_icalls, G_N_ELEMENTS (assemblybuilder_icalls)},
5268 {"System.Reflection.Emit.CustomAttributeBuilder", customattrbuilder_icalls, G_N_ELEMENTS (customattrbuilder_icalls)},
5269 {"System.Reflection.Emit.DynamicMethod", dynamicmethod_icalls, G_N_ELEMENTS (dynamicmethod_icalls)},
5270 {"System.Reflection.Emit.MethodBuilder", methodbuilder_icalls, G_N_ELEMENTS (methodbuilder_icalls)},
5271 {"System.Reflection.Emit.ModuleBuilder", modulebuilder_icalls, G_N_ELEMENTS (modulebuilder_icalls)},
5272 {"System.Reflection.Emit.SignatureHelper", signaturehelper_icalls, G_N_ELEMENTS (signaturehelper_icalls)},
5273 {"System.Reflection.Emit.TypeBuilder", typebuilder_icalls, G_N_ELEMENTS (typebuilder_icalls)},
5274 {"System.Reflection.FieldInfo", fieldinfo_icalls, G_N_ELEMENTS (fieldinfo_icalls)},
5275 {"System.Reflection.MethodBase", methodbase_icalls, G_N_ELEMENTS (methodbase_icalls)},
5276 {"System.Reflection.MethodInfo", methodinfo_icalls, G_N_ELEMENTS (methodinfo_icalls)},
5277 {"System.Reflection.Module", module_icalls, G_N_ELEMENTS (module_icalls)},
5278 {"System.Reflection.MonoCMethod", monocmethod_icalls, G_N_ELEMENTS (monocmethod_icalls)},
5279 {"System.Reflection.MonoEventInfo", monoeventinfo_icalls, G_N_ELEMENTS (monoeventinfo_icalls)},
5280 {"System.Reflection.MonoField", monofield_icalls, G_N_ELEMENTS (monofield_icalls)},
5281 {"System.Reflection.MonoGenericInst", monogenericinst_icalls, G_N_ELEMENTS (monogenericinst_icalls)},
5282 {"System.Reflection.MonoGenericParam", monogenericparam_icalls, G_N_ELEMENTS (monogenericparam_icalls)},
5283 {"System.Reflection.MonoMethod", monomethod_icalls, G_N_ELEMENTS (monomethod_icalls)},
5284 {"System.Reflection.MonoMethodInfo", monomethodinfo_icalls, G_N_ELEMENTS (monomethodinfo_icalls)},
5285 {"System.Reflection.MonoPropertyInfo", monopropertyinfo_icalls, G_N_ELEMENTS (monopropertyinfo_icalls)},
5286 {"System.Runtime.CompilerServices.RuntimeHelpers", runtimehelpers_icalls, G_N_ELEMENTS (runtimehelpers_icalls)},
5287 {"System.Runtime.InteropServices.GCHandle", gchandle_icalls, G_N_ELEMENTS (gchandle_icalls)},
5288 {"System.Runtime.InteropServices.Marshal", marshal_icalls, G_N_ELEMENTS (marshal_icalls)},
5289 {"System.Runtime.Remoting.Activation.ActivationServices", activationservices_icalls, G_N_ELEMENTS (activationservices_icalls)},
5290 {"System.Runtime.Remoting.Messaging.MonoMethodMessage", monomethodmessage_icalls, G_N_ELEMENTS (monomethodmessage_icalls)},
5291 {"System.Runtime.Remoting.Proxies.RealProxy", realproxy_icalls, G_N_ELEMENTS (realproxy_icalls)},
5292 {"System.Runtime.Remoting.RemotingServices", remotingservices_icalls, G_N_ELEMENTS (remotingservices_icalls)},
5293 {"System.RuntimeMethodHandle", methodhandle_icalls, G_N_ELEMENTS (methodhandle_icalls)},
5294 {"System.Security.Cryptography.RNGCryptoServiceProvider", rng_icalls, G_N_ELEMENTS (rng_icalls)},
5295 {"System.String", string_icalls, G_N_ELEMENTS (string_icalls)},
5296 {"System.Text.Encoding", encoding_icalls, G_N_ELEMENTS (encoding_icalls)},
5297 {"System.Threading.Interlocked", interlocked_icalls, G_N_ELEMENTS (interlocked_icalls)},
5298 {"System.Threading.Monitor", monitor_icalls, G_N_ELEMENTS (monitor_icalls)},
5299 {"System.Threading.Mutex", mutex_icalls, G_N_ELEMENTS (mutex_icalls)},
5300 {"System.Threading.NativeEventCalls", nativeevents_icalls, G_N_ELEMENTS (nativeevents_icalls)},
5301 {"System.Threading.Thread", thread_icalls, G_N_ELEMENTS (thread_icalls)},
5302 {"System.Threading.ThreadPool", threadpool_icalls, G_N_ELEMENTS (threadpool_icalls)},
5303 {"System.Threading.WaitHandle", waithandle_icalls, G_N_ELEMENTS (waithandle_icalls)},
5304 {"System.Type", type_icalls, G_N_ELEMENTS (type_icalls)},
5305 {"System.TypedReference", typedref_icalls, G_N_ELEMENTS (typedref_icalls)},
5306 {"System.ValueType", valuetype_icalls, G_N_ELEMENTS (valuetype_icalls)},
5307 {"System.Web.Util.ICalls", web_icalls, G_N_ELEMENTS (web_icalls)}
5310 static GHashTable *icall_hash = NULL;
5313 mono_init_icall (void)
5317 /* check that tables are sorted: disable in release */
5320 const IcallMap *imap;
5321 const IcallEntry *ientry;
5322 const char *prev_class = NULL;
5323 const char *prev_method;
5325 for (i = 0; i < G_N_ELEMENTS (icall_entries); ++i) {
5326 imap = &icall_entries [i];
5328 if (prev_class && strcmp (prev_class, imap->klass) >= 0)
5329 g_print ("class %s should come before class %s\n", imap->klass, prev_class);
5330 prev_class = imap->klass;
5331 for (j = 0; j < imap->size; ++j) {
5332 ientry = &imap->icalls [j];
5333 if (prev_method && strcmp (prev_method, ientry->method) >= 0)
5334 g_print ("method %s should come before method %s\n", ientry->method, prev_method);
5335 prev_method = ientry->method;
5340 icall_hash = g_hash_table_new (g_str_hash , g_str_equal);
5344 mono_add_internal_call (const char *name, gconstpointer method)
5346 mono_loader_lock ();
5348 g_hash_table_insert (icall_hash, g_strdup (name), (gpointer) method);
5350 mono_loader_unlock ();
5354 compare_class_imap (const void *key, const void *elem)
5356 const IcallMap* imap = (const IcallMap*)elem;
5357 return strcmp (key, imap->klass);
5360 static const IcallMap*
5361 find_class_icalls (const char *name)
5363 return (const IcallMap*) bsearch (name, icall_entries, G_N_ELEMENTS (icall_entries), sizeof (IcallMap), compare_class_imap);
5367 compare_method_imap (const void *key, const void *elem)
5369 const IcallEntry* ientry = (const IcallEntry*)elem;
5370 return strcmp (key, ientry->method);
5374 find_method_icall (const IcallMap *imap, const char *name)
5376 const IcallEntry *ientry = (const IcallEntry*) bsearch (name, imap->icalls, imap->size, sizeof (IcallEntry), compare_method_imap);
5378 return (void*)ientry->func;
5383 * we should probably export this as an helper (handle nested types).
5384 * Returns the number of chars written in buf.
5387 concat_class_name (char *buf, int bufsize, MonoClass *klass)
5389 int nspacelen, cnamelen;
5390 nspacelen = strlen (klass->name_space);
5391 cnamelen = strlen (klass->name);
5392 if (nspacelen + cnamelen + 2 > bufsize)
5395 memcpy (buf, klass->name_space, nspacelen);
5396 buf [nspacelen ++] = '.';
5398 memcpy (buf + nspacelen, klass->name, cnamelen);
5399 buf [nspacelen + cnamelen] = 0;
5400 return nspacelen + cnamelen;
5404 mono_lookup_internal_call (MonoMethod *method)
5409 int typelen = 0, mlen, siglen;
5411 const IcallMap *imap;
5413 g_assert (method != NULL);
5415 typelen = concat_class_name (mname, sizeof (mname), method->klass);
5419 imap = find_class_icalls (mname);
5421 mname [typelen] = ':';
5422 mname [typelen + 1] = ':';
5424 mlen = strlen (method->name);
5425 memcpy (mname + typelen + 2, method->name, mlen);
5426 sigstart = mname + typelen + 2 + mlen;
5429 tmpsig = mono_signature_get_desc (method->signature, TRUE);
5430 siglen = strlen (tmpsig);
5431 if (typelen + mlen + siglen + 6 > sizeof (mname))
5434 memcpy (sigstart + 1, tmpsig, siglen);
5435 sigstart [siglen + 1] = ')';
5436 sigstart [siglen + 2] = 0;
5439 mono_loader_lock ();
5441 res = g_hash_table_lookup (icall_hash, mname);
5443 mono_loader_unlock ();
5446 /* try without signature */
5448 res = g_hash_table_lookup (icall_hash, mname);
5450 mono_loader_unlock ();
5454 /* it wasn't found in the static call tables */
5456 mono_loader_unlock ();
5459 res = find_method_icall (imap, sigstart - mlen);
5461 mono_loader_unlock ();
5464 /* try _with_ signature */
5466 res = find_method_icall (imap, sigstart - mlen);
5468 mono_loader_unlock ();
5472 g_warning ("cant resolve internal call to \"%s\" (tested without signature also)", mname);
5473 g_print ("\nYour mono runtime and corlib are out of sync.\n");
5474 g_print ("Corlib is: %s\n", method->klass->image->name);
5475 g_print ("\nWhen you update one from cvs you need to update, compile and install\nthe other too.\n");
5476 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");
5477 g_print ("If you see other errors or faults after this message they are probably related\n");
5478 g_print ("and you need to fix your mono install first.\n");
5480 mono_loader_unlock ();