5 * Dietmar Maurer (dietmar@ximian.com)
6 * Paolo Molaro (lupus@ximian.com)
7 * Patrik Torstensson (patrik.torstensson@labs2.com)
9 * (C) 2001 Ximian, Inc.
19 #if defined (PLATFORM_WIN32)
23 #include <mono/metadata/object.h>
24 #include <mono/metadata/threads.h>
25 #include <mono/metadata/threads-types.h>
26 #include <mono/metadata/threadpool.h>
27 #include <mono/metadata/monitor.h>
28 #include <mono/metadata/reflection.h>
29 #include <mono/metadata/assembly.h>
30 #include <mono/metadata/tabledefs.h>
31 #include <mono/metadata/exception.h>
32 #include <mono/metadata/file-io.h>
33 #include <mono/metadata/socket-io.h>
34 #include <mono/metadata/mono-endian.h>
35 #include <mono/metadata/tokentype.h>
36 #include <mono/metadata/unicode.h>
37 #include <mono/metadata/domain-internals.h>
38 #include <mono/metadata/metadata-internals.h>
39 #include <mono/metadata/class-internals.h>
40 #include <mono/metadata/marshal.h>
41 #include <mono/metadata/gc-internal.h>
42 #include <mono/metadata/rand.h>
43 #include <mono/metadata/sysmath.h>
44 #include <mono/metadata/string-icalls.h>
45 #include <mono/metadata/mono-debug-debugger.h>
46 #include <mono/metadata/process.h>
47 #include <mono/metadata/environment.h>
48 #include <mono/metadata/profiler-private.h>
49 #include <mono/metadata/locales.h>
50 #include <mono/metadata/filewatcher.h>
51 #include <mono/metadata/char-conversions.h>
52 #include <mono/metadata/security.h>
53 #include <mono/metadata/mono-config.h>
54 #include <mono/io-layer/io-layer.h>
55 #include <mono/utils/strtod.h>
56 #include <mono/utils/monobitset.h>
58 #if defined (PLATFORM_WIN32)
64 static MonoReflectionAssembly* ves_icall_System_Reflection_Assembly_GetCallingAssembly (void);
68 * We expect a pointer to a char, not a string
71 mono_double_ParseImpl (char *ptr)
79 result = bsd_strtod (ptr, &endptr);
81 if (!*ptr || (endptr && *endptr))
82 mono_raise_exception (mono_exception_from_name (mono_defaults.corlib,
90 ves_icall_System_Double_AssertEndianity (double *value)
94 MONO_DOUBLE_ASSERT_ENDIANITY (value);
98 ves_icall_System_Array_GetValueImpl (MonoObject *this, guint32 pos)
107 ao = (MonoArray *)this;
108 ac = (MonoClass *)ao->obj.vtable->klass;
110 esize = mono_array_element_size (ac);
111 ea = (gpointer*)((char*)ao->vector + (pos * esize));
113 if (ac->element_class->valuetype)
114 return mono_value_box (this->vtable->domain, ac->element_class, ea);
120 ves_icall_System_Array_GetValue (MonoObject *this, MonoObject *idxs)
128 MONO_CHECK_ARG_NULL (idxs);
130 io = (MonoArray *)idxs;
131 ic = (MonoClass *)io->obj.vtable->klass;
133 ao = (MonoArray *)this;
134 ac = (MonoClass *)ao->obj.vtable->klass;
136 g_assert (ic->rank == 1);
137 if (io->bounds != NULL || io->max_length != ac->rank)
138 mono_raise_exception (mono_get_exception_argument (NULL, NULL));
140 ind = (guint32 *)io->vector;
142 if (ao->bounds == NULL) {
143 if (*ind < 0 || *ind >= ao->max_length)
144 mono_raise_exception (mono_get_exception_index_out_of_range ());
146 return ves_icall_System_Array_GetValueImpl (this, *ind);
149 for (i = 0; i < ac->rank; i++)
150 if ((ind [i] < ao->bounds [i].lower_bound) ||
151 (ind [i] >= ao->bounds [i].length + ao->bounds [i].lower_bound))
152 mono_raise_exception (mono_get_exception_index_out_of_range ());
154 pos = ind [0] - ao->bounds [0].lower_bound;
155 for (i = 1; i < ac->rank; i++)
156 pos = pos*ao->bounds [i].length + ind [i] -
157 ao->bounds [i].lower_bound;
159 return ves_icall_System_Array_GetValueImpl (this, pos);
163 ves_icall_System_Array_SetValueImpl (MonoArray *this, MonoObject *value, guint32 pos)
165 MonoClass *ac, *vc, *ec;
176 vc = value->vtable->klass;
180 ac = this->obj.vtable->klass;
181 ec = ac->element_class;
183 esize = mono_array_element_size (ac);
184 ea = (gpointer*)((char*)this->vector + (pos * esize));
185 va = (gpointer*)((char*)value + sizeof (MonoObject));
188 memset (ea, 0, esize);
192 #define NO_WIDENING_CONVERSION G_STMT_START{\
193 mono_raise_exception (mono_get_exception_argument ( \
194 "value", "not a widening conversion")); \
197 #define CHECK_WIDENING_CONVERSION(extra) G_STMT_START{\
198 if (esize < vsize + (extra)) \
199 mono_raise_exception (mono_get_exception_argument ( \
200 "value", "not a widening conversion")); \
203 #define INVALID_CAST G_STMT_START{\
204 mono_raise_exception (mono_get_exception_invalid_cast ()); \
207 /* Check element (destination) type. */
208 switch (ec->byval_arg.type) {
209 case MONO_TYPE_STRING:
210 switch (vc->byval_arg.type) {
211 case MONO_TYPE_STRING:
217 case MONO_TYPE_BOOLEAN:
218 switch (vc->byval_arg.type) {
219 case MONO_TYPE_BOOLEAN:
232 NO_WIDENING_CONVERSION;
239 if (!ec->valuetype) {
240 if (!mono_object_isinst (value, ec))
242 *ea = (gpointer)value;
246 if (mono_object_isinst (value, ec)) {
247 memcpy (ea, (char *)value + sizeof (MonoObject), esize);
254 vsize = mono_class_instance_size (vc) - sizeof (MonoObject);
257 g_message (G_STRLOC ": %d (%d) <= %d (%d)",
258 ec->byval_arg.type, esize,
259 vc->byval_arg.type, vsize);
262 #define ASSIGN_UNSIGNED(etype) G_STMT_START{\
263 switch (vc->byval_arg.type) { \
268 case MONO_TYPE_CHAR: \
269 CHECK_WIDENING_CONVERSION(0); \
270 *(etype *) ea = (etype) u64; \
272 /* You can't assign a signed value to an unsigned array. */ \
277 /* You can't assign a floating point number to an integer array. */ \
280 NO_WIDENING_CONVERSION; \
284 #define ASSIGN_SIGNED(etype) G_STMT_START{\
285 switch (vc->byval_arg.type) { \
290 CHECK_WIDENING_CONVERSION(0); \
291 *(etype *) ea = (etype) i64; \
293 /* You can assign an unsigned value to a signed array if the array's */ \
294 /* element size is larger than the value size. */ \
299 case MONO_TYPE_CHAR: \
300 CHECK_WIDENING_CONVERSION(1); \
301 *(etype *) ea = (etype) u64; \
303 /* You can't assign a floating point number to an integer array. */ \
306 NO_WIDENING_CONVERSION; \
310 #define ASSIGN_REAL(etype) G_STMT_START{\
311 switch (vc->byval_arg.type) { \
314 CHECK_WIDENING_CONVERSION(0); \
315 *(etype *) ea = (etype) r64; \
317 /* All integer values fit into a floating point array, so we don't */ \
318 /* need to CHECK_WIDENING_CONVERSION here. */ \
323 *(etype *) ea = (etype) i64; \
329 case MONO_TYPE_CHAR: \
330 *(etype *) ea = (etype) u64; \
335 switch (vc->byval_arg.type) {
337 u64 = *(guint8 *) va;
340 u64 = *(guint16 *) va;
343 u64 = *(guint32 *) va;
346 u64 = *(guint64 *) va;
352 i64 = *(gint16 *) va;
355 i64 = *(gint32 *) va;
358 i64 = *(gint64 *) va;
361 r64 = *(gfloat *) va;
364 r64 = *(gdouble *) va;
367 u64 = *(guint16 *) va;
369 case MONO_TYPE_BOOLEAN:
370 /* Boolean is only compatible with itself. */
371 switch (ec->byval_arg.type) {
383 NO_WIDENING_CONVERSION;
390 /* If we can't do a direct copy, let's try a widening conversion. */
391 switch (ec->byval_arg.type) {
393 ASSIGN_UNSIGNED (guint16);
395 ASSIGN_UNSIGNED (guint8);
397 ASSIGN_UNSIGNED (guint16);
399 ASSIGN_UNSIGNED (guint32);
401 ASSIGN_UNSIGNED (guint64);
403 ASSIGN_SIGNED (gint8);
405 ASSIGN_SIGNED (gint16);
407 ASSIGN_SIGNED (gint32);
409 ASSIGN_SIGNED (gint64);
411 ASSIGN_REAL (gfloat);
413 ASSIGN_REAL (gdouble);
417 /* Not reached, INVALID_CAST does not return. Just to avoid a compiler warning ... */
421 #undef NO_WIDENING_CONVERSION
422 #undef CHECK_WIDENING_CONVERSION
423 #undef ASSIGN_UNSIGNED
429 ves_icall_System_Array_SetValue (MonoArray *this, MonoObject *value,
437 MONO_CHECK_ARG_NULL (idxs);
439 ic = idxs->obj.vtable->klass;
440 ac = this->obj.vtable->klass;
442 g_assert (ic->rank == 1);
443 if (idxs->bounds != NULL || idxs->max_length != ac->rank)
444 mono_raise_exception (mono_get_exception_argument (NULL, NULL));
446 ind = (guint32 *)idxs->vector;
448 if (this->bounds == NULL) {
449 if (*ind < 0 || *ind >= this->max_length)
450 mono_raise_exception (mono_get_exception_index_out_of_range ());
452 ves_icall_System_Array_SetValueImpl (this, value, *ind);
456 for (i = 0; i < ac->rank; i++)
457 if ((ind [i] < this->bounds [i].lower_bound) ||
458 (ind [i] >= this->bounds [i].length + this->bounds [i].lower_bound))
459 mono_raise_exception (mono_get_exception_index_out_of_range ());
461 pos = ind [0] - this->bounds [0].lower_bound;
462 for (i = 1; i < ac->rank; i++)
463 pos = pos * this->bounds [i].length + ind [i] -
464 this->bounds [i].lower_bound;
466 ves_icall_System_Array_SetValueImpl (this, value, pos);
470 ves_icall_System_Array_CreateInstanceImpl (MonoReflectionType *type, MonoArray *lengths, MonoArray *bounds)
475 gboolean bounded = FALSE;
479 MONO_CHECK_ARG_NULL (type);
480 MONO_CHECK_ARG_NULL (lengths);
482 MONO_CHECK_ARG (lengths, mono_array_length (lengths) > 0);
484 MONO_CHECK_ARG (bounds, mono_array_length (lengths) == mono_array_length (bounds));
486 for (i = 0; i < mono_array_length (lengths); i++)
487 if (mono_array_get (lengths, gint32, i) < 0)
488 mono_raise_exception (mono_get_exception_argument_out_of_range (NULL));
490 if (bounds && (mono_array_length (bounds) == 1) && (mono_array_get (bounds, gint32, 0) != 0))
491 /* vectors are not the same as one dimensional arrays with no-zero bounds */
496 aklass = mono_bounded_array_class_get (mono_class_from_mono_type (type->type), mono_array_length (lengths), bounded);
498 sizes = alloca (aklass->rank * sizeof(guint32) * 2);
499 for (i = 0; i < aklass->rank; ++i) {
500 sizes [i] = mono_array_get (lengths, gint32, i);
502 sizes [i + aklass->rank] = mono_array_get (bounds, gint32, i);
504 sizes [i + aklass->rank] = 0;
507 array = mono_array_new_full (mono_object_domain (type), aklass, sizes, sizes + aklass->rank);
513 ves_icall_System_Array_GetRank (MonoObject *this)
517 return this->vtable->klass->rank;
521 ves_icall_System_Array_GetLength (MonoArray *this, gint32 dimension)
523 gint32 rank = ((MonoObject *)this)->vtable->klass->rank;
527 if ((dimension < 0) || (dimension >= rank))
528 mono_raise_exception (mono_get_exception_index_out_of_range ());
530 if (this->bounds == NULL)
531 return this->max_length;
533 return this->bounds [dimension].length;
537 ves_icall_System_Array_GetLowerBound (MonoArray *this, gint32 dimension)
539 gint32 rank = ((MonoObject *)this)->vtable->klass->rank;
543 if ((dimension < 0) || (dimension >= rank))
544 mono_raise_exception (mono_get_exception_index_out_of_range ());
546 if (this->bounds == NULL)
549 return this->bounds [dimension].lower_bound;
553 ves_icall_System_Array_ClearInternal (MonoArray *arr, int idx, int length)
555 int sz = mono_array_element_size (mono_object_class (arr));
556 memset (mono_array_addr_with_size (arr, idx, sz), 0, length * sz);
560 ves_icall_System_Array_FastCopy (MonoArray *source, int source_idx, MonoArray* dest, int dest_idx, int length)
565 MonoClass *src_class;
566 MonoClass *dest_class;
571 if (source->obj.vtable->klass->rank != dest->obj.vtable->klass->rank)
574 if (source->bounds || dest->bounds)
577 if ((dest_idx + length > mono_array_length (dest)) ||
578 (source_idx + length > mono_array_length (source)))
581 element_size = mono_array_element_size (source->obj.vtable->klass);
582 dest_addr = mono_array_addr_with_size (dest, element_size, dest_idx);
583 source_addr = mono_array_addr_with_size (source, element_size, source_idx);
585 src_class = source->obj.vtable->klass->element_class;
586 dest_class = dest->obj.vtable->klass->element_class;
589 * Handle common cases.
592 /* Case1: object[] -> valuetype[] (ArrayList::ToArray) */
593 if (src_class == mono_defaults.object_class && dest_class->valuetype) {
594 for (i = source_idx; i < source_idx + length; ++i) {
595 MonoObject *elem = mono_array_get (source, MonoObject*, i);
596 if (elem && !mono_object_isinst (elem, dest_class))
600 element_size = mono_array_element_size (dest->obj.vtable->klass);
601 for (i = 0; i < length; ++i) {
602 MonoObject *elem = mono_array_get (source, MonoObject*, source_idx + i);
603 void *addr = mono_array_addr_with_size (dest, element_size, dest_idx + i);
605 memset (addr, 0, element_size);
607 memcpy (addr, (char *)elem + sizeof (MonoObject), element_size);
612 if (src_class != dest_class) {
613 if (dest_class->valuetype || dest_class->enumtype || src_class->valuetype || src_class->enumtype)
616 if (mono_class_is_subclass_of (src_class, dest_class, FALSE))
618 /* Case2: object[] -> reftype[] (ArrayList::ToArray) */
619 else if (mono_class_is_subclass_of (dest_class, src_class, FALSE))
620 for (i = source_idx; i < source_idx + length; ++i) {
621 MonoObject *elem = mono_array_get (source, MonoObject*, i);
622 if (elem && !mono_object_isinst (elem, dest_class))
629 memmove (dest_addr, source_addr, element_size * length);
635 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_InitializeArray (MonoArray *array, MonoClassField *field_handle)
637 MonoClass *klass = array->obj.vtable->klass;
638 guint32 size = mono_array_element_size (klass);
643 if (array->bounds == NULL)
644 size *= array->max_length;
646 for (i = 0; i < klass->rank; ++i)
647 size *= array->bounds [i].length;
649 memcpy (mono_array_addr (array, char, 0), field_handle->data, size);
651 #if G_BYTE_ORDER != G_LITTLE_ENDIAN
655 guint ## n *data = (guint ## n *) mono_array_addr (array, char, 0); \
657 for (i = 0; i < size; i += n/8, data++) { \
658 tmp = read ## n (data); \
663 /* printf ("Initialize array with elements of %s type\n", klass->element_class->name); */
665 switch (klass->element_class->byval_arg.type) {
685 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetOffsetToStringData (void)
689 return offsetof (MonoString, chars);
693 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetObjectValue (MonoObject *obj)
697 if ((obj == NULL) || (! (obj->vtable->klass->valuetype)))
700 return mono_object_clone (obj);
704 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_RunClassConstructor (MonoType *handle)
710 MONO_CHECK_ARG_NULL (handle);
712 klass = mono_class_from_mono_type (handle);
713 MONO_CHECK_ARG (handle, klass);
715 /* This will call the type constructor */
716 if (! (klass->flags & TYPE_ATTRIBUTE_INTERFACE))
717 mono_runtime_class_init (mono_class_vtable (mono_domain_get (), klass));
721 ves_icall_System_Object_MemberwiseClone (MonoObject *this)
725 return mono_object_clone (this);
729 #define MONO_OBJECT_ALIGNMENT_SHIFT 3
731 #define MONO_OBJECT_ALIGNMENT_SHIFT 2
735 * Return hashcode based on object address. This function will need to be
736 * smarter in the presence of a moving garbage collector, which will cache
737 * the address hash before relocating the object.
739 * Wang's address-based hash function:
740 * http://www.concentric.net/~Ttwang/tech/addrhash.htm
743 ves_icall_System_Object_GetHashCode (MonoObject *this)
745 register guint32 key;
749 key = (GPOINTER_TO_UINT (this) >> MONO_OBJECT_ALIGNMENT_SHIFT) * 2654435761u;
751 return key & 0x7fffffff;
755 ves_icall_System_ValueType_InternalGetHashCode (MonoObject *this, MonoArray **fields)
759 MonoObject **values = NULL;
766 klass = this->vtable->klass;
768 if (klass->field.count == 0)
769 return ves_icall_System_Object_GetHashCode (this);
772 * Compute the starting value of the hashcode for fields of primitive
773 * types, and return the remaining fields in an array to the managed side.
774 * This way, we can avoid costly reflection operations in managed code.
776 for (i = 0; i < klass->field.count; ++i) {
777 MonoClassField *field = &klass->fields [i];
778 if (field->type->attrs & FIELD_ATTRIBUTE_STATIC)
780 if (mono_field_is_deleted (field))
782 /* FIXME: Add more types */
783 switch (field->type->type) {
785 result ^= *(gint32*)((guint8*)this + field->offset);
787 case MONO_TYPE_STRING: {
789 s = *(MonoString**)((guint8*)this + field->offset);
791 result ^= ves_icall_System_String_GetHashCode (s);
796 values = alloca (klass->field.count * sizeof (MonoObject*));
797 o = mono_field_get_value_object (mono_object_domain (this), field, this);
798 values [count++] = o;
803 *fields = mono_array_new (mono_domain_get (), mono_defaults.object_class, count);
804 memcpy (mono_array_addr (*fields, MonoObject*, 0), values, count * sizeof (MonoObject*));
812 ves_icall_System_ValueType_Equals (MonoObject *this, MonoObject *that, MonoArray **fields)
816 MonoObject **values = NULL;
822 MONO_CHECK_ARG_NULL (that);
824 if (this->vtable != that->vtable)
827 klass = this->vtable->klass;
830 * Do the comparison for fields of primitive type and return a result if
831 * possible. Otherwise, return the remaining fields in an array to the
832 * managed side. This way, we can avoid costly reflection operations in
836 for (i = 0; i < klass->field.count; ++i) {
837 MonoClassField *field = &klass->fields [i];
838 if (field->type->attrs & FIELD_ATTRIBUTE_STATIC)
840 if (mono_field_is_deleted (field))
842 /* FIXME: Add more types */
843 switch (field->type->type) {
845 if (*(gint32*)((guint8*)this + field->offset) != *(gint32*)((guint8*)that + field->offset))
848 case MONO_TYPE_STRING: {
850 guint32 s1len, s2len;
851 s1 = *(MonoString**)((guint8*)this + field->offset);
852 s2 = *(MonoString**)((guint8*)that + field->offset);
855 if ((s1 == NULL) || (s2 == NULL))
857 s1len = mono_string_length (s1);
858 s2len = mono_string_length (s2);
862 if (memcmp (mono_string_chars (s1), mono_string_chars (s2), s1len * sizeof (gunichar2)) != 0)
868 values = alloca (klass->field.count * 2 * sizeof (MonoObject*));
869 o = mono_field_get_value_object (mono_object_domain (this), field, this);
870 values [count++] = o;
871 o = mono_field_get_value_object (mono_object_domain (this), field, that);
872 values [count++] = o;
877 *fields = mono_array_new (mono_domain_get (), mono_defaults.object_class, count);
878 memcpy (mono_array_addr (*fields, MonoObject*, 0), values, count * sizeof (MonoObject*));
886 static MonoReflectionType *
887 ves_icall_System_Object_GetType (MonoObject *obj)
891 if (obj->vtable->klass != mono_defaults.transparent_proxy_class)
892 return mono_type_get_object (mono_object_domain (obj), &obj->vtable->klass->byval_arg);
894 return mono_type_get_object (mono_object_domain (obj), &((MonoTransparentProxy*)obj)->remote_class->proxy_class->byval_arg);
898 mono_type_type_from_obj (MonoReflectionType *mtype, MonoObject *obj)
902 mtype->type = &obj->vtable->klass->byval_arg;
903 g_assert (mtype->type->type);
907 ves_icall_ModuleBuilder_getToken (MonoReflectionModuleBuilder *mb, MonoObject *obj)
911 return mono_image_create_token (mb->dynamic_image, obj, TRUE);
915 ves_icall_ModuleBuilder_getMethodToken (MonoReflectionModuleBuilder *mb,
916 MonoReflectionMethod *method,
917 MonoArray *opt_param_types)
921 return mono_image_create_method_token (
922 mb->dynamic_image, (MonoObject *) method, opt_param_types);
926 ves_icall_ModuleBuilder_getDataChunk (MonoReflectionModuleBuilder *mb, MonoArray *buf, gint32 offset)
929 MonoDynamicImage *image = mb->dynamic_image;
930 char *p = mono_array_addr (buf, char, 0);
934 mono_image_create_pefile (mb);
936 if (offset >= image->pefile.index)
938 count = mono_array_length (buf);
939 count = MIN (count, image->pefile.index - offset);
941 memcpy (p, image->pefile.data + offset, count);
947 ves_icall_ModuleBuilder_build_metadata (MonoReflectionModuleBuilder *mb)
951 mono_image_build_metadata (mb);
954 static MonoReflectionType *
955 type_from_name (const char *str, MonoBoolean ignoreCase)
957 MonoType *type = NULL;
958 MonoAssembly *assembly;
959 MonoTypeNameParse info;
960 char *temp_str = g_strdup (str);
961 gboolean type_resolve = FALSE;
965 /* mono_reflection_parse_type() mangles the string */
966 if (!mono_reflection_parse_type (temp_str, &info)) {
967 g_list_free (info.modifiers);
968 g_list_free (info.nested);
973 if (info.assembly.name) {
974 assembly = mono_assembly_load (&info.assembly, NULL, NULL);
976 MonoReflectionAssembly *refass;
978 refass = ves_icall_System_Reflection_Assembly_GetCallingAssembly ();
979 assembly = refass->assembly;
983 type = mono_reflection_get_type (assembly->image, &info, ignoreCase, &type_resolve);
985 if (!info.assembly.name && !type) /* try mscorlib */
986 type = mono_reflection_get_type (NULL, &info, ignoreCase, &type_resolve);
988 g_list_free (info.modifiers);
989 g_list_free (info.nested);
995 return mono_type_get_object (mono_domain_get (), type);
1000 mono_type_get (const char *str)
1002 char *copy = g_strdup (str);
1003 MonoReflectionType *type = type_from_name (copy, FALSE);
1010 static MonoReflectionType*
1011 ves_icall_type_from_name (MonoString *name,
1012 MonoBoolean throwOnError,
1013 MonoBoolean ignoreCase)
1015 char *str = mono_string_to_utf8 (name);
1016 MonoReflectionType *type;
1018 type = type_from_name (str, ignoreCase);
1022 mono_raise_exception (mono_get_exception_type_load (name));
1029 static MonoReflectionType*
1030 ves_icall_type_from_handle (MonoType *handle)
1032 MonoDomain *domain = mono_domain_get ();
1033 MonoClass *klass = mono_class_from_mono_type (handle);
1035 MONO_ARCH_SAVE_REGS;
1037 mono_class_init (klass);
1038 return mono_type_get_object (domain, handle);
1042 ves_icall_type_Equals (MonoReflectionType *type, MonoReflectionType *c)
1044 MONO_ARCH_SAVE_REGS;
1046 if (type->type && c->type)
1047 return mono_metadata_type_equal (type->type, c->type);
1048 g_print ("type equals\n");
1052 /* System.TypeCode */
1071 TYPECODE_STRING = 18
1075 ves_icall_type_GetTypeCode (MonoReflectionType *type)
1077 int t = type->type->type;
1079 MONO_ARCH_SAVE_REGS;
1083 case MONO_TYPE_VOID:
1084 return TYPECODE_OBJECT;
1085 case MONO_TYPE_BOOLEAN:
1086 return TYPECODE_BOOLEAN;
1088 return TYPECODE_BYTE;
1090 return TYPECODE_SBYTE;
1092 return TYPECODE_UINT16;
1094 return TYPECODE_INT16;
1095 case MONO_TYPE_CHAR:
1096 return TYPECODE_CHAR;
1100 return TYPECODE_OBJECT;
1102 return TYPECODE_UINT32;
1104 return TYPECODE_INT32;
1106 return TYPECODE_UINT64;
1108 return TYPECODE_INT64;
1110 return TYPECODE_SINGLE;
1112 return TYPECODE_DOUBLE;
1113 case MONO_TYPE_VALUETYPE:
1114 if (type->type->data.klass->enumtype) {
1115 t = type->type->data.klass->enum_basetype->type;
1118 MonoClass *k = type->type->data.klass;
1119 if (strcmp (k->name_space, "System") == 0) {
1120 if (strcmp (k->name, "Decimal") == 0)
1121 return TYPECODE_DECIMAL;
1122 else if (strcmp (k->name, "DateTime") == 0)
1123 return TYPECODE_DATETIME;
1126 return TYPECODE_OBJECT;
1127 case MONO_TYPE_STRING:
1128 return TYPECODE_STRING;
1129 case MONO_TYPE_SZARRAY:
1130 case MONO_TYPE_ARRAY:
1131 case MONO_TYPE_OBJECT:
1133 case MONO_TYPE_MVAR:
1134 return TYPECODE_OBJECT;
1135 case MONO_TYPE_CLASS:
1137 MonoClass *k = type->type->data.klass;
1138 if (strcmp (k->name_space, "System") == 0) {
1139 if (strcmp (k->name, "DBNull") == 0)
1140 return TYPECODE_DBNULL;
1143 return TYPECODE_OBJECT;
1144 case MONO_TYPE_GENERICINST:
1145 return TYPECODE_OBJECT;
1147 g_error ("type 0x%02x not handled in GetTypeCode()", t);
1153 ves_icall_type_is_subtype_of (MonoReflectionType *type, MonoReflectionType *c, MonoBoolean check_interfaces)
1159 MONO_ARCH_SAVE_REGS;
1161 g_assert (type != NULL);
1163 domain = ((MonoObject *)type)->vtable->domain;
1165 if (!c) /* FIXME: dont know what do do here */
1168 klass = mono_class_from_mono_type (type->type);
1169 klassc = mono_class_from_mono_type (c->type);
1171 return mono_class_is_subclass_of (klass, klassc, check_interfaces);
1175 ves_icall_type_is_assignable_from (MonoReflectionType *type, MonoReflectionType *c)
1181 MONO_ARCH_SAVE_REGS;
1183 g_assert (type != NULL);
1185 domain = ((MonoObject *)type)->vtable->domain;
1187 klass = mono_class_from_mono_type (type->type);
1188 klassc = mono_class_from_mono_type (c->type);
1190 return mono_class_is_assignable_from (klass, klassc);
1194 ves_icall_type_IsInstanceOfType (MonoReflectionType *type, MonoObject *obj)
1196 MonoClass *klass = mono_class_from_mono_type (type->type);
1197 return mono_object_isinst (obj, klass) != NULL;
1201 ves_icall_get_attributes (MonoReflectionType *type)
1203 MonoClass *klass = mono_class_from_mono_type (type->type);
1205 MONO_ARCH_SAVE_REGS;
1207 return klass->flags;
1210 static MonoReflectionField*
1211 ves_icall_System_Reflection_FieldInfo_internal_from_handle (MonoClassField *handle)
1213 MONO_ARCH_SAVE_REGS;
1217 return mono_field_get_object (mono_domain_get (), handle->parent, handle);
1221 ves_icall_get_method_info (MonoMethod *method, MonoMethodInfo *info)
1223 MonoDomain *domain = mono_domain_get ();
1225 MONO_ARCH_SAVE_REGS;
1227 info->parent = mono_type_get_object (domain, &method->klass->byval_arg);
1228 info->ret = mono_type_get_object (domain, method->signature->ret);
1229 info->attrs = method->flags;
1230 info->implattrs = method->iflags;
1231 if (method->signature->call_convention == MONO_CALL_DEFAULT)
1234 if (method->signature->call_convention == MONO_CALL_VARARG)
1239 info->callconv |= (method->signature->hasthis << 5) | (method->signature->explicit_this << 6);
1243 ves_icall_get_parameter_info (MonoMethod *method)
1245 MonoDomain *domain = mono_domain_get ();
1247 MONO_ARCH_SAVE_REGS;
1249 return mono_param_get_objects (domain, method);
1252 static MonoReflectionType*
1253 ves_icall_MonoField_GetParentType (MonoReflectionField *field, MonoBoolean declaring)
1256 MONO_ARCH_SAVE_REGS;
1258 parent = declaring? field->field->parent: field->klass;
1260 return mono_type_get_object (mono_object_domain (field), &parent->byval_arg);
1264 ves_icall_MonoField_GetValueInternal (MonoReflectionField *field, MonoObject *obj)
1267 MonoClassField *cf = field->field;
1270 MonoDomain *domain = mono_object_domain (field);
1272 gboolean is_static = FALSE;
1273 gboolean is_ref = FALSE;
1275 MONO_ARCH_SAVE_REGS;
1277 mono_class_init (field->klass);
1279 switch (cf->type->type) {
1280 case MONO_TYPE_STRING:
1281 case MONO_TYPE_OBJECT:
1282 case MONO_TYPE_CLASS:
1283 case MONO_TYPE_ARRAY:
1284 case MONO_TYPE_SZARRAY:
1289 case MONO_TYPE_BOOLEAN:
1292 case MONO_TYPE_CHAR:
1301 case MONO_TYPE_VALUETYPE:
1302 is_ref = cf->type->byref;
1305 g_error ("type 0x%x not handled in "
1306 "ves_icall_Monofield_GetValue", cf->type->type);
1311 if (cf->type->attrs & FIELD_ATTRIBUTE_STATIC) {
1313 vtable = mono_class_vtable (domain, field->klass);
1314 if (!vtable->initialized && !(cf->type->attrs & FIELD_ATTRIBUTE_LITERAL))
1315 mono_runtime_class_init (vtable);
1320 mono_field_static_get_value (vtable, cf, &o);
1322 mono_field_get_value (obj, cf, &o);
1327 /* boxed value type */
1328 klass = mono_class_from_mono_type (cf->type);
1329 o = mono_object_new (domain, klass);
1330 v = ((gchar *) o) + sizeof (MonoObject);
1332 mono_field_static_get_value (vtable, cf, v);
1334 mono_field_get_value (obj, cf, v);
1341 ves_icall_FieldInfo_SetValueInternal (MonoReflectionField *field, MonoObject *obj, MonoObject *value)
1343 MonoClassField *cf = field->field;
1346 MONO_ARCH_SAVE_REGS;
1348 v = (gchar *) value;
1349 if (!cf->type->byref) {
1350 switch (cf->type->type) {
1353 case MONO_TYPE_BOOLEAN:
1356 case MONO_TYPE_CHAR:
1365 case MONO_TYPE_VALUETYPE:
1366 v += sizeof (MonoObject);
1368 case MONO_TYPE_STRING:
1369 case MONO_TYPE_OBJECT:
1370 case MONO_TYPE_CLASS:
1371 case MONO_TYPE_ARRAY:
1372 case MONO_TYPE_SZARRAY:
1376 g_error ("type 0x%x not handled in "
1377 "ves_icall_FieldInfo_SetValueInternal", cf->type->type);
1382 if (cf->type->attrs & FIELD_ATTRIBUTE_STATIC) {
1383 MonoVTable *vtable = mono_class_vtable (mono_object_domain (field), field->klass);
1384 if (!vtable->initialized)
1385 mono_runtime_class_init (vtable);
1386 mono_field_static_set_value (vtable, cf, v);
1388 mono_field_set_value (obj, cf, v);
1392 static MonoReflectionField*
1393 ves_icall_MonoField_Mono_GetGenericFieldDefinition (MonoReflectionField *field)
1395 MONO_ARCH_SAVE_REGS;
1397 if (field->field->generic_info && field->field->generic_info->reflection_info)
1398 return field->field->generic_info->reflection_info;
1403 /* From MonoProperty.cs */
1405 PInfo_Attributes = 1,
1406 PInfo_GetMethod = 1 << 1,
1407 PInfo_SetMethod = 1 << 2,
1408 PInfo_ReflectedType = 1 << 3,
1409 PInfo_DeclaringType = 1 << 4,
1414 ves_icall_get_property_info (MonoReflectionProperty *property, MonoPropertyInfo *info, PInfo req_info)
1416 MonoDomain *domain = mono_object_domain (property);
1418 MONO_ARCH_SAVE_REGS;
1420 if ((req_info & PInfo_ReflectedType) != 0)
1421 info->parent = mono_type_get_object (domain, &property->klass->byval_arg);
1422 else if ((req_info & PInfo_DeclaringType) != 0)
1423 info->parent = mono_type_get_object (domain, &property->property->parent->byval_arg);
1425 if ((req_info & PInfo_Name) != 0)
1426 info->name = mono_string_new (domain, property->property->name);
1428 if ((req_info & PInfo_Attributes) != 0)
1429 info->attrs = property->property->attrs;
1431 if ((req_info & PInfo_GetMethod) != 0)
1432 info->get = property->property->get ?
1433 mono_method_get_object (domain, property->property->get, NULL): NULL;
1435 if ((req_info & PInfo_SetMethod) != 0)
1436 info->set = property->property->set ?
1437 mono_method_get_object (domain, property->property->set, NULL): NULL;
1439 * There may be other methods defined for properties, though, it seems they are not exposed
1440 * in the reflection API
1445 ves_icall_get_event_info (MonoReflectionEvent *event, MonoEventInfo *info)
1447 MonoDomain *domain = mono_object_domain (event);
1449 MONO_ARCH_SAVE_REGS;
1451 info->declaring_type = mono_type_get_object (domain, &event->klass->byval_arg);
1452 info->reflected_type = mono_type_get_object (domain, &event->event->parent->byval_arg);
1454 info->name = mono_string_new (domain, event->event->name);
1455 info->attrs = event->event->attrs;
1456 info->add_method = event->event->add ? mono_method_get_object (domain, event->event->add, NULL): NULL;
1457 info->remove_method = event->event->remove ? mono_method_get_object (domain, event->event->remove, NULL): NULL;
1458 info->raise_method = event->event->raise ? mono_method_get_object (domain, event->event->raise, NULL): NULL;
1462 ves_icall_Type_GetInterfaces (MonoReflectionType* type)
1464 MonoDomain *domain = mono_object_domain (type);
1467 MonoClass *class = mono_class_from_mono_type (type->type);
1469 MonoBitSet *slots = mono_bitset_new (class->max_interface_id + 1, 0);
1471 MONO_ARCH_SAVE_REGS;
1474 /* GetInterfaces() returns an empty array in MS.NET (this may be a bug) */
1475 mono_bitset_free (slots);
1476 return mono_array_new (domain, mono_defaults.monotype_class, 0);
1480 for (parent = class; parent; parent = parent->parent) {
1481 for (i = 0; i < parent->interface_count; ++i) {
1482 if (mono_bitset_test (slots, parent->interfaces [i]->interface_id))
1485 mono_bitset_set (slots, parent->interfaces [i]->interface_id);
1490 intf = mono_array_new (domain, mono_defaults.monotype_class, ninterf);
1492 for (parent = class; parent; parent = parent->parent) {
1493 for (i = 0; i < parent->interface_count; ++i) {
1494 if (!mono_bitset_test (slots, parent->interfaces [i]->interface_id))
1497 mono_bitset_clear (slots, parent->interfaces [i]->interface_id);
1498 mono_array_set (intf, gpointer, ninterf,
1499 mono_type_get_object (domain, &parent->interfaces [i]->byval_arg));
1504 mono_bitset_free (slots);
1509 ves_icall_Type_GetInterfaceMapData (MonoReflectionType *type, MonoReflectionType *iface, MonoArray **targets, MonoArray **methods)
1511 MonoClass *class = mono_class_from_mono_type (type->type);
1512 MonoClass *iclass = mono_class_from_mono_type (iface->type);
1513 MonoReflectionMethod *member;
1514 int i, len, ioffset;
1517 MONO_ARCH_SAVE_REGS;
1519 /* type doesn't implement iface: the exception is thrown in managed code */
1520 if ((iclass->interface_id > class->max_interface_id) || !class->interface_offsets [iclass->interface_id])
1523 len = iclass->method.count;
1524 ioffset = class->interface_offsets [iclass->interface_id];
1525 domain = mono_object_domain (type);
1526 *targets = mono_array_new (domain, mono_defaults.method_info_class, len);
1527 *methods = mono_array_new (domain, mono_defaults.method_info_class, len);
1528 for (i = 0; i < len; ++i) {
1529 member = mono_method_get_object (domain, iclass->methods [i], iclass);
1530 mono_array_set (*methods, gpointer, i, member);
1531 member = mono_method_get_object (domain, class->vtable [i + ioffset], class);
1532 mono_array_set (*targets, gpointer, i, member);
1536 static MonoReflectionType*
1537 ves_icall_MonoType_GetElementType (MonoReflectionType *type)
1539 MonoClass *class = mono_class_from_mono_type (type->type);
1541 MONO_ARCH_SAVE_REGS;
1543 if (type->type->byref)
1544 return mono_type_get_object (mono_object_domain (type), &class->byval_arg);
1545 if (class->enumtype && class->enum_basetype) /* types that are modifierd typebuilkders may not have enum_basetype set */
1546 return mono_type_get_object (mono_object_domain (type), class->enum_basetype);
1547 else if (class->element_class)
1548 return mono_type_get_object (mono_object_domain (type), &class->element_class->byval_arg);
1553 static MonoReflectionType*
1554 ves_icall_get_type_parent (MonoReflectionType *type)
1556 MonoClass *class = mono_class_from_mono_type (type->type);
1558 MONO_ARCH_SAVE_REGS;
1560 return class->parent ? mono_type_get_object (mono_object_domain (type), &class->parent->byval_arg): NULL;
1564 ves_icall_type_ispointer (MonoReflectionType *type)
1566 MONO_ARCH_SAVE_REGS;
1568 return type->type->type == MONO_TYPE_PTR;
1572 ves_icall_type_isprimitive (MonoReflectionType *type)
1574 MONO_ARCH_SAVE_REGS;
1576 return (!type->type->byref && (type->type->type >= MONO_TYPE_BOOLEAN) && (type->type->type <= MONO_TYPE_R8));
1580 ves_icall_type_isbyref (MonoReflectionType *type)
1582 MONO_ARCH_SAVE_REGS;
1584 return type->type->byref;
1587 static MonoReflectionModule*
1588 ves_icall_MonoType_get_Module (MonoReflectionType *type)
1590 MonoClass *class = mono_class_from_mono_type (type->type);
1592 MONO_ARCH_SAVE_REGS;
1594 return mono_module_get_object (mono_object_domain (type), class->image);
1597 static MonoReflectionAssembly*
1598 ves_icall_MonoType_get_Assembly (MonoReflectionType *type)
1600 MonoDomain *domain = mono_domain_get ();
1601 MonoClass *class = mono_class_from_mono_type (type->type);
1603 MONO_ARCH_SAVE_REGS;
1605 return mono_assembly_get_object (domain, class->image->assembly);
1608 static MonoReflectionType*
1609 ves_icall_MonoType_get_DeclaringType (MonoReflectionType *type)
1611 MonoDomain *domain = mono_domain_get ();
1612 MonoClass *class = mono_class_from_mono_type (type->type);
1614 MONO_ARCH_SAVE_REGS;
1616 return class->nested_in ? mono_type_get_object (domain, &class->nested_in->byval_arg) : NULL;
1619 static MonoReflectionType*
1620 ves_icall_MonoType_get_UnderlyingSystemType (MonoReflectionType *type)
1622 MonoDomain *domain = mono_domain_get ();
1623 MonoClass *class = mono_class_from_mono_type (type->type);
1625 MONO_ARCH_SAVE_REGS;
1627 if (class->enumtype && class->enum_basetype) /* types that are modified typebuilders may not have enum_basetype set */
1628 return mono_type_get_object (domain, class->enum_basetype);
1629 else if (class->element_class)
1630 return mono_type_get_object (domain, &class->element_class->byval_arg);
1636 ves_icall_MonoType_get_Name (MonoReflectionType *type)
1638 MonoDomain *domain = mono_domain_get ();
1639 MonoClass *class = mono_class_from_mono_type (type->type);
1641 MONO_ARCH_SAVE_REGS;
1643 return mono_string_new (domain, class->name);
1647 ves_icall_MonoType_get_Namespace (MonoReflectionType *type)
1649 MonoDomain *domain = mono_domain_get ();
1650 MonoClass *class = mono_class_from_mono_type (type->type);
1652 MONO_ARCH_SAVE_REGS;
1654 while (class->nested_in)
1655 class = class->nested_in;
1657 return mono_string_new (domain, class->name_space);
1661 ves_icall_MonoType_GetArrayRank (MonoReflectionType *type)
1663 MonoClass *class = mono_class_from_mono_type (type->type);
1665 MONO_ARCH_SAVE_REGS;
1671 ves_icall_MonoType_GetGenericArguments (MonoReflectionType *type)
1674 MonoClass *klass, *pklass;
1676 MONO_ARCH_SAVE_REGS;
1678 klass = mono_class_from_mono_type (type->type);
1680 if (type->type->byref) {
1681 res = mono_array_new (mono_object_domain (type), mono_defaults.monotype_class, 0);
1682 } else if (klass->gen_params) {
1683 res = mono_array_new (mono_object_domain (type), mono_defaults.monotype_class, klass->num_gen_params);
1684 for (i = 0; i < klass->num_gen_params; ++i) {
1685 pklass = mono_class_from_generic_parameter (&klass->gen_params [i], klass->image, FALSE);
1686 mono_array_set (res, gpointer, i, mono_type_get_object (mono_object_domain (type), &pklass->byval_arg));
1688 } else if (klass->generic_inst) {
1689 MonoGenericInst *inst = klass->generic_inst;
1690 res = mono_array_new (mono_object_domain (type), mono_defaults.monotype_class, inst->type_argc);
1691 for (i = 0; i < inst->type_argc; ++i) {
1692 mono_array_set (res, gpointer, i, mono_type_get_object (mono_object_domain (type), inst->type_argv [i]));
1695 res = mono_array_new (mono_object_domain (type), mono_defaults.monotype_class, 0);
1701 ves_icall_Type_get_IsGenericTypeDefinition (MonoReflectionType *type)
1704 MONO_ARCH_SAVE_REGS;
1706 if (type->type->byref)
1708 klass = mono_class_from_mono_type (type->type);
1710 return klass->gen_params != NULL;
1713 static MonoReflectionType*
1714 ves_icall_Type_GetGenericTypeDefinition_impl (MonoReflectionType *type)
1717 MONO_ARCH_SAVE_REGS;
1719 if (type->type->byref)
1721 klass = mono_class_from_mono_type (type->type);
1722 if (klass->gen_params) {
1723 return type; /* check this one */
1725 if (klass->generic_inst) {
1726 MonoType *generic_type = klass->generic_inst->generic_type;
1727 MonoClass *generic_class = mono_class_from_mono_type (generic_type);
1729 if (generic_class->wastypebuilder && generic_class->reflection_info)
1730 return generic_class->reflection_info;
1732 return mono_type_get_object (mono_object_domain (type), generic_type);
1737 static MonoReflectionType*
1738 ves_icall_Type_BindGenericParameters (MonoReflectionType *type, MonoArray *type_array)
1740 MonoType *geninst, **types;
1743 MONO_ARCH_SAVE_REGS;
1745 if (type->type->byref)
1748 count = mono_array_length (type_array);
1749 types = g_new0 (MonoType *, count);
1751 for (i = 0; i < count; i++) {
1752 MonoReflectionType *t = mono_array_get (type_array, gpointer, i);
1753 types [i] = t->type;
1756 geninst = mono_reflection_bind_generic_parameters (type, count, types);
1758 return mono_type_get_object (mono_object_domain (type), geninst);
1762 ves_icall_Type_get_IsGenericInstance (MonoReflectionType *type)
1765 MONO_ARCH_SAVE_REGS;
1767 if (type->type->byref)
1769 klass = mono_class_from_mono_type (type->type);
1770 return klass->generic_inst != NULL;
1774 ves_icall_Type_GetGenericParameterPosition (MonoReflectionType *type)
1776 MONO_ARCH_SAVE_REGS;
1778 if (type->type->byref)
1780 if (type->type->type == MONO_TYPE_VAR || type->type->type == MONO_TYPE_MVAR)
1781 return type->type->data.generic_param->num;
1786 ves_icall_MonoType_get_HasGenericArguments (MonoReflectionType *type)
1789 MONO_ARCH_SAVE_REGS;
1791 if (type->type->byref)
1793 klass = mono_class_from_mono_type (type->type);
1794 if (klass->gen_params || klass->generic_inst)
1800 ves_icall_MonoType_get_IsGenericParameter (MonoReflectionType *type)
1802 MONO_ARCH_SAVE_REGS;
1804 if (type->type->byref)
1806 if (type->type->type == MONO_TYPE_VAR || type->type->type == MONO_TYPE_MVAR)
1812 ves_icall_TypeBuilder_get_IsGenericParameter (MonoReflectionTypeBuilder *tb)
1814 MONO_ARCH_SAVE_REGS;
1816 if (tb->type.type->byref)
1818 if (tb->type.type->type == MONO_TYPE_VAR || tb->type.type->type == MONO_TYPE_MVAR)
1824 ves_icall_EnumBuilder_setup_enum_type (MonoReflectionType *enumtype,
1825 MonoReflectionType *t)
1827 enumtype->type = t->type;
1830 static MonoReflectionType*
1831 ves_icall_MonoGenericInst_GetParentType (MonoReflectionGenericInst *type)
1833 MonoGenericInst *ginst;
1836 MONO_ARCH_SAVE_REGS;
1838 ginst = type->type.type->data.generic_inst;
1839 if (!ginst || !ginst->parent || (ginst->parent->type != MONO_TYPE_GENERICINST))
1842 klass = mono_class_from_mono_type (ginst->parent);
1843 if (!klass->generic_inst && !klass->gen_params)
1846 return mono_type_get_object (mono_object_domain (type), ginst->parent);
1850 ves_icall_MonoGenericInst_GetInterfaces (MonoReflectionGenericInst *type)
1852 static MonoClass *System_Reflection_MonoGenericInst;
1853 MonoGenericInst *ginst;
1859 MONO_ARCH_SAVE_REGS;
1861 if (!System_Reflection_MonoGenericInst) {
1862 System_Reflection_MonoGenericInst = mono_class_from_name (
1863 mono_defaults.corlib, "System.Reflection", "MonoGenericInst");
1864 g_assert (System_Reflection_MonoGenericInst);
1867 domain = mono_object_domain (type);
1869 ginst = type->type.type->data.generic_inst;
1870 if (!ginst || !ginst->ifaces)
1871 return mono_array_new (domain, System_Reflection_MonoGenericInst, 0);
1873 klass = mono_class_from_mono_type (ginst->generic_type);
1875 res = mono_array_new (domain, System_Reflection_MonoGenericInst, ginst->count_ifaces);
1877 for (i = 0; i < ginst->count_ifaces; i++) {
1878 MonoReflectionType *iface = mono_type_get_object (domain, ginst->ifaces [i]);
1880 mono_array_set (res, gpointer, i, iface);
1887 ves_icall_MonoGenericInst_GetMethods (MonoReflectionGenericInst *type,
1888 MonoReflectionType *reflected_type)
1890 MonoGenericInst *ginst;
1891 MonoDynamicGenericInst *dginst;
1893 MonoClass *refclass;
1897 MONO_ARCH_SAVE_REGS;
1899 ginst = type->type.type->data.generic_inst;
1900 g_assert ((dginst = ginst->dynamic_info) != NULL);
1902 refclass = mono_class_from_mono_type (reflected_type->type);
1904 domain = mono_object_domain (type);
1905 res = mono_array_new (domain, mono_defaults.method_info_class, dginst->count_methods);
1907 for (i = 0; i < dginst->count_methods; i++)
1908 mono_array_set (res, gpointer, i,
1909 mono_method_get_object (domain, dginst->methods [i], refclass));
1915 ves_icall_MonoGenericInst_GetConstructors (MonoReflectionGenericInst *type,
1916 MonoReflectionType *reflected_type)
1918 static MonoClass *System_Reflection_ConstructorInfo;
1919 MonoGenericInst *ginst;
1920 MonoDynamicGenericInst *dginst;
1922 MonoClass *refclass;
1926 MONO_ARCH_SAVE_REGS;
1928 if (!System_Reflection_ConstructorInfo)
1929 System_Reflection_ConstructorInfo = mono_class_from_name (
1930 mono_defaults.corlib, "System.Reflection", "ConstructorInfo");
1932 ginst = type->type.type->data.generic_inst;
1933 g_assert ((dginst = ginst->dynamic_info) != NULL);
1935 refclass = mono_class_from_mono_type (reflected_type->type);
1937 domain = mono_object_domain (type);
1938 res = mono_array_new (domain, System_Reflection_ConstructorInfo, dginst->count_ctors);
1940 for (i = 0; i < dginst->count_ctors; i++)
1941 mono_array_set (res, gpointer, i,
1942 mono_method_get_object (domain, dginst->ctors [i], refclass));
1948 ves_icall_MonoGenericInst_GetFields (MonoReflectionGenericInst *type,
1949 MonoReflectionType *reflected_type)
1951 MonoGenericInst *ginst;
1952 MonoDynamicGenericInst *dginst;
1954 MonoClass *refclass;
1958 MONO_ARCH_SAVE_REGS;
1960 ginst = type->type.type->data.generic_inst;
1961 g_assert ((dginst = ginst->dynamic_info) != NULL);
1963 refclass = mono_class_from_mono_type (reflected_type->type);
1965 domain = mono_object_domain (type);
1966 res = mono_array_new (domain, mono_defaults.field_info_class, dginst->count_fields);
1968 for (i = 0; i < dginst->count_fields; i++)
1969 mono_array_set (res, gpointer, i,
1970 mono_field_get_object (domain, refclass, &dginst->fields [i]));
1976 ves_icall_MonoGenericInst_GetProperties (MonoReflectionGenericInst *type,
1977 MonoReflectionType *reflected_type)
1979 static MonoClass *System_Reflection_PropertyInfo;
1980 MonoGenericInst *ginst;
1981 MonoDynamicGenericInst *dginst;
1983 MonoClass *refclass;
1987 MONO_ARCH_SAVE_REGS;
1989 if (!System_Reflection_PropertyInfo)
1990 System_Reflection_PropertyInfo = mono_class_from_name (
1991 mono_defaults.corlib, "System.Reflection", "PropertyInfo");
1993 ginst = type->type.type->data.generic_inst;
1994 g_assert ((dginst = ginst->dynamic_info) != NULL);
1996 refclass = mono_class_from_mono_type (reflected_type->type);
1998 domain = mono_object_domain (type);
1999 res = mono_array_new (domain, System_Reflection_PropertyInfo, dginst->count_properties);
2001 for (i = 0; i < dginst->count_properties; i++)
2002 mono_array_set (res, gpointer, i,
2003 mono_property_get_object (domain, refclass, &dginst->properties [i]));
2009 ves_icall_MonoGenericInst_GetEvents (MonoReflectionGenericInst *type,
2010 MonoReflectionType *reflected_type)
2012 static MonoClass *System_Reflection_EventInfo;
2013 MonoGenericInst *ginst;
2014 MonoDynamicGenericInst *dginst;
2016 MonoClass *refclass;
2020 MONO_ARCH_SAVE_REGS;
2022 if (!System_Reflection_EventInfo)
2023 System_Reflection_EventInfo = mono_class_from_name (
2024 mono_defaults.corlib, "System.Reflection", "EventInfo");
2026 ginst = type->type.type->data.generic_inst;
2027 g_assert ((dginst = ginst->dynamic_info) != NULL);
2029 refclass = mono_class_from_mono_type (reflected_type->type);
2031 domain = mono_object_domain (type);
2032 res = mono_array_new (domain, System_Reflection_EventInfo, dginst->count_events);
2034 for (i = 0; i < dginst->count_events; i++)
2035 mono_array_set (res, gpointer, i,
2036 mono_event_get_object (domain, refclass, &dginst->events [i]));
2041 static MonoReflectionMethod *
2042 ves_icall_MonoType_get_DeclaringMethod (MonoReflectionType *type)
2047 MONO_ARCH_SAVE_REGS;
2049 if (type->type->byref)
2052 method = type->type->data.generic_param->method;
2056 klass = mono_class_from_mono_type (type->type);
2057 return mono_method_get_object (mono_object_domain (type), method, klass);
2060 static MonoReflectionMethod *
2061 ves_icall_MonoMethod_GetGenericMethodDefinition (MonoReflectionMethod *method)
2063 MonoMethodInflated *imethod;
2065 MONO_ARCH_SAVE_REGS;
2067 if (!method->method->signature->is_inflated) {
2068 if (method->method->signature->generic_param_count)
2074 imethod = (MonoMethodInflated *) method->method;
2075 if (imethod->context->gmethod && imethod->context->gmethod->reflection_info)
2076 return imethod->context->gmethod->reflection_info;
2078 return mono_method_get_object (
2079 mono_object_domain (method), imethod->declaring, NULL);
2083 ves_icall_MonoMethod_get_HasGenericParameters (MonoReflectionMethod *method)
2085 MONO_ARCH_SAVE_REGS;
2087 if ((method->method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) ||
2088 (method->method->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL))
2091 return method->method->signature->generic_param_count != 0;
2095 ves_icall_MonoMethod_get_Mono_IsInflatedMethod (MonoReflectionMethod *method)
2097 MONO_ARCH_SAVE_REGS;
2099 if ((method->method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) ||
2100 (method->method->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL))
2103 return method->method->signature->is_inflated;
2107 ves_icall_MonoMethod_get_IsGenericMethodDefinition (MonoReflectionMethod *method)
2109 MONO_ARCH_SAVE_REGS;
2111 if ((method->method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) ||
2112 (method->method->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL))
2115 return method->method->signature->generic_param_count != 0;
2119 ves_icall_MonoMethod_GetGenericArguments (MonoReflectionMethod *method)
2123 MonoMethodNormal *mn;
2125 MONO_ARCH_SAVE_REGS;
2127 domain = mono_object_domain (method);
2129 if ((method->method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) ||
2130 (method->method->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL))
2131 return mono_array_new (domain, mono_defaults.monotype_class, 0);
2133 if (method->method->signature->is_inflated) {
2134 MonoMethodInflated *imethod = (MonoMethodInflated *) method->method;
2135 MonoGenericMethod *gmethod = imethod->context->gmethod;
2138 count = gmethod->mtype_argc;
2139 res = mono_array_new (domain, mono_defaults.monotype_class, count);
2141 for (i = 0; i < count; i++) {
2142 MonoType *t = gmethod->mtype_argv [i];
2144 res, gpointer, i, mono_type_get_object (domain, t));
2151 mn = (MonoMethodNormal *) method->method;
2152 count = method->method->signature->generic_param_count;
2153 res = mono_array_new (domain, mono_defaults.monotype_class, count);
2155 for (i = 0; i < count; i++) {
2156 MonoGenericParam *param = &mn->gen_params [i];
2157 MonoClass *pklass = mono_class_from_generic_parameter (
2158 param, method->method->klass->image, TRUE);
2159 mono_array_set (res, gpointer, i,
2160 mono_type_get_object (domain, &pklass->byval_arg));
2167 ves_icall_InternalInvoke (MonoReflectionMethod *method, MonoObject *this, MonoArray *params)
2170 * Invoke from reflection is supposed to always be a virtual call (the API
2171 * is stupid), mono_runtime_invoke_*() calls the provided method, allowing
2172 * greater flexibility.
2174 MonoMethod *m = method->method;
2178 MONO_ARCH_SAVE_REGS;
2181 if (!mono_object_isinst (this, m->klass))
2182 mono_raise_exception (mono_exception_from_name (mono_defaults.corlib, "System.Reflection", "TargetException"));
2183 m = mono_object_get_virtual_method (this, m);
2184 /* must pass the pointer to the value for valuetype methods */
2185 if (m->klass->valuetype)
2186 obj = mono_object_unbox (this);
2187 } else if (!(m->flags & METHOD_ATTRIBUTE_STATIC) && strcmp (m->name, ".ctor") && !m->wrapper_type)
2188 mono_raise_exception (mono_exception_from_name (mono_defaults.corlib, "System.Reflection", "TargetException"));
2190 pcount = params? mono_array_length (params): 0;
2191 if (pcount != m->signature->param_count)
2192 mono_raise_exception (mono_exception_from_name (mono_defaults.corlib, "System.Reflection", "TargetParameterCountException"));
2194 if (m->klass->rank && !strcmp (m->name, ".ctor")) {
2197 guint32 *lower_bounds;
2198 pcount = mono_array_length (params);
2199 lengths = alloca (sizeof (guint32) * pcount);
2200 for (i = 0; i < pcount; ++i)
2201 lengths [i] = *(gint32*) ((char*)mono_array_get (params, gpointer, i) + sizeof (MonoObject));
2203 if (m->klass->rank == pcount) {
2204 /* Only lengths provided. */
2205 lower_bounds = NULL;
2207 g_assert (pcount == (m->klass->rank * 2));
2208 /* lower bounds are first. */
2209 lower_bounds = lengths;
2210 lengths += m->klass->rank;
2213 return (MonoObject*)mono_array_new_full (mono_object_domain (params), m->klass, lengths, lower_bounds);
2215 return mono_runtime_invoke_array (m, obj, params, NULL);
2219 ves_icall_InternalExecute (MonoReflectionMethod *method, MonoObject *this, MonoArray *params, MonoArray **outArgs)
2221 MonoDomain *domain = mono_object_domain (method);
2222 MonoMethod *m = method->method;
2223 MonoMethodSignature *sig = m->signature;
2224 MonoArray *out_args;
2226 int i, j, outarg_count = 0;
2228 MONO_ARCH_SAVE_REGS;
2230 if (m->klass == mono_defaults.object_class) {
2232 if (!strcmp (m->name, "FieldGetter")) {
2233 MonoClass *k = this->vtable->klass;
2234 MonoString *name = mono_array_get (params, MonoString *, 1);
2237 str = mono_string_to_utf8 (name);
2240 for (i = 0; i < k->field.count; i++) {
2241 if (!strcmp (k->fields [i].name, str)) {
2242 MonoClass *field_klass = mono_class_from_mono_type (k->fields [i].type);
2243 if (field_klass->valuetype)
2244 result = mono_value_box (domain, field_klass,
2245 (char *)this + k->fields [i].offset);
2247 result = *((gpointer *)((char *)this + k->fields [i].offset));
2250 out_args = mono_array_new (domain, mono_defaults.object_class, 1);
2251 *outArgs = out_args;
2252 mono_array_set (out_args, gpointer, 0, result);
2262 g_assert_not_reached ();
2264 } else if (!strcmp (m->name, "FieldSetter")) {
2265 MonoClass *k = this->vtable->klass;
2266 MonoString *name = mono_array_get (params, MonoString *, 1);
2270 str = mono_string_to_utf8 (name);
2273 for (i = 0; i < k->field.count; i++) {
2274 if (!strcmp (k->fields [i].name, str)) {
2275 MonoClass *field_klass = mono_class_from_mono_type (k->fields [i].type);
2276 MonoObject *val = mono_array_get (params, gpointer, 2);
2278 if (field_klass->valuetype) {
2279 size = mono_type_size (k->fields [i].type, &align);
2280 memcpy ((char *)this + k->fields [i].offset,
2281 ((char *)val) + sizeof (MonoObject), size);
2283 *(MonoObject**)((char *)this + k->fields [i].offset) = val;
2285 out_args = mono_array_new (domain, mono_defaults.object_class, 0);
2286 *outArgs = out_args;
2297 g_assert_not_reached ();
2302 for (i = 0; i < mono_array_length (params); i++) {
2303 if (sig->params [i]->byref)
2307 out_args = mono_array_new (domain, mono_defaults.object_class, outarg_count);
2309 /* fixme: handle constructors? */
2310 if (!strcmp (method->method->name, ".ctor"))
2311 g_assert_not_reached ();
2313 /* This can be called only on MBR objects, so no need to unbox for valuetypes. */
2314 g_assert (!method->method->klass->valuetype);
2315 result = mono_runtime_invoke_array (method->method, this, params, NULL);
2317 for (i = 0, j = 0; i < mono_array_length (params); i++) {
2318 if (sig->params [i]->byref) {
2320 arg = mono_array_get (params, gpointer, i);
2321 mono_array_set (out_args, gpointer, j, arg);
2326 *outArgs = out_args;
2332 ves_icall_System_Enum_ToObject (MonoReflectionType *type, MonoObject *obj)
2335 MonoClass *enumc, *objc;
2339 MONO_ARCH_SAVE_REGS;
2341 MONO_CHECK_ARG_NULL (type);
2342 MONO_CHECK_ARG_NULL (obj);
2344 domain = mono_object_domain (type);
2345 enumc = mono_class_from_mono_type (type->type);
2346 objc = obj->vtable->klass;
2348 MONO_CHECK_ARG (obj, enumc->enumtype == TRUE);
2349 MONO_CHECK_ARG (obj, (objc->enumtype) || (objc->byval_arg.type >= MONO_TYPE_I1 &&
2350 objc->byval_arg.type <= MONO_TYPE_U8));
2352 s1 = mono_class_value_size (enumc, NULL);
2353 s2 = mono_class_value_size (objc, NULL);
2355 res = mono_object_new (domain, enumc);
2357 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
2358 memcpy ((char *)res + sizeof (MonoObject), (char *)obj + sizeof (MonoObject), MIN (s1, s2));
2360 memcpy ((char *)res + sizeof (MonoObject) + (s1 > s2 ? s1 - s2 : 0),
2361 (char *)obj + sizeof (MonoObject) + (s2 > s1 ? s2 - s1 : 0),
2368 ves_icall_System_Enum_get_value (MonoObject *this)
2376 MONO_ARCH_SAVE_REGS;
2381 g_assert (this->vtable->klass->enumtype);
2383 enumc = mono_class_from_mono_type (this->vtable->klass->enum_basetype);
2384 res = mono_object_new (mono_object_domain (this), enumc);
2385 dst = (char *)res + sizeof (MonoObject);
2386 src = (char *)this + sizeof (MonoObject);
2387 size = mono_class_value_size (enumc, NULL);
2389 memcpy (dst, src, size);
2395 ves_icall_get_enum_info (MonoReflectionType *type, MonoEnumInfo *info)
2397 MonoDomain *domain = mono_object_domain (type);
2398 MonoClass *enumc = mono_class_from_mono_type (type->type);
2399 guint i, j, nvalues, crow;
2400 MonoClassField *field;
2402 MONO_ARCH_SAVE_REGS;
2404 info->utype = mono_type_get_object (domain, enumc->enum_basetype);
2405 nvalues = enumc->field.count - 1;
2406 info->names = mono_array_new (domain, mono_defaults.string_class, nvalues);
2407 info->values = mono_array_new (domain, enumc, nvalues);
2410 for (i = 0, j = 0; i < enumc->field.count; ++i) {
2414 field = &enumc->fields [i];
2415 if (strcmp ("value__", field->name) == 0)
2417 if (mono_field_is_deleted (field))
2419 mono_array_set (info->names, gpointer, j, mono_string_new (domain, field->name));
2422 crow = mono_metadata_get_constant_index (enumc->image, MONO_TOKEN_FIELD_DEF | (i+enumc->field.first+1), crow + 1);
2423 field->def_type = mono_metadata_decode_row_col (&enumc->image->tables [MONO_TABLE_CONSTANT], crow-1, MONO_CONSTANT_TYPE);
2424 crow = mono_metadata_decode_row_col (&enumc->image->tables [MONO_TABLE_CONSTANT], crow-1, MONO_CONSTANT_VALUE);
2425 field->data = (gpointer)mono_metadata_blob_heap (enumc->image, crow);
2429 len = mono_metadata_decode_blob_size (p, &p);
2430 switch (enumc->enum_basetype->type) {
2433 mono_array_set (info->values, gchar, j, *p);
2435 case MONO_TYPE_CHAR:
2438 mono_array_set (info->values, gint16, j, read16 (p));
2442 mono_array_set (info->values, gint32, j, read32 (p));
2446 mono_array_set (info->values, gint64, j, read64 (p));
2449 g_error ("Implement type 0x%02x in get_enum_info", enumc->enum_basetype->type);
2456 BFLAGS_IgnoreCase = 1,
2457 BFLAGS_DeclaredOnly = 2,
2458 BFLAGS_Instance = 4,
2460 BFLAGS_Public = 0x10,
2461 BFLAGS_NonPublic = 0x20,
2462 BFLAGS_FlattenHierarchy = 0x40,
2463 BFLAGS_InvokeMethod = 0x100,
2464 BFLAGS_CreateInstance = 0x200,
2465 BFLAGS_GetField = 0x400,
2466 BFLAGS_SetField = 0x800,
2467 BFLAGS_GetProperty = 0x1000,
2468 BFLAGS_SetProperty = 0x2000,
2469 BFLAGS_ExactBinding = 0x10000,
2470 BFLAGS_SuppressChangeType = 0x20000,
2471 BFLAGS_OptionalParamBinding = 0x40000
2474 static MonoReflectionField *
2475 ves_icall_Type_GetField (MonoReflectionType *type, MonoString *name, guint32 bflags)
2478 MonoClass *startklass, *klass;
2480 MonoClassField *field;
2482 domain = ((MonoObject *)type)->vtable->domain;
2483 klass = startklass = mono_class_from_mono_type (type->type);
2485 MONO_ARCH_SAVE_REGS;
2488 mono_raise_exception (mono_get_exception_argument_null ("name"));
2491 for (i = 0; i < klass->field.count; ++i) {
2493 field = &klass->fields [i];
2494 if (mono_field_is_deleted (field))
2496 if ((field->type->attrs & FIELD_ATTRIBUTE_FIELD_ACCESS_MASK) == FIELD_ATTRIBUTE_PUBLIC) {
2497 if (bflags & BFLAGS_Public)
2500 if (bflags & BFLAGS_NonPublic)
2506 if (field->type->attrs & FIELD_ATTRIBUTE_STATIC) {
2507 if (bflags & BFLAGS_Static)
2508 if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
2511 if (bflags & BFLAGS_Instance)
2518 utf8_name = mono_string_to_utf8 (name);
2520 if (strcmp (field->name, utf8_name)) {
2526 return mono_field_get_object (domain, startklass, field);
2528 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
2535 ves_icall_Type_GetFields_internal (MonoReflectionType *type, guint32 bflags, MonoReflectionType *reftype)
2538 GSList *l = NULL, *tmp;
2539 MonoClass *startklass, *klass, *refklass;
2543 MonoClassField *field;
2545 MONO_ARCH_SAVE_REGS;
2547 domain = ((MonoObject *)type)->vtable->domain;
2548 klass = startklass = mono_class_from_mono_type (type->type);
2549 refklass = mono_class_from_mono_type (reftype->type);
2552 for (i = 0; i < klass->field.count; ++i) {
2554 field = &klass->fields [i];
2555 if (mono_field_is_deleted (field))
2557 if ((field->type->attrs & FIELD_ATTRIBUTE_FIELD_ACCESS_MASK) == FIELD_ATTRIBUTE_PUBLIC) {
2558 if (bflags & BFLAGS_Public)
2561 if (bflags & BFLAGS_NonPublic)
2567 if (field->type->attrs & FIELD_ATTRIBUTE_STATIC) {
2568 if (bflags & BFLAGS_Static)
2569 if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
2572 if (bflags & BFLAGS_Instance)
2578 member = (MonoObject*)mono_field_get_object (domain, refklass, field);
2579 l = g_slist_prepend (l, member);
2581 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
2583 len = g_slist_length (l);
2584 res = mono_array_new (domain, mono_defaults.field_info_class, len);
2586 tmp = l = g_slist_reverse (l);
2587 for (; tmp; tmp = tmp->next, ++i)
2588 mono_array_set (res, gpointer, i, tmp->data);
2594 ves_icall_Type_GetMethodsByName (MonoReflectionType *type, MonoString *name, guint32 bflags, MonoBoolean ignore_case, MonoReflectionType *reftype)
2597 GSList *l = NULL, *tmp;
2598 MonoClass *startklass, *klass, *refklass;
2603 GHashTable *method_slots = g_hash_table_new (NULL, NULL);
2604 gchar *mname = NULL;
2605 int (*compare_func) (const char *s1, const char *s2) = NULL;
2607 MONO_ARCH_SAVE_REGS;
2609 domain = ((MonoObject *)type)->vtable->domain;
2610 klass = startklass = mono_class_from_mono_type (type->type);
2611 refklass = mono_class_from_mono_type (reftype->type);
2614 mname = mono_string_to_utf8 (name);
2615 compare_func = (ignore_case) ? g_strcasecmp : strcmp;
2619 for (i = 0; i < klass->method.count; ++i) {
2621 method = klass->methods [i];
2622 if (strcmp (method->name, ".ctor") == 0 || strcmp (method->name, ".cctor") == 0)
2624 if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
2625 if (bflags & BFLAGS_Public)
2628 if (bflags & BFLAGS_NonPublic)
2634 if (method->flags & METHOD_ATTRIBUTE_STATIC) {
2635 if (bflags & BFLAGS_Static)
2636 if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
2639 if (bflags & BFLAGS_Instance)
2647 if (compare_func (mname, method->name))
2652 if (method->slot != -1) {
2653 if (g_hash_table_lookup (method_slots, GUINT_TO_POINTER (method->slot)))
2655 g_hash_table_insert (method_slots, GUINT_TO_POINTER (method->slot), method);
2658 member = (MonoObject*)mono_method_get_object (domain, method, refklass);
2660 l = g_slist_prepend (l, member);
2663 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
2667 res = mono_array_new (domain, mono_defaults.method_info_class, len);
2670 tmp = l = g_slist_reverse (l);
2672 for (; tmp; tmp = tmp->next, ++i)
2673 mono_array_set (res, gpointer, i, tmp->data);
2675 g_hash_table_destroy (method_slots);
2680 ves_icall_Type_GetConstructors_internal (MonoReflectionType *type, guint32 bflags, MonoReflectionType *reftype)
2683 GSList *l = NULL, *tmp;
2684 static MonoClass *System_Reflection_ConstructorInfo;
2685 MonoClass *startklass, *klass, *refklass;
2691 MONO_ARCH_SAVE_REGS;
2693 domain = ((MonoObject *)type)->vtable->domain;
2694 klass = startklass = mono_class_from_mono_type (type->type);
2695 refklass = mono_class_from_mono_type (reftype->type);
2697 for (i = 0; i < klass->method.count; ++i) {
2699 method = klass->methods [i];
2700 if (strcmp (method->name, ".ctor") && strcmp (method->name, ".cctor"))
2702 if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
2703 if (bflags & BFLAGS_Public)
2706 if (bflags & BFLAGS_NonPublic)
2712 if (method->flags & METHOD_ATTRIBUTE_STATIC) {
2713 if (bflags & BFLAGS_Static)
2714 if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
2717 if (bflags & BFLAGS_Instance)
2723 member = (MonoObject*)mono_method_get_object (domain, method, refklass);
2725 l = g_slist_prepend (l, member);
2727 len = g_slist_length (l);
2728 if (!System_Reflection_ConstructorInfo)
2729 System_Reflection_ConstructorInfo = mono_class_from_name (
2730 mono_defaults.corlib, "System.Reflection", "ConstructorInfo");
2731 res = mono_array_new (domain, System_Reflection_ConstructorInfo, len);
2733 tmp = l = g_slist_reverse (l);
2734 for (; tmp; tmp = tmp->next, ++i)
2735 mono_array_set (res, gpointer, i, tmp->data);
2741 ves_icall_Type_GetPropertiesByName (MonoReflectionType *type, MonoString *name, guint32 bflags, MonoBoolean ignore_case, MonoReflectionType *reftype)
2744 GSList *l = NULL, *tmp;
2745 static MonoClass *System_Reflection_PropertyInfo;
2746 MonoClass *startklass, *klass;
2752 GHashTable *method_slots = g_hash_table_new (NULL, NULL);
2753 gchar *propname = NULL;
2754 int (*compare_func) (const char *s1, const char *s2) = NULL;
2756 MONO_ARCH_SAVE_REGS;
2758 domain = ((MonoObject *)type)->vtable->domain;
2759 klass = startklass = mono_class_from_mono_type (type->type);
2761 propname = mono_string_to_utf8 (name);
2762 compare_func = (ignore_case) ? g_strcasecmp : strcmp;
2766 for (i = 0; i < klass->property.count; ++i) {
2767 prop = &klass->properties [i];
2772 if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
2773 if (bflags & BFLAGS_Public)
2776 if (bflags & BFLAGS_NonPublic)
2782 if (method->flags & METHOD_ATTRIBUTE_STATIC) {
2783 if (bflags & BFLAGS_Static)
2784 if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
2787 if (bflags & BFLAGS_Instance)
2796 if (compare_func (propname, prop->name))
2800 if (prop->get && prop->get->slot != -1) {
2801 if (g_hash_table_lookup (method_slots, GUINT_TO_POINTER (prop->get->slot)))
2803 g_hash_table_insert (method_slots, GUINT_TO_POINTER (prop->get->slot), prop);
2805 if (prop->set && prop->set->slot != -1) {
2806 if (g_hash_table_lookup (method_slots, GUINT_TO_POINTER (prop->set->slot)))
2808 g_hash_table_insert (method_slots, GUINT_TO_POINTER (prop->set->slot), prop);
2811 l = g_slist_prepend (l, mono_property_get_object (domain, startklass, prop));
2814 if ((!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent)))
2818 if (!System_Reflection_PropertyInfo)
2819 System_Reflection_PropertyInfo = mono_class_from_name (
2820 mono_defaults.corlib, "System.Reflection", "PropertyInfo");
2821 res = mono_array_new (domain, System_Reflection_PropertyInfo, len);
2824 tmp = l = g_slist_reverse (l);
2826 for (; tmp; tmp = tmp->next, ++i)
2827 mono_array_set (res, gpointer, i, tmp->data);
2829 g_hash_table_destroy (method_slots);
2833 static MonoReflectionEvent *
2834 ves_icall_MonoType_GetEvent (MonoReflectionType *type, MonoString *name, guint32 bflags)
2837 MonoClass *klass, *startklass;
2843 MONO_ARCH_SAVE_REGS;
2845 event_name = mono_string_to_utf8 (name);
2846 klass = startklass = mono_class_from_mono_type (type->type);
2847 domain = mono_object_domain (type);
2850 for (i = 0; i < klass->event.count; i++) {
2851 event = &klass->events [i];
2852 if (strcmp (event->name, event_name))
2855 method = event->add;
2857 method = event->remove;
2859 method = event->raise;
2861 if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
2862 if (!(bflags & BFLAGS_Public))
2865 if (!(bflags & BFLAGS_NonPublic))
2870 if (!(bflags & BFLAGS_NonPublic))
2873 g_free (event_name);
2874 return mono_event_get_object (domain, startklass, event);
2877 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
2880 g_free (event_name);
2885 ves_icall_Type_GetEvents_internal (MonoReflectionType *type, guint32 bflags, MonoReflectionType *reftype)
2888 GSList *l = NULL, *tmp;
2889 static MonoClass *System_Reflection_EventInfo;
2890 MonoClass *startklass, *klass;
2896 MONO_ARCH_SAVE_REGS;
2898 domain = ((MonoObject *)type)->vtable->domain;
2899 klass = startklass = mono_class_from_mono_type (type->type);
2902 for (i = 0; i < klass->event.count; ++i) {
2903 event = &klass->events [i];
2905 method = event->add;
2907 method = event->remove;
2909 method = event->raise;
2911 if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
2912 if (bflags & BFLAGS_Public)
2915 if (bflags & BFLAGS_NonPublic)
2920 if (bflags & BFLAGS_NonPublic)
2926 if (method->flags & METHOD_ATTRIBUTE_STATIC) {
2927 if (bflags & BFLAGS_Static)
2928 if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
2931 if (bflags & BFLAGS_Instance)
2936 if (bflags & BFLAGS_Instance)
2941 l = g_slist_prepend (l, mono_event_get_object (domain, klass, event));
2943 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
2945 len = g_slist_length (l);
2946 if (!System_Reflection_EventInfo)
2947 System_Reflection_EventInfo = mono_class_from_name (
2948 mono_defaults.corlib, "System.Reflection", "EventInfo");
2949 res = mono_array_new (domain, System_Reflection_EventInfo, len);
2952 tmp = l = g_slist_reverse (l);
2954 for (; tmp; tmp = tmp->next, ++i)
2955 mono_array_set (res, gpointer, i, tmp->data);
2960 static MonoReflectionType *
2961 ves_icall_Type_GetNestedType (MonoReflectionType *type, MonoString *name, guint32 bflags)
2964 MonoClass *startklass, *klass;
2969 MONO_ARCH_SAVE_REGS;
2971 domain = ((MonoObject *)type)->vtable->domain;
2972 klass = startklass = mono_class_from_mono_type (type->type);
2973 str = mono_string_to_utf8 (name);
2976 for (tmpn = klass->nested_classes; tmpn; tmpn = tmpn->next) {
2978 nested = tmpn->data;
2979 if ((nested->flags & TYPE_ATTRIBUTE_VISIBILITY_MASK) == TYPE_ATTRIBUTE_NESTED_PUBLIC) {
2980 if (bflags & BFLAGS_Public)
2983 if (bflags & BFLAGS_NonPublic)
2988 if (strcmp (nested->name, str) == 0){
2990 return mono_type_get_object (domain, &nested->byval_arg);
2993 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
3000 ves_icall_Type_GetNestedTypes (MonoReflectionType *type, guint32 bflags)
3003 GSList *l = NULL, *tmp;
3005 MonoClass *startklass, *klass;
3011 MONO_ARCH_SAVE_REGS;
3013 domain = ((MonoObject *)type)->vtable->domain;
3014 klass = startklass = mono_class_from_mono_type (type->type);
3016 for (tmpn = klass->nested_classes; tmpn; tmpn = tmpn->next) {
3018 nested = tmpn->data;
3019 if ((nested->flags & TYPE_ATTRIBUTE_VISIBILITY_MASK) == TYPE_ATTRIBUTE_NESTED_PUBLIC) {
3020 if (bflags & BFLAGS_Public)
3023 if (bflags & BFLAGS_NonPublic)
3028 member = (MonoObject*)mono_type_get_object (domain, &nested->byval_arg);
3029 l = g_slist_prepend (l, member);
3031 len = g_slist_length (l);
3032 res = mono_array_new (domain, mono_defaults.monotype_class, len);
3034 tmp = l = g_slist_reverse (l);
3035 for (; tmp; tmp = tmp->next, ++i)
3036 mono_array_set (res, gpointer, i, tmp->data);
3041 static MonoReflectionType*
3042 ves_icall_System_Reflection_Assembly_InternalGetType (MonoReflectionAssembly *assembly, MonoReflectionModule *module, MonoString *name, MonoBoolean throwOnError, MonoBoolean ignoreCase)
3045 MonoType *type = NULL;
3046 MonoTypeNameParse info;
3047 gboolean type_resolve = FALSE;
3049 MONO_ARCH_SAVE_REGS;
3051 str = mono_string_to_utf8 (name);
3052 /*g_print ("requested type %s in %s\n", str, assembly->assembly->aname.name);*/
3053 if (!mono_reflection_parse_type (str, &info)) {
3055 g_list_free (info.modifiers);
3056 g_list_free (info.nested);
3057 if (throwOnError) /* uhm: this is a parse error, though... */
3058 mono_raise_exception (mono_get_exception_type_load (name));
3059 /*g_print ("failed parse\n");*/
3063 if (module != NULL) {
3065 type = mono_reflection_get_type (module->image, &info, ignoreCase, &type_resolve);
3070 if (assembly->assembly->dynamic) {
3071 /* Enumerate all modules */
3072 MonoReflectionAssemblyBuilder *abuilder = (MonoReflectionAssemblyBuilder*)assembly;
3076 if (abuilder->modules) {
3077 for (i = 0; i < mono_array_length (abuilder->modules); ++i) {
3078 MonoReflectionModuleBuilder *mb = mono_array_get (abuilder->modules, MonoReflectionModuleBuilder*, i);
3079 type = mono_reflection_get_type (&mb->dynamic_image->image, &info, ignoreCase, &type_resolve);
3085 if (!type && abuilder->loaded_modules) {
3086 for (i = 0; i < mono_array_length (abuilder->loaded_modules); ++i) {
3087 MonoReflectionModule *mod = mono_array_get (abuilder->loaded_modules, MonoReflectionModule*, i);
3088 type = mono_reflection_get_type (mod->image, &info, ignoreCase, &type_resolve);
3095 type = mono_reflection_get_type (assembly->assembly->image, &info, ignoreCase, &type_resolve);
3097 g_list_free (info.modifiers);
3098 g_list_free (info.nested);
3101 mono_raise_exception (mono_get_exception_type_load (name));
3102 /* g_print ("failed find\n"); */
3105 /* g_print ("got it\n"); */
3106 return mono_type_get_object (mono_object_domain (assembly), type);
3111 ves_icall_System_Reflection_Assembly_get_code_base (MonoReflectionAssembly *assembly)
3113 MonoDomain *domain = mono_object_domain (assembly);
3114 MonoAssembly *mass = assembly->assembly;
3119 MONO_ARCH_SAVE_REGS;
3121 absolute = g_build_filename (mass->basedir, mass->image->module_name, NULL);
3122 uri = g_filename_to_uri (absolute, NULL, NULL);
3123 res = mono_string_new (domain, uri);
3130 ves_icall_System_Reflection_Assembly_get_global_assembly_cache (MonoReflectionAssembly *assembly)
3132 MonoAssembly *mass = assembly->assembly;
3134 MONO_ARCH_SAVE_REGS;
3136 return mass->in_gac;
3139 static MonoReflectionAssembly*
3140 ves_icall_System_Reflection_Assembly_load_with_partial_name (MonoString *mname, MonoObject *evidence)
3144 MonoImageOpenStatus status;
3146 MONO_ARCH_SAVE_REGS;
3148 name = mono_string_to_utf8 (mname);
3149 res = mono_assembly_load_with_partial_name (name, &status);
3155 return mono_assembly_get_object (mono_domain_get (), res);
3159 ves_icall_System_Reflection_Assembly_get_location (MonoReflectionAssembly *assembly)
3161 MonoDomain *domain = mono_object_domain (assembly);
3164 MONO_ARCH_SAVE_REGS;
3166 res = mono_string_new (domain, mono_image_get_filename (assembly->assembly->image));
3172 ves_icall_System_Reflection_Assembly_InternalImageRuntimeVersion (MonoReflectionAssembly *assembly)
3174 MonoDomain *domain = mono_object_domain (assembly);
3176 MONO_ARCH_SAVE_REGS;
3178 return mono_string_new (domain, assembly->assembly->image->version);
3181 static MonoReflectionMethod*
3182 ves_icall_System_Reflection_Assembly_get_EntryPoint (MonoReflectionAssembly *assembly)
3184 guint32 token = mono_image_get_entry_point (assembly->assembly->image);
3186 MONO_ARCH_SAVE_REGS;
3190 return mono_method_get_object (mono_object_domain (assembly), mono_get_method (assembly->assembly->image, token, NULL), NULL);
3194 ves_icall_System_Reflection_Assembly_GetManifestResourceNames (MonoReflectionAssembly *assembly)
3196 MonoTableInfo *table = &assembly->assembly->image->tables [MONO_TABLE_MANIFESTRESOURCE];
3197 MonoArray *result = mono_array_new (mono_object_domain (assembly), mono_defaults.string_class, table->rows);
3201 MONO_ARCH_SAVE_REGS;
3203 for (i = 0; i < table->rows; ++i) {
3204 val = mono_metadata_string_heap (assembly->assembly->image, mono_metadata_decode_row_col (table, i, MONO_MANIFEST_NAME));
3205 mono_array_set (result, gpointer, i, mono_string_new (mono_object_domain (assembly), val));
3211 ves_icall_System_Reflection_Assembly_GetReferencedAssemblies (MonoReflectionAssembly *assembly)
3213 static MonoClass *System_Reflection_AssemblyName;
3215 MonoDomain *domain = mono_object_domain (assembly);
3217 static MonoMethod *create_culture = NULL;
3220 MONO_ARCH_SAVE_REGS;
3222 if (!System_Reflection_AssemblyName)
3223 System_Reflection_AssemblyName = mono_class_from_name (
3224 mono_defaults.corlib, "System.Reflection", "AssemblyName");
3226 t = &assembly->assembly->image->tables [MONO_TABLE_ASSEMBLYREF];
3229 result = mono_array_new (domain, System_Reflection_AssemblyName, count);
3232 MonoMethodDesc *desc = mono_method_desc_new (
3233 "System.Globalization.CultureInfo:CreateSpecificCulture(string)", TRUE);
3234 create_culture = mono_method_desc_search_in_image (desc, mono_defaults.corlib);
3235 g_assert (create_culture);
3236 mono_method_desc_free (desc);
3239 for (i = 0; i < count; i++) {
3240 MonoAssembly *assem;
3241 MonoReflectionAssemblyName *aname;
3242 char *codebase, *absolute;
3244 /* FIXME: There is no need to load the assemblies themselves */
3245 mono_assembly_load_reference (assembly->assembly->image, i);
3247 assem = assembly->assembly->image->references [i];
3248 if (assem == (gpointer)-1) {
3249 char *msg = g_strdup_printf ("Assembly %d referenced from assembly %s not found ", i, assembly->assembly->image->name);
3250 MonoException *ex = mono_get_exception_file_not_found2 (msg, NULL);
3252 mono_raise_exception (ex);
3255 aname = (MonoReflectionAssemblyName *) mono_object_new (
3256 domain, System_Reflection_AssemblyName);
3258 aname->name = mono_string_new (domain, assem->aname.name);
3260 aname->major = assem->aname.major;
3261 aname->minor = assem->aname.minor;
3262 aname->build = assem->aname.build;
3263 aname->revision = assem->aname.revision;
3264 aname->revision = assem->aname.revision;
3265 aname->hashalg = assem->aname.hash_alg;
3266 aname->flags = assem->aname.flags;
3268 if (create_culture) {
3270 args [0] = mono_string_new (domain, assem->aname.culture);
3271 aname->cultureInfo = mono_runtime_invoke (create_culture, NULL, args, NULL);
3274 if (assem->aname.public_key) {
3276 const char *pkey_ptr = assem->aname.public_key;
3277 pkey_len = mono_metadata_decode_blob_size (pkey_ptr, &pkey_ptr);
3279 aname->publicKey = mono_array_new (domain, mono_defaults.byte_class, pkey_len);
3280 memcpy (mono_array_addr (aname->publicKey, guint8, 0), pkey_ptr, pkey_len);
3283 /* public key token isn't copied - the class library will
3284 automatically generate it from the public key if required */
3286 absolute = g_build_filename (assem->basedir, assem->image->module_name, NULL);
3287 codebase = g_filename_to_uri (absolute, NULL, NULL);
3288 aname->codebase = mono_string_new (domain, codebase);
3291 mono_array_set (result, gpointer, i, aname);
3302 foreach_namespace (const char* key, gconstpointer val, NameSpaceInfo *info)
3304 MonoString *name = mono_string_new (mono_object_domain (info->res), key);
3306 mono_array_set (info->res, gpointer, info->idx, name);
3311 ves_icall_System_Reflection_Assembly_GetNamespaces (MonoReflectionAssembly *assembly)
3313 MonoImage *img = assembly->assembly->image;
3317 MonoTableInfo *t = &img->tables [MONO_TABLE_EXPORTEDTYPE];
3320 MONO_ARCH_SAVE_REGS;
3322 n = g_hash_table_size (img->name_cache);
3323 res = mono_array_new (mono_object_domain (assembly), mono_defaults.string_class, n);
3326 g_hash_table_foreach (img->name_cache, (GHFunc)foreach_namespace, &info);
3328 /* Add namespaces from the EXPORTEDTYPES table as well */
3331 GPtrArray *nspaces = g_ptr_array_new ();
3332 for (i = 0; i < t->rows; ++i) {
3333 const char *nspace = mono_metadata_string_heap (img, mono_metadata_decode_row_col (t, i, MONO_EXP_TYPE_NAMESPACE));
3334 if (!g_hash_table_lookup (img->name_cache, nspace)) {
3335 g_ptr_array_add (nspaces, (char*)nspace);
3338 if (nspaces->len > 0) {
3339 res2 = mono_array_new (mono_object_domain (assembly), mono_defaults.string_class, n + nspaces->len);
3340 memcpy (mono_array_addr (res2, MonoString*, 0),
3341 mono_array_addr (res, MonoString*, 0),
3342 n * sizeof (MonoString*));
3343 for (i = 0; i < nspaces->len; ++i)
3344 mono_array_set (res2, MonoString*, n + i,
3345 mono_string_new (mono_object_domain (assembly),
3346 g_ptr_array_index (nspaces, i)));
3349 g_ptr_array_free (nspaces, TRUE);
3355 /* move this in some file in mono/util/ */
3357 g_concat_dir_and_file (const char *dir, const char *file)
3359 g_return_val_if_fail (dir != NULL, NULL);
3360 g_return_val_if_fail (file != NULL, NULL);
3363 * If the directory name doesn't have a / on the end, we need
3364 * to add one so we get a proper path to the file
3366 if (dir [strlen(dir) - 1] != G_DIR_SEPARATOR)
3367 return g_strconcat (dir, G_DIR_SEPARATOR_S, file, NULL);
3369 return g_strconcat (dir, file, NULL);
3373 ves_icall_System_Reflection_Assembly_GetManifestResourceInternal (MonoReflectionAssembly *assembly, MonoString *name, gint32 *size, MonoReflectionModule **ref_module)
3375 char *n = mono_string_to_utf8 (name);
3376 MonoTableInfo *table = &assembly->assembly->image->tables [MONO_TABLE_MANIFESTRESOURCE];
3378 guint32 cols [MONO_MANIFEST_SIZE];
3379 guint32 impl, file_idx;
3383 MONO_ARCH_SAVE_REGS;
3385 for (i = 0; i < table->rows; ++i) {
3386 mono_metadata_decode_row (table, i, cols, MONO_MANIFEST_SIZE);
3387 val = mono_metadata_string_heap (assembly->assembly->image, cols [MONO_MANIFEST_NAME]);
3388 if (strcmp (val, n) == 0)
3392 if (i == table->rows)
3395 impl = cols [MONO_MANIFEST_IMPLEMENTATION];
3398 * this code should only be called after obtaining the
3399 * ResourceInfo and handling the other cases.
3401 g_assert ((impl & MONO_IMPLEMENTATION_MASK) == MONO_IMPLEMENTATION_FILE);
3402 file_idx = impl >> MONO_IMPLEMENTATION_BITS;
3404 module = mono_image_load_file_for_image (assembly->assembly->image, file_idx);
3409 module = assembly->assembly->image;
3411 *ref_module = mono_module_get_object (mono_domain_get (), module);
3413 return (void*)mono_image_get_resource (module, cols [MONO_MANIFEST_OFFSET], size);
3417 ves_icall_System_Reflection_Assembly_GetManifestResourceInfoInternal (MonoReflectionAssembly *assembly, MonoString *name, MonoManifestResourceInfo *info)
3419 MonoTableInfo *table = &assembly->assembly->image->tables [MONO_TABLE_MANIFESTRESOURCE];
3421 guint32 cols [MONO_MANIFEST_SIZE];
3422 guint32 file_cols [MONO_FILE_SIZE];
3426 MONO_ARCH_SAVE_REGS;
3428 n = mono_string_to_utf8 (name);
3429 for (i = 0; i < table->rows; ++i) {
3430 mono_metadata_decode_row (table, i, cols, MONO_MANIFEST_SIZE);
3431 val = mono_metadata_string_heap (assembly->assembly->image, cols [MONO_MANIFEST_NAME]);
3432 if (strcmp (val, n) == 0)
3436 if (i == table->rows)
3439 if (!cols [MONO_MANIFEST_IMPLEMENTATION]) {
3440 info->location = RESOURCE_LOCATION_EMBEDDED | RESOURCE_LOCATION_IN_MANIFEST;
3443 switch (cols [MONO_MANIFEST_IMPLEMENTATION] & MONO_IMPLEMENTATION_MASK) {
3444 case MONO_IMPLEMENTATION_FILE:
3445 i = cols [MONO_MANIFEST_IMPLEMENTATION] >> MONO_IMPLEMENTATION_BITS;
3446 table = &assembly->assembly->image->tables [MONO_TABLE_FILE];
3447 mono_metadata_decode_row (table, i - 1, file_cols, MONO_FILE_SIZE);
3448 val = mono_metadata_string_heap (assembly->assembly->image, file_cols [MONO_FILE_NAME]);
3449 info->filename = mono_string_new (mono_object_domain (assembly), val);
3450 if (file_cols [MONO_FILE_FLAGS] && FILE_CONTAINS_NO_METADATA)
3453 info->location = RESOURCE_LOCATION_EMBEDDED;
3456 case MONO_IMPLEMENTATION_ASSEMBLYREF:
3457 i = cols [MONO_MANIFEST_IMPLEMENTATION] >> MONO_IMPLEMENTATION_BITS;
3458 mono_assembly_load_reference (assembly->assembly->image, i - 1);
3459 if (assembly->assembly->image->references [i - 1] == (gpointer)-1) {
3460 char *msg = g_strdup_printf ("Assembly %d referenced from assembly %s not found ", i - 1, assembly->assembly->image->name);
3461 MonoException *ex = mono_get_exception_file_not_found2 (msg, NULL);
3463 mono_raise_exception (ex);
3465 info->assembly = mono_assembly_get_object (mono_domain_get (), assembly->assembly->image->references [i - 1]);
3467 /* Obtain info recursively */
3468 ves_icall_System_Reflection_Assembly_GetManifestResourceInfoInternal (info->assembly, name, info);
3469 info->location |= RESOURCE_LOCATION_ANOTHER_ASSEMBLY;
3472 case MONO_IMPLEMENTATION_EXP_TYPE:
3473 g_assert_not_reached ();
3482 ves_icall_System_Reflection_Assembly_GetFilesInternal (MonoReflectionAssembly *assembly, MonoString *name)
3484 MonoTableInfo *table = &assembly->assembly->image->tables [MONO_TABLE_FILE];
3485 MonoArray *result = NULL;
3490 MONO_ARCH_SAVE_REGS;
3492 /* check hash if needed */
3494 n = mono_string_to_utf8 (name);
3495 for (i = 0; i < table->rows; ++i) {
3496 val = mono_metadata_string_heap (assembly->assembly->image, mono_metadata_decode_row_col (table, i, MONO_FILE_NAME));
3497 if (strcmp (val, n) == 0) {
3500 n = g_concat_dir_and_file (assembly->assembly->basedir, val);
3501 fn = mono_string_new (mono_object_domain (assembly), n);
3503 return (MonoObject*)fn;
3510 for (i = 0; i < table->rows; ++i) {
3511 result = mono_array_new (mono_object_domain (assembly), mono_defaults.string_class, table->rows);
3512 val = mono_metadata_string_heap (assembly->assembly->image, mono_metadata_decode_row_col (table, i, MONO_FILE_NAME));
3513 n = g_concat_dir_and_file (assembly->assembly->basedir, val);
3514 mono_array_set (result, gpointer, i, mono_string_new (mono_object_domain (assembly), n));
3517 return (MonoObject*)result;
3521 ves_icall_System_Reflection_Assembly_GetModulesInternal (MonoReflectionAssembly *assembly)
3523 MonoDomain *domain = mono_domain_get();
3526 int i, module_count = 0, file_count = 0;
3527 MonoImage **modules = assembly->assembly->image->modules;
3528 MonoTableInfo *table;
3531 while (modules[module_count])
3535 table = &assembly->assembly->image->tables [MONO_TABLE_FILE];
3536 file_count = table->rows;
3538 g_assert( assembly->assembly->image != NULL);
3541 klass = mono_class_from_name ( mono_defaults.corlib, "System.Reflection", "Module");
3542 res = mono_array_new (domain, klass, module_count + file_count);
3544 mono_array_set (res, gpointer, 0, mono_module_get_object (domain, assembly->assembly->image));
3545 for ( i = 1; i < module_count; ++i )
3546 mono_array_set (res, gpointer, i, mono_module_get_object (domain, modules[i]));
3548 for (i = 0; i < table->rows; ++i)
3549 mono_array_set (res, gpointer, module_count + i, mono_module_file_get_object (domain, assembly->assembly->image, i));
3554 static MonoReflectionMethod*
3555 ves_icall_GetCurrentMethod (void)
3557 MonoMethod *m = mono_method_get_last_managed ();
3559 MONO_ARCH_SAVE_REGS;
3561 return mono_method_get_object (mono_domain_get (), m, NULL);
3564 static MonoReflectionMethod*
3565 ves_icall_System_Reflection_MethodBase_GetMethodFromHandleInternal (MonoMethod *method)
3567 return mono_method_get_object (mono_domain_get (), method, NULL);
3570 static MonoReflectionAssembly*
3571 ves_icall_System_Reflection_Assembly_GetExecutingAssembly (void)
3573 MonoMethod *m = mono_method_get_last_managed ();
3575 MONO_ARCH_SAVE_REGS;
3577 return mono_assembly_get_object (mono_domain_get (), m->klass->image->assembly);
3582 get_caller (MonoMethod *m, gint32 no, gint32 ilo, gboolean managed, gpointer data)
3584 MonoMethod **dest = data;
3586 /* skip unmanaged frames */
3601 static MonoReflectionAssembly*
3602 ves_icall_System_Reflection_Assembly_GetEntryAssembly (void)
3604 MonoDomain* domain = mono_domain_get ();
3606 MONO_ARCH_SAVE_REGS;
3608 if (!domain->entry_assembly)
3609 domain = mono_get_root_domain ();
3611 return mono_assembly_get_object (domain, domain->entry_assembly);
3615 static MonoReflectionAssembly*
3616 ves_icall_System_Reflection_Assembly_GetCallingAssembly (void)
3618 MonoMethod *m = mono_method_get_last_managed ();
3619 MonoMethod *dest = m;
3621 MONO_ARCH_SAVE_REGS;
3623 mono_stack_walk (get_caller, &dest);
3626 return mono_assembly_get_object (mono_domain_get (), dest->klass->image->assembly);
3630 ves_icall_System_MonoType_getFullName (MonoReflectionType *object, gboolean full_name)
3632 MonoDomain *domain = mono_object_domain (object);
3636 MONO_ARCH_SAVE_REGS;
3639 name = mono_type_get_full_name (object->type);
3641 name = mono_type_get_name (object->type);
3642 res = mono_string_new (domain, name);
3649 fill_reflection_assembly_name (MonoDomain *domain, MonoReflectionAssemblyName *aname, MonoAssemblyName *name, const char *absolute)
3651 static MonoMethod *create_culture = NULL;
3654 const char *pkey_ptr;
3657 MONO_ARCH_SAVE_REGS;
3659 aname->name = mono_string_new (domain, name->name);
3660 aname->major = name->major;
3661 aname->minor = name->minor;
3662 aname->build = name->build;
3663 aname->revision = name->revision;
3664 aname->hashalg = name->hash_alg;
3666 codebase = g_filename_to_uri (absolute, NULL, NULL);
3668 aname->codebase = mono_string_new (domain, codebase);
3672 if (!create_culture) {
3673 MonoMethodDesc *desc = mono_method_desc_new ("System.Globalization.CultureInfo:CreateSpecificCulture(string)", TRUE);
3674 create_culture = mono_method_desc_search_in_image (desc, mono_defaults.corlib);
3675 g_assert (create_culture);
3676 mono_method_desc_free (desc);
3679 args [0] = mono_string_new (domain, name->culture);
3680 aname->cultureInfo =
3681 mono_runtime_invoke (create_culture, NULL, args, NULL);
3683 if (name->public_key) {
3684 pkey_ptr = name->public_key;
3685 pkey_len = mono_metadata_decode_blob_size (pkey_ptr, &pkey_ptr);
3687 aname->publicKey = mono_array_new (domain, mono_defaults.byte_class, pkey_len);
3688 memcpy (mono_array_addr (aname->publicKey, guint8, 0), pkey_ptr, pkey_len);
3693 ves_icall_System_Reflection_Assembly_FillName (MonoReflectionAssembly *assembly, MonoReflectionAssemblyName *aname)
3697 MONO_ARCH_SAVE_REGS;
3699 absolute = g_build_filename (assembly->assembly->basedir, assembly->assembly->image->module_name, NULL);
3701 fill_reflection_assembly_name (mono_object_domain (assembly), aname,
3702 &assembly->assembly->aname, absolute);
3708 ves_icall_System_Reflection_Assembly_InternalGetAssemblyName (MonoString *fname, MonoReflectionAssemblyName *aname)
3711 MonoImageOpenStatus status = MONO_IMAGE_OK;
3714 MonoAssemblyName name;
3716 MONO_ARCH_SAVE_REGS;
3718 filename = mono_string_to_utf8 (fname);
3720 image = mono_image_open (filename, &status);
3726 exc = mono_get_exception_file_not_found (fname);
3727 mono_raise_exception (exc);
3730 res = mono_assembly_fill_assembly_name (image, &name);
3732 mono_image_close (image);
3734 mono_raise_exception (mono_get_exception_argument ("assemblyFile", "The file does not contain a manifest"));
3737 fill_reflection_assembly_name (mono_domain_get (), aname, &name, filename);
3740 mono_image_close (image);
3744 mono_module_get_types (MonoDomain *domain, MonoImage *image,
3745 MonoBoolean exportedOnly)
3749 MonoTableInfo *tdef = &image->tables [MONO_TABLE_TYPEDEF];
3751 guint32 attrs, visibility;
3753 /* we start the count from 1 because we skip the special type <Module> */
3756 for (i = 1; i < tdef->rows; ++i) {
3757 attrs = mono_metadata_decode_row_col (tdef, i, MONO_TYPEDEF_FLAGS);
3758 visibility = attrs & TYPE_ATTRIBUTE_VISIBILITY_MASK;
3759 if (visibility == TYPE_ATTRIBUTE_PUBLIC || visibility == TYPE_ATTRIBUTE_NESTED_PUBLIC)
3763 count = tdef->rows - 1;
3765 res = mono_array_new (domain, mono_defaults.monotype_class, count);
3767 for (i = 1; i < tdef->rows; ++i) {
3768 attrs = mono_metadata_decode_row_col (tdef, i, MONO_TYPEDEF_FLAGS);
3769 visibility = attrs & TYPE_ATTRIBUTE_VISIBILITY_MASK;
3770 if (!exportedOnly || (visibility == TYPE_ATTRIBUTE_PUBLIC || visibility == TYPE_ATTRIBUTE_NESTED_PUBLIC)) {
3771 klass = mono_class_get (image, (i + 1) | MONO_TOKEN_TYPE_DEF);
3772 mono_array_set (res, gpointer, count, mono_type_get_object (domain, &klass->byval_arg));
3781 ves_icall_System_Reflection_Assembly_GetTypes (MonoReflectionAssembly *assembly, MonoBoolean exportedOnly)
3783 MonoArray *res = NULL;
3784 MonoImage *image = NULL;
3785 MonoTableInfo *table = NULL;
3789 MONO_ARCH_SAVE_REGS;
3791 domain = mono_object_domain (assembly);
3793 if (assembly->assembly->dynamic) {
3794 MonoReflectionAssemblyBuilder *abuilder = (MonoReflectionAssemblyBuilder*)assembly;
3795 if (abuilder->modules)
3796 for (i = 0; i < mono_array_length(abuilder->modules); i++) {
3797 MonoReflectionModuleBuilder *mb = mono_array_get (abuilder->modules, MonoReflectionModuleBuilder*, i);
3801 MonoArray *append = mb->types;
3802 if (mono_array_length (append) > 0) {
3805 len1 = mono_array_length (res);
3806 len2 = mono_array_length (append);
3807 new = mono_array_new (domain, mono_defaults.monotype_class, len1 + len2);
3808 memcpy (mono_array_addr (new, MonoReflectionType*, 0),
3809 mono_array_addr (res, MonoReflectionType*, 0),
3810 len1 * sizeof (MonoReflectionType*));
3811 memcpy (mono_array_addr (new, MonoReflectionType*, len1),
3812 mono_array_addr (append, MonoReflectionType*, 0),
3813 len2 * sizeof (MonoReflectionType*));
3818 if (abuilder->loaded_modules)
3819 for (i = 0; i < mono_array_length(abuilder->loaded_modules); i++) {
3820 MonoReflectionModule *rm = mono_array_get (abuilder->loaded_modules, MonoReflectionModule*, i);
3822 res = mono_module_get_types (domain, rm->image, exportedOnly);
3824 MonoArray *append = mono_module_get_types (domain, rm->image, exportedOnly);
3825 if (mono_array_length (append) > 0) {
3828 len1 = mono_array_length (res);
3829 len2 = mono_array_length (append);
3830 new = mono_array_new (domain, mono_defaults.monotype_class, len1 + len2);
3831 memcpy (mono_array_addr (new, MonoReflectionType*, 0),
3832 mono_array_addr (res, MonoReflectionType*, 0),
3833 len1 * sizeof (MonoReflectionType*));
3834 memcpy (mono_array_addr (new, MonoReflectionType*, len1),
3835 mono_array_addr (append, MonoReflectionType*, 0),
3836 len2 * sizeof (MonoReflectionType*));
3843 image = assembly->assembly->image;
3844 table = &image->tables [MONO_TABLE_FILE];
3845 res = mono_module_get_types (domain, image, exportedOnly);
3847 /* Append data from all modules in the assembly */
3848 for (i = 0; i < table->rows; ++i) {
3849 if (!(mono_metadata_decode_row_col (table, i, MONO_FILE_FLAGS) & FILE_CONTAINS_NO_METADATA)) {
3850 MonoImage *loaded_image = mono_assembly_load_module (image->assembly, i + 1);
3852 MonoArray *res2 = mono_module_get_types (domain, loaded_image, exportedOnly);
3853 /* Append the new types to the end of the array */
3854 if (mono_array_length (res2) > 0) {
3858 len1 = mono_array_length (res);
3859 len2 = mono_array_length (res2);
3860 res3 = mono_array_new (domain, mono_defaults.monotype_class, len1 + len2);
3861 memcpy (mono_array_addr (res3, MonoReflectionType*, 0),
3862 mono_array_addr (res, MonoReflectionType*, 0),
3863 len1 * sizeof (MonoReflectionType*));
3864 memcpy (mono_array_addr (res3, MonoReflectionType*, len1),
3865 mono_array_addr (res2, MonoReflectionType*, 0),
3866 len2 * sizeof (MonoReflectionType*));
3875 static MonoReflectionType*
3876 ves_icall_System_Reflection_Module_GetGlobalType (MonoReflectionModule *module)
3878 MonoDomain *domain = mono_object_domain (module);
3881 MONO_ARCH_SAVE_REGS;
3883 g_assert (module->image);
3884 klass = mono_class_get (module->image, 1 | MONO_TOKEN_TYPE_DEF);
3885 return mono_type_get_object (domain, &klass->byval_arg);
3889 ves_icall_System_Reflection_Module_Close (MonoReflectionModule *module)
3892 mono_image_close (module->image);
3896 ves_icall_System_Reflection_Module_GetGuidInternal (MonoReflectionModule *module)
3898 MonoDomain *domain = mono_object_domain (module);
3900 MONO_ARCH_SAVE_REGS;
3902 g_assert (module->image);
3903 return mono_string_new (domain, module->image->guid);
3907 ves_icall_System_Reflection_Module_InternalGetTypes (MonoReflectionModule *module)
3909 MONO_ARCH_SAVE_REGS;
3912 return mono_array_new (mono_object_domain (module), mono_defaults.monotype_class, 0);
3914 return mono_module_get_types (mono_object_domain (module), module->image, FALSE);
3917 static MonoReflectionType*
3918 ves_icall_ModuleBuilder_create_modified_type (MonoReflectionTypeBuilder *tb, MonoString *smodifiers)
3921 int isbyref = 0, rank;
3922 char *str = mono_string_to_utf8 (smodifiers);
3925 MONO_ARCH_SAVE_REGS;
3927 klass = mono_class_from_mono_type (tb->type.type);
3929 /* logic taken from mono_reflection_parse_type(): keep in sync */
3933 if (isbyref) { /* only one level allowed by the spec */
3940 return mono_type_get_object (mono_object_domain (tb), &klass->this_arg);
3943 klass = mono_ptr_class_get (&klass->byval_arg);
3944 mono_class_init (klass);
3955 else if (*p != '*') { /* '*' means unknown lower bound */
3966 klass = mono_array_class_get (klass, rank);
3967 mono_class_init (klass);
3974 return mono_type_get_object (mono_object_domain (tb), &klass->byval_arg);
3978 ves_icall_Type_IsArrayImpl (MonoReflectionType *t)
3983 MONO_ARCH_SAVE_REGS;
3986 res = !type->byref && (type->type == MONO_TYPE_ARRAY || type->type == MONO_TYPE_SZARRAY);
3991 static MonoReflectionType *
3992 ves_icall_Type_make_array_type (MonoReflectionType *type, int rank)
3994 MonoClass *klass, *aklass;
3996 MONO_ARCH_SAVE_REGS;
3998 klass = mono_class_from_mono_type (type->type);
3999 aklass = mono_array_class_get (klass, rank);
4001 return mono_type_get_object (mono_object_domain (type), &aklass->byval_arg);
4004 static MonoReflectionType *
4005 ves_icall_Type_make_byref_type (MonoReflectionType *type)
4009 MONO_ARCH_SAVE_REGS;
4011 klass = mono_class_from_mono_type (type->type);
4013 return mono_type_get_object (mono_object_domain (type), &klass->this_arg);
4017 ves_icall_System_Delegate_CreateDelegate_internal (MonoReflectionType *type, MonoObject *target,
4018 MonoReflectionMethod *info)
4020 MonoClass *delegate_class = mono_class_from_mono_type (type->type);
4021 MonoObject *delegate;
4024 MONO_ARCH_SAVE_REGS;
4026 mono_assert (delegate_class->parent == mono_defaults.multicastdelegate_class);
4028 delegate = mono_object_new (mono_object_domain (type), delegate_class);
4030 func = mono_compile_method (info->method);
4032 mono_delegate_ctor (delegate, target, func);
4038 ves_icall_System_Delegate_FreeTrampoline (MonoDelegate *this)
4040 mono_delegate_free_ftnptr (this);
4044 * Magic number to convert a time which is relative to
4045 * Jan 1, 1970 into a value which is relative to Jan 1, 0001.
4047 #define EPOCH_ADJUST ((guint64)62135596800LL)
4050 * Magic number to convert FILETIME base Jan 1, 1601 to DateTime - base Jan, 1, 0001
4052 #define FILETIME_ADJUST ((guint64)504911232000000000LL)
4055 * This returns Now in UTC
4058 ves_icall_System_DateTime_GetNow (void)
4060 #ifdef PLATFORM_WIN32
4064 GetSystemTime (&st);
4065 SystemTimeToFileTime (&st, &ft);
4066 return (gint64) FILETIME_ADJUST + ((((gint64)ft.dwHighDateTime)<<32) | ft.dwLowDateTime);
4068 /* FIXME: put this in io-layer and call it GetLocalTime */
4072 MONO_ARCH_SAVE_REGS;
4074 if (gettimeofday (&tv, NULL) == 0) {
4075 res = (((gint64)tv.tv_sec + EPOCH_ADJUST)* 1000000 + tv.tv_usec)*10;
4078 /* fixme: raise exception */
4083 #ifdef PLATFORM_WIN32
4084 /* convert a SYSTEMTIME which is of the form "last thursday in october" to a real date */
4086 convert_to_absolute_date(SYSTEMTIME *date)
4088 #define IS_LEAP(y) ((y % 4) == 0 && ((y % 100) != 0 || (y % 400) == 0))
4089 static int days_in_month[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
4090 static int leap_days_in_month[] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
4091 /* from the calendar FAQ */
4092 int a = (14 - date->wMonth) / 12;
4093 int y = date->wYear - a;
4094 int m = date->wMonth + 12 * a - 2;
4095 int d = (1 + y + y/4 - y/100 + y/400 + (31*m)/12) % 7;
4097 /* d is now the day of the week for the first of the month (0 == Sunday) */
4099 int day_of_week = date->wDayOfWeek;
4101 /* set day_in_month to the first day in the month which falls on day_of_week */
4102 int day_in_month = 1 + (day_of_week - d);
4103 if (day_in_month <= 0)
4106 /* wDay is 1 for first weekday in month, 2 for 2nd ... 5 means last - so work that out allowing for days in the month */
4107 date->wDay = day_in_month + (date->wDay - 1) * 7;
4108 if (date->wDay > (IS_LEAP(date->wYear) ? leap_days_in_month[date->wMonth - 1] : days_in_month[date->wMonth - 1]))
4113 #ifndef PLATFORM_WIN32
4115 * Return's the offset from GMT of a local time.
4117 * tm is a local time
4118 * t is the same local time as seconds.
4121 gmt_offset(struct tm *tm, time_t t)
4123 #if defined (HAVE_TM_GMTOFF)
4124 return tm->tm_gmtoff;
4129 g.tm_isdst = tm->tm_isdst;
4131 return (int)difftime(t, t2);
4136 * This is heavily based on zdump.c from glibc 2.2.
4138 * * data[0]: start of daylight saving time (in DateTime ticks).
4139 * * data[1]: end of daylight saving time (in DateTime ticks).
4140 * * data[2]: utcoffset (in TimeSpan ticks).
4141 * * data[3]: additional offset when daylight saving (in TimeSpan ticks).
4142 * * name[0]: name of this timezone when not daylight saving.
4143 * * name[1]: name of this timezone when daylight saving.
4145 * FIXME: This only works with "standard" Unix dates (years between 1900 and 2100) while
4146 * the class library allows years between 1 and 9999.
4148 * Returns true on success and zero on failure.
4151 ves_icall_System_CurrentTimeZone_GetTimeZoneData (guint32 year, MonoArray **data, MonoArray **names)
4153 #ifndef PLATFORM_WIN32
4154 MonoDomain *domain = mono_domain_get ();
4155 struct tm start, tt;
4159 int is_daylight = 0, day;
4162 MONO_ARCH_SAVE_REGS;
4164 MONO_CHECK_ARG_NULL (data);
4165 MONO_CHECK_ARG_NULL (names);
4167 (*data) = mono_array_new (domain, mono_defaults.int64_class, 4);
4168 (*names) = mono_array_new (domain, mono_defaults.string_class, 2);
4171 * no info is better than crashing: we'll need our own tz data to make
4172 * this work properly, anyway. The range is reduced to 1970 .. 2037 because
4173 * that is what mktime is guaranteed to support (we get into an infinite loop
4176 if ((year < 1970) || (year > 2037)) {
4178 tt = *localtime (&t);
4179 strftime (tzone, sizeof (tzone), "%Z", &tt);
4180 mono_array_set ((*names), gpointer, 0, mono_string_new (domain, tzone));
4181 mono_array_set ((*names), gpointer, 1, mono_string_new (domain, tzone));
4185 memset (&start, 0, sizeof (start));
4188 start.tm_year = year-1900;
4190 t = mktime (&start);
4191 gmtoff = gmt_offset (&start, t);
4193 /* For each day of the year, calculate the tm_gmtoff. */
4194 for (day = 0; day < 365; day++) {
4197 tt = *localtime (&t);
4199 /* Daylight saving starts or ends here. */
4200 if (gmt_offset (&tt, t) != gmtoff) {
4204 /* Try to find the exact hour when daylight saving starts/ends. */
4208 tt1 = *localtime (&t1);
4209 } while (gmt_offset (&tt1, t1) != gmtoff);
4211 /* Try to find the exact minute when daylight saving starts/ends. */
4214 tt1 = *localtime (&t1);
4215 } while (gmt_offset (&tt1, t1) == gmtoff);
4217 strftime (tzone, sizeof (tzone), "%Z", &tt);
4219 /* Write data, if we're already in daylight saving, we're done. */
4221 mono_array_set ((*names), gpointer, 0, mono_string_new (domain, tzone));
4222 mono_array_set ((*data), gint64, 1, ((gint64)t1 + EPOCH_ADJUST) * 10000000L);
4225 mono_array_set ((*names), gpointer, 1, mono_string_new (domain, tzone));
4226 mono_array_set ((*data), gint64, 0, ((gint64)t1 + EPOCH_ADJUST) * 10000000L);
4230 /* This is only set once when we enter daylight saving. */
4231 mono_array_set ((*data), gint64, 2, (gint64)gmtoff * 10000000L);
4232 mono_array_set ((*data), gint64, 3, (gint64)(gmt_offset (&tt, t) - gmtoff) * 10000000L);
4234 gmtoff = gmt_offset (&tt, t);
4239 strftime (tzone, sizeof (tzone), "%Z", &tt);
4240 mono_array_set ((*names), gpointer, 0, mono_string_new (domain, tzone));
4241 mono_array_set ((*names), gpointer, 1, mono_string_new (domain, tzone));
4242 mono_array_set ((*data), gint64, 0, 0);
4243 mono_array_set ((*data), gint64, 1, 0);
4244 mono_array_set ((*data), gint64, 2, (gint64) gmtoff * 10000000L);
4245 mono_array_set ((*data), gint64, 3, 0);
4250 MonoDomain *domain = mono_domain_get ();
4251 TIME_ZONE_INFORMATION tz_info;
4256 tz_id = GetTimeZoneInformation (&tz_info);
4257 if (tz_id == TIME_ZONE_ID_INVALID)
4260 MONO_CHECK_ARG_NULL (data);
4261 MONO_CHECK_ARG_NULL (names);
4263 (*data) = mono_array_new (domain, mono_defaults.int64_class, 4);
4264 (*names) = mono_array_new (domain, mono_defaults.string_class, 2);
4266 for (i = 0; i < 32; ++i)
4267 if (!tz_info.DaylightName [i])
4269 mono_array_set ((*names), gpointer, 1, mono_string_new_utf16 (domain, tz_info.DaylightName, i));
4270 for (i = 0; i < 32; ++i)
4271 if (!tz_info.StandardName [i])
4273 mono_array_set ((*names), gpointer, 0, mono_string_new_utf16 (domain, tz_info.StandardName, i));
4275 if ((year <= 1601) || (year > 30827)) {
4277 * According to MSDN, the MS time functions can't handle dates outside
4283 /* even if the timezone has no daylight savings it may have Bias (e.g. GMT+13 it seems) */
4284 if (tz_id != TIME_ZONE_ID_UNKNOWN) {
4285 tz_info.StandardDate.wYear = year;
4286 convert_to_absolute_date(&tz_info.StandardDate);
4287 err = SystemTimeToFileTime (&tz_info.StandardDate, &ft);
4289 mono_array_set ((*data), gint64, 1, FILETIME_ADJUST + (((guint64)ft.dwHighDateTime<<32) | ft.dwLowDateTime));
4290 tz_info.DaylightDate.wYear = year;
4291 convert_to_absolute_date(&tz_info.DaylightDate);
4292 err = SystemTimeToFileTime (&tz_info.DaylightDate, &ft);
4294 mono_array_set ((*data), gint64, 0, FILETIME_ADJUST + (((guint64)ft.dwHighDateTime<<32) | ft.dwLowDateTime));
4296 mono_array_set ((*data), gint64, 2, (tz_info.Bias + tz_info.StandardBias) * -600000000LL);
4297 mono_array_set ((*data), gint64, 3, (tz_info.DaylightBias - tz_info.StandardBias) * -600000000LL);
4304 ves_icall_System_Object_obj_address (MonoObject *this)
4306 MONO_ARCH_SAVE_REGS;
4313 static inline gint32
4314 mono_array_get_byte_length (MonoArray *array)
4320 klass = array->obj.vtable->klass;
4322 if (array->bounds == NULL)
4323 length = array->max_length;
4326 for (i = 0; i < klass->rank; ++ i)
4327 length *= array->bounds [i].length;
4330 switch (klass->element_class->byval_arg.type) {
4333 case MONO_TYPE_BOOLEAN:
4337 case MONO_TYPE_CHAR:
4345 return length * sizeof (gpointer);
4356 ves_icall_System_Buffer_ByteLengthInternal (MonoArray *array)
4358 MONO_ARCH_SAVE_REGS;
4360 return mono_array_get_byte_length (array);
4364 ves_icall_System_Buffer_GetByteInternal (MonoArray *array, gint32 idx)
4366 MONO_ARCH_SAVE_REGS;
4368 return mono_array_get (array, gint8, idx);
4372 ves_icall_System_Buffer_SetByteInternal (MonoArray *array, gint32 idx, gint8 value)
4374 MONO_ARCH_SAVE_REGS;
4376 mono_array_set (array, gint8, idx, value);
4380 ves_icall_System_Buffer_BlockCopyInternal (MonoArray *src, gint32 src_offset, MonoArray *dest, gint32 dest_offset, gint32 count)
4382 char *src_buf, *dest_buf;
4384 MONO_ARCH_SAVE_REGS;
4386 /* watch out for integer overflow */
4387 if ((src_offset > mono_array_get_byte_length (src) - count) || (dest_offset > mono_array_get_byte_length (dest) - count))
4390 src_buf = (gint8 *)src->vector + src_offset;
4391 dest_buf = (gint8 *)dest->vector + dest_offset;
4393 memcpy (dest_buf, src_buf, count);
4399 ves_icall_Remoting_RealProxy_GetTransparentProxy (MonoObject *this, MonoString *class_name)
4401 MonoDomain *domain = mono_object_domain (this);
4403 MonoRealProxy *rp = ((MonoRealProxy *)this);
4404 MonoTransparentProxy *tp;
4408 MONO_ARCH_SAVE_REGS;
4410 res = mono_object_new (domain, mono_defaults.transparent_proxy_class);
4411 tp = (MonoTransparentProxy*) res;
4414 type = ((MonoReflectionType *)rp->class_to_proxy)->type;
4415 klass = mono_class_from_mono_type (type);
4417 tp->custom_type_info = (mono_object_isinst (this, mono_defaults.iremotingtypeinfo_class) != NULL);
4418 tp->remote_class = mono_remote_class (domain, class_name, klass);
4419 res->vtable = tp->remote_class->vtable;
4424 static MonoReflectionType *
4425 ves_icall_Remoting_RealProxy_InternalGetProxyType (MonoTransparentProxy *tp)
4427 return mono_type_get_object (mono_object_domain (tp), &tp->remote_class->proxy_class->byval_arg);
4430 /* System.Environment */
4433 ves_icall_System_Environment_get_MachineName (void)
4435 #if defined (PLATFORM_WIN32)
4440 len = MAX_COMPUTERNAME_LENGTH + 1;
4441 buf = g_new (gunichar2, len);
4444 if (GetComputerName (buf, (PDWORD) &len))
4445 result = mono_string_new_utf16 (mono_domain_get (), buf, len);
4454 MONO_ARCH_SAVE_REGS;
4457 buf = g_new (gchar, len);
4460 if (gethostname (buf, len) == 0)
4461 result = mono_string_new (mono_domain_get (), buf);
4469 ves_icall_System_Environment_get_Platform (void)
4471 MONO_ARCH_SAVE_REGS;
4473 #if defined (PLATFORM_WIN32)
4483 ves_icall_System_Environment_get_NewLine (void)
4485 MONO_ARCH_SAVE_REGS;
4487 #if defined (PLATFORM_WIN32)
4488 return mono_string_new (mono_domain_get (), "\r\n");
4490 return mono_string_new (mono_domain_get (), "\n");
4495 ves_icall_System_Environment_GetEnvironmentVariable (MonoString *name)
4500 MONO_ARCH_SAVE_REGS;
4505 utf8_name = mono_string_to_utf8 (name); /* FIXME: this should be ascii */
4506 value = g_getenv (utf8_name);
4512 return mono_string_new (mono_domain_get (), value);
4516 * There is no standard way to get at environ.
4524 ves_icall_System_Environment_GetEnvironmentVariableNames (void)
4532 MONO_ARCH_SAVE_REGS;
4535 for (e = environ; *e != 0; ++ e)
4538 domain = mono_domain_get ();
4539 names = mono_array_new (domain, mono_defaults.string_class, n);
4542 for (e = environ; *e != 0; ++ e) {
4543 parts = g_strsplit (*e, "=", 2);
4545 str = mono_string_new (domain, *parts);
4546 mono_array_set (names, MonoString *, n, str);
4558 * Returns the number of milliseconds elapsed since the system started.
4561 ves_icall_System_Environment_get_TickCount (void)
4563 #if defined (PLATFORM_WIN32)
4564 return GetTickCount();
4570 MONO_ARCH_SAVE_REGS;
4572 res = (gint32) gettimeofday (&tv, &tz);
4575 res = (gint32) ((tv.tv_sec & 0xFFFFF) * 1000 + (tv.tv_usec / 1000));
4582 ves_icall_System_Environment_Exit (int result)
4584 MONO_ARCH_SAVE_REGS;
4586 mono_runtime_quit ();
4588 /* we may need to do some cleanup here... */
4593 ves_icall_System_Environment_GetGacPath (void)
4595 return mono_string_new (mono_domain_get (), mono_assembly_getrootdir ());
4599 ves_icall_System_Environment_GetWindowsFolderPath (int folder)
4601 #if defined (PLATFORM_WIN32)
4602 #ifndef CSIDL_FLAG_CREATE
4603 #define CSIDL_FLAG_CREATE 0x8000
4606 WCHAR path [MAX_PATH];
4607 /* Create directory if no existing */
4608 if (SUCCEEDED (SHGetFolderPathW (NULL, folder | CSIDL_FLAG_CREATE, NULL, 0, path))) {
4612 return mono_string_new_utf16 (mono_domain_get (), path, len);
4615 g_warning ("ves_icall_System_Environment_GetWindowsFolderPath should only be called on Windows!");
4617 return mono_string_new (mono_domain_get (), "");
4621 ves_icall_System_Environment_GetLogicalDrives (void)
4623 gunichar2 buf [128], *ptr, *dname;
4625 gint initial_size = 127, size = 128;
4628 MonoString *drivestr;
4629 MonoDomain *domain = mono_domain_get ();
4631 MONO_ARCH_SAVE_REGS;
4636 while (size > initial_size) {
4637 size = GetLogicalDriveStrings (initial_size, ptr);
4638 if (size > initial_size) {
4641 ptr = g_malloc0 ((size + 1) * sizeof (gunichar2));
4642 initial_size = size;
4656 result = mono_array_new (domain, mono_defaults.string_class, ndrives);
4659 u8 = g_utf16_to_utf8 (dname, -1, NULL, NULL, NULL);
4660 drivestr = mono_string_new (domain, u8);
4662 mono_array_set (result, gpointer, ndrives++, drivestr);
4673 ves_icall_System_Environment_InternalGetHome (void)
4675 MONO_ARCH_SAVE_REGS;
4677 return mono_string_new (mono_domain_get (), g_get_home_dir ());
4680 static const char *encodings [] = {
4682 "ascii", "us_ascii", "us", "ansi_x3.4_1968",
4683 "ansi_x3.4_1986", "cp367", "csascii", "ibm367",
4684 "iso_ir_6", "iso646_us", "iso_646.irv:1991",
4686 "utf_7", "csunicode11utf7", "unicode_1_1_utf_7",
4687 "unicode_2_0_utf_7", "x_unicode_1_1_utf_7",
4688 "x_unicode_2_0_utf_7",
4690 "utf_8", "unicode_1_1_utf_8", "unicode_2_0_utf_8",
4691 "x_unicode_1_1_utf_8", "x_unicode_2_0_utf_8",
4693 "utf_16", "UTF_16LE", "ucs_2", "unicode",
4696 "unicodefffe", "utf_16be",
4703 * Returns the internal codepage, if the value of "int_code_page" is
4704 * 1 at entry, and we can not compute a suitable code page number,
4705 * returns the code page as a string
4708 ves_icall_System_Text_Encoding_InternalCodePage (gint32 *int_code_page)
4713 char *codepage = NULL;
4715 int want_name = *int_code_page;
4718 *int_code_page = -1;
4719 MONO_ARCH_SAVE_REGS;
4721 g_get_charset (&cset);
4722 c = codepage = strdup (cset);
4723 for (c = codepage; *c; c++){
4724 if (isascii (*c) && isalpha (*c))
4729 /* g_print ("charset: %s\n", cset); */
4731 /* handle some common aliases */
4734 for (i = 0; p != 0; ){
4737 p = encodings [++i];
4740 if (strcmp (p, codepage) == 0){
4741 *int_code_page = code;
4744 p = encodings [++i];
4747 if (strstr (codepage, "utf_8") != NULL)
4748 *int_code_page |= 0x10000000;
4751 if (want_name && *int_code_page == -1)
4752 return mono_string_new (mono_domain_get (), cset);
4758 ves_icall_System_Environment_get_HasShutdownStarted (void)
4760 if (mono_runtime_is_shutting_down ())
4763 if (mono_domain_is_unloading (mono_domain_get ()))
4770 ves_icall_MonoMethodMessage_InitMessage (MonoMethodMessage *this,
4771 MonoReflectionMethod *method,
4772 MonoArray *out_args)
4774 MONO_ARCH_SAVE_REGS;
4776 mono_message_init (mono_object_domain (this), this, method, out_args);
4780 ves_icall_IsTransparentProxy (MonoObject *proxy)
4782 MONO_ARCH_SAVE_REGS;
4787 if (proxy->vtable->klass == mono_defaults.transparent_proxy_class)
4794 ves_icall_System_Runtime_Activation_ActivationServices_EnableProxyActivation (MonoReflectionType *type, MonoBoolean enable)
4799 MONO_ARCH_SAVE_REGS;
4801 klass = mono_class_from_mono_type (type->type);
4802 vtable = mono_class_vtable (mono_domain_get (), klass);
4804 if (enable) vtable->remote = 1;
4805 else vtable->remote = 0;
4809 ves_icall_System_Runtime_Activation_ActivationServices_AllocateUninitializedClassInstance (MonoReflectionType *type)
4814 MONO_ARCH_SAVE_REGS;
4816 domain = mono_object_domain (type);
4817 klass = mono_class_from_mono_type (type->type);
4819 if (klass->rank >= 1) {
4820 g_assert (klass->rank == 1);
4821 return (MonoObject *) mono_array_new (domain, klass->element_class, 0);
4823 /* Bypass remoting object creation check */
4824 return mono_object_new_alloc_specific (mono_class_vtable (domain, klass));
4829 ves_icall_System_IO_get_temp_path (void)
4831 MONO_ARCH_SAVE_REGS;
4833 return mono_string_new (mono_domain_get (), g_get_tmp_dir ());
4837 ves_icall_RuntimeMethod_GetFunctionPointer (MonoMethod *method)
4839 MONO_ARCH_SAVE_REGS;
4841 return mono_compile_method (method);
4845 ves_icall_System_Configuration_DefaultConfig_get_machine_config_path (void)
4850 MONO_ARCH_SAVE_REGS;
4852 path = g_build_path (G_DIR_SEPARATOR_S, mono_get_config_dir (), "mono", mono_get_framework_version (), "machine.config", NULL);
4854 #if defined (PLATFORM_WIN32)
4855 /* Avoid mixing '/' and '\\' */
4858 for (i = strlen (path) - 1; i >= 0; i--)
4859 if (path [i] == '/')
4863 mcpath = mono_string_new (mono_domain_get (), path);
4870 ves_icall_System_Web_Util_ICalls_get_machine_install_dir (void)
4875 MONO_ARCH_SAVE_REGS;
4877 path = g_path_get_dirname (mono_get_config_dir ());
4879 #if defined (PLATFORM_WIN32)
4880 /* Avoid mixing '/' and '\\' */
4883 for (i = strlen (path) - 1; i >= 0; i--)
4884 if (path [i] == '/')
4888 ipath = mono_string_new (mono_domain_get (), path);
4895 ves_icall_System_Diagnostics_DefaultTraceListener_WriteWindowsDebugString (MonoString *message)
4897 #if defined (PLATFORM_WIN32)
4898 static void (*output_debug) (gchar *);
4899 static gboolean tried_loading = FALSE;
4901 MONO_ARCH_SAVE_REGS;
4903 if (!tried_loading && output_debug == NULL) {
4906 tried_loading = TRUE;
4907 k32 = g_module_open ("kernel32", G_MODULE_BIND_LAZY);
4909 gchar *error = g_strdup (g_module_error ());
4910 g_warning ("Failed to load kernel32.dll: %s\n", error);
4915 g_module_symbol (k32, "OutputDebugStringW", (gpointer *) &output_debug);
4916 if (!output_debug) {
4917 gchar *error = g_strdup (g_module_error ());
4918 g_warning ("Failed to load OutputDebugStringW: %s\n", error);
4924 if (output_debug == NULL)
4927 output_debug (mono_string_chars (message));
4929 g_warning ("WriteWindowsDebugString called and PLATFORM_WIN32 not defined!\n");
4933 /* Only used for value types */
4935 ves_icall_System_Activator_CreateInstanceInternal (MonoReflectionType *type)
4940 MONO_ARCH_SAVE_REGS;
4942 domain = mono_object_domain (type);
4943 klass = mono_class_from_mono_type (type->type);
4945 return mono_object_new (domain, klass);
4948 static MonoReflectionMethod *
4949 ves_icall_MonoMethod_get_base_definition (MonoReflectionMethod *m)
4952 MonoMethod *method = m->method;
4953 MonoMethod *result = NULL;
4955 MONO_ARCH_SAVE_REGS;
4957 if (!(method->flags & METHOD_ATTRIBUTE_VIRTUAL) ||
4958 MONO_CLASS_IS_INTERFACE (method->klass) ||
4959 method->flags & METHOD_ATTRIBUTE_NEW_SLOT)
4962 if (method->klass == NULL || (klass = method->klass->parent) == NULL)
4965 if (klass->generic_inst)
4966 klass = mono_class_from_mono_type (klass->generic_inst->generic_type);
4968 while (result == NULL && klass != NULL && (klass->vtable_size > method->slot))
4970 result = klass->vtable [method->slot];
4971 if (result == NULL) {
4972 /* It is an abstract method */
4974 for (i=0; i<klass->method.count; i++) {
4975 if (klass->methods [i]->slot == method->slot) {
4976 result = klass->methods [i];
4981 klass = klass->parent;
4987 return mono_method_get_object (mono_domain_get (), result, NULL);
4991 mono_ArgIterator_Setup (MonoArgIterator *iter, char* argsp, char* start)
4993 MONO_ARCH_SAVE_REGS;
4995 iter->sig = *(MonoMethodSignature**)argsp;
4997 g_assert (iter->sig->sentinelpos <= iter->sig->param_count);
4998 g_assert (iter->sig->call_convention == MONO_CALL_VARARG);
5001 /* FIXME: it's not documented what start is exactly... */
5005 int i, align, arg_size;
5006 iter->args = argsp + sizeof (gpointer);
5007 for (i = 0; i < iter->sig->sentinelpos; ++i) {
5008 arg_size = mono_type_stack_size (iter->sig->params [i], &align);
5009 iter->args = (char*)iter->args + arg_size;
5012 iter->num_args = iter->sig->param_count - iter->sig->sentinelpos;
5014 /* g_print ("sig %p, param_count: %d, sent: %d\n", iter->sig, iter->sig->param_count, iter->sig->sentinelpos); */
5018 mono_ArgIterator_IntGetNextArg (MonoArgIterator *iter)
5020 gint i, align, arg_size;
5022 MONO_ARCH_SAVE_REGS;
5024 i = iter->sig->sentinelpos + iter->next_arg;
5026 g_assert (i < iter->sig->param_count);
5028 res.type = iter->sig->params [i];
5029 res.klass = mono_class_from_mono_type (res.type);
5030 /* FIXME: endianess issue... */
5031 res.value = iter->args;
5032 arg_size = mono_type_stack_size (res.type, &align);
5033 iter->args = (char*)iter->args + arg_size;
5036 /* g_print ("returning arg %d, type 0x%02x of size %d at %p\n", i, res.type->type, arg_size, res.value); */
5042 mono_ArgIterator_IntGetNextArgT (MonoArgIterator *iter, MonoType *type)
5044 gint i, align, arg_size;
5046 MONO_ARCH_SAVE_REGS;
5048 i = iter->sig->sentinelpos + iter->next_arg;
5050 g_assert (i < iter->sig->param_count);
5052 while (i < iter->sig->param_count) {
5053 if (!mono_metadata_type_equal (type, iter->sig->params [i]))
5055 res.type = iter->sig->params [i];
5056 res.klass = mono_class_from_mono_type (res.type);
5057 /* FIXME: endianess issue... */
5058 res.value = iter->args;
5059 arg_size = mono_type_stack_size (res.type, &align);
5060 iter->args = (char*)iter->args + arg_size;
5062 /* g_print ("returning arg %d, type 0x%02x of size %d at %p\n", i, res.type->type, arg_size, res.value); */
5065 /* g_print ("arg type 0x%02x not found\n", res.type->type); */
5074 mono_ArgIterator_IntGetNextArgType (MonoArgIterator *iter)
5077 MONO_ARCH_SAVE_REGS;
5079 i = iter->sig->sentinelpos + iter->next_arg;
5081 g_assert (i < iter->sig->param_count);
5083 return iter->sig->params [i];
5087 mono_TypedReference_ToObject (MonoTypedRef tref)
5089 MONO_ARCH_SAVE_REGS;
5091 if (MONO_TYPE_IS_REFERENCE (tref.type)) {
5092 MonoObject** objp = tref.value;
5096 return mono_value_box (mono_domain_get (), tref.klass, tref.value);
5100 prelink_method (MonoMethod *method)
5102 const char *exc_class, *exc_arg;
5103 if (!(method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL))
5105 mono_lookup_pinvoke_call (method, &exc_class, &exc_arg);
5107 mono_raise_exception(
5108 mono_exception_from_name_msg (mono_defaults.corlib, "System", exc_class, exc_arg ) );
5110 /* create the wrapper, too? */
5114 ves_icall_System_Runtime_InteropServices_Marshal_Prelink (MonoReflectionMethod *method)
5116 MONO_ARCH_SAVE_REGS;
5117 prelink_method (method->method);
5121 ves_icall_System_Runtime_InteropServices_Marshal_PrelinkAll (MonoReflectionType *type)
5123 MonoClass *klass = mono_class_from_mono_type (type->type);
5125 MONO_ARCH_SAVE_REGS;
5127 mono_class_init (klass);
5128 for (i = 0; i < klass->method.count; ++i)
5129 prelink_method (klass->methods [i]);
5132 /* These parameters are "readonly" in corlib/System/Char.cs */
5134 ves_icall_System_Char_GetDataTablePointers (guint8 const **category_data,
5135 guint8 const **numeric_data,
5136 gdouble const **numeric_data_values,
5137 guint16 const **to_lower_data_low,
5138 guint16 const **to_lower_data_high,
5139 guint16 const **to_upper_data_low,
5140 guint16 const **to_upper_data_high)
5142 *category_data = CategoryData;
5143 *numeric_data = NumericData;
5144 *numeric_data_values = NumericDataValues;
5145 *to_lower_data_low = ToLowerDataLow;
5146 *to_lower_data_high = ToLowerDataHigh;
5147 *to_upper_data_low = ToUpperDataLow;
5148 *to_upper_data_high = ToUpperDataHigh;
5159 const IcallEntry *icalls;
5163 static const IcallEntry activator_icalls [] = {
5164 {"CreateInstanceInternal", ves_icall_System_Activator_CreateInstanceInternal}
5166 static const IcallEntry appdomain_icalls [] = {
5167 {"ExecuteAssembly", ves_icall_System_AppDomain_ExecuteAssembly},
5168 {"GetAssemblies", ves_icall_System_AppDomain_GetAssemblies},
5169 {"GetData", ves_icall_System_AppDomain_GetData},
5170 {"InternalGetContext", ves_icall_System_AppDomain_InternalGetContext},
5171 {"InternalGetDefaultContext", ves_icall_System_AppDomain_InternalGetDefaultContext},
5172 {"InternalGetProcessGuid", ves_icall_System_AppDomain_InternalGetProcessGuid},
5173 {"InternalIsFinalizingForUnload", ves_icall_System_AppDomain_InternalIsFinalizingForUnload},
5174 {"InternalPopDomainRef", ves_icall_System_AppDomain_InternalPopDomainRef},
5175 {"InternalPushDomainRef", ves_icall_System_AppDomain_InternalPushDomainRef},
5176 {"InternalPushDomainRefByID", ves_icall_System_AppDomain_InternalPushDomainRefByID},
5177 {"InternalSetContext", ves_icall_System_AppDomain_InternalSetContext},
5178 {"InternalSetDomain", ves_icall_System_AppDomain_InternalSetDomain},
5179 {"InternalSetDomainByID", ves_icall_System_AppDomain_InternalSetDomainByID},
5180 {"InternalUnload", ves_icall_System_AppDomain_InternalUnload},
5181 {"LoadAssembly", ves_icall_System_AppDomain_LoadAssembly},
5182 {"LoadAssemblyRaw", ves_icall_System_AppDomain_LoadAssemblyRaw},
5183 {"SetData", ves_icall_System_AppDomain_SetData},
5184 {"createDomain", ves_icall_System_AppDomain_createDomain},
5185 {"getCurDomain", ves_icall_System_AppDomain_getCurDomain},
5186 {"getDomainByID", ves_icall_System_AppDomain_getDomainByID},
5187 {"getFriendlyName", ves_icall_System_AppDomain_getFriendlyName},
5188 {"getSetup", ves_icall_System_AppDomain_getSetup}
5191 static const IcallEntry argiterator_icalls [] = {
5192 {"IntGetNextArg()", mono_ArgIterator_IntGetNextArg},
5193 {"IntGetNextArg(intptr)", mono_ArgIterator_IntGetNextArgT},
5194 {"IntGetNextArgType", mono_ArgIterator_IntGetNextArgType},
5195 {"Setup", mono_ArgIterator_Setup}
5198 static const IcallEntry array_icalls [] = {
5199 {"ClearInternal", ves_icall_System_Array_ClearInternal},
5200 {"Clone", mono_array_clone},
5201 {"CreateInstanceImpl", ves_icall_System_Array_CreateInstanceImpl},
5202 {"FastCopy", ves_icall_System_Array_FastCopy},
5203 {"GetLength", ves_icall_System_Array_GetLength},
5204 {"GetLowerBound", ves_icall_System_Array_GetLowerBound},
5205 {"GetRank", ves_icall_System_Array_GetRank},
5206 {"GetValue", ves_icall_System_Array_GetValue},
5207 {"GetValueImpl", ves_icall_System_Array_GetValueImpl},
5208 {"SetValue", ves_icall_System_Array_SetValue},
5209 {"SetValueImpl", ves_icall_System_Array_SetValueImpl}
5212 static const IcallEntry buffer_icalls [] = {
5213 {"BlockCopyInternal", ves_icall_System_Buffer_BlockCopyInternal},
5214 {"ByteLengthInternal", ves_icall_System_Buffer_ByteLengthInternal},
5215 {"GetByteInternal", ves_icall_System_Buffer_GetByteInternal},
5216 {"SetByteInternal", ves_icall_System_Buffer_SetByteInternal}
5219 static const IcallEntry char_icalls [] = {
5220 {"GetDataTablePointers", ves_icall_System_Char_GetDataTablePointers},
5221 {"InternalToLower(char,System.Globalization.CultureInfo)", ves_icall_System_Char_InternalToLower_Comp},
5222 {"InternalToUpper(char,System.Globalization.CultureInfo)", ves_icall_System_Char_InternalToUpper_Comp}
5225 static const IcallEntry defaultconf_icalls [] = {
5226 {"get_machine_config_path", ves_icall_System_Configuration_DefaultConfig_get_machine_config_path}
5229 static const IcallEntry timezone_icalls [] = {
5230 {"GetTimeZoneData", ves_icall_System_CurrentTimeZone_GetTimeZoneData}
5233 static const IcallEntry datetime_icalls [] = {
5234 {"GetNow", ves_icall_System_DateTime_GetNow}
5237 static const IcallEntry decimal_icalls [] = {
5238 {"decimal2Int64", mono_decimal2Int64},
5239 {"decimal2UInt64", mono_decimal2UInt64},
5240 {"decimal2double", mono_decimal2double},
5241 {"decimal2string", mono_decimal2string},
5242 {"decimalCompare", mono_decimalCompare},
5243 {"decimalDiv", mono_decimalDiv},
5244 {"decimalFloorAndTrunc", mono_decimalFloorAndTrunc},
5245 {"decimalIncr", mono_decimalIncr},
5246 {"decimalIntDiv", mono_decimalIntDiv},
5247 {"decimalMult", mono_decimalMult},
5248 {"decimalRound", mono_decimalRound},
5249 {"decimalSetExponent", mono_decimalSetExponent},
5250 {"double2decimal", mono_double2decimal}, /* FIXME: wrong signature. */
5251 {"string2decimal", mono_string2decimal}
5254 static const IcallEntry delegate_icalls [] = {
5255 {"CreateDelegate_internal", ves_icall_System_Delegate_CreateDelegate_internal},
5256 {"FreeTrampoline", ves_icall_System_Delegate_FreeTrampoline}
5259 static const IcallEntry tracelist_icalls [] = {
5260 {"WriteWindowsDebugString", ves_icall_System_Diagnostics_DefaultTraceListener_WriteWindowsDebugString}
5263 static const IcallEntry fileversion_icalls [] = {
5264 {"GetVersionInfo_internal(string)", ves_icall_System_Diagnostics_FileVersionInfo_GetVersionInfo_internal}
5267 static const IcallEntry process_icalls [] = {
5268 {"ExitCode_internal(intptr)", ves_icall_System_Diagnostics_Process_ExitCode_internal},
5269 {"ExitTime_internal(intptr)", ves_icall_System_Diagnostics_Process_ExitTime_internal},
5270 {"GetModules_internal()", ves_icall_System_Diagnostics_Process_GetModules_internal},
5271 {"GetPid_internal()", ves_icall_System_Diagnostics_Process_GetPid_internal},
5272 {"GetProcess_internal(int)", ves_icall_System_Diagnostics_Process_GetProcess_internal},
5273 {"GetProcesses_internal()", ves_icall_System_Diagnostics_Process_GetProcesses_internal},
5274 {"GetWorkingSet_internal(intptr,int&,int&)", ves_icall_System_Diagnostics_Process_GetWorkingSet_internal},
5275 {"Kill_internal", ves_icall_System_Diagnostics_Process_Kill_internal},
5276 {"ProcessName_internal(intptr)", ves_icall_System_Diagnostics_Process_ProcessName_internal},
5277 {"Process_free_internal(intptr)", ves_icall_System_Diagnostics_Process_Process_free_internal},
5278 {"SetWorkingSet_internal(intptr,int,int,bool)", ves_icall_System_Diagnostics_Process_SetWorkingSet_internal},
5279 {"StartTime_internal(intptr)", ves_icall_System_Diagnostics_Process_StartTime_internal},
5280 {"Start_internal(string,string,string,intptr,intptr,intptr,System.Diagnostics.Process/ProcInfo&)", ves_icall_System_Diagnostics_Process_Start_internal},
5281 {"WaitForExit_internal(intptr,int)", ves_icall_System_Diagnostics_Process_WaitForExit_internal}
5284 static const IcallEntry double_icalls [] = {
5285 {"AssertEndianity", ves_icall_System_Double_AssertEndianity},
5286 {"ParseImpl", mono_double_ParseImpl}
5289 static const IcallEntry enum_icalls [] = {
5290 {"ToObject", ves_icall_System_Enum_ToObject},
5291 {"get_value", ves_icall_System_Enum_get_value}
5294 static const IcallEntry environment_icalls [] = {
5295 {"Exit", ves_icall_System_Environment_Exit},
5296 {"GetCommandLineArgs", mono_runtime_get_main_args},
5297 {"GetEnvironmentVariable", ves_icall_System_Environment_GetEnvironmentVariable},
5298 {"GetEnvironmentVariableNames", ves_icall_System_Environment_GetEnvironmentVariableNames},
5299 {"GetLogicalDrivesInternal", ves_icall_System_Environment_GetLogicalDrives },
5300 {"GetMachineConfigPath", ves_icall_System_Configuration_DefaultConfig_get_machine_config_path},
5301 {"GetOSVersionString", ves_icall_System_Environment_GetOSVersionString},
5302 {"GetWindowsFolderPath", ves_icall_System_Environment_GetWindowsFolderPath},
5303 {"get_ExitCode", mono_environment_exitcode_get},
5304 {"get_HasShutdownStarted", ves_icall_System_Environment_get_HasShutdownStarted},
5305 {"get_MachineName", ves_icall_System_Environment_get_MachineName},
5306 {"get_NewLine", ves_icall_System_Environment_get_NewLine},
5307 {"get_Platform", ves_icall_System_Environment_get_Platform},
5308 {"get_TickCount", ves_icall_System_Environment_get_TickCount},
5309 {"get_UserName", ves_icall_System_Environment_get_UserName},
5310 {"internalGetGacPath", ves_icall_System_Environment_GetGacPath},
5311 {"internalGetHome", ves_icall_System_Environment_InternalGetHome},
5312 {"set_ExitCode", mono_environment_exitcode_set}
5315 static const IcallEntry cultureinfo_icalls [] = {
5316 {"construct_compareinfo(object,string)", ves_icall_System_Globalization_CompareInfo_construct_compareinfo},
5317 {"construct_datetime_format", ves_icall_System_Globalization_CultureInfo_construct_datetime_format},
5318 {"construct_internal_locale(string)", ves_icall_System_Globalization_CultureInfo_construct_internal_locale},
5319 {"construct_internal_locale_from_current_locale", ves_icall_System_Globalization_CultureInfo_construct_internal_locale_from_current_locale},
5320 {"construct_internal_locale_from_lcid", ves_icall_System_Globalization_CultureInfo_construct_internal_locale_from_lcid},
5321 {"construct_internal_locale_from_name", ves_icall_System_Globalization_CultureInfo_construct_internal_locale_from_name},
5322 {"construct_internal_locale_from_specific_name", ves_icall_System_Globalization_CultureInfo_construct_internal_locale_from_specific_name},
5323 {"construct_number_format", ves_icall_System_Globalization_CultureInfo_construct_number_format},
5324 {"internal_get_cultures", ves_icall_System_Globalization_CultureInfo_internal_get_cultures},
5325 {"internal_is_lcid_neutral", ves_icall_System_Globalization_CultureInfo_internal_is_lcid_neutral}
5328 static const IcallEntry compareinfo_icalls [] = {
5329 {"assign_sortkey(object,string,System.Globalization.CompareOptions)", ves_icall_System_Globalization_CompareInfo_assign_sortkey},
5330 {"construct_compareinfo(string)", ves_icall_System_Globalization_CompareInfo_construct_compareinfo},
5331 {"free_internal_collator()", ves_icall_System_Globalization_CompareInfo_free_internal_collator},
5332 {"internal_compare(string,int,int,string,int,int,System.Globalization.CompareOptions)", ves_icall_System_Globalization_CompareInfo_internal_compare},
5333 {"internal_index(string,int,int,char,System.Globalization.CompareOptions,bool)", ves_icall_System_Globalization_CompareInfo_internal_index_char},
5334 {"internal_index(string,int,int,string,System.Globalization.CompareOptions,bool)", ves_icall_System_Globalization_CompareInfo_internal_index}
5337 static const IcallEntry gc_icalls [] = {
5338 {"GetTotalMemory", ves_icall_System_GC_GetTotalMemory},
5339 {"InternalCollect", ves_icall_System_GC_InternalCollect},
5340 {"KeepAlive", ves_icall_System_GC_KeepAlive},
5341 {"ReRegisterForFinalize", ves_icall_System_GC_ReRegisterForFinalize},
5342 {"SuppressFinalize", ves_icall_System_GC_SuppressFinalize},
5343 {"WaitForPendingFinalizers", ves_icall_System_GC_WaitForPendingFinalizers}
5346 static const IcallEntry famwatcher_icalls [] = {
5347 {"InternalFAMNextEvent", ves_icall_System_IO_FAMW_InternalFAMNextEvent}
5350 static const IcallEntry filewatcher_icalls [] = {
5351 {"InternalCloseDirectory", ves_icall_System_IO_FSW_CloseDirectory},
5352 {"InternalOpenDirectory", ves_icall_System_IO_FSW_OpenDirectory},
5353 {"InternalReadDirectoryChanges", ves_icall_System_IO_FSW_ReadDirectoryChanges},
5354 {"InternalSupportsFSW", ves_icall_System_IO_FSW_SupportsFSW}
5357 static const IcallEntry path_icalls [] = {
5358 {"get_temp_path", ves_icall_System_IO_get_temp_path}
5361 static const IcallEntry monoio_icalls [] = {
5362 {"BeginRead", ves_icall_System_IO_MonoIO_BeginRead },
5363 {"BeginWrite", ves_icall_System_IO_MonoIO_BeginWrite },
5364 {"Close(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Close},
5365 {"CopyFile(string,string,bool,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_CopyFile},
5366 {"CreateDirectory(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_CreateDirectory},
5367 {"CreatePipe(intptr&,intptr&)", ves_icall_System_IO_MonoIO_CreatePipe},
5368 {"DeleteFile(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_DeleteFile},
5369 {"FindClose(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_FindClose},
5370 {"FindFirstFile(string,System.IO.MonoIOStat&,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_FindFirstFile},
5371 {"FindNextFile(intptr,System.IO.MonoIOStat&,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_FindNextFile},
5372 {"Flush(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Flush},
5373 {"GetCurrentDirectory(System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetCurrentDirectory},
5374 {"GetFileAttributes(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetFileAttributes},
5375 {"GetFileStat(string,System.IO.MonoIOStat&,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetFileStat},
5376 {"GetFileType(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetFileType},
5377 {"GetLength(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetLength},
5378 {"GetSupportsAsync", ves_icall_System_IO_MonoIO_GetSupportsAsync},
5379 {"GetTempPath(string&)", ves_icall_System_IO_MonoIO_GetTempPath},
5380 {"Lock(intptr,long,long,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Lock},
5381 {"MoveFile(string,string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_MoveFile},
5382 {"Open(string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare,bool,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Open},
5383 {"Read(intptr,byte[],int,int,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Read},
5384 {"RemoveDirectory(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_RemoveDirectory},
5385 {"Seek(intptr,long,System.IO.SeekOrigin,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Seek},
5386 {"SetCurrentDirectory(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_SetCurrentDirectory},
5387 {"SetFileAttributes(string,System.IO.FileAttributes,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_SetFileAttributes},
5388 {"SetFileTime(intptr,long,long,long,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_SetFileTime},
5389 {"SetLength(intptr,long,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_SetLength},
5390 {"Unlock(intptr,long,long,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Unlock},
5391 {"Write(intptr,byte[],int,int,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Write},
5392 {"get_AltDirectorySeparatorChar", ves_icall_System_IO_MonoIO_get_AltDirectorySeparatorChar},
5393 {"get_ConsoleError", ves_icall_System_IO_MonoIO_get_ConsoleError},
5394 {"get_ConsoleInput", ves_icall_System_IO_MonoIO_get_ConsoleInput},
5395 {"get_ConsoleOutput", ves_icall_System_IO_MonoIO_get_ConsoleOutput},
5396 {"get_DirectorySeparatorChar", ves_icall_System_IO_MonoIO_get_DirectorySeparatorChar},
5397 {"get_InvalidPathChars", ves_icall_System_IO_MonoIO_get_InvalidPathChars},
5398 {"get_PathSeparator", ves_icall_System_IO_MonoIO_get_PathSeparator},
5399 {"get_VolumeSeparatorChar", ves_icall_System_IO_MonoIO_get_VolumeSeparatorChar}
5402 static const IcallEntry math_icalls [] = {
5403 {"Acos", ves_icall_System_Math_Acos},
5404 {"Asin", ves_icall_System_Math_Asin},
5405 {"Atan", ves_icall_System_Math_Atan},
5406 {"Atan2", ves_icall_System_Math_Atan2},
5407 {"Cos", ves_icall_System_Math_Cos},
5408 {"Cosh", ves_icall_System_Math_Cosh},
5409 {"Exp", ves_icall_System_Math_Exp},
5410 {"Floor", ves_icall_System_Math_Floor},
5411 {"Log", ves_icall_System_Math_Log},
5412 {"Log10", ves_icall_System_Math_Log10},
5413 {"Pow", ves_icall_System_Math_Pow},
5414 {"Round", ves_icall_System_Math_Round},
5415 {"Round2", ves_icall_System_Math_Round2},
5416 {"Sin", ves_icall_System_Math_Sin},
5417 {"Sinh", ves_icall_System_Math_Sinh},
5418 {"Sqrt", ves_icall_System_Math_Sqrt},
5419 {"Tan", ves_icall_System_Math_Tan},
5420 {"Tanh", ves_icall_System_Math_Tanh}
5423 static const IcallEntry customattrs_icalls [] = {
5424 {"GetCustomAttributes", mono_reflection_get_custom_attrs}
5427 static const IcallEntry enuminfo_icalls [] = {
5428 {"get_enum_info", ves_icall_get_enum_info}
5431 static const IcallEntry fieldinfo_icalls [] = {
5432 {"internal_from_handle", ves_icall_System_Reflection_FieldInfo_internal_from_handle}
5435 static const IcallEntry monotype_icalls [] = {
5436 {"GetArrayRank", ves_icall_MonoType_GetArrayRank},
5437 {"GetConstructors", ves_icall_Type_GetConstructors_internal},
5438 {"GetConstructors_internal", ves_icall_Type_GetConstructors_internal},
5439 {"GetElementType", ves_icall_MonoType_GetElementType},
5440 {"GetEvents_internal", ves_icall_Type_GetEvents_internal},
5441 {"GetField", ves_icall_Type_GetField},
5442 {"GetFields_internal", ves_icall_Type_GetFields_internal},
5443 {"GetGenericArguments", ves_icall_MonoType_GetGenericArguments},
5444 {"GetInterfaces", ves_icall_Type_GetInterfaces},
5445 {"GetMethodsByName", ves_icall_Type_GetMethodsByName},
5446 {"GetNestedType", ves_icall_Type_GetNestedType},
5447 {"GetNestedTypes", ves_icall_Type_GetNestedTypes},
5448 {"GetPropertiesByName", ves_icall_Type_GetPropertiesByName},
5449 {"InternalGetEvent", ves_icall_MonoType_GetEvent},
5450 {"IsByRefImpl", ves_icall_type_isbyref},
5451 {"IsPointerImpl", ves_icall_type_ispointer},
5452 {"IsPrimitiveImpl", ves_icall_type_isprimitive},
5453 {"getFullName", ves_icall_System_MonoType_getFullName},
5454 {"get_Assembly", ves_icall_MonoType_get_Assembly},
5455 {"get_BaseType", ves_icall_get_type_parent},
5456 {"get_DeclaringMethod", ves_icall_MonoType_get_DeclaringMethod},
5457 {"get_DeclaringType", ves_icall_MonoType_get_DeclaringType},
5458 {"get_HasGenericArguments", ves_icall_MonoType_get_HasGenericArguments},
5459 {"get_IsGenericParameter", ves_icall_MonoType_get_IsGenericParameter},
5460 {"get_Module", ves_icall_MonoType_get_Module},
5461 {"get_Name", ves_icall_MonoType_get_Name},
5462 {"get_Namespace", ves_icall_MonoType_get_Namespace},
5463 {"get_UnderlyingSystemType", ves_icall_MonoType_get_UnderlyingSystemType},
5464 {"get_attributes", ves_icall_get_attributes},
5465 {"type_from_obj", mono_type_type_from_obj}
5468 static const IcallEntry assembly_icalls [] = {
5469 {"FillName", ves_icall_System_Reflection_Assembly_FillName},
5470 {"GetCallingAssembly", ves_icall_System_Reflection_Assembly_GetCallingAssembly},
5471 {"GetEntryAssembly", ves_icall_System_Reflection_Assembly_GetEntryAssembly},
5472 {"GetExecutingAssembly", ves_icall_System_Reflection_Assembly_GetExecutingAssembly},
5473 {"GetFilesInternal", ves_icall_System_Reflection_Assembly_GetFilesInternal},
5474 {"GetManifestResourceInfoInternal", ves_icall_System_Reflection_Assembly_GetManifestResourceInfoInternal},
5475 {"GetManifestResourceInternal", ves_icall_System_Reflection_Assembly_GetManifestResourceInternal},
5476 {"GetManifestResourceNames", ves_icall_System_Reflection_Assembly_GetManifestResourceNames},
5477 {"GetModulesInternal", ves_icall_System_Reflection_Assembly_GetModulesInternal},
5478 {"GetNamespaces", ves_icall_System_Reflection_Assembly_GetNamespaces},
5479 {"GetReferencedAssemblies", ves_icall_System_Reflection_Assembly_GetReferencedAssemblies},
5480 {"GetTypes", ves_icall_System_Reflection_Assembly_GetTypes},
5481 {"InternalGetAssemblyName", ves_icall_System_Reflection_Assembly_InternalGetAssemblyName},
5482 {"InternalGetType", ves_icall_System_Reflection_Assembly_InternalGetType},
5483 {"InternalImageRuntimeVersion", ves_icall_System_Reflection_Assembly_InternalImageRuntimeVersion},
5484 {"LoadFrom", ves_icall_System_Reflection_Assembly_LoadFrom},
5486 * Private icalls for the Mono Debugger
5488 {"MonoDebugger_GetLocalTypeFromSignature", ves_icall_MonoDebugger_GetLocalTypeFromSignature},
5489 {"MonoDebugger_GetMethod", ves_icall_MonoDebugger_GetMethod},
5490 {"MonoDebugger_GetMethodToken", ves_icall_MonoDebugger_GetMethodToken},
5491 {"MonoDebugger_GetType", ves_icall_MonoDebugger_GetType},
5492 /* normal icalls again */
5493 {"get_EntryPoint", ves_icall_System_Reflection_Assembly_get_EntryPoint},
5494 {"get_code_base", ves_icall_System_Reflection_Assembly_get_code_base},
5495 {"get_global_assembly_cache", ves_icall_System_Reflection_Assembly_get_global_assembly_cache},
5496 {"get_location", ves_icall_System_Reflection_Assembly_get_location},
5497 {"load_with_partial_name", ves_icall_System_Reflection_Assembly_load_with_partial_name}
5500 static const IcallEntry methodbase_icalls [] = {
5501 {"GetCurrentMethod", ves_icall_GetCurrentMethod},
5502 {"GetMethodFromHandleInternal", ves_icall_System_Reflection_MethodBase_GetMethodFromHandleInternal}
5505 static const IcallEntry module_icalls [] = {
5506 {"Close", ves_icall_System_Reflection_Module_Close},
5507 {"GetGlobalType", ves_icall_System_Reflection_Module_GetGlobalType},
5508 {"GetGuidInternal", ves_icall_System_Reflection_Module_GetGuidInternal},
5509 {"InternalGetTypes", ves_icall_System_Reflection_Module_InternalGetTypes}
5512 static const IcallEntry monocmethod_icalls [] = {
5513 {"GetGenericMethodDefinition_impl", ves_icall_MonoMethod_GetGenericMethodDefinition},
5514 {"InternalInvoke", ves_icall_InternalInvoke},
5515 {"get_Mono_IsInflatedMethod", ves_icall_MonoMethod_get_Mono_IsInflatedMethod}
5518 static const IcallEntry monoeventinfo_icalls [] = {
5519 {"get_event_info", ves_icall_get_event_info}
5522 static const IcallEntry monofield_icalls [] = {
5523 {"GetParentType", ves_icall_MonoField_GetParentType},
5524 {"GetValueInternal", ves_icall_MonoField_GetValueInternal},
5525 {"Mono_GetGenericFieldDefinition", ves_icall_MonoField_Mono_GetGenericFieldDefinition},
5526 {"SetValueInternal", ves_icall_FieldInfo_SetValueInternal}
5529 static const IcallEntry monogenericinst_icalls [] = {
5530 {"GetConstructors_internal", ves_icall_MonoGenericInst_GetConstructors},
5531 {"GetEvents_internal", ves_icall_MonoGenericInst_GetEvents},
5532 {"GetFields_internal", ves_icall_MonoGenericInst_GetFields},
5533 {"GetInterfaces_internal", ves_icall_MonoGenericInst_GetInterfaces},
5534 {"GetMethods_internal", ves_icall_MonoGenericInst_GetMethods},
5535 {"GetParentType", ves_icall_MonoGenericInst_GetParentType},
5536 {"GetProperties_internal", ves_icall_MonoGenericInst_GetProperties},
5537 {"initialize", mono_reflection_generic_inst_initialize}
5540 static const IcallEntry generictypeparambuilder_icalls [] = {
5541 {"initialize", mono_reflection_initialize_generic_parameter}
5544 static const IcallEntry monomethod_icalls [] = {
5545 {"BindGenericParameters", mono_reflection_bind_generic_method_parameters},
5546 {"GetGenericArguments", ves_icall_MonoMethod_GetGenericArguments},
5547 {"GetGenericMethodDefinition_impl", ves_icall_MonoMethod_GetGenericMethodDefinition},
5548 {"InternalInvoke", ves_icall_InternalInvoke},
5549 {"get_HasGenericParameters", ves_icall_MonoMethod_get_HasGenericParameters},
5550 {"get_IsGenericMethodDefinition", ves_icall_MonoMethod_get_IsGenericMethodDefinition},
5551 {"get_Mono_IsInflatedMethod", ves_icall_MonoMethod_get_Mono_IsInflatedMethod},
5552 {"get_base_definition", ves_icall_MonoMethod_get_base_definition}
5555 static const IcallEntry monomethodinfo_icalls [] = {
5556 {"get_method_info", ves_icall_get_method_info},
5557 {"get_parameter_info", ves_icall_get_parameter_info}
5560 static const IcallEntry monopropertyinfo_icalls [] = {
5561 {"get_property_info", ves_icall_get_property_info}
5564 static const IcallEntry dns_icalls [] = {
5565 {"GetHostByAddr_internal(string,string&,string[]&,string[]&)", ves_icall_System_Net_Dns_GetHostByAddr_internal},
5566 {"GetHostByName_internal(string,string&,string[]&,string[]&)", ves_icall_System_Net_Dns_GetHostByName_internal},
5567 {"GetHostName_internal(string&)", ves_icall_System_Net_Dns_GetHostName_internal}
5570 static const IcallEntry socket_icalls [] = {
5571 {"Accept_internal(intptr,int&)", ves_icall_System_Net_Sockets_Socket_Accept_internal},
5572 {"AsyncReceiveInternal", ves_icall_System_Net_Sockets_Socket_AsyncReceive},
5573 {"AsyncSendInternal", ves_icall_System_Net_Sockets_Socket_AsyncSend},
5574 {"Available_internal(intptr,int&)", ves_icall_System_Net_Sockets_Socket_Available_internal},
5575 {"Bind_internal(intptr,System.Net.SocketAddress,int&)", ves_icall_System_Net_Sockets_Socket_Bind_internal},
5576 {"Blocking_internal(intptr,bool,int&)", ves_icall_System_Net_Sockets_Socket_Blocking_internal},
5577 {"Close_internal(intptr,int&)", ves_icall_System_Net_Sockets_Socket_Close_internal},
5578 {"Connect_internal(intptr,System.Net.SocketAddress,int&)", ves_icall_System_Net_Sockets_Socket_Connect_internal},
5579 {"GetSocketOption_arr_internal(intptr,System.Net.Sockets.SocketOptionLevel,System.Net.Sockets.SocketOptionName,byte[]&,int&)", ves_icall_System_Net_Sockets_Socket_GetSocketOption_arr_internal},
5580 {"GetSocketOption_obj_internal(intptr,System.Net.Sockets.SocketOptionLevel,System.Net.Sockets.SocketOptionName,object&,int&)", ves_icall_System_Net_Sockets_Socket_GetSocketOption_obj_internal},
5581 {"GetSupportsAsync", ves_icall_System_IO_MonoIO_GetSupportsAsync},
5582 {"Listen_internal(intptr,int,int&)", ves_icall_System_Net_Sockets_Socket_Listen_internal},
5583 {"LocalEndPoint_internal(intptr,int&)", ves_icall_System_Net_Sockets_Socket_LocalEndPoint_internal},
5584 {"Poll_internal", ves_icall_System_Net_Sockets_Socket_Poll_internal},
5585 {"Receive_internal(intptr,byte[],int,int,System.Net.Sockets.SocketFlags,int&)", ves_icall_System_Net_Sockets_Socket_Receive_internal},
5586 {"RecvFrom_internal(intptr,byte[],int,int,System.Net.Sockets.SocketFlags,System.Net.SocketAddress&,int&)", ves_icall_System_Net_Sockets_Socket_RecvFrom_internal},
5587 {"RemoteEndPoint_internal(intptr,int&)", ves_icall_System_Net_Sockets_Socket_RemoteEndPoint_internal},
5588 {"Select_internal(System.Net.Sockets.Socket[]&,System.Net.Sockets.Socket[]&,System.Net.Sockets.Socket[]&,int,int&)", ves_icall_System_Net_Sockets_Socket_Select_internal},
5589 {"SendTo_internal(intptr,byte[],int,int,System.Net.Sockets.SocketFlags,System.Net.SocketAddress,int&)", ves_icall_System_Net_Sockets_Socket_SendTo_internal},
5590 {"Send_internal(intptr,byte[],int,int,System.Net.Sockets.SocketFlags,int&)", ves_icall_System_Net_Sockets_Socket_Send_internal},
5591 {"SetSocketOption_internal(intptr,System.Net.Sockets.SocketOptionLevel,System.Net.Sockets.SocketOptionName,object,byte[],int,int&)", ves_icall_System_Net_Sockets_Socket_SetSocketOption_internal},
5592 {"Shutdown_internal(intptr,System.Net.Sockets.SocketShutdown,int&)", ves_icall_System_Net_Sockets_Socket_Shutdown_internal},
5593 {"Socket_internal(System.Net.Sockets.AddressFamily,System.Net.Sockets.SocketType,System.Net.Sockets.ProtocolType,int&)", ves_icall_System_Net_Sockets_Socket_Socket_internal},
5594 {"WSAIoctl(intptr,int,byte[],byte[],int&)", ves_icall_System_Net_Sockets_Socket_WSAIoctl}
5597 static const IcallEntry socketex_icalls [] = {
5598 {"WSAGetLastError_internal", ves_icall_System_Net_Sockets_SocketException_WSAGetLastError_internal}
5601 static const IcallEntry object_icalls [] = {
5602 {"GetType", ves_icall_System_Object_GetType},
5603 {"InternalGetHashCode", ves_icall_System_Object_GetHashCode},
5604 {"MemberwiseClone", ves_icall_System_Object_MemberwiseClone},
5605 {"obj_address", ves_icall_System_Object_obj_address}
5608 static const IcallEntry assemblybuilder_icalls[] = {
5609 {"InternalAddModule", mono_image_load_module},
5610 {"basic_init", mono_image_basic_init}
5613 static const IcallEntry customattrbuilder_icalls [] = {
5614 {"GetBlob", mono_reflection_get_custom_attrs_blob}
5617 static const IcallEntry dynamicmethod_icalls [] = {
5618 {"create_dynamic_method", mono_reflection_create_dynamic_method}
5621 static const IcallEntry methodbuilder_icalls [] = {
5622 {"BindGenericParameters", mono_reflection_bind_generic_method_parameters}
5625 static const IcallEntry modulebuilder_icalls [] = {
5626 {"basic_init", mono_image_module_basic_init},
5627 {"build_metadata", ves_icall_ModuleBuilder_build_metadata},
5628 {"create_modified_type", ves_icall_ModuleBuilder_create_modified_type},
5629 {"getDataChunk", ves_icall_ModuleBuilder_getDataChunk},
5630 {"getMethodToken", ves_icall_ModuleBuilder_getMethodToken},
5631 {"getToken", ves_icall_ModuleBuilder_getToken},
5632 {"getUSIndex", mono_image_insert_string}
5635 static const IcallEntry signaturehelper_icalls [] = {
5636 {"get_signature_field", mono_reflection_sighelper_get_signature_field},
5637 {"get_signature_local", mono_reflection_sighelper_get_signature_local}
5640 static const IcallEntry typebuilder_icalls [] = {
5641 {"create_internal_class", mono_reflection_create_internal_class},
5642 {"create_runtime_class", mono_reflection_create_runtime_class},
5643 {"get_IsGenericParameter", ves_icall_TypeBuilder_get_IsGenericParameter},
5644 {"get_event_info", mono_reflection_event_builder_get_event_info},
5645 {"setup_generic_class", mono_reflection_setup_generic_class},
5646 {"setup_internal_class", mono_reflection_setup_internal_class}
5649 static const IcallEntry enumbuilder_icalls [] = {
5650 {"setup_enum_type", ves_icall_EnumBuilder_setup_enum_type}
5653 static const IcallEntry runtimehelpers_icalls [] = {
5654 {"GetObjectValue", ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetObjectValue},
5655 /* REMOVEME: no longer needed, just so we dont break things when not needed */
5656 {"GetOffsetToStringData", ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetOffsetToStringData},
5657 {"InitializeArray", ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_InitializeArray},
5658 {"RunClassConstructor", ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_RunClassConstructor},
5659 {"get_OffsetToStringData", ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetOffsetToStringData}
5662 static const IcallEntry gchandle_icalls [] = {
5663 {"FreeHandle", ves_icall_System_GCHandle_FreeHandle},
5664 {"GetAddrOfPinnedObject", ves_icall_System_GCHandle_GetAddrOfPinnedObject},
5665 {"GetTarget", ves_icall_System_GCHandle_GetTarget},
5666 {"GetTargetHandle", ves_icall_System_GCHandle_GetTargetHandle}
5669 static const IcallEntry marshal_icalls [] = {
5670 {"AllocCoTaskMem", ves_icall_System_Runtime_InteropServices_Marshal_AllocCoTaskMem},
5671 {"AllocHGlobal", mono_marshal_alloc},
5672 {"DestroyStructure", ves_icall_System_Runtime_InteropServices_Marshal_DestroyStructure},
5673 {"FreeCoTaskMem", ves_icall_System_Runtime_InteropServices_Marshal_FreeCoTaskMem},
5674 {"FreeHGlobal", mono_marshal_free},
5675 {"GetLastWin32Error", ves_icall_System_Runtime_InteropServices_Marshal_GetLastWin32Error},
5676 {"OffsetOf", ves_icall_System_Runtime_InteropServices_Marshal_OffsetOf},
5677 {"Prelink", ves_icall_System_Runtime_InteropServices_Marshal_Prelink},
5678 {"PrelinkAll", ves_icall_System_Runtime_InteropServices_Marshal_PrelinkAll},
5679 {"PtrToStringAnsi(intptr)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi},
5680 {"PtrToStringAnsi(intptr,int)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi_len},
5681 {"PtrToStringAuto(intptr)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi},
5682 {"PtrToStringAuto(intptr,int)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi_len},
5683 {"PtrToStringBSTR", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringBSTR},
5684 {"PtrToStringUni(intptr)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringUni},
5685 {"PtrToStringUni(intptr,int)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringUni_len},
5686 {"PtrToStructure(intptr,System.Type)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStructure_type},
5687 {"PtrToStructure(intptr,object)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStructure},
5688 {"ReAllocHGlobal", mono_marshal_realloc},
5689 {"ReadByte", ves_icall_System_Runtime_InteropServices_Marshal_ReadByte},
5690 {"ReadInt16", ves_icall_System_Runtime_InteropServices_Marshal_ReadInt16},
5691 {"ReadInt32", ves_icall_System_Runtime_InteropServices_Marshal_ReadInt32},
5692 {"ReadInt64", ves_icall_System_Runtime_InteropServices_Marshal_ReadInt64},
5693 {"ReadIntPtr", ves_icall_System_Runtime_InteropServices_Marshal_ReadIntPtr},
5694 {"SizeOf", ves_icall_System_Runtime_InteropServices_Marshal_SizeOf},
5695 {"StringToHGlobalAnsi", ves_icall_System_Runtime_InteropServices_Marshal_StringToHGlobalAnsi},
5696 {"StringToHGlobalAuto", ves_icall_System_Runtime_InteropServices_Marshal_StringToHGlobalAnsi},
5697 {"StringToHGlobalUni", ves_icall_System_Runtime_InteropServices_Marshal_StringToHGlobalUni},
5698 {"StructureToPtr", ves_icall_System_Runtime_InteropServices_Marshal_StructureToPtr},
5699 {"UnsafeAddrOfPinnedArrayElement", ves_icall_System_Runtime_InteropServices_Marshal_UnsafeAddrOfPinnedArrayElement},
5700 {"WriteByte", ves_icall_System_Runtime_InteropServices_Marshal_WriteByte},
5701 {"WriteInt16", ves_icall_System_Runtime_InteropServices_Marshal_WriteInt16},
5702 {"WriteInt32", ves_icall_System_Runtime_InteropServices_Marshal_WriteInt32},
5703 {"WriteInt64", ves_icall_System_Runtime_InteropServices_Marshal_WriteInt64},
5704 {"WriteIntPtr", ves_icall_System_Runtime_InteropServices_Marshal_WriteIntPtr},
5705 {"copy_from_unmanaged", ves_icall_System_Runtime_InteropServices_Marshal_copy_from_unmanaged},
5706 {"copy_to_unmanaged", ves_icall_System_Runtime_InteropServices_Marshal_copy_to_unmanaged}
5709 static const IcallEntry activationservices_icalls [] = {
5710 {"AllocateUninitializedClassInstance", ves_icall_System_Runtime_Activation_ActivationServices_AllocateUninitializedClassInstance},
5711 {"EnableProxyActivation", ves_icall_System_Runtime_Activation_ActivationServices_EnableProxyActivation}
5714 static const IcallEntry monomethodmessage_icalls [] = {
5715 {"InitMessage", ves_icall_MonoMethodMessage_InitMessage}
5718 static const IcallEntry realproxy_icalls [] = {
5719 {"InternalGetProxyType", ves_icall_Remoting_RealProxy_InternalGetProxyType},
5720 {"InternalGetTransparentProxy", ves_icall_Remoting_RealProxy_GetTransparentProxy}
5723 static const IcallEntry remotingservices_icalls [] = {
5724 {"InternalExecute", ves_icall_InternalExecute},
5725 {"IsTransparentProxy", ves_icall_IsTransparentProxy}
5728 static const IcallEntry rng_icalls [] = {
5729 {"RngClose", ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngClose},
5730 {"RngGetBytes", ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngGetBytes},
5731 {"RngInitialize", ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngInitialize}
5734 static const IcallEntry methodhandle_icalls [] = {
5735 {"GetFunctionPointer", ves_icall_RuntimeMethod_GetFunctionPointer}
5738 static const IcallEntry string_icalls [] = {
5739 {".ctor(char*)", ves_icall_System_String_ctor_charp},
5740 {".ctor(char*,int,int)", ves_icall_System_String_ctor_charp_int_int},
5741 {".ctor(char,int)", ves_icall_System_String_ctor_char_int},
5742 {".ctor(char[])", ves_icall_System_String_ctor_chara},
5743 {".ctor(char[],int,int)", ves_icall_System_String_ctor_chara_int_int},
5744 {".ctor(sbyte*)", ves_icall_System_String_ctor_sbytep},
5745 {".ctor(sbyte*,int,int)", ves_icall_System_String_ctor_sbytep_int_int},
5746 {".ctor(sbyte*,int,int,System.Text.Encoding)", ves_icall_System_String_ctor_encoding},
5747 {"GetHashCode", ves_icall_System_String_GetHashCode},
5748 {"InternalAllocateStr", ves_icall_System_String_InternalAllocateStr},
5749 {"InternalCharCopy", ves_icall_System_String_InternalCharCopy},
5750 {"InternalCopyTo", ves_icall_System_String_InternalCopyTo},
5751 {"InternalIndexOfAny", ves_icall_System_String_InternalIndexOfAny},
5752 {"InternalInsert", ves_icall_System_String_InternalInsert},
5753 {"InternalIntern", ves_icall_System_String_InternalIntern},
5754 {"InternalIsInterned", ves_icall_System_String_InternalIsInterned},
5755 {"InternalJoin", ves_icall_System_String_InternalJoin},
5756 {"InternalLastIndexOfAny", ves_icall_System_String_InternalLastIndexOfAny},
5757 {"InternalPad", ves_icall_System_String_InternalPad},
5758 {"InternalRemove", ves_icall_System_String_InternalRemove},
5759 {"InternalReplace(char,char)", ves_icall_System_String_InternalReplace_Char},
5760 {"InternalReplace(string,string,System.Globalization.CompareInfo)", ves_icall_System_String_InternalReplace_Str_Comp},
5761 {"InternalSplit", ves_icall_System_String_InternalSplit},
5762 {"InternalStrcpy(string,int,char[])", ves_icall_System_String_InternalStrcpy_Chars},
5763 {"InternalStrcpy(string,int,char[],int,int)", ves_icall_System_String_InternalStrcpy_CharsN},
5764 {"InternalStrcpy(string,int,string)", ves_icall_System_String_InternalStrcpy_Str},
5765 {"InternalStrcpy(string,int,string,int,int)", ves_icall_System_String_InternalStrcpy_StrN},
5766 {"InternalToLower(System.Globalization.CultureInfo)", ves_icall_System_String_InternalToLower_Comp},
5767 {"InternalToUpper(System.Globalization.CultureInfo)", ves_icall_System_String_InternalToUpper_Comp},
5768 {"InternalTrim", ves_icall_System_String_InternalTrim},
5769 {"get_Chars", ves_icall_System_String_get_Chars}
5772 static const IcallEntry encoding_icalls [] = {
5773 {"InternalCodePage", ves_icall_System_Text_Encoding_InternalCodePage}
5776 static const IcallEntry monitor_icalls [] = {
5777 {"Monitor_exit", ves_icall_System_Threading_Monitor_Monitor_exit},
5778 {"Monitor_pulse", ves_icall_System_Threading_Monitor_Monitor_pulse},
5779 {"Monitor_pulse_all", ves_icall_System_Threading_Monitor_Monitor_pulse_all},
5780 {"Monitor_test_owner", ves_icall_System_Threading_Monitor_Monitor_test_owner},
5781 {"Monitor_test_synchronised", ves_icall_System_Threading_Monitor_Monitor_test_synchronised},
5782 {"Monitor_try_enter", ves_icall_System_Threading_Monitor_Monitor_try_enter},
5783 {"Monitor_wait", ves_icall_System_Threading_Monitor_Monitor_wait}
5786 static const IcallEntry interlocked_icalls [] = {
5787 {"CompareExchange(int&,int,int)", ves_icall_System_Threading_Interlocked_CompareExchange_Int},
5788 {"CompareExchange(object&,object,object)", ves_icall_System_Threading_Interlocked_CompareExchange_Object},
5789 {"CompareExchange(single&,single,single)", ves_icall_System_Threading_Interlocked_CompareExchange_Single},
5790 {"Decrement(int&)", ves_icall_System_Threading_Interlocked_Decrement_Int},
5791 {"Decrement(long&)", ves_icall_System_Threading_Interlocked_Decrement_Long},
5792 {"Exchange(int&,int)", ves_icall_System_Threading_Interlocked_Exchange_Int},
5793 {"Exchange(object&,object)", ves_icall_System_Threading_Interlocked_Exchange_Object},
5794 {"Exchange(single&,single)", ves_icall_System_Threading_Interlocked_Exchange_Single},
5795 {"Increment(int&)", ves_icall_System_Threading_Interlocked_Increment_Int},
5796 {"Increment(long&)", ves_icall_System_Threading_Interlocked_Increment_Long}
5799 static const IcallEntry mutex_icalls [] = {
5800 {"CreateMutex_internal(bool,string,bool&)", ves_icall_System_Threading_Mutex_CreateMutex_internal},
5801 {"ReleaseMutex_internal(intptr)", ves_icall_System_Threading_Mutex_ReleaseMutex_internal}
5804 static const IcallEntry nativeevents_icalls [] = {
5805 {"CloseEvent_internal", ves_icall_System_Threading_Events_CloseEvent_internal},
5806 {"CreateEvent_internal", ves_icall_System_Threading_Events_CreateEvent_internal},
5807 {"ResetEvent_internal", ves_icall_System_Threading_Events_ResetEvent_internal},
5808 {"SetEvent_internal", ves_icall_System_Threading_Events_SetEvent_internal}
5811 static const IcallEntry thread_icalls [] = {
5812 {"Abort_internal(object)", ves_icall_System_Threading_Thread_Abort},
5813 {"CurrentThread_internal", mono_thread_current},
5814 {"GetDomainID", ves_icall_System_Threading_Thread_GetDomainID},
5815 {"GetName_internal", ves_icall_System_Threading_Thread_GetName_internal},
5816 {"Join_internal", ves_icall_System_Threading_Thread_Join_internal},
5817 {"ResetAbort_internal()", ves_icall_System_Threading_Thread_ResetAbort},
5818 {"Resume_internal()", ves_icall_System_Threading_Thread_Resume},
5819 {"SetName_internal", ves_icall_System_Threading_Thread_SetName_internal},
5820 {"Sleep_internal", ves_icall_System_Threading_Thread_Sleep_internal},
5821 {"SlotHash_lookup", ves_icall_System_Threading_Thread_SlotHash_lookup},
5822 {"SlotHash_store", ves_icall_System_Threading_Thread_SlotHash_store},
5823 {"Start_internal", ves_icall_System_Threading_Thread_Start_internal},
5824 {"Suspend_internal", ves_icall_System_Threading_Thread_Suspend},
5825 {"Thread_free_internal", ves_icall_System_Threading_Thread_Thread_free_internal},
5826 {"Thread_internal", ves_icall_System_Threading_Thread_Thread_internal},
5827 {"VolatileRead(byte&)", ves_icall_System_Threading_Thread_VolatileRead1},
5828 {"VolatileRead(double&)", ves_icall_System_Threading_Thread_VolatileRead8},
5829 {"VolatileRead(int&)", ves_icall_System_Threading_Thread_VolatileRead4},
5830 {"VolatileRead(int16&)", ves_icall_System_Threading_Thread_VolatileRead2},
5831 {"VolatileRead(intptr&)", ves_icall_System_Threading_Thread_VolatileReadIntPtr},
5832 {"VolatileRead(long&)", ves_icall_System_Threading_Thread_VolatileRead8},
5833 {"VolatileRead(object&)", ves_icall_System_Threading_Thread_VolatileReadIntPtr},
5834 {"VolatileRead(sbyte&)", ves_icall_System_Threading_Thread_VolatileRead1},
5835 {"VolatileRead(single&)", ves_icall_System_Threading_Thread_VolatileRead4},
5836 {"VolatileRead(uint&)", ves_icall_System_Threading_Thread_VolatileRead2},
5837 {"VolatileRead(uint16&)", ves_icall_System_Threading_Thread_VolatileRead2},
5838 {"VolatileRead(uintptr&)", ves_icall_System_Threading_Thread_VolatileReadIntPtr},
5839 {"VolatileRead(ulong&)", ves_icall_System_Threading_Thread_VolatileRead8},
5840 {"VolatileWrite(byte&,byte)", ves_icall_System_Threading_Thread_VolatileWrite1},
5841 {"VolatileWrite(double&,double)", ves_icall_System_Threading_Thread_VolatileWrite8},
5842 {"VolatileWrite(int&,int)", ves_icall_System_Threading_Thread_VolatileWrite4},
5843 {"VolatileWrite(int16&,int16)", ves_icall_System_Threading_Thread_VolatileWrite2},
5844 {"VolatileWrite(intptr&,intptr)", ves_icall_System_Threading_Thread_VolatileWriteIntPtr},
5845 {"VolatileWrite(long&,long)", ves_icall_System_Threading_Thread_VolatileWrite8},
5846 {"VolatileWrite(object&,object)", ves_icall_System_Threading_Thread_VolatileWriteIntPtr},
5847 {"VolatileWrite(sbyte&,sbyte)", ves_icall_System_Threading_Thread_VolatileWrite1},
5848 {"VolatileWrite(single&,single)", ves_icall_System_Threading_Thread_VolatileWrite4},
5849 {"VolatileWrite(uint&,uint)", ves_icall_System_Threading_Thread_VolatileWrite2},
5850 {"VolatileWrite(uint16&,uint16)", ves_icall_System_Threading_Thread_VolatileWrite2},
5851 {"VolatileWrite(uintptr&,uintptr)", ves_icall_System_Threading_Thread_VolatileWriteIntPtr},
5852 {"VolatileWrite(ulong&,ulong)", ves_icall_System_Threading_Thread_VolatileWrite8},
5853 {"current_lcid()", ves_icall_System_Threading_Thread_current_lcid}
5856 static const IcallEntry threadpool_icalls [] = {
5857 {"BindHandleInternal", ves_icall_System_Threading_ThreadPool_BindHandle},
5858 {"GetAvailableThreads", ves_icall_System_Threading_ThreadPool_GetAvailableThreads},
5859 {"GetMaxThreads", ves_icall_System_Threading_ThreadPool_GetMaxThreads},
5860 {"GetMinThreads", ves_icall_System_Threading_ThreadPool_GetMinThreads},
5861 {"SetMinThreads", ves_icall_System_Threading_ThreadPool_SetMinThreads}
5864 static const IcallEntry waithandle_icalls [] = {
5865 {"WaitAll_internal", ves_icall_System_Threading_WaitHandle_WaitAll_internal},
5866 {"WaitAny_internal", ves_icall_System_Threading_WaitHandle_WaitAny_internal},
5867 {"WaitOne_internal", ves_icall_System_Threading_WaitHandle_WaitOne_internal}
5870 static const IcallEntry type_icalls [] = {
5871 {"BindGenericParameters", ves_icall_Type_BindGenericParameters},
5872 {"Equals", ves_icall_type_Equals},
5873 {"GetGenericParameterPosition", ves_icall_Type_GetGenericParameterPosition},
5874 {"GetGenericTypeDefinition_impl", ves_icall_Type_GetGenericTypeDefinition_impl},
5875 {"GetInterfaceMapData", ves_icall_Type_GetInterfaceMapData},
5876 {"GetTypeCode", ves_icall_type_GetTypeCode},
5877 {"IsArrayImpl", ves_icall_Type_IsArrayImpl},
5878 {"IsInstanceOfType", ves_icall_type_IsInstanceOfType},
5879 {"get_IsGenericInstance", ves_icall_Type_get_IsGenericInstance},
5880 {"get_IsGenericTypeDefinition", ves_icall_Type_get_IsGenericTypeDefinition},
5881 {"internal_from_handle", ves_icall_type_from_handle},
5882 {"internal_from_name", ves_icall_type_from_name},
5883 {"make_array_type", ves_icall_Type_make_array_type},
5884 {"make_byref_type", ves_icall_Type_make_byref_type},
5885 {"type_is_assignable_from", ves_icall_type_is_assignable_from},
5886 {"type_is_subtype_of", ves_icall_type_is_subtype_of}
5889 static const IcallEntry typedref_icalls [] = {
5890 {"ToObject", mono_TypedReference_ToObject}
5893 static const IcallEntry valuetype_icalls [] = {
5894 {"InternalEquals", ves_icall_System_ValueType_Equals},
5895 {"InternalGetHashCode", ves_icall_System_ValueType_InternalGetHashCode}
5898 static const IcallEntry web_icalls [] = {
5899 {"GetMachineConfigPath", ves_icall_System_Configuration_DefaultConfig_get_machine_config_path},
5900 {"GetMachineInstallDirectory", ves_icall_System_Web_Util_ICalls_get_machine_install_dir}
5903 static const IcallEntry identity_icalls [] = {
5904 {"GetCurrentToken", ves_icall_System_Security_Principal_WindowsIdentity_GetCurrentToken},
5905 {"GetTokenName", ves_icall_System_Security_Principal_WindowsIdentity_GetTokenName},
5906 {"GetUserToken", ves_icall_System_Security_Principal_WindowsIdentity_GetUserToken},
5907 {"_GetRoles", ves_icall_System_Security_Principal_WindowsIdentity_GetRoles}
5910 static const IcallEntry impersonation_icalls [] = {
5911 {"CloseToken", ves_icall_System_Security_Principal_WindowsImpersonationContext_CloseToken},
5912 {"DuplicateToken", ves_icall_System_Security_Principal_WindowsImpersonationContext_DuplicateToken},
5913 {"RevertToSelf", ves_icall_System_Security_Principal_WindowsImpersonationContext_RevertToSelf},
5914 {"SetCurrentToken", ves_icall_System_Security_Principal_WindowsImpersonationContext_SetCurrentToken}
5917 static const IcallEntry principal_icalls [] = {
5918 {"IsMemberOfGroupId", ves_icall_System_Security_Principal_WindowsPrincipal_IsMemberOfGroupId},
5919 {"IsMemberOfGroupName", ves_icall_System_Security_Principal_WindowsPrincipal_IsMemberOfGroupName}
5922 static const IcallEntry keypair_icalls [] = {
5923 {"_CanSecure", ves_icall_Mono_Security_Cryptography_KeyPairPersistence_CanSecure},
5924 {"_IsMachineProtected", ves_icall_Mono_Security_Cryptography_KeyPairPersistence_IsMachineProtected},
5925 {"_IsUserProtected", ves_icall_Mono_Security_Cryptography_KeyPairPersistence_IsUserProtected},
5926 {"_ProtectMachine", ves_icall_Mono_Security_Cryptography_KeyPairPersistence_ProtectMachine},
5927 {"_ProtectUser", ves_icall_Mono_Security_Cryptography_KeyPairPersistence_ProtectUser}
5931 static const IcallEntry array_icalls [] = {
5936 /* keep the entries all sorted */
5937 static const IcallMap icall_entries [] = {
5938 {"Mono.Security.Cryptography.KeyPairPersistence", keypair_icalls, G_N_ELEMENTS (keypair_icalls)},
5939 {"System.Activator", activator_icalls, G_N_ELEMENTS (activator_icalls)},
5940 {"System.AppDomain", appdomain_icalls, G_N_ELEMENTS (appdomain_icalls)},
5941 {"System.ArgIterator", argiterator_icalls, G_N_ELEMENTS (argiterator_icalls)},
5942 {"System.Array", array_icalls, G_N_ELEMENTS (array_icalls)},
5943 {"System.Buffer", buffer_icalls, G_N_ELEMENTS (buffer_icalls)},
5944 {"System.Char", char_icalls, G_N_ELEMENTS (char_icalls)},
5945 {"System.Configuration.DefaultConfig", defaultconf_icalls, G_N_ELEMENTS (defaultconf_icalls)},
5946 {"System.CurrentTimeZone", timezone_icalls, G_N_ELEMENTS (timezone_icalls)},
5947 {"System.DateTime", datetime_icalls, G_N_ELEMENTS (datetime_icalls)},
5948 {"System.Decimal", decimal_icalls, G_N_ELEMENTS (decimal_icalls)},
5949 {"System.Delegate", delegate_icalls, G_N_ELEMENTS (delegate_icalls)},
5950 {"System.Diagnostics.DefaultTraceListener", tracelist_icalls, G_N_ELEMENTS (tracelist_icalls)},
5951 {"System.Diagnostics.FileVersionInfo", fileversion_icalls, G_N_ELEMENTS (fileversion_icalls)},
5952 {"System.Diagnostics.Process", process_icalls, G_N_ELEMENTS (process_icalls)},
5953 {"System.Double", double_icalls, G_N_ELEMENTS (double_icalls)},
5954 {"System.Enum", enum_icalls, G_N_ELEMENTS (enum_icalls)},
5955 {"System.Environment", environment_icalls, G_N_ELEMENTS (environment_icalls)},
5956 {"System.GC", gc_icalls, G_N_ELEMENTS (gc_icalls)},
5957 {"System.Globalization.CompareInfo", compareinfo_icalls, G_N_ELEMENTS (compareinfo_icalls)},
5958 {"System.Globalization.CultureInfo", cultureinfo_icalls, G_N_ELEMENTS (cultureinfo_icalls)},
5959 {"System.IO.FAMWatcher", famwatcher_icalls, G_N_ELEMENTS (famwatcher_icalls)},
5960 {"System.IO.FileSystemWatcher", filewatcher_icalls, G_N_ELEMENTS (filewatcher_icalls)},
5961 {"System.IO.MonoIO", monoio_icalls, G_N_ELEMENTS (monoio_icalls)},
5962 {"System.IO.Path", path_icalls, G_N_ELEMENTS (path_icalls)},
5963 {"System.Math", math_icalls, G_N_ELEMENTS (math_icalls)},
5964 {"System.MonoCustomAttrs", customattrs_icalls, G_N_ELEMENTS (customattrs_icalls)},
5965 {"System.MonoEnumInfo", enuminfo_icalls, G_N_ELEMENTS (enuminfo_icalls)},
5966 {"System.MonoType", monotype_icalls, G_N_ELEMENTS (monotype_icalls)},
5967 {"System.Net.Dns", dns_icalls, G_N_ELEMENTS (dns_icalls)},
5968 {"System.Net.Sockets.Socket", socket_icalls, G_N_ELEMENTS (socket_icalls)},
5969 {"System.Net.Sockets.SocketException", socketex_icalls, G_N_ELEMENTS (socketex_icalls)},
5970 {"System.Object", object_icalls, G_N_ELEMENTS (object_icalls)},
5971 {"System.Reflection.Assembly", assembly_icalls, G_N_ELEMENTS (assembly_icalls)},
5972 {"System.Reflection.Emit.AssemblyBuilder", assemblybuilder_icalls, G_N_ELEMENTS (assemblybuilder_icalls)},
5973 {"System.Reflection.Emit.CustomAttributeBuilder", customattrbuilder_icalls, G_N_ELEMENTS (customattrbuilder_icalls)},
5974 {"System.Reflection.Emit.DynamicMethod", dynamicmethod_icalls, G_N_ELEMENTS (dynamicmethod_icalls)},
5975 {"System.Reflection.Emit.EnumBuilder", enumbuilder_icalls, G_N_ELEMENTS (enumbuilder_icalls)},
5976 {"System.Reflection.Emit.GenericTypeParameterBuilder", generictypeparambuilder_icalls, G_N_ELEMENTS (generictypeparambuilder_icalls)},
5977 {"System.Reflection.Emit.MethodBuilder", methodbuilder_icalls, G_N_ELEMENTS (methodbuilder_icalls)},
5978 {"System.Reflection.Emit.ModuleBuilder", modulebuilder_icalls, G_N_ELEMENTS (modulebuilder_icalls)},
5979 {"System.Reflection.Emit.SignatureHelper", signaturehelper_icalls, G_N_ELEMENTS (signaturehelper_icalls)},
5980 {"System.Reflection.Emit.TypeBuilder", typebuilder_icalls, G_N_ELEMENTS (typebuilder_icalls)},
5981 {"System.Reflection.FieldInfo", fieldinfo_icalls, G_N_ELEMENTS (fieldinfo_icalls)},
5982 {"System.Reflection.MethodBase", methodbase_icalls, G_N_ELEMENTS (methodbase_icalls)},
5983 {"System.Reflection.Module", module_icalls, G_N_ELEMENTS (module_icalls)},
5984 {"System.Reflection.MonoCMethod", monocmethod_icalls, G_N_ELEMENTS (monocmethod_icalls)},
5985 {"System.Reflection.MonoEventInfo", monoeventinfo_icalls, G_N_ELEMENTS (monoeventinfo_icalls)},
5986 {"System.Reflection.MonoField", monofield_icalls, G_N_ELEMENTS (monofield_icalls)},
5987 {"System.Reflection.MonoGenericInst", monogenericinst_icalls, G_N_ELEMENTS (monogenericinst_icalls)},
5988 {"System.Reflection.MonoMethod", monomethod_icalls, G_N_ELEMENTS (monomethod_icalls)},
5989 {"System.Reflection.MonoMethodInfo", monomethodinfo_icalls, G_N_ELEMENTS (monomethodinfo_icalls)},
5990 {"System.Reflection.MonoPropertyInfo", monopropertyinfo_icalls, G_N_ELEMENTS (monopropertyinfo_icalls)},
5991 {"System.Runtime.CompilerServices.RuntimeHelpers", runtimehelpers_icalls, G_N_ELEMENTS (runtimehelpers_icalls)},
5992 {"System.Runtime.InteropServices.GCHandle", gchandle_icalls, G_N_ELEMENTS (gchandle_icalls)},
5993 {"System.Runtime.InteropServices.Marshal", marshal_icalls, G_N_ELEMENTS (marshal_icalls)},
5994 {"System.Runtime.Remoting.Activation.ActivationServices", activationservices_icalls, G_N_ELEMENTS (activationservices_icalls)},
5995 {"System.Runtime.Remoting.Messaging.MonoMethodMessage", monomethodmessage_icalls, G_N_ELEMENTS (monomethodmessage_icalls)},
5996 {"System.Runtime.Remoting.Proxies.RealProxy", realproxy_icalls, G_N_ELEMENTS (realproxy_icalls)},
5997 {"System.Runtime.Remoting.RemotingServices", remotingservices_icalls, G_N_ELEMENTS (remotingservices_icalls)},
5998 {"System.RuntimeMethodHandle", methodhandle_icalls, G_N_ELEMENTS (methodhandle_icalls)},
5999 {"System.Security.Cryptography.RNGCryptoServiceProvider", rng_icalls, G_N_ELEMENTS (rng_icalls)},
6000 {"System.Security.Principal.WindowsIdentity", identity_icalls, G_N_ELEMENTS (identity_icalls)},
6001 {"System.Security.Principal.WindowsImpersonationContext", impersonation_icalls, G_N_ELEMENTS (impersonation_icalls)},
6002 {"System.Security.Principal.WindowsPrincipal", principal_icalls, G_N_ELEMENTS (principal_icalls)},
6003 {"System.String", string_icalls, G_N_ELEMENTS (string_icalls)},
6004 {"System.Text.Encoding", encoding_icalls, G_N_ELEMENTS (encoding_icalls)},
6005 {"System.Threading.Interlocked", interlocked_icalls, G_N_ELEMENTS (interlocked_icalls)},
6006 {"System.Threading.Monitor", monitor_icalls, G_N_ELEMENTS (monitor_icalls)},
6007 {"System.Threading.Mutex", mutex_icalls, G_N_ELEMENTS (mutex_icalls)},
6008 {"System.Threading.NativeEventCalls", nativeevents_icalls, G_N_ELEMENTS (nativeevents_icalls)},
6009 {"System.Threading.Thread", thread_icalls, G_N_ELEMENTS (thread_icalls)},
6010 {"System.Threading.ThreadPool", threadpool_icalls, G_N_ELEMENTS (threadpool_icalls)},
6011 {"System.Threading.WaitHandle", waithandle_icalls, G_N_ELEMENTS (waithandle_icalls)},
6012 {"System.Type", type_icalls, G_N_ELEMENTS (type_icalls)},
6013 {"System.TypedReference", typedref_icalls, G_N_ELEMENTS (typedref_icalls)},
6014 {"System.ValueType", valuetype_icalls, G_N_ELEMENTS (valuetype_icalls)},
6015 {"System.Web.Util.ICalls", web_icalls, G_N_ELEMENTS (web_icalls)}
6018 static GHashTable *icall_hash = NULL;
6019 static GHashTable *jit_icall_hash_name = NULL;
6020 static GHashTable *jit_icall_hash_addr = NULL;
6023 mono_init_icall (void)
6027 /* check that tables are sorted: disable in release */
6030 const IcallMap *imap;
6031 const IcallEntry *ientry;
6032 const char *prev_class = NULL;
6033 const char *prev_method;
6035 for (i = 0; i < G_N_ELEMENTS (icall_entries); ++i) {
6036 imap = &icall_entries [i];
6038 if (prev_class && strcmp (prev_class, imap->klass) >= 0)
6039 g_print ("class %s should come before class %s\n", imap->klass, prev_class);
6040 prev_class = imap->klass;
6041 for (j = 0; j < imap->size; ++j) {
6042 ientry = &imap->icalls [j];
6043 if (prev_method && strcmp (prev_method, ientry->method) >= 0)
6044 g_print ("method %s should come before method %s\n", ientry->method, prev_method);
6045 prev_method = ientry->method;
6050 icall_hash = g_hash_table_new (g_str_hash , g_str_equal);
6054 mono_add_internal_call (const char *name, gconstpointer method)
6056 mono_loader_lock ();
6058 g_hash_table_insert (icall_hash, g_strdup (name), (gpointer) method);
6060 mono_loader_unlock ();
6064 compare_class_imap (const void *key, const void *elem)
6066 const IcallMap* imap = (const IcallMap*)elem;
6067 return strcmp (key, imap->klass);
6070 static const IcallMap*
6071 find_class_icalls (const char *name)
6073 return (const IcallMap*) bsearch (name, icall_entries, G_N_ELEMENTS (icall_entries), sizeof (IcallMap), compare_class_imap);
6077 compare_method_imap (const void *key, const void *elem)
6079 const IcallEntry* ientry = (const IcallEntry*)elem;
6080 return strcmp (key, ientry->method);
6084 find_method_icall (const IcallMap *imap, const char *name)
6086 const IcallEntry *ientry = (const IcallEntry*) bsearch (name, imap->icalls, imap->size, sizeof (IcallEntry), compare_method_imap);
6088 return (void*)ientry->func;
6093 * we should probably export this as an helper (handle nested types).
6094 * Returns the number of chars written in buf.
6097 concat_class_name (char *buf, int bufsize, MonoClass *klass)
6099 int nspacelen, cnamelen;
6100 nspacelen = strlen (klass->name_space);
6101 cnamelen = strlen (klass->name);
6102 if (nspacelen + cnamelen + 2 > bufsize)
6105 memcpy (buf, klass->name_space, nspacelen);
6106 buf [nspacelen ++] = '.';
6108 memcpy (buf + nspacelen, klass->name, cnamelen);
6109 buf [nspacelen + cnamelen] = 0;
6110 return nspacelen + cnamelen;
6114 mono_lookup_internal_call (MonoMethod *method)
6119 int typelen = 0, mlen, siglen;
6121 const IcallMap *imap;
6123 g_assert (method != NULL);
6125 typelen = concat_class_name (mname, sizeof (mname), method->klass);
6129 imap = find_class_icalls (mname);
6131 mname [typelen] = ':';
6132 mname [typelen + 1] = ':';
6134 mlen = strlen (method->name);
6135 memcpy (mname + typelen + 2, method->name, mlen);
6136 sigstart = mname + typelen + 2 + mlen;
6139 tmpsig = mono_signature_get_desc (method->signature, TRUE);
6140 siglen = strlen (tmpsig);
6141 if (typelen + mlen + siglen + 6 > sizeof (mname))
6144 memcpy (sigstart + 1, tmpsig, siglen);
6145 sigstart [siglen + 1] = ')';
6146 sigstart [siglen + 2] = 0;
6149 mono_loader_lock ();
6151 res = g_hash_table_lookup (icall_hash, mname);
6153 mono_loader_unlock ();
6156 /* try without signature */
6158 res = g_hash_table_lookup (icall_hash, mname);
6160 mono_loader_unlock ();
6164 /* it wasn't found in the static call tables */
6166 mono_loader_unlock ();
6169 res = find_method_icall (imap, sigstart - mlen);
6171 mono_loader_unlock ();
6174 /* try _with_ signature */
6176 res = find_method_icall (imap, sigstart - mlen);
6178 mono_loader_unlock ();
6182 g_warning ("cant resolve internal call to \"%s\" (tested without signature also)", mname);
6183 g_print ("\nYour mono runtime and class libraries are out of sync.\n");
6184 g_print ("The out of sync library is: %s\n", method->klass->image->name);
6185 g_print ("\nWhen you update one from cvs you need to update, compile and install\nthe other too.\n");
6186 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");
6187 g_print ("If you see other errors or faults after this message they are probably related\n");
6188 g_print ("and you need to fix your mono install first.\n");
6190 mono_loader_unlock ();
6196 type_from_typename (char *typename)
6198 MonoClass *klass = NULL; /* assignment to shut GCC warning up */
6200 if (!strcmp (typename, "int"))
6201 klass = mono_defaults.int_class;
6202 else if (!strcmp (typename, "ptr"))
6203 klass = mono_defaults.int_class;
6204 else if (!strcmp (typename, "void"))
6205 klass = mono_defaults.void_class;
6206 else if (!strcmp (typename, "int32"))
6207 klass = mono_defaults.int32_class;
6208 else if (!strcmp (typename, "uint32"))
6209 klass = mono_defaults.uint32_class;
6210 else if (!strcmp (typename, "long"))
6211 klass = mono_defaults.int64_class;
6212 else if (!strcmp (typename, "ulong"))
6213 klass = mono_defaults.uint64_class;
6214 else if (!strcmp (typename, "float"))
6215 klass = mono_defaults.single_class;
6216 else if (!strcmp (typename, "double"))
6217 klass = mono_defaults.double_class;
6218 else if (!strcmp (typename, "object"))
6219 klass = mono_defaults.object_class;
6220 else if (!strcmp (typename, "obj"))
6221 klass = mono_defaults.object_class;
6224 g_assert_not_reached ();
6226 return &klass->byval_arg;
6229 MonoMethodSignature*
6230 mono_create_icall_signature (const char *sigstr)
6235 MonoMethodSignature *res;
6237 mono_loader_lock ();
6238 res = g_hash_table_lookup (mono_defaults.corlib->helper_signatures, sigstr);
6240 mono_loader_unlock ();
6244 parts = g_strsplit (sigstr, " ", 256);
6253 res = mono_metadata_signature_alloc (mono_defaults.corlib, len - 1);
6256 #ifdef PLATFORM_WIN32
6258 * Under windows, the default pinvoke calling convention is STDCALL but
6261 res->call_convention = MONO_CALL_C;
6264 res->ret = type_from_typename (parts [0]);
6265 for (i = 1; i < len; ++i) {
6266 res->params [i - 1] = type_from_typename (parts [i]);
6271 g_hash_table_insert (mono_defaults.corlib->helper_signatures, (gpointer)sigstr, res);
6273 mono_loader_unlock ();
6279 mono_find_jit_icall_by_name (const char *name)
6281 MonoJitICallInfo *info;
6282 g_assert (jit_icall_hash_name);
6284 mono_loader_lock ();
6285 info = g_hash_table_lookup (jit_icall_hash_name, name);
6286 mono_loader_unlock ();
6291 mono_find_jit_icall_by_addr (gconstpointer addr)
6293 MonoJitICallInfo *info;
6294 g_assert (jit_icall_hash_addr);
6296 mono_loader_lock ();
6297 info = g_hash_table_lookup (jit_icall_hash_addr, (gpointer)addr);
6298 mono_loader_unlock ();
6304 mono_register_jit_icall_wrapper (MonoJitICallInfo *info, gconstpointer wrapper)
6306 mono_loader_lock ();
6307 g_hash_table_insert (jit_icall_hash_addr, (gpointer)info->wrapper, info);
6308 mono_loader_unlock ();
6312 mono_register_jit_icall (gconstpointer func, const char *name, MonoMethodSignature *sig, gboolean is_save)
6314 MonoJitICallInfo *info;
6319 mono_loader_lock ();
6321 if (!jit_icall_hash_name) {
6322 jit_icall_hash_name = g_hash_table_new (g_str_hash, g_str_equal);
6323 jit_icall_hash_addr = g_hash_table_new (NULL, NULL);
6326 if (g_hash_table_lookup (jit_icall_hash_name, name)) {
6327 g_warning ("jit icall already defined \"%s\"\n", name);
6328 g_assert_not_reached ();
6331 info = g_new (MonoJitICallInfo, 1);
6338 info->wrapper = func;
6340 info->wrapper = NULL;
6343 g_hash_table_insert (jit_icall_hash_name, (gpointer)info->name, info);
6344 g_hash_table_insert (jit_icall_hash_addr, (gpointer)func, info);
6346 mono_loader_unlock ();