5 * Dietmar Maurer (dietmar@ximian.com)
6 * Paolo Molaro (lupus@ximian.com)
7 * Patrik Torstensson (patrik.torstensson@labs2.com)
9 * (C) 2001 Ximian, Inc.
19 #if defined (PLATFORM_WIN32)
23 #include <mono/metadata/object.h>
24 #include <mono/metadata/threads.h>
25 #include <mono/metadata/threadpool.h>
26 #include <mono/metadata/monitor.h>
27 #include <mono/metadata/reflection.h>
28 #include <mono/metadata/assembly.h>
29 #include <mono/metadata/tabledefs.h>
30 #include <mono/metadata/exception.h>
31 #include <mono/metadata/file-io.h>
32 #include <mono/metadata/socket-io.h>
33 #include <mono/metadata/mono-endian.h>
34 #include <mono/metadata/tokentype.h>
35 #include <mono/metadata/unicode.h>
36 #include <mono/metadata/appdomain.h>
37 #include <mono/metadata/marshal.h>
38 #include <mono/metadata/gc-internal.h>
39 #include <mono/metadata/rand.h>
40 #include <mono/metadata/sysmath.h>
41 #include <mono/metadata/string-icalls.h>
42 #include <mono/metadata/mono-debug-debugger.h>
43 #include <mono/metadata/process.h>
44 #include <mono/metadata/environment.h>
45 #include <mono/metadata/profiler-private.h>
46 #include <mono/metadata/locales.h>
47 #include <mono/metadata/filewatcher.h>
48 #include <mono/metadata/char-conversions.h>
49 #include <mono/metadata/security.h>
50 #include <mono/metadata/mono-config.h>
51 #include <mono/io-layer/io-layer.h>
52 #include <mono/utils/strtod.h>
53 #include <mono/utils/monobitset.h>
55 #if defined (PLATFORM_WIN32)
61 static MonoReflectionAssembly* ves_icall_System_Reflection_Assembly_GetCallingAssembly (void);
65 * We expect a pointer to a char, not a string
68 mono_double_ParseImpl (char *ptr)
76 result = bsd_strtod (ptr, &endptr);
78 if (!*ptr || (endptr && *endptr))
79 mono_raise_exception (mono_exception_from_name (mono_defaults.corlib,
87 ves_icall_System_Double_AssertEndianity (double *value)
91 MONO_DOUBLE_ASSERT_ENDIANITY (value);
95 ves_icall_System_Array_GetValueImpl (MonoObject *this, guint32 pos)
104 ao = (MonoArray *)this;
105 ac = (MonoClass *)ao->obj.vtable->klass;
107 esize = mono_array_element_size (ac);
108 ea = (gpointer*)((char*)ao->vector + (pos * esize));
110 if (ac->element_class->valuetype)
111 return mono_value_box (this->vtable->domain, ac->element_class, ea);
117 ves_icall_System_Array_GetValue (MonoObject *this, MonoObject *idxs)
125 MONO_CHECK_ARG_NULL (idxs);
127 io = (MonoArray *)idxs;
128 ic = (MonoClass *)io->obj.vtable->klass;
130 ao = (MonoArray *)this;
131 ac = (MonoClass *)ao->obj.vtable->klass;
133 g_assert (ic->rank == 1);
134 if (io->bounds != NULL || io->max_length != ac->rank)
135 mono_raise_exception (mono_get_exception_argument (NULL, NULL));
137 ind = (guint32 *)io->vector;
139 if (ao->bounds == NULL) {
140 if (*ind < 0 || *ind >= ao->max_length)
141 mono_raise_exception (mono_get_exception_index_out_of_range ());
143 return ves_icall_System_Array_GetValueImpl (this, *ind);
146 for (i = 0; i < ac->rank; i++)
147 if ((ind [i] < ao->bounds [i].lower_bound) ||
148 (ind [i] >= ao->bounds [i].length + ao->bounds [i].lower_bound))
149 mono_raise_exception (mono_get_exception_index_out_of_range ());
151 pos = ind [0] - ao->bounds [0].lower_bound;
152 for (i = 1; i < ac->rank; i++)
153 pos = pos*ao->bounds [i].length + ind [i] -
154 ao->bounds [i].lower_bound;
156 return ves_icall_System_Array_GetValueImpl (this, pos);
160 ves_icall_System_Array_SetValueImpl (MonoArray *this, MonoObject *value, guint32 pos)
162 MonoClass *ac, *vc, *ec;
173 vc = value->vtable->klass;
177 ac = this->obj.vtable->klass;
178 ec = ac->element_class;
180 esize = mono_array_element_size (ac);
181 ea = (gpointer*)((char*)this->vector + (pos * esize));
182 va = (gpointer*)((char*)value + sizeof (MonoObject));
185 memset (ea, 0, esize);
189 #define NO_WIDENING_CONVERSION G_STMT_START{\
190 mono_raise_exception (mono_get_exception_argument ( \
191 "value", "not a widening conversion")); \
194 #define CHECK_WIDENING_CONVERSION(extra) G_STMT_START{\
195 if (esize < vsize + (extra)) \
196 mono_raise_exception (mono_get_exception_argument ( \
197 "value", "not a widening conversion")); \
200 #define INVALID_CAST G_STMT_START{\
201 mono_raise_exception (mono_get_exception_invalid_cast ()); \
204 /* Check element (destination) type. */
205 switch (ec->byval_arg.type) {
206 case MONO_TYPE_STRING:
207 switch (vc->byval_arg.type) {
208 case MONO_TYPE_STRING:
214 case MONO_TYPE_BOOLEAN:
215 switch (vc->byval_arg.type) {
216 case MONO_TYPE_BOOLEAN:
229 NO_WIDENING_CONVERSION;
236 if (!ec->valuetype) {
237 if (!mono_object_isinst (value, ec))
239 *ea = (gpointer)value;
243 if (mono_object_isinst (value, ec)) {
244 memcpy (ea, (char *)value + sizeof (MonoObject), esize);
251 vsize = mono_class_instance_size (vc) - sizeof (MonoObject);
254 g_message (G_STRLOC ": %d (%d) <= %d (%d)",
255 ec->byval_arg.type, esize,
256 vc->byval_arg.type, vsize);
259 #define ASSIGN_UNSIGNED(etype) G_STMT_START{\
260 switch (vc->byval_arg.type) { \
265 case MONO_TYPE_CHAR: \
266 CHECK_WIDENING_CONVERSION(0); \
267 *(etype *) ea = (etype) u64; \
269 /* You can't assign a signed value to an unsigned array. */ \
274 /* You can't assign a floating point number to an integer array. */ \
277 NO_WIDENING_CONVERSION; \
281 #define ASSIGN_SIGNED(etype) G_STMT_START{\
282 switch (vc->byval_arg.type) { \
287 CHECK_WIDENING_CONVERSION(0); \
288 *(etype *) ea = (etype) i64; \
290 /* You can assign an unsigned value to a signed array if the array's */ \
291 /* element size is larger than the value size. */ \
296 case MONO_TYPE_CHAR: \
297 CHECK_WIDENING_CONVERSION(1); \
298 *(etype *) ea = (etype) u64; \
300 /* You can't assign a floating point number to an integer array. */ \
303 NO_WIDENING_CONVERSION; \
307 #define ASSIGN_REAL(etype) G_STMT_START{\
308 switch (vc->byval_arg.type) { \
311 CHECK_WIDENING_CONVERSION(0); \
312 *(etype *) ea = (etype) r64; \
314 /* All integer values fit into a floating point array, so we don't */ \
315 /* need to CHECK_WIDENING_CONVERSION here. */ \
320 *(etype *) ea = (etype) i64; \
326 case MONO_TYPE_CHAR: \
327 *(etype *) ea = (etype) u64; \
332 switch (vc->byval_arg.type) {
334 u64 = *(guint8 *) va;
337 u64 = *(guint16 *) va;
340 u64 = *(guint32 *) va;
343 u64 = *(guint64 *) va;
349 i64 = *(gint16 *) va;
352 i64 = *(gint32 *) va;
355 i64 = *(gint64 *) va;
358 r64 = *(gfloat *) va;
361 r64 = *(gdouble *) va;
364 u64 = *(guint16 *) va;
366 case MONO_TYPE_BOOLEAN:
367 /* Boolean is only compatible with itself. */
368 switch (ec->byval_arg.type) {
380 NO_WIDENING_CONVERSION;
387 /* If we can't do a direct copy, let's try a widening conversion. */
388 switch (ec->byval_arg.type) {
390 ASSIGN_UNSIGNED (guint16);
392 ASSIGN_UNSIGNED (guint8);
394 ASSIGN_UNSIGNED (guint16);
396 ASSIGN_UNSIGNED (guint32);
398 ASSIGN_UNSIGNED (guint64);
400 ASSIGN_SIGNED (gint8);
402 ASSIGN_SIGNED (gint16);
404 ASSIGN_SIGNED (gint32);
406 ASSIGN_SIGNED (gint64);
408 ASSIGN_REAL (gfloat);
410 ASSIGN_REAL (gdouble);
414 /* Not reached, INVALID_CAST does not return. Just to avoid a compiler warning ... */
418 #undef NO_WIDENING_CONVERSION
419 #undef CHECK_WIDENING_CONVERSION
420 #undef ASSIGN_UNSIGNED
426 ves_icall_System_Array_SetValue (MonoArray *this, MonoObject *value,
434 MONO_CHECK_ARG_NULL (idxs);
436 ic = idxs->obj.vtable->klass;
437 ac = this->obj.vtable->klass;
439 g_assert (ic->rank == 1);
440 if (idxs->bounds != NULL || idxs->max_length != ac->rank)
441 mono_raise_exception (mono_get_exception_argument (NULL, NULL));
443 ind = (guint32 *)idxs->vector;
445 if (this->bounds == NULL) {
446 if (*ind < 0 || *ind >= this->max_length)
447 mono_raise_exception (mono_get_exception_index_out_of_range ());
449 ves_icall_System_Array_SetValueImpl (this, value, *ind);
453 for (i = 0; i < ac->rank; i++)
454 if ((ind [i] < this->bounds [i].lower_bound) ||
455 (ind [i] >= this->bounds [i].length + this->bounds [i].lower_bound))
456 mono_raise_exception (mono_get_exception_index_out_of_range ());
458 pos = ind [0] - this->bounds [0].lower_bound;
459 for (i = 1; i < ac->rank; i++)
460 pos = pos * this->bounds [i].length + ind [i] -
461 this->bounds [i].lower_bound;
463 ves_icall_System_Array_SetValueImpl (this, value, pos);
467 ves_icall_System_Array_CreateInstanceImpl (MonoReflectionType *type, MonoArray *lengths, MonoArray *bounds)
472 gboolean bounded = FALSE;
476 MONO_CHECK_ARG_NULL (type);
477 MONO_CHECK_ARG_NULL (lengths);
479 MONO_CHECK_ARG (lengths, mono_array_length (lengths) > 0);
481 MONO_CHECK_ARG (bounds, mono_array_length (lengths) == mono_array_length (bounds));
483 for (i = 0; i < mono_array_length (lengths); i++)
484 if (mono_array_get (lengths, gint32, i) < 0)
485 mono_raise_exception (mono_get_exception_argument_out_of_range (NULL));
487 if (bounds && (mono_array_length (bounds) == 1) && (mono_array_get (bounds, gint32, 0) != 0))
488 /* vectors are not the same as one dimensional arrays with no-zero bounds */
493 aklass = mono_bounded_array_class_get (mono_class_from_mono_type (type->type), mono_array_length (lengths), bounded);
495 sizes = alloca (aklass->rank * sizeof(guint32) * 2);
496 for (i = 0; i < aklass->rank; ++i) {
497 sizes [i] = mono_array_get (lengths, gint32, i);
499 sizes [i + aklass->rank] = mono_array_get (bounds, gint32, i);
501 sizes [i + aklass->rank] = 0;
504 array = mono_array_new_full (mono_object_domain (type), aklass, sizes, sizes + aklass->rank);
510 ves_icall_System_Array_GetRank (MonoObject *this)
514 return this->vtable->klass->rank;
518 ves_icall_System_Array_GetLength (MonoArray *this, gint32 dimension)
520 gint32 rank = ((MonoObject *)this)->vtable->klass->rank;
524 if ((dimension < 0) || (dimension >= rank))
525 mono_raise_exception (mono_get_exception_index_out_of_range ());
527 if (this->bounds == NULL)
528 return this->max_length;
530 return this->bounds [dimension].length;
534 ves_icall_System_Array_GetLowerBound (MonoArray *this, gint32 dimension)
536 gint32 rank = ((MonoObject *)this)->vtable->klass->rank;
540 if ((dimension < 0) || (dimension >= rank))
541 mono_raise_exception (mono_get_exception_index_out_of_range ());
543 if (this->bounds == NULL)
546 return this->bounds [dimension].lower_bound;
550 ves_icall_System_Array_FastCopy (MonoArray *source, int source_idx, MonoArray* dest, int dest_idx, int length)
555 MonoClass *src_class;
556 MonoClass *dest_class;
561 if (source->obj.vtable->klass->rank != dest->obj.vtable->klass->rank)
564 if (source->bounds || dest->bounds)
567 if ((dest_idx + length > mono_array_length (dest)) ||
568 (source_idx + length > mono_array_length (source)))
571 element_size = mono_array_element_size (source->obj.vtable->klass);
572 dest_addr = mono_array_addr_with_size (dest, element_size, dest_idx);
573 source_addr = mono_array_addr_with_size (source, element_size, source_idx);
575 src_class = source->obj.vtable->klass->element_class;
576 dest_class = dest->obj.vtable->klass->element_class;
579 * Handle common cases.
582 /* Case1: object[] -> valuetype[] (ArrayList::ToArray) */
583 if (src_class == mono_defaults.object_class && dest_class->valuetype) {
584 for (i = source_idx; i < source_idx + length; ++i) {
585 MonoObject *elem = mono_array_get (source, MonoObject*, i);
586 if (elem && !mono_object_isinst (elem, dest_class))
590 element_size = mono_array_element_size (dest->obj.vtable->klass);
591 for (i = 0; i < length; ++i) {
592 MonoObject *elem = mono_array_get (source, MonoObject*, source_idx + i);
593 void *addr = mono_array_addr_with_size (dest, element_size, dest_idx + i);
595 memset (addr, 0, element_size);
597 memcpy (addr, (char *)elem + sizeof (MonoObject), element_size);
602 if (src_class != dest_class) {
603 if (dest_class->valuetype || dest_class->enumtype || src_class->valuetype || src_class->enumtype)
606 if (mono_class_is_subclass_of (src_class, dest_class, FALSE))
608 /* Case2: object[] -> reftype[] (ArrayList::ToArray) */
609 else if (mono_class_is_subclass_of (dest_class, src_class, FALSE))
610 for (i = source_idx; i < source_idx + length; ++i) {
611 MonoObject *elem = mono_array_get (source, MonoObject*, i);
612 if (elem && !mono_object_isinst (elem, dest_class))
619 memmove (dest_addr, source_addr, element_size * length);
625 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_InitializeArray (MonoArray *array, MonoClassField *field_handle)
627 MonoClass *klass = array->obj.vtable->klass;
628 guint32 size = mono_array_element_size (klass);
633 if (array->bounds == NULL)
634 size *= array->max_length;
636 for (i = 0; i < klass->rank; ++i)
637 size *= array->bounds [i].length;
639 memcpy (mono_array_addr (array, char, 0), field_handle->data, size);
641 #if G_BYTE_ORDER != G_LITTLE_ENDIAN
645 guint ## n *data = (guint ## n *) mono_array_addr (array, char, 0); \
647 for (i = 0; i < size; i += n/8, data++) { \
648 tmp = read ## n (data); \
653 /* printf ("Initialize array with elements of %s type\n", klass->element_class->name); */
655 switch (klass->element_class->byval_arg.type) {
675 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetOffsetToStringData (void)
679 return offsetof (MonoString, chars);
683 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetObjectValue (MonoObject *obj)
687 if ((obj == NULL) || (! (obj->vtable->klass->valuetype)))
690 return mono_object_clone (obj);
694 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_RunClassConstructor (MonoType *handle)
700 MONO_CHECK_ARG_NULL (handle);
702 klass = mono_class_from_mono_type (handle);
703 MONO_CHECK_ARG (handle, klass);
705 /* This will call the type constructor */
706 if (! (klass->flags & TYPE_ATTRIBUTE_INTERFACE))
707 mono_runtime_class_init (mono_class_vtable (mono_domain_get (), klass));
711 ves_icall_System_Object_MemberwiseClone (MonoObject *this)
715 return mono_object_clone (this);
719 #define MONO_OBJECT_ALIGNMENT_SHIFT 3
721 #define MONO_OBJECT_ALIGNMENT_SHIFT 2
725 * Return hashcode based on object address. This function will need to be
726 * smarter in the presence of a moving garbage collector, which will cache
727 * the address hash before relocating the object.
729 * Wang's address-based hash function:
730 * http://www.concentric.net/~Ttwang/tech/addrhash.htm
733 ves_icall_System_Object_GetHashCode (MonoObject *this)
735 register guint32 key;
739 key = (GPOINTER_TO_UINT (this) >> MONO_OBJECT_ALIGNMENT_SHIFT) * 2654435761u;
741 return key & 0x7fffffff;
745 ves_icall_System_ValueType_InternalGetHashCode (MonoObject *this, MonoArray **fields)
749 MonoObject **values = NULL;
756 klass = this->vtable->klass;
758 if (klass->field.count == 0)
759 return ves_icall_System_Object_GetHashCode (this);
762 * Compute the starting value of the hashcode for fields of primitive
763 * types, and return the remaining fields in an array to the managed side.
764 * This way, we can avoid costly reflection operations in managed code.
766 for (i = 0; i < klass->field.count; ++i) {
767 MonoClassField *field = &klass->fields [i];
768 if (field->type->attrs & FIELD_ATTRIBUTE_STATIC)
770 if (mono_field_is_deleted (field))
772 /* FIXME: Add more types */
773 switch (field->type->type) {
775 result ^= *(gint32*)((guint8*)this + field->offset);
777 case MONO_TYPE_STRING: {
779 s = *(MonoString**)((guint8*)this + field->offset);
781 result ^= ves_icall_System_String_GetHashCode (s);
786 values = alloca (klass->field.count * sizeof (MonoObject*));
787 o = mono_field_get_value_object (mono_object_domain (this), field, this);
788 values [count++] = o;
793 *fields = mono_array_new (mono_domain_get (), mono_defaults.object_class, count);
794 memcpy (mono_array_addr (*fields, MonoObject*, 0), values, count * sizeof (MonoObject*));
802 ves_icall_System_ValueType_Equals (MonoObject *this, MonoObject *that, MonoArray **fields)
806 MonoObject **values = NULL;
812 MONO_CHECK_ARG_NULL (that);
814 if (this->vtable != that->vtable)
817 klass = this->vtable->klass;
820 * Do the comparison for fields of primitive type and return a result if
821 * possible. Otherwise, return the remaining fields in an array to the
822 * managed side. This way, we can avoid costly reflection operations in
826 for (i = 0; i < klass->field.count; ++i) {
827 MonoClassField *field = &klass->fields [i];
828 if (field->type->attrs & FIELD_ATTRIBUTE_STATIC)
830 if (mono_field_is_deleted (field))
832 /* FIXME: Add more types */
833 switch (field->type->type) {
835 if (*(gint32*)((guint8*)this + field->offset) != *(gint32*)((guint8*)that + field->offset))
838 case MONO_TYPE_STRING: {
840 guint32 s1len, s2len;
841 s1 = *(MonoString**)((guint8*)this + field->offset);
842 s2 = *(MonoString**)((guint8*)that + field->offset);
845 if ((s1 == NULL) || (s2 == NULL))
847 s1len = mono_string_length (s1);
848 s2len = mono_string_length (s2);
852 if (memcmp (mono_string_chars (s1), mono_string_chars (s2), s1len * sizeof (gunichar2)) != 0)
858 values = alloca (klass->field.count * 2 * sizeof (MonoObject*));
859 o = mono_field_get_value_object (mono_object_domain (this), field, this);
860 values [count++] = o;
861 o = mono_field_get_value_object (mono_object_domain (this), field, that);
862 values [count++] = o;
867 *fields = mono_array_new (mono_domain_get (), mono_defaults.object_class, count);
868 memcpy (mono_array_addr (*fields, MonoObject*, 0), values, count * sizeof (MonoObject*));
876 static MonoReflectionType *
877 ves_icall_System_Object_GetType (MonoObject *obj)
881 if (obj->vtable->klass != mono_defaults.transparent_proxy_class)
882 return mono_type_get_object (mono_object_domain (obj), &obj->vtable->klass->byval_arg);
884 return mono_type_get_object (mono_object_domain (obj), &((MonoTransparentProxy*)obj)->remote_class->proxy_class->byval_arg);
888 mono_type_type_from_obj (MonoReflectionType *mtype, MonoObject *obj)
892 mtype->type = &obj->vtable->klass->byval_arg;
893 g_assert (mtype->type->type);
897 ves_icall_ModuleBuilder_getToken (MonoReflectionModuleBuilder *mb, MonoObject *obj)
901 return mono_image_create_token (mb->dynamic_image, obj);
905 ves_icall_ModuleBuilder_getMethodToken (MonoReflectionModuleBuilder *mb,
906 MonoReflectionMethod *method,
907 MonoArray *opt_param_types)
911 return mono_image_create_method_token (mb->dynamic_image, method, opt_param_types);
915 ves_icall_ModuleBuilder_getDataChunk (MonoReflectionModuleBuilder *mb, MonoArray *buf, gint32 offset)
918 MonoDynamicImage *image = mb->dynamic_image;
919 char *p = mono_array_addr (buf, char, 0);
923 mono_image_create_pefile (mb);
925 if (offset >= image->pefile.index)
927 count = mono_array_length (buf);
928 count = MIN (count, image->pefile.index - offset);
930 memcpy (p, image->pefile.data + offset, count);
936 ves_icall_ModuleBuilder_build_metadata (MonoReflectionModuleBuilder *mb)
940 mono_image_build_metadata (mb);
943 static MonoReflectionType *
944 type_from_name (const char *str, MonoBoolean ignoreCase)
946 MonoType *type = NULL;
947 MonoAssembly *assembly;
948 MonoTypeNameParse info;
952 if (!mono_reflection_parse_type (str, &info)) {
953 g_list_free (info.modifiers);
954 g_list_free (info.nested);
958 if (info.assembly.name) {
959 assembly = mono_assembly_load (&info.assembly, NULL, NULL);
961 MonoReflectionAssembly *refass;
963 refass = ves_icall_System_Reflection_Assembly_GetCallingAssembly ();
964 assembly = refass->assembly;
968 type = mono_reflection_get_type (assembly->image, &info, ignoreCase);
970 if (!info.assembly.name && !type) /* try mscorlib */
971 type = mono_reflection_get_type (NULL, &info, ignoreCase);
973 g_list_free (info.modifiers);
974 g_list_free (info.nested);
978 return mono_type_get_object (mono_domain_get (), type);
982 mono_type_get (const char *str)
984 char *copy = g_strdup (str);
985 MonoReflectionType *type = type_from_name (copy, FALSE);
991 static MonoReflectionType*
992 ves_icall_type_from_name (MonoString *name,
993 MonoBoolean throwOnError,
994 MonoBoolean ignoreCase)
996 char *str = mono_string_to_utf8 (name);
997 MonoReflectionType *type;
999 type = type_from_name (str, ignoreCase);
1003 mono_raise_exception (mono_get_exception_type_load (name));
1010 static MonoReflectionType*
1011 ves_icall_type_from_handle (MonoType *handle)
1013 MonoDomain *domain = mono_domain_get ();
1014 MonoClass *klass = mono_class_from_mono_type (handle);
1016 MONO_ARCH_SAVE_REGS;
1018 mono_class_init (klass);
1019 return mono_type_get_object (domain, handle);
1023 ves_icall_type_Equals (MonoReflectionType *type, MonoReflectionType *c)
1025 MONO_ARCH_SAVE_REGS;
1027 if (type->type && c->type)
1028 return mono_metadata_type_equal (type->type, c->type);
1029 g_print ("type equals\n");
1033 /* System.TypeCode */
1052 TYPECODE_STRING = 18
1056 ves_icall_type_GetTypeCode (MonoReflectionType *type)
1058 int t = type->type->type;
1060 MONO_ARCH_SAVE_REGS;
1064 case MONO_TYPE_VOID:
1065 return TYPECODE_OBJECT;
1066 case MONO_TYPE_BOOLEAN:
1067 return TYPECODE_BOOLEAN;
1069 return TYPECODE_BYTE;
1071 return TYPECODE_SBYTE;
1073 return TYPECODE_UINT16;
1075 return TYPECODE_INT16;
1076 case MONO_TYPE_CHAR:
1077 return TYPECODE_CHAR;
1081 return TYPECODE_OBJECT;
1083 return TYPECODE_UINT32;
1085 return TYPECODE_INT32;
1087 return TYPECODE_UINT64;
1089 return TYPECODE_INT64;
1091 return TYPECODE_SINGLE;
1093 return TYPECODE_DOUBLE;
1094 case MONO_TYPE_VALUETYPE:
1095 if (type->type->data.klass->enumtype) {
1096 t = type->type->data.klass->enum_basetype->type;
1099 MonoClass *k = type->type->data.klass;
1100 if (strcmp (k->name_space, "System") == 0) {
1101 if (strcmp (k->name, "Decimal") == 0)
1102 return TYPECODE_DECIMAL;
1103 else if (strcmp (k->name, "DateTime") == 0)
1104 return TYPECODE_DATETIME;
1107 return TYPECODE_OBJECT;
1108 case MONO_TYPE_STRING:
1109 return TYPECODE_STRING;
1110 case MONO_TYPE_SZARRAY:
1111 case MONO_TYPE_ARRAY:
1112 case MONO_TYPE_OBJECT:
1114 case MONO_TYPE_MVAR:
1115 return TYPECODE_OBJECT;
1116 case MONO_TYPE_CLASS:
1118 MonoClass *k = type->type->data.klass;
1119 if (strcmp (k->name_space, "System") == 0) {
1120 if (strcmp (k->name, "DBNull") == 0)
1121 return TYPECODE_DBNULL;
1124 return TYPECODE_OBJECT;
1125 case MONO_TYPE_GENERICINST:
1126 return TYPECODE_OBJECT;
1128 g_error ("type 0x%02x not handled in GetTypeCode()", t);
1134 ves_icall_type_is_subtype_of (MonoReflectionType *type, MonoReflectionType *c, MonoBoolean check_interfaces)
1140 MONO_ARCH_SAVE_REGS;
1142 g_assert (type != NULL);
1144 domain = ((MonoObject *)type)->vtable->domain;
1146 if (!c) /* FIXME: dont know what do do here */
1149 klass = mono_class_from_mono_type (type->type);
1150 klassc = mono_class_from_mono_type (c->type);
1152 return mono_class_is_subclass_of (klass, klassc, check_interfaces);
1156 ves_icall_type_is_assignable_from (MonoReflectionType *type, MonoReflectionType *c)
1162 MONO_ARCH_SAVE_REGS;
1164 g_assert (type != NULL);
1166 domain = ((MonoObject *)type)->vtable->domain;
1168 klass = mono_class_from_mono_type (type->type);
1169 klassc = mono_class_from_mono_type (c->type);
1171 return mono_class_is_assignable_from (klass, klassc);
1175 ves_icall_type_IsInstanceOfType (MonoReflectionType *type, MonoObject *obj)
1177 MonoClass *klass = mono_class_from_mono_type (type->type);
1178 return mono_object_isinst (obj, klass) != NULL;
1182 ves_icall_get_attributes (MonoReflectionType *type)
1184 MonoClass *klass = mono_class_from_mono_type (type->type);
1186 MONO_ARCH_SAVE_REGS;
1188 return klass->flags;
1191 static MonoReflectionField*
1192 ves_icall_System_Reflection_FieldInfo_internal_from_handle (MonoClassField *handle)
1194 MONO_ARCH_SAVE_REGS;
1198 return mono_field_get_object (mono_domain_get (), handle->parent, handle);
1202 ves_icall_get_method_info (MonoMethod *method, MonoMethodInfo *info)
1204 MonoDomain *domain = mono_domain_get ();
1206 MONO_ARCH_SAVE_REGS;
1208 info->parent = mono_type_get_object (domain, &method->klass->byval_arg);
1209 info->ret = mono_type_get_object (domain, method->signature->ret);
1210 info->attrs = method->flags;
1211 info->implattrs = method->iflags;
1212 if (method->signature->call_convention == MONO_CALL_DEFAULT)
1215 if (method->signature->call_convention == MONO_CALL_VARARG)
1219 info->callconv |= (method->signature->hasthis << 5) | (method->signature->explicit_this << 6);
1223 ves_icall_get_parameter_info (MonoMethod *method)
1225 MonoDomain *domain = mono_domain_get ();
1227 MONO_ARCH_SAVE_REGS;
1229 return mono_param_get_objects (domain, method);
1232 static MonoReflectionType*
1233 ves_icall_MonoField_GetParentType (MonoReflectionField *field, MonoBoolean declaring)
1236 MONO_ARCH_SAVE_REGS;
1238 parent = declaring? field->field->parent: field->klass;
1240 return mono_type_get_object (mono_object_domain (field), &parent->byval_arg);
1244 ves_icall_MonoField_GetValueInternal (MonoReflectionField *field, MonoObject *obj)
1247 MonoClassField *cf = field->field;
1250 MonoDomain *domain = mono_object_domain (field);
1252 gboolean is_static = FALSE;
1253 gboolean is_ref = FALSE;
1255 MONO_ARCH_SAVE_REGS;
1257 mono_class_init (field->klass);
1259 switch (cf->type->type) {
1260 case MONO_TYPE_STRING:
1261 case MONO_TYPE_OBJECT:
1262 case MONO_TYPE_CLASS:
1263 case MONO_TYPE_ARRAY:
1264 case MONO_TYPE_SZARRAY:
1269 case MONO_TYPE_BOOLEAN:
1272 case MONO_TYPE_CHAR:
1281 case MONO_TYPE_VALUETYPE:
1282 is_ref = cf->type->byref;
1285 g_error ("type 0x%x not handled in "
1286 "ves_icall_Monofield_GetValue", cf->type->type);
1291 if (cf->type->attrs & FIELD_ATTRIBUTE_STATIC) {
1293 vtable = mono_class_vtable (domain, field->klass);
1294 if (!vtable->initialized && !(cf->type->attrs & FIELD_ATTRIBUTE_LITERAL))
1295 mono_runtime_class_init (vtable);
1300 mono_field_static_get_value (vtable, cf, &o);
1302 mono_field_get_value (obj, cf, &o);
1307 /* boxed value type */
1308 klass = mono_class_from_mono_type (cf->type);
1309 o = mono_object_new (domain, klass);
1310 v = ((gchar *) o) + sizeof (MonoObject);
1312 mono_field_static_get_value (vtable, cf, v);
1314 mono_field_get_value (obj, cf, v);
1321 ves_icall_FieldInfo_SetValueInternal (MonoReflectionField *field, MonoObject *obj, MonoObject *value)
1323 MonoClassField *cf = field->field;
1326 MONO_ARCH_SAVE_REGS;
1328 v = (gchar *) value;
1329 if (!cf->type->byref) {
1330 switch (cf->type->type) {
1333 case MONO_TYPE_BOOLEAN:
1336 case MONO_TYPE_CHAR:
1345 case MONO_TYPE_VALUETYPE:
1346 v += sizeof (MonoObject);
1348 case MONO_TYPE_STRING:
1349 case MONO_TYPE_OBJECT:
1350 case MONO_TYPE_CLASS:
1351 case MONO_TYPE_ARRAY:
1352 case MONO_TYPE_SZARRAY:
1356 g_error ("type 0x%x not handled in "
1357 "ves_icall_FieldInfo_SetValueInternal", cf->type->type);
1362 if (cf->type->attrs & FIELD_ATTRIBUTE_STATIC) {
1363 MonoVTable *vtable = mono_class_vtable (mono_object_domain (field), field->klass);
1364 if (!vtable->initialized)
1365 mono_runtime_class_init (vtable);
1366 mono_field_static_set_value (vtable, cf, v);
1368 mono_field_set_value (obj, cf, v);
1372 /* From MonoProperty.cs */
1374 PInfo_Attributes = 1,
1375 PInfo_GetMethod = 1 << 1,
1376 PInfo_SetMethod = 1 << 2,
1377 PInfo_ReflectedType = 1 << 3,
1378 PInfo_DeclaringType = 1 << 4,
1383 ves_icall_get_property_info (MonoReflectionProperty *property, MonoPropertyInfo *info, PInfo req_info)
1385 MonoDomain *domain = mono_object_domain (property);
1387 MONO_ARCH_SAVE_REGS;
1389 if ((req_info & PInfo_ReflectedType) != 0)
1390 info->parent = mono_type_get_object (domain, &property->klass->byval_arg);
1391 else if ((req_info & PInfo_DeclaringType) != 0)
1392 info->parent = mono_type_get_object (domain, &property->property->parent->byval_arg);
1394 if ((req_info & PInfo_Name) != 0)
1395 info->name = mono_string_new (domain, property->property->name);
1397 if ((req_info & PInfo_Attributes) != 0)
1398 info->attrs = property->property->attrs;
1400 if ((req_info & PInfo_GetMethod) != 0)
1401 info->get = property->property->get ?
1402 mono_method_get_object (domain, property->property->get, NULL): NULL;
1404 if ((req_info & PInfo_SetMethod) != 0)
1405 info->set = property->property->set ?
1406 mono_method_get_object (domain, property->property->set, NULL): NULL;
1408 * There may be other methods defined for properties, though, it seems they are not exposed
1409 * in the reflection API
1414 ves_icall_get_event_info (MonoReflectionEvent *event, MonoEventInfo *info)
1416 MonoDomain *domain = mono_object_domain (event);
1418 MONO_ARCH_SAVE_REGS;
1420 info->declaring_type = mono_type_get_object (domain, &event->klass->byval_arg);
1421 info->reflected_type = mono_type_get_object (domain, &event->event->parent->byval_arg);
1423 info->name = mono_string_new (domain, event->event->name);
1424 info->attrs = event->event->attrs;
1425 info->add_method = event->event->add ? mono_method_get_object (domain, event->event->add, NULL): NULL;
1426 info->remove_method = event->event->remove ? mono_method_get_object (domain, event->event->remove, NULL): NULL;
1427 info->raise_method = event->event->raise ? mono_method_get_object (domain, event->event->raise, NULL): NULL;
1431 ves_icall_Type_GetInterfaces (MonoReflectionType* type)
1433 MonoDomain *domain = mono_object_domain (type);
1436 MonoClass *class = mono_class_from_mono_type (type->type);
1438 MonoBitSet *slots = mono_bitset_new (class->max_interface_id + 1, 0);
1440 MONO_ARCH_SAVE_REGS;
1443 /* GetInterfaces() returns an empty array in MS.NET (this may be a bug) */
1444 mono_bitset_free (slots);
1445 return mono_array_new (domain, mono_defaults.monotype_class, 0);
1449 for (parent = class; parent; parent = parent->parent) {
1450 for (i = 0; i < parent->interface_count; ++i) {
1451 if (mono_bitset_test (slots, parent->interfaces [i]->interface_id))
1454 mono_bitset_set (slots, parent->interfaces [i]->interface_id);
1459 intf = mono_array_new (domain, mono_defaults.monotype_class, ninterf);
1461 for (parent = class; parent; parent = parent->parent) {
1462 for (i = 0; i < parent->interface_count; ++i) {
1463 if (!mono_bitset_test (slots, parent->interfaces [i]->interface_id))
1466 mono_bitset_clear (slots, parent->interfaces [i]->interface_id);
1467 mono_array_set (intf, gpointer, ninterf,
1468 mono_type_get_object (domain, &parent->interfaces [i]->byval_arg));
1473 mono_bitset_free (slots);
1478 ves_icall_Type_GetInterfaceMapData (MonoReflectionType *type, MonoReflectionType *iface, MonoArray **targets, MonoArray **methods)
1480 MonoClass *class = mono_class_from_mono_type (type->type);
1481 MonoClass *iclass = mono_class_from_mono_type (iface->type);
1482 MonoReflectionMethod *member;
1483 int i, len, ioffset;
1486 MONO_ARCH_SAVE_REGS;
1488 /* type doesn't implement iface: the exception is thrown in managed code */
1489 if ((iclass->interface_id > class->max_interface_id) || !class->interface_offsets [iclass->interface_id])
1492 len = iclass->method.count;
1493 ioffset = class->interface_offsets [iclass->interface_id];
1494 domain = mono_object_domain (type);
1495 *targets = mono_array_new (domain, mono_defaults.method_info_class, len);
1496 *methods = mono_array_new (domain, mono_defaults.method_info_class, len);
1497 for (i = 0; i < len; ++i) {
1498 member = mono_method_get_object (domain, iclass->methods [i], iclass);
1499 mono_array_set (*methods, gpointer, i, member);
1500 member = mono_method_get_object (domain, class->vtable [i + ioffset], class);
1501 mono_array_set (*targets, gpointer, i, member);
1505 static MonoReflectionType*
1506 ves_icall_MonoType_GetElementType (MonoReflectionType *type)
1508 MonoClass *class = mono_class_from_mono_type (type->type);
1510 MONO_ARCH_SAVE_REGS;
1512 if (type->type->byref)
1513 return mono_type_get_object (mono_object_domain (type), &class->byval_arg);
1514 if (class->enumtype && class->enum_basetype) /* types that are modifierd typebuilkders may not have enum_basetype set */
1515 return mono_type_get_object (mono_object_domain (type), class->enum_basetype);
1516 else if (class->element_class)
1517 return mono_type_get_object (mono_object_domain (type), &class->element_class->byval_arg);
1522 static MonoReflectionType*
1523 ves_icall_get_type_parent (MonoReflectionType *type)
1525 MonoClass *class = mono_class_from_mono_type (type->type);
1527 MONO_ARCH_SAVE_REGS;
1529 return class->parent ? mono_type_get_object (mono_object_domain (type), &class->parent->byval_arg): NULL;
1533 ves_icall_type_ispointer (MonoReflectionType *type)
1535 MONO_ARCH_SAVE_REGS;
1537 return type->type->type == MONO_TYPE_PTR;
1541 ves_icall_type_isprimitive (MonoReflectionType *type)
1543 MONO_ARCH_SAVE_REGS;
1545 return (!type->type->byref && (type->type->type >= MONO_TYPE_BOOLEAN) && (type->type->type <= MONO_TYPE_R8));
1549 ves_icall_type_isbyref (MonoReflectionType *type)
1551 MONO_ARCH_SAVE_REGS;
1553 return type->type->byref;
1556 static MonoReflectionModule*
1557 ves_icall_MonoType_get_Module (MonoReflectionType *type)
1559 MonoClass *class = mono_class_from_mono_type (type->type);
1561 MONO_ARCH_SAVE_REGS;
1563 return mono_module_get_object (mono_object_domain (type), class->image);
1566 static MonoReflectionAssembly*
1567 ves_icall_MonoType_get_Assembly (MonoReflectionType *type)
1569 MonoDomain *domain = mono_domain_get ();
1570 MonoClass *class = mono_class_from_mono_type (type->type);
1572 MONO_ARCH_SAVE_REGS;
1574 return mono_assembly_get_object (domain, class->image->assembly);
1577 static MonoReflectionType*
1578 ves_icall_MonoType_get_DeclaringType (MonoReflectionType *type)
1580 MonoDomain *domain = mono_domain_get ();
1581 MonoClass *class = mono_class_from_mono_type (type->type);
1583 MONO_ARCH_SAVE_REGS;
1585 return class->nested_in ? mono_type_get_object (domain, &class->nested_in->byval_arg) : NULL;
1588 static MonoReflectionType*
1589 ves_icall_MonoType_get_UnderlyingSystemType (MonoReflectionType *type)
1591 MonoDomain *domain = mono_domain_get ();
1592 MonoClass *class = mono_class_from_mono_type (type->type);
1594 MONO_ARCH_SAVE_REGS;
1596 if (class->enumtype && class->enum_basetype) /* types that are modified typebuilders may not have enum_basetype set */
1597 return mono_type_get_object (domain, class->enum_basetype);
1598 else if (class->element_class)
1599 return mono_type_get_object (domain, &class->element_class->byval_arg);
1605 ves_icall_MonoType_get_Name (MonoReflectionType *type)
1607 MonoDomain *domain = mono_domain_get ();
1608 MonoClass *class = mono_class_from_mono_type (type->type);
1610 MONO_ARCH_SAVE_REGS;
1612 return mono_string_new (domain, class->name);
1616 ves_icall_MonoType_get_Namespace (MonoReflectionType *type)
1618 MonoDomain *domain = mono_domain_get ();
1619 MonoClass *class = mono_class_from_mono_type (type->type);
1621 MONO_ARCH_SAVE_REGS;
1623 while (class->nested_in)
1624 class = class->nested_in;
1626 return mono_string_new (domain, class->name_space);
1630 ves_icall_MonoType_GetArrayRank (MonoReflectionType *type)
1632 MonoClass *class = mono_class_from_mono_type (type->type);
1634 MONO_ARCH_SAVE_REGS;
1640 ves_icall_MonoType_GetGenericArguments (MonoReflectionType *type)
1643 MonoClass *klass, *pklass;
1645 MONO_ARCH_SAVE_REGS;
1647 klass = mono_class_from_mono_type (type->type);
1649 if (type->type->byref) {
1650 res = mono_array_new (mono_object_domain (type), mono_defaults.monotype_class, 0);
1651 } else if (klass->gen_params) {
1652 res = mono_array_new (mono_object_domain (type), mono_defaults.monotype_class, klass->num_gen_params);
1653 for (i = 0; i < klass->num_gen_params; ++i) {
1654 pklass = mono_class_from_generic_parameter (&klass->gen_params [i], klass->image, FALSE);
1655 mono_array_set (res, gpointer, i, mono_type_get_object (mono_object_domain (type), &pklass->byval_arg));
1657 } else if (klass->generic_inst) {
1658 MonoGenericInst *inst = klass->generic_inst;
1659 res = mono_array_new (mono_object_domain (type), mono_defaults.monotype_class, inst->type_argc);
1660 for (i = 0; i < inst->type_argc; ++i) {
1661 mono_array_set (res, gpointer, i, mono_type_get_object (mono_object_domain (type), inst->type_argv [i]));
1664 res = mono_array_new (mono_object_domain (type), mono_defaults.monotype_class, 0);
1670 ves_icall_Type_get_IsGenericTypeDefinition (MonoReflectionType *type)
1673 MONO_ARCH_SAVE_REGS;
1675 if (type->type->byref)
1677 klass = mono_class_from_mono_type (type->type);
1679 return klass->gen_params != NULL;
1682 static MonoReflectionType*
1683 ves_icall_Type_GetGenericTypeDefinition_impl (MonoReflectionType *type)
1686 MONO_ARCH_SAVE_REGS;
1688 if (type->type->byref)
1690 klass = mono_class_from_mono_type (type->type);
1691 if (klass->gen_params) {
1692 return type; /* check this one */
1694 if (klass->generic_inst) {
1695 MonoType *generic_type = klass->generic_inst->generic_type;
1696 MonoClass *generic_class = mono_class_from_mono_type (generic_type);
1698 if (generic_class->wastypebuilder && generic_class->reflection_info)
1699 return generic_class->reflection_info;
1701 return mono_type_get_object (mono_object_domain (type), generic_type);
1706 static MonoReflectionType*
1707 ves_icall_Type_BindGenericParameters (MonoReflectionType *type, MonoArray *type_array)
1709 MonoType *geninst, **types;
1712 MONO_ARCH_SAVE_REGS;
1714 if (type->type->byref)
1717 count = mono_array_length (type_array);
1718 types = g_new0 (MonoType *, count);
1720 for (i = 0; i < count; i++) {
1721 MonoReflectionType *t = mono_array_get (type_array, gpointer, i);
1722 types [i] = t->type;
1725 geninst = mono_reflection_bind_generic_parameters (type, count, types);
1727 return mono_type_get_object (mono_object_domain (type), geninst);
1731 ves_icall_Type_get_IsGenericInstance (MonoReflectionType *type)
1734 MONO_ARCH_SAVE_REGS;
1736 if (type->type->byref)
1738 klass = mono_class_from_mono_type (type->type);
1739 return klass->generic_inst != NULL;
1743 ves_icall_Type_GetGenericParameterPosition (MonoReflectionType *type)
1745 MONO_ARCH_SAVE_REGS;
1747 if (type->type->byref)
1749 if (type->type->type == MONO_TYPE_VAR || type->type->type == MONO_TYPE_MVAR)
1750 return type->type->data.generic_param->num;
1755 ves_icall_MonoType_get_HasGenericArguments (MonoReflectionType *type)
1758 MONO_ARCH_SAVE_REGS;
1760 if (type->type->byref)
1762 klass = mono_class_from_mono_type (type->type);
1763 if (klass->gen_params || klass->generic_inst)
1769 ves_icall_MonoType_get_IsGenericParameter (MonoReflectionType *type)
1771 MONO_ARCH_SAVE_REGS;
1773 if (type->type->byref)
1775 if (type->type->type == MONO_TYPE_VAR || type->type->type == MONO_TYPE_MVAR)
1781 ves_icall_TypeBuilder_get_IsGenericParameter (MonoReflectionTypeBuilder *tb)
1783 MONO_ARCH_SAVE_REGS;
1785 if (tb->type.type->byref)
1787 if (tb->type.type->type == MONO_TYPE_VAR || tb->type.type->type == MONO_TYPE_MVAR)
1792 static MonoReflectionType*
1793 ves_icall_MonoGenericInst_GetParentType (MonoReflectionGenericInst *type)
1795 MonoGenericInst *ginst;
1798 MONO_ARCH_SAVE_REGS;
1800 ginst = type->type.type->data.generic_inst;
1801 if (!ginst || !ginst->parent || (ginst->parent->type != MONO_TYPE_GENERICINST))
1804 klass = mono_class_from_mono_type (ginst->parent);
1805 if (!klass->generic_inst && !klass->gen_params)
1808 return mono_type_get_object (mono_object_domain (type), ginst->parent);
1812 ves_icall_MonoGenericInst_GetInterfaces (MonoReflectionGenericInst *type)
1814 static MonoClass *System_Reflection_MonoGenericInst;
1815 MonoGenericInst *ginst;
1821 MONO_ARCH_SAVE_REGS;
1823 if (!System_Reflection_MonoGenericInst) {
1824 System_Reflection_MonoGenericInst = mono_class_from_name (
1825 mono_defaults.corlib, "System.Reflection", "MonoGenericInst");
1826 g_assert (System_Reflection_MonoGenericInst);
1829 domain = mono_object_domain (type);
1831 ginst = type->type.type->data.generic_inst;
1832 if (!ginst || !ginst->ifaces)
1833 return mono_array_new (domain, System_Reflection_MonoGenericInst, 0);
1835 klass = mono_class_from_mono_type (ginst->generic_type);
1837 res = mono_array_new (domain, System_Reflection_MonoGenericInst, ginst->count_ifaces);
1839 for (i = 0; i < ginst->count_ifaces; i++) {
1840 MonoReflectionType *iface = mono_type_get_object (domain, ginst->ifaces [i]);
1842 mono_array_set (res, gpointer, i, iface);
1849 ves_icall_MonoGenericInst_GetMethods (MonoReflectionGenericInst *type,
1850 MonoReflectionType *reflected_type)
1852 MonoGenericInst *ginst;
1853 MonoDynamicGenericInst *dginst;
1855 MonoClass *refclass;
1859 MONO_ARCH_SAVE_REGS;
1861 ginst = type->type.type->data.generic_inst;
1862 g_assert ((dginst = ginst->dynamic_info) != NULL);
1864 refclass = mono_class_from_mono_type (reflected_type->type);
1866 domain = mono_object_domain (type);
1867 res = mono_array_new (domain, mono_defaults.method_info_class, dginst->count_methods);
1869 for (i = 0; i < dginst->count_methods; i++)
1870 mono_array_set (res, gpointer, i,
1871 mono_method_get_object (domain, dginst->methods [i], refclass));
1877 ves_icall_MonoGenericInst_GetConstructors (MonoReflectionGenericInst *type,
1878 MonoReflectionType *reflected_type)
1880 static MonoClass *System_Reflection_ConstructorInfo;
1881 MonoGenericInst *ginst;
1882 MonoDynamicGenericInst *dginst;
1884 MonoClass *refclass;
1888 MONO_ARCH_SAVE_REGS;
1890 if (!System_Reflection_ConstructorInfo)
1891 System_Reflection_ConstructorInfo = mono_class_from_name (
1892 mono_defaults.corlib, "System.Reflection", "ConstructorInfo");
1894 ginst = type->type.type->data.generic_inst;
1895 g_assert ((dginst = ginst->dynamic_info) != NULL);
1897 refclass = mono_class_from_mono_type (reflected_type->type);
1899 domain = mono_object_domain (type);
1900 res = mono_array_new (domain, System_Reflection_ConstructorInfo, dginst->count_ctors);
1902 for (i = 0; i < dginst->count_ctors; i++)
1903 mono_array_set (res, gpointer, i,
1904 mono_method_get_object (domain, dginst->ctors [i], refclass));
1910 ves_icall_MonoGenericInst_GetFields (MonoReflectionGenericInst *type,
1911 MonoReflectionType *reflected_type)
1913 MonoGenericInst *ginst;
1914 MonoDynamicGenericInst *dginst;
1916 MonoClass *refclass;
1920 MONO_ARCH_SAVE_REGS;
1922 ginst = type->type.type->data.generic_inst;
1923 g_assert ((dginst = ginst->dynamic_info) != NULL);
1925 refclass = mono_class_from_mono_type (reflected_type->type);
1927 domain = mono_object_domain (type);
1928 res = mono_array_new (domain, mono_defaults.field_info_class, dginst->count_fields);
1930 for (i = 0; i < dginst->count_fields; i++)
1931 mono_array_set (res, gpointer, i,
1932 mono_field_get_object (domain, refclass, &dginst->fields [i]));
1938 ves_icall_MonoGenericInst_GetProperties (MonoReflectionGenericInst *type,
1939 MonoReflectionType *reflected_type)
1941 static MonoClass *System_Reflection_PropertyInfo;
1942 MonoGenericInst *ginst;
1943 MonoDynamicGenericInst *dginst;
1945 MonoClass *refclass;
1949 MONO_ARCH_SAVE_REGS;
1951 if (!System_Reflection_PropertyInfo)
1952 System_Reflection_PropertyInfo = mono_class_from_name (
1953 mono_defaults.corlib, "System.Reflection", "PropertyInfo");
1955 ginst = type->type.type->data.generic_inst;
1956 g_assert ((dginst = ginst->dynamic_info) != NULL);
1958 refclass = mono_class_from_mono_type (reflected_type->type);
1960 domain = mono_object_domain (type);
1961 res = mono_array_new (domain, System_Reflection_PropertyInfo, dginst->count_properties);
1963 for (i = 0; i < dginst->count_properties; i++)
1964 mono_array_set (res, gpointer, i,
1965 mono_property_get_object (domain, refclass, &dginst->properties [i]));
1971 ves_icall_MonoGenericInst_GetEvents (MonoReflectionGenericInst *type,
1972 MonoReflectionType *reflected_type)
1974 static MonoClass *System_Reflection_EventInfo;
1975 MonoGenericInst *ginst;
1976 MonoDynamicGenericInst *dginst;
1978 MonoClass *refclass;
1982 MONO_ARCH_SAVE_REGS;
1984 if (!System_Reflection_EventInfo)
1985 System_Reflection_EventInfo = mono_class_from_name (
1986 mono_defaults.corlib, "System.Reflection", "EventInfo");
1988 ginst = type->type.type->data.generic_inst;
1989 g_assert ((dginst = ginst->dynamic_info) != NULL);
1991 refclass = mono_class_from_mono_type (reflected_type->type);
1993 domain = mono_object_domain (type);
1994 res = mono_array_new (domain, System_Reflection_EventInfo, dginst->count_events);
1996 for (i = 0; i < dginst->count_events; i++)
1997 mono_array_set (res, gpointer, i,
1998 mono_event_get_object (domain, refclass, &dginst->events [i]));
2003 static MonoReflectionMethod *
2004 ves_icall_MonoType_get_DeclaringMethod (MonoReflectionType *type)
2009 MONO_ARCH_SAVE_REGS;
2011 if (type->type->byref)
2014 method = type->type->data.generic_param->method;
2018 klass = mono_class_from_mono_type (type->type);
2019 return mono_method_get_object (mono_object_domain (type), method, klass);
2022 static MonoReflectionMethod *
2023 ves_icall_MonoMethod_GetGenericMethodDefinition (MonoReflectionMethod *method)
2025 MonoMethodInflated *imethod;
2027 MONO_ARCH_SAVE_REGS;
2029 if (!method->method->signature->is_inflated) {
2030 if (method->method->signature->generic_param_count)
2036 imethod = (MonoMethodInflated *) method->method;
2037 if (imethod->context->gmethod && imethod->context->gmethod->reflection_info)
2038 return imethod->context->gmethod->reflection_info;
2040 return mono_method_get_object (
2041 mono_object_domain (method), imethod->declaring, NULL);
2045 ves_icall_MonoMethod_get_HasGenericParameters (MonoReflectionMethod *method)
2047 MONO_ARCH_SAVE_REGS;
2049 if ((method->method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) ||
2050 (method->method->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL))
2053 return method->method->signature->generic_param_count != 0;
2057 ves_icall_MonoMethod_get_Mono_IsInflatedMethod (MonoReflectionMethod *method)
2059 MONO_ARCH_SAVE_REGS;
2061 if ((method->method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) ||
2062 (method->method->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL))
2065 return method->method->signature->is_inflated;
2069 ves_icall_MonoMethod_get_IsGenericMethodDefinition (MonoReflectionMethod *method)
2071 MONO_ARCH_SAVE_REGS;
2073 if ((method->method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) ||
2074 (method->method->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL))
2077 return method->method->signature->generic_param_count != 0;
2081 ves_icall_MonoMethod_GetGenericArguments (MonoReflectionMethod *method)
2085 MonoMethodNormal *mn;
2087 MONO_ARCH_SAVE_REGS;
2089 domain = mono_object_domain (method);
2091 if ((method->method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) ||
2092 (method->method->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL))
2093 return mono_array_new (domain, mono_defaults.monotype_class, 0);
2095 if (method->method->signature->is_inflated) {
2096 MonoMethodInflated *imethod = (MonoMethodInflated *) method->method;
2097 MonoGenericMethod *gmethod = imethod->context->gmethod;
2100 count = gmethod->mtype_argc;
2101 res = mono_array_new (domain, mono_defaults.monotype_class, count);
2103 for (i = 0; i < count; i++) {
2104 MonoType *t = gmethod->mtype_argv [i];
2106 res, gpointer, i, mono_type_get_object (domain, t));
2113 mn = (MonoMethodNormal *) method->method;
2114 count = method->method->signature->generic_param_count;
2115 res = mono_array_new (domain, mono_defaults.monotype_class, count);
2117 for (i = 0; i < count; i++) {
2118 MonoGenericParam *param = &mn->header->gen_params [i];
2119 MonoClass *pklass = mono_class_from_generic_parameter (
2120 param, method->method->klass->image, TRUE);
2121 mono_array_set (res, gpointer, i,
2122 mono_type_get_object (domain, &pklass->byval_arg));
2129 ves_icall_InternalInvoke (MonoReflectionMethod *method, MonoObject *this, MonoArray *params)
2132 * Invoke from reflection is supposed to always be a virtual call (the API
2133 * is stupid), mono_runtime_invoke_*() calls the provided method, allowing
2134 * greater flexibility.
2136 MonoMethod *m = method->method;
2139 MONO_ARCH_SAVE_REGS;
2142 if (!mono_object_isinst (this, m->klass))
2143 mono_raise_exception (mono_exception_from_name (mono_defaults.corlib, "System.Reflection", "TargetException"));
2144 m = mono_object_get_virtual_method (this, m);
2145 } else if (!(m->flags & METHOD_ATTRIBUTE_STATIC) && strcmp (m->name, ".ctor") && !m->wrapper_type)
2146 mono_raise_exception (mono_exception_from_name (mono_defaults.corlib, "System.Reflection", "TargetException"));
2148 pcount = params? mono_array_length (params): 0;
2149 if (pcount != m->signature->param_count)
2150 mono_raise_exception (mono_exception_from_name (mono_defaults.corlib, "System.Reflection", "TargetParameterCountException"));
2152 if (m->klass->rank && !strcmp (m->name, ".ctor")) {
2155 guint32 *lower_bounds;
2156 pcount = mono_array_length (params);
2157 lengths = alloca (sizeof (guint32) * pcount);
2158 for (i = 0; i < pcount; ++i)
2159 lengths [i] = *(gint32*) ((char*)mono_array_get (params, gpointer, i) + sizeof (MonoObject));
2161 if (m->klass->rank == pcount) {
2162 /* Only lengths provided. */
2163 lower_bounds = NULL;
2165 g_assert (pcount == (m->klass->rank * 2));
2166 /* lower bounds are first. */
2167 lower_bounds = lengths;
2168 lengths += m->klass->rank;
2171 return (MonoObject*)mono_array_new_full (mono_object_domain (params), m->klass, lengths, lower_bounds);
2173 return mono_runtime_invoke_array (m, this, params, NULL);
2177 ves_icall_InternalExecute (MonoReflectionMethod *method, MonoObject *this, MonoArray *params, MonoArray **outArgs)
2179 MonoDomain *domain = mono_object_domain (method);
2180 MonoMethod *m = method->method;
2181 MonoMethodSignature *sig = m->signature;
2182 MonoArray *out_args;
2184 int i, j, outarg_count = 0;
2186 MONO_ARCH_SAVE_REGS;
2188 if (m->klass == mono_defaults.object_class) {
2190 if (!strcmp (m->name, "FieldGetter")) {
2191 MonoClass *k = this->vtable->klass;
2192 MonoString *name = mono_array_get (params, MonoString *, 1);
2195 str = mono_string_to_utf8 (name);
2197 for (i = 0; i < k->field.count; i++) {
2198 if (!strcmp (k->fields [i].name, str)) {
2199 MonoClass *field_klass = mono_class_from_mono_type (k->fields [i].type);
2200 if (field_klass->valuetype)
2201 result = mono_value_box (domain, field_klass,
2202 (char *)this + k->fields [i].offset);
2204 result = *((gpointer *)((char *)this + k->fields [i].offset));
2207 out_args = mono_array_new (domain, mono_defaults.object_class, 1);
2208 *outArgs = out_args;
2209 mono_array_set (out_args, gpointer, 0, result);
2216 g_assert_not_reached ();
2218 } else if (!strcmp (m->name, "FieldSetter")) {
2219 MonoClass *k = this->vtable->klass;
2220 MonoString *name = mono_array_get (params, MonoString *, 1);
2224 str = mono_string_to_utf8 (name);
2226 for (i = 0; i < k->field.count; i++) {
2227 if (!strcmp (k->fields [i].name, str)) {
2228 MonoClass *field_klass = mono_class_from_mono_type (k->fields [i].type);
2229 MonoObject *val = mono_array_get (params, gpointer, 2);
2231 if (field_klass->valuetype) {
2232 size = mono_type_size (k->fields [i].type, &align);
2233 memcpy ((char *)this + k->fields [i].offset,
2234 ((char *)val) + sizeof (MonoObject), size);
2236 *(MonoObject**)((char *)this + k->fields [i].offset) = val;
2238 out_args = mono_array_new (domain, mono_defaults.object_class, 0);
2239 *outArgs = out_args;
2247 g_assert_not_reached ();
2252 for (i = 0; i < mono_array_length (params); i++) {
2253 if (sig->params [i]->byref)
2257 out_args = mono_array_new (domain, mono_defaults.object_class, outarg_count);
2259 /* fixme: handle constructors? */
2260 if (!strcmp (method->method->name, ".ctor"))
2261 g_assert_not_reached ();
2263 result = mono_runtime_invoke_array (method->method, this, params, NULL);
2265 for (i = 0, j = 0; i < mono_array_length (params); i++) {
2266 if (sig->params [i]->byref) {
2268 arg = mono_array_get (params, gpointer, i);
2269 mono_array_set (out_args, gpointer, j, arg);
2274 *outArgs = out_args;
2280 ves_icall_System_Enum_ToObject (MonoReflectionType *type, MonoObject *obj)
2283 MonoClass *enumc, *objc;
2287 MONO_ARCH_SAVE_REGS;
2289 MONO_CHECK_ARG_NULL (type);
2290 MONO_CHECK_ARG_NULL (obj);
2292 domain = mono_object_domain (type);
2293 enumc = mono_class_from_mono_type (type->type);
2294 objc = obj->vtable->klass;
2296 MONO_CHECK_ARG (obj, enumc->enumtype == TRUE);
2297 MONO_CHECK_ARG (obj, (objc->enumtype) || (objc->byval_arg.type >= MONO_TYPE_I1 &&
2298 objc->byval_arg.type <= MONO_TYPE_U8));
2300 s1 = mono_class_value_size (enumc, NULL);
2301 s2 = mono_class_value_size (objc, NULL);
2303 res = mono_object_new (domain, enumc);
2305 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
2306 memcpy ((char *)res + sizeof (MonoObject), (char *)obj + sizeof (MonoObject), MIN (s1, s2));
2308 memcpy ((char *)res + sizeof (MonoObject) + (s1 > s2 ? s1 - s2 : 0),
2309 (char *)obj + sizeof (MonoObject) + (s2 > s1 ? s2 - s1 : 0),
2316 ves_icall_System_Enum_get_value (MonoObject *this)
2324 MONO_ARCH_SAVE_REGS;
2329 g_assert (this->vtable->klass->enumtype);
2331 enumc = mono_class_from_mono_type (this->vtable->klass->enum_basetype);
2332 res = mono_object_new (mono_object_domain (this), enumc);
2333 dst = (char *)res + sizeof (MonoObject);
2334 src = (char *)this + sizeof (MonoObject);
2335 size = mono_class_value_size (enumc, NULL);
2337 memcpy (dst, src, size);
2343 ves_icall_get_enum_info (MonoReflectionType *type, MonoEnumInfo *info)
2345 MonoDomain *domain = mono_object_domain (type);
2346 MonoClass *enumc = mono_class_from_mono_type (type->type);
2347 guint i, j, nvalues, crow;
2348 MonoClassField *field;
2350 MONO_ARCH_SAVE_REGS;
2352 info->utype = mono_type_get_object (domain, enumc->enum_basetype);
2353 nvalues = enumc->field.count - 1;
2354 info->names = mono_array_new (domain, mono_defaults.string_class, nvalues);
2355 info->values = mono_array_new (domain, enumc, nvalues);
2358 for (i = 0, j = 0; i < enumc->field.count; ++i) {
2362 field = &enumc->fields [i];
2363 if (strcmp ("value__", field->name) == 0)
2365 if (mono_field_is_deleted (field))
2367 mono_array_set (info->names, gpointer, j, mono_string_new (domain, field->name));
2368 if (!field->def_value) {
2369 field->def_value = g_new0 (MonoConstant, 1);
2370 crow = mono_metadata_get_constant_index (enumc->image, MONO_TOKEN_FIELD_DEF | (i+enumc->field.first+1), crow + 1);
2371 field->def_value->type = mono_metadata_decode_row_col (&enumc->image->tables [MONO_TABLE_CONSTANT], crow-1, MONO_CONSTANT_TYPE);
2372 crow = mono_metadata_decode_row_col (&enumc->image->tables [MONO_TABLE_CONSTANT], crow-1, MONO_CONSTANT_VALUE);
2373 field->def_value->value = (gpointer)mono_metadata_blob_heap (enumc->image, crow);
2376 p = field->def_value->value;
2377 len = mono_metadata_decode_blob_size (p, &p);
2378 switch (enumc->enum_basetype->type) {
2381 mono_array_set (info->values, gchar, j, *p);
2383 case MONO_TYPE_CHAR:
2386 mono_array_set (info->values, gint16, j, read16 (p));
2390 mono_array_set (info->values, gint32, j, read32 (p));
2394 mono_array_set (info->values, gint64, j, read64 (p));
2397 g_error ("Implement type 0x%02x in get_enum_info", enumc->enum_basetype->type);
2404 BFLAGS_IgnoreCase = 1,
2405 BFLAGS_DeclaredOnly = 2,
2406 BFLAGS_Instance = 4,
2408 BFLAGS_Public = 0x10,
2409 BFLAGS_NonPublic = 0x20,
2410 BFLAGS_FlattenHierarchy = 0x40,
2411 BFLAGS_InvokeMethod = 0x100,
2412 BFLAGS_CreateInstance = 0x200,
2413 BFLAGS_GetField = 0x400,
2414 BFLAGS_SetField = 0x800,
2415 BFLAGS_GetProperty = 0x1000,
2416 BFLAGS_SetProperty = 0x2000,
2417 BFLAGS_ExactBinding = 0x10000,
2418 BFLAGS_SuppressChangeType = 0x20000,
2419 BFLAGS_OptionalParamBinding = 0x40000
2422 static MonoReflectionField *
2423 ves_icall_Type_GetField (MonoReflectionType *type, MonoString *name, guint32 bflags)
2426 MonoClass *startklass, *klass;
2428 MonoClassField *field;
2430 domain = ((MonoObject *)type)->vtable->domain;
2431 klass = startklass = mono_class_from_mono_type (type->type);
2433 MONO_ARCH_SAVE_REGS;
2436 mono_raise_exception (mono_get_exception_argument_null ("name"));
2439 for (i = 0; i < klass->field.count; ++i) {
2441 field = &klass->fields [i];
2442 if (mono_field_is_deleted (field))
2444 if ((field->type->attrs & FIELD_ATTRIBUTE_FIELD_ACCESS_MASK) == FIELD_ATTRIBUTE_PUBLIC) {
2445 if (bflags & BFLAGS_Public)
2448 if (bflags & BFLAGS_NonPublic)
2454 if (field->type->attrs & FIELD_ATTRIBUTE_STATIC) {
2455 if (bflags & BFLAGS_Static)
2456 if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
2459 if (bflags & BFLAGS_Instance)
2466 utf8_name = mono_string_to_utf8 (name);
2468 if (strcmp (field->name, utf8_name)) {
2474 return mono_field_get_object (domain, startklass, field);
2476 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
2483 ves_icall_Type_GetFields_internal (MonoReflectionType *type, guint32 bflags, MonoReflectionType *reftype)
2486 GSList *l = NULL, *tmp;
2487 MonoClass *startklass, *klass, *refklass;
2491 MonoClassField *field;
2493 MONO_ARCH_SAVE_REGS;
2495 domain = ((MonoObject *)type)->vtable->domain;
2496 klass = startklass = mono_class_from_mono_type (type->type);
2497 refklass = mono_class_from_mono_type (reftype->type);
2500 for (i = 0; i < klass->field.count; ++i) {
2502 field = &klass->fields [i];
2503 if (mono_field_is_deleted (field))
2505 if ((field->type->attrs & FIELD_ATTRIBUTE_FIELD_ACCESS_MASK) == FIELD_ATTRIBUTE_PUBLIC) {
2506 if (bflags & BFLAGS_Public)
2509 if (bflags & BFLAGS_NonPublic)
2515 if (field->type->attrs & FIELD_ATTRIBUTE_STATIC) {
2516 if (bflags & BFLAGS_Static)
2517 if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
2520 if (bflags & BFLAGS_Instance)
2526 member = (MonoObject*)mono_field_get_object (domain, refklass, field);
2527 l = g_slist_prepend (l, member);
2529 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
2531 len = g_slist_length (l);
2532 res = mono_array_new (domain, mono_defaults.field_info_class, len);
2534 tmp = l = g_slist_reverse (l);
2535 for (; tmp; tmp = tmp->next, ++i)
2536 mono_array_set (res, gpointer, i, tmp->data);
2542 ves_icall_Type_GetMethodsByName (MonoReflectionType *type, MonoString *name, guint32 bflags, MonoBoolean ignore_case, MonoReflectionType *reftype)
2545 GSList *l = NULL, *tmp;
2546 MonoClass *startklass, *klass, *refklass;
2551 GHashTable *method_slots = g_hash_table_new (NULL, NULL);
2552 gchar *mname = NULL;
2553 int (*compare_func) (const char *s1, const char *s2) = NULL;
2555 MONO_ARCH_SAVE_REGS;
2557 domain = ((MonoObject *)type)->vtable->domain;
2558 klass = startklass = mono_class_from_mono_type (type->type);
2559 refklass = mono_class_from_mono_type (reftype->type);
2562 mname = mono_string_to_utf8 (name);
2563 compare_func = (ignore_case) ? g_strcasecmp : strcmp;
2567 for (i = 0; i < klass->method.count; ++i) {
2569 method = klass->methods [i];
2570 if (strcmp (method->name, ".ctor") == 0 || strcmp (method->name, ".cctor") == 0)
2572 if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
2573 if (bflags & BFLAGS_Public)
2576 if (bflags & BFLAGS_NonPublic)
2582 if (method->flags & METHOD_ATTRIBUTE_STATIC) {
2583 if (bflags & BFLAGS_Static)
2584 if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
2587 if (bflags & BFLAGS_Instance)
2595 if (compare_func (mname, method->name))
2600 if (method->slot != -1) {
2601 if (g_hash_table_lookup (method_slots, GUINT_TO_POINTER (method->slot)))
2603 g_hash_table_insert (method_slots, GUINT_TO_POINTER (method->slot), method);
2606 member = (MonoObject*)mono_method_get_object (domain, method, refklass);
2608 l = g_slist_prepend (l, member);
2611 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
2615 res = mono_array_new (domain, mono_defaults.method_info_class, len);
2618 tmp = l = g_slist_reverse (l);
2620 for (; tmp; tmp = tmp->next, ++i)
2621 mono_array_set (res, gpointer, i, tmp->data);
2623 g_hash_table_destroy (method_slots);
2628 ves_icall_Type_GetConstructors_internal (MonoReflectionType *type, guint32 bflags, MonoReflectionType *reftype)
2631 GSList *l = NULL, *tmp;
2632 static MonoClass *System_Reflection_ConstructorInfo;
2633 MonoClass *startklass, *klass, *refklass;
2639 MONO_ARCH_SAVE_REGS;
2641 domain = ((MonoObject *)type)->vtable->domain;
2642 klass = startklass = mono_class_from_mono_type (type->type);
2643 refklass = mono_class_from_mono_type (reftype->type);
2645 for (i = 0; i < klass->method.count; ++i) {
2647 method = klass->methods [i];
2648 if (strcmp (method->name, ".ctor") && strcmp (method->name, ".cctor"))
2650 if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
2651 if (bflags & BFLAGS_Public)
2654 if (bflags & BFLAGS_NonPublic)
2660 if (method->flags & METHOD_ATTRIBUTE_STATIC) {
2661 if (bflags & BFLAGS_Static)
2662 if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
2665 if (bflags & BFLAGS_Instance)
2671 member = (MonoObject*)mono_method_get_object (domain, method, refklass);
2673 l = g_slist_prepend (l, member);
2675 len = g_slist_length (l);
2676 if (!System_Reflection_ConstructorInfo)
2677 System_Reflection_ConstructorInfo = mono_class_from_name (
2678 mono_defaults.corlib, "System.Reflection", "ConstructorInfo");
2679 res = mono_array_new (domain, System_Reflection_ConstructorInfo, len);
2681 tmp = l = g_slist_reverse (l);
2682 for (; tmp; tmp = tmp->next, ++i)
2683 mono_array_set (res, gpointer, i, tmp->data);
2689 ves_icall_Type_GetPropertiesByName (MonoReflectionType *type, MonoString *name, guint32 bflags, MonoBoolean ignore_case, MonoReflectionType *reftype)
2692 GSList *l = NULL, *tmp;
2693 static MonoClass *System_Reflection_PropertyInfo;
2694 MonoClass *startklass, *klass;
2700 GHashTable *method_slots = g_hash_table_new (NULL, NULL);
2701 gchar *propname = NULL;
2702 int (*compare_func) (const char *s1, const char *s2) = NULL;
2704 MONO_ARCH_SAVE_REGS;
2706 domain = ((MonoObject *)type)->vtable->domain;
2707 klass = startklass = mono_class_from_mono_type (type->type);
2709 propname = mono_string_to_utf8 (name);
2710 compare_func = (ignore_case) ? g_strcasecmp : strcmp;
2714 for (i = 0; i < klass->property.count; ++i) {
2715 prop = &klass->properties [i];
2720 if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
2721 if (bflags & BFLAGS_Public)
2724 if (bflags & BFLAGS_NonPublic)
2730 if (method->flags & METHOD_ATTRIBUTE_STATIC) {
2731 if (bflags & BFLAGS_Static)
2732 if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
2735 if (bflags & BFLAGS_Instance)
2744 if (compare_func (propname, prop->name))
2748 if (prop->get && prop->get->slot != -1) {
2749 if (g_hash_table_lookup (method_slots, GUINT_TO_POINTER (prop->get->slot)))
2751 g_hash_table_insert (method_slots, GUINT_TO_POINTER (prop->get->slot), prop);
2753 if (prop->set && prop->set->slot != -1) {
2754 if (g_hash_table_lookup (method_slots, GUINT_TO_POINTER (prop->set->slot)))
2756 g_hash_table_insert (method_slots, GUINT_TO_POINTER (prop->set->slot), prop);
2759 l = g_slist_prepend (l, mono_property_get_object (domain, startklass, prop));
2762 if ((!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent)))
2766 if (!System_Reflection_PropertyInfo)
2767 System_Reflection_PropertyInfo = mono_class_from_name (
2768 mono_defaults.corlib, "System.Reflection", "PropertyInfo");
2769 res = mono_array_new (domain, System_Reflection_PropertyInfo, len);
2772 tmp = l = g_slist_reverse (l);
2774 for (; tmp; tmp = tmp->next, ++i)
2775 mono_array_set (res, gpointer, i, tmp->data);
2777 g_hash_table_destroy (method_slots);
2781 static MonoReflectionEvent *
2782 ves_icall_MonoType_GetEvent (MonoReflectionType *type, MonoString *name, guint32 bflags)
2785 MonoClass *klass, *startklass;
2791 MONO_ARCH_SAVE_REGS;
2793 event_name = mono_string_to_utf8 (name);
2794 klass = startklass = mono_class_from_mono_type (type->type);
2795 domain = mono_object_domain (type);
2798 for (i = 0; i < klass->event.count; i++) {
2799 event = &klass->events [i];
2800 if (strcmp (event->name, event_name))
2803 method = event->add;
2805 method = event->remove;
2807 method = event->raise;
2809 if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
2810 if (!(bflags & BFLAGS_Public))
2813 if (!(bflags & BFLAGS_NonPublic))
2818 if (!(bflags & BFLAGS_NonPublic))
2821 g_free (event_name);
2822 return mono_event_get_object (domain, startklass, event);
2825 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
2828 g_free (event_name);
2833 ves_icall_Type_GetEvents_internal (MonoReflectionType *type, guint32 bflags, MonoReflectionType *reftype)
2836 GSList *l = NULL, *tmp;
2837 static MonoClass *System_Reflection_EventInfo;
2838 MonoClass *startklass, *klass;
2844 MONO_ARCH_SAVE_REGS;
2846 domain = ((MonoObject *)type)->vtable->domain;
2847 klass = startklass = mono_class_from_mono_type (type->type);
2850 for (i = 0; i < klass->event.count; ++i) {
2851 event = &klass->events [i];
2853 method = event->add;
2855 method = event->remove;
2857 method = event->raise;
2859 if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
2860 if (bflags & BFLAGS_Public)
2863 if (bflags & BFLAGS_NonPublic)
2868 if (bflags & BFLAGS_NonPublic)
2874 if (method->flags & METHOD_ATTRIBUTE_STATIC) {
2875 if (bflags & BFLAGS_Static)
2876 if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
2879 if (bflags & BFLAGS_Instance)
2884 if (bflags & BFLAGS_Instance)
2889 l = g_slist_prepend (l, mono_event_get_object (domain, klass, event));
2891 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
2893 len = g_slist_length (l);
2894 if (!System_Reflection_EventInfo)
2895 System_Reflection_EventInfo = mono_class_from_name (
2896 mono_defaults.corlib, "System.Reflection", "EventInfo");
2897 res = mono_array_new (domain, System_Reflection_EventInfo, len);
2900 tmp = l = g_slist_reverse (l);
2902 for (; tmp; tmp = tmp->next, ++i)
2903 mono_array_set (res, gpointer, i, tmp->data);
2908 static MonoReflectionType *
2909 ves_icall_Type_GetNestedType (MonoReflectionType *type, MonoString *name, guint32 bflags)
2912 MonoClass *startklass, *klass;
2917 MONO_ARCH_SAVE_REGS;
2919 domain = ((MonoObject *)type)->vtable->domain;
2920 klass = startklass = mono_class_from_mono_type (type->type);
2921 str = mono_string_to_utf8 (name);
2924 for (tmpn = klass->nested_classes; tmpn; tmpn = tmpn->next) {
2926 nested = tmpn->data;
2927 if ((nested->flags & TYPE_ATTRIBUTE_VISIBILITY_MASK) == TYPE_ATTRIBUTE_NESTED_PUBLIC) {
2928 if (bflags & BFLAGS_Public)
2931 if (bflags & BFLAGS_NonPublic)
2936 if (strcmp (nested->name, str) == 0){
2938 return mono_type_get_object (domain, &nested->byval_arg);
2941 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
2948 ves_icall_Type_GetNestedTypes (MonoReflectionType *type, guint32 bflags)
2951 GSList *l = NULL, *tmp;
2953 MonoClass *startklass, *klass;
2959 MONO_ARCH_SAVE_REGS;
2961 domain = ((MonoObject *)type)->vtable->domain;
2962 klass = startklass = mono_class_from_mono_type (type->type);
2964 for (tmpn = klass->nested_classes; tmpn; tmpn = tmpn->next) {
2966 nested = tmpn->data;
2967 if ((nested->flags & TYPE_ATTRIBUTE_VISIBILITY_MASK) == TYPE_ATTRIBUTE_NESTED_PUBLIC) {
2968 if (bflags & BFLAGS_Public)
2971 if (bflags & BFLAGS_NonPublic)
2976 member = (MonoObject*)mono_type_get_object (domain, &nested->byval_arg);
2977 l = g_slist_prepend (l, member);
2979 len = g_slist_length (l);
2980 res = mono_array_new (domain, mono_defaults.monotype_class, len);
2982 tmp = l = g_slist_reverse (l);
2983 for (; tmp; tmp = tmp->next, ++i)
2984 mono_array_set (res, gpointer, i, tmp->data);
2989 static MonoReflectionType*
2990 ves_icall_System_Reflection_Assembly_InternalGetType (MonoReflectionAssembly *assembly, MonoReflectionModule *module, MonoString *name, MonoBoolean throwOnError, MonoBoolean ignoreCase)
2993 MonoType *type = NULL;
2994 MonoTypeNameParse info;
2996 MONO_ARCH_SAVE_REGS;
2998 str = mono_string_to_utf8 (name);
2999 /*g_print ("requested type %s in %s\n", str, assembly->assembly->aname.name);*/
3000 if (!mono_reflection_parse_type (str, &info)) {
3002 g_list_free (info.modifiers);
3003 g_list_free (info.nested);
3004 if (throwOnError) /* uhm: this is a parse error, though... */
3005 mono_raise_exception (mono_get_exception_type_load (name));
3006 /*g_print ("failed parse\n");*/
3010 if (module != NULL) {
3012 type = mono_reflection_get_type (module->image, &info, ignoreCase);
3017 if (assembly->assembly->dynamic) {
3018 /* Enumerate all modules */
3019 MonoReflectionAssemblyBuilder *abuilder = (MonoReflectionAssemblyBuilder*)assembly;
3023 if (abuilder->modules) {
3024 for (i = 0; i < mono_array_length (abuilder->modules); ++i) {
3025 MonoReflectionModuleBuilder *mb = mono_array_get (abuilder->modules, MonoReflectionModuleBuilder*, i);
3026 type = mono_reflection_get_type (&mb->dynamic_image->image, &info, ignoreCase);
3032 if (!type && abuilder->loaded_modules) {
3033 for (i = 0; i < mono_array_length (abuilder->loaded_modules); ++i) {
3034 MonoReflectionModule *mod = mono_array_get (abuilder->loaded_modules, MonoReflectionModule*, i);
3035 type = mono_reflection_get_type (mod->image, &info, ignoreCase);
3042 type = mono_reflection_get_type (assembly->assembly->image, &info, ignoreCase);
3044 g_list_free (info.modifiers);
3045 g_list_free (info.nested);
3048 mono_raise_exception (mono_get_exception_type_load (name));
3049 /* g_print ("failed find\n"); */
3052 /* g_print ("got it\n"); */
3053 return mono_type_get_object (mono_object_domain (assembly), type);
3058 ves_icall_System_Reflection_Assembly_get_code_base (MonoReflectionAssembly *assembly)
3060 MonoDomain *domain = mono_object_domain (assembly);
3061 MonoAssembly *mass = assembly->assembly;
3066 MONO_ARCH_SAVE_REGS;
3068 absolute = g_build_filename (mass->basedir, mass->image->module_name, NULL);
3069 uri = g_filename_to_uri (absolute, NULL, NULL);
3070 res = mono_string_new (domain, uri);
3077 ves_icall_System_Reflection_Assembly_get_global_assembly_cache (MonoReflectionAssembly *assembly)
3079 MonoAssembly *mass = assembly->assembly;
3081 MONO_ARCH_SAVE_REGS;
3083 return mass->in_gac;
3086 static MonoReflectionAssembly*
3087 ves_icall_System_Reflection_Assembly_load_with_partial_name (MonoString *mname, MonoObject *evidence)
3091 MonoImageOpenStatus status;
3093 MONO_ARCH_SAVE_REGS;
3095 name = mono_string_to_utf8 (mname);
3096 res = mono_assembly_load_with_partial_name (name, &status);
3102 return mono_assembly_get_object (mono_domain_get (), res);
3106 ves_icall_System_Reflection_Assembly_get_location (MonoReflectionAssembly *assembly)
3108 MonoDomain *domain = mono_object_domain (assembly);
3110 char *name = g_build_filename (
3111 assembly->assembly->basedir,
3112 assembly->assembly->image->module_name, NULL);
3114 MONO_ARCH_SAVE_REGS;
3116 res = mono_string_new (domain, name);
3122 ves_icall_System_Reflection_Assembly_InternalImageRuntimeVersion (MonoReflectionAssembly *assembly)
3124 MonoDomain *domain = mono_object_domain (assembly);
3126 MONO_ARCH_SAVE_REGS;
3128 return mono_string_new (domain, assembly->assembly->image->version);
3131 static MonoReflectionMethod*
3132 ves_icall_System_Reflection_Assembly_get_EntryPoint (MonoReflectionAssembly *assembly)
3134 guint32 token = mono_image_get_entry_point (assembly->assembly->image);
3136 MONO_ARCH_SAVE_REGS;
3140 return mono_method_get_object (mono_object_domain (assembly), mono_get_method (assembly->assembly->image, token, NULL), NULL);
3144 ves_icall_System_Reflection_Assembly_GetManifestResourceNames (MonoReflectionAssembly *assembly)
3146 MonoTableInfo *table = &assembly->assembly->image->tables [MONO_TABLE_MANIFESTRESOURCE];
3147 MonoArray *result = mono_array_new (mono_object_domain (assembly), mono_defaults.string_class, table->rows);
3151 MONO_ARCH_SAVE_REGS;
3153 for (i = 0; i < table->rows; ++i) {
3154 val = mono_metadata_string_heap (assembly->assembly->image, mono_metadata_decode_row_col (table, i, MONO_MANIFEST_NAME));
3155 mono_array_set (result, gpointer, i, mono_string_new (mono_object_domain (assembly), val));
3161 ves_icall_System_Reflection_Assembly_GetReferencedAssemblies (MonoReflectionAssembly *assembly)
3163 static MonoClass *System_Reflection_AssemblyName;
3166 MonoDomain *domain = mono_object_domain (assembly);
3169 MONO_ARCH_SAVE_REGS;
3171 if (!System_Reflection_AssemblyName)
3172 System_Reflection_AssemblyName = mono_class_from_name (
3173 mono_defaults.corlib, "System.Reflection", "AssemblyName");
3175 for (ptr = assembly->assembly->image->references; ptr && *ptr; ptr++)
3178 result = mono_array_new (mono_object_domain (assembly), System_Reflection_AssemblyName, count);
3180 for (i = 0; i < count; i++) {
3181 MonoAssembly *assem = assembly->assembly->image->references [i];
3182 MonoReflectionAssemblyName *aname;
3183 char *codebase, *absolute;
3185 aname = (MonoReflectionAssemblyName *) mono_object_new (
3186 domain, System_Reflection_AssemblyName);
3188 aname->name = mono_string_new (domain, assem->aname.name);
3190 aname->major = assem->aname.major;
3191 aname->minor = assem->aname.minor;
3192 aname->build = assem->aname.build;
3193 aname->revision = assem->aname.revision;
3195 absolute = g_build_filename (assem->basedir, assem->image->module_name, NULL);
3196 codebase = g_filename_to_uri (absolute, NULL, NULL);
3197 aname->codebase = mono_string_new (domain, codebase);
3200 mono_array_set (result, gpointer, i, aname);
3211 foreach_namespace (const char* key, gconstpointer val, NameSpaceInfo *info)
3213 MonoString *name = mono_string_new (mono_object_domain (info->res), key);
3215 mono_array_set (info->res, gpointer, info->idx, name);
3220 ves_icall_System_Reflection_Assembly_GetNamespaces (MonoReflectionAssembly *assembly)
3222 MonoImage *img = assembly->assembly->image;
3226 MonoTableInfo *t = &img->tables [MONO_TABLE_EXPORTEDTYPE];
3229 MONO_ARCH_SAVE_REGS;
3231 n = g_hash_table_size (img->name_cache);
3232 res = mono_array_new (mono_object_domain (assembly), mono_defaults.string_class, n);
3235 g_hash_table_foreach (img->name_cache, (GHFunc)foreach_namespace, &info);
3237 /* Add namespaces from the EXPORTEDTYPES table as well */
3240 GPtrArray *nspaces = g_ptr_array_new ();
3241 for (i = 0; i < t->rows; ++i) {
3242 const char *nspace = mono_metadata_string_heap (img, mono_metadata_decode_row_col (t, i, MONO_EXP_TYPE_NAMESPACE));
3243 if (!g_hash_table_lookup (img->name_cache, nspace)) {
3244 g_ptr_array_add (nspaces, (char*)nspace);
3247 if (nspaces->len > 0) {
3248 res2 = mono_array_new (mono_object_domain (assembly), mono_defaults.string_class, n + nspaces->len);
3249 memcpy (mono_array_addr (res2, MonoString*, 0),
3250 mono_array_addr (res, MonoString*, 0),
3251 n * sizeof (MonoString*));
3252 for (i = 0; i < nspaces->len; ++i)
3253 mono_array_set (res2, MonoString*, n + i,
3254 mono_string_new (mono_object_domain (assembly),
3255 g_ptr_array_index (nspaces, i)));
3258 g_ptr_array_free (nspaces, TRUE);
3264 /* move this in some file in mono/util/ */
3266 g_concat_dir_and_file (const char *dir, const char *file)
3268 g_return_val_if_fail (dir != NULL, NULL);
3269 g_return_val_if_fail (file != NULL, NULL);
3272 * If the directory name doesn't have a / on the end, we need
3273 * to add one so we get a proper path to the file
3275 if (dir [strlen(dir) - 1] != G_DIR_SEPARATOR)
3276 return g_strconcat (dir, G_DIR_SEPARATOR_S, file, NULL);
3278 return g_strconcat (dir, file, NULL);
3282 ves_icall_System_Reflection_Assembly_GetManifestResourceInternal (MonoReflectionAssembly *assembly, MonoString *name, gint32 *size, MonoReflectionModule **ref_module)
3284 char *n = mono_string_to_utf8 (name);
3285 MonoTableInfo *table = &assembly->assembly->image->tables [MONO_TABLE_MANIFESTRESOURCE];
3287 guint32 cols [MONO_MANIFEST_SIZE];
3288 guint32 impl, file_idx;
3292 MONO_ARCH_SAVE_REGS;
3294 for (i = 0; i < table->rows; ++i) {
3295 mono_metadata_decode_row (table, i, cols, MONO_MANIFEST_SIZE);
3296 val = mono_metadata_string_heap (assembly->assembly->image, cols [MONO_MANIFEST_NAME]);
3297 if (strcmp (val, n) == 0)
3301 if (i == table->rows)
3304 impl = cols [MONO_MANIFEST_IMPLEMENTATION];
3307 * this code should only be called after obtaining the
3308 * ResourceInfo and handling the other cases.
3310 g_assert ((impl & IMPLEMENTATION_MASK) == IMPLEMENTATION_FILE);
3311 file_idx = impl >> IMPLEMENTATION_BITS;
3313 module = mono_image_load_file_for_image (assembly->assembly->image, file_idx);
3318 module = assembly->assembly->image;
3320 *ref_module = mono_module_get_object (mono_domain_get (), module);
3322 return (void*)mono_image_get_resource (module, cols [MONO_MANIFEST_OFFSET], size);
3326 ves_icall_System_Reflection_Assembly_GetManifestResourceInfoInternal (MonoReflectionAssembly *assembly, MonoString *name, MonoManifestResourceInfo *info)
3328 MonoTableInfo *table = &assembly->assembly->image->tables [MONO_TABLE_MANIFESTRESOURCE];
3330 guint32 cols [MONO_MANIFEST_SIZE];
3331 guint32 file_cols [MONO_FILE_SIZE];
3335 MONO_ARCH_SAVE_REGS;
3337 n = mono_string_to_utf8 (name);
3338 for (i = 0; i < table->rows; ++i) {
3339 mono_metadata_decode_row (table, i, cols, MONO_MANIFEST_SIZE);
3340 val = mono_metadata_string_heap (assembly->assembly->image, cols [MONO_MANIFEST_NAME]);
3341 if (strcmp (val, n) == 0)
3345 if (i == table->rows)
3348 if (!cols [MONO_MANIFEST_IMPLEMENTATION]) {
3349 info->location = RESOURCE_LOCATION_EMBEDDED | RESOURCE_LOCATION_IN_MANIFEST;
3352 switch (cols [MONO_MANIFEST_IMPLEMENTATION] & IMPLEMENTATION_MASK) {
3353 case IMPLEMENTATION_FILE:
3354 i = cols [MONO_MANIFEST_IMPLEMENTATION] >> IMPLEMENTATION_BITS;
3355 table = &assembly->assembly->image->tables [MONO_TABLE_FILE];
3356 mono_metadata_decode_row (table, i - 1, file_cols, MONO_FILE_SIZE);
3357 val = mono_metadata_string_heap (assembly->assembly->image, file_cols [MONO_FILE_NAME]);
3358 info->filename = mono_string_new (mono_object_domain (assembly), val);
3359 if (file_cols [MONO_FILE_FLAGS] && FILE_CONTAINS_NO_METADATA)
3362 info->location = RESOURCE_LOCATION_EMBEDDED;
3365 case IMPLEMENTATION_ASSEMBLYREF:
3366 i = cols [MONO_MANIFEST_IMPLEMENTATION] >> IMPLEMENTATION_BITS;
3367 info->assembly = mono_assembly_get_object (mono_domain_get (), assembly->assembly->image->references [i - 1]);
3369 /* Obtain info recursively */
3370 ves_icall_System_Reflection_Assembly_GetManifestResourceInfoInternal (info->assembly, name, info);
3371 info->location |= RESOURCE_LOCATION_ANOTHER_ASSEMBLY;
3374 case IMPLEMENTATION_EXP_TYPE:
3375 g_assert_not_reached ();
3384 ves_icall_System_Reflection_Assembly_GetFilesInternal (MonoReflectionAssembly *assembly, MonoString *name)
3386 MonoTableInfo *table = &assembly->assembly->image->tables [MONO_TABLE_FILE];
3387 MonoArray *result = NULL;
3392 MONO_ARCH_SAVE_REGS;
3394 /* check hash if needed */
3396 n = mono_string_to_utf8 (name);
3397 for (i = 0; i < table->rows; ++i) {
3398 val = mono_metadata_string_heap (assembly->assembly->image, mono_metadata_decode_row_col (table, i, MONO_FILE_NAME));
3399 if (strcmp (val, n) == 0) {
3402 n = g_concat_dir_and_file (assembly->assembly->basedir, val);
3403 fn = mono_string_new (mono_object_domain (assembly), n);
3405 return (MonoObject*)fn;
3412 for (i = 0; i < table->rows; ++i) {
3413 result = mono_array_new (mono_object_domain (assembly), mono_defaults.string_class, table->rows);
3414 val = mono_metadata_string_heap (assembly->assembly->image, mono_metadata_decode_row_col (table, i, MONO_FILE_NAME));
3415 n = g_concat_dir_and_file (assembly->assembly->basedir, val);
3416 mono_array_set (result, gpointer, i, mono_string_new (mono_object_domain (assembly), n));
3419 return (MonoObject*)result;
3423 ves_icall_System_Reflection_Assembly_GetModulesInternal (MonoReflectionAssembly *assembly)
3425 MonoDomain *domain = mono_domain_get();
3428 int i, module_count = 0, file_count = 0;
3429 MonoImage **modules = assembly->assembly->image->modules;
3430 MonoTableInfo *table;
3433 while (modules[module_count])
3437 table = &assembly->assembly->image->tables [MONO_TABLE_FILE];
3438 file_count = table->rows;
3440 g_assert( assembly->assembly->image != NULL);
3443 klass = mono_class_from_name ( mono_defaults.corlib, "System.Reflection", "Module");
3444 res = mono_array_new (domain, klass, module_count + file_count);
3446 mono_array_set (res, gpointer, 0, mono_module_get_object (domain, assembly->assembly->image));
3447 for ( i = 1; i < module_count; ++i )
3448 mono_array_set (res, gpointer, i, mono_module_get_object (domain, modules[i]));
3450 for (i = 0; i < table->rows; ++i)
3451 mono_array_set (res, gpointer, module_count + i, mono_module_file_get_object (domain, assembly->assembly->image, i));
3456 static MonoReflectionMethod*
3457 ves_icall_GetCurrentMethod (void)
3459 MonoMethod *m = mono_method_get_last_managed ();
3461 MONO_ARCH_SAVE_REGS;
3463 return mono_method_get_object (mono_domain_get (), m, NULL);
3466 static MonoReflectionAssembly*
3467 ves_icall_System_Reflection_Assembly_GetExecutingAssembly (void)
3469 MonoMethod *m = mono_method_get_last_managed ();
3471 MONO_ARCH_SAVE_REGS;
3473 return mono_assembly_get_object (mono_domain_get (), m->klass->image->assembly);
3478 get_caller (MonoMethod *m, gint32 no, gint32 ilo, gboolean managed, gpointer data)
3480 MonoMethod **dest = data;
3482 /* skip unmanaged frames */
3497 static MonoReflectionAssembly*
3498 ves_icall_System_Reflection_Assembly_GetEntryAssembly (void)
3500 MonoDomain* domain = mono_domain_get ();
3502 MONO_ARCH_SAVE_REGS;
3504 if (!domain->entry_assembly)
3505 domain = mono_root_domain;
3507 return mono_assembly_get_object (domain, domain->entry_assembly);
3511 static MonoReflectionAssembly*
3512 ves_icall_System_Reflection_Assembly_GetCallingAssembly (void)
3514 MonoMethod *m = mono_method_get_last_managed ();
3515 MonoMethod *dest = m;
3517 MONO_ARCH_SAVE_REGS;
3519 mono_stack_walk (get_caller, &dest);
3522 return mono_assembly_get_object (mono_domain_get (), dest->klass->image->assembly);
3526 ves_icall_System_MonoType_getFullName (MonoReflectionType *object)
3528 MonoDomain *domain = mono_object_domain (object);
3532 MONO_ARCH_SAVE_REGS;
3534 name = mono_type_get_name (object->type);
3535 res = mono_string_new (domain, name);
3542 fill_reflection_assembly_name (MonoDomain *domain, MonoReflectionAssemblyName *aname, MonoAssemblyName *name, const char *absolute)
3544 static MonoMethod *create_culture = NULL;
3547 const char *pkey_ptr;
3550 MONO_ARCH_SAVE_REGS;
3552 aname->name = mono_string_new (domain, name->name);
3553 aname->major = name->major;
3554 aname->minor = name->minor;
3555 aname->build = name->build;
3556 aname->revision = name->revision;
3557 aname->hashalg = name->hash_alg;
3559 codebase = g_filename_to_uri (absolute, NULL, NULL);
3561 aname->codebase = mono_string_new (domain, codebase);
3565 if (!create_culture) {
3566 MonoMethodDesc *desc = mono_method_desc_new ("System.Globalization.CultureInfo:CreateSpecificCulture(string)", TRUE);
3567 create_culture = mono_method_desc_search_in_image (desc, mono_defaults.corlib);
3568 g_assert (create_culture);
3569 mono_method_desc_free (desc);
3572 args [0] = mono_string_new (domain, name->culture);
3573 aname->cultureInfo =
3574 mono_runtime_invoke (create_culture, NULL, args, NULL);
3576 if (name->public_key) {
3577 pkey_ptr = name->public_key;
3578 pkey_len = mono_metadata_decode_blob_size (pkey_ptr, &pkey_ptr);
3580 aname->publicKey = mono_array_new (domain, mono_defaults.byte_class, pkey_len);
3581 memcpy (mono_array_addr (aname->publicKey, guint8, 0), pkey_ptr, pkey_len);
3586 ves_icall_System_Reflection_Assembly_FillName (MonoReflectionAssembly *assembly, MonoReflectionAssemblyName *aname)
3590 MONO_ARCH_SAVE_REGS;
3592 absolute = g_build_filename (assembly->assembly->basedir, assembly->assembly->image->module_name, NULL);
3594 fill_reflection_assembly_name (mono_object_domain (assembly), aname,
3595 &assembly->assembly->aname, absolute);
3601 ves_icall_System_Reflection_Assembly_InternalGetAssemblyName (MonoString *fname, MonoReflectionAssemblyName *aname)
3604 MonoImageOpenStatus status = MONO_IMAGE_OK;
3607 MonoAssemblyName name;
3609 MONO_ARCH_SAVE_REGS;
3611 filename = mono_string_to_utf8 (fname);
3613 image = mono_image_open (filename, &status);
3619 exc = mono_get_exception_file_not_found (fname);
3620 mono_raise_exception (exc);
3623 res = mono_assembly_fill_assembly_name (image, &name);
3625 mono_image_close (image);
3627 mono_raise_exception (mono_get_exception_argument ("assemblyFile", "The file does not contain a manifest"));
3630 fill_reflection_assembly_name (mono_domain_get (), aname, &name, filename);
3633 mono_image_close (image);
3637 mono_module_get_types (MonoDomain *domain, MonoImage *image,
3638 MonoBoolean exportedOnly)
3642 MonoTableInfo *tdef = &image->tables [MONO_TABLE_TYPEDEF];
3644 guint32 attrs, visibility;
3646 /* we start the count from 1 because we skip the special type <Module> */
3649 for (i = 1; i < tdef->rows; ++i) {
3650 attrs = mono_metadata_decode_row_col (tdef, i, MONO_TYPEDEF_FLAGS);
3651 visibility = attrs & TYPE_ATTRIBUTE_VISIBILITY_MASK;
3652 if (visibility == TYPE_ATTRIBUTE_PUBLIC || visibility == TYPE_ATTRIBUTE_NESTED_PUBLIC)
3656 count = tdef->rows - 1;
3658 res = mono_array_new (domain, mono_defaults.monotype_class, count);
3660 for (i = 1; i < tdef->rows; ++i) {
3661 attrs = mono_metadata_decode_row_col (tdef, i, MONO_TYPEDEF_FLAGS);
3662 visibility = attrs & TYPE_ATTRIBUTE_VISIBILITY_MASK;
3663 if (!exportedOnly || (visibility == TYPE_ATTRIBUTE_PUBLIC || visibility == TYPE_ATTRIBUTE_NESTED_PUBLIC)) {
3664 klass = mono_class_get (image, (i + 1) | MONO_TOKEN_TYPE_DEF);
3665 mono_array_set (res, gpointer, count, mono_type_get_object (domain, &klass->byval_arg));
3674 ves_icall_System_Reflection_Assembly_GetTypes (MonoReflectionAssembly *assembly, MonoBoolean exportedOnly)
3677 MonoImage *image = assembly->assembly->image;
3678 MonoTableInfo *table = &image->tables [MONO_TABLE_FILE];
3682 MONO_ARCH_SAVE_REGS;
3684 domain = mono_object_domain (assembly);
3685 res = mono_module_get_types (domain, image, exportedOnly);
3687 /* Append data from all modules in the assembly */
3688 for (i = 0; i < table->rows; ++i) {
3689 if (!(mono_metadata_decode_row_col (table, i, MONO_FILE_FLAGS) & FILE_CONTAINS_NO_METADATA)) {
3690 MonoImage *loaded_image = mono_assembly_load_module (image->assembly, i + 1);
3692 MonoArray *res2 = mono_module_get_types (domain, loaded_image, exportedOnly);
3693 /* Append the new types to the end of the array */
3694 if (mono_array_length (res2) > 0) {
3698 len1 = mono_array_length (res);
3699 len2 = mono_array_length (res2);
3700 res3 = mono_array_new (domain, mono_defaults.monotype_class, len1 + len2);
3701 memcpy (mono_array_addr (res3, MonoReflectionType*, 0),
3702 mono_array_addr (res, MonoReflectionType*, 0),
3703 len1 * sizeof (MonoReflectionType*));
3704 memcpy (mono_array_addr (res3, MonoReflectionType*, len1),
3705 mono_array_addr (res2, MonoReflectionType*, 0),
3706 len2 * sizeof (MonoReflectionType*));
3716 static MonoReflectionType*
3717 ves_icall_System_Reflection_Module_GetGlobalType (MonoReflectionModule *module)
3719 MonoDomain *domain = mono_object_domain (module);
3722 MONO_ARCH_SAVE_REGS;
3724 g_assert (module->image);
3725 klass = mono_class_get (module->image, 1 | MONO_TOKEN_TYPE_DEF);
3726 return mono_type_get_object (domain, &klass->byval_arg);
3730 ves_icall_System_Reflection_Module_Close (MonoReflectionModule *module)
3733 mono_image_close (module->image);
3737 ves_icall_System_Reflection_Module_GetGuidInternal (MonoReflectionModule *module)
3739 MonoDomain *domain = mono_object_domain (module);
3741 MONO_ARCH_SAVE_REGS;
3743 g_assert (module->image);
3744 return mono_string_new (domain, module->image->guid);
3748 ves_icall_System_Reflection_Module_InternalGetTypes (MonoReflectionModule *module)
3750 MONO_ARCH_SAVE_REGS;
3753 return mono_array_new (mono_object_domain (module), mono_defaults.monotype_class, 0);
3755 return mono_module_get_types (mono_object_domain (module), module->image, FALSE);
3758 static MonoReflectionType*
3759 ves_icall_ModuleBuilder_create_modified_type (MonoReflectionTypeBuilder *tb, MonoString *smodifiers)
3762 int isbyref = 0, rank;
3763 char *str = mono_string_to_utf8 (smodifiers);
3766 MONO_ARCH_SAVE_REGS;
3768 klass = mono_class_from_mono_type (tb->type.type);
3770 /* logic taken from mono_reflection_parse_type(): keep in sync */
3774 if (isbyref) { /* only one level allowed by the spec */
3781 return mono_type_get_object (mono_object_domain (tb), &klass->this_arg);
3784 klass = mono_ptr_class_get (&klass->byval_arg);
3785 mono_class_init (klass);
3796 else if (*p != '*') { /* '*' means unknown lower bound */
3807 klass = mono_array_class_get (klass, rank);
3808 mono_class_init (klass);
3815 return mono_type_get_object (mono_object_domain (tb), &klass->byval_arg);
3819 ves_icall_Type_IsArrayImpl (MonoReflectionType *t)
3824 MONO_ARCH_SAVE_REGS;
3827 res = !type->byref && (type->type == MONO_TYPE_ARRAY || type->type == MONO_TYPE_SZARRAY);
3832 static MonoReflectionType *
3833 ves_icall_Type_make_array_type (MonoReflectionType *type, int rank)
3835 MonoClass *klass, *aklass;
3837 MONO_ARCH_SAVE_REGS;
3839 klass = mono_class_from_mono_type (type->type);
3840 aklass = mono_array_class_get (klass, rank);
3842 return mono_type_get_object (mono_object_domain (type), &aklass->byval_arg);
3845 static MonoReflectionType *
3846 ves_icall_Type_make_byref_type (MonoReflectionType *type)
3850 MONO_ARCH_SAVE_REGS;
3852 klass = mono_class_from_mono_type (type->type);
3854 return mono_type_get_object (mono_object_domain (type), &klass->this_arg);
3858 ves_icall_System_Delegate_CreateDelegate_internal (MonoReflectionType *type, MonoObject *target,
3859 MonoReflectionMethod *info)
3861 MonoClass *delegate_class = mono_class_from_mono_type (type->type);
3862 MonoObject *delegate;
3865 MONO_ARCH_SAVE_REGS;
3867 mono_assert (delegate_class->parent == mono_defaults.multicastdelegate_class);
3869 delegate = mono_object_new (mono_object_domain (type), delegate_class);
3871 func = mono_compile_method (info->method);
3873 mono_delegate_ctor (delegate, target, func);
3879 * Magic number to convert a time which is relative to
3880 * Jan 1, 1970 into a value which is relative to Jan 1, 0001.
3882 #define EPOCH_ADJUST ((guint64)62135596800LL)
3885 * Magic number to convert FILETIME base Jan 1, 1601 to DateTime - base Jan, 1, 0001
3887 #define FILETIME_ADJUST ((guint64)504911232000000000LL)
3890 * This returns Now in UTC
3893 ves_icall_System_DateTime_GetNow (void)
3895 #ifdef PLATFORM_WIN32
3899 GetSystemTime (&st);
3900 SystemTimeToFileTime (&st, &ft);
3901 return (gint64) FILETIME_ADJUST + ((((gint64)ft.dwHighDateTime)<<32) | ft.dwLowDateTime);
3903 /* FIXME: put this in io-layer and call it GetLocalTime */
3907 MONO_ARCH_SAVE_REGS;
3909 if (gettimeofday (&tv, NULL) == 0) {
3910 res = (((gint64)tv.tv_sec + EPOCH_ADJUST)* 1000000 + tv.tv_usec)*10;
3913 /* fixme: raise exception */
3918 #ifdef PLATFORM_WIN32
3919 /* convert a SYSTEMTIME which is of the form "last thursday in october" to a real date */
3921 convert_to_absolute_date(SYSTEMTIME *date)
3923 #define IS_LEAP(y) ((y % 4) == 0 && ((y % 100) != 0 || (y % 400) == 0))
3924 static int days_in_month[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
3925 static int leap_days_in_month[] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
3926 /* from the calendar FAQ */
3927 int a = (14 - date->wMonth) / 12;
3928 int y = date->wYear - a;
3929 int m = date->wMonth + 12 * a - 2;
3930 int d = (1 + y + y/4 - y/100 + y/400 + (31*m)/12) % 7;
3932 /* d is now the day of the week for the first of the month (0 == Sunday) */
3934 int day_of_week = date->wDayOfWeek;
3936 /* set day_in_month to the first day in the month which falls on day_of_week */
3937 int day_in_month = 1 + (day_of_week - d);
3938 if (day_in_month <= 0)
3941 /* wDay is 1 for first weekday in month, 2 for 2nd ... 5 means last - so work that out allowing for days in the month */
3942 date->wDay = day_in_month + (date->wDay - 1) * 7;
3943 if (date->wDay > (IS_LEAP(date->wYear) ? leap_days_in_month[date->wMonth - 1] : days_in_month[date->wMonth - 1]))
3948 #ifndef PLATFORM_WIN32
3950 * Return's the offset from GMT of a local time.
3952 * tm is a local time
3953 * t is the same local time as seconds.
3956 gmt_offset(struct tm *tm, time_t t)
3958 #if defined (HAVE_TM_GMTOFF)
3959 return tm->tm_gmtoff;
3964 g.tm_isdst = tm->tm_isdst;
3966 return (int)difftime(t, t2);
3971 * This is heavily based on zdump.c from glibc 2.2.
3973 * * data[0]: start of daylight saving time (in DateTime ticks).
3974 * * data[1]: end of daylight saving time (in DateTime ticks).
3975 * * data[2]: utcoffset (in TimeSpan ticks).
3976 * * data[3]: additional offset when daylight saving (in TimeSpan ticks).
3977 * * name[0]: name of this timezone when not daylight saving.
3978 * * name[1]: name of this timezone when daylight saving.
3980 * FIXME: This only works with "standard" Unix dates (years between 1900 and 2100) while
3981 * the class library allows years between 1 and 9999.
3983 * Returns true on success and zero on failure.
3986 ves_icall_System_CurrentTimeZone_GetTimeZoneData (guint32 year, MonoArray **data, MonoArray **names)
3988 #ifndef PLATFORM_WIN32
3989 MonoDomain *domain = mono_domain_get ();
3990 struct tm start, tt;
3994 int is_daylight = 0, day;
3997 MONO_ARCH_SAVE_REGS;
3999 MONO_CHECK_ARG_NULL (data);
4000 MONO_CHECK_ARG_NULL (names);
4002 (*data) = mono_array_new (domain, mono_defaults.int64_class, 4);
4003 (*names) = mono_array_new (domain, mono_defaults.string_class, 2);
4006 * no info is better than crashing: we'll need our own tz data to make
4007 * this work properly, anyway. The range is reduced to 1970 .. 2037 because
4008 * that is what mktime is guaranteed to support (we get into an infinite loop
4011 if ((year < 1970) || (year > 2037)) {
4013 tt = *localtime (&t);
4014 strftime (tzone, sizeof (tzone), "%Z", &tt);
4015 mono_array_set ((*names), gpointer, 0, mono_string_new (domain, tzone));
4016 mono_array_set ((*names), gpointer, 1, mono_string_new (domain, tzone));
4020 memset (&start, 0, sizeof (start));
4023 start.tm_year = year-1900;
4025 t = mktime (&start);
4026 gmtoff = gmt_offset (&start, t);
4028 /* For each day of the year, calculate the tm_gmtoff. */
4029 for (day = 0; day < 365; day++) {
4032 tt = *localtime (&t);
4034 /* Daylight saving starts or ends here. */
4035 if (gmt_offset (&tt, t) != gmtoff) {
4039 /* Try to find the exact hour when daylight saving starts/ends. */
4043 tt1 = *localtime (&t1);
4044 } while (gmt_offset (&tt1, t1) != gmtoff);
4046 /* Try to find the exact minute when daylight saving starts/ends. */
4049 tt1 = *localtime (&t1);
4050 } while (gmt_offset (&tt1, t1) == gmtoff);
4052 strftime (tzone, sizeof (tzone), "%Z", &tt);
4054 /* Write data, if we're already in daylight saving, we're done. */
4056 mono_array_set ((*names), gpointer, 0, mono_string_new (domain, tzone));
4057 mono_array_set ((*data), gint64, 1, ((gint64)t1 + EPOCH_ADJUST) * 10000000L);
4060 mono_array_set ((*names), gpointer, 1, mono_string_new (domain, tzone));
4061 mono_array_set ((*data), gint64, 0, ((gint64)t1 + EPOCH_ADJUST) * 10000000L);
4065 /* This is only set once when we enter daylight saving. */
4066 mono_array_set ((*data), gint64, 2, (gint64)gmtoff * 10000000L);
4067 mono_array_set ((*data), gint64, 3, (gint64)(gmt_offset (&tt, t) - gmtoff) * 10000000L);
4069 gmtoff = gmt_offset (&tt, t);
4074 strftime (tzone, sizeof (tzone), "%Z", &tt);
4075 mono_array_set ((*names), gpointer, 0, mono_string_new (domain, tzone));
4076 mono_array_set ((*names), gpointer, 1, mono_string_new (domain, tzone));
4077 mono_array_set ((*data), gint64, 0, 0);
4078 mono_array_set ((*data), gint64, 1, 0);
4079 mono_array_set ((*data), gint64, 2, (gint64) gmtoff * 10000000L);
4080 mono_array_set ((*data), gint64, 3, 0);
4085 MonoDomain *domain = mono_domain_get ();
4086 TIME_ZONE_INFORMATION tz_info;
4091 tz_id = GetTimeZoneInformation (&tz_info);
4092 if (tz_id == TIME_ZONE_ID_INVALID)
4095 MONO_CHECK_ARG_NULL (data);
4096 MONO_CHECK_ARG_NULL (names);
4098 (*data) = mono_array_new (domain, mono_defaults.int64_class, 4);
4099 (*names) = mono_array_new (domain, mono_defaults.string_class, 2);
4101 for (i = 0; i < 32; ++i)
4102 if (!tz_info.DaylightName [i])
4104 mono_array_set ((*names), gpointer, 1, mono_string_new_utf16 (domain, tz_info.DaylightName, i));
4105 for (i = 0; i < 32; ++i)
4106 if (!tz_info.StandardName [i])
4108 mono_array_set ((*names), gpointer, 0, mono_string_new_utf16 (domain, tz_info.StandardName, i));
4110 if ((year <= 1601) || (year > 30827)) {
4112 * According to MSDN, the MS time functions can't handle dates outside
4118 /* even if the timezone has no daylight savings it may have Bias (e.g. GMT+13 it seems) */
4119 if (tz_id != TIME_ZONE_ID_UNKNOWN) {
4120 tz_info.StandardDate.wYear = year;
4121 convert_to_absolute_date(&tz_info.StandardDate);
4122 err = SystemTimeToFileTime (&tz_info.StandardDate, &ft);
4124 mono_array_set ((*data), gint64, 1, FILETIME_ADJUST + (((guint64)ft.dwHighDateTime<<32) | ft.dwLowDateTime));
4125 tz_info.DaylightDate.wYear = year;
4126 convert_to_absolute_date(&tz_info.DaylightDate);
4127 err = SystemTimeToFileTime (&tz_info.DaylightDate, &ft);
4129 mono_array_set ((*data), gint64, 0, FILETIME_ADJUST + (((guint64)ft.dwHighDateTime<<32) | ft.dwLowDateTime));
4131 mono_array_set ((*data), gint64, 2, (tz_info.Bias + tz_info.StandardBias) * -600000000LL);
4132 mono_array_set ((*data), gint64, 3, (tz_info.DaylightBias - tz_info.StandardBias) * -600000000LL);
4139 ves_icall_System_Object_obj_address (MonoObject *this)
4141 MONO_ARCH_SAVE_REGS;
4148 static inline gint32
4149 mono_array_get_byte_length (MonoArray *array)
4155 klass = array->obj.vtable->klass;
4157 if (array->bounds == NULL)
4158 length = array->max_length;
4161 for (i = 0; i < klass->rank; ++ i)
4162 length *= array->bounds [i].length;
4165 switch (klass->element_class->byval_arg.type) {
4168 case MONO_TYPE_BOOLEAN:
4172 case MONO_TYPE_CHAR:
4180 return length * sizeof (gpointer);
4191 ves_icall_System_Buffer_ByteLengthInternal (MonoArray *array)
4193 MONO_ARCH_SAVE_REGS;
4195 return mono_array_get_byte_length (array);
4199 ves_icall_System_Buffer_GetByteInternal (MonoArray *array, gint32 idx)
4201 MONO_ARCH_SAVE_REGS;
4203 return mono_array_get (array, gint8, idx);
4207 ves_icall_System_Buffer_SetByteInternal (MonoArray *array, gint32 idx, gint8 value)
4209 MONO_ARCH_SAVE_REGS;
4211 mono_array_set (array, gint8, idx, value);
4215 ves_icall_System_Buffer_BlockCopyInternal (MonoArray *src, gint32 src_offset, MonoArray *dest, gint32 dest_offset, gint32 count)
4217 char *src_buf, *dest_buf;
4219 MONO_ARCH_SAVE_REGS;
4221 /* watch out for integer overflow */
4222 if ((src_offset > mono_array_get_byte_length (src) - count) || (dest_offset > mono_array_get_byte_length (dest) - count))
4225 src_buf = (gint8 *)src->vector + src_offset;
4226 dest_buf = (gint8 *)dest->vector + dest_offset;
4228 memcpy (dest_buf, src_buf, count);
4234 ves_icall_Remoting_RealProxy_GetTransparentProxy (MonoObject *this, MonoString *class_name)
4236 MonoDomain *domain = mono_object_domain (this);
4238 MonoRealProxy *rp = ((MonoRealProxy *)this);
4239 MonoTransparentProxy *tp;
4243 MONO_ARCH_SAVE_REGS;
4245 res = mono_object_new (domain, mono_defaults.transparent_proxy_class);
4246 tp = (MonoTransparentProxy*) res;
4249 type = ((MonoReflectionType *)rp->class_to_proxy)->type;
4250 klass = mono_class_from_mono_type (type);
4252 tp->custom_type_info = (mono_object_isinst (this, mono_defaults.iremotingtypeinfo_class) != NULL);
4253 tp->remote_class = mono_remote_class (domain, class_name, klass);
4254 res->vtable = tp->remote_class->vtable;
4259 static MonoReflectionType *
4260 ves_icall_Remoting_RealProxy_InternalGetProxyType (MonoTransparentProxy *tp)
4262 return mono_type_get_object (mono_object_domain (tp), &tp->remote_class->proxy_class->byval_arg);
4265 /* System.Environment */
4268 ves_icall_System_Environment_get_MachineName (void)
4270 #if defined (PLATFORM_WIN32)
4275 len = MAX_COMPUTERNAME_LENGTH + 1;
4276 buf = g_new (gunichar2, len);
4279 if (GetComputerName (buf, (PDWORD) &len))
4280 result = mono_string_new_utf16 (mono_domain_get (), buf, len);
4289 MONO_ARCH_SAVE_REGS;
4292 buf = g_new (gchar, len);
4295 if (gethostname (buf, len) == 0)
4296 result = mono_string_new (mono_domain_get (), buf);
4304 ves_icall_System_Environment_get_Platform (void)
4306 MONO_ARCH_SAVE_REGS;
4308 #if defined (PLATFORM_WIN32)
4318 ves_icall_System_Environment_get_NewLine (void)
4320 MONO_ARCH_SAVE_REGS;
4322 #if defined (PLATFORM_WIN32)
4323 return mono_string_new (mono_domain_get (), "\r\n");
4325 return mono_string_new (mono_domain_get (), "\n");
4330 ves_icall_System_Environment_GetEnvironmentVariable (MonoString *name)
4335 MONO_ARCH_SAVE_REGS;
4340 utf8_name = mono_string_to_utf8 (name); /* FIXME: this should be ascii */
4341 value = g_getenv (utf8_name);
4347 return mono_string_new (mono_domain_get (), value);
4351 * There is no standard way to get at environ.
4359 ves_icall_System_Environment_GetEnvironmentVariableNames (void)
4367 MONO_ARCH_SAVE_REGS;
4370 for (e = environ; *e != 0; ++ e)
4373 domain = mono_domain_get ();
4374 names = mono_array_new (domain, mono_defaults.string_class, n);
4377 for (e = environ; *e != 0; ++ e) {
4378 parts = g_strsplit (*e, "=", 2);
4380 str = mono_string_new (domain, *parts);
4381 mono_array_set (names, MonoString *, n, str);
4393 * Returns the number of milliseconds elapsed since the system started.
4396 ves_icall_System_Environment_get_TickCount (void)
4398 #if defined (PLATFORM_WIN32)
4399 return GetTickCount();
4405 MONO_ARCH_SAVE_REGS;
4407 res = (gint32) gettimeofday (&tv, &tz);
4410 res = (gint32) ((tv.tv_sec & 0xFFFFF) * 1000 + (tv.tv_usec / 1000));
4417 ves_icall_System_Environment_Exit (int result)
4419 MONO_ARCH_SAVE_REGS;
4421 mono_runtime_quit ();
4423 /* we may need to do some cleanup here... */
4428 ves_icall_System_Environment_GetGacPath (void)
4430 return mono_string_new (mono_domain_get (), mono_assembly_getrootdir ());
4434 ves_icall_System_Environment_GetWindowsFolderPath (int folder)
4436 #if defined (PLATFORM_WIN32)
4437 #ifndef CSIDL_FLAG_CREATE
4438 #define CSIDL_FLAG_CREATE 0x8000
4441 WCHAR path [MAX_PATH];
4442 /* Create directory if no existing */
4443 if (SUCCEEDED (SHGetFolderPathW (NULL, folder | CSIDL_FLAG_CREATE, NULL, 0, path))) {
4447 return mono_string_new_utf16 (mono_domain_get (), path, len);
4450 g_warning ("ves_icall_System_Environment_GetWindowsFolderPath should only be called on Windows!");
4452 return mono_string_new (mono_domain_get (), "");
4456 ves_icall_System_Environment_GetLogicalDrives (void)
4458 gunichar2 buf [128], *ptr, *dname;
4460 gint initial_size = 127, size = 128;
4463 MonoString *drivestr;
4464 MonoDomain *domain = mono_domain_get ();
4466 MONO_ARCH_SAVE_REGS;
4471 while (size > initial_size) {
4472 size = GetLogicalDriveStrings (initial_size, ptr);
4473 if (size > initial_size) {
4476 ptr = g_malloc0 ((size + 1) * sizeof (gunichar2));
4477 initial_size = size;
4491 result = mono_array_new (domain, mono_defaults.string_class, ndrives);
4494 u8 = g_utf16_to_utf8 (dname, -1, NULL, NULL, NULL);
4495 drivestr = mono_string_new (domain, u8);
4497 mono_array_set (result, gpointer, ndrives++, drivestr);
4507 static const char *encodings [] = {
4509 "ascii", "us_ascii", "us", "ansi_x3.4_1968",
4510 "ansi_x3.4_1986", "cp367", "csascii", "ibm367",
4511 "iso_ir_6", "iso646_us", "iso_646.irv:1991",
4513 "utf_7", "csunicode11utf7", "unicode_1_1_utf_7",
4514 "unicode_2_0_utf_7", "x_unicode_1_1_utf_7",
4515 "x_unicode_2_0_utf_7",
4517 "utf_8", "unicode_1_1_utf_8", "unicode_2_0_utf_8",
4518 "x_unicode_1_1_utf_8", "x_unicode_2_0_utf_8",
4520 "utf_16", "UTF_16LE", "ucs_2", "unicode",
4523 "unicodefffe", "utf_16be",
4530 * Returns the internal codepage, if the value of "int_code_page" is
4531 * 1 at entry, and we can not compute a suitable code page number,
4532 * returns the code page as a string
4535 ves_icall_System_Text_Encoding_InternalCodePage (gint32 *int_code_page)
4539 char *codepage = NULL;
4541 int want_name = *int_code_page;
4544 *int_code_page = -1;
4545 MONO_ARCH_SAVE_REGS;
4547 g_get_charset (&cset);
4548 p = codepage = strdup (cset);
4549 for (p = codepage; *p; p++){
4550 if (isascii (*p) && isalpha (*p))
4555 /* g_print ("charset: %s\n", cset); */
4557 /* handle some common aliases */
4560 for (i = 0; p != 0; ){
4563 p = encodings [++i];
4566 if (strcmp (p, codepage) == 0){
4567 *int_code_page = code;
4570 p = encodings [++i];
4573 if (strstr (codepage, "utf_8") != NULL)
4574 *int_code_page |= 0x10000000;
4577 if (want_name && *int_code_page == -1)
4578 return mono_string_new (mono_domain_get (), cset);
4584 ves_icall_System_Environment_get_HasShutdownStarted (void)
4586 if (mono_runtime_is_shutting_down ())
4589 if (mono_domain_is_unloading (mono_domain_get ()))
4596 ves_icall_MonoMethodMessage_InitMessage (MonoMethodMessage *this,
4597 MonoReflectionMethod *method,
4598 MonoArray *out_args)
4600 MONO_ARCH_SAVE_REGS;
4602 mono_message_init (mono_object_domain (this), this, method, out_args);
4606 ves_icall_IsTransparentProxy (MonoObject *proxy)
4608 MONO_ARCH_SAVE_REGS;
4613 if (proxy->vtable->klass == mono_defaults.transparent_proxy_class)
4620 ves_icall_System_Runtime_Activation_ActivationServices_EnableProxyActivation (MonoReflectionType *type, MonoBoolean enable)
4625 MONO_ARCH_SAVE_REGS;
4627 klass = mono_class_from_mono_type (type->type);
4628 vtable = mono_class_vtable (mono_domain_get (), klass);
4630 if (enable) vtable->remote = 1;
4631 else vtable->remote = 0;
4635 ves_icall_System_Runtime_Activation_ActivationServices_AllocateUninitializedClassInstance (MonoReflectionType *type)
4640 MONO_ARCH_SAVE_REGS;
4642 domain = mono_object_domain (type);
4643 klass = mono_class_from_mono_type (type->type);
4645 if (klass->rank >= 1) {
4646 g_assert (klass->rank == 1);
4647 return (MonoObject *) mono_array_new (domain, klass->element_class, 0);
4649 /* Bypass remoting object creation check */
4650 return mono_object_new_alloc_specific (mono_class_vtable (domain, klass));
4655 ves_icall_System_IO_get_temp_path (void)
4657 MONO_ARCH_SAVE_REGS;
4659 return mono_string_new (mono_domain_get (), g_get_tmp_dir ());
4663 ves_icall_RuntimeMethod_GetFunctionPointer (MonoMethod *method)
4665 MONO_ARCH_SAVE_REGS;
4667 return mono_compile_method (method);
4671 ves_icall_System_Configuration_DefaultConfig_get_machine_config_path (void)
4676 MONO_ARCH_SAVE_REGS;
4678 path = g_build_path (G_DIR_SEPARATOR_S, mono_get_config_dir (), "mono", "machine.config", NULL);
4680 #if defined (PLATFORM_WIN32)
4681 /* Avoid mixing '/' and '\\' */
4684 for (i = strlen (path) - 1; i >= 0; i--)
4685 if (path [i] == '/')
4689 mcpath = mono_string_new (mono_domain_get (), path);
4696 ves_icall_System_Web_Util_ICalls_get_machine_install_dir (void)
4701 MONO_ARCH_SAVE_REGS;
4703 path = g_path_get_dirname (mono_get_config_dir ());
4705 #if defined (PLATFORM_WIN32)
4706 /* Avoid mixing '/' and '\\' */
4709 for (i = strlen (path) - 1; i >= 0; i--)
4710 if (path [i] == '/')
4714 ipath = mono_string_new (mono_domain_get (), path);
4721 ves_icall_System_Diagnostics_DefaultTraceListener_WriteWindowsDebugString (MonoString *message)
4723 #if defined (PLATFORM_WIN32)
4724 static void (*output_debug) (gchar *);
4725 static gboolean tried_loading = FALSE;
4727 MONO_ARCH_SAVE_REGS;
4729 if (!tried_loading && output_debug == NULL) {
4732 tried_loading = TRUE;
4733 k32 = g_module_open ("kernel32", G_MODULE_BIND_LAZY);
4735 gchar *error = g_strdup (g_module_error ());
4736 g_warning ("Failed to load kernel32.dll: %s\n", error);
4741 g_module_symbol (k32, "OutputDebugStringW", (gpointer *) &output_debug);
4742 if (!output_debug) {
4743 gchar *error = g_strdup (g_module_error ());
4744 g_warning ("Failed to load OutputDebugStringW: %s\n", error);
4750 if (output_debug == NULL)
4753 output_debug (mono_string_chars (message));
4755 g_warning ("WriteWindowsDebugString called and PLATFORM_WIN32 not defined!\n");
4759 /* Only used for value types */
4761 ves_icall_System_Activator_CreateInstanceInternal (MonoReflectionType *type)
4766 MONO_ARCH_SAVE_REGS;
4768 domain = mono_object_domain (type);
4769 klass = mono_class_from_mono_type (type->type);
4771 return mono_object_new (domain, klass);
4774 static MonoReflectionMethod *
4775 ves_icall_MonoMethod_get_base_definition (MonoReflectionMethod *m)
4778 MonoMethod *method = m->method;
4779 MonoMethod *result = NULL;
4781 MONO_ARCH_SAVE_REGS;
4783 if (!(method->flags & METHOD_ATTRIBUTE_VIRTUAL) ||
4784 MONO_CLASS_IS_INTERFACE (method->klass) ||
4785 method->flags & METHOD_ATTRIBUTE_NEW_SLOT)
4788 if (method->klass == NULL || (klass = method->klass->parent) == NULL)
4791 if (klass->generic_inst)
4792 klass = mono_class_from_mono_type (klass->generic_inst->generic_type);
4794 while (result == NULL && klass != NULL && (klass->vtable_size > method->slot))
4796 result = klass->vtable [method->slot];
4797 if (result == NULL) {
4798 /* It is an abstract method */
4800 for (i=0; i<klass->method.count; i++) {
4801 if (klass->methods [i]->slot == method->slot) {
4802 result = klass->methods [i];
4807 klass = klass->parent;
4813 return mono_method_get_object (mono_domain_get (), result, NULL);
4817 mono_ArgIterator_Setup (MonoArgIterator *iter, char* argsp, char* start)
4819 MONO_ARCH_SAVE_REGS;
4821 iter->sig = *(MonoMethodSignature**)argsp;
4823 g_assert (iter->sig->sentinelpos <= iter->sig->param_count);
4824 g_assert (iter->sig->call_convention == MONO_CALL_VARARG);
4827 /* FIXME: it's not documented what start is exactly... */
4828 iter->args = start? start: argsp + sizeof (gpointer);
4829 iter->num_args = iter->sig->param_count - iter->sig->sentinelpos;
4831 /* g_print ("sig %p, param_count: %d, sent: %d\n", iter->sig, iter->sig->param_count, iter->sig->sentinelpos); */
4835 mono_ArgIterator_IntGetNextArg (MonoArgIterator *iter)
4837 gint i, align, arg_size;
4839 MONO_ARCH_SAVE_REGS;
4841 i = iter->sig->sentinelpos + iter->next_arg;
4843 g_assert (i < iter->sig->param_count);
4845 res.type = iter->sig->params [i];
4846 res.klass = mono_class_from_mono_type (res.type);
4847 /* FIXME: endianess issue... */
4848 res.value = iter->args;
4849 arg_size = mono_type_stack_size (res.type, &align);
4850 iter->args = (char*)iter->args + arg_size;
4853 //g_print ("returning arg %d, type 0x%02x of size %d at %p\n", i, res.type->type, arg_size, res.value);
4859 mono_ArgIterator_IntGetNextArgT (MonoArgIterator *iter, MonoType *type)
4861 gint i, align, arg_size;
4863 MONO_ARCH_SAVE_REGS;
4865 i = iter->sig->sentinelpos + iter->next_arg;
4867 g_assert (i < iter->sig->param_count);
4869 while (i < iter->sig->param_count) {
4870 if (!mono_metadata_type_equal (type, iter->sig->params [i]))
4872 res.type = iter->sig->params [i];
4873 res.klass = mono_class_from_mono_type (res.type);
4874 /* FIXME: endianess issue... */
4875 res.value = iter->args;
4876 arg_size = mono_type_stack_size (res.type, &align);
4877 iter->args = (char*)iter->args + arg_size;
4879 //g_print ("returning arg %d, type 0x%02x of size %d at %p\n", i, res.type->type, arg_size, res.value);
4882 //g_print ("arg type 0x%02x not found\n", res.type->type);
4891 mono_ArgIterator_IntGetNextArgType (MonoArgIterator *iter)
4894 MONO_ARCH_SAVE_REGS;
4896 i = iter->sig->sentinelpos + iter->next_arg;
4898 g_assert (i < iter->sig->param_count);
4900 return iter->sig->params [i];
4904 mono_TypedReference_ToObject (MonoTypedRef tref)
4906 MONO_ARCH_SAVE_REGS;
4908 if (MONO_TYPE_IS_REFERENCE (tref.type)) {
4909 MonoObject** objp = tref.value;
4913 return mono_value_box (mono_domain_get (), tref.klass, tref.value);
4917 prelink_method (MonoMethod *method)
4919 const char *exc_class, *exc_arg;
4920 if (!(method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL))
4922 mono_lookup_pinvoke_call (method, &exc_class, &exc_arg);
4924 mono_raise_exception(
4925 mono_exception_from_name_msg (mono_defaults.corlib, "System", exc_class, exc_arg ) );
4927 /* create the wrapper, too? */
4931 ves_icall_System_Runtime_InteropServices_Marshal_Prelink (MonoReflectionMethod *method)
4933 MONO_ARCH_SAVE_REGS;
4934 prelink_method (method->method);
4938 ves_icall_System_Runtime_InteropServices_Marshal_PrelinkAll (MonoReflectionType *type)
4940 MonoClass *klass = mono_class_from_mono_type (type->type);
4942 MONO_ARCH_SAVE_REGS;
4944 mono_class_init (klass);
4945 for (i = 0; i < klass->method.count; ++i)
4946 prelink_method (klass->methods [i]);
4950 ves_icall_System_Char_GetDataTablePointers (guint8 **category_data, guint8 **numeric_data,
4951 gdouble **numeric_data_values, guint16 **to_lower_data_low,
4952 guint16 **to_lower_data_high, guint16 **to_upper_data_low,
4953 guint16 **to_upper_data_high)
4955 *category_data = CategoryData;
4956 *numeric_data = NumericData;
4957 *numeric_data_values = NumericDataValues;
4958 *to_lower_data_low = ToLowerDataLow;
4959 *to_lower_data_high = ToLowerDataHigh;
4960 *to_upper_data_low = ToUpperDataLow;
4961 *to_upper_data_high = ToUpperDataHigh;
4972 const IcallEntry *icalls;
4976 static const IcallEntry activator_icalls [] = {
4977 {"CreateInstanceInternal", ves_icall_System_Activator_CreateInstanceInternal}
4979 static const IcallEntry appdomain_icalls [] = {
4980 {"ExecuteAssembly", ves_icall_System_AppDomain_ExecuteAssembly},
4981 {"GetAssemblies", ves_icall_System_AppDomain_GetAssemblies},
4982 {"GetData", ves_icall_System_AppDomain_GetData},
4983 {"InternalGetContext", ves_icall_System_AppDomain_InternalGetContext},
4984 {"InternalGetDefaultContext", ves_icall_System_AppDomain_InternalGetDefaultContext},
4985 {"InternalGetProcessGuid", ves_icall_System_AppDomain_InternalGetProcessGuid},
4986 {"InternalIsFinalizingForUnload", ves_icall_System_AppDomain_InternalIsFinalizingForUnload},
4987 {"InternalPopDomainRef", ves_icall_System_AppDomain_InternalPopDomainRef},
4988 {"InternalPushDomainRef", ves_icall_System_AppDomain_InternalPushDomainRef},
4989 {"InternalPushDomainRefByID", ves_icall_System_AppDomain_InternalPushDomainRefByID},
4990 {"InternalSetContext", ves_icall_System_AppDomain_InternalSetContext},
4991 {"InternalSetDomain", ves_icall_System_AppDomain_InternalSetDomain},
4992 {"InternalSetDomainByID", ves_icall_System_AppDomain_InternalSetDomainByID},
4993 {"InternalUnload", ves_icall_System_AppDomain_InternalUnload},
4994 {"LoadAssembly", ves_icall_System_AppDomain_LoadAssembly},
4995 {"LoadAssemblyRaw", ves_icall_System_AppDomain_LoadAssemblyRaw},
4996 {"SetData", ves_icall_System_AppDomain_SetData},
4997 {"createDomain", ves_icall_System_AppDomain_createDomain},
4998 {"getCurDomain", ves_icall_System_AppDomain_getCurDomain},
4999 {"getFriendlyName", ves_icall_System_AppDomain_getFriendlyName},
5000 {"getSetup", ves_icall_System_AppDomain_getSetup}
5003 static const IcallEntry argiterator_icalls [] = {
5004 {"IntGetNextArg()", mono_ArgIterator_IntGetNextArg},
5005 {"IntGetNextArg(intptr)", mono_ArgIterator_IntGetNextArgT},
5006 {"IntGetNextArgType", mono_ArgIterator_IntGetNextArgType},
5007 {"Setup", mono_ArgIterator_Setup}
5010 static const IcallEntry array_icalls [] = {
5011 {"Clone", mono_array_clone},
5012 {"CreateInstanceImpl", ves_icall_System_Array_CreateInstanceImpl},
5013 {"FastCopy", ves_icall_System_Array_FastCopy},
5014 {"GetLength", ves_icall_System_Array_GetLength},
5015 {"GetLowerBound", ves_icall_System_Array_GetLowerBound},
5016 {"GetRank", ves_icall_System_Array_GetRank},
5017 {"GetValue", ves_icall_System_Array_GetValue},
5018 {"GetValueImpl", ves_icall_System_Array_GetValueImpl},
5019 {"SetValue", ves_icall_System_Array_SetValue},
5020 {"SetValueImpl", ves_icall_System_Array_SetValueImpl}
5023 static const IcallEntry buffer_icalls [] = {
5024 {"BlockCopyInternal", ves_icall_System_Buffer_BlockCopyInternal},
5025 {"ByteLengthInternal", ves_icall_System_Buffer_ByteLengthInternal},
5026 {"GetByteInternal", ves_icall_System_Buffer_GetByteInternal},
5027 {"SetByteInternal", ves_icall_System_Buffer_SetByteInternal}
5030 static const IcallEntry char_icalls [] = {
5031 {"GetDataTablePointers", ves_icall_System_Char_GetDataTablePointers},
5032 {"InternalToLower(char,System.Globalization.CultureInfo)", ves_icall_System_Char_InternalToLower_Comp},
5033 {"InternalToUpper(char,System.Globalization.CultureInfo)", ves_icall_System_Char_InternalToUpper_Comp}
5036 static const IcallEntry defaultconf_icalls [] = {
5037 {"get_machine_config_path", ves_icall_System_Configuration_DefaultConfig_get_machine_config_path}
5040 static const IcallEntry timezone_icalls [] = {
5041 {"GetTimeZoneData", ves_icall_System_CurrentTimeZone_GetTimeZoneData}
5044 static const IcallEntry datetime_icalls [] = {
5045 {"GetNow", ves_icall_System_DateTime_GetNow}
5048 static const IcallEntry decimal_icalls [] = {
5049 {"decimal2Int64", mono_decimal2Int64},
5050 {"decimal2UInt64", mono_decimal2UInt64},
5051 {"decimal2double", mono_decimal2double},
5052 {"decimal2string", mono_decimal2string},
5053 {"decimalCompare", mono_decimalCompare},
5054 {"decimalDiv", mono_decimalDiv},
5055 {"decimalFloorAndTrunc", mono_decimalFloorAndTrunc},
5056 {"decimalIncr", mono_decimalIncr},
5057 {"decimalIntDiv", mono_decimalIntDiv},
5058 {"decimalMult", mono_decimalMult},
5059 {"decimalRound", mono_decimalRound},
5060 {"decimalSetExponent", mono_decimalSetExponent},
5061 {"double2decimal", mono_double2decimal}, /* FIXME: wrong signature. */
5062 {"string2decimal", mono_string2decimal}
5065 static const IcallEntry delegate_icalls [] = {
5066 {"CreateDelegate_internal", ves_icall_System_Delegate_CreateDelegate_internal}
5069 static const IcallEntry tracelist_icalls [] = {
5070 {"WriteWindowsDebugString", ves_icall_System_Diagnostics_DefaultTraceListener_WriteWindowsDebugString}
5073 static const IcallEntry fileversion_icalls [] = {
5074 {"GetVersionInfo_internal(string)", ves_icall_System_Diagnostics_FileVersionInfo_GetVersionInfo_internal}
5077 static const IcallEntry process_icalls [] = {
5078 {"ExitCode_internal(intptr)", ves_icall_System_Diagnostics_Process_ExitCode_internal},
5079 {"ExitTime_internal(intptr)", ves_icall_System_Diagnostics_Process_ExitTime_internal},
5080 {"GetModules_internal()", ves_icall_System_Diagnostics_Process_GetModules_internal},
5081 {"GetPid_internal()", ves_icall_System_Diagnostics_Process_GetPid_internal},
5082 {"GetProcess_internal(int)", ves_icall_System_Diagnostics_Process_GetProcess_internal},
5083 {"GetProcesses_internal()", ves_icall_System_Diagnostics_Process_GetProcesses_internal},
5084 {"GetWorkingSet_internal(intptr,int&,int&)", ves_icall_System_Diagnostics_Process_GetWorkingSet_internal},
5085 {"Kill_internal", ves_icall_System_Diagnostics_Process_Kill_internal},
5086 {"ProcessName_internal(intptr)", ves_icall_System_Diagnostics_Process_ProcessName_internal},
5087 {"Process_free_internal(intptr)", ves_icall_System_Diagnostics_Process_Process_free_internal},
5088 {"SetWorkingSet_internal(intptr,int,int,bool)", ves_icall_System_Diagnostics_Process_SetWorkingSet_internal},
5089 {"StartTime_internal(intptr)", ves_icall_System_Diagnostics_Process_StartTime_internal},
5090 {"Start_internal(string,string,string,intptr,intptr,intptr,System.Diagnostics.Process/ProcInfo&)", ves_icall_System_Diagnostics_Process_Start_internal},
5091 {"WaitForExit_internal(intptr,int)", ves_icall_System_Diagnostics_Process_WaitForExit_internal}
5094 static const IcallEntry double_icalls [] = {
5095 {"AssertEndianity", ves_icall_System_Double_AssertEndianity},
5096 {"ParseImpl", mono_double_ParseImpl}
5099 static const IcallEntry enum_icalls [] = {
5100 {"ToObject", ves_icall_System_Enum_ToObject},
5101 {"get_value", ves_icall_System_Enum_get_value}
5104 static const IcallEntry environment_icalls [] = {
5105 {"Exit", ves_icall_System_Environment_Exit},
5106 {"GetCommandLineArgs", mono_runtime_get_main_args},
5107 {"GetEnvironmentVariable", ves_icall_System_Environment_GetEnvironmentVariable},
5108 {"GetEnvironmentVariableNames", ves_icall_System_Environment_GetEnvironmentVariableNames},
5109 {"GetLogicalDrivesInternal", ves_icall_System_Environment_GetLogicalDrives },
5110 {"GetMachineConfigPath", ves_icall_System_Configuration_DefaultConfig_get_machine_config_path},
5111 {"GetOSVersionString", ves_icall_System_Environment_GetOSVersionString},
5112 {"GetWindowsFolderPath", ves_icall_System_Environment_GetWindowsFolderPath},
5113 {"get_ExitCode", mono_environment_exitcode_get},
5114 {"get_HasShutdownStarted", ves_icall_System_Environment_get_HasShutdownStarted},
5115 {"get_MachineName", ves_icall_System_Environment_get_MachineName},
5116 {"get_NewLine", ves_icall_System_Environment_get_NewLine},
5117 {"get_Platform", ves_icall_System_Environment_get_Platform},
5118 {"get_TickCount", ves_icall_System_Environment_get_TickCount},
5119 {"get_UserName", ves_icall_System_Environment_get_UserName},
5120 {"internalGetGacPath", ves_icall_System_Environment_GetGacPath},
5121 {"set_ExitCode", mono_environment_exitcode_set}
5124 static const IcallEntry cultureinfo_icalls [] = {
5125 {"construct_compareinfo(object,string)", ves_icall_System_Globalization_CompareInfo_construct_compareinfo},
5126 {"construct_datetime_format", ves_icall_System_Globalization_CultureInfo_construct_datetime_format},
5127 {"construct_internal_locale(string)", ves_icall_System_Globalization_CultureInfo_construct_internal_locale},
5128 {"construct_internal_locale_from_current_locale", ves_icall_System_Globalization_CultureInfo_construct_internal_locale_from_current_locale},
5129 {"construct_internal_locale_from_lcid", ves_icall_System_Globalization_CultureInfo_construct_internal_locale_from_lcid},
5130 {"construct_internal_locale_from_name", ves_icall_System_Globalization_CultureInfo_construct_internal_locale_from_name},
5131 {"construct_internal_locale_from_specific_name", ves_icall_System_Globalization_CultureInfo_construct_internal_locale_from_specific_name},
5132 {"construct_number_format", ves_icall_System_Globalization_CultureInfo_construct_number_format},
5133 {"internal_get_cultures", ves_icall_System_Globalization_CultureInfo_internal_get_cultures},
5134 {"internal_is_lcid_neutral", ves_icall_System_Globalization_CultureInfo_internal_is_lcid_neutral}
5137 static const IcallEntry compareinfo_icalls [] = {
5138 {"assign_sortkey(object,string,System.Globalization.CompareOptions)", ves_icall_System_Globalization_CompareInfo_assign_sortkey},
5139 {"construct_compareinfo(string)", ves_icall_System_Globalization_CompareInfo_construct_compareinfo},
5140 {"free_internal_collator()", ves_icall_System_Globalization_CompareInfo_free_internal_collator},
5141 {"internal_compare(string,int,int,string,int,int,System.Globalization.CompareOptions)", ves_icall_System_Globalization_CompareInfo_internal_compare},
5142 {"internal_index(string,int,int,char,System.Globalization.CompareOptions,bool)", ves_icall_System_Globalization_CompareInfo_internal_index_char},
5143 {"internal_index(string,int,int,string,System.Globalization.CompareOptions,bool)", ves_icall_System_Globalization_CompareInfo_internal_index}
5146 static const IcallEntry gc_icalls [] = {
5147 {"GetTotalMemory", ves_icall_System_GC_GetTotalMemory},
5148 {"InternalCollect", ves_icall_System_GC_InternalCollect},
5149 {"KeepAlive", ves_icall_System_GC_KeepAlive},
5150 {"ReRegisterForFinalize", ves_icall_System_GC_ReRegisterForFinalize},
5151 {"SuppressFinalize", ves_icall_System_GC_SuppressFinalize},
5152 {"WaitForPendingFinalizers", ves_icall_System_GC_WaitForPendingFinalizers}
5155 static const IcallEntry famwatcher_icalls [] = {
5156 {"InternalFAMNextEvent", ves_icall_System_IO_FAMW_InternalFAMNextEvent}
5159 static const IcallEntry filewatcher_icalls [] = {
5160 {"InternalCloseDirectory", ves_icall_System_IO_FSW_CloseDirectory},
5161 {"InternalOpenDirectory", ves_icall_System_IO_FSW_OpenDirectory},
5162 {"InternalReadDirectoryChanges", ves_icall_System_IO_FSW_ReadDirectoryChanges},
5163 {"InternalSupportsFSW", ves_icall_System_IO_FSW_SupportsFSW}
5166 static const IcallEntry path_icalls [] = {
5167 {"get_temp_path", ves_icall_System_IO_get_temp_path}
5170 static const IcallEntry monoio_icalls [] = {
5171 {"BeginRead", ves_icall_System_IO_MonoIO_BeginRead },
5172 {"BeginWrite", ves_icall_System_IO_MonoIO_BeginWrite },
5173 {"Close(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Close},
5174 {"CopyFile(string,string,bool,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_CopyFile},
5175 {"CreateDirectory(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_CreateDirectory},
5176 {"CreatePipe(intptr&,intptr&)", ves_icall_System_IO_MonoIO_CreatePipe},
5177 {"DeleteFile(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_DeleteFile},
5178 {"FindClose(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_FindClose},
5179 {"FindFirstFile(string,System.IO.MonoIOStat&,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_FindFirstFile},
5180 {"FindNextFile(intptr,System.IO.MonoIOStat&,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_FindNextFile},
5181 {"Flush(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Flush},
5182 {"GetCurrentDirectory(System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetCurrentDirectory},
5183 {"GetFileAttributes(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetFileAttributes},
5184 {"GetFileStat(string,System.IO.MonoIOStat&,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetFileStat},
5185 {"GetFileType(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetFileType},
5186 {"GetLength(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetLength},
5187 {"GetSupportsAsync", ves_icall_System_IO_MonoIO_GetSupportsAsync},
5188 {"GetTempPath(string&)", ves_icall_System_IO_MonoIO_GetTempPath},
5189 {"Lock(intptr,long,long,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Lock},
5190 {"MoveFile(string,string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_MoveFile},
5191 {"Open(string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare,bool,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Open},
5192 {"Read(intptr,byte[],int,int,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Read},
5193 {"RemoveDirectory(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_RemoveDirectory},
5194 {"Seek(intptr,long,System.IO.SeekOrigin,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Seek},
5195 {"SetCurrentDirectory(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_SetCurrentDirectory},
5196 {"SetFileAttributes(string,System.IO.FileAttributes,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_SetFileAttributes},
5197 {"SetFileTime(intptr,long,long,long,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_SetFileTime},
5198 {"SetLength(intptr,long,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_SetLength},
5199 {"Unlock(intptr,long,long,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Unlock},
5200 {"Write(intptr,byte[],int,int,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Write},
5201 {"get_AltDirectorySeparatorChar", ves_icall_System_IO_MonoIO_get_AltDirectorySeparatorChar},
5202 {"get_ConsoleError", ves_icall_System_IO_MonoIO_get_ConsoleError},
5203 {"get_ConsoleInput", ves_icall_System_IO_MonoIO_get_ConsoleInput},
5204 {"get_ConsoleOutput", ves_icall_System_IO_MonoIO_get_ConsoleOutput},
5205 {"get_DirectorySeparatorChar", ves_icall_System_IO_MonoIO_get_DirectorySeparatorChar},
5206 {"get_InvalidPathChars", ves_icall_System_IO_MonoIO_get_InvalidPathChars},
5207 {"get_PathSeparator", ves_icall_System_IO_MonoIO_get_PathSeparator},
5208 {"get_VolumeSeparatorChar", ves_icall_System_IO_MonoIO_get_VolumeSeparatorChar}
5211 static const IcallEntry math_icalls [] = {
5212 {"Acos", ves_icall_System_Math_Acos},
5213 {"Asin", ves_icall_System_Math_Asin},
5214 {"Atan", ves_icall_System_Math_Atan},
5215 {"Atan2", ves_icall_System_Math_Atan2},
5216 {"Cos", ves_icall_System_Math_Cos},
5217 {"Cosh", ves_icall_System_Math_Cosh},
5218 {"Exp", ves_icall_System_Math_Exp},
5219 {"Floor", ves_icall_System_Math_Floor},
5220 {"Log", ves_icall_System_Math_Log},
5221 {"Log10", ves_icall_System_Math_Log10},
5222 {"Pow", ves_icall_System_Math_Pow},
5223 {"Round", ves_icall_System_Math_Round},
5224 {"Round2", ves_icall_System_Math_Round2},
5225 {"Sin", ves_icall_System_Math_Sin},
5226 {"Sinh", ves_icall_System_Math_Sinh},
5227 {"Sqrt", ves_icall_System_Math_Sqrt},
5228 {"Tan", ves_icall_System_Math_Tan},
5229 {"Tanh", ves_icall_System_Math_Tanh}
5232 static const IcallEntry customattrs_icalls [] = {
5233 {"GetCustomAttributes", mono_reflection_get_custom_attrs}
5236 static const IcallEntry enuminfo_icalls [] = {
5237 {"get_enum_info", ves_icall_get_enum_info}
5240 static const IcallEntry fieldinfo_icalls [] = {
5241 {"internal_from_handle", ves_icall_System_Reflection_FieldInfo_internal_from_handle}
5244 static const IcallEntry monotype_icalls [] = {
5245 {"GetArrayRank", ves_icall_MonoType_GetArrayRank},
5246 {"GetConstructors", ves_icall_Type_GetConstructors_internal},
5247 {"GetConstructors_internal", ves_icall_Type_GetConstructors_internal},
5248 {"GetElementType", ves_icall_MonoType_GetElementType},
5249 {"GetEvents_internal", ves_icall_Type_GetEvents_internal},
5250 {"GetField", ves_icall_Type_GetField},
5251 {"GetFields_internal", ves_icall_Type_GetFields_internal},
5252 {"GetGenericArguments", ves_icall_MonoType_GetGenericArguments},
5253 {"GetInterfaces", ves_icall_Type_GetInterfaces},
5254 {"GetMethodsByName", ves_icall_Type_GetMethodsByName},
5255 {"GetNestedType", ves_icall_Type_GetNestedType},
5256 {"GetNestedTypes", ves_icall_Type_GetNestedTypes},
5257 {"GetPropertiesByName", ves_icall_Type_GetPropertiesByName},
5258 {"InternalGetEvent", ves_icall_MonoType_GetEvent},
5259 {"IsByRefImpl", ves_icall_type_isbyref},
5260 {"IsPointerImpl", ves_icall_type_ispointer},
5261 {"IsPrimitiveImpl", ves_icall_type_isprimitive},
5262 {"getFullName", ves_icall_System_MonoType_getFullName},
5263 {"get_Assembly", ves_icall_MonoType_get_Assembly},
5264 {"get_BaseType", ves_icall_get_type_parent},
5265 {"get_DeclaringMethod", ves_icall_MonoType_get_DeclaringMethod},
5266 {"get_DeclaringType", ves_icall_MonoType_get_DeclaringType},
5267 {"get_HasGenericArguments", ves_icall_MonoType_get_HasGenericArguments},
5268 {"get_IsGenericParameter", ves_icall_MonoType_get_IsGenericParameter},
5269 {"get_Module", ves_icall_MonoType_get_Module},
5270 {"get_Name", ves_icall_MonoType_get_Name},
5271 {"get_Namespace", ves_icall_MonoType_get_Namespace},
5272 {"get_UnderlyingSystemType", ves_icall_MonoType_get_UnderlyingSystemType},
5273 {"get_attributes", ves_icall_get_attributes},
5274 {"type_from_obj", mono_type_type_from_obj}
5277 static const IcallEntry assembly_icalls [] = {
5278 {"FillName", ves_icall_System_Reflection_Assembly_FillName},
5279 {"GetCallingAssembly", ves_icall_System_Reflection_Assembly_GetCallingAssembly},
5280 {"GetEntryAssembly", ves_icall_System_Reflection_Assembly_GetEntryAssembly},
5281 {"GetExecutingAssembly", ves_icall_System_Reflection_Assembly_GetExecutingAssembly},
5282 {"GetFilesInternal", ves_icall_System_Reflection_Assembly_GetFilesInternal},
5283 {"GetManifestResourceInfoInternal", ves_icall_System_Reflection_Assembly_GetManifestResourceInfoInternal},
5284 {"GetManifestResourceInternal", ves_icall_System_Reflection_Assembly_GetManifestResourceInternal},
5285 {"GetManifestResourceNames", ves_icall_System_Reflection_Assembly_GetManifestResourceNames},
5286 {"GetModulesInternal", ves_icall_System_Reflection_Assembly_GetModulesInternal},
5287 {"GetNamespaces", ves_icall_System_Reflection_Assembly_GetNamespaces},
5288 {"GetReferencedAssemblies", ves_icall_System_Reflection_Assembly_GetReferencedAssemblies},
5289 {"GetTypes", ves_icall_System_Reflection_Assembly_GetTypes},
5290 {"InternalGetAssemblyName", ves_icall_System_Reflection_Assembly_InternalGetAssemblyName},
5291 {"InternalGetType", ves_icall_System_Reflection_Assembly_InternalGetType},
5292 {"InternalImageRuntimeVersion", ves_icall_System_Reflection_Assembly_InternalImageRuntimeVersion},
5293 {"LoadFrom", ves_icall_System_Reflection_Assembly_LoadFrom},
5295 * Private icalls for the Mono Debugger
5297 {"MonoDebugger_GetLocalTypeFromSignature", ves_icall_MonoDebugger_GetLocalTypeFromSignature},
5298 {"MonoDebugger_GetMethod", ves_icall_MonoDebugger_GetMethod},
5299 {"MonoDebugger_GetMethodToken", ves_icall_MonoDebugger_GetMethodToken},
5300 {"MonoDebugger_GetType", ves_icall_MonoDebugger_GetType},
5301 /* normal icalls again */
5302 {"get_EntryPoint", ves_icall_System_Reflection_Assembly_get_EntryPoint},
5303 {"get_code_base", ves_icall_System_Reflection_Assembly_get_code_base},
5304 {"get_global_assembly_cache", ves_icall_System_Reflection_Assembly_get_global_assembly_cache},
5305 {"get_location", ves_icall_System_Reflection_Assembly_get_location},
5306 {"load_with_partial_name", ves_icall_System_Reflection_Assembly_load_with_partial_name}
5309 static const IcallEntry methodbase_icalls [] = {
5310 {"GetCurrentMethod", ves_icall_GetCurrentMethod}
5313 static const IcallEntry module_icalls [] = {
5314 {"Close", ves_icall_System_Reflection_Module_Close},
5315 {"GetGlobalType", ves_icall_System_Reflection_Module_GetGlobalType},
5316 {"GetGuidInternal", ves_icall_System_Reflection_Module_GetGuidInternal},
5317 {"InternalGetTypes", ves_icall_System_Reflection_Module_InternalGetTypes}
5320 static const IcallEntry monocmethod_icalls [] = {
5321 {"GetGenericMethodDefinition_impl", ves_icall_MonoMethod_GetGenericMethodDefinition},
5322 {"InternalInvoke", ves_icall_InternalInvoke},
5323 {"get_Mono_IsInflatedMethod", ves_icall_MonoMethod_get_Mono_IsInflatedMethod}
5326 static const IcallEntry monoeventinfo_icalls [] = {
5327 {"get_event_info", ves_icall_get_event_info}
5330 static const IcallEntry monofield_icalls [] = {
5331 {"GetParentType", ves_icall_MonoField_GetParentType},
5332 {"GetValueInternal", ves_icall_MonoField_GetValueInternal},
5333 {"SetValueInternal", ves_icall_FieldInfo_SetValueInternal}
5336 static const IcallEntry monogenericinst_icalls [] = {
5337 {"GetConstructors_internal", ves_icall_MonoGenericInst_GetConstructors},
5338 {"GetEvents_internal", ves_icall_MonoGenericInst_GetEvents},
5339 {"GetFields_internal", ves_icall_MonoGenericInst_GetFields},
5340 {"GetInterfaces_internal", ves_icall_MonoGenericInst_GetInterfaces},
5341 {"GetMethods_internal", ves_icall_MonoGenericInst_GetMethods},
5342 {"GetParentType", ves_icall_MonoGenericInst_GetParentType},
5343 {"GetProperties_internal", ves_icall_MonoGenericInst_GetProperties},
5344 {"initialize", mono_reflection_generic_inst_initialize}
5347 static const IcallEntry generictypeparambuilder_icalls [] = {
5348 {"initialize", mono_reflection_initialize_generic_parameter}
5351 static const IcallEntry monomethod_icalls [] = {
5352 {"BindGenericParameters", mono_reflection_bind_generic_method_parameters},
5353 {"GetGenericArguments", ves_icall_MonoMethod_GetGenericArguments},
5354 {"GetGenericMethodDefinition_impl", ves_icall_MonoMethod_GetGenericMethodDefinition},
5355 {"InternalInvoke", ves_icall_InternalInvoke},
5356 {"get_HasGenericParameters", ves_icall_MonoMethod_get_HasGenericParameters},
5357 {"get_IsGenericMethodDefinition", ves_icall_MonoMethod_get_IsGenericMethodDefinition},
5358 {"get_Mono_IsInflatedMethod", ves_icall_MonoMethod_get_Mono_IsInflatedMethod},
5359 {"get_base_definition", ves_icall_MonoMethod_get_base_definition}
5362 static const IcallEntry monomethodinfo_icalls [] = {
5363 {"get_method_info", ves_icall_get_method_info},
5364 {"get_parameter_info", ves_icall_get_parameter_info}
5367 static const IcallEntry monopropertyinfo_icalls [] = {
5368 {"get_property_info", ves_icall_get_property_info}
5371 static const IcallEntry dns_icalls [] = {
5372 {"GetHostByAddr_internal(string,string&,string[]&,string[]&)", ves_icall_System_Net_Dns_GetHostByAddr_internal},
5373 {"GetHostByName_internal(string,string&,string[]&,string[]&)", ves_icall_System_Net_Dns_GetHostByName_internal},
5374 {"GetHostName_internal(string&)", ves_icall_System_Net_Dns_GetHostName_internal}
5377 static const IcallEntry socket_icalls [] = {
5378 {"Accept_internal(intptr,int&)", ves_icall_System_Net_Sockets_Socket_Accept_internal},
5379 {"AsyncReceiveInternal", ves_icall_System_Net_Sockets_Socket_AsyncReceive},
5380 {"AsyncSendInternal", ves_icall_System_Net_Sockets_Socket_AsyncSend},
5381 {"Available_internal(intptr,int&)", ves_icall_System_Net_Sockets_Socket_Available_internal},
5382 {"Bind_internal(intptr,System.Net.SocketAddress,int&)", ves_icall_System_Net_Sockets_Socket_Bind_internal},
5383 {"Blocking_internal(intptr,bool,int&)", ves_icall_System_Net_Sockets_Socket_Blocking_internal},
5384 {"Close_internal(intptr,int&)", ves_icall_System_Net_Sockets_Socket_Close_internal},
5385 {"Connect_internal(intptr,System.Net.SocketAddress,int&)", ves_icall_System_Net_Sockets_Socket_Connect_internal},
5386 {"GetSocketOption_arr_internal(intptr,System.Net.Sockets.SocketOptionLevel,System.Net.Sockets.SocketOptionName,byte[]&,int&)", ves_icall_System_Net_Sockets_Socket_GetSocketOption_arr_internal},
5387 {"GetSocketOption_obj_internal(intptr,System.Net.Sockets.SocketOptionLevel,System.Net.Sockets.SocketOptionName,object&,int&)", ves_icall_System_Net_Sockets_Socket_GetSocketOption_obj_internal},
5388 {"GetSupportsAsync", ves_icall_System_IO_MonoIO_GetSupportsAsync},
5389 {"Listen_internal(intptr,int,int&)", ves_icall_System_Net_Sockets_Socket_Listen_internal},
5390 {"LocalEndPoint_internal(intptr,int&)", ves_icall_System_Net_Sockets_Socket_LocalEndPoint_internal},
5391 {"Poll_internal", ves_icall_System_Net_Sockets_Socket_Poll_internal},
5392 {"Receive_internal(intptr,byte[],int,int,System.Net.Sockets.SocketFlags,int&)", ves_icall_System_Net_Sockets_Socket_Receive_internal},
5393 {"RecvFrom_internal(intptr,byte[],int,int,System.Net.Sockets.SocketFlags,System.Net.SocketAddress&,int&)", ves_icall_System_Net_Sockets_Socket_RecvFrom_internal},
5394 {"RemoteEndPoint_internal(intptr,int&)", ves_icall_System_Net_Sockets_Socket_RemoteEndPoint_internal},
5395 {"Select_internal(System.Net.Sockets.Socket[]&,System.Net.Sockets.Socket[]&,System.Net.Sockets.Socket[]&,int,int&)", ves_icall_System_Net_Sockets_Socket_Select_internal},
5396 {"SendTo_internal(intptr,byte[],int,int,System.Net.Sockets.SocketFlags,System.Net.SocketAddress,int&)", ves_icall_System_Net_Sockets_Socket_SendTo_internal},
5397 {"Send_internal(intptr,byte[],int,int,System.Net.Sockets.SocketFlags,int&)", ves_icall_System_Net_Sockets_Socket_Send_internal},
5398 {"SetSocketOption_internal(intptr,System.Net.Sockets.SocketOptionLevel,System.Net.Sockets.SocketOptionName,object,byte[],int,int&)", ves_icall_System_Net_Sockets_Socket_SetSocketOption_internal},
5399 {"Shutdown_internal(intptr,System.Net.Sockets.SocketShutdown,int&)", ves_icall_System_Net_Sockets_Socket_Shutdown_internal},
5400 {"Socket_internal(System.Net.Sockets.AddressFamily,System.Net.Sockets.SocketType,System.Net.Sockets.ProtocolType,int&)", ves_icall_System_Net_Sockets_Socket_Socket_internal},
5401 {"WSAIoctl(intptr,int,byte[],byte[],int&)", ves_icall_System_Net_Sockets_Socket_WSAIoctl}
5404 static const IcallEntry socketex_icalls [] = {
5405 {"WSAGetLastError_internal", ves_icall_System_Net_Sockets_SocketException_WSAGetLastError_internal}
5408 static const IcallEntry object_icalls [] = {
5409 {"GetType", ves_icall_System_Object_GetType},
5410 {"InternalGetHashCode", ves_icall_System_Object_GetHashCode},
5411 {"MemberwiseClone", ves_icall_System_Object_MemberwiseClone},
5412 {"obj_address", ves_icall_System_Object_obj_address}
5415 static const IcallEntry assemblybuilder_icalls[] = {
5416 {"InternalAddModule", mono_image_load_module},
5417 {"basic_init", mono_image_basic_init}
5420 static const IcallEntry customattrbuilder_icalls [] = {
5421 {"GetBlob", mono_reflection_get_custom_attrs_blob}
5424 static const IcallEntry dynamicmethod_icalls [] = {
5425 {"create_dynamic_method", mono_reflection_create_dynamic_method}
5428 static const IcallEntry methodbuilder_icalls [] = {
5429 {"BindGenericParameters", mono_reflection_bind_generic_method_parameters}
5432 static const IcallEntry modulebuilder_icalls [] = {
5433 {"basic_init", mono_image_module_basic_init},
5434 {"build_metadata", ves_icall_ModuleBuilder_build_metadata},
5435 {"create_modified_type", ves_icall_ModuleBuilder_create_modified_type},
5436 {"getDataChunk", ves_icall_ModuleBuilder_getDataChunk},
5437 {"getMethodToken", ves_icall_ModuleBuilder_getMethodToken},
5438 {"getToken", ves_icall_ModuleBuilder_getToken},
5439 {"getUSIndex", mono_image_insert_string}
5442 static const IcallEntry signaturehelper_icalls [] = {
5443 {"get_signature_field", mono_reflection_sighelper_get_signature_field},
5444 {"get_signature_local", mono_reflection_sighelper_get_signature_local}
5447 static const IcallEntry typebuilder_icalls [] = {
5448 {"create_internal_class", mono_reflection_create_internal_class},
5449 {"create_runtime_class", mono_reflection_create_runtime_class},
5450 {"get_IsGenericParameter", ves_icall_TypeBuilder_get_IsGenericParameter},
5451 {"get_event_info", mono_reflection_event_builder_get_event_info},
5452 {"setup_generic_class", mono_reflection_setup_generic_class},
5453 {"setup_internal_class", mono_reflection_setup_internal_class}
5456 static const IcallEntry runtimehelpers_icalls [] = {
5457 {"GetObjectValue", ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetObjectValue},
5458 {"GetOffsetToStringData", ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetOffsetToStringData},
5459 {"InitializeArray", ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_InitializeArray},
5460 {"RunClassConstructor", ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_RunClassConstructor}
5463 static const IcallEntry gchandle_icalls [] = {
5464 {"FreeHandle", ves_icall_System_GCHandle_FreeHandle},
5465 {"GetAddrOfPinnedObject", ves_icall_System_GCHandle_GetAddrOfPinnedObject},
5466 {"GetTarget", ves_icall_System_GCHandle_GetTarget},
5467 {"GetTargetHandle", ves_icall_System_GCHandle_GetTargetHandle}
5470 static const IcallEntry marshal_icalls [] = {
5471 {"AllocCoTaskMem", ves_icall_System_Runtime_InteropServices_Marshal_AllocCoTaskMem},
5472 {"AllocHGlobal", mono_marshal_alloc},
5473 {"DestroyStructure", ves_icall_System_Runtime_InteropServices_Marshal_DestroyStructure},
5474 {"FreeCoTaskMem", ves_icall_System_Runtime_InteropServices_Marshal_FreeCoTaskMem},
5475 {"FreeHGlobal", mono_marshal_free},
5476 {"GetLastWin32Error", ves_icall_System_Runtime_InteropServices_Marshal_GetLastWin32Error},
5477 {"OffsetOf", ves_icall_System_Runtime_InteropServices_Marshal_OffsetOf},
5478 {"Prelink", ves_icall_System_Runtime_InteropServices_Marshal_Prelink},
5479 {"PrelinkAll", ves_icall_System_Runtime_InteropServices_Marshal_PrelinkAll},
5480 {"PtrToStringAnsi(intptr)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi},
5481 {"PtrToStringAnsi(intptr,int)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi_len},
5482 {"PtrToStringAuto(intptr)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi},
5483 {"PtrToStringAuto(intptr,int)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi_len},
5484 {"PtrToStringBSTR", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringBSTR},
5485 {"PtrToStringUni(intptr)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringUni},
5486 {"PtrToStringUni(intptr,int)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringUni_len},
5487 {"PtrToStructure(intptr,System.Type)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStructure_type},
5488 {"PtrToStructure(intptr,object)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStructure},
5489 {"ReAllocHGlobal", mono_marshal_realloc},
5490 {"ReadByte", ves_icall_System_Runtime_InteropServices_Marshal_ReadByte},
5491 {"ReadInt16", ves_icall_System_Runtime_InteropServices_Marshal_ReadInt16},
5492 {"ReadInt32", ves_icall_System_Runtime_InteropServices_Marshal_ReadInt32},
5493 {"ReadInt64", ves_icall_System_Runtime_InteropServices_Marshal_ReadInt64},
5494 {"ReadIntPtr", ves_icall_System_Runtime_InteropServices_Marshal_ReadIntPtr},
5495 {"SizeOf", ves_icall_System_Runtime_InteropServices_Marshal_SizeOf},
5496 {"StringToHGlobalAnsi", ves_icall_System_Runtime_InteropServices_Marshal_StringToHGlobalAnsi},
5497 {"StringToHGlobalAuto", ves_icall_System_Runtime_InteropServices_Marshal_StringToHGlobalAnsi},
5498 {"StringToHGlobalUni", ves_icall_System_Runtime_InteropServices_Marshal_StringToHGlobalUni},
5499 {"StructureToPtr", ves_icall_System_Runtime_InteropServices_Marshal_StructureToPtr},
5500 {"UnsafeAddrOfPinnedArrayElement", ves_icall_System_Runtime_InteropServices_Marshal_UnsafeAddrOfPinnedArrayElement},
5501 {"WriteByte", ves_icall_System_Runtime_InteropServices_Marshal_WriteByte},
5502 {"WriteInt16", ves_icall_System_Runtime_InteropServices_Marshal_WriteInt16},
5503 {"WriteInt32", ves_icall_System_Runtime_InteropServices_Marshal_WriteInt32},
5504 {"WriteInt64", ves_icall_System_Runtime_InteropServices_Marshal_WriteInt64},
5505 {"WriteIntPtr", ves_icall_System_Runtime_InteropServices_Marshal_WriteIntPtr},
5506 {"copy_from_unmanaged", ves_icall_System_Runtime_InteropServices_Marshal_copy_from_unmanaged},
5507 {"copy_to_unmanaged", ves_icall_System_Runtime_InteropServices_Marshal_copy_to_unmanaged}
5510 static const IcallEntry activationservices_icalls [] = {
5511 {"AllocateUninitializedClassInstance", ves_icall_System_Runtime_Activation_ActivationServices_AllocateUninitializedClassInstance},
5512 {"EnableProxyActivation", ves_icall_System_Runtime_Activation_ActivationServices_EnableProxyActivation}
5515 static const IcallEntry monomethodmessage_icalls [] = {
5516 {"InitMessage", ves_icall_MonoMethodMessage_InitMessage}
5519 static const IcallEntry realproxy_icalls [] = {
5520 {"InternalGetProxyType", ves_icall_Remoting_RealProxy_InternalGetProxyType},
5521 {"InternalGetTransparentProxy", ves_icall_Remoting_RealProxy_GetTransparentProxy}
5524 static const IcallEntry remotingservices_icalls [] = {
5525 {"InternalExecute", ves_icall_InternalExecute},
5526 {"IsTransparentProxy", ves_icall_IsTransparentProxy}
5529 static const IcallEntry rng_icalls [] = {
5530 {"RngClose", ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngClose},
5531 {"RngGetBytes", ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngGetBytes},
5532 {"RngInitialize", ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngInitialize}
5535 static const IcallEntry methodhandle_icalls [] = {
5536 {"GetFunctionPointer", ves_icall_RuntimeMethod_GetFunctionPointer}
5539 static const IcallEntry string_icalls [] = {
5540 {".ctor(char*)", ves_icall_System_String_ctor_charp},
5541 {".ctor(char*,int,int)", ves_icall_System_String_ctor_charp_int_int},
5542 {".ctor(char,int)", ves_icall_System_String_ctor_char_int},
5543 {".ctor(char[])", ves_icall_System_String_ctor_chara},
5544 {".ctor(char[],int,int)", ves_icall_System_String_ctor_chara_int_int},
5545 {".ctor(sbyte*)", ves_icall_System_String_ctor_sbytep},
5546 {".ctor(sbyte*,int,int)", ves_icall_System_String_ctor_sbytep_int_int},
5547 {".ctor(sbyte*,int,int,System.Text.Encoding)", ves_icall_System_String_ctor_encoding},
5548 {"GetHashCode", ves_icall_System_String_GetHashCode},
5549 {"InternalAllocateStr", ves_icall_System_String_InternalAllocateStr},
5550 {"InternalCharCopy", ves_icall_System_String_InternalCharCopy},
5551 {"InternalCopyTo", ves_icall_System_String_InternalCopyTo},
5552 {"InternalIndexOfAny", ves_icall_System_String_InternalIndexOfAny},
5553 {"InternalInsert", ves_icall_System_String_InternalInsert},
5554 {"InternalIntern", ves_icall_System_String_InternalIntern},
5555 {"InternalIsInterned", ves_icall_System_String_InternalIsInterned},
5556 {"InternalJoin", ves_icall_System_String_InternalJoin},
5557 {"InternalLastIndexOfAny", ves_icall_System_String_InternalLastIndexOfAny},
5558 {"InternalPad", ves_icall_System_String_InternalPad},
5559 {"InternalRemove", ves_icall_System_String_InternalRemove},
5560 {"InternalReplace(char,char)", ves_icall_System_String_InternalReplace_Char},
5561 {"InternalReplace(string,string,System.Globalization.CompareInfo)", ves_icall_System_String_InternalReplace_Str_Comp},
5562 {"InternalSplit", ves_icall_System_String_InternalSplit},
5563 {"InternalStrcpy(string,int,char[])", ves_icall_System_String_InternalStrcpy_Chars},
5564 {"InternalStrcpy(string,int,char[],int,int)", ves_icall_System_String_InternalStrcpy_CharsN},
5565 {"InternalStrcpy(string,int,string)", ves_icall_System_String_InternalStrcpy_Str},
5566 {"InternalStrcpy(string,int,string,int,int)", ves_icall_System_String_InternalStrcpy_StrN},
5567 {"InternalToLower(System.Globalization.CultureInfo)", ves_icall_System_String_InternalToLower_Comp},
5568 {"InternalToUpper(System.Globalization.CultureInfo)", ves_icall_System_String_InternalToUpper_Comp},
5569 {"InternalTrim", ves_icall_System_String_InternalTrim},
5570 {"get_Chars", ves_icall_System_String_get_Chars}
5573 static const IcallEntry encoding_icalls [] = {
5574 {"InternalCodePage", ves_icall_System_Text_Encoding_InternalCodePage}
5577 static const IcallEntry monitor_icalls [] = {
5578 {"Monitor_exit", ves_icall_System_Threading_Monitor_Monitor_exit},
5579 {"Monitor_pulse", ves_icall_System_Threading_Monitor_Monitor_pulse},
5580 {"Monitor_pulse_all", ves_icall_System_Threading_Monitor_Monitor_pulse_all},
5581 {"Monitor_test_owner", ves_icall_System_Threading_Monitor_Monitor_test_owner},
5582 {"Monitor_test_synchronised", ves_icall_System_Threading_Monitor_Monitor_test_synchronised},
5583 {"Monitor_try_enter", ves_icall_System_Threading_Monitor_Monitor_try_enter},
5584 {"Monitor_wait", ves_icall_System_Threading_Monitor_Monitor_wait}
5587 static const IcallEntry interlocked_icalls [] = {
5588 {"CompareExchange(int&,int,int)", ves_icall_System_Threading_Interlocked_CompareExchange_Int},
5589 {"CompareExchange(object&,object,object)", ves_icall_System_Threading_Interlocked_CompareExchange_Object},
5590 {"CompareExchange(single&,single,single)", ves_icall_System_Threading_Interlocked_CompareExchange_Single},
5591 {"Decrement(int&)", ves_icall_System_Threading_Interlocked_Decrement_Int},
5592 {"Decrement(long&)", ves_icall_System_Threading_Interlocked_Decrement_Long},
5593 {"Exchange(int&,int)", ves_icall_System_Threading_Interlocked_Exchange_Int},
5594 {"Exchange(object&,object)", ves_icall_System_Threading_Interlocked_Exchange_Object},
5595 {"Exchange(single&,single)", ves_icall_System_Threading_Interlocked_Exchange_Single},
5596 {"Increment(int&)", ves_icall_System_Threading_Interlocked_Increment_Int},
5597 {"Increment(long&)", ves_icall_System_Threading_Interlocked_Increment_Long}
5600 static const IcallEntry mutex_icalls [] = {
5601 {"CreateMutex_internal", ves_icall_System_Threading_Mutex_CreateMutex_internal},
5602 {"ReleaseMutex_internal", ves_icall_System_Threading_Mutex_ReleaseMutex_internal}
5605 static const IcallEntry nativeevents_icalls [] = {
5606 {"CloseEvent_internal", ves_icall_System_Threading_Events_CloseEvent_internal},
5607 {"CreateEvent_internal", ves_icall_System_Threading_Events_CreateEvent_internal},
5608 {"ResetEvent_internal", ves_icall_System_Threading_Events_ResetEvent_internal},
5609 {"SetEvent_internal", ves_icall_System_Threading_Events_SetEvent_internal}
5612 static const IcallEntry thread_icalls [] = {
5613 {"Abort_internal(object)", ves_icall_System_Threading_Thread_Abort},
5614 {"CurrentThread_internal", mono_thread_current},
5615 {"GetDomainID", ves_icall_System_Threading_Thread_GetDomainID},
5616 {"GetName_internal", ves_icall_System_Threading_Thread_GetName_internal},
5617 {"Join_internal", ves_icall_System_Threading_Thread_Join_internal},
5618 {"ResetAbort_internal()", ves_icall_System_Threading_Thread_ResetAbort},
5619 {"Resume_internal()", ves_icall_System_Threading_Thread_Resume},
5620 {"SetName_internal", ves_icall_System_Threading_Thread_SetName_internal},
5621 {"Sleep_internal", ves_icall_System_Threading_Thread_Sleep_internal},
5622 {"SlotHash_lookup", ves_icall_System_Threading_Thread_SlotHash_lookup},
5623 {"SlotHash_store", ves_icall_System_Threading_Thread_SlotHash_store},
5624 {"Start_internal", ves_icall_System_Threading_Thread_Start_internal},
5625 {"Suspend_internal", ves_icall_System_Threading_Thread_Suspend},
5626 {"Thread_free_internal", ves_icall_System_Threading_Thread_Thread_free_internal},
5627 {"Thread_internal", ves_icall_System_Threading_Thread_Thread_internal},
5628 {"VolatileRead(IntPtr&)", ves_icall_System_Threading_Thread_VolatileReadIntPtr},
5629 {"VolatileRead(UIntPtr&)", ves_icall_System_Threading_Thread_VolatileReadIntPtr},
5630 {"VolatileRead(byte&)", ves_icall_System_Threading_Thread_VolatileRead1},
5631 {"VolatileRead(double&)", ves_icall_System_Threading_Thread_VolatileRead8},
5632 {"VolatileRead(float&)", ves_icall_System_Threading_Thread_VolatileRead4},
5633 {"VolatileRead(int&)", ves_icall_System_Threading_Thread_VolatileRead4},
5634 {"VolatileRead(long&)", ves_icall_System_Threading_Thread_VolatileRead8},
5635 {"VolatileRead(object&)", ves_icall_System_Threading_Thread_VolatileReadIntPtr},
5636 {"VolatileRead(sbyte&)", ves_icall_System_Threading_Thread_VolatileRead1},
5637 {"VolatileRead(short&)", ves_icall_System_Threading_Thread_VolatileRead2},
5638 {"VolatileRead(uint&)", ves_icall_System_Threading_Thread_VolatileRead2},
5639 {"VolatileRead(ulong&)", ves_icall_System_Threading_Thread_VolatileRead8},
5640 {"VolatileRead(ushort&)", ves_icall_System_Threading_Thread_VolatileRead2},
5641 {"VolatileWrite(IntPtr&,IntPtr)", ves_icall_System_Threading_Thread_VolatileWriteIntPtr},
5642 {"VolatileWrite(UIntPtr&,UIntPtr)", ves_icall_System_Threading_Thread_VolatileWriteIntPtr},
5643 {"VolatileWrite(byte&,byte)", ves_icall_System_Threading_Thread_VolatileWrite1},
5644 {"VolatileWrite(double&,double)", ves_icall_System_Threading_Thread_VolatileWrite8},
5645 {"VolatileWrite(float&,float)", ves_icall_System_Threading_Thread_VolatileWrite4},
5646 {"VolatileWrite(int&,int)", ves_icall_System_Threading_Thread_VolatileWrite4},
5647 {"VolatileWrite(long&,long)", ves_icall_System_Threading_Thread_VolatileWrite8},
5648 {"VolatileWrite(object&,object)", ves_icall_System_Threading_Thread_VolatileWriteIntPtr},
5649 {"VolatileWrite(sbyte&,sbyte)", ves_icall_System_Threading_Thread_VolatileWrite1},
5650 {"VolatileWrite(short&,short)", ves_icall_System_Threading_Thread_VolatileWrite2},
5651 {"VolatileWrite(uint&,uint)", ves_icall_System_Threading_Thread_VolatileWrite2},
5652 {"VolatileWrite(ulong&,ulong)", ves_icall_System_Threading_Thread_VolatileWrite8},
5653 {"VolatileWrite(ushort&,ushort)", ves_icall_System_Threading_Thread_VolatileWrite2},
5654 {"current_lcid()", ves_icall_System_Threading_Thread_current_lcid}
5657 static const IcallEntry threadpool_icalls [] = {
5658 {"BindHandleInternal", ves_icall_System_Threading_ThreadPool_BindHandle},
5659 {"GetAvailableThreads", ves_icall_System_Threading_ThreadPool_GetAvailableThreads},
5660 {"GetMaxThreads", ves_icall_System_Threading_ThreadPool_GetMaxThreads},
5661 {"GetMinThreads", ves_icall_System_Threading_ThreadPool_GetMinThreads},
5662 {"SetMinThreads", ves_icall_System_Threading_ThreadPool_SetMinThreads}
5665 static const IcallEntry waithandle_icalls [] = {
5666 {"WaitAll_internal", ves_icall_System_Threading_WaitHandle_WaitAll_internal},
5667 {"WaitAny_internal", ves_icall_System_Threading_WaitHandle_WaitAny_internal},
5668 {"WaitOne_internal", ves_icall_System_Threading_WaitHandle_WaitOne_internal}
5671 static const IcallEntry type_icalls [] = {
5672 {"BindGenericParameters", ves_icall_Type_BindGenericParameters},
5673 {"Equals", ves_icall_type_Equals},
5674 {"GetGenericParameterPosition", ves_icall_Type_GetGenericParameterPosition},
5675 {"GetGenericTypeDefinition_impl", ves_icall_Type_GetGenericTypeDefinition_impl},
5676 {"GetInterfaceMapData", ves_icall_Type_GetInterfaceMapData},
5677 {"GetTypeCode", ves_icall_type_GetTypeCode},
5678 {"IsArrayImpl", ves_icall_Type_IsArrayImpl},
5679 {"IsInstanceOfType", ves_icall_type_IsInstanceOfType},
5680 {"get_IsGenericInstance", ves_icall_Type_get_IsGenericInstance},
5681 {"get_IsGenericTypeDefinition", ves_icall_Type_get_IsGenericTypeDefinition},
5682 {"internal_from_handle", ves_icall_type_from_handle},
5683 {"internal_from_name", ves_icall_type_from_name},
5684 {"make_array_type", ves_icall_Type_make_array_type},
5685 {"make_byref_type", ves_icall_Type_make_byref_type},
5686 {"type_is_assignable_from", ves_icall_type_is_assignable_from},
5687 {"type_is_subtype_of", ves_icall_type_is_subtype_of}
5690 static const IcallEntry typedref_icalls [] = {
5691 {"ToObject", mono_TypedReference_ToObject}
5694 static const IcallEntry valuetype_icalls [] = {
5695 {"InternalEquals", ves_icall_System_ValueType_Equals},
5696 {"InternalGetHashCode", ves_icall_System_ValueType_InternalGetHashCode}
5699 static const IcallEntry web_icalls [] = {
5700 {"GetMachineConfigPath", ves_icall_System_Configuration_DefaultConfig_get_machine_config_path},
5701 {"GetMachineInstallDirectory", ves_icall_System_Web_Util_ICalls_get_machine_install_dir}
5704 static const IcallEntry identity_icalls [] = {
5705 {"GetCurrentToken", ves_icall_System_Security_Principal_WindowsIdentity_GetCurrentToken},
5706 {"GetTokenName", ves_icall_System_Security_Principal_WindowsIdentity_GetTokenName},
5707 {"GetUserToken", ves_icall_System_Security_Principal_WindowsIdentity_GetUserToken},
5708 {"_GetRoles", ves_icall_System_Security_Principal_WindowsIdentity_GetRoles}
5711 static const IcallEntry impersonation_icalls [] = {
5712 {"CloseToken", ves_icall_System_Security_Principal_WindowsImpersonationContext_CloseToken},
5713 {"DuplicateToken", ves_icall_System_Security_Principal_WindowsImpersonationContext_DuplicateToken},
5714 {"RevertToSelf", ves_icall_System_Security_Principal_WindowsImpersonationContext_RevertToSelf},
5715 {"SetCurrentToken", ves_icall_System_Security_Principal_WindowsImpersonationContext_SetCurrentToken}
5718 static const IcallEntry principal_icalls [] = {
5719 {"IsMemberOfGroupId", ves_icall_System_Security_Principal_WindowsPrincipal_IsMemberOfGroupId},
5720 {"IsMemberOfGroupName", ves_icall_System_Security_Principal_WindowsPrincipal_IsMemberOfGroupName}
5723 static const IcallEntry keypair_icalls [] = {
5724 {"_CanSecure", ves_icall_Mono_Security_Cryptography_KeyPairPersistence_CanSecure},
5725 {"_IsMachineProtected", ves_icall_Mono_Security_Cryptography_KeyPairPersistence_IsMachineProtected},
5726 {"_IsUserProtected", ves_icall_Mono_Security_Cryptography_KeyPairPersistence_IsUserProtected},
5727 {"_ProtectMachine", ves_icall_Mono_Security_Cryptography_KeyPairPersistence_ProtectMachine},
5728 {"_ProtectUser", ves_icall_Mono_Security_Cryptography_KeyPairPersistence_ProtectUser}
5732 static const IcallEntry array_icalls [] = {
5737 /* keep the entries all sorted */
5738 static const IcallMap icall_entries [] = {
5739 {"Mono.Security.Cryptography.KeyPairPersistence", keypair_icalls, G_N_ELEMENTS (keypair_icalls)},
5740 {"System.Activator", activator_icalls, G_N_ELEMENTS (activator_icalls)},
5741 {"System.AppDomain", appdomain_icalls, G_N_ELEMENTS (appdomain_icalls)},
5742 {"System.ArgIterator", argiterator_icalls, G_N_ELEMENTS (argiterator_icalls)},
5743 {"System.Array", array_icalls, G_N_ELEMENTS (array_icalls)},
5744 {"System.Buffer", buffer_icalls, G_N_ELEMENTS (buffer_icalls)},
5745 {"System.Char", char_icalls, G_N_ELEMENTS (char_icalls)},
5746 {"System.Configuration.DefaultConfig", defaultconf_icalls, G_N_ELEMENTS (defaultconf_icalls)},
5747 {"System.CurrentTimeZone", timezone_icalls, G_N_ELEMENTS (timezone_icalls)},
5748 {"System.DateTime", datetime_icalls, G_N_ELEMENTS (datetime_icalls)},
5749 {"System.Decimal", decimal_icalls, G_N_ELEMENTS (decimal_icalls)},
5750 {"System.Delegate", delegate_icalls, G_N_ELEMENTS (delegate_icalls)},
5751 {"System.Diagnostics.DefaultTraceListener", tracelist_icalls, G_N_ELEMENTS (tracelist_icalls)},
5752 {"System.Diagnostics.FileVersionInfo", fileversion_icalls, G_N_ELEMENTS (fileversion_icalls)},
5753 {"System.Diagnostics.Process", process_icalls, G_N_ELEMENTS (process_icalls)},
5754 {"System.Double", double_icalls, G_N_ELEMENTS (double_icalls)},
5755 {"System.Enum", enum_icalls, G_N_ELEMENTS (enum_icalls)},
5756 {"System.Environment", environment_icalls, G_N_ELEMENTS (environment_icalls)},
5757 {"System.GC", gc_icalls, G_N_ELEMENTS (gc_icalls)},
5758 {"System.Globalization.CompareInfo", compareinfo_icalls, G_N_ELEMENTS (compareinfo_icalls)},
5759 {"System.Globalization.CultureInfo", cultureinfo_icalls, G_N_ELEMENTS (cultureinfo_icalls)},
5760 {"System.IO.FAMWatcher", famwatcher_icalls, G_N_ELEMENTS (famwatcher_icalls)},
5761 {"System.IO.FileSystemWatcher", filewatcher_icalls, G_N_ELEMENTS (filewatcher_icalls)},
5762 {"System.IO.MonoIO", monoio_icalls, G_N_ELEMENTS (monoio_icalls)},
5763 {"System.IO.Path", path_icalls, G_N_ELEMENTS (path_icalls)},
5764 {"System.Math", math_icalls, G_N_ELEMENTS (math_icalls)},
5765 {"System.MonoCustomAttrs", customattrs_icalls, G_N_ELEMENTS (customattrs_icalls)},
5766 {"System.MonoEnumInfo", enuminfo_icalls, G_N_ELEMENTS (enuminfo_icalls)},
5767 {"System.MonoType", monotype_icalls, G_N_ELEMENTS (monotype_icalls)},
5768 {"System.Net.Dns", dns_icalls, G_N_ELEMENTS (dns_icalls)},
5769 {"System.Net.Sockets.Socket", socket_icalls, G_N_ELEMENTS (socket_icalls)},
5770 {"System.Net.Sockets.SocketException", socketex_icalls, G_N_ELEMENTS (socketex_icalls)},
5771 {"System.Object", object_icalls, G_N_ELEMENTS (object_icalls)},
5772 {"System.Reflection.Assembly", assembly_icalls, G_N_ELEMENTS (assembly_icalls)},
5773 {"System.Reflection.Emit.AssemblyBuilder", assemblybuilder_icalls, G_N_ELEMENTS (assemblybuilder_icalls)},
5774 {"System.Reflection.Emit.CustomAttributeBuilder", customattrbuilder_icalls, G_N_ELEMENTS (customattrbuilder_icalls)},
5775 {"System.Reflection.Emit.DynamicMethod", dynamicmethod_icalls, G_N_ELEMENTS (dynamicmethod_icalls)},
5776 {"System.Reflection.Emit.GenericTypeParameterBuilder", generictypeparambuilder_icalls, G_N_ELEMENTS (generictypeparambuilder_icalls)},
5777 {"System.Reflection.Emit.MethodBuilder", methodbuilder_icalls, G_N_ELEMENTS (methodbuilder_icalls)},
5778 {"System.Reflection.Emit.ModuleBuilder", modulebuilder_icalls, G_N_ELEMENTS (modulebuilder_icalls)},
5779 {"System.Reflection.Emit.SignatureHelper", signaturehelper_icalls, G_N_ELEMENTS (signaturehelper_icalls)},
5780 {"System.Reflection.Emit.TypeBuilder", typebuilder_icalls, G_N_ELEMENTS (typebuilder_icalls)},
5781 {"System.Reflection.FieldInfo", fieldinfo_icalls, G_N_ELEMENTS (fieldinfo_icalls)},
5782 {"System.Reflection.MethodBase", methodbase_icalls, G_N_ELEMENTS (methodbase_icalls)},
5783 {"System.Reflection.Module", module_icalls, G_N_ELEMENTS (module_icalls)},
5784 {"System.Reflection.MonoCMethod", monocmethod_icalls, G_N_ELEMENTS (monocmethod_icalls)},
5785 {"System.Reflection.MonoEventInfo", monoeventinfo_icalls, G_N_ELEMENTS (monoeventinfo_icalls)},
5786 {"System.Reflection.MonoField", monofield_icalls, G_N_ELEMENTS (monofield_icalls)},
5787 {"System.Reflection.MonoGenericInst", monogenericinst_icalls, G_N_ELEMENTS (monogenericinst_icalls)},
5788 {"System.Reflection.MonoMethod", monomethod_icalls, G_N_ELEMENTS (monomethod_icalls)},
5789 {"System.Reflection.MonoMethodInfo", monomethodinfo_icalls, G_N_ELEMENTS (monomethodinfo_icalls)},
5790 {"System.Reflection.MonoPropertyInfo", monopropertyinfo_icalls, G_N_ELEMENTS (monopropertyinfo_icalls)},
5791 {"System.Runtime.CompilerServices.RuntimeHelpers", runtimehelpers_icalls, G_N_ELEMENTS (runtimehelpers_icalls)},
5792 {"System.Runtime.InteropServices.GCHandle", gchandle_icalls, G_N_ELEMENTS (gchandle_icalls)},
5793 {"System.Runtime.InteropServices.Marshal", marshal_icalls, G_N_ELEMENTS (marshal_icalls)},
5794 {"System.Runtime.Remoting.Activation.ActivationServices", activationservices_icalls, G_N_ELEMENTS (activationservices_icalls)},
5795 {"System.Runtime.Remoting.Messaging.MonoMethodMessage", monomethodmessage_icalls, G_N_ELEMENTS (monomethodmessage_icalls)},
5796 {"System.Runtime.Remoting.Proxies.RealProxy", realproxy_icalls, G_N_ELEMENTS (realproxy_icalls)},
5797 {"System.Runtime.Remoting.RemotingServices", remotingservices_icalls, G_N_ELEMENTS (remotingservices_icalls)},
5798 {"System.RuntimeMethodHandle", methodhandle_icalls, G_N_ELEMENTS (methodhandle_icalls)},
5799 {"System.Security.Cryptography.RNGCryptoServiceProvider", rng_icalls, G_N_ELEMENTS (rng_icalls)},
5800 {"System.Security.Principal.WindowsIdentity", identity_icalls, G_N_ELEMENTS (identity_icalls)},
5801 {"System.Security.Principal.WindowsImpersonationContext", impersonation_icalls, G_N_ELEMENTS (impersonation_icalls)},
5802 {"System.Security.Principal.WindowsPrincipal", principal_icalls, G_N_ELEMENTS (principal_icalls)},
5803 {"System.String", string_icalls, G_N_ELEMENTS (string_icalls)},
5804 {"System.Text.Encoding", encoding_icalls, G_N_ELEMENTS (encoding_icalls)},
5805 {"System.Threading.Interlocked", interlocked_icalls, G_N_ELEMENTS (interlocked_icalls)},
5806 {"System.Threading.Monitor", monitor_icalls, G_N_ELEMENTS (monitor_icalls)},
5807 {"System.Threading.Mutex", mutex_icalls, G_N_ELEMENTS (mutex_icalls)},
5808 {"System.Threading.NativeEventCalls", nativeevents_icalls, G_N_ELEMENTS (nativeevents_icalls)},
5809 {"System.Threading.Thread", thread_icalls, G_N_ELEMENTS (thread_icalls)},
5810 {"System.Threading.ThreadPool", threadpool_icalls, G_N_ELEMENTS (threadpool_icalls)},
5811 {"System.Threading.WaitHandle", waithandle_icalls, G_N_ELEMENTS (waithandle_icalls)},
5812 {"System.Type", type_icalls, G_N_ELEMENTS (type_icalls)},
5813 {"System.TypedReference", typedref_icalls, G_N_ELEMENTS (typedref_icalls)},
5814 {"System.ValueType", valuetype_icalls, G_N_ELEMENTS (valuetype_icalls)},
5815 {"System.Web.Util.ICalls", web_icalls, G_N_ELEMENTS (web_icalls)}
5818 static GHashTable *icall_hash = NULL;
5821 mono_init_icall (void)
5825 /* check that tables are sorted: disable in release */
5828 const IcallMap *imap;
5829 const IcallEntry *ientry;
5830 const char *prev_class = NULL;
5831 const char *prev_method;
5833 for (i = 0; i < G_N_ELEMENTS (icall_entries); ++i) {
5834 imap = &icall_entries [i];
5836 if (prev_class && strcmp (prev_class, imap->klass) >= 0)
5837 g_print ("class %s should come before class %s\n", imap->klass, prev_class);
5838 prev_class = imap->klass;
5839 for (j = 0; j < imap->size; ++j) {
5840 ientry = &imap->icalls [j];
5841 if (prev_method && strcmp (prev_method, ientry->method) >= 0)
5842 g_print ("method %s should come before method %s\n", ientry->method, prev_method);
5843 prev_method = ientry->method;
5848 icall_hash = g_hash_table_new (g_str_hash , g_str_equal);
5852 mono_add_internal_call (const char *name, gconstpointer method)
5854 mono_loader_lock ();
5856 g_hash_table_insert (icall_hash, g_strdup (name), (gpointer) method);
5858 mono_loader_unlock ();
5862 compare_class_imap (const void *key, const void *elem)
5864 const IcallMap* imap = (const IcallMap*)elem;
5865 return strcmp (key, imap->klass);
5868 static const IcallMap*
5869 find_class_icalls (const char *name)
5871 return (const IcallMap*) bsearch (name, icall_entries, G_N_ELEMENTS (icall_entries), sizeof (IcallMap), compare_class_imap);
5875 compare_method_imap (const void *key, const void *elem)
5877 const IcallEntry* ientry = (const IcallEntry*)elem;
5878 return strcmp (key, ientry->method);
5882 find_method_icall (const IcallMap *imap, const char *name)
5884 const IcallEntry *ientry = (const IcallEntry*) bsearch (name, imap->icalls, imap->size, sizeof (IcallEntry), compare_method_imap);
5886 return (void*)ientry->func;
5891 * we should probably export this as an helper (handle nested types).
5892 * Returns the number of chars written in buf.
5895 concat_class_name (char *buf, int bufsize, MonoClass *klass)
5897 int nspacelen, cnamelen;
5898 nspacelen = strlen (klass->name_space);
5899 cnamelen = strlen (klass->name);
5900 if (nspacelen + cnamelen + 2 > bufsize)
5903 memcpy (buf, klass->name_space, nspacelen);
5904 buf [nspacelen ++] = '.';
5906 memcpy (buf + nspacelen, klass->name, cnamelen);
5907 buf [nspacelen + cnamelen] = 0;
5908 return nspacelen + cnamelen;
5912 mono_lookup_internal_call (MonoMethod *method)
5917 int typelen = 0, mlen, siglen;
5919 const IcallMap *imap;
5921 g_assert (method != NULL);
5923 typelen = concat_class_name (mname, sizeof (mname), method->klass);
5927 imap = find_class_icalls (mname);
5929 mname [typelen] = ':';
5930 mname [typelen + 1] = ':';
5932 mlen = strlen (method->name);
5933 memcpy (mname + typelen + 2, method->name, mlen);
5934 sigstart = mname + typelen + 2 + mlen;
5937 tmpsig = mono_signature_get_desc (method->signature, TRUE);
5938 siglen = strlen (tmpsig);
5939 if (typelen + mlen + siglen + 6 > sizeof (mname))
5942 memcpy (sigstart + 1, tmpsig, siglen);
5943 sigstart [siglen + 1] = ')';
5944 sigstart [siglen + 2] = 0;
5947 mono_loader_lock ();
5949 res = g_hash_table_lookup (icall_hash, mname);
5951 mono_loader_unlock ();
5954 /* try without signature */
5956 res = g_hash_table_lookup (icall_hash, mname);
5958 mono_loader_unlock ();
5962 /* it wasn't found in the static call tables */
5964 mono_loader_unlock ();
5967 res = find_method_icall (imap, sigstart - mlen);
5969 mono_loader_unlock ();
5972 /* try _with_ signature */
5974 res = find_method_icall (imap, sigstart - mlen);
5976 mono_loader_unlock ();
5980 g_warning ("cant resolve internal call to \"%s\" (tested without signature also)", mname);
5981 g_print ("\nYour mono runtime and class libraries are out of sync.\n");
5982 g_print ("The out of sync library is: %s\n", method->klass->image->name);
5983 g_print ("\nWhen you update one from cvs you need to update, compile and install\nthe other too.\n");
5984 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");
5985 g_print ("If you see other errors or faults after this message they are probably related\n");
5986 g_print ("and you need to fix your mono install first.\n");
5988 mono_loader_unlock ();