5 * Dietmar Maurer (dietmar@ximian.com)
6 * Paolo Molaro (lupus@ximian.com)
7 * Patrik Torstensson (patrik.torstensson@labs2.com)
9 * (C) 2001 Ximian, Inc.
19 #if defined (PLATFORM_WIN32)
23 #include <mono/metadata/object.h>
24 #include <mono/metadata/threads.h>
25 #include <mono/metadata/threads-types.h>
26 #include <mono/metadata/threadpool.h>
27 #include <mono/metadata/monitor.h>
28 #include <mono/metadata/reflection.h>
29 #include <mono/metadata/assembly.h>
30 #include <mono/metadata/tabledefs.h>
31 #include <mono/metadata/exception.h>
32 #include <mono/metadata/file-io.h>
33 #include <mono/metadata/socket-io.h>
34 #include <mono/metadata/mono-endian.h>
35 #include <mono/metadata/tokentype.h>
36 #include <mono/metadata/unicode.h>
37 #include <mono/metadata/domain-internals.h>
38 #include <mono/metadata/metadata-internals.h>
39 #include <mono/metadata/marshal.h>
40 #include <mono/metadata/gc-internal.h>
41 #include <mono/metadata/rand.h>
42 #include <mono/metadata/sysmath.h>
43 #include <mono/metadata/string-icalls.h>
44 #include <mono/metadata/mono-debug-debugger.h>
45 #include <mono/metadata/process.h>
46 #include <mono/metadata/environment.h>
47 #include <mono/metadata/profiler-private.h>
48 #include <mono/metadata/locales.h>
49 #include <mono/metadata/filewatcher.h>
50 #include <mono/metadata/char-conversions.h>
51 #include <mono/metadata/security.h>
52 #include <mono/metadata/mono-config.h>
53 #include <mono/io-layer/io-layer.h>
54 #include <mono/utils/strtod.h>
55 #include <mono/utils/monobitset.h>
57 #if defined (PLATFORM_WIN32)
63 static MonoReflectionAssembly* ves_icall_System_Reflection_Assembly_GetCallingAssembly (void);
67 * We expect a pointer to a char, not a string
70 mono_double_ParseImpl (char *ptr)
78 result = bsd_strtod (ptr, &endptr);
80 if (!*ptr || (endptr && *endptr))
81 mono_raise_exception (mono_exception_from_name (mono_defaults.corlib,
89 ves_icall_System_Double_AssertEndianity (double *value)
93 MONO_DOUBLE_ASSERT_ENDIANITY (value);
97 ves_icall_System_Array_GetValueImpl (MonoObject *this, guint32 pos)
106 ao = (MonoArray *)this;
107 ac = (MonoClass *)ao->obj.vtable->klass;
109 esize = mono_array_element_size (ac);
110 ea = (gpointer*)((char*)ao->vector + (pos * esize));
112 if (ac->element_class->valuetype)
113 return mono_value_box (this->vtable->domain, ac->element_class, ea);
119 ves_icall_System_Array_GetValue (MonoObject *this, MonoObject *idxs)
127 MONO_CHECK_ARG_NULL (idxs);
129 io = (MonoArray *)idxs;
130 ic = (MonoClass *)io->obj.vtable->klass;
132 ao = (MonoArray *)this;
133 ac = (MonoClass *)ao->obj.vtable->klass;
135 g_assert (ic->rank == 1);
136 if (io->bounds != NULL || io->max_length != ac->rank)
137 mono_raise_exception (mono_get_exception_argument (NULL, NULL));
139 ind = (guint32 *)io->vector;
141 if (ao->bounds == NULL) {
142 if (*ind < 0 || *ind >= ao->max_length)
143 mono_raise_exception (mono_get_exception_index_out_of_range ());
145 return ves_icall_System_Array_GetValueImpl (this, *ind);
148 for (i = 0; i < ac->rank; i++)
149 if ((ind [i] < ao->bounds [i].lower_bound) ||
150 (ind [i] >= ao->bounds [i].length + ao->bounds [i].lower_bound))
151 mono_raise_exception (mono_get_exception_index_out_of_range ());
153 pos = ind [0] - ao->bounds [0].lower_bound;
154 for (i = 1; i < ac->rank; i++)
155 pos = pos*ao->bounds [i].length + ind [i] -
156 ao->bounds [i].lower_bound;
158 return ves_icall_System_Array_GetValueImpl (this, pos);
162 ves_icall_System_Array_SetValueImpl (MonoArray *this, MonoObject *value, guint32 pos)
164 MonoClass *ac, *vc, *ec;
175 vc = value->vtable->klass;
179 ac = this->obj.vtable->klass;
180 ec = ac->element_class;
182 esize = mono_array_element_size (ac);
183 ea = (gpointer*)((char*)this->vector + (pos * esize));
184 va = (gpointer*)((char*)value + sizeof (MonoObject));
187 memset (ea, 0, esize);
191 #define NO_WIDENING_CONVERSION G_STMT_START{\
192 mono_raise_exception (mono_get_exception_argument ( \
193 "value", "not a widening conversion")); \
196 #define CHECK_WIDENING_CONVERSION(extra) G_STMT_START{\
197 if (esize < vsize + (extra)) \
198 mono_raise_exception (mono_get_exception_argument ( \
199 "value", "not a widening conversion")); \
202 #define INVALID_CAST G_STMT_START{\
203 mono_raise_exception (mono_get_exception_invalid_cast ()); \
206 /* Check element (destination) type. */
207 switch (ec->byval_arg.type) {
208 case MONO_TYPE_STRING:
209 switch (vc->byval_arg.type) {
210 case MONO_TYPE_STRING:
216 case MONO_TYPE_BOOLEAN:
217 switch (vc->byval_arg.type) {
218 case MONO_TYPE_BOOLEAN:
231 NO_WIDENING_CONVERSION;
238 if (!ec->valuetype) {
239 if (!mono_object_isinst (value, ec))
241 *ea = (gpointer)value;
245 if (mono_object_isinst (value, ec)) {
246 memcpy (ea, (char *)value + sizeof (MonoObject), esize);
253 vsize = mono_class_instance_size (vc) - sizeof (MonoObject);
256 g_message (G_STRLOC ": %d (%d) <= %d (%d)",
257 ec->byval_arg.type, esize,
258 vc->byval_arg.type, vsize);
261 #define ASSIGN_UNSIGNED(etype) G_STMT_START{\
262 switch (vc->byval_arg.type) { \
267 case MONO_TYPE_CHAR: \
268 CHECK_WIDENING_CONVERSION(0); \
269 *(etype *) ea = (etype) u64; \
271 /* You can't assign a signed value to an unsigned array. */ \
276 /* You can't assign a floating point number to an integer array. */ \
279 NO_WIDENING_CONVERSION; \
283 #define ASSIGN_SIGNED(etype) G_STMT_START{\
284 switch (vc->byval_arg.type) { \
289 CHECK_WIDENING_CONVERSION(0); \
290 *(etype *) ea = (etype) i64; \
292 /* You can assign an unsigned value to a signed array if the array's */ \
293 /* element size is larger than the value size. */ \
298 case MONO_TYPE_CHAR: \
299 CHECK_WIDENING_CONVERSION(1); \
300 *(etype *) ea = (etype) u64; \
302 /* You can't assign a floating point number to an integer array. */ \
305 NO_WIDENING_CONVERSION; \
309 #define ASSIGN_REAL(etype) G_STMT_START{\
310 switch (vc->byval_arg.type) { \
313 CHECK_WIDENING_CONVERSION(0); \
314 *(etype *) ea = (etype) r64; \
316 /* All integer values fit into a floating point array, so we don't */ \
317 /* need to CHECK_WIDENING_CONVERSION here. */ \
322 *(etype *) ea = (etype) i64; \
328 case MONO_TYPE_CHAR: \
329 *(etype *) ea = (etype) u64; \
334 switch (vc->byval_arg.type) {
336 u64 = *(guint8 *) va;
339 u64 = *(guint16 *) va;
342 u64 = *(guint32 *) va;
345 u64 = *(guint64 *) va;
351 i64 = *(gint16 *) va;
354 i64 = *(gint32 *) va;
357 i64 = *(gint64 *) va;
360 r64 = *(gfloat *) va;
363 r64 = *(gdouble *) va;
366 u64 = *(guint16 *) va;
368 case MONO_TYPE_BOOLEAN:
369 /* Boolean is only compatible with itself. */
370 switch (ec->byval_arg.type) {
382 NO_WIDENING_CONVERSION;
389 /* If we can't do a direct copy, let's try a widening conversion. */
390 switch (ec->byval_arg.type) {
392 ASSIGN_UNSIGNED (guint16);
394 ASSIGN_UNSIGNED (guint8);
396 ASSIGN_UNSIGNED (guint16);
398 ASSIGN_UNSIGNED (guint32);
400 ASSIGN_UNSIGNED (guint64);
402 ASSIGN_SIGNED (gint8);
404 ASSIGN_SIGNED (gint16);
406 ASSIGN_SIGNED (gint32);
408 ASSIGN_SIGNED (gint64);
410 ASSIGN_REAL (gfloat);
412 ASSIGN_REAL (gdouble);
416 /* Not reached, INVALID_CAST does not return. Just to avoid a compiler warning ... */
420 #undef NO_WIDENING_CONVERSION
421 #undef CHECK_WIDENING_CONVERSION
422 #undef ASSIGN_UNSIGNED
428 ves_icall_System_Array_SetValue (MonoArray *this, MonoObject *value,
436 MONO_CHECK_ARG_NULL (idxs);
438 ic = idxs->obj.vtable->klass;
439 ac = this->obj.vtable->klass;
441 g_assert (ic->rank == 1);
442 if (idxs->bounds != NULL || idxs->max_length != ac->rank)
443 mono_raise_exception (mono_get_exception_argument (NULL, NULL));
445 ind = (guint32 *)idxs->vector;
447 if (this->bounds == NULL) {
448 if (*ind < 0 || *ind >= this->max_length)
449 mono_raise_exception (mono_get_exception_index_out_of_range ());
451 ves_icall_System_Array_SetValueImpl (this, value, *ind);
455 for (i = 0; i < ac->rank; i++)
456 if ((ind [i] < this->bounds [i].lower_bound) ||
457 (ind [i] >= this->bounds [i].length + this->bounds [i].lower_bound))
458 mono_raise_exception (mono_get_exception_index_out_of_range ());
460 pos = ind [0] - this->bounds [0].lower_bound;
461 for (i = 1; i < ac->rank; i++)
462 pos = pos * this->bounds [i].length + ind [i] -
463 this->bounds [i].lower_bound;
465 ves_icall_System_Array_SetValueImpl (this, value, pos);
469 ves_icall_System_Array_CreateInstanceImpl (MonoReflectionType *type, MonoArray *lengths, MonoArray *bounds)
474 gboolean bounded = FALSE;
478 MONO_CHECK_ARG_NULL (type);
479 MONO_CHECK_ARG_NULL (lengths);
481 MONO_CHECK_ARG (lengths, mono_array_length (lengths) > 0);
483 MONO_CHECK_ARG (bounds, mono_array_length (lengths) == mono_array_length (bounds));
485 for (i = 0; i < mono_array_length (lengths); i++)
486 if (mono_array_get (lengths, gint32, i) < 0)
487 mono_raise_exception (mono_get_exception_argument_out_of_range (NULL));
489 if (bounds && (mono_array_length (bounds) == 1) && (mono_array_get (bounds, gint32, 0) != 0))
490 /* vectors are not the same as one dimensional arrays with no-zero bounds */
495 aklass = mono_bounded_array_class_get (mono_class_from_mono_type (type->type), mono_array_length (lengths), bounded);
497 sizes = alloca (aklass->rank * sizeof(guint32) * 2);
498 for (i = 0; i < aklass->rank; ++i) {
499 sizes [i] = mono_array_get (lengths, gint32, i);
501 sizes [i + aklass->rank] = mono_array_get (bounds, gint32, i);
503 sizes [i + aklass->rank] = 0;
506 array = mono_array_new_full (mono_object_domain (type), aklass, sizes, sizes + aklass->rank);
512 ves_icall_System_Array_GetRank (MonoObject *this)
516 return this->vtable->klass->rank;
520 ves_icall_System_Array_GetLength (MonoArray *this, gint32 dimension)
522 gint32 rank = ((MonoObject *)this)->vtable->klass->rank;
526 if ((dimension < 0) || (dimension >= rank))
527 mono_raise_exception (mono_get_exception_index_out_of_range ());
529 if (this->bounds == NULL)
530 return this->max_length;
532 return this->bounds [dimension].length;
536 ves_icall_System_Array_GetLowerBound (MonoArray *this, gint32 dimension)
538 gint32 rank = ((MonoObject *)this)->vtable->klass->rank;
542 if ((dimension < 0) || (dimension >= rank))
543 mono_raise_exception (mono_get_exception_index_out_of_range ());
545 if (this->bounds == NULL)
548 return this->bounds [dimension].lower_bound;
552 ves_icall_System_Array_FastCopy (MonoArray *source, int source_idx, MonoArray* dest, int dest_idx, int length)
557 MonoClass *src_class;
558 MonoClass *dest_class;
563 if (source->obj.vtable->klass->rank != dest->obj.vtable->klass->rank)
566 if (source->bounds || dest->bounds)
569 if ((dest_idx + length > mono_array_length (dest)) ||
570 (source_idx + length > mono_array_length (source)))
573 element_size = mono_array_element_size (source->obj.vtable->klass);
574 dest_addr = mono_array_addr_with_size (dest, element_size, dest_idx);
575 source_addr = mono_array_addr_with_size (source, element_size, source_idx);
577 src_class = source->obj.vtable->klass->element_class;
578 dest_class = dest->obj.vtable->klass->element_class;
581 * Handle common cases.
584 /* Case1: object[] -> valuetype[] (ArrayList::ToArray) */
585 if (src_class == mono_defaults.object_class && dest_class->valuetype) {
586 for (i = source_idx; i < source_idx + length; ++i) {
587 MonoObject *elem = mono_array_get (source, MonoObject*, i);
588 if (elem && !mono_object_isinst (elem, dest_class))
592 element_size = mono_array_element_size (dest->obj.vtable->klass);
593 for (i = 0; i < length; ++i) {
594 MonoObject *elem = mono_array_get (source, MonoObject*, source_idx + i);
595 void *addr = mono_array_addr_with_size (dest, element_size, dest_idx + i);
597 memset (addr, 0, element_size);
599 memcpy (addr, (char *)elem + sizeof (MonoObject), element_size);
604 if (src_class != dest_class) {
605 if (dest_class->valuetype || dest_class->enumtype || src_class->valuetype || src_class->enumtype)
608 if (mono_class_is_subclass_of (src_class, dest_class, FALSE))
610 /* Case2: object[] -> reftype[] (ArrayList::ToArray) */
611 else if (mono_class_is_subclass_of (dest_class, src_class, FALSE))
612 for (i = source_idx; i < source_idx + length; ++i) {
613 MonoObject *elem = mono_array_get (source, MonoObject*, i);
614 if (elem && !mono_object_isinst (elem, dest_class))
621 memmove (dest_addr, source_addr, element_size * length);
627 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_InitializeArray (MonoArray *array, MonoClassField *field_handle)
629 MonoClass *klass = array->obj.vtable->klass;
630 guint32 size = mono_array_element_size (klass);
635 if (array->bounds == NULL)
636 size *= array->max_length;
638 for (i = 0; i < klass->rank; ++i)
639 size *= array->bounds [i].length;
641 memcpy (mono_array_addr (array, char, 0), field_handle->data, size);
643 #if G_BYTE_ORDER != G_LITTLE_ENDIAN
647 guint ## n *data = (guint ## n *) mono_array_addr (array, char, 0); \
649 for (i = 0; i < size; i += n/8, data++) { \
650 tmp = read ## n (data); \
655 /* printf ("Initialize array with elements of %s type\n", klass->element_class->name); */
657 switch (klass->element_class->byval_arg.type) {
677 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetOffsetToStringData (void)
681 return offsetof (MonoString, chars);
685 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetObjectValue (MonoObject *obj)
689 if ((obj == NULL) || (! (obj->vtable->klass->valuetype)))
692 return mono_object_clone (obj);
696 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_RunClassConstructor (MonoType *handle)
702 MONO_CHECK_ARG_NULL (handle);
704 klass = mono_class_from_mono_type (handle);
705 MONO_CHECK_ARG (handle, klass);
707 /* This will call the type constructor */
708 if (! (klass->flags & TYPE_ATTRIBUTE_INTERFACE))
709 mono_runtime_class_init (mono_class_vtable (mono_domain_get (), klass));
713 ves_icall_System_Object_MemberwiseClone (MonoObject *this)
717 return mono_object_clone (this);
721 #define MONO_OBJECT_ALIGNMENT_SHIFT 3
723 #define MONO_OBJECT_ALIGNMENT_SHIFT 2
727 * Return hashcode based on object address. This function will need to be
728 * smarter in the presence of a moving garbage collector, which will cache
729 * the address hash before relocating the object.
731 * Wang's address-based hash function:
732 * http://www.concentric.net/~Ttwang/tech/addrhash.htm
735 ves_icall_System_Object_GetHashCode (MonoObject *this)
737 register guint32 key;
741 key = (GPOINTER_TO_UINT (this) >> MONO_OBJECT_ALIGNMENT_SHIFT) * 2654435761u;
743 return key & 0x7fffffff;
747 ves_icall_System_ValueType_InternalGetHashCode (MonoObject *this, MonoArray **fields)
751 MonoObject **values = NULL;
758 klass = this->vtable->klass;
760 if (klass->field.count == 0)
761 return ves_icall_System_Object_GetHashCode (this);
764 * Compute the starting value of the hashcode for fields of primitive
765 * types, and return the remaining fields in an array to the managed side.
766 * This way, we can avoid costly reflection operations in managed code.
768 for (i = 0; i < klass->field.count; ++i) {
769 MonoClassField *field = &klass->fields [i];
770 if (field->type->attrs & FIELD_ATTRIBUTE_STATIC)
772 if (mono_field_is_deleted (field))
774 /* FIXME: Add more types */
775 switch (field->type->type) {
777 result ^= *(gint32*)((guint8*)this + field->offset);
779 case MONO_TYPE_STRING: {
781 s = *(MonoString**)((guint8*)this + field->offset);
783 result ^= ves_icall_System_String_GetHashCode (s);
788 values = alloca (klass->field.count * sizeof (MonoObject*));
789 o = mono_field_get_value_object (mono_object_domain (this), field, this);
790 values [count++] = o;
795 *fields = mono_array_new (mono_domain_get (), mono_defaults.object_class, count);
796 memcpy (mono_array_addr (*fields, MonoObject*, 0), values, count * sizeof (MonoObject*));
804 ves_icall_System_ValueType_Equals (MonoObject *this, MonoObject *that, MonoArray **fields)
808 MonoObject **values = NULL;
814 MONO_CHECK_ARG_NULL (that);
816 if (this->vtable != that->vtable)
819 klass = this->vtable->klass;
822 * Do the comparison for fields of primitive type and return a result if
823 * possible. Otherwise, return the remaining fields in an array to the
824 * managed side. This way, we can avoid costly reflection operations in
828 for (i = 0; i < klass->field.count; ++i) {
829 MonoClassField *field = &klass->fields [i];
830 if (field->type->attrs & FIELD_ATTRIBUTE_STATIC)
832 if (mono_field_is_deleted (field))
834 /* FIXME: Add more types */
835 switch (field->type->type) {
837 if (*(gint32*)((guint8*)this + field->offset) != *(gint32*)((guint8*)that + field->offset))
840 case MONO_TYPE_STRING: {
842 guint32 s1len, s2len;
843 s1 = *(MonoString**)((guint8*)this + field->offset);
844 s2 = *(MonoString**)((guint8*)that + field->offset);
847 if ((s1 == NULL) || (s2 == NULL))
849 s1len = mono_string_length (s1);
850 s2len = mono_string_length (s2);
854 if (memcmp (mono_string_chars (s1), mono_string_chars (s2), s1len * sizeof (gunichar2)) != 0)
860 values = alloca (klass->field.count * 2 * sizeof (MonoObject*));
861 o = mono_field_get_value_object (mono_object_domain (this), field, this);
862 values [count++] = o;
863 o = mono_field_get_value_object (mono_object_domain (this), field, that);
864 values [count++] = o;
869 *fields = mono_array_new (mono_domain_get (), mono_defaults.object_class, count);
870 memcpy (mono_array_addr (*fields, MonoObject*, 0), values, count * sizeof (MonoObject*));
878 static MonoReflectionType *
879 ves_icall_System_Object_GetType (MonoObject *obj)
883 if (obj->vtable->klass != mono_defaults.transparent_proxy_class)
884 return mono_type_get_object (mono_object_domain (obj), &obj->vtable->klass->byval_arg);
886 return mono_type_get_object (mono_object_domain (obj), &((MonoTransparentProxy*)obj)->remote_class->proxy_class->byval_arg);
890 mono_type_type_from_obj (MonoReflectionType *mtype, MonoObject *obj)
894 mtype->type = &obj->vtable->klass->byval_arg;
895 g_assert (mtype->type->type);
899 ves_icall_ModuleBuilder_getToken (MonoReflectionModuleBuilder *mb, MonoObject *obj)
903 return mono_image_create_token (mb->dynamic_image, obj);
907 ves_icall_ModuleBuilder_getMethodToken (MonoReflectionModuleBuilder *mb,
908 MonoReflectionMethod *method,
909 MonoArray *opt_param_types)
913 return mono_image_create_method_token (
914 mb->dynamic_image, (MonoObject *) method, opt_param_types);
918 ves_icall_ModuleBuilder_getDataChunk (MonoReflectionModuleBuilder *mb, MonoArray *buf, gint32 offset)
921 MonoDynamicImage *image = mb->dynamic_image;
922 char *p = mono_array_addr (buf, char, 0);
926 mono_image_create_pefile (mb);
928 if (offset >= image->pefile.index)
930 count = mono_array_length (buf);
931 count = MIN (count, image->pefile.index - offset);
933 memcpy (p, image->pefile.data + offset, count);
939 ves_icall_ModuleBuilder_build_metadata (MonoReflectionModuleBuilder *mb)
943 mono_image_build_metadata (mb);
946 static MonoReflectionType *
947 type_from_name (const char *str, MonoBoolean ignoreCase)
949 MonoType *type = NULL;
950 MonoAssembly *assembly;
951 MonoTypeNameParse info;
955 if (!mono_reflection_parse_type (str, &info)) {
956 g_list_free (info.modifiers);
957 g_list_free (info.nested);
961 if (info.assembly.name) {
962 assembly = mono_assembly_load (&info.assembly, NULL, NULL);
964 MonoReflectionAssembly *refass;
966 refass = ves_icall_System_Reflection_Assembly_GetCallingAssembly ();
967 assembly = refass->assembly;
971 type = mono_reflection_get_type (assembly->image, &info, ignoreCase);
973 if (!info.assembly.name && !type) /* try mscorlib */
974 type = mono_reflection_get_type (NULL, &info, ignoreCase);
976 g_list_free (info.modifiers);
977 g_list_free (info.nested);
981 return mono_type_get_object (mono_domain_get (), type);
985 mono_type_get (const char *str)
987 char *copy = g_strdup (str);
988 MonoReflectionType *type = type_from_name (copy, FALSE);
994 static MonoReflectionType*
995 ves_icall_type_from_name (MonoString *name,
996 MonoBoolean throwOnError,
997 MonoBoolean ignoreCase)
999 char *str = mono_string_to_utf8 (name);
1000 MonoReflectionType *type;
1002 type = type_from_name (str, ignoreCase);
1006 mono_raise_exception (mono_get_exception_type_load (name));
1013 static MonoReflectionType*
1014 ves_icall_type_from_handle (MonoType *handle)
1016 MonoDomain *domain = mono_domain_get ();
1017 MonoClass *klass = mono_class_from_mono_type (handle);
1019 MONO_ARCH_SAVE_REGS;
1021 mono_class_init (klass);
1022 return mono_type_get_object (domain, handle);
1026 ves_icall_type_Equals (MonoReflectionType *type, MonoReflectionType *c)
1028 MONO_ARCH_SAVE_REGS;
1030 if (type->type && c->type)
1031 return mono_metadata_type_equal (type->type, c->type);
1032 g_print ("type equals\n");
1036 /* System.TypeCode */
1055 TYPECODE_STRING = 18
1059 ves_icall_type_GetTypeCode (MonoReflectionType *type)
1061 int t = type->type->type;
1063 MONO_ARCH_SAVE_REGS;
1067 case MONO_TYPE_VOID:
1068 return TYPECODE_OBJECT;
1069 case MONO_TYPE_BOOLEAN:
1070 return TYPECODE_BOOLEAN;
1072 return TYPECODE_BYTE;
1074 return TYPECODE_SBYTE;
1076 return TYPECODE_UINT16;
1078 return TYPECODE_INT16;
1079 case MONO_TYPE_CHAR:
1080 return TYPECODE_CHAR;
1084 return TYPECODE_OBJECT;
1086 return TYPECODE_UINT32;
1088 return TYPECODE_INT32;
1090 return TYPECODE_UINT64;
1092 return TYPECODE_INT64;
1094 return TYPECODE_SINGLE;
1096 return TYPECODE_DOUBLE;
1097 case MONO_TYPE_VALUETYPE:
1098 if (type->type->data.klass->enumtype) {
1099 t = type->type->data.klass->enum_basetype->type;
1102 MonoClass *k = type->type->data.klass;
1103 if (strcmp (k->name_space, "System") == 0) {
1104 if (strcmp (k->name, "Decimal") == 0)
1105 return TYPECODE_DECIMAL;
1106 else if (strcmp (k->name, "DateTime") == 0)
1107 return TYPECODE_DATETIME;
1110 return TYPECODE_OBJECT;
1111 case MONO_TYPE_STRING:
1112 return TYPECODE_STRING;
1113 case MONO_TYPE_SZARRAY:
1114 case MONO_TYPE_ARRAY:
1115 case MONO_TYPE_OBJECT:
1117 case MONO_TYPE_MVAR:
1118 return TYPECODE_OBJECT;
1119 case MONO_TYPE_CLASS:
1121 MonoClass *k = type->type->data.klass;
1122 if (strcmp (k->name_space, "System") == 0) {
1123 if (strcmp (k->name, "DBNull") == 0)
1124 return TYPECODE_DBNULL;
1127 return TYPECODE_OBJECT;
1128 case MONO_TYPE_GENERICINST:
1129 return TYPECODE_OBJECT;
1131 g_error ("type 0x%02x not handled in GetTypeCode()", t);
1137 ves_icall_type_is_subtype_of (MonoReflectionType *type, MonoReflectionType *c, MonoBoolean check_interfaces)
1143 MONO_ARCH_SAVE_REGS;
1145 g_assert (type != NULL);
1147 domain = ((MonoObject *)type)->vtable->domain;
1149 if (!c) /* FIXME: dont know what do do here */
1152 klass = mono_class_from_mono_type (type->type);
1153 klassc = mono_class_from_mono_type (c->type);
1155 return mono_class_is_subclass_of (klass, klassc, check_interfaces);
1159 ves_icall_type_is_assignable_from (MonoReflectionType *type, MonoReflectionType *c)
1165 MONO_ARCH_SAVE_REGS;
1167 g_assert (type != NULL);
1169 domain = ((MonoObject *)type)->vtable->domain;
1171 klass = mono_class_from_mono_type (type->type);
1172 klassc = mono_class_from_mono_type (c->type);
1174 return mono_class_is_assignable_from (klass, klassc);
1178 ves_icall_type_IsInstanceOfType (MonoReflectionType *type, MonoObject *obj)
1180 MonoClass *klass = mono_class_from_mono_type (type->type);
1181 return mono_object_isinst (obj, klass) != NULL;
1185 ves_icall_get_attributes (MonoReflectionType *type)
1187 MonoClass *klass = mono_class_from_mono_type (type->type);
1189 MONO_ARCH_SAVE_REGS;
1191 return klass->flags;
1194 static MonoReflectionField*
1195 ves_icall_System_Reflection_FieldInfo_internal_from_handle (MonoClassField *handle)
1197 MONO_ARCH_SAVE_REGS;
1201 return mono_field_get_object (mono_domain_get (), handle->parent, handle);
1205 ves_icall_get_method_info (MonoMethod *method, MonoMethodInfo *info)
1207 MonoDomain *domain = mono_domain_get ();
1209 MONO_ARCH_SAVE_REGS;
1211 info->parent = mono_type_get_object (domain, &method->klass->byval_arg);
1212 info->ret = mono_type_get_object (domain, method->signature->ret);
1213 info->attrs = method->flags;
1214 info->implattrs = method->iflags;
1215 if (method->signature->call_convention == MONO_CALL_DEFAULT)
1218 if (method->signature->call_convention == MONO_CALL_VARARG)
1223 info->callconv |= (method->signature->hasthis << 5) | (method->signature->explicit_this << 6);
1227 ves_icall_get_parameter_info (MonoMethod *method)
1229 MonoDomain *domain = mono_domain_get ();
1231 MONO_ARCH_SAVE_REGS;
1233 return mono_param_get_objects (domain, method);
1236 static MonoReflectionType*
1237 ves_icall_MonoField_GetParentType (MonoReflectionField *field, MonoBoolean declaring)
1240 MONO_ARCH_SAVE_REGS;
1242 parent = declaring? field->field->parent: field->klass;
1244 return mono_type_get_object (mono_object_domain (field), &parent->byval_arg);
1248 ves_icall_MonoField_GetValueInternal (MonoReflectionField *field, MonoObject *obj)
1251 MonoClassField *cf = field->field;
1254 MonoDomain *domain = mono_object_domain (field);
1256 gboolean is_static = FALSE;
1257 gboolean is_ref = FALSE;
1259 MONO_ARCH_SAVE_REGS;
1261 mono_class_init (field->klass);
1263 switch (cf->type->type) {
1264 case MONO_TYPE_STRING:
1265 case MONO_TYPE_OBJECT:
1266 case MONO_TYPE_CLASS:
1267 case MONO_TYPE_ARRAY:
1268 case MONO_TYPE_SZARRAY:
1273 case MONO_TYPE_BOOLEAN:
1276 case MONO_TYPE_CHAR:
1285 case MONO_TYPE_VALUETYPE:
1286 is_ref = cf->type->byref;
1289 g_error ("type 0x%x not handled in "
1290 "ves_icall_Monofield_GetValue", cf->type->type);
1295 if (cf->type->attrs & FIELD_ATTRIBUTE_STATIC) {
1297 vtable = mono_class_vtable (domain, field->klass);
1298 if (!vtable->initialized && !(cf->type->attrs & FIELD_ATTRIBUTE_LITERAL))
1299 mono_runtime_class_init (vtable);
1304 mono_field_static_get_value (vtable, cf, &o);
1306 mono_field_get_value (obj, cf, &o);
1311 /* boxed value type */
1312 klass = mono_class_from_mono_type (cf->type);
1313 o = mono_object_new (domain, klass);
1314 v = ((gchar *) o) + sizeof (MonoObject);
1316 mono_field_static_get_value (vtable, cf, v);
1318 mono_field_get_value (obj, cf, v);
1325 ves_icall_FieldInfo_SetValueInternal (MonoReflectionField *field, MonoObject *obj, MonoObject *value)
1327 MonoClassField *cf = field->field;
1330 MONO_ARCH_SAVE_REGS;
1332 v = (gchar *) value;
1333 if (!cf->type->byref) {
1334 switch (cf->type->type) {
1337 case MONO_TYPE_BOOLEAN:
1340 case MONO_TYPE_CHAR:
1349 case MONO_TYPE_VALUETYPE:
1350 v += sizeof (MonoObject);
1352 case MONO_TYPE_STRING:
1353 case MONO_TYPE_OBJECT:
1354 case MONO_TYPE_CLASS:
1355 case MONO_TYPE_ARRAY:
1356 case MONO_TYPE_SZARRAY:
1360 g_error ("type 0x%x not handled in "
1361 "ves_icall_FieldInfo_SetValueInternal", cf->type->type);
1366 if (cf->type->attrs & FIELD_ATTRIBUTE_STATIC) {
1367 MonoVTable *vtable = mono_class_vtable (mono_object_domain (field), field->klass);
1368 if (!vtable->initialized)
1369 mono_runtime_class_init (vtable);
1370 mono_field_static_set_value (vtable, cf, v);
1372 mono_field_set_value (obj, cf, v);
1376 static MonoReflectionField*
1377 ves_icall_MonoField_Mono_GetGenericFieldDefinition (MonoReflectionField *field)
1379 MONO_ARCH_SAVE_REGS;
1381 if (field->field->generic_info && field->field->generic_info->reflection_info)
1382 return field->field->generic_info->reflection_info;
1387 /* From MonoProperty.cs */
1389 PInfo_Attributes = 1,
1390 PInfo_GetMethod = 1 << 1,
1391 PInfo_SetMethod = 1 << 2,
1392 PInfo_ReflectedType = 1 << 3,
1393 PInfo_DeclaringType = 1 << 4,
1398 ves_icall_get_property_info (MonoReflectionProperty *property, MonoPropertyInfo *info, PInfo req_info)
1400 MonoDomain *domain = mono_object_domain (property);
1402 MONO_ARCH_SAVE_REGS;
1404 if ((req_info & PInfo_ReflectedType) != 0)
1405 info->parent = mono_type_get_object (domain, &property->klass->byval_arg);
1406 else if ((req_info & PInfo_DeclaringType) != 0)
1407 info->parent = mono_type_get_object (domain, &property->property->parent->byval_arg);
1409 if ((req_info & PInfo_Name) != 0)
1410 info->name = mono_string_new (domain, property->property->name);
1412 if ((req_info & PInfo_Attributes) != 0)
1413 info->attrs = property->property->attrs;
1415 if ((req_info & PInfo_GetMethod) != 0)
1416 info->get = property->property->get ?
1417 mono_method_get_object (domain, property->property->get, NULL): NULL;
1419 if ((req_info & PInfo_SetMethod) != 0)
1420 info->set = property->property->set ?
1421 mono_method_get_object (domain, property->property->set, NULL): NULL;
1423 * There may be other methods defined for properties, though, it seems they are not exposed
1424 * in the reflection API
1429 ves_icall_get_event_info (MonoReflectionEvent *event, MonoEventInfo *info)
1431 MonoDomain *domain = mono_object_domain (event);
1433 MONO_ARCH_SAVE_REGS;
1435 info->declaring_type = mono_type_get_object (domain, &event->klass->byval_arg);
1436 info->reflected_type = mono_type_get_object (domain, &event->event->parent->byval_arg);
1438 info->name = mono_string_new (domain, event->event->name);
1439 info->attrs = event->event->attrs;
1440 info->add_method = event->event->add ? mono_method_get_object (domain, event->event->add, NULL): NULL;
1441 info->remove_method = event->event->remove ? mono_method_get_object (domain, event->event->remove, NULL): NULL;
1442 info->raise_method = event->event->raise ? mono_method_get_object (domain, event->event->raise, NULL): NULL;
1446 ves_icall_Type_GetInterfaces (MonoReflectionType* type)
1448 MonoDomain *domain = mono_object_domain (type);
1451 MonoClass *class = mono_class_from_mono_type (type->type);
1453 MonoBitSet *slots = mono_bitset_new (class->max_interface_id + 1, 0);
1455 MONO_ARCH_SAVE_REGS;
1458 /* GetInterfaces() returns an empty array in MS.NET (this may be a bug) */
1459 mono_bitset_free (slots);
1460 return mono_array_new (domain, mono_defaults.monotype_class, 0);
1464 for (parent = class; parent; parent = parent->parent) {
1465 for (i = 0; i < parent->interface_count; ++i) {
1466 if (mono_bitset_test (slots, parent->interfaces [i]->interface_id))
1469 mono_bitset_set (slots, parent->interfaces [i]->interface_id);
1474 intf = mono_array_new (domain, mono_defaults.monotype_class, ninterf);
1476 for (parent = class; parent; parent = parent->parent) {
1477 for (i = 0; i < parent->interface_count; ++i) {
1478 if (!mono_bitset_test (slots, parent->interfaces [i]->interface_id))
1481 mono_bitset_clear (slots, parent->interfaces [i]->interface_id);
1482 mono_array_set (intf, gpointer, ninterf,
1483 mono_type_get_object (domain, &parent->interfaces [i]->byval_arg));
1488 mono_bitset_free (slots);
1493 ves_icall_Type_GetInterfaceMapData (MonoReflectionType *type, MonoReflectionType *iface, MonoArray **targets, MonoArray **methods)
1495 MonoClass *class = mono_class_from_mono_type (type->type);
1496 MonoClass *iclass = mono_class_from_mono_type (iface->type);
1497 MonoReflectionMethod *member;
1498 int i, len, ioffset;
1501 MONO_ARCH_SAVE_REGS;
1503 /* type doesn't implement iface: the exception is thrown in managed code */
1504 if ((iclass->interface_id > class->max_interface_id) || !class->interface_offsets [iclass->interface_id])
1507 len = iclass->method.count;
1508 ioffset = class->interface_offsets [iclass->interface_id];
1509 domain = mono_object_domain (type);
1510 *targets = mono_array_new (domain, mono_defaults.method_info_class, len);
1511 *methods = mono_array_new (domain, mono_defaults.method_info_class, len);
1512 for (i = 0; i < len; ++i) {
1513 member = mono_method_get_object (domain, iclass->methods [i], iclass);
1514 mono_array_set (*methods, gpointer, i, member);
1515 member = mono_method_get_object (domain, class->vtable [i + ioffset], class);
1516 mono_array_set (*targets, gpointer, i, member);
1520 static MonoReflectionType*
1521 ves_icall_MonoType_GetElementType (MonoReflectionType *type)
1523 MonoClass *class = mono_class_from_mono_type (type->type);
1525 MONO_ARCH_SAVE_REGS;
1527 if (type->type->byref)
1528 return mono_type_get_object (mono_object_domain (type), &class->byval_arg);
1529 if (class->enumtype && class->enum_basetype) /* types that are modifierd typebuilkders may not have enum_basetype set */
1530 return mono_type_get_object (mono_object_domain (type), class->enum_basetype);
1531 else if (class->element_class)
1532 return mono_type_get_object (mono_object_domain (type), &class->element_class->byval_arg);
1537 static MonoReflectionType*
1538 ves_icall_get_type_parent (MonoReflectionType *type)
1540 MonoClass *class = mono_class_from_mono_type (type->type);
1542 MONO_ARCH_SAVE_REGS;
1544 return class->parent ? mono_type_get_object (mono_object_domain (type), &class->parent->byval_arg): NULL;
1548 ves_icall_type_ispointer (MonoReflectionType *type)
1550 MONO_ARCH_SAVE_REGS;
1552 return type->type->type == MONO_TYPE_PTR;
1556 ves_icall_type_isprimitive (MonoReflectionType *type)
1558 MONO_ARCH_SAVE_REGS;
1560 return (!type->type->byref && (type->type->type >= MONO_TYPE_BOOLEAN) && (type->type->type <= MONO_TYPE_R8));
1564 ves_icall_type_isbyref (MonoReflectionType *type)
1566 MONO_ARCH_SAVE_REGS;
1568 return type->type->byref;
1571 static MonoReflectionModule*
1572 ves_icall_MonoType_get_Module (MonoReflectionType *type)
1574 MonoClass *class = mono_class_from_mono_type (type->type);
1576 MONO_ARCH_SAVE_REGS;
1578 return mono_module_get_object (mono_object_domain (type), class->image);
1581 static MonoReflectionAssembly*
1582 ves_icall_MonoType_get_Assembly (MonoReflectionType *type)
1584 MonoDomain *domain = mono_domain_get ();
1585 MonoClass *class = mono_class_from_mono_type (type->type);
1587 MONO_ARCH_SAVE_REGS;
1589 return mono_assembly_get_object (domain, class->image->assembly);
1592 static MonoReflectionType*
1593 ves_icall_MonoType_get_DeclaringType (MonoReflectionType *type)
1595 MonoDomain *domain = mono_domain_get ();
1596 MonoClass *class = mono_class_from_mono_type (type->type);
1598 MONO_ARCH_SAVE_REGS;
1600 return class->nested_in ? mono_type_get_object (domain, &class->nested_in->byval_arg) : NULL;
1603 static MonoReflectionType*
1604 ves_icall_MonoType_get_UnderlyingSystemType (MonoReflectionType *type)
1606 MonoDomain *domain = mono_domain_get ();
1607 MonoClass *class = mono_class_from_mono_type (type->type);
1609 MONO_ARCH_SAVE_REGS;
1611 if (class->enumtype && class->enum_basetype) /* types that are modified typebuilders may not have enum_basetype set */
1612 return mono_type_get_object (domain, class->enum_basetype);
1613 else if (class->element_class)
1614 return mono_type_get_object (domain, &class->element_class->byval_arg);
1620 ves_icall_MonoType_get_Name (MonoReflectionType *type)
1622 MonoDomain *domain = mono_domain_get ();
1623 MonoClass *class = mono_class_from_mono_type (type->type);
1625 MONO_ARCH_SAVE_REGS;
1627 return mono_string_new (domain, class->name);
1631 ves_icall_MonoType_get_Namespace (MonoReflectionType *type)
1633 MonoDomain *domain = mono_domain_get ();
1634 MonoClass *class = mono_class_from_mono_type (type->type);
1636 MONO_ARCH_SAVE_REGS;
1638 while (class->nested_in)
1639 class = class->nested_in;
1641 return mono_string_new (domain, class->name_space);
1645 ves_icall_MonoType_GetArrayRank (MonoReflectionType *type)
1647 MonoClass *class = mono_class_from_mono_type (type->type);
1649 MONO_ARCH_SAVE_REGS;
1655 ves_icall_MonoType_GetGenericArguments (MonoReflectionType *type)
1658 MonoClass *klass, *pklass;
1660 MONO_ARCH_SAVE_REGS;
1662 klass = mono_class_from_mono_type (type->type);
1664 if (type->type->byref) {
1665 res = mono_array_new (mono_object_domain (type), mono_defaults.monotype_class, 0);
1666 } else if (klass->gen_params) {
1667 res = mono_array_new (mono_object_domain (type), mono_defaults.monotype_class, klass->num_gen_params);
1668 for (i = 0; i < klass->num_gen_params; ++i) {
1669 pklass = mono_class_from_generic_parameter (&klass->gen_params [i], klass->image, FALSE);
1670 mono_array_set (res, gpointer, i, mono_type_get_object (mono_object_domain (type), &pklass->byval_arg));
1672 } else if (klass->generic_inst) {
1673 MonoGenericInst *inst = klass->generic_inst;
1674 res = mono_array_new (mono_object_domain (type), mono_defaults.monotype_class, inst->type_argc);
1675 for (i = 0; i < inst->type_argc; ++i) {
1676 mono_array_set (res, gpointer, i, mono_type_get_object (mono_object_domain (type), inst->type_argv [i]));
1679 res = mono_array_new (mono_object_domain (type), mono_defaults.monotype_class, 0);
1685 ves_icall_Type_get_IsGenericTypeDefinition (MonoReflectionType *type)
1688 MONO_ARCH_SAVE_REGS;
1690 if (type->type->byref)
1692 klass = mono_class_from_mono_type (type->type);
1694 return klass->gen_params != NULL;
1697 static MonoReflectionType*
1698 ves_icall_Type_GetGenericTypeDefinition_impl (MonoReflectionType *type)
1701 MONO_ARCH_SAVE_REGS;
1703 if (type->type->byref)
1705 klass = mono_class_from_mono_type (type->type);
1706 if (klass->gen_params) {
1707 return type; /* check this one */
1709 if (klass->generic_inst) {
1710 MonoType *generic_type = klass->generic_inst->generic_type;
1711 MonoClass *generic_class = mono_class_from_mono_type (generic_type);
1713 if (generic_class->wastypebuilder && generic_class->reflection_info)
1714 return generic_class->reflection_info;
1716 return mono_type_get_object (mono_object_domain (type), generic_type);
1721 static MonoReflectionType*
1722 ves_icall_Type_BindGenericParameters (MonoReflectionType *type, MonoArray *type_array)
1724 MonoType *geninst, **types;
1727 MONO_ARCH_SAVE_REGS;
1729 if (type->type->byref)
1732 count = mono_array_length (type_array);
1733 types = g_new0 (MonoType *, count);
1735 for (i = 0; i < count; i++) {
1736 MonoReflectionType *t = mono_array_get (type_array, gpointer, i);
1737 types [i] = t->type;
1740 geninst = mono_reflection_bind_generic_parameters (type, count, types);
1742 return mono_type_get_object (mono_object_domain (type), geninst);
1746 ves_icall_Type_get_IsGenericInstance (MonoReflectionType *type)
1749 MONO_ARCH_SAVE_REGS;
1751 if (type->type->byref)
1753 klass = mono_class_from_mono_type (type->type);
1754 return klass->generic_inst != NULL;
1758 ves_icall_Type_GetGenericParameterPosition (MonoReflectionType *type)
1760 MONO_ARCH_SAVE_REGS;
1762 if (type->type->byref)
1764 if (type->type->type == MONO_TYPE_VAR || type->type->type == MONO_TYPE_MVAR)
1765 return type->type->data.generic_param->num;
1770 ves_icall_MonoType_get_HasGenericArguments (MonoReflectionType *type)
1773 MONO_ARCH_SAVE_REGS;
1775 if (type->type->byref)
1777 klass = mono_class_from_mono_type (type->type);
1778 if (klass->gen_params || klass->generic_inst)
1784 ves_icall_MonoType_get_IsGenericParameter (MonoReflectionType *type)
1786 MONO_ARCH_SAVE_REGS;
1788 if (type->type->byref)
1790 if (type->type->type == MONO_TYPE_VAR || type->type->type == MONO_TYPE_MVAR)
1796 ves_icall_TypeBuilder_get_IsGenericParameter (MonoReflectionTypeBuilder *tb)
1798 MONO_ARCH_SAVE_REGS;
1800 if (tb->type.type->byref)
1802 if (tb->type.type->type == MONO_TYPE_VAR || tb->type.type->type == MONO_TYPE_MVAR)
1807 static MonoReflectionType*
1808 ves_icall_MonoGenericInst_GetParentType (MonoReflectionGenericInst *type)
1810 MonoGenericInst *ginst;
1813 MONO_ARCH_SAVE_REGS;
1815 ginst = type->type.type->data.generic_inst;
1816 if (!ginst || !ginst->parent || (ginst->parent->type != MONO_TYPE_GENERICINST))
1819 klass = mono_class_from_mono_type (ginst->parent);
1820 if (!klass->generic_inst && !klass->gen_params)
1823 return mono_type_get_object (mono_object_domain (type), ginst->parent);
1827 ves_icall_MonoGenericInst_GetInterfaces (MonoReflectionGenericInst *type)
1829 static MonoClass *System_Reflection_MonoGenericInst;
1830 MonoGenericInst *ginst;
1836 MONO_ARCH_SAVE_REGS;
1838 if (!System_Reflection_MonoGenericInst) {
1839 System_Reflection_MonoGenericInst = mono_class_from_name (
1840 mono_defaults.corlib, "System.Reflection", "MonoGenericInst");
1841 g_assert (System_Reflection_MonoGenericInst);
1844 domain = mono_object_domain (type);
1846 ginst = type->type.type->data.generic_inst;
1847 if (!ginst || !ginst->ifaces)
1848 return mono_array_new (domain, System_Reflection_MonoGenericInst, 0);
1850 klass = mono_class_from_mono_type (ginst->generic_type);
1852 res = mono_array_new (domain, System_Reflection_MonoGenericInst, ginst->count_ifaces);
1854 for (i = 0; i < ginst->count_ifaces; i++) {
1855 MonoReflectionType *iface = mono_type_get_object (domain, ginst->ifaces [i]);
1857 mono_array_set (res, gpointer, i, iface);
1864 ves_icall_MonoGenericInst_GetMethods (MonoReflectionGenericInst *type,
1865 MonoReflectionType *reflected_type)
1867 MonoGenericInst *ginst;
1868 MonoDynamicGenericInst *dginst;
1870 MonoClass *refclass;
1874 MONO_ARCH_SAVE_REGS;
1876 ginst = type->type.type->data.generic_inst;
1877 g_assert ((dginst = ginst->dynamic_info) != NULL);
1879 refclass = mono_class_from_mono_type (reflected_type->type);
1881 domain = mono_object_domain (type);
1882 res = mono_array_new (domain, mono_defaults.method_info_class, dginst->count_methods);
1884 for (i = 0; i < dginst->count_methods; i++)
1885 mono_array_set (res, gpointer, i,
1886 mono_method_get_object (domain, dginst->methods [i], refclass));
1892 ves_icall_MonoGenericInst_GetConstructors (MonoReflectionGenericInst *type,
1893 MonoReflectionType *reflected_type)
1895 static MonoClass *System_Reflection_ConstructorInfo;
1896 MonoGenericInst *ginst;
1897 MonoDynamicGenericInst *dginst;
1899 MonoClass *refclass;
1903 MONO_ARCH_SAVE_REGS;
1905 if (!System_Reflection_ConstructorInfo)
1906 System_Reflection_ConstructorInfo = mono_class_from_name (
1907 mono_defaults.corlib, "System.Reflection", "ConstructorInfo");
1909 ginst = type->type.type->data.generic_inst;
1910 g_assert ((dginst = ginst->dynamic_info) != NULL);
1912 refclass = mono_class_from_mono_type (reflected_type->type);
1914 domain = mono_object_domain (type);
1915 res = mono_array_new (domain, System_Reflection_ConstructorInfo, dginst->count_ctors);
1917 for (i = 0; i < dginst->count_ctors; i++)
1918 mono_array_set (res, gpointer, i,
1919 mono_method_get_object (domain, dginst->ctors [i], refclass));
1925 ves_icall_MonoGenericInst_GetFields (MonoReflectionGenericInst *type,
1926 MonoReflectionType *reflected_type)
1928 MonoGenericInst *ginst;
1929 MonoDynamicGenericInst *dginst;
1931 MonoClass *refclass;
1935 MONO_ARCH_SAVE_REGS;
1937 ginst = type->type.type->data.generic_inst;
1938 g_assert ((dginst = ginst->dynamic_info) != NULL);
1940 refclass = mono_class_from_mono_type (reflected_type->type);
1942 domain = mono_object_domain (type);
1943 res = mono_array_new (domain, mono_defaults.field_info_class, dginst->count_fields);
1945 for (i = 0; i < dginst->count_fields; i++)
1946 mono_array_set (res, gpointer, i,
1947 mono_field_get_object (domain, refclass, &dginst->fields [i]));
1953 ves_icall_MonoGenericInst_GetProperties (MonoReflectionGenericInst *type,
1954 MonoReflectionType *reflected_type)
1956 static MonoClass *System_Reflection_PropertyInfo;
1957 MonoGenericInst *ginst;
1958 MonoDynamicGenericInst *dginst;
1960 MonoClass *refclass;
1964 MONO_ARCH_SAVE_REGS;
1966 if (!System_Reflection_PropertyInfo)
1967 System_Reflection_PropertyInfo = mono_class_from_name (
1968 mono_defaults.corlib, "System.Reflection", "PropertyInfo");
1970 ginst = type->type.type->data.generic_inst;
1971 g_assert ((dginst = ginst->dynamic_info) != NULL);
1973 refclass = mono_class_from_mono_type (reflected_type->type);
1975 domain = mono_object_domain (type);
1976 res = mono_array_new (domain, System_Reflection_PropertyInfo, dginst->count_properties);
1978 for (i = 0; i < dginst->count_properties; i++)
1979 mono_array_set (res, gpointer, i,
1980 mono_property_get_object (domain, refclass, &dginst->properties [i]));
1986 ves_icall_MonoGenericInst_GetEvents (MonoReflectionGenericInst *type,
1987 MonoReflectionType *reflected_type)
1989 static MonoClass *System_Reflection_EventInfo;
1990 MonoGenericInst *ginst;
1991 MonoDynamicGenericInst *dginst;
1993 MonoClass *refclass;
1997 MONO_ARCH_SAVE_REGS;
1999 if (!System_Reflection_EventInfo)
2000 System_Reflection_EventInfo = mono_class_from_name (
2001 mono_defaults.corlib, "System.Reflection", "EventInfo");
2003 ginst = type->type.type->data.generic_inst;
2004 g_assert ((dginst = ginst->dynamic_info) != NULL);
2006 refclass = mono_class_from_mono_type (reflected_type->type);
2008 domain = mono_object_domain (type);
2009 res = mono_array_new (domain, System_Reflection_EventInfo, dginst->count_events);
2011 for (i = 0; i < dginst->count_events; i++)
2012 mono_array_set (res, gpointer, i,
2013 mono_event_get_object (domain, refclass, &dginst->events [i]));
2018 static MonoReflectionMethod *
2019 ves_icall_MonoType_get_DeclaringMethod (MonoReflectionType *type)
2024 MONO_ARCH_SAVE_REGS;
2026 if (type->type->byref)
2029 method = type->type->data.generic_param->method;
2033 klass = mono_class_from_mono_type (type->type);
2034 return mono_method_get_object (mono_object_domain (type), method, klass);
2037 static MonoReflectionMethod *
2038 ves_icall_MonoMethod_GetGenericMethodDefinition (MonoReflectionMethod *method)
2040 MonoMethodInflated *imethod;
2042 MONO_ARCH_SAVE_REGS;
2044 if (!method->method->signature->is_inflated) {
2045 if (method->method->signature->generic_param_count)
2051 imethod = (MonoMethodInflated *) method->method;
2052 if (imethod->context->gmethod && imethod->context->gmethod->reflection_info)
2053 return imethod->context->gmethod->reflection_info;
2055 return mono_method_get_object (
2056 mono_object_domain (method), imethod->declaring, NULL);
2060 ves_icall_MonoMethod_get_HasGenericParameters (MonoReflectionMethod *method)
2062 MONO_ARCH_SAVE_REGS;
2064 if ((method->method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) ||
2065 (method->method->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL))
2068 return method->method->signature->generic_param_count != 0;
2072 ves_icall_MonoMethod_get_Mono_IsInflatedMethod (MonoReflectionMethod *method)
2074 MONO_ARCH_SAVE_REGS;
2076 if ((method->method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) ||
2077 (method->method->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL))
2080 return method->method->signature->is_inflated;
2084 ves_icall_MonoMethod_get_IsGenericMethodDefinition (MonoReflectionMethod *method)
2086 MONO_ARCH_SAVE_REGS;
2088 if ((method->method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) ||
2089 (method->method->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL))
2092 return method->method->signature->generic_param_count != 0;
2096 ves_icall_MonoMethod_GetGenericArguments (MonoReflectionMethod *method)
2100 MonoMethodNormal *mn;
2102 MONO_ARCH_SAVE_REGS;
2104 domain = mono_object_domain (method);
2106 if ((method->method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) ||
2107 (method->method->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL))
2108 return mono_array_new (domain, mono_defaults.monotype_class, 0);
2110 if (method->method->signature->is_inflated) {
2111 MonoMethodInflated *imethod = (MonoMethodInflated *) method->method;
2112 MonoGenericMethod *gmethod = imethod->context->gmethod;
2115 count = gmethod->mtype_argc;
2116 res = mono_array_new (domain, mono_defaults.monotype_class, count);
2118 for (i = 0; i < count; i++) {
2119 MonoType *t = gmethod->mtype_argv [i];
2121 res, gpointer, i, mono_type_get_object (domain, t));
2128 mn = (MonoMethodNormal *) method->method;
2129 count = method->method->signature->generic_param_count;
2130 res = mono_array_new (domain, mono_defaults.monotype_class, count);
2132 for (i = 0; i < count; i++) {
2133 MonoGenericParam *param = &mn->header->gen_params [i];
2134 MonoClass *pklass = mono_class_from_generic_parameter (
2135 param, method->method->klass->image, TRUE);
2136 mono_array_set (res, gpointer, i,
2137 mono_type_get_object (domain, &pklass->byval_arg));
2144 ves_icall_InternalInvoke (MonoReflectionMethod *method, MonoObject *this, MonoArray *params)
2147 * Invoke from reflection is supposed to always be a virtual call (the API
2148 * is stupid), mono_runtime_invoke_*() calls the provided method, allowing
2149 * greater flexibility.
2151 MonoMethod *m = method->method;
2154 MONO_ARCH_SAVE_REGS;
2157 if (!mono_object_isinst (this, m->klass))
2158 mono_raise_exception (mono_exception_from_name (mono_defaults.corlib, "System.Reflection", "TargetException"));
2159 m = mono_object_get_virtual_method (this, m);
2160 } else if (!(m->flags & METHOD_ATTRIBUTE_STATIC) && strcmp (m->name, ".ctor") && !m->wrapper_type)
2161 mono_raise_exception (mono_exception_from_name (mono_defaults.corlib, "System.Reflection", "TargetException"));
2163 pcount = params? mono_array_length (params): 0;
2164 if (pcount != m->signature->param_count)
2165 mono_raise_exception (mono_exception_from_name (mono_defaults.corlib, "System.Reflection", "TargetParameterCountException"));
2167 if (m->klass->rank && !strcmp (m->name, ".ctor")) {
2170 guint32 *lower_bounds;
2171 pcount = mono_array_length (params);
2172 lengths = alloca (sizeof (guint32) * pcount);
2173 for (i = 0; i < pcount; ++i)
2174 lengths [i] = *(gint32*) ((char*)mono_array_get (params, gpointer, i) + sizeof (MonoObject));
2176 if (m->klass->rank == pcount) {
2177 /* Only lengths provided. */
2178 lower_bounds = NULL;
2180 g_assert (pcount == (m->klass->rank * 2));
2181 /* lower bounds are first. */
2182 lower_bounds = lengths;
2183 lengths += m->klass->rank;
2186 return (MonoObject*)mono_array_new_full (mono_object_domain (params), m->klass, lengths, lower_bounds);
2188 return mono_runtime_invoke_array (m, this, params, NULL);
2192 ves_icall_InternalExecute (MonoReflectionMethod *method, MonoObject *this, MonoArray *params, MonoArray **outArgs)
2194 MonoDomain *domain = mono_object_domain (method);
2195 MonoMethod *m = method->method;
2196 MonoMethodSignature *sig = m->signature;
2197 MonoArray *out_args;
2199 int i, j, outarg_count = 0;
2201 MONO_ARCH_SAVE_REGS;
2203 if (m->klass == mono_defaults.object_class) {
2205 if (!strcmp (m->name, "FieldGetter")) {
2206 MonoClass *k = this->vtable->klass;
2207 MonoString *name = mono_array_get (params, MonoString *, 1);
2210 str = mono_string_to_utf8 (name);
2212 for (i = 0; i < k->field.count; i++) {
2213 if (!strcmp (k->fields [i].name, str)) {
2214 MonoClass *field_klass = mono_class_from_mono_type (k->fields [i].type);
2215 if (field_klass->valuetype)
2216 result = mono_value_box (domain, field_klass,
2217 (char *)this + k->fields [i].offset);
2219 result = *((gpointer *)((char *)this + k->fields [i].offset));
2222 out_args = mono_array_new (domain, mono_defaults.object_class, 1);
2223 *outArgs = out_args;
2224 mono_array_set (out_args, gpointer, 0, result);
2231 g_assert_not_reached ();
2233 } else if (!strcmp (m->name, "FieldSetter")) {
2234 MonoClass *k = this->vtable->klass;
2235 MonoString *name = mono_array_get (params, MonoString *, 1);
2239 str = mono_string_to_utf8 (name);
2241 for (i = 0; i < k->field.count; i++) {
2242 if (!strcmp (k->fields [i].name, str)) {
2243 MonoClass *field_klass = mono_class_from_mono_type (k->fields [i].type);
2244 MonoObject *val = mono_array_get (params, gpointer, 2);
2246 if (field_klass->valuetype) {
2247 size = mono_type_size (k->fields [i].type, &align);
2248 memcpy ((char *)this + k->fields [i].offset,
2249 ((char *)val) + sizeof (MonoObject), size);
2251 *(MonoObject**)((char *)this + k->fields [i].offset) = val;
2253 out_args = mono_array_new (domain, mono_defaults.object_class, 0);
2254 *outArgs = out_args;
2262 g_assert_not_reached ();
2267 for (i = 0; i < mono_array_length (params); i++) {
2268 if (sig->params [i]->byref)
2272 out_args = mono_array_new (domain, mono_defaults.object_class, outarg_count);
2274 /* fixme: handle constructors? */
2275 if (!strcmp (method->method->name, ".ctor"))
2276 g_assert_not_reached ();
2278 result = mono_runtime_invoke_array (method->method, this, params, NULL);
2280 for (i = 0, j = 0; i < mono_array_length (params); i++) {
2281 if (sig->params [i]->byref) {
2283 arg = mono_array_get (params, gpointer, i);
2284 mono_array_set (out_args, gpointer, j, arg);
2289 *outArgs = out_args;
2295 ves_icall_System_Enum_ToObject (MonoReflectionType *type, MonoObject *obj)
2298 MonoClass *enumc, *objc;
2302 MONO_ARCH_SAVE_REGS;
2304 MONO_CHECK_ARG_NULL (type);
2305 MONO_CHECK_ARG_NULL (obj);
2307 domain = mono_object_domain (type);
2308 enumc = mono_class_from_mono_type (type->type);
2309 objc = obj->vtable->klass;
2311 MONO_CHECK_ARG (obj, enumc->enumtype == TRUE);
2312 MONO_CHECK_ARG (obj, (objc->enumtype) || (objc->byval_arg.type >= MONO_TYPE_I1 &&
2313 objc->byval_arg.type <= MONO_TYPE_U8));
2315 s1 = mono_class_value_size (enumc, NULL);
2316 s2 = mono_class_value_size (objc, NULL);
2318 res = mono_object_new (domain, enumc);
2320 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
2321 memcpy ((char *)res + sizeof (MonoObject), (char *)obj + sizeof (MonoObject), MIN (s1, s2));
2323 memcpy ((char *)res + sizeof (MonoObject) + (s1 > s2 ? s1 - s2 : 0),
2324 (char *)obj + sizeof (MonoObject) + (s2 > s1 ? s2 - s1 : 0),
2331 ves_icall_System_Enum_get_value (MonoObject *this)
2339 MONO_ARCH_SAVE_REGS;
2344 g_assert (this->vtable->klass->enumtype);
2346 enumc = mono_class_from_mono_type (this->vtable->klass->enum_basetype);
2347 res = mono_object_new (mono_object_domain (this), enumc);
2348 dst = (char *)res + sizeof (MonoObject);
2349 src = (char *)this + sizeof (MonoObject);
2350 size = mono_class_value_size (enumc, NULL);
2352 memcpy (dst, src, size);
2358 ves_icall_get_enum_info (MonoReflectionType *type, MonoEnumInfo *info)
2360 MonoDomain *domain = mono_object_domain (type);
2361 MonoClass *enumc = mono_class_from_mono_type (type->type);
2362 guint i, j, nvalues, crow;
2363 MonoClassField *field;
2365 MONO_ARCH_SAVE_REGS;
2367 info->utype = mono_type_get_object (domain, enumc->enum_basetype);
2368 nvalues = enumc->field.count - 1;
2369 info->names = mono_array_new (domain, mono_defaults.string_class, nvalues);
2370 info->values = mono_array_new (domain, enumc, nvalues);
2373 for (i = 0, j = 0; i < enumc->field.count; ++i) {
2377 field = &enumc->fields [i];
2378 if (strcmp ("value__", field->name) == 0)
2380 if (mono_field_is_deleted (field))
2382 mono_array_set (info->names, gpointer, j, mono_string_new (domain, field->name));
2383 if (!field->def_value) {
2384 field->def_value = g_new0 (MonoConstant, 1);
2385 crow = mono_metadata_get_constant_index (enumc->image, MONO_TOKEN_FIELD_DEF | (i+enumc->field.first+1), crow + 1);
2386 field->def_value->type = mono_metadata_decode_row_col (&enumc->image->tables [MONO_TABLE_CONSTANT], crow-1, MONO_CONSTANT_TYPE);
2387 crow = mono_metadata_decode_row_col (&enumc->image->tables [MONO_TABLE_CONSTANT], crow-1, MONO_CONSTANT_VALUE);
2388 field->def_value->value = (gpointer)mono_metadata_blob_heap (enumc->image, crow);
2391 p = field->def_value->value;
2392 len = mono_metadata_decode_blob_size (p, &p);
2393 switch (enumc->enum_basetype->type) {
2396 mono_array_set (info->values, gchar, j, *p);
2398 case MONO_TYPE_CHAR:
2401 mono_array_set (info->values, gint16, j, read16 (p));
2405 mono_array_set (info->values, gint32, j, read32 (p));
2409 mono_array_set (info->values, gint64, j, read64 (p));
2412 g_error ("Implement type 0x%02x in get_enum_info", enumc->enum_basetype->type);
2419 BFLAGS_IgnoreCase = 1,
2420 BFLAGS_DeclaredOnly = 2,
2421 BFLAGS_Instance = 4,
2423 BFLAGS_Public = 0x10,
2424 BFLAGS_NonPublic = 0x20,
2425 BFLAGS_FlattenHierarchy = 0x40,
2426 BFLAGS_InvokeMethod = 0x100,
2427 BFLAGS_CreateInstance = 0x200,
2428 BFLAGS_GetField = 0x400,
2429 BFLAGS_SetField = 0x800,
2430 BFLAGS_GetProperty = 0x1000,
2431 BFLAGS_SetProperty = 0x2000,
2432 BFLAGS_ExactBinding = 0x10000,
2433 BFLAGS_SuppressChangeType = 0x20000,
2434 BFLAGS_OptionalParamBinding = 0x40000
2437 static MonoReflectionField *
2438 ves_icall_Type_GetField (MonoReflectionType *type, MonoString *name, guint32 bflags)
2441 MonoClass *startklass, *klass;
2443 MonoClassField *field;
2445 domain = ((MonoObject *)type)->vtable->domain;
2446 klass = startklass = mono_class_from_mono_type (type->type);
2448 MONO_ARCH_SAVE_REGS;
2451 mono_raise_exception (mono_get_exception_argument_null ("name"));
2454 for (i = 0; i < klass->field.count; ++i) {
2456 field = &klass->fields [i];
2457 if (mono_field_is_deleted (field))
2459 if ((field->type->attrs & FIELD_ATTRIBUTE_FIELD_ACCESS_MASK) == FIELD_ATTRIBUTE_PUBLIC) {
2460 if (bflags & BFLAGS_Public)
2463 if (bflags & BFLAGS_NonPublic)
2469 if (field->type->attrs & FIELD_ATTRIBUTE_STATIC) {
2470 if (bflags & BFLAGS_Static)
2471 if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
2474 if (bflags & BFLAGS_Instance)
2481 utf8_name = mono_string_to_utf8 (name);
2483 if (strcmp (field->name, utf8_name)) {
2489 return mono_field_get_object (domain, startklass, field);
2491 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
2498 ves_icall_Type_GetFields_internal (MonoReflectionType *type, guint32 bflags, MonoReflectionType *reftype)
2501 GSList *l = NULL, *tmp;
2502 MonoClass *startklass, *klass, *refklass;
2506 MonoClassField *field;
2508 MONO_ARCH_SAVE_REGS;
2510 domain = ((MonoObject *)type)->vtable->domain;
2511 klass = startklass = mono_class_from_mono_type (type->type);
2512 refklass = mono_class_from_mono_type (reftype->type);
2515 for (i = 0; i < klass->field.count; ++i) {
2517 field = &klass->fields [i];
2518 if (mono_field_is_deleted (field))
2520 if ((field->type->attrs & FIELD_ATTRIBUTE_FIELD_ACCESS_MASK) == FIELD_ATTRIBUTE_PUBLIC) {
2521 if (bflags & BFLAGS_Public)
2524 if (bflags & BFLAGS_NonPublic)
2530 if (field->type->attrs & FIELD_ATTRIBUTE_STATIC) {
2531 if (bflags & BFLAGS_Static)
2532 if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
2535 if (bflags & BFLAGS_Instance)
2541 member = (MonoObject*)mono_field_get_object (domain, refklass, field);
2542 l = g_slist_prepend (l, member);
2544 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
2546 len = g_slist_length (l);
2547 res = mono_array_new (domain, mono_defaults.field_info_class, len);
2549 tmp = l = g_slist_reverse (l);
2550 for (; tmp; tmp = tmp->next, ++i)
2551 mono_array_set (res, gpointer, i, tmp->data);
2557 ves_icall_Type_GetMethodsByName (MonoReflectionType *type, MonoString *name, guint32 bflags, MonoBoolean ignore_case, MonoReflectionType *reftype)
2560 GSList *l = NULL, *tmp;
2561 MonoClass *startklass, *klass, *refklass;
2566 GHashTable *method_slots = g_hash_table_new (NULL, NULL);
2567 gchar *mname = NULL;
2568 int (*compare_func) (const char *s1, const char *s2) = NULL;
2570 MONO_ARCH_SAVE_REGS;
2572 domain = ((MonoObject *)type)->vtable->domain;
2573 klass = startklass = mono_class_from_mono_type (type->type);
2574 refklass = mono_class_from_mono_type (reftype->type);
2577 mname = mono_string_to_utf8 (name);
2578 compare_func = (ignore_case) ? g_strcasecmp : strcmp;
2582 for (i = 0; i < klass->method.count; ++i) {
2584 method = klass->methods [i];
2585 if (strcmp (method->name, ".ctor") == 0 || strcmp (method->name, ".cctor") == 0)
2587 if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
2588 if (bflags & BFLAGS_Public)
2591 if (bflags & BFLAGS_NonPublic)
2597 if (method->flags & METHOD_ATTRIBUTE_STATIC) {
2598 if (bflags & BFLAGS_Static)
2599 if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
2602 if (bflags & BFLAGS_Instance)
2610 if (compare_func (mname, method->name))
2615 if (method->slot != -1) {
2616 if (g_hash_table_lookup (method_slots, GUINT_TO_POINTER (method->slot)))
2618 g_hash_table_insert (method_slots, GUINT_TO_POINTER (method->slot), method);
2621 member = (MonoObject*)mono_method_get_object (domain, method, refklass);
2623 l = g_slist_prepend (l, member);
2626 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
2630 res = mono_array_new (domain, mono_defaults.method_info_class, len);
2633 tmp = l = g_slist_reverse (l);
2635 for (; tmp; tmp = tmp->next, ++i)
2636 mono_array_set (res, gpointer, i, tmp->data);
2638 g_hash_table_destroy (method_slots);
2643 ves_icall_Type_GetConstructors_internal (MonoReflectionType *type, guint32 bflags, MonoReflectionType *reftype)
2646 GSList *l = NULL, *tmp;
2647 static MonoClass *System_Reflection_ConstructorInfo;
2648 MonoClass *startklass, *klass, *refklass;
2654 MONO_ARCH_SAVE_REGS;
2656 domain = ((MonoObject *)type)->vtable->domain;
2657 klass = startklass = mono_class_from_mono_type (type->type);
2658 refklass = mono_class_from_mono_type (reftype->type);
2660 for (i = 0; i < klass->method.count; ++i) {
2662 method = klass->methods [i];
2663 if (strcmp (method->name, ".ctor") && strcmp (method->name, ".cctor"))
2665 if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
2666 if (bflags & BFLAGS_Public)
2669 if (bflags & BFLAGS_NonPublic)
2675 if (method->flags & METHOD_ATTRIBUTE_STATIC) {
2676 if (bflags & BFLAGS_Static)
2677 if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
2680 if (bflags & BFLAGS_Instance)
2686 member = (MonoObject*)mono_method_get_object (domain, method, refklass);
2688 l = g_slist_prepend (l, member);
2690 len = g_slist_length (l);
2691 if (!System_Reflection_ConstructorInfo)
2692 System_Reflection_ConstructorInfo = mono_class_from_name (
2693 mono_defaults.corlib, "System.Reflection", "ConstructorInfo");
2694 res = mono_array_new (domain, System_Reflection_ConstructorInfo, len);
2696 tmp = l = g_slist_reverse (l);
2697 for (; tmp; tmp = tmp->next, ++i)
2698 mono_array_set (res, gpointer, i, tmp->data);
2704 ves_icall_Type_GetPropertiesByName (MonoReflectionType *type, MonoString *name, guint32 bflags, MonoBoolean ignore_case, MonoReflectionType *reftype)
2707 GSList *l = NULL, *tmp;
2708 static MonoClass *System_Reflection_PropertyInfo;
2709 MonoClass *startklass, *klass;
2715 GHashTable *method_slots = g_hash_table_new (NULL, NULL);
2716 gchar *propname = NULL;
2717 int (*compare_func) (const char *s1, const char *s2) = NULL;
2719 MONO_ARCH_SAVE_REGS;
2721 domain = ((MonoObject *)type)->vtable->domain;
2722 klass = startklass = mono_class_from_mono_type (type->type);
2724 propname = mono_string_to_utf8 (name);
2725 compare_func = (ignore_case) ? g_strcasecmp : strcmp;
2729 for (i = 0; i < klass->property.count; ++i) {
2730 prop = &klass->properties [i];
2735 if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
2736 if (bflags & BFLAGS_Public)
2739 if (bflags & BFLAGS_NonPublic)
2745 if (method->flags & METHOD_ATTRIBUTE_STATIC) {
2746 if (bflags & BFLAGS_Static)
2747 if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
2750 if (bflags & BFLAGS_Instance)
2759 if (compare_func (propname, prop->name))
2763 if (prop->get && prop->get->slot != -1) {
2764 if (g_hash_table_lookup (method_slots, GUINT_TO_POINTER (prop->get->slot)))
2766 g_hash_table_insert (method_slots, GUINT_TO_POINTER (prop->get->slot), prop);
2768 if (prop->set && prop->set->slot != -1) {
2769 if (g_hash_table_lookup (method_slots, GUINT_TO_POINTER (prop->set->slot)))
2771 g_hash_table_insert (method_slots, GUINT_TO_POINTER (prop->set->slot), prop);
2774 l = g_slist_prepend (l, mono_property_get_object (domain, startklass, prop));
2777 if ((!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent)))
2781 if (!System_Reflection_PropertyInfo)
2782 System_Reflection_PropertyInfo = mono_class_from_name (
2783 mono_defaults.corlib, "System.Reflection", "PropertyInfo");
2784 res = mono_array_new (domain, System_Reflection_PropertyInfo, len);
2787 tmp = l = g_slist_reverse (l);
2789 for (; tmp; tmp = tmp->next, ++i)
2790 mono_array_set (res, gpointer, i, tmp->data);
2792 g_hash_table_destroy (method_slots);
2796 static MonoReflectionEvent *
2797 ves_icall_MonoType_GetEvent (MonoReflectionType *type, MonoString *name, guint32 bflags)
2800 MonoClass *klass, *startklass;
2806 MONO_ARCH_SAVE_REGS;
2808 event_name = mono_string_to_utf8 (name);
2809 klass = startklass = mono_class_from_mono_type (type->type);
2810 domain = mono_object_domain (type);
2813 for (i = 0; i < klass->event.count; i++) {
2814 event = &klass->events [i];
2815 if (strcmp (event->name, event_name))
2818 method = event->add;
2820 method = event->remove;
2822 method = event->raise;
2824 if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
2825 if (!(bflags & BFLAGS_Public))
2828 if (!(bflags & BFLAGS_NonPublic))
2833 if (!(bflags & BFLAGS_NonPublic))
2836 g_free (event_name);
2837 return mono_event_get_object (domain, startklass, event);
2840 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
2843 g_free (event_name);
2848 ves_icall_Type_GetEvents_internal (MonoReflectionType *type, guint32 bflags, MonoReflectionType *reftype)
2851 GSList *l = NULL, *tmp;
2852 static MonoClass *System_Reflection_EventInfo;
2853 MonoClass *startklass, *klass;
2859 MONO_ARCH_SAVE_REGS;
2861 domain = ((MonoObject *)type)->vtable->domain;
2862 klass = startklass = mono_class_from_mono_type (type->type);
2865 for (i = 0; i < klass->event.count; ++i) {
2866 event = &klass->events [i];
2868 method = event->add;
2870 method = event->remove;
2872 method = event->raise;
2874 if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
2875 if (bflags & BFLAGS_Public)
2878 if (bflags & BFLAGS_NonPublic)
2883 if (bflags & BFLAGS_NonPublic)
2889 if (method->flags & METHOD_ATTRIBUTE_STATIC) {
2890 if (bflags & BFLAGS_Static)
2891 if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
2894 if (bflags & BFLAGS_Instance)
2899 if (bflags & BFLAGS_Instance)
2904 l = g_slist_prepend (l, mono_event_get_object (domain, klass, event));
2906 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
2908 len = g_slist_length (l);
2909 if (!System_Reflection_EventInfo)
2910 System_Reflection_EventInfo = mono_class_from_name (
2911 mono_defaults.corlib, "System.Reflection", "EventInfo");
2912 res = mono_array_new (domain, System_Reflection_EventInfo, len);
2915 tmp = l = g_slist_reverse (l);
2917 for (; tmp; tmp = tmp->next, ++i)
2918 mono_array_set (res, gpointer, i, tmp->data);
2923 static MonoReflectionType *
2924 ves_icall_Type_GetNestedType (MonoReflectionType *type, MonoString *name, guint32 bflags)
2927 MonoClass *startklass, *klass;
2932 MONO_ARCH_SAVE_REGS;
2934 domain = ((MonoObject *)type)->vtable->domain;
2935 klass = startklass = mono_class_from_mono_type (type->type);
2936 str = mono_string_to_utf8 (name);
2939 for (tmpn = klass->nested_classes; tmpn; tmpn = tmpn->next) {
2941 nested = tmpn->data;
2942 if ((nested->flags & TYPE_ATTRIBUTE_VISIBILITY_MASK) == TYPE_ATTRIBUTE_NESTED_PUBLIC) {
2943 if (bflags & BFLAGS_Public)
2946 if (bflags & BFLAGS_NonPublic)
2951 if (strcmp (nested->name, str) == 0){
2953 return mono_type_get_object (domain, &nested->byval_arg);
2956 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
2963 ves_icall_Type_GetNestedTypes (MonoReflectionType *type, guint32 bflags)
2966 GSList *l = NULL, *tmp;
2968 MonoClass *startklass, *klass;
2974 MONO_ARCH_SAVE_REGS;
2976 domain = ((MonoObject *)type)->vtable->domain;
2977 klass = startklass = mono_class_from_mono_type (type->type);
2979 for (tmpn = klass->nested_classes; tmpn; tmpn = tmpn->next) {
2981 nested = tmpn->data;
2982 if ((nested->flags & TYPE_ATTRIBUTE_VISIBILITY_MASK) == TYPE_ATTRIBUTE_NESTED_PUBLIC) {
2983 if (bflags & BFLAGS_Public)
2986 if (bflags & BFLAGS_NonPublic)
2991 member = (MonoObject*)mono_type_get_object (domain, &nested->byval_arg);
2992 l = g_slist_prepend (l, member);
2994 len = g_slist_length (l);
2995 res = mono_array_new (domain, mono_defaults.monotype_class, len);
2997 tmp = l = g_slist_reverse (l);
2998 for (; tmp; tmp = tmp->next, ++i)
2999 mono_array_set (res, gpointer, i, tmp->data);
3004 static MonoReflectionType*
3005 ves_icall_System_Reflection_Assembly_InternalGetType (MonoReflectionAssembly *assembly, MonoReflectionModule *module, MonoString *name, MonoBoolean throwOnError, MonoBoolean ignoreCase)
3008 MonoType *type = NULL;
3009 MonoTypeNameParse info;
3011 MONO_ARCH_SAVE_REGS;
3013 str = mono_string_to_utf8 (name);
3014 /*g_print ("requested type %s in %s\n", str, assembly->assembly->aname.name);*/
3015 if (!mono_reflection_parse_type (str, &info)) {
3017 g_list_free (info.modifiers);
3018 g_list_free (info.nested);
3019 if (throwOnError) /* uhm: this is a parse error, though... */
3020 mono_raise_exception (mono_get_exception_type_load (name));
3021 /*g_print ("failed parse\n");*/
3025 if (module != NULL) {
3027 type = mono_reflection_get_type (module->image, &info, ignoreCase);
3032 if (assembly->assembly->dynamic) {
3033 /* Enumerate all modules */
3034 MonoReflectionAssemblyBuilder *abuilder = (MonoReflectionAssemblyBuilder*)assembly;
3038 if (abuilder->modules) {
3039 for (i = 0; i < mono_array_length (abuilder->modules); ++i) {
3040 MonoReflectionModuleBuilder *mb = mono_array_get (abuilder->modules, MonoReflectionModuleBuilder*, i);
3041 type = mono_reflection_get_type (&mb->dynamic_image->image, &info, ignoreCase);
3047 if (!type && abuilder->loaded_modules) {
3048 for (i = 0; i < mono_array_length (abuilder->loaded_modules); ++i) {
3049 MonoReflectionModule *mod = mono_array_get (abuilder->loaded_modules, MonoReflectionModule*, i);
3050 type = mono_reflection_get_type (mod->image, &info, ignoreCase);
3057 type = mono_reflection_get_type (assembly->assembly->image, &info, ignoreCase);
3059 g_list_free (info.modifiers);
3060 g_list_free (info.nested);
3063 mono_raise_exception (mono_get_exception_type_load (name));
3064 /* g_print ("failed find\n"); */
3067 /* g_print ("got it\n"); */
3068 return mono_type_get_object (mono_object_domain (assembly), type);
3073 ves_icall_System_Reflection_Assembly_get_code_base (MonoReflectionAssembly *assembly)
3075 MonoDomain *domain = mono_object_domain (assembly);
3076 MonoAssembly *mass = assembly->assembly;
3081 MONO_ARCH_SAVE_REGS;
3083 absolute = g_build_filename (mass->basedir, mass->image->module_name, NULL);
3084 uri = g_filename_to_uri (absolute, NULL, NULL);
3085 res = mono_string_new (domain, uri);
3092 ves_icall_System_Reflection_Assembly_get_global_assembly_cache (MonoReflectionAssembly *assembly)
3094 MonoAssembly *mass = assembly->assembly;
3096 MONO_ARCH_SAVE_REGS;
3098 return mass->in_gac;
3101 static MonoReflectionAssembly*
3102 ves_icall_System_Reflection_Assembly_load_with_partial_name (MonoString *mname, MonoObject *evidence)
3106 MonoImageOpenStatus status;
3108 MONO_ARCH_SAVE_REGS;
3110 name = mono_string_to_utf8 (mname);
3111 res = mono_assembly_load_with_partial_name (name, &status);
3117 return mono_assembly_get_object (mono_domain_get (), res);
3121 ves_icall_System_Reflection_Assembly_get_location (MonoReflectionAssembly *assembly)
3123 MonoDomain *domain = mono_object_domain (assembly);
3125 char *name = g_build_filename (
3126 assembly->assembly->basedir,
3127 assembly->assembly->image->module_name, NULL);
3129 MONO_ARCH_SAVE_REGS;
3131 res = mono_string_new (domain, name);
3137 ves_icall_System_Reflection_Assembly_InternalImageRuntimeVersion (MonoReflectionAssembly *assembly)
3139 MonoDomain *domain = mono_object_domain (assembly);
3141 MONO_ARCH_SAVE_REGS;
3143 return mono_string_new (domain, assembly->assembly->image->version);
3146 static MonoReflectionMethod*
3147 ves_icall_System_Reflection_Assembly_get_EntryPoint (MonoReflectionAssembly *assembly)
3149 guint32 token = mono_image_get_entry_point (assembly->assembly->image);
3151 MONO_ARCH_SAVE_REGS;
3155 return mono_method_get_object (mono_object_domain (assembly), mono_get_method (assembly->assembly->image, token, NULL), NULL);
3159 ves_icall_System_Reflection_Assembly_GetManifestResourceNames (MonoReflectionAssembly *assembly)
3161 MonoTableInfo *table = &assembly->assembly->image->tables [MONO_TABLE_MANIFESTRESOURCE];
3162 MonoArray *result = mono_array_new (mono_object_domain (assembly), mono_defaults.string_class, table->rows);
3166 MONO_ARCH_SAVE_REGS;
3168 for (i = 0; i < table->rows; ++i) {
3169 val = mono_metadata_string_heap (assembly->assembly->image, mono_metadata_decode_row_col (table, i, MONO_MANIFEST_NAME));
3170 mono_array_set (result, gpointer, i, mono_string_new (mono_object_domain (assembly), val));
3176 ves_icall_System_Reflection_Assembly_GetReferencedAssemblies (MonoReflectionAssembly *assembly)
3178 static MonoClass *System_Reflection_AssemblyName;
3181 MonoDomain *domain = mono_object_domain (assembly);
3184 MONO_ARCH_SAVE_REGS;
3186 if (!System_Reflection_AssemblyName)
3187 System_Reflection_AssemblyName = mono_class_from_name (
3188 mono_defaults.corlib, "System.Reflection", "AssemblyName");
3190 for (ptr = assembly->assembly->image->references; ptr && *ptr; ptr++)
3193 result = mono_array_new (mono_object_domain (assembly), System_Reflection_AssemblyName, count);
3195 for (i = 0; i < count; i++) {
3196 MonoAssembly *assem = assembly->assembly->image->references [i];
3197 MonoReflectionAssemblyName *aname;
3198 char *codebase, *absolute;
3200 aname = (MonoReflectionAssemblyName *) mono_object_new (
3201 domain, System_Reflection_AssemblyName);
3203 aname->name = mono_string_new (domain, assem->aname.name);
3205 aname->major = assem->aname.major;
3206 aname->minor = assem->aname.minor;
3207 aname->build = assem->aname.build;
3208 aname->revision = assem->aname.revision;
3210 absolute = g_build_filename (assem->basedir, assem->image->module_name, NULL);
3211 codebase = g_filename_to_uri (absolute, NULL, NULL);
3212 aname->codebase = mono_string_new (domain, codebase);
3215 mono_array_set (result, gpointer, i, aname);
3226 foreach_namespace (const char* key, gconstpointer val, NameSpaceInfo *info)
3228 MonoString *name = mono_string_new (mono_object_domain (info->res), key);
3230 mono_array_set (info->res, gpointer, info->idx, name);
3235 ves_icall_System_Reflection_Assembly_GetNamespaces (MonoReflectionAssembly *assembly)
3237 MonoImage *img = assembly->assembly->image;
3241 MonoTableInfo *t = &img->tables [MONO_TABLE_EXPORTEDTYPE];
3244 MONO_ARCH_SAVE_REGS;
3246 n = g_hash_table_size (img->name_cache);
3247 res = mono_array_new (mono_object_domain (assembly), mono_defaults.string_class, n);
3250 g_hash_table_foreach (img->name_cache, (GHFunc)foreach_namespace, &info);
3252 /* Add namespaces from the EXPORTEDTYPES table as well */
3255 GPtrArray *nspaces = g_ptr_array_new ();
3256 for (i = 0; i < t->rows; ++i) {
3257 const char *nspace = mono_metadata_string_heap (img, mono_metadata_decode_row_col (t, i, MONO_EXP_TYPE_NAMESPACE));
3258 if (!g_hash_table_lookup (img->name_cache, nspace)) {
3259 g_ptr_array_add (nspaces, (char*)nspace);
3262 if (nspaces->len > 0) {
3263 res2 = mono_array_new (mono_object_domain (assembly), mono_defaults.string_class, n + nspaces->len);
3264 memcpy (mono_array_addr (res2, MonoString*, 0),
3265 mono_array_addr (res, MonoString*, 0),
3266 n * sizeof (MonoString*));
3267 for (i = 0; i < nspaces->len; ++i)
3268 mono_array_set (res2, MonoString*, n + i,
3269 mono_string_new (mono_object_domain (assembly),
3270 g_ptr_array_index (nspaces, i)));
3273 g_ptr_array_free (nspaces, TRUE);
3279 /* move this in some file in mono/util/ */
3281 g_concat_dir_and_file (const char *dir, const char *file)
3283 g_return_val_if_fail (dir != NULL, NULL);
3284 g_return_val_if_fail (file != NULL, NULL);
3287 * If the directory name doesn't have a / on the end, we need
3288 * to add one so we get a proper path to the file
3290 if (dir [strlen(dir) - 1] != G_DIR_SEPARATOR)
3291 return g_strconcat (dir, G_DIR_SEPARATOR_S, file, NULL);
3293 return g_strconcat (dir, file, NULL);
3297 ves_icall_System_Reflection_Assembly_GetManifestResourceInternal (MonoReflectionAssembly *assembly, MonoString *name, gint32 *size, MonoReflectionModule **ref_module)
3299 char *n = mono_string_to_utf8 (name);
3300 MonoTableInfo *table = &assembly->assembly->image->tables [MONO_TABLE_MANIFESTRESOURCE];
3302 guint32 cols [MONO_MANIFEST_SIZE];
3303 guint32 impl, file_idx;
3307 MONO_ARCH_SAVE_REGS;
3309 for (i = 0; i < table->rows; ++i) {
3310 mono_metadata_decode_row (table, i, cols, MONO_MANIFEST_SIZE);
3311 val = mono_metadata_string_heap (assembly->assembly->image, cols [MONO_MANIFEST_NAME]);
3312 if (strcmp (val, n) == 0)
3316 if (i == table->rows)
3319 impl = cols [MONO_MANIFEST_IMPLEMENTATION];
3322 * this code should only be called after obtaining the
3323 * ResourceInfo and handling the other cases.
3325 g_assert ((impl & IMPLEMENTATION_MASK) == IMPLEMENTATION_FILE);
3326 file_idx = impl >> IMPLEMENTATION_BITS;
3328 module = mono_image_load_file_for_image (assembly->assembly->image, file_idx);
3333 module = assembly->assembly->image;
3335 *ref_module = mono_module_get_object (mono_domain_get (), module);
3337 return (void*)mono_image_get_resource (module, cols [MONO_MANIFEST_OFFSET], size);
3341 ves_icall_System_Reflection_Assembly_GetManifestResourceInfoInternal (MonoReflectionAssembly *assembly, MonoString *name, MonoManifestResourceInfo *info)
3343 MonoTableInfo *table = &assembly->assembly->image->tables [MONO_TABLE_MANIFESTRESOURCE];
3345 guint32 cols [MONO_MANIFEST_SIZE];
3346 guint32 file_cols [MONO_FILE_SIZE];
3350 MONO_ARCH_SAVE_REGS;
3352 n = mono_string_to_utf8 (name);
3353 for (i = 0; i < table->rows; ++i) {
3354 mono_metadata_decode_row (table, i, cols, MONO_MANIFEST_SIZE);
3355 val = mono_metadata_string_heap (assembly->assembly->image, cols [MONO_MANIFEST_NAME]);
3356 if (strcmp (val, n) == 0)
3360 if (i == table->rows)
3363 if (!cols [MONO_MANIFEST_IMPLEMENTATION]) {
3364 info->location = RESOURCE_LOCATION_EMBEDDED | RESOURCE_LOCATION_IN_MANIFEST;
3367 switch (cols [MONO_MANIFEST_IMPLEMENTATION] & IMPLEMENTATION_MASK) {
3368 case IMPLEMENTATION_FILE:
3369 i = cols [MONO_MANIFEST_IMPLEMENTATION] >> IMPLEMENTATION_BITS;
3370 table = &assembly->assembly->image->tables [MONO_TABLE_FILE];
3371 mono_metadata_decode_row (table, i - 1, file_cols, MONO_FILE_SIZE);
3372 val = mono_metadata_string_heap (assembly->assembly->image, file_cols [MONO_FILE_NAME]);
3373 info->filename = mono_string_new (mono_object_domain (assembly), val);
3374 if (file_cols [MONO_FILE_FLAGS] && FILE_CONTAINS_NO_METADATA)
3377 info->location = RESOURCE_LOCATION_EMBEDDED;
3380 case IMPLEMENTATION_ASSEMBLYREF:
3381 i = cols [MONO_MANIFEST_IMPLEMENTATION] >> IMPLEMENTATION_BITS;
3382 info->assembly = mono_assembly_get_object (mono_domain_get (), assembly->assembly->image->references [i - 1]);
3384 /* Obtain info recursively */
3385 ves_icall_System_Reflection_Assembly_GetManifestResourceInfoInternal (info->assembly, name, info);
3386 info->location |= RESOURCE_LOCATION_ANOTHER_ASSEMBLY;
3389 case IMPLEMENTATION_EXP_TYPE:
3390 g_assert_not_reached ();
3399 ves_icall_System_Reflection_Assembly_GetFilesInternal (MonoReflectionAssembly *assembly, MonoString *name)
3401 MonoTableInfo *table = &assembly->assembly->image->tables [MONO_TABLE_FILE];
3402 MonoArray *result = NULL;
3407 MONO_ARCH_SAVE_REGS;
3409 /* check hash if needed */
3411 n = mono_string_to_utf8 (name);
3412 for (i = 0; i < table->rows; ++i) {
3413 val = mono_metadata_string_heap (assembly->assembly->image, mono_metadata_decode_row_col (table, i, MONO_FILE_NAME));
3414 if (strcmp (val, n) == 0) {
3417 n = g_concat_dir_and_file (assembly->assembly->basedir, val);
3418 fn = mono_string_new (mono_object_domain (assembly), n);
3420 return (MonoObject*)fn;
3427 for (i = 0; i < table->rows; ++i) {
3428 result = mono_array_new (mono_object_domain (assembly), mono_defaults.string_class, table->rows);
3429 val = mono_metadata_string_heap (assembly->assembly->image, mono_metadata_decode_row_col (table, i, MONO_FILE_NAME));
3430 n = g_concat_dir_and_file (assembly->assembly->basedir, val);
3431 mono_array_set (result, gpointer, i, mono_string_new (mono_object_domain (assembly), n));
3434 return (MonoObject*)result;
3438 ves_icall_System_Reflection_Assembly_GetModulesInternal (MonoReflectionAssembly *assembly)
3440 MonoDomain *domain = mono_domain_get();
3443 int i, module_count = 0, file_count = 0;
3444 MonoImage **modules = assembly->assembly->image->modules;
3445 MonoTableInfo *table;
3448 while (modules[module_count])
3452 table = &assembly->assembly->image->tables [MONO_TABLE_FILE];
3453 file_count = table->rows;
3455 g_assert( assembly->assembly->image != NULL);
3458 klass = mono_class_from_name ( mono_defaults.corlib, "System.Reflection", "Module");
3459 res = mono_array_new (domain, klass, module_count + file_count);
3461 mono_array_set (res, gpointer, 0, mono_module_get_object (domain, assembly->assembly->image));
3462 for ( i = 1; i < module_count; ++i )
3463 mono_array_set (res, gpointer, i, mono_module_get_object (domain, modules[i]));
3465 for (i = 0; i < table->rows; ++i)
3466 mono_array_set (res, gpointer, module_count + i, mono_module_file_get_object (domain, assembly->assembly->image, i));
3471 static MonoReflectionMethod*
3472 ves_icall_GetCurrentMethod (void)
3474 MonoMethod *m = mono_method_get_last_managed ();
3476 MONO_ARCH_SAVE_REGS;
3478 return mono_method_get_object (mono_domain_get (), m, NULL);
3481 static MonoReflectionAssembly*
3482 ves_icall_System_Reflection_Assembly_GetExecutingAssembly (void)
3484 MonoMethod *m = mono_method_get_last_managed ();
3486 MONO_ARCH_SAVE_REGS;
3488 return mono_assembly_get_object (mono_domain_get (), m->klass->image->assembly);
3493 get_caller (MonoMethod *m, gint32 no, gint32 ilo, gboolean managed, gpointer data)
3495 MonoMethod **dest = data;
3497 /* skip unmanaged frames */
3512 static MonoReflectionAssembly*
3513 ves_icall_System_Reflection_Assembly_GetEntryAssembly (void)
3515 MonoDomain* domain = mono_domain_get ();
3517 MONO_ARCH_SAVE_REGS;
3519 if (!domain->entry_assembly)
3520 domain = mono_get_root_domain ();
3522 return mono_assembly_get_object (domain, domain->entry_assembly);
3526 static MonoReflectionAssembly*
3527 ves_icall_System_Reflection_Assembly_GetCallingAssembly (void)
3529 MonoMethod *m = mono_method_get_last_managed ();
3530 MonoMethod *dest = m;
3532 MONO_ARCH_SAVE_REGS;
3534 mono_stack_walk (get_caller, &dest);
3537 return mono_assembly_get_object (mono_domain_get (), dest->klass->image->assembly);
3541 ves_icall_System_MonoType_getFullName (MonoReflectionType *object)
3543 MonoDomain *domain = mono_object_domain (object);
3547 MONO_ARCH_SAVE_REGS;
3549 name = mono_type_get_name (object->type);
3550 res = mono_string_new (domain, name);
3557 fill_reflection_assembly_name (MonoDomain *domain, MonoReflectionAssemblyName *aname, MonoAssemblyName *name, const char *absolute)
3559 static MonoMethod *create_culture = NULL;
3562 const char *pkey_ptr;
3565 MONO_ARCH_SAVE_REGS;
3567 aname->name = mono_string_new (domain, name->name);
3568 aname->major = name->major;
3569 aname->minor = name->minor;
3570 aname->build = name->build;
3571 aname->revision = name->revision;
3572 aname->hashalg = name->hash_alg;
3574 codebase = g_filename_to_uri (absolute, NULL, NULL);
3576 aname->codebase = mono_string_new (domain, codebase);
3580 if (!create_culture) {
3581 MonoMethodDesc *desc = mono_method_desc_new ("System.Globalization.CultureInfo:CreateSpecificCulture(string)", TRUE);
3582 create_culture = mono_method_desc_search_in_image (desc, mono_defaults.corlib);
3583 g_assert (create_culture);
3584 mono_method_desc_free (desc);
3587 args [0] = mono_string_new (domain, name->culture);
3588 aname->cultureInfo =
3589 mono_runtime_invoke (create_culture, NULL, args, NULL);
3591 if (name->public_key) {
3592 pkey_ptr = name->public_key;
3593 pkey_len = mono_metadata_decode_blob_size (pkey_ptr, &pkey_ptr);
3595 aname->publicKey = mono_array_new (domain, mono_defaults.byte_class, pkey_len);
3596 memcpy (mono_array_addr (aname->publicKey, guint8, 0), pkey_ptr, pkey_len);
3601 ves_icall_System_Reflection_Assembly_FillName (MonoReflectionAssembly *assembly, MonoReflectionAssemblyName *aname)
3605 MONO_ARCH_SAVE_REGS;
3607 absolute = g_build_filename (assembly->assembly->basedir, assembly->assembly->image->module_name, NULL);
3609 fill_reflection_assembly_name (mono_object_domain (assembly), aname,
3610 &assembly->assembly->aname, absolute);
3616 ves_icall_System_Reflection_Assembly_InternalGetAssemblyName (MonoString *fname, MonoReflectionAssemblyName *aname)
3619 MonoImageOpenStatus status = MONO_IMAGE_OK;
3622 MonoAssemblyName name;
3624 MONO_ARCH_SAVE_REGS;
3626 filename = mono_string_to_utf8 (fname);
3628 image = mono_image_open (filename, &status);
3634 exc = mono_get_exception_file_not_found (fname);
3635 mono_raise_exception (exc);
3638 res = mono_assembly_fill_assembly_name (image, &name);
3640 mono_image_close (image);
3642 mono_raise_exception (mono_get_exception_argument ("assemblyFile", "The file does not contain a manifest"));
3645 fill_reflection_assembly_name (mono_domain_get (), aname, &name, filename);
3648 mono_image_close (image);
3652 mono_module_get_types (MonoDomain *domain, MonoImage *image,
3653 MonoBoolean exportedOnly)
3657 MonoTableInfo *tdef = &image->tables [MONO_TABLE_TYPEDEF];
3659 guint32 attrs, visibility;
3661 /* we start the count from 1 because we skip the special type <Module> */
3664 for (i = 1; i < tdef->rows; ++i) {
3665 attrs = mono_metadata_decode_row_col (tdef, i, MONO_TYPEDEF_FLAGS);
3666 visibility = attrs & TYPE_ATTRIBUTE_VISIBILITY_MASK;
3667 if (visibility == TYPE_ATTRIBUTE_PUBLIC || visibility == TYPE_ATTRIBUTE_NESTED_PUBLIC)
3671 count = tdef->rows - 1;
3673 res = mono_array_new (domain, mono_defaults.monotype_class, count);
3675 for (i = 1; i < tdef->rows; ++i) {
3676 attrs = mono_metadata_decode_row_col (tdef, i, MONO_TYPEDEF_FLAGS);
3677 visibility = attrs & TYPE_ATTRIBUTE_VISIBILITY_MASK;
3678 if (!exportedOnly || (visibility == TYPE_ATTRIBUTE_PUBLIC || visibility == TYPE_ATTRIBUTE_NESTED_PUBLIC)) {
3679 klass = mono_class_get (image, (i + 1) | MONO_TOKEN_TYPE_DEF);
3680 mono_array_set (res, gpointer, count, mono_type_get_object (domain, &klass->byval_arg));
3689 ves_icall_System_Reflection_Assembly_GetTypes (MonoReflectionAssembly *assembly, MonoBoolean exportedOnly)
3692 MonoImage *image = assembly->assembly->image;
3693 MonoTableInfo *table = &image->tables [MONO_TABLE_FILE];
3697 MONO_ARCH_SAVE_REGS;
3699 domain = mono_object_domain (assembly);
3700 res = mono_module_get_types (domain, image, exportedOnly);
3702 /* Append data from all modules in the assembly */
3703 for (i = 0; i < table->rows; ++i) {
3704 if (!(mono_metadata_decode_row_col (table, i, MONO_FILE_FLAGS) & FILE_CONTAINS_NO_METADATA)) {
3705 MonoImage *loaded_image = mono_assembly_load_module (image->assembly, i + 1);
3707 MonoArray *res2 = mono_module_get_types (domain, loaded_image, exportedOnly);
3708 /* Append the new types to the end of the array */
3709 if (mono_array_length (res2) > 0) {
3713 len1 = mono_array_length (res);
3714 len2 = mono_array_length (res2);
3715 res3 = mono_array_new (domain, mono_defaults.monotype_class, len1 + len2);
3716 memcpy (mono_array_addr (res3, MonoReflectionType*, 0),
3717 mono_array_addr (res, MonoReflectionType*, 0),
3718 len1 * sizeof (MonoReflectionType*));
3719 memcpy (mono_array_addr (res3, MonoReflectionType*, len1),
3720 mono_array_addr (res2, MonoReflectionType*, 0),
3721 len2 * sizeof (MonoReflectionType*));
3731 static MonoReflectionType*
3732 ves_icall_System_Reflection_Module_GetGlobalType (MonoReflectionModule *module)
3734 MonoDomain *domain = mono_object_domain (module);
3737 MONO_ARCH_SAVE_REGS;
3739 g_assert (module->image);
3740 klass = mono_class_get (module->image, 1 | MONO_TOKEN_TYPE_DEF);
3741 return mono_type_get_object (domain, &klass->byval_arg);
3745 ves_icall_System_Reflection_Module_Close (MonoReflectionModule *module)
3748 mono_image_close (module->image);
3752 ves_icall_System_Reflection_Module_GetGuidInternal (MonoReflectionModule *module)
3754 MonoDomain *domain = mono_object_domain (module);
3756 MONO_ARCH_SAVE_REGS;
3758 g_assert (module->image);
3759 return mono_string_new (domain, module->image->guid);
3763 ves_icall_System_Reflection_Module_InternalGetTypes (MonoReflectionModule *module)
3765 MONO_ARCH_SAVE_REGS;
3768 return mono_array_new (mono_object_domain (module), mono_defaults.monotype_class, 0);
3770 return mono_module_get_types (mono_object_domain (module), module->image, FALSE);
3773 static MonoReflectionType*
3774 ves_icall_ModuleBuilder_create_modified_type (MonoReflectionTypeBuilder *tb, MonoString *smodifiers)
3777 int isbyref = 0, rank;
3778 char *str = mono_string_to_utf8 (smodifiers);
3781 MONO_ARCH_SAVE_REGS;
3783 klass = mono_class_from_mono_type (tb->type.type);
3785 /* logic taken from mono_reflection_parse_type(): keep in sync */
3789 if (isbyref) { /* only one level allowed by the spec */
3796 return mono_type_get_object (mono_object_domain (tb), &klass->this_arg);
3799 klass = mono_ptr_class_get (&klass->byval_arg);
3800 mono_class_init (klass);
3811 else if (*p != '*') { /* '*' means unknown lower bound */
3822 klass = mono_array_class_get (klass, rank);
3823 mono_class_init (klass);
3830 return mono_type_get_object (mono_object_domain (tb), &klass->byval_arg);
3834 ves_icall_Type_IsArrayImpl (MonoReflectionType *t)
3839 MONO_ARCH_SAVE_REGS;
3842 res = !type->byref && (type->type == MONO_TYPE_ARRAY || type->type == MONO_TYPE_SZARRAY);
3847 static MonoReflectionType *
3848 ves_icall_Type_make_array_type (MonoReflectionType *type, int rank)
3850 MonoClass *klass, *aklass;
3852 MONO_ARCH_SAVE_REGS;
3854 klass = mono_class_from_mono_type (type->type);
3855 aklass = mono_array_class_get (klass, rank);
3857 return mono_type_get_object (mono_object_domain (type), &aklass->byval_arg);
3860 static MonoReflectionType *
3861 ves_icall_Type_make_byref_type (MonoReflectionType *type)
3865 MONO_ARCH_SAVE_REGS;
3867 klass = mono_class_from_mono_type (type->type);
3869 return mono_type_get_object (mono_object_domain (type), &klass->this_arg);
3873 ves_icall_System_Delegate_CreateDelegate_internal (MonoReflectionType *type, MonoObject *target,
3874 MonoReflectionMethod *info)
3876 MonoClass *delegate_class = mono_class_from_mono_type (type->type);
3877 MonoObject *delegate;
3880 MONO_ARCH_SAVE_REGS;
3882 mono_assert (delegate_class->parent == mono_defaults.multicastdelegate_class);
3884 delegate = mono_object_new (mono_object_domain (type), delegate_class);
3886 func = mono_compile_method (info->method);
3888 mono_delegate_ctor (delegate, target, func);
3894 * Magic number to convert a time which is relative to
3895 * Jan 1, 1970 into a value which is relative to Jan 1, 0001.
3897 #define EPOCH_ADJUST ((guint64)62135596800LL)
3900 * Magic number to convert FILETIME base Jan 1, 1601 to DateTime - base Jan, 1, 0001
3902 #define FILETIME_ADJUST ((guint64)504911232000000000LL)
3905 * This returns Now in UTC
3908 ves_icall_System_DateTime_GetNow (void)
3910 #ifdef PLATFORM_WIN32
3914 GetSystemTime (&st);
3915 SystemTimeToFileTime (&st, &ft);
3916 return (gint64) FILETIME_ADJUST + ((((gint64)ft.dwHighDateTime)<<32) | ft.dwLowDateTime);
3918 /* FIXME: put this in io-layer and call it GetLocalTime */
3922 MONO_ARCH_SAVE_REGS;
3924 if (gettimeofday (&tv, NULL) == 0) {
3925 res = (((gint64)tv.tv_sec + EPOCH_ADJUST)* 1000000 + tv.tv_usec)*10;
3928 /* fixme: raise exception */
3933 #ifdef PLATFORM_WIN32
3934 /* convert a SYSTEMTIME which is of the form "last thursday in october" to a real date */
3936 convert_to_absolute_date(SYSTEMTIME *date)
3938 #define IS_LEAP(y) ((y % 4) == 0 && ((y % 100) != 0 || (y % 400) == 0))
3939 static int days_in_month[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
3940 static int leap_days_in_month[] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
3941 /* from the calendar FAQ */
3942 int a = (14 - date->wMonth) / 12;
3943 int y = date->wYear - a;
3944 int m = date->wMonth + 12 * a - 2;
3945 int d = (1 + y + y/4 - y/100 + y/400 + (31*m)/12) % 7;
3947 /* d is now the day of the week for the first of the month (0 == Sunday) */
3949 int day_of_week = date->wDayOfWeek;
3951 /* set day_in_month to the first day in the month which falls on day_of_week */
3952 int day_in_month = 1 + (day_of_week - d);
3953 if (day_in_month <= 0)
3956 /* wDay is 1 for first weekday in month, 2 for 2nd ... 5 means last - so work that out allowing for days in the month */
3957 date->wDay = day_in_month + (date->wDay - 1) * 7;
3958 if (date->wDay > (IS_LEAP(date->wYear) ? leap_days_in_month[date->wMonth - 1] : days_in_month[date->wMonth - 1]))
3963 #ifndef PLATFORM_WIN32
3965 * Return's the offset from GMT of a local time.
3967 * tm is a local time
3968 * t is the same local time as seconds.
3971 gmt_offset(struct tm *tm, time_t t)
3973 #if defined (HAVE_TM_GMTOFF)
3974 return tm->tm_gmtoff;
3979 g.tm_isdst = tm->tm_isdst;
3981 return (int)difftime(t, t2);
3986 * This is heavily based on zdump.c from glibc 2.2.
3988 * * data[0]: start of daylight saving time (in DateTime ticks).
3989 * * data[1]: end of daylight saving time (in DateTime ticks).
3990 * * data[2]: utcoffset (in TimeSpan ticks).
3991 * * data[3]: additional offset when daylight saving (in TimeSpan ticks).
3992 * * name[0]: name of this timezone when not daylight saving.
3993 * * name[1]: name of this timezone when daylight saving.
3995 * FIXME: This only works with "standard" Unix dates (years between 1900 and 2100) while
3996 * the class library allows years between 1 and 9999.
3998 * Returns true on success and zero on failure.
4001 ves_icall_System_CurrentTimeZone_GetTimeZoneData (guint32 year, MonoArray **data, MonoArray **names)
4003 #ifndef PLATFORM_WIN32
4004 MonoDomain *domain = mono_domain_get ();
4005 struct tm start, tt;
4009 int is_daylight = 0, day;
4012 MONO_ARCH_SAVE_REGS;
4014 MONO_CHECK_ARG_NULL (data);
4015 MONO_CHECK_ARG_NULL (names);
4017 (*data) = mono_array_new (domain, mono_defaults.int64_class, 4);
4018 (*names) = mono_array_new (domain, mono_defaults.string_class, 2);
4021 * no info is better than crashing: we'll need our own tz data to make
4022 * this work properly, anyway. The range is reduced to 1970 .. 2037 because
4023 * that is what mktime is guaranteed to support (we get into an infinite loop
4026 if ((year < 1970) || (year > 2037)) {
4028 tt = *localtime (&t);
4029 strftime (tzone, sizeof (tzone), "%Z", &tt);
4030 mono_array_set ((*names), gpointer, 0, mono_string_new (domain, tzone));
4031 mono_array_set ((*names), gpointer, 1, mono_string_new (domain, tzone));
4035 memset (&start, 0, sizeof (start));
4038 start.tm_year = year-1900;
4040 t = mktime (&start);
4041 gmtoff = gmt_offset (&start, t);
4043 /* For each day of the year, calculate the tm_gmtoff. */
4044 for (day = 0; day < 365; day++) {
4047 tt = *localtime (&t);
4049 /* Daylight saving starts or ends here. */
4050 if (gmt_offset (&tt, t) != gmtoff) {
4054 /* Try to find the exact hour when daylight saving starts/ends. */
4058 tt1 = *localtime (&t1);
4059 } while (gmt_offset (&tt1, t1) != gmtoff);
4061 /* Try to find the exact minute when daylight saving starts/ends. */
4064 tt1 = *localtime (&t1);
4065 } while (gmt_offset (&tt1, t1) == gmtoff);
4067 strftime (tzone, sizeof (tzone), "%Z", &tt);
4069 /* Write data, if we're already in daylight saving, we're done. */
4071 mono_array_set ((*names), gpointer, 0, mono_string_new (domain, tzone));
4072 mono_array_set ((*data), gint64, 1, ((gint64)t1 + EPOCH_ADJUST) * 10000000L);
4075 mono_array_set ((*names), gpointer, 1, mono_string_new (domain, tzone));
4076 mono_array_set ((*data), gint64, 0, ((gint64)t1 + EPOCH_ADJUST) * 10000000L);
4080 /* This is only set once when we enter daylight saving. */
4081 mono_array_set ((*data), gint64, 2, (gint64)gmtoff * 10000000L);
4082 mono_array_set ((*data), gint64, 3, (gint64)(gmt_offset (&tt, t) - gmtoff) * 10000000L);
4084 gmtoff = gmt_offset (&tt, t);
4089 strftime (tzone, sizeof (tzone), "%Z", &tt);
4090 mono_array_set ((*names), gpointer, 0, mono_string_new (domain, tzone));
4091 mono_array_set ((*names), gpointer, 1, mono_string_new (domain, tzone));
4092 mono_array_set ((*data), gint64, 0, 0);
4093 mono_array_set ((*data), gint64, 1, 0);
4094 mono_array_set ((*data), gint64, 2, (gint64) gmtoff * 10000000L);
4095 mono_array_set ((*data), gint64, 3, 0);
4100 MonoDomain *domain = mono_domain_get ();
4101 TIME_ZONE_INFORMATION tz_info;
4106 tz_id = GetTimeZoneInformation (&tz_info);
4107 if (tz_id == TIME_ZONE_ID_INVALID)
4110 MONO_CHECK_ARG_NULL (data);
4111 MONO_CHECK_ARG_NULL (names);
4113 (*data) = mono_array_new (domain, mono_defaults.int64_class, 4);
4114 (*names) = mono_array_new (domain, mono_defaults.string_class, 2);
4116 for (i = 0; i < 32; ++i)
4117 if (!tz_info.DaylightName [i])
4119 mono_array_set ((*names), gpointer, 1, mono_string_new_utf16 (domain, tz_info.DaylightName, i));
4120 for (i = 0; i < 32; ++i)
4121 if (!tz_info.StandardName [i])
4123 mono_array_set ((*names), gpointer, 0, mono_string_new_utf16 (domain, tz_info.StandardName, i));
4125 if ((year <= 1601) || (year > 30827)) {
4127 * According to MSDN, the MS time functions can't handle dates outside
4133 /* even if the timezone has no daylight savings it may have Bias (e.g. GMT+13 it seems) */
4134 if (tz_id != TIME_ZONE_ID_UNKNOWN) {
4135 tz_info.StandardDate.wYear = year;
4136 convert_to_absolute_date(&tz_info.StandardDate);
4137 err = SystemTimeToFileTime (&tz_info.StandardDate, &ft);
4139 mono_array_set ((*data), gint64, 1, FILETIME_ADJUST + (((guint64)ft.dwHighDateTime<<32) | ft.dwLowDateTime));
4140 tz_info.DaylightDate.wYear = year;
4141 convert_to_absolute_date(&tz_info.DaylightDate);
4142 err = SystemTimeToFileTime (&tz_info.DaylightDate, &ft);
4144 mono_array_set ((*data), gint64, 0, FILETIME_ADJUST + (((guint64)ft.dwHighDateTime<<32) | ft.dwLowDateTime));
4146 mono_array_set ((*data), gint64, 2, (tz_info.Bias + tz_info.StandardBias) * -600000000LL);
4147 mono_array_set ((*data), gint64, 3, (tz_info.DaylightBias - tz_info.StandardBias) * -600000000LL);
4154 ves_icall_System_Object_obj_address (MonoObject *this)
4156 MONO_ARCH_SAVE_REGS;
4163 static inline gint32
4164 mono_array_get_byte_length (MonoArray *array)
4170 klass = array->obj.vtable->klass;
4172 if (array->bounds == NULL)
4173 length = array->max_length;
4176 for (i = 0; i < klass->rank; ++ i)
4177 length *= array->bounds [i].length;
4180 switch (klass->element_class->byval_arg.type) {
4183 case MONO_TYPE_BOOLEAN:
4187 case MONO_TYPE_CHAR:
4195 return length * sizeof (gpointer);
4206 ves_icall_System_Buffer_ByteLengthInternal (MonoArray *array)
4208 MONO_ARCH_SAVE_REGS;
4210 return mono_array_get_byte_length (array);
4214 ves_icall_System_Buffer_GetByteInternal (MonoArray *array, gint32 idx)
4216 MONO_ARCH_SAVE_REGS;
4218 return mono_array_get (array, gint8, idx);
4222 ves_icall_System_Buffer_SetByteInternal (MonoArray *array, gint32 idx, gint8 value)
4224 MONO_ARCH_SAVE_REGS;
4226 mono_array_set (array, gint8, idx, value);
4230 ves_icall_System_Buffer_BlockCopyInternal (MonoArray *src, gint32 src_offset, MonoArray *dest, gint32 dest_offset, gint32 count)
4232 char *src_buf, *dest_buf;
4234 MONO_ARCH_SAVE_REGS;
4236 /* watch out for integer overflow */
4237 if ((src_offset > mono_array_get_byte_length (src) - count) || (dest_offset > mono_array_get_byte_length (dest) - count))
4240 src_buf = (gint8 *)src->vector + src_offset;
4241 dest_buf = (gint8 *)dest->vector + dest_offset;
4243 memcpy (dest_buf, src_buf, count);
4249 ves_icall_Remoting_RealProxy_GetTransparentProxy (MonoObject *this, MonoString *class_name)
4251 MonoDomain *domain = mono_object_domain (this);
4253 MonoRealProxy *rp = ((MonoRealProxy *)this);
4254 MonoTransparentProxy *tp;
4258 MONO_ARCH_SAVE_REGS;
4260 res = mono_object_new (domain, mono_defaults.transparent_proxy_class);
4261 tp = (MonoTransparentProxy*) res;
4264 type = ((MonoReflectionType *)rp->class_to_proxy)->type;
4265 klass = mono_class_from_mono_type (type);
4267 tp->custom_type_info = (mono_object_isinst (this, mono_defaults.iremotingtypeinfo_class) != NULL);
4268 tp->remote_class = mono_remote_class (domain, class_name, klass);
4269 res->vtable = tp->remote_class->vtable;
4274 static MonoReflectionType *
4275 ves_icall_Remoting_RealProxy_InternalGetProxyType (MonoTransparentProxy *tp)
4277 return mono_type_get_object (mono_object_domain (tp), &tp->remote_class->proxy_class->byval_arg);
4280 /* System.Environment */
4283 ves_icall_System_Environment_get_MachineName (void)
4285 #if defined (PLATFORM_WIN32)
4290 len = MAX_COMPUTERNAME_LENGTH + 1;
4291 buf = g_new (gunichar2, len);
4294 if (GetComputerName (buf, (PDWORD) &len))
4295 result = mono_string_new_utf16 (mono_domain_get (), buf, len);
4304 MONO_ARCH_SAVE_REGS;
4307 buf = g_new (gchar, len);
4310 if (gethostname (buf, len) == 0)
4311 result = mono_string_new (mono_domain_get (), buf);
4319 ves_icall_System_Environment_get_Platform (void)
4321 MONO_ARCH_SAVE_REGS;
4323 #if defined (PLATFORM_WIN32)
4333 ves_icall_System_Environment_get_NewLine (void)
4335 MONO_ARCH_SAVE_REGS;
4337 #if defined (PLATFORM_WIN32)
4338 return mono_string_new (mono_domain_get (), "\r\n");
4340 return mono_string_new (mono_domain_get (), "\n");
4345 ves_icall_System_Environment_GetEnvironmentVariable (MonoString *name)
4350 MONO_ARCH_SAVE_REGS;
4355 utf8_name = mono_string_to_utf8 (name); /* FIXME: this should be ascii */
4356 value = g_getenv (utf8_name);
4362 return mono_string_new (mono_domain_get (), value);
4366 * There is no standard way to get at environ.
4374 ves_icall_System_Environment_GetEnvironmentVariableNames (void)
4382 MONO_ARCH_SAVE_REGS;
4385 for (e = environ; *e != 0; ++ e)
4388 domain = mono_domain_get ();
4389 names = mono_array_new (domain, mono_defaults.string_class, n);
4392 for (e = environ; *e != 0; ++ e) {
4393 parts = g_strsplit (*e, "=", 2);
4395 str = mono_string_new (domain, *parts);
4396 mono_array_set (names, MonoString *, n, str);
4408 * Returns the number of milliseconds elapsed since the system started.
4411 ves_icall_System_Environment_get_TickCount (void)
4413 #if defined (PLATFORM_WIN32)
4414 return GetTickCount();
4420 MONO_ARCH_SAVE_REGS;
4422 res = (gint32) gettimeofday (&tv, &tz);
4425 res = (gint32) ((tv.tv_sec & 0xFFFFF) * 1000 + (tv.tv_usec / 1000));
4432 ves_icall_System_Environment_Exit (int result)
4434 MONO_ARCH_SAVE_REGS;
4436 mono_runtime_quit ();
4438 /* we may need to do some cleanup here... */
4443 ves_icall_System_Environment_GetGacPath (void)
4445 return mono_string_new (mono_domain_get (), mono_assembly_getrootdir ());
4449 ves_icall_System_Environment_GetWindowsFolderPath (int folder)
4451 #if defined (PLATFORM_WIN32)
4452 #ifndef CSIDL_FLAG_CREATE
4453 #define CSIDL_FLAG_CREATE 0x8000
4456 WCHAR path [MAX_PATH];
4457 /* Create directory if no existing */
4458 if (SUCCEEDED (SHGetFolderPathW (NULL, folder | CSIDL_FLAG_CREATE, NULL, 0, path))) {
4462 return mono_string_new_utf16 (mono_domain_get (), path, len);
4465 g_warning ("ves_icall_System_Environment_GetWindowsFolderPath should only be called on Windows!");
4467 return mono_string_new (mono_domain_get (), "");
4471 ves_icall_System_Environment_GetLogicalDrives (void)
4473 gunichar2 buf [128], *ptr, *dname;
4475 gint initial_size = 127, size = 128;
4478 MonoString *drivestr;
4479 MonoDomain *domain = mono_domain_get ();
4481 MONO_ARCH_SAVE_REGS;
4486 while (size > initial_size) {
4487 size = GetLogicalDriveStrings (initial_size, ptr);
4488 if (size > initial_size) {
4491 ptr = g_malloc0 ((size + 1) * sizeof (gunichar2));
4492 initial_size = size;
4506 result = mono_array_new (domain, mono_defaults.string_class, ndrives);
4509 u8 = g_utf16_to_utf8 (dname, -1, NULL, NULL, NULL);
4510 drivestr = mono_string_new (domain, u8);
4512 mono_array_set (result, gpointer, ndrives++, drivestr);
4523 ves_icall_System_Environment_InternalGetHome (void)
4525 MONO_ARCH_SAVE_REGS;
4527 return mono_string_new (mono_domain_get (), g_get_home_dir ());
4530 static const char *encodings [] = {
4532 "ascii", "us_ascii", "us", "ansi_x3.4_1968",
4533 "ansi_x3.4_1986", "cp367", "csascii", "ibm367",
4534 "iso_ir_6", "iso646_us", "iso_646.irv:1991",
4536 "utf_7", "csunicode11utf7", "unicode_1_1_utf_7",
4537 "unicode_2_0_utf_7", "x_unicode_1_1_utf_7",
4538 "x_unicode_2_0_utf_7",
4540 "utf_8", "unicode_1_1_utf_8", "unicode_2_0_utf_8",
4541 "x_unicode_1_1_utf_8", "x_unicode_2_0_utf_8",
4543 "utf_16", "UTF_16LE", "ucs_2", "unicode",
4546 "unicodefffe", "utf_16be",
4553 * Returns the internal codepage, if the value of "int_code_page" is
4554 * 1 at entry, and we can not compute a suitable code page number,
4555 * returns the code page as a string
4558 ves_icall_System_Text_Encoding_InternalCodePage (gint32 *int_code_page)
4562 char *codepage = NULL;
4564 int want_name = *int_code_page;
4567 *int_code_page = -1;
4568 MONO_ARCH_SAVE_REGS;
4570 g_get_charset (&cset);
4571 p = codepage = strdup (cset);
4572 for (p = codepage; *p; p++){
4573 if (isascii (*p) && isalpha (*p))
4578 /* g_print ("charset: %s\n", cset); */
4580 /* handle some common aliases */
4583 for (i = 0; p != 0; ){
4586 p = encodings [++i];
4589 if (strcmp (p, codepage) == 0){
4590 *int_code_page = code;
4593 p = encodings [++i];
4596 if (strstr (codepage, "utf_8") != NULL)
4597 *int_code_page |= 0x10000000;
4600 if (want_name && *int_code_page == -1)
4601 return mono_string_new (mono_domain_get (), cset);
4607 ves_icall_System_Environment_get_HasShutdownStarted (void)
4609 if (mono_runtime_is_shutting_down ())
4612 if (mono_domain_is_unloading (mono_domain_get ()))
4619 ves_icall_MonoMethodMessage_InitMessage (MonoMethodMessage *this,
4620 MonoReflectionMethod *method,
4621 MonoArray *out_args)
4623 MONO_ARCH_SAVE_REGS;
4625 mono_message_init (mono_object_domain (this), this, method, out_args);
4629 ves_icall_IsTransparentProxy (MonoObject *proxy)
4631 MONO_ARCH_SAVE_REGS;
4636 if (proxy->vtable->klass == mono_defaults.transparent_proxy_class)
4643 ves_icall_System_Runtime_Activation_ActivationServices_EnableProxyActivation (MonoReflectionType *type, MonoBoolean enable)
4648 MONO_ARCH_SAVE_REGS;
4650 klass = mono_class_from_mono_type (type->type);
4651 vtable = mono_class_vtable (mono_domain_get (), klass);
4653 if (enable) vtable->remote = 1;
4654 else vtable->remote = 0;
4658 ves_icall_System_Runtime_Activation_ActivationServices_AllocateUninitializedClassInstance (MonoReflectionType *type)
4663 MONO_ARCH_SAVE_REGS;
4665 domain = mono_object_domain (type);
4666 klass = mono_class_from_mono_type (type->type);
4668 if (klass->rank >= 1) {
4669 g_assert (klass->rank == 1);
4670 return (MonoObject *) mono_array_new (domain, klass->element_class, 0);
4672 /* Bypass remoting object creation check */
4673 return mono_object_new_alloc_specific (mono_class_vtable (domain, klass));
4678 ves_icall_System_IO_get_temp_path (void)
4680 MONO_ARCH_SAVE_REGS;
4682 return mono_string_new (mono_domain_get (), g_get_tmp_dir ());
4686 ves_icall_RuntimeMethod_GetFunctionPointer (MonoMethod *method)
4688 MONO_ARCH_SAVE_REGS;
4690 return mono_compile_method (method);
4694 ves_icall_System_Configuration_DefaultConfig_get_machine_config_path (void)
4699 MONO_ARCH_SAVE_REGS;
4701 path = g_build_path (G_DIR_SEPARATOR_S, mono_get_config_dir (), "mono", "machine.config", NULL);
4703 #if defined (PLATFORM_WIN32)
4704 /* Avoid mixing '/' and '\\' */
4707 for (i = strlen (path) - 1; i >= 0; i--)
4708 if (path [i] == '/')
4712 mcpath = mono_string_new (mono_domain_get (), path);
4719 ves_icall_System_Web_Util_ICalls_get_machine_install_dir (void)
4724 MONO_ARCH_SAVE_REGS;
4726 path = g_path_get_dirname (mono_get_config_dir ());
4728 #if defined (PLATFORM_WIN32)
4729 /* Avoid mixing '/' and '\\' */
4732 for (i = strlen (path) - 1; i >= 0; i--)
4733 if (path [i] == '/')
4737 ipath = mono_string_new (mono_domain_get (), path);
4744 ves_icall_System_Diagnostics_DefaultTraceListener_WriteWindowsDebugString (MonoString *message)
4746 #if defined (PLATFORM_WIN32)
4747 static void (*output_debug) (gchar *);
4748 static gboolean tried_loading = FALSE;
4750 MONO_ARCH_SAVE_REGS;
4752 if (!tried_loading && output_debug == NULL) {
4755 tried_loading = TRUE;
4756 k32 = g_module_open ("kernel32", G_MODULE_BIND_LAZY);
4758 gchar *error = g_strdup (g_module_error ());
4759 g_warning ("Failed to load kernel32.dll: %s\n", error);
4764 g_module_symbol (k32, "OutputDebugStringW", (gpointer *) &output_debug);
4765 if (!output_debug) {
4766 gchar *error = g_strdup (g_module_error ());
4767 g_warning ("Failed to load OutputDebugStringW: %s\n", error);
4773 if (output_debug == NULL)
4776 output_debug (mono_string_chars (message));
4778 g_warning ("WriteWindowsDebugString called and PLATFORM_WIN32 not defined!\n");
4782 /* Only used for value types */
4784 ves_icall_System_Activator_CreateInstanceInternal (MonoReflectionType *type)
4789 MONO_ARCH_SAVE_REGS;
4791 domain = mono_object_domain (type);
4792 klass = mono_class_from_mono_type (type->type);
4794 return mono_object_new (domain, klass);
4797 static MonoReflectionMethod *
4798 ves_icall_MonoMethod_get_base_definition (MonoReflectionMethod *m)
4801 MonoMethod *method = m->method;
4802 MonoMethod *result = NULL;
4804 MONO_ARCH_SAVE_REGS;
4806 if (!(method->flags & METHOD_ATTRIBUTE_VIRTUAL) ||
4807 MONO_CLASS_IS_INTERFACE (method->klass) ||
4808 method->flags & METHOD_ATTRIBUTE_NEW_SLOT)
4811 if (method->klass == NULL || (klass = method->klass->parent) == NULL)
4814 if (klass->generic_inst)
4815 klass = mono_class_from_mono_type (klass->generic_inst->generic_type);
4817 while (result == NULL && klass != NULL && (klass->vtable_size > method->slot))
4819 result = klass->vtable [method->slot];
4820 if (result == NULL) {
4821 /* It is an abstract method */
4823 for (i=0; i<klass->method.count; i++) {
4824 if (klass->methods [i]->slot == method->slot) {
4825 result = klass->methods [i];
4830 klass = klass->parent;
4836 return mono_method_get_object (mono_domain_get (), result, NULL);
4840 mono_ArgIterator_Setup (MonoArgIterator *iter, char* argsp, char* start)
4842 MONO_ARCH_SAVE_REGS;
4844 iter->sig = *(MonoMethodSignature**)argsp;
4846 g_assert (iter->sig->sentinelpos <= iter->sig->param_count);
4847 g_assert (iter->sig->call_convention == MONO_CALL_VARARG);
4850 /* FIXME: it's not documented what start is exactly... */
4854 int i, align, arg_size;
4855 iter->args = argsp + sizeof (gpointer);
4856 for (i = 0; i < iter->sig->sentinelpos; ++i) {
4857 arg_size = mono_type_stack_size (iter->sig->params [i], &align);
4858 iter->args = (char*)iter->args + arg_size;
4861 iter->num_args = iter->sig->param_count - iter->sig->sentinelpos;
4863 /* g_print ("sig %p, param_count: %d, sent: %d\n", iter->sig, iter->sig->param_count, iter->sig->sentinelpos); */
4867 mono_ArgIterator_IntGetNextArg (MonoArgIterator *iter)
4869 gint i, align, arg_size;
4871 MONO_ARCH_SAVE_REGS;
4873 i = iter->sig->sentinelpos + iter->next_arg;
4875 g_assert (i < iter->sig->param_count);
4877 res.type = iter->sig->params [i];
4878 res.klass = mono_class_from_mono_type (res.type);
4879 /* FIXME: endianess issue... */
4880 res.value = iter->args;
4881 arg_size = mono_type_stack_size (res.type, &align);
4882 iter->args = (char*)iter->args + arg_size;
4885 //g_print ("returning arg %d, type 0x%02x of size %d at %p\n", i, res.type->type, arg_size, res.value);
4891 mono_ArgIterator_IntGetNextArgT (MonoArgIterator *iter, MonoType *type)
4893 gint i, align, arg_size;
4895 MONO_ARCH_SAVE_REGS;
4897 i = iter->sig->sentinelpos + iter->next_arg;
4899 g_assert (i < iter->sig->param_count);
4901 while (i < iter->sig->param_count) {
4902 if (!mono_metadata_type_equal (type, iter->sig->params [i]))
4904 res.type = iter->sig->params [i];
4905 res.klass = mono_class_from_mono_type (res.type);
4906 /* FIXME: endianess issue... */
4907 res.value = iter->args;
4908 arg_size = mono_type_stack_size (res.type, &align);
4909 iter->args = (char*)iter->args + arg_size;
4911 //g_print ("returning arg %d, type 0x%02x of size %d at %p\n", i, res.type->type, arg_size, res.value);
4914 //g_print ("arg type 0x%02x not found\n", res.type->type);
4923 mono_ArgIterator_IntGetNextArgType (MonoArgIterator *iter)
4926 MONO_ARCH_SAVE_REGS;
4928 i = iter->sig->sentinelpos + iter->next_arg;
4930 g_assert (i < iter->sig->param_count);
4932 return iter->sig->params [i];
4936 mono_TypedReference_ToObject (MonoTypedRef tref)
4938 MONO_ARCH_SAVE_REGS;
4940 if (MONO_TYPE_IS_REFERENCE (tref.type)) {
4941 MonoObject** objp = tref.value;
4945 return mono_value_box (mono_domain_get (), tref.klass, tref.value);
4949 prelink_method (MonoMethod *method)
4951 const char *exc_class, *exc_arg;
4952 if (!(method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL))
4954 mono_lookup_pinvoke_call (method, &exc_class, &exc_arg);
4956 mono_raise_exception(
4957 mono_exception_from_name_msg (mono_defaults.corlib, "System", exc_class, exc_arg ) );
4959 /* create the wrapper, too? */
4963 ves_icall_System_Runtime_InteropServices_Marshal_Prelink (MonoReflectionMethod *method)
4965 MONO_ARCH_SAVE_REGS;
4966 prelink_method (method->method);
4970 ves_icall_System_Runtime_InteropServices_Marshal_PrelinkAll (MonoReflectionType *type)
4972 MonoClass *klass = mono_class_from_mono_type (type->type);
4974 MONO_ARCH_SAVE_REGS;
4976 mono_class_init (klass);
4977 for (i = 0; i < klass->method.count; ++i)
4978 prelink_method (klass->methods [i]);
4982 ves_icall_System_Char_GetDataTablePointers (guint8 **category_data, guint8 **numeric_data,
4983 gdouble **numeric_data_values, guint16 **to_lower_data_low,
4984 guint16 **to_lower_data_high, guint16 **to_upper_data_low,
4985 guint16 **to_upper_data_high)
4987 *category_data = CategoryData;
4988 *numeric_data = NumericData;
4989 *numeric_data_values = NumericDataValues;
4990 *to_lower_data_low = ToLowerDataLow;
4991 *to_lower_data_high = ToLowerDataHigh;
4992 *to_upper_data_low = ToUpperDataLow;
4993 *to_upper_data_high = ToUpperDataHigh;
5004 const IcallEntry *icalls;
5008 static const IcallEntry activator_icalls [] = {
5009 {"CreateInstanceInternal", ves_icall_System_Activator_CreateInstanceInternal}
5011 static const IcallEntry appdomain_icalls [] = {
5012 {"ExecuteAssembly", ves_icall_System_AppDomain_ExecuteAssembly},
5013 {"GetAssemblies", ves_icall_System_AppDomain_GetAssemblies},
5014 {"GetData", ves_icall_System_AppDomain_GetData},
5015 {"InternalGetContext", ves_icall_System_AppDomain_InternalGetContext},
5016 {"InternalGetDefaultContext", ves_icall_System_AppDomain_InternalGetDefaultContext},
5017 {"InternalGetProcessGuid", ves_icall_System_AppDomain_InternalGetProcessGuid},
5018 {"InternalIsFinalizingForUnload", ves_icall_System_AppDomain_InternalIsFinalizingForUnload},
5019 {"InternalPopDomainRef", ves_icall_System_AppDomain_InternalPopDomainRef},
5020 {"InternalPushDomainRef", ves_icall_System_AppDomain_InternalPushDomainRef},
5021 {"InternalPushDomainRefByID", ves_icall_System_AppDomain_InternalPushDomainRefByID},
5022 {"InternalSetContext", ves_icall_System_AppDomain_InternalSetContext},
5023 {"InternalSetDomain", ves_icall_System_AppDomain_InternalSetDomain},
5024 {"InternalSetDomainByID", ves_icall_System_AppDomain_InternalSetDomainByID},
5025 {"InternalUnload", ves_icall_System_AppDomain_InternalUnload},
5026 {"LoadAssembly", ves_icall_System_AppDomain_LoadAssembly},
5027 {"LoadAssemblyRaw", ves_icall_System_AppDomain_LoadAssemblyRaw},
5028 {"SetData", ves_icall_System_AppDomain_SetData},
5029 {"createDomain", ves_icall_System_AppDomain_createDomain},
5030 {"getCurDomain", ves_icall_System_AppDomain_getCurDomain},
5031 {"getFriendlyName", ves_icall_System_AppDomain_getFriendlyName},
5032 {"getSetup", ves_icall_System_AppDomain_getSetup}
5035 static const IcallEntry argiterator_icalls [] = {
5036 {"IntGetNextArg()", mono_ArgIterator_IntGetNextArg},
5037 {"IntGetNextArg(intptr)", mono_ArgIterator_IntGetNextArgT},
5038 {"IntGetNextArgType", mono_ArgIterator_IntGetNextArgType},
5039 {"Setup", mono_ArgIterator_Setup}
5042 static const IcallEntry array_icalls [] = {
5043 {"Clone", mono_array_clone},
5044 {"CreateInstanceImpl", ves_icall_System_Array_CreateInstanceImpl},
5045 {"FastCopy", ves_icall_System_Array_FastCopy},
5046 {"GetLength", ves_icall_System_Array_GetLength},
5047 {"GetLowerBound", ves_icall_System_Array_GetLowerBound},
5048 {"GetRank", ves_icall_System_Array_GetRank},
5049 {"GetValue", ves_icall_System_Array_GetValue},
5050 {"GetValueImpl", ves_icall_System_Array_GetValueImpl},
5051 {"SetValue", ves_icall_System_Array_SetValue},
5052 {"SetValueImpl", ves_icall_System_Array_SetValueImpl}
5055 static const IcallEntry buffer_icalls [] = {
5056 {"BlockCopyInternal", ves_icall_System_Buffer_BlockCopyInternal},
5057 {"ByteLengthInternal", ves_icall_System_Buffer_ByteLengthInternal},
5058 {"GetByteInternal", ves_icall_System_Buffer_GetByteInternal},
5059 {"SetByteInternal", ves_icall_System_Buffer_SetByteInternal}
5062 static const IcallEntry char_icalls [] = {
5063 {"GetDataTablePointers", ves_icall_System_Char_GetDataTablePointers},
5064 {"InternalToLower(char,System.Globalization.CultureInfo)", ves_icall_System_Char_InternalToLower_Comp},
5065 {"InternalToUpper(char,System.Globalization.CultureInfo)", ves_icall_System_Char_InternalToUpper_Comp}
5068 static const IcallEntry defaultconf_icalls [] = {
5069 {"get_machine_config_path", ves_icall_System_Configuration_DefaultConfig_get_machine_config_path}
5072 static const IcallEntry timezone_icalls [] = {
5073 {"GetTimeZoneData", ves_icall_System_CurrentTimeZone_GetTimeZoneData}
5076 static const IcallEntry datetime_icalls [] = {
5077 {"GetNow", ves_icall_System_DateTime_GetNow}
5080 static const IcallEntry decimal_icalls [] = {
5081 {"decimal2Int64", mono_decimal2Int64},
5082 {"decimal2UInt64", mono_decimal2UInt64},
5083 {"decimal2double", mono_decimal2double},
5084 {"decimal2string", mono_decimal2string},
5085 {"decimalCompare", mono_decimalCompare},
5086 {"decimalDiv", mono_decimalDiv},
5087 {"decimalFloorAndTrunc", mono_decimalFloorAndTrunc},
5088 {"decimalIncr", mono_decimalIncr},
5089 {"decimalIntDiv", mono_decimalIntDiv},
5090 {"decimalMult", mono_decimalMult},
5091 {"decimalRound", mono_decimalRound},
5092 {"decimalSetExponent", mono_decimalSetExponent},
5093 {"double2decimal", mono_double2decimal}, /* FIXME: wrong signature. */
5094 {"string2decimal", mono_string2decimal}
5097 static const IcallEntry delegate_icalls [] = {
5098 {"CreateDelegate_internal", ves_icall_System_Delegate_CreateDelegate_internal}
5101 static const IcallEntry tracelist_icalls [] = {
5102 {"WriteWindowsDebugString", ves_icall_System_Diagnostics_DefaultTraceListener_WriteWindowsDebugString}
5105 static const IcallEntry fileversion_icalls [] = {
5106 {"GetVersionInfo_internal(string)", ves_icall_System_Diagnostics_FileVersionInfo_GetVersionInfo_internal}
5109 static const IcallEntry process_icalls [] = {
5110 {"ExitCode_internal(intptr)", ves_icall_System_Diagnostics_Process_ExitCode_internal},
5111 {"ExitTime_internal(intptr)", ves_icall_System_Diagnostics_Process_ExitTime_internal},
5112 {"GetModules_internal()", ves_icall_System_Diagnostics_Process_GetModules_internal},
5113 {"GetPid_internal()", ves_icall_System_Diagnostics_Process_GetPid_internal},
5114 {"GetProcess_internal(int)", ves_icall_System_Diagnostics_Process_GetProcess_internal},
5115 {"GetProcesses_internal()", ves_icall_System_Diagnostics_Process_GetProcesses_internal},
5116 {"GetWorkingSet_internal(intptr,int&,int&)", ves_icall_System_Diagnostics_Process_GetWorkingSet_internal},
5117 {"Kill_internal", ves_icall_System_Diagnostics_Process_Kill_internal},
5118 {"ProcessName_internal(intptr)", ves_icall_System_Diagnostics_Process_ProcessName_internal},
5119 {"Process_free_internal(intptr)", ves_icall_System_Diagnostics_Process_Process_free_internal},
5120 {"SetWorkingSet_internal(intptr,int,int,bool)", ves_icall_System_Diagnostics_Process_SetWorkingSet_internal},
5121 {"StartTime_internal(intptr)", ves_icall_System_Diagnostics_Process_StartTime_internal},
5122 {"Start_internal(string,string,string,intptr,intptr,intptr,System.Diagnostics.Process/ProcInfo&)", ves_icall_System_Diagnostics_Process_Start_internal},
5123 {"WaitForExit_internal(intptr,int)", ves_icall_System_Diagnostics_Process_WaitForExit_internal}
5126 static const IcallEntry double_icalls [] = {
5127 {"AssertEndianity", ves_icall_System_Double_AssertEndianity},
5128 {"ParseImpl", mono_double_ParseImpl}
5131 static const IcallEntry enum_icalls [] = {
5132 {"ToObject", ves_icall_System_Enum_ToObject},
5133 {"get_value", ves_icall_System_Enum_get_value}
5136 static const IcallEntry environment_icalls [] = {
5137 {"Exit", ves_icall_System_Environment_Exit},
5138 {"GetCommandLineArgs", mono_runtime_get_main_args},
5139 {"GetEnvironmentVariable", ves_icall_System_Environment_GetEnvironmentVariable},
5140 {"GetEnvironmentVariableNames", ves_icall_System_Environment_GetEnvironmentVariableNames},
5141 {"GetLogicalDrivesInternal", ves_icall_System_Environment_GetLogicalDrives },
5142 {"GetMachineConfigPath", ves_icall_System_Configuration_DefaultConfig_get_machine_config_path},
5143 {"GetOSVersionString", ves_icall_System_Environment_GetOSVersionString},
5144 {"GetWindowsFolderPath", ves_icall_System_Environment_GetWindowsFolderPath},
5145 {"get_ExitCode", mono_environment_exitcode_get},
5146 {"get_HasShutdownStarted", ves_icall_System_Environment_get_HasShutdownStarted},
5147 {"get_MachineName", ves_icall_System_Environment_get_MachineName},
5148 {"get_NewLine", ves_icall_System_Environment_get_NewLine},
5149 {"get_Platform", ves_icall_System_Environment_get_Platform},
5150 {"get_TickCount", ves_icall_System_Environment_get_TickCount},
5151 {"get_UserName", ves_icall_System_Environment_get_UserName},
5152 {"internalGetGacPath", ves_icall_System_Environment_GetGacPath},
5153 {"internalGetHome", ves_icall_System_Environment_InternalGetHome},
5154 {"set_ExitCode", mono_environment_exitcode_set}
5157 static const IcallEntry cultureinfo_icalls [] = {
5158 {"construct_compareinfo(object,string)", ves_icall_System_Globalization_CompareInfo_construct_compareinfo},
5159 {"construct_datetime_format", ves_icall_System_Globalization_CultureInfo_construct_datetime_format},
5160 {"construct_internal_locale(string)", ves_icall_System_Globalization_CultureInfo_construct_internal_locale},
5161 {"construct_internal_locale_from_current_locale", ves_icall_System_Globalization_CultureInfo_construct_internal_locale_from_current_locale},
5162 {"construct_internal_locale_from_lcid", ves_icall_System_Globalization_CultureInfo_construct_internal_locale_from_lcid},
5163 {"construct_internal_locale_from_name", ves_icall_System_Globalization_CultureInfo_construct_internal_locale_from_name},
5164 {"construct_internal_locale_from_specific_name", ves_icall_System_Globalization_CultureInfo_construct_internal_locale_from_specific_name},
5165 {"construct_number_format", ves_icall_System_Globalization_CultureInfo_construct_number_format},
5166 {"internal_get_cultures", ves_icall_System_Globalization_CultureInfo_internal_get_cultures},
5167 {"internal_is_lcid_neutral", ves_icall_System_Globalization_CultureInfo_internal_is_lcid_neutral}
5170 static const IcallEntry compareinfo_icalls [] = {
5171 {"assign_sortkey(object,string,System.Globalization.CompareOptions)", ves_icall_System_Globalization_CompareInfo_assign_sortkey},
5172 {"construct_compareinfo(string)", ves_icall_System_Globalization_CompareInfo_construct_compareinfo},
5173 {"free_internal_collator()", ves_icall_System_Globalization_CompareInfo_free_internal_collator},
5174 {"internal_compare(string,int,int,string,int,int,System.Globalization.CompareOptions)", ves_icall_System_Globalization_CompareInfo_internal_compare},
5175 {"internal_index(string,int,int,char,System.Globalization.CompareOptions,bool)", ves_icall_System_Globalization_CompareInfo_internal_index_char},
5176 {"internal_index(string,int,int,string,System.Globalization.CompareOptions,bool)", ves_icall_System_Globalization_CompareInfo_internal_index}
5179 static const IcallEntry gc_icalls [] = {
5180 {"GetTotalMemory", ves_icall_System_GC_GetTotalMemory},
5181 {"InternalCollect", ves_icall_System_GC_InternalCollect},
5182 {"KeepAlive", ves_icall_System_GC_KeepAlive},
5183 {"ReRegisterForFinalize", ves_icall_System_GC_ReRegisterForFinalize},
5184 {"SuppressFinalize", ves_icall_System_GC_SuppressFinalize},
5185 {"WaitForPendingFinalizers", ves_icall_System_GC_WaitForPendingFinalizers}
5188 static const IcallEntry famwatcher_icalls [] = {
5189 {"InternalFAMNextEvent", ves_icall_System_IO_FAMW_InternalFAMNextEvent}
5192 static const IcallEntry filewatcher_icalls [] = {
5193 {"InternalCloseDirectory", ves_icall_System_IO_FSW_CloseDirectory},
5194 {"InternalOpenDirectory", ves_icall_System_IO_FSW_OpenDirectory},
5195 {"InternalReadDirectoryChanges", ves_icall_System_IO_FSW_ReadDirectoryChanges},
5196 {"InternalSupportsFSW", ves_icall_System_IO_FSW_SupportsFSW}
5199 static const IcallEntry path_icalls [] = {
5200 {"get_temp_path", ves_icall_System_IO_get_temp_path}
5203 static const IcallEntry monoio_icalls [] = {
5204 {"BeginRead", ves_icall_System_IO_MonoIO_BeginRead },
5205 {"BeginWrite", ves_icall_System_IO_MonoIO_BeginWrite },
5206 {"Close(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Close},
5207 {"CopyFile(string,string,bool,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_CopyFile},
5208 {"CreateDirectory(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_CreateDirectory},
5209 {"CreatePipe(intptr&,intptr&)", ves_icall_System_IO_MonoIO_CreatePipe},
5210 {"DeleteFile(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_DeleteFile},
5211 {"FindClose(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_FindClose},
5212 {"FindFirstFile(string,System.IO.MonoIOStat&,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_FindFirstFile},
5213 {"FindNextFile(intptr,System.IO.MonoIOStat&,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_FindNextFile},
5214 {"Flush(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Flush},
5215 {"GetCurrentDirectory(System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetCurrentDirectory},
5216 {"GetFileAttributes(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetFileAttributes},
5217 {"GetFileStat(string,System.IO.MonoIOStat&,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetFileStat},
5218 {"GetFileType(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetFileType},
5219 {"GetLength(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetLength},
5220 {"GetSupportsAsync", ves_icall_System_IO_MonoIO_GetSupportsAsync},
5221 {"GetTempPath(string&)", ves_icall_System_IO_MonoIO_GetTempPath},
5222 {"Lock(intptr,long,long,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Lock},
5223 {"MoveFile(string,string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_MoveFile},
5224 {"Open(string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare,bool,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Open},
5225 {"Read(intptr,byte[],int,int,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Read},
5226 {"RemoveDirectory(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_RemoveDirectory},
5227 {"Seek(intptr,long,System.IO.SeekOrigin,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Seek},
5228 {"SetCurrentDirectory(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_SetCurrentDirectory},
5229 {"SetFileAttributes(string,System.IO.FileAttributes,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_SetFileAttributes},
5230 {"SetFileTime(intptr,long,long,long,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_SetFileTime},
5231 {"SetLength(intptr,long,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_SetLength},
5232 {"Unlock(intptr,long,long,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Unlock},
5233 {"Write(intptr,byte[],int,int,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Write},
5234 {"get_AltDirectorySeparatorChar", ves_icall_System_IO_MonoIO_get_AltDirectorySeparatorChar},
5235 {"get_ConsoleError", ves_icall_System_IO_MonoIO_get_ConsoleError},
5236 {"get_ConsoleInput", ves_icall_System_IO_MonoIO_get_ConsoleInput},
5237 {"get_ConsoleOutput", ves_icall_System_IO_MonoIO_get_ConsoleOutput},
5238 {"get_DirectorySeparatorChar", ves_icall_System_IO_MonoIO_get_DirectorySeparatorChar},
5239 {"get_InvalidPathChars", ves_icall_System_IO_MonoIO_get_InvalidPathChars},
5240 {"get_PathSeparator", ves_icall_System_IO_MonoIO_get_PathSeparator},
5241 {"get_VolumeSeparatorChar", ves_icall_System_IO_MonoIO_get_VolumeSeparatorChar}
5244 static const IcallEntry math_icalls [] = {
5245 {"Acos", ves_icall_System_Math_Acos},
5246 {"Asin", ves_icall_System_Math_Asin},
5247 {"Atan", ves_icall_System_Math_Atan},
5248 {"Atan2", ves_icall_System_Math_Atan2},
5249 {"Cos", ves_icall_System_Math_Cos},
5250 {"Cosh", ves_icall_System_Math_Cosh},
5251 {"Exp", ves_icall_System_Math_Exp},
5252 {"Floor", ves_icall_System_Math_Floor},
5253 {"Log", ves_icall_System_Math_Log},
5254 {"Log10", ves_icall_System_Math_Log10},
5255 {"Pow", ves_icall_System_Math_Pow},
5256 {"Round", ves_icall_System_Math_Round},
5257 {"Round2", ves_icall_System_Math_Round2},
5258 {"Sin", ves_icall_System_Math_Sin},
5259 {"Sinh", ves_icall_System_Math_Sinh},
5260 {"Sqrt", ves_icall_System_Math_Sqrt},
5261 {"Tan", ves_icall_System_Math_Tan},
5262 {"Tanh", ves_icall_System_Math_Tanh}
5265 static const IcallEntry customattrs_icalls [] = {
5266 {"GetCustomAttributes", mono_reflection_get_custom_attrs}
5269 static const IcallEntry enuminfo_icalls [] = {
5270 {"get_enum_info", ves_icall_get_enum_info}
5273 static const IcallEntry fieldinfo_icalls [] = {
5274 {"internal_from_handle", ves_icall_System_Reflection_FieldInfo_internal_from_handle}
5277 static const IcallEntry monotype_icalls [] = {
5278 {"GetArrayRank", ves_icall_MonoType_GetArrayRank},
5279 {"GetConstructors", ves_icall_Type_GetConstructors_internal},
5280 {"GetConstructors_internal", ves_icall_Type_GetConstructors_internal},
5281 {"GetElementType", ves_icall_MonoType_GetElementType},
5282 {"GetEvents_internal", ves_icall_Type_GetEvents_internal},
5283 {"GetField", ves_icall_Type_GetField},
5284 {"GetFields_internal", ves_icall_Type_GetFields_internal},
5285 {"GetGenericArguments", ves_icall_MonoType_GetGenericArguments},
5286 {"GetInterfaces", ves_icall_Type_GetInterfaces},
5287 {"GetMethodsByName", ves_icall_Type_GetMethodsByName},
5288 {"GetNestedType", ves_icall_Type_GetNestedType},
5289 {"GetNestedTypes", ves_icall_Type_GetNestedTypes},
5290 {"GetPropertiesByName", ves_icall_Type_GetPropertiesByName},
5291 {"InternalGetEvent", ves_icall_MonoType_GetEvent},
5292 {"IsByRefImpl", ves_icall_type_isbyref},
5293 {"IsPointerImpl", ves_icall_type_ispointer},
5294 {"IsPrimitiveImpl", ves_icall_type_isprimitive},
5295 {"getFullName", ves_icall_System_MonoType_getFullName},
5296 {"get_Assembly", ves_icall_MonoType_get_Assembly},
5297 {"get_BaseType", ves_icall_get_type_parent},
5298 {"get_DeclaringMethod", ves_icall_MonoType_get_DeclaringMethod},
5299 {"get_DeclaringType", ves_icall_MonoType_get_DeclaringType},
5300 {"get_HasGenericArguments", ves_icall_MonoType_get_HasGenericArguments},
5301 {"get_IsGenericParameter", ves_icall_MonoType_get_IsGenericParameter},
5302 {"get_Module", ves_icall_MonoType_get_Module},
5303 {"get_Name", ves_icall_MonoType_get_Name},
5304 {"get_Namespace", ves_icall_MonoType_get_Namespace},
5305 {"get_UnderlyingSystemType", ves_icall_MonoType_get_UnderlyingSystemType},
5306 {"get_attributes", ves_icall_get_attributes},
5307 {"type_from_obj", mono_type_type_from_obj}
5310 static const IcallEntry assembly_icalls [] = {
5311 {"FillName", ves_icall_System_Reflection_Assembly_FillName},
5312 {"GetCallingAssembly", ves_icall_System_Reflection_Assembly_GetCallingAssembly},
5313 {"GetEntryAssembly", ves_icall_System_Reflection_Assembly_GetEntryAssembly},
5314 {"GetExecutingAssembly", ves_icall_System_Reflection_Assembly_GetExecutingAssembly},
5315 {"GetFilesInternal", ves_icall_System_Reflection_Assembly_GetFilesInternal},
5316 {"GetManifestResourceInfoInternal", ves_icall_System_Reflection_Assembly_GetManifestResourceInfoInternal},
5317 {"GetManifestResourceInternal", ves_icall_System_Reflection_Assembly_GetManifestResourceInternal},
5318 {"GetManifestResourceNames", ves_icall_System_Reflection_Assembly_GetManifestResourceNames},
5319 {"GetModulesInternal", ves_icall_System_Reflection_Assembly_GetModulesInternal},
5320 {"GetNamespaces", ves_icall_System_Reflection_Assembly_GetNamespaces},
5321 {"GetReferencedAssemblies", ves_icall_System_Reflection_Assembly_GetReferencedAssemblies},
5322 {"GetTypes", ves_icall_System_Reflection_Assembly_GetTypes},
5323 {"InternalGetAssemblyName", ves_icall_System_Reflection_Assembly_InternalGetAssemblyName},
5324 {"InternalGetType", ves_icall_System_Reflection_Assembly_InternalGetType},
5325 {"InternalImageRuntimeVersion", ves_icall_System_Reflection_Assembly_InternalImageRuntimeVersion},
5326 {"LoadFrom", ves_icall_System_Reflection_Assembly_LoadFrom},
5328 * Private icalls for the Mono Debugger
5330 {"MonoDebugger_GetLocalTypeFromSignature", ves_icall_MonoDebugger_GetLocalTypeFromSignature},
5331 {"MonoDebugger_GetMethod", ves_icall_MonoDebugger_GetMethod},
5332 {"MonoDebugger_GetMethodToken", ves_icall_MonoDebugger_GetMethodToken},
5333 {"MonoDebugger_GetType", ves_icall_MonoDebugger_GetType},
5334 /* normal icalls again */
5335 {"get_EntryPoint", ves_icall_System_Reflection_Assembly_get_EntryPoint},
5336 {"get_code_base", ves_icall_System_Reflection_Assembly_get_code_base},
5337 {"get_global_assembly_cache", ves_icall_System_Reflection_Assembly_get_global_assembly_cache},
5338 {"get_location", ves_icall_System_Reflection_Assembly_get_location},
5339 {"load_with_partial_name", ves_icall_System_Reflection_Assembly_load_with_partial_name}
5342 static const IcallEntry methodbase_icalls [] = {
5343 {"GetCurrentMethod", ves_icall_GetCurrentMethod}
5346 static const IcallEntry module_icalls [] = {
5347 {"Close", ves_icall_System_Reflection_Module_Close},
5348 {"GetGlobalType", ves_icall_System_Reflection_Module_GetGlobalType},
5349 {"GetGuidInternal", ves_icall_System_Reflection_Module_GetGuidInternal},
5350 {"InternalGetTypes", ves_icall_System_Reflection_Module_InternalGetTypes}
5353 static const IcallEntry monocmethod_icalls [] = {
5354 {"GetGenericMethodDefinition_impl", ves_icall_MonoMethod_GetGenericMethodDefinition},
5355 {"InternalInvoke", ves_icall_InternalInvoke},
5356 {"get_Mono_IsInflatedMethod", ves_icall_MonoMethod_get_Mono_IsInflatedMethod}
5359 static const IcallEntry monoeventinfo_icalls [] = {
5360 {"get_event_info", ves_icall_get_event_info}
5363 static const IcallEntry monofield_icalls [] = {
5364 {"GetParentType", ves_icall_MonoField_GetParentType},
5365 {"GetValueInternal", ves_icall_MonoField_GetValueInternal},
5366 {"Mono_GetGenericFieldDefinition", ves_icall_MonoField_Mono_GetGenericFieldDefinition},
5367 {"SetValueInternal", ves_icall_FieldInfo_SetValueInternal}
5370 static const IcallEntry monogenericinst_icalls [] = {
5371 {"GetConstructors_internal", ves_icall_MonoGenericInst_GetConstructors},
5372 {"GetEvents_internal", ves_icall_MonoGenericInst_GetEvents},
5373 {"GetFields_internal", ves_icall_MonoGenericInst_GetFields},
5374 {"GetInterfaces_internal", ves_icall_MonoGenericInst_GetInterfaces},
5375 {"GetMethods_internal", ves_icall_MonoGenericInst_GetMethods},
5376 {"GetParentType", ves_icall_MonoGenericInst_GetParentType},
5377 {"GetProperties_internal", ves_icall_MonoGenericInst_GetProperties},
5378 {"initialize", mono_reflection_generic_inst_initialize}
5381 static const IcallEntry generictypeparambuilder_icalls [] = {
5382 {"initialize", mono_reflection_initialize_generic_parameter}
5385 static const IcallEntry monomethod_icalls [] = {
5386 {"BindGenericParameters", mono_reflection_bind_generic_method_parameters},
5387 {"GetGenericArguments", ves_icall_MonoMethod_GetGenericArguments},
5388 {"GetGenericMethodDefinition_impl", ves_icall_MonoMethod_GetGenericMethodDefinition},
5389 {"InternalInvoke", ves_icall_InternalInvoke},
5390 {"get_HasGenericParameters", ves_icall_MonoMethod_get_HasGenericParameters},
5391 {"get_IsGenericMethodDefinition", ves_icall_MonoMethod_get_IsGenericMethodDefinition},
5392 {"get_Mono_IsInflatedMethod", ves_icall_MonoMethod_get_Mono_IsInflatedMethod},
5393 {"get_base_definition", ves_icall_MonoMethod_get_base_definition}
5396 static const IcallEntry monomethodinfo_icalls [] = {
5397 {"get_method_info", ves_icall_get_method_info},
5398 {"get_parameter_info", ves_icall_get_parameter_info}
5401 static const IcallEntry monopropertyinfo_icalls [] = {
5402 {"get_property_info", ves_icall_get_property_info}
5405 static const IcallEntry dns_icalls [] = {
5406 {"GetHostByAddr_internal(string,string&,string[]&,string[]&)", ves_icall_System_Net_Dns_GetHostByAddr_internal},
5407 {"GetHostByName_internal(string,string&,string[]&,string[]&)", ves_icall_System_Net_Dns_GetHostByName_internal},
5408 {"GetHostName_internal(string&)", ves_icall_System_Net_Dns_GetHostName_internal}
5411 static const IcallEntry socket_icalls [] = {
5412 {"Accept_internal(intptr,int&)", ves_icall_System_Net_Sockets_Socket_Accept_internal},
5413 {"AsyncReceiveInternal", ves_icall_System_Net_Sockets_Socket_AsyncReceive},
5414 {"AsyncSendInternal", ves_icall_System_Net_Sockets_Socket_AsyncSend},
5415 {"Available_internal(intptr,int&)", ves_icall_System_Net_Sockets_Socket_Available_internal},
5416 {"Bind_internal(intptr,System.Net.SocketAddress,int&)", ves_icall_System_Net_Sockets_Socket_Bind_internal},
5417 {"Blocking_internal(intptr,bool,int&)", ves_icall_System_Net_Sockets_Socket_Blocking_internal},
5418 {"Close_internal(intptr,int&)", ves_icall_System_Net_Sockets_Socket_Close_internal},
5419 {"Connect_internal(intptr,System.Net.SocketAddress,int&)", ves_icall_System_Net_Sockets_Socket_Connect_internal},
5420 {"GetSocketOption_arr_internal(intptr,System.Net.Sockets.SocketOptionLevel,System.Net.Sockets.SocketOptionName,byte[]&,int&)", ves_icall_System_Net_Sockets_Socket_GetSocketOption_arr_internal},
5421 {"GetSocketOption_obj_internal(intptr,System.Net.Sockets.SocketOptionLevel,System.Net.Sockets.SocketOptionName,object&,int&)", ves_icall_System_Net_Sockets_Socket_GetSocketOption_obj_internal},
5422 {"GetSupportsAsync", ves_icall_System_IO_MonoIO_GetSupportsAsync},
5423 {"Listen_internal(intptr,int,int&)", ves_icall_System_Net_Sockets_Socket_Listen_internal},
5424 {"LocalEndPoint_internal(intptr,int&)", ves_icall_System_Net_Sockets_Socket_LocalEndPoint_internal},
5425 {"Poll_internal", ves_icall_System_Net_Sockets_Socket_Poll_internal},
5426 {"Receive_internal(intptr,byte[],int,int,System.Net.Sockets.SocketFlags,int&)", ves_icall_System_Net_Sockets_Socket_Receive_internal},
5427 {"RecvFrom_internal(intptr,byte[],int,int,System.Net.Sockets.SocketFlags,System.Net.SocketAddress&,int&)", ves_icall_System_Net_Sockets_Socket_RecvFrom_internal},
5428 {"RemoteEndPoint_internal(intptr,int&)", ves_icall_System_Net_Sockets_Socket_RemoteEndPoint_internal},
5429 {"Select_internal(System.Net.Sockets.Socket[]&,System.Net.Sockets.Socket[]&,System.Net.Sockets.Socket[]&,int,int&)", ves_icall_System_Net_Sockets_Socket_Select_internal},
5430 {"SendTo_internal(intptr,byte[],int,int,System.Net.Sockets.SocketFlags,System.Net.SocketAddress,int&)", ves_icall_System_Net_Sockets_Socket_SendTo_internal},
5431 {"Send_internal(intptr,byte[],int,int,System.Net.Sockets.SocketFlags,int&)", ves_icall_System_Net_Sockets_Socket_Send_internal},
5432 {"SetSocketOption_internal(intptr,System.Net.Sockets.SocketOptionLevel,System.Net.Sockets.SocketOptionName,object,byte[],int,int&)", ves_icall_System_Net_Sockets_Socket_SetSocketOption_internal},
5433 {"Shutdown_internal(intptr,System.Net.Sockets.SocketShutdown,int&)", ves_icall_System_Net_Sockets_Socket_Shutdown_internal},
5434 {"Socket_internal(System.Net.Sockets.AddressFamily,System.Net.Sockets.SocketType,System.Net.Sockets.ProtocolType,int&)", ves_icall_System_Net_Sockets_Socket_Socket_internal},
5435 {"WSAIoctl(intptr,int,byte[],byte[],int&)", ves_icall_System_Net_Sockets_Socket_WSAIoctl}
5438 static const IcallEntry socketex_icalls [] = {
5439 {"WSAGetLastError_internal", ves_icall_System_Net_Sockets_SocketException_WSAGetLastError_internal}
5442 static const IcallEntry object_icalls [] = {
5443 {"GetType", ves_icall_System_Object_GetType},
5444 {"InternalGetHashCode", ves_icall_System_Object_GetHashCode},
5445 {"MemberwiseClone", ves_icall_System_Object_MemberwiseClone},
5446 {"obj_address", ves_icall_System_Object_obj_address}
5449 static const IcallEntry assemblybuilder_icalls[] = {
5450 {"InternalAddModule", mono_image_load_module},
5451 {"basic_init", mono_image_basic_init}
5454 static const IcallEntry customattrbuilder_icalls [] = {
5455 {"GetBlob", mono_reflection_get_custom_attrs_blob}
5458 static const IcallEntry dynamicmethod_icalls [] = {
5459 {"create_dynamic_method", mono_reflection_create_dynamic_method}
5462 static const IcallEntry methodbuilder_icalls [] = {
5463 {"BindGenericParameters", mono_reflection_bind_generic_method_parameters}
5466 static const IcallEntry modulebuilder_icalls [] = {
5467 {"basic_init", mono_image_module_basic_init},
5468 {"build_metadata", ves_icall_ModuleBuilder_build_metadata},
5469 {"create_modified_type", ves_icall_ModuleBuilder_create_modified_type},
5470 {"getDataChunk", ves_icall_ModuleBuilder_getDataChunk},
5471 {"getMethodToken", ves_icall_ModuleBuilder_getMethodToken},
5472 {"getToken", ves_icall_ModuleBuilder_getToken},
5473 {"getUSIndex", mono_image_insert_string}
5476 static const IcallEntry signaturehelper_icalls [] = {
5477 {"get_signature_field", mono_reflection_sighelper_get_signature_field},
5478 {"get_signature_local", mono_reflection_sighelper_get_signature_local}
5481 static const IcallEntry typebuilder_icalls [] = {
5482 {"create_internal_class", mono_reflection_create_internal_class},
5483 {"create_runtime_class", mono_reflection_create_runtime_class},
5484 {"get_IsGenericParameter", ves_icall_TypeBuilder_get_IsGenericParameter},
5485 {"get_event_info", mono_reflection_event_builder_get_event_info},
5486 {"setup_generic_class", mono_reflection_setup_generic_class},
5487 {"setup_internal_class", mono_reflection_setup_internal_class}
5490 static const IcallEntry runtimehelpers_icalls [] = {
5491 {"GetObjectValue", ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetObjectValue},
5492 {"GetOffsetToStringData", ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetOffsetToStringData},
5493 {"InitializeArray", ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_InitializeArray},
5494 {"RunClassConstructor", ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_RunClassConstructor}
5497 static const IcallEntry gchandle_icalls [] = {
5498 {"FreeHandle", ves_icall_System_GCHandle_FreeHandle},
5499 {"GetAddrOfPinnedObject", ves_icall_System_GCHandle_GetAddrOfPinnedObject},
5500 {"GetTarget", ves_icall_System_GCHandle_GetTarget},
5501 {"GetTargetHandle", ves_icall_System_GCHandle_GetTargetHandle}
5504 static const IcallEntry marshal_icalls [] = {
5505 {"AllocCoTaskMem", ves_icall_System_Runtime_InteropServices_Marshal_AllocCoTaskMem},
5506 {"AllocHGlobal", mono_marshal_alloc},
5507 {"DestroyStructure", ves_icall_System_Runtime_InteropServices_Marshal_DestroyStructure},
5508 {"FreeCoTaskMem", ves_icall_System_Runtime_InteropServices_Marshal_FreeCoTaskMem},
5509 {"FreeHGlobal", mono_marshal_free},
5510 {"GetLastWin32Error", ves_icall_System_Runtime_InteropServices_Marshal_GetLastWin32Error},
5511 {"OffsetOf", ves_icall_System_Runtime_InteropServices_Marshal_OffsetOf},
5512 {"Prelink", ves_icall_System_Runtime_InteropServices_Marshal_Prelink},
5513 {"PrelinkAll", ves_icall_System_Runtime_InteropServices_Marshal_PrelinkAll},
5514 {"PtrToStringAnsi(intptr)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi},
5515 {"PtrToStringAnsi(intptr,int)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi_len},
5516 {"PtrToStringAuto(intptr)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi},
5517 {"PtrToStringAuto(intptr,int)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi_len},
5518 {"PtrToStringBSTR", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringBSTR},
5519 {"PtrToStringUni(intptr)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringUni},
5520 {"PtrToStringUni(intptr,int)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringUni_len},
5521 {"PtrToStructure(intptr,System.Type)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStructure_type},
5522 {"PtrToStructure(intptr,object)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStructure},
5523 {"ReAllocHGlobal", mono_marshal_realloc},
5524 {"ReadByte", ves_icall_System_Runtime_InteropServices_Marshal_ReadByte},
5525 {"ReadInt16", ves_icall_System_Runtime_InteropServices_Marshal_ReadInt16},
5526 {"ReadInt32", ves_icall_System_Runtime_InteropServices_Marshal_ReadInt32},
5527 {"ReadInt64", ves_icall_System_Runtime_InteropServices_Marshal_ReadInt64},
5528 {"ReadIntPtr", ves_icall_System_Runtime_InteropServices_Marshal_ReadIntPtr},
5529 {"SizeOf", ves_icall_System_Runtime_InteropServices_Marshal_SizeOf},
5530 {"StringToHGlobalAnsi", ves_icall_System_Runtime_InteropServices_Marshal_StringToHGlobalAnsi},
5531 {"StringToHGlobalAuto", ves_icall_System_Runtime_InteropServices_Marshal_StringToHGlobalAnsi},
5532 {"StringToHGlobalUni", ves_icall_System_Runtime_InteropServices_Marshal_StringToHGlobalUni},
5533 {"StructureToPtr", ves_icall_System_Runtime_InteropServices_Marshal_StructureToPtr},
5534 {"UnsafeAddrOfPinnedArrayElement", ves_icall_System_Runtime_InteropServices_Marshal_UnsafeAddrOfPinnedArrayElement},
5535 {"WriteByte", ves_icall_System_Runtime_InteropServices_Marshal_WriteByte},
5536 {"WriteInt16", ves_icall_System_Runtime_InteropServices_Marshal_WriteInt16},
5537 {"WriteInt32", ves_icall_System_Runtime_InteropServices_Marshal_WriteInt32},
5538 {"WriteInt64", ves_icall_System_Runtime_InteropServices_Marshal_WriteInt64},
5539 {"WriteIntPtr", ves_icall_System_Runtime_InteropServices_Marshal_WriteIntPtr},
5540 {"copy_from_unmanaged", ves_icall_System_Runtime_InteropServices_Marshal_copy_from_unmanaged},
5541 {"copy_to_unmanaged", ves_icall_System_Runtime_InteropServices_Marshal_copy_to_unmanaged}
5544 static const IcallEntry activationservices_icalls [] = {
5545 {"AllocateUninitializedClassInstance", ves_icall_System_Runtime_Activation_ActivationServices_AllocateUninitializedClassInstance},
5546 {"EnableProxyActivation", ves_icall_System_Runtime_Activation_ActivationServices_EnableProxyActivation}
5549 static const IcallEntry monomethodmessage_icalls [] = {
5550 {"InitMessage", ves_icall_MonoMethodMessage_InitMessage}
5553 static const IcallEntry realproxy_icalls [] = {
5554 {"InternalGetProxyType", ves_icall_Remoting_RealProxy_InternalGetProxyType},
5555 {"InternalGetTransparentProxy", ves_icall_Remoting_RealProxy_GetTransparentProxy}
5558 static const IcallEntry remotingservices_icalls [] = {
5559 {"InternalExecute", ves_icall_InternalExecute},
5560 {"IsTransparentProxy", ves_icall_IsTransparentProxy}
5563 static const IcallEntry rng_icalls [] = {
5564 {"RngClose", ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngClose},
5565 {"RngGetBytes", ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngGetBytes},
5566 {"RngInitialize", ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngInitialize}
5569 static const IcallEntry methodhandle_icalls [] = {
5570 {"GetFunctionPointer", ves_icall_RuntimeMethod_GetFunctionPointer}
5573 static const IcallEntry string_icalls [] = {
5574 {".ctor(char*)", ves_icall_System_String_ctor_charp},
5575 {".ctor(char*,int,int)", ves_icall_System_String_ctor_charp_int_int},
5576 {".ctor(char,int)", ves_icall_System_String_ctor_char_int},
5577 {".ctor(char[])", ves_icall_System_String_ctor_chara},
5578 {".ctor(char[],int,int)", ves_icall_System_String_ctor_chara_int_int},
5579 {".ctor(sbyte*)", ves_icall_System_String_ctor_sbytep},
5580 {".ctor(sbyte*,int,int)", ves_icall_System_String_ctor_sbytep_int_int},
5581 {".ctor(sbyte*,int,int,System.Text.Encoding)", ves_icall_System_String_ctor_encoding},
5582 {"GetHashCode", ves_icall_System_String_GetHashCode},
5583 {"InternalAllocateStr", ves_icall_System_String_InternalAllocateStr},
5584 {"InternalCharCopy", ves_icall_System_String_InternalCharCopy},
5585 {"InternalCopyTo", ves_icall_System_String_InternalCopyTo},
5586 {"InternalIndexOfAny", ves_icall_System_String_InternalIndexOfAny},
5587 {"InternalInsert", ves_icall_System_String_InternalInsert},
5588 {"InternalIntern", ves_icall_System_String_InternalIntern},
5589 {"InternalIsInterned", ves_icall_System_String_InternalIsInterned},
5590 {"InternalJoin", ves_icall_System_String_InternalJoin},
5591 {"InternalLastIndexOfAny", ves_icall_System_String_InternalLastIndexOfAny},
5592 {"InternalPad", ves_icall_System_String_InternalPad},
5593 {"InternalRemove", ves_icall_System_String_InternalRemove},
5594 {"InternalReplace(char,char)", ves_icall_System_String_InternalReplace_Char},
5595 {"InternalReplace(string,string,System.Globalization.CompareInfo)", ves_icall_System_String_InternalReplace_Str_Comp},
5596 {"InternalSplit", ves_icall_System_String_InternalSplit},
5597 {"InternalStrcpy(string,int,char[])", ves_icall_System_String_InternalStrcpy_Chars},
5598 {"InternalStrcpy(string,int,char[],int,int)", ves_icall_System_String_InternalStrcpy_CharsN},
5599 {"InternalStrcpy(string,int,string)", ves_icall_System_String_InternalStrcpy_Str},
5600 {"InternalStrcpy(string,int,string,int,int)", ves_icall_System_String_InternalStrcpy_StrN},
5601 {"InternalToLower(System.Globalization.CultureInfo)", ves_icall_System_String_InternalToLower_Comp},
5602 {"InternalToUpper(System.Globalization.CultureInfo)", ves_icall_System_String_InternalToUpper_Comp},
5603 {"InternalTrim", ves_icall_System_String_InternalTrim},
5604 {"get_Chars", ves_icall_System_String_get_Chars}
5607 static const IcallEntry encoding_icalls [] = {
5608 {"InternalCodePage", ves_icall_System_Text_Encoding_InternalCodePage}
5611 static const IcallEntry monitor_icalls [] = {
5612 {"Monitor_exit", ves_icall_System_Threading_Monitor_Monitor_exit},
5613 {"Monitor_pulse", ves_icall_System_Threading_Monitor_Monitor_pulse},
5614 {"Monitor_pulse_all", ves_icall_System_Threading_Monitor_Monitor_pulse_all},
5615 {"Monitor_test_owner", ves_icall_System_Threading_Monitor_Monitor_test_owner},
5616 {"Monitor_test_synchronised", ves_icall_System_Threading_Monitor_Monitor_test_synchronised},
5617 {"Monitor_try_enter", ves_icall_System_Threading_Monitor_Monitor_try_enter},
5618 {"Monitor_wait", ves_icall_System_Threading_Monitor_Monitor_wait}
5621 static const IcallEntry interlocked_icalls [] = {
5622 {"CompareExchange(int&,int,int)", ves_icall_System_Threading_Interlocked_CompareExchange_Int},
5623 {"CompareExchange(object&,object,object)", ves_icall_System_Threading_Interlocked_CompareExchange_Object},
5624 {"CompareExchange(single&,single,single)", ves_icall_System_Threading_Interlocked_CompareExchange_Single},
5625 {"Decrement(int&)", ves_icall_System_Threading_Interlocked_Decrement_Int},
5626 {"Decrement(long&)", ves_icall_System_Threading_Interlocked_Decrement_Long},
5627 {"Exchange(int&,int)", ves_icall_System_Threading_Interlocked_Exchange_Int},
5628 {"Exchange(object&,object)", ves_icall_System_Threading_Interlocked_Exchange_Object},
5629 {"Exchange(single&,single)", ves_icall_System_Threading_Interlocked_Exchange_Single},
5630 {"Increment(int&)", ves_icall_System_Threading_Interlocked_Increment_Int},
5631 {"Increment(long&)", ves_icall_System_Threading_Interlocked_Increment_Long}
5634 static const IcallEntry mutex_icalls [] = {
5635 {"CreateMutex_internal", ves_icall_System_Threading_Mutex_CreateMutex_internal},
5636 {"ReleaseMutex_internal", ves_icall_System_Threading_Mutex_ReleaseMutex_internal}
5639 static const IcallEntry nativeevents_icalls [] = {
5640 {"CloseEvent_internal", ves_icall_System_Threading_Events_CloseEvent_internal},
5641 {"CreateEvent_internal", ves_icall_System_Threading_Events_CreateEvent_internal},
5642 {"ResetEvent_internal", ves_icall_System_Threading_Events_ResetEvent_internal},
5643 {"SetEvent_internal", ves_icall_System_Threading_Events_SetEvent_internal}
5646 static const IcallEntry thread_icalls [] = {
5647 {"Abort_internal(object)", ves_icall_System_Threading_Thread_Abort},
5648 {"CurrentThread_internal", mono_thread_current},
5649 {"GetDomainID", ves_icall_System_Threading_Thread_GetDomainID},
5650 {"GetName_internal", ves_icall_System_Threading_Thread_GetName_internal},
5651 {"Join_internal", ves_icall_System_Threading_Thread_Join_internal},
5652 {"ResetAbort_internal()", ves_icall_System_Threading_Thread_ResetAbort},
5653 {"Resume_internal()", ves_icall_System_Threading_Thread_Resume},
5654 {"SetName_internal", ves_icall_System_Threading_Thread_SetName_internal},
5655 {"Sleep_internal", ves_icall_System_Threading_Thread_Sleep_internal},
5656 {"SlotHash_lookup", ves_icall_System_Threading_Thread_SlotHash_lookup},
5657 {"SlotHash_store", ves_icall_System_Threading_Thread_SlotHash_store},
5658 {"Start_internal", ves_icall_System_Threading_Thread_Start_internal},
5659 {"Suspend_internal", ves_icall_System_Threading_Thread_Suspend},
5660 {"Thread_free_internal", ves_icall_System_Threading_Thread_Thread_free_internal},
5661 {"Thread_internal", ves_icall_System_Threading_Thread_Thread_internal},
5662 {"VolatileRead(byte&)", ves_icall_System_Threading_Thread_VolatileRead1},
5663 {"VolatileRead(double&)", ves_icall_System_Threading_Thread_VolatileRead8},
5664 {"VolatileRead(int&)", ves_icall_System_Threading_Thread_VolatileRead4},
5665 {"VolatileRead(int16&)", ves_icall_System_Threading_Thread_VolatileRead2},
5666 {"VolatileRead(intptr&)", ves_icall_System_Threading_Thread_VolatileReadIntPtr},
5667 {"VolatileRead(long&)", ves_icall_System_Threading_Thread_VolatileRead8},
5668 {"VolatileRead(object&)", ves_icall_System_Threading_Thread_VolatileReadIntPtr},
5669 {"VolatileRead(sbyte&)", ves_icall_System_Threading_Thread_VolatileRead1},
5670 {"VolatileRead(single&)", ves_icall_System_Threading_Thread_VolatileRead4},
5671 {"VolatileRead(uint&)", ves_icall_System_Threading_Thread_VolatileRead2},
5672 {"VolatileRead(uint16&)", ves_icall_System_Threading_Thread_VolatileRead2},
5673 {"VolatileRead(uintptr&)", ves_icall_System_Threading_Thread_VolatileReadIntPtr},
5674 {"VolatileRead(ulong&)", ves_icall_System_Threading_Thread_VolatileRead8},
5675 {"VolatileWrite(byte&,byte)", ves_icall_System_Threading_Thread_VolatileWrite1},
5676 {"VolatileWrite(double&,double)", ves_icall_System_Threading_Thread_VolatileWrite8},
5677 {"VolatileWrite(int&,int)", ves_icall_System_Threading_Thread_VolatileWrite4},
5678 {"VolatileWrite(int16&,int16)", ves_icall_System_Threading_Thread_VolatileWrite2},
5679 {"VolatileWrite(intptr&,intptr)", ves_icall_System_Threading_Thread_VolatileWriteIntPtr},
5680 {"VolatileWrite(long&,long)", ves_icall_System_Threading_Thread_VolatileWrite8},
5681 {"VolatileWrite(object&,object)", ves_icall_System_Threading_Thread_VolatileWriteIntPtr},
5682 {"VolatileWrite(sbyte&,sbyte)", ves_icall_System_Threading_Thread_VolatileWrite1},
5683 {"VolatileWrite(single&,single)", ves_icall_System_Threading_Thread_VolatileWrite4},
5684 {"VolatileWrite(uint&,uint)", ves_icall_System_Threading_Thread_VolatileWrite2},
5685 {"VolatileWrite(uint16&,uint16)", ves_icall_System_Threading_Thread_VolatileWrite2},
5686 {"VolatileWrite(uintptr&,uintptr)", ves_icall_System_Threading_Thread_VolatileWriteIntPtr},
5687 {"VolatileWrite(ulong&,ulong)", ves_icall_System_Threading_Thread_VolatileWrite8},
5688 {"current_lcid()", ves_icall_System_Threading_Thread_current_lcid}
5691 static const IcallEntry threadpool_icalls [] = {
5692 {"BindHandleInternal", ves_icall_System_Threading_ThreadPool_BindHandle},
5693 {"GetAvailableThreads", ves_icall_System_Threading_ThreadPool_GetAvailableThreads},
5694 {"GetMaxThreads", ves_icall_System_Threading_ThreadPool_GetMaxThreads},
5695 {"GetMinThreads", ves_icall_System_Threading_ThreadPool_GetMinThreads},
5696 {"SetMinThreads", ves_icall_System_Threading_ThreadPool_SetMinThreads}
5699 static const IcallEntry waithandle_icalls [] = {
5700 {"WaitAll_internal", ves_icall_System_Threading_WaitHandle_WaitAll_internal},
5701 {"WaitAny_internal", ves_icall_System_Threading_WaitHandle_WaitAny_internal},
5702 {"WaitOne_internal", ves_icall_System_Threading_WaitHandle_WaitOne_internal}
5705 static const IcallEntry type_icalls [] = {
5706 {"BindGenericParameters", ves_icall_Type_BindGenericParameters},
5707 {"Equals", ves_icall_type_Equals},
5708 {"GetGenericParameterPosition", ves_icall_Type_GetGenericParameterPosition},
5709 {"GetGenericTypeDefinition_impl", ves_icall_Type_GetGenericTypeDefinition_impl},
5710 {"GetInterfaceMapData", ves_icall_Type_GetInterfaceMapData},
5711 {"GetTypeCode", ves_icall_type_GetTypeCode},
5712 {"IsArrayImpl", ves_icall_Type_IsArrayImpl},
5713 {"IsInstanceOfType", ves_icall_type_IsInstanceOfType},
5714 {"get_IsGenericInstance", ves_icall_Type_get_IsGenericInstance},
5715 {"get_IsGenericTypeDefinition", ves_icall_Type_get_IsGenericTypeDefinition},
5716 {"internal_from_handle", ves_icall_type_from_handle},
5717 {"internal_from_name", ves_icall_type_from_name},
5718 {"make_array_type", ves_icall_Type_make_array_type},
5719 {"make_byref_type", ves_icall_Type_make_byref_type},
5720 {"type_is_assignable_from", ves_icall_type_is_assignable_from},
5721 {"type_is_subtype_of", ves_icall_type_is_subtype_of}
5724 static const IcallEntry typedref_icalls [] = {
5725 {"ToObject", mono_TypedReference_ToObject}
5728 static const IcallEntry valuetype_icalls [] = {
5729 {"InternalEquals", ves_icall_System_ValueType_Equals},
5730 {"InternalGetHashCode", ves_icall_System_ValueType_InternalGetHashCode}
5733 static const IcallEntry web_icalls [] = {
5734 {"GetMachineConfigPath", ves_icall_System_Configuration_DefaultConfig_get_machine_config_path},
5735 {"GetMachineInstallDirectory", ves_icall_System_Web_Util_ICalls_get_machine_install_dir}
5738 static const IcallEntry identity_icalls [] = {
5739 {"GetCurrentToken", ves_icall_System_Security_Principal_WindowsIdentity_GetCurrentToken},
5740 {"GetTokenName", ves_icall_System_Security_Principal_WindowsIdentity_GetTokenName},
5741 {"GetUserToken", ves_icall_System_Security_Principal_WindowsIdentity_GetUserToken},
5742 {"_GetRoles", ves_icall_System_Security_Principal_WindowsIdentity_GetRoles}
5745 static const IcallEntry impersonation_icalls [] = {
5746 {"CloseToken", ves_icall_System_Security_Principal_WindowsImpersonationContext_CloseToken},
5747 {"DuplicateToken", ves_icall_System_Security_Principal_WindowsImpersonationContext_DuplicateToken},
5748 {"RevertToSelf", ves_icall_System_Security_Principal_WindowsImpersonationContext_RevertToSelf},
5749 {"SetCurrentToken", ves_icall_System_Security_Principal_WindowsImpersonationContext_SetCurrentToken}
5752 static const IcallEntry principal_icalls [] = {
5753 {"IsMemberOfGroupId", ves_icall_System_Security_Principal_WindowsPrincipal_IsMemberOfGroupId},
5754 {"IsMemberOfGroupName", ves_icall_System_Security_Principal_WindowsPrincipal_IsMemberOfGroupName}
5757 static const IcallEntry keypair_icalls [] = {
5758 {"_CanSecure", ves_icall_Mono_Security_Cryptography_KeyPairPersistence_CanSecure},
5759 {"_IsMachineProtected", ves_icall_Mono_Security_Cryptography_KeyPairPersistence_IsMachineProtected},
5760 {"_IsUserProtected", ves_icall_Mono_Security_Cryptography_KeyPairPersistence_IsUserProtected},
5761 {"_ProtectMachine", ves_icall_Mono_Security_Cryptography_KeyPairPersistence_ProtectMachine},
5762 {"_ProtectUser", ves_icall_Mono_Security_Cryptography_KeyPairPersistence_ProtectUser}
5766 static const IcallEntry array_icalls [] = {
5771 /* keep the entries all sorted */
5772 static const IcallMap icall_entries [] = {
5773 {"Mono.Security.Cryptography.KeyPairPersistence", keypair_icalls, G_N_ELEMENTS (keypair_icalls)},
5774 {"System.Activator", activator_icalls, G_N_ELEMENTS (activator_icalls)},
5775 {"System.AppDomain", appdomain_icalls, G_N_ELEMENTS (appdomain_icalls)},
5776 {"System.ArgIterator", argiterator_icalls, G_N_ELEMENTS (argiterator_icalls)},
5777 {"System.Array", array_icalls, G_N_ELEMENTS (array_icalls)},
5778 {"System.Buffer", buffer_icalls, G_N_ELEMENTS (buffer_icalls)},
5779 {"System.Char", char_icalls, G_N_ELEMENTS (char_icalls)},
5780 {"System.Configuration.DefaultConfig", defaultconf_icalls, G_N_ELEMENTS (defaultconf_icalls)},
5781 {"System.CurrentTimeZone", timezone_icalls, G_N_ELEMENTS (timezone_icalls)},
5782 {"System.DateTime", datetime_icalls, G_N_ELEMENTS (datetime_icalls)},
5783 {"System.Decimal", decimal_icalls, G_N_ELEMENTS (decimal_icalls)},
5784 {"System.Delegate", delegate_icalls, G_N_ELEMENTS (delegate_icalls)},
5785 {"System.Diagnostics.DefaultTraceListener", tracelist_icalls, G_N_ELEMENTS (tracelist_icalls)},
5786 {"System.Diagnostics.FileVersionInfo", fileversion_icalls, G_N_ELEMENTS (fileversion_icalls)},
5787 {"System.Diagnostics.Process", process_icalls, G_N_ELEMENTS (process_icalls)},
5788 {"System.Double", double_icalls, G_N_ELEMENTS (double_icalls)},
5789 {"System.Enum", enum_icalls, G_N_ELEMENTS (enum_icalls)},
5790 {"System.Environment", environment_icalls, G_N_ELEMENTS (environment_icalls)},
5791 {"System.GC", gc_icalls, G_N_ELEMENTS (gc_icalls)},
5792 {"System.Globalization.CompareInfo", compareinfo_icalls, G_N_ELEMENTS (compareinfo_icalls)},
5793 {"System.Globalization.CultureInfo", cultureinfo_icalls, G_N_ELEMENTS (cultureinfo_icalls)},
5794 {"System.IO.FAMWatcher", famwatcher_icalls, G_N_ELEMENTS (famwatcher_icalls)},
5795 {"System.IO.FileSystemWatcher", filewatcher_icalls, G_N_ELEMENTS (filewatcher_icalls)},
5796 {"System.IO.MonoIO", monoio_icalls, G_N_ELEMENTS (monoio_icalls)},
5797 {"System.IO.Path", path_icalls, G_N_ELEMENTS (path_icalls)},
5798 {"System.Math", math_icalls, G_N_ELEMENTS (math_icalls)},
5799 {"System.MonoCustomAttrs", customattrs_icalls, G_N_ELEMENTS (customattrs_icalls)},
5800 {"System.MonoEnumInfo", enuminfo_icalls, G_N_ELEMENTS (enuminfo_icalls)},
5801 {"System.MonoType", monotype_icalls, G_N_ELEMENTS (monotype_icalls)},
5802 {"System.Net.Dns", dns_icalls, G_N_ELEMENTS (dns_icalls)},
5803 {"System.Net.Sockets.Socket", socket_icalls, G_N_ELEMENTS (socket_icalls)},
5804 {"System.Net.Sockets.SocketException", socketex_icalls, G_N_ELEMENTS (socketex_icalls)},
5805 {"System.Object", object_icalls, G_N_ELEMENTS (object_icalls)},
5806 {"System.Reflection.Assembly", assembly_icalls, G_N_ELEMENTS (assembly_icalls)},
5807 {"System.Reflection.Emit.AssemblyBuilder", assemblybuilder_icalls, G_N_ELEMENTS (assemblybuilder_icalls)},
5808 {"System.Reflection.Emit.CustomAttributeBuilder", customattrbuilder_icalls, G_N_ELEMENTS (customattrbuilder_icalls)},
5809 {"System.Reflection.Emit.DynamicMethod", dynamicmethod_icalls, G_N_ELEMENTS (dynamicmethod_icalls)},
5810 {"System.Reflection.Emit.GenericTypeParameterBuilder", generictypeparambuilder_icalls, G_N_ELEMENTS (generictypeparambuilder_icalls)},
5811 {"System.Reflection.Emit.MethodBuilder", methodbuilder_icalls, G_N_ELEMENTS (methodbuilder_icalls)},
5812 {"System.Reflection.Emit.ModuleBuilder", modulebuilder_icalls, G_N_ELEMENTS (modulebuilder_icalls)},
5813 {"System.Reflection.Emit.SignatureHelper", signaturehelper_icalls, G_N_ELEMENTS (signaturehelper_icalls)},
5814 {"System.Reflection.Emit.TypeBuilder", typebuilder_icalls, G_N_ELEMENTS (typebuilder_icalls)},
5815 {"System.Reflection.FieldInfo", fieldinfo_icalls, G_N_ELEMENTS (fieldinfo_icalls)},
5816 {"System.Reflection.MethodBase", methodbase_icalls, G_N_ELEMENTS (methodbase_icalls)},
5817 {"System.Reflection.Module", module_icalls, G_N_ELEMENTS (module_icalls)},
5818 {"System.Reflection.MonoCMethod", monocmethod_icalls, G_N_ELEMENTS (monocmethod_icalls)},
5819 {"System.Reflection.MonoEventInfo", monoeventinfo_icalls, G_N_ELEMENTS (monoeventinfo_icalls)},
5820 {"System.Reflection.MonoField", monofield_icalls, G_N_ELEMENTS (monofield_icalls)},
5821 {"System.Reflection.MonoGenericInst", monogenericinst_icalls, G_N_ELEMENTS (monogenericinst_icalls)},
5822 {"System.Reflection.MonoMethod", monomethod_icalls, G_N_ELEMENTS (monomethod_icalls)},
5823 {"System.Reflection.MonoMethodInfo", monomethodinfo_icalls, G_N_ELEMENTS (monomethodinfo_icalls)},
5824 {"System.Reflection.MonoPropertyInfo", monopropertyinfo_icalls, G_N_ELEMENTS (monopropertyinfo_icalls)},
5825 {"System.Runtime.CompilerServices.RuntimeHelpers", runtimehelpers_icalls, G_N_ELEMENTS (runtimehelpers_icalls)},
5826 {"System.Runtime.InteropServices.GCHandle", gchandle_icalls, G_N_ELEMENTS (gchandle_icalls)},
5827 {"System.Runtime.InteropServices.Marshal", marshal_icalls, G_N_ELEMENTS (marshal_icalls)},
5828 {"System.Runtime.Remoting.Activation.ActivationServices", activationservices_icalls, G_N_ELEMENTS (activationservices_icalls)},
5829 {"System.Runtime.Remoting.Messaging.MonoMethodMessage", monomethodmessage_icalls, G_N_ELEMENTS (monomethodmessage_icalls)},
5830 {"System.Runtime.Remoting.Proxies.RealProxy", realproxy_icalls, G_N_ELEMENTS (realproxy_icalls)},
5831 {"System.Runtime.Remoting.RemotingServices", remotingservices_icalls, G_N_ELEMENTS (remotingservices_icalls)},
5832 {"System.RuntimeMethodHandle", methodhandle_icalls, G_N_ELEMENTS (methodhandle_icalls)},
5833 {"System.Security.Cryptography.RNGCryptoServiceProvider", rng_icalls, G_N_ELEMENTS (rng_icalls)},
5834 {"System.Security.Principal.WindowsIdentity", identity_icalls, G_N_ELEMENTS (identity_icalls)},
5835 {"System.Security.Principal.WindowsImpersonationContext", impersonation_icalls, G_N_ELEMENTS (impersonation_icalls)},
5836 {"System.Security.Principal.WindowsPrincipal", principal_icalls, G_N_ELEMENTS (principal_icalls)},
5837 {"System.String", string_icalls, G_N_ELEMENTS (string_icalls)},
5838 {"System.Text.Encoding", encoding_icalls, G_N_ELEMENTS (encoding_icalls)},
5839 {"System.Threading.Interlocked", interlocked_icalls, G_N_ELEMENTS (interlocked_icalls)},
5840 {"System.Threading.Monitor", monitor_icalls, G_N_ELEMENTS (monitor_icalls)},
5841 {"System.Threading.Mutex", mutex_icalls, G_N_ELEMENTS (mutex_icalls)},
5842 {"System.Threading.NativeEventCalls", nativeevents_icalls, G_N_ELEMENTS (nativeevents_icalls)},
5843 {"System.Threading.Thread", thread_icalls, G_N_ELEMENTS (thread_icalls)},
5844 {"System.Threading.ThreadPool", threadpool_icalls, G_N_ELEMENTS (threadpool_icalls)},
5845 {"System.Threading.WaitHandle", waithandle_icalls, G_N_ELEMENTS (waithandle_icalls)},
5846 {"System.Type", type_icalls, G_N_ELEMENTS (type_icalls)},
5847 {"System.TypedReference", typedref_icalls, G_N_ELEMENTS (typedref_icalls)},
5848 {"System.ValueType", valuetype_icalls, G_N_ELEMENTS (valuetype_icalls)},
5849 {"System.Web.Util.ICalls", web_icalls, G_N_ELEMENTS (web_icalls)}
5852 static GHashTable *icall_hash = NULL;
5855 mono_init_icall (void)
5859 /* check that tables are sorted: disable in release */
5862 const IcallMap *imap;
5863 const IcallEntry *ientry;
5864 const char *prev_class = NULL;
5865 const char *prev_method;
5867 for (i = 0; i < G_N_ELEMENTS (icall_entries); ++i) {
5868 imap = &icall_entries [i];
5870 if (prev_class && strcmp (prev_class, imap->klass) >= 0)
5871 g_print ("class %s should come before class %s\n", imap->klass, prev_class);
5872 prev_class = imap->klass;
5873 for (j = 0; j < imap->size; ++j) {
5874 ientry = &imap->icalls [j];
5875 if (prev_method && strcmp (prev_method, ientry->method) >= 0)
5876 g_print ("method %s should come before method %s\n", ientry->method, prev_method);
5877 prev_method = ientry->method;
5882 icall_hash = g_hash_table_new (g_str_hash , g_str_equal);
5886 mono_add_internal_call (const char *name, gconstpointer method)
5888 mono_loader_lock ();
5890 g_hash_table_insert (icall_hash, g_strdup (name), (gpointer) method);
5892 mono_loader_unlock ();
5896 compare_class_imap (const void *key, const void *elem)
5898 const IcallMap* imap = (const IcallMap*)elem;
5899 return strcmp (key, imap->klass);
5902 static const IcallMap*
5903 find_class_icalls (const char *name)
5905 return (const IcallMap*) bsearch (name, icall_entries, G_N_ELEMENTS (icall_entries), sizeof (IcallMap), compare_class_imap);
5909 compare_method_imap (const void *key, const void *elem)
5911 const IcallEntry* ientry = (const IcallEntry*)elem;
5912 return strcmp (key, ientry->method);
5916 find_method_icall (const IcallMap *imap, const char *name)
5918 const IcallEntry *ientry = (const IcallEntry*) bsearch (name, imap->icalls, imap->size, sizeof (IcallEntry), compare_method_imap);
5920 return (void*)ientry->func;
5925 * we should probably export this as an helper (handle nested types).
5926 * Returns the number of chars written in buf.
5929 concat_class_name (char *buf, int bufsize, MonoClass *klass)
5931 int nspacelen, cnamelen;
5932 nspacelen = strlen (klass->name_space);
5933 cnamelen = strlen (klass->name);
5934 if (nspacelen + cnamelen + 2 > bufsize)
5937 memcpy (buf, klass->name_space, nspacelen);
5938 buf [nspacelen ++] = '.';
5940 memcpy (buf + nspacelen, klass->name, cnamelen);
5941 buf [nspacelen + cnamelen] = 0;
5942 return nspacelen + cnamelen;
5946 mono_lookup_internal_call (MonoMethod *method)
5951 int typelen = 0, mlen, siglen;
5953 const IcallMap *imap;
5955 g_assert (method != NULL);
5957 typelen = concat_class_name (mname, sizeof (mname), method->klass);
5961 imap = find_class_icalls (mname);
5963 mname [typelen] = ':';
5964 mname [typelen + 1] = ':';
5966 mlen = strlen (method->name);
5967 memcpy (mname + typelen + 2, method->name, mlen);
5968 sigstart = mname + typelen + 2 + mlen;
5971 tmpsig = mono_signature_get_desc (method->signature, TRUE);
5972 siglen = strlen (tmpsig);
5973 if (typelen + mlen + siglen + 6 > sizeof (mname))
5976 memcpy (sigstart + 1, tmpsig, siglen);
5977 sigstart [siglen + 1] = ')';
5978 sigstart [siglen + 2] = 0;
5981 mono_loader_lock ();
5983 res = g_hash_table_lookup (icall_hash, mname);
5985 mono_loader_unlock ();
5988 /* try without signature */
5990 res = g_hash_table_lookup (icall_hash, mname);
5992 mono_loader_unlock ();
5996 /* it wasn't found in the static call tables */
5998 mono_loader_unlock ();
6001 res = find_method_icall (imap, sigstart - mlen);
6003 mono_loader_unlock ();
6006 /* try _with_ signature */
6008 res = find_method_icall (imap, sigstart - mlen);
6010 mono_loader_unlock ();
6014 g_warning ("cant resolve internal call to \"%s\" (tested without signature also)", mname);
6015 g_print ("\nYour mono runtime and class libraries are out of sync.\n");
6016 g_print ("The out of sync library is: %s\n", method->klass->image->name);
6017 g_print ("\nWhen you update one from cvs you need to update, compile and install\nthe other too.\n");
6018 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");
6019 g_print ("If you see other errors or faults after this message they are probably related\n");
6020 g_print ("and you need to fix your mono install first.\n");
6022 mono_loader_unlock ();